oolong-engine 0.0.2-t.5 → 0.0.2-t.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/engine.js +1 -1
- package/dist/engine.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/engine.umd.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
(function(T,st){typeof exports=="object"&&typeof module<"u"?st(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],st):(T=typeof globalThis<"u"?globalThis:T||self,st(T.engine={},T.React))})(this,function(T,st){"use strict";var Ux=Object.defineProperty;var _x=(T,st,bn)=>st in T?Ux(T,st,{enumerable:!0,configurable:!0,writable:!0,value:bn}):T[st]=bn;var p=(T,st,bn)=>_x(T,typeof st!="symbol"?st+"":st,bn);var bn=document.createElement("style");bn.textContent=`.canvas-container .auxiliary-canvas{position:absolute;left:0;top:0;width:100%;height:100%;z-index:2;pointer-events:none}.canvas-container .content-canvas{position:absolute;left:0;top:0;width:100%;height:100%;z-index:1}.canvas-container .page-canvas{position:absolute;left:0;top:0;width:100%;height:100%;z-index:0}.normal-container,.normal-container .normal-canvas{width:100%;height:100%}.canvas-input{position:absolute;border:none;outline:none;-webkit-user-select:none;user-select:none;width:1px;z-index:3;opacity:0;pointer-events:none}@keyframes van-cursor-flicker{0%{opacity:1}50%{opacity:0}to{opacity:1}}.render-input{position:absolute;background-color:#000;width:1px;height:12px;z-index:4;pointer-events:none;animation:.6s van-cursor-flicker infinite}
|
|
2
2
|
/*$vite$:1*/`,document.head.appendChild(bn);class zl{constructor(t){p(this,"ctx");this.ctx=t,t.actionManager.addNetworkPlugin(this)}onEnable(t){return!0}}class hn{exec(t,e){const n=t.data;t.reverseLog=this.reverseLog(n,e),this.execData(n,e)}}var Xe=(l=>(l[l.Start=0]="Start",l[l.End=1]="End",l[l.AddNode=2]="AddNode",l[l.RemoveNode=3]="RemoveNode",l[l.UpdateNode=4]="UpdateNode",l[l.SelectNode=5]="SelectNode",l[l.TextFocus=6]="TextFocus",l))(Xe||{});class m{constructor(t=0,e=0){p(this,"x");p(this,"y");this.x=t,this.y=e}clone(){return new m(this.x,this.y)}}var Xr=(l=>(l.LEFT="LEFT",l.TOP="TOP",l.RIGHT="RIGHT",l.BOTTOM="BOTTOM",l))(Xr||{});class Wl extends m{constructor(e,n,o,s){super(e.x,e.y);p(this,"xPos");p(this,"yPos");p(this,"nodeSide");this.xPos=n,this.yPos=o,this.nodeSide=s}}class Fl extends m{constructor(){super(...arguments);p(this,"isHorizon",!0)}}const Mn="ROOT",zr="ROOT";var v=(l=>(l[l.Shape=0]="Shape",l[l.Line=1]="Line",l[l.SVG=2]="SVG",l[l.IMG=3]="IMG",l[l.Section=4]="Section",l[l.Group=5]="Group",l[l.Checkbox=6]="Checkbox",l[l.CheckboxText=7]="CheckboxText",l[l.SlideContainer=8]="SlideContainer",l[l.ROOT=99]="ROOT",l))(v||{}),et=(l=>(l[l.None=0]="None",l[l.Solid=1]="Solid",l[l.Dash1=2]="Dash1",l[l.Dash2=3]="Dash2",l))(et||{}),it=(l=>(l[l.None=0]="None",l[l.Arrow=1]="Arrow",l[l.Triangle=2]="Triangle",l[l.EmptyTriangle=3]="EmptyTriangle",l[l.Diamond=4]="Diamond",l[l.EmptyDiamond=5]="EmptyDiamond",l[l.Circle=6]="Circle",l[l.EmptyCircle=7]="EmptyCircle",l))(it||{}),at=(l=>(l[l.Top=0]="Top",l[l.Middle=1]="Middle",l[l.Bottom=2]="Bottom",l))(at||{}),We=(l=>(l[l.fix=0]="fix",l[l.autoHeight=1]="autoHeight",l[l.autoWidth=2]="autoWidth",l))(We||{}),I=(l=>(l[l.Base=0]="Base",l[l.Color=1]="Color",l[l.Border=2]="Border",l[l.Text=3]="Text",l[l.Shape=4]="Shape",l[l.Line=5]="Line",l[l.Arrow=6]="Arrow",l[l.Connect=7]="Connect",l[l.LineTextRect=8]="LineTextRect",l[l.Svg=9]="Svg",l[l.Image=10]="Image",l[l.Crop=11]="Crop",l[l.CheckStatus=12]="CheckStatus",l[l.CheckSize=13]="CheckSize",l[l.TextParagraph=14]="TextParagraph",l[l.TextParagraphQuote=15]="TextParagraphQuote",l[l.Slide=16]="Slide",l))(I||{});class ct{}class ro extends ct{constructor(){super(...arguments);p(this,"type",I.Image);p(this,"url","")}static from(e){const n=new ro;return n.url=e.url,n}clone(){const e=new ro;return e.url=this.url,e}update(e){const{url:n}=e;n!==void 0&&(this.url=n)}}class ie extends ct{constructor(){super(...arguments);p(this,"type",I.Base);p(this,"x",0);p(this,"y",0);p(this,"width",100);p(this,"height",100);p(this,"angle",0)}static create(e){const n=new ie;return n.update(e),n}static from(e){const n=new ie;return n.x=e.x,n.y=e.y,n.width=e.width,n.height=e.height,n.angle=e.angle,n}update(e){const{x:n,y:o,height:s,width:r,angle:i}=e;n!==void 0&&(this.x=n),o!==void 0&&(this.y=o),s!==void 0&&(this.height=s),r!==void 0&&(this.width=r),i!==void 0&&(this.angle=i)}clone(){const e=new ie;return e.x=this.x,e.y=this.y,e.width=this.width,e.height=this.height,e.angle=this.angle,e}}class Ae extends ct{constructor(){super(...arguments);p(this,"type",I.Border);p(this,"color","#000000");p(this,"alpha",1);p(this,"width",2);p(this,"dashType",et.Solid)}static create(e){const n=new Ae;return n.update(e),n}static from(e){const n=new Ae;return n.color=e.color,n.alpha=e.alpha,n.width=e.width,n.dashType=e.dashType,n}update(e){const{color:n,alpha:o,width:s,dashType:r}=e;n!==void 0&&(this.color=n),o!==void 0&&(this.alpha=o),s!==void 0&&(this.width=s),r!==void 0&&(this.dashType=r)}clone(){const e=new Ae;return e.color=this.color,e.alpha=this.alpha,e.width=this.width,e.dashType=this.dashType,e}}class re{constructor(){p(this,"a",1);p(this,"b",0);p(this,"c",0);p(this,"d",1);p(this,"e",0);p(this,"f",0)}static generateMatrix(){return new re}setTransform(t,e,n,o,s,r){this.a=t,this.b=e,this.c=n,this.d=o,this.e=s,this.f=r}rotate(t){const e=t/180*Math.PI;return this.rotate2(e),this}rotate2(t){return this.a=Math.cos(t),this.c=-Math.sin(t),this.b=Math.sin(t),this.d=Math.cos(t),this}scale(t,e){return this.a=t,this.d=e,this}translate(t,e){return this.e=t,this.f=e,this}crossProduct(t){const e=new re;return e.a=this.a*t.a+this.c*t.b,e.b=this.b*t.a+this.d*t.b,e.c=this.a*t.c+this.c*t.d,e.d=this.b*t.c+this.d*t.d,e.e=this.a*t.e+this.c*t.f+this.e,e.f=this.b*t.e+this.d*t.f+this.f,e}crossPoint(t){return new m(this.a*t.x+this.c*t.y+this.e,this.b*t.x+this.d*t.y+this.f)}inverseMatrix(){const{a:t,b:e,c:n,d:o,e:s,f:r}=this,i=t*o-e*n;if(Math.abs(i)<1e-4)throw new Error("该仿射变换不可逆");const a=o/i,c=-e/i,h=-n/i,d=t/i,u=(n*r-o*s)/i,f=(e*s-t*r)/i,g=re.generateMatrix();return g.a=a,g.b=c,g.c=h,g.d=d,g.e=u,g.f=f,g}clone(){const t=new re;return t.a=this.a,t.b=this.b,t.c=this.c,t.d=this.d,t.e=this.e,t.f=this.f,t}}class Yl{constructor(t,e,n){p(this,"p0");p(this,"p1");p(this,"p2");this.p0=t,this.p1=e,this.p2=n}xStationaryPoint(){return(this.p0.x-this.p1.x)/(this.p0.x-2*this.p1.x+this.p2.x)}dxdt(t){return 2*t*(this.p0.x-2*this.p1.x+this.p2.x)-2*(this.p0.x-this.p1.x)}xValue(t){const e=1-t;return e*e*this.p0.x+2*t*e*this.p1.x+t*t*this.p2.x}yValue(t){const e=1-t;return e*e*this.p0.y+2*t*e*this.p1.y+t*t*this.p2.y}newtonSolveX(t,e,n){let s=.5*(e+n),r=0;for(;;){r++;const i=this.xValue(s)-t,a=this.dxdt(s),c=s-i/a;if(Math.abs(c-s)<.01)return c;if(r>20)return null;s=c}return null}solve(t,e=6){const n=this.xStationaryPoint();if(n<0||n>1)return this.monotonicSolve(t,0,1,e);let o=this.monotonicSolve(t,0,n,e);return o?!0:(o=this.monotonicSolve(t,n,1,e),o)}monotonicSolve(t,e,n,o){const s=this.xValue(e),r=this.xValue(n),i=t.x,a=t.y;if((i-s)*(i-r)>0)return!1;const c=this.newtonSolveX(i,e,n);return c===null?(console.warn("newton 迭代求解贝塞尔曲线出错."),!1):Math.abs(a-this.yValue(c))<o}}class Bo{constructor(t){p(this,"prev",null);p(this,"next",null);p(this,"data",null);this.data=t}breakOff(){this.prev=null,this.next=null}toString(){return this.data?this.data.toString():""}add(t){const e=this.next;this.next=t,t.prev=this,t.next=e,e&&(e.prev=t)}pushAdd(t){this.next=t,t.prev=this}removeSelf(){const t=this.next,e=this.prev;this.next=null,this.prev=null,t.prev=e,e.next=t}getIndex(){let t=this.prev,e=0;for(;t&&t.data;)e++,t=t.prev;return e}static generateLink(){const t=new Bo(null),e=new Bo(null);return t.add(e),t}}class D{constructor(t=0,e=0,n=100,o=100){p(this,"x");p(this,"y");p(this,"width");p(this,"height");this.x=t,this.y=e,this.width=n,this.height=o}clone(){return new D(this.x,this.y,this.width,this.height)}static baseProps2Rect(t){const{x:e,y:n,width:o,height:s}=t;return new D(e,n,o,s)}static rectNode2Rect(t){const{minY:e,minX:n,maxY:o,maxX:s}=t;return new D(n,e,s-n,o-e)}static toRectNode(t){const{x:e,y:n,width:o,height:s}=t;return{minX:e,minY:n,maxX:e+o,maxY:n+s}}}var zn=(l=>(l[l.Image=0]="Image",l[l.SVG=1]="SVG",l))(zn||{});class Ke{constructor(){p(this,"result",null)}detect(t,e){return this.result?!0:this.onDetect(t,e)}reset(){this.result=null}}var F=(l=>(l[l.Node=0]="Node",l[l.Stretch=1]="Stretch",l[l.HoverNode=2]="HoverNode",l[l.ParagraphHead=3]="ParagraphHead",l[l.PolyControlPoint=4]="PolyControlPoint",l[l.CurveControlPoint=5]="CurveControlPoint",l[l.LineEndPoint=6]="LineEndPoint",l[l.ConnectorPoint=7]="ConnectorPoint",l[l.Rotate=8]="Rotate",l[l.SingleStretch=9]="SingleStretch",l[l.ExpandShape=10]="ExpandShape",l[l.NodeEdge=11]="NodeEdge",l[l.BufferNode=12]="BufferNode",l[l.BufferHoverNode=13]="BufferHoverNode",l[l.HoverNodeAnchor=14]="HoverNodeAnchor",l[l.HoverConnectAnchor=15]="HoverConnectAnchor",l[l.HoverOnContainer=16]="HoverOnContainer",l[l.Image=17]="Image",l[l.ImageOriginBounds=18]="ImageOriginBounds",l[l.CurveEndPoint=19]="CurveEndPoint",l[l.DragLineText=20]="DragLineText",l[l.SlideGap=21]="SlideGap",l[l.EmptySlideContainer=22]="EmptySlideContainer",l))(F||{}),be=(l=>(l.pointerDown="pointerdown",l.pointermove="pointermove",l.pointermoveOutside="pointermoveOutside",l.pointerup="pointerup",l.unknown="unknown",l))(be||{}),V=(l=>(l[l.TOP=0]="TOP",l[l.LEFT=1]="LEFT",l[l.BOTTOM=2]="BOTTOM",l[l.RIGHT=3]="RIGHT",l[l.TOP_LEFT=4]="TOP_LEFT",l[l.TOP_RIGHT=5]="TOP_RIGHT",l[l.BOTTOM_LEFT=6]="BOTTOM_LEFT",l[l.BOTTOM_RIGHT=7]="BOTTOM_RIGHT",l))(V||{});class tt extends ct{constructor(){super(...arguments);p(this,"type",I.Color);p(this,"color","#ffccff");p(this,"alpha",1)}static create(e){const n=new tt;return n.update(e),n}static from(e){const n=new tt;return n.color=e.color,n.alpha=e.alpha,n}update(e){const{color:n,alpha:o}=e;n!==void 0&&(this.color=n),o!==void 0&&(this.alpha=o)}clone(){const e=new tt;return e.color=this.color,e.alpha=this.alpha,e}}class Ge extends ct{constructor(){super(...arguments);p(this,"type",I.Text);p(this,"text","");p(this,"richText","");p(this,"fontSize",14);p(this,"fontFamily","Noto Sans");p(this,"fontColor","#000000");p(this,"fontBgColor","");p(this,"bold",!1);p(this,"italic",!1);p(this,"underline",!1);p(this,"strikethrough",!1);p(this,"verticalAlign",at.Middle);p(this,"horizonAlign",at.Middle);p(this,"sizeMode",We.fix)}static create(e){const n=new Ge;return n.update(e),n}static from(e){const n=new Ge;return n.text=e.text,n.fontSize=e.fontSize,n.fontFamily=e.fontFamily,n.fontColor=e.fontColor,n.fontBgColor=e.fontBgColor,n.bold=e.bold,n.italic=e.italic,n.underline=e.underline,n.strikethrough=e.strikethrough,n.verticalAlign=e.verticalAlign,n.horizonAlign=e.horizonAlign,n.sizeMode=e.sizeMode,n.richText=e.richText,!e.richText&&e.text&&(n.richText=this.dealTextToRichText(e.text)),n}update(e){const{sizeMode:n,verticalAlign:o,horizonAlign:s,fontFamily:r,fontSize:i,text:a,bold:c,italic:h,fontColor:d,fontBgColor:u,underline:f,strikethrough:g,richText:y}=e;a!==void 0&&(this.text=a),r!==void 0&&(this.fontFamily=r),i!==void 0&&(this.fontSize=i),d!==void 0&&(this.fontColor=d),u!==void 0&&(this.fontBgColor=u.trim()),c!==void 0&&(this.bold=c),h!==void 0&&(this.italic=h),f!==void 0&&(this.underline=f),g!==void 0&&(this.strikethrough=g),o!==void 0&&(this.verticalAlign=o),s!==void 0&&(this.horizonAlign=s),n!==void 0&&(this.sizeMode=n),y!==void 0&&(this.richText=y)}clone(){const e=new Ge;return e.text=this.text,e.fontFamily=this.fontFamily,e.fontSize=this.fontSize,e.fontColor=this.fontColor,e.fontBgColor=this.fontBgColor,e.bold=this.bold,e.italic=this.italic,e.underline=this.underline,e.strikethrough=this.strikethrough,e.horizonAlign=this.horizonAlign,e.verticalAlign=this.verticalAlign,e.sizeMode=this.sizeMode,e.richText=this.richText,e}static dealTextToRichText(e){const n=e.split(`
|
|
3
|
-
`);let o="<root>";for(const s of n)o=o+"<p>"+s+"</p>";return o+="</root>",o}}class Oe extends ct{constructor(e=1){super();p(this,"type",I.Shape);p(this,"shapeCode",1);this.shapeCode=e}static from(e){const n=new Oe;return n.shapeCode=e.shapeCode,n}update(e){const{shapeCode:n}=e;n!==void 0&&(this.shapeCode=n)}clone(){const e=new Oe;return e.shapeCode=this.shapeCode,e}}class je extends ct{constructor(){super(...arguments);p(this,"type",I.Line);p(this,"points",[]);p(this,"auto",!0)}static create(e,n=!0){const o=new je;return o.auto=n,o.points=e,o}static from(e){const n=new je;return n.points=e.points,n.auto=e.auto,n}clone(){const e=new je,n=[];for(const o of this.points)n.push(M.cloneIPoint(o));return e.points=n,e.auto=this.auto,e}update(e){const{points:n,auto:o}=e;n!==void 0&&(this.points=n),o!==void 0&&(this.auto=o)}}class Rt extends ct{constructor(){super(...arguments);p(this,"type",I.Connect);p(this,"start",null);p(this,"end",null)}static from(e){const n=new Rt;return n.start=e.start,n.end=e.end,n}clone(){const e=new Rt;return e.start=this.start,e.end=this.end,e}update(e){const{start:n,end:o}=e;n!==void 0&&(this.start=n),o!==void 0&&(this.end=o)}}class lt extends ct{constructor(){super(...arguments);p(this,"type",I.Arrow);p(this,"lArrow",it.None);p(this,"rArrow",it.None)}static create(e){const n=new lt;return n.update(e),n}static from(e){const n=new lt;return n.lArrow=e.lArrow,n.rArrow=e.rArrow,n}clone(){const e=new lt;return e.rArrow=this.rArrow,e.lArrow=this.lArrow,e}update(e){const{lArrow:n,rArrow:o}=e;n!==void 0&&(this.lArrow=n),o!==void 0&&(this.rArrow=o)}}var ue=(l=>(l[l.Top=0]="Top",l[l.Right=1]="Right",l[l.Bottom=2]="Bottom",l[l.Left=3]="Left",l))(ue||{});class Et extends ct{constructor(){super(...arguments);p(this,"type",I.LineTextRect);p(this,"width",20);p(this,"height",20);p(this,"x",0);p(this,"y",0);p(this,"point",{x:0,y:0})}static from(e){const n=new Et;return n.width=e.width,n.height=e.height,n.x=e.x,n.y=e.y,n.point=e.point,n}update(e){const{x:n,y:o,point:s,height:r,width:i}=e;n!==void 0&&(this.x=n),o!==void 0&&(this.y=o),r!==void 0&&(this.height=r),i!==void 0&&(this.width=i),s!==void 0&&(this.point=s)}clone(){const e=new Et;return e.width=this.width,e.height=this.height,e.x=this.x,e.y=this.y,e.point=this.point,e}}var N=(l=>(l[l.HoverBounds=0]="HoverBounds",l[l.HoverLine=1]="HoverLine",l[l.SelectLine=2]="SelectLine",l[l.MultiSelectBound=3]="MultiSelectBound",l[l.TextSelection=4]="TextSelection",l[l.SelectGroup=5]="SelectGroup",l[l.SelectRect=6]="SelectRect",l[l.HighLightLine=7]="HighLightLine",l[l.AlignLine=8]="AlignLine",l[l.AlignStretchLine=9]="AlignStretchLine",l[l.SingleSelectBound=10]="SingleSelectBound",l[l.RotateLine=11]="RotateLine",l[l.HighlightRects=12]="HighlightRects",l[l.CreateRectBound=13]="CreateRectBound",l[l.ExpandShape=14]="ExpandShape",l[l.SelectLineEnd=15]="SelectLineEnd",l[l.HoverConnectPoint=16]="HoverConnectPoint",l[l.HoverConnectAnchorPoint=17]="HoverConnectAnchorPoint",l[l.HoverAnchorPoint=18]="HoverAnchorPoint",l[l.SelectPolyLineControlPoint=19]="SelectPolyLineControlPoint",l[l.SelectLineTextRect=20]="SelectLineTextRect",l[l.PlaceHolder=21]="PlaceHolder",l[l.SelectConnectAnchor=22]="SelectConnectAnchor",l[l.HoverConnectAnchor=23]="HoverConnectAnchor",l[l.PreviewGraphics=24]="PreviewGraphics",l[l.HoverContainer=25]="HoverContainer",l[l.CropBounds=26]="CropBounds",l[l.CropOriginImg=27]="CropOriginImg",l[l.StretchRect=28]="StretchRect",l[l.HoverSize=29]="HoverSize",l[l.SelectCurveControlPoint=30]="SelectCurveControlPoint",l[l.SelectCurveEnd=31]="SelectCurveEnd",l[l.SelectParentGroupBound=32]="SelectParentGroupBound",l[l.SelectSlideGapInsertPoint=33]="SelectSlideGapInsertPoint",l[l.HoverSlidePlaceHolder=34]="HoverSlidePlaceHolder",l[l.HoverInsertSlide=35]="HoverInsertSlide",l[l.HoverInsertHorizonSlide=36]="HoverInsertHorizonSlide",l[l.HoverSlideGapInsertPoint=37]="HoverSlideGapInsertPoint",l[l.HoverFocusCopy=38]="HoverFocusCopy",l))(N||{});class Se{constructor(){p(this,"prop")}update(t){this.prop=t}}const Ht="#FFFFFF",bs="#000000",Gt="#647ee5",Qe="#545DE7",Ms="#32a8f2",Wr="#3370FF",Fr=8,Yr=18,Gr=5,Ss=11,Ur="#CCCCCC",_r="#B7BEF5",$r="#DADEFA";class jr extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.HoverBounds)}draw(e,n){const{node:o,transform:s}=this.prop;e.save(),e.strokeStyle=Gt,e.lineWidth=2/n,e.globalAlpha=1;const{x:r,y:i,width:a,height:c}=o.baseProps,{a:h,b:d,c:u,d:f,e:g,f:y}=s;e.transform(h,d,u,f,g,y),e.beginPath(),e.strokeRect(0,0,a,c),e.restore()}}class Vr extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.SingleSelectBound)}draw(e,n){const{x:o,y:s,width:r,height:i,transform:a}=this.prop;e.save(),e.strokeStyle=Qe,e.lineWidth=1/n,e.globalAlpha=1;const{a:c,b:h,c:d,d:u,e:f,f:g}=a;e.transform(c,h,d,u,f,g),e.beginPath(),e.strokeRect(o,s,r,i),e.restore()}}class Kr extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.MultiSelectBound)}draw(e,n){const{rect:o}=this.prop;e.save(),e.strokeStyle=Qe,e.lineWidth=1/n,e.globalAlpha=1;const{x:s,y:r,width:i,height:a}=o;e.beginPath(),e.strokeRect(s,r,i,a),e.restore()}}class Qr extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.HighlightRects)}draw(e,n){const{rects:o}=this.prop;for(const s of o){e.save(),e.strokeStyle=Qe,e.lineWidth=1/n,e.globalAlpha=1;const{x:r,y:i,width:a,height:c}=s;e.beginPath(),e.strokeRect(r,i,a,c),e.restore()}}}class Zr extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.SelectGroup)}draw(e,n){const{rect:o,isPrecise:s}=this.prop;e.save(),e.beginPath(),e.strokeStyle=Ms,e.fillStyle=Ms,s&&e.setLineDash([2,2]),e.rect(o.x,o.y,o.width,o.height),e.lineWidth=1/n,e.stroke(),e.globalAlpha=.2,e.fill(),e.restore()}}class qr extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.TextSelection)}draw(e){const{selectionList:n,node:o}=this.prop;if(n.length===0)return;e.save(),e.fillStyle=Wr,e.globalAlpha=.5;const{a:s,b:r,c:i,d:a,e:c,f:h}=o.globalTransform();e.transform(s,r,i,a,c,h);for(const d of n)e.fillRect(d.x,d.y,d.width,d.height);e.restore()}}class Jr{static computeStretchRects(t,e){const n=Fr/e,o=.5*n;return[new D(t.x-o,t.y-o,n,n),new D(t.x+t.width-o,t.y-o,n,n),new D(t.x+t.width-o,t.y+t.height-o,n,n),new D(t.x-o,t.y+t.height-o,n,n)]}}class ei extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.StretchRect)}draw(e,n){const{rect:o,transform:s}=this.prop,r=Jr.computeStretchRects(o,n);e.save();const{a:i,b:a,c,d:h,e:d,f:u}=s;e.transform(i,a,c,h,d,u),e.strokeStyle=Qe,e.fillStyle=Ht,e.lineWidth=1/n,e.globalAlpha=1,e.beginPath();for(const f of r)e.roundRect(f.x,f.y,f.width,f.height,1/n),e.fill(),e.stroke();e.restore()}}class ti extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.CreateRectBound)}draw(e,n){const{rect:o,transform:s}=this.prop;e.save();const{a:r,b:i,c:a,d:c,e:h,f:d}=s;e.transform(r,i,a,c,h,d),e.strokeStyle=Qe,e.lineWidth=1/n,e.globalAlpha=1;const{width:u,height:f}=o;e.beginPath(),e.strokeRect(0,0,u,f),e.restore()}}class ni extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.ExpandShape)}draw(e,n){const{rect:o,transform:s}=this.prop,{width:r,height:i}=o,a=1.5/n,c=re.generateMatrix().scale(a,a),h=re.generateMatrix().translate(.5*r-.5*a*14,i-.5*a*8),d=s.crossProduct(h.crossProduct(c));e.save(),e.beginPath();const{a:u,b:f,c:g,d:y,e:P,f:b}=d;e.transform(u,f,g,y,P,b),e.fillStyle=Qe,e.roundRect(0,0,14,7.58333,2),e.fill(),e.beginPath(),e.fillStyle=Ht,e.rect(1.75,2.91666,2.33333,2.33333),e.rect(5.83333,2.91666,2.33333,2.33333),e.rect(9.91667,2.91666,2.33333,2.33333),e.fill(),e.restore()}}class oi extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.AlignLine)}draw(e,n){const{lines:o}=this.prop;e.save(),e.beginPath(),e.strokeStyle=Qe,e.lineWidth=1/n,e.globalAlpha=1,e.setLineDash([4,2]);for(const s of o){const{start:r,end:i}=s;e.moveTo(r.x,r.y),e.lineTo(i.x,i.y)}e.stroke(),e.restore()}}class si extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.AlignStretchLine)}draw(e,n){const o=10/n,{alignInfo:s}=this.prop,{width:r,height:i}=s;e.save(),e.beginPath(),e.strokeStyle=Qe,e.lineWidth=1/n,e.globalAlpha=1,r&&this.drawWidth(e,r,o),i&&this.drawHeight(e,i,o),e.restore()}drawWidth(e,n,o){const{lines:s}=n;for(const r of s){const{line:i,transform:a}=r,{start:c,end:h}=i;e.save();const{a:d,b:u,c:f,d:g,e:y,f:P}=a;e.transform(d,u,f,g,y,P);const b={x:c.x,y:c.y},w={x:c.x,y:c.y+2*o};e.moveTo(b.x,b.y),e.lineTo(w.x,w.y);const L={x:h.x,y:h.y},B={x:h.x,y:h.y+2*o};e.moveTo(L.x,L.y),e.lineTo(B.x,B.y),e.moveTo(c.x,c.y+o),e.lineTo(h.x,h.y+o),e.stroke(),e.restore()}}drawHeight(e,n,o){const{lines:s}=n;for(const r of s){const{line:i,transform:a}=r,{start:c,end:h}=i;e.save();const{a:d,b:u,c:f,d:g,e:y,f:P}=a;e.transform(d,u,f,g,y,P);const b={x:c.x,y:c.y},w={x:c.x+2*o,y:c.y};e.moveTo(b.x,b.y),e.lineTo(w.x,w.y);const L={x:h.x,y:h.y},B={x:h.x+2*o,y:h.y};e.moveTo(L.x,L.y),e.lineTo(B.x,B.y),e.moveTo(c.x+o,c.y),e.lineTo(h.x+o,h.y),e.stroke(),e.restore()}}}class Gl extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.SingleSelectBound)}draw(e,n){const{start:o,end:s,transform:r}=this.prop,i=5/n;e.save();const{a,b:c,c:h,d,e:u,f}=r;e.transform(a,c,h,d,u,f),e.strokeStyle=Qe,e.fillStyle=Ht,e.lineWidth=2/n,e.globalAlpha=1,e.beginPath(),e.arc(o.x,o.y,i,0,2*Math.PI),e.fill(),e.stroke(),e.beginPath(),e.arc(s.x,s.y,i,0,2*Math.PI),e.fill(),e.stroke(),e.restore()}}class Ul extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.HoverLine)}draw(e,n){const{node:o,transform:s}=this.prop;e.save();const{a:r,b:i,c:a,d:c,e:h,f:d}=s;e.transform(r,i,a,c,h,d),e.strokeStyle=Gt,e.lineWidth=2/n,e.globalAlpha=1,e.beginPath(),o.drawer.draw(o,e),e.restore()}}class _l extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.SelectLine)}draw(e,n){const{node:o}=this.prop;e.save();const{a:s,b:r,c:i,d:a,e:c,f:h}=o.globalTransform();e.transform(s,r,i,a,c,h),e.strokeStyle=Qe,e.lineWidth=2/n,e.globalAlpha=1,e.beginPath(),o.drawer.draw(o,e),e.restore()}}class $l extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.HoverConnectPoint)}draw(e,n){const{point:o}=this.prop,s=4/n;e.save(),e.fillStyle=Gt,e.strokeStyle=Gt,e.lineWidth=2/n,e.globalAlpha=1,e.beginPath(),e.arc(o.x,o.y,s,0,2*Math.PI),e.fill(),e.restore()}}class jl extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.HoverConnectAnchorPoint)}draw(e,n){const{node:o}=this.prop;if(!o.canQuickCreate())return;const s=5/n,{width:r,height:i}=o.baseProps,{a,b:c,c:h,d,e:u,f}=o.globalTransform(),g=o.getConnectAnchor(),y=[];for(const P of g)y.push(new m(P.x*r,P.y*i));e.save(),e.transform(a,c,h,d,u,f),e.fillStyle=Ht,e.strokeStyle=Qe;for(const P of y)e.beginPath(),e.arc(P.x,P.y,s,0,2*Math.PI),e.fill(),e.stroke();e.restore()}}class Vl extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.HoverConnectAnchorPoint)}draw(e,n){const{node:o,localPoint:s}=this.prop;if(!o.canBeConnected())return;const r=6/n,{a:i,b:a,c,d:h,e:d,f:u}=o.globalTransform();e.save(),e.transform(i,a,c,h,d,u),e.fillStyle=Gt,e.beginPath(),e.arc(s.x,s.y,r,0,2*Math.PI),e.fill(),e.stroke(),e.restore()}}const A=22;class Kl extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.SelectPolyLineControlPoint)}draw(e,n){const{points:o,transform:s}=this.prop;e.save(),e.fillStyle=Qe,e.strokeStyle=Ht,e.lineWidth=2/n,e.globalAlpha=1;const{a:r,b:i,c:a,d:c,e:h,f:d}=s;e.transform(r,i,a,c,h,d);for(let u=0;u<o.length-1;u++){const f=o[u],g=o[u+1];if(M.distance(f,g)<(A+6)/n)continue;const P=M.judgeHorizon(f,g),b=.5*(f.x+g.x),w=.5*(f.y+g.y);if(e.beginPath(),P){const L=new m(b-6/n,w);e.roundRect(L.x,L.y-2/n,12/n,4/n,2/n)}else{const L=new m(b,w-6/n);e.roundRect(L.x-2/n,L.y,4/n,12/n,2/n)}e.stroke(),e.fill()}e.restore()}}class Ql extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.SelectLineTextRect)}draw(e,n){const{node:s,transform:r}=this.prop,i=s.getTextContentRect();e.save();const{a,b:c,c:h,d,e:u,f}=r;e.transform(a,c,h,d,u,f),e.strokeStyle=Qe,e.lineWidth=2/n,e.globalAlpha=1,e.beginPath(),e.strokeRect(i.x-2,i.y-2,i.width+2*2,i.height+2*2),e.restore()}}const ri="输入文本";class Zl extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.PlaceHolder)}draw(e,n){const{node:o}=this.prop,s=o.shapeType!==K.PureText,r=o.renderText,i=r.paragraphs[0],a=i.lines[0],c=r.x+i.x+a.x,h=r.y+i.y+a.y,{fontSize:d,fontFamily:u,bold:f,italic:g}=r.textProps;e.save();const{a:y,b:P,c:b,d:w,e:L,f:B}=o.globalTransform();e.transform(y,P,b,w,L,B),e.textAlign="left",e.textBaseline="alphabetic",e.fillStyle="#000000",e.globalAlpha=.5,e.font=M.calcFont(d,u,f,g);const H=e.measureText(ri),E=H.fontBoundingBoxAscent,X=H.width,$=s?c-.5*X:c;e.fillText(ri,$,h+E),e.restore()}}class ql extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.SelectConnectAnchor)}draw(e,n){const{node:o}=this.prop,s=Gr/n,r=M.computeNodeConnectAnchor(o,n);e.save(),e.fillStyle=_r,e.globalAlpha=1;const{a:i,b:a,c,d:h,e:d,f:u}=o.globalTransform();e.transform(i,a,c,h,d,u);for(const f of r)e.beginPath(),e.arc(f.x,f.y,s,0,2*Math.PI),e.fill();e.restore()}}class Jl extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.HoverConnectAnchor)}draw(e,n){const{point:o}=this.prop,s=Ss/n;e.save(),e.strokeStyle=Qe,e.fillStyle=$r,e.globalAlpha=1,e.lineWidth=2/n,e.beginPath(),e.arc(o.x,o.y,s,0,2*Math.PI),e.fill(),e.stroke(),e.restore()}}class eh extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.PreviewGraphics)}draw(e,n){const{previewNodes:o}=this.prop;for(const s of o)s.drawOnGLCtx(e)}}class th extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.HoverContainer)}draw(e,n){const{node:o}=this.prop;e.save(),e.strokeStyle=Gt,e.lineWidth=2/n,e.globalAlpha=1;const{width:s,height:r}=o.baseProps,{a:i,b:a,c,d:h,e:d,f:u}=o.globalTransform();e.transform(i,a,c,h,d,u),e.beginPath(),e.strokeRect(0,0,s,r),e.restore()}}class nh extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.CropBounds)}draw(e,n){const{node:o,transform:s}=this.prop,r=12/n;e.save(),e.strokeStyle=bs,e.lineWidth=2/n,e.globalAlpha=1;const{width:i,height:a}=o.baseProps,{a:c,b:h,c:d,d:u,e:f,f:g}=s;e.transform(c,h,d,u,f,g),e.beginPath(),e.moveTo(0,r),e.lineTo(0,0),e.lineTo(r,0),e.moveTo(i-r,0),e.lineTo(i,0),e.lineTo(i,r),e.moveTo(i-r,a),e.lineTo(i,a),e.lineTo(i,a-r),e.moveTo(0,a-r),e.lineTo(0,a),e.lineTo(r,a),e.moveTo(.5*i-.5*r,0),e.lineTo(.5*i+.5*r,0),e.moveTo(.5*i-.5*r,a),e.lineTo(.5*i+.5*r,a),e.moveTo(0,.5*a-.5*r),e.lineTo(0,.5*a+.5*r),e.moveTo(i,.5*a-.5*r),e.lineTo(i,.5*a+.5*r),e.stroke(),e.beginPath(),e.setLineDash([2,2]),e.lineWidth=1/n,e.strokeRect(0,0,i,a),e.restore()}}class oh extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.CropOriginImg)}draw(e,n){const{imgBitmap:o,transform:s,x:r,y:i,width:a,height:c}=this.prop;e.save();const{a:h,b:d,c:u,d:f,e:g,f:y}=s;e.transform(h,d,u,f,g,y),e.globalAlpha=.4,e.drawImage(o,r,i,a,c),e.restore()}}class sh extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.HoverSize)}draw(e,n){const{rect:o,transform:s}=this.prop,{width:r,height:i}=o,a=Math.round(r),c=Math.round(i),h=`${a}x${c}`,d=12/n,u="Noto Sans",f=M.measureTextByFont(e,h,d,"Noto Sans",!1,!1);e.save();const g=re.generateMatrix().translate(r-f.width,i),{a:y,b:P,c:b,d:w,e:L,f:B}=s.crossProduct(g);e.transform(y,P,b,w,L,B),e.fillStyle=Qe,e.globalAlpha=1,e.fillRect(0,0,f.width,f.height),e.fillStyle=Ht,e.font=M.calcFont(d,u),e.textAlign="left",e.textBaseline="top",e.fillText(h,0,2/n),e.restore()}}class rh extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.SingleSelectBound)}draw(e,n){const{points:o,transform:s}=this.prop,r=5/n;e.save();const{a:i,b:a,c,d:h,e:d,f:u}=s;e.transform(i,a,c,h,d,u),e.strokeStyle=Qe,e.fillStyle=Qe,e.lineWidth=2/n,e.globalAlpha=1;for(const f of o)e.beginPath(),e.arc(f.x,f.y,r,0,2*Math.PI),e.fill(),e.stroke();e.restore()}}class ih extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.SelectCurveEnd)}draw(e,n){const{points:o,transform:s}=this.prop,r=5/n;e.save();const{a:i,b:a,c,d:h,e:d,f:u}=s;e.transform(i,a,c,h,d,u),e.strokeStyle=Qe,e.fillStyle=Ht,e.lineWidth=2/n,e.globalAlpha=1;for(const f of o)e.beginPath(),e.arc(f.x,f.y,r,0,2*Math.PI),e.fill(),e.stroke();e.restore()}}class ah extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.SelectParentGroupBound)}draw(e,n){const{node:o}=this.prop;e.save(),e.strokeStyle=Gt,e.lineWidth=1/n,e.globalAlpha=1;const{width:s,height:r}=o.baseProps,{a:i,b:a,c,d:h,e:d,f:u}=o.nameGlobalTransform();e.transform(i,a,c,h,d,u),e.beginPath(),e.strokeRect(0,0,s,r),e.restore()}}class ch extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.HoverSlidePlaceHolder)}draw(e,n){const{baseProps:o}=this.prop;e.save(),e.fillStyle=Ur,e.lineWidth=2/n,e.globalAlpha=.5;const{x:s,y:r,width:i,height:a}=o;e.beginPath(),e.roundRect(s,r,i,a,10),e.fill(),e.restore()}}class lh extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.HoverFocusCopy)}draw(e,n){const{nodes:o}=this.prop;e.save();for(const s of o)s.drawOnGLCtx(e);e.restore()}}class hh extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.HoverInsertSlide)}draw(e,n){const{x:o,y1:s,y0:r}=this.prop;e.save(),e.strokeStyle=Gt,e.lineWidth=2/n,e.globalAlpha=1,e.moveTo(o,r),e.lineTo(o,s),e.stroke(),e.restore()}}class dh extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.HoverInsertHorizonSlide)}draw(e,n){const{x0:o,x1:s,y:r}=this.prop;e.save(),e.strokeStyle=Gt,e.lineWidth=2/n,e.globalAlpha=1,e.moveTo(o,r),e.lineTo(s,r),e.stroke(),e.restore()}}class uh extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.HoverSlideGapInsertPoint)}draw(e,n){const{point:o}=this.prop,s=10/n;e.save(),e.fillStyle=Qe,e.globalAlpha=1,e.beginPath(),e.arc(o.x,o.y,s,0,2*Math.PI),e.fill();const r=6/n;e.strokeStyle=Ht,e.lineWidth=2.5/n,e.lineCap="square",e.beginPath(),e.moveTo(o.x-r,o.y),e.lineTo(o.x+r,o.y),e.moveTo(o.x,o.y-r),e.lineTo(o.x,o.y+r),e.stroke(),e.restore()}}class ph extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.SelectSlideGapInsertPoint)}draw(e,n){const{points:o}=this.prop,s=6/n;e.save(),e.fillStyle=Qe,e.globalAlpha=.9,e.beginPath();for(const r of o){e.beginPath(),e.arc(r.x,r.y,s,0,2*Math.PI),e.fill();const i=3.6/n;e.strokeStyle=Ht,e.lineWidth=1.5/n,e.lineCap="square",e.beginPath(),e.moveTo(r.x-i,r.y),e.lineTo(r.x+i,r.y),e.moveTo(r.x,r.y-i),e.lineTo(r.x,r.y+i),e.stroke()}e.restore()}}class vs{static create(t){const e=this.constructorMap[t];return e?new e:(console.error("缺少对应构造函数"),null)}}p(vs,"constructorMap",{[N.HoverBounds]:jr,[N.SingleSelectBound]:Vr,[N.MultiSelectBound]:Kr,[N.HighlightRects]:Qr,[N.SelectGroup]:Zr,[N.TextSelection]:qr,[N.StretchRect]:ei,[N.CreateRectBound]:ti,[N.ExpandShape]:ni,[N.AlignLine]:oi,[N.AlignStretchLine]:si,[N.SelectLineEnd]:Gl,[N.HoverLine]:Ul,[N.SelectLine]:_l,[N.HoverConnectPoint]:$l,[N.HoverConnectAnchorPoint]:jl,[N.HoverAnchorPoint]:Vl,[N.SelectPolyLineControlPoint]:Kl,[N.SelectLineTextRect]:Ql,[N.PlaceHolder]:Zl,[N.SelectConnectAnchor]:ql,[N.HoverConnectAnchor]:Jl,[N.PreviewGraphics]:eh,[N.HoverContainer]:th,[N.CropBounds]:nh,[N.CropOriginImg]:oh,[N.HoverSize]:sh,[N.SelectCurveControlPoint]:rh,[N.SelectCurveEnd]:ih,[N.SelectParentGroupBound]:ah,[N.HoverSlidePlaceHolder]:ch,[N.HoverFocusCopy]:lh,[N.HoverInsertSlide]:hh,[N.HoverInsertHorizonSlide]:dh,[N.HoverSlideGapInsertPoint]:uh,[N.SelectSlideGapInsertPoint]:ph});class ii{constructor(){p(this,"isWorking",!1);p(this,"idList",[]);p(this,"originX",0);p(this,"originY",0)}startWorking(t,e,n){this.idList=t,this.originX=e,this.originY=n,this.isWorking=!0}selectChange(t){if(!this.isWorking)return;t.size!==this.idList.length&&this.stopWork();const e=new Set(this.idList);for(const n of t)e.has(n.id)||this.stopWork(),e.delete(n.id);e.size!==0&&this.stopWork()}stopWork(){this.idList=[],this.isWorking=!1}}class bt{}const fh=new Set([v.Shape,v.SVG,v.IMG,v.Group,v.Section,v.Checkbox,v.CheckboxText]);class ai extends bt{enable(t){return t.length===1&&fh.has(t[0].type)}handle(t,e){const n=t[0],o=n.globalTransform().clone(),{width:s,height:r}=n.baseProps;e.addOrUpdate(N.SingleSelectBound,{x:0,y:0,width:s,height:r,transform:o}),n.parent&&n.parent.type===v.Group&&e.addOrUpdate(N.SelectParentGroupBound,{node:n.parent});const i=D.baseProps2Rect(n.baseProps);if(t.filter(c=>M.judgeNodeCanBeStretch(c)).length>0&&e.addOrUpdate(N.StretchRect,{transform:o,rect:new D(0,0,i.width,i.height)}),n.canQuickCreate()&&e.addOrUpdate(N.SelectConnectAnchor,{node:n}),n instanceof vt&&n.shapeType!==K.PureText){const h=n.drawer.fullTextNodeHeight(n);n.baseProps.height<h&&e.addOrUpdate(N.ExpandShape,{transform:o,rect:i})}}}class ci extends bt{enable(t){return t.length>1}handle(t,e){const n=[],o=[];t.forEach(i=>{const a=i.getBounds();n.push(a),o.push(D.rectNode2Rect(a))});const s=M.getBounds(n),r=D.rectNode2Rect(s);e.addOrUpdate(N.MultiSelectBound,{rect:r}),e.addOrUpdate(N.HighlightRects,{rects:o}),e.addOrUpdate(N.StretchRect,{rect:new D(0,0,r.width,r.height),transform:re.generateMatrix().translate(r.x,r.y)})}}var ze=(l=>(l[l.Scale=0]="Scale",l[l.Focus=1]="Focus",l[l.FocusPropsChange=2]="FocusPropsChange",l[l.ToolChange=3]="ToolChange",l[l.QuickCreate=4]="QuickCreate",l[l.ClickImg=5]="ClickImg",l[l.ImgUrls=6]="ImgUrls",l[l.ContextMenu=7]="ContextMenu",l[l.ExitCrop=8]="ExitCrop",l[l.DocMode=9]="DocMode",l[l.SlideCovers=10]="SlideCovers",l[l.SlideIndex=11]="SlideIndex",l))(ze||{});class li{constructor(){p(this,"slotMap",new Map);p(this,"slotCallBack",new Map);p(this,"working",!1);p(this,"tickerRun",()=>{for(const[t,e]of this.slotMap){const n=this.slotCallBack.get(t);n&&n(e)}this.slotMap.clear(),this.working&&requestAnimationFrame(this.tickerRun)})}start(){this.working=!0,this.tickerRun()}stop(){this.working=!1}reset(){this.slotMap.clear()}addSlotState(t,e){this.slotMap.set(t,e)}registerSlotCallback(t,e){this.slotCallBack.set(t,e)}}class gh extends bt{enable(t){return t.length===1&&t[0].type===v.Line}handle(t,e){const n=t[0],o=n.points,s=n.globalTransform();e.addOrUpdate(N.SelectLineEnd,{start:o[0],end:o[o.length-1],transform:s})}}class yh extends bt{enable(t){if(t.length!==1)return!1;const e=t[0];return e.type!==v.Line?!1:!!e.isPolyLine()}handle(t,e){const n=t[0],o=n.points,s=n.globalTransform();e.addOrUpdate(N.SelectLineEnd,{start:o[0],end:o[o.length-1],transform:s}),e.addOrUpdate(N.SelectPolyLineControlPoint,{points:n.points,transform:s})}}class xh extends bt{enable(t,e){if(t.length!==1)return!1;const n=t[0];if(n.type!==v.Line)return!1;const o=e.inputManager.editTextInfo;if(!o)return!1;const s=n;return o.node.id===s.id}handle(t,e){const n=t[0];e.addOrUpdate(N.SelectLineTextRect,{node:n,transform:n.globalTransform()})}}class wh extends bt{enable(t){return t.length===1&&t[0].type===v.Group}handle(t,e){const n=t[0],o=n.nameGlobalTransform().clone(),{width:s,height:r}=n.baseProps;e.addOrUpdate(N.SingleSelectBound,{x:0,y:0,width:s,height:r,transform:o}),n.parent&&n.parent.type===v.Group&&e.addOrUpdate(N.SelectParentGroupBound,{node:n.parent});const i=D.baseProps2Rect(n.baseProps);e.addOrUpdate(N.StretchRect,{transform:o,rect:new D(0,0,i.width,i.height)})}}const mh=new Set([v.SVG,v.IMG]);class Ph extends bt{enable(t,e){if(t.length!==1)return!1;const n=t[0];return!(!mh.has(n.type)||!e.cropManager.duringCrop||!n.imgBitmap)}handle(t,e){const n=t[0],o=n.globalTransform().clone();e.addOrUpdate(N.CropBounds,{node:n,transform:o});const{cropType:s,cropInfo:r}=n.cropProps,{x:i,y:a,width:c,height:h}=n.baseProps;if(s===0||!r){e.addOrUpdate(N.SingleSelectBound,{x:0,y:0,width:c,height:h,transform:o});const d=new D(0,0,c,h);e.addOrUpdate(N.StretchRect,{transform:o,rect:d})}else{const d=n.getOriginImageRect();e.addOrUpdate(N.SingleSelectBound,{x:d.x,y:d.y,width:d.width,height:d.height,transform:o}),e.addOrUpdate(N.StretchRect,{transform:o,rect:d}),e.addOrUpdate(N.CropOriginImg,{x:d.x,y:d.y,width:d.width,height:d.height,transform:o,imgBitmap:n.imgBitmap})}}}class bh extends bt{enable(t){return t.length===1&&t[0].type===v.Line&&t[0].shapeType===de.Curve}handle(t,e){const n=t[0],o=n.globalTransform();e.addOrUpdate(N.SelectCurveEnd,{points:M.computeCurveEndPoints(n),transform:o}),e.addOrUpdate(N.SelectCurveControlPoint,{points:M.computeCurveControlPoints(n),transform:o})}}const Mh=new Set([v.Shape,v.SVG,v.IMG,v.Group,v.Section,v.Checkbox,v.CheckboxText]);class Sh extends bt{enable(t,e){return!e.docState.userPermission.canEdit&&t.length===1}handle(t,e){const n=t[0];if(n.type===v.Group){this.handleGroup(n,e);return}if(n instanceof Ct){this.handleLine(n,e);return}if(Mh.has(n.type)){this.handleNormalNode(n,e);return}}handleNormalNode(t,e){const n=t.globalTransform().clone(),{width:o,height:s}=t.baseProps;e.addOrUpdate(N.SingleSelectBound,{x:0,y:0,width:o,height:s,transform:n}),t.parent&&t.parent.type===v.Group&&e.addOrUpdate(N.SelectParentGroupBound,{node:t.parent})}handleLine(t,e){e.addOrUpdate(N.SelectLine,{node:t})}handleGroup(t,e){const n=t.nameGlobalTransform().clone(),{width:o,height:s}=t.baseProps;e.addOrUpdate(N.SingleSelectBound,{x:0,y:0,width:o,height:s,transform:n}),t.parent&&t.parent.type===v.Group&&e.addOrUpdate(N.SelectParentGroupBound,{node:t.parent})}}class vh extends bt{enable(t,e){return!e.docState.userPermission.canEdit&&t.length>1}handle(t,e){const n=[],o=[];t.forEach(i=>{const a=i.getBounds();n.push(a),o.push(D.rectNode2Rect(a))});const s=M.getBounds(n),r=D.rectNode2Rect(s);e.addOrUpdate(N.MultiSelectBound,{rect:r}),e.addOrUpdate(N.HighlightRects,{rects:o})}}class Ih extends bt{enable(t){return t.length===1&&t[0].type===v.SlideContainer}handle(t,e){const n=t[0],o=n.globalTransform().clone(),{width:s,height:r}=n.baseProps;e.addOrUpdate(N.SingleSelectBound,{x:0,y:0,width:s,height:r,transform:o}),n.parent&&n.parent.type===v.Group&&e.addOrUpdate(N.SelectParentGroupBound,{node:n.parent})}}const Th=5,nt=50,xt=40;class Lh extends bt{enable(t){var e;return t.length===1&&((e=t[0].parent)==null?void 0:e.type)===v.SlideContainer}handle(t,e){const n=t[0],o=n.globalTransform().clone(),{x:s,y:r,height:i,width:a}=n.globalBaseProps;e.addOrUpdate(N.SingleSelectBound,{x:0,y:0,width:a,height:i,transform:o});const c=[{x:s-nt/2,y:r+i/2},{x:s+a+nt/2,y:r+i/2}];e.addOrUpdate(N.SelectSlideGapInsertPoint,{points:c})}}var he=(l=>(l[l.BOARD=0]="BOARD",l[l.SLIDE_EDIT=1]="SLIDE_EDIT",l[l.SLIDE_PLAY=2]="SLIDE_PLAY",l))(he||{});class Ch extends bt{enable(t,e){var n;return t.length===1&&((n=t[0].parent)==null?void 0:n.type)===v.SlideContainer&&e.docState.docMode===he.SLIDE_EDIT}handle(t,e){const n=t[0],o=n.globalTransform().clone(),{x:s,y:r,height:i,width:a}=n.globalBaseProps;e.addOrUpdate(N.SingleSelectBound,{x:0,y:0,width:a,height:i,transform:o})}}class hi{constructor(t,e,n,o){p(this,"selectNodes",new Set);p(this,"optionHelper");p(this,"auxiliaryManager");p(this,"inputManager");p(this,"cropManager");p(this,"docState");p(this,"statusHandlers",[new Sh,new vh,new Ih,new wh,new xh,new yh,new bh,new gh,new Ph,new Ch,new Lh,new ai,new ci]);this.auxiliaryManager=e,this.optionHelper=new ii,this.cropManager=n,this.docState=o}register(t){this.inputManager=t}reset(){this.selectNodes.clear()}refreshSelectStatus(){this.auxiliaryManager.removeSelectGraphics();const t=[...this.selectNodes],e=this.selectStatusContext();for(const n of this.statusHandlers)if(n.enable(t,e)){n.handle(t,this.auxiliaryManager);return}}selectStatusContext(){return{inputManager:this.inputManager,cropManager:this.cropManager,docState:this.docState}}getSelectNodes(){return[...this.selectNodes]}getSelectBounds(){const t=[];for(const e of this.selectNodes)t.push(e.getBounds());return M.getBounds(t,"selectBounds")}set(t){this.selectNodes=t,this.optionHelper.selectChange(t),this.auxiliaryManager.slotManager.addSlotState(ze.Focus,[...t]),this.auxiliaryManager.slotManager.addSlotState(ze.FocusPropsChange,!0),this.refreshSelectStatus()}startOptWorking(t,e,n){this.optionHelper.startWorking(t,e,n)}include(t){return this.selectNodes.has(t)}}class di{constructor(t,e,n,o){p(this,"gmlRender");p(this,"selectManager");p(this,"graphicMap");p(this,"slotManager");this.gmlRender=t,this.slotManager=e,this.selectManager=new hi(t,this,n,o),this.graphicMap=new Map}start(){}reset(){this.graphicMap.clear(),this.selectManager.reset()}addOrUpdate(t,e){const n=this.graphicMap.get(t);if(n){n.update(e);return}const o=vs.create(t);o&&(this.graphicMap.set(t,o),o.update(e))}remove(t){this.graphicMap.delete(t)}redraw(){const t=this.gmlRender.getViewPortBounds();this.gmlRender.glCtx.clearRect(t.minX,t.minY,t.maxX-t.minX,t.maxY-t.minY);const e=this.gmlRender.getScale(),n=[...this.graphicMap.values()];n.sort((o,s)=>o.auxiliaryType-s.auxiliaryType);for(const o of n)o.draw(this.gmlRender.glCtx,e)}removeHoverGraphics(){this.remove(N.HoverBounds),this.remove(N.HoverLine),this.remove(N.HoverConnectPoint),this.remove(N.HoverConnectAnchorPoint),this.remove(N.HoverAnchorPoint),this.remove(N.HoverConnectAnchor),this.remove(N.PreviewGraphics),this.remove(N.HoverContainer),this.remove(N.HoverSize),this.remove(N.HoverSlidePlaceHolder),this.remove(N.HoverFocusCopy),this.remove(N.HoverInsertSlide),this.remove(N.HoverInsertHorizonSlide),this.remove(N.HoverSlideGapInsertPoint),this.removeAlignGraphics()}removeSelectGraphics(){this.remove(N.SingleSelectBound),this.remove(N.MultiSelectBound),this.remove(N.HighlightRects),this.remove(N.TextSelection),this.remove(N.StretchRect),this.remove(N.ExpandShape),this.remove(N.SelectLineEnd),this.remove(N.SelectLine),this.remove(N.SelectPolyLineControlPoint),this.remove(N.SelectCurveControlPoint),this.remove(N.SelectCurveEnd),this.remove(N.SelectLineTextRect),this.remove(N.SelectConnectAnchor),this.remove(N.CropBounds),this.remove(N.CropOriginImg),this.remove(N.SelectParentGroupBound),this.remove(N.SelectSlideGapInsertPoint)}removeAlignGraphics(){this.remove(N.AlignLine),this.remove(N.AlignStretchLine)}}class Ah{}class Wn extends ct{constructor(){super(...arguments);p(this,"type",I.Svg);p(this,"useCode",!1);p(this,"url","");p(this,"code","")}static from(e){const n=new Wn;return n.url=e.url,n.code=e.code,n.useCode=e.useCode,n}clone(){const e=new Wn;return e.url=this.url,e.code=this.code,e.useCode=this.useCode,e}update(e){const{url:n,code:o,useCode:s}=e;n!==void 0&&(this.url=n),o!==void 0&&(this.code=o),s!==void 0&&(this.useCode=s)}}var wt=(l=>(l[l.None=0]="None",l[l.Rect=1]="Rect",l[l.RoundRect=2]="RoundRect",l[l.Circle=3]="Circle",l))(wt||{});class Sn extends ct{constructor(){super(...arguments);p(this,"type",I.Crop);p(this,"cropType",wt.None);p(this,"cropInfo")}static from(e){const n=new Sn;return n.cropType=e.cropType||wt.None,n.cropInfo=e.cropInfo,n}clone(){const e=new Sn;return e.cropType=this.cropType,this.cropInfo&&(e.cropInfo={imgX:this.cropInfo.imgX,imgY:this.cropInfo.imgY,imgWidth:this.cropInfo.imgWidth,imgHeight:this.cropInfo.imgHeight}),e}update(e){const{cropInfo:n,cropType:o}=e;n!==void 0&&(this.cropInfo=n),o!==void 0&&(this.cropType=o)}}class Qt extends ct{constructor(){super(...arguments);p(this,"type",I.CheckStatus);p(this,"checkStatus",!1)}static create(e){const n=new Qt;return n.update(e),n}static from(e){const n=new Qt;return n.checkStatus=e.checkStatus,n}clone(){const e=new Qt;return e.checkStatus=this.checkStatus,e}update(e){const{checkStatus:n}=e;n!==void 0&&(this.checkStatus=n)}}class vn extends ct{constructor(){super(...arguments);p(this,"type",I.CheckSize);p(this,"size",16)}static create(e){const n=new vn;return n.update(e),n}static from(e){const n=new vn;return n.size=e.size,n}clone(){const e=new vn;return e.size=this.size,e}update(e){const{size:n}=e;n!==void 0&&(this.size=n)}}var me=(l=>(l[l.Decision=0]="Decision",l[l.Step=1]="Step",l[l.Data=2]="Data",l[l.Status=3]="Status",l[l.Operation=4]="Operation",l[l.Others=5]="Others",l[l.Section=6]="Section",l[l.Resource=7]="Resource",l[l.Line=8]="Line",l[l.Check=9]="Check",l))(me||{}),K=(l=>(l[l.PureText=0]="PureText",l[l.Rect=1]="Rect",l[l.Ellipse=2]="Ellipse",l[l.Octagon=3]="Octagon",l[l.DoubleArrow=4]="DoubleArrow",l[l.LeftArrow=5]="LeftArrow",l[l.LeftKuohao=6]="LeftKuohao",l[l.Diamond=7]="Diamond",l[l.Hexagon=8]="Hexagon",l[l.LiuCheng=9]="LiuCheng",l[l.LiuCheng2=10]="LiuCheng2",l[l.Parallelogram=11]="Parallelogram",l[l.Qipao=12]="Qipao",l[l.Qipao2=13]="Qipao2",l[l.RightArrow=14]="RightArrow",l[l.RightKuohao=15]="RightKuohao",l[l.RoundRect=16]="RoundRect",l[l.RoundRect2=17]="RoundRect2",l[l.Cross=18]="Cross",l[l.Trapezoid=19]="Trapezoid",l[l.Triangle=20]="Triangle",l[l.Triangle2=21]="Triangle2",l[l.Pentagon=22]="Pentagon",l[l.Star=23]="Star",l[l.YuanZhu=24]="YuanZhu",l[l.Cloud=25]="Cloud",l))(K||{});const Is={[K.PureText]:me.Operation,[K.Rect]:me.Operation,[K.RoundRect]:me.Step,[K.Triangle]:me.Operation,[K.Diamond]:me.Decision,[K.Ellipse]:me.Status,[K.Parallelogram]:me.Operation,[K.Trapezoid]:me.Step,[K.Cross]:me.Operation,[K.Pentagon]:me.Operation,[K.Hexagon]:me.Decision,[K.Octagon]:me.Operation,[K.Star]:me.Decision};var Zt=(l=>(l[l.TOP_RIGHT=0]="TOP_RIGHT",l[l.TOP_LEFT=1]="TOP_LEFT",l[l.BOTTOM_RIGHT=2]="BOTTOM_RIGHT",l[l.BOTTOM_LEFT=3]="BOTTOM_LEFT",l))(Zt||{});class qt extends ct{constructor(){super(...arguments);p(this,"type",I.TextParagraph);p(this,"paragraphStyles",[])}static create(e){const n=new qt;return n.update(e),n}static from(e){const n=new qt;return n.paragraphStyles=e.paragraphStyles,n}clone(){const e=new qt;return e.paragraphStyles=JSON.parse(JSON.stringify(this.paragraphStyles)),e}update(e){const{paragraphStyles:n}=e;n!==void 0&&(this.paragraphStyles=n)}}class Dt extends ct{constructor(){super(...arguments);p(this,"paraQuoteStyles",[]);p(this,"type",I.TextParagraphQuote)}static create(e){const n=new Dt;return n.update(e),n}static from(e){const n=new Dt;return n.paraQuoteStyles=e.paraQuoteStyles,n}clone(){const e=new Dt;return e.paraQuoteStyles=JSON.parse(JSON.stringify(this.paraQuoteStyles)),e}update(e){const{paraQuoteStyles:n}=e;n!==void 0&&(this.paraQuoteStyles=n)}}var de=(l=>(l[l.Line=0]="Line",l[l.PolyLine=1]="PolyLine",l[l.RoundPolyLine=2]="RoundPolyLine",l[l.Curve=3]="Curve",l))(de||{});class ui{constructor(t,e,n,o){p(this,"p0");p(this,"p1");p(this,"p2");p(this,"p3");this.p0=t,this.p1=e,this.p2=n,this.p3=o}getPos(t){if(t<0||t>1)throw new Error(`非法的t值:${t}`);const e=1-t,n=e*e*e*this.p0.x+3*t*e*e*this.p1.x+3*t*t*e*this.p2.x+t*t*t*this.p3.x,o=e*e*e*this.p0.y+3*t*e*e*this.p1.y+3*t*t*e*this.p2.y+t*t*t*this.p3.y;return new m(n,o)}getHalfTPos(){return this.getPos(.5)}getDerivative(t){const e=1-t,n=3*e*e*(this.p1.x-this.p0.x)+6*e*t*(this.p2.x-this.p1.x)+3*t*t*(this.p3.x-this.p2.x),o=3*e*e*(this.p1.y-this.p0.y)+6*e*t*(this.p2.y-this.p1.y)+3*t*t*(this.p3.y-this.p2.y);return new m(n,o)}getDistanceSquared(t,e){const n=this.getPos(e),o=n.x-t.x,s=n.y-t.y;return o*o+s*s}getTValueByPoint(t,e=1,n=50){let o=0,s=1/0;const r=20;for(let a=0;a<=r;a++){const c=a/r,h=this.getDistanceSquared(t,c);h<s&&(s=h,o=c)}if(Math.sqrt(s)<e)return o;let i=o;for(let a=0;a<n;a++){const c=this.getPos(i),h=this.getDerivative(i),d=c.x-t.x,u=c.y-t.y,f=d*h.x+u*h.y;if(Math.abs(f)<e)return Math.max(0,Math.min(1,i));const g=1-i,y=6*g*(this.p2.x-2*this.p1.x+this.p0.x)+6*i*(this.p3.x-2*this.p2.x+this.p1.x),P=6*g*(this.p2.y-2*this.p1.y+this.p0.y)+6*i*(this.p3.y-2*this.p2.y+this.p1.y),b=h.x*h.x+h.y*h.y+d*y+u*P;if(Math.abs(b)<1e-10)break;const w=i-f/b;if(i=Math.max(0,Math.min(1,w)),Math.abs(w-i)<e&&i===w)break}return i}getApproximateLength(t=10){let e=0,n=this.getPos(0);for(let o=1;o<=t;o++){const s=o/t,r=this.getPos(s),i=r.x-n.x,a=r.y-n.y;e+=Math.sqrt(i*i+a*a),n=r}return e}getTValueByDistance(t,e=20){if(t<=0)return 0;let n=0,o=this.getPos(0);for(let s=1;s<=e;s++){const r=s/e,i=this.getPos(r),a=i.x-o.x,c=i.y-o.y,h=Math.sqrt(a*a+c*c);if(n+h>=t){const u=(t-n)/h,f=(s-1)/e;return f+u*(r-f)}n+=h,o=i}return 1}}var Jt=(l=>(l.Windows="Windows",l.MacOS="MacOS",l.Linux="Linux",l.Android="Android",l.IOS="ios",l.Unknown="unknown",l))(Jt||{});class pi{static getOS(){const t=navigator.userAgent;return t.includes("Win")?Jt.Windows:t.includes("Mac")?Jt.MacOS:t.includes("Linux")?Jt.Linux:/Android/.test(t)?Jt.Android:/iPhone|iPad|iPod/.test(t)?Jt.IOS:Jt.Unknown}}class Mt extends ct{constructor(){super(...arguments);p(this,"type",I.Slide);p(this,"children",[])}static create(e){const n=new Mt;return n.update(e),n}static from(e){const n=new Mt;return n.children=e.children,n}clone(){const e=new Mt;return e.children=this.children,e}update(e){const{children:n}=e;n!==void 0&&(this.children=n)}}class M{static computeShapeCategory(t,e=0){return t===v.Shape?Is[e]??me.Others:t===v.CheckboxText||t===v.Checkbox?me.Check:t===v.Line?me.Line:t===v.Section?me.Section:t===v.SVG?me.Resource:me.Others}static makeSortGraphic(t){const e=[t];let n=t.parent;for(;n&&n.id!==Mn;)e.unshift(n),n=n.parent;return{graphics:e}}static sortGraphics(t){const e=t.map(this.makeSortGraphic);return e.sort((n,o)=>{const s=Math.min(n.graphics.length,o.graphics.length);for(let r=0;r<s;r++){const i=n.graphics[r],a=o.graphics[r];if(i!==a)return i.zIndex>a.zIndex?1:-1}return n.graphics.length-o.graphics.length}),e.map(n=>n.graphics[n.graphics.length-1])}static setDashLine(t,e){t.dashType===et.Dash1?e.setLineDash([4,2]):t.dashType===et.Dash2&&e.setLineDash([2,2])}static convertPropsToCapInfo(t){const e={},n=t.get(I.Base);n&&(e.baseProps=n);const o=t.get(I.Color);o&&(e.colorProps=o);const s=t.get(I.Border);s&&(e.borderProps=s);const r=t.get(I.Text);r&&(e.textProps=r);const i=t.get(I.Shape);i&&(e.shapeProps=i);const a=t.get(I.Line);a&&(e.lineProps=a);const c=t.get(I.Connect);c&&(e.connectProps=c);const h=t.get(I.Arrow);h&&(e.arrowProps=h);const d=t.get(I.LineTextRect);d&&(e.lineTextRectProps=d);const u=t.get(I.Svg);u&&(e.svgProps=u);const f=t.get(I.Image);f&&(e.imageProps=f);const g=t.get(I.Crop);g&&(e.cropProps=g);const y=t.get(I.CheckStatus);y&&(e.checkStatusProps=y);const P=t.get(I.CheckSize);y&&(e.checkSizeProps=P);const b=t.get(I.TextParagraph);b&&(e.textParagraphProps=b);const w=t.get(I.TextParagraphQuote);w&&(e.textParagraphQuoteProps=w);const L=t.get(I.Slide);return L&&(e.slideProps=L),e}static convertCapInfoToProps(t){const e=[],{baseProps:n,borderProps:o,shapeProps:s,colorProps:r,textProps:i,lineProps:a,connectProps:c,arrowProps:h,lineTextRectProps:d,svgProps:u,imageProps:f,cropProps:g,checkStatusProps:y,checkSizeProps:P,textParagraphProps:b,textParagraphQuoteProps:w,slideProps:L}=t;return o&&e.push(Ae.from(o)),r&&e.push(tt.from(r)),i&&e.push(Ge.from(i)),n&&e.push(ie.from(n)),s&&e.push(Oe.from(s)),a&&e.push(je.from(a)),c&&e.push(Rt.from(c)),h&&e.push(lt.from(h)),d&&e.push(Et.from(d)),u&&e.push(Wn.from(u)),f&&e.push(ro.from(f)),g&&e.push(Sn.from(g)),y&&e.push(Qt.from(y)),P&&e.push(vn.from(P)),b&&e.push(qt.from(b)),w&&e.push(Dt.from(w)),L&&e.push(Mt.from(L)),e}static centerPoint(t){const e=t.baseProps;return new m(e.x+.5*e.width,e.y+.5*e.height)}static topPoint(t){const e=t.baseProps;return new m(e.x+.5*e.width,e.y)}static rightPoint(t){const e=t.baseProps;return new m(e.x+e.width,e.y+.5*e.height)}static bottomPoint(t){const e=t.baseProps;return new m(e.x+.5*e.width,e.y+e.height)}static leftPoint(t){const e=t.baseProps;return new m(e.x,e.y+.5*e.height)}static topLeft(t){const e=t.baseProps;return new m(e.x,e.y)}static topRight(t){const e=t.baseProps;return new m(e.x+e.width,e.x+e.width)}static bottomLeft(t){const e=t.baseProps;return new m(e.x,e.y+e.height)}static bottomRight(t){const e=t.baseProps;return new m(e.x+e.width,e.y+e.height)}static middleInsertPoint(t,e,n){const o=new m(t.x,e.y);n.push(t,o,e)}static doubleMiddleInsertPoint(t,e,n){const o=new m(.5*(t.x+e.x),t.y),s=new m(.5*(t.x+e.x),e.y);n.push(t,o,s,e)}static rectContains(t,e){return t.x>e.x&&t.x<e.x+e.width&&t.y>e.y&&t.y<e.y+e.height}static rectContains2(t,e){return t.x>=e.minX&&t.x<=e.maxX&&t.y>=e.minY&&t.y<=e.maxY}static circleContains(t,e,n=2){return(t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y)<n*n}static overlapRect(t,e){return!(t.maxX<e.minX||t.minX>e.maxX||t.maxY<e.minY||t.minY>e.maxY)}static containRect(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&t.maxX>=e.maxX&&t.maxY>=e.maxY}static distance(t,e){return Math.sqrt((t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y))}static lineAngle(t,e){if(Math.abs(t.x-e.x)<.001)return e.y>t.y?Math.PI*.5:-Math.PI*.5;const n=(e.y-t.y)/(e.x-t.x);let o=Math.atan(n);return e.x<t.x&&(o+=Math.PI),o}static basicGetArrowPoint(t,e,n,o){const s=M.lineAngle(t,e),r=re.generateMatrix().translate(t.x,t.y).rotate2(s),i=r.crossPoint(n),a=r.crossPoint(o);return{a:i,b:a}}static getLArrowPoint(t,e,n=5){const o=new m(Math.sqrt(3)*.5*n,.5*n),s=new m(Math.sqrt(3)*.5*n,-.5*n);return M.basicGetArrowPoint(t,e,o,s)}static getRArrowPoint(t,e,n=5){const o=M.distance(t,e),s=new m(o-Math.sqrt(3)*.5*n,.5*n),r=new m(o-Math.sqrt(3)*.5*n,-.5*n);return M.basicGetArrowPoint(t,e,s,r)}static getNodeBounds(t){const e=[];t.forEach(o=>e.push(o.getBounds()));const n=this.getBounds(e);return D.rectNode2Rect(n)}static cloneIRectNode(t){return{minX:t.minX,maxX:t.maxX,minY:t.minY,maxY:t.maxY}}static cloneIPoint(t){return{x:t.x,y:t.y}}static getBoundsByBaseProps(t){const{x:e,y:n,width:o,height:s,angle:r}=t,i=re.generateMatrix().rotate(r),a=re.generateMatrix().translate(e,n),c=[new m(0,0),new m(0,s),new m(o,0),new m(o,s)],h=a.crossProduct(i),d=c.map(u=>h.crossPoint(u));return this.getBoundsByPoints(d)}static getBoundsByBasePropsList(t){const e=[];for(const n of t){const{x:o,y:s,width:r,height:i}=n,a=n.angle??0,c=re.generateMatrix().rotate(a),d=re.generateMatrix().translate(o,s).crossProduct(c),f=[new m(0,0),new m(0,i),new m(r,0),new m(r,i)].map(g=>d.crossPoint(g));e.push(...f)}return this.getBoundsByPoints(e)}static getBounds(t,e="getBounds"){const n=[],o=[];for(const s of t)n.push(s.maxX,s.minX),o.push(s.maxY,s.minY);return{id:e,minX:Math.min(...n),maxX:Math.max(...n),minY:Math.min(...o),maxY:Math.max(...o)}}static getBoundsByPoints(t){const e=[],n=[];for(const o of t)e.push(o.x),n.push(o.y);return{id:"getBounds",minX:Math.min(...e),maxX:Math.max(...e),minY:Math.min(...n),maxY:Math.max(...n)}}static calcFont(t,e,n=!1,o=!1){let s=`${t.toString()}px ${e}`;return n?s=`700 ${s}`:s=`400 ${s}`,o&&(s=`italic ${s}`),s}static calcFontByTextProps(t){const{fontSize:e,fontFamily:n,bold:o,italic:s}=t;return this.calcFont(e,n,o,s)}static measureText(t,e){const n=t.measureText(e),o=n.width,s=n.fontBoundingBoxDescent+n.fontBoundingBoxAscent,r=n.fontBoundingBoxAscent;return{width:o,height:s,boxAscent:r}}static measureTextByFont(t,e,n,o,s,r){t.save(),t.font=this.calcFont(n,o,s,r);const i=t.measureText(e);t.restore();const a=i.width,c=i.fontBoundingBoxDescent+i.fontBoundingBoxAscent,h=i.fontBoundingBoxAscent;return{width:a,height:c,boxAscent:h}}static judgeHorizon(t,e,n=.01){return Math.abs(t.y-e.y)<n}static judgeVertical(t,e,n=.01){return Math.abs(t.x-e.x)<n}static computePolyLinePoints(t,e){const n=[],o=new m(e.x-t.x,e.y-t.y);if(Math.abs(o.x)<.001||Math.abs(o.y)<.001)n.push(t,e);else if(Math.abs(o.x)>Math.abs(o.y)){const s=new m(t.x+.5*o.x,t.y),r=new m(e.x-.5*o.x,e.y);n.push(t,s,r,e)}else{const s=new m(t.x,t.y+.5*o.y),r=new m(e.x,e.y-.5*o.y);n.push(t,s,r,e)}return n}static normalizeAngle(t){let e=t%360;return e<0&&(e+=360),e}static computeOriginNodeConnectEnd(t){const{x:e,y:n}=t,o=Math.atan2(n-.5,e-.5)/Math.PI*180,s=this.normalizeAngle(o);if(s<45||s>315)return ue.Right;if(Math.abs(s-90)<45)return ue.Bottom;if(Math.abs(s-180)<45)return ue.Left;if(Math.abs(s-270)<45)return ue.Top;throw new Error("没有正确的end type")}static computeNodeConnectEnd(t,e){const{x:n,y:o}=t,s=Math.atan2(o-.5,n-.5)/Math.PI*180+e,r=this.normalizeAngle(s);if(r<45||r>315)return ue.Right;if(Math.abs(r-90)<45)return ue.Bottom;if(Math.abs(r-180)<45)return ue.Left;if(Math.abs(r-270)<45)return ue.Top;throw new Error("没有正确的end type")}static inDistance(t,e,n){return Math.abs(t-e-.5*n)<.5*n}static dealWithEndPolyPointsInUp(t,e,n){if(t.length<4)return t;const o=t.length;if(n){const a=t[o-1],c=t[o-2],h=t[o-3];return M.distance(c,h)<3/e&&(M.judgeHorizon(a,c)?a.y=h.y:a.x=h.x,t.splice(o-3,2)),t}const s=t[0],r=t[1],i=t[2];return M.distance(i,r)<3/e&&(M.judgeHorizon(s,r)?s.y=i.y:s.x=i.x,t.splice(1,2)),t}static dealWithEndPolyPoints(t,e,n){if(t.length<4)return t;const o=t.length;if(n){const a=t[o-1],c=t[o-2],h=t[o-3];return M.distance(c,h)<3/e&&(M.judgeHorizon(a,c)?(c.y=h.y,a.y=h.y):(c.x=h.x,a.x=h.x)),t}const s=t[0],r=t[1],i=t[2];return M.distance(i,r)<3/e&&(M.judgeHorizon(s,r)?(r.y=i.y,s.y=i.y):(r.x=i.x,s.x=i.x)),t}static dealWithPolyPoints(t,e){if(t.length===0)return[];const n=[t[0]];for(let o=1;o<t.length-1;o++){const s=t[o],r=t[o+1];if(M.distance(s,r)<3/e){const i=t[o+2],a=t[o-1];M.judgeHorizon(a,s)?a.y=i.y:a.x=i.x,o=o+1}else n.push(s)}return n.push(t[t.length-1]),n}static computePointByT(t,e){const n=t.points;if(t.isPolyLine()){let a=0;for(let h=0;h<n.length-1;h++){const d=n[h],u=n[h+1],f=M.distance(d,u);a+=f}const c=e*a;a=0;for(let h=0;h<n.length-1;h++){const d=n[h],u=n[h+1],f=M.distance(d,u);if(c>a&&c<=a+f)if(M.judgeHorizon(d,u)){const y=u.x>d.x?1:-1;return new m(d.x+(c-a)*y,d.y)}else{const y=u.y>d.y?1:-1;return new m(d.x,d.y+(c-a)*y)}a+=f}}else if(t.shapeType===de.Curve){const a=M.computeBezierCurves(t);let c=0;const h=[];for(const u of a){const f=u.getApproximateLength();c+=f,h.push(f)}c=e*c;for(let u=0;u<a.length;u++){const f=a[u],g=h[u];if(c>g){c-=g;continue}const y=f.getTValueByDistance(c);return f.getPos(y)}}const o=n[0],s=n[n.length-1],r=o.x+(s.x-o.x)*e,i=o.y+(s.y-o.y)*e;return new m(r,i)}static computeNodeConnectAnchor(t,e){const{width:n,height:o}=t.baseProps,s=Yr/e;return[{x:.5*n,y:-s},{x:n+s,y:.5*o},{x:.5*n,y:o+s},{x:-s,y:.5*o}]}static computeSelectNode(t,e){const n=new Set(t.getSelectNodes());let o=e.parent;for(;o;)n.has(o)&&n.delete(o),o=o.parent;return this.filterChildInSet(n,e),n.add(e),n}static filterChildInSet(t,e){const n=e.children;if(n.size!==0)for(const o of n)t.has(o)&&t.delete(o),this.filterChildInSet(t,o)}static computeSelectNodes(t){const e=new Set(t);for(const n of t)this.filterChildInSet(e,n);return[...e]}static filterToGroupNodes(t){const e=[];for(const n of t)if(n.type!==v.Section){if(n.type===v.Line){const o=n,{start:s,end:r}=o.connectProps;if(s&&r){const i=t.find(c=>c.id===s.objectId),a=t.find(c=>c.id===r.objectId);i&&a&&e.push(n);continue}if(s&&!r){t.find(a=>a.id===s.objectId)&&e.push(n);continue}if(r&&!s){t.find(a=>a.id===r.objectId)&&e.push(n);continue}e.push(n);continue}e.push(n)}return e}static detectRectBounds(t,e,n){const{x:o,y:s,width:r,height:i}=t;return M.circleContains(new m(o,s),e,n)?{type:V.TOP_LEFT}:M.circleContains(new m(o+r,s),e,n)?{type:V.TOP_RIGHT}:M.circleContains(new m(o+r,s+i),e,n)?{type:V.BOTTOM_RIGHT}:M.circleContains(new m(o,s+i),e,n)?{type:V.BOTTOM_LEFT}:M.rectContains(e,new D(o,s-.5*n,r,n))?{type:V.TOP}:M.rectContains(e,new D(o+r-.5*n,s,n,i))?{type:V.RIGHT}:M.rectContains(e,new D(o,s+i-.5*n,r,n))?{type:V.BOTTOM}:M.rectContains(e,new D(o-.5*n,s,n,i))?{type:V.LEFT}:null}static computeShiftPoint(t,e){if(M.distance(t,e)<.1)return new m(e.x,t.y);let n=Math.atan2(e.y-t.y,e.x-t.x)*180/Math.PI;return n=(n+360)%360,n<45||n>=315?new m(e.x,t.y):n>45&&n<=135?new m(t.x,e.y):n>135&&n<225?new m(e.x,t.y):new m(t.x,e.y)}static dealWithShiftLineInteractEvent(t,e,n=!0){if(!t.originEvent.shiftKey)return t;const o=e.globalLinePoints,s=n?o[0]:o[o.length-1],r=M.computeShiftPoint(s,t.globalPoint);return{clientPoint:t.clientPoint,globalPoint:r,type:t.type,originEvent:t.originEvent}}static getMockEventModifierInit(t){return{shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,ctrlKey:t.ctrlKey}}static judgeParentInset(t,e){let n=t;for(;n;){if(e.has(n))return!0;n=n.parent}return!1}static judgeSlideSectionChildren(t,e){let n=t;for(;n!=null&&n.parent;){if(n.parent.id===e.id)return n;n=n.parent}return null}static filterContainerFromNodes(t){const e=t.filter(o=>o.type===v.Section);return new Set(e)}static judgeEndNode(t,e,n,o,s){if(!n)return;const r=o.nodeManager.getNode(n.objectId);r&&!M.judgeParentInset(r,s)&&e.add(t)}static getViewportBoundCenter(t){const e=t.renderManager.gmlRender.getViewPortBounds();return new m(.5*(e.minX+e.maxX),.5*(e.minY+e.maxY))}static computeRotateAngle(t,e){let n=0;return t.length===1&&(n=n+t[0].baseProps.angle),n=n+e,Math.round(n)}static computeRotateDeltaAngle(t){let e=0;switch(t){case Zt.BOTTOM_LEFT:e=90;break;case Zt.BOTTOM_RIGHT:e=0;break;case Zt.TOP_LEFT:e=180;break;case Zt.TOP_RIGHT:e=-90;break}return e}static computeRelationChangeUpdateNodeInfo(t,e,n,o){if(t.type===v.Line){const i=t.globalLinePoints.map(c=>e.toLocal(c)),a=D.rectNode2Rect(M.getBoundsByPoints(i));return{id:t.id,props:[{type:I.Line,points:i},ie.create({x:a.x,y:a.y,width:a.width,height:a.height})],zIndex:n,parentId:o}}const s=e.toLocal(t.globalPos);return{id:t.id,zIndex:n,parentId:o,props:[{type:I.Base,x:s.x,y:s.y}]}}static computeStretchAngle(t,e){let n=0;return t.length===1&&(n=n+t[0].baseProps.angle),e===V.TOP_RIGHT||e===V.BOTTOM_LEFT?n=n-45:e===V.TOP_LEFT||e===V.BOTTOM_RIGHT?n=n+45:(e===V.TOP||e===V.BOTTOM)&&(n=n+90),Math.round(n)}static correctZIndex(t){if(t.length===0)return t;const e=new Map;if(t.forEach((s,r)=>{const i=s.zIndex;e.has(i)||e.set(i,[]),e.get(i).push(r)}),!Array.from(e.values()).some(s=>s.length>1))return t;const o=t.map(s=>({...s}));return e.forEach((s,r)=>{if(s.length>1){const i=s[0];let a=.1,c=0;i===0?(c=r-1,a=(r-c)/(s.length+1)):(c=o[i-1].zIndex<r?o[i-1].zIndex:r-1,a=(r-c)/(s.length+1)),s.forEach((h,d)=>{o[h].zIndex=(d+1)*a+c})}}),o}static judgeLineBreak(t,e,n,o){let s=-1;for(const r of t){const i=e.characters.slice(0,r);let a=0;if(i.forEach(c=>{a+=c.width}),n.width+a<o)s=r;else return s>0?s:-1}return s>-1?s:-1}static getParaStyle(t,e){const n=t.paragraphStyles;for(const o of n)if(o.paraIndex===e)return o;return null}static computeNotUnOrderParas(t){const n=t.paragraphProps.paragraphStyles,o=new Set;for(let s=0;s<t.paragraphs.length;s++)o.add(s);for(const s of n)s.orderIndex===-1&&o.delete(s.paraIndex);return o}static computeNotOrderParas(t){const n=t.paragraphProps.paragraphStyles,o=new Set;for(let s=0;s<t.paragraphs.length;s++)o.add(s);for(const s of n)s.orderIndex>-1&&o.delete(s.paraIndex);return o}static computeNotNormalParas(t){const n=t.paragraphProps.paragraphStyles,o=new Set;for(const s of n)o.add(s.paraIndex);return o}static computeNotQuoteParas(t){const n=t.paragraphQuoteProps.paraQuoteStyles,o=new Set;for(let s=0;s<t.paragraphs.length;s++)o.add(s);for(const s of n)s.quote&&o.delete(s.paraIndex);return o}static drawControlPoints(t,e){t.save(),t.beginPath(),t.strokeStyle="#cc2626",t.lineWidth=1;const n=e.globalLinePoints;t.moveTo(n[0].x,n[0].y);for(let o=1;o<n.length;o++){const s=n[o];t.lineTo(s.x,s.y)}t.stroke(),t.fillStyle="#000000";for(let o=1;o<n.length-2;o=o+3){const s=n[o],r=n[o+1];t.beginPath(),t.arc(s.x,s.y,5,0,2*Math.PI),t.fill(),t.stroke(),t.beginPath(),t.arc(r.x,r.y,5,0,2*Math.PI),t.fill(),t.stroke()}t.restore()}static computeBezierCurves(t){if(t.shapeType!==de.Curve)return[];const e=t.points,n=[];for(let o=1;o<e.length-2;o=o+3){const s=e[o-1],r=e[o],i=e[o+1],a=e[o+2],c=new ui(s,r,i,a);n.push(c)}return n}static computeBezierCurvesByPoints(t){const e=[];for(let n=1;n<t.length-2;n=n+3){const o=t[n-1],s=t[n],r=t[n+1],i=t[n+2],a=new ui(o,s,r,i);e.push(a)}return e}static computeCurveControlPoints(t){const e=this.computeBezierCurves(t),n=[];for(const o of e)n.push(o.getHalfTPos());return n}static computeCurveEndPoints(t){if(t.shapeType!==de.Curve)return[];const e=t.points,n=[];for(let o=1;o<e.length-2;o=o+3){const s=e[o-1],r=e[o+2];n.push(s),n.push(r)}return n}static pressMeta(t){return pi.getOS()===Jt.MacOS?t.originEvent.metaKey:t.originEvent.ctrlKey}static getAllChildren(t,e){const n=t.children;for(const o of n)e.add(o),this.getAllChildren(o,e)}static judgeNodeCanBeStretch(t){var e;return!(t.type===v.SlideContainer||t.type===v.Section&&((e=t.parent)==null?void 0:e.type)===v.SlideContainer)}static getSlideContainerChildNode(t,e,n){const o=t.getChildIdByIndex(e);if(!o)return null;const s=n.nodeManager.getNode(o);return s||null}static filterSlideContainerNodes(t,e){const n=t.docState.docMode,o=t.docState.slideStatus,s=o.slideContainer;if(n===he.SLIDE_EDIT&&s){const r=this.getSlideContainerChildNode(s,o.currentIndex,t);if(!r)return e;const i=new Set;M.getAllChildren(r,i);const a=[];for(const c of e)i.has(c)&&a.push(c);return a}return e}static getSlideInfo(t,{renderManager:e,nodeManager:n}){return new Promise((o,s)=>{const r=t.getBounds(),i=r.maxX-r.minX,a=r.maxY-r.minY,c=new Set([t]);M.getAllChildren(t,c),e.exportWorker.exportToOfflineCanvasByFilterNodes(r,n,1,"",c).toBlob(d=>{if(d){const u=URL.createObjectURL(d),f={id:t.id,blobUrl:u,width:i,height:a};o(f)}else console.error("导出图片错误"),s("导出图片错误")})})}}class en{constructor(t,e){p(this,"type",v.Shape);p(this,"id");p(this,"parent",null);p(this,"children",new Set);p(this,"zIndex",0);p(this,"graphicContext");p(this,"props",new Map);p(this,"transform",re.generateMatrix());this.id=t,this.graphicContext=e}get baseProps(){return this.props.get(I.Base)}get globalBaseProps(){const t=this.baseProps.clone(),e=this.globalPos;return t.x=e.x,t.y=e.y,t}get pos(){const t=this.baseProps;return new m(t.x,t.y)}get globalPos(){return this.globalTransform().crossPoint(new m)}setParent(t){this.parent=t,t.children.add(this)}updateProps(t){for(const e of t){if(e.type===void 0)continue;const n=this.props.get(e.type);n&&n.update(e)}}getProp(t){const e=this.props.get(t);return e||null}updateTransformMatrix(){const t=this.baseProps,e=re.generateMatrix().rotate(t.angle),n=re.generateMatrix().translate(t.x,t.y);this.transform=n.crossProduct(e)}contains(t,e=1){const{width:n,height:o}=this.baseProps,s=this.toLocal(t);return M.rectContains(s,new D(0,0,n,o))}canQuickCreate(){return!!this.canBeConnected()}canBeConnected(){return!0}getConnectAnchor(){return[]}borderContains(t,e){return null}draw(){return this.drawOnGLCtx(this.graphicContext)}globalTransform(){const t=[this];let e=this.parent;for(;e;)t.push(e),e=e.parent;let n=re.generateMatrix();for(const o of t.reverse())n=n.crossProduct(o.transform);return n}getRectNode(){const{width:t,height:e}=this.baseProps,n=this.getProp(I.Border),o=n?n.width:0,s=[new m(-o,-o),new m(t+o,-o),new m(t+o,e+o),new m(-o,e+o)],r=[];for(const a of s)r.push(this.toGlobal(a));const i=M.getBoundsByPoints(r);return i.id=this.id,i}getBounds(){const t=this.baseProps,e={id:this.id,minX:0,minY:0,maxX:t.width,maxY:t.height},n=[new m(e.minX,e.minY),new m(e.maxX,e.minY),new m(e.maxX,e.maxY),new m(e.minX,e.maxY)],o=[];for(const r of n)o.push(this.toGlobal(r));const s=M.getBoundsByPoints(o);return s.id=this.id,s}getStretchMinSize(){return{x:10,y:10}}overlapRect(t){return M.overlapRect(t,this.getBounds())}isEmptyText(){return!0}toLocal(t){return this.globalTransform().inverseMatrix().crossPoint(t)}toGlobal(t){return this.globalTransform().crossPoint(t)}modifyPosInEditing(t){return!1}resetFromEditing(){}serializeTo(){const t=M.convertPropsToCapInfo(this.props),e=JSON.parse(JSON.stringify(t));return{type:this.type,zIndex:this.zIndex,id:this.id,parentId:"",capInfo:e,children:[]}}}class kh{fallbackDraw(t,e){const{width:n,height:o}=t.baseProps;e.save();const{a:s,b:r,c:i,d:a,e:c,f:h}=t.globalTransform();e.transform(s,r,i,a,c,h),e.beginPath();let d=!1;const u=n/3,f=o/3;for(let g=0;g<3;g++)for(let y=0;y<3;y++){const P=d?Ht:bs,b=u*g,w=f*y;e.fillStyle=P,e.fillRect(b,w,u,f),d=!d}e.restore()}}class ge{constructor(t=0,e=0){this.x=t,this.y=e}clone(){return new this.constructor(this.x,this.y)}add(t){return new this.constructor(this.x+t.x,this.y+t.y)}subtract(t){return new this.constructor(this.x-t.x,this.y-t.y)}multiply(t){return new this.constructor(this.x*t,this.y*t)}divide(t){return new this.constructor(this.x/t,this.y/t)}equals(t){return this.x===t.x&&this.y===t.y}precisionEquals(t,e){return Math.abs(this.x-t.x)<e&&Math.abs(this.y-t.y)<e}lerp(t,e){const n=1-e;return new this.constructor(this.x*n+t.x*e,this.y*n+t.y*e)}distanceFrom(t){const e=this.x-t.x,n=this.y-t.y;return Math.sqrt(e*e+n*n)}min(t){return new this.constructor(Math.min(this.x,t.x),Math.min(this.y,t.y))}max(t){return new this.constructor(Math.max(this.x,t.x),Math.max(this.y,t.y))}transform(t){return new this.constructor(t.a*this.x+t.c*this.y+t.e,t.b*this.x+t.d*this.y+t.f)}toString(){return`point(${this.x},${this.y})`}}class rt{constructor(t=0,e=0){this.x=t,this.y=e}static fromPoints(t,e){return new rt(e.x-t.x,e.y-t.y)}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}magnitude(){return this.x*this.x+this.y*this.y}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}determinant(t){return this.x*t.y-this.y*t.x}unit(){return this.divide(this.length())}add(t){return new this.constructor(this.x+t.x,this.y+t.y)}subtract(t){return new this.constructor(this.x-t.x,this.y-t.y)}multiply(t){return new this.constructor(this.x*t,this.y*t)}divide(t){return new this.constructor(this.x/t,this.y/t)}angleBetween(t){let e=this.dot(t)/(this.length()*t.length());e=Math.max(-1,Math.min(e,1));const n=Math.acos(e);return this.cross(t)<0?-n:n}perp(){return new this.constructor(-this.y,this.x)}perpendicular(t){return this.subtract(this.project(t))}project(t){const e=this.dot(t)/t.dot(t);return t.multiply(e)}transform(t){return new this.constructor(t.a*this.x+t.c*this.y,t.b*this.x+t.d*this.y)}equals(t){return this.x===t.x&&this.y===t.y}precisionEquals(t,e){return Math.abs(this.x-t.x)<e&&Math.abs(this.y-t.y)<e}toString(){return`vector(${this.x},${this.y})`}}class pt{constructor(t=1,e=0,n=0,o=1,s=0,r=0){this.a=t,this.b=e,this.c=n,this.d=o,this.e=s,this.f=r}static translation(t,e){return new pt(1,0,0,1,t,e)}static scaling(t){return new pt(t,0,0,t,0,0)}static scalingAt(t,e){return new pt(t,0,0,t,e.x-e.x*t,e.y-e.y*t)}static nonUniformScaling(t,e){return new pt(t,0,0,e,0,0)}static nonUniformScalingAt(t,e,n){return new pt(t,0,0,e,n.x-n.x*t,n.y-n.y*e)}static rotation(t){const e=Math.cos(t),n=Math.sin(t);return new pt(e,n,-n,e,0,0)}static rotationAt(t,e){const n=Math.cos(t),o=Math.sin(t);return new pt(n,o,-o,n,e.x-e.x*n+e.y*o,e.y-e.y*n-e.x*o)}static rotationFromVector(t){const e=t.unit(),n=e.x,o=e.y;return new pt(n,o,-o,n,0,0)}static xFlip(){return new pt(-1,0,0,1,0,0)}static yFlip(){return new pt(1,0,0,-1,0,0)}static xSkew(t){const e=Math.tan(t);return new pt(1,0,e,1,0,0)}static ySkew(t){const e=Math.tan(t);return new pt(1,e,0,1,0,0)}multiply(t){return this.isIdentity()?t:t.isIdentity()?this:new this.constructor(this.a*t.a+this.c*t.b,this.b*t.a+this.d*t.b,this.a*t.c+this.c*t.d,this.b*t.c+this.d*t.d,this.a*t.e+this.c*t.f+this.e,this.b*t.e+this.d*t.f+this.f)}inverse(){if(this.isIdentity())return this;const t=this.a*this.d-this.b*this.c;if(t===0)throw new Error("Matrix is not invertible");const e=1/t,n=this.f*this.c-this.e*this.d,o=this.e*this.b-this.f*this.a;return new this.constructor(this.d*e,-this.b*e,-this.c*e,this.a*e,n*e,o*e)}translate(t,e){return new this.constructor(this.a,this.b,this.c,this.d,this.a*t+this.c*e+this.e,this.b*t+this.d*e+this.f)}scale(t){return new this.constructor(this.a*t,this.b*t,this.c*t,this.d*t,this.e,this.f)}scaleAt(t,e){const n=e.x-t*e.x,o=e.y-t*e.y;return new this.constructor(this.a*t,this.b*t,this.c*t,this.d*t,this.a*n+this.c*o+this.e,this.b*n+this.d*o+this.f)}scaleNonUniform(t,e){return new this.constructor(this.a*t,this.b*t,this.c*e,this.d*e,this.e,this.f)}scaleNonUniformAt(t,e,n){const o=n.x-t*n.x,s=n.y-e*n.y;return new this.constructor(this.a*t,this.b*t,this.c*e,this.d*e,this.a*o+this.c*s+this.e,this.b*o+this.d*s+this.f)}rotate(t){const e=Math.cos(t),n=Math.sin(t);return new this.constructor(this.a*e+this.c*n,this.b*e+this.d*n,this.a*-n+this.c*e,this.b*-n+this.d*e,this.e,this.f)}rotateAt(t,e){const n=Math.cos(t),o=Math.sin(t),s=e.x,r=e.y,i=this.a*n+this.c*o,a=this.b*n+this.d*o,c=this.c*n-this.a*o,h=this.d*n-this.b*o;return new this.constructor(i,a,c,h,(this.a-i)*s+(this.c-c)*r+this.e,(this.b-a)*s+(this.d-h)*r+this.f)}rotateFromVector(t){const e=t.unit(),n=e.x,o=e.y;return new this.constructor(this.a*n+this.c*o,this.b*n+this.d*o,this.a*-o+this.c*n,this.b*-o+this.d*n,this.e,this.f)}flipX(){return new this.constructor(-this.a,-this.b,this.c,this.d,this.e,this.f)}flipY(){return new this.constructor(this.a,this.b,-this.c,-this.d,this.e,this.f)}skewX(t){const e=Math.tan(t);return new this.constructor(this.a,this.b,this.c+this.a*e,this.d+this.b*e,this.e,this.f)}skewY(t){const e=Math.tan(t);return new this.constructor(this.a+this.c*e,this.b+this.d*e,this.c,this.d,this.e,this.f)}isIdentity(){return this.a===1&&this.b===0&&this.c===0&&this.d===1&&this.e===0&&this.f===0}isInvertible(){return this.a*this.d-this.b*this.c!==0}getScale(){return{scaleX:Math.sqrt(this.a*this.a+this.c*this.c),scaleY:Math.sqrt(this.b*this.b+this.d*this.d)}}getDecomposition(){const t=(this.a+this.d)*.5,e=(this.a-this.d)*.5,n=(this.b+this.c)*.5,o=(this.b-this.c)*.5,s=Math.sqrt(t*t+o*o),r=Math.sqrt(e*e+n*n),i=s+r,a=s-r,c=Math.atan2(n,e),h=Math.atan2(o,t),d=(h-c)*.5,u=(h+c)*.5;return{translation:this.constructor.translation(this.e,this.f),rotation:this.constructor.rotation(u),scale:this.constructor.nonUniformScaling(i,a),rotation0:this.constructor.rotation(d)}}equals(t){return this.a===t.a&&this.b===t.b&&this.c===t.c&&this.d===t.d&&this.e===t.e&&this.f===t.f}precisionEquals(t,e){return Math.abs(this.a-t.a)<e&&Math.abs(this.b-t.b)<e&&Math.abs(this.c-t.c)<e&&Math.abs(this.d-t.d)<e&&Math.abs(this.e-t.e)<e&&Math.abs(this.f-t.f)<e}toString(){return`matrix(${this.a},${this.b},${this.c},${this.d},${this.e},${this.f})`}}pt.IDENTITY=new pt,pt.IDENTITY.isIdentity=()=>!0;function St(l){return typeof l=="number"?l?l<0?-1:1:l===l?l:NaN:NaN}class Ue{constructor(...t){this.coefs=[];for(let e=t.length-1;e>=0;e--)this.coefs.push(t[e]);this._variable="t",this._s=0}static interpolate(t,e,n,o,s){if(t.constructor!==Array||e.constructor!==Array)throw new TypeError("xs and ys must be arrays");if(isNaN(n)||isNaN(o)||isNaN(s))throw new TypeError("n, offset, and x must be numbers");let r,i,a=0;const c=new Array(n),h=new Array(n);let d=0,u=Math.abs(s-t[o]);for(r=0;r<n;r++){const f=Math.abs(s-t[o+r]);f<u&&(d=r,u=f),c[r]=h[r]=e[o+r]}i=e[o+d],d--;for(let f=1;f<n;f++){for(r=0;r<n-f;r++){const g=t[o+r]-s,y=t[o+r+f]-s,P=c[r+1]-h[r];let b=g-y;if(b===0)throw new RangeError("Unable to interpolate polynomial. Two numbers in n were identical (to within roundoff)");b=P/b,h[r]=y*b,c[r]=g*b}a=2*(d+1)<n-f?c[d+1]:h[d--],i+=a}return{y:i,dy:a}}static newtonSecantBisection(t,e,n,o,s,r){let i,a=0,c,h=0,d,u,f,g,y;i=t;const P=Math.pow(10,-14),b=typeof s=="number"&&typeof r=="number";if(b){if(s>r)throw new RangeError("Min must be greater than max");if(g=e(s),y=e(r),St(g)===St(y))throw new RangeError("Y values of bounds must be of opposite sign")}const w=function(){return Math.abs(d)<=P*Math.abs(i)||h===i-d-i};for(let L=0;L<o;L++){if(c=n(i),c===0){if(a===0)throw new RangeError("df(x) is zero");c=a}if(a=c,f=e(i),d=f/c,u=i-d,w())break;if(b){if(St(f)===St(y))r=i,y=f;else if(St(f)===St(g))s=i,g=f;else{i=u;break}if(u<s||u>r){if(St(g)===St(y))break;const B=50,H=.25,E=y-g,X=r-s;if(E===0?d=i-(s+X*.5):Math.abs(E/Math.min(g,y))>B?d=i-(s+X*(.5+(Math.abs(g)<Math.abs(y)?-H:H))):d=i-(s-g/E*X),u=i-d,w())break}}h=i-u,i=u}return i}clone(){const t=new Ue;return t.coefs=this.coefs.slice(),t}eval(t){if(isNaN(t))throw new TypeError(`Parameter must be a number. Found '${t}'`);let e=0;for(let n=this.coefs.length-1;n>=0;n--)e=e*t+this.coefs[n];return e}add(t){const e=new Ue,n=this.getDegree(),o=t.getDegree(),s=Math.max(n,o);for(let r=0;r<=s;r++){const i=r<=n?this.coefs[r]:0,a=r<=o?t.coefs[r]:0;e.coefs[r]=i+a}return e}multiply(t){const e=new Ue;for(let n=0;n<=this.getDegree()+t.getDegree();n++)e.coefs.push(0);for(let n=0;n<=this.getDegree();n++)for(let o=0;o<=t.getDegree();o++)e.coefs[n+o]+=this.coefs[n]*t.coefs[o];return e}divideEqualsScalar(t){for(let e=0;e<this.coefs.length;e++)this.coefs[e]/=t}simplifyEquals(t=1e-12){for(let e=this.getDegree();e>=0&&Math.abs(this.coefs[e])<=t;e--)this.coefs.pop()}removeZerosEquals(t=1e-15){const e=this.coefs,n=10*t*Math.abs(e.reduce((o,s)=>Math.abs(s)>Math.abs(o)?s:o));for(let o=0;o<e.length-1;o++)Math.abs(e[o])<n&&(e[o]=0);return this}monicEquals(){const t=this.coefs;return t[t.length-1]!==1&&this.divideEqualsScalar(t[t.length-1]),this}toString(){const t=[],e=[];for(let o=this.coefs.length-1;o>=0;o--){let s=Math.round(this.coefs[o]*1e3)/1e3;if(s!==0){const r=s<0?" - ":" + ";s=Math.abs(s),o>0&&(s===1?s=this._variable:s+=this._variable),o>1&&(s+="^"+o),e.push(r),t.push(s)}}e[0]=e[0]===" + "?"":"-";let n="";for(let o=0;o<t.length;o++)n+=e[o]+t[o];return n}bisection(t,e,n=1e-6,o=15){let s=this.eval(t),r=this.eval(e),i;if(Math.abs(s)<=n)i=t;else if(Math.abs(r)<=n)i=e;else if(s*r<=0){const a=Math.log(e-t),c=Math.LN10*o,h=Math.ceil((a+c)/Math.LN2);for(let d=0;d<h;d++){i=.5*(t+e);const u=this.eval(i);if(Math.abs(u)<=n)break;u*s<0?(e=i,r=u):(t=i,s=u)}}return i}trapezoid(t,e,n){if(isNaN(t)||isNaN(e)||isNaN(n))throw new TypeError("Parameters must be numbers");const o=e-t;if(n===1){const s=this.eval(t),r=this.eval(e);this._s=.5*o*(s+r)}else{const s=1<<n-2,r=o/s;let i=t+.5*r,a=0;for(let c=0;c<s;c++)a+=this.eval(i),i+=r;this._s=.5*(this._s+o*a/s)}if(isNaN(this._s))throw new TypeError("this._s is NaN");return this._s}simpson(t,e){if(isNaN(t)||isNaN(e))throw new TypeError("Parameters must be numbers");const n=e-t;let o=.5*n*(this.eval(t)+this.eval(e)),s=o,r=4*o/3,i=r,a=o;const c=1e-7;let h=1;for(let d=2;d<=20;d++){const u=n/h;let f=t+.5*u,g=0;for(let y=1;y<=h;y++)g+=this.eval(f),f+=u;if(s=.5*(s+n*g/h),o=s,r=(4*o-a)/3,Math.abs(r-i)<c*Math.abs(i))break;i=r,a=o,h<<=1}return r}romberg(t,e){if(isNaN(t)||isNaN(e))throw new TypeError("Parameters must be numbers");const n=20,o=3,s=1e-6,r=new Array(n+1),i=new Array(n+1);let a={y:0,dy:0};i[0]=1;for(let c=1;c<=n&&(r[c-1]=this.trapezoid(t,e,c),!(c>=o&&(a=Ue.interpolate(i,r,o,c-o,0),Math.abs(a.dy)<=s*a.y)));c++)r[c]=r[c-1],i[c]=.25*i[c-1];return a.y}zeroErrorEstimate(t){const e=this,n=1e-15;if(typeof t>"u"){const r=e.bounds();t=Math.max(Math.abs(r.minX),Math.abs(r.maxX))}if(t<.001)return 2*Math.abs(e.eval(n));const o=e.coefs.length-1,s=e.coefs[o];return 10*n*e.coefs.reduce((r,i,a)=>{const c=i/s*Math.pow(t,a);return c>r?c:r},0)}boundsUpperRealFujiwara(){let t=this.coefs;const e=t.length-1,n=t[e];n!==1&&(t=this.coefs.map(c=>c/n));const o=t.map((c,h)=>h<e?Math.pow(Math.abs(h===0?c/2:c),1/(e-h)):c);let s;const r=function(c,h,d){return s(d)&&(c.max<h?(c.nearmax=c.max,c.max=h):c.nearmax<h&&(c.nearmax=h)),c};s=function(c){return c<e&&t[c]<0};const i=o.reduce(r,{max:0,nearmax:0});return s=function(c){return c<e&&(e%2===c%2?t[c]<0:t[c]>0)},{negX:-2*o.reduce(r,{max:0,nearmax:0}).max,posX:2*i.max}}boundsLowerRealFujiwara(){const t=new Ue;t.coefs=this.coefs.slice().reverse();const e=t.boundsUpperRealFujiwara();return e.negX=1/e.negX,e.posX=1/e.posX,e}bounds(){const t=this.boundsUpperRealFujiwara(),e={minX:t.negX,maxX:t.posX};return t.negX===0&&t.posX===0||(t.negX===0?e.minX=this.boundsLowerRealFujiwara().posX:t.posX===0&&(e.maxX=this.boundsLowerRealFujiwara().negX),e.minX>e.maxX&&(e.minX=e.maxX=0)),e}boundUpperAbsRouche(){const t=this.coefs,e=t.length-1;return 1+t.reduce((o,s,r)=>r!==e?(s=Math.abs(s),o<s?s:o):o,0)/Math.abs(t[e])}boundLowerAbsRouche(){const t=this.coefs,e=t.reduce((n,o,s)=>s!==0?(o=Math.abs(o),n<o?o:n):n,0);return Math.abs(t[0])/(Math.abs(t[0])+e)}boundsRealLaguerre(){const t=this.coefs,e=t.length-1,n=-t[e-1]/(e*t[e]),o=t[e-1]*t[e-1]-2*e/(e-1)*t[e]*t[e-2];let s=(e-1)/(e*t[e])*Math.sqrt(o);return s<0&&(s=-s),{minX:n-s,maxX:n+s}}countRootsDescartes(){const t=this.coefs,e=t.length-1,n=t.reduce((o,s,r)=>(o.prev_a!==0&&s!==0&&(o.prev_a<0==s>0&&o.pos++,r%2===0!=o.prev_a<0==(r%2===1!=s>0)&&o.neg++),o.prev_a=s,o),{pos:0,neg:0,prev_a:0});return{maxRealPos:n.pos,maxRealNeg:n.neg,minComplex:e-(n.pos+n.neg)}}getDegree(){return this.coefs.length-1}getDerivative(){const t=new Ue;for(let e=1;e<this.coefs.length;e++)t.coefs.push(e*this.coefs[e]);return t}getRoots(){let t;switch(this.simplifyEquals(),this.getDegree()){case 0:t=[];break;case 1:t=this.getLinearRoot();break;case 2:t=this.getQuadraticRoots();break;case 3:t=this.getCubicRoots();break;case 4:t=this.getQuarticRoots();break;default:t=[]}return t}getRootsInInterval(t,e){const n=[];function o(s){typeof s=="number"&&n.push(s)}if(this.getDegree()===0)throw new RangeError("Unexpected empty polynomial");if(this.getDegree()===1)o(this.bisection(t,e));else{const r=this.getDerivative().getRootsInInterval(t,e);if(r.length>0){o(this.bisection(t,r[0]));for(let i=0;i<=r.length-2;i++)o(this.bisection(r[i],r[i+1]));o(this.bisection(r[r.length-1],e))}else o(this.bisection(t,e))}return n}getLinearRoot(){const t=[],e=this.coefs[1];return e!==0&&t.push(-this.coefs[0]/e),t}getQuadraticRoots(){const t=[];if(this.getDegree()===2){const e=this.coefs[2],n=this.coefs[1]/e,o=this.coefs[0]/e,s=n*n-4*o;if(s>0){const r=Math.sqrt(s);t.push(.5*(-n+r)),t.push(.5*(-n-r))}else s===0&&t.push(.5*-n)}return t}getCubicRoots(){const t=[];if(this.getDegree()===3){const e=this.coefs[3],n=this.coefs[2]/e,o=this.coefs[1]/e,s=this.coefs[0]/e,r=(3*o-n*n)/3,i=(2*n*n*n-9*o*n+27*s)/27,a=n/3;let c=i*i/4+r*r*r/27;const h=i/2,d=this.zeroErrorEstimate();if(Math.abs(c)<=d&&(c=0),c>0){const u=Math.sqrt(c);let f,g=-h+u;g>=0?f=Math.pow(g,1/3):f=-Math.pow(-g,1/3),g=-h-u,g>=0?f+=Math.pow(g,1/3):f-=Math.pow(-g,1/3),t.push(f-a)}else if(c<0){const u=Math.sqrt(-r/3),f=Math.atan2(Math.sqrt(-c),-h)/3,g=Math.cos(f),y=Math.sin(f),P=Math.sqrt(3);t.push(2*u*g-a),t.push(-u*(g+P*y)-a),t.push(-u*(g-P*y)-a)}else{let u;h>=0?u=-Math.pow(h,1/3):u=Math.pow(-h,1/3),t.push(2*u-a),t.push(-u-a)}}return t}getQuarticRoots(){let t=[];const e=this.getDegree();if(e===4){const n=new Ue;n.coefs=this.coefs.slice(),n.divideEqualsScalar(n.coefs[e]);const o=1e-15;Math.abs(n.coefs[0])<10*o*Math.abs(n.coefs[3])&&(n.coefs[0]=0);const s=n.getDerivative(),r=s.getRoots().sort((w,L)=>w-L),i=[],a=r.length-1,c=this.bounds(),h=Math.max(Math.abs(c.minX),Math.abs(c.maxX)),d=this.zeroErrorEstimate(h);for(let w=0;w<=a;w++)i.push(n.eval(r[w]));for(let w=0;w<=a;w++)Math.abs(i[w])<d&&(i[w]=0);let u=0;const f=Math.max(.1*(c.maxX-c.minX)/e,o),g=[],y=[];if(a>-1){for(i[0]!==0?St(i[0])!==St(n.eval(r[0]-f)-i[0])&&(g.push(r[0]-f),y.push([c.minX,r[0]])):(t.push(r[0],r[0]),u++);u<a;u++)i[u+1]===0?(t.push(r[u+1],r[u+1]),u++):St(i[u])!==St(i[u+1])&&(g.push((r[u]+r[u+1])/2),y.push([r[u],r[u+1]]));i[a]!==0&&St(i[a])!==St(n.eval(r[a]+f)-i[a])&&(g.push(r[a]+f),y.push([r[a],c.maxX]))}const P=function(w){return n.eval(w)},b=function(w){return s.eval(w)};if(g.length>0)for(u=0;u<g.length;u++)g[u]=Ue.newtonSecantBisection(g[u],P,b,32,y[u][0],y[u][1]);t=t.concat(g)}return t}}class ft{constructor(t,e){this.type=t,this.text=e}typeis(t){return this.type===t}}ft.UNDEFINED=0,ft.COMMAND=1,ft.NUMBER=2,ft.EOD=3;class Nh{constructor(t){t==null&&(t=""),this.setPathData(t)}setPathData(t){if(typeof t!="string")throw new TypeError("The first parameter must be a string");this._pathData=t}getNextToken(){let t=null,e=this._pathData;for(;t===null;)if(e===null||e==="")t=new ft(ft.EOD,"");else if(e.match(/^([ \t\r\n,]+)/))e=e.substr(RegExp.$1.length);else if(e.match(/^([AaCcHhLlMmQqSsTtVvZz])/))t=new ft(ft.COMMAND,RegExp.$1),e=e.substr(RegExp.$1.length);else if(e.match(/^(([-+]?\d+(\.\d*)?|[-+]?\.\d+)([eE][-+]?\d+)?)/))t=new ft(ft.NUMBER,RegExp.$1),e=e.substr(RegExp.$1.length);else throw new SyntaxError(`Unrecognized path data: ${e}`);return this._pathData=e,t}}const Ts="BOP";class In{constructor(){this._lexer=new Nh,this._handler=null}parseData(t){if(typeof t!="string")throw new TypeError(`The first parameter must be a string: ${t}`);this._handler!==null&&typeof this._handler.beginParse=="function"&&this._handler.beginParse();const e=this._lexer;e.setPathData(t);let n=Ts,o=null,s=e.getNextToken();for(;s.typeis(ft.EOD)===!1;){let r;const i=[];switch(s.type){case ft.COMMAND:if(n===Ts&&s.text!=="M"&&s.text!=="m")throw new SyntaxError(`New paths must begin with a moveto command. Found '${s.text}'`);n=s.text,r=In.PARAMCOUNT[s.text.toUpperCase()],s=e.getNextToken();break;case ft.NUMBER:if(n===Ts)throw new SyntaxError(`New paths must begin with a moveto command. Found '${s.text}'`);r=In.PARAMCOUNT[n.toUpperCase()];break;default:throw new SyntaxError(`Unrecognized command type: ${s.type}`)}for(let a=0;a<r;a++){switch(s.type){case ft.COMMAND:throw new SyntaxError(`Parameter must be a number. Found '${s.text}'`);case ft.NUMBER:i[a]=parseFloat(s.text);break;case ft.EOD:throw new SyntaxError("Unexpected end of string");default:throw new SyntaxError(`Unrecognized parameter type. Found type '${s.type}'`)}s=e.getNextToken()}if(this._handler!==null){const a=this._handler,c=In.METHODNAME[n];(n==="a"||n==="A")&&(i[3]=i[3]!==0,i[4]=i[4]!==0),a!==null&&typeof a[c]=="function"&&a[c](...i)}switch(n){case"M":n="L";break;case"m":n="l";break;case"Z":case"z":n="BOP";break}if(s===o)throw new SyntaxError(`Parser stalled on '${s.text}'`);o=s}this._handler!==null&&typeof this._handler.endParse=="function"&&this._handler.endParse()}setHandler(t){this._handler=t}}In.PARAMCOUNT={A:7,C:6,H:1,L:2,M:2,Q:4,S:4,T:2,V:1,Z:0},In.METHODNAME={A:"arcAbs",a:"arcRel",C:"curvetoCubicAbs",c:"curvetoCubicRel",H:"linetoHorizontalAbs",h:"linetoHorizontalRel",L:"linetoAbs",l:"linetoRel",M:"movetoAbs",m:"movetoRel",Q:"curvetoQuadraticAbs",q:"curvetoQuadraticRel",S:"curvetoCubicSmoothAbs",s:"curvetoCubicSmoothRel",T:"curvetoQuadraticSmoothAbs",t:"curvetoQuadraticSmoothRel",V:"linetoVerticalAbs",v:"linetoVerticalRel",Z:"closePath",z:"closePath"};const Bh=2*Math.PI;function fi(l,t,e,n,o,s,r){o=o*Math.PI/180;const i=Math.cos(o),a=Math.sin(o),c=1e-6,h=l.subtract(t).multiply(.5),d=h.x*i+h.y*a,u=h.x*-a+h.y*i;e=Math.abs(e),n=Math.abs(n);const f=d*d,g=u*u,y=f/(e*e)+g/(n*n);if(y>1){const pe=Math.sqrt(y);e*=pe,n*=pe}const P=e*e,b=n*n,w=P*g,L=b*f;let B=(P*b-w-L)/(w+L);Math.abs(B)<c&&(B=0);let H=Math.sqrt(B);s===r&&(H=-H);const E=l.add(t).multiply(.5),X=H*e*u/n,$=H*-n*d/e,Z=(d-X)/e,se=(d+X)/e,ne=(u-$)/n,ae=(u+$)/n,te=new rt(1,0).angleBetween(new rt(Z,ne));let ce=new rt(Z,ne).angleBetween(new rt(-se,-ae));return r===!1&&(ce-=Bh),[X*i-$*a+E.x,X*a+$*i+E.y,e,n,te,te+ce]}class Rh{constructor(t){this.shapeCreator=t,this.shapes=[],this.firstX=null,this.firstY=null,this.lastX=null,this.lastY=null,this.lastCommand=null}beginParse(){this.shapes=[],this.firstX=null,this.firstY=null,this.lastX=null,this.lastY=null,this.lastCommand=null}addShape(t){this.shapes.push(t)}arcAbs(t,e,n,o,s,r,i){if(t===0||e===0)this.addShape(this.shapeCreator.line(this.lastX,this.lastY,r,i));else{const a=fi(new ge(this.lastX,this.lastY),new ge(r,i),t,e,n,o,s);this.addShape(this.shapeCreator.arc(...a))}this.lastCommand="A",this.lastX=r,this.lastY=i}arcRel(t,e,n,o,s,r,i){if(t===0||e===0)this.addShape(this.shapeCreator.line(this.lastX,this.lastY,this.lastX+r,this.lastY+i));else{const a=fi(new ge(this.lastX,this.lastY),new ge(this.lastX+r,this.lastY+i),t,e,n,o,s);this.addShape(this.shapeCreator.arc(...a))}this.lastCommand="a",this.lastX+=r,this.lastY+=i}curvetoCubicAbs(t,e,n,o,s,r){this.addShape(this.shapeCreator.cubicBezier(this.lastX,this.lastY,t,e,n,o,s,r)),this.lastX=s,this.lastY=r,this.lastCommand="C"}curvetoCubicRel(t,e,n,o,s,r){this.addShape(this.shapeCreator.cubicBezier(this.lastX,this.lastY,this.lastX+t,this.lastY+e,this.lastX+n,this.lastY+o,this.lastX+s,this.lastY+r)),this.lastX+=s,this.lastY+=r,this.lastCommand="c"}linetoHorizontalAbs(t){this.addShape(this.shapeCreator.line(this.lastX,this.lastY,t,this.lastY)),this.lastX=t,this.lastCommand="H"}linetoHorizontalRel(t){this.addShape(this.shapeCreator.line(this.lastX,this.lastY,this.lastX+t,this.lastY)),this.lastX+=t,this.lastCommand="h"}linetoAbs(t,e){this.addShape(this.shapeCreator.line(this.lastX,this.lastY,t,e)),this.lastX=t,this.lastY=e,this.lastCommand="L"}linetoRel(t,e){this.addShape(this.shapeCreator.line(this.lastX,this.lastY,this.lastX+t,this.lastY+e)),this.lastX+=t,this.lastY+=e,this.lastCommand="l"}movetoAbs(t,e){this.firstX=t,this.firstY=e,this.lastX=t,this.lastY=e,this.lastCommand="M"}movetoRel(t,e){this.firstX+=t,this.firstY+=e,this.lastX+=t,this.lastY+=e,this.lastCommand="m"}curvetoQuadraticAbs(t,e,n,o){this.addShape(this.shapeCreator.quadraticBezier(this.lastX,this.lastY,t,e,n,o)),this.lastX=n,this.lastY=o,this.lastCommand="Q"}curvetoQuadraticRel(t,e,n,o){this.addShape(this.shapeCreator.quadraticBezier(this.lastX,this.lastY,this.lastX+t,this.lastY+e,this.lastX+n,this.lastY+o)),this.lastX+=n,this.lastY+=o,this.lastCommand="q"}curvetoCubicSmoothAbs(t,e,n,o){let s,r;if(this.lastCommand.match(/^[SsCc]$/)){const i=this.shapes[this.shapes.length-1].args[2];s=2*this.lastX-i.x,r=2*this.lastY-i.y}else s=this.lastX,r=this.lastY;this.addShape(this.shapeCreator.cubicBezier(this.lastX,this.lastY,s,r,t,e,n,o)),this.lastX=n,this.lastY=o,this.lastCommand="S"}curvetoCubicSmoothRel(t,e,n,o){let s,r;if(this.lastCommand.match(/^[SsCc]$/)){const i=this.shapes[this.shapes.length-1].args[2];s=2*this.lastX-i.x,r=2*this.lastY-i.y}else s=this.lastX,r=this.lastY;this.addShape(this.shapeCreator.cubicBezier(this.lastX,this.lastY,s,r,this.lastX+t,this.lastY+e,this.lastX+n,this.lastY+o)),this.lastX+=n,this.lastY+=o,this.lastCommand="s"}curvetoQuadraticSmoothAbs(t,e){let n,o;if(this.lastCommand.match(/^[QqTt]$/)){const s=this.shapes[this.shapes.length-1].args[1];n=2*this.lastX-s.x,o=2*this.lastY-s.y}else n=this.lastX,o=this.lastY;this.addShape(this.shapeCreator.quadraticBezier(this.lastX,this.lastY,n,o,t,e)),this.lastX=t,this.lastY=e,this.lastCommand="T"}curvetoQuadraticSmoothRel(t,e){let n,o;if(this.lastCommand.match(/^[QqTt]$/)){const s=this.shapes[this.shapes.length-1].args[1];n=2*this.lastX-s.x,o=2*this.lastY-s.y}else n=this.lastX,o=this.lastY;this.addShape(this.shapeCreator.quadraticBezier(this.lastX,this.lastY,n,o,this.lastX+t,this.lastY+e)),this.lastX+=t,this.lastY+=e,this.lastCommand="t"}linetoVerticalAbs(t){this.addShape(this.shapeCreator.line(this.lastX,this.lastY,this.lastX,t)),this.lastY=t,this.lastCommand="V"}linetoVerticalRel(t){this.addShape(this.shapeCreator.line(this.lastX,this.lastY,this.lastX,this.lastY+t)),this.lastY+=t,this.lastCommand="v"}closePath(){this.addShape(this.shapeCreator.line(this.lastX,this.lastY,this.firstX,this.firstY)),this.lastX=this.firstX,this.lastY=this.firstY,this.lastCommand="z"}}const Tn=Math.PI*.5,gi=new In;function tn(l,t){const e=[];for(const[n,o]of l){let s=null;if(o==="Point2D")s=Ls(n,t);else if(o==="Number")s=yi(n,t);else if(o==="Array<Point2D>"||o==="Point2D[]"){const r=[];for(;t.length>0;)r.push(Ls(n,t));r.length>0&&(s=r)}else if(o==="Optional<Number>"||o==="Number?")s=yi(n,t),s===null&&(s=void 0);else throw new TypeError(`Unrecognized value type: ${o}`);if(s!==null)e.push(s);else throw new TypeError(`Unable to extract value for ${n}`)}return e}function yi(l,t){let e=null;if(t.length>0){const n=t[0],o=typeof n;if(o==="number")return t.shift();if(o==="object"){for(const s of l)if(s in n&&typeof n[s]=="number"){e=n[s];break}}}return e}function Ls(l,t){let e=null;if(t.length>0){const n=t[0],o=typeof n;if(o==="number"){if(t.length>1){const s=t.shift(),r=t.shift();e=new ge(s,r)}}else if(Array.isArray(n)&&n.length>1)if(n.length===2){const[s,r]=t.shift();e=new ge(s,r)}else throw new TypeError(`Unhandled array of length ${n.length}`);else if(o==="object"){if("x"in n&&"y"in n)e=new ge(n.x,n.y),t.shift();else for(const s of l)if(Array.isArray(s)){if(s.every(r=>r in n)){e=new ge(n[s[0]],n[s[1]]);break}}else if(s in n){e=Ls([],[n[s]]);break}}}return e}class q{constructor(t,e){this.name=t,this.args=e}static arc(...t){const n=tn([[["center",["centerX","centerY"],["cx","cy"]],"Point2D"],[["radiusX","rx"],"Number"],[["radiusY","ry"],"Number"],[["startRadians"],"Number"],[["endRadians"],"Number"]],t);return new q(q.ARC,n)}static quadraticBezier(...t){const n=tn([[["p1",["p1x","p1y"]],"Point2D"],[["p2",["p2x","p2y"]],"Point2D"],[["p3",["p3x","p3y"]],"Point2D"]],t);return new q(q.QUADRATIC_BEZIER,n)}static cubicBezier(...t){const n=tn([[["p1",["p1x","p1y"]],"Point2D"],[["p2",["p2x","p2y"]],"Point2D"],[["p3",["p3x","p3y"]],"Point2D"],[["p4",["p4x","p4y"]],"Point2D"]],t);return new q(q.CUBIC_BEZIER,n)}static circle(...t){const n=tn([[["center",["centerX","centerY"],["cx","cy"]],"Point2D"],[["radius","r"],"Number"]],t);return new q(q.CIRCLE,n)}static ellipse(...t){const n=tn([[["center",["centerX","centerY"],["cx","cy"]],"Point2D"],[["radiusX","rx"],"Number"],[["radiusY","ry"],"Number"]],t);return new q(q.ELLIPSE,n)}static line(...t){const n=tn([[["p1",["p1x","p1y"],["x1","y1"]],"Point2D"],[["p2",["p2x","p2y"],["x2","y2"]],"Point2D"]],t);return new q(q.LINE,n)}static path(...t){return gi.parseData(t[0]),new q(q.PATH,xi.shapes)}static polygon(...t){const n=tn([[[],"Array<Point2D>"]],t.length===1&&Array.isArray(t[0])?t[0]:t);return new q(q.POLYGON,n)}static polyline(...t){const n=tn([[[],"Array<Point2D>"]],t.length===1&&Array.isArray(t[0])?t[0]:t);return new q(q.POLYLINE,n)}static rectangle(...t){const n=tn([[["topLeft",["x","y"],["left","top"]],"Point2D"],[["size",["width","height"],["w","h"]],"Point2D"],[["radiusX","rx"],"Optional<Number>"],[["radiusY","ry"],"Optional<Number>"]],t),o=n[0],s=n[1];n[1]=new ge(o.x+s.x,o.y+s.y);const r=new q(q.RECTANGLE,n);let i=r.args.pop(),a=r.args.pop();if(a=a===void 0?0:a,i=i===void 0?0:i,a===0&&i===0)return r;const{x:c,y:h}=r.args[0],{x:d,y:u}=r.args[1],f=d-c,g=u-h;a===0&&(a=i),i===0&&(i=a),a>f*.5&&(a=f*.5),i>g*.5&&(i=g*.5);const y=c,P=h,b=c+a,w=h+i,L=d-a,B=u-i,H=d,E=u,X=[q.arc(b,w,a,i,2*Tn,3*Tn),q.line(b,P,L,P),q.arc(L,w,a,i,3*Tn,4*Tn),q.line(H,w,H,B),q.arc(L,B,a,i,0,Tn),q.line(L,E,b,E),q.arc(b,B,a,i,Tn,2*Tn),q.line(y,B,y,w)];return new q(q.PATH,X)}}q.ARC="Arc",q.QUADRATIC_BEZIER="Bezier2",q.CUBIC_BEZIER="Bezier3",q.CIRCLE="Circle",q.ELLIPSE="Ellipse",q.LINE="Line",q.PATH="Path",q.POLYGON="Polygon",q.POLYLINE="Polyline",q.RECTANGLE="Rectangle";const xi=new Rh(q);gi.setHandler(xi);const io=2*Math.PI,Eh=new rt(1,0);function wi(l){return l==null}function Hh(l,t){const e=l[0]*t[1]-t[0]*l[1],n=l[0]*t[2]-t[0]*l[2],o=l[0]*t[3]-t[0]*l[3],s=l[0]*t[4]-t[0]*l[4],r=l[0]*t[5]-t[0]*l[5],i=l[1]*t[2]-t[1]*l[2],a=l[1]*t[4]-t[1]*l[4],c=l[1]*t[5]-t[1]*l[5],h=l[2]*t[3]-t[2]*l[3],d=l[3]*t[4]-t[3]*l[4],u=l[3]*t[5]-t[3]*l[5],f=c+d,g=a-h;return new Ue(e*i-n*n,e*g+o*i-2*n*s,e*f+o*g-s*s-2*n*r,e*u+o*f-2*s*r,o*u-r*r)}function Dh(l){const t=l%io;return t<0?t+io:t}function Oh(l,t,e,n,o,s){if(l.points.length===0)return l;const r=new Y("No Intersection");s<o&&([o,s]=[s,o]),(o<0||s<0)&&(o+=io,s+=io);for(const i of l.points){let a=Dh(Eh.angleBetween(rt.fromPoints(t,i)));a<o&&(a+=io),o<=a&&a<=s&&r.appendPoint(i)}return r.points.length>0&&(r.status="Intersection"),r}function nn(l){const t=l.slice();return t.push(l[0]),t}class Y{constructor(t){this.init(t)}init(t){this.status=t,this.points=[]}static intersect(t,e){let n;if(!wi(t)&&!wi(e))if(t.name==="Path")n=Y.intersectPathShape(t,e);else if(e.name==="Path")n=Y.intersectPathShape(e,t);else if(t.name==="Arc")n=Y.intersectArcShape(t,e);else if(e.name==="Arc")n=Y.intersectArcShape(e,t);else{let o,s;if(t.name<e.name?(o="intersect"+t.name+e.name,s=t.args.concat(e.args)):(o="intersect"+e.name+t.name,s=e.args.concat(t.args)),!(o in Y))throw new TypeError("Intersection not available: "+o);n=Y[o].apply(null,s)}else n=new Y("No Intersection");return n}static intersectPathShape(t,e){const n=new Y("No Intersection");for(const o of t.args){const s=Y.intersect(o,e);n.appendPoints(s.points)}return n.points.length>0&&(n.status="Intersection"),n}static intersectArcShape(t,e){const[n,o,s,r,i]=t.args,a=new q(q.ELLIPSE,[n,o,s]),c=Y.intersect(a,e);return Oh(c,n,o,s,r,i)}static intersectBezier2Bezier2(t,e,n,o,s,r){let i,a;const c=new Y("No Intersection");i=e.multiply(-2);const h=t.add(i.add(n));i=t.multiply(-2),a=e.multiply(2);const d=i.add(a),u=new ge(t.x,t.y);i=s.multiply(-2);const f=o.add(i.add(r));i=o.multiply(-2),a=s.multiply(2);const g=i.add(a),y=new ge(o.x,o.y);i=h.x*d.y-d.x*h.y,a=f.x*d.y-d.x*f.y;const P=g.x*d.y-d.x*g.y,b=d.x*(u.y-y.y)+d.y*(-u.x+y.x),w=f.x*h.y-h.x*f.y,L=g.x*h.y-h.x*g.y,B=h.x*(u.y-y.y)+h.y*(-u.x+y.x),E=new Ue(-w*w,-2*w*L,i*a-L*L-2*w*B,i*P-2*L*B,i*b-B*B).getRoots();for(const X of E)if(0<=X&&X<=1){const $=new Ue(h.x,d.x,u.x-y.x-X*g.x-X*X*f.x);$.simplifyEquals();const Z=$.getRoots(),se=new Ue(h.y,d.y,u.y-y.y-X*g.y-X*X*f.y);se.simplifyEquals();const ne=se.getRoots();if(Z.length>0&&ne.length>0){e:for(const te of Z)if(0<=te&&te<=1){for(let ce=0;ce<ne.length;ce++)if(Math.abs(te-ne[ce])<1e-4){c.points.push(f.multiply(X*X).add(g.multiply(X).add(y)));break e}}}}return c.points.length>0&&(c.status="Intersection"),c}static intersectBezier2Bezier3(t,e,n,o,s,r,i){let a,c,h,d;const u=new Y("No Intersection");a=e.multiply(-2);const f=t.add(a.add(n));a=t.multiply(-2),c=e.multiply(2);const g=a.add(c),y=new ge(t.x,t.y);a=o.multiply(-1),c=s.multiply(3),h=r.multiply(-3),d=a.add(c.add(h.add(i)));const P=new ge(d.x,d.y);a=o.multiply(3),c=s.multiply(-6),h=r.multiply(3),d=a.add(c.add(h));const b=new ge(d.x,d.y);a=o.multiply(-3),c=s.multiply(3),h=a.add(c);const w=new ge(h.x,h.y),L=new ge(o.x,o.y),B=y.x*y.x,H=y.y*y.y,E=g.x*g.x,X=g.y*g.y,$=f.x*f.x,Z=f.y*f.y,se=L.x*L.x,ne=L.y*L.y,ae=w.x*w.x,te=w.y*w.y,ce=b.x*b.x,pe=b.y*b.y,Be=P.x*P.x,Re=P.y*P.y,Te=new Ue(-2*f.x*f.y*P.x*P.y+$*Re+Z*Be,-2*f.x*f.y*b.x*P.y-2*f.x*f.y*b.y*P.x+2*Z*b.x*P.x+2*$*b.y*P.y,-2*f.x*w.x*f.y*P.y-2*f.x*f.y*w.y*P.x-2*f.x*f.y*b.x*b.y+2*w.x*Z*P.x+Z*ce+$*(2*w.y*P.y+pe),2*y.x*f.x*f.y*P.y+2*y.y*f.x*f.y*P.x+g.x*g.y*f.x*P.y+g.x*g.y*f.y*P.x-2*L.x*f.x*f.y*P.y-2*f.x*L.y*f.y*P.x-2*f.x*w.x*f.y*b.y-2*f.x*f.y*w.y*b.x-2*y.x*Z*P.x-2*y.y*$*P.y+2*L.x*Z*P.x+2*w.x*Z*b.x-X*f.x*P.x-E*f.y*P.y+$*(2*L.y*P.y+2*w.y*b.y),2*y.x*f.x*f.y*b.y+2*y.y*f.x*f.y*b.x+g.x*g.y*f.x*b.y+g.x*g.y*f.y*b.x-2*L.x*f.x*f.y*b.y-2*f.x*L.y*f.y*b.x-2*f.x*w.x*f.y*w.y-2*y.x*Z*b.x-2*y.y*$*b.y+2*L.x*Z*b.x-X*f.x*b.x-E*f.y*b.y+ae*Z+$*(2*L.y*b.y+te),2*y.x*f.x*f.y*w.y+2*y.y*f.x*w.x*f.y+g.x*g.y*f.x*w.y+g.x*g.y*w.x*f.y-2*L.x*f.x*f.y*w.y-2*f.x*L.y*w.x*f.y-2*y.x*w.x*Z-2*y.y*$*w.y+2*L.x*w.x*Z-X*f.x*w.x-E*f.y*w.y+2*$*L.y*w.y,-2*y.x*y.y*f.x*f.y-y.x*g.x*g.y*f.y-y.y*g.x*g.y*f.x+2*y.x*f.x*L.y*f.y+2*y.y*L.x*f.x*f.y+g.x*L.x*g.y*f.y+g.x*g.y*f.x*L.y-2*L.x*f.x*L.y*f.y-2*y.x*L.x*Z+y.x*X*f.x+y.y*E*f.y-2*y.y*$*L.y-L.x*X*f.x-E*L.y*f.y+B*Z+H*$+se*Z+$*ne).getRootsInInterval(0,1);for(const fe of Te){const O=new Ue(f.x,g.x,y.x-L.x-fe*w.x-fe*fe*b.x-fe*fe*fe*P.x).getRoots(),G=new Ue(f.y,g.y,y.y-L.y-fe*w.y-fe*fe*b.y-fe*fe*fe*P.y).getRoots();if(O.length>0&&G.length>0){e:for(const _ of O)if(0<=_&&_<=1){for(let Ve=0;Ve<G.length;Ve++)if(Math.abs(_-G[Ve])<1e-4){u.points.push(P.multiply(fe*fe*fe).add(b.multiply(fe*fe).add(w.multiply(fe).add(L))));break e}}}}return u.points.length>0&&(u.status="Intersection"),u}static intersectBezier2Circle(t,e,n,o,s){return Y.intersectBezier2Ellipse(t,e,n,o,s,s)}static intersectBezier2Ellipse(t,e,n,o,s,r){let i;const a=new Y("No Intersection");i=e.multiply(-2);const c=t.add(i.add(n));i=t.multiply(-2);const h=e.multiply(2),d=i.add(h),u=new ge(t.x,t.y),f=s*s,g=r*r,y=new Ue(g*c.x*c.x+f*c.y*c.y,2*(g*c.x*d.x+f*c.y*d.y),g*(2*c.x*u.x+d.x*d.x)+f*(2*c.y*u.y+d.y*d.y)-2*(g*o.x*c.x+f*o.y*c.y),2*(g*d.x*(u.x-o.x)+f*d.y*(u.y-o.y)),g*(u.x*u.x+o.x*o.x)+f*(u.y*u.y+o.y*o.y)-2*(g*o.x*u.x+f*o.y*u.y)-f*g).getRoots();for(const P of y)0<=P&&P<=1&&a.points.push(c.multiply(P*P).add(d.multiply(P).add(u)));return a.points.length>0&&(a.status="Intersection"),a}static intersectBezier2Line(t,e,n,o,s){let r;const i=o.min(s),a=o.max(s),c=new Y("No Intersection");r=e.multiply(-2);const h=t.add(r.add(n));r=t.multiply(-2);const d=e.multiply(2),u=r.add(d),f=new ge(t.x,t.y),g=new rt(o.y-s.y,s.x-o.x),y=o.x*s.y-s.x*o.y,P=new Ue(g.dot(h),g.dot(u),g.dot(f)+y).getRoots();for(const b of P)if(0<=b&&b<=1){const w=t.lerp(e,b),L=e.lerp(n,b),B=w.lerp(L,b);o.x===s.x?i.y<=B.y&&B.y<=a.y&&(c.status="Intersection",c.appendPoint(B)):o.y===s.y?i.x<=B.x&&B.x<=a.x&&(c.status="Intersection",c.appendPoint(B)):i.x<=B.x&&B.x<=a.x&&i.y<=B.y&&B.y<=a.y&&(c.status="Intersection",c.appendPoint(B))}return c}static intersectBezier2Polygon(t,e,n,o){return Y.intersectBezier2Polyline(t,e,n,nn(o))}static intersectBezier2Polyline(t,e,n,o){const s=new Y("No Intersection"),{length:r}=o;for(let i=0;i<r-1;i++){const a=o[i],c=o[i+1],h=Y.intersectBezier2Line(t,e,n,a,c);s.appendPoints(h.points)}return s.points.length>0&&(s.status="Intersection"),s}static intersectBezier2Rectangle(t,e,n,o,s){const r=o.min(s),i=o.max(s),a=new ge(i.x,r.y),c=new ge(r.x,i.y),h=Y.intersectBezier2Line(t,e,n,r,a),d=Y.intersectBezier2Line(t,e,n,a,i),u=Y.intersectBezier2Line(t,e,n,i,c),f=Y.intersectBezier2Line(t,e,n,c,r),g=new Y("No Intersection");return g.appendPoints(h.points),g.appendPoints(d.points),g.appendPoints(u.points),g.appendPoints(f.points),g.points.length>0&&(g.status="Intersection"),g}static intersectBezier3Bezier3(t,e,n,o,s,r,i,a){let c,h,d,u;const f=new Y("No Intersection");c=t.multiply(-1),h=e.multiply(3),d=n.multiply(-3),u=c.add(h.add(d.add(o)));const g=new ge(u.x,u.y);c=t.multiply(3),h=e.multiply(-6),d=n.multiply(3),u=c.add(h.add(d));const y=new ge(u.x,u.y);c=t.multiply(-3),h=e.multiply(3),d=c.add(h);const P=new ge(d.x,d.y),b=new ge(t.x,t.y);c=s.multiply(-1),h=r.multiply(3),d=i.multiply(-3),u=c.add(h.add(d.add(a)));const w=new ge(u.x,u.y);c=s.multiply(3),h=r.multiply(-6),d=i.multiply(3),u=c.add(h.add(d));const L=new ge(u.x,u.y);c=s.multiply(-3),h=r.multiply(3),d=c.add(h);const B=new ge(d.x,d.y),H=new ge(s.x,s.y);c=g.x*y.y-y.x*g.y,h=g.x*P.y-P.x*g.y;const E=g.x*b.y-b.x*g.y+H.x*g.y-g.x*H.y,X=B.x*g.y-g.x*B.y,$=L.x*g.y-g.x*L.y,Z=w.x*g.y-g.x*w.y;u=g.x*P.y-P.x*g.y;const se=g.x*b.y+y.x*P.y-P.x*y.y-b.x*g.y+H.x*g.y-g.x*H.y,ne=B.x*g.y-g.x*B.y,ae=L.x*g.y-g.x*L.y,te=w.x*g.y-g.x*w.y,ce=y.x*b.y-b.x*y.y+H.x*y.y-y.x*H.y,pe=B.x*y.y-y.x*B.y,Be=L.x*y.y-y.x*L.y,Re=w.x*y.y-y.x*w.y,Me=g.x*b.y-b.x*g.y+H.x*g.y-g.x*H.y,Te=B.x*g.y-g.x*B.y,fe=L.x*g.y-g.x*L.y,O=w.x*g.y-g.x*w.y,G=y.x*b.y-b.x*y.y+H.x*y.y-y.x*H.y,j=B.x*y.y-y.x*B.y,_=L.x*y.y-y.x*L.y,Ve=w.x*y.y-y.x*w.y,ut=P.x*b.y-b.x*P.y+H.x*P.y-P.x*H.y,yt=B.x*P.y-P.x*B.y,Nt=L.x*P.y-P.x*L.y,Ft=w.x*P.y-P.x*w.y,ln=new Ue(-Z*te*O,-Z*te*fe-Z*ae*O-$*te*O,-Z*te*Te-Z*ae*fe-$*te*fe-Z*ne*O-$*ae*O-X*te*O,-Z*te*Me-Z*ae*Te-$*te*Te-Z*ne*fe-$*ae*fe-X*te*fe-Z*se*O-$*ne*O-X*ae*O-E*te*O+h*Re*O+Z*u*Ve-c*Re*Ve+c*te*Ft,-Z*ae*Me-$*te*Me-Z*ne*Te-$*ae*Te-X*te*Te-Z*se*fe-$*ne*fe-X*ae*fe-E*te*fe+h*Re*fe-$*se*O-X*ne*O-E*ae*O+h*Be*O+Z*u*_-c*Re*_+$*u*Ve-c*Be*Ve+c*te*Nt+c*ae*Ft,-Z*ne*Me-$*ae*Me-X*te*Me-Z*se*Te-$*ne*Te-X*ae*Te-E*te*Te+h*Re*Te-$*se*fe-X*ne*fe-E*ae*fe+h*Be*fe-X*se*O-E*ne*O+h*pe*O+Z*u*j-c*Re*j+$*u*_-c*Be*_+X*u*Ve-c*pe*Ve+c*te*yt+c*ae*Nt+c*ne*Ft,-Z*se*Me-$*ne*Me-X*ae*Me-E*te*Me+h*Re*Me-$*se*Te-X*ne*Te-E*ae*Te+h*Be*Te-X*se*fe-E*ne*fe+h*pe*fe-E*se*O+h*ce*O+Z*u*G-c*Re*G+$*u*j-c*Be*j+X*u*_-c*pe*_+E*u*Ve-c*ce*Ve+c*te*ut+c*ae*yt+c*ne*Nt-h*u*Ft+c*se*Ft,-$*se*Me-X*ne*Me-E*ae*Me+h*Be*Me-X*se*Te-E*ne*Te+h*pe*Te-E*se*fe+h*ce*fe+$*u*G-c*Be*G+X*u*j-c*pe*j+E*u*_-c*ce*_+c*ae*ut+c*ne*yt-h*u*Nt+c*se*Nt,-X*se*Me-E*ne*Me+h*pe*Me-E*se*Te+h*ce*Te+X*u*G-c*pe*G+E*u*j-c*ce*j+c*ne*ut-h*u*yt+c*se*yt,-E*se*Me+h*ce*Me+E*u*G-c*ce*G-h*u*ut+c*se*ut);ln.simplifyEquals();const On=ln.getRootsInInterval(0,1);for(const $e of On){const eo=new Ue(g.x,y.x,P.x,b.x-H.x-$e*B.x-$e*$e*L.x-$e*$e*$e*w.x);eo.simplifyEquals();const to=eo.getRoots(),mn=new Ue(g.y,y.y,P.y,b.y-H.y-$e*B.y-$e*$e*L.y-$e*$e*$e*w.y);mn.simplifyEquals();const Yt=mn.getRoots();if(to.length>0&&Yt.length>0){e:for(const no of to)if(0<=no&&no<=1){for(let Pn=0;Pn<Yt.length;Pn++)if(Math.abs(no-Yt[Pn])<1e-4){f.points.push(w.multiply($e*$e*$e).add(L.multiply($e*$e).add(B.multiply($e).add(H))));break e}}}}return f.points.length>0&&(f.status="Intersection"),f}static intersectBezier3Circle(t,e,n,o,s,r){return Y.intersectBezier3Ellipse(t,e,n,o,s,r,r)}static intersectBezier3Ellipse(t,e,n,o,s,r,i){let a,c,h,d;const u=new Y("No Intersection");a=t.multiply(-1),c=e.multiply(3),h=n.multiply(-3),d=a.add(c.add(h.add(o)));const f=new ge(d.x,d.y);a=t.multiply(3),c=e.multiply(-6),h=n.multiply(3),d=a.add(c.add(h));const g=new ge(d.x,d.y);a=t.multiply(-3),c=e.multiply(3),h=a.add(c);const y=new ge(h.x,h.y),P=new ge(t.x,t.y),b=r*r,w=i*i,B=new Ue(f.x*f.x*w+f.y*f.y*b,2*(f.x*g.x*w+f.y*g.y*b),2*(f.x*y.x*w+f.y*y.y*b)+g.x*g.x*w+g.y*g.y*b,2*f.x*w*(P.x-s.x)+2*f.y*b*(P.y-s.y)+2*(g.x*y.x*w+g.y*y.y*b),2*g.x*w*(P.x-s.x)+2*g.y*b*(P.y-s.y)+y.x*y.x*w+y.y*y.y*b,2*y.x*w*(P.x-s.x)+2*y.y*b*(P.y-s.y),P.x*P.x*w-2*P.y*s.y*b-2*P.x*s.x*w+P.y*P.y*b+s.x*s.x*w+s.y*s.y*b-b*w).getRootsInInterval(0,1);for(const H of B)u.points.push(f.multiply(H*H*H).add(g.multiply(H*H).add(y.multiply(H).add(P))));return u.points.length>0&&(u.status="Intersection"),u}static intersectBezier3Line(t,e,n,o,s,r){let i,a,c,h;const d=s.min(r),u=s.max(r),f=new Y("No Intersection");i=t.multiply(-1),a=e.multiply(3),c=n.multiply(-3),h=i.add(a.add(c.add(o)));const g=new rt(h.x,h.y);i=t.multiply(3),a=e.multiply(-6),c=n.multiply(3),h=i.add(a.add(c));const y=new rt(h.x,h.y);i=t.multiply(-3),a=e.multiply(3),c=i.add(a);const P=new rt(c.x,c.y),b=new rt(t.x,t.y),w=new rt(s.y-r.y,r.x-s.x),L=s.x*r.y-r.x*s.y,B=new Ue(w.dot(g),w.dot(y),w.dot(P),w.dot(b)+L).getRoots();for(const H of B)if(0<=H&&H<=1){const E=t.lerp(e,H),X=e.lerp(n,H),$=n.lerp(o,H),Z=E.lerp(X,H),se=X.lerp($,H),ne=Z.lerp(se,H);s.x===r.x?d.y<=ne.y&&ne.y<=u.y&&(f.status="Intersection",f.appendPoint(ne)):s.y===r.y?d.x<=ne.x&&ne.x<=u.x&&(f.status="Intersection",f.appendPoint(ne)):d.x<=ne.x&&ne.x<=u.x&&d.y<=ne.y&&ne.y<=u.y&&(f.status="Intersection",f.appendPoint(ne))}return f}static intersectBezier3Polygon(t,e,n,o,s){return Y.intersectBezier3Polyline(t,e,n,o,nn(s))}static intersectBezier3Polyline(t,e,n,o,s){const r=new Y("No Intersection"),{length:i}=s;for(let a=0;a<i-1;a++){const c=s[a],h=s[a+1],d=Y.intersectBezier3Line(t,e,n,o,c,h);r.appendPoints(d.points)}return r.points.length>0&&(r.status="Intersection"),r}static intersectBezier3Rectangle(t,e,n,o,s,r){const i=s.min(r),a=s.max(r),c=new ge(a.x,i.y),h=new ge(i.x,a.y),d=Y.intersectBezier3Line(t,e,n,o,i,c),u=Y.intersectBezier3Line(t,e,n,o,c,a),f=Y.intersectBezier3Line(t,e,n,o,a,h),g=Y.intersectBezier3Line(t,e,n,o,h,i),y=new Y("No Intersection");return y.appendPoints(d.points),y.appendPoints(u.points),y.appendPoints(f.points),y.appendPoints(g.points),y.points.length>0&&(y.status="Intersection"),y}static intersectCircleCircle(t,e,n,o){let s;const r=e+o,i=Math.abs(e-o),a=t.distanceFrom(n);if(a>r)s=new Y("Outside");else if(a<i)s=new Y("Inside");else{s=new Y("Intersection");const c=(e*e-o*o+a*a)/(2*a),h=Math.sqrt(e*e-c*c),d=t.lerp(n,c/a),u=h/a;s.points.push(new ge(d.x-u*(n.y-t.y),d.y+u*(n.x-t.x))),s.points.push(new ge(d.x+u*(n.y-t.y),d.y-u*(n.x-t.x)))}return s}static intersectCircleEllipse(t,e,n,o,s){return Y.intersectEllipseEllipse(t,e,e,n,o,s)}static intersectCircleLine(t,e,n,o){let s;const r=(o.x-n.x)*(o.x-n.x)+(o.y-n.y)*(o.y-n.y),i=2*((o.x-n.x)*(n.x-t.x)+(o.y-n.y)*(n.y-t.y)),a=t.x*t.x+t.y*t.y+n.x*n.x+n.y*n.y-2*(t.x*n.x+t.y*n.y)-e*e,c=i*i-4*r*a;if(c<0)s=new Y("Outside");else if(c===0)s=new Y("Tangent");else{const h=Math.sqrt(c),d=(-i+h)/(2*r),u=(-i-h)/(2*r);(d<0||d>1)&&(u<0||u>1)?d<0&&u<0||d>1&&u>1?s=new Y("Outside"):s=new Y("Inside"):(s=new Y("Intersection"),0<=d&&d<=1&&s.points.push(n.lerp(o,d)),0<=u&&u<=1&&s.points.push(n.lerp(o,u)))}return s}static intersectCirclePolygon(t,e,n){return Y.intersectCirclePolyline(t,e,nn(n))}static intersectCirclePolyline(t,e,n){const o=new Y("No Intersection"),{length:s}=n;let r;for(let i=0;i<s-1;i++){const a=n[i],c=n[i+1];r=Y.intersectCircleLine(t,e,a,c),o.appendPoints(r.points)}return o.points.length>0?o.status="Intersection":o.status=r.status,o}static intersectCircleRectangle(t,e,n,o){const s=n.min(o),r=n.max(o),i=new ge(r.x,s.y),a=new ge(s.x,r.y),c=Y.intersectCircleLine(t,e,s,i),h=Y.intersectCircleLine(t,e,i,r),d=Y.intersectCircleLine(t,e,r,a),u=Y.intersectCircleLine(t,e,a,s),f=new Y("No Intersection");return f.appendPoints(c.points),f.appendPoints(h.points),f.appendPoints(d.points),f.appendPoints(u.points),f.points.length>0?f.status="Intersection":f.status=c.status,f}static intersectEllipseEllipse(t,e,n,o,s,r){const i=[n*n,0,e*e,-2*n*n*t.x,-2*e*e*t.y,n*n*t.x*t.x+e*e*t.y*t.y-e*e*n*n],a=[r*r,0,s*s,-2*r*r*o.x,-2*s*s*o.y,r*r*o.x*o.x+s*s*o.y*o.y-s*s*r*r],h=Hh(i,a).getRoots(),d=.001,u=(i[0]*i[0]+2*i[1]*i[1]+i[2]*i[2])*d,f=(a[0]*a[0]+2*a[1]*a[1]+a[2]*a[2])*d,g=new Y("No Intersection");for(let y=0;y<h.length;y++){const b=new Ue(i[0],i[3]+h[y]*i[1],i[5]+h[y]*(i[4]+h[y]*i[2])).getRoots();for(let w=0;w<b.length;w++){let L=(i[0]*b[w]+i[1]*h[y]+i[3])*b[w]+(i[2]*h[y]+i[4])*h[y]+i[5];Math.abs(L)<u&&(L=(a[0]*b[w]+a[1]*h[y]+a[3])*b[w]+(a[2]*h[y]+a[4])*h[y]+a[5],Math.abs(L)<f&&g.appendPoint(new ge(b[w],h[y])))}}return g.points.length>0&&(g.status="Intersection"),g}static intersectEllipseLine(t,e,n,o,s){let r;const i=new rt(o.x,o.y),a=rt.fromPoints(o,s),c=new rt(t.x,t.y),h=i.subtract(c),d=new rt(a.x/(e*e),a.y/(n*n)),u=new rt(h.x/(e*e),h.y/(n*n)),f=a.dot(d),g=a.dot(u);t=h.dot(u)-1;const y=g*g-f*t;if(y<0)r=new Y("Outside");else if(y>0){const P=Math.sqrt(y),b=(-g-P)/f,w=(-g+P)/f;(b<0||1<b)&&(w<0||1<w)?b<0&&w<0||b>1&&w>1?r=new Y("Outside"):r=new Y("Inside"):(r=new Y("Intersection"),0<=b&&b<=1&&r.appendPoint(o.lerp(s,b)),0<=w&&w<=1&&r.appendPoint(o.lerp(s,w)))}else{const P=-g/f;0<=P&&P<=1?(r=new Y("Intersection"),r.appendPoint(o.lerp(s,P))):r=new Y("Outside")}return r}static intersectEllipsePolygon(t,e,n,o){return Y.intersectEllipsePolyline(t,e,n,nn(o))}static intersectEllipsePolyline(t,e,n,o){const s=new Y("No Intersection"),{length:r}=o;for(let i=0;i<r-1;i++){const a=o[i],c=o[i+1],h=Y.intersectEllipseLine(t,e,n,a,c);s.appendPoints(h.points)}return s.points.length>0&&(s.status="Intersection"),s}static intersectEllipseRectangle(t,e,n,o,s){const r=o.min(s),i=o.max(s),a=new ge(i.x,r.y),c=new ge(r.x,i.y),h=Y.intersectEllipseLine(t,e,n,r,a),d=Y.intersectEllipseLine(t,e,n,a,i),u=Y.intersectEllipseLine(t,e,n,i,c),f=Y.intersectEllipseLine(t,e,n,c,r),g=new Y("No Intersection");return g.appendPoints(h.points),g.appendPoints(d.points),g.appendPoints(u.points),g.appendPoints(f.points),g.points.length>0&&(g.status="Intersection"),g}static intersectLineLine(t,e,n,o){let s;const r=(o.x-n.x)*(t.y-n.y)-(o.y-n.y)*(t.x-n.x),i=(e.x-t.x)*(t.y-n.y)-(e.y-t.y)*(t.x-n.x),a=(o.y-n.y)*(e.x-t.x)-(o.x-n.x)*(e.y-t.y);if(a!==0){const c=r/a,h=i/a;0<=c&&c<=1&&0<=h&&h<=1?(s=new Y("Intersection"),s.points.push(new ge(t.x+c*(e.x-t.x),t.y+c*(e.y-t.y)))):s=new Y("No Intersection")}else r===0||i===0?s=new Y("Coincident"):s=new Y("Parallel");return s}static intersectLinePolygon(t,e,n){return Y.intersectLinePolyline(t,e,nn(n))}static intersectLinePolyline(t,e,n){const o=new Y("No Intersection"),{length:s}=n;for(let r=0;r<s-1;r++){const i=n[r],a=n[r+1],c=Y.intersectLineLine(t,e,i,a);o.appendPoints(c.points)}return o.points.length>0&&(o.status="Intersection"),o}static intersectLineRectangle(t,e,n,o){const s=n.min(o),r=n.max(o),i=new ge(r.x,s.y),a=new ge(s.x,r.y),c=Y.intersectLineLine(s,i,t,e),h=Y.intersectLineLine(i,r,t,e),d=Y.intersectLineLine(r,a,t,e),u=Y.intersectLineLine(a,s,t,e),f=new Y("No Intersection");return f.appendPoints(c.points),f.appendPoints(h.points),f.appendPoints(d.points),f.appendPoints(u.points),f.points.length>0&&(f.status="Intersection"),f}static intersectPolygonPolygon(t,e){return Y.intersectPolylinePolyline(nn(t),nn(e))}static intersectPolygonPolyline(t,e){return Y.intersectPolylinePolyline(nn(t),e)}static intersectPolygonRectangle(t,e,n){return Y.intersectPolylineRectangle(nn(t),e,n)}static intersectPolylinePolyline(t,e){const n=new Y("No Intersection"),{length:o}=t;for(let s=0;s<o-1;s++){const r=t[s],i=t[s+1],a=Y.intersectLinePolyline(r,i,e);n.appendPoints(a.points)}return n.points.length>0&&(n.status="Intersection"),n}static intersectPolylineRectangle(t,e,n){const o=e.min(n),s=e.max(n),r=new ge(s.x,o.y),i=new ge(o.x,s.y),a=Y.intersectLinePolyline(o,r,t),c=Y.intersectLinePolyline(r,s,t),h=Y.intersectLinePolyline(s,i,t),d=Y.intersectLinePolyline(i,o,t),u=new Y("No Intersection");return u.appendPoints(a.points),u.appendPoints(c.points),u.appendPoints(h.points),u.appendPoints(d.points),u.points.length>0&&(u.status="Intersection"),u}static intersectRectangleRectangle(t,e,n,o){const s=t.min(e),r=t.max(e),i=new ge(r.x,s.y),a=new ge(s.x,r.y),c=Y.intersectLineRectangle(s,i,n,o),h=Y.intersectLineRectangle(i,r,n,o),d=Y.intersectLineRectangle(r,a,n,o),u=Y.intersectLineRectangle(a,s,n,o),f=new Y("No Intersection");return f.appendPoints(c.points),f.appendPoints(h.points),f.appendPoints(d.points),f.appendPoints(u.points),f.points.length>0&&(f.status="Intersection"),f}static intersectRayRay(t,e,n,o){let s;const r=(o.x-n.x)*(t.y-n.y)-(o.y-n.y)*(t.x-n.x),i=(e.x-t.x)*(t.y-n.y)-(e.y-t.y)*(t.x-n.x),a=(o.y-n.y)*(e.x-t.x)-(o.x-n.x)*(e.y-t.y);if(a!==0){const c=r/a;s=new Y("Intersection"),s.points.push(new ge(t.x+c*(e.x-t.x),t.y+c*(e.y-t.y)))}else r===0||i===0?s=new Y("Coincident"):s=new Y("Parallel");return s}appendPoint(t){this.points.push(t)}appendPoints(t){this.points=this.points.concat(t)}}class Fn extends en{constructor(){super(...arguments);p(this,"imgBitmap",null);p(this,"fallbackDrawer",new kh);p(this,"broken",!1)}setBroken(e=!0){this.broken=e}setImageBitmap(e){this.imgBitmap=e}get borderProps(){return this.props.get(I.Border)}get cropProps(){return this.props.get(I.Crop)}updateProps(e){super.updateProps(e),e.find(o=>o.type===I.Base)&&this.updateTransformMatrix()}drawOnGLCtx(e){if(!this.imgBitmap){this.broken&&this.fallbackDrawer.fallbackDraw(this,e);return}e.save();const{a:n,b:o,c:s,d:r,e:i,f:a}=this.globalTransform();e.transform(n,o,s,r,i,a),this.clipDrawImage(e,this.imgBitmap),this.clipDrawBorder(e),e.restore()}clipDrawBorder(e){const n=this.borderProps,o=this.cropProps,s=this.baseProps;if(n.color!==""&&n.dashType!==et.None){if(M.setDashLine(n,e),e.strokeStyle=n.color,e.lineWidth=n.width,e.globalAlpha=n.alpha,o.cropType===wt.Circle){const r=.5*Math.min(s.width,s.height);e.beginPath(),e.arc(.5*s.width,.5*s.height,r,0,2*Math.PI),e.stroke();return}if(o.cropType===wt.RoundRect){e.beginPath(),e.roundRect(0,0,s.width,s.height,10),e.stroke();return}e.strokeRect(0,0,s.width,s.height)}}clipDrawImage(e,n){const o=this.cropProps,s=this.baseProps;if(o.cropType===wt.None)e.drawImage(n,0,0,s.width,s.height);else{if(e.save(),o.cropType===wt.RoundRect&&(e.beginPath(),e.roundRect(0,0,s.width,s.height,10),e.clip()),o.cropType===wt.Circle){const b=.5*Math.min(s.width,s.height);e.beginPath(),e.arc(.5*s.width,.5*s.height,b,0,2*Math.PI),e.clip()}const{imgX:r,imgY:i,imgWidth:a,imgHeight:c}=o.cropInfo,h=this.getImgSize(),d=a/h.imgWidth,u=c/h.imgHeight,f=-r/d,g=-i/u,y=s.width/d,P=s.height/u;e.drawImage(n,f,g,y,P,0,0,s.width,s.height),e.restore()}}getImgSize(){if(!this.imgBitmap){console.warn("img bitmap不存在,已经降级处理");const{width:o,height:s}=this.baseProps;return{imgWidth:o,imgHeight:s}}const e=this.imgBitmap.width,n=this.imgBitmap.height;return{imgWidth:e,imgHeight:n}}getOriginImageRect(){const{cropType:e,cropInfo:n}=this.cropProps;if(e===wt.None||!n){const a=this.baseProps;return new D(0,0,a.width,a.height)}const{imgX:o,imgY:s,imgWidth:r,imgHeight:i}=n;return new D(o,s,r,i)}getTextContentRect(){return this.baseProps}getConnectAnchor(){return[new m(.5,0),new m(1,.5),new m(.5,1),new m(0,.5)]}borderContains(e,n){const o=this.toLocal(e),{width:s,height:r}=this.baseProps,i=q.rectangle({top:0,left:0,width:s,height:r}),a=q.line({x:o.x-n,y:o.y},{x:o.x+n,y:o.y}),c=q.line({x:o.x,y:o.y-n},{x:o.x,y:o.y+n});for(const h of[a,c]){const d=Y.intersect(i,h);if(d.points.length>0)return d.points[0]}return null}}class Yn extends Fn{constructor(e,n){super(e,n);p(this,"type",v.IMG);this.props.set(I.Base,new ie),this.props.set(I.Border,new Ae),this.props.set(I.Image,new ro),this.props.set(I.Crop,new Sn)}get imgSrc(){return this.getProp(I.Image).url}static load(e,n,o,s,r,i){const a=new Yn(e,i);return a.type=n,a.zIndex=o,a.setParent(r),a.updateProps(s),a}}class Xh{draw(t,e){const n=t.getDrawPoints();if(n.length<2){console.error("line has no point!");return}const o=n[0],s=n.length>1?n[n.length-1]:{...o};e.beginPath(),e.moveTo(o.x,o.y),e.lineTo(s.x,s.y),e.stroke()}textContentBounds(t){const e=t.baseProps;return{x:e.x,y:e.y,width:e.width,height:e.height}}borderContains(t,e,n){return null}getConnectAnchor(){return[]}}class mi{static lineContainsPoint(t,e,n){const o=t.shapeType,s=[...t.points];return o===de.Line?this.simpleLineContains(s,e,n):t.isPolyLine()?this.polyLineContains(s,e,n):o===de.Curve?this.curveLineContains(s,e,n):!1}static overlapRectNode(t,e){const n=t.shapeType,o=[...t.points],s=q.rectangle({top:e.minY,left:e.minX,width:e.maxX-e.minX,height:e.maxY-e.minY});if(n===de.Line){const r=q.line(o[0],o[o.length-1]);if(Y.intersect(s,r).points.length>0)return!0}if(t.isPolyLine()){const r=q.polyline(o);if(Y.intersect(s,r).points.length>0)return!0}if(n===de.Curve)for(let r=0;r<o.length-2;r=r+3){const i=o[r],a=o[r+1],c=o[r+2],h=o[r+3],d=q.cubicBezier(i,a,c,h);if(Y.intersect(s,d).points.length>0)return!0}return!1}static curveLineContains(t,e,n){for(let o=0;o<t.length-2;o=o+3){const s=t[o],r=t[o+1],i=t[o+2],a=t[o+3],c=q.cubicBezier(s,r,i,a),h=q.circle(e,n);if(Y.intersect(h,c).points.length>0)return!0}return!1}static polyLineContains(t,e,n){const o=q.polyline(t),s=q.circle(e,n);return Y.intersect(s,o).points.length>0}static simpleLineContains(t,e,n){const o=q.line(t[0],t[t.length-1]),s=q.circle(e,n);return Y.intersect(s,o).points.length>0}}class zh{constructor(){p(this,"radius",8)}draw(t,e){const n=t.getDrawPoints();if(n.length<2)return;e.save(),e.beginPath();const o=n[0];e.moveTo(o.x,o.y);for(const s of n)e.lineTo(s.x,s.y);e.stroke(),e.restore()}textContentBounds(t){const e=t.baseProps;return new D(e.x,e.y,e.width,e.height)}borderContains(t,e,n){return null}getConnectAnchor(){return[]}}class Wh{draw(t,e){const n=t.getDrawPoints();if(!(n.length<3)){e.save(),e.beginPath();for(let o=1;o<n.length-2;o=o+3){const s=n[o-1],r=n[o],i=n[o+1],a=n[o+2];e.moveTo(s.x,s.y),e.bezierCurveTo(r.x,r.y,i.x,i.y,a.x,a.y)}e.stroke(),e.restore()}}textContentBounds(t){const e=t.baseProps;return{x:e.x,y:e.y,width:e.width,height:e.height}}borderContains(t,e,n){return null}getConnectAnchor(){return[]}}class Fh{constructor(){p(this,"radius",8)}draw(t,e){const n=t.getDrawPoints();n.length<2||(e.save(),e.beginPath(),t.points.length===2?(e.moveTo(n[0].x,n[0].y),e.lineTo(n[1].x,n[1].y),e.stroke()):this.acrPolyDraw(e,n),e.restore())}textContentBounds(t){const e=t.baseProps;return new D(e.x,e.y,e.width,e.height)}acrPolyDraw(t,e){const n=e[e.length-1],o=this.dealArcPoly(e);for(const s of o)t.moveTo(s.p0.x,s.p0.y),t.lineTo(s.p1.x,s.p1.y),s.arcDraw.r>0&&Number.isFinite(s.arcDraw.r)?t.arcTo(s.arcDraw.a.x,s.arcDraw.a.y,s.arcDraw.b.x,s.arcDraw.b.y,s.arcDraw.r):t.lineTo(s.arcDraw.b.x,s.arcDraw.b.y);t.lineTo(n.x,n.y),t.stroke()}dealArcPoly(t){const e=[];let n=t[0];for(let o=0;o<t.length-2;o=o+1){const s=n,r=t[o+1],i=t[o+2];if(M.judgeHorizon(s,r)){const c=.5*Math.abs(s.x-r.x),h=.5*Math.abs(r.y-i.y),d=c>h?h:c,u=this.radius<d?this.radius:d,f=u,g=r.x>s.x?1:-1,y=i.y>r.y?1:-1;n=new m(r.x,r.y+y*f);const P={p0:s,p1:new m(r.x-g*f,r.y),arcDraw:{a:r,b:n,r:u}};e.push(P)}else{const c=.5*Math.abs(s.y-r.y),h=.5*Math.abs(r.x-i.x),d=c>h?h:c,u=this.radius<d?this.radius:d,f=u,g=r.y>s.y?1:-1,y=i.x>r.x?1:-1;n=new m(r.x+y*f,r.y);const P={p0:s,p1:new m(r.x,r.y-g*f),arcDraw:{a:r,b:n,r:u}};e.push(P)}}return e}borderContains(t,e,n){return null}getConnectAnchor(){return[]}}class Fe{constructor(t,e,n){p(this,"paragraphIndex");p(this,"lineIndex");p(this,"charIndex");this.paragraphIndex=t,this.lineIndex=e,this.charIndex=n}static head(){return new Fe(0,0,-1)}clone(){return new Fe(this.paragraphIndex,this.lineIndex,this.charIndex)}equal(t){return this.paragraphIndex===t.paragraphIndex&&this.lineIndex===t.lineIndex&&this.charIndex===t.charIndex}greaterThan(t){return this.paragraphIndex>t.paragraphIndex?!0:this.paragraphIndex<t.paragraphIndex?!1:this.lineIndex>t.lineIndex?!0:this.lineIndex<t.lineIndex?!1:this.charIndex>t.charIndex?!0:!(this.charIndex<t.charIndex)}}class Cs{constructor(){p(this,"lines",[]);p(this,"index",0);p(this,"x",0);p(this,"y",0);p(this,"width",0);p(this,"height",0);p(this,"paragraphStyle",null)}addLine(t){t.y=this.height,t.index=this.lines.length,this.lines.push(t),this.width=Math.max(t.width,this.width),this.height=this.height+t.height}contains(t){return M.rectContains2(t,{minX:this.x,maxX:this.x+this.width,minY:this.y,maxY:this.y+this.height})}headCursorPosition(){return new Fe(this.index,0,-1)}tailCursorPosition(){if(this.lines.length===0)return new Fe(this.index,-1,-1);const t=this.lines.length-1,n=this.lines[t].getCharLength();return n===0?new Fe(this.index,t,-1):new Fe(this.index,t,n-1)}detect(t){const{x:e,y:n}=t;if(n<0||n>this.height||this.lines.length===0)return null;for(let o=0;o<this.lines.length;o++){const s=this.lines[o];if(n>=s.y&&n<s.y+s.height){const r=new m(t.x-s.x,t.y-s.y),i=s.detect(r);return{lineIndex:s.index,charIndex:i}}}return null}getLine(t){return t<0||this.lines.length===0?null:t>this.lines.length-1?(console.warn("index 超出该段最大数目,fall back处理"),this.lines[this.lines.length-1]):this.lines[t]}draw(t,e){for(const n of this.lines){const o=new m(e.x+this.x,e.y+this.y);n.draw(t,o)}}alignHorizon(t,e){for(const n of this.lines)t===at.Bottom&&(n.x=e-n.width),t===at.Middle&&(n.x=.5*e-.5*n.width)}toString(){let t="";for(const e of this.lines)t+=e.toString();return t+`
|
|
3
|
+
`);let o="<root>";for(const s of n)o=o+"<p>"+s+"</p>";return o+="</root>",o}}class Oe extends ct{constructor(e=1){super();p(this,"type",I.Shape);p(this,"shapeCode",1);this.shapeCode=e}static from(e){const n=new Oe;return n.shapeCode=e.shapeCode,n}update(e){const{shapeCode:n}=e;n!==void 0&&(this.shapeCode=n)}clone(){const e=new Oe;return e.shapeCode=this.shapeCode,e}}class je extends ct{constructor(){super(...arguments);p(this,"type",I.Line);p(this,"points",[]);p(this,"auto",!0)}static create(e,n=!0){const o=new je;return o.auto=n,o.points=e,o}static from(e){const n=new je;return n.points=e.points,n.auto=e.auto,n}clone(){const e=new je,n=[];for(const o of this.points)n.push(M.cloneIPoint(o));return e.points=n,e.auto=this.auto,e}update(e){const{points:n,auto:o}=e;n!==void 0&&(this.points=n),o!==void 0&&(this.auto=o)}}class Rt extends ct{constructor(){super(...arguments);p(this,"type",I.Connect);p(this,"start",null);p(this,"end",null)}static from(e){const n=new Rt;return n.start=e.start,n.end=e.end,n}clone(){const e=new Rt;return e.start=this.start,e.end=this.end,e}update(e){const{start:n,end:o}=e;n!==void 0&&(this.start=n),o!==void 0&&(this.end=o)}}class lt extends ct{constructor(){super(...arguments);p(this,"type",I.Arrow);p(this,"lArrow",it.None);p(this,"rArrow",it.None)}static create(e){const n=new lt;return n.update(e),n}static from(e){const n=new lt;return n.lArrow=e.lArrow,n.rArrow=e.rArrow,n}clone(){const e=new lt;return e.rArrow=this.rArrow,e.lArrow=this.lArrow,e}update(e){const{lArrow:n,rArrow:o}=e;n!==void 0&&(this.lArrow=n),o!==void 0&&(this.rArrow=o)}}var ue=(l=>(l[l.Top=0]="Top",l[l.Right=1]="Right",l[l.Bottom=2]="Bottom",l[l.Left=3]="Left",l))(ue||{});class Et extends ct{constructor(){super(...arguments);p(this,"type",I.LineTextRect);p(this,"width",20);p(this,"height",20);p(this,"x",0);p(this,"y",0);p(this,"point",{x:0,y:0})}static from(e){const n=new Et;return n.width=e.width,n.height=e.height,n.x=e.x,n.y=e.y,n.point=e.point,n}update(e){const{x:n,y:o,point:s,height:r,width:i}=e;n!==void 0&&(this.x=n),o!==void 0&&(this.y=o),r!==void 0&&(this.height=r),i!==void 0&&(this.width=i),s!==void 0&&(this.point=s)}clone(){const e=new Et;return e.width=this.width,e.height=this.height,e.x=this.x,e.y=this.y,e.point=this.point,e}}var N=(l=>(l[l.HoverBounds=0]="HoverBounds",l[l.HoverLine=1]="HoverLine",l[l.SelectLine=2]="SelectLine",l[l.MultiSelectBound=3]="MultiSelectBound",l[l.TextSelection=4]="TextSelection",l[l.SelectGroup=5]="SelectGroup",l[l.SelectRect=6]="SelectRect",l[l.HighLightLine=7]="HighLightLine",l[l.AlignLine=8]="AlignLine",l[l.AlignStretchLine=9]="AlignStretchLine",l[l.SingleSelectBound=10]="SingleSelectBound",l[l.RotateLine=11]="RotateLine",l[l.HighlightRects=12]="HighlightRects",l[l.CreateRectBound=13]="CreateRectBound",l[l.ExpandShape=14]="ExpandShape",l[l.SelectLineEnd=15]="SelectLineEnd",l[l.HoverConnectPoint=16]="HoverConnectPoint",l[l.HoverConnectAnchorPoint=17]="HoverConnectAnchorPoint",l[l.HoverAnchorPoint=18]="HoverAnchorPoint",l[l.SelectPolyLineControlPoint=19]="SelectPolyLineControlPoint",l[l.SelectLineTextRect=20]="SelectLineTextRect",l[l.PlaceHolder=21]="PlaceHolder",l[l.SelectConnectAnchor=22]="SelectConnectAnchor",l[l.HoverConnectAnchor=23]="HoverConnectAnchor",l[l.PreviewGraphics=24]="PreviewGraphics",l[l.HoverContainer=25]="HoverContainer",l[l.CropBounds=26]="CropBounds",l[l.CropOriginImg=27]="CropOriginImg",l[l.StretchRect=28]="StretchRect",l[l.HoverSize=29]="HoverSize",l[l.SelectCurveControlPoint=30]="SelectCurveControlPoint",l[l.SelectCurveEnd=31]="SelectCurveEnd",l[l.SelectParentGroupBound=32]="SelectParentGroupBound",l[l.SelectSlideGapInsertPoint=33]="SelectSlideGapInsertPoint",l[l.HoverSlidePlaceHolder=34]="HoverSlidePlaceHolder",l[l.HoverInsertSlide=35]="HoverInsertSlide",l[l.HoverInsertHorizonSlide=36]="HoverInsertHorizonSlide",l[l.HoverSlideGapInsertPoint=37]="HoverSlideGapInsertPoint",l[l.HoverFocusCopy=38]="HoverFocusCopy",l))(N||{});class Se{constructor(){p(this,"prop")}update(t){this.prop=t}}const Ht="#FFFFFF",bs="#000000",Gt="#647ee5",Qe="#545DE7",Ms="#32a8f2",Wr="#3370FF",Fr=8,Yr=18,Gr=5,Ss=11,Ur="#CCCCCC",_r="#B7BEF5",$r="#DADEFA";class jr extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.HoverBounds)}draw(e,n){const{node:o,transform:s}=this.prop;e.save(),e.strokeStyle=Gt,e.lineWidth=2/n,e.globalAlpha=1;const{x:r,y:i,width:a,height:c}=o.baseProps,{a:h,b:d,c:u,d:f,e:g,f:y}=s;e.transform(h,d,u,f,g,y),e.beginPath(),e.strokeRect(0,0,a,c),e.restore()}}class Vr extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.SingleSelectBound)}draw(e,n){const{x:o,y:s,width:r,height:i,transform:a}=this.prop;e.save(),e.strokeStyle=Qe,e.lineWidth=1/n,e.globalAlpha=1;const{a:c,b:h,c:d,d:u,e:f,f:g}=a;e.transform(c,h,d,u,f,g),e.beginPath(),e.strokeRect(o,s,r,i),e.restore()}}class Kr extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.MultiSelectBound)}draw(e,n){const{rect:o}=this.prop;e.save(),e.strokeStyle=Qe,e.lineWidth=1/n,e.globalAlpha=1;const{x:s,y:r,width:i,height:a}=o;e.beginPath(),e.strokeRect(s,r,i,a),e.restore()}}class Qr extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.HighlightRects)}draw(e,n){const{rects:o}=this.prop;for(const s of o){e.save(),e.strokeStyle=Qe,e.lineWidth=1/n,e.globalAlpha=1;const{x:r,y:i,width:a,height:c}=s;e.beginPath(),e.strokeRect(r,i,a,c),e.restore()}}}class Zr extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.SelectGroup)}draw(e,n){const{rect:o,isPrecise:s}=this.prop;e.save(),e.beginPath(),e.strokeStyle=Ms,e.fillStyle=Ms,s&&e.setLineDash([2,2]),e.rect(o.x,o.y,o.width,o.height),e.lineWidth=1/n,e.stroke(),e.globalAlpha=.2,e.fill(),e.restore()}}class qr extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.TextSelection)}draw(e){const{selectionList:n,node:o}=this.prop;if(n.length===0)return;e.save(),e.fillStyle=Wr,e.globalAlpha=.5;const{a:s,b:r,c:i,d:a,e:c,f:h}=o.globalTransform();e.transform(s,r,i,a,c,h);for(const d of n)e.fillRect(d.x,d.y,d.width,d.height);e.restore()}}class Jr{static computeStretchRects(t,e){const n=Fr/e,o=.5*n;return[new D(t.x-o,t.y-o,n,n),new D(t.x+t.width-o,t.y-o,n,n),new D(t.x+t.width-o,t.y+t.height-o,n,n),new D(t.x-o,t.y+t.height-o,n,n)]}}class ei extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.StretchRect)}draw(e,n){const{rect:o,transform:s}=this.prop,r=Jr.computeStretchRects(o,n);e.save();const{a:i,b:a,c,d:h,e:d,f:u}=s;e.transform(i,a,c,h,d,u),e.strokeStyle=Qe,e.fillStyle=Ht,e.lineWidth=1/n,e.globalAlpha=1,e.beginPath();for(const f of r)e.roundRect(f.x,f.y,f.width,f.height,1/n),e.fill(),e.stroke();e.restore()}}class ti extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.CreateRectBound)}draw(e,n){const{rect:o,transform:s}=this.prop;e.save();const{a:r,b:i,c:a,d:c,e:h,f:d}=s;e.transform(r,i,a,c,h,d),e.strokeStyle=Qe,e.lineWidth=1/n,e.globalAlpha=1;const{width:u,height:f}=o;e.beginPath(),e.strokeRect(0,0,u,f),e.restore()}}class ni extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.ExpandShape)}draw(e,n){const{rect:o,transform:s}=this.prop,{width:r,height:i}=o,a=1.5/n,c=re.generateMatrix().scale(a,a),h=re.generateMatrix().translate(.5*r-.5*a*14,i-.5*a*8),d=s.crossProduct(h.crossProduct(c));e.save(),e.beginPath();const{a:u,b:f,c:g,d:y,e:P,f:b}=d;e.transform(u,f,g,y,P,b),e.fillStyle=Qe,e.roundRect(0,0,14,7.58333,2),e.fill(),e.beginPath(),e.fillStyle=Ht,e.rect(1.75,2.91666,2.33333,2.33333),e.rect(5.83333,2.91666,2.33333,2.33333),e.rect(9.91667,2.91666,2.33333,2.33333),e.fill(),e.restore()}}class oi extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.AlignLine)}draw(e,n){const{lines:o}=this.prop;e.save(),e.beginPath(),e.strokeStyle=Qe,e.lineWidth=1/n,e.globalAlpha=1,e.setLineDash([4,2]);for(const s of o){const{start:r,end:i}=s;e.moveTo(r.x,r.y),e.lineTo(i.x,i.y)}e.stroke(),e.restore()}}class si extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.AlignStretchLine)}draw(e,n){const o=10/n,{alignInfo:s}=this.prop,{width:r,height:i}=s;e.save(),e.beginPath(),e.strokeStyle=Qe,e.lineWidth=1/n,e.globalAlpha=1,r&&this.drawWidth(e,r,o),i&&this.drawHeight(e,i,o),e.restore()}drawWidth(e,n,o){const{lines:s}=n;for(const r of s){const{line:i,transform:a}=r,{start:c,end:h}=i;e.save();const{a:d,b:u,c:f,d:g,e:y,f:P}=a;e.transform(d,u,f,g,y,P);const b={x:c.x,y:c.y},w={x:c.x,y:c.y+2*o};e.moveTo(b.x,b.y),e.lineTo(w.x,w.y);const L={x:h.x,y:h.y},B={x:h.x,y:h.y+2*o};e.moveTo(L.x,L.y),e.lineTo(B.x,B.y),e.moveTo(c.x,c.y+o),e.lineTo(h.x,h.y+o),e.stroke(),e.restore()}}drawHeight(e,n,o){const{lines:s}=n;for(const r of s){const{line:i,transform:a}=r,{start:c,end:h}=i;e.save();const{a:d,b:u,c:f,d:g,e:y,f:P}=a;e.transform(d,u,f,g,y,P);const b={x:c.x,y:c.y},w={x:c.x+2*o,y:c.y};e.moveTo(b.x,b.y),e.lineTo(w.x,w.y);const L={x:h.x,y:h.y},B={x:h.x+2*o,y:h.y};e.moveTo(L.x,L.y),e.lineTo(B.x,B.y),e.moveTo(c.x+o,c.y),e.lineTo(h.x+o,h.y),e.stroke(),e.restore()}}}class Gl extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.SingleSelectBound)}draw(e,n){const{start:o,end:s,transform:r}=this.prop,i=5/n;e.save();const{a,b:c,c:h,d,e:u,f}=r;e.transform(a,c,h,d,u,f),e.strokeStyle=Qe,e.fillStyle=Ht,e.lineWidth=2/n,e.globalAlpha=1,e.beginPath(),e.arc(o.x,o.y,i,0,2*Math.PI),e.fill(),e.stroke(),e.beginPath(),e.arc(s.x,s.y,i,0,2*Math.PI),e.fill(),e.stroke(),e.restore()}}class Ul extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.HoverLine)}draw(e,n){const{node:o,transform:s}=this.prop;e.save();const{a:r,b:i,c:a,d:c,e:h,f:d}=s;e.transform(r,i,a,c,h,d),e.strokeStyle=Gt,e.lineWidth=2/n,e.globalAlpha=1,e.beginPath(),o.drawer.draw(o,e),e.restore()}}class _l extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.SelectLine)}draw(e,n){const{node:o}=this.prop;e.save();const{a:s,b:r,c:i,d:a,e:c,f:h}=o.globalTransform();e.transform(s,r,i,a,c,h),e.strokeStyle=Qe,e.lineWidth=2/n,e.globalAlpha=1,e.beginPath(),o.drawer.draw(o,e),e.restore()}}class $l extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.HoverConnectPoint)}draw(e,n){const{point:o}=this.prop,s=4/n;e.save(),e.fillStyle=Gt,e.strokeStyle=Gt,e.lineWidth=2/n,e.globalAlpha=1,e.beginPath(),e.arc(o.x,o.y,s,0,2*Math.PI),e.fill(),e.restore()}}class jl extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.HoverConnectAnchorPoint)}draw(e,n){const{node:o}=this.prop;if(!o.canQuickCreate())return;const s=5/n,{width:r,height:i}=o.baseProps,{a,b:c,c:h,d,e:u,f}=o.globalTransform(),g=o.getConnectAnchor(),y=[];for(const P of g)y.push(new m(P.x*r,P.y*i));e.save(),e.transform(a,c,h,d,u,f),e.fillStyle=Ht,e.strokeStyle=Qe;for(const P of y)e.beginPath(),e.arc(P.x,P.y,s,0,2*Math.PI),e.fill(),e.stroke();e.restore()}}class Vl extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.HoverConnectAnchorPoint)}draw(e,n){const{node:o,localPoint:s}=this.prop;if(!o.canBeConnected())return;const r=6/n,{a:i,b:a,c,d:h,e:d,f:u}=o.globalTransform();e.save(),e.transform(i,a,c,h,d,u),e.fillStyle=Gt,e.beginPath(),e.arc(s.x,s.y,r,0,2*Math.PI),e.fill(),e.stroke(),e.restore()}}const A=22;class Kl extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.SelectPolyLineControlPoint)}draw(e,n){const{points:o,transform:s}=this.prop;e.save(),e.fillStyle=Qe,e.strokeStyle=Ht,e.lineWidth=2/n,e.globalAlpha=1;const{a:r,b:i,c:a,d:c,e:h,f:d}=s;e.transform(r,i,a,c,h,d);for(let u=0;u<o.length-1;u++){const f=o[u],g=o[u+1];if(M.distance(f,g)<(A+6)/n)continue;const P=M.judgeHorizon(f,g),b=.5*(f.x+g.x),w=.5*(f.y+g.y);if(e.beginPath(),P){const L=new m(b-6/n,w);e.roundRect(L.x,L.y-2/n,12/n,4/n,2/n)}else{const L=new m(b,w-6/n);e.roundRect(L.x-2/n,L.y,4/n,12/n,2/n)}e.stroke(),e.fill()}e.restore()}}class Ql extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.SelectLineTextRect)}draw(e,n){const{node:s,transform:r}=this.prop,i=s.getTextContentRect();e.save();const{a,b:c,c:h,d,e:u,f}=r;e.transform(a,c,h,d,u,f),e.strokeStyle=Qe,e.lineWidth=2/n,e.globalAlpha=1,e.beginPath(),e.strokeRect(i.x-2,i.y-2,i.width+2*2,i.height+2*2),e.restore()}}const ri="输入文本";class Zl extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.PlaceHolder)}draw(e,n){const{node:o}=this.prop,s=o.shapeType!==K.PureText,r=o.renderText,i=r.paragraphs[0],a=i.lines[0],c=r.x+i.x+a.x,h=r.y+i.y+a.y,{fontSize:d,fontFamily:u,bold:f,italic:g}=r.textProps;e.save();const{a:y,b:P,c:b,d:w,e:L,f:B}=o.globalTransform();e.transform(y,P,b,w,L,B),e.textAlign="left",e.textBaseline="alphabetic",e.fillStyle="#000000",e.globalAlpha=.5,e.font=M.calcFont(d,u,f,g);const H=e.measureText(ri),E=H.fontBoundingBoxAscent,X=H.width,$=s?c-.5*X:c;e.fillText(ri,$,h+E),e.restore()}}class ql extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.SelectConnectAnchor)}draw(e,n){const{node:o}=this.prop,s=Gr/n,r=M.computeNodeConnectAnchor(o,n);e.save(),e.fillStyle=_r,e.globalAlpha=1;const{a:i,b:a,c,d:h,e:d,f:u}=o.globalTransform();e.transform(i,a,c,h,d,u);for(const f of r)e.beginPath(),e.arc(f.x,f.y,s,0,2*Math.PI),e.fill();e.restore()}}class Jl extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.HoverConnectAnchor)}draw(e,n){const{point:o}=this.prop,s=Ss/n;e.save(),e.strokeStyle=Qe,e.fillStyle=$r,e.globalAlpha=1,e.lineWidth=2/n,e.beginPath(),e.arc(o.x,o.y,s,0,2*Math.PI),e.fill(),e.stroke(),e.restore()}}class eh extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.PreviewGraphics)}draw(e,n){const{previewNodes:o}=this.prop;for(const s of o)s.drawOnGLCtx(e)}}class th extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.HoverContainer)}draw(e,n){const{node:o}=this.prop;e.save(),e.strokeStyle=Gt,e.lineWidth=2/n,e.globalAlpha=1;const{width:s,height:r}=o.baseProps,{a:i,b:a,c,d:h,e:d,f:u}=o.globalTransform();e.transform(i,a,c,h,d,u),e.beginPath(),e.strokeRect(0,0,s,r),e.restore()}}class nh extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.CropBounds)}draw(e,n){const{node:o,transform:s}=this.prop,r=12/n;e.save(),e.strokeStyle=bs,e.lineWidth=2/n,e.globalAlpha=1;const{width:i,height:a}=o.baseProps,{a:c,b:h,c:d,d:u,e:f,f:g}=s;e.transform(c,h,d,u,f,g),e.beginPath(),e.moveTo(0,r),e.lineTo(0,0),e.lineTo(r,0),e.moveTo(i-r,0),e.lineTo(i,0),e.lineTo(i,r),e.moveTo(i-r,a),e.lineTo(i,a),e.lineTo(i,a-r),e.moveTo(0,a-r),e.lineTo(0,a),e.lineTo(r,a),e.moveTo(.5*i-.5*r,0),e.lineTo(.5*i+.5*r,0),e.moveTo(.5*i-.5*r,a),e.lineTo(.5*i+.5*r,a),e.moveTo(0,.5*a-.5*r),e.lineTo(0,.5*a+.5*r),e.moveTo(i,.5*a-.5*r),e.lineTo(i,.5*a+.5*r),e.stroke(),e.beginPath(),e.setLineDash([2,2]),e.lineWidth=1/n,e.strokeRect(0,0,i,a),e.restore()}}class oh extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.CropOriginImg)}draw(e,n){const{imgBitmap:o,transform:s,x:r,y:i,width:a,height:c}=this.prop;e.save();const{a:h,b:d,c:u,d:f,e:g,f:y}=s;e.transform(h,d,u,f,g,y),e.globalAlpha=.4,e.drawImage(o,r,i,a,c),e.restore()}}class sh extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.HoverSize)}draw(e,n){const{rect:o,transform:s}=this.prop,{width:r,height:i}=o,a=Math.round(r),c=Math.round(i),h=`${a}x${c}`,d=12/n,u="Noto Sans",f=M.measureTextByFont(e,h,d,"Noto Sans",!1,!1);e.save();const g=re.generateMatrix().translate(r-f.width,i),{a:y,b:P,c:b,d:w,e:L,f:B}=s.crossProduct(g);e.transform(y,P,b,w,L,B),e.fillStyle=Qe,e.globalAlpha=1,e.fillRect(0,0,f.width,f.height),e.fillStyle=Ht,e.font=M.calcFont(d,u),e.textAlign="left",e.textBaseline="top",e.fillText(h,0,2/n),e.restore()}}class rh extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.SingleSelectBound)}draw(e,n){const{points:o,transform:s}=this.prop,r=5/n;e.save();const{a:i,b:a,c,d:h,e:d,f:u}=s;e.transform(i,a,c,h,d,u),e.strokeStyle=Qe,e.fillStyle=Qe,e.lineWidth=2/n,e.globalAlpha=1;for(const f of o)e.beginPath(),e.arc(f.x,f.y,r,0,2*Math.PI),e.fill(),e.stroke();e.restore()}}class ih extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.SelectCurveEnd)}draw(e,n){const{points:o,transform:s}=this.prop,r=5/n;e.save();const{a:i,b:a,c,d:h,e:d,f:u}=s;e.transform(i,a,c,h,d,u),e.strokeStyle=Qe,e.fillStyle=Ht,e.lineWidth=2/n,e.globalAlpha=1;for(const f of o)e.beginPath(),e.arc(f.x,f.y,r,0,2*Math.PI),e.fill(),e.stroke();e.restore()}}class ah extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.SelectParentGroupBound)}draw(e,n){const{node:o}=this.prop;e.save(),e.strokeStyle=Gt,e.lineWidth=1/n,e.globalAlpha=1;const{width:s,height:r}=o.baseProps,{a:i,b:a,c,d:h,e:d,f:u}=o.nameGlobalTransform();e.transform(i,a,c,h,d,u),e.beginPath(),e.strokeRect(0,0,s,r),e.restore()}}class ch extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.HoverSlidePlaceHolder)}draw(e,n){const{baseProps:o}=this.prop;e.save(),e.fillStyle=Ur,e.lineWidth=2/n,e.globalAlpha=.5;const{x:s,y:r,width:i,height:a}=o;e.beginPath(),e.roundRect(s,r,i,a,10),e.fill(),e.restore()}}class lh extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.HoverFocusCopy)}draw(e,n){const{nodes:o}=this.prop;e.save();for(const s of o)s.drawOnGLCtx(e);e.restore()}}class hh extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.HoverInsertSlide)}draw(e,n){const{x:o,y1:s,y0:r}=this.prop;e.save(),e.strokeStyle=Gt,e.lineWidth=2/n,e.globalAlpha=1,e.moveTo(o,r),e.lineTo(o,s),e.stroke(),e.restore()}}class dh extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.HoverInsertHorizonSlide)}draw(e,n){const{x0:o,x1:s,y:r}=this.prop;e.save(),e.strokeStyle=Gt,e.lineWidth=2/n,e.globalAlpha=1,e.moveTo(o,r),e.lineTo(s,r),e.stroke(),e.restore()}}class uh extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.HoverSlideGapInsertPoint)}draw(e,n){const{point:o}=this.prop,s=10/n;e.save(),e.fillStyle=Qe,e.globalAlpha=1,e.beginPath(),e.arc(o.x,o.y,s,0,2*Math.PI),e.fill();const r=6/n;e.strokeStyle=Ht,e.lineWidth=2.5/n,e.lineCap="square",e.beginPath(),e.moveTo(o.x-r,o.y),e.lineTo(o.x+r,o.y),e.moveTo(o.x,o.y-r),e.lineTo(o.x,o.y+r),e.stroke(),e.restore()}}class ph extends Se{constructor(){super(...arguments);p(this,"auxiliaryType",N.SelectSlideGapInsertPoint)}draw(e,n){const{points:o}=this.prop,s=6/n;e.save(),e.fillStyle=Qe,e.globalAlpha=.9,e.beginPath();for(const r of o){e.beginPath(),e.arc(r.x,r.y,s,0,2*Math.PI),e.fill();const i=3.6/n;e.strokeStyle=Ht,e.lineWidth=1.5/n,e.lineCap="square",e.beginPath(),e.moveTo(r.x-i,r.y),e.lineTo(r.x+i,r.y),e.moveTo(r.x,r.y-i),e.lineTo(r.x,r.y+i),e.stroke()}e.restore()}}class vs{static create(t){const e=this.constructorMap[t];return e?new e:(console.error("缺少对应构造函数"),null)}}p(vs,"constructorMap",{[N.HoverBounds]:jr,[N.SingleSelectBound]:Vr,[N.MultiSelectBound]:Kr,[N.HighlightRects]:Qr,[N.SelectGroup]:Zr,[N.TextSelection]:qr,[N.StretchRect]:ei,[N.CreateRectBound]:ti,[N.ExpandShape]:ni,[N.AlignLine]:oi,[N.AlignStretchLine]:si,[N.SelectLineEnd]:Gl,[N.HoverLine]:Ul,[N.SelectLine]:_l,[N.HoverConnectPoint]:$l,[N.HoverConnectAnchorPoint]:jl,[N.HoverAnchorPoint]:Vl,[N.SelectPolyLineControlPoint]:Kl,[N.SelectLineTextRect]:Ql,[N.PlaceHolder]:Zl,[N.SelectConnectAnchor]:ql,[N.HoverConnectAnchor]:Jl,[N.PreviewGraphics]:eh,[N.HoverContainer]:th,[N.CropBounds]:nh,[N.CropOriginImg]:oh,[N.HoverSize]:sh,[N.SelectCurveControlPoint]:rh,[N.SelectCurveEnd]:ih,[N.SelectParentGroupBound]:ah,[N.HoverSlidePlaceHolder]:ch,[N.HoverFocusCopy]:lh,[N.HoverInsertSlide]:hh,[N.HoverInsertHorizonSlide]:dh,[N.HoverSlideGapInsertPoint]:uh,[N.SelectSlideGapInsertPoint]:ph});class ii{constructor(){p(this,"isWorking",!1);p(this,"idList",[]);p(this,"originX",0);p(this,"originY",0)}startWorking(t,e,n){this.idList=t,this.originX=e,this.originY=n,this.isWorking=!0}selectChange(t){if(!this.isWorking)return;t.size!==this.idList.length&&this.stopWork();const e=new Set(this.idList);for(const n of t)e.has(n.id)||this.stopWork(),e.delete(n.id);e.size!==0&&this.stopWork()}stopWork(){this.idList=[],this.isWorking=!1}}class bt{}const fh=new Set([v.Shape,v.SVG,v.IMG,v.Group,v.Section,v.Checkbox,v.CheckboxText]);class ai extends bt{enable(t){return t.length===1&&fh.has(t[0].type)}handle(t,e){const n=t[0],o=n.globalTransform().clone(),{width:s,height:r}=n.baseProps;e.addOrUpdate(N.SingleSelectBound,{x:0,y:0,width:s,height:r,transform:o}),n.parent&&n.parent.type===v.Group&&e.addOrUpdate(N.SelectParentGroupBound,{node:n.parent});const i=D.baseProps2Rect(n.baseProps);if(t.filter(c=>M.judgeNodeCanBeStretch(c)).length>0&&e.addOrUpdate(N.StretchRect,{transform:o,rect:new D(0,0,i.width,i.height)}),n.canQuickCreate()&&e.addOrUpdate(N.SelectConnectAnchor,{node:n}),n instanceof vt&&n.shapeType!==K.PureText){const h=n.drawer.fullTextNodeHeight(n);n.baseProps.height<h&&e.addOrUpdate(N.ExpandShape,{transform:o,rect:i})}}}class ci extends bt{enable(t){return t.length>1}handle(t,e){const n=[],o=[];t.forEach(i=>{const a=i.getBounds();n.push(a),o.push(D.rectNode2Rect(a))});const s=M.getBounds(n),r=D.rectNode2Rect(s);e.addOrUpdate(N.MultiSelectBound,{rect:r}),e.addOrUpdate(N.HighlightRects,{rects:o}),e.addOrUpdate(N.StretchRect,{rect:new D(0,0,r.width,r.height),transform:re.generateMatrix().translate(r.x,r.y)})}}var ze=(l=>(l[l.Scale=0]="Scale",l[l.Focus=1]="Focus",l[l.FocusPropsChange=2]="FocusPropsChange",l[l.ToolChange=3]="ToolChange",l[l.QuickCreate=4]="QuickCreate",l[l.ClickImg=5]="ClickImg",l[l.ImgUrls=6]="ImgUrls",l[l.ContextMenu=7]="ContextMenu",l[l.ExitCrop=8]="ExitCrop",l[l.DocMode=9]="DocMode",l[l.SlideCovers=10]="SlideCovers",l[l.SlideIndex=11]="SlideIndex",l))(ze||{});class li{constructor(){p(this,"slotMap",new Map);p(this,"slotCallBack",new Map);p(this,"working",!1);p(this,"tickerRun",()=>{for(const[t,e]of this.slotMap){const n=this.slotCallBack.get(t);n&&n(e)}this.slotMap.clear(),this.working&&requestAnimationFrame(this.tickerRun)})}start(){this.working=!0,this.tickerRun()}stop(){this.working=!1}reset(){this.slotMap.clear()}addSlotState(t,e){this.slotMap.set(t,e)}registerSlotCallback(t,e){this.slotCallBack.set(t,e)}}class gh extends bt{enable(t){return t.length===1&&t[0].type===v.Line}handle(t,e){const n=t[0],o=n.points,s=n.globalTransform();e.addOrUpdate(N.SelectLineEnd,{start:o[0],end:o[o.length-1],transform:s})}}class yh extends bt{enable(t){if(t.length!==1)return!1;const e=t[0];return e.type!==v.Line?!1:!!e.isPolyLine()}handle(t,e){const n=t[0],o=n.points,s=n.globalTransform();e.addOrUpdate(N.SelectLineEnd,{start:o[0],end:o[o.length-1],transform:s}),e.addOrUpdate(N.SelectPolyLineControlPoint,{points:n.points,transform:s})}}class xh extends bt{enable(t,e){if(t.length!==1)return!1;const n=t[0];if(n.type!==v.Line)return!1;const o=e.inputManager.editTextInfo;if(!o)return!1;const s=n;return o.node.id===s.id}handle(t,e){const n=t[0];e.addOrUpdate(N.SelectLineTextRect,{node:n,transform:n.globalTransform()})}}class wh extends bt{enable(t){return t.length===1&&t[0].type===v.Group}handle(t,e){const n=t[0],o=n.nameGlobalTransform().clone(),{width:s,height:r}=n.baseProps;e.addOrUpdate(N.SingleSelectBound,{x:0,y:0,width:s,height:r,transform:o}),n.parent&&n.parent.type===v.Group&&e.addOrUpdate(N.SelectParentGroupBound,{node:n.parent});const i=D.baseProps2Rect(n.baseProps);e.addOrUpdate(N.StretchRect,{transform:o,rect:new D(0,0,i.width,i.height)})}}const mh=new Set([v.SVG,v.IMG]);class Ph extends bt{enable(t,e){if(t.length!==1)return!1;const n=t[0];return!(!mh.has(n.type)||!e.cropManager.duringCrop||!n.imgBitmap)}handle(t,e){const n=t[0],o=n.globalTransform().clone();e.addOrUpdate(N.CropBounds,{node:n,transform:o});const{cropType:s,cropInfo:r}=n.cropProps,{x:i,y:a,width:c,height:h}=n.baseProps;if(s===0||!r){e.addOrUpdate(N.SingleSelectBound,{x:0,y:0,width:c,height:h,transform:o});const d=new D(0,0,c,h);e.addOrUpdate(N.StretchRect,{transform:o,rect:d})}else{const d=n.getOriginImageRect();e.addOrUpdate(N.SingleSelectBound,{x:d.x,y:d.y,width:d.width,height:d.height,transform:o}),e.addOrUpdate(N.StretchRect,{transform:o,rect:d}),e.addOrUpdate(N.CropOriginImg,{x:d.x,y:d.y,width:d.width,height:d.height,transform:o,imgBitmap:n.imgBitmap})}}}class bh extends bt{enable(t){return t.length===1&&t[0].type===v.Line&&t[0].shapeType===de.Curve}handle(t,e){const n=t[0],o=n.globalTransform();e.addOrUpdate(N.SelectCurveEnd,{points:M.computeCurveEndPoints(n),transform:o}),e.addOrUpdate(N.SelectCurveControlPoint,{points:M.computeCurveControlPoints(n),transform:o})}}const Mh=new Set([v.Shape,v.SVG,v.IMG,v.Group,v.Section,v.Checkbox,v.CheckboxText]);class Sh extends bt{enable(t,e){return!e.docState.userPermission.canEdit&&t.length===1}handle(t,e){const n=t[0];if(n.type===v.Group){this.handleGroup(n,e);return}if(n instanceof Ct){this.handleLine(n,e);return}if(Mh.has(n.type)){this.handleNormalNode(n,e);return}}handleNormalNode(t,e){const n=t.globalTransform().clone(),{width:o,height:s}=t.baseProps;e.addOrUpdate(N.SingleSelectBound,{x:0,y:0,width:o,height:s,transform:n}),t.parent&&t.parent.type===v.Group&&e.addOrUpdate(N.SelectParentGroupBound,{node:t.parent})}handleLine(t,e){e.addOrUpdate(N.SelectLine,{node:t})}handleGroup(t,e){const n=t.nameGlobalTransform().clone(),{width:o,height:s}=t.baseProps;e.addOrUpdate(N.SingleSelectBound,{x:0,y:0,width:o,height:s,transform:n}),t.parent&&t.parent.type===v.Group&&e.addOrUpdate(N.SelectParentGroupBound,{node:t.parent})}}class vh extends bt{enable(t,e){return!e.docState.userPermission.canEdit&&t.length>1}handle(t,e){const n=[],o=[];t.forEach(i=>{const a=i.getBounds();n.push(a),o.push(D.rectNode2Rect(a))});const s=M.getBounds(n),r=D.rectNode2Rect(s);e.addOrUpdate(N.MultiSelectBound,{rect:r}),e.addOrUpdate(N.HighlightRects,{rects:o})}}class Ih extends bt{enable(t){return t.length===1&&t[0].type===v.SlideContainer}handle(t,e){const n=t[0],o=n.globalTransform().clone(),{width:s,height:r}=n.baseProps;e.addOrUpdate(N.SingleSelectBound,{x:0,y:0,width:s,height:r,transform:o}),n.parent&&n.parent.type===v.Group&&e.addOrUpdate(N.SelectParentGroupBound,{node:n.parent})}}const Th=5,nt=50,xt=40;class Lh extends bt{enable(t){var e;return t.length===1&&((e=t[0].parent)==null?void 0:e.type)===v.SlideContainer}handle(t,e){const n=t[0],o=n.globalTransform().clone(),{x:s,y:r,height:i,width:a}=n.globalBaseProps;e.addOrUpdate(N.SingleSelectBound,{x:0,y:0,width:a,height:i,transform:o});const c=[{x:s-nt/2,y:r+i/2},{x:s+a+nt/2,y:r+i/2}];e.addOrUpdate(N.SelectSlideGapInsertPoint,{points:c})}}var he=(l=>(l[l.BOARD=0]="BOARD",l[l.SLIDE_EDIT=1]="SLIDE_EDIT",l[l.SLIDE_PLAY=2]="SLIDE_PLAY",l))(he||{});class Ch extends bt{enable(t,e){var n;return t.length===1&&((n=t[0].parent)==null?void 0:n.type)===v.SlideContainer&&e.docState.docMode===he.SLIDE_EDIT}handle(t,e){const n=t[0],o=n.globalTransform().clone(),{x:s,y:r,height:i,width:a}=n.globalBaseProps;e.addOrUpdate(N.SingleSelectBound,{x:0,y:0,width:a,height:i,transform:o})}}class hi{constructor(t,e,n,o){p(this,"selectNodes",new Set);p(this,"optionHelper");p(this,"auxiliaryManager");p(this,"inputManager");p(this,"cropManager");p(this,"docState");p(this,"statusHandlers",[new Sh,new vh,new Ih,new wh,new xh,new yh,new bh,new gh,new Ph,new Ch,new Lh,new ai,new ci]);this.auxiliaryManager=e,this.optionHelper=new ii,this.cropManager=n,this.docState=o}register(t){this.inputManager=t}reset(){this.selectNodes.clear()}refreshSelectStatus(){this.auxiliaryManager.removeSelectGraphics();const t=[...this.selectNodes],e=this.selectStatusContext();for(const n of this.statusHandlers)if(n.enable(t,e)){n.handle(t,this.auxiliaryManager);return}}selectStatusContext(){return{inputManager:this.inputManager,cropManager:this.cropManager,docState:this.docState}}getSelectNodes(){return[...this.selectNodes]}getSelectBounds(){const t=[];for(const e of this.selectNodes)t.push(e.getBounds());return M.getBounds(t,"selectBounds")}set(t){this.selectNodes=t,this.optionHelper.selectChange(t),this.auxiliaryManager.slotManager.addSlotState(ze.Focus,[...t]),this.auxiliaryManager.slotManager.addSlotState(ze.FocusPropsChange,!0),this.refreshSelectStatus()}startOptWorking(t,e,n){this.optionHelper.startWorking(t,e,n)}include(t){return this.selectNodes.has(t)}}class di{constructor(t,e,n,o){p(this,"gmlRender");p(this,"selectManager");p(this,"graphicMap");p(this,"slotManager");this.gmlRender=t,this.slotManager=e,this.selectManager=new hi(t,this,n,o),this.graphicMap=new Map}start(){}reset(){this.graphicMap.clear(),this.selectManager.reset()}addOrUpdate(t,e){const n=this.graphicMap.get(t);if(n){n.update(e);return}const o=vs.create(t);o&&(this.graphicMap.set(t,o),o.update(e))}remove(t){this.graphicMap.delete(t)}redraw(){const t=this.gmlRender.getViewPortBounds();this.gmlRender.glCtx.clearRect(t.minX,t.minY,t.maxX-t.minX,t.maxY-t.minY);const e=this.gmlRender.getScale(),n=[...this.graphicMap.values()];n.sort((o,s)=>o.auxiliaryType-s.auxiliaryType);for(const o of n)o.draw(this.gmlRender.glCtx,e)}removeHoverGraphics(){this.remove(N.HoverBounds),this.remove(N.HoverLine),this.remove(N.HoverConnectPoint),this.remove(N.HoverConnectAnchorPoint),this.remove(N.HoverAnchorPoint),this.remove(N.HoverConnectAnchor),this.remove(N.PreviewGraphics),this.remove(N.HoverContainer),this.remove(N.HoverSize),this.remove(N.HoverSlidePlaceHolder),this.remove(N.HoverFocusCopy),this.remove(N.HoverInsertSlide),this.remove(N.HoverInsertHorizonSlide),this.remove(N.HoverSlideGapInsertPoint),this.removeAlignGraphics()}removeSelectGraphics(){this.remove(N.SingleSelectBound),this.remove(N.MultiSelectBound),this.remove(N.HighlightRects),this.remove(N.TextSelection),this.remove(N.StretchRect),this.remove(N.ExpandShape),this.remove(N.SelectLineEnd),this.remove(N.SelectLine),this.remove(N.SelectPolyLineControlPoint),this.remove(N.SelectCurveControlPoint),this.remove(N.SelectCurveEnd),this.remove(N.SelectLineTextRect),this.remove(N.SelectConnectAnchor),this.remove(N.CropBounds),this.remove(N.CropOriginImg),this.remove(N.SelectParentGroupBound),this.remove(N.SelectSlideGapInsertPoint)}removeAlignGraphics(){this.remove(N.AlignLine),this.remove(N.AlignStretchLine)}}class Ah{}class Wn extends ct{constructor(){super(...arguments);p(this,"type",I.Svg);p(this,"useCode",!1);p(this,"url","");p(this,"code","")}static from(e){const n=new Wn;return n.url=e.url,n.code=e.code,n.useCode=e.useCode,n}clone(){const e=new Wn;return e.url=this.url,e.code=this.code,e.useCode=this.useCode,e}update(e){const{url:n,code:o,useCode:s}=e;n!==void 0&&(this.url=n),o!==void 0&&(this.code=o),s!==void 0&&(this.useCode=s)}}var wt=(l=>(l[l.None=0]="None",l[l.Rect=1]="Rect",l[l.RoundRect=2]="RoundRect",l[l.Circle=3]="Circle",l))(wt||{});class Sn extends ct{constructor(){super(...arguments);p(this,"type",I.Crop);p(this,"cropType",wt.None);p(this,"cropInfo")}static from(e){const n=new Sn;return n.cropType=e.cropType||wt.None,n.cropInfo=e.cropInfo,n}clone(){const e=new Sn;return e.cropType=this.cropType,this.cropInfo&&(e.cropInfo={imgX:this.cropInfo.imgX,imgY:this.cropInfo.imgY,imgWidth:this.cropInfo.imgWidth,imgHeight:this.cropInfo.imgHeight}),e}update(e){const{cropInfo:n,cropType:o}=e;n!==void 0&&(this.cropInfo=n),o!==void 0&&(this.cropType=o)}}class Qt extends ct{constructor(){super(...arguments);p(this,"type",I.CheckStatus);p(this,"checkStatus",!1)}static create(e){const n=new Qt;return n.update(e),n}static from(e){const n=new Qt;return n.checkStatus=e.checkStatus,n}clone(){const e=new Qt;return e.checkStatus=this.checkStatus,e}update(e){const{checkStatus:n}=e;n!==void 0&&(this.checkStatus=n)}}class vn extends ct{constructor(){super(...arguments);p(this,"type",I.CheckSize);p(this,"size",16)}static create(e){const n=new vn;return n.update(e),n}static from(e){const n=new vn;return n.size=e.size,n}clone(){const e=new vn;return e.size=this.size,e}update(e){const{size:n}=e;n!==void 0&&(this.size=n)}}var me=(l=>(l[l.Decision=0]="Decision",l[l.Step=1]="Step",l[l.Data=2]="Data",l[l.Status=3]="Status",l[l.Operation=4]="Operation",l[l.Others=5]="Others",l[l.Section=6]="Section",l[l.Resource=7]="Resource",l[l.Line=8]="Line",l[l.Check=9]="Check",l))(me||{}),K=(l=>(l[l.PureText=0]="PureText",l[l.Rect=1]="Rect",l[l.Ellipse=2]="Ellipse",l[l.Octagon=3]="Octagon",l[l.DoubleArrow=4]="DoubleArrow",l[l.LeftArrow=5]="LeftArrow",l[l.LeftKuohao=6]="LeftKuohao",l[l.Diamond=7]="Diamond",l[l.Hexagon=8]="Hexagon",l[l.LiuCheng=9]="LiuCheng",l[l.LiuCheng2=10]="LiuCheng2",l[l.Parallelogram=11]="Parallelogram",l[l.Qipao=12]="Qipao",l[l.Qipao2=13]="Qipao2",l[l.RightArrow=14]="RightArrow",l[l.RightKuohao=15]="RightKuohao",l[l.RoundRect=16]="RoundRect",l[l.RoundRect2=17]="RoundRect2",l[l.Cross=18]="Cross",l[l.Trapezoid=19]="Trapezoid",l[l.Triangle=20]="Triangle",l[l.Triangle2=21]="Triangle2",l[l.Pentagon=22]="Pentagon",l[l.Star=23]="Star",l[l.YuanZhu=24]="YuanZhu",l[l.Cloud=25]="Cloud",l))(K||{});const Is={[K.PureText]:me.Operation,[K.Rect]:me.Operation,[K.RoundRect]:me.Step,[K.Triangle]:me.Operation,[K.Diamond]:me.Decision,[K.Ellipse]:me.Status,[K.Parallelogram]:me.Operation,[K.Trapezoid]:me.Step,[K.Cross]:me.Operation,[K.Pentagon]:me.Operation,[K.Hexagon]:me.Decision,[K.Octagon]:me.Operation,[K.Star]:me.Decision};var Zt=(l=>(l[l.TOP_RIGHT=0]="TOP_RIGHT",l[l.TOP_LEFT=1]="TOP_LEFT",l[l.BOTTOM_RIGHT=2]="BOTTOM_RIGHT",l[l.BOTTOM_LEFT=3]="BOTTOM_LEFT",l))(Zt||{});class qt extends ct{constructor(){super(...arguments);p(this,"type",I.TextParagraph);p(this,"paragraphStyles",[])}static create(e){const n=new qt;return n.update(e),n}static from(e){const n=new qt;return n.paragraphStyles=e.paragraphStyles,n}clone(){const e=new qt;return e.paragraphStyles=JSON.parse(JSON.stringify(this.paragraphStyles)),e}update(e){const{paragraphStyles:n}=e;n!==void 0&&(this.paragraphStyles=n)}}class Dt extends ct{constructor(){super(...arguments);p(this,"paraQuoteStyles",[]);p(this,"type",I.TextParagraphQuote)}static create(e){const n=new Dt;return n.update(e),n}static from(e){const n=new Dt;return n.paraQuoteStyles=e.paraQuoteStyles,n}clone(){const e=new Dt;return e.paraQuoteStyles=JSON.parse(JSON.stringify(this.paraQuoteStyles)),e}update(e){const{paraQuoteStyles:n}=e;n!==void 0&&(this.paraQuoteStyles=n)}}var de=(l=>(l[l.Line=0]="Line",l[l.PolyLine=1]="PolyLine",l[l.RoundPolyLine=2]="RoundPolyLine",l[l.Curve=3]="Curve",l))(de||{});class ui{constructor(t,e,n,o){p(this,"p0");p(this,"p1");p(this,"p2");p(this,"p3");this.p0=t,this.p1=e,this.p2=n,this.p3=o}getPos(t){if(t<0||t>1)throw new Error(`非法的t值:${t}`);const e=1-t,n=e*e*e*this.p0.x+3*t*e*e*this.p1.x+3*t*t*e*this.p2.x+t*t*t*this.p3.x,o=e*e*e*this.p0.y+3*t*e*e*this.p1.y+3*t*t*e*this.p2.y+t*t*t*this.p3.y;return new m(n,o)}getHalfTPos(){return this.getPos(.5)}getDerivative(t){const e=1-t,n=3*e*e*(this.p1.x-this.p0.x)+6*e*t*(this.p2.x-this.p1.x)+3*t*t*(this.p3.x-this.p2.x),o=3*e*e*(this.p1.y-this.p0.y)+6*e*t*(this.p2.y-this.p1.y)+3*t*t*(this.p3.y-this.p2.y);return new m(n,o)}getDistanceSquared(t,e){const n=this.getPos(e),o=n.x-t.x,s=n.y-t.y;return o*o+s*s}getTValueByPoint(t,e=1,n=50){let o=0,s=1/0;const r=20;for(let a=0;a<=r;a++){const c=a/r,h=this.getDistanceSquared(t,c);h<s&&(s=h,o=c)}if(Math.sqrt(s)<e)return o;let i=o;for(let a=0;a<n;a++){const c=this.getPos(i),h=this.getDerivative(i),d=c.x-t.x,u=c.y-t.y,f=d*h.x+u*h.y;if(Math.abs(f)<e)return Math.max(0,Math.min(1,i));const g=1-i,y=6*g*(this.p2.x-2*this.p1.x+this.p0.x)+6*i*(this.p3.x-2*this.p2.x+this.p1.x),P=6*g*(this.p2.y-2*this.p1.y+this.p0.y)+6*i*(this.p3.y-2*this.p2.y+this.p1.y),b=h.x*h.x+h.y*h.y+d*y+u*P;if(Math.abs(b)<1e-10)break;const w=i-f/b;if(i=Math.max(0,Math.min(1,w)),Math.abs(w-i)<e&&i===w)break}return i}getApproximateLength(t=10){let e=0,n=this.getPos(0);for(let o=1;o<=t;o++){const s=o/t,r=this.getPos(s),i=r.x-n.x,a=r.y-n.y;e+=Math.sqrt(i*i+a*a),n=r}return e}getTValueByDistance(t,e=20){if(t<=0)return 0;let n=0,o=this.getPos(0);for(let s=1;s<=e;s++){const r=s/e,i=this.getPos(r),a=i.x-o.x,c=i.y-o.y,h=Math.sqrt(a*a+c*c);if(n+h>=t){const u=(t-n)/h,f=(s-1)/e;return f+u*(r-f)}n+=h,o=i}return 1}}var Jt=(l=>(l.Windows="Windows",l.MacOS="MacOS",l.Linux="Linux",l.Android="Android",l.IOS="ios",l.Unknown="unknown",l))(Jt||{});class pi{static getOS(){const t=navigator.userAgent;return t.includes("Win")?Jt.Windows:t.includes("Mac")?Jt.MacOS:t.includes("Linux")?Jt.Linux:/Android/.test(t)?Jt.Android:/iPhone|iPad|iPod/.test(t)?Jt.IOS:Jt.Unknown}}class Mt extends ct{constructor(){super(...arguments);p(this,"type",I.Slide);p(this,"children",[])}static create(e){const n=new Mt;return n.update(e),n}static from(e){const n=new Mt;return n.children=e.children,n}clone(){const e=new Mt;return e.children=this.children,e}update(e){const{children:n}=e;n!==void 0&&(this.children=n)}}class M{static computeShapeCategory(t,e=0){return t===v.Shape?Is[e]??me.Others:t===v.CheckboxText||t===v.Checkbox?me.Check:t===v.Line?me.Line:t===v.Section?me.Section:t===v.SVG?me.Resource:me.Others}static makeSortGraphic(t){const e=[t];let n=t.parent;for(;n&&n.id!==Mn;)e.unshift(n),n=n.parent;return{graphics:e}}static sortGraphics(t){const e=t.map(this.makeSortGraphic);return e.sort((n,o)=>{const s=Math.min(n.graphics.length,o.graphics.length);for(let r=0;r<s;r++){const i=n.graphics[r],a=o.graphics[r];if(i!==a)return i.zIndex>a.zIndex?1:-1}return n.graphics.length-o.graphics.length}),e.map(n=>n.graphics[n.graphics.length-1])}static setDashLine(t,e){t.dashType===et.Dash1?e.setLineDash([4,2]):t.dashType===et.Dash2&&e.setLineDash([2,2])}static convertPropsToCapInfo(t){const e={},n=t.get(I.Base);n&&(e.baseProps=n);const o=t.get(I.Color);o&&(e.colorProps=o);const s=t.get(I.Border);s&&(e.borderProps=s);const r=t.get(I.Text);r&&(e.textProps=r);const i=t.get(I.Shape);i&&(e.shapeProps=i);const a=t.get(I.Line);a&&(e.lineProps=a);const c=t.get(I.Connect);c&&(e.connectProps=c);const h=t.get(I.Arrow);h&&(e.arrowProps=h);const d=t.get(I.LineTextRect);d&&(e.lineTextRectProps=d);const u=t.get(I.Svg);u&&(e.svgProps=u);const f=t.get(I.Image);f&&(e.imageProps=f);const g=t.get(I.Crop);g&&(e.cropProps=g);const y=t.get(I.CheckStatus);y&&(e.checkStatusProps=y);const P=t.get(I.CheckSize);y&&(e.checkSizeProps=P);const b=t.get(I.TextParagraph);b&&(e.textParagraphProps=b);const w=t.get(I.TextParagraphQuote);w&&(e.textParagraphQuoteProps=w);const L=t.get(I.Slide);return L&&(e.slideProps=L),e}static convertCapInfoToProps(t){const e=[],{baseProps:n,borderProps:o,shapeProps:s,colorProps:r,textProps:i,lineProps:a,connectProps:c,arrowProps:h,lineTextRectProps:d,svgProps:u,imageProps:f,cropProps:g,checkStatusProps:y,checkSizeProps:P,textParagraphProps:b,textParagraphQuoteProps:w,slideProps:L}=t;return o&&e.push(Ae.from(o)),r&&e.push(tt.from(r)),i&&e.push(Ge.from(i)),n&&e.push(ie.from(n)),s&&e.push(Oe.from(s)),a&&e.push(je.from(a)),c&&e.push(Rt.from(c)),h&&e.push(lt.from(h)),d&&e.push(Et.from(d)),u&&e.push(Wn.from(u)),f&&e.push(ro.from(f)),g&&e.push(Sn.from(g)),y&&e.push(Qt.from(y)),P&&e.push(vn.from(P)),b&&e.push(qt.from(b)),w&&e.push(Dt.from(w)),L&&e.push(Mt.from(L)),e}static centerPoint(t){const e=t.baseProps;return new m(e.x+.5*e.width,e.y+.5*e.height)}static topPoint(t){const e=t.baseProps;return new m(e.x+.5*e.width,e.y)}static rightPoint(t){const e=t.baseProps;return new m(e.x+e.width,e.y+.5*e.height)}static bottomPoint(t){const e=t.baseProps;return new m(e.x+.5*e.width,e.y+e.height)}static leftPoint(t){const e=t.baseProps;return new m(e.x,e.y+.5*e.height)}static topLeft(t){const e=t.baseProps;return new m(e.x,e.y)}static topRight(t){const e=t.baseProps;return new m(e.x+e.width,e.x+e.width)}static bottomLeft(t){const e=t.baseProps;return new m(e.x,e.y+e.height)}static bottomRight(t){const e=t.baseProps;return new m(e.x+e.width,e.y+e.height)}static middleInsertPoint(t,e,n){const o=new m(t.x,e.y);n.push(t,o,e)}static doubleMiddleInsertPoint(t,e,n){const o=new m(.5*(t.x+e.x),t.y),s=new m(.5*(t.x+e.x),e.y);n.push(t,o,s,e)}static rectContains(t,e){return t.x>e.x&&t.x<e.x+e.width&&t.y>e.y&&t.y<e.y+e.height}static rectContains2(t,e){return t.x>=e.minX&&t.x<=e.maxX&&t.y>=e.minY&&t.y<=e.maxY}static circleContains(t,e,n=2){return(t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y)<n*n}static overlapRect(t,e){return!(t.maxX<e.minX||t.minX>e.maxX||t.maxY<e.minY||t.minY>e.maxY)}static containRect(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&t.maxX>=e.maxX&&t.maxY>=e.maxY}static distance(t,e){return Math.sqrt((t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y))}static lineAngle(t,e){if(Math.abs(t.x-e.x)<.001)return e.y>t.y?Math.PI*.5:-Math.PI*.5;const n=(e.y-t.y)/(e.x-t.x);let o=Math.atan(n);return e.x<t.x&&(o+=Math.PI),o}static basicGetArrowPoint(t,e,n,o){const s=M.lineAngle(t,e),r=re.generateMatrix().translate(t.x,t.y).rotate2(s),i=r.crossPoint(n),a=r.crossPoint(o);return{a:i,b:a}}static getLArrowPoint(t,e,n=5){const o=new m(Math.sqrt(3)*.5*n,.5*n),s=new m(Math.sqrt(3)*.5*n,-.5*n);return M.basicGetArrowPoint(t,e,o,s)}static getRArrowPoint(t,e,n=5){const o=M.distance(t,e),s=new m(o-Math.sqrt(3)*.5*n,.5*n),r=new m(o-Math.sqrt(3)*.5*n,-.5*n);return M.basicGetArrowPoint(t,e,s,r)}static getNodeBounds(t){const e=[];t.forEach(o=>e.push(o.getBounds()));const n=this.getBounds(e);return D.rectNode2Rect(n)}static cloneIRectNode(t){return{minX:t.minX,maxX:t.maxX,minY:t.minY,maxY:t.maxY}}static cloneIPoint(t){return{x:t.x,y:t.y}}static getBoundsByBaseProps(t){const{x:e,y:n,width:o,height:s,angle:r}=t,i=re.generateMatrix().rotate(r),a=re.generateMatrix().translate(e,n),c=[new m(0,0),new m(0,s),new m(o,0),new m(o,s)],h=a.crossProduct(i),d=c.map(u=>h.crossPoint(u));return this.getBoundsByPoints(d)}static getBoundsByBasePropsList(t){const e=[];for(const n of t){const{x:o,y:s,width:r,height:i}=n,a=n.angle??0,c=re.generateMatrix().rotate(a),d=re.generateMatrix().translate(o,s).crossProduct(c),f=[new m(0,0),new m(0,i),new m(r,0),new m(r,i)].map(g=>d.crossPoint(g));e.push(...f)}return this.getBoundsByPoints(e)}static getBounds(t,e="getBounds"){const n=[],o=[];for(const s of t)n.push(s.maxX,s.minX),o.push(s.maxY,s.minY);return{id:e,minX:Math.min(...n),maxX:Math.max(...n),minY:Math.min(...o),maxY:Math.max(...o)}}static getBoundsByPoints(t){const e=[],n=[];for(const o of t)e.push(o.x),n.push(o.y);return{id:"getBounds",minX:Math.min(...e),maxX:Math.max(...e),minY:Math.min(...n),maxY:Math.max(...n)}}static calcFont(t,e,n=!1,o=!1){let s=`${t.toString()}px ${e}`;return n?s=`700 ${s}`:s=`400 ${s}`,o&&(s=`italic ${s}`),s}static calcFontByTextProps(t){const{fontSize:e,fontFamily:n,bold:o,italic:s}=t;return this.calcFont(e,n,o,s)}static measureText(t,e){const n=t.measureText(e),o=n.width,s=n.fontBoundingBoxDescent+n.fontBoundingBoxAscent,r=n.fontBoundingBoxAscent;return{width:o,height:s,boxAscent:r}}static measureTextByFont(t,e,n,o,s,r){t.save(),t.font=this.calcFont(n,o,s,r);const i=t.measureText(e);t.restore();const a=i.width,c=i.fontBoundingBoxDescent+i.fontBoundingBoxAscent,h=i.fontBoundingBoxAscent;return{width:a,height:c,boxAscent:h}}static judgeHorizon(t,e,n=.01){return Math.abs(t.y-e.y)<n}static judgeVertical(t,e,n=.01){return Math.abs(t.x-e.x)<n}static computePolyLinePoints(t,e){const n=[],o=new m(e.x-t.x,e.y-t.y);if(Math.abs(o.x)<.001||Math.abs(o.y)<.001)n.push(t,e);else if(Math.abs(o.x)>Math.abs(o.y)){const s=new m(t.x+.5*o.x,t.y),r=new m(e.x-.5*o.x,e.y);n.push(t,s,r,e)}else{const s=new m(t.x,t.y+.5*o.y),r=new m(e.x,e.y-.5*o.y);n.push(t,s,r,e)}return n}static normalizeAngle(t){let e=t%360;return e<0&&(e+=360),e}static computeOriginNodeConnectEnd(t){const{x:e,y:n}=t,o=Math.atan2(n-.5,e-.5)/Math.PI*180,s=this.normalizeAngle(o);if(s<45||s>315)return ue.Right;if(Math.abs(s-90)<45)return ue.Bottom;if(Math.abs(s-180)<45)return ue.Left;if(Math.abs(s-270)<45)return ue.Top;throw new Error("没有正确的end type")}static computeNodeConnectEnd(t,e){const{x:n,y:o}=t,s=Math.atan2(o-.5,n-.5)/Math.PI*180+e,r=this.normalizeAngle(s);if(r<45||r>315)return ue.Right;if(Math.abs(r-90)<45)return ue.Bottom;if(Math.abs(r-180)<45)return ue.Left;if(Math.abs(r-270)<45)return ue.Top;throw new Error("没有正确的end type")}static inDistance(t,e,n){return Math.abs(t-e-.5*n)<.5*n}static dealWithEndPolyPointsInUp(t,e,n){if(t.length<4)return t;const o=t.length;if(n){const a=t[o-1],c=t[o-2],h=t[o-3];return M.distance(c,h)<3/e&&(M.judgeHorizon(a,c)?a.y=h.y:a.x=h.x,t.splice(o-3,2)),t}const s=t[0],r=t[1],i=t[2];return M.distance(i,r)<3/e&&(M.judgeHorizon(s,r)?s.y=i.y:s.x=i.x,t.splice(1,2)),t}static dealWithEndPolyPoints(t,e,n){if(t.length<4)return t;const o=t.length;if(n){const a=t[o-1],c=t[o-2],h=t[o-3];return M.distance(c,h)<3/e&&(M.judgeHorizon(a,c)?(c.y=h.y,a.y=h.y):(c.x=h.x,a.x=h.x)),t}const s=t[0],r=t[1],i=t[2];return M.distance(i,r)<3/e&&(M.judgeHorizon(s,r)?(r.y=i.y,s.y=i.y):(r.x=i.x,s.x=i.x)),t}static dealWithPolyPoints(t,e){if(t.length===0)return[];const n=[t[0]];for(let o=1;o<t.length-1;o++){const s=t[o],r=t[o+1];if(M.distance(s,r)<3/e){const i=t[o+2],a=t[o-1];M.judgeHorizon(a,s)?a.y=i.y:a.x=i.x,o=o+1}else n.push(s)}return n.push(t[t.length-1]),n}static computePointByT(t,e){const n=t.points;if(t.isPolyLine()){let a=0;for(let h=0;h<n.length-1;h++){const d=n[h],u=n[h+1],f=M.distance(d,u);a+=f}const c=e*a;a=0;for(let h=0;h<n.length-1;h++){const d=n[h],u=n[h+1],f=M.distance(d,u);if(c>a&&c<=a+f)if(M.judgeHorizon(d,u)){const y=u.x>d.x?1:-1;return new m(d.x+(c-a)*y,d.y)}else{const y=u.y>d.y?1:-1;return new m(d.x,d.y+(c-a)*y)}a+=f}}else if(t.shapeType===de.Curve){const a=M.computeBezierCurves(t);let c=0;const h=[];for(const u of a){const f=u.getApproximateLength();c+=f,h.push(f)}c=e*c;for(let u=0;u<a.length;u++){const f=a[u],g=h[u];if(c>g){c-=g;continue}const y=f.getTValueByDistance(c);return f.getPos(y)}}const o=n[0],s=n[n.length-1],r=o.x+(s.x-o.x)*e,i=o.y+(s.y-o.y)*e;return new m(r,i)}static computeNodeConnectAnchor(t,e){const{width:n,height:o}=t.baseProps,s=Yr/e;return[{x:.5*n,y:-s},{x:n+s,y:.5*o},{x:.5*n,y:o+s},{x:-s,y:.5*o}]}static computeSelectNode(t,e){const n=new Set(t.getSelectNodes());let o=e.parent;for(;o;)n.has(o)&&n.delete(o),o=o.parent;return this.filterChildInSet(n,e),n.add(e),n}static filterChildInSet(t,e){const n=e.children;if(n.size!==0)for(const o of n)t.has(o)&&t.delete(o),this.filterChildInSet(t,o)}static computeSelectNodes(t){const e=new Set(t);for(const n of t)this.filterChildInSet(e,n);return[...e]}static filterToGroupNodes(t){const e=[];for(const n of t)if(n.type!==v.Section){if(n.type===v.Line){const o=n,{start:s,end:r}=o.connectProps;if(s&&r){const i=t.find(c=>c.id===s.objectId),a=t.find(c=>c.id===r.objectId);i&&a&&e.push(n);continue}if(s&&!r){t.find(a=>a.id===s.objectId)&&e.push(n);continue}if(r&&!s){t.find(a=>a.id===r.objectId)&&e.push(n);continue}e.push(n);continue}e.push(n)}return e}static detectRectBounds(t,e,n){const{x:o,y:s,width:r,height:i}=t;return M.circleContains(new m(o,s),e,n)?{type:V.TOP_LEFT}:M.circleContains(new m(o+r,s),e,n)?{type:V.TOP_RIGHT}:M.circleContains(new m(o+r,s+i),e,n)?{type:V.BOTTOM_RIGHT}:M.circleContains(new m(o,s+i),e,n)?{type:V.BOTTOM_LEFT}:M.rectContains(e,new D(o,s-.5*n,r,n))?{type:V.TOP}:M.rectContains(e,new D(o+r-.5*n,s,n,i))?{type:V.RIGHT}:M.rectContains(e,new D(o,s+i-.5*n,r,n))?{type:V.BOTTOM}:M.rectContains(e,new D(o-.5*n,s,n,i))?{type:V.LEFT}:null}static computeShiftPoint(t,e){if(M.distance(t,e)<.1)return new m(e.x,t.y);let n=Math.atan2(e.y-t.y,e.x-t.x)*180/Math.PI;return n=(n+360)%360,n<45||n>=315?new m(e.x,t.y):n>45&&n<=135?new m(t.x,e.y):n>135&&n<225?new m(e.x,t.y):new m(t.x,e.y)}static dealWithShiftLineInteractEvent(t,e,n=!0){if(!t.originEvent.shiftKey)return t;const o=e.globalLinePoints,s=n?o[0]:o[o.length-1],r=M.computeShiftPoint(s,t.globalPoint);return{clientPoint:t.clientPoint,globalPoint:r,type:t.type,originEvent:t.originEvent}}static getMockEventModifierInit(t){return{shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,ctrlKey:t.ctrlKey}}static judgeParentInset(t,e){let n=t;for(;n;){if(e.has(n))return!0;n=n.parent}return!1}static judgeSlideSectionChildren(t,e){let n=t;for(;n!=null&&n.parent;){if(n.parent.id===e.id)return n;n=n.parent}return null}static filterContainerFromNodes(t){const e=t.filter(o=>o.type===v.Section);return new Set(e)}static judgeEndNode(t,e,n,o,s){if(!n)return;const r=o.nodeManager.getNode(n.objectId);r&&!M.judgeParentInset(r,s)&&e.add(t)}static getViewportBoundCenter(t){const e=t.renderManager.gmlRender.getViewPortBounds();return new m(.5*(e.minX+e.maxX),.5*(e.minY+e.maxY))}static computeRotateAngle(t,e){let n=0;return t.length===1&&(n=n+t[0].baseProps.angle),n=n+e,Math.round(n)}static computeRotateDeltaAngle(t){let e=0;switch(t){case Zt.BOTTOM_LEFT:e=90;break;case Zt.BOTTOM_RIGHT:e=0;break;case Zt.TOP_LEFT:e=180;break;case Zt.TOP_RIGHT:e=-90;break}return e}static computeRelationChangeUpdateNodeInfo(t,e,n,o){if(t.type===v.Line){const i=t.globalLinePoints.map(c=>e.toLocal(c)),a=D.rectNode2Rect(M.getBoundsByPoints(i));return{id:t.id,props:[{type:I.Line,points:i},ie.create({x:a.x,y:a.y,width:a.width,height:a.height})],zIndex:n,parentId:o}}const s=e.toLocal(t.globalPos);return{id:t.id,zIndex:n,parentId:o,props:[{type:I.Base,x:s.x,y:s.y}]}}static computeStretchAngle(t,e){let n=0;return t.length===1&&(n=n+t[0].baseProps.angle),e===V.TOP_RIGHT||e===V.BOTTOM_LEFT?n=n-45:e===V.TOP_LEFT||e===V.BOTTOM_RIGHT?n=n+45:(e===V.TOP||e===V.BOTTOM)&&(n=n+90),Math.round(n)}static correctZIndex(t){if(t.length===0)return t;const e=new Map;if(t.forEach((s,r)=>{const i=s.zIndex;e.has(i)||e.set(i,[]),e.get(i).push(r)}),!Array.from(e.values()).some(s=>s.length>1))return t;const o=t.map(s=>({...s}));return e.forEach((s,r)=>{if(s.length>1){const i=s[0];let a=.1,c=0;i===0?(c=r-1,a=(r-c)/(s.length+1)):(c=o[i-1].zIndex<r?o[i-1].zIndex:r-1,a=(r-c)/(s.length+1)),s.forEach((h,d)=>{o[h].zIndex=(d+1)*a+c})}}),o}static judgeLineBreak(t,e,n,o){let s=-1;for(const r of t){const i=e.characters.slice(0,r);let a=0;if(i.forEach(c=>{a+=c.width}),n.width+a<o)s=r;else return s>0?s:-1}return s>-1?s:-1}static getParaStyle(t,e){const n=t.paragraphStyles;for(const o of n)if(o.paraIndex===e)return o;return null}static computeNotUnOrderParas(t){const n=t.paragraphProps.paragraphStyles,o=new Set;for(let s=0;s<t.paragraphs.length;s++)o.add(s);for(const s of n)s.orderIndex===-1&&o.delete(s.paraIndex);return o}static computeNotOrderParas(t){const n=t.paragraphProps.paragraphStyles,o=new Set;for(let s=0;s<t.paragraphs.length;s++)o.add(s);for(const s of n)s.orderIndex>-1&&o.delete(s.paraIndex);return o}static computeNotNormalParas(t){const n=t.paragraphProps.paragraphStyles,o=new Set;for(const s of n)o.add(s.paraIndex);return o}static computeNotQuoteParas(t){const n=t.paragraphQuoteProps.paraQuoteStyles,o=new Set;for(let s=0;s<t.paragraphs.length;s++)o.add(s);for(const s of n)s.quote&&o.delete(s.paraIndex);return o}static drawControlPoints(t,e){t.save(),t.beginPath(),t.strokeStyle="#cc2626",t.lineWidth=1;const n=e.globalLinePoints;t.moveTo(n[0].x,n[0].y);for(let o=1;o<n.length;o++){const s=n[o];t.lineTo(s.x,s.y)}t.stroke(),t.fillStyle="#000000";for(let o=1;o<n.length-2;o=o+3){const s=n[o],r=n[o+1];t.beginPath(),t.arc(s.x,s.y,5,0,2*Math.PI),t.fill(),t.stroke(),t.beginPath(),t.arc(r.x,r.y,5,0,2*Math.PI),t.fill(),t.stroke()}t.restore()}static computeBezierCurves(t){if(t.shapeType!==de.Curve)return[];const e=t.points,n=[];for(let o=1;o<e.length-2;o=o+3){const s=e[o-1],r=e[o],i=e[o+1],a=e[o+2],c=new ui(s,r,i,a);n.push(c)}return n}static computeBezierCurvesByPoints(t){const e=[];for(let n=1;n<t.length-2;n=n+3){const o=t[n-1],s=t[n],r=t[n+1],i=t[n+2],a=new ui(o,s,r,i);e.push(a)}return e}static computeCurveControlPoints(t){const e=this.computeBezierCurves(t),n=[];for(const o of e)n.push(o.getHalfTPos());return n}static computeCurveEndPoints(t){if(t.shapeType!==de.Curve)return[];const e=t.points,n=[];for(let o=1;o<e.length-2;o=o+3){const s=e[o-1],r=e[o+2];n.push(s),n.push(r)}return n}static pressMeta(t){return pi.getOS()===Jt.MacOS?t.originEvent.metaKey:t.originEvent.ctrlKey}static getAllChildren(t,e){const n=t.children;for(const o of n)e.add(o),this.getAllChildren(o,e)}static judgeNodeCanBeStretch(t){var e;return!(t.type===v.SlideContainer||t.type===v.Section&&((e=t.parent)==null?void 0:e.type)===v.SlideContainer)}static getSlideContainerChildNode(t,e,n){const o=t.getChildIdByIndex(e);if(!o)return null;const s=n.nodeManager.getNode(o);return s||null}static filterSlideContainerNodes(t,e){const n=t.docState.docMode,o=t.docState.slideStatus,s=o.slideContainer;if(n===he.SLIDE_EDIT&&s){const r=this.getSlideContainerChildNode(s,o.currentIndex,t);if(!r)return e;const i=new Set;M.getAllChildren(r,i);const a=[];for(const c of e)i.has(c)&&a.push(c);return a}return e}static getSlideInfo(t,{renderManager:e,nodeManager:n}){return new Promise((o,s)=>{const r=t.getBounds(),i=r.maxX-r.minX,a=r.maxY-r.minY,c=new Set([t]);M.getAllChildren(t,c),e.exportWorker.exportToOfflineCanvasByFilterNodes(r,n,1,"",c).toBlob(d=>{if(d){const u=URL.createObjectURL(d),f={id:t.id,blobUrl:u,width:i,height:a};o(f)}else console.error("导出图片错误"),s("导出图片错误")})})}}class en{constructor(t,e){p(this,"type",v.Shape);p(this,"id");p(this,"parent",null);p(this,"children",new Set);p(this,"zIndex",0);p(this,"graphicContext");p(this,"props",new Map);p(this,"transform",re.generateMatrix());this.id=t,this.graphicContext=e}get baseProps(){return this.props.get(I.Base)}get globalBaseProps(){const t=this.baseProps.clone(),e=this.globalPos;return t.x=e.x,t.y=e.y,t}get pos(){const t=this.baseProps;return new m(t.x,t.y)}get globalPos(){return this.globalTransform().crossPoint(new m)}setParent(t){this.parent=t,t.children.add(this)}updateProps(t){for(const e of t){if(e.type===void 0)continue;const n=this.props.get(e.type);n&&n.update(e)}}getProp(t){const e=this.props.get(t);return e||null}updateTransformMatrix(){const t=this.baseProps,e=re.generateMatrix().rotate(t.angle),n=re.generateMatrix().translate(t.x,t.y);this.transform=n.crossProduct(e)}contains(t,e=1){const{width:n,height:o}=this.baseProps,s=this.toLocal(t);return M.rectContains(s,new D(0,0,n,o))}canQuickCreate(){return!!this.canBeConnected()}canBeConnected(){return!0}getConnectAnchor(){return[]}borderContains(t,e){return null}draw(){return this.drawOnGLCtx(this.graphicContext)}globalTransform(){const t=[this];let e=this.parent;for(;e;)t.push(e),e=e.parent;let n=re.generateMatrix();for(const o of t.reverse())n=n.crossProduct(o.transform);return n}getRectNode(){const{width:t,height:e}=this.baseProps,n=this.getProp(I.Border),o=n?n.width:0,s=[new m(-o,-o),new m(t+o,-o),new m(t+o,e+o),new m(-o,e+o)],r=[];for(const a of s)r.push(this.toGlobal(a));const i=M.getBoundsByPoints(r);return i.id=this.id,i}getBounds(){const t=this.baseProps,e={id:this.id,minX:0,minY:0,maxX:t.width,maxY:t.height},n=[new m(e.minX,e.minY),new m(e.maxX,e.minY),new m(e.maxX,e.maxY),new m(e.minX,e.maxY)],o=[];for(const r of n)o.push(this.toGlobal(r));const s=M.getBoundsByPoints(o);return s.id=this.id,s}getStretchMinSize(){return{x:10,y:10}}overlapRect(t){return M.overlapRect(t,this.getBounds())}isEmptyText(){return!0}toLocal(t){return this.globalTransform().inverseMatrix().crossPoint(t)}toGlobal(t){return this.globalTransform().crossPoint(t)}modifyPosInEditing(t){return!1}resetFromEditing(){}serializeTo(){const t=M.convertPropsToCapInfo(this.props),e=JSON.parse(JSON.stringify(t));return{type:this.type,zIndex:this.zIndex,id:this.id,parentId:"",capInfo:e,children:[]}}}class kh{fallbackDraw(t,e){const{width:n,height:o}=t.baseProps;e.save();const{a:s,b:r,c:i,d:a,e:c,f:h}=t.globalTransform();e.transform(s,r,i,a,c,h),e.beginPath();let d=!1;const u=n/3,f=o/3;for(let g=0;g<3;g++)for(let y=0;y<3;y++){const P=d?Ht:bs,b=u*g,w=f*y;e.fillStyle=P,e.fillRect(b,w,u,f),d=!d}e.restore()}}class ge{constructor(t=0,e=0){this.x=t,this.y=e}clone(){return new this.constructor(this.x,this.y)}add(t){return new this.constructor(this.x+t.x,this.y+t.y)}subtract(t){return new this.constructor(this.x-t.x,this.y-t.y)}multiply(t){return new this.constructor(this.x*t,this.y*t)}divide(t){return new this.constructor(this.x/t,this.y/t)}equals(t){return this.x===t.x&&this.y===t.y}precisionEquals(t,e){return Math.abs(this.x-t.x)<e&&Math.abs(this.y-t.y)<e}lerp(t,e){const n=1-e;return new this.constructor(this.x*n+t.x*e,this.y*n+t.y*e)}distanceFrom(t){const e=this.x-t.x,n=this.y-t.y;return Math.sqrt(e*e+n*n)}min(t){return new this.constructor(Math.min(this.x,t.x),Math.min(this.y,t.y))}max(t){return new this.constructor(Math.max(this.x,t.x),Math.max(this.y,t.y))}transform(t){return new this.constructor(t.a*this.x+t.c*this.y+t.e,t.b*this.x+t.d*this.y+t.f)}toString(){return`point(${this.x},${this.y})`}}class rt{constructor(t=0,e=0){this.x=t,this.y=e}static fromPoints(t,e){return new rt(e.x-t.x,e.y-t.y)}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}magnitude(){return this.x*this.x+this.y*this.y}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}determinant(t){return this.x*t.y-this.y*t.x}unit(){return this.divide(this.length())}add(t){return new this.constructor(this.x+t.x,this.y+t.y)}subtract(t){return new this.constructor(this.x-t.x,this.y-t.y)}multiply(t){return new this.constructor(this.x*t,this.y*t)}divide(t){return new this.constructor(this.x/t,this.y/t)}angleBetween(t){let e=this.dot(t)/(this.length()*t.length());e=Math.max(-1,Math.min(e,1));const n=Math.acos(e);return this.cross(t)<0?-n:n}perp(){return new this.constructor(-this.y,this.x)}perpendicular(t){return this.subtract(this.project(t))}project(t){const e=this.dot(t)/t.dot(t);return t.multiply(e)}transform(t){return new this.constructor(t.a*this.x+t.c*this.y,t.b*this.x+t.d*this.y)}equals(t){return this.x===t.x&&this.y===t.y}precisionEquals(t,e){return Math.abs(this.x-t.x)<e&&Math.abs(this.y-t.y)<e}toString(){return`vector(${this.x},${this.y})`}}class pt{constructor(t=1,e=0,n=0,o=1,s=0,r=0){this.a=t,this.b=e,this.c=n,this.d=o,this.e=s,this.f=r}static translation(t,e){return new pt(1,0,0,1,t,e)}static scaling(t){return new pt(t,0,0,t,0,0)}static scalingAt(t,e){return new pt(t,0,0,t,e.x-e.x*t,e.y-e.y*t)}static nonUniformScaling(t,e){return new pt(t,0,0,e,0,0)}static nonUniformScalingAt(t,e,n){return new pt(t,0,0,e,n.x-n.x*t,n.y-n.y*e)}static rotation(t){const e=Math.cos(t),n=Math.sin(t);return new pt(e,n,-n,e,0,0)}static rotationAt(t,e){const n=Math.cos(t),o=Math.sin(t);return new pt(n,o,-o,n,e.x-e.x*n+e.y*o,e.y-e.y*n-e.x*o)}static rotationFromVector(t){const e=t.unit(),n=e.x,o=e.y;return new pt(n,o,-o,n,0,0)}static xFlip(){return new pt(-1,0,0,1,0,0)}static yFlip(){return new pt(1,0,0,-1,0,0)}static xSkew(t){const e=Math.tan(t);return new pt(1,0,e,1,0,0)}static ySkew(t){const e=Math.tan(t);return new pt(1,e,0,1,0,0)}multiply(t){return this.isIdentity()?t:t.isIdentity()?this:new this.constructor(this.a*t.a+this.c*t.b,this.b*t.a+this.d*t.b,this.a*t.c+this.c*t.d,this.b*t.c+this.d*t.d,this.a*t.e+this.c*t.f+this.e,this.b*t.e+this.d*t.f+this.f)}inverse(){if(this.isIdentity())return this;const t=this.a*this.d-this.b*this.c;if(t===0)throw new Error("Matrix is not invertible");const e=1/t,n=this.f*this.c-this.e*this.d,o=this.e*this.b-this.f*this.a;return new this.constructor(this.d*e,-this.b*e,-this.c*e,this.a*e,n*e,o*e)}translate(t,e){return new this.constructor(this.a,this.b,this.c,this.d,this.a*t+this.c*e+this.e,this.b*t+this.d*e+this.f)}scale(t){return new this.constructor(this.a*t,this.b*t,this.c*t,this.d*t,this.e,this.f)}scaleAt(t,e){const n=e.x-t*e.x,o=e.y-t*e.y;return new this.constructor(this.a*t,this.b*t,this.c*t,this.d*t,this.a*n+this.c*o+this.e,this.b*n+this.d*o+this.f)}scaleNonUniform(t,e){return new this.constructor(this.a*t,this.b*t,this.c*e,this.d*e,this.e,this.f)}scaleNonUniformAt(t,e,n){const o=n.x-t*n.x,s=n.y-e*n.y;return new this.constructor(this.a*t,this.b*t,this.c*e,this.d*e,this.a*o+this.c*s+this.e,this.b*o+this.d*s+this.f)}rotate(t){const e=Math.cos(t),n=Math.sin(t);return new this.constructor(this.a*e+this.c*n,this.b*e+this.d*n,this.a*-n+this.c*e,this.b*-n+this.d*e,this.e,this.f)}rotateAt(t,e){const n=Math.cos(t),o=Math.sin(t),s=e.x,r=e.y,i=this.a*n+this.c*o,a=this.b*n+this.d*o,c=this.c*n-this.a*o,h=this.d*n-this.b*o;return new this.constructor(i,a,c,h,(this.a-i)*s+(this.c-c)*r+this.e,(this.b-a)*s+(this.d-h)*r+this.f)}rotateFromVector(t){const e=t.unit(),n=e.x,o=e.y;return new this.constructor(this.a*n+this.c*o,this.b*n+this.d*o,this.a*-o+this.c*n,this.b*-o+this.d*n,this.e,this.f)}flipX(){return new this.constructor(-this.a,-this.b,this.c,this.d,this.e,this.f)}flipY(){return new this.constructor(this.a,this.b,-this.c,-this.d,this.e,this.f)}skewX(t){const e=Math.tan(t);return new this.constructor(this.a,this.b,this.c+this.a*e,this.d+this.b*e,this.e,this.f)}skewY(t){const e=Math.tan(t);return new this.constructor(this.a+this.c*e,this.b+this.d*e,this.c,this.d,this.e,this.f)}isIdentity(){return this.a===1&&this.b===0&&this.c===0&&this.d===1&&this.e===0&&this.f===0}isInvertible(){return this.a*this.d-this.b*this.c!==0}getScale(){return{scaleX:Math.sqrt(this.a*this.a+this.c*this.c),scaleY:Math.sqrt(this.b*this.b+this.d*this.d)}}getDecomposition(){const t=(this.a+this.d)*.5,e=(this.a-this.d)*.5,n=(this.b+this.c)*.5,o=(this.b-this.c)*.5,s=Math.sqrt(t*t+o*o),r=Math.sqrt(e*e+n*n),i=s+r,a=s-r,c=Math.atan2(n,e),h=Math.atan2(o,t),d=(h-c)*.5,u=(h+c)*.5;return{translation:this.constructor.translation(this.e,this.f),rotation:this.constructor.rotation(u),scale:this.constructor.nonUniformScaling(i,a),rotation0:this.constructor.rotation(d)}}equals(t){return this.a===t.a&&this.b===t.b&&this.c===t.c&&this.d===t.d&&this.e===t.e&&this.f===t.f}precisionEquals(t,e){return Math.abs(this.a-t.a)<e&&Math.abs(this.b-t.b)<e&&Math.abs(this.c-t.c)<e&&Math.abs(this.d-t.d)<e&&Math.abs(this.e-t.e)<e&&Math.abs(this.f-t.f)<e}toString(){return`matrix(${this.a},${this.b},${this.c},${this.d},${this.e},${this.f})`}}pt.IDENTITY=new pt,pt.IDENTITY.isIdentity=()=>!0;function St(l){return typeof l=="number"?l?l<0?-1:1:l===l?l:NaN:NaN}class Ue{constructor(...t){this.coefs=[];for(let e=t.length-1;e>=0;e--)this.coefs.push(t[e]);this._variable="t",this._s=0}static interpolate(t,e,n,o,s){if(t.constructor!==Array||e.constructor!==Array)throw new TypeError("xs and ys must be arrays");if(isNaN(n)||isNaN(o)||isNaN(s))throw new TypeError("n, offset, and x must be numbers");let r,i,a=0;const c=new Array(n),h=new Array(n);let d=0,u=Math.abs(s-t[o]);for(r=0;r<n;r++){const f=Math.abs(s-t[o+r]);f<u&&(d=r,u=f),c[r]=h[r]=e[o+r]}i=e[o+d],d--;for(let f=1;f<n;f++){for(r=0;r<n-f;r++){const g=t[o+r]-s,y=t[o+r+f]-s,P=c[r+1]-h[r];let b=g-y;if(b===0)throw new RangeError("Unable to interpolate polynomial. Two numbers in n were identical (to within roundoff)");b=P/b,h[r]=y*b,c[r]=g*b}a=2*(d+1)<n-f?c[d+1]:h[d--],i+=a}return{y:i,dy:a}}static newtonSecantBisection(t,e,n,o,s,r){let i,a=0,c,h=0,d,u,f,g,y;i=t;const P=Math.pow(10,-14),b=typeof s=="number"&&typeof r=="number";if(b){if(s>r)throw new RangeError("Min must be greater than max");if(g=e(s),y=e(r),St(g)===St(y))throw new RangeError("Y values of bounds must be of opposite sign")}const w=function(){return Math.abs(d)<=P*Math.abs(i)||h===i-d-i};for(let L=0;L<o;L++){if(c=n(i),c===0){if(a===0)throw new RangeError("df(x) is zero");c=a}if(a=c,f=e(i),d=f/c,u=i-d,w())break;if(b){if(St(f)===St(y))r=i,y=f;else if(St(f)===St(g))s=i,g=f;else{i=u;break}if(u<s||u>r){if(St(g)===St(y))break;const B=50,H=.25,E=y-g,X=r-s;if(E===0?d=i-(s+X*.5):Math.abs(E/Math.min(g,y))>B?d=i-(s+X*(.5+(Math.abs(g)<Math.abs(y)?-H:H))):d=i-(s-g/E*X),u=i-d,w())break}}h=i-u,i=u}return i}clone(){const t=new Ue;return t.coefs=this.coefs.slice(),t}eval(t){if(isNaN(t))throw new TypeError(`Parameter must be a number. Found '${t}'`);let e=0;for(let n=this.coefs.length-1;n>=0;n--)e=e*t+this.coefs[n];return e}add(t){const e=new Ue,n=this.getDegree(),o=t.getDegree(),s=Math.max(n,o);for(let r=0;r<=s;r++){const i=r<=n?this.coefs[r]:0,a=r<=o?t.coefs[r]:0;e.coefs[r]=i+a}return e}multiply(t){const e=new Ue;for(let n=0;n<=this.getDegree()+t.getDegree();n++)e.coefs.push(0);for(let n=0;n<=this.getDegree();n++)for(let o=0;o<=t.getDegree();o++)e.coefs[n+o]+=this.coefs[n]*t.coefs[o];return e}divideEqualsScalar(t){for(let e=0;e<this.coefs.length;e++)this.coefs[e]/=t}simplifyEquals(t=1e-12){for(let e=this.getDegree();e>=0&&Math.abs(this.coefs[e])<=t;e--)this.coefs.pop()}removeZerosEquals(t=1e-15){const e=this.coefs,n=10*t*Math.abs(e.reduce((o,s)=>Math.abs(s)>Math.abs(o)?s:o));for(let o=0;o<e.length-1;o++)Math.abs(e[o])<n&&(e[o]=0);return this}monicEquals(){const t=this.coefs;return t[t.length-1]!==1&&this.divideEqualsScalar(t[t.length-1]),this}toString(){const t=[],e=[];for(let o=this.coefs.length-1;o>=0;o--){let s=Math.round(this.coefs[o]*1e3)/1e3;if(s!==0){const r=s<0?" - ":" + ";s=Math.abs(s),o>0&&(s===1?s=this._variable:s+=this._variable),o>1&&(s+="^"+o),e.push(r),t.push(s)}}e[0]=e[0]===" + "?"":"-";let n="";for(let o=0;o<t.length;o++)n+=e[o]+t[o];return n}bisection(t,e,n=1e-6,o=15){let s=this.eval(t),r=this.eval(e),i;if(Math.abs(s)<=n)i=t;else if(Math.abs(r)<=n)i=e;else if(s*r<=0){const a=Math.log(e-t),c=Math.LN10*o,h=Math.ceil((a+c)/Math.LN2);for(let d=0;d<h;d++){i=.5*(t+e);const u=this.eval(i);if(Math.abs(u)<=n)break;u*s<0?(e=i,r=u):(t=i,s=u)}}return i}trapezoid(t,e,n){if(isNaN(t)||isNaN(e)||isNaN(n))throw new TypeError("Parameters must be numbers");const o=e-t;if(n===1){const s=this.eval(t),r=this.eval(e);this._s=.5*o*(s+r)}else{const s=1<<n-2,r=o/s;let i=t+.5*r,a=0;for(let c=0;c<s;c++)a+=this.eval(i),i+=r;this._s=.5*(this._s+o*a/s)}if(isNaN(this._s))throw new TypeError("this._s is NaN");return this._s}simpson(t,e){if(isNaN(t)||isNaN(e))throw new TypeError("Parameters must be numbers");const n=e-t;let o=.5*n*(this.eval(t)+this.eval(e)),s=o,r=4*o/3,i=r,a=o;const c=1e-7;let h=1;for(let d=2;d<=20;d++){const u=n/h;let f=t+.5*u,g=0;for(let y=1;y<=h;y++)g+=this.eval(f),f+=u;if(s=.5*(s+n*g/h),o=s,r=(4*o-a)/3,Math.abs(r-i)<c*Math.abs(i))break;i=r,a=o,h<<=1}return r}romberg(t,e){if(isNaN(t)||isNaN(e))throw new TypeError("Parameters must be numbers");const n=20,o=3,s=1e-6,r=new Array(n+1),i=new Array(n+1);let a={y:0,dy:0};i[0]=1;for(let c=1;c<=n&&(r[c-1]=this.trapezoid(t,e,c),!(c>=o&&(a=Ue.interpolate(i,r,o,c-o,0),Math.abs(a.dy)<=s*a.y)));c++)r[c]=r[c-1],i[c]=.25*i[c-1];return a.y}zeroErrorEstimate(t){const e=this,n=1e-15;if(typeof t>"u"){const r=e.bounds();t=Math.max(Math.abs(r.minX),Math.abs(r.maxX))}if(t<.001)return 2*Math.abs(e.eval(n));const o=e.coefs.length-1,s=e.coefs[o];return 10*n*e.coefs.reduce((r,i,a)=>{const c=i/s*Math.pow(t,a);return c>r?c:r},0)}boundsUpperRealFujiwara(){let t=this.coefs;const e=t.length-1,n=t[e];n!==1&&(t=this.coefs.map(c=>c/n));const o=t.map((c,h)=>h<e?Math.pow(Math.abs(h===0?c/2:c),1/(e-h)):c);let s;const r=function(c,h,d){return s(d)&&(c.max<h?(c.nearmax=c.max,c.max=h):c.nearmax<h&&(c.nearmax=h)),c};s=function(c){return c<e&&t[c]<0};const i=o.reduce(r,{max:0,nearmax:0});return s=function(c){return c<e&&(e%2===c%2?t[c]<0:t[c]>0)},{negX:-2*o.reduce(r,{max:0,nearmax:0}).max,posX:2*i.max}}boundsLowerRealFujiwara(){const t=new Ue;t.coefs=this.coefs.slice().reverse();const e=t.boundsUpperRealFujiwara();return e.negX=1/e.negX,e.posX=1/e.posX,e}bounds(){const t=this.boundsUpperRealFujiwara(),e={minX:t.negX,maxX:t.posX};return t.negX===0&&t.posX===0||(t.negX===0?e.minX=this.boundsLowerRealFujiwara().posX:t.posX===0&&(e.maxX=this.boundsLowerRealFujiwara().negX),e.minX>e.maxX&&(e.minX=e.maxX=0)),e}boundUpperAbsRouche(){const t=this.coefs,e=t.length-1;return 1+t.reduce((o,s,r)=>r!==e?(s=Math.abs(s),o<s?s:o):o,0)/Math.abs(t[e])}boundLowerAbsRouche(){const t=this.coefs,e=t.reduce((n,o,s)=>s!==0?(o=Math.abs(o),n<o?o:n):n,0);return Math.abs(t[0])/(Math.abs(t[0])+e)}boundsRealLaguerre(){const t=this.coefs,e=t.length-1,n=-t[e-1]/(e*t[e]),o=t[e-1]*t[e-1]-2*e/(e-1)*t[e]*t[e-2];let s=(e-1)/(e*t[e])*Math.sqrt(o);return s<0&&(s=-s),{minX:n-s,maxX:n+s}}countRootsDescartes(){const t=this.coefs,e=t.length-1,n=t.reduce((o,s,r)=>(o.prev_a!==0&&s!==0&&(o.prev_a<0==s>0&&o.pos++,r%2===0!=o.prev_a<0==(r%2===1!=s>0)&&o.neg++),o.prev_a=s,o),{pos:0,neg:0,prev_a:0});return{maxRealPos:n.pos,maxRealNeg:n.neg,minComplex:e-(n.pos+n.neg)}}getDegree(){return this.coefs.length-1}getDerivative(){const t=new Ue;for(let e=1;e<this.coefs.length;e++)t.coefs.push(e*this.coefs[e]);return t}getRoots(){let t;switch(this.simplifyEquals(),this.getDegree()){case 0:t=[];break;case 1:t=this.getLinearRoot();break;case 2:t=this.getQuadraticRoots();break;case 3:t=this.getCubicRoots();break;case 4:t=this.getQuarticRoots();break;default:t=[]}return t}getRootsInInterval(t,e){const n=[];function o(s){typeof s=="number"&&n.push(s)}if(this.getDegree()===0)throw new RangeError("Unexpected empty polynomial");if(this.getDegree()===1)o(this.bisection(t,e));else{const r=this.getDerivative().getRootsInInterval(t,e);if(r.length>0){o(this.bisection(t,r[0]));for(let i=0;i<=r.length-2;i++)o(this.bisection(r[i],r[i+1]));o(this.bisection(r[r.length-1],e))}else o(this.bisection(t,e))}return n}getLinearRoot(){const t=[],e=this.coefs[1];return e!==0&&t.push(-this.coefs[0]/e),t}getQuadraticRoots(){const t=[];if(this.getDegree()===2){const e=this.coefs[2],n=this.coefs[1]/e,o=this.coefs[0]/e,s=n*n-4*o;if(s>0){const r=Math.sqrt(s);t.push(.5*(-n+r)),t.push(.5*(-n-r))}else s===0&&t.push(.5*-n)}return t}getCubicRoots(){const t=[];if(this.getDegree()===3){const e=this.coefs[3],n=this.coefs[2]/e,o=this.coefs[1]/e,s=this.coefs[0]/e,r=(3*o-n*n)/3,i=(2*n*n*n-9*o*n+27*s)/27,a=n/3;let c=i*i/4+r*r*r/27;const h=i/2,d=this.zeroErrorEstimate();if(Math.abs(c)<=d&&(c=0),c>0){const u=Math.sqrt(c);let f,g=-h+u;g>=0?f=Math.pow(g,1/3):f=-Math.pow(-g,1/3),g=-h-u,g>=0?f+=Math.pow(g,1/3):f-=Math.pow(-g,1/3),t.push(f-a)}else if(c<0){const u=Math.sqrt(-r/3),f=Math.atan2(Math.sqrt(-c),-h)/3,g=Math.cos(f),y=Math.sin(f),P=Math.sqrt(3);t.push(2*u*g-a),t.push(-u*(g+P*y)-a),t.push(-u*(g-P*y)-a)}else{let u;h>=0?u=-Math.pow(h,1/3):u=Math.pow(-h,1/3),t.push(2*u-a),t.push(-u-a)}}return t}getQuarticRoots(){let t=[];const e=this.getDegree();if(e===4){const n=new Ue;n.coefs=this.coefs.slice(),n.divideEqualsScalar(n.coefs[e]);const o=1e-15;Math.abs(n.coefs[0])<10*o*Math.abs(n.coefs[3])&&(n.coefs[0]=0);const s=n.getDerivative(),r=s.getRoots().sort((w,L)=>w-L),i=[],a=r.length-1,c=this.bounds(),h=Math.max(Math.abs(c.minX),Math.abs(c.maxX)),d=this.zeroErrorEstimate(h);for(let w=0;w<=a;w++)i.push(n.eval(r[w]));for(let w=0;w<=a;w++)Math.abs(i[w])<d&&(i[w]=0);let u=0;const f=Math.max(.1*(c.maxX-c.minX)/e,o),g=[],y=[];if(a>-1){for(i[0]!==0?St(i[0])!==St(n.eval(r[0]-f)-i[0])&&(g.push(r[0]-f),y.push([c.minX,r[0]])):(t.push(r[0],r[0]),u++);u<a;u++)i[u+1]===0?(t.push(r[u+1],r[u+1]),u++):St(i[u])!==St(i[u+1])&&(g.push((r[u]+r[u+1])/2),y.push([r[u],r[u+1]]));i[a]!==0&&St(i[a])!==St(n.eval(r[a]+f)-i[a])&&(g.push(r[a]+f),y.push([r[a],c.maxX]))}const P=function(w){return n.eval(w)},b=function(w){return s.eval(w)};if(g.length>0)for(u=0;u<g.length;u++)g[u]=Ue.newtonSecantBisection(g[u],P,b,32,y[u][0],y[u][1]);t=t.concat(g)}return t}}class ft{constructor(t,e){this.type=t,this.text=e}typeis(t){return this.type===t}}ft.UNDEFINED=0,ft.COMMAND=1,ft.NUMBER=2,ft.EOD=3;class Nh{constructor(t){t==null&&(t=""),this.setPathData(t)}setPathData(t){if(typeof t!="string")throw new TypeError("The first parameter must be a string");this._pathData=t}getNextToken(){let t=null,e=this._pathData;for(;t===null;)if(e===null||e==="")t=new ft(ft.EOD,"");else if(e.match(/^([ \t\r\n,]+)/))e=e.substr(RegExp.$1.length);else if(e.match(/^([AaCcHhLlMmQqSsTtVvZz])/))t=new ft(ft.COMMAND,RegExp.$1),e=e.substr(RegExp.$1.length);else if(e.match(/^(([-+]?\d+(\.\d*)?|[-+]?\.\d+)([eE][-+]?\d+)?)/))t=new ft(ft.NUMBER,RegExp.$1),e=e.substr(RegExp.$1.length);else throw new SyntaxError(`Unrecognized path data: ${e}`);return this._pathData=e,t}}const Ts="BOP";class In{constructor(){this._lexer=new Nh,this._handler=null}parseData(t){if(typeof t!="string")throw new TypeError(`The first parameter must be a string: ${t}`);this._handler!==null&&typeof this._handler.beginParse=="function"&&this._handler.beginParse();const e=this._lexer;e.setPathData(t);let n=Ts,o=null,s=e.getNextToken();for(;s.typeis(ft.EOD)===!1;){let r;const i=[];switch(s.type){case ft.COMMAND:if(n===Ts&&s.text!=="M"&&s.text!=="m")throw new SyntaxError(`New paths must begin with a moveto command. Found '${s.text}'`);n=s.text,r=In.PARAMCOUNT[s.text.toUpperCase()],s=e.getNextToken();break;case ft.NUMBER:if(n===Ts)throw new SyntaxError(`New paths must begin with a moveto command. Found '${s.text}'`);r=In.PARAMCOUNT[n.toUpperCase()];break;default:throw new SyntaxError(`Unrecognized command type: ${s.type}`)}for(let a=0;a<r;a++){switch(s.type){case ft.COMMAND:throw new SyntaxError(`Parameter must be a number. Found '${s.text}'`);case ft.NUMBER:i[a]=parseFloat(s.text);break;case ft.EOD:throw new SyntaxError("Unexpected end of string");default:throw new SyntaxError(`Unrecognized parameter type. Found type '${s.type}'`)}s=e.getNextToken()}if(this._handler!==null){const a=this._handler,c=In.METHODNAME[n];(n==="a"||n==="A")&&(i[3]=i[3]!==0,i[4]=i[4]!==0),a!==null&&typeof a[c]=="function"&&a[c](...i)}switch(n){case"M":n="L";break;case"m":n="l";break;case"Z":case"z":n="BOP";break}if(s===o)throw new SyntaxError(`Parser stalled on '${s.text}'`);o=s}this._handler!==null&&typeof this._handler.endParse=="function"&&this._handler.endParse()}setHandler(t){this._handler=t}}In.PARAMCOUNT={A:7,C:6,H:1,L:2,M:2,Q:4,S:4,T:2,V:1,Z:0},In.METHODNAME={A:"arcAbs",a:"arcRel",C:"curvetoCubicAbs",c:"curvetoCubicRel",H:"linetoHorizontalAbs",h:"linetoHorizontalRel",L:"linetoAbs",l:"linetoRel",M:"movetoAbs",m:"movetoRel",Q:"curvetoQuadraticAbs",q:"curvetoQuadraticRel",S:"curvetoCubicSmoothAbs",s:"curvetoCubicSmoothRel",T:"curvetoQuadraticSmoothAbs",t:"curvetoQuadraticSmoothRel",V:"linetoVerticalAbs",v:"linetoVerticalRel",Z:"closePath",z:"closePath"};const Bh=2*Math.PI;function fi(l,t,e,n,o,s,r){o=o*Math.PI/180;const i=Math.cos(o),a=Math.sin(o),c=1e-6,h=l.subtract(t).multiply(.5),d=h.x*i+h.y*a,u=h.x*-a+h.y*i;e=Math.abs(e),n=Math.abs(n);const f=d*d,g=u*u,y=f/(e*e)+g/(n*n);if(y>1){const pe=Math.sqrt(y);e*=pe,n*=pe}const P=e*e,b=n*n,w=P*g,L=b*f;let B=(P*b-w-L)/(w+L);Math.abs(B)<c&&(B=0);let H=Math.sqrt(B);s===r&&(H=-H);const E=l.add(t).multiply(.5),X=H*e*u/n,$=H*-n*d/e,Z=(d-X)/e,se=(d+X)/e,ne=(u-$)/n,ae=(u+$)/n,te=new rt(1,0).angleBetween(new rt(Z,ne));let ce=new rt(Z,ne).angleBetween(new rt(-se,-ae));return r===!1&&(ce-=Bh),[X*i-$*a+E.x,X*a+$*i+E.y,e,n,te,te+ce]}class Rh{constructor(t){this.shapeCreator=t,this.shapes=[],this.firstX=null,this.firstY=null,this.lastX=null,this.lastY=null,this.lastCommand=null}beginParse(){this.shapes=[],this.firstX=null,this.firstY=null,this.lastX=null,this.lastY=null,this.lastCommand=null}addShape(t){this.shapes.push(t)}arcAbs(t,e,n,o,s,r,i){if(t===0||e===0)this.addShape(this.shapeCreator.line(this.lastX,this.lastY,r,i));else{const a=fi(new ge(this.lastX,this.lastY),new ge(r,i),t,e,n,o,s);this.addShape(this.shapeCreator.arc(...a))}this.lastCommand="A",this.lastX=r,this.lastY=i}arcRel(t,e,n,o,s,r,i){if(t===0||e===0)this.addShape(this.shapeCreator.line(this.lastX,this.lastY,this.lastX+r,this.lastY+i));else{const a=fi(new ge(this.lastX,this.lastY),new ge(this.lastX+r,this.lastY+i),t,e,n,o,s);this.addShape(this.shapeCreator.arc(...a))}this.lastCommand="a",this.lastX+=r,this.lastY+=i}curvetoCubicAbs(t,e,n,o,s,r){this.addShape(this.shapeCreator.cubicBezier(this.lastX,this.lastY,t,e,n,o,s,r)),this.lastX=s,this.lastY=r,this.lastCommand="C"}curvetoCubicRel(t,e,n,o,s,r){this.addShape(this.shapeCreator.cubicBezier(this.lastX,this.lastY,this.lastX+t,this.lastY+e,this.lastX+n,this.lastY+o,this.lastX+s,this.lastY+r)),this.lastX+=s,this.lastY+=r,this.lastCommand="c"}linetoHorizontalAbs(t){this.addShape(this.shapeCreator.line(this.lastX,this.lastY,t,this.lastY)),this.lastX=t,this.lastCommand="H"}linetoHorizontalRel(t){this.addShape(this.shapeCreator.line(this.lastX,this.lastY,this.lastX+t,this.lastY)),this.lastX+=t,this.lastCommand="h"}linetoAbs(t,e){this.addShape(this.shapeCreator.line(this.lastX,this.lastY,t,e)),this.lastX=t,this.lastY=e,this.lastCommand="L"}linetoRel(t,e){this.addShape(this.shapeCreator.line(this.lastX,this.lastY,this.lastX+t,this.lastY+e)),this.lastX+=t,this.lastY+=e,this.lastCommand="l"}movetoAbs(t,e){this.firstX=t,this.firstY=e,this.lastX=t,this.lastY=e,this.lastCommand="M"}movetoRel(t,e){this.firstX+=t,this.firstY+=e,this.lastX+=t,this.lastY+=e,this.lastCommand="m"}curvetoQuadraticAbs(t,e,n,o){this.addShape(this.shapeCreator.quadraticBezier(this.lastX,this.lastY,t,e,n,o)),this.lastX=n,this.lastY=o,this.lastCommand="Q"}curvetoQuadraticRel(t,e,n,o){this.addShape(this.shapeCreator.quadraticBezier(this.lastX,this.lastY,this.lastX+t,this.lastY+e,this.lastX+n,this.lastY+o)),this.lastX+=n,this.lastY+=o,this.lastCommand="q"}curvetoCubicSmoothAbs(t,e,n,o){let s,r;if(this.lastCommand.match(/^[SsCc]$/)){const i=this.shapes[this.shapes.length-1].args[2];s=2*this.lastX-i.x,r=2*this.lastY-i.y}else s=this.lastX,r=this.lastY;this.addShape(this.shapeCreator.cubicBezier(this.lastX,this.lastY,s,r,t,e,n,o)),this.lastX=n,this.lastY=o,this.lastCommand="S"}curvetoCubicSmoothRel(t,e,n,o){let s,r;if(this.lastCommand.match(/^[SsCc]$/)){const i=this.shapes[this.shapes.length-1].args[2];s=2*this.lastX-i.x,r=2*this.lastY-i.y}else s=this.lastX,r=this.lastY;this.addShape(this.shapeCreator.cubicBezier(this.lastX,this.lastY,s,r,this.lastX+t,this.lastY+e,this.lastX+n,this.lastY+o)),this.lastX+=n,this.lastY+=o,this.lastCommand="s"}curvetoQuadraticSmoothAbs(t,e){let n,o;if(this.lastCommand.match(/^[QqTt]$/)){const s=this.shapes[this.shapes.length-1].args[1];n=2*this.lastX-s.x,o=2*this.lastY-s.y}else n=this.lastX,o=this.lastY;this.addShape(this.shapeCreator.quadraticBezier(this.lastX,this.lastY,n,o,t,e)),this.lastX=t,this.lastY=e,this.lastCommand="T"}curvetoQuadraticSmoothRel(t,e){let n,o;if(this.lastCommand.match(/^[QqTt]$/)){const s=this.shapes[this.shapes.length-1].args[1];n=2*this.lastX-s.x,o=2*this.lastY-s.y}else n=this.lastX,o=this.lastY;this.addShape(this.shapeCreator.quadraticBezier(this.lastX,this.lastY,n,o,this.lastX+t,this.lastY+e)),this.lastX+=t,this.lastY+=e,this.lastCommand="t"}linetoVerticalAbs(t){this.addShape(this.shapeCreator.line(this.lastX,this.lastY,this.lastX,t)),this.lastY=t,this.lastCommand="V"}linetoVerticalRel(t){this.addShape(this.shapeCreator.line(this.lastX,this.lastY,this.lastX,this.lastY+t)),this.lastY+=t,this.lastCommand="v"}closePath(){this.addShape(this.shapeCreator.line(this.lastX,this.lastY,this.firstX,this.firstY)),this.lastX=this.firstX,this.lastY=this.firstY,this.lastCommand="z"}}const Tn=Math.PI*.5,gi=new In;function tn(l,t){const e=[];for(const[n,o]of l){let s=null;if(o==="Point2D")s=Ls(n,t);else if(o==="Number")s=yi(n,t);else if(o==="Array<Point2D>"||o==="Point2D[]"){const r=[];for(;t.length>0;)r.push(Ls(n,t));r.length>0&&(s=r)}else if(o==="Optional<Number>"||o==="Number?")s=yi(n,t),s===null&&(s=void 0);else throw new TypeError(`Unrecognized value type: ${o}`);if(s!==null)e.push(s);else throw new TypeError(`Unable to extract value for ${n}`)}return e}function yi(l,t){let e=null;if(t.length>0){const n=t[0],o=typeof n;if(o==="number")return t.shift();if(o==="object"){for(const s of l)if(s in n&&typeof n[s]=="number"){e=n[s];break}}}return e}function Ls(l,t){let e=null;if(t.length>0){const n=t[0],o=typeof n;if(o==="number"){if(t.length>1){const s=t.shift(),r=t.shift();e=new ge(s,r)}}else if(Array.isArray(n)&&n.length>1)if(n.length===2){const[s,r]=t.shift();e=new ge(s,r)}else throw new TypeError(`Unhandled array of length ${n.length}`);else if(o==="object"){if("x"in n&&"y"in n)e=new ge(n.x,n.y),t.shift();else for(const s of l)if(Array.isArray(s)){if(s.every(r=>r in n)){e=new ge(n[s[0]],n[s[1]]);break}}else if(s in n){e=Ls([],[n[s]]);break}}}return e}class q{constructor(t,e){this.name=t,this.args=e}static arc(...t){const n=tn([[["center",["centerX","centerY"],["cx","cy"]],"Point2D"],[["radiusX","rx"],"Number"],[["radiusY","ry"],"Number"],[["startRadians"],"Number"],[["endRadians"],"Number"]],t);return new q(q.ARC,n)}static quadraticBezier(...t){const n=tn([[["p1",["p1x","p1y"]],"Point2D"],[["p2",["p2x","p2y"]],"Point2D"],[["p3",["p3x","p3y"]],"Point2D"]],t);return new q(q.QUADRATIC_BEZIER,n)}static cubicBezier(...t){const n=tn([[["p1",["p1x","p1y"]],"Point2D"],[["p2",["p2x","p2y"]],"Point2D"],[["p3",["p3x","p3y"]],"Point2D"],[["p4",["p4x","p4y"]],"Point2D"]],t);return new q(q.CUBIC_BEZIER,n)}static circle(...t){const n=tn([[["center",["centerX","centerY"],["cx","cy"]],"Point2D"],[["radius","r"],"Number"]],t);return new q(q.CIRCLE,n)}static ellipse(...t){const n=tn([[["center",["centerX","centerY"],["cx","cy"]],"Point2D"],[["radiusX","rx"],"Number"],[["radiusY","ry"],"Number"]],t);return new q(q.ELLIPSE,n)}static line(...t){const n=tn([[["p1",["p1x","p1y"],["x1","y1"]],"Point2D"],[["p2",["p2x","p2y"],["x2","y2"]],"Point2D"]],t);return new q(q.LINE,n)}static path(...t){return gi.parseData(t[0]),new q(q.PATH,xi.shapes)}static polygon(...t){const n=tn([[[],"Array<Point2D>"]],t.length===1&&Array.isArray(t[0])?t[0]:t);return new q(q.POLYGON,n)}static polyline(...t){const n=tn([[[],"Array<Point2D>"]],t.length===1&&Array.isArray(t[0])?t[0]:t);return new q(q.POLYLINE,n)}static rectangle(...t){const n=tn([[["topLeft",["x","y"],["left","top"]],"Point2D"],[["size",["width","height"],["w","h"]],"Point2D"],[["radiusX","rx"],"Optional<Number>"],[["radiusY","ry"],"Optional<Number>"]],t),o=n[0],s=n[1];n[1]=new ge(o.x+s.x,o.y+s.y);const r=new q(q.RECTANGLE,n);let i=r.args.pop(),a=r.args.pop();if(a=a===void 0?0:a,i=i===void 0?0:i,a===0&&i===0)return r;const{x:c,y:h}=r.args[0],{x:d,y:u}=r.args[1],f=d-c,g=u-h;a===0&&(a=i),i===0&&(i=a),a>f*.5&&(a=f*.5),i>g*.5&&(i=g*.5);const y=c,P=h,b=c+a,w=h+i,L=d-a,B=u-i,H=d,E=u,X=[q.arc(b,w,a,i,2*Tn,3*Tn),q.line(b,P,L,P),q.arc(L,w,a,i,3*Tn,4*Tn),q.line(H,w,H,B),q.arc(L,B,a,i,0,Tn),q.line(L,E,b,E),q.arc(b,B,a,i,Tn,2*Tn),q.line(y,B,y,w)];return new q(q.PATH,X)}}q.ARC="Arc",q.QUADRATIC_BEZIER="Bezier2",q.CUBIC_BEZIER="Bezier3",q.CIRCLE="Circle",q.ELLIPSE="Ellipse",q.LINE="Line",q.PATH="Path",q.POLYGON="Polygon",q.POLYLINE="Polyline",q.RECTANGLE="Rectangle";const xi=new Rh(q);gi.setHandler(xi);const io=2*Math.PI,Eh=new rt(1,0);function wi(l){return l==null}function Hh(l,t){const e=l[0]*t[1]-t[0]*l[1],n=l[0]*t[2]-t[0]*l[2],o=l[0]*t[3]-t[0]*l[3],s=l[0]*t[4]-t[0]*l[4],r=l[0]*t[5]-t[0]*l[5],i=l[1]*t[2]-t[1]*l[2],a=l[1]*t[4]-t[1]*l[4],c=l[1]*t[5]-t[1]*l[5],h=l[2]*t[3]-t[2]*l[3],d=l[3]*t[4]-t[3]*l[4],u=l[3]*t[5]-t[3]*l[5],f=c+d,g=a-h;return new Ue(e*i-n*n,e*g+o*i-2*n*s,e*f+o*g-s*s-2*n*r,e*u+o*f-2*s*r,o*u-r*r)}function Dh(l){const t=l%io;return t<0?t+io:t}function Oh(l,t,e,n,o,s){if(l.points.length===0)return l;const r=new Y("No Intersection");s<o&&([o,s]=[s,o]),(o<0||s<0)&&(o+=io,s+=io);for(const i of l.points){let a=Dh(Eh.angleBetween(rt.fromPoints(t,i)));a<o&&(a+=io),o<=a&&a<=s&&r.appendPoint(i)}return r.points.length>0&&(r.status="Intersection"),r}function nn(l){const t=l.slice();return t.push(l[0]),t}class Y{constructor(t){this.init(t)}init(t){this.status=t,this.points=[]}static intersect(t,e){let n;if(!wi(t)&&!wi(e))if(t.name==="Path")n=Y.intersectPathShape(t,e);else if(e.name==="Path")n=Y.intersectPathShape(e,t);else if(t.name==="Arc")n=Y.intersectArcShape(t,e);else if(e.name==="Arc")n=Y.intersectArcShape(e,t);else{let o,s;if(t.name<e.name?(o="intersect"+t.name+e.name,s=t.args.concat(e.args)):(o="intersect"+e.name+t.name,s=e.args.concat(t.args)),!(o in Y))throw new TypeError("Intersection not available: "+o);n=Y[o].apply(null,s)}else n=new Y("No Intersection");return n}static intersectPathShape(t,e){const n=new Y("No Intersection");for(const o of t.args){const s=Y.intersect(o,e);n.appendPoints(s.points)}return n.points.length>0&&(n.status="Intersection"),n}static intersectArcShape(t,e){const[n,o,s,r,i]=t.args,a=new q(q.ELLIPSE,[n,o,s]),c=Y.intersect(a,e);return Oh(c,n,o,s,r,i)}static intersectBezier2Bezier2(t,e,n,o,s,r){let i,a;const c=new Y("No Intersection");i=e.multiply(-2);const h=t.add(i.add(n));i=t.multiply(-2),a=e.multiply(2);const d=i.add(a),u=new ge(t.x,t.y);i=s.multiply(-2);const f=o.add(i.add(r));i=o.multiply(-2),a=s.multiply(2);const g=i.add(a),y=new ge(o.x,o.y);i=h.x*d.y-d.x*h.y,a=f.x*d.y-d.x*f.y;const P=g.x*d.y-d.x*g.y,b=d.x*(u.y-y.y)+d.y*(-u.x+y.x),w=f.x*h.y-h.x*f.y,L=g.x*h.y-h.x*g.y,B=h.x*(u.y-y.y)+h.y*(-u.x+y.x),E=new Ue(-w*w,-2*w*L,i*a-L*L-2*w*B,i*P-2*L*B,i*b-B*B).getRoots();for(const X of E)if(0<=X&&X<=1){const $=new Ue(h.x,d.x,u.x-y.x-X*g.x-X*X*f.x);$.simplifyEquals();const Z=$.getRoots(),se=new Ue(h.y,d.y,u.y-y.y-X*g.y-X*X*f.y);se.simplifyEquals();const ne=se.getRoots();if(Z.length>0&&ne.length>0){e:for(const te of Z)if(0<=te&&te<=1){for(let ce=0;ce<ne.length;ce++)if(Math.abs(te-ne[ce])<1e-4){c.points.push(f.multiply(X*X).add(g.multiply(X).add(y)));break e}}}}return c.points.length>0&&(c.status="Intersection"),c}static intersectBezier2Bezier3(t,e,n,o,s,r,i){let a,c,h,d;const u=new Y("No Intersection");a=e.multiply(-2);const f=t.add(a.add(n));a=t.multiply(-2),c=e.multiply(2);const g=a.add(c),y=new ge(t.x,t.y);a=o.multiply(-1),c=s.multiply(3),h=r.multiply(-3),d=a.add(c.add(h.add(i)));const P=new ge(d.x,d.y);a=o.multiply(3),c=s.multiply(-6),h=r.multiply(3),d=a.add(c.add(h));const b=new ge(d.x,d.y);a=o.multiply(-3),c=s.multiply(3),h=a.add(c);const w=new ge(h.x,h.y),L=new ge(o.x,o.y),B=y.x*y.x,H=y.y*y.y,E=g.x*g.x,X=g.y*g.y,$=f.x*f.x,Z=f.y*f.y,se=L.x*L.x,ne=L.y*L.y,ae=w.x*w.x,te=w.y*w.y,ce=b.x*b.x,pe=b.y*b.y,Be=P.x*P.x,Re=P.y*P.y,Te=new Ue(-2*f.x*f.y*P.x*P.y+$*Re+Z*Be,-2*f.x*f.y*b.x*P.y-2*f.x*f.y*b.y*P.x+2*Z*b.x*P.x+2*$*b.y*P.y,-2*f.x*w.x*f.y*P.y-2*f.x*f.y*w.y*P.x-2*f.x*f.y*b.x*b.y+2*w.x*Z*P.x+Z*ce+$*(2*w.y*P.y+pe),2*y.x*f.x*f.y*P.y+2*y.y*f.x*f.y*P.x+g.x*g.y*f.x*P.y+g.x*g.y*f.y*P.x-2*L.x*f.x*f.y*P.y-2*f.x*L.y*f.y*P.x-2*f.x*w.x*f.y*b.y-2*f.x*f.y*w.y*b.x-2*y.x*Z*P.x-2*y.y*$*P.y+2*L.x*Z*P.x+2*w.x*Z*b.x-X*f.x*P.x-E*f.y*P.y+$*(2*L.y*P.y+2*w.y*b.y),2*y.x*f.x*f.y*b.y+2*y.y*f.x*f.y*b.x+g.x*g.y*f.x*b.y+g.x*g.y*f.y*b.x-2*L.x*f.x*f.y*b.y-2*f.x*L.y*f.y*b.x-2*f.x*w.x*f.y*w.y-2*y.x*Z*b.x-2*y.y*$*b.y+2*L.x*Z*b.x-X*f.x*b.x-E*f.y*b.y+ae*Z+$*(2*L.y*b.y+te),2*y.x*f.x*f.y*w.y+2*y.y*f.x*w.x*f.y+g.x*g.y*f.x*w.y+g.x*g.y*w.x*f.y-2*L.x*f.x*f.y*w.y-2*f.x*L.y*w.x*f.y-2*y.x*w.x*Z-2*y.y*$*w.y+2*L.x*w.x*Z-X*f.x*w.x-E*f.y*w.y+2*$*L.y*w.y,-2*y.x*y.y*f.x*f.y-y.x*g.x*g.y*f.y-y.y*g.x*g.y*f.x+2*y.x*f.x*L.y*f.y+2*y.y*L.x*f.x*f.y+g.x*L.x*g.y*f.y+g.x*g.y*f.x*L.y-2*L.x*f.x*L.y*f.y-2*y.x*L.x*Z+y.x*X*f.x+y.y*E*f.y-2*y.y*$*L.y-L.x*X*f.x-E*L.y*f.y+B*Z+H*$+se*Z+$*ne).getRootsInInterval(0,1);for(const fe of Te){const O=new Ue(f.x,g.x,y.x-L.x-fe*w.x-fe*fe*b.x-fe*fe*fe*P.x).getRoots(),G=new Ue(f.y,g.y,y.y-L.y-fe*w.y-fe*fe*b.y-fe*fe*fe*P.y).getRoots();if(O.length>0&&G.length>0){e:for(const _ of O)if(0<=_&&_<=1){for(let Ve=0;Ve<G.length;Ve++)if(Math.abs(_-G[Ve])<1e-4){u.points.push(P.multiply(fe*fe*fe).add(b.multiply(fe*fe).add(w.multiply(fe).add(L))));break e}}}}return u.points.length>0&&(u.status="Intersection"),u}static intersectBezier2Circle(t,e,n,o,s){return Y.intersectBezier2Ellipse(t,e,n,o,s,s)}static intersectBezier2Ellipse(t,e,n,o,s,r){let i;const a=new Y("No Intersection");i=e.multiply(-2);const c=t.add(i.add(n));i=t.multiply(-2);const h=e.multiply(2),d=i.add(h),u=new ge(t.x,t.y),f=s*s,g=r*r,y=new Ue(g*c.x*c.x+f*c.y*c.y,2*(g*c.x*d.x+f*c.y*d.y),g*(2*c.x*u.x+d.x*d.x)+f*(2*c.y*u.y+d.y*d.y)-2*(g*o.x*c.x+f*o.y*c.y),2*(g*d.x*(u.x-o.x)+f*d.y*(u.y-o.y)),g*(u.x*u.x+o.x*o.x)+f*(u.y*u.y+o.y*o.y)-2*(g*o.x*u.x+f*o.y*u.y)-f*g).getRoots();for(const P of y)0<=P&&P<=1&&a.points.push(c.multiply(P*P).add(d.multiply(P).add(u)));return a.points.length>0&&(a.status="Intersection"),a}static intersectBezier2Line(t,e,n,o,s){let r;const i=o.min(s),a=o.max(s),c=new Y("No Intersection");r=e.multiply(-2);const h=t.add(r.add(n));r=t.multiply(-2);const d=e.multiply(2),u=r.add(d),f=new ge(t.x,t.y),g=new rt(o.y-s.y,s.x-o.x),y=o.x*s.y-s.x*o.y,P=new Ue(g.dot(h),g.dot(u),g.dot(f)+y).getRoots();for(const b of P)if(0<=b&&b<=1){const w=t.lerp(e,b),L=e.lerp(n,b),B=w.lerp(L,b);o.x===s.x?i.y<=B.y&&B.y<=a.y&&(c.status="Intersection",c.appendPoint(B)):o.y===s.y?i.x<=B.x&&B.x<=a.x&&(c.status="Intersection",c.appendPoint(B)):i.x<=B.x&&B.x<=a.x&&i.y<=B.y&&B.y<=a.y&&(c.status="Intersection",c.appendPoint(B))}return c}static intersectBezier2Polygon(t,e,n,o){return Y.intersectBezier2Polyline(t,e,n,nn(o))}static intersectBezier2Polyline(t,e,n,o){const s=new Y("No Intersection"),{length:r}=o;for(let i=0;i<r-1;i++){const a=o[i],c=o[i+1],h=Y.intersectBezier2Line(t,e,n,a,c);s.appendPoints(h.points)}return s.points.length>0&&(s.status="Intersection"),s}static intersectBezier2Rectangle(t,e,n,o,s){const r=o.min(s),i=o.max(s),a=new ge(i.x,r.y),c=new ge(r.x,i.y),h=Y.intersectBezier2Line(t,e,n,r,a),d=Y.intersectBezier2Line(t,e,n,a,i),u=Y.intersectBezier2Line(t,e,n,i,c),f=Y.intersectBezier2Line(t,e,n,c,r),g=new Y("No Intersection");return g.appendPoints(h.points),g.appendPoints(d.points),g.appendPoints(u.points),g.appendPoints(f.points),g.points.length>0&&(g.status="Intersection"),g}static intersectBezier3Bezier3(t,e,n,o,s,r,i,a){let c,h,d,u;const f=new Y("No Intersection");c=t.multiply(-1),h=e.multiply(3),d=n.multiply(-3),u=c.add(h.add(d.add(o)));const g=new ge(u.x,u.y);c=t.multiply(3),h=e.multiply(-6),d=n.multiply(3),u=c.add(h.add(d));const y=new ge(u.x,u.y);c=t.multiply(-3),h=e.multiply(3),d=c.add(h);const P=new ge(d.x,d.y),b=new ge(t.x,t.y);c=s.multiply(-1),h=r.multiply(3),d=i.multiply(-3),u=c.add(h.add(d.add(a)));const w=new ge(u.x,u.y);c=s.multiply(3),h=r.multiply(-6),d=i.multiply(3),u=c.add(h.add(d));const L=new ge(u.x,u.y);c=s.multiply(-3),h=r.multiply(3),d=c.add(h);const B=new ge(d.x,d.y),H=new ge(s.x,s.y);c=g.x*y.y-y.x*g.y,h=g.x*P.y-P.x*g.y;const E=g.x*b.y-b.x*g.y+H.x*g.y-g.x*H.y,X=B.x*g.y-g.x*B.y,$=L.x*g.y-g.x*L.y,Z=w.x*g.y-g.x*w.y;u=g.x*P.y-P.x*g.y;const se=g.x*b.y+y.x*P.y-P.x*y.y-b.x*g.y+H.x*g.y-g.x*H.y,ne=B.x*g.y-g.x*B.y,ae=L.x*g.y-g.x*L.y,te=w.x*g.y-g.x*w.y,ce=y.x*b.y-b.x*y.y+H.x*y.y-y.x*H.y,pe=B.x*y.y-y.x*B.y,Be=L.x*y.y-y.x*L.y,Re=w.x*y.y-y.x*w.y,Me=g.x*b.y-b.x*g.y+H.x*g.y-g.x*H.y,Te=B.x*g.y-g.x*B.y,fe=L.x*g.y-g.x*L.y,O=w.x*g.y-g.x*w.y,G=y.x*b.y-b.x*y.y+H.x*y.y-y.x*H.y,j=B.x*y.y-y.x*B.y,_=L.x*y.y-y.x*L.y,Ve=w.x*y.y-y.x*w.y,ut=P.x*b.y-b.x*P.y+H.x*P.y-P.x*H.y,yt=B.x*P.y-P.x*B.y,Nt=L.x*P.y-P.x*L.y,Ft=w.x*P.y-P.x*w.y,ln=new Ue(-Z*te*O,-Z*te*fe-Z*ae*O-$*te*O,-Z*te*Te-Z*ae*fe-$*te*fe-Z*ne*O-$*ae*O-X*te*O,-Z*te*Me-Z*ae*Te-$*te*Te-Z*ne*fe-$*ae*fe-X*te*fe-Z*se*O-$*ne*O-X*ae*O-E*te*O+h*Re*O+Z*u*Ve-c*Re*Ve+c*te*Ft,-Z*ae*Me-$*te*Me-Z*ne*Te-$*ae*Te-X*te*Te-Z*se*fe-$*ne*fe-X*ae*fe-E*te*fe+h*Re*fe-$*se*O-X*ne*O-E*ae*O+h*Be*O+Z*u*_-c*Re*_+$*u*Ve-c*Be*Ve+c*te*Nt+c*ae*Ft,-Z*ne*Me-$*ae*Me-X*te*Me-Z*se*Te-$*ne*Te-X*ae*Te-E*te*Te+h*Re*Te-$*se*fe-X*ne*fe-E*ae*fe+h*Be*fe-X*se*O-E*ne*O+h*pe*O+Z*u*j-c*Re*j+$*u*_-c*Be*_+X*u*Ve-c*pe*Ve+c*te*yt+c*ae*Nt+c*ne*Ft,-Z*se*Me-$*ne*Me-X*ae*Me-E*te*Me+h*Re*Me-$*se*Te-X*ne*Te-E*ae*Te+h*Be*Te-X*se*fe-E*ne*fe+h*pe*fe-E*se*O+h*ce*O+Z*u*G-c*Re*G+$*u*j-c*Be*j+X*u*_-c*pe*_+E*u*Ve-c*ce*Ve+c*te*ut+c*ae*yt+c*ne*Nt-h*u*Ft+c*se*Ft,-$*se*Me-X*ne*Me-E*ae*Me+h*Be*Me-X*se*Te-E*ne*Te+h*pe*Te-E*se*fe+h*ce*fe+$*u*G-c*Be*G+X*u*j-c*pe*j+E*u*_-c*ce*_+c*ae*ut+c*ne*yt-h*u*Nt+c*se*Nt,-X*se*Me-E*ne*Me+h*pe*Me-E*se*Te+h*ce*Te+X*u*G-c*pe*G+E*u*j-c*ce*j+c*ne*ut-h*u*yt+c*se*yt,-E*se*Me+h*ce*Me+E*u*G-c*ce*G-h*u*ut+c*se*ut);ln.simplifyEquals();const On=ln.getRootsInInterval(0,1);for(const $e of On){const eo=new Ue(g.x,y.x,P.x,b.x-H.x-$e*B.x-$e*$e*L.x-$e*$e*$e*w.x);eo.simplifyEquals();const to=eo.getRoots(),mn=new Ue(g.y,y.y,P.y,b.y-H.y-$e*B.y-$e*$e*L.y-$e*$e*$e*w.y);mn.simplifyEquals();const Yt=mn.getRoots();if(to.length>0&&Yt.length>0){e:for(const no of to)if(0<=no&&no<=1){for(let Pn=0;Pn<Yt.length;Pn++)if(Math.abs(no-Yt[Pn])<1e-4){f.points.push(w.multiply($e*$e*$e).add(L.multiply($e*$e).add(B.multiply($e).add(H))));break e}}}}return f.points.length>0&&(f.status="Intersection"),f}static intersectBezier3Circle(t,e,n,o,s,r){return Y.intersectBezier3Ellipse(t,e,n,o,s,r,r)}static intersectBezier3Ellipse(t,e,n,o,s,r,i){let a,c,h,d;const u=new Y("No Intersection");a=t.multiply(-1),c=e.multiply(3),h=n.multiply(-3),d=a.add(c.add(h.add(o)));const f=new ge(d.x,d.y);a=t.multiply(3),c=e.multiply(-6),h=n.multiply(3),d=a.add(c.add(h));const g=new ge(d.x,d.y);a=t.multiply(-3),c=e.multiply(3),h=a.add(c);const y=new ge(h.x,h.y),P=new ge(t.x,t.y),b=r*r,w=i*i,B=new Ue(f.x*f.x*w+f.y*f.y*b,2*(f.x*g.x*w+f.y*g.y*b),2*(f.x*y.x*w+f.y*y.y*b)+g.x*g.x*w+g.y*g.y*b,2*f.x*w*(P.x-s.x)+2*f.y*b*(P.y-s.y)+2*(g.x*y.x*w+g.y*y.y*b),2*g.x*w*(P.x-s.x)+2*g.y*b*(P.y-s.y)+y.x*y.x*w+y.y*y.y*b,2*y.x*w*(P.x-s.x)+2*y.y*b*(P.y-s.y),P.x*P.x*w-2*P.y*s.y*b-2*P.x*s.x*w+P.y*P.y*b+s.x*s.x*w+s.y*s.y*b-b*w).getRootsInInterval(0,1);for(const H of B)u.points.push(f.multiply(H*H*H).add(g.multiply(H*H).add(y.multiply(H).add(P))));return u.points.length>0&&(u.status="Intersection"),u}static intersectBezier3Line(t,e,n,o,s,r){let i,a,c,h;const d=s.min(r),u=s.max(r),f=new Y("No Intersection");i=t.multiply(-1),a=e.multiply(3),c=n.multiply(-3),h=i.add(a.add(c.add(o)));const g=new rt(h.x,h.y);i=t.multiply(3),a=e.multiply(-6),c=n.multiply(3),h=i.add(a.add(c));const y=new rt(h.x,h.y);i=t.multiply(-3),a=e.multiply(3),c=i.add(a);const P=new rt(c.x,c.y),b=new rt(t.x,t.y),w=new rt(s.y-r.y,r.x-s.x),L=s.x*r.y-r.x*s.y,B=new Ue(w.dot(g),w.dot(y),w.dot(P),w.dot(b)+L).getRoots();for(const H of B)if(0<=H&&H<=1){const E=t.lerp(e,H),X=e.lerp(n,H),$=n.lerp(o,H),Z=E.lerp(X,H),se=X.lerp($,H),ne=Z.lerp(se,H);s.x===r.x?d.y<=ne.y&&ne.y<=u.y&&(f.status="Intersection",f.appendPoint(ne)):s.y===r.y?d.x<=ne.x&&ne.x<=u.x&&(f.status="Intersection",f.appendPoint(ne)):d.x<=ne.x&&ne.x<=u.x&&d.y<=ne.y&&ne.y<=u.y&&(f.status="Intersection",f.appendPoint(ne))}return f}static intersectBezier3Polygon(t,e,n,o,s){return Y.intersectBezier3Polyline(t,e,n,o,nn(s))}static intersectBezier3Polyline(t,e,n,o,s){const r=new Y("No Intersection"),{length:i}=s;for(let a=0;a<i-1;a++){const c=s[a],h=s[a+1],d=Y.intersectBezier3Line(t,e,n,o,c,h);r.appendPoints(d.points)}return r.points.length>0&&(r.status="Intersection"),r}static intersectBezier3Rectangle(t,e,n,o,s,r){const i=s.min(r),a=s.max(r),c=new ge(a.x,i.y),h=new ge(i.x,a.y),d=Y.intersectBezier3Line(t,e,n,o,i,c),u=Y.intersectBezier3Line(t,e,n,o,c,a),f=Y.intersectBezier3Line(t,e,n,o,a,h),g=Y.intersectBezier3Line(t,e,n,o,h,i),y=new Y("No Intersection");return y.appendPoints(d.points),y.appendPoints(u.points),y.appendPoints(f.points),y.appendPoints(g.points),y.points.length>0&&(y.status="Intersection"),y}static intersectCircleCircle(t,e,n,o){let s;const r=e+o,i=Math.abs(e-o),a=t.distanceFrom(n);if(a>r)s=new Y("Outside");else if(a<i)s=new Y("Inside");else{s=new Y("Intersection");const c=(e*e-o*o+a*a)/(2*a),h=Math.sqrt(e*e-c*c),d=t.lerp(n,c/a),u=h/a;s.points.push(new ge(d.x-u*(n.y-t.y),d.y+u*(n.x-t.x))),s.points.push(new ge(d.x+u*(n.y-t.y),d.y-u*(n.x-t.x)))}return s}static intersectCircleEllipse(t,e,n,o,s){return Y.intersectEllipseEllipse(t,e,e,n,o,s)}static intersectCircleLine(t,e,n,o){let s;const r=(o.x-n.x)*(o.x-n.x)+(o.y-n.y)*(o.y-n.y),i=2*((o.x-n.x)*(n.x-t.x)+(o.y-n.y)*(n.y-t.y)),a=t.x*t.x+t.y*t.y+n.x*n.x+n.y*n.y-2*(t.x*n.x+t.y*n.y)-e*e,c=i*i-4*r*a;if(c<0)s=new Y("Outside");else if(c===0)s=new Y("Tangent");else{const h=Math.sqrt(c),d=(-i+h)/(2*r),u=(-i-h)/(2*r);(d<0||d>1)&&(u<0||u>1)?d<0&&u<0||d>1&&u>1?s=new Y("Outside"):s=new Y("Inside"):(s=new Y("Intersection"),0<=d&&d<=1&&s.points.push(n.lerp(o,d)),0<=u&&u<=1&&s.points.push(n.lerp(o,u)))}return s}static intersectCirclePolygon(t,e,n){return Y.intersectCirclePolyline(t,e,nn(n))}static intersectCirclePolyline(t,e,n){const o=new Y("No Intersection"),{length:s}=n;let r;for(let i=0;i<s-1;i++){const a=n[i],c=n[i+1];r=Y.intersectCircleLine(t,e,a,c),o.appendPoints(r.points)}return o.points.length>0?o.status="Intersection":o.status=r.status,o}static intersectCircleRectangle(t,e,n,o){const s=n.min(o),r=n.max(o),i=new ge(r.x,s.y),a=new ge(s.x,r.y),c=Y.intersectCircleLine(t,e,s,i),h=Y.intersectCircleLine(t,e,i,r),d=Y.intersectCircleLine(t,e,r,a),u=Y.intersectCircleLine(t,e,a,s),f=new Y("No Intersection");return f.appendPoints(c.points),f.appendPoints(h.points),f.appendPoints(d.points),f.appendPoints(u.points),f.points.length>0?f.status="Intersection":f.status=c.status,f}static intersectEllipseEllipse(t,e,n,o,s,r){const i=[n*n,0,e*e,-2*n*n*t.x,-2*e*e*t.y,n*n*t.x*t.x+e*e*t.y*t.y-e*e*n*n],a=[r*r,0,s*s,-2*r*r*o.x,-2*s*s*o.y,r*r*o.x*o.x+s*s*o.y*o.y-s*s*r*r],h=Hh(i,a).getRoots(),d=.001,u=(i[0]*i[0]+2*i[1]*i[1]+i[2]*i[2])*d,f=(a[0]*a[0]+2*a[1]*a[1]+a[2]*a[2])*d,g=new Y("No Intersection");for(let y=0;y<h.length;y++){const b=new Ue(i[0],i[3]+h[y]*i[1],i[5]+h[y]*(i[4]+h[y]*i[2])).getRoots();for(let w=0;w<b.length;w++){let L=(i[0]*b[w]+i[1]*h[y]+i[3])*b[w]+(i[2]*h[y]+i[4])*h[y]+i[5];Math.abs(L)<u&&(L=(a[0]*b[w]+a[1]*h[y]+a[3])*b[w]+(a[2]*h[y]+a[4])*h[y]+a[5],Math.abs(L)<f&&g.appendPoint(new ge(b[w],h[y])))}}return g.points.length>0&&(g.status="Intersection"),g}static intersectEllipseLine(t,e,n,o,s){let r;const i=new rt(o.x,o.y),a=rt.fromPoints(o,s),c=new rt(t.x,t.y),h=i.subtract(c),d=new rt(a.x/(e*e),a.y/(n*n)),u=new rt(h.x/(e*e),h.y/(n*n)),f=a.dot(d),g=a.dot(u);t=h.dot(u)-1;const y=g*g-f*t;if(y<0)r=new Y("Outside");else if(y>0){const P=Math.sqrt(y),b=(-g-P)/f,w=(-g+P)/f;(b<0||1<b)&&(w<0||1<w)?b<0&&w<0||b>1&&w>1?r=new Y("Outside"):r=new Y("Inside"):(r=new Y("Intersection"),0<=b&&b<=1&&r.appendPoint(o.lerp(s,b)),0<=w&&w<=1&&r.appendPoint(o.lerp(s,w)))}else{const P=-g/f;0<=P&&P<=1?(r=new Y("Intersection"),r.appendPoint(o.lerp(s,P))):r=new Y("Outside")}return r}static intersectEllipsePolygon(t,e,n,o){return Y.intersectEllipsePolyline(t,e,n,nn(o))}static intersectEllipsePolyline(t,e,n,o){const s=new Y("No Intersection"),{length:r}=o;for(let i=0;i<r-1;i++){const a=o[i],c=o[i+1],h=Y.intersectEllipseLine(t,e,n,a,c);s.appendPoints(h.points)}return s.points.length>0&&(s.status="Intersection"),s}static intersectEllipseRectangle(t,e,n,o,s){const r=o.min(s),i=o.max(s),a=new ge(i.x,r.y),c=new ge(r.x,i.y),h=Y.intersectEllipseLine(t,e,n,r,a),d=Y.intersectEllipseLine(t,e,n,a,i),u=Y.intersectEllipseLine(t,e,n,i,c),f=Y.intersectEllipseLine(t,e,n,c,r),g=new Y("No Intersection");return g.appendPoints(h.points),g.appendPoints(d.points),g.appendPoints(u.points),g.appendPoints(f.points),g.points.length>0&&(g.status="Intersection"),g}static intersectLineLine(t,e,n,o){let s;const r=(o.x-n.x)*(t.y-n.y)-(o.y-n.y)*(t.x-n.x),i=(e.x-t.x)*(t.y-n.y)-(e.y-t.y)*(t.x-n.x),a=(o.y-n.y)*(e.x-t.x)-(o.x-n.x)*(e.y-t.y);if(a!==0){const c=r/a,h=i/a;0<=c&&c<=1&&0<=h&&h<=1?(s=new Y("Intersection"),s.points.push(new ge(t.x+c*(e.x-t.x),t.y+c*(e.y-t.y)))):s=new Y("No Intersection")}else r===0||i===0?s=new Y("Coincident"):s=new Y("Parallel");return s}static intersectLinePolygon(t,e,n){return Y.intersectLinePolyline(t,e,nn(n))}static intersectLinePolyline(t,e,n){const o=new Y("No Intersection"),{length:s}=n;for(let r=0;r<s-1;r++){const i=n[r],a=n[r+1],c=Y.intersectLineLine(t,e,i,a);o.appendPoints(c.points)}return o.points.length>0&&(o.status="Intersection"),o}static intersectLineRectangle(t,e,n,o){const s=n.min(o),r=n.max(o),i=new ge(r.x,s.y),a=new ge(s.x,r.y),c=Y.intersectLineLine(s,i,t,e),h=Y.intersectLineLine(i,r,t,e),d=Y.intersectLineLine(r,a,t,e),u=Y.intersectLineLine(a,s,t,e),f=new Y("No Intersection");return f.appendPoints(c.points),f.appendPoints(h.points),f.appendPoints(d.points),f.appendPoints(u.points),f.points.length>0&&(f.status="Intersection"),f}static intersectPolygonPolygon(t,e){return Y.intersectPolylinePolyline(nn(t),nn(e))}static intersectPolygonPolyline(t,e){return Y.intersectPolylinePolyline(nn(t),e)}static intersectPolygonRectangle(t,e,n){return Y.intersectPolylineRectangle(nn(t),e,n)}static intersectPolylinePolyline(t,e){const n=new Y("No Intersection"),{length:o}=t;for(let s=0;s<o-1;s++){const r=t[s],i=t[s+1],a=Y.intersectLinePolyline(r,i,e);n.appendPoints(a.points)}return n.points.length>0&&(n.status="Intersection"),n}static intersectPolylineRectangle(t,e,n){const o=e.min(n),s=e.max(n),r=new ge(s.x,o.y),i=new ge(o.x,s.y),a=Y.intersectLinePolyline(o,r,t),c=Y.intersectLinePolyline(r,s,t),h=Y.intersectLinePolyline(s,i,t),d=Y.intersectLinePolyline(i,o,t),u=new Y("No Intersection");return u.appendPoints(a.points),u.appendPoints(c.points),u.appendPoints(h.points),u.appendPoints(d.points),u.points.length>0&&(u.status="Intersection"),u}static intersectRectangleRectangle(t,e,n,o){const s=t.min(e),r=t.max(e),i=new ge(r.x,s.y),a=new ge(s.x,r.y),c=Y.intersectLineRectangle(s,i,n,o),h=Y.intersectLineRectangle(i,r,n,o),d=Y.intersectLineRectangle(r,a,n,o),u=Y.intersectLineRectangle(a,s,n,o),f=new Y("No Intersection");return f.appendPoints(c.points),f.appendPoints(h.points),f.appendPoints(d.points),f.appendPoints(u.points),f.points.length>0&&(f.status="Intersection"),f}static intersectRayRay(t,e,n,o){let s;const r=(o.x-n.x)*(t.y-n.y)-(o.y-n.y)*(t.x-n.x),i=(e.x-t.x)*(t.y-n.y)-(e.y-t.y)*(t.x-n.x),a=(o.y-n.y)*(e.x-t.x)-(o.x-n.x)*(e.y-t.y);if(a!==0){const c=r/a;s=new Y("Intersection"),s.points.push(new ge(t.x+c*(e.x-t.x),t.y+c*(e.y-t.y)))}else r===0||i===0?s=new Y("Coincident"):s=new Y("Parallel");return s}appendPoint(t){this.points.push(t)}appendPoints(t){this.points=this.points.concat(t)}}class Fn extends en{constructor(){super(...arguments);p(this,"imgBitmap",null);p(this,"fallbackDrawer",new kh);p(this,"broken",!1)}setBroken(e=!0){this.broken=e}setImageBitmap(e){this.imgBitmap=e}get borderProps(){return this.props.get(I.Border)}get cropProps(){return this.props.get(I.Crop)}updateProps(e){super.updateProps(e),e.find(o=>o.type===I.Base)&&this.updateTransformMatrix()}drawOnGLCtx(e){if(!this.imgBitmap){this.broken&&this.fallbackDrawer.fallbackDraw(this,e);return}e.save();const{a:n,b:o,c:s,d:r,e:i,f:a}=this.globalTransform();e.transform(n,o,s,r,i,a),this.clipDrawImage(e,this.imgBitmap),this.clipDrawBorder(e),e.restore()}clipDrawBorder(e){const n=this.borderProps,o=this.cropProps,s=this.baseProps;if(n.color!==""&&n.dashType!==et.None){if(M.setDashLine(n,e),e.strokeStyle=n.color,e.lineWidth=n.width,e.globalAlpha=n.alpha,o.cropType===wt.Circle){const r=.5*Math.min(s.width,s.height);e.beginPath(),e.arc(.5*s.width,.5*s.height,r,0,2*Math.PI),e.stroke();return}if(o.cropType===wt.RoundRect){e.beginPath(),e.roundRect(0,0,s.width,s.height,10),e.stroke();return}e.strokeRect(0,0,s.width,s.height)}}clipDrawImage(e,n){const o=this.cropProps,s=this.baseProps;if(o.cropType===wt.None)e.drawImage(n,0,0,s.width,s.height);else{if(e.save(),o.cropType===wt.RoundRect&&(e.beginPath(),e.roundRect(0,0,s.width,s.height,10),e.clip()),o.cropType===wt.Circle){const b=.5*Math.min(s.width,s.height);e.beginPath(),e.arc(.5*s.width,.5*s.height,b,0,2*Math.PI),e.clip()}const{imgX:r,imgY:i,imgWidth:a,imgHeight:c}=o.cropInfo,h=this.getImgSize(),d=a/h.imgWidth,u=c/h.imgHeight,f=-r/d,g=-i/u,y=s.width/d,P=s.height/u;e.drawImage(n,f,g,y,P,0,0,s.width,s.height),e.restore()}}getImgSize(){if(!this.imgBitmap){console.warn("img bitmap不存在,已经降级处理");const{width:o,height:s}=this.baseProps;return{imgWidth:o,imgHeight:s}}const e=this.imgBitmap.width,n=this.imgBitmap.height;return{imgWidth:e,imgHeight:n}}getOriginImageRect(){const{cropType:e,cropInfo:n}=this.cropProps;if(e===wt.None||!n){const a=this.baseProps;return new D(0,0,a.width,a.height)}const{imgX:o,imgY:s,imgWidth:r,imgHeight:i}=n;return new D(o,s,r,i)}getTextContentRect(){return this.baseProps}getConnectAnchor(){return[new m(.5,0),new m(1,.5),new m(.5,1),new m(0,.5)]}borderContains(e,n){const o=this.toLocal(e),{width:s,height:r}=this.baseProps,i=q.rectangle({top:0,left:0,width:s,height:r}),a=q.line({x:o.x-n,y:o.y},{x:o.x+n,y:o.y}),c=q.line({x:o.x,y:o.y-n},{x:o.x,y:o.y+n});for(const h of[a,c]){const d=Y.intersect(i,h);if(d.points.length>0)return d.points[0]}return null}}class Yn extends Fn{constructor(e,n){super(e,n);p(this,"type",v.IMG);this.props.set(I.Base,new ie),this.props.set(I.Border,new Ae),this.props.set(I.Image,new ro),this.props.set(I.Crop,new Sn)}get imgSrc(){return this.getProp(I.Image).url}static load(e,n,o,s,r,i){const a=new Yn(e,i);return a.type=n,a.zIndex=o,a.setParent(r),a.updateProps(s),a}}class Xh{draw(t,e){const n=t.getDrawPoints();if(n.length<2){console.error("line has no point!");return}const o=n[0],s=n.length>1?n[n.length-1]:{...o};e.beginPath(),e.moveTo(o.x,o.y),e.lineTo(s.x,s.y),e.stroke()}textContentBounds(t){const e=t.baseProps;return{x:e.x,y:e.y,width:e.width,height:e.height}}borderContains(t,e,n){return null}getConnectAnchor(){return[]}}class mi{static lineContainsPoint(t,e,n){const o=t.shapeType,s=[...t.points];return o===de.Line?this.simpleLineContains(s,e,n):t.isPolyLine()?this.polyLineContains(s,e,n):o===de.Curve?this.curveLineContains(s,e,n):!1}static overlapRectNode(t,e){const n=t.shapeType,o=[...t.points],s=q.rectangle({top:e.minY,left:e.minX,width:e.maxX-e.minX,height:e.maxY-e.minY});if(n===de.Line){const r=q.line(o[0],o[o.length-1]);if(Y.intersect(s,r).points.length>0)return!0}if(t.isPolyLine()){const r=q.polyline(o);if(Y.intersect(s,r).points.length>0)return!0}if(n===de.Curve)for(let r=0;r<o.length-2;r=r+3){const i=o[r],a=o[r+1],c=o[r+2],h=o[r+3],d=q.cubicBezier(i,a,c,h);if(Y.intersect(s,d).points.length>0)return!0}return!1}static curveLineContains(t,e,n){for(let o=0;o<t.length-2;o=o+3){const s=t[o],r=t[o+1],i=t[o+2],a=t[o+3],c=q.cubicBezier(s,r,i,a),h=q.circle(e,n);if(Y.intersect(h,c).points.length>0)return!0}return!1}static polyLineContains(t,e,n){const o=q.polyline(t),s=q.circle(e,n);return Y.intersect(s,o).points.length>0}static simpleLineContains(t,e,n){const o=q.line(t[0],t[t.length-1]),s=q.circle(e,n);return Y.intersect(s,o).points.length>0}}class zh{constructor(){p(this,"radius",8)}draw(t,e){const n=t.getDrawPoints();if(n.length<2)return;e.save(),e.beginPath();const o=n[0];e.moveTo(o.x,o.y);for(const s of n)e.lineTo(s.x,s.y);e.stroke(),e.restore()}textContentBounds(t){const e=t.baseProps;return new D(e.x,e.y,e.width,e.height)}borderContains(t,e,n){return null}getConnectAnchor(){return[]}}class Wh{draw(t,e){const n=t.getDrawPoints();if(!(n.length<3)){e.save(),e.beginPath();for(let o=1;o<n.length-2;o=o+3){const s=n[o-1],r=n[o],i=n[o+1],a=n[o+2];e.moveTo(s.x,s.y),e.bezierCurveTo(r.x,r.y,i.x,i.y,a.x,a.y)}e.stroke(),e.restore()}}textContentBounds(t){const e=t.baseProps;return{x:e.x,y:e.y,width:e.width,height:e.height}}borderContains(t,e,n){return null}getConnectAnchor(){return[]}}class Fh{constructor(){p(this,"radius",8)}draw(t,e){const n=t.getDrawPoints();n.length<2||(e.save(),e.beginPath(),t.points.length===2?(e.moveTo(n[0].x,n[0].y),e.lineTo(n[1].x,n[1].y),e.stroke()):this.acrPolyDraw(e,n),e.restore())}textContentBounds(t){const e=t.baseProps;return new D(e.x,e.y,e.width,e.height)}acrPolyDraw(t,e){const n=e[e.length-1],o=this.dealArcPoly(e);for(const s of o)t.moveTo(s.p0.x,s.p0.y),t.lineTo(s.p1.x,s.p1.y),s.arcDraw.r>1&&Number.isFinite(s.arcDraw.r)?t.arcTo(s.arcDraw.a.x,s.arcDraw.a.y,s.arcDraw.b.x,s.arcDraw.b.y,s.arcDraw.r):t.lineTo(s.arcDraw.b.x,s.arcDraw.b.y);t.lineTo(n.x,n.y),t.stroke()}dealArcPoly(t){const e=[];let n=t[0];for(let o=0;o<t.length-2;o=o+1){const s=n,r=t[o+1],i=t[o+2];if(M.judgeHorizon(s,r)){const c=.5*Math.abs(s.x-r.x),h=.5*Math.abs(r.y-i.y),d=c>h?h:c,u=this.radius<d?this.radius:d,f=u,g=r.x>s.x?1:-1,y=i.y>r.y?1:-1;n=new m(r.x,r.y+y*f);const P={p0:s,p1:new m(r.x-g*f,r.y),arcDraw:{a:r,b:n,r:u}};e.push(P)}else{const c=.5*Math.abs(s.y-r.y),h=.5*Math.abs(r.x-i.x),d=c>h?h:c,u=this.radius<d?this.radius:d,f=u,g=r.y>s.y?1:-1,y=i.x>r.x?1:-1;n=new m(r.x+y*f,r.y);const P={p0:s,p1:new m(r.x,r.y-g*f),arcDraw:{a:r,b:n,r:u}};e.push(P)}}return e}borderContains(t,e,n){return null}getConnectAnchor(){return[]}}class Fe{constructor(t,e,n){p(this,"paragraphIndex");p(this,"lineIndex");p(this,"charIndex");this.paragraphIndex=t,this.lineIndex=e,this.charIndex=n}static head(){return new Fe(0,0,-1)}clone(){return new Fe(this.paragraphIndex,this.lineIndex,this.charIndex)}equal(t){return this.paragraphIndex===t.paragraphIndex&&this.lineIndex===t.lineIndex&&this.charIndex===t.charIndex}greaterThan(t){return this.paragraphIndex>t.paragraphIndex?!0:this.paragraphIndex<t.paragraphIndex?!1:this.lineIndex>t.lineIndex?!0:this.lineIndex<t.lineIndex?!1:this.charIndex>t.charIndex?!0:!(this.charIndex<t.charIndex)}}class Cs{constructor(){p(this,"lines",[]);p(this,"index",0);p(this,"x",0);p(this,"y",0);p(this,"width",0);p(this,"height",0);p(this,"paragraphStyle",null)}addLine(t){t.y=this.height,t.index=this.lines.length,this.lines.push(t),this.width=Math.max(t.width,this.width),this.height=this.height+t.height}contains(t){return M.rectContains2(t,{minX:this.x,maxX:this.x+this.width,minY:this.y,maxY:this.y+this.height})}headCursorPosition(){return new Fe(this.index,0,-1)}tailCursorPosition(){if(this.lines.length===0)return new Fe(this.index,-1,-1);const t=this.lines.length-1,n=this.lines[t].getCharLength();return n===0?new Fe(this.index,t,-1):new Fe(this.index,t,n-1)}detect(t){const{x:e,y:n}=t;if(n<0||n>this.height||this.lines.length===0)return null;for(let o=0;o<this.lines.length;o++){const s=this.lines[o];if(n>=s.y&&n<s.y+s.height){const r=new m(t.x-s.x,t.y-s.y),i=s.detect(r);return{lineIndex:s.index,charIndex:i}}}return null}getLine(t){return t<0||this.lines.length===0?null:t>this.lines.length-1?(console.warn("index 超出该段最大数目,fall back处理"),this.lines[this.lines.length-1]):this.lines[t]}draw(t,e){for(const n of this.lines){const o=new m(e.x+this.x,e.y+this.y);n.draw(t,o)}}alignHorizon(t,e){for(const n of this.lines)t===at.Bottom&&(n.x=e-n.width),t===at.Middle&&(n.x=.5*e-.5*n.width)}toString(){let t="";for(const e of this.lines)t+=e.toString();return t+`
|
|
4
4
|
`}toRichTextXML(t){let e="<p>";for(const n of this.lines)e+=n.toRichTextXML(t);return e+"</p>"}prevToRichTextXML(t,e){let n="";for(let o=0;o<t;o++){const s=this.lines[o];n+=s.toRichTextXML(e)}return n}nextToRichTextXML(t,e){let n="";for(let o=t+1;o<this.lines.length;o++){const s=this.lines[o];n+=s.toRichTextXML(e)}return n}}class Gn{constructor(){p(this,"textBlocks",[]);p(this,"index",0);p(this,"x",0);p(this,"y",0);p(this,"width",0);p(this,"height",0);p(this,"boxAscent",0)}contains(t){return M.rectContains2(t,{minX:this.x,maxX:this.x+this.width,minY:this.y,maxY:this.y+this.height})}getCharLength(){let t=0;return this.textBlocks.forEach(e=>t+=e.characters.length),t}detect(t){const{x:e,y:n}=t;if(n<0||e<0)return-1;const o=this.getCharLength();if(n>this.height||e>this.width)return o-1;if(o===0)return-1;let s=0;for(let r=0;r<this.textBlocks.length;r++){const i=this.textBlocks[r];for(let a=0;a<i.characters.length;a++){const c=i.characters[a],h=i.x+c.x+.5*c.width;if(e<h)return s-1;s++}}return o-1}addTextBlock(t){if(this.textBlocks.length>0){const e=this.textBlocks[this.textBlocks.length-1];if(e.fontSize===t.fontSize&&e.fontFamily===t.fontFamily&&e.fontColor===t.fontColor&&e.fontBgColor===t.fontBgColor&&e.bold===t.bold&&e.italic===t.italic&&e.underline===t.underline&&e.strikethrough===t.strikethrough){for(const n of t.characters)e.addCharacter(n);e.text+=t.text,this.width=this.width+t.width,this.height=Math.max(this.height,e.height),this.boxAscent=Math.max(e.height,this.boxAscent);return}}t.x=this.width,t.y=0,this.textBlocks.push(t),this.width=this.width+t.width,this.height=Math.max(this.height,t.height),this.boxAscent=Math.max(t.height,this.boxAscent)}getBlockIndex(t){const e=this.getCharLength();if(t<0||e===0)return this.textBlocks.length>0?{textBlock:this.textBlocks[0],charIndex:-1,blockIndex:0}:null;if(t>e-1){console.warn("index 超出该行最大字符数目,fall back处理");const o=this.textBlocks[this.textBlocks.length-1];return{textBlock:o,charIndex:o.characters.length-1,blockIndex:this.textBlocks.length-1}}let n=0;for(let o=0;o<this.textBlocks.length;o++){const s=this.textBlocks[o];if(t-n<s.characters.length)return{textBlock:s,charIndex:t-n,blockIndex:o};n+=s.characters.length}return null}getCharacter(t){const e=this.getCharLength();if(t<0||e===0)return null;if(t>e-1){console.warn("index 超出该行最大字符数目,fall back处理");const o=this.textBlocks[this.textBlocks.length-1];return{character:o.characters[o.characters.length-1],textBlock:o,charIndex:o.characters.length-1,blockIndex:this.textBlocks.length-1}}let n=0;for(let o=0;o<this.textBlocks.length;o++){const s=this.textBlocks[o];if(t-n<s.characters.length)return{character:s.characters[t-n],textBlock:s,charIndex:t-n,blockIndex:o};n+=s.characters.length}return null}draw(t,e){const n=e.x+this.x,o=e.y+this.y,s=new m(n,o);for(const r of this.textBlocks)r.draw(t,s,this.height)}toString(){let t="";for(const e of this.textBlocks)t+=e.toString();return t}toRichTextXML(t){let e="";for(const n of this.textBlocks)e+=n.toRichTextXML(t);return e}prevToRichTextXML(t,e){let n="";for(let o=0;o<t;o++){const s=this.textBlocks[o];n+=s.toRichTextXML(e)}return n}nextToRichTextXML(t,e){let n="";for(let o=t+1;o<this.textBlocks.length;o++){const s=this.textBlocks[o];n+=s.toRichTextXML(e)}return n}}class Pi{constructor(){p(this,"parser",new DOMParser)}parseBooleanAttribute(t){if(t!=null){if(typeof t=="boolean")return t;if(typeof t=="string"){const e=t.toLowerCase().trim();if(e==="true")return!0;if(e==="false")return!1}}}parse(t,e){const n=[],o=this.parseRichText(t);for(const s of o){const r=this.computeTextBlocks(s,e);n.push({textBlocks:r})}return n}escapeXmlText(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}preprocessXmlString(t){return t.replace(/>([^<>]+)</g,(e,n)=>{if(/[&<>"']/.test(n)){const o=[];let s=n.replace(/&(?:amp|lt|gt|quot|apos);/g,r=>(o.push(r),`__ENTITY_${o.length-1}__`));return s=this.escapeXmlText(s),s=s.replace(/__ENTITY_(\d+)__/g,(r,i)=>o[parseInt(i)]),`>${s}<`}return e})}parseRichText(t){if(!t)return[{textBlocks:[]}];const e=this.preprocessXmlString(t),n=this.parser.parseFromString(e,"text/xml"),o=n.querySelector("parsererror");if(o)return console.error("解析富文本样式失败:",o,t),[{textBlocks:[t]}];const s=[],r=n.documentElement;for(const i of r.childNodes){const a=this.flattenNodes(i);s.push({textBlocks:a})}return s}flattenNodes(t){const e=[];for(const n of t.childNodes)if(n.nodeType===Node.TEXT_NODE){const o=n.textContent;o&&e.push(o)}else if(n.nodeType===Node.ELEMENT_NODE){const o=n;if(o.tagName.toLowerCase()==="style"){const r=o.textContent||"",i={text:""};o.childNodes.length>0?i.text=this.flattenNodes(o):i.text=r;const a=o.getAttribute("color");a&&(i.fontColor=a);const c=o.getAttribute("bg-color");c&&(i.fontBgColor=c);const h=o.getAttribute("bold"),d=this.parseBooleanAttribute(h);d!==void 0&&(i.bold=d);const u=o.getAttribute("italic"),f=this.parseBooleanAttribute(u);f!==void 0&&(i.italic=f);const g=o.getAttribute("font-size");g&&(i.fontSize=parseFloat(g));const y=o.getAttribute("underline"),P=this.parseBooleanAttribute(y);P!==void 0&&(i.underline=P);const b=o.getAttribute("strikethrough"),w=this.parseBooleanAttribute(b);w!==void 0&&(i.strikethrough=w),e.push(i)}}return e}computeTextBlocks(t,e){const n=[];for(const o of t.textBlocks)this.makeupTextBlock(o,e,n);return n}makeupTextBlock(t,e,n){if(typeof t=="string"){n.push(this.makeupTextBlockOfText(t,e));return}const o=t.text;if(typeof o=="string"){n.push(this.makeupTextBlockOfCacheTextBlock(t,e));return}if(!(o instanceof Array))return;const s={...e,...this.computeTextProps(t,e)};for(const r of o)this.makeupTextBlock(r,s,n)}makeupTextBlockOfText(t,e){return{text:t,fontSize:e.fontSize,fontFamily:e.fontFamily,fontColor:e.fontColor,fontBgColor:e.fontBgColor,bold:e.bold,italic:e.italic,underline:e.underline,strikethrough:e.strikethrough}}makeupTextBlockOfCacheTextBlock(t,e){return{...this.computeTextProps(t,e),text:t.text}}computeTextProps(t,e){return{text:"",fontSize:t.fontSize!==void 0?t.fontSize:e.fontSize,fontFamily:t.fontFamily!==void 0?t.fontFamily:e.fontFamily,fontColor:t.fontColor!==void 0?t.fontColor:e.fontColor,fontBgColor:t.fontBgColor!==void 0?t.fontBgColor:e.fontBgColor,bold:t.bold!==void 0?t.bold:e.bold,italic:t.italic!==void 0?t.italic:e.italic,underline:t.underline!==void 0?t.underline:e.underline,strikethrough:t.strikethrough!==void 0?t.strikethrough:e.strikethrough}}}class As{constructor(t,e,n,o,s,r){p(this,"charText");p(this,"index",0);p(this,"x");p(this,"y");p(this,"width");p(this,"height");p(this,"boxAscent");this.charText=t,this.x=e,this.y=n,this.width=o,this.height=s,this.boxAscent=r}contains(t){return M.rectContains2(t,{minX:this.x,maxX:this.x+this.width,minY:this.y,maxY:this.y+this.height})}toString(){return this.charText}}class Ro{constructor(){p(this,"segmentWorker",new Intl.Segmenter("en",{granularity:"grapheme"}))}split(t){return Array.from(this.segmentWorker.segment(t)).map(n=>n.segment)}}const Eo=new Ro;class Yh{measureParagraphs(t,e){for(const n of e)this.measure(t,n)}measure(t,e){for(const n of e.textBlocks){const{fontSize:o,fontFamily:s,italic:r,bold:i,text:a}=n;t.font=M.calcFont(o,s,i,r);const c=Eo.split(a),h=[];for(const d of c){const{width:u,height:f,boxAscent:g}=M.measureText(t,d),y=new As(d,0,0,u,f,g);h.push(y)}n.characters=h}}}var ao=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ks(l){return l&&l.__esModule&&Object.prototype.hasOwnProperty.call(l,"default")?l.default:l}function Gh(l){if(l.__esModule)return l;var t=l.default;if(typeof t=="function"){var e=function n(){return this instanceof n?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};e.prototype=t.prototype}else e={};return Object.defineProperty(e,"__esModule",{value:!0}),Object.keys(l).forEach(function(n){var o=Object.getOwnPropertyDescriptor(l,n);Object.defineProperty(e,n,o.get?o:{enumerable:!0,get:function(){return l[n]}})}),e}var Ns=0,bi=-3;function co(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function Uh(l,t){this.source=l,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=t,this.destLen=0,this.ltree=new co,this.dtree=new co}var Mi=new co,Si=new co,Bs=new Uint8Array(30),Rs=new Uint16Array(30),vi=new Uint8Array(30),Ii=new Uint16Array(30),_h=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Ti=new co,Ut=new Uint8Array(320);function Li(l,t,e,n){var o,s;for(o=0;o<e;++o)l[o]=0;for(o=0;o<30-e;++o)l[o+e]=o/e|0;for(s=n,o=0;o<30;++o)t[o]=s,s+=1<<l[o]}function $h(l,t){var e;for(e=0;e<7;++e)l.table[e]=0;for(l.table[7]=24,l.table[8]=152,l.table[9]=112,e=0;e<24;++e)l.trans[e]=256+e;for(e=0;e<144;++e)l.trans[24+e]=e;for(e=0;e<8;++e)l.trans[168+e]=280+e;for(e=0;e<112;++e)l.trans[176+e]=144+e;for(e=0;e<5;++e)t.table[e]=0;for(t.table[5]=32,e=0;e<32;++e)t.trans[e]=e}var Ci=new Uint16Array(16);function Es(l,t,e,n){var o,s;for(o=0;o<16;++o)l.table[o]=0;for(o=0;o<n;++o)l.table[t[e+o]]++;for(l.table[0]=0,s=0,o=0;o<16;++o)Ci[o]=s,s+=l.table[o];for(o=0;o<n;++o)t[e+o]&&(l.trans[Ci[t[e+o]]++]=o)}function jh(l){l.bitcount--||(l.tag=l.source[l.sourceIndex++],l.bitcount=7);var t=l.tag&1;return l.tag>>>=1,t}function _t(l,t,e){if(!t)return e;for(;l.bitcount<24;)l.tag|=l.source[l.sourceIndex++]<<l.bitcount,l.bitcount+=8;var n=l.tag&65535>>>16-t;return l.tag>>>=t,l.bitcount-=t,n+e}function Hs(l,t){for(;l.bitcount<24;)l.tag|=l.source[l.sourceIndex++]<<l.bitcount,l.bitcount+=8;var e=0,n=0,o=0,s=l.tag;do n=2*n+(s&1),s>>>=1,++o,e+=t.table[o],n-=t.table[o];while(n>=0);return l.tag=s,l.bitcount-=o,t.trans[e+n]}function Vh(l,t,e){var n,o,s,r,i,a;for(n=_t(l,5,257),o=_t(l,5,1),s=_t(l,4,4),r=0;r<19;++r)Ut[r]=0;for(r=0;r<s;++r){var c=_t(l,3,0);Ut[_h[r]]=c}for(Es(Ti,Ut,0,19),i=0;i<n+o;){var h=Hs(l,Ti);switch(h){case 16:var d=Ut[i-1];for(a=_t(l,2,3);a;--a)Ut[i++]=d;break;case 17:for(a=_t(l,3,3);a;--a)Ut[i++]=0;break;case 18:for(a=_t(l,7,11);a;--a)Ut[i++]=0;break;default:Ut[i++]=h;break}}Es(t,Ut,0,n),Es(e,Ut,n,o)}function Ai(l,t,e){for(;;){var n=Hs(l,t);if(n===256)return Ns;if(n<256)l.dest[l.destLen++]=n;else{var o,s,r,i;for(n-=257,o=_t(l,Bs[n],Rs[n]),s=Hs(l,e),r=l.destLen-_t(l,vi[s],Ii[s]),i=r;i<r+o;++i)l.dest[l.destLen++]=l.dest[i]}}}function Kh(l){for(var t,e,n;l.bitcount>8;)l.sourceIndex--,l.bitcount-=8;if(t=l.source[l.sourceIndex+1],t=256*t+l.source[l.sourceIndex],e=l.source[l.sourceIndex+3],e=256*e+l.source[l.sourceIndex+2],t!==(~e&65535))return bi;for(l.sourceIndex+=4,n=t;n;--n)l.dest[l.destLen++]=l.source[l.sourceIndex++];return l.bitcount=0,Ns}function Qh(l,t){var e=new Uh(l,t),n,o,s;do{switch(n=jh(e),o=_t(e,2,0),o){case 0:s=Kh(e);break;case 1:s=Ai(e,Mi,Si);break;case 2:Vh(e,e.ltree,e.dtree),s=Ai(e,e.ltree,e.dtree);break;default:s=bi}if(s!==Ns)throw new Error("Data error")}while(!n);return e.destLen<e.dest.length?typeof e.dest.slice=="function"?e.dest.slice(0,e.destLen):e.dest.subarray(0,e.destLen):e.dest}$h(Mi,Si),Li(Bs,Rs,4,3),Li(vi,Ii,2,1),Bs[28]=0,Rs[28]=258;var Zh=Qh;const qh=new Uint8Array(new Uint32Array([305419896]).buffer)[0]===18,ki=(l,t,e)=>{let n=l[t];l[t]=l[e],l[e]=n},Jh=l=>{const t=l.length;for(let e=0;e<t;e+=4)ki(l,e,e+3),ki(l,e+1,e+2)};var ed={swap32LE:l=>{qh&&Jh(l)}};const Ni=Zh,{swap32LE:td}=ed,Ds=11,Ln=5,nd=Ds-Ln,od=65536>>Ds,sd=(1<<nd)-1,Ho=2,Os=(1<<Ln)-1,Bi=65536>>Ln,rd=1024>>Ln,id=Bi+rd+32,ad=1<<Ho;class cd{constructor(t){const e=typeof t.readUInt32BE=="function"&&typeof t.slice=="function";if(e||t instanceof Uint8Array){let n;if(e)this.highStart=t.readUInt32LE(0),this.errorValue=t.readUInt32LE(4),n=t.readUInt32LE(8),t=t.slice(12);else{const o=new DataView(t.buffer);this.highStart=o.getUint32(0,!0),this.errorValue=o.getUint32(4,!0),n=o.getUint32(8,!0),t=t.subarray(12)}t=Ni(t,new Uint8Array(n)),t=Ni(t,new Uint8Array(n)),td(t),this.data=new Uint32Array(t.buffer)}else({data:this.data,highStart:this.highStart,errorValue:this.errorValue}=t)}get(t){let e;return t<0||t>1114111?this.errorValue:t<55296||t>56319&&t<=65535?(e=(this.data[t>>Ln]<<Ho)+(t&Os),this.data[e]):t<=65535?(e=(this.data[Bi+(t-55296>>Ln)]<<Ho)+(t&Os),this.data[e]):t<this.highStart?(e=this.data[id-od+(t>>Ds)],e=this.data[e+(t>>Ln&sd)],e=(e<<Ho)+(t&Os),this.data[e]):this.data[this.data.length-ad]}}var ld=cd;const hd=ks(ld);var Ri={};(function(l){var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";(function(e){var n=typeof Uint8Array<"u"?Uint8Array:Array,o=43,s=47,r=48,i=97,a=65,c=45,h=95;function d(g){var y=g.charCodeAt(0);if(y===o||y===c)return 62;if(y===s||y===h)return 63;if(y<r)return-1;if(y<r+10)return y-r+26+26;if(y<a+26)return y-a;if(y<i+26)return y-i+26}function u(g){var y,P,b,w,L,B;if(g.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var H=g.length;L=g.charAt(H-2)==="="?2:g.charAt(H-1)==="="?1:0,B=new n(g.length*3/4-L),b=L>0?g.length-4:g.length;var E=0;function X($){B[E++]=$}for(y=0,P=0;y<b;y+=4,P+=3)w=d(g.charAt(y))<<18|d(g.charAt(y+1))<<12|d(g.charAt(y+2))<<6|d(g.charAt(y+3)),X((w&16711680)>>16),X((w&65280)>>8),X(w&255);return L===2?(w=d(g.charAt(y))<<2|d(g.charAt(y+1))>>4,X(w&255)):L===1&&(w=d(g.charAt(y))<<10|d(g.charAt(y+1))<<4|d(g.charAt(y+2))>>2,X(w>>8&255),X(w&255)),B}function f(g){var y,P=g.length%3,b="",w,L;function B(E){return t.charAt(E)}function H(E){return B(E>>18&63)+B(E>>12&63)+B(E>>6&63)+B(E&63)}for(y=0,L=g.length-P;y<L;y+=3)w=(g[y]<<16)+(g[y+1]<<8)+g[y+2],b+=H(w);switch(P){case 1:w=g[g.length-1],b+=B(w>>2),b+=B(w<<4&63),b+="==";break;case 2:w=(g[g.length-2]<<8)+g[g.length-1],b+=B(w>>10),b+=B(w>>4&63),b+=B(w<<2&63),b+="=";break}return b}e.toByteArray=u,e.fromByteArray=f})(l)})(Ri);const dd=ks(Ri);var Ei={};const ud=5,Hi=12,pd=13,fd=16,gd=17,yd=22,Di=28,Oi=31,xd=33,Do=34,wd=35,Xs=36,zs=37,Xi=38,md=39,Pd=40,lo=41,bd=42,x=0,S=1,Ee=2,zi=3,C=4,Md=[[C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,zi,C,C,C,C,C,C,C,C,C,C,C],[x,C,C,S,S,C,C,C,C,S,S,x,x,x,x,S,S,S,x,x,C,Ee,C,x,x,x,x,x,x,x,x,S,x],[x,C,C,S,S,C,C,C,C,S,S,S,S,S,x,S,S,S,x,x,C,Ee,C,x,x,x,x,x,x,x,x,S,x],[C,C,C,S,S,S,C,C,C,S,S,S,S,S,S,S,S,S,S,S,C,Ee,C,S,S,S,S,S,S,S,S,S,S],[S,C,C,S,S,S,C,C,C,S,S,S,S,S,S,S,S,S,S,S,C,Ee,C,S,S,S,S,S,S,S,S,S,S],[x,C,C,S,S,S,C,C,C,x,x,x,x,x,x,S,S,S,x,x,C,Ee,C,x,x,x,x,x,x,x,x,S,x],[x,C,C,S,S,S,C,C,C,x,x,x,x,x,x,S,S,S,x,x,C,Ee,C,x,x,x,x,x,x,x,x,S,x],[x,C,C,S,S,S,C,C,C,x,x,S,x,S,x,S,S,S,x,x,C,Ee,C,x,x,x,x,x,x,x,x,S,x],[x,C,C,S,S,S,C,C,C,x,x,S,S,S,x,S,S,S,x,x,C,Ee,C,x,x,x,x,x,x,x,x,S,x],[S,C,C,S,S,S,C,C,C,x,x,S,S,S,S,S,S,S,x,x,C,Ee,C,S,S,S,S,S,x,S,S,S,x],[S,C,C,S,S,S,C,C,C,x,x,S,S,S,x,S,S,S,x,x,C,Ee,C,x,x,x,x,x,x,x,x,S,x],[S,C,C,S,S,S,C,C,C,S,S,S,S,S,x,S,S,S,x,x,C,Ee,C,x,x,x,x,x,x,x,x,S,x],[S,C,C,S,S,S,C,C,C,S,S,S,S,S,x,S,S,S,x,x,C,Ee,C,x,x,x,x,x,x,x,x,S,x],[S,C,C,S,S,S,C,C,C,S,S,S,S,S,x,S,S,S,x,x,C,Ee,C,x,x,x,x,x,x,x,x,S,x],[x,C,C,S,S,S,C,C,C,x,S,x,x,x,x,S,S,S,x,x,C,Ee,C,x,x,x,x,x,x,x,x,S,x],[x,C,C,S,S,S,C,C,C,x,x,x,x,x,x,S,S,S,x,x,C,Ee,C,x,x,x,x,x,x,x,x,S,x],[x,C,C,S,x,S,C,C,C,x,x,S,x,x,x,S,S,S,x,x,C,Ee,C,x,x,x,x,x,x,x,x,S,x],[x,C,C,S,x,S,C,C,C,x,x,x,x,x,x,S,S,S,x,x,C,Ee,C,x,x,x,x,x,x,x,x,S,x],[S,C,C,S,S,S,C,C,C,S,S,S,S,S,S,S,S,S,S,S,C,Ee,C,S,S,S,S,S,S,S,S,S,x],[x,C,C,S,S,S,C,C,C,x,x,x,x,x,x,S,S,S,x,C,C,Ee,C,x,x,x,x,x,x,x,x,S,x],[x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,C,x,x,x,x,x,x,x,x,x,x,x,x],[S,C,C,S,S,S,C,C,C,S,S,S,S,S,x,S,S,S,x,x,C,Ee,C,x,x,x,x,x,x,x,x,S,x],[S,C,C,S,S,S,C,C,C,S,S,S,S,S,S,S,S,S,S,S,C,Ee,C,S,S,S,S,S,S,S,S,S,S],[x,C,C,S,S,S,C,C,C,x,S,x,x,x,x,S,S,S,x,x,C,Ee,C,x,x,x,S,S,x,x,x,S,x],[x,C,C,S,S,S,C,C,C,x,S,x,x,x,x,S,S,S,x,x,C,Ee,C,x,x,x,x,S,x,x,x,S,x],[x,C,C,S,S,S,C,C,C,x,S,x,x,x,x,S,S,S,x,x,C,Ee,C,S,S,S,S,x,x,x,x,S,x],[x,C,C,S,S,S,C,C,C,x,S,x,x,x,x,S,S,S,x,x,C,Ee,C,x,x,x,S,S,x,x,x,S,x],[x,C,C,S,S,S,C,C,C,x,S,x,x,x,x,S,S,S,x,x,C,Ee,C,x,x,x,x,S,x,x,x,S,x],[x,C,C,S,S,S,C,C,C,x,x,x,x,x,x,S,S,S,x,x,C,Ee,C,x,x,x,x,x,S,x,x,S,x],[x,C,C,S,S,S,C,C,C,x,S,x,x,x,x,S,S,S,x,x,C,Ee,C,x,x,x,x,x,x,x,S,S,x],[x,C,C,S,S,S,C,C,C,x,S,x,x,x,x,S,S,S,x,x,C,Ee,C,x,x,x,x,x,x,x,x,S,x],[S,C,C,S,S,S,C,C,C,S,S,S,S,S,x,S,S,S,x,x,C,Ee,C,x,x,x,x,x,x,x,x,S,x],[x,C,C,S,S,x,C,C,C,x,x,x,x,x,x,x,x,x,x,x,C,Ee,C,x,x,x,x,x,x,x,x,S,x]],Sd=dd.toByteArray("AAgOAAAAAAAQ4QAAAQ0P8vDtnQuMXUUZx+eyu7d7797d9m5bHoWltKVUlsjLWE0VJNigQoMVqkStEoNQQUl5GIo1KKmogEgqkKbBRki72lYabZMGKoGAjQRtJJDaCCIRiiigREBQS3z+xzOTnZ3O+3HOhd5NfpkzZx7fN9988zivu2M9hGwB28F94DnwEngd/Asc1EtIs9c/bIPDwCxwLDgezHcodyo4w5C+CCwBS8FnwSXgCnA1uFbI93XwbXAbWAfWgx+CzWAb+An4KfgFeAzsYWWfYuFz4CXwGvgb+Dfo6yNkEEwGh4CZYB44FpwI3g1OY+kfBItZOo2fB84Hy8DF4HJwNbiWpV8PVoO1LH4n2NRXyN+KcAd4kNVP9XsY4aPgcfAbsBfs6SniL4K/sPjfEf6HlanXCRkCw2BGvUh/keWfXS/CY+pFXs7x9XHmM94LTmWIeU2cgbxnS/k/B3kf86jDhU8L9V2E40vAFWAlWFUfb++NOL4F3C7JX4/4GiE+hvgWsF0oS7mXldspnN+F493gyXrh9xTav0cg3EvzgVfBG6wsmVSEkxBOBgdPGpd7JI6PnqRvJ68/xlbHof53gPeA94OzwLngk+ACsAwsByvASrAK3MB0Ws3CtQjvBJvAVrADPMDSHkb4CNijaccTwvnf4fiPEs8Lxy+D18A/QU8/xjgYBjPAbDAKTgYLwOngTHAO+EQ/8wuEF4EvsPiVCFf2+9tsFStzA8LVHuXXBsi6QyqzUYiPMR/7Mc7dAx7oL8bzw/3u/Bw8Bp4Az4AXwCtgHzsmDXP5fiF9iiVvly5d0sHngar16NKlS5cuXbp06fLmYlqHXrcd3ph4P0THUY3iXh49novju4S0tzfs5d+JPKewfAsRntZb3K9ZhOMlrO6lCC8An28U9+OuovcPcPxlVu5rCL/VmHh/iHIrzn3fIPu7SN8Axmg+8AOwEWwCm7tp3bRuWjetm5Y8bSu4B9zbKO6ZVsnORrVU3f4uXTqZ2H3sLoyx3eDXjfDndE9qyj6L838CfwVvgFpzYnof4oNgOhgBc8Fos9DrZIQLmtXPP1MmF6wGj4H+KXoWguvADkXaPil+YpuQy8Am8Ey7ODdtmJDF4HowBp4De6HDTNjhfHAHeBr0DBBy0kDxfPbcgSIusgrcWhtnJ8vL+TPix7UIOQtcBq4C28Cr4KRBnANbwSuDE+s50JgyNNFuXbp06XIgsXjIvPafjvXozKY+fVFz/z0LT1uCtKVSWbrOLWPnztG8e0Xfy7ol8XtZJi7WtG+5od2UFXQ/A12vUeS7jp27yVKHjdsU9lXB869TyNvAzt0lpP2oWbwLdjiO78bx/Sz+EMJHwK9Y/LcIfw+eZ3F67/Hl5vh9xX80J+rwX8SvRDhpgL17iPAQMHNArfPrqHPewLheI+AERV6efwV418B4nOZ/H+IfYHV8GOF5LJ3eAz0fx8sM9S0fUNud39O9CulfGZhY5huI3wzWgNvBelbHZoTbNPVpfYjKQpkHwUNgl0LWblbnk0LbbDxr0OMFpL3iqWdu9nWYPlVAWkXY39LnGdCkDbeqv1YNbfcMQ3t9oe8lzm6NH9N1ZB6Ln4BwfkJZJk7RyFnYKt6b/JDQXx9p5X+eFdqOjzM9P9MB/lUlFzr20aXIdzlY4dmn9F3YqtvoO76/2hp/D/xA5Zue88nNyL8GbFbs075X0tyUig3Qd2MCnf//HjnzpbsR3g9+1kHzzVjdnE71/qVBX9rGPUh/ysNWe1neFzvIDi5zAufV1sT0N0poR22wkFUfTOPfA4N2mbZ5fSrqOHSw+IbkSBbOGSzSRgf91/GTUWYBOB2cIZQ/G8cfBZ8CFwrnL8XxF8FKcA24jqXdiPA7Qr61OF7H4mMItwzuv2/YLth1ISt3Hzu3k4W7EH5JqPdRHD/O4k+z8A8IX5Lq3y7Z4nXE9xn6kX6vQ4bKfy+ok+hH+xf3hq9dnTTHhjKd2GmDuWA242iHMq4cC7A8kJ7i8o1+skSa7Jieo38HCWnoNjKFhdSFBxzpZ7QE6lI8N4S14aASZcryaV/WWHw66f6NHuCoxuQxmvM56GX9QMd8Q4D65ywGP+ZzRJuM+zQvx/MOS2VFeqQ4IXnH26zM9Xe6/E6D+4foAzzuajPZp8Qyw5ayZVDWuH0z0BtYRkeIDqH9KO9VbH1btd/lhNqCzvl8zeLnG0S/hnU6baHfpiuO6yy0rd+DHURo/zYF5H26j03rQsip2ndzz82u1z9N4VjWKWeb68Tedpt95HRVXp7H1R6p+/Wt4FPy/PpWwscOLRJ+PVWF/+W0iVyGzs18TIvXkOJ1Wxm66vSXz+vylenrZcj1ub439W+K8RNCGTJi2p/TJ1K23VaXr35tRpnzmjxequgfcfyk6B/TGBVlyedsNgpdd/h+W1U3P99QyFPNo1X3TwpM/WLTIWYfoBqXrv6iskHZ/RFr79R6hIyHBrH3f1nrUVnjP8SnZZ+rYtzr9Exld5MNbPNErusAPg+77u/eDOPftU9yj39TH7rezxd1LvsZQJlzkWlOirG/79zjMj/mtHUKu7vKy+3/LnXr9okyKedjX5/0He9iP/j63LwOQdarEVlfy8OO/Lqw023j6xcqmwxLiOd6heM2i9cV9LJy8jMJ23yQ+rpbfu7EQ/pXE8KYvUSqvVnb4XzZa6LrHMXHR+zcLvqWbm/Bn0/HzIs6fWPHoat8XfnDKmZGxRxeMbn2UqZ5Q94nmcZRbqqUXbZ8+lcjE+cPX11t814orvvAXNcG8vqj2vvk1MGn3anlj0bIT72v47bvE+Lc98T9b6r7AKn6j+8Duf7D0nnZx/j7Zjn0j9nbpSTndaLr9WNLivP+iN23xF7L+fqv6ZouFyb78jxVXvv5jJ9YUs9/sddO8h7KNg5jrhfaJGztT6G7KF+1d6yCmD5Kdb2fan60rSc552fZr3zeQ9DpnPp+Si5cx5Ktv2QfSzF/mMbWdOm46rFI4XstnU9xeqX4NKb7TKEdcr6pZOK3ID1k/LvFHkVczEuZLEDr499YqvqBym1aEHWgcvoYOtv0M91qQl5TfpO/in6rWx8OVpT1Wedkv3f5xom3T/xeR/6Gx6V86PWAOB4bBpqWdN+yTcVxjIyGRz/FrDGu6w/3d7kPm8StX8RyPu+uuvpNju/vTLJV37GpvoM0oZPnW87VLnL/5pDno1NoW1R6yedU6TyUv3u19a3KFnIbTLYz+ZCLP4T0tU1uivFgso0pnsJ/UtXvarNY28Xq5cvkBDrQP/E5ZaiuQwwfmTlsOiQRU1fMuqrDd/3ISSuwjOwXOfTyGUMpZIXq4GpLn3pUcdfzch2x7XO1u2uZHOPb1G6b3Xg9PH1IIWeEpJlPQtqos2EKW8b0u8rnuP1UeVLoXJb9be0uG9nnbchjU+XTszT5VeNBThPHnc5OKj1U9aj0GTHIVaGy1YhEWT4ixns00DT+XEzWn/7VAsIc63Cov3OdyhwjrnaqQqZvWKXdypRdlq+k8msZ031U+Rm4fA+3TtyeR9hwfW9G9yxDN0fZMN33F+9TE6md4hwoxumfaUzI9fN3PFT3xVV2msrQ3UsnChm6Nulk8TndpS28D3zX9tTIPsF/z7Am5OkTjm1tI1JZW74+4VgsZ0N3L1yXV3WeP5uR7TGHHdvC3JQlxybfpd22tDlk/2eofRK8TzrN/qnar/K/OUTth6I/+jAnEptNbPvFHP2gs40N3+dfMWtwqvVct7/wfd8gtQ7imifial9ZJ9/3IHLYU6eDj3+4PhsNhX+vwvcWLnu6kGfEMe8DuciPfUfGZB8X/7HJy/Gefe5n+VRGFd/wyP2ta7/LO4yh/sbLV/k9lev6kfO9Dt/5U67b1/6u/epqB1U9Me23jfHY9sscAg4tkbLl+e4/U36rJ9ddxfd6sg5vq5ice42Wpk/pb9FOJ36/W9tpv4kbC79nUbZceX8Zu6/qJ+P3WvhvA8v3reh7Jbn2d6rrNC7XNZTLma4Ba0JI9efX2uLzF5scG/w9UNU1ZxW+ymUfzELeTllXlQ1rUuhzjS5fp9c964iFBOqeSz63bU065nZKdU+mDEz3qHIjjifquw0pnb/raRtvrnsYcb46ihT3taoYz6brdNW9l6rWRnE/navdPn1XlR1km7hcz1WlH/elKuSOSvLLuE8U6m8uzwRdfcGl73VyTHuyMvzJ1Sa2cWDTP/Z63Kc94n2B1PYr24dz1JlyHLlcP+S4B6vD1c9EW4q2LWstCvUjeVy63k/LMYdUNd5D1xQfvVTzX1VjkMsUv88N8VH5fReVn/Fjn++/h6X6Q8a6b1/q3g/i/ewi0/Scs8zxXeV6mWIOUPlPzBgdFerW+bZrm2P18dnjuK6HunEp+rHvPMXbr+sHVb/lnL+pTP57jPw9Cvk3PW178JD9qChfzuvTf7Htl38L1QUf/VKu9SFjwWbTWPvFEvu7Uq76y7+31g6QlYPc669pbsm9Xur2LWI9Pu8ypfDXqm3A2z8s1FWGn4ntL9NfQu2oSlftX9uetvTtv7J8Ql4zxfXGZ3zk8PeQ9w59x2uMfqI8/q5eKh/l9cb2rwsu9rSNl06ZP2Pmxtz+rNMx93yno0n2/82rVH7rQ+y9P15H6FyRun9ViH81ATmffI7nJ5r8uXXW6enbP6b/B8/l5OifVHYLnb9S39s2zcc+Ph+rh8+eQgVPS72elzGWY/tUtbbabBpDiI7yN1q6/4th2y+ErAc5+9BVvu/7KamJbWNZeuqI/R4tRf+YyD1HmOZM1bMV3/14Sn10c0Xu+Sj1nOXb5jL73ncdy02uvlXZNde65dOHYl7Vs4KYuS6FzWLn2zJlpZqPXPVPOa5yzKOyn1VhT9lmMfdbfH7D11Wf2PXN5h9y+dD287+qxgSnaYmnIrRtIb8pJe6/Uv9OVer6Whn0zfGO/BEloZI9ojmfAlUflClDd178bTmVHVTpZXOkAlk/lb42UujmI89HH5V+cl7XtowY6vTxLVWok6UrGzoGTHN+bB+6ri05687VNpvfuvRfaP2uMlNQth1D5JjGelm/8yn+9p3p/7qk9gnfeddXZmq/Sm333PJT659Kv1zjNbZ9uv2Oi//67CV8/N1nj1DmviyXDNVeJkaeaX8UsyesYg8cu2+NvdaPfb+lLDu5tvt/"),vd=new hd(Sd),Wi=function(l){switch(l){case xd:return Hi;case md:case Pd:case bd:return Hi;case wd:return ud;default:return l}},Fi=function(l){switch(l){case zs:case Xi:return Do;case lo:return yd;default:return l}};class Ws{constructor(t,e=!1){this.position=t,this.required=e}}class Id{nextCodePoint(){const t=this.string.charCodeAt(this.pos++),e=this.string.charCodeAt(this.pos);return 55296<=t&&t<=56319&&56320<=e&&e<=57343?(this.pos++,(t-55296)*1024+(e-56320)+65536):t}nextCharClass(){return Wi(vd.get(this.nextCodePoint()))}getSimpleBreak(){switch(this.nextClass){case lo:return!1;case Do:case zs:case Xi:return this.curClass=Do,!1;case Xs:return this.curClass=Xs,!1}return null}getPairTableBreak(t){let e=!1;switch(Md[this.curClass][this.nextClass]){case x:e=!0;break;case S:e=t===lo;break;case Ee:if(e=t===lo,!e)return e=!1,e;break;case zi:if(t!==lo)return e;break}return this.LB8a&&(e=!1),this.LB21a&&(this.curClass===fd||this.curClass===gd)?(e=!1,this.LB21a=!1):this.LB21a=this.curClass===pd,this.curClass===Di?(this.LB30a++,this.LB30a==2&&this.nextClass===Di&&(e=!0,this.LB30a=0)):this.LB30a=0,this.curClass=this.nextClass,e}nextBreak(){if(this.curClass==null){let t=this.nextCharClass();this.curClass=Fi(t),this.nextClass=t,this.LB8a=t===Oi,this.LB30a=0}for(;this.pos<this.string.length;){this.lastPos=this.pos;const t=this.nextClass;if(this.nextClass=this.nextCharClass(),this.curClass===Do||this.curClass===Xs&&this.nextClass!==zs)return this.curClass=Fi(Wi(this.nextClass)),new Ws(this.lastPos,!0);let e=this.getSimpleBreak();if(e===null&&(e=this.getPairTableBreak(t)),this.LB8a=this.nextClass===Oi,e)return new Ws(this.lastPos)}return this.lastPos<this.string.length?(this.lastPos=this.string.length,new Ws(this.string.length)):null}constructor(t){this.string=t,this.pos=0,this.lastPos=0,this.curClass=null,this.nextClass=null,this.LB8a=!1,this.LB21a=!1,this.LB30a=0}}Ei=Id;class Td{split(t){const e=new Ei(t);let n=0,o;const s=[];for(;o=e.nextBreak();){const r=t.slice(n,o.position);s.push(r),o.required,n=o.position}return s}}const Yi=new Td;class dn{constructor(){p(this,"text");p(this,"characters",[]);p(this,"fontSize");p(this,"fontFamily");p(this,"fontColor");p(this,"fontBgColor");p(this,"bold");p(this,"italic");p(this,"underline");p(this,"strikethrough");p(this,"x",0);p(this,"y",0);p(this,"width",0);p(this,"height",0);this.text="",this.characters=[],this.fontSize=14,this.fontFamily="Noto Sans",this.fontColor="#000000",this.fontBgColor="",this.bold=!1,this.italic=!1,this.underline=!1,this.strikethrough=!1}static create(t){const e=new dn;e.fontSize=t.fontSize,e.fontFamily=t.fontFamily,e.fontColor=t.fontColor,e.fontBgColor=t.fontBgColor,e.bold=t.bold,e.italic=t.italic,e.underline=t.underline,e.strikethrough=t.strikethrough;const n=t.characters||[];let o="";for(const s of n)e.addCharacter(s),o+=s.charText;return e.text=o,e}static createByStyleAndCharacter(t,e=[]){const n=new dn;n.fontSize=t.fontSize,n.fontFamily=t.fontFamily,n.fontColor=t.fontColor,n.fontBgColor=t.fontBgColor,n.bold=t.bold,n.italic=t.italic,n.underline=t.underline,n.strikethrough=t.strikethrough;let o="";for(const s of e)n.addCharacter(s),o+=s.charText;return n.text=o,n}addCharacter(t){t.x=this.width,t.index=this.characters.length,this.characters.push(t),this.width=this.width+t.width,this.height=Math.max(this.height,t.height)}draw(t,e,n){const{fontBgColor:o,underline:s,strikethrough:r,fontColor:i,fontSize:a,fontFamily:c,bold:h,italic:d}=this,u=e.x+this.x,f=e.y+this.y;if(o&&(t.save(),t.fillStyle=o,t.fillRect(u,f,this.width,n),t.restore()),t.save(),t.fillStyle=i,t.font=M.calcFont(a,c,h,d),t.textAlign="left",t.textBaseline="bottom",t.fillText(this.text,u,f+n),t.restore(),s){const g=.08333333333333333*a;t.strokeStyle=i,t.lineWidth=g,t.beginPath(),t.moveTo(u,f+n-g),t.lineTo(u+this.width,f+n-g),t.stroke()}r&&(t.strokeStyle=i,t.lineWidth=1/12*a,t.beginPath(),t.moveTo(u,f+n-.4*this.height),t.lineTo(u+this.width,f+n-.4*this.height),t.stroke())}computeLineBreakPoint(t){const e=Yi.split(this.text);let n=0;const o=[];for(let s=0;s<e.length-1;s++){const r=e[s],i=Eo.split(r);n+=i.length,o.push(n)}if(!t)o.push(this.characters.length);else{const s=Yi.split(this.text+t.text);let r=0;for(const i of s){const a=Eo.split(i);if(r+=a.length,r===this.characters.length)return o.push(this.characters.length),o;if(r>this.characters.length)return o}}return o}toString(){let t="";for(const e of this.characters)t+=e.toString();return t}toRichTextXML(t){return`<style ${this.computeStyle(t)}>${this.text}</style>`}computeStyle(t){let e="";return this.fontColor!==t.fontColor&&(e+=`color='${this.fontColor}' `),this.fontBgColor!==t.fontBgColor&&(e+=`bg-color='${this.fontBgColor}' `),this.fontSize!==t.fontSize&&(e+=`font-size='${this.fontSize}' `),this.bold!==t.bold&&(e+=`bold=${this.bold?"'true'":"'false'"} `),this.italic!==t.italic&&(e+=`italic=${this.italic?"'true'":"'false'"} `),this.underline!==t.underline&&(e+=`underline=${this.underline?"'true'":"'false'"} `),this.strikethrough!==t.strikethrough&&(e+=`strikethrough=${this.strikethrough?"'true'":"'false'"} `),e}getPrevText(t){let e="";for(let n=0;n<t+1;n++)e+=this.characters[n].charText;return e}getNextText(t){let e="";const n=Math.max(t+1,0);for(let o=n;o<this.characters.length;o++)e+=this.characters[o].charText;return e}insertTextToRichTextXML(t,e,n){const o=this.getPrevText(e)+t+this.getNextText(e);return`<style ${this.computeStyle(n)}>${o}</style>`}}class Ld{work(t,e,n){let o=[],s=n.line.width;for(const r of t.characters)if(s+r.width<e)o.push(r),s+=r.width;else{if(o.length>0){const i=dn.createByStyleAndCharacter(t,o);n.line.addTextBlock(i)}n.paragraph.addLine(n.line),o=[],n.line=new Gn,o.push(r),s=r.width}if(o.length>0){const r=dn.createByStyleAndCharacter(t,o);n.line.addTextBlock(r)}}}const Cd=new Ld;class ho{checkValid(t,e){const{paragraphIndex:n,lineIndex:o,charIndex:s}=e;if(n<0||o<0||s<-1||n>t.paragraphs.length-1)return console.warn("警告,光标位置异常,",e),null;const r=t.paragraphs[n];if(o>r.lines.length-1)return console.warn("警告,光标位置异常,",e),null;const i=r.lines[o],a=i.getCharLength();return s>a-1?(console.warn("警告,光标位置异常,",e),null):{paragraph:r,line:i}}moveRight(t,e){const{paragraphIndex:n,lineIndex:o,charIndex:s}=e,r=this.checkValid(t,e);if(!r)return e;const{paragraph:i,line:a}=r;if(e.equal(t.tailTextCursorPosition()))return e;const c=a.getCharLength();return o===i.lines.length-1&&s===c-1?new Fe(n+1,0,-1):s===c-1?new Fe(n,o+1,-1):new Fe(n,o,s+1)}moveLeft(t,e){const{paragraphIndex:n,lineIndex:o,charIndex:s}=e,r=this.checkValid(t,e);if(!r)return e;const{paragraph:i,line:a}=r;if(e.equal(t.headTextCursorPosition()))return e;if(o===0&&s===-1)return t.paragraphs[n-1].tailCursorPosition();if(s===-1){const h=i.lines[o-1].getCharLength();return h>0?new Fe(n,o-1,h-2):new Fe(n,o-1,-1)}return new Fe(n,o,s-1)}moveUp(t,e){const{paragraphIndex:n,lineIndex:o,charIndex:s}=e,r=this.checkValid(t,e);if(!r)return e;const{paragraph:i,line:a}=r;if(n===0&&o===0)return e;const{relativePos:c,height:h}=t.getPosByCursorPosition(e),d=new m(c.x,c.y-1);return t.detect(d)}moveDown(t,e){const{paragraphIndex:n,lineIndex:o,charIndex:s}=e,r=this.checkValid(t,e);if(!r)return e;const{paragraph:i}=r;if(n===t.paragraphs.length-1&&o===i.lines.length-1)return e;const{relativePos:a,height:c}=t.getPosByCursorPosition(e),h=new m(a.x,a.y+c+1);return t.detect(h)}}const Ad="pingfang",le=5,kd=2,Nd=5,Bd=50,Rd="main_text_id",Ed=14,Hd=10,Gi=8,Oo=2,Ui=.4;class Dd{computeStyle(t,e,n,o,s){if(!s){t.paragraphStyle=null;return}const r=this.firstLineHeight(t),i=this.computePrefixToken(s.orderIndex,s.level),a={level:s.level,orderIndex:s.orderIndex,paraIndex:s.paraIndex,width:n,lineHeight:r,prefixToken:i,color:o};t.paragraphStyle=a}computePrefixToken(t,e){switch(e%3){case 0:return t.toString();case 1:return this.numberToLetter(t);case 2:return this.numberToRoman(t);default:return t.toString()}}numberToLetter(t){if(t<1)return"a";const e=(t-1)%26+97;return String.fromCharCode(e)}numberToRoman(t){if(t<1)return"I";const e=[[1e3,"M"],[900,"CM"],[500,"D"],[400,"CD"],[100,"C"],[90,"XC"],[50,"L"],[40,"XL"],[10,"X"],[9,"IX"],[5,"V"],[4,"IV"],[1,"I"]];let n="",o=t;for(const[s,r]of e)for(;o>=s;)n+=r,o-=s;return n}computeParagraphX(t,e,n){let o=0;if(n&&(o+=Gi),!e)return o;const{level:s}=e;return o+(s+1)*t}computePrefixWidth(t,e){const{fontSize:n,fontFamily:o,bold:s,italic:r}=e;t.font=M.calcFont(n,o,s,r);const{width:i,height:a}=M.measureText(t,"aaa"),c=M.measureText(t,"aa");return{width:i,height:a,prefixWidth:c.width}}draw(t,e,n){if(!e.paragraphStyle)return;const o=e.paragraphStyle.width,s=e.paragraphStyle.lineHeight,r=this.firstLineX(e),i=n.x+e.x+r-o,a=n.y+e.y+s;if(e.paragraphStyle.orderIndex>=0){t.fillText(e.paragraphStyle.prefixToken+".",i,a);return}const c=e.paragraphStyle.color||"#000000";t.strokeStyle=c,t.lineWidth=1,t.beginPath();const h=e.paragraphStyle.level%3,d=.1*o;switch(h){case 1:t.arc(i+.5*o,a-.5*s+d,d,0,Math.PI*2),t.stroke();return;case 2:t.rect(i+.5*o,a-.5*s,2*d,2*d),t.fill(),t.stroke();return;case 0:default:t.arc(i+.5*o,a-.5*s+d,d,0,Math.PI*2),t.fill(),t.stroke();return}}firstLineHeight(t){if(t.lines.length===0)return 20;const e=t.lines[0];return e.height<.1?20:e.height}firstLineX(t){if(t.lines.length===0)return 0;const e=t.lines[0];return e.height<.1?0:e.x}}class Od{constructor(){p(this,"textQuoteInfo",null);p(this,"paraStyleMap",new Map)}reset(){this.textQuoteInfo=null,this.paraStyleMap.clear()}getQuoteStyle(t){return this.paraStyleMap.get(t)}work(t,e){t.paraQuoteStyles.forEach(s=>this.paraStyleMap.set(s.paraIndex,s));let n=null;const o=[];for(let s=0;s<e.paragraphs.length;s++){const r=e.paragraphs[s],i=this.paraStyleMap.get(s);i&&i.quote?n?n.y1=r.y+r.height:n={x:0,y0:r.y,y1:r.y+r.height}:n&&(o.push(n),n=null)}n&&o.push(n),o.length>0&&(this.textQuoteInfo={quoteLines:o})}draw(t,e){if(this.textQuoteInfo){t.lineWidth=Oo,t.strokeStyle="#8F959E",t.lineCap="round",t.globalAlpha=1,t.beginPath();for(const n of this.textQuoteInfo.quoteLines){const{x:o,y1:s,y0:r}=n;t.moveTo(e.x+o+Oo,e.y+r),t.lineTo(e.x+o+Oo,e.y+s)}t.stroke()}}}class uo{constructor(){p(this,"paragraphs",[]);p(this,"x",0);p(this,"y",0);p(this,"width",0);p(this,"height",0);p(this,"textProps",new Ge);p(this,"paragraphProps",new qt);p(this,"paragraphQuoteProps",new Dt);p(this,"rect",new D);p(this,"prefixDrawer",new Dd);p(this,"textBlockMeasureWorker",new Yh);p(this,"richTextHelper",new Pi);p(this,"cursorMoveWorker",new ho);p(this,"textQuoteLineWorker",new Od)}draw(t,e,n=1){t.save();for(let d=0;d<this.paragraphs.length;d++){const u=this.paragraphs[d],f=new m(e.x+this.x,e.y+this.y),g=this.textQuoteLineWorker.getQuoteStyle(d);g&&g.quote?t.globalAlpha=Ui*n:t.globalAlpha=n,u.draw(t,f)}const{fontSize:o,fontColor:s,fontFamily:r,bold:i,italic:a}=this.textProps,c=e.x+this.x,h=e.y+this.y;t.globalAlpha=n,t.textBaseline="bottom",t.textAlign="left",t.fillStyle=s,t.font=M.calcFont(o,r,i,a);for(const d of this.paragraphs)this.prefixDrawer.draw(t,d,{x:c,y:h});this.textQuoteLineWorker.draw(t,{x:c,y:h}),t.restore()}contains(t){return M.rectContains2(t,{minX:this.rect.x,maxX:this.rect.x+this.rect.width,minY:this.rect.y,maxY:this.rect.y+this.rect.height})}detect(t){let{x:e,y:n}=t;if(this.paragraphs.length===0)return new Fe(-1,-1,-1);if(n<this.y)return this.headTextCursorPosition();if(e<this.x)return this.headTextCursorPosition();if(n>this.y+this.height)return this.tailTextCursorPosition();if(e>this.x+this.rect.width)return this.tailTextCursorPosition();e=e-this.x,n=n-this.y;for(const o of this.paragraphs){const s=new m(e-o.x,n-o.y),r=o.detect(s);if(r)return new Fe(o.index,r.lineIndex,r.charIndex)}return this.tailTextCursorPosition()}headTextCursorPosition(){return Fe.head()}tailTextCursorPosition(){const t=this.paragraphs[this.paragraphs.length-1],e=t.lines[t.lines.length-1],n=e.getCharLength(),o=n===0?-1:n-1;return new Fe(t.index,e.index,o)}addParagraph(t){t.y=this.height,t.index=this.paragraphs.length,this.paragraphs.push(t),this.width=Math.max(t.x+t.width,this.width),this.height=this.height+t.height}getParagraph(t){return t<0||this.paragraphs.length===0?null:t>this.paragraphs.length-1?(console.warn("index 超出该文本最大段落数目,fall back处理"),this.paragraphs[this.paragraphs.length-1]):this.paragraphs[t]}getPosByCursorPosition(t){const e=this.textProps,n=new m(this.x,this.y),{charIndex:o,lineIndex:s,paragraphIndex:r}=t,i=this.getParagraph(r);if(i===null)return{relativePos:n,height:e.fontSize};n.x+=i.x,n.y+=i.y;const a=i.getLine(s);if(a===null)return{relativePos:n,height:e.fontSize};n.x+=a.x,n.y+=a.y;const c=a.getCharacter(o);if(c===null)return{relativePos:n,height:a.height};const{character:h,textBlock:d}=c;return n.x+=d.x+h.x+h.width,n.y+=h.y,{relativePos:n,height:a.height}}reset(){this.paragraphs=[],this.x=0,this.y=0,this.width=0,this.height=0,this.textQuoteLineWorker.reset()}computeParagraphMap(){const t=new Map;for(const e of this.paragraphProps.paragraphStyles)t.set(e.paraIndex,e);return t}computeParagraphQuoteMap(){const t=new Map;for(const e of this.paragraphQuoteProps.paraQuoteStyles)t.set(e.paraIndex,e);return t}typesetting(t,e=this.textProps,n,o=this.paragraphProps,s=this.paragraphQuoteProps){this.reset(),this.rect=n,this.x=0,this.y=0,this.textProps=e,this.paragraphProps=o,this.paragraphQuoteProps=s;const r=this.computeParagraphMap(),i=this.computeParagraphQuoteMap(),{sizeMode:a}=e,c=a===We.autoWidth,h=this.richTextHelper.parse(e.richText,e);this.textBlockMeasureWorker.measureParagraphs(t,h);const{width:d,prefixWidth:u}=this.prefixDrawer.computePrefixWidth(t,this.textProps);for(let f=0;f<h.length;f++){const g=h[f],y=r.get(f),P=i.get(f),b=this.prefixDrawer.computeParagraphX(d,y,P),w=this.typesettingParagraph(t,g,n.width-b,c);w.x=b,this.prefixDrawer.computeStyle(w,b,u,e.fontColor,y),this.addParagraph(w)}this.alignVertical(n),this.alignHorizon(n),this.textQuoteLineWorker.work(this.paragraphQuoteProps,this)}typesettingParagraph(t,e,n,o){if(e.textBlocks.length===0){const c=new Cs,h=new Gn,{fontSize:d,fontFamily:u,bold:f,italic:g}=this.textProps,{height:y}=M.measureTextByFont(t,"1",d,u,f,g);return h.height=y,c.addLine(h),c}const s=new Cs,r=new Gn,i={paragraph:s,line:r};for(let c=0;c<e.textBlocks.length;c++){const h=e.textBlocks[c],d=c===e.textBlocks.length-1?null:e.textBlocks[c+1],u=dn.create(h);if(u.characters.length===0){const{fontSize:f,fontFamily:g,bold:y,italic:P}=u,{height:b}=M.measureTextByFont(t,"1",f,g,y,P);u.height=b}this.lineAddTextBlock(u,d,n,o,i)}const a=i.paragraph.lines;return(a.length===0||i.line!==a[a.length-1])&&i.paragraph.addLine(i.line),s}lineAddTextBlock(t,e,n,o,s){if(o)s.line.addTextBlock(t);else if(s.line.width+t.width<n)s.line.addTextBlock(t);else{const r=t.computeLineBreakPoint(e),i=M.judgeLineBreak(r,t,s.line,n);if(r.length===0||i<0)s.line.textBlocks.length>0&&(s.paragraph.addLine(s.line),s.line=new Gn),Cd.work(t,n,s);else{const a=t.characters.slice(0,i),c=dn.createByStyleAndCharacter(t,a);s.line.addTextBlock(c),s.paragraph.addLine(s.line),s.line=new Gn;const h=t.characters.slice(i,t.characters.length),d=dn.createByStyleAndCharacter(t,h);this.lineAddTextBlock(d,e,n,o,s);return}}}alignVertical(t){const e=this.textProps.verticalAlign;if(e===at.Top){this.y=t.y;return}if(e===at.Bottom){this.y=t.y+t.height-this.height;return}if(e===at.Middle){this.y=t.y+.5*t.height-.5*this.height;return}}alignHorizon(t){this.x=this.rect.x;let e=this.textProps.horizonAlign;this.textProps.sizeMode===We.autoWidth&&(e=at.Top);for(const n of this.paragraphs)n.alignHorizon(e,t.width-n.x)}modifyPosInEditing(t,e){const n=new m;let o=!1;const{relativePos:s,height:r}=this.getPosByCursorPosition(e);return s.x<t.x&&(n.x=t.x-s.x,o=!0),s.x>t.x+t.width&&(n.x=-(s.x-(t.x+t.width)),o=!0),s.y<t.y&&(n.y=t.y-s.y,o=!0),s.y+r>t.y+t.height&&(n.y=-(s.y+r-(t.y+t.height)),o=!0),o&&(this.x+=n.x,this.y+=n.y),o}resetFromEditing(t){this.alignVertical(t),this.x=t.x}isEmptyText(){if(this.paragraphs.length!==1)return!1;const t=this.paragraphs[0];return t.lines.length===0||t.lines.length===1&&t.lines[0].toString()===""}toRichTextXML(){let t="<root>";for(const e of this.paragraphs)t+=e.toRichTextXML(this.textProps);return t+"</root>"}toString(){let t="";for(const e of this.paragraphs)t+=e.toString();return t}prevParagraphToXML(t){let e="";for(let n=0;n<t;n++)e+=this.paragraphs[n].toRichTextXML(this.textProps);return e}nextParagraphToXML(t){let e="";for(let n=t+1;n<this.paragraphs.length;n++)e+=this.paragraphs[n].toRichTextXML(this.textProps);return e}nextCursorPos(t,e){let n=t;for(let o=0;o<e;o++)n=this.cursorMoveWorker.moveRight(this,n);return n}prevCursorPos(t,e){let n=t;for(let o=0;o<e;o++)n=this.cursorMoveWorker.moveLeft(this,n);return n}getTextCursorPosByIndex(t){let e=-1;for(let n=0;n<this.paragraphs.length;n++){const o=this.paragraphs[n];for(let s=0;s<o.lines.length;s++){const i=o.lines[s].getCharLength();if(e===t)return new Fe(n,s,-1);for(let a=0;a<i;a++)if(e++,e===t)return new Fe(n,s,a)}n<this.paragraphs.length-1&&e++}return this.tailTextCursorPosition()}getIndexByTextCursorPos(t){const{paragraphIndex:e,lineIndex:n,charIndex:o}=t;if(e<0||e>=this.paragraphs.length)return-1;let s=0;for(let c=0;c<e;c++){const h=this.paragraphs[c];for(let d=0;d<h.lines.length;d++){const u=h.lines[d];s+=u.getCharLength()}s++}const r=this.paragraphs[e];if(n<0||n>=r.lines.length)return s-1;for(let c=0;c<n;c++){const h=r.lines[c];s+=h.getCharLength()}const i=r.lines[n];if(o===-1)return s-1;const a=i.getCharLength();return o>=a?s+a-1:s+o}}class _i{constructor(){p(this,"characters",[]);p(this,"width",0)}addCharacter(t){this.characters.push(t),this.width=this.width+t.width}}class Fs{handle(t,e){const n=this.layoutToPoints(t,e);return this.getUpdateNodeData(t.id,n)}getNodePos(t,{x:e,y:n}){const o=new m,{width:s,height:r}=t.baseProps;return o.x=e*s,o.y=n*r,t.toGlobal(o)}getUpdateNodeData(t,e){return{infos:[{id:t,props:[{type:I.Line,points:e}]}]}}}class Xo extends Fs{enable(t){return t.shapeType===de.Line}layoutToPoints(t,e){const{start:n,end:o}=t.connectProps,s=t.globalLinePoints;let r=s[0],i=s[s.length-1];if(n){const d=e.nodeManager.getNode(n.objectId);d&&(r=this.getNodePos(d,n))}if(o){const d=e.nodeManager.getNode(o.objectId);d&&(i=this.getNodePos(d,o))}const a=[r,i],c=t.globalTransform().inverseMatrix();return a.map(d=>c.crossPoint(d))}layoutToPointsPro(t,e){return[t.point,e.point]}}function Xd(l,t,e){return(t.x-l.x)*(e.y-l.y)-(t.y-l.y)*(e.x-l.x)}function zd(l){if(l.length!==4)return!1;const t=[];for(let e=0;e<4;e++){const n=l[e],o=l[(e+1)%4],s=l[(e+2)%4],r=Xd(n,o,s);if(r===0)return!1;t.push(Math.sign(r))}return t.every(e=>e===t[0])}class zo{splitCurve(t){const e=t.getHalfTPos();return this.computeCurveControlPoint(t.p0,e,t.p3)}computeCurvePointsForLine(t,e,n=t.points){const{start:o,end:s}=t.connectProps,r=this.computeConnectEndInfo(o,e),i=this.computeConnectEndInfo(s,e);return this.computeCurvePoints(n,r,i)}computeConnectEndInfo(t,e){let n;if(t){const o=this.computeEndType(t,e);o&&(n=this.computeEndDirection(o.endType,o.nodeAngle))}return n}computeEndDirection(t,e){let n=0;switch(t){case ue.Top:n=-.5*Math.PI;break;case ue.Left:n=Math.PI;break;case ue.Bottom:n=.5*Math.PI;break;default:case ue.Right:n=0;break}const o=e/180*Math.PI;n+=o;const s=Math.cos(n),r=Math.sin(n);return{direction:{x:s,y:r}}}computeEndType(t,e){if(t){const n=e.getNode(t.objectId);if(n)return{endType:M.computeNodeConnectEnd(t,0),nodeAngle:n.baseProps.angle}}return null}computeCurvePoints(t,e,n){const o=M.computeBezierCurvesByPoints(t),s=o[0],r=s.p0;let i=new m(r.x,r.y);if(e){const f=.4*M.distance(r,s.p3),g=Math.sqrt(e.direction.x*e.direction.x+e.direction.y*e.direction.y);i=new m(r.x+f*(e.direction.x/g),r.y+f*(e.direction.y/g))}const a=[r,i];for(let u=1;u<o.length;u++){const f=o[u],g=f.p0,y=f.p3,{lP:P,midPoint:b,rP:w}=this.computeCurveControlPoint(i,g,y);a.push(P,b,w),i=w}const c=o[o.length-1],h=c.p3;let d=new m(h.x,h.y);if(n){const f=.4*M.distance(h,c.p0),g=Math.sqrt(n.direction.x*n.direction.x+n.direction.y*n.direction.y);d=new m(h.x+f*(n.direction.x/g),h.y+f*(n.direction.y/g))}return a.push(d,h),a}computeCurveControlPoint(t,e,n){const o=M.distance(t,e),s=M.distance(e,n),r=M.lineAngle(e,t),i=M.lineAngle(e,n),a=r-i,c=i+.5*a,h=c+.5*Math.PI,d=c-.5*Math.PI,u=e.x+.4*o*Math.cos(h),f=e.y+.4*o*Math.sin(h),g=e.x+.4*s*Math.cos(d),y=e.y+.4*s*Math.sin(d),P=new m(u,f),b=new m(g,y);return zd([n,t,P,b])?{lP:P,midPoint:e,rP:b}:{lP:b,midPoint:e,rP:P}}}class po extends Fs{constructor(){super(...arguments);p(this,"bezierWorker",new zo)}enable(e){return e.shapeType===de.Curve}handle(e,n){const{start:o,end:s}=e.connectProps,r=[...e.globalLinePoints];let i=r[0],a=r[r.length-1];if(o){const u=n.nodeManager.getNode(o.objectId);u&&(i=this.getNodePos(u,o),r.splice(0,1,i))}if(s){const u=n.nodeManager.getNode(s.objectId);u&&(a=this.getNodePos(u,s),r.splice(r.length-1,1,a))}const c=this.bezierWorker.computeCurvePointsForLine(e,n.nodeManager,r),h=e.globalTransform().inverseMatrix(),d=c.map(u=>h.crossPoint(u));return this.getUpdateNodeData(e.id,d)}computeLinePoints(e,n){const o=[],s=new m(n.x-e.x,n.y-e.y);if(Math.abs(s.x)>Math.abs(s.y)){const r=new m(e.x+.5*s.x,e.y),i=new m(n.x-.5*s.x,n.y);o.push(e,r,i,n)}else{const r=new m(e.x,e.y+.5*s.y),i=new m(n.x,n.y-.5*s.y);o.push(e,r,i,n)}return o}layoutToPoints(e,n){const{start:o,end:s}=e.connectProps,r=e.points,i=r[0],a=r[r.length-1];return this.computeLinePoints(i,a)}layoutToPointsPro(e,n){return this.computeLinePoints(e.point,n.point)}}class fo{constructor(t){p(this,"startPoint");this.startPoint=t}}class R{static computeZLinePoints(t,e,n){if(n){const r=new m(t.x,.5*(t.y+e.y)),i=new m(e.x,.5*(t.y+e.y));return[t,r,i,e]}const o=new m(.5*(t.x+e.x),t.y),s=new m(.5*(t.x+e.x),e.y);return[t,o,s,e]}static computeLLinePoints(t,e,n){if(n){const s=new m(t.x,e.y);return[t,s,e]}const o=new m(e.x,t.y);return[t,o,e]}}class Wd extends fo{constructor(e,n){super(e);p(this,"rect");this.rect=n}bottom(e,n){const o=this.startPoint;if(e.y<o.y)return Math.abs(o.x-e.x)<.01?[o,e]:R.computeZLinePoints(o,e,!0);const s=new m(.5*(o.x+e.x),o.y-A);if(Math.abs(s.x-this.rect.x-.5*this.rect.width)<.5*this.rect.width||Math.abs(s.x-n.x-.5*n.width)<.5*n.width)if(o.x>e.x){const c=new m(Math.min(this.rect.x-A,n.x-A),Math.min(n.y-A,this.rect.y-A)),h=new m(e.x,Math.max(this.rect.y+this.rect.height+A,n.y+n.height+A)),d=R.computeLLinePoints(o,c,!0),u=R.computeLLinePoints(c,h,!0);return u.shift(),[...d,...u,e]}else{const c=new m(n.x+n.width+A,Math.min(n.y-A,this.rect.y-A)),h=new m(e.x,Math.max(this.rect.y+this.rect.height+A,n.y+n.height+A)),d=R.computeLLinePoints(o,c,!0),u=R.computeLLinePoints(c,h,!0);return u.shift(),[...d,...u,e]}const r=new m(e.x,e.y+A),i=R.computeLLinePoints(o,s,!0),a=R.computeLLinePoints(s,r,!0);return a.shift(),[...i,...a,e]}left(e,n){const o=this.startPoint;if(e.y<o.y&&e.x>o.x)return R.computeLLinePoints(o,e,!0);if(e.y<o.y){const a=new m(Math.min(this.rect.x-A,n.x-A),.5*(o.y+e.y));if(Math.abs(a.y-this.rect.y-.5*this.rect.height)<.5*this.rect.height||Math.abs(a.y-n.y-.5*n.height)<.5*n.height){const d=new m(Math.min(this.rect.x-A,n.x-A),Math.min(this.rect.y-A,n.y-A)),u=R.computeLLinePoints(o,d,!0),f=R.computeLLinePoints(d,e,!0);return f.shift(),[...u,...f]}const c=R.computeLLinePoints(o,a,!0),h=R.computeLLinePoints(a,e,!0);return h.shift(),[...c,...h]}if(e.x>this.rect.x+this.rect.width+A){const a=new m(.5*(this.rect.x+this.rect.width+n.x),this.rect.y-A),c=R.computeLLinePoints(o,a,!0),h=R.computeLLinePoints(a,e,!0);return h.shift(),[...c,...h]}const s=new m(Math.min(this.rect.x-A,n.x-A),this.rect.y-A),r=R.computeLLinePoints(o,s,!0),i=R.computeLLinePoints(s,e,!0);return i.shift(),[...r,...i]}right(e,n){const o=this.startPoint;if(e.y<o.y&&e.x<o.x)return R.computeLLinePoints(o,e,!0);if(e.y<o.y){const a=new m(Math.max(this.rect.x+this.rect.width+A,n.x+n.width+A),.5*(o.y+e.y));if(Math.abs(a.y-this.rect.y-.5*this.rect.height)<.5*this.rect.height||Math.abs(a.y-n.y-.5*n.height)<.5*n.height){const d=new m(Math.min(this.rect.x+this.rect.width+A,n.x+n.width+A),Math.min(this.rect.y-A,n.y-A)),u=R.computeLLinePoints(o,d,!0),f=R.computeLLinePoints(d,e,!0);return f.shift(),[...u,...f]}const c=R.computeLLinePoints(o,a,!0),h=R.computeLLinePoints(a,e,!0);return h.shift(),[...c,...h]}if(e.x<this.rect.x-A){const a=new m(.5*(this.rect.x+n.x),this.rect.y-A),c=R.computeLLinePoints(o,a,!0),h=R.computeLLinePoints(a,e,!0);return h.shift(),[...c,...h]}const s=new m(Math.min(this.rect.x+this.rect.width+A,n.x+n.width+A),this.rect.y-A),r=R.computeLLinePoints(o,s,!0),i=R.computeLLinePoints(s,e,!0);return i.shift(),[...r,...i]}top(e,n){const o=this.startPoint;if(e.y>this.rect.y+this.rect.height+A&&Math.abs(e.x-this.rect.x-.5*this.rect.width)<.5*this.rect.width){if(e.x>o.x){const d=new m(this.rect.x+this.rect.width+A,this.rect.y-A),u=new m(e.x,n.y-A),f=R.computeLLinePoints(o,d,!0),g=R.computeLLinePoints(d,u,!0);return g.shift(),[...f,...g,e]}const i=new m(this.rect.x-A,this.rect.y-A),a=new m(e.x,n.y-A),c=R.computeLLinePoints(o,i,!0),h=R.computeLLinePoints(i,a,!0);return h.shift(),[...c,...h,e]}if(n.y+n.height<this.rect.y){if(e.x>o.x){const d=new m(n.x-A,this.rect.y-A),u=new m(e.x,n.y-A),f=R.computeLLinePoints(o,d,!0),g=R.computeLLinePoints(d,u,!0);return g.shift(),[...f,...g,e]}const i=new m(n.x+n.width+A,this.rect.y-A),a=new m(e.x,n.y-A),c=R.computeLLinePoints(o,i,!0),h=R.computeLLinePoints(i,a,!0);return h.shift(),[...c,...h,e]}const s=new m(e.x,Math.min(this.rect.y-A,n.y-A));return[...R.computeLLinePoints(o,s,!0),e]}toPoint(e){if(M.rectContains(e,new D(this.rect.x-A,this.rect.y,2*A,this.rect.height))){const r=new m(this.rect.x-A,this.rect.y-A),i=R.computeLLinePoints(this.startPoint,r,!0),a=R.computeLLinePoints(r,e,!0);return a.shift(),[...i,...a]}if(M.rectContains(e,new D(this.rect.x+this.rect.width-A,this.rect.y,2*A,this.rect.height))){const r=new m(this.rect.x+this.rect.width+A,this.rect.y-A),i=R.computeLLinePoints(this.startPoint,r,!0),a=R.computeLLinePoints(r,e,!0);return a.shift(),[...i,...a]}if(M.rectContains(e,new D(this.rect.x,this.rect.y+this.rect.height-A,this.rect.width,2*A))){const r=new m(this.rect.x-A,this.rect.y-A),i=new m(e.x,this.rect.y+this.rect.height+A),a=R.computeLLinePoints(this.startPoint,r,!0),c=R.computeLLinePoints(r,i,!0);return c.shift(),[...a,...c,e]}if(M.rectContains(e,new D(this.rect.x,this.rect.y-A,this.rect.width,2*A))){const r=new m(e.x,this.rect.y-A);return[...R.computeLLinePoints(this.startPoint,r,!0),e]}if(e.y<this.startPoint.y)return R.computeZLinePoints(this.startPoint,e,!0);if(e.x<this.rect.x||e.x>this.rect.x+this.rect.width)return[...R.computeLLinePoints(this.startPoint,new m(e.x,this.rect.y-A),!0),e];if(e.x<this.rect.x+.5*this.rect.width){const r=new m(this.rect.x-A,this.rect.y-A),i=R.computeLLinePoints(this.startPoint,r,!0),a=R.computeLLinePoints(r,e,!0);return a.shift(),[...i,...a]}const n=new m(this.rect.x+this.rect.width+A,this.rect.y-A),o=R.computeLLinePoints(this.startPoint,n,!0),s=R.computeLLinePoints(n,e,!0);return s.shift(),[...o,...s]}}class $i extends fo{bottom(t,e){const n=this.startPoint;if(t.y<n.y)return R.computeZLinePoints(n,t,!0);if(M.inDistance(n.x,e.x,e.width))if(n.x<e.x+.5*e.width){const r=new m(e.x-A,e.y+e.height+A),i=R.computeLLinePoints(n,r,!1),a=R.computeLLinePoints(r,t,!1);return a.shift(),[...i,...a]}else{const r=new m(e.x+e.width+A,e.y+e.height+A),i=R.computeLLinePoints(n,r,!1),a=R.computeLLinePoints(r,t,!1);return a.shift(),[...i,...a]}const o=new m(t.x,e.y+e.height+A);return[...R.computeLLinePoints(n,o,!0),t]}left(t,e){const n=this.startPoint;if(t.x>n.x)return R.computeZLinePoints(n,t,!1);if(M.inDistance(n.y,e.y,e.height))if(n.y<e.y+.5*e.height){const r=new m(e.x-A,e.y-A),i=R.computeLLinePoints(n,r,!0),a=R.computeLLinePoints(r,t,!0);return a.shift(),[...i,...a]}else{const r=new m(e.x-A,e.y+e.height+A),i=R.computeLLinePoints(n,r,!0),a=R.computeLLinePoints(r,t,!0);return a.shift(),[...i,...a]}const o=new m(e.x-A,t.y);return[...R.computeLLinePoints(n,o,!1),t]}right(t,e){const n=this.startPoint;if(t.x<n.x)return R.computeZLinePoints(n,t,!1);if(M.inDistance(n.y,e.y,e.height))if(n.y<e.y+.5*e.height){const r=new m(e.x+e.width+A,e.y-A),i=R.computeLLinePoints(n,r,!0),a=R.computeLLinePoints(r,t,!0);return a.shift(),[...i,...a]}else{const r=new m(e.x+e.width+A,e.y+e.height+A),i=R.computeLLinePoints(n,r,!0),a=R.computeLLinePoints(r,t,!0);return a.shift(),[...i,...a]}const o=new m(e.x+e.width+A,t.y);return[...R.computeLLinePoints(n,o,!1),t]}toPoint(t){return M.computePolyLinePoints(this.startPoint,t)}top(t,e){const n=this.startPoint;if(t.y>n.y)return R.computeZLinePoints(n,t,!0);if(M.inDistance(n.x,e.x,e.width))if(n.x<e.x+.5*e.width){const r=new m(e.x-A,e.y-A),i=R.computeLLinePoints(n,r,!1),a=R.computeLLinePoints(r,t,!1);return a.shift(),[...i,...a]}else{const r=new m(e.x+e.width+A,e.y-A),i=R.computeLLinePoints(n,r,!1),a=R.computeLLinePoints(r,t,!1);return a.shift(),[...i,...a]}const o=new m(t.x,e.y-A);return[...R.computeLLinePoints(n,o,!0),t]}}class Fd extends fo{constructor(e,n){super(e);p(this,"rect");this.rect=n}bottom(e,n){const o=this.startPoint;if(e.y+A<this.rect.y&&M.inDistance(e.x,this.rect.x,this.rect.width))if(e.x>this.rect.x+.5*this.rect.width){const i=new m(this.rect.x+this.rect.width+A,this.rect.y+this.rect.height+A),a=new m(e.x,n.y+n.height+A),c=R.computeLLinePoints(o,i,!0),h=R.computeLLinePoints(i,a,!0);return h.shift(),[...c,...h,e]}else{const i=new m(this.rect.x-A,this.rect.y+this.rect.height+A),a=new m(e.x,n.y+n.height+A),c=R.computeLLinePoints(o,i,!0),h=R.computeLLinePoints(i,a,!0);return h.shift(),[...c,...h,e]}if(o.y+A<n.y&&M.inDistance(o.x,n.x,n.width)){if(o.x<n.x+.5*n.width){const d=new m(n.x-A,this.rect.y+this.rect.height+A),u=new m(e.x,n.y+n.height+A),f=R.computeLLinePoints(o,d,!0),g=R.computeLLinePoints(d,u,!0);return g.shift(),[...f,...g,e]}const i=new m(n.x+n.width+A,this.rect.y+this.rect.height+A),a=new m(e.x,n.y+n.height+A),c=R.computeLLinePoints(o,i,!0),h=R.computeLLinePoints(i,a,!0);return h.shift(),[...c,...h,e]}const s=new m(e.x,Math.max(n.y+n.height+A,this.rect.y+this.rect.height+A));return[...R.computeLLinePoints(o,s,!0),e]}left(e,n){const o=this.startPoint;if(e.x>o.x&&e.y>o.y)return R.computeLLinePoints(o,e,!0);if(e.x>this.rect.x+this.rect.width+A&&e.y<o.y){const a=new m(this.rect.x+this.rect.width+A,this.rect.y+this.rect.height+A),c=R.computeLLinePoints(o,a,!0),h=R.computeLLinePoints(a,e,!0);return h.shift(),[...c,...h]}if(e.x<this.rect.x+this.rect.width+A){const a=new m(Math.min(n.x-A,this.rect.x-A),Math.max(n.y+n.height+A,this.rect.y+this.rect.height+A)),c=R.computeLLinePoints(o,a,!0),h=R.computeLLinePoints(a,e,!0);return h.shift(),[...c,...h]}const s=new m(n.x-A,n.y-A),r=R.computeLLinePoints(o,s,!0),i=R.computeLLinePoints(s,e,!0);return i.shift(),[...r,...i]}right(e,n){const o=this.startPoint;if(e.x<o.x&&e.y>o.y)return R.computeLLinePoints(o,e,!0);if(n.x+n.width>this.rect.x-A){if(n.y<this.rect.y+this.rect.height+A){const a=new m(Math.max(n.x+n.width+A,this.rect.x+this.rect.width+A),Math.max(this.rect.y+this.rect.height+A,n.y+n.height+A)),c=R.computeLLinePoints(o,a,!0),h=R.computeLLinePoints(a,e,!0);return h.shift(),[...c,...h]}const s=new m(n.x+n.width+A,this.rect.y+this.rect.height+A),r=R.computeLLinePoints(o,s,!0),i=R.computeLLinePoints(s,e,!0);return i.shift(),[...r,...i]}if(e.y<this.rect.y+this.rect.height+A){const s=new m(this.rect.x-A,this.rect.y+this.rect.height+A),r=R.computeLLinePoints(o,s,!0),i=R.computeLLinePoints(s,e,!0);return i.shift(),[...r,...i]}return R.computeLLinePoints(o,e,!0)}toPoint(e){const n=this.startPoint;if(e.y>n.y)return R.computeZLinePoints(n,e,!0);if(M.inDistance(e.x,this.rect.x,this.rect.width))if(e.x<this.rect.x+.5*this.rect.width){const r=new m(this.rect.x-A,this.rect.y+this.rect.height+A),i=R.computeLLinePoints(n,r,!0),a=R.computeLLinePoints(r,e,!0);return a.shift(),[...i,...a]}else{const r=new m(this.rect.x+this.rect.width+A,this.rect.y+this.rect.height+A),i=R.computeLLinePoints(n,r,!0),a=R.computeLLinePoints(r,e,!0);return a.shift(),[...i,...a]}const o=new m(n.x,this.rect.y+this.rect.height+A),s=R.computeLLinePoints(o,e,!1);return[n,...s]}top(e,n){const o=this.startPoint;if(e.y>o.y)return R.computeZLinePoints(o,e,!0);if(n.x+n.width+A<this.rect.x){const c=new m(n.x+n.width+A,this.rect.y+this.rect.height+A),h=new m(e.x,n.y-A),d=R.computeLLinePoints(o,c,!0),u=R.computeLLinePoints(c,h,!0);return u.shift(),[...d,...u,e]}if(n.x+n.width<o.x){const c=new m(n.x+-A,this.rect.y+this.rect.height+A),h=new m(e.x,n.y-A),d=R.computeLLinePoints(o,c,!0),u=R.computeLLinePoints(c,h,!0);return u.shift(),[...d,...u,e]}if(n.x>this.rect.x+this.rect.width+A){const c=new m(n.x-A,this.rect.y+this.rect.height+A),h=new m(e.x,n.y-A),d=R.computeLLinePoints(o,c,!0),u=R.computeLLinePoints(c,h,!0);return u.shift(),[...d,...u,e]}const s=new m(Math.max(n.x+n.width+A,this.rect.x+this.rect.width+A),this.rect.y+this.rect.height+A),r=new m(e.x,n.y-A),i=R.computeLLinePoints(o,s,!0),a=R.computeLLinePoints(s,r,!0);return a.shift(),[...i,...a,e]}}class Yd extends fo{constructor(e,n){super(e);p(this,"rect");this.rect=n}bottom(e,n){const o=this.startPoint;if(e.y<o.y){if(e.x<o.x)return R.computeLLinePoints(o,e,!1);const a=new m(this.rect.x-A,n.y+n.height+A),c=R.computeLLinePoints(o,a,!1),h=R.computeLLinePoints(a,e,!1);return h.shift(),[...c,...h]}if(e.y>o.y&&e.x<o.x){const a=new m(this.rect.x-A,e.y+A),c=R.computeLLinePoints(o,a,!1),h=R.computeLLinePoints(a,e,!1);return h.shift(),[...c,...h]}const s=new m(this.rect.x-A,e.y+A),r=R.computeLLinePoints(o,s,!1),i=R.computeLLinePoints(s,e,!1);return i.shift(),[...r,...i]}left(e,n){const o=this.startPoint;if(e.y<this.rect.y){const i=new m(Math.min(this.rect.x-A,n.x-A),e.y);return[...R.computeLLinePoints(o,i,!1),e]}if(e.y>this.rect.y+this.rect.height){const i=new m(Math.min(this.rect.x-A,n.x-A),e.y);return[...R.computeLLinePoints(o,i,!1),e]}if(e.y<this.rect.y+this.rect.height&&e.x>this.rect.x+this.rect.width){const i=new m(this.rect.x-A,this.rect.y-A),a=new m(n.x-A,e.y),c=R.computeLLinePoints(o,i,!1),h=R.computeLLinePoints(i,a,!1);return h.shift(),[...c,...h,e]}const s=new m(Math.min(this.rect.x-A,n.x-A),e.y);return[...R.computeLLinePoints(o,s,!1),e]}right(e,n){const o=this.startPoint;if(e.x<o.x)return R.computeZLinePoints(o,e,!1);if(e.y<o.y){const c=new m(this.rect.x-A,n.y+n.height+A),h=new m(n.x+n.width+A,e.y),d=R.computeLLinePoints(o,c,!1),u=R.computeLLinePoints(c,h,!1);return u.shift(),[...d,...u,e]}const s=new m(this.rect.x-A,n.y-A),r=new m(n.x+n.width+A,e.y),i=R.computeLLinePoints(o,s,!1),a=R.computeLLinePoints(s,r,!1);return a.shift(),[...i,...a,e]}toPoint(e){const n=this.startPoint;if(e.x>n.x&&e.y<this.rect.y){const r=new m(this.rect.x-A,e.y);return[...R.computeLLinePoints(n,r,!1),e]}if(e.x>n.x&&e.y>this.rect.y&&e.y<n.y){const r=new m(this.rect.x-A,this.rect.y-A),i=R.computeLLinePoints(n,r,!1),a=R.computeLLinePoints(r,e,!1);return a.shift(),[...i,...a]}if(e.x>n.x&&e.y>n.y&&e.y<this.rect.y+this.rect.height){const r=new m(this.rect.x-A,this.rect.y+this.rect.height+A),i=R.computeLLinePoints(n,r,!1),a=R.computeLLinePoints(r,e,!1);return a.shift(),[...i,...a]}if(e.x<n.x)return R.computeZLinePoints(n,e,!1);const o=new m(this.rect.x-A,e.y);return[...R.computeLLinePoints(n,o,!1),e]}top(e,n){const o=this.startPoint;if(e.x>o.x&&e.y<this.rect.y+this.rect.height+A){const s=new m(this.rect.x-A,Math.min(this.rect.y-A,n.y-A)),r=R.computeLLinePoints(o,s,!1),i=R.computeLLinePoints(s,e,!1);return i.shift(),[...r,...i]}if(e.y<o.y+2&&e.x<o.x){const s=new m(this.rect.x-A,n.y-A),r=R.computeLLinePoints(o,s,!1),i=R.computeLLinePoints(s,e,!1);return i.shift(),[...r,...i]}if(e.x>o.x&&e.y>this.rect.y+this.rect.height+A){const s=new m(this.rect.x-A,this.rect.y+this.rect.height+A),r=R.computeLLinePoints(o,s,!1),i=R.computeLLinePoints(s,e,!1);return i.shift(),[...r,...i]}return R.computeLLinePoints(o,e,!1)}}class Gd extends fo{constructor(e,n){super(e);p(this,"rect");this.rect=n}bottom(e,n){const o=this.startPoint;if(e.x>o.x){if(e.y<o.y)return R.computeLLinePoints(o,e,!1);const a=new m(this.rect.x+this.rect.width+A,n.y+n.height+A),c=R.computeLLinePoints(o,a,!1),h=R.computeLLinePoints(a,e,!1);return h.shift(),[...c,...h]}if(e.y<this.rect.y){const a=new m(this.rect.x+this.rect.width+A,n.y+n.height+A),c=R.computeLLinePoints(o,a,!1),h=R.computeLLinePoints(a,e,!1);return h.shift(),[...c,...h]}const s=new m(this.rect.x+this.rect.width+A,Math.max(n.y+n.height+A,this.rect.y+this.rect.height+A)),r=R.computeLLinePoints(o,s,!1),i=R.computeLLinePoints(s,e,!1);return i.shift(),[...r,...i]}left(e,n){const o=this.startPoint;if(e.x>o.x)return R.computeZLinePoints(o,e,!1);if(e.y<this.rect.y){const c=new m(this.rect.x+this.rect.width+A,n.y+n.height+A),h=new m(n.x-A,e.y),d=R.computeLLinePoints(o,c,!1),u=R.computeLLinePoints(c,h,!1);return u.shift(),[...d,...u,e]}if(e.y>this.rect.y+this.rect.height){const c=new m(this.rect.x+this.rect.width+A,n.y-A),h=new m(n.x-A,e.y),d=R.computeLLinePoints(o,c,!1),u=R.computeLLinePoints(c,h,!1);return u.shift(),[...d,...u,e]}if(e.y<this.rect.y+.5*this.rect.height){const c=new m(this.rect.x+this.rect.width+A,Math.min(n.y-A,this.rect.y-A)),h=new m(n.x-A,e.y),d=R.computeLLinePoints(o,c,!1),u=R.computeLLinePoints(c,h,!1);return u.shift(),[...d,...u,e]}const s=new m(this.rect.x+this.rect.width+A,Math.max(n.y+n.height+A,this.rect.y+this.rect.height+A)),r=new m(n.x-A,e.y),i=R.computeLLinePoints(o,s,!1),a=R.computeLLinePoints(s,r,!1);return a.shift(),[...i,...a,e]}right(e,n){const o=this.startPoint;if(e.y<this.rect.y||e.y>this.rect.y+this.rect.height){const c=new m(Math.max(n.x+n.width+A,this.rect.x+this.rect.width+A),e.y);return[...R.computeLLinePoints(o,c,!1),e]}if(e.y<this.rect.y+.5*this.rect.height){const c=new m(this.rect.x+this.rect.width+A,this.rect.y-A),h=new m(n.x+n.width+A,e.y),d=R.computeLLinePoints(o,c,!1),u=R.computeLLinePoints(c,h,!1);return u.shift(),[...d,...u,e]}const s=new m(this.rect.x+this.rect.width+A,this.rect.y+this.rect.height+A),r=new m(n.x+n.width+A,e.y),i=R.computeLLinePoints(o,s,!1),a=R.computeLLinePoints(s,r,!1);return a.shift(),[...i,...a,e]}toPoint(e){const n=this.startPoint;if(e.x>n.x)return R.computeZLinePoints(n,e,!1);if(e.y<this.rect.y||e.y>this.rect.y+this.rect.height){const i=new m(this.rect.x+this.rect.width+A,e.y);return[...R.computeLLinePoints(n,i,!1),e]}if(e.y<this.rect.y+.5*this.rect.height){const i=new m(this.rect.x+this.rect.width+A,this.rect.y-A),a=R.computeLLinePoints(n,i,!1),c=R.computeLLinePoints(i,e,!1);return c.shift(),[...a,...c]}const o=new m(this.rect.x+this.rect.width+A,this.rect.y+this.rect.height+A),s=R.computeLLinePoints(n,o,!1),r=R.computeLLinePoints(o,e,!1);return r.shift(),[...s,...r]}top(e,n){const o=this.startPoint;if(e.y>o.y&&e.x>o.x)return R.computeLLinePoints(o,e,!1);if(e.y>this.rect.y+this.rect.height){const a=new m(this.rect.x+this.rect.width+A,this.rect.y+this.rect.height+A),c=R.computeLLinePoints(o,a,!1),h=R.computeLLinePoints(a,e,!1);return h.shift(),[...c,...h]}if(n.x<this.rect.x+this.rect.width+A){const a=new m(Math.max(this.rect.x+this.rect.width+A,n.x+n.width+A),Math.min(n.y-A,this.rect.y-A)),c=R.computeLLinePoints(o,a,!1),h=R.computeLLinePoints(a,e,!1);return h.shift(),[...c,...h]}const s=new m(this.rect.x+this.rect.width+A,n.y-A),r=R.computeLLinePoints(o,s,!1),i=R.computeLLinePoints(s,e,!1);return i.shift(),[...r,...i]}}class Ze{static mockPointermoveEvent(t,e){return{pointerId:1,width:1,height:1,pressure:.5,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,type:"pointermove",pointerType:"mouse",isPrimary:!0,bubbles:!0,cancelable:!0,composed:!0,clientX:t.x,clientY:t.y,...e}}static getNodePos(t,{x:e,y:n}){const o=new m,{width:s,height:r}=t.baseProps;return o.x=e*s,o.y=n*r,t.toGlobal(o)}static computeConnectInfo(t,e,n,o=!1){const s=t.globalLinePoints,r={point:o?s[s.length-1]:s[0]};if(e){const i=n.nodeManager.getNode(e.objectId);i&&(r.nodeConnect={rect:D.rectNode2Rect(i.getBounds()),endType:M.computeNodeConnectEnd(e,i.baseProps.angle)},r.point=this.getNodePos(i,e))}return r}static computeLinePoints(t,e,n,o,s){const r=o.detect(F.NodeEdge,n),i=!M.pressMeta(n),c={point:s.alignLineEndAndDrawAlignLines(n,o,o.getSelectNodes(),i)};return r&&(c.point=new m(r.point.x,r.point.y),c.nodeConnect={rect:D.rectNode2Rect(r.node.getBounds()),endType:M.computeNodeConnectEnd(r.relativePos,r.node.baseProps.angle)}),e.layoutToPointsPro(t,c)}static trimAngle(t){const e=Math.floor(t/360);return t-e*360}static calculateAngle(t,e){return Math.abs(t.x-e.x)<.01?e.y>t.y?90:-90:Math.atan2(e.y-t.y,e.x-t.x)/Math.PI*180}static calculateAngle2(t,e){return Math.abs(t.x-e.x)<.01?e.y>t.y?.5*Math.PI:-.5*Math.PI:Math.atan2(e.y-t.y,e.x-t.x)}static trimPoint(t){return new m(Math.floor(t.x),Math.floor(t.y))}static overlapHorizonVertical(t,e,n){if(Ze.judgeHorizon(t,e)){if(t.y<n.minY||t.y>n.maxY)return!1;const s=t.x>e.x?e.x:t.x,r=t.x<e.x?e.x:t.x;if(s>n.maxX||r<n.minX)return!1}else{if(t.x<n.minX||t.x>n.maxX)return!1;const s=t.y>e.y?e.y:t.y,r=t.y<e.y?e.y:t.y;if(s>n.maxY||r<n.minY)return!1}return!0}static overlapHorizon(t,e,n,o,s){const r=o.y>s.y?s.y:o.y,i=o.y<s.y?s.y:o.y;if(r>n||i<n)return!1;const a=o.x>s.x?s.x:o.x,c=o.x<s.x?s.x:o.x;return!(a>e||c<t)}static overlapVertical(t,e,n,o,s){const r=o.x>s.x?s.x:o.x,i=o.x<s.x?s.x:o.x;if(r>n||i<n)return!1;const a=o.y>s.y?s.y:o.y,c=o.y<s.y?s.y:o.y;return!(a>e||c<t)}static overlapSimpleLine(t,e,n){if(this.overlapHorizon(n.minX,n.maxX,n.minY,t,e)||this.overlapHorizon(n.minX,n.maxX,n.maxY,t,e)||this.overlapVertical(n.minY,n.maxY,n.maxX,t,e)||this.overlapVertical(n.minY,n.maxY,n.minX,t,e))return!0;const o=t.x>e.x?e.x:t.x,s=t.x<e.x?e.x:t.x,r=t.y>e.y?e.y:t.y,i=t.y<e.y?e.y:t.y;return s<=n.maxX&&o>=n.minX&&i<=n.maxY&&r>=n.minY}static overlapPolyLine(t,e){for(let n=0;n<t.length-1;n++){const o=t[n],s=t[n+1];if(this.overlapHorizonVertical(o,s,e))return!0}return!1}static interactRect(t,e){return{minX:Math.max(t.minX,e.minX),maxX:Math.min(t.maxX,e.maxX),minY:Math.max(t.minY,e.minY),maxY:Math.min(t.maxY,e.maxY)}}static needDrawByDelete(t,e,n,o,s){const r=t.nodeManager.tree.search(e),i=new Set;for(const c of r){const h=t.nodeManager.nodeMap.get(c.id);h&&i.add(h)}s||i.add(o);const a=[...i];return a.sort((c,h)=>c.zIndex-h.zIndex),a}static layout(t,e){const n=[];return M.doubleMiddleInsertPoint(t,e,n),n}static judgeHorizon(t,e,n=.01){return Math.abs(t.y-e.y)<n}static judgeVertical(t,e,n=.01){return Math.abs(t.x-e.x)<n}static getOfflineCanvas(t,e,n){const o=D.rectNode2Rect(t),s=document.createElement("canvas");s.width=n*o.width,s.height=n*o.height;const r=s.getContext("2d");r.scale(n,n),r.translate(-o.x,-o.y);const i=e.searchNodesByRectNode(t);for(const a of i)a.drawOnGLCtx(r);return s}}class ji{constructor(t){p(this,"modes",[]);p(this,"currentMode");this.modes=t.modes,this.currentMode=t.modes[t.modes.length-1]}onEvent(t,e){this.reset(t,e);const n=this.convertInteractiveEvent(t,e);this.detect(n,e),this.currentMode.work(n,e),this.afterOnEvent(n,e)}refreshEvent(t,e){const n=t.lastInteractiveEvent.originEvent,o=new m(n.clientX,n.clientY),s=Ze.mockPointermoveEvent(o,e);s.target=t.gmlRender.canvas,this.onEvent(s,t)}detect(t,e){if(this.currentMode.canBeExit(t,e)){for(const n of this.modes)if(n.canBeEnable(t,e)){this.currentMode=n;return}}}reset(t,e){var n;e.reset();for(const[o,s]of e.detectors)s.reset();t.type!==((n=e.lastInteractiveEvent)==null?void 0:n.type)&&(e.lastDiffTypeEvent=e.lastInteractiveEvent)}afterOnEvent(t,e){this.record(t,e)}record(t,e){e.lastInteractiveEvent=t}convertInteractiveEvent(t,e){const n=e.gmlRender.canvas.getBoundingClientRect(),o=new m(t.clientX-n.x,t.clientY-n.y),s=e.gmlRender.transformToGlobal(o);return{clientPoint:new m(t.clientX,t.clientY),globalPoint:s,type:this.convertEventType(t,e),originEvent:t}}convertEventType(t,e){const n=t.type;return n==="pointerdown"?be.pointerDown:n==="pointermove"?t.target!=e.gmlRender.canvas?be.pointermoveOutside:be.pointermove:n==="pointerup"?be.pointerup:be.unknown}}class Ud{constructor(){p(this,"isWorking",!1);p(this,"initialTouchInfo",null);p(this,"lastTouchInfo",null);p(this,"SCALE_THRESHOLD",10);p(this,"MOVE_THRESHOLD",5)}enable(t){return t.touches.length===2}start(t,e){this.enable(t)&&(this.isWorking=!0,this.initialTouchInfo=this.getTouchInfo(t),this.lastTouchInfo=this.initialTouchInfo)}move(t,e){if(!this.isWorking||!this.lastTouchInfo)return;const n=this.getTouchInfo(t),o=e.renderManager.gmlRender.transformToGlobal(this.lastTouchInfo.centerPoint),s=n.distance/this.lastTouchInfo.distance;this.handleZoom(s,o,e);const r=n.centerPoint.x-this.lastTouchInfo.centerPoint.x,i=n.centerPoint.y-this.lastTouchInfo.centerPoint.y;this.handleScroll(r,i,e),this.lastTouchInfo=n}stop(t,e){this.isWorking=!1,this.initialTouchInfo=null,this.lastTouchInfo=null}getTouchInfo(t){const e=new m(t.touches[0].clientX,t.touches[0].clientY),n=new m(t.touches[1].clientX,t.touches[1].clientY),o=new m((e.x+n.x)/2,(e.y+n.y)/2),s=n.x-e.x,r=n.y-e.y,i=Math.sqrt(s*s+r*r);return{centerPoint:o,distance:i,touch1:e,touch2:n}}handleZoom(t,e,n){n.renderManager.zoomScale(t,e)}handleScroll(t,e,n){n.renderManager.scroll(-t,-e)}}class Wo{constructor(t,e){p(this,"eventCtx");p(this,"interactiveManager");p(this,"touchScrollZoomWorker");p(this,"onContextMenu",t=>{t.preventDefault()});p(this,"onTouchStart",t=>{if(this.touchScrollZoomWorker.enable(t)){t.preventDefault(),t.stopPropagation(),this.touchScrollZoomWorker.start(t,this.eventCtx);return}});p(this,"onTouchMove",t=>{if(this.touchScrollZoomWorker.isWorking){t.preventDefault(),t.stopPropagation(),this.touchScrollZoomWorker.move(t,this.eventCtx);return}t.preventDefault()});p(this,"onTouchEnd",t=>{if(this.touchScrollZoomWorker.isWorking){t.preventDefault(),t.stopPropagation(),this.touchScrollZoomWorker.stop(t,this.eventCtx);return}});p(this,"onPointerDown",t=>{this.touchScrollZoomWorker.isWorking||this.triggerEvent(t)});p(this,"onPointerMove",t=>{this.touchScrollZoomWorker.isWorking||this.triggerEvent(t)});p(this,"onPointerUp",t=>{this.touchScrollZoomWorker.isWorking||this.triggerEvent(t)});this.eventCtx=t,this.interactiveManager=new ji(e),this.touchScrollZoomWorker=new Ud}start(){document.addEventListener("pointerdown",this.onPointerDown),document.addEventListener("pointermove",this.onPointerMove),document.addEventListener("pointerup",this.onPointerUp),document.addEventListener("contextmenu",this.onContextMenu);const t=this.eventCtx.renderManager.gmlRender.canvas;t&&(t.addEventListener("touchstart",this.onTouchStart),t.addEventListener("touchmove",this.onTouchMove),t.addEventListener("touchend",this.onTouchEnd))}stop(){document.removeEventListener("pointerdown",this.onPointerDown),document.removeEventListener("pointermove",this.onPointerMove),document.removeEventListener("pointerup",this.onPointerUp),document.removeEventListener("contextmenu",this.onContextMenu);const t=this.eventCtx.renderManager.gmlRender.canvas;t&&(t.removeEventListener("touchstart",this.onTouchStart),t.removeEventListener("touchmove",this.onTouchMove),t.removeEventListener("touchend",this.onTouchEnd))}triggerEvent(t){this.onEnable(t)&&(this.interactiveManager.onEvent(t,this.eventCtx),this.afterEvent())}onEnable(t){return t.type!=="pointermove"&&t.target!==this.eventCtx.gmlRender.canvas?(this.eventCtx.inputManager.blur(),!1):!0}afterEvent(){}}const Ys=8,Gs=8,Us=500;var _e=(l=>(l[l.width=0]="width",l[l.height=1]="height",l[l.both=2]="both",l))(_e||{});const Cn=new Set([v.Line,v.Group]);class An{}class Vi extends An{align(t,e,n,o,s,r){const i={minX:o.minX,maxX:o.maxX,minY:n.minY-r,maxY:n.minY+r},a=t.nodeManager.searchNodesByRectNode(i),c=M.filterSlideContainerNodes(t,a),h=[];for(const g of c){if(e.has(g)||Cn.has(g.type))continue;const y=g.getBounds();if(Math.abs(n.minY-y.minY)<r){const P=Math.min(n.minX,y.minX),b=Math.max(n.maxX,y.maxX),w={start:new m(P,y.minY),end:new m(b,y.minY)};h.push({line:w,dx:0,dy:y.minY-n.minY})}if(Math.abs(n.minY-y.maxY)<r){const P=Math.min(n.minX,y.minX),b=Math.max(n.maxX,y.maxX),w={start:new m(P,y.maxY),end:new m(b,y.maxY)};h.push({line:w,dx:0,dy:y.maxY-n.minY})}}if(h.length===0)return;const d=h.map(g=>g.dy),u=Math.min(...d),f={dx:0,dy:u,lines:[]};for(const g of h)Math.abs(g.dy-u)<.01&&f.lines.push(g.line);s.top=f}}class Ki extends An{align(t,e,n,o,s,r=2){const i={minX:o.minX,maxX:o.maxX,minY:n.maxY-r,maxY:n.maxY+r},a=t.nodeManager.searchNodesByRectNode(i),c=M.filterSlideContainerNodes(t,a),h=[];for(const g of c){if(e.has(g)||Cn.has(g.type))continue;const y=g.getBounds();if(Math.abs(n.maxY-y.minY)<r){const P=Math.min(n.minX,y.minX),b=Math.max(n.maxX,y.maxX),w={start:new m(P,y.minY),end:new m(b,y.minY)};h.push({line:w,dx:0,dy:y.minY-n.maxY})}if(Math.abs(n.maxY-y.maxY)<r){const P=Math.min(n.minX,y.minX),b=Math.max(n.maxX,y.maxX),w={start:new m(P,y.maxY),end:new m(b,y.maxY)};h.push({line:w,dx:0,dy:y.maxY-n.maxY})}}if(h.length===0)return;const d=h.map(g=>g.dy),u=Math.min(...d),f={dx:0,dy:u,lines:[]};for(const g of h)Math.abs(g.dy-u)<.01&&f.lines.push(g.line);s.bottom=f}}class Qi extends An{align(t,e,n,o,s,r){const i={minX:n.minX-r,maxX:n.minX+r,minY:o.minY,maxY:o.maxY},a=t.nodeManager.searchNodesByRectNode(i),c=M.filterSlideContainerNodes(t,a),h=[];for(const g of c){if(e.has(g)||Cn.has(g.type))continue;const y=g.getBounds();if(Math.abs(n.minX-y.minX)<r){const P=Math.min(n.minY,y.minY),b=Math.max(n.maxY,y.maxY),w={start:new m(y.minX,P),end:new m(y.minX,b)};h.push({line:w,dy:0,dx:y.minX-n.minX})}if(Math.abs(n.minX-y.maxX)<r){const P=Math.min(n.minY,y.minY),b=Math.max(n.maxY,y.maxY),w={start:new m(y.maxX,P),end:new m(y.maxX,b)};h.push({line:w,dy:0,dx:y.maxX-n.minX})}}if(h.length===0)return;const d=h.map(g=>g.dx),u=Math.min(...d),f={dy:0,dx:u,lines:[]};for(const g of h)Math.abs(g.dx-u)<.01&&f.lines.push(g.line);s.left=f}}class Zi extends An{align(t,e,n,o,s,r){const i={minX:n.maxX-r,maxX:n.maxX+r,minY:o.minY,maxY:o.maxY},a=t.nodeManager.searchNodesByRectNode(i),c=M.filterSlideContainerNodes(t,a),h=[];for(const g of c){if(e.has(g)||Cn.has(g.type))continue;const y=g.getBounds();if(Math.abs(n.maxX-y.minX)<r){const P=Math.min(n.minY,y.minY),b=Math.max(n.maxY,y.maxY),w={start:new m(y.minX,P),end:new m(y.minX,b)};h.push({line:w,dy:0,dx:y.minX-n.maxX})}if(Math.abs(n.maxX-y.maxX)<r){const P=Math.min(n.minY,y.minY),b=Math.max(n.maxY,y.maxY),w={start:new m(y.maxX,P),end:new m(y.maxX,b)};h.push({line:w,dy:0,dx:y.maxX-n.maxX})}}if(h.length===0)return;const d=h.map(g=>g.dx),u=Math.min(...d),f={dy:0,dx:u,lines:[]};for(const g of h)Math.abs(g.dx-u)<.01&&f.lines.push(g.line);s.right=f}}class _d extends An{align(t,e,n,o,s,r){const i=.5*(n.minY+n.maxY),a={minX:o.minX,maxX:o.maxX,minY:i-r,maxY:i+r},c=t.nodeManager.searchNodesByRectNode(a),h=M.filterSlideContainerNodes(t,c),d=[];for(const y of h){if(e.has(y)||Cn.has(y.type))continue;const P=y.getBounds(),b=.5*(P.minY+P.maxY);if(Math.abs(i-b)<r){const w=Math.min(n.minX,n.maxX,P.maxX,P.minX),L=Math.max(n.minX,n.maxX,P.maxX,P.minX),B={start:new m(w,b),end:new m(L,b)};d.push({line:B,dx:0,dy:b-i})}}if(d.length===0)return;const u=d.map(y=>y.dy),f=Math.min(...u),g={dx:0,dy:f,lines:[]};for(const y of d)Math.abs(y.dy-f)<.01&&g.lines.push(y.line);s.horizonMid=g}}class $d extends An{align(t,e,n,o,s,r){const i=.5*(n.minX+n.maxX),a={minX:i-r,maxX:i+r,minY:o.minY,maxY:o.maxY},c=t.nodeManager.searchNodesByRectNode(a),h=M.filterSlideContainerNodes(t,c),d=[];for(const y of h){if(e.has(y)||Cn.has(y.type))continue;const P=y.getBounds(),b=.5*(P.minX+P.maxX);if(Math.abs(i-b)<r){const w=Math.min(n.minY,n.maxY,P.maxY,P.minY),L=Math.max(n.minY,n.maxY,P.maxY,P.minY),B={start:new m(b,w),end:new m(b,L)};d.push({line:B,dx:b-i,dy:0})}}if(d.length===0)return;const u=d.map(y=>y.dx),f=Math.min(...u),g={dx:f,dy:0,lines:[]};for(const y of d)Math.abs(y.dx-f)<.01&&g.lines.push(y.line);s.verticalMid=g}}class qi{constructor(){p(this,"handlers",[new Vi,new _d,new Ki,new Qi,new $d,new Zi])}align(t,e,n){const o=n.gmlRender.getViewPortBounds(),s=Ys/n.gmlRender.getScale(),r=new Set;for(const a of e)this.computeFilterSet(a,r);const i={};for(const a of this.handlers)a.align(n,r,t,o,i,s);return this.dealAlignTopBottom(i),this.dealAlignLeftRight(i),i}computeFilterSet(t,e){e.add(t);const n=t.children;for(const o of n)this.computeFilterSet(o,e)}dealAlignTopBottom(t){const{top:e,bottom:n,horizonMid:o}=t,s=[e,o,n].map(i=>i==null?void 0:i.dy).filter(i=>i!==void 0);if(s.length===0)return;const r=Math.min(...s);for(const i of["top","bottom","horizonMid"]){const a=t[i];a&&Math.abs(r-a.dy)>.01&&(t[i]=void 0)}}dealAlignLeftRight(t){const{left:e,right:n,verticalMid:o}=t,s=[e,n,o].map(i=>i==null?void 0:i.dx).filter(i=>i!==void 0);if(s.length===0)return;const r=Math.min(...s);for(const i of["left","right","verticalMid"]){const a=t[i];a&&Math.abs(r-a.dx)>.01&&(t[i]=void 0)}if(e&&n){if(Math.abs(e.dx-n.dx)<.01)return;e.dx<n.dx?t.right=void 0:t.left=void 0}}}const _s=new Set([v.Group,v.Line]);class $s{}class Ji extends $s{enable(t){return t===_e.both||t===_e.width}align(t,e,n,o,s,r,i,a){const c=n.maxX-n.minX,h=this.searchNodes(t,c,s,n,o,r,i,a);if(h.length===0)return;const d=h.map(y=>y.dt),u=Math.min(...d),f=[];for(const y of h)Math.abs(y.dt-u)<.01&&f.push(y.info);const g={dt:u,sideSize:c,lines:f};e.width=g}searchNodes(t,e,n,o,s,r,i,a){let c=200;const h={minX:o.minX-c,maxX:o.maxX+c,minY:o.minY-c,maxY:o.maxY+c},d=[];for(;d.length===0&&!(c>i||M.containRect(h,r));){const u=this.searchNodesForOffset(t,e,n,h,s,r,c,a);d.push(...u),c=2*c}return d}searchNodesForOffset(t,e,n,o,s,r,i,a){const c=t.nodeManager.searchNodesByRectNode(r),h=M.filterSlideContainerNodes(t,c),d=[];for(const u of h){if(s.has(u)||_s.has(u.type))continue;const{width:f,height:g,angle:y}=u.baseProps,P=y%360;if(!(Math.abs(P)>30)&&Math.abs(f-e)<a){const b={x:0,y:g},w={x:f,y:g};d.push({dt:f-e,sideSize:f,info:{line:{start:b,end:w},transform:u.globalTransform().clone()}})}}return d}}class ea extends $s{enable(t){return t===_e.both||t===_e.height}align(t,e,n,o,s,r,i,a){const c=n.maxY-n.minY,h=this.searchNodes(t,c,s,n,o,r,i,a);if(h.length===0)return;const d=h.map(y=>y.dt),u=Math.min(...d),f=[];for(const y of h)Math.abs(y.dt-u)<.01&&f.push(y.info);const g={dt:u,sideSize:c,lines:f};e.height=g}searchNodes(t,e,n,o,s,r,i,a){let c=200;const h={minX:o.minX-c,maxX:o.maxX+c,minY:o.minY-c,maxY:o.maxY+c},d=[];for(;d.length===0&&!(c>i||M.containRect(h,r));){const u=this.searchNodesForOffset(t,e,n,h,s,r,c,a);d.push(...u),c=2*c}return d}searchNodesForOffset(t,e,n,o,s,r,i,a){const c=t.nodeManager.searchNodesByRectNode(r),h=M.filterSlideContainerNodes(t,c),d=[];for(const u of h){if(s.has(u)||_s.has(u.type))continue;const{width:f,height:g,angle:y}=u.baseProps,P=y%360;if(!(Math.abs(P)>30)&&Math.abs(g-e)<a){const b={x:f,y:0},w={x:f,y:g};d.push({dt:g-e,sideSize:g,info:{line:{start:b,end:w},transform:u.transform.clone()}})}}return d}}class ta{constructor(){p(this,"handlers",[new Ji,new ea])}align(t,e,n,o,s,r,i){const a={};for(const c of this.handlers)c.enable(o)&&c.align(t,a,e,n,o,s,r,i);return a}}class na{}class jd extends na{align(t,e,n,o,s,r){const i={minX:o.minX,maxX:o.maxX,minY:n.y-r,maxY:n.y+r},a=t.nodeManager.searchNodesByRectNode(i),c=M.filterSlideContainerNodes(t,a),h=[];for(const g of c){if(this.skipNodeAlign(e,g))continue;const y=g.getBounds(),P=[y.minY,y.maxY];for(const b of P)if(Math.abs(n.y-b)<r){const w=Math.min(n.x,y.minX,y.maxX),L=Math.max(n.x,y.minX,y.maxX),B={start:new m(w,b),end:new m(L,b)};h.push({line:B,dx:0,dy:b-n.y})}}if(h.length===0)return;const d=h.map(g=>g.dy),u=Math.min(...d),f={dx:0,dy:u,lines:[]};for(const g of h)Math.abs(g.dy-u)<.01&&f.lines.push(g.line);s.horizon=f}skipNodeAlign(t,e){if(t.has(e))return!0;if(e.type===v.Line){const n=e;if(n.shapeType!==de.Line)return!0;const o=n.points;return!M.judgeHorizon(o[0],o[o.length-1])}return e.type===v.Group}}class Vd extends na{align(t,e,n,o,s,r){const i={minY:o.minY,maxY:o.maxY,minX:n.x-r,maxX:n.x+r},a=t.nodeManager.searchNodesByRectNode(i),c=M.filterSlideContainerNodes(t,a),h=[];for(const g of c){if(this.skipNodeAlign(e,g))continue;const y=g.getBounds(),P=[y.minX,y.maxX];for(const b of P)if(Math.abs(n.x-b)<r){const w=Math.min(n.y,y.minY,y.maxY),L=Math.max(n.y,y.minY,y.maxY),B={start:new m(b,w),end:new m(b,L)};h.push({line:B,dx:b-n.x,dy:0})}}if(h.length===0)return;const d=h.map(g=>g.dx),u=Math.min(...d),f={dx:u,dy:0,lines:[]};for(const g of h)Math.abs(g.dx-u)<.01&&f.lines.push(g.line);s.vertical=f}skipNodeAlign(t,e){if(t.has(e))return!0;if(e.type===v.Line){const n=e;if(n.shapeType!==de.Line)return!0;const o=n.points;return!M.judgeVertical(o[0],o[o.length-1])}return e.type===v.Group}}class Kd{constructor(){p(this,"handlers",[new jd,new Vd])}align(t,e,n){const o=n.gmlRender.getViewPortBounds(),s=Ys/n.gmlRender.getScale(),r={};for(const i of this.handlers)i.align(n,e,t,o,r,s);return r}}class $t{static addAllParentToSet(t,e){let n=t.parent;for(;n&&n.type===v.Group;)e.add(n),n=n.parent}static findHoverNode(t,e){if(t.parent.type!==v.Group)return t;const n=new Set;for(const s of e)n.add(s.parent);let o=t.parent;if(n.has(o))return t;for(;o;){const s=o.parent;if(n.has(s))return o;if(s.type!==v.Group)break;o=s}return o}static flattenNodes(t){const e=new Set;for(const n of t)this.flattenGroupNodes(n,e);return[...e]}static flattenGroupNodes(t,e){if(t.type!==v.Group){e.add(t);return}const o=t.children;for(const s of o)this.flattenGroupNodes(s,e)}}class un{constructor(){p(this,"alignMoveWorker",new qi);p(this,"alignStretchWorker",new ta);p(this,"alignLineEndWorker",new Kd)}alignLineEnd(t,e,n,o){return o?this.alignLineEndWorker.align(t,e,n):{}}alignMove(t,e,n,o){if(!o)return{};const s=new Set;for(const r of e)this.addChildrenToFilterSet(r,s);return this.alignMoveWorker.align(t,s,n)}alignStretch(t,e,n,o,s,r,i){const a=D.toRectNode(e),c=new Set(n);for(const d of[...n])$t.addAllParentToSet(d,c);return this.alignStretchWorker.align(t,a,c,o,s,r,i)}alignLineEndAndDrawAlignLines(t,e,n=e.getSelectNodes(),o=!0){const s=t.globalPoint.clone(),r=this.alignLineEnd(s,n,e,o),i=[];return r.horizon&&(i.push(...r.horizon.lines),s.y+=r.horizon.dy),r.vertical&&(i.push(...r.vertical.lines),s.x+=r.vertical.dx),e.addOrUpdate(N.AlignLine,{lines:i}),s}drawAlignLines(t,e){const{top:n,bottom:o,horizonMid:s,right:r,left:i,verticalMid:a}=t,c=[],h=new m;return n&&(h.y=n.dy,c.push(...n.lines)),s&&(h.y=s.dy,c.push(...s.lines)),o&&(h.y=o.dy,c.push(...o.lines)),i&&(h.x=i.dx,c.push(...i.lines)),a&&(h.x=a.dx,c.push(...a.lines)),r&&(h.x=r.dx,c.push(...r.lines)),e.addOrUpdate(N.AlignLine,{lines:c}),h}addChildrenToFilterSet(t,e){e.add(t);const n=t.children;for(const o of n)this.addChildrenToFilterSet(o,e)}}class qe{}class Ot{constructor(t){p(this,"processors",[]);this.processors=t}work(t,e){for(const n of this.processors)n.allowEventTypeSet.has(t.type)&&n.process(t,e)}stop(t,e){for(const n of this.processors)n.stop&&n.stop(t,e)}isStreaming(){return!1}}class pn extends Ot{constructor(e){super(e);p(this,"deltaDistance",1);p(this,"locked",!1)}clickEnable(e,n){return!0}canBeEnable(e,n){if(e.type!==be.pointerDown)return!1;const o=this.clickEnable(e,n);return o&&(this.locked=!0),o}work(e,n){e.type===be.pointerup&&(this.locked=!1),e.type!==be.pointerDown&&n.lastDiffTypeEvent&&M.distance(n.lastDiffTypeEvent.globalPoint,e.globalPoint)>this.deltaDistance/n.gmlRender.getScale()&&(this.locked=!1),super.work(e,n)}canBeExit(e,n){const o=!this.locked;return o&&this.stop(e,n),o}}class jt{constructor(){p(this,"downHandlers",[]);p(this,"upHandlers",[]);p(this,"hasWorking",!1);p(this,"allowEventTypeSet",new Set([be.pointerDown,be.pointerup]))}registerDownHandler(t){this.downHandlers.push(t)}registerUpHandler(t){this.upHandlers.push(t)}process(t,e){this.downProcess(t,e),this.upProcess(t,e)}stop(t,e){this.hasWorking=!1}downProcess(t,e){if(t.type===be.pointerDown){for(const n of this.downHandlers)if(n.enable(t,e)){this.hasWorking=!0,n.handle(t,e);return}}}upProcess(t,e){if(t.type===be.pointerup){if(this.hasWorking){this.hasWorking=!1;return}for(const n of this.upHandlers)if(n.enable(t,e)){n.handle(t,e);return}}}}class js extends Ot{constructor(e){super(e);p(this,"deltaDistance",1);p(this,"locked",!1);p(this,"firstPointerDown",!1)}canBeEnable(e,n){return e.type===be.pointerDown?this.firstPointerDown?(this.locked=!0,!0):(this.firstPointerDown=!0,setTimeout(()=>{this.firstPointerDown=!1},300),!1):!1}work(e,n){this.firstPointerDown&&e.type===be.pointerup&&(this.locked=!1),e.type===be.pointermove&&M.distance(n.lastInteractiveEvent.globalPoint,e.globalPoint)>this.deltaDistance/n.gmlRender.getScale()&&(this.locked=!1),this.firstPointerDown||(this.locked=!1),super.work(e,n)}canBeExit(e,n){const o=!this.locked;return o&&this.stop(e,n),o}}class dt extends Ot{constructor(e,n=[]){super(n);p(this,"streamProcessor");p(this,"deltaDistance",1);p(this,"locked",!1);this.streamProcessor=e}onDown(e,n){}canBeEnable(e,n){var i;if(e.type===be.pointerDown&&this.onDown(e,n),!(((i=n.lastDiffTypeEvent)==null?void 0:i.type)===be.pointerDown&&e.type===be.pointermove))return!1;const s=n.lastDiffTypeEvent.globalPoint;if(M.distance(s,e.globalPoint)<this.deltaDistance/n.gmlRender.getScale())return!1;const r=this.streamEnable(n.lastDiffTypeEvent,n);if(r){this.locked=!0;for(const a of this.streamProcessor)a.onStart(n.lastDiffTypeEvent,n)}return r}work(e,n){if(e.type===be.pointermove)for(const o of this.streamProcessor)o.onMove(e,n);if(e.type===be.pointerup){for(const o of this.streamProcessor)o.onUp(e,n);this.locked=!1}super.work(e,n)}canBeExit(e,n){const o=!this.locked;return o&&this.stop(e,n),o}isStreaming(){return this.locked}}class fn{constructor(t){p(this,"currentSubMode");p(this,"subModes",[]);this.subModes=t,this.currentSubMode=t[t.length-1]}canBeExit(t,e){return this.currentSubMode.canBeExit(t,e)}work(t,e){this.detect(t,e),this.currentSubMode.work(t,e)}detect(t,e){if(this.currentSubMode.canBeExit(t,e)){for(const n of this.subModes)if(n.canBeEnable(t,e)){this.currentSubMode=n;return}}}}class kn extends Ot{constructor(e,n=[]){super(n);p(this,"streamProcessor");p(this,"locked",!1);this.streamProcessor=e}canBeEnable(e,n){if(e.type!==be.pointerDown)return!1;const o=this.streamEnable(e,n);return o&&(this.locked=!0),o}work(e,n){if(e.type===be.pointerDown)for(const o of this.streamProcessor)o.onStart(e,n);if(e.type===be.pointermove)for(const o of this.streamProcessor)o.onMove(e,n);if(e.type===be.pointerup){for(const o of this.streamProcessor)o.onUp(e,n);this.locked=!1}super.work(e,n)}canBeExit(e,n){const o=!this.locked;return o&&this.stop(e,n),o}isStreaming(){return this.locked}}class ht{constructor(){p(this,"allowEventTypeSet",new Set([be.pointerDown,be.pointermove,be.pointerup]))}process(t,e){}}class oa{}class sa extends Ke{onDetect(t,e){if(e.detect(F.Stretch,t)||e.detect(F.Rotate,t)||e.detect(F.LineEndPoint,t))return!1;const r=t.globalPoint;let i=e.nodeManager.searchNodes(r.x,r.y);i=M.filterSlideContainerNodes(e,i);let a=[];for(const c of i)c.type!==v.Group&&c.contains(t.globalPoint,e.gmlRender.getScale())&&a.push(c);return a.length===0?(this.result=null,!1):(a=M.sortGraphics(a),a.reverse(),this.result=a,!0)}}class ra extends Ke{onDetect(t,e){const n=e.detect(F.Node,t);if(!n)return!1;const o=n[0];if(n.length===1&&e.auxiliaryManager.selectManager.include(o))return!1;if(t.originEvent.metaKey)return this.result=o,!0;const s=e.getSelectNodes(),r=$t.findHoverNode(o,s);return r?(this.result=r,!0):(this.result=o,!0)}}const ys=class ys extends Ke{computeLocalPoint(t,e,n){if(t.length===1){const i=t[0],a=i.baseProps,c=i.toLocal(e.globalPoint),h=D.baseProps2Rect(a);return{localPoint:c,rect:h}}const o=n.auxiliaryManager.selectManager.getSelectBounds(),s=D.rectNode2Rect(o);return{localPoint:new m(e.globalPoint.x-s.x,e.globalPoint.y-s.y),rect:s}}onDetect(t,e){const n=e.auxiliaryManager.selectManager.selectNodes;if(n.size===0||e.detect(F.ExpandShape,t))return!1;const s=$t.flattenNodes([...n]),r=e.gmlRender.getScale(),i=ys.HOT_DISTANCE/r,{rect:a,localPoint:c}=this.computeLocalPoint(s,t,e),h=new D(0,0,a.width,a.height),d=M.detectRectBounds(h,c,i);return d?(this.result={nodes:s,type:d.type,angle:M.computeStretchAngle(s,d.type)},!0):!1}};p(ys,"HOT_DISTANCE",8);let Fo=ys;class ia extends ht{constructor(){super(...arguments);p(this,"start",null)}onStart(e,n){const{renderText:o,node:s}=n.inputManager.editTextInfo,r=s.toLocal(e.globalPoint),i=o.detect(r);n.setCursor("text"),this.start=i,n.execAction(new W)}onMove(e,n){const{renderText:o,node:s}=n.inputManager.editTextInfo,r=s.toLocal(e.globalPoint),i=o.detect(r);this.start.equal(i)?n.execAction(ee.focus(s.id,this.start)):n.execAction(ee.selection(s.id,this.start,i))}onUp(e,n){const{renderText:o,node:s}=n.inputManager.editTextInfo,r=s.toLocal(e.globalPoint),i=o.detect(r);this.start.equal(i)?n.execAction(ee.focus(s.id,this.start)):n.execAction(ee.selection(s.id,this.start,i)),n.execAction(new z)}}class aa extends dt{constructor(){super([new ia])}streamEnable(t,e){const n=e.inputManager.editTextInfo;if(!n)return!1;const{node:o,renderText:s}=n,r=o.getTextContentRect(),i=o.toLocal(t.globalPoint);return!!M.rectContains(i,r)}}class on{constructor(){p(this,"parentGroupSet",new Set)}start(t){this.parentGroupSet.clear();for(const e of t)$t.addAllParentToSet(e,this.parentGroupSet)}work(t,e){if(this.parentGroupSet.size===0)return;const n=M.sortGraphics([...this.parentGroupSet]).reverse();for(const o of n){const s=o.computeBasePropsByChildren();t.execAction(new U({infos:[{id:o.id,props:[s]}]},{streaming:e}))}}}class gn{}class Qd extends gn{enable(t){return!(!(t instanceof Fn)||t.cropProps.cropType===wt.None||!t.cropProps.cropInfo)}handle(t,e,n,o,s){const r=this.handleCropProp(t,e,n,o,s);return[{id:t.id,props:[r]}]}handleCropProp(t,e,n,o,s){const r=e.crop,i=e.crop.globalImgPos,a=r.originCropProps,c=a.cropType,h=s.crossPoint(new m(i.x,i.y)),d=t.toLocal(h);return{type:I.Crop,cropInfo:{imgX:d.x,imgY:d.y,imgWidth:a.cropInfo.imgWidth*n,imgHeight:a.cropInfo.imgHeight*o},cropType:c}}}class Zd extends en{updateProps(t){super.updateProps(t),t.find(n=>n.type===I.Base)&&this.updateTransformMatrix()}getTextContentRect(){return this.baseProps}getConnectAnchor(){return[new m(.5,0),new m(1,.5),new m(.5,1),new m(0,.5)]}borderContains(t,e){const n=this.toLocal(t),{width:o,height:s}=this.baseProps,r=q.rectangle({top:0,left:0,width:o,height:s}),i=q.line({x:n.x-e,y:n.y},{x:n.x+e,y:n.y}),a=q.line({x:n.x,y:n.y-e},{x:n.x,y:n.y+e});for(const c of[i,a]){const h=Y.intersect(r,c);if(h.points.length>0)return h.points[0]}return null}}class Yo extends Zd{get checkStatus(){return this.getProp(I.CheckStatus).checkStatus}constructor(t,e){super(t,e),this.props.set(I.Base,new ie),this.props.set(I.Border,new Ae),this.props.set(I.CheckStatus,new Qt),this.props.set(I.Color,new tt),this.props.set(I.Shape,new Oe)}drawOnGLCtx(t){this.drawCheckboxBorder(t),this.drawCheckboxIcon(t)}drawCheckboxBorder(t){const e=this.getProp(I.Border),n=this.baseProps;if(e.color!==""&&e.alpha!==0&&e.dashType!==et.None){const{a:o,b:s,c:r,d:i,e:a,f:c}=this.globalTransform();t.save(),t.transform(o,s,r,i,a,c),t.beginPath(),t.roundRect(0,0,n.width,n.height,4),t.lineWidth=e.width,t.strokeStyle=e.color,t.globalAlpha=e.alpha,M.setDashLine(e,t),t.stroke(),t.restore()}}drawCheckboxIcon(t){if(!this.checkStatus)return;const e=this.getProp(I.Color),n=this.baseProps;if(e.color!==""&&e.alpha!==0){t.save();const o=re.generateMatrix().scale(n.width/16,n.height/16),{a:s,b:r,c:i,d:a,e:c,f:h}=this.globalTransform().crossProduct(o);t.transform(s,r,i,a,c,h),t.fillStyle=e.color,t.globalAlpha=e.alpha,t.scale(1,1),t.beginPath();const d=new Path2D("M10.97 4.97a.75.75 0 0 1 1.07 1.05l-3.99 4.99a.75.75 0 0 1-1.08.02L4.324 8.384a.75.75 0 1 1 1.06-1.06l2.094 2.093 3.473-4.425a.267.267 0 0 1 .02-.022z");t.fill(d),t.restore()}}checkboxContain(t){return this.contains(t)}canQuickCreate(){return!1}canBeConnected(){return!0}static load(t,e,n,o,s,r){const i=new Yo(t,r);return i.type=e,i.zIndex=n,i.setParent(s),i.updateProps(o),i}}const ca=1;class Un extends Yo{constructor(e,n){super(e,n);p(this,"renderText");p(this,"checkboxTopPadding",ca);this.props.set(I.Text,new Ge),this.props.set(I.CheckSize,new vn),this.renderText=new uo}get textProps(){return this.props.get(I.Text)}get chickSize(){return this.props.get(I.CheckSize).size}updateProps(e){super.updateProps(e);const n=e.find(r=>r.type===I.Text),o=e.find(r=>r.type===I.Base),s=e.find(r=>r.type===I.CheckSize);if(n||o||s){const r=this.getTextContentRect();if(this.renderText.typesetting(this.graphicContext,this.textProps,r),this.baseProps.height=this.renderText.height+2*le,this.renderText.rect.height=this.renderText.height+2*le,this.renderText.paragraphs.length>0){const i=this.renderText.paragraphs[0];if(i.lines.length>0){const a=i.lines[0];this.checkboxTopPadding=.5*(a.height-this.chickSize)}}}}drawOnGLCtx(e){super.drawOnGLCtx(e),this.drawText(e)}drawCheckboxBorder(e){const n=this.getProp(I.Border);if(n.color!==""&&n.alpha!==0&&n.dashType!==et.None){const o=this.chickSize,{a:s,b:r,c:i,d:a,e:c,f:h}=this.globalTransform();e.save(),e.transform(s,r,i,a,c,h),e.beginPath(),e.roundRect(0,le+this.checkboxTopPadding,o,o,4),e.lineWidth=n.width,e.strokeStyle=n.color,e.globalAlpha=n.alpha,M.setDashLine(n,e),e.stroke(),e.restore()}}drawCheckboxIcon(e){if(!this.checkStatus)return;const n=this.getProp(I.Color);if(n.color!==""&&n.alpha!==0){e.save();const o=this.chickSize,s=re.generateMatrix().scale(o/16,o/16),r=re.generateMatrix().translate(0,this.checkboxTopPadding+le),{a:i,b:a,c,d:h,e:d,f:u}=this.globalTransform().crossProduct(r).crossProduct(s);e.transform(i,a,c,h,d,u),e.fillStyle=n.color,e.globalAlpha=n.alpha,e.scale(1,1),e.beginPath();const f=new Path2D("M10.97 4.97a.75.75 0 0 1 1.07 1.05l-3.99 4.99a.75.75 0 0 1-1.08.02L4.324 8.384a.75.75 0 1 1 1.06-1.06l2.094 2.093 3.473-4.425a.267.267 0 0 1 .02-.022z");e.fill(f),e.restore()}}drawText(e){const{alpha:n}=this.getProp(I.Color);e.save(),e.beginPath();const o=this.globalPos;this.renderText.draw(e,new m(o.x,o.y),n),e.restore()}checkboxContain(e){const{height:n}=this.baseProps,o=this.toLocal(e);return M.rectContains(o,new D(0,0,n,n))}getTextContentRect(){const{width:e,height:n}=this.baseProps,o=this.chickSize;return{x:o+le,y:le,width:e-2*le-o-ca,height:n-2*le}}static load(e,n,o,s,r,i){const a=new Un(e,i);return a.type=n,a.zIndex=o,a.setParent(r),a.updateProps(s),a}}class Go extends ht{constructor(){super(...arguments);p(this,"minStretchSize",new m(0,0));p(this,"originPos",new m(0,0));p(this,"originStretchRect");p(this,"propsMap",new Map);p(this,"originTransform",re.generateMatrix());p(this,"viewBounds");p(this,"target",null);p(this,"alignWorker",new un);p(this,"alignType",_e.width);p(this,"originWidthHeightRatio",1);p(this,"isUniform",!1);p(this,"relatedLines",new Set);p(this,"layoutWorker",new Rn);p(this,"cropStretchHandler",new Qd);p(this,"groupBaseWorker",new on)}recordNodePropInfo(e){const{x:n,y:o,width:s,height:r}=e.globalBaseProps,i=this.originTransform.crossPoint({x:n,y:o}),a={x:i.x,y:i.y,width:s,height:r};if(e instanceof Fn){const c=e.cropProps,h=e.getOriginImageRect().clone(),d=e.toGlobal({x:h.x,y:h.y}),u={originCropProps:c.clone(),originImgRect:h,originTransform:e.globalTransform().inverseMatrix().clone(),globalImgPos:this.originTransform.crossPoint(d)};a.crop=u}return e instanceof vt&&e.shapeType===K.PureText&&(a.fontSize=e.textProps.fontSize),e instanceof Un&&(a.fontSize=e.textProps.fontSize,a.checkSize=e.chickSize),a}computeAnchorPoint(e,n){const{width:o,height:s}=n;switch(e.type){case V.TOP:return this.alignType=_e.height,{x:.5*o,y:s};case V.RIGHT:return this.alignType=_e.width,{x:0,y:.5*s};case V.BOTTOM:return this.alignType=_e.height,{x:.5*o,y:0};case V.LEFT:return this.alignType=_e.width,{x:o,y:.5*s};case V.TOP_LEFT:return this.alignType=_e.both,{x:o,y:s};case V.TOP_RIGHT:return this.alignType=_e.both,{x:0,y:s};case V.BOTTOM_RIGHT:return this.alignType=_e.both,{x:0,y:0};case V.BOTTOM_LEFT:default:return this.alignType=_e.both,{x:o,y:0}}}judgeUniform(e){this.isUniform=!1;const n=this.target.nodes;for(const o of n){if(Math.abs(o.baseProps.angle)>.1){this.isUniform=!0;return}if(o.type===v.SVG||o.type===v.IMG||o.type===v.Checkbox){this.isUniform=!0;return}if(o.type===v.Shape&&o.shapeType===K.PureText&&(this.target.type===V.TOP||this.target.type===V.TOP_LEFT||this.target.type===V.BOTTOM_LEFT||this.target.type===V.BOTTOM||this.target.type===V.BOTTOM_RIGHT||this.target.type===V.TOP_RIGHT)){this.isUniform=!0;return}if(o.type===v.CheckboxText&&(this.target.type===V.TOP||this.target.type===V.TOP_LEFT||this.target.type===V.BOTTOM_LEFT||this.target.type===V.BOTTOM||this.target.type===V.BOTTOM_RIGHT||this.target.type===V.TOP_RIGHT)){this.isUniform=!0;return}}}computeStretchRect(e,n){switch(this.target.type){case V.BOTTOM:e.height+=n.y;break;case V.LEFT:e.x+=n.x,e.width-=n.x;break;case V.RIGHT:e.width+=n.x;break;case V.TOP:e.y+=n.y,e.height-=n.y;break;case V.BOTTOM_LEFT:e.height+=n.y,e.x+=n.x,e.width-=n.x;break;case V.BOTTOM_RIGHT:e.height+=n.y,e.width+=n.x;break;case V.TOP_LEFT:e.y+=n.y,e.height-=n.y,e.x+=n.x,e.width-=n.x;break;case V.TOP_RIGHT:e.y+=n.y,e.height-=n.y,e.width+=n.x;break}e.width<this.minStretchSize.x&&(e.width=this.minStretchSize.x),e.height<this.minStretchSize.y&&(e.height=this.minStretchSize.y)}computeTarget(e,n){this.target=n.detect(F.Stretch,e)}onStart(e,n){this.computeTarget(e,n),this.originStretchRect=this.getStretchRect(n),this.originWidthHeightRatio=this.originStretchRect.width/this.originStretchRect.height,this.computeOriginTransform(n),this.minStretchSize=this.getMiniSize(n),this.judgeUniform(n),this.originPos=this.originTransform.crossPoint(e.globalPoint),this.recordPropsMap(n),this.relatedLines.clear(),this.batchCollectNodeLinks(this.target.nodes,n,this.relatedLines),this.groupBaseWorker.start(this.target.nodes),this.viewBounds=n.gmlRender.getViewPortBounds(),n.actionManager.execAction(new W);const o=[];for(const s of this.target.nodes)(s.type===v.CheckboxText||s instanceof vt&&s.shapeType===K.PureText)&&(this.target.type===V.RIGHT||this.target.type===V.LEFT)&&o.push({id:s.id,props:[{type:I.Text,sizeMode:We.autoHeight}]}),s instanceof vt&&this.target.type!==V.RIGHT&&this.target.type!==V.LEFT&&o.push({id:s.id,props:[{type:I.Text,sizeMode:We.fix}]});n.actionManager.execAction(new U({infos:o})),n.inputManager.editTextInfo&&n.execAction(ee.blur(n.inputManager.editTextInfo.node.id))}onMove(e,n){n.auxiliaryManager.removeAlignGraphics(),this.stretchNode(e,n,!0)}onUp(e,n){this.stretchNode(e,n,!1),n.actionManager.execAction(new z),n.auxiliaryManager.removeAlignGraphics()}alignStretchGlobalPoint(e,n){const o=new Set(this.target.nodes),s=!M.pressMeta(e);return this.alignWorker.alignLineEndAndDrawAlignLines(e,n,o,s)}stretchNode(e,n,o){const s=this.alignStretchGlobalPoint(e,n),r=this.originTransform.crossPoint(s),i=new m(r.x-this.originPos.x,r.y-this.originPos.y),a=this.originStretchRect.clone();this.computeStretchRect(a,i);const c=n.gmlRender.getScale(),h=new Set(this.target.nodes),d=this.alignWorker.alignStretch(n,a,h,this.alignType,this.viewBounds,Us/c,Gs/c);this.drawAlignLine(a,d,n);const{sx:u,sy:f}=this.computeScale(a),g=re.generateMatrix().scale(u,f),y=this.originTransform.inverseMatrix().crossProduct(g),P=[],b=[],w=[];for(const[L,B]of this.propsMap){for(const H of this.handlers)if(H.enable(L)){const E=H.handle(L,B,u,f,y,n,this.isUniform);P.push(...E);break}L.type===v.SVG&&b.push(L),this.cropStretchHandler.enable(L)&&w.push(L)}n.execAction(new U({infos:P},{streaming:o})),this.afterStretchNode(n,u,f,y,o,w,b),this.layoutWorker.work([...this.relatedLines],n,o),this.groupBaseWorker.work(n,o)}afterStretchNode(e,n,o,s,r,i,a){if(i.length>0){const c=[];i.forEach(h=>{c.push(...this.cropStretchHandler.handle(h,this.propsMap.get(h),n,o,s))}),e.execAction(new U({infos:c},{streaming:r}))}if(r||e.asyncRenderNodeManager.batchAddRenderNode(a),this.target.type===V.BOTTOM_RIGHT){const c=[...this.target.nodes],h=c[0];if(c.length===1)e.addOrUpdate(N.HoverSize,{rect:D.baseProps2Rect(h.baseProps),transform:h.globalTransform().clone()});else{const d=e.auxiliaryManager.selectManager.getSelectBounds();e.addOrUpdate(N.HoverSize,{rect:D.rectNode2Rect(d),transform:re.generateMatrix().translate(d.minX,d.minY)})}}}computeScale(e){let n=e.width/this.originStretchRect.width,o=e.height/this.originStretchRect.height;if(!this.isUniform)return{sx:n,sy:o};const s=this.target.type;if(s===V.BOTTOM||s===V.TOP)return n=o,{sx:n,sy:o};if(s===V.LEFT||s===V.RIGHT)return o=n,{sx:n,sy:o};const r=e.width/e.height;return r>this.originWidthHeightRatio?o=n:r<this.originWidthHeightRatio&&(n=o),{sx:n,sy:o}}batchCollectNodeLinks(e,n,o){const s=n.getSelectNodes();for(const r of e)this.collectNodeLinks(r,n,s,o)}collectNodeLinks(e,n,o,s){const r=n.nodeManager.getNodeLinks(e);for(const i of r)o.has(i)||s.add(i);for(const i of e.children)i.type===v.Line&&this.collectNodeLinks(i,n,o,s)}}class qd extends gn{enable(t){return t.type===v.Section}handle(t,e,n,o,s,r){const i=s.crossPoint({x:e.x,y:e.y}),a=t.baseProps,c=t.parent.toLocal(i),h=new m(c.x-a.x,c.y-a.y),d=[{id:t.id,props:[{type:I.Base,x:c.x,y:c.y,width:e.width*n,height:e.height*o}]}];if(t.type===v.Section&&t.children.size>0){const u=t,f=this.computeSectionChildren(u,r);for(const g of f){const y=g.baseProps;if(g.type===v.Line){const P=g.points.map(w=>new m(w.x,w.y));for(const w of P)w.x-=h.x,w.y-=h.y;const b=D.rectNode2Rect(M.getBoundsByPoints(P));d.push({id:g.id,props:[{type:I.Line,points:P},{type:I.Base,x:b.x,y:b.y,width:b.width,height:b.height}]})}else d.push({id:g.id,props:[{type:I.Base,x:y.x-h.x,y:y.y-h.y}]})}}return d}computeSectionChildren(t,e){const n=t.children,o=new Set;for(const s of n)s.type===v.Group?$t.flattenGroupNodes(s,o):o.add(s);return o}}class la extends gn{enable(t){return!0}handle(t,e,n,o,s){const r=s.crossPoint({x:e.x,y:e.y}),i=t.parent.toLocal(r);return[{id:t.id,props:[{type:I.Base,x:i.x,y:i.y,width:e.width*n,height:e.height*o}]}]}}class ha extends gn{enable(t){return t.type!==v.Shape?!1:t.shapeType===K.PureText}handle(t,e,n,o,s,r,i){const a=s.crossPoint({x:e.x,y:e.y}),c=t.parent.toLocal(a),d=[{type:I.Base,x:c.x,y:c.y,width:e.width*n,height:e.height*o}],u=t.getProp(I.Text);if(i&&u){const f=e.fontSize*o,g={type:I.Text,fontSize:f};d.push(g)}return[{id:t.id,props:d}]}}class da extends gn{enable(t){return t.type===v.CheckboxText}handle(t,e,n,o,s,r,i){const a=s.crossPoint({x:e.x,y:e.y}),c=t.parent.toLocal(a),d=[{type:I.Base,x:c.x,y:c.y,width:e.width*n,height:e.height*o}],u=t.getProp(I.Text);if(i&&u){const f=e.fontSize*o,g={type:I.Text,fontSize:f};d.push(g);const y=e.checkSize*n;d.push({type:I.CheckSize,size:y})}return[{id:t.id,props:d}]}}class ua extends Go{constructor(){super(...arguments);p(this,"handlers",[new qd,new ha,new da,new la])}getStretchRect(e){const n=[...e.getSelectNodes()];return D.baseProps2Rect(n[0].baseProps)}getMiniSize(e){return[...e.getSelectNodes()][0].getStretchMinSize()}recordPropsMap(e){this.propsMap.clear();const n=this.target.nodes;for(const o of n){const s=this.recordNodePropInfo(o);this.propsMap.set(o,s)}}computeOriginTransform(e){const n=this.target,o=[...e.getSelectNodes()][0],{x:s,y:r,width:i,height:a,angle:c}=o.globalBaseProps,h=re.generateMatrix().rotate(-c),d=re.generateMatrix().translate(-s,-r),u=this.computeAnchorPoint(n,new D(0,0,i,a)),g=re.generateMatrix().translate(-u.x,-u.y).crossProduct(h.crossProduct(d));this.originTransform=g}drawAlignLine(e,n,o){const s=this.target.nodes[0],r=s.baseProps,{width:i,height:a}=n,c=s.globalTransform().clone();if(i){e.width+=i.dt;const h={transform:c,line:{start:new m(0,r.height),end:new m(r.width,r.height)}};i.lines.push(h)}if(a){e.height+=a.dt;const h={transform:c,line:{start:new m(r.width,0),end:new m(r.width,r.height)}};a.lines.push(h)}o.addOrUpdate(N.AlignStretchLine,{alignInfo:n})}}class pa extends kn{constructor(){super([new ua])}streamEnable(t,e){if(e.getSelectNodes().size===0)return!1;const n=e.detect(F.Stretch,t);return n?n.nodes.filter(s=>M.judgeNodeCanBeStretch(s)).length===1:!1}}class Vs{handleChangeRelation(t,e,n){if(t.parent===e)return[];if(t.parent.type===v.Group)return[];const o=t.globalPos,s=e.toLocal(o);return[{id:t.id,props:[{type:I.Base,x:s.x,y:s.y}],parentId:e.id,zIndex:n}]}}class fa extends Vs{enable(t){return t.type===v.Line}handle(t,e){const n=t.baseProps.clone();n.x+=e.x,n.y+=e.y;const o=t.getProp(I.Line).clone();for(const s of o.points)s.x+=e.x,s.y+=e.y;return[{id:t.id,props:[n,o]}]}handleChangeRelation(t,e,n){if(t.parent===e)return[];const o=t.globalLinePoints,s=e.globalTransform().inverseMatrix(),r=o.map(a=>s.crossPoint(a)),i=M.getBoundsByPoints(r);return[{id:t.id,props:[{type:I.Base,x:i.minX,y:i.minY},{type:I.Line,points:r}],parentId:e.id,zIndex:n}]}}class ga extends Vs{enable(t){return!0}handle(t,e){const n=t.baseProps.clone();return n.x+=e.x,n.y+=e.y,[{id:t.id,props:[n]}]}}var go=(l=>(l[l.Resource=0]="Resource",l[l.Template=1]="Template",l))(go||{});class Ks{work(t){const e=t.getSelectNodes();return e.size===0?null:this.copyByIds([...e].map(n=>n.id),t)}copyByIds(t,e){const n=[];if(t.forEach(i=>{const a=e.nodeManager.getNode(i);a&&n.push(a)}),n.length===0)return null;const o=D.rectNode2Rect(e.auxiliaryManager.selectManager.getSelectBounds()),s=[],r=[];for(const i of n){const a=this.makeupPasteDO(i,!0,r);s.push(a)}return s.sort((i,a)=>i.zIndex-a.zIndex),{meta:{docId:e.docState.docId,resourceType:go.Resource},nodes:s,bounds:o,resources:r}}makeupPasteDO(t,e=!1,n){const{id:o,zIndex:s,capInfo:r,type:i}=t.serializeTo(),a={id:o,type:i,zIndex:s,capInfo:r,children:[]};if(this.collectResourceInfo(t,n),e){const u=t.globalPos;a.capInfo.baseProps.x=u.x,a.capInfo.baseProps.y=u.y,t instanceof Ct&&(a.capInfo.lineProps.points=[...t.globalLinePoints])}const c=t.children;if(c.size===0)return a;const h=[],d=e&&t.type===v.Group;for(const u of c)h.push(this.makeupPasteDO(u,d,n));return h.sort((u,f)=>u.zIndex-f.zIndex),a.children=h,a}collectResourceInfo(t,e){if(t.type===v.IMG){const n=t;e.push({type:zn.Image,fileKey:n.imgSrc})}if(t.type===v.SVG){const n=t;n.svgProps.useCode||e.push({type:zn.SVG,fileKey:n.svgUrl})}}}let yo=class{};class ya extends yo{handle(t,e){const n=t.find(o=>o.type===I.Base);n&&(n.x+=e.x,n.y+=e.y)}}let xa=class extends yo{handle(t,e,n){const o=t.find(i=>i.type===I.Connect);if(!o)return;const{start:s,end:r}=o;if(s){const i=n.get(s.objectId);i?s.objectId=i:o.start=null}if(r){const i=n.get(r.objectId);i?r.objectId=i:o.end=null}}};class wa extends yo{handle(t,e){const n=t.find(o=>o.type===I.Line);if(n)for(const o of n.points)o.x+=e.x,o.y+=e.y}}var ma={exports:{}};function Jd(l){throw new Error('Could not dynamically require "'+l+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var Qs={exports:{}};const eu=Gh(Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"})));var Pa;function tu(){return Pa||(Pa=1,function(l,t){(function(e,n){l.exports=n()})(ao,function(){var e=e||function(n,o){var s;if(typeof window<"u"&&window.crypto&&(s=window.crypto),typeof self<"u"&&self.crypto&&(s=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(s=globalThis.crypto),!s&&typeof window<"u"&&window.msCrypto&&(s=window.msCrypto),!s&&typeof ao<"u"&&ao.crypto&&(s=ao.crypto),!s&&typeof Jd=="function")try{s=eu}catch{}var r=function(){if(s){if(typeof s.getRandomValues=="function")try{return s.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof s.randomBytes=="function")try{return s.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},i=Object.create||function(){function w(){}return function(L){var B;return w.prototype=L,B=new w,w.prototype=null,B}}(),a={},c=a.lib={},h=c.Base=function(){return{extend:function(w){var L=i(this);return w&&L.mixIn(w),(!L.hasOwnProperty("init")||this.init===L.init)&&(L.init=function(){L.$super.init.apply(this,arguments)}),L.init.prototype=L,L.$super=this,L},create:function(){var w=this.extend();return w.init.apply(w,arguments),w},init:function(){},mixIn:function(w){for(var L in w)w.hasOwnProperty(L)&&(this[L]=w[L]);w.hasOwnProperty("toString")&&(this.toString=w.toString)},clone:function(){return this.init.prototype.extend(this)}}}(),d=c.WordArray=h.extend({init:function(w,L){w=this.words=w||[],L!=o?this.sigBytes=L:this.sigBytes=w.length*4},toString:function(w){return(w||f).stringify(this)},concat:function(w){var L=this.words,B=w.words,H=this.sigBytes,E=w.sigBytes;if(this.clamp(),H%4)for(var X=0;X<E;X++){var $=B[X>>>2]>>>24-X%4*8&255;L[H+X>>>2]|=$<<24-(H+X)%4*8}else for(var Z=0;Z<E;Z+=4)L[H+Z>>>2]=B[Z>>>2];return this.sigBytes+=E,this},clamp:function(){var w=this.words,L=this.sigBytes;w[L>>>2]&=4294967295<<32-L%4*8,w.length=n.ceil(L/4)},clone:function(){var w=h.clone.call(this);return w.words=this.words.slice(0),w},random:function(w){for(var L=[],B=0;B<w;B+=4)L.push(r());return new d.init(L,w)}}),u=a.enc={},f=u.Hex={stringify:function(w){for(var L=w.words,B=w.sigBytes,H=[],E=0;E<B;E++){var X=L[E>>>2]>>>24-E%4*8&255;H.push((X>>>4).toString(16)),H.push((X&15).toString(16))}return H.join("")},parse:function(w){for(var L=w.length,B=[],H=0;H<L;H+=2)B[H>>>3]|=parseInt(w.substr(H,2),16)<<24-H%8*4;return new d.init(B,L/2)}},g=u.Latin1={stringify:function(w){for(var L=w.words,B=w.sigBytes,H=[],E=0;E<B;E++){var X=L[E>>>2]>>>24-E%4*8&255;H.push(String.fromCharCode(X))}return H.join("")},parse:function(w){for(var L=w.length,B=[],H=0;H<L;H++)B[H>>>2]|=(w.charCodeAt(H)&255)<<24-H%4*8;return new d.init(B,L)}},y=u.Utf8={stringify:function(w){try{return decodeURIComponent(escape(g.stringify(w)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(w){return g.parse(unescape(encodeURIComponent(w)))}},P=c.BufferedBlockAlgorithm=h.extend({reset:function(){this._data=new d.init,this._nDataBytes=0},_append:function(w){typeof w=="string"&&(w=y.parse(w)),this._data.concat(w),this._nDataBytes+=w.sigBytes},_process:function(w){var L,B=this._data,H=B.words,E=B.sigBytes,X=this.blockSize,$=X*4,Z=E/$;w?Z=n.ceil(Z):Z=n.max((Z|0)-this._minBufferSize,0);var se=Z*X,ne=n.min(se*4,E);if(se){for(var ae=0;ae<se;ae+=X)this._doProcessBlock(H,ae);L=H.splice(0,se),B.sigBytes-=ne}return new d.init(L,ne)},clone:function(){var w=h.clone.call(this);return w._data=this._data.clone(),w},_minBufferSize:0});c.Hasher=P.extend({cfg:h.extend(),init:function(w){this.cfg=this.cfg.extend(w),this.reset()},reset:function(){P.reset.call(this),this._doReset()},update:function(w){return this._append(w),this._process(),this},finalize:function(w){w&&this._append(w);var L=this._doFinalize();return L},blockSize:16,_createHelper:function(w){return function(L,B){return new w.init(B).finalize(L)}},_createHmacHelper:function(w){return function(L,B){return new b.HMAC.init(w,B).finalize(L)}}});var b=a.algo={};return a}(Math);return e})}(Qs)),Qs.exports}(function(l,t){(function(e,n){l.exports=n(tu())})(ao,function(e){return function(n){var o=e,s=o.lib,r=s.WordArray,i=s.Hasher,a=o.algo,c=[];(function(){for(var y=0;y<64;y++)c[y]=n.abs(n.sin(y+1))*4294967296|0})();var h=a.MD5=i.extend({_doReset:function(){this._hash=new r.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(y,P){for(var b=0;b<16;b++){var w=P+b,L=y[w];y[w]=(L<<8|L>>>24)&16711935|(L<<24|L>>>8)&4278255360}var B=this._hash.words,H=y[P+0],E=y[P+1],X=y[P+2],$=y[P+3],Z=y[P+4],se=y[P+5],ne=y[P+6],ae=y[P+7],te=y[P+8],ce=y[P+9],pe=y[P+10],Be=y[P+11],Re=y[P+12],Me=y[P+13],Te=y[P+14],fe=y[P+15],O=B[0],G=B[1],j=B[2],_=B[3];O=d(O,G,j,_,H,7,c[0]),_=d(_,O,G,j,E,12,c[1]),j=d(j,_,O,G,X,17,c[2]),G=d(G,j,_,O,$,22,c[3]),O=d(O,G,j,_,Z,7,c[4]),_=d(_,O,G,j,se,12,c[5]),j=d(j,_,O,G,ne,17,c[6]),G=d(G,j,_,O,ae,22,c[7]),O=d(O,G,j,_,te,7,c[8]),_=d(_,O,G,j,ce,12,c[9]),j=d(j,_,O,G,pe,17,c[10]),G=d(G,j,_,O,Be,22,c[11]),O=d(O,G,j,_,Re,7,c[12]),_=d(_,O,G,j,Me,12,c[13]),j=d(j,_,O,G,Te,17,c[14]),G=d(G,j,_,O,fe,22,c[15]),O=u(O,G,j,_,E,5,c[16]),_=u(_,O,G,j,ne,9,c[17]),j=u(j,_,O,G,Be,14,c[18]),G=u(G,j,_,O,H,20,c[19]),O=u(O,G,j,_,se,5,c[20]),_=u(_,O,G,j,pe,9,c[21]),j=u(j,_,O,G,fe,14,c[22]),G=u(G,j,_,O,Z,20,c[23]),O=u(O,G,j,_,ce,5,c[24]),_=u(_,O,G,j,Te,9,c[25]),j=u(j,_,O,G,$,14,c[26]),G=u(G,j,_,O,te,20,c[27]),O=u(O,G,j,_,Me,5,c[28]),_=u(_,O,G,j,X,9,c[29]),j=u(j,_,O,G,ae,14,c[30]),G=u(G,j,_,O,Re,20,c[31]),O=f(O,G,j,_,se,4,c[32]),_=f(_,O,G,j,te,11,c[33]),j=f(j,_,O,G,Be,16,c[34]),G=f(G,j,_,O,Te,23,c[35]),O=f(O,G,j,_,E,4,c[36]),_=f(_,O,G,j,Z,11,c[37]),j=f(j,_,O,G,ae,16,c[38]),G=f(G,j,_,O,pe,23,c[39]),O=f(O,G,j,_,Me,4,c[40]),_=f(_,O,G,j,H,11,c[41]),j=f(j,_,O,G,$,16,c[42]),G=f(G,j,_,O,ne,23,c[43]),O=f(O,G,j,_,ce,4,c[44]),_=f(_,O,G,j,Re,11,c[45]),j=f(j,_,O,G,fe,16,c[46]),G=f(G,j,_,O,X,23,c[47]),O=g(O,G,j,_,H,6,c[48]),_=g(_,O,G,j,ae,10,c[49]),j=g(j,_,O,G,Te,15,c[50]),G=g(G,j,_,O,se,21,c[51]),O=g(O,G,j,_,Re,6,c[52]),_=g(_,O,G,j,$,10,c[53]),j=g(j,_,O,G,pe,15,c[54]),G=g(G,j,_,O,E,21,c[55]),O=g(O,G,j,_,te,6,c[56]),_=g(_,O,G,j,fe,10,c[57]),j=g(j,_,O,G,ne,15,c[58]),G=g(G,j,_,O,Me,21,c[59]),O=g(O,G,j,_,Z,6,c[60]),_=g(_,O,G,j,Be,10,c[61]),j=g(j,_,O,G,X,15,c[62]),G=g(G,j,_,O,ce,21,c[63]),B[0]=B[0]+O|0,B[1]=B[1]+G|0,B[2]=B[2]+j|0,B[3]=B[3]+_|0},_doFinalize:function(){var y=this._data,P=y.words,b=this._nDataBytes*8,w=y.sigBytes*8;P[w>>>5]|=128<<24-w%32;var L=n.floor(b/4294967296),B=b;P[(w+64>>>9<<4)+15]=(L<<8|L>>>24)&16711935|(L<<24|L>>>8)&4278255360,P[(w+64>>>9<<4)+14]=(B<<8|B>>>24)&16711935|(B<<24|B>>>8)&4278255360,y.sigBytes=(P.length+1)*4,this._process();for(var H=this._hash,E=H.words,X=0;X<4;X++){var $=E[X];E[X]=($<<8|$>>>24)&16711935|($<<24|$>>>8)&4278255360}return H},clone:function(){var y=i.clone.call(this);return y._hash=this._hash.clone(),y}});function d(y,P,b,w,L,B,H){var E=y+(P&b|~P&w)+L+H;return(E<<B|E>>>32-B)+P}function u(y,P,b,w,L,B,H){var E=y+(P&w|b&~w)+L+H;return(E<<B|E>>>32-B)+P}function f(y,P,b,w,L,B,H){var E=y+(P^b^w)+L+H;return(E<<B|E>>>32-B)+P}function g(y,P,b,w,L,B,H){var E=y+(b^(P|~w))+L+H;return(E<<B|E>>>32-B)+P}o.MD5=i._createHelper(h),o.HmacMD5=i._createHmacHelper(h)}(Math),e.MD5})})(ma);var nu=ma.exports;const ou=ks(nu);class ve{constructor(){p(this,"prefix","001");p(this,"map",new Map);p(this,"zIndex",0)}setPrefix(t){this.prefix=t}reset(){this.map.clear(),this.zIndex=0}genId(t){const e=(this.map.get(t)||0)+1;return this.map.set(t,e),ve.type2NodePrefix(t)+this.prefix+":"+e}static genImgFileName(t,e){const n="img:"+t+"|"+e;return ou(n).toString()}loadNode(t){this.loadNodeId(t.id)}loadNodeId(t){const e=ve.nodePrefix2Type(t[0]),n=t.split(":");try{const o=parseInt(n[1]),s=this.map.get(e);s!==void 0?s<o&&this.map.set(e,o):this.map.set(e,o)}catch(o){console.error("id错误",o)}}static genZIndex(t){return t.children.size===0?1:[...t.children].sort((n,o)=>o.zIndex-n.zIndex)[0].zIndex+1}static type2NodePrefix(t){switch(t){case v.Shape:return"a";case v.Line:return"c";case v.SVG:return"d";case v.IMG:return"e";case v.Section:return"f";case v.Group:return"g";case v.Checkbox:return"i";case v.CheckboxText:return"j";case v.SlideContainer:return"k";default:return"x"}}static nodePrefix2Type(t){return t==="a"?v.Shape:t==="c"?v.Line:t==="d"?v.SVG:t==="e"?v.IMG:t==="f"?v.Section:t==="g"?v.Group:t==="i"?v.Checkbox:t==="j"?v.CheckboxText:t==="k"?v.SlideContainer:v.Shape}}class ba{work(t,e,n,o){const s=new Map;this.recordIdMap(e,t,s);const r=[],i=[];let a=ve.genZIndex(t.nodeManager.root);for(const h of e){const d=this.convertToAddNodeInfo(t,h,s,n,r,Mn,a,o);a++,i.push(d)}return{addNodeData:{nodes:r},nextFocusIds:i}}convertToAddNodeInfo(t,e,n,o,s,r,i,a){const c=n.get(e.id),h=this.convertToProps(e.capInfo,o,n,a),d={id:c,type:e.type,zIndex:i,parentId:r,props:h};s.push(d);const u=new m;e.type===v.Group&&(u.x=o.x,u.y=o.y);for(const f of e.children)this.convertToAddNodeInfo(t,f,n,u,s,c,f.zIndex,a);return c}convertToProps(t,e,n,o){const s=M.convertCapInfoToProps(t);for(const r of this.propsHandler)r.handle(s,e,n,o);return s}recordIdMap(t,e,n){for(const o of t){const s=e.idGenerator.genId(o.type);n.set(o.id,s);const r=o.children;this.recordIdMap(r,e,n)}}}class Ma extends ba{constructor(){super(...arguments);p(this,"propsHandler",[new ya,new xa,new wa])}}class Zs{constructor(){p(this,"copyWorker",new Ks);p(this,"pasteWorker",new Ma)}work(t,e){var d;const n=this.copyWorker.work(t);if(!n)return;let o;e?o=e:o=new m(20,20);const s=n.nodes,r=JSON.parse(JSON.stringify(s)),{addNodeData:i,nextFocusIds:a}=this.pasteWorker.work(t,r,o),c=[...t.getSelectNodes()];c.length===1&&((d=c[0].parent)==null?void 0:d.type)===v.SlideContainer?(i.nodes[0].parentId=c[0].parent.id,i.nodes[0].zIndex=ve.genZIndex(c[0].parent),t.execAction(new Le(i)),this.handleSlideContainerDuplicate(t,c[0],a[0])):t.execAction(new Le(i)),t.execAction(xe.create(a))}duplicateByIds(t,e,n){var u;const o=this.copyWorker.copyByIds(t,e);if(!o)return;let s;n?s=n:s=new m(20,20);const r=o.nodes,i=JSON.parse(JSON.stringify(r)),{addNodeData:a,nextFocusIds:c}=this.pasteWorker.work(e,i,s),h=[];t.forEach(f=>{const g=e.nodeManager.getNode(f);g&&h.push(g)}),h.length===1&&((u=h[0].parent)==null?void 0:u.type)===v.SlideContainer?(a.nodes[0].parentId=h[0].parent.id,a.nodes[0].zIndex=ve.genZIndex(h[0].parent),e.execAction(new Le(a)),this.handleSlideContainerDuplicate(e,h[0],c[0])):e.execAction(new Le(a)),e.execAction(xe.create(c))}handleSlideContainerDuplicate(t,e,n){const o=e.parent,s=o.slideProps.children,r=this.getNodePosition(o,e.id);if(!r)return;const{rowIndex:i,colIndex:a}=r,c=s.map((g,y)=>{if(y===i){const P=[...g.ids];return P.splice(a+1,0,n),{ids:P}}return{ids:[...g.ids]}}),h=[{id:o.id,props:[Mt.create({children:c})]}],d=c[i],u=t.nodeManager.getNode(e.id);if(u){let g=u.baseProps.x+u.baseProps.width+nt;const y=u.baseProps.y;for(let P=a+1;P<d.ids.length;P++){const b=d.ids[P],w=t.nodeManager.getNode(b);w&&(h.push({id:b,props:[ie.create({x:g,y,width:w.baseProps.width,height:w.baseProps.height})]}),g+=w.baseProps.width+nt)}}t.execAction(new U({infos:h}));const f=[];for(const g of c)for(const y of g.ids){const P=t.nodeManager.getNode(y);P&&f.push(P.baseProps)}if(f.length>0){const g=M.getBoundsByBasePropsList(f),y=g.maxX-g.minX+2*nt,P=g.maxY-g.minY+2*xt;t.execAction(U.create(o.id,[{type:I.Base,width:y,height:P}]))}}getNodePosition(t,e){const n=t.slideProps.children;for(let o=0;o<n.length;o++){const s=n[o];for(let r=0;r<s.ids.length;r++)if(s.ids[r]===e)return{rowIndex:o,colIndex:r}}return null}}class Sa extends Vs{enable(t){return t.type===v.Group}handle(t,e,n){const o=[],s=t.baseProps.clone();s.x+=e.x,s.y+=e.y,o.push({id:t.id,props:[s]});for(const r of t.children)o.push(...n.handle(r,e));return o}handleChangeRelation(t,e,n){if(t.parent===e)return[];if(t.parent.type===v.Group)return[];const o=t.globalPos,s=e.toLocal(o),r=[];r.push({id:t.id,props:[{type:I.Base,x:s.x,y:s.y}],parentId:e.id,zIndex:n});for(const i of t.children)this.handlePosChange(i,e,r);return r}handlePosChange(t,e,n){if(t.type===v.Line){const s=t.globalLinePoints.map(a=>e.toLocal(a)),r=D.rectNode2Rect(M.getBoundsByPoints(s)),i={id:t.id,props:[{type:I.Line,points:s},{type:I.Base,x:r.x,y:r.y,width:r.width,height:r.height}]};n.push(i)}else{const o=t.globalPos,s=e.toLocal(o),r={id:t.id,props:[{type:I.Base,x:s.x,y:s.y}]};n.push(r)}if(t.type===v.Group)for(const o of t.children)this.handlePosChange(o,e,n)}}class va{constructor(t){p(this,"handlers");this.handlers=t}handle(t,e){for(const n of this.handlers)if(n.enable(t))return n.handle(t,e,this);return[]}handleRelation(t,e,n){for(const o of this.handlers)if(o.enable(t))return o.handleChangeRelation(t,e,n);return[]}}class Ia extends ht{constructor(){super(...arguments);p(this,"moveRect",null);p(this,"lastPos",new m(0,0));p(this,"lastMoveRectPos",new m);p(this,"targetNodes",[]);p(this,"alignWorker",new un);p(this,"layoutWorker",new Rn);p(this,"duplicateWorker",new Zs);p(this,"groupBaseWorker",new on);p(this,"handlerCtx",new va([new fa,new Sa,new ga]))}computeMoveNodes(e,n){e.originEvent.altKey&&this.duplicateWorker.work(n,new m);const o=n.getSelectNodes(),s=this.recordNodeMap(o),r=[];for(const i of o)if(i.type===v.Line){const a=i,{start:c,end:h}=a.connectProps;if(c&&h&&s.has(c.objectId)&&s.has(h.objectId)){r.push(i);continue}if(!c&&h&&s.has(h.objectId)){r.push(i);continue}if(!h&&c&&s.has(c.objectId)){r.push(i);continue}!h&&!c&&r.push(i)}else r.push(i);return r}recordNodeMap(e){const n=new Map;for(const o of e)n.set(o.id,o);return n}onStart(e,n){n.actionManager.execAction(new W),this.targetNodes=this.computeMoveNodes(e,n),this.targetNodes.length!==0&&(this.lastPos=e.globalPoint.clone(),this.moveRect=n.auxiliaryManager.selectManager.getSelectBounds(),this.lastMoveRectPos=new m(this.moveRect.minX,this.moveRect.minY),n.inputManager.editTextInfo&&n.execAction(ee.blur(n.inputManager.editTextInfo.node.id)),this.groupBaseWorker.start(this.targetNodes))}onMove(e,n){if(n.auxiliaryManager.removeAlignGraphics(),this.targetNodes.length===0)return;this.moveNode(e,n,!0);const o=this.hoverOnContainer(e,n);o&&n.addOrUpdate(N.HoverContainer,{node:o})}judgeLinkLineRelation(e,n,o){const{start:s,end:r}=e.connectProps;let i=null,a=null;return s&&(i=n.nodeManager.getNode(s.objectId)),r&&(a=n.nodeManager.getNode(r.objectId)),i?!!(!a||o.has(a)):a?!!o.has(a):!1}onUp(e,n){this.targetNodes.length!==0&&(this.moveNode(e,n,!1),this.changeNodesRelation(e,n),n.actionManager.execAction(new z),n.auxiliaryManager.removeAlignGraphics())}changeNodesRelation(e,n){const o=this.hoverOnContainer(e,n)||n.nodeManager.root,s=n.getSelectNodes(),r=new Set;for(const u of s)u.type!==v.SlideContainer&&r.add(u);const i=new Set;for(const u of s)n.nodeManager.getNodeLinks(u).forEach(g=>i.add(g));for(const u of i)this.judgeLinkLineRelation(u,n,s)&&r.add(u);const a=[],c=o.children.size===0?0:Math.max(...[...o.children].map(u=>u.zIndex));let h=1;const d=M.sortGraphics([...r]);for(const u of d){if(u.parent===o)continue;const f=this.handlerCtx.handleRelation(u,o,c+h);a.push(...f),h++}a.length>0&&n.execAction(new U({infos:a}))}moveNode(e,n,o){const s=e.globalPoint,r=!M.pressMeta(e),i=new m(s.x-this.lastPos.x,s.y-this.lastPos.y);this.moveRectChange(this.moveRect,i);const a=this.alignWorker.alignMove(this.moveRect,n.getSelectNodes(),n,r),c=this.alignWorker.drawAlignLines(a,n),h=this.checkAlign(a),d=M.cloneIRectNode(this.moveRect),u={x:0,y:0};if(h){const y=d.minX+c.x,P=d.minY+c.y;u.x=y-this.lastMoveRectPos.x,u.y=P-this.lastMoveRectPos.y,this.lastMoveRectPos.x=y,this.lastMoveRectPos.y=P}else u.x=i.x,u.y=i.y,this.lastMoveRectPos.x+=i.x,this.lastMoveRectPos.y+=i.y;const f=[];for(const y of this.targetNodes){const P=this.handlerCtx.handle(y,u);f.push(...P)}const g=new Set;this.batchCollectNodeLinks(this.targetNodes,n,g),n.execAction(new U({infos:f},{streaming:o})),this.groupBaseWorker.work(n,o),this.layoutWorker.work([...g],n,o),this.lastPos=s}hoverOnContainer(e,n){const o=n.detect(F.HoverOnContainer,e);return o||null}moveRectChange(e,n){e.minX+=n.x,e.maxX+=n.x,e.minY+=n.y,e.maxY+=n.y}checkAlign(e){const{top:n,bottom:o,right:s,left:r,horizonMid:i,verticalMid:a}=e;return n!==void 0||o!==void 0||s!==void 0||r!==void 0||i!==void 0||a!==void 0}batchCollectNodeLinks(e,n,o){const s=n.getSelectNodes();for(const r of e)this.collectNodeLinks(r,n,s,o)}collectNodeLinks(e,n,o,s){const r=n.nodeManager.getNodeLinks(e);for(const i of r)o.has(i)||s.add(i);for(const i of e.children)i.type!==v.Line&&this.collectNodeLinks(i,n,o,s)}}class Ta extends dt{constructor(){super([new Ia])}streamEnable(t,e){if(e.auxiliaryManager.selectManager.selectNodes.size===0)return!1;const o=e.auxiliaryManager.selectManager.getSelectBounds(),s=D.rectNode2Rect(o);if(s.width<.1||s.height<.1){const i=q.line({x:s.x,y:s.y},{x:o.maxX,y:o.maxY}),a=q.circle(t.globalPoint,4/e.gmlRender.getScale());return Y.intersect(i,a).points.length>0}return M.rectContains2(t.globalPoint,o)}}class La{}class su extends La{enable(t){return t.originEvent.metaKey}handle(t,e,n){for(const o of e)M.containRect(t,o.getBounds())&&n.add(o)}drawGroupRect(t,e){t.addOrUpdate(N.SelectGroup,{rect:e,isPrecise:!0})}}class ru extends La{enable(t){return!0}handle(t,e,n){for(const o of e){if(o.type===v.Section||o.type===v.SlideContainer){M.containRect(t,o.getBounds())&&n.add(o);continue}o.overlapRect(t)&&n.add(o)}}drawGroupRect(t,e){t.addOrUpdate(N.SelectGroup,{rect:e})}}class Ca extends ht{constructor(){super(...arguments);p(this,"startPoint",null);p(this,"handlers",[new su,new ru])}onStart(e,n){this.startPoint=e.globalPoint,n.actionManager.execAction(new W),n.inputManager.editTextInfo&&n.execAction(ee.blur(n.inputManager.editTextInfo.node.id)),n.actionManager.execAction(xe.create([]))}onMove(e,n){if(!this.startPoint)return;const o=Math.min(e.globalPoint.x,this.startPoint.x),s=Math.max(e.globalPoint.x,this.startPoint.x),r=Math.min(e.globalPoint.y,this.startPoint.y),i=Math.max(e.globalPoint.y,this.startPoint.y),a={id:"group-rect",minX:o,maxX:s,minY:r,maxY:i},c=D.rectNode2Rect(a),h=n.nodeManager.searchNodes(o,r,s,i),d=new Set;for(const y of this.handlers)if(y.enable(e)){y.handle(a,h,d),y.drawGroupRect(n,c);break}const u=M.computeSelectNodes(d),g=M.filterSlideContainerNodes(n,u).map(y=>y.id);n.actionManager.execAction(xe.create(g))}onUp(e,n){n.actionManager.execAction(new z),n.removeAuxGraphic(N.SelectGroup),this.startPoint=null}}class qs extends dt{constructor(){super([new Ca])}streamEnable(t,e){if(t.originEvent.metaKey)return!0;const n=e.detect(F.Node,t);if(n&&n.length>0&&e.auxiliaryManager.selectManager.include(n[0])&&n[0].contains(t.globalPoint))return!1;const o=e.auxiliaryManager.selectManager.getSelectBounds();return!M.rectContains2(t.globalPoint,o)}}class xo{moveForward(t){const e=t.getSelectNodes();if(e.size===0)return;t.execAction(new W);const n=M.sortGraphics([...e]).reverse();for(const o of n){const s=this.moveNodeForward(o);s&&t.execAction(s)}t.execAction(new z)}moveBackward(t){const e=t.getSelectNodes();if(e.size===0)return;t.execAction(new W);const n=M.sortGraphics([...e]);for(const o of n){const s=this.moveNodeBackward(o);s&&t.execAction(s)}t.execAction(new z)}moveToUp(t){const e=t.getSelectNodes();if(e.size===0)return;const n=new Map;for(const o of e){const s=o.parent,r=n.get(s);r?r.push(o):n.set(s,[o])}t.execAction(new W);for(const[o,s]of n){const r=this.moveNodesToUp(s,o);r&&t.execAction(r)}t.execAction(new z)}moveToBack(t){const e=t.getSelectNodes();if(e.size===0)return;const n=new Map;for(const o of e){const s=o.parent,r=n.get(s);r?r.push(o):n.set(s,[o])}t.execAction(new W);for(const[o,s]of n){const r=this.moveNodesToBack(s,o);r&&t.execAction(r)}t.execAction(new z)}moveNodesToUp(t,e){if(t.length===0)return null;const n=M.sortGraphics(t),o=new Set(t),s=e.children,r=[];for(const d of s)o.has(d)||r.push(d);const i=M.sortGraphics(r),a=i[i.length-1].zIndex,c=[];let h=1;for(const d of n)c.push({id:d.id,zIndex:a+h,props:[]}),h++;return new U({infos:c})}moveNodesToBack(t,e){if(t.length===0)return null;const n=M.sortGraphics(t).reverse(),o=new Set(t),s=e.children,r=[];for(const d of s)o.has(d)||r.push(d);const a=M.sortGraphics(r)[0].zIndex,c=[];let h=1;for(const d of n)c.push({id:d.id,zIndex:a-h,props:[]}),h++;return new U({infos:c})}moveNodeForward(t){const e=t.parent;if(!e)return null;let n=[...e.children];n=M.sortGraphics(n);const o=n.indexOf(t);if(o<0&&console.error("排序时发生错误",o,t.id),o===n.length-1)return null;if(o===n.length-2){const a=n[o+1],c=[{id:t.id,zIndex:a.zIndex+1,props:[]}];return new U({infos:c})}const s=n[o+1],r=n[o+2],i=[{id:t.id,zIndex:.5*(s.zIndex+r.zIndex),props:[]}];return new U({infos:i})}moveNodeBackward(t){const e=t.parent;if(!e)return null;let n=[...e.children];n=M.sortGraphics(n);const o=n.indexOf(t);if(o<0&&console.error("排序时发生错误",o,t.id),o===0)return null;if(o===1){const a=n[o-1],c=[{id:t.id,zIndex:a.zIndex-1,props:[]}];return new U({infos:c})}const s=n[o-1],r=n[o-2],i=[{id:t.id,zIndex:.5*(s.zIndex+r.zIndex),props:[]}];return new U({infos:i})}}const xs=class xs{constructor(){p(this,"offlineCanvas");p(this,"ctx");this.offlineCanvas=document.createElement("canvas"),this.ctx=this.offlineCanvas.getContext("2d")}static getInstance(){return this.instance||(this.instance=new xs),this.instance}getCanvasCtx(){return this.ctx}};p(xs,"instance",null);let Js=xs;class sn{static dealWithAIDocumentInfo(t){if(t.nodes)for(const e of t.nodes)this.dealNodeInfo(e)}static dealNodeInfo(t){sn.dealNodeSizeForFullText(t);const e=t.children;for(const n of e)this.dealNodeInfo(n)}static dealNodeSizeForFullText(t){var e,n;try{if(t.type!==v.Shape||!((e=t.capInfo)!=null&&e.shapeProps)||!t.capInfo.textProps)return;const o=t.capInfo.shapeProps.shapeCode;if(o!==K.Rect&&o!==K.RoundRect){t.capInfo.textProps.sizeMode=We.fix;return}if(!t.capInfo.textProps.text){t.capInfo.textProps.sizeMode=We.fix;return}if(!t.capInfo.baseProps)return;const s=Js.getInstance().getCanvasCtx(),r=new uo,i=new Ge;i.update(((n=t.capInfo)==null?void 0:n.textProps)||{});const a={x:le,y:le,width:t.capInfo.baseProps.width-2*le,height:t.capInfo.baseProps.height-2*le};r.typesetting(s,i,a);const c=r.height+2*le,h=r.width+2*le;t.capInfo.baseProps.height=c,h>t.capInfo.baseProps.width&&(t.capInfo.baseProps.width=h),t.capInfo.textProps.sizeMode=We.fix}catch{console.error("处理失败,忽略node",t)}}static blurText(t){const e=t.inputManager.editTextInfo;e&&t.execAction(ee.blur(e.node.id))}}class er extends qe{constructor(){super(...arguments);p(this,"node",null)}enable(e,n){const o=n.auxiliaryManager.selectManager.getSelectBounds();if(M.rectContains2(e.globalPoint,o)||!e.originEvent.shiftKey)return!1;if(e.originEvent.metaKey){const r=n.detect(F.Node,e);if(r&&r.length>0)return this.node=r[0],!0}const s=n.detect(F.HoverNode,e);return s?(this.node=s,!0):!1}handle(e,n){if(!this.node)return;const s=[...M.computeSelectNode(n,this.node)].map(r=>r.id);n.actionManager.execAction(new W),sn.blurText(n),n.actionManager.execAction(xe.create([...s])),n.actionManager.execAction(new z)}}class Aa extends qe{constructor(){super(...arguments);p(this,"node",null)}enable(e,n){const o=n.auxiliaryManager.selectManager.getSelectBounds();if(n.getSelectNodes().size>1&&M.rectContains2(e.globalPoint,o))return!1;const s=n.detect(F.HoverNode,e);return s?n.auxiliaryManager.selectManager.include(s)||!this.canEnable(s)?!1:(this.node=s,!0):!1}handle(e,n){this.node&&(n.actionManager.execAction(new W),sn.blurText(n),n.actionManager.execAction(xe.create([this.node.id])),n.actionManager.execAction(new z),this.node.type===v.IMG&&n.setCursor("zoom-in"))}}class tr extends Aa{constructor(){super(...arguments);p(this,"node",null)}canEnable(e){return e.type!==v.Section}}class ka extends qe{constructor(){super(...arguments);p(this,"res",null)}enable(e,n){if(n.getSelectNodes().size!==1)return!1;const o=n.detect(F.Node,e);if(o){const s=o[0];if(n.auxiliaryManager.selectManager.include(s)){const r=s.toLocal(e.globalPoint);if(s instanceof vt&&s.renderText.contains(r))return this.res={node:s,relativePos:r},!0;if(s instanceof Ct)return this.res={node:s,relativePos:r},!0;if(s instanceof Un&&s.renderText.contains(r))return this.res={node:s,relativePos:r},!0}}return!1}handle(e,n){if(!this.res)return;const{node:o,relativePos:s}=this.res,r=o.renderText.detect(s);this.shiftTextClick(e,n,r)||(n.execAction(new W),n.execAction(ee.focus(o.id,r)),n.execAction(new z))}shiftTextClick(e,n,o){if(!e.originEvent.shiftKey)return!1;const s=n.inputManager.editTextInfo,{node:r}=this.res;return s&&!n.inputManager.selectionManager.selectionInfo&&!s.textCursorPosition.equal(o)?(n.execAction(new W),n.execAction(ee.selection(r.id,o,s.textCursorPosition)),n.execAction(new z),!0):!1}}class nr extends qe{constructor(){super(...arguments);p(this,"node",null)}enable(e,n){if(!e.originEvent.shiftKey)return!1;const o=n.detect(F.Node,e);if(o){const s=o[0];if(n.auxiliaryManager.selectManager.include(s))return this.node=s,!0}return!1}handle(e,n){if(!this.node)return;const o=n.getSelectNodes(),s=new Set;o.forEach(r=>s.add(r.id)),s.delete(this.node.id),n.actionManager.execAction(new W),sn.blurText(n),n.actionManager.execAction(xe.create([...s])),n.actionManager.execAction(new z)}}class or extends qe{enable(t,e){return!e.detect(F.Node,t)}handle(t,e){if(e.getSelectNodes().size===0){e.slotManager.addSlotState(ze.QuickCreate,{show:!1});return}if(e.execAction(new W),e.inputManager.editTextInfo){const n=e.inputManager.editTextInfo.node;if(e.execAction(ee.blur(e.inputManager.editTextInfo.node.id)),n.type===v.Shape&&n.shapeType===K.PureText&&n.getProp(I.Text)&&n.isEmptyText()){e.execAction(xe.create([])),e.execAction(At.create([n.id])),e.execAction(new z);return}}e.execAction(xe.create([])),e.execAction(new z)}}class Na extends qe{constructor(){super(...arguments);p(this,"res",null);p(this,"layoutWorker",new Rn)}enable(e,n){const o=n.detect(F.ExpandShape,e);return o?(this.res=o,!0):!1}handle(e,n){const{node:o,realHeight:s}=this.res,r={infos:[{id:o.id,props:[{height:s,type:I.Base},{type:I.Text,sizeMode:We.autoHeight}]}]};n.execAction(new W),sn.blurText(n),n.execAction(new U(r));const i=[...n.nodeManager.getNodeLinks(o)];this.layoutWorker.work(i,n,!1),n.execAction(new z)}}class Ba extends Aa{constructor(){super(...arguments);p(this,"node",null)}canEnable(e){return e.type===v.Section}}class iu extends qe{constructor(){super(...arguments);p(this,"node")}enable(e,n){const o=n.detect(F.Image,e);return o?(this.node=o,!0):!1}handle(e,n){const o=this.getFileKey(this.node),s={nodeId:this.node.id,fileKey:o,blobUrl:n.resourceManager.getBlobUrl(o)};n.slotManager.addSlotState(ze.ClickImg,s)}getFileKey(e){return e.type===v.SVG?e.svgUrl:e.type===v.IMG?e.imgSrc:""}}class Ra{checkbox(t,e,n){const o=t.checkStatus;n.execAction(new W),sn.blurText(n),n.execAction(U.create(t.id,[{type:I.CheckStatus,checkStatus:!o}])),t.type===v.CheckboxText&&n.execAction(U.create(t.id,[{type:I.Text,strikethrough:!o}])),n.execAction(new z)}}const au=new Set([v.Checkbox,v.CheckboxText]);class cu extends qe{constructor(){super(...arguments);p(this,"node",null);p(this,"checkboxWorker",new Ra)}enable(e,n){const o=[...n.getSelectNodes()];if(o.length!==1)return!1;const s=o[0];return au.has(s.type)&&s.checkboxContain(e.globalPoint)?(this.node=s,!0):!1}handle(e,n){this.node&&this.checkboxWorker.checkbox(this.node,e,n)}}class lu extends qe{enable(t,e){return!!e.detect(F.SlideGap,t)}handle(t,e){const n=e.detect(F.SlideGap,t);if(!n)return;const{slideContainer:o,i:s,j:r}=n,i=o.slideProps.children,a=i[s];if(!a||!a.ids||a.ids.length===0)return;const c=this.getGlobalIndex(i,s,r>0?r-1:0),h=r>0;e.execAction(new W);const d=e.slideManager.insertSlide(o,c,h,e);d&&e.execAction(xe.create([d.id])),e.execAction(new z)}getGlobalIndex(t,e,n){let o=0;for(let s=0;s<e;s++)o+=t[s].ids.length;return o+n}}var Nn=(l=>(l[l.A4=0]="A4",l[l.S16_9=1]="S16_9",l[l.S4_3=2]="S4_3",l[l.S1_1=3]="S1_1",l))(Nn||{});const Uo={[Nn.A4]:{width:595,height:842},[Nn.S16_9]:{width:860,height:540},[Nn.S4_3]:{width:860,height:720},[Nn.S1_1]:{width:600,height:600}};class hu extends qe{enable(t,e){return!!e.detect(F.EmptySlideContainer,t)}handle(t,e){const n=e.detect(F.EmptySlideContainer,t);if(!n)return;const{slideContainer:o,rect:s}=n;e.execAction(new W);const r=Uo[Nn.S16_9],i=r.width,a=r.height,d=[ie.create({x:nt,y:xt,width:i,height:a}),tt.create({color:"#F4F2F3"}),Ae.create({color:"#C0A9BD"})],u=e.idGenerator.genId(v.Section),f={id:u,type:v.Section,zIndex:ve.genZIndex(o),parentId:o.id,props:d};e.execAction(Le.create(f));const g=[{ids:[u]}],y=[{id:o.id,props:[Mt.create({children:g})]}],P=i+2*nt,b=a+2*xt;y.push({id:o.id,props:[{type:I.Base,width:P,height:b}]}),e.execAction(new U({infos:y})),e.execAction(xe.create([u])),e.execAction(new z)}}class Ea extends jt{constructor(){super(),this.registerDownHandler(new hu),this.registerDownHandler(new lu),this.registerDownHandler(new Na),this.registerDownHandler(new er),this.registerDownHandler(new tr),this.registerUpHandler(new nr),this.registerUpHandler(new Ba),this.registerUpHandler(new ka),this.registerUpHandler(new cu),this.registerUpHandler(new iu),this.registerUpHandler(new or)}}class Ha extends pn{constructor(){super([new Ea])}}class du{}class Da extends du{enable(t){return t.type===v.Line}handle(t,e){e.addOrUpdate(N.HoverLine,{node:t,transform:t.globalTransform()})}}class Oa{enable(t){return!0}handle(t,e){e.addOrUpdate(N.HoverBounds,{node:t,transform:t.globalTransform()})}}class Xa{enable(t){return t.type===v.Group}handle(t,e){const n=t;if(e.auxiliaryManager.selectManager.include(t))return;const o=n.nameGlobalTransform();e.addOrUpdate(N.HoverBounds,{node:t,transform:o})}}class za{enable(t){return t.type===v.Section}handle(t,e){}}class Wa{constructor(){p(this,"allowEventTypeSet",new Set([be.pointermove]));p(this,"handlers",[new Da,new Xa,new za,new Oa])}process(t,e){const n=e.detect(F.EmptySlideContainer,t);if(n){const i=n.slideContainer,a=n.rect;e.addOrUpdate(N.HoverSlideGapInsertPoint,{point:{x:i.globalBaseProps.x+i.globalBaseProps.width/2,y:i.globalBaseProps.y+i.globalBaseProps.height/2}});const c=ie.create({x:a.x,y:a.y,width:a.width,height:a.height});e.addOrUpdate(N.HoverSlidePlaceHolder,{baseProps:c});return}const o=e.detect(F.SlideGap,t);if(o){e.addOrUpdate(N.HoverSlideGapInsertPoint,{point:o.point});return}const s=e.detect(F.HoverConnectAnchor,t);if(s){s.node.type===v.Shape&&e.previewManager.quickCreateManager.enterQuickPreview(s.node,s.relative,e),e.addOrUpdate(N.HoverConnectAnchor,{point:s.globalPoint});return}e.previewManager.quickCreateManager.exitQuickPreview(e),this.hoverSizer(t,e);const r=e.detect(F.HoverNode,t);if(r){for(const i of this.handlers)if(i.enable(r)){i.handle(r,e);return}}}hoverSizer(t,e){const n=e.detect(F.Stretch,t);if(!n)return;const o=n.nodes,s=o[0];if(n.type===V.BOTTOM_RIGHT)if(o.length===1)e.addOrUpdate(N.HoverSize,{rect:D.baseProps2Rect(s.baseProps),transform:s.globalTransform().clone()});else{const r=e.auxiliaryManager.selectManager.getSelectBounds();e.addOrUpdate(N.HoverSize,{rect:D.rectNode2Rect(r),transform:re.generateMatrix().translate(r.minX,r.minY)})}}}var ye=(l=>(l[l.DEFAULT=0]="DEFAULT",l[l.TEXT=1]="TEXT",l[l.SHAPE=2]="SHAPE",l[l.LINE=3]="LINE",l[l.SECTION=4]="SECTION",l[l.STICKY=5]="STICKY",l[l.HandTool=6]="HandTool",l[l.Resource=7]="Resource",l[l.Widget=8]="Widget",l[l.SlideContainer=9]="SlideContainer",l))(ye||{});class Fa{constructor(t,e,n,o){p(this,"nodeManager");p(this,"inputManager");p(this,"slotManager");p(this,"cursorManager");p(this,"currentTool",ye.DEFAULT);p(this,"shapeType",0);p(this,"grab",!1);p(this,"creatingLine",null);this.nodeManager=t,this.inputManager=e,this.slotManager=n,this.cursorManager=o}setCurrentTool(t,e=0,n=!1){this.currentTool=t,this.shapeType=e,this.grab=n,this.slotManager.addSlotState(ze.ToolChange,{tool:t,shapeType:e}),t===ye.DEFAULT&&this.cursorManager.setCursor("default")}resetTool(){this.creatingLine||this.setCurrentTool(ye.DEFAULT)}setInCreatingLine(t){this.creatingLine=t}}var _n=(l=>(l[l.Checkbox=0]="Checkbox",l[l.CheckboxText=1]="CheckboxText",l))(_n||{});class gt{}class Ya extends gt{constructor(){super(...arguments);p(this,"cursorMap",new Map([[ye.SHAPE,"crosshair"],[ye.SECTION,"crosshair"],[ye.TEXT,"text"],[ye.LINE,"crosshair"]]))}enable(e,n){return this.cursorMap.has(n.toolManager.currentTool)}handle(e,n){if(n.toolManager.grab){n.setCursor("grabbing");return}const o=this.cursorMap.get(n.toolManager.currentTool);n.setCursor(o)}}class uu extends gt{enable(t,e){return!!e.detect(F.ExpandShape,t)}handle(t,e){e.setCursor("pointer")}}class pu extends gt{enable(t,e){const n=e.inputManager.editTextInfo;if(!n)return!1;const{node:o}=n,s=o.getTextContentRect(),r=o.toLocal(t.globalPoint);return!!M.rectContains(r,s)}handle(t,e){e.setCursor("text")}}class Ga extends gt{enable(t,e){const n=e.detect(F.Stretch,t);return n?n.nodes.filter(s=>M.judgeNodeCanBeStretch(s)).length>0:!1}handle(t,e){const n=e.detect(F.Stretch,t);e.setCursor("stretch",n.angle)}}class fu extends gt{enable(t,e){return!!e.detect(F.HoverNode,t)}handle(t,e){e.setCursor("default")}}class sr extends gt{enable(t,e){return!0}handle(t,e){e.setCursor("default")}}class _o{constructor(){p(this,"allowEventTypeSet",new Set([be.pointermove]))}process(t,e){for(const n of this.handlers)if(n.enable(t,e)){n.handle(t,e);return}}}class gu extends gt{enable(t,e){return!!e.detect(F.LineEndPoint,t)}handle(t,e){e.setCursor("move")}}class yu extends gt{constructor(){super(...arguments);p(this,"res",null)}enable(e,n){const o=n.detect(F.PolyControlPoint,e);return o?(this.res=o,!0):!1}handle(e,n){if(!this.res)return;const{isHorizon:o}=this.res;o?n.setCursor("ns-resize"):n.setCursor("ew-resize")}}class xu extends gt{enable(t,e){return!!e.detect(F.Rotate,t)}handle(t,e){const n=e.detect(F.Rotate,t);e.setCursor("rotate",n.cursorAngle)}}class wu extends gt{enable(t,e){return!!e.detect(F.Image,t)}handle(t,e){e.setCursor("zoom-in")}}class mu extends gt{constructor(){super(...arguments);p(this,"res",null)}enable(e,n){const o=n.detect(F.CurveControlPoint,e);return o?(this.res=o,!0):!1}handle(e,n){this.res&&n.setCursor("move")}}class Pu extends gt{constructor(){super(...arguments);p(this,"res",null)}enable(e,n){const o=n.detect(F.CurveEndPoint,e);return o?(this.res=o,!0):!1}handle(e,n){this.res&&n.setCursor("move")}}class bu extends gt{constructor(){super(...arguments);p(this,"res",null)}enable(e,n){const o=n.detect(F.DragLineText,e);return o?(this.res=o,!0):!1}handle(e,n){this.res&&n.setCursor("move")}}class Mu extends gt{enable(t,e){var o;const n=e.detect(F.HoverNode,t);return n?!!(((o=n.parent)==null?void 0:o.type)===v.SlideContainer&&e.auxiliaryManager.selectManager.include(n)):!1}handle(t,e){e.setCursor("move")}}class Su extends gt{enable(t,e){return!!e.detect(F.SlideGap,t)}handle(t,e){e.setCursor("pointer")}}class Ua extends _o{constructor(){super(...arguments);p(this,"handlers",[new Ya,new yu,new Pu,new mu,new bu,new uu,new gu,new pu,new Ga,new xu,new Su,new Mu,new fu,new wu,new sr])}}class _a extends Ot{constructor(){super([new Wa,new Ua])}canBeEnable(t,e){return!0}canBeExit(t,e){return!0}}class vu extends gn{enable(t){return t.type===v.Line}handle(t,e,n,o,s){const i=t.parent.globalTransform().inverseMatrix().crossProduct(s),a=[];for(const h of e.points){const d=i.crossPoint(h);a.push(d)}const c=D.rectNode2Rect(M.getBoundsByPoints(a));return[{id:t.id,props:[{type:I.Line,points:a},{type:I.Base,x:c.x,y:c.y,width:c.width,height:c.height}]}]}}class Iu extends gn{enable(t){return t.type===v.SlideContainer}handle(t,e,n,o,s){return[]}}class $a extends Go{constructor(){super(...arguments);p(this,"handlers",[new vu,new ha,new da,new Iu,new la])}computeOriginTransform(e){const n=this.target,{x:o,y:s}=this.originStretchRect,r=re.generateMatrix().translate(-o,-s),i=this.computeAnchorPoint(n,this.originStretchRect),c=re.generateMatrix().translate(-i.x,-i.y).crossProduct(r);this.originTransform=c}recordPropsMap(e){this.propsMap.clear();for(const n of this.target.nodes){const o=this.recordNodePropInfo(n);if(n.type===v.Line){const r=n.globalLinePoints.map(i=>this.originTransform.crossPoint(i));o.points=r}this.propsMap.set(n,o)}}drawAlignLine(e,n,o){const s=o.auxiliaryManager.selectManager.getSelectBounds(),r=D.rectNode2Rect(s),i=re.generateMatrix().translate(s.minX,s.minY),{width:a,height:c}=n;if(a){e.width+=a.dt;const h={transform:i,line:{start:new m(0,r.height),end:new m(r.width,r.height)}};a.lines.push(h)}if(c){e.height+=c.dt;const h={transform:i,line:{start:new m(r.width,0),end:new m(r.width,r.height)}};c.lines.push(h)}o.addOrUpdate(N.AlignStretchLine,{alignInfo:n})}getMiniSize(e){const n=[],o=[],{width:s,height:r}=this.originStretchRect,i=this.target.nodes;if([...i].filter(d=>d.type===v.Line).length===i.length)return{x:10,y:10};for(const d of i){if(d.type===v.Line)continue;const u=d.getStretchMinSize();n.push(u.x/s),o.push(u.y/r)}const c=Math.max(...n),h=Math.max(...o);return{x:c*s,y:h*r}}getStretchRect(e){const n=e.auxiliaryManager.selectManager.getSelectBounds();return D.rectNode2Rect(n)}}class ja extends kn{constructor(){super([new $a])}streamEnable(t,e){if(e.getSelectNodes().size===0)return!1;const n=e.detect(F.Stretch,t);if(!n)return!1;const o=n.nodes,s=o.filter(r=>M.judgeNodeCanBeStretch(r));return o.length>1&&s.length>0}}class rr{}class Tu extends rr{constructor(){super(...arguments);p(this,"polylineHandler",new Vt)}enable(e){return e.isPolyLine()}handleMove(e,n,o){const{line:s}=n,r=this.handle(e,n,o),i=M.dealWithEndPolyPoints(r,o.gmlRender.getScale(),!n.isStart),a=s.globalTransform().inverseMatrix(),c=i.map(u=>a.crossPoint(u)),h=D.rectNode2Rect(M.getBoundsByPoints(c));return{id:s.id,props:[{type:I.Line,points:c},ie.create({x:h.x,y:h.y,width:h.width,height:h.height})]}}handleUp(e,n,o,s){const{line:r}=n,i=this.handle(e,n,o),a=M.dealWithEndPolyPointsInUp(i,o.gmlRender.getScale(),!n.isStart),c=r.globalTransform().inverseMatrix(),h=a.map(f=>c.crossPoint(f)),d=D.rectNode2Rect(M.getBoundsByPoints(h));return{id:r.id,props:[{type:I.Line,points:h},ie.create({x:d.x,y:d.y,width:d.width,height:d.height}),s]}}handle(e,n,o){const{line:s}=n,r=s.lineProps;let i=[];return r.auto?i=this.autoLayoutLine(e,n,o):i=this.editLine(e,n,o),i}autoLayoutLine(e,n,o){const{line:s,isStart:r}=n,i=s.connectProps;if(r){const a=e,c=Ze.computeConnectInfo(s,i.end,o,!0);return this.polylineHandler.layoutToPointsPro(a,c)}else{const a=e,c=Ze.computeConnectInfo(s,i.start,o,!1);return this.polylineHandler.layoutToPointsPro(c,a)}}editLine(e,n,o){const{line:s,isStart:r}=n,i=[...s.globalLinePoints];if(i.length===2)return this.autoLayoutLine(e,n,o);const a=e.point;if(r){const c=i[0],h=i[1],d=M.judgeHorizon(c,h);if(i.length>3){const u=i[2];M.distance(h,u)<3&&(d?Math.abs(a.y-u.y)<6:Math.abs(a.x-u.x)<6)&&(d?a.y=u.y:a.x=u.x)}c.x=a.x,c.y=a.y,d?h.y=c.y:h.x=c.x}else{const c=i[i.length-2],h=i[i.length-1],d=M.judgeHorizon(c,h);if(i.length>3){const u=i[i.length-3];M.distance(c,u)<3&&(d?Math.abs(a.y-u.y)<6:Math.abs(a.x-u.x)<6)&&(d?a.y=u.y:a.x=u.x)}h.x=a.x,h.y=a.y,d?c.y=h.y:c.x=h.x}return i}}class Lu extends rr{enable(t){return t.shapeType===de.Line}handle(t,e,n){const{line:o,isStart:s}=e,r=[...o.globalLinePoints];return s?(r.shift(),r.unshift(t.point)):(r.pop(),r.push(t.point)),r}handleMove(t,e,n){const{line:o}=e,s=this.handle(t,e,n),r=o.globalTransform().inverseMatrix(),i=s.map(c=>r.crossPoint(c)),a=D.rectNode2Rect(M.getBoundsByPoints(i));return{id:o.id,props:[{type:I.Line,points:i},ie.create({x:a.x,y:a.y,width:a.width,height:a.height})]}}handleUp(t,e,n,o){const{line:s}=e,r=this.handle(t,e,n),i=s.globalTransform().inverseMatrix(),a=r.map(h=>i.crossPoint(h)),c=D.rectNode2Rect(M.getBoundsByPoints(a));return{id:s.id,props:[{type:I.Line,points:a},ie.create({x:c.x,y:c.y,width:c.width,height:c.height}),o]}}}class Cu extends rr{constructor(){super(...arguments);p(this,"bezierWorker",new zo)}enable(e){return e.shapeType===de.Curve}handle(e,n,o){const{line:s,isStart:r}=n,i=[...s.globalLinePoints],{start:a,end:c}=s.connectProps;if(r){i.shift(),i.unshift(e.point);let h;e.endTypeInfo&&(h=this.bezierWorker.computeConnectEndInfo(e.endTypeInfo,o.nodeManager));const d=this.bezierWorker.computeConnectEndInfo(c,o.nodeManager);return this.bezierWorker.computeCurvePoints(i,h,d)}else{i.pop(),i.push(e.point);let h;e.endTypeInfo&&(h=this.bezierWorker.computeConnectEndInfo(e.endTypeInfo,o.nodeManager));const d=this.bezierWorker.computeConnectEndInfo(a,o.nodeManager);return this.bezierWorker.computeCurvePoints(i,d,h)}}handleMove(e,n,o){const{line:s}=n,r=this.handle(e,n,o),i=s.globalTransform().inverseMatrix(),a=r.map(h=>i.crossPoint(h)),c=D.rectNode2Rect(M.getBoundsByPoints(a));return{id:s.id,props:[{type:I.Line,points:a},ie.create({x:c.x,y:c.y,width:c.width,height:c.height})]}}handleUp(e,n,o,s){const{line:r}=n,i=this.handle(e,n,o),a=r.globalTransform().inverseMatrix(),c=i.map(d=>a.crossPoint(d)),h=D.rectNode2Rect(M.getBoundsByPoints(c));return{id:r.id,props:[{type:I.Line,points:c},ie.create({x:h.x,y:h.y,width:h.width,height:h.height}),s]}}}class $n{constructor(){p(this,"t",.5)}init(t){if(t.renderText.isEmptyText())return;const e=t.getLineLength(),n=t.points,{point:o}=t.lineTextRect,s=t.baseProps,r=new m(o.x+s.x,o.y+s.y);if(t.shapeType===de.Line){const i=M.distance(n[0],r);this.t=i/e;return}if(t.isPolyLine()){let i=0;for(let a=0;a<n.length;a++){const c=n[a],h=n[a+1],d=q.circle(r,1),u=q.line(c,h);if(Y.intersect(d,u).points.length>0){const g=M.distance(r,c);this.t=(g+i)/e;return}i+=M.distance(c,h)}return}if(t.shapeType===de.Curve){const i=M.computeBezierCurves(t);let a=0;for(let c=0;c<i.length;c++){const h=i[c],d=q.circle(r,1),{p0:u,p1:f,p2:g,p3:y}=h,P=q.cubicBezier(u,f,g,y),b=Y.intersect(d,P),w=h.getApproximateLength();if(b.points.length>0){const L=h.getTValueByPoint(r);this.t=(L*w+a)/e;return}a+=w}}}work(t,e,n){if(t.renderText.isEmptyText())return;const{width:o,height:s}=t.lineTextRect,r=M.computePointByT(t,this.t),i=t.baseProps,a=new m(r.x-i.x,r.y-i.y);e.execAction(U.create(t.id,[{type:I.LineTextRect,point:a,x:a.x-.5*o,y:a.y-.5*s}],{streaming:n}))}}class Va extends ht{constructor(){super(...arguments);p(this,"res",null);p(this,"connectEndProp");p(this,"alignWorker",new un);p(this,"groupBaseWorker",new on);p(this,"lineTextWorker",new $n);p(this,"handlers",[new Tu,new Cu,new Lu]);p(this,"currentHandler",null)}selectHandler(){const{line:e,isStart:n}=this.res;for(const o of this.handlers)o.enable(e)&&(this.currentHandler=o)}computeConnectProp(e,n){const o=n.detect(F.LineEndPoint,e);if(!o)return;this.res=o;const s=o.line.connectProps;if(o.isStart){const r=Ze.computeConnectInfo(o.line,s.end,n,!0);this.connectEndProp={isStart:!1,connectInfo:r}}}onStart(e,n){this.computeConnectProp(e,n),this.selectHandler(),n.execAction(new W),this.removeConnectInfoAndSendMsg(e,n),this.groupBaseWorker.start([this.res.line]),this.lineTextWorker.init(this.res.line)}onMove(e,n){if(!this.res)return;const o=this.getConnectInfo(e,n),s=this.currentHandler.handleMove(o,this.res,n);n.execAction(new U({infos:[s]},{streaming:!0})),this.lineTextWorker.work(this.res.line,n,!0),this.groupBaseWorker.work(n,!0)}onUp(e,n){if(!this.res)return;const o=this.addConnectInfoAndSendMsg(e,n),s=this.getConnectInfo(e,n),r=this.currentHandler.handleUp(s,this.res,n,o);n.execAction(new U({infos:[r]},{streaming:!1})),this.lineTextWorker.work(this.res.line,n,!1),this.groupBaseWorker.work(n,!1),n.execAction(new z)}getConnectInfo(e,n){const o=this.res.line,s=this.res.isStart,r=M.dealWithShiftLineInteractEvent(e,o,!s),i=!M.pressMeta(e),c={point:this.alignWorker.alignLineEndAndDrawAlignLines(r,n,n.getSelectNodes(),i)},h=n.detect(F.NodeEdge,r);return h&&(c.point=new m(h.point.x,h.point.y),c.nodeConnect={rect:D.rectNode2Rect(h.node.getBounds()),endType:M.computeNodeConnectEnd(h.relativePos,h.node.baseProps.angle)},c.endTypeInfo=this.computeEndType(e,n)||void 0),c}computeEndType(e,n){const o=n.detect(F.NodeEdge,e);return o?{objectId:o.node.id,x:o.relativePos.x,y:o.relativePos.y}:null}addConnectInfoAndSendMsg(e,n){const{line:o,isStart:s}=this.res,r=o.connectProps.clone(),i=s?"start":"end",a=this.computeEndType(e,n);return a?r[i]=a:r[i]=null,r}removeConnectInfoAndSendMsg(e,n){const{line:o,isStart:s}=this.res,r=o.connectProps.clone(),i=s?"start":"end";r[i]=null;const a={id:o.id,props:[r]};n.execAction(new U({infos:[a]}))}}class $o{constructor(){p(this,"allowEventTypeSet",new Set([be.pointermove]))}process(t,e){const n=e.detect(F.BufferNode,t);if(!n)return;const o=n.filter(s=>s.canBeConnected());o.length!==0&&(e.auxiliaryManager.selectManager.include(o[0])||o[0].canBeConnected()&&e.addOrUpdate(N.HoverConnectAnchorPoint,{node:o[0]}))}}class jo{constructor(){p(this,"allowEventTypeSet",new Set([be.pointermove]))}process(t,e){const n=e.detect(F.HoverConnectAnchor,t);if(n){e.addOrUpdate(N.HoverConnectAnchor,{point:n.globalPoint});return}const o=e.detect(F.HoverNodeAnchor,t);o&&e.addOrUpdate(N.HoverAnchorPoint,{node:o.node,localPoint:o.localPoint})}}class Vo{constructor(){p(this,"allowEventTypeSet",new Set([be.pointermove]))}process(t,e){if(e.toolManager.currentTool!==ye.LINE)return;const o=e.detect(F.NodeEdge,t);o&&e.addOrUpdate(N.HoverConnectPoint,{point:o.point})}}class Au extends dt{constructor(){super([new Va],[new $o,new jo,new Vo])}streamEnable(t,e){return!!e.detect(F.LineEndPoint,t)}}class Ko{setPointValue(t,e,n,o){t?(e.y=o.y,n.y=o.y):(e.x=o.x,n.x=o.x)}}class ku extends Ko{enable(t){const{rIndex:e,lIndex:n,line:o}=t,s=[...o.points];return n>0&&e<s.length-1}handle(t,e,n){const{rIndex:o,lIndex:s,line:r,isHorizon:i}=t,a=[...r.points],c=r.toLocal(e.globalPoint),h=a[s],d=a[o],u=a[o+1],f=a[s-1],g=n.gmlRender.getScale();return M.distance(f,h)<3/g&&(i?Math.abs(c.y-f.y)<6/g:Math.abs(c.x-f.x)<6/g)?i?c.y=f.y:c.x=f.x:M.distance(d,u)<3/g&&(i?Math.abs(c.y-u.y)<6/g:Math.abs(c.x-u.x)<6/g)&&(i?c.y=u.y:c.x=u.x),this.setPointValue(i,h,d,c),a}setPointValue(t,e,n,o){t?(e.y=o.y,n.y=o.y):(e.x=o.x,n.x=o.x)}}class Nu extends Ko{enable(t){const{rIndex:e,lIndex:n,line:o}=t,s=[...o.points];return n===0&&e===1&&s.length===2}handle(t,e){const{rIndex:n,lIndex:o,line:s,isHorizon:r}=t,i=[...s.points],{start:a,end:c}=s.connectProps,h=i[o],d=i[n],u=s.toLocal(e.globalPoint);if(!a&&!c)return this.setPointValue(r,h,d,u),i;if(c&&!a){if(r){const P=d.x>h.x?1:-1,b=new m(d.x-P*A,d.y),w=new m(d.x-P*A,u.y);return i.splice(o+1,0,b,w),t.lIndex=o+2,t.rIndex=n+2,i}const f=d.y>h.y?1:-1,g=new m(d.x,d.y-f*A),y=new m(u.x,d.y-f*A);return i.splice(o+1,0,g,y),t.lIndex=o+2,t.rIndex=n+2,i}if(a&&!c){if(r){const P=d.x>h.x?1:-1,b=new m(h.x+P*A,h.y),w=new m(h.x+P*A,u.y);return i.splice(o+1,0,b,w),t.lIndex=o+2,t.rIndex=n+2,i}const f=d.y>h.y?1:-1,g=new m(h.x,h.y-f*A),y=new m(u.x,h.y-f*A);return i.splice(o+1,0,g,y),t.lIndex=o+2,t.rIndex=n+2,i}if(a&&c){if(r){const w=d.x>h.x?1:-1,L=new m(h.x+w*A,h.y),B=new m(h.x+w*A,u.y),H=new m(d.x-w*A,d.y),E=new m(d.x-w*A,u.y);return i.splice(o+1,0,L,B,H,E),t.lIndex=o+4,t.rIndex=n+4,i}const f=d.y>h.y?1:-1,g=new m(h.x,h.y-f*A),y=new m(u.x,h.y-f*A),P=new m(d.x,d.y-f*A),b=new m(u.x,d.y-f*A);return i.splice(o+1,0,g,y,P,b),t.lIndex=o+4,t.rIndex=n+4,i}return[]}}class Bu extends Ko{enable(t){const{lIndex:e}=t;return e===0}handle(t,e){const{rIndex:n,lIndex:o,line:s,isHorizon:r}=t,i=[...s.points],{start:a,end:c}=s.connectProps,h=i[o],d=i[n],u=s.toLocal(e.globalPoint);if(!a)return this.setPointValue(r,h,d,u),i;if(r){const P=d.x>h.x?1:-1,b=new m(h.x+P*A,h.y),w=new m(h.x+P*A,u.y);return i.splice(o+1,0,b,w),t.lIndex=o+2,t.rIndex=n+2,i}const f=d.y<h.y?1:-1,g=new m(h.x,h.y-f*A),y=new m(u.x,h.y-f*A);return i.splice(o+1,0,g,y),t.lIndex=o+2,t.rIndex=n+2,i}}class Ru extends Ko{enable(t){const{rIndex:e,line:n}=t;return e===n.points.length-1}handle(t,e){const{rIndex:n,lIndex:o,line:s,isHorizon:r}=t,i=[...s.points],{end:a}=s.connectProps,c=i[o],h=i[n],d=s.toLocal(e.globalPoint);if(!a)return this.setPointValue(r,c,h,d),i;if(r){const y=h.x<c.x?1:-1,P=new m(h.x+y*A,h.y),b=new m(h.x+y*A,d.y);return i.splice(o+1,0,b,P),c.y=d.y,i}const u=h.y>c.y?1:-1,f=new m(h.x,h.y-u*A),g=new m(d.x,h.y-u*A);return i.splice(o+1,0,g,f),c.x=d.x,i}}class Eu extends ht{constructor(){super(...arguments);p(this,"res");p(this,"handlers",[new ku,new Nu,new Bu,new Ru]);p(this,"lineTextWorker",new $n)}onStart(e,n){this.res=n.detect(F.PolyControlPoint,e),n.execAction(new W),this.lineTextWorker.init(this.res.line)}onMove(e,n){const{line:o}=this.res,s=this.computeLinePoints(e,n),r=D.rectNode2Rect(M.getBoundsByPoints(s)),i={infos:[{id:o.id,props:[{type:I.Line,points:s,auto:!1},ie.create({x:r.x,y:r.y,width:r.width,height:r.height})]}]};n.execAction(new U(i,{streaming:!0})),this.lineTextWorker.work(this.res.line,n,!0)}onUp(e,n){const{line:o}=this.res,s=n.gmlRender.getScale(),r=this.computeLinePoints(e,n),i=M.dealWithPolyPoints(r,s),a=D.rectNode2Rect(M.getBoundsByPoints(i)),c={infos:[{id:o.id,props:[{type:I.Line,points:i,auto:!1},ie.create({x:a.x,y:a.y,width:a.width,height:a.height})]}]};n.execAction(new U(c,{streaming:!1})),this.lineTextWorker.work(this.res.line,n,!1),n.execAction(new z)}computeLinePoints(e,n){for(const o of this.handlers)if(o.enable(this.res))return o.handle(this.res,e,n);return[]}}class Hu extends dt{constructor(){super([new Eu],[])}streamEnable(t,e){return!!e.detect(F.PolyControlPoint,t)}}class Du extends ht{constructor(){super(...arguments);p(this,"startConnectInfo",{point:new m});p(this,"target",null);p(this,"layoutHandler",new Vt);p(this,"alignWorker",new un)}onStart(e,n){this.startConnectInfo.point=e.globalPoint;const s=[new Oe(de.RoundPolyLine)],{node:r,relative:i}=n.detect(F.HoverConnectAnchor,e),a={type:I.Connect,start:{objectId:r.id,x:i.x,y:i.y}};s.push(a);const c=Ze.getNodePos(r,i);this.startConnectInfo={point:new m(c.x,c.y),nodeConnect:{rect:D.rectNode2Rect(r.getBounds()),endType:M.computeNodeConnectEnd(i,r.baseProps.angle)}};const h={point:e.globalPoint.clone()},d=this.layoutHandler.layoutToPointsPro(this.startConnectInfo,h),u=je.create(d),f=D.rectNode2Rect(M.getBoundsByPoints(d)),g=ie.create({x:f.x,y:f.y,width:f.width,height:f.height});s.push(u,g,new Ae,lt.create({rArrow:it.Arrow}),Ge.create({sizeMode:We.autoWidth}),new Et);const y=n.idGenerator.genId(v.Line),P={id:y,type:v.Line,zIndex:ve.genZIndex(n.nodeManager.root),parentId:"",props:s};n.actionManager.execAction(new W);const b=Le.create(P);n.actionManager.execAction(b),this.target=n.nodeManager.nodeMap.get(y),n.actionManager.execAction(xe.create([this.target.id])),n.setCursor("crosshair")}onMove(e,n){const o=M.dealWithShiftLineInteractEvent(e,this.target),s=Ze.computeLinePoints(this.startConnectInfo,this.layoutHandler,o,n,this.alignWorker),r=M.dealWithEndPolyPoints(s,n.gmlRender.getScale(),!0),i=D.rectNode2Rect(M.getBoundsByPoints(r)),a=[je.create(r),ie.create({x:i.x,y:i.y,width:i.width,height:i.height})],c={infos:[{id:this.target.id,props:a}]};n.actionManager.execAction(new U(c,{streaming:!0}))}onUp(e,n){const o=M.dealWithShiftLineInteractEvent(e,this.target),s=[],r=n.detect(F.NodeEdge,o);if(r){const d=this.target.connectProps.clone();d.end={objectId:r.node.id,x:r.relativePos.x,y:r.relativePos.y},s.push(d)}const i=Ze.computeLinePoints(this.startConnectInfo,this.layoutHandler,o,n,this.alignWorker),a=M.dealWithEndPolyPointsInUp(i,n.gmlRender.getScale(),!0),c=D.rectNode2Rect(M.getBoundsByPoints(a));s.push(je.create(a),ie.create({x:c.x,y:c.y,width:c.width,height:c.height}));const h={infos:[{id:this.target.id,props:s}]};if(n.actionManager.execAction(new U(h,{streaming:!1})),!r){n.execAction(xe.create([]));const d={clientPoint:o.clientPoint,show:!0,lineId:this.target.id};n.slotManager.addSlotState(ze.QuickCreate,d)}n.execAction(new z),n.setCursor("default")}}class Ou extends dt{constructor(){super([new Du],[new $o,new jo,new Vo])}streamEnable(t,e){return!!e.detect(F.HoverConnectAnchor,t)}}class ir{}const Xu=new Set([v.Shape,v.SVG,v.IMG]);class zu extends ir{enable(t){return Xu.has(t.type)}handle(t,e,n,o){const s=t.baseProps,r=new m(0,0),i=t.toGlobal(r),a=e.crossPoint(i),h=t.parent.globalTransform().inverseMatrix().crossPoint(a);o.push({id:t.id,props:[{type:I.Base,x:h.x,y:h.y,angle:s.angle+n}]})}}class Wu extends ir{enable(t){return t.type===v.Line}handle(t,e,n,o){const{start:s,end:r}=t.connectProps;if(s||r)return;const i=t.lineProps,a=[],c=[];for(const u of i.points){const f=e.crossPoint(u);a.push(f)}c.push({type:I.Line,points:a});const h=M.getBoundsByPoints(a),d={type:I.Base,x:h.minX,y:h.minY,width:h.maxX-h.minX,height:h.maxY-h.minY};c.push(d),o.push({id:t.id,props:c})}}class Fu extends ir{constructor(){super(...arguments);p(this,"layoutHandler",new Vt)}enable(e){return e.type!==v.Line?!1:e.isPolyLine()}handle(e,n,o,s){const{start:r,end:i}=e.connectProps;if(r||i)return;const a=e.lineProps,c=[],h=a.points[0],d=a.points[a.points.length-1],u=n.crossPoint(h),f=n.crossPoint(d),g=this.layoutHandler.layoutToPointsPro({point:u},{point:f});c.push({type:I.Line,points:g});const y=M.getBoundsByPoints(g),P={type:I.Base,x:y.minX,y:y.minY,width:y.maxX-y.minX,height:y.maxY-y.minY};c.push(P),s.push({id:e.id,props:c})}}class Ka extends ht{constructor(){super(...arguments);p(this,"rotateInfo",null);p(this,"lastAngle",0);p(this,"originAngle",0);p(this,"originNodeAngle",0);p(this,"matrix",re.generateMatrix());p(this,"reverseMatrix",re.generateMatrix());p(this,"layoutWorker",new Rn);p(this,"groupBaseWorker",new on);p(this,"handlers",[new zu,new Fu,new Wu])}onStart(e,n){this.rotateInfo=n.detect(F.Rotate,e);const o=Ze.trimPoint(e.globalPoint),s=this.rotateInfo.rotateCenter,r=this.rotateInfo.nodes;r.length===1?this.originNodeAngle=r[0].baseProps.angle:this.originNodeAngle=0,this.lastAngle=Ze.calculateAngle(s,o),this.originAngle=this.lastAngle;const i=re.generateMatrix().translate(-s.x,-s.y);this.matrix=i,this.reverseMatrix=i.inverseMatrix(),n.actionManager.execAction(new W),n.inputManager.editTextInfo&&n.execAction(ee.blur(n.inputManager.editTextInfo.node.id)),this.groupBaseWorker.start(this.rotateInfo.nodes)}onMove(e,n){this.rotateNode(e,n,!0),this.removeAuxiliaryGraphics(n)}onUp(e,n){this.rotateNode(e,n,!1),n.auxiliaryManager.selectManager.refreshSelectStatus(),n.setCursor("default"),n.actionManager.execAction(new z),this.rotateInfo=null}removeAuxiliaryGraphics(e){e.removeAuxGraphic(N.HighlightRects),e.removeAuxGraphic(N.MultiSelectBound),e.removeAuxGraphic(N.SingleSelectBound),e.removeAuxGraphic(N.StretchRect),e.removeAuxGraphic(N.ExpandShape),e.removeAuxGraphic(N.SelectConnectAnchor)}rotateNode(e,n,o){const s=Ze.trimPoint(e.globalPoint),r=this.rotateInfo.rotateCenter;let i=Ze.calculateAngle(r,s);i=this.computeDeltaAngle(e,i);const a=i-this.lastAngle,c=re.generateMatrix().rotate(a),h=this.reverseMatrix.crossProduct(c).crossProduct(this.matrix),d=[],u=new Set;for(const f of this.rotateInfo.nodes){for(const g of this.handlers)if(g.enable(f)){g.handle(f,h,a,d);break}this.layoutWorker.collectNodeLinks(f,n,u)}if(n.execAction(new U({infos:d},{streaming:o})),this.lastAngle=i,this.rotateInfo.nodes.length===1){const f=M.computeRotateDeltaAngle(this.rotateInfo.rotateType),g=M.computeRotateAngle(this.rotateInfo.nodes,f);n.setCursor("rotate",g)}this.layoutWorker.work([...u],n,o),this.groupBaseWorker.work(n,o)}computeDeltaAngle(e,n){if(e.originEvent.ctrlKey)return n;let o=n-this.originAngle+this.originNodeAngle;const s=Ze.trimAngle(o),r=7.5;return Math.abs(s)<r?(o+=0-s,o+this.originAngle-this.originNodeAngle):Math.abs(s-90)<r?(o+=90-s,o+this.originAngle-this.originNodeAngle):Math.abs(s-180)<r?(o+=180-s,o+this.originAngle-this.originNodeAngle):Math.abs(s-270)<r?(o+=270-s,o+this.originAngle-this.originNodeAngle):Math.abs(s-360)<r?(o+=360-s,o+this.originAngle-this.originNodeAngle):n}}class Qa extends kn{constructor(){super([new Ka])}streamEnable(t,e){return e.getSelectNodes().size===0?!1:!!e.detect(F.Rotate,t)}}const Xt=100,rn=50;class Za{computeEndNodeRelative(t,e){const n=t.drawer.getConnectAnchor(),o=M.computeOriginNodeConnectEnd(e);let s;return o===ue.Top?s=n[ue.Bottom]:o===ue.Bottom?s=n[ue.Top]:o===ue.Left?s=n[ue.Right]:s=n[ue.Left],s}judgeQuickCreateMode(t,e,n){const o=M.computeNodeConnectEnd(e,t.baseProps.angle),s=t.globalBaseProps,r=s.clone();o===ue.Top?r.y=s.y-s.height-Xt:o===ue.Bottom?r.y=s.y+s.height+Xt:o===ue.Left?r.x=s.x-s.width-Xt:r.x=s.x+s.width+Xt;const i=M.getBoundsByBaseProps(r),a=n.nodeManager.searchNodesByRectNode(i).filter(h=>h.type!==v.Line&&h.type!==v.Section),c=M.sortGraphics(a);return c.length===0?null:c[c.length-1]}computePreviewNodePos(t,e,n){const o=M.computeNodeConnectEnd(e,t.baseProps.angle);return o===ue.Top?this.findTopPlace(t,o,n):o===ue.Bottom?this.findBottomPlace(t,o,n):o===ue.Left?this.findLeftPlace(t,o,n):this.findRightPlace(t,o,n)}findTopPlace(t,e,n){const o=t.globalBaseProps;for(let s=0;s<20;s++){const r=o.clone();r.y=o.y-o.height-Xt;const i=s%2,a=Math.ceil(s/2);i?r.x-=a*(o.width+rn):r.x+=a*(o.width+rn);const c=M.getBoundsByBaseProps(r);if(n.nodeManager.searchNodesByRectNode(c).filter(d=>d.type!==v.Line&&d.type!==v.Section).length===0)return{x:r.x,y:r.y}}return{x:o.x,y:o.y-o.height-rn}}findBottomPlace(t,e,n){const o=t.globalBaseProps;for(let s=0;s<20;s++){const r=o.clone();r.y=o.y+o.height+Xt;const i=s%2,a=Math.ceil(s/2);i?r.x-=a*(o.width+rn):r.x+=a*(o.width+rn);const c=M.getBoundsByBaseProps(r);if(n.nodeManager.searchNodesByRectNode(c).filter(d=>d.type!==v.Line&&d.type!==v.Section).length===0)return{x:r.x,y:r.y}}return{x:o.x,y:o.y+o.height+Xt}}findRightPlace(t,e,n){const o=t.globalBaseProps;for(let s=0;s<20;s++){const r=o.clone();r.x=o.x+o.width+Xt;const i=s%2,a=Math.ceil(s/2);i?r.y-=a*(o.width+rn):r.y+=a*(o.width+rn);const c=M.getBoundsByBaseProps(r);if(n.nodeManager.searchNodesByRectNode(c).filter(d=>d.type!==v.Line&&d.type!==v.Section).length===0)return{x:r.x,y:r.y}}return{x:o.x+o.width+Xt,y:o.y}}findLeftPlace(t,e,n){const o=t.globalBaseProps;for(let s=0;s<20;s++){const r=o.clone();r.x=o.x-o.width-Xt;const i=s%2,a=Math.ceil(s/2);i?r.y-=a*(o.width+rn):r.y+=a*(o.width+rn);const c=M.getBoundsByBaseProps(r);if(n.nodeManager.searchNodesByRectNode(c).filter(d=>d.type!==v.Line&&d.type!==v.Section).length===0)return{x:r.x,y:r.y}}return{x:o.x-o.width-Xt,y:o.y}}}class Yu extends qe{constructor(){super(...arguments);p(this,"createWorker",new Za);p(this,"layoutHandler",new Vt)}enable(e,n){const o=n.detect(F.HoverConnectAnchor,e);return o?o.node.type===v.Shape:!1}isParentRoot(e,n,o){const s=e.parent;if(s===o.nodeManager.root)return!0;const r=e.getBounds(),i=e.globalPos,a=n.x-i.x,c=n.y-i.y,h={minX:r.minX+a,minY:r.minY+c,maxX:r.maxX+a,maxY:r.maxY+c},d=s.getBounds();return!(M.containRect(d,h)||M.overlapRect(d,h))}handle(e,n){const o=n.detect(F.HoverConnectAnchor,e),s=o.node,r=o.relative,i=this.createWorker.judgeQuickCreateMode(s,r,n);if(i){this.handleCreateLineAndLink(i,e,n);return}this.handleCreateNode(e,n)}handleCreateLine(e,n,o,s){const r=o.globalPos,i=this.createWorker.computeEndNodeRelative(e,n),a=e.baseProps,c=e.toGlobal({x:n.x*a.width,y:n.y*a.height}),h=this.isParentRoot(e,r,s),d=o.id,u=o.baseProps,f=o.toGlobal({x:i.x*u.width,y:i.y*u.height}),g={point:c,nodeConnect:{rect:D.rectNode2Rect(e.getBounds()),endType:M.computeNodeConnectEnd(n,e.baseProps.angle)}},y={point:f,nodeConnect:{rect:D.rectNode2Rect(o.getBounds()),endType:M.computeNodeConnectEnd(i,o.baseProps.angle)}},P=this.makeupLineProps(g,y,e.parent,h);P.push({type:I.Connect,start:{objectId:e.id,x:n.x,y:n.y},end:{objectId:d,x:i.x,y:i.y}});const b=s.idGenerator.genId(v.Line);return s.execAction(Le.create({id:b,zIndex:ve.genZIndex(s.nodeManager.root),type:v.Line,props:P,parentId:h?"":e.parent.id})),b}handleCreateLineAndLink(e,n,o){const s=o.detect(F.HoverConnectAnchor,n),r=s.node,i=s.relative;o.execAction(new W);const a=this.handleCreateLine(r,i,e,o);o.execAction(xe.create([a])),sn.blurText(o),o.execAction(new z)}handleCreateNode(e,n){const o=n.detect(F.HoverConnectAnchor,e),s=o.node,r=o.relative,i=this.createWorker.computePreviewNodePos(s,r,n),a=this.isParentRoot(s,i,n),c=this.makeupNodeProps(s,i,a),h=n.idGenerator.genId(v.Shape);n.execAction(new W),n.execAction(Le.create({id:h,zIndex:ve.genZIndex(n.nodeManager.root),type:v.Shape,props:c,parentId:a?"":s.parent.id}));const d=n.nodeManager.getNode(h);if(this.handleCreateLine(s,r,d,n),n.execAction(xe.create([h])),d.type===v.Shape&&d.shapeType===K.PureText){const u=d.renderText;n.execAction(ee.selection(h,u.headTextCursorPosition(),u.tailTextCursorPosition()))}else n.execAction(ee.focus(h));n.execAction(new z)}makeupNodeProps(e,n,o){const s=e.baseProps,r=e.shapeType;let i=n;o||(i=e.parent.globalTransform().inverseMatrix().crossPoint(i));const a=i.x,c=i.y,h=e.colorProps,d=e.borderProps,u=[{type:I.Base,x:a,y:c,width:s.width,height:s.height,angle:s.angle},tt.create({...h}),Ae.create({...d}),new Oe(r)];if(e.type===v.Shape&&e.shapeType===K.PureText){const f=e.textProps;u.push(f.clone());const g=e.paragraphProps;u.push(g.clone())}return u}makeupLineProps(e,n,o,s){let r=this.layoutHandler.layoutToPointsPro(e,n);if(!s){const c=o.globalTransform().inverseMatrix();r=r.map(h=>c.crossPoint(h))}const i=D.rectNode2Rect(M.getBoundsByPoints(r));return[je.create(r),ie.create({x:i.x,y:i.y,width:i.width,height:i.height}),lt.create({rArrow:it.Arrow}),new Oe(de.RoundPolyLine)]}}class Gu extends jt{constructor(){super(),this.registerUpHandler(new Yu)}}class Uu extends pn{constructor(){super([new Gu])}clickEnable(t,e){return!!e.detect(F.HoverConnectAnchor,t)}}class qa extends qe{constructor(){super(...arguments);p(this,"group",null)}enable(e,n){const o=[...n.getSelectNodes()];if(o.length!==1)return!1;const s=o[0];if(s.type!==v.Group)return!1;const r=s;return r.contains(e.globalPoint)?(this.group=r,!0):!1}handle(e,n){if(this.group){for(const o of this.group.children)if(o.contains(e.globalPoint)){n.execAction(new W),n.execAction(xe.create([o.id])),n.execAction(new z);return}}}}class _u extends qe{constructor(){super(...arguments);p(this,"res",null)}enable(e,n){const o=n.detect(F.Node,e);if(o){const s=o[0];if(n.auxiliaryManager.selectManager.include(s)){const r=s.toLocal(e.globalPoint);if(s instanceof vt&&s.renderText.contains(r))return this.res={node:s,relativePos:r},!0;if(s instanceof Ct)return this.res={node:s,relativePos:r},!0;if(s instanceof Un&&s.renderText.contains(r))return this.res={node:s,relativePos:r},!0}}return!1}handle(e,n){if(!this.res)return;const{node:o,relativePos:s}=this.res;if(o.isEmptyText()){const r=o.renderText.detect(s);if(n.execAction(new W),o instanceof Ct&&o.renderText.isEmptyText()){const{height:a}=o.renderText,c=o.baseProps,h=M.computePointByT(o,.5),d=h.x-.5*20,u=h.y-.5*a,f=new D(d,u,20,a);n.execAction(U.create(o.id,[{type:I.LineTextRect,x:f.x-c.x,y:f.y-c.y,width:f.width,height:f.height,point:{x:h.x-c.x,y:h.y-c.y}}]))}n.execAction(ee.focus(o.id,r)),n.execAction(new z);return}n.execAction(new W),n.execAction(ee.selection(o.id,Fe.head(),o.renderText.tailTextCursorPosition())),n.execAction(new z)}}const $u=new Set([v.Checkbox,v.CheckboxText]);class ju extends qe{constructor(){super(...arguments);p(this,"node",null);p(this,"checkboxWorker",new Ra)}enable(e,n){const o=n.detect(F.Node,e);if(!o)return!1;const s=o[0];return $u.has(s.type)&&s.checkboxContain(e.globalPoint)?(this.node=s,!0):!1}handle(e,n){this.node&&this.checkboxWorker.checkbox(this.node,e,n)}}class Vu extends jt{constructor(){super(),this.registerDownHandler(new qa),this.registerDownHandler(new _u),this.registerDownHandler(new ju)}}class Ku extends js{constructor(){super([new Vu])}}class Qu extends qe{constructor(){super(...arguments);p(this,"node",null)}enable(e,n){return!0}handle(e,n){if(n.getSelectNodes().size>0){const r=n.auxiliaryManager.selectManager.getSelectBounds();if(M.rectContains2(e.globalPoint,r)){const i={clientPoint:e.clientPoint,show:!0,hasFocus:n.getSelectNodes().size>0};n.slotManager.addSlotState(ze.ContextMenu,i);return}}const o=n.detect(F.Node,e);if(o&&o.length>0){const r=o[0];n.auxiliaryManager.selectManager.include(r)||(n.execAction(new W),n.execAction(xe.create([r.id])),n.execAction(new z))}else n.execAction(new W),n.execAction(xe.create([])),n.execAction(new z);const s={clientPoint:e.clientPoint,show:!0,hasFocus:n.getSelectNodes().size>0};n.slotManager.addSlotState(ze.ContextMenu,s)}}class Zu extends jt{constructor(){super(),this.registerUpHandler(new Qu)}}class qu extends pn{constructor(){super([new Zu])}canBeEnable(t,e){return t.originEvent.button===2}}class Ja extends ht{constructor(){super(...arguments);p(this,"lastPoint",null)}onStart(e,n){this.lastPoint=e.clientPoint,n.setCursor("grabbing")}onMove(e,n){if(!this.lastPoint)return;n.setCursor("grabbing");const o=e.clientPoint,s=o.x-this.lastPoint.x,r=o.y-this.lastPoint.y;n.renderManager.scroll(-s,-r),this.lastPoint=o}onUp(e,n){n.setCursor("grab")}}class Ju extends dt{constructor(){super([new Ja])}streamEnable(t,e){return t.originEvent.button===2}}class ep extends ht{constructor(){super(...arguments);p(this,"line");p(this,"bezierWorker",new zo);p(this,"startPoint");p(this,"endPoint");p(this,"leftPoints",[]);p(this,"rightPoints",[]);p(this,"lineTextWorker",new $n)}onStart(e,n){const{line:o,lPoint:s,rPoint:r,curve:i,index:a}=n.detect(F.CurveControlPoint,e);this.line=o,this.startPoint=s,this.endPoint=r;const{lP:c,rP:h,midPoint:d}=this.bezierWorker.splitCurve(i),u=JSON.parse(JSON.stringify(o.points));this.leftPoints=u.slice(0,a),this.rightPoints=u.slice(a+4);const g=.4*M.distance(this.startPoint,e.globalPoint),y=new m(this.startPoint.x+g,this.startPoint.y),P=i.p3,w=.4*M.distance(P,d),L=new m(P.x-w,P.y),B=[...this.leftPoints,s,y,c,d,h,L,r,...this.rightPoints];this.lineTextWorker.init(o),n.execAction(new W);const H=this.bezierWorker.computeCurvePointsForLine(o,n.nodeManager,B);n.execAction(U.create(this.line.id,[{type:I.Line,points:H}]))}onMove(e,n){this.onWork(e,n,!0)}onUp(e,n){this.onWork(e,n,!1),n.execAction(new z)}onWork(e,n,o){const s=e.globalPoint,i=.4*M.distance(this.startPoint,s),a=new m(this.startPoint.x+i,this.startPoint.y),c=this.endPoint,d=.4*M.distance(c,e.globalPoint),u=new m(c.x-d,c.y),{lP:f,rP:g,midPoint:y}=this.bezierWorker.computeCurveControlPoint(a,s,u),P=this.startPoint,b=this.endPoint,w=[...this.leftPoints,P,a,f,y,g,u,b,...this.rightPoints],L=this.bezierWorker.computeCurvePointsForLine(this.line,n.nodeManager,w);n.execAction(U.create(this.line.id,[{type:I.Line,points:L}],{streaming:o})),this.lineTextWorker.work(this.line,n,o)}}class tp extends dt{constructor(){super([new ep],[])}streamEnable(t,e){return!!e.detect(F.CurveControlPoint,t)}}class np extends ht{constructor(){super(...arguments);p(this,"line");p(this,"dragIndex");p(this,"bezierWorker",new zo);p(this,"lineTextWorker",new $n)}onStart(e,n){const{line:o,index:s}=n.detect(F.CurveEndPoint,e);this.line=o,this.dragIndex=s,n.execAction(new W),this.lineTextWorker.init(o)}onMove(e,n){this.onWork(e,n,!0)}onUp(e,n){this.onWork(e,n,!1),n.execAction(new z)}onWork(e,n,o){const s=this.line,r=[...s.points];r.splice(this.dragIndex,1,e.globalPoint);const i=this.bezierWorker.computeCurvePointsForLine(s,n.nodeManager,r);n.execAction(U.create(this.line.id,[{type:I.Line,points:i}],{streaming:o})),this.lineTextWorker.work(s,n,o)}}class op extends dt{constructor(){super([new np],[])}streamEnable(t,e){return!!e.detect(F.CurveEndPoint,t)}}class ar{init(t){}dealWithPoint(t,e){t.x<e.minX&&(t.x=e.minX),t.y<e.minY&&(t.y=e.minY),t.x>e.maxX&&(t.x=e.maxX),t.y>e.maxY&&(t.y=e.maxY)}}class sp extends ar{constructor(){super(...arguments);p(this,"lineShapes",[])}init(e){const n=[],o=e.globalLinePoints;for(let s=0;s<o.length-1;s++){const r=o[s],i=o[s+1],a=q.line(r,i),c=M.judgeHorizon(r,i);n.push({isHorizon:c,shapeInfo:a})}this.lineShapes=n}enable(e){return e.isPolyLine()}handle(e,n){const o=e.getBounds(),{minX:s,minY:r,maxX:i,maxY:a}=o,c=this.lineShapes,h={x:n.x,y:n.y};this.dealWithPoint(h,o);const d=10,u=q.line({x:s-d,y:h.y},{x:i+d,y:h.y}),f=q.line({x:h.x,y:r-d},{x:h.x,y:a+d}),g=[];for(const b of c)if(b.isHorizon){const w=Y.intersect(b.shapeInfo,f);if(w.points.length>0){const L=w.points[0],B=M.distance(L,h);g.push({point:L,distance:B})}}else{const w=Y.intersect(b.shapeInfo,u);if(w.points.length>0){const L=w.points[0],B=M.distance(L,h);g.push({point:L,distance:B})}}if(g.length===0)return console.warn("探测结果出现问题,兜底容错"),null;const y=Math.min(...g.map(b=>b.distance));return g.find(b=>b.distance-y<.1)??null}dealWithPoint(e,n){e.x<n.minX&&(e.x=n.minX),e.y<n.minY&&(e.y=n.minY),e.x>n.maxX&&(e.x=n.maxX),e.y>n.maxY&&(e.y=n.maxY)}}class rp extends ar{constructor(){super(...arguments);p(this,"lineShape")}init(e){const n=e.globalLinePoints,o=n[0],s=n[n.length-1],r=q.line({x:o.x,y:o.y},{x:s.x,y:s.y});this.lineShape=r}enable(e){return e.shapeType===de.Line}handle(e,n){const o=e.getBounds(),{minX:s,minY:r,maxX:i,maxY:a}=o,c={x:n.x,y:n.y};this.dealWithPoint(c,o);const h=10,d=q.line({x:s-h,y:c.y},{x:i+h,y:c.y}),u=q.line({x:c.x,y:r-h},{x:c.x,y:a+h}),f=[];if(this.intersectLine(d,c,f),this.intersectLine(u,c,f),f.length===0)return console.warn("探测结果出现问题,兜底容错"),null;const g=Math.min(...f.map(P=>P.distance));return f.find(P=>P.distance-g<.1)??null}intersectLine(e,n,o){const s=Y.intersect(this.lineShape,e);if(s.points.length>0){const r=s.points[0],i=M.distance(r,n);o.push({point:r,distance:i})}}}class ip extends ar{constructor(){super(...arguments);p(this,"lineShapes",[])}init(e){const n=M.computeBezierCurves(e),o=[];for(const s of n){const r=q.cubicBezier(s.p0,s.p1,s.p2,s.p3);o.push(r)}this.lineShapes=o}enable(e){return e.shapeType===de.Curve}handle(e,n){const o=e.getBounds(),{minX:s,minY:r,maxX:i,maxY:a}=o,c={x:n.x,y:n.y};this.dealWithPoint(c,o);const h=10,d=q.line({x:s-h,y:c.y},{x:i+h,y:c.y}),u=q.line({x:c.x,y:r-h},{x:c.x,y:a+h}),f=[];for(const P of this.lineShapes)this.intersectLine(P,d,c,f),this.intersectLine(P,u,c,f);if(f.length===0)return console.warn("探测结果出现问题,兜底容错"),null;const g=Math.min(...f.map(P=>P.distance));return f.find(P=>P.distance-g<.1)??null}intersectLine(e,n,o,s){const r=Y.intersect(e,n);if(r.points.length>0){const i=r.points[0],a=M.distance(i,o);s.push({point:i,distance:a})}}}class ap extends ht{constructor(){super(...arguments);p(this,"line");p(this,"intersectHandlers",[new sp,new ip,new rp]);p(this,"currentHandler",null)}onStart(e,n){const{line:o}=n.detect(F.DragLineText,e);this.line=o,this.selectHandler(o),n.execAction(new W)}onMove(e,n){this.onWork(e,n,!0)}onUp(e,n){this.onWork(e,n,!1),n.execAction(new z)}onWork(e,n,o){if(!this.currentHandler)return;const s=e.globalPoint,r=this.currentHandler.handle(this.line,s);if(!r)return;const{width:i,height:a}=this.line.lineTextRect,c=this.line.baseProps,h=r.point,d=h.x-.5*i-c.x,u=h.y-.5*a-c.y;n.execAction(U.create(this.line.id,[{type:I.LineTextRect,x:d,y:u,point:{x:h.x-c.x,y:h.y-c.y}}],{streaming:o}))}selectHandler(e){for(const n of this.intersectHandlers)if(n.enable(e)){n.init(e),this.currentHandler=n;return}}}class cp extends dt{constructor(){super([new ap])}streamEnable(t,e){return!!e.detect(F.DragLineText,t)}}class lp extends ht{constructor(){super(...arguments);p(this,"originPos");p(this,"originNodePos");p(this,"dragNode");p(this,"originDragNodes",[]);p(this,"originBaseProps");p(this,"rowNodes",[]);p(this,"rowIds",[]);p(this,"rowIndex",0);p(this,"targetRowIndex",0);p(this,"isInsertNewRow",!1);p(this,"originIndex",0);p(this,"insertIndex",0)}computeRowNodes(e){const o=this.dragNode.parent.slideProps.children;this.rowNodes=[],this.rowIds=[];let s=-1,r=-1;for(let i=0;i<o.length;i++){const a=o[i],c=[];for(const h of a.ids){const d=e.nodeManager.getNode(h);d&&(c.push(d),d.id===this.dragNode.id&&(s=i,r=c.length-1))}this.rowNodes.push(c.map(h=>h.baseProps.clone())),this.rowIds.push(c.map(h=>h.id))}if(s===-1){this.rowIndex=0,this.originIndex=0;return}this.rowIndex=s,this.originIndex=r}onStart(e,n){const s=[...n.getSelectNodes()][0],r=s.pos;this.dragNode=s,this.originNodePos=new m(r.x,r.y),this.originPos=e.globalPoint,this.originBaseProps=s.globalBaseProps.clone();const i=new Set;M.getAllChildren(s,i);const a=M.sortGraphics([s,...i]);this.originDragNodes=a,this.computeRowNodes(n),n.execAction(new W)}onMove(e,n){const o=e.globalPoint,s=this.originPos,r=o.x-s.x,i=o.y-s.y;n.addOrUpdate(N.HoverSlidePlaceHolder,{baseProps:this.originBaseProps}),n.addOrUpdate(N.HoverFocusCopy,{nodes:this.originDragNodes});const a=this.originNodePos.x+r,c=this.originNodePos.y+i,h=this.dragNode.parent.globalPos,d=o.x-h.x,u=o.y-h.y;this.determineTargetRow(u),this.showInsertIndicator(d,h,n),n.execAction(U.create(this.dragNode.id,[{type:I.Base,x:a,y:c}],{streaming:!0}))}relayoutRow(e,n,o,s,r){let i=n;for(const a of e){const c=s.nodeManager.getNode(a);c&&(r.push({id:a,props:[{type:I.Base,x:i,y:o}]}),i+=c.baseProps.width+nt)}}handleInsertNewRow(e,n){const o=[],s=[...this.rowIds[this.rowIndex]];s.splice(this.originIndex,1);const r=this.targetRowIndex,i=r===0,a=r===this.rowNodes.length;s.length===0?(e.splice(this.rowIndex,1),this.rowIndex<this.targetRowIndex&&this.targetRowIndex--):e[this.rowIndex].ids=s,e.splice(this.targetRowIndex,0,{ids:[this.dragNode.id]});const c=this.dragNode.baseProps;let h,d;if(i){h=this.rowNodes[0][0].x,d=this.rowNodes[0][0].y;const u=c.height+xt;for(let f=0;f<this.rowNodes.length;f++){const g=this.rowIds[f].filter(P=>P!==this.dragNode.id),y=this.rowNodes[f][0].y+u;this.relayoutRow(g,this.rowNodes[f][0].x,y,n,o)}}else if(a){const u=this.rowNodes.length-1,f=this.rowNodes[u];h=f[0].x,d=f[0].y+f[0].height+xt,s.length>0&&this.relayoutRow(s,this.rowNodes[this.rowIndex][0].x,this.rowNodes[this.rowIndex][0].y,n,o)}else{const u=this.rowNodes[r-1];this.rowNodes[r],h=u[0].x,d=u[0].y+u[0].height+xt;const f=c.height+xt;for(let g=0;g<this.rowNodes.length;g++){const y=this.rowIds[g].filter(b=>b!==this.dragNode.id);if(y.length===0)continue;let P;g<r?P=this.rowNodes[g][0].y:P=this.rowNodes[g][0].y+f,this.relayoutRow(y,this.rowNodes[g][0].x,P,n,o)}}return o.push({id:this.dragNode.id,props:[{type:I.Base,x:h,y:d}]}),o}determineTargetRow(e){var a,c,h;if(this.isInsertNewRow=!1,this.rowNodes.length===0){this.targetRowIndex=0;return}const n=((a=this.rowNodes[0][0])==null?void 0:a.y)??0;if(e<n){this.isInsertNewRow=!0,this.targetRowIndex=0,this.insertIndex=0;return}const o=this.rowNodes.length-1,s=this.rowNodes[o],r=((c=s[0])==null?void 0:c.y)??0,i=((h=s[0])==null?void 0:h.height)??0;if(e>r+i){this.isInsertNewRow=!0,this.targetRowIndex=this.rowNodes.length,this.insertIndex=0;return}for(let d=0;d<this.rowNodes.length;d++){const u=this.rowNodes[d];if(u.length===0)continue;const f=u[0].y,g=u[0].height;if(e>=f&&e<=f+g){this.targetRowIndex=d;return}if(d<this.rowNodes.length-1){const y=this.rowNodes[d+1];if(y.length===0)continue;const P=y[0].y,b=f+g,w=P;if(e>b&&e<w){this.isInsertNewRow=!0,this.targetRowIndex=d+1,this.insertIndex=0;return}}}this.targetRowIndex=this.rowIndex}showInsertIndicator(e,n,o){this.isInsertNewRow?this.showNewRowIndicator(n,o):this.showExistingRowIndicator(e,n,o)}showNewRowIndicator(e,n){const o=this.targetRowIndex===0,s=this.targetRowIndex===this.rowNodes.length;let r,i;if(o)r=this.rowNodes[0],i=r[0].y+e.y-.5*xt;else if(s)r=this.rowNodes[this.rowNodes.length-1],i=r[0].y+r[0].height+e.y+.5*xt;else{const u=this.rowNodes[this.targetRowIndex-1],f=this.rowNodes[this.targetRowIndex],g=u[u.length-1].x+u[u.length-1].width-u[0].x,y=f[f.length-1].x+f[f.length-1].width-f[0].x;r=g>=y?u:f;const P=u[0].y+u[0].height,b=f[0].y;i=(P+b)/2+e.y}const a=r[0],c=r[r.length-1],h=a.x+e.x,d=c.x+c.width+e.x;n.addOrUpdate(N.HoverInsertHorizonSlide,{x0:h,x1:d,y:i})}showExistingRowIndicator(e,n,o){const s=this.rowNodes[this.targetRowIndex]||[];for(let r=0;r<s.length;r++){const i=s[r],a=i.x+.5*i.width;if(e<a){this.insertIndex=r,o.addOrUpdate(N.HoverInsertSlide,{x:i.x-.5*nt+n.x,y0:i.y+n.y,y1:i.y+i.height+n.y});return}if(r===s.length-1){this.insertIndex=s.length,o.addOrUpdate(N.HoverInsertSlide,{x:i.x+i.width+.5*nt+n.x,y0:i.y+n.y,y1:i.y+i.height+n.y});return}}}handleSameRowDrag(e,n){const o=[],s=[...this.rowIds[this.rowIndex]];return this.insertIndex<this.originIndex?(s.splice(this.originIndex,1),s.splice(this.insertIndex,0,this.dragNode.id)):(s.splice(this.insertIndex,0,this.dragNode.id),s.splice(this.originIndex,1)),e[this.rowIndex].ids=s,this.relayoutRow(s,this.rowNodes[this.rowIndex][0].x,this.rowNodes[this.rowIndex][0].y,n,o),o}handleCrossRowDrag(e,n){const o=[],s=[...this.rowIds[this.rowIndex]],r=[...this.rowIds[this.targetRowIndex]];if(s.splice(this.originIndex,1),e[this.rowIndex].ids=s,r.splice(this.insertIndex,0,this.dragNode.id),e[this.targetRowIndex].ids=r,s.length===0){const a=this.rowNodes[this.rowIndex][0].height+xt;for(let c=0;c<this.rowNodes.length;c++){if(c===this.rowIndex)continue;const h=c===this.targetRowIndex?r:this.rowIds[c],d=c>this.rowIndex?this.rowNodes[c][0].y-a:this.rowNodes[c][0].y;this.relayoutRow(h,this.rowNodes[c][0].x,d,n,o)}}else this.relayoutRow(s,this.rowNodes[this.rowIndex][0].x,this.rowNodes[this.rowIndex][0].y,n,o),this.relayoutRow(r,this.rowNodes[this.targetRowIndex][0].x,this.rowNodes[this.targetRowIndex][0].y,n,o);return o}onUp(e,n){const o=!this.isInsertNewRow&&this.targetRowIndex===this.rowIndex,s=o&&(this.insertIndex===this.originIndex||this.insertIndex===this.originIndex+1),r=this.rowIds[this.rowIndex].length===1,i=this.isInsertNewRow&&r&&(this.targetRowIndex===this.rowIndex||this.targetRowIndex===this.rowIndex+1);if(s||i){n.execAction(U.create(this.dragNode.id,[{type:I.Base,x:this.originNodePos.x,y:this.originNodePos.y}],{streaming:!1})),n.execAction(new z);return}const c=this.dragNode.parent.slideProps.children.map(g=>({ids:[...g.ids]}));let h;this.isInsertNewRow?h=this.handleInsertNewRow(c,n):o?h=this.handleSameRowDrag(c,n):h=this.handleCrossRowDrag(c,n);const d=c.filter(g=>g.ids.length>0);h.unshift({id:this.dragNode.parent.id,props:[{type:I.Slide,children:d}]}),n.execAction(new U({infos:h}));const u=this.dragNode.parent,f=[];for(const g of d)for(const y of g.ids){const P=n.nodeManager.getNode(y);P&&f.push(P.baseProps)}if(f.length>0){const g=M.getBoundsByBasePropsList(f),y=g.maxX-g.minX,P=g.maxY-g.minY;n.execAction(U.create(u.id,[{type:I.Base,width:y+2*nt,height:P+2*xt}]))}n.execAction(new z)}}class hp extends dt{constructor(){super([new lp])}streamEnable(t,e){var i;const o=[...e.auxiliaryManager.selectManager.getSelectNodes()];if(o.length!==1)return!1;const s=o[0];return((i=s.parent)==null?void 0:i.type)!==v.SlideContainer?!1:M.rectContains2(t.globalPoint,s.getRectNode())}}class ec extends fn{constructor(){super([new Ju,new Uu,new Ou,new Hu,new tp,new Au,new op,new cp,new aa,new qs,new pa,new ja,new Qa,new hp,new Ta,new Ku,new qu,new Ha,new _a])}canBeEnable(t,e){return!0}}class tc extends Ke{onDetect(t,e){const n=e.getSelectNodes();if(n.size!==1)return!1;const o=[...n][0];if(o.type!==v.Shape)return!1;const s=o;if(s.isEmptyText())return!1;const r=s.getTextContentRect();if(s.renderText.height<r.height)return!1;const i=e.gmlRender.getScale(),a=s.toLocal(t.globalPoint),{width:c,height:h}=s.baseProps,d=new D(.5*c-.5*21/i,h-.5*12/i,21/i,12/i);return M.rectContains(a,d)?(this.result={node:s,realHeight:s.drawer.fullTextNodeHeight(s)},!0):!1}}class nc extends Ke{onDetect(t,e){const n=e.auxiliaryManager.selectManager.selectNodes;if(n.size!==1)return!1;const o=[...n][0];if(o.type!==v.Line)return!1;const s=o,i=8/e.gmlRender.getScale(),a=s.points,c=a[0],h=a[a.length-1],d=s.toLocal(t.globalPoint);let u=M.circleContains(d,c,i);return u?(this.result={detectPoint:c,isStart:!0,line:s},!0):(u=M.circleContains(d,h,i),u?(this.result={detectPoint:h,isStart:!1,line:s},!0):!1)}}const dp=12;class up extends Ke{onDetect(t,e){const n=e.detect(F.HoverConnectAnchor,t);if(n){const u=Ze.getNodePos(n.node,n.relative);return this.result={node:n.node,point:u,relativePos:n.relative},!0}const o=e.detect(F.HoverNodeAnchor,t);if(o){const u=Ze.getNodePos(o.node,o.ratio);return this.result={node:o.node,point:u,relativePos:o.ratio},!0}const s=e.detect(F.BufferNode,t);if(!s)return!1;const r=s.filter(u=>u.canBeConnected());if(r.length===0)return!1;const i=r[0];if(!i.canBeConnected())return!1;const a=e.renderManager.getScale(),{width:c,height:h}=i.baseProps,d=i.borderContains(t.globalPoint,dp/a);return d?(this.result={node:i,point:i.toGlobal(d),relativePos:new m(d.x/c,d.y/h)},!0):!1}}class Qo extends ht{constructor(){super(...arguments);p(this,"startPos",new m);p(this,"target",null);p(this,"viewBounds");p(this,"alignWorker",new un)}nodeType(){return v.Shape}autoFocus(){return!0}onStart(e,n){n.previewManager.resetPreviewNode(n),n.alignPoint?(this.startPos=n.alignPoint,n.alignPoint=null):this.startPos=e.globalPoint;const o=n.detect(F.HoverOnContainer,e);let s=n.nodeManager.root,r=new m(this.startPos.x,this.startPos.y);o&&(r=o.toLocal(this.startPos),s=o);const i=this.nodeType(),a=n.idGenerator.genId(i),c=this.makeupDefaultProps(n,r);console.log("njx debug,props:",c);const h={id:a,type:i,zIndex:ve.genZIndex(s),parentId:s.id,props:c};n.actionManager.execAction(new W);const d=Le.create(h);n.actionManager.execAction(d),this.target=n.nodeManager.nodeMap.get(a);const u=D.baseProps2Rect(this.target.baseProps);n.addOrUpdate(N.CreateRectBound,{rect:u,transform:this.target.globalTransform()}),n.auxiliaryManager.removeAlignGraphics(),this.viewBounds=n.gmlRender.getViewPortBounds()}onMove(e,n){if(!this.target)return;n.auxiliaryManager.removeAlignGraphics();const o=this.target.baseProps.clone(),s=new Set([this.target]),r=!M.pressMeta(e),i=this.alignWorker.alignLineEndAndDrawAlignLines(e,n,s,r);this.computeRectBounds(i,o);const a=n.gmlRender.getScale(),c=D.baseProps2Rect(o),h=new Set(n.getSelectNodes());h.add(this.target);const d=this.alignWorker.alignStretch(n,c,h,_e.both,this.viewBounds,Us/a,Gs/a);this.drawAlignLine(c,d,n);const u=new m(c.x,c.y),f=this.target.parent.toLocal(u),g={type:I.Base,x:f.x,y:f.y,width:c.width,height:c.height},y=U.create(this.target.id,[g],{streaming:!0});n.actionManager.execAction(y);const P=D.baseProps2Rect(this.target.baseProps);n.addOrUpdate(N.CreateRectBound,{rect:P,transform:this.target.globalTransform()})}onUp(e,n){if(!this.target)return;const o=n.renderManager.getScale(),s=this.target.baseProps,r={type:I.Base,x:s.x,y:s.y,width:s.width,height:s.height},{width:i,height:a}=this.computeMiniSize(),c=this.computeDefaultSize(n);let h=!1;M.distance(this.startPos,e.globalPoint)<Math.max(9,9/o)?(r.width=c.width,r.height=c.height,h=!0):(r.width<i||r.height<a)&&(r.width=c.width,r.height=c.height);const d=[r];this.dealWithUpUpdateProps(h,d);const u=U.create(this.target.id,d);n.actionManager.execAction(u),n.actionManager.execAction(xe.create([this.target.id])),this.autoFocus()&&n.actionManager.execAction(ee.focus(this.target.id)),n.actionManager.execAction(new z),this.target=null,n.toolManager.resetTool(),n.removeAuxGraphic(N.CreateRectBound),n.auxiliaryManager.removeAlignGraphics(),n.setCursor("default")}dealWithUpUpdateProps(e,n){}computeRectBounds(e,n,o=10,s=10){if(!this.target)return;const r=Math.max(Math.abs(e.x-this.startPos.x),o),i=Math.max(Math.abs(e.y-this.startPos.y),s);n.width=r,n.height=i,e.x>=this.startPos.x&&e.y>=this.startPos.y?(n.x=this.startPos.x,n.y=this.startPos.y):e.x>this.startPos.x&&e.y<this.startPos.y?(n.x=this.startPos.x,n.y=this.startPos.y-i):e.x<this.startPos.x&&e.y>this.startPos.y?(n.x=this.startPos.x-r,n.y=this.startPos.y):e.x<=this.startPos.x&&e.y<=this.startPos.y?(n.x=this.startPos.x-r,n.y=this.startPos.y-i):(n.x=this.startPos.x-r,n.y=this.startPos.y-i)}drawAlignLine(e,n,o){const s=this.target,r=s.baseProps,{width:i,height:a}=n;if(i){e.width+=i.dt;const c={transform:s.transform.clone(),line:{start:new m(0,r.height),end:new m(r.width,r.height)}};i.lines.push(c)}if(a){e.height+=a.dt;const c={transform:s.transform.clone(),line:{start:new m(r.width,0),end:new m(r.width,r.height)}};a.lines.push(c)}o.addOrUpdate(N.AlignStretchLine,{alignInfo:n})}}class oc extends Qo{constructor(){super(...arguments);p(this,"startPos",new m);p(this,"target",null)}computeDefaultSize(){return{width:100,height:100}}computeMiniSize(){return{height:5,width:5}}makeupDefaultProps(e,n){return e.createWorker.makeupDefaultProps(v.Shape,e,e.toolManager.shapeType,n)}dealWithUpUpdateProps(e,n){e||n.push({type:I.Text,sizeMode:We.fix})}}class sc extends kn{constructor(){super([new oc])}streamEnable(t,e){return e.toolManager.currentTool==ye.SHAPE}}class rc extends Qo{computeDefaultSize(){return{height:0,width:0}}computeMiniSize(){return{height:0,width:0}}makeupDefaultProps(t,e){return[ie.create({x:e.x,y:e.y}),Ge.create({type:I.Text,fontSize:16,richText:"<root><p></p></root>",horizonAlign:at.Top,verticalAlign:at.Top}),new Oe(K.PureText)]}}class ic extends dt{constructor(){super([new rc])}streamEnable(t,e){return e.toolManager.currentTool==ye.TEXT}}class ac extends Ot{constructor(t){super(t)}canBeEnable(t,e){return!0}canBeExit(t,e){return!0}}class pp extends qe{constructor(){super(...arguments);p(this,"res",null)}enable(e,n){return n.toolManager.currentTool===ye.TEXT}handle(e,n){const o=n.idGenerator.genId(v.Shape),s=n.detect(F.HoverOnContainer,e);let r=n.nodeManager.root,i=e.globalPoint.clone();s&&(i=s.toLocal(i),r=s);const a=this.makeupDefaultProps(i),c={id:o,type:v.Shape,zIndex:ve.genZIndex(n.nodeManager.root),parentId:r.id,props:a};n.actionManager.execAction(new W);const h=Le.create(c);n.actionManager.execAction(h),n.actionManager.execAction(xe.create([o])),n.actionManager.execAction(ee.focus(o)),n.actionManager.execAction(new z),n.toolManager.resetTool()}makeupDefaultProps(e){return[ie.create({x:e.x,y:e.y,height:22,width:64}),Ge.create({type:I.Text,fontSize:16,richText:"<root><p></p></root>",horizonAlign:at.Top,verticalAlign:at.Top,sizeMode:We.autoWidth}),new Oe(K.PureText)]}}class fp extends qe{constructor(){super(...arguments);p(this,"res",null)}enable(e,n){const o=n.detect(F.Node,e);if(o){const s=o[0],r=s.toLocal(e.globalPoint);if(s instanceof vt&&s.renderText.contains(r))return this.res={node:s,relativePos:r},!0;if(s instanceof Ct)return this.res={node:s,relativePos:r},!0}return!1}handle(e,n){if(!this.res)return;n.toolManager.resetTool();const{node:o,relativePos:s}=this.res,r=o.renderText.detect(s);n.execAction(new W),n.execAction(xe.create([o.id])),n.execAction(ee.focus(o.id,r)),n.execAction(new z)}}class gp extends jt{constructor(){super(),this.registerUpHandler(new pp),this.registerUpHandler(new fp)}}class yp extends pn{constructor(){super([new gp])}clickEnable(t,e){return e.toolManager.currentTool===ye.TEXT}}class xp extends Qo{constructor(){super(...arguments);p(this,"startPos",new m);p(this,"target",null)}computeDefaultSize(e){const n=e.toolManager.shapeType,o=Uo[n];return{width:o.width,height:o.height}}computeMiniSize(){return{height:5,width:5}}nodeType(){return v.Section}autoFocus(){return!1}makeupDefaultProps(e,n){return e.createWorker.makeupDefaultProps(v.Section,e,e.toolManager.shapeType,n)}}class wp extends kn{constructor(){super([new xp])}streamEnable(t,e){return e.toolManager.currentTool==ye.SECTION}}class cc extends _o{constructor(){super(...arguments);p(this,"handlers",[new Ya])}}class lc{constructor(){p(this,"allowEventTypeSet",new Set([be.pointermove]));p(this,"alignWorker",new un)}process(t,e){const n=e.previewManager.createManager;if(!n.previewGraphics)return;const o=e.toolManager.grab;e.auxiliaryManager.removeAlignGraphics();const{rectNode:s,delta:r}=this.computeMoveRect(n.previewGraphics,t.globalPoint,o),i=this.alignWorker.alignMove(s,e.getSelectNodes(),e,!0),a=this.alignWorker.drawAlignLines(i,e),c=new m(s.minX+a.x,s.minY+a.y);e.alignPoint=c,e.previewManager.updatePos(c),e.addOrUpdate(N.PreviewGraphics,{previewNodes:[n.previewGraphics]})}computeMoveRect(t,e,n){const o=t.getBounds(),s=D.rectNode2Rect(o),r=n?s.x+.5*s.width:s.x,i=n?s.y+.5*s.height:s.y,a=new m(e.x-r,e.y-i);return o.minX+=a.x,o.maxX+=a.x,o.minY+=a.y,o.maxY+=a.y,{rectNode:o,delta:a}}}class Bn{handle(t,e,n){this.makeupAddNodeInfo(t,e,n).then(o=>{const s=o.id;t.actionManager.execAction(new W);const r=Le.create(o);t.actionManager.execAction(r),t.actionManager.execAction(xe.create([s])),this.autoFocus()&&t.actionManager.execAction(ee.focus(s)),t.actionManager.execAction(new z),t.toolManager.resetTool(),t.previewManager.resetPreviewNode(t),t.auxiliaryManager.removeAlignGraphics()})}detectParentContainer(t,e){const n=t.detect(F.HoverOnContainer,e);let o=t.nodeManager.root;return n&&(o=n),o}}class mp extends Bn{enable(t){return t===ye.SHAPE}async makeupAddNodeInfo(t,e,n){const o=t.toolManager.shapeType,s=this.detectParentContainer(t,n),r=t.createWorker.makeupDefaultProps(v.Shape,t,o,e,s);return{id:t.idGenerator.genId(v.Shape),type:v.Shape,zIndex:ve.genZIndex(s),parentId:s.id,props:r}}autoFocus(){return!0}}class Pp extends Bn{enable(t){return t===ye.SECTION}async makeupAddNodeInfo(t,e,n){const o=this.detectParentContainer(t,n),s=t.toolManager.shapeType,r=t.createWorker.makeupDefaultProps(v.Section,t,s,e,o);return{id:t.idGenerator.genId(v.Section),type:v.Section,zIndex:ve.genZIndex(o),parentId:o.id,props:r}}autoFocus(){return!1}}const bp="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Zo=(l=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(l|=0));for(;l--;)t+=bp[e[l]&63];return t};class cr{async addSvgNodeBySvgCode(t,e,n,o=n.nodeManager.root){const s=n.docState.docId,r=Zo(10),i=`${s}/${r}`,a=await n.resourceManager.uploadSvgString(i,t),c=this.computeAddSvgNode(t,a,e,n,o);return{url:a,addNodeInfo:c}}computeAddSvgNode(t,e,n,o,s=o.nodeManager.root){const r=an.trimSvgCode(t),i=[{type:I.Base,x:n.x,y:n.y,width:r.width,height:r.height},{type:I.Svg,url:e},{type:I.Border,dashType:et.None}];return{id:o.idGenerator.genId(v.SVG),type:v.SVG,zIndex:ve.genZIndex(s),parentId:s.id,props:i}}}class Mp extends Bn{constructor(){super(...arguments);p(this,"svgWorker",new cr)}autoFocus(){return!1}enable(e){return e===ye.Resource}async makeupAddNodeInfo(e,n,o){const s=this.detectParentContainer(e,o),r=s.toLocal(n),i=e.previewManager.previewResourceManager.previewSvgCode;i===""&&console.error("出现错误,svg code为空");const{addNodeInfo:a}=await this.svgWorker.addSvgNodeBySvgCode(i,r,e,s);return a}}class Sp extends Bn{autoFocus(){return!1}enable(t,e){return t===ye.Widget&&e===_n.Checkbox}async makeupAddNodeInfo(t,e,n){const o=this.detectParentContainer(t,n),s=t.createWorker.makeupDefaultProps(v.Checkbox,t,0,e,o);return{id:t.idGenerator.genId(v.Checkbox),type:v.Checkbox,zIndex:ve.genZIndex(o),parentId:o.id,props:s}}}class vp extends Bn{autoFocus(){return!1}enable(t,e){return t===ye.Widget&&e===_n.CheckboxText}async makeupAddNodeInfo(t,e,n){const o=this.detectParentContainer(t,n),s=t.createWorker.makeupDefaultProps(v.CheckboxText,t,0,e,o);return{id:t.idGenerator.genId(v.CheckboxText),type:v.CheckboxText,zIndex:ve.genZIndex(o),parentId:o.id,props:s}}}class Ip extends Bn{enable(t){return t===ye.LINE}async makeupAddNodeInfo(t,e,n){const o=t.toolManager.shapeType,s=this.detectParentContainer(t,n),r=t.createWorker.makeupDefaultProps(v.Line,t,o,e,s);return{id:t.idGenerator.genId(v.Line),type:v.Line,zIndex:ve.genZIndex(s),parentId:s.id,props:r}}autoFocus(){return!1}}class Tp extends Bn{autoFocus(){return!1}enable(t,e){return t===ye.SlideContainer}async makeupAddNodeInfo(t,e,n){const o=this.detectParentContainer(t,n),s=t.createWorker.makeupDefaultProps(v.SlideContainer,t,0,e,o);return{id:t.idGenerator.genId(v.SlideContainer),type:v.SlideContainer,zIndex:ve.genZIndex(o),parentId:o.id,props:s}}}class hc{constructor(){p(this,"allowEventTypeSet",new Set([be.pointerup]));p(this,"startPos",new m);p(this,"handlers",[new Mp,new mp,new Pp,new Ip,new Sp,new vp,new Tp])}process(t,e){e.toolManager.grab&&(e.alignPoint?(this.startPos=e.alignPoint,e.alignPoint=null):this.startPos=t.globalPoint,this.handleCreateUp(this.startPos,e,t))}handleCreateUp(t,e,n){for(const o of this.handlers)if(o.enable(e.toolManager.currentTool,e.toolManager.shapeType)){o.handle(e,t,n);return}}}const Lp=new Set([ye.SHAPE,ye.TEXT,ye.SECTION,ye.Resource,ye.Widget,ye.SlideContainer]);class Cp extends fn{constructor(){super([new yp,new wp,new sc,new ic,new ac([new cc,new lc,new hc])])}canBeEnable(t,e){return Lp.has(e.toolManager.currentTool)}}const qo=12;class Ap extends Ke{onDetect(t,e){const n=t.globalPoint,o=e.nodeManager.searchNodes(n.x-qo,n.y-qo,n.x+qo,n.y+qo);if(o.length===0)return this.result=null,!1;const s=M.sortGraphics(o);return s.reverse(),this.result=s,!0}}class kp extends Ke{onDetect(t,e){const n=e.detect(F.BufferNode,t);if(!n)return!1;const o=n[0];return e.auxiliaryManager.selectManager.include(o)?!1:(this.result=o,!0)}}const Np=12;class Bp extends Ke{onDetect(t,e){const n=e.detect(F.BufferNode,t);if(!n)return!1;const o=n.filter(u=>u.canBeConnected());if(o.length===0)return!1;const s=o[0];if(!s.canBeConnected()||e.auxiliaryManager.selectManager.include(s))return!1;const r=e.renderManager.getScale(),i=Np/r,{width:a,height:c}=s.baseProps,h=s.toLocal(t.globalPoint),d=s.getConnectAnchor();for(const u of d){const f=new m(u.x*a,u.y*c);if(M.circleContains(h,f,i))return this.result={node:s,ratio:u,localPoint:f},!0}return!1}}class dc extends Ke{onDetect(t,e){const n=e.auxiliaryManager.selectManager.selectNodes;if(n.size!==1)return!1;const o=[...n][0];if(o.type!==v.Line)return!1;const s=o;if(!s.isPolyLine())return!1;const r=e.gmlRender.getScale(),i=s.points;for(let a=0;a<i.length-1;a++){const c=i[a],h=i[a+1];if(M.distance(c,h)<(A+6)/r)continue;const u=M.judgeHorizon(c,h),f=.5*(c.x+h.x),g=.5*(c.y+h.y);let y;if(u){const w=new m(f-8/r,g);y=new D(w.x,w.y-4/r,16/r,8/r)}else{const w=new m(f,g-8/r);y=new D(w.x-4/r,w.y,8/r,16/r)}const P=s.toLocal(t.globalPoint);if(M.rectContains(P,y))return this.result={isHorizon:u,line:s,point:new m(f,g),lIndex:a,rIndex:a+1},!0}return!1}}const Rp=[new m(.5,0),new m(1,.5),new m(.5,1),new m(0,.5)];class Ep extends Ke{onDetect(t,e){const n=e.getSelectNodes();if(n.size!==1)return!1;const o=[...n][0];if(!o.canQuickCreate())return!1;const s=e.renderManager.getScale(),r=M.computeNodeConnectAnchor(o,s),i=Ss/s;for(let a=0;a<r.length;a++){const c=r[a],h=o.toLocal(t.globalPoint);let d=Rp[a];if(M.circleContains(h,c,i))return o.type===v.Shape&&(d=o.drawer.getConnectAnchor()[a]),this.result={node:o,localPoint:c,globalPoint:o.toGlobal(c),relative:d},!0}return!1}}const Hp=new Set([v.Checkbox,v.Group,v.CheckboxText,v.Section,v.Line]),ws=class ws extends Ke{onDetect(t,e){const n=$t.flattenNodes([...e.getSelectNodes()]);if(n.length===0)return!1;const o=e.auxiliaryManager.selectManager.getSelectBounds();if(M.rectContains2(t.globalPoint,o)||e.detect(F.Stretch,t))return!1;const s=e.gmlRender.getScale(),r=ws.HOT_DISTANCE/s;let i=re.generateMatrix(),a,c,h;if(n.length===1){const d=n[0];if(Hp.has(d.type))return!1;const u=d.baseProps;i=d.globalTransform().clone();const f=new m(.5*u.width,.5*u.height);a=i.crossPoint(f),c=new D(0,0,u.width,u.height),h=i.inverseMatrix().crossPoint(t.globalPoint)}else{const d=e.auxiliaryManager.selectManager.getSelectBounds();c=D.rectNode2Rect(d),a=new m(.5*(d.minX+d.maxX),.5*(d.minY+d.maxY)),h=new m(t.globalPoint.x-c.x,t.globalPoint.y-c.y)}return M.circleContains({x:0,y:0},h,r)?(this.result={rotateCenter:a,nodes:n,cursorAngle:M.computeRotateAngle(n,180),rotateType:Zt.TOP_LEFT},!0):M.circleContains({x:c.width,y:0},h,r)?(this.result={rotateCenter:a,nodes:n,cursorAngle:M.computeRotateAngle(n,-90),rotateType:Zt.TOP_RIGHT},!0):M.circleContains({x:c.width,y:c.height},h,r)?(this.result={rotateCenter:a,nodes:n,cursorAngle:M.computeRotateAngle(n,0),rotateType:Zt.BOTTOM_RIGHT},!0):M.circleContains({x:0,y:c.height},h,r)?(this.result={rotateCenter:a,nodes:n,cursorAngle:M.computeRotateAngle(n,90),rotateType:Zt.BOTTOM_LEFT},!0):!1}};p(ws,"HOT_DISTANCE",16);let Jo=ws;class Dp extends Ke{onDetect(t,e){const n=e.detect(F.Node,t),o=e.docState.docMode===he.SLIDE_EDIT;if(!n){if(o){const r=M.getSlideContainerChildNode(e.docState.slideStatus.slideContainer,e.docState.slideStatus.currentIndex,e);return this.result=r,!0}return!1}const s=e.getSelectNodes();for(const r of n)if(!s.has(r)&&r.type===v.Section)return this.result=r,!0;if(o){const r=M.getSlideContainerChildNode(e.docState.slideStatus.slideContainer,e.docState.slideStatus.currentIndex,e);return this.result=r,!0}return!1}}class Op extends jt{constructor(){super(),this.registerDownHandler(new er),this.registerDownHandler(new tr),this.registerUpHandler(new nr),this.registerUpHandler(new Ba),this.registerUpHandler(new or)}}class Xp extends pn{constructor(){super([new Op])}}class zp extends jt{constructor(){super(),this.registerDownHandler(new qa)}}class Wp extends js{constructor(){super([new zp])}}class Fp extends _o{constructor(){super(...arguments);p(this,"handlers",[new sr])}}class Yp{constructor(){p(this,"allowEventTypeSet",new Set([be.pointermove]));p(this,"handlers",[new Da,new Xa,new za,new Oa])}process(t,e){const n=e.detect(F.HoverNode,t);if(n){for(const o of this.handlers)if(o.enable(n)){o.handle(n,e);return}}}}class Gp extends Ot{constructor(){super([new Yp,new Fp])}canBeEnable(t,e){return!0}canBeExit(t,e){return!0}}class Up extends fn{constructor(){super([new qs,new Wp,new Xp,new Gp])}canBeEnable(t,e){return!e.docState.canEdit()}}class _p extends Ke{onDetect(t,e){const n=[...e.getSelectNodes()];if(n.length!==1)return!1;const o=n[0];if(o.type!==v.IMG)return!1;const s=e.detect(F.Node,t);return s&&e.auxiliaryManager.selectManager.include(s[0])?(this.result=o,!0):!1}}class $p extends kn{constructor(){super([new Ja])}streamEnable(t,e){return!0}}class jp{constructor(){p(this,"allowEventTypeSet",new Set([be.pointermove]))}process(t,e){e.setCursor("grab")}}class Vp extends Ot{constructor(){super([new jp])}canBeEnable(t,e){return!0}canBeExit(t,e){return!0}}class Kp extends fn{constructor(){super([new $p,new Vp])}canBeEnable(t,e){return e.toolManager.currentTool===ye.HandTool}}class Qp extends gt{enable(t,e){return!!e.detect(F.ImageOriginBounds,t)}handle(t,e){const n=e.detect(F.ImageOriginBounds,t);n.type===V.BOTTOM||n.type===V.TOP?e.setCursor("ns-resize"):n.type===V.RIGHT||n.type===V.LEFT?e.setCursor("ew-resize"):n.type===V.TOP_LEFT||n.type===V.BOTTOM_RIGHT?e.setCursor("nwse-resize"):(n.type===V.TOP_RIGHT||n.type===V.BOTTOM_LEFT)&&e.setCursor("nesw-resize")}}class Zp extends _o{constructor(){super(...arguments);p(this,"handlers",[new Ga,new Qp,new sr])}}class qp extends Ot{constructor(){super([new Zp])}canBeEnable(t,e){return!0}canBeExit(t,e){return!0}}class Jp extends ht{constructor(){super(...arguments);p(this,"limitBounds");p(this,"imgNode");p(this,"lastPoint");p(this,"stretchRect");p(this,"transform");p(this,"stretchType")}onStart(e,n){const o=n.detect(F.Stretch,e);this.stretchType=o.type;const s=[...n.getSelectNodes()][0];this.imgNode=s;const r=s.getOriginImageRect().clone(),i=s.toGlobal({x:r.x,y:r.y}),a=this.imgNode.globalBaseProps;this.limitBounds=new D(i.x,i.y,r.width,r.height);const c=re.generateMatrix().rotate(a.angle),d=re.generateMatrix().translate(i.x,i.y).crossProduct(c);this.transform=d.inverseMatrix(),this.lastPoint=this.transform.crossPoint(e.globalPoint);const u=new m(a.x,a.y),f=this.transform.crossPoint(u);this.stretchRect=new D(f.x,f.y,a.width,a.height),n.execAction(new W)}onCropNode(e,n,o){const s=this.transform.crossPoint(e.globalPoint),r=new m(s.x-this.lastPoint.x,s.y-this.lastPoint.y);this.lastPoint=s;const i=this.stretchRect;switch(this.stretchType){case V.TOP:i.y=i.y+r.y,i.height=i.height-r.y;break;case V.BOTTOM:i.height=i.height+r.y;break;case V.LEFT:i.x=i.x+r.x,i.width=i.width-r.x;break;case V.RIGHT:i.width=i.width+r.x;break;case V.TOP_LEFT:i.y=i.y+r.y,i.height=i.height-r.y,i.x=i.x+r.x,i.width=i.width-r.x;break;case V.TOP_RIGHT:i.y=i.y+r.y,i.height=i.height-r.y,i.width=i.width+r.x;break;case V.BOTTOM_LEFT:i.x=i.x+r.x,i.width=i.width-r.x,i.height=i.height+r.y;break;case V.BOTTOM_RIGHT:i.width=i.width+r.x,i.height=i.height+r.y;break}const a=this.modifyStretchRect(i),c=new m(a.x,a.y),h=this.transform.inverseMatrix().crossPoint(c),d=this.imgNode.parent.toLocal(h),u=[{type:I.Base,x:d.x,y:d.y,width:a.width,height:a.height}];n.execAction(U.create(this.imgNode.id,u,{streaming:o}));const f=this.imgNode.toLocal(new m(this.limitBounds.x,this.limitBounds.y));n.execAction(U.create(this.imgNode.id,[{type:I.Crop,cropInfo:{imgX:f.x,imgY:f.y,imgWidth:this.limitBounds.width,imgHeight:this.limitBounds.height}}],{streaming:o}))}onMove(e,n){this.onCropNode(e,n,!0)}modifyStretchRect(e){const n=new D(e.x,e.y,e.width,e.height);return n.width<10&&(n.width=10),n.height<10&&(n.height=10),e.x<0?(n.x=0,n.width=e.x+e.width):e.x+e.width>this.limitBounds.width&&(n.width=this.limitBounds.width-e.x),e.y<0?(n.y=0,n.height=e.y+e.height):e.y+e.height>this.limitBounds.height&&(n.height=this.limitBounds.height-e.y),n}onUp(e,n){this.onCropNode(e,n,!1),n.execAction(new z)}}class ef extends dt{constructor(){super([new Jp])}streamEnable(t,e){return!!e.detect(F.Stretch,t)}}class tf extends gn{enable(t){return t.type===v.IMG}handle(t,e,n,o,s){const r=e.crop,i=e.crop.globalImgPos,a=r.originCropProps,c=a.cropType,h=r.originTransform,d=s.crossPoint(i),u=h.crossPoint(d);return[{id:t.id,props:[{type:I.Crop,cropInfo:{imgX:u.x,imgY:u.y,imgWidth:a.cropInfo.imgWidth*n,imgHeight:a.cropInfo.imgHeight*o},cropType:c}]}]}}class nf extends Go{constructor(){super(...arguments);p(this,"handlers",[new tf])}computeAnchorPoint(e,n){const o=this.target.nodes[0],{x:s,y:r,width:i,height:a}=o.getOriginImageRect();switch(e.type){case V.TOP:return this.alignType=_e.height,{x:s,y:r+a};case V.RIGHT:return this.alignType=_e.width,{x:s,y:r};case V.BOTTOM:return this.alignType=_e.height,{x:s,y:r};case V.LEFT:return this.alignType=_e.width,{x:s+i,y:r};case V.TOP_LEFT:return this.alignType=_e.both,{x:s+i,y:r+a};case V.TOP_RIGHT:return this.alignType=_e.both,{x:s,y:r+a};case V.BOTTOM_RIGHT:return this.alignType=_e.both,{x:s,y:r};case V.BOTTOM_LEFT:default:return this.alignType=_e.both,{x:s+i,y:r}}}judgeUniform(e){this.isUniform=!0}computeTarget(e,n){const o=n.detect(F.ImageOriginBounds,e),s=[...n.getSelectNodes()];this.target={type:o.type,nodes:s,angle:M.computeStretchAngle(s,o.type)}}alignStretchGlobalPoint(e,n){const o=[...n.getSelectNodes()][0],s=o.toLocal(e.globalPoint),r=o.baseProps,i=e.globalPoint.clone(),a=this.target.type;return s.x>0&&(a===V.LEFT||a===V.BOTTOM_LEFT||a===V.TOP_LEFT)&&(i.x=o.toGlobal({x:0,y:0}).x),s.x<r.width&&(a===V.RIGHT||a===V.BOTTOM_RIGHT||a===V.TOP_RIGHT)&&(i.x=o.toGlobal({x:r.width,y:0}).x),s.y>0&&(a===V.TOP||a===V.TOP_RIGHT||a===V.TOP_LEFT)&&(i.y=o.toGlobal({x:0,y:0}).y),s.y<r.height&&(a===V.BOTTOM||a===V.BOTTOM_RIGHT||a===V.BOTTOM_LEFT)&&(i.y=o.toGlobal({x:0,y:r.height}).y),i}computeOriginTransform(e){const n=this.target,o=[...e.getSelectNodes()][0],{x:s,y:r,angle:i}=o.globalBaseProps,a=re.generateMatrix().rotate(-i),c=re.generateMatrix().translate(-s,-r),h=this.computeAnchorPoint(n,D.baseProps2Rect(o.baseProps)),u=re.generateMatrix().translate(-h.x,-h.y).crossProduct(a.crossProduct(c));this.originTransform=u}drawAlignLine(e,n,o){const s=this.target.nodes[0],r=s.baseProps,{width:i,height:a}=n,c=s.globalTransform().clone();if(i){e.width+=i.dt;const h={transform:c,line:{start:new m(0,r.height),end:new m(r.width,r.height)}};i.lines.push(h)}if(a){e.height+=a.dt;const h={transform:c,line:{start:new m(r.width,0),end:new m(r.width,r.height)}};a.lines.push(h)}o.addOrUpdate(N.AlignStretchLine,{alignInfo:n})}getMiniSize(e){const n=this.target.type,o=this.target.nodes[0],s=o.baseProps,{x:r,y:i,width:a,height:c}=o.getOriginImageRect(),h=a/c;switch(n){case V.BOTTOM:case V.RIGHT:case V.BOTTOM_RIGHT:{const d=s.width-r,u=s.height-i,f=u*h;return d>f?new m(d,d/h):new m(f,u)}case V.LEFT:case V.BOTTOM_LEFT:{const d=a+r,u=s.height-i,f=u*h;return d>f?new m(d,d/h):new m(f,u)}case V.TOP_LEFT:{const d=a+r,u=c+i,f=u*h;return d>f?new m(d,d/h):new m(f,u)}case V.TOP:case V.TOP_RIGHT:{const d=s.width-r,u=c+i,f=u*h;return d>f?new m(d,d/h):new m(f,u)}default:return new m(s.width,s.height)}}getStretchRect(e){const n=[...e.getSelectNodes()][0],o=D.baseProps2Rect(n.baseProps),s=n.getOriginImageRect();return o.width=s.width,o.height=s.height,o.x=o.x-s.x,o.y=o.y-s.y,o}recordPropsMap(e){this.propsMap.clear();const n=this.target.nodes;for(const o of n){const s=this.recordNodePropInfo(o);this.propsMap.set(o,s)}}afterStretchNode(e,n,o,s,r,i,a){e.asyncRenderNodeManager.batchAddRenderNode(a)}}class of extends dt{constructor(){super([new nf])}streamEnable(t,e){return!!e.detect(F.ImageOriginBounds,t)}}class sf extends ht{constructor(){super(...arguments);p(this,"lastPoint");p(this,"originImgRect");p(this,"imgNode");p(this,"limitBounds");p(this,"transform");p(this,"dragRect")}onStart(e,n){this.imgNode=[...n.getSelectNodes()][0],this.originImgRect=this.imgNode.getOriginImageRect().clone();const o=this.imgNode.globalBaseProps,s=this.imgNode.toGlobal({x:this.originImgRect.x,y:this.originImgRect.y});this.limitBounds=new D(s.x,s.y,this.originImgRect.width,this.originImgRect.height);const r=re.generateMatrix().rotate(o.angle),a=re.generateMatrix().translate(s.x,s.y).crossProduct(r);this.transform=a.inverseMatrix();const c=this.transform.crossPoint({x:o.x,y:o.y});this.dragRect=new D(c.x,c.y,o.width,o.height),this.lastPoint=this.transform.crossPoint(e.globalPoint),n.execAction(new W)}onMove(e,n){this.dragCrop(e,n,!0)}onUp(e,n){this.dragCrop(e,n,!1),n.execAction(new z)}dragCrop(e,n,o){const s=this.imgNode.cropProps.cropInfo,r=this.modifyCropBasePos(e,n),i=this.imgNode.parent.toLocal(r),a=[{type:I.Base,x:i.x,y:i.y}];n.execAction(new U({infos:[{id:this.imgNode.id,props:a}]},{streaming:o}));const c=this.imgNode.toLocal(this.limitBounds),h={imgX:c.x,imgY:c.y,imgWidth:s.imgWidth,imgHeight:s.imgHeight},d=[{type:I.Crop,cropInfo:h}];n.execAction(new U({infos:[{id:this.imgNode.id,props:d}]},{streaming:o}))}modifyCropBasePos(e,n){const o=e.globalPoint,s=this.transform.crossPoint(o),r=s.x-this.lastPoint.x,i=s.y-this.lastPoint.y,a=this.dragRect;a.x+=r,a.y+=i;const c=this.imgNode.baseProps,h=new m(a.x,a.y);a.x+a.width>this.limitBounds.width?h.x=this.limitBounds.width-c.width:a.x<0&&(h.x=0),a.y<0?h.y=0:a.y+a.height>this.limitBounds.height&&(h.y=this.limitBounds.height-c.height);const d=this.transform.inverseMatrix().crossPoint(h);return this.lastPoint=s,d}}class rf extends dt{constructor(){super([new sf])}streamEnable(t,e){const n=[...e.getSelectNodes()];return n.length!==1||!e.cropManager.duringCrop?!1:!!n[0].contains(t.globalPoint)}}class wo{intoCrop(t){const e=t.getSelectNodes();if(e.size!==1)return;const n=[...e][0];if(!(n instanceof Fn)||t.cropManager.duringCrop)return;t.cropManager.intoCrop(),t.auxiliaryManager.selectManager.refreshSelectStatus(),t.renderManager.addAuxiliaryDrawTask();const s=n.cropProps;if(!s.cropInfo||s.cropType===wt.None){const{width:r,height:i}=n.baseProps;t.execAction(new W),t.execAction(U.create(n.id,[{cropType:wt.Rect,cropInfo:{imgX:0,imgY:0,imgWidth:r,imgHeight:i},type:I.Crop}])),t.execAction(new z)}}exitCrop(t){if(t.cropManager.duringCrop){t.cropManager.exitCrop(),t.auxiliaryManager.selectManager.refreshSelectStatus(),t.renderManager.addAuxiliaryDrawTask();return}}resetCrop(t){const e=t.getSelectNodes();if(e.size!==1)return;const n=[...e][0];if(!(n instanceof Fn)||!t.cropManager.duringCrop)return;const s=n.cropProps;if(!s.cropInfo||s.cropType===wt.None)return;const r=n.getOriginImageRect(),i=new m(r.x,r.y),a=n.toGlobal(i),c=n.parent.toLocal(a);t.execAction(new W),t.execAction(U.create(n.id,[{cropType:wt.None,type:I.Crop},{type:I.Base,x:c.x,y:c.y,width:r.width,height:r.height}])),t.execAction(new z),t.cropManager.exitCrop(),t.auxiliaryManager.selectManager.refreshSelectStatus()}}class af extends qe{constructor(){super(...arguments);p(this,"worker",new wo)}enable(e,n){const o=[...n.getSelectNodes()];if(o.length!==1)return!1;const s=o[0],r=s.toLocal(e.globalPoint),i=s.getOriginImageRect();return n.detect(F.ImageOriginBounds,e)?!1:!M.rectContains(r,i)}handle(e,n){this.worker.exitCrop(n),n.auxiliaryManager.slotManager.addSlotState(ze.ExitCrop,!0)}}class cf extends jt{constructor(){super(),this.registerDownHandler(new af)}}class lf extends pn{constructor(){super([new cf])}}class hf extends fn{constructor(){super([new ef,new of,new rf,new lf,new qp])}canBeEnable(t,e){return e.cropManager.duringCrop}}class df extends Ke{onDetect(t,e){const n=e.getSelectNodes();if(n.size!==1)return!1;const o=[...n][0];if(o.type!==v.IMG||!e.cropManager.duringCrop)return!1;const s=o,{cropType:r,cropInfo:i}=s.cropProps;if(r===wt.None||!i)return!1;const a=8/e.renderManager.getScale(),c=s.getOriginImageRect(),h=o.toLocal(t.globalPoint),d=M.detectRectBounds(c,h,a);return d?(this.result={type:d.type},!0):!1}}class lr{constructor(){p(this,"alignWorker",new un)}computeLinePoints(t,e,n){return Ze.computeLinePoints(t,this.layoutHandler,e,n,this.alignWorker)}alignLinePointsInMove(t,e){return t}alignLinePointsInUp(t,e){return t}computeDownProps(t,e,n,o){const r=[new Oe(e.toolManager.shapeType)],i=e.detect(F.NodeEdge,e.lastDiffTypeEvent);if(i){const y={type:I.Connect,start:{objectId:i.node.id,x:i.relativePos.x,y:i.relativePos.y}};t.point=new m(i.point.x,i.point.y),t.nodeConnect={rect:D.rectNode2Rect(i.node.getBounds()),endType:M.computeNodeConnectEnd(i.relativePos,i.node.baseProps.angle)},r.push(y)}else r.push(new Rt);const a={point:new m(t.point.x+1,t.point.y+1)},c=this.layoutHandler.layoutToPointsPro(t,a),h=o.globalTransform().inverseMatrix(),d=c.map(y=>h.crossPoint(y)),u=je.create(d),f=D.rectNode2Rect(M.getBoundsByPoints(d)),g=ie.create({x:f.x,y:f.y,width:f.width,height:f.height});return r.push(u,g,new Ae,lt.create({rArrow:it.Arrow}),Ge.create({sizeMode:We.autoWidth}),new Et),r}computeMoveProps(t,e,n,o){const s=M.dealWithShiftLineInteractEvent(e,o),r=this.computeLinePoints(t,s,n),i=this.alignLinePointsInMove(r,n),a=o.parent.globalTransform().inverseMatrix(),c=i.map(f=>a.crossPoint(f)),h=D.rectNode2Rect(M.getBoundsByPoints(c)),d=[je.create(c),ie.create({x:h.x,y:h.y,width:h.width,height:h.height})],u={infos:[{id:o.id,props:d}]};n.actionManager.execAction(new U(u,{streaming:!0}))}computeUpProps(t,e,n,o){const s=M.dealWithShiftLineInteractEvent(e,o),r=[],i=n.detect(F.NodeEdge,s);if(i){const g=o.connectProps.clone();g.end={objectId:i.node.id,x:i.relativePos.x,y:i.relativePos.y},r.push(g)}const a=this.computeLinePoints(t,s,n),c=this.alignLinePointsInUp(a,n),h=o.parent.globalTransform().inverseMatrix(),d=c.map(g=>h.crossPoint(g)),u=D.rectNode2Rect(M.getBoundsByPoints(d));r.push(je.create(d),ie.create({x:u.x,y:u.y,width:u.width,height:u.height}));const f={infos:[{id:o.id,props:r}]};n.actionManager.execAction(new U(f,{streaming:!1}))}}let es=class extends lr{constructor(){super(...arguments);p(this,"layoutHandler",new Xo)}enable(e){return e===de.Line}};class ts extends lr{constructor(){super(...arguments);p(this,"layoutHandler",new po)}enable(e){return e===de.Curve}}class ns extends lr{constructor(){super(...arguments);p(this,"layoutHandler",new Vt)}enable(e){return e===de.RoundPolyLine||e===de.PolyLine}alignLinePointsInMove(e,n){return M.dealWithEndPolyPoints(e,n.gmlRender.getScale(),!0)}alignLinePointsInUp(e,n){return M.dealWithEndPolyPointsInUp(e,n.gmlRender.getScale(),!0)}}class uc extends ht{constructor(){super(...arguments);p(this,"startConnectInfo",{point:new m});p(this,"target",null);p(this,"shapeType",de.Line);p(this,"currentHandler",null);p(this,"handlers",[new es,new ts,new ns])}selectHandler(){for(const e of this.handlers)if(e.enable(this.shapeType)){this.currentHandler=e;return}throw new Error("类型错误:没有合适的handler处理")}onStart(e,n){this.startConnectInfo.point=e.globalPoint,this.shapeType=n.toolManager.shapeType,this.selectHandler();const o=n.detect(F.HoverOnContainer,e);let s=n.nodeManager.root;o&&(s=o);const r=this.currentHandler.computeDownProps(this.startConnectInfo,n,e,s),i=n.idGenerator.genId(v.Line),a={id:i,type:v.Line,zIndex:ve.genZIndex(n.nodeManager.root),parentId:s.id,props:r};n.actionManager.execAction(new W);const c=Le.create(a);n.actionManager.execAction(c),this.target=n.nodeManager.nodeMap.get(i),n.actionManager.execAction(xe.create([this.target.id]))}onMove(e,n){this.currentHandler.computeMoveProps(this.startConnectInfo,e,n,this.target)}onUp(e,n){this.currentHandler.computeUpProps(this.startConnectInfo,e,n,this.target),n.execAction(new z),n.setCursor("default"),n.toolManager.resetTool()}}class pc extends dt{constructor(){super([new uc],[new $o,new jo,new Vo])}streamEnable(t,e){return e.toolManager.currentTool==ye.LINE}}class uf extends qe{constructor(){super(...arguments);p(this,"handlers",[new es,new ts,new ns])}enable(e,n){return!n.toolManager.creatingLine}handle(e,n){const o=n.idGenerator.genId(v.Line),s=this.makeupLineProps(e,n);if(!s)return;const r={id:o,type:v.Line,zIndex:ve.genZIndex(n.nodeManager.root),parentId:"",props:s};n.actionManager.execAction(new W);const i=Le.create(r);n.actionManager.execAction(i);const a=n.nodeManager.getNode(o);n.toolManager.setInCreatingLine(a)}makeupLineProps(e,n){const o={point:e.globalPoint},r=n.detect(F.HoverOnContainer,e)??n.nodeManager.root;for(const i of this.handlers)if(i.enable(n.toolManager.shapeType))return i.computeDownProps(o,n,e,r);return null}}class pf extends qe{constructor(){super(...arguments);p(this,"handlers",[new es,new ts,new ns])}enable(e,n){return n.previewManager.resetPreviewNode(n),n.auxiliaryManager.removeAlignGraphics(),!!n.toolManager.creatingLine}handle(e,n){const o=n.toolManager.creatingLine,s=this.getStartConnectInfo(o,n);for(const r of this.handlers)r.enable(o.shapeType)&&r.computeUpProps(s,e,n,o);n.execAction(new z),n.toolManager.setInCreatingLine(null),n.toolManager.resetTool(),n.setCursor("default")}getStartConnectInfo(e,n){const o=e.points,{start:s}=e.connectProps,r={point:o[0]};if(s){const i=n.nodeManager.getNode(s.objectId);i&&(r.nodeConnect={endType:M.computeNodeConnectEnd(s,i.baseProps.angle),rect:D.rectNode2Rect(i.getBounds())})}return r}}class ff extends jt{constructor(){super(),this.registerDownHandler(new pf),this.registerUpHandler(new uf)}}class gf extends pn{constructor(){super([new ff])}clickEnable(t,e){return e.toolManager.currentTool===ye.LINE}}class yf{constructor(){p(this,"allowEventTypeSet",new Set([be.pointermove]));p(this,"handlers",[new es,new ts,new ns])}process(t,e){const n=e.toolManager.creatingLine;if(!n)return;const o=this.getStartConnectInfo(n,e);for(const s of this.handlers)s.enable(n.shapeType)&&s.computeMoveProps(o,t,e,n)}getStartConnectInfo(t,e){const n=t.points,{start:o}=t.connectProps,s={point:n[0]};if(o){const r=e.nodeManager.getNode(o.objectId);r&&(s.nodeConnect={endType:M.computeNodeConnectEnd(o,r.baseProps.angle),rect:D.rectNode2Rect(r.getBounds())})}return s}}const xf=new Set([ye.LINE]);class wf extends fn{constructor(){super([new gf,new pc,new ac([new cc,new $o,new jo,new Vo,new yf,new lc,new hc])])}canBeEnable(t,e){return xf.has(e.toolManager.currentTool)}}class mf extends Ke{onDetect(t,e){const n=e.auxiliaryManager.selectManager.selectNodes;if(n.size!==1)return!1;const o=[...n][0];if(o.type!==v.Line)return!1;const s=o;if(s.shapeType!==de.Curve)return!1;const r=e.gmlRender.getScale(),i=M.computeBezierCurves(s);let a=0;for(const c of i){const h=c.getHalfTPos();if(M.circleContains(h,t.globalPoint,8/r))return this.result={line:s,midPoint:new m(h.x,h.y),lPoint:c.p0,rPoint:c.p3,curve:c,index:a},!0;a=a+3}return!1}}class Pf extends Ke{onDetect(t,e){const n=e.auxiliaryManager.selectManager.selectNodes;if(n.size!==1)return!1;const o=[...n][0];if(o.type!==v.Line)return!1;const s=o;if(s.shapeType!==de.Curve)return!1;const r=e.gmlRender.getScale(),i=M.computeBezierCurves(s);let a=0;for(const c of i){const h=[c.p0,c.p3];let d=0;for(const u of h){if(M.circleContains(u,t.globalPoint,8/r))return this.result={line:s,index:a+d},!0;d=d+3}a+=3}return!1}}class bf extends Ke{onDetect(t,e){if(e.inputManager.editTextInfo)return!1;const n=e.auxiliaryManager.selectManager.selectNodes;if(n.size!==1)return!1;const o=[...n][0];if(o.type!==v.Line)return!1;const s=o;if(s.renderText.isEmptyText())return!1;const r=s.toLocal(t.globalPoint),i=s.getTextContentRect();return M.rectContains(r,i)?(this.result={line:s},!0):!1}}class Mf extends Ot{constructor(){super([])}canBeEnable(t,e){return!0}canBeExit(t,e){return!0}}class Sf extends fn{constructor(){super([new Mf])}canBeEnable(t,e){return e.docState.docMode===he.SLIDE_PLAY}}class vf extends Ke{onDetect(t,e){var u;const n=[...e.getSelectNodes()];if(n.length!==1)return!1;const o=n[0];if(((u=o.parent)==null?void 0:u.type)!==v.SlideContainer||e.docState.docMode===he.SLIDE_EDIT)return!1;const r=o.parent,i=this.getRowColIndex(r,o.id);if(!i)return!1;const{x:a,y:c,height:h,width:d}=o.globalBaseProps;return M.rectContains(t.globalPoint,new D(a-nt,c,nt,h))?(this.result={slideContainer:r,i:i.i,j:i.j,point:{x:a-nt/2,y:c+h/2}},!0):M.rectContains(t.globalPoint,new D(a+d,c,nt,h))?(this.result={slideContainer:r,i:i.i,j:i.j+1,point:{x:a+d+nt/2,y:c+h/2}},!0):!1}getRowColIndex(t,e){const n=t.slideProps.children;let o=0,s=0;for(const r of n){s=0;for(const i of r.ids){if(e===i)return{i:o,j:s};s++}o++}return null}}class If extends Ke{onDetect(t,e){const n=e.detect(F.Node,t);if(!n)return!1;const o=n[0];if(o.type!==v.SlideContainer||!e.auxiliaryManager.selectManager.include(o))return!1;const s=o;if(s.slideProps.children.length!==0)return!1;const{x:i,y:a,height:c,width:h}=o.globalBaseProps,d=new D(i+nt,a+xt,h-2*nt,c-2*xt);return M.rectContains(t.globalPoint,d)?(this.result={slideContainer:s,rect:d},!0):!1}getRowColIndex(t,e){const n=t.slideProps.children;let o=0,s=0;for(const r of n){s=0;for(const i of r.ids){if(e===i)return{i:o,j:s};s++}o++}return null}}class hr extends oa{constructor(){super(...arguments);p(this,"detectors",new Map([[F.Node,new sa],[F.HoverNode,new ra],[F.PolyControlPoint,new dc],[F.CurveControlPoint,new mf],[F.Rotate,new Jo],[F.Stretch,new Fo],[F.ExpandShape,new tc],[F.LineEndPoint,new nc],[F.NodeEdge,new up],[F.BufferNode,new Ap],[F.BufferHoverNode,new kp],[F.HoverNodeAnchor,new Bp],[F.HoverConnectAnchor,new Ep],[F.HoverOnContainer,new Dp],[F.Image,new _p],[F.ImageOriginBounds,new df],[F.CurveEndPoint,new Pf],[F.DragLineText,new bf],[F.SlideGap,new vf],[F.EmptySlideContainer,new If]]));p(this,"modes",[new Sf,new Kp,new Up,new hf,new wf,new Cp,new ec])}}const Tf={[K.Ellipse]:"#F2F3F5",[K.Hexagon]:"#F2F3F5",[K.Cloud]:"#F2F3F5",[K.YuanZhu]:"#F0FBEF",[K.Parallelogram]:"#F0FBEF",[K.Trapezoid]:"#E1EAFF",[K.Triangle]:"#E1EAFF",[K.Triangle2]:"#E1EAFF",[K.RightArrow]:"#E1EAFF",[K.DoubleArrow]:"#E1EAFF",[K.LeftArrow]:"#E1EAFF",[K.RoundRect]:"#E0E2FA",[K.RoundRect2]:"#E0E2FA",[K.Rect]:"#E0E2FA",[K.LiuCheng]:"#E0E2FA",[K.LiuCheng2]:"#E0E2FA",[K.Diamond]:"#FEEAD2",[K.Star]:"#FEEAD2",[K.Qipao]:"#FEF1F1",[K.Qipao2]:"#FEF1F1",[K.RightKuohao]:"#FEF1F1",[K.LeftKuohao]:"#FEF1F1"},Lf={[K.Ellipse]:"#DEE0E3",[K.Hexagon]:"#DEE0E3",[K.Cloud]:"#DEE0E3",[K.YuanZhu]:"#8EE085",[K.Parallelogram]:"#8EE085",[K.Trapezoid]:"#82A7FC",[K.Triangle]:"#82A7FC",[K.Triangle2]:"#82A7FC",[K.RightArrow]:"#82A7FC",[K.DoubleArrow]:"#82A7FC",[K.LeftArrow]:"#82A7FC",[K.RoundRect]:"#7B83EA",[K.RoundRect2]:"#7B83EA",[K.Rect]:"#7B83EA",[K.LiuCheng]:"#7B83EA",[K.LiuCheng2]:"#7B83EA",[K.Diamond]:"#FFBA6B",[K.Star]:"#FFBA6B",[K.Qipao]:"#F98E8B",[K.Qipao2]:"#F98E8B",[K.RightKuohao]:"#F98E8B",[K.LeftKuohao]:"#F98E8B"},Cf=(l,{x:t,y:e,width:n,height:o})=>l.x>=t&&l.x<=t+n&&l.y>=e&&l.y<=e+o;class Vt extends Fs{enable(t){return t.isPolyLine()}layoutToPoints(t,e){const n=t.lineProps,{start:o,end:s}=t.connectProps,r=[...t.globalLinePoints];if(!n.auto&&r.length>2){if(o){const c=r[0],h=r[1],d=M.judgeHorizon(c,h),u=e.nodeManager.getNode(o.objectId);if(u){const f=this.getNodePos(u,o);c.x=f.x,c.y=f.y}d?h.y=c.y:h.x=c.x}if(s){const c=r[r.length-2],h=r[r.length-1],d=M.judgeHorizon(c,h),u=e.nodeManager.getNode(s.objectId);if(u){const f=this.getNodePos(u,s);h.x=f.x,h.y=f.y}d?c.y=h.y:c.x=h.x}const i=t.globalTransform().inverseMatrix();return r.map(c=>i.crossPoint(c))}else{const i=this.getLayoutHandler(t,o,e),a=this.computeLayout(i,t,s,e),c=t.globalTransform().inverseMatrix();return a.map(d=>c.crossPoint(d))}}layoutToPointsPro(t,e){const n=this.getLayoutHandlerV2(t);return this.computePointsV2(n,e)}getLayoutHandlerV2({point:t,nodeConnect:e}){if(!e)return new $i(t);const{rect:n,endType:o}=e;switch(o){case ue.Top:return new Wd(t,n);case ue.Bottom:return new Fd(t,n);case ue.Left:return new Yd(t,n);case ue.Right:return new Gd(t,n);default:return new $i(t)}}computePointsV2(t,{point:e,nodeConnect:n}){if(!n)return t.toPoint(e);const{rect:o,endType:s}=n;switch(s){case ue.Right:return t.right(e,o);case ue.Left:return t.left(e,o);case ue.Bottom:return t.bottom(e,o);case ue.Top:return t.top(e,o);default:return t.toPoint(e)}}getLayoutHandler(t,e,n){const o={point:t.globalLinePoints[0]};if(e){const s=n.nodeManager.getNode(e.objectId);s&&(o.nodeConnect={rect:D.rectNode2Rect(s.getBounds()),endType:M.computeNodeConnectEnd(e,s.baseProps.angle)},o.point=this.getNodePos(s,e))}return this.getLayoutHandlerV2(o)}computeLayout(t,e,n,o){const s=Ze.computeConnectInfo(e,n,o,!0);return this.computePointsV2(t,s)}}class Af{constructor(){p(this,"workerMap",new Map)}init(t){this.workerMap.clear();for(const e of t){const n=new $n;n.init(e),this.workerMap.set(e,n)}}work(t,e,n){for(const o of t){const s=this.workerMap.get(o);s&&s.work(o,e,n)}}}class Rn{constructor(){p(this,"handlers",[new Xo,new po,new Vt]);p(this,"batchLineTextWorker",new Af)}work(t,e,n){this.batchLineTextWorker.init(t);for(const o of t)this.handleAndMsg(o,e,n);this.batchLineTextWorker.work(t,e,n)}layoutToPoints(t,e){for(const n of this.handlers)if(n.enable(t))return n.layoutToPoints(t,e);return[]}handleAndMsg(t,e,n){for(const o of this.handlers)if(o.enable(t)){const s=o.handle(t,e);e.execAction(new U(s,{streaming:n}));return}}batchCollectNodeLinks(t,e,n){const o=new Set(t);for(const s of t)this.collectNodeLinks(s,e,n,o)}collectNodeLinks(t,e,n,o=new Set){const s=e.nodeManager.getNodeLinks(t);for(const r of s){const{start:i,end:a}=r.connectProps;M.judgeEndNode(r,n,i,e,o),M.judgeEndNode(r,n,a,e,o)}for(const r of t.children){if(r.type===v.Line){const i=r,{start:a,end:c}=i.connectProps;M.judgeEndNode(i,n,a,e,o),M.judgeEndNode(i,n,c,e,o)}this.collectNodeLinks(r,e,n,o)}}judgeEndNode(t,e,n,o,s){if(!n)return;const r=o.nodeManager.getNode(n.objectId);r&&!M.judgeParentInset(r,s)&&e.add(t)}}class kf{constructor(){p(this,"layoutWorker",new Rn);p(this,"groupBaseWorker",new on)}work(t,e,n){let o=!1;if(this.groupBaseWorker.start([e]),t.textProps.sizeMode===We.autoWidth){const s=e.getTextContentRect(),{width:r,height:i}=e.baseProps,a=r-s.width,c=t.height+(i-s.height)+.2;n.execAction(U.create(e.id,[{type:I.Base,width:t.width+a,height:c}])),o=!0}else if(t.textProps.sizeMode===We.autoHeight&&e instanceof vt){let s=e.drawer.fullTextNodeHeight(e);s<100&&(s=100),n.execAction(U.create(e.id,[{type:I.Base,height:s}])),o=!0}if(o){const s=new Set;this.groupBaseWorker.work(n,!1),this.layoutWorker.collectNodeLinks(e,n,s),this.layoutWorker.work([...s],n,!1)}}}class Nf{work(t,e,n){const o=e.lineTextRect,s=new m(o.point.x,o.point.y),r=t.width,i=t.height;n.execAction(U.create(e.id,[{type:I.LineTextRect,x:s.x-.5*r,y:s.y-.5*i,width:r,height:i}]))}}class mo{constructor(){p(this,"prevStringBuilder",{text:""});p(this,"nextStringBuilder",{text:""});p(this,"currentbuilder",this.prevStringBuilder);p(this,"layoutWorker",new Rn);p(this,"groupBaseWorker",new on);p(this,"nodeModifyBaseWorker",new kf);p(this,"lineModifyWorker",new Nf)}switchCurrentBuilder(t,e){return this.currentbuilder===this.nextStringBuilder?!1:t.equal(e)?(this.currentbuilder=this.nextStringBuilder,!0):!1}splitText(t,e){this.prevStringBuilder={text:""},this.nextStringBuilder={text:""},this.currentbuilder=this.prevStringBuilder;let n=-1,o=0;for(let s=0;s<t.paragraphs.length;s++){const r=t.paragraphs[s];for(let i=0;i<r.lines.length;i++){const a=r.lines[i];this.switchCurrentBuilder(e,new Fe(s,i,-1))&&(o=n);const h=a.getCharLength();for(let d=0;d<h;d++){const{character:u}=a.getCharacter(d);this.currentbuilder.text+=u.charText,n++,this.switchCurrentBuilder(e,new Fe(s,i,d))&&(o=n)}}s<t.paragraphs.length-1&&(this.currentbuilder.text+=`
|
|
5
5
|
`,n++)}return{prev:this.prevStringBuilder.text,next:this.nextStringBuilder.text,index:o}}editText(t,e,n){const{paragraphIndex:o,lineIndex:s,charIndex:r}=e,i=t.prevParagraphToXML(o),a=t.nextParagraphToXML(o),c=t.getParagraph(o),h=c.prevToRichTextXML(s,t.textProps),d=c.nextToRichTextXML(s,t.textProps),u=c.getLine(s),f=u.getBlockIndex(r);if(f){const{textBlock:g,blockIndex:y,charIndex:P}=f,b=u.prevToRichTextXML(y,t.textProps),w=u.nextToRichTextXML(y,t.textProps),L=g.insertTextToRichTextXML(n,P,t.textProps);return`<root>${i}<p>${h}${b}${L}${w}${d}</p>${a}</root>`}return`<root>${i}<p>${h}${n}${d}</p>${a}</root>`}modifyBaseProps(t,e,n){e.type===v.Shape?this.nodeModifyBaseWorker.work(t,e,n):e.type===v.Line&&this.lineModifyWorker.work(t,e,n)}}class Bf{measure(t,e,n){const o=[];t.font=M.calcFontByTextProps(n);for(const s of e){const r=new _i;for(const i of[...s]){const{width:a,height:c,boxAscent:h}=M.measureText(t,i),d=new As(i,0,0,a,c,h);r.addCharacter(d)}o.push(r)}return o}}class fc{constructor(){p(this,"streaming",!1)}}class yn{constructor(t,e){p(this,"meta",new fc);p(this,"data");p(this,"reverseLog",null);this.data=t,e&&(this.meta=e)}reverse(){if(this.reverseLog===null)throw new Error("缺少对应逆消息");return this.reverseLog}}var Lt=(l=>(l[l.Focus=0]="Focus",l[l.Selection=1]="Selection",l[l.Blur=2]="Blur",l[l.Empty=3]="Empty",l))(Lt||{});class ee extends yn{constructor(){super(...arguments);p(this,"type",Xe.TextFocus)}static focus(e,n=Fe.head()){return new ee({focusType:Lt.Focus,focus:{id:e,textCursorPosition:n}})}static selection(e,n,o){return new ee({focusType:Lt.Selection,selection:{id:e,start:n,end:o}})}static blur(e){return new ee({blur:{id:e},focusType:Lt.Blur})}static empty(){return new ee({focusType:Lt.Empty})}clone(){const e=JSON.parse(JSON.stringify(this.data));return new ee(e,this.meta)}}class gc{constructor(){p(this,"cursorMoveWorker",new ho)}work(t,e,n=1){const{node:o,renderText:s,textCursorPosition:r}=t,{updateTextProps:i}=this.computeUpdateTextProps(t,n);let a=r;for(let c=0;c<n;c++)a=this.cursorMoveWorker.moveLeft(s,a);e.execAction(new W),e.execAction(U.create(o.id,[i])),e.execAction(ee.focus(o.id,a)),e.execAction(new z)}computeUpdateTextProps(t,e){const{renderText:n,textCursorPosition:o}=t,s=this.deleteText(n,o,e);return{updateTextProps:{type:I.Text,richText:s}}}deleteText(t,e,n){if(n<=0)return t.toRichTextXML();const o=t.prevCursorPos(e,n),s=e;return this.deleteTextByCursorPos(t,o,s)}deleteTextByCursorPos(t,e,n){return e.equal(n)?t.toRichTextXML():this.generateDeletedXML(t,e,n)}generateDeletedXML(t,e,n){const{paragraphIndex:o,lineIndex:s,charIndex:r}=e,{paragraphIndex:i,lineIndex:a,charIndex:c}=n;return o===i?this.deleteSameParagraph(t,o,s,r,a,c):this.deleteCrossParagraph(t,o,s,r,i,a,c)}deleteSameParagraph(t,e,n,o,s,r){const i=t.prevParagraphToXML(e),a=t.nextParagraphToXML(e),c=t.getParagraph(e);if(n===s){const se=c.prevToRichTextXML(n,t.textProps),ne=c.nextToRichTextXML(s,t.textProps),ae=c.getLine(n),te=ae.getBlockIndex(o),ce=ae.getBlockIndex(r);if(!te||!ce)return`<root>${i}<p>${se}${ne}</p>${a}</root>`;const{blockIndex:pe,charIndex:Be}=te,{blockIndex:Re,charIndex:Me}=ce;if(pe===Re){const Ft=ae.prevToRichTextXML(pe,t.textProps),ln=ae.nextToRichTextXML(Re,t.textProps),On=te.textBlock,$e=On.getPrevText(Be),eo=On.getNextText(Me),to=$e+eo,Yt=`<style ${On.computeStyle(t.textProps)}>${to}</style>`;return`<root>${i}<p>${se}${Ft}${Yt}${ln}${ne}</p>${a}</root>`}const Te=ae.prevToRichTextXML(pe,t.textProps),fe=ae.nextToRichTextXML(Re,t.textProps),O=te.textBlock,G=ce.textBlock,j=O.getPrevText(Be),_=O.computeStyle(t.textProps),Ve=j?`<style ${_}>${j}</style>`:"",ut=G.getNextText(Me),yt=G.computeStyle(t.textProps),Nt=ut?`<style ${yt}>${ut}</style>`:"";return`<root>${i}<p>${se}${Te}${Ve}${Nt}${fe}${ne}</p>${a}</root>`}const h=c.prevToRichTextXML(n,t.textProps),d=c.nextToRichTextXML(s,t.textProps),u=c.getLine(n),f=c.getLine(s),g=u.getBlockIndex(o),y=f.getBlockIndex(r);if(!g||!y)return`<root>${i}<p>${h}${d}</p>${a}</root>`;const P=u.prevToRichTextXML(g.blockIndex,t.textProps),b=g.textBlock,w=b.getPrevText(g.charIndex),L=b.computeStyle(t.textProps),B=w?`<style ${L}>${w}</style>`:"",H=f.nextToRichTextXML(y.blockIndex,t.textProps),E=y.textBlock,X=E.getNextText(y.charIndex),$=E.computeStyle(t.textProps),Z=X?`<style ${$}>${X}</style>`:"";return`<root>${i}<p>${h}${P}${B}${Z}${H}${d}</p>${a}</root>`}deleteCrossParagraph(t,e,n,o,s,r,i){const a=t.prevParagraphToXML(e),c=t.nextParagraphToXML(s),h=t.getParagraph(e),d=t.getParagraph(s),u=h.prevToRichTextXML(n,t.textProps),f=h.getLine(n),g=f.getBlockIndex(o);let y="";if(g){const B=f.prevToRichTextXML(g.blockIndex,t.textProps),H=g.textBlock,E=H.getPrevText(g.charIndex),X=H.computeStyle(t.textProps),$=E?`<style ${X}>${E}</style>`:"";y=`${B}${$}`}const P=d.nextToRichTextXML(r,t.textProps),b=d.getLine(r),w=b.getBlockIndex(i);let L="";if(w){const B=b.nextToRichTextXML(w.blockIndex,t.textProps),H=w.textBlock,E=H.getNextText(w.charIndex),X=H.computeStyle(t.textProps);L=`${E?`<style ${X}>${E}</style>`:""}${B}`}return`<root>${a}<p>${u}${y}${L}${P}</p>${c}</root>`}}class os{constructor(){p(this,"deleteInputWorker",new gc)}work(t,e,n){n.execAction(ee.selection(t.node.id,e.start,e.end));const{node:o,renderText:s}=t,r=e.start;n.execAction(ee.focus(o.id,r));const i=this.deleteInputWorker.deleteTextByCursorPos(s,e.start,e.end),a={type:I.Text,richText:i};n.execAction(U.create(o.id,[a])),n.execAction(ee.focus(o.id,r))}}class ss{}class dr extends ss{enable(t,e){return t.paragraphIndex===e.paragraphIndex&&t.lineIndex===e.lineIndex}handle(t,e,n){const o=t.paragraphs[e.paragraphIndex],s=o.lines[e.lineIndex],r=s.getCharacter(n.charIndex);let i=0,a=0;if(e.charIndex>-1){const h=s.getCharacter(e.charIndex);i=h.textBlock.x+h.character.x+h.character.width,a=h.character.y}const c=new D(i,a,r.textBlock.x+r.character.x+r.character.width-i,s.height);return c.x+=s.x+o.x+t.x,c.y+=s.y+o.y+t.y,[c]}}class ur extends ss{enable(t,e){return t.paragraphIndex===e.paragraphIndex&&t.lineIndex!==e.lineIndex}handle(t,e,n){const o=[],s=t.paragraphs[e.paragraphIndex],r=s.lines[e.lineIndex],i=s.lines[n.lineIndex];let a=0,c=0;const h=r.getCharacter(e.charIndex);a=h===null?0:h.textBlock.x+h.character.x+h.character.width,c=h===null?0:h.character.y;const d=r.width-a;if(a+=r.x+s.x+t.x,c+=r.y+s.y+t.y,o.push(new D(a,c,d,r.height)),e.lineIndex+1===n.lineIndex&&n.charIndex===-1)return o;for(let f=e.lineIndex+1;f<n.lineIndex;f++){const g=s.lines[f];a=g.x+s.x+t.x,c=g.y+s.y+t.y,o.push(new D(a,c,g.width,g.height))}const u=i.getCharacter(n.charIndex);return u&&(a=i.x+s.x+t.x,c=i.y+s.y+t.y,o.push(new D(a,c,u.textBlock.x+u.character.x+u.character.width,i.height))),o}}class yc extends ss{constructor(){super(...arguments);p(this,"handlers",[new dr,new ur])}enable(e,n){return e.paragraphIndex!==n.paragraphIndex}handleSamePara(e,n,o){for(const s of this.handlers)if(s.enable(n,o))return s.handle(e,n,o);return[]}handle(e,n,o){const s=[],r=e.paragraphs[n.paragraphIndex],i=e.paragraphs[o.paragraphIndex],a=this.handleSamePara(e,n,r.tailCursorPosition());s.push(...a);for(let h=n.paragraphIndex+1;h<o.paragraphIndex;h++){const d=e.paragraphs[h];for(const u of d.lines)s.push(new D(e.x+d.x+u.x,e.y+d.y+u.y,u.width,u.height))}const c=this.handleSamePara(e,i.headCursorPosition(),o);return s.push(...c),s}}class xc{constructor(){p(this,"handlers",[new dr,new ur,new yc])}handleTextSelection(t,e,n){for(const o of this.handlers)if(o.enable(e,n))return o.handle(t,e,n);return[]}computeTextSelection(t,e,n){return e.equal(n)?[]:this.handleTextSelection(t,e,n)}}class wc{constructor(){p(this,"segmentWorker",new Intl.Segmenter("en",{granularity:"word"}))}split(t){return Array.from(this.segmentWorker.segment(t)).map(n=>n.segment)}}const Rf=new wc,He=16,ke=16,mc=[{x:0,y:0},{x:He,y:0},{x:He,y:ke},{x:0,y:ke}];class En{}class Ef extends En{drawOnGLCtx(t,e){const n=e.borderProps;t.strokeStyle=n.color,t.lineWidth=n.width,t.globalAlpha=n.alpha,t.moveTo(0,.5*ke),t.lineTo(He,.5*ke),t.moveTo(.5*He,0),t.lineTo(He,.5*ke),t.lineTo(.5*He,ke),t.stroke()}}class Hf extends En{drawOnGLCtx(t,e){const n=e.borderProps;t.fillStyle=n.color,t.strokeStyle=n.color,t.lineWidth=n.width,t.globalAlpha=n.alpha,t.moveTo(0,.5*ke),t.lineTo(.5*He,.5*ke),t.stroke(),t.beginPath(),t.moveTo(.5*He,0),t.lineTo(He,.5*ke),t.lineTo(.5*He,ke),t.closePath(),t.fill(),t.stroke()}}class Df extends En{drawOnGLCtx(t,e){const n=e.borderProps;t.strokeStyle=n.color,t.lineWidth=2,t.globalAlpha=n.alpha,t.moveTo(0,.5*ke),t.lineTo(.5*He,.5*ke),t.stroke(),t.beginPath(),t.moveTo(.5*He,0),t.lineTo(He,.5*ke),t.lineTo(.5*He,ke),t.closePath(),t.stroke()}}class Of extends En{drawOnGLCtx(t,e){const n=e.borderProps;t.fillStyle=n.color,t.lineWidth=n.width,t.globalAlpha=n.alpha,t.moveTo(0,.5*ke),t.lineTo(.5*He,.3*ke),t.lineTo(He,.5*ke),t.lineTo(.5*He,.7*ke),t.closePath(),t.fill()}}class Xf extends En{drawOnGLCtx(t,e){const n=e.borderProps;t.strokeStyle=n.color,t.lineWidth=2,t.globalAlpha=n.alpha,t.moveTo(0,.5*ke),t.lineTo(.5*He,.3*ke),t.lineTo(He,.5*ke),t.lineTo(.5*He,.7*ke),t.closePath(),t.stroke()}}class zf extends En{drawOnGLCtx(t,e){const n=e.borderProps;t.fillStyle=n.color,t.strokeStyle=n.color,t.lineWidth=n.width,t.globalAlpha=n.alpha;const o=Math.min(He,ke)*.3;if(o<=0||!Number.isFinite(o))return;t.moveTo(0,.5*ke),t.lineTo(He-o,.5*ke),t.stroke(),t.beginPath();const s=He,r=.5*ke;t.arc(s,r,o,0,2*Math.PI),t.fill(),t.stroke()}}class Wf extends En{drawOnGLCtx(t,e){const n=e.borderProps;t.strokeStyle=n.color,t.lineWidth=2,t.globalAlpha=n.alpha;const o=Math.min(He,ke)*.3;if(o<=0||!Number.isFinite(o))return;t.moveTo(0,.5*ke),t.lineTo(He-o,.5*ke),t.stroke(),t.beginPath();const s=He,r=.5*ke;t.arc(s,r,o,0,2*Math.PI),t.stroke()}}const wn=class wn extends en{constructor(e,n){super(e,n);p(this,"type",v.Line);p(this,"renderText");p(this,"inEditing",!1);p(this,"rArrowMatrix",re.generateMatrix());p(this,"lArrowMatrix",re.generateMatrix());this.props.set(I.Base,new ie),this.props.set(I.Border,new Ae),this.props.set(I.Shape,new Oe),this.props.set(I.Line,new je),this.props.set(I.Arrow,new lt),this.props.set(I.Connect,new Rt),this.props.set(I.Text,Ge.create({sizeMode:We.autoWidth})),this.props.set(I.LineTextRect,new Et),this.props.set(I.TextParagraph,new qt),this.props.set(I.TextParagraphQuote,new Dt),this.renderText=new uo}get globalPos(){const e=this.pos;return this.globalTransform().crossPoint(e)}get borderProps(){return this.props.get(I.Border)}get textProps(){return this.props.get(I.Text)}get paragraphProps(){return this.props.get(I.TextParagraph)}get paragraphQuoteProps(){return this.props.get(I.TextParagraphQuote)}get arrowProps(){return this.props.get(I.Arrow)}get shapeType(){return this.props.get(I.Shape).shapeCode}get lineProps(){return this.props.get(I.Line)}get globalLinePoints(){const e=this.lineProps.points,n=this.globalTransform();return e.map(s=>n.crossPoint(s))}get connectProps(){return this.props.get(I.Connect)}get points(){return this.lineProps.points}get lineTextRect(){return this.props.get(I.LineTextRect)}get drawer(){const e=this.shapeType;let n=wn.drawerMap.get(e);return n||(console.error("取不到drawer,使用line兜底!"),n=wn.drawerMap.get(de.Line)),n}canBeConnected(){return!1}getStretchMinSize(){return new m(10,10)}drawWithTextClip(e){const o=this.getTextContentRect();o.x-=2,o.y-=2,o.width+=2*2,o.height+=2*2;const s=D.rectNode2Rect(this.getRectNode());let r=new m(s.x,s.y);r=this.toLocal(r),e.save(),e.beginPath(),e.rect(r.x,r.y,s.width,s.height),e.rect(o.x,o.y,o.width,o.height),e.clip("evenodd"),this.drawCore(e),e.restore()}drawCore(e){const n=this.borderProps;M.setDashLine(n,e),e.save(),e.strokeStyle=n.color,e.globalAlpha=n.alpha,e.lineWidth=n.width,this.drawer.draw(this,e),e.restore(),e.beginPath(),this.drawArrow(e)}drawOnGLCtx(e){const n=!this.isEmptyText()||this.inEditing;e.save();const{a:o,b:s,c:r,d:i,e:a,f:c}=this.globalTransform();e.transform(o,s,r,i,a,c),n?this.drawWithTextClip(e):this.drawCore(e),this.drawText(e),e.restore()}drawText(e){const{alpha:n}=this.borderProps;e.save(),e.beginPath();const o=new m;this.renderText.draw(e,o,n),e.restore()}isEmptyText(){return this.renderText.isEmptyText()}updateProps(e){super.updateProps(e),this.updateLArrowMatrix(),this.updateRArrowMatrix();const n=e.find(c=>c.type===I.Text),o=e.find(c=>c.type===I.Base),s=e.find(c=>c.type===I.Line),r=e.find(c=>c.type===I.LineTextRect),i=e.find(c=>c.type===I.TextParagraph),a=e.find(c=>c.type===I.TextParagraphQuote);if(n||o||s||r||i||a){const c=this.getTextContentRect();this.renderText.typesetting(this.graphicContext,this.textProps,c,this.paragraphProps,this.paragraphQuoteProps)}}getArrowDrawer(e){const n=wn.arrowDrawerMap.get(e);return n||null}draw(){this.drawOnGLCtx(this.graphicContext)}getBounds(){const e=[...this.points],n=this.globalTransform(),o=e.map(r=>n.crossPoint(r));return M.getBoundsByPoints(o)}getRectNode(){const e=[...this.points],{lArrow:n,rArrow:o}=this.arrowProps;if(n)for(const c of mc)e.push(this.lArrowMatrix.crossPoint(c));if(o)for(const c of mc)e.push(this.rArrowMatrix.crossPoint(c));const s=this.globalTransform(),r=e.map(c=>s.crossPoint(c)),i=M.getBoundsByPoints(r),a=this.borderProps;return i.minX=i.minX-a.width,i.minY=i.minY-a.width,i.maxX=i.maxX+2*a.width,i.maxY=i.maxY+2*a.width,i.id=this.id,i}updateRArrowMatrix(){const{rArrow:e}=this.arrowProps;if(!e)return;const n=this.points,o=n[n.length-1],s=new m(He,.5*ke);let r=0;if(this.isPolyLine()){const u=n[n.length-2],f=o;M.judgeHorizon(u,f)?r=f.x>u.x?0:180:r=f.y>u.y?90:-90}else if(this.shapeType===de.Curve){const u=n[n.length-1],f=n[n.length-2],g=n[n.length-3];M.distance(u,f)>.1?r=M.lineAngle(f,u)/Math.PI*180:r=M.lineAngle(g,u)/Math.PI*180}else{const u=n[n.length-2];r=M.lineAngle(u,o)/Math.PI*180}const i=re.generateMatrix().translate(-.5*He,-.5*He),a=re.generateMatrix().rotate(r),c=i.crossProduct(a),h=c.crossPoint(s),d=re.generateMatrix().translate(o.x-h.x,o.y-h.y);this.rArrowMatrix=d.crossProduct(c)}updateLArrowMatrix(){const{lArrow:e}=this.arrowProps;if(!e)return;const n=this.points,o=n[0],s=new m(He,.5*ke);let r=0;if(this.isPolyLine()){const u=o,f=n[1];M.judgeHorizon(u,f)?r=f.x>u.x?180:0:r=f.y>u.y?-90:90}else if(this.shapeType===de.Curve){const u=n[0],f=n[1],g=n[2];M.distance(u,f)>.1?r=M.lineAngle(f,u)/Math.PI*180:r=M.lineAngle(g,u)/Math.PI*180}else{const u=n[1];r=M.lineAngle(u,o)/Math.PI*180}const i=re.generateMatrix().translate(-.5*He,-.5*He),a=re.generateMatrix().rotate(r),c=i.crossProduct(a),h=c.crossPoint(s),d=re.generateMatrix().translate(o.x-h.x,o.y-h.y);this.lArrowMatrix=d.crossProduct(c)}drawArrow(e){if(this.points.length===0){console.error("line has no point!");return}const o=this.arrowProps;if(o.rArrow){const s=this.getArrowDrawer(o.rArrow);if(s){e.save();const{a:r,b:i,c:a,d:c,e:h,f:d}=this.rArrowMatrix;e.transform(r,i,a,c,h,d),s.drawOnGLCtx(e,this),e.restore()}}if(o.lArrow){const s=this.getArrowDrawer(o.lArrow);if(s){e.save();const{a:r,b:i,c:a,d:c,e:h,f:d}=this.lArrowMatrix;e.transform(r,i,a,c,h,d),s.drawOnGLCtx(e,this),e.restore()}}}getRArrowPoint(e,n,o=5){const s=M.distance(e,n),r=new m(s-Math.sqrt(3)*.5*o,.5*o),i=new m(s-Math.sqrt(3)*.5*o,-.5*o);return this.basicGetArrowPoint(e,n,r,i)}basicGetArrowPoint(e,n,o,s){const r=M.lineAngle(e,n),i=re.generateMatrix().translate(e.x,e.y).rotate2(r),a=i.crossPoint(o),c=i.crossPoint(s);return{a,b:c}}static load(e,n,o,s,r,i){const a=new wn(e,i);return a.type=n,a.zIndex=o,a.setParent(r),a.updateProps(s),a}contains(e,n=1){const o=this.toLocal(e),s=this.getTextContentRect();if(M.rectContains(o,s))return!0;const r=8/n;return mi.lineContainsPoint(this,o,r)}overlapRect(e){const n=this.getBounds();return M.containRect(e,n)?!0:mi.overlapRectNode(this,e)}getTextContentRect(){const e=this.baseProps,{x:n,y:o,width:s,height:r}=this.lineTextRect;return new D(n+e.x,o+e.y,s,r)}isPolyLine(){const e=this.shapeType;return e===de.PolyLine||e===de.RoundPolyLine}modifyPosInEditing(){return this.inEditing=!0,!0}resetFromEditing(){this.inEditing=!1}getDrawPoints(){const{lArrow:e,rArrow:n}=this.arrowProps,o=[...this.points];if(e){const s=new m(0,.5*ke),r=this.lArrowMatrix.crossPoint(s);o.shift(),o.unshift(r)}if(n){const s=new m(0,.5*ke),r=this.rArrowMatrix.crossPoint(s);o.pop(),o.push(r)}return o}getLineLength(){const e=this.points;if(this.isPolyLine()){let s=0;for(let r=0;r<e.length-1;r++){const i=e[r],a=e[r+1],c=M.distance(i,a);s+=c}return s}if(this.shapeType===de.Curve){const s=M.computeBezierCurves(this);let r=0;for(const i of s){const a=i.getApproximateLength();r+=a}return r}const n=e[0],o=e[e.length-1];return M.distance(n,o)}};p(wn,"arrowDrawerMap",new Map([[it.Arrow,new Ef],[it.Triangle,new Hf],[it.EmptyTriangle,new Df],[it.Diamond,new Of],[it.EmptyDiamond,new Xf],[it.Circle,new zf],[it.EmptyCircle,new Wf]])),p(wn,"drawerMap",new Map([[de.Curve,new Wh],[de.RoundPolyLine,new Fh],[de.PolyLine,new zh],[de.Line,new Xh]]));let Ct=wn;class mt{buildPath(t,e){}draw(t,e){const n=t.colorProps,o=t.borderProps;e.lineJoin="round",e.lineCap="round",this.buildPath(t,e),n.color!==""&&(e.fillStyle=n.color,e.globalAlpha=n.alpha,e.fill()),o.color!==""&&o.dashType!==et.None&&(M.setDashLine(o,e),e.strokeStyle=o.color,e.lineWidth=o.width,e.globalAlpha=o.alpha,e.stroke())}getTextPadding(t){const e=t.textProps.fontSize;return e>10?le:e<4?0:1}fullTextNodeHeight(t){const e=this.getTextPadding(t);return t.renderText.height+2*e}textContentBounds(t){const e=t.baseProps,n=this.getTextPadding(t);return{x:n,y:n,width:e.width-2*n+2,height:e.height-2*n}}nodeShapeInfo(t){const{width:e,height:n}=t.baseProps;return q.rectangle({top:0,left:0,width:e,height:n})}borderContains(t,e,n){const o=this.nodeShapeInfo(t),s=q.line({x:e.x-n,y:e.y},{x:e.x+n,y:e.y}),r=q.line({x:e.x,y:e.y-n},{x:e.x,y:e.y+n});for(const i of[s,r]){const a=Y.intersect(o,i);if(a.points.length>0)return a.points[0]}return null}getConnectAnchor(){return[new m(.5,0),new m(1,.5),new m(.5,1),new m(0,.5)]}}class Ff extends mt{draw(t,e){}textContentBounds(t){const e=t.baseProps,n=this.getTextPadding(t);return{x:n,y:n,width:e.width-2*n,height:e.height-2*n}}fullTextNodeHeight(t){const e=this.getTextPadding(t);return t.renderText.height+2*e}getTextPadding(t){const e=t.textProps.fontSize;return e>10?2:e<4?0:1}}class Yf extends mt{draw(t,e){const n=t.colorProps,o=t.baseProps,s=t.borderProps;n.color!==""&&(e.fillStyle=n.color,e.globalAlpha=n.alpha,e.fillRect(0,0,o.width,o.height)),s.color!==""&&s.dashType!==et.None&&(M.setDashLine(s,e),e.strokeStyle=s.color,e.lineWidth=s.width,e.globalAlpha=s.alpha,e.strokeRect(0,0,o.width,o.height))}}class Gf extends mt{textContentBounds(t){const e=t.baseProps,n=e.width/4,o=-e.height/(e.width/2),s=e.height,r=o*n+s,i={x:n,y:r,width:e.width/2,height:e.height-r};return{x:i.x+le,y:i.y+le,width:i.width-le*2,height:i.height-le*2}}fullTextNodeHeight(t){return(t.renderText.height+le)*2}draw(t,e){const n=t.colorProps,{width:o,height:s}=t.baseProps,r=t.borderProps;e.fillStyle=n.color,e.globalAlpha=n.alpha,e.lineWidth=r.width,e.lineJoin="round",e.lineCap="round",e.beginPath(),e.moveTo(0,s),e.lineTo(.5*o,0),e.lineTo(o,s),e.closePath(),n.color!==""&&e.fill(),r.color!==""&&r.dashType!==et.None&&Math.abs(r.alpha)>.001&&(M.setDashLine(r,e),e.globalAlpha=r.alpha,e.strokeStyle=r.color,e.stroke())}nodeShapeInfo(t){const{width:e,height:n}=t.baseProps;return q.polygon([{x:0,y:n},{x:.5*e,y:0},{x:e,y:n}])}getConnectAnchor(){return[new m(.5,0),new m(.75,.5),new m(.5,1),new m(.25,.5)]}}class Uf extends mt{draw(t,e){const n=t.colorProps,{width:o,height:s}=t.baseProps,r=t.borderProps;e.fillStyle=n.color,e.globalAlpha=n.alpha,e.lineWidth=r.width,e.lineJoin="round",e.lineCap="round",e.beginPath(),e.moveTo(0,.5*s),e.lineTo(.5*o,0),e.lineTo(o,.5*s),e.lineTo(.5*o,s),e.closePath(),n.color!==""&&e.fill(),r.color!==""&&r.dashType!==et.None&&Math.abs(r.alpha)>.001&&(e.strokeStyle=r.color,e.globalAlpha=r.alpha,M.setDashLine(r,e),e.stroke())}fullTextNodeHeight(t){return(t.renderText.height+le)*2}textContentBounds(t){const e=t.baseProps,n={x:0,y:e.height/2},o={x:e.width/2,y:0},s=(n.y-o.y)/(n.x-o.x),r=n.y,i=.25*e.width,a=s*i+r,c={x:i,y:a,with:e.width-i*2,height:e.height-a*2};return{x:c.x+le,y:c.y+le,width:c.with-le*2,height:c.height-le*2}}nodeShapeInfo(t){const{width:e,height:n}=t.baseProps;return q.polygon([{x:0,y:.5*n},{x:.5*e,y:0},{x:e,y:.5*n},{x:.5*e,y:n}])}}class _f extends mt{draw(t,e){const n=t.baseProps,o=t.colorProps,s=t.borderProps;n.width<=0||n.height<=0||!Number.isFinite(n.width)||!Number.isFinite(n.height)||(e.beginPath(),e.fillStyle=o.color,e.roundRect(0,0,n.width,n.height,10),o.color!==""&&(e.globalAlpha=o.alpha,e.fill()),s.color!==""&&s.dashType!==et.None&&Math.abs(s.alpha)>.001&&(e.strokeStyle=s.color,e.lineWidth=s.width,e.globalAlpha=s.alpha,M.setDashLine(s,e),e.stroke()))}nodeShapeInfo(t){const{width:e,height:n}=t.baseProps;return q.rectangle({top:0,left:0,width:e,height:n})}}class $f extends mt{draw(t,e){const n=t.colorProps,{width:o,height:s}=t.baseProps,r=t.borderProps;o<=0||s<=0||!Number.isFinite(o)||!Number.isFinite(s)||(e.fillStyle=n.color,e.globalAlpha=n.alpha,e.lineWidth=r.width,e.lineJoin="round",e.lineCap="round",e.beginPath(),e.ellipse(.5*o,.5*s,.5*o,.5*s,0,0,2*Math.PI,!1),n.color!==""&&e.fill(),r.color!==""&&r.dashType!==et.None&&Math.abs(r.alpha)>.001&&(e.strokeStyle=r.color,e.globalAlpha=r.alpha,M.setDashLine(r,e),e.stroke()))}textContentBounds(t){const e=t.baseProps,n=e.width*Math.sqrt(2)/2,o=(e.width-n)/2,s=Math.max(e.width,e.height)/2,r=Math.min(e.width,e.height)/2,i=(1-(n/2)**2/s**2)*r**2,a={x:o,y:e.height/2-Math.sqrt(i),width:n,height:2*Math.sqrt(i)},c=this.getTextPadding(t);return{x:a.x+c,y:a.y+c,width:a.width-c*2,height:a.height-c*2}}fullTextNodeHeight(t){const e=this.getTextPadding(t);return(t.renderText.height+e)*2}nodeShapeInfo(t){const{width:e,height:n}=t.baseProps;return q.ellipse({centerX:.5*e,centerY:.5*n,radiusX:.5*e,radiusY:.5*n})}}class jf extends mt{textContentBounds(t){const e=t.baseProps;return{x:.16*e.width+le,y:le,width:(1-.16*2)*e.width-2*le,height:e.height-2*le}}buildPath(t,e){const n=t.baseProps;e.beginPath(),e.moveTo(.16*n.width,0),e.lineTo(n.width,0),e.lineTo(.84*n.width,n.height),e.lineTo(0,n.height),e.closePath()}nodeShapeInfo(t){const{width:e,height:n}=t.baseProps;return q.polygon([{x:.16*e,y:0},{x:e,y:0},{x:.84*e,y:n},{x:0,y:n}])}getConnectAnchor(){return[new m(.5,0),new m(.92,.5),new m(.5,1),new m(.08,.5)]}}class Vf extends mt{textContentBounds(t){const e=t.baseProps;return{x:.2*e.width,y:le,width:.6*e.width,height:e.height-2*le}}draw(t,e){const n=t.colorProps,{width:o,height:s}=t.baseProps,r=t.borderProps;e.lineJoin="round",e.lineCap="round",e.beginPath(),e.moveTo(.2*o,0),e.lineTo(.8*o,0),e.lineTo(o,s),e.lineTo(0,s),e.closePath(),n.color!==""&&(e.fillStyle=n.color,e.globalAlpha=n.alpha,e.fill()),r.color!==""&&r.dashType!==et.None&&(M.setDashLine(r,e),e.strokeStyle=r.color,e.lineWidth=r.width,e.globalAlpha=r.alpha,e.stroke())}nodeShapeInfo(t){const{width:e,height:n}=t.baseProps;return q.polygon([{x:.2*e,y:0},{x:.8*e,y:0},{x:e,y:n},{x:0,y:n}])}getConnectAnchor(){return[new m(.5,0),new m(.9,.5),new m(.5,1),new m(.1,.5)]}}class Kf extends mt{buildPath(t,e){const{width:n,height:o}=t.baseProps;e.beginPath(),e.moveTo(.5*n,0),e.lineTo(n,.38196601125010515*o),e.lineTo(.8090169943749473*n,o),e.lineTo(.1909830056250526*n,o),e.lineTo(0,.381966011250105*o),e.closePath()}nodeShapeInfo(t){const{width:e,height:n}=t.baseProps;return q.polygon([{x:.5*e,y:0},{x:e,y:.38196601125010515*n},{x:.8090169943749473*e,y:n},{x:.1909830056250526*e,y:n},{x:0,y:.381966011250105*n}])}textContentBounds(t){const e=t.baseProps,n={x:0,y:e.height*.38196601125010515},o={x:e.width/2,y:0},s=(n.y-o.y)/(n.x-o.x),r=n.y,i=.1909830056250526*e.width,a=s*i+r,c={x:i,y:a,with:e.width-i*2,height:e.height-a};return{x:c.x+le,y:c.y+le,width:c.with-le*2,height:c.height-le*2}}fullTextNodeHeight(t){const e=t.renderText.height,n=t.baseProps,o={x:0,y:n.height*.38196601125010515},s={x:n.width/2,y:0},r=(o.y-s.y)/(o.x-s.x),i=o.y,a=.1909830056250526*n.width,c=r*a+i;return e+2*le+c}getConnectAnchor(){return super.getConnectAnchor()}}class Qf extends mt{buildPath(t,e){const{width:n,height:o}=t.baseProps;e.beginPath(),e.moveTo(n,.5*o),e.lineTo(.75*n,o),e.lineTo(.25*n,o),e.lineTo(0,.5*o),e.lineTo(.25*n,0),e.lineTo(.75*n,0),e.closePath()}nodeShapeInfo(t){const{width:e,height:n}=t.baseProps;return q.polygon([{x:e,y:.5*n},{x:.75*e,y:n},{x:.25*e,y:n},{x:0,y:.5*n},{x:.25*e,y:0},{x:.75*e,y:0}])}textContentBounds(t){const e=t.baseProps;return{x:.25*e.width+le,y:le,width:.5*e.width-2*le,height:e.height-2*le}}getConnectAnchor(){return super.getConnectAnchor()}}class Zf extends mt{buildPath(t,e){const{width:n,height:o}=t.baseProps;e.beginPath(),e.moveTo(.7071067811865476*n,0),e.lineTo(n,.2928932188134524*o),e.lineTo(n,.7071067811865476*o),e.lineTo(.7071067811865476*n,o),e.lineTo(.2928932188134525*n,o),e.lineTo(0,.7071067811865476*o),e.lineTo(0,.29289321881345254*o),e.lineTo(.29289321881345215*n,0),e.closePath()}nodeShapeInfo(t){const{width:e,height:n}=t.baseProps;return q.polygon([{x:.7071067811865476*e,y:0},{x:e,y:.2928932188134524*n},{x:e,y:.7071067811865476*n},{x:.7071067811865476*e,y:n},{x:.2928932188134525*e,y:n},{x:0,y:.7071067811865476*n},{x:0,y:.29289321881345254*n},{x:.29289321881345215*e,y:0}])}textContentBounds(t){const e=t.baseProps,n={x:.064625*e.width,y:.064625*e.height,width:e.width*(1-.064625*2),height:e.height*(1-.064625*2)};return{x:n.x+le,y:n.y+le,width:n.width-le*2,height:n.height-le*2}}fullTextNodeHeight(t){return(t.renderText.height+2*le)/(1-.064625*2)}getConnectAnchor(){return super.getConnectAnchor()}}const qf="M19.1498 8.12942L18.9895 8.95084L19.7971 9.17031C21.3773 9.59972 22.4731 10.9487 22.4731 12.4833C22.4731 13.901 21.5408 15.1571 20.1512 15.6818L19.5155 15.9218L19.5722 16.5988C19.5788 16.6767 19.5821 16.7556 19.5821 16.8356C19.5821 18.3711 18.3424 19.6106 16.8195 19.6106C16.2161 19.6106 15.66 19.4173 15.206 19.0884L14.4417 18.5348L13.925 19.3244C13.4292 20.082 12.5786 20.5777 11.6143 20.5777C10.5661 20.5777 9.65135 19.9913 9.18244 19.1206L8.73358 18.2873L7.92388 18.7776C7.45803 19.0596 6.90757 19.2236 6.31413 19.2236C4.61055 19.2236 3.26243 17.8766 3.26243 16.2551C3.26243 15.774 3.37941 15.3216 3.58718 14.9209L4.05462 14.0194L3.1035 13.6636C2.19708 13.3246 1.52704 12.4149 1.52704 11.323C1.52704 9.96428 2.55686 8.90054 3.79171 8.84083L4.78871 8.79263L4.63791 7.80592C4.62047 7.69176 4.61134 7.57433 4.61134 7.45418C4.61134 6.18576 5.63529 5.16272 6.89198 5.16272C7.18142 5.16272 7.45628 5.21645 7.70869 5.31377L8.44216 5.59655L8.82102 4.90778C9.30983 4.01913 10.2497 3.42222 11.3256 3.42222C12.5174 3.42222 13.5428 4.15533 13.9715 5.20352L14.3964 6.24229L15.3181 5.60191C15.717 5.32477 16.1997 5.16272 16.7227 5.16272C18.0858 5.16272 19.1961 6.27235 19.1961 7.6476C19.1961 7.81325 19.1801 7.97425 19.1498 8.12942Z";class Jf extends mt{constructor(){super(...arguments);p(this,"path2D",new Path2D(qf))}textContentBounds(e){const n=e.baseProps;return{x:.2*n.width,y:.2*n.height,width:.6*n.width,height:.6*n.height}}draw(e,n){const o=e.colorProps,s=e.borderProps,{width:r,height:i}=e.baseProps,a=new Path2D;a.addPath(this.path2D,new DOMMatrix().scale(r/24,i/24)),n.lineJoin="round",n.lineCap="round",o.color!==""&&(n.fillStyle=o.color,n.globalAlpha=o.alpha,n.fill(a)),s.color!==""&&s.dashType!==et.None&&(M.setDashLine(s,n),n.strokeStyle=s.color,n.lineWidth=s.width,n.globalAlpha=s.alpha,n.stroke(a))}borderContains(e,n,o){const{width:s,height:r}=e.baseProps,i=e.borderProps,a=new Path2D;a.addPath(this.path2D,new DOMMatrix().scale(s/24,r/24));const c=e.graphicContext;return c.lineWidth=i.width,c.isPointInStroke(a,n.x,n.y)?n:null}}const Ie=.3;class eg extends mt{buildPath(t,e){const{width:n,height:o}=t.baseProps;e.beginPath(),e.moveTo(0,Ie*o),e.lineTo(Ie*n,Ie*o),e.lineTo(Ie*n,0),e.lineTo((1-Ie)*n,0),e.lineTo((1-Ie)*n,Ie*o),e.lineTo(n,Ie*o),e.lineTo(n,(1-Ie)*o),e.lineTo((1-Ie)*n,(1-Ie)*o),e.lineTo((1-Ie)*n,o),e.lineTo(Ie*n,o),e.lineTo(Ie*n,(1-Ie)*o),e.lineTo(0,(1-Ie)*o),e.closePath()}nodeShapeInfo(t){const{width:e,height:n}=t.baseProps;return q.polygon([{x:0,y:Ie*n},{x:Ie*e,y:Ie*n},{x:Ie*e,y:0},{x:(1-Ie)*e,y:0},{x:(1-Ie)*e,y:Ie*n},{x:e,y:Ie*n},{x:e,y:(1-Ie)*n},{x:(1-Ie)*e,y:(1-Ie)*n},{x:(1-Ie)*e,y:n},{x:Ie*e,y:n},{x:Ie*e,y:(1-Ie)*n},{x:0,y:(1-Ie)*n}])}textContentBounds(t){const e=t.baseProps;return{x:e.width*Ie+le,y:e.height*Ie+le,width:e.width*(1-Ie*2)-le*2,height:e.height*(1-Ie*2)-le*2}}fullTextNodeHeight(t){return(t.renderText.height+2*le)/(1-Ie*2)}getConnectAnchor(){return super.getConnectAnchor()}}class tg extends mt{buildPath(t,e){const{width:n,height:o}=t.baseProps;e.beginPath(),e.moveTo(.45331701407562014*n,.04068531978415023*o),e.lineTo(.47241283626581937*n,0),e.lineTo(.5275866431283414*n,0),e.lineTo(.5466824653185405*n,.04068531978415023*o),e.lineTo(.6561866975837122*n,.2739844955129827*o),e.lineTo(.6637719246641702*n,.29014093296241683*o),e.lineTo(.6784321851024475*n,.3013390437841371*o),e.lineTo(.6953883172925998*n,.3039298761896317*o),e.lineTo(.9402500678089105*n,.3413412114782689*o),e.lineTo(.9829501587587509*n,.3478650949789417*o),e.lineTo(n,.40304112159559813*o),e.lineTo(.9691020434299804*n,.4347080674349939*o),e.lineTo(.7919190520392391*n,.616307190723145*o),e.lineTo(.779648372403934*n,.6288863854576189*o),e.lineTo(.7740466535716944*n,.647005242973332*o),e.lineTo(.7769464280973055*n,.6647628181337468*o),e.lineTo(.8187719012369075*n,.9211802328191082*o),e.lineTo(.8260655890472862*n,.9658971352498816*o),e.lineTo(.7814288443747758*n,o),e.lineTo(.7432371999943775*n,.9788868781153761*o),e.lineTo(.5242235294056399*n,.8578189712649151*o),e.lineTo(.509058281303118*n,.849438315417013*o),e.lineTo(.49094119809104253*n,.849438315417013*o),e.lineTo(.4757759499885207*n,.8578189712649151*o),e.lineTo(.2567643618231409*n,.9788868781153761*o),e.lineTo(.21857115562522422*n,o),e.lineTo(.1739323285293562*n,.9658971352498816*o),e.lineTo(.18122705755141377*n,.9211802328191082*o),e.lineTo(.22305409250853406*n,.6647628181337468*o),e.lineTo(.22595074339910845*n,.647005242973332*o),e.lineTo(.2203516275960661*n,.6288863854576189*o),e.lineTo(.20808146856660034*n,.616307190723145*o),e.lineTo(.030898997781698512*n,.4347080674349939*o),e.lineTo(0,.40304112159559813*o),e.lineTo(.017050361847088705*n,.3478650949789417*o),e.lineTo(.059751494008607714*n,.3413412114782689*o),e.lineTo(.3046116827074003*n,.3039298761896317*o),e.lineTo(.3215683355033921*n,.3013390437841371*o),e.lineTo(.33622703412415095*n,.29014093296241683*o),e.lineTo(.34381017878125136*n,.2739844955129827*o),e.lineTo(.45331701407562014*n,.04068531978415023*o),e.closePath()}nodeShapeInfo(t){const{width:e,height:n}=t.baseProps;return q.polygon([{x:.45331701407562014*e,y:.04068531978415023*n},{x:.47241283626581937*e,y:0},{x:.5275866431283414*e,y:0},{x:.5466824653185405*e,y:.04068531978415023*n},{x:.6561866975837122*e,y:.2739844955129827*n},{x:.6637719246641702*e,y:.29014093296241683*n},{x:.6784321851024475*e,y:.3013390437841371*n},{x:.6953883172925998*e,y:.3039298761896317*n},{x:.9402500678089105*e,y:.3413412114782689*n},{x:.9829501587587509*e,y:.3478650949789417*n},{x:e,y:.40304112159559813*n},{x:.9691020434299804*e,y:.4347080674349939*n},{x:.7919190520392391*e,y:.616307190723145*n},{x:.779648372403934*e,y:.6288863854576189*n},{x:.7740466535716944*e,y:.647005242973332*n},{x:.7769464280973055*e,y:.6647628181337468*n},{x:.8187719012369075*e,y:.9211802328191082*n},{x:.8260655890472862*e,y:.9658971352498816*n},{x:.7814288443747758*e,y:n},{x:.7432371999943775*e,y:.9788868781153761*n},{x:.5242235294056399*e,y:.8578189712649151*n},{x:.509058281303118*e,y:.849438315417013*n},{x:.49094119809104253*e,y:.849438315417013*n},{x:.4757759499885207*e,y:.8578189712649151*n},{x:.2567643618231409*e,y:.9788868781153761*n},{x:.21857115562522422*e,y:n},{x:.1739323285293562*e,y:.9658971352498816*n},{x:.18122705755141377*e,y:.9211802328191082*n},{x:.22305409250853406*e,y:.6647628181337468*n},{x:.22595074339910845*e,y:.647005242973332*n},{x:.2203516275960661*e,y:.6288863854576189*n},{x:.20808146856660034*e,y:.616307190723145*n},{x:.030898997781698512*e,y:.4347080674349939*n},{x:0,y:.40304112159559813*n},{x:.017050361847088705*e,y:.3478650949789417*n},{x:.059751494008607714*e,y:.3413412114782689*n},{x:.3046116827074003*e,y:.3039298761896317*n},{x:.3215683355033921*e,y:.3013390437841371*n},{x:.33622703412415095*e,y:.29014093296241683*n},{x:.34381017878125136*e,y:.2739844955129827*n},{x:.45331701407562014*e,y:.04068531978415023*n}])}textContentBounds(t){const e=t.baseProps,n={x:e.width*.059751494008607714,y:e.height*.3413412114782689},o={x:e.width*.3046116827074003,y:e.height*.3039298761896317},s=(n.y-o.y)/(n.x-o.x),r=n.y,i=.22595074339910845*e.width,a=s*i+r,c={x:i,y:a,with:e.width-i*2,height:e.height*.849438315417013-a};return{x:c.x+le,y:c.y+le,width:c.with-le*2,height:c.height-le*2}}fullTextNodeHeight(t){const e=t.baseProps;return e.width*.059751494008607714,e.height*.3413412114782689,e.width*.3046116827074003,e.height*.3039298761896317,(t.renderText.height+2*le)/.849438315417013}getConnectAnchor(){return super.getConnectAnchor()}}const Wt=class Wt extends en{constructor(e,n){super(e,n);p(this,"type",v.Shape);p(this,"transform",re.generateMatrix());p(this,"renderText");this.props.set(I.Base,new ie),this.props.set(I.Shape,new Oe),this.props.set(I.Color,new tt),this.props.set(I.Border,new Ae),this.props.set(I.Text,new Ge),this.props.set(I.TextParagraph,new qt),this.props.set(I.TextParagraphQuote,new Dt),this.renderText=new uo}validShapeCode(e){return!!Wt.drawerMap.get(e)}get borderProps(){return this.props.get(I.Border)}get colorProps(){return this.props.get(I.Color)}get textProps(){return this.props.get(I.Text)}get paragraphProps(){return this.props.get(I.TextParagraph)}get paragraphQuoteProps(){return this.props.get(I.TextParagraphQuote)}get shapeType(){return this.props.get(I.Shape).shapeCode}get drawer(){const e=Wt.drawerMap.get(this.shapeType);return e||Wt.drawerMap.get(K.RoundRect)}borderContains(e,n){const o=this.toLocal(e);return this.drawer.borderContains(this,o,n)}updateProps(e){super.updateProps(e);const n=e.find(i=>i.type===I.Text),o=e.find(i=>i.type===I.TextParagraph),s=e.find(i=>i.type===I.TextParagraphQuote),r=e.find(i=>i.type===I.Base);if(r&&this.updateTransformMatrix(),n||r||o||s){const i=this.drawer.textContentBounds(this);this.shapeType===K.PureText&&this.textProps.sizeMode!==We.fix&&this.textProps.verticalAlign!==at.Top&&(this.textProps.verticalAlign=at.Top),this.renderText.typesetting(this.graphicContext,this.textProps,i,this.paragraphProps,this.paragraphQuoteProps),this.shapeType===K.PureText&&this.textProps.sizeMode!==We.fix&&(this.baseProps.height=this.renderText.y+this.renderText.height,this.renderText.rect.height=this.renderText.height+4,this.textProps.sizeMode===We.autoWidth&&(this.baseProps.width=this.renderText.width+4))}}modifyPosInEditing(e){if(this.shapeType===K.PureText)return!1;const n=this.drawer.textContentBounds(this);return this.renderText.modifyPosInEditing(n,e)}resetFromEditing(){const e=this.drawer.textContentBounds(this);return this.renderText.resetFromEditing(e)}contains(e){const{width:n,height:o}=this.baseProps,s=this.toLocal(e);return M.rectContains(s,new D(0,0,n,o))}drawOnGLCtx(e){const n=this.shapeType;let o=Wt.drawerMap.get(n);o||(console.error("取不到drawer,使用rect兜底!"),o=Wt.drawerMap.get(K.Rect)),e.save(),e.beginPath();const{a:s,b:r,c:i,d:a,e:c,f:h}=this.globalTransform();e.transform(s,r,i,a,c,h),o.draw(this,e),this.drawText(e),e.restore()}drawText(e){if(this.shapeType===K.PureText){const a=new m;this.renderText.draw(e,a,1);return}const{x:n,y:o,width:s,height:r}=this.getTextContentRect();e.save(),e.beginPath(),e.rect(n,o,s,r),e.clip();const i=new m;this.renderText.draw(e,i,1),e.restore()}getStretchMinSize(){return new m(20,20)}draw(){this.drawOnGLCtx(this.graphicContext)}getTextContentRect(){const e=this.shapeType;let n=Wt.drawerMap.get(e);return n||(console.error("取不到drawer,使用rect兜底!"),n=Wt.drawerMap.get(K.Rect)),n.textContentBounds(this)}isEmptyText(){return this.renderText.isEmptyText()}getConnectAnchor(){return this.drawer.getConnectAnchor()}static load(e,n,o,s,r,i){const a=new Wt(e,i);return a.type=n,a.zIndex=o,a.setParent(r),a.updateProps(s),a}};p(Wt,"drawerMap",new Map([[K.PureText,new Ff],[K.Ellipse,new $f],[K.Rect,new Yf],[K.RoundRect,new _f],[K.Triangle,new Gf],[K.Diamond,new Uf],[K.Parallelogram,new jf],[K.Octagon,new Zf],[K.Hexagon,new Qf],[K.Trapezoid,new Vf],[K.Pentagon,new Kf],[K.Star,new tg],[K.Cloud,new Jf],[K.Cross,new eg]]));let vt=Wt;class jn extends Fn{constructor(e,n){super(e,n);p(this,"type",v.SVG);p(this,"imgBitmap",null);p(this,"svgCode","");this.props.set(I.Base,new ie),this.props.set(I.Border,new Ae),this.props.set(I.Svg,new Wn),this.props.set(I.Crop,new Sn)}get svgUrl(){return this.props.get(I.Svg).url}get svgProps(){return this.props.get(I.Svg)}setSvgCode(e){this.svgCode=e}static load(e,n,o,s,r,i){const a=new jn(e,i);return a.type=n,a.zIndex=o,a.setParent(r),a.updateProps(s),a}}class an{static getNumFromString(t){try{const e=t.match(/(\d+)/);return e&&e[1]?parseInt(e[1],10):100}catch{return console.error("从字符串中获取num出错:",t),100}}static trimSvgCode(t){const n=new DOMParser().parseFromString(t,"image/svg+xml").documentElement,o=n.getAttribute("width"),s=n.getAttribute("height");n.removeAttribute("width"),n.removeAttribute("height");const r=n.style.width,i=n.style.height;n.style.removeProperty("width"),n.style.removeProperty("height");let a=100,c=100;return o!==null?a=this.getNumFromString(o):r!==""&&(a=this.getNumFromString(r)),s!==null?c=this.getNumFromString(s):i!==""&&(c=this.getNumFromString(i)),n.getAttribute("viewBox")||n.setAttribute("viewBox",`0 0 ${a} ${c}`),{svgCode:n.outerHTML,width:a,height:c}}}class Po extends en{constructor(e,n){super(e,n);p(this,"type",v.Group);this.props.set(I.Base,new ie)}get globalPos(){return this.nameGlobalTransform().crossPoint(new m)}computeBasePropsByChildren(){const e=[];for(const s of this.children)e.push(s.baseProps);const n=M.getBoundsByBasePropsList(e),o=D.rectNode2Rect(n);return ie.create({x:o.x,y:o.y,width:o.width,height:o.height})}drawOnGLCtx(e){}getTextContentRect(){return this.baseProps}canBeConnected(){return!1}transToLocalPoint(e){return this.nameGlobalTransform().inverseMatrix().crossPoint(e)}contains(e,n=1){const{width:o,height:s}=this.baseProps,r=this.transToLocalPoint(e);return M.rectContains(r,new D(0,0,o,s))}toGlobal(e){return this.nameGlobalTransform().crossPoint(e)}nameGlobalTransform(){const e=this.selfTransform();return this.globalTransform().crossProduct(e)}selfTransform(){const{x:e,y:n}=this.baseProps;return re.generateMatrix().translate(e,n)}updateTransformMatrix(){}static load(e,n,o,s,r,i){const a=new Po(e,i);return a.type=n,a.zIndex=o,a.setParent(r),a.updateProps(s),a}}class rs extends en{constructor(e,n){super(e,n);p(this,"type",v.Section);this.props.set(I.Base,new ie),this.props.set(I.Border,new Ae),this.props.set(I.Color,new tt),this.props.set(I.Slide,new Mt)}get borderProps(){return this.props.get(I.Border)}get colorProps(){return this.props.get(I.Color)}updateProps(e){super.updateProps(e),e.find(o=>o.type===I.Base)&&this.updateTransformMatrix()}drawOnGLCtx(e){e.save();const n=this.baseProps,{a:o,b:s,c:r,d:i,e:a,f:c}=this.globalTransform();e.transform(o,s,r,i,a,c);const h=this.colorProps,d=this.borderProps;e.beginPath(),e.roundRect(0,0,n.width,n.height,6),h.color!==""&&(e.fillStyle=h.color,e.globalAlpha=h.alpha,e.fill()),d.color!==""&&d.dashType!==et.None&&(M.setDashLine(d,e),e.strokeStyle=d.color,e.lineWidth=d.width,e.globalAlpha=d.alpha,e.stroke()),e.restore()}static load(e,n,o,s,r,i){const a=new rs(e,i);return a.type=n,a.zIndex=o,a.setParent(r),a.updateProps(s),a}canQuickCreate(){return!1}getTextContentRect(){return this.baseProps}}class bo extends en{constructor(e,n){super(e,n);p(this,"type",v.SlideContainer);this.props.set(I.Base,new ie),this.props.set(I.Slide,new Mt)}get slideProps(){return this.props.get(I.Slide)}updateProps(e){super.updateProps(e),e.find(o=>o.type===I.Base)&&this.updateTransformMatrix()}drawOnGLCtx(e){const{width:n,height:o}=this.baseProps,{a:s,b:r,c:i,d:a,e:c,f:h}=this.globalTransform();e.save(),e.transform(s,r,i,a,c,h),e.shadowColor="rgba(0, 0, 0, 0.1)",e.shadowBlur=15,e.shadowOffsetX=0,e.shadowOffsetY=6,e.fillStyle="rgba(255, 255, 255, 0.6)",e.beginPath(),e.roundRect(0,0,n,o,8),e.fill(),e.shadowColor="transparent",e.fillStyle="rgba(240, 242, 245, 0.5)",e.fill(),e.strokeStyle="rgba(0, 0, 0, 0.1)",e.lineWidth=1,e.stroke(),e.restore()}canQuickCreate(){return!1}getTextContentRect(){return this.baseProps}static load(e,n,o,s,r,i){const a=new bo(e,i);return a.type=n,a.zIndex=o,a.setParent(r),a.updateProps(s),a}getChildIdByIndex(e){const n=this.slideProps.children;let o=0;for(let s=0;s<n.length;s++){if(e<o+n[s].ids.length){const r=e-o;return n[s].ids[r]}o+=n[s].ids.length}return null}getTotalCount(){return this.slideProps.children.reduce((n,o)=>n+o.ids.length,0)}}const ms=class ms{static getInstance(){return this.instance||(this.instance=new ms),this.instance}create(t,e,n,o,s,r){switch(e){case v.Line:return Ct.load(t,e,n,o,s,r);case v.SVG:return jn.load(t,e,n,o,s,r);case v.IMG:return Yn.load(t,e,n,o,s,r);case v.Section:return rs.load(t,e,n,o,s,r);case v.Group:return Po.load(t,e,n,o,s,r);case v.Checkbox:return Yo.load(t,e,n,o,s,r);case v.CheckboxText:return Un.load(t,e,n,o,s,r);case v.SlideContainer:return bo.load(t,e,n,o,s,r);case v.Shape:default:return vt.load(t,e,n,o,s,r)}}createByNodeInfo(t,e,n){const o=M.convertCapInfoToProps(t.capInfo);return this.create(t.id,t.type,t.zIndex,o,e,n)}};p(ms,"instance",null);let It=ms;class pr extends en{constructor(e){const o=document.createElement("canvas").getContext("2d");super(e,o);p(this,"type",v.ROOT);p(this,"transform",re.generateMatrix())}updateProps(e){}drawOnGLCtx(e){}getTextContentRect(){return new D}toGlobal(e){return e}toLocal(e){return e}}const is=800;class Pc{static async getImageSize(t){return new Promise((e,n)=>{const o=URL.createObjectURL(t),s=new Image;s.crossOrigin="anonymous",s.onload=()=>{let r=s.naturalWidth*.5,i=s.naturalHeight*.5;URL.revokeObjectURL(o);const a=r/i;r>i&&r>is?(r=is,i=r/a):i>r&&i>is&&(i=is,r=i*a),e({width:r,height:i})},s.onerror=()=>{URL.revokeObjectURL(o),n(new Error("无法加载图片"))},s.src=o})}}class At extends yn{constructor(){super(...arguments);p(this,"type",Xe.RemoveNode)}static create(e){return new At({idList:e})}clone(){const e=JSON.parse(JSON.stringify(this.data));return new At(e,this.meta)}}class fr{}class bc extends fr{handle(t,e,n){const o=e.find(i=>i.type===I.Connect);if(!o)return;const{start:s,end:r}=o;if(s!==void 0)if(s!==null){const i=n.nodeManager.getNode(s.objectId)||null;n.nodeManager.addLink(t,i,!0)}else n.nodeManager.addLink(t,null,!0);if(r!==void 0)if(r!==null){const i=n.nodeManager.getNode(r.objectId)||null;n.nodeManager.addLink(t,i,!1)}else n.nodeManager.addLink(t,null,!1)}}class ng extends fr{handle(t,e,n){if(!e.find(r=>r.type===I.Image)||t.type!==v.IMG)return;const s=t;n.asyncRenderNodeManager.addRenderNode(s)}}let og=class extends fr{handle(t,e,n){const o=e.find(r=>r.type===I.Svg);if(!o||t.type!==v.SVG)return;const s=t;if(s.svgProps.useCode){const r=an.trimSvgCode(s.svgProps.code);s.setSvgCode(r.svgCode),n.asyncRenderNodeManager.addRenderNode(s);return}n.resourceManager.loadSvgUrl(o.url).then(r=>{const i=an.trimSvgCode(r);s.setSvgCode(i.svgCode),n.asyncRenderNodeManager.addRenderNode(s)}).catch(r=>{console.error("加载图片出现问题",r),s.setBroken(),n.renderManager.dirtyDraw(t.getBounds())})}};class Mc extends hn{constructor(){super(...arguments);p(this,"type",Xe.AddNode);p(this,"handlers",[new bc,new ng,new og])}execData(e,n){const o=e.nodes;for(const s of o)this.execNodeInfo(s,n);n.renderManager.addContentRenderTask()}execNodeInfo(e,n){const o=n.gmlRender.glCtx,s=n.nodeManager.getParentNode(e.parentId),r=It.getInstance().create(e.id,e.type,e.zIndex,e.props,s,o);n.nodeManager.addNode(r);for(const i of this.handlers)i.handle(r,e.props,n)}reverseLog(e,n){const o=e.nodes.map(s=>s.id);return new At({idList:o})}}class Le extends yn{constructor(){super(...arguments);p(this,"type",Xe.AddNode)}static create(e){return new Le({nodes:[e]})}clone(){const e=JSON.parse(JSON.stringify(this.data));return new Le(e,this.meta)}}class Sc extends hn{constructor(){super(...arguments);p(this,"type",Xe.RemoveNode)}execData(e,n){for(const o of e.idList)n.nodeManager.getNode(o)&&n.nodeManager.removeNode(o);n.renderManager.addContentRenderTask(),n.renderManager.addAuxiliaryDrawTask()}reverseLog(e,n){var s;const o=[];for(const r of e.idList){const i=n.nodeManager.getNode(r);if(!i){console.error("错误,生成逆消息时节点不存在:",r);continue}const a=[...i.props.values()];o.push({id:i.id,type:i.type,zIndex:i.zIndex,parentId:((s=i.parent)==null?void 0:s.id)||Mn,props:a})}return new Le({nodes:o})}}class U extends yn{constructor(){super(...arguments);p(this,"type",Xe.UpdateNode)}static create(e,n,o){const s={id:e,props:n};return new U({infos:[s]},o)}clone(){const e=JSON.parse(JSON.stringify(this.data));return new U(e,this.meta)}}class vc extends hn{constructor(){super(...arguments);p(this,"type",Xe.UpdateNode);p(this,"handlers",[new bc])}execData(e,n){for(const o of e.infos)this.execNodeInfo(o,n);n.renderManager.addContentRenderTask()}execNodeInfo(e,n){const{id:o,zIndex:s,props:r,parentId:i}=e,a=n.nodeManager.getNode(o);if(!a){console.error("错误:节点不存在:",o);return}if(this.removeIndexNode(a,n),s!==void 0&&(a.zIndex=s),this.changeParent(a,n,i),r.length>0){a.updateProps(r);for(const c of this.handlers)c.handle(a,r,n)}this.addIndexNode(a,n),n.auxiliaryManager.selectManager.include(a)&&(n.auxiliaryManager.selectManager.refreshSelectStatus(),n.renderManager.addAuxiliaryDrawTask(),n.auxiliaryManager.slotManager.addSlotState(ze.FocusPropsChange,!0))}changeParent(e,n,o){if(o===void 0||o===e.parent.id)return;const s=n.nodeManager.getNode(o);s&&(e.parent.children.delete(e),s.children.add(e),e.parent=s)}removeIndexNode(e,n){n.nodeManager.removeIndexNode(e.getRectNode());for(const o of e.children)this.removeIndexNode(o,n)}addIndexNode(e,n){n.nodeManager.addIndexNode(e.getRectNode());for(const o of e.children)this.addIndexNode(o,n)}reverseLog(e,n){const o=[];for(const s of e.infos){const r=n.nodeManager.getNode(s.id);if(!r)continue;const i=r.parent?r.parent.id:n.nodeManager.root.id,a=r.serializeTo(),c=M.convertCapInfoToProps(a.capInfo);o.push({id:r.id,zIndex:r.zIndex,props:c,parentId:i})}return new U({infos:o})}}class xe extends yn{constructor(){super(...arguments);p(this,"type",Xe.SelectNode)}static create(e){return new xe({idList:e})}clone(){const e=JSON.parse(JSON.stringify(this.data));return new xe(e,this.meta)}}class Ic extends hn{constructor(){super(...arguments);p(this,"type",Xe.SelectNode)}execData(e,n){const o=e.idList,s=new Set;o.forEach(r=>{const i=n.nodeManager.getNode(r);i&&s.add(i)}),n.auxiliaryManager.selectManager.set(s),n.renderManager.addAuxiliaryDrawTask(),n.auxiliaryManager.slotManager.addSlotState(ze.FocusPropsChange,!0)}reverseLog(e,n){const s=n.auxiliaryManager.selectManager.getSelectNodes().map(r=>r.id);return new xe({idList:s})}}class z extends yn{constructor(){super(null);p(this,"type",Xe.End)}clone(){return new z}}class Tc extends hn{constructor(){super(...arguments);p(this,"type",Xe.Start)}execData(e,n){}reverseLog(e,n){return new z}}class W extends yn{constructor(){super(null);p(this,"type",Xe.Start)}clone(){return new W}}class Lc extends hn{constructor(){super(...arguments);p(this,"type",Xe.End)}execData(e,n){}reverseLog(e,n){return new W}}class Cc extends hn{constructor(){super(...arguments);p(this,"type",Xe.TextFocus)}checkValidNode(e,n){const o=n.nodeManager.getNode(e);if(!o)throw new Error("错误:节点不存在:"+e);const s=o.renderText;return{node:o,renderText:s}}execData(e,n){var a;const{focusType:o,blur:s,selection:r,focus:i}=e;if(o===Lt.Empty){n.auxiliaryManager.remove(N.TextSelection);return}if(n.renderManager.addAuxiliaryDrawTask(),o===Lt.Focus){n.auxiliaryManager.remove(N.TextSelection);const{id:c,textCursorPosition:h}=i,{node:d,renderText:u}=this.checkValidNode(c,n);d.modifyPosInEditing(h)&&n.renderManager.addContentRenderTask(),n.inputManager.focus({node:d,renderText:u,textCursorPosition:h}),u.isEmptyText()?d.type===v.Shape&&n.auxiliaryManager.addOrUpdate(N.PlaceHolder,{node:d}):n.auxiliaryManager.remove(N.PlaceHolder),n.auxiliaryManager.selectManager.refreshSelectStatus();return}if(o===Lt.Selection){const{id:c,start:h,end:d}=r,{node:u,renderText:f}=this.checkValidNode(c,n);n.inputManager.selection(u,f,h,d);const g=(a=n.inputManager.selectionManager.selectionInfo)==null?void 0:a.selectionList;g&&(n.auxiliaryManager.addOrUpdate(N.TextSelection,{selectionList:g,node:u}),n.renderManager.addAuxiliaryDrawTask()),n.auxiliaryManager.remove(N.PlaceHolder),n.auxiliaryManager.slotManager.addSlotState(ze.FocusPropsChange,!0);return}if(o===Lt.Blur){n.inputManager.blur(),n.auxiliaryManager.remove(N.PlaceHolder);return}}reverseLog(e,n){const{focusType:o}=e,s=n.inputManager.editTextInfo,r=n.inputManager.selectionManager.selectionInfo;if(o===Lt.Focus){const i=e.focus.id;return s?r?ee.selection(s.node.id,r.start,r.end):ee.focus(s.node.id,s.textCursorPosition):ee.blur(i)}if(o===Lt.Blur)return s?r?ee.selection(s.node.id,r.start,r.end):ee.focus(s.node.id,s.textCursorPosition):(console.warn("选中消息不符合预期,已容错处理"),ee.empty());if(o===Lt.Selection){const i=e.selection.id;return s?r?ee.selection(s.node.id,r.start,r.end):ee.focus(s.node.id,s.textCursorPosition):ee.blur(i)}return ee.empty()}}const Ac=[new Mc,new Sc,new vc,new Ic,new Cc,new Tc,new Lc];class kc{}class sg extends kc{constructor(){super(...arguments);p(this,"slideContainer",null)}enable(e,n){if(e.meta.streaming||n.docState.docMode!==he.SLIDE_EDIT)return!1;const o=n.docState.slideStatus.slideContainer;return o?(this.slideContainer=o,!0):!1}handle(e,n){this.slideContainer&&(this.handleUpdateLog(e,n,this.slideContainer),this.handleAddLog(e,n,this.slideContainer),this.handleRemoveLog(e,n,this.slideContainer))}handleUpdateLog(e,n,o){var s;if(e.type===Xe.UpdateNode){const r=e.data;for(const i of r.infos){const a=n.nodeManager.getNode(i.id);if(!a)continue;if(((s=a.parent)==null?void 0:s.id)===o.id&&this.judgeOnlyPosChange(i.props,a)){this.judgeSlideEditCurrent(a,n)&&(console.log("协同端正在更新此幻灯片位置,触发器重置视图"),setTimeout(()=>{n.slideManager.refocusSlide(n,50)},10));continue}if(a.id===o.id){const h=n.renderManager.getScale(),d=this.judgeOnlyPosChange(i.props,a);if(d){n.renderManager.scroll(d.x*h,d.y*h);continue}}const c=M.judgeSlideSectionChildren(a,o);c&&n.slideManager.slideCoverManager.updateSlideCover(c)}}}judgeSlideEditCurrent(e,n){const o=n.docState.slideStatus;return o.slideContainer?o.slideContainer.getChildIdByIndex(o.currentIndex)===e.id:!1}judgeOnlyPosChange(e,n){if(e.length!==1)return null;const o=e[0];if(o.type!==I.Base)return null;const s=n.baseProps,r=o.width===void 0||Math.abs(o.width-s.width)<.1;if(!(o.height===void 0||Math.abs(o.height-s.height)<.1)||!r)return null;if(o.x!==void 0||o.y!==void 0){const a=new m;return o.x!==void 0&&(a.x=o.x-s.x),o.y!==void 0&&(a.y=o.y-s.y),a}return null}handleAddLog(e,n,o){if(e.type===Xe.AddNode){const s=e.data;for(const r of s.nodes){const i=n.nodeManager.getNode(r.parentId);if(!i)continue;const a=M.judgeSlideSectionChildren(i,o);a&&n.slideManager.slideCoverManager.updateSlideCover(a)}}}handleRemoveLog(e,n,o){if(e.type===Xe.RemoveNode){const s=e.data;for(const r of s.idList){const i=n.nodeManager.getNode(r);if(!i)continue;const a=M.judgeSlideSectionChildren(i,o);a&&n.slideManager.slideCoverManager.updateSlideCover(a)}}}}class rg extends kc{constructor(){super(...arguments);p(this,"slideContainer",null)}enable(e,n){if(e.meta.streaming||n.docState.docMode!==he.SLIDE_EDIT)return!1;const o=n.docState.slideStatus.slideContainer;return o?(this.slideContainer=o,!0):!1}handle(e,n){this.slideContainer&&this.handleUpdateLog(e,n,this.slideContainer)}handleUpdateLog(e,n,o){if(e.type===Xe.UpdateNode){const s=e.data;for(const r of s.infos){const i=n.nodeManager.getNode(r.id);!i||i.id!==o.id||!r.props.find(c=>c.type===I.Slide)||n.slideManager.slideCoverManager.updateSlideContainerCover(o)}}}}class Nc{constructor(t){p(this,"executors",new Map);p(this,"ctx");p(this,"beforeInterceptors",[new sg,new rg]);p(this,"afterInterceptors",[]);for(const e of t)this.executors.set(e.type,e)}init(t){this.ctx=t}exec(t,e){const n=this.executors.get(t.type);if(!n){console.error("缺乏对应的消息处理器,已忽略该消息");return}for(const o of this.beforeInterceptors)o.enable(t,this.ctx)&&o.handle(t,this.ctx);n.exec(t,e);for(const o of this.afterInterceptors)o.enable(t,this.ctx)&&o.handle(t,this.ctx)}}class Bc{constructor(){p(this,"undoStack",[]);p(this,"redoStack",[])}add(t){const e=t.reverse();this.undoStack.push(e),this.redoStack=[]}undo(t,e){const n=this.undoStack.pop()||null;if(!n)return null;for(const o of n.actionLogs)t.exec(o,e);return this.redoStack.push(n.reverse()),n}redo(t,e){const n=this.redoStack.pop()||null;if(!n)return null;for(const o of n.actionLogs)t.exec(o,e);return this.undoStack.push(n.reverse()),n}}class as{constructor(t=[]){p(this,"actionLogs",[]);this.actionLogs=t}reverse(){const t=new as;for(let e=this.actionLogs.length-1;e>-1;e--){const n=this.actionLogs[e];t.actionLogs.push(n.reverse())}return t}}class Rc{constructor(){p(this,"cacheLogs",[]);p(this,"duringGroup",!1)}add(t){t.type===Xe.Start&&(this.duringGroup=!0),this.cacheLogs.push(t),t.type===Xe.End&&(this.duringGroup=!1)}getActionGroup(){if(this.duringGroup)return null;const t=new as(this.cacheLogs);return this.cacheLogs=[],t}}const Ec=new Set([Xe.Start,Xe.End,Xe.SelectNode,Xe.TextFocus]);class Hc{constructor(t,e,n,o,s,r,i,a,c,h,d,u){p(this,"execCtx");p(this,"executor");p(this,"undoManager");p(this,"networkPlugin",null);p(this,"actionCache");p(this,"renderManager");p(this,"docState");this.executor=new Nc(Ac),this.undoManager=new Bc,this.renderManager=r,this.execCtx={inputManager:e,nodeManager:t,gmlRender:n,auxiliaryManager:o,toolManager:s,renderManager:this.renderManager,resourceManager:i,idGenerator:c,slotManager:h,asyncRenderNodeManager:d,docState:a,slideManager:u},this.actionCache=new Rc,this.docState=a}addNetworkPlugin(t){this.networkPlugin=t}execAction(t){var n;this.dealDocSeq(t),this.executor.exec(t,this.execCtx),Ec.has(t.type)||(n=this.networkPlugin)==null||n.addMessage(t),this.actionCache.add(t);const e=this.actionCache.getActionGroup();e&&this.undoManager.add(e)}dealDocSeq(t){Ec.has(t.type)||this.docState.seq++}undo(){var e;const t=this.undoManager.undo(this.executor,this.execCtx);t&&((e=this.networkPlugin)==null||e.addActionGroup(t))}redo(){var e;const t=this.undoManager.redo(this.executor,this.execCtx);t&&((e=this.networkPlugin)==null||e.addActionGroup(t))}}function ig(l){return l.type===Xe.AddNode?{addNodeData:{data:l.data.nodes.map(n=>{const o=n.props,s=new Map;o.forEach(a=>s.set(a.type,a));const r=M.convertPropsToCapInfo(s);return{id:n.id,type:n.type,zIndex:n.zIndex,parentId:n.parentId,capInfo:r}})}}:l.type===Xe.UpdateNode?{updateNodeData:{data:l.data.infos.map(n=>{const o=n.props,s=new Map;o.forEach(a=>s.set(a.type,a));const r=M.convertPropsToCapInfo(s);return{id:n.id,zIndex:n.zIndex,parentId:n.parentId,capInfo:r}})}}:l instanceof At?{removeNodeData:{data:l.data.idList}}:null}function ag(l){const{updateNodeData:t,addNodeData:e,removeNodeData:n}=l;if(e){const o=[];for(const s of e.data)o.push({id:s.id,parentId:s.parentId,zIndex:s.zIndex,type:s.type,props:M.convertCapInfoToProps(s.capInfo)});return new Le({nodes:o})}if(t){const o=[];for(const s of t.data)o.push({id:s.id,zIndex:s.zIndex,parentId:s.parentId,props:M.convertCapInfoToProps(s.capInfo)});return new U({infos:o})}if(n)return At.create(n.data);throw new Error("类型转换错误!")}const gr=.04,yr=4;class Dc{static isMobile(){const t=navigator.userAgent||navigator.vendor||window.opera;if(/android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini|mobile/i.test(t.toLowerCase()))return!0;const n="ontouchstart"in window||navigator.maxTouchPoints>0,o=window.innerWidth<768;return n&&o}}const cg=70,lg=10;class hg{zoomScale(t,e,n){const o=n.getScale();let s=t;o*t>yr&&(s=yr/o),o*t<gr&&(s=gr/o),this.zoomToScale(s,e,n.gmlRender),this.zoomToScale(s,e,n.auxiliaryManager.gmlRender);const r=n.getScale();n.slotManager.addSlotState(ze.Scale,r),n.addContentRenderTask(),n.addAuxiliaryDrawTask()}zoomToSelect(t){if(t.auxiliaryManager.selectManager.getSelectNodes().length===0)return;const n=t.auxiliaryManager.selectManager.getSelectBounds();this.zoomToBounds(n,t)}zoomToFit(t){if(t.nodeManager.nodeMap.size===0)return;const n=t.nodeManager.getNodeBounds();this.zoomToBounds(n,t)}zoomTo100(t){if(t.nodeManager.nodeMap.size===0)return;const n=t.nodeManager.getNodeBounds(),o=t.gmlRender.canvas.getBoundingClientRect(),s=window.devicePixelRatio,r=1*s,i=new m(.5*s*o.width,.5*s*o.height),a=new m(.5*(n.minX+n.maxX),.5*(n.minY+n.maxY)),c=new m(-a.x*r+i.x,-a.y*r+i.y);this.zoomToMatrix(r,c.x,c.y,t.gmlRender),this.zoomToMatrix(r,c.x,c.y,t.auxiliaryManager.gmlRender);const h=t.getScale();t.slotManager.addSlotState(ze.Scale,h),t.addContentRenderTask(),t.addAuxiliaryDrawTask()}zoomToBounds(t,e,n){const o=Dc.isMobile()?lg:cg,s=n!==void 0?n:o,r=D.rectNode2Rect(t),i=e.gmlRender.canvas.getBoundingClientRect(),a=window.devicePixelRatio,c=i.width-s*2*a,h=i.height-s*2*a,d=c/r.width,u=h/r.height,f=Math.min(d,u)*a,g=new m(.5*a*i.width,.5*a*i.height),y=new m(.5*(t.minX+t.maxX),.5*(t.minY+t.maxY)),P=new m(-y.x*f+g.x,-y.y*f+g.y);this.zoomToMatrix(f,P.x,P.y,e.gmlRender),this.zoomToMatrix(f,P.x,P.y,e.auxiliaryManager.gmlRender);const b=e.getScale();e.slotManager.addSlotState(ze.Scale,b),e.addContentRenderTask(),e.addAuxiliaryDrawTask()}zoomToScale(t,e,n){n.scale(t,t,e);const o=n.glCtx,{a:s,b:r,c:i,d:a,e:c,f:h}=n.globalTransform;o.setTransform(s,r,i,a,c,h)}zoomToMatrix(t,e,n,o){const s=t,r=t,i=e,a=n;o.setTransform(s,0,0,r,i,a)}}class dg{exportToOfflineCanvas(t,e,n,o){const s=D.rectNode2Rect(t),r=document.createElement("canvas");r.width=n*s.width,r.height=n*s.height;const i=r.getContext("2d");i.scale(n,n),i.translate(-s.x,-s.y);let a=e.searchNodesByRectNode(t);a=M.sortGraphics(a),i.save(),o&&(i.fillStyle=o,i.fillRect(s.x,s.y,s.width,s.height)),i.restore();for(const c of a)c.drawOnGLCtx(i);return r}exportToOfflineCanvasByFilterNodes(t,e,n,o,s){const r=D.rectNode2Rect(t),i=document.createElement("canvas");i.width=n*r.width,i.height=n*r.height;const a=i.getContext("2d");a.scale(n,n),a.translate(-r.x,-r.y);let c=e.searchNodesByRectNode(t);c=M.sortGraphics(c),a.save(),o&&(a.fillStyle=o,a.fillRect(r.x,r.y,r.width,r.height)),a.restore();for(const h of c)s.has(h)&&h.drawOnGLCtx(a);return i}}class Oc{constructor(t,e,n,o){p(this,"gmlRender");p(this,"nodeManager");p(this,"auxiliaryManager");p(this,"slotManager");p(this,"zoomWorker",new hg);p(this,"exportWorker",new dg);p(this,"working",!1);p(this,"contentDraw",!1);p(this,"auxiliaryDraw",!1);p(this,"focusId");p(this,"tickerRun",()=>{if(this.contentDraw){const t=this.judgeFocusNode();t?this.auxiliaryManager.selectManager.docState.docMode===he.SLIDE_PLAY?this.drawInPlayingMode(t):this.drawInFocusMode(t):this.drawInNormalMode()}this.auxiliaryDraw&&(this.auxiliaryManager.redraw(),this.auxiliaryDraw=!1),this.working&&requestAnimationFrame(this.tickerRun)});p(this,"drawInNormalMode",()=>{const t=this.gmlRender.getViewPortBounds(),e=this.nodeManager.tree.search(t),n=new Set;for(const s of e){const r=this.nodeManager.nodeMap.get(s.id);r&&n.add(r)}let o=[...n];o=M.sortGraphics(o),this.gmlRender.dirtyDraw(t,o),this.contentDraw=!1});p(this,"drawInFocusMode",t=>{const e=this.gmlRender.getViewPortBounds(),n=new Set;M.getAllChildren(t,n);const o=M.sortGraphics([t,...n]);this.gmlRender.dirtyDraw(e,o),this.contentDraw=!1});p(this,"drawInPlayingMode",t=>{this.gmlRender.getViewPortBounds();const e=t.getBounds(),n=new Set;M.getAllChildren(t,n);const o=M.sortGraphics([t,...n]);this.gmlRender.dirtyDraw(e,o),this.contentDraw=!1});this.gmlRender=t,this.nodeManager=e,this.auxiliaryManager=n,this.slotManager=o}getScale(){return this.gmlRender.getScale()}zoomScale(t,e){this.zoomWorker.zoomScale(t,e,this)}zoomToFit(){this.zoomWorker.zoomToFit(this)}zoomToSelect(){this.zoomWorker.zoomToSelect(this)}zoomTo100(){this.zoomWorker.zoomTo100(this)}exportOfflineCanvas(t,e,n){return this.exportWorker.exportToOfflineCanvas(t,this.nodeManager,e,n)}scroll(t,e){this.scrollTo(t,e,this.gmlRender),this.scrollTo(t,e,this.auxiliaryManager.gmlRender),this.addContentRenderTask(),this.addAuxiliaryDrawTask()}start(){this.working=!0,this.tickerRun()}stop(){this.working=!1}addAuxiliaryDrawTask(){this.auxiliaryDraw=!0}addContentRenderTask(){this.contentDraw=!0}dirtyDraw(t){const e=this.nodeManager.tree.search(t),n=new Set;for(const r of e){const i=this.nodeManager.nodeMap.get(r.id);i&&n.add(i)}let o=[...n];o=M.sortGraphics(o);const s=this.judgeFocusNode();if(s){const r=new Set([s]);M.getAllChildren(s,r),o=o.filter(i=>r.has(i))}console.log("njx debug:====>",o.map(r=>r.id)),this.gmlRender.dirtyDraw(t,o)}judgeFocusNode(){if(this.focusId){const t=this.nodeManager.nodeMap.get(this.focusId);if(t)return t}return null}scrollTo(t,e,n){const o=n.getScale();n.translation(-t/o,-e/o);const s=n.glCtx,{a:r,b:i,c:a,d:c,e:h,f:d}=n.globalTransform;s.setTransform(r,i,a,c,h,d)}}const ug={default:"default"};class Xc{constructor(){p(this,"currentCursor","default");p(this,"currentAngle")}resetCursor(){this.currentCursor=null}setCursor(t,e){if(this.currentCursor!==null){const o=e!==void 0?`${t}-${e}`:t;if((this.currentAngle!==void 0?`${this.currentCursor}-${this.currentAngle}`:this.currentCursor)===o)return}if(t==="stretch"&&e!==void 0){const o=this.generateRotatedStretchCursorSvg(e),r=`url("data:image/svg+xml,${encodeURIComponent(o)}") 16 16, auto`;document.body.style.cursor=r,this.currentCursor=t,this.currentAngle=e;return}if(t==="rotate"&&e!==void 0){const o=this.generateRotatedRotateCursorSvg(e),r=`url("data:image/svg+xml,${encodeURIComponent(o)}") 16 16, auto`;document.body.style.cursor=r,this.currentCursor=t,this.currentAngle=e;return}const n=ug[t];n?document.body.style.cursor=n:document.body.style.cursor=t,this.currentCursor=t,this.currentAngle=void 0}generateRotatedStretchCursorSvg(t){return`<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32" fill="none">
|
|
6
6
|
<g transform="rotate(${t} 16 16)">
|