@yft-design/engine 0.0.52 → 0.0.53
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/core/psdEffects.d.ts +42 -0
- package/dist/index.js +58 -58
- package/dist/model/scene.d.ts +1 -0
- package/dist/render/imageEffects.d.ts +12 -1
- package/dist/render/psdBevel.d.ts +14 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
var _e={enabled:!1,metrics:new Map,counters:new Map,sampleRate:1,reportIntervalMs:5e3,reportTimer:null},
|
|
2
|
-
`)},pu=()=>{let n=mu();if(!_e.enabled)return n;let e=Wa(),t=Ha();return console.info(n),console.groupCollapsed("[canvas-perf] report details"),e.length?console.table(e):console.log("no timing metrics"),t.length&&console.table(t),console.groupEnd(),n},hb=()=>{typeof window>"u"||!_e.enabled||_e.reportTimer!=null||(_e.reportTimer=window.setInterval(pu,_e.reportIntervalMs))},db=()=>{_e.reportTimer!=null&&(window.clearInterval(_e.reportTimer),_e.reportTimer=null)},Ba=n=>{_e.enabled=n,n?(hb(),console.info("[canvas-perf] enabled")):(db(),console.info("[canvas-perf] disabled"))},bu=()=>_e.enabled,fb=()=>{_e.metrics.clear(),_e.counters.clear()},xu=(n,e=1)=>{_e.enabled&&_e.counters.set(n,(_e.counters.get(n)||0)+e)},oi=(n,e)=>{if(!_e.enabled)return;let t=ab(n);t.count+=1,t.total+=e,t.max=Math.max(t.max,e),t.last=e},Ga=(n,e)=>{if(!_e.enabled)return e();let t=fu();try{return e()}finally{oi(n,fu()-t)}};var gu=()=>{typeof window>"u"||window.__YFT_CANVAS_PERF__||(window.__YFT_CANVAS_PERF__={enable:()=>Ba(!0),disable:()=>Ba(!1),report:pu,reportJson:mu,reportText:ub,reset:fb,mark:xu,time:Ga,isEnabled:bu},sb()&&Ba(!0))};var Fn=class{_handlers=new Map;on(e,t){let r=this._handlers.get(e);r||(r=new Set,this._handlers.set(e,r));let o=t;return r.add(o),()=>this.off(e,o)}once(e,t){let r=t,o=(...i)=>{this.off(e,o),r(...i)};return this.on(e,o)}off(e,t){if(!t){this._handlers.delete(e);return}this._handlers.get(e)?.delete(t)}fire(e,...t){let r=this._handlers.get(e);if(!(!r||r.size===0))for(let o of[...r])o(...t)}clear(){this._handlers.clear()}};var dr=n=>n*Math.PI/180,$=(n,e,t=!1)=>[n[0]*e[0]+n[2]*e[1],n[1]*e[0]+n[3]*e[1],n[0]*e[2]+n[2]*e[3],n[1]*e[2]+n[3]*e[3],t?0:n[0]*e[4]+n[2]*e[5]+n[4],t?0:n[1]*e[4]+n[3]*e[5]+n[5]],ve=n=>{let e=1/(n[0]*n[3]-n[1]*n[2]),t=[e*n[3],-e*n[1],-e*n[2],e*n[0],0,0],r=t[0]*n[4]+t[2]*n[5],o=t[1]*n[4]+t[3]*n[5];return t[4]=-r,t[5]=-o,t},Q=(n,e,t,r=!1)=>({x:n[0]*e+n[2]*t+(r?0:n[4]),y:n[1]*e+n[3]*t+(r?0:n[5])}),mb=n=>n[0]===1&&n[1]===0&&n[2]===0&&n[3]===1&&n[4]===0&&n[5]===0,ii=n=>{if(typeof n=="number")return n-.5;switch(n){case"left":case"top":return-.5;case"right":case"bottom":return .5;default:return 0}},pb=n=>{let e=dr(n),t=Math.cos(e),r=Math.sin(e);return[t,r,-r,t,0,0]},yu=n=>{let{scaleX:e=1,scaleY:t=1,flipX:r=!1,flipY:o=!1,skewX:i=0,skewY:s=0}=n,a=[r?-e:e,0,0,o?-t:t,0,0];return i&&(a=$(a,[1,0,Math.tan(dr(i)),1,0,0],!0)),s&&(a=$(a,[1,Math.tan(dr(s)),0,1,0,0],!0)),a},kt=n=>{let{translateX:e=0,translateY:t=0,angle:r=0}=n,o=[1,0,0,1,e,t];r&&(o=$(o,pb(r)));let i=yu(n);return mb(i)||(o=$(o,i)),o},bb=(n,e,t)=>{let r=n/2,o=e/2,i=[],s=[];for(let[a,l]of[[-r,-o],[r,-o],[-r,o],[r,o]]){let c=Q(t,a,l,!0);i.push(c.x),s.push(c.y)}return{x:Math.max(...i)-Math.min(...i),y:Math.max(...s)-Math.min(...s)}},si=n=>{let{width:e=0,height:t=0,scaleX:r=1,scaleY:o=1,skewX:i=0,skewY:s=0,strokeWidth:a=0,strokeUniform:l}=n,c=l?0:a,u=l?a:0,h=e+c,d=t+c,f;return i===0&&s===0?f={x:h*r,y:d*o}:f=bb(h,d,yu(n)),{x:f.x+u,y:f.y+u}},On=n=>{let e=Xt(n);return kt({...n,translateX:e.x,translateY:e.y})},Xt=n=>{let e=si(n),t=-ii(n.originX??"left")*e.x,r=-ii(n.originY??"top")*e.y,o=n.angle??0;if(o){let i=dr(o),s=Math.cos(i),a=Math.sin(i),l=t*s-r*a,c=t*a+r*s;t=l,r=c}return{x:(n.left??0)+t,y:(n.top??0)+r}},xe=(n,e)=>{let t=si(n),r=-ii(n.originX??"left")*t.x,o=-ii(n.originY??"top")*t.y,i=n.angle??0;if(i){let s=dr(i),a=Math.cos(s),l=Math.sin(s),c=r*a-o*l,u=r*l+o*a;r=c,o=u}return{x:e.x-r,y:e.y-o}},xb=n=>{let e=a=>a*180/Math.PI,t=e(Math.atan2(n[1],n[0])),r=n[0]*n[0]+n[1]*n[1],o=Math.sqrt(r),i=r===0?0:(n[0]*n[3]-n[2]*n[1])/o,s=r===0?0:e(Math.atan2(n[0]*n[2]+n[1]*n[3],r));return{angle:t,scaleX:o,scaleY:i,skewX:s,skewY:0,center:{x:n[4],y:n[5]}}},Xa=n=>{let e=Xt(n),t=dr(n.angle??0),r=Math.cos(t),o=Math.sin(t),i=si(n),s=i.x/2,a=i.y/2,l=(c,u)=>({x:e.x+r*c-o*u,y:e.y+o*c+r*u});return{tl:l(-s,-a),tr:l(s,-a),br:l(s,a),bl:l(-s,a)}},Bn=n=>{let e=[n.tl.x,n.tr.x,n.br.x,n.bl.x],t=[n.tl.y,n.tr.y,n.br.y,n.bl.y],r=Math.min(...e),o=Math.min(...t);return{left:r,top:o,right:Math.max(...e),bottom:Math.max(...t),width:Math.max(...e)-r,height:Math.max(...t)-o}},qr=(n,e,t,r)=>{let o=Math.max(1,e*r),i=Math.max(1,t*r),s=[2/o,0,0,-2/i,-1,1];return $(s,$([r,0,0,r,0,0],n))};var ht=(n,e=!1)=>{if(typeof window>"u")return e;let t=new URLSearchParams(window.location.search).get(n);if(t==="1"||t==="true")return!0;if(t==="0"||t==="false")return!1;let r=window.localStorage.getItem(`engine.${n}`);return r==="1"?!0:r==="0"?!1:e},Su=()=>ht("gpuShadow",!0),za=()=>ht("gpuPsdShadow",!0),Ya=()=>ht("gpuPsdFill",!0),vu=()=>ht("stencilClip",!0),Ua=()=>{if(typeof window>"u")return!0;let n=new URLSearchParams(window.location.search).get("snapGuide");return!(n==="0"||n==="false")},wu=()=>ht("arcGlyph",!0),gb=()=>ht("export",!0),$a=()=>ht("retained",!0),Wn=()=>ht("retainedDebug",!1),ai=()=>ht("sdfDash",!0),Tu=()=>ht("sdfPolygon",!0),Eu=()=>ht("sdfLineDeco",!0),yb=()=>ht("svgexport",!0);var Sb={transparent:"#0000",aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"},Cu=n=>{if(n.length===3||n.length===4){let e=parseInt(n[0]+n[0],16)/255,t=parseInt(n[1]+n[1],16)/255,r=parseInt(n[2]+n[2],16)/255,o=n.length===4?parseInt(n[3]+n[3],16)/255:1;return[e,t,r,o]}if(n.length===6||n.length===8){let e=parseInt(n.slice(0,2),16)/255,t=parseInt(n.slice(2,4),16)/255,r=parseInt(n.slice(4,6),16)/255,o=n.length===8?parseInt(n.slice(6,8),16)/255:1;return[e,t,r,o]}return[0,0,0,0]},vb=Object.fromEntries(Object.entries(Sb).map(([n,e])=>[n,Cu(e.slice(1))])),Kr=n=>Math.min(1,Math.max(0,n)),wb=65536,li=new Map,oe=n=>{if(!n)return[0,0,0,0];if(Array.isArray(n))return n;if(typeof n!="string")return[0,0,0,0];let e=li.get(n);if(e)return e;let t=Tb(n);return li.size>=wb&&li.clear(),li.set(n,t),t},Tb=n=>{let e=n.trim().toLowerCase(),t=vb[e];if(t)return t;if(e.startsWith("#"))return Cu(e.slice(1));let r=e.match(/^(rgba?|hsla?)\(([^)]+)\)$/);if(r){let o=r[2].split(/[\s,/]+/).filter(Boolean);if(r[1].startsWith("rgb")&&o.length>=3){let i=s=>s.endsWith("%")?parseFloat(s)/100*255:parseFloat(s);return[Kr(i(o[0])/255),Kr(i(o[1])/255),Kr(i(o[2])/255),o[3]!==void 0?Kr(parseFloat(o[3])):1]}if(r[1].startsWith("hsl")&&o.length>=3){let i=parseFloat(o[0])/360,s=parseFloat(o[1])/100,a=parseFloat(o[2])/100,l=(d,f,m)=>(m<0&&(m+=1),m>1&&(m-=1),m<1/6?d+(f-d)*6*m:m<1/2?f:m<2/3?d+(f-d)*(2/3-m)*6:d),c=a<.5?a*(1+s):a+s-a*s,u=2*a-c,h=o[3]!==void 0?Kr(parseFloat(o[3])):1;return[l(u,c,i+1/3),l(u,c,i),l(u,c,i-1/3),h]}}return[0,0,0,0]};var Hn=n=>{if(!n||typeof n!="object"||Array.isArray(n))return null;let e=n,t=e.type;if(typeof t!="string"||t==="pattern")return null;let r=t==="linear"?"linear":"radial",o=e.coords??{},i=Array.isArray(e.colorStops)?e.colorStops:[],s=[];for(let a of i){if(!a||typeof a!="object")continue;let l=a,c=oe(l.color),u=typeof l.opacity=="number"?l.opacity:1;s.push({offset:Number(l.offset)||0,color:[c[0],c[1],c[2],c[3]*u]})}return s.length===0?null:(s.sort((a,l)=>a.offset-l.offset),{kind:r,x1:Number(o.x1)||0,y1:Number(o.y1)||0,x2:Number(o.x2)||0,y2:Number(o.y2)||0,r1:Math.max(0,Number(o.r1)||0),r2:Math.max(0,Number(o.r2)||0),stops:s,offsetX:Number(e.offsetX)||0,offsetY:Number(e.offsetY)||0,gradientUnits:e.gradientUnits==="percentage"?"percentage":"pixels",gradientTransform:Array.isArray(e.gradientTransform)&&e.gradientTransform.length===6?[...e.gradientTransform]:null})},ci=(n,e,t)=>{let r=[1,0,0,1,-e/2+n.offsetX,-t/2+n.offsetY];return n.gradientUnits==="percentage"&&(r=$(r,[e,0,0,t,0,0])),n.gradientTransform&&(r=$(r,n.gradientTransform)),r};var Mu=(n,e)=>{let t=n.x2-n.x1,r=n.y2-n.y1,o=t*t+r*r;return o<=0?0:((e.x-n.x1)*t+(e.y-n.y1)*r)/o},Ru=(n,e)=>{let t=n.x2-n.x1,r=n.y2-n.y1,o=n.r2-n.r1,i=e.x-n.x1,s=e.y-n.y1,a=t*t+r*r-o*o,l=2*(-(t*i+r*s)-n.r1*o),c=i*i+s*s-n.r1*n.r1;if(Math.abs(a)<1e-9)return Math.abs(l)>1e-9?-c/l:0;let u=Math.max(0,l*l-4*a*c);return(-l-Math.sqrt(u))/(2*a)},ui=(n,e=512)=>{let t=new Uint8Array(e*4),r=n.stops,o=i=>Math.round(Math.min(255,Math.max(0,i*255)));for(let i=0;i<e;i++){let s=i/(e-1),a;if(s<=r[0].offset)a=r[0].color;else if(s>=r[r.length-1].offset)a=r[r.length-1].color;else{let l=r[0],c=r[1];for(let h=0;h<r.length-1;h++)if(s>=r[h].offset&&s<=r[h+1].offset){l=r[h],c=r[h+1];break}let u=c.offset===l.offset?0:(s-l.offset)/(c.offset-l.offset);a=[l.color[0]+(c.color[0]-l.color[0])*u,l.color[1]+(c.color[1]-l.color[1])*u,l.color[2]+(c.color[2]-l.color[2])*u,l.color[3]+(c.color[3]-l.color[3])*u]}t[i*4]=o(a[0]),t[i*4+1]=o(a[1]),t[i*4+2]=o(a[2]),t[i*4+3]=o(a[3])}return t},hi=n=>{let e=r=>String(Math.round(r*1e4)/1e4),t=n.stops.map(r=>`${e(r.offset)}:${r.color.map(o=>e(o)).join(",")}`).join(";");return[n.kind,e(n.x1),e(n.y1),e(n.x2),e(n.y2),e(n.r1),e(n.r2),t,e(n.offsetX),e(n.offsetY),n.gradientUnits,n.gradientTransform?n.gradientTransform.map(e).join(","):""].join("|")};var Eb=["repeat","repeat-x","repeat-y","no-repeat"],di=n=>{if(!n||typeof n!="object"||Array.isArray(n))return null;let e=n;if(e.type!=="pattern"||typeof e.source!="string"||!e.source)return null;let t=Eb.includes(e.repeat)?e.repeat:"repeat";return{kind:"pattern",src:e.source,repeat:t,offsetX:Number(e.offsetX)||0,offsetY:Number(e.offsetY)||0,patternTransform:Array.isArray(e.patternTransform)&&e.patternTransform.length===6?[...e.patternTransform]:null,crossOrigin:typeof e.crossOrigin=="string"?e.crossOrigin:null}},fi=(n,e,t)=>{let r=[1,0,0,1,-e/2+n.offsetX,-t/2+n.offsetY];return n.patternTransform&&(r=$(r,n.patternTransform)),r},Pu=n=>[n==="repeat"||n==="repeat-x",n==="repeat"||n==="repeat-y"];var L={TEXTBOX:"textbox",TEXT:"text",ITEXT:"i-text",INPUTTEXT:"itext",ARCHTEXT:"archtext",WAISTTEXT:"waisttext",FLAGTEXT:"flagtext",ARCTEXT:"arctext",CIRCLETEXT:"circletext",SCROLLTEXT:"scrolltext",TEXTIMAGE:"textimage",IMAGE:"image",SVGIMAGE:"svgimage",CROPIMAGE:"cropimage",ECHART:"echart",FABRIC_ECHART:"fabricechart",QRCODE:"qrcode",BARCODE:"barcode",MASK:"mask",PATH:"path",RECT:"rect",FABRICRECT:"fabricrect",LINE:"line",ARROW:"arrow",POLYLINE:"polyline",POLYGON:"polygon",ELLIPSE:"ellipse",CIRCLE:"circle",TRIANGLE:"triangle",TABLE:"table",GROUP:"group",ACTIVE_SELECTION:"activeselection",PUZZLE:"puzzle",GIF:"gif",VIDEO:"video",DIMENSION:"dimension",REFERENCELINE:"referenceline"},se=n=>{let e=n?.type;return typeof e=="string"?e.toLowerCase():""},rn=new Set([L.TEXTBOX,L.INPUTTEXT,L.ITEXT,L.TEXT,L.ARCHTEXT,L.WAISTTEXT,L.FLAGTEXT,L.ARCTEXT,L.CIRCLETEXT,L.SCROLLTEXT,L.TEXTIMAGE]),dt=new Set([L.IMAGE,L.SVGIMAGE,L.CROPIMAGE,L.QRCODE,L.BARCODE,L.ECHART,L.FABRIC_ECHART]),Gn=new Set([L.ELLIPSE,L.CIRCLE,L.POLYGON,L.POLYLINE,L.PATH,L.TRIANGLE]),ft=new Set([L.LINE,L.ARROW,L.DIMENSION,L.REFERENCELINE]),Xn=new Set([L.RECT,L.FABRICRECT]),ot=new Set([L.MASK]),mi=new Set([L.PUZZLE]),pi=new Set([L.GIF]),bi=new Set([L.VIDEO]);var on=1-.5522847498,ja=new Set([L.FABRICRECT]),sn=(n,e)=>typeof n=="number"&&Number.isFinite(n)?n:e,Va=(n,e,t)=>{let r=sn(n,0);return r>0?{rx:r/(sn(e,1)||1),ry:r/(sn(t,1)||1)}:null},ku=n=>{if(!ja.has(se(n)))return;let e=Va(n.radius,n.scaleX,n.scaleY);e&&(n.rx=e.rx,n.ry=e.ry)},Au=(n,e)=>{if(!ja.has(se(n)))return!1;let t="radius"in e,r="scaleX"in e||"scaleY"in e,o=sn(n.radius,0)>0&&("rx"in e||"ry"in e);if(!t&&!r&&!o)return!1;let i=t?e.radius:n.radius,s="scaleX"in e?e.scaleX:n.scaleX,a="scaleY"in e?e.scaleY:n.scaleY,l=Va(i,s,a);return e.rx=l?l.rx:0,e.ry=l?l.ry:0,!0},it=(n,e,t)=>{if(!(e>0)||!(t>0))return null;let r=ja.has(se(n))?Va(n.radius,n.scaleX,n.scaleY):null,o=r?r.rx:sn(n.rx,0),i=r?r.ry:sn(n.ry,0);o>0&&!(i>0)&&(i=o);let s=Math.min(o,e/2),a=Math.min(i,t/2);return s>0||a>0?{rx:s,ry:a}:null},fr=(n,e,t)=>{if(!(e>0)||!(t>0))return null;let r=Math.min(Math.max(sn(n.rx,0),sn(n.ry,0)),e/2,t/2);return r>0?r:null},zn=(n,e,t,r,o)=>{let i=Math.max(0,e),s=Math.max(0,t),a=Math.min(Math.max(0,r),i/2),l=Math.min(Math.max(0,o),s/2),c=-i/2,u=-s/2,h=a!==0||l!==0;n.beginPath(),n.moveTo(c+a,u),n.lineTo(c+i-a,u),h&&n.bezierCurveTo(c+i-on*a,u,c+i,u+on*l,c+i,u+l),n.lineTo(c+i,u+s-l),h&&n.bezierCurveTo(c+i,u+s-on*l,c+i-on*a,u+s,c+i-a,u+s),n.lineTo(c+a,u+s),h&&n.bezierCurveTo(c+on*a,u+s,c,u+s-on*l,c,u+s-l),n.lineTo(c,u+l),h&&n.bezierCurveTo(c,u+on*l,c+on*a,u,c+a,u),n.closePath()},Nu=(n,e,t,r)=>{let o=Math.max(0,n),i=Math.max(0,e);if(!(o>0)||!(i>0))return null;let s=Math.min(Math.max(0,t),o/2),a=Math.min(Math.max(0,r),i/2);if(!(s>0)&&!(a>0))return null;let l=Math.max(2,Math.min(16,Math.ceil((s+a)*.6))),c=[[o/2-s,-i/2+a,s,a,-Math.PI/2],[o/2-s,i/2-a,s,a,0],[-o/2+s,i/2-a,s,a,Math.PI/2],[-o/2+s,-i/2+a,s,a,Math.PI]],u=[0,0];for(let[f,m,p,b,x]of c)for(let g=0;g<l;g++){let y=x+g/l*(Math.PI/2);u.push(f+p*Math.cos(y),m+b*Math.sin(y))}let h=u.length/2-1,d=new Uint32Array(h*3);for(let f=0;f<h;f++)d[f*3]=0,d[f*3+1]=1+f,d[f*3+2]=1+(f+1)%h;return{verts:new Float32Array(u),triangles:d}};import Cb from"rbush";var Ae=1e-12,Mb=96,xi=(n,e,t,r,o,i)=>(t-n)*(i-e)-(r-e)*(o-n),qa=(n,e,t,r)=>{if(Math.abs(r)>Ae)return!1;let o=e.x-n.x,i=e.y-n.y,s=o*o+i*i;if(s<Ae)return!0;let a=(t.x-n.x)*o+(t.y-n.y)*i;return a>=-Ae&&a<=s+Ae},mr=n=>{let e=0;for(let t=0;t<n.length;t++){let r=n[t],o=n[(t+1)%n.length];e+=r.x*o.y-o.x*r.y}return e/2},Lu=(n,e,t,r,o)=>{let i=n[e];if(Math.abs(i.x-t.x)<Ae&&Math.abs(i.y-t.y)<Ae||Math.abs(i.x-r.x)<Ae&&Math.abs(i.y-r.y)<Ae||Math.abs(i.x-o.x)<Ae&&Math.abs(i.y-o.y)<Ae)return!1;let s=xi(t.x,t.y,r.x,r.y,i.x,i.y),a=xi(r.x,r.y,o.x,o.y,i.x,i.y),l=xi(o.x,o.y,t.x,t.y,i.x,i.y);return s>Ae&&a>Ae&&l>Ae||s<-Ae&&a<-Ae&&l<-Ae?!0:qa(t,r,i,s)||qa(r,o,i,a)||qa(o,t,i,l)},Ka=n=>{let e=n.length;if(e<3)return[];let t=mr(n);if(Math.abs(t)<Ae)return[];let r=new Array(e);for(let d=0;d<e;d++)r[d]=t>0?d:e-1-d;let o=[],i=r.length,s=i*i+16,a=0,l=null,c=null,u=null;if(e>=Mb){l=new Cb,c=new Array(e);for(let d=0;d<e;d++){let f=n[d];c[d]={minX:f.x,minY:f.y,maxX:f.x,maxY:f.y,v:d}}l.load(c),u=new Uint8Array(e).fill(1)}let h=0;for(;i>3&&s-- >0&&(a>=i&&(a=0),!(++h>i));){let d=r[a],f=r[(a+1)%i],m=r[(a+2)%i],p=n[d],b=n[f],x=n[m],g=xi(p.x,p.y,b.x,b.y,x.x,x.y);if(g>Ae){let y=!1;if(l&&c){let v=Math.min(p.x,b.x,x.x)-Ae,S=Math.max(p.x,b.x,x.x)+Ae,w=Math.min(p.y,b.y,x.y)-Ae,R=Math.max(p.y,b.y,x.y)+Ae,P=l.search({minX:v,minY:w,maxX:S,maxY:R});for(let E=0;E<P.length;E++){let C=P[E].v;if(u[C]&&!(C===d||C===f||C===m)&&Lu(n,C,p,b,x)){y=!0;break}}}else for(let v=3;v<i;v++){let S=r[(a+v)%i];if(Lu(n,S,p,b,x)){y=!0;break}}if(!y){o.push(d,f,m);let v=r.splice((a+1)%i,1)[0];i--,u&&(u[v]=0),h=0;continue}}else if(g>=-Ae){let y=r.splice((a+1)%i,1)[0];i--,u&&(u[y]=0),h=0;continue}a++}if(i>3)for(let d=1;d<i-1;d++)o.push(r[0],r[d],r[d+1]);else i===3&&o.push(r[0],r[1],r[2]);return o};var gi=Math.PI,Rb=Math.PI/180,Hu=Math.PI/2,Za=n=>{if(n===0)return 1;switch(Math.abs(n)/Hu){case 1:case 3:return 0;case 2:return-1}return Math.cos(n)},Ja=n=>{if(n===0)return 0;let e=n/Hu,t=Math.sign(n);switch(e){case 1:return t;case 2:return 0;case 3:return-t}return Math.sin(n)},Pb=/[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/gi,kb=/[mzlhvcsqta][^mzlhvcsqta]*/gi,Yn=/\s*,?\s*/,Qr="([-+]?(?:\\d*\\.\\d+|\\d+\\.?)(?:[eE][-+]?\\d+)?)",Qa=new RegExp(`${Yn.source}${Qr}${Yn.source}${Qr}${Yn.source}${Qr}${Yn.source}([01])${Yn.source}([01])${Yn.source}${Qr}${Yn.source}${Qr}`,"g"),Gu={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},Ab={m:"l",M:"L"},Nb=n=>{let e=[],t=n.match(kb)??[];for(let r of t){let o=r[0];if(o==="z"||o==="Z"){e.push([o]);continue}let i=Gu[o.toLowerCase()],s=[];if(o==="a"||o==="A"){Qa.lastIndex=0;for(let a=Qa.exec(r);a;a=Qa.exec(r))s=s.concat(a.slice(1))}else s=r.match(Pb)??[];for(let a=0;a<s.length;a+=i){let l=new Array(i),c=Ab[o];l[0]=a>0&&c?c:o;for(let u=0;u<i;u++)l[u+1]=parseFloat(s[a+u]);e.push(l)}}return e},Iu=(n,e,t,r)=>{let o=Math.atan2(e,n),i=Math.atan2(r,t);return i>=o?i-o:2*gi-(o-i)},Lb=(n,e,t,r,o,i,s,a,l,c,u)=>{let h=Za(n),d=Ja(n),f=Za(e),m=Ja(e),p=t*o*f-r*i*m+s,b=r*o*f+t*i*m+a,x=c+l*(-t*o*d-r*i*h),g=u+l*(-r*o*d+t*i*h),y=p+l*(t*o*m+r*i*f),v=b+l*(r*o*m-t*i*f);return["C",x,g,y,v,p,b]},Ib=(n,e,t,r,o,i,s)=>{if(t===0||r===0)return[];let a=0,l=0,c=0,u=s*Rb,h=Ja(u),d=Za(u),f=.5*(-d*n-h*e),m=.5*(-d*e+h*n),p=t**2,b=r**2,x=m**2,g=f**2,y=p*b-p*x-b*g,v=Math.abs(t),S=Math.abs(r);if(y<0){let H=Math.sqrt(1-y/(p*b));v*=H,S*=H}else c=(o===i?-1:1)*Math.sqrt(y/(p*x+b*g));let w=c*v*m/S,R=-c*S*f/v,P=d*w-h*R+n*.5,E=h*w+d*R+e*.5,C=Iu(1,0,(f-w)/v,(m-R)/S),T=Iu((f-w)/v,(m-R)/S,(-f-w)/v,(-m-R)/S);i===0&&T>0?T-=2*gi:i===1&&T<0&&(T+=2*gi);let M=Math.ceil(Math.abs(T/gi*2)),k=[],A=T/M,O=8/3*Math.sin(A/4)*Math.sin(A/4)/Math.sin(A/2),F=C+A;for(let H=0;H<M;H++)k[H]=Lb(C,F,d,h,v,S,P,E,O,a,l),a=k[H][5],l=k[H][6],C=F,F+=A;return k},_b=(n,e,t,r,o,i,s,a,l)=>Ib(a-n,l-e,t,r,i,s,o).map(c=>(c[1]=c[1]+n,c[2]=c[2]+e,c[3]=c[3]+n,c[4]=c[4]+e,c[5]=c[5]+n,c[6]=c[6]+e,c)),_u=n=>{let e=0,t=0,r=0,o=0,i=[],s,a=0,l=0;for(let c of n){let u=[...c],h;switch(u[0]){case"l":u[1]+=e,u[2]+=t;case"L":e=u[1],t=u[2],h=["L",e,t];break;case"h":u[1]+=e;case"H":e=u[1],h=["L",e,t];break;case"v":u[1]+=t;case"V":t=u[1],h=["L",e,t];break;case"m":u[1]+=e,u[2]+=t;case"M":e=u[1],t=u[2],r=u[1],o=u[2],h=["M",e,t];break;case"c":u[1]+=e,u[2]+=t,u[3]+=e,u[4]+=t,u[5]+=e,u[6]+=t;case"C":a=u[3],l=u[4],e=u[5],t=u[6],h=["C",u[1],u[2],a,l,e,t];break;case"s":u[1]+=e,u[2]+=t,u[3]+=e,u[4]+=t;case"S":s==="C"?(a=2*e-a,l=2*t-l):(a=e,l=t),e=u[3],t=u[4],h=["C",a,l,u[1],u[2],e,t],a=h[3],l=h[4];break;case"q":u[1]+=e,u[2]+=t,u[3]+=e,u[4]+=t;case"Q":a=u[1],l=u[2],e=u[3],t=u[4],h=["Q",a,l,e,t];break;case"t":u[1]+=e,u[2]+=t;case"T":s==="Q"?(a=2*e-a,l=2*t-l):(a=e,l=t),e=u[1],t=u[2],h=["Q",a,l,e,t];break;case"a":u[6]+=e,u[7]+=t;case"A":for(let d of _b(e,t,u[1],u[2],u[3],u[4],u[5],u[6],u[7]))i.push(d);e=u[6],t=u[7];break;case"z":case"Z":e=r,t=o,h=["Z"];break}h&&(i.push(h),s=h[0])}return i},Ce=n=>{if(typeof n=="string"){if(!n)return null;let e=Nb(n);return e.length>0?_u(e):null}if(Array.isArray(n)){if(n.length===0)return null;let e=[];for(let t of n){if(!Array.isArray(t)||typeof t[0]!="string")continue;let r=t[0].toLowerCase();(r==="z"||Gu[r]!==void 0)&&e.push(t)}return e.length===0?null:_u(e)}return null},Du=(n,e,t,r,o,i,s,a)=>{let l=[],c=[],u=[],h=6*n-12*t+6*o,d=-3*n+9*t-9*o+3*s,f=3*t-3*n;for(let p=0;p<2;++p){if(p>0&&(h=6*e-12*r+6*i,d=-3*e+9*r-9*i+3*a,f=3*r-3*e),Math.abs(d)<1e-12){if(Math.abs(h)<1e-12)continue;let v=-f/h;0<v&&v<1&&l.push(v);continue}let b=h*h-4*f*d;if(b<0)continue;let x=Math.sqrt(b),g=(-h+x)/(2*d);0<g&&g<1&&l.push(g);let y=(-h-x)/(2*d);0<y&&y<1&&l.push(y)}let m=l.length;for(let p=0;p<m;p++){let b=l[p],x=b**3,g=3*b**2*(1-b),y=3*b*(1-b)**2,v=(1-b)**3;c.push(s*x+o*g+t*y+n*v),u.push(a*x+i*g+r*y+e*v)}return c.push(n,s),u.push(e,a),[{x:Math.min(...c),y:Math.min(...u)},{x:Math.max(...c),y:Math.max(...u)}]},Fe=n=>{let e=[],t=0,r=0,o=0,i=0;for(let u of n)switch(u[0]){case"L":o=u[1],i=u[2],e.push({x:t,y:r},{x:o,y:i});break;case"M":o=u[1],i=u[2],t=o,r=i;break;case"C":for(let h of Du(o,i,u[1],u[2],u[3],u[4],u[5],u[6]))e.push(h);o=u[5],i=u[6];break;case"Q":for(let h of Du(o,i,u[1],u[2],u[1],u[2],u[3],u[4]))e.push(h);o=u[3],i=u[4];break;case"Z":o=t,i=r;break}if(e.length===0)return null;let s=1/0,a=1/0,l=-1/0,c=-1/0;for(let u of e){if(!Number.isFinite(u.x)||!Number.isFinite(u.y))return null;s>u.x&&(s=u.x),a>u.y&&(a=u.y),l<u.x&&(l=u.x),c<u.y&&(c=u.y)}return{left:s,top:a,right:l,bottom:c}},Db=(n,e,t,r,o,i,s,a)=>{let l=s-n,c=a-e,u=l*l+c*c;if(u<1e-12)return Math.hypot(t-n,r-e)+Math.hypot(o-s,i-a);let h=Math.abs(l*(r-e)-c*(t-n)),d=Math.abs(l*(i-e)-c*(o-n));return(h+d)/Math.sqrt(u)},yi=(n,e,t,r,o,i,s,a,l,c,u)=>{if(u>24){n.push({x:a,y:l});return}if(Db(e,t,r,o,i,s,a,l)<=c){n.push({x:a,y:l});return}let h=(e+r)/2,d=(t+o)/2,f=(r+i)/2,m=(o+s)/2,p=(i+a)/2,b=(s+l)/2,x=(h+f)/2,g=(d+m)/2,y=(f+p)/2,v=(m+b)/2,S=(x+y)/2,w=(g+v)/2;yi(n,e,t,h,d,x,g,S,w,c,u+1),yi(n,S,w,y,v,p,b,a,l,c,u+1)},Xu=(n,e=.1)=>{let t=[],r=null,o=0,i=0,s=0,a=0;for(let l of n)switch(l[0]){case"M":{r&&r.length>=2&&t.push({points:r,closed:!1}),r=[{x:l[1],y:l[2]}],o=l[1],i=l[2],s=o,a=i;break}case"L":{o=l[1],i=l[2],(r??=[]).push({x:o,y:i});break}case"C":{yi(r??=[],o,i,l[1],l[2],l[3],l[4],l[5],l[6],e,0),o=l[5],i=l[6];break}case"Q":{yi(r??=[],o,i,o+2/3*(l[1]-o),i+2/3*(l[2]-i),l[3]+2/3*(l[1]-l[3]),l[4]+2/3*(l[2]-l[4]),l[3],l[4],e,0),o=l[3],i=l[4];break}case"Z":{if(r&&r.length>=2){let c=r[0],u=r[r.length-1];(Math.abs(c.x-u.x)>1e-9||Math.abs(c.y-u.y)>1e-9)&&r.push({x:c.x,y:c.y}),t.push({points:r,closed:!0})}r=null,o=s,i=a;break}}return r&&r.length>=2&&t.push({points:r,closed:!1}),t},Fu=(n,e)=>{let t=!1;for(let r=0,o=e.length-1;r<e.length;o=r++){let i=e[o],s=e[r];s.y>n.y!=i.y>n.y&&n.x<(i.x-s.x)*(n.y-s.y)/(i.y-s.y)+s.x&&(t=!t)}return t},Fb=n=>{if(n.length<3)return[];let e=n,t=e[0],r=e[e.length-1];return Math.abs(t.x-r.x)<1e-9&&Math.abs(t.y-r.y)<1e-9?e.slice(0,-1):e.slice()},Ob=(n,e,t,r)=>{let o=(e.x-n.x)*(r.y-n.y)-(e.y-n.y)*(r.x-n.x),i=(t.x-e.x)*(r.y-e.y)-(t.y-e.y)*(r.x-e.x),s=(n.x-t.x)*(r.y-t.y)-(n.y-t.y)*(r.x-t.x),a=o<-1e-12||i<-1e-12||s<-1e-12,l=o>1e-12||i>1e-12||s>1e-12;return!(a&&l)},zu=(n,e,t,r)=>{let o=(e.x-n.x)*(r.y-t.y)-(e.y-n.y)*(r.x-t.x);if(Math.abs(o)<1e-12)return!1;let i=((t.x-n.x)*(r.y-t.y)-(t.y-n.y)*(r.x-t.x))/o,s=((t.x-n.x)*(e.y-n.y)-(t.y-n.y)*(e.x-n.x))/o;return i>1e-9&&i<1-1e-9&&s>1e-9&&s<1-1e-9},Bb=(n,e,t)=>{for(let r=0,o=e.length-1;r<e.length;o=r++){let i=e[o],s=e[r],a=s.x-i.x,l=s.y-i.y,c=a*a+l*l;if(c===0){if(Math.hypot(n.x-i.x,n.y-i.y)<=t)return!0;continue}let u=Math.min(1,Math.max(0,((n.x-i.x)*a+(n.y-i.y)*l)/c));if(Math.hypot(n.x-i.x-u*a,n.y-i.y-u*l)<=t)return!0}return!1},el=n=>{let e=1/0,t=1/0,r=-1/0,o=-1/0;for(let i of n)i.x<e&&(e=i.x),i.x>r&&(r=i.x),i.y<t&&(t=i.y),i.y>o&&(o=i.y);return{minX:e,minY:t,maxX:r,maxY:o}},Ou=(n,e,t)=>e.x>=n.minX-t&&e.x<=n.maxX+t&&e.y>=n.minY-t&&e.y<=n.maxY+t,Wb=n=>{let e=n.length,t=el(n),r=Math.max(8,Math.min(64,Math.ceil(Math.sqrt(e)))),o=Math.max(t.maxX-t.minX,1e-9)/r,i=Math.max(t.maxY-t.minY,1e-9)/r,s=new Array(r*r),a=l=>{let c=Math.max(0,Math.min(r-1,Math.floor((Math.min(l.pa.x,l.pb.x)-t.minX)/o))),u=Math.max(0,Math.min(r-1,Math.floor((Math.max(l.pa.x,l.pb.x)-t.minX)/o))),h=Math.max(0,Math.min(r-1,Math.floor((Math.min(l.pa.y,l.pb.y)-t.minY)/i))),d=Math.max(0,Math.min(r-1,Math.floor((Math.max(l.pa.y,l.pb.y)-t.minY)/i)));for(let f=h;f<=d;f++)for(let m=c;m<=u;m++)(s[f*r+m]??=[]).push(l)};for(let l=0;l<e;l++)a({pa:n[l],pb:n[(l+1)%e]});return{addEdge:(l,c)=>a({pa:l,pb:c}),blockedExcept(l,c){let u=Math.max(0,Math.min(r-1,Math.floor((Math.min(l.x,c.x)-t.minX)/o))),h=Math.max(0,Math.min(r-1,Math.floor((Math.max(l.x,c.x)-t.minX)/o))),d=Math.max(0,Math.min(r-1,Math.floor((Math.min(l.y,c.y)-t.minY)/i))),f=Math.max(0,Math.min(r-1,Math.floor((Math.max(l.y,c.y)-t.minY)/i)));for(let m=d;m<=f;m++)for(let p=u;p<=h;p++){let b=s[m*r+p];if(b){for(let x of b)if(!(x.pa===c||x.pb===c)&&zu(l,c,x.pa,x.pb))return!0}}return!1}}},Hb=(n,e,t)=>{let r=n.length,o=0;for(let y=1;y<e.length;y++)(e[y].x>e[o].x||e[y].x===e[o].x&&e[y].y>e[o].y)&&(o=y);let i=e[o],s=-1,a=1/0;for(let y=0;y<r;y++){let v=n[y],S=Math.hypot(v.x-i.x,v.y-i.y);if(S>=a)continue;let w=t.blockedExcept(i,v);if(!w){for(let R=0;R<e.length;R++)if(!(R===o||(R+1)%e.length===o)&&zu(i,v,e[R],e[(R+1)%e.length])){w=!0;break}}w||(a=S,s=y)}if(s>=0){let y=[];for(let v=s;v<r;v++)y.push(n[v]);for(let v=0;v<s;v++)y.push(n[v]);y.push(n[s]),y.push(i);for(let v=1;v<e.length;v++)y.push(e[(o+v)%e.length]);return y.push(i),Bu(t,n[s],i,e),y}let l=1/0,c=-1;for(let y=0;y<r;y++){let v=n[y],S=n[(y+1)%r];if(v.y!==S.y&&i.y>=Math.min(v.y,S.y)&&i.y<Math.max(v.y,S.y)){let w=(i.y-v.y)/(S.y-v.y),R=v.x+w*(S.x-v.x);R>=i.x&&R<l&&(l=R,c=y)}}if(c<0)return n;let u=n[c];s=n[(c+1)%r].x>u.x?(c+1)%r:c;let d=n[s],f={x:l,y:i.y},m=d.x-i.x,p=d.y-i.y,b=Math.hypot(m,p)||1,x=-1/0;for(let y=0;y<r;y++){if(y===s)continue;let v=n[y];if(!Ob(i,f,d,v))continue;let S=v.x-i.x,w=v.y-i.y,R=Math.hypot(S,w)||1,P=(S*m+w*p)/(R*b);(P>x+1e-12||Math.abs(P-x)<=1e-12&&R<a)&&(x=P,a=R,d=v,s=y)}let g=[];for(let y=s;y<r;y++)g.push(n[y]);for(let y=0;y<s;y++)g.push(n[y]);g.push(n[s]),g.push(i);for(let y=1;y<e.length;y++)g.push(e[(o+y)%e.length]);return g.push(i),Bu(t,n[s],i,e),g},Bu=(n,e,t,r)=>{n.addEdge(e,t);for(let o=0;o<r.length;o++)n.addEdge(r[o],r[(o+1)%r.length])},Yu=(n,e="evenodd")=>{let t=n.map(c=>Fb(c.points)).filter(c=>c.length>=3);if(t.length===0)return[];let r=t.map(c=>el(c)),o=new Array(t.length).fill(0),i=t.map(()=>new Array(t.length).fill(!1));for(let c=0;c<t.length;c++){let u=t[c][0];for(let h=0;h<t.length;h++)c!==h&&Ou(r[h],u,1e-6)&&(Bb(u,t[h],1e-6)||Fu(u,t[h])&&(o[c]++,i[h][c]=!0))}let s=new Array(t.length);if(e==="evenodd")for(let c=0;c<t.length;c++)s[c]=o[c]%2===0;else for(let c=0;c<t.length;c++){let u=mr(t[c])>0?1:-1;for(let h=0;h<t.length;h++)h!==c&&i[h][c]&&(u+=mr(t[h])>0?1:-1);s[c]=u!==0}let a=[],l=[];for(let c=0;c<t.length;c++)s[c]?a.push({ring:t[c],index:c,bbox:r[c]}):l.push({ring:t[c],depth:o[c]});if(a.length===0)return[];l.sort((c,u)=>Wu(u.ring)-Wu(c.ring));for(let c of l){let u=c.ring[0],h=a.find(f=>o[f.index]===c.depth-1&&Ou(f.bbox,u,0)&&Fu(u,f.ring));if(!h)continue;mr(h.ring)*mr(c.ring)>0&&(c.ring=c.ring.slice().reverse()),h.grid??=Wb(h.ring),h.ring=Hb(h.ring,c.ring,h.grid);let d=el(c.ring);h.bbox.minX=Math.min(h.bbox.minX,d.minX),h.bbox.minY=Math.min(h.bbox.minY,d.minY),h.bbox.maxX=Math.max(h.bbox.maxX,d.maxX),h.bbox.maxY=Math.max(h.bbox.maxY,d.maxY)}return a.map(c=>c.ring)},Wu=n=>{let e=-1/0;for(let t of n)t.x>e&&(e=t.x);return e};var Gb=new Set(["miter","round","bevel"]),Xb=new Set(["butt","round","square"]),Si=n=>{if(typeof n.stroke!="string"||!n.stroke)return null;let e=Number(n.strokeWidth)||0;if(e<=0)return null;let t=Array.isArray(n.strokeDashArray)?n.strokeDashArray.map(i=>Number(i)||0).filter(i=>i>=0):null,r=typeof n.strokeLineJoin=="string"&&Gb.has(n.strokeLineJoin)?n.strokeLineJoin:"miter",o=typeof n.strokeLineCap=="string"&&Xb.has(n.strokeLineCap)?n.strokeLineCap:"butt";return{color:n.stroke,rgba:oe(n.stroke),width:e,dashArray:t&&t.length>0?t:null,dashOffset:Number(n.strokeDashOffset)||0,lineJoin:r,lineCap:o,miterLimit:Number(n.strokeMiterLimit)||4,paintFirst:n.paintFirst==="stroke"?"stroke":"fill",alignment:n.strokeAlignment==="inside"||n.strokeAlignment==="outside"?n.strokeAlignment:"center",uniform:n.strokeUniform===!0||se(n)===L.PATH}},Uu=n=>{let e=r=>String(Math.round(r*1e4)/1e4),t=n.dashArray?n.dashArray.map(e).join(","):"-";return`s|${n.rgba.map(e).join(",")}|${e(n.width)}|${n.uniform?1:0}|${t}|${e(n.dashOffset)}|${n.lineJoin}|${n.lineCap}|${e(n.miterLimit)}|${n.paintFirst}|${n.alignment}`};var zb=(n,e)=>{let t=e.matrix,r=Math.max(Math.hypot(t[0],t[1]),Math.hypot(t[2],t[3]));return Math.ceil(n.width*Math.max(1,n.miterLimit)*(n.uniform?1:r)/2+4)},Yb=625e4,$u=(n,e,t)=>Math.min(n,8192/e,8192/t,Math.sqrt(Yb/(e*t))),vi=(n,e,t,r,o,i)=>{let s=e*t,a=r[4]*t,l=r[5]*t;return{lx:(Math.round((n[4]-o/2)*s+a)-a)/s,ly:(Math.round((n[5]-i/2)*s+l)-l)/s}},pr=(n,e)=>{let t=e.raw,r=se(t);if(n.beginPath(),r===L.PATH){let o=Ce(t.path);if(!o)return!1;let i=Fe(o);if(!i)return!1;let s=(i.left+i.right)/2,a=(i.top+i.bottom)/2;for(let l of o)switch(l[0]){case"M":n.moveTo(l[1]-s,l[2]-a);break;case"L":n.lineTo(l[1]-s,l[2]-a);break;case"C":n.bezierCurveTo(l[1]-s,l[2]-a,l[3]-s,l[4]-a,l[5]-s,l[6]-a);break;case"Q":n.quadraticCurveTo(l[1]-s,l[2]-a,l[3]-s,l[4]-a);break;case"Z":n.closePath();break}return!0}if(r===L.POLYGON||r===L.POLYLINE){let o=Array.isArray(t.points)?t.points:[];if(o.length<2)return!1;let i=1/0,s=1/0,a=-1/0,l=-1/0;for(let h of o)i>h.x&&(i=h.x),s>h.y&&(s=h.y),a<h.x&&(a=h.x),l<h.y&&(l=h.y);let c=(i+a)/2,u=(s+l)/2;n.moveTo(o[0].x-c,o[0].y-u);for(let h=0;h<o.length;h++)n.lineTo(o[h].x-c,o[h].y-u);return r===L.POLYGON&&n.closePath(),!0}if(r===L.TRIANGLE){let o=e.dims.x,i=e.dims.y;return!(o>0)||!(i>0)?!1:(n.moveTo(0,-i/2),n.lineTo(o/2,i/2),n.lineTo(-o/2,i/2),n.closePath(),!0)}if(r===L.ELLIPSE||r===L.CIRCLE){let o=(r===L.CIRCLE?Number(t.radius):Number(t.rx))||0,i=(r===L.CIRCLE?Number(t.radius):Number(t.ry))||0;return!(o>0)||!(i>0)?!1:(n.ellipse(0,0,o,i,0,0,Math.PI*2),!0)}if(r===L.LINE||r===L.REFERENCELINE){let o=Number(t.x1),i=Number(t.y1),s=Number(t.x2),a=Number(t.y2);return!Number.isFinite(o)||!Number.isFinite(i)||!Number.isFinite(s)||!Number.isFinite(a)?!1:(n.moveTo(o,i),n.lineTo(s,a),!0)}if(r===L.RECT||r===L.FABRICRECT){let o=e.dims.x,i=e.dims.y;if(!(o>0)||!(i>0))return!1;let s=it(t,o,i);return s?zn(n,o,i,s.rx,s.ry):n.rect(-o/2,-i/2,o,i),!0}return!1},ju=(n,e)=>{let t=Si(n.raw);if(!t)return null;let r=se(n.raw);if(r===L.ARROW||r===L.DIMENSION)return jb(n,t,e);let o=Math.abs(n.matrix[0])*n.dims.x+Math.abs(n.matrix[2])*n.dims.y,i=Math.abs(n.matrix[1])*n.dims.x+Math.abs(n.matrix[3])*n.dims.y,s=zb(t,n),a=o+s*2,l=i+s*2;if(!(a>0)||!(l>0)||a>8192||l>8192)return null;let c=e?e.zoom*e.dpr:1,u=$u(c,a,l),h=Math.ceil(a*u),d=Math.ceil(l*u);if(!(h>0)||!(d>0))return null;let f=document.createElement("canvas");f.width=h,f.height=d;let m=f.getContext("2d");if(!m)return null;let p=n.matrix,b=e&&u===c?vi(p,e.zoom,e.dpr,e.vpt,a,l):null,x=b?b.lx:p[4]-a/2,g=b?b.ly:p[5]-l/2,y=h/u,v=d/u,S=[p[0]*u,p[1]*u,p[2]*u,p[3]*u,(p[4]-x)*u,(p[5]-g)*u];if(m.setTransform(S[0],S[1],S[2],S[3],S[4],S[5]),!pr(m,n))return null;let w=S;if(t.uniform){let R=Math.hypot(p[0],p[1])||1,P=Math.hypot(p[2],p[3])||1;w=$(S,[1/R,0,0,1/P,0,0])}if(m.setTransform(w[0],w[1],w[2],w[3],w[4],w[5]),m.lineWidth=t.width,m.lineCap=t.lineCap,m.lineDashOffset=t.dashOffset,m.lineJoin=t.lineJoin,m.miterLimit=t.miterLimit,t.dashArray&&m.setLineDash(t.dashArray),m.strokeStyle=t.color,t.alignment==="outside"||t.alignment==="inside"){if(m.lineWidth=t.width*2,t.alignment==="inside")m.clip(),m.stroke();else{m.stroke(),m.globalCompositeOperation="destination-out";let R=Zr(n,m);typeof n.raw.fill=="string"&&n.raw.fill!==""&&n.raw.fill!=="transparent"||m.clip(),m.fillStyle=R,m.fill(),m.globalCompositeOperation="source-over"}return{canvas:f,w:y,h:v,lx:x,ly:g,sceneW:a,sceneH:l,snapped:!!b}}return m.stroke(),{canvas:f,w:y,h:v,lx:x,ly:g,sceneW:a,sceneH:l,snapped:!!b}},Zr=(n,e)=>{let t=n.raw.fill;if(typeof t=="string"&&t)return t;if(t&&typeof t=="object"&&t.type==="linear"){let r=t,o=r.coords??{},i=n.dims.x,s=n.dims.y,a=r.gradientUnits==="percentage"?i:1,l=r.gradientUnits==="percentage"?s:1,c=e.createLinearGradient((o.x1??0)*a+(r.offsetX??0),(o.y1??0)*l+(r.offsetY??0),(o.x2??0)*a+(r.offsetX??0),(o.y2??0)*l+(r.offsetY??0));for(let u of r.colorStops??[])typeof u?.offset=="number"&&typeof u?.color=="string"&&c.addColorStop(Math.min(1,Math.max(0,u.offset)),u.color);return c}return Ub(n)},Ub=n=>{let e=n.raw.stroke;return typeof e=="string"&&e?e:"#000"},$b=n=>{let e=Number(n.raw.x1),t=Number(n.raw.y1),r=Number(n.raw.x2),o=Number(n.raw.y2);return!Number.isFinite(e)||!Number.isFinite(t)||!Number.isFinite(r)||!Number.isFinite(o)?null:{x1:e,y1:t,x2:r,y2:o}},jb=(n,e,t)=>{let r=$b(n);if(!r)return null;let o=n.raw,s=se(o)===L.ARROW,a=Number(o.strokeWidth)||1,l=typeof o.stroke=="string"?o.stroke:"#000000",c=Array.isArray(o.strokeDashArray)?o.strokeDashArray:null,u=Math.ceil(a*2+8),h=null,d=Number(o.arrowWidth)||15,f=Number(o.arrowHeight)||22.5,m=o.arrowType==="start"||o.arrowType==="both"?o.arrowType:(o.arrowType==="end","end"),p=Math.sqrt(a),b=d*p,x=f*p;if(s)u=Math.ceil(u+x+b);else{let q=Number(o.textFontSize)||50,j=typeof o.text=="string"&&o.text.trim()?o.text:"50cm",Z=Number(o.textPadding)||4,W=`${q}px Arial, sans-serif`,V=Jr(W,j)+Z*2,Y=Math.atan2(r.y2-r.y1,r.x2-r.x1),re=-Math.sin(Y),te=Math.cos(Y),de=q+a/2+5;h={text:j,fontPx:q,w:V,h:q+Z*2,cx:(r.x1+r.x2)/2+re*de,cy:(r.y1+r.y2)/2+te*de,angle:o.textFollowLine===!1?0:Y,color:typeof o.textColor=="string"?o.textColor:"#333333",bg:typeof o.textBackgroundColor=="string"?o.textBackgroundColor:"#ffffff",pad:Z,follow:o.textFollowLine!==!1},u=Math.ceil(u+de+Math.max(V,q*2)*.75)}let g=Math.abs(n.matrix[0])*n.dims.x+Math.abs(n.matrix[2])*n.dims.y,y=Math.abs(n.matrix[1])*n.dims.x+Math.abs(n.matrix[3])*n.dims.y,v=g+u*2,S=y+u*2;if(!(v>0)||!(S>0)||v>8192||S>8192)return null;let w=t?t.zoom*t.dpr:1,R=$u(w,v,S),P=Math.ceil(v*R),E=Math.ceil(S*R);if(!(P>0)||!(E>0))return null;let C=document.createElement("canvas");C.width=P,C.height=E;let T=C.getContext("2d");if(!T)return null;let M=n.matrix,k=t&&R===w?vi(M,t.zoom,t.dpr,t.vpt,v,S):null,A=k?k.lx:M[4]-v/2,O=k?k.ly:M[5]-S/2,F=[M[0]*R,M[1]*R,M[2]*R,M[3]*R,(M[4]-A)*R,(M[5]-O)*R];T.setTransform(F[0],F[1],F[2],F[3],F[4],F[5]);let H=r.x2-r.x1,z=r.y2-r.y1,_=Math.atan2(z,H),D=Math.cos(_),I=Math.sin(_);if(s){let q=m==="start"||m==="both",j=m==="end"||m==="both",Z=r.x1+D*(q?x:0),W=r.y1+I*(q?x:0),V=r.x2-D*(j?x:0),Y=r.y2-I*(j?x:0);T.lineWidth=a,T.strokeStyle=l,c&&c.length>0?T.setLineDash(c):T.setLineDash([]),T.beginPath(),T.moveTo(Z,W),T.lineTo(V,Y),T.stroke(),T.setLineDash([]);let re=(te,de,Pe)=>{T.save(),T.translate(te,de),T.rotate(Pe),T.beginPath(),T.moveTo(0,0),T.lineTo(-x,-b/2),T.lineTo(-x,b/2),T.closePath(),T.fillStyle=l,T.fill(),T.restore()};return j&&re(r.x2,r.y2,_),q&&re(r.x1,r.y1,_+Math.PI),{canvas:C,w:P/R,h:E/R,lx:A,ly:O,sceneW:v,sceneH:S,snapped:!!k}}T.beginPath(),T.moveTo(r.x1,r.y1),T.lineTo(r.x2,r.y2);let B=F;if(e.uniform){let q=Math.hypot(M[0],M[1])||1,j=Math.hypot(M[2],M[3])||1;B=$(F,[1/q,0,0,1/j,0,0])}T.setTransform(B[0],B[1],B[2],B[3],B[4],B[5]),T.lineWidth=e.width,T.lineCap=e.lineCap,T.lineDashOffset=e.dashOffset,T.lineJoin=e.lineJoin,T.miterLimit=e.miterLimit,e.dashArray&&T.setLineDash(e.dashArray),T.strokeStyle=l,T.stroke(),T.setTransform(F[0],F[1],F[2],F[3],F[4],F[5]);let G=-I,X=D,U=(Number(o.textFontSize)||50)/2;T.lineWidth=a,T.lineCap="round",e.dashArray&&T.setLineDash([]),T.strokeStyle=l;for(let[q,j]of[[r.x1,r.y1],[r.x2,r.y2]])T.beginPath(),T.moveTo(q-G*U,j-X*U),T.lineTo(q+G*U,j+X*U),T.stroke();return h&&(T.save(),T.translate(h.cx,h.cy),h.follow&&T.rotate(h.angle),T.font=`${h.fontPx}px Arial, sans-serif`,T.textAlign="center",T.textBaseline="middle",h.bg&&(T.fillStyle=h.bg,T.fillRect(-h.w/2,-h.h/2,h.w,h.h)),T.fillStyle=h.color,T.fillText(h.text,0,0),T.restore()),{canvas:C,w:P/R,h:E/R,lx:A,ly:O,sceneW:v,sceneH:S,snapped:!!k}},Jr=(n,e)=>{let t=document.createElement("canvas").getContext("2d");return t?(t.font=n,t.measureText(e).width):e.length*50};var fe={LEFT:"left",CENTER:"center",RIGHT:"right",JUSTIFY:"justify",JUSTIFY_LEFT:"justify-left",JUSTIFY_CENTER:"justify-center",JUSTIFY_RIGHT:"justify-right",DISPERSE:"disperse"},Vb=Object.values(fe),zt=n=>n===fe.JUSTIFY||n===fe.JUSTIFY_LEFT||n===fe.JUSTIFY_CENTER||n===fe.JUSTIFY_RIGHT,tl=n=>n===fe.JUSTIFY_LEFT||n===fe.JUSTIFY_CENTER||n===fe.JUSTIFY_RIGHT,eo=n=>n===fe.JUSTIFY||n===fe.DISPERSE;var Vu=400,wi=1.13,Ti=.222,qb=2,Kb={underline:.1,linethrough:-.28167,overline:-.81333},Qb=66.667,Zb=/[a-zA-Z.\s]+/,Jb=/[0-9]/,ex=/[()[\]{}></:;:,.?!]/,ro=n=>Zb.test(n)||Jb.test(n)||ex.test(n),tx=new Set(["ー","「","」","『","』","(",")","〔","〕","[","]","{","}","⦅","⦆","〈","〉","《","》","【","】","〖","〗","〘","〙","〚","〛","゛","゜","。","、","・","゠","=","〜","…","•","‥","◦","﹅","﹆"]),nx=new Set(["「","」","『","』","〔","〕","[","]","{","}","⦅","⦆","〈","〉","《","》","【","】","〖","〗","〘","〙","〚","〛","(",")"]),Un=n=>ro(n)?"latin":nx.has(n)?"bracket":tx.has(n)?"symbol":"cjk",$n=(n,e,t)=>ro(n)?e.width:e.height+t,an=n=>n/1.1,br=(n,e,t)=>n==="symbol"?-t/3.14:e.height/2-t/3.14,wt=(n,e,t)=>n===0||t%2===0?0:n/300*e*.5,Ju=(n,e,t)=>{if(n===0)return 0;let r=e.fontSize;for(let o of t)for(let i of o.charStyles){let s=i?.fontSize;typeof s=="number"&&s>r&&(r=s)}return Math.abs(n)/300*r*.5},to=null,eh=(n,e,t)=>{let r={left:0,right:0,ascent:t*.88,descent:t*.24};if(typeof document>"u")return r;if(!to){let i=document.createElement("canvas");i.width=8,i.height=8,to=i.getContext("2d")}if(!to)return r;to.font=n;let o=to.measureText(e);return o.actualBoundingBoxAscent===void 0||o.actualBoundingBoxDescent===void 0?r:{left:-(o.actualBoundingBoxLeft??0),right:o.actualBoundingBoxRight??0,ascent:o.actualBoundingBoxAscent,descent:o.actualBoundingBoxDescent}},qu=new WeakMap,ol=new Set,Ku=(n,e,t)=>{let r=qu.get(n);r||(r=new Map,qu.set(n,r),ol.add(r));let o=`${Me(e,e.fontSize)}|${t}`,i=r.get(o);return i||(i=n(Me(e,e.fontSize),t,e.fontSize),r.set(o,i)),i},th=(n,e,t=eh)=>{let r=e.charSpacing?e.fontSize*e.charSpacing/1e3:0,o=0,i=0,s=0;for(let a=0;a<n.graphemes.length;a++){let l=n.graphemes[a],c=n.boxes[a],u=rh(e,n.charStyles[a]),h=Un(l),d,f;if(h==="latin"||h==="bracket"){let m=h==="latin"?c.kernedWidth-c.width:0,p=Ku(t,u,l);d=p.left+m,f=p.right+m}else{let m=Ku(t,u,l);d=an(u.fontSize)-m.ascent,f=an(u.fontSize)+m.descent}a===0&&(i=d),s=o+f,o+=$n(l,c,r)}return{start:i,end:s}},il=new Set(["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","math","emoji","fangsong","inherit","initial","unset"]),Ei=(n,e,t={})=>{let r=1/0,o=-1/0,i=1/0;for(let a of n.lines){if(a.width<=0||a.graphemes.length===0)continue;let l,c;if(t.vertical){let u=th(a,e,t.inkMeasure);l=a.leftOffset+u.start,c=a.leftOffset+u.end}else{let u=a.boxes[a.boxes.length-1];l=a.leftOffset,c=a.leftOffset+Math.max(a.width,u.left+u.width)}c>l&&(r=Math.min(r,l),o=Math.max(o,c),i=Math.min(i,a.top))}if(!(o>r)||!Number.isFinite(i))return null;let s=t.align===void 0?{lo:r,hi:o}:rx(r,o,n.width,t.align);return{lo:s.lo,hi:s.hi,firstTop:i}},rx=(n,e,t,r)=>!(t>0)||!Number.isFinite(t)?{lo:n,hi:e}:r===fe.CENTER||r===fe.JUSTIFY_CENTER?{lo:Math.min(0,n),hi:Math.max(t,e)}:r===fe.RIGHT||r===fe.JUSTIFY_RIGHT?{lo:n,hi:Math.max(t,e)}:{lo:Math.min(0,n),hi:e},Me=(n,e)=>{let t=n.fontFamily,r=t.includes("'")||t.includes('"')||t.includes(",")||il.has(t.toLowerCase())?t:`"${t}"`;return`${n.fontStyle??"normal"} ${n.fontWeight??"normal"} ${e}px ${r}`},ox=(n,e)=>{if(n)return n.id===0?`${e+1}`:n.content||void 0},Oe=(n,e)=>{let t=e?.stroke??n?.color,r=e?.strokeWidth??n?.width;return!t||!r?null:{color:t,width:r,lineJoin:n?.lineJoin,miterLimit:n?.miterLimit,lineCap:n?.lineCap}},oo=/[\u4e00-\u9fa5\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af]/,ln=n=>{let e=n.boxes[n.boxes.length-1];return e?e.left+e.width:0},Tt=(n,e,t,r,o={})=>{let i=e.prefix;if(!i)return 0;let s=n.font;return n.font=Me(i.style,i.style.fontSize),o.fill&&(o.fill!=="keep"&&(n.fillStyle=o.fill),n.fillText(i.text,t,r)),o.stroke&&o.stroke.width>0&&(n.lineWidth=o.stroke.width,n.strokeStyle=o.stroke.color,n.strokeText(i.text,t,r)),n.font=s,i.width},sl=(n,e,t)=>{let r=[],o=!!t[e],i=y=>!!(n.charStyles[y]?.[e]??o);if(!n.graphemes.some((y,v)=>i(v)))return r;let s=y=>n.charStyles[y]?.fill??t.fill??"",a=y=>n.charStyles[y]?.textDecorationThickness??t.textDecorationThickness??Qb,l=y=>n.charStyles[y]?.fontSize??t.fontSize,c=Kb[e],u=e==="linethrough"?.5:e==="overline"?1:0,h=t.charSpacing?t.fontSize*t.charSpacing/1e3:0,d=(y,v,S,w,R,P)=>{if(!y||!v||!S||P<=0)return;let E=t.fontSize*S/1e3;r.push({x:R,width:P,y:c*w-u*E,thickness:E,color:v})},f=0,m=0,p=i(0),b=s(0),x=a(0),g=l(0);for(let y=0;y<n.graphemes.length;y++){let v=i(y),S=s(y),w=a(y),R=l(y),P=n.boxes[y],E=t.vertical?ro(n.graphemes[y])?P.kernedWidth:P.height:P.kernedWidth;(v!==p||S!==b||w!==x||R!==g)&&m>0?(d(p,b,x,g,f,m),f=P.left,m=t.vertical?E:P.width,p=v,b=S,x=w,g=R):m+=t.vertical?E:P.kernedWidth}return d(p,b,x,g,f,m-h),r},no=null,ix=(n,e)=>{if(typeof document>"u")return 0;if(!no){let t=document.createElement("canvas");if(t.width=8,t.height=8,no=t.getContext("2d"),!no)return 0}return no.font=n,no.measureText(e).width},At=n=>Array.from(n),sx=n=>n.split(/[ \t\r]/),nl=class{constructor(e,t){this.decl=e;this.measure=t}decl;measure;charWidths=new Map;coupleWidths=new Map;charWidth(e){let t=this.charWidths.get(e);return t===void 0&&(t=this.measure(this.decl,e),this.charWidths.set(e,t)),t}coupleWidth(e,t){let r=e+"\0"+t,o=this.coupleWidths.get(r);return o===void 0&&(o=this.measure(this.decl,e+t),this.coupleWidths.set(r,o)),o}},Qu=new WeakMap,ax=(n,e)=>{let t=Qu.get(e);t||(t=new Map,Qu.set(e,t),ol.add(t));let r=t.get(n);return r||(r=new nl(n,e),t.set(n,r)),r},nh=()=>{for(let n of ol)n.clear()},rh=(n,e)=>!e||e.fontSize===void 0&&e.fontFamily===void 0&&e.fontWeight===void 0&&e.fontStyle===void 0?n:{...n,fontSize:e.fontSize??n.fontSize,fontFamily:e.fontFamily??n.fontFamily,fontWeight:e.fontWeight??n.fontWeight,fontStyle:e.fontStyle??n.fontStyle},rl=(n,e,t,r,o)=>{let i=ax(Me(e,Vu),n),s=e.fontSize/Vu,a=i.charWidth(t),l=a;return r&&o&&Me(o,o.fontSize)===Me(e,e.fontSize)&&(l=i.coupleWidth(r,t)-i.charWidth(r)),{width:a*s,kernedWidth:l*s}},oh=n=>n.charSpacing?n.fontSize*n.charSpacing/1e3:0,Zu=(n,e,t,r,o,i,s,a=!1)=>{let l=oh(o),c=[],u=" ",h=0,d=[],f=0,m=!0,p=0,b=Math.max(e,r,qb),x=t[n];for(let g=0;g<x.length;g++){let y=x[g].graphemes,v=x[g].width;p+=y.length,h+=(a?0:f)+v-l,h>b&&!m?(c.push(d),d=[],h=v,m=!0):h+=l,!m&&!a&&d.push(u),d=d.concat(y),f=a?0:rl(s,i(n,p),u).kernedWidth+l,p++,m=!1}return x.length&&c.push(d),c},jn=(n,e,t={})=>{let r=t.measure??ix,o=t.inkMeasure??eh,i=t.styles,s=(T,M)=>rh(e,i?.[T]?.[M]),a=oh(e),l=e.lineHeight??1.16,c=(T,M,k)=>{let A=0,O;for(let F=0;F<T.length;F++){let H=rl(r,s(M,k+F),T[F],O,F>0?s(M,k+F-1):void 0);A+=H.kernedWidth+a,O=T[F]}return A},u=(n??"").split(`
|
|
3
|
-
`),h,d=0;if(t.boxWidth==null)h=
|
|
4
|
-
`&&A>0?(M=0,k++,T++):A>0&&!t.splitByGrapheme&&/[ \t\r]/.test(O??"")&&(M++,k++),m[A]={line:T,offset:M,flatStart:k},k+=h[A].length,M+=h[A].length}}let p=h.map((T,M)=>{let k=m[M],A=[],O=0;for(let _=0;_<T.length;_++){let D=rl(r,s(k.line,k.offset+_),T[_],_>0?T[_-1]:void 0,_>0?s(k.line,k.offset+_-1):void 0),I={left:0,width:D.width+a,kernedWidth:D.kernedWidth+a,height:s(k.line,k.offset+_).fontSize};_>0&&(I.left=A[_-1].left+A[_-1].width+D.kernedWidth-D.width),A.push(I),t.vertical&&!ro(T[_])?O+=I.height:O+=I.kernedWidth}a!==0&&(O-=a),O<0&&(O=0);let F=T.map((_,D)=>i?.[k.line]?.[k.offset+D]),H=0;if(T.length>0)for(let _=0;_<T.length;_++)H=Math.max(H,i?.[k.line]?.[k.offset+_]?.fontSize??e.fontSize);else H=i?.[k.line]?.[k.offset]?.fontSize??e.fontSize;let z;if(t.paragraph){let _=ox(t.paragraph,M);if(_){let D=s(k.line,k.offset),I=Me(D,D.fontSize),B=r(I,_);if(B>0){z={text:_,width:B,advances:At(_).map(G=>r(I,G)),style:D};for(let G of A)G.left+=z.width;O+=z.width}}}return{graphemes:T,boxes:A,width:O,leftOffset:0,baseline:0,top:0,implHeight:H*wi,styleMap:k,charStyles:F,prefix:z}}),b=0,x=0;for(let T=0;T<p.length;T++){let M=p[T].implHeight,k=T===p.length-1;p[T].top=x,p[T].baseline=x+M*(1-Ti),x+=M*l,b+=k?M:M*l}let g=t.boxWidth!=null?Math.max(t.boxWidth,d-a):0,y=()=>{let T=0;for(let M of p){let k=0;for(let A=0;A<M.graphemes.length;A++)k+=ro(M.graphemes[A])?M.boxes[A].width+a:M.boxes[A].height+a;T=Math.max(T,k)}return T+2},v=t.vertical?y():void 0,S=t.boxWidth!=null?g:t.vertical?v:Math.max(0,...p.map(T=>T.width)),w=e.textAlign??fe.LEFT,R=T=>{if(t.boxWidth==null)return T===p.length-1;let M=p[T+1]?.styleMap;return!M||M.line!==p[T].styleMap.line};for(let T=0;T<p.length;T++){let M=w===fe.CENTER||w===fe.JUSTIFY_CENTER&&R(T),k=w===fe.RIGHT||w===fe.JUSTIFY_RIGHT&&R(T);if(t.vertical&&(M||k)&&p[T].graphemes.length>0){let O=th(p[T],e,o);p[T].leftOffset=M?(S-O.start-O.end)/2:S-O.end;continue}let A=S-p[T].width;M?p[T].leftOffset=A/2:k&&(p[T].leftOffset=A)}let P=w===fe.DISPERSE;if((zt(w)||P)&&!t.vertical)for(let T=0;T<p.length;T++){let M=p[T],k=tl(w);if(k&&(T===p.length-1||R(T))||!k&&!P&&T===p.length-1||M.width>=S)continue;let A=!k&&M.graphemes.some(z=>oo.test(z)),O=A?M.graphemes.length-1:M.graphemes.reduce((z,_)=>/[ \t\r]/.test(_)?z+1:z,0);if(O<=0)continue;let F=(S-M.width)/O,H=0;for(let z=0;z<M.graphemes.length;z++){let _=M.boxes[z],D=A?z<M.graphemes.length-1:/[ \t\r]/.test(M.graphemes[z]);_.left+=H,D&&(_.width+=F,_.kernedWidth+=F,H+=F)}}let E=[],C=0;for(let T of f)E.push(C),C+=T.length;return E.push(C),{lines:p,width:S,height:b,graphemeCodeUnitOffsets:E,verticalWidth:v}};var lx={arc:"arc",circle:"circle",waist:"waist",flag:"flag",arch:"arch",scroll:"scroll"},cx={[L.ARCTEXT]:"arc",[L.CIRCLETEXT]:"circle",[L.WAISTTEXT]:"waist",[L.FLAGTEXT]:"flag",[L.ARCHTEXT]:"arch",[L.SCROLLTEXT]:"scroll"},Ke=n=>{let e=n.textTransform;if(typeof e=="string"){let t=lx[e];if(t)return t}return cx[se(n)]??null},xr=n=>{if(!(Number(n.warpStrength)||0))return null;let t=Ke(n);return t==="arch"||t==="waist"||t==="flag"?t:null},ih=(n,e,t,r,o)=>{if(!(r.hi>r.lo))return null;let i=Math.max(-1,Math.min(1,Number(t.warpStrength)||0)),s=Number(t.fontSize)||40,a=typeof t.height=="number"?t.height:0,l=Math.max(a,s),c=-e.width/2+r.lo,u=-e.width/2+r.hi,h=o+r.firstTop,d=o+e.height,f=d-h;if(n==="arch"){if(i<=0)return{left:c,right:u,top:h,bottom:d};let b=l*i/2;return{left:c,right:u,top:d+b-f*(1+i),bottom:d+b}}if(n==="flag"){let b=Math.abs(i)*(a||s)*.3,x=Math.abs(i)*b;return{left:c,right:u,top:h-x,bottom:d+x}}let m=(h+d)/2,p=f/2*(1+.5*Math.abs(i));return{left:c,right:u,top:m-p,bottom:m+p}};var ux=1e4,io=2,sh=(n,e)=>{let t=e-n;for(;t>=2*Math.PI;)t-=2*Math.PI;for(;t<=0;)t+=2*Math.PI;return t},Ci=(n,e,t)=>sh(n,e)+sh(e,t)<2*Math.PI,Mi=(n,e,t,r)=>{let o=n.x,i=n.y,s=o,a=i;e.x<o&&(o=e.x),e.x>s&&(s=e.x),e.y<i&&(i=e.y),e.y>a&&(a=e.y);let l=Math.atan2(n.y-t.y,n.x-t.x),c=Math.atan2(e.y-t.y,e.x-t.x);if(Ci(l,0,c)){let u=t.x+r;u>s&&(s=u)}if(Ci(l,Math.PI/2,c)){let u=t.y+r;u>a&&(a=u)}if(Ci(l,Math.PI,c)){let u=t.x-r;u<o&&(o=u)}if(Ci(l,Math.PI*3/2,c)){let u=t.y-r;u<i&&(i=u)}return{x:o,y:i,width:s-o,height:a-i}},Ge=n=>{let e=Ke(n);return e==="arc"||e==="circle"?e:null},ah=n=>n.lines.map(e=>{let t=e.boxes.map(o=>({left:o.left,width:o.width})),r=t[t.length-1];return t.push(r?{left:r.left+r.width,width:0}:{left:0,width:0}),t}),hx=(n,e,t)=>{let r=ah(n),o=n.width,i=P=>n.lines[P].implHeight*e,s=0;for(let P=0;P<n.lines.length;P++)s+=i(P);let a=Math.abs(t),l=a*Math.PI/180,c=0;for(let P=0;P<n.lines.length;P++)c+=n.lines[P].width;let u=l>0?c/l:0,h=Math.max(ux/Math.max(a,.1),u),d=0,f=t>0?s/2+h:-s/2+h,m=t>0?s:0,p=1/0,b=-1/0,x=1/0,g=-1/0,y=[];for(let P=0;P<r.length;P++){let E=-o/2+n.lines[P].leftOffset,C=i(P),T=C-C/e+C*Ti/e;m+=t>0?-C:C;let M=Math.abs(h)+m,k=t>0?M+C-C/e:M-C+C/e,A=[];for(let D=0;D<r[P].length;D++){let I=r[P][D],B,G,X,U,q,j,Z;t>0?(B=M,G=M+C,X=M+T,U=(B*3+G*2)/5,q=-(E+I.left)/U,j=-(E+I.left+I.width)/U,Z=-(E+I.left+I.width/2)/U):(B=M,G=M-C,X=M-T,U=(B*2+G*3)/5,q=Math.PI+(E+I.left)/U,j=Math.PI+(E+I.left+I.width)/U,Z=Math.PI+(E+I.left+I.width/2)/U);let W=Math.sin(j),V=Math.cos(j),Y=Math.sin(q),re=Math.cos(q),te=Math.sin(Z),de=Math.cos(Z);A.push({tl:{x:d-G*Y,y:f-G*re},tr:{x:d-G*W,y:f-G*V},nl:{x:d-k*Y,y:f-k*re},nr:{x:d-k*W,y:f-k*V}});let Pe=n.lines[P].graphemes[D];Pe!==void 0&&y.push({char:Pe,line:P,index:D,x:d-X*te,y:f-X*de,rotation:t>0?-Z:-Z-Math.PI})}let O=A[0],F=A[A.length-1];if(!O||!F)continue;let H={x:d,y:f},z=t>0?Mi(O.tl,F.tr,H,M+C):Mi(F.tr,O.tl,H,M-C),_=t>0?Mi(O.nl,F.nr,H,M):Mi(F.nr,O.nl,H,M);p=Math.min(p,z.x,_.x),b=Math.max(b,z.x+z.width,_.x+_.width),x=Math.min(x,z.y,_.y),g=Math.max(g,z.y+z.height,_.y+_.height)}Number.isFinite(p)||(p=b=x=g=0);let v=-p-o/2,S=b-o/2,w=-x-s/2,R=g-s/2;return{width:Math.max(o+v+S,io),height:s+w+R,contentOffsetX:S/2-v/2,contentOffsetY:R/2-w/2,chars:y}},dx=(n,e,t)=>{let r=ah(n),o=C=>n.lines[C].implHeight*e,i=0;for(let C=0;C<n.lines.length;C++)i+=o(C);let s=n.width,a=Math.max(t.size,1),l=Math.min(Math.max(t.eccentricity,0),.95),c=a*(1-l),u=Math.max(t.sweep,1)*(Math.PI/180),h=t.startAngle*(Math.PI/180),d=t.horizontal,f=0;for(let C=0;C<n.lines.length;C++)f+=n.lines[C].width;let m=0,p=0;if(f<=0||r.length===0)return{width:io,height:Math.max(i,io),contentOffsetX:0,contentOffsetY:0,chars:[]};let b=1/0,x=-1/0,g=1/0,y=-1/0,v=[],S=0;for(let C=0;C<r.length;C++){let T=o(C),M=T-T/e+T*Ti/e,k=T-M;for(let A=0;A<r[C].length;A++){let O=r[C][A],H=(S+O.left+O.width/2)/f,z=h-H*u,_=Math.sin(z),D=Math.cos(z),I=m-a*_,B=p-c*D,G,X,U,q,j;if(d)G=0,X=1,U=0,q=0,j=-1;else{let Y=a*D,re=-c*_,te=Math.hypot(Y,re)||1;X=Y/te,U=re/te;let de=-c*_,Pe=-a*D,De=Math.hypot(de,Pe)||1;q=de/De,j=Pe/De,G=Math.atan2(re,Y)}let Z=-G,W=O.width/2;b=Math.min(b,I-q*M-X*W,I-q*M+X*W,I+q*k-X*W,I+q*k+X*W),x=Math.max(x,I-q*M-X*W,I-q*M+X*W,I+q*k-X*W,I+q*k+X*W),g=Math.min(g,B-j*M-U*W,B-j*M+U*W,B+j*k-U*W,B+j*k+U*W),y=Math.max(y,B-j*M-U*W,B-j*M+U*W,B+j*k-U*W,B+j*k+U*W);let V=n.lines[C].graphemes[A];V!==void 0&&v.push({char:V,line:C,index:A,x:I,y:B,rotation:-Z})}S+=n.lines[C].width}Number.isFinite(b)||(b=x=g=y=0);let w=-b-s/2,R=x-s/2,P=-g-i/2,E=y-i/2;return{width:Math.max(x-b,io),height:Math.max(y-g,io),contentOffsetX:R/2-w/2,contentOffsetY:E/2-P/2,chars:v}},Et=(n,e,t)=>Ke(e)==="circle"?dx(n,t,{size:typeof e.circleSize=="number"?e.circleSize:40,startAngle:typeof e.circleStartAngle=="number"?e.circleStartAngle:0,sweep:typeof e.circleSweep=="number"?e.circleSweep:360,eccentricity:typeof e.circleEccentricity=="number"?e.circleEccentricity:0,horizontal:e.circleDirection==="horizontal"}):hx(n,t,typeof e.curvature=="number"?e.curvature:300);var lh=(n,e)=>{let t=1-e;return n===2?[t,e,0,0]:n===3?[t*t,2*t*e,e*e,0]:[t*t*t,3*t*t*e,3*t*e*e,e*e*e]},cn=(n,e,t,r,o,i)=>{let s={uOrder:Math.min(4,Math.max(2,o)),vOrder:Math.min(4,Math.max(2,i)),xs:[],ys:[]};for(let a=0;a<s.vOrder;a++){let l=s.vOrder===1?0:a/(s.vOrder-1);for(let c=0;c<s.uOrder;c++){let u=s.uOrder===1?0:c/(s.uOrder-1);s.xs.push(n+(t-n)*u),s.ys.push(e+(r-e)*l)}}return s},Ri=(n,e,t)=>{let r=lh(n.uOrder,e),o=lh(n.vOrder,t),i=0,s=0;for(let a=0;a<n.vOrder;a++)for(let l=0;l<n.uOrder;l++){let c=r[l]*o[a];i+=c*n.xs[a*n.uOrder+l],s+=c*n.ys[a*n.uOrder+l]}return{x:i,y:s}},Vn=(n,e,t,r,o,i)=>{let s=Math.sin(o),a=Math.cos(o),l=(t-e)/(2*s),c=4/3*Math.tan(o/2)*l,u=i?-c*s:c*s;n.xs.push(e,e+c*a,t-c*a,t),n.ys.push(r,r+u,r+u,r)},mt=(n,e,t)=>{n.xs.push(0,e/3,2*e/3,e),n.ys.push(t,t,t,t)},al=(n,e)=>{let t={uOrder:n.uOrder,vOrder:n.vOrder,xs:[],ys:[]};for(let r=0;r<n.vOrder;r++){let o=n.vOrder-1-r;for(let i=0;i<n.uOrder;i++){let s=r*n.uOrder+i,a=o*n.uOrder+i;t.xs[s]=n.xs[a],t.ys[s]=e-n.ys[a]}}return t},fx=n=>{let e={uOrder:n.vOrder,vOrder:n.uOrder,xs:[],ys:[]};for(let t=0;t<n.vOrder;t++)for(let r=0;r<n.uOrder;r++){let o=t*n.uOrder+r,i=r*n.vOrder+t;e.xs[i]=n.ys[o],e.ys[i]=n.xs[o]}return e},ch=(n,e,t,r)=>{let o=Math.min(100,Math.max(-100,e)),i=Math.abs(o)*Math.PI/200,s=2*r*o/100,a={uOrder:4,vOrder:n==="wave"?3:2,xs:[],ys:[]};if(n==="arcLower"||n==="arcUpper")return Math.abs(o)<1e-9?cn(0,0,t,r,4,2):(mt(a,t,0),Vn(a,0,t,r,i,o<0),n==="arcUpper"?al(a,r):a);if(n==="fish")return mt(a,t,0),mt(a,t,r),a.ys[1]-=s,a.ys[2]+=s,a.ys[5]+=s,a.ys[6]-=s,a;if(n==="fisheye"){a=cn(0,0,t,r,4,4);let l=o/50;for(let c=1;c<=2;c++)for(let u=1;u<=2;u++){let h=c*4+u,d=u===1?0:t,f=c===1?0:r;a.xs[h]+=l*(d-a.xs[h]),a.ys[h]+=l*(f-a.ys[h])}return a}if(n==="inflate"||n==="squeeze"){a=cn(0,0,t,r,3,3);let l=t*o/200,c=r*o/200;return a.ys[1]-=c,a.ys[7]+=c,n==="inflate"?(a.xs[3]-=l,a.xs[5]+=l):(a.xs[3]+=l,a.xs[5]-=l),a}if(n==="twist"){a=cn(0,0,t,r,4,4);let l=t*Math.abs(o)/100,c=r*Math.abs(o)/100;return o>0?(a.xs[5]+=l,a.ys[6]+=c,a.xs[10]-=l,a.ys[9]-=c):o<0&&(a.ys[5]+=c,a.xs[6]-=l,a.ys[10]-=c,a.xs[9]+=l),a}if(n==="shellLower"||n==="shellUpper"){if(Math.abs(o)<1e-9)return cn(0,0,t,r,4,4);let l=Math.sin(i),c=Math.cos(i);if(a={uOrder:4,vOrder:4,xs:[],ys:[]},mt(a,t,0),mt(a,t,r/3),o>0){let u=2*r/3;a.xs.push(-u*l,t/3,2*t/3,t+u*l),a.ys.push(u*c,2*r/3,2*r/3,u*c),Vn(a,-r*l,t+r*l,r*c,i,!1)}else{let u=r/3;a.xs.push(-u*l,t/3,2*t/3,t+u*l),a.ys.push(r-u*c,2*r/3,2*r/3,r-u*c),Vn(a,0,t,r,i,!0)}return n==="shellUpper"?al(a,r):a}if(n==="arc"){if(Math.abs(o)<1e-9)return cn(0,0,t,r,4,2);let l=Math.sin(i);return Vn(a,-r*l,t+r*l,r*(1-Math.cos(i)),i,!0),Vn(a,0,t,r,i,!0),o<0?al(a,r):a}if(n==="arch"||n==="bulge"){if(Math.abs(o)<1e-9)return cn(0,0,t,r,4,2);let l=o>0;return Vn(a,0,t,0,i,l),Vn(a,0,t,r,i,n==="bulge"?!l:l),a}if(n==="flag")return mt(a,t,0),mt(a,t,r),a.ys[1]-=s,a.ys[2]+=s,a.ys[5]-=s,a.ys[6]+=s,a;if(n==="wave")return mt(a,t,0),mt(a,t,r/2),mt(a,t,r),a.ys[5]+=s,a.ys[6]-=s,a;if(n==="rise")return mt(a,t,0),mt(a,t,r),a.ys[0]+=s,a.ys[1]+=s,a.ys[4]+=s,a.ys[5]+=s,a},ll=n=>n==="arc"||n==="arch"||n==="bulge"||n==="flag"||n==="wave"||n==="rise"||n==="arcLower"||n==="arcUpper"||n==="shellLower"||n==="shellUpper"||n==="fish"||n==="fisheye"||n==="inflate"||n==="squeeze"||n==="twist",uh=(n,e,t,r,o)=>{if(!ll(n)||r<=0||o<=0)return;if(!t||n==="twist")return ch(n,e,r,o);let i=ch(n,e,o,r);return i?fx(i):void 0},hh=(n,e,t)=>{let r=Math.min(100,Math.max(-100,t)),o=Math.min(100,Math.max(-100,e));if(r!==0&&n.vOrder>1)for(let i=0;i<n.vOrder;i++){let s=i*n.uOrder,a=s+n.uOrder-1,l=(n.xs[s]+n.xs[a])/2,c=(n.ys[s]+n.ys[a])/2,h=1+(2*(i/(n.vOrder-1))-1)*r/100;for(let d=0;d<n.uOrder;d++){let f=s+d;n.xs[f]=l+(n.xs[f]-l)*h,n.ys[f]=c+(n.ys[f]-c)*h}}if(o!==0&&n.uOrder>1)for(let i=0;i<n.uOrder;i++){let s=i,a=(n.vOrder-1)*n.uOrder+i,l=(n.xs[s]+n.xs[a])/2,c=(n.ys[s]+n.ys[a])/2,h=1+(2*(i/(n.uOrder-1))-1)*o/100;for(let d=0;d<n.vOrder;d++){let f=d*n.uOrder+i;n.xs[f]=l+(n.xs[f]-l)*h,n.ys[f]=c+(n.ys[f]-c)*h}}},cl=(n,e,t)=>{let r=uh(n.style,n.bend,n.rotate==="vertical",e,t);if(r)return hh(r,n.horizontal,n.vertical),r},qn=n=>{if(n===null||typeof n!="object")return null;let t=n.psdWarp;if(t===null||typeof t!="object")return null;let r=t,o=typeof r.style=="string"?r.style:"";if(!ll(o))return null;let i=Number(r.bend)||0,s=Number(r.horizontal)||0,a=Number(r.vertical)||0;return i===0&&s===0&&a===0?null:{style:o,bend:i,horizontal:s,vertical:a,rotate:r.rotate==="vertical"?"vertical":"horizontal"}},ul=(n,e,t,r,o,i,s,a,l,c,u,h,d,f)=>{let m=r-e,p=o-t,b=a-i,x=l-s;if(m<=0||p<=0||b<=0||x<=0||c<=0||u<=0||d<=0||n.xs.length===0)return;let g=(i-e)/m,y=(a-e)/m,v=(s-t)/p,S=(l-t)/p,w=(H,z)=>{let _=Ri(n,H,z);return{x:h[0]*_.x+h[2]*_.y+h[4],y:h[1]*_.x+h[3]*_.y+h[5]}},R=0,P=0,E=0,C=0,T=!0,M=8;for(let H=0;H<=M;H++){let z=v+(S-v)*H/M;for(let _=0;_<=M;_++){let D=g+(y-g)*_/M,I=w(D,z);T?(R=P=I.x,E=C=I.y,T=!1):(R=Math.min(R,I.x),P=Math.max(P,I.x),E=Math.min(E,I.y),C=Math.max(C,I.y))}}let k=Math.max(8,f),A=Math.min(k,Math.max(8,Math.ceil((P-R)/d))),O=Math.min(k,Math.max(8,Math.ceil((C-E)/d))),F={columns:A+1,rows:O+1,docXs:[],docYs:[],sourceXs:[],sourceYs:[]};for(let H=0;H<F.rows;H++){let z=H/O;for(let _=0;_<F.columns;_++){let D=_/A,I=w(g+(y-g)*D,v+(S-v)*z);F.docXs.push(I.x),F.docYs.push(I.y),F.sourceXs.push(D*c),F.sourceYs.push(z*u)}}return F},hl=(n,e,t,r,o,i,s,a,l,c)=>{let u=o-t,h=i-r,d=l-t,f=c-r,m=t-o-l+s,p=r-i-c+a,b=n-t,x=e-r,g=u*p-h*m,y=u*f-h*d-(b*p-x*m),v=-(b*f-x*d),S;if(Math.abs(g)<1e-9){if(Math.abs(y)<1e-9)return;S=-v/y}else{let E=y*y-4*g*v;if(E<0)return;let C=Math.sqrt(E),T=(-y+C)/(2*g),M=(-y-C)/(2*g),k=T>=-1e-9&&T<=1+1e-9,A=M>=-1e-9&&M<=1+1e-9;if(k&&A)S=Math.min(Math.max(T,0),1);else if(k)S=T;else if(A)S=M;else return}let w=d+m*S,R=f+p*S,P;if(Math.abs(w)>=Math.abs(R)){if(Math.abs(w)<1e-9)return;P=(b-u*S)/w}else{if(Math.abs(R)<1e-9)return;P=(x-h*S)/R}if(!(S<-1e-9||S>1.000000001||P<-1e-9||P>1.000000001))return{s:Math.min(Math.max(S,0),1),t:Math.min(Math.max(P,0),1)}};var mx=(n,e)=>{let t=n.boxes;if(t.length===0)return{left:0,width:0,kernedWidth:0,height:e};let r=t[t.length-1];return{left:r.left+r.width,width:0,kernedWidth:0,height:e}},Pi=(n,e,t)=>e<0?null:e<n.boxes.length?n.boxes[e]:e===n.boxes.length?mx(n,t):null,px=(n,e,t)=>{if(!Array.isArray(t)||t.length===0)return[];let r=0;for(let h of t){if(!h||typeof h.text!="string")return[];r+=h.text.length}if(r!==n.length)return[];let o=[],i=[];for(let h=0;h<e.lines.length;h++){let d=e.lines[h].graphemes.length;for(let f=0;f<d;f++)i.push(f),o.push(h)}let s=[],a=0;for(let h=0;h<n.length;h++)n[h]===`
|
|
5
|
-
`?s.push(-1):a<o.length?(s.push(a),a++):s.push(-1);let l=[],
|
|
6
|
-
`){u+=1;continue}if(!h.highlight||h.highlight.type!=="svg"||!h.highlight.svgInfo){u+=h.text.length;continue}let d=h.highlight.svgInfo,f=c(u);if(f===-1){u+=h.text.length;continue}let m=o[f],p=0,b=m,x=0,g=y=>{if(p>=y)return;let v=c(u+p),S=c(u+x);v===-1||S===-1||l.push({lineIndex:b,start:i[v],end:i[S]+1,info:d})};for(let y=0;y<h.text.length;y++){let v=c(u+y);if(v===-1){g(y),p=y+1;continue}let S=o[v];S!==m&&(g(y),p=y,m=S),b=S,x=y}g(h.text.length),u+=h.text.length}return l},dl=(n,e,t,r,o,i)=>{let s=r||e;return i==="bottom"?n+e-(t+s)*o:i==="top"?n-t*o:n+(e-s*o)/2-t*o},dh=n=>{let e=Ce(n);if(!e)return null;let t=Fe(e);return t?{left:t.left,top:t.top,width:t.right-t.left,height:t.bottom-t.top}:null},bx=n=>{let e=n.split(/[Zz]/).map(r=>r.trim()).filter(r=>r.length>0);if(e.length===0)return null;let t=e[0];return t.endsWith("Z")||t.endsWith("z")?t:`${t} Z`},Kn=(n,e,t,r,o)=>{let i=px(n,e,t);if(i.length===0)return null;let s=[],a={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},l=(f,m)=>{let p=f.isFill?0:(f.strokeWidth||0)*Math.abs(f.scaleX)/2,b=f.isFill?0:(f.strokeWidth||0)*Math.abs(f.scaleY)/2,x=f.translateX+m.left*f.scaleX-p,g=f.translateY+m.top*f.scaleY-b,y=f.translateX+(m.left+m.width)*f.scaleX+p,v=f.translateY+(m.top+m.height)*f.scaleY+b;x<a.minX&&(a.minX=x),g<a.minY&&(a.minY=g),y>a.maxX&&(a.maxX=y),v>a.maxY&&(a.maxY=v)};for(let f of i){let m=e.lines[f.lineIndex];if(!m)continue;let p=f.info,b=typeof p.path=="string"?p.path:"";if(!b)continue;let x=p.alignVertical||"center",g=p.isFill===!0,y=p.strokeWidth||0,v=-e.width/2+m.leftOffset,S=r+m.top,w=Pi(m,f.start,o);if(!w)continue;if(p.isSingle===!0){let z=bx(b);if(!z)continue;let _=dh(z);if(!_||!Number.isFinite(_.width)||!Number.isFinite(_.height))continue;let D=z;for(let I=f.start;I<f.end;I++){let B=m.graphemes[I];if(!B||/^\s$/.test(B))continue;let G=Pi(m,I,o),X=Pi(m,I+1,o);if(!G)continue;let U=v+G.left,q=S,j=G.kernedWidth||G.width||(X?X.left:G.left)-G.left,Z=G.height,W=_.height;W||(W=Z);let V=_.width?j/_.width:1,Y=W?Z/W:1,re=p.scale||1,te=Math.min(V,Y)*re,de=(_.width||0)*te,Pe=U+(j-de)/2-_.left*te,De=x==="bottom"?q+Z-_.top*te:dl(q,Z,_.top,W,te,x),nt={d:D,translateX:Pe,translateY:De,scaleX:te,scaleY:te,isFill:g,fill:p.fill||"#9FFFFC",stroke:p.stroke||"#9FFFFC",strokeWidth:y};s.push(nt),l(nt,_)}continue}let R=Pi(m,f.end,o);if(!R)continue;let P=v+w.left,E=R.left-w.left,C=w.height,T=dh(b);if(!T||!Number.isFinite(T.width)||!Number.isFinite(T.height)||T.width===0)continue;let M=T.height;M||(M=C);let k=E/T.width,A=C/M,O=P-T.left*k,F=dl(S,C,T.top,M,A,x);if(x==="bottom"||x==="top"){let z=T.top+M,_=z>0?z:M||1;A=C/_,F=dl(S,C,T.top,M,A,x)}T.height||(F+=C/2);let H={d:b,translateX:O,translateY:F,scaleX:k,scaleY:A,isFill:g,fill:p.fill||"#9FFFFC",stroke:p.stroke||"#9FFFFC",strokeWidth:y};s.push(H),l(H,T)}if(s.length===0)return null;let c=e.width/2,u=Number.isFinite(a.minX)&&Number.isFinite(a.minY),h=u?Math.max(2,-c-a.minX,a.maxX-c):2,d=u?Math.max(2,r-a.minY,a.maxY-(r+e.height)):2;return{ops:s,padX:h,padY:d,inkBounds:{left:a.minX,top:a.minY,right:a.maxX,bottom:a.maxY}}},fh=(n,e,t,r)=>{let o=Math.ceil(e.width+n.padX*2),i=Math.ceil(e.height+n.padY*2);if(!(o>0)||!(i>0)||o>8192||i>8192)return null;let s=document.createElement("canvas");s.width=Math.ceil(o*r),s.height=Math.ceil(i*r);let a=s.getContext("2d");if(!a)return null;a.setTransform(r,0,0,r,0,0),a.translate(e.width/2+n.padX,n.padY-t);for(let l of n.ops){let c=new Path2D(l.d);a.save(),a.translate(l.translateX,l.translateY),a.scale(l.scaleX,l.scaleY),l.isFill?(a.fillStyle=l.fill,a.fill(c)):(a.lineWidth=l.strokeWidth,a.strokeStyle=l.stroke,a.stroke(c)),a.restore()}return{canvas:s,logicalW:o,logicalH:i}};var so=n=>{let e=n.pathBackground;if(!e||!e.backgroundChecked||typeof e.path!="string"||!e.path.trim())return null;let t=Number(e.width)||0,r=Number(e.height)||0;if(!t||!r)return null;let o=typeof e.fill=="string"&&e.fill?e.fill:void 0;return{path:e.path,fill:o,width:t,height:r}};var ki=n=>{let e=n.raw,t=so(e);if(!t||!t.fill)return null;let r=n.dims;if(!r.x||!r.y)return null;let o=Ce(t.path);if(!o)return null;let i=Fe(o);if(!i)return null;let s=i.right-i.left,a=i.bottom-i.top;if(!(s>0)||!(a>0))return null;let l=r.x/t.width,c=r.y/t.height,u=s*l,h=a*c;return!(u>0)||!(h>0)||u>8192||h>8192?null:{path:t.path,fill:t.fill,bounds:i,scaleX:l,scaleY:c,logicalW:u,logicalH:h,sigBase:[t.path,t.fill,t.width,t.height,r.x.toFixed(3),r.y.toFixed(3)].join(";")}},mh=(n,e)=>{let t=document.createElement("canvas");t.width=Math.ceil(n.logicalW*e),t.height=Math.ceil(n.logicalH*e);let r=t.getContext("2d");if(!r)return null;let o=(n.bounds.left+n.bounds.right)/2,i=(n.bounds.top+n.bounds.bottom)/2;r.setTransform(e*n.scaleX,0,0,e*n.scaleY,t.width/2-o*n.scaleX*e,t.height/2-i*n.scaleY*e);let s=oe(n.fill);return r.fillStyle=`rgba(${Math.round(s[0]*255)}, ${Math.round(s[1]*255)}, ${Math.round(s[2]*255)}, ${s[3]})`,r.fill(new Path2D(n.path),"nonzero"),{canvas:t,logicalW:n.logicalW,logicalH:n.logicalH}};var ph=n=>{if(!n||typeof n!="object"||Array.isArray(n))return null;let e=n,t=Number(e.blur)||0,r=Number(e.offsetX)||0,o=Number(e.offsetY)||0;if(!t&&!r&&!o)return null;let i=typeof e.color=="string"&&e.color?e.color:"rgb(0,0,0)";return{color:i,rgba:oe(i),blur:t,offsetX:r,offsetY:o,nonScaling:!!e.nonScaling}},Nt=(n,e,t)=>{if(n.nonScaling)return{blur:n.blur,offX:n.offsetX,offY:n.offsetY};let r=Math.abs(e),o=Math.abs(t);return{blur:n.blur*(r+o)/2,offX:n.offsetX*r,offY:n.offsetY*o}},Ai=n=>Math.ceil(n.blur*2+Math.max(Math.abs(n.offX),Math.abs(n.offY))+4),bh=n=>{let e=t=>String(Math.round(t*1e4)/1e4);return[n.color,e(n.blur),e(n.offsetX),e(n.offsetY),n.nonScaling?1:0].join("|")};var Yt=(n,e,t,r,o)=>{let i=[],s=o?r.fontSize*o/1e3:0,a=0;for(let l=0;l<n.graphemes.length;l++){let c=n.graphemes[l],u=n.boxes[l],h=n.charStyles[l]?.fontSize??r.fontSize,d=Un(c);d==="latin"||d==="bracket"?i.push({ch:c,rotated:!1,x:e+a+(d==="latin"?u.kernedWidth-u.width:0),y:t}):i.push({ch:c,rotated:!0,x:e+a+an(h),y:t+br(d,u,h)}),a+=$n(c,u,s)}return i},Ut=(n,e,t)=>{if(!e.rotated){n[t](e.ch,e.x,e.y);return}n.save(),n.translate(e.x,e.y),n.rotate(-Math.PI/2),n[t](e.ch,0,0),n.restore()},un=(n,e)=>!e||e.fontSize===void 0&&e.fontFamily===void 0&&e.fontWeight===void 0&&e.fontStyle===void 0?n:{...n,fontSize:e.fontSize??n.fontSize,fontFamily:e.fontFamily??n.fontFamily,fontWeight:e.fontWeight??n.fontWeight,fontStyle:e.fontStyle??n.fontStyle};var fl=n=>{let e=n.matrix,t=n.dims.x,r=n.dims.y;return{x:Math.abs(e[0])*t+Math.abs(e[2])*r,y:Math.abs(e[1])*t+Math.abs(e[3])*r}},Li=n=>{let e=n.raw;return JSON.stringify([e.path,e.points,e.rx,e.ry,e.radius])},ml=(n,e,t)=>{let r=e.textLayout,o=e.textStyle;n.fillStyle=t,n.textBaseline="alphabetic";let i=e.raw.vertical===!0,s=Number(e.raw.textOffsetY)||0,a=0;for(let l of r.lines){let c=-r.width/2+l.leftOffset,u=e.contentTopY+l.baseline;if(l.prefix&&Tt(n,l,c,u,{fill:"keep"}),i){let h=Yt(l,c,u,o,o.charSpacing??0);for(let d=0;d<h.length;d++){let f=un(o,l.charStyles[d]);n.font=Me(f,f.fontSize),Ut(n,{...h[d],y:h[d].y+wt(s,f.fontSize,a+d)},"fillText")}a+=l.graphemes.length;continue}for(let h=0;h<l.graphemes.length;h++){let d=l.charStyles[h],f=un(o,d);n.font=Me(f,f.fontSize),n.fillText(l.graphemes[h],c+l.boxes[h].left,u+wt(s,f.fontSize,a+h))}a+=l.graphemes.length}},Ni=(n,e,t)=>{let r=e.dims.x,o=e.dims.y;if(e.isSolidType){n.fillStyle=t;let i=it(e.raw,r,o);if(i){zn(n,r,o,i.rx,i.ry),n.fill();return}n.fillRect(-r/2,-o/2,r,o);return}if(e.isShapeType){let i=e.raw;if(se(i)===L.ELLIPSE||se(i)===L.CIRCLE){n.fillStyle=t,n.beginPath(),n.ellipse(0,0,r/2,o/2,0,0,Math.PI*2),n.fill();return}let s=e.shapeMesh;if(!s)return;n.fillStyle=t,n.beginPath();let a=s.verts.length/2;for(let l=0;l<a;l++){let c=s.verts[l*2],u=s.verts[l*2+1];l===0?n.moveTo(c,u):n.lineTo(c,u)}n.closePath(),n.fill();return}if(e instanceof ie){let i=e.paintSource;i&&n.drawImage(i,-r/2,-o/2,r,o);return}if((e.isImageType||e.isMaskType)&&e.imageEl){let i=e.cropRect,s=e.isImageType&&!(e instanceof ie)?fr(e.raw,r,o):null;s&&(n.save(),zn(n,r,o,s,s),n.clip()),i?n.drawImage(e.imageEl,i.sx,i.sy,i.sw,i.sh,-r/2,-o/2,r,o):n.drawImage(e.imageEl,-r/2,-o/2,r,o),s&&n.restore();return}if(e.isTextType&&e instanceof Se){if($t(e)){if(!e.imageEl)return;let i=e.bitmapRect;n.save(),n.translate(i.x,i.y),i.angle&&n.rotate(-i.angle*Math.PI/180),n.drawImage(e.imageEl,-i.w/2,-i.h/2,i.w,i.h),n.restore();return}ml(n,e,t)}},xh=(n,e)=>{let t=Nt(e,n.raw.scaleX??1,n.raw.scaleY??1),r=Ai(t)+(n.isTextType?Math.ceil((n.raw.fontSize??40)*.5):0),o=fl(n),i=Math.ceil(o.x+r*2),s=Math.ceil(o.y+r*2);if(!(i>0)||!(s>0)||i>8192||s>8192)return null;let a=document.createElement("canvas");a.width=i,a.height=s;let l=a.getContext("2d");if(!l)return null;let c=n.matrix;l.setTransform(c[0],c[1],c[2],c[3],i/2,s/2);let u=`rgba(${Math.round(e.rgba[0]*255)},${Math.round(e.rgba[1]*255)},${Math.round(e.rgba[2]*255)},1)`;return l.shadowColor=e.color,l.shadowBlur=t.blur,l.shadowOffsetX=t.offX,l.shadowOffsetY=t.offY,Ni(l,n,u),l.shadowColor="rgba(0,0,0,0)",l.shadowBlur=0,l.shadowOffsetX=0,l.shadowOffsetY=0,l.globalCompositeOperation="destination-out",Ni(l,n,u),{canvas:a,w:i,h:s}};var pl=(n,e,t)=>{let r=e+t,o=n,i=new Int32Array(e*t);for(let f=0;f<e;f++){o[f+0*e]?i[f+0*e]=0:i[f+0*e]=r;for(let m=1;m<t;m++)o[f+m*e]?i[f+m*e]=0:i[f+m*e]=1+i[f+(m-1)*e];for(let m=t-2;m>=0;m--)i[f+(m+1)*e]<i[f+m*e]&&(i[f+m*e]=1+i[f+(m+1)*e])}let s=(f,m,p)=>(f-m)*(f-m)+p*p,a=(f,m,p,b)=>Math.floor((m*m-f*f+b*b-p*p)/(2*(m-f))),l=new Int32Array(e*t),c=new Int32Array(e),u=new Int32Array(e),h,d;for(let f=0;f<t;f++){h=0,c[0]=0,u[0]=0;for(let m=1;m<e;m++){for(;h>=0&&s(u[h],c[h],i[c[h]+f*e])>s(u[h],m,i[m+f*e]);)h--;h<0?(h=0,c[0]=m):(d=1+a(c[h],m,i[c[h]+f*e],i[m+f*e]),d<e&&(h++,c[h]=m,u[h]=d))}for(let m=e-1;m>=0;m--){let p=s(m,c[h],i[c[h]+f*e]);p=Math.floor(Math.sqrt(p)),l[m+f*e]=p,m===u[h]&&h--}}return l},gh=(n,e=10)=>{let t=new Uint8Array(n.length/4);for(let r=0;r<t.length;r++)t[r]=n[r*4+3]>e?1:0;return t};var yh={Brownie:[.5997,.34553,-.27082,0,.186,-.0377,.86095,.15059,0,-.1449,.24113,-.07441,.44972,0,-.02965,0,0,0,1,0],Vintage:[.62793,.32021,-.03965,0,.03784,.02578,.64411,.03259,0,.02926,.0466,-.08512,.52416,0,.02023,0,0,0,1,0],Kodachrome:[1.12855,-.39673,-.03992,0,.24991,-.16404,1.08352,-.05498,0,.09698,-.16786,-.56034,1.60148,0,.13972,0,0,0,1,0],Technicolor:[1.91252,-.85453,-.09155,0,.04624,-.30878,1.76589,-.10601,0,-.27589,-.2311,-.75018,1.84759,0,.12137,0,0,0,1,0],Polaroid:[1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0],Sepia:[.393,.769,.189,0,0,.349,.686,.168,0,0,.272,.534,.131,0,0,0,0,0,1,0],BlackWhite:[1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,0,0,0,1,0]},me=(n,e)=>typeof n=="number"&&Number.isFinite(n)?n:e,hn=(n,e)=>typeof n=="string"&&n?n:e,bl=(n,e)=>typeof n=="boolean"?n:e;function xx(n){let e=i=>Math.max(0,Math.min(255,Math.round(i))),t=n.map(i=>({input:e(i.input),output:e(i.output)}));t.sort((i,s)=>i.input-s.input);let r=[];for(let i of t)r.length&&r[r.length-1].input===i.input?r[r.length-1]=i:r.push(i);if(r.length<2)return[];if(r.length<=16)return r;let o=[];for(let i=0;i<16;i++){let s=e(i/15*255);o.push({input:s,output:e(gx(r,s))})}return o}function gx(n,e){if(n.length===0)return e;let t=n[0],r=n[n.length-1];if(e<=t.input)return t.output;if(e>=r.input)return r.output;for(let o=0;o<n.length-1;o++){let i=n[o],s=n[o+1];if(e>=i.input&&e<=s.input){let a=(e-i.input)/Math.max(1e-5,s.input-i.input);return i.output+(s.output-i.output)*a}}return e}function yx(n){if(!Array.isArray(n))return[];let e=[];for(let r of n){if(!r||typeof r!="object")continue;let o=r,i=o.input,s=o.output;typeof i!="number"||!Number.isFinite(i)||typeof s!="number"||!Number.isFinite(s)||e.push({input:i,output:s})}let t=[];for(let r of xx(e))t.push(r.input,r.output);return t}function ao(n){if(!Array.isArray(n))return[];let e=[];for(let t of n){if(!t||typeof t!="object")continue;let r=t,o=r.psd===1;switch(r.type){case"Brightness":e.push({kind:"Brightness",brightness:o?me(r.brightness,0)/100:me(r.brightness,0)});break;case"Contrast":e.push({kind:"Contrast",contrast:o?me(r.contrast,0)/100:me(r.contrast,0)});break;case"Saturation":e.push({kind:"Saturation",saturation:o?me(r.saturation,0)/100:me(r.saturation,0)});break;case"Vibrance":e.push({kind:"Vibrance",vibrance:o?me(r.vibrance,0)/100:me(r.vibrance,0)});break;case"HueRotation":e.push({kind:"HueRotation",rotation:o?me(r.hue,0)/100:me(r.rotation,0)});break;case"Grayscale":{let i=hn(r.mode,"average");e.push({kind:"Grayscale",mode:i==="lightness"||i==="luminosity"?i:"average"});break}case"Invert":e.push({kind:"Invert",invert:bl(r.invert,!0),alphaOnly:bl(r.alphaOnly,!1)});break;case"Sepia":case"Brownie":case"Kodachrome":case"Technicolor":case"Polaroid":case"BlackWhite":case"Vintage":e.push({kind:"ColorMatrix",matrixId:r.type});break;case"ColorMatrix":{let i=Array.isArray(r.matrix)?r.matrix.filter(s=>typeof s=="number"&&Number.isFinite(s)):[];i.length===20&&e.push({kind:"ColorMatrixOp",matrix:i});break}case"Blur":e.push({kind:"Blur",blur:me(o?r.radius:r.blur,0)});break;case"Noise":e.push({kind:"Noise",noise:me(r.noise,0)});break;case"Pixelate":e.push({kind:"Pixelate",blocksize:me(r.blocksize,1)});break;case"Convolute":{let i=Array.isArray(r.matrix)?r.matrix.filter(a=>typeof a=="number"):[],s=Math.sqrt(i.length);Number.isInteger(s)&&s>=3&&s<=9&&e.push({kind:"Convolute",matrix:i,opaque:bl(r.opaque,!1)});break}case"BlendColor":{let i=hn(r.mode,"multiply"),s=["multiply","screen","add","difference","subtract","darken","lighten","overlay","exclusion","tint"];e.push({kind:"BlendColor",color:hn(r.color,"#000000"),mode:s.includes(i)?i:"multiply",alpha:me(r.alpha,1)});break}case"Vignette":e.push({kind:"Vignette",intensity:me(r.intensity,0)});break;case"Temperature":{if(o){let i=dn(hn(r.color,"#ffb86b")),s=i[0]>=i[2];e.push({kind:"Temperature",temperature:me(r.density,0)/100*(s?1:-1)})}else e.push({kind:"Temperature",temperature:me(r.temperature,0)});break}case"Posterize":e.push({kind:"Posterize",levels:me(r.levels,20)});break;case"FilmGrain":e.push({kind:"FilmGrain",intensity:me(r.intensity,0),seed:me(r.seed,0)});break;case"Duotone":e.push({kind:"Duotone",color1:hn(r.color1,"#000000"),color2:hn(r.color2,"#ffffff")});break;case"Sketch":e.push({kind:"Sketch"});break;case"ChromaticAberration":e.push({kind:"ChromaticAberration",offset:me(r.offset,4)});break;case"SoftFocus":e.push({kind:"SoftFocus",blend:me(r.blend,.5)});break;case"Threshold":e.push({kind:"Threshold",threshold:me(r.threshold,128)});break;case"UnsharpMask":e.push({kind:"UnsharpMask",amount:o?me(r.amount,100)/100:me(r.amount,1)});break;case"MotionBlur":e.push({kind:"MotionBlur",distance:me(r.distance,0),angle:me(r.angle,0)});break;case"LensFlare":e.push({kind:"LensFlare",intensity:me(r.intensity,.8)});break;case"GradientMap":e.push({kind:"GradientMap",color0:hn(r.color0,"#000000"),color1:hn(r.color1,"#888888"),color2:typeof r.color2=="string"&&r.color2?r.color2:""});break;case"Levels":e.push({kind:"Levels",blackPoint:me(r.blackPoint,0),whitePoint:me(r.whitePoint,255),gamma:me(r.gamma,1)});break;case"Curves":e.push({kind:"Curves",points:yx(r.points)});break;case"SurfaceBlur":e.push({kind:"SurfaceBlur",radius:me(r.radius,3),threshold:o?me(r.threshold,51)/255:me(r.threshold,.2)});break;case"Exposure":e.push({kind:"Exposure",exposure:me(r.exposure,0),offset:me(r.offset,0),gamma:me(r.gamma,1)});break;default:break}}return e}function Ii(n){return JSON.stringify(n)}var Ow=Math.PI/2;function dn(n){let e=n.replace("#","");return/^[0-9a-fA-F]{6}$/.test(e)?[parseInt(e.substring(0,2),16),parseInt(e.substring(2,4),16),parseInt(e.substring(4,6),16)]:[0,0,0]}var fn=(n,e,t,r,o,i,s)=>{t?n.drawImage(e,t.sx,t.sy,t.sw,t.sh,r,o,i,s):n.drawImage(e,r,o,i,s)},Sx=6e5,_i=n=>Math.max(1,Math.floor(Math.sqrt(Sx/Math.max(1,n.dims.x*n.dims.y)))),Di=n=>{if(!n.isImageType||n instanceof ie)return"";let e=ao(n.raw.filters);return e.length?`|f${Ii(e)}`:""},jt=n=>!n.isImageType||n instanceof ie?null:fr(n.raw,n.dims.x,n.dims.y),vh=n=>{let e=jt(n);return e?`|rr${e}`:""},wh=(n,e,t,r,o,i,s)=>{n.save(),n.translate(t,r),e&&(zn(n,o,i,e,e),n.clip()),s(),n.restore()},lo=(n,e,t,r,o)=>{if(!t)return n;let i=document.createElement("canvas");i.width=r,i.height=o;let s=i.getContext("2d",{willReadFrequently:!0});return s?(wh(s,t,r/2,o/2,r,o,()=>fn(s,n,e,-r/2,-o/2,r,o)),i):n},vx=n=>{let e=n.matrix,t=n.dims.x,r=n.dims.y;return{x:Math.abs(e[0])*t+Math.abs(e[2])*r,y:Math.abs(e[1])*t+Math.abs(e[3])*r}},Sh=n=>({color:n.color,rgba:n.rgba,blur:n.blur,offsetX:n.offsetX,offsetY:n.offsetY,nonScaling:!1}),co=(n,e=1)=>{let t=Math.max(1,Math.ceil(n.dims.x*e)),r=Math.max(1,Math.ceil(n.dims.y*e));if(t>8192||r>8192)return null;let o=document.createElement("canvas");o.width=t,o.height=r;let i=o.getContext("2d");return i?(i.translate(t/2,r/2),i.scale(e,e),ml(i,n,"#ffffff"),o):null},Fi=(n,e,t,r=1,o=null)=>{if(!t||e.length===0)return null;let i=n.raw.scaleX??1,s=n.raw.scaleY??1,a=4;for(let S of e){let w=Nt(Sh(S),i,s);a=Math.max(a,Math.ceil(w.blur*2+Math.max(Math.abs(w.offX),Math.abs(w.offY))+4))}let l=vx(n),c=Math.ceil(l.x+a*2),u=Math.ceil(l.y+a*2),h=Math.ceil(c*r),d=Math.ceil(u*r);if(!(c>0)||!(u>0)||h>8192||d>8192)return null;let f=jt(n),m=f?lo(t,o,f*r,Math.max(1,Math.ceil(n.dims.x*r)),Math.max(1,Math.ceil(n.dims.y*r))):t,p=f?null:o,b=document.createElement("canvas");b.width=h,b.height=d;let x=b.getContext("2d");if(!x)return null;let g=n.matrix;x.setTransform(g[0]*r,g[1]*r,g[2]*r,g[3]*r,h/2,d/2);let y=n.dims.x,v=n.dims.y;for(let S of e){let w=Nt(Sh(S),i,s);x.filter=`drop-shadow(${w.offX*r}px ${w.offY*r}px ${w.blur*r}px ${S.color})`,fn(x,m,p,-y/2,-v/2,y,v)}return x.filter="none",x.globalCompositeOperation="destination-out",fn(x,m,p,-y/2,-v/2,y,v),{canvas:b,w:h,h:d,quadW:c,quadH:u}},Th=(n,e,t)=>{let r=[1,0,0,1,n.offsetX,n.offsetY];return n.gradientUnits==="percentage"&&(r=$(r,[e,0,0,t,0,0])),n.gradientTransform&&(r=$(r,n.gradientTransform)),r},wx=(n,e,t,r)=>{let o=$([1,0,0,1,r,r],Th(n,e,t)),i=ve(o),s=ui(n,512),a=511,l=n.kind==="linear";return(c,u)=>{let h=c+.5,d=u+.5,f=i[0]*h+i[2]*d+i[4],m=i[1]*h+i[3]*d+i[5],p=l?Mu(n,{x:f,y:m}):Ru(n,{x:f,y:m}),b=Math.min(a,Math.max(0,Math.round((isFinite(p)?p:0)*a)));return[s[b*4],s[b*4+1],s[b*4+2],s[b*4+3]]}},gr=(n,e,t,r=1,o=null)=>{if(!t)return null;let i=Math.max(1,Math.ceil(n.dims.x)),s=Math.max(1,Math.ceil(n.dims.y)),a=Math.ceil(i*r),l=Math.ceil(s*r);if(a>8192||l>8192)return null;let c=document.createElement("canvas");c.width=a,c.height=l;let u=c.getContext("2d");if(!u)return null;if(e.kind==="gradient"){let d=e.decl,f=Th(d,a,l);u.setTransform(f[0],f[1],f[2],f[3],f[4],f[5]);let m=d.kind==="linear"?u.createLinearGradient(d.x1,d.y1,d.x2,d.y2):u.createRadialGradient(d.x1,d.y1,d.r1,d.x2,d.y2,d.r2);for(let p of d.stops){let b=Math.min(1,Math.max(0,p.offset));m.addColorStop(b,`rgba(${Math.round(p.color[0]*255)}, ${Math.round(p.color[1]*255)}, ${Math.round(p.color[2]*255)}, ${p.color[3]})`)}if(u.fillStyle=m,d.gradientUnits==="percentage")u.fillRect(-2,-2,5,5);else{let p=ve(f),b=[Q(p,0,0),Q(p,a,0),Q(p,0,l),Q(p,a,l)];if(b.every(x=>isFinite(x.x)&&isFinite(x.y))){let x=Math.min(...b.map(S=>S.x))-2,g=Math.max(...b.map(S=>S.x))+2,y=Math.min(...b.map(S=>S.y))-2,v=Math.max(...b.map(S=>S.y))+2;u.fillRect(x,y,g-x,v-y)}else u.fillRect(-a-l,-a-l,(a+l)*3,(a+l)*3)}u.setTransform(1,0,0,1,0,0)}else u.fillStyle=e.color,u.fillRect(0,0,a,l);u.globalCompositeOperation="destination-in";let h=jt(n);return h?fn(u,lo(t,o,h*r,a,l),null,0,0,a,l):fn(u,t,o,0,0,a,l),c},Eh=(n,e)=>{if(e.length===0)return null;let t=n.raw.fill;if(t==null||t===""||t==="transparent")return null;let r=Math.abs(n.matrix[0])*n.dims.x+Math.abs(n.matrix[2])*n.dims.y,o=Math.abs(n.matrix[1])*n.dims.x+Math.abs(n.matrix[3])*n.dims.y,i=4;for(let h of e)i=Math.max(i,Math.ceil(h.blur*2+Math.max(Math.abs(h.offsetX),Math.abs(h.offsetY))+4));let s=Math.ceil(r+i*2),a=Math.ceil(o+i*2);if(!(s>0)||!(a>0)||s>8192||a>8192)return null;let l=document.createElement("canvas");l.width=s,l.height=a;let c=l.getContext("2d");if(!c)return null;let u=n.matrix;c.setTransform(u[0],u[1],u[2],u[3],s/2,a/2);for(let h of e){if(c.filter=`drop-shadow(${h.offsetX}px ${h.offsetY}px ${h.blur}px ${h.color})`,c.fillStyle=Zr(n,c),!pr(c,n))return null;c.fill()}return c.filter="none",{canvas:l,w:s,h:a,quadW:s,quadH:a}},Ch=(n,e=1)=>{let t=Math.max(1,Math.ceil(n.dims.x*e)),r=Math.max(1,Math.ceil(n.dims.y*e));if(t>8192||r>8192)return null;let o=document.createElement("canvas");o.width=t,o.height=r;let i=o.getContext("2d");return!i||(i.setTransform(e,0,0,e,t/2,r/2),i.fillStyle="#fff",!pr(i,n))?null:(i.fill(n.raw.fillRule==="evenodd"?"evenodd":"nonzero"),o)},yr=(n,e,t,r=1,o=null)=>{if(!t)return null;let i=Math.max(1,Math.ceil(n.dims.x)),s=Math.max(1,Math.ceil(n.dims.y)),a=Math.ceil(i*r),l=Math.ceil(s*r);if(a>8192||l>8192)return null;let c=jt(n),u=c?lo(t,o,c*r,a,l):t,h=document.createElement("canvas");h.width=a,h.height=l;let d=h.getContext("2d");if(!d)return null;fn(d,u,c?null:o,0,0,a,l),d.globalCompositeOperation="source-in",d.fillStyle=e.color,d.fillRect(0,0,a,l);let f=document.createElement("canvas");f.width=a,f.height=l;let m=f.getContext("2d");return m?(m.drawImage(h,0,0),m.globalCompositeOperation="destination-out",e.blur>0&&(m.filter=`blur(${e.blur}px)`),fn(m,u,c?null:o,e.offsetX,e.offsetY,a,l),m.filter="none",m.globalCompositeOperation="source-over",f):null},mn=(n,e,t,r=!0,o=1,i=null,s=!1)=>{if(!t||e.length===0)return[];let a=o,l=Math.max(1,Math.ceil(n.dims.x*a)),c=Math.max(1,Math.ceil(n.dims.y*a));if((l>8192||c>8192)&&(a=1,l=Math.max(1,Math.ceil(n.dims.x)),c=Math.max(1,Math.ceil(n.dims.y))),l>8192||c>8192)return[];let u=document.createElement("canvas");u.width=l,u.height=c;let h=u.getContext("2d",{willReadFrequently:!0});if(!h)return[];let d=jt(n),f=n.dims.x*a,m=n.dims.y*a;wh(h,d?d*a:null,l/2,c/2,f,m,()=>fn(h,t,i,-f/2,-m/2,f,m));let p=[];for(let b=e.length-1;b>=0;b--){let x=e[b],g=x.width,y=x.alignment,v=y==="outside"?g:y==="center"?Math.ceil(g/2):0,S=v*a,w=Math.floor(l+S*2),R=Math.floor(c+S*2);if(w<=0||R<=0)continue;let P=document.createElement("canvas");P.width=w,P.height=R;let E=P.getContext("2d",{willReadFrequently:!0});if(!E)continue;E.drawImage(u,S,S);let C=gh(E.getImageData(0,0,w,R).data),T=pl(C,w,R),M=new Uint8Array(C.length);for(let Y=0;Y<C.length;Y++)M[Y]=C[Y]?0:1;for(let Y=0;Y<w;Y++)M[Y]=1,M[Y+(R-1)*w]=1;for(let Y=0;Y<R;Y++)M[Y*w]=1,M[w-1+Y*w]=1;let k=pl(M,w,R),A=w*R,O=new Int32Array(A);for(let Y=0;Y<A;Y++)O[Y]=C[Y]?-k[Y]:T[Y];let F=s?.5*a:0,H,z;y==="inside"?(H=-g*a-F,z=F):y==="center"?(H=-g/2*a-F,z=g/2*a+F):(H=-F,z=g*a+F);let _=Math.round(x.rgba[0]*255),D=Math.round(x.rgba[1]*255),I=Math.round(x.rgba[2]*255),B=Math.round(x.rgba[3]*255),G=x.kind==="gradient"&&x.decl?wx(x.decl,l,c,S):null,X=document.createElement("canvas");X.width=w,X.height=R;let U=X.getContext("2d");if(!U)continue;let q=U.createImageData(w,R),j=q.data;for(let Y=0;Y<A;Y++){let re=O[Y];if(re>=H&&re<z){let te=Y*4;if(G){let de=G(Y%w,Y/w|0);j[te]=de[0],j[te+1]=de[1],j[te+2]=de[2],j[te+3]=de[3]}else j[te]=_,j[te+1]=D,j[te+2]=I,j[te+3]=B}}U.putImageData(q,0,0);let Z=document.createElement("canvas");Z.width=w,Z.height=R;let W=Z.getContext("2d");if(!W)continue;r&&W.drawImage(u,S,S),W.drawImage(X,0,0);let V=y==="outside"?g:y==="center"?g/2:0;p.push({canvas:Z,w,h:R,quadW:w/a,quadH:R/a,dx:v-V+x.offset.x,dy:v-V+x.offset.y})}return p};var Mh=n=>xr(n),Qe=2,uo=(n,e)=>{let t=e.textLayout,r=e.textStyle,o=e.textStroke;n.textBaseline="alphabetic";for(let i of t.lines){let s=-t.width/2+i.leftOffset,a=e.contentTopY+i.baseline,l=i.charStyles[0],c=typeof l?.fill=="string"&&l.fill?l.fill:typeof e.raw.fill=="string"?e.raw.fill:null,u="",h=i.prefix?Tt(n,i,s,a,{fill:c,stroke:Oe(o,l)}):0,d="",f="",m=null,p=b=>{if(!u)return;n.font=d;let x=s+h;typeof f=="string"&&f?(n.fillStyle=f,n.fillText(u,x,a)):typeof e.raw.fill=="string"&&e.raw.fill&&(n.fillStyle=e.raw.fill,n.fillText(u,x,a)),m&&m.width>0&&(n.lineWidth=m.width,n.strokeStyle=m.color,n.strokeText(u,x,a)),u="",b<i.boxes.length&&(h=i.boxes[b].left)};for(let b=0;b<i.graphemes.length;b++){let x=i.charStyles[b],y=x!==void 0&&(x.fontSize!==void 0||x.fontFamily!==void 0||x.fontWeight!==void 0||x.fontStyle!==void 0)&&x?{...r,fontSize:x.fontSize??r.fontSize,fontFamily:x.fontFamily??r.fontFamily,fontWeight:x.fontWeight??r.fontWeight,fontStyle:x.fontStyle??r.fontStyle}:r,v=Me(y,y.fontSize),S=Oe(o,x),w=typeof x?.fill=="string"?x.fill:"",R=m;u&&(v!==d||S?.color!==R?.color||S?.width!==R?.width||w!==f)&&p(b),u||(d=v,m=S,f=w),u+=i.graphemes[b]}p(i.graphemes.length)}},Sr=n=>{let e=0;for(let t of n.strokes)e=Math.max(e,t.alignment==="outside"?t.width:t.alignment==="center"?Math.ceil(t.width/2):0);for(let t of n.dropShadows)e=Math.max(e,Math.ceil(t.blur*2+Math.max(Math.abs(t.offsetX),Math.abs(t.offsetY))));for(let t of n.solidFills)e=Math.max(e,Math.ceil(Math.max(Math.abs(t.offset.x),Math.abs(t.offset.y))));return e},xl=(n,e,t)=>{let r=4;for(let m of n)r=Math.max(r,Math.ceil(m.blur*2+Math.max(Math.abs(m.offsetX),Math.abs(m.offsetY))+4));let o=e.width/t,i=e.height/t,s=Math.ceil(o+r*2),a=Math.ceil(i+r*2),l=Math.ceil(s*t),c=Math.ceil(a*t);if(!(l>0)||!(c>0)||l>8192||c>8192)return null;let u=document.createElement("canvas");u.width=l,u.height=c;let h=u.getContext("2d");if(!h)return null;let d=(l-e.width)/2,f=(c-e.height)/2;for(let m of n)h.filter=`drop-shadow(${m.offsetX*t}px ${m.offsetY*t}px ${m.blur*t}px ${m.color})`,h.drawImage(e,d,f);return h.filter="none",h.globalCompositeOperation="destination-out",h.drawImage(e,d,f),{canvas:u,w:s,h:a}},ho=(n,e,t)=>{if(!t||t.dropShadows.length===0&&t.innerShadows.length===0&&t.solidFills.length===0&&t.strokes.length===0)return;let r=co(e,Qe);if(!r)return;let o=e.dims.x,i=e.dims.y;if(t.dropShadows.length){let l=xl(t.dropShadows,r,Qe);l&&(n.save(),n.globalCompositeOperation="destination-over",n.drawImage(l.canvas,-l.w/2,-l.h/2,l.w,l.h),n.restore())}let s=(l,c)=>{if(!l){c();return}n.save(),n.globalCompositeOperation=l,c(),n.restore()};for(let l of t.innerShadows){let c=yr(e,l,r,Qe);c&&s(l.blendMode,()=>n.drawImage(c,-o/2,-i/2,o,i))}for(let l of t.solidFills){let c=gr(e,l,r,Qe);c&&s(l.blendMode,()=>n.drawImage(c,-o/2+l.offset.x,-i/2+l.offset.y,o,i))}mn(e,t.strokes,r,!1,Math.min(2,Qe),null,!0).forEach((l,c)=>{let u=t.strokes[t.strokes.length-1-c];s(u?.blendMode,()=>n.drawImage(l.canvas,-l.quadW/2+l.dx,-l.quadH/2+l.dy,l.quadW,l.quadH))})},gl=(n,e,t=null)=>{let r=n.textLayout,o=Number(n.raw.fontSize)||40,i=Math.max(-1,Math.min(1,Number(n.raw.warpStrength)||0)),s=typeof n.raw.width=="number"?n.raw.width:r.width,a=typeof n.raw.height=="number"?n.raw.height:r.height,l=o*(e==="arch"?.6:.5),c=Math.max(r.width,s,o),u=Math.max(a,o),h=e==="arch"?u*Math.max(0,i):0,d=e==="flag"?Math.abs(i)*(a||o)*.3:0,f=1+Math.abs(i),m=t?Sr(t):0,p=Math.ceil(c+l*2+m*2),b=Math.ceil(e==="arch"?u+l*2+m*2+h:e==="flag"?(a||o)+d*2+l*2+m*2:(a||o)*f+l*2+m*2),x=p*Qe,g=b*Qe;if(!(x>0)||!(g>0)||x>8192||g>8192)return null;let y=document.createElement("canvas");y.width=x,y.height=g;let v=y.getContext("2d",{willReadFrequently:!0});if(!v)return null;let S=e==="arch"?h/2*Qe:0;v.setTransform(Qe,0,0,Qe,x/2,g/2+S),uo(v,n),ho(v,n,t);let w=v.getImageData(0,0,x,g),R=new Uint32Array(w.data.buffer),P=x,E=0,C=g,T=0,M=!1;for(let _=0;_<g;_++)for(let D=0;D<x;D++)(R[_*x+D]>>>24&255)>10&&(M=!0,D<P&&(P=D),D>E&&(E=D),_<C&&(C=_),_>T&&(T=_));let k=M?(P+E)/2:x/2,A=M?T:g-1,O=M?Math.max(1,E-P)/2:x/2,F=v.createImageData(x,g),H=new Uint32Array(F.data.buffer),z=(_,D)=>{let I=Math.floor(D),B=I+1;if(I<0||B>=g)return 0;let G=D-I,X=R[I*x+_],U=R[B*x+_],q=X>>>24&255,j=U>>>24&255;if(q<=10&&j<=10)return 0;let Z=Math.round((X&255)*(1-G)+(U&255)*G),W=Math.round((X>>>8&255)*(1-G)+(U>>>8&255)*G),V=Math.round((X>>>16&255)*(1-G)+(U>>>16&255)*G);return Math.round(q*(1-G)+j*G)<<24|V<<16|W<<8|Z};if(e==="flag")for(let _=0;_<x;_++){let D=O>0?(_-k)/O:0,I=Math.sin(D*Math.PI)*d*Qe*i;for(let B=0;B<g;B++)H[B*x+_]=z(_,B+I)}else if(e==="arch")for(let _=0;_<x;_++){let D=Math.max(-1,Math.min(1,(_-k)/O)),I=Math.sqrt(Math.max(0,1-D*D)),B=I*I*(3-2*I),G=i>0?Math.pow(B,2.5):B,X=Math.min(1+Math.max(0,i),Math.max(.05,1+i*G));for(let U=0;U<=A;U++){let q=A-U;H[U*x+_]=z(_,A-q/X)}}else{let _=M?(C+T)/2:g/2;for(let D=0;D<x;D++){let I=O>0?(D-k)/O:0,B=1+i*(I*I-.5);B=Math.min(1+Math.abs(i),Math.max(.4,B));for(let G=0;G<g;G++)H[G*x+D]=z(D,_+(G-_)/B)}}return v.setTransform(1,0,0,1,0,0),v.clearRect(0,0,x,g),v.putImageData(F,0,0),{canvas:y,logicalW:p,logicalH:b}},Oi=(n,e)=>{let t=e.textLayout,r=e.textStyle,o=e.textStroke,i=typeof e.raw.fill=="string"?e.raw.fill:"",s=Number(e.raw.textOffsetY)||0;n.textBaseline="alphabetic";let a=0;for(let l of t.lines){let c=-t.width/2+l.leftOffset,u=e.contentTopY+l.baseline,h=l.charStyles[0],d=typeof h?.fill=="string"&&h.fill?h.fill:i||null;l.prefix&&Tt(n,l,c,u,{fill:d,stroke:Oe(o,h)});let f=Yt(l,c,u,r,r.charSpacing??0);for(let m=0;m<f.length;m++){let p=l.charStyles[m],b=un(r,p);n.font=Me(b,b.fontSize);let x=typeof p?.fill=="string"&&p.fill?p.fill:i,g=Oe(o,p),y={...f[m],y:f[m].y+wt(s,b.fontSize,a+m)};x&&(n.fillStyle=x,Ut(n,y,"fillText")),g&&g.width>0&&(n.lineWidth=g.width,n.strokeStyle=g.color,Ut(n,y,"strokeText"))}a+=l.graphemes.length}},Tx=(n,e)=>{let t=e?Sr(e):0,r=Math.ceil(n.dims.x+t*2),o=Math.ceil(n.dims.y+t*2),i=r*Qe,s=o*Qe;if(!(i>0)||!(s>0)||i>8192||s>8192)return null;let a=document.createElement("canvas");a.width=i,a.height=s;let l=a.getContext("2d");return l?(l.setTransform(Qe,0,0,Qe,i/2,s/2),n.raw.vertical===!0?Oi(l,n):uo(l,n),ho(l,n,e),{canvas:a,logicalW:r,logicalH:o}):null};var Ph=2,pn=(n,e)=>e!==void 0&&(e.fontSize!==void 0||e.fontFamily!==void 0||e.fontWeight!==void 0||e.fontStyle!==void 0)&&e?{...n,fontSize:e.fontSize??n.fontSize,fontFamily:e.fontFamily??n.fontFamily,fontWeight:e.fontWeight??n.fontWeight,fontStyle:e.fontStyle??n.fontStyle}:n,kh=(n,e,t,r)=>{let o=e.textStyle,i=e.textStroke,s=e.raw.strokeVisible===!0,a=e.paintFirst==="stroke",l=typeof e.raw.fill=="string"?e.raw.fill:"";for(let c of t.chars){let u=e.textLayout.lines[c.line]?.charStyles[c.index],h=pn(o,u),d=r==="silhouette"?"#ffffff":typeof u?.fill=="string"&&u.fill?u.fill:l,f=r==="silhouette"?null:s?Oe(i,u):null,m=Me(h,h.fontSize);n.save(),n.translate(c.x,c.y),n.rotate(c.rotation),n.font=m;let p=()=>{d&&(n.fillStyle=d,n.fillText(c.char,0,0))},b=()=>{f&&f.width>0&&(n.lineWidth=f.width,n.strokeStyle=f.color,n.strokeText(c.char,0,0))};a?(b(),p()):(p(),b()),n.restore()}},Rh=(n,e,t=Ph)=>{let r=Math.max(1,Math.ceil(n.dims.x*t)),o=Math.max(1,Math.ceil(n.dims.y*t));if(r>8192||o>8192)return null;let i=document.createElement("canvas");i.width=r,i.height=o;let s=i.getContext("2d");return s?(s.setTransform(t,0,0,t,r/2-e.contentOffsetX*t,o/2-e.contentOffsetY*t),s.textBaseline="alphabetic",s.textAlign="center",kh(s,n,e,"silhouette"),i):null},Ex=(n,e,t,r,o)=>{if(r.dropShadows.length===0&&r.innerShadows.length===0&&r.solidFills.length===0&&r.strokes.length===0)return;let i=e.dims.x,s=e.dims.y,a=t.contentOffsetX,l=t.contentOffsetY,c=(u,h)=>{if(!u){h();return}n.save(),n.globalCompositeOperation=u,h(),n.restore()};if(r.dropShadows.length||r.solidFills.length||r.innerShadows.length){let u=Rh(e,t,o);if(u){if(r.dropShadows.length){let h=xl(r.dropShadows,u,o);h&&(n.save(),n.globalCompositeOperation="destination-over",n.drawImage(h.canvas,a-h.w/2,l-h.h/2,h.w,h.h),n.restore())}for(let h of r.innerShadows){let d=yr(e,h,u,o);d&&c(h.blendMode,()=>n.drawImage(d,a-i/2,l-s/2,i,s))}for(let h of r.solidFills){let d=gr(e,h,u,o);d&&c(h.blendMode,()=>n.drawImage(d,a-i/2+h.offset.x,l-s/2+h.offset.y,i,s))}}}if(r.strokes.length){let u=Math.min(Math.max(2,o),_i(e)),h=Rh(e,t,u);h&&mn(e,r.strokes,h,!1,u,null,!0).forEach((f,m)=>{let p=r.strokes[r.strokes.length-1-m];c(p?.blendMode,()=>n.drawImage(f.canvas,a-f.quadW/2+f.dx,l-f.quadH/2+f.dy,f.quadW,f.quadH))})}},yl=(n,e,t=null,r=Ph)=>{let o=Et(n.textLayout,n.raw,n.textStyle.lineHeight??1.16),i=t?Sr(t):0,s=o.width+i*2,a=o.height+i*2,l=Math.ceil(s*r),c=Math.ceil(a*r);if(!(l>0)||!(c>0)||l>8192||c>8192)return null;let u=document.createElement("canvas");u.width=l,u.height=c;let h=u.getContext("2d");return h?(h.setTransform(r,0,0,r,l/2-o.contentOffsetX*r,c/2-o.contentOffsetY*r),h.textBaseline="alphabetic",h.textAlign="center",kh(h,n,o,"render"),t&&Ex(h,n,o,t,r),{canvas:u,logicalW:s,logicalH:a}):null};var vr=n=>{if(Ke(n)!=="scroll")return null;let e=typeof n.scrollSpeed=="number"&&Number.isFinite(n.scrollSpeed)?n.scrollSpeed:50;return{direction:n.scrollDirection==="right-to-left"?"right-to-left":"left-to-right",speed:e,enabled:n.scrollEnabled===void 0?!0:n.scrollEnabled===!0}},Cx=(n,e,t,r)=>{let o=t+e,i=n.direction==="left-to-right"?-e/2-t+r:e/2-r,s=n.direction==="left-to-right"?o:-o;return{copy1:i,copy2:i+s}},Ah=n=>{let e=vr(n.raw);return e?{target:n,viewWidth:n.dims.x,textTotalWidth:n.textTotalWidth,scrollSpeed:e.speed,scrollDirection:e.direction,scrollEnabled:e.enabled}:null},Mx=n=>`rgba(${Math.round(n.color[0]*255)},${Math.round(n.color[1]*255)},${Math.round(n.color[2]*255)},${n.color[3]})`,Nh=(n,e,t)=>{let r=vr(n.raw);if(!r||!r.enabled)return null;let o=n.dims.x,i=n.dims.y;if(!(o>0)||!(i>0))return null;let s=Math.max(1,e);if((o*s>8192||i*s>8192)&&(s=Math.max(1,Math.floor(Math.min(8192/o,8192/i))),o*s>8192||i*s>8192))return null;let a=Math.ceil(o*s),l=Math.ceil(i*s);if(!(a>0)||!(l>0))return null;let c=document.createElement("canvas");c.width=a,c.height=l;let u=c.getContext("2d");if(!u)return null;u.setTransform(s,0,0,s,a/2,l/2),u.textBaseline="alphabetic",u.textAlign="left",u.beginPath(),u.rect(-o/2,-i/2,o,i),u.clip();let h=n.textTotalWidth,{copy1:d,copy2:f}=Cx(r,o,h,t);for(let m of[d,f])u.save(),u.translate(m,0),Rx(u,n),u.restore();return{canvas:c,logicalW:o,logicalH:i}},Rx=(n,e)=>{let t=e.paintFirst==="stroke"?["stroke","fill"]:["fill","stroke"];for(let r of t)Px(n,e,r)},Px=(n,e,t)=>{let r=e.textLayout,o=e.textStyle,i=e.textStroke,s=e.raw,a=e.fillPaint,l=typeof s.fill=="string"?s.fill:a?.kind==="gradient"&&a.decl.stops.length?Mx(a.decl.stops[0]):"",c=s.vertical===!0,u=Number(s.charSpacing)||0,h=t==="stroke"&&Array.isArray(s.strokeDashArray)?s.strokeDashArray.filter(f=>typeof f=="number"&&Number.isFinite(f)):null;if(t==="fill"&&!l&&!r.lines.some(f=>f.charStyles.some(m=>typeof m?.fill=="string"))||t==="stroke"&&!i)return;h&&h.length&&(n.setLineDash(h),n.lineDashOffset=Number(s.strokeDashOffset)||0);let d=f=>{n.lineWidth=f.width,n.strokeStyle=f.color,n.lineJoin=typeof s.strokeLineJoin=="string"?s.strokeLineJoin:"miter",n.lineCap=typeof s.strokeLineCap=="string"?s.strokeLineCap:"butt",n.miterLimit=Number(s.strokeMiterLimit)||4};for(let f of r.lines){let m=-r.width/2+f.leftOffset,p=e.contentTopY+f.baseline,b=f.prefix?.width??0;if(f.prefix){let x=f.charStyles[0];if(t==="fill"){let g=typeof x?.fill=="string"&&x.fill?x.fill:l;g&&Tt(n,f,m,p,{fill:g})}else Tt(n,f,m,p,{stroke:Oe(i,x)})}if(c){let x=Yt(f,m,p,o,u);for(let g=0;g<x.length;g++){let y=f.charStyles[g];if(t==="fill"){let S=typeof y?.fill=="string"&&y.fill?y.fill:l;if(!S)continue;n.fillStyle=S}else{let S=Oe(i,y);if(!S||S.width<=0)continue;d(S)}let v=pn(o,y);n.font=Me(v,v.fontSize),Ut(n,x[g],t==="fill"?"fillText":"strokeText")}continue}if(h&&h.length){let x="",g=b,y="",v=null,S,w=C=>{if(!x)return;let T=v;T&&T.width>0&&(n.font=y,d(T),n.strokeText(x,m+g,p)),x="",C<f.boxes.length&&(g=f.boxes[C].left)},R=zt(s.textAlign),P=s.textAlign===fe.DISPERSE,E=eo(s.textAlign)&&f.graphemes.some(C=>oo.test(C));for(let C=0;C<f.graphemes.length;C++){let T=f.charStyles[C],M=pn(o,T),k=Me(M,M.fontSize),A=Oe(i,T),O=T?.fill??"",F=v;x&&(k!==y||A?.color!==F?.color||A?.width!==F?.width||O!==S)&&w(C),x||(y=k,v=A,S=O),x+=f.graphemes[C],(u||(R||P)&&/[ \t\r]/.test(f.graphemes[C])||E)&&w(C+1)}w(f.graphemes.length);continue}for(let x=0;x<f.graphemes.length;x++){let g=f.charStyles[x];if(t==="fill"){let S=typeof g?.fill=="string"&&g.fill?g.fill:l;if(!S)continue;n.fillStyle=S}else{let S=Oe(i,g);if(!S||S.width<=0)continue;d(S)}let y=pn(o,g);n.font=Me(y,y.fontSize);let v=m+f.boxes[x].left;t==="fill"?n.fillText(f.graphemes[x],v,p):n.strokeText(f.graphemes[x],v,p)}}};var Lh=(n,e)=>{let t=[],r=ki(n);r&&t.push({left:-r.logicalW/2,top:-r.logicalH/2,right:r.logicalW/2,bottom:r.logicalH/2});let o=n.raw;if(Array.isArray(o.texts)&&typeof o.renderSrc!="string"&&!xr(o)&&!qn(o)&&!Ge(o)&&!vr(o)?.enabled){let h=n.textLayout,d=Kn(String(o.text??""),h,o.texts,n.contentTopY,n.textStyle.fontSize);if(d&&Math.ceil(h.width+d.padX*2)<=8192&&Math.ceil(h.height+d.padY*2)<=8192){let f=d.inkBounds;t.push({left:f.left-2,top:f.top-2,right:f.right+2,bottom:f.bottom+2})}}if(!t.length)return e;let i=Bn(e),{left:s,top:a,right:l,bottom:c}=i,u=n.matrix;for(let h of t)for(let[d,f]of[[h.left,h.top],[h.right,h.top],[h.right,h.bottom],[h.left,h.bottom]]){let m=Q(u,d,f);s=Math.min(s,m.x),a=Math.min(a,m.y),l=Math.max(l,m.x),c=Math.max(c,m.y)}return{tl:{x:s,y:a},tr:{x:l,y:a},br:{x:l,y:c},bl:{x:s,y:c}}};var Qn=n=>{if(!n||typeof n!="object")return null;let e=n;if(typeof e.rows!="number"||typeof e.cols!="number"||!Array.isArray(e.pieces)||e.pieces.length===0)return null;let t=[];for(let r of e.pieces){if(!r||typeof r!="object")continue;let o=r;typeof o.row!="number"||typeof o.col!="number"||t.push({id:r.id,row:o.row,col:o.col,rowSpan:r.rowSpan,colSpan:r.colSpan})}return t.length>0?{rows:e.rows,cols:e.cols,pieces:t}:null},Sl=(n,e)=>{let{rows:t,cols:r,pieces:o}=n,i=Math.max(0,e.width-e.groupPadding*2),s=Math.max(0,e.height-e.groupPadding*2),a=e.hGap*Math.max(0,r-1),l=e.vGap*Math.max(0,t-1),c=r>0?(i-a)/r:0,u=t>0?(s-l)/t:0,h=c+e.hGap,d=u+e.vGap,f=(r-1)/2,m=(t-1)/2;return o.map(p=>{let b=p.colSpan??1,x=p.rowSpan??1,g=Math.max(c*b+e.hGap*(b-1),0),y=Math.max(u*x+e.vGap*(x-1),0),v=p.col+(b-1)/2,S=p.row+(x-1)/2;return{w:g,h:y,cx:(v-f)*h,cy:(S-m)*d}})},kx=(n,e)=>e&&e.naturalWidth&&e.naturalHeight?{w:e.naturalWidth,h:e.naturalHeight}:{w:n?.width??0,h:n?.height??0},Ih=(n,e,t)=>{let r=typeof e.widthRatio=="number"&&isFinite(e.widthRatio)&&e.widthRatio>0?e.widthRatio:1,o=typeof e.heightRatio=="number"&&isFinite(e.heightRatio)&&e.heightRatio>0?e.heightRatio:1,i=r!==1,s=o!==1;if(!i&&!s||n.masks.length===0)return!1;let a=n.width||0,l=n.height||0;return i&&a&&(n.width=a*r,n.hGap*=r,n.groupPadding*=r),s&&l&&(n.height=l*o,n.vGap*=o,n.groupPadding*=o),n.masks.forEach((c,u)=>{let h=c.width||0,d=c.height||0,f=i?Math.max(h*r,1):h,m=s?Math.max(d*o,1):d,p=i?(c.left||0)*r:c.left,b=s?(c.top||0)*o:c.top;if(c.left=p,c.top=b,c.width=f,c.height=m,c.clip){let x=i&&h?f/h:1,g=s&&d?m/d:1,y=t?.[u]??kx(c.clip,null);if(y.w&&y.h){let v=Math.max(h/y.w,d/y.h),S=Math.max(f/y.w,m/y.h),w=c.clip.scaleX||c.clip.scaleY||1,R=v?w/v:1,P=S*(R||1);c.clip.scaleX=P,c.clip.scaleY=P}c.clip.clipX=(c.clip.clipX||0)*x,c.clip.clipY=(c.clip.clipY||0)*g}}),!0},Bi=n=>{let e=n.clipImage;if(!e||typeof e!="object"||typeof e.src!="string")return null;let t=e;return{scaleX:t.scaleX??1,scaleY:t.scaleY??1,clipX:t.clipX??0,clipY:t.clipY??0,width:t.width??0,height:t.height??0}};var Ax=(n,e)=>{if(typeof n.colStart!="number"||typeof n.colEnd!="number"||e<=0)return 0;let t=0;return n.colStart>0&&(t+=1),n.colEnd<e-1&&(t+=1),t},Nx=(n,e)=>{if(typeof n.rowStart!="number"||typeof n.rowEnd!="number"||e<=0)return 0;let t=0;return n.rowStart>0&&(t+=1),n.rowEnd<e-1&&(t+=1),t},Lt=n=>({left:n.left-n.width/2,right:n.left+n.width/2,top:n.top-n.height/2,bottom:n.top+n.height/2}),wr=(n,e,t,r)=>{if(!n.clip)return;let o=n.width,i=n.height,s=e?o/e:1,a=t?i/t:1,l=r??{w:n.clip.width,h:n.clip.height};if(l.w&&l.h){let c=Math.max(e/l.w,t/l.h),u=Math.max(o/l.w,i/l.h),h=n.clip.scaleX||n.clip.scaleY||1,d=c?h/c:1,f=u*(d||1);n.clip.scaleX=f,n.clip.scaleY=f}n.clip.clipX=(n.clip.clipX||0)*s,n.clip.clipY=(n.clip.clipY||0)*a},_h=(n,e,t,r="right",o)=>{let i=n.masks[e];if(!i)return!1;let s=Math.max(n.innerRadius+1,12);if(t<=s||!n.layoutWidth)return!1;let a=n.groupPadding||0,l=Math.max(0,n.layoutWidth-a*2),c=1,u=i.width||0,h=i.height||0;if(!l||!u)return!1;let d=n.innerRadius+1,f=Ax(i,n.cols)*d;if(t<f)return!1;let m=l-f,p=Math.min(t,Math.max(c,m)),b=Lt(i),x=n.hGap||0,g=[],y=null,v=5,S=.3;n.masks.forEach((W,V)=>{if(V===e)return;let Y=Lt(W),re=Math.min(b.bottom,Y.bottom)-Math.max(b.top,Y.top);if(!(re<=0||re<Math.min(i.height,W.height)*S))if(r==="right"){if(Y.left<=i.left)return;let te=Y.left;y===null||te<y-v?(y=te,g.length=0,g.push(V)):Math.abs(te-y)<=v&&g.push(V)}else{if(Y.right>=i.left)return;let te=Y.right;y===null||te>y+v?(y=te,g.length=0,g.push(V)):Math.abs(te-y)<=v&&g.push(V)}});let w=W=>o?.[W]??null;if(!g.length){let W=l/2,V=r==="right"?W-b.left:b.right+W,Y=Math.max(s,Math.min(p,Math.max(s,V)));return Y===u?!1:(i.left=r==="right"?b.left+Y/2:b.right-Y/2,i.width=Y,wr(i,u,h,w(e)),!0)}let R=1/0,P=-1/0;for(let W of g){let V=Lt(n.masks[W]);V.left<R&&(R=V.left),V.right>P&&(P=V.right)}let E=r==="right"?b.left:b.right,C=W=>{let V=Lt(n.masks[W]);return r==="right"?V.right:V.left},T=1/0;for(let W of g){let V=(r==="right"?C(W)-E:E-C(W))-x-s;V<T&&(T=V)}let M=Math.max(s,Math.min(p,Math.max(s,T))),k=r==="right"?E+M:E-M;for(let W of g)if((r==="right"?C(W)-k:k-C(W))-x<s-1e-6)return!1;if(M<=0)return!1;i.left=r==="right"?E+M/2:E-M/2,i.width=M;let A=new Map;A.set(e,{width:u,height:h});for(let W of g){let V=n.masks[W];A.set(W,{width:V.width,height:V.height});let Y=C(W);r==="right"?(V.width=Y-k-x,V.left=(k+x+Y)/2):(V.width=k-x-Y,V.left=(k-x+Y)/2)}for(let W of[e,...g]){let V=A.get(W);wr(n.masks[W],V.width,V.height,w(W))}let O=Lt(i),F=O.left,H=O.right,z=Lt(n.masks[g[0]]),_=z.left,D=z.right,I=r==="right"?b.right:b.left,B=r==="right"?H:F,G=new Set(g),X=typeof i.colStart=="number"&&typeof i.colEnd=="number"?{colStart:i.colStart,colEnd:i.colEnd}:null,U=n.masks[g[0]],q=U&&typeof U.colStart=="number"&&typeof U.colEnd=="number"?{colStart:U.colStart,colEnd:U.colEnd}:null,j=n.cols>0&&!!X&&!!q,Z=(W,V,Y)=>{let re=n.masks[W],te=re.width,de=re.height,Pe=Math.max(c,Y-V);re.left=(V+Y)/2,re.width=Pe,wr(re,te,de,w(W))};return n.masks.forEach((W,V)=>{if(V===e||G.has(V))return;let Y=Lt(W),re=Y.left,te=Y.right;if(j&&X&&q&&typeof W.colStart=="number"&&typeof W.colEnd=="number"){if(W.colStart===X.colStart&&W.colEnd===X.colEnd){Z(V,F,H);return}if(W.colStart===q.colStart&&W.colEnd===q.colEnd){Z(V,_,D);return}let Ee=r==="right"?X.colEnd+1:X.colStart,ue=W.colStart===Ee,ge=W.colEnd+1===Ee;if(!ue&&!ge)return;let pe=ue?B+(r==="right"?x:0):re,Te=ge?B-(r==="left"?x:0):te;if(Te-pe<=0)return;Z(V,pe,Te);return}let de=.5;if(Math.abs(re-b.left)<de&&Math.abs(te-b.right)<de){Z(V,F,H);return}if(Math.abs(re-R)<de&&Math.abs(te-P)<de){Z(V,_,D);return}let Pe=Math.abs(re-I)<de,De=Math.abs(te-I)<de;if(!Pe&&!De)return;let nt=Pe?B:re,ke=De?B:te;ke-nt<=0||Z(V,nt,ke)}),i.width!==u},Dh=(n,e,t,r="bottom",o)=>{let i=n.masks[e];if(!i)return!1;let s=Math.max(n.innerRadius+1,12);if(t<=s||!n.layoutHeight)return!1;let a=n.groupPadding||0,l=Math.max(0,n.layoutHeight-a*2),c=1,u=i.height||0,h=i.width||0;if(!l||!u)return!1;let d=n.innerRadius+1,f=Nx(i,n.rows)*d;if(t<f)return!1;let m=l-f,p=Math.min(t,Math.max(c,m)),b=Lt(i),x=n.vGap||0,g=-1,y=0,v=0,S=.3;n.masks.forEach((ue,ge)=>{if(ge===e)return;let pe=Lt(ue),Te=Math.min(b.right,pe.right)-Math.max(b.left,pe.left);if(!(Te<=0||Te<Math.min(i.width,ue.width)*S))if(r==="bottom"){if(pe.top<=i.top)return;(g===-1||pe.top<y)&&(g=ge,y=pe.top,v=pe.bottom)}else{if(pe.bottom>=i.top)return;(g===-1||pe.bottom>v)&&(g=ge,y=pe.top,v=pe.bottom)}});let w=ue=>o?.[ue]??null;if(g===-1){let ue=l/2,ge=r==="bottom"?ue-b.top:b.bottom+ue,pe=Math.max(s,Math.min(p,Math.max(s,ge)));return pe===u?!1:(i.top=r==="bottom"?b.top+pe/2:b.bottom-pe/2,i.height=pe,wr(i,h,u,w(e)),!0)}let R=r==="bottom"?b.top:y,P=r==="bottom"?v:b.bottom,E=P-R,C=Math.max(s,E-x-s),T=Math.max(s,Math.min(p,C)),M=E-x-T;if(M<s){let ue=E-x-s;if(ue<s||(T=Math.max(s,Math.min(p,ue)),M=E-x-T,M<s))return!1}if(T<=0||M<=0)return!1;let k,A;r==="bottom"?(k=R+T/2,A=P-M/2):(A=R+M/2,k=P-T/2);let O=new Map;O.set(e,{width:h,height:u}),O.set(g,{width:n.masks[g].width,height:n.masks[g].height}),i.top=k,i.height=T;let F=n.masks[g];F.top=A,F.height=M;for(let ue of[e,g]){let ge=O.get(ue);wr(n.masks[ue],ge.width,ge.height,w(ue))}let H=k-T/2,z=k+T/2,_=A-M/2,D=A+M/2,I=r==="bottom",B=I?H:_,G=I?z:D,X=I?_:H,U=I?D:z,q=I?b.top:y,j=I?b.bottom:v,Z=I?y:b.top,W=I?v:b.bottom,V=r==="bottom"?b.bottom:b.top,Y=r==="bottom"?z:H,re=typeof i.rowStart=="number"&&typeof i.rowEnd=="number"?{rowStart:i.rowStart,rowEnd:i.rowEnd}:null,te=n.masks[g],de=te&&typeof te.rowStart=="number"&&typeof te.rowEnd=="number"?{rowStart:te.rowStart,rowEnd:te.rowEnd}:null,Pe=n.rows>0&&!!re&&!!de,De=Pe&&re&&de?re.rowStart<=de.rowStart?re:de:null,nt=Pe&&re&&de?De===re?de:re:null,ke=De?De.rowEnd+1:void 0,Ee=(ue,ge,pe)=>{let Te=n.masks[ue],rt=Te.width,qe=Te.height,Ye=Math.max(c,pe-ge);Te.top=(ge+pe)/2,Te.height=Ye,wr(Te,rt,qe,w(ue))};return n.masks.forEach((ue,ge)=>{if(ge===e||ge===g)return;let pe=Lt(ue),Te=pe.top,rt=pe.bottom;if(Pe&&De&&nt&&ke!==void 0&&typeof ue.rowStart=="number"&&typeof ue.rowEnd=="number"){if(ue.rowStart===De.rowStart&&ue.rowEnd===De.rowEnd){Ee(ge,B,G);return}if(ue.rowStart===nt.rowStart&&ue.rowEnd===nt.rowEnd){Ee(ge,X,U);return}let yt=ue.rowStart===ke,St=ue.rowEnd+1===ke;if(!yt&&!St)return;let _n=yt?Y+(r==="bottom"?x:0):Te,Dn=St?Y-(r==="top"?x:0):rt;if(Dn-_n<=0)return;Ee(ge,_n,Dn);return}let qe=.5;if(Math.abs(Te-q)<qe&&Math.abs(rt-j)<qe){Ee(ge,B,G);return}if(Math.abs(Te-Z)<qe&&Math.abs(rt-W)<qe){Ee(ge,X,U);return}let Ye=Math.abs(Te-V)<qe,bt=Math.abs(rt-V)<qe;if(!Ye&&!bt)return;let xt=Ye?Y:Te,gt=bt?Y:rt;gt-xt<=0||Ee(ge,xt,gt)}),i.height!==u};var Fh=(n,e,t=[])=>{let r=n.layoutConfig,o=r&&typeof r=="object"&&Array.isArray(r.pieces)?r.pieces:[],i=e.map(c=>({left:c.left??0,top:c.top??0,width:c.width??0,height:c.height??0,clip:Bi(c)})),s=e.map((c,u)=>{let h=c.clipImage;if(!h||typeof h.src!="string")return null;let d=t[u];return d&&d.naturalWidth&&d.naturalHeight?{w:d.naturalWidth,h:d.naturalHeight}:{w:h.width??0,h:h.height??0}});o.forEach((c,u)=>{let h=i[u];!h||typeof c.col!="number"||typeof c.row!="number"||(h.colStart=c.col,h.colEnd=c.col+(c.colSpan??1)-1,h.rowStart=c.row,h.rowEnd=c.row+(c.rowSpan??1)-1)});let a={layoutWidth:n.layoutWidth??600,layoutHeight:n.layoutHeight??600,hGap:n.hGap??12,vGap:n.vGap??12,groupPadding:n.groupPadding??0,innerRadius:n.innerRadius??12,cols:(r&&typeof r.cols=="number"?r.cols:0)||1,rows:(r&&typeof r.rows=="number"?r.rows:0)||1,masks:i},l=o.filter(c=>typeof c.row=="number"&&typeof c.col=="number").map(c=>({row:c.row,col:c.col,rowSpan:c.rowSpan,colSpan:c.colSpan}));return{state:a,pieces:l,clipSizes:s}},Oh=(n,e,t)=>{if(e<=1)return null;let r=[];n.forEach((o,i)=>{let s=o.col,a=o.col+(o.colSpan??1)-1;s===t&&(o.colSpan??1)===1?r.push(i):t>=s&&t<=a&&(o.colSpan=(o.colSpan??1)-1)}),r.forEach(o=>{let i=n[o],s=t>0?t-1:t+1,a=n.find((l,c)=>!r.includes(c)&&l.row===i.row&&l.col<=s&&l.col+(l.colSpan??1)-1>=s);a&&(a.colSpan=(a.colSpan??1)+1,a.col>t&&(a.col=t))}),n.forEach(o=>{o.col>t&&(o.col-=1)});for(let o of[...r].sort((i,s)=>s-i))n.splice(o,1);return{removed:r}},Bh=(n,e,t)=>{if(e<=1)return null;let r=[];n.forEach((o,i)=>{let s=o.row,a=o.row+(o.rowSpan??1)-1;s===t&&(o.rowSpan??1)===1?r.push(i):t>=s&&t<=a&&(o.rowSpan=(o.rowSpan??1)-1)}),r.forEach(o=>{let i=n[o],s=t>0?t-1:t+1,a=n.find((l,c)=>!r.includes(c)&&l.col===i.col&&l.row<=s&&l.row+(l.rowSpan??1)-1>=s);a&&(a.rowSpan=(a.rowSpan??1)+1,a.row>t&&(a.row=t))}),n.forEach(o=>{o.row>t&&(o.row-=1)});for(let o of[...r].sort((i,s)=>s-i))n.splice(o,1);return{removed:r}},Wh=(n,e)=>{let t=n.findIndex(h=>h.row===e.row&&h.col===e.col);if(t===-1||n.length<=1)return null;let r=n[t],o=r.row,i=r.col,s=r.rowSpan??1,a=r.colSpan??1,l=[],c="v",u=n.filter(h=>h!==r&&h.row+(h.rowSpan??1)===o&&h.col>=i&&h.col+(h.colSpan??1)<=i+a);if(u.reduce((h,d)=>h+(d.colSpan??1),0)===a)l=u,c="v";else{let h=n.filter(d=>d!==r&&d.row===o+s&&d.col>=i&&d.col+(d.colSpan??1)<=i+a);if(h.reduce((d,f)=>d+(f.colSpan??1),0)===a)l=h,c="v",l.forEach(d=>d.row=o);else{let d=n.filter(f=>f!==r&&f.col+(f.colSpan??1)===i&&f.row>=o&&f.row+(f.rowSpan??1)<=o+s);if(d.reduce((f,m)=>f+(m.rowSpan??1),0)===s)l=d,c="h";else{let f=n.filter(m=>m!==r&&m.col===i+a&&m.row>=o&&m.row+(m.rowSpan??1)<=o+s);f.reduce((m,p)=>m+(p.rowSpan??1),0)===s&&(l=f,c="h",l.forEach(m=>m.col=i))}}}return l.length>0&&l.forEach(h=>{c==="v"?h.rowSpan=(h.rowSpan??1)+s:h.colSpan=(h.colSpan??1)+a}),n.splice(t,1),{removed:[t]}};var It=n=>{let e=new Map;for(let t of n)e.set(`${t.row},${t.col}`,t);for(let t of n){if(t.isMerged)continue;let r=t.colspan??1,o=t.rowspan??1;if(!(r<=1&&o<=1))for(let i=t.row;i<t.row+o;i++)for(let s=t.col;s<t.col+r;s++){if(i===t.row&&s===t.col)continue;let a=`${i},${s}`;e.has(a)||e.set(a,{row:i,col:s,isMerged:!0,mergeParent:{row:t.row,col:t.col}})}}return e},we=(n,e,t)=>n.get(`${e},${t}`),lt=(n,e,t)=>{let r=we(n,e,t);return r?.isMerged&&r.mergeParent?{row:r.mergeParent.row,col:r.mergeParent.col}:{row:e,col:t}},Cr=n=>{let e=Array.isArray(n.cellData)?n.cellData:null;if(e)return e;let t=[];return n.cellData=t,t},Mr=n=>n.rows??3,Hi=n=>n.cols??3,wl=n=>n.minCellHeight??40,vl=n=>n.minCellWidth??40,Tl=n=>{let e=Hi(n),t=Array.isArray(n.columnWidths)?n.columnWidths:[],r=typeof t[0]=="number"?t[0]:n.cellWidth??100,o=t.slice(0,e).map(i=>typeof i=="number"&&i>0?i:r);for(;o.length<e;)o.push(r);return o},fo=(n,e)=>{let t=Array.isArray(n.columnWidths)?n.columnWidths:null;t?(t.length=0,t.push(...e)):n.columnWidths=e},Xh=(n,e,t,r)=>{let o=Mr(n),i=wl(n),s=Array.isArray(n.rowHeights)?n.rowHeights:Array.from({length:o},()=>i);for(;s.length<o;)s.push(i);r!==void 0?s.splice(e,t,r):s.splice(e,t),n.rowHeights=s},zh=(n,e,t,r)=>{let o=Mr(n),i=Array.isArray(n.manualRowHeights)?n.manualRowHeights:[],s=[];for(let a=0;a<Math.max(o,i.length);a++)s.push(typeof i[a]=="number"?i[a]:null);r!==void 0?s.splice(e,t,r):s.splice(e,t),n.manualRowHeights=s},mo=(n,e,t)=>{let r=Tl(n);e<0||e>=r.length||(r[e]=Math.max(vl(n),t),fo(n,r))},po=(n,e,t)=>{let r=Mr(n);if(e<0||e>=r)return;let o=Array.isArray(n.manualRowHeights)?n.manualRowHeights:[],i=[];for(let s=0;s<r;s++)i.push(typeof o[s]=="number"?o[s]:null);i[e]=Math.max(wl(n),t),n.manualRowHeights=i},El=(n,e,t,r,o)=>{let i=!0;for(;i;){i=!1;for(let s=e;s<=t;s++)for(let a=r;a<=o;a++){let l=we(n,s,a);if(l){if(l.isMerged&&l.mergeParent){let c=we(n,l.mergeParent.row,l.mergeParent.col);if(c){l.mergeParent.row<e&&(e=l.mergeParent.row,i=!0),l.mergeParent.col<r&&(r=l.mergeParent.col,i=!0);let u=l.mergeParent.row+(c.rowspan??1)-1,h=l.mergeParent.col+(c.colspan??1)-1;u>t&&(t=u,i=!0),h>o&&(o=h,i=!0)}}(l.colspan??1)>1&&a+(l.colspan??1)-1>o&&(o=a+(l.colspan??1)-1,i=!0),(l.rowspan??1)>1&&s+(l.rowspan??1)-1>t&&(t=s+(l.rowspan??1)-1,i=!0)}}}return{r1:e,r2:t,c1:r,c2:o}},Lx=(n,e,t)=>{for(let r=t.r1;r<=t.r2;r++)for(let o=t.c1;o<=t.c2;o++){let i=we(e,r,o);i||(i={row:r,col:o},n.push(i),e.set(`${r},${o}`,i)),i.colspan=1,i.rowspan=1,i.isMerged=!1,i.mergeParent=null}},Ix=(n,e)=>{let t=[];for(let r=e.r1;r<=e.r2;r++)for(let o=e.c1;o<=e.c2;o++){let i=we(n,r,o)?.text;i&&i.trim()&&t.push(i.trim())}return t.join(`
|
|
7
|
-
`)},Cl=(n,e,t,r,o,i)=>{for(let s=t;s<t+o;s++)for(let a=r;a<r+i;a++){if(s===t&&a===r)continue;let l=we(e,s,a);l||(l={row:s,col:a},n.push(l),e.set(`${s},${a}`,l)),l.isMerged=!0,l.mergeParent={row:t,col:r},l.text=""}},bo=(n,e,t,r,o)=>{let i=Cr(n),s=It(i),a=El(s,Math.min(e,r),Math.max(e,r),Math.min(t,o),Math.max(t,o));Lx(i,s,a);let l=we(s,a.r1,a.c1);return l&&(l.text=Ix(s,a),l.colspan=a.c2-a.c1+1,l.rowspan=a.r2-a.r1+1,Cl(i,s,a.r1,a.c1,l.rowspan,l.colspan)),a},xo=(n,e,t)=>{let r=It(Cr(n)),o=we(r,e,t);if(!o||(o.colspan??1)===1&&(o.rowspan??1)===1)return!1;let i=o.colspan??1,s=o.rowspan??1;o.colspan=1,o.rowspan=1;for(let a=e;a<e+s;a++)for(let l=t;l<t+i;l++){if(a===e&&l===t)continue;let c=we(r,a,l);c&&(c.isMerged=!1,c.mergeParent=null)}return!0},Yh=n=>({cellFill:n.cellFill,textFill:n.textFill,fontSize:n.fontSize,fontWeight:n.fontWeight,fontFamily:n.fontFamily,fontStyle:n.fontStyle,textAlign:n.textAlign}),Uh=(n,e,t,r)=>({row:t,col:r,fill:n?.fill??e.cellFill,stroke:n?.stroke,text:"",textFill:n?.textFill??e.textFill,fontSize:n?.fontSize??e.fontSize,fontWeight:n?.fontWeight??e.fontWeight,fontFamily:n?.fontFamily??e.fontFamily,fontStyle:n?.fontStyle??e.fontStyle,textAlign:n?.textAlign??e.textAlign}),Gi=(n,e,t,r)=>{for(let o of n)o[e]>=t&&(o[e]+=r),o.isMerged&&o.mergeParent&&o.mergeParent[e]>=t&&(o.mergeParent[e]+=r)},$h=(n,e,t)=>{let r=e==="row"?"rowspan":"colspan",o=[];for(let i of n){let s=i[r]??1;if(s>1){let a=i[e];t>a&&t<=a+s-1&&o.push(i)}}return o},go=(n,e)=>{let t=Mr(n),r=Hi(n),o=Cr(n),i=It(o),s=Math.max(0,Math.min(e,t)),a=$h(o,"row",s),l=s>0?s-1:s<t?s:null;Gi(o,"row",s,1);for(let u=0;u<r;u++){let h=l!==null?we(i,l,u):void 0;o.push(Uh(h,Yh(n),s,u))}Xh(n,s,0,wl(n)),zh(n,s,0,null),n.rows=t+1;let c=It(o);for(let u of a)u.rowspan=(u.rowspan??1)+1,Cl(o,c,u.row,u.col,u.rowspan??1,u.colspan??1)},Ml=(n,e)=>{let t=Mr(n);if(t<=1)return!1;let r=Math.max(0,Math.min(e,t-1)),o=Cr(n),i=0;for(let s of o)s.row!==r&&(o[i++]=s);return o.length=i,Gi(o,"row",r+1,-1),Xh(n,r,1),zh(n,r,1),n.rows=t-1,!0},yo=(n,e)=>{let t=Mr(n),r=Hi(n),o=Cr(n),i=It(o),s=Tl(n),a=Math.max(0,Math.min(e,r)),l=$h(o,"col",a),c=a>0?a-1:a<r?a:null;Gi(o,"col",a,1);for(let d=0;d<t;d++){let f=c!==null?we(i,d,c):void 0;o.push(Uh(f,Yh(n),d,a))}n.cols=r+1;let u=Math.max(vl(n),c!==null?s[c]:vl(n));s.splice(a,0,u),fo(n,s);let h=It(o);for(let d of l)d.colspan=(d.colspan??1)+1,Cl(o,h,d.row,d.col,d.rowspan??1,d.colspan??1)},Rl=(n,e)=>{let t=Hi(n);if(t<=1)return!1;let r=Math.max(0,Math.min(e,t-1)),o=Cr(n),i=Tl(n),s=0;for(let a of o)a.col!==r&&(o[s++]=a);return o.length=s,Gi(o,"col",r+1,-1),n.cols=t-1,i.splice(r,1),fo(n,i),!0},Zn=n=>n.columnWidths.reduce((e,t)=>e+t,0)+(n.cols-1)*n.cellSpacing,Jn=n=>n.rowHeights.reduce((e,t)=>e+t,0)+(n.rows-1)*n.cellSpacing,Tr=(n,e,t)=>{let r=0;for(let o=0;o<n.length;o++){if(t>=r&&t<r+n[o])return o;r+=n[o]+e}return-1},Er=(n,e,t)=>{let r=e==="col"?n.columnWidths:n.rowHeights,o=e==="col"?Zn(n):Jn(n),i=0;for(let s=0;s<t&&s<r.length;s++)i+=r[s]+n.cellSpacing;return i-n.cellSpacing/2-o/2},Hh=(n,e,t,r,o,i)=>{let s=e/2,a=0;for(let l=0;l<=n.length;l++){let c=l>0&&l<n.length,u=a-s;if(c&&Math.abs(t-u)<r&&o>=0&&o<=i)return l;l<n.length&&(a+=n[l]+e)}return-1},Gh=(n,e,t,r)=>{if(e==="col"){let i=we(n,r,t-1);if(!i)return!1;if(i.isMerged&&i.mergeParent){let s=we(n,i.mergeParent.row,i.mergeParent.col);if(s&&s.col+(s.colspan??1)>t)return!0}else if((i.colspan??1)>1)return!0;return!1}let o=we(n,t-1,r);if(!o)return!1;if(o.isMerged&&o.mergeParent){let i=we(n,o.mergeParent.row,o.mergeParent.col);if(i&&i.row+(i.rowspan??1)>t)return!0}else if((o.rowspan??1)>1)return!0;return!1},Pl=(n,e,t,r,o,i)=>{let s=t+Zn(n)/2,a=r+Jn(n)/2,l=o,c=i,u=Tr(n.rowHeights,n.cellSpacing,a),h=Tr(n.columnWidths,n.cellSpacing,s),d=Hh(n.columnWidths,n.cellSpacing,s,l,a,Jn(n));if(d>0&&u>=0&&!Gh(e,"col",d,u))return{type:"col",index:d,position:Er(n,"col",d)};let f=Hh(n.rowHeights,n.cellSpacing,a,c,s,Zn(n));return f>0&&h>=0&&!Gh(e,"row",f,h)?{type:"row",index:f,position:Er(n,"row",f)}:null},jh=(n,e,t,r)=>{let o=t+Zn(n)/2,i=r+Jn(n)/2,s=Tr(n.columnWidths,n.cellSpacing,o);if(s<0)return null;let a=Tr(n.rowHeights,n.cellSpacing,i);return a<0?null:lt(e,a,s)},Vh=(n,e,t,r,o)=>{let i=o.indicatorOffset??15,s=o.indicatorRadius??8,a=Jn(n)/2,l=Zn(n)/2;for(let u=1;u<=n.cols;u++){let h=Er(n,"col",u),d=s/(Math.abs(o.scaleX)*o.zoom);if(Math.hypot(t-h,r-(-a-i))<=d)return{border:{type:"col",index:u,position:h},inCircle:!0}}for(let u=1;u<=n.rows;u++){let h=Er(n,"row",u),d=s/(Math.abs(o.scaleY)*o.zoom);if(Math.hypot(t-(-l-i),r-h)<=d)return{border:{type:"row",index:u,position:h},inCircle:!0}}let c=Pl(n,e,t,r,o.thresholdX,o.thresholdY);return c?{border:c,inCircle:!1}:null},So=(n,e)=>{let t=0;for(let l=0;l<e.c1;l++)t+=n.columnWidths[l]+n.cellSpacing;let r=0;for(let l=e.c1;l<=e.c2;l++)r+=n.columnWidths[l]+(l<e.c2?n.cellSpacing:0);let o=0;for(let l=0;l<e.r1;l++)o+=n.rowHeights[l]+n.cellSpacing;let i=0;for(let l=e.r1;l<=e.r2;l++)i+=n.rowHeights[l]+(l<e.r2?n.cellSpacing:0);let s=Zn(n)/2,a=Jn(n)/2;return{left:t-s,top:o-a,width:r,height:i}},vo=n=>{let e=new Set,t=[];for(let r of n){let o=`${r.row},${r.col}`;e.has(o)||(e.add(o),t.push(r))}return t},bn=(n,e,t)=>vo((()=>{let r=[];for(let o=Math.min(e.row,t.row);o<=Math.max(e.row,t.row);o++)for(let i=Math.min(e.col,t.col);i<=Math.max(e.col,t.col);i++)r.push(lt(n,o,i));return r})()),Xi=(n,e,t)=>{let r=[];for(let o=0;o<e;o++){let i=lt(n,o,t);i.col===t&&r.push(i)}return vo(r)},zi=(n,e,t)=>{let r=[];for(let o=0;o<e;o++){let i=lt(n,t,o);i.row===t&&r.push(i)}return vo(r)},wo=(n,e,t)=>{let r=[];for(let o=0;o<e;o++)for(let i=0;i<t;i++)r.push(lt(n,o,i));return vo(r)},Xe=n=>{if(!n.length)return null;let e=1/0,t=-1/0,r=1/0,o=-1/0;for(let i of n)e>i.row&&(e=i.row),t<i.row&&(t=i.row),r>i.col&&(r=i.col),o<i.col&&(o=i.col);return{r1:e,r2:t,c1:r,c2:o}},Yi=(n,e,t,r)=>{let o=[];for(let c of n){let u=r==="row"?c.row:c.col;if(u===t)continue;let h=u>t?u-1:u;o.push(r==="row"?{row:h,col:c.col}:{row:c.row,col:h})}let i=vo(o);if(!i.length)return null;if(!e)return{cells:i,range:null};let s=r==="row"?e.r1:e.c1,a=r==="row"?e.r2:e.c2,l;if(s===t&&a===t)l=Xe(i)??e;else{let c=s>t?s-1:s,u=a>t?a-1:a===t?t-1:a;l=r==="row"?{r1:c,r2:u,c1:e.c1,c2:e.c2}:{r1:e.r1,r2:e.r2,c1:c,c2:u}}return{cells:i,range:l}},qh=(n,e,t,r)=>Math.abs(e-n)>=.5||Math.abs(t)<=1?0:Math.sign(t)*Math.min(1.5,Math.abs(t)*.1)/r,_x=["ew","nwse","ns","nesw"],Kh=(n,e)=>{let t=e==="col"?0:2,r=(n%180+180)%180,o=Math.round(r/45)%4;return`${_x[(t+o)%4]}-resize`};var Wi=(n,e)=>{let t=Math.abs(n)*Math.max(e,1e-6);return t>1e-6?20/t:20},Qh=(n,e,t,r,o,i={x:1,y:1},s=1)=>{if(o<-t/2&&o>=-t/2-Wi(i.y,s)){let a=Tr(n.columnWidths,n.cellSpacing,r+Zn(n)/2);if(a>=0)return{kind:"col-strip",col:a}}if(r<-e/2&&r>=-e/2-Wi(i.x,s)){let a=Tr(n.rowHeights,n.cellSpacing,o+Jn(n)/2);if(a>=0)return{kind:"row-strip",row:a}}return null},Zh=(n,e,t,r,o={x:1,y:1},i=1)=>{let s=Wi(o.x,i),a=Wi(o.y,i);return t>=-n/2-s&&t<-n/2&&r>=-e/2-a&&r<-e/2};var Jh=(n,e,t,r={x:1,y:1},o=1)=>{let i=l=>Math.max(Math.abs(l)*Math.max(o,1e-6),1e-6),s=12/i(r.x),a=12/i(r.y);return Math.abs(e-(n.left+n.width))<=s&&Math.abs(t-(n.top+n.height))<=a},Rr=(n,e)=>{let t=new Set,r=new Set;for(let o of e){let i=lt(n,o.row,o.col),s=we(n,i.row,i.col),a=s?.rowspan??1,l=s?.colspan??1;for(let c=i.row;c<i.row+a;c++)t.add(c);for(let c=i.col;c<i.col+l;c++)r.add(c)}return{rows:t,cols:r}};var Ui=14,ed=(n,e,t)=>{let r=[0];for(let o=0;o<n-1;o++)r.push(r[o]+e[o]+t);return r},kl=(n,e,t,r)=>{let o=0;for(let i=0;i<e;i++)o+=t[n+i]??0,i>0&&(o+=r);return o},To=(n,e,t)=>{let r=n.rows??3,o=n.cols??3,i=Array.isArray(n.columnWidths)?n.columnWidths:[],s=i[0]??100,a=Array.from({length:o},(_,D)=>i[D]??s),l=n.minCellHeight??40,c=n.cellPadding??8,u=n.cellSpacing??0,h=n.cellStrokeWidth??1,d=n.cellFill,f=n.cellStroke,m=n.textFill,p=n.fontFamily||"仓耳小丸子",b=Array.isArray(n.manualRowHeights)?n.manualRowHeights:[],x=Array.from({length:r},(_,D)=>typeof b[D]=="number"?b[D]:null),g=Array.isArray(n.cellData)?n.cellData:[],y=It(g),v=new Map;for(let _ of g){if(_.isMerged)continue;let D=Math.max(0,kl(_.col,_.colspan??1,a,u)-c*2);v.set(`${_.row},${_.col}`,{layout:jn(_.text??"",{fontFamily:_.fontFamily||p,fontSize:_.fontSize??Ui,fontWeight:_.fontWeight,fontStyle:_.fontStyle,lineHeight:1.16,charSpacing:0,textAlign:_.textAlign??fe.CENTER},{boxWidth:D,splitByGrapheme:!0,measure:e}),data:_})}let S=Ui*wi,w=[],R=[];for(let _=0;_<r;_++){let D=0;for(let X=0;X<o;X++){if(y.get(`${_},${X}`)?.isMerged)continue;let U=v.get(`${_},${X}`);D=Math.max(D,U?U.layout.height:S)}let I=x[_],B=D+c*2,G=I!==null?I:l;R.push(B),w.push(Math.max(G,B))}let P=a.reduce((_,D)=>_+D,0)+(o-1)*u,E=w.reduce((_,D)=>_+D,0)+(r-1)*u,C=ed(o,a,u),T=ed(r,w,u),M=typeof n.id=="string"&&n.id?n.id:"table",k=[];for(let _=0;_<r;_++)for(let D=0;D<o;D++){let I=y.get(`${_},${D}`);if(I?.isMerged)continue;let B=I?.colspan??1,G=I?.rowspan??1,X=kl(D,B,a,u),U=kl(_,G,w,u),q=C[D]-P/2+X/2,j=T[_]-E/2+U/2;k.push({type:"rect",id:`${M}-r${_}c${D}-rect`,left:q,top:j,width:X,height:U,originX:"center",originY:"center",fill:I?I.fill:d,stroke:I?I.stroke:f,strokeWidth:h,scaleX:1,scaleY:1,angle:0,opacity:1,visible:!0});let Z=I?v.get(`${_},${D}`):void 0,W=t?.hideTextCell!==void 0&&t.hideTextCell.row===_&&t.hideTextCell.col===D;if(Z&&!W&&(I?.text??"")!==""){let V=Z.layout.height,Y=I?.verticalAlign??"middle",re=j;Y==="top"?re=j-U/2+V/2+c:Y==="bottom"&&(re=j+U/2-V/2-c),k.push({type:"textbox",id:`${M}-r${_}c${D}-text`,left:q,top:re,width:Math.max(0,X-c*2),text:I?.text??"",fill:I?.textFill??m,fontFamily:I?.fontFamily||p,fontSize:I?.fontSize??Ui,fontWeight:I?.fontWeight,fontStyle:I?.fontStyle,textAlign:I?.textAlign??fe.CENTER,lineHeight:1.16,splitByGrapheme:!0,originX:"center",originY:"center",scaleX:1,scaleY:1,angle:0,opacity:1,visible:!0})}}let A=Math.max(l,Ui*wi+c*2),O=o*s+(o-1)*u+h,F=r*A+(r-1)*u+h,H=P+h,z=E+h;return{rowHeights:w,rowTextFloors:R,columnWidths:a,contentWidth:P,contentHeight:E,width:H,height:z,children:k,constructorDims:{width:O,height:F}}};var gn="WorkSpaceDrawType",Ar=new Set(["WorkSpaceDrawType","WorkSpaceClipType","WorkSpaceSafeType","WorkSpaceMaskType","WorkSpaceLineType","WorkSpaceShadowType"]),Dx=new Set(["WorkSpaceClipType","WorkSpaceSafeType"]),er=n=>{let e=n.raw?.id;return typeof e=="string"&&Dx.has(e)},$t=n=>n.isTextType&&typeof n.raw.renderSrc=="string",Eo=n=>{let e=n.fill;return typeof e!="string"||!e?1:Math.max(0,Math.min(1,oe(e)[3]))},Fx=new Set(["left","top","angle","scaleX","scaleY","skewX","skewY","flipX","flipY","originX","originY"]),Ox=new Set(["text","styles","paragraph","texts","textPath","path","pathStartOffset","pathSide","pathAlign","fontFamily","fontSize","fontWeight","fontStyle","lineHeight","charSpacing","textAlign","splitByGrapheme","vertical","direction","underline","overline","linethrough","textBackgroundColor","textDecorationThickness","textScaleX","textScaleY","width","height","minWidth","fill","stroke","strokeWidth","strokeUniform","paintFirst"]),Ll=n=>{for(let e in n)if(!Fx.has(e))return!1;return!0},ji=999999,Ze=n=>n.isReferenceLine,id=(n,e)=>({type:"ReferenceLine",id:`referenceline-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`,name:"ReferenceLine",axis:n,x1:n==="horizontal"?-ji:0,y1:n==="horizontal"?0:-ji,x2:n==="horizontal"?ji:0,y2:n==="horizontal"?0:ji,left:n==="horizontal"?0:e,top:n==="horizontal"?e:0,originX:"center",originY:"center",scaleX:1,scaleY:1,angle:0,opacity:1,visible:!1,selectable:!1,evented:!0,hasControls:!1,hasBorders:!1,stroke:"pink",fill:"pink",strokeWidth:1,padding:8,globalCompositeOperation:"difference",lockMovementX:n==="horizontal",lockMovementY:n==="vertical",hoverCursor:n==="horizontal"?"ns-resize":"ew-resize"}),Bx=["type","left","top","width","height","angle","scaleX","scaleY","skewX","skewY","flipX","flipY","originX","originY","strokeWidth","strokeUniform","fill","opacity","visible","src","crossOrigin","id","name"],ct=class{raw;syntheticOwner;_parentMatrix=null;_parentOpacity=1;_inIsolatedFBO=!1;_imageEl=null;_matrix=null;_aCoords=null;_bounds=null;_fillPaint;_animationOverride=null;constructor(e){this.raw={...e},ku(this.raw),this._typeKey=se(this.raw),this._isReferenceLine=this._typeKey===L.REFERENCELINE}_typeKey;get typeKey(){return this._typeKey}_isReferenceLine;get isReferenceLine(){return this._isReferenceLine}_strokeDecl;get strokeDecl(){return this._strokeDecl===void 0&&(this._strokeDecl=Si(this.raw)),this._strokeDecl}get imageEl(){return this._imageEl}set imageEl(e){this._imageEl=e,this.invalidateGeometryCache(),this._renderNotify?.()}invalidateGeometryCache(){this._matrix=null,this._aCoords=null,this._bounds=null}_renderNotify=null;markRenderDirty(){this._renderNotify?.()}set(e){Au(this.raw,e),Object.assign(this.raw,e),this.invalidateGeometryCache(),Ll(e)||(this._fillPaint=void 0,this._strokeDecl=void 0),"type"in e&&(this._typeKey=se(e),this._isReferenceLine=this._typeKey===L.REFERENCELINE),this._renderNotify?.()}setAnimationOverride(e){this._animationOverride=e,this.invalidateGeometryCache(),this._renderNotify?.()}get id(){return typeof this.raw.id=="string"?this.raw.id:""}get isImageType(){return dt.has(this.typeKey)}get isMaskType(){return ot.has(this.typeKey)}get isSolidType(){return Xn.has(this.typeKey)}get isTextType(){return rn.has(this.typeKey)}get isLineType(){return ft.has(this.typeKey)}get isShapeType(){return Gn.has(this.typeKey)}get visible(){return this.raw.visible!==!1}get fillPaint(){if(this._fillPaint===void 0){let e=Hn(this.raw.fill),t=e?null:di(this.raw.fill);e?this._fillPaint={kind:"gradient",decl:e}:t?this._fillPaint={kind:"pattern",decl:t}:this.raw.fill?this._fillPaint={kind:"solid",color:oe(this.raw.fill)}:this._fillPaint=null}return this._fillPaint}get drawColor(){let e=this.renderOpacity;if(this.isImageType)return[1,1,1,e];let t=oe(this.raw.fill);return[t[0],t[1],t[2],t[3]*e]}get transformProps(){let e={...this.raw,width:this.dims.x,height:this.dims.y},t=this._animationOverride;if(!t)return e;let{opacity:r,...o}=t;return{...e,...o}}get center(){return Xt(this.transformProps)}get matrix(){return this._matrix||(this._matrix=On(this.transformProps)),this._parentMatrix?$(this._parentMatrix,this._matrix):this._matrix}get ownMatrix(){return this._matrix||(this._matrix=On(this.transformProps)),this._matrix}get worldAngle(){let e=this.matrix;return Math.atan2(e[1],e[0])*180/Math.PI}get worldScale(){let e=this.matrix;return{x:Math.hypot(e[0],e[1]),y:Math.hypot(e[2],e[3])}}get aCoords(){if(this._aCoords||(this._aCoords=Xa(this.transformProps)),!this._parentMatrix)return this._aCoords;let e=this._parentMatrix;return{tl:Q(e,this._aCoords.tl.x,this._aCoords.tl.y),tr:Q(e,this._aCoords.tr.x,this._aCoords.tr.y),br:Q(e,this._aCoords.br.x,this._aCoords.br.y),bl:Q(e,this._aCoords.bl.x,this._aCoords.bl.y)}}contentBoxCorners(){let e=typeof this.raw.strokeWidth=="number"?this.raw.strokeWidth:0,t=this.raw.strokeUniform===!0,r=(t?this.dims.x:this.dims.x+e)/2,o=(t?this.dims.y:this.dims.y+e)/2,i=t?e/2:0,s=this.ownMatrix,a=1/0,l=1/0,c=-1/0,u=-1/0;for(let h of[-r,r])for(let d of[-o,o]){let f=Q(s,h,d);f.x<a&&(a=f.x),f.y<l&&(l=f.y),f.x>c&&(c=f.x),f.y>u&&(u=f.y)}return{tl:{x:a-i,y:l-i},tr:{x:c+i,y:l-i},br:{x:c+i,y:u+i},bl:{x:a-i,y:u+i}}}get inkACoords(){return this.aCoords}get parentMatrix(){return this._parentMatrix}setParentMatrix(e,t=1){this._parentMatrix=e,this._parentOpacity=t,this.invalidateWorldGeometry(),this._renderNotify?.()}get renderOpacity(){return(this._animationOverride?.opacity??this.raw.opacity??1)*(this._inIsolatedFBO?1:this._parentOpacity)}setIsolation(e){if(this._inIsolatedFBO=e,this instanceof J)for(let t of this.children)t.setIsolation(e)}invalidateWorldGeometry(){this._matrix=null,this._aCoords=null,this._bounds=null}get bounds(){return this._bounds||(this._bounds=Bn(this.aCoords)),this._bounds}containsPoint(e,t,r=0){if(this.isSolidType&&!Ki(this))return Il(this)&&this.outlineStrokeHitAt(e,t,r);let o=this.aCoords,i=[o.tl,o.tr,o.br,o.bl],s=!1;for(let a=0,l=3;a<4;l=a++){let c=i[a].x,u=i[a].y,h=i[l].x,d=i[l].y;u>t!=d>t&&e<(h-c)*(t-u)/(d-u)+c&&(s=!s)}return s}outlineStrokeHitAt(e,t,r=0){if(!this.isSolidType)return!1;let o=this.dims.x/2,i=this.dims.y/2;if(!(o>0)||!(i>0))return!1;let s=this.localPoint(e,t),a=Math.abs(s.x)-o,l=Math.abs(s.y)-i;return(a>0||l>0?Math.hypot(Math.max(a,0),Math.max(l,0)):Math.min(-a,-l))<=_l(this,r)}localPoint(e,t){return Q(ve(this.matrix),e,t)}rotateAroundCenter(e,t=this.center){let r=xe({...this.transformProps,angle:e},t);return{angle:e,left:r.x,top:r.y}}get dims(){let e=this.cropRect;if(e)return{x:e.sw,y:e.sh};let t=this.raw.width??(this.imageEl?this.imageEl.naturalWidth:0),r=this.raw.height??(this.imageEl?this.imageEl.naturalHeight:0);return{x:t,y:r}}get cropRect(){return Qi(this.raw)}toObject(){let e={};for(let t of Bx)this.raw[t]!==void 0&&(e[t]=this.raw[t]);for(let[t,r]of Object.entries(this.raw))e[t]===void 0&&!t.startsWith("_")&&(e[t]=r);return e}},Wx=n=>{if(n.angle===0||n.w<=0||n.h<=0)return null;let e=(n.angle%180+180)%180,t=Math.min(e,180-e);if(t<2)return null;let r=t*Math.PI/180,o=Math.abs(Math.cos(r)),i=Math.abs(Math.sin(r)),s=o*o-i*i;if(Math.abs(s)<.5)return null;let a=(n.w*o-n.h*i)/s,l=(n.h*o-n.w*i)/s;return!Number.isFinite(a)||!Number.isFinite(l)||a<=0||l<=0?null:{w:a,h:l}},Hx=n=>{let{fw:e,fh:t}=n;if(e===void 0||t===void 0)return null;let r=n.w+n.h;return!Number.isFinite(e)||!Number.isFinite(t)||e<=0||t<=0||e>r||t>r?null:{w:e,h:t}},Se=class extends ct{_layout=null;_arcDims=null;_scrollOffset=0;constructor(e){super(e)}set(e){super.set(e),Ll(e)||(this.invalidateTextLayout(),typeof this.raw.renderSrc=="string"&&Object.keys(e).some(t=>Ox.has(t))&&(delete this.raw.renderSrc,delete this.raw.renderRect))}invalidateTextLayout(){this._layout=null,this._arcDims=null,this.invalidateGeometryCache(),this._renderNotify?.()}get textStyle(){let e=this.raw;return{fontFamily:e.fontFamily??"Times New Roman",fontSize:e.fontSize??40,fontWeight:e.fontWeight,fontStyle:e.fontStyle,lineHeight:e.lineHeight??1.16,charSpacing:e.charSpacing??0,textAlign:e.textAlign??fe.LEFT}}get paintFirst(){return this.raw.paintFirst==="stroke"?"stroke":"fill"}get textStroke(){let e=this.raw,t=typeof e.stroke=="string"?e.stroke:"",r=e.strokeWidth??1;return!t||r===0?null:{color:t,width:r,lineJoin:e.strokeLineJoin,miterLimit:e.strokeMiterLimit,lineCap:e.strokeLineCap}}get decorationDefaults(){let e=this.raw;return{underline:!!e.underline,overline:!!e.overline,linethrough:!!e.linethrough,textDecorationThickness:e.textDecorationThickness,fontSize:this.textStyle.fontSize,fill:typeof e.fill=="string"?e.fill:void 0,charSpacing:this.textStyle.charSpacing,vertical:e.vertical===!0}}get textLayout(){if(!this._layout){let e=this.raw,t=Ke(e),r=(se(e)===L.TEXTBOX||se(e)===L.TEXTIMAGE)&&t===null;this._layout=jn(e.text??"",this.textStyle,{boxWidth:r?e.width??0:null,styles:e.styles,splitByGrapheme:e.splitByGrapheme===!0,vertical:e.vertical===!0,paragraph:t==="arc"||t==="circle"?void 0:e.paragraph})}return this._layout}get scrollOffset(){return this._scrollOffset}setScrollOffset(e){this._scrollOffset=Number.isFinite(e)?e:0,this._renderNotify?.()}get textTotalWidth(){let e=this.textLayout;if(this.raw.vertical===!0&&e.verticalWidth!==void 0)return e.verticalWidth;let t=0;for(let r of e.lines)r.width>t&&(t=r.width);return t}get dims(){if(typeof this.raw.renderSrc=="string"){let t=this.bitmapRect;return{x:t.w,y:t.h}}if(Ge(this.raw)){if(!this._arcDims){let t=Et(this.textLayout,this.raw,this.textStyle.lineHeight??1.16);this._arcDims={x:t.width,y:t.height}}return this._arcDims}let e=typeof this.raw.height=="number"?this.raw.height:0;return{x:this.textLayout.width,y:Math.max(this.textLayout.height,e)}}get bitmapRect(){let e=this.raw.renderRect,t=c=>typeof c=="number"&&Number.isFinite(c)&&c>=0?c:null,r=(e&&t(e.w))??(typeof this.raw.width=="number"?this.raw.width:0),o=(e&&t(e.h))??(typeof this.raw.height=="number"?this.raw.height:0),i=e&&typeof e.x=="number"&&Number.isFinite(e.x)?e.x:0,s=e&&typeof e.y=="number"&&Number.isFinite(e.y)?e.y:0,a=e&&typeof e.angle=="number"&&Number.isFinite(e.angle)?e.angle:0,l={x:i,y:s,w:r,h:o,angle:a};if(e){let c=m=>typeof m=="number"&&Number.isFinite(m)?m:void 0,u=c(e.fw),h=c(e.fh);u!==void 0&&h!==void 0&&(l.fw=u,l.fh=h);let d=c(e.fx),f=c(e.fy);d!==void 0&&f!==void 0&&(l.fx=d,l.fy=f)}return l}get aCoords(){let e=this.bitmapFrameCorners();if(e){let t=this.parentMatrix;if(!t)return e;let r=o=>Q(t,o.x,o.y);return{tl:r(e.tl),tr:r(e.tr),br:r(e.br),bl:r(e.bl)}}return super.aCoords}contentBoxCorners(){return this.bitmapFrameCorners()??super.contentBoxCorners()}bitmapFrameCorners(){if(typeof this.raw.renderSrc!="string")return null;let e=this.bitmapRect,t=Hx(e)??Wx(e);if(!t&&e.angle===0&&e.x===0&&e.y===0)return null;let r=this.ownMatrix;(e.x!==0||e.y!==0)&&(r=$(r,[1,0,0,1,e.x,e.y])),t&&e.fx!==void 0&&e.fy!==void 0&&(e.fx!==0||e.fy!==0)&&(r=$(r,[1,0,0,1,e.fx,e.fy])),!t&&e.angle!==0&&(r=$(r,kt({angle:-e.angle})));let o=(t?t.w:e.w)/2,i=(t?t.h:e.h)/2;return{tl:Q(r,-o,-i),tr:Q(r,o,-i),br:Q(r,o,i),bl:Q(r,-o,i)}}get inkACoords(){return Lh(this,this.textInkACoords)}get textInkACoords(){if(typeof this.raw.renderSrc=="string")return super.inkACoords;let e=Ke(this.raw);if(e==="arc"||e==="circle"||e==="scroll")return super.inkACoords;let t=this.textLayout,r,o,i,s;if(e!==null){let u=xr(this.raw),h=u?Ei(t,this.textStyle,{align:this.textStyle.textAlign}):null,d=u&&h?ih(u,t,this.raw,h,this.contentTopY):null;if(d)r=d.left,o=d.right,i=d.top,s=d.bottom;else{if(u)return super.inkACoords;let f=Ei(t,this.textStyle,{vertical:this.raw.vertical===!0,align:this.textStyle.textAlign});if(!f)return super.inkACoords;let m=t.width/2;r=-m+f.lo,o=-m+f.hi,i=this.contentTopY+f.firstTop,s=this.contentTopY+t.height}}else{let u=Ei(t,this.textStyle,{vertical:this.raw.vertical===!0,align:this.textStyle.textAlign});if(!u)return super.inkACoords;let h=t.width/2;r=-h+u.lo,o=-h+u.hi,i=this.contentTopY+u.firstTop,s=this.contentTopY+t.height}let a=this.ownMatrix,l=this.parentMatrix,c=(u,h)=>{let d=Q(a,u,h);return l?Q(l,d.x,d.y):d};return{tl:c(r,i),tr:c(o,i),br:c(o,s),bl:c(r,s)}}get contentTopY(){return typeof this.raw.renderSrc=="string"?-this.textLayout.height/2:-this.dims.y/2}cursorCoord(e){let t=this.textLayout;if(t.lines.length===0)return null;let r=0,o=0;for(let u=0;u<t.lines.length;u++){let h=t.lines[u],d=h.styleMap.flatStart,f=d+h.graphemes.length;if(e<=f){r=u,o=Math.max(0,e-d);break}u===t.lines.length-1&&(r=u,o=h.graphemes.length)}let i=t.lines[r],s=-t.width/2+i.leftOffset+(o<i.boxes.length?i.boxes[o].left:ln(i)),l=i.charStyles[Math.max(0,o-1)]?.fontSize??this.textStyle.fontSize,c=this.contentTopY+i.baseline-l*.93;return{x:s,y:c,height:l*1.28}}cursorIndexAt(e,t){let r=this.textLayout;if(r.lines.length===0)return 0;let o=t-this.contentTopY,i=0;for(let l=0;l<r.lines.length;l++){let c=r.lines[l];if(o<=c.baseline+this.textStyle.fontSize*.3){i=l;break}i=l}let s=r.lines[i],a=-r.width/2+s.leftOffset;for(let l=0;l<s.boxes.length;l++){let c=s.boxes[l];if(e<a+c.left+c.width/2)return s.styleMap.flatStart+l}return s.styleMap.flatStart+s.graphemes.length}wordBoundsAt(e){let t=Array.from(this.raw.text??""),r=a=>a===" "||a===" "||a==="\r"||a===`
|
|
8
|
-
`,o=Math.max(0,Math.min(e,t.length));if(r(t[o]))return[o,o];let i=o,s=o;for(;i>0&&!r(t[i-1]);)i--;for(;s<t.length&&!r(t[s]);)s++;return[i,s]}},Gx=(n,e)=>Math.max(24,Math.min(128,Math.ceil((n+e)*.6))),td=(n,e)=>{if(!(n>0)||!(e>0))return null;let t=Gx(n,e),r=new Float32Array((t+1)*2);for(let i=0;i<t;i++){let s=i/t*Math.PI*2;r[(i+1)*2]=n*Math.cos(s),r[(i+1)*2+1]=e*Math.sin(s)}let o=new Uint32Array(t*3);for(let i=0;i<t;i++)o[i*3]=0,o[i*3+1]=1+i,o[i*3+2]=1+(i+1)%t;return{verts:r,triangles:o}},nd=n=>{if(!Array.isArray(n)||n.length<3)return null;let e=n,t=1/0,r=1/0,o=-1/0,i=-1/0;for(let h of e)t>h.x&&(t=h.x),r>h.y&&(r=h.y),o<h.x&&(o=h.x),i<h.y&&(i=h.y);let s=(t+o)/2,a=(r+i)/2,l=new Float32Array(e.length*2),c=new Array(e.length);for(let h=0;h<e.length;h++)l[h*2]=e[h].x-s,l[h*2+1]=e[h].y-a,c[h]={x:l[h*2],y:l[h*2+1]};let u=Ka(c);return u.length>0?{verts:l,triangles:new Uint32Array(u)}:null},Xx=n=>{let e=0;for(let i of n)e+=i.length;if(e<3)return null;let t=new Float32Array(e*2),r=[],o=0;for(let i of n){for(let s=0;s<i.length;s++)t[(o+s)*2]=i[s].x,t[(o+s)*2+1]=i[s].y;for(let s of Ka(i))r.push(s+o);o+=i.length}return r.length>0?{verts:t,triangles:new Uint32Array(r)}:null},zx=n=>{let e=Ce(n);if(!e)return{contours:[],dims:{x:0,y:0}};let t=Fe(e),r=Xu(e);if(!t)return{contours:r,dims:{x:0,y:0}};let o=(t.left+t.right)/2,i=(t.top+t.bottom)/2;return{contours:r.map(a=>({closed:a.closed,points:a.points.map(l=>({x:l.x-o,y:l.y-i}))})),dims:{x:t.right-t.left,y:t.bottom-t.top}}},xn=class extends ct{_mesh;set(e){super.set(e),Ll(e)||(this._mesh=void 0)}get shapeKind(){return this.typeKey}get shapeMesh(){if(this._mesh===void 0){let e=this.raw,t=this.shapeKind;if(t===L.ELLIPSE)this._mesh=td(e.rx??0,e.ry??0);else if(t===L.CIRCLE){let r=e.radius??0;this._mesh=td(r,r)}else t===L.TRIANGLE?this._mesh=nd(rd(e)):this._mesh=nd(e.points)}return this._mesh}get dims(){let e=this.raw,t=this.shapeKind;return t===L.ELLIPSE?{x:2*(e.rx??0),y:2*(e.ry??0)}:t===L.CIRCLE?{x:2*(e.radius??0),y:2*(e.radius??0)}:t===L.TRIANGLE?{x:e.width??0,y:e.height??0}:Yx(e.points)}containsPoint(e,t,r=0){if(!Ki(this))return Il(this)&&this.outlineStrokeHitAt(e,t,r);let o=this.localPoint(e,t),i=this.shapeKind;if(i===L.ELLIPSE||i===L.CIRCLE){let a=this.dims.x/2,l=this.dims.y/2;if(!(a>0)||!(l>0))return!1;let c=o.x/a,u=o.y/l;return c*c+u*u<=1}let s=this.shapeMesh;return i===L.POLYLINE||i===L.POLYGON?s?od(s.verts,o.x,o.y):Al(this.raw.points,o,i===L.POLYGON,Math.max((Number(this.raw.strokeWidth)||1)/2,3,r)):s?od(s.verts,o.x,o.y):!1}outlineStrokeHitAt(e,t,r=0){let o=this.localPoint(e,t),i=this.shapeKind,s=_l(this,r);if(i===L.ELLIPSE||i===L.CIRCLE){let a=this.dims.x/2,l=this.dims.y/2;if(!(a>0)||!(l>0))return!1;let c=2*o.x/(a*a),u=2*o.y/(l*l),h=Math.hypot(c,u);if(h<1e-9)return Math.min(a,l)<=s;let d=o.x*o.x/(a*a)+o.y*o.y/(l*l)-1;return Math.abs(d)/h<=s}return i===L.TRIANGLE?Al(rd(this.raw),o,!0,s):Al(this.raw.points,o,i===L.POLYGON,s)}},rd=n=>{let e=n.width??0,t=n.height??0;return[{x:e/2,y:0},{x:e,y:t},{x:0,y:t}]},Yx=n=>{if(!Array.isArray(n)||n.length===0)return{x:0,y:0};let e=1/0,t=1/0,r=-1/0,o=-1/0;for(let i of n)e>i.x&&(e=i.x),t>i.y&&(t=i.y),r<i.x&&(r=i.x),o<i.y&&(o=i.y);return{x:r-e,y:o-t}},qi=10,Nl=n=>Math.min(1,Math.max(0,n)),Ux=n=>{let e=n.fillPaint;if(!e)return 0;if(e.kind==="solid")return Nl(e.color[3])*n.renderOpacity;if(e.kind==="gradient"){let t=0;for(let r of e.decl.stops)t=Math.max(t,Nl(r.color[3]));return t*n.renderOpacity}return null},Ki=n=>{let e=Ux(n);return e===null||e*255>qi},Il=n=>{let e=n.raw.stroke;return typeof e=="object"&&e!==null?!0:typeof e!="string"||!e||Number(n.raw.strokeWidth)===0?!1:Nl(oe(e)[3])*n.renderOpacity*255>qi},_l=(n,e)=>Math.max((Number(n.raw.strokeWidth)||1)/2,3,e),Dl=8,sd=n=>{let e=n.typeKey;return e===L.LINE||e===L.ARROW||e===L.DIMENSION||e===L.POLYLINE?!0:(n.isShapeType||n.isSolidType)&&!Ki(n)},Vi=(n,e,t,r,o,i)=>{let s=o-t,a=i-r,l=s*s+a*a,c=l>0?Math.max(0,Math.min(1,((n-t)*s+(e-r)*a)/l)):0,u=t+c*s-n,h=r+c*a-e;return u*u+h*h},Al=(n,e,t,r)=>{if(!Array.isArray(n)||n.length<2)return!1;let o=n,i=1/0,s=1/0,a=-1/0,l=-1/0;for(let d of o)i>d.x&&(i=d.x),s>d.y&&(s=d.y),a<d.x&&(a=d.x),l<d.y&&(l=d.y);let c=(i+a)/2,u=(s+l)/2,h=r*r;for(let d=0;d+1<o.length;d++)if(Vi(e.x,e.y,o[d].x-c,o[d].y-u,o[d+1].x-c,o[d+1].y-u)<=h)return!0;if(t&&o.length>2){let d=o[o.length-1];if(Vi(e.x,e.y,d.x-c,d.y-u,o[0].x-c,o[0].y-u)<=h)return!0}return!1},Pr=class extends xn{_pathGeo;_fillPolys;_pathMesh;set(e){super.set(e),("path"in e||"fillRule"in e)&&(this._pathGeo=void 0,this._fillPolys=void 0,this._pathMesh=void 0)}get pathGeometry(){return this._pathGeo===void 0&&(this._pathGeo=zx(this.raw.path)),this._pathGeo}get fillPolygons(){if(this._fillPolys===void 0){let e=this.raw.fillRule==="evenodd"?"evenodd":"nonzero";this._fillPolys=Yu(this.pathGeometry.contours,e)}return this._fillPolys}get shapeMesh(){return this._pathMesh===void 0&&(this._pathMesh=Xx(this.fillPolygons)),this._pathMesh}get dims(){return this.pathGeometry.dims}containsPoint(e,t,r=0){return Ki(this)?ct.prototype.containsPoint.call(this,e,t):Il(this)&&this.outlineStrokeHitAt(e,t,r)}outlineStrokeHitAt(e,t,r=0){let o=this.localPoint(e,t),i=this.pathGeometry.contours;if(i.length===0)return!1;let s=_l(this,r)**2;for(let a of i){let l=a.points;for(let c=0;c+1<l.length;c++)if(Vi(o.x,o.y,l[c].x,l[c].y,l[c+1].x,l[c+1].y)<=s)return!0}return!1}},$x=(n,e,t)=>{let r=Number(n.strokeWidth)||1,o=Number(n.arrowWidth)||15,i=Number(n.arrowHeight)||22.5,s=n.arrowType==="start"||n.arrowType==="both"?n.arrowType:"end",a=Math.sqrt(r),l=o*a,c=i*a;if(!(c>0)||!(l>0))return!1;let u=Math.atan2(t.y2-t.y1,t.x2-t.x1),h=(d,f,m)=>{let p=Math.cos(m),b=Math.sin(m),x=e.x-d,g=e.y-f,y=x*p+g*b,v=-x*b+g*p;return y<-c||y>0?!1:Math.abs(v)<=l/2*(1+y/c)};return!!((s==="end"||s==="both")&&h(t.x2,t.y2,u)||(s==="start"||s==="both")&&h(t.x1,t.y1,u+Math.PI))},jx=(n,e,t,r)=>{let o=Number(n.textFontSize)||50,i=Number(n.textPadding)||4,s=typeof n.text=="string"&&n.text.trim()?n.text:"50cm",a=Jr(`${o}px Arial, sans-serif`,s)+i*2,l=Math.atan2(t.y2-t.y1,t.x2-t.x1),c=-Math.sin(l),u=Math.cos(l),h=o/2,d=r*r;for(let[R,P]of[[t.x1,t.y1],[t.x2,t.y2]])if(Vi(e.x,e.y,R-c*h,P-u*h,R+c*h,P+u*h)<=d)return!0;let f=o+(Number(n.strokeWidth)||1)/2+5,m=(t.x1+t.x2)/2+c*f,p=(t.y1+t.y2)/2+u*f,b=n.textFollowLine===!1?0:l,x=Math.cos(b),g=Math.sin(b),y=e.x-m,v=e.y-p,S=y*x+v*g,w=-y*g+v*x;return Math.abs(S)<=a/2&&Math.abs(w)<=(o+i*2)/2},kr=class extends ct{get dims(){let e=this.linePoints;return e?{x:Math.abs(e.x2-e.x1),y:Math.abs(e.y2-e.y1)}:{x:0,y:0}}get linePoints(){let e=Number(this.raw.x1),t=Number(this.raw.y1),r=Number(this.raw.x2),o=Number(this.raw.y2);return!Number.isFinite(e)||!Number.isFinite(t)||!Number.isFinite(r)||!Number.isFinite(o)?null:{x1:e,y1:t,x2:r,y2:o}}containsPoint(e,t,r=0){let o=this.linePoints;if(!o)return!1;let i=this.localPoint(e,t);if(!i)return!1;let s=o.x2-o.x1,a=o.y2-o.y1,l=s*s+a*a,c=0;l>0&&(c=Math.max(0,Math.min(1,((i.x-o.x1)*s+(i.y-o.y1)*a)/l)));let u=o.x1+c*s,h=o.y1+c*a,d=Math.max((Number(this.raw.strokeWidth)||1)/2,3,r);if(Math.hypot(i.x-u,i.y-h)<=d)return!0;let f=this.typeKey;return f===L.ARROW?$x(this.raw,i,o):f===L.DIMENSION?jx(this.raw,i,o,d):!1}},ie=class extends ct{animatedKind;_sprite=null;_frameCanvas=null;_frameIndex=0;_anchorTime=0;_playing=!1;_videoEl=null;_frameDirty=!1;_rvfcActive=!1;_contentVersion=0;_onNewFrame=null;constructor(e,t){super(e),this.animatedKind=t}get isImageType(){return!0}get animating(){if(this.animatedKind==="video"){let e=this._videoEl;return!!e&&!e.paused&&!e.ended}return this._playing&&!!this._sprite&&this._sprite.framesLength>1}get paintSource(){return this.animatedKind==="video"?this._videoEl:this._frameCanvas}attachSprite(e,t){this._sprite=e,this._onNewFrame=t??null;let r=document.createElement("canvas");r.width=e.frameWidth,r.height=e.canvas.height,this._frameCanvas=r,this._frameIndex=0,this._anchorTime=performance.now(),this._playing=e.framesLength>1,this.blitFrame(),this.invalidateGeometryCache(),this._renderNotify?.()}attachVideo(e,t){this._videoEl=e,this._onNewFrame=t??null;let r=()=>{this._frameDirty=!0,this._onNewFrame?.()};e.addEventListener("play",()=>this.startFrameWatch()),e.addEventListener("pause",r),e.addEventListener("seeked",r),e.addEventListener("ended",()=>{try{e.currentTime=0,e.pause()}catch{}}),this.invalidateGeometryCache(),this._renderNotify?.(),e.play().catch(()=>{})}tick(e){if(this.animatedKind==="video"){let s=this._videoEl;if(!s)return!1;if(this._frameDirty)return this._frameDirty=!1,this._contentVersion++,!0;let a=this._rvfcActive?!1:!s.paused&&!s.ended;return a&&this._contentVersion++,a}let t=this._sprite;if(!this._playing||!t||t.framesLength<=1)return!1;let r=!1,o=0,i=t.framesLength;for(;o<i;){let s=t.frameDelays[this._frameIndex]||t.delay||100;if(e-this._anchorTime<s)break;this._anchorTime+=s,this._frameIndex=(this._frameIndex+1)%i,r=!0,o++}return r&&(this._contentVersion++,this.blitFrame()),r}play(){if(this.animatedKind==="video"){this._videoEl?.play().catch(()=>{});return}!this._sprite||this._sprite.framesLength<=1||(this._playing=!0,this._anchorTime=performance.now())}pause(){if(this.animatedKind==="video"){this._videoEl?.pause();return}this._playing=!1}stop(){if(this.animatedKind==="video"){let e=this._videoEl;if(!e)return;try{e.currentTime=0,e.pause()}catch{}return}this._playing=!1,this._frameIndex=0,this._contentVersion++,this.blitFrame()}syncVideoToTime(e,t){if(this.animatedKind!=="video")return;let r=this._videoEl;if(!r)return;r.pause();let o=r.duration,i=Number.isFinite(o)&&o>0?Math.min(Math.max(e,0),o):Math.max(e,0);try{r.currentTime=i}catch{}t&&r.play().catch(()=>{})}get frameIndex(){return this._frameIndex}get contentVersion(){return this._contentVersion}get mediaDuration(){if(this.animatedKind==="video"){let t=this._videoEl?.duration;if(t&&Number.isFinite(t))return t;let r=Number(this.raw.duration);return Number.isFinite(r)&&r>0?r:0}let e=this._sprite;return e?e.frameDelays.reduce((t,r)=>t+(r||e.delay||100),0)/1e3:0}startFrameWatch(){let e=this._videoEl;if(!e||this._rvfcActive||typeof e.requestVideoFrameCallback!="function")return;this._rvfcActive=!0;let t=()=>{if(!(!this._rvfcActive||!this._videoEl)){if(this._videoEl.paused||this._videoEl.ended){this._rvfcActive=!1;return}this._frameDirty=!0,this._onNewFrame?.(),e.requestVideoFrameCallback(t)}};e.requestVideoFrameCallback(t)}blitFrame(){let e=this._sprite,t=this._frameCanvas;if(!e||!t)return;let r=t.getContext("2d");r&&(r.clearRect(0,0,t.width,t.height),r.drawImage(e.canvas,this._frameIndex*e.frameWidth,0,e.frameWidth,e.canvas.height,0,0,t.width,t.height))}detach(){this._playing=!1,this._rvfcActive=!1,this._frameDirty=!1;let e=this._videoEl;if(e)try{e.pause(),e.removeAttribute("src"),e.load()}catch{}this._videoEl=null,this._sprite=null,this._frameCanvas=null,this._onNewFrame=null}get dims(){return this.animatedKind==="gif"?{x:this.raw.width??this._sprite?.frameWidth??0,y:this.raw.height??this._sprite?.canvas.height??0}:{x:this.raw.width??this._videoEl?.videoWidth??0,y:this.raw.height??this._videoEl?.videoHeight??0}}},od=(n,e,t)=>{let r=n.length/2,o=!1;for(let i=0,s=r-1;i<r;s=i++){let a=n[i*2],l=n[i*2+1],c=n[s*2],u=n[s*2+1];l>t!=u>t&&e<(c-a)*(t-l)/(u-l)+a&&(o=!o)}return o},J=class n extends ct{children=[];constructor(e,t){super(e);let r=Array.isArray(e.objects)?e.objects:[];for(let o of r){if(!o||typeof o.type!="string")continue;let i=t(o);i&&this.children.push(i)}this.syncChildMatrices()}set(e){super.set(e),this.syncChildMatrices()}setParentMatrix(e,t=1){super.setParentMatrix(e,t),this.syncChildMatrices()}setAnimationOverride(e){super.setAnimationOverride(e),this.syncChildMatrices()}syncChildMatrices(){let e=this.matrix,t=this.renderOpacity;for(let r of this.children)r.setParentMatrix(e,t)}get dims(){let e=Number(this.raw.width),t=Number(this.raw.height);return{x:Number.isFinite(e)&&e>0?e:0,y:Number.isFinite(t)&&t>0?t:0}}containsPoint(e,t,r=0){return this.visible?this.children.some(o=>o.visible&&o.containsPoint(e,t,r)):!1}get inkACoords(){let e=1/0,t=1/0,r=-1/0,o=-1/0;for(let i of this.children)if(i.visible)for(let s of[i.inkACoords.tl,i.inkACoords.tr,i.inkACoords.br,i.inkACoords.bl])e=Math.min(e,s.x),t=Math.min(t,s.y),r=Math.max(r,s.x),o=Math.max(o,s.y);return Number.isFinite(e)?{tl:{x:e,y:t},tr:{x:r,y:t},br:{x:r,y:o},bl:{x:e,y:o}}:this.aCoords}childAtPoint(e,t,r=0){for(let o=this.children.length-1;o>=0;o--){let i=this.children[o];if(!(!i.visible||!i.containsPoint(e,t,r)))return i instanceof n&&!(i instanceof ee)&&!(i instanceof le)?i.childAtPoint(e,t)??i:i}return null}containsDeep(e){return this.children.some(t=>t===e||t instanceof n&&t.containsDeep(e))}adoptChild(e,t=this.children.length){this.children.splice(t,0,e),this.syncChildMatrices()}removeChildRaw(e){let t=this.children.indexOf(e);t<0||(this.children.splice(t,1),e.setParentMatrix(null),this.syncChildMatrices())}moveChildRaw(e,t){let r=this.children.indexOf(e);if(r<0)return;this.children.splice(r,1);let o=Math.max(0,Math.min(t,this.children.length));this.children.splice(o,0,e),this.syncChildMatrices()}toObject(){let e=super.toObject();return e.objects=this.children.map(t=>t.toObject()),e}},ee=class n extends J{_layout;_childFactory;_placedShift;get inkACoords(){return this.aCoords}selectedCells=[];cellAnchor=null;cellRange=null;hoveredBorder=null;hoveredIndicator=null;indicatorVisible=!1;borderDragging=!1;hoveredStrip=null;hoveredDragHandle=!1;hoveredRangeHandle=!1;editingCell=null;constructor(e,t){let r=To(e),o=Xt({...e,width:r.constructorDims.width,height:r.constructorDims.height}),i=xe({...e,width:r.width,height:r.height},o);super({...e,left:i.x,top:i.y,width:r.width,height:r.height,objects:r.children},t),this._layout=r,this._childFactory=t,this._placedShift={x:i.x-(e.left??0),y:i.y-(e.top??0)}}_rebuilding=!1;set(e){let t=["rows","cols","columnWidths","rowHeights","manualRowHeights","minCellWidth","minCellHeight","cellPadding","cellSpacing","cellData"],r=!this._rebuilding&&Object.keys(e).some(o=>t.includes(o));if(super.set(e),r){this._rebuilding=!0;try{this.rebuildTable()}finally{this._rebuilding=!1}}}toObject(){let e=super.toObject();return typeof e.left=="number"&&(e.left=e.left-this._placedShift.x),typeof e.top=="number"&&(e.top=e.top-this._placedShift.y),e}get layout(){return this._layout}get tableView(){let e=this.raw.rows??3,t=this.raw.cols??3,r=this.raw.cellSpacing??0;return{rows:e,cols:t,columnWidths:this._layout.columnWidths,rowHeights:this._layout.rowHeights,cellSpacing:r}}get cellMap(){let e=Array.isArray(this.raw.cellData)?this.raw.cellData:[];return It(e)}get tableAngle(){return this.raw.angle??0}get objectScale(){return{x:Math.abs(this.raw.scaleX??1),y:Math.abs(this.raw.scaleY??1)}}cellHit(e,t){let r=this.localPoint(e,t);return jh(this.tableView,this.cellMap,r.x,r.y)}borderHit(e,t){let r=this.localPoint(e,t),o=this.objectScale;return Pl(this.tableView,this.cellMap,r.x,r.y,5/o.x,5/o.y)}borderOrIndicatorHit(e,t,r){let o=this.localPoint(e,t),i=this.objectScale;return Vh(this.tableView,this.cellMap,o.x,o.y,{thresholdX:5/i.x,thresholdY:5/i.y,scaleX:this.raw.scaleX??1,scaleY:this.raw.scaleY??1,zoom:r})}stripHit(e,t,r=1){let o=this.localPoint(e,t);return Qh(this.tableView,this.dims.x,this.dims.y,o.x,o.y,this.objectScale,r)}dragHandleHit(e,t,r=1){let o=this.localPoint(e,t);return Zh(this.dims.x,this.dims.y,o.x,o.y,this.objectScale,r)}get expandedCellRange(){if(!this.selectedCells.length)return null;let e=this.cellRange??Xe(this.selectedCells);return e?El(this.cellMap,e.r1,e.r2,e.c1,e.c2):null}get selectionBoundsRect(){let e=this.expandedCellRange;return e?So(this.tableView,e):null}get isFullCellSelection(){let e=this.expandedCellRange;if(!e)return!1;let t=this.tableView;return e.r1===0&&e.c1===0&&e.r2===t.rows-1&&e.c2===t.cols-1}rangeHandleHit(e,t,r=1){if(this.editingCell||!this.selectedCells.length||this.isFullCellSelection)return!1;let o=this.selectionBoundsRect;if(!o)return!1;let i=this.localPoint(e,t);return Jh(o,i.x,i.y,this.objectScale,r)}static cellSelectionSink=null;setCellSelection(e,t,r){let o=this.selectedCells,i=o.length!==e.length||o.some((s,a)=>s.row!==e[a].row||s.col!==e[a].col)||this.cellAnchor?.row!==t?.row||this.cellAnchor?.col!==t?.col||this.cellRange?.r1!==r?.r1||this.cellRange?.r2!==r?.r2||this.cellRange?.c1!==r?.c1||this.cellRange?.c2!==r?.c2;this.selectedCells=e,this.cellAnchor=t,this.cellRange=r,i&&n.cellSelectionSink?.(this)}setRowSelection(e){let t=zi(this.cellMap,this.tableView.cols,e);this.setCellSelection(t,t[0]??null,Xe(t))}setColumnSelection(e){let t=Xi(this.cellMap,this.tableView.rows,e);this.setCellSelection(t,t[0]??null,Xe(t))}clearCellSelection(){let e=this.selectedCells.length>0;this.selectedCells=[],this.cellAnchor=null,this.cellRange=null,e&&n.cellSelectionSink?.(this)}get hasCellSelection(){return this.selectedCells.length>0}clearCellInteractionState(){this.clearCellSelection(),this.clearHoverState()}clearHoverState(){this.hoveredBorder=null,this.hoveredIndicator=null,this.indicatorVisible=!1,this.hoveredStrip=null,this.hoveredDragHandle=!1,this.hoveredRangeHandle=!1}getRowMinHeight(e){let t=this.raw.minCellHeight??40;return Math.max(t,this._layout.rowTextFloors[e]??0)}cellBounds(e,t){let r=we(this.cellMap,e,t);if(r?.isMerged)return null;let o=this.tableView;if(e<0||t<0||e>=o.rows||t>=o.cols)return null;let i=r?.colspan??1,s=r?.rowspan??1;return So(o,{r1:e,r2:e+s-1,c1:t,c2:t+i-1})}cellSceneCenter(e,t){let r=this.cellBounds(e,t);return r?Q(this.matrix,r.left+r.width/2,r.top+r.height/2):null}rebuildTable(){let e=this.raw.reflowOriginX??"left",t=this.raw.reflowOriginY??"top",r=(b,x)=>({x:e==="left"?-b/2:e==="right"?b/2:0,y:t==="top"?-x/2:t==="bottom"?x/2:0}),o=this.dims.x,i=this.dims.y,s=On({...this.raw,width:o,height:i}),a=Q(s,r(o,i).x,r(o,i).y),l=To(this.raw,void 0,this.editingCell?{hideTextCell:this.editingCell}:void 0);this._layout=l;let c=[];for(let b of l.children){let x=this._childFactory(b);x&&c.push(x)}this.children.length=0,this.children.push(...c),this.set({width:l.width,height:l.height,objects:l.children,rowHeights:l.rowHeights});let u=r(l.width,l.height),h=a.x-(s[0]*u.x+s[2]*u.y),d=a.y-(s[1]*u.x+s[3]*u.y),f=xe({...this.raw,width:l.width,height:l.height},{x:h,y:d});this.set({left:f.x,top:f.y});let m=Xt({...this.raw,width:l.constructorDims.width,height:l.constructorDims.height}),p=xe({...this.raw,width:l.width,height:l.height},m);this._placedShift={x:p.x-(this.raw.left??0),y:p.y-(this.raw.top??0)}}},ae=class extends ct{_clipImageEl=null;constructor(e){super(e)}get clipImageEl(){return this._clipImageEl}set clipImageEl(e){this._clipImageEl=e,this._renderNotify?.()}get clipImageRaw(){let e=this.raw.clipImage;return!e||typeof e!="object"||typeof e.src!="string"?null:e}_clipVideoEl=null;_clipSprite=null;_clipFrameCanvas=null;_clipFrameIndex=0;_clipAnchorTime=0;_clipPlaying=!1;_clipOnNewFrame=null;clipDynamicVersion=0;get clipDynamicKind(){let e=se(this.clipImageRaw);return e===L.VIDEO?"video":e===L.GIF?"gif":null}get hasDynamicClip(){return!!this._clipVideoEl||!!this._clipFrameCanvas}get clipAnimating(){return this._clipVideoEl?!this._clipVideoEl.paused&&!this._clipVideoEl.ended:this._clipPlaying&&!!this._clipSprite&&this._clipSprite.framesLength>1}attachClipSprite(e,t){this._clipSprite=e,this._clipOnNewFrame=t??null;let r=document.createElement("canvas");r.width=e.frameWidth,r.height=e.canvas.height,this._clipFrameCanvas=r,this._clipFrameIndex=0,this._clipAnchorTime=performance.now(),this._clipPlaying=e.framesLength>1,this.clipDynamicVersion++,this.blitClipFrame(),this._renderNotify?.()}attachClipVideo(e,t){this._clipVideoEl=e,this._clipOnNewFrame=t??null;let r=()=>{this.clipDynamicVersion++,this._renderNotify?.(),this._clipOnNewFrame?.()};e.addEventListener("seeked",r),e.addEventListener("pause",r),e.addEventListener("play",r),this.clipDynamicVersion++,this._renderNotify?.(),e.play().catch(()=>{})}dynamicClipSource(){return this._clipVideoEl?this._clipVideoEl:this._clipFrameCanvas}tickDynamicClip(e){if(this._clipVideoEl){let i=this._clipVideoEl;return!i.paused&&!i.ended?(this.clipDynamicVersion++,!0):!1}if(!this._clipPlaying||!this._clipSprite||this._clipSprite.framesLength<=1)return!1;let t=!1,r=0,o=this._clipSprite.framesLength;for(;r<o;){let i=this._clipSprite.frameDelays[this._clipFrameIndex]||this._clipSprite.delay||100;if(e-this._clipAnchorTime<i)break;this._clipAnchorTime+=i,this._clipFrameIndex=(this._clipFrameIndex+1)%o,t=!0,r++}return t&&(this.clipDynamicVersion=this._clipFrameIndex,this.blitClipFrame()),t}blitClipFrame(){let e=this._clipSprite,t=this._clipFrameCanvas;if(!e||!t)return;let r=t.getContext("2d");r&&(r.clearRect(0,0,t.width,t.height),r.drawImage(e.canvas,this._clipFrameIndex*e.frameWidth,0,e.frameWidth,e.canvas.height,0,0,t.width,t.height))}detachDynamicClip(){this._clipPlaying=!1;try{this._clipVideoEl?.pause()}catch{}this._clipVideoEl=null,this._clipSprite=null,this._clipFrameCanvas=null,this._renderNotify?.()}get clipMediaDuration(){if(this.clipDynamicKind!=="video")return 0;let e=this._clipVideoEl?.duration;if(e&&Number.isFinite(e))return e;let t=Number(this.clipImageRaw?.duration);return Number.isFinite(t)&&t>0?t:0}playClipMedia(){this.clipDynamicKind==="video"&&this._clipVideoEl?.play().catch(()=>{})}pauseClipMedia(){this.clipDynamicKind==="video"&&this._clipVideoEl?.pause()}syncClipMediaToTime(e,t){if(this.clipDynamicKind!=="video")return;let r=this._clipVideoEl;if(!r)return;r.pause();let o=r.duration,i=Number.isFinite(o)&&o>0?Math.min(Math.max(e,0),o):Math.max(e,0);try{r.currentTime=i}catch{}t&&r.play().catch(()=>{})}},le=class extends J{constructor(e,t){super(e,t);let r=this.layoutParams,o=Qn(e.layoutConfig),i=!!o&&o.pieces.length===this.maskChildren.length;o&&!i&&this.reconcileIncompleteLayout(o),this.set({width:r.width,height:r.height}),this.reconcileOverlappingChildren()}get inkACoords(){return this.aCoords}reconcileIncompleteLayout(e){let t=this.maskChildren;if(t.length>0&&e.pieces.length>t.length){let r=e.pieces.slice(0,t.length),o=1,i=1;for(let s of r)o=Math.max(o,s.col+(s.colSpan??1)),i=Math.max(i,s.row+(s.rowSpan??1));e.cols=o,e.rows=i,e.pieces=r,this.set({layoutConfig:{rows:i,cols:o,pieces:r}})}this.relayoutFromConfig(e,this.layoutParams)}reconcileOverlappingChildren(){let{hGap:e,vGap:t}=this.layoutParams,r=this.layoutParams.width/2,o=this.layoutParams.height/2,i=.5,s=this.maskChildren,a=new Map,l=u=>{let h=u.raw,d=h.width??0,f=h.height??0;return{x0:h.left-d/2,x1:h.left+d/2,y0:h.top-f/2,y1:h.top+f/2}};for(let u=0;u<s.length;u++)for(let h=u+1;h<s.length;h++){let d=l(s[u]),f=l(s[h]),m=Math.min(d.x1,f.x1)-Math.max(d.x0,f.x0),p=Math.min(d.y1,f.y1)-Math.max(d.y0,f.y0);if(!(m>i&&p>i))continue;let b=d.x0<=f.x0?s[u]:s[h],x=b===s[u]?s[h]:s[u],g=l(b),y=l(x);if(g.x1>y.x0+i){if(Math.abs(g.x1-r)<i&&y.x0<r-i){let P=a.get(b)??{};P.right=y.x0-e,a.set(b,P)}else if(Math.abs(y.x0+r)<i&&g.x1>-r+i){let P=a.get(x)??{};P.left=g.x1+e,a.set(x,P)}}let v=d.y0<=f.y0?s[u]:s[h],S=v===s[u]?s[h]:s[u],w=l(v),R=l(S);if(w.y1>R.y0+i){if(Math.abs(w.y1-o)<i&&R.y0<o-i){let P=a.get(v)??{};P.bottom=R.y0-t,a.set(v,P)}else if(Math.abs(R.y0+o)<i&&w.y1>-o+i){let P=a.get(S)??{};P.top=w.y1+t,a.set(S,P)}}}if(!a.size)return;let c=[];for(let[u,h]of a){let d=l(u),f=h.left??d.x0,m=h.right??d.x1,p=h.top??d.y0,b=h.bottom??d.y1;if(!(m-f>i)||!(b-p>i))continue;let x={left:(f+m)/2,width:m-f,top:(p+b)/2,height:b-p};u.set(x),c.push(`${String(u.raw.id)}→${Math.round(x.left)},${Math.round(x.top)},${Math.round(x.width)}×${Math.round(x.height)}`)}c.length&&console.info("[PuzzleNode] 装载期叠压自愈(外缘钉签名,批次 307 存量损伤):",c.join("; "))}get layoutParams(){return{width:this.raw.layoutWidth??600,height:this.raw.layoutHeight??600,hGap:this.raw.hGap??12,vGap:this.raw.vGap??12,groupPadding:this.raw.groupPadding??0}}get maskChildren(){return this.children.filter(e=>e instanceof ae)}containsPoint(e,t,r=0){return super.containsPoint(e,t,r)?!0:this.visible?ct.prototype.containsPoint.call(this,e,t,r):!1}applyMaskParams(e){let t={};for(let[r,o]of Object.entries(e))if(o!==void 0){t[r]=o;for(let i of this.maskChildren)i.set({[r]:o})}Object.keys(t).length&&this.set(t)}updateGapParams(e){let t={};if(typeof e.hGap=="number"&&(t.hGap=e.hGap),typeof e.vGap=="number"&&(t.vGap=e.vGap),typeof e.groupPadding=="number"&&(t.groupPadding=e.groupPadding),!Object.keys(t).length)return;this.set(t);let r=Qn(this.raw.layoutConfig);r&&this.relayoutFromConfig(r,this.layoutParams)}updateLayout(e){let t=Qn(this.raw.layoutConfig);if(!t||!t.pieces.length){console.warn("[PuzzleNode] layoutConfig is invalid, skipping layout update");return}let r={...this.layoutParams};typeof e.width=="number"&&e.width>0&&(r.width=e.width),typeof e.height=="number"&&e.height>0&&(r.height=e.height),typeof e.hGap=="number"&&(r.hGap=e.hGap),typeof e.vGap=="number"&&(r.vGap=e.vGap),typeof e.groupPadding=="number"&&(r.groupPadding=e.groupPadding),this.set({hGap:r.hGap,vGap:r.vGap,groupPadding:r.groupPadding}),this.relayoutFromConfig(t,r),this.set({width:r.width,height:r.height})}editingMask=null;get editingMaskIndex(){return this.editingMask?this.maskChildren.indexOf(this.editingMask):-1}maskEdgeOnOuterBorder(e,t){let r=this.layoutParams,o=Math.max(0,r.width-r.groupPadding*2),i=Math.max(0,r.height-r.groupPadding*2),s=o/2,a=i/2,l=e.raw.left??0,c=e.raw.top??0,u=e.raw.width??0,h=e.raw.height??0,d=.5;return t==="left"?l-u/2<=-s+d:t==="right"?l+u/2>=s-d:t==="top"?c-h/2<=-a+d:c+h/2>=a-d}exitMaskEditing(){this.editingMask=null}removeCol(e){let t=Qn(this.raw.layoutConfig);if(!t||t.pieces.length!==this.maskChildren.length)return!1;let r=Oh(t.pieces,t.cols,e);return r?(t.cols-=1,this.applyPuzzleRemoval(t,r.removed)):!1}removeRow(e){let t=Qn(this.raw.layoutConfig);if(!t||t.pieces.length!==this.maskChildren.length)return!1;let r=Bh(t.pieces,t.rows,e);return r?(t.rows-=1,this.applyPuzzleRemoval(t,r.removed)):!1}removePiece(e){let t=Qn(this.raw.layoutConfig);if(!t||t.pieces.length!==this.maskChildren.length)return!1;let r=Wh(t.pieces,e);return r?this.applyPuzzleRemoval(t,r.removed):!1}applyPuzzleRemoval(e,t){if(!e)return!1;let r=new Set(t),o=this.children.filter(s=>!(s instanceof ae&&r.has(this.maskChildren.indexOf(s)))),i=o.filter(s=>s instanceof ae).map(s=>s.toObject());return this.children.length=0,this.children.push(...o),this.set({layoutConfig:{rows:e.rows,cols:e.cols,pieces:e.pieces},objects:i}),this.relayoutFromConfig(e,this.layoutParams),!0}toObject(){let e=super.toObject();return e.objects=this.children.map(t=>t.toObject()),e}relayoutFromConfig(e,t){let r=Sl(e,t);this.maskChildren.forEach((o,i)=>{let s=r[i];if(!s)return;let a=o.raw.width||s.w,l=o.raw.height||s.h;o.set({left:s.cx,top:s.cy,width:s.w,height:s.h});let c=o.clipImageRaw;if(c){let u=c.width||0,h=c.height||0;if(u&&h){let d=Math.max(a/u,l/h),f=Math.max(s.w/u,s.h/h),m=c.scaleX??1,p=d?m/d:1,b=f*(p||1);o.set({clipImage:{...c,scaleX:b,scaleY:b}})}typeof c.clipX=="number"&&o.set({clipImage:{...o.raw.clipImage,clipX:(c.clipX||0)*(a?s.w/a:1)}}),typeof c.clipY=="number"&&o.set({clipImage:{...o.raw.clipImage,clipY:(c.clipY||0)*(l?s.h/l:1)}})}}),this.set({layoutWidth:t.width,layoutHeight:t.height})}},Qi=n=>{if(!dt.has(se(n)))return null;let e=Number(n.cropX)||0,t=Number(n.cropY)||0;if(!(typeof n.cropX=="number"||typeof n.cropY=="number"||n.cropSizeMode==="visible"||e>0||t>0)||typeof n.width!="number"||typeof n.height!="number")return null;let o=n.cropSizeMode==="visible";return{sx:e,sy:t,sw:Math.max(0,o?n.width:n.width-e),sh:Math.max(0,o?n.height:n.height-t)}},Ct=n=>{if(!n||typeof n.type!="string")return null;let e=se(n);return e===L.TABLE?new ee(n,Ct):mi.has(e)?new le(n,Ct):ot.has(e)&&typeof n.src=="string"?new ae(n):e===L.GROUP?new J(n,Ct):pi.has(e)&&typeof n.src=="string"?new ie(n,"gif"):bi.has(e)&&typeof n.src=="string"?new ie(n,"video"):dt.has(e)&&typeof n.src=="string"?new ct(n):Xn.has(e)?new ct(n):rn.has(e)&&typeof n.text=="string"?new Se(n):e===L.PATH?new Pr(n):ft.has(e)?new kr(n):Gn.has(e)?new xn(n):null},Fl=n=>{let e=[],t={};for(let r of n){let o=Ct(r);o?e.push(o):r&&typeof r.type=="string"&&(t[r.type]=(t[r.type]||0)+1)}return{nodes:e,skippedTypes:t}},Je=(n,e)=>new Promise((t,r)=>{let o=new Image;e!==null&&(o.crossOrigin=e||"anonymous"),o.onload=()=>t(o),o.onerror=()=>r(new Error(`[engine] image load failed: ${n.slice(0,80)}`)),o.src=n}),Co=n=>{if(n instanceof J||n instanceof ae||n instanceof ie||n.isImageType)return null;let e=n.raw.mask;return!e||e.disabled===!0||typeof e.src!="string"||!e.src?null:e.src};var Vx=n=>typeof n!="string"||!n||/^cmyk\(/i.test(n)?null:n,yn=n=>{if(n&&typeof n=="object"&&!Array.isArray(n)){let e=n;if(typeof e.r!="number"||typeof e.g!="number"||typeof e.b!="number")return null;let t=r=>Math.max(0,Math.min(255,Math.round(r)));return`rgba(${t(e.r)}, ${t(e.g)}, ${t(e.b)}, 1)`}return Vx(n)},Ol=n=>n?.offsetEnable?{x:Number(n.offsetX)||0,y:Number(n.offsetY)||0}:{x:0,y:0},Mo=n=>{if(typeof n!="string")return;let e=n.trim().toLowerCase().replace(/\s*\([^)]*\)\s*$/,"").replace(/\s+/g,"-");if(!(!e||e==="normal"||e==="source-over")){if(e==="linear-dodge")return"lighter";if(/^[a-z-]+$/.test(e))return e}},Vt=(n,e={})=>{if(!n||typeof n!="object"||Array.isArray(n))return null;let t=n,r=l=>{if(!l||typeof l!="object")return!1;let c=l;return c.enabled!==!1&&c.showInDialog!==!1},o=[];if(Array.isArray(t.dropShadow))for(let l of t.dropShadow){if(!r(l))continue;let c=yn(l?.fill)??yn(l?.color)??"rgba(0,0,0,0.5)",u=Number(l?.blur)||0,h=Number(l?.offsetX)||0,d=Number(l?.offsetY)||0;!u&&!h&&!d||o.push({color:c,rgba:oe(c),blur:u,offsetX:h,offsetY:d,blendMode:Mo(l?.blendMode)})}let i=[];if(Array.isArray(t.innerShadow))for(let l of t.innerShadow){if(!r(l))continue;let c=yn(l?.fill)??yn(l?.color)??"rgba(0,0,0,0.5)",u=Number(l?.blur)||0,h=Number(l?.offsetX)||0,d=Number(l?.offsetY)||0;!u&&!h&&!d||i.push({color:c,rgba:oe(c),blur:u,offsetX:h,offsetY:d,blendMode:Mo(l?.blendMode)})}let s=[];if(Array.isArray(t.solidFill))for(let l of t.solidFill){if(!r(l))continue;let c=Number(l?.fillType)||0;if(c===1){if(!l?.fill||typeof l.fill!="object")continue;let h=Hn(l.fill);if(!h)continue;s.push({kind:"gradient",decl:h,offset:Ol(l),blendMode:Mo(l?.blendMode)});continue}if(c!==0)continue;let u=yn(l?.fill)??yn(l?.color);u&&s.push({kind:"solid",color:u,rgba:oe(u),offset:Ol(l),blendMode:Mo(l?.blendMode)})}let a=[];if(Array.isArray(t.stroke))for(let l of t.stroke){if(!r(l))continue;let c=l?.size&&typeof l.size=="object"?Number(l.size.value):0,u=e.text?c:Number(l?.strokeWidth)||c||0;if(!u)continue;let h=l?.fill&&typeof l.fill=="object"&&!Array.isArray(l.fill)?Hn(l.fill):null,d=yn(l?.fill)??yn(l?.color)??"#666666",f=l?.position||l?.strokeAlignment||(e.text?"center":"outside");a.push({kind:h?"gradient":"solid",color:d,rgba:oe(d),width:u,alignment:f,offset:Ol(l),blendMode:Mo(l?.blendMode),...h?{decl:h}:{}})}return o.length===0&&i.length===0&&s.length===0&&a.length===0?null:{dropShadows:o,innerShadows:i,solidFills:s,strokes:a}},Sn=n=>{let e=c=>String(Math.round(c*1e4)/1e4),t=c=>c.map(e).join(","),r=c=>c?`~${c}`:"",o=n.dropShadows.map(c=>`${t(c.rgba)}:${e(c.blur)}:${e(c.offsetX)}:${e(c.offsetY)}${r(c.blendMode)}`).join(";"),i=n.innerShadows.map(c=>`${t(c.rgba)}:${e(c.blur)}:${e(c.offsetX)}:${e(c.offsetY)}${r(c.blendMode)}`).join(";"),s=c=>{let u=`@${e(c.offset.x)},${e(c.offset.y)}${r(c.blendMode)}`;if(c.kind==="solid")return t(c.rgba)+u;let h=c.decl,d=h.stops.map(m=>`${e(m.offset)}@${m.color.map(e).join(",")}`).join(","),f=h.gradientTransform?h.gradientTransform.map(e).join(","):"-";return`g${h.kind[0]}:${e(h.x1)},${e(h.y1)},${e(h.x2)},${e(h.y2)},${e(h.r1)},${e(h.r2)},${h.gradientUnits},${f};${d}${u}`},a=n.solidFills.map(s).join(";"),l=n.strokes.map(c=>`${t(c.rgba)}:${e(c.width)}:${c.alignment}@${e(c.offset.x)},${e(c.offset.y)}${r(c.blendMode)}${c.decl?`~g${hi(c.decl)}`:""}`).join(";");return`psd|${o}|${i}|${a}|${l}`};var qx=512,Kx=new Set([L.QRCODE,L.BARCODE,L.ECHART,L.FABRIC_ECHART]),ld=n=>{let e=Vt(n.raw.effects);if(!e)return null;let t=e.dropShadows,r=e.strokes;return!t.length&&!r.length?null:{shadows:t,strokes:r,key:Sn(e)}},Qx=n=>n?`${n.sx},${n.sy},${n.sw},${n.sh}`:"none",Bl=new WeakMap,ad=n=>Math.max(1,Math.min(qx,Math.floor(n))),Zx=(n,e,t,r,o)=>{let i=ld(n);if(!i)return;let s=n.imageEl;if(!s)return;let a=n.dims,l=null;if(i.shadows.length){let h=Fi(n,i.shadows,s,1,n.cropRect);if(!h)throw new Error("fx mask: shadow bake unavailable");let d=h.canvas.getContext("2d",{willReadFrequently:!0});if(!d)throw new Error("fx mask: shadow ctx unavailable");l={data:d.getImageData(0,0,h.w,h.h).data,w:h.w,h:h.h}}let c=[];if(i.strokes.length){for(let h of mn(n,i.strokes,s,!0,1,n.cropRect)){let d=h.canvas.getContext("2d",{willReadFrequently:!0});if(!d)throw new Error("fx mask: stroke ctx unavailable");c.push({data:d.getImageData(0,0,h.w,h.h).data,w:h.w,h:h.h,dx:h.dx,dy:h.dy})}if(!c.length)throw new Error("fx mask: stroke bake unavailable")}let u=n.matrix;for(let h=0;h<r;h++)for(let d=0;d<t;d++){if(e[h*t+d])continue;let f=((d+.5)/t-.5)*a.x,m=((h+.5)/r-.5)*a.y;if(l){let p=Math.round(u[0]*f+u[2]*m+l.w/2),b=Math.round(u[1]*f+u[3]*m+l.h/2);if(p>=0&&b>=0&&p<l.w&&b<l.h&&l.data[(b*l.w+p)*4+3]>o){e[h*t+d]=1;continue}}for(let p of c){let b=Math.round(f-p.dx+p.w/2),x=Math.round(m-p.dy+p.h/2);if(b>=0&&x>=0&&b<p.w&&x<p.h&&p.data[(x*p.w+b)*4+3]>o){e[h*t+d]=1;break}}}},Jx=n=>{let e=n.imageEl,t=n.dims,r=n.cropRect,o=r?r.sw:e?.naturalWidth||0,i=r?r.sh:e?.naturalHeight||0;if(!e||!(t.x>0)||!(t.y>0)||!(o>0)||!(i>0))return{mask:new Uint8Array(0),maskW:0,maskH:0};let s=ad(t.x),a=ad(t.y),l=document.createElement("canvas");l.width=s,l.height=a;let c=new Uint8Array(0);try{let u=l.getContext("2d",{willReadFrequently:!0});if(u){u.drawImage(e,r?r.sx:0,r?r.sy:0,o,i,0,0,s,a);let h=Math.min(255,qi/Math.max(n.renderOpacity,1/255)),{data:d}=u.getImageData(0,0,s,a);c=new Uint8Array(s*a);for(let f=0;f<c.length;f++)d[f*4+3]>h&&(c[f]=1);Zx(n,c,s,a,h)}}catch{c=new Uint8Array(0)}finally{l.width=0,l.height=0}return{mask:c,maskW:c.length>0?s:0,maskH:c.length>0?a:0}},eg=n=>{let e=`${n.dims.x},${n.dims.y}|${Qx(n.cropRect)}|${n.renderOpacity}`,t=ld(n);if(!t)return e;let r=n.matrix,o=i=>Math.round(i*1e3)/1e3;return`${e}|${t.key}|${o(r[0])},${o(r[1])},${o(r[2])},${o(r[3])}`},tg=n=>{let e=eg(n),t=Bl.get(n);if(t&&t.stamp===e&&t.element===n.imageEl)return t.rec;let r=Jx(n);return Bl.set(n,{element:n.imageEl,stamp:e,rec:r}),r},ng=(n,e,t)=>{let r=tg(n);if(r.maskW===0||r.maskH===0)return!1;let o=n.dims,i=n.localPoint(e,t),s=i.x+o.x/2,a=i.y+o.y/2;if(s<0||a<0||s>=o.x||a>=o.y)return!0;let l=Math.min(r.maskW-1,Math.floor(s/o.x*r.maskW)),c=Math.min(r.maskH-1,Math.floor(a/o.y*r.maskH));return r.mask[c*r.maskW+l]===0},rg=(n,e,t,r)=>{for(let o of n.children)if(!(!o.visible||!o.containsPoint(e,t,r.strokeBandOf?.(o)??0))&&!Zi(o,e,t,r))return!0;return!1},Zi=(n,e,t,r)=>{if(n instanceof ee)return!1;let o=typeof n.raw.globalCompositeOperation=="string"?n.raw.globalCompositeOperation:"";return o==="multiply"&&!r.selection.includes(n)||o&&o!=="source-over"&&n.typeKey!==L.REFERENCELINE&&r.hasSelectableBelow()?!0:n instanceof le||n instanceof ae||n instanceof ie||n.isTextType||n.isLineType?!1:n instanceof J?!rg(n,e,t,r):!n.isImageType||Kx.has(n.typeKey)||typeof n.raw.name=="string"&&n.raw.name.toLowerCase()==="qrcode"||!dt.has(n.typeKey)?!1:ng(n,e,t)},og=n=>{Bl.delete(n)},Nr=(n,e,t,r)=>{for(let o=n.children.length-1;o>=0;o--){let i=n.children[o];if(!(!i.visible||i.raw.evented===!1||!i.containsPoint(e,t)||Zi(i,e,t,{selection:r,hasSelectableBelow:()=>{for(let a=o-1;a>=0;a--){let l=n.children[a];if(l.visible&&l.raw.evented!==!1&&l.containsPoint(e,t))return!0}return!1}})))return i instanceof J&&!(i instanceof ee)&&!(i instanceof le)?Nr(i,e,t,r)??i:i}return null};import ig from"rbush";var Wl=0,sg=()=>(Wl=(Wl+1)%4294967295,`tx-${Date.now().toString(36)}-${Wl.toString(36)}`),Ro=class{events=new Fn;_nodes=[];_index=new ig;_indexDirty=!1;_selection=[];_editingNode=null;_editingTextSnapshot="";_editingBeforeObject=null;_editingBitmapSnapshot=null;_editingTransient=!1;editSelection={start:0,end:0};skippedTypes={};get nodes(){return this._nodes}get selection(){return this._selection}get editingNode(){return this._editingNode}_selectionFrame=null;get selectionFrame(){return this._selectionFrame}setSelectionFrame(e){this._selectionFrame=e}get activeObject(){return this._selection[0]??null}_activeGroupChild=null;get activeGroupChild(){return this._activeGroupChild}setActiveGroupChild(e){let t=this._selection.length===1?this._selection[0]:null,r=e&&t instanceof J&&t.containsDeep(e)?e:null;if(this._activeGroupChild===r)return;let o=this._activeGroupChild;this._activeGroupChild=r,o&&this.events.fire("group:child-deactivated"),r&&this.events.fire("group:child-activated",r,t)}_groupEditingGroup=null;get groupEditing(){return this._groupEditingGroup!==null}get groupEditingGroup(){return this._groupEditingGroup}setGroupEditing(e,t){if(!e){this._groupEditingGroup=null;return}let r=t??(this._selection.length===1&&this._selection[0]instanceof J?this._selection[0]:null);this._groupEditingGroup=r&&!(r instanceof ee)&&!(r instanceof le)?r:null}_hovered=null;get hovered(){return this._hovered}setHovered(e){let r=e!==null&&this._nodes.some(o=>o===e||o instanceof J&&o.containsDeep(e))?e:null;this._hovered!==r&&(this._hovered=r)}_seamHover=null;get seamHover(){return this._seamHover}setSeamHover(e){let t=this._seamHover,r=e&&this._nodes.includes(e.puzzle)&&e.puzzle.maskChildren.includes(e.mask)?e:null;t?.puzzle===r?.puzzle&&t?.mask===r?.mask&&t?.handle===r?.handle||(this._seamHover=r)}loadObjects(e){let{nodes:t,skippedTypes:r}=Fl(e);this._nodes=t,this.skippedTypes=r;for(let o of t)this.attachRenderTracking(o);this.clearSelection(),this.rebuildIndex(),this.bumpStructure()}add(e){this._nodes.push(e),this.attachRenderTracking(e),this.markIndexDirty(),this.events.fire("object:added",e),this.bumpStructure()}remove(e){let t=this._nodes.indexOf(e);t>=0&&this._nodes.splice(t,1),this._selection=this._selection.filter(r=>r!==e),this._selectionFrame=null,this._activeGroupChild&&this.setActiveGroupChild(this._activeGroupChild),this._hovered&&this.setHovered(this._hovered),this.markIndexDirty(),this.events.fire("object:removed",e),this.bumpStructure()}insertAt(e,...t){let r=Math.max(0,Math.min(e,this._nodes.length));this._nodes.splice(r,0,...t);for(let o of t)this.attachRenderTracking(o);this.markIndexDirty();for(let o of t)this.events.fire("object:added",o);return this.bumpStructure(),this._nodes.length}moveNodeTo(e,t){let r=this._nodes.indexOf(e);if(r<0)return;this._nodes.splice(r,1);let o=Math.max(0,Math.min(t,this._nodes.length));this._nodes.splice(o,0,e),this.bumpStructure()}_structureVersion=1;_renderDirty=new Set;get structureVersion(){return this._structureVersion}get renderDirty(){return this._renderDirty}drainRenderDirty(){this._renderDirty.clear()}bumpStructure(){this._structureVersion++,this._renderDirty.clear()}attachRenderTracking(e){if(e._renderNotify=()=>{this._renderDirty.add(e)},e instanceof J)for(let t of e.children)this.attachRenderTracking(t)}findNodeDeep(e){let t=(r,o)=>{for(let i=0;i<r.length;i++){let s=r[i];if(s.id===e)return{node:s,parent:o,index:i};if(s instanceof J&&!(s instanceof ee)){let a=t(s.children,s);if(a)return a}}return null};return t(this._nodes,null)}setProps(e,t,r={}){let o="visible"in t;if(o&&t.visible===e.raw.visible&&Object.keys(t).length===1)return;let i=e.visible;e.set(t);let s=o&&e.visible!==i;s&&this.bumpStructure(),o&&!s&&Object.keys(t).length===1||this.markIndexDirty()}rebuildIndex(){let e=[];for(let t of this._nodes){if(!t.visible)continue;let r=t.bounds,o=this.strokeHitBand(t);e.push({minX:r.left-o,minY:r.top-o,maxX:r.right+o,maxY:r.bottom+o,node:t})}this._index.clear(),this._index.load(e),this._indexDirty=!1}commitGeometry(){this._indexDirty&&this.rebuildIndex()}refreshHitIndex(){this.rebuildIndex()}markIndexDirty(){this._indexDirty=!0}_hitZoom=1;setViewportZoom(e){!(e>0)||e===this._hitZoom||(this._hitZoom=e,this.rebuildIndex())}hitBandScene(){return Dl/this._hitZoom}strokeHitBand(e){return sd(e)?Math.max(Number(e.raw.padding)||0,Dl)/this._hitZoom:0}findTarget(e,t){this._indexDirty&&this.rebuildIndex();let r=this._index.search({minX:e,minY:t,maxX:e,maxY:t}),o=new Map;this._nodes.forEach((i,s)=>o.set(i,s)),r.sort((i,s)=>(o.get(s.node)??-1)-(o.get(i.node)??-1));for(let i=0;i<r.length;i++){let s=r[i].node,a=this.hitBandScene();if(!(!s.visible||s.raw.evented===!1||!s.containsPoint(e,t,a))&&!Zi(s,e,t,this.alphaHitContext(r,i,e,t)))return s}return null}alphaHitContext(e,t,r,o){let i=null,s=this.hitBandScene();return{selection:this._selection,strokeBandOf:()=>s,hasSelectableBelow:()=>(i===null&&(i=e.slice(t+1).some(a=>a.node.visible&&a.node.raw.evented!==!1&&a.node.containsPoint(r,o,s))),i)}}objectsIntersectingRect(e,t,r,o){this._indexDirty&&this.rebuildIndex();let i={minX:Math.min(e,r),minY:Math.min(t,o),maxX:Math.max(e,r),maxY:Math.max(t,o)},s=new Set(this._index.search(i).map(a=>a.node));return this._nodes.filter(a=>a.visible&&s.has(a)&&a.bounds.left<=i.maxX&&i.minX<=a.bounds.right&&a.bounds.top<=i.maxY&&i.minY<=a.bounds.bottom&&!a.syntheticOwner&&!Ar.has(String(a.raw.id??""))&&!Ze(a))}setSelection(e,t="create"){this._selection=e.filter(r=>this._nodes.includes(r)),this._selectionFrame=null,this._groupEditingGroup&&!(this._selection.length===1&&this._selection[0]===this._groupEditingGroup)&&(this._groupEditingGroup=null),this._hovered=null,this._selection.length===0?this.events.fire("selection:cleared"):t==="create"?this.events.fire("selection:created",[...this._selection]):this.events.fire("selection:updated",[...this._selection]),this._activeGroupChild&&this.setActiveGroupChild(this._activeGroupChild)}clearSelection(){this._activeGroupChild&&this.setActiveGroupChild(null),this._groupEditingGroup=null,this._hovered=null,this._selection.length!==0&&(this._selection=[],this._selectionFrame=null,this.events.fire("selection:cleared"))}_transformGestureAt=-1/0;get transformGestureAt(){return this._transformGestureAt}applyTransform(e,t,r,o){if(e.length){(r==="moving"||r==="scaling"||r==="rotating")&&(this._transformGestureAt=performance.now());for(let i of e)this.setProps(i,t(i),{deferIndexRebuild:!0});if(this.markIndexDirty(),r==="modified"){this.commitGeometry();let i=o?.before,s=i||o?.action||o?.transactionId?{action:o?.action,before:i?e.map(a=>i.get(a)).filter(a=>!!a):void 0,transactionId:o?.transactionId}:void 0;this.fireObjectModified([...e],s)}else this.events.fire(`object:${r}`,e[0])}}fireObjectModified(e,t){let r=t?.transactionId??sg();this.events.fire("object:modified",e,{...t,transactionId:r})}enterEditing(e,t={}){let r=this._nodes.find(i=>i===e||i instanceof J&&i.containsDeep(e));if(!r||this._editingNode===e)return;this._editingNode&&this.exitEditing(),this._editingNode=e,this._editingTransient=t.transient===!0,this._editingTextSnapshot=e.raw.text??"",this._editingBitmapSnapshot=typeof e.raw.renderSrc=="string"?{renderSrc:e.raw.renderSrc,renderRect:e.raw.renderRect}:null,this._editingBeforeObject=e.toObject();let o=this._editingTextSnapshot.length;this.editSelection.start=this.editSelection.end=o,t.transient||this.setSelection([r],"update"),this.events.fire("text:editing:entered",e)}exitEditing(){let e=this._editingNode;if(!e)return;let t=this._editingTransient;if(this._editingNode=null,this._editingTransient=!1,this.rebuildIndex(),this.events.fire("text:editing:exited",e),t){this._editingTextSnapshot="",this._editingBeforeObject=null,this._editingBitmapSnapshot=null;return}let r=e.raw.text??"";r!==this._editingTextSnapshot?(this.events.fire("text:editing:committed",e,this._editingTextSnapshot,r),this.fireObjectModified([e],{before:this._editingBeforeObject?[this._editingBeforeObject]:void 0})):this._editingBitmapSnapshot&&(e.raw.renderSrc=this._editingBitmapSnapshot.renderSrc,e.raw.renderRect=this._editingBitmapSnapshot.renderRect,e.markRenderDirty()),this._editingTextSnapshot="",this._editingBeforeObject=null,this._editingBitmapSnapshot=null}updateEditingText(e,t,r){let o=this._editingNode;o&&(o.set({text:e}),this.syncEditSelection(t,r),this.markIndexDirty(),this.events.fire("text:changed",o))}updateEditingSelection(e,t){this._editingNode&&this.syncEditSelection(e,t)}syncEditSelection(e,t){let r=this._editingNode.textLayout.graphemeCodeUnitOffsets;this.editSelection.start=cd(r,e),this.editSelection.end=cd(r,t)}toObjects(){return this._nodes.filter(e=>!e.syntheticOwner).map(e=>e.toObject())}},cd=(n,e)=>{let t=0,r=n.length-1;for(;t<r;){let o=t+r+1>>1;n[o]<=e?t=o:r=o-1}return t};var Ji=n=>typeof n!="string"||n.length===0?!1:/^data:image\/svg\+xml/i.test(n)?!0:/\.svg(?:[?#]|$)/i.test(n),ud=(n,e,t,r=4096)=>{let o=Math.max(n.w,n.h);if(!(o>0)||!(t>=1))return{factor:1,needsRaster:!1};let i=Math.max(e.w/n.w,e.h/n.h);if(!(i>0)||!Number.isFinite(i))return{factor:1,needsRaster:!1};let s=1;for(;s*2*o<=r;)s*=2;let a=1;for(;a<i-1e-9&&a<s;)a*=2;return a===t?{factor:t,needsRaster:!1}:{factor:a,needsRaster:!0}},hd=(n,e)=>{let t=n.naturalWidth||n.width,r=n.naturalHeight||n.height,o=document.createElement("canvas");o.width=Math.max(1,Math.round(t*e)),o.height=Math.max(1,Math.round(r*e));let i=o.getContext("2d");return i&&(i.imageSmoothingEnabled=!0,i.imageSmoothingQuality="high",i.drawImage(n,0,0,o.width,o.height)),o};var es=(n,e)=>{if(n.children.includes(e))return[n];for(let t of n.children)if(t instanceof J&&!(t instanceof ee)&&!(t instanceof le)){let r=es(t,e);if(r.length)return[...r,n]}return[]},dd=n=>{let e=n.matrix,t=n.ownMatrix,r=ve(e),o=(i,s,a)=>Q(i,s,a,!0);return(i,s)=>{let a=o(r,i,s);return o(t,a.x,a.y)}},fd=n=>{let e=1/0,t=1/0,r=-1/0,o=-1/0;for(let i of n.children){if(!i.visible)continue;let s=i.contentBoxCorners();for(let a of[s.tl,s.tr,s.br,s.bl])a.x<e&&(e=a.x),a.y<t&&(t=a.y),a.x>r&&(r=a.x),a.y>o&&(o=a.y)}return Number.isFinite(e)?{minX:e,minY:t,maxX:r,maxY:o}:null},md=n=>{let e=fd(n);if(!e)return null;let t=n.matrix;return{tl:Q(t,e.minX,e.minY),tr:Q(t,e.maxX,e.minY),br:Q(t,e.maxX,e.maxY),bl:Q(t,e.minX,e.maxY)}},ts=n=>{let e=[];for(let t=0;t<n.length;t++){let r=n[t],o=fd(r);if(!o)continue;let i=o.maxX-o.minX,s=o.maxY-o.minY,a={x:(o.minX+o.maxX)/2,y:(o.minY+o.maxY)/2},l=new Map;for(let m of r.children){let p=m.aCoords;l.set(m,{x:(p.tl.x+p.br.x)/2,y:(p.tl.y+p.br.y)/2})}let c=Q(r.matrix,a.x,a.y),u=n[t+1]??null,h=u?Q(ve(u.matrix),c.x,c.y):c,d=xe({...r.raw,width:i,height:s},h);r.set({width:i,height:s,left:d.x,top:d.y});let f=ve(r.matrix);for(let m of r.children){let p=l.get(m);if(!p)continue;let b=Q(f,p.x,p.y),x=xe({...m.raw,width:m.dims.x,height:m.dims.y},b);m.set({left:x.x,top:x.y})}e.push(r,...r.children)}return e};var Hl=["tl","tr","bl","br"],vn=new Set(Hl),ns=["tlS","trS","blS","brS"],ag=new Set(ns),Po={tlS:"tl",trS:"tr",blS:"bl",brS:"br"},lg=new Set(["ml","mr","mt","mb"]),tr={ml:"x",mr:"x",mt:"y",mb:"y"},rs={ml:"left",mr:"right",mt:"top",mb:"bottom"},nr=n=>lg.has(n),os=n=>vn.has(n),Lr=n=>ag.has(n);var Mn=8,rr=12,Mt=1.5,pd=24,cg=["lockMovementX","lockMovementY","lockScalingX","lockScalingY","lockSkewingX","lockSkewingY","lockRotation"],at=n=>{let e=n.raw;return cg.some(t=>!!e[t])},cs=28,Gl=null,ug=()=>{if(Gl)return Gl;let n=document.createElement("canvas");n.width=cs*2,n.height=cs*2;let e=n.getContext("2d");if(e){e.scale(2,2);let t=cs/2;e.beginPath(),e.arc(t,t,12,0,Math.PI*2),e.fillStyle="#ffffff",e.fill(),e.strokeStyle="#e0e0e0",e.lineWidth=4/3,e.stroke(),typeof Path2D<"u"&&(e.translate(t,t),e.scale(2/3,2/3),e.translate(-12,-12),e.beginPath(),e.strokeStyle="#2c2c2c",e.lineWidth=2,e.lineCap="round",e.lineJoin="round",e.stroke(new Path2D("M5 13a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2v6a2 2 0 0 1 -2 2h-10a2 2 0 0 1 -2 -2v-6z M11 16a1 1 0 1 0 2 0a1 1 0 0 0 -2 0 M8 11v-4a4 4 0 1 1 8 0v4")))}return Gl=n,n},us=28,hg="M706.144 847.264A384.32 384.32 0 0 0 896 515.84c0-118.016-53.504-227.136-143.776-299.616a32 32 0 0 1 40.064-49.92A447.136 447.136 0 0 1 960 515.84c0 166.528-91.424 313.6-228.672 390.784l34.624 81.6-270.464-29.28 168.768-210.368 41.888 98.688zM320.736 182.72A384.288 384.288 0 0 0 128 515.84a383.36 383.36 0 0 0 157.76 310.304 32 32 0 0 1-37.728 51.712A447.36 447.36 0 0 1 64 515.84 448.32 448.32 0 0 1 294.56 123.968L261.664 50.112l268.928 20.032-163.04 217.76-46.816-105.184z",Xl=null,dg=()=>{if(Xl)return Xl;let n=document.createElement("canvas");n.width=us*2,n.height=us*2;let e=n.getContext("2d");if(e){e.scale(2,2);let t=us/2;e.fillStyle="#ffffff",e.beginPath(),e.arc(t,t,10,0,Math.PI*2),e.shadowColor="#333",e.shadowBlur=2,e.fill(),e.shadowColor="",e.shadowBlur=0,typeof Path2D<"u"&&(e.translate(t-8-1.392,t-8-.89),e.scale(.0178,.0178),e.fillStyle="black",e.fill(new Path2D(hg)))}return Xl=n,n};var fg=24,hs=20,xd=16,mg="M607.573333 295.908693h-184.32l92.16-92.16zM515.413333 813.42464l-92.16-92.16h184.32l-92.16 92.16M210.57536 508.586667l92.16-92.16v184.32l-92.16-92.16M820.251307 508.586667l-92.16 92.16v-184.32l92.16 92.16M446.88384 507.405653c0 37.195093 30.153387 67.345067 67.345067 67.345067 37.198507 0 67.351893-30.149973 67.351893-67.345067s-30.153387-67.345067-67.34848-67.345066c-37.195093 0-67.345067 30.149973-67.345067 67.345066z",zl=null,pg=()=>{if(zl)return zl;let n=document.createElement("canvas");n.width=hs*2,n.height=hs*2;let e=n.getContext("2d");if(e){e.scale(2,2);let t=hs/2;e.beginPath(),e.arc(t,t,8,0,Math.PI*2),e.strokeStyle="#2c2c2c",e.lineWidth=2,e.stroke(),e.fillStyle="#ffffff",e.fill(),typeof Path2D<"u"&&(e.translate(t-8,t-8),e.scale(16/1024,16/1024),e.fillStyle="#2c2c2c",e.fill(new Path2D(mg)))}return zl=n,n},jl=n=>{if(n.selection.length!==1)return null;let e=n.selection[0];if(e instanceof ee||e instanceof le)return null;let t=e.typeKey;return ft.has(t)||ot.has(t)||at(e)?null:e},Vl=(n,e,t)=>bs(n,e,t,{x:.5,y:0,offsetX:fg,offsetY:0}),Tn=3,Yl=new Map,bg=n=>{let e=Yl.get(n);if(e)return e;let t=document.createElement("canvas"),r=t.getContext("2d"),o=`bold ${14*Tn}px Helvetica, Arial, sans-serif`;if(!r)return t.width=Math.max(1,Math.round((n.length*14*.6+16)*Tn)),t.height=Math.round(30*Tn),Yl.set(n,t),t;r.font=o;let i=r.measureText(n).width,s=8*Tn;t.width=Math.max(1,Math.ceil(i)+s*2),t.height=Math.ceil(30*Tn),r.font=o;let a=6*Tn;return r.beginPath(),r.moveTo(a,0),r.lineTo(t.width-a,0),r.arcTo(t.width,0,t.width,a,a),r.lineTo(t.width,t.height-a),r.arcTo(t.width,t.height,t.width-a,t.height,a),r.lineTo(a,t.height),r.arcTo(0,t.height,0,t.height-a,a),r.lineTo(0,a),r.arcTo(0,0,a,0,a),r.closePath(),r.fillStyle="rgba(44, 44, 44, 0.9)",r.fill(),r.fillStyle="#ffffff",r.textAlign="center",r.textBaseline="middle",r.fillText(n,t.width/2,t.height/2),Yl.set(n,t),t},xg=(n,e,t)=>{let r=bg(`${Math.round(e)}°`);return{matrix:[1,0,0,1,n.x,n.y],dims:{x:r.width/Tn/t,y:r.height/Tn/t},color:[1,1,1,1],texture:r}},st=oe("#2f6fed"),ko=oe("#ffffff"),is=oe("#2f6fed"),ql=st,ss=(n,e)=>({x:(n.x+e.x)/2,y:(n.y+e.y)/2}),Re=(n,e,t,r)=>{let o=(n.x+e.x)/2,i=(n.y+e.y)/2,s=Math.hypot(e.x-n.x,e.y-n.y),a=Math.atan2(e.y-n.y,e.x-n.x),l=Math.cos(a),c=Math.sin(a);return{matrix:[l,c,-c,l,o,i],dims:{x:s,y:t},color:r}},En=(n,e,t,r)=>{let o=r*Math.PI/180,i=Math.cos(o),s=Math.sin(o);return{matrix:[i,s,-s,i,n.x,n.y],dims:{x:e,y:e},color:t}},gg=n=>{let e=n.angle*Math.PI/180,t=Math.cos(e),r=Math.sin(e),o=n.width/2,i=n.height/2,s=(a,l)=>({x:n.center.x+t*a-r*l,y:n.center.y+r*a+t*l});return{tl:s(-o,-i),tr:s(o,-i),br:s(o,i),bl:s(-o,i)}},et=n=>{let e=n.selection;if(e.length===0)return null;if(e.length===1){let a=e[0];return{quad:a.aCoords,angle:a.raw.angle??0}}let t=n.selectionFrame;if(t)return{quad:gg(t),angle:t.angle};let r=1/0,o=1/0,i=-1/0,s=-1/0;for(let a of e){let l=a.bounds;r=Math.min(r,l.left),o=Math.min(o,l.top),i=Math.max(i,l.right),s=Math.max(s,l.bottom)}return{quad:{tl:{x:r,y:o},tr:{x:i,y:o},br:{x:i,y:s},bl:{x:r,y:s}},angle:0}},_r=(n,e,t=1,r)=>{let o=ss(n.tl,n.tr),i=ss(n.tr,n.br),s=ss(n.bl,n.br),a=ss(n.tl,n.bl),l=Ig(n,e,t),c=[{id:"tl",x:n.tl.x,y:n.tl.y},{id:"tr",x:n.tr.x,y:n.tr.y},{id:"br",x:n.br.x,y:n.br.y},{id:"bl",x:n.bl.x,y:n.bl.y},{id:"mt",x:o.x,y:o.y},{id:"mr",x:i.x,y:i.y},{id:"mb",x:s.x,y:s.y},{id:"ml",x:a.x,y:a.y},{id:"mtr",x:l.x,y:l.y}],u=r?Tg(r,t):[];return u.length?[...u,...c]:c},yg=32,Sg=.25,fs=14,gd=n=>n<=0?0:Math.min(yg,n*Sg),yd=(n,e)=>{if(e<=0)return 0;let t=Math.max(0,Math.min(e,n)),r=gd(e);return r<=0||e<=r?t:r+t/e*(e-r)},Kl=(n,e)=>{if(e<=0)return 0;let t=Math.max(0,Math.min(e,n)),r=gd(e);return r<=0||e<=r?t:t<=r?0:(t-r)/(e-r)*e},ms=n=>!!n&&n.typeKey===L.FABRICRECT,vg=new Set([L.QRCODE,L.BARCODE,L.ECHART,L.FABRIC_ECHART]),Ao=n=>{if(!n)return!1;let e=se(n.raw);return!vg.has(e)&&(e===L.IMAGE||e===L.SVGIMAGE||e===L.CROPIMAGE)},Sd=n=>{let e=Math.max(Math.abs(n.raw.scaleX??1)||1,1e-4),t=Math.max(Math.abs(n.raw.scaleY??1)||1,1e-4);return Math.min(n.dims.x*e,n.dims.y*t)/2},wg=(n,e)=>{let t=n.aCoords,r=Math.hypot(t.tr.x-t.tl.x,t.tr.y-t.tl.y)*e,o=Math.hypot(t.bl.x-t.tl.x,t.bl.y-t.tl.y)*e;return r>Ir&&o>Ir},Tg=(n,e)=>wg(n,e)?ms(n)?Eg(n,e):Ao(n)?Cg(n,e):[]:[],Eg=(n,e)=>{let t=n.raw,r=Math.max(Math.abs(t.scaleX??1)||1,1e-4),o=Math.max(Math.abs(t.scaleY??1)||1,1e-4),i=n.dims.x/2,s=n.dims.y/2,a=i*r,l=s*o,c=Math.min(a,l),u=Math.max(0,Math.min(c,t.radius??0)),h=yd(u,c),d=Math.max(0,(fs-h*e)/e),f=Math.max(0,(fs-h*e)/e),m=h+Math.min(d,Math.max(0,a-h)),p=h+Math.min(f,Math.max(0,l-h)),b=n.matrix;return ns.map(x=>{let g=Po[x],y=g==="tl"||g==="bl",v=g==="tl"||g==="tr",S=(y?-a+m:a-m)/r,w=(v?-l+p:l-p)/o;return{id:x,x:b[0]*S+b[2]*w+b[4],y:b[1]*S+b[3]*w+b[5]}})},Cg=(n,e)=>{let t=n.raw,r=n.dims.x/2,o=n.dims.y/2,i=Math.min(r,o),s=Math.max(0,Math.min(i,Math.max(t.rx??0,t.ry??0))),a=yd(s,i),l=Math.max(Math.abs(t.scaleX??1)||1,1e-4),c=Math.max(Math.abs(t.scaleY??1)||1,1e-4),u=l*e,h=c*e,d=Math.min(Math.max(0,(fs-a*u)/u),Math.max(0,r-a)),f=Math.min(Math.max(0,(fs-a*h)/h),Math.max(0,o-a)),m=n.matrix;return ns.map(p=>{let b=Po[p],x=b==="tl"||b==="bl",g=b==="tl"||b==="tr",y=x?-r+a+d:r-a-d,v=g?-o+a+f:o-a-f;return{id:p,x:m[0]*y+m[2]*v+m[4],y:m[1]*y+m[3]*v+m[5]}})},ds=12,as=null,Mg=()=>{if(as)return as;let n=document.createElement("canvas");n.width=ds*2,n.height=ds*2;let e=n.getContext("2d");if(e){e.scale(2,2);let t=ds/2,r=Mn/2;e.beginPath(),e.arc(t,t,r+Mt,0,Math.PI*2),e.fillStyle=`rgb(${st[0]*255},${st[1]*255},${st[2]*255})`,e.fill(),e.beginPath(),e.arc(t,t,r,0,Math.PI*2),e.fillStyle=`rgb(${ko[0]*255},${ko[1]*255},${ko[2]*255})`,e.fill()}return as=n,as},vd=16,wn=4,bd={tlr:{x:-.5,y:-.5,offsetX:-wn,offsetY:-wn},trr:{x:.5,y:-.5,offsetX:wn,offsetY:-wn},brr:{x:.5,y:.5,offsetX:wn,offsetY:wn},blr:{x:-.5,y:.5,offsetX:-wn,offsetY:wn}},Ql={tlr:0,trr:90,brr:180,blr:270},Ir=50,Zl=(n,e)=>({width:Math.hypot(n.tr.x-n.tl.x,n.tr.y-n.tl.y)*e,height:Math.hypot(n.bl.x-n.tl.x,n.bl.y-n.tl.y)*e}),Rg=(n,e)=>{let{width:t,height:r}=Zl(n,e);return t>Ir&&r>Ir},Pg=new Set(["mr","br","mtr"]),kg=new Set(["mr","br"]),Ag=new Set(["mr","br","mtr"]),Ng=new Set(["ml","mr","tl","tr","bl","br","tlS","trS","blS","brS"]),Lg=new Set(["mt","mb","tl","tr","bl","br","mtr","tlS","trS","blS","brS"]),wd=(n,e,t)=>{let r=e<=Ir,o=t<=Ir;return!r&&!o?!0:r&&o?Pg.has(n):!(r&&Ng.has(n)&&!kg.has(n)||o&&Lg.has(n)&&!Ag.has(n))},Td=n=>n instanceof le||n instanceof ee||ot.has(n.typeKey),No=(n,e,t,r,o)=>{let i=_r(e,t,r,o),s=n.selection.length===1?n.selection[0]:null;if(!s||Td(s))return i;let a=ft.has(s.typeKey),l=Zl(e,r);return i.filter(c=>a&&(c.id==="ml"||c.id==="mr")||wd(c.id,l.width,l.height))},Jl=(n,e)=>{let t=n.aCoords,r=n.worldAngle,o=_r(t,r,e);if(Td(n))return o;let i=ft.has(n.typeKey),s=Zl(t,e);return o.filter(a=>i&&(a.id==="ml"||a.id==="mr")||wd(a.id,s.width,s.height))},Ed=(n,e,t)=>Rg(n,t)?Object.keys(bd).map(r=>{let o=bs(n,e,t,bd[r]);return{id:r,x:o.x,y:o.y}}):[],ps=n=>{let e=n*Math.PI/180,t=Math.sin(e),r=Math.cos(e);if(Math.abs(t)>=Math.abs(r)){let i=Math.sign(t);return{x:i/2,y:0,offsetX:i*pd,offsetY:0}}let o=Math.sign(r);return{x:0,y:o/2,offsetX:0,offsetY:o*pd}},bs=(n,e,t,r)=>{let o=(n.tl.x+n.br.x)/2,i=(n.tl.y+n.br.y)/2,s=Math.hypot(n.tr.x-n.tl.x,n.tr.y-n.tl.y),a=Math.hypot(n.bl.x-n.tl.x,n.bl.y-n.tl.y),l=r.x*s+r.offsetX/t,c=r.y*a+r.offsetY/t,u=e*Math.PI/180,h=Math.cos(u),d=Math.sin(u);return{x:o+l*h-c*d,y:i+l*d+c*h}},Ig=(n,e,t)=>bs(n,e,t,ps(e)),Cn=(n,e)=>{let t=Mt/e;return[Re(n.tl,n.tr,t,st),Re(n.tr,n.br,t,st),Re(n.br,n.bl,t,st),Re(n.bl,n.tl,t,st)]},_g=3,ls=(n,e,t,r,o)=>{let i=e.x-n.x,s=e.y-n.y,a=Math.hypot(i,s);if(a<=0)return[];let l=i/a,c=s/a,u=_g/o,h=[];for(let d=0;d<a;d+=u*2){let f=Math.min(d+u,a);h.push(Re({x:n.x+l*d,y:n.y+c*d},{x:n.x+l*f,y:n.y+c*f},t,r))}return h},xs=(n,e)=>{let t=Mt/e;return[...ls(n.tl,n.tr,t,st,e),...ls(n.tr,n.br,t,st,e),...ls(n.br,n.bl,t,st,e),...ls(n.bl,n.tl,t,st,e)]},Dg=(n,e,t,r)=>{let o=Mt/r,i=Mn/r;for(let s of e)s.id==="mtr"?n.push({...En(s,us/r,[1,1,1,1],t),texture:dg()}):Lr(s.id)?n.push({...En(s,ds/r,[1,1,1,1],t),texture:Mg()}):(n.push(En(s,i,st,t)),n.push(En(s,i-2*o,ko,t)))},Ul=(n,e,t,r,o,i)=>{if(i?.spec){let s=e.find(l=>l.id==="mtr"),a=bs(t,r,o,i.spec);s.x=a.x,s.y=a.y}Dg(n,e,r,o),i&&n.push(xg(i.center,r,o))},Cd=(n,e,t=null,r=!1)=>{if(n.selection.length===1&&Ze(n.selection[0]))return[];let o=et(n);if(!o)return[];let{quad:i,angle:s}=o,a=[],l=n.activeGroupChild,c=l&&n.groupEditing&&n.selection[0]instanceof J&&!(n.selection[0]instanceof ee)&&!(n.selection[0]instanceof le)?n.selection[0]:null,h=(c?md(c):null)??i;if(l)a.push(...Cn(l.aCoords,e)),a.push(...xs(h,e));else{if(n.selection.length>=2)for(let d of n.selection)a.push(...Cn(d.aCoords,e));a.push(...Cn(i,e))}if(n.selection.length===1&&at(n.selection[0]))return a.push({...En(i.br,cs/e,[1,1,1,1],s),texture:ug()}),a;if(Ul(a,No(n,h,s,e,Lo(n)),h,s,e,t?.onChild?null:t),l&&n.groupEditing&&Ul(a,Jl(l,e),l.aCoords,l.worldAngle,e,t?.onChild?t:null),r&&jl(n)){let d=Vl(h,s,e);a.push({...En(d,hs/e,[1,1,1,1],0),texture:pg()})}return a},Lo=n=>{if(n.selection.length!==1)return null;let e=n.selection[0];return ms(e)||Ao(e)?e:null},Md=(n,e)=>{let t=Mt/e,r={x:n.left,y:n.top},o={x:n.right,y:n.top},i={x:n.right,y:n.bottom},s={x:n.left,y:n.bottom};return[Re(r,o,t,is),Re(o,i,t,is),Re(i,s,t,is),Re(s,r,t,is)]},Io=n=>{let e=n.editingMask;if(!e)return[];let t=e.aCoords;return _r(t,e.worldAngle).filter(o=>nr(o.id)?!n.maskEdgeOnOuterBorder(e,rs[o.id]):!1)},Rd=(n,e,t=null)=>{let r=n.editingMask;if(!r)return[];let o=r.worldAngle,i=Cn(r.aCoords,e),s=Mt/e,a=Mn/e;for(let c of Io(n))i.push(En(c,a,st,o)),i.push(En(c,a-2*s,ko,o));let l=n.raw.angle??0;return i.push(...xs(n.aCoords,e)),Ul(i,_r(n.aCoords,l),n.aCoords,l,e,t),i},Fg=2.5,$l=(n,e,t)=>{let r=e.aCoords,o=t==="mr"?{p1:r.tr,p2:r.br}:{p1:r.bl,p2:r.br},i=n.layoutParams,s=t==="mr"?i.hGap:i.vGap;if(s>0){let a=(o.p1.x+o.p2.x)/2,l=(o.p1.y+o.p2.y)/2,c=(r.tl.x+r.br.x)/2,u=(r.tl.y+r.br.y)/2,h=a-c,d=l-u,f=Math.hypot(h,d)||1,m=s/2*(t==="mr"?n.worldScale.x:n.worldScale.y);return{mask:e,handle:t,p1:{x:o.p1.x+h/f*m,y:o.p1.y+d/f*m},p2:{x:o.p2.x+h/f*m,y:o.p2.y+d/f*m}}}return{mask:e,handle:t,p1:o.p1,p2:o.p2}},ec=n=>{let e=[];for(let i of n.maskChildren)i.visible&&(n.maskEdgeOnOuterBorder(i,"right")||e.push($l(n,i,"mr")),n.maskEdgeOnOuterBorder(i,"bottom")||e.push($l(n,i,"mb")));let t=n.layoutParams,r=Math.max(t.hGap,t.vGap)+1,o=[];for(let i of e){let s=o.find(a=>{let l=a.p2.x-a.p1.x,c=a.p2.y-a.p1.y,u=Math.hypot(l,c)||1,h=l/u,d=c/u;if(Math.abs((i.p2.x-i.p1.x)*d-(i.p2.y-i.p1.y)*h)/Math.max(1e-9,Math.hypot(i.p2.x-i.p1.x,i.p2.y-i.p1.y))>1e-6||Math.abs((i.p1.x-a.p1.x)*d-(i.p1.y-a.p1.y)*h)>.5)return!1;let m=(i.p1.x-a.p1.x)*h+(i.p1.y-a.p1.y)*d,p=(i.p2.x-a.p1.x)*h+(i.p2.y-a.p1.y)*d,b=Math.min(m,p),x=Math.max(m,p);return b<=u+r&&x>=-r});if(s){let a=s.p2.x-s.p1.x,l=s.p2.y-s.p1.y,c=Math.hypot(a,l)||1,u=a/c,h=l/c,d=[0,c,(i.p1.x-s.p1.x)*u+(i.p1.y-s.p1.y)*h,(i.p2.x-s.p1.x)*u+(i.p2.y-s.p1.y)*h],f=Math.min(...d),m=Math.max(...d);s.p1={x:s.p1.x+u*f,y:s.p1.y+h*f},s.p2={x:s.p1.x+u*(m-f),y:s.p1.y+h*(m-f)}}else o.push({...i})}return o},Pd=(n,e,t)=>ec(n).find(o=>o.mask===e&&o.handle===t)??$l(n,e,t),kd=(n,e)=>[Re(n.p1,n.p2,Fg/e,ql)],Og=oe("#3c7eff"),Bg=2,Wg=(n,e,t)=>{let r=e.x-n.x,o=e.y-n.y,i=Math.hypot(r,o)||1,s=-o/i,a=r/i,l={x:(n.x+e.x)/2,y:(n.y+e.y)/2};return(l.x+s-t.x)*s+(l.y+a-t.y)*a>=0?{x:s,y:a}:{x:-s,y:-a}},Ad=(n,e)=>{let t=n.aCoords,r=[t.tl,t.tr,t.br,t.bl],o={x:(t.tl.x+t.br.x)/2,y:(t.tl.y+t.br.y)/2},i=r.map((c,u)=>Wg(c,r[(u+1)%4],o)),s=n.bounds,a=Math.min(Bg,(s.right-s.left)*e,(s.bottom-s.top)*e)/e;if(a<=0)return[];let l=[];for(let c=0;c<4;c++){let u=r[c],h=r[(c+1)%4],d=i[c];l.push(Re({x:u.x-d.x*a/2,y:u.y-d.y*a/2},{x:h.x-d.x*a/2,y:h.y-d.y*a/2},a,Og))}return l};function Nd(n,e,t,r){let o=n.selection.map(l=>l.id),i=et(n);if(!i||n.editingNode||e)return{ids:o,handles:[]};let s=n.selection.length===1&&n.selection[0]instanceof le?n.selection[0]:null,a=s?.editingMask?[...Io(s).map(l=>{let c=r(l.x,l.y);return{id:l.id,x:c.x,y:c.y}}),..._r(i.quad,i.angle,t).map(l=>{let c=r(l.x,l.y);return{id:l.id,x:c.x,y:c.y}})]:No(n,i.quad,i.angle,t,Lo(n)).map(l=>{let c=r(l.x,l.y);return{id:l.id,x:c.x,y:c.y}});return{ids:o,handles:a}}function Ld(n){let e=n.activeGroupChild;if(!e)return null;let t=n.selection[0];return!(t instanceof J)||!t.containsDeep(e)?null:{rootId:t.id,childId:e.id}}function Id(n,e){let t=[],r=o=>{for(let i of o){if(i instanceof J&&r(i.children),!i.imageEl||!Ji(i.raw.src))continue;let s=i.imageEl.naturalWidth||i.imageEl.width,a=i.imageEl.naturalHeight||i.imageEl.height,l=e(i);t.push({id:i.id,type:i.raw.type,factor:l,rasterWidth:Math.round(s*(l??1)),rasterHeight:Math.round(a*(l??1))})}};return r(n.nodes),t}function _d(n){return n.nodes.map(e=>({id:e.id,type:e.raw.type,left:e.raw.left??0,top:e.raw.top??0,width:e.raw.width??0,height:e.raw.height??0,scaleX:e.raw.scaleX??1,scaleY:e.raw.scaleY??1,angle:e.raw.angle??0,visible:e.visible,bounds:e.bounds,aCoords:e.aCoords}))}function Dd(n,e){e();let t=performance.now();for(let o=0;o<n;o++)e();let r=(performance.now()-t)/n;return oi("engine.render.avgMeasured",r),r}function Fd(n){let e=n.width,t=n.height,r=document.createElement("canvas");r.width=e,r.height=t;let o=r.getContext("2d");o.drawImage(n,0,0);let i=o.getImageData(0,0,e,t);return{width:e,height:t,data:i.data}}var Hg=2,Ne={drag:"drag",scale:"scale",rotate:"rotate",cornerRadius:"cornerRadius",crop:"crop",tableCellEdit:"table-cell-edit",warpImage:"warpvas-image"},Gg=(n,e)=>{let{bus:t,wrap:r,syncSelection:o,settleSnap:i}=e,s=n.events,a=(u,h)=>{let d=h.map(r);o(),t.fire(u,{selected:d,deselected:[],target:d[0]})},l=(u,h)=>{h.syntheticOwner||t.fire(u,{target:r(h)})},c=[s.on("selection:created",u=>a("selection:created",u)),s.on("selection:updated",u=>a("selection:updated",u)),s.on("selection:cleared",()=>{o(),t.fire("selection:cleared",{selected:[],deselected:[]})}),s.on("object:added",u=>l("object:added",u)),s.on("object:removed",u=>l("object:removed",u)),s.on("object:moving",u=>{i?.(),l("object:moving",u)}),s.on("object:scaling",u=>l("object:scaling",u)),s.on("object:rotating",u=>l("object:rotating",u)),s.on("object:cornerRadius",u=>l("object:cornerRadius",u)),s.on("object:modified",(u,h)=>{let d=u.map((x,g)=>x.syntheticOwner?-1:g).filter(x=>x>=0);if(!d.length)return;let f=d.map(x=>r(u[x])),m=h?.before,p=m?.length?d.map(x=>m[x]).filter(x=>!!x):void 0,b=p&&(p.length>1||d.length>1)?{original:{objects:p}}:p?{original:p[0]}:void 0;t.fire("object:modified",{target:f[0],targets:f,transform:b,action:h?.action,transactionId:h?.transactionId,protocolVersion:2})}),s.on("text:editing:entered",u=>l("text:editing:entered",u)),s.on("text:editing:exited",u=>l("text:editing:exited",u)),s.on("text:changed",u=>l("text:changed",u)),s.on("text:editing:committed",(u,h,d)=>{t.fire("text:editing:committed",{target:r(u),before:h,after:d})}),s.on("smartobject:open-requested",u=>l("smartobject:open-requested",u)),s.on("image:replace-requested",u=>l("image:replace-requested",u)),s.on("lock:unlock-requested",u=>l("lock:unlock-requested",u)),s.on("path:active-anchor-change",(u,h)=>{t.fire("path:active-anchor-change",{target:r(u),key:h})}),s.on("group:child-activated",u=>{o(),t.fire("group:child-activated",{target:r(u)})}),s.on("group:child-deactivated",()=>{o(),t.fire("group:child-deactivated")}),s.on("table:cellselection",u=>{t.fire("table:cellselection",{target:r(u)})})];return()=>c.forEach(u=>u())};function Od(n,e){let t=n.nodes.filter(r=>r.visible&&!Ar.has(String(r.raw.id??""))&&!Ze(r));return n.setSelection(t),e(),t.length}function Bd(n,e){let t=[...n.selection];for(let r of t)n.remove(r);return t.length&&e(),t.length}function Wd(n,e,t,r){let o=[...n.selection];if(!o.length)return 0;let i=o.map(s=>s.toObject());for(let s of o)n.setProps(s,{left:(s.raw.left??0)+e,top:(s.raw.top??0)+t},{deferIndexRebuild:!0});return n.commitGeometry(),n.fireObjectModified(o,{action:Ne.drag,before:i}),r(),o.length}var Ss=20,Gd={ruleSize:Ss,backgroundColor:oe("#ffffff"),tickColor:oe("#A1A7AF"),textColor:"#444444",highlightColor:oe("#165dff3b"),fontSize:8,unitName:"px"},Xg=.6,ze=3,Xd="'Arial Narrow', 'Segoe UI', sans-serif",Hd=[.02,.03,.05,.1,.2,.5,1,2,5],zg=[5e3,2500,1e3,500,200,100,50,20,10],Yg=n=>{let e=0;for(;e<Hd.length&&Hd[e]<n;)e++;return zg[e-1]??1e4},Ug=(n,e,t,r)=>{let o=Yg(r),i=Math.floor(n/o)*o,s=n+e,a=[],l=[],c=u=>u>=n-1e-6&&u<=s+1e-6&&(!t||u>=t[0]-1e-6&&u<=t[1]+1e-6);for(let u=i;u<=s+o;u+=o){c(u)&&a.push(u);for(let h=1;h<10;h++){let d=u+o*h/10;if(d>s+o)break;c(d)&&l.push(d)}}return{majors:a,minors:l}},$g=(n,e)=>{if(!n.length)return[];let t=e?"left":"top",r=e?"width":"height",o=[...n].sort((a,l)=>a[t]-l[t]),i=[],s={start:o[0][t],length:o[0][r]};for(let a=1;a<o.length;a++){let l=o[a];s.start+s.length>=l[t]?s.length=Math.max(s.start+s.length,l[t]+l[r])-s.start:(i.push(s),s={start:l[t],length:l[r]})}return i.push(s),i},tc=new Map,jg=(n,e=Gd)=>{let t=tc.get(n);if(t)return t;let r=document.createElement("canvas"),o=r.getContext("2d");if(!o)return r.width=Math.max(1,Math.round(n.length*e.fontSize*.6*ze)),r.height=Math.max(1,Math.round(e.fontSize*1.4*ze)),tc.set(n,r),r;let i=`${e.fontSize*ze}px ${Xd}`;o.font=i;let s=o.measureText(n);return r.width=Math.max(1,Math.ceil(s.width)+2),r.height=Math.ceil(e.fontSize*ze*1.25),o.font=i,o.textBaseline="top",o.fillStyle=e.textColor,o.fillText(n,1,Math.round(e.fontSize*ze*.15)),tc.set(n,r),r},nc=new Map,gs=10,ys=4,Vg=n=>{let e=nc.get(n);if(e)return e;let t=gs*ze,r=ys*ze,o=document.createElement("canvas"),i=o.getContext("2d");if(!i)return o.width=Math.max(1,Math.round((n.length*gs*.6+ys*2)*ze)),o.height=Math.max(1,Math.round((gs+ys*2)*ze)),nc.set(n,o),o;let s=`${t}px ${Xd}`;i.font=s;let a=i.measureText(n).width,l=3*ze;return o.width=Math.max(1,Math.ceil(a)+r*2),o.height=Math.ceil((gs+ys*2)*ze),i.font=s,i.beginPath(),i.moveTo(l,0),i.lineTo(o.width-l,0),i.quadraticCurveTo(o.width,0,o.width,l),i.lineTo(o.width,o.height-l),i.quadraticCurveTo(o.width,o.height,o.width-l,o.height),i.lineTo(l,o.height),i.quadraticCurveTo(0,o.height,0,o.height-l),i.lineTo(0,l),i.quadraticCurveTo(0,0,l,0),i.closePath(),i.fillStyle="rgba(22, 93, 255, 0.9)",i.fill(),i.strokeStyle="#fff",i.lineWidth=.5*ze,i.stroke(),i.fillStyle="#fff",i.textBaseline="top",i.fillText(n,r,r),nc.set(n,o),o},zd=n=>{let e={...Gd,...n.style},{vpt:t,cssWidth:r,cssHeight:o}=n,i=t[0],s=n.digitCanvas??(b=>jg(b,e)),a=[],l=b=>(b-t[4])/i,c=b=>(b-t[5])/i,u=1/i,h=(b,x,g,y,v)=>({matrix:[u,0,0,u,l(b+g/2),c(x+y/2)],dims:{x:g,y},color:v}),d=(b,x,g,y=!1)=>{let v=s(b),S=v.width/ze,w=v.height/ze;return{matrix:y?[0,u,-u,0,l(x+w/2),c(g-S/2)]:[u,0,0,u,l(x+S/2),c(g+w/2)],dims:{x:S,y:w},color:[1,1,1,1],texture:v}},f=e.ruleSize,m=b=>{let x=b?r:o;a.push(b?h(0,0,r,f,e.backgroundColor):h(0,0,f,o,e.backgroundColor));let g=n.workspaceRect,y=g?b?[g.left,g.left+g.width]:[g.top,g.top+g.height]:null,v=b?-t[4]/i:-t[5]/i,S=Ug(v,x/i,y,i),w=[e.tickColor[0],e.tickColor[1],e.tickColor[2],e.tickColor[3]*Xg],R=P=>(P-v)*i;for(let P of S.majors){let E=Math.round(R(P));a.push(b?h(E,0,1,f,w):h(0,E,f,1,w))}for(let P of S.minors){let E=Math.round(R(P));a.push(b?h(E,f-8,1,8,w):h(f-8,E,8,1,w))}for(let P of S.majors){let E=R(P),C=String(Math.round(P));b?a.push(d(C,E+6,2.5)):a.push(d(C,2.5,E-6,!0))}for(let P of $g(n.selectionRects,b)){let E=(P.start-v)*i,C=P.length*i;a.push(b?h(E,0,C,f,e.highlightColor):h(0,E,f,C,e.highlightColor))}};m(!0),m(!1),a.push(h(0,0,f,f,e.backgroundColor));let p=s(e.unitName);if(a.push(d(e.unitName,f/2-p.width/ze/2,f/2-p.height/ze/2)),n.referenceLine){let b=Vg(String(Math.round(n.referenceLine.position))),x=b.width/ze,g=b.height/ze,y,v;if(n.referenceLine.axis==="horizontal"){let S=n.referenceLine.position*i+t[5];y=f+5,v=S+g/2,v<0&&(v=2),v+g>o&&(v=o-g-2)}else y=n.referenceLine.position*i+t[4]+x/2,v=f+5,y<0&&(y=2),y+x>r&&(y=r-x-2);a.push({matrix:[u,0,0,u,l(y+x/2),c(v+g/2)],dims:{x,y:g},color:[1,1,1,1],texture:b})}return a};var vs=n=>n*180/Math.PI,ye=n=>n*Math.PI/180,ws=n=>({x:(n.tl.x+n.br.x)/2,y:(n.tl.y+n.br.y)/2}),Ts=n=>({width:Math.hypot(n.tr.x-n.tl.x,n.tr.y-n.tl.y),height:Math.hypot(n.bl.x-n.tl.x,n.bl.y-n.tl.y)}),rc={mr:0,br:45,mb:90,bl:135,ml:180,tl:225,mt:270,tr:315},oc=["ew-resize","nwse-resize","ns-resize","nesw-resize"],Es=5,Yd=4,qt=(n,e,t)=>{let r=e/2,o=t/2;switch(n){case"tl":return{u:{x:-r,y:-o},a:{x:r,y:o},axis:"both"};case"tr":return{u:{x:r,y:-o},a:{x:-r,y:o},axis:"both"};case"br":return{u:{x:r,y:o},a:{x:-r,y:-o},axis:"both"};case"bl":return{u:{x:-r,y:o},a:{x:r,y:-o},axis:"both"};case"ml":return{u:{x:-r,y:0},a:{x:r,y:0},axis:"x"};case"mr":return{u:{x:r,y:0},a:{x:-r,y:0},axis:"x"};case"mt":return{u:{x:0,y:-o},a:{x:0,y:o},axis:"y"};case"mb":return{u:{x:0,y:o},a:{x:0,y:-o},axis:"y"};default:return{u:{x:r,y:o},a:{x:-r,y:-o},axis:"both"}}},ic=(n,e,t)=>Q([Math.cos(ye(n)),-Math.sin(ye(n)),Math.sin(ye(n)),Math.cos(ye(n)),0,0],e.x-t.x,e.y-t.y,!0),sc=(n,e)=>{let r=(s,a)=>{let l=s/a;return Math.sign(l||a)*Math.max(.01,Math.abs(l))},o=n.scaleX,i=n.scaleY;if(n.axis==="both"||n.axis==="x"){let s=n.handleLocal.x-n.anchorLocal.x;Math.abs(s)>1e-6&&(o=r(e.x,s))}if(n.axis==="both"||n.axis==="y"){let s=n.handleLocal.y-n.anchorLocal.y;Math.abs(s)>1e-6&&(i=r(e.y,s))}return{scaleX:o,scaleY:i}};var qg=n=>n instanceof Se&&(n.typeKey===L.TEXTBOX||n.typeKey===L.TEXTIMAGE&&!$t(n));function ac(n,e){let t=n.dims.x,r=n.dims.y,o=n.raw,i={x:-e*t/2,y:0},s=n.matrix,a=n.children.map(h=>({node:h,centerX:h.center.x,centerY:h.center.y,scaleX:h.raw.scaleX??1,width:h.dims.x,fixedBox:qg(h)})),l=Q(s,i.x,i.y),c=n.parentMatrix,u=c?Q(ve(c),l.x,l.y):l;return{node:n,sign:e,width:t,height:r,angle:o.angle??0,scaleX:o.scaleX??1,scaleY:o.scaleY??1,anchorScene:l,anchorWrite:u,children:a}}function Ud(n,e,t){let r=t/Math.max(e.width,1e-6);n.setProps(e.node,{width:t},{deferIndexRebuild:!0});let o={x:-e.sign*t/2,y:0},i=e.angle*Math.PI/180,s=Math.cos(i),a=Math.sin(i),l=s*(e.scaleX*o.x)-a*(e.scaleY*o.y),c=a*(e.scaleX*o.x)+s*(e.scaleY*o.y),u={x:e.anchorWrite.x-l,y:e.anchorWrite.y-c},h=xe({...e.node.raw,width:t,height:e.height,scaleX:e.scaleX,scaleY:e.scaleY},u);n.setProps(e.node,{left:h.x,top:h.y},{deferIndexRebuild:!0});for(let d of e.children){let f=d.centerX*r;if(d.fixedBox){let m=Math.max(d.width*r,1);n.setProps(d.node,{width:m},{deferIndexRebuild:!0});let p=d.node.dims,b=xe({...d.node.raw,width:p.x,height:p.y},{x:f,y:d.centerY});n.setProps(d.node,{left:b.x,top:b.y},{deferIndexRebuild:!0})}else{let m=d.scaleX*r;n.setProps(d.node,{scaleX:m},{deferIndexRebuild:!0});let p=d.node.dims,b=xe({...d.node.raw,width:p.x,height:p.y,scaleX:m},{x:f,y:d.centerY});n.setProps(d.node,{left:b.x,top:b.y},{deferIndexRebuild:!0})}}}function $d(n,e,t){if(t.x*e.sign<=0)return;let o=(typeof e.node.raw.strokeWidth=="number"?e.node.raw.strokeWidth:0)/(e.node.raw.strokeUniform?e.scaleX:1),i=Math.max(e.sign*t.x/e.scaleX-o,1);Ud(n,e,i)}function Kg(n,e,t){if(!(t>0))return;let r=ac(e,1);Ud(n,r,t)}function Dr(n){return n instanceof J&&!(n instanceof ee)&&!(n instanceof le)}function cc(n,e,t){let r=n.raw,o=n.dims.x,i=n.dims.y,{u:s,a,axis:l}=qt(e,o,i),c=$t(n),u=(n.typeKey===L.TEXTBOX||n.typeKey===L.TEXTIMAGE&&!c)&&(e==="ml"||e==="mr");u&&(a.x=-s.x,a.y=-i/2);let h=n.matrix,d=Q(h,a.x,a.y),f=n.parentMatrix,m=f?Q(ve(f),d.x,d.y):d,p={node:n,left:r.left??0,top:r.top??0,angle:r.angle??0,scaleX:r.scaleX??1,scaleY:r.scaleY??1,width:o,height:i,anchorLocal:a,handleLocal:s,anchorScene:d,anchorWrite:m,axis:l,bakeWidth:u||void 0,bakeHeight:n.isTextType&&!c&&(e==="mt"||e==="mb")&&n instanceof Se||void 0};if(Dr(n)&&(e==="ml"||e==="mr")&&(p.bakeGroup=ac(n,e==="mr"?1:-1)),n.isMaskType&&(!t||t.nodes.includes(n))&&(e==="ml"||e==="mr"?p.bakeMaskWidth=!0:(e==="mt"||e==="mb")&&(p.bakeMaskHeight=!0)),n.isTextType&&!c&&vn.has(e)&&n instanceof Se){let b=Ge(r)==="circle"?typeof r.circleSize=="number"?r.circleSize:40:void 0;p.bakeFont={fontSize0:n.textStyle.fontSize,styles0:r.styles??null,...b!==void 0?{circleSize0:b}:{}}}return p}function Kd(n,e,t,r=!1){let o=ic(e.angle,t,e.anchorScene);if(e.bakeFont){Zg(n,e,o);return}if(e.bakeWidth){Jg(n,e,o);return}if(e.bakeHeight){ey(n,e,o);return}if(e.bakeGroup){$d(n,e.bakeGroup,o);return}if(e.bakeMaskWidth){jd(n,e,o,"width");return}if(e.bakeMaskHeight){jd(n,e,o,"height");return}let i,s;if(e.axis==="both"&&!r){let f=(Math.abs(o.x)+Math.abs(o.y))/Math.max(Math.abs(e.width*e.scaleX)+Math.abs(e.height*e.scaleY),1e-6),m=Math.max(f,.01);i=e.scaleX*m,s=e.scaleY*m}else({scaleX:i,scaleY:s}=sc(e,o));let a=Math.cos(ye(e.angle)),l=Math.sin(ye(e.angle)),c=a*(i*e.anchorLocal.x)-l*(s*e.anchorLocal.y),u=l*(i*e.anchorLocal.x)+a*(s*e.anchorLocal.y),h={x:e.anchorWrite.x-c,y:e.anchorWrite.y-u},d=xe({...e.node.raw,width:e.width,height:e.height,scaleX:i,scaleY:s},h);n.setProps(e.node,{scaleX:i,scaleY:s,left:d.x,top:d.y},{deferIndexRebuild:!0})}function Qd(n,e,t){let{quad:r,angle:o}=t,i=ws(r),{width:s,height:a}=Ts(r),{u:l,a:c,axis:u}=qt(e,s,a),h=Math.cos(ye(o)),d=Math.sin(ye(o));return{members:n.map(f=>({node:f,center:{...f.center},scaleX:f.raw.scaleX??1,scaleY:f.raw.scaleY??1,dims:{...f.dims}})),center:i,angle:o,width:s,height:a,anchorLocal:c,handleLocal:l,anchorScene:{x:i.x+h*c.x-d*c.y,y:i.y+d*c.x+h*c.y},axis:u,handle:e}}function Zd(n,e,t,r=!1){let o=ic(e.angle,t,e.anchorScene),i,s;if(e.axis==="both"&&!r){let h=(Math.abs(o.x)+Math.abs(o.y))/Math.max(Math.abs(e.width)+Math.abs(e.height),1e-6);i=s=Math.max(h,.01)}else({scaleX:i,scaleY:s}=sc({...e,scaleX:1,scaleY:1},o));let a=Math.cos(ye(e.angle)),l=Math.sin(ye(e.angle)),c={x:e.anchorScene.x-(a*(i*e.anchorLocal.x)-l*(s*e.anchorLocal.y)),y:e.anchorScene.y-(l*(i*e.anchorLocal.x)+a*(s*e.anchorLocal.y))},u=e.members;n.applyTransform(u.map(h=>h.node),h=>{let d=u.find(x=>x.node===h),f=Qg(e,c,i,s,d,a,l),m=d.scaleX*i,p=d.scaleY*s,b=xe({...h.raw,width:d.dims.x,height:d.dims.y,scaleX:m,scaleY:p},f);return{scaleX:m,scaleY:p,left:b.x,top:b.y}},"scaling"),n.setSelectionFrame({center:c,width:e.width*i,height:e.height*s,angle:e.angle})}function Qg(n,e,t,r,o,i,s){let a=i*(o.center.x-n.center.x)+s*(o.center.y-n.center.y),l=-s*(o.center.x-n.center.x)+i*(o.center.y-n.center.y);return{x:e.x+i*(t*a)-s*(r*l),y:e.y+s*(t*a)+i*(r*l)}}function Jd(n,e,t){let r=Math.atan2(t.y-e.center.y,t.x-e.center.x),o=vs(r-e.startAngle),i=Math.cos(ye(o)),s=Math.sin(ye(o)),a=e.snapshot.members;n.applyTransform(a.map(c=>c.node),c=>{let u=a.find(p=>p.node===c),h=((u.angle0+o)%360+360)%360,d=u.center0.x-e.center.x,f=u.center0.y-e.center.y,m={x:e.center.x+i*d-s*f,y:e.center.y+s*d+i*f};return c.rotateAroundCenter(h,m)},"rotating");let l=((e.frameAngle0+o)%360+360)%360;n.setSelectionFrame({center:{...e.center},width:e.frame.width,height:e.frame.height,angle:l})}var lc=n=>{if(n===null||typeof n!="object")return typeof n=="function"?void 0:n;if(Array.isArray(n))return n.map(lc);let e={};for(let t of Object.keys(n)){let r=lc(n[t]);r!==void 0&&(e[t]=r)}return e};function Zg(n,e,t){let r=e.bakeFont,o=e.handleLocal.x-e.anchorLocal.x,i=e.handleLocal.y-e.anchorLocal.y,s=Math.abs(o)+Math.abs(i),a=s>1e-6?(Math.abs(t.x)+Math.abs(t.y))/s:1,l=Math.max(r.fontSize0*a,1);a=l/r.fontSize0;let c={fontSize:l,scaleX:e.scaleX,scaleY:e.scaleY},u=r.circleSize0,h=u!==void 0;h&&(c.circleSize=Math.max(u*a,1)),e.node.typeKey===L.TEXTBOX&&!h&&(c.width=Math.max(e.width*a,1)),h||(c.height=Math.max(e.height*a,1));let d=r.styles0;if(d){let y=lc(d);for(let v of Object.values(y))if(v)for(let[S,w]of Object.entries(v)){let R=w;R&&typeof R.fontSize=="number"&&(v[S]={...R,fontSize:R.fontSize*a})}c.styles=y}let f=Math.cos(ye(e.angle)),m=Math.sin(ye(e.angle)),p=f*(e.scaleX*e.anchorLocal.x*a)-m*(e.scaleY*e.anchorLocal.y*a),b=m*(e.scaleX*e.anchorLocal.x*a)+f*(e.scaleY*e.anchorLocal.y*a),x={x:e.anchorWrite.x-p,y:e.anchorWrite.y-b},g=xe({...e.node.raw,width:e.width*a,height:e.height*a,scaleX:e.scaleX,scaleY:e.scaleY},x);c.left=g.x,c.top=g.y,n.setProps(e.node,c,{deferIndexRebuild:!0})}function Jg(n,e,t){let o=Math.sign(e.handleLocal.x);if(t.x*o<=0)return;let s=(typeof e.node.raw.strokeWidth=="number"?e.node.raw.strokeWidth:0)/(e.node.raw.strokeUniform?e.scaleX:1),a=Math.max(o*t.x/e.scaleX-s,1);n.setProps(e.node,{width:a},{deferIndexRebuild:!0});let l=e.node.dims.x,c=e.node.dims.y,u={x:-o*l/2,y:-c/2},h=Math.cos(ye(e.angle)),d=Math.sin(ye(e.angle)),f=h*(e.scaleX*u.x)-d*(e.scaleY*u.y),m=d*(e.scaleX*u.x)+h*(e.scaleY*u.y),p={x:e.anchorWrite.x-f,y:e.anchorWrite.y-m},b=xe({...e.node.raw,width:l,height:c,scaleX:e.scaleX,scaleY:e.scaleY},p);n.setProps(e.node,{left:b.x,top:b.y},{deferIndexRebuild:!0})}function ey(n,e,t){let r=e.node;if(!(r instanceof Se))return;let o=Math.sign(e.handleLocal.y);if(t.y*o<=0)return;let s=(typeof r.raw.strokeWidth=="number"?r.raw.strokeWidth:0)/(r.raw.strokeUniform?e.scaleY:1),a=Math.max(Math.ceil(Math.abs(t.y)/e.scaleY-s),r.textLayout.height,0);n.setProps(r,{height:a},{deferIndexRebuild:!0});let l={x:0,y:-o*a/2},c=Math.cos(ye(e.angle)),u=Math.sin(ye(e.angle)),h=c*(e.scaleX*l.x)-u*(e.scaleY*l.y),d=u*(e.scaleX*l.x)+c*(e.scaleY*l.y),f={x:e.anchorWrite.x-h,y:e.anchorWrite.y-d},m=xe({...r.raw,width:e.width,height:a,scaleX:e.scaleX,scaleY:e.scaleY},f);n.setProps(r,{left:m.x,top:m.y},{deferIndexRebuild:!0})}function jd(n,e,t,r){let i=e.node,s=i.raw,a=typeof s.strokeWidth=="number"?s.strokeWidth:0;if(r==="width"){let l=Math.sign(e.handleLocal.x);if(t.x*l<=0)return;let c=a/(s.strokeUniform?e.scaleX:1),u=Math.max(l*t.x/e.scaleX-c,1),h=Number(s.width)||e.width,d=Number(s.height)||e.height,f=qd(i,h,d,u,d);n.setProps(e.node,{width:u,...f??{}},{deferIndexRebuild:!0});let m={x:-l*u/2,y:0},p=Vd(e,m),b=xe({...s,width:u,height:d,scaleX:e.scaleX,scaleY:e.scaleY},p);n.setProps(e.node,{left:b.x,top:b.y},{deferIndexRebuild:!0})}else{let l=Math.sign(e.handleLocal.y);if(t.y*l<=0)return;let c=a/(s.strokeUniform?e.scaleY:1),u=Math.max(l*t.y/e.scaleY-c,1),h=Number(s.width)||e.width,d=Number(s.height)||e.height,f=qd(i,h,d,h,u);n.setProps(e.node,{height:u,...f??{}},{deferIndexRebuild:!0});let m={x:0,y:-l*u/2},p=Vd(e,m),b=xe({...s,width:h,height:u,scaleX:e.scaleX,scaleY:e.scaleY},p);n.setProps(e.node,{left:b.x,top:b.y},{deferIndexRebuild:!0})}}function Vd(n,e){let t=Math.cos(ye(n.angle)),r=Math.sin(ye(n.angle)),o=t*(n.scaleX*e.x)-r*(n.scaleY*e.y),i=r*(n.scaleX*e.x)+t*(n.scaleY*e.y);return{x:n.anchorWrite.x-o,y:n.anchorWrite.y-i}}function qd(n,e,t,r,o){let s=n.raw.clipImage;if(!s||typeof s.src!="string")return null;let a=n.clipImageEl,l=a?.naturalWidth||Number(s.width)||0,c=a?.naturalHeight||Number(s.height)||0;if(!l||!c||!e||!t||!r||!o)return null;let u=(m,p)=>Math.max(m/l,p/c),h=Number(s.scaleX)||1,d=u(e,t)?h/u(e,t):1,f=u(r,o)*(d||1);return{clipImage:{...s,scaleX:f,scaleY:f}}}var ef=(n,e)=>e.length>=2&&(e.includes(n-1)||e.includes(n));function nf(n,e,t){let r=n.raw,o={type:"table-border-drag",node:n,border:e,startMatrix:[...n.matrix],startLocal:n.localPoint(t.x,t.y),startBorderPos:e.position,startWidths:Array.isArray(r.columnWidths)?[...r.columnWidths]:[...n.layout.columnWidths],startHeights:[...n.layout.rowHeights],selectedCols:[...new Set(n.selectedCells.map(i=>i.col))],selectedRows:[...new Set(n.selectedCells.map(i=>i.row))],savedCells:n.selectedCells,savedAnchor:n.cellAnchor,savedRange:n.cellRange};return n.setCellSelection([],null,null),n.borderDragging=!0,o}function rf(n,e){let t=n.node.raw,r=Q(ve(n.startMatrix),e.x,e.y),o={x:r.x-n.startLocal.x,y:r.y-n.startLocal.y};if(n.border.type==="col"){let c=t.minCellWidth??40,u=(Array.isArray(t.columnWidths)?[...t.columnWidths]:[...n.startWidths]).slice(0,n.node.tableView.cols);for(;u.length<n.node.tableView.cols;)u.push(c);if(ef(n.border.index,n.selectedCols))for(let h of n.selectedCols)u[h]=Math.max(c,n.startWidths[h]+o.x);else u[n.border.index-1]=Math.max(c,n.startWidths[n.border.index-1]+o.x);fo(t,u)}else{let c=n.node.tableView.rows,u=Array.isArray(t.manualRowHeights)?t.manualRowHeights:[],h=[];for(let d=0;d<c;d++)h.push(typeof u[d]=="number"?u[d]:null);if(ef(n.border.index,n.selectedRows))for(let d of n.selectedRows)h[d]=Math.max(n.node.getRowMinHeight(d),n.startHeights[d]+o.y);else{let d=n.border.index-1;h[d]=Math.max(n.node.getRowMinHeight(d),n.startHeights[d]+o.y)}t.manualRowHeights=h}n.node.rebuildTable();let i=Er(n.node.tableView,n.border.type,n.border.index),s=n.border.type==="col"?o.x:o.y,a=n.border.type==="col"?n.node.objectScale.x:n.node.objectScale.y,l=qh(n.startBorderPos,i,s,a);n.node.hoveredBorder={type:n.border.type,index:n.border.index,position:i+l}}function of(n,e){let t=qt(e,n.dims.x,n.dims.y).a;return{type:"table-edge-resize",node:n,handle:e,anchorScene:Q(n.matrix,t.x,t.y)}}function sf(n,e){let t=qt(e,n.dims.x,n.dims.y).a;return{type:"puzzle-edge-resize",node:n,handle:e,anchorScene:Q(n.matrix,t.x,t.y)}}function Cs(n,e,t,r){for(let o of Io(e)){let i=n(o.x,o.y);if(nr(o.id)&&Math.hypot(i.x-t,i.y-r)<=rr)return o.id}return null}function ny(n,e,t,r){let o=r.x-t.x,i=r.y-t.y,s=o*o+i*i,a=s>0?Math.max(0,Math.min(1,((n-t.x)*o+(e-t.y)*i)/s)):0;return Math.hypot(n-(t.x+a*o),e-(t.y+a*i))}function _o(n,e,t,r){for(let o of ec(e)){let i=n(o.p1.x,o.p1.y),s=n(o.p2.x,o.p2.y);if(ny(t,r,i,s)<=rr)return{mask:o.mask,handle:o.handle}}return null}function uc(n,e,t){let r=n.maskChildren.indexOf(e);if(r<0)return null;let o=Fh(n.raw,n.maskChildren.map(s=>s.raw),n.maskChildren.map(s=>s.clipImageEl)),i=qt(t,e.dims.x,e.dims.y).a;return{type:"puzzle-mask-edge-resize",node:n,maskIdx:r,handle:t,anchorScene:Q(e.matrix,i.x,i.y),state:o.state,pieces:o.pieces,clipSizes:o.clipSizes}}function ry(n,e){n.maskChildren.forEach((t,r)=>{let o=e.masks[r];if(!o)return;let i=t.clipImageRaw,s=o.clip&&i?{...i,scaleX:o.clip.scaleX,scaleY:o.clip.scaleY,clipX:o.clip.clipX,clipY:o.clip.clipY}:null;t.set({left:o.left,top:o.top,width:o.width,height:o.height,...s?{clipImage:s}:{}})})}function af(n,e){let t=n.node.maskChildren[n.maskIdx];if(!t)return;let r=t.raw,o=t.worldAngle,i=t.worldScale,s=e.x-n.anchorScene.x,a=e.y-n.anchorScene.y;if(o){let c=Math.cos(ye(-o)),u=Math.sin(ye(-o)),h=s;s=c*h-u*a,a=u*h+c*a}let l=rs[n.handle];if(l==="left"||l==="right"){let c=(r.strokeWidth??0)/(r.strokeUniform===!0?i.x:1);_h(n.state,n.maskIdx,Math.abs(s)/i.x-c,l,n.clipSizes)}else{let c=(r.strokeWidth??0)/(r.strokeUniform===!0?i.y:1);Dh(n.state,n.maskIdx,Math.abs(a)/i.y-c,l,n.clipSizes)}ry(n.node,n.state)}function tf(n,e){let t=n.layoutParams,r=n.maskChildren,o={...t,masks:r.map(s=>({left:s.raw.left??0,top:s.raw.top??0,width:s.raw.width??0,height:s.raw.height??0,clip:Bi(s.raw)}))},i=r.map(s=>s.clipImageEl?{w:s.clipImageEl.naturalWidth,h:s.clipImageEl.naturalHeight}:null);Ih(o,e,i)&&(n.set({layoutWidth:o.width,layoutHeight:o.height,hGap:o.hGap,vGap:o.vGap,groupPadding:o.groupPadding,width:o.width,height:o.height}),r.forEach((s,a)=>{let l=o.masks[a],c=s.clipImageRaw,u=l.clip&&c?{...c,scaleX:l.clip.scaleX,scaleY:l.clip.scaleY,clipX:l.clip.clipX,clipY:l.clip.clipY}:null;s.set({left:l.left,top:l.top,width:l.width,height:l.height,...u?{clipImage:u}:{}})}))}function lf(n,e,t){let r=e.node.raw,o={x:Math.abs(r.scaleX??1),y:Math.abs(r.scaleY??1)},i=r.angle??0,s=t.x-e.anchorScene.x,a=t.y-e.anchorScene.y;if(i){let m=Math.cos(ye(-i)),p=Math.sin(ye(-i)),b=s;s=m*b-p*a,a=p*b+m*a}let l=e.node.layoutParams;if(tr[e.handle]==="x"){let m=(r.strokeWidth??0)/(r.strokeUniform===!0?o.x:1),p=Math.max(Math.abs(s)/o.x-m,1);tf(e.node,{widthRatio:p/(l.width||1)})}else{let m=(r.strokeWidth??0)/(r.strokeUniform===!0?o.y:1),p=Math.max(Math.abs(a)/o.y-m,1);tf(e.node,{heightRatio:p/(l.height||1)})}let c=qt(e.handle,e.node.dims.x,e.node.dims.y).a,u=Math.cos(ye(i)),h=Math.sin(ye(i)),d={x:e.anchorScene.x-(u*(o.x*c.x)-h*(o.y*c.y)),y:e.anchorScene.y-(h*(o.x*c.x)+u*(o.y*c.y))},f=xe({...r,width:e.node.dims.x,height:e.node.dims.y},d);n.setProps(e.node,{left:f.x,top:f.y},{deferIndexRebuild:!0})}function cf(n,e,t){let r=e.node.raw,o=e.node.tableView,i=e.node.objectScale,s=e.node.tableAngle,a=t.x-e.anchorScene.x,l=t.y-e.anchorScene.y;if(s){let p=Math.cos(ye(-s)),b=Math.sin(ye(-s)),x=a;a=p*x-b*l,l=b*x+p*l}let c=r.cellStrokeWidth??1;if(tr[e.handle]==="x"){let p=Math.abs(a)/i.x-o.cellSpacing*(o.cols-1)-c,b=e.handle==="ml"?0:o.cols-1,x=o.columnWidths.reduce((g,y,v)=>v===b?g:g+y,0);mo(r,b,p-x)}else{let p=Math.abs(l)/i.y-o.cellSpacing*(o.rows-1)-c,b=e.handle==="mt"?0:o.rows-1,x=o.rowHeights.reduce((g,y,v)=>v===b?g:g+y,0);po(r,b,p-x)}e.node.rebuildTable();let u=qt(e.handle,e.node.dims.x,e.node.dims.y).a,h=Math.cos(ye(s)),d=Math.sin(ye(s)),f={x:e.anchorScene.x-(h*(i.x*u.x)-d*(i.y*u.y)),y:e.anchorScene.y-(d*(i.x*u.x)+h*(i.y*u.y))},m=xe({...r,width:e.node.dims.x,height:e.node.dims.y},f);n.setProps(e.node,{left:m.x,top:m.y},{deferIndexRebuild:!0})}function uf(n,e,t){let r=Math.max(0,t.index);if(t.type==="col"){yo(e.raw,r),e.rebuildTable();let o=e.tableView,i=Xi(e.cellMap,o.rows,Math.min(r,o.cols-1));e.setCellSelection(i,i[0]??null,Xe(i))}else{go(e.raw,r),e.rebuildTable();let o=e.tableView,i=zi(e.cellMap,o.cols,Math.min(r,o.rows-1));e.setCellSelection(i,i[0]??null,Xe(i))}n.applyTransform([e],()=>({}),"modified")}var oy=n=>n.kind==="col-strip"?{kind:"col",index:n.col}:{kind:"row",index:n.row},iy=(n,e,t)=>{let r=n.raw,{x:o,y:i}=n.dims;if(!o||!i)return null;let s=Math.max(Math.abs(r.scaleX??1)||1,1e-4),a=Math.max(Math.abs(r.scaleY??1)||1,1e-4),l=n.localPoint(t.x,t.y),c=o/2,u=i/2,h,d;e==="tl"?(h=(l.x+c)*s,d=(l.y+u)*a):e==="tr"?(h=(c-l.x)*s,d=(l.y+u)*a):e==="bl"?(h=(l.x+c)*s,d=(u-l.y)*a):(h=(c-l.x)*s,d=(u-l.y)*a);let f=Sd(n),m=Math.max(0,Math.min(f,Kl(Math.min(h,d),f))),p=r.radius??0;return Math.abs(m-p)<.001?null:m},sy=(n,e,t)=>{let r=n.raw,{x:o,y:i}=n.dims;if(!o||!i)return null;let s=n.localPoint(t.x,t.y),a=o/2,l=i/2,c,u;e==="tl"?(c=s.x+a,u=s.y+l):e==="tr"?(c=a-s.x,u=s.y+l):e==="bl"?(c=s.x+a,u=l-s.y):(c=a-s.x,u=l-s.y);let h=Math.min(a,l),d=Math.max(0,Math.min(h,Kl(Math.min(c,u),h))),f=Math.max(r.rx??0,r.ry??0);if(Math.abs(d-f)<.001)return null;let m={rx:d,ry:d};return d>0&&r.perPixelTargetFind===!1&&(m.perPixelTargetFind=!0),m},hc=(n,e)=>n<Ss?"vertical":e<Ss?"horizontal":null,Do=n=>`url("data:image/svg+xml,<svg height='20' width='20' viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg'><g fill='none' transform='rotate(${n} 16 16)'><path fill='white' d='M18.24 5.37C11.41 6.04 5.98 11.46 5.32 18.26L0 18.26L7.8 26L15.61 18.27L10.6 18.27C11.21 14.35 14.31 11.25 18.24 10.64L18.24 15.55L26 7.78L18.24 0L18.24 5.37Z'></path><path fill='black' d='M19.5463 6.61441C12.4063 6.68441 6.61632 12.4444 6.56632 19.5644L3.17632 19.5644L7.80632 24.1444L12.4363 19.5644L9.18632 19.5644C9.24632 13.8844 13.8563 9.28441 19.5463 9.22441L19.5463 12.3844L24.1463 7.78441L19.5463 3.16441L19.5463 6.61441Z'></path></g></svg>") 12 12,auto`,We=n=>{let e=new Map;for(let t of n)e.set(t,t.toObject());return e},Ms=class{host;el;gesture={type:"none"};performed=!1;hoveredTable=null;deferredClickSwitch=null;detach=null;interactive;constructor(e,t,r=!0){this.el=e,this.host=t,this.interactive=r,this.attach()}get active(){return this.gesture.type!=="none"}hitHandle(e,t){let r=et(this.host.document);if(!r||this.host.document.selection.length===1&&at(this.host.document.selection[0]))return null;for(let o of No(this.host.document,r.quad,r.angle,this.host.zoom,Lo(this.host.document))){let i=this.host.toScreen(o.x,o.y);if(Math.hypot(i.x-e,i.y-t)<=rr)return o.id}return null}hitActiveChildHandle(e,t){let r=this.host.document,o=r.activeGroupChild;if(!o||!r.groupEditing)return null;for(let i of Jl(o,this.host.zoom)){let s=this.host.toScreen(i.x,i.y);if(Math.hypot(s.x-e,s.y-t)<=rr)return i.id}return null}hitLockControl(e,t){let r=this.host.document;if(r.selection.length!==1||!at(r.selection[0]))return null;let o=et(r);if(!o)return null;let i=this.host.toScreen(o.quad.br.x,o.quad.br.y);return Math.hypot(i.x-e,i.y-t)<=rr?r.selection[0]:null}hitMoveControl(e,t){if(this.host.mobileControls!==!0||!jl(this.host.document))return!1;let r=et(this.host.document);if(!r)return!1;let o=Vl(r.quad,r.angle,this.host.zoom),i=this.host.toScreen(o.x,o.y);return Math.hypot(i.x-e,i.y-t)<=xd}hitCornerRotateZone(e,t){let r=this.host.document;if(r.selection.length!==1)return null;let o=r.selection[0];if(o instanceof ee||at(o))return null;let i=et(r);if(!i)return null;let s=i.angle*Math.PI/180,a=Math.cos(s),l=Math.sin(s),c=vd/2;for(let u of Ed(i.quad,i.angle,this.host.zoom)){let h=this.host.toScreen(u.x,u.y),d=e-h.x,f=t-h.y,m=d*a+f*l,p=-d*l+f*a;if(Math.abs(m)<=c&&Math.abs(p)<=c)return u.id}return null}freezeRotateHandle(e,t,r=!1){this.host.rotateDrag!==void 0&&(this.host.rotateDrag=r?{spec:ps(e),center:{x:t.x,y:t.y},onChild:!0}:{spec:ps(e),center:{x:t.x,y:t.y}})}hoverCursor(e,t,r){let o=this.host.document;if(this.host.rulerVisible){let p=hc(e,t);if(p)return p==="horizontal"?"ns-resize":"ew-resize"}let i=this.host.cropSession;if(i)return i.hoverCursor(e,t,r);let s=this.host.expandSession;if(s)return s.hoverCursor(e,t,r.x,r.y);let a=this.host.pathSession;if(a)return a.hoverCursor(e,t,r);let l=this.host.warpSession;if(l)return l.hoverCursor(e,t);let c=o.selection.length===1&&o.selection[0]instanceof le?o.selection[0]:null;if(c?.editingMask){let p=Cs((x,g)=>this.host.toScreen(x,g),c,e,t);if(p)return tr[p]==="x"?"ew-resize":"ns-resize";let b=_o((x,g)=>this.host.toScreen(x,g),c,e,t);if(b)return tr[b.handle]==="x"?"ew-resize":"ns-resize"}else if(c){let p=_o((b,x)=>this.host.toScreen(b,x),c,e,t);if(p)return tr[p.handle]==="x"?"ew-resize":"ns-resize"}let u=o.selection.length===1&&o.selection[0]instanceof ee?o.selection[0]:null;if(u&&!o.findTarget(r.x,r.y)){let p=u.borderOrIndicatorHit(r.x,r.y,this.host.zoom);if(p?.inCircle)return this.updateTableHover(u,p,!1),"pointer";let b=u.stripHit(r.x,r.y,this.host.zoom);if(b)return this.updateTableHover(u,null,!1,{strip:oy(b)}),"pointer";if(u.dragHandleHit(r.x,r.y,this.host.zoom))return this.updateTableHover(u,null,!1,{dragHandle:!0}),"move"}if(u&&o.findTarget(r.x,r.y)===u&&u.rangeHandleHit(r.x,r.y,this.host.zoom))return this.updateTableHover(u,null,!0,{rangeHandle:!0}),"crosshair";if(this.hitLockControl(e,t))return"pointer";let h=this.hitActiveChildHandle(e,t);if(h==="mtr"){let p=o.activeGroupChild;return Do(p.worldAngle+225)}if(h){let p=o.activeGroupChild,b=rc[h];if(typeof b=="number"){let x=b+p.worldAngle;return oc[(Math.round(x/45)%4+4)%4]}}if(this.hitMoveControl(e,t))return"move";let d=this.hitHandle(e,t);if(d==="mtr")return Do((et(o)?.angle??0)+225);if(d&&Lr(d))return d==="tlS"||d==="brS"?"nwse-resize":"nesw-resize";if(d){let p=rc[d]+(et(o)?.angle??0);return oc[(Math.round(p/45)%4+4)%4]}let f=this.hitCornerRotateZone(e,t);if(f)return Do((et(o)?.angle??0)+Ql[f]);let m=o.findTarget(r.x,r.y);if(m&&m===o.editingNode)return"text";if(m instanceof ee){let p=m.borderOrIndicatorHit(r.x,r.y,this.host.zoom),b="move";return p?.inCircle?b="pointer":p?.border&&o.selection.includes(m)&&(b=Kh(m.tableAngle,p.border.type)),this.updateTableHover(m,p,!0),b}if(this.updateTableHover(null,null,!1),!this.host.cropSession&&!this.host.expandSession&&!this.host.pathSession&&!this.host.warpSession){let p=o.nodes.find(b=>Ze(b)&&b.visible&&b.raw.visible!==!1&&b.containsPoint(r.x,r.y));if(p)return p.dims.y===0?"ns-resize":"ew-resize"}return m?"move":""}updateTableHover(e,t,r,o={}){if(this.hoveredTable&&this.hoveredTable!==e&&(this.hoveredTable.clearHoverState(),this.hoveredTable=null,this.host.requestRenderAll()),!e)return;let i=e.hoveredBorder,s=e.hoveredIndicator,a=e.indicatorVisible,l=e.hoveredStrip,c=e.hoveredDragHandle,u=e.hoveredRangeHandle;e.hoveredBorder=t&&!t.inCircle?t.border:null,e.hoveredIndicator=t?.inCircle?t.border:null,e.indicatorVisible=r||!!t,e.hoveredStrip=o.strip??null,e.hoveredDragHandle=o.dragHandle??!1,e.hoveredRangeHandle=o.rangeHandle??!1,this.hoveredTable=e;let h=l?.kind!==e.hoveredStrip?.kind||l?.index!==e.hoveredStrip?.index;(i!==e.hoveredBorder||s!==e.hoveredIndicator||a!==e.indicatorVisible||h||c!==e.hoveredDragHandle||u!==e.hoveredRangeHandle)&&this.host.requestRenderAll()}updateHover(e,t,r){let o=this.host.document,i=null,s=null,a=o.nodes.find(d=>d instanceof le&&d.editingMask)??null,l=!!this.host.cropSession||!!this.host.expandSession||!!this.host.pathSession||!!this.host.warpSession||!!a,c=!this.hitHandle(e,t)&&!this.hitMoveControl(e,t);if(!l&&c){let d=o.findTarget(r.x,r.y);if(d instanceof J&&!(d instanceof ee)&&!(d instanceof le)){let f=o.activeGroupChild;if(!(f!==null&&o.selection.length===1&&o.selection[0]===d))o.selection.includes(d)||(i=d);else{let p=Nr(d,r.x,r.y,o.selection);i=p&&p!==f?p:null}}else d&&!o.selection.includes(d)&&(i=d)}if(i&&i===o.editingNode&&(i=null),c&&!(a&&Cs((d,f)=>this.host.toScreen(d,f),a,e,t))){let d=o.selection.length===1&&o.selection[0]instanceof le?o.selection[0]:null;if(d){let f=_o((m,p)=>this.host.toScreen(m,p),d,e,t);f&&(s={puzzle:d,mask:f.mask,handle:f.handle})}}let u=o.hovered;o.setHovered(i);let h=o.seamHover;o.setSeamHover(s),(o.hovered!==u||o.seamHover!==h)&&this.host.requestRenderAll()}attach(){if(!this.interactive)return;let e=this.el,t=s=>{if(s.button!==0||this.host.interactionSuspended)return;this.host.document.editingNode&&s.preventDefault();let a=e.getBoundingClientRect(),l=s.clientX-a.left,c=s.clientY-a.top;this.onPointerDown(l,c,s.shiftKey)},r=s=>{if(this.host.interactionSuspended&&this.gesture.type==="none"||this.host.panning)return;let a=e.getBoundingClientRect();this.onPointerMove(s.clientX-a.left,s.clientY-a.top)},o=s=>{if(this.host.interactionSuspended&&this.gesture.type==="none")return;let a=e.getBoundingClientRect();this.onPointerUp(s.clientX-a.left,s.clientY-a.top)},i=()=>{let s=this.host.document,a=s.hovered;s.setHovered(null),this.el.style.cursor="",s.hovered!==a&&this.host.requestRenderAll()};e.addEventListener("pointerdown",t),window.addEventListener("pointermove",r),window.addEventListener("pointerup",o),e.addEventListener("pointerleave",i),this.detach=()=>{e.removeEventListener("pointerdown",t),window.removeEventListener("pointermove",r),window.removeEventListener("pointerup",o),e.removeEventListener("pointerleave",i)}}onPointerDown(e,t,r){let o=this.host.document,i=this.host.toScene(e,t);this.performed=!1,this.deferredClickSwitch=null,o.setHovered(null);let s=this.host.cropSession;if(s){let S=s.hitHandle(e,t);S?this.gesture={type:"crop-handle",handle:S}:s.hitRect(i.x,i.y)?this.gesture={type:"crop-move",last:i}:s.exitByOutsideClick(),this.host.requestRenderAll();return}let a=this.host.expandSession;if(a){let S=a.hitHandle(e,t);S?this.gesture={type:"expand-handle",handle:S}:a.hitRect(i.x,i.y)?this.gesture={type:"expand-image-drag",last:i}:a.exitByOutsideClick(),this.host.requestRenderAll();return}let l=this.host.pathSession;if(l){let S=l.hitAnchor(e,t);if(S&&l.startAnchorDrag(S)){this.gesture={type:"path-anchor-drag",key:S},this.host.requestRenderAll();return}let w=l.findInsertCandidate(i.x,i.y);if(w){let R=l.insertAnchor(w);if(R){this.gesture={type:"path-anchor-drag",key:R},this.host.requestRenderAll();return}}if(l.hitBody(i.x,i.y)){this.gesture={type:"path-body-drag",last:i},this.host.requestRenderAll();return}l.exitByOutsideClick()}let c=this.host.warpSession;if(c){let S=c.hitAnchor(e,t);S&&(this.gesture={type:"warp-anchor-drag",anchor:S},c.applyAnchorDrag(S,i)),this.host.requestRenderAll();return}if(this.host.rulerVisible){let S=hc(e,t);if(S){let w=id(S,S==="horizontal"?i.y:i.x),R=Ct(w);R&&(o.add(R),o.clearSelection(),this.gesture={type:"reference-line",node:R,axis:S,creating:!0,historyBefore:We([R])}),this.host.requestRenderAll();return}}let u=o.editingNode,h=!1;if(u){if(u.containsPoint(i.x,i.y)){let S=u.localPoint(i.x,i.y),w=u.cursorIndexAt(S.x,S.y);this.host.setEditingSelection(w,w),this.gesture={type:"text-select",anchorIdx:w};return}o.exitEditing(),h=!0}if(!h&&o.selection.length===1&&o.selection[0]instanceof ee){let S=o.selection[0],w=o.findTarget(i.x,i.y)?null:S.borderOrIndicatorHit(i.x,i.y,this.host.zoom);if(w?.inCircle){this.gesture={type:"table-indicator-click",node:S,border:w.border};return}let R=o.findTarget(i.x,i.y)?null:S.stripHit(i.x,i.y,this.host.zoom);if(R){this.gesture=R.kind==="col-strip"?{type:"table-strip-click",node:S,kind:"col",index:R.col}:{type:"table-strip-click",node:S,kind:"row",index:R.row};return}}if(!h&&o.selection.length===1&&o.selection[0]instanceof ee){let S=o.selection[0];if(o.findTarget(i.x,i.y)===S&&S.rangeHandleHit(i.x,i.y,this.host.zoom)){let w=S.expandedCellRange;if(w){this.gesture={type:"table-range-drag",node:S,anchor:{row:w.r1,col:w.c1}};return}}}let d=h?null:o.nodes.find(S=>S instanceof le&&S.editingMask)??null,f=!!d;if(f&&d){let S=Cs((w,R)=>this.host.toScreen(w,R),d,e,t);if(S&&d.editingMask){let w=uc(d,d.editingMask,S);w&&(this.gesture=w);return}}{let S=o.selection.length===1&&o.selection[0]instanceof le?o.selection[0]:null;if(S){let w=_o((R,P)=>this.host.toScreen(R,P),S,e,t);if(w){let R=uc(S,w.mask,w.handle);R&&(this.gesture=R);return}}}let m=h?null:this.hitLockControl(e,t);if(m){this.host.document.events.fire("lock:unlock-requested",m);return}let p=!f||d!=null&&o.selection.length===1&&o.selection[0]===d;if(p&&!h){let S=this.hitActiveChildHandle(e,t),w=o.activeGroupChild,R=o.selection.length===1?o.selection[0]:null;if(S&&w&&R instanceof J&&!(R instanceof ee)&&!(R instanceof le)){let P=es(R,w);if(P.length){let E=[w,...P,...P.flatMap(C=>C.children)];if(S==="mtr"){let C=w.aCoords,T={x:(C.tl.x+C.br.x)/2,y:(C.tl.y+C.br.y)/2};this.freezeRotateHandle(w.raw.angle??0,T,!0),this.gesture={type:"rotate",center:T,startAngle:Math.atan2(i.y-T.y,i.x-T.x),snapshot:{node:w,angle0:w.raw.angle??0},cursorOffset:225,childTransform:{child:w,shells:P,pivotLocal:{...w.center}},historyBefore:We(E)}}else if(!Lr(S))this.gesture={type:"scale",handle:S,snapshot:cc(w,S,o),freeScale:r&&vn.has(S),childTransform:{child:w,shells:P},historyBefore:We(E)};else return;this.host.requestRenderAll();return}}}if(!h&&p&&this.hitMoveControl(e,t)){let S=o.selection[0],w=new Map;w.set(S,{left:S.raw.left??0,top:S.raw.top??0}),this.gesture={type:"move",start:i,startCss:{x:e,y:t},snapshot:w,historyBefore:We([S])},this.host.requestRenderAll();return}let b=h||!p?null:this.hitHandle(e,t);if(b){if(o.selection.length===1){let S=o.selection[0];if(b==="mtr"){let w=S.center;this.freezeRotateHandle(S.raw.angle??0,w),this.gesture={type:"rotate",center:w,startAngle:Math.atan2(i.y-w.y,i.x-w.x),snapshot:{node:S,angle0:S.raw.angle??0},cursorOffset:225,historyBefore:We([S])}}else if(Lr(b)&&(ms(S)||Ao(S)))this.gesture={type:"cornerRadius",node:S,corner:Po[b],model:Ao(S)?"image":"rect",historyBefore:We([S])};else if(S instanceof ee&&nr(b)){let w=of(S,b);w.historyBefore=We([S]),this.gesture=w}else if(S instanceof le&&nr(b)){let w=sf(S,b);w.historyBefore=We([S]),this.gesture=w}else this.gesture={type:"scale",handle:b,snapshot:cc(S,b,o),freeScale:r&&vn.has(b),historyBefore:We([S])}}else{let S=et(o),w=o.selection.filter(R=>!at(R));if(b==="mtr"){let R=ws(S.quad);w.length&&this.freezeRotateHandle(S.angle,R),this.gesture={type:"multi-rotate",center:R,startAngle:Math.atan2(i.y-R.y,i.x-R.x),frameAngle0:S.angle,frame:Ts(S.quad),snapshot:{members:w.map(P=>({node:P,angle0:P.raw.angle??0,center0:{...P.center}}))},historyBefore:We(o.selection)}}else this.gesture={type:"multi-scale",snapshot:Qd(w,b,S),freeScale:r&&vn.has(b),historyBefore:We(o.selection)}}return}let x=h||!p?null:this.hitCornerRotateZone(e,t);if(x){let S=o.selection[0],w=S.center;this.host.rotateDrag!==void 0&&(this.host.rotateDrag={spec:null,center:{x:w.x,y:w.y}}),this.gesture={type:"rotate",center:w,startAngle:Math.atan2(i.y-w.y,i.x-w.x),snapshot:{node:S,angle0:S.raw.angle??0},cursorOffset:Ql[x],historyBefore:We([S])};return}if(!h&&o.selection.length===1&&o.selection[0]instanceof ee){let S=o.selection[0];if(!o.findTarget(i.x,i.y)&&S.dragHandleHit(i.x,i.y,this.host.zoom)){let w=new Map;for(let R of o.selection)w.set(R,{left:R.raw.left??0,top:R.raw.top??0});this.gesture={type:"move",start:i,startCss:{x:e,y:t},snapshot:w,historyBefore:We(o.selection)},this.host.requestRenderAll();return}}if(!r){let S=o.nodes.find(w=>Ze(w)&&w.visible&&w.raw.visible!==!1&&w.containsPoint(i.x,i.y));if(S){o.setSelection([S],"create"),this.gesture={type:"reference-line",node:S,axis:S.dims.y===0?"horizontal":"vertical",creating:!1,historyBefore:We([S])},this.host.requestRenderAll();return}}let g=o.findTarget(i.x,i.y),y=g instanceof ee?g:null;if(y){let S=y.borderOrIndicatorHit(i.x,i.y,this.host.zoom);if(S?.inCircle){this.gesture={type:"table-indicator-click",node:y,border:S.border};return}let w=y.borderHit(i.x,i.y);if(w&&o.selection.includes(y)){let P=nf(y,w,i);P.historyBefore=We([y]),this.gesture=P;return}let R=y.cellHit(i.x,i.y);if(R){o.selection.includes(y)?!r&&o.selection.length>1&&(this.deferredClickSwitch=y):o.setSelection([y],"create");let P=new Map;for(let E of o.selection)at(E)||P.set(E,{left:E.raw.left??0,top:E.raw.top??0});this.gesture={type:"table-cell-click",node:y,start:i,anchorCell:R,shift:r,moveSnapshot:P,frame0:o.selection.length>1&&o.selectionFrame?{...o.selectionFrame}:void 0,historyBefore:We(o.selection)},this.host.requestRenderAll();return}}if(f&&d){if(g===d){let S=d.maskChildren.find(w=>w.visible&&w.containsPoint(i.x,i.y));if(S){S!==d.editingMask&&(d.editingMask=S),o.setActiveGroupChild(S);let w=new Map;for(let R of o.selection)at(R)||w.set(R,{left:R.raw.left??0,top:R.raw.top??0});this.gesture={type:"move",start:i,startCss:{x:e,y:t},snapshot:w,frame0:void 0,historyBefore:We(o.selection)}}else d.exitMaskEditing(),o.setActiveGroupChild(null);this.host.requestRenderAll();return}d.exitMaskEditing(),this.host.requestRenderAll()}let v=g instanceof ee?null:g;if(v){let S=o.selection.includes(v),w=o.groupEditing;if(r){let R=(o.selection.includes(v)?o.selection.filter(P=>P!==v):[...o.selection,v]).filter(P=>!at(P));o.setSelection(R,"update")}else o.selection.includes(v)?o.selection.length>1&&(this.deferredClickSwitch=v):o.setSelection([v],"create");if(v instanceof J&&!(v instanceof ee)&&!(v instanceof le))o.setActiveGroupChild(Nr(v,i.x,i.y,o.selection));else if(v instanceof le&&S&&o.selection.length===1){let R=v.maskChildren.find(P=>P.visible&&P.containsPoint(i.x,i.y))??null;o.setActiveGroupChild(R),R?v.editingMask=R:v.exitMaskEditing()}else o.activeGroupChild&&o.setActiveGroupChild(null);if(o.selection.includes(v))if(at(v)&&S&&o.selection.length===1&&o.selection[0]===v)this.gesture={type:"marquee",anchor:i,additive:r,hold:!0};else{let R=o.activeGroupChild,P=w&&R&&v instanceof J&&!(v instanceof ee)&&!(v instanceof le)&&o.selection.length===1&&o.selection[0]===v?es(v,R):[],E=P.length&&R?{child:R,toLocal:dd(R),shells:P}:null;if(E){let C=new Map;C.set(E.child,{left:E.child.raw.left??0,top:E.child.raw.top??0});let T=[E.child,...E.shells,...E.shells.flatMap(M=>M.children)];this.gesture={type:"move",start:i,startCss:{x:e,y:t},snapshot:C,childMove:E,historyBefore:We(T)}}else{let C=new Map;for(let T of o.selection)at(T)||C.set(T,{left:T.raw.left??0,top:T.raw.top??0});this.gesture={type:"move",start:i,startCss:{x:e,y:t},snapshot:C,frame0:o.selection.length>1&&o.selectionFrame?{...o.selectionFrame}:void 0,historyBefore:We(o.selection)}}}this.host.requestRenderAll();return}this.gesture={type:"marquee",anchor:i,additive:r},r||o.clearSelection(),this.host.requestRenderAll()}onPointerMove(e,t){let r=this.host.document,o=this.host.toScene(e,t),i=this.gesture;if(i.type==="none"){this.el.style.cursor=this.hoverCursor(e,t,o),this.updateHover(e,t,o);return}if(i.type==="move"){if(i.snapshot.size){if(!this.performed&&Math.hypot(e-i.startCss.x,t-i.startCss.y)<=Yd)return;this.performed=!0;let s=o.x-i.start.x,a=o.y-i.start.y;if(i.childMove){let l=i.childMove.toLocal(s,a);r.applyTransform([...i.snapshot.keys()],c=>{let u=i.snapshot.get(c);return{left:u.left+l.x,top:u.top+l.y}},"moving")}else r.applyTransform([...i.snapshot.keys()],l=>{let c=i.snapshot.get(l);return{left:c.left+s,top:c.top+a}},"moving"),i.frame0&&r.setSelectionFrame({...i.frame0,center:{x:i.frame0.center.x+s,y:i.frame0.center.y+a}})}}else if(i.type==="reference-line"){this.performed=!0;let s=i.axis==="horizontal";r.applyTransform([i.node],()=>({visible:!0,...s?{top:o.y}:{left:o.x}}),"moving"),this.host.referenceLineDrag!==void 0&&(this.host.referenceLineDrag={axis:i.axis,position:s?o.y:o.x})}else if(i.type==="scale")this.performed=!0,Kd(r,i.snapshot,o,i.freeScale),r.applyTransform([i.snapshot.node],()=>({}),"scaling"),!i.snapshot.bakeFont&&!i.snapshot.bakeWidth&&!i.snapshot.bakeHeight&&!i.snapshot.bakeGroup&&this.host.registerScalingSnap?.(i.snapshot.node,i.handle);else if(i.type==="cornerRadius")if(i.model==="image"){let s=sy(i.node,i.corner,o);s&&(this.performed=!0,r.applyTransform([i.node],()=>s,"cornerRadius"))}else{let s=iy(i.node,i.corner,o);s!==null&&(this.performed=!0,r.applyTransform([i.node],()=>({radius:s}),"cornerRadius"))}else if(i.type==="multi-scale")i.snapshot.members.length&&(this.performed=!0,Zd(r,i.snapshot,o,i.freeScale),this.host.registerScalingSnap?.(r.selection[0],i.snapshot.handle));else if(i.type==="rotate"){this.performed=!0;let s=Math.atan2(o.y-i.center.y,o.x-i.center.x),a=i.snapshot.angle0+vs(s-i.startAngle);a=(a%360+360)%360;let l=i.childTransform?.pivotLocal??i.center;r.applyTransform([i.snapshot.node],c=>c.rotateAroundCenter(a,l),"rotating"),this.el.style.cursor=Do((i.snapshot.node.raw.angle??0)+(i.cursorOffset??225))}else if(i.type==="multi-rotate")i.snapshot.members.length&&(this.performed=!0,Jd(r,i,o),this.el.style.cursor=Do((r.selectionFrame?.angle??0)+225));else if(i.type==="marquee"){if(i.hold&&Math.hypot(o.x-i.anchor.x,o.y-i.anchor.y)<=Es)return;this.host.marquee={left:i.anchor.x,top:i.anchor.y,right:o.x,bottom:o.y};let s=r.objectsIntersectingRect(i.anchor.x,i.anchor.y,o.x,o.y).filter(l=>!at(l)),a=(i.additive?[...new Set([...r.selection,...s])]:s).filter(l=>!at(l));r.setSelection(a,"update")}else if(i.type==="text-select"){let s=r.editingNode;if(s){let a=s.localPoint(o.x,o.y),l=s.cursorIndexAt(a.x,a.y);this.host.setEditingSelection(Math.min(i.anchorIdx,l),Math.max(i.anchorIdx,l))}}else if(i.type==="table-border-drag")this.performed=!0,rf(i,o);else if(i.type==="table-edge-resize")this.performed=!0,cf(r,i,o);else if(i.type==="puzzle-edge-resize")this.performed=!0,lf(r,i,o);else if(i.type==="puzzle-mask-edge-resize")this.performed=!0,af(i,o);else if(i.type==="crop-handle")this.performed=!0,this.host.cropSession?.applyHandle(i.handle,o);else if(i.type==="expand-handle")this.performed=!0,this.host.expandSession?.applyHandle(i.handle,o);else if(i.type==="expand-image-drag")this.performed=!0,this.host.expandSession?.moveImageBy({x:o.x-i.last.x,y:o.y-i.last.y}),i.last=o;else if(i.type==="crop-move")this.performed=!0,this.host.cropSession?.moveImageBy({x:o.x-i.last.x,y:o.y-i.last.y}),i.last=o;else if(i.type==="path-anchor-drag")this.performed=!0,this.host.pathSession?.applyAnchorDrag(i.key,o);else if(i.type==="path-body-drag")this.performed=!0,this.host.pathSession?.moveBodyBy({x:o.x-i.last.x,y:o.y-i.last.y}),i.last=o;else if(i.type==="warp-anchor-drag")this.performed=!0,this.host.warpSession?.applyAnchorDrag(i.anchor,o);else if(i.type==="table-range-drag"){let s=i.node.cellHit(o.x,o.y);if(s){let a=bn(i.node.cellMap,i.anchor,s);i.node.setCellSelection(a,i.anchor,Xe(a))}}else if(i.type==="table-cell-click"){if(i.shift){let s=i.node.cellHit(o.x,o.y),a=i.node.cellAnchor??i.anchorCell;if(s&&a){let l=bn(i.node.cellMap,a,s);i.node.setCellSelection(l,a,Xe(l))}}else if(Math.hypot(o.x-i.start.x,o.y-i.start.y)>Es)return this.deferredClickSwitch=null,this.gesture={type:"move",start:i.start,startCss:{x:e,y:t},snapshot:i.moveSnapshot,frame0:i.frame0,historyBefore:i.historyBefore},this.onPointerMove(e,t)}this.host.requestRenderAll()}onPointerUp(e,t){let r=this.host.document,o=this.gesture;if(this.gesture={type:"none"},this.host.marquee=null,this.host.rotateDrag!==void 0&&(this.host.rotateDrag=null),o.type!=="none"){if(this.host.settleMoveSnap?.(),this.host.finishSnapGesture?.(),o.type==="move"){if(this.performed)if(o.childMove){let i=ts(o.childMove.shells),s=[...new Set([o.childMove.child,...i])];r.applyTransform(s,()=>({}),"modified",{action:Ne.drag,before:o.historyBefore})}else r.applyTransform([...o.snapshot.keys()],()=>({}),"modified",{action:Ne.drag,before:o.historyBefore});else if(this.deferredClickSwitch){let i=this.deferredClickSwitch;r.selection.length>1&&r.selection.includes(i)&&r.setSelection([i],"create")}}else if(o.type==="reference-line")this.host.referenceLineDrag!==void 0&&(this.host.referenceLineDrag=null),(this.host.rulerVisible?hc(e,t):null)===o.axis||o.creating&&!this.performed?(r.remove(o.node),r.fireObjectModified([o.node],{action:Ne.drag,before:o.historyBefore?[o.historyBefore.get(o.node)].filter(s=>!!s):void 0})):this.performed&&r.applyTransform([o.node],()=>({selectable:!1}),"modified",{action:Ne.drag,before:o.historyBefore});else if(o.type==="scale"||o.type==="rotate"){if(this.performed)if(o.childTransform){let i=ts(o.childTransform.shells),s=[...new Set([o.childTransform.child,...i])];r.applyTransform(s,()=>({}),"modified",{action:o.type,before:o.historyBefore})}else r.applyTransform([o.snapshot.node],()=>({}),"modified",{action:o.type,before:o.historyBefore})}else if(o.type==="cornerRadius")this.performed&&r.applyTransform([o.node],()=>({}),"modified",{action:Ne.cornerRadius,before:o.historyBefore});else if(o.type==="multi-scale"||o.type==="multi-rotate")this.performed&&r.applyTransform(o.snapshot.members.map(i=>i.node),()=>({}),"modified",{action:o.type==="multi-scale"?Ne.scale:Ne.rotate,before:o.historyBefore});else if(o.type==="marquee")r.commitGeometry();else if(o.type==="path-anchor-drag"||o.type==="path-body-drag")this.performed&&this.host.pathSession?.commit();else if(o.type==="warp-anchor-drag")this.performed&&this.host.warpSession?.endDrag();else if(o.type==="table-border-drag")o.node.setCellSelection(o.savedCells,o.savedAnchor,o.savedRange),o.node.hoveredBorder=null,o.node.borderDragging=!1,this.performed&&(o.node.rebuildTable(),r.applyTransform([o.node],()=>({}),"modified",{action:Ne.scale,before:o.historyBefore}));else if(o.type==="table-edge-resize")this.performed&&r.applyTransform([o.node],()=>({}),"modified",{action:Ne.scale,before:o.historyBefore});else if(o.type==="puzzle-edge-resize")this.performed&&r.applyTransform([o.node],()=>({}),"modified",{action:Ne.scale,before:o.historyBefore});else if(o.type==="puzzle-mask-edge-resize")this.performed&&r.applyTransform([o.node],()=>({}),"modified",{action:Ne.scale,before:o.historyBefore});else if(o.type==="table-indicator-click"){let i=this.host.toScene(e,t),s=o.node.borderOrIndicatorHit(i.x,i.y,this.host.zoom);s?.inCircle&&uf(r,o.node,s.border)}else if(o.type==="table-strip-click"){let i=this.host.toScene(e,t),s=o.node.stripHit(i.x,i.y,this.host.zoom);s?.kind==="col-strip"?o.node.setColumnSelection(s.col):s?.kind==="row-strip"&&o.node.setRowSelection(s.row)}else if(o.type==="table-cell-click"){let i=this.host.toScene(e,t);if(Math.hypot(i.x-o.start.x,i.y-o.start.y)<=Es)if(this.deferredClickSwitch===o.node)r.selection.length>1&&r.selection.includes(o.node)&&r.setSelection([o.node],"create");else{let s=o.node.cellHit(i.x,i.y);if(s)if(o.shift){let a=o.node.cellAnchor??o.anchorCell??s,l=bn(o.node.cellMap,a,s);o.node.setCellSelection(l,a,Xe(l))}else o.node.setCellSelection([s],s,{r1:s.row,r2:s.row,c1:s.col,c2:s.col})}}this.deferredClickSwitch=null,this.host.requestRenderAll()}}dispose(){this.detach?.(),this.detach=null}};var ay=new Set(["qrcode","barcode"]),ly=n=>{let e=n.raw.type;return typeof e=="string"&&ay.has(e.toLowerCase())},Rs=class{host;onDblClick;disposed=!1;interactive;constructor(e,t=!0){this.host=e,this.interactive=t,this.onDblClick=r=>{if(e.interactionSuspended)return;let o=e.canvasEl.getBoundingClientRect(),i=e.toScene(r.clientX-o.left,r.clientY-o.top),s=e.document.findTarget(i.x,i.y);if(s instanceof J&&!(s instanceof ee)&&!(s instanceof le)){let a=Nr(s,i.x,i.y,e.document.selection);a&&!(a instanceof ee)&&!(a instanceof le)&&(s=a)}this.dispatch(s,i.x,i.y)},this.interactive&&e.canvasEl.addEventListener("dblclick",this.onDblClick)}dispatch(e,t,r){if(e instanceof ee){let o=e.cellHit(t,r);o&&this.host.startCellEditing(e,o.row,o.col);return}if(e instanceof le){let o=e.maskChildren.find(i=>i.visible&&i.containsPoint(t,r));o&&(this.host.document.selection.includes(e)||this.host.document.setSelection([e],"create"),e.editingMask=o,this.host.document.setActiveGroupChild(o),this.host.requestRenderAll());return}if(e instanceof Se){this.host.enterTextEditingAtClick(e,t,r);return}if(e?.isImageType&&!ly(e)){let o=this.host.document.events;e.raw.smartObject?o.fire("smartobject:open-requested",e):o.fire("image:replace-requested",e)}}dispose(){this.disposed||(this.disposed=!0,this.host.canvasEl.removeEventListener("dblclick",this.onDblClick))}};var Ps=class n{host;onKeydown;offDocEvents;disposed=!1;constructor(e){this.host=e,this.onKeydown=i=>this.handleKey(i),window.addEventListener("keydown",this.onKeydown);let t=e.document.events,r=()=>this.pruneCellState(),o=[t.on("selection:created",r),t.on("selection:updated",r),t.on("selection:cleared",r)];this.offDocEvents=()=>o.forEach(i=>i())}dispose(){this.disposed||(this.disposed=!0,window.removeEventListener("keydown",this.onKeydown),this.offDocEvents())}pruneCellState(){let e=this.host.document;for(let t of e.nodes)t instanceof ee&&!e.selection.includes(t)&&t.clearCellInteractionState()}get activeTable(){let e=this.host.document;if(e.editingNode||e.selection.length!==1)return null;let t=e.selection[0];return t instanceof ee?t:null}static isTypingTarget(e){let t=e.target;return t instanceof HTMLElement?t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.tagName==="SELECT"||t.isContentEditable:!1}handleKey(e){let t=this.activeTable;if(!t||n.isTypingTarget(e))return;let r=e.ctrlKey||e.metaKey,o=e.key;if(o==="Escape"){t.hasCellSelection&&(t.clearCellSelection(),this.host.requestRenderAll(),e.preventDefault());return}if(r&&!e.shiftKey&&o.toLowerCase()==="a"){let i=t.tableView,s=wo(t.cellMap,i.rows,i.cols);t.setCellSelection(s,s[0]??null,Xe(s)),this.host.requestRenderAll(),e.preventDefault();return}if(r&&o.toLowerCase()==="m"){e.shiftKey?this.unmergeFirst(t):this.mergeSelection(t);return}if(t.hasCellSelection&&!r&&!e.altKey&&o.length===1&&!/^(Enter|Escape|Tab|Delete|Backspace)$/.test(o)){let i=t.selectedCells[0];i&&(e.preventDefault(),this.host.startCellEditing(t,i.row,i.col,{initialText:o}));return}if(o==="Enter"&&t.hasCellSelection){let i=t.selectedCells[0];i&&(e.preventDefault(),this.host.startCellEditing(t,i.row,i.col));return}if(o==="Delete"||o==="Backspace"){this.deleteSelectionText(t);return}if(t.hasCellSelection&&(o==="ArrowUp"||o==="ArrowDown"||o==="ArrowLeft"||o==="ArrowRight")){let s={ArrowUp:{row:-1,col:0},ArrowDown:{row:1,col:0},ArrowLeft:{row:0,col:-1},ArrowRight:{row:0,col:1}}[o];this.navigate(t,s.row,s.col),e.preventDefault();return}o==="Tab"&&(this.navigate(t,0,e.shiftKey?-1:1,!0),e.preventDefault())}navigate(e,t,r,o=!1){let i=e.tableView,s=e.cellAnchor??e.selectedCells[0]??{row:0,col:0},a=s.row+t,l=s.col+r;o?(l>=i.cols?(l=0,a++):l<0&&(l=i.cols-1,a--),a>=i.rows?a=0:a<0&&(a=i.rows-1)):(a=Math.max(0,Math.min(i.rows-1,a)),l=Math.max(0,Math.min(i.cols-1,l)));let c=lt(e.cellMap,a,l);e.setCellSelection([c],c,{r1:c.row,r2:c.row,c1:c.col,c2:c.col}),this.host.requestRenderAll()}commit(e){e.rebuildTable(),this.host.document.applyTransform([e],()=>({}),"modified"),this.host.requestRenderAll()}mergeSelection(e){if(e.selectedCells.length<2)return;let t=Xe(e.selectedCells);if(!t)return;let r=bo(e.raw,t.r1,t.c1,t.r2,t.c2),o={row:r.r1,col:r.c1};e.setCellSelection([o],o,r),this.commit(e)}unmergeFirst(e){for(let t of e.selectedCells)if(xo(e.raw,t.row,t.col)){let r={row:t.row,col:t.col};e.setCellSelection([r],r,{r1:t.row,r2:t.row,c1:t.col,c2:t.col}),this.commit(e);return}}deleteSelectionText(e){let t=e.cellMap,r=!1;for(let o of e.selectedCells){let i=we(t,o.row,o.col);i&&!i.isMerged&&i.text&&(i.text="",r=!0)}r&&this.commit(e)}};var dc=(n,e,t)=>Math.max(e,Math.min(t,n)),ks={min:.05,max:5},Fr=60,cy=n=>{let e=n.workspaceRect();if(e.width<=0||e.height<=0)return null;let t=n.viewportTransform,r=e.left*t[0]+t[4],o=e.top*t[0]+t[5],i=r+e.width*t[0],s=o+e.height*t[0],{width:a,height:l}=n.viewSize;return r<-1||o<-1||i>a+1||s>l+1?null:{x:(r+i)/2,y:(o+s)/2}},hf=(n,e)=>{n.preventDefault();let{deltaX:t,deltaY:r,deltaMode:o,ctrlKey:i,metaKey:s,altKey:a,shiftKey:l}=n,c=o===1?16:o===2&&e.viewSize.height||1,u=o===0?t:t*c,h=o===0?r:r*c;if(i||s||a){let A=Math.abs(h)<10?h*2:h/3,O=e.viewportTransform[0],F=dc(O*(1-A/200),ks.min,ks.max),H=cy(e)??e.cursorPoint(n);e.zoomAt(H.x,H.y,F/O);return}let d=o===0&&Math.abs(t)<=10&&Math.abs(r)<=10,f=dc(e.viewportTransform[0],.1,ks.max),m=Math.max(1,f)*1.25,p=20*m,b=A=>dc(A,-60,60),x=0,g=0;if(l||Math.abs(u)>Math.abs(h)){let A=u!==0?u:h;A!==0&&(x=d?-b(A)*m:A>0?-p:p)}else h!==0&&(g=d?-b(h)*m:h>0?-p:p);if(x===0&&g===0)return;let v=e.viewportTransform,{width:S,height:w}=e.viewSize,R=e.workspaceRect(),P=R.width*f,E=R.height*f,C=v[4],T=v[5],M=Fr-P;C+x<M&&(x=M-C),C+x>S-Fr&&(x=S-Fr-C);let k=Fr-E;T+g<k&&(g=k-T),T+g>w-Fr&&(g=w-Fr-T),!(x===0&&g===0)&&e.pan(x,g)};var As=class{constructor(e,t,r,o=!0){this.host=e;this.snapGuide=t;this.sources=r;this.interactive=o;let i=e.canvasEl;this.pointer=new Ms(i,e,this.interactive),this.tableInteraction=new Ps(e);let s=p=>{if(p.key!=="Escape")return;let b=e.document.selection;b.length===1&&b[0]instanceof le&&b[0].editingMask&&(b[0].exitMaskEditing(),e.document.setActiveGroupChild(null),e.requestRenderAll())};this.interactive&&window.addEventListener("keydown",s);let a=e.document.events,l=()=>e.requestRenderAll(),c=[a.on("selection:created",l),a.on("selection:updated",l),a.on("selection:cleared",l),a.on("object:modified",l),a.on("object:moving",p=>this.snapGuide.registerMove(p)),a.on("object:removed",p=>{p instanceof ie&&this.sources.releaseAnimatedNode(p)})];this.offDocEvents=()=>c.forEach(p=>p()),this.dblClick=new Rs(e,this.interactive);let u=p=>{hf(p,e)},h=p=>{if(p.button===1){p.preventDefault(),e.panning=!0,this.lastPanPointer={x:p.clientX,y:p.clientY},i.style.cursor="grab";try{i.setPointerCapture(p.pointerId)}catch{}}},d=p=>{if(!e.panning||!this.lastPanPointer)return;let b=p.clientX-this.lastPanPointer.x,x=p.clientY-this.lastPanPointer.y;this.lastPanPointer={x:p.clientX,y:p.clientY},e.pan(b,x),i.style.cursor="grab"},f=p=>{e.panning&&(e.panning=!1,this.lastPanPointer=null,i.hasPointerCapture(p.pointerId)&&i.releasePointerCapture(p.pointerId),i.style.cursor="default")},m=p=>e.handleFontsLoaded(p.fontfaces??[]);document.fonts?.addEventListener?.("loadingdone",m),this.interactive&&(i.addEventListener("wheel",u,{passive:!1}),i.addEventListener("pointerdown",h),window.addEventListener("pointermove",d),window.addEventListener("pointerup",f)),this.detachListeners=()=>{document.fonts?.removeEventListener?.("loadingdone",m),i.removeEventListener("wheel",u),i.removeEventListener("pointerdown",h),window.removeEventListener("pointermove",d),window.removeEventListener("pointerup",f),window.removeEventListener("keydown",s)}}host;snapGuide;sources;interactive;pointer;tableInteraction;dblClick;detachListeners=null;offDocEvents=null;lastPanPointer=null;get pointerActive(){return this.pointer.active}dispose(){this.detachListeners?.(),this.offDocEvents?.(),this.pointer.dispose(),this.dblClick.dispose(),this.tableInteraction.dispose()}};var uy={left:-.5,top:-.5,center:0,bottom:.5,right:.5},_t=n=>typeof n=="string"?uy[n]??0:n-.5,fc=(n,e,t)=>{let r=Math.cos(e),o=Math.sin(e),i=n.x-t.x,s=n.y-t.y;return{x:t.x+r*i-o*s,y:t.y+o*i+r*s}},mc=n=>({x:n.width*n.scaleX,y:n.height*n.scaleY}),Ns=mc,Fo=n=>n*Math.PI/180,pc=(n,e,t,r,o,i=!1,s=!1)=>{let a=i?-1:1,l=s?-1:1,c={x:n.x+e*r.x*a,y:n.y+t*r.y*l};return o&&(c=fc(c,Fo(o),n)),c},bc=(n,e,t,r,o,i=!1,s=!1)=>{let a=i?-1:1,l=s?-1:1,c={x:n.x-e*r.x*a,y:n.y-t*r.y*l};return o&&(c=fc(c,Fo(o),n)),c},Is=(n,e,t,r,o)=>pc(n,_t(e),_t(t),r,o),Oo=(n,e,t,r,o,i)=>bc({x:n,y:e},_t(t),_t(r),o,i),Or=(n,e,t=0,r=0)=>{let o=Oo(n.left,n.top,n.originX,n.originY,Ns(n),n.angle),i=e;n.angle&&(i=fc(i,-Fo(n.angle),o));let s=Ns(n),a=n.flipX?-1:1,l=n.flipY?-1:1;return{x:(i.x-o.x)*a-t*s.x,y:(i.y-o.y)*l-r*s.y}},Br=(n,e,t,r)=>{let o=Ns(n),i=Oo(n.left,n.top,n.originX,n.originY,o,n.angle),s=pc(i,e,t,o,n.angle,n.flipX,n.flipY),a=r.scaleX??n.scaleX,l=r.scaleY??n.scaleY,c={x:r.width*a,y:r.height*l},u=bc(s,e,t,c,n.angle,n.flipX,n.flipY),h=Is(u,n.originX,n.originY,c,n.angle);return{...n,...r,scaleX:a,scaleY:l,left:h.x,top:h.y}},hy=(n,e)=>{let{width:t,cropX:r}=n,i=Or(n,e).x/n.scaleX- -(t/2),s=t-i;if(r+i<0&&(i=-r,s=t+r),s<8){let a=Math.min(8,r+t);i=t-a,s=a}return Br(n,.5,0,{width:s,height:n.height,cropX:r+i,cropY:n.cropY})};var dy=(n,e)=>{let{width:t,cropX:r}=n,o=Or(n,e),i=t-(t/2-o.x/n.scaleX);return i+r>n.naturalWidth&&(i=n.naturalWidth-r),i<8&&(i=Math.min(8,n.naturalWidth-r)),Br(n,-.5,0,{width:i,height:n.height,cropX:r,cropY:n.cropY})};var fy=(n,e)=>{let{height:t,cropY:r}=n,i=Or(n,e).y/n.scaleY- -(t/2),s=t-i;if(r+i<0&&(i=-r,s=t+r),s<8){let a=Math.min(8,r+t);i=t-a,s=a}return Br(n,0,.5,{width:n.width,height:s,cropX:n.cropX,cropY:r+i})};var my=(n,e)=>{let{height:t,cropY:r}=n,o=Or(n,e),i=t-(t/2-o.y/n.scaleY);return i+r>n.naturalHeight&&(i=n.naturalHeight-r),i<8&&(i=Math.min(8,n.naturalHeight-r)),Br(n,0,-.5,{width:n.width,height:i,cropX:n.cropX,cropY:r})};var Ls=(n,e,t)=>e==="left"||e==="right"?e==="left"?hy(n,t):dy(n,t):e==="top"?fy(n,t):my(n,t),df=(n,e,t)=>{let r=e==="tl"||e==="bl"?"left":"right",o=e==="tl"||e==="tr"?"top":"bottom",i=Ls(n,r,t);return Ls(i,o,t)};var ff=(n,e,t,r)=>{if(!(r>0)||!Number.isFinite(r))return null;let o=Or(n,t),i=e==="tl"||e==="bl",s=e==="tl"||e==="tr",a=i?n.cropX+n.width:n.naturalWidth-n.cropX,l=s?n.cropY+n.height:n.naturalHeight-n.cropY,c=Math.min(a,l/r);if(!(c>0))return null;let u=Math.min(c,Math.max(8,8/r)),h=n.width/2+(i?-1:1)*o.x/n.scaleX,d=n.height/2+(s?-1:1)*o.y/n.scaleY,f=Math.max(u,Math.min(c,h,d/r)),m=f*r;return Br(n,i?.5:-.5,s?.5:-.5,{width:f,height:m,cropX:i?n.cropX+n.width-f:n.cropX,cropY:s?n.cropY+n.height-m:n.cropY})},mf=(n,e,t=!1)=>{if(!(e>0)||!Number.isFinite(e))return null;let r=t?n.scaleY*e/n.scaleX:e,o=n.width*n.scaleX/e,i=n.height*n.scaleY/r,s=n.cropX+(n.width-o)/2,a=n.cropY+(n.height-i)/2;return o<Math.min(8,n.naturalWidth)||i<Math.min(8,n.naturalHeight)||s<0||a<0||s+o>n.naturalWidth||a+i>n.naturalHeight?null:Br(n,0,0,{width:o,height:i,cropX:s,cropY:a,scaleX:e,scaleY:r})},py=(n,e,t,r,o)=>{let i=Math.abs(n.x/t),s=Math.abs(n.y/e);return Math.min(i,s)},pf=(n,e,t)=>{if(n.width<=0||n.height<=0)return null;let{naturalWidth:r,naturalHeight:o}=n,i=r-n.width-n.cropX,s=o-n.height-n.cropY,a,l;e==="br"?(a=-n.cropX/n.width,l=-n.cropY/n.height):e==="tl"?(a=1+i/n.width,l=1+s/n.height):e==="tr"?(a=-n.cropX/n.width,l=1+s/n.height):(a=1+i/n.width,l=-n.cropY/n.height);let c=Or(n,t,_t(a),_t(l)),u=Math.min(n.width*n.scaleX/Math.min(8,r),n.height*n.scaleY/Math.min(8,o)),h=Math.min(py(c,o,r,n.flipX,n.flipY),u);if(!(h>0)||!Number.isFinite(h))return null;let d=h/n.scaleX,f=h/n.scaleY,m=n.width/d,p=n.height/f,b=i/d,x=s/f,g,y;if(e==="br"){if(g=n.cropX/d,y=n.cropY/f,g+m>r||y+p>o)return null}else if(e==="tl"){if(g=r-m-b,y=o-p-x,m+b>r||p+x>o)return null}else if(e==="tr"){if(g=n.cropX/d,y=o-p-x,g+m>r||x+p>o)return null}else if(g=r-m-b,y=n.cropY/f,m+b>r||p+y>o)return null;let v,S;e==="br"?(v=-g/m,S=-y/p):e==="tl"?(v=1+b/m,S=1+x/p):e==="tr"?(v=-g/m,S=1+x/p):(v=1+b/m,S=-y/p);let w=Ns(n),R=Oo(n.left,n.top,n.originX,n.originY,w,n.angle),P=pc(R,_t(a),_t(l),w,n.angle,n.flipX,n.flipY),E={x:m*h,y:p*h},C=bc(P,_t(v),_t(S),E,n.angle,n.flipX,n.flipY),T=Is(C,n.originX,n.originY,E,n.angle);return{...n,width:m,height:p,cropX:g,cropY:y,scaleX:h,scaleY:h,left:T.x,top:T.y}},bf=(n,e)=>{let t=Math.cos(Fo(n.angle)),r=Math.sin(Fo(n.angle)),o=n.flipX?-1:1,i=n.flipY?-1:1,s=t*e.x+r*e.y,a=-r*e.x+t*e.y,l=-s/(o*n.scaleX),c=-a/(i*n.scaleY),u=n.cropX+l,h=n.cropY+c;return u<0?u=0:u+n.width>n.naturalWidth&&(u=n.naturalWidth-n.width),h<0?h=0:h+n.height>n.naturalHeight&&(h=n.naturalHeight-n.height),{cropX:u,cropY:h}},xf=(n,e)=>{let t=n.naturalHeight/n.naturalWidth,r,o;t>e?(r=n.naturalWidth,o=n.naturalWidth*e):(o=n.naturalHeight,r=n.naturalHeight/e);let i=(n.naturalWidth-r)/2,s=(n.naturalHeight-o)/2;return{...n,width:r,height:o,cropX:i,cropY:s}},gf=(n,e,t)=>{let r=n.cropSizeMode==="visible",o=n.cropX??0,i=n.cropY??0,s=n.width??e,a=n.height??t,l=r?s:s-o,c=r?a:a-i;return e>0&&t>0&&(l=Math.min(Math.max(l,0),e),c=Math.min(Math.max(c,0),t),o=Math.min(Math.max(o,0),e-l),i=Math.min(Math.max(i,0),t-c)),{left:n.left??0,top:n.top??0,angle:n.angle??0,originX:n.originX??"left",originY:n.originY??"top",flipX:n.flipX===!0,flipY:n.flipY===!0,width:l,height:c,cropX:o,cropY:i,scaleX:n.scaleX??1,scaleY:n.scaleY??1,naturalWidth:e,naturalHeight:t,cropSizeMode:n.cropSizeMode??"legacy"}},yf=n=>{let e=n.cropSizeMode==="visible";return{left:n.left,top:n.top,width:e?n.width:n.width+n.cropX,height:e?n.height:n.height+n.cropY,cropX:n.cropX,cropY:n.cropY,scaleX:n.scaleX,scaleY:n.scaleY}},Kt={tl:{x:-.5,y:-.5},tr:{x:.5,y:-.5},bl:{x:-.5,y:.5},br:{x:.5,y:.5},left:{x:-.5,y:0},right:{x:.5,y:0},top:{x:0,y:-.5},bottom:{x:0,y:.5}},Bo=(n,e)=>{let t=-n.width/2-n.cropX,r=-n.height/2-n.cropY,o=n.naturalWidth-n.width/2-n.cropX,i=n.naturalHeight-n.height/2-n.cropY;return e==="tl"?{x:t,y:r}:e==="tr"?{x:o,y:r}:e==="bl"?{x:t,y:i}:{x:o,y:i}};var Sf=(n,e,t)=>({type:"Path",path:n.pathOf(e,t),originX:"center",originY:"center",left:0,top:0}),xc=n=>{if(!(n.width>0)||!(n.height>0))return n;let e=n.naturalWidth>0?n.naturalWidth:n.width,t=n.naturalHeight>0?n.naturalHeight:n.height,r=Math.min(n.width,n.height,e,t);if(!(r>0))return n;let o=n.cropX+n.width/2,i=n.cropY+n.height/2,s=o-r/2,a=i-r/2;s<0?s=0:s+r>n.naturalWidth&&n.naturalWidth>0&&(s=Math.max(0,n.naturalWidth-r)),a<0?a=0:a+r>n.naturalHeight&&n.naturalHeight>0&&(a=Math.max(0,n.naturalHeight-r));let l=Oo(n.left,n.top,n.originX,n.originY,mc(n),n.angle),c=Is(l,n.originX,n.originY,{x:r*n.scaleX,y:r*n.scaleY},n.angle);return{...n,width:r,height:r,cropX:s,cropY:a,left:c.x,top:c.y}};var by=(n,e)=>({w:e.naturalWidth||e.width||(n.width??0),h:e.naturalHeight||e.height||(n.height??0)}),xy=(n,e,t)=>({w:e*Math.abs((n.scaleX??1)||1),h:t*Math.abs((n.scaleY??1)||1)}),gy=(n,e,t,r,o,i)=>({cropX:Math.max(0,t/2-o/2-n),cropY:Math.max(0,r/2-i/2-e)}),yy=(n,e,t,r,o,i)=>({clipX:t/2-o/2-n,clipY:r/2-i/2-e}),vf=(n,e,t)=>{let r=by(e,t),o=xy(e,r.w,r.h),i=n.width??0,s=n.height??0,{cropX:a,cropY:l}=gy(n.clipX??0,n.clipY??0,o.w,o.h,i,s);return{left:n.left??0,top:n.top??0,angle:n.angle??0,originX:n.originX??"center",originY:n.originY??"center",flipX:n.flipX===!0,flipY:n.flipY===!0,width:i,height:s,cropX:a,cropY:l,scaleX:n.scaleX??1,scaleY:n.scaleY??1,naturalWidth:o.w,naturalHeight:o.h,cropSizeMode:"visible"}},wf=n=>{let{clipX:e,clipY:t}=yy(n.cropX,n.cropY,n.naturalWidth,n.naturalHeight,n.width,n.height);return{left:n.left,top:n.top,width:n.width,height:n.height,cropX:n.cropX,cropY:n.cropY,clipX:e,clipY:t,scaleX:n.scaleX,scaleY:n.scaleY}};var Tf=12,Ef=14,Cf=7,Sy=1,vy=1,Mf=oe("#f6f7fa"),Rf=oe("#2f6fed"),vc=["e","se","s","sw","w","nw","n","ne","e"],wy=["tl","tr","bl","br"],Ty=["tl","tr","bl","br"],Ey=["left","right","top","bottom"],gc=(n,e,t,r,o)=>{let i=null,s=1/0;for(let a of n){let l=e(a),c=Math.hypot(l.x-t,l.y-r);c<=o&&c<s&&(i=a,s=c)}return i},yc=null,wc=()=>{if(yc)return yc;let n=Math.ceil((Cf+2)*2),e=document.createElement("canvas");e.width=n,e.height=n;let t=e.getContext("2d");return t.beginPath(),t.arc(n/2,n/2,Cf,0,Math.PI*2),t.fillStyle="#ffffff",t.fill(),t.lineWidth=1.5,t.strokeStyle="#2f6fed",t.stroke(),yc=e,e},or=30,ir=7,Wo={x:28,y:16},Ho={x:14,y:4},Sc=2,kf=(n,e)=>{let t=document.createElement("canvas");t.width=n*Sc,t.height=e*Sc;let r=t.getContext("2d");return r?{canvas:t,ctx:r}:null},tt=n=>n*Sc,_s=null,Tc=()=>{if(_s)return _s;let n=kf(or,or);if(!n)return _s=document.createElement("canvas");let{canvas:e,ctx:t}=n;return t.translate(tt(ir),tt(ir)),t.shadowColor="rgba(12, 18, 28, 0.38)",t.shadowBlur=tt(4),t.shadowOffsetX=tt(2),t.shadowOffsetY=tt(2),t.beginPath(),t.lineWidth=tt(6),t.lineCap="round",t.strokeStyle="#dfe2e8",t.moveTo(0,tt(10)),t.lineTo(0,0),t.lineTo(tt(10),0),t.stroke(),_s=e,e},Ds=null,Ec=()=>{if(Ds)return Ds;let n=kf(Wo.x,Wo.y);if(!n)return Ds=document.createElement("canvas");let{canvas:e,ctx:t}=n;return t.translate(tt(Ho.x),tt(Ho.y)),t.shadowColor="rgba(12, 18, 28, 0.38)",t.shadowBlur=tt(4),t.shadowOffsetX=0,t.shadowOffsetY=tt(2),t.beginPath(),t.lineWidth=tt(4),t.lineCap="round",t.strokeStyle="#dfe2e8",t.moveTo(tt(-6),0),t.lineTo(tt(6),0),t.stroke(),Ds=e,e},Af=n=>{let e=Math.hypot(n[0],n[1])||1,t=Math.hypot(n[2],n[3])||1;return[n[0]/e,n[1]/e,n[2]/t,n[3]/t]},Go=(n,e,t,r,o,i,s,a)=>{let l=r*Math.PI/180,c=Math.cos(l),u=Math.sin(l),[h,d,f,m]=Af(n),p=n[0]*e+n[2]*t+n[4],b=n[1]*e+n[3]*t+n[5],x=$([h,d,f,m,0,0],[c,u,-u,c,0,0],!0),g=(i.x-o.x/2)/s,y=(i.y-o.y/2)/s;return{matrix:[x[0],x[1],x[2],x[3],p-(x[0]*g+x[2]*y),b-(x[1]*g+x[3]*y)],dims:{x:o.x/s,y:o.y/s},color:[1,1,1,1],texture:a}},Pf=(n,e)=>{let t=!1;for(let r=0,o=e.length-1;r<e.length;o=r++){let i=e[r].x,s=e[r].y,a=e[o].x,l=e[o].y;s>n.y!=l>n.y&&n.x<(a-i)*(n.y-s)/(l-s)+i&&(t=!t)}return t},Fs=class{constructor(e){this.host=e}host;node=null;circlesVisible=!0;ratio=null;shape=null;detachKey=null;get active(){return this.node!==null}get target(){return this.node}get info(){let e=this.node;if(!e||!(e instanceof ae?e.clipImageEl:e.imageEl))return null;let t=this.liveState();return{nodeId:e.id,handle:"",ratio:this.ratio,circlesVisible:this.circlesVisible,cropX:t.cropX,cropY:t.cropY,width:t.width,height:t.height,isMask:e instanceof ae,shapeActive:!(e instanceof ae)&&this.shape!==null}}enter(e,t){if(this.node&&this.exit(),e instanceof ae){if(!this.host.document.nodes.includes(e)||e.clipDynamicKind||!e.clipImageRaw||!e.clipImageEl)return!1}else if(e instanceof ie||!e.isImageType||!e.imageEl)return!1;this.node=e,this.ratio=null,this.shape=e instanceof ae||!t?.shape?null:t.shape,this.ratio=this.shape?.aspectRatio??null;let r=Math.abs(e.raw.scaleX??1),o=Math.abs(e.raw.scaleY??1);if(this.circlesVisible=r===o,this.host.document.exitEditing(),this.host.document.setSelection([e],"update"),!(e instanceof ae)){let i=s=>{s.key==="Escape"&&this.node&&this.exit()};window.addEventListener("keydown",i),this.detachKey=()=>window.removeEventListener("keydown",i)}return this.shape&&this.writeBack(xc(this.liveState())),this.host.requestRenderAll(),!0}exit(){if(!this.node)return;let e=this.node;this.node=null,this.ratio=null,this.shape=null,this.detachKey?.(),this.detachKey=null,this.host.document.applyTransform([e],()=>({}),"modified",{action:Ne.crop}),this.host.requestRenderAll()}exitByOutsideClick(){this.exit()}setCropShape(e){let t=this.node;if(!t||t instanceof ae)return;this.ratio=e?.aspectRatio??null;let r=this.shape!==null;this.shape=e,e?this.writeBack(xc(this.liveState())):r&&this.writeBack(this.liveState(),!0),this.host.requestRenderAll()}setAspectRatio(e){if(this.node){if(this.ratio=e,e&&e>0){let t=this.shape!==null;this.shape=null;let r=xf(this.liveState(),e);this.writeBack(r,t)}this.host.requestRenderAll()}}hitHandle(e,t){let r=this.node;if(!r)return null;let o=r.matrix,i=this.liveState(),s=(l,c)=>{let u=Q(o,l,c);return this.host.toScreen(u.x,u.y)},a=gc(["br","bl","tr","tl"],l=>{let c=Kt[l];return s(c.x*i.width,c.y*i.height)},e,t,Tf);if(a)return a;if(!this.ratio){let l=gc(["bottom","right","top","left"],c=>{let u=Kt[c];return s(u.x*i.width,u.y*i.height)},e,t,Tf);if(l)return l}if(this.circlesVisible){let l=gc(["br","bl","tr","tl"],c=>{let u=Bo(i,c);return s(u.x,u.y)},e,t,Ef);if(l){let c=Kt[l],u=s(c.x*i.width,c.y*i.height);return Math.hypot(u.x-e,u.y-t)<=Ef?l:`${l}S`}}return null}hitRect(e,t){let r=this.node;if(!r)return!1;let o=this.liveState(),i=r.matrix;if(!(r instanceof ae)){let u=["tl","tr","br","bl"].map(h=>{let d=(h==="tr"||h==="br"?.5:-.5)*o.width,f=(h==="bl"||h==="br"?.5:-.5)*o.height;return Q(i,d,f)});return Pf({x:e,y:t},u)}let s=["tl","tr","br","bl"].map(u=>{let h=(u==="tr"||u==="br"?.5:-.5)*o.width,d=(u==="bl"||u==="br"?.5:-.5)*o.height,f=Q(i,h,d);return this.host.toScreen(f.x,f.y)}),a=Math.abs(s[1].x-s[0].x)/2,l=Math.abs(s[3].y-s[0].y)/2,c=[{x:s[0].x-a,y:s[0].y-l},{x:s[1].x+a,y:s[1].y-l},{x:s[2].x+a,y:s[2].y+l},{x:s[3].x-a,y:s[3].y+l}];return Pf(this.host.toScreen(e,t),c)}applyHandle(e,t){if(!this.node)return;let o=this.liveState(),i=null;e.endsWith("S")?i=this.circlesVisible?pf(o,e.slice(0,2),t):null:os(e)?i=this.ratio?ff(o,e,t,this.ratio):df(o,e,t):this.ratio||(i=Ls(o,e,t)),i&&this.writeBack(i),this.host.requestRenderAll()}setScale(e){if(!this.node)return!1;let t=mf(this.liveState(),e,this.shape!==null);return t?(this.writeBack(t),this.host.document.setProps(this.node,{cropScale:t.scaleX},{deferIndexRebuild:!0}),this.host.requestRenderAll(),!0):!1}moveImageBy(e){if(!this.node)return;let r=this.liveState(),{cropX:o,cropY:i}=bf(r,e);this.writeBack({...r,cropX:o,cropY:i}),this.host.requestRenderAll()}hoverCursor(e,t,r){let o=this.hitHandle(e,t);if(o){if(o.endsWith("S")&&this.node){let i=Kt[o.slice(0,2)],a=((this.node.raw.angle??0)+Math.atan2(i.y,i.x)*180/Math.PI+360)%360;return`${vc[Math.round(a/45)]}-resize`}return"pointer"}return this.hitRect(r.x,r.y)?"move":""}buildOverlay(e){let t=this.node;if(!t||!t.imageEl)return[];let r=this.liveState(),o=t.matrix,i=[],s=(b,x)=>Q(o,b,x),a=r.width,l=r.height,c=Sy/e;for(let b of[1,2]){let x=-a/2+b*a/3,g=s(x,-l/2),y=s(x,l/2);i.push(Re(g,y,c,Mf))}for(let b of[1,2]){let x=-l/2+b*l/3,g=s(-a/2,x),y=s(a/2,x);i.push(Re(g,y,c,Mf))}let u=vy/e,h=["tl","tr","br","bl"].map(b=>s(Bo(r,b).x,Bo(r,b).y));for(let b=0;b<4;b++)i.push(Re(h[b],h[(b+1)%4],u,Rf));let d=1.5/e,f=["tl","tr","br","bl"].map(b=>s(Kt[b].x*a,Kt[b].y*l));for(let b=0;b<4;b++)i.push(Re(f[b],f[(b+1)%4],d,Rf));if(this.circlesVisible){let b=wc(),[x,g,y,v]=Af(o),S=b.width/e;for(let w of Ty){let R=Bo(r,w);i.push({matrix:[x,g,y,v,o[0]*R.x+o[2]*R.y+o[4],o[1]*R.x+o[3]*R.y+o[5]],dims:{x:S,y:S},color:[1,1,1,1],texture:b})}}if(!this.ratio){let b={top:0,right:90,bottom:180,left:270},x=Ec();for(let g of Ey){let y=Kt[g];i.push(Go(o,y.x*a,y.y*l,b[g],Wo,Ho,e,x))}}let m={tl:0,tr:90,br:180,bl:270},p=Tc();for(let b of wy){let x=Kt[b];i.push(Go(o,x.x*a,x.y*l,m[b],{x:or,y:or},{x:ir,y:ir},e,p))}return i}dispose(){this.detachKey?.(),this.detachKey=null,this.node=null,this.shape=null}liveState(){let e=this.node;if(e instanceof ae)return vf(e.raw,e.clipImageRaw,e.clipImageEl);let t=e.imageEl;return gf(e.raw,t.naturalWidth,t.naturalHeight)}writeBack(e,t=!1){let r=this.node,o={...r instanceof ae?wf(e):yf(e)};r instanceof ae||(this.shape?o.clipPath=Sf(this.shape,e.width,e.height):t&&(o.clipPath=void 0)),this.host.document.setProps(r,o,{deferIndexRebuild:!0})}};var Nf={ml:{left:!0},mr:{right:!0},mt:{top:!0},mb:{bottom:!0},tl:{left:!0,top:!0},tr:{right:!0,top:!0},bl:{left:!0,bottom:!0},br:{right:!0,bottom:!0}},Lf=(n,e,t)=>{let r=n.expandScale??1.5;return{width:n.expandWidth??t.width*r,height:n.expandHeight??t.height*r,centerX:n.expandRectCenterX??e.x,centerY:n.expandRectCenterY??e.y}},If=(n,e,t,r,o)=>{let i=t*Math.PI/180,s=Math.cos(i),a=Math.sin(i),{centerX:l,centerY:c}=n,u=n.width/2,h=n.height/2,d=r.x-l,f=r.y-c,m=d*s+f*a,p=-d*a+f*s,b=-u,x=u,g=-h,y=h;o.left&&(b=Math.min(m,x-1)),o.right&&(x=Math.max(m,b+1)),o.top&&(g=Math.min(p,y-1)),o.bottom&&(y=Math.max(p,g+1));let v=o.right,S=o.left,w=o.bottom,R=o.top,P=e.centerX-l,E=e.centerY-c,C=P*s+E*a,T=-P*a+E*s,M=C-e.scaledWidth/2,k=C+e.scaledWidth/2,A=T-e.scaledHeight/2,O=T+e.scaledHeight/2;!v&&M<b&&(b=M),!S&&k>x&&(x=k),!w&&A<g&&(g=A),!R&&O>y&&(y=O);let F=(b+x)/2,H=(g+y)/2;return{width:x-b,height:y-g,centerX:l+F*s-H*a,centerY:c+F*a+H*s}},Cc=(n,e,t,r)=>{let o=t*Math.PI/180,i=Math.cos(o),s=Math.sin(o),a=r.width/e.scaledWidth,l=r.height/e.scaledHeight,c=e.centerX-n.centerX,u=e.centerY-n.centerY,h=c*i+u*s,d=-c*s+u*i,f=e.scaledWidth/2,m=e.scaledHeight/2,p=n.width/2,b=n.height/2,x=Math.max(0,h-f+p),g=Math.max(0,p-h-f),y=Math.max(0,d-m+b),v=Math.max(0,b-d-m);return{left:Math.floor(x*a),right:Math.floor(g*a),top:Math.floor(y*l),bottom:Math.floor(v*l)}},_f=(n,e,t,r)=>{let o=t*Math.PI/180,i=Math.cos(o),s=Math.sin(o),a=r.x-n.centerX,l=r.y-n.centerY,c=a*i+l*s,u=-a*s+l*i,h=Math.max(0,n.width/2-e.scaledWidth/2),d=Math.max(0,n.height/2-e.scaledHeight/2);return c=Math.max(-h,Math.min(h,c)),u=Math.max(-d,Math.min(d,u)),{x:n.centerX+c*i-u*s,y:n.centerY+c*s+u*i}},Rn={tl:{x:-.5,y:-.5},tr:{x:.5,y:-.5},bl:{x:-.5,y:.5},br:{x:.5,y:.5},ml:{x:-.5,y:0},mr:{x:.5,y:0},mt:{x:0,y:-.5},mb:{x:0,y:.5}},Cy={tl:{x:-1,y:-1},tr:{x:1,y:-1},bl:{x:-1,y:1},br:{x:1,y:1}},Df=(n,e,t,r)=>{let o=Cy[t],i=n.centerX-o.x*(n.scaledWidth/2),s=n.centerY-o.y*(n.scaledHeight/2),a=r.x-i,l=r.y-s,c=Math.hypot(n.scaledWidth,n.scaledHeight),u=c>0?Math.hypot(a,l)/c:1,h=Math.max(Math.abs(n.scaleX),Math.abs(n.scaleY));u=Math.max(.1/h,Math.min(5/h,u));let d=n.scaledWidth*u,f=n.scaledHeight*u,m=i+o.x*(d/2),p=s+o.y*(f/2),b=Math.min(i,i+o.x*d),x=Math.min(s,s+o.y*f),g=b+d,y=x+f;return b<e.centerX-e.width/2||x<e.centerY-e.height/2||g>e.centerX+e.width/2||y>e.centerY+e.height/2?null:{scaleX:n.scaleX*u,scaleY:n.scaleY*u,centerX:m,centerY:p}};var Xo=n=>n*Math.PI/180,My=12,Ry=14,Py=1,ky=(()=>{let n=oe("#3788ff");return[n[0],n[1],n[2],.5]})(),Ay=oe("#3788ff"),Mc=["tl","tr","bl","br"],Ny={tl:0,tr:90,br:180,bl:270},Ly={mt:0,mr:90,mb:180,ml:270},Iy=(n,e)=>{let t=!1;for(let r=0,o=e.length-1;r<e.length;o=r++){let i=e[r].x,s=e[r].y,a=e[o].x,l=e[o].y;s>n.y!=l>n.y&&n.x<(a-i)*(n.y-s)/(l-s)+i&&(t=!t)}return t},Os=class{constructor(e){this.host=e}host;node=null;detachKey=null;get active(){return this.node!==null}get target(){return this.node}get info(){let e=this.node;if(!e)return null;let t=this.view();return{nodeId:e.id,width:t.rect.width,height:t.rect.height,centerX:t.rect.centerX,centerY:t.rect.centerY,angle:t.angle,offsets:t.offsets}}enter(e){if(this.node&&this.exit(),!(e instanceof ie?!1:(e.isImageType||e instanceof ae)&&!!e.imageEl&&!(e instanceof ae&&e.clipDynamicKind)))return!1;this.node=e,this.host.document.exitEditing(),this.host.document.setSelection([e],"update");let r=e.raw,o=Math.abs(r.scaleX??1),i=Math.abs(r.scaleY??1),s=r.expandScale??1.5,a=e.center,l={};r.expandRectCenterX===void 0&&(l.expandRectCenterX=a.x),r.expandRectCenterY===void 0&&(l.expandRectCenterY=a.y),r.expandWidth===void 0&&(l.expandWidth=e.dims.x*o*s),r.expandHeight===void 0&&(l.expandHeight=e.dims.y*i*s),Object.keys(l).length>0&&this.host.document.setProps(e,l);let c=u=>{u.key==="Escape"&&this.node&&this.exit()};return window.addEventListener("keydown",c),this.detachKey=()=>window.removeEventListener("keydown",c),this.host.requestRenderAll(),!0}exit(){let e=this.node;if(!e)return;this.node=null,this.detachKey?.(),this.detachKey=null;let t=e.imageEl;if(t){let r=this.expandViewOf(e,t),o=Cc(r.rect,r.img,r.angle,{width:t.naturalWidth,height:t.naturalHeight});this.host.document.setProps(e,{expandLeftOffset:o.left,expandRightOffset:o.right,expandTopOffset:o.top,expandBottomOffset:o.bottom})}this.host.document.applyTransform([e],()=>({}),"modified",{action:Ne.crop}),this.host.requestRenderAll()}exitByOutsideClick(){let e=this.node;this.exit(),e&&this.host.document.selection.includes(e)&&this.host.document.clearSelection()}async applyResult(e,t,r){this.host.document.setProps(e,{src:t});let o=await this.host.reloadImageElement(e);if(!o||!o.naturalWidth||!o.naturalHeight)return!1;let i=r.width/o.naturalWidth,s=r.height/o.naturalHeight,a=xe({...e.raw,width:o.naturalWidth,height:o.naturalHeight,scaleX:i,scaleY:s},{x:r.centerX,y:r.centerY});return this.host.document.setProps(e,{width:o.naturalWidth,height:o.naturalHeight,scaleX:i,scaleY:s,left:a.x,top:a.y}),this.host.document.applyTransform([e],()=>({}),"modified"),this.host.requestRenderAll(),!0}hitHandle(e,t){let r=this.view(),o=Xo(r.angle),i=Math.cos(o),s=Math.sin(o);for(let a of Object.keys(Rn)){let l=Rn[a],c=l.x*r.rect.width,u=l.y*r.rect.height,h=r.rect.centerX+c*i-u*s,d=r.rect.centerY+c*s+u*i,f=this.host.toScreen(h,d);if(Math.hypot(f.x-e,f.y-t)<=My)return a}for(let a of Mc){let l=this.imageCornerOf(a),c=this.host.toScreen(l.x,l.y);if(Math.hypot(c.x-e,c.y-t)<=Ry)return`${a}S`}return null}hitRect(e,t){let r=this.view(),o=Xo(r.angle),i=Math.cos(o),s=Math.sin(o),a=["tl","tr","br","bl"].map(l=>{let c=Rn[l],u=c.x*r.rect.width,h=c.y*r.rect.height;return{x:r.rect.centerX+u*i-h*s,y:r.rect.centerY+u*s+h*i}});return Iy({x:e,y:t},a)}applyHandle(e,t){let r=this.node;if(!r)return;if(e.endsWith("S")){let s=this.view(),a=r.raw,l=Df({...s.img,scaleX:a.scaleX??1,scaleY:a.scaleY??1},s.rect,e.slice(0,2),t);if(l){let c=xe({...r.raw,width:r.dims.x,height:r.dims.y,scaleX:l.scaleX,scaleY:l.scaleY},{x:l.centerX,y:l.centerY});this.host.document.setProps(r,{scaleX:l.scaleX,scaleY:l.scaleY,left:c.x,top:c.y},{deferIndexRebuild:!0})}this.host.requestRenderAll();return}let o=this.view(),i=If(o.rect,o.img,o.angle,t,Nf[e]);this.host.document.setProps(r,{expandWidth:i.width,expandHeight:i.height,expandRectCenterX:i.centerX,expandRectCenterY:i.centerY},{deferIndexRebuild:!0}),this.host.requestRenderAll()}moveImageBy(e){let t=this.node;if(!t)return;let r=this.view(),o=_f(r.rect,r.img,r.angle,{x:r.img.centerX+e.x,y:r.img.centerY+e.y}),i=xe({...t.raw,width:t.dims.x,height:t.dims.y},o);this.host.document.setProps(t,{left:i.x,top:i.y},{deferIndexRebuild:!0}),this.host.requestRenderAll()}hoverCursor(e,t,r,o){let i=this.hitHandle(e,t);if(i){if(i.endsWith("S")&&this.node){let s=Rn[i.slice(0,2)],l=((this.node.raw.angle??0)+Math.atan2(s.y,s.x)*180/Math.PI+360)%360;return`${vc[Math.round(l/45)]}-resize`}return"pointer"}return this.hitRect(r,o)?"move":""}buildUnderlay(){let e=this.view(),t=Xo(e.angle);return[{matrix:[Math.cos(t),Math.sin(t),-Math.sin(t),Math.cos(t),e.rect.centerX,e.rect.centerY],dims:{x:e.rect.width,y:e.rect.height},color:ky}]}buildOverlay(e){let t=this.view(),r=[],o=Xo(t.angle),i=[Math.cos(o),Math.sin(o),-Math.sin(o),Math.cos(o),t.rect.centerX,t.rect.centerY],s=p=>{let b=Rn[p];return Q(i,b.x*t.rect.width,b.y*t.rect.height)},a=Py/e,l=["tl","tr","br","bl"].map(s);for(let p=0;p<4;p++)r.push(Re(l[p],l[(p+1)%4],a,Ay));let c=wc(),u=c.width/e,h=Math.cos(o),d=Math.sin(o);for(let p of Mc){let b=this.imageCornerOf(p);r.push({matrix:[h,d,-d,h,b.x,b.y],dims:{x:u,y:u},color:[1,1,1,1],texture:c})}let f=Ec();for(let p of["ml","mr","mt","mb"]){let b=Rn[p];r.push(Go(i,b.x*t.rect.width,b.y*t.rect.height,Ly[p],Wo,Ho,e,f))}let m=Tc();for(let p of Mc){let b=Rn[p];r.push(Go(i,b.x*t.rect.width,b.y*t.rect.height,Ny[p],{x:or,y:or},{x:ir,y:ir},e,m))}return r}dispose(){this.detachKey?.(),this.detachKey=null,this.node=null}view(){let e=this.node;return this.expandViewOf(e,e.imageEl)}imageCornerOf(e){let t=this.view(),r=Xo(t.angle),o=Math.cos(r),i=Math.sin(r),s=(e==="tr"||e==="br"?.5:-.5)*t.img.scaledWidth,a=(e==="bl"||e==="br"?.5:-.5)*t.img.scaledHeight;return{x:t.img.centerX+s*o-a*i,y:t.img.centerY+s*i+a*o}}expandViewOf(e,t){let r=e.raw,o=Math.abs(r.scaleX??1),i=Math.abs(r.scaleY??1),s=e.center,a=e.dims.x*o,l=e.dims.y*i,c={centerX:s.x,centerY:s.y,scaledWidth:a,scaledHeight:l},u=Lf(r,s,{width:a,height:l}),h=r.angle??0,d=t?Cc(u,c,h,{width:t.naturalWidth,height:t.naturalHeight}):null;return{rect:u,img:c,angle:h,offsets:d}}};var _y=8,Dy=6;var ar=n=>{if(!n)return null;let e=Fe(n);return e?{x:(e.left+e.right)/2,y:(e.top+e.bottom)/2}:null},Ff=(n,e)=>{let t=n[e],r=String(t[0]).toUpperCase();if(r==="M"||r==="L")return{x:t[1],y:t[2]};if(r==="C")return{x:t[5],y:t[6]};if(r==="Q")return{x:t[3],y:t[4]};for(let o=e;o>=0;o--)if(String(n[o][0]).toUpperCase()==="M")return{x:n[o][1],y:n[o][2]};return{x:0,y:0}},sr=(n,e)=>{for(let t=e-1;t>=0;t--){let r=String(n[t][0]).toUpperCase();if(r==="M"||r==="L")return{x:n[t][1],y:n[t][2]};if(r==="C")return{x:n[t][5],y:n[t][6]};if(r==="Q")return{x:n[t][3],y:n[t][4]};if(r==="Z"){for(let o=t;o>=0;o--)if(String(n[o][0]).toUpperCase()==="M")return{x:n[o][1],y:n[o][2]}}}return{x:0,y:0}},Fy=n=>n==="C"?5:n==="Q"?3:1,ut=(n,e,t)=>({x:n[e]-t.x,y:n[e+1]-t.y}),Rc=(n,e)=>{let t=[],r=[];return n.forEach((o,i)=>{let s=String(o[0]);if(s!=="Z"&&t.push({key:`c_${i}_${s}`,kind:"anchor",commandIndex:i,pointIndex:o.length-2,local:ut(o,o.length-2,e)}),s==="C"){let a=ut(o,1,e),l=ut(o,3,e);t.push({key:`c_${i}_C_CP_1`,kind:"handle",commandIndex:i,pointIndex:1,local:a}),t.push({key:`c_${i}_C_CP_2`,kind:"handle",commandIndex:i,pointIndex:3,local:l});let c=i>0?String(n[i-1][0]).toUpperCase():"M",u=i>0?ut(n[i-1],Fy(c),e):a;r.push({from:a,to:u},{from:l,to:ut(o,5,e)})}else if(s==="Q"){let a=ut(o,1,e);t.push({key:`c_${i}_Q_CP_1`,kind:"handle",commandIndex:i,pointIndex:1,local:a}),r.push({from:a,to:ut(o,3,e)})}}),{handles:t,connections:r}},Wf=(n,e)=>n.map((t,r)=>({key:`p_${r}`,kind:"point",commandIndex:r,pointIndex:r,local:{x:t.x-e.x,y:t.y-e.y}})),Bs=n=>{if(!n.length)return null;let e=1/0,t=1/0,r=-1/0,o=-1/0;for(let i of n)e>i.x&&(e=i.x),t>i.y&&(t=i.y),r<i.x&&(r=i.x),o<i.y&&(o=i.y);return{x:(e+r)/2,y:(t+o)/2}},Oy=(n,e,t)=>{let r=t.x-e.x,o=t.y-e.y,i=r*r+o*o;if(!i)return{distance:Math.hypot(n.x-e.x,n.y-e.y),t:0,point:{...e},length:0};let s=Math.max(0,Math.min(1,((n.x-e.x)*r+(n.y-e.y)*o)/i)),a={x:e.x+r*s,y:e.y+o*s};return{distance:Math.hypot(n.x-a.x,n.y-a.y),t:s,point:a,length:Math.sqrt(i)}},By=(n,e,t=100)=>{let r=1/t,o=0,i=Number.POSITIVE_INFINITY,s=0,a=null;for(let h=0;h<=t;h++){let d=h*r,f=e(d);a&&(s+=Math.hypot(f.x-a.x,f.y-a.y)),a=f;let m=(f.x-n.x)**2+(f.y-n.y)**2;m<i&&(i=m,o=d)}let l=Math.max(0,o-r),c=Math.min(1,o+r),u=(c-l)/20;for(let h=l;h<=c;h+=u){let d=e(h),f=(d.x-n.x)**2+(d.y-n.y)**2;f<i&&(i=f,o=h)}return{distance:Math.sqrt(i),t:o,point:e(o),length:s}},Of=(n,e,t,r,o)=>{let i=1-o,s=i*i*i,a=3*i*i*o,l=3*i*o*o,c=o*o*o;return{x:s*n.x+a*e.x+l*t.x+c*r.x,y:s*n.y+a*e.y+l*t.y+c*r.y}},Bf=(n,e,t,r)=>{let o=1-r,i=o*o,s=2*o*r,a=r*r;return{x:i*n.x+s*e.x+a*t.x,y:i*n.y+s*e.y+a*t.y}},Wy=(n,e,t)=>({x:n.x+(e.x-n.x)*t,y:n.y+(e.y-n.y)*t}),Hf=(n,e,t,r,o)=>{let i=_y/o,s=Dy/o,a=h=>Q(r,h.x,h.y),l=(h,d)=>a(ut(h,d,e)),c,u=Number.POSITIVE_INFINITY;return n.forEach((h,d)=>{let f=String(h[0]).toUpperCase();if(f==="C"||f==="Q"){let w={x:sr(n,d).x-e.x,y:sr(n,d).y-e.y},R=a(w),P=l(h,1),E=f==="C"?ut(h,5,e):ut(h,3,e),C=a(E),M=By(t,f==="C"?F=>Of(R,P,l(h,3),C,F):F=>Bf(R,P,C,F));if(M.distance>i||M.length<=s*2||M.distance>=u)return;let k=s/M.length;if(M.t<=k||M.t>=1-k)return;let A=sr(n,d),O=f==="C"?(()=>{let F={x:A.x-e.x,y:A.y-e.y},H=ut(h,1,e),z=ut(h,3,e),_={x:h[5]-e.x,y:h[6]-e.y};return Of(F,H,z,_,M.t)})():(()=>{let F={x:A.x-e.x,y:A.y-e.y},H=ut(h,1,e),z={x:h[3]-e.x,y:h[4]-e.y};return Bf(F,H,z,M.t)})();u=M.distance,c={commandIndex:d,commandType:f,t:M.t,local:O,scene:M.point};return}if(f!=="L"&&f!=="Z")return;let m=f==="L"?sr(n,d):Ff(n,Math.max(0,d-1)),p=Ff(n,d),b=a({x:m.x-e.x,y:m.y-e.y}),x=a({x:p.x-e.x,y:p.y-e.y}),g=Oy(t,b,x);if(g.distance>i||g.length<=s*2||g.distance>=u)return;let y=s/g.length;if(g.t<=y||g.t>=1-y)return;u=g.distance;let v={x:m.x-e.x,y:m.y-e.y},S={x:p.x-e.x,y:p.y-e.y};c={commandIndex:d,commandType:f,t:g.t,local:Wy(v,S,g.t),scene:g.point}}),c},Gf=(n,e,t,r,o)=>n.map((i,s)=>{if(s!==e)return i;let a=[...i];return a[t]=r.x+o.x,a[t+1]=r.y+o.y,a}),Xf=(n,e,t,r)=>n.map((o,i)=>i===e?{x:t.x+r.x,y:t.y+r.y}:o),zf=(n,e,t)=>{let r=n.map(a=>[...a]),o=t.local.x+e.x,i=t.local.y+e.y,s=t.commandIndex;if(t.commandType==="L"){let a=r[s],l=a[1],c=a[2];return r[s]=["L",o,i],r.splice(s+1,0,["L",l,c]),r}if(t.commandType==="C"){let a=r[s],l=sr(n,s),c=t.t,u=a[1],h=a[2],d=a[3],f=a[4],m=a[5],p=a[6],b=l.x+(u-l.x)*c,x=l.y+(h-l.y)*c,g=u+(d-u)*c,y=h+(f-h)*c,v=d+(m-d)*c,S=f+(p-f)*c,w=b+(g-b)*c,R=x+(y-x)*c,P=g+(v-g)*c,E=y+(S-y)*c;return r[s]=["C",b,x,w,R,o,i],r.splice(s+1,0,["C",P,E,v,S,m,p]),r}if(t.commandType==="Q"){let a=r[s],l=sr(n,s),c=t.t,u=a[1],h=a[2],d=a[3],f=a[4],m=l.x+(u-l.x)*c,p=l.y+(h-l.y)*c,b=u+(d-u)*c,x=h+(f-h)*c;return r[s]=["Q",m,p,o,i],r.splice(s+1,0,["Q",b,x,d,f]),r}return t.commandType==="Z"?(r.splice(s,1,["L",o,i],["Z"]),r):null},Yf=(n,e,t)=>{if(e<0||e>=n.length)return null;let r=n[e],o=String(r[0]).toUpperCase();if(o==="M"||o==="Z")return null;let i=o==="C"||o==="Q",s=t.toUpperCase()==="C";if(i===s)return{commands:n,changed:!1};let a,l;o==="L"?(a=r[1],l=r[2]):o==="C"?(a=r[5],l=r[6]):(a=r[3],l=r[4]);let c=sr(n,e),u=n.map(h=>[...h]);return u[e]=s?["C",c.x+(a-c.x)/3,c.y+(l-c.y)/3,a-(a-c.x)/3,l-(l-c.y)/3,a,l]:["L",a,l],{commands:u,changed:!0}},Pc=(n,e)=>{let t=n?.[e]?.[0];return t&&["C","Q","S","T","A"].includes(String(t).toUpperCase())?"smooth":"line"},Uf=(n,e,t,r)=>{if(!t)return n;let o=t.x-e.x,i=t.y-e.y;return{x:n.x+r[0]*o+r[2]*i,y:n.y+r[1]*o+r[3]*i}};var Hy=12,zo=oe("#2254f4"),$f=oe("#ffffff"),jf=7,Vf=5,Gy=1,kc=null,Xy=()=>{if(kc)return kc;let n=Math.ceil((Vf+2)*2),e=document.createElement("canvas");e.width=n,e.height=n;let t=e.getContext("2d");return t.beginPath(),t.arc(n/2,n/2,Vf,0,Math.PI*2),t.fillStyle="#ffffff",t.fill(),t.lineWidth=1.5,t.strokeStyle="#2254f4",t.stroke(),kc=e,e},Dt=n=>{let e=n.typeKey;return e===L.PATH?"path":e===L.POLYGON||e===L.POLYLINE?"poly":e===L.LINE?"line":null},Ws=class{constructor(e){this.host=e}host;node=null;kind=null;activeAnchorKey;insertCandidate;detachKey=null;get active(){return this.node!==null}get target(){return this.node}get info(){let e=this.node,t=this.kind;if(!e||!t)return null;let r=e.matrix,o=this.currentHandles().map(i=>{let s=Q(r,i.local.x,i.local.y);return{key:i.key,kind:i.kind,x:s.x,y:s.y}});return{nodeId:e.id,kind:t,anchors:o,activeAnchorKey:this.activeAnchorKey,activeAnchorIndex:this.activeAnchorIndex(),insertCandidate:this.insertCandidate?{commandIndex:this.insertCandidate.commandIndex,commandType:this.insertCandidate.commandType,x:this.insertCandidate.scene.x,y:this.insertCandidate.scene.y}:void 0}}enter(e){this.node&&this.exit();let t=Dt(e);if(!t||t==="path"&&!Ce(e.raw.path)||t==="poly"&&!Array.isArray(e.raw.points)||t==="line"&&!(e instanceof kr))return!1;this.node=e,this.kind=t,this.activeAnchorKey=void 0,this.insertCandidate=void 0,this.host.document.exitEditing(),this.host.document.setSelection([e],"update");let r=o=>{o.key==="Escape"&&this.node&&this.exit()};return window.addEventListener("keydown",r),this.detachKey=()=>window.removeEventListener("keydown",r),this.host.requestRenderAll(),!0}exit(){this.node&&(this.node=null,this.kind=null,this.activeAnchorKey=void 0,this.insertCandidate=void 0,this.detachKey?.(),this.detachKey=null,this.host.requestRenderAll())}exitByOutsideClick(){this.exit()}hitAnchor(e,t){let r=this.node;if(!r)return null;let o=r.matrix,i=null,s=Hy;for(let a of this.currentHandles()){let l=Q(o,a.local.x,a.local.y),c=this.host.toScreen(l.x,l.y),u=Math.hypot(c.x-e,c.y-t);u<=s&&(s=u,i=a.key)}return i}hitBody(e,t){let r=this.node;return r?r.containsPoint(e,t):!1}findInsertCandidate(e,t){let r=this.node;if(!r||this.kind!=="path")return null;let o=Ce(r.raw.path),i=ar(o);return!o||!i?null:Hf(o,i,{x:e,y:t},r.matrix,this.host.zoom)??null}startAnchorDrag(e){return!this.node||!this.currentHandles().some(r=>r.key===e)?!1:(this.captureDragBefore(),this.setActiveAnchor(e),!0)}applyAnchorDrag(e,t){let r=this.node,o=this.kind;if(!r||!o)return;let i=this.currentHandles().find(l=>l.key===e);if(!i)return;let s=r.matrix,a=Q(ve(s),t.x,t.y);if(o==="path"){let l=Ce(r.raw.path),c=ar(l);if(!l||!c)return;let u=Gf(l,i.commandIndex,i.pointIndex,a,c);this.writeBackWithCompensation(r,u,c,ar(u),Fe(u))}else if(o==="poly"){let l=r.raw.points,c=Bs(l);if(!c)return;let u=Xf(l,i.commandIndex,a,c),h=1/0,d=1/0,f=-1/0,m=-1/0;for(let p of u)h>p.x&&(h=p.x),d>p.y&&(d=p.y),f<p.x&&(f=p.x),m<p.y&&(m=p.y);this.writeBackWithCompensation(r,u,c,Bs(u),{left:h,top:d,right:f,bottom:m})}else{let l=i.commandIndex===0?{x1:a.x,y1:a.y}:{x2:a.x,y2:a.y},c=Number(l.x1??r.raw.x1),u=Number(l.y1??r.raw.y1),h=Number(l.x2??r.raw.x2),d=Number(l.y2??r.raw.y2),f=xe({...r.raw,width:Math.abs(h-c),height:Math.abs(d-u)},r.center);this.host.document.setProps(r,{...l,left:f.x,top:f.y},{deferIndexRebuild:!0})}this.host.requestRenderAll()}moveBodyBy(e){let t=this.node;t&&(this.captureDragBefore(),this.host.document.setProps(t,{left:(t.raw.left??0)+e.x,top:(t.raw.top??0)+e.y},{deferIndexRebuild:!0}),this.host.requestRenderAll())}captureDragBefore(){this._dragBefore??=this.node?this.node.toObject():null}_dragBefore=null;commit(){let e=this.node;if(!e)return;let t=this._dragBefore;this._dragBefore=null,this.host.document.applyTransform([e],()=>({}),"modified",t?{before:new Map([[e,t]])}:void 0)}insertAnchor(e){let t=this.node;if(!t||this.kind!=="path")return null;let r=Ce(t.raw.path),o=ar(r);if(!r||!o)return null;let i=zf(r,o,e);if(!i)return null;let s=t.toObject();this.host.document.setProps(t,{path:i},{deferIndexRebuild:!0}),this.host.document.applyTransform([t],()=>({}),"modified",{before:new Map([[t,s]])});let a=e.commandType==="Z"?"L":e.commandType,l=`c_${e.commandIndex}_${a}`;return this.insertCandidate=void 0,this.setActiveAnchor(l),this.host.requestRenderAll(),l}setAnchorType(e,t){let r=this.node;if(!r||this.kind!=="path")return!1;let o=Ce(r.raw.path);if(!o)return!1;let i=Yf(o,e,t);if(!i)return!1;if(i.changed){let s=r.toObject();this.host.document.setProps(r,{path:i.commands},{deferIndexRebuild:!0}),this.host.document.applyTransform([r],()=>({}),"modified",{before:new Map([[r,s]])})}return this.setActiveAnchor(`c_${e}_${String(i.commands[e][0])}`),this.host.requestRenderAll(),i.changed}setActiveAnchor(e){if(this.activeAnchorKey===e)return;this.activeAnchorKey=e;let t=this.node;t&&this.host.document.events.fire("path:active-anchor-change",t,e),this.host.requestRenderAll()}resetAnchorStyles(){this.activeAnchorKey!==void 0&&(this.activeAnchorKey=void 0,this.host.requestRenderAll())}activeAnchorIndex(){let e=this.activeAnchorKey;if(e){if(e.startsWith("c_")){let t=e.match(/^c_(\d+)_/),r=t?Number(t[1]):NaN;return Number.isFinite(r)?r:void 0}if(e.startsWith("p_"))return Number(e.slice(2));if(e==="e0"||e==="e1")return Number(e[1])}}hoverCursor(e,t,r){let o=this.hitAnchor(e,t);if(o)return o.includes("_CP_")?"crosshair":"default";let i=this.findInsertCandidate(r.x,r.y);return i?(this.updateInsertCandidate(i),"copy"):(this.updateInsertCandidate(void 0),this.hitBody(r.x,r.y)?"move":"")}updateInsertCandidate(e){let t=this.insertCandidate;t&&e&&t.commandIndex===e.commandIndex&&t.commandType===e.commandType&&Math.abs(t.scene.x-e.scene.x)<.1&&Math.abs(t.scene.y-e.scene.y)<.1||!t&&!e||(this.insertCandidate=e,this.host.requestRenderAll())}buildOverlay(e){let t=this.node,r=this.kind;if(!t||!r)return[];let o=t.matrix,i=[...Cn(t.aCoords,e)],s=a=>Q(o,a.x,a.y);if(r==="path"){let a=Ce(t.raw.path),l=ar(a);if(!a||!l)return i;let{handles:c,connections:u}=Rc(a,l),h=Gy/e;for(let p of u)i.push(Re(s(p.from),s(p.to),h,zo));let d=jf/e,f=Xy(),m=f.width/2*2*(1/e);for(let p of c){let b=s(p.local);if(p.kind==="handle")i.push({matrix:[1,0,0,1,b.x,b.y],dims:{x:m,y:m},color:[1,1,1,1],texture:f});else{let x=p.key===this.activeAnchorKey;i.push({matrix:[1,0,0,1,b.x,b.y],dims:{x:d,y:d},color:zo}),i.push({matrix:[1,0,0,1,b.x,b.y],dims:{x:d-2/e,y:d-2/e},color:x?zo:$f})}}this.insertCandidate&&i.push({matrix:[1,0,0,1,this.insertCandidate.scene.x,this.insertCandidate.scene.y],dims:{x:m,y:m},color:[1,1,1,1],texture:f})}else{let a=jf/e;for(let l of this.currentHandles()){let c=s(l.local),u=l.key===this.activeAnchorKey;i.push({matrix:[1,0,0,1,c.x,c.y],dims:{x:a,y:a},color:zo}),i.push({matrix:[1,0,0,1,c.x,c.y],dims:{x:a-2/e,y:a-2/e},color:u?zo:$f})}}return i}dispose(){this.detachKey?.(),this.detachKey=null,this.node=null,this.kind=null}currentHandles(){let e=this.node,t=this.kind;if(!e||!t)return[];if(t==="path"){let a=Ce(e.raw.path),l=ar(a);return!a||!l?[]:Rc(a,l).handles}if(t==="poly"){let a=e.raw.points,l=Bs(a);return!Array.isArray(a)||!l?[]:Wf(a,l)}let r=Number(e.raw.x1),o=Number(e.raw.y1),i=Number(e.raw.x2),s=Number(e.raw.y2);return[r,o,i,s].every(Number.isFinite)?[{key:"e0",kind:"endpoint",commandIndex:0,pointIndex:0,local:{x:r,y:o}},{key:"e1",kind:"endpoint",commandIndex:1,pointIndex:1,local:{x:i,y:s}}]:[]}writeBackWithCompensation(e,t,r,o,i){if(!i)return;let s=e.ownMatrix,a=Uf(e.center,r,o,[s[0],s[1],s[2],s[3]]),l=xe({...e.raw,width:i.right-i.left,height:i.bottom-i.top},a),c=this.kind==="path"?{path:t}:{points:t};this.host.document.setProps(e,{...c,left:l.x,top:l.y},{deferIndexRebuild:!0})}};import{Warpvas as zy}from"warpvas";var qf=12,Yy=5,Uy=4,$y=1,Kf=3,Qf=2e3,Zf=10,jy=[.2,.2,.2,.6],Vy=[.11,.35,.96,1],qy=[1,1,1,.9],Hs=class{host;warp=null;node=null;beforeRaw=null;originalSrc=null;undoStack=[];redoStack=[];previewCanvas=null;previewVersion=0;renderedVersion=-1;coreSize={w:0,h:0};displayScale={x:1,y:1};coreAnchor={x:0,y:0};renderCanvas=null;constructor(e){this.host=e}get document(){return this.host.document}get zoom(){return this.host.zoom}get textures(){return this.host.textures}toScreen(e,t){return this.host.toScreen(e,t)}requestRenderAll(){this.host.requestRenderAll()}reloadNodeImage(e){return this.host.reloadNodeImage(e)}get active(){return!!this.warp}get target(){return this.node}get debugAnchors(){if(!this.warp||!this.node)return[];let e=[],t=this.currentBounds();for(let r=0;r<t.length;r++)for(let o=0;o<t[r].length;o++){let i=t[r][o];for(let s of Ac){let a=i[s];a&&a.forEach((l,c)=>{let u=this.toScene(l);e.push({row:r,col:o,dir:s,i:c,srcX:Math.round(l.x),srcY:Math.round(l.y),sceneX:Math.round(u.x),sceneY:Math.round(u.y)})})}}return e}get debugPreviewInfo(){if(!this.previewCanvas)return null;let e=this.previewCanvas;e.__probeId===void 0&&(e.__probeId=Math.random());let t=this.warp?this.warp.getBoundingBoxInfo():null;return{canvasId:e.__probeId,width:e.width,height:e.height,version:this.previewVersion,box:t,dataURL:e.width*e.height<=4e5?e.toDataURL("image/png"):void 0}}get debugBoundsSample(){return!this.warp||!this.coreSize.w?null:{region:this.currentBounds()[0]?.[0]??null,natural:{w:this.coreSize.w,h:this.coreSize.h}}}async enter(e,t){if(this.warp&&this.cancel(),!e.imageEl||e.cropRect||e instanceof ie||!e.imageEl.naturalWidth||!e.imageEl.naturalHeight)return!1;let r=e.raw;this.originalSrc=r.warpOriginalSrc??r.src??null;let o=e.imageEl,i=r.warpOriginalSrc,s=o,a=!1;if(i)try{let f=await this.host.loadImage(i,r.crossOrigin??void 0);f?.naturalWidth&&(s=f,a=!0)}catch{}let l=new zy(s,t?.gridRows??Kf,t?.gridCols??Kf);l.setInputLimitSize({width:Qf,height:Qf}),this.renderCanvas=document.createElement("canvas"),l.setRenderingCanvas(this.renderCanvas);let c=s===o?o:s;this.coreSize={w:c.naturalWidth*l.scale.x,h:c.naturalHeight*l.scale.y};let u=r.warpDisplayScale,h=r.warpCoreAnchor;a&&u&&typeof u.x=="number"&&h&&typeof h.x=="number"?(this.displayScale={x:u.x,y:u.y??u.x},this.coreAnchor={x:h.x,y:h.y??h.x}):(this.displayScale={x:e.dims.x/this.coreSize.w,y:e.dims.y/this.coreSize.h},this.coreAnchor={x:this.coreSize.w/2,y:this.coreSize.h/2});let d=a?r.warpvasState:void 0;if(d&&Array.isArray(d.splitPoints))try{l.setWarpState(d.splitPoints,d.regionBounds??null)}catch{}return this.node=e,this.warp=l,this.beforeRaw=e.toObject(),this.undoStack=[this.snapshot()],this.redoStack=[],this.fireHistory(),this.refreshPreview(),this.requestRenderAll(),!0}hitAnchor(e,t){let r=this.hitAnchorsOfKind(e,t,"vertex");return r||this.hitAnchorsOfKind(e,t,"curve")}hitAnchorsOfKind(e,t,r){let o=this.currentBounds(),i=null;for(let s=0;s<o.length;s++)for(let a=0;a<o[s].length;a++){let l=o[s][a];if(r==="vertex")for(let c of Jf){let u=em(l,c);if(!u)continue;let h=this.screenDist(u,e,t);h<=qf&&(!i||h<i.dist)&&(i={anchor:{kind:"vertex",row:s,col:a,pos:c},dist:h})}else for(let c of Ac){let u=l[c];if(!(!u||u.length<4))for(let h of[0,1]){let d=this.screenDist(u[h+1],e,t);d<=qf&&(!i||d<i.dist)&&(i={anchor:{kind:"curve",row:s,col:a,dir:c,index:h},dist:d})}}}return i?.anchor??null}applyAnchorDrag(e,t){let r=this.warp;if(!r)return;let o=this.toSource(t);if(e.kind==="vertex")r.updateVertexCoord(e.row,e.col,e.pos,o);else{let i=this.currentBounds()[e.row]?.[e.col]?.[e.dir];if(!i||i.length<4)return;let s=i.map(a=>({...a}));s[e.index+1]=o,r.updateRegionBoundCoords(e.row,e.col,e.dir,[s[0],s[1],s[2],s[3]])}this.refreshPreview(),this.requestRenderAll()}endDrag(){this.warp&&(this.undoStack.push(this.snapshot()),this.redoStack=[],this.fireHistory())}undo(){return!this.warp||this.undoStack.length<=1?!1:(this.redoStack.push(this.undoStack.pop()),this.restore(this.undoStack[this.undoStack.length-1]),this.afterHistoryStep(),!0)}redo(){if(!this.warp)return!1;let e=this.redoStack.pop();return e?(this.undoStack.push(e),this.restore(e),this.afterHistoryStep(),!0):!1}afterHistoryStep(){this.fireHistory(),this.refreshPreview(),this.requestRenderAll()}get undoable(){return this.undoStack.length>1}get redoable(){return this.redoStack.length>0}getWarpState(){return this.warp?this.snapshot():null}buildOverlay(){if(!this.warp||!this.node)return[];let e=this.zoom,t=[];if(this.previewCanvas){this.renderedVersion!==this.previewVersion&&(this.textures.update(this.previewCanvas),this.renderedVersion=this.previewVersion);let s=this.localFromSourceBox(this.warp.getBoundingBoxInfo());t.push({matrix:this.quadMatrix(s.cx,s.cy),dims:{x:s.w,y:s.h},color:[1,1,1,1],texture:this.previewCanvas})}let r=this.currentBounds(),o=new Set,i=new Set;for(let s of r)for(let a of s){for(let l of Ac){let c=a[l];if(!c||c.length<4)continue;let u=this.toScene(c[0]);for(let h=1;h<=Zf;h++){let d=this.toScene(Ky(c[0],c[1],c[2],c[3],h/Zf));t.push(Re(u,d,$y/e,jy)),u=d}for(let h of[0,1]){let d=c[h+1],f=`${Math.round(d.x)},${Math.round(d.y)}`;i.has(f)||(i.add(f),t.push(tm(this.toScene(d),Uy,qy,e)))}}for(let l of Jf){let c=em(a,l);if(!c)continue;let u=`${Math.round(c.x)},${Math.round(c.y)}`;o.has(u)||(o.add(u),t.push(tm(this.toScene(c),Yy,Vy,e)))}}return t}hoverCursor(e,t){return this.hitAnchor(e,t)?"pointer":"default"}async exit(e){let t=this.warp,r=this.node;if(!t||!r)return null;let o=this.beforeRaw,i=null;if(e&&!t.isUnwarped()){let a=t.render().toDataURL("image/png"),l=t.getBoundingBoxInfo(),c=t.getWarpState(),u=this.localFromSourceBox(l),h=this.sourceToDisplayScale(),d=Math.max(1,Math.round(l.width*h.x)),f=Math.max(1,Math.round(l.height*h.y)),m=r.matrix,p={x:r.center.x+m[0]*u.cx+m[2]*u.cy,y:r.center.y+m[1]*u.cx+m[3]*u.cy},b=xe({...r.raw,width:d,height:f},p),x={x:l.width/2-l.offsetX,y:l.height/2-l.offsetY};i={dataURL:a,state:c,nextWidth:d,nextHeight:f,left:b.x,top:b.y,originalSrc:this.originalSrc,displayScale:{x:this.displayScale.x,y:this.displayScale.y},coreAnchor:x}}this.teardown(t);let s=!1;return i&&(r.set({src:i.dataURL,width:i.nextWidth,height:i.nextHeight,left:i.left,top:i.top,warpvasState:i.state,warpOriginalSrc:i.originalSrc??void 0,warpDisplayScale:i.displayScale,warpCoreAnchor:i.coreAnchor}),await this.reloadNodeImage(r.id),this.host.document.applyTransform([r],()=>({}),"modified",{action:Ne.warpImage,before:new Map([[r,o]])}),s=!0),this.requestRenderAll(),{committed:s,node:r,before:o,after:r.toObject()}}async cancel(){await this.exit(!1)}teardown(e=this.warp){this.previewCanvas&&this.textures.remove(this.previewCanvas),e?.dispose?.(),this.warp=null,this.node=null,this.beforeRaw=null,this.originalSrc=null,this.undoStack=[],this.redoStack=[],this.previewCanvas=null,this.previewVersion=0,this.renderedVersion=-1,this.coreSize={w:0,h:0},this.displayScale={x:1,y:1},this.coreAnchor={x:0,y:0},this.renderCanvas=null}snapshot(){return this.warp.getWarpState()}restore(e){this.warp.setWarpState(e.splitPoints,e.regionBounds)}currentBounds(){return this.warp?this.warp.getWarpState().regionBounds??[]:[]}sourceToDisplayScale(){return{x:this.displayScale.x,y:this.displayScale.y}}quadMatrix(e,t){return Qy(this.node.matrix,e,t)}toScene(e){let t=this.node;return Q(t.matrix,(e.x-this.coreAnchor.x)*this.displayScale.x,(e.y-this.coreAnchor.y)*this.displayScale.y)}toSource(e){let r=this.node.localPoint(e.x,e.y);return{x:r.x/this.displayScale.x+this.coreAnchor.x,y:r.y/this.displayScale.y+this.coreAnchor.y}}screenDist(e,t,r){let o=this.toScene(e),i=this.toScreen(o.x,o.y);return Math.hypot(i.x-t,i.y-r)}localFromSourceBox(e){return{cx:(e.width/2-e.offsetX-this.coreAnchor.x)*this.displayScale.x,cy:(e.height/2-e.offsetY-this.coreAnchor.y)*this.displayScale.y,w:e.width*this.displayScale.x,h:e.height*this.displayScale.y}}refreshPreview(){if(!this.warp)return;let e=this.previewCanvas;this.previewCanvas=this.warp.render(),e&&e!==this.previewCanvas&&this.textures.remove(e),this.previewVersion++}fireHistory(){this.host.onWarpHistoryChange?.(this.undoable,this.redoable)}},Jf=["tl","tr","bl","br"],Ac=["top","right","bottom","left"],em=(n,e)=>{let t=n[e==="tl"||e==="tr"?"top":"bottom"],r=n[e==="tl"||e==="bl"?"left":"right"];if(!t||t.length<4||!r||r.length<4)return null;let o=null;for(let i of[t[0],t[3]])for(let s of[r[0],r[3]]){let a=Math.hypot(i.x-s.x,i.y-s.y);(!o||a<o.dist)&&(o={pt:{x:(i.x+s.x)/2,y:(i.y+s.y)/2},dist:a})}return o?.pt??null},Ky=(n,e,t,r,o)=>{let i=1-o;return{x:i*i*i*n.x+3*i*i*o*e.x+3*i*o*o*t.x+o*o*o*r.x,y:i*i*i*n.y+3*i*i*o*e.y+3*i*o*o*t.y+o*o*o*r.y}},tm=(n,e,t,r)=>({matrix:[1,0,0,1,n.x,n.y],dims:{x:e*2/r,y:e*2/r},color:t}),Qy=(n,e,t)=>[n[0],n[1],n[2],n[3],n[0]*e+n[2]*t+n[4],n[1]*e+n[3]*t+n[5]];var he=n=>Math.round(n*1e6)/1e6;var Wr=([n,e],[t,r])=>n<=t?e>=t:n>=t?r>=n:!1,Gs=([n,e],[t,r])=>{let o=Math.max(n,t),i=Math.min(e,r);return o<=i?[o,i]:null},Qt=(n,e,t,r,o)=>{let i=Math.abs(e);i<=t[r]&&(i<t[r]&&(n.length=0),n.push(o),t[r]=i)},om=n=>{let e=n.map((r,o)=>({p:r,i:o}));e.sort((r,o)=>r.p.x-o.p.x);let t=n.map((r,o)=>({p:r,i:o}));return t.sort((r,o)=>r.p.y-o.p.y),{byX:e,byY:t}},Zy=(n,e,t)=>{let r=0,o=n.length;for(;r<o;){let i=r+o>>1;n[i].p[e]<t?r=i+1:o=i}return r},nm=(n,e,t,r,o,i,s)=>{let a=[],l=(c,u,h,d,f,m)=>{let p=u;for(let b of d){let x=Zy(c,u,b[u]-h),g=b[u]+h,y=m[p];a.length=0;for(let v=x;v<c.length;v++){let S=c[v];if(S.p[u]>g)break;let w=S.p[u]-b[u],R=Math.abs(w);R<=y&&(R<y&&(y=R,a.length=0),a.push({p:S.p,i:S.i,offset:w}))}a.sort((v,S)=>v.i-S.i);for(let v of a)Qt(f,v.offset,m,p,{type:"point",points:[b,v.p],offset:v.offset})}};l(e.byX,"x",t,n,i,o),l(e.byY,"y",r,n,s,o)},Lc=n=>({x:he(n.x),y:he(n.y)}),Nc=n=>({left:he(n.left),top:he(n.top),right:he(n.right),bottom:he(n.bottom)}),zs=n=>[n.tl,n.tr,n.br,n.bl,n.c].map(Lc),im=n=>n.flatMap(zs);var sm=n=>{let e=n.map(Nc).map((o,i)=>({bounds:o,idx:i})),t=o=>[...e].sort((i,s)=>i.bounds[o]-s.bounds[o]),r=(o,i)=>[...e].sort((s,a)=>s.bounds[o]+s.bounds[i]-a.bounds[o]-a.bounds[i]);return{byLeft:t("left"),byRight:t("right"),byTop:t("top"),byBottom:t("bottom"),byLeftPlusRight:r("left","right"),byTopPlusBottom:r("top","bottom")}};var Jy=(n,e,t,r,o)=>{let{left:i,top:s,right:a,bottom:l}=n,c=(i+a)/2,u=(s+l)/2,h=t.x,d=t.y,f=a-i,m=l-s,p=(E,C,T,M)=>({startBounds:E,endBounds:C,startSide:[{x:E.right,y:E.top},{x:E.right,y:E.bottom}],endSide:[{x:C.left,y:C.top},{x:C.left,y:C.bottom}],length:M,overlap:T}),b=(E,C,T,M)=>({startBounds:E,endBounds:C,startSide:[{x:E.left,y:E.bottom},{x:E.right,y:E.bottom}],endSide:[{x:C.left,y:C.top},{x:C.right,y:C.top}],length:M,overlap:T}),x=(E,C)=>{if(!(E.right<C.left&&Wr([E.top,E.bottom],[C.top,C.bottom])))return;let T=Gs([E.top,E.bottom],[C.top,C.bottom]);if(!Wr([s,l],T))return;let M=C.left-E.right,k=he(E.right+M/2-c);if(M>f&&Math.abs(k)<=t.x){Qt(r,k,t,"x",{type:"gap",direction:"center_horizontal",gap:p(E,C,T,M),offset:k});return}let A=he(M-(i-C.right));if(Math.abs(A)<=t.x){Qt(r,A,t,"x",{type:"gap",direction:"side_right",gap:p(E,C,T,M),offset:A});return}let O=he(E.left-a-M);Math.abs(O)<=t.x&&Qt(r,O,t,"x",{type:"gap",direction:"side_left",gap:p(E,C,T,M),offset:O})},g=(E,C)=>{if(!(E.bottom<C.top&&Wr([E.left,E.right],[C.left,C.right])))return;let T=Gs([E.left,E.right],[C.left,C.right]);if(!Wr([i,a],T))return;let M=C.top-E.bottom,k=he(E.bottom+M/2-u);if(M>m&&Math.abs(k)<=t.y){Qt(o,k,t,"y",{type:"gap",direction:"center_vertical",gap:b(E,C,T,M),offset:k});return}let A=he(E.top-l-M);if(Math.abs(A)<=t.y){Qt(o,A,t,"y",{type:"gap",direction:"side_top",gap:b(E,C,T,M),offset:A});return}let O=he(s-C.bottom),F=M-O;Math.abs(F)<=t.y&&Qt(o,F,t,"y",{type:"gap",direction:"side_bottom",gap:b(E,C,T,M),offset:F})},y=e.byLeft,v=e.byRight,S=e.byTop,w=e.byBottom,R=h+1e-6,P=d+1e-6;{let E=y.length;for(let C of v){if(C.bounds.right>=c+h+.001)break;let T=2*c-C.bounds.right,M=T+2*R,k=T-2*R;for(;E>0&&y[E-1].bounds.left>M;)E--;for(let A=E-1;A>=0&&y[A].bounds.left>=k;A--)x(C.bounds,y[A].bounds)}}{let E=0;for(let C of e.byLeftPlusRight){if(C.bounds.right>=i+h+.001)continue;let T=C.bounds.left+C.bounds.right-i,M=T-R,k=T+R;for(;E<v.length&&v[E].bounds.right<M;)E++;for(let A=E;A<v.length&&v[A].bounds.right<=k;A++)x(v[A].bounds,C.bounds)}}{let E=0;for(let C of e.byLeftPlusRight){if(C.bounds.left<=a-h-.001)continue;let T=C.bounds.left+C.bounds.right-a,M=T-R,k=T+R;for(;E<y.length&&y[E].bounds.left<M;)E++;for(let A=E;A<y.length&&y[A].bounds.left<=k;A++)x(C.bounds,y[A].bounds)}}{let E=S.length;for(let C of w){if(C.bounds.bottom>=u+d+.001)break;let T=2*u-C.bounds.bottom,M=T+2*P,k=T-2*P;for(;E>0&&S[E-1].bounds.top>M;)E--;for(let A=E-1;A>=0&&S[A].bounds.top>=k;A--)g(C.bounds,S[A].bounds)}}{let E=0;for(let C of e.byTopPlusBottom){if(C.bounds.top<=l-d-.001)continue;let T=C.bounds.top+C.bounds.bottom-l,M=T-P,k=T+P;for(;E<S.length&&S[E].bounds.top<M;)E++;for(let A=E;A<S.length&&S[A].bounds.top<=k;A++)g(C.bounds,S[A].bounds)}}{let C=0;for(let T of e.byTopPlusBottom){if(T.bounds.bottom>=s+d+.001)continue;let M=T.bounds.top-he(s-T.bounds.bottom),k=M-P,A=M+P;for(;C<w.length&&w[C].bounds.bottom<k-1e-5;)C++;for(let O=C;O<w.length&&w[O].bounds.bottom<=A;O++)g(w[O].bounds,T.bounds)}}},Xs=(n,e,t,r,o)=>{for(let i of n)for(let s of e){let a=s.x-i.x,l=s.y-i.y;Math.abs(a)<=t.x&&Qt(r,a,t,"x",{type:"point",points:[i,s],offset:a}),Math.abs(l)<=t.y&&Qt(o,l,t,"y",{type:"point",points:[i,s],offset:l})}},e0=(n,e,t,r,o)=>{let{left:i,top:s,right:a,bottom:l}=n,c=(i+a)/2,u=(s+l)/2;for(let h of e.horizontalGaps){if(!Wr([s,l],h.overlap))continue;let d=h.startSide[0].x+h.length/2,f=he(d-c);if(h.length>a-i&&Math.abs(f)<=t.x){Math.abs(f)<t.x&&(r.length=0),t.x=Math.abs(f),r.push({type:"gap",direction:"center_horizontal",gap:h,offset:f});continue}let p=i-h.endBounds.right,b=he(h.length-p);if(Math.abs(b)<=t.x){Math.abs(b)<t.x&&(r.length=0),t.x=Math.abs(b),r.push({type:"gap",direction:"side_right",gap:h,offset:b});continue}let x=h.startBounds.left-a,g=he(x-h.length);if(Math.abs(g)<=t.x){Math.abs(g)<t.x&&(r.length=0),t.x=Math.abs(g),r.push({type:"gap",direction:"side_left",gap:h,offset:g});continue}}for(let h of e.verticalGaps){if(!Wr([i,a],h.overlap))continue;let d=h.startSide[0].y+h.length/2,f=he(d-u);if(h.length>l-s&&Math.abs(f)<=t.y){Math.abs(f)<t.y&&(o.length=0),t.y=Math.abs(f),o.push({type:"gap",direction:"center_vertical",gap:h,offset:f});continue}let p=h.startBounds.top-l,b=he(p-h.length);if(Math.abs(b)<=t.y){Math.abs(b)<t.y&&(o.length=0),t.y=Math.abs(b),o.push({type:"gap",direction:"side_top",gap:h,offset:b});continue}let x=he(s-h.endBounds.bottom),g=h.length-x;if(Math.abs(g)<=t.y){Math.abs(g)<t.y&&(o.length=0),t.y=Math.abs(g),o.push({type:"gap",direction:"side_bottom",gap:h,offset:g});continue}}},rm=n=>{let e=new Map;for(let t of n){let r=`${he(t.x)},${he(t.y)}`;e.has(r)||e.set(r,t)}return Array.from(e.values())},am=(n,e)=>{let t={},r={};for(let s of n){if(s.type!=="point")continue;let a=String(he(s.points[0].x));t[a]||(t[a]=[]),t[a].push(...s.points.map(l=>({x:he(l.x),y:he(l.y)})))}for(let s of e){if(s.type!=="point")continue;let a=String(he(s.points[0].y));r[a]||(r[a]=[]),r[a].push(...s.points.map(l=>({x:he(l.x),y:he(l.y)})))}let o=Object.entries(t).map(([s,a])=>({type:"points",points:rm(a.map(l=>({x:Number(s),y:l.y})).sort((l,c)=>l.y-c.y))})),i=Object.entries(r).map(([s,a])=>({type:"points",points:rm(a.map(l=>({x:l.x,y:Number(s)})).sort((l,c)=>l.x-c.x))}));return[...o,...i]},t0=n=>{let e=new Map;for(let t of n){let r=[t.points[0],t.points[1]].flatMap(o=>[he(o.x),he(o.y)]).join(",");e.has(r)||e.set(r,t)}return Array.from(e.values())},n0=(n,e)=>{let{left:t,top:r,right:o,bottom:i}=n,s=[];for(let a of e){let l=a.gap.startBounds,c=a.gap.endBounds,u=Gs([r,i],a.gap.overlap),h=Gs([t,o],a.gap.overlap);switch(a.direction){case"center_horizontal":{if(u){let d=(u[0]+u[1])/2;s.push({type:"gap",direction:"horizontal",points:[{x:a.gap.startSide[0].x,y:d},{x:t,y:d}]},{type:"gap",direction:"horizontal",points:[{x:o,y:d},{x:a.gap.endSide[0].x,y:d}]})}break}case"center_vertical":{if(h){let d=(h[0]+h[1])/2;s.push({type:"gap",direction:"vertical",points:[{x:d,y:a.gap.startSide[0].y},{x:d,y:r}]},{type:"gap",direction:"vertical",points:[{x:d,y:i},{x:d,y:a.gap.endSide[0].y}]})}break}case"side_right":{if(u){let d=(u[0]+u[1])/2;s.push({type:"gap",direction:"horizontal",points:[{x:l.right,y:d},{x:c.left,y:d}]},{type:"gap",direction:"horizontal",points:[{x:c.right,y:d},{x:t,y:d}]})}break}case"side_left":{if(u){let d=(u[0]+u[1])/2;s.push({type:"gap",direction:"horizontal",points:[{x:o,y:d},{x:l.left,y:d}]},{type:"gap",direction:"horizontal",points:[{x:l.right,y:d},{x:c.left,y:d}]})}break}case"side_top":{if(h){let d=(h[0]+h[1])/2;s.push({type:"gap",direction:"vertical",points:[{x:d,y:i},{x:d,y:l.top}]},{type:"gap",direction:"vertical",points:[{x:d,y:l.bottom},{x:d,y:c.top}]})}break}case"side_bottom":{if(h){let d=(h[0]+h[1])/2;s.push({type:"gap",direction:"vertical",points:[{x:d,y:l.bottom},{x:d,y:c.top}]},{type:"gap",direction:"vertical",points:[{x:d,y:c.bottom},{x:d,y:r}]})}break}}}return t0(s.map(a=>({...a,points:[{x:he(a.points[0].x),y:he(a.points[0].y)},{x:he(a.points[1].x),y:he(a.points[1].y)}]})))},lm=(n,e,t,r,o,i)=>{let s=(x,g,y)=>{"byLeft"in r?Jy(x,r,l,g,y):e0(x,r,l,g,y)},a=Nc(e),l={x:o,y:o},c=[],u=[];i?nm(n,i,o,o,l,c,u):Xs(n,t,l,c,u),s(a,c,u);let h={x:he(c[0]?.offset??0),y:he(u[0]?.offset??0)},d=n.map(x=>Lc({x:x.x+h.x,y:x.y+h.y})),f=Nc({left:a.left+h.x,top:a.top+h.y,right:a.right+h.x,bottom:a.bottom+h.y});l.x=0,l.y=0,c.length=0,u.length=0,i?nm(d,i,0,0,l,c,u):Xs(d,t,l,c,u),s(f,c,u);let m=am(c,u),p=[...c,...u].filter(x=>x.type==="gap"),b=n0(f,p);return{snapOffset:h,pointSnapLines:m,gapSnapLines:b}},cm=(n,e,t)=>{let r={x:t,y:t},o=[],i=[];Xs(n,e,r,o,i);let s={x:he(o[0]?.offset??0),y:he(i[0]?.offset??0)};r.x=0,r.y=0,o.length=0,i.length=0;let a=n.map(c=>Lc({x:c.x+s.x,y:c.y+s.y}));Xs(a,e,r,o,i);let l=am(o,i);return{snapOffset:s,pointSnapLines:l}};var r0=200,um=8,o0=1,i0=3,s0=8,a0=oe("#F68066"),hm=new Set(["WorkSpaceClipType","WorkSpaceSafeType","WorkSpaceMaskType","WorkSpaceLineType","WorkSpaceShadowType"]),l0="WorkSpaceDrawType",Hr=n=>({left:Math.min(n.tl.x,n.tr.x,n.br.x,n.bl.x),top:Math.min(n.tl.y,n.tr.y,n.br.y,n.bl.y),right:Math.max(n.tl.x,n.tr.x,n.br.x,n.bl.x),bottom:Math.max(n.tl.y,n.tr.y,n.br.y,n.bl.y)}),dm=(n,e)=>!(Hr(n).right<e.minX||Hr(n).left>e.maxX||Hr(n).bottom<e.minY||Hr(n).top>e.maxY),c0=n=>({x:(n.tl.x+n.br.x)/2,y:(n.tl.y+n.br.y)/2}),Ys=class{constructor(e,t=()=>!1){this.host=e;this.enabled=t}host;enabled;pointSnapLines=[];gapSnapLines=[];lastSnapOffset={x:0,y:0};activeType="";pendingMove=!1;gestureKey="";viewportSignature="";referenceCoords=[];referencePoints=[];axisIndex=null;gapIndex=null;scalingKey="";scalingPoints=[];workspaceResolved=!1;workspacePointKeys=new Set;workspaceBounds;get info(){return{pending:this.pendingMove,offset:{...this.lastSnapOffset},pointLines:this.pointSnapLines.length,gapLines:this.gapSnapLines.length,candidates:this.referenceCoords.length,activeType:this.activeType}}registerMove(e){this.enabled()&&(this.clearLines(),this.activeType=e.raw.type,this.ensureMoveCaches(),this.pendingMove=!0)}settleMoveSnap(){if(!this.pendingMove||(this.pendingMove=!1,!this.enabled()))return;let e=this.host.document;if(e.groupEditing&&e.activeGroupChild){this.clearLines();return}let t=e.selection;if(!t.length||!this.referenceCoords.length||!this.referencePoints.length||!this.gapIndex){this.clearLines();return}let r=et(e);if(!r){this.clearLines();return}let o={tl:r.quad.tl,tr:r.quad.tr,br:r.quad.br,bl:r.quad.bl,c:c0(r.quad)},i=um/this.host.zoom,{snapOffset:s,pointSnapLines:a,gapSnapLines:l}=lm(zs(o),Hr(o),this.referencePoints,this.gapIndex,i,this.axisIndex??void 0);if(s.x!==0||s.y!==0){for(let u of t)e.setProps(u,{left:(u.raw.left??0)+s.x,top:(u.raw.top??0)+s.y},{deferIndexRebuild:!0});let c=e.selectionFrame;c&&e.setSelectionFrame({...c,center:{x:c.center.x+s.x,y:c.center.y+s.y}})}this.lastSnapOffset={...s},this.pointSnapLines=a,this.gapSnapLines=l}registerScaling(e,t){if(!this.enabled()||e.typeKey===L.CIRCLE)return;this.clearLines(),this.activeType=e.raw.type;let r=this.host.document;this.ensureScalingCaches();let o=et(r);if(!o||!this.scalingPoints.length)return;let s=(os(t)?[t]:[...Hl]).map(c=>({x:o.quad[c].x,y:o.quad[c].y})),a=um/this.host.zoom,{pointSnapLines:l}=cm(s,this.scalingPoints,a);this.pointSnapLines=l,this.gapSnapLines=[]}finishGesture(){this.settleMoveSnap(),this.clearLines(),this.activeType="",this.gestureKey="",this.viewportSignature="",this.referenceCoords=[],this.referencePoints=[],this.axisIndex=null,this.gapIndex=null,this.scalingKey="",this.scalingPoints=[],this.workspaceResolved=!1,this.workspacePointKeys.clear(),this.workspaceBounds=void 0}buildOverlay(e){if(this.activeType==="ReferenceLine")return[];if(!this.pointSnapLines.length&&!this.gapSnapLines.length)return[];let t=[],r=o0/e,o=(i,s)=>t.push(Re(i,s,r,a0));this.ensureWorkspaceInfo();for(let i of this.pointSnapLines){let s=i.points;if(!s.length)continue;if(!!this.workspaceBounds&&s.some(c=>this.workspacePointKeys.has(`${he(c.x)},${he(c.y)}`))&&this.workspaceBounds){let c=this.workspaceBounds,u=s.every(d=>d.x===s[0].x),h=s.every(d=>d.y===s[0].y);u&&o({x:s[0].x,y:Math.min(s[0].y,c.top)},{x:s[0].x,y:Math.max(s[s.length-1].y,c.bottom)}),h&&o({x:Math.min(s[0].x,c.left),y:s[0].y},{x:Math.max(s[s.length-1].x,c.right),y:s[0].y})}else s.length>=2&&o(s[0],s[s.length-1]);let l=i0/e;for(let c of s)o({x:c.x-l,y:c.y-l},{x:c.x+l,y:c.y+l}),o({x:c.x+l,y:c.y-l},{x:c.x-l,y:c.y+l})}for(let i of this.gapSnapLines){let[s,a]=i.points,l=s0/e,c=l/2,u=l/4;if(i.direction==="horizontal"){let h=s.y,d=(s.x+a.x)/2;o({x:s.x,y:h-l},{x:s.x,y:h+l}),o({x:d-u,y:h-c},{x:d-u,y:h+c}),o({x:d+u,y:h-c},{x:d+u,y:h+c}),o({x:a.x,y:h-l},{x:a.x,y:h+l}),o(s,a)}else{let h=s.x,d=(s.y+a.y)/2;o({x:h-l,y:s.y},{x:h+l,y:s.y}),o({x:h-c,y:d-u},{x:h+c,y:d-u}),o({x:h-c,y:d+u},{x:h+c,y:d+u}),o({x:h-l,y:a.y},{x:h+l,y:a.y}),o(s,a)}}return t}clearLines(){this.pointSnapLines=[],this.gapSnapLines=[]}keyCacheSelection=null;keyCacheValue="";ensureMoveCaches(){let e=this.host.document,t=e.selection;this.keyCacheSelection!==t&&(this.keyCacheSelection=t,this.keyCacheValue=t.map(l=>l.id).join("|"));let r=this.keyCacheValue,o=this.getViewportRect(),i=o?.signature??"";if(this.gestureKey===r&&this.referenceCoords.length&&this.viewportSignature===i)return;this.gestureKey=r,this.viewportSignature=i;let s=new Set(t),a=o?.rect;this.referenceCoords=[];for(let l of e.nodes){if(!l.visible||s.has(l)||hm.has(l.id))continue;let c=this.nodeCoords(l);a&&!dm(c,a)||this.referenceCoords.push(c)}this.referencePoints=im(this.referenceCoords),this.axisIndex=om(this.referencePoints),this.gapIndex=sm(this.referenceCoords.map(Hr))}ensureScalingCaches(){let e=this.host.document,t=e.selection.map(s=>s.id).join("|");if(this.scalingKey===t&&this.scalingPoints.length)return;this.scalingKey=t;let r=new Set(e.selection),o=this.getViewportRect()?.rect,i=[];for(let s of e.nodes){if(!s.visible||r.has(s)||hm.has(s.id))continue;let a=this.nodeCoords(s);o&&!dm(a,o)||i.push(...zs(a))}this.scalingPoints=i}ensureWorkspaceInfo(){if(this.workspaceResolved)return;this.workspaceResolved=!0;let e=this.host.document.nodes.find(o=>o.id===l0);if(!e)return;let t=e.aCoords,r=e.center;for(let o of[t.tl,t.tr,t.br,t.bl,r])this.workspacePointKeys.add(`${he(o.x)},${he(o.y)}`);this.workspaceBounds=e.bounds}nodeCoords(e){let t=e.aCoords,r=e.center;return{tl:{x:t.tl.x,y:t.tl.y},tr:{x:t.tr.x,y:t.tr.y},br:{x:t.br.x,y:t.br.y},bl:{x:t.bl.x,y:t.bl.y},c:{x:r.x,y:r.y}}}getViewportRect(){let e=this.host.viewportTransform,t=e[0];if(!t||!Number.isFinite(t))return;let{width:r,height:o}=this.host.viewSize,i={x:(0-e[4])/e[0],y:(0-e[5])/e[3]},s={x:(r-e[4])/e[0],y:(o-e[5])/e[3]},a=r0/t;return{rect:{minX:Math.min(i.x,s.x)-a,minY:Math.min(i.y,s.y)-a,maxX:Math.max(i.x,s.x)+a,maxY:Math.max(i.y,s.y)+a},signature:`${e[0]},${e[1]},${e[2]},${e[3]},${e[4]},${e[5]}`}}};var fm=n=>{let e=n?.animates;return Array.isArray(e)?e.filter(t=>!!t&&typeof t=="object"&&typeof t.key=="string"):[]},u0={width:0,height:0},be=(n,e={})=>({originX:"center",originY:"center",left:n.center.x,top:n.center.y,...e}),Ft=(n,e,t=u0,r={})=>e==="left"?be(n,{left:-n.width/2,...r}):e==="right"?be(n,{left:t.width+n.width/2,...r}):e==="top"?be(n,{top:-n.height/2,...r}):be(n,{top:t.height+n.height/2,...r}),h0=[{key:"left-swipe-entry",name:"左滑入场",category:"entrance",getStartState:n=>Ft(n,"left"),getEndState:n=>be(n)},{key:"right-swipe-entry",name:"右滑入场",category:"entrance",getStartState:(n,e)=>Ft(n,"right",e),getEndState:n=>be(n)},{key:"top-swipe-entry",name:"上滑入场",category:"entrance",getStartState:(n,e)=>Ft(n,"bottom",e),getEndState:n=>be(n)},{key:"bottom-swipe-entry",name:"下滑入场",category:"entrance",getStartState:n=>Ft(n,"top"),getEndState:n=>be(n)},{key:"smash-off",name:"砸落",category:"entrance",getStartState:n=>be(n,{scaleX:n.scaleX*2.5,scaleY:n.scaleY*2.5}),getEndState:n=>be(n,{scaleX:n.scaleX,scaleY:n.scaleY})},{key:"gradually-display",name:"渐显",category:"entrance",getStartState:n=>be(n,{scaleX:n.scaleX*.01,scaleY:n.scaleY*.01,opacity:.01}),getEndState:n=>be(n,{scaleX:n.scaleX,scaleY:n.scaleY,opacity:1})},{key:"pop-up",name:"弹出",category:"entrance",getStartState:n=>be(n,{scaleX:n.scaleX*.01,scaleY:n.scaleY*.01}),getEndState:n=>be(n,{scaleX:n.scaleX*1.3,scaleY:n.scaleY*1.3})},{key:"flip-horizontal-entry",name:"水平翻转",category:"entrance",getStartState:n=>be(n,{scaleX:n.scaleX*.01}),getEndState:n=>be(n,{scaleX:n.scaleX})},{key:"flip-vertical-entry",name:"垂直翻转",category:"entrance",getStartState:n=>be(n,{scaleY:n.scaleY*.01}),getEndState:n=>be(n,{scaleY:n.scaleY})},{key:"rotate-entry",name:"旋入",category:"entrance",getStartState:n=>be(n,{angle:n.angle-720,scaleX:n.scaleX*.01,scaleY:n.scaleY*.01}),getEndState:n=>be(n,{angle:n.angle,scaleX:n.scaleX,scaleY:n.scaleY})}],d0=[{key:"left-swipe-exit",name:"左滑退场",category:"exit",getStartState:n=>be(n),getEndState:n=>Ft(n,"left")},{key:"right-swipe-exit",name:"右滑退场",category:"exit",getStartState:n=>be(n),getEndState:(n,e)=>Ft(n,"right",e)},{key:"top-swipe-exit",name:"上滑退场",category:"exit",getStartState:n=>be(n),getEndState:n=>Ft(n,"top")},{key:"bottom-swipe-exit",name:"下滑退场",category:"exit",getStartState:n=>be(n),getEndState:(n,e)=>Ft(n,"bottom",e)},{key:"fade-out",name:"渐隐",category:"exit",getStartState:n=>be(n,{scaleX:n.scaleX,scaleY:n.scaleY,opacity:1}),getEndState:n=>be(n,{scaleX:n.scaleX*.01,scaleY:n.scaleY*.01,opacity:.01})},{key:"flip-horizontal-exit",name:"水平翻转",category:"exit",getStartState:n=>be(n,{scaleX:n.scaleX}),getEndState:n=>be(n,{scaleX:n.scaleX*.01})},{key:"flip-vertical-exit",name:"垂直翻转",category:"exit",getStartState:n=>be(n,{scaleY:n.scaleY}),getEndState:n=>be(n,{scaleY:n.scaleY*.01})},{key:"rotate-exit",name:"旋出",category:"exit",getStartState:n=>be(n,{angle:n.angle-720,scaleX:n.scaleX,scaleY:n.scaleY}),getEndState:n=>be(n,{angle:n.angle+720,scaleX:n.scaleX*.01,scaleY:n.scaleY*.01})}],f0=[{key:"subtitle-scroll",name:"字幕滚动",category:"emphasis",getStartState:(n,e)=>Ft(n,"right",e),getEndState:n=>Ft(n,"left")},{key:"flip-horizontal",name:"水平翻转",category:"emphasis",getStartState:n=>be(n,{scaleX:n.scaleX}),getEndState:n=>be(n,{scaleX:-n.scaleX})},{key:"flip-vertical",name:"垂直翻转",category:"emphasis",getStartState:n=>be(n,{scaleY:n.scaleY}),getEndState:n=>be(n,{scaleY:-n.scaleY})}],m0=[...h0,...d0,...f0],Ic=new Map(m0.map(n=>[n.key,n])),p0=n=>Ic.get(n),Us=n=>{let e=Ic.get(n);return e?e.category==="entrance"?0:e.category==="emphasis"?1:2:Number.MAX_SAFE_INTEGER},mm=n=>Us(n)===1,b0=n=>{let e=n.duration??0;return!mm(n.key)||!n.single?e:Math.floor(e/n.single)*n.single},x0=n=>{let e=[...n].sort((r,o)=>{let i=Us(r.key)-Us(o.key);return i!==0?i:Us(r.key)===Number.MAX_SAFE_INTEGER?(r.startTime??0)-(o.startTime??0):0}),t=0;return e.map(r=>{let o={...r,startTime:Number(t.toFixed(3))};return t+=r.duration??0,o})},pm=.2,bm=(n,e)=>{let t=[];for(let s of n)for(let a of x0(s.animates??[]))t.push({target:s.target,view:s.view,animate:a});t.sort((s,a)=>(s.animate.startTime??0)-(a.animate.startTime??0));let r=[],o=0,i=0;for(let s of t){let a=s.animate.startTime??0,l=Math.max(0,a-i),c=o+l,u=b0(s.animate),h=c+pm,d=h+u;r.push({target:s.target,animate:s.animate,definition:Ic.get(s.animate.key)??null,view:s.view,waitTime:l,invokeTime:c,motionStart:h,motionEnd:d,playbackDuration:u}),o=d,i=a+(s.animate.duration??0)}return{timeline:r,duration:r[r.length-1]?.motionEnd??0,ws:e}},_c=(n,e)=>{let t=new Map;for(let o of e.timeline){let i=t.get(o.target);i?i.push(o):t.set(o.target,[o])}let r=[];return t.forEach((o,i)=>{let s=o.find(f=>n>=f.invokeTime&&n<f.motionEnd);if(!s||!s.definition){r.push({target:i,override:null});return}if(n<s.motionStart){r.push({target:i,override:s.definition.getStartState(s.view,e.ws)});return}let a=n-s.motionStart,l=s.animate,c=s.playbackDuration>0?s.playbackDuration:1,u;mm(l.key)&&l.single&&l.single>0?u=a%l.single/l.single:u=a/c,u=Math.min(Math.max(u,0),1);let h=s.definition.getStartState(s.view,e.ws),d=s.definition.getEndState(s.view,e.ws);r.push({target:i,override:xm(l.key,h,d,u)})}),r},xm=(n,e,t,r)=>{let o={};for(let i of Object.keys(t)){let s=e[i],a=t[i];if(typeof s=="number"&&typeof a=="number"){let l;n==="smash-off"&&(i==="scaleX"||i==="scaleY")?l=s-(s-a)*r:l=s+(a-s)*r,o[i]=Number(l.toFixed(3))}else o[i]=r<.5?s:a}for(let i of Object.keys(e))i in o||(o[i]=e[i]);return o},g0=n=>1-Math.cos(Math.min(Math.max(n,0),1)*Math.PI/2),gm=(n,e,t)=>{let r=p0(t.key);if(!r)return null;let o=t.duration??0,i=t.single&&t.single>0?t.single:void 0,s=r.category==="emphasis",a=s&&i?Math.floor(o/i):1,l=s&&i?i:o;return{key:t.key,definition:r,view:n,ws:e,delay:pm,loopDuration:l,loopCount:a}},Dc=(n,e)=>{if(n<0)return{override:e.definition.getStartState(e.view,e.ws),done:!1};if(n<e.delay)return{override:e.definition.getStartState(e.view,e.ws),done:!1};let t=n-e.delay,r=e.loopCount*e.loopDuration;if(t>=r)return{override:null,done:!0};let o=e.loopDuration>0?Math.floor(t/e.loopDuration):0,i=e.loopDuration>0?t-o*e.loopDuration:0,s=e.loopDuration>0?i/e.loopDuration:1,a=e.definition.getStartState(e.view,e.ws),l=e.definition.getEndState(e.view,e.ws);return{override:xm(e.key,a,l,g0(s)),done:!1}},$s=n=>n.scrollSpeed?(n.textTotalWidth+n.viewWidth)/n.scrollSpeed:0,y0=(n,e,t)=>{if(e<=0)return 0;let r=Math.max(n,0);return t==="loop"?r%e:Math.min(r,e)},ym=(n,e,t="loop")=>{if(!n.scrollEnabled)return 0;let r=$s(n);if(r<=0)return 0;let o=y0(e,r,t)/r,i=n.textTotalWidth+n.viewWidth;return n.scrollDirection==="left-to-right"?o*i:-o*i},Yo=class{_state="idle";_time=0;anchorNow=0;anchorTime=0;_trackDuration;constructor(e){this._trackDuration=e}get trackDuration(){return this._trackDuration}retargetDuration(e){this._trackDuration=e,this._time>e&&(this._time=e)}get state(){return this._state}get time(){return this._time}play(e){this._state==="idle"||this._state==="ended"?(this._time=0,this.anchorTime=0):this.anchorTime=this._time,this.anchorNow=e,this._state="playing"}pause(e){this._state==="playing"&&(this.syncTime(e),this._state=this._time>=this.trackDuration?"ended":"paused")}seek(e,t){this._time=Math.min(Math.max(t,0),this.trackDuration),this.anchorNow=e,this.anchorTime=this._time,this._state=this._time>=this.trackDuration?"ended":"paused"}stop(){this._state="idle",this._time=0,this.anchorNow=0,this.anchorTime=0}tick(e){return this._state==="idle"?null:(this._state==="playing"&&this.syncTime(e),{time:this._time,playing:this._state==="playing"})}syncTime(e){let t=(e-this.anchorNow)/1e3;this._time=Math.min(Math.max(this.anchorTime+t,0),this.trackDuration),this._time>=this.trackDuration&&(this._state="ended")}},Fc=(n,e)=>Math.max(n,...e,0);var js=class{constructor(e){this.host=e}host;playback=null;player=null;totalDuration=0;overridesActive=!1;previews=new Map;previewOverridesActive=!1;reset(){this.playback=null,this.player=null,this.totalDuration=0,this.overridesActive=!1,this.previews.clear(),this.previewOverridesActive=!1}play(){this.cancelPreviews(),this.rebuild();let e=[...this.collectMediaDurations(),...this.collectScrollTextDurations()];this.totalDuration=Fc(this.playback?.duration??0,e),this.player?this.player.retargetDuration(this.totalDuration):this.player=new Yo(this.totalDuration),this.player.play(performance.now());for(let t of this.host.document.nodes)t instanceof ie?t.play():t instanceof ae&&t.playClipMedia();this.syncVideosToTime(this.player.time,!0),this.applyScrollTextOffsets(this.player.time),this.host.requestRenderAll()}pause(){this.player?.pause(performance.now());for(let e of this.host.document.nodes)e instanceof ie?e.pause():e instanceof ae&&e.pauseClipMedia();this.host.requestRenderAll()}stop(){this.cancelPreviews(),this.player?.stop(),this.clearOverrides();for(let{node:e}of this.scrollTextTracks())e.setScrollOffset(0);for(let e of this.host.document.nodes)e instanceof ie?e.stop():e instanceof ae&&e.syncClipMediaToTime(0,!1);this.host.requestRenderAll()}seek(e){if(this.cancelPreviews(),!this.player){this.rebuild();let t=[...this.collectMediaDurations(),...this.collectScrollTextDurations()];this.totalDuration=Fc(this.playback?.duration??0,t),this.player=new Yo(this.totalDuration)}this.player.seek(performance.now(),e),this.applyAnimationTime(this.player.time),this.applyScrollTextOffsets(this.player.time),this.syncVideosToTime(this.player.time,!1),this.host.requestRenderAll()}get info(){return!this.player&&!this.playback?null:{state:this.player?.state??"idle",time:this.player?.time??0,duration:this.totalDuration,animatedCount:this.playback?.timeline.length??0}}playSingleAnimation(e,t,r){let o=gm(this.targetView(e),this.workspaceView(),t);if(!o)return!1;this.stopSingleAnimation(e);let i={target:e,plan:o,startAt:performance.now(),onComplete:r};this.previews.set(e,i);let s=Dc(0,o);return e.setAnimationOverride(s.override),(s.override||this.previewOverridesActive)&&this.host.document.refreshHitIndex(),this.previewOverridesActive=!!s.override,this.host.requestRenderAll(),!0}stopSingleAnimation(e){let t=e?this.previews.has(e)?[e]:[]:[...this.previews.keys()];if(t.length){for(let r of t)this.previews.delete(r),r.setAnimationOverride(null);this.previewOverridesActive&&this.host.document.refreshHitIndex(),this.previewOverridesActive=!1,this.host.requestRenderAll()}}get singlePreviewInfo(){let e=performance.now();return[...this.previews.values()].map(t=>{let r=(e-t.startAt)/1e3,o=t.plan.loopCount*t.plan.loopDuration;return{nodeId:t.target.id,key:t.plan.key,elapsed:r,duration:t.plan.delay+o,state:r<t.plan.delay?"delay":r<t.plan.delay+o?"playing":"done"}})}tick(e){let t=this.player,r=t?t.tick(e):null;r&&(this.applyAnimationTime(r.time),this.applyScrollTextOffsets(r.time));let o=this.tickPreviews(e);return!!r?.playing||o}tickPreviews(e){if(!this.previews.size)return!1;let t=!1,r=!1;for(let o of[...this.previews.values()]){let i=(e-o.startAt)/1e3,s=Dc(i,o.plan);o.target.setAnimationOverride(s.override),s.override&&(r=!0),s.done?(this.previews.delete(o.target),o.onComplete?.()):t=!0}return(r||this.previewOverridesActive)&&this.host.document.refreshHitIndex(),this.previewOverridesActive=r,t}cancelPreviews(){this.previews.size&&this.stopSingleAnimation()}get scrollTextInfo(){return this.scrollTextTracks().map(({node:e,input:t})=>({id:e.id,offset:e.scrollOffset,duration:$s(t),viewWidth:t.viewWidth,textTotalWidth:t.textTotalWidth,speed:t.scrollSpeed,direction:t.scrollDirection,enabled:t.scrollEnabled}))}applyAnimationTime(e){if(!this.playback)return;let t=!1;for(let{target:r,override:o}of _c(e,this.playback))r.setAnimationOverride(o),o&&(t=!0);(t||this.overridesActive)&&this.host.document.refreshHitIndex(),this.overridesActive=t}clearOverrides(){if(this.playback){for(let{target:e}of _c(0,this.playback))e.setAnimationOverride(null);this.host.document.refreshHitIndex(),this.overridesActive=!1}}rebuild(){let e=[];for(let t of this.host.document.nodes){let r=fm(t.raw);r.length&&e.push({target:t,view:this.targetView(t),animates:r})}this.playback=bm(e,this.workspaceView())}targetView(e){let t=e.raw.scaleX??1,r=e.raw.scaleY??1,o=e.dims;return{left:e.raw.left??0,top:e.raw.top??0,scaleX:t,scaleY:r,angle:e.raw.angle??0,opacity:e.raw.opacity??1,width:o.x*t,height:o.y*r,center:Xt({...e.raw,width:o.x,height:o.y})}}workspaceView(){for(let e of this.host.document.nodes)if(e.raw.id===gn)return{width:e.dims.x*(e.raw.scaleX??1),height:e.dims.y*(e.raw.scaleY??1)};return{width:0,height:0}}scrollTextTracks(){let e=[];for(let t of this.host.document.nodes){if(!(t instanceof Se))continue;let r=Ah(t);r&&e.push({node:t,input:r})}return e}collectScrollTextDurations(){return this.scrollTextTracks().map(({input:e})=>e.scrollEnabled?$s(e):0)}applyScrollTextOffsets(e){for(let{node:t,input:r}of this.scrollTextTracks())t.setScrollOffset(ym(r,e,"loop"))}collectMediaDurations(){let e=[],t=r=>{for(let o of r)o instanceof ie?e.push(o.mediaDuration):o instanceof ae?o.clipMediaDuration>0&&e.push(o.clipMediaDuration):o instanceof J&&t(o.children)};return t(this.host.document.nodes),e}syncVideosToTime(e,t){let r=o=>{for(let i of o)i instanceof ie?i.syncVideoToTime(e,t):i instanceof ae?i.syncClipMediaToTime(e,t):i instanceof J&&r(i.children)};r(this.host.document.nodes)}};var Sm=14,vm=n=>n.fontFamily||"仓耳小丸子",Vs=class{host;session=null;offDocEvents;disposed=!1;constructor(e){this.host=e;let t=e.document.events,r=[t.on("text:changed",o=>this.onTextChanged(o)),t.on("text:editing:exited",()=>this.finish()),t.on("object:removed",o=>this.onOverlayRemoved(o))];this.offDocEvents=()=>r.forEach(o=>o())}dispose(){this.disposed||(this.disposed=!0,this.offDocEvents())}get active(){return this.session!==null}isOverlay(e){return this.session?.overlay===e}get info(){let e=this.session;return e?{tableId:e.table.id,row:e.row,col:e.col,text:e.overlay.raw.text??""}:null}startEditing(e,t,r,o={}){let i=this.host.document;if(!i.nodes.includes(e))return!1;let s=lt(e.cellMap,t,r),a=e.cellBounds(s.row,s.col);if(!a)return!1;i.editingNode&&i.exitEditing(),e.rebuildTable();let l=JSON.stringify(e.toObject()),c=e.raw,u=c.cellPadding??8,h=we(e.cellMap,s.row,s.col),d=e.cellSceneCenter(s.row,s.col),f={type:"textbox",id:`${e.id}-cell-edit`,text:o.initialText??h?.text??"",left:d.x,top:d.y,width:Math.max(0,a.width-u*2),originX:"center",originY:"center",scaleX:c.scaleX??1,scaleY:c.scaleY??1,angle:e.tableAngle,fill:h?.textFill??c.textFill,fontSize:h?.fontSize??Sm,fontWeight:h?.fontWeight,fontStyle:h?.fontStyle,fontFamily:h?.fontFamily||vm(c),textAlign:h?.textAlign??fe.CENTER,lineHeight:1.16,splitByGrapheme:!0,opacity:1,visible:!0},m=new Se(f);if(e.editingCell=s,e.clearCellInteractionState(),this.session={overlay:m,table:e,row:s.row,col:s.col,snapshot:l,data:h??null},i.add(m),e.rebuildTable(),(i.selection.length!==1||i.selection[0]!==e)&&i.setSelection([e],"update"),i.enterEditing(m,{transient:!0}),o.initialText===void 0){let p=m.textLayout.graphemeCodeUnitOffsets.length-1;this.host.setEditingSelection(0,p)}return this.host.requestRenderAll(),!0}onTextChanged(e){let t=this.session;if(!t||e!==t.overlay)return;if(!t.data){let o=Array.isArray(t.table.raw.cellData)?t.table.raw.cellData:t.table.raw.cellData=[];t.data={row:t.row,col:t.col,fill:t.table.raw.cellFill,stroke:t.table.raw.cellStroke,text:"",textFill:t.table.raw.textFill,fontSize:Sm,fontWeight:"normal",fontStyle:"normal",fontFamily:vm(t.table.raw),textAlign:"center"},o.push(t.data)}t.data.text=e.raw.text??"",t.table.rebuildTable();let r=t.table.cellSceneCenter(t.row,t.col);r&&e.set({left:r.x,top:r.y}),this.host.requestRenderAll()}finish(){let e=this.session;if(!e)return;this.session=null;let t=this.host.document;if(e.table.editingCell=null,t.remove(e.overlay),e.table.rebuildTable(),t.setSelection([e.table],"create"),e.table.setCellSelection([{row:e.row,col:e.col}],{row:e.row,col:e.col},{r1:e.row,r2:e.row,c1:e.col,c2:e.col}),JSON.stringify(e.table.toObject())!==e.snapshot){let r=new Map;r.set(e.table,JSON.parse(e.snapshot)),t.applyTransform([e.table],()=>({}),"modified",{action:Ne.tableCellEdit,before:r})}this.host.requestRenderAll()}onOverlayRemoved(e){let t=this.session;!t||e!==t.overlay||(this.session=null,t.table.editingCell=null,t.table.rebuildTable(),this.host.requestRenderAll())}};var S0=530,wm=[.1,.1,.1,1],v0=[.18,.44,.96,.3],qs=class{host;textarea=null;blinkTimer=null;caretVisible=!0;onSelectionChange=null;offDocEvents;inComposition=!1;compositionRange=null;constructor(e){this.host=e;let t=e.document.events,r=[t.on("text:changed",()=>{this.positionAtCaret(),this.host.requestRenderAll()}),t.on("text:editing:entered",()=>this.startUi()),t.on("text:editing:exited",()=>this.stopUi())];this.offDocEvents=()=>r.forEach(o=>o())}get composing(){return this.inComposition}enterEditingAtClick(e,t,r){let o=this.host.document.editingNode===e;if(this.host.document.enterEditing(e),!o){let c=e.textLayout.graphemeCodeUnitOffsets.length-1;this.setSelection(0,c);return}let i=e.localPoint(t,r),s=e.cursorIndexAt(i.x,i.y),[a,l]=e.wordBoundsAt(s);this.setSelection(a,l)}setSelection(e,t){let r=this.host.document.editingNode;if(!r)return;this.host.document.editSelection.start=e,this.host.document.editSelection.end=t;let o=this.textarea;if(o){let i=r.textLayout.graphemeCodeUnitOffsets,s=i[Math.min(e,i.length-1)]??0,a=i[Math.min(t,i.length-1)]??0;o.setSelectionRange(Math.min(s,a),Math.max(s,a))}this.caretVisible=!0,this.positionAtCaret(),this.focusTextarea(),this.host.requestRenderAll()}buildOverlay(){let e=this.host.document.editingNode;if(!e)return[];let t=e.textLayout,r=this.host.document.editSelection,o=Math.min(r.start,r.end),i=Math.max(r.start,r.end),s=e.matrix,a=Math.hypot(s[0],s[1])||1,l=[];for(let c of t.lines){let u=c.styleMap.flatStart,h=u+c.graphemes.length,d=Math.max(o,u),f=Math.min(i,h);if(f>d){let m=-t.width/2+c.leftOffset,p=m+(d<h?c.boxes[d-u].left:ln(c)),b=m+(f<h?c.boxes[f-u].left:ln(c));if(b>p){let x=e.contentTopY+c.top;l.push({matrix:$(s,[1,0,0,1,(p+b)/2,x+c.implHeight/2]),dims:{x:b-p,y:c.implHeight},color:v0})}}}if(o===i&&this.caretVisible&&!this.inComposition){let c=e.cursorCoord(o);if(c){let u=2/this.host.zoom/a;l.push({matrix:$(s,[1,0,0,1,c.x+u/2,c.y+c.height/2]),dims:{x:u,y:c.height},color:wm})}}if(this.inComposition&&this.compositionRange){let c=this.compositionRange.start,u=this.compositionRange.end,h=t.lines.find(d=>{let f=d.styleMap.flatStart;return c>=f&&c<=f+d.graphemes.length});if(h){let d=h.styleMap.flatStart,f=-t.width/2+h.leftOffset,m=f+(c-d<h.boxes.length?h.boxes[c-d].left:ln(h)),p=f+(u-d<h.boxes.length?h.boxes[u-d].left:ln(h)),x=e.contentTopY+h.baseline+e.textStyle.fontSize*.14;l.push({matrix:$(s,[1,0,0,1,(m+p)/2,x]),dims:{x:Math.max(0,p-m),y:1.5/this.host.zoom/a},color:wm})}}return l}startUi(){let e=this.host.document.editingNode;if(!e)return;let t=this.ensureTextarea();t.value=e.raw.text??"",this.positionAtCaret();let r=t.value.length;t.setSelectionRange(r,r),this.focusTextarea(),this.caretVisible=!0,this.inComposition=!1,this.compositionRange=null,this.blinkTimer!==null&&window.clearInterval(this.blinkTimer),this.blinkTimer=window.setInterval(()=>{this.caretVisible=!this.caretVisible,this.host.requestRenderAll()},S0),this.host.requestRenderAll()}stopUi(){this.blinkTimer!==null&&(window.clearInterval(this.blinkTimer),this.blinkTimer=null),this.textarea?.blur(),this.textarea?.remove(),this.textarea=null,this.host.requestRenderAll()}ensureTextarea(){if(this.textarea)return this.textarea;let e=document.createElement("textarea");return e.setAttribute("data-engine-editing",""),e.autocomplete="off",e.spellcheck=!1,Object.assign(e.style,{position:"absolute",opacity:"0",width:"4px",height:"20px",padding:"0",border:"none",overflow:"hidden",resize:"none",background:"transparent",pointerEvents:"none",zIndex:"0"}),this.host.canvasEl.parentElement?.appendChild(e),e.addEventListener("input",()=>{this.host.document.updateEditingText(e.value,e.selectionStart??0,e.selectionEnd??0)}),e.addEventListener("compositionstart",()=>{this.inComposition=!0,this.caretVisible=!0,this.blinkTimer!==null&&(window.clearInterval(this.blinkTimer),this.blinkTimer=null)}),e.addEventListener("compositionupdate",t=>{let r=t.data??"",i=t.target.selectionStart??0;this.compositionRange={start:i-r.length,end:i},this.positionAtCaret(),this.host.requestRenderAll()}),e.addEventListener("compositionend",()=>{this.inComposition=!1,this.compositionRange=null,this.host.requestRenderAll()}),e.addEventListener("keydown",t=>{if(t.stopPropagation(),t.key==="Escape"){if(this.inComposition)return;t.preventDefault(),this.host.document.exitEditing();return}if(this.inComposition)return;let r=this.navigateKey(t);r&&(t.preventDefault(),e.setSelectionRange(r[0],r[1],r[2]),this.host.document.updateEditingSelection(r[0],r[1]),this.caretVisible=!0,this.positionAtCaret(),this.host.requestRenderAll())}),this.onSelectionChange&&document.removeEventListener("selectionchange",this.onSelectionChange),this.onSelectionChange=()=>{let t=this.textarea;t&&this.host.document.editingNode&&document.activeElement===t&&(this.host.document.updateEditingSelection(t.selectionStart??0,t.selectionEnd??0),this.positionAtCaret(),this.host.requestRenderAll())},document.addEventListener("selectionchange",this.onSelectionChange),this.textarea=e,e}focusTextarea(){this.textarea?.focus({preventScroll:!0})}positionAtCaret(){let e=this.host.document.editingNode,t=this.textarea;if(!e||!t)return;let r=this.host.document.editSelection,o=e.cursorCoord(Math.min(r.start,r.end));if(!o)return;let i=e.matrix,s=i[0]*o.x+i[2]*o.y+i[4],a=i[1]*o.x+i[3]*o.y+i[5],l=this.host.toScreen(s,a),c=this.host.canvasEl.getBoundingClientRect(),u=this.host.canvasEl.parentElement?.getBoundingClientRect()??c;t.style.left=`${c.left-u.left+l.x}px`,t.style.top=`${c.top-u.top+l.y}px`}navigateKey(e){let t=this.host.document.editingNode;if(!t||e.ctrlKey||e.metaKey||e.altKey)return null;let r=t.textLayout,o=r.graphemeCodeUnitOffsets,i=o.length-1,s=this.host.document.editSelection,a=e.shiftKey?Math.max(s.start,s.end):s.end,l=e.shiftKey?Math.min(s.start,s.end):a,c=p=>o[Math.max(0,Math.min(p,i))]??0,u=p=>{for(let b=0;b<r.lines.length;b++){let x=r.lines[b].styleMap.flatStart;if(p<=x+r.lines[b].graphemes.length)return b}return r.lines.length-1},h=(p,b)=>{let x=r.lines[p],g=b-x.styleMap.flatStart;return-r.width/2+x.leftOffset+(g<x.boxes.length?x.boxes[g].left:ln(x))},d=(p,b)=>{let x=r.lines[p],g=-r.width/2+x.leftOffset;for(let y=0;y<x.boxes.length;y++)if(b<g+x.boxes[y].left+x.boxes[y].width/2)return x.styleMap.flatStart+y;return x.styleMap.flatStart+x.graphemes.length},f,m;switch(e.key){case"ArrowLeft":f=Math.max(0,a-1),m="backward";break;case"ArrowRight":f=Math.min(i,a+1),m="forward";break;case"Home":case"End":{let p=r.lines[u(a)];f=e.key==="Home"?p.styleMap.flatStart:p.styleMap.flatStart+p.graphemes.length,m=e.key==="Home"?"backward":"forward";break}case"ArrowUp":case"ArrowDown":{let p=u(a),b=e.key==="ArrowUp"?p-1:p+1;if(b<0||b>=r.lines.length)return null;f=d(b,h(p,a)),m=e.key==="ArrowUp"?"backward":"forward";break}default:return null}return e.shiftKey?[c(Math.min(l,f)),c(Math.max(l,f)),m]:[c(f),c(f),"none"]}dispose(){this.offDocEvents(),this.onSelectionChange&&document.removeEventListener("selectionchange",this.onSelectionChange),this.blinkTimer!==null&&window.clearInterval(this.blinkTimer),this.textarea?.remove(),this.textarea=null}};var Tm=(n,e={})=>{let t=n.getContext("webgl2",{alpha:!0,premultipliedAlpha:!0,antialias:!0,stencil:!0,preserveDrawingBuffer:!0,powerPreference:"high-performance"});if(!t)return null;let r=a=>{a.preventDefault(),e.onLost?.()},o=()=>e.onRestored?.();n.addEventListener("webglcontextlost",r),n.addEventListener("webglcontextrestored",o);let i=t.getExtension("WEBGL_debug_renderer_info"),s=i?String(t.getParameter(i.UNMASKED_RENDERER_WEBGL)):"unknown";return{gl:t,capabilities:{maxTextureSize:t.getParameter(t.MAX_TEXTURE_SIZE),maxTextureUnits:t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS),renderer:s},dispose:()=>{n.removeEventListener("webglcontextlost",r),n.removeEventListener("webglcontextrestored",o)}}};var Ks=n=>n.trim().replace(/^['"]|['"]$/g,"").toLowerCase(),Em=n=>{let e=new Set;for(let t of n){let r=Ks(t?.family??"");r&&e.add(r)}return e},w0=n=>{let e=new Set,t=o=>{if(!(typeof o!="string"||!o))for(let i of o.split(",")){let s=Ks(i);s&&e.add(s)}};t(n.raw.fontFamily);let r=n.raw.styles;if(r&&typeof r=="object"){for(let o of Object.values(r))if(!(!o||typeof o!="object"))for(let i of Object.values(o))i&&typeof i=="object"&&t(i.fontFamily)}return e},Cm=(n,e)=>{let t=[],r=o=>{for(let i of o)if(i instanceof Se){for(let s of w0(i))if(e.has(s)){t.push(i);break}}else i instanceof J&&r(i.children)};return r(n),t};var Qs=class{constructor(e,t,r,o){this.host=e;this.textRenderer=t;this.glyphAtlas=r;this.renderer=o}host;textRenderer;glyphAtlas;renderer;pendingSettle=new Set;invalidateNodeTextBakes(e){this.host.engineDisposed||(this.textRenderer.invalidateNodeBakes(e),e.markRenderDirty(),this.host.requestRenderAll())}handleFontsLoaded(e){if(this.host.engineDisposed||this.host.engineContextLost)return;let t=Em(e);t.size===0||!this.invalidateTextCachesFor(t)||(this.glyphAtlas.reset(),this.host.requestRenderAll(),this.host.render())}invalidateTextCachesFor(e){let t=Cm(this.host.document.nodes,e);if(t.length===0)return!1;for(let r of t)r.invalidateTextLayout(),this.textRenderer.invalidateNodeBakes(r);return nh(),this.renderer.invalidateTextDerivedBakes(),!0}queueSettle(e){if(!(this.host.engineDisposed||e.length===0))for(let t of e)this.pendingSettle.add(t)}consumePendingSettle(){if(this.pendingSettle.size===0)return;let e=new Set(this.pendingSettle);this.pendingSettle.clear(),this.invalidateTextCachesFor(e)}};var Pn=class{_value=0;_lastReason="";get value(){return this._value}get lastReason(){return this._lastReason}bump(e){this._value++,this._lastReason=e}};var pt=1024,T0=2,E0=256,Ot=n=>{let e=[.5,1,2,4];for(let t of e)if(n<=t+1e-6)return t;return e[e.length-1]},C0=256,Js=(n,e)=>{let t=Math.max(6,Math.ceil(n*e)),r=Math.max(C0,Math.ceil(n));return t<=r?{rs:t,scale:e}:{rs:r,scale:r/Math.max(1,n)}},Zs=class{gl;pages=new Map;currentPage=null;nextPageIndex=0;frameStamp=0;cells=new Map;tmpCanvas;disposed=!1;pageCap=12;pendingTrim=!1;_generation=0;provisionalFaces=new Map;faceLoads=new Map;onCellsInvalidated;onProvisionalSettled;detachFontsListener=null;epoch;constructor(e,t,r,o=new Pn){this.gl=e,this.onCellsInvalidated=t,this.onProvisionalSettled=r,this.epoch=o,this.tmpCanvas=document.createElement("canvas"),this.tmpCanvas.width=8,this.tmpCanvas.height=8;let i=this.fontSet();if(i&&typeof i.addEventListener=="function"){let s=()=>this.dropProvisionalCells();i.addEventListener("loadingdone",s),this.detachFontsListener=()=>i.removeEventListener("loadingdone",s)}}fontSet(){return typeof document>"u"?null:document.fonts??null}isFacePending(e,t){let r=this.fontSet();if(!r||typeof r.check!="function")return!1;try{if(!r.check(e))return!0;let o=t.fontFamily?.trim().replace(/^['"]|['"]$/g,"")??"";if(!o||o.includes(",")||il.has(o.toLowerCase())||typeof r.forEach!="function")return!1;let i=!1;return r.forEach(s=>{i||typeof s?.family!="string"||(s.family===o||s.family.toLowerCase()===o.toLowerCase())&&(i=!0)}),!i}catch{return!1}}kickFaceLoad(e){if(this.faceLoads.has(e))return;let t=this.fontSet();if(!t||typeof t.load!="function")return;let r={};this.faceLoads.set(e,r);let o=()=>{this.faceLoads.get(e)===r&&this.faceLoads.delete(e)};try{t.load(e).then(o,o)}catch{o()}}dropProvisionalCells(){if(!(this.disposed||this.provisionalFaces.size===0)){for(let e of this.provisionalFaces.values())for(let t of e.keys)this.cells.delete(t);this.provisionalFaces.clear(),this.onCellsInvalidated?.()}}markFrame(){this.pendingTrim&&this.trimUnusedPages(),this.frameStamp++,this.settleProvisionalCells()}keepPagesForRetainedFrame(){for(let e of this.pages.values())e.lastFrame=this.frameStamp}trimUnusedPages(){let e=[...this.pages.values()].filter(r=>r.lastFrame<this.frameStamp).sort((r,o)=>r.lastFrame-o.lastFrame),t=!1;for(let r of e){if(this.pages.size<=this.pageCap)break;this.gl.deleteTexture(r.texture),this.pages.delete(r.index),this.currentPage===r&&(this.currentPage=null),t=!0}if(this.pendingTrim=this.pages.size>this.pageCap,!!t){for(let[r,o]of this.cells)this.pages.has(o.pageIndex)||this.cells.delete(r);for(let[r,o]of this.provisionalFaces){for(let i of o.keys)this.cells.has(i)||o.keys.delete(i);o.keys.size===0&&this.provisionalFaces.delete(r)}this._generation++,this.epoch.bump("atlas-trim")}}settleProvisionalCells(){if(this.disposed||this.provisionalFaces.size===0)return;let e=!1,t=new Set;for(let[r,o]of this.provisionalFaces)if(!this.isFacePending(r,o.style)){for(let s of o.keys)this.cells.delete(s);this.provisionalFaces.delete(r),e=!0;let i=Ks(o.style.fontFamily??"");i&&t.add(i)}e&&(this.onCellsInvalidated?.(),t.size>0&&this.onProvisionalSettled?.([...t]))}reset(){let e=this.pages.size>0;if(!this.disposed&&e)for(let t of this.pages.values())this.gl.deleteTexture(t.texture);this.pages.clear(),this.currentPage=null,this.pendingTrim=!1,this.cells.clear(),this.provisionalFaces.clear(),e&&(this._generation++,this.epoch.bump("atlas-reset"),Wn()&&console.warn("[retained] GlyphAtlas.reset → generation",this._generation,new Error("reset 调用栈取证").stack))}get generation(){return this._generation}stats(){return{pages:this.pages.size,cells:this.cells.size,pageCap:this.pageCap,pendingReset:!1,pendingTrim:this.pendingTrim,generation:this._generation}}get(e,t,r,o=null){if(this.disposed||r===" "||r===""||r===`
|
|
9
|
-
`||r===" ")return null;let i=`${e.fontFamily}|${e.fontWeight??""}|${e.fontStyle??""}|${t}|${r}`;o&&(i+=`|S${o.width}|${o.lineJoin??""}|${o.lineCap??""}|${o.miterLimit??""}`);let s=this.cells.get(i);if(s)return this.pages.get(s.pageIndex).lastFrame=this.frameStamp,s;let a=Me(e,t),l=this.isFacePending(a,e);l&&this.kickFaceLoad(a);let
|
|
1
|
+
var _e={enabled:!1,metrics:new Map,counters:new Map,sampleRate:1,reportIntervalMs:5e3,reportTimer:null},pu=()=>performance.now(),ub=()=>typeof window>"u"?!1:window.location.search.includes("canvasPerf=1"),hb=n=>{let e=_e.metrics.get(n);return e||(e={count:0,total:0,max:0,last:0},_e.metrics.set(n,e)),e},db=(n,e)=>e>0?n/e:0,Ha=()=>[..._e.metrics.entries()].map(([n,e])=>({name:n,count:e.count,totalMs:Number(e.total.toFixed(2)),avgMs:Number(db(e.total,e.count).toFixed(3)),maxMs:Number(e.max.toFixed(3)),lastMs:Number(e.last.toFixed(3))})).sort((n,e)=>e.totalMs-n.totalMs),Ga=()=>[..._e.counters.entries()].map(([n,e])=>({name:n,count:e})).sort((n,e)=>e.count-n.count),fb=()=>({type:"canvas-perf",timestamp:new Date().toISOString(),enabled:_e.enabled,metrics:Ha(),counters:Ga()}),bu=()=>JSON.stringify(fb()),mb=()=>{let n=Ha(),e=Ga(),t=["[canvas-perf] report"];if(n.length){t.push("metrics:");for(let r of n)t.push(`- ${r.name}: count=${r.count}, totalMs=${r.totalMs}, avgMs=${r.avgMs}, maxMs=${r.maxMs}, lastMs=${r.lastMs}`)}else t.push("metrics: none");if(e.length){t.push("counters:");for(let r of e)t.push(`- ${r.name}: count=${r.count}`)}else t.push("counters: none");return t.join(`
|
|
2
|
+
`)},xu=()=>{let n=bu();if(!_e.enabled)return n;let e=Ha(),t=Ga();return console.info(n),console.groupCollapsed("[canvas-perf] report details"),e.length?console.table(e):console.log("no timing metrics"),t.length&&console.table(t),console.groupEnd(),n},pb=()=>{typeof window>"u"||!_e.enabled||_e.reportTimer!=null||(_e.reportTimer=window.setInterval(xu,_e.reportIntervalMs))},bb=()=>{_e.reportTimer!=null&&(window.clearInterval(_e.reportTimer),_e.reportTimer=null)},Wa=n=>{_e.enabled=n,n?(pb(),console.info("[canvas-perf] enabled")):(bb(),console.info("[canvas-perf] disabled"))},gu=()=>_e.enabled,xb=()=>{_e.metrics.clear(),_e.counters.clear()},yu=(n,e=1)=>{_e.enabled&&_e.counters.set(n,(_e.counters.get(n)||0)+e)},ii=(n,e)=>{if(!_e.enabled)return;let t=hb(n);t.count+=1,t.total+=e,t.max=Math.max(t.max,e),t.last=e},Xa=(n,e)=>{if(!_e.enabled)return e();let t=pu();try{return e()}finally{ii(n,pu()-t)}};var Su=()=>{typeof window>"u"||window.__YFT_CANVAS_PERF__||(window.__YFT_CANVAS_PERF__={enable:()=>Wa(!0),disable:()=>Wa(!1),report:xu,reportJson:bu,reportText:mb,reset:xb,mark:yu,time:Xa,isEnabled:gu},ub()&&Wa(!0))};var On=class{_handlers=new Map;on(e,t){let r=this._handlers.get(e);r||(r=new Set,this._handlers.set(e,r));let o=t;return r.add(o),()=>this.off(e,o)}once(e,t){let r=t,o=(...i)=>{this.off(e,o),r(...i)};return this.on(e,o)}off(e,t){if(!t){this._handlers.delete(e);return}this._handlers.get(e)?.delete(t)}fire(e,...t){let r=this._handlers.get(e);if(!(!r||r.size===0))for(let o of[...r])o(...t)}clear(){this._handlers.clear()}};var mr=n=>n*Math.PI/180,V=(n,e,t=!1)=>[n[0]*e[0]+n[2]*e[1],n[1]*e[0]+n[3]*e[1],n[0]*e[2]+n[2]*e[3],n[1]*e[2]+n[3]*e[3],t?0:n[0]*e[4]+n[2]*e[5]+n[4],t?0:n[1]*e[4]+n[3]*e[5]+n[5]],ve=n=>{let e=1/(n[0]*n[3]-n[1]*n[2]),t=[e*n[3],-e*n[1],-e*n[2],e*n[0],0,0],r=t[0]*n[4]+t[2]*n[5],o=t[1]*n[4]+t[3]*n[5];return t[4]=-r,t[5]=-o,t},Q=(n,e,t,r=!1)=>({x:n[0]*e+n[2]*t+(r?0:n[4]),y:n[1]*e+n[3]*t+(r?0:n[5])}),gb=n=>n[0]===1&&n[1]===0&&n[2]===0&&n[3]===1&&n[4]===0&&n[5]===0,si=n=>{if(typeof n=="number")return n-.5;switch(n){case"left":case"top":return-.5;case"right":case"bottom":return .5;default:return 0}},yb=n=>{let e=mr(n),t=Math.cos(e),r=Math.sin(e);return[t,r,-r,t,0,0]},vu=n=>{let{scaleX:e=1,scaleY:t=1,flipX:r=!1,flipY:o=!1,skewX:i=0,skewY:s=0}=n,a=[r?-e:e,0,0,o?-t:t,0,0];return i&&(a=V(a,[1,0,Math.tan(mr(i)),1,0,0],!0)),s&&(a=V(a,[1,Math.tan(mr(s)),0,1,0,0],!0)),a},kt=n=>{let{translateX:e=0,translateY:t=0,angle:r=0}=n,o=[1,0,0,1,e,t];r&&(o=V(o,yb(r)));let i=vu(n);return gb(i)||(o=V(o,i)),o},Sb=(n,e,t)=>{let r=n/2,o=e/2,i=[],s=[];for(let[a,l]of[[-r,-o],[r,-o],[-r,o],[r,o]]){let u=Q(t,a,l,!0);i.push(u.x),s.push(u.y)}return{x:Math.max(...i)-Math.min(...i),y:Math.max(...s)-Math.min(...s)}},ai=n=>{let{width:e=0,height:t=0,scaleX:r=1,scaleY:o=1,skewX:i=0,skewY:s=0,strokeWidth:a=0,strokeUniform:l}=n,u=l?0:a,c=l?a:0,h=e+u,d=t+u,f;return i===0&&s===0?f={x:h*r,y:d*o}:f=Sb(h,d,vu(n)),{x:f.x+c,y:f.y+c}},Bn=n=>{let e=Yt(n);return kt({...n,translateX:e.x,translateY:e.y})},Yt=n=>{let e=ai(n),t=-si(n.originX??"left")*e.x,r=-si(n.originY??"top")*e.y,o=n.angle??0;if(o){let i=mr(o),s=Math.cos(i),a=Math.sin(i),l=t*s-r*a,u=t*a+r*s;t=l,r=u}return{x:(n.left??0)+t,y:(n.top??0)+r}},xe=(n,e)=>{let t=ai(n),r=-si(n.originX??"left")*t.x,o=-si(n.originY??"top")*t.y,i=n.angle??0;if(i){let s=mr(i),a=Math.cos(s),l=Math.sin(s),u=r*a-o*l,c=r*l+o*a;r=u,o=c}return{x:e.x-r,y:e.y-o}},vb=n=>{let e=a=>a*180/Math.PI,t=e(Math.atan2(n[1],n[0])),r=n[0]*n[0]+n[1]*n[1],o=Math.sqrt(r),i=r===0?0:(n[0]*n[3]-n[2]*n[1])/o,s=r===0?0:e(Math.atan2(n[0]*n[2]+n[1]*n[3],r));return{angle:t,scaleX:o,scaleY:i,skewX:s,skewY:0,center:{x:n[4],y:n[5]}}},za=n=>{let e=Yt(n),t=mr(n.angle??0),r=Math.cos(t),o=Math.sin(t),i=ai(n),s=i.x/2,a=i.y/2,l=(u,c)=>({x:e.x+r*u-o*c,y:e.y+o*u+r*c});return{tl:l(-s,-a),tr:l(s,-a),br:l(s,a),bl:l(-s,a)}},Wn=n=>{let e=[n.tl.x,n.tr.x,n.br.x,n.bl.x],t=[n.tl.y,n.tr.y,n.br.y,n.bl.y],r=Math.min(...e),o=Math.min(...t);return{left:r,top:o,right:Math.max(...e),bottom:Math.max(...t),width:Math.max(...e)-r,height:Math.max(...t)-o}},Kr=(n,e,t,r)=>{let o=Math.max(1,e*r),i=Math.max(1,t*r),s=[2/o,0,0,-2/i,-1,1];return V(s,V([r,0,0,r,0,0],n))};var ht=(n,e=!1)=>{if(typeof window>"u")return e;let t=new URLSearchParams(window.location.search).get(n);if(t==="1"||t==="true")return!0;if(t==="0"||t==="false")return!1;let r=window.localStorage.getItem(`engine.${n}`);return r==="1"?!0:r==="0"?!1:e},wu=()=>ht("gpuShadow",!0),Ya=()=>ht("gpuPsdShadow",!0),Ua=()=>ht("gpuPsdFill",!0),Tu=()=>ht("stencilClip",!0),$a=()=>{if(typeof window>"u")return!0;let n=new URLSearchParams(window.location.search).get("snapGuide");return!(n==="0"||n==="false")},Eu=()=>ht("arcGlyph",!0),wb=()=>ht("export",!0),ja=()=>ht("retained",!0),Hn=()=>ht("retainedDebug",!1),li=()=>ht("sdfDash",!0),Cu=()=>ht("sdfPolygon",!0),Mu=()=>ht("sdfLineDeco",!0),Tb=()=>ht("svgexport",!0);var Eb={transparent:"#0000",aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"},Ru=n=>{if(n.length===3||n.length===4){let e=parseInt(n[0]+n[0],16)/255,t=parseInt(n[1]+n[1],16)/255,r=parseInt(n[2]+n[2],16)/255,o=n.length===4?parseInt(n[3]+n[3],16)/255:1;return[e,t,r,o]}if(n.length===6||n.length===8){let e=parseInt(n.slice(0,2),16)/255,t=parseInt(n.slice(2,4),16)/255,r=parseInt(n.slice(4,6),16)/255,o=n.length===8?parseInt(n.slice(6,8),16)/255:1;return[e,t,r,o]}return[0,0,0,0]},Cb=Object.fromEntries(Object.entries(Eb).map(([n,e])=>[n,Ru(e.slice(1))])),Qr=n=>Math.min(1,Math.max(0,n)),Mb=65536,ci=new Map,ee=n=>{if(!n)return[0,0,0,0];if(Array.isArray(n))return n;if(typeof n!="string")return[0,0,0,0];let e=ci.get(n);if(e)return e;let t=Rb(n);return ci.size>=Mb&&ci.clear(),ci.set(n,t),t},Rb=n=>{let e=n.trim().toLowerCase(),t=Cb[e];if(t)return t;if(e.startsWith("#"))return Ru(e.slice(1));let r=e.match(/^(rgba?|hsla?)\(([^)]+)\)$/);if(r){let o=r[2].split(/[\s,/]+/).filter(Boolean);if(r[1].startsWith("rgb")&&o.length>=3){let i=s=>s.endsWith("%")?parseFloat(s)/100*255:parseFloat(s);return[Qr(i(o[0])/255),Qr(i(o[1])/255),Qr(i(o[2])/255),o[3]!==void 0?Qr(parseFloat(o[3])):1]}if(r[1].startsWith("hsl")&&o.length>=3){let i=parseFloat(o[0])/360,s=parseFloat(o[1])/100,a=parseFloat(o[2])/100,l=(d,f,m)=>(m<0&&(m+=1),m>1&&(m-=1),m<1/6?d+(f-d)*6*m:m<1/2?f:m<2/3?d+(f-d)*(2/3-m)*6:d),u=a<.5?a*(1+s):a+s-a*s,c=2*a-u,h=o[3]!==void 0?Qr(parseFloat(o[3])):1;return[l(c,u,i+1/3),l(c,u,i),l(c,u,i-1/3),h]}}return[0,0,0,0]};var Gn=n=>{if(!n||typeof n!="object"||Array.isArray(n))return null;let e=n,t=e.type;if(typeof t!="string"||t==="pattern")return null;let r=t==="linear"?"linear":"radial",o=e.coords??{},i=Array.isArray(e.colorStops)?e.colorStops:[],s=[];for(let a of i){if(!a||typeof a!="object")continue;let l=a,u=ee(l.color),c=typeof l.opacity=="number"?l.opacity:1;s.push({offset:Number(l.offset)||0,color:[u[0],u[1],u[2],u[3]*c]})}return s.length===0?null:(s.sort((a,l)=>a.offset-l.offset),{kind:r,x1:Number(o.x1)||0,y1:Number(o.y1)||0,x2:Number(o.x2)||0,y2:Number(o.y2)||0,r1:Math.max(0,Number(o.r1)||0),r2:Math.max(0,Number(o.r2)||0),stops:s,offsetX:Number(e.offsetX)||0,offsetY:Number(e.offsetY)||0,gradientUnits:e.gradientUnits==="percentage"?"percentage":"pixels",gradientTransform:Array.isArray(e.gradientTransform)&&e.gradientTransform.length===6?[...e.gradientTransform]:null})},ui=(n,e,t)=>{let r=[1,0,0,1,-e/2+n.offsetX,-t/2+n.offsetY];return n.gradientUnits==="percentage"&&(r=V(r,[e,0,0,t,0,0])),n.gradientTransform&&(r=V(r,n.gradientTransform)),r};var Pu=(n,e)=>{let t=n.x2-n.x1,r=n.y2-n.y1,o=t*t+r*r;return o<=0?0:((e.x-n.x1)*t+(e.y-n.y1)*r)/o},ku=(n,e)=>{let t=n.x2-n.x1,r=n.y2-n.y1,o=n.r2-n.r1,i=e.x-n.x1,s=e.y-n.y1,a=t*t+r*r-o*o,l=2*(-(t*i+r*s)-n.r1*o),u=i*i+s*s-n.r1*n.r1;if(Math.abs(a)<1e-9)return Math.abs(l)>1e-9?-u/l:0;let c=Math.max(0,l*l-4*a*u);return(-l-Math.sqrt(c))/(2*a)},hi=(n,e=512)=>{let t=new Uint8Array(e*4),r=n.stops,o=i=>Math.round(Math.min(255,Math.max(0,i*255)));for(let i=0;i<e;i++){let s=i/(e-1),a;if(s<=r[0].offset)a=r[0].color;else if(s>=r[r.length-1].offset)a=r[r.length-1].color;else{let l=r[0],u=r[1];for(let h=0;h<r.length-1;h++)if(s>=r[h].offset&&s<=r[h+1].offset){l=r[h],u=r[h+1];break}let c=u.offset===l.offset?0:(s-l.offset)/(u.offset-l.offset);a=[l.color[0]+(u.color[0]-l.color[0])*c,l.color[1]+(u.color[1]-l.color[1])*c,l.color[2]+(u.color[2]-l.color[2])*c,l.color[3]+(u.color[3]-l.color[3])*c]}t[i*4]=o(a[0]),t[i*4+1]=o(a[1]),t[i*4+2]=o(a[2]),t[i*4+3]=o(a[3])}return t},di=n=>{let e=r=>String(Math.round(r*1e4)/1e4),t=n.stops.map(r=>`${e(r.offset)}:${r.color.map(o=>e(o)).join(",")}`).join(";");return[n.kind,e(n.x1),e(n.y1),e(n.x2),e(n.y2),e(n.r1),e(n.r2),t,e(n.offsetX),e(n.offsetY),n.gradientUnits,n.gradientTransform?n.gradientTransform.map(e).join(","):""].join("|")};var Pb=["repeat","repeat-x","repeat-y","no-repeat"],fi=n=>{if(!n||typeof n!="object"||Array.isArray(n))return null;let e=n;if(e.type!=="pattern"||typeof e.source!="string"||!e.source)return null;let t=Pb.includes(e.repeat)?e.repeat:"repeat";return{kind:"pattern",src:e.source,repeat:t,offsetX:Number(e.offsetX)||0,offsetY:Number(e.offsetY)||0,patternTransform:Array.isArray(e.patternTransform)&&e.patternTransform.length===6?[...e.patternTransform]:null,crossOrigin:typeof e.crossOrigin=="string"?e.crossOrigin:null}},mi=(n,e,t)=>{let r=[1,0,0,1,-e/2+n.offsetX,-t/2+n.offsetY];return n.patternTransform&&(r=V(r,n.patternTransform)),r},Au=n=>[n==="repeat"||n==="repeat-x",n==="repeat"||n==="repeat-y"];var L={TEXTBOX:"textbox",TEXT:"text",ITEXT:"i-text",INPUTTEXT:"itext",ARCHTEXT:"archtext",WAISTTEXT:"waisttext",FLAGTEXT:"flagtext",ARCTEXT:"arctext",CIRCLETEXT:"circletext",SCROLLTEXT:"scrolltext",TEXTIMAGE:"textimage",IMAGE:"image",SVGIMAGE:"svgimage",CROPIMAGE:"cropimage",ECHART:"echart",FABRIC_ECHART:"fabricechart",QRCODE:"qrcode",BARCODE:"barcode",MASK:"mask",PATH:"path",RECT:"rect",FABRICRECT:"fabricrect",LINE:"line",ARROW:"arrow",POLYLINE:"polyline",POLYGON:"polygon",ELLIPSE:"ellipse",CIRCLE:"circle",TRIANGLE:"triangle",TABLE:"table",GROUP:"group",ACTIVE_SELECTION:"activeselection",PUZZLE:"puzzle",GIF:"gif",VIDEO:"video",DIMENSION:"dimension",REFERENCELINE:"referenceline"},se=n=>{let e=n?.type;return typeof e=="string"?e.toLowerCase():""},sn=new Set([L.TEXTBOX,L.INPUTTEXT,L.ITEXT,L.TEXT,L.ARCHTEXT,L.WAISTTEXT,L.FLAGTEXT,L.ARCTEXT,L.CIRCLETEXT,L.SCROLLTEXT,L.TEXTIMAGE]),dt=new Set([L.IMAGE,L.SVGIMAGE,L.CROPIMAGE,L.QRCODE,L.BARCODE,L.ECHART,L.FABRIC_ECHART]),Xn=new Set([L.ELLIPSE,L.CIRCLE,L.POLYGON,L.POLYLINE,L.PATH,L.TRIANGLE]),ft=new Set([L.LINE,L.ARROW,L.DIMENSION,L.REFERENCELINE]),zn=new Set([L.RECT,L.FABRICRECT]),ot=new Set([L.MASK]),pi=new Set([L.PUZZLE]),bi=new Set([L.GIF]),xi=new Set([L.VIDEO]);var an=1-.5522847498,Va=new Set([L.FABRICRECT]),ln=(n,e)=>typeof n=="number"&&Number.isFinite(n)?n:e,qa=(n,e,t)=>{let r=ln(n,0);return r>0?{rx:r/(ln(e,1)||1),ry:r/(ln(t,1)||1)}:null},Nu=n=>{if(!Va.has(se(n)))return;let e=qa(n.radius,n.scaleX,n.scaleY);e&&(n.rx=e.rx,n.ry=e.ry)},Lu=(n,e)=>{if(!Va.has(se(n)))return!1;let t="radius"in e,r="scaleX"in e||"scaleY"in e,o=ln(n.radius,0)>0&&("rx"in e||"ry"in e);if(!t&&!r&&!o)return!1;let i=t?e.radius:n.radius,s="scaleX"in e?e.scaleX:n.scaleX,a="scaleY"in e?e.scaleY:n.scaleY,l=qa(i,s,a);return e.rx=l?l.rx:0,e.ry=l?l.ry:0,!0},it=(n,e,t)=>{if(!(e>0)||!(t>0))return null;let r=Va.has(se(n))?qa(n.radius,n.scaleX,n.scaleY):null,o=r?r.rx:ln(n.rx,0),i=r?r.ry:ln(n.ry,0);o>0&&!(i>0)&&(i=o);let s=Math.min(o,e/2),a=Math.min(i,t/2);return s>0||a>0?{rx:s,ry:a}:null},pr=(n,e,t)=>{if(!(e>0)||!(t>0))return null;let r=Math.min(Math.max(ln(n.rx,0),ln(n.ry,0)),e/2,t/2);return r>0?r:null},Yn=(n,e,t,r,o)=>{let i=Math.max(0,e),s=Math.max(0,t),a=Math.min(Math.max(0,r),i/2),l=Math.min(Math.max(0,o),s/2),u=-i/2,c=-s/2,h=a!==0||l!==0;n.beginPath(),n.moveTo(u+a,c),n.lineTo(u+i-a,c),h&&n.bezierCurveTo(u+i-an*a,c,u+i,c+an*l,u+i,c+l),n.lineTo(u+i,c+s-l),h&&n.bezierCurveTo(u+i,c+s-an*l,u+i-an*a,c+s,u+i-a,c+s),n.lineTo(u+a,c+s),h&&n.bezierCurveTo(u+an*a,c+s,u,c+s-an*l,u,c+s-l),n.lineTo(u,c+l),h&&n.bezierCurveTo(u,c+an*l,u+an*a,c,u+a,c),n.closePath()},Iu=(n,e,t,r)=>{let o=Math.max(0,n),i=Math.max(0,e);if(!(o>0)||!(i>0))return null;let s=Math.min(Math.max(0,t),o/2),a=Math.min(Math.max(0,r),i/2);if(!(s>0)&&!(a>0))return null;let l=Math.max(2,Math.min(16,Math.ceil((s+a)*.6))),u=[[o/2-s,-i/2+a,s,a,-Math.PI/2],[o/2-s,i/2-a,s,a,0],[-o/2+s,i/2-a,s,a,Math.PI/2],[-o/2+s,-i/2+a,s,a,Math.PI]],c=[0,0];for(let[f,m,p,b,x]of u)for(let g=0;g<l;g++){let y=x+g/l*(Math.PI/2);c.push(f+p*Math.cos(y),m+b*Math.sin(y))}let h=c.length/2-1,d=new Uint32Array(h*3);for(let f=0;f<h;f++)d[f*3]=0,d[f*3+1]=1+f,d[f*3+2]=1+(f+1)%h;return{verts:new Float32Array(c),triangles:d}};import kb from"rbush";var Ne=1e-12,Ab=96,gi=(n,e,t,r,o,i)=>(t-n)*(i-e)-(r-e)*(o-n),Ka=(n,e,t,r)=>{if(Math.abs(r)>Ne)return!1;let o=e.x-n.x,i=e.y-n.y,s=o*o+i*i;if(s<Ne)return!0;let a=(t.x-n.x)*o+(t.y-n.y)*i;return a>=-Ne&&a<=s+Ne},br=n=>{let e=0;for(let t=0;t<n.length;t++){let r=n[t],o=n[(t+1)%n.length];e+=r.x*o.y-o.x*r.y}return e/2},_u=(n,e,t,r,o)=>{let i=n[e];if(Math.abs(i.x-t.x)<Ne&&Math.abs(i.y-t.y)<Ne||Math.abs(i.x-r.x)<Ne&&Math.abs(i.y-r.y)<Ne||Math.abs(i.x-o.x)<Ne&&Math.abs(i.y-o.y)<Ne)return!1;let s=gi(t.x,t.y,r.x,r.y,i.x,i.y),a=gi(r.x,r.y,o.x,o.y,i.x,i.y),l=gi(o.x,o.y,t.x,t.y,i.x,i.y);return s>Ne&&a>Ne&&l>Ne||s<-Ne&&a<-Ne&&l<-Ne?!0:Ka(t,r,i,s)||Ka(r,o,i,a)||Ka(o,t,i,l)},Qa=n=>{let e=n.length;if(e<3)return[];let t=br(n);if(Math.abs(t)<Ne)return[];let r=new Array(e);for(let d=0;d<e;d++)r[d]=t>0?d:e-1-d;let o=[],i=r.length,s=i*i+16,a=0,l=null,u=null,c=null;if(e>=Ab){l=new kb,u=new Array(e);for(let d=0;d<e;d++){let f=n[d];u[d]={minX:f.x,minY:f.y,maxX:f.x,maxY:f.y,v:d}}l.load(u),c=new Uint8Array(e).fill(1)}let h=0;for(;i>3&&s-- >0&&(a>=i&&(a=0),!(++h>i));){let d=r[a],f=r[(a+1)%i],m=r[(a+2)%i],p=n[d],b=n[f],x=n[m],g=gi(p.x,p.y,b.x,b.y,x.x,x.y);if(g>Ne){let y=!1;if(l&&u){let v=Math.min(p.x,b.x,x.x)-Ne,S=Math.max(p.x,b.x,x.x)+Ne,w=Math.min(p.y,b.y,x.y)-Ne,R=Math.max(p.y,b.y,x.y)+Ne,P=l.search({minX:v,minY:w,maxX:S,maxY:R});for(let T=0;T<P.length;T++){let C=P[T].v;if(c[C]&&!(C===d||C===f||C===m)&&_u(n,C,p,b,x)){y=!0;break}}}else for(let v=3;v<i;v++){let S=r[(a+v)%i];if(_u(n,S,p,b,x)){y=!0;break}}if(!y){o.push(d,f,m);let v=r.splice((a+1)%i,1)[0];i--,c&&(c[v]=0),h=0;continue}}else if(g>=-Ne){let y=r.splice((a+1)%i,1)[0];i--,c&&(c[y]=0),h=0;continue}a++}if(i>3)for(let d=1;d<i-1;d++)o.push(r[0],r[d],r[d+1]);else i===3&&o.push(r[0],r[1],r[2]);return o};var yi=Math.PI,Nb=Math.PI/180,Xu=Math.PI/2,Ja=n=>{if(n===0)return 1;switch(Math.abs(n)/Xu){case 1:case 3:return 0;case 2:return-1}return Math.cos(n)},el=n=>{if(n===0)return 0;let e=n/Xu,t=Math.sign(n);switch(e){case 1:return t;case 2:return 0;case 3:return-t}return Math.sin(n)},Lb=/[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/gi,Ib=/[mzlhvcsqta][^mzlhvcsqta]*/gi,Un=/\s*,?\s*/,Zr="([-+]?(?:\\d*\\.\\d+|\\d+\\.?)(?:[eE][-+]?\\d+)?)",Za=new RegExp(`${Un.source}${Zr}${Un.source}${Zr}${Un.source}${Zr}${Un.source}([01])${Un.source}([01])${Un.source}${Zr}${Un.source}${Zr}`,"g"),zu={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},_b={m:"l",M:"L"},Db=n=>{let e=[],t=n.match(Ib)??[];for(let r of t){let o=r[0];if(o==="z"||o==="Z"){e.push([o]);continue}let i=zu[o.toLowerCase()],s=[];if(o==="a"||o==="A"){Za.lastIndex=0;for(let a=Za.exec(r);a;a=Za.exec(r))s=s.concat(a.slice(1))}else s=r.match(Lb)??[];for(let a=0;a<s.length;a+=i){let l=new Array(i),u=_b[o];l[0]=a>0&&u?u:o;for(let c=0;c<i;c++)l[c+1]=parseFloat(s[a+c]);e.push(l)}}return e},Du=(n,e,t,r)=>{let o=Math.atan2(e,n),i=Math.atan2(r,t);return i>=o?i-o:2*yi-(o-i)},Fb=(n,e,t,r,o,i,s,a,l,u,c)=>{let h=Ja(n),d=el(n),f=Ja(e),m=el(e),p=t*o*f-r*i*m+s,b=r*o*f+t*i*m+a,x=u+l*(-t*o*d-r*i*h),g=c+l*(-r*o*d+t*i*h),y=p+l*(t*o*m+r*i*f),v=b+l*(r*o*m-t*i*f);return["C",x,g,y,v,p,b]},Ob=(n,e,t,r,o,i,s)=>{if(t===0||r===0)return[];let a=0,l=0,u=0,c=s*Nb,h=el(c),d=Ja(c),f=.5*(-d*n-h*e),m=.5*(-d*e+h*n),p=t**2,b=r**2,x=m**2,g=f**2,y=p*b-p*x-b*g,v=Math.abs(t),S=Math.abs(r);if(y<0){let G=Math.sqrt(1-y/(p*b));v*=G,S*=G}else u=(o===i?-1:1)*Math.sqrt(y/(p*x+b*g));let w=u*v*m/S,R=-u*S*f/v,P=d*w-h*R+n*.5,T=h*w+d*R+e*.5,C=Du(1,0,(f-w)/v,(m-R)/S),E=Du((f-w)/v,(m-R)/S,(-f-w)/v,(-m-R)/S);i===0&&E>0?E-=2*yi:i===1&&E<0&&(E+=2*yi);let M=Math.ceil(Math.abs(E/yi*2)),k=[],A=E/M,O=8/3*Math.sin(A/4)*Math.sin(A/4)/Math.sin(A/2),F=C+A;for(let G=0;G<M;G++)k[G]=Fb(C,F,d,h,v,S,P,T,O,a,l),a=k[G][5],l=k[G][6],C=F,F+=A;return k},Bb=(n,e,t,r,o,i,s,a,l)=>Ob(a-n,l-e,t,r,i,s,o).map(u=>(u[1]=u[1]+n,u[2]=u[2]+e,u[3]=u[3]+n,u[4]=u[4]+e,u[5]=u[5]+n,u[6]=u[6]+e,u)),Fu=n=>{let e=0,t=0,r=0,o=0,i=[],s,a=0,l=0;for(let u of n){let c=[...u],h;switch(c[0]){case"l":c[1]+=e,c[2]+=t;case"L":e=c[1],t=c[2],h=["L",e,t];break;case"h":c[1]+=e;case"H":e=c[1],h=["L",e,t];break;case"v":c[1]+=t;case"V":t=c[1],h=["L",e,t];break;case"m":c[1]+=e,c[2]+=t;case"M":e=c[1],t=c[2],r=c[1],o=c[2],h=["M",e,t];break;case"c":c[1]+=e,c[2]+=t,c[3]+=e,c[4]+=t,c[5]+=e,c[6]+=t;case"C":a=c[3],l=c[4],e=c[5],t=c[6],h=["C",c[1],c[2],a,l,e,t];break;case"s":c[1]+=e,c[2]+=t,c[3]+=e,c[4]+=t;case"S":s==="C"?(a=2*e-a,l=2*t-l):(a=e,l=t),e=c[3],t=c[4],h=["C",a,l,c[1],c[2],e,t],a=h[3],l=h[4];break;case"q":c[1]+=e,c[2]+=t,c[3]+=e,c[4]+=t;case"Q":a=c[1],l=c[2],e=c[3],t=c[4],h=["Q",a,l,e,t];break;case"t":c[1]+=e,c[2]+=t;case"T":s==="Q"?(a=2*e-a,l=2*t-l):(a=e,l=t),e=c[1],t=c[2],h=["Q",a,l,e,t];break;case"a":c[6]+=e,c[7]+=t;case"A":for(let d of Bb(e,t,c[1],c[2],c[3],c[4],c[5],c[6],c[7]))i.push(d);e=c[6],t=c[7];break;case"z":case"Z":e=r,t=o,h=["Z"];break}h&&(i.push(h),s=h[0])}return i},Ce=n=>{if(typeof n=="string"){if(!n)return null;let e=Db(n);return e.length>0?Fu(e):null}if(Array.isArray(n)){if(n.length===0)return null;let e=[];for(let t of n){if(!Array.isArray(t)||typeof t[0]!="string")continue;let r=t[0].toLowerCase();(r==="z"||zu[r]!==void 0)&&e.push(t)}return e.length===0?null:Fu(e)}return null},Ou=(n,e,t,r,o,i,s,a)=>{let l=[],u=[],c=[],h=6*n-12*t+6*o,d=-3*n+9*t-9*o+3*s,f=3*t-3*n;for(let p=0;p<2;++p){if(p>0&&(h=6*e-12*r+6*i,d=-3*e+9*r-9*i+3*a,f=3*r-3*e),Math.abs(d)<1e-12){if(Math.abs(h)<1e-12)continue;let v=-f/h;0<v&&v<1&&l.push(v);continue}let b=h*h-4*f*d;if(b<0)continue;let x=Math.sqrt(b),g=(-h+x)/(2*d);0<g&&g<1&&l.push(g);let y=(-h-x)/(2*d);0<y&&y<1&&l.push(y)}let m=l.length;for(let p=0;p<m;p++){let b=l[p],x=b**3,g=3*b**2*(1-b),y=3*b*(1-b)**2,v=(1-b)**3;u.push(s*x+o*g+t*y+n*v),c.push(a*x+i*g+r*y+e*v)}return u.push(n,s),c.push(e,a),[{x:Math.min(...u),y:Math.min(...c)},{x:Math.max(...u),y:Math.max(...c)}]},Fe=n=>{let e=[],t=0,r=0,o=0,i=0;for(let c of n)switch(c[0]){case"L":o=c[1],i=c[2],e.push({x:t,y:r},{x:o,y:i});break;case"M":o=c[1],i=c[2],t=o,r=i;break;case"C":for(let h of Ou(o,i,c[1],c[2],c[3],c[4],c[5],c[6]))e.push(h);o=c[5],i=c[6];break;case"Q":for(let h of Ou(o,i,c[1],c[2],c[1],c[2],c[3],c[4]))e.push(h);o=c[3],i=c[4];break;case"Z":o=t,i=r;break}if(e.length===0)return null;let s=1/0,a=1/0,l=-1/0,u=-1/0;for(let c of e){if(!Number.isFinite(c.x)||!Number.isFinite(c.y))return null;s>c.x&&(s=c.x),a>c.y&&(a=c.y),l<c.x&&(l=c.x),u<c.y&&(u=c.y)}return{left:s,top:a,right:l,bottom:u}},Wb=(n,e,t,r,o,i,s,a)=>{let l=s-n,u=a-e,c=l*l+u*u;if(c<1e-12)return Math.hypot(t-n,r-e)+Math.hypot(o-s,i-a);let h=Math.abs(l*(r-e)-u*(t-n)),d=Math.abs(l*(i-e)-u*(o-n));return(h+d)/Math.sqrt(c)},Si=(n,e,t,r,o,i,s,a,l,u,c)=>{if(c>24){n.push({x:a,y:l});return}if(Wb(e,t,r,o,i,s,a,l)<=u){n.push({x:a,y:l});return}let h=(e+r)/2,d=(t+o)/2,f=(r+i)/2,m=(o+s)/2,p=(i+a)/2,b=(s+l)/2,x=(h+f)/2,g=(d+m)/2,y=(f+p)/2,v=(m+b)/2,S=(x+y)/2,w=(g+v)/2;Si(n,e,t,h,d,x,g,S,w,u,c+1),Si(n,S,w,y,v,p,b,a,l,u,c+1)},Yu=(n,e=.1)=>{let t=[],r=null,o=0,i=0,s=0,a=0;for(let l of n)switch(l[0]){case"M":{r&&r.length>=2&&t.push({points:r,closed:!1}),r=[{x:l[1],y:l[2]}],o=l[1],i=l[2],s=o,a=i;break}case"L":{o=l[1],i=l[2],(r??=[]).push({x:o,y:i});break}case"C":{Si(r??=[],o,i,l[1],l[2],l[3],l[4],l[5],l[6],e,0),o=l[5],i=l[6];break}case"Q":{Si(r??=[],o,i,o+2/3*(l[1]-o),i+2/3*(l[2]-i),l[3]+2/3*(l[1]-l[3]),l[4]+2/3*(l[2]-l[4]),l[3],l[4],e,0),o=l[3],i=l[4];break}case"Z":{if(r&&r.length>=2){let u=r[0],c=r[r.length-1];(Math.abs(u.x-c.x)>1e-9||Math.abs(u.y-c.y)>1e-9)&&r.push({x:u.x,y:u.y}),t.push({points:r,closed:!0})}r=null,o=s,i=a;break}}return r&&r.length>=2&&t.push({points:r,closed:!1}),t},Bu=(n,e)=>{let t=!1;for(let r=0,o=e.length-1;r<e.length;o=r++){let i=e[o],s=e[r];s.y>n.y!=i.y>n.y&&n.x<(i.x-s.x)*(n.y-s.y)/(i.y-s.y)+s.x&&(t=!t)}return t},Hb=n=>{if(n.length<3)return[];let e=n,t=e[0],r=e[e.length-1];return Math.abs(t.x-r.x)<1e-9&&Math.abs(t.y-r.y)<1e-9?e.slice(0,-1):e.slice()},Gb=(n,e,t,r)=>{let o=(e.x-n.x)*(r.y-n.y)-(e.y-n.y)*(r.x-n.x),i=(t.x-e.x)*(r.y-e.y)-(t.y-e.y)*(r.x-e.x),s=(n.x-t.x)*(r.y-t.y)-(n.y-t.y)*(r.x-t.x),a=o<-1e-12||i<-1e-12||s<-1e-12,l=o>1e-12||i>1e-12||s>1e-12;return!(a&&l)},Uu=(n,e,t,r)=>{let o=(e.x-n.x)*(r.y-t.y)-(e.y-n.y)*(r.x-t.x);if(Math.abs(o)<1e-12)return!1;let i=((t.x-n.x)*(r.y-t.y)-(t.y-n.y)*(r.x-t.x))/o,s=((t.x-n.x)*(e.y-n.y)-(t.y-n.y)*(e.x-n.x))/o;return i>1e-9&&i<1-1e-9&&s>1e-9&&s<1-1e-9},Xb=(n,e,t)=>{for(let r=0,o=e.length-1;r<e.length;o=r++){let i=e[o],s=e[r],a=s.x-i.x,l=s.y-i.y,u=a*a+l*l;if(u===0){if(Math.hypot(n.x-i.x,n.y-i.y)<=t)return!0;continue}let c=Math.min(1,Math.max(0,((n.x-i.x)*a+(n.y-i.y)*l)/u));if(Math.hypot(n.x-i.x-c*a,n.y-i.y-c*l)<=t)return!0}return!1},tl=n=>{let e=1/0,t=1/0,r=-1/0,o=-1/0;for(let i of n)i.x<e&&(e=i.x),i.x>r&&(r=i.x),i.y<t&&(t=i.y),i.y>o&&(o=i.y);return{minX:e,minY:t,maxX:r,maxY:o}},Wu=(n,e,t)=>e.x>=n.minX-t&&e.x<=n.maxX+t&&e.y>=n.minY-t&&e.y<=n.maxY+t,zb=n=>{let e=n.length,t=tl(n),r=Math.max(8,Math.min(64,Math.ceil(Math.sqrt(e)))),o=Math.max(t.maxX-t.minX,1e-9)/r,i=Math.max(t.maxY-t.minY,1e-9)/r,s=new Array(r*r),a=l=>{let u=Math.max(0,Math.min(r-1,Math.floor((Math.min(l.pa.x,l.pb.x)-t.minX)/o))),c=Math.max(0,Math.min(r-1,Math.floor((Math.max(l.pa.x,l.pb.x)-t.minX)/o))),h=Math.max(0,Math.min(r-1,Math.floor((Math.min(l.pa.y,l.pb.y)-t.minY)/i))),d=Math.max(0,Math.min(r-1,Math.floor((Math.max(l.pa.y,l.pb.y)-t.minY)/i)));for(let f=h;f<=d;f++)for(let m=u;m<=c;m++)(s[f*r+m]??=[]).push(l)};for(let l=0;l<e;l++)a({pa:n[l],pb:n[(l+1)%e]});return{addEdge:(l,u)=>a({pa:l,pb:u}),blockedExcept(l,u){let c=Math.max(0,Math.min(r-1,Math.floor((Math.min(l.x,u.x)-t.minX)/o))),h=Math.max(0,Math.min(r-1,Math.floor((Math.max(l.x,u.x)-t.minX)/o))),d=Math.max(0,Math.min(r-1,Math.floor((Math.min(l.y,u.y)-t.minY)/i))),f=Math.max(0,Math.min(r-1,Math.floor((Math.max(l.y,u.y)-t.minY)/i)));for(let m=d;m<=f;m++)for(let p=c;p<=h;p++){let b=s[m*r+p];if(b){for(let x of b)if(!(x.pa===u||x.pb===u)&&Uu(l,u,x.pa,x.pb))return!0}}return!1}}},Yb=(n,e,t)=>{let r=n.length,o=0;for(let y=1;y<e.length;y++)(e[y].x>e[o].x||e[y].x===e[o].x&&e[y].y>e[o].y)&&(o=y);let i=e[o],s=-1,a=1/0;for(let y=0;y<r;y++){let v=n[y],S=Math.hypot(v.x-i.x,v.y-i.y);if(S>=a)continue;let w=t.blockedExcept(i,v);if(!w){for(let R=0;R<e.length;R++)if(!(R===o||(R+1)%e.length===o)&&Uu(i,v,e[R],e[(R+1)%e.length])){w=!0;break}}w||(a=S,s=y)}if(s>=0){let y=[];for(let v=s;v<r;v++)y.push(n[v]);for(let v=0;v<s;v++)y.push(n[v]);y.push(n[s]),y.push(i);for(let v=1;v<e.length;v++)y.push(e[(o+v)%e.length]);return y.push(i),Hu(t,n[s],i,e),y}let l=1/0,u=-1;for(let y=0;y<r;y++){let v=n[y],S=n[(y+1)%r];if(v.y!==S.y&&i.y>=Math.min(v.y,S.y)&&i.y<Math.max(v.y,S.y)){let w=(i.y-v.y)/(S.y-v.y),R=v.x+w*(S.x-v.x);R>=i.x&&R<l&&(l=R,u=y)}}if(u<0)return n;let c=n[u];s=n[(u+1)%r].x>c.x?(u+1)%r:u;let d=n[s],f={x:l,y:i.y},m=d.x-i.x,p=d.y-i.y,b=Math.hypot(m,p)||1,x=-1/0;for(let y=0;y<r;y++){if(y===s)continue;let v=n[y];if(!Gb(i,f,d,v))continue;let S=v.x-i.x,w=v.y-i.y,R=Math.hypot(S,w)||1,P=(S*m+w*p)/(R*b);(P>x+1e-12||Math.abs(P-x)<=1e-12&&R<a)&&(x=P,a=R,d=v,s=y)}let g=[];for(let y=s;y<r;y++)g.push(n[y]);for(let y=0;y<s;y++)g.push(n[y]);g.push(n[s]),g.push(i);for(let y=1;y<e.length;y++)g.push(e[(o+y)%e.length]);return g.push(i),Hu(t,n[s],i,e),g},Hu=(n,e,t,r)=>{n.addEdge(e,t);for(let o=0;o<r.length;o++)n.addEdge(r[o],r[(o+1)%r.length])},$u=(n,e="evenodd")=>{let t=n.map(u=>Hb(u.points)).filter(u=>u.length>=3);if(t.length===0)return[];let r=t.map(u=>tl(u)),o=new Array(t.length).fill(0),i=t.map(()=>new Array(t.length).fill(!1));for(let u=0;u<t.length;u++){let c=t[u][0];for(let h=0;h<t.length;h++)u!==h&&Wu(r[h],c,1e-6)&&(Xb(c,t[h],1e-6)||Bu(c,t[h])&&(o[u]++,i[h][u]=!0))}let s=new Array(t.length);if(e==="evenodd")for(let u=0;u<t.length;u++)s[u]=o[u]%2===0;else for(let u=0;u<t.length;u++){let c=br(t[u])>0?1:-1;for(let h=0;h<t.length;h++)h!==u&&i[h][u]&&(c+=br(t[h])>0?1:-1);s[u]=c!==0}let a=[],l=[];for(let u=0;u<t.length;u++)s[u]?a.push({ring:t[u],index:u,bbox:r[u]}):l.push({ring:t[u],depth:o[u]});if(a.length===0)return[];l.sort((u,c)=>Gu(c.ring)-Gu(u.ring));for(let u of l){let c=u.ring[0],h=a.find(f=>o[f.index]===u.depth-1&&Wu(f.bbox,c,0)&&Bu(c,f.ring));if(!h)continue;br(h.ring)*br(u.ring)>0&&(u.ring=u.ring.slice().reverse()),h.grid??=zb(h.ring),h.ring=Yb(h.ring,u.ring,h.grid);let d=tl(u.ring);h.bbox.minX=Math.min(h.bbox.minX,d.minX),h.bbox.minY=Math.min(h.bbox.minY,d.minY),h.bbox.maxX=Math.max(h.bbox.maxX,d.maxX),h.bbox.maxY=Math.max(h.bbox.maxY,d.maxY)}return a.map(u=>u.ring)},Gu=n=>{let e=-1/0;for(let t of n)t.x>e&&(e=t.x);return e};var Ub=new Set(["miter","round","bevel"]),$b=new Set(["butt","round","square"]),vi=n=>{if(typeof n.stroke!="string"||!n.stroke)return null;let e=Number(n.strokeWidth)||0;if(e<=0)return null;let t=Array.isArray(n.strokeDashArray)?n.strokeDashArray.map(i=>Number(i)||0).filter(i=>i>=0):null,r=typeof n.strokeLineJoin=="string"&&Ub.has(n.strokeLineJoin)?n.strokeLineJoin:"miter",o=typeof n.strokeLineCap=="string"&&$b.has(n.strokeLineCap)?n.strokeLineCap:"butt";return{color:n.stroke,rgba:ee(n.stroke),width:e,dashArray:t&&t.length>0?t:null,dashOffset:Number(n.strokeDashOffset)||0,lineJoin:r,lineCap:o,miterLimit:Number(n.strokeMiterLimit)||4,paintFirst:n.paintFirst==="stroke"?"stroke":"fill",alignment:n.strokeAlignment==="inside"||n.strokeAlignment==="outside"?n.strokeAlignment:"center",uniform:n.strokeUniform===!0||se(n)===L.PATH}},ju=n=>{let e=r=>String(Math.round(r*1e4)/1e4),t=n.dashArray?n.dashArray.map(e).join(","):"-";return`s|${n.rgba.map(e).join(",")}|${e(n.width)}|${n.uniform?1:0}|${t}|${e(n.dashOffset)}|${n.lineJoin}|${n.lineCap}|${e(n.miterLimit)}|${n.paintFirst}|${n.alignment}`};var jb=(n,e)=>{let t=e.matrix,r=Math.max(Math.hypot(t[0],t[1]),Math.hypot(t[2],t[3]));return Math.ceil(n.width*Math.max(1,n.miterLimit)*(n.uniform?1:r)/2+4)},Vb=625e4,Vu=(n,e,t)=>Math.min(n,8192/e,8192/t,Math.sqrt(Vb/(e*t))),wi=(n,e,t,r,o,i)=>{let s=e*t,a=r[4]*t,l=r[5]*t;return{lx:(Math.round((n[4]-o/2)*s+a)-a)/s,ly:(Math.round((n[5]-i/2)*s+l)-l)/s}},xr=(n,e)=>{let t=e.raw,r=se(t);if(n.beginPath(),r===L.PATH){let o=Ce(t.path);if(!o)return!1;let i=Fe(o);if(!i)return!1;let s=(i.left+i.right)/2,a=(i.top+i.bottom)/2;for(let l of o)switch(l[0]){case"M":n.moveTo(l[1]-s,l[2]-a);break;case"L":n.lineTo(l[1]-s,l[2]-a);break;case"C":n.bezierCurveTo(l[1]-s,l[2]-a,l[3]-s,l[4]-a,l[5]-s,l[6]-a);break;case"Q":n.quadraticCurveTo(l[1]-s,l[2]-a,l[3]-s,l[4]-a);break;case"Z":n.closePath();break}return!0}if(r===L.POLYGON||r===L.POLYLINE){let o=Array.isArray(t.points)?t.points:[];if(o.length<2)return!1;let i=1/0,s=1/0,a=-1/0,l=-1/0;for(let h of o)i>h.x&&(i=h.x),s>h.y&&(s=h.y),a<h.x&&(a=h.x),l<h.y&&(l=h.y);let u=(i+a)/2,c=(s+l)/2;n.moveTo(o[0].x-u,o[0].y-c);for(let h=0;h<o.length;h++)n.lineTo(o[h].x-u,o[h].y-c);return r===L.POLYGON&&n.closePath(),!0}if(r===L.TRIANGLE){let o=e.dims.x,i=e.dims.y;return!(o>0)||!(i>0)?!1:(n.moveTo(0,-i/2),n.lineTo(o/2,i/2),n.lineTo(-o/2,i/2),n.closePath(),!0)}if(r===L.ELLIPSE||r===L.CIRCLE){let o=(r===L.CIRCLE?Number(t.radius):Number(t.rx))||0,i=(r===L.CIRCLE?Number(t.radius):Number(t.ry))||0;return!(o>0)||!(i>0)?!1:(n.ellipse(0,0,o,i,0,0,Math.PI*2),!0)}if(r===L.LINE||r===L.REFERENCELINE){let o=Number(t.x1),i=Number(t.y1),s=Number(t.x2),a=Number(t.y2);return!Number.isFinite(o)||!Number.isFinite(i)||!Number.isFinite(s)||!Number.isFinite(a)?!1:(n.moveTo(o,i),n.lineTo(s,a),!0)}if(r===L.RECT||r===L.FABRICRECT){let o=e.dims.x,i=e.dims.y;if(!(o>0)||!(i>0))return!1;let s=it(t,o,i);return s?Yn(n,o,i,s.rx,s.ry):n.rect(-o/2,-i/2,o,i),!0}return!1},qu=(n,e)=>{let t=vi(n.raw);if(!t)return null;let r=se(n.raw);if(r===L.ARROW||r===L.DIMENSION)return Qb(n,t,e);let o=Math.abs(n.matrix[0])*n.dims.x+Math.abs(n.matrix[2])*n.dims.y,i=Math.abs(n.matrix[1])*n.dims.x+Math.abs(n.matrix[3])*n.dims.y,s=jb(t,n),a=o+s*2,l=i+s*2;if(!(a>0)||!(l>0)||a>8192||l>8192)return null;let u=e?e.zoom*e.dpr:1,c=Vu(u,a,l),h=Math.ceil(a*c),d=Math.ceil(l*c);if(!(h>0)||!(d>0))return null;let f=document.createElement("canvas");f.width=h,f.height=d;let m=f.getContext("2d");if(!m)return null;let p=n.matrix,b=e&&c===u?wi(p,e.zoom,e.dpr,e.vpt,a,l):null,x=b?b.lx:p[4]-a/2,g=b?b.ly:p[5]-l/2,y=h/c,v=d/c,S=[p[0]*c,p[1]*c,p[2]*c,p[3]*c,(p[4]-x)*c,(p[5]-g)*c];if(m.setTransform(S[0],S[1],S[2],S[3],S[4],S[5]),!xr(m,n))return null;let w=S;if(t.uniform){let R=Math.hypot(p[0],p[1])||1,P=Math.hypot(p[2],p[3])||1;w=V(S,[1/R,0,0,1/P,0,0])}if(m.setTransform(w[0],w[1],w[2],w[3],w[4],w[5]),m.lineWidth=t.width,m.lineCap=t.lineCap,m.lineDashOffset=t.dashOffset,m.lineJoin=t.lineJoin,m.miterLimit=t.miterLimit,t.dashArray&&m.setLineDash(t.dashArray),m.strokeStyle=t.color,t.alignment==="outside"||t.alignment==="inside"){if(m.lineWidth=t.width*2,t.alignment==="inside")m.clip(),m.stroke();else{m.stroke(),m.globalCompositeOperation="destination-out";let R=Jr(n,m);typeof n.raw.fill=="string"&&n.raw.fill!==""&&n.raw.fill!=="transparent"||m.clip(),m.fillStyle=R,m.fill(),m.globalCompositeOperation="source-over"}return{canvas:f,w:y,h:v,lx:x,ly:g,sceneW:a,sceneH:l,snapped:!!b}}return m.stroke(),{canvas:f,w:y,h:v,lx:x,ly:g,sceneW:a,sceneH:l,snapped:!!b}},Jr=(n,e)=>{let t=n.raw.fill;if(typeof t=="string"&&t)return t;if(t&&typeof t=="object"&&t.type==="linear"){let r=t,o=r.coords??{},i=n.dims.x,s=n.dims.y,a=r.gradientUnits==="percentage"?i:1,l=r.gradientUnits==="percentage"?s:1,u=e.createLinearGradient((o.x1??0)*a+(r.offsetX??0),(o.y1??0)*l+(r.offsetY??0),(o.x2??0)*a+(r.offsetX??0),(o.y2??0)*l+(r.offsetY??0));for(let c of r.colorStops??[])typeof c?.offset=="number"&&typeof c?.color=="string"&&u.addColorStop(Math.min(1,Math.max(0,c.offset)),c.color);return u}return qb(n)},qb=n=>{let e=n.raw.stroke;return typeof e=="string"&&e?e:"#000"},Kb=n=>{let e=Number(n.raw.x1),t=Number(n.raw.y1),r=Number(n.raw.x2),o=Number(n.raw.y2);return!Number.isFinite(e)||!Number.isFinite(t)||!Number.isFinite(r)||!Number.isFinite(o)?null:{x1:e,y1:t,x2:r,y2:o}},Qb=(n,e,t)=>{let r=Kb(n);if(!r)return null;let o=n.raw,s=se(o)===L.ARROW,a=Number(o.strokeWidth)||1,l=typeof o.stroke=="string"?o.stroke:"#000000",u=Array.isArray(o.strokeDashArray)?o.strokeDashArray:null,c=Math.ceil(a*2+8),h=null,d=Number(o.arrowWidth)||15,f=Number(o.arrowHeight)||22.5,m=o.arrowType==="start"||o.arrowType==="both"?o.arrowType:(o.arrowType==="end","end"),p=Math.sqrt(a),b=d*p,x=f*p;if(s)c=Math.ceil(c+x+b);else{let z=Number(o.textFontSize)||50,$=typeof o.text=="string"&&o.text.trim()?o.text:"50cm",Z=Number(o.textPadding)||4,B=`${z}px Arial, sans-serif`,q=eo(B,$)+Z*2,U=Math.atan2(r.y2-r.y1,r.x2-r.x1),oe=-Math.sin(U),ne=Math.cos(U),de=z+a/2+5;h={text:$,fontPx:z,w:q,h:z+Z*2,cx:(r.x1+r.x2)/2+oe*de,cy:(r.y1+r.y2)/2+ne*de,angle:o.textFollowLine===!1?0:U,color:typeof o.textColor=="string"?o.textColor:"#333333",bg:typeof o.textBackgroundColor=="string"?o.textBackgroundColor:"#ffffff",pad:Z,follow:o.textFollowLine!==!1},c=Math.ceil(c+de+Math.max(q,z*2)*.75)}let g=Math.abs(n.matrix[0])*n.dims.x+Math.abs(n.matrix[2])*n.dims.y,y=Math.abs(n.matrix[1])*n.dims.x+Math.abs(n.matrix[3])*n.dims.y,v=g+c*2,S=y+c*2;if(!(v>0)||!(S>0)||v>8192||S>8192)return null;let w=t?t.zoom*t.dpr:1,R=Vu(w,v,S),P=Math.ceil(v*R),T=Math.ceil(S*R);if(!(P>0)||!(T>0))return null;let C=document.createElement("canvas");C.width=P,C.height=T;let E=C.getContext("2d");if(!E)return null;let M=n.matrix,k=t&&R===w?wi(M,t.zoom,t.dpr,t.vpt,v,S):null,A=k?k.lx:M[4]-v/2,O=k?k.ly:M[5]-S/2,F=[M[0]*R,M[1]*R,M[2]*R,M[3]*R,(M[4]-A)*R,(M[5]-O)*R];E.setTransform(F[0],F[1],F[2],F[3],F[4],F[5]);let G=r.x2-r.x1,Y=r.y2-r.y1,_=Math.atan2(Y,G),D=Math.cos(_),I=Math.sin(_);if(s){let z=m==="start"||m==="both",$=m==="end"||m==="both",Z=r.x1+D*(z?x:0),B=r.y1+I*(z?x:0),q=r.x2-D*($?x:0),U=r.y2-I*($?x:0);E.lineWidth=a,E.strokeStyle=l,u&&u.length>0?E.setLineDash(u):E.setLineDash([]),E.beginPath(),E.moveTo(Z,B),E.lineTo(q,U),E.stroke(),E.setLineDash([]);let oe=(ne,de,Pe)=>{E.save(),E.translate(ne,de),E.rotate(Pe),E.beginPath(),E.moveTo(0,0),E.lineTo(-x,-b/2),E.lineTo(-x,b/2),E.closePath(),E.fillStyle=l,E.fill(),E.restore()};return $&&oe(r.x2,r.y2,_),z&&oe(r.x1,r.y1,_+Math.PI),{canvas:C,w:P/R,h:T/R,lx:A,ly:O,sceneW:v,sceneH:S,snapped:!!k}}E.beginPath(),E.moveTo(r.x1,r.y1),E.lineTo(r.x2,r.y2);let W=F;if(e.uniform){let z=Math.hypot(M[0],M[1])||1,$=Math.hypot(M[2],M[3])||1;W=V(F,[1/z,0,0,1/$,0,0])}E.setTransform(W[0],W[1],W[2],W[3],W[4],W[5]),E.lineWidth=e.width,E.lineCap=e.lineCap,E.lineDashOffset=e.dashOffset,E.lineJoin=e.lineJoin,E.miterLimit=e.miterLimit,e.dashArray&&E.setLineDash(e.dashArray),E.strokeStyle=l,E.stroke(),E.setTransform(F[0],F[1],F[2],F[3],F[4],F[5]);let j=-I,H=D,X=(Number(o.textFontSize)||50)/2;E.lineWidth=a,E.lineCap="round",e.dashArray&&E.setLineDash([]),E.strokeStyle=l;for(let[z,$]of[[r.x1,r.y1],[r.x2,r.y2]])E.beginPath(),E.moveTo(z-j*X,$-H*X),E.lineTo(z+j*X,$+H*X),E.stroke();return h&&(E.save(),E.translate(h.cx,h.cy),h.follow&&E.rotate(h.angle),E.font=`${h.fontPx}px Arial, sans-serif`,E.textAlign="center",E.textBaseline="middle",h.bg&&(E.fillStyle=h.bg,E.fillRect(-h.w/2,-h.h/2,h.w,h.h)),E.fillStyle=h.color,E.fillText(h.text,0,0),E.restore()),{canvas:C,w:P/R,h:T/R,lx:A,ly:O,sceneW:v,sceneH:S,snapped:!!k}},eo=(n,e)=>{let t=document.createElement("canvas").getContext("2d");return t?(t.font=n,t.measureText(e).width):e.length*50};var fe={LEFT:"left",CENTER:"center",RIGHT:"right",JUSTIFY:"justify",JUSTIFY_LEFT:"justify-left",JUSTIFY_CENTER:"justify-center",JUSTIFY_RIGHT:"justify-right",DISPERSE:"disperse"},Zb=Object.values(fe),Ut=n=>n===fe.JUSTIFY||n===fe.JUSTIFY_LEFT||n===fe.JUSTIFY_CENTER||n===fe.JUSTIFY_RIGHT,nl=n=>n===fe.JUSTIFY_LEFT||n===fe.JUSTIFY_CENTER||n===fe.JUSTIFY_RIGHT,to=n=>n===fe.JUSTIFY||n===fe.DISPERSE;var Ku=400,Ti=1.13,Ei=.222,Jb=2,ex={underline:.1,linethrough:-.28167,overline:-.81333},tx=66.667,nx=/[a-zA-Z.\s]+/,rx=/[0-9]/,ox=/[()[\]{}></:;:,.?!]/,oo=n=>nx.test(n)||rx.test(n)||ox.test(n),ix=new Set(["ー","「","」","『","』","(",")","〔","〕","[","]","{","}","⦅","⦆","〈","〉","《","》","【","】","〖","〗","〘","〙","〚","〛","゛","゜","。","、","・","゠","=","〜","…","•","‥","◦","﹅","﹆"]),sx=new Set(["「","」","『","』","〔","〕","[","]","{","}","⦅","⦆","〈","〉","《","》","【","】","〖","〗","〘","〙","〚","〛","(",")"]),$n=n=>oo(n)?"latin":sx.has(n)?"bracket":ix.has(n)?"symbol":"cjk",jn=(n,e,t)=>oo(n)?e.width:e.height+t,cn=n=>n/1.1,gr=(n,e,t)=>n==="symbol"?-t/3.14:e.height/2-t/3.14,wt=(n,e,t)=>n===0||t%2===0?0:n/300*e*.5,th=(n,e,t)=>{if(n===0)return 0;let r=e.fontSize;for(let o of t)for(let i of o.charStyles){let s=i?.fontSize;typeof s=="number"&&s>r&&(r=s)}return Math.abs(n)/300*r*.5},no=null,nh=(n,e,t)=>{let r={left:0,right:0,ascent:t*.88,descent:t*.24};if(typeof document>"u")return r;if(!no){let i=document.createElement("canvas");i.width=8,i.height=8,no=i.getContext("2d")}if(!no)return r;no.font=n;let o=no.measureText(e);return o.actualBoundingBoxAscent===void 0||o.actualBoundingBoxDescent===void 0?r:{left:-(o.actualBoundingBoxLeft??0),right:o.actualBoundingBoxRight??0,ascent:o.actualBoundingBoxAscent,descent:o.actualBoundingBoxDescent}},Qu=new WeakMap,il=new Set,Zu=(n,e,t)=>{let r=Qu.get(n);r||(r=new Map,Qu.set(n,r),il.add(r));let o=`${Me(e,e.fontSize)}|${t}`,i=r.get(o);return i||(i=n(Me(e,e.fontSize),t,e.fontSize),r.set(o,i)),i},rh=(n,e,t=nh)=>{let r=e.charSpacing?e.fontSize*e.charSpacing/1e3:0,o=0,i=0,s=0;for(let a=0;a<n.graphemes.length;a++){let l=n.graphemes[a],u=n.boxes[a],c=ih(e,n.charStyles[a]),h=$n(l),d,f;if(h==="latin"||h==="bracket"){let m=h==="latin"?u.kernedWidth-u.width:0,p=Zu(t,c,l);d=p.left+m,f=p.right+m}else{let m=Zu(t,c,l);d=cn(c.fontSize)-m.ascent,f=cn(c.fontSize)+m.descent}a===0&&(i=d),s=o+f,o+=jn(l,u,r)}return{start:i,end:s}},sl=new Set(["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","math","emoji","fangsong","inherit","initial","unset"]),Ci=(n,e,t={})=>{let r=1/0,o=-1/0,i=1/0;for(let a of n.lines){if(a.width<=0||a.graphemes.length===0)continue;let l,u;if(t.vertical){let c=rh(a,e,t.inkMeasure);l=a.leftOffset+c.start,u=a.leftOffset+c.end}else{let c=a.boxes[a.boxes.length-1];l=a.leftOffset,u=a.leftOffset+Math.max(a.width,c.left+c.width)}u>l&&(r=Math.min(r,l),o=Math.max(o,u),i=Math.min(i,a.top))}if(!(o>r)||!Number.isFinite(i))return null;let s=t.align===void 0?{lo:r,hi:o}:ax(r,o,n.width,t.align);return{lo:s.lo,hi:s.hi,firstTop:i}},ax=(n,e,t,r)=>!(t>0)||!Number.isFinite(t)?{lo:n,hi:e}:r===fe.CENTER||r===fe.JUSTIFY_CENTER?{lo:Math.min(0,n),hi:Math.max(t,e)}:r===fe.RIGHT||r===fe.JUSTIFY_RIGHT?{lo:n,hi:Math.max(t,e)}:{lo:Math.min(0,n),hi:e},Me=(n,e)=>{let t=n.fontFamily,r=t.includes("'")||t.includes('"')||t.includes(",")||sl.has(t.toLowerCase())?t:`"${t}"`;return`${n.fontStyle??"normal"} ${n.fontWeight??"normal"} ${e}px ${r}`},lx=(n,e)=>{if(n)return n.id===0?`${e+1}`:n.content||void 0},Oe=(n,e)=>{let t=e?.stroke??n?.color,r=e?.strokeWidth??n?.width;return!t||!r?null:{color:t,width:r,lineJoin:n?.lineJoin,miterLimit:n?.miterLimit,lineCap:n?.lineCap}},io=/[\u4e00-\u9fa5\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af]/,un=n=>{let e=n.boxes[n.boxes.length-1];return e?e.left+e.width:0},Tt=(n,e,t,r,o={})=>{let i=e.prefix;if(!i)return 0;let s=n.font;return n.font=Me(i.style,i.style.fontSize),o.fill&&(o.fill!=="keep"&&(n.fillStyle=o.fill),n.fillText(i.text,t,r)),o.stroke&&o.stroke.width>0&&(n.lineWidth=o.stroke.width,n.strokeStyle=o.stroke.color,n.strokeText(i.text,t,r)),n.font=s,i.width},al=(n,e,t)=>{let r=[],o=!!t[e],i=y=>!!(n.charStyles[y]?.[e]??o);if(!n.graphemes.some((y,v)=>i(v)))return r;let s=y=>n.charStyles[y]?.fill??t.fill??"",a=y=>n.charStyles[y]?.textDecorationThickness??t.textDecorationThickness??tx,l=y=>n.charStyles[y]?.fontSize??t.fontSize,u=ex[e],c=e==="linethrough"?.5:e==="overline"?1:0,h=t.charSpacing?t.fontSize*t.charSpacing/1e3:0,d=(y,v,S,w,R,P)=>{if(!y||!v||!S||P<=0)return;let T=t.fontSize*S/1e3;r.push({x:R,width:P,y:u*w-c*T,thickness:T,color:v})},f=0,m=0,p=i(0),b=s(0),x=a(0),g=l(0);for(let y=0;y<n.graphemes.length;y++){let v=i(y),S=s(y),w=a(y),R=l(y),P=n.boxes[y],T=t.vertical?oo(n.graphemes[y])?P.kernedWidth:P.height:P.kernedWidth;(v!==p||S!==b||w!==x||R!==g)&&m>0?(d(p,b,x,g,f,m),f=P.left,m=t.vertical?T:P.width,p=v,b=S,x=w,g=R):m+=t.vertical?T:P.kernedWidth}return d(p,b,x,g,f,m-h),r},ro=null,cx=(n,e)=>{if(typeof document>"u")return 0;if(!ro){let t=document.createElement("canvas");if(t.width=8,t.height=8,ro=t.getContext("2d"),!ro)return 0}return ro.font=n,ro.measureText(e).width},At=n=>Array.from(n),ux=n=>n.split(/[ \t\r]/),rl=class{constructor(e,t){this.decl=e;this.measure=t}decl;measure;charWidths=new Map;coupleWidths=new Map;charWidth(e){let t=this.charWidths.get(e);return t===void 0&&(t=this.measure(this.decl,e),this.charWidths.set(e,t)),t}coupleWidth(e,t){let r=e+"\0"+t,o=this.coupleWidths.get(r);return o===void 0&&(o=this.measure(this.decl,e+t),this.coupleWidths.set(r,o)),o}},Ju=new WeakMap,hx=(n,e)=>{let t=Ju.get(e);t||(t=new Map,Ju.set(e,t),il.add(t));let r=t.get(n);return r||(r=new rl(n,e),t.set(n,r)),r},oh=()=>{for(let n of il)n.clear()},ih=(n,e)=>!e||e.fontSize===void 0&&e.fontFamily===void 0&&e.fontWeight===void 0&&e.fontStyle===void 0?n:{...n,fontSize:e.fontSize??n.fontSize,fontFamily:e.fontFamily??n.fontFamily,fontWeight:e.fontWeight??n.fontWeight,fontStyle:e.fontStyle??n.fontStyle},ol=(n,e,t,r,o)=>{let i=hx(Me(e,Ku),n),s=e.fontSize/Ku,a=i.charWidth(t),l=a;return r&&o&&Me(o,o.fontSize)===Me(e,e.fontSize)&&(l=i.coupleWidth(r,t)-i.charWidth(r)),{width:a*s,kernedWidth:l*s}},sh=n=>n.charSpacing?n.fontSize*n.charSpacing/1e3:0,eh=(n,e,t,r,o,i,s,a=!1)=>{let l=sh(o),u=[],c=" ",h=0,d=[],f=0,m=!0,p=0,b=Math.max(e,r,Jb),x=t[n];for(let g=0;g<x.length;g++){let y=x[g].graphemes,v=x[g].width;p+=y.length,h+=(a?0:f)+v-l,h>b&&!m?(u.push(d),d=[],h=v,m=!0):h+=l,!m&&!a&&d.push(c),d=d.concat(y),f=a?0:ol(s,i(n,p),c).kernedWidth+l,p++,m=!1}return x.length&&u.push(d),u},Vn=(n,e,t={})=>{let r=t.measure??cx,o=t.inkMeasure??nh,i=t.styles,s=(E,M)=>ih(e,i?.[E]?.[M]),a=sh(e),l=e.lineHeight??1.16,u=(E,M,k)=>{let A=0,O;for(let F=0;F<E.length;F++){let G=ol(r,s(M,k+F),E[F],O,F>0?s(M,k+F-1):void 0);A+=G.kernedWidth+a,O=E[F]}return A},c=(n??"").split(`
|
|
3
|
+
`),h,d=0;if(t.boxWidth==null)h=c.map(E=>At(E));else if(t.splitByGrapheme){let E=[];for(let M=0;M<c.length;M++){let k=At(c[M]);if(k.length===0){E.push([{graphemes:[],width:0,charOffset:0}]);continue}let A=k.map((O,F)=>{let G=u([O],M,F);return d=Math.max(G,d),{graphemes:[O],width:G,charOffset:F}});E.push(A)}h=[];for(let M=0;M<E.length;M++)h.push(...eh(M,t.boxWidth,E,d,e,s,r,!0))}else{let E=[];for(let M=0;M<c.length;M++){let k=[],A=0;for(let O of ux(c[M])){let F=At(O),G=u(F,M,A);d=Math.max(G,d),k.push({graphemes:F,width:G,charOffset:A}),A+=F.length+1}E.push(k)}h=[];for(let M=0;M<E.length;M++)h.push(...eh(M,t.boxWidth,E,d,e,s,r))}let f=At(n??""),m=[];{let E=0,M=0,k=0;for(let A=0;A<h.length;A++){let O=f[k];O===`
|
|
4
|
+
`&&A>0?(M=0,k++,E++):A>0&&!t.splitByGrapheme&&/[ \t\r]/.test(O??"")&&(M++,k++),m[A]={line:E,offset:M,flatStart:k},k+=h[A].length,M+=h[A].length}}let p=h.map((E,M)=>{let k=m[M],A=[],O=0;for(let _=0;_<E.length;_++){let D=ol(r,s(k.line,k.offset+_),E[_],_>0?E[_-1]:void 0,_>0?s(k.line,k.offset+_-1):void 0),I={left:0,width:D.width+a,kernedWidth:D.kernedWidth+a,height:s(k.line,k.offset+_).fontSize};_>0&&(I.left=A[_-1].left+A[_-1].width+D.kernedWidth-D.width),A.push(I),t.vertical&&!oo(E[_])?O+=I.height:O+=I.kernedWidth}a!==0&&(O-=a),O<0&&(O=0);let F=E.map((_,D)=>i?.[k.line]?.[k.offset+D]),G=0;if(E.length>0)for(let _=0;_<E.length;_++)G=Math.max(G,i?.[k.line]?.[k.offset+_]?.fontSize??e.fontSize);else G=i?.[k.line]?.[k.offset]?.fontSize??e.fontSize;let Y;if(t.paragraph){let _=lx(t.paragraph,M);if(_){let D=s(k.line,k.offset),I=Me(D,D.fontSize),W=r(I,_);if(W>0){Y={text:_,width:W,advances:At(_).map(j=>r(I,j)),style:D};for(let j of A)j.left+=Y.width;O+=Y.width}}}return{graphemes:E,boxes:A,width:O,leftOffset:0,baseline:0,top:0,implHeight:G*Ti,styleMap:k,charStyles:F,prefix:Y}}),b=0,x=0;for(let E=0;E<p.length;E++){let M=p[E].implHeight,k=E===p.length-1;p[E].top=x,p[E].baseline=x+M*(1-Ei),x+=M*l,b+=k?M:M*l}let g=t.boxWidth!=null?Math.max(t.boxWidth,d-a):0,y=()=>{let E=0;for(let M of p){let k=0;for(let A=0;A<M.graphemes.length;A++)k+=oo(M.graphemes[A])?M.boxes[A].width+a:M.boxes[A].height+a;E=Math.max(E,k)}return E+2},v=t.vertical?y():void 0,S=t.boxWidth!=null?g:t.vertical?v:Math.max(0,...p.map(E=>E.width)),w=e.textAlign??fe.LEFT,R=E=>{if(t.boxWidth==null)return E===p.length-1;let M=p[E+1]?.styleMap;return!M||M.line!==p[E].styleMap.line};for(let E=0;E<p.length;E++){let M=w===fe.CENTER||w===fe.JUSTIFY_CENTER&&R(E),k=w===fe.RIGHT||w===fe.JUSTIFY_RIGHT&&R(E);if(t.vertical&&(M||k)&&p[E].graphemes.length>0){let O=rh(p[E],e,o);p[E].leftOffset=M?(S-O.start-O.end)/2:S-O.end;continue}let A=S-p[E].width;M?p[E].leftOffset=A/2:k&&(p[E].leftOffset=A)}let P=w===fe.DISPERSE;if((Ut(w)||P)&&!t.vertical)for(let E=0;E<p.length;E++){let M=p[E],k=nl(w);if(k&&(E===p.length-1||R(E))||!k&&!P&&E===p.length-1||M.width>=S)continue;let A=!k&&M.graphemes.some(Y=>io.test(Y)),O=A?M.graphemes.length-1:M.graphemes.reduce((Y,_)=>/[ \t\r]/.test(_)?Y+1:Y,0);if(O<=0)continue;let F=(S-M.width)/O,G=0;for(let Y=0;Y<M.graphemes.length;Y++){let _=M.boxes[Y],D=A?Y<M.graphemes.length-1:/[ \t\r]/.test(M.graphemes[Y]);_.left+=G,D&&(_.width+=F,_.kernedWidth+=F,G+=F)}}let T=[],C=0;for(let E of f)T.push(C),C+=E.length;return T.push(C),{lines:p,width:S,height:b,graphemeCodeUnitOffsets:T,verticalWidth:v}};var dx={arc:"arc",circle:"circle",waist:"waist",flag:"flag",arch:"arch",scroll:"scroll"},fx={[L.ARCTEXT]:"arc",[L.CIRCLETEXT]:"circle",[L.WAISTTEXT]:"waist",[L.FLAGTEXT]:"flag",[L.ARCHTEXT]:"arch",[L.SCROLLTEXT]:"scroll"},Ke=n=>{let e=n.textTransform;if(typeof e=="string"){let t=dx[e];if(t)return t}return fx[se(n)]??null},yr=n=>{if(!(Number(n.warpStrength)||0))return null;let t=Ke(n);return t==="arch"||t==="waist"||t==="flag"?t:null},ah=(n,e,t,r,o)=>{if(!(r.hi>r.lo))return null;let i=Math.max(-1,Math.min(1,Number(t.warpStrength)||0)),s=Number(t.fontSize)||40,a=typeof t.height=="number"?t.height:0,l=Math.max(a,s),u=-e.width/2+r.lo,c=-e.width/2+r.hi,h=o+r.firstTop,d=o+e.height,f=d-h;if(n==="arch"){if(i<=0)return{left:u,right:c,top:h,bottom:d};let b=l*i/2;return{left:u,right:c,top:d+b-f*(1+i),bottom:d+b}}if(n==="flag"){let b=Math.abs(i)*(a||s)*.3,x=Math.abs(i)*b;return{left:u,right:c,top:h-x,bottom:d+x}}let m=(h+d)/2,p=f/2*(1+.5*Math.abs(i));return{left:u,right:c,top:m-p,bottom:m+p}};var mx=1e4,so=2,lh=(n,e)=>{let t=e-n;for(;t>=2*Math.PI;)t-=2*Math.PI;for(;t<=0;)t+=2*Math.PI;return t},Mi=(n,e,t)=>lh(n,e)+lh(e,t)<2*Math.PI,Ri=(n,e,t,r)=>{let o=n.x,i=n.y,s=o,a=i;e.x<o&&(o=e.x),e.x>s&&(s=e.x),e.y<i&&(i=e.y),e.y>a&&(a=e.y);let l=Math.atan2(n.y-t.y,n.x-t.x),u=Math.atan2(e.y-t.y,e.x-t.x);if(Mi(l,0,u)){let c=t.x+r;c>s&&(s=c)}if(Mi(l,Math.PI/2,u)){let c=t.y+r;c>a&&(a=c)}if(Mi(l,Math.PI,u)){let c=t.x-r;c<o&&(o=c)}if(Mi(l,Math.PI*3/2,u)){let c=t.y-r;c<i&&(i=c)}return{x:o,y:i,width:s-o,height:a-i}},Ge=n=>{let e=Ke(n);return e==="arc"||e==="circle"?e:null},ch=n=>n.lines.map(e=>{let t=e.boxes.map(o=>({left:o.left,width:o.width})),r=t[t.length-1];return t.push(r?{left:r.left+r.width,width:0}:{left:0,width:0}),t}),px=(n,e,t)=>{let r=ch(n),o=n.width,i=P=>n.lines[P].implHeight*e,s=0;for(let P=0;P<n.lines.length;P++)s+=i(P);let a=Math.abs(t),l=a*Math.PI/180,u=0;for(let P=0;P<n.lines.length;P++)u+=n.lines[P].width;let c=l>0?u/l:0,h=Math.max(mx/Math.max(a,.1),c),d=0,f=t>0?s/2+h:-s/2+h,m=t>0?s:0,p=1/0,b=-1/0,x=1/0,g=-1/0,y=[];for(let P=0;P<r.length;P++){let T=-o/2+n.lines[P].leftOffset,C=i(P),E=C-C/e+C*Ei/e;m+=t>0?-C:C;let M=Math.abs(h)+m,k=t>0?M+C-C/e:M-C+C/e,A=[];for(let D=0;D<r[P].length;D++){let I=r[P][D],W,j,H,X,z,$,Z;t>0?(W=M,j=M+C,H=M+E,X=(W*3+j*2)/5,z=-(T+I.left)/X,$=-(T+I.left+I.width)/X,Z=-(T+I.left+I.width/2)/X):(W=M,j=M-C,H=M-E,X=(W*2+j*3)/5,z=Math.PI+(T+I.left)/X,$=Math.PI+(T+I.left+I.width)/X,Z=Math.PI+(T+I.left+I.width/2)/X);let B=Math.sin($),q=Math.cos($),U=Math.sin(z),oe=Math.cos(z),ne=Math.sin(Z),de=Math.cos(Z);A.push({tl:{x:d-j*U,y:f-j*oe},tr:{x:d-j*B,y:f-j*q},nl:{x:d-k*U,y:f-k*oe},nr:{x:d-k*B,y:f-k*q}});let Pe=n.lines[P].graphemes[D];Pe!==void 0&&y.push({char:Pe,line:P,index:D,x:d-H*ne,y:f-H*de,rotation:t>0?-Z:-Z-Math.PI})}let O=A[0],F=A[A.length-1];if(!O||!F)continue;let G={x:d,y:f},Y=t>0?Ri(O.tl,F.tr,G,M+C):Ri(F.tr,O.tl,G,M-C),_=t>0?Ri(O.nl,F.nr,G,M):Ri(F.nr,O.nl,G,M);p=Math.min(p,Y.x,_.x),b=Math.max(b,Y.x+Y.width,_.x+_.width),x=Math.min(x,Y.y,_.y),g=Math.max(g,Y.y+Y.height,_.y+_.height)}Number.isFinite(p)||(p=b=x=g=0);let v=-p-o/2,S=b-o/2,w=-x-s/2,R=g-s/2;return{width:Math.max(o+v+S,so),height:s+w+R,contentOffsetX:S/2-v/2,contentOffsetY:R/2-w/2,chars:y}},bx=(n,e,t)=>{let r=ch(n),o=C=>n.lines[C].implHeight*e,i=0;for(let C=0;C<n.lines.length;C++)i+=o(C);let s=n.width,a=Math.max(t.size,1),l=Math.min(Math.max(t.eccentricity,0),.95),u=a*(1-l),c=Math.max(t.sweep,1)*(Math.PI/180),h=t.startAngle*(Math.PI/180),d=t.horizontal,f=0;for(let C=0;C<n.lines.length;C++)f+=n.lines[C].width;let m=0,p=0;if(f<=0||r.length===0)return{width:so,height:Math.max(i,so),contentOffsetX:0,contentOffsetY:0,chars:[]};let b=1/0,x=-1/0,g=1/0,y=-1/0,v=[],S=0;for(let C=0;C<r.length;C++){let E=o(C),M=E-E/e+E*Ei/e,k=E-M;for(let A=0;A<r[C].length;A++){let O=r[C][A],G=(S+O.left+O.width/2)/f,Y=h-G*c,_=Math.sin(Y),D=Math.cos(Y),I=m-a*_,W=p-u*D,j,H,X,z,$;if(d)j=0,H=1,X=0,z=0,$=-1;else{let U=a*D,oe=-u*_,ne=Math.hypot(U,oe)||1;H=U/ne,X=oe/ne;let de=-u*_,Pe=-a*D,De=Math.hypot(de,Pe)||1;z=de/De,$=Pe/De,j=Math.atan2(oe,U)}let Z=-j,B=O.width/2;b=Math.min(b,I-z*M-H*B,I-z*M+H*B,I+z*k-H*B,I+z*k+H*B),x=Math.max(x,I-z*M-H*B,I-z*M+H*B,I+z*k-H*B,I+z*k+H*B),g=Math.min(g,W-$*M-X*B,W-$*M+X*B,W+$*k-X*B,W+$*k+X*B),y=Math.max(y,W-$*M-X*B,W-$*M+X*B,W+$*k-X*B,W+$*k+X*B);let q=n.lines[C].graphemes[A];q!==void 0&&v.push({char:q,line:C,index:A,x:I,y:W,rotation:-Z})}S+=n.lines[C].width}Number.isFinite(b)||(b=x=g=y=0);let w=-b-s/2,R=x-s/2,P=-g-i/2,T=y-i/2;return{width:Math.max(x-b,so),height:Math.max(y-g,so),contentOffsetX:R/2-w/2,contentOffsetY:T/2-P/2,chars:v}},Et=(n,e,t)=>Ke(e)==="circle"?bx(n,t,{size:typeof e.circleSize=="number"?e.circleSize:40,startAngle:typeof e.circleStartAngle=="number"?e.circleStartAngle:0,sweep:typeof e.circleSweep=="number"?e.circleSweep:360,eccentricity:typeof e.circleEccentricity=="number"?e.circleEccentricity:0,horizontal:e.circleDirection==="horizontal"}):px(n,t,typeof e.curvature=="number"?e.curvature:300);var uh=(n,e)=>{let t=1-e;return n===2?[t,e,0,0]:n===3?[t*t,2*t*e,e*e,0]:[t*t*t,3*t*t*e,3*t*e*e,e*e*e]},hn=(n,e,t,r,o,i)=>{let s={uOrder:Math.min(4,Math.max(2,o)),vOrder:Math.min(4,Math.max(2,i)),xs:[],ys:[]};for(let a=0;a<s.vOrder;a++){let l=s.vOrder===1?0:a/(s.vOrder-1);for(let u=0;u<s.uOrder;u++){let c=s.uOrder===1?0:u/(s.uOrder-1);s.xs.push(n+(t-n)*c),s.ys.push(e+(r-e)*l)}}return s},Pi=(n,e,t)=>{let r=uh(n.uOrder,e),o=uh(n.vOrder,t),i=0,s=0;for(let a=0;a<n.vOrder;a++)for(let l=0;l<n.uOrder;l++){let u=r[l]*o[a];i+=u*n.xs[a*n.uOrder+l],s+=u*n.ys[a*n.uOrder+l]}return{x:i,y:s}},qn=(n,e,t,r,o,i)=>{let s=Math.sin(o),a=Math.cos(o),l=(t-e)/(2*s),u=4/3*Math.tan(o/2)*l,c=i?-u*s:u*s;n.xs.push(e,e+u*a,t-u*a,t),n.ys.push(r,r+c,r+c,r)},mt=(n,e,t)=>{n.xs.push(0,e/3,2*e/3,e),n.ys.push(t,t,t,t)},ll=(n,e)=>{let t={uOrder:n.uOrder,vOrder:n.vOrder,xs:[],ys:[]};for(let r=0;r<n.vOrder;r++){let o=n.vOrder-1-r;for(let i=0;i<n.uOrder;i++){let s=r*n.uOrder+i,a=o*n.uOrder+i;t.xs[s]=n.xs[a],t.ys[s]=e-n.ys[a]}}return t},xx=n=>{let e={uOrder:n.vOrder,vOrder:n.uOrder,xs:[],ys:[]};for(let t=0;t<n.vOrder;t++)for(let r=0;r<n.uOrder;r++){let o=t*n.uOrder+r,i=r*n.vOrder+t;e.xs[i]=n.ys[o],e.ys[i]=n.xs[o]}return e},hh=(n,e,t,r)=>{let o=Math.min(100,Math.max(-100,e)),i=Math.abs(o)*Math.PI/200,s=2*r*o/100,a={uOrder:4,vOrder:n==="wave"?3:2,xs:[],ys:[]};if(n==="arcLower"||n==="arcUpper")return Math.abs(o)<1e-9?hn(0,0,t,r,4,2):(mt(a,t,0),qn(a,0,t,r,i,o<0),n==="arcUpper"?ll(a,r):a);if(n==="fish")return mt(a,t,0),mt(a,t,r),a.ys[1]-=s,a.ys[2]+=s,a.ys[5]+=s,a.ys[6]-=s,a;if(n==="fisheye"){a=hn(0,0,t,r,4,4);let l=o/50;for(let u=1;u<=2;u++)for(let c=1;c<=2;c++){let h=u*4+c,d=c===1?0:t,f=u===1?0:r;a.xs[h]+=l*(d-a.xs[h]),a.ys[h]+=l*(f-a.ys[h])}return a}if(n==="inflate"||n==="squeeze"){a=hn(0,0,t,r,3,3);let l=t*o/200,u=r*o/200;return a.ys[1]-=u,a.ys[7]+=u,n==="inflate"?(a.xs[3]-=l,a.xs[5]+=l):(a.xs[3]+=l,a.xs[5]-=l),a}if(n==="twist"){a=hn(0,0,t,r,4,4);let l=t*Math.abs(o)/100,u=r*Math.abs(o)/100;return o>0?(a.xs[5]+=l,a.ys[6]+=u,a.xs[10]-=l,a.ys[9]-=u):o<0&&(a.ys[5]+=u,a.xs[6]-=l,a.ys[10]-=u,a.xs[9]+=l),a}if(n==="shellLower"||n==="shellUpper"){if(Math.abs(o)<1e-9)return hn(0,0,t,r,4,4);let l=Math.sin(i),u=Math.cos(i);if(a={uOrder:4,vOrder:4,xs:[],ys:[]},mt(a,t,0),mt(a,t,r/3),o>0){let c=2*r/3;a.xs.push(-c*l,t/3,2*t/3,t+c*l),a.ys.push(c*u,2*r/3,2*r/3,c*u),qn(a,-r*l,t+r*l,r*u,i,!1)}else{let c=r/3;a.xs.push(-c*l,t/3,2*t/3,t+c*l),a.ys.push(r-c*u,2*r/3,2*r/3,r-c*u),qn(a,0,t,r,i,!0)}return n==="shellUpper"?ll(a,r):a}if(n==="arc"){if(Math.abs(o)<1e-9)return hn(0,0,t,r,4,2);let l=Math.sin(i);return qn(a,-r*l,t+r*l,r*(1-Math.cos(i)),i,!0),qn(a,0,t,r,i,!0),o<0?ll(a,r):a}if(n==="arch"||n==="bulge"){if(Math.abs(o)<1e-9)return hn(0,0,t,r,4,2);let l=o>0;return qn(a,0,t,0,i,l),qn(a,0,t,r,i,n==="bulge"?!l:l),a}if(n==="flag")return mt(a,t,0),mt(a,t,r),a.ys[1]-=s,a.ys[2]+=s,a.ys[5]-=s,a.ys[6]+=s,a;if(n==="wave")return mt(a,t,0),mt(a,t,r/2),mt(a,t,r),a.ys[5]+=s,a.ys[6]-=s,a;if(n==="rise")return mt(a,t,0),mt(a,t,r),a.ys[0]+=s,a.ys[1]+=s,a.ys[4]+=s,a.ys[5]+=s,a},cl=n=>n==="arc"||n==="arch"||n==="bulge"||n==="flag"||n==="wave"||n==="rise"||n==="arcLower"||n==="arcUpper"||n==="shellLower"||n==="shellUpper"||n==="fish"||n==="fisheye"||n==="inflate"||n==="squeeze"||n==="twist",dh=(n,e,t,r,o)=>{if(!cl(n)||r<=0||o<=0)return;if(!t||n==="twist")return hh(n,e,r,o);let i=hh(n,e,o,r);return i?xx(i):void 0},fh=(n,e,t)=>{let r=Math.min(100,Math.max(-100,t)),o=Math.min(100,Math.max(-100,e));if(r!==0&&n.vOrder>1)for(let i=0;i<n.vOrder;i++){let s=i*n.uOrder,a=s+n.uOrder-1,l=(n.xs[s]+n.xs[a])/2,u=(n.ys[s]+n.ys[a])/2,h=1+(2*(i/(n.vOrder-1))-1)*r/100;for(let d=0;d<n.uOrder;d++){let f=s+d;n.xs[f]=l+(n.xs[f]-l)*h,n.ys[f]=u+(n.ys[f]-u)*h}}if(o!==0&&n.uOrder>1)for(let i=0;i<n.uOrder;i++){let s=i,a=(n.vOrder-1)*n.uOrder+i,l=(n.xs[s]+n.xs[a])/2,u=(n.ys[s]+n.ys[a])/2,h=1+(2*(i/(n.uOrder-1))-1)*o/100;for(let d=0;d<n.vOrder;d++){let f=d*n.uOrder+i;n.xs[f]=l+(n.xs[f]-l)*h,n.ys[f]=u+(n.ys[f]-u)*h}}},ul=(n,e,t)=>{let r=dh(n.style,n.bend,n.rotate==="vertical",e,t);if(r)return fh(r,n.horizontal,n.vertical),r},Kn=n=>{if(n===null||typeof n!="object")return null;let t=n.psdWarp;if(t===null||typeof t!="object")return null;let r=t,o=typeof r.style=="string"?r.style:"";if(!cl(o))return null;let i=Number(r.bend)||0,s=Number(r.horizontal)||0,a=Number(r.vertical)||0;return i===0&&s===0&&a===0?null:{style:o,bend:i,horizontal:s,vertical:a,rotate:r.rotate==="vertical"?"vertical":"horizontal"}},hl=(n,e,t,r,o,i,s,a,l,u,c,h,d,f)=>{let m=r-e,p=o-t,b=a-i,x=l-s;if(m<=0||p<=0||b<=0||x<=0||u<=0||c<=0||d<=0||n.xs.length===0)return;let g=(i-e)/m,y=(a-e)/m,v=(s-t)/p,S=(l-t)/p,w=(G,Y)=>{let _=Pi(n,G,Y);return{x:h[0]*_.x+h[2]*_.y+h[4],y:h[1]*_.x+h[3]*_.y+h[5]}},R=0,P=0,T=0,C=0,E=!0,M=8;for(let G=0;G<=M;G++){let Y=v+(S-v)*G/M;for(let _=0;_<=M;_++){let D=g+(y-g)*_/M,I=w(D,Y);E?(R=P=I.x,T=C=I.y,E=!1):(R=Math.min(R,I.x),P=Math.max(P,I.x),T=Math.min(T,I.y),C=Math.max(C,I.y))}}let k=Math.max(8,f),A=Math.min(k,Math.max(8,Math.ceil((P-R)/d))),O=Math.min(k,Math.max(8,Math.ceil((C-T)/d))),F={columns:A+1,rows:O+1,docXs:[],docYs:[],sourceXs:[],sourceYs:[]};for(let G=0;G<F.rows;G++){let Y=G/O;for(let _=0;_<F.columns;_++){let D=_/A,I=w(g+(y-g)*D,v+(S-v)*Y);F.docXs.push(I.x),F.docYs.push(I.y),F.sourceXs.push(D*u),F.sourceYs.push(Y*c)}}return F},dl=(n,e,t,r,o,i,s,a,l,u)=>{let c=o-t,h=i-r,d=l-t,f=u-r,m=t-o-l+s,p=r-i-u+a,b=n-t,x=e-r,g=c*p-h*m,y=c*f-h*d-(b*p-x*m),v=-(b*f-x*d),S;if(Math.abs(g)<1e-9){if(Math.abs(y)<1e-9)return;S=-v/y}else{let T=y*y-4*g*v;if(T<0)return;let C=Math.sqrt(T),E=(-y+C)/(2*g),M=(-y-C)/(2*g),k=E>=-1e-9&&E<=1+1e-9,A=M>=-1e-9&&M<=1+1e-9;if(k&&A)S=Math.min(Math.max(E,0),1);else if(k)S=E;else if(A)S=M;else return}let w=d+m*S,R=f+p*S,P;if(Math.abs(w)>=Math.abs(R)){if(Math.abs(w)<1e-9)return;P=(b-c*S)/w}else{if(Math.abs(R)<1e-9)return;P=(x-h*S)/R}if(!(S<-1e-9||S>1.000000001||P<-1e-9||P>1.000000001))return{s:Math.min(Math.max(S,0),1),t:Math.min(Math.max(P,0),1)}};var gx=(n,e)=>{let t=n.boxes;if(t.length===0)return{left:0,width:0,kernedWidth:0,height:e};let r=t[t.length-1];return{left:r.left+r.width,width:0,kernedWidth:0,height:e}},ki=(n,e,t)=>e<0?null:e<n.boxes.length?n.boxes[e]:e===n.boxes.length?gx(n,t):null,yx=(n,e,t)=>{if(!Array.isArray(t)||t.length===0)return[];let r=0;for(let h of t){if(!h||typeof h.text!="string")return[];r+=h.text.length}if(r!==n.length)return[];let o=[],i=[];for(let h=0;h<e.lines.length;h++){let d=e.lines[h].graphemes.length;for(let f=0;f<d;f++)i.push(f),o.push(h)}let s=[],a=0;for(let h=0;h<n.length;h++)n[h]===`
|
|
5
|
+
`?s.push(-1):a<o.length?(s.push(a),a++):s.push(-1);let l=[],u=h=>{let d=s[h];return d===void 0||d===-1||d>=o.length?-1:d},c=0;for(let h of t){if(h.text.length===0)continue;if(h.text===`
|
|
6
|
+
`){c+=1;continue}if(!h.highlight||h.highlight.type!=="svg"||!h.highlight.svgInfo){c+=h.text.length;continue}let d=h.highlight.svgInfo,f=u(c);if(f===-1){c+=h.text.length;continue}let m=o[f],p=0,b=m,x=0,g=y=>{if(p>=y)return;let v=u(c+p),S=u(c+x);v===-1||S===-1||l.push({lineIndex:b,start:i[v],end:i[S]+1,info:d})};for(let y=0;y<h.text.length;y++){let v=u(c+y);if(v===-1){g(y),p=y+1;continue}let S=o[v];S!==m&&(g(y),p=y,m=S),b=S,x=y}g(h.text.length),c+=h.text.length}return l},fl=(n,e,t,r,o,i)=>{let s=r||e;return i==="bottom"?n+e-(t+s)*o:i==="top"?n-t*o:n+(e-s*o)/2-t*o},mh=n=>{let e=Ce(n);if(!e)return null;let t=Fe(e);return t?{left:t.left,top:t.top,width:t.right-t.left,height:t.bottom-t.top}:null},Sx=n=>{let e=n.split(/[Zz]/).map(r=>r.trim()).filter(r=>r.length>0);if(e.length===0)return null;let t=e[0];return t.endsWith("Z")||t.endsWith("z")?t:`${t} Z`},Qn=(n,e,t,r,o)=>{let i=yx(n,e,t);if(i.length===0)return null;let s=[],a={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},l=(f,m)=>{let p=f.isFill?0:(f.strokeWidth||0)*Math.abs(f.scaleX)/2,b=f.isFill?0:(f.strokeWidth||0)*Math.abs(f.scaleY)/2,x=f.translateX+m.left*f.scaleX-p,g=f.translateY+m.top*f.scaleY-b,y=f.translateX+(m.left+m.width)*f.scaleX+p,v=f.translateY+(m.top+m.height)*f.scaleY+b;x<a.minX&&(a.minX=x),g<a.minY&&(a.minY=g),y>a.maxX&&(a.maxX=y),v>a.maxY&&(a.maxY=v)};for(let f of i){let m=e.lines[f.lineIndex];if(!m)continue;let p=f.info,b=typeof p.path=="string"?p.path:"";if(!b)continue;let x=p.alignVertical||"center",g=p.isFill===!0,y=p.strokeWidth||0,v=-e.width/2+m.leftOffset,S=r+m.top,w=ki(m,f.start,o);if(!w)continue;if(p.isSingle===!0){let Y=Sx(b);if(!Y)continue;let _=mh(Y);if(!_||!Number.isFinite(_.width)||!Number.isFinite(_.height))continue;let D=Y;for(let I=f.start;I<f.end;I++){let W=m.graphemes[I];if(!W||/^\s$/.test(W))continue;let j=ki(m,I,o),H=ki(m,I+1,o);if(!j)continue;let X=v+j.left,z=S,$=j.kernedWidth||j.width||(H?H.left:j.left)-j.left,Z=j.height,B=_.height;B||(B=Z);let q=_.width?$/_.width:1,U=B?Z/B:1,oe=p.scale||1,ne=Math.min(q,U)*oe,de=(_.width||0)*ne,Pe=X+($-de)/2-_.left*ne,De=x==="bottom"?z+Z-_.top*ne:fl(z,Z,_.top,B,ne,x),nt={d:D,translateX:Pe,translateY:De,scaleX:ne,scaleY:ne,isFill:g,fill:p.fill||"#9FFFFC",stroke:p.stroke||"#9FFFFC",strokeWidth:y};s.push(nt),l(nt,_)}continue}let R=ki(m,f.end,o);if(!R)continue;let P=v+w.left,T=R.left-w.left,C=w.height,E=mh(b);if(!E||!Number.isFinite(E.width)||!Number.isFinite(E.height)||E.width===0)continue;let M=E.height;M||(M=C);let k=T/E.width,A=C/M,O=P-E.left*k,F=fl(S,C,E.top,M,A,x);if(x==="bottom"||x==="top"){let Y=E.top+M,_=Y>0?Y:M||1;A=C/_,F=fl(S,C,E.top,M,A,x)}E.height||(F+=C/2);let G={d:b,translateX:O,translateY:F,scaleX:k,scaleY:A,isFill:g,fill:p.fill||"#9FFFFC",stroke:p.stroke||"#9FFFFC",strokeWidth:y};s.push(G),l(G,E)}if(s.length===0)return null;let u=e.width/2,c=Number.isFinite(a.minX)&&Number.isFinite(a.minY),h=c?Math.max(2,-u-a.minX,a.maxX-u):2,d=c?Math.max(2,r-a.minY,a.maxY-(r+e.height)):2;return{ops:s,padX:h,padY:d,inkBounds:{left:a.minX,top:a.minY,right:a.maxX,bottom:a.maxY}}},ph=(n,e,t,r)=>{let o=Math.ceil(e.width+n.padX*2),i=Math.ceil(e.height+n.padY*2);if(!(o>0)||!(i>0)||o>8192||i>8192)return null;let s=document.createElement("canvas");s.width=Math.ceil(o*r),s.height=Math.ceil(i*r);let a=s.getContext("2d");if(!a)return null;a.setTransform(r,0,0,r,0,0),a.translate(e.width/2+n.padX,n.padY-t);for(let l of n.ops){let u=new Path2D(l.d);a.save(),a.translate(l.translateX,l.translateY),a.scale(l.scaleX,l.scaleY),l.isFill?(a.fillStyle=l.fill,a.fill(u)):(a.lineWidth=l.strokeWidth,a.strokeStyle=l.stroke,a.stroke(u)),a.restore()}return{canvas:s,logicalW:o,logicalH:i}};var ao=n=>{let e=n.pathBackground;if(!e||!e.backgroundChecked||typeof e.path!="string"||!e.path.trim())return null;let t=Number(e.width)||0,r=Number(e.height)||0;if(!t||!r)return null;let o=typeof e.fill=="string"&&e.fill?e.fill:void 0;return{path:e.path,fill:o,width:t,height:r}};var Ai=n=>{let e=n.raw,t=ao(e);if(!t||!t.fill)return null;let r=n.dims;if(!r.x||!r.y)return null;let o=Ce(t.path);if(!o)return null;let i=Fe(o);if(!i)return null;let s=i.right-i.left,a=i.bottom-i.top;if(!(s>0)||!(a>0))return null;let l=r.x/t.width,u=r.y/t.height,c=s*l,h=a*u;return!(c>0)||!(h>0)||c>8192||h>8192?null:{path:t.path,fill:t.fill,bounds:i,scaleX:l,scaleY:u,logicalW:c,logicalH:h,sigBase:[t.path,t.fill,t.width,t.height,r.x.toFixed(3),r.y.toFixed(3)].join(";")}},bh=(n,e)=>{let t=document.createElement("canvas");t.width=Math.ceil(n.logicalW*e),t.height=Math.ceil(n.logicalH*e);let r=t.getContext("2d");if(!r)return null;let o=(n.bounds.left+n.bounds.right)/2,i=(n.bounds.top+n.bounds.bottom)/2;r.setTransform(e*n.scaleX,0,0,e*n.scaleY,t.width/2-o*n.scaleX*e,t.height/2-i*n.scaleY*e);let s=ee(n.fill);return r.fillStyle=`rgba(${Math.round(s[0]*255)}, ${Math.round(s[1]*255)}, ${Math.round(s[2]*255)}, ${s[3]})`,r.fill(new Path2D(n.path),"nonzero"),{canvas:t,logicalW:n.logicalW,logicalH:n.logicalH}};var xh=n=>{if(!n||typeof n!="object"||Array.isArray(n))return null;let e=n,t=Number(e.blur)||0,r=Number(e.offsetX)||0,o=Number(e.offsetY)||0;if(!t&&!r&&!o)return null;let i=typeof e.color=="string"&&e.color?e.color:"rgb(0,0,0)";return{color:i,rgba:ee(i),blur:t,offsetX:r,offsetY:o,nonScaling:!!e.nonScaling}},Nt=(n,e,t)=>{if(n.nonScaling)return{blur:n.blur,offX:n.offsetX,offY:n.offsetY};let r=Math.abs(e),o=Math.abs(t);return{blur:n.blur*(r+o)/2,offX:n.offsetX*r,offY:n.offsetY*o}},Ni=n=>Math.ceil(n.blur*2+Math.max(Math.abs(n.offX),Math.abs(n.offY))+4),gh=n=>{let e=t=>String(Math.round(t*1e4)/1e4);return[n.color,e(n.blur),e(n.offsetX),e(n.offsetY),n.nonScaling?1:0].join("|")};var $t=(n,e,t,r,o)=>{let i=[],s=o?r.fontSize*o/1e3:0,a=0;for(let l=0;l<n.graphemes.length;l++){let u=n.graphemes[l],c=n.boxes[l],h=n.charStyles[l]?.fontSize??r.fontSize,d=$n(u);d==="latin"||d==="bracket"?i.push({ch:u,rotated:!1,x:e+a+(d==="latin"?c.kernedWidth-c.width:0),y:t}):i.push({ch:u,rotated:!0,x:e+a+cn(h),y:t+gr(d,c,h)}),a+=jn(u,c,s)}return i},jt=(n,e,t)=>{if(!e.rotated){n[t](e.ch,e.x,e.y);return}n.save(),n.translate(e.x,e.y),n.rotate(-Math.PI/2),n[t](e.ch,0,0),n.restore()},dn=(n,e)=>!e||e.fontSize===void 0&&e.fontFamily===void 0&&e.fontWeight===void 0&&e.fontStyle===void 0?n:{...n,fontSize:e.fontSize??n.fontSize,fontFamily:e.fontFamily??n.fontFamily,fontWeight:e.fontWeight??n.fontWeight,fontStyle:e.fontStyle??n.fontStyle};var ml=n=>{let e=n.matrix,t=n.dims.x,r=n.dims.y;return{x:Math.abs(e[0])*t+Math.abs(e[2])*r,y:Math.abs(e[1])*t+Math.abs(e[3])*r}},Ii=n=>{let e=n.raw;return JSON.stringify([e.path,e.points,e.rx,e.ry,e.radius])},pl=(n,e,t)=>{let r=e.textLayout,o=e.textStyle;n.fillStyle=t,n.textBaseline="alphabetic";let i=e.raw.vertical===!0,s=Number(e.raw.textOffsetY)||0,a=0;for(let l of r.lines){let u=-r.width/2+l.leftOffset,c=e.contentTopY+l.baseline;if(l.prefix&&Tt(n,l,u,c,{fill:"keep"}),i){let h=$t(l,u,c,o,o.charSpacing??0);for(let d=0;d<h.length;d++){let f=dn(o,l.charStyles[d]);n.font=Me(f,f.fontSize),jt(n,{...h[d],y:h[d].y+wt(s,f.fontSize,a+d)},"fillText")}a+=l.graphemes.length;continue}for(let h=0;h<l.graphemes.length;h++){let d=l.charStyles[h],f=dn(o,d);n.font=Me(f,f.fontSize),n.fillText(l.graphemes[h],u+l.boxes[h].left,c+wt(s,f.fontSize,a+h))}a+=l.graphemes.length}},Li=(n,e,t)=>{let r=e.dims.x,o=e.dims.y;if(e.isSolidType){n.fillStyle=t;let i=it(e.raw,r,o);if(i){Yn(n,r,o,i.rx,i.ry),n.fill();return}n.fillRect(-r/2,-o/2,r,o);return}if(e.isShapeType){let i=e.raw;if(se(i)===L.ELLIPSE||se(i)===L.CIRCLE){n.fillStyle=t,n.beginPath(),n.ellipse(0,0,r/2,o/2,0,0,Math.PI*2),n.fill();return}let s=e.shapeMesh;if(!s)return;n.fillStyle=t,n.beginPath();let a=s.verts.length/2;for(let l=0;l<a;l++){let u=s.verts[l*2],c=s.verts[l*2+1];l===0?n.moveTo(u,c):n.lineTo(u,c)}n.closePath(),n.fill();return}if(e instanceof ie){let i=e.paintSource;i&&n.drawImage(i,-r/2,-o/2,r,o);return}if((e.isImageType||e.isMaskType)&&e.imageEl){let i=e.cropRect,s=e.isImageType&&!(e instanceof ie)?pr(e.raw,r,o):null;s&&(n.save(),Yn(n,r,o,s,s),n.clip()),i?n.drawImage(e.imageEl,i.sx,i.sy,i.sw,i.sh,-r/2,-o/2,r,o):n.drawImage(e.imageEl,-r/2,-o/2,r,o),s&&n.restore();return}if(e.isTextType&&e instanceof Se){if(Vt(e)){if(!e.imageEl)return;let i=e.bitmapRect;n.save(),n.translate(i.x,i.y),i.angle&&n.rotate(-i.angle*Math.PI/180),n.drawImage(e.imageEl,-i.w/2,-i.h/2,i.w,i.h),n.restore();return}pl(n,e,t)}},yh=(n,e)=>{let t=Nt(e,n.raw.scaleX??1,n.raw.scaleY??1),r=Ni(t)+(n.isTextType?Math.ceil((n.raw.fontSize??40)*.5):0),o=ml(n),i=Math.ceil(o.x+r*2),s=Math.ceil(o.y+r*2);if(!(i>0)||!(s>0)||i>8192||s>8192)return null;let a=document.createElement("canvas");a.width=i,a.height=s;let l=a.getContext("2d");if(!l)return null;let u=n.matrix;l.setTransform(u[0],u[1],u[2],u[3],i/2,s/2);let c=`rgba(${Math.round(e.rgba[0]*255)},${Math.round(e.rgba[1]*255)},${Math.round(e.rgba[2]*255)},1)`;return l.shadowColor=e.color,l.shadowBlur=t.blur,l.shadowOffsetX=t.offX,l.shadowOffsetY=t.offY,Li(l,n,c),l.shadowColor="rgba(0,0,0,0)",l.shadowBlur=0,l.shadowOffsetX=0,l.shadowOffsetY=0,l.globalCompositeOperation="destination-out",Li(l,n,c),{canvas:a,w:i,h:s}};var lo=(n,e,t)=>{let r=e+t,o=n,i=new Int32Array(e*t);for(let f=0;f<e;f++){o[f+0*e]?i[f+0*e]=0:i[f+0*e]=r;for(let m=1;m<t;m++)o[f+m*e]?i[f+m*e]=0:i[f+m*e]=1+i[f+(m-1)*e];for(let m=t-2;m>=0;m--)i[f+(m+1)*e]<i[f+m*e]&&(i[f+m*e]=1+i[f+(m+1)*e])}let s=(f,m,p)=>(f-m)*(f-m)+p*p,a=(f,m,p,b)=>Math.floor((m*m-f*f+b*b-p*p)/(2*(m-f))),l=new Int32Array(e*t),u=new Int32Array(e),c=new Int32Array(e),h,d;for(let f=0;f<t;f++){h=0,u[0]=0,c[0]=0;for(let m=1;m<e;m++){for(;h>=0&&s(c[h],u[h],i[u[h]+f*e])>s(c[h],m,i[m+f*e]);)h--;h<0?(h=0,u[0]=m):(d=1+a(u[h],m,i[u[h]+f*e],i[m+f*e]),d<e&&(h++,u[h]=m,c[h]=d))}for(let m=e-1;m>=0;m--){let p=s(m,u[h],i[u[h]+f*e]);p=Math.floor(Math.sqrt(p)),l[m+f*e]=p,m===c[h]&&h--}}return l},bl=(n,e=10)=>{let t=new Uint8Array(n.length/4);for(let r=0;r<t.length;r++)t[r]=n[r*4+3]>e?1:0;return t};var Sh=(n,e)=>e==="smooth"?6*n*(1-n):1,vh=(n,e,t,r,o,i)=>{let s=r*o,a=new Float32Array(s),l=new Float32Array(s),u=Math.max(i.sizePx,.5),c=i.angleDeg*Math.PI/180,h=Math.sin(c),d=-Math.cos(c),f=Math.max(0,i.strength)*((90-Math.min(90,Math.max(0,i.altitudeDeg)))/90),m=i.style==="pillow"!==i.directionDown,p=i.style==="inner"||i.style==="emboss"||i.style==="pillow",b=i.style==="outer"||i.style==="emboss"||i.style==="pillow",x=(v,S,w)=>{let R=Math.min(1,Math.max(0,S)*w*f);R<=0||(m?l[v]=Math.min(1,l[v]+R):a[v]=Math.min(1,a[v]+R))},g=(v,S,w)=>{let R=Math.min(1,Math.max(0,-S)*w*f);R<=0||(m?a[v]=Math.min(1,a[v]+R):l[v]=Math.min(1,l[v]+R))},y=(v,S,w)=>{let R=v[Math.min(S+1,r-1)+w*r]-v[Math.max(S-1,0)+w*r],P=v[S+Math.min(w+1,o-1)*r]-v[S+Math.max(w-1,0)*r];return[R,P]};for(let v=0;v<o;v++)for(let S=0;S<r;S++){let w=S+v*r;if(t[w]){if(!p)continue;let R=n[w]-.5;if(R>=u)continue;let P=Math.max(0,R/u),[T,C]=y(n,S,v),E=Math.hypot(T,C);if(E<1e-6)continue;let M=-(T/E*h+C/E*d),k=Sh(P,i.technique);x(w,M,k),g(w,M,k)}else{if(!b)continue;let R=e[w]-.5;if(R>=u)continue;let P=Math.max(0,1-R/u),[T,C]=y(e,S,v),E=Math.hypot(T,C);if(E<1e-6)continue;let M=T/E*h+C/E*d,k=Sh(P,i.technique);x(w,M,k),g(w,M,k)}}return{highlight:a,shadow:l}};var wh={Brownie:[.5997,.34553,-.27082,0,.186,-.0377,.86095,.15059,0,-.1449,.24113,-.07441,.44972,0,-.02965,0,0,0,1,0],Vintage:[.62793,.32021,-.03965,0,.03784,.02578,.64411,.03259,0,.02926,.0466,-.08512,.52416,0,.02023,0,0,0,1,0],Kodachrome:[1.12855,-.39673,-.03992,0,.24991,-.16404,1.08352,-.05498,0,.09698,-.16786,-.56034,1.60148,0,.13972,0,0,0,1,0],Technicolor:[1.91252,-.85453,-.09155,0,.04624,-.30878,1.76589,-.10601,0,-.27589,-.2311,-.75018,1.84759,0,.12137,0,0,0,1,0],Polaroid:[1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0],Sepia:[.393,.769,.189,0,0,.349,.686,.168,0,0,.272,.534,.131,0,0,0,0,0,1,0],BlackWhite:[1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,0,0,0,1,0]},me=(n,e)=>typeof n=="number"&&Number.isFinite(n)?n:e,fn=(n,e)=>typeof n=="string"&&n?n:e,xl=(n,e)=>typeof n=="boolean"?n:e;function vx(n){let e=i=>Math.max(0,Math.min(255,Math.round(i))),t=n.map(i=>({input:e(i.input),output:e(i.output)}));t.sort((i,s)=>i.input-s.input);let r=[];for(let i of t)r.length&&r[r.length-1].input===i.input?r[r.length-1]=i:r.push(i);if(r.length<2)return[];if(r.length<=16)return r;let o=[];for(let i=0;i<16;i++){let s=e(i/15*255);o.push({input:s,output:e(wx(r,s))})}return o}function wx(n,e){if(n.length===0)return e;let t=n[0],r=n[n.length-1];if(e<=t.input)return t.output;if(e>=r.input)return r.output;for(let o=0;o<n.length-1;o++){let i=n[o],s=n[o+1];if(e>=i.input&&e<=s.input){let a=(e-i.input)/Math.max(1e-5,s.input-i.input);return i.output+(s.output-i.output)*a}}return e}function Tx(n){if(!Array.isArray(n))return[];let e=[];for(let r of n){if(!r||typeof r!="object")continue;let o=r,i=o.input,s=o.output;typeof i!="number"||!Number.isFinite(i)||typeof s!="number"||!Number.isFinite(s)||e.push({input:i,output:s})}let t=[];for(let r of vx(e))t.push(r.input,r.output);return t}function co(n){if(!Array.isArray(n))return[];let e=[];for(let t of n){if(!t||typeof t!="object")continue;let r=t,o=r.psd===1;switch(r.type){case"Brightness":e.push({kind:"Brightness",brightness:o?me(r.brightness,0)/100:me(r.brightness,0)});break;case"Contrast":e.push({kind:"Contrast",contrast:o?me(r.contrast,0)/100:me(r.contrast,0)});break;case"Saturation":e.push({kind:"Saturation",saturation:o?me(r.saturation,0)/100:me(r.saturation,0)});break;case"Vibrance":e.push({kind:"Vibrance",vibrance:o?me(r.vibrance,0)/100:me(r.vibrance,0)});break;case"HueRotation":e.push({kind:"HueRotation",rotation:o?me(r.hue,0)/100:me(r.rotation,0)});break;case"Grayscale":{let i=fn(r.mode,"average");e.push({kind:"Grayscale",mode:i==="lightness"||i==="luminosity"?i:"average"});break}case"Invert":e.push({kind:"Invert",invert:xl(r.invert,!0),alphaOnly:xl(r.alphaOnly,!1)});break;case"Sepia":case"Brownie":case"Kodachrome":case"Technicolor":case"Polaroid":case"BlackWhite":case"Vintage":e.push({kind:"ColorMatrix",matrixId:r.type});break;case"ColorMatrix":{let i=Array.isArray(r.matrix)?r.matrix.filter(s=>typeof s=="number"&&Number.isFinite(s)):[];i.length===20&&e.push({kind:"ColorMatrixOp",matrix:i});break}case"Blur":e.push({kind:"Blur",blur:me(o?r.radius:r.blur,0)});break;case"Noise":e.push({kind:"Noise",noise:me(r.noise,0)});break;case"Pixelate":e.push({kind:"Pixelate",blocksize:me(r.blocksize,1)});break;case"Convolute":{let i=Array.isArray(r.matrix)?r.matrix.filter(a=>typeof a=="number"):[],s=Math.sqrt(i.length);Number.isInteger(s)&&s>=3&&s<=9&&e.push({kind:"Convolute",matrix:i,opaque:xl(r.opaque,!1)});break}case"BlendColor":{let i=fn(r.mode,"multiply"),s=["multiply","screen","add","difference","subtract","darken","lighten","overlay","exclusion","tint"];e.push({kind:"BlendColor",color:fn(r.color,"#000000"),mode:s.includes(i)?i:"multiply",alpha:me(r.alpha,1)});break}case"Vignette":e.push({kind:"Vignette",intensity:me(r.intensity,0)});break;case"Temperature":{if(o){let i=mn(fn(r.color,"#ffb86b")),s=i[0]>=i[2];e.push({kind:"Temperature",temperature:me(r.density,0)/100*(s?1:-1)})}else e.push({kind:"Temperature",temperature:me(r.temperature,0)});break}case"Posterize":e.push({kind:"Posterize",levels:me(r.levels,20)});break;case"FilmGrain":e.push({kind:"FilmGrain",intensity:me(r.intensity,0),seed:me(r.seed,0)});break;case"Duotone":e.push({kind:"Duotone",color1:fn(r.color1,"#000000"),color2:fn(r.color2,"#ffffff")});break;case"Sketch":e.push({kind:"Sketch"});break;case"ChromaticAberration":e.push({kind:"ChromaticAberration",offset:me(r.offset,4)});break;case"SoftFocus":e.push({kind:"SoftFocus",blend:me(r.blend,.5)});break;case"Threshold":e.push({kind:"Threshold",threshold:me(r.threshold,128)});break;case"UnsharpMask":e.push({kind:"UnsharpMask",amount:o?me(r.amount,100)/100:me(r.amount,1)});break;case"MotionBlur":e.push({kind:"MotionBlur",distance:me(r.distance,0),angle:me(r.angle,0)});break;case"LensFlare":e.push({kind:"LensFlare",intensity:me(r.intensity,.8)});break;case"GradientMap":e.push({kind:"GradientMap",color0:fn(r.color0,"#000000"),color1:fn(r.color1,"#888888"),color2:typeof r.color2=="string"&&r.color2?r.color2:""});break;case"Levels":e.push({kind:"Levels",blackPoint:me(r.blackPoint,0),whitePoint:me(r.whitePoint,255),gamma:me(r.gamma,1)});break;case"Curves":e.push({kind:"Curves",points:Tx(r.points)});break;case"SurfaceBlur":e.push({kind:"SurfaceBlur",radius:me(r.radius,3),threshold:o?me(r.threshold,51)/255:me(r.threshold,.2)});break;case"Exposure":e.push({kind:"Exposure",exposure:me(r.exposure,0),offset:me(r.offset,0),gamma:me(r.gamma,1)});break;default:break}}return e}function _i(n){return JSON.stringify(n)}var Xw=Math.PI/2;function mn(n){let e=n.replace("#","");return/^[0-9a-fA-F]{6}$/.test(e)?[parseInt(e.substring(0,2),16),parseInt(e.substring(2,4),16),parseInt(e.substring(4,6),16)]:[0,0,0]}var qt=(n,e,t,r,o,i,s)=>{t?n.drawImage(e,t.sx,t.sy,t.sw,t.sh,r,o,i,s):n.drawImage(e,r,o,i,s)},Ex=6e5,Di=n=>Math.max(1,Math.floor(Math.sqrt(Ex/Math.max(1,n.dims.x*n.dims.y)))),Fi=n=>{if(!n.isImageType||n instanceof ie)return"";let e=co(n.raw.filters);return e.length?`|f${_i(e)}`:""},Lt=n=>!n.isImageType||n instanceof ie?null:pr(n.raw,n.dims.x,n.dims.y),Eh=n=>{let e=Lt(n);return e?`|rr${e}`:""},gl=(n,e,t,r,o,i,s)=>{n.save(),n.translate(t,r),e&&(Yn(n,o,i,e,e),n.clip()),s(),n.restore()},uo=(n,e,t,r,o)=>{if(!t)return n;let i=document.createElement("canvas");i.width=r,i.height=o;let s=i.getContext("2d",{willReadFrequently:!0});return s?(gl(s,t,r/2,o/2,r,o,()=>qt(s,n,e,-r/2,-o/2,r,o)),i):n},Cx=n=>{let e=n.matrix,t=n.dims.x,r=n.dims.y;return{x:Math.abs(e[0])*t+Math.abs(e[2])*r,y:Math.abs(e[1])*t+Math.abs(e[3])*r}},Th=n=>({color:n.color,rgba:n.rgba,blur:n.blur,offsetX:n.offsetX,offsetY:n.offsetY,nonScaling:!1}),ho=(n,e=1)=>{let t=Math.max(1,Math.ceil(n.dims.x*e)),r=Math.max(1,Math.ceil(n.dims.y*e));if(t>8192||r>8192)return null;let o=document.createElement("canvas");o.width=t,o.height=r;let i=o.getContext("2d");return i?(i.translate(t/2,r/2),i.scale(e,e),pl(i,n,"#ffffff"),o):null},Oi=(n,e,t,r=1,o=null)=>{if(!t||e.length===0)return null;let i=n.raw.scaleX??1,s=n.raw.scaleY??1,a=4;for(let S of e){let w=Nt(Th(S),i,s);a=Math.max(a,Math.ceil(w.blur*2+Math.max(Math.abs(w.offX),Math.abs(w.offY))+4))}let l=Cx(n),u=Math.ceil(l.x+a*2),c=Math.ceil(l.y+a*2),h=Math.ceil(u*r),d=Math.ceil(c*r);if(!(u>0)||!(c>0)||h>8192||d>8192)return null;let f=Lt(n),m=f?uo(t,o,f*r,Math.max(1,Math.ceil(n.dims.x*r)),Math.max(1,Math.ceil(n.dims.y*r))):t,p=f?null:o,b=document.createElement("canvas");b.width=h,b.height=d;let x=b.getContext("2d");if(!x)return null;let g=n.matrix;x.setTransform(g[0]*r,g[1]*r,g[2]*r,g[3]*r,h/2,d/2);let y=n.dims.x,v=n.dims.y;for(let S of e){let w=Nt(Th(S),i,s);x.filter=`drop-shadow(${w.offX*r}px ${w.offY*r}px ${w.blur*r}px ${S.color})`,qt(x,m,p,-y/2,-v/2,y,v)}return x.filter="none",x.globalCompositeOperation="destination-out",qt(x,m,p,-y/2,-v/2,y,v),{canvas:b,w:h,h:d,quadW:u,quadH:c}},Ch=(n,e,t)=>{let r=[1,0,0,1,n.offsetX,n.offsetY];return n.gradientUnits==="percentage"&&(r=V(r,[e,0,0,t,0,0])),n.gradientTransform&&(r=V(r,n.gradientTransform)),r},Mx=(n,e,t,r)=>{let o=V([1,0,0,1,r,r],Ch(n,e,t)),i=ve(o),s=hi(n,512),a=511,l=n.kind==="linear";return(u,c)=>{let h=u+.5,d=c+.5,f=i[0]*h+i[2]*d+i[4],m=i[1]*h+i[3]*d+i[5],p=l?Pu(n,{x:f,y:m}):ku(n,{x:f,y:m}),b=Math.min(a,Math.max(0,Math.round((isFinite(p)?p:0)*a)));return[s[b*4],s[b*4+1],s[b*4+2],s[b*4+3]]}},Sr=(n,e,t,r=1,o=null)=>{if(!t)return null;let i=Math.max(1,Math.ceil(n.dims.x)),s=Math.max(1,Math.ceil(n.dims.y)),a=Math.ceil(i*r),l=Math.ceil(s*r);if(a>8192||l>8192)return null;let u=document.createElement("canvas");u.width=a,u.height=l;let c=u.getContext("2d");if(!c)return null;if(e.kind==="gradient"){let d=e.decl,f=Ch(d,a,l);c.setTransform(f[0],f[1],f[2],f[3],f[4],f[5]);let m=d.kind==="linear"?c.createLinearGradient(d.x1,d.y1,d.x2,d.y2):c.createRadialGradient(d.x1,d.y1,d.r1,d.x2,d.y2,d.r2);for(let p of d.stops){let b=Math.min(1,Math.max(0,p.offset));m.addColorStop(b,`rgba(${Math.round(p.color[0]*255)}, ${Math.round(p.color[1]*255)}, ${Math.round(p.color[2]*255)}, ${p.color[3]})`)}if(c.fillStyle=m,d.gradientUnits==="percentage")c.fillRect(-2,-2,5,5);else{let p=ve(f),b=[Q(p,0,0),Q(p,a,0),Q(p,0,l),Q(p,a,l)];if(b.every(x=>isFinite(x.x)&&isFinite(x.y))){let x=Math.min(...b.map(S=>S.x))-2,g=Math.max(...b.map(S=>S.x))+2,y=Math.min(...b.map(S=>S.y))-2,v=Math.max(...b.map(S=>S.y))+2;c.fillRect(x,y,g-x,v-y)}else c.fillRect(-a-l,-a-l,(a+l)*3,(a+l)*3)}c.setTransform(1,0,0,1,0,0)}else c.fillStyle=e.color,c.fillRect(0,0,a,l);c.globalCompositeOperation="destination-in";let h=Lt(n);return h?qt(c,uo(t,o,h*r,a,l),null,0,0,a,l):qt(c,t,o,0,0,a,l),u},Mh=(n,e)=>{if(e.length===0)return null;let t=n.raw.fill;if(t==null||t===""||t==="transparent")return null;let r=Math.abs(n.matrix[0])*n.dims.x+Math.abs(n.matrix[2])*n.dims.y,o=Math.abs(n.matrix[1])*n.dims.x+Math.abs(n.matrix[3])*n.dims.y,i=4;for(let h of e)i=Math.max(i,Math.ceil(h.blur*2+Math.max(Math.abs(h.offsetX),Math.abs(h.offsetY))+4));let s=Math.ceil(r+i*2),a=Math.ceil(o+i*2);if(!(s>0)||!(a>0)||s>8192||a>8192)return null;let l=document.createElement("canvas");l.width=s,l.height=a;let u=l.getContext("2d");if(!u)return null;let c=n.matrix;u.setTransform(c[0],c[1],c[2],c[3],s/2,a/2);for(let h of e){if(u.filter=`drop-shadow(${h.offsetX}px ${h.offsetY}px ${h.blur}px ${h.color})`,u.fillStyle=Jr(n,u),!xr(u,n))return null;u.fill()}return u.filter="none",{canvas:l,w:s,h:a,quadW:s,quadH:a}},Rh=(n,e=1)=>{let t=Math.max(1,Math.ceil(n.dims.x*e)),r=Math.max(1,Math.ceil(n.dims.y*e));if(t>8192||r>8192)return null;let o=document.createElement("canvas");o.width=t,o.height=r;let i=o.getContext("2d");return!i||(i.setTransform(e,0,0,e,t/2,r/2),i.fillStyle="#fff",!xr(i,n))?null:(i.fill(n.raw.fillRule==="evenodd"?"evenodd":"nonzero"),o)},vr=(n,e,t,r=1,o=null)=>{if(!t)return null;let i=Math.max(1,Math.ceil(n.dims.x)),s=Math.max(1,Math.ceil(n.dims.y)),a=Math.ceil(i*r),l=Math.ceil(s*r);if(a>8192||l>8192)return null;let u=Lt(n),c=u?uo(t,o,u*r,a,l):t,h=document.createElement("canvas");h.width=a,h.height=l;let d=h.getContext("2d");if(!d)return null;qt(d,c,u?null:o,0,0,a,l),d.globalCompositeOperation="source-in",d.fillStyle=e.color,d.fillRect(0,0,a,l);let f=document.createElement("canvas");f.width=a,f.height=l;let m=f.getContext("2d");return m?(m.drawImage(h,0,0),m.globalCompositeOperation="destination-out",e.blur>0&&(m.filter=`blur(${e.blur}px)`),qt(m,c,u?null:o,e.offsetX,e.offsetY,a,l),m.filter="none",m.globalCompositeOperation="source-over",f):null},pn=(n,e,t,r=!0,o=1,i=null,s=!1)=>{if(!t||e.length===0)return[];let a=o,l=Math.max(1,Math.ceil(n.dims.x*a)),u=Math.max(1,Math.ceil(n.dims.y*a));if((l>8192||u>8192)&&(a=1,l=Math.max(1,Math.ceil(n.dims.x)),u=Math.max(1,Math.ceil(n.dims.y))),l>8192||u>8192)return[];let c=document.createElement("canvas");c.width=l,c.height=u;let h=c.getContext("2d",{willReadFrequently:!0});if(!h)return[];let d=Lt(n),f=n.dims.x*a,m=n.dims.y*a;gl(h,d?d*a:null,l/2,u/2,f,m,()=>qt(h,t,i,-f/2,-m/2,f,m));let p=[];for(let b=e.length-1;b>=0;b--){let x=e[b],g=x.width,y=x.alignment,v=y==="outside"?g:y==="center"?Math.ceil(g/2):0,S=v*a,w=Math.floor(l+S*2),R=Math.floor(u+S*2);if(w<=0||R<=0)continue;let P=document.createElement("canvas");P.width=w,P.height=R;let T=P.getContext("2d",{willReadFrequently:!0});if(!T)continue;T.drawImage(c,S,S);let C=bl(T.getImageData(0,0,w,R).data),E=lo(C,w,R),M=new Uint8Array(C.length);for(let U=0;U<C.length;U++)M[U]=C[U]?0:1;for(let U=0;U<w;U++)M[U]=1,M[U+(R-1)*w]=1;for(let U=0;U<R;U++)M[U*w]=1,M[w-1+U*w]=1;let k=lo(M,w,R),A=w*R,O=new Int32Array(A);for(let U=0;U<A;U++)O[U]=C[U]?-k[U]:E[U];let F=s?.5*a:0,G,Y;y==="inside"?(G=-g*a-F,Y=F):y==="center"?(G=-g/2*a-F,Y=g/2*a+F):(G=-F,Y=g*a+F);let _=Math.round(x.rgba[0]*255),D=Math.round(x.rgba[1]*255),I=Math.round(x.rgba[2]*255),W=Math.round(x.rgba[3]*255),j=x.kind==="gradient"&&x.decl?Mx(x.decl,l,u,S):null,H=document.createElement("canvas");H.width=w,H.height=R;let X=H.getContext("2d");if(!X)continue;let z=X.createImageData(w,R),$=z.data;for(let U=0;U<A;U++){let oe=O[U];if(oe>=G&&oe<Y){let ne=U*4;if(j){let de=j(U%w,U/w|0);$[ne]=de[0],$[ne+1]=de[1],$[ne+2]=de[2],$[ne+3]=de[3]}else $[ne]=_,$[ne+1]=D,$[ne+2]=I,$[ne+3]=W}}X.putImageData(z,0,0);let Z=document.createElement("canvas");Z.width=w,Z.height=R;let B=Z.getContext("2d");if(!B)continue;r&&B.drawImage(c,S,S),B.drawImage(H,0,0);let q=y==="outside"?g:y==="center"?g/2:0;p.push({canvas:Z,w,h:R,quadW:w/a,quadH:R/a,dx:v-q+x.offset.x,dy:v-q+x.offset.y})}return p},Ph=(n,e,t,r=1,o=null)=>{if(!t)return null;let i=r,s=Math.max(1,Math.ceil(n.dims.x*i)),a=Math.max(1,Math.ceil(n.dims.y*i));if((s>8192||a>8192)&&(i=1,s=Math.max(1,Math.ceil(n.dims.x)),a=Math.max(1,Math.ceil(n.dims.y))),s>8192||a>8192)return null;let l=document.createElement("canvas");l.width=s,l.height=a;let u=l.getContext("2d",{willReadFrequently:!0});if(!u)return null;let c=Lt(n),h=n.dims.x*i,d=n.dims.y*i;gl(u,c?c*i:null,s/2,a/2,h,d,()=>qt(u,t,o,-h/2,-d/2,h,d));let f=e.sizePx*i,m=e.style==="outer"||e.style==="emboss"||e.style==="pillow"?Math.ceil(f):0,p=s+m*2,b=a+m*2,x=document.createElement("canvas");x.width=p,x.height=b;let g=x.getContext("2d",{willReadFrequently:!0});if(!g)return null;g.drawImage(l,m,m);let y=bl(g.getImageData(0,0,p,b).data),v=lo(y,p,b),S=new Uint8Array(y.length);for(let T=0;T<y.length;T++)S[T]=y[T]?0:1;for(let T=0;T<p;T++)S[T]=1,S[T+(b-1)*p]=1;for(let T=0;T<b;T++)S[T*p]=1,S[p-1+T*p]=1;let w=lo(S,p,b),R=vh(w,v,y,p,b,{sizePx:f,angleDeg:e.angleDeg,altitudeDeg:e.altitudeDeg,strength:e.strength,directionDown:e.directionDown,technique:e.technique,style:e.style}),P=(T,C,E)=>{let M=document.createElement("canvas");M.width=p,M.height=b;let k=M.getContext("2d");if(!k)return M;let A=ee(C),O=Math.round(A[0]*255),F=Math.round(A[1]*255),G=Math.round(A[2]*255),Y=k.createImageData(p,b),_=Y.data;for(let D=0;D<T.length;D++){let I=T[D];if(I<=0)continue;let W=D*4;_[W]=O,_[W+1]=F,_[W+2]=G,_[W+3]=Math.round(Math.min(1,I*E)*255)}return k.putImageData(Y,0,0),M};return{highlight:P(R.highlight,e.highlight.color,e.highlight.opacity),shadow:P(R.shadow,e.shadow.color,e.shadow.opacity),w:p,h:b,quadW:p/i,quadH:b/i,dx:0,dy:0}};var kh=n=>yr(n),Qe=2,fo=(n,e)=>{let t=e.textLayout,r=e.textStyle,o=e.textStroke;n.textBaseline="alphabetic";for(let i of t.lines){let s=-t.width/2+i.leftOffset,a=e.contentTopY+i.baseline,l=i.charStyles[0],u=typeof l?.fill=="string"&&l.fill?l.fill:typeof e.raw.fill=="string"?e.raw.fill:null,c="",h=i.prefix?Tt(n,i,s,a,{fill:u,stroke:Oe(o,l)}):0,d="",f="",m=null,p=b=>{if(!c)return;n.font=d;let x=s+h;typeof f=="string"&&f?(n.fillStyle=f,n.fillText(c,x,a)):typeof e.raw.fill=="string"&&e.raw.fill&&(n.fillStyle=e.raw.fill,n.fillText(c,x,a)),m&&m.width>0&&(n.lineWidth=m.width,n.strokeStyle=m.color,n.strokeText(c,x,a)),c="",b<i.boxes.length&&(h=i.boxes[b].left)};for(let b=0;b<i.graphemes.length;b++){let x=i.charStyles[b],y=x!==void 0&&(x.fontSize!==void 0||x.fontFamily!==void 0||x.fontWeight!==void 0||x.fontStyle!==void 0)&&x?{...r,fontSize:x.fontSize??r.fontSize,fontFamily:x.fontFamily??r.fontFamily,fontWeight:x.fontWeight??r.fontWeight,fontStyle:x.fontStyle??r.fontStyle}:r,v=Me(y,y.fontSize),S=Oe(o,x),w=typeof x?.fill=="string"?x.fill:"",R=m;c&&(v!==d||S?.color!==R?.color||S?.width!==R?.width||w!==f)&&p(b),c||(d=v,m=S,f=w),c+=i.graphemes[b]}p(i.graphemes.length)}},wr=n=>{let e=0;for(let t of n.strokes)e=Math.max(e,t.alignment==="outside"?t.width:t.alignment==="center"?Math.ceil(t.width/2):0);for(let t of n.dropShadows)e=Math.max(e,Math.ceil(t.blur*2+Math.max(Math.abs(t.offsetX),Math.abs(t.offsetY))));for(let t of n.solidFills)e=Math.max(e,Math.ceil(Math.max(Math.abs(t.offset.x),Math.abs(t.offset.y))));return e},yl=(n,e,t)=>{let r=4;for(let m of n)r=Math.max(r,Math.ceil(m.blur*2+Math.max(Math.abs(m.offsetX),Math.abs(m.offsetY))+4));let o=e.width/t,i=e.height/t,s=Math.ceil(o+r*2),a=Math.ceil(i+r*2),l=Math.ceil(s*t),u=Math.ceil(a*t);if(!(l>0)||!(u>0)||l>8192||u>8192)return null;let c=document.createElement("canvas");c.width=l,c.height=u;let h=c.getContext("2d");if(!h)return null;let d=(l-e.width)/2,f=(u-e.height)/2;for(let m of n)h.filter=`drop-shadow(${m.offsetX*t}px ${m.offsetY*t}px ${m.blur*t}px ${m.color})`,h.drawImage(e,d,f);return h.filter="none",h.globalCompositeOperation="destination-out",h.drawImage(e,d,f),{canvas:c,w:s,h:a}},mo=(n,e,t)=>{if(!t||t.dropShadows.length===0&&t.innerShadows.length===0&&t.solidFills.length===0&&t.strokes.length===0)return;let r=ho(e,Qe);if(!r)return;let o=e.dims.x,i=e.dims.y;if(t.dropShadows.length){let l=yl(t.dropShadows,r,Qe);l&&(n.save(),n.globalCompositeOperation="destination-over",n.drawImage(l.canvas,-l.w/2,-l.h/2,l.w,l.h),n.restore())}let s=(l,u)=>{if(!l){u();return}n.save(),n.globalCompositeOperation=l,u(),n.restore()};for(let l of t.innerShadows){let u=vr(e,l,r,Qe);u&&s(l.blendMode,()=>n.drawImage(u,-o/2,-i/2,o,i))}for(let l of t.solidFills){let u=Sr(e,l,r,Qe);u&&s(l.blendMode,()=>n.drawImage(u,-o/2+l.offset.x,-i/2+l.offset.y,o,i))}pn(e,t.strokes,r,!1,Math.min(2,Qe),null,!0).forEach((l,u)=>{let c=t.strokes[t.strokes.length-1-u];s(c?.blendMode,()=>n.drawImage(l.canvas,-l.quadW/2+l.dx,-l.quadH/2+l.dy,l.quadW,l.quadH))})},Sl=(n,e,t=null)=>{let r=n.textLayout,o=Number(n.raw.fontSize)||40,i=Math.max(-1,Math.min(1,Number(n.raw.warpStrength)||0)),s=typeof n.raw.width=="number"?n.raw.width:r.width,a=typeof n.raw.height=="number"?n.raw.height:r.height,l=o*(e==="arch"?.6:.5),u=Math.max(r.width,s,o),c=Math.max(a,o),h=e==="arch"?c*Math.max(0,i):0,d=e==="flag"?Math.abs(i)*(a||o)*.3:0,f=1+Math.abs(i),m=t?wr(t):0,p=Math.ceil(u+l*2+m*2),b=Math.ceil(e==="arch"?c+l*2+m*2+h:e==="flag"?(a||o)+d*2+l*2+m*2:(a||o)*f+l*2+m*2),x=p*Qe,g=b*Qe;if(!(x>0)||!(g>0)||x>8192||g>8192)return null;let y=document.createElement("canvas");y.width=x,y.height=g;let v=y.getContext("2d",{willReadFrequently:!0});if(!v)return null;let S=e==="arch"?h/2*Qe:0;v.setTransform(Qe,0,0,Qe,x/2,g/2+S),fo(v,n),mo(v,n,t);let w=v.getImageData(0,0,x,g),R=new Uint32Array(w.data.buffer),P=x,T=0,C=g,E=0,M=!1;for(let _=0;_<g;_++)for(let D=0;D<x;D++)(R[_*x+D]>>>24&255)>10&&(M=!0,D<P&&(P=D),D>T&&(T=D),_<C&&(C=_),_>E&&(E=_));let k=M?(P+T)/2:x/2,A=M?E:g-1,O=M?Math.max(1,T-P)/2:x/2,F=v.createImageData(x,g),G=new Uint32Array(F.data.buffer),Y=(_,D)=>{let I=Math.floor(D),W=I+1;if(I<0||W>=g)return 0;let j=D-I,H=R[I*x+_],X=R[W*x+_],z=H>>>24&255,$=X>>>24&255;if(z<=10&&$<=10)return 0;let Z=Math.round((H&255)*(1-j)+(X&255)*j),B=Math.round((H>>>8&255)*(1-j)+(X>>>8&255)*j),q=Math.round((H>>>16&255)*(1-j)+(X>>>16&255)*j);return Math.round(z*(1-j)+$*j)<<24|q<<16|B<<8|Z};if(e==="flag")for(let _=0;_<x;_++){let D=O>0?(_-k)/O:0,I=Math.sin(D*Math.PI)*d*Qe*i;for(let W=0;W<g;W++)G[W*x+_]=Y(_,W+I)}else if(e==="arch")for(let _=0;_<x;_++){let D=Math.max(-1,Math.min(1,(_-k)/O)),I=Math.sqrt(Math.max(0,1-D*D)),W=I*I*(3-2*I),j=i>0?Math.pow(W,2.5):W,H=Math.min(1+Math.max(0,i),Math.max(.05,1+i*j));for(let X=0;X<=A;X++){let z=A-X;G[X*x+_]=Y(_,A-z/H)}}else{let _=M?(C+E)/2:g/2;for(let D=0;D<x;D++){let I=O>0?(D-k)/O:0,W=1+i*(I*I-.5);W=Math.min(1+Math.abs(i),Math.max(.4,W));for(let j=0;j<g;j++)G[j*x+D]=Y(D,_+(j-_)/W)}}return v.setTransform(1,0,0,1,0,0),v.clearRect(0,0,x,g),v.putImageData(F,0,0),{canvas:y,logicalW:p,logicalH:b}},Bi=(n,e)=>{let t=e.textLayout,r=e.textStyle,o=e.textStroke,i=typeof e.raw.fill=="string"?e.raw.fill:"",s=Number(e.raw.textOffsetY)||0;n.textBaseline="alphabetic";let a=0;for(let l of t.lines){let u=-t.width/2+l.leftOffset,c=e.contentTopY+l.baseline,h=l.charStyles[0],d=typeof h?.fill=="string"&&h.fill?h.fill:i||null;l.prefix&&Tt(n,l,u,c,{fill:d,stroke:Oe(o,h)});let f=$t(l,u,c,r,r.charSpacing??0);for(let m=0;m<f.length;m++){let p=l.charStyles[m],b=dn(r,p);n.font=Me(b,b.fontSize);let x=typeof p?.fill=="string"&&p.fill?p.fill:i,g=Oe(o,p),y={...f[m],y:f[m].y+wt(s,b.fontSize,a+m)};x&&(n.fillStyle=x,jt(n,y,"fillText")),g&&g.width>0&&(n.lineWidth=g.width,n.strokeStyle=g.color,jt(n,y,"strokeText"))}a+=l.graphemes.length}},Rx=(n,e)=>{let t=e?wr(e):0,r=Math.ceil(n.dims.x+t*2),o=Math.ceil(n.dims.y+t*2),i=r*Qe,s=o*Qe;if(!(i>0)||!(s>0)||i>8192||s>8192)return null;let a=document.createElement("canvas");a.width=i,a.height=s;let l=a.getContext("2d");return l?(l.setTransform(Qe,0,0,Qe,i/2,s/2),n.raw.vertical===!0?Bi(l,n):fo(l,n),mo(l,n,e),{canvas:a,logicalW:r,logicalH:o}):null};var Nh=2,bn=(n,e)=>e!==void 0&&(e.fontSize!==void 0||e.fontFamily!==void 0||e.fontWeight!==void 0||e.fontStyle!==void 0)&&e?{...n,fontSize:e.fontSize??n.fontSize,fontFamily:e.fontFamily??n.fontFamily,fontWeight:e.fontWeight??n.fontWeight,fontStyle:e.fontStyle??n.fontStyle}:n,Lh=(n,e,t,r)=>{let o=e.textStyle,i=e.textStroke,s=e.raw.strokeVisible===!0,a=e.paintFirst==="stroke",l=typeof e.raw.fill=="string"?e.raw.fill:"";for(let u of t.chars){let c=e.textLayout.lines[u.line]?.charStyles[u.index],h=bn(o,c),d=r==="silhouette"?"#ffffff":typeof c?.fill=="string"&&c.fill?c.fill:l,f=r==="silhouette"?null:s?Oe(i,c):null,m=Me(h,h.fontSize);n.save(),n.translate(u.x,u.y),n.rotate(u.rotation),n.font=m;let p=()=>{d&&(n.fillStyle=d,n.fillText(u.char,0,0))},b=()=>{f&&f.width>0&&(n.lineWidth=f.width,n.strokeStyle=f.color,n.strokeText(u.char,0,0))};a?(b(),p()):(p(),b()),n.restore()}},Ah=(n,e,t=Nh)=>{let r=Math.max(1,Math.ceil(n.dims.x*t)),o=Math.max(1,Math.ceil(n.dims.y*t));if(r>8192||o>8192)return null;let i=document.createElement("canvas");i.width=r,i.height=o;let s=i.getContext("2d");return s?(s.setTransform(t,0,0,t,r/2-e.contentOffsetX*t,o/2-e.contentOffsetY*t),s.textBaseline="alphabetic",s.textAlign="center",Lh(s,n,e,"silhouette"),i):null},Px=(n,e,t,r,o)=>{if(r.dropShadows.length===0&&r.innerShadows.length===0&&r.solidFills.length===0&&r.strokes.length===0)return;let i=e.dims.x,s=e.dims.y,a=t.contentOffsetX,l=t.contentOffsetY,u=(c,h)=>{if(!c){h();return}n.save(),n.globalCompositeOperation=c,h(),n.restore()};if(r.dropShadows.length||r.solidFills.length||r.innerShadows.length){let c=Ah(e,t,o);if(c){if(r.dropShadows.length){let h=yl(r.dropShadows,c,o);h&&(n.save(),n.globalCompositeOperation="destination-over",n.drawImage(h.canvas,a-h.w/2,l-h.h/2,h.w,h.h),n.restore())}for(let h of r.innerShadows){let d=vr(e,h,c,o);d&&u(h.blendMode,()=>n.drawImage(d,a-i/2,l-s/2,i,s))}for(let h of r.solidFills){let d=Sr(e,h,c,o);d&&u(h.blendMode,()=>n.drawImage(d,a-i/2+h.offset.x,l-s/2+h.offset.y,i,s))}}}if(r.strokes.length){let c=Math.min(Math.max(2,o),Di(e)),h=Ah(e,t,c);h&&pn(e,r.strokes,h,!1,c,null,!0).forEach((f,m)=>{let p=r.strokes[r.strokes.length-1-m];u(p?.blendMode,()=>n.drawImage(f.canvas,a-f.quadW/2+f.dx,l-f.quadH/2+f.dy,f.quadW,f.quadH))})}},vl=(n,e,t=null,r=Nh)=>{let o=Et(n.textLayout,n.raw,n.textStyle.lineHeight??1.16),i=t?wr(t):0,s=o.width+i*2,a=o.height+i*2,l=Math.ceil(s*r),u=Math.ceil(a*r);if(!(l>0)||!(u>0)||l>8192||u>8192)return null;let c=document.createElement("canvas");c.width=l,c.height=u;let h=c.getContext("2d");return h?(h.setTransform(r,0,0,r,l/2-o.contentOffsetX*r,u/2-o.contentOffsetY*r),h.textBaseline="alphabetic",h.textAlign="center",Lh(h,n,o,"render"),t&&Px(h,n,o,t,r),{canvas:c,logicalW:s,logicalH:a}):null};var Tr=n=>{if(Ke(n)!=="scroll")return null;let e=typeof n.scrollSpeed=="number"&&Number.isFinite(n.scrollSpeed)?n.scrollSpeed:50;return{direction:n.scrollDirection==="right-to-left"?"right-to-left":"left-to-right",speed:e,enabled:n.scrollEnabled===void 0?!0:n.scrollEnabled===!0}},kx=(n,e,t,r)=>{let o=t+e,i=n.direction==="left-to-right"?-e/2-t+r:e/2-r,s=n.direction==="left-to-right"?o:-o;return{copy1:i,copy2:i+s}},Ih=n=>{let e=Tr(n.raw);return e?{target:n,viewWidth:n.dims.x,textTotalWidth:n.textTotalWidth,scrollSpeed:e.speed,scrollDirection:e.direction,scrollEnabled:e.enabled}:null},Ax=n=>`rgba(${Math.round(n.color[0]*255)},${Math.round(n.color[1]*255)},${Math.round(n.color[2]*255)},${n.color[3]})`,_h=(n,e,t)=>{let r=Tr(n.raw);if(!r||!r.enabled)return null;let o=n.dims.x,i=n.dims.y;if(!(o>0)||!(i>0))return null;let s=Math.max(1,e);if((o*s>8192||i*s>8192)&&(s=Math.max(1,Math.floor(Math.min(8192/o,8192/i))),o*s>8192||i*s>8192))return null;let a=Math.ceil(o*s),l=Math.ceil(i*s);if(!(a>0)||!(l>0))return null;let u=document.createElement("canvas");u.width=a,u.height=l;let c=u.getContext("2d");if(!c)return null;c.setTransform(s,0,0,s,a/2,l/2),c.textBaseline="alphabetic",c.textAlign="left",c.beginPath(),c.rect(-o/2,-i/2,o,i),c.clip();let h=n.textTotalWidth,{copy1:d,copy2:f}=kx(r,o,h,t);for(let m of[d,f])c.save(),c.translate(m,0),Nx(c,n),c.restore();return{canvas:u,logicalW:o,logicalH:i}},Nx=(n,e)=>{let t=e.paintFirst==="stroke"?["stroke","fill"]:["fill","stroke"];for(let r of t)Lx(n,e,r)},Lx=(n,e,t)=>{let r=e.textLayout,o=e.textStyle,i=e.textStroke,s=e.raw,a=e.fillPaint,l=typeof s.fill=="string"?s.fill:a?.kind==="gradient"&&a.decl.stops.length?Ax(a.decl.stops[0]):"",u=s.vertical===!0,c=Number(s.charSpacing)||0,h=t==="stroke"&&Array.isArray(s.strokeDashArray)?s.strokeDashArray.filter(f=>typeof f=="number"&&Number.isFinite(f)):null;if(t==="fill"&&!l&&!r.lines.some(f=>f.charStyles.some(m=>typeof m?.fill=="string"))||t==="stroke"&&!i)return;h&&h.length&&(n.setLineDash(h),n.lineDashOffset=Number(s.strokeDashOffset)||0);let d=f=>{n.lineWidth=f.width,n.strokeStyle=f.color,n.lineJoin=typeof s.strokeLineJoin=="string"?s.strokeLineJoin:"miter",n.lineCap=typeof s.strokeLineCap=="string"?s.strokeLineCap:"butt",n.miterLimit=Number(s.strokeMiterLimit)||4};for(let f of r.lines){let m=-r.width/2+f.leftOffset,p=e.contentTopY+f.baseline,b=f.prefix?.width??0;if(f.prefix){let x=f.charStyles[0];if(t==="fill"){let g=typeof x?.fill=="string"&&x.fill?x.fill:l;g&&Tt(n,f,m,p,{fill:g})}else Tt(n,f,m,p,{stroke:Oe(i,x)})}if(u){let x=$t(f,m,p,o,c);for(let g=0;g<x.length;g++){let y=f.charStyles[g];if(t==="fill"){let S=typeof y?.fill=="string"&&y.fill?y.fill:l;if(!S)continue;n.fillStyle=S}else{let S=Oe(i,y);if(!S||S.width<=0)continue;d(S)}let v=bn(o,y);n.font=Me(v,v.fontSize),jt(n,x[g],t==="fill"?"fillText":"strokeText")}continue}if(h&&h.length){let x="",g=b,y="",v=null,S,w=C=>{if(!x)return;let E=v;E&&E.width>0&&(n.font=y,d(E),n.strokeText(x,m+g,p)),x="",C<f.boxes.length&&(g=f.boxes[C].left)},R=Ut(s.textAlign),P=s.textAlign===fe.DISPERSE,T=to(s.textAlign)&&f.graphemes.some(C=>io.test(C));for(let C=0;C<f.graphemes.length;C++){let E=f.charStyles[C],M=bn(o,E),k=Me(M,M.fontSize),A=Oe(i,E),O=E?.fill??"",F=v;x&&(k!==y||A?.color!==F?.color||A?.width!==F?.width||O!==S)&&w(C),x||(y=k,v=A,S=O),x+=f.graphemes[C],(c||(R||P)&&/[ \t\r]/.test(f.graphemes[C])||T)&&w(C+1)}w(f.graphemes.length);continue}for(let x=0;x<f.graphemes.length;x++){let g=f.charStyles[x];if(t==="fill"){let S=typeof g?.fill=="string"&&g.fill?g.fill:l;if(!S)continue;n.fillStyle=S}else{let S=Oe(i,g);if(!S||S.width<=0)continue;d(S)}let y=bn(o,g);n.font=Me(y,y.fontSize);let v=m+f.boxes[x].left;t==="fill"?n.fillText(f.graphemes[x],v,p):n.strokeText(f.graphemes[x],v,p)}}};var Dh=(n,e)=>{let t=[],r=Ai(n);r&&t.push({left:-r.logicalW/2,top:-r.logicalH/2,right:r.logicalW/2,bottom:r.logicalH/2});let o=n.raw;if(Array.isArray(o.texts)&&typeof o.renderSrc!="string"&&!yr(o)&&!Kn(o)&&!Ge(o)&&!Tr(o)?.enabled){let h=n.textLayout,d=Qn(String(o.text??""),h,o.texts,n.contentTopY,n.textStyle.fontSize);if(d&&Math.ceil(h.width+d.padX*2)<=8192&&Math.ceil(h.height+d.padY*2)<=8192){let f=d.inkBounds;t.push({left:f.left-2,top:f.top-2,right:f.right+2,bottom:f.bottom+2})}}if(!t.length)return e;let i=Wn(e),{left:s,top:a,right:l,bottom:u}=i,c=n.matrix;for(let h of t)for(let[d,f]of[[h.left,h.top],[h.right,h.top],[h.right,h.bottom],[h.left,h.bottom]]){let m=Q(c,d,f);s=Math.min(s,m.x),a=Math.min(a,m.y),l=Math.max(l,m.x),u=Math.max(u,m.y)}return{tl:{x:s,y:a},tr:{x:l,y:a},br:{x:l,y:u},bl:{x:s,y:u}}};var Zn=n=>{if(!n||typeof n!="object")return null;let e=n;if(typeof e.rows!="number"||typeof e.cols!="number"||!Array.isArray(e.pieces)||e.pieces.length===0)return null;let t=[];for(let r of e.pieces){if(!r||typeof r!="object")continue;let o=r;typeof o.row!="number"||typeof o.col!="number"||t.push({id:r.id,row:o.row,col:o.col,rowSpan:r.rowSpan,colSpan:r.colSpan})}return t.length>0?{rows:e.rows,cols:e.cols,pieces:t}:null},wl=(n,e)=>{let{rows:t,cols:r,pieces:o}=n,i=Math.max(0,e.width-e.groupPadding*2),s=Math.max(0,e.height-e.groupPadding*2),a=e.hGap*Math.max(0,r-1),l=e.vGap*Math.max(0,t-1),u=r>0?(i-a)/r:0,c=t>0?(s-l)/t:0,h=u+e.hGap,d=c+e.vGap,f=(r-1)/2,m=(t-1)/2;return o.map(p=>{let b=p.colSpan??1,x=p.rowSpan??1,g=Math.max(u*b+e.hGap*(b-1),0),y=Math.max(c*x+e.vGap*(x-1),0),v=p.col+(b-1)/2,S=p.row+(x-1)/2;return{w:g,h:y,cx:(v-f)*h,cy:(S-m)*d}})},Ix=(n,e)=>e&&e.naturalWidth&&e.naturalHeight?{w:e.naturalWidth,h:e.naturalHeight}:{w:n?.width??0,h:n?.height??0},Fh=(n,e,t)=>{let r=typeof e.widthRatio=="number"&&isFinite(e.widthRatio)&&e.widthRatio>0?e.widthRatio:1,o=typeof e.heightRatio=="number"&&isFinite(e.heightRatio)&&e.heightRatio>0?e.heightRatio:1,i=r!==1,s=o!==1;if(!i&&!s||n.masks.length===0)return!1;let a=n.width||0,l=n.height||0;return i&&a&&(n.width=a*r,n.hGap*=r,n.groupPadding*=r),s&&l&&(n.height=l*o,n.vGap*=o,n.groupPadding*=o),n.masks.forEach((u,c)=>{let h=u.width||0,d=u.height||0,f=i?Math.max(h*r,1):h,m=s?Math.max(d*o,1):d,p=i?(u.left||0)*r:u.left,b=s?(u.top||0)*o:u.top;if(u.left=p,u.top=b,u.width=f,u.height=m,u.clip){let x=i&&h?f/h:1,g=s&&d?m/d:1,y=t?.[c]??Ix(u.clip,null);if(y.w&&y.h){let v=Math.max(h/y.w,d/y.h),S=Math.max(f/y.w,m/y.h),w=u.clip.scaleX||u.clip.scaleY||1,R=v?w/v:1,P=S*(R||1);u.clip.scaleX=P,u.clip.scaleY=P}u.clip.clipX=(u.clip.clipX||0)*x,u.clip.clipY=(u.clip.clipY||0)*g}}),!0},Wi=n=>{let e=n.clipImage;if(!e||typeof e!="object"||typeof e.src!="string")return null;let t=e;return{scaleX:t.scaleX??1,scaleY:t.scaleY??1,clipX:t.clipX??0,clipY:t.clipY??0,width:t.width??0,height:t.height??0}};var _x=(n,e)=>{if(typeof n.colStart!="number"||typeof n.colEnd!="number"||e<=0)return 0;let t=0;return n.colStart>0&&(t+=1),n.colEnd<e-1&&(t+=1),t},Dx=(n,e)=>{if(typeof n.rowStart!="number"||typeof n.rowEnd!="number"||e<=0)return 0;let t=0;return n.rowStart>0&&(t+=1),n.rowEnd<e-1&&(t+=1),t},It=n=>({left:n.left-n.width/2,right:n.left+n.width/2,top:n.top-n.height/2,bottom:n.top+n.height/2}),Er=(n,e,t,r)=>{if(!n.clip)return;let o=n.width,i=n.height,s=e?o/e:1,a=t?i/t:1,l=r??{w:n.clip.width,h:n.clip.height};if(l.w&&l.h){let u=Math.max(e/l.w,t/l.h),c=Math.max(o/l.w,i/l.h),h=n.clip.scaleX||n.clip.scaleY||1,d=u?h/u:1,f=c*(d||1);n.clip.scaleX=f,n.clip.scaleY=f}n.clip.clipX=(n.clip.clipX||0)*s,n.clip.clipY=(n.clip.clipY||0)*a},Oh=(n,e,t,r="right",o)=>{let i=n.masks[e];if(!i)return!1;let s=Math.max(n.innerRadius+1,12);if(t<=s||!n.layoutWidth)return!1;let a=n.groupPadding||0,l=Math.max(0,n.layoutWidth-a*2),u=1,c=i.width||0,h=i.height||0;if(!l||!c)return!1;let d=n.innerRadius+1,f=_x(i,n.cols)*d;if(t<f)return!1;let m=l-f,p=Math.min(t,Math.max(u,m)),b=It(i),x=n.hGap||0,g=[],y=null,v=5,S=.3;n.masks.forEach((B,q)=>{if(q===e)return;let U=It(B),oe=Math.min(b.bottom,U.bottom)-Math.max(b.top,U.top);if(!(oe<=0||oe<Math.min(i.height,B.height)*S))if(r==="right"){if(U.left<=i.left)return;let ne=U.left;y===null||ne<y-v?(y=ne,g.length=0,g.push(q)):Math.abs(ne-y)<=v&&g.push(q)}else{if(U.right>=i.left)return;let ne=U.right;y===null||ne>y+v?(y=ne,g.length=0,g.push(q)):Math.abs(ne-y)<=v&&g.push(q)}});let w=B=>o?.[B]??null;if(!g.length){let B=l/2,q=r==="right"?B-b.left:b.right+B,U=Math.max(s,Math.min(p,Math.max(s,q)));return U===c?!1:(i.left=r==="right"?b.left+U/2:b.right-U/2,i.width=U,Er(i,c,h,w(e)),!0)}let R=1/0,P=-1/0;for(let B of g){let q=It(n.masks[B]);q.left<R&&(R=q.left),q.right>P&&(P=q.right)}let T=r==="right"?b.left:b.right,C=B=>{let q=It(n.masks[B]);return r==="right"?q.right:q.left},E=1/0;for(let B of g){let q=(r==="right"?C(B)-T:T-C(B))-x-s;q<E&&(E=q)}let M=Math.max(s,Math.min(p,Math.max(s,E))),k=r==="right"?T+M:T-M;for(let B of g)if((r==="right"?C(B)-k:k-C(B))-x<s-1e-6)return!1;if(M<=0)return!1;i.left=r==="right"?T+M/2:T-M/2,i.width=M;let A=new Map;A.set(e,{width:c,height:h});for(let B of g){let q=n.masks[B];A.set(B,{width:q.width,height:q.height});let U=C(B);r==="right"?(q.width=U-k-x,q.left=(k+x+U)/2):(q.width=k-x-U,q.left=(k-x+U)/2)}for(let B of[e,...g]){let q=A.get(B);Er(n.masks[B],q.width,q.height,w(B))}let O=It(i),F=O.left,G=O.right,Y=It(n.masks[g[0]]),_=Y.left,D=Y.right,I=r==="right"?b.right:b.left,W=r==="right"?G:F,j=new Set(g),H=typeof i.colStart=="number"&&typeof i.colEnd=="number"?{colStart:i.colStart,colEnd:i.colEnd}:null,X=n.masks[g[0]],z=X&&typeof X.colStart=="number"&&typeof X.colEnd=="number"?{colStart:X.colStart,colEnd:X.colEnd}:null,$=n.cols>0&&!!H&&!!z,Z=(B,q,U)=>{let oe=n.masks[B],ne=oe.width,de=oe.height,Pe=Math.max(u,U-q);oe.left=(q+U)/2,oe.width=Pe,Er(oe,ne,de,w(B))};return n.masks.forEach((B,q)=>{if(q===e||j.has(q))return;let U=It(B),oe=U.left,ne=U.right;if($&&H&&z&&typeof B.colStart=="number"&&typeof B.colEnd=="number"){if(B.colStart===H.colStart&&B.colEnd===H.colEnd){Z(q,F,G);return}if(B.colStart===z.colStart&&B.colEnd===z.colEnd){Z(q,_,D);return}let Ee=r==="right"?H.colEnd+1:H.colStart,ue=B.colStart===Ee,ge=B.colEnd+1===Ee;if(!ue&&!ge)return;let pe=ue?W+(r==="right"?x:0):oe,Te=ge?W-(r==="left"?x:0):ne;if(Te-pe<=0)return;Z(q,pe,Te);return}let de=.5;if(Math.abs(oe-b.left)<de&&Math.abs(ne-b.right)<de){Z(q,F,G);return}if(Math.abs(oe-R)<de&&Math.abs(ne-P)<de){Z(q,_,D);return}let Pe=Math.abs(oe-I)<de,De=Math.abs(ne-I)<de;if(!Pe&&!De)return;let nt=Pe?W:oe,ke=De?W:ne;ke-nt<=0||Z(q,nt,ke)}),i.width!==c},Bh=(n,e,t,r="bottom",o)=>{let i=n.masks[e];if(!i)return!1;let s=Math.max(n.innerRadius+1,12);if(t<=s||!n.layoutHeight)return!1;let a=n.groupPadding||0,l=Math.max(0,n.layoutHeight-a*2),u=1,c=i.height||0,h=i.width||0;if(!l||!c)return!1;let d=n.innerRadius+1,f=Dx(i,n.rows)*d;if(t<f)return!1;let m=l-f,p=Math.min(t,Math.max(u,m)),b=It(i),x=n.vGap||0,g=-1,y=0,v=0,S=.3;n.masks.forEach((ue,ge)=>{if(ge===e)return;let pe=It(ue),Te=Math.min(b.right,pe.right)-Math.max(b.left,pe.left);if(!(Te<=0||Te<Math.min(i.width,ue.width)*S))if(r==="bottom"){if(pe.top<=i.top)return;(g===-1||pe.top<y)&&(g=ge,y=pe.top,v=pe.bottom)}else{if(pe.bottom>=i.top)return;(g===-1||pe.bottom>v)&&(g=ge,y=pe.top,v=pe.bottom)}});let w=ue=>o?.[ue]??null;if(g===-1){let ue=l/2,ge=r==="bottom"?ue-b.top:b.bottom+ue,pe=Math.max(s,Math.min(p,Math.max(s,ge)));return pe===c?!1:(i.top=r==="bottom"?b.top+pe/2:b.bottom-pe/2,i.height=pe,Er(i,h,c,w(e)),!0)}let R=r==="bottom"?b.top:y,P=r==="bottom"?v:b.bottom,T=P-R,C=Math.max(s,T-x-s),E=Math.max(s,Math.min(p,C)),M=T-x-E;if(M<s){let ue=T-x-s;if(ue<s||(E=Math.max(s,Math.min(p,ue)),M=T-x-E,M<s))return!1}if(E<=0||M<=0)return!1;let k,A;r==="bottom"?(k=R+E/2,A=P-M/2):(A=R+M/2,k=P-E/2);let O=new Map;O.set(e,{width:h,height:c}),O.set(g,{width:n.masks[g].width,height:n.masks[g].height}),i.top=k,i.height=E;let F=n.masks[g];F.top=A,F.height=M;for(let ue of[e,g]){let ge=O.get(ue);Er(n.masks[ue],ge.width,ge.height,w(ue))}let G=k-E/2,Y=k+E/2,_=A-M/2,D=A+M/2,I=r==="bottom",W=I?G:_,j=I?Y:D,H=I?_:G,X=I?D:Y,z=I?b.top:y,$=I?b.bottom:v,Z=I?y:b.top,B=I?v:b.bottom,q=r==="bottom"?b.bottom:b.top,U=r==="bottom"?Y:G,oe=typeof i.rowStart=="number"&&typeof i.rowEnd=="number"?{rowStart:i.rowStart,rowEnd:i.rowEnd}:null,ne=n.masks[g],de=ne&&typeof ne.rowStart=="number"&&typeof ne.rowEnd=="number"?{rowStart:ne.rowStart,rowEnd:ne.rowEnd}:null,Pe=n.rows>0&&!!oe&&!!de,De=Pe&&oe&&de?oe.rowStart<=de.rowStart?oe:de:null,nt=Pe&&oe&&de?De===oe?de:oe:null,ke=De?De.rowEnd+1:void 0,Ee=(ue,ge,pe)=>{let Te=n.masks[ue],rt=Te.width,qe=Te.height,Ye=Math.max(u,pe-ge);Te.top=(ge+pe)/2,Te.height=Ye,Er(Te,rt,qe,w(ue))};return n.masks.forEach((ue,ge)=>{if(ge===e||ge===g)return;let pe=It(ue),Te=pe.top,rt=pe.bottom;if(Pe&&De&&nt&&ke!==void 0&&typeof ue.rowStart=="number"&&typeof ue.rowEnd=="number"){if(ue.rowStart===De.rowStart&&ue.rowEnd===De.rowEnd){Ee(ge,W,j);return}if(ue.rowStart===nt.rowStart&&ue.rowEnd===nt.rowEnd){Ee(ge,H,X);return}let yt=ue.rowStart===ke,St=ue.rowEnd+1===ke;if(!yt&&!St)return;let Dn=yt?U+(r==="bottom"?x:0):Te,Fn=St?U-(r==="top"?x:0):rt;if(Fn-Dn<=0)return;Ee(ge,Dn,Fn);return}let qe=.5;if(Math.abs(Te-z)<qe&&Math.abs(rt-$)<qe){Ee(ge,W,j);return}if(Math.abs(Te-Z)<qe&&Math.abs(rt-B)<qe){Ee(ge,H,X);return}let Ye=Math.abs(Te-q)<qe,bt=Math.abs(rt-q)<qe;if(!Ye&&!bt)return;let xt=Ye?U:Te,gt=bt?U:rt;gt-xt<=0||Ee(ge,xt,gt)}),i.height!==c};var Wh=(n,e,t=[])=>{let r=n.layoutConfig,o=r&&typeof r=="object"&&Array.isArray(r.pieces)?r.pieces:[],i=e.map(u=>({left:u.left??0,top:u.top??0,width:u.width??0,height:u.height??0,clip:Wi(u)})),s=e.map((u,c)=>{let h=u.clipImage;if(!h||typeof h.src!="string")return null;let d=t[c];return d&&d.naturalWidth&&d.naturalHeight?{w:d.naturalWidth,h:d.naturalHeight}:{w:h.width??0,h:h.height??0}});o.forEach((u,c)=>{let h=i[c];!h||typeof u.col!="number"||typeof u.row!="number"||(h.colStart=u.col,h.colEnd=u.col+(u.colSpan??1)-1,h.rowStart=u.row,h.rowEnd=u.row+(u.rowSpan??1)-1)});let a={layoutWidth:n.layoutWidth??600,layoutHeight:n.layoutHeight??600,hGap:n.hGap??12,vGap:n.vGap??12,groupPadding:n.groupPadding??0,innerRadius:n.innerRadius??12,cols:(r&&typeof r.cols=="number"?r.cols:0)||1,rows:(r&&typeof r.rows=="number"?r.rows:0)||1,masks:i},l=o.filter(u=>typeof u.row=="number"&&typeof u.col=="number").map(u=>({row:u.row,col:u.col,rowSpan:u.rowSpan,colSpan:u.colSpan}));return{state:a,pieces:l,clipSizes:s}},Hh=(n,e,t)=>{if(e<=1)return null;let r=[];n.forEach((o,i)=>{let s=o.col,a=o.col+(o.colSpan??1)-1;s===t&&(o.colSpan??1)===1?r.push(i):t>=s&&t<=a&&(o.colSpan=(o.colSpan??1)-1)}),r.forEach(o=>{let i=n[o],s=t>0?t-1:t+1,a=n.find((l,u)=>!r.includes(u)&&l.row===i.row&&l.col<=s&&l.col+(l.colSpan??1)-1>=s);a&&(a.colSpan=(a.colSpan??1)+1,a.col>t&&(a.col=t))}),n.forEach(o=>{o.col>t&&(o.col-=1)});for(let o of[...r].sort((i,s)=>s-i))n.splice(o,1);return{removed:r}},Gh=(n,e,t)=>{if(e<=1)return null;let r=[];n.forEach((o,i)=>{let s=o.row,a=o.row+(o.rowSpan??1)-1;s===t&&(o.rowSpan??1)===1?r.push(i):t>=s&&t<=a&&(o.rowSpan=(o.rowSpan??1)-1)}),r.forEach(o=>{let i=n[o],s=t>0?t-1:t+1,a=n.find((l,u)=>!r.includes(u)&&l.col===i.col&&l.row<=s&&l.row+(l.rowSpan??1)-1>=s);a&&(a.rowSpan=(a.rowSpan??1)+1,a.row>t&&(a.row=t))}),n.forEach(o=>{o.row>t&&(o.row-=1)});for(let o of[...r].sort((i,s)=>s-i))n.splice(o,1);return{removed:r}},Xh=(n,e)=>{let t=n.findIndex(h=>h.row===e.row&&h.col===e.col);if(t===-1||n.length<=1)return null;let r=n[t],o=r.row,i=r.col,s=r.rowSpan??1,a=r.colSpan??1,l=[],u="v",c=n.filter(h=>h!==r&&h.row+(h.rowSpan??1)===o&&h.col>=i&&h.col+(h.colSpan??1)<=i+a);if(c.reduce((h,d)=>h+(d.colSpan??1),0)===a)l=c,u="v";else{let h=n.filter(d=>d!==r&&d.row===o+s&&d.col>=i&&d.col+(d.colSpan??1)<=i+a);if(h.reduce((d,f)=>d+(f.colSpan??1),0)===a)l=h,u="v",l.forEach(d=>d.row=o);else{let d=n.filter(f=>f!==r&&f.col+(f.colSpan??1)===i&&f.row>=o&&f.row+(f.rowSpan??1)<=o+s);if(d.reduce((f,m)=>f+(m.rowSpan??1),0)===s)l=d,u="h";else{let f=n.filter(m=>m!==r&&m.col===i+a&&m.row>=o&&m.row+(m.rowSpan??1)<=o+s);f.reduce((m,p)=>m+(p.rowSpan??1),0)===s&&(l=f,u="h",l.forEach(m=>m.col=i))}}}return l.length>0&&l.forEach(h=>{u==="v"?h.rowSpan=(h.rowSpan??1)+s:h.colSpan=(h.colSpan??1)+a}),n.splice(t,1),{removed:[t]}};var _t=n=>{let e=new Map;for(let t of n)e.set(`${t.row},${t.col}`,t);for(let t of n){if(t.isMerged)continue;let r=t.colspan??1,o=t.rowspan??1;if(!(r<=1&&o<=1))for(let i=t.row;i<t.row+o;i++)for(let s=t.col;s<t.col+r;s++){if(i===t.row&&s===t.col)continue;let a=`${i},${s}`;e.has(a)||e.set(a,{row:i,col:s,isMerged:!0,mergeParent:{row:t.row,col:t.col}})}}return e},we=(n,e,t)=>n.get(`${e},${t}`),lt=(n,e,t)=>{let r=we(n,e,t);return r?.isMerged&&r.mergeParent?{row:r.mergeParent.row,col:r.mergeParent.col}:{row:e,col:t}},Rr=n=>{let e=Array.isArray(n.cellData)?n.cellData:null;if(e)return e;let t=[];return n.cellData=t,t},Pr=n=>n.rows??3,Gi=n=>n.cols??3,El=n=>n.minCellHeight??40,Tl=n=>n.minCellWidth??40,Cl=n=>{let e=Gi(n),t=Array.isArray(n.columnWidths)?n.columnWidths:[],r=typeof t[0]=="number"?t[0]:n.cellWidth??100,o=t.slice(0,e).map(i=>typeof i=="number"&&i>0?i:r);for(;o.length<e;)o.push(r);return o},po=(n,e)=>{let t=Array.isArray(n.columnWidths)?n.columnWidths:null;t?(t.length=0,t.push(...e)):n.columnWidths=e},Uh=(n,e,t,r)=>{let o=Pr(n),i=El(n),s=Array.isArray(n.rowHeights)?n.rowHeights:Array.from({length:o},()=>i);for(;s.length<o;)s.push(i);r!==void 0?s.splice(e,t,r):s.splice(e,t),n.rowHeights=s},$h=(n,e,t,r)=>{let o=Pr(n),i=Array.isArray(n.manualRowHeights)?n.manualRowHeights:[],s=[];for(let a=0;a<Math.max(o,i.length);a++)s.push(typeof i[a]=="number"?i[a]:null);r!==void 0?s.splice(e,t,r):s.splice(e,t),n.manualRowHeights=s},bo=(n,e,t)=>{let r=Cl(n);e<0||e>=r.length||(r[e]=Math.max(Tl(n),t),po(n,r))},xo=(n,e,t)=>{let r=Pr(n);if(e<0||e>=r)return;let o=Array.isArray(n.manualRowHeights)?n.manualRowHeights:[],i=[];for(let s=0;s<r;s++)i.push(typeof o[s]=="number"?o[s]:null);i[e]=Math.max(El(n),t),n.manualRowHeights=i},Ml=(n,e,t,r,o)=>{let i=!0;for(;i;){i=!1;for(let s=e;s<=t;s++)for(let a=r;a<=o;a++){let l=we(n,s,a);if(l){if(l.isMerged&&l.mergeParent){let u=we(n,l.mergeParent.row,l.mergeParent.col);if(u){l.mergeParent.row<e&&(e=l.mergeParent.row,i=!0),l.mergeParent.col<r&&(r=l.mergeParent.col,i=!0);let c=l.mergeParent.row+(u.rowspan??1)-1,h=l.mergeParent.col+(u.colspan??1)-1;c>t&&(t=c,i=!0),h>o&&(o=h,i=!0)}}(l.colspan??1)>1&&a+(l.colspan??1)-1>o&&(o=a+(l.colspan??1)-1,i=!0),(l.rowspan??1)>1&&s+(l.rowspan??1)-1>t&&(t=s+(l.rowspan??1)-1,i=!0)}}}return{r1:e,r2:t,c1:r,c2:o}},Fx=(n,e,t)=>{for(let r=t.r1;r<=t.r2;r++)for(let o=t.c1;o<=t.c2;o++){let i=we(e,r,o);i||(i={row:r,col:o},n.push(i),e.set(`${r},${o}`,i)),i.colspan=1,i.rowspan=1,i.isMerged=!1,i.mergeParent=null}},Ox=(n,e)=>{let t=[];for(let r=e.r1;r<=e.r2;r++)for(let o=e.c1;o<=e.c2;o++){let i=we(n,r,o)?.text;i&&i.trim()&&t.push(i.trim())}return t.join(`
|
|
7
|
+
`)},Rl=(n,e,t,r,o,i)=>{for(let s=t;s<t+o;s++)for(let a=r;a<r+i;a++){if(s===t&&a===r)continue;let l=we(e,s,a);l||(l={row:s,col:a},n.push(l),e.set(`${s},${a}`,l)),l.isMerged=!0,l.mergeParent={row:t,col:r},l.text=""}},go=(n,e,t,r,o)=>{let i=Rr(n),s=_t(i),a=Ml(s,Math.min(e,r),Math.max(e,r),Math.min(t,o),Math.max(t,o));Fx(i,s,a);let l=we(s,a.r1,a.c1);return l&&(l.text=Ox(s,a),l.colspan=a.c2-a.c1+1,l.rowspan=a.r2-a.r1+1,Rl(i,s,a.r1,a.c1,l.rowspan,l.colspan)),a},yo=(n,e,t)=>{let r=_t(Rr(n)),o=we(r,e,t);if(!o||(o.colspan??1)===1&&(o.rowspan??1)===1)return!1;let i=o.colspan??1,s=o.rowspan??1;o.colspan=1,o.rowspan=1;for(let a=e;a<e+s;a++)for(let l=t;l<t+i;l++){if(a===e&&l===t)continue;let u=we(r,a,l);u&&(u.isMerged=!1,u.mergeParent=null)}return!0},jh=n=>({cellFill:n.cellFill,textFill:n.textFill,fontSize:n.fontSize,fontWeight:n.fontWeight,fontFamily:n.fontFamily,fontStyle:n.fontStyle,textAlign:n.textAlign}),Vh=(n,e,t,r)=>({row:t,col:r,fill:n?.fill??e.cellFill,stroke:n?.stroke,text:"",textFill:n?.textFill??e.textFill,fontSize:n?.fontSize??e.fontSize,fontWeight:n?.fontWeight??e.fontWeight,fontFamily:n?.fontFamily??e.fontFamily,fontStyle:n?.fontStyle??e.fontStyle,textAlign:n?.textAlign??e.textAlign}),Xi=(n,e,t,r)=>{for(let o of n)o[e]>=t&&(o[e]+=r),o.isMerged&&o.mergeParent&&o.mergeParent[e]>=t&&(o.mergeParent[e]+=r)},qh=(n,e,t)=>{let r=e==="row"?"rowspan":"colspan",o=[];for(let i of n){let s=i[r]??1;if(s>1){let a=i[e];t>a&&t<=a+s-1&&o.push(i)}}return o},So=(n,e)=>{let t=Pr(n),r=Gi(n),o=Rr(n),i=_t(o),s=Math.max(0,Math.min(e,t)),a=qh(o,"row",s),l=s>0?s-1:s<t?s:null;Xi(o,"row",s,1);for(let c=0;c<r;c++){let h=l!==null?we(i,l,c):void 0;o.push(Vh(h,jh(n),s,c))}Uh(n,s,0,El(n)),$h(n,s,0,null),n.rows=t+1;let u=_t(o);for(let c of a)c.rowspan=(c.rowspan??1)+1,Rl(o,u,c.row,c.col,c.rowspan??1,c.colspan??1)},Pl=(n,e)=>{let t=Pr(n);if(t<=1)return!1;let r=Math.max(0,Math.min(e,t-1)),o=Rr(n),i=0;for(let s of o)s.row!==r&&(o[i++]=s);return o.length=i,Xi(o,"row",r+1,-1),Uh(n,r,1),$h(n,r,1),n.rows=t-1,!0},vo=(n,e)=>{let t=Pr(n),r=Gi(n),o=Rr(n),i=_t(o),s=Cl(n),a=Math.max(0,Math.min(e,r)),l=qh(o,"col",a),u=a>0?a-1:a<r?a:null;Xi(o,"col",a,1);for(let d=0;d<t;d++){let f=u!==null?we(i,d,u):void 0;o.push(Vh(f,jh(n),d,a))}n.cols=r+1;let c=Math.max(Tl(n),u!==null?s[u]:Tl(n));s.splice(a,0,c),po(n,s);let h=_t(o);for(let d of l)d.colspan=(d.colspan??1)+1,Rl(o,h,d.row,d.col,d.rowspan??1,d.colspan??1)},kl=(n,e)=>{let t=Gi(n);if(t<=1)return!1;let r=Math.max(0,Math.min(e,t-1)),o=Rr(n),i=Cl(n),s=0;for(let a of o)a.col!==r&&(o[s++]=a);return o.length=s,Xi(o,"col",r+1,-1),n.cols=t-1,i.splice(r,1),po(n,i),!0},Jn=n=>n.columnWidths.reduce((e,t)=>e+t,0)+(n.cols-1)*n.cellSpacing,er=n=>n.rowHeights.reduce((e,t)=>e+t,0)+(n.rows-1)*n.cellSpacing,Cr=(n,e,t)=>{let r=0;for(let o=0;o<n.length;o++){if(t>=r&&t<r+n[o])return o;r+=n[o]+e}return-1},Mr=(n,e,t)=>{let r=e==="col"?n.columnWidths:n.rowHeights,o=e==="col"?Jn(n):er(n),i=0;for(let s=0;s<t&&s<r.length;s++)i+=r[s]+n.cellSpacing;return i-n.cellSpacing/2-o/2},zh=(n,e,t,r,o,i)=>{let s=e/2,a=0;for(let l=0;l<=n.length;l++){let u=l>0&&l<n.length,c=a-s;if(u&&Math.abs(t-c)<r&&o>=0&&o<=i)return l;l<n.length&&(a+=n[l]+e)}return-1},Yh=(n,e,t,r)=>{if(e==="col"){let i=we(n,r,t-1);if(!i)return!1;if(i.isMerged&&i.mergeParent){let s=we(n,i.mergeParent.row,i.mergeParent.col);if(s&&s.col+(s.colspan??1)>t)return!0}else if((i.colspan??1)>1)return!0;return!1}let o=we(n,t-1,r);if(!o)return!1;if(o.isMerged&&o.mergeParent){let i=we(n,o.mergeParent.row,o.mergeParent.col);if(i&&i.row+(i.rowspan??1)>t)return!0}else if((o.rowspan??1)>1)return!0;return!1},Al=(n,e,t,r,o,i)=>{let s=t+Jn(n)/2,a=r+er(n)/2,l=o,u=i,c=Cr(n.rowHeights,n.cellSpacing,a),h=Cr(n.columnWidths,n.cellSpacing,s),d=zh(n.columnWidths,n.cellSpacing,s,l,a,er(n));if(d>0&&c>=0&&!Yh(e,"col",d,c))return{type:"col",index:d,position:Mr(n,"col",d)};let f=zh(n.rowHeights,n.cellSpacing,a,u,s,Jn(n));return f>0&&h>=0&&!Yh(e,"row",f,h)?{type:"row",index:f,position:Mr(n,"row",f)}:null},Kh=(n,e,t,r)=>{let o=t+Jn(n)/2,i=r+er(n)/2,s=Cr(n.columnWidths,n.cellSpacing,o);if(s<0)return null;let a=Cr(n.rowHeights,n.cellSpacing,i);return a<0?null:lt(e,a,s)},Qh=(n,e,t,r,o)=>{let i=o.indicatorOffset??15,s=o.indicatorRadius??8,a=er(n)/2,l=Jn(n)/2;for(let c=1;c<=n.cols;c++){let h=Mr(n,"col",c),d=s/(Math.abs(o.scaleX)*o.zoom);if(Math.hypot(t-h,r-(-a-i))<=d)return{border:{type:"col",index:c,position:h},inCircle:!0}}for(let c=1;c<=n.rows;c++){let h=Mr(n,"row",c),d=s/(Math.abs(o.scaleY)*o.zoom);if(Math.hypot(t-(-l-i),r-h)<=d)return{border:{type:"row",index:c,position:h},inCircle:!0}}let u=Al(n,e,t,r,o.thresholdX,o.thresholdY);return u?{border:u,inCircle:!1}:null},wo=(n,e)=>{let t=0;for(let l=0;l<e.c1;l++)t+=n.columnWidths[l]+n.cellSpacing;let r=0;for(let l=e.c1;l<=e.c2;l++)r+=n.columnWidths[l]+(l<e.c2?n.cellSpacing:0);let o=0;for(let l=0;l<e.r1;l++)o+=n.rowHeights[l]+n.cellSpacing;let i=0;for(let l=e.r1;l<=e.r2;l++)i+=n.rowHeights[l]+(l<e.r2?n.cellSpacing:0);let s=Jn(n)/2,a=er(n)/2;return{left:t-s,top:o-a,width:r,height:i}},To=n=>{let e=new Set,t=[];for(let r of n){let o=`${r.row},${r.col}`;e.has(o)||(e.add(o),t.push(r))}return t},xn=(n,e,t)=>To((()=>{let r=[];for(let o=Math.min(e.row,t.row);o<=Math.max(e.row,t.row);o++)for(let i=Math.min(e.col,t.col);i<=Math.max(e.col,t.col);i++)r.push(lt(n,o,i));return r})()),zi=(n,e,t)=>{let r=[];for(let o=0;o<e;o++){let i=lt(n,o,t);i.col===t&&r.push(i)}return To(r)},Yi=(n,e,t)=>{let r=[];for(let o=0;o<e;o++){let i=lt(n,t,o);i.row===t&&r.push(i)}return To(r)},Eo=(n,e,t)=>{let r=[];for(let o=0;o<e;o++)for(let i=0;i<t;i++)r.push(lt(n,o,i));return To(r)},Xe=n=>{if(!n.length)return null;let e=1/0,t=-1/0,r=1/0,o=-1/0;for(let i of n)e>i.row&&(e=i.row),t<i.row&&(t=i.row),r>i.col&&(r=i.col),o<i.col&&(o=i.col);return{r1:e,r2:t,c1:r,c2:o}},Ui=(n,e,t,r)=>{let o=[];for(let u of n){let c=r==="row"?u.row:u.col;if(c===t)continue;let h=c>t?c-1:c;o.push(r==="row"?{row:h,col:u.col}:{row:u.row,col:h})}let i=To(o);if(!i.length)return null;if(!e)return{cells:i,range:null};let s=r==="row"?e.r1:e.c1,a=r==="row"?e.r2:e.c2,l;if(s===t&&a===t)l=Xe(i)??e;else{let u=s>t?s-1:s,c=a>t?a-1:a===t?t-1:a;l=r==="row"?{r1:u,r2:c,c1:e.c1,c2:e.c2}:{r1:e.r1,r2:e.r2,c1:u,c2:c}}return{cells:i,range:l}},Zh=(n,e,t,r)=>Math.abs(e-n)>=.5||Math.abs(t)<=1?0:Math.sign(t)*Math.min(1.5,Math.abs(t)*.1)/r,Bx=["ew","nwse","ns","nesw"],Jh=(n,e)=>{let t=e==="col"?0:2,r=(n%180+180)%180,o=Math.round(r/45)%4;return`${Bx[(t+o)%4]}-resize`};var Hi=(n,e)=>{let t=Math.abs(n)*Math.max(e,1e-6);return t>1e-6?20/t:20},ed=(n,e,t,r,o,i={x:1,y:1},s=1)=>{if(o<-t/2&&o>=-t/2-Hi(i.y,s)){let a=Cr(n.columnWidths,n.cellSpacing,r+Jn(n)/2);if(a>=0)return{kind:"col-strip",col:a}}if(r<-e/2&&r>=-e/2-Hi(i.x,s)){let a=Cr(n.rowHeights,n.cellSpacing,o+er(n)/2);if(a>=0)return{kind:"row-strip",row:a}}return null},td=(n,e,t,r,o={x:1,y:1},i=1)=>{let s=Hi(o.x,i),a=Hi(o.y,i);return t>=-n/2-s&&t<-n/2&&r>=-e/2-a&&r<-e/2};var nd=(n,e,t,r={x:1,y:1},o=1)=>{let i=l=>Math.max(Math.abs(l)*Math.max(o,1e-6),1e-6),s=12/i(r.x),a=12/i(r.y);return Math.abs(e-(n.left+n.width))<=s&&Math.abs(t-(n.top+n.height))<=a},kr=(n,e)=>{let t=new Set,r=new Set;for(let o of e){let i=lt(n,o.row,o.col),s=we(n,i.row,i.col),a=s?.rowspan??1,l=s?.colspan??1;for(let u=i.row;u<i.row+a;u++)t.add(u);for(let u=i.col;u<i.col+l;u++)r.add(u)}return{rows:t,cols:r}};var $i=14,rd=(n,e,t)=>{let r=[0];for(let o=0;o<n-1;o++)r.push(r[o]+e[o]+t);return r},Nl=(n,e,t,r)=>{let o=0;for(let i=0;i<e;i++)o+=t[n+i]??0,i>0&&(o+=r);return o},Co=(n,e,t)=>{let r=n.rows??3,o=n.cols??3,i=Array.isArray(n.columnWidths)?n.columnWidths:[],s=i[0]??100,a=Array.from({length:o},(_,D)=>i[D]??s),l=n.minCellHeight??40,u=n.cellPadding??8,c=n.cellSpacing??0,h=n.cellStrokeWidth??1,d=n.cellFill,f=n.cellStroke,m=n.textFill,p=n.fontFamily||"仓耳小丸子",b=Array.isArray(n.manualRowHeights)?n.manualRowHeights:[],x=Array.from({length:r},(_,D)=>typeof b[D]=="number"?b[D]:null),g=Array.isArray(n.cellData)?n.cellData:[],y=_t(g),v=new Map;for(let _ of g){if(_.isMerged)continue;let D=Math.max(0,Nl(_.col,_.colspan??1,a,c)-u*2);v.set(`${_.row},${_.col}`,{layout:Vn(_.text??"",{fontFamily:_.fontFamily||p,fontSize:_.fontSize??$i,fontWeight:_.fontWeight,fontStyle:_.fontStyle,lineHeight:1.16,charSpacing:0,textAlign:_.textAlign??fe.CENTER},{boxWidth:D,splitByGrapheme:!0,measure:e}),data:_})}let S=$i*Ti,w=[],R=[];for(let _=0;_<r;_++){let D=0;for(let H=0;H<o;H++){if(y.get(`${_},${H}`)?.isMerged)continue;let X=v.get(`${_},${H}`);D=Math.max(D,X?X.layout.height:S)}let I=x[_],W=D+u*2,j=I!==null?I:l;R.push(W),w.push(Math.max(j,W))}let P=a.reduce((_,D)=>_+D,0)+(o-1)*c,T=w.reduce((_,D)=>_+D,0)+(r-1)*c,C=rd(o,a,c),E=rd(r,w,c),M=typeof n.id=="string"&&n.id?n.id:"table",k=[];for(let _=0;_<r;_++)for(let D=0;D<o;D++){let I=y.get(`${_},${D}`);if(I?.isMerged)continue;let W=I?.colspan??1,j=I?.rowspan??1,H=Nl(D,W,a,c),X=Nl(_,j,w,c),z=C[D]-P/2+H/2,$=E[_]-T/2+X/2;k.push({type:"rect",id:`${M}-r${_}c${D}-rect`,left:z,top:$,width:H,height:X,originX:"center",originY:"center",fill:I?I.fill:d,stroke:I?I.stroke:f,strokeWidth:h,scaleX:1,scaleY:1,angle:0,opacity:1,visible:!0});let Z=I?v.get(`${_},${D}`):void 0,B=t?.hideTextCell!==void 0&&t.hideTextCell.row===_&&t.hideTextCell.col===D;if(Z&&!B&&(I?.text??"")!==""){let q=Z.layout.height,U=I?.verticalAlign??"middle",oe=$;U==="top"?oe=$-X/2+q/2+u:U==="bottom"&&(oe=$+X/2-q/2-u),k.push({type:"textbox",id:`${M}-r${_}c${D}-text`,left:z,top:oe,width:Math.max(0,H-u*2),text:I?.text??"",fill:I?.textFill??m,fontFamily:I?.fontFamily||p,fontSize:I?.fontSize??$i,fontWeight:I?.fontWeight,fontStyle:I?.fontStyle,textAlign:I?.textAlign??fe.CENTER,lineHeight:1.16,splitByGrapheme:!0,originX:"center",originY:"center",scaleX:1,scaleY:1,angle:0,opacity:1,visible:!0})}}let A=Math.max(l,$i*Ti+u*2),O=o*s+(o-1)*c+h,F=r*A+(r-1)*c+h,G=P+h,Y=T+h;return{rowHeights:w,rowTextFloors:R,columnWidths:a,contentWidth:P,contentHeight:T,width:G,height:Y,children:k,constructorDims:{width:O,height:F}}};var yn="WorkSpaceDrawType",Lr=new Set(["WorkSpaceDrawType","WorkSpaceClipType","WorkSpaceSafeType","WorkSpaceMaskType","WorkSpaceLineType","WorkSpaceShadowType"]),Wx=new Set(["WorkSpaceClipType","WorkSpaceSafeType"]),tr=n=>{let e=n.raw?.id;return typeof e=="string"&&Wx.has(e)},Vt=n=>n.isTextType&&typeof n.raw.renderSrc=="string",Mo=n=>{let e=n.fill;return typeof e!="string"||!e?1:Math.max(0,Math.min(1,ee(e)[3]))},ld=n=>{let e=n.fillOpacity;if(typeof e!="number"||!isFinite(e))return 1;let t=e>1?e/255:e;return Math.max(0,Math.min(1,t))},Hx=new Set(["left","top","angle","scaleX","scaleY","skewX","skewY","flipX","flipY","originX","originY"]),Gx=new Set(["text","styles","paragraph","texts","textPath","path","pathStartOffset","pathSide","pathAlign","fontFamily","fontSize","fontWeight","fontStyle","lineHeight","charSpacing","textAlign","splitByGrapheme","vertical","direction","underline","overline","linethrough","textBackgroundColor","textDecorationThickness","textScaleX","textScaleY","width","height","minWidth","fill","stroke","strokeWidth","strokeUniform","paintFirst"]),_l=n=>{for(let e in n)if(!Hx.has(e))return!1;return!0},Vi=999999,Ze=n=>n.isReferenceLine,cd=(n,e)=>({type:"ReferenceLine",id:`referenceline-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`,name:"ReferenceLine",axis:n,x1:n==="horizontal"?-Vi:0,y1:n==="horizontal"?0:-Vi,x2:n==="horizontal"?Vi:0,y2:n==="horizontal"?0:Vi,left:n==="horizontal"?0:e,top:n==="horizontal"?e:0,originX:"center",originY:"center",scaleX:1,scaleY:1,angle:0,opacity:1,visible:!1,selectable:!1,evented:!0,hasControls:!1,hasBorders:!1,stroke:"pink",fill:"pink",strokeWidth:1,padding:8,globalCompositeOperation:"difference",lockMovementX:n==="horizontal",lockMovementY:n==="vertical",hoverCursor:n==="horizontal"?"ns-resize":"ew-resize"}),Xx=["type","left","top","width","height","angle","scaleX","scaleY","skewX","skewY","flipX","flipY","originX","originY","strokeWidth","strokeUniform","fill","opacity","visible","src","crossOrigin","id","name"],ct=class{raw;syntheticOwner;_parentMatrix=null;_parentOpacity=1;_inIsolatedFBO=!1;_imageEl=null;_matrix=null;_aCoords=null;_bounds=null;_fillPaint;_animationOverride=null;constructor(e){this.raw={...e},Nu(this.raw),this._typeKey=se(this.raw),this._isReferenceLine=this._typeKey===L.REFERENCELINE}_typeKey;get typeKey(){return this._typeKey}_isReferenceLine;get isReferenceLine(){return this._isReferenceLine}_strokeDecl;get strokeDecl(){return this._strokeDecl===void 0&&(this._strokeDecl=vi(this.raw)),this._strokeDecl}get imageEl(){return this._imageEl}set imageEl(e){this._imageEl=e,this.invalidateGeometryCache(),this._renderNotify?.()}invalidateGeometryCache(){this._matrix=null,this._aCoords=null,this._bounds=null}_renderNotify=null;markRenderDirty(){this._renderNotify?.()}set(e){Lu(this.raw,e),Object.assign(this.raw,e),this.invalidateGeometryCache(),_l(e)||(this._fillPaint=void 0,this._strokeDecl=void 0),"type"in e&&(this._typeKey=se(e),this._isReferenceLine=this._typeKey===L.REFERENCELINE),this._renderNotify?.()}setAnimationOverride(e){this._animationOverride=e,this.invalidateGeometryCache(),this._renderNotify?.()}get id(){return typeof this.raw.id=="string"?this.raw.id:""}get isImageType(){return dt.has(this.typeKey)}get isMaskType(){return ot.has(this.typeKey)}get isSolidType(){return zn.has(this.typeKey)}get isTextType(){return sn.has(this.typeKey)}get isLineType(){return ft.has(this.typeKey)}get isShapeType(){return Xn.has(this.typeKey)}get visible(){return this.raw.visible!==!1}get fillPaint(){if(this._fillPaint===void 0){let e=Gn(this.raw.fill),t=e?null:fi(this.raw.fill);e?this._fillPaint={kind:"gradient",decl:e}:t?this._fillPaint={kind:"pattern",decl:t}:this.raw.fill?this._fillPaint={kind:"solid",color:ee(this.raw.fill)}:this._fillPaint=null}return this._fillPaint}get drawColor(){let e=this.renderOpacity;if(this.isImageType)return[1,1,1,e];let t=ee(this.raw.fill);return[t[0],t[1],t[2],t[3]*e]}get transformProps(){let e={...this.raw,width:this.dims.x,height:this.dims.y},t=this._animationOverride;if(!t)return e;let{opacity:r,...o}=t;return{...e,...o}}get center(){return Yt(this.transformProps)}get matrix(){return this._matrix||(this._matrix=Bn(this.transformProps)),this._parentMatrix?V(this._parentMatrix,this._matrix):this._matrix}get ownMatrix(){return this._matrix||(this._matrix=Bn(this.transformProps)),this._matrix}get worldAngle(){let e=this.matrix;return Math.atan2(e[1],e[0])*180/Math.PI}get worldScale(){let e=this.matrix;return{x:Math.hypot(e[0],e[1]),y:Math.hypot(e[2],e[3])}}get aCoords(){if(this._aCoords||(this._aCoords=za(this.transformProps)),!this._parentMatrix)return this._aCoords;let e=this._parentMatrix;return{tl:Q(e,this._aCoords.tl.x,this._aCoords.tl.y),tr:Q(e,this._aCoords.tr.x,this._aCoords.tr.y),br:Q(e,this._aCoords.br.x,this._aCoords.br.y),bl:Q(e,this._aCoords.bl.x,this._aCoords.bl.y)}}contentBoxCorners(){let e=typeof this.raw.strokeWidth=="number"?this.raw.strokeWidth:0,t=this.raw.strokeUniform===!0,r=(t?this.dims.x:this.dims.x+e)/2,o=(t?this.dims.y:this.dims.y+e)/2,i=t?e/2:0,s=this.ownMatrix,a=1/0,l=1/0,u=-1/0,c=-1/0;for(let h of[-r,r])for(let d of[-o,o]){let f=Q(s,h,d);f.x<a&&(a=f.x),f.y<l&&(l=f.y),f.x>u&&(u=f.x),f.y>c&&(c=f.y)}return{tl:{x:a-i,y:l-i},tr:{x:u+i,y:l-i},br:{x:u+i,y:c+i},bl:{x:a-i,y:c+i}}}get inkACoords(){return this.aCoords}get parentMatrix(){return this._parentMatrix}setParentMatrix(e,t=1){this._parentMatrix=e,this._parentOpacity=t,this.invalidateWorldGeometry(),this._renderNotify?.()}get renderOpacity(){return(this._animationOverride?.opacity??this.raw.opacity??1)*(this._inIsolatedFBO?1:this._parentOpacity)}setIsolation(e){if(this._inIsolatedFBO=e,this instanceof J)for(let t of this.children)t.setIsolation(e)}invalidateWorldGeometry(){this._matrix=null,this._aCoords=null,this._bounds=null}get bounds(){return this._bounds||(this._bounds=Wn(this.aCoords)),this._bounds}containsPoint(e,t,r=0){if(this.isSolidType&&!Qi(this))return Dl(this)&&this.outlineStrokeHitAt(e,t,r);let o=this.aCoords,i=[o.tl,o.tr,o.br,o.bl],s=!1;for(let a=0,l=3;a<4;l=a++){let u=i[a].x,c=i[a].y,h=i[l].x,d=i[l].y;c>t!=d>t&&e<(h-u)*(t-c)/(d-c)+u&&(s=!s)}return s}outlineStrokeHitAt(e,t,r=0){if(!this.isSolidType)return!1;let o=this.dims.x/2,i=this.dims.y/2;if(!(o>0)||!(i>0))return!1;let s=this.localPoint(e,t),a=Math.abs(s.x)-o,l=Math.abs(s.y)-i;return(a>0||l>0?Math.hypot(Math.max(a,0),Math.max(l,0)):Math.min(-a,-l))<=Fl(this,r)}localPoint(e,t){return Q(ve(this.matrix),e,t)}rotateAroundCenter(e,t=this.center){let r=xe({...this.transformProps,angle:e},t);return{angle:e,left:r.x,top:r.y}}get dims(){let e=this.cropRect;if(e)return{x:e.sw,y:e.sh};let t=this.raw.width??(this.imageEl?this.imageEl.naturalWidth:0),r=this.raw.height??(this.imageEl?this.imageEl.naturalHeight:0);return{x:t,y:r}}get cropRect(){return Zi(this.raw)}toObject(){let e={};for(let t of Xx)this.raw[t]!==void 0&&(e[t]=this.raw[t]);for(let[t,r]of Object.entries(this.raw))e[t]===void 0&&!t.startsWith("_")&&(e[t]=r);return e}},zx=n=>{if(n.angle===0||n.w<=0||n.h<=0)return null;let e=(n.angle%180+180)%180,t=Math.min(e,180-e);if(t<2)return null;let r=t*Math.PI/180,o=Math.abs(Math.cos(r)),i=Math.abs(Math.sin(r)),s=o*o-i*i;if(Math.abs(s)<.5)return null;let a=(n.w*o-n.h*i)/s,l=(n.h*o-n.w*i)/s;return!Number.isFinite(a)||!Number.isFinite(l)||a<=0||l<=0?null:{w:a,h:l}},Yx=n=>{let{fw:e,fh:t}=n;if(e===void 0||t===void 0)return null;let r=n.w+n.h;return!Number.isFinite(e)||!Number.isFinite(t)||e<=0||t<=0||e>r||t>r?null:{w:e,h:t}},Se=class extends ct{_layout=null;_arcDims=null;_scrollOffset=0;constructor(e){super(e)}set(e){super.set(e),_l(e)||(this.invalidateTextLayout(),typeof this.raw.renderSrc=="string"&&Object.keys(e).some(t=>Gx.has(t))&&(delete this.raw.renderSrc,delete this.raw.renderRect))}invalidateTextLayout(){this._layout=null,this._arcDims=null,this.invalidateGeometryCache(),this._renderNotify?.()}get textStyle(){let e=this.raw;return{fontFamily:e.fontFamily??"Times New Roman",fontSize:e.fontSize??40,fontWeight:e.fontWeight,fontStyle:e.fontStyle,lineHeight:e.lineHeight??1.16,charSpacing:e.charSpacing??0,textAlign:e.textAlign??fe.LEFT}}get paintFirst(){return this.raw.paintFirst==="stroke"?"stroke":"fill"}get textStroke(){let e=this.raw,t=typeof e.stroke=="string"?e.stroke:"",r=e.strokeWidth??1;return!t||r===0?null:{color:t,width:r,lineJoin:e.strokeLineJoin,miterLimit:e.strokeMiterLimit,lineCap:e.strokeLineCap}}get decorationDefaults(){let e=this.raw;return{underline:!!e.underline,overline:!!e.overline,linethrough:!!e.linethrough,textDecorationThickness:e.textDecorationThickness,fontSize:this.textStyle.fontSize,fill:typeof e.fill=="string"?e.fill:void 0,charSpacing:this.textStyle.charSpacing,vertical:e.vertical===!0}}get textLayout(){if(!this._layout){let e=this.raw,t=Ke(e),r=(se(e)===L.TEXTBOX||se(e)===L.TEXTIMAGE)&&t===null;this._layout=Vn(e.text??"",this.textStyle,{boxWidth:r?e.width??0:null,styles:e.styles,splitByGrapheme:e.splitByGrapheme===!0,vertical:e.vertical===!0,paragraph:t==="arc"||t==="circle"?void 0:e.paragraph})}return this._layout}get scrollOffset(){return this._scrollOffset}setScrollOffset(e){this._scrollOffset=Number.isFinite(e)?e:0,this._renderNotify?.()}get textTotalWidth(){let e=this.textLayout;if(this.raw.vertical===!0&&e.verticalWidth!==void 0)return e.verticalWidth;let t=0;for(let r of e.lines)r.width>t&&(t=r.width);return t}get dims(){if(typeof this.raw.renderSrc=="string"){let t=this.bitmapRect;return{x:t.w,y:t.h}}if(Ge(this.raw)){if(!this._arcDims){let t=Et(this.textLayout,this.raw,this.textStyle.lineHeight??1.16);this._arcDims={x:t.width,y:t.height}}return this._arcDims}let e=typeof this.raw.height=="number"?this.raw.height:0;return{x:this.textLayout.width,y:Math.max(this.textLayout.height,e)}}get bitmapRect(){let e=this.raw.renderRect,t=u=>typeof u=="number"&&Number.isFinite(u)&&u>=0?u:null,r=(e&&t(e.w))??(typeof this.raw.width=="number"?this.raw.width:0),o=(e&&t(e.h))??(typeof this.raw.height=="number"?this.raw.height:0),i=e&&typeof e.x=="number"&&Number.isFinite(e.x)?e.x:0,s=e&&typeof e.y=="number"&&Number.isFinite(e.y)?e.y:0,a=e&&typeof e.angle=="number"&&Number.isFinite(e.angle)?e.angle:0,l={x:i,y:s,w:r,h:o,angle:a};if(e){let u=m=>typeof m=="number"&&Number.isFinite(m)?m:void 0,c=u(e.fw),h=u(e.fh);c!==void 0&&h!==void 0&&(l.fw=c,l.fh=h);let d=u(e.fx),f=u(e.fy);d!==void 0&&f!==void 0&&(l.fx=d,l.fy=f)}return l}get aCoords(){let e=this.bitmapFrameCorners();if(e){let t=this.parentMatrix;if(!t)return e;let r=o=>Q(t,o.x,o.y);return{tl:r(e.tl),tr:r(e.tr),br:r(e.br),bl:r(e.bl)}}return super.aCoords}contentBoxCorners(){return this.bitmapFrameCorners()??super.contentBoxCorners()}bitmapFrameCorners(){if(typeof this.raw.renderSrc!="string")return null;let e=this.bitmapRect,t=Yx(e)??zx(e);if(!t&&e.angle===0&&e.x===0&&e.y===0)return null;let r=this.ownMatrix;(e.x!==0||e.y!==0)&&(r=V(r,[1,0,0,1,e.x,e.y])),t&&e.fx!==void 0&&e.fy!==void 0&&(e.fx!==0||e.fy!==0)&&(r=V(r,[1,0,0,1,e.fx,e.fy])),!t&&e.angle!==0&&(r=V(r,kt({angle:-e.angle})));let o=(t?t.w:e.w)/2,i=(t?t.h:e.h)/2;return{tl:Q(r,-o,-i),tr:Q(r,o,-i),br:Q(r,o,i),bl:Q(r,-o,i)}}get inkACoords(){return Dh(this,this.textInkACoords)}get textInkACoords(){if(typeof this.raw.renderSrc=="string")return super.inkACoords;let e=Ke(this.raw);if(e==="arc"||e==="circle"||e==="scroll")return super.inkACoords;let t=this.textLayout,r,o,i,s;if(e!==null){let c=yr(this.raw),h=c?Ci(t,this.textStyle,{align:this.textStyle.textAlign}):null,d=c&&h?ah(c,t,this.raw,h,this.contentTopY):null;if(d)r=d.left,o=d.right,i=d.top,s=d.bottom;else{if(c)return super.inkACoords;let f=Ci(t,this.textStyle,{vertical:this.raw.vertical===!0,align:this.textStyle.textAlign});if(!f)return super.inkACoords;let m=t.width/2;r=-m+f.lo,o=-m+f.hi,i=this.contentTopY+f.firstTop,s=this.contentTopY+t.height}}else{let c=Ci(t,this.textStyle,{vertical:this.raw.vertical===!0,align:this.textStyle.textAlign});if(!c)return super.inkACoords;let h=t.width/2;r=-h+c.lo,o=-h+c.hi,i=this.contentTopY+c.firstTop,s=this.contentTopY+t.height}let a=this.ownMatrix,l=this.parentMatrix,u=(c,h)=>{let d=Q(a,c,h);return l?Q(l,d.x,d.y):d};return{tl:u(r,i),tr:u(o,i),br:u(o,s),bl:u(r,s)}}get contentTopY(){return typeof this.raw.renderSrc=="string"?-this.textLayout.height/2:-this.dims.y/2}cursorCoord(e){let t=this.textLayout;if(t.lines.length===0)return null;let r=0,o=0;for(let c=0;c<t.lines.length;c++){let h=t.lines[c],d=h.styleMap.flatStart,f=d+h.graphemes.length;if(e<=f){r=c,o=Math.max(0,e-d);break}c===t.lines.length-1&&(r=c,o=h.graphemes.length)}let i=t.lines[r],s=-t.width/2+i.leftOffset+(o<i.boxes.length?i.boxes[o].left:un(i)),l=i.charStyles[Math.max(0,o-1)]?.fontSize??this.textStyle.fontSize,u=this.contentTopY+i.baseline-l*.93;return{x:s,y:u,height:l*1.28}}cursorIndexAt(e,t){let r=this.textLayout;if(r.lines.length===0)return 0;let o=t-this.contentTopY,i=0;for(let l=0;l<r.lines.length;l++){let u=r.lines[l];if(o<=u.baseline+this.textStyle.fontSize*.3){i=l;break}i=l}let s=r.lines[i],a=-r.width/2+s.leftOffset;for(let l=0;l<s.boxes.length;l++){let u=s.boxes[l];if(e<a+u.left+u.width/2)return s.styleMap.flatStart+l}return s.styleMap.flatStart+s.graphemes.length}wordBoundsAt(e){let t=Array.from(this.raw.text??""),r=a=>a===" "||a===" "||a==="\r"||a===`
|
|
8
|
+
`,o=Math.max(0,Math.min(e,t.length));if(r(t[o]))return[o,o];let i=o,s=o;for(;i>0&&!r(t[i-1]);)i--;for(;s<t.length&&!r(t[s]);)s++;return[i,s]}},Ux=(n,e)=>Math.max(24,Math.min(128,Math.ceil((n+e)*.6))),od=(n,e)=>{if(!(n>0)||!(e>0))return null;let t=Ux(n,e),r=new Float32Array((t+1)*2);for(let i=0;i<t;i++){let s=i/t*Math.PI*2;r[(i+1)*2]=n*Math.cos(s),r[(i+1)*2+1]=e*Math.sin(s)}let o=new Uint32Array(t*3);for(let i=0;i<t;i++)o[i*3]=0,o[i*3+1]=1+i,o[i*3+2]=1+(i+1)%t;return{verts:r,triangles:o}},id=n=>{if(!Array.isArray(n)||n.length<3)return null;let e=n,t=1/0,r=1/0,o=-1/0,i=-1/0;for(let h of e)t>h.x&&(t=h.x),r>h.y&&(r=h.y),o<h.x&&(o=h.x),i<h.y&&(i=h.y);let s=(t+o)/2,a=(r+i)/2,l=new Float32Array(e.length*2),u=new Array(e.length);for(let h=0;h<e.length;h++)l[h*2]=e[h].x-s,l[h*2+1]=e[h].y-a,u[h]={x:l[h*2],y:l[h*2+1]};let c=Qa(u);return c.length>0?{verts:l,triangles:new Uint32Array(c)}:null},$x=n=>{let e=0;for(let i of n)e+=i.length;if(e<3)return null;let t=new Float32Array(e*2),r=[],o=0;for(let i of n){for(let s=0;s<i.length;s++)t[(o+s)*2]=i[s].x,t[(o+s)*2+1]=i[s].y;for(let s of Qa(i))r.push(s+o);o+=i.length}return r.length>0?{verts:t,triangles:new Uint32Array(r)}:null},jx=n=>{let e=Ce(n);if(!e)return{contours:[],dims:{x:0,y:0}};let t=Fe(e),r=Yu(e);if(!t)return{contours:r,dims:{x:0,y:0}};let o=(t.left+t.right)/2,i=(t.top+t.bottom)/2;return{contours:r.map(a=>({closed:a.closed,points:a.points.map(l=>({x:l.x-o,y:l.y-i}))})),dims:{x:t.right-t.left,y:t.bottom-t.top}}},gn=class extends ct{_mesh;set(e){super.set(e),_l(e)||(this._mesh=void 0)}get shapeKind(){return this.typeKey}get shapeMesh(){if(this._mesh===void 0){let e=this.raw,t=this.shapeKind;if(t===L.ELLIPSE)this._mesh=od(e.rx??0,e.ry??0);else if(t===L.CIRCLE){let r=e.radius??0;this._mesh=od(r,r)}else t===L.TRIANGLE?this._mesh=id(sd(e)):this._mesh=id(e.points)}return this._mesh}get dims(){let e=this.raw,t=this.shapeKind;return t===L.ELLIPSE?{x:2*(e.rx??0),y:2*(e.ry??0)}:t===L.CIRCLE?{x:2*(e.radius??0),y:2*(e.radius??0)}:t===L.TRIANGLE?{x:e.width??0,y:e.height??0}:Vx(e.points)}containsPoint(e,t,r=0){if(!Qi(this))return Dl(this)&&this.outlineStrokeHitAt(e,t,r);let o=this.localPoint(e,t),i=this.shapeKind;if(i===L.ELLIPSE||i===L.CIRCLE){let a=this.dims.x/2,l=this.dims.y/2;if(!(a>0)||!(l>0))return!1;let u=o.x/a,c=o.y/l;return u*u+c*c<=1}let s=this.shapeMesh;return i===L.POLYLINE||i===L.POLYGON?s?ad(s.verts,o.x,o.y):Ll(this.raw.points,o,i===L.POLYGON,Math.max((Number(this.raw.strokeWidth)||1)/2,3,r)):s?ad(s.verts,o.x,o.y):!1}outlineStrokeHitAt(e,t,r=0){let o=this.localPoint(e,t),i=this.shapeKind,s=Fl(this,r);if(i===L.ELLIPSE||i===L.CIRCLE){let a=this.dims.x/2,l=this.dims.y/2;if(!(a>0)||!(l>0))return!1;let u=2*o.x/(a*a),c=2*o.y/(l*l),h=Math.hypot(u,c);if(h<1e-9)return Math.min(a,l)<=s;let d=o.x*o.x/(a*a)+o.y*o.y/(l*l)-1;return Math.abs(d)/h<=s}return i===L.TRIANGLE?Ll(sd(this.raw),o,!0,s):Ll(this.raw.points,o,i===L.POLYGON,s)}},sd=n=>{let e=n.width??0,t=n.height??0;return[{x:e/2,y:0},{x:e,y:t},{x:0,y:t}]},Vx=n=>{if(!Array.isArray(n)||n.length===0)return{x:0,y:0};let e=1/0,t=1/0,r=-1/0,o=-1/0;for(let i of n)e>i.x&&(e=i.x),t>i.y&&(t=i.y),r<i.x&&(r=i.x),o<i.y&&(o=i.y);return{x:r-e,y:o-t}},Ki=10,Il=n=>Math.min(1,Math.max(0,n)),qx=n=>{let e=n.fillPaint;if(!e)return 0;if(e.kind==="solid")return Il(e.color[3])*n.renderOpacity;if(e.kind==="gradient"){let t=0;for(let r of e.decl.stops)t=Math.max(t,Il(r.color[3]));return t*n.renderOpacity}return null},Qi=n=>{let e=qx(n);return e===null||e*255>Ki},Dl=n=>{let e=n.raw.stroke;return typeof e=="object"&&e!==null?!0:typeof e!="string"||!e||Number(n.raw.strokeWidth)===0?!1:Il(ee(e)[3])*n.renderOpacity*255>Ki},Fl=(n,e)=>Math.max((Number(n.raw.strokeWidth)||1)/2,3,e),Ol=8,ud=n=>{let e=n.typeKey;return e===L.LINE||e===L.ARROW||e===L.DIMENSION||e===L.POLYLINE?!0:(n.isShapeType||n.isSolidType)&&!Qi(n)},qi=(n,e,t,r,o,i)=>{let s=o-t,a=i-r,l=s*s+a*a,u=l>0?Math.max(0,Math.min(1,((n-t)*s+(e-r)*a)/l)):0,c=t+u*s-n,h=r+u*a-e;return c*c+h*h},Ll=(n,e,t,r)=>{if(!Array.isArray(n)||n.length<2)return!1;let o=n,i=1/0,s=1/0,a=-1/0,l=-1/0;for(let d of o)i>d.x&&(i=d.x),s>d.y&&(s=d.y),a<d.x&&(a=d.x),l<d.y&&(l=d.y);let u=(i+a)/2,c=(s+l)/2,h=r*r;for(let d=0;d+1<o.length;d++)if(qi(e.x,e.y,o[d].x-u,o[d].y-c,o[d+1].x-u,o[d+1].y-c)<=h)return!0;if(t&&o.length>2){let d=o[o.length-1];if(qi(e.x,e.y,d.x-u,d.y-c,o[0].x-u,o[0].y-c)<=h)return!0}return!1},Ar=class extends gn{_pathGeo;_fillPolys;_pathMesh;set(e){super.set(e),("path"in e||"fillRule"in e)&&(this._pathGeo=void 0,this._fillPolys=void 0,this._pathMesh=void 0)}get pathGeometry(){return this._pathGeo===void 0&&(this._pathGeo=jx(this.raw.path)),this._pathGeo}get fillPolygons(){if(this._fillPolys===void 0){let e=this.raw.fillRule==="evenodd"?"evenodd":"nonzero";this._fillPolys=$u(this.pathGeometry.contours,e)}return this._fillPolys}get shapeMesh(){return this._pathMesh===void 0&&(this._pathMesh=$x(this.fillPolygons)),this._pathMesh}get dims(){return this.pathGeometry.dims}containsPoint(e,t,r=0){return Qi(this)?ct.prototype.containsPoint.call(this,e,t):Dl(this)&&this.outlineStrokeHitAt(e,t,r)}outlineStrokeHitAt(e,t,r=0){let o=this.localPoint(e,t),i=this.pathGeometry.contours;if(i.length===0)return!1;let s=Fl(this,r)**2;for(let a of i){let l=a.points;for(let u=0;u+1<l.length;u++)if(qi(o.x,o.y,l[u].x,l[u].y,l[u+1].x,l[u+1].y)<=s)return!0}return!1}},Kx=(n,e,t)=>{let r=Number(n.strokeWidth)||1,o=Number(n.arrowWidth)||15,i=Number(n.arrowHeight)||22.5,s=n.arrowType==="start"||n.arrowType==="both"?n.arrowType:"end",a=Math.sqrt(r),l=o*a,u=i*a;if(!(u>0)||!(l>0))return!1;let c=Math.atan2(t.y2-t.y1,t.x2-t.x1),h=(d,f,m)=>{let p=Math.cos(m),b=Math.sin(m),x=e.x-d,g=e.y-f,y=x*p+g*b,v=-x*b+g*p;return y<-u||y>0?!1:Math.abs(v)<=l/2*(1+y/u)};return!!((s==="end"||s==="both")&&h(t.x2,t.y2,c)||(s==="start"||s==="both")&&h(t.x1,t.y1,c+Math.PI))},Qx=(n,e,t,r)=>{let o=Number(n.textFontSize)||50,i=Number(n.textPadding)||4,s=typeof n.text=="string"&&n.text.trim()?n.text:"50cm",a=eo(`${o}px Arial, sans-serif`,s)+i*2,l=Math.atan2(t.y2-t.y1,t.x2-t.x1),u=-Math.sin(l),c=Math.cos(l),h=o/2,d=r*r;for(let[R,P]of[[t.x1,t.y1],[t.x2,t.y2]])if(qi(e.x,e.y,R-u*h,P-c*h,R+u*h,P+c*h)<=d)return!0;let f=o+(Number(n.strokeWidth)||1)/2+5,m=(t.x1+t.x2)/2+u*f,p=(t.y1+t.y2)/2+c*f,b=n.textFollowLine===!1?0:l,x=Math.cos(b),g=Math.sin(b),y=e.x-m,v=e.y-p,S=y*x+v*g,w=-y*g+v*x;return Math.abs(S)<=a/2&&Math.abs(w)<=(o+i*2)/2},Nr=class extends ct{get dims(){let e=this.linePoints;return e?{x:Math.abs(e.x2-e.x1),y:Math.abs(e.y2-e.y1)}:{x:0,y:0}}get linePoints(){let e=Number(this.raw.x1),t=Number(this.raw.y1),r=Number(this.raw.x2),o=Number(this.raw.y2);return!Number.isFinite(e)||!Number.isFinite(t)||!Number.isFinite(r)||!Number.isFinite(o)?null:{x1:e,y1:t,x2:r,y2:o}}containsPoint(e,t,r=0){let o=this.linePoints;if(!o)return!1;let i=this.localPoint(e,t);if(!i)return!1;let s=o.x2-o.x1,a=o.y2-o.y1,l=s*s+a*a,u=0;l>0&&(u=Math.max(0,Math.min(1,((i.x-o.x1)*s+(i.y-o.y1)*a)/l)));let c=o.x1+u*s,h=o.y1+u*a,d=Math.max((Number(this.raw.strokeWidth)||1)/2,3,r);if(Math.hypot(i.x-c,i.y-h)<=d)return!0;let f=this.typeKey;return f===L.ARROW?Kx(this.raw,i,o):f===L.DIMENSION?Qx(this.raw,i,o,d):!1}},ie=class extends ct{animatedKind;_sprite=null;_frameCanvas=null;_frameIndex=0;_anchorTime=0;_playing=!1;_videoEl=null;_frameDirty=!1;_rvfcActive=!1;_contentVersion=0;_onNewFrame=null;constructor(e,t){super(e),this.animatedKind=t}get isImageType(){return!0}get animating(){if(this.animatedKind==="video"){let e=this._videoEl;return!!e&&!e.paused&&!e.ended}return this._playing&&!!this._sprite&&this._sprite.framesLength>1}get paintSource(){return this.animatedKind==="video"?this._videoEl:this._frameCanvas}attachSprite(e,t){this._sprite=e,this._onNewFrame=t??null;let r=document.createElement("canvas");r.width=e.frameWidth,r.height=e.canvas.height,this._frameCanvas=r,this._frameIndex=0,this._anchorTime=performance.now(),this._playing=e.framesLength>1,this.blitFrame(),this.invalidateGeometryCache(),this._renderNotify?.()}attachVideo(e,t){this._videoEl=e,this._onNewFrame=t??null;let r=()=>{this._frameDirty=!0,this._onNewFrame?.()};e.addEventListener("play",()=>this.startFrameWatch()),e.addEventListener("pause",r),e.addEventListener("seeked",r),e.addEventListener("ended",()=>{try{e.currentTime=0,e.pause()}catch{}}),this.invalidateGeometryCache(),this._renderNotify?.(),e.play().catch(()=>{})}tick(e){if(this.animatedKind==="video"){let s=this._videoEl;if(!s)return!1;if(this._frameDirty)return this._frameDirty=!1,this._contentVersion++,!0;let a=this._rvfcActive?!1:!s.paused&&!s.ended;return a&&this._contentVersion++,a}let t=this._sprite;if(!this._playing||!t||t.framesLength<=1)return!1;let r=!1,o=0,i=t.framesLength;for(;o<i;){let s=t.frameDelays[this._frameIndex]||t.delay||100;if(e-this._anchorTime<s)break;this._anchorTime+=s,this._frameIndex=(this._frameIndex+1)%i,r=!0,o++}return r&&(this._contentVersion++,this.blitFrame()),r}play(){if(this.animatedKind==="video"){this._videoEl?.play().catch(()=>{});return}!this._sprite||this._sprite.framesLength<=1||(this._playing=!0,this._anchorTime=performance.now())}pause(){if(this.animatedKind==="video"){this._videoEl?.pause();return}this._playing=!1}stop(){if(this.animatedKind==="video"){let e=this._videoEl;if(!e)return;try{e.currentTime=0,e.pause()}catch{}return}this._playing=!1,this._frameIndex=0,this._contentVersion++,this.blitFrame()}syncVideoToTime(e,t){if(this.animatedKind!=="video")return;let r=this._videoEl;if(!r)return;r.pause();let o=r.duration,i=Number.isFinite(o)&&o>0?Math.min(Math.max(e,0),o):Math.max(e,0);try{r.currentTime=i}catch{}t&&r.play().catch(()=>{})}get frameIndex(){return this._frameIndex}get contentVersion(){return this._contentVersion}get mediaDuration(){if(this.animatedKind==="video"){let t=this._videoEl?.duration;if(t&&Number.isFinite(t))return t;let r=Number(this.raw.duration);return Number.isFinite(r)&&r>0?r:0}let e=this._sprite;return e?e.frameDelays.reduce((t,r)=>t+(r||e.delay||100),0)/1e3:0}startFrameWatch(){let e=this._videoEl;if(!e||this._rvfcActive||typeof e.requestVideoFrameCallback!="function")return;this._rvfcActive=!0;let t=()=>{if(!(!this._rvfcActive||!this._videoEl)){if(this._videoEl.paused||this._videoEl.ended){this._rvfcActive=!1;return}this._frameDirty=!0,this._onNewFrame?.(),e.requestVideoFrameCallback(t)}};e.requestVideoFrameCallback(t)}blitFrame(){let e=this._sprite,t=this._frameCanvas;if(!e||!t)return;let r=t.getContext("2d");r&&(r.clearRect(0,0,t.width,t.height),r.drawImage(e.canvas,this._frameIndex*e.frameWidth,0,e.frameWidth,e.canvas.height,0,0,t.width,t.height))}detach(){this._playing=!1,this._rvfcActive=!1,this._frameDirty=!1;let e=this._videoEl;if(e)try{e.pause(),e.removeAttribute("src"),e.load()}catch{}this._videoEl=null,this._sprite=null,this._frameCanvas=null,this._onNewFrame=null}get dims(){return this.animatedKind==="gif"?{x:this.raw.width??this._sprite?.frameWidth??0,y:this.raw.height??this._sprite?.canvas.height??0}:{x:this.raw.width??this._videoEl?.videoWidth??0,y:this.raw.height??this._videoEl?.videoHeight??0}}},ad=(n,e,t)=>{let r=n.length/2,o=!1;for(let i=0,s=r-1;i<r;s=i++){let a=n[i*2],l=n[i*2+1],u=n[s*2],c=n[s*2+1];l>t!=c>t&&e<(u-a)*(t-l)/(c-l)+a&&(o=!o)}return o},J=class n extends ct{children=[];constructor(e,t){super(e);let r=Array.isArray(e.objects)?e.objects:[];for(let o of r){if(!o||typeof o.type!="string")continue;let i=t(o);i&&this.children.push(i)}this.syncChildMatrices()}set(e){super.set(e),this.syncChildMatrices()}setParentMatrix(e,t=1){super.setParentMatrix(e,t),this.syncChildMatrices()}setAnimationOverride(e){super.setAnimationOverride(e),this.syncChildMatrices()}syncChildMatrices(){let e=this.matrix,t=this.renderOpacity;for(let r of this.children)r.setParentMatrix(e,t)}get dims(){let e=Number(this.raw.width),t=Number(this.raw.height);return{x:Number.isFinite(e)&&e>0?e:0,y:Number.isFinite(t)&&t>0?t:0}}containsPoint(e,t,r=0){return this.visible?this.children.some(o=>o.visible&&o.containsPoint(e,t,r)):!1}get inkACoords(){let e=1/0,t=1/0,r=-1/0,o=-1/0;for(let i of this.children)if(i.visible)for(let s of[i.inkACoords.tl,i.inkACoords.tr,i.inkACoords.br,i.inkACoords.bl])e=Math.min(e,s.x),t=Math.min(t,s.y),r=Math.max(r,s.x),o=Math.max(o,s.y);return Number.isFinite(e)?{tl:{x:e,y:t},tr:{x:r,y:t},br:{x:r,y:o},bl:{x:e,y:o}}:this.aCoords}childAtPoint(e,t,r=0){for(let o=this.children.length-1;o>=0;o--){let i=this.children[o];if(!(!i.visible||!i.containsPoint(e,t,r)))return i instanceof n&&!(i instanceof te)&&!(i instanceof le)?i.childAtPoint(e,t)??i:i}return null}containsDeep(e){return this.children.some(t=>t===e||t instanceof n&&t.containsDeep(e))}adoptChild(e,t=this.children.length){this.children.splice(t,0,e),this.syncChildMatrices()}removeChildRaw(e){let t=this.children.indexOf(e);t<0||(this.children.splice(t,1),e.setParentMatrix(null),this.syncChildMatrices())}moveChildRaw(e,t){let r=this.children.indexOf(e);if(r<0)return;this.children.splice(r,1);let o=Math.max(0,Math.min(t,this.children.length));this.children.splice(o,0,e),this.syncChildMatrices()}toObject(){let e=super.toObject();return e.objects=this.children.map(t=>t.toObject()),e}},te=class n extends J{_layout;_childFactory;_placedShift;get inkACoords(){return this.aCoords}selectedCells=[];cellAnchor=null;cellRange=null;hoveredBorder=null;hoveredIndicator=null;indicatorVisible=!1;borderDragging=!1;hoveredStrip=null;hoveredDragHandle=!1;hoveredRangeHandle=!1;editingCell=null;constructor(e,t){let r=Co(e),o=Yt({...e,width:r.constructorDims.width,height:r.constructorDims.height}),i=xe({...e,width:r.width,height:r.height},o);super({...e,left:i.x,top:i.y,width:r.width,height:r.height,objects:r.children},t),this._layout=r,this._childFactory=t,this._placedShift={x:i.x-(e.left??0),y:i.y-(e.top??0)}}_rebuilding=!1;set(e){let t=["rows","cols","columnWidths","rowHeights","manualRowHeights","minCellWidth","minCellHeight","cellPadding","cellSpacing","cellData"],r=!this._rebuilding&&Object.keys(e).some(o=>t.includes(o));if(super.set(e),r){this._rebuilding=!0;try{this.rebuildTable()}finally{this._rebuilding=!1}}}toObject(){let e=super.toObject();return typeof e.left=="number"&&(e.left=e.left-this._placedShift.x),typeof e.top=="number"&&(e.top=e.top-this._placedShift.y),e}get layout(){return this._layout}get tableView(){let e=this.raw.rows??3,t=this.raw.cols??3,r=this.raw.cellSpacing??0;return{rows:e,cols:t,columnWidths:this._layout.columnWidths,rowHeights:this._layout.rowHeights,cellSpacing:r}}get cellMap(){let e=Array.isArray(this.raw.cellData)?this.raw.cellData:[];return _t(e)}get tableAngle(){return this.raw.angle??0}get objectScale(){return{x:Math.abs(this.raw.scaleX??1),y:Math.abs(this.raw.scaleY??1)}}cellHit(e,t){let r=this.localPoint(e,t);return Kh(this.tableView,this.cellMap,r.x,r.y)}borderHit(e,t){let r=this.localPoint(e,t),o=this.objectScale;return Al(this.tableView,this.cellMap,r.x,r.y,5/o.x,5/o.y)}borderOrIndicatorHit(e,t,r){let o=this.localPoint(e,t),i=this.objectScale;return Qh(this.tableView,this.cellMap,o.x,o.y,{thresholdX:5/i.x,thresholdY:5/i.y,scaleX:this.raw.scaleX??1,scaleY:this.raw.scaleY??1,zoom:r})}stripHit(e,t,r=1){let o=this.localPoint(e,t);return ed(this.tableView,this.dims.x,this.dims.y,o.x,o.y,this.objectScale,r)}dragHandleHit(e,t,r=1){let o=this.localPoint(e,t);return td(this.dims.x,this.dims.y,o.x,o.y,this.objectScale,r)}get expandedCellRange(){if(!this.selectedCells.length)return null;let e=this.cellRange??Xe(this.selectedCells);return e?Ml(this.cellMap,e.r1,e.r2,e.c1,e.c2):null}get selectionBoundsRect(){let e=this.expandedCellRange;return e?wo(this.tableView,e):null}get isFullCellSelection(){let e=this.expandedCellRange;if(!e)return!1;let t=this.tableView;return e.r1===0&&e.c1===0&&e.r2===t.rows-1&&e.c2===t.cols-1}rangeHandleHit(e,t,r=1){if(this.editingCell||!this.selectedCells.length||this.isFullCellSelection)return!1;let o=this.selectionBoundsRect;if(!o)return!1;let i=this.localPoint(e,t);return nd(o,i.x,i.y,this.objectScale,r)}static cellSelectionSink=null;setCellSelection(e,t,r){let o=this.selectedCells,i=o.length!==e.length||o.some((s,a)=>s.row!==e[a].row||s.col!==e[a].col)||this.cellAnchor?.row!==t?.row||this.cellAnchor?.col!==t?.col||this.cellRange?.r1!==r?.r1||this.cellRange?.r2!==r?.r2||this.cellRange?.c1!==r?.c1||this.cellRange?.c2!==r?.c2;this.selectedCells=e,this.cellAnchor=t,this.cellRange=r,i&&n.cellSelectionSink?.(this)}setRowSelection(e){let t=Yi(this.cellMap,this.tableView.cols,e);this.setCellSelection(t,t[0]??null,Xe(t))}setColumnSelection(e){let t=zi(this.cellMap,this.tableView.rows,e);this.setCellSelection(t,t[0]??null,Xe(t))}clearCellSelection(){let e=this.selectedCells.length>0;this.selectedCells=[],this.cellAnchor=null,this.cellRange=null,e&&n.cellSelectionSink?.(this)}get hasCellSelection(){return this.selectedCells.length>0}clearCellInteractionState(){this.clearCellSelection(),this.clearHoverState()}clearHoverState(){this.hoveredBorder=null,this.hoveredIndicator=null,this.indicatorVisible=!1,this.hoveredStrip=null,this.hoveredDragHandle=!1,this.hoveredRangeHandle=!1}getRowMinHeight(e){let t=this.raw.minCellHeight??40;return Math.max(t,this._layout.rowTextFloors[e]??0)}cellBounds(e,t){let r=we(this.cellMap,e,t);if(r?.isMerged)return null;let o=this.tableView;if(e<0||t<0||e>=o.rows||t>=o.cols)return null;let i=r?.colspan??1,s=r?.rowspan??1;return wo(o,{r1:e,r2:e+s-1,c1:t,c2:t+i-1})}cellSceneCenter(e,t){let r=this.cellBounds(e,t);return r?Q(this.matrix,r.left+r.width/2,r.top+r.height/2):null}rebuildTable(){let e=this.raw.reflowOriginX??"left",t=this.raw.reflowOriginY??"top",r=(b,x)=>({x:e==="left"?-b/2:e==="right"?b/2:0,y:t==="top"?-x/2:t==="bottom"?x/2:0}),o=this.dims.x,i=this.dims.y,s=Bn({...this.raw,width:o,height:i}),a=Q(s,r(o,i).x,r(o,i).y),l=Co(this.raw,void 0,this.editingCell?{hideTextCell:this.editingCell}:void 0);this._layout=l;let u=[];for(let b of l.children){let x=this._childFactory(b);x&&u.push(x)}this.children.length=0,this.children.push(...u),this.set({width:l.width,height:l.height,objects:l.children,rowHeights:l.rowHeights});let c=r(l.width,l.height),h=a.x-(s[0]*c.x+s[2]*c.y),d=a.y-(s[1]*c.x+s[3]*c.y),f=xe({...this.raw,width:l.width,height:l.height},{x:h,y:d});this.set({left:f.x,top:f.y});let m=Yt({...this.raw,width:l.constructorDims.width,height:l.constructorDims.height}),p=xe({...this.raw,width:l.width,height:l.height},m);this._placedShift={x:p.x-(this.raw.left??0),y:p.y-(this.raw.top??0)}}},ae=class extends ct{_clipImageEl=null;constructor(e){super(e)}get clipImageEl(){return this._clipImageEl}set clipImageEl(e){this._clipImageEl=e,this._renderNotify?.()}get clipImageRaw(){let e=this.raw.clipImage;return!e||typeof e!="object"||typeof e.src!="string"?null:e}_clipVideoEl=null;_clipSprite=null;_clipFrameCanvas=null;_clipFrameIndex=0;_clipAnchorTime=0;_clipPlaying=!1;_clipOnNewFrame=null;clipDynamicVersion=0;get clipDynamicKind(){let e=se(this.clipImageRaw);return e===L.VIDEO?"video":e===L.GIF?"gif":null}get hasDynamicClip(){return!!this._clipVideoEl||!!this._clipFrameCanvas}get clipAnimating(){return this._clipVideoEl?!this._clipVideoEl.paused&&!this._clipVideoEl.ended:this._clipPlaying&&!!this._clipSprite&&this._clipSprite.framesLength>1}attachClipSprite(e,t){this._clipSprite=e,this._clipOnNewFrame=t??null;let r=document.createElement("canvas");r.width=e.frameWidth,r.height=e.canvas.height,this._clipFrameCanvas=r,this._clipFrameIndex=0,this._clipAnchorTime=performance.now(),this._clipPlaying=e.framesLength>1,this.clipDynamicVersion++,this.blitClipFrame(),this._renderNotify?.()}attachClipVideo(e,t){this._clipVideoEl=e,this._clipOnNewFrame=t??null;let r=()=>{this.clipDynamicVersion++,this._renderNotify?.(),this._clipOnNewFrame?.()};e.addEventListener("seeked",r),e.addEventListener("pause",r),e.addEventListener("play",r),this.clipDynamicVersion++,this._renderNotify?.(),e.play().catch(()=>{})}dynamicClipSource(){return this._clipVideoEl?this._clipVideoEl:this._clipFrameCanvas}tickDynamicClip(e){if(this._clipVideoEl){let i=this._clipVideoEl;return!i.paused&&!i.ended?(this.clipDynamicVersion++,!0):!1}if(!this._clipPlaying||!this._clipSprite||this._clipSprite.framesLength<=1)return!1;let t=!1,r=0,o=this._clipSprite.framesLength;for(;r<o;){let i=this._clipSprite.frameDelays[this._clipFrameIndex]||this._clipSprite.delay||100;if(e-this._clipAnchorTime<i)break;this._clipAnchorTime+=i,this._clipFrameIndex=(this._clipFrameIndex+1)%o,t=!0,r++}return t&&(this.clipDynamicVersion=this._clipFrameIndex,this.blitClipFrame()),t}blitClipFrame(){let e=this._clipSprite,t=this._clipFrameCanvas;if(!e||!t)return;let r=t.getContext("2d");r&&(r.clearRect(0,0,t.width,t.height),r.drawImage(e.canvas,this._clipFrameIndex*e.frameWidth,0,e.frameWidth,e.canvas.height,0,0,t.width,t.height))}detachDynamicClip(){this._clipPlaying=!1;try{this._clipVideoEl?.pause()}catch{}this._clipVideoEl=null,this._clipSprite=null,this._clipFrameCanvas=null,this._renderNotify?.()}get clipMediaDuration(){if(this.clipDynamicKind!=="video")return 0;let e=this._clipVideoEl?.duration;if(e&&Number.isFinite(e))return e;let t=Number(this.clipImageRaw?.duration);return Number.isFinite(t)&&t>0?t:0}playClipMedia(){this.clipDynamicKind==="video"&&this._clipVideoEl?.play().catch(()=>{})}pauseClipMedia(){this.clipDynamicKind==="video"&&this._clipVideoEl?.pause()}syncClipMediaToTime(e,t){if(this.clipDynamicKind!=="video")return;let r=this._clipVideoEl;if(!r)return;r.pause();let o=r.duration,i=Number.isFinite(o)&&o>0?Math.min(Math.max(e,0),o):Math.max(e,0);try{r.currentTime=i}catch{}t&&r.play().catch(()=>{})}},le=class extends J{constructor(e,t){super(e,t);let r=this.layoutParams,o=Zn(e.layoutConfig),i=!!o&&o.pieces.length===this.maskChildren.length;o&&!i&&this.reconcileIncompleteLayout(o),this.set({width:r.width,height:r.height}),this.reconcileOverlappingChildren()}get inkACoords(){return this.aCoords}reconcileIncompleteLayout(e){let t=this.maskChildren;if(t.length>0&&e.pieces.length>t.length){let r=e.pieces.slice(0,t.length),o=1,i=1;for(let s of r)o=Math.max(o,s.col+(s.colSpan??1)),i=Math.max(i,s.row+(s.rowSpan??1));e.cols=o,e.rows=i,e.pieces=r,this.set({layoutConfig:{rows:i,cols:o,pieces:r}})}this.relayoutFromConfig(e,this.layoutParams)}reconcileOverlappingChildren(){let{hGap:e,vGap:t}=this.layoutParams,r=this.layoutParams.width/2,o=this.layoutParams.height/2,i=.5,s=this.maskChildren,a=new Map,l=c=>{let h=c.raw,d=h.width??0,f=h.height??0;return{x0:h.left-d/2,x1:h.left+d/2,y0:h.top-f/2,y1:h.top+f/2}};for(let c=0;c<s.length;c++)for(let h=c+1;h<s.length;h++){let d=l(s[c]),f=l(s[h]),m=Math.min(d.x1,f.x1)-Math.max(d.x0,f.x0),p=Math.min(d.y1,f.y1)-Math.max(d.y0,f.y0);if(!(m>i&&p>i))continue;let b=d.x0<=f.x0?s[c]:s[h],x=b===s[c]?s[h]:s[c],g=l(b),y=l(x);if(g.x1>y.x0+i){if(Math.abs(g.x1-r)<i&&y.x0<r-i){let P=a.get(b)??{};P.right=y.x0-e,a.set(b,P)}else if(Math.abs(y.x0+r)<i&&g.x1>-r+i){let P=a.get(x)??{};P.left=g.x1+e,a.set(x,P)}}let v=d.y0<=f.y0?s[c]:s[h],S=v===s[c]?s[h]:s[c],w=l(v),R=l(S);if(w.y1>R.y0+i){if(Math.abs(w.y1-o)<i&&R.y0<o-i){let P=a.get(v)??{};P.bottom=R.y0-t,a.set(v,P)}else if(Math.abs(R.y0+o)<i&&w.y1>-o+i){let P=a.get(S)??{};P.top=w.y1+t,a.set(S,P)}}}if(!a.size)return;let u=[];for(let[c,h]of a){let d=l(c),f=h.left??d.x0,m=h.right??d.x1,p=h.top??d.y0,b=h.bottom??d.y1;if(!(m-f>i)||!(b-p>i))continue;let x={left:(f+m)/2,width:m-f,top:(p+b)/2,height:b-p};c.set(x),u.push(`${String(c.raw.id)}→${Math.round(x.left)},${Math.round(x.top)},${Math.round(x.width)}×${Math.round(x.height)}`)}u.length&&console.info("[PuzzleNode] 装载期叠压自愈(外缘钉签名,批次 307 存量损伤):",u.join("; "))}get layoutParams(){return{width:this.raw.layoutWidth??600,height:this.raw.layoutHeight??600,hGap:this.raw.hGap??12,vGap:this.raw.vGap??12,groupPadding:this.raw.groupPadding??0}}get maskChildren(){return this.children.filter(e=>e instanceof ae)}containsPoint(e,t,r=0){return super.containsPoint(e,t,r)?!0:this.visible?ct.prototype.containsPoint.call(this,e,t,r):!1}applyMaskParams(e){let t={};for(let[r,o]of Object.entries(e))if(o!==void 0){t[r]=o;for(let i of this.maskChildren)i.set({[r]:o})}Object.keys(t).length&&this.set(t)}updateGapParams(e){let t={};if(typeof e.hGap=="number"&&(t.hGap=e.hGap),typeof e.vGap=="number"&&(t.vGap=e.vGap),typeof e.groupPadding=="number"&&(t.groupPadding=e.groupPadding),!Object.keys(t).length)return;this.set(t);let r=Zn(this.raw.layoutConfig);r&&this.relayoutFromConfig(r,this.layoutParams)}updateLayout(e){let t=Zn(this.raw.layoutConfig);if(!t||!t.pieces.length){console.warn("[PuzzleNode] layoutConfig is invalid, skipping layout update");return}let r={...this.layoutParams};typeof e.width=="number"&&e.width>0&&(r.width=e.width),typeof e.height=="number"&&e.height>0&&(r.height=e.height),typeof e.hGap=="number"&&(r.hGap=e.hGap),typeof e.vGap=="number"&&(r.vGap=e.vGap),typeof e.groupPadding=="number"&&(r.groupPadding=e.groupPadding),this.set({hGap:r.hGap,vGap:r.vGap,groupPadding:r.groupPadding}),this.relayoutFromConfig(t,r),this.set({width:r.width,height:r.height})}editingMask=null;get editingMaskIndex(){return this.editingMask?this.maskChildren.indexOf(this.editingMask):-1}maskEdgeOnOuterBorder(e,t){let r=this.layoutParams,o=Math.max(0,r.width-r.groupPadding*2),i=Math.max(0,r.height-r.groupPadding*2),s=o/2,a=i/2,l=e.raw.left??0,u=e.raw.top??0,c=e.raw.width??0,h=e.raw.height??0,d=.5;return t==="left"?l-c/2<=-s+d:t==="right"?l+c/2>=s-d:t==="top"?u-h/2<=-a+d:u+h/2>=a-d}exitMaskEditing(){this.editingMask=null}removeCol(e){let t=Zn(this.raw.layoutConfig);if(!t||t.pieces.length!==this.maskChildren.length)return!1;let r=Hh(t.pieces,t.cols,e);return r?(t.cols-=1,this.applyPuzzleRemoval(t,r.removed)):!1}removeRow(e){let t=Zn(this.raw.layoutConfig);if(!t||t.pieces.length!==this.maskChildren.length)return!1;let r=Gh(t.pieces,t.rows,e);return r?(t.rows-=1,this.applyPuzzleRemoval(t,r.removed)):!1}removePiece(e){let t=Zn(this.raw.layoutConfig);if(!t||t.pieces.length!==this.maskChildren.length)return!1;let r=Xh(t.pieces,e);return r?this.applyPuzzleRemoval(t,r.removed):!1}applyPuzzleRemoval(e,t){if(!e)return!1;let r=new Set(t),o=this.children.filter(s=>!(s instanceof ae&&r.has(this.maskChildren.indexOf(s)))),i=o.filter(s=>s instanceof ae).map(s=>s.toObject());return this.children.length=0,this.children.push(...o),this.set({layoutConfig:{rows:e.rows,cols:e.cols,pieces:e.pieces},objects:i}),this.relayoutFromConfig(e,this.layoutParams),!0}toObject(){let e=super.toObject();return e.objects=this.children.map(t=>t.toObject()),e}relayoutFromConfig(e,t){let r=wl(e,t);this.maskChildren.forEach((o,i)=>{let s=r[i];if(!s)return;let a=o.raw.width||s.w,l=o.raw.height||s.h;o.set({left:s.cx,top:s.cy,width:s.w,height:s.h});let u=o.clipImageRaw;if(u){let c=u.width||0,h=u.height||0;if(c&&h){let d=Math.max(a/c,l/h),f=Math.max(s.w/c,s.h/h),m=u.scaleX??1,p=d?m/d:1,b=f*(p||1);o.set({clipImage:{...u,scaleX:b,scaleY:b}})}typeof u.clipX=="number"&&o.set({clipImage:{...o.raw.clipImage,clipX:(u.clipX||0)*(a?s.w/a:1)}}),typeof u.clipY=="number"&&o.set({clipImage:{...o.raw.clipImage,clipY:(u.clipY||0)*(l?s.h/l:1)}})}}),this.set({layoutWidth:t.width,layoutHeight:t.height})}},Zi=n=>{if(!dt.has(se(n)))return null;let e=Number(n.cropX)||0,t=Number(n.cropY)||0;if(!(typeof n.cropX=="number"||typeof n.cropY=="number"||n.cropSizeMode==="visible"||e>0||t>0)||typeof n.width!="number"||typeof n.height!="number")return null;let o=n.cropSizeMode==="visible";return{sx:e,sy:t,sw:Math.max(0,o?n.width:n.width-e),sh:Math.max(0,o?n.height:n.height-t)}},Ct=n=>{if(!n||typeof n.type!="string")return null;let e=se(n);return e===L.TABLE?new te(n,Ct):pi.has(e)?new le(n,Ct):ot.has(e)&&typeof n.src=="string"?new ae(n):e===L.GROUP?new J(n,Ct):bi.has(e)&&typeof n.src=="string"?new ie(n,"gif"):xi.has(e)&&typeof n.src=="string"?new ie(n,"video"):dt.has(e)&&typeof n.src=="string"?new ct(n):zn.has(e)?new ct(n):sn.has(e)&&typeof n.text=="string"?new Se(n):e===L.PATH?new Ar(n):ft.has(e)?new Nr(n):Xn.has(e)?new gn(n):null},Bl=n=>{let e=[],t={};for(let r of n){let o=Ct(r);o?e.push(o):r&&typeof r.type=="string"&&(t[r.type]=(t[r.type]||0)+1)}return{nodes:e,skippedTypes:t}},Je=(n,e)=>new Promise((t,r)=>{let o=new Image;e!==null&&(o.crossOrigin=e||"anonymous"),o.onload=()=>t(o),o.onerror=()=>r(new Error(`[engine] image load failed: ${n.slice(0,80)}`)),o.src=n}),Ro=n=>{if(n instanceof J||n instanceof ae||n instanceof ie||n.isImageType)return null;let e=n.raw.mask;return!e||e.disabled===!0||typeof e.src!="string"||!e.src?null:e.src};var Zx=n=>typeof n!="string"||!n||/^cmyk\(/i.test(n)?null:n,Dt=n=>{if(n&&typeof n=="object"&&!Array.isArray(n)){let e=n;if(typeof e.r!="number"||typeof e.g!="number"||typeof e.b!="number")return null;let t=r=>Math.max(0,Math.min(255,Math.round(r)));return`rgba(${t(e.r)}, ${t(e.g)}, ${t(e.b)}, 1)`}return Zx(n)},Wl=n=>n?.offsetEnable?{x:Number(n.offsetX)||0,y:Number(n.offsetY)||0}:{x:0,y:0},nr=n=>{if(typeof n!="string")return;let e=n.trim().toLowerCase().replace(/\s*\([^)]*\)\s*$/,"").replace(/\s+/g,"-");if(!(!e||e==="normal"||e==="source-over")){if(e==="linear-dodge")return"lighter";if(/^[a-z-]+$/.test(e))return e}},Kt=(n,e={})=>{if(!n||typeof n!="object"||Array.isArray(n))return null;let t=n,r=c=>{if(!c||typeof c!="object")return!1;let h=c;return h.enabled!==!1&&h.showInDialog!==!1},o=[];if(Array.isArray(t.dropShadow))for(let c of t.dropShadow){if(!r(c))continue;let h=Dt(c?.fill)??Dt(c?.color)??"rgba(0,0,0,0.5)",d=Number(c?.blur)||0,f=Number(c?.offsetX)||0,m=Number(c?.offsetY)||0;!d&&!f&&!m||o.push({color:h,rgba:ee(h),blur:d,offsetX:f,offsetY:m,blendMode:nr(c?.blendMode)})}let i=[];if(Array.isArray(t.innerShadow))for(let c of t.innerShadow){if(!r(c))continue;let h=Dt(c?.fill)??Dt(c?.color)??"rgba(0,0,0,0.5)",d=Number(c?.blur)||0,f=Number(c?.offsetX)||0,m=Number(c?.offsetY)||0;!d&&!f&&!m||i.push({color:h,rgba:ee(h),blur:d,offsetX:f,offsetY:m,blendMode:nr(c?.blendMode)})}let s=[];if(Array.isArray(t.solidFill))for(let c of t.solidFill){if(!r(c))continue;let h=Number(c?.fillType)||0;if(h===1){if(!c?.fill||typeof c.fill!="object")continue;let f=Gn(c.fill);if(!f)continue;s.push({kind:"gradient",decl:f,offset:Wl(c),blendMode:nr(c?.blendMode)});continue}if(h!==0)continue;let d=Dt(c?.fill)??Dt(c?.color);d&&s.push({kind:"solid",color:d,rgba:ee(d),offset:Wl(c),blendMode:nr(c?.blendMode)})}let a=[];if(Array.isArray(t.stroke))for(let c of t.stroke){if(!r(c))continue;let h=c?.size&&typeof c.size=="object"?Number(c.size.value):0,d=e.text?h:Number(c?.strokeWidth)||h||0;if(!d)continue;let f=c?.fill&&typeof c.fill=="object"&&!Array.isArray(c.fill)?Gn(c.fill):null,m=Dt(c?.fill)??Dt(c?.color)??"#666666",p=c?.position||c?.strokeAlignment||(e.text?"center":"outside");a.push({kind:f?"gradient":"solid",color:m,rgba:ee(m),width:d,alignment:p,offset:Wl(c),blendMode:nr(c?.blendMode),...f?{decl:f}:{}})}let l,u=n.bevel;if(u&&typeof u=="object"&&!Array.isArray(u)){let c=u;if(r(c)){let h=Number(n.scale)||1,d=c.size&&typeof c.size=="object"?Number(c.size.value):Number(c.size),f=(Number.isFinite(d)?d:0)/(h>0?h:1);if(f>0){let m=typeof c.style=="string"?c.style.toLowerCase():"",p=m.includes("outer")?"outer":m.includes("pillow")?"pillow":m.includes("emboss")?"emboss":"inner",b=typeof c.technique=="string"&&c.technique.toLowerCase().includes("chisel")&&!c.technique.toLowerCase().includes("soft")?"hard":"smooth",x=Dt(c.highlightColor)??"rgba(255, 255, 255, 1)",g=Dt(c.shadowColor)??"rgba(0, 0, 0, 1)";l={style:p,technique:b,sizePx:f,strength:Math.min(4,Math.max(0,Number(c.strength??c.depth)||1)),angleDeg:Number.isFinite(Number(c.angle))?Number(c.angle):120,altitudeDeg:Math.min(90,Math.max(0,Number.isFinite(Number(c.altitude))?Number(c.altitude):30)),directionDown:typeof c.direction=="string"&&c.direction.toLowerCase()==="down",highlight:{color:x,rgba:ee(x),opacity:Math.min(1,Math.max(0,Number(c.highlightOpacity)||.5)),blendMode:nr(c.highlightBlendMode)},shadow:{color:g,rgba:ee(g),opacity:Math.min(1,Math.max(0,Number(c.shadowOpacity)||.5)),blendMode:nr(c.shadowBlendMode)}}}}}return o.length===0&&i.length===0&&s.length===0&&a.length===0&&!l?null:{dropShadows:o,innerShadows:i,solidFills:s,strokes:a,...l?{bevel:l}:{}}},Sn=n=>{let e=c=>String(Math.round(c*1e4)/1e4),t=c=>c.map(e).join(","),r=c=>c?`~${c}`:"",o=n.dropShadows.map(c=>`${t(c.rgba)}:${e(c.blur)}:${e(c.offsetX)}:${e(c.offsetY)}${r(c.blendMode)}`).join(";"),i=n.innerShadows.map(c=>`${t(c.rgba)}:${e(c.blur)}:${e(c.offsetX)}:${e(c.offsetY)}${r(c.blendMode)}`).join(";"),s=c=>{let h=`@${e(c.offset.x)},${e(c.offset.y)}${r(c.blendMode)}`;if(c.kind==="solid")return t(c.rgba)+h;let d=c.decl,f=d.stops.map(p=>`${e(p.offset)}@${p.color.map(e).join(",")}`).join(","),m=d.gradientTransform?d.gradientTransform.map(e).join(","):"-";return`g${d.kind[0]}:${e(d.x1)},${e(d.y1)},${e(d.x2)},${e(d.y2)},${e(d.r1)},${e(d.r2)},${d.gradientUnits},${m};${f}${h}`},a=n.solidFills.map(s).join(";"),l=n.strokes.map(c=>`${t(c.rgba)}:${e(c.width)}:${c.alignment}@${e(c.offset.x)},${e(c.offset.y)}${r(c.blendMode)}${c.decl?`~g${di(c.decl)}`:""}`).join(";"),u=n.bevel?`${n.bevel.style}/${n.bevel.technique}:${e(n.bevel.sizePx)}:${e(n.bevel.strength)}:${e(n.bevel.angleDeg)}:${e(n.bevel.altitudeDeg)}:${n.bevel.directionDown?"d":"u"}:${t(n.bevel.highlight.rgba)}@${e(n.bevel.highlight.opacity)}${r(n.bevel.highlight.blendMode)}:${t(n.bevel.shadow.rgba)}@${e(n.bevel.shadow.opacity)}${r(n.bevel.shadow.blendMode)}`:"";return`psd|${o}|${i}|${a}|${l}|${u}`};var Jx=512,eg=new Set([L.QRCODE,L.BARCODE,L.ECHART,L.FABRIC_ECHART]),dd=n=>{let e=Kt(n.raw.effects);if(!e)return null;let t=e.dropShadows,r=e.strokes;return!t.length&&!r.length?null:{shadows:t,strokes:r,key:Sn(e)}},tg=n=>n?`${n.sx},${n.sy},${n.sw},${n.sh}`:"none",Hl=new WeakMap,hd=n=>Math.max(1,Math.min(Jx,Math.floor(n))),ng=(n,e,t,r,o)=>{let i=dd(n);if(!i)return;let s=n.imageEl;if(!s)return;let a=n.dims,l=null;if(i.shadows.length){let h=Oi(n,i.shadows,s,1,n.cropRect);if(!h)throw new Error("fx mask: shadow bake unavailable");let d=h.canvas.getContext("2d",{willReadFrequently:!0});if(!d)throw new Error("fx mask: shadow ctx unavailable");l={data:d.getImageData(0,0,h.w,h.h).data,w:h.w,h:h.h}}let u=[];if(i.strokes.length){for(let h of pn(n,i.strokes,s,!0,1,n.cropRect)){let d=h.canvas.getContext("2d",{willReadFrequently:!0});if(!d)throw new Error("fx mask: stroke ctx unavailable");u.push({data:d.getImageData(0,0,h.w,h.h).data,w:h.w,h:h.h,dx:h.dx,dy:h.dy})}if(!u.length)throw new Error("fx mask: stroke bake unavailable")}let c=n.matrix;for(let h=0;h<r;h++)for(let d=0;d<t;d++){if(e[h*t+d])continue;let f=((d+.5)/t-.5)*a.x,m=((h+.5)/r-.5)*a.y;if(l){let p=Math.round(c[0]*f+c[2]*m+l.w/2),b=Math.round(c[1]*f+c[3]*m+l.h/2);if(p>=0&&b>=0&&p<l.w&&b<l.h&&l.data[(b*l.w+p)*4+3]>o){e[h*t+d]=1;continue}}for(let p of u){let b=Math.round(f-p.dx+p.w/2),x=Math.round(m-p.dy+p.h/2);if(b>=0&&x>=0&&b<p.w&&x<p.h&&p.data[(x*p.w+b)*4+3]>o){e[h*t+d]=1;break}}}},rg=n=>{let e=n.imageEl,t=n.dims,r=n.cropRect,o=r?r.sw:e?.naturalWidth||0,i=r?r.sh:e?.naturalHeight||0;if(!e||!(t.x>0)||!(t.y>0)||!(o>0)||!(i>0))return{mask:new Uint8Array(0),maskW:0,maskH:0};let s=hd(t.x),a=hd(t.y),l=document.createElement("canvas");l.width=s,l.height=a;let u=new Uint8Array(0);try{let c=l.getContext("2d",{willReadFrequently:!0});if(c){c.drawImage(e,r?r.sx:0,r?r.sy:0,o,i,0,0,s,a);let h=Math.min(255,Ki/Math.max(n.renderOpacity,1/255)),{data:d}=c.getImageData(0,0,s,a);u=new Uint8Array(s*a);for(let f=0;f<u.length;f++)d[f*4+3]>h&&(u[f]=1);ng(n,u,s,a,h)}}catch{u=new Uint8Array(0)}finally{l.width=0,l.height=0}return{mask:u,maskW:u.length>0?s:0,maskH:u.length>0?a:0}},og=n=>{let e=`${n.dims.x},${n.dims.y}|${tg(n.cropRect)}|${n.renderOpacity}`,t=dd(n);if(!t)return e;let r=n.matrix,o=i=>Math.round(i*1e3)/1e3;return`${e}|${t.key}|${o(r[0])},${o(r[1])},${o(r[2])},${o(r[3])}`},ig=n=>{let e=og(n),t=Hl.get(n);if(t&&t.stamp===e&&t.element===n.imageEl)return t.rec;let r=rg(n);return Hl.set(n,{element:n.imageEl,stamp:e,rec:r}),r},sg=(n,e,t)=>{let r=ig(n);if(r.maskW===0||r.maskH===0)return!1;let o=n.dims,i=n.localPoint(e,t),s=i.x+o.x/2,a=i.y+o.y/2;if(s<0||a<0||s>=o.x||a>=o.y)return!0;let l=Math.min(r.maskW-1,Math.floor(s/o.x*r.maskW)),u=Math.min(r.maskH-1,Math.floor(a/o.y*r.maskH));return r.mask[u*r.maskW+l]===0},ag=(n,e,t,r)=>{for(let o of n.children)if(!(!o.visible||!o.containsPoint(e,t,r.strokeBandOf?.(o)??0))&&!Ji(o,e,t,r))return!0;return!1},Ji=(n,e,t,r)=>{if(n instanceof te)return!1;let o=typeof n.raw.globalCompositeOperation=="string"?n.raw.globalCompositeOperation:"";return o==="multiply"&&!r.selection.includes(n)||o&&o!=="source-over"&&n.typeKey!==L.REFERENCELINE&&r.hasSelectableBelow()?!0:n instanceof le||n instanceof ae||n instanceof ie||n.isTextType||n.isLineType?!1:n instanceof J?!ag(n,e,t,r):!n.isImageType||eg.has(n.typeKey)||typeof n.raw.name=="string"&&n.raw.name.toLowerCase()==="qrcode"||!dt.has(n.typeKey)?!1:sg(n,e,t)},lg=n=>{Hl.delete(n)},Ir=(n,e,t,r)=>{for(let o=n.children.length-1;o>=0;o--){let i=n.children[o];if(!(!i.visible||i.raw.evented===!1||!i.containsPoint(e,t)||Ji(i,e,t,{selection:r,hasSelectableBelow:()=>{for(let a=o-1;a>=0;a--){let l=n.children[a];if(l.visible&&l.raw.evented!==!1&&l.containsPoint(e,t))return!0}return!1}})))return i instanceof J&&!(i instanceof te)&&!(i instanceof le)?Ir(i,e,t,r)??i:i}return null};import cg from"rbush";var Gl=0,ug=()=>(Gl=(Gl+1)%4294967295,`tx-${Date.now().toString(36)}-${Gl.toString(36)}`),Po=class{events=new On;_nodes=[];_index=new cg;_indexDirty=!1;_selection=[];_editingNode=null;_editingTextSnapshot="";_editingBeforeObject=null;_editingBitmapSnapshot=null;_editingTransient=!1;editSelection={start:0,end:0};skippedTypes={};get nodes(){return this._nodes}get selection(){return this._selection}get editingNode(){return this._editingNode}_selectionFrame=null;get selectionFrame(){return this._selectionFrame}setSelectionFrame(e){this._selectionFrame=e}get activeObject(){return this._selection[0]??null}_activeGroupChild=null;get activeGroupChild(){return this._activeGroupChild}setActiveGroupChild(e){let t=this._selection.length===1?this._selection[0]:null,r=e&&t instanceof J&&t.containsDeep(e)?e:null;if(this._activeGroupChild===r)return;let o=this._activeGroupChild;this._activeGroupChild=r,o&&this.events.fire("group:child-deactivated"),r&&this.events.fire("group:child-activated",r,t)}_groupEditingGroup=null;get groupEditing(){return this._groupEditingGroup!==null}get groupEditingGroup(){return this._groupEditingGroup}setGroupEditing(e,t){if(!e){this._groupEditingGroup=null;return}let r=t??(this._selection.length===1&&this._selection[0]instanceof J?this._selection[0]:null);this._groupEditingGroup=r&&!(r instanceof te)&&!(r instanceof le)?r:null}_hovered=null;get hovered(){return this._hovered}setHovered(e){let r=e!==null&&this._nodes.some(o=>o===e||o instanceof J&&o.containsDeep(e))?e:null;this._hovered!==r&&(this._hovered=r)}_seamHover=null;get seamHover(){return this._seamHover}setSeamHover(e){let t=this._seamHover,r=e&&this._nodes.includes(e.puzzle)&&e.puzzle.maskChildren.includes(e.mask)?e:null;t?.puzzle===r?.puzzle&&t?.mask===r?.mask&&t?.handle===r?.handle||(this._seamHover=r)}loadObjects(e){let{nodes:t,skippedTypes:r}=Bl(e);this._nodes=t,this.skippedTypes=r;for(let o of t)this.attachRenderTracking(o);this.clearSelection(),this.rebuildIndex(),this.bumpStructure()}add(e){this._nodes.push(e),this.attachRenderTracking(e),this.markIndexDirty(),this.events.fire("object:added",e),this.bumpStructure()}remove(e){let t=this._nodes.indexOf(e);t>=0&&this._nodes.splice(t,1),this._selection=this._selection.filter(r=>r!==e),this._selectionFrame=null,this._activeGroupChild&&this.setActiveGroupChild(this._activeGroupChild),this._hovered&&this.setHovered(this._hovered),this.markIndexDirty(),this.events.fire("object:removed",e),this.bumpStructure()}insertAt(e,...t){let r=Math.max(0,Math.min(e,this._nodes.length));this._nodes.splice(r,0,...t);for(let o of t)this.attachRenderTracking(o);this.markIndexDirty();for(let o of t)this.events.fire("object:added",o);return this.bumpStructure(),this._nodes.length}moveNodeTo(e,t){let r=this._nodes.indexOf(e);if(r<0)return;this._nodes.splice(r,1);let o=Math.max(0,Math.min(t,this._nodes.length));this._nodes.splice(o,0,e),this.bumpStructure()}_structureVersion=1;_renderDirty=new Set;get structureVersion(){return this._structureVersion}get renderDirty(){return this._renderDirty}drainRenderDirty(){this._renderDirty.clear()}bumpStructure(){this._structureVersion++,this._renderDirty.clear()}attachRenderTracking(e){if(e._renderNotify=()=>{this._renderDirty.add(e)},e instanceof J)for(let t of e.children)this.attachRenderTracking(t)}findNodeDeep(e){let t=(r,o)=>{for(let i=0;i<r.length;i++){let s=r[i];if(s.id===e)return{node:s,parent:o,index:i};if(s instanceof J&&!(s instanceof te)){let a=t(s.children,s);if(a)return a}}return null};return t(this._nodes,null)}setProps(e,t,r={}){let o="visible"in t;if(o&&t.visible===e.raw.visible&&Object.keys(t).length===1)return;let i=e.visible;e.set(t);let s=o&&e.visible!==i;s&&this.bumpStructure(),o&&!s&&Object.keys(t).length===1||this.markIndexDirty()}rebuildIndex(){let e=[];for(let t of this._nodes){if(!t.visible)continue;let r=t.bounds,o=this.strokeHitBand(t);e.push({minX:r.left-o,minY:r.top-o,maxX:r.right+o,maxY:r.bottom+o,node:t})}this._index.clear(),this._index.load(e),this._indexDirty=!1}commitGeometry(){this._indexDirty&&this.rebuildIndex()}refreshHitIndex(){this.rebuildIndex()}markIndexDirty(){this._indexDirty=!0}_hitZoom=1;setViewportZoom(e){!(e>0)||e===this._hitZoom||(this._hitZoom=e,this.rebuildIndex())}hitBandScene(){return Ol/this._hitZoom}strokeHitBand(e){return ud(e)?Math.max(Number(e.raw.padding)||0,Ol)/this._hitZoom:0}findTarget(e,t){this._indexDirty&&this.rebuildIndex();let r=this._index.search({minX:e,minY:t,maxX:e,maxY:t}),o=new Map;this._nodes.forEach((i,s)=>o.set(i,s)),r.sort((i,s)=>(o.get(s.node)??-1)-(o.get(i.node)??-1));for(let i=0;i<r.length;i++){let s=r[i].node,a=this.hitBandScene();if(!(!s.visible||s.raw.evented===!1||!s.containsPoint(e,t,a))&&!Ji(s,e,t,this.alphaHitContext(r,i,e,t)))return s}return null}alphaHitContext(e,t,r,o){let i=null,s=this.hitBandScene();return{selection:this._selection,strokeBandOf:()=>s,hasSelectableBelow:()=>(i===null&&(i=e.slice(t+1).some(a=>a.node.visible&&a.node.raw.evented!==!1&&a.node.containsPoint(r,o,s))),i)}}objectsIntersectingRect(e,t,r,o){this._indexDirty&&this.rebuildIndex();let i={minX:Math.min(e,r),minY:Math.min(t,o),maxX:Math.max(e,r),maxY:Math.max(t,o)},s=new Set(this._index.search(i).map(a=>a.node));return this._nodes.filter(a=>a.visible&&s.has(a)&&a.bounds.left<=i.maxX&&i.minX<=a.bounds.right&&a.bounds.top<=i.maxY&&i.minY<=a.bounds.bottom&&!a.syntheticOwner&&!Lr.has(String(a.raw.id??""))&&!Ze(a))}setSelection(e,t="create"){this._selection=e.filter(r=>this._nodes.includes(r)),this._selectionFrame=null,this._groupEditingGroup&&!(this._selection.length===1&&this._selection[0]===this._groupEditingGroup)&&(this._groupEditingGroup=null),this._hovered=null,this._selection.length===0?this.events.fire("selection:cleared"):t==="create"?this.events.fire("selection:created",[...this._selection]):this.events.fire("selection:updated",[...this._selection]),this._activeGroupChild&&this.setActiveGroupChild(this._activeGroupChild)}clearSelection(){this._activeGroupChild&&this.setActiveGroupChild(null),this._groupEditingGroup=null,this._hovered=null,this._selection.length!==0&&(this._selection=[],this._selectionFrame=null,this.events.fire("selection:cleared"))}_transformGestureAt=-1/0;get transformGestureAt(){return this._transformGestureAt}applyTransform(e,t,r,o){if(e.length){(r==="moving"||r==="scaling"||r==="rotating")&&(this._transformGestureAt=performance.now());for(let i of e)this.setProps(i,t(i),{deferIndexRebuild:!0});if(this.markIndexDirty(),r==="modified"){this.commitGeometry();let i=o?.before,s=i||o?.action||o?.transactionId?{action:o?.action,before:i?e.map(a=>i.get(a)).filter(a=>!!a):void 0,transactionId:o?.transactionId}:void 0;this.fireObjectModified([...e],s)}else this.events.fire(`object:${r}`,e[0])}}fireObjectModified(e,t){let r=t?.transactionId??ug();this.events.fire("object:modified",e,{...t,transactionId:r})}enterEditing(e,t={}){let r=this._nodes.find(i=>i===e||i instanceof J&&i.containsDeep(e));if(!r||this._editingNode===e)return;this._editingNode&&this.exitEditing(),this._editingNode=e,this._editingTransient=t.transient===!0,this._editingTextSnapshot=e.raw.text??"",this._editingBitmapSnapshot=typeof e.raw.renderSrc=="string"?{renderSrc:e.raw.renderSrc,renderRect:e.raw.renderRect}:null,this._editingBeforeObject=e.toObject();let o=this._editingTextSnapshot.length;this.editSelection.start=this.editSelection.end=o,t.transient||this.setSelection([r],"update"),this.events.fire("text:editing:entered",e)}exitEditing(){let e=this._editingNode;if(!e)return;let t=this._editingTransient;if(this._editingNode=null,this._editingTransient=!1,this.rebuildIndex(),this.events.fire("text:editing:exited",e),t){this._editingTextSnapshot="",this._editingBeforeObject=null,this._editingBitmapSnapshot=null;return}let r=e.raw.text??"";r!==this._editingTextSnapshot?(this.events.fire("text:editing:committed",e,this._editingTextSnapshot,r),this.fireObjectModified([e],{before:this._editingBeforeObject?[this._editingBeforeObject]:void 0})):this._editingBitmapSnapshot&&(e.raw.renderSrc=this._editingBitmapSnapshot.renderSrc,e.raw.renderRect=this._editingBitmapSnapshot.renderRect,e.markRenderDirty()),this._editingTextSnapshot="",this._editingBeforeObject=null,this._editingBitmapSnapshot=null}updateEditingText(e,t,r){let o=this._editingNode;o&&(o.set({text:e}),this.syncEditSelection(t,r),this.markIndexDirty(),this.events.fire("text:changed",o))}updateEditingSelection(e,t){this._editingNode&&this.syncEditSelection(e,t)}syncEditSelection(e,t){let r=this._editingNode.textLayout.graphemeCodeUnitOffsets;this.editSelection.start=fd(r,e),this.editSelection.end=fd(r,t)}toObjects(){return this._nodes.filter(e=>!e.syntheticOwner).map(e=>e.toObject())}},fd=(n,e)=>{let t=0,r=n.length-1;for(;t<r;){let o=t+r+1>>1;n[o]<=e?t=o:r=o-1}return t};var es=n=>typeof n!="string"||n.length===0?!1:/^data:image\/svg\+xml/i.test(n)?!0:/\.svg(?:[?#]|$)/i.test(n),md=(n,e,t,r=4096)=>{let o=Math.max(n.w,n.h);if(!(o>0)||!(t>=1))return{factor:1,needsRaster:!1};let i=Math.max(e.w/n.w,e.h/n.h);if(!(i>0)||!Number.isFinite(i))return{factor:1,needsRaster:!1};let s=1;for(;s*2*o<=r;)s*=2;let a=1;for(;a<i-1e-9&&a<s;)a*=2;return a===t?{factor:t,needsRaster:!1}:{factor:a,needsRaster:!0}},pd=(n,e)=>{let t=n.naturalWidth||n.width,r=n.naturalHeight||n.height,o=document.createElement("canvas");o.width=Math.max(1,Math.round(t*e)),o.height=Math.max(1,Math.round(r*e));let i=o.getContext("2d");return i&&(i.imageSmoothingEnabled=!0,i.imageSmoothingQuality="high",i.drawImage(n,0,0,o.width,o.height)),o};var ts=(n,e)=>{if(n.children.includes(e))return[n];for(let t of n.children)if(t instanceof J&&!(t instanceof te)&&!(t instanceof le)){let r=ts(t,e);if(r.length)return[...r,n]}return[]},bd=n=>{let e=n.matrix,t=n.ownMatrix,r=ve(e),o=(i,s,a)=>Q(i,s,a,!0);return(i,s)=>{let a=o(r,i,s);return o(t,a.x,a.y)}},xd=n=>{let e=1/0,t=1/0,r=-1/0,o=-1/0;for(let i of n.children){if(!i.visible)continue;let s=i.contentBoxCorners();for(let a of[s.tl,s.tr,s.br,s.bl])a.x<e&&(e=a.x),a.y<t&&(t=a.y),a.x>r&&(r=a.x),a.y>o&&(o=a.y)}return Number.isFinite(e)?{minX:e,minY:t,maxX:r,maxY:o}:null},gd=n=>{let e=xd(n);if(!e)return null;let t=n.matrix;return{tl:Q(t,e.minX,e.minY),tr:Q(t,e.maxX,e.minY),br:Q(t,e.maxX,e.maxY),bl:Q(t,e.minX,e.maxY)}},ns=n=>{let e=[];for(let t=0;t<n.length;t++){let r=n[t],o=xd(r);if(!o)continue;let i=o.maxX-o.minX,s=o.maxY-o.minY,a={x:(o.minX+o.maxX)/2,y:(o.minY+o.maxY)/2},l=new Map;for(let m of r.children){let p=m.aCoords;l.set(m,{x:(p.tl.x+p.br.x)/2,y:(p.tl.y+p.br.y)/2})}let u=Q(r.matrix,a.x,a.y),c=n[t+1]??null,h=c?Q(ve(c.matrix),u.x,u.y):u,d=xe({...r.raw,width:i,height:s},h);r.set({width:i,height:s,left:d.x,top:d.y});let f=ve(r.matrix);for(let m of r.children){let p=l.get(m);if(!p)continue;let b=Q(f,p.x,p.y),x=xe({...m.raw,width:m.dims.x,height:m.dims.y},b);m.set({left:x.x,top:x.y})}e.push(r,...r.children)}return e};var Xl=["tl","tr","bl","br"],vn=new Set(Xl),rs=["tlS","trS","blS","brS"],hg=new Set(rs),ko={tlS:"tl",trS:"tr",blS:"bl",brS:"br"},dg=new Set(["ml","mr","mt","mb"]),rr={ml:"x",mr:"x",mt:"y",mb:"y"},os={ml:"left",mr:"right",mt:"top",mb:"bottom"},or=n=>dg.has(n),is=n=>vn.has(n),_r=n=>hg.has(n);var Mn=8,ir=12,Mt=1.5,yd=24,fg=["lockMovementX","lockMovementY","lockScalingX","lockScalingY","lockSkewingX","lockSkewingY","lockRotation"],at=n=>{let e=n.raw;return fg.some(t=>!!e[t])},us=28,zl=null,mg=()=>{if(zl)return zl;let n=document.createElement("canvas");n.width=us*2,n.height=us*2;let e=n.getContext("2d");if(e){e.scale(2,2);let t=us/2;e.beginPath(),e.arc(t,t,12,0,Math.PI*2),e.fillStyle="#ffffff",e.fill(),e.strokeStyle="#e0e0e0",e.lineWidth=4/3,e.stroke(),typeof Path2D<"u"&&(e.translate(t,t),e.scale(2/3,2/3),e.translate(-12,-12),e.beginPath(),e.strokeStyle="#2c2c2c",e.lineWidth=2,e.lineCap="round",e.lineJoin="round",e.stroke(new Path2D("M5 13a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2v6a2 2 0 0 1 -2 2h-10a2 2 0 0 1 -2 -2v-6z M11 16a1 1 0 1 0 2 0a1 1 0 0 0 -2 0 M8 11v-4a4 4 0 1 1 8 0v4")))}return zl=n,n},hs=28,pg="M706.144 847.264A384.32 384.32 0 0 0 896 515.84c0-118.016-53.504-227.136-143.776-299.616a32 32 0 0 1 40.064-49.92A447.136 447.136 0 0 1 960 515.84c0 166.528-91.424 313.6-228.672 390.784l34.624 81.6-270.464-29.28 168.768-210.368 41.888 98.688zM320.736 182.72A384.288 384.288 0 0 0 128 515.84a383.36 383.36 0 0 0 157.76 310.304 32 32 0 0 1-37.728 51.712A447.36 447.36 0 0 1 64 515.84 448.32 448.32 0 0 1 294.56 123.968L261.664 50.112l268.928 20.032-163.04 217.76-46.816-105.184z",Yl=null,bg=()=>{if(Yl)return Yl;let n=document.createElement("canvas");n.width=hs*2,n.height=hs*2;let e=n.getContext("2d");if(e){e.scale(2,2);let t=hs/2;e.fillStyle="#ffffff",e.beginPath(),e.arc(t,t,10,0,Math.PI*2),e.shadowColor="#333",e.shadowBlur=2,e.fill(),e.shadowColor="",e.shadowBlur=0,typeof Path2D<"u"&&(e.translate(t-8-1.392,t-8-.89),e.scale(.0178,.0178),e.fillStyle="black",e.fill(new Path2D(pg)))}return Yl=n,n};var xg=24,ds=20,vd=16,gg="M607.573333 295.908693h-184.32l92.16-92.16zM515.413333 813.42464l-92.16-92.16h184.32l-92.16 92.16M210.57536 508.586667l92.16-92.16v184.32l-92.16-92.16M820.251307 508.586667l-92.16 92.16v-184.32l92.16 92.16M446.88384 507.405653c0 37.195093 30.153387 67.345067 67.345067 67.345067 37.198507 0 67.351893-30.149973 67.351893-67.345067s-30.153387-67.345067-67.34848-67.345066c-37.195093 0-67.345067 30.149973-67.345067 67.345066z",Ul=null,yg=()=>{if(Ul)return Ul;let n=document.createElement("canvas");n.width=ds*2,n.height=ds*2;let e=n.getContext("2d");if(e){e.scale(2,2);let t=ds/2;e.beginPath(),e.arc(t,t,8,0,Math.PI*2),e.strokeStyle="#2c2c2c",e.lineWidth=2,e.stroke(),e.fillStyle="#ffffff",e.fill(),typeof Path2D<"u"&&(e.translate(t-8,t-8),e.scale(16/1024,16/1024),e.fillStyle="#2c2c2c",e.fill(new Path2D(gg)))}return Ul=n,n},ql=n=>{if(n.selection.length!==1)return null;let e=n.selection[0];if(e instanceof te||e instanceof le)return null;let t=e.typeKey;return ft.has(t)||ot.has(t)||at(e)?null:e},Kl=(n,e,t)=>xs(n,e,t,{x:.5,y:0,offsetX:xg,offsetY:0}),Tn=3,$l=new Map,Sg=n=>{let e=$l.get(n);if(e)return e;let t=document.createElement("canvas"),r=t.getContext("2d"),o=`bold ${14*Tn}px Helvetica, Arial, sans-serif`;if(!r)return t.width=Math.max(1,Math.round((n.length*14*.6+16)*Tn)),t.height=Math.round(30*Tn),$l.set(n,t),t;r.font=o;let i=r.measureText(n).width,s=8*Tn;t.width=Math.max(1,Math.ceil(i)+s*2),t.height=Math.ceil(30*Tn),r.font=o;let a=6*Tn;return r.beginPath(),r.moveTo(a,0),r.lineTo(t.width-a,0),r.arcTo(t.width,0,t.width,a,a),r.lineTo(t.width,t.height-a),r.arcTo(t.width,t.height,t.width-a,t.height,a),r.lineTo(a,t.height),r.arcTo(0,t.height,0,t.height-a,a),r.lineTo(0,a),r.arcTo(0,0,a,0,a),r.closePath(),r.fillStyle="rgba(44, 44, 44, 0.9)",r.fill(),r.fillStyle="#ffffff",r.textAlign="center",r.textBaseline="middle",r.fillText(n,t.width/2,t.height/2),$l.set(n,t),t},vg=(n,e,t)=>{let r=Sg(`${Math.round(e)}°`);return{matrix:[1,0,0,1,n.x,n.y],dims:{x:r.width/Tn/t,y:r.height/Tn/t},color:[1,1,1,1],texture:r}},st=ee("#2f6fed"),Ao=ee("#ffffff"),ss=ee("#2f6fed"),Ql=st,as=(n,e)=>({x:(n.x+e.x)/2,y:(n.y+e.y)/2}),Re=(n,e,t,r)=>{let o=(n.x+e.x)/2,i=(n.y+e.y)/2,s=Math.hypot(e.x-n.x,e.y-n.y),a=Math.atan2(e.y-n.y,e.x-n.x),l=Math.cos(a),u=Math.sin(a);return{matrix:[l,u,-u,l,o,i],dims:{x:s,y:t},color:r}},En=(n,e,t,r)=>{let o=r*Math.PI/180,i=Math.cos(o),s=Math.sin(o);return{matrix:[i,s,-s,i,n.x,n.y],dims:{x:e,y:e},color:t}},wg=n=>{let e=n.angle*Math.PI/180,t=Math.cos(e),r=Math.sin(e),o=n.width/2,i=n.height/2,s=(a,l)=>({x:n.center.x+t*a-r*l,y:n.center.y+r*a+t*l});return{tl:s(-o,-i),tr:s(o,-i),br:s(o,i),bl:s(-o,i)}},et=n=>{let e=n.selection;if(e.length===0)return null;if(e.length===1){let a=e[0];return{quad:a.aCoords,angle:a.raw.angle??0}}let t=n.selectionFrame;if(t)return{quad:wg(t),angle:t.angle};let r=1/0,o=1/0,i=-1/0,s=-1/0;for(let a of e){let l=a.bounds;r=Math.min(r,l.left),o=Math.min(o,l.top),i=Math.max(i,l.right),s=Math.max(s,l.bottom)}return{quad:{tl:{x:r,y:o},tr:{x:i,y:o},br:{x:i,y:s},bl:{x:r,y:s}},angle:0}},Fr=(n,e,t=1,r)=>{let o=as(n.tl,n.tr),i=as(n.tr,n.br),s=as(n.bl,n.br),a=as(n.tl,n.bl),l=Og(n,e,t),u=[{id:"tl",x:n.tl.x,y:n.tl.y},{id:"tr",x:n.tr.x,y:n.tr.y},{id:"br",x:n.br.x,y:n.br.y},{id:"bl",x:n.bl.x,y:n.bl.y},{id:"mt",x:o.x,y:o.y},{id:"mr",x:i.x,y:i.y},{id:"mb",x:s.x,y:s.y},{id:"ml",x:a.x,y:a.y},{id:"mtr",x:l.x,y:l.y}],c=r?Rg(r,t):[];return c.length?[...c,...u]:u},Tg=32,Eg=.25,ms=14,wd=n=>n<=0?0:Math.min(Tg,n*Eg),Td=(n,e)=>{if(e<=0)return 0;let t=Math.max(0,Math.min(e,n)),r=wd(e);return r<=0||e<=r?t:r+t/e*(e-r)},Zl=(n,e)=>{if(e<=0)return 0;let t=Math.max(0,Math.min(e,n)),r=wd(e);return r<=0||e<=r?t:t<=r?0:(t-r)/(e-r)*e},ps=n=>!!n&&n.typeKey===L.FABRICRECT,Cg=new Set([L.QRCODE,L.BARCODE,L.ECHART,L.FABRIC_ECHART]),No=n=>{if(!n)return!1;let e=se(n.raw);return!Cg.has(e)&&(e===L.IMAGE||e===L.SVGIMAGE||e===L.CROPIMAGE)},Ed=n=>{let e=Math.max(Math.abs(n.raw.scaleX??1)||1,1e-4),t=Math.max(Math.abs(n.raw.scaleY??1)||1,1e-4);return Math.min(n.dims.x*e,n.dims.y*t)/2},Mg=(n,e)=>{let t=n.aCoords,r=Math.hypot(t.tr.x-t.tl.x,t.tr.y-t.tl.y)*e,o=Math.hypot(t.bl.x-t.tl.x,t.bl.y-t.tl.y)*e;return r>Dr&&o>Dr},Rg=(n,e)=>Mg(n,e)?ps(n)?Pg(n,e):No(n)?kg(n,e):[]:[],Pg=(n,e)=>{let t=n.raw,r=Math.max(Math.abs(t.scaleX??1)||1,1e-4),o=Math.max(Math.abs(t.scaleY??1)||1,1e-4),i=n.dims.x/2,s=n.dims.y/2,a=i*r,l=s*o,u=Math.min(a,l),c=Math.max(0,Math.min(u,t.radius??0)),h=Td(c,u),d=Math.max(0,(ms-h*e)/e),f=Math.max(0,(ms-h*e)/e),m=h+Math.min(d,Math.max(0,a-h)),p=h+Math.min(f,Math.max(0,l-h)),b=n.matrix;return rs.map(x=>{let g=ko[x],y=g==="tl"||g==="bl",v=g==="tl"||g==="tr",S=(y?-a+m:a-m)/r,w=(v?-l+p:l-p)/o;return{id:x,x:b[0]*S+b[2]*w+b[4],y:b[1]*S+b[3]*w+b[5]}})},kg=(n,e)=>{let t=n.raw,r=n.dims.x/2,o=n.dims.y/2,i=Math.min(r,o),s=Math.max(0,Math.min(i,Math.max(t.rx??0,t.ry??0))),a=Td(s,i),l=Math.max(Math.abs(t.scaleX??1)||1,1e-4),u=Math.max(Math.abs(t.scaleY??1)||1,1e-4),c=l*e,h=u*e,d=Math.min(Math.max(0,(ms-a*c)/c),Math.max(0,r-a)),f=Math.min(Math.max(0,(ms-a*h)/h),Math.max(0,o-a)),m=n.matrix;return rs.map(p=>{let b=ko[p],x=b==="tl"||b==="bl",g=b==="tl"||b==="tr",y=x?-r+a+d:r-a-d,v=g?-o+a+f:o-a-f;return{id:p,x:m[0]*y+m[2]*v+m[4],y:m[1]*y+m[3]*v+m[5]}})},fs=12,ls=null,Ag=()=>{if(ls)return ls;let n=document.createElement("canvas");n.width=fs*2,n.height=fs*2;let e=n.getContext("2d");if(e){e.scale(2,2);let t=fs/2,r=Mn/2;e.beginPath(),e.arc(t,t,r+Mt,0,Math.PI*2),e.fillStyle=`rgb(${st[0]*255},${st[1]*255},${st[2]*255})`,e.fill(),e.beginPath(),e.arc(t,t,r,0,Math.PI*2),e.fillStyle=`rgb(${Ao[0]*255},${Ao[1]*255},${Ao[2]*255})`,e.fill()}return ls=n,ls},Cd=16,wn=4,Sd={tlr:{x:-.5,y:-.5,offsetX:-wn,offsetY:-wn},trr:{x:.5,y:-.5,offsetX:wn,offsetY:-wn},brr:{x:.5,y:.5,offsetX:wn,offsetY:wn},blr:{x:-.5,y:.5,offsetX:-wn,offsetY:wn}},Jl={tlr:0,trr:90,brr:180,blr:270},Dr=50,ec=(n,e)=>({width:Math.hypot(n.tr.x-n.tl.x,n.tr.y-n.tl.y)*e,height:Math.hypot(n.bl.x-n.tl.x,n.bl.y-n.tl.y)*e}),Ng=(n,e)=>{let{width:t,height:r}=ec(n,e);return t>Dr&&r>Dr},Lg=new Set(["mr","br","mtr"]),Ig=new Set(["mr","br"]),_g=new Set(["mr","br","mtr"]),Dg=new Set(["ml","mr","tl","tr","bl","br","tlS","trS","blS","brS"]),Fg=new Set(["mt","mb","tl","tr","bl","br","mtr","tlS","trS","blS","brS"]),Md=(n,e,t)=>{let r=e<=Dr,o=t<=Dr;return!r&&!o?!0:r&&o?Lg.has(n):!(r&&Dg.has(n)&&!Ig.has(n)||o&&Fg.has(n)&&!_g.has(n))},Rd=n=>n instanceof le||n instanceof te||ot.has(n.typeKey),Lo=(n,e,t,r,o)=>{let i=Fr(e,t,r,o),s=n.selection.length===1?n.selection[0]:null;if(!s||Rd(s))return i;let a=ft.has(s.typeKey),l=ec(e,r);return i.filter(u=>a&&(u.id==="ml"||u.id==="mr")||Md(u.id,l.width,l.height))},tc=(n,e)=>{let t=n.aCoords,r=n.worldAngle,o=Fr(t,r,e);if(Rd(n))return o;let i=ft.has(n.typeKey),s=ec(t,e);return o.filter(a=>i&&(a.id==="ml"||a.id==="mr")||Md(a.id,s.width,s.height))},Pd=(n,e,t)=>Ng(n,t)?Object.keys(Sd).map(r=>{let o=xs(n,e,t,Sd[r]);return{id:r,x:o.x,y:o.y}}):[],bs=n=>{let e=n*Math.PI/180,t=Math.sin(e),r=Math.cos(e);if(Math.abs(t)>=Math.abs(r)){let i=Math.sign(t);return{x:i/2,y:0,offsetX:i*yd,offsetY:0}}let o=Math.sign(r);return{x:0,y:o/2,offsetX:0,offsetY:o*yd}},xs=(n,e,t,r)=>{let o=(n.tl.x+n.br.x)/2,i=(n.tl.y+n.br.y)/2,s=Math.hypot(n.tr.x-n.tl.x,n.tr.y-n.tl.y),a=Math.hypot(n.bl.x-n.tl.x,n.bl.y-n.tl.y),l=r.x*s+r.offsetX/t,u=r.y*a+r.offsetY/t,c=e*Math.PI/180,h=Math.cos(c),d=Math.sin(c);return{x:o+l*h-u*d,y:i+l*d+u*h}},Og=(n,e,t)=>xs(n,e,t,bs(e)),Cn=(n,e)=>{let t=Mt/e;return[Re(n.tl,n.tr,t,st),Re(n.tr,n.br,t,st),Re(n.br,n.bl,t,st),Re(n.bl,n.tl,t,st)]},Bg=3,cs=(n,e,t,r,o)=>{let i=e.x-n.x,s=e.y-n.y,a=Math.hypot(i,s);if(a<=0)return[];let l=i/a,u=s/a,c=Bg/o,h=[];for(let d=0;d<a;d+=c*2){let f=Math.min(d+c,a);h.push(Re({x:n.x+l*d,y:n.y+u*d},{x:n.x+l*f,y:n.y+u*f},t,r))}return h},gs=(n,e)=>{let t=Mt/e;return[...cs(n.tl,n.tr,t,st,e),...cs(n.tr,n.br,t,st,e),...cs(n.br,n.bl,t,st,e),...cs(n.bl,n.tl,t,st,e)]},Wg=(n,e,t,r)=>{let o=Mt/r,i=Mn/r;for(let s of e)s.id==="mtr"?n.push({...En(s,hs/r,[1,1,1,1],t),texture:bg()}):_r(s.id)?n.push({...En(s,fs/r,[1,1,1,1],t),texture:Ag()}):(n.push(En(s,i,st,t)),n.push(En(s,i-2*o,Ao,t)))},jl=(n,e,t,r,o,i)=>{if(i?.spec){let s=e.find(l=>l.id==="mtr"),a=xs(t,r,o,i.spec);s.x=a.x,s.y=a.y}Wg(n,e,r,o),i&&n.push(vg(i.center,r,o))},kd=(n,e,t=null,r=!1)=>{if(n.selection.length===1&&Ze(n.selection[0]))return[];let o=et(n);if(!o)return[];let{quad:i,angle:s}=o,a=[],l=n.activeGroupChild,u=l&&n.groupEditing&&n.selection[0]instanceof J&&!(n.selection[0]instanceof te)&&!(n.selection[0]instanceof le)?n.selection[0]:null,h=(u?gd(u):null)??i;if(l)a.push(...Cn(l.aCoords,e)),a.push(...gs(h,e));else{if(n.selection.length>=2)for(let d of n.selection)a.push(...Cn(d.aCoords,e));a.push(...Cn(i,e))}if(n.selection.length===1&&at(n.selection[0]))return a.push({...En(i.br,us/e,[1,1,1,1],s),texture:mg()}),a;if(jl(a,Lo(n,h,s,e,Io(n)),h,s,e,t?.onChild?null:t),l&&n.groupEditing&&jl(a,tc(l,e),l.aCoords,l.worldAngle,e,t?.onChild?t:null),r&&ql(n)){let d=Kl(h,s,e);a.push({...En(d,ds/e,[1,1,1,1],0),texture:yg()})}return a},Io=n=>{if(n.selection.length!==1)return null;let e=n.selection[0];return ps(e)||No(e)?e:null},Ad=(n,e)=>{let t=Mt/e,r={x:n.left,y:n.top},o={x:n.right,y:n.top},i={x:n.right,y:n.bottom},s={x:n.left,y:n.bottom};return[Re(r,o,t,ss),Re(o,i,t,ss),Re(i,s,t,ss),Re(s,r,t,ss)]},_o=n=>{let e=n.editingMask;if(!e)return[];let t=e.aCoords;return Fr(t,e.worldAngle).filter(o=>or(o.id)?!n.maskEdgeOnOuterBorder(e,os[o.id]):!1)},Nd=(n,e,t=null)=>{let r=n.editingMask;if(!r)return[];let o=r.worldAngle,i=Cn(r.aCoords,e),s=Mt/e,a=Mn/e;for(let u of _o(n))i.push(En(u,a,st,o)),i.push(En(u,a-2*s,Ao,o));let l=n.raw.angle??0;return i.push(...gs(n.aCoords,e)),jl(i,Fr(n.aCoords,l),n.aCoords,l,e,t),i},Hg=2.5,Vl=(n,e,t)=>{let r=e.aCoords,o=t==="mr"?{p1:r.tr,p2:r.br}:{p1:r.bl,p2:r.br},i=n.layoutParams,s=t==="mr"?i.hGap:i.vGap;if(s>0){let a=(o.p1.x+o.p2.x)/2,l=(o.p1.y+o.p2.y)/2,u=(r.tl.x+r.br.x)/2,c=(r.tl.y+r.br.y)/2,h=a-u,d=l-c,f=Math.hypot(h,d)||1,m=s/2*(t==="mr"?n.worldScale.x:n.worldScale.y);return{mask:e,handle:t,p1:{x:o.p1.x+h/f*m,y:o.p1.y+d/f*m},p2:{x:o.p2.x+h/f*m,y:o.p2.y+d/f*m}}}return{mask:e,handle:t,p1:o.p1,p2:o.p2}},nc=n=>{let e=[];for(let i of n.maskChildren)i.visible&&(n.maskEdgeOnOuterBorder(i,"right")||e.push(Vl(n,i,"mr")),n.maskEdgeOnOuterBorder(i,"bottom")||e.push(Vl(n,i,"mb")));let t=n.layoutParams,r=Math.max(t.hGap,t.vGap)+1,o=[];for(let i of e){let s=o.find(a=>{let l=a.p2.x-a.p1.x,u=a.p2.y-a.p1.y,c=Math.hypot(l,u)||1,h=l/c,d=u/c;if(Math.abs((i.p2.x-i.p1.x)*d-(i.p2.y-i.p1.y)*h)/Math.max(1e-9,Math.hypot(i.p2.x-i.p1.x,i.p2.y-i.p1.y))>1e-6||Math.abs((i.p1.x-a.p1.x)*d-(i.p1.y-a.p1.y)*h)>.5)return!1;let m=(i.p1.x-a.p1.x)*h+(i.p1.y-a.p1.y)*d,p=(i.p2.x-a.p1.x)*h+(i.p2.y-a.p1.y)*d,b=Math.min(m,p),x=Math.max(m,p);return b<=c+r&&x>=-r});if(s){let a=s.p2.x-s.p1.x,l=s.p2.y-s.p1.y,u=Math.hypot(a,l)||1,c=a/u,h=l/u,d=[0,u,(i.p1.x-s.p1.x)*c+(i.p1.y-s.p1.y)*h,(i.p2.x-s.p1.x)*c+(i.p2.y-s.p1.y)*h],f=Math.min(...d),m=Math.max(...d);s.p1={x:s.p1.x+c*f,y:s.p1.y+h*f},s.p2={x:s.p1.x+c*(m-f),y:s.p1.y+h*(m-f)}}else o.push({...i})}return o},Ld=(n,e,t)=>nc(n).find(o=>o.mask===e&&o.handle===t)??Vl(n,e,t),Id=(n,e)=>[Re(n.p1,n.p2,Hg/e,Ql)],Gg=ee("#3c7eff"),Xg=2,zg=(n,e,t)=>{let r=e.x-n.x,o=e.y-n.y,i=Math.hypot(r,o)||1,s=-o/i,a=r/i,l={x:(n.x+e.x)/2,y:(n.y+e.y)/2};return(l.x+s-t.x)*s+(l.y+a-t.y)*a>=0?{x:s,y:a}:{x:-s,y:-a}},_d=(n,e)=>{let t=n.aCoords,r=[t.tl,t.tr,t.br,t.bl],o={x:(t.tl.x+t.br.x)/2,y:(t.tl.y+t.br.y)/2},i=r.map((u,c)=>zg(u,r[(c+1)%4],o)),s=n.bounds,a=Math.min(Xg,(s.right-s.left)*e,(s.bottom-s.top)*e)/e;if(a<=0)return[];let l=[];for(let u=0;u<4;u++){let c=r[u],h=r[(u+1)%4],d=i[u];l.push(Re({x:c.x-d.x*a/2,y:c.y-d.y*a/2},{x:h.x-d.x*a/2,y:h.y-d.y*a/2},a,Gg))}return l};function Dd(n,e,t,r){let o=n.selection.map(l=>l.id),i=et(n);if(!i||n.editingNode||e)return{ids:o,handles:[]};let s=n.selection.length===1&&n.selection[0]instanceof le?n.selection[0]:null,a=s?.editingMask?[..._o(s).map(l=>{let u=r(l.x,l.y);return{id:l.id,x:u.x,y:u.y}}),...Fr(i.quad,i.angle,t).map(l=>{let u=r(l.x,l.y);return{id:l.id,x:u.x,y:u.y}})]:Lo(n,i.quad,i.angle,t,Io(n)).map(l=>{let u=r(l.x,l.y);return{id:l.id,x:u.x,y:u.y}});return{ids:o,handles:a}}function Fd(n){let e=n.activeGroupChild;if(!e)return null;let t=n.selection[0];return!(t instanceof J)||!t.containsDeep(e)?null:{rootId:t.id,childId:e.id}}function Od(n,e){let t=[],r=o=>{for(let i of o){if(i instanceof J&&r(i.children),!i.imageEl||!es(i.raw.src))continue;let s=i.imageEl.naturalWidth||i.imageEl.width,a=i.imageEl.naturalHeight||i.imageEl.height,l=e(i);t.push({id:i.id,type:i.raw.type,factor:l,rasterWidth:Math.round(s*(l??1)),rasterHeight:Math.round(a*(l??1))})}};return r(n.nodes),t}function Bd(n){return n.nodes.map(e=>({id:e.id,type:e.raw.type,left:e.raw.left??0,top:e.raw.top??0,width:e.raw.width??0,height:e.raw.height??0,scaleX:e.raw.scaleX??1,scaleY:e.raw.scaleY??1,angle:e.raw.angle??0,visible:e.visible,bounds:e.bounds,aCoords:e.aCoords}))}function Wd(n,e){e();let t=performance.now();for(let o=0;o<n;o++)e();let r=(performance.now()-t)/n;return ii("engine.render.avgMeasured",r),r}function Hd(n){let e=n.width,t=n.height,r=document.createElement("canvas");r.width=e,r.height=t;let o=r.getContext("2d");o.drawImage(n,0,0);let i=o.getImageData(0,0,e,t);return{width:e,height:t,data:i.data}}var Yg=2,Le={drag:"drag",scale:"scale",rotate:"rotate",cornerRadius:"cornerRadius",crop:"crop",tableCellEdit:"table-cell-edit",warpImage:"warpvas-image"},Ug=(n,e)=>{let{bus:t,wrap:r,syncSelection:o,settleSnap:i}=e,s=n.events,a=(c,h)=>{let d=h.map(r);o(),t.fire(c,{selected:d,deselected:[],target:d[0]})},l=(c,h)=>{h.syntheticOwner||t.fire(c,{target:r(h)})},u=[s.on("selection:created",c=>a("selection:created",c)),s.on("selection:updated",c=>a("selection:updated",c)),s.on("selection:cleared",()=>{o(),t.fire("selection:cleared",{selected:[],deselected:[]})}),s.on("object:added",c=>l("object:added",c)),s.on("object:removed",c=>l("object:removed",c)),s.on("object:moving",c=>{i?.(),l("object:moving",c)}),s.on("object:scaling",c=>l("object:scaling",c)),s.on("object:rotating",c=>l("object:rotating",c)),s.on("object:cornerRadius",c=>l("object:cornerRadius",c)),s.on("object:modified",(c,h)=>{let d=c.map((x,g)=>x.syntheticOwner?-1:g).filter(x=>x>=0);if(!d.length)return;let f=d.map(x=>r(c[x])),m=h?.before,p=m?.length?d.map(x=>m[x]).filter(x=>!!x):void 0,b=p&&(p.length>1||d.length>1)?{original:{objects:p}}:p?{original:p[0]}:void 0;t.fire("object:modified",{target:f[0],targets:f,transform:b,action:h?.action,transactionId:h?.transactionId,protocolVersion:2})}),s.on("text:editing:entered",c=>l("text:editing:entered",c)),s.on("text:editing:exited",c=>l("text:editing:exited",c)),s.on("text:changed",c=>l("text:changed",c)),s.on("text:editing:committed",(c,h,d)=>{t.fire("text:editing:committed",{target:r(c),before:h,after:d})}),s.on("smartobject:open-requested",c=>l("smartobject:open-requested",c)),s.on("image:replace-requested",c=>l("image:replace-requested",c)),s.on("lock:unlock-requested",c=>l("lock:unlock-requested",c)),s.on("path:active-anchor-change",(c,h)=>{t.fire("path:active-anchor-change",{target:r(c),key:h})}),s.on("group:child-activated",c=>{o(),t.fire("group:child-activated",{target:r(c)})}),s.on("group:child-deactivated",()=>{o(),t.fire("group:child-deactivated")}),s.on("table:cellselection",c=>{t.fire("table:cellselection",{target:r(c)})})];return()=>u.forEach(c=>c())};function Gd(n,e){let t=n.nodes.filter(r=>r.visible&&!Lr.has(String(r.raw.id??""))&&!Ze(r));return n.setSelection(t),e(),t.length}function Xd(n,e){let t=[...n.selection];for(let r of t)n.remove(r);return t.length&&e(),t.length}function zd(n,e,t,r){let o=[...n.selection];if(!o.length)return 0;let i=o.map(s=>s.toObject());for(let s of o)n.setProps(s,{left:(s.raw.left??0)+e,top:(s.raw.top??0)+t},{deferIndexRebuild:!0});return n.commitGeometry(),n.fireObjectModified(o,{action:Le.drag,before:i}),r(),o.length}var vs=20,Ud={ruleSize:vs,backgroundColor:ee("#ffffff"),tickColor:ee("#A1A7AF"),textColor:"#444444",highlightColor:ee("#165dff3b"),fontSize:8,unitName:"px"},$g=.6,ze=3,$d="'Arial Narrow', 'Segoe UI', sans-serif",Yd=[.02,.03,.05,.1,.2,.5,1,2,5],jg=[5e3,2500,1e3,500,200,100,50,20,10],Vg=n=>{let e=0;for(;e<Yd.length&&Yd[e]<n;)e++;return jg[e-1]??1e4},qg=(n,e,t,r)=>{let o=Vg(r),i=Math.floor(n/o)*o,s=n+e,a=[],l=[],u=c=>c>=n-1e-6&&c<=s+1e-6&&(!t||c>=t[0]-1e-6&&c<=t[1]+1e-6);for(let c=i;c<=s+o;c+=o){u(c)&&a.push(c);for(let h=1;h<10;h++){let d=c+o*h/10;if(d>s+o)break;u(d)&&l.push(d)}}return{majors:a,minors:l}},Kg=(n,e)=>{if(!n.length)return[];let t=e?"left":"top",r=e?"width":"height",o=[...n].sort((a,l)=>a[t]-l[t]),i=[],s={start:o[0][t],length:o[0][r]};for(let a=1;a<o.length;a++){let l=o[a];s.start+s.length>=l[t]?s.length=Math.max(s.start+s.length,l[t]+l[r])-s.start:(i.push(s),s={start:l[t],length:l[r]})}return i.push(s),i},rc=new Map,Qg=(n,e=Ud)=>{let t=rc.get(n);if(t)return t;let r=document.createElement("canvas"),o=r.getContext("2d");if(!o)return r.width=Math.max(1,Math.round(n.length*e.fontSize*.6*ze)),r.height=Math.max(1,Math.round(e.fontSize*1.4*ze)),rc.set(n,r),r;let i=`${e.fontSize*ze}px ${$d}`;o.font=i;let s=o.measureText(n);return r.width=Math.max(1,Math.ceil(s.width)+2),r.height=Math.ceil(e.fontSize*ze*1.25),o.font=i,o.textBaseline="top",o.fillStyle=e.textColor,o.fillText(n,1,Math.round(e.fontSize*ze*.15)),rc.set(n,r),r},oc=new Map,ys=10,Ss=4,Zg=n=>{let e=oc.get(n);if(e)return e;let t=ys*ze,r=Ss*ze,o=document.createElement("canvas"),i=o.getContext("2d");if(!i)return o.width=Math.max(1,Math.round((n.length*ys*.6+Ss*2)*ze)),o.height=Math.max(1,Math.round((ys+Ss*2)*ze)),oc.set(n,o),o;let s=`${t}px ${$d}`;i.font=s;let a=i.measureText(n).width,l=3*ze;return o.width=Math.max(1,Math.ceil(a)+r*2),o.height=Math.ceil((ys+Ss*2)*ze),i.font=s,i.beginPath(),i.moveTo(l,0),i.lineTo(o.width-l,0),i.quadraticCurveTo(o.width,0,o.width,l),i.lineTo(o.width,o.height-l),i.quadraticCurveTo(o.width,o.height,o.width-l,o.height),i.lineTo(l,o.height),i.quadraticCurveTo(0,o.height,0,o.height-l),i.lineTo(0,l),i.quadraticCurveTo(0,0,l,0),i.closePath(),i.fillStyle="rgba(22, 93, 255, 0.9)",i.fill(),i.strokeStyle="#fff",i.lineWidth=.5*ze,i.stroke(),i.fillStyle="#fff",i.textBaseline="top",i.fillText(n,r,r),oc.set(n,o),o},jd=n=>{let e={...Ud,...n.style},{vpt:t,cssWidth:r,cssHeight:o}=n,i=t[0],s=n.digitCanvas??(b=>Qg(b,e)),a=[],l=b=>(b-t[4])/i,u=b=>(b-t[5])/i,c=1/i,h=(b,x,g,y,v)=>({matrix:[c,0,0,c,l(b+g/2),u(x+y/2)],dims:{x:g,y},color:v}),d=(b,x,g,y=!1)=>{let v=s(b),S=v.width/ze,w=v.height/ze;return{matrix:y?[0,c,-c,0,l(x+w/2),u(g-S/2)]:[c,0,0,c,l(x+S/2),u(g+w/2)],dims:{x:S,y:w},color:[1,1,1,1],texture:v}},f=e.ruleSize,m=b=>{let x=b?r:o;a.push(b?h(0,0,r,f,e.backgroundColor):h(0,0,f,o,e.backgroundColor));let g=n.workspaceRect,y=g?b?[g.left,g.left+g.width]:[g.top,g.top+g.height]:null,v=b?-t[4]/i:-t[5]/i,S=qg(v,x/i,y,i),w=[e.tickColor[0],e.tickColor[1],e.tickColor[2],e.tickColor[3]*$g],R=P=>(P-v)*i;for(let P of S.majors){let T=Math.round(R(P));a.push(b?h(T,0,1,f,w):h(0,T,f,1,w))}for(let P of S.minors){let T=Math.round(R(P));a.push(b?h(T,f-8,1,8,w):h(f-8,T,8,1,w))}for(let P of S.majors){let T=R(P),C=String(Math.round(P));b?a.push(d(C,T+6,2.5)):a.push(d(C,2.5,T-6,!0))}for(let P of Kg(n.selectionRects,b)){let T=(P.start-v)*i,C=P.length*i;a.push(b?h(T,0,C,f,e.highlightColor):h(0,T,f,C,e.highlightColor))}};m(!0),m(!1),a.push(h(0,0,f,f,e.backgroundColor));let p=s(e.unitName);if(a.push(d(e.unitName,f/2-p.width/ze/2,f/2-p.height/ze/2)),n.referenceLine){let b=Zg(String(Math.round(n.referenceLine.position))),x=b.width/ze,g=b.height/ze,y,v;if(n.referenceLine.axis==="horizontal"){let S=n.referenceLine.position*i+t[5];y=f+5,v=S+g/2,v<0&&(v=2),v+g>o&&(v=o-g-2)}else y=n.referenceLine.position*i+t[4]+x/2,v=f+5,y<0&&(y=2),y+x>r&&(y=r-x-2);a.push({matrix:[c,0,0,c,l(y+x/2),u(v+g/2)],dims:{x,y:g},color:[1,1,1,1],texture:b})}return a};var ws=n=>n*180/Math.PI,ye=n=>n*Math.PI/180,Ts=n=>({x:(n.tl.x+n.br.x)/2,y:(n.tl.y+n.br.y)/2}),Es=n=>({width:Math.hypot(n.tr.x-n.tl.x,n.tr.y-n.tl.y),height:Math.hypot(n.bl.x-n.tl.x,n.bl.y-n.tl.y)}),ic={mr:0,br:45,mb:90,bl:135,ml:180,tl:225,mt:270,tr:315},sc=["ew-resize","nwse-resize","ns-resize","nesw-resize"],Cs=5,Vd=4,Qt=(n,e,t)=>{let r=e/2,o=t/2;switch(n){case"tl":return{u:{x:-r,y:-o},a:{x:r,y:o},axis:"both"};case"tr":return{u:{x:r,y:-o},a:{x:-r,y:o},axis:"both"};case"br":return{u:{x:r,y:o},a:{x:-r,y:-o},axis:"both"};case"bl":return{u:{x:-r,y:o},a:{x:r,y:-o},axis:"both"};case"ml":return{u:{x:-r,y:0},a:{x:r,y:0},axis:"x"};case"mr":return{u:{x:r,y:0},a:{x:-r,y:0},axis:"x"};case"mt":return{u:{x:0,y:-o},a:{x:0,y:o},axis:"y"};case"mb":return{u:{x:0,y:o},a:{x:0,y:-o},axis:"y"};default:return{u:{x:r,y:o},a:{x:-r,y:-o},axis:"both"}}},ac=(n,e,t)=>Q([Math.cos(ye(n)),-Math.sin(ye(n)),Math.sin(ye(n)),Math.cos(ye(n)),0,0],e.x-t.x,e.y-t.y,!0),lc=(n,e)=>{let r=(s,a)=>{let l=s/a;return Math.sign(l||a)*Math.max(.01,Math.abs(l))},o=n.scaleX,i=n.scaleY;if(n.axis==="both"||n.axis==="x"){let s=n.handleLocal.x-n.anchorLocal.x;Math.abs(s)>1e-6&&(o=r(e.x,s))}if(n.axis==="both"||n.axis==="y"){let s=n.handleLocal.y-n.anchorLocal.y;Math.abs(s)>1e-6&&(i=r(e.y,s))}return{scaleX:o,scaleY:i}};var Jg=n=>n instanceof Se&&(n.typeKey===L.TEXTBOX||n.typeKey===L.TEXTIMAGE&&!Vt(n));function cc(n,e){let t=n.dims.x,r=n.dims.y,o=n.raw,i={x:-e*t/2,y:0},s=n.matrix,a=n.children.map(h=>({node:h,centerX:h.center.x,centerY:h.center.y,scaleX:h.raw.scaleX??1,width:h.dims.x,fixedBox:Jg(h)})),l=Q(s,i.x,i.y),u=n.parentMatrix,c=u?Q(ve(u),l.x,l.y):l;return{node:n,sign:e,width:t,height:r,angle:o.angle??0,scaleX:o.scaleX??1,scaleY:o.scaleY??1,anchorScene:l,anchorWrite:c,children:a}}function qd(n,e,t){let r=t/Math.max(e.width,1e-6);n.setProps(e.node,{width:t},{deferIndexRebuild:!0});let o={x:-e.sign*t/2,y:0},i=e.angle*Math.PI/180,s=Math.cos(i),a=Math.sin(i),l=s*(e.scaleX*o.x)-a*(e.scaleY*o.y),u=a*(e.scaleX*o.x)+s*(e.scaleY*o.y),c={x:e.anchorWrite.x-l,y:e.anchorWrite.y-u},h=xe({...e.node.raw,width:t,height:e.height,scaleX:e.scaleX,scaleY:e.scaleY},c);n.setProps(e.node,{left:h.x,top:h.y},{deferIndexRebuild:!0});for(let d of e.children){let f=d.centerX*r;if(d.fixedBox){let m=Math.max(d.width*r,1);n.setProps(d.node,{width:m},{deferIndexRebuild:!0});let p=d.node.dims,b=xe({...d.node.raw,width:p.x,height:p.y},{x:f,y:d.centerY});n.setProps(d.node,{left:b.x,top:b.y},{deferIndexRebuild:!0})}else{let m=d.scaleX*r;n.setProps(d.node,{scaleX:m},{deferIndexRebuild:!0});let p=d.node.dims,b=xe({...d.node.raw,width:p.x,height:p.y,scaleX:m},{x:f,y:d.centerY});n.setProps(d.node,{left:b.x,top:b.y},{deferIndexRebuild:!0})}}}function Kd(n,e,t){if(t.x*e.sign<=0)return;let o=(typeof e.node.raw.strokeWidth=="number"?e.node.raw.strokeWidth:0)/(e.node.raw.strokeUniform?e.scaleX:1),i=Math.max(e.sign*t.x/e.scaleX-o,1);qd(n,e,i)}function ey(n,e,t){if(!(t>0))return;let r=cc(e,1);qd(n,r,t)}function Or(n){return n instanceof J&&!(n instanceof te)&&!(n instanceof le)}function hc(n,e,t){let r=n.raw,o=n.dims.x,i=n.dims.y,{u:s,a,axis:l}=Qt(e,o,i),u=Vt(n),c=(n.typeKey===L.TEXTBOX||n.typeKey===L.TEXTIMAGE&&!u)&&(e==="ml"||e==="mr");c&&(a.x=-s.x,a.y=-i/2);let h=n.matrix,d=Q(h,a.x,a.y),f=n.parentMatrix,m=f?Q(ve(f),d.x,d.y):d,p={node:n,left:r.left??0,top:r.top??0,angle:r.angle??0,scaleX:r.scaleX??1,scaleY:r.scaleY??1,width:o,height:i,anchorLocal:a,handleLocal:s,anchorScene:d,anchorWrite:m,axis:l,bakeWidth:c||void 0,bakeHeight:n.isTextType&&!u&&(e==="mt"||e==="mb")&&n instanceof Se||void 0};if(Or(n)&&(e==="ml"||e==="mr")&&(p.bakeGroup=cc(n,e==="mr"?1:-1)),n.isMaskType&&(!t||t.nodes.includes(n))&&(e==="ml"||e==="mr"?p.bakeMaskWidth=!0:(e==="mt"||e==="mb")&&(p.bakeMaskHeight=!0)),n.isTextType&&!u&&vn.has(e)&&n instanceof Se){let b=Ge(r)==="circle"?typeof r.circleSize=="number"?r.circleSize:40:void 0;p.bakeFont={fontSize0:n.textStyle.fontSize,styles0:r.styles??null,...b!==void 0?{circleSize0:b}:{}}}return p}function ef(n,e,t,r=!1){let o=ac(e.angle,t,e.anchorScene);if(e.bakeFont){ny(n,e,o);return}if(e.bakeWidth){ry(n,e,o);return}if(e.bakeHeight){oy(n,e,o);return}if(e.bakeGroup){Kd(n,e.bakeGroup,o);return}if(e.bakeMaskWidth){Qd(n,e,o,"width");return}if(e.bakeMaskHeight){Qd(n,e,o,"height");return}let i,s;if(e.axis==="both"&&!r){let f=(Math.abs(o.x)+Math.abs(o.y))/Math.max(Math.abs(e.width*e.scaleX)+Math.abs(e.height*e.scaleY),1e-6),m=Math.max(f,.01);i=e.scaleX*m,s=e.scaleY*m}else({scaleX:i,scaleY:s}=lc(e,o));let a=Math.cos(ye(e.angle)),l=Math.sin(ye(e.angle)),u=a*(i*e.anchorLocal.x)-l*(s*e.anchorLocal.y),c=l*(i*e.anchorLocal.x)+a*(s*e.anchorLocal.y),h={x:e.anchorWrite.x-u,y:e.anchorWrite.y-c},d=xe({...e.node.raw,width:e.width,height:e.height,scaleX:i,scaleY:s},h);n.setProps(e.node,{scaleX:i,scaleY:s,left:d.x,top:d.y},{deferIndexRebuild:!0})}function tf(n,e,t){let{quad:r,angle:o}=t,i=Ts(r),{width:s,height:a}=Es(r),{u:l,a:u,axis:c}=Qt(e,s,a),h=Math.cos(ye(o)),d=Math.sin(ye(o));return{members:n.map(f=>({node:f,center:{...f.center},scaleX:f.raw.scaleX??1,scaleY:f.raw.scaleY??1,dims:{...f.dims}})),center:i,angle:o,width:s,height:a,anchorLocal:u,handleLocal:l,anchorScene:{x:i.x+h*u.x-d*u.y,y:i.y+d*u.x+h*u.y},axis:c,handle:e}}function nf(n,e,t,r=!1){let o=ac(e.angle,t,e.anchorScene),i,s;if(e.axis==="both"&&!r){let h=(Math.abs(o.x)+Math.abs(o.y))/Math.max(Math.abs(e.width)+Math.abs(e.height),1e-6);i=s=Math.max(h,.01)}else({scaleX:i,scaleY:s}=lc({...e,scaleX:1,scaleY:1},o));let a=Math.cos(ye(e.angle)),l=Math.sin(ye(e.angle)),u={x:e.anchorScene.x-(a*(i*e.anchorLocal.x)-l*(s*e.anchorLocal.y)),y:e.anchorScene.y-(l*(i*e.anchorLocal.x)+a*(s*e.anchorLocal.y))},c=e.members;n.applyTransform(c.map(h=>h.node),h=>{let d=c.find(x=>x.node===h),f=ty(e,u,i,s,d,a,l),m=d.scaleX*i,p=d.scaleY*s,b=xe({...h.raw,width:d.dims.x,height:d.dims.y,scaleX:m,scaleY:p},f);return{scaleX:m,scaleY:p,left:b.x,top:b.y}},"scaling"),n.setSelectionFrame({center:u,width:e.width*i,height:e.height*s,angle:e.angle})}function ty(n,e,t,r,o,i,s){let a=i*(o.center.x-n.center.x)+s*(o.center.y-n.center.y),l=-s*(o.center.x-n.center.x)+i*(o.center.y-n.center.y);return{x:e.x+i*(t*a)-s*(r*l),y:e.y+s*(t*a)+i*(r*l)}}function rf(n,e,t){let r=Math.atan2(t.y-e.center.y,t.x-e.center.x),o=ws(r-e.startAngle),i=Math.cos(ye(o)),s=Math.sin(ye(o)),a=e.snapshot.members;n.applyTransform(a.map(u=>u.node),u=>{let c=a.find(p=>p.node===u),h=((c.angle0+o)%360+360)%360,d=c.center0.x-e.center.x,f=c.center0.y-e.center.y,m={x:e.center.x+i*d-s*f,y:e.center.y+s*d+i*f};return u.rotateAroundCenter(h,m)},"rotating");let l=((e.frameAngle0+o)%360+360)%360;n.setSelectionFrame({center:{...e.center},width:e.frame.width,height:e.frame.height,angle:l})}var uc=n=>{if(n===null||typeof n!="object")return typeof n=="function"?void 0:n;if(Array.isArray(n))return n.map(uc);let e={};for(let t of Object.keys(n)){let r=uc(n[t]);r!==void 0&&(e[t]=r)}return e};function ny(n,e,t){let r=e.bakeFont,o=e.handleLocal.x-e.anchorLocal.x,i=e.handleLocal.y-e.anchorLocal.y,s=Math.abs(o)+Math.abs(i),a=s>1e-6?(Math.abs(t.x)+Math.abs(t.y))/s:1,l=Math.max(r.fontSize0*a,1);a=l/r.fontSize0;let u={fontSize:l,scaleX:e.scaleX,scaleY:e.scaleY},c=r.circleSize0,h=c!==void 0;h&&(u.circleSize=Math.max(c*a,1)),e.node.typeKey===L.TEXTBOX&&!h&&(u.width=Math.max(e.width*a,1)),h||(u.height=Math.max(e.height*a,1));let d=r.styles0;if(d){let y=uc(d);for(let v of Object.values(y))if(v)for(let[S,w]of Object.entries(v)){let R=w;R&&typeof R.fontSize=="number"&&(v[S]={...R,fontSize:R.fontSize*a})}u.styles=y}let f=Math.cos(ye(e.angle)),m=Math.sin(ye(e.angle)),p=f*(e.scaleX*e.anchorLocal.x*a)-m*(e.scaleY*e.anchorLocal.y*a),b=m*(e.scaleX*e.anchorLocal.x*a)+f*(e.scaleY*e.anchorLocal.y*a),x={x:e.anchorWrite.x-p,y:e.anchorWrite.y-b},g=xe({...e.node.raw,width:e.width*a,height:e.height*a,scaleX:e.scaleX,scaleY:e.scaleY},x);u.left=g.x,u.top=g.y,n.setProps(e.node,u,{deferIndexRebuild:!0})}function ry(n,e,t){let o=Math.sign(e.handleLocal.x);if(t.x*o<=0)return;let s=(typeof e.node.raw.strokeWidth=="number"?e.node.raw.strokeWidth:0)/(e.node.raw.strokeUniform?e.scaleX:1),a=Math.max(o*t.x/e.scaleX-s,1);n.setProps(e.node,{width:a},{deferIndexRebuild:!0});let l=e.node.dims.x,u=e.node.dims.y,c={x:-o*l/2,y:-u/2},h=Math.cos(ye(e.angle)),d=Math.sin(ye(e.angle)),f=h*(e.scaleX*c.x)-d*(e.scaleY*c.y),m=d*(e.scaleX*c.x)+h*(e.scaleY*c.y),p={x:e.anchorWrite.x-f,y:e.anchorWrite.y-m},b=xe({...e.node.raw,width:l,height:u,scaleX:e.scaleX,scaleY:e.scaleY},p);n.setProps(e.node,{left:b.x,top:b.y},{deferIndexRebuild:!0})}function oy(n,e,t){let r=e.node;if(!(r instanceof Se))return;let o=Math.sign(e.handleLocal.y);if(t.y*o<=0)return;let s=(typeof r.raw.strokeWidth=="number"?r.raw.strokeWidth:0)/(r.raw.strokeUniform?e.scaleY:1),a=Math.max(Math.ceil(Math.abs(t.y)/e.scaleY-s),r.textLayout.height,0);n.setProps(r,{height:a},{deferIndexRebuild:!0});let l={x:0,y:-o*a/2},u=Math.cos(ye(e.angle)),c=Math.sin(ye(e.angle)),h=u*(e.scaleX*l.x)-c*(e.scaleY*l.y),d=c*(e.scaleX*l.x)+u*(e.scaleY*l.y),f={x:e.anchorWrite.x-h,y:e.anchorWrite.y-d},m=xe({...r.raw,width:e.width,height:a,scaleX:e.scaleX,scaleY:e.scaleY},f);n.setProps(r,{left:m.x,top:m.y},{deferIndexRebuild:!0})}function Qd(n,e,t,r){let i=e.node,s=i.raw,a=typeof s.strokeWidth=="number"?s.strokeWidth:0;if(r==="width"){let l=Math.sign(e.handleLocal.x);if(t.x*l<=0)return;let u=a/(s.strokeUniform?e.scaleX:1),c=Math.max(l*t.x/e.scaleX-u,1),h=Number(s.width)||e.width,d=Number(s.height)||e.height,f=Jd(i,h,d,c,d);n.setProps(e.node,{width:c,...f??{}},{deferIndexRebuild:!0});let m={x:-l*c/2,y:0},p=Zd(e,m),b=xe({...s,width:c,height:d,scaleX:e.scaleX,scaleY:e.scaleY},p);n.setProps(e.node,{left:b.x,top:b.y},{deferIndexRebuild:!0})}else{let l=Math.sign(e.handleLocal.y);if(t.y*l<=0)return;let u=a/(s.strokeUniform?e.scaleY:1),c=Math.max(l*t.y/e.scaleY-u,1),h=Number(s.width)||e.width,d=Number(s.height)||e.height,f=Jd(i,h,d,h,c);n.setProps(e.node,{height:c,...f??{}},{deferIndexRebuild:!0});let m={x:0,y:-l*c/2},p=Zd(e,m),b=xe({...s,width:h,height:c,scaleX:e.scaleX,scaleY:e.scaleY},p);n.setProps(e.node,{left:b.x,top:b.y},{deferIndexRebuild:!0})}}function Zd(n,e){let t=Math.cos(ye(n.angle)),r=Math.sin(ye(n.angle)),o=t*(n.scaleX*e.x)-r*(n.scaleY*e.y),i=r*(n.scaleX*e.x)+t*(n.scaleY*e.y);return{x:n.anchorWrite.x-o,y:n.anchorWrite.y-i}}function Jd(n,e,t,r,o){let s=n.raw.clipImage;if(!s||typeof s.src!="string")return null;let a=n.clipImageEl,l=a?.naturalWidth||Number(s.width)||0,u=a?.naturalHeight||Number(s.height)||0;if(!l||!u||!e||!t||!r||!o)return null;let c=(m,p)=>Math.max(m/l,p/u),h=Number(s.scaleX)||1,d=c(e,t)?h/c(e,t):1,f=c(r,o)*(d||1);return{clipImage:{...s,scaleX:f,scaleY:f}}}var of=(n,e)=>e.length>=2&&(e.includes(n-1)||e.includes(n));function af(n,e,t){let r=n.raw,o={type:"table-border-drag",node:n,border:e,startMatrix:[...n.matrix],startLocal:n.localPoint(t.x,t.y),startBorderPos:e.position,startWidths:Array.isArray(r.columnWidths)?[...r.columnWidths]:[...n.layout.columnWidths],startHeights:[...n.layout.rowHeights],selectedCols:[...new Set(n.selectedCells.map(i=>i.col))],selectedRows:[...new Set(n.selectedCells.map(i=>i.row))],savedCells:n.selectedCells,savedAnchor:n.cellAnchor,savedRange:n.cellRange};return n.setCellSelection([],null,null),n.borderDragging=!0,o}function lf(n,e){let t=n.node.raw,r=Q(ve(n.startMatrix),e.x,e.y),o={x:r.x-n.startLocal.x,y:r.y-n.startLocal.y};if(n.border.type==="col"){let u=t.minCellWidth??40,c=(Array.isArray(t.columnWidths)?[...t.columnWidths]:[...n.startWidths]).slice(0,n.node.tableView.cols);for(;c.length<n.node.tableView.cols;)c.push(u);if(of(n.border.index,n.selectedCols))for(let h of n.selectedCols)c[h]=Math.max(u,n.startWidths[h]+o.x);else c[n.border.index-1]=Math.max(u,n.startWidths[n.border.index-1]+o.x);po(t,c)}else{let u=n.node.tableView.rows,c=Array.isArray(t.manualRowHeights)?t.manualRowHeights:[],h=[];for(let d=0;d<u;d++)h.push(typeof c[d]=="number"?c[d]:null);if(of(n.border.index,n.selectedRows))for(let d of n.selectedRows)h[d]=Math.max(n.node.getRowMinHeight(d),n.startHeights[d]+o.y);else{let d=n.border.index-1;h[d]=Math.max(n.node.getRowMinHeight(d),n.startHeights[d]+o.y)}t.manualRowHeights=h}n.node.rebuildTable();let i=Mr(n.node.tableView,n.border.type,n.border.index),s=n.border.type==="col"?o.x:o.y,a=n.border.type==="col"?n.node.objectScale.x:n.node.objectScale.y,l=Zh(n.startBorderPos,i,s,a);n.node.hoveredBorder={type:n.border.type,index:n.border.index,position:i+l}}function cf(n,e){let t=Qt(e,n.dims.x,n.dims.y).a;return{type:"table-edge-resize",node:n,handle:e,anchorScene:Q(n.matrix,t.x,t.y)}}function uf(n,e){let t=Qt(e,n.dims.x,n.dims.y).a;return{type:"puzzle-edge-resize",node:n,handle:e,anchorScene:Q(n.matrix,t.x,t.y)}}function Ms(n,e,t,r){for(let o of _o(e)){let i=n(o.x,o.y);if(or(o.id)&&Math.hypot(i.x-t,i.y-r)<=ir)return o.id}return null}function sy(n,e,t,r){let o=r.x-t.x,i=r.y-t.y,s=o*o+i*i,a=s>0?Math.max(0,Math.min(1,((n-t.x)*o+(e-t.y)*i)/s)):0;return Math.hypot(n-(t.x+a*o),e-(t.y+a*i))}function Do(n,e,t,r){for(let o of nc(e)){let i=n(o.p1.x,o.p1.y),s=n(o.p2.x,o.p2.y);if(sy(t,r,i,s)<=ir)return{mask:o.mask,handle:o.handle}}return null}function dc(n,e,t){let r=n.maskChildren.indexOf(e);if(r<0)return null;let o=Wh(n.raw,n.maskChildren.map(s=>s.raw),n.maskChildren.map(s=>s.clipImageEl)),i=Qt(t,e.dims.x,e.dims.y).a;return{type:"puzzle-mask-edge-resize",node:n,maskIdx:r,handle:t,anchorScene:Q(e.matrix,i.x,i.y),state:o.state,pieces:o.pieces,clipSizes:o.clipSizes}}function ay(n,e){n.maskChildren.forEach((t,r)=>{let o=e.masks[r];if(!o)return;let i=t.clipImageRaw,s=o.clip&&i?{...i,scaleX:o.clip.scaleX,scaleY:o.clip.scaleY,clipX:o.clip.clipX,clipY:o.clip.clipY}:null;t.set({left:o.left,top:o.top,width:o.width,height:o.height,...s?{clipImage:s}:{}})})}function hf(n,e){let t=n.node.maskChildren[n.maskIdx];if(!t)return;let r=t.raw,o=t.worldAngle,i=t.worldScale,s=e.x-n.anchorScene.x,a=e.y-n.anchorScene.y;if(o){let u=Math.cos(ye(-o)),c=Math.sin(ye(-o)),h=s;s=u*h-c*a,a=c*h+u*a}let l=os[n.handle];if(l==="left"||l==="right"){let u=(r.strokeWidth??0)/(r.strokeUniform===!0?i.x:1);Oh(n.state,n.maskIdx,Math.abs(s)/i.x-u,l,n.clipSizes)}else{let u=(r.strokeWidth??0)/(r.strokeUniform===!0?i.y:1);Bh(n.state,n.maskIdx,Math.abs(a)/i.y-u,l,n.clipSizes)}ay(n.node,n.state)}function sf(n,e){let t=n.layoutParams,r=n.maskChildren,o={...t,masks:r.map(s=>({left:s.raw.left??0,top:s.raw.top??0,width:s.raw.width??0,height:s.raw.height??0,clip:Wi(s.raw)}))},i=r.map(s=>s.clipImageEl?{w:s.clipImageEl.naturalWidth,h:s.clipImageEl.naturalHeight}:null);Fh(o,e,i)&&(n.set({layoutWidth:o.width,layoutHeight:o.height,hGap:o.hGap,vGap:o.vGap,groupPadding:o.groupPadding,width:o.width,height:o.height}),r.forEach((s,a)=>{let l=o.masks[a],u=s.clipImageRaw,c=l.clip&&u?{...u,scaleX:l.clip.scaleX,scaleY:l.clip.scaleY,clipX:l.clip.clipX,clipY:l.clip.clipY}:null;s.set({left:l.left,top:l.top,width:l.width,height:l.height,...c?{clipImage:c}:{}})}))}function df(n,e,t){let r=e.node.raw,o={x:Math.abs(r.scaleX??1),y:Math.abs(r.scaleY??1)},i=r.angle??0,s=t.x-e.anchorScene.x,a=t.y-e.anchorScene.y;if(i){let m=Math.cos(ye(-i)),p=Math.sin(ye(-i)),b=s;s=m*b-p*a,a=p*b+m*a}let l=e.node.layoutParams;if(rr[e.handle]==="x"){let m=(r.strokeWidth??0)/(r.strokeUniform===!0?o.x:1),p=Math.max(Math.abs(s)/o.x-m,1);sf(e.node,{widthRatio:p/(l.width||1)})}else{let m=(r.strokeWidth??0)/(r.strokeUniform===!0?o.y:1),p=Math.max(Math.abs(a)/o.y-m,1);sf(e.node,{heightRatio:p/(l.height||1)})}let u=Qt(e.handle,e.node.dims.x,e.node.dims.y).a,c=Math.cos(ye(i)),h=Math.sin(ye(i)),d={x:e.anchorScene.x-(c*(o.x*u.x)-h*(o.y*u.y)),y:e.anchorScene.y-(h*(o.x*u.x)+c*(o.y*u.y))},f=xe({...r,width:e.node.dims.x,height:e.node.dims.y},d);n.setProps(e.node,{left:f.x,top:f.y},{deferIndexRebuild:!0})}function ff(n,e,t){let r=e.node.raw,o=e.node.tableView,i=e.node.objectScale,s=e.node.tableAngle,a=t.x-e.anchorScene.x,l=t.y-e.anchorScene.y;if(s){let p=Math.cos(ye(-s)),b=Math.sin(ye(-s)),x=a;a=p*x-b*l,l=b*x+p*l}let u=r.cellStrokeWidth??1;if(rr[e.handle]==="x"){let p=Math.abs(a)/i.x-o.cellSpacing*(o.cols-1)-u,b=e.handle==="ml"?0:o.cols-1,x=o.columnWidths.reduce((g,y,v)=>v===b?g:g+y,0);bo(r,b,p-x)}else{let p=Math.abs(l)/i.y-o.cellSpacing*(o.rows-1)-u,b=e.handle==="mt"?0:o.rows-1,x=o.rowHeights.reduce((g,y,v)=>v===b?g:g+y,0);xo(r,b,p-x)}e.node.rebuildTable();let c=Qt(e.handle,e.node.dims.x,e.node.dims.y).a,h=Math.cos(ye(s)),d=Math.sin(ye(s)),f={x:e.anchorScene.x-(h*(i.x*c.x)-d*(i.y*c.y)),y:e.anchorScene.y-(d*(i.x*c.x)+h*(i.y*c.y))},m=xe({...r,width:e.node.dims.x,height:e.node.dims.y},f);n.setProps(e.node,{left:m.x,top:m.y},{deferIndexRebuild:!0})}function mf(n,e,t){let r=Math.max(0,t.index);if(t.type==="col"){vo(e.raw,r),e.rebuildTable();let o=e.tableView,i=zi(e.cellMap,o.rows,Math.min(r,o.cols-1));e.setCellSelection(i,i[0]??null,Xe(i))}else{So(e.raw,r),e.rebuildTable();let o=e.tableView,i=Yi(e.cellMap,o.cols,Math.min(r,o.rows-1));e.setCellSelection(i,i[0]??null,Xe(i))}n.applyTransform([e],()=>({}),"modified")}var ly=n=>n.kind==="col-strip"?{kind:"col",index:n.col}:{kind:"row",index:n.row},cy=(n,e,t)=>{let r=n.raw,{x:o,y:i}=n.dims;if(!o||!i)return null;let s=Math.max(Math.abs(r.scaleX??1)||1,1e-4),a=Math.max(Math.abs(r.scaleY??1)||1,1e-4),l=n.localPoint(t.x,t.y),u=o/2,c=i/2,h,d;e==="tl"?(h=(l.x+u)*s,d=(l.y+c)*a):e==="tr"?(h=(u-l.x)*s,d=(l.y+c)*a):e==="bl"?(h=(l.x+u)*s,d=(c-l.y)*a):(h=(u-l.x)*s,d=(c-l.y)*a);let f=Ed(n),m=Math.max(0,Math.min(f,Zl(Math.min(h,d),f))),p=r.radius??0;return Math.abs(m-p)<.001?null:m},uy=(n,e,t)=>{let r=n.raw,{x:o,y:i}=n.dims;if(!o||!i)return null;let s=n.localPoint(t.x,t.y),a=o/2,l=i/2,u,c;e==="tl"?(u=s.x+a,c=s.y+l):e==="tr"?(u=a-s.x,c=s.y+l):e==="bl"?(u=s.x+a,c=l-s.y):(u=a-s.x,c=l-s.y);let h=Math.min(a,l),d=Math.max(0,Math.min(h,Zl(Math.min(u,c),h))),f=Math.max(r.rx??0,r.ry??0);if(Math.abs(d-f)<.001)return null;let m={rx:d,ry:d};return d>0&&r.perPixelTargetFind===!1&&(m.perPixelTargetFind=!0),m},fc=(n,e)=>n<vs?"vertical":e<vs?"horizontal":null,Fo=n=>`url("data:image/svg+xml,<svg height='20' width='20' viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg'><g fill='none' transform='rotate(${n} 16 16)'><path fill='white' d='M18.24 5.37C11.41 6.04 5.98 11.46 5.32 18.26L0 18.26L7.8 26L15.61 18.27L10.6 18.27C11.21 14.35 14.31 11.25 18.24 10.64L18.24 15.55L26 7.78L18.24 0L18.24 5.37Z'></path><path fill='black' d='M19.5463 6.61441C12.4063 6.68441 6.61632 12.4444 6.56632 19.5644L3.17632 19.5644L7.80632 24.1444L12.4363 19.5644L9.18632 19.5644C9.24632 13.8844 13.8563 9.28441 19.5463 9.22441L19.5463 12.3844L24.1463 7.78441L19.5463 3.16441L19.5463 6.61441Z'></path></g></svg>") 12 12,auto`,We=n=>{let e=new Map;for(let t of n)e.set(t,t.toObject());return e},Rs=class{host;el;gesture={type:"none"};performed=!1;hoveredTable=null;deferredClickSwitch=null;detach=null;interactive;constructor(e,t,r=!0){this.el=e,this.host=t,this.interactive=r,this.attach()}get active(){return this.gesture.type!=="none"}hitHandle(e,t){let r=et(this.host.document);if(!r||this.host.document.selection.length===1&&at(this.host.document.selection[0]))return null;for(let o of Lo(this.host.document,r.quad,r.angle,this.host.zoom,Io(this.host.document))){let i=this.host.toScreen(o.x,o.y);if(Math.hypot(i.x-e,i.y-t)<=ir)return o.id}return null}hitActiveChildHandle(e,t){let r=this.host.document,o=r.activeGroupChild;if(!o||!r.groupEditing)return null;for(let i of tc(o,this.host.zoom)){let s=this.host.toScreen(i.x,i.y);if(Math.hypot(s.x-e,s.y-t)<=ir)return i.id}return null}hitLockControl(e,t){let r=this.host.document;if(r.selection.length!==1||!at(r.selection[0]))return null;let o=et(r);if(!o)return null;let i=this.host.toScreen(o.quad.br.x,o.quad.br.y);return Math.hypot(i.x-e,i.y-t)<=ir?r.selection[0]:null}hitMoveControl(e,t){if(this.host.mobileControls!==!0||!ql(this.host.document))return!1;let r=et(this.host.document);if(!r)return!1;let o=Kl(r.quad,r.angle,this.host.zoom),i=this.host.toScreen(o.x,o.y);return Math.hypot(i.x-e,i.y-t)<=vd}hitCornerRotateZone(e,t){let r=this.host.document;if(r.selection.length!==1)return null;let o=r.selection[0];if(o instanceof te||at(o))return null;let i=et(r);if(!i)return null;let s=i.angle*Math.PI/180,a=Math.cos(s),l=Math.sin(s),u=Cd/2;for(let c of Pd(i.quad,i.angle,this.host.zoom)){let h=this.host.toScreen(c.x,c.y),d=e-h.x,f=t-h.y,m=d*a+f*l,p=-d*l+f*a;if(Math.abs(m)<=u&&Math.abs(p)<=u)return c.id}return null}freezeRotateHandle(e,t,r=!1){this.host.rotateDrag!==void 0&&(this.host.rotateDrag=r?{spec:bs(e),center:{x:t.x,y:t.y},onChild:!0}:{spec:bs(e),center:{x:t.x,y:t.y}})}hoverCursor(e,t,r){let o=this.host.document;if(this.host.rulerVisible){let p=fc(e,t);if(p)return p==="horizontal"?"ns-resize":"ew-resize"}let i=this.host.cropSession;if(i)return i.hoverCursor(e,t,r);let s=this.host.expandSession;if(s)return s.hoverCursor(e,t,r.x,r.y);let a=this.host.pathSession;if(a)return a.hoverCursor(e,t,r);let l=this.host.warpSession;if(l)return l.hoverCursor(e,t);let u=o.selection.length===1&&o.selection[0]instanceof le?o.selection[0]:null;if(u?.editingMask){let p=Ms((x,g)=>this.host.toScreen(x,g),u,e,t);if(p)return rr[p]==="x"?"ew-resize":"ns-resize";let b=Do((x,g)=>this.host.toScreen(x,g),u,e,t);if(b)return rr[b.handle]==="x"?"ew-resize":"ns-resize"}else if(u){let p=Do((b,x)=>this.host.toScreen(b,x),u,e,t);if(p)return rr[p.handle]==="x"?"ew-resize":"ns-resize"}let c=o.selection.length===1&&o.selection[0]instanceof te?o.selection[0]:null;if(c&&!o.findTarget(r.x,r.y)){let p=c.borderOrIndicatorHit(r.x,r.y,this.host.zoom);if(p?.inCircle)return this.updateTableHover(c,p,!1),"pointer";let b=c.stripHit(r.x,r.y,this.host.zoom);if(b)return this.updateTableHover(c,null,!1,{strip:ly(b)}),"pointer";if(c.dragHandleHit(r.x,r.y,this.host.zoom))return this.updateTableHover(c,null,!1,{dragHandle:!0}),"move"}if(c&&o.findTarget(r.x,r.y)===c&&c.rangeHandleHit(r.x,r.y,this.host.zoom))return this.updateTableHover(c,null,!0,{rangeHandle:!0}),"crosshair";if(this.hitLockControl(e,t))return"pointer";let h=this.hitActiveChildHandle(e,t);if(h==="mtr"){let p=o.activeGroupChild;return Fo(p.worldAngle+225)}if(h){let p=o.activeGroupChild,b=ic[h];if(typeof b=="number"){let x=b+p.worldAngle;return sc[(Math.round(x/45)%4+4)%4]}}if(this.hitMoveControl(e,t))return"move";let d=this.hitHandle(e,t);if(d==="mtr")return Fo((et(o)?.angle??0)+225);if(d&&_r(d))return d==="tlS"||d==="brS"?"nwse-resize":"nesw-resize";if(d){let p=ic[d]+(et(o)?.angle??0);return sc[(Math.round(p/45)%4+4)%4]}let f=this.hitCornerRotateZone(e,t);if(f)return Fo((et(o)?.angle??0)+Jl[f]);let m=o.findTarget(r.x,r.y);if(m&&m===o.editingNode)return"text";if(m instanceof te){let p=m.borderOrIndicatorHit(r.x,r.y,this.host.zoom),b="move";return p?.inCircle?b="pointer":p?.border&&o.selection.includes(m)&&(b=Jh(m.tableAngle,p.border.type)),this.updateTableHover(m,p,!0),b}if(this.updateTableHover(null,null,!1),!this.host.cropSession&&!this.host.expandSession&&!this.host.pathSession&&!this.host.warpSession){let p=o.nodes.find(b=>Ze(b)&&b.visible&&b.raw.visible!==!1&&b.containsPoint(r.x,r.y));if(p)return p.dims.y===0?"ns-resize":"ew-resize"}return m?"move":""}updateTableHover(e,t,r,o={}){if(this.hoveredTable&&this.hoveredTable!==e&&(this.hoveredTable.clearHoverState(),this.hoveredTable=null,this.host.requestRenderAll()),!e)return;let i=e.hoveredBorder,s=e.hoveredIndicator,a=e.indicatorVisible,l=e.hoveredStrip,u=e.hoveredDragHandle,c=e.hoveredRangeHandle;e.hoveredBorder=t&&!t.inCircle?t.border:null,e.hoveredIndicator=t?.inCircle?t.border:null,e.indicatorVisible=r||!!t,e.hoveredStrip=o.strip??null,e.hoveredDragHandle=o.dragHandle??!1,e.hoveredRangeHandle=o.rangeHandle??!1,this.hoveredTable=e;let h=l?.kind!==e.hoveredStrip?.kind||l?.index!==e.hoveredStrip?.index;(i!==e.hoveredBorder||s!==e.hoveredIndicator||a!==e.indicatorVisible||h||u!==e.hoveredDragHandle||c!==e.hoveredRangeHandle)&&this.host.requestRenderAll()}updateHover(e,t,r){let o=this.host.document,i=null,s=null,a=o.nodes.find(d=>d instanceof le&&d.editingMask)??null,l=!!this.host.cropSession||!!this.host.expandSession||!!this.host.pathSession||!!this.host.warpSession||!!a,u=!this.hitHandle(e,t)&&!this.hitMoveControl(e,t);if(!l&&u){let d=o.findTarget(r.x,r.y);if(d instanceof J&&!(d instanceof te)&&!(d instanceof le)){let f=o.activeGroupChild;if(!(f!==null&&o.selection.length===1&&o.selection[0]===d))o.selection.includes(d)||(i=d);else{let p=Ir(d,r.x,r.y,o.selection);i=p&&p!==f?p:null}}else d&&!o.selection.includes(d)&&(i=d)}if(i&&i===o.editingNode&&(i=null),u&&!(a&&Ms((d,f)=>this.host.toScreen(d,f),a,e,t))){let d=o.selection.length===1&&o.selection[0]instanceof le?o.selection[0]:null;if(d){let f=Do((m,p)=>this.host.toScreen(m,p),d,e,t);f&&(s={puzzle:d,mask:f.mask,handle:f.handle})}}let c=o.hovered;o.setHovered(i);let h=o.seamHover;o.setSeamHover(s),(o.hovered!==c||o.seamHover!==h)&&this.host.requestRenderAll()}attach(){if(!this.interactive)return;let e=this.el,t=s=>{if(s.button!==0||this.host.interactionSuspended)return;this.host.document.editingNode&&s.preventDefault();let a=e.getBoundingClientRect(),l=s.clientX-a.left,u=s.clientY-a.top;this.onPointerDown(l,u,s.shiftKey)},r=s=>{if(this.host.interactionSuspended&&this.gesture.type==="none"||this.host.panning)return;let a=e.getBoundingClientRect();this.onPointerMove(s.clientX-a.left,s.clientY-a.top)},o=s=>{if(this.host.interactionSuspended&&this.gesture.type==="none")return;let a=e.getBoundingClientRect();this.onPointerUp(s.clientX-a.left,s.clientY-a.top)},i=()=>{let s=this.host.document,a=s.hovered;s.setHovered(null),this.el.style.cursor="",s.hovered!==a&&this.host.requestRenderAll()};e.addEventListener("pointerdown",t),window.addEventListener("pointermove",r),window.addEventListener("pointerup",o),e.addEventListener("pointerleave",i),this.detach=()=>{e.removeEventListener("pointerdown",t),window.removeEventListener("pointermove",r),window.removeEventListener("pointerup",o),e.removeEventListener("pointerleave",i)}}onPointerDown(e,t,r){let o=this.host.document,i=this.host.toScene(e,t);this.performed=!1,this.deferredClickSwitch=null,o.setHovered(null);let s=this.host.cropSession;if(s){let S=s.hitHandle(e,t);S?this.gesture={type:"crop-handle",handle:S}:s.hitRect(i.x,i.y)?this.gesture={type:"crop-move",last:i}:s.exitByOutsideClick(),this.host.requestRenderAll();return}let a=this.host.expandSession;if(a){let S=a.hitHandle(e,t);S?this.gesture={type:"expand-handle",handle:S}:a.hitRect(i.x,i.y)?this.gesture={type:"expand-image-drag",last:i}:a.exitByOutsideClick(),this.host.requestRenderAll();return}let l=this.host.pathSession;if(l){let S=l.hitAnchor(e,t);if(S&&l.startAnchorDrag(S)){this.gesture={type:"path-anchor-drag",key:S},this.host.requestRenderAll();return}let w=l.findInsertCandidate(i.x,i.y);if(w){let R=l.insertAnchor(w);if(R){this.gesture={type:"path-anchor-drag",key:R},this.host.requestRenderAll();return}}if(l.hitBody(i.x,i.y)){this.gesture={type:"path-body-drag",last:i},this.host.requestRenderAll();return}l.exitByOutsideClick()}let u=this.host.warpSession;if(u){let S=u.hitAnchor(e,t);S&&(this.gesture={type:"warp-anchor-drag",anchor:S},u.applyAnchorDrag(S,i)),this.host.requestRenderAll();return}if(this.host.rulerVisible){let S=fc(e,t);if(S){let w=cd(S,S==="horizontal"?i.y:i.x),R=Ct(w);R&&(o.add(R),o.clearSelection(),this.gesture={type:"reference-line",node:R,axis:S,creating:!0,historyBefore:We([R])}),this.host.requestRenderAll();return}}let c=o.editingNode,h=!1;if(c){if(c.containsPoint(i.x,i.y)){let S=c.localPoint(i.x,i.y),w=c.cursorIndexAt(S.x,S.y);this.host.setEditingSelection(w,w),this.gesture={type:"text-select",anchorIdx:w};return}o.exitEditing(),h=!0}if(!h&&o.selection.length===1&&o.selection[0]instanceof te){let S=o.selection[0],w=o.findTarget(i.x,i.y)?null:S.borderOrIndicatorHit(i.x,i.y,this.host.zoom);if(w?.inCircle){this.gesture={type:"table-indicator-click",node:S,border:w.border};return}let R=o.findTarget(i.x,i.y)?null:S.stripHit(i.x,i.y,this.host.zoom);if(R){this.gesture=R.kind==="col-strip"?{type:"table-strip-click",node:S,kind:"col",index:R.col}:{type:"table-strip-click",node:S,kind:"row",index:R.row};return}}if(!h&&o.selection.length===1&&o.selection[0]instanceof te){let S=o.selection[0];if(o.findTarget(i.x,i.y)===S&&S.rangeHandleHit(i.x,i.y,this.host.zoom)){let w=S.expandedCellRange;if(w){this.gesture={type:"table-range-drag",node:S,anchor:{row:w.r1,col:w.c1}};return}}}let d=h?null:o.nodes.find(S=>S instanceof le&&S.editingMask)??null,f=!!d;if(f&&d){let S=Ms((w,R)=>this.host.toScreen(w,R),d,e,t);if(S&&d.editingMask){let w=dc(d,d.editingMask,S);w&&(this.gesture=w);return}}{let S=o.selection.length===1&&o.selection[0]instanceof le?o.selection[0]:null;if(S){let w=Do((R,P)=>this.host.toScreen(R,P),S,e,t);if(w){let R=dc(S,w.mask,w.handle);R&&(this.gesture=R);return}}}let m=h?null:this.hitLockControl(e,t);if(m){this.host.document.events.fire("lock:unlock-requested",m);return}let p=!f||d!=null&&o.selection.length===1&&o.selection[0]===d;if(p&&!h){let S=this.hitActiveChildHandle(e,t),w=o.activeGroupChild,R=o.selection.length===1?o.selection[0]:null;if(S&&w&&R instanceof J&&!(R instanceof te)&&!(R instanceof le)){let P=ts(R,w);if(P.length){let T=[w,...P,...P.flatMap(C=>C.children)];if(S==="mtr"){let C=w.aCoords,E={x:(C.tl.x+C.br.x)/2,y:(C.tl.y+C.br.y)/2};this.freezeRotateHandle(w.raw.angle??0,E,!0),this.gesture={type:"rotate",center:E,startAngle:Math.atan2(i.y-E.y,i.x-E.x),snapshot:{node:w,angle0:w.raw.angle??0},cursorOffset:225,childTransform:{child:w,shells:P,pivotLocal:{...w.center}},historyBefore:We(T)}}else if(!_r(S))this.gesture={type:"scale",handle:S,snapshot:hc(w,S,o),freeScale:r&&vn.has(S),childTransform:{child:w,shells:P},historyBefore:We(T)};else return;this.host.requestRenderAll();return}}}if(!h&&p&&this.hitMoveControl(e,t)){let S=o.selection[0],w=new Map;w.set(S,{left:S.raw.left??0,top:S.raw.top??0}),this.gesture={type:"move",start:i,startCss:{x:e,y:t},snapshot:w,historyBefore:We([S])},this.host.requestRenderAll();return}let b=h||!p?null:this.hitHandle(e,t);if(b){if(o.selection.length===1){let S=o.selection[0];if(b==="mtr"){let w=S.center;this.freezeRotateHandle(S.raw.angle??0,w),this.gesture={type:"rotate",center:w,startAngle:Math.atan2(i.y-w.y,i.x-w.x),snapshot:{node:S,angle0:S.raw.angle??0},cursorOffset:225,historyBefore:We([S])}}else if(_r(b)&&(ps(S)||No(S)))this.gesture={type:"cornerRadius",node:S,corner:ko[b],model:No(S)?"image":"rect",historyBefore:We([S])};else if(S instanceof te&&or(b)){let w=cf(S,b);w.historyBefore=We([S]),this.gesture=w}else if(S instanceof le&&or(b)){let w=uf(S,b);w.historyBefore=We([S]),this.gesture=w}else this.gesture={type:"scale",handle:b,snapshot:hc(S,b,o),freeScale:r&&vn.has(b),historyBefore:We([S])}}else{let S=et(o),w=o.selection.filter(R=>!at(R));if(b==="mtr"){let R=Ts(S.quad);w.length&&this.freezeRotateHandle(S.angle,R),this.gesture={type:"multi-rotate",center:R,startAngle:Math.atan2(i.y-R.y,i.x-R.x),frameAngle0:S.angle,frame:Es(S.quad),snapshot:{members:w.map(P=>({node:P,angle0:P.raw.angle??0,center0:{...P.center}}))},historyBefore:We(o.selection)}}else this.gesture={type:"multi-scale",snapshot:tf(w,b,S),freeScale:r&&vn.has(b),historyBefore:We(o.selection)}}return}let x=h||!p?null:this.hitCornerRotateZone(e,t);if(x){let S=o.selection[0],w=S.center;this.host.rotateDrag!==void 0&&(this.host.rotateDrag={spec:null,center:{x:w.x,y:w.y}}),this.gesture={type:"rotate",center:w,startAngle:Math.atan2(i.y-w.y,i.x-w.x),snapshot:{node:S,angle0:S.raw.angle??0},cursorOffset:Jl[x],historyBefore:We([S])};return}if(!h&&o.selection.length===1&&o.selection[0]instanceof te){let S=o.selection[0];if(!o.findTarget(i.x,i.y)&&S.dragHandleHit(i.x,i.y,this.host.zoom)){let w=new Map;for(let R of o.selection)w.set(R,{left:R.raw.left??0,top:R.raw.top??0});this.gesture={type:"move",start:i,startCss:{x:e,y:t},snapshot:w,historyBefore:We(o.selection)},this.host.requestRenderAll();return}}if(!r){let S=o.nodes.find(w=>Ze(w)&&w.visible&&w.raw.visible!==!1&&w.containsPoint(i.x,i.y));if(S){o.setSelection([S],"create"),this.gesture={type:"reference-line",node:S,axis:S.dims.y===0?"horizontal":"vertical",creating:!1,historyBefore:We([S])},this.host.requestRenderAll();return}}let g=o.findTarget(i.x,i.y),y=g instanceof te?g:null;if(y){let S=y.borderOrIndicatorHit(i.x,i.y,this.host.zoom);if(S?.inCircle){this.gesture={type:"table-indicator-click",node:y,border:S.border};return}let w=y.borderHit(i.x,i.y);if(w&&o.selection.includes(y)){let P=af(y,w,i);P.historyBefore=We([y]),this.gesture=P;return}let R=y.cellHit(i.x,i.y);if(R){o.selection.includes(y)?!r&&o.selection.length>1&&(this.deferredClickSwitch=y):o.setSelection([y],"create");let P=new Map;for(let T of o.selection)at(T)||P.set(T,{left:T.raw.left??0,top:T.raw.top??0});this.gesture={type:"table-cell-click",node:y,start:i,anchorCell:R,shift:r,moveSnapshot:P,frame0:o.selection.length>1&&o.selectionFrame?{...o.selectionFrame}:void 0,historyBefore:We(o.selection)},this.host.requestRenderAll();return}}if(f&&d){if(g===d){let S=d.maskChildren.find(w=>w.visible&&w.containsPoint(i.x,i.y));if(S){S!==d.editingMask&&(d.editingMask=S),o.setActiveGroupChild(S);let w=new Map;for(let R of o.selection)at(R)||w.set(R,{left:R.raw.left??0,top:R.raw.top??0});this.gesture={type:"move",start:i,startCss:{x:e,y:t},snapshot:w,frame0:void 0,historyBefore:We(o.selection)}}else d.exitMaskEditing(),o.setActiveGroupChild(null);this.host.requestRenderAll();return}d.exitMaskEditing(),this.host.requestRenderAll()}let v=g instanceof te?null:g;if(v){let S=o.selection.includes(v),w=o.groupEditing;if(r){let R=(o.selection.includes(v)?o.selection.filter(P=>P!==v):[...o.selection,v]).filter(P=>!at(P));o.setSelection(R,"update")}else o.selection.includes(v)?o.selection.length>1&&(this.deferredClickSwitch=v):o.setSelection([v],"create");if(v instanceof J&&!(v instanceof te)&&!(v instanceof le))o.setActiveGroupChild(Ir(v,i.x,i.y,o.selection));else if(v instanceof le&&S&&o.selection.length===1){let R=v.maskChildren.find(P=>P.visible&&P.containsPoint(i.x,i.y))??null;o.setActiveGroupChild(R),R?v.editingMask=R:v.exitMaskEditing()}else o.activeGroupChild&&o.setActiveGroupChild(null);if(o.selection.includes(v))if(at(v)&&S&&o.selection.length===1&&o.selection[0]===v)this.gesture={type:"marquee",anchor:i,additive:r,hold:!0};else{let R=o.activeGroupChild,P=w&&R&&v instanceof J&&!(v instanceof te)&&!(v instanceof le)&&o.selection.length===1&&o.selection[0]===v?ts(v,R):[],T=P.length&&R?{child:R,toLocal:bd(R),shells:P}:null;if(T){let C=new Map;C.set(T.child,{left:T.child.raw.left??0,top:T.child.raw.top??0});let E=[T.child,...T.shells,...T.shells.flatMap(M=>M.children)];this.gesture={type:"move",start:i,startCss:{x:e,y:t},snapshot:C,childMove:T,historyBefore:We(E)}}else{let C=new Map;for(let E of o.selection)at(E)||C.set(E,{left:E.raw.left??0,top:E.raw.top??0});this.gesture={type:"move",start:i,startCss:{x:e,y:t},snapshot:C,frame0:o.selection.length>1&&o.selectionFrame?{...o.selectionFrame}:void 0,historyBefore:We(o.selection)}}}this.host.requestRenderAll();return}this.gesture={type:"marquee",anchor:i,additive:r},r||o.clearSelection(),this.host.requestRenderAll()}onPointerMove(e,t){let r=this.host.document,o=this.host.toScene(e,t),i=this.gesture;if(i.type==="none"){this.el.style.cursor=this.hoverCursor(e,t,o),this.updateHover(e,t,o);return}if(i.type==="move"){if(i.snapshot.size){if(!this.performed&&Math.hypot(e-i.startCss.x,t-i.startCss.y)<=Vd)return;this.performed=!0;let s=o.x-i.start.x,a=o.y-i.start.y;if(i.childMove){let l=i.childMove.toLocal(s,a);r.applyTransform([...i.snapshot.keys()],u=>{let c=i.snapshot.get(u);return{left:c.left+l.x,top:c.top+l.y}},"moving")}else r.applyTransform([...i.snapshot.keys()],l=>{let u=i.snapshot.get(l);return{left:u.left+s,top:u.top+a}},"moving"),i.frame0&&r.setSelectionFrame({...i.frame0,center:{x:i.frame0.center.x+s,y:i.frame0.center.y+a}})}}else if(i.type==="reference-line"){this.performed=!0;let s=i.axis==="horizontal";r.applyTransform([i.node],()=>({visible:!0,...s?{top:o.y}:{left:o.x}}),"moving"),this.host.referenceLineDrag!==void 0&&(this.host.referenceLineDrag={axis:i.axis,position:s?o.y:o.x})}else if(i.type==="scale")this.performed=!0,ef(r,i.snapshot,o,i.freeScale),r.applyTransform([i.snapshot.node],()=>({}),"scaling"),!i.snapshot.bakeFont&&!i.snapshot.bakeWidth&&!i.snapshot.bakeHeight&&!i.snapshot.bakeGroup&&this.host.registerScalingSnap?.(i.snapshot.node,i.handle);else if(i.type==="cornerRadius")if(i.model==="image"){let s=uy(i.node,i.corner,o);s&&(this.performed=!0,r.applyTransform([i.node],()=>s,"cornerRadius"))}else{let s=cy(i.node,i.corner,o);s!==null&&(this.performed=!0,r.applyTransform([i.node],()=>({radius:s}),"cornerRadius"))}else if(i.type==="multi-scale")i.snapshot.members.length&&(this.performed=!0,nf(r,i.snapshot,o,i.freeScale),this.host.registerScalingSnap?.(r.selection[0],i.snapshot.handle));else if(i.type==="rotate"){this.performed=!0;let s=Math.atan2(o.y-i.center.y,o.x-i.center.x),a=i.snapshot.angle0+ws(s-i.startAngle);a=(a%360+360)%360;let l=i.childTransform?.pivotLocal??i.center;r.applyTransform([i.snapshot.node],u=>u.rotateAroundCenter(a,l),"rotating"),this.el.style.cursor=Fo((i.snapshot.node.raw.angle??0)+(i.cursorOffset??225))}else if(i.type==="multi-rotate")i.snapshot.members.length&&(this.performed=!0,rf(r,i,o),this.el.style.cursor=Fo((r.selectionFrame?.angle??0)+225));else if(i.type==="marquee"){if(i.hold&&Math.hypot(o.x-i.anchor.x,o.y-i.anchor.y)<=Cs)return;this.host.marquee={left:i.anchor.x,top:i.anchor.y,right:o.x,bottom:o.y};let s=r.objectsIntersectingRect(i.anchor.x,i.anchor.y,o.x,o.y).filter(l=>!at(l)),a=(i.additive?[...new Set([...r.selection,...s])]:s).filter(l=>!at(l));r.setSelection(a,"update")}else if(i.type==="text-select"){let s=r.editingNode;if(s){let a=s.localPoint(o.x,o.y),l=s.cursorIndexAt(a.x,a.y);this.host.setEditingSelection(Math.min(i.anchorIdx,l),Math.max(i.anchorIdx,l))}}else if(i.type==="table-border-drag")this.performed=!0,lf(i,o);else if(i.type==="table-edge-resize")this.performed=!0,ff(r,i,o);else if(i.type==="puzzle-edge-resize")this.performed=!0,df(r,i,o);else if(i.type==="puzzle-mask-edge-resize")this.performed=!0,hf(i,o);else if(i.type==="crop-handle")this.performed=!0,this.host.cropSession?.applyHandle(i.handle,o);else if(i.type==="expand-handle")this.performed=!0,this.host.expandSession?.applyHandle(i.handle,o);else if(i.type==="expand-image-drag")this.performed=!0,this.host.expandSession?.moveImageBy({x:o.x-i.last.x,y:o.y-i.last.y}),i.last=o;else if(i.type==="crop-move")this.performed=!0,this.host.cropSession?.moveImageBy({x:o.x-i.last.x,y:o.y-i.last.y}),i.last=o;else if(i.type==="path-anchor-drag")this.performed=!0,this.host.pathSession?.applyAnchorDrag(i.key,o);else if(i.type==="path-body-drag")this.performed=!0,this.host.pathSession?.moveBodyBy({x:o.x-i.last.x,y:o.y-i.last.y}),i.last=o;else if(i.type==="warp-anchor-drag")this.performed=!0,this.host.warpSession?.applyAnchorDrag(i.anchor,o);else if(i.type==="table-range-drag"){let s=i.node.cellHit(o.x,o.y);if(s){let a=xn(i.node.cellMap,i.anchor,s);i.node.setCellSelection(a,i.anchor,Xe(a))}}else if(i.type==="table-cell-click"){if(i.shift){let s=i.node.cellHit(o.x,o.y),a=i.node.cellAnchor??i.anchorCell;if(s&&a){let l=xn(i.node.cellMap,a,s);i.node.setCellSelection(l,a,Xe(l))}}else if(Math.hypot(o.x-i.start.x,o.y-i.start.y)>Cs)return this.deferredClickSwitch=null,this.gesture={type:"move",start:i.start,startCss:{x:e,y:t},snapshot:i.moveSnapshot,frame0:i.frame0,historyBefore:i.historyBefore},this.onPointerMove(e,t)}this.host.requestRenderAll()}onPointerUp(e,t){let r=this.host.document,o=this.gesture;if(this.gesture={type:"none"},this.host.marquee=null,this.host.rotateDrag!==void 0&&(this.host.rotateDrag=null),o.type!=="none"){if(this.host.settleMoveSnap?.(),this.host.finishSnapGesture?.(),o.type==="move"){if(this.performed)if(o.childMove){let i=ns(o.childMove.shells),s=[...new Set([o.childMove.child,...i])];r.applyTransform(s,()=>({}),"modified",{action:Le.drag,before:o.historyBefore})}else r.applyTransform([...o.snapshot.keys()],()=>({}),"modified",{action:Le.drag,before:o.historyBefore});else if(this.deferredClickSwitch){let i=this.deferredClickSwitch;r.selection.length>1&&r.selection.includes(i)&&r.setSelection([i],"create")}}else if(o.type==="reference-line")this.host.referenceLineDrag!==void 0&&(this.host.referenceLineDrag=null),(this.host.rulerVisible?fc(e,t):null)===o.axis||o.creating&&!this.performed?(r.remove(o.node),r.fireObjectModified([o.node],{action:Le.drag,before:o.historyBefore?[o.historyBefore.get(o.node)].filter(s=>!!s):void 0})):this.performed&&r.applyTransform([o.node],()=>({selectable:!1}),"modified",{action:Le.drag,before:o.historyBefore});else if(o.type==="scale"||o.type==="rotate"){if(this.performed)if(o.childTransform){let i=ns(o.childTransform.shells),s=[...new Set([o.childTransform.child,...i])];r.applyTransform(s,()=>({}),"modified",{action:o.type,before:o.historyBefore})}else r.applyTransform([o.snapshot.node],()=>({}),"modified",{action:o.type,before:o.historyBefore})}else if(o.type==="cornerRadius")this.performed&&r.applyTransform([o.node],()=>({}),"modified",{action:Le.cornerRadius,before:o.historyBefore});else if(o.type==="multi-scale"||o.type==="multi-rotate")this.performed&&r.applyTransform(o.snapshot.members.map(i=>i.node),()=>({}),"modified",{action:o.type==="multi-scale"?Le.scale:Le.rotate,before:o.historyBefore});else if(o.type==="marquee")r.commitGeometry();else if(o.type==="path-anchor-drag"||o.type==="path-body-drag")this.performed&&this.host.pathSession?.commit();else if(o.type==="warp-anchor-drag")this.performed&&this.host.warpSession?.endDrag();else if(o.type==="table-border-drag")o.node.setCellSelection(o.savedCells,o.savedAnchor,o.savedRange),o.node.hoveredBorder=null,o.node.borderDragging=!1,this.performed&&(o.node.rebuildTable(),r.applyTransform([o.node],()=>({}),"modified",{action:Le.scale,before:o.historyBefore}));else if(o.type==="table-edge-resize")this.performed&&r.applyTransform([o.node],()=>({}),"modified",{action:Le.scale,before:o.historyBefore});else if(o.type==="puzzle-edge-resize")this.performed&&r.applyTransform([o.node],()=>({}),"modified",{action:Le.scale,before:o.historyBefore});else if(o.type==="puzzle-mask-edge-resize")this.performed&&r.applyTransform([o.node],()=>({}),"modified",{action:Le.scale,before:o.historyBefore});else if(o.type==="table-indicator-click"){let i=this.host.toScene(e,t),s=o.node.borderOrIndicatorHit(i.x,i.y,this.host.zoom);s?.inCircle&&mf(r,o.node,s.border)}else if(o.type==="table-strip-click"){let i=this.host.toScene(e,t),s=o.node.stripHit(i.x,i.y,this.host.zoom);s?.kind==="col-strip"?o.node.setColumnSelection(s.col):s?.kind==="row-strip"&&o.node.setRowSelection(s.row)}else if(o.type==="table-cell-click"){let i=this.host.toScene(e,t);if(Math.hypot(i.x-o.start.x,i.y-o.start.y)<=Cs)if(this.deferredClickSwitch===o.node)r.selection.length>1&&r.selection.includes(o.node)&&r.setSelection([o.node],"create");else{let s=o.node.cellHit(i.x,i.y);if(s)if(o.shift){let a=o.node.cellAnchor??o.anchorCell??s,l=xn(o.node.cellMap,a,s);o.node.setCellSelection(l,a,Xe(l))}else o.node.setCellSelection([s],s,{r1:s.row,r2:s.row,c1:s.col,c2:s.col})}}this.deferredClickSwitch=null,this.host.requestRenderAll()}}dispose(){this.detach?.(),this.detach=null}};var hy=new Set(["qrcode","barcode"]),dy=n=>{let e=n.raw.type;return typeof e=="string"&&hy.has(e.toLowerCase())},Ps=class{host;onDblClick;disposed=!1;interactive;constructor(e,t=!0){this.host=e,this.interactive=t,this.onDblClick=r=>{if(e.interactionSuspended)return;let o=e.canvasEl.getBoundingClientRect(),i=e.toScene(r.clientX-o.left,r.clientY-o.top),s=e.document.findTarget(i.x,i.y);if(s instanceof J&&!(s instanceof te)&&!(s instanceof le)){let a=Ir(s,i.x,i.y,e.document.selection);a&&!(a instanceof te)&&!(a instanceof le)&&(s=a)}this.dispatch(s,i.x,i.y)},this.interactive&&e.canvasEl.addEventListener("dblclick",this.onDblClick)}dispatch(e,t,r){if(e instanceof te){let o=e.cellHit(t,r);o&&this.host.startCellEditing(e,o.row,o.col);return}if(e instanceof le){let o=e.maskChildren.find(i=>i.visible&&i.containsPoint(t,r));o&&(this.host.document.selection.includes(e)||this.host.document.setSelection([e],"create"),e.editingMask=o,this.host.document.setActiveGroupChild(o),this.host.requestRenderAll());return}if(e instanceof Se){this.host.enterTextEditingAtClick(e,t,r);return}if(e?.isImageType&&!dy(e)){let o=this.host.document.events;e.raw.smartObject?o.fire("smartobject:open-requested",e):o.fire("image:replace-requested",e)}}dispose(){this.disposed||(this.disposed=!0,this.host.canvasEl.removeEventListener("dblclick",this.onDblClick))}};var ks=class n{host;onKeydown;offDocEvents;disposed=!1;constructor(e){this.host=e,this.onKeydown=i=>this.handleKey(i),window.addEventListener("keydown",this.onKeydown);let t=e.document.events,r=()=>this.pruneCellState(),o=[t.on("selection:created",r),t.on("selection:updated",r),t.on("selection:cleared",r)];this.offDocEvents=()=>o.forEach(i=>i())}dispose(){this.disposed||(this.disposed=!0,window.removeEventListener("keydown",this.onKeydown),this.offDocEvents())}pruneCellState(){let e=this.host.document;for(let t of e.nodes)t instanceof te&&!e.selection.includes(t)&&t.clearCellInteractionState()}get activeTable(){let e=this.host.document;if(e.editingNode||e.selection.length!==1)return null;let t=e.selection[0];return t instanceof te?t:null}static isTypingTarget(e){let t=e.target;return t instanceof HTMLElement?t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.tagName==="SELECT"||t.isContentEditable:!1}handleKey(e){let t=this.activeTable;if(!t||n.isTypingTarget(e))return;let r=e.ctrlKey||e.metaKey,o=e.key;if(o==="Escape"){t.hasCellSelection&&(t.clearCellSelection(),this.host.requestRenderAll(),e.preventDefault());return}if(r&&!e.shiftKey&&o.toLowerCase()==="a"){let i=t.tableView,s=Eo(t.cellMap,i.rows,i.cols);t.setCellSelection(s,s[0]??null,Xe(s)),this.host.requestRenderAll(),e.preventDefault();return}if(r&&o.toLowerCase()==="m"){e.shiftKey?this.unmergeFirst(t):this.mergeSelection(t);return}if(t.hasCellSelection&&!r&&!e.altKey&&o.length===1&&!/^(Enter|Escape|Tab|Delete|Backspace)$/.test(o)){let i=t.selectedCells[0];i&&(e.preventDefault(),this.host.startCellEditing(t,i.row,i.col,{initialText:o}));return}if(o==="Enter"&&t.hasCellSelection){let i=t.selectedCells[0];i&&(e.preventDefault(),this.host.startCellEditing(t,i.row,i.col));return}if(o==="Delete"||o==="Backspace"){this.deleteSelectionText(t);return}if(t.hasCellSelection&&(o==="ArrowUp"||o==="ArrowDown"||o==="ArrowLeft"||o==="ArrowRight")){let s={ArrowUp:{row:-1,col:0},ArrowDown:{row:1,col:0},ArrowLeft:{row:0,col:-1},ArrowRight:{row:0,col:1}}[o];this.navigate(t,s.row,s.col),e.preventDefault();return}o==="Tab"&&(this.navigate(t,0,e.shiftKey?-1:1,!0),e.preventDefault())}navigate(e,t,r,o=!1){let i=e.tableView,s=e.cellAnchor??e.selectedCells[0]??{row:0,col:0},a=s.row+t,l=s.col+r;o?(l>=i.cols?(l=0,a++):l<0&&(l=i.cols-1,a--),a>=i.rows?a=0:a<0&&(a=i.rows-1)):(a=Math.max(0,Math.min(i.rows-1,a)),l=Math.max(0,Math.min(i.cols-1,l)));let u=lt(e.cellMap,a,l);e.setCellSelection([u],u,{r1:u.row,r2:u.row,c1:u.col,c2:u.col}),this.host.requestRenderAll()}commit(e){e.rebuildTable(),this.host.document.applyTransform([e],()=>({}),"modified"),this.host.requestRenderAll()}mergeSelection(e){if(e.selectedCells.length<2)return;let t=Xe(e.selectedCells);if(!t)return;let r=go(e.raw,t.r1,t.c1,t.r2,t.c2),o={row:r.r1,col:r.c1};e.setCellSelection([o],o,r),this.commit(e)}unmergeFirst(e){for(let t of e.selectedCells)if(yo(e.raw,t.row,t.col)){let r={row:t.row,col:t.col};e.setCellSelection([r],r,{r1:t.row,r2:t.row,c1:t.col,c2:t.col}),this.commit(e);return}}deleteSelectionText(e){let t=e.cellMap,r=!1;for(let o of e.selectedCells){let i=we(t,o.row,o.col);i&&!i.isMerged&&i.text&&(i.text="",r=!0)}r&&this.commit(e)}};var mc=(n,e,t)=>Math.max(e,Math.min(t,n)),As={min:.05,max:5},Br=60,fy=n=>{let e=n.workspaceRect();if(e.width<=0||e.height<=0)return null;let t=n.viewportTransform,r=e.left*t[0]+t[4],o=e.top*t[0]+t[5],i=r+e.width*t[0],s=o+e.height*t[0],{width:a,height:l}=n.viewSize;return r<-1||o<-1||i>a+1||s>l+1?null:{x:(r+i)/2,y:(o+s)/2}},pf=(n,e)=>{n.preventDefault();let{deltaX:t,deltaY:r,deltaMode:o,ctrlKey:i,metaKey:s,altKey:a,shiftKey:l}=n,u=o===1?16:o===2&&e.viewSize.height||1,c=o===0?t:t*u,h=o===0?r:r*u;if(i||s||a){let A=Math.abs(h)<10?h*2:h/3,O=e.viewportTransform[0],F=mc(O*(1-A/200),As.min,As.max),G=fy(e)??e.cursorPoint(n);e.zoomAt(G.x,G.y,F/O);return}let d=o===0&&Math.abs(t)<=10&&Math.abs(r)<=10,f=mc(e.viewportTransform[0],.1,As.max),m=Math.max(1,f)*1.25,p=20*m,b=A=>mc(A,-60,60),x=0,g=0;if(l||Math.abs(c)>Math.abs(h)){let A=c!==0?c:h;A!==0&&(x=d?-b(A)*m:A>0?-p:p)}else h!==0&&(g=d?-b(h)*m:h>0?-p:p);if(x===0&&g===0)return;let v=e.viewportTransform,{width:S,height:w}=e.viewSize,R=e.workspaceRect(),P=R.width*f,T=R.height*f,C=v[4],E=v[5],M=Br-P;C+x<M&&(x=M-C),C+x>S-Br&&(x=S-Br-C);let k=Br-T;E+g<k&&(g=k-E),E+g>w-Br&&(g=w-Br-E),!(x===0&&g===0)&&e.pan(x,g)};var Ns=class{constructor(e,t,r,o=!0){this.host=e;this.snapGuide=t;this.sources=r;this.interactive=o;let i=e.canvasEl;this.pointer=new Rs(i,e,this.interactive),this.tableInteraction=new ks(e);let s=p=>{if(p.key!=="Escape")return;let b=e.document.selection;b.length===1&&b[0]instanceof le&&b[0].editingMask&&(b[0].exitMaskEditing(),e.document.setActiveGroupChild(null),e.requestRenderAll())};this.interactive&&window.addEventListener("keydown",s);let a=e.document.events,l=()=>e.requestRenderAll(),u=[a.on("selection:created",l),a.on("selection:updated",l),a.on("selection:cleared",l),a.on("object:modified",l),a.on("object:moving",p=>this.snapGuide.registerMove(p)),a.on("object:removed",p=>{p instanceof ie&&this.sources.releaseAnimatedNode(p)})];this.offDocEvents=()=>u.forEach(p=>p()),this.dblClick=new Ps(e,this.interactive);let c=p=>{pf(p,e)},h=p=>{if(p.button===1){p.preventDefault(),e.panning=!0,this.lastPanPointer={x:p.clientX,y:p.clientY},i.style.cursor="grab";try{i.setPointerCapture(p.pointerId)}catch{}}},d=p=>{if(!e.panning||!this.lastPanPointer)return;let b=p.clientX-this.lastPanPointer.x,x=p.clientY-this.lastPanPointer.y;this.lastPanPointer={x:p.clientX,y:p.clientY},e.pan(b,x),i.style.cursor="grab"},f=p=>{e.panning&&(e.panning=!1,this.lastPanPointer=null,i.hasPointerCapture(p.pointerId)&&i.releasePointerCapture(p.pointerId),i.style.cursor="default")},m=p=>e.handleFontsLoaded(p.fontfaces??[]);document.fonts?.addEventListener?.("loadingdone",m),this.interactive&&(i.addEventListener("wheel",c,{passive:!1}),i.addEventListener("pointerdown",h),window.addEventListener("pointermove",d),window.addEventListener("pointerup",f)),this.detachListeners=()=>{document.fonts?.removeEventListener?.("loadingdone",m),i.removeEventListener("wheel",c),i.removeEventListener("pointerdown",h),window.removeEventListener("pointermove",d),window.removeEventListener("pointerup",f),window.removeEventListener("keydown",s)}}host;snapGuide;sources;interactive;pointer;tableInteraction;dblClick;detachListeners=null;offDocEvents=null;lastPanPointer=null;get pointerActive(){return this.pointer.active}dispose(){this.detachListeners?.(),this.offDocEvents?.(),this.pointer.dispose(),this.dblClick.dispose(),this.tableInteraction.dispose()}};var my={left:-.5,top:-.5,center:0,bottom:.5,right:.5},Ft=n=>typeof n=="string"?my[n]??0:n-.5,pc=(n,e,t)=>{let r=Math.cos(e),o=Math.sin(e),i=n.x-t.x,s=n.y-t.y;return{x:t.x+r*i-o*s,y:t.y+o*i+r*s}},bc=n=>({x:n.width*n.scaleX,y:n.height*n.scaleY}),Ls=bc,Oo=n=>n*Math.PI/180,xc=(n,e,t,r,o,i=!1,s=!1)=>{let a=i?-1:1,l=s?-1:1,u={x:n.x+e*r.x*a,y:n.y+t*r.y*l};return o&&(u=pc(u,Oo(o),n)),u},gc=(n,e,t,r,o,i=!1,s=!1)=>{let a=i?-1:1,l=s?-1:1,u={x:n.x-e*r.x*a,y:n.y-t*r.y*l};return o&&(u=pc(u,Oo(o),n)),u},_s=(n,e,t,r,o)=>xc(n,Ft(e),Ft(t),r,o),Bo=(n,e,t,r,o,i)=>gc({x:n,y:e},Ft(t),Ft(r),o,i),Wr=(n,e,t=0,r=0)=>{let o=Bo(n.left,n.top,n.originX,n.originY,Ls(n),n.angle),i=e;n.angle&&(i=pc(i,-Oo(n.angle),o));let s=Ls(n),a=n.flipX?-1:1,l=n.flipY?-1:1;return{x:(i.x-o.x)*a-t*s.x,y:(i.y-o.y)*l-r*s.y}},Hr=(n,e,t,r)=>{let o=Ls(n),i=Bo(n.left,n.top,n.originX,n.originY,o,n.angle),s=xc(i,e,t,o,n.angle,n.flipX,n.flipY),a=r.scaleX??n.scaleX,l=r.scaleY??n.scaleY,u={x:r.width*a,y:r.height*l},c=gc(s,e,t,u,n.angle,n.flipX,n.flipY),h=_s(c,n.originX,n.originY,u,n.angle);return{...n,...r,scaleX:a,scaleY:l,left:h.x,top:h.y}},py=(n,e)=>{let{width:t,cropX:r}=n,i=Wr(n,e).x/n.scaleX- -(t/2),s=t-i;if(r+i<0&&(i=-r,s=t+r),s<8){let a=Math.min(8,r+t);i=t-a,s=a}return Hr(n,.5,0,{width:s,height:n.height,cropX:r+i,cropY:n.cropY})};var by=(n,e)=>{let{width:t,cropX:r}=n,o=Wr(n,e),i=t-(t/2-o.x/n.scaleX);return i+r>n.naturalWidth&&(i=n.naturalWidth-r),i<8&&(i=Math.min(8,n.naturalWidth-r)),Hr(n,-.5,0,{width:i,height:n.height,cropX:r,cropY:n.cropY})};var xy=(n,e)=>{let{height:t,cropY:r}=n,i=Wr(n,e).y/n.scaleY- -(t/2),s=t-i;if(r+i<0&&(i=-r,s=t+r),s<8){let a=Math.min(8,r+t);i=t-a,s=a}return Hr(n,0,.5,{width:n.width,height:s,cropX:n.cropX,cropY:r+i})};var gy=(n,e)=>{let{height:t,cropY:r}=n,o=Wr(n,e),i=t-(t/2-o.y/n.scaleY);return i+r>n.naturalHeight&&(i=n.naturalHeight-r),i<8&&(i=Math.min(8,n.naturalHeight-r)),Hr(n,0,-.5,{width:n.width,height:i,cropX:n.cropX,cropY:r})};var Is=(n,e,t)=>e==="left"||e==="right"?e==="left"?py(n,t):by(n,t):e==="top"?xy(n,t):gy(n,t),bf=(n,e,t)=>{let r=e==="tl"||e==="bl"?"left":"right",o=e==="tl"||e==="tr"?"top":"bottom",i=Is(n,r,t);return Is(i,o,t)};var xf=(n,e,t,r)=>{if(!(r>0)||!Number.isFinite(r))return null;let o=Wr(n,t),i=e==="tl"||e==="bl",s=e==="tl"||e==="tr",a=i?n.cropX+n.width:n.naturalWidth-n.cropX,l=s?n.cropY+n.height:n.naturalHeight-n.cropY,u=Math.min(a,l/r);if(!(u>0))return null;let c=Math.min(u,Math.max(8,8/r)),h=n.width/2+(i?-1:1)*o.x/n.scaleX,d=n.height/2+(s?-1:1)*o.y/n.scaleY,f=Math.max(c,Math.min(u,h,d/r)),m=f*r;return Hr(n,i?.5:-.5,s?.5:-.5,{width:f,height:m,cropX:i?n.cropX+n.width-f:n.cropX,cropY:s?n.cropY+n.height-m:n.cropY})},gf=(n,e,t=!1)=>{if(!(e>0)||!Number.isFinite(e))return null;let r=t?n.scaleY*e/n.scaleX:e,o=n.width*n.scaleX/e,i=n.height*n.scaleY/r,s=n.cropX+(n.width-o)/2,a=n.cropY+(n.height-i)/2;return o<Math.min(8,n.naturalWidth)||i<Math.min(8,n.naturalHeight)||s<0||a<0||s+o>n.naturalWidth||a+i>n.naturalHeight?null:Hr(n,0,0,{width:o,height:i,cropX:s,cropY:a,scaleX:e,scaleY:r})},yy=(n,e,t,r,o)=>{let i=Math.abs(n.x/t),s=Math.abs(n.y/e);return Math.min(i,s)},yf=(n,e,t)=>{if(n.width<=0||n.height<=0)return null;let{naturalWidth:r,naturalHeight:o}=n,i=r-n.width-n.cropX,s=o-n.height-n.cropY,a,l;e==="br"?(a=-n.cropX/n.width,l=-n.cropY/n.height):e==="tl"?(a=1+i/n.width,l=1+s/n.height):e==="tr"?(a=-n.cropX/n.width,l=1+s/n.height):(a=1+i/n.width,l=-n.cropY/n.height);let u=Wr(n,t,Ft(a),Ft(l)),c=Math.min(n.width*n.scaleX/Math.min(8,r),n.height*n.scaleY/Math.min(8,o)),h=Math.min(yy(u,o,r,n.flipX,n.flipY),c);if(!(h>0)||!Number.isFinite(h))return null;let d=h/n.scaleX,f=h/n.scaleY,m=n.width/d,p=n.height/f,b=i/d,x=s/f,g,y;if(e==="br"){if(g=n.cropX/d,y=n.cropY/f,g+m>r||y+p>o)return null}else if(e==="tl"){if(g=r-m-b,y=o-p-x,m+b>r||p+x>o)return null}else if(e==="tr"){if(g=n.cropX/d,y=o-p-x,g+m>r||x+p>o)return null}else if(g=r-m-b,y=n.cropY/f,m+b>r||p+y>o)return null;let v,S;e==="br"?(v=-g/m,S=-y/p):e==="tl"?(v=1+b/m,S=1+x/p):e==="tr"?(v=-g/m,S=1+x/p):(v=1+b/m,S=-y/p);let w=Ls(n),R=Bo(n.left,n.top,n.originX,n.originY,w,n.angle),P=xc(R,Ft(a),Ft(l),w,n.angle,n.flipX,n.flipY),T={x:m*h,y:p*h},C=gc(P,Ft(v),Ft(S),T,n.angle,n.flipX,n.flipY),E=_s(C,n.originX,n.originY,T,n.angle);return{...n,width:m,height:p,cropX:g,cropY:y,scaleX:h,scaleY:h,left:E.x,top:E.y}},Sf=(n,e)=>{let t=Math.cos(Oo(n.angle)),r=Math.sin(Oo(n.angle)),o=n.flipX?-1:1,i=n.flipY?-1:1,s=t*e.x+r*e.y,a=-r*e.x+t*e.y,l=-s/(o*n.scaleX),u=-a/(i*n.scaleY),c=n.cropX+l,h=n.cropY+u;return c<0?c=0:c+n.width>n.naturalWidth&&(c=n.naturalWidth-n.width),h<0?h=0:h+n.height>n.naturalHeight&&(h=n.naturalHeight-n.height),{cropX:c,cropY:h}},vf=(n,e)=>{let t=n.naturalHeight/n.naturalWidth,r,o;t>e?(r=n.naturalWidth,o=n.naturalWidth*e):(o=n.naturalHeight,r=n.naturalHeight/e);let i=(n.naturalWidth-r)/2,s=(n.naturalHeight-o)/2;return{...n,width:r,height:o,cropX:i,cropY:s}},wf=(n,e,t)=>{let r=n.cropSizeMode==="visible",o=n.cropX??0,i=n.cropY??0,s=n.width??e,a=n.height??t,l=r?s:s-o,u=r?a:a-i;return e>0&&t>0&&(l=Math.min(Math.max(l,0),e),u=Math.min(Math.max(u,0),t),o=Math.min(Math.max(o,0),e-l),i=Math.min(Math.max(i,0),t-u)),{left:n.left??0,top:n.top??0,angle:n.angle??0,originX:n.originX??"left",originY:n.originY??"top",flipX:n.flipX===!0,flipY:n.flipY===!0,width:l,height:u,cropX:o,cropY:i,scaleX:n.scaleX??1,scaleY:n.scaleY??1,naturalWidth:e,naturalHeight:t,cropSizeMode:n.cropSizeMode??"legacy"}},Tf=n=>{let e=n.cropSizeMode==="visible";return{left:n.left,top:n.top,width:e?n.width:n.width+n.cropX,height:e?n.height:n.height+n.cropY,cropX:n.cropX,cropY:n.cropY,scaleX:n.scaleX,scaleY:n.scaleY}},Zt={tl:{x:-.5,y:-.5},tr:{x:.5,y:-.5},bl:{x:-.5,y:.5},br:{x:.5,y:.5},left:{x:-.5,y:0},right:{x:.5,y:0},top:{x:0,y:-.5},bottom:{x:0,y:.5}},Wo=(n,e)=>{let t=-n.width/2-n.cropX,r=-n.height/2-n.cropY,o=n.naturalWidth-n.width/2-n.cropX,i=n.naturalHeight-n.height/2-n.cropY;return e==="tl"?{x:t,y:r}:e==="tr"?{x:o,y:r}:e==="bl"?{x:t,y:i}:{x:o,y:i}};var Ef=(n,e,t)=>({type:"Path",path:n.pathOf(e,t),originX:"center",originY:"center",left:0,top:0}),yc=n=>{if(!(n.width>0)||!(n.height>0))return n;let e=n.naturalWidth>0?n.naturalWidth:n.width,t=n.naturalHeight>0?n.naturalHeight:n.height,r=Math.min(n.width,n.height,e,t);if(!(r>0))return n;let o=n.cropX+n.width/2,i=n.cropY+n.height/2,s=o-r/2,a=i-r/2;s<0?s=0:s+r>n.naturalWidth&&n.naturalWidth>0&&(s=Math.max(0,n.naturalWidth-r)),a<0?a=0:a+r>n.naturalHeight&&n.naturalHeight>0&&(a=Math.max(0,n.naturalHeight-r));let l=Bo(n.left,n.top,n.originX,n.originY,bc(n),n.angle),u=_s(l,n.originX,n.originY,{x:r*n.scaleX,y:r*n.scaleY},n.angle);return{...n,width:r,height:r,cropX:s,cropY:a,left:u.x,top:u.y}};var Sy=(n,e)=>({w:e.naturalWidth||e.width||(n.width??0),h:e.naturalHeight||e.height||(n.height??0)}),vy=(n,e,t)=>({w:e*Math.abs((n.scaleX??1)||1),h:t*Math.abs((n.scaleY??1)||1)}),wy=(n,e,t,r,o,i)=>({cropX:Math.max(0,t/2-o/2-n),cropY:Math.max(0,r/2-i/2-e)}),Ty=(n,e,t,r,o,i)=>({clipX:t/2-o/2-n,clipY:r/2-i/2-e}),Cf=(n,e,t)=>{let r=Sy(e,t),o=vy(e,r.w,r.h),i=n.width??0,s=n.height??0,{cropX:a,cropY:l}=wy(n.clipX??0,n.clipY??0,o.w,o.h,i,s);return{left:n.left??0,top:n.top??0,angle:n.angle??0,originX:n.originX??"center",originY:n.originY??"center",flipX:n.flipX===!0,flipY:n.flipY===!0,width:i,height:s,cropX:a,cropY:l,scaleX:n.scaleX??1,scaleY:n.scaleY??1,naturalWidth:o.w,naturalHeight:o.h,cropSizeMode:"visible"}},Mf=n=>{let{clipX:e,clipY:t}=Ty(n.cropX,n.cropY,n.naturalWidth,n.naturalHeight,n.width,n.height);return{left:n.left,top:n.top,width:n.width,height:n.height,cropX:n.cropX,cropY:n.cropY,clipX:e,clipY:t,scaleX:n.scaleX,scaleY:n.scaleY}};var Rf=12,Pf=14,kf=7,Ey=1,Cy=1,Af=ee("#f6f7fa"),Nf=ee("#2f6fed"),Tc=["e","se","s","sw","w","nw","n","ne","e"],My=["tl","tr","bl","br"],Ry=["tl","tr","bl","br"],Py=["left","right","top","bottom"],Sc=(n,e,t,r,o)=>{let i=null,s=1/0;for(let a of n){let l=e(a),u=Math.hypot(l.x-t,l.y-r);u<=o&&u<s&&(i=a,s=u)}return i},vc=null,Ec=()=>{if(vc)return vc;let n=Math.ceil((kf+2)*2),e=document.createElement("canvas");e.width=n,e.height=n;let t=e.getContext("2d");return t.beginPath(),t.arc(n/2,n/2,kf,0,Math.PI*2),t.fillStyle="#ffffff",t.fill(),t.lineWidth=1.5,t.strokeStyle="#2f6fed",t.stroke(),vc=e,e},sr=30,ar=7,Ho={x:28,y:16},Go={x:14,y:4},wc=2,If=(n,e)=>{let t=document.createElement("canvas");t.width=n*wc,t.height=e*wc;let r=t.getContext("2d");return r?{canvas:t,ctx:r}:null},tt=n=>n*wc,Ds=null,Cc=()=>{if(Ds)return Ds;let n=If(sr,sr);if(!n)return Ds=document.createElement("canvas");let{canvas:e,ctx:t}=n;return t.translate(tt(ar),tt(ar)),t.shadowColor="rgba(12, 18, 28, 0.38)",t.shadowBlur=tt(4),t.shadowOffsetX=tt(2),t.shadowOffsetY=tt(2),t.beginPath(),t.lineWidth=tt(6),t.lineCap="round",t.strokeStyle="#dfe2e8",t.moveTo(0,tt(10)),t.lineTo(0,0),t.lineTo(tt(10),0),t.stroke(),Ds=e,e},Fs=null,Mc=()=>{if(Fs)return Fs;let n=If(Ho.x,Ho.y);if(!n)return Fs=document.createElement("canvas");let{canvas:e,ctx:t}=n;return t.translate(tt(Go.x),tt(Go.y)),t.shadowColor="rgba(12, 18, 28, 0.38)",t.shadowBlur=tt(4),t.shadowOffsetX=0,t.shadowOffsetY=tt(2),t.beginPath(),t.lineWidth=tt(4),t.lineCap="round",t.strokeStyle="#dfe2e8",t.moveTo(tt(-6),0),t.lineTo(tt(6),0),t.stroke(),Fs=e,e},_f=n=>{let e=Math.hypot(n[0],n[1])||1,t=Math.hypot(n[2],n[3])||1;return[n[0]/e,n[1]/e,n[2]/t,n[3]/t]},Xo=(n,e,t,r,o,i,s,a)=>{let l=r*Math.PI/180,u=Math.cos(l),c=Math.sin(l),[h,d,f,m]=_f(n),p=n[0]*e+n[2]*t+n[4],b=n[1]*e+n[3]*t+n[5],x=V([h,d,f,m,0,0],[u,c,-c,u,0,0],!0),g=(i.x-o.x/2)/s,y=(i.y-o.y/2)/s;return{matrix:[x[0],x[1],x[2],x[3],p-(x[0]*g+x[2]*y),b-(x[1]*g+x[3]*y)],dims:{x:o.x/s,y:o.y/s},color:[1,1,1,1],texture:a}},Lf=(n,e)=>{let t=!1;for(let r=0,o=e.length-1;r<e.length;o=r++){let i=e[r].x,s=e[r].y,a=e[o].x,l=e[o].y;s>n.y!=l>n.y&&n.x<(a-i)*(n.y-s)/(l-s)+i&&(t=!t)}return t},Os=class{constructor(e){this.host=e}host;node=null;circlesVisible=!0;ratio=null;shape=null;detachKey=null;get active(){return this.node!==null}get target(){return this.node}get info(){let e=this.node;if(!e||!(e instanceof ae?e.clipImageEl:e.imageEl))return null;let t=this.liveState();return{nodeId:e.id,handle:"",ratio:this.ratio,circlesVisible:this.circlesVisible,cropX:t.cropX,cropY:t.cropY,width:t.width,height:t.height,isMask:e instanceof ae,shapeActive:!(e instanceof ae)&&this.shape!==null}}enter(e,t){if(this.node&&this.exit(),e instanceof ae){if(!this.host.document.nodes.includes(e)||e.clipDynamicKind||!e.clipImageRaw||!e.clipImageEl)return!1}else if(e instanceof ie||!e.isImageType||!e.imageEl)return!1;this.node=e,this.ratio=null,this.shape=e instanceof ae||!t?.shape?null:t.shape,this.ratio=this.shape?.aspectRatio??null;let r=Math.abs(e.raw.scaleX??1),o=Math.abs(e.raw.scaleY??1);if(this.circlesVisible=r===o,this.host.document.exitEditing(),this.host.document.setSelection([e],"update"),!(e instanceof ae)){let i=s=>{s.key==="Escape"&&this.node&&this.exit()};window.addEventListener("keydown",i),this.detachKey=()=>window.removeEventListener("keydown",i)}return this.shape&&this.writeBack(yc(this.liveState())),this.host.requestRenderAll(),!0}exit(){if(!this.node)return;let e=this.node;this.node=null,this.ratio=null,this.shape=null,this.detachKey?.(),this.detachKey=null,this.host.document.applyTransform([e],()=>({}),"modified",{action:Le.crop}),this.host.requestRenderAll()}exitByOutsideClick(){this.exit()}setCropShape(e){let t=this.node;if(!t||t instanceof ae)return;this.ratio=e?.aspectRatio??null;let r=this.shape!==null;this.shape=e,e?this.writeBack(yc(this.liveState())):r&&this.writeBack(this.liveState(),!0),this.host.requestRenderAll()}setAspectRatio(e){if(this.node){if(this.ratio=e,e&&e>0){let t=this.shape!==null;this.shape=null;let r=vf(this.liveState(),e);this.writeBack(r,t)}this.host.requestRenderAll()}}hitHandle(e,t){let r=this.node;if(!r)return null;let o=r.matrix,i=this.liveState(),s=(l,u)=>{let c=Q(o,l,u);return this.host.toScreen(c.x,c.y)},a=Sc(["br","bl","tr","tl"],l=>{let u=Zt[l];return s(u.x*i.width,u.y*i.height)},e,t,Rf);if(a)return a;if(!this.ratio){let l=Sc(["bottom","right","top","left"],u=>{let c=Zt[u];return s(c.x*i.width,c.y*i.height)},e,t,Rf);if(l)return l}if(this.circlesVisible){let l=Sc(["br","bl","tr","tl"],u=>{let c=Wo(i,u);return s(c.x,c.y)},e,t,Pf);if(l){let u=Zt[l],c=s(u.x*i.width,u.y*i.height);return Math.hypot(c.x-e,c.y-t)<=Pf?l:`${l}S`}}return null}hitRect(e,t){let r=this.node;if(!r)return!1;let o=this.liveState(),i=r.matrix;if(!(r instanceof ae)){let c=["tl","tr","br","bl"].map(h=>{let d=(h==="tr"||h==="br"?.5:-.5)*o.width,f=(h==="bl"||h==="br"?.5:-.5)*o.height;return Q(i,d,f)});return Lf({x:e,y:t},c)}let s=["tl","tr","br","bl"].map(c=>{let h=(c==="tr"||c==="br"?.5:-.5)*o.width,d=(c==="bl"||c==="br"?.5:-.5)*o.height,f=Q(i,h,d);return this.host.toScreen(f.x,f.y)}),a=Math.abs(s[1].x-s[0].x)/2,l=Math.abs(s[3].y-s[0].y)/2,u=[{x:s[0].x-a,y:s[0].y-l},{x:s[1].x+a,y:s[1].y-l},{x:s[2].x+a,y:s[2].y+l},{x:s[3].x-a,y:s[3].y+l}];return Lf(this.host.toScreen(e,t),u)}applyHandle(e,t){if(!this.node)return;let o=this.liveState(),i=null;e.endsWith("S")?i=this.circlesVisible?yf(o,e.slice(0,2),t):null:is(e)?i=this.ratio?xf(o,e,t,this.ratio):bf(o,e,t):this.ratio||(i=Is(o,e,t)),i&&this.writeBack(i),this.host.requestRenderAll()}setScale(e){if(!this.node)return!1;let t=gf(this.liveState(),e,this.shape!==null);return t?(this.writeBack(t),this.host.document.setProps(this.node,{cropScale:t.scaleX},{deferIndexRebuild:!0}),this.host.requestRenderAll(),!0):!1}moveImageBy(e){if(!this.node)return;let r=this.liveState(),{cropX:o,cropY:i}=Sf(r,e);this.writeBack({...r,cropX:o,cropY:i}),this.host.requestRenderAll()}hoverCursor(e,t,r){let o=this.hitHandle(e,t);if(o){if(o.endsWith("S")&&this.node){let i=Zt[o.slice(0,2)],a=((this.node.raw.angle??0)+Math.atan2(i.y,i.x)*180/Math.PI+360)%360;return`${Tc[Math.round(a/45)]}-resize`}return"pointer"}return this.hitRect(r.x,r.y)?"move":""}buildOverlay(e){let t=this.node;if(!t||!t.imageEl)return[];let r=this.liveState(),o=t.matrix,i=[],s=(b,x)=>Q(o,b,x),a=r.width,l=r.height,u=Ey/e;for(let b of[1,2]){let x=-a/2+b*a/3,g=s(x,-l/2),y=s(x,l/2);i.push(Re(g,y,u,Af))}for(let b of[1,2]){let x=-l/2+b*l/3,g=s(-a/2,x),y=s(a/2,x);i.push(Re(g,y,u,Af))}let c=Cy/e,h=["tl","tr","br","bl"].map(b=>s(Wo(r,b).x,Wo(r,b).y));for(let b=0;b<4;b++)i.push(Re(h[b],h[(b+1)%4],c,Nf));let d=1.5/e,f=["tl","tr","br","bl"].map(b=>s(Zt[b].x*a,Zt[b].y*l));for(let b=0;b<4;b++)i.push(Re(f[b],f[(b+1)%4],d,Nf));if(this.circlesVisible){let b=Ec(),[x,g,y,v]=_f(o),S=b.width/e;for(let w of Ry){let R=Wo(r,w);i.push({matrix:[x,g,y,v,o[0]*R.x+o[2]*R.y+o[4],o[1]*R.x+o[3]*R.y+o[5]],dims:{x:S,y:S},color:[1,1,1,1],texture:b})}}if(!this.ratio){let b={top:0,right:90,bottom:180,left:270},x=Mc();for(let g of Py){let y=Zt[g];i.push(Xo(o,y.x*a,y.y*l,b[g],Ho,Go,e,x))}}let m={tl:0,tr:90,br:180,bl:270},p=Cc();for(let b of My){let x=Zt[b];i.push(Xo(o,x.x*a,x.y*l,m[b],{x:sr,y:sr},{x:ar,y:ar},e,p))}return i}dispose(){this.detachKey?.(),this.detachKey=null,this.node=null,this.shape=null}liveState(){let e=this.node;if(e instanceof ae)return Cf(e.raw,e.clipImageRaw,e.clipImageEl);let t=e.imageEl;return wf(e.raw,t.naturalWidth,t.naturalHeight)}writeBack(e,t=!1){let r=this.node,o={...r instanceof ae?Mf(e):Tf(e)};r instanceof ae||(this.shape?o.clipPath=Ef(this.shape,e.width,e.height):t&&(o.clipPath=void 0)),this.host.document.setProps(r,o,{deferIndexRebuild:!0})}};var Df={ml:{left:!0},mr:{right:!0},mt:{top:!0},mb:{bottom:!0},tl:{left:!0,top:!0},tr:{right:!0,top:!0},bl:{left:!0,bottom:!0},br:{right:!0,bottom:!0}},Ff=(n,e,t)=>{let r=n.expandScale??1.5;return{width:n.expandWidth??t.width*r,height:n.expandHeight??t.height*r,centerX:n.expandRectCenterX??e.x,centerY:n.expandRectCenterY??e.y}},Of=(n,e,t,r,o)=>{let i=t*Math.PI/180,s=Math.cos(i),a=Math.sin(i),{centerX:l,centerY:u}=n,c=n.width/2,h=n.height/2,d=r.x-l,f=r.y-u,m=d*s+f*a,p=-d*a+f*s,b=-c,x=c,g=-h,y=h;o.left&&(b=Math.min(m,x-1)),o.right&&(x=Math.max(m,b+1)),o.top&&(g=Math.min(p,y-1)),o.bottom&&(y=Math.max(p,g+1));let v=o.right,S=o.left,w=o.bottom,R=o.top,P=e.centerX-l,T=e.centerY-u,C=P*s+T*a,E=-P*a+T*s,M=C-e.scaledWidth/2,k=C+e.scaledWidth/2,A=E-e.scaledHeight/2,O=E+e.scaledHeight/2;!v&&M<b&&(b=M),!S&&k>x&&(x=k),!w&&A<g&&(g=A),!R&&O>y&&(y=O);let F=(b+x)/2,G=(g+y)/2;return{width:x-b,height:y-g,centerX:l+F*s-G*a,centerY:u+F*a+G*s}},Rc=(n,e,t,r)=>{let o=t*Math.PI/180,i=Math.cos(o),s=Math.sin(o),a=r.width/e.scaledWidth,l=r.height/e.scaledHeight,u=e.centerX-n.centerX,c=e.centerY-n.centerY,h=u*i+c*s,d=-u*s+c*i,f=e.scaledWidth/2,m=e.scaledHeight/2,p=n.width/2,b=n.height/2,x=Math.max(0,h-f+p),g=Math.max(0,p-h-f),y=Math.max(0,d-m+b),v=Math.max(0,b-d-m);return{left:Math.floor(x*a),right:Math.floor(g*a),top:Math.floor(y*l),bottom:Math.floor(v*l)}},Bf=(n,e,t,r)=>{let o=t*Math.PI/180,i=Math.cos(o),s=Math.sin(o),a=r.x-n.centerX,l=r.y-n.centerY,u=a*i+l*s,c=-a*s+l*i,h=Math.max(0,n.width/2-e.scaledWidth/2),d=Math.max(0,n.height/2-e.scaledHeight/2);return u=Math.max(-h,Math.min(h,u)),c=Math.max(-d,Math.min(d,c)),{x:n.centerX+u*i-c*s,y:n.centerY+u*s+c*i}},Rn={tl:{x:-.5,y:-.5},tr:{x:.5,y:-.5},bl:{x:-.5,y:.5},br:{x:.5,y:.5},ml:{x:-.5,y:0},mr:{x:.5,y:0},mt:{x:0,y:-.5},mb:{x:0,y:.5}},ky={tl:{x:-1,y:-1},tr:{x:1,y:-1},bl:{x:-1,y:1},br:{x:1,y:1}},Wf=(n,e,t,r)=>{let o=ky[t],i=n.centerX-o.x*(n.scaledWidth/2),s=n.centerY-o.y*(n.scaledHeight/2),a=r.x-i,l=r.y-s,u=Math.hypot(n.scaledWidth,n.scaledHeight),c=u>0?Math.hypot(a,l)/u:1,h=Math.max(Math.abs(n.scaleX),Math.abs(n.scaleY));c=Math.max(.1/h,Math.min(5/h,c));let d=n.scaledWidth*c,f=n.scaledHeight*c,m=i+o.x*(d/2),p=s+o.y*(f/2),b=Math.min(i,i+o.x*d),x=Math.min(s,s+o.y*f),g=b+d,y=x+f;return b<e.centerX-e.width/2||x<e.centerY-e.height/2||g>e.centerX+e.width/2||y>e.centerY+e.height/2?null:{scaleX:n.scaleX*c,scaleY:n.scaleY*c,centerX:m,centerY:p}};var zo=n=>n*Math.PI/180,Ay=12,Ny=14,Ly=1,Iy=(()=>{let n=ee("#3788ff");return[n[0],n[1],n[2],.5]})(),_y=ee("#3788ff"),Pc=["tl","tr","bl","br"],Dy={tl:0,tr:90,br:180,bl:270},Fy={mt:0,mr:90,mb:180,ml:270},Oy=(n,e)=>{let t=!1;for(let r=0,o=e.length-1;r<e.length;o=r++){let i=e[r].x,s=e[r].y,a=e[o].x,l=e[o].y;s>n.y!=l>n.y&&n.x<(a-i)*(n.y-s)/(l-s)+i&&(t=!t)}return t},Bs=class{constructor(e){this.host=e}host;node=null;detachKey=null;get active(){return this.node!==null}get target(){return this.node}get info(){let e=this.node;if(!e)return null;let t=this.view();return{nodeId:e.id,width:t.rect.width,height:t.rect.height,centerX:t.rect.centerX,centerY:t.rect.centerY,angle:t.angle,offsets:t.offsets}}enter(e){if(this.node&&this.exit(),!(e instanceof ie?!1:(e.isImageType||e instanceof ae)&&!!e.imageEl&&!(e instanceof ae&&e.clipDynamicKind)))return!1;this.node=e,this.host.document.exitEditing(),this.host.document.setSelection([e],"update");let r=e.raw,o=Math.abs(r.scaleX??1),i=Math.abs(r.scaleY??1),s=r.expandScale??1.5,a=e.center,l={};r.expandRectCenterX===void 0&&(l.expandRectCenterX=a.x),r.expandRectCenterY===void 0&&(l.expandRectCenterY=a.y),r.expandWidth===void 0&&(l.expandWidth=e.dims.x*o*s),r.expandHeight===void 0&&(l.expandHeight=e.dims.y*i*s),Object.keys(l).length>0&&this.host.document.setProps(e,l);let u=c=>{c.key==="Escape"&&this.node&&this.exit()};return window.addEventListener("keydown",u),this.detachKey=()=>window.removeEventListener("keydown",u),this.host.requestRenderAll(),!0}exit(){let e=this.node;if(!e)return;this.node=null,this.detachKey?.(),this.detachKey=null;let t=e.imageEl;if(t){let r=this.expandViewOf(e,t),o=Rc(r.rect,r.img,r.angle,{width:t.naturalWidth,height:t.naturalHeight});this.host.document.setProps(e,{expandLeftOffset:o.left,expandRightOffset:o.right,expandTopOffset:o.top,expandBottomOffset:o.bottom})}this.host.document.applyTransform([e],()=>({}),"modified",{action:Le.crop}),this.host.requestRenderAll()}exitByOutsideClick(){let e=this.node;this.exit(),e&&this.host.document.selection.includes(e)&&this.host.document.clearSelection()}async applyResult(e,t,r){this.host.document.setProps(e,{src:t});let o=await this.host.reloadImageElement(e);if(!o||!o.naturalWidth||!o.naturalHeight)return!1;let i=r.width/o.naturalWidth,s=r.height/o.naturalHeight,a=xe({...e.raw,width:o.naturalWidth,height:o.naturalHeight,scaleX:i,scaleY:s},{x:r.centerX,y:r.centerY});return this.host.document.setProps(e,{width:o.naturalWidth,height:o.naturalHeight,scaleX:i,scaleY:s,left:a.x,top:a.y}),this.host.document.applyTransform([e],()=>({}),"modified"),this.host.requestRenderAll(),!0}hitHandle(e,t){let r=this.view(),o=zo(r.angle),i=Math.cos(o),s=Math.sin(o);for(let a of Object.keys(Rn)){let l=Rn[a],u=l.x*r.rect.width,c=l.y*r.rect.height,h=r.rect.centerX+u*i-c*s,d=r.rect.centerY+u*s+c*i,f=this.host.toScreen(h,d);if(Math.hypot(f.x-e,f.y-t)<=Ay)return a}for(let a of Pc){let l=this.imageCornerOf(a),u=this.host.toScreen(l.x,l.y);if(Math.hypot(u.x-e,u.y-t)<=Ny)return`${a}S`}return null}hitRect(e,t){let r=this.view(),o=zo(r.angle),i=Math.cos(o),s=Math.sin(o),a=["tl","tr","br","bl"].map(l=>{let u=Rn[l],c=u.x*r.rect.width,h=u.y*r.rect.height;return{x:r.rect.centerX+c*i-h*s,y:r.rect.centerY+c*s+h*i}});return Oy({x:e,y:t},a)}applyHandle(e,t){let r=this.node;if(!r)return;if(e.endsWith("S")){let s=this.view(),a=r.raw,l=Wf({...s.img,scaleX:a.scaleX??1,scaleY:a.scaleY??1},s.rect,e.slice(0,2),t);if(l){let u=xe({...r.raw,width:r.dims.x,height:r.dims.y,scaleX:l.scaleX,scaleY:l.scaleY},{x:l.centerX,y:l.centerY});this.host.document.setProps(r,{scaleX:l.scaleX,scaleY:l.scaleY,left:u.x,top:u.y},{deferIndexRebuild:!0})}this.host.requestRenderAll();return}let o=this.view(),i=Of(o.rect,o.img,o.angle,t,Df[e]);this.host.document.setProps(r,{expandWidth:i.width,expandHeight:i.height,expandRectCenterX:i.centerX,expandRectCenterY:i.centerY},{deferIndexRebuild:!0}),this.host.requestRenderAll()}moveImageBy(e){let t=this.node;if(!t)return;let r=this.view(),o=Bf(r.rect,r.img,r.angle,{x:r.img.centerX+e.x,y:r.img.centerY+e.y}),i=xe({...t.raw,width:t.dims.x,height:t.dims.y},o);this.host.document.setProps(t,{left:i.x,top:i.y},{deferIndexRebuild:!0}),this.host.requestRenderAll()}hoverCursor(e,t,r,o){let i=this.hitHandle(e,t);if(i){if(i.endsWith("S")&&this.node){let s=Rn[i.slice(0,2)],l=((this.node.raw.angle??0)+Math.atan2(s.y,s.x)*180/Math.PI+360)%360;return`${Tc[Math.round(l/45)]}-resize`}return"pointer"}return this.hitRect(r,o)?"move":""}buildUnderlay(){let e=this.view(),t=zo(e.angle);return[{matrix:[Math.cos(t),Math.sin(t),-Math.sin(t),Math.cos(t),e.rect.centerX,e.rect.centerY],dims:{x:e.rect.width,y:e.rect.height},color:Iy}]}buildOverlay(e){let t=this.view(),r=[],o=zo(t.angle),i=[Math.cos(o),Math.sin(o),-Math.sin(o),Math.cos(o),t.rect.centerX,t.rect.centerY],s=p=>{let b=Rn[p];return Q(i,b.x*t.rect.width,b.y*t.rect.height)},a=Ly/e,l=["tl","tr","br","bl"].map(s);for(let p=0;p<4;p++)r.push(Re(l[p],l[(p+1)%4],a,_y));let u=Ec(),c=u.width/e,h=Math.cos(o),d=Math.sin(o);for(let p of Pc){let b=this.imageCornerOf(p);r.push({matrix:[h,d,-d,h,b.x,b.y],dims:{x:c,y:c},color:[1,1,1,1],texture:u})}let f=Mc();for(let p of["ml","mr","mt","mb"]){let b=Rn[p];r.push(Xo(i,b.x*t.rect.width,b.y*t.rect.height,Fy[p],Ho,Go,e,f))}let m=Cc();for(let p of Pc){let b=Rn[p];r.push(Xo(i,b.x*t.rect.width,b.y*t.rect.height,Dy[p],{x:sr,y:sr},{x:ar,y:ar},e,m))}return r}dispose(){this.detachKey?.(),this.detachKey=null,this.node=null}view(){let e=this.node;return this.expandViewOf(e,e.imageEl)}imageCornerOf(e){let t=this.view(),r=zo(t.angle),o=Math.cos(r),i=Math.sin(r),s=(e==="tr"||e==="br"?.5:-.5)*t.img.scaledWidth,a=(e==="bl"||e==="br"?.5:-.5)*t.img.scaledHeight;return{x:t.img.centerX+s*o-a*i,y:t.img.centerY+s*i+a*o}}expandViewOf(e,t){let r=e.raw,o=Math.abs(r.scaleX??1),i=Math.abs(r.scaleY??1),s=e.center,a=e.dims.x*o,l=e.dims.y*i,u={centerX:s.x,centerY:s.y,scaledWidth:a,scaledHeight:l},c=Ff(r,s,{width:a,height:l}),h=r.angle??0,d=t?Rc(c,u,h,{width:t.naturalWidth,height:t.naturalHeight}):null;return{rect:c,img:u,angle:h,offsets:d}}};var By=8,Wy=6;var cr=n=>{if(!n)return null;let e=Fe(n);return e?{x:(e.left+e.right)/2,y:(e.top+e.bottom)/2}:null},Hf=(n,e)=>{let t=n[e],r=String(t[0]).toUpperCase();if(r==="M"||r==="L")return{x:t[1],y:t[2]};if(r==="C")return{x:t[5],y:t[6]};if(r==="Q")return{x:t[3],y:t[4]};for(let o=e;o>=0;o--)if(String(n[o][0]).toUpperCase()==="M")return{x:n[o][1],y:n[o][2]};return{x:0,y:0}},lr=(n,e)=>{for(let t=e-1;t>=0;t--){let r=String(n[t][0]).toUpperCase();if(r==="M"||r==="L")return{x:n[t][1],y:n[t][2]};if(r==="C")return{x:n[t][5],y:n[t][6]};if(r==="Q")return{x:n[t][3],y:n[t][4]};if(r==="Z"){for(let o=t;o>=0;o--)if(String(n[o][0]).toUpperCase()==="M")return{x:n[o][1],y:n[o][2]}}}return{x:0,y:0}},Hy=n=>n==="C"?5:n==="Q"?3:1,ut=(n,e,t)=>({x:n[e]-t.x,y:n[e+1]-t.y}),kc=(n,e)=>{let t=[],r=[];return n.forEach((o,i)=>{let s=String(o[0]);if(s!=="Z"&&t.push({key:`c_${i}_${s}`,kind:"anchor",commandIndex:i,pointIndex:o.length-2,local:ut(o,o.length-2,e)}),s==="C"){let a=ut(o,1,e),l=ut(o,3,e);t.push({key:`c_${i}_C_CP_1`,kind:"handle",commandIndex:i,pointIndex:1,local:a}),t.push({key:`c_${i}_C_CP_2`,kind:"handle",commandIndex:i,pointIndex:3,local:l});let u=i>0?String(n[i-1][0]).toUpperCase():"M",c=i>0?ut(n[i-1],Hy(u),e):a;r.push({from:a,to:c},{from:l,to:ut(o,5,e)})}else if(s==="Q"){let a=ut(o,1,e);t.push({key:`c_${i}_Q_CP_1`,kind:"handle",commandIndex:i,pointIndex:1,local:a}),r.push({from:a,to:ut(o,3,e)})}}),{handles:t,connections:r}},zf=(n,e)=>n.map((t,r)=>({key:`p_${r}`,kind:"point",commandIndex:r,pointIndex:r,local:{x:t.x-e.x,y:t.y-e.y}})),Ws=n=>{if(!n.length)return null;let e=1/0,t=1/0,r=-1/0,o=-1/0;for(let i of n)e>i.x&&(e=i.x),t>i.y&&(t=i.y),r<i.x&&(r=i.x),o<i.y&&(o=i.y);return{x:(e+r)/2,y:(t+o)/2}},Gy=(n,e,t)=>{let r=t.x-e.x,o=t.y-e.y,i=r*r+o*o;if(!i)return{distance:Math.hypot(n.x-e.x,n.y-e.y),t:0,point:{...e},length:0};let s=Math.max(0,Math.min(1,((n.x-e.x)*r+(n.y-e.y)*o)/i)),a={x:e.x+r*s,y:e.y+o*s};return{distance:Math.hypot(n.x-a.x,n.y-a.y),t:s,point:a,length:Math.sqrt(i)}},Xy=(n,e,t=100)=>{let r=1/t,o=0,i=Number.POSITIVE_INFINITY,s=0,a=null;for(let h=0;h<=t;h++){let d=h*r,f=e(d);a&&(s+=Math.hypot(f.x-a.x,f.y-a.y)),a=f;let m=(f.x-n.x)**2+(f.y-n.y)**2;m<i&&(i=m,o=d)}let l=Math.max(0,o-r),u=Math.min(1,o+r),c=(u-l)/20;for(let h=l;h<=u;h+=c){let d=e(h),f=(d.x-n.x)**2+(d.y-n.y)**2;f<i&&(i=f,o=h)}return{distance:Math.sqrt(i),t:o,point:e(o),length:s}},Gf=(n,e,t,r,o)=>{let i=1-o,s=i*i*i,a=3*i*i*o,l=3*i*o*o,u=o*o*o;return{x:s*n.x+a*e.x+l*t.x+u*r.x,y:s*n.y+a*e.y+l*t.y+u*r.y}},Xf=(n,e,t,r)=>{let o=1-r,i=o*o,s=2*o*r,a=r*r;return{x:i*n.x+s*e.x+a*t.x,y:i*n.y+s*e.y+a*t.y}},zy=(n,e,t)=>({x:n.x+(e.x-n.x)*t,y:n.y+(e.y-n.y)*t}),Yf=(n,e,t,r,o)=>{let i=By/o,s=Wy/o,a=h=>Q(r,h.x,h.y),l=(h,d)=>a(ut(h,d,e)),u,c=Number.POSITIVE_INFINITY;return n.forEach((h,d)=>{let f=String(h[0]).toUpperCase();if(f==="C"||f==="Q"){let w={x:lr(n,d).x-e.x,y:lr(n,d).y-e.y},R=a(w),P=l(h,1),T=f==="C"?ut(h,5,e):ut(h,3,e),C=a(T),M=Xy(t,f==="C"?F=>Gf(R,P,l(h,3),C,F):F=>Xf(R,P,C,F));if(M.distance>i||M.length<=s*2||M.distance>=c)return;let k=s/M.length;if(M.t<=k||M.t>=1-k)return;let A=lr(n,d),O=f==="C"?(()=>{let F={x:A.x-e.x,y:A.y-e.y},G=ut(h,1,e),Y=ut(h,3,e),_={x:h[5]-e.x,y:h[6]-e.y};return Gf(F,G,Y,_,M.t)})():(()=>{let F={x:A.x-e.x,y:A.y-e.y},G=ut(h,1,e),Y={x:h[3]-e.x,y:h[4]-e.y};return Xf(F,G,Y,M.t)})();c=M.distance,u={commandIndex:d,commandType:f,t:M.t,local:O,scene:M.point};return}if(f!=="L"&&f!=="Z")return;let m=f==="L"?lr(n,d):Hf(n,Math.max(0,d-1)),p=Hf(n,d),b=a({x:m.x-e.x,y:m.y-e.y}),x=a({x:p.x-e.x,y:p.y-e.y}),g=Gy(t,b,x);if(g.distance>i||g.length<=s*2||g.distance>=c)return;let y=s/g.length;if(g.t<=y||g.t>=1-y)return;c=g.distance;let v={x:m.x-e.x,y:m.y-e.y},S={x:p.x-e.x,y:p.y-e.y};u={commandIndex:d,commandType:f,t:g.t,local:zy(v,S,g.t),scene:g.point}}),u},Uf=(n,e,t,r,o)=>n.map((i,s)=>{if(s!==e)return i;let a=[...i];return a[t]=r.x+o.x,a[t+1]=r.y+o.y,a}),$f=(n,e,t,r)=>n.map((o,i)=>i===e?{x:t.x+r.x,y:t.y+r.y}:o),jf=(n,e,t)=>{let r=n.map(a=>[...a]),o=t.local.x+e.x,i=t.local.y+e.y,s=t.commandIndex;if(t.commandType==="L"){let a=r[s],l=a[1],u=a[2];return r[s]=["L",o,i],r.splice(s+1,0,["L",l,u]),r}if(t.commandType==="C"){let a=r[s],l=lr(n,s),u=t.t,c=a[1],h=a[2],d=a[3],f=a[4],m=a[5],p=a[6],b=l.x+(c-l.x)*u,x=l.y+(h-l.y)*u,g=c+(d-c)*u,y=h+(f-h)*u,v=d+(m-d)*u,S=f+(p-f)*u,w=b+(g-b)*u,R=x+(y-x)*u,P=g+(v-g)*u,T=y+(S-y)*u;return r[s]=["C",b,x,w,R,o,i],r.splice(s+1,0,["C",P,T,v,S,m,p]),r}if(t.commandType==="Q"){let a=r[s],l=lr(n,s),u=t.t,c=a[1],h=a[2],d=a[3],f=a[4],m=l.x+(c-l.x)*u,p=l.y+(h-l.y)*u,b=c+(d-c)*u,x=h+(f-h)*u;return r[s]=["Q",m,p,o,i],r.splice(s+1,0,["Q",b,x,d,f]),r}return t.commandType==="Z"?(r.splice(s,1,["L",o,i],["Z"]),r):null},Vf=(n,e,t)=>{if(e<0||e>=n.length)return null;let r=n[e],o=String(r[0]).toUpperCase();if(o==="M"||o==="Z")return null;let i=o==="C"||o==="Q",s=t.toUpperCase()==="C";if(i===s)return{commands:n,changed:!1};let a,l;o==="L"?(a=r[1],l=r[2]):o==="C"?(a=r[5],l=r[6]):(a=r[3],l=r[4]);let u=lr(n,e),c=n.map(h=>[...h]);return c[e]=s?["C",u.x+(a-u.x)/3,u.y+(l-u.y)/3,a-(a-u.x)/3,l-(l-u.y)/3,a,l]:["L",a,l],{commands:c,changed:!0}},Ac=(n,e)=>{let t=n?.[e]?.[0];return t&&["C","Q","S","T","A"].includes(String(t).toUpperCase())?"smooth":"line"},qf=(n,e,t,r)=>{if(!t)return n;let o=t.x-e.x,i=t.y-e.y;return{x:n.x+r[0]*o+r[2]*i,y:n.y+r[1]*o+r[3]*i}};var Yy=12,Yo=ee("#2254f4"),Kf=ee("#ffffff"),Qf=7,Zf=5,Uy=1,Nc=null,$y=()=>{if(Nc)return Nc;let n=Math.ceil((Zf+2)*2),e=document.createElement("canvas");e.width=n,e.height=n;let t=e.getContext("2d");return t.beginPath(),t.arc(n/2,n/2,Zf,0,Math.PI*2),t.fillStyle="#ffffff",t.fill(),t.lineWidth=1.5,t.strokeStyle="#2254f4",t.stroke(),Nc=e,e},Ot=n=>{let e=n.typeKey;return e===L.PATH?"path":e===L.POLYGON||e===L.POLYLINE?"poly":e===L.LINE?"line":null},Hs=class{constructor(e){this.host=e}host;node=null;kind=null;activeAnchorKey;insertCandidate;detachKey=null;get active(){return this.node!==null}get target(){return this.node}get info(){let e=this.node,t=this.kind;if(!e||!t)return null;let r=e.matrix,o=this.currentHandles().map(i=>{let s=Q(r,i.local.x,i.local.y);return{key:i.key,kind:i.kind,x:s.x,y:s.y}});return{nodeId:e.id,kind:t,anchors:o,activeAnchorKey:this.activeAnchorKey,activeAnchorIndex:this.activeAnchorIndex(),insertCandidate:this.insertCandidate?{commandIndex:this.insertCandidate.commandIndex,commandType:this.insertCandidate.commandType,x:this.insertCandidate.scene.x,y:this.insertCandidate.scene.y}:void 0}}enter(e){this.node&&this.exit();let t=Ot(e);if(!t||t==="path"&&!Ce(e.raw.path)||t==="poly"&&!Array.isArray(e.raw.points)||t==="line"&&!(e instanceof Nr))return!1;this.node=e,this.kind=t,this.activeAnchorKey=void 0,this.insertCandidate=void 0,this.host.document.exitEditing(),this.host.document.setSelection([e],"update");let r=o=>{o.key==="Escape"&&this.node&&this.exit()};return window.addEventListener("keydown",r),this.detachKey=()=>window.removeEventListener("keydown",r),this.host.requestRenderAll(),!0}exit(){this.node&&(this.node=null,this.kind=null,this.activeAnchorKey=void 0,this.insertCandidate=void 0,this.detachKey?.(),this.detachKey=null,this.host.requestRenderAll())}exitByOutsideClick(){this.exit()}hitAnchor(e,t){let r=this.node;if(!r)return null;let o=r.matrix,i=null,s=Yy;for(let a of this.currentHandles()){let l=Q(o,a.local.x,a.local.y),u=this.host.toScreen(l.x,l.y),c=Math.hypot(u.x-e,u.y-t);c<=s&&(s=c,i=a.key)}return i}hitBody(e,t){let r=this.node;return r?r.containsPoint(e,t):!1}findInsertCandidate(e,t){let r=this.node;if(!r||this.kind!=="path")return null;let o=Ce(r.raw.path),i=cr(o);return!o||!i?null:Yf(o,i,{x:e,y:t},r.matrix,this.host.zoom)??null}startAnchorDrag(e){return!this.node||!this.currentHandles().some(r=>r.key===e)?!1:(this.captureDragBefore(),this.setActiveAnchor(e),!0)}applyAnchorDrag(e,t){let r=this.node,o=this.kind;if(!r||!o)return;let i=this.currentHandles().find(l=>l.key===e);if(!i)return;let s=r.matrix,a=Q(ve(s),t.x,t.y);if(o==="path"){let l=Ce(r.raw.path),u=cr(l);if(!l||!u)return;let c=Uf(l,i.commandIndex,i.pointIndex,a,u);this.writeBackWithCompensation(r,c,u,cr(c),Fe(c))}else if(o==="poly"){let l=r.raw.points,u=Ws(l);if(!u)return;let c=$f(l,i.commandIndex,a,u),h=1/0,d=1/0,f=-1/0,m=-1/0;for(let p of c)h>p.x&&(h=p.x),d>p.y&&(d=p.y),f<p.x&&(f=p.x),m<p.y&&(m=p.y);this.writeBackWithCompensation(r,c,u,Ws(c),{left:h,top:d,right:f,bottom:m})}else{let l=i.commandIndex===0?{x1:a.x,y1:a.y}:{x2:a.x,y2:a.y},u=Number(l.x1??r.raw.x1),c=Number(l.y1??r.raw.y1),h=Number(l.x2??r.raw.x2),d=Number(l.y2??r.raw.y2),f=xe({...r.raw,width:Math.abs(h-u),height:Math.abs(d-c)},r.center);this.host.document.setProps(r,{...l,left:f.x,top:f.y},{deferIndexRebuild:!0})}this.host.requestRenderAll()}moveBodyBy(e){let t=this.node;t&&(this.captureDragBefore(),this.host.document.setProps(t,{left:(t.raw.left??0)+e.x,top:(t.raw.top??0)+e.y},{deferIndexRebuild:!0}),this.host.requestRenderAll())}captureDragBefore(){this._dragBefore??=this.node?this.node.toObject():null}_dragBefore=null;commit(){let e=this.node;if(!e)return;let t=this._dragBefore;this._dragBefore=null,this.host.document.applyTransform([e],()=>({}),"modified",t?{before:new Map([[e,t]])}:void 0)}insertAnchor(e){let t=this.node;if(!t||this.kind!=="path")return null;let r=Ce(t.raw.path),o=cr(r);if(!r||!o)return null;let i=jf(r,o,e);if(!i)return null;let s=t.toObject();this.host.document.setProps(t,{path:i},{deferIndexRebuild:!0}),this.host.document.applyTransform([t],()=>({}),"modified",{before:new Map([[t,s]])});let a=e.commandType==="Z"?"L":e.commandType,l=`c_${e.commandIndex}_${a}`;return this.insertCandidate=void 0,this.setActiveAnchor(l),this.host.requestRenderAll(),l}setAnchorType(e,t){let r=this.node;if(!r||this.kind!=="path")return!1;let o=Ce(r.raw.path);if(!o)return!1;let i=Vf(o,e,t);if(!i)return!1;if(i.changed){let s=r.toObject();this.host.document.setProps(r,{path:i.commands},{deferIndexRebuild:!0}),this.host.document.applyTransform([r],()=>({}),"modified",{before:new Map([[r,s]])})}return this.setActiveAnchor(`c_${e}_${String(i.commands[e][0])}`),this.host.requestRenderAll(),i.changed}setActiveAnchor(e){if(this.activeAnchorKey===e)return;this.activeAnchorKey=e;let t=this.node;t&&this.host.document.events.fire("path:active-anchor-change",t,e),this.host.requestRenderAll()}resetAnchorStyles(){this.activeAnchorKey!==void 0&&(this.activeAnchorKey=void 0,this.host.requestRenderAll())}activeAnchorIndex(){let e=this.activeAnchorKey;if(e){if(e.startsWith("c_")){let t=e.match(/^c_(\d+)_/),r=t?Number(t[1]):NaN;return Number.isFinite(r)?r:void 0}if(e.startsWith("p_"))return Number(e.slice(2));if(e==="e0"||e==="e1")return Number(e[1])}}hoverCursor(e,t,r){let o=this.hitAnchor(e,t);if(o)return o.includes("_CP_")?"crosshair":"default";let i=this.findInsertCandidate(r.x,r.y);return i?(this.updateInsertCandidate(i),"copy"):(this.updateInsertCandidate(void 0),this.hitBody(r.x,r.y)?"move":"")}updateInsertCandidate(e){let t=this.insertCandidate;t&&e&&t.commandIndex===e.commandIndex&&t.commandType===e.commandType&&Math.abs(t.scene.x-e.scene.x)<.1&&Math.abs(t.scene.y-e.scene.y)<.1||!t&&!e||(this.insertCandidate=e,this.host.requestRenderAll())}buildOverlay(e){let t=this.node,r=this.kind;if(!t||!r)return[];let o=t.matrix,i=[...Cn(t.aCoords,e)],s=a=>Q(o,a.x,a.y);if(r==="path"){let a=Ce(t.raw.path),l=cr(a);if(!a||!l)return i;let{handles:u,connections:c}=kc(a,l),h=Uy/e;for(let p of c)i.push(Re(s(p.from),s(p.to),h,Yo));let d=Qf/e,f=$y(),m=f.width/2*2*(1/e);for(let p of u){let b=s(p.local);if(p.kind==="handle")i.push({matrix:[1,0,0,1,b.x,b.y],dims:{x:m,y:m},color:[1,1,1,1],texture:f});else{let x=p.key===this.activeAnchorKey;i.push({matrix:[1,0,0,1,b.x,b.y],dims:{x:d,y:d},color:Yo}),i.push({matrix:[1,0,0,1,b.x,b.y],dims:{x:d-2/e,y:d-2/e},color:x?Yo:Kf})}}this.insertCandidate&&i.push({matrix:[1,0,0,1,this.insertCandidate.scene.x,this.insertCandidate.scene.y],dims:{x:m,y:m},color:[1,1,1,1],texture:f})}else{let a=Qf/e;for(let l of this.currentHandles()){let u=s(l.local),c=l.key===this.activeAnchorKey;i.push({matrix:[1,0,0,1,u.x,u.y],dims:{x:a,y:a},color:Yo}),i.push({matrix:[1,0,0,1,u.x,u.y],dims:{x:a-2/e,y:a-2/e},color:c?Yo:Kf})}}return i}dispose(){this.detachKey?.(),this.detachKey=null,this.node=null,this.kind=null}currentHandles(){let e=this.node,t=this.kind;if(!e||!t)return[];if(t==="path"){let a=Ce(e.raw.path),l=cr(a);return!a||!l?[]:kc(a,l).handles}if(t==="poly"){let a=e.raw.points,l=Ws(a);return!Array.isArray(a)||!l?[]:zf(a,l)}let r=Number(e.raw.x1),o=Number(e.raw.y1),i=Number(e.raw.x2),s=Number(e.raw.y2);return[r,o,i,s].every(Number.isFinite)?[{key:"e0",kind:"endpoint",commandIndex:0,pointIndex:0,local:{x:r,y:o}},{key:"e1",kind:"endpoint",commandIndex:1,pointIndex:1,local:{x:i,y:s}}]:[]}writeBackWithCompensation(e,t,r,o,i){if(!i)return;let s=e.ownMatrix,a=qf(e.center,r,o,[s[0],s[1],s[2],s[3]]),l=xe({...e.raw,width:i.right-i.left,height:i.bottom-i.top},a),u=this.kind==="path"?{path:t}:{points:t};this.host.document.setProps(e,{...u,left:l.x,top:l.y},{deferIndexRebuild:!0})}};import{Warpvas as jy}from"warpvas";var Jf=12,Vy=5,qy=4,Ky=1,em=3,tm=2e3,nm=10,Qy=[.2,.2,.2,.6],Zy=[.11,.35,.96,1],Jy=[1,1,1,.9],Gs=class{host;warp=null;node=null;beforeRaw=null;originalSrc=null;undoStack=[];redoStack=[];previewCanvas=null;previewVersion=0;renderedVersion=-1;coreSize={w:0,h:0};displayScale={x:1,y:1};coreAnchor={x:0,y:0};renderCanvas=null;constructor(e){this.host=e}get document(){return this.host.document}get zoom(){return this.host.zoom}get textures(){return this.host.textures}toScreen(e,t){return this.host.toScreen(e,t)}requestRenderAll(){this.host.requestRenderAll()}reloadNodeImage(e){return this.host.reloadNodeImage(e)}get active(){return!!this.warp}get target(){return this.node}get debugAnchors(){if(!this.warp||!this.node)return[];let e=[],t=this.currentBounds();for(let r=0;r<t.length;r++)for(let o=0;o<t[r].length;o++){let i=t[r][o];for(let s of Lc){let a=i[s];a&&a.forEach((l,u)=>{let c=this.toScene(l);e.push({row:r,col:o,dir:s,i:u,srcX:Math.round(l.x),srcY:Math.round(l.y),sceneX:Math.round(c.x),sceneY:Math.round(c.y)})})}}return e}get debugPreviewInfo(){if(!this.previewCanvas)return null;let e=this.previewCanvas;e.__probeId===void 0&&(e.__probeId=Math.random());let t=this.warp?this.warp.getBoundingBoxInfo():null;return{canvasId:e.__probeId,width:e.width,height:e.height,version:this.previewVersion,box:t,dataURL:e.width*e.height<=4e5?e.toDataURL("image/png"):void 0}}get debugBoundsSample(){return!this.warp||!this.coreSize.w?null:{region:this.currentBounds()[0]?.[0]??null,natural:{w:this.coreSize.w,h:this.coreSize.h}}}async enter(e,t){if(this.warp&&this.cancel(),!e.imageEl||e.cropRect||e instanceof ie||!e.imageEl.naturalWidth||!e.imageEl.naturalHeight)return!1;let r=e.raw;this.originalSrc=r.warpOriginalSrc??r.src??null;let o=e.imageEl,i=r.warpOriginalSrc,s=o,a=!1;if(i)try{let f=await this.host.loadImage(i,r.crossOrigin??void 0);f?.naturalWidth&&(s=f,a=!0)}catch{}let l=new jy(s,t?.gridRows??em,t?.gridCols??em);l.setInputLimitSize({width:tm,height:tm}),this.renderCanvas=document.createElement("canvas"),l.setRenderingCanvas(this.renderCanvas);let u=s===o?o:s;this.coreSize={w:u.naturalWidth*l.scale.x,h:u.naturalHeight*l.scale.y};let c=r.warpDisplayScale,h=r.warpCoreAnchor;a&&c&&typeof c.x=="number"&&h&&typeof h.x=="number"?(this.displayScale={x:c.x,y:c.y??c.x},this.coreAnchor={x:h.x,y:h.y??h.x}):(this.displayScale={x:e.dims.x/this.coreSize.w,y:e.dims.y/this.coreSize.h},this.coreAnchor={x:this.coreSize.w/2,y:this.coreSize.h/2});let d=a?r.warpvasState:void 0;if(d&&Array.isArray(d.splitPoints))try{l.setWarpState(d.splitPoints,d.regionBounds??null)}catch{}return this.node=e,this.warp=l,this.beforeRaw=e.toObject(),this.undoStack=[this.snapshot()],this.redoStack=[],this.fireHistory(),this.refreshPreview(),this.requestRenderAll(),!0}hitAnchor(e,t){let r=this.hitAnchorsOfKind(e,t,"vertex");return r||this.hitAnchorsOfKind(e,t,"curve")}hitAnchorsOfKind(e,t,r){let o=this.currentBounds(),i=null;for(let s=0;s<o.length;s++)for(let a=0;a<o[s].length;a++){let l=o[s][a];if(r==="vertex")for(let u of rm){let c=om(l,u);if(!c)continue;let h=this.screenDist(c,e,t);h<=Jf&&(!i||h<i.dist)&&(i={anchor:{kind:"vertex",row:s,col:a,pos:u},dist:h})}else for(let u of Lc){let c=l[u];if(!(!c||c.length<4))for(let h of[0,1]){let d=this.screenDist(c[h+1],e,t);d<=Jf&&(!i||d<i.dist)&&(i={anchor:{kind:"curve",row:s,col:a,dir:u,index:h},dist:d})}}}return i?.anchor??null}applyAnchorDrag(e,t){let r=this.warp;if(!r)return;let o=this.toSource(t);if(e.kind==="vertex")r.updateVertexCoord(e.row,e.col,e.pos,o);else{let i=this.currentBounds()[e.row]?.[e.col]?.[e.dir];if(!i||i.length<4)return;let s=i.map(a=>({...a}));s[e.index+1]=o,r.updateRegionBoundCoords(e.row,e.col,e.dir,[s[0],s[1],s[2],s[3]])}this.refreshPreview(),this.requestRenderAll()}endDrag(){this.warp&&(this.undoStack.push(this.snapshot()),this.redoStack=[],this.fireHistory())}undo(){return!this.warp||this.undoStack.length<=1?!1:(this.redoStack.push(this.undoStack.pop()),this.restore(this.undoStack[this.undoStack.length-1]),this.afterHistoryStep(),!0)}redo(){if(!this.warp)return!1;let e=this.redoStack.pop();return e?(this.undoStack.push(e),this.restore(e),this.afterHistoryStep(),!0):!1}afterHistoryStep(){this.fireHistory(),this.refreshPreview(),this.requestRenderAll()}get undoable(){return this.undoStack.length>1}get redoable(){return this.redoStack.length>0}getWarpState(){return this.warp?this.snapshot():null}buildOverlay(){if(!this.warp||!this.node)return[];let e=this.zoom,t=[];if(this.previewCanvas){this.renderedVersion!==this.previewVersion&&(this.textures.update(this.previewCanvas),this.renderedVersion=this.previewVersion);let s=this.localFromSourceBox(this.warp.getBoundingBoxInfo());t.push({matrix:this.quadMatrix(s.cx,s.cy),dims:{x:s.w,y:s.h},color:[1,1,1,1],texture:this.previewCanvas})}let r=this.currentBounds(),o=new Set,i=new Set;for(let s of r)for(let a of s){for(let l of Lc){let u=a[l];if(!u||u.length<4)continue;let c=this.toScene(u[0]);for(let h=1;h<=nm;h++){let d=this.toScene(e0(u[0],u[1],u[2],u[3],h/nm));t.push(Re(c,d,Ky/e,Qy)),c=d}for(let h of[0,1]){let d=u[h+1],f=`${Math.round(d.x)},${Math.round(d.y)}`;i.has(f)||(i.add(f),t.push(im(this.toScene(d),qy,Jy,e)))}}for(let l of rm){let u=om(a,l);if(!u)continue;let c=`${Math.round(u.x)},${Math.round(u.y)}`;o.has(c)||(o.add(c),t.push(im(this.toScene(u),Vy,Zy,e)))}}return t}hoverCursor(e,t){return this.hitAnchor(e,t)?"pointer":"default"}async exit(e){let t=this.warp,r=this.node;if(!t||!r)return null;let o=this.beforeRaw,i=null;if(e&&!t.isUnwarped()){let a=t.render().toDataURL("image/png"),l=t.getBoundingBoxInfo(),u=t.getWarpState(),c=this.localFromSourceBox(l),h=this.sourceToDisplayScale(),d=Math.max(1,Math.round(l.width*h.x)),f=Math.max(1,Math.round(l.height*h.y)),m=r.matrix,p={x:r.center.x+m[0]*c.cx+m[2]*c.cy,y:r.center.y+m[1]*c.cx+m[3]*c.cy},b=xe({...r.raw,width:d,height:f},p),x={x:l.width/2-l.offsetX,y:l.height/2-l.offsetY};i={dataURL:a,state:u,nextWidth:d,nextHeight:f,left:b.x,top:b.y,originalSrc:this.originalSrc,displayScale:{x:this.displayScale.x,y:this.displayScale.y},coreAnchor:x}}this.teardown(t);let s=!1;return i&&(r.set({src:i.dataURL,width:i.nextWidth,height:i.nextHeight,left:i.left,top:i.top,warpvasState:i.state,warpOriginalSrc:i.originalSrc??void 0,warpDisplayScale:i.displayScale,warpCoreAnchor:i.coreAnchor}),await this.reloadNodeImage(r.id),this.host.document.applyTransform([r],()=>({}),"modified",{action:Le.warpImage,before:new Map([[r,o]])}),s=!0),this.requestRenderAll(),{committed:s,node:r,before:o,after:r.toObject()}}async cancel(){await this.exit(!1)}teardown(e=this.warp){this.previewCanvas&&this.textures.remove(this.previewCanvas),e?.dispose?.(),this.warp=null,this.node=null,this.beforeRaw=null,this.originalSrc=null,this.undoStack=[],this.redoStack=[],this.previewCanvas=null,this.previewVersion=0,this.renderedVersion=-1,this.coreSize={w:0,h:0},this.displayScale={x:1,y:1},this.coreAnchor={x:0,y:0},this.renderCanvas=null}snapshot(){return this.warp.getWarpState()}restore(e){this.warp.setWarpState(e.splitPoints,e.regionBounds)}currentBounds(){return this.warp?this.warp.getWarpState().regionBounds??[]:[]}sourceToDisplayScale(){return{x:this.displayScale.x,y:this.displayScale.y}}quadMatrix(e,t){return t0(this.node.matrix,e,t)}toScene(e){let t=this.node;return Q(t.matrix,(e.x-this.coreAnchor.x)*this.displayScale.x,(e.y-this.coreAnchor.y)*this.displayScale.y)}toSource(e){let r=this.node.localPoint(e.x,e.y);return{x:r.x/this.displayScale.x+this.coreAnchor.x,y:r.y/this.displayScale.y+this.coreAnchor.y}}screenDist(e,t,r){let o=this.toScene(e),i=this.toScreen(o.x,o.y);return Math.hypot(i.x-t,i.y-r)}localFromSourceBox(e){return{cx:(e.width/2-e.offsetX-this.coreAnchor.x)*this.displayScale.x,cy:(e.height/2-e.offsetY-this.coreAnchor.y)*this.displayScale.y,w:e.width*this.displayScale.x,h:e.height*this.displayScale.y}}refreshPreview(){if(!this.warp)return;let e=this.previewCanvas;this.previewCanvas=this.warp.render(),e&&e!==this.previewCanvas&&this.textures.remove(e),this.previewVersion++}fireHistory(){this.host.onWarpHistoryChange?.(this.undoable,this.redoable)}},rm=["tl","tr","bl","br"],Lc=["top","right","bottom","left"],om=(n,e)=>{let t=n[e==="tl"||e==="tr"?"top":"bottom"],r=n[e==="tl"||e==="bl"?"left":"right"];if(!t||t.length<4||!r||r.length<4)return null;let o=null;for(let i of[t[0],t[3]])for(let s of[r[0],r[3]]){let a=Math.hypot(i.x-s.x,i.y-s.y);(!o||a<o.dist)&&(o={pt:{x:(i.x+s.x)/2,y:(i.y+s.y)/2},dist:a})}return o?.pt??null},e0=(n,e,t,r,o)=>{let i=1-o;return{x:i*i*i*n.x+3*i*i*o*e.x+3*i*o*o*t.x+o*o*o*r.x,y:i*i*i*n.y+3*i*i*o*e.y+3*i*o*o*t.y+o*o*o*r.y}},im=(n,e,t,r)=>({matrix:[1,0,0,1,n.x,n.y],dims:{x:e*2/r,y:e*2/r},color:t}),t0=(n,e,t)=>[n[0],n[1],n[2],n[3],n[0]*e+n[2]*t+n[4],n[1]*e+n[3]*t+n[5]];var he=n=>Math.round(n*1e6)/1e6;var Gr=([n,e],[t,r])=>n<=t?e>=t:n>=t?r>=n:!1,Xs=([n,e],[t,r])=>{let o=Math.max(n,t),i=Math.min(e,r);return o<=i?[o,i]:null},Jt=(n,e,t,r,o)=>{let i=Math.abs(e);i<=t[r]&&(i<t[r]&&(n.length=0),n.push(o),t[r]=i)},lm=n=>{let e=n.map((r,o)=>({p:r,i:o}));e.sort((r,o)=>r.p.x-o.p.x);let t=n.map((r,o)=>({p:r,i:o}));return t.sort((r,o)=>r.p.y-o.p.y),{byX:e,byY:t}},n0=(n,e,t)=>{let r=0,o=n.length;for(;r<o;){let i=r+o>>1;n[i].p[e]<t?r=i+1:o=i}return r},sm=(n,e,t,r,o,i,s)=>{let a=[],l=(u,c,h,d,f,m)=>{let p=c;for(let b of d){let x=n0(u,c,b[c]-h),g=b[c]+h,y=m[p];a.length=0;for(let v=x;v<u.length;v++){let S=u[v];if(S.p[c]>g)break;let w=S.p[c]-b[c],R=Math.abs(w);R<=y&&(R<y&&(y=R,a.length=0),a.push({p:S.p,i:S.i,offset:w}))}a.sort((v,S)=>v.i-S.i);for(let v of a)Jt(f,v.offset,m,p,{type:"point",points:[b,v.p],offset:v.offset})}};l(e.byX,"x",t,n,i,o),l(e.byY,"y",r,n,s,o)},_c=n=>({x:he(n.x),y:he(n.y)}),Ic=n=>({left:he(n.left),top:he(n.top),right:he(n.right),bottom:he(n.bottom)}),Ys=n=>[n.tl,n.tr,n.br,n.bl,n.c].map(_c),cm=n=>n.flatMap(Ys);var um=n=>{let e=n.map(Ic).map((o,i)=>({bounds:o,idx:i})),t=o=>[...e].sort((i,s)=>i.bounds[o]-s.bounds[o]),r=(o,i)=>[...e].sort((s,a)=>s.bounds[o]+s.bounds[i]-a.bounds[o]-a.bounds[i]);return{byLeft:t("left"),byRight:t("right"),byTop:t("top"),byBottom:t("bottom"),byLeftPlusRight:r("left","right"),byTopPlusBottom:r("top","bottom")}};var r0=(n,e,t,r,o)=>{let{left:i,top:s,right:a,bottom:l}=n,u=(i+a)/2,c=(s+l)/2,h=t.x,d=t.y,f=a-i,m=l-s,p=(T,C,E,M)=>({startBounds:T,endBounds:C,startSide:[{x:T.right,y:T.top},{x:T.right,y:T.bottom}],endSide:[{x:C.left,y:C.top},{x:C.left,y:C.bottom}],length:M,overlap:E}),b=(T,C,E,M)=>({startBounds:T,endBounds:C,startSide:[{x:T.left,y:T.bottom},{x:T.right,y:T.bottom}],endSide:[{x:C.left,y:C.top},{x:C.right,y:C.top}],length:M,overlap:E}),x=(T,C)=>{if(!(T.right<C.left&&Gr([T.top,T.bottom],[C.top,C.bottom])))return;let E=Xs([T.top,T.bottom],[C.top,C.bottom]);if(!Gr([s,l],E))return;let M=C.left-T.right,k=he(T.right+M/2-u);if(M>f&&Math.abs(k)<=t.x){Jt(r,k,t,"x",{type:"gap",direction:"center_horizontal",gap:p(T,C,E,M),offset:k});return}let A=he(M-(i-C.right));if(Math.abs(A)<=t.x){Jt(r,A,t,"x",{type:"gap",direction:"side_right",gap:p(T,C,E,M),offset:A});return}let O=he(T.left-a-M);Math.abs(O)<=t.x&&Jt(r,O,t,"x",{type:"gap",direction:"side_left",gap:p(T,C,E,M),offset:O})},g=(T,C)=>{if(!(T.bottom<C.top&&Gr([T.left,T.right],[C.left,C.right])))return;let E=Xs([T.left,T.right],[C.left,C.right]);if(!Gr([i,a],E))return;let M=C.top-T.bottom,k=he(T.bottom+M/2-c);if(M>m&&Math.abs(k)<=t.y){Jt(o,k,t,"y",{type:"gap",direction:"center_vertical",gap:b(T,C,E,M),offset:k});return}let A=he(T.top-l-M);if(Math.abs(A)<=t.y){Jt(o,A,t,"y",{type:"gap",direction:"side_top",gap:b(T,C,E,M),offset:A});return}let O=he(s-C.bottom),F=M-O;Math.abs(F)<=t.y&&Jt(o,F,t,"y",{type:"gap",direction:"side_bottom",gap:b(T,C,E,M),offset:F})},y=e.byLeft,v=e.byRight,S=e.byTop,w=e.byBottom,R=h+1e-6,P=d+1e-6;{let T=y.length;for(let C of v){if(C.bounds.right>=u+h+.001)break;let E=2*u-C.bounds.right,M=E+2*R,k=E-2*R;for(;T>0&&y[T-1].bounds.left>M;)T--;for(let A=T-1;A>=0&&y[A].bounds.left>=k;A--)x(C.bounds,y[A].bounds)}}{let T=0;for(let C of e.byLeftPlusRight){if(C.bounds.right>=i+h+.001)continue;let E=C.bounds.left+C.bounds.right-i,M=E-R,k=E+R;for(;T<v.length&&v[T].bounds.right<M;)T++;for(let A=T;A<v.length&&v[A].bounds.right<=k;A++)x(v[A].bounds,C.bounds)}}{let T=0;for(let C of e.byLeftPlusRight){if(C.bounds.left<=a-h-.001)continue;let E=C.bounds.left+C.bounds.right-a,M=E-R,k=E+R;for(;T<y.length&&y[T].bounds.left<M;)T++;for(let A=T;A<y.length&&y[A].bounds.left<=k;A++)x(C.bounds,y[A].bounds)}}{let T=S.length;for(let C of w){if(C.bounds.bottom>=c+d+.001)break;let E=2*c-C.bounds.bottom,M=E+2*P,k=E-2*P;for(;T>0&&S[T-1].bounds.top>M;)T--;for(let A=T-1;A>=0&&S[A].bounds.top>=k;A--)g(C.bounds,S[A].bounds)}}{let T=0;for(let C of e.byTopPlusBottom){if(C.bounds.top<=l-d-.001)continue;let E=C.bounds.top+C.bounds.bottom-l,M=E-P,k=E+P;for(;T<S.length&&S[T].bounds.top<M;)T++;for(let A=T;A<S.length&&S[A].bounds.top<=k;A++)g(C.bounds,S[A].bounds)}}{let C=0;for(let E of e.byTopPlusBottom){if(E.bounds.bottom>=s+d+.001)continue;let M=E.bounds.top-he(s-E.bounds.bottom),k=M-P,A=M+P;for(;C<w.length&&w[C].bounds.bottom<k-1e-5;)C++;for(let O=C;O<w.length&&w[O].bounds.bottom<=A;O++)g(w[O].bounds,E.bounds)}}},zs=(n,e,t,r,o)=>{for(let i of n)for(let s of e){let a=s.x-i.x,l=s.y-i.y;Math.abs(a)<=t.x&&Jt(r,a,t,"x",{type:"point",points:[i,s],offset:a}),Math.abs(l)<=t.y&&Jt(o,l,t,"y",{type:"point",points:[i,s],offset:l})}},o0=(n,e,t,r,o)=>{let{left:i,top:s,right:a,bottom:l}=n,u=(i+a)/2,c=(s+l)/2;for(let h of e.horizontalGaps){if(!Gr([s,l],h.overlap))continue;let d=h.startSide[0].x+h.length/2,f=he(d-u);if(h.length>a-i&&Math.abs(f)<=t.x){Math.abs(f)<t.x&&(r.length=0),t.x=Math.abs(f),r.push({type:"gap",direction:"center_horizontal",gap:h,offset:f});continue}let p=i-h.endBounds.right,b=he(h.length-p);if(Math.abs(b)<=t.x){Math.abs(b)<t.x&&(r.length=0),t.x=Math.abs(b),r.push({type:"gap",direction:"side_right",gap:h,offset:b});continue}let x=h.startBounds.left-a,g=he(x-h.length);if(Math.abs(g)<=t.x){Math.abs(g)<t.x&&(r.length=0),t.x=Math.abs(g),r.push({type:"gap",direction:"side_left",gap:h,offset:g});continue}}for(let h of e.verticalGaps){if(!Gr([i,a],h.overlap))continue;let d=h.startSide[0].y+h.length/2,f=he(d-c);if(h.length>l-s&&Math.abs(f)<=t.y){Math.abs(f)<t.y&&(o.length=0),t.y=Math.abs(f),o.push({type:"gap",direction:"center_vertical",gap:h,offset:f});continue}let p=h.startBounds.top-l,b=he(p-h.length);if(Math.abs(b)<=t.y){Math.abs(b)<t.y&&(o.length=0),t.y=Math.abs(b),o.push({type:"gap",direction:"side_top",gap:h,offset:b});continue}let x=he(s-h.endBounds.bottom),g=h.length-x;if(Math.abs(g)<=t.y){Math.abs(g)<t.y&&(o.length=0),t.y=Math.abs(g),o.push({type:"gap",direction:"side_bottom",gap:h,offset:g});continue}}},am=n=>{let e=new Map;for(let t of n){let r=`${he(t.x)},${he(t.y)}`;e.has(r)||e.set(r,t)}return Array.from(e.values())},hm=(n,e)=>{let t={},r={};for(let s of n){if(s.type!=="point")continue;let a=String(he(s.points[0].x));t[a]||(t[a]=[]),t[a].push(...s.points.map(l=>({x:he(l.x),y:he(l.y)})))}for(let s of e){if(s.type!=="point")continue;let a=String(he(s.points[0].y));r[a]||(r[a]=[]),r[a].push(...s.points.map(l=>({x:he(l.x),y:he(l.y)})))}let o=Object.entries(t).map(([s,a])=>({type:"points",points:am(a.map(l=>({x:Number(s),y:l.y})).sort((l,u)=>l.y-u.y))})),i=Object.entries(r).map(([s,a])=>({type:"points",points:am(a.map(l=>({x:l.x,y:Number(s)})).sort((l,u)=>l.x-u.x))}));return[...o,...i]},i0=n=>{let e=new Map;for(let t of n){let r=[t.points[0],t.points[1]].flatMap(o=>[he(o.x),he(o.y)]).join(",");e.has(r)||e.set(r,t)}return Array.from(e.values())},s0=(n,e)=>{let{left:t,top:r,right:o,bottom:i}=n,s=[];for(let a of e){let l=a.gap.startBounds,u=a.gap.endBounds,c=Xs([r,i],a.gap.overlap),h=Xs([t,o],a.gap.overlap);switch(a.direction){case"center_horizontal":{if(c){let d=(c[0]+c[1])/2;s.push({type:"gap",direction:"horizontal",points:[{x:a.gap.startSide[0].x,y:d},{x:t,y:d}]},{type:"gap",direction:"horizontal",points:[{x:o,y:d},{x:a.gap.endSide[0].x,y:d}]})}break}case"center_vertical":{if(h){let d=(h[0]+h[1])/2;s.push({type:"gap",direction:"vertical",points:[{x:d,y:a.gap.startSide[0].y},{x:d,y:r}]},{type:"gap",direction:"vertical",points:[{x:d,y:i},{x:d,y:a.gap.endSide[0].y}]})}break}case"side_right":{if(c){let d=(c[0]+c[1])/2;s.push({type:"gap",direction:"horizontal",points:[{x:l.right,y:d},{x:u.left,y:d}]},{type:"gap",direction:"horizontal",points:[{x:u.right,y:d},{x:t,y:d}]})}break}case"side_left":{if(c){let d=(c[0]+c[1])/2;s.push({type:"gap",direction:"horizontal",points:[{x:o,y:d},{x:l.left,y:d}]},{type:"gap",direction:"horizontal",points:[{x:l.right,y:d},{x:u.left,y:d}]})}break}case"side_top":{if(h){let d=(h[0]+h[1])/2;s.push({type:"gap",direction:"vertical",points:[{x:d,y:i},{x:d,y:l.top}]},{type:"gap",direction:"vertical",points:[{x:d,y:l.bottom},{x:d,y:u.top}]})}break}case"side_bottom":{if(h){let d=(h[0]+h[1])/2;s.push({type:"gap",direction:"vertical",points:[{x:d,y:l.bottom},{x:d,y:u.top}]},{type:"gap",direction:"vertical",points:[{x:d,y:u.bottom},{x:d,y:r}]})}break}}}return i0(s.map(a=>({...a,points:[{x:he(a.points[0].x),y:he(a.points[0].y)},{x:he(a.points[1].x),y:he(a.points[1].y)}]})))},dm=(n,e,t,r,o,i)=>{let s=(x,g,y)=>{"byLeft"in r?r0(x,r,l,g,y):o0(x,r,l,g,y)},a=Ic(e),l={x:o,y:o},u=[],c=[];i?sm(n,i,o,o,l,u,c):zs(n,t,l,u,c),s(a,u,c);let h={x:he(u[0]?.offset??0),y:he(c[0]?.offset??0)},d=n.map(x=>_c({x:x.x+h.x,y:x.y+h.y})),f=Ic({left:a.left+h.x,top:a.top+h.y,right:a.right+h.x,bottom:a.bottom+h.y});l.x=0,l.y=0,u.length=0,c.length=0,i?sm(d,i,0,0,l,u,c):zs(d,t,l,u,c),s(f,u,c);let m=hm(u,c),p=[...u,...c].filter(x=>x.type==="gap"),b=s0(f,p);return{snapOffset:h,pointSnapLines:m,gapSnapLines:b}},fm=(n,e,t)=>{let r={x:t,y:t},o=[],i=[];zs(n,e,r,o,i);let s={x:he(o[0]?.offset??0),y:he(i[0]?.offset??0)};r.x=0,r.y=0,o.length=0,i.length=0;let a=n.map(u=>_c({x:u.x+s.x,y:u.y+s.y}));zs(a,e,r,o,i);let l=hm(o,i);return{snapOffset:s,pointSnapLines:l}};var a0=200,mm=8,l0=1,c0=3,u0=8,h0=ee("#F68066"),pm=new Set(["WorkSpaceClipType","WorkSpaceSafeType","WorkSpaceMaskType","WorkSpaceLineType","WorkSpaceShadowType"]),d0="WorkSpaceDrawType",Xr=n=>({left:Math.min(n.tl.x,n.tr.x,n.br.x,n.bl.x),top:Math.min(n.tl.y,n.tr.y,n.br.y,n.bl.y),right:Math.max(n.tl.x,n.tr.x,n.br.x,n.bl.x),bottom:Math.max(n.tl.y,n.tr.y,n.br.y,n.bl.y)}),bm=(n,e)=>!(Xr(n).right<e.minX||Xr(n).left>e.maxX||Xr(n).bottom<e.minY||Xr(n).top>e.maxY),f0=n=>({x:(n.tl.x+n.br.x)/2,y:(n.tl.y+n.br.y)/2}),Us=class{constructor(e,t=()=>!1){this.host=e;this.enabled=t}host;enabled;pointSnapLines=[];gapSnapLines=[];lastSnapOffset={x:0,y:0};activeType="";pendingMove=!1;gestureKey="";viewportSignature="";referenceCoords=[];referencePoints=[];axisIndex=null;gapIndex=null;scalingKey="";scalingPoints=[];workspaceResolved=!1;workspacePointKeys=new Set;workspaceBounds;get info(){return{pending:this.pendingMove,offset:{...this.lastSnapOffset},pointLines:this.pointSnapLines.length,gapLines:this.gapSnapLines.length,candidates:this.referenceCoords.length,activeType:this.activeType}}registerMove(e){this.enabled()&&(this.clearLines(),this.activeType=e.raw.type,this.ensureMoveCaches(),this.pendingMove=!0)}settleMoveSnap(){if(!this.pendingMove||(this.pendingMove=!1,!this.enabled()))return;let e=this.host.document;if(e.groupEditing&&e.activeGroupChild){this.clearLines();return}let t=e.selection;if(!t.length||!this.referenceCoords.length||!this.referencePoints.length||!this.gapIndex){this.clearLines();return}let r=et(e);if(!r){this.clearLines();return}let o={tl:r.quad.tl,tr:r.quad.tr,br:r.quad.br,bl:r.quad.bl,c:f0(r.quad)},i=mm/this.host.zoom,{snapOffset:s,pointSnapLines:a,gapSnapLines:l}=dm(Ys(o),Xr(o),this.referencePoints,this.gapIndex,i,this.axisIndex??void 0);if(s.x!==0||s.y!==0){for(let c of t)e.setProps(c,{left:(c.raw.left??0)+s.x,top:(c.raw.top??0)+s.y},{deferIndexRebuild:!0});let u=e.selectionFrame;u&&e.setSelectionFrame({...u,center:{x:u.center.x+s.x,y:u.center.y+s.y}})}this.lastSnapOffset={...s},this.pointSnapLines=a,this.gapSnapLines=l}registerScaling(e,t){if(!this.enabled()||e.typeKey===L.CIRCLE)return;this.clearLines(),this.activeType=e.raw.type;let r=this.host.document;this.ensureScalingCaches();let o=et(r);if(!o||!this.scalingPoints.length)return;let s=(is(t)?[t]:[...Xl]).map(u=>({x:o.quad[u].x,y:o.quad[u].y})),a=mm/this.host.zoom,{pointSnapLines:l}=fm(s,this.scalingPoints,a);this.pointSnapLines=l,this.gapSnapLines=[]}finishGesture(){this.settleMoveSnap(),this.clearLines(),this.activeType="",this.gestureKey="",this.viewportSignature="",this.referenceCoords=[],this.referencePoints=[],this.axisIndex=null,this.gapIndex=null,this.scalingKey="",this.scalingPoints=[],this.workspaceResolved=!1,this.workspacePointKeys.clear(),this.workspaceBounds=void 0}buildOverlay(e){if(this.activeType==="ReferenceLine")return[];if(!this.pointSnapLines.length&&!this.gapSnapLines.length)return[];let t=[],r=l0/e,o=(i,s)=>t.push(Re(i,s,r,h0));this.ensureWorkspaceInfo();for(let i of this.pointSnapLines){let s=i.points;if(!s.length)continue;if(!!this.workspaceBounds&&s.some(u=>this.workspacePointKeys.has(`${he(u.x)},${he(u.y)}`))&&this.workspaceBounds){let u=this.workspaceBounds,c=s.every(d=>d.x===s[0].x),h=s.every(d=>d.y===s[0].y);c&&o({x:s[0].x,y:Math.min(s[0].y,u.top)},{x:s[0].x,y:Math.max(s[s.length-1].y,u.bottom)}),h&&o({x:Math.min(s[0].x,u.left),y:s[0].y},{x:Math.max(s[s.length-1].x,u.right),y:s[0].y})}else s.length>=2&&o(s[0],s[s.length-1]);let l=c0/e;for(let u of s)o({x:u.x-l,y:u.y-l},{x:u.x+l,y:u.y+l}),o({x:u.x+l,y:u.y-l},{x:u.x-l,y:u.y+l})}for(let i of this.gapSnapLines){let[s,a]=i.points,l=u0/e,u=l/2,c=l/4;if(i.direction==="horizontal"){let h=s.y,d=(s.x+a.x)/2;o({x:s.x,y:h-l},{x:s.x,y:h+l}),o({x:d-c,y:h-u},{x:d-c,y:h+u}),o({x:d+c,y:h-u},{x:d+c,y:h+u}),o({x:a.x,y:h-l},{x:a.x,y:h+l}),o(s,a)}else{let h=s.x,d=(s.y+a.y)/2;o({x:h-l,y:s.y},{x:h+l,y:s.y}),o({x:h-u,y:d-c},{x:h+u,y:d-c}),o({x:h-u,y:d+c},{x:h+u,y:d+c}),o({x:h-l,y:a.y},{x:h+l,y:a.y}),o(s,a)}}return t}clearLines(){this.pointSnapLines=[],this.gapSnapLines=[]}keyCacheSelection=null;keyCacheValue="";ensureMoveCaches(){let e=this.host.document,t=e.selection;this.keyCacheSelection!==t&&(this.keyCacheSelection=t,this.keyCacheValue=t.map(l=>l.id).join("|"));let r=this.keyCacheValue,o=this.getViewportRect(),i=o?.signature??"";if(this.gestureKey===r&&this.referenceCoords.length&&this.viewportSignature===i)return;this.gestureKey=r,this.viewportSignature=i;let s=new Set(t),a=o?.rect;this.referenceCoords=[];for(let l of e.nodes){if(!l.visible||s.has(l)||pm.has(l.id))continue;let u=this.nodeCoords(l);a&&!bm(u,a)||this.referenceCoords.push(u)}this.referencePoints=cm(this.referenceCoords),this.axisIndex=lm(this.referencePoints),this.gapIndex=um(this.referenceCoords.map(Xr))}ensureScalingCaches(){let e=this.host.document,t=e.selection.map(s=>s.id).join("|");if(this.scalingKey===t&&this.scalingPoints.length)return;this.scalingKey=t;let r=new Set(e.selection),o=this.getViewportRect()?.rect,i=[];for(let s of e.nodes){if(!s.visible||r.has(s)||pm.has(s.id))continue;let a=this.nodeCoords(s);o&&!bm(a,o)||i.push(...Ys(a))}this.scalingPoints=i}ensureWorkspaceInfo(){if(this.workspaceResolved)return;this.workspaceResolved=!0;let e=this.host.document.nodes.find(o=>o.id===d0);if(!e)return;let t=e.aCoords,r=e.center;for(let o of[t.tl,t.tr,t.br,t.bl,r])this.workspacePointKeys.add(`${he(o.x)},${he(o.y)}`);this.workspaceBounds=e.bounds}nodeCoords(e){let t=e.aCoords,r=e.center;return{tl:{x:t.tl.x,y:t.tl.y},tr:{x:t.tr.x,y:t.tr.y},br:{x:t.br.x,y:t.br.y},bl:{x:t.bl.x,y:t.bl.y},c:{x:r.x,y:r.y}}}getViewportRect(){let e=this.host.viewportTransform,t=e[0];if(!t||!Number.isFinite(t))return;let{width:r,height:o}=this.host.viewSize,i={x:(0-e[4])/e[0],y:(0-e[5])/e[3]},s={x:(r-e[4])/e[0],y:(o-e[5])/e[3]},a=a0/t;return{rect:{minX:Math.min(i.x,s.x)-a,minY:Math.min(i.y,s.y)-a,maxX:Math.max(i.x,s.x)+a,maxY:Math.max(i.y,s.y)+a},signature:`${e[0]},${e[1]},${e[2]},${e[3]},${e[4]},${e[5]}`}}};var xm=n=>{let e=n?.animates;return Array.isArray(e)?e.filter(t=>!!t&&typeof t=="object"&&typeof t.key=="string"):[]},m0={width:0,height:0},be=(n,e={})=>({originX:"center",originY:"center",left:n.center.x,top:n.center.y,...e}),Bt=(n,e,t=m0,r={})=>e==="left"?be(n,{left:-n.width/2,...r}):e==="right"?be(n,{left:t.width+n.width/2,...r}):e==="top"?be(n,{top:-n.height/2,...r}):be(n,{top:t.height+n.height/2,...r}),p0=[{key:"left-swipe-entry",name:"左滑入场",category:"entrance",getStartState:n=>Bt(n,"left"),getEndState:n=>be(n)},{key:"right-swipe-entry",name:"右滑入场",category:"entrance",getStartState:(n,e)=>Bt(n,"right",e),getEndState:n=>be(n)},{key:"top-swipe-entry",name:"上滑入场",category:"entrance",getStartState:(n,e)=>Bt(n,"bottom",e),getEndState:n=>be(n)},{key:"bottom-swipe-entry",name:"下滑入场",category:"entrance",getStartState:n=>Bt(n,"top"),getEndState:n=>be(n)},{key:"smash-off",name:"砸落",category:"entrance",getStartState:n=>be(n,{scaleX:n.scaleX*2.5,scaleY:n.scaleY*2.5}),getEndState:n=>be(n,{scaleX:n.scaleX,scaleY:n.scaleY})},{key:"gradually-display",name:"渐显",category:"entrance",getStartState:n=>be(n,{scaleX:n.scaleX*.01,scaleY:n.scaleY*.01,opacity:.01}),getEndState:n=>be(n,{scaleX:n.scaleX,scaleY:n.scaleY,opacity:1})},{key:"pop-up",name:"弹出",category:"entrance",getStartState:n=>be(n,{scaleX:n.scaleX*.01,scaleY:n.scaleY*.01}),getEndState:n=>be(n,{scaleX:n.scaleX*1.3,scaleY:n.scaleY*1.3})},{key:"flip-horizontal-entry",name:"水平翻转",category:"entrance",getStartState:n=>be(n,{scaleX:n.scaleX*.01}),getEndState:n=>be(n,{scaleX:n.scaleX})},{key:"flip-vertical-entry",name:"垂直翻转",category:"entrance",getStartState:n=>be(n,{scaleY:n.scaleY*.01}),getEndState:n=>be(n,{scaleY:n.scaleY})},{key:"rotate-entry",name:"旋入",category:"entrance",getStartState:n=>be(n,{angle:n.angle-720,scaleX:n.scaleX*.01,scaleY:n.scaleY*.01}),getEndState:n=>be(n,{angle:n.angle,scaleX:n.scaleX,scaleY:n.scaleY})}],b0=[{key:"left-swipe-exit",name:"左滑退场",category:"exit",getStartState:n=>be(n),getEndState:n=>Bt(n,"left")},{key:"right-swipe-exit",name:"右滑退场",category:"exit",getStartState:n=>be(n),getEndState:(n,e)=>Bt(n,"right",e)},{key:"top-swipe-exit",name:"上滑退场",category:"exit",getStartState:n=>be(n),getEndState:n=>Bt(n,"top")},{key:"bottom-swipe-exit",name:"下滑退场",category:"exit",getStartState:n=>be(n),getEndState:(n,e)=>Bt(n,"bottom",e)},{key:"fade-out",name:"渐隐",category:"exit",getStartState:n=>be(n,{scaleX:n.scaleX,scaleY:n.scaleY,opacity:1}),getEndState:n=>be(n,{scaleX:n.scaleX*.01,scaleY:n.scaleY*.01,opacity:.01})},{key:"flip-horizontal-exit",name:"水平翻转",category:"exit",getStartState:n=>be(n,{scaleX:n.scaleX}),getEndState:n=>be(n,{scaleX:n.scaleX*.01})},{key:"flip-vertical-exit",name:"垂直翻转",category:"exit",getStartState:n=>be(n,{scaleY:n.scaleY}),getEndState:n=>be(n,{scaleY:n.scaleY*.01})},{key:"rotate-exit",name:"旋出",category:"exit",getStartState:n=>be(n,{angle:n.angle-720,scaleX:n.scaleX,scaleY:n.scaleY}),getEndState:n=>be(n,{angle:n.angle+720,scaleX:n.scaleX*.01,scaleY:n.scaleY*.01})}],x0=[{key:"subtitle-scroll",name:"字幕滚动",category:"emphasis",getStartState:(n,e)=>Bt(n,"right",e),getEndState:n=>Bt(n,"left")},{key:"flip-horizontal",name:"水平翻转",category:"emphasis",getStartState:n=>be(n,{scaleX:n.scaleX}),getEndState:n=>be(n,{scaleX:-n.scaleX})},{key:"flip-vertical",name:"垂直翻转",category:"emphasis",getStartState:n=>be(n,{scaleY:n.scaleY}),getEndState:n=>be(n,{scaleY:-n.scaleY})}],g0=[...p0,...b0,...x0],Dc=new Map(g0.map(n=>[n.key,n])),y0=n=>Dc.get(n),$s=n=>{let e=Dc.get(n);return e?e.category==="entrance"?0:e.category==="emphasis"?1:2:Number.MAX_SAFE_INTEGER},gm=n=>$s(n)===1,S0=n=>{let e=n.duration??0;return!gm(n.key)||!n.single?e:Math.floor(e/n.single)*n.single},v0=n=>{let e=[...n].sort((r,o)=>{let i=$s(r.key)-$s(o.key);return i!==0?i:$s(r.key)===Number.MAX_SAFE_INTEGER?(r.startTime??0)-(o.startTime??0):0}),t=0;return e.map(r=>{let o={...r,startTime:Number(t.toFixed(3))};return t+=r.duration??0,o})},ym=.2,Sm=(n,e)=>{let t=[];for(let s of n)for(let a of v0(s.animates??[]))t.push({target:s.target,view:s.view,animate:a});t.sort((s,a)=>(s.animate.startTime??0)-(a.animate.startTime??0));let r=[],o=0,i=0;for(let s of t){let a=s.animate.startTime??0,l=Math.max(0,a-i),u=o+l,c=S0(s.animate),h=u+ym,d=h+c;r.push({target:s.target,animate:s.animate,definition:Dc.get(s.animate.key)??null,view:s.view,waitTime:l,invokeTime:u,motionStart:h,motionEnd:d,playbackDuration:c}),o=d,i=a+(s.animate.duration??0)}return{timeline:r,duration:r[r.length-1]?.motionEnd??0,ws:e}},Fc=(n,e)=>{let t=new Map;for(let o of e.timeline){let i=t.get(o.target);i?i.push(o):t.set(o.target,[o])}let r=[];return t.forEach((o,i)=>{let s=o.find(f=>n>=f.invokeTime&&n<f.motionEnd);if(!s||!s.definition){r.push({target:i,override:null});return}if(n<s.motionStart){r.push({target:i,override:s.definition.getStartState(s.view,e.ws)});return}let a=n-s.motionStart,l=s.animate,u=s.playbackDuration>0?s.playbackDuration:1,c;gm(l.key)&&l.single&&l.single>0?c=a%l.single/l.single:c=a/u,c=Math.min(Math.max(c,0),1);let h=s.definition.getStartState(s.view,e.ws),d=s.definition.getEndState(s.view,e.ws);r.push({target:i,override:vm(l.key,h,d,c)})}),r},vm=(n,e,t,r)=>{let o={};for(let i of Object.keys(t)){let s=e[i],a=t[i];if(typeof s=="number"&&typeof a=="number"){let l;n==="smash-off"&&(i==="scaleX"||i==="scaleY")?l=s-(s-a)*r:l=s+(a-s)*r,o[i]=Number(l.toFixed(3))}else o[i]=r<.5?s:a}for(let i of Object.keys(e))i in o||(o[i]=e[i]);return o},w0=n=>1-Math.cos(Math.min(Math.max(n,0),1)*Math.PI/2),wm=(n,e,t)=>{let r=y0(t.key);if(!r)return null;let o=t.duration??0,i=t.single&&t.single>0?t.single:void 0,s=r.category==="emphasis",a=s&&i?Math.floor(o/i):1,l=s&&i?i:o;return{key:t.key,definition:r,view:n,ws:e,delay:ym,loopDuration:l,loopCount:a}},Oc=(n,e)=>{if(n<0)return{override:e.definition.getStartState(e.view,e.ws),done:!1};if(n<e.delay)return{override:e.definition.getStartState(e.view,e.ws),done:!1};let t=n-e.delay,r=e.loopCount*e.loopDuration;if(t>=r)return{override:null,done:!0};let o=e.loopDuration>0?Math.floor(t/e.loopDuration):0,i=e.loopDuration>0?t-o*e.loopDuration:0,s=e.loopDuration>0?i/e.loopDuration:1,a=e.definition.getStartState(e.view,e.ws),l=e.definition.getEndState(e.view,e.ws);return{override:vm(e.key,a,l,w0(s)),done:!1}},js=n=>n.scrollSpeed?(n.textTotalWidth+n.viewWidth)/n.scrollSpeed:0,T0=(n,e,t)=>{if(e<=0)return 0;let r=Math.max(n,0);return t==="loop"?r%e:Math.min(r,e)},Tm=(n,e,t="loop")=>{if(!n.scrollEnabled)return 0;let r=js(n);if(r<=0)return 0;let o=T0(e,r,t)/r,i=n.textTotalWidth+n.viewWidth;return n.scrollDirection==="left-to-right"?o*i:-o*i},Uo=class{_state="idle";_time=0;anchorNow=0;anchorTime=0;_trackDuration;constructor(e){this._trackDuration=e}get trackDuration(){return this._trackDuration}retargetDuration(e){this._trackDuration=e,this._time>e&&(this._time=e)}get state(){return this._state}get time(){return this._time}play(e){this._state==="idle"||this._state==="ended"?(this._time=0,this.anchorTime=0):this.anchorTime=this._time,this.anchorNow=e,this._state="playing"}pause(e){this._state==="playing"&&(this.syncTime(e),this._state=this._time>=this.trackDuration?"ended":"paused")}seek(e,t){this._time=Math.min(Math.max(t,0),this.trackDuration),this.anchorNow=e,this.anchorTime=this._time,this._state=this._time>=this.trackDuration?"ended":"paused"}stop(){this._state="idle",this._time=0,this.anchorNow=0,this.anchorTime=0}tick(e){return this._state==="idle"?null:(this._state==="playing"&&this.syncTime(e),{time:this._time,playing:this._state==="playing"})}syncTime(e){let t=(e-this.anchorNow)/1e3;this._time=Math.min(Math.max(this.anchorTime+t,0),this.trackDuration),this._time>=this.trackDuration&&(this._state="ended")}},Bc=(n,e)=>Math.max(n,...e,0);var Vs=class{constructor(e){this.host=e}host;playback=null;player=null;totalDuration=0;overridesActive=!1;previews=new Map;previewOverridesActive=!1;reset(){this.playback=null,this.player=null,this.totalDuration=0,this.overridesActive=!1,this.previews.clear(),this.previewOverridesActive=!1}play(){this.cancelPreviews(),this.rebuild();let e=[...this.collectMediaDurations(),...this.collectScrollTextDurations()];this.totalDuration=Bc(this.playback?.duration??0,e),this.player?this.player.retargetDuration(this.totalDuration):this.player=new Uo(this.totalDuration),this.player.play(performance.now());for(let t of this.host.document.nodes)t instanceof ie?t.play():t instanceof ae&&t.playClipMedia();this.syncVideosToTime(this.player.time,!0),this.applyScrollTextOffsets(this.player.time),this.host.requestRenderAll()}pause(){this.player?.pause(performance.now());for(let e of this.host.document.nodes)e instanceof ie?e.pause():e instanceof ae&&e.pauseClipMedia();this.host.requestRenderAll()}stop(){this.cancelPreviews(),this.player?.stop(),this.clearOverrides();for(let{node:e}of this.scrollTextTracks())e.setScrollOffset(0);for(let e of this.host.document.nodes)e instanceof ie?e.stop():e instanceof ae&&e.syncClipMediaToTime(0,!1);this.host.requestRenderAll()}seek(e){if(this.cancelPreviews(),!this.player){this.rebuild();let t=[...this.collectMediaDurations(),...this.collectScrollTextDurations()];this.totalDuration=Bc(this.playback?.duration??0,t),this.player=new Uo(this.totalDuration)}this.player.seek(performance.now(),e),this.applyAnimationTime(this.player.time),this.applyScrollTextOffsets(this.player.time),this.syncVideosToTime(this.player.time,!1),this.host.requestRenderAll()}get info(){return!this.player&&!this.playback?null:{state:this.player?.state??"idle",time:this.player?.time??0,duration:this.totalDuration,animatedCount:this.playback?.timeline.length??0}}playSingleAnimation(e,t,r){let o=wm(this.targetView(e),this.workspaceView(),t);if(!o)return!1;this.stopSingleAnimation(e);let i={target:e,plan:o,startAt:performance.now(),onComplete:r};this.previews.set(e,i);let s=Oc(0,o);return e.setAnimationOverride(s.override),(s.override||this.previewOverridesActive)&&this.host.document.refreshHitIndex(),this.previewOverridesActive=!!s.override,this.host.requestRenderAll(),!0}stopSingleAnimation(e){let t=e?this.previews.has(e)?[e]:[]:[...this.previews.keys()];if(t.length){for(let r of t)this.previews.delete(r),r.setAnimationOverride(null);this.previewOverridesActive&&this.host.document.refreshHitIndex(),this.previewOverridesActive=!1,this.host.requestRenderAll()}}get singlePreviewInfo(){let e=performance.now();return[...this.previews.values()].map(t=>{let r=(e-t.startAt)/1e3,o=t.plan.loopCount*t.plan.loopDuration;return{nodeId:t.target.id,key:t.plan.key,elapsed:r,duration:t.plan.delay+o,state:r<t.plan.delay?"delay":r<t.plan.delay+o?"playing":"done"}})}tick(e){let t=this.player,r=t?t.tick(e):null;r&&(this.applyAnimationTime(r.time),this.applyScrollTextOffsets(r.time));let o=this.tickPreviews(e);return!!r?.playing||o}tickPreviews(e){if(!this.previews.size)return!1;let t=!1,r=!1;for(let o of[...this.previews.values()]){let i=(e-o.startAt)/1e3,s=Oc(i,o.plan);o.target.setAnimationOverride(s.override),s.override&&(r=!0),s.done?(this.previews.delete(o.target),o.onComplete?.()):t=!0}return(r||this.previewOverridesActive)&&this.host.document.refreshHitIndex(),this.previewOverridesActive=r,t}cancelPreviews(){this.previews.size&&this.stopSingleAnimation()}get scrollTextInfo(){return this.scrollTextTracks().map(({node:e,input:t})=>({id:e.id,offset:e.scrollOffset,duration:js(t),viewWidth:t.viewWidth,textTotalWidth:t.textTotalWidth,speed:t.scrollSpeed,direction:t.scrollDirection,enabled:t.scrollEnabled}))}applyAnimationTime(e){if(!this.playback)return;let t=!1;for(let{target:r,override:o}of Fc(e,this.playback))r.setAnimationOverride(o),o&&(t=!0);(t||this.overridesActive)&&this.host.document.refreshHitIndex(),this.overridesActive=t}clearOverrides(){if(this.playback){for(let{target:e}of Fc(0,this.playback))e.setAnimationOverride(null);this.host.document.refreshHitIndex(),this.overridesActive=!1}}rebuild(){let e=[];for(let t of this.host.document.nodes){let r=xm(t.raw);r.length&&e.push({target:t,view:this.targetView(t),animates:r})}this.playback=Sm(e,this.workspaceView())}targetView(e){let t=e.raw.scaleX??1,r=e.raw.scaleY??1,o=e.dims;return{left:e.raw.left??0,top:e.raw.top??0,scaleX:t,scaleY:r,angle:e.raw.angle??0,opacity:e.raw.opacity??1,width:o.x*t,height:o.y*r,center:Yt({...e.raw,width:o.x,height:o.y})}}workspaceView(){for(let e of this.host.document.nodes)if(e.raw.id===yn)return{width:e.dims.x*(e.raw.scaleX??1),height:e.dims.y*(e.raw.scaleY??1)};return{width:0,height:0}}scrollTextTracks(){let e=[];for(let t of this.host.document.nodes){if(!(t instanceof Se))continue;let r=Ih(t);r&&e.push({node:t,input:r})}return e}collectScrollTextDurations(){return this.scrollTextTracks().map(({input:e})=>e.scrollEnabled?js(e):0)}applyScrollTextOffsets(e){for(let{node:t,input:r}of this.scrollTextTracks())t.setScrollOffset(Tm(r,e,"loop"))}collectMediaDurations(){let e=[],t=r=>{for(let o of r)o instanceof ie?e.push(o.mediaDuration):o instanceof ae?o.clipMediaDuration>0&&e.push(o.clipMediaDuration):o instanceof J&&t(o.children)};return t(this.host.document.nodes),e}syncVideosToTime(e,t){let r=o=>{for(let i of o)i instanceof ie?i.syncVideoToTime(e,t):i instanceof ae?i.syncClipMediaToTime(e,t):i instanceof J&&r(i.children)};r(this.host.document.nodes)}};var Em=14,Cm=n=>n.fontFamily||"仓耳小丸子",qs=class{host;session=null;offDocEvents;disposed=!1;constructor(e){this.host=e;let t=e.document.events,r=[t.on("text:changed",o=>this.onTextChanged(o)),t.on("text:editing:exited",()=>this.finish()),t.on("object:removed",o=>this.onOverlayRemoved(o))];this.offDocEvents=()=>r.forEach(o=>o())}dispose(){this.disposed||(this.disposed=!0,this.offDocEvents())}get active(){return this.session!==null}isOverlay(e){return this.session?.overlay===e}get info(){let e=this.session;return e?{tableId:e.table.id,row:e.row,col:e.col,text:e.overlay.raw.text??""}:null}startEditing(e,t,r,o={}){let i=this.host.document;if(!i.nodes.includes(e))return!1;let s=lt(e.cellMap,t,r),a=e.cellBounds(s.row,s.col);if(!a)return!1;i.editingNode&&i.exitEditing(),e.rebuildTable();let l=JSON.stringify(e.toObject()),u=e.raw,c=u.cellPadding??8,h=we(e.cellMap,s.row,s.col),d=e.cellSceneCenter(s.row,s.col),f={type:"textbox",id:`${e.id}-cell-edit`,text:o.initialText??h?.text??"",left:d.x,top:d.y,width:Math.max(0,a.width-c*2),originX:"center",originY:"center",scaleX:u.scaleX??1,scaleY:u.scaleY??1,angle:e.tableAngle,fill:h?.textFill??u.textFill,fontSize:h?.fontSize??Em,fontWeight:h?.fontWeight,fontStyle:h?.fontStyle,fontFamily:h?.fontFamily||Cm(u),textAlign:h?.textAlign??fe.CENTER,lineHeight:1.16,splitByGrapheme:!0,opacity:1,visible:!0},m=new Se(f);if(e.editingCell=s,e.clearCellInteractionState(),this.session={overlay:m,table:e,row:s.row,col:s.col,snapshot:l,data:h??null},i.add(m),e.rebuildTable(),(i.selection.length!==1||i.selection[0]!==e)&&i.setSelection([e],"update"),i.enterEditing(m,{transient:!0}),o.initialText===void 0){let p=m.textLayout.graphemeCodeUnitOffsets.length-1;this.host.setEditingSelection(0,p)}return this.host.requestRenderAll(),!0}onTextChanged(e){let t=this.session;if(!t||e!==t.overlay)return;if(!t.data){let o=Array.isArray(t.table.raw.cellData)?t.table.raw.cellData:t.table.raw.cellData=[];t.data={row:t.row,col:t.col,fill:t.table.raw.cellFill,stroke:t.table.raw.cellStroke,text:"",textFill:t.table.raw.textFill,fontSize:Em,fontWeight:"normal",fontStyle:"normal",fontFamily:Cm(t.table.raw),textAlign:"center"},o.push(t.data)}t.data.text=e.raw.text??"",t.table.rebuildTable();let r=t.table.cellSceneCenter(t.row,t.col);r&&e.set({left:r.x,top:r.y}),this.host.requestRenderAll()}finish(){let e=this.session;if(!e)return;this.session=null;let t=this.host.document;if(e.table.editingCell=null,t.remove(e.overlay),e.table.rebuildTable(),t.setSelection([e.table],"create"),e.table.setCellSelection([{row:e.row,col:e.col}],{row:e.row,col:e.col},{r1:e.row,r2:e.row,c1:e.col,c2:e.col}),JSON.stringify(e.table.toObject())!==e.snapshot){let r=new Map;r.set(e.table,JSON.parse(e.snapshot)),t.applyTransform([e.table],()=>({}),"modified",{action:Le.tableCellEdit,before:r})}this.host.requestRenderAll()}onOverlayRemoved(e){let t=this.session;!t||e!==t.overlay||(this.session=null,t.table.editingCell=null,t.table.rebuildTable(),this.host.requestRenderAll())}};var E0=530,Mm=[.1,.1,.1,1],C0=[.18,.44,.96,.3],Ks=class{host;textarea=null;blinkTimer=null;caretVisible=!0;onSelectionChange=null;offDocEvents;inComposition=!1;compositionRange=null;constructor(e){this.host=e;let t=e.document.events,r=[t.on("text:changed",()=>{this.positionAtCaret(),this.host.requestRenderAll()}),t.on("text:editing:entered",()=>this.startUi()),t.on("text:editing:exited",()=>this.stopUi())];this.offDocEvents=()=>r.forEach(o=>o())}get composing(){return this.inComposition}enterEditingAtClick(e,t,r){let o=this.host.document.editingNode===e;if(this.host.document.enterEditing(e),!o){let u=e.textLayout.graphemeCodeUnitOffsets.length-1;this.setSelection(0,u);return}let i=e.localPoint(t,r),s=e.cursorIndexAt(i.x,i.y),[a,l]=e.wordBoundsAt(s);this.setSelection(a,l)}setSelection(e,t){let r=this.host.document.editingNode;if(!r)return;this.host.document.editSelection.start=e,this.host.document.editSelection.end=t;let o=this.textarea;if(o){let i=r.textLayout.graphemeCodeUnitOffsets,s=i[Math.min(e,i.length-1)]??0,a=i[Math.min(t,i.length-1)]??0;o.setSelectionRange(Math.min(s,a),Math.max(s,a))}this.caretVisible=!0,this.positionAtCaret(),this.focusTextarea(),this.host.requestRenderAll()}buildOverlay(){let e=this.host.document.editingNode;if(!e)return[];let t=e.textLayout,r=this.host.document.editSelection,o=Math.min(r.start,r.end),i=Math.max(r.start,r.end),s=e.matrix,a=Math.hypot(s[0],s[1])||1,l=[];for(let u of t.lines){let c=u.styleMap.flatStart,h=c+u.graphemes.length,d=Math.max(o,c),f=Math.min(i,h);if(f>d){let m=-t.width/2+u.leftOffset,p=m+(d<h?u.boxes[d-c].left:un(u)),b=m+(f<h?u.boxes[f-c].left:un(u));if(b>p){let x=e.contentTopY+u.top;l.push({matrix:V(s,[1,0,0,1,(p+b)/2,x+u.implHeight/2]),dims:{x:b-p,y:u.implHeight},color:C0})}}}if(o===i&&this.caretVisible&&!this.inComposition){let u=e.cursorCoord(o);if(u){let c=2/this.host.zoom/a;l.push({matrix:V(s,[1,0,0,1,u.x+c/2,u.y+u.height/2]),dims:{x:c,y:u.height},color:Mm})}}if(this.inComposition&&this.compositionRange){let u=this.compositionRange.start,c=this.compositionRange.end,h=t.lines.find(d=>{let f=d.styleMap.flatStart;return u>=f&&u<=f+d.graphemes.length});if(h){let d=h.styleMap.flatStart,f=-t.width/2+h.leftOffset,m=f+(u-d<h.boxes.length?h.boxes[u-d].left:un(h)),p=f+(c-d<h.boxes.length?h.boxes[c-d].left:un(h)),x=e.contentTopY+h.baseline+e.textStyle.fontSize*.14;l.push({matrix:V(s,[1,0,0,1,(m+p)/2,x]),dims:{x:Math.max(0,p-m),y:1.5/this.host.zoom/a},color:Mm})}}return l}startUi(){let e=this.host.document.editingNode;if(!e)return;let t=this.ensureTextarea();t.value=e.raw.text??"",this.positionAtCaret();let r=t.value.length;t.setSelectionRange(r,r),this.focusTextarea(),this.caretVisible=!0,this.inComposition=!1,this.compositionRange=null,this.blinkTimer!==null&&window.clearInterval(this.blinkTimer),this.blinkTimer=window.setInterval(()=>{this.caretVisible=!this.caretVisible,this.host.requestRenderAll()},E0),this.host.requestRenderAll()}stopUi(){this.blinkTimer!==null&&(window.clearInterval(this.blinkTimer),this.blinkTimer=null),this.textarea?.blur(),this.textarea?.remove(),this.textarea=null,this.host.requestRenderAll()}ensureTextarea(){if(this.textarea)return this.textarea;let e=document.createElement("textarea");return e.setAttribute("data-engine-editing",""),e.autocomplete="off",e.spellcheck=!1,Object.assign(e.style,{position:"absolute",opacity:"0",width:"4px",height:"20px",padding:"0",border:"none",overflow:"hidden",resize:"none",background:"transparent",pointerEvents:"none",zIndex:"0"}),this.host.canvasEl.parentElement?.appendChild(e),e.addEventListener("input",()=>{this.host.document.updateEditingText(e.value,e.selectionStart??0,e.selectionEnd??0)}),e.addEventListener("compositionstart",()=>{this.inComposition=!0,this.caretVisible=!0,this.blinkTimer!==null&&(window.clearInterval(this.blinkTimer),this.blinkTimer=null)}),e.addEventListener("compositionupdate",t=>{let r=t.data??"",i=t.target.selectionStart??0;this.compositionRange={start:i-r.length,end:i},this.positionAtCaret(),this.host.requestRenderAll()}),e.addEventListener("compositionend",()=>{this.inComposition=!1,this.compositionRange=null,this.host.requestRenderAll()}),e.addEventListener("keydown",t=>{if(t.stopPropagation(),t.key==="Escape"){if(this.inComposition)return;t.preventDefault(),this.host.document.exitEditing();return}if(this.inComposition)return;let r=this.navigateKey(t);r&&(t.preventDefault(),e.setSelectionRange(r[0],r[1],r[2]),this.host.document.updateEditingSelection(r[0],r[1]),this.caretVisible=!0,this.positionAtCaret(),this.host.requestRenderAll())}),this.onSelectionChange&&document.removeEventListener("selectionchange",this.onSelectionChange),this.onSelectionChange=()=>{let t=this.textarea;t&&this.host.document.editingNode&&document.activeElement===t&&(this.host.document.updateEditingSelection(t.selectionStart??0,t.selectionEnd??0),this.positionAtCaret(),this.host.requestRenderAll())},document.addEventListener("selectionchange",this.onSelectionChange),this.textarea=e,e}focusTextarea(){this.textarea?.focus({preventScroll:!0})}positionAtCaret(){let e=this.host.document.editingNode,t=this.textarea;if(!e||!t)return;let r=this.host.document.editSelection,o=e.cursorCoord(Math.min(r.start,r.end));if(!o)return;let i=e.matrix,s=i[0]*o.x+i[2]*o.y+i[4],a=i[1]*o.x+i[3]*o.y+i[5],l=this.host.toScreen(s,a),u=this.host.canvasEl.getBoundingClientRect(),c=this.host.canvasEl.parentElement?.getBoundingClientRect()??u;t.style.left=`${u.left-c.left+l.x}px`,t.style.top=`${u.top-c.top+l.y}px`}navigateKey(e){let t=this.host.document.editingNode;if(!t||e.ctrlKey||e.metaKey||e.altKey)return null;let r=t.textLayout,o=r.graphemeCodeUnitOffsets,i=o.length-1,s=this.host.document.editSelection,a=e.shiftKey?Math.max(s.start,s.end):s.end,l=e.shiftKey?Math.min(s.start,s.end):a,u=p=>o[Math.max(0,Math.min(p,i))]??0,c=p=>{for(let b=0;b<r.lines.length;b++){let x=r.lines[b].styleMap.flatStart;if(p<=x+r.lines[b].graphemes.length)return b}return r.lines.length-1},h=(p,b)=>{let x=r.lines[p],g=b-x.styleMap.flatStart;return-r.width/2+x.leftOffset+(g<x.boxes.length?x.boxes[g].left:un(x))},d=(p,b)=>{let x=r.lines[p],g=-r.width/2+x.leftOffset;for(let y=0;y<x.boxes.length;y++)if(b<g+x.boxes[y].left+x.boxes[y].width/2)return x.styleMap.flatStart+y;return x.styleMap.flatStart+x.graphemes.length},f,m;switch(e.key){case"ArrowLeft":f=Math.max(0,a-1),m="backward";break;case"ArrowRight":f=Math.min(i,a+1),m="forward";break;case"Home":case"End":{let p=r.lines[c(a)];f=e.key==="Home"?p.styleMap.flatStart:p.styleMap.flatStart+p.graphemes.length,m=e.key==="Home"?"backward":"forward";break}case"ArrowUp":case"ArrowDown":{let p=c(a),b=e.key==="ArrowUp"?p-1:p+1;if(b<0||b>=r.lines.length)return null;f=d(b,h(p,a)),m=e.key==="ArrowUp"?"backward":"forward";break}default:return null}return e.shiftKey?[u(Math.min(l,f)),u(Math.max(l,f)),m]:[u(f),u(f),"none"]}dispose(){this.offDocEvents(),this.onSelectionChange&&document.removeEventListener("selectionchange",this.onSelectionChange),this.blinkTimer!==null&&window.clearInterval(this.blinkTimer),this.textarea?.remove(),this.textarea=null}};var Rm=(n,e={})=>{let t=n.getContext("webgl2",{alpha:!0,premultipliedAlpha:!0,antialias:!0,stencil:!0,preserveDrawingBuffer:!0,powerPreference:"high-performance"});if(!t)return null;let r=a=>{a.preventDefault(),e.onLost?.()},o=()=>e.onRestored?.();n.addEventListener("webglcontextlost",r),n.addEventListener("webglcontextrestored",o);let i=t.getExtension("WEBGL_debug_renderer_info"),s=i?String(t.getParameter(i.UNMASKED_RENDERER_WEBGL)):"unknown";return{gl:t,capabilities:{maxTextureSize:t.getParameter(t.MAX_TEXTURE_SIZE),maxTextureUnits:t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS),renderer:s},dispose:()=>{n.removeEventListener("webglcontextlost",r),n.removeEventListener("webglcontextrestored",o)}}};var Qs=n=>n.trim().replace(/^['"]|['"]$/g,"").toLowerCase(),Pm=n=>{let e=new Set;for(let t of n){let r=Qs(t?.family??"");r&&e.add(r)}return e},M0=n=>{let e=new Set,t=o=>{if(!(typeof o!="string"||!o))for(let i of o.split(",")){let s=Qs(i);s&&e.add(s)}};t(n.raw.fontFamily);let r=n.raw.styles;if(r&&typeof r=="object"){for(let o of Object.values(r))if(!(!o||typeof o!="object"))for(let i of Object.values(o))i&&typeof i=="object"&&t(i.fontFamily)}return e},km=(n,e)=>{let t=[],r=o=>{for(let i of o)if(i instanceof Se){for(let s of M0(i))if(e.has(s)){t.push(i);break}}else i instanceof J&&r(i.children)};return r(n),t};var Zs=class{constructor(e,t,r,o){this.host=e;this.textRenderer=t;this.glyphAtlas=r;this.renderer=o}host;textRenderer;glyphAtlas;renderer;pendingSettle=new Set;invalidateNodeTextBakes(e){this.host.engineDisposed||(this.textRenderer.invalidateNodeBakes(e),e.markRenderDirty(),this.host.requestRenderAll())}handleFontsLoaded(e){if(this.host.engineDisposed||this.host.engineContextLost)return;let t=Pm(e);t.size===0||!this.invalidateTextCachesFor(t)||(this.glyphAtlas.reset(),this.host.requestRenderAll(),this.host.render())}invalidateTextCachesFor(e){let t=km(this.host.document.nodes,e);if(t.length===0)return!1;for(let r of t)r.invalidateTextLayout(),this.textRenderer.invalidateNodeBakes(r);return oh(),this.renderer.invalidateTextDerivedBakes(),!0}queueSettle(e){if(!(this.host.engineDisposed||e.length===0))for(let t of e)this.pendingSettle.add(t)}consumePendingSettle(){if(this.pendingSettle.size===0)return;let e=new Set(this.pendingSettle);this.pendingSettle.clear(),this.invalidateTextCachesFor(e)}};var Pn=class{_value=0;_lastReason="";get value(){return this._value}get lastReason(){return this._lastReason}bump(e){this._value++,this._lastReason=e}};var pt=1024,R0=2,P0=256,Wt=n=>{let e=[.5,1,2,4];for(let t of e)if(n<=t+1e-6)return t;return e[e.length-1]},k0=256,ea=(n,e)=>{let t=Math.max(6,Math.ceil(n*e)),r=Math.max(k0,Math.ceil(n));return t<=r?{rs:t,scale:e}:{rs:r,scale:r/Math.max(1,n)}},Js=class{gl;pages=new Map;currentPage=null;nextPageIndex=0;frameStamp=0;cells=new Map;tmpCanvas;disposed=!1;pageCap=12;pendingTrim=!1;_generation=0;provisionalFaces=new Map;faceLoads=new Map;onCellsInvalidated;onProvisionalSettled;detachFontsListener=null;epoch;constructor(e,t,r,o=new Pn){this.gl=e,this.onCellsInvalidated=t,this.onProvisionalSettled=r,this.epoch=o,this.tmpCanvas=document.createElement("canvas"),this.tmpCanvas.width=8,this.tmpCanvas.height=8;let i=this.fontSet();if(i&&typeof i.addEventListener=="function"){let s=()=>this.dropProvisionalCells();i.addEventListener("loadingdone",s),this.detachFontsListener=()=>i.removeEventListener("loadingdone",s)}}fontSet(){return typeof document>"u"?null:document.fonts??null}isFacePending(e,t){let r=this.fontSet();if(!r||typeof r.check!="function")return!1;try{if(!r.check(e))return!0;let o=t.fontFamily?.trim().replace(/^['"]|['"]$/g,"")??"";if(!o||o.includes(",")||sl.has(o.toLowerCase())||typeof r.forEach!="function")return!1;let i=!1;return r.forEach(s=>{i||typeof s?.family!="string"||(s.family===o||s.family.toLowerCase()===o.toLowerCase())&&(i=!0)}),!i}catch{return!1}}kickFaceLoad(e){if(this.faceLoads.has(e))return;let t=this.fontSet();if(!t||typeof t.load!="function")return;let r={};this.faceLoads.set(e,r);let o=()=>{this.faceLoads.get(e)===r&&this.faceLoads.delete(e)};try{t.load(e).then(o,o)}catch{o()}}dropProvisionalCells(){if(!(this.disposed||this.provisionalFaces.size===0)){for(let e of this.provisionalFaces.values())for(let t of e.keys)this.cells.delete(t);this.provisionalFaces.clear(),this.onCellsInvalidated?.()}}markFrame(){this.pendingTrim&&this.trimUnusedPages(),this.frameStamp++,this.settleProvisionalCells()}keepPagesForRetainedFrame(){for(let e of this.pages.values())e.lastFrame=this.frameStamp}trimUnusedPages(){let e=[...this.pages.values()].filter(r=>r.lastFrame<this.frameStamp).sort((r,o)=>r.lastFrame-o.lastFrame),t=!1;for(let r of e){if(this.pages.size<=this.pageCap)break;this.gl.deleteTexture(r.texture),this.pages.delete(r.index),this.currentPage===r&&(this.currentPage=null),t=!0}if(this.pendingTrim=this.pages.size>this.pageCap,!!t){for(let[r,o]of this.cells)this.pages.has(o.pageIndex)||this.cells.delete(r);for(let[r,o]of this.provisionalFaces){for(let i of o.keys)this.cells.has(i)||o.keys.delete(i);o.keys.size===0&&this.provisionalFaces.delete(r)}this._generation++,this.epoch.bump("atlas-trim")}}settleProvisionalCells(){if(this.disposed||this.provisionalFaces.size===0)return;let e=!1,t=new Set;for(let[r,o]of this.provisionalFaces)if(!this.isFacePending(r,o.style)){for(let s of o.keys)this.cells.delete(s);this.provisionalFaces.delete(r),e=!0;let i=Qs(o.style.fontFamily??"");i&&t.add(i)}e&&(this.onCellsInvalidated?.(),t.size>0&&this.onProvisionalSettled?.([...t]))}reset(){let e=this.pages.size>0;if(!this.disposed&&e)for(let t of this.pages.values())this.gl.deleteTexture(t.texture);this.pages.clear(),this.currentPage=null,this.pendingTrim=!1,this.cells.clear(),this.provisionalFaces.clear(),e&&(this._generation++,this.epoch.bump("atlas-reset"),Hn()&&console.warn("[retained] GlyphAtlas.reset → generation",this._generation,new Error("reset 调用栈取证").stack))}get generation(){return this._generation}stats(){return{pages:this.pages.size,cells:this.cells.size,pageCap:this.pageCap,pendingReset:!1,pendingTrim:this.pendingTrim,generation:this._generation}}get(e,t,r,o=null){if(this.disposed||r===" "||r===""||r===`
|
|
9
|
+
`||r===" ")return null;let i=`${e.fontFamily}|${e.fontWeight??""}|${e.fontStyle??""}|${t}|${r}`;o&&(i+=`|S${o.width}|${o.lineJoin??""}|${o.lineCap??""}|${o.miterLimit??""}`);let s=this.cells.get(i);if(s)return this.pages.get(s.pageIndex).lastFrame=this.frameStamp,s;let a=Me(e,t),l=this.isFacePending(a,e);l&&this.kickFaceLoad(a);let u=this.rasterize(e,t,r,o);if(u&&(this.cells.set(i,u),l)){let c=this.provisionalFaces.get(a);c||(c={style:{fontFamily:e.fontFamily,fontSize:e.fontSize,fontWeight:e.fontWeight,fontStyle:e.fontStyle},keys:new Set},this.provisionalFaces.set(a,c)),c.keys.add(i)}return u}rasterize(e,t,r,o){let i=this.currentPage;i||(i=this.newPage());let s=i.ctx;s.font=Me(e,t),s.textBaseline="alphabetic",s.textAlign="left",s.fillStyle="#ffffff";let a=s.measureText(r);if(!isFinite(a.width)||a.width<=0&&r.trim()==="")return null;let l=a.actualBoundingBoxLeft??0,u=a.actualBoundingBoxRight??a.width,c=a.actualBoundingBoxAscent??t*.88,h=a.actualBoundingBoxDescent??t*.24,d=t/Math.max(1,e.fontSize),f=o?Math.max(.5,o.width*d):0,m=o?Math.min(f*Math.max(1,o.miterLimit??4)/2,P0):0,p=R0+(o?Math.ceil(m)+1:0),b=Math.max(1,Math.ceil(l+u)+p*2),x=Math.max(1,Math.ceil(c+h)+p*2);if(b>pt||x>pt)return null;i.cursorX+b>pt&&(i.cursorX=0,i.cursorY+=i.rowHeight,i.rowHeight=0),i.cursorY+x>pt&&(i=this.newPage());let g=i.ctx;g.font=Me(e,t),g.textBaseline="alphabetic",g.textAlign="left",g.fillStyle="#ffffff";let y=i.cursorX,v=i.cursorY,S=y+p+l,w=v+p+c;g.save(),o?(g.lineWidth=f,g.lineJoin=o.lineJoin??"miter",g.lineCap=o.lineCap??"butt",g.miterLimit=Math.max(1,o.miterLimit??4),g.strokeStyle="#ffffff",g.strokeText(r,S,w)):g.fillText(r,S,w),g.restore(),(this.tmpCanvas.width<b||this.tmpCanvas.height<x)&&(this.tmpCanvas.width=Math.max(this.tmpCanvas.width,b),this.tmpCanvas.height=Math.max(this.tmpCanvas.height,x));let R=this.tmpCanvas.getContext("2d");return R.clearRect(0,0,this.tmpCanvas.width,this.tmpCanvas.height),R.drawImage(i.canvas,y,v,b,x,0,0,b,x),this.gl.bindTexture(this.gl.TEXTURE_2D,i.texture),this.gl.texSubImage2D(this.gl.TEXTURE_2D,0,y,v,b,x,this.gl.RGBA,this.gl.UNSIGNED_BYTE,this.tmpCanvas),i.cursorX+=b,i.rowHeight=Math.max(i.rowHeight,x),{pageIndex:i.index,u0:y/pt,v0:v/pt,u1:(y+b)/pt,v1:(v+x)/pt,wPx:b,hPx:x,inkLeftPx:-l,ascentPx:c,padPx:p,advancePx:a.width}}textureOf(e){let t=this.pages.get(e.pageIndex);return t?(t.lastFrame=this.frameStamp,t.texture):null}newPage(){this.pages.size>=this.pageCap&&(this.pendingTrim=!0);let e=document.createElement("canvas");e.width=pt,e.height=pt;let t=e.getContext("2d"),r=this.gl.createTexture();this.gl.bindTexture(this.gl.TEXTURE_2D,r),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,pt,pt,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,null),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE);let o={index:this.nextPageIndex++,lastFrame:this.frameStamp,canvas:e,ctx:t,texture:r,cursorX:0,cursorY:0,rowHeight:0};return this.pages.set(o.index,o),this.currentPage=o,o}dispose(){if(!this.disposed){this.disposed=!0,this.detachFontsListener?.(),this.detachFontsListener=null;for(let e of this.pages.values())this.gl.deleteTexture(e.texture);this.pages.clear(),this.currentPage=null,this.pendingTrim=!1,this.cells.clear(),this.provisionalFaces.clear(),this.faceLoads.clear()}}};var zr=(n,e,t,r)=>{if(!t){n.uniform1i(e.paintMode,0);return}n.uniform1i(e.paintMode,t.kind==="gradient"?t.decl.kind==="linear"?1:2:3),n.uniformMatrix3fv(e.paintInv,!1,[t.inv[0],t.inv[1],0,t.inv[2],t.inv[3],0,t.inv[4],t.inv[5],1]),t.kind==="gradient"?t.decl.kind==="linear"?n.uniform4f(e.paintA,t.decl.x1,t.decl.y1,t.decl.x2,t.decl.y2):(n.uniform4f(e.paintA,t.decl.x1,t.decl.y1,t.decl.r1,0),n.uniform4f(e.paintB,t.decl.x2,t.decl.y2,t.decl.r2,0)):n.uniform4f(e.patInfo,t.size[0],t.size[1],t.repeat[0]?1:0,t.repeat[1]?1:0),n.activeTexture(n.TEXTURE0+r),n.bindTexture(n.TEXTURE_2D,t.tex),n.uniform1i(e.fillTex,r)},ta=class{gl;cache=new Map;disposed=!1;constructor(e){this.gl=e}get(e){if(this.disposed)return null;let t=di(e),r=this.cache.get(t);if(r)return r;let o=this.gl,i=o.createTexture();if(!i)return null;let s=hi(e);return o.bindTexture(o.TEXTURE_2D,i),o.texImage2D(o.TEXTURE_2D,0,o.RGBA,s.length/4,1,0,o.RGBA,o.UNSIGNED_BYTE,s),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,o.LINEAR),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MAG_FILTER,o.LINEAR),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_S,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_T,o.CLAMP_TO_EDGE),this.cache.set(t,i),i}invalidateAll(){for(let e of this.cache.values())this.gl.deleteTexture(e);this.cache.clear()}dispose(){this.disposed||(this.disposed=!0,this.invalidateAll())}};var A0=512*1024*1024,N0=2048,L0=30,I0=32*1024*1024,na=class{gl;cache=new Map;budgetBytes;maxEntries;evictGraceFrames;gestureActive=!1;frameStamp=0;frameTouches=0;evictions=0;trackedBytes=0;disposed=!1;epoch;constructor(e,t={}){this.gl=e,this.budgetBytes=t.budgetBytes??A0,this.maxEntries=t.maxEntries??N0,this.evictGraceFrames=t.evictGraceFrames??L0,this.epoch=t.epoch??new Pn}markFrame(e=!1){this.frameStamp+=1,this.frameTouches=0,this.gestureActive=e}get evictionCount(){return this.evictions}setBudget(e){e>0&&(this.budgetBytes=e,this.evictIfNeeded(0,!1))}get(e){if(this.disposed)return null;let t=this.cache.get(e);if(t)return t.lastFrame=this.frameStamp,this.frameTouches+=1,this.cache.delete(e),this.cache.set(e,t),t.tex;let r=this.gl.createTexture();if(!r)return null;let o=!(e instanceof HTMLVideoElement);this.gl.bindTexture(this.gl.TEXTURE_2D,r),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,e),o?(this.gl.generateMipmap(this.gl.TEXTURE_2D),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.LINEAR_MIPMAP_LINEAR)):this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE);let i=_0(e,o),s={tex:r,mipmap:o,bytes:i,lastFrame:this.frameStamp};return this.evictIfNeeded(i,!0),this.trackedBytes+=i,this.frameTouches+=1,this.cache.set(e,s),r}evictIfNeeded(e,t){if(!this.disposed&&!(t&&this.gestureActive)){for(;this.trackedBytes+e>this.budgetBytes||this.cache.size>=this.maxEntries;)if(!(this.evictOldestEligible(t,!1)||this.evictOldestEligible(t,!0)))return}}evictOldestEligible(e,t){for(let[r,o]of this.cache)if(!(e&&this.frameStamp-o.lastFrame<this.evictGraceFrames)&&!(!t&&o.bytes>=I0))return this.gl.deleteTexture(o.tex),this.cache.delete(r),this.trackedBytes-=o.bytes,this.evictions+=1,this.epoch.bump("texture-evict"),!0;return!1}update(e){if(this.disposed)return;let t=this.cache.get(e);t&&(this.gl.bindTexture(this.gl.TEXTURE_2D,t.tex),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,e),t.mipmap&&this.gl.generateMipmap(this.gl.TEXTURE_2D))}remove(e){let t=this.cache.get(e);t&&(this.gl.deleteTexture(t.tex),this.cache.delete(e),this.trackedBytes-=t.bytes)}invalidateAll(){for(let e of this.cache.values())this.gl.deleteTexture(e.tex);this.cache.clear(),this.trackedBytes=0}stats(){return{entries:this.cache.size,bytes:this.trackedBytes,budgetBytes:this.budgetBytes,maxEntries:this.maxEntries,evictions:this.evictions,frameTouches:this.frameTouches}}dispose(){this.disposed||(this.disposed=!0,this.invalidateAll())}},_0=(n,e)=>{let t=n instanceof HTMLVideoElement?n.videoWidth:n instanceof HTMLImageElement&&n.naturalWidth||n.width,r=n instanceof HTMLVideoElement?n.videoHeight:n instanceof HTMLImageElement&&n.naturalHeight||n.height,o=Math.max(1,t)*Math.max(1,r)*4;return Math.round(e?o*(4/3):o)};var Am=`#version 300 es
|
|
10
10
|
layout(location = 0) in vec2 aCorner;
|
|
11
11
|
layout(location = 1) in vec2 aRow0;
|
|
12
12
|
layout(location = 2) in vec2 aRow1;
|
|
@@ -39,7 +39,7 @@ vHalf = aDim * 0.5;
|
|
|
39
39
|
vShape = aUv;
|
|
40
40
|
vDash = aDash;
|
|
41
41
|
vSeg = aSeg;
|
|
42
|
-
}`,
|
|
42
|
+
}`,Nm=`uniform int uPaintMode;
|
|
43
43
|
uniform mat3 uPaintInv;
|
|
44
44
|
uniform vec4 uPaintA;
|
|
45
45
|
uniform vec4 uPaintB;
|
|
@@ -71,7 +71,7 @@ float disc = max(b * b - 4.0 * a * c, 0.0);
|
|
|
71
71
|
t = abs(a) > 1e-9 ? (-b - sqrt(disc)) / (2.0 * a) : (abs(b) > 1e-9 ? -c / b : 0.0);
|
|
72
72
|
}
|
|
73
73
|
return texture(uFillTex, vec2(clamp(t, 0.0, 1.0), 0.5));
|
|
74
|
-
}`,
|
|
74
|
+
}`,Lm=`#version 300 es
|
|
75
75
|
precision highp float;
|
|
76
76
|
in vec2 vUv;
|
|
77
77
|
in vec4 vColor;
|
|
@@ -85,7 +85,7 @@ uniform sampler2D uTex;
|
|
|
85
85
|
uniform float uPenScale;
|
|
86
86
|
uniform sampler2D uSegTex;
|
|
87
87
|
const int MAX_QUAD_SEG = 64;
|
|
88
|
-
${
|
|
88
|
+
${Nm}
|
|
89
89
|
out vec4 fragColor;
|
|
90
90
|
float sdRoundBoxDist(vec2 p, vec2 halfSize, vec2 r) {
|
|
91
91
|
vec2 q = (abs(p) - (halfSize - r)) / max(r, vec2(1e-6));
|
|
@@ -233,7 +233,7 @@ return cov;
|
|
|
233
233
|
void main() {
|
|
234
234
|
fragColor = paintColor(vLocal, texture(uTex, vUv)) * vColor;
|
|
235
235
|
fragColor.a *= -vRadius.y > 0.5 ? strokeCoverage(vLocal, vRadius, vShape, vDash, vSeg, uPenScale) : roundedCoverage(vLocal, vHalf, vRadius);
|
|
236
|
-
}`,
|
|
236
|
+
}`,Im=`#version 300 es
|
|
237
237
|
layout(location = 0) in vec2 aPos;
|
|
238
238
|
layout(location = 1) in vec4 aColor;
|
|
239
239
|
layout(location = 2) in vec2 aLocal;
|
|
@@ -245,21 +245,21 @@ vec3 clip = uView * vec3(aPos, 1.0);
|
|
|
245
245
|
gl_Position = vec4(clip.xy, 0.0, 1.0);
|
|
246
246
|
vColor = aColor;
|
|
247
247
|
vLocal = aLocal;
|
|
248
|
-
}`,
|
|
248
|
+
}`,_m=`#version 300 es
|
|
249
249
|
precision mediump float;
|
|
250
250
|
in vec4 vColor;
|
|
251
251
|
in vec2 vLocal;
|
|
252
|
-
${
|
|
252
|
+
${Nm}
|
|
253
253
|
out vec4 fragColor;
|
|
254
254
|
void main() {
|
|
255
255
|
fragColor = paintColor(vLocal, vColor);
|
|
256
|
-
}`,na=(n,e,t)=>{let r=(a,l)=>{let c=n.createShader(a);return c?(n.shaderSource(c,l),n.compileShader(c),n.getShaderParameter(c,n.COMPILE_STATUS)?c:(console.error("[engine] shader compile failed:",n.getShaderInfoLog(c)),n.deleteShader(c),null)):null},o=r(n.VERTEX_SHADER,e),i=r(n.FRAGMENT_SHADER,t);if(!o||!i)return o&&n.deleteShader(o),i&&n.deleteShader(i),null;let s=n.createProgram();return s?(n.attachShader(s,o),n.attachShader(s,i),n.linkProgram(s),n.deleteShader(o),n.deleteShader(i),n.getProgramParameter(s,n.LINK_STATUS)?{program:s,uniforms:{view:n.getUniformLocation(s,"uView"),tex:n.getUniformLocation(s,"uTex"),penScale:n.getUniformLocation(s,"uPenScale"),segTex:n.getUniformLocation(s,"uSegTex"),paintMode:n.getUniformLocation(s,"uPaintMode"),paintInv:n.getUniformLocation(s,"uPaintInv"),paintA:n.getUniformLocation(s,"uPaintA"),paintB:n.getUniformLocation(s,"uPaintB"),fillTex:n.getUniformLocation(s,"uFillTex"),patInfo:n.getUniformLocation(s,"uPatInfo")}}:(console.error("[engine] program link failed:",n.getProgramInfoLog(s)),n.deleteProgram(s),null)):(n.deleteShader(o),n.deleteShader(i),null)};var Xr=n=>{let e=2166136261;for(let t=0;t<n.length;t++)e=Math.imul(e^Math.round(n[t]*256),16777619);return e>>>1},ra=class{constructor(e){this.gl=e}gl;tex=null;data=new Float32Array(0);rowOwners=[];rowHashes=[];rows=0;healthy=!0;ensureRows(e){if(!this.healthy)return!1;if(e<=this.rows)return!0;let t=this.gl;try{let r=new Float32Array(e*64*4);r.set(this.data);let o=this.tex??t.createTexture();if(!o)return this.healthy=!1,!1;for(t.activeTexture(t.TEXTURE2),t.bindTexture(t.TEXTURE_2D,o),t.texImage2D(t.TEXTURE_2D,0,t.RGBA32F,64,e,0,t.RGBA,t.FLOAT,r),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.activeTexture(t.TEXTURE0),this.tex=o,this.data=r;this.rowOwners.length<e;)this.rowOwners.push(null),this.rowHashes.push(0);return this.rows=e,!0}catch{return this.healthy=!1,!1}}writeRow(e,t,r){if(!this.healthy||e>=this.rows||t&&this.rowOwners[e]===t&&this.rowHashes[e]===r.hash)return;let o=e*64*4;this.data.fill(0,o,o+256),this.data.set(r.data.subarray(0,r.count*4),o),this.rowOwners[e]=t,this.rowHashes[e]=r.hash;let i=this.gl;i.activeTexture(i.TEXTURE2),i.bindTexture(i.TEXTURE_2D,this.tex),i.texSubImage2D(i.TEXTURE_2D,0,0,e,r.count,1,i.RGBA,i.FLOAT,this.data,o),i.activeTexture(i.TEXTURE0)}rowAt(e){return e>=this.rows?null:this.data.slice(e*64*4,(e+1)*64*4)}get texture(){return this.tex}get rowCount(){return this.rows}dispose(){this.tex&&this.gl.deleteTexture(this.tex),this.tex=null,this.data=new Float32Array(0),this.rowOwners=[],this.rowHashes=[],this.rows=0}};var Ve=24,Nm=new Float32Array(9),N0=4096,L0=new Float32Array([0,0,1,0,1,1,0,1]),I0=new Uint16Array([0,1,2,0,2,3]),Zt=class{gl;order=null;gpuRecords=new Map;ownerBlocks=new WeakMap;pendingSegments=[];pendingUploads=[];deferDraws=!1;frameSlots=null;drawnFrom=0;programInfo=null;vao=null;cornerBuffer=null;indexBuffer=null;instanceBuffer=null;instanceData=new Float32Array(N0*Ve);whiteTexture=null;segmentTable=null;instanceCount=0;currentTexture=null;currentGradient=null;viewMat=[1,0,0,1,0,0];penScale=1;disposed=!1;constructor(e){this.gl=e,this.init()}init(){let e=this.gl;if(this.programInfo=na(e,Mm,Pm),!this.programInfo){this.disposed=!0;return}this.whiteTexture=e.createTexture(),e.bindTexture(e.TEXTURE_2D,this.whiteTexture),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,1,1,0,e.RGBA,e.UNSIGNED_BYTE,new Uint8Array([255,255,255,255])),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),this.vao=e.createVertexArray(),e.bindVertexArray(this.vao),this.cornerBuffer=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.cornerBuffer),e.bufferData(e.ARRAY_BUFFER,L0,e.STATIC_DRAW),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,2,e.FLOAT,!1,0,0),this.indexBuffer=e.createBuffer(),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,this.indexBuffer),e.bufferData(e.ELEMENT_ARRAY_BUFFER,I0,e.STATIC_DRAW),this.instanceBuffer=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.instanceBuffer),e.bufferData(e.ARRAY_BUFFER,this.instanceData.byteLength,e.DYNAMIC_DRAW);let t=Ve*4,r=(o,i,s)=>{e.enableVertexAttribArray(o),e.vertexAttribPointer(o,i,e.FLOAT,!1,t,s*4),e.vertexAttribDivisor(o,1)};r(1,2,0),r(2,2,2),r(3,2,4),r(4,2,6),r(5,4,8),r(6,4,12),r(7,2,16),r(8,3,18),r(9,3,21),e.bindVertexArray(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA)}get valid(){return!this.disposed&&!!this.programInfo}rebuild(){this.release(),this.disposed=!1,this.init()}release(){let e=this.gl;this.whiteTexture&&e.deleteTexture(this.whiteTexture),this.segmentTable?.dispose(),this.segmentTable=null,this.instanceBuffer&&e.deleteBuffer(this.instanceBuffer),this.indexBuffer&&e.deleteBuffer(this.indexBuffer),this.cornerBuffer&&e.deleteBuffer(this.cornerBuffer),this.vao&&e.deleteVertexArray(this.vao),this.programInfo&&e.deleteProgram(this.programInfo.program),this.whiteTexture=null,this.instanceBuffer=null,this.indexBuffer=null,this.cornerBuffer=null,this.vao=null,this.programInfo=null,this.instanceCount=0,this.drawnFrom=0,this.currentTexture=null,this.currentGradient=null,this.pendingSegments=[],this.pendingUploads=[],this.gpuRecords.clear()}pushedTextures=new Set;begin(e,t=1){this.valid&&(this.viewMat=e,this.penScale=t,this.frameSlots=null,this.instanceCount=0,this.drawnFrom=0,this.currentTexture=null,this.currentGradient=null,this.pushedTextures.clear(),this.dropPendingSegments(),this.pendingUploads=[])}pushQuad(e,t,r,o,i,s=[0,0,1,1],a=null,l,c,u){if(!this.valid)return;this.order?.beforeQuadPush(),i!==this.currentTexture&&(this.flush(),this.currentTexture=i),this.instanceCount*Ve+Ve>this.instanceData.length&&this.grow();let h=this.instanceCount*Ve,d=this.instanceCount;this.pushedTextures.add(i);let f=this.instanceData,m=!0,p=l?this.ownerBlocks.get(l):void 0;p&&p.m0===e[0]&&p.m1===e[1]&&p.m2===e[2]&&p.m3===e[3]&&p.m4===e[4]&&p.m5===e[5]&&p.dx===t&&p.dy===r&&p.u0===s[0]&&p.u1===s[1]&&p.u2===s[2]&&p.u3===s[3]&&p.r0===(a?a[0]:0)&&p.r1===(a?a[1]:0)&&p.c0===o[0]&&p.c1===o[1]&&p.c2===o[2]&&p.c3===o[3]&&p.dashOn===(c?c[0]:0)&&p.dashCycle===(c?c[1]:0)&&p.dashPhase===(c?c[2]:0)&&p.segCount===(u?u.count:0)&&p.segHash===(u?u.hash:0)?(f.set(p.block,h),f[h+21]=d,f[h+22]=u?u.count:0,f[h+23]=u?u.hash:0,m=!1):(f[h]=e[0],f[h+1]=e[1],f[h+2]=e[2],f[h+3]=e[3],f[h+4]=e[4],f[h+5]=e[5],f[h+6]=t,f[h+7]=r,f[h+8]=s[0],f[h+9]=s[1],f[h+10]=s[2],f[h+11]=s[3],f[h+12]=o[0],f[h+13]=o[1],f[h+14]=o[2],f[h+15]=o[3],f[h+16]=a?a[0]:0,f[h+17]=a?a[1]:0,f[h+18]=c?c[0]:0,f[h+19]=c?c[1]:0,f[h+20]=c?c[2]:0,f[h+21]=d,f[h+22]=u?u.count:0,f[h+23]=u?u.hash:0,l&&this.ownerBlocks.set(l,{floatCount:Ve,m0:e[0],m1:e[1],m2:e[2],m3:e[3],m4:e[4],m5:e[5],dx:t,dy:r,u0:s[0],u1:s[1],u2:s[2],u3:s[3],r0:a?a[0]:0,r1:a?a[1]:0,c0:o[0],c1:o[1],c2:o[2],c3:o[3],dashOn:c?c[0]:0,dashCycle:c?c[1]:0,dashPhase:c?c[2]:0,segCount:u?u.count:0,segHash:u?u.hash:0,block:this.instanceData.slice(h,h+Ve)})),u&&this.segmentTable?.writeRow(d,l??null,u);let b=l?this.gpuRecords.get(l):void 0,x=m||!b||b.startFloat!==h||b.floatCount!==Ve;if(this.pendingSegments.push({owner:l??null,startFloat:h,floatCount:Ve,dirty:x}),x){let g=this.pendingUploads[this.pendingUploads.length-1];g&&g[1]===h?g[1]=h+Ve:this.pendingUploads.push([h,h+Ve])}if(this.instanceCount+=1,l){let g=this.frameSlots??=new Map,y=g.get(l);y&&y.start+y.count===this.instanceCount-1?y.count+=1:g.set(l,{start:this.instanceCount-1,count:1})}}pushPaintQuad(e,t,r,o,i,s=null){this.valid&&(this.order?.beforeQuadPush(),this.flush(),this.currentGradient=o,this.currentTexture=o.tex,this.pushQuad(e,t,r,[1,1,1,i],o.tex,[0,0,1,1],s),this.flush(),this.currentGradient=null)}flush(){if(!this.valid||this.instanceCount<=this.drawnFrom)return;if(this.deferDraws){let l={startInstance:this.drawnFrom,count:this.instanceCount-this.drawnFrom,texture:this.currentTexture,gradient:this.currentGradient};if(this.drawnFrom=this.instanceCount,this.order){this.order.recordDraw(this,l);return}this.uploadPending(),this.drawDeferred(l);return}let e=this.gl,{program:t,uniforms:r}=this.programInfo,o=this.instanceCount-this.drawnFrom;e.useProgram(t),e.bindVertexArray(this.vao);let i=new Float32Array([this.viewMat[0],this.viewMat[1],0,this.viewMat[2],this.viewMat[3],0,this.viewMat[4],this.viewMat[5],1]);e.uniformMatrix3fv(r.view,!1,i),e.uniform1f(r.penScale,this.penScale),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,this.currentTexture??this.whiteTexture),e.uniform1i(r.tex,0),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,this.segmentTable?.texture??this.whiteTexture),e.uniform1i(r.segTex,2),e.activeTexture(e.TEXTURE0),Gr(e,r,this.currentGradient,1),e.bindBuffer(e.ARRAY_BUFFER,this.instanceBuffer);for(let[l,c]of this.pendingUploads)e.bufferSubData(e.ARRAY_BUFFER,l*4,this.instanceData,l,c-l),this.invalidateOverlappingRecords(l,c);this.pendingUploads=[];let s=Ve*4,a=this.drawnFrom*s;e.vertexAttribPointer(1,2,e.FLOAT,!1,s,a),e.vertexAttribPointer(2,2,e.FLOAT,!1,s,a+8),e.vertexAttribPointer(3,2,e.FLOAT,!1,s,a+16),e.vertexAttribPointer(4,2,e.FLOAT,!1,s,a+24),e.vertexAttribPointer(5,4,e.FLOAT,!1,s,a+32),e.vertexAttribPointer(6,4,e.FLOAT,!1,s,a+48),e.vertexAttribPointer(7,2,e.FLOAT,!1,s,a+64),e.vertexAttribPointer(8,3,e.FLOAT,!1,s,a+72),e.vertexAttribPointer(9,3,e.FLOAT,!1,s,a+84),e.drawElementsInstanced(e.TRIANGLES,6,e.UNSIGNED_SHORT,0,o),this.drawnFrom=this.instanceCount;for(let l of this.pendingSegments)l.owner&&this.gpuRecords.set(l.owner,{startFloat:l.startFloat,floatCount:l.floatCount});this.pendingSegments=[]}currentFrameSlots(){return this.frameSlots??new Map}rewindToSlot(e){this.instanceCount=e,this.drawnFrom>e&&(this.drawnFrom=e)}restoreTotals(e){this.instanceCount=e,this.drawnFrom=e}uploadPending(){if(!this.valid)return;let e=this.gl;e.bindBuffer(e.ARRAY_BUFFER,this.instanceBuffer);let t=this.pendingUploads;for(let r=0;r<t.length;r++){let[o,i]=t[r],s=t[r+1];if(s&&s[0]<=i+4096){s[0]=o;continue}e.bufferSubData(e.ARRAY_BUFFER,o*4,this.instanceData,o,i-o),this.invalidateOverlappingRecords(o,i)}this.pendingUploads=[];for(let r of this.pendingSegments)r.owner&&this.gpuRecords.set(r.owner,{startFloat:r.startFloat,floatCount:r.floatCount});this.pendingSegments=[]}dropPendingSegments(){for(let e of this.pendingSegments)e.dirty&&e.owner&&this.gpuRecords.delete(e.owner);this.pendingSegments=[]}invalidateOverlappingRecords(e,t){if(this.gpuRecords.size===0)return;let r=new Set;for(let o of this.pendingSegments)o.owner&&o.startFloat<t&&e<o.startFloat+o.floatCount&&r.add(o.owner);for(let[o,i]of this.gpuRecords)!r.has(o)&&i.startFloat<t&&e<i.startFloat+i.floatCount&&this.gpuRecords.delete(o)}drawDeferred(e){if(!this.valid)return;let t=this.gl,{program:r,uniforms:o}=this.programInfo;t.useProgram(r),t.bindVertexArray(this.vao),Nm.set([this.viewMat[0],this.viewMat[1],0,this.viewMat[2],this.viewMat[3],0,this.viewMat[4],this.viewMat[5],1]),t.uniformMatrix3fv(o.view,!1,Nm),t.uniform1f(o.penScale,this.penScale),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,e.texture??this.whiteTexture),t.uniform1i(o.tex,0),t.activeTexture(t.TEXTURE2),t.bindTexture(t.TEXTURE_2D,this.segmentTable?.texture??this.whiteTexture),t.uniform1i(o.segTex,2),t.activeTexture(t.TEXTURE0),Gr(t,o,e.gradient,1),t.bindBuffer(t.ARRAY_BUFFER,this.instanceBuffer);let i=Ve*4,s=e.startInstance*i;t.vertexAttribPointer(1,2,t.FLOAT,!1,i,s),t.vertexAttribPointer(2,2,t.FLOAT,!1,i,s+8),t.vertexAttribPointer(3,2,t.FLOAT,!1,i,s+16),t.vertexAttribPointer(4,2,t.FLOAT,!1,i,s+24),t.vertexAttribPointer(5,4,t.FLOAT,!1,i,s+32),t.vertexAttribPointer(6,4,t.FLOAT,!1,i,s+48),t.vertexAttribPointer(7,2,t.FLOAT,!1,i,s+64),t.vertexAttribPointer(8,3,t.FLOAT,!1,i,s+72),t.vertexAttribPointer(9,3,t.FLOAT,!1,i,s+84),t.drawElementsInstanced(t.TRIANGLES,6,t.UNSIGNED_SHORT,0,e.count)}grow(){let e=this.gl,t=new Float32Array(this.instanceData.length*2);t.set(this.instanceData),this.instanceData=t,this.gpuRecords.clear(),this.pendingUploads=[[0,this.instanceCount*Ve]],e.bindBuffer(e.ARRAY_BUFFER,this.instanceBuffer),e.bufferData(e.ARRAY_BUFFER,this.instanceData.byteLength,e.DYNAMIC_DRAW),this.segmentTable?.ensureRows(this.instanceData.length/Ve)}canPushSegments(){return this.valid?(this.segmentTable||(this.segmentTable=new ra(this.gl)),this.segmentTable.ensureRows(this.instanceData.length/Ve)):!1}get drawnInstances(){return this.instanceCount}get instanceTotal(){return this.instanceCount}dispose(){this.disposed||(this.disposed=!0,this.release())}};var oa=class{constructor(e,t){this.quad=e;this.mesh=t}quad;mesh;seq=0;quadSeq=-1;meshSeq=-1;deferred=[];requestSnapshot=!1;retained=null;beforeQuadPush(){this.meshSeq>this.quadSeq&&(this.meshSeq=-1,this.mesh.flush()),this.quadSeq=++this.seq}beforeMeshPush(){this.quadSeq>this.meshSeq&&(this.quadSeq=-1,this.quad.flush()),this.meshSeq=++this.seq}recordDraw(e,t){this.deferred.push({batch:e,cmd:t})}recordState(e){this.quadSeq>=0&&(this.meshSeq<0||this.quadSeq>this.meshSeq)&&(this.quadSeq=-1,this.quad.flush()),this.meshSeq>=0&&(this.meshSeq=-1,this.mesh.flush()),this.quad.deferDraws&&this.mesh.deferDraws?this.deferred.push({fn:e}):e()}hasRecordedCommands(){return this.deferred.length>0}hasNovelPaintReferences(e){if(this.quad.pushedTextures.size){let t=new Set;for(let r of e.commands)"fn"in r||r.batch instanceof Zt&&t.add(r.cmd.texture);for(let r of this.quad.pushedTextures)if(!t.has(r))return!0}if(this.mesh.pushedGradients.size){let t=new Set;for(let r of e.commands)"fn"in r||r.batch instanceof Zt||t.add(r.cmd.gradient);for(let r of this.mesh.pushedGradients)if(!t.has(r))return!0}return!1}flushAll(){this.quadSeq>=0&&(this.meshSeq<0||this.quadSeq>this.meshSeq)&&(this.quadSeq=-1,this.quad.flush()),this.meshSeq>=0&&(this.meshSeq=-1,this.mesh.flush()),this.executeDeferred()}executeDeferred(){if(this.requestSnapshot&&(this.requestSnapshot=!1,this.retained={commands:this.deferred,quadSlots:this.quad.currentFrameSlots(),meshSlots:this.mesh.currentFrameSlots(),quadTotal:this.quad.instanceTotal,meshTotal:this.mesh.vertexTotal}),!!this.deferred.length){this.quad.uploadPending(),this.mesh.uploadPending();for(let e of this.deferred)"fn"in e?e.fn():(e.batch instanceof Zt,e.batch.drawDeferred(e.cmd));this.deferred=[]}}reset(){this.seq=0,this.quadSeq=-1,this.meshSeq=-1,this.deferred=[]}discardRecorded(){this.deferred=[]}replaySnapshot(e){this.quad.uploadPending(),this.mesh.uploadPending();for(let t of e.commands)"fn"in t?t.fn():(t.batch instanceof Zt,t.batch.drawDeferred(t.cmd))}};var Lm=new Float32Array(9),Rt=8,_0=8192,ia=class{gl;order=null;ownerBlocks=new WeakMap;gpuRecords=new Map;pendingSegments=[];pendingUploads=[];deferDraws=!1;frameSlots=null;drawnFrom=0;programInfo=null;vao=null;vertexBuffer=null;whiteTex=null;vertexData=new Float32Array(_0*Rt);vertexCount=0;currentGradient=null;viewMat=[1,0,0,1,0,0];disposed=!1;constructor(e){this.gl=e,this.init()}init(){let e=this.gl;if(this.programInfo=na(e,km,Am),!this.programInfo){this.disposed=!0;return}this.vao=e.createVertexArray(),e.bindVertexArray(this.vao),this.vertexBuffer=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer),e.bufferData(e.ARRAY_BUFFER,this.vertexData.byteLength,e.DYNAMIC_DRAW),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,2,e.FLOAT,!1,Rt*4,0),e.enableVertexAttribArray(1),e.vertexAttribPointer(1,4,e.FLOAT,!1,Rt*4,8),e.enableVertexAttribArray(2),e.vertexAttribPointer(2,2,e.FLOAT,!1,Rt*4,24),e.bindVertexArray(null),this.whiteTex=e.createTexture(),e.bindTexture(e.TEXTURE_2D,this.whiteTex),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,1,1,0,e.RGBA,e.UNSIGNED_BYTE,new Uint8Array([255,255,255,255])),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA)}get valid(){return!this.disposed&&!!this.programInfo}rebuild(){this.release(),this.disposed=!1,this.init()}release(){let e=this.gl;this.vertexBuffer&&e.deleteBuffer(this.vertexBuffer),this.vao&&e.deleteVertexArray(this.vao),this.programInfo&&e.deleteProgram(this.programInfo.program),this.whiteTex&&e.deleteTexture(this.whiteTex),this.vertexBuffer=null,this.vao=null,this.programInfo=null,this.whiteTex=null,this.vertexCount=0,this.drawnFrom=0,this.currentGradient=null,this.pendingSegments=[],this.pendingUploads=[],this.gpuRecords.clear()}pushedGradients=new Set;begin(e){this.valid&&(this.viewMat=e,this.frameSlots=null,this.vertexCount=0,this.drawnFrom=0,this.currentGradient=null,this.pushedGradients.clear(),this.dropPendingSegments(),this.pendingUploads=[])}pushMesh(e,t,r,o,i,s){if(!this.valid)return;this.order?.beforeMeshPush(),(!!i!=!!this.currentGradient||i&&this.currentGradient&&i!==this.currentGradient)&&(this.flush(),this.currentGradient=i??null);let a=o.length/3,l=a*3*Rt;this.vertexCount*Rt+l>this.vertexData.length&&this.grow(this.vertexCount*Rt+l);let c=this.vertexCount*Rt;this.pushedGradients.add(i??null);let u=!0,h=s?this.ownerBlocks.get(s):void 0;if(h&&h.floatCount===l&&h.verts===r&&h.triangles===o&&h.m0===e[0]&&h.m1===e[1]&&h.m2===e[2]&&h.m3===e[3]&&h.m4===e[4]&&h.m5===e[5]&&h.c0===t[0]&&h.c1===t[1]&&h.c2===t[2]&&h.c3===t[3])this.vertexData.set(h.block,c),u=!1;else{let p=e,b=this.vertexData,x=c;for(let g=0;g<o.length;g++){let y=o[g]*2,v=r[y],S=r[y+1];b[x]=p[0]*v+p[2]*S+p[4],b[x+1]=p[1]*v+p[3]*S+p[5],b[x+2]=t[0],b[x+3]=t[1],b[x+4]=t[2],b[x+5]=t[3],b[x+6]=v,b[x+7]=S,x+=Rt}s&&this.ownerBlocks.set(s,{floatCount:l,verts:r,triangles:o,m0:e[0],m1:e[1],m2:e[2],m3:e[3],m4:e[4],m5:e[5],c0:t[0],c1:t[1],c2:t[2],c3:t[3],block:this.vertexData.slice(c,c+l)})}let d=s?this.gpuRecords.get(s):void 0,f=d&&d.startFloat===c&&d.floatCount===l,m=u||!f;if(this.pendingSegments.push({owner:s??null,startFloat:c,floatCount:l,dirty:m}),m){let p=this.pendingUploads[this.pendingUploads.length-1];p&&p[1]===c?p[1]=c+l:this.pendingUploads.push([c,c+l])}if(this.vertexCount+=a*3,s){let p=this.frameSlots??=new Map,b=a*3,x=p.get(s);x&&x.start+x.count===this.vertexCount-b?x.count+=b:p.set(s,{start:this.vertexCount-b,count:b})}}flush(){if(!this.valid||this.vertexCount<=this.drawnFrom)return;if(this.deferDraws){let i={startVertex:this.drawnFrom,count:this.vertexCount-this.drawnFrom,gradient:this.currentGradient};if(this.drawnFrom=this.vertexCount,this.order){this.order.recordDraw(this,i);return}this.uploadPending(),this.drawDeferred(i);return}let e=this.gl,{program:t,uniforms:r}=this.programInfo;e.useProgram(t),e.bindVertexArray(this.vao);let o=new Float32Array([this.viewMat[0],this.viewMat[1],0,this.viewMat[2],this.viewMat[3],0,this.viewMat[4],this.viewMat[5],1]);e.uniformMatrix3fv(r.view,!1,o),Gr(e,r,this.currentGradient,0),!this.currentGradient&&this.whiteTex&&(e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,this.whiteTex),e.uniform1i(r.fillTex,0)),e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer);for(let[i,s]of this.pendingUploads)e.bufferSubData(e.ARRAY_BUFFER,i*4,this.vertexData,i,s-i),this.invalidateOverlappingRecords(i,s);this.pendingUploads=[],e.drawArrays(e.TRIANGLES,this.drawnFrom,this.vertexCount-this.drawnFrom),this.drawnFrom=this.vertexCount;for(let i of this.pendingSegments)i.owner&&this.gpuRecords.set(i.owner,{startFloat:i.startFloat,floatCount:i.floatCount});this.pendingSegments=[]}currentFrameSlots(){return this.frameSlots??new Map}rewindToSlot(e){this.vertexCount=e,this.drawnFrom>e&&(this.drawnFrom=e)}restoreTotals(e){this.vertexCount=e,this.drawnFrom=e}uploadPending(){if(!this.valid)return;let e=this.gl;e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer);let t=this.pendingUploads;for(let r=0;r<t.length;r++){let[o,i]=t[r],s=t[r+1];if(s&&s[0]<=i+4096){s[0]=o;continue}e.bufferSubData(e.ARRAY_BUFFER,o*4,this.vertexData,o,i-o),this.invalidateOverlappingRecords(o,i)}this.pendingUploads=[];for(let r of this.pendingSegments)r.owner&&this.gpuRecords.set(r.owner,{startFloat:r.startFloat,floatCount:r.floatCount});this.pendingSegments=[]}dropPendingSegments(){for(let e of this.pendingSegments)e.dirty&&e.owner&&this.gpuRecords.delete(e.owner);this.pendingSegments=[]}invalidateOverlappingRecords(e,t){if(this.gpuRecords.size===0)return;let r=new Set;for(let o of this.pendingSegments)o.owner&&o.startFloat<t&&e<o.startFloat+o.floatCount&&r.add(o.owner);for(let[o,i]of this.gpuRecords)!r.has(o)&&i.startFloat<t&&e<i.startFloat+i.floatCount&&this.gpuRecords.delete(o)}drawDeferred(e){if(!this.valid)return;let t=this.gl,{program:r,uniforms:o}=this.programInfo;t.useProgram(r),t.bindVertexArray(this.vao),Lm.set([this.viewMat[0],this.viewMat[1],0,this.viewMat[2],this.viewMat[3],0,this.viewMat[4],this.viewMat[5],1]),t.uniformMatrix3fv(o.view,!1,Lm),Gr(t,o,e.gradient,0),!e.gradient&&this.whiteTex&&(t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,this.whiteTex),t.uniform1i(o.fillTex,0)),t.drawArrays(t.TRIANGLES,e.startVertex,e.count)}grow(e){let t=this.gl,r=this.vertexData.length;for(;r<e;)r*=2;let o=new Float32Array(r);o.set(this.vertexData.subarray(0,this.vertexCount*Rt)),this.vertexData=o,t.bindBuffer(t.ARRAY_BUFFER,this.vertexBuffer),t.bufferData(t.ARRAY_BUFFER,this.vertexData.byteLength,t.DYNAMIC_DRAW),this.gpuRecords.clear(),this.pendingUploads=[[0,this.vertexCount*Rt]]}get drawnVertices(){return this.vertexCount}get vertexTotal(){return this.vertexCount}dispose(){this.disposed||(this.disposed=!0,this.release())}};var Bt=ql,F0=[Bt[0],Bt[1],Bt[2],.14],Oc=[1,1,1,1],O0=2,Dm=[238/255,238/255,238/255,128/255],Fm=[24/255,144/255,1,128/255],Uo=20,kn=20,sa=null,B0=()=>{if(sa)return sa;let n=e=>{let t=document.createElement("canvas");t.width=Uo,t.height=Uo;let r=t.getContext("2d");if(!r)return t;let o=Uo/2;r.beginPath(),r.arc(o,o,8,0,Math.PI*2),r.fillStyle=e?"#2f6fed":"#ffffff",r.fill(),r.lineWidth=1.5,r.strokeStyle="#2f6fed",r.stroke();let i=4;return r.beginPath(),r.moveTo(o-i,o),r.lineTo(o+i,o),r.moveTo(o,o-i),r.lineTo(o,o+i),r.lineWidth=1.5,r.strokeStyle=e?"#ffffff":"#2f6fed",r.stroke(),t};return sa={normal:n(!1),hover:n(!0)},sa},W0=n=>n.columnWidths.reduce((e,t)=>e+t,0)+(n.cols-1)*n.cellSpacing,H0=n=>n.rowHeights.reduce((e,t)=>e+t,0)+(n.rows-1)*n.cellSpacing,Om=(n,e,t)=>{let r=0;for(let o=0;o<t;o++)r+=n[o]+e;return r},aa=null,G0=()=>{if(aa)return aa;let n=e=>{let t=document.createElement("canvas");t.width=kn*2,t.height=kn*2;let r=t.getContext("2d");if(!r)return t;r.scale(2,2),r.fillStyle=e?"#1890ff20":"#eeeeee99",r.fillRect(0,0,kn-1,kn-1);let o=kn/2-.5,i=kn/2-.5,s=kn*.25,a=kn*.18;r.strokeStyle=e?"#1890ff":"#888888",r.lineWidth=1.5,r.lineCap="round";for(let l=-1;l<=1;l++)r.beginPath(),r.moveTo(o-s,i+l*a),r.lineTo(o+s,i+l*a),r.stroke();return t};return aa={normal:n(!1),hover:n(!0)},aa},Bm=(n,e)=>{let t=[],r=n.tableView,o=n.cellMap,i=n.matrix,s=n.objectScale,a=W0(r)/2,l=H0(r)/2,c=Mt/e/Math.max(s.x,1e-6),u=Mt/e/Math.max(s.y,1e-6);for(let x of n.selectedCells){let g=o.get(`${x.row},${x.col}`);if(g?.isMerged)continue;let y=g?.rowspan??1,v=g?.colspan??1,S=So(r,{r1:x.row,r2:x.row+y-1,c1:x.col,c2:x.col+v-1}),w=S.left+S.width/2,R=S.top+S.height/2;t.push({matrix:$(i,[1,0,0,1,w,R]),dims:{x:S.width,y:S.height},color:F0}),t.push({matrix:$(i,[1,0,0,1,w,S.top]),dims:{x:S.width+2*c,y:u},color:Bt}),t.push({matrix:$(i,[1,0,0,1,w,S.top+S.height]),dims:{x:S.width+2*c,y:u},color:Bt}),t.push({matrix:$(i,[1,0,0,1,S.left,R]),dims:{x:c,y:S.height+2*u},color:Bt}),t.push({matrix:$(i,[1,0,0,1,S.left+S.width,R]),dims:{x:c,y:S.height+2*u},color:Bt})}if(n.hoveredBorder){let{type:x,position:g}=n.hoveredBorder,y=x==="col"?Q(i,g,-l):Q(i,-a,g),v=x==="col"?Q(i,g,l):Q(i,a,g);t.push(Re(y,v,O0/e,Bt))}let h=-n.dims.x/2,d=-n.dims.y/2,f=20/(e*Math.max(s.x,1e-6)),m=20/(e*Math.max(s.y,1e-6)),p=Rr(o,n.selectedCells);for(let x=0;x<r.rows;x++){let g=Om(r.rowHeights,r.cellSpacing,x)-l,y=r.rowHeights[x],v=n.hoveredStrip?.kind==="row"&&n.hoveredStrip.index===x?!0:p.rows.has(x);t.push({matrix:$(i,[1,0,0,1,h-f/2,g+y/2]),dims:{x:f,y},color:v?Fm:Dm})}for(let x=0;x<r.cols;x++){let g=Om(r.columnWidths,r.cellSpacing,x)-a,y=r.columnWidths[x],v=n.hoveredStrip?.kind==="col"&&n.hoveredStrip.index===x?!0:p.cols.has(x);t.push({matrix:$(i,[1,0,0,1,g+y/2,d-m/2]),dims:{x:y,y:m},color:v?Fm:Dm})}{let x=G0();t.push({matrix:$(i,[1,0,0,1,h-f/2,d-m/2]),dims:{x:f,y:m},color:Oc,texture:n.hoveredDragHandle?x.hover:x.normal})}let b=n.hoveredIndicator??(n.borderDragging?null:n.hoveredBorder);if(b){let x=B0(),g=b.type==="col";t.push({matrix:$(i,[1,0,0,1,g?b.position:-a-15,g?-l-15:b.position]),dims:{x:Uo/(e*Math.max(s.x,1e-6)),y:Uo/(e*Math.max(s.y,1e-6))},color:Oc,texture:n.hoveredIndicator?x.hover:x.normal})}if(n.selectedCells.length&&!n.editingCell&&!n.isFullCellSelection){let x=n.selectionBoundsRect;if(x){let g=x.left+x.width,y=x.top+x.height,v=Mn/e/Math.max(s.x,1e-6),S=Mn/e/Math.max(s.y,1e-6),w=(Mn-2*Mt)/e/Math.max(s.x,1e-6),R=(Mn-2*Mt)/e/Math.max(s.y,1e-6);t.push({matrix:$(i,[1,0,0,1,g,y]),dims:{x:v,y:S},color:Bt}),t.push({matrix:$(i,[1,0,0,1,g,y]),dims:{x:w,y:R},color:n.hoveredRangeHandle?Bt:Oc})}}return t};var X0=(n,e,t,r)=>{let o=n.nodes.filter(h=>Ze(h)&&h.visible&&h.raw.visible!==!1);if(!o.length)return[];let i=e[0],s=-e[4]/i,a=-e[5]/i,l=t/i,c=r/i,u=[];for(let h of o){let d=h.raw,f=oe(typeof d.stroke=="string"?d.stroke:"pink"),m=typeof d.opacity=="number"?d.opacity:1,p=[f[0],f[1],f[2],f[3]*m],b=Math.max(Number(d.strokeWidth)||1,1.2/i),x=h.bounds;if(h.dims.y===0){let g=(x.top+x.bottom)/2;u.push({matrix:[1,0,0,1,s+l/2,g],dims:{x:l,y:b},color:p})}else if(h.dims.x===0){let g=(x.left+x.right)/2;u.push({matrix:[1,0,0,1,g,a+c/2],dims:{x:b,y:c},color:p})}}return u},Wm=n=>{let{doc:e,zoom:t,marquee:r,textEdit:o,snapOverlay:i,ruler:s}=n,a=n.rotate??null,l=o.node,c=!l&&!r&&e.selection.length===1&&e.selection[0]instanceof le?e.selection[0]:null,u=l?[...n.cellEditOverlayOnly?[]:Cn(l.aCoords,t),...o.quads]:r?Md(r,t):c?.editingMask?Rd(c,t,a):Cd(e,t,a,n.mobileControls===!0),h=l&&e.selection.length===1?e.selection[0]:null;l&&h instanceof J&&h.containsDeep(l)&&(u=[...u,...xs(h.aCoords,t)]),!l&&!r&&e.selection.length===1&&e.selection[0]instanceof ee&&(u=[...u,...Bm(e.selection[0],t)]);let d=e.seamHover;if(c&&d&&d.puzzle===c&&(u=[...u,...kd(Pd(d.puzzle,d.mask,d.handle),t)]),e.hovered&&!r&&!Ze(e.hovered)&&(u=[...u,...Ad(e.hovered,t)]),u=[...u,...i],s){u=[...u,...X0(e,s.vpt,s.cssWidth,s.cssHeight)];let f=e.nodes.find(p=>p.raw.id===gn),m=f&&typeof f.raw.width=="number"&&typeof f.raw.height=="number"?{left:f.raw.left??0,top:f.raw.top??0,width:f.raw.width,height:f.raw.height}:null;u=[...u,...zd({vpt:s.vpt,cssWidth:s.cssWidth,cssHeight:s.cssHeight,workspaceRect:m,referenceLine:s.referenceLine??null,selectionRects:e.selection.filter(p=>!Ze(p)).map(p=>({left:p.bounds.left,top:p.bounds.top,width:p.bounds.right-p.bounds.left,height:p.bounds.bottom-p.bounds.top}))})]}return u};function Hm(n,e,t,r,o){for(let i=0;i<o;i++){let s=t[i];if(!Ze(s)&&!er(s)){if(r&&s===r.target)for(let a of r.underlay())n.pushQuad(a.matrix,a.dims.x,a.dims.y,a.color,null);e.renderSceneNode(s)}}}function Gm(n,e){for(let t of e)er(t)&&t.visible&&n.renderSceneNode(t)}function Xm(n){let e=n.doc.editingNode;if(n.cropSessionController.active){$o(n,n.cropSessionController.buildOverlay(n.zoom))&&n.requestRenderAll();return}if(n.expandSessionController.active){$o(n,n.expandSessionController.buildOverlay(n.zoom))&&n.requestRenderAll();return}if(n.pathSessionController.active){$o(n,n.pathSessionController.buildOverlay(n.zoom))&&n.requestRenderAll();return}if(n.warpSessionController.active){$o(n,n.warpSessionController.buildOverlay())&&n.requestRenderAll();return}let t=Wm({doc:n.doc,zoom:n.zoom,marquee:n.marquee,textEdit:{node:e,quads:e?n.textEditing.buildOverlay():[]},cellEditOverlayOnly:e!==null&&n.tableCellEditing.isOverlay(e),snapOverlay:n.snapGuide.buildOverlay(n.zoom),rotate:n.rotateDrag,mobileControls:n.mobileControls,ruler:n.rulerVisible?{vpt:n.vpt,cssWidth:n.cssWidth,cssHeight:n.cssHeight,referenceLine:n.referenceLineDrag}:null});$o(n,t),n.renderer.frame.animationActive&&n.requestRenderAll()}function $o(n,e){for(let t of e)n.batch.pushQuad(t.matrix,t.dims.x,t.dims.y,t.color,t.texture?n.textures.get(t.texture):null);return n.batch.flush(),n.batch.deferDraws=!1,n.meshBatch.deferDraws=!1,n.batchOrder.executeDeferred(),n.renderer.frame.animationActive}var la=class{constructor(e){this.host=e}host;limit=-1;rafId=null;deadline=0;rendered=!1;start(e=1e3,t=800){if(!this.host.alive())return;let r=this.host.nodeCount();r<e||(this.rafId!==null&&cancelAnimationFrame(this.rafId),this.limit=Math.min(e,r),this.rendered=!1,this.deadline=performance.now()+t,this.rafId=requestAnimationFrame(()=>this.step()))}step(){if(this.rafId=null,this.limit<0||!this.host.alive())return;let e=this.host.nodeCount();if(this.limit>=e){this.limit=-1,this.host.onProgressiveDone(e);return}let t=performance.now();this.host.render(),this.rendered=!0;let r=performance.now()-t,o=r>1?Math.min(4,Math.max(.5,20/r)):2;if(this.limit=Math.min(e,Math.max(this.limit+1,Math.round(this.limit*(1+o)))),this.limit>=e){this.host.render(),this.limit=-1,this.host.onProgressiveDone(e);return}this.rafId=requestAnimationFrame(()=>this.step())}absorbExternalRenderRequest(){this.rendered&&performance.now()>this.deadline&&this.limit>=0&&this.limit<this.host.nodeCount()&&(this.limit=this.host.nodeCount())}dispose(){this.rafId!==null&&cancelAnimationFrame(this.rafId),this.rafId=null,this.limit=-1,this.rendered=!1}};var ca=class{constructor(e){this.host=e}host;retained=null;lastFrameAnimated=!1;lastFrameBakeMore=!1;lastGateReason=null;tryRetainedFrame(){let{host:e}=this;if(e.renderer.flatFrame=!0,!$a())return this.gateFail("flag-off");let t=this.retained;if(!t)return this.gateFail("no-snapshot");if(this.lastFrameAnimated)return this.gateFail("animating");if(this.lastFrameBakeMore)return this.gateFail("bake-continue");if(e.cropSessionController.active||e.expandSessionController.active||e.pathSessionController.active||e.warpSessionController.active)return this.gateFail("session");if(e.progressiveLoad.limit>=0&&e.progressiveLoad.limit<e.doc.nodes.length)return this.gateFail("progressive");if(e.doc.editingNode)return this.gateFail("editing");if(t.structureVersion!==e.doc.structureVersion)return this.gateFail("structure");if(t.vptKey!==e.vpt.join(","))return this.gateFail("vpt");if(t.dpr!==e.dpr||t.sizeKey!==`${e.canvasEl.width}x${e.canvasEl.height}`)return this.gateFail("surface");if(t.artifactEpoch!==e.renderEpoch.value)return this.gateFail(`artifact-epoch(${e.renderEpoch.lastReason})`);let r=t.snap,o=e.doc.renderDirty;for(let i of o){if(i.isReferenceLine||er(i))continue;let s=r.quadSlots.get(i),a=r.meshSlots.get(i);if(!s&&!a)return this.gateFail("no-slot");let l=e.batch.instanceTotal,c=e.meshBatch.vertexTotal;if(s&&e.batch.rewindToSlot(s.start),a&&e.meshBatch.rewindToSlot(a.start),e.renderer.renderSceneNode(i),e.batch.instanceTotal!==(s?s.start+s.count:l))return this.gateFail("contract-quad");if(e.meshBatch.vertexTotal!==(a?a.start+a.count:c))return this.gateFail("contract-mesh");if(!e.renderer.flatFrame)return this.gateFail("isolated");if(e.batchOrder.hasNovelPaintReferences(r))return this.gateFail("repush-commands")}return t.artifactEpoch!==e.renderEpoch.value?this.gateFail(`artifact-epoch-late(${e.renderEpoch.lastReason})`):(e.batch.restoreTotals(r.quadTotal),e.meshBatch.restoreTotals(r.meshTotal),e.batchOrder.discardRecorded(),e.glyphAtlas.keepPagesForRetainedFrame(),e.batchOrder.replaySnapshot(r),this.gateOk(),!0)}captureSnapshot(){let{host:e}=this;if(!$a()){this.retained=null;return}let t=e.renderer.flatFrame,r=e.cropSessionController.active||e.expandSessionController.active||e.pathSessionController.active||e.warpSessionController.active,o=e.progressiveLoad.limit>=0&&e.progressiveLoad.limit<e.doc.nodes.length;if(!t||r||o||e.doc.editingNode){this.retained=null,this.logDebug(`snapshot 跳过(flat=${t} sessions=${r} progressive=${o} editing=${e.doc.editingNode!==null})`);return}let i=e.batchOrder.retained;if(this.retained=i?{snap:i,structureVersion:e.doc.structureVersion,vptKey:e.vpt.join(","),dpr:e.dpr,sizeKey:`${e.canvasEl.width}x${e.canvasEl.height}`,artifactEpoch:e.renderEpoch.value}:null,i&&Wn()){let s=e.glyphAtlas.stats();console.info("[retained] 快照收录",{commands:i.commands.length,quadSlots:i.quadSlots.size,meshSlots:i.meshSlots.size,structureVersion:e.doc.structureVersion,atlasPages:s.pages,artifactEpoch:e.renderEpoch.value,epochLastReason:e.renderEpoch.lastReason})}}noteFrameRendered(){this.lastFrameAnimated=this.host.renderer.frame.animationActive,this.lastFrameBakeMore=this.host.renderer.frame.bakeMore}invalidate(){this.retained=null}dispose(){this.retained=null}gateFail(e){return this.lastGateReason!==e&&(this.lastGateReason=e,Wn()&&console.info("[retained] 门链回退:",e)),!1}gateOk(){this.lastGateReason!==null&&(this.lastGateReason=null,Wn()&&console.info("[retained] 保留式帧恢复生效"))}logDebug(e){Wn()&&console.info("[retained]",e)}};var z0=`#version 300 es
|
|
256
|
+
}`,ra=(n,e,t)=>{let r=(a,l)=>{let u=n.createShader(a);return u?(n.shaderSource(u,l),n.compileShader(u),n.getShaderParameter(u,n.COMPILE_STATUS)?u:(console.error("[engine] shader compile failed:",n.getShaderInfoLog(u)),n.deleteShader(u),null)):null},o=r(n.VERTEX_SHADER,e),i=r(n.FRAGMENT_SHADER,t);if(!o||!i)return o&&n.deleteShader(o),i&&n.deleteShader(i),null;let s=n.createProgram();return s?(n.attachShader(s,o),n.attachShader(s,i),n.linkProgram(s),n.deleteShader(o),n.deleteShader(i),n.getProgramParameter(s,n.LINK_STATUS)?{program:s,uniforms:{view:n.getUniformLocation(s,"uView"),tex:n.getUniformLocation(s,"uTex"),penScale:n.getUniformLocation(s,"uPenScale"),segTex:n.getUniformLocation(s,"uSegTex"),paintMode:n.getUniformLocation(s,"uPaintMode"),paintInv:n.getUniformLocation(s,"uPaintInv"),paintA:n.getUniformLocation(s,"uPaintA"),paintB:n.getUniformLocation(s,"uPaintB"),fillTex:n.getUniformLocation(s,"uFillTex"),patInfo:n.getUniformLocation(s,"uPatInfo")}}:(console.error("[engine] program link failed:",n.getProgramInfoLog(s)),n.deleteProgram(s),null)):(n.deleteShader(o),n.deleteShader(i),null)};var Yr=n=>{let e=2166136261;for(let t=0;t<n.length;t++)e=Math.imul(e^Math.round(n[t]*256),16777619);return e>>>1},oa=class{constructor(e){this.gl=e}gl;tex=null;data=new Float32Array(0);rowOwners=[];rowHashes=[];rows=0;healthy=!0;ensureRows(e){if(!this.healthy)return!1;if(e<=this.rows)return!0;let t=this.gl;try{let r=new Float32Array(e*64*4);r.set(this.data);let o=this.tex??t.createTexture();if(!o)return this.healthy=!1,!1;for(t.activeTexture(t.TEXTURE2),t.bindTexture(t.TEXTURE_2D,o),t.texImage2D(t.TEXTURE_2D,0,t.RGBA32F,64,e,0,t.RGBA,t.FLOAT,r),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.activeTexture(t.TEXTURE0),this.tex=o,this.data=r;this.rowOwners.length<e;)this.rowOwners.push(null),this.rowHashes.push(0);return this.rows=e,!0}catch{return this.healthy=!1,!1}}writeRow(e,t,r){if(!this.healthy||e>=this.rows||t&&this.rowOwners[e]===t&&this.rowHashes[e]===r.hash)return;let o=e*64*4;this.data.fill(0,o,o+256),this.data.set(r.data.subarray(0,r.count*4),o),this.rowOwners[e]=t,this.rowHashes[e]=r.hash;let i=this.gl;i.activeTexture(i.TEXTURE2),i.bindTexture(i.TEXTURE_2D,this.tex),i.texSubImage2D(i.TEXTURE_2D,0,0,e,r.count,1,i.RGBA,i.FLOAT,this.data,o),i.activeTexture(i.TEXTURE0)}rowAt(e){return e>=this.rows?null:this.data.slice(e*64*4,(e+1)*64*4)}get texture(){return this.tex}get rowCount(){return this.rows}dispose(){this.tex&&this.gl.deleteTexture(this.tex),this.tex=null,this.data=new Float32Array(0),this.rowOwners=[],this.rowHashes=[],this.rows=0}};var Ve=24,Dm=new Float32Array(9),D0=4096,F0=new Float32Array([0,0,1,0,1,1,0,1]),O0=new Uint16Array([0,1,2,0,2,3]),en=class{gl;order=null;gpuRecords=new Map;ownerBlocks=new WeakMap;pendingSegments=[];pendingUploads=[];deferDraws=!1;frameSlots=null;drawnFrom=0;programInfo=null;vao=null;cornerBuffer=null;indexBuffer=null;instanceBuffer=null;instanceData=new Float32Array(D0*Ve);whiteTexture=null;segmentTable=null;instanceCount=0;currentTexture=null;currentGradient=null;viewMat=[1,0,0,1,0,0];penScale=1;disposed=!1;constructor(e){this.gl=e,this.init()}init(){let e=this.gl;if(this.programInfo=ra(e,Am,Lm),!this.programInfo){this.disposed=!0;return}this.whiteTexture=e.createTexture(),e.bindTexture(e.TEXTURE_2D,this.whiteTexture),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,1,1,0,e.RGBA,e.UNSIGNED_BYTE,new Uint8Array([255,255,255,255])),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),this.vao=e.createVertexArray(),e.bindVertexArray(this.vao),this.cornerBuffer=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.cornerBuffer),e.bufferData(e.ARRAY_BUFFER,F0,e.STATIC_DRAW),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,2,e.FLOAT,!1,0,0),this.indexBuffer=e.createBuffer(),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,this.indexBuffer),e.bufferData(e.ELEMENT_ARRAY_BUFFER,O0,e.STATIC_DRAW),this.instanceBuffer=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.instanceBuffer),e.bufferData(e.ARRAY_BUFFER,this.instanceData.byteLength,e.DYNAMIC_DRAW);let t=Ve*4,r=(o,i,s)=>{e.enableVertexAttribArray(o),e.vertexAttribPointer(o,i,e.FLOAT,!1,t,s*4),e.vertexAttribDivisor(o,1)};r(1,2,0),r(2,2,2),r(3,2,4),r(4,2,6),r(5,4,8),r(6,4,12),r(7,2,16),r(8,3,18),r(9,3,21),e.bindVertexArray(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA)}get valid(){return!this.disposed&&!!this.programInfo}rebuild(){this.release(),this.disposed=!1,this.init()}release(){let e=this.gl;this.whiteTexture&&e.deleteTexture(this.whiteTexture),this.segmentTable?.dispose(),this.segmentTable=null,this.instanceBuffer&&e.deleteBuffer(this.instanceBuffer),this.indexBuffer&&e.deleteBuffer(this.indexBuffer),this.cornerBuffer&&e.deleteBuffer(this.cornerBuffer),this.vao&&e.deleteVertexArray(this.vao),this.programInfo&&e.deleteProgram(this.programInfo.program),this.whiteTexture=null,this.instanceBuffer=null,this.indexBuffer=null,this.cornerBuffer=null,this.vao=null,this.programInfo=null,this.instanceCount=0,this.drawnFrom=0,this.currentTexture=null,this.currentGradient=null,this.pendingSegments=[],this.pendingUploads=[],this.gpuRecords.clear()}pushedTextures=new Set;begin(e,t=1){this.valid&&(this.viewMat=e,this.penScale=t,this.frameSlots=null,this.instanceCount=0,this.drawnFrom=0,this.currentTexture=null,this.currentGradient=null,this.pushedTextures.clear(),this.dropPendingSegments(),this.pendingUploads=[])}pushQuad(e,t,r,o,i,s=[0,0,1,1],a=null,l,u,c){if(!this.valid)return;this.order?.beforeQuadPush(),i!==this.currentTexture&&(this.flush(),this.currentTexture=i),this.instanceCount*Ve+Ve>this.instanceData.length&&this.grow();let h=this.instanceCount*Ve,d=this.instanceCount;this.pushedTextures.add(i);let f=this.instanceData,m=!0,p=l?this.ownerBlocks.get(l):void 0;p&&p.m0===e[0]&&p.m1===e[1]&&p.m2===e[2]&&p.m3===e[3]&&p.m4===e[4]&&p.m5===e[5]&&p.dx===t&&p.dy===r&&p.u0===s[0]&&p.u1===s[1]&&p.u2===s[2]&&p.u3===s[3]&&p.r0===(a?a[0]:0)&&p.r1===(a?a[1]:0)&&p.c0===o[0]&&p.c1===o[1]&&p.c2===o[2]&&p.c3===o[3]&&p.dashOn===(u?u[0]:0)&&p.dashCycle===(u?u[1]:0)&&p.dashPhase===(u?u[2]:0)&&p.segCount===(c?c.count:0)&&p.segHash===(c?c.hash:0)?(f.set(p.block,h),f[h+21]=d,f[h+22]=c?c.count:0,f[h+23]=c?c.hash:0,m=!1):(f[h]=e[0],f[h+1]=e[1],f[h+2]=e[2],f[h+3]=e[3],f[h+4]=e[4],f[h+5]=e[5],f[h+6]=t,f[h+7]=r,f[h+8]=s[0],f[h+9]=s[1],f[h+10]=s[2],f[h+11]=s[3],f[h+12]=o[0],f[h+13]=o[1],f[h+14]=o[2],f[h+15]=o[3],f[h+16]=a?a[0]:0,f[h+17]=a?a[1]:0,f[h+18]=u?u[0]:0,f[h+19]=u?u[1]:0,f[h+20]=u?u[2]:0,f[h+21]=d,f[h+22]=c?c.count:0,f[h+23]=c?c.hash:0,l&&this.ownerBlocks.set(l,{floatCount:Ve,m0:e[0],m1:e[1],m2:e[2],m3:e[3],m4:e[4],m5:e[5],dx:t,dy:r,u0:s[0],u1:s[1],u2:s[2],u3:s[3],r0:a?a[0]:0,r1:a?a[1]:0,c0:o[0],c1:o[1],c2:o[2],c3:o[3],dashOn:u?u[0]:0,dashCycle:u?u[1]:0,dashPhase:u?u[2]:0,segCount:c?c.count:0,segHash:c?c.hash:0,block:this.instanceData.slice(h,h+Ve)})),c&&this.segmentTable?.writeRow(d,l??null,c);let b=l?this.gpuRecords.get(l):void 0,x=m||!b||b.startFloat!==h||b.floatCount!==Ve;if(this.pendingSegments.push({owner:l??null,startFloat:h,floatCount:Ve,dirty:x}),x){let g=this.pendingUploads[this.pendingUploads.length-1];g&&g[1]===h?g[1]=h+Ve:this.pendingUploads.push([h,h+Ve])}if(this.instanceCount+=1,l){let g=this.frameSlots??=new Map,y=g.get(l);y&&y.start+y.count===this.instanceCount-1?y.count+=1:g.set(l,{start:this.instanceCount-1,count:1})}}pushPaintQuad(e,t,r,o,i,s=null){this.valid&&(this.order?.beforeQuadPush(),this.flush(),this.currentGradient=o,this.currentTexture=o.tex,this.pushQuad(e,t,r,[1,1,1,i],o.tex,[0,0,1,1],s),this.flush(),this.currentGradient=null)}flush(){if(!this.valid||this.instanceCount<=this.drawnFrom)return;if(this.deferDraws){let l={startInstance:this.drawnFrom,count:this.instanceCount-this.drawnFrom,texture:this.currentTexture,gradient:this.currentGradient};if(this.drawnFrom=this.instanceCount,this.order){this.order.recordDraw(this,l);return}this.uploadPending(),this.drawDeferred(l);return}let e=this.gl,{program:t,uniforms:r}=this.programInfo,o=this.instanceCount-this.drawnFrom;e.useProgram(t),e.bindVertexArray(this.vao);let i=new Float32Array([this.viewMat[0],this.viewMat[1],0,this.viewMat[2],this.viewMat[3],0,this.viewMat[4],this.viewMat[5],1]);e.uniformMatrix3fv(r.view,!1,i),e.uniform1f(r.penScale,this.penScale),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,this.currentTexture??this.whiteTexture),e.uniform1i(r.tex,0),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,this.segmentTable?.texture??this.whiteTexture),e.uniform1i(r.segTex,2),e.activeTexture(e.TEXTURE0),zr(e,r,this.currentGradient,1),e.bindBuffer(e.ARRAY_BUFFER,this.instanceBuffer);for(let[l,u]of this.pendingUploads)e.bufferSubData(e.ARRAY_BUFFER,l*4,this.instanceData,l,u-l),this.invalidateOverlappingRecords(l,u);this.pendingUploads=[];let s=Ve*4,a=this.drawnFrom*s;e.vertexAttribPointer(1,2,e.FLOAT,!1,s,a),e.vertexAttribPointer(2,2,e.FLOAT,!1,s,a+8),e.vertexAttribPointer(3,2,e.FLOAT,!1,s,a+16),e.vertexAttribPointer(4,2,e.FLOAT,!1,s,a+24),e.vertexAttribPointer(5,4,e.FLOAT,!1,s,a+32),e.vertexAttribPointer(6,4,e.FLOAT,!1,s,a+48),e.vertexAttribPointer(7,2,e.FLOAT,!1,s,a+64),e.vertexAttribPointer(8,3,e.FLOAT,!1,s,a+72),e.vertexAttribPointer(9,3,e.FLOAT,!1,s,a+84),e.drawElementsInstanced(e.TRIANGLES,6,e.UNSIGNED_SHORT,0,o),this.drawnFrom=this.instanceCount;for(let l of this.pendingSegments)l.owner&&this.gpuRecords.set(l.owner,{startFloat:l.startFloat,floatCount:l.floatCount});this.pendingSegments=[]}currentFrameSlots(){return this.frameSlots??new Map}rewindToSlot(e){this.instanceCount=e,this.drawnFrom>e&&(this.drawnFrom=e)}restoreTotals(e){this.instanceCount=e,this.drawnFrom=e}uploadPending(){if(!this.valid)return;let e=this.gl;e.bindBuffer(e.ARRAY_BUFFER,this.instanceBuffer);let t=this.pendingUploads;for(let r=0;r<t.length;r++){let[o,i]=t[r],s=t[r+1];if(s&&s[0]<=i+4096){s[0]=o;continue}e.bufferSubData(e.ARRAY_BUFFER,o*4,this.instanceData,o,i-o),this.invalidateOverlappingRecords(o,i)}this.pendingUploads=[];for(let r of this.pendingSegments)r.owner&&this.gpuRecords.set(r.owner,{startFloat:r.startFloat,floatCount:r.floatCount});this.pendingSegments=[]}dropPendingSegments(){for(let e of this.pendingSegments)e.dirty&&e.owner&&this.gpuRecords.delete(e.owner);this.pendingSegments=[]}invalidateOverlappingRecords(e,t){if(this.gpuRecords.size===0)return;let r=new Set;for(let o of this.pendingSegments)o.owner&&o.startFloat<t&&e<o.startFloat+o.floatCount&&r.add(o.owner);for(let[o,i]of this.gpuRecords)!r.has(o)&&i.startFloat<t&&e<i.startFloat+i.floatCount&&this.gpuRecords.delete(o)}drawDeferred(e){if(!this.valid)return;let t=this.gl,{program:r,uniforms:o}=this.programInfo;t.useProgram(r),t.bindVertexArray(this.vao),Dm.set([this.viewMat[0],this.viewMat[1],0,this.viewMat[2],this.viewMat[3],0,this.viewMat[4],this.viewMat[5],1]),t.uniformMatrix3fv(o.view,!1,Dm),t.uniform1f(o.penScale,this.penScale),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,e.texture??this.whiteTexture),t.uniform1i(o.tex,0),t.activeTexture(t.TEXTURE2),t.bindTexture(t.TEXTURE_2D,this.segmentTable?.texture??this.whiteTexture),t.uniform1i(o.segTex,2),t.activeTexture(t.TEXTURE0),zr(t,o,e.gradient,1),t.bindBuffer(t.ARRAY_BUFFER,this.instanceBuffer);let i=Ve*4,s=e.startInstance*i;t.vertexAttribPointer(1,2,t.FLOAT,!1,i,s),t.vertexAttribPointer(2,2,t.FLOAT,!1,i,s+8),t.vertexAttribPointer(3,2,t.FLOAT,!1,i,s+16),t.vertexAttribPointer(4,2,t.FLOAT,!1,i,s+24),t.vertexAttribPointer(5,4,t.FLOAT,!1,i,s+32),t.vertexAttribPointer(6,4,t.FLOAT,!1,i,s+48),t.vertexAttribPointer(7,2,t.FLOAT,!1,i,s+64),t.vertexAttribPointer(8,3,t.FLOAT,!1,i,s+72),t.vertexAttribPointer(9,3,t.FLOAT,!1,i,s+84),t.drawElementsInstanced(t.TRIANGLES,6,t.UNSIGNED_SHORT,0,e.count)}grow(){let e=this.gl,t=new Float32Array(this.instanceData.length*2);t.set(this.instanceData),this.instanceData=t,this.gpuRecords.clear(),this.pendingUploads=[[0,this.instanceCount*Ve]],e.bindBuffer(e.ARRAY_BUFFER,this.instanceBuffer),e.bufferData(e.ARRAY_BUFFER,this.instanceData.byteLength,e.DYNAMIC_DRAW),this.segmentTable?.ensureRows(this.instanceData.length/Ve)}canPushSegments(){return this.valid?(this.segmentTable||(this.segmentTable=new oa(this.gl)),this.segmentTable.ensureRows(this.instanceData.length/Ve)):!1}get drawnInstances(){return this.instanceCount}get instanceTotal(){return this.instanceCount}dispose(){this.disposed||(this.disposed=!0,this.release())}};var ia=class{constructor(e,t){this.quad=e;this.mesh=t}quad;mesh;seq=0;quadSeq=-1;meshSeq=-1;deferred=[];requestSnapshot=!1;retained=null;beforeQuadPush(){this.meshSeq>this.quadSeq&&(this.meshSeq=-1,this.mesh.flush()),this.quadSeq=++this.seq}beforeMeshPush(){this.quadSeq>this.meshSeq&&(this.quadSeq=-1,this.quad.flush()),this.meshSeq=++this.seq}recordDraw(e,t){this.deferred.push({batch:e,cmd:t})}recordState(e){this.quadSeq>=0&&(this.meshSeq<0||this.quadSeq>this.meshSeq)&&(this.quadSeq=-1,this.quad.flush()),this.meshSeq>=0&&(this.meshSeq=-1,this.mesh.flush()),this.quad.deferDraws&&this.mesh.deferDraws?this.deferred.push({fn:e}):e()}hasRecordedCommands(){return this.deferred.length>0}hasNovelPaintReferences(e){if(this.quad.pushedTextures.size){let t=new Set;for(let r of e.commands)"fn"in r||r.batch instanceof en&&t.add(r.cmd.texture);for(let r of this.quad.pushedTextures)if(!t.has(r))return!0}if(this.mesh.pushedGradients.size){let t=new Set;for(let r of e.commands)"fn"in r||r.batch instanceof en||t.add(r.cmd.gradient);for(let r of this.mesh.pushedGradients)if(!t.has(r))return!0}return!1}flushAll(){this.quadSeq>=0&&(this.meshSeq<0||this.quadSeq>this.meshSeq)&&(this.quadSeq=-1,this.quad.flush()),this.meshSeq>=0&&(this.meshSeq=-1,this.mesh.flush()),this.executeDeferred()}executeDeferred(){if(this.requestSnapshot&&(this.requestSnapshot=!1,this.retained={commands:this.deferred,quadSlots:this.quad.currentFrameSlots(),meshSlots:this.mesh.currentFrameSlots(),quadTotal:this.quad.instanceTotal,meshTotal:this.mesh.vertexTotal}),!!this.deferred.length){this.quad.uploadPending(),this.mesh.uploadPending();for(let e of this.deferred)"fn"in e?e.fn():(e.batch instanceof en,e.batch.drawDeferred(e.cmd));this.deferred=[]}}reset(){this.seq=0,this.quadSeq=-1,this.meshSeq=-1,this.deferred=[]}discardRecorded(){this.deferred=[]}replaySnapshot(e){this.quad.uploadPending(),this.mesh.uploadPending();for(let t of e.commands)"fn"in t?t.fn():(t.batch instanceof en,t.batch.drawDeferred(t.cmd))}};var Fm=new Float32Array(9),Rt=8,B0=8192,sa=class{gl;order=null;ownerBlocks=new WeakMap;gpuRecords=new Map;pendingSegments=[];pendingUploads=[];deferDraws=!1;frameSlots=null;drawnFrom=0;programInfo=null;vao=null;vertexBuffer=null;whiteTex=null;vertexData=new Float32Array(B0*Rt);vertexCount=0;currentGradient=null;viewMat=[1,0,0,1,0,0];disposed=!1;constructor(e){this.gl=e,this.init()}init(){let e=this.gl;if(this.programInfo=ra(e,Im,_m),!this.programInfo){this.disposed=!0;return}this.vao=e.createVertexArray(),e.bindVertexArray(this.vao),this.vertexBuffer=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer),e.bufferData(e.ARRAY_BUFFER,this.vertexData.byteLength,e.DYNAMIC_DRAW),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,2,e.FLOAT,!1,Rt*4,0),e.enableVertexAttribArray(1),e.vertexAttribPointer(1,4,e.FLOAT,!1,Rt*4,8),e.enableVertexAttribArray(2),e.vertexAttribPointer(2,2,e.FLOAT,!1,Rt*4,24),e.bindVertexArray(null),this.whiteTex=e.createTexture(),e.bindTexture(e.TEXTURE_2D,this.whiteTex),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,1,1,0,e.RGBA,e.UNSIGNED_BYTE,new Uint8Array([255,255,255,255])),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA)}get valid(){return!this.disposed&&!!this.programInfo}rebuild(){this.release(),this.disposed=!1,this.init()}release(){let e=this.gl;this.vertexBuffer&&e.deleteBuffer(this.vertexBuffer),this.vao&&e.deleteVertexArray(this.vao),this.programInfo&&e.deleteProgram(this.programInfo.program),this.whiteTex&&e.deleteTexture(this.whiteTex),this.vertexBuffer=null,this.vao=null,this.programInfo=null,this.whiteTex=null,this.vertexCount=0,this.drawnFrom=0,this.currentGradient=null,this.pendingSegments=[],this.pendingUploads=[],this.gpuRecords.clear()}pushedGradients=new Set;begin(e){this.valid&&(this.viewMat=e,this.frameSlots=null,this.vertexCount=0,this.drawnFrom=0,this.currentGradient=null,this.pushedGradients.clear(),this.dropPendingSegments(),this.pendingUploads=[])}pushMesh(e,t,r,o,i,s){if(!this.valid)return;this.order?.beforeMeshPush(),(!!i!=!!this.currentGradient||i&&this.currentGradient&&i!==this.currentGradient)&&(this.flush(),this.currentGradient=i??null);let a=o.length/3,l=a*3*Rt;this.vertexCount*Rt+l>this.vertexData.length&&this.grow(this.vertexCount*Rt+l);let u=this.vertexCount*Rt;this.pushedGradients.add(i??null);let c=!0,h=s?this.ownerBlocks.get(s):void 0;if(h&&h.floatCount===l&&h.verts===r&&h.triangles===o&&h.m0===e[0]&&h.m1===e[1]&&h.m2===e[2]&&h.m3===e[3]&&h.m4===e[4]&&h.m5===e[5]&&h.c0===t[0]&&h.c1===t[1]&&h.c2===t[2]&&h.c3===t[3])this.vertexData.set(h.block,u),c=!1;else{let p=e,b=this.vertexData,x=u;for(let g=0;g<o.length;g++){let y=o[g]*2,v=r[y],S=r[y+1];b[x]=p[0]*v+p[2]*S+p[4],b[x+1]=p[1]*v+p[3]*S+p[5],b[x+2]=t[0],b[x+3]=t[1],b[x+4]=t[2],b[x+5]=t[3],b[x+6]=v,b[x+7]=S,x+=Rt}s&&this.ownerBlocks.set(s,{floatCount:l,verts:r,triangles:o,m0:e[0],m1:e[1],m2:e[2],m3:e[3],m4:e[4],m5:e[5],c0:t[0],c1:t[1],c2:t[2],c3:t[3],block:this.vertexData.slice(u,u+l)})}let d=s?this.gpuRecords.get(s):void 0,f=d&&d.startFloat===u&&d.floatCount===l,m=c||!f;if(this.pendingSegments.push({owner:s??null,startFloat:u,floatCount:l,dirty:m}),m){let p=this.pendingUploads[this.pendingUploads.length-1];p&&p[1]===u?p[1]=u+l:this.pendingUploads.push([u,u+l])}if(this.vertexCount+=a*3,s){let p=this.frameSlots??=new Map,b=a*3,x=p.get(s);x&&x.start+x.count===this.vertexCount-b?x.count+=b:p.set(s,{start:this.vertexCount-b,count:b})}}flush(){if(!this.valid||this.vertexCount<=this.drawnFrom)return;if(this.deferDraws){let i={startVertex:this.drawnFrom,count:this.vertexCount-this.drawnFrom,gradient:this.currentGradient};if(this.drawnFrom=this.vertexCount,this.order){this.order.recordDraw(this,i);return}this.uploadPending(),this.drawDeferred(i);return}let e=this.gl,{program:t,uniforms:r}=this.programInfo;e.useProgram(t),e.bindVertexArray(this.vao);let o=new Float32Array([this.viewMat[0],this.viewMat[1],0,this.viewMat[2],this.viewMat[3],0,this.viewMat[4],this.viewMat[5],1]);e.uniformMatrix3fv(r.view,!1,o),zr(e,r,this.currentGradient,0),!this.currentGradient&&this.whiteTex&&(e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,this.whiteTex),e.uniform1i(r.fillTex,0)),e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer);for(let[i,s]of this.pendingUploads)e.bufferSubData(e.ARRAY_BUFFER,i*4,this.vertexData,i,s-i),this.invalidateOverlappingRecords(i,s);this.pendingUploads=[],e.drawArrays(e.TRIANGLES,this.drawnFrom,this.vertexCount-this.drawnFrom),this.drawnFrom=this.vertexCount;for(let i of this.pendingSegments)i.owner&&this.gpuRecords.set(i.owner,{startFloat:i.startFloat,floatCount:i.floatCount});this.pendingSegments=[]}currentFrameSlots(){return this.frameSlots??new Map}rewindToSlot(e){this.vertexCount=e,this.drawnFrom>e&&(this.drawnFrom=e)}restoreTotals(e){this.vertexCount=e,this.drawnFrom=e}uploadPending(){if(!this.valid)return;let e=this.gl;e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer);let t=this.pendingUploads;for(let r=0;r<t.length;r++){let[o,i]=t[r],s=t[r+1];if(s&&s[0]<=i+4096){s[0]=o;continue}e.bufferSubData(e.ARRAY_BUFFER,o*4,this.vertexData,o,i-o),this.invalidateOverlappingRecords(o,i)}this.pendingUploads=[];for(let r of this.pendingSegments)r.owner&&this.gpuRecords.set(r.owner,{startFloat:r.startFloat,floatCount:r.floatCount});this.pendingSegments=[]}dropPendingSegments(){for(let e of this.pendingSegments)e.dirty&&e.owner&&this.gpuRecords.delete(e.owner);this.pendingSegments=[]}invalidateOverlappingRecords(e,t){if(this.gpuRecords.size===0)return;let r=new Set;for(let o of this.pendingSegments)o.owner&&o.startFloat<t&&e<o.startFloat+o.floatCount&&r.add(o.owner);for(let[o,i]of this.gpuRecords)!r.has(o)&&i.startFloat<t&&e<i.startFloat+i.floatCount&&this.gpuRecords.delete(o)}drawDeferred(e){if(!this.valid)return;let t=this.gl,{program:r,uniforms:o}=this.programInfo;t.useProgram(r),t.bindVertexArray(this.vao),Fm.set([this.viewMat[0],this.viewMat[1],0,this.viewMat[2],this.viewMat[3],0,this.viewMat[4],this.viewMat[5],1]),t.uniformMatrix3fv(o.view,!1,Fm),zr(t,o,e.gradient,0),!e.gradient&&this.whiteTex&&(t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,this.whiteTex),t.uniform1i(o.fillTex,0)),t.drawArrays(t.TRIANGLES,e.startVertex,e.count)}grow(e){let t=this.gl,r=this.vertexData.length;for(;r<e;)r*=2;let o=new Float32Array(r);o.set(this.vertexData.subarray(0,this.vertexCount*Rt)),this.vertexData=o,t.bindBuffer(t.ARRAY_BUFFER,this.vertexBuffer),t.bufferData(t.ARRAY_BUFFER,this.vertexData.byteLength,t.DYNAMIC_DRAW),this.gpuRecords.clear(),this.pendingUploads=[[0,this.vertexCount*Rt]]}get drawnVertices(){return this.vertexCount}get vertexTotal(){return this.vertexCount}dispose(){this.disposed||(this.disposed=!0,this.release())}};var Ht=Ql,H0=[Ht[0],Ht[1],Ht[2],.14],Wc=[1,1,1,1],G0=2,Wm=[238/255,238/255,238/255,128/255],Hm=[24/255,144/255,1,128/255],$o=20,kn=20,aa=null,X0=()=>{if(aa)return aa;let n=e=>{let t=document.createElement("canvas");t.width=$o,t.height=$o;let r=t.getContext("2d");if(!r)return t;let o=$o/2;r.beginPath(),r.arc(o,o,8,0,Math.PI*2),r.fillStyle=e?"#2f6fed":"#ffffff",r.fill(),r.lineWidth=1.5,r.strokeStyle="#2f6fed",r.stroke();let i=4;return r.beginPath(),r.moveTo(o-i,o),r.lineTo(o+i,o),r.moveTo(o,o-i),r.lineTo(o,o+i),r.lineWidth=1.5,r.strokeStyle=e?"#ffffff":"#2f6fed",r.stroke(),t};return aa={normal:n(!1),hover:n(!0)},aa},z0=n=>n.columnWidths.reduce((e,t)=>e+t,0)+(n.cols-1)*n.cellSpacing,Y0=n=>n.rowHeights.reduce((e,t)=>e+t,0)+(n.rows-1)*n.cellSpacing,Gm=(n,e,t)=>{let r=0;for(let o=0;o<t;o++)r+=n[o]+e;return r},la=null,U0=()=>{if(la)return la;let n=e=>{let t=document.createElement("canvas");t.width=kn*2,t.height=kn*2;let r=t.getContext("2d");if(!r)return t;r.scale(2,2),r.fillStyle=e?"#1890ff20":"#eeeeee99",r.fillRect(0,0,kn-1,kn-1);let o=kn/2-.5,i=kn/2-.5,s=kn*.25,a=kn*.18;r.strokeStyle=e?"#1890ff":"#888888",r.lineWidth=1.5,r.lineCap="round";for(let l=-1;l<=1;l++)r.beginPath(),r.moveTo(o-s,i+l*a),r.lineTo(o+s,i+l*a),r.stroke();return t};return la={normal:n(!1),hover:n(!0)},la},Xm=(n,e)=>{let t=[],r=n.tableView,o=n.cellMap,i=n.matrix,s=n.objectScale,a=z0(r)/2,l=Y0(r)/2,u=Mt/e/Math.max(s.x,1e-6),c=Mt/e/Math.max(s.y,1e-6);for(let x of n.selectedCells){let g=o.get(`${x.row},${x.col}`);if(g?.isMerged)continue;let y=g?.rowspan??1,v=g?.colspan??1,S=wo(r,{r1:x.row,r2:x.row+y-1,c1:x.col,c2:x.col+v-1}),w=S.left+S.width/2,R=S.top+S.height/2;t.push({matrix:V(i,[1,0,0,1,w,R]),dims:{x:S.width,y:S.height},color:H0}),t.push({matrix:V(i,[1,0,0,1,w,S.top]),dims:{x:S.width+2*u,y:c},color:Ht}),t.push({matrix:V(i,[1,0,0,1,w,S.top+S.height]),dims:{x:S.width+2*u,y:c},color:Ht}),t.push({matrix:V(i,[1,0,0,1,S.left,R]),dims:{x:u,y:S.height+2*c},color:Ht}),t.push({matrix:V(i,[1,0,0,1,S.left+S.width,R]),dims:{x:u,y:S.height+2*c},color:Ht})}if(n.hoveredBorder){let{type:x,position:g}=n.hoveredBorder,y=x==="col"?Q(i,g,-l):Q(i,-a,g),v=x==="col"?Q(i,g,l):Q(i,a,g);t.push(Re(y,v,G0/e,Ht))}let h=-n.dims.x/2,d=-n.dims.y/2,f=20/(e*Math.max(s.x,1e-6)),m=20/(e*Math.max(s.y,1e-6)),p=kr(o,n.selectedCells);for(let x=0;x<r.rows;x++){let g=Gm(r.rowHeights,r.cellSpacing,x)-l,y=r.rowHeights[x],v=n.hoveredStrip?.kind==="row"&&n.hoveredStrip.index===x?!0:p.rows.has(x);t.push({matrix:V(i,[1,0,0,1,h-f/2,g+y/2]),dims:{x:f,y},color:v?Hm:Wm})}for(let x=0;x<r.cols;x++){let g=Gm(r.columnWidths,r.cellSpacing,x)-a,y=r.columnWidths[x],v=n.hoveredStrip?.kind==="col"&&n.hoveredStrip.index===x?!0:p.cols.has(x);t.push({matrix:V(i,[1,0,0,1,g+y/2,d-m/2]),dims:{x:y,y:m},color:v?Hm:Wm})}{let x=U0();t.push({matrix:V(i,[1,0,0,1,h-f/2,d-m/2]),dims:{x:f,y:m},color:Wc,texture:n.hoveredDragHandle?x.hover:x.normal})}let b=n.hoveredIndicator??(n.borderDragging?null:n.hoveredBorder);if(b){let x=X0(),g=b.type==="col";t.push({matrix:V(i,[1,0,0,1,g?b.position:-a-15,g?-l-15:b.position]),dims:{x:$o/(e*Math.max(s.x,1e-6)),y:$o/(e*Math.max(s.y,1e-6))},color:Wc,texture:n.hoveredIndicator?x.hover:x.normal})}if(n.selectedCells.length&&!n.editingCell&&!n.isFullCellSelection){let x=n.selectionBoundsRect;if(x){let g=x.left+x.width,y=x.top+x.height,v=Mn/e/Math.max(s.x,1e-6),S=Mn/e/Math.max(s.y,1e-6),w=(Mn-2*Mt)/e/Math.max(s.x,1e-6),R=(Mn-2*Mt)/e/Math.max(s.y,1e-6);t.push({matrix:V(i,[1,0,0,1,g,y]),dims:{x:v,y:S},color:Ht}),t.push({matrix:V(i,[1,0,0,1,g,y]),dims:{x:w,y:R},color:n.hoveredRangeHandle?Ht:Wc})}}return t};var $0=(n,e,t,r)=>{let o=n.nodes.filter(h=>Ze(h)&&h.visible&&h.raw.visible!==!1);if(!o.length)return[];let i=e[0],s=-e[4]/i,a=-e[5]/i,l=t/i,u=r/i,c=[];for(let h of o){let d=h.raw,f=ee(typeof d.stroke=="string"?d.stroke:"pink"),m=typeof d.opacity=="number"?d.opacity:1,p=[f[0],f[1],f[2],f[3]*m],b=Math.max(Number(d.strokeWidth)||1,1.2/i),x=h.bounds;if(h.dims.y===0){let g=(x.top+x.bottom)/2;c.push({matrix:[1,0,0,1,s+l/2,g],dims:{x:l,y:b},color:p})}else if(h.dims.x===0){let g=(x.left+x.right)/2;c.push({matrix:[1,0,0,1,g,a+u/2],dims:{x:b,y:u},color:p})}}return c},zm=n=>{let{doc:e,zoom:t,marquee:r,textEdit:o,snapOverlay:i,ruler:s}=n,a=n.rotate??null,l=o.node,u=!l&&!r&&e.selection.length===1&&e.selection[0]instanceof le?e.selection[0]:null,c=l?[...n.cellEditOverlayOnly?[]:Cn(l.aCoords,t),...o.quads]:r?Ad(r,t):u?.editingMask?Nd(u,t,a):kd(e,t,a,n.mobileControls===!0),h=l&&e.selection.length===1?e.selection[0]:null;l&&h instanceof J&&h.containsDeep(l)&&(c=[...c,...gs(h.aCoords,t)]),!l&&!r&&e.selection.length===1&&e.selection[0]instanceof te&&(c=[...c,...Xm(e.selection[0],t)]);let d=e.seamHover;if(u&&d&&d.puzzle===u&&(c=[...c,...Id(Ld(d.puzzle,d.mask,d.handle),t)]),e.hovered&&!r&&!Ze(e.hovered)&&(c=[...c,..._d(e.hovered,t)]),c=[...c,...i],s){c=[...c,...$0(e,s.vpt,s.cssWidth,s.cssHeight)];let f=e.nodes.find(p=>p.raw.id===yn),m=f&&typeof f.raw.width=="number"&&typeof f.raw.height=="number"?{left:f.raw.left??0,top:f.raw.top??0,width:f.raw.width,height:f.raw.height}:null;c=[...c,...jd({vpt:s.vpt,cssWidth:s.cssWidth,cssHeight:s.cssHeight,workspaceRect:m,referenceLine:s.referenceLine??null,selectionRects:e.selection.filter(p=>!Ze(p)).map(p=>({left:p.bounds.left,top:p.bounds.top,width:p.bounds.right-p.bounds.left,height:p.bounds.bottom-p.bounds.top}))})]}return c};function Ym(n,e,t,r,o){for(let i=0;i<o;i++){let s=t[i];if(!Ze(s)&&!tr(s)){if(r&&s===r.target)for(let a of r.underlay())n.pushQuad(a.matrix,a.dims.x,a.dims.y,a.color,null);e.renderSceneNode(s)}}}function Um(n,e){for(let t of e)tr(t)&&t.visible&&n.renderSceneNode(t)}function $m(n){let e=n.doc.editingNode;if(n.cropSessionController.active){jo(n,n.cropSessionController.buildOverlay(n.zoom))&&n.requestRenderAll();return}if(n.expandSessionController.active){jo(n,n.expandSessionController.buildOverlay(n.zoom))&&n.requestRenderAll();return}if(n.pathSessionController.active){jo(n,n.pathSessionController.buildOverlay(n.zoom))&&n.requestRenderAll();return}if(n.warpSessionController.active){jo(n,n.warpSessionController.buildOverlay())&&n.requestRenderAll();return}let t=zm({doc:n.doc,zoom:n.zoom,marquee:n.marquee,textEdit:{node:e,quads:e?n.textEditing.buildOverlay():[]},cellEditOverlayOnly:e!==null&&n.tableCellEditing.isOverlay(e),snapOverlay:n.snapGuide.buildOverlay(n.zoom),rotate:n.rotateDrag,mobileControls:n.mobileControls,ruler:n.rulerVisible?{vpt:n.vpt,cssWidth:n.cssWidth,cssHeight:n.cssHeight,referenceLine:n.referenceLineDrag}:null});jo(n,t),n.renderer.frame.animationActive&&n.requestRenderAll()}function jo(n,e){for(let t of e)n.batch.pushQuad(t.matrix,t.dims.x,t.dims.y,t.color,t.texture?n.textures.get(t.texture):null);return n.batch.flush(),n.batch.deferDraws=!1,n.meshBatch.deferDraws=!1,n.batchOrder.executeDeferred(),n.renderer.frame.animationActive}var ca=class{constructor(e){this.host=e}host;limit=-1;rafId=null;deadline=0;rendered=!1;start(e=1e3,t=800){if(!this.host.alive())return;let r=this.host.nodeCount();r<e||(this.rafId!==null&&cancelAnimationFrame(this.rafId),this.limit=Math.min(e,r),this.rendered=!1,this.deadline=performance.now()+t,this.rafId=requestAnimationFrame(()=>this.step()))}step(){if(this.rafId=null,this.limit<0||!this.host.alive())return;let e=this.host.nodeCount();if(this.limit>=e){this.limit=-1,this.host.onProgressiveDone(e);return}let t=performance.now();this.host.render(),this.rendered=!0;let r=performance.now()-t,o=r>1?Math.min(4,Math.max(.5,20/r)):2;if(this.limit=Math.min(e,Math.max(this.limit+1,Math.round(this.limit*(1+o)))),this.limit>=e){this.host.render(),this.limit=-1,this.host.onProgressiveDone(e);return}this.rafId=requestAnimationFrame(()=>this.step())}absorbExternalRenderRequest(){this.rendered&&performance.now()>this.deadline&&this.limit>=0&&this.limit<this.host.nodeCount()&&(this.limit=this.host.nodeCount())}dispose(){this.rafId!==null&&cancelAnimationFrame(this.rafId),this.rafId=null,this.limit=-1,this.rendered=!1}};var ua=class{constructor(e){this.host=e}host;retained=null;lastFrameAnimated=!1;lastFrameBakeMore=!1;lastGateReason=null;tryRetainedFrame(){let{host:e}=this;if(e.renderer.flatFrame=!0,!ja())return this.gateFail("flag-off");let t=this.retained;if(!t)return this.gateFail("no-snapshot");if(this.lastFrameAnimated)return this.gateFail("animating");if(this.lastFrameBakeMore)return this.gateFail("bake-continue");if(e.cropSessionController.active||e.expandSessionController.active||e.pathSessionController.active||e.warpSessionController.active)return this.gateFail("session");if(e.progressiveLoad.limit>=0&&e.progressiveLoad.limit<e.doc.nodes.length)return this.gateFail("progressive");if(e.doc.editingNode)return this.gateFail("editing");if(t.structureVersion!==e.doc.structureVersion)return this.gateFail("structure");if(t.vptKey!==e.vpt.join(","))return this.gateFail("vpt");if(t.dpr!==e.dpr||t.sizeKey!==`${e.canvasEl.width}x${e.canvasEl.height}`)return this.gateFail("surface");if(t.artifactEpoch!==e.renderEpoch.value)return this.gateFail(`artifact-epoch(${e.renderEpoch.lastReason})`);let r=t.snap,o=e.doc.renderDirty;for(let i of o){if(i.isReferenceLine||tr(i))continue;let s=r.quadSlots.get(i),a=r.meshSlots.get(i);if(!s&&!a)return this.gateFail("no-slot");let l=e.batch.instanceTotal,u=e.meshBatch.vertexTotal;if(s&&e.batch.rewindToSlot(s.start),a&&e.meshBatch.rewindToSlot(a.start),e.renderer.renderSceneNode(i),e.batch.instanceTotal!==(s?s.start+s.count:l))return this.gateFail("contract-quad");if(e.meshBatch.vertexTotal!==(a?a.start+a.count:u))return this.gateFail("contract-mesh");if(!e.renderer.flatFrame)return this.gateFail("isolated");if(e.batchOrder.hasNovelPaintReferences(r))return this.gateFail("repush-commands")}return t.artifactEpoch!==e.renderEpoch.value?this.gateFail(`artifact-epoch-late(${e.renderEpoch.lastReason})`):(e.batch.restoreTotals(r.quadTotal),e.meshBatch.restoreTotals(r.meshTotal),e.batchOrder.discardRecorded(),e.glyphAtlas.keepPagesForRetainedFrame(),e.batchOrder.replaySnapshot(r),this.gateOk(),!0)}captureSnapshot(){let{host:e}=this;if(!ja()){this.retained=null;return}let t=e.renderer.flatFrame,r=e.cropSessionController.active||e.expandSessionController.active||e.pathSessionController.active||e.warpSessionController.active,o=e.progressiveLoad.limit>=0&&e.progressiveLoad.limit<e.doc.nodes.length;if(!t||r||o||e.doc.editingNode){this.retained=null,this.logDebug(`snapshot 跳过(flat=${t} sessions=${r} progressive=${o} editing=${e.doc.editingNode!==null})`);return}let i=e.batchOrder.retained;if(this.retained=i?{snap:i,structureVersion:e.doc.structureVersion,vptKey:e.vpt.join(","),dpr:e.dpr,sizeKey:`${e.canvasEl.width}x${e.canvasEl.height}`,artifactEpoch:e.renderEpoch.value}:null,i&&Hn()){let s=e.glyphAtlas.stats();console.info("[retained] 快照收录",{commands:i.commands.length,quadSlots:i.quadSlots.size,meshSlots:i.meshSlots.size,structureVersion:e.doc.structureVersion,atlasPages:s.pages,artifactEpoch:e.renderEpoch.value,epochLastReason:e.renderEpoch.lastReason})}}noteFrameRendered(){this.lastFrameAnimated=this.host.renderer.frame.animationActive,this.lastFrameBakeMore=this.host.renderer.frame.bakeMore}invalidate(){this.retained=null}dispose(){this.retained=null}gateFail(e){return this.lastGateReason!==e&&(this.lastGateReason=e,Hn()&&console.info("[retained] 门链回退:",e)),!1}gateOk(){this.lastGateReason!==null&&(this.lastGateReason=null,Hn()&&console.info("[retained] 保留式帧恢复生效"))}logDebug(e){Hn()&&console.info("[retained]",e)}};var j0=`#version 300 es
|
|
257
257
|
out vec2 vUv;
|
|
258
258
|
void main() {
|
|
259
259
|
vec2 p = vec2((gl_VertexID << 1) & 2, gl_VertexID & 2);
|
|
260
260
|
vUv = p;
|
|
261
261
|
gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);
|
|
262
|
-
}`,
|
|
262
|
+
}`,V0=`#version 300 es
|
|
263
263
|
precision mediump float;
|
|
264
264
|
in vec2 vUv;
|
|
265
265
|
uniform sampler2D uSrc;
|
|
@@ -284,13 +284,13 @@ ma = uCovers;
|
|
|
284
284
|
factor *= mix(ma, 1.0 - ma, uInvert);
|
|
285
285
|
}
|
|
286
286
|
outColor = vec4(src.rgb * factor, src.a * factor);
|
|
287
|
-
}`,
|
|
287
|
+
}`,ha=class{fb=null;tex=null;prog=null;w=0;h=0;vao=null;boundFb=null;stencilRb=null;savedStencilEnabled=!1;savedStencilFunc=0;savedStencilRef=0;savedStencilMask=0;ensureProgram(e){if(this.prog)return;let t=(s,a)=>{let l=e.createShader(s);return l?(e.shaderSource(l,a),e.compileShader(l),e.getShaderParameter(l,e.COMPILE_STATUS)?l:(console.warn("[GLIsolator] shader:",e.getShaderInfoLog(l)),e.deleteShader(l),null)):null},r=t(e.VERTEX_SHADER,j0),o=t(e.FRAGMENT_SHADER,V0),i=e.createProgram();if(!(!r||!o||!i)){if(e.attachShader(i,r),e.attachShader(i,o),e.linkProgram(i),e.deleteShader(r),e.deleteShader(o),!e.getProgramParameter(i,e.LINK_STATUS)){console.warn("[GLIsolator] link:",e.getProgramInfoLog(i));return}this.prog=i,this.vao=e.createVertexArray()}}ensureSize(e,t,r){this.fb&&this.w===t&&this.h===r||(this.fb&&e.deleteFramebuffer(this.fb),this.tex&&e.deleteTexture(this.tex),this.stencilRb&&e.deleteRenderbuffer(this.stencilRb),this.tex=e.createTexture(),e.bindTexture(e.TEXTURE_2D,this.tex),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,t,r,0,e.RGBA,e.UNSIGNED_BYTE,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),this.fb=e.createFramebuffer(),e.bindFramebuffer(e.FRAMEBUFFER,this.fb),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,this.tex,0),this.stencilRb=e.createRenderbuffer(),this.stencilRb&&(e.bindRenderbuffer(e.RENDERBUFFER,this.stencilRb),e.renderbufferStorage(e.RENDERBUFFER,e.DEPTH24_STENCIL8,t,r),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_STENCIL_ATTACHMENT,e.RENDERBUFFER,this.stencilRb),e.bindRenderbuffer(e.RENDERBUFFER,null)),e.bindFramebuffer(e.FRAMEBUFFER,null),this.w=t,this.h=r)}begin(e,t,r){return this.boundFb=e.getParameter(e.FRAMEBUFFER_BINDING),this.ensureProgram(e),!this.prog||(this.ensureSize(e,t,r),!this.fb)?!1:(this.savedStencilEnabled=e.isEnabled(e.STENCIL_TEST),this.savedStencilEnabled&&(this.savedStencilFunc=e.getParameter(e.STENCIL_FUNC),this.savedStencilRef=e.getParameter(e.STENCIL_REF),this.savedStencilMask=e.getParameter(e.STENCIL_VALUE_MASK)),e.bindFramebuffer(e.FRAMEBUFFER,this.fb),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),this.stencilRb&&(e.clearStencil(0),e.clear(e.STENCIL_BUFFER_BIT)),e.disable(e.STENCIL_TEST),!0)}end(e){e.bindFramebuffer(e.FRAMEBUFFER,this.boundFb),this.savedStencilEnabled?e.enable(e.STENCIL_TEST):e.disable(e.STENCIL_TEST),this.savedStencilEnabled&&e.stencilFunc(this.savedStencilFunc,this.savedStencilRef,this.savedStencilMask)}composite(e,t,r){!this.prog||!this.tex||(e.useProgram(this.prog),e.bindVertexArray(this.vao),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,this.tex),e.uniform1i(e.getUniformLocation(this.prog,"uSrc"),0),e.uniform1f(e.getUniformLocation(this.prog,"uOpacity"),t),r?(e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,r.tex),e.uniform1i(e.getUniformLocation(this.prog,"uMask"),1),e.uniformMatrix3fv(e.getUniformLocation(this.prog,"uMaskInv"),!1,r.maskInv),e.uniform1f(e.getUniformLocation(this.prog,"uHasMask"),1),e.uniform1f(e.getUniformLocation(this.prog,"uCovers"),r.coversHost?1:0),e.uniform1f(e.getUniformLocation(this.prog,"uInvert"),r.invert?1:0)):e.uniform1f(e.getUniformLocation(this.prog,"uHasMask"),0),e.enable(e.BLEND),e.blendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA),e.drawArrays(e.TRIANGLES,0,3),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),e.bindVertexArray(null),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,null))}dispose(e){this.fb&&e.deleteFramebuffer(this.fb),this.tex&&e.deleteTexture(this.tex),this.prog&&e.deleteProgram(this.prog),this.vao&&e.deleteVertexArray(this.vao),this.fb=null,this.tex=null,this.prog=null,this.vao=null}};var Hc=["multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity","lighter"],q0=new Map(Hc.map((n,e)=>[n,e])),da=n=>typeof n!="string"?null:q0.get(n)??null;var K0=`#version 300 es
|
|
288
288
|
out vec2 vUv;
|
|
289
289
|
void main() {
|
|
290
290
|
vec2 p = vec2((gl_VertexID << 1) & 2, gl_VertexID & 2);
|
|
291
291
|
vUv = p;
|
|
292
292
|
gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);
|
|
293
|
-
}`,
|
|
293
|
+
}`,Q0=`#version 300 es
|
|
294
294
|
precision mediump float;
|
|
295
295
|
in vec2 vUv;
|
|
296
296
|
uniform sampler2D uSrc;
|
|
@@ -376,13 +376,13 @@ vec3 b = blendB(cb, cs, uMode);
|
|
|
376
376
|
vec3 co = (1.0 - ab) * src.rgb + b * (as * ab) + (1.0 - as) * dst.rgb;
|
|
377
377
|
float ao = as + ab * (1.0 - as);
|
|
378
378
|
outColor = vec4(co, ao);
|
|
379
|
-
}`,
|
|
379
|
+
}`,Vo=class{fb=null;tex=null;stencilRb=null;savedStencilEnabled=!1;savedStencilFunc=0;savedStencilRef=0;savedStencilMask=0;dstTex=null;prog=null;w=0;h=0;vao=null;boundFb=null;ensureProgram(e){if(this.prog)return;let t=(s,a)=>{let l=e.createShader(s);return l?(e.shaderSource(l,a),e.compileShader(l),e.getShaderParameter(l,e.COMPILE_STATUS)?l:(console.warn("[GLBlender] shader:",e.getShaderInfoLog(l)),e.deleteShader(l),null)):null},r=t(e.VERTEX_SHADER,K0),o=t(e.FRAGMENT_SHADER,Q0),i=e.createProgram();if(!(!r||!o||!i)){if(e.attachShader(i,r),e.attachShader(i,o),e.linkProgram(i),e.deleteShader(r),e.deleteShader(o),!e.getProgramParameter(i,e.LINK_STATUS)){console.warn("[GLBlender] link:",e.getProgramInfoLog(i));return}this.prog=i,this.vao=e.createVertexArray()}}ensureSize(e,t,r){return this.fb&&this.w===t&&this.h===r?!0:(this.fb&&e.deleteFramebuffer(this.fb),this.tex&&e.deleteTexture(this.tex),this.tex=e.createTexture(),e.bindTexture(e.TEXTURE_2D,this.tex),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,t,r,0,e.RGBA,e.UNSIGNED_BYTE,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),this.fb=e.createFramebuffer(),e.bindFramebuffer(e.FRAMEBUFFER,this.fb),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,this.tex,0),this.stencilRb&&e.deleteRenderbuffer(this.stencilRb),this.stencilRb=e.createRenderbuffer(),this.stencilRb&&(e.bindRenderbuffer(e.RENDERBUFFER,this.stencilRb),e.renderbufferStorage(e.RENDERBUFFER,e.DEPTH24_STENCIL8,t,r),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_STENCIL_ATTACHMENT,e.RENDERBUFFER,this.stencilRb),e.bindRenderbuffer(e.RENDERBUFFER,null)),this.dstTex&&e.deleteTexture(this.dstTex),this.dstTex=e.createTexture(),e.bindTexture(e.TEXTURE_2D,this.dstTex),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,t,r,0,e.RGBA,e.UNSIGNED_BYTE,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindTexture(e.TEXTURE_2D,null),this.w=t,this.h=r,!!this.fb)}begin(e,t,r){return this.boundFb=e.getParameter(e.FRAMEBUFFER_BINDING),this.ensureProgram(e),!this.prog||!this.ensureSize(e,t,r)||!this.fb?!1:(this.savedStencilEnabled=e.isEnabled(e.STENCIL_TEST),this.savedStencilEnabled&&(this.savedStencilFunc=e.getParameter(e.STENCIL_FUNC),this.savedStencilRef=e.getParameter(e.STENCIL_REF),this.savedStencilMask=e.getParameter(e.STENCIL_VALUE_MASK)),e.bindFramebuffer(e.FRAMEBUFFER,this.fb),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),this.stencilRb&&(e.clearStencil(0),e.clear(e.STENCIL_BUFFER_BIT)),e.disable(e.STENCIL_TEST),!0)}end(e){e.bindFramebuffer(e.FRAMEBUFFER,this.boundFb),this.savedStencilEnabled?e.enable(e.STENCIL_TEST):e.disable(e.STENCIL_TEST),this.savedStencilEnabled&&e.stencilFunc(this.savedStencilFunc,this.savedStencilRef,this.savedStencilMask)}composite(e,t){!this.prog||!this.tex||!this.dstTex||t<0||t>=Hc.length||(e.bindTexture(e.TEXTURE_2D,this.dstTex),e.copyTexSubImage2D(e.TEXTURE_2D,0,0,0,0,0,this.w,this.h),e.useProgram(this.prog),e.bindVertexArray(this.vao),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,this.tex),e.uniform1i(e.getUniformLocation(this.prog,"uSrc"),0),e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,this.dstTex),e.uniform1i(e.getUniformLocation(this.prog,"uDst"),1),e.uniform1i(e.getUniformLocation(this.prog,"uMode"),t),e.disable(e.BLEND),e.drawArrays(e.TRIANGLES,0,3),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),e.bindVertexArray(null),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,null))}dispose(e){this.fb&&e.deleteFramebuffer(this.fb),this.tex&&e.deleteTexture(this.tex),this.dstTex&&e.deleteTexture(this.dstTex),this.prog&&e.deleteProgram(this.prog),this.vao&&e.deleteVertexArray(this.vao),this.fb=null,this.tex=null,this.dstTex=null,this.prog=null,this.vao=null,this.w=0,this.h=0}};var Ae=(n,e,t={})=>{let r=n.createTexture();if(!r)return null;n.bindTexture(n.TEXTURE_2D,r),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,e),t.mipmap&&n.generateMipmap(n.TEXTURE_2D),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,t.mipmap?n.LINEAR_MIPMAP_LINEAR:n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR);let o=t.repeat?n.REPEAT:n.CLAMP_TO_EDGE;return n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,o),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,o),r};var jm=`#version 300 es
|
|
380
380
|
out vec2 vUv;
|
|
381
381
|
void main() {
|
|
382
382
|
vec2 p = vec2((gl_VertexID << 1) & 2, gl_VertexID & 2);
|
|
383
383
|
vUv = p;
|
|
384
384
|
gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);
|
|
385
|
-
}`,
|
|
385
|
+
}`,Z0=`#version 300 es
|
|
386
386
|
precision mediump float;
|
|
387
387
|
in vec2 vUv;
|
|
388
388
|
uniform sampler2D uSrc;
|
|
@@ -396,7 +396,7 @@ if (k >= uBoxW) break;
|
|
|
396
396
|
acc += texture(uSrc, vUv + uDir * (float(k) - float(uBoxW - 1) * 0.5)).a;
|
|
397
397
|
}
|
|
398
398
|
outColor = vec4(0.0, 0.0, 0.0, acc / float(uBoxW));
|
|
399
|
-
}`,
|
|
399
|
+
}`,J0=`#version 300 es
|
|
400
400
|
precision mediump float;
|
|
401
401
|
in vec2 vUv;
|
|
402
402
|
uniform sampler2D uBlur;
|
|
@@ -408,13 +408,13 @@ void main() {
|
|
|
408
408
|
float bl = texture(uBlur, vUv + uOffUv).a;
|
|
409
409
|
float sil = texture(uSil, vUv).a;
|
|
410
410
|
outColor = vec4(uColor.rgb, bl * (1.0 - sil) * uColor.a);
|
|
411
|
-
}`,K0=n=>{let e=n.cropRect?`${n.cropRect.sx},${n.cropRect.sy},${n.cropRect.sw},${n.cropRect.sh}`:"",t=n.isTextType?`${n.raw.renderSrc??""}|${n.raw.text??""}|${n.raw.fontSize??""}`:typeof n.raw.src=="string"?`${n.raw.src}|${e}`:e,r=n instanceof ie?`v${n.contentVersion}`:"";return`${n.raw.type};${t};${r};${Li(n)}`},Q0=(n,e,t,r)=>{let o=n.matrix;return[K0(n),n.dims.x,n.dims.y,Z0(e),t,r,o[0].toFixed(4),o[1].toFixed(4),o[2].toFixed(4),o[3].toFixed(4)].join(";")},Z0=n=>[n.rgba.join(","),n.blur,n.offsetX,n.offsetY,n.nonScaling?1:0].join("|"),da=class{constructor(e){this.epoch=e}epoch;silhouettes=new WeakMap;targets=new WeakMap;blurProg=null;finalProg=null;b1=null;b2=null;liveRts=new Set;liveSilTexes=new Set;invalidate(e){for(let t of this.liveRts)e.isTexture(t.tex)&&e.deleteTexture(t.tex),e.isFramebuffer(t.fb)&&e.deleteFramebuffer(t.fb);this.liveRts.clear();for(let t of this.liveSilTexes)e.isTexture(t)&&e.deleteTexture(t);this.liveSilTexes.clear(),this.blurProg=null,this.finalProg=null,this.b1=null,this.b2=null,this.silhouettes=new WeakMap,this.targets=new WeakMap}compile(e,t,r){let o=(l,c)=>{let u=e.createShader(l);return u?(e.shaderSource(u,c),e.compileShader(u),e.getShaderParameter(u,e.COMPILE_STATUS)?u:(console.warn("[GpuShadowBaker] shader:",e.getShaderInfoLog(u)),e.deleteShader(u),null)):null},i=o(e.VERTEX_SHADER,t),s=o(e.FRAGMENT_SHADER,r),a=e.createProgram();return!i||!s||!a?null:(e.attachShader(a,i),e.attachShader(a,s),e.linkProgram(a),e.deleteShader(i),e.deleteShader(s),e.getProgramParameter(a,e.LINK_STATUS)?a:(console.warn("[GpuShadowBaker] link:",e.getProgramInfoLog(a)),null))}ensurePrograms(e){return this.blurProg&&this.finalProg?!0:(this.blurProg=this.blurProg??this.compile(e,zm,V0),this.finalProg=this.finalProg??this.compile(e,zm,q0),!!(this.blurProg&&this.finalProg))}ensureTarget(e,t,r,o){if(t&&t.w===r&&t.h===o)return t;t&&(e.deleteFramebuffer(t.fb),e.deleteTexture(t.tex),this.liveRts.delete(t));let i=e.createTexture();if(!i)return null;e.bindTexture(e.TEXTURE_2D,i),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,r,o,0,e.RGBA,e.UNSIGNED_BYTE,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE);let s=e.createFramebuffer();if(!s)return e.deleteTexture(i),null;e.bindFramebuffer(e.FRAMEBUFFER,s),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,i,0),e.bindFramebuffer(e.FRAMEBUFFER,null);let a={fb:s,tex:i,w:r,h:o};return this.liveRts.add(a),a}silhouette(e,t,r,o,i){let s=this.silhouettes.get(t);if(s&&s.sig!==r&&(e.deleteTexture(s.tex),this.liveSilTexes.delete(s.tex),this.epoch?.bump("gpu-shadow-silhouette-rebake"),s=void 0),!s){let a=document.createElement("canvas");a.width=o,a.height=i;let l=a.getContext("2d");if(!l)return null;let c=t.matrix;l.setTransform(c[0],c[1],c[2],c[3],o/2,i/2),Ni(l,t,"#ffffff");let u=Le(e,a);if(!u)return null;this.liveSilTexes.add(u),s={sig:r,tex:u,w:o,h:i},this.silhouettes.set(t,s)}return s.tex}fullscreenPass(e,t,r,o){e.bindFramebuffer(e.FRAMEBUFFER,r.fb),e.viewport(0,0,r.w,r.h),e.useProgram(t),o(t),e.disable(e.BLEND),e.bindVertexArray(null),e.drawArrays(e.TRIANGLES,0,3)}render(e,t,r,o,i){if(!this.ensurePrograms(e))return null;let s=e.getParameter(e.FRAMEBUFFER_BINDING),a=Nt(r,t.raw.scaleX??1,t.raw.scaleY??1),l=Ai(a)+(t.isTextType?Math.ceil((t.raw.fontSize??40)*.5):0),c=fl(t),u=Math.ceil(c.x+l*2),h=Math.ceil(c.y+l*2);if(!(u>0)||!(h>0)||u>8192||h>8192)return null;let d=Q0(t,r,u,h);try{let f=this.targets.get(t);if(f&&f.sig!==d&&(e.deleteFramebuffer(f.rt.fb),e.deleteTexture(f.rt.tex),this.liveRts.delete(f.rt),this.epoch?.bump("gpu-shadow-rebake"),f=void 0),!f){let v=this.ensureTarget(e,null,u,h);if(!v)return null;f={sig:d,rt:v},this.targets.set(t,f)}let m=this.silhouette(e,t,d,u,h);if(!m)return null;this.b1=this.ensureTarget(e,this.b1,u,h),this.b2=this.ensureTarget(e,this.b2,u,h);let p=this.b1,b=this.b2;if(!p||!b)return null;let x=a.blur/2,g=x<.05?1:Math.max(1,Math.min(64,Math.round(Math.sqrt(4*x*x+1)))),y=(v,S,w,R)=>{this.fullscreenPass(e,this.blurProg,S,P=>{e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,v),e.uniform1i(e.getUniformLocation(P,"uSrc"),0),e.uniform2f(e.getUniformLocation(P,"uDir"),w,R),e.uniform1i(e.getUniformLocation(P,"uBoxW"),g)})};return y(m,p,1/u,0),y(p.tex,b,1/u,0),y(b.tex,p,1/u,0),y(p.tex,b,0,1/h),y(b.tex,p,0,1/h),y(p.tex,b,0,1/h),this.fullscreenPass(e,this.finalProg,f.rt,v=>{e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,b.tex),e.uniform1i(e.getUniformLocation(v,"uBlur"),0),e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,m),e.uniform1i(e.getUniformLocation(v,"uSil"),1),e.uniform2f(e.getUniformLocation(v,"uOffUv"),-a.offX/u,-a.offY/h),e.uniform4f(e.getUniformLocation(v,"uColor"),r.rgba[0],r.rgba[1],r.rgba[2],r.rgba[3])}),{tex:f.rt.tex,w:u,h}}finally{e.bindFramebuffer(e.FRAMEBUFFER,s),e.viewport(0,0,o,i),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA)}}};var fa=class{host;shadowBakes=new WeakMap;liveTexes=new Set;gpuShadowBaker=null;constructor(e){this.host=e}render(e){let t=ph(e.raw.shadow);if(!t)return;let r=e.cropRect?`${e.cropRect.sx},${e.cropRect.sy},${e.cropRect.sw},${e.cropRect.sh}`:"",o=e.isTextType?`${e.raw.renderSrc??""}|${e.raw.text??""}|${e.raw.fontSize??""}`:typeof e.raw.src=="string"?`${e.raw.src}|${r}${Di(e)}`:r,i=e instanceof ie?`v${e.contentVersion}`:"",s=[bh(t),e.raw.type,e.matrix.join(","),e.dims.x,e.dims.y,Li(e),o,i].join(";");if(Su()){this.gpuShadowBaker||(this.gpuShadowBaker=new da(this.host.renderEpoch));let c=this.gpuShadowBaker.render(this.host.gl,e,t,this.host.canvasEl.width,this.host.canvasEl.height);c&&this.host.batch.pushQuad([1,0,0,1,e.matrix[4],e.matrix[5]],c.w,c.h,[1,1,1,e.renderOpacity],c.tex);return}let a=this.shadowBakes.get(e);if(a&&a.sig!==s&&(a.tex&&(this.host.gl.deleteTexture(a.tex),this.liveTexes.delete(a.tex)),a=void 0),!a){let c=xh(e,t);if(!c)return;let u=Le(this.host.gl,c.canvas,{mipmap:!0});if(!u)return;this.liveTexes.add(u),a={sig:s,tex:u,w:c.w,h:c.h},this.shadowBakes.set(e,a)}if(!a.tex)return;let l=e.matrix;this.host.batch.pushQuad([1,0,0,1,l[4],l[5]],a.w,a.h,[1,1,1,e.renderOpacity],a.tex)}invalidate(){for(let e of this.liveTexes)this.host.gl.deleteTexture(e);this.liveTexes.clear(),this.shadowBakes=new WeakMap,this.host.renderEpoch?.bump("shadow-bake-invalidate"),this.gpuShadowBaker?.invalidate(this.host.gl)}};var Ym=(n,e,t,r)=>{let o=[];for(let E of n){if(!Number.isFinite(E.x)||!Number.isFinite(E.y))return null;let C=o[o.length-1];C&&C.x===E.x&&C.y===E.y||o.push({x:E.x,y:E.y})}if(e&&o.length>1){let E=o[0],C=o[o.length-1];E.x===C.x&&E.y===C.y&&o.pop()}let i=o.length;if(i<(e?3:2))return null;let s=e?i:i-1,a=[],l=[];for(let E=0;E<s;E++){let C=o[E],T=o[(E+1)%i],M=Math.hypot(T.x-C.x,T.y-C.y);if(!(M>1e-12))return null;a.push((T.x-C.x)/M),l.push((T.y-C.y)/M)}let c=[],u=[],h=[],d=[];for(let E=0;E<i;E++){let C=o[E],T=e||E>0,M=e||E<s;if(!T||!M){let D=T?E-1:0,I=-l[D],B=a[D];c.push(C.x+t*I),u.push(C.y+t*B),h.push(C.x-t*I),d.push(C.y-t*B);continue}let k=a[(E-1+s)%s],A=l[(E-1+s)%s],O=a[E%s],F=l[E%s],H=-(k*O+A*F),z=Math.sqrt(Math.max(0,(1-H)/2));if(1/Math.max(z,1e-300)>r*(1+1e-9))return null;let _=k*F-A*O;for(let D of[1,-1]){let I=o[(E-1+i)%i].x+t*D*-A,B=o[(E-1+i)%i].y+t*D*k,G=C.x+t*D*-F,X=C.y+t*D*O;if(Math.abs(_)<1e-12){let V=C.x+t*D*-F,Y=C.y+t*D*O;if(!Number.isFinite(V)||!Number.isFinite(Y))return null;D===1?(c.push(V),u.push(Y)):(h.push(V),d.push(Y));continue}let U=G-I,q=X-B,j=(U*F-q*O)/_,Z=I+j*k,W=B+j*A;if(!Number.isFinite(Z)||!Number.isFinite(W))return null;D===1?(c.push(Z),u.push(W)):(h.push(Z),d.push(W))}}for(let E=0;E<s;E++){let C=E+1;if((c[C]-c[E])*a[E]+(u[C]-u[E])*l[E]<=0||(h[C]-h[E])*a[E]+(d[C]-d[E])*l[E]<=0)return null}h.reverse(),d.reverse();let f=2*i;if(f>64||f<3)return null;let m=[],p=[],b=(E,C,T)=>{for(let M=0;M+1<E.length;M++)m.push(E[M],E[M+1]),p.push(C[M],C[M+1]);T&&E.length>2&&(m.push(E[E.length-1],E[0]),p.push(C[C.length-1],C[0]))};b(c,u,e),b(h,d,e),e||(m.push(c[c.length-1],h[0]),p.push(u[u.length-1],d[0]),m.push(h[h.length-1],c[0]),p.push(d[d.length-1],u[0]));let x=m.length/2;if(x!==f||x>64)return null;let g=(E,C,T,M,k,A)=>(T-E)*(A-C)-(M-C)*(k-E),y=(E,C)=>{let T=m[E*2],M=p[E*2],k=m[E*2+1],A=p[E*2+1],O=m[C*2],F=p[C*2],H=m[C*2+1],z=p[C*2+1];if(T===k&&M===A||O===H&&F===z)return!1;let _=g(T,M,k,A,O,F),D=g(T,M,k,A,H,z),I=g(O,F,H,z,T,M),B=g(O,F,H,z,k,A);return(_>0&&D<0||_<0&&D>0)&&(I>0&&B<0||I<0&&B>0)};for(let E=0;E<x;E++)for(let C=E+2;C<x;C++)if(y(E,C))return null;let v=new Float32Array(x*4),S=0,w=0,R=0,P=0;for(let E=0;E<x;E++)v[E*4]=m[E*2],v[E*4+1]=p[E*2],v[E*4+2]=m[E*2+1],v[E*4+3]=p[E*2+1],S=Math.max(S,Math.abs(m[E*2]),Math.abs(m[E*2+1])),w=Math.max(w,Math.abs(p[E*2]),Math.abs(p[E*2+1]));for(let E of o)R=Math.max(R,Math.abs(E.x)),P=Math.max(P,Math.abs(E.y));return!(R>0)||!(P>0)?null:{segments:{data:v,count:x,hash:Xr(v)},marginX:S-R,marginY:w-P}};var J0=1,eS=2,tS=3,Um=4,nS={butt:0,round:1,square:2},rS=1.5,oS=(n,e,t)=>{let r=e?n.length:n.length-1;if(r<1)return null;let o=[],i=[],s=[],a=[];for(let m=0;m<r;m++){let p=n[m],b=n[(m+1)%n.length],x=b.x-p.x,g=b.y-p.y;x*x+g*g<1e-18||(o.push(p.x),i.push(p.y),s.push(b.x),a.push(b.y))}let l=o.length;if(l<1||l>64)return null;let c=new Float32Array(l*4),u=0,h=0;for(let m=0;m<l;m++)c[m*4]=o[m],c[m*4+1]=i[m],c[m*4+2]=s[m],c[m*4+3]=a[m],u=Math.max(u,Math.abs(o[m]),Math.abs(s[m])),h=Math.max(h,Math.abs(i[m]),Math.abs(a[m]));let d=0,f=0;for(let m of n)d=Math.max(d,Math.abs(m.x)),f=Math.max(f,Math.abs(m.y));return!(d>0)||!(f>0)?null:{segments:{data:c,count:l,hash:Xr(c)},marginX:u+t-d,marginY:h+t-f}},$m=(n,e,t,r)=>{let o=null;if(e.dashArray){if(!ai()||e.dashArray.length>2||e.lineCap!=="butt"&&e.lineCap!=="square"||e.uniform)return null;let T=e.dashArray[0],M=e.dashArray.length>1?e.dashArray[1]:T;T+M>0&&(o=[T,T+M,e.dashOffset])}if(e.alignment!=="center")return null;let i=n.raw,s=se(i),a=n.dims;if(s!==L.LINE&&(!(a.x>0)||!(a.y>0)))return null;let l=s===L.LINE?eS:s===L.ELLIPSE||s===L.CIRCLE?tS:s===L.POLYGON||s===L.POLYLINE||s===L.TRIANGLE?Um:J0,c=e.width/2,u,h=null,d=c,f=c,m=0;if(s===L.RECT||s===L.FABRICRECT){let T=it(i,a.x,a.y),M=T?.rx??0,k=T?.ry??0;if(M<1e-4&&k<1e-4&&(e.lineJoin!=="miter"||e.miterLimit<rS)||o&&Math.abs(M-k)>=1e-4)return null;u=[M,k,a.x/2,a.y/2]}else if(s===L.LINE){let T=Number(i.x1),M=Number(i.y1),k=Number(i.x2),A=Number(i.y2);if(!Number.isFinite(T)||!Number.isFinite(M)||!Number.isFinite(k)||!Number.isFinite(A)||T===k&&M===A)return null;u=[T,M,k,A]}else if(s===L.ELLIPSE||s===L.CIRCLE){if(o)return null;u=[0,0,a.x/2,a.y/2]}else if(s===L.POLYGON||s===L.POLYLINE||s===L.TRIANGLE){if(!Tu()||o||e.uniform)return null;let T=s!==L.POLYLINE,M;if(s===L.TRIANGLE){let I=a.x,B=a.y;if(!(I>0)||!(B>0))return null;M=[{x:0,y:-B/2},{x:I/2,y:B/2},{x:-I/2,y:B/2}]}else{let I=Array.isArray(i.points)?i.points:[];if(I.length<(T?3:2))return null;M=[];for(let B of I){let G=Number(B?.x),X=Number(B?.y);if(!Number.isFinite(G)||!Number.isFinite(X))return null;M.push({x:G,y:X})}}let k=1/0,A=1/0,O=-1/0,F=-1/0;for(let I of M)k>I.x&&(k=I.x),A>I.y&&(A=I.y),O<I.x&&(O=I.x),F<I.y&&(F=I.y);let H=(k+O)/2,z=(A+F)/2,_=M.map(I=>({x:I.x-H,y:I.y-z})),D=0;if(e.lineJoin==="round"){if(!T&&e.lineCap!=="round")return null;let I=oS(_,T,c);if(!I)return null;h=I.segments,d=I.marginX,f=I.marginY}else if(e.lineJoin==="miter"){if(!T&&e.lineCap!=="butt")return null;let I=Ym(_,T,c,e.miterLimit);if(!I)return null;h=I.segments,d=I.marginX,f=I.marginY,D=1}else return null;u=[0,0,0,0],m=D}else return null;let p=l===Um?m:nS[e.lineCap]??0,b=l+(p<<3)+(e.uniform?64:0),x=n.matrix,g=Math.max(1e-6,t*r),y=Math.hypot(x[0],x[1]),v=Math.hypot(x[2],x[3]),S=Math.max(Math.min(y,v),1e-6),w=1/(S*g),R=(e.uniform?c/S:d)+4*w,P=(e.uniform?c/S:f)+4*w,E=a.x+2*R,C=a.y+2*P;return!Number.isFinite(E)||!Number.isFinite(C)?null:{halfW:c,code:-b,shape:u,quadW:E,quadH:C,dash:o,segments:h}};var iS=2,sS=4,pa={butt:0,round:1,square:2},aS=(n,e,t)=>{let r=Math.max(1e-6,e*t),o=Math.hypot(n[0],n[1]),i=Math.hypot(n[2],n[3]),s=Math.max(Math.min(o,i),1e-6);return{aa:1/(s*r),minAxis:s}},jm=n=>{if(!n.dashArray)return{dash:null,ok:!0};if(!ai())return{dash:null,ok:!1};if(n.dashArray.length>2)return{dash:null,ok:!1};if(n.lineCap!=="butt"&&n.lineCap!=="square")return{dash:null,ok:!1};if(n.uniform)return{dash:null,ok:!1};let e=n.dashArray[0],t=n.dashArray.length>1?n.dashArray[1]:e;return e+t<=0?{dash:null,ok:!0}:{dash:[e,e+t,n.dashOffset],ok:!0}},ba=(n,e,t,r,o,i,s,a,l,c)=>{let u=(n+t)/2,h=(e+r)/2,d=s?o/c:o,f=Math.abs(t-n)+2*(d+l),m=Math.abs(r-e)+2*(d+l);return{centerX:u,centerY:h,shape:[n-u,e-h,t-u,r-h],halfW:o,code:-(iS+(i<<3)+(s?64:0)),quadW:f,quadH:m,dash:a,segments:null}},lS=(n,e)=>{let t=1/0,r=1/0,o=-1/0,i=-1/0;for(let u of n)t>u.x&&(t=u.x),r>u.y&&(r=u.y),o<u.x&&(o=u.x),i<u.y&&(i=u.y);let s=(t+o)/2,a=(r+i)/2,l=[n[0],n[1],n[2],n[0]],c=new Float32Array(12);for(let u=0;u<3;u++)c[u*4]=l[u].x-s,c[u*4+1]=l[u].y-a,c[u*4+2]=l[u+1].x-s,c[u*4+3]=l[u+1].y-a;return{centerX:s,centerY:a,shape:[0,0,0,0],halfW:0,code:-(sS+8),quadW:o-t+2*e,quadH:i-r+2*e,dash:null,segments:{data:c,count:3,hash:Xr(c)}}},cS=n=>{let e=Number(n.x1),t=Number(n.y1),r=Number(n.x2),o=Number(n.y2);return!Number.isFinite(e)||!Number.isFinite(t)||!Number.isFinite(r)||!Number.isFinite(o)||e===r&&t===o?null:{x1:e,y1:t,x2:r,y2:o}},Vm=(n,e,t,r,o)=>{let i=se(n);if(i!==L.ARROW&&i!==L.DIMENSION||!Eu())return null;let s=cS(n);if(!s||e.alignment!=="center")return null;let{aa:a,minAxis:l}=aS(t,r,o),c=4*a,u=e.width,h=(s.x2-s.x1)/Math.hypot(s.x2-s.x1,s.y2-s.y1),d=(s.y2-s.y1)/Math.hypot(s.x2-s.x1,s.y2-s.y1);if(i===L.ARROW){let E=Number(n.arrowWidth)||15,C=Number(n.arrowHeight)||22.5,T=n.arrowType==="start"||n.arrowType==="both"?n.arrowType:"end",M=Math.sqrt(u),k=E*M,A=C*M,O=T==="start"||T==="both",F=T==="end"||T==="both",{dash:H,ok:z}=jm(e);if(!z)return null;let _=s.x1+h*(O?A:0),D=s.y1+d*(O?A:0),I=s.x2-h*(F?A:0),B=s.y2-d*(F?A:0),X=[ba(_,D,I,B,u/2,pa[e.lineCap]??0,e.uniform,H,c,l)],U=(q,j,Z,W)=>{let V=q-Z*A,Y=j-W*A;return lS([{x:q,y:j},{x:V+-W*(k/2),y:Y+Z*(k/2)},{x:V- -W*(k/2),y:Y-Z*(k/2)}],c)};return F&&X.push(U(s.x2,s.y2,h,d)),O&&X.push(U(s.x1,s.y1,-h,-d)),{pieces:X,text:null}}let{dash:f,ok:m}=jm(e);if(!m)return null;let p=ba(s.x1,s.y1,s.x2,s.y2,u/2,pa[e.lineCap]??0,e.uniform,f,c,l),b=Number(n.textFontSize)||50,x=-d,g=h,y=b/2,v=ba(s.x1-x*y,s.y1-g*y,s.x1+x*y,s.y1+g*y,u/2,pa.round,!1,null,c,l),S=ba(s.x2-x*y,s.y2-g*y,s.x2+x*y,s.y2+g*y,u/2,pa.round,!1,null,c,l),w=typeof n.text=="string"&&n.text.trim()?n.text:"50cm",R=Number(n.textPadding)||4,P=b+u/2+5;return{pieces:[p,v,S],text:{text:w,fontPx:b,w:0,h:b+R*2,cx:(s.x1+s.x2)/2+x*P,cy:(s.y1+s.y2)/2+g*P,angle:Math.atan2(s.y2-s.y1,s.x2-s.x1),color:typeof n.textColor=="string"?n.textColor:"#333333",bg:typeof n.textBackgroundColor=="string"?n.textBackgroundColor:"#ffffff",follow:n.textFollowLine!==!1,pad:R}}};var An=class{constructor(e){this.requestRender=e}requestRender;lastInteractionAt=-1/0;settleTimer=null;noteInteraction(){this.lastInteractionAt=performance.now(),this.settleTimer!==null&&clearTimeout(this.settleTimer),this.settleTimer=window.setTimeout(()=>{this.settleTimer=null,this.requestRender()},160)}isSettling(e=performance.now()){return e-this.lastInteractionAt<160||this.settleTimer!==null}dispose(){this.settleTimer!==null&&clearTimeout(this.settleTimer),this.settleTimer=null,this.lastInteractionAt=-1/0}};var qm=n=>n?120:6,Km=(n,e,t)=>{if(n===e)return!0;if(!(t>0))return!1;let r=Number(n),o=Number(e);return!Number.isFinite(r)||!Number.isFinite(o)||o<=0?!1:r/o>=t},xa=(n,e,t,r)=>!n.isExporting()&&e.isSettling(r)||r>t.bakeDeadline;var ga=class{host;frame;settle;liveTexes=new Set;strokeBakes=new WeakMap;lineDecoTextBakes=new WeakMap;constructor(e,t,r=new An(()=>e.requestRenderAll())){this.host=e,this.frame=t,this.settle=r}noteVptChange(){this.settle.noteInteraction()}render(e){let t=e.strokeDecl;if(!t)return;let r=Vm(e.raw,t,e.matrix,this.host.zoom,this.host.dpr);if(r&&(!r.pieces.some(h=>h.segments)||this.host.batch.canPushSegments())){let h=t.rgba,d=[h[0],h[1],h[2],h[3]*e.renderOpacity];for(let f of r.pieces){let m=f.centerX===0&&f.centerY===0?e.matrix:$(e.matrix,[1,0,0,1,f.centerX,f.centerY]);this.host.batch.pushQuad(m,f.quadW,f.quadH,d,null,f.shape,[f.halfW,f.code],e,f.dash,f.segments)}r.text&&this.renderLineDecoText(e,r.text);return}let o=$m(e,t,this.host.zoom,this.host.dpr);if(o&&(!o.segments||this.host.batch.canPushSegments())){let h=t.rgba;this.host.batch.pushQuad(e.matrix,o.quadW,o.quadH,[h[0],h[1],h[2],h[3]*e.renderOpacity],null,o.shape,[o.halfW,o.code],e,o.dash,o.segments);return}let i=e.raw,s=e.matrix,a=JSON.stringify([i.type,i.path,i.points,i.rx,i.ry,i.radius,e.dims.x,e.dims.y]),l=(this.host.zoom*this.host.dpr).toFixed(4),c=[Uu(t),s.join(","),a].join(";"),u=this.strokeBakes.get(e);if(u&&u.sigBase!==c)this.deleteBakeTex(u.tex),u=void 0;else if(u){let h=this.host.bakeKReuseFloor??0,d=u.k===l&&u.snapped?vi(s,this.host.zoom,this.host.dpr,this.host.viewportTransform,u.sceneW,u.sceneH):null;if(!Km(u.k,l,h)||d&&(d.lx!==u.lx||d.ly!==u.ly)){if(xa(this.host,this.settle,this.frame,performance.now())){this.frame.bakeMore=!0,this.host.batch.pushQuad([1,0,0,1,u.lx+u.w/2,u.ly+u.h/2],u.w,u.h,[1,1,1,e.renderOpacity],u.tex);return}this.deleteBakeTex(u.tex),u=void 0}}if(!u){let h=ju(e,{zoom:this.host.zoom,dpr:this.host.dpr,vpt:this.host.viewportTransform});if(!h){this.strokeBakes.set(e,void 0);return}let d=Le(this.host.gl,h.canvas);if(!d)return;this.liveTexes.add(d),u={sigBase:c,k:l,tex:d,w:h.w,h:h.h,lx:h.lx,ly:h.ly,sceneW:h.sceneW,sceneH:h.sceneH,snapped:h.snapped},this.strokeBakes.set(e,u)}this.host.batch.pushQuad([1,0,0,1,u.lx+u.w/2,u.ly+u.h/2],u.w,u.h,[1,1,1,e.renderOpacity],u.tex)}deleteBakeTex(e){this.host.gl.deleteTexture(e),this.liveTexes.delete(e)}renderLineDecoText(e,t){let r=`${t.fontPx}px Arial, sans-serif`,o=Jr(r,t.text)+t.pad*2;if(!(o>0)||!(t.h>0))return;let i=e.worldScale,s=Ot(this.host.zoom*this.host.dpr*Math.max(i.x,i.y,1e-6)),a=[t.text,t.fontPx,t.color,t.bg,t.follow,t.angle.toFixed(4),t.cx.toFixed(3),t.cy.toFixed(3),s].join(";"),l=this.lineDecoTextBakes.get(e);if(l&&l.sig!==a&&(this.deleteBakeTex(l.tex),l=void 0),!l){let d=document.createElement("canvas");d.width=Math.ceil(o*s),d.height=Math.ceil(t.h*s);let f=d.getContext("2d");if(!f)return;f.setTransform(s,0,0,s,d.width/2,d.height/2),t.bg&&(f.fillStyle=t.bg,f.fillRect(-o/2,-t.h/2,o,t.h)),f.font=r,f.textAlign="center",f.textBaseline="middle",f.fillStyle=t.color,f.fillText(t.text,0,0);let m=Le(this.host.gl,d);if(!m)return;this.liveTexes.add(m),l={sig:a,tex:m,w:d.width/s,h:d.height/s},this.lineDecoTextBakes.set(e,l)}let c=t.follow?t.angle:0,u=Math.cos(c),h=Math.sin(c);this.host.batch.pushQuad($(e.matrix,[u,h,-h,u,t.cx,t.cy]),l.w,l.h,[1,1,1,e.renderOpacity],l.tex)}invalidate(){for(let e of this.liveTexes)this.host.gl.deleteTexture(e);this.liveTexes.clear(),this.strokeBakes=new WeakMap,this.lineDecoTextBakes=new WeakMap,this.host.renderEpoch?.bump("stroke-bake-invalidate")}};var uS=new Set([...Gn,L.RECT,L.FABRICRECT]),Wc=n=>{let e=n.raw.clipPath;return!e||typeof e!="object"||Array.isArray(e)||!uS.has(se(e))?null:e},ya=class{enabled=!1;depth=0;silhouettes=new WeakMap;resetFrame(){this.enabled=vu(),this.depth=0}begin(e,t,r){if(!this.enabled||!t.batchOrder||r.rasterMask)return!1;let o=this.silhouetteOf(e);if(!o||o.inverted&&this.depth>0)return!1;let i=t.gl,s=++this.depth,a=o.inverted;return t.batchOrder.recordState(()=>{i.enable(i.STENCIL_TEST),i.stencilFunc(i.ALWAYS,s,255),i.stencilOp(i.KEEP,i.KEEP,i.REPLACE),i.colorMask(!1,!1,!1,!1)}),t.meshBatch.pushMesh(o.clipWorld,[1,1,1,1],o.verts,o.triangles,null,e),t.meshBatch.flush(),t.batchOrder.recordState(()=>{i.colorMask(!0,!0,!0,!0),i.stencilFunc(a?i.NOTEQUAL:i.EQUAL,s,255),i.stencilOp(i.KEEP,i.KEEP,i.KEEP)}),!0}end(e){let t=--this.depth,r=e.gl;e.batchOrder?.recordState(()=>{t<=0?r.disable(r.STENCIL_TEST):r.stencilFunc(r.EQUAL,t,255)})}silhouetteOf(e){let t=Wc(e);if(!t)return null;let r=this.silhouettes.get(e);if(r&&r.decl===t&&r.hostMatrix===e.matrix)return r;let o=this.buildSilhouette(e,t);return o&&this.silhouettes.set(e,o),o}buildSilhouette(e,t){let r=Ct(t);if(!r)return null;let i=t.absolutePositioned===!0?r.matrix:$(e.matrix,r.matrix),s=t.inverted===!0,a=r instanceof xn||!r.dims.x||!r.dims.y?null:it(r.raw,r.dims.x,r.dims.y),l=r instanceof xn?r.shapeMesh:a?Nu(r.dims.x,r.dims.y,a.rx,a.ry):null;if(l)return{decl:t,hostMatrix:e.matrix,clipWorld:i,inverted:s,verts:l.verts,triangles:l.triangles};if(r.dims.x>0&&r.dims.y>0){let c=r.dims.x/2,u=r.dims.y/2;return{decl:t,hostMatrix:e.matrix,clipWorld:i,inverted:s,verts:new Float32Array([-c,-u,c,-u,c,u,-c,u]),triangles:new Uint32Array([0,1,2,0,2,3])}}return null}};var hS=`#version 300 es
|
|
411
|
+
}`,eS=n=>{let e=n.cropRect?`${n.cropRect.sx},${n.cropRect.sy},${n.cropRect.sw},${n.cropRect.sh}`:"",t=n.isTextType?`${n.raw.renderSrc??""}|${n.raw.text??""}|${n.raw.fontSize??""}`:typeof n.raw.src=="string"?`${n.raw.src}|${e}`:e,r=n instanceof ie?`v${n.contentVersion}`:"";return`${n.raw.type};${t};${r};${Ii(n)}`},tS=(n,e,t,r)=>{let o=n.matrix;return[eS(n),n.dims.x,n.dims.y,nS(e),t,r,o[0].toFixed(4),o[1].toFixed(4),o[2].toFixed(4),o[3].toFixed(4)].join(";")},nS=n=>[n.rgba.join(","),n.blur,n.offsetX,n.offsetY,n.nonScaling?1:0].join("|"),fa=class{constructor(e){this.epoch=e}epoch;silhouettes=new WeakMap;targets=new WeakMap;blurProg=null;finalProg=null;b1=null;b2=null;liveRts=new Set;liveSilTexes=new Set;invalidate(e){for(let t of this.liveRts)e.isTexture(t.tex)&&e.deleteTexture(t.tex),e.isFramebuffer(t.fb)&&e.deleteFramebuffer(t.fb);this.liveRts.clear();for(let t of this.liveSilTexes)e.isTexture(t)&&e.deleteTexture(t);this.liveSilTexes.clear(),this.blurProg=null,this.finalProg=null,this.b1=null,this.b2=null,this.silhouettes=new WeakMap,this.targets=new WeakMap}compile(e,t,r){let o=(l,u)=>{let c=e.createShader(l);return c?(e.shaderSource(c,u),e.compileShader(c),e.getShaderParameter(c,e.COMPILE_STATUS)?c:(console.warn("[GpuShadowBaker] shader:",e.getShaderInfoLog(c)),e.deleteShader(c),null)):null},i=o(e.VERTEX_SHADER,t),s=o(e.FRAGMENT_SHADER,r),a=e.createProgram();return!i||!s||!a?null:(e.attachShader(a,i),e.attachShader(a,s),e.linkProgram(a),e.deleteShader(i),e.deleteShader(s),e.getProgramParameter(a,e.LINK_STATUS)?a:(console.warn("[GpuShadowBaker] link:",e.getProgramInfoLog(a)),null))}ensurePrograms(e){return this.blurProg&&this.finalProg?!0:(this.blurProg=this.blurProg??this.compile(e,jm,Z0),this.finalProg=this.finalProg??this.compile(e,jm,J0),!!(this.blurProg&&this.finalProg))}ensureTarget(e,t,r,o){if(t&&t.w===r&&t.h===o)return t;t&&(e.deleteFramebuffer(t.fb),e.deleteTexture(t.tex),this.liveRts.delete(t));let i=e.createTexture();if(!i)return null;e.bindTexture(e.TEXTURE_2D,i),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,r,o,0,e.RGBA,e.UNSIGNED_BYTE,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE);let s=e.createFramebuffer();if(!s)return e.deleteTexture(i),null;e.bindFramebuffer(e.FRAMEBUFFER,s),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,i,0),e.bindFramebuffer(e.FRAMEBUFFER,null);let a={fb:s,tex:i,w:r,h:o};return this.liveRts.add(a),a}silhouette(e,t,r,o,i){let s=this.silhouettes.get(t);if(s&&s.sig!==r&&(e.deleteTexture(s.tex),this.liveSilTexes.delete(s.tex),this.epoch?.bump("gpu-shadow-silhouette-rebake"),s=void 0),!s){let a=document.createElement("canvas");a.width=o,a.height=i;let l=a.getContext("2d");if(!l)return null;let u=t.matrix;l.setTransform(u[0],u[1],u[2],u[3],o/2,i/2),Li(l,t,"#ffffff");let c=Ae(e,a);if(!c)return null;this.liveSilTexes.add(c),s={sig:r,tex:c,w:o,h:i},this.silhouettes.set(t,s)}return s.tex}fullscreenPass(e,t,r,o){e.bindFramebuffer(e.FRAMEBUFFER,r.fb),e.viewport(0,0,r.w,r.h),e.useProgram(t),o(t),e.disable(e.BLEND),e.bindVertexArray(null),e.drawArrays(e.TRIANGLES,0,3)}render(e,t,r,o,i){if(!this.ensurePrograms(e))return null;let s=e.getParameter(e.FRAMEBUFFER_BINDING),a=Nt(r,t.raw.scaleX??1,t.raw.scaleY??1),l=Ni(a)+(t.isTextType?Math.ceil((t.raw.fontSize??40)*.5):0),u=ml(t),c=Math.ceil(u.x+l*2),h=Math.ceil(u.y+l*2);if(!(c>0)||!(h>0)||c>8192||h>8192)return null;let d=tS(t,r,c,h);try{let f=this.targets.get(t);if(f&&f.sig!==d&&(e.deleteFramebuffer(f.rt.fb),e.deleteTexture(f.rt.tex),this.liveRts.delete(f.rt),this.epoch?.bump("gpu-shadow-rebake"),f=void 0),!f){let v=this.ensureTarget(e,null,c,h);if(!v)return null;f={sig:d,rt:v},this.targets.set(t,f)}let m=this.silhouette(e,t,d,c,h);if(!m)return null;this.b1=this.ensureTarget(e,this.b1,c,h),this.b2=this.ensureTarget(e,this.b2,c,h);let p=this.b1,b=this.b2;if(!p||!b)return null;let x=a.blur/2,g=x<.05?1:Math.max(1,Math.min(64,Math.round(Math.sqrt(4*x*x+1)))),y=(v,S,w,R)=>{this.fullscreenPass(e,this.blurProg,S,P=>{e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,v),e.uniform1i(e.getUniformLocation(P,"uSrc"),0),e.uniform2f(e.getUniformLocation(P,"uDir"),w,R),e.uniform1i(e.getUniformLocation(P,"uBoxW"),g)})};return y(m,p,1/c,0),y(p.tex,b,1/c,0),y(b.tex,p,1/c,0),y(p.tex,b,0,1/h),y(b.tex,p,0,1/h),y(p.tex,b,0,1/h),this.fullscreenPass(e,this.finalProg,f.rt,v=>{e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,b.tex),e.uniform1i(e.getUniformLocation(v,"uBlur"),0),e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,m),e.uniform1i(e.getUniformLocation(v,"uSil"),1),e.uniform2f(e.getUniformLocation(v,"uOffUv"),-a.offX/c,-a.offY/h),e.uniform4f(e.getUniformLocation(v,"uColor"),r.rgba[0],r.rgba[1],r.rgba[2],r.rgba[3])}),{tex:f.rt.tex,w:c,h}}finally{e.bindFramebuffer(e.FRAMEBUFFER,s),e.viewport(0,0,o,i),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA)}}};var ma=class{host;shadowBakes=new WeakMap;liveTexes=new Set;gpuShadowBaker=null;constructor(e){this.host=e}render(e){let t=xh(e.raw.shadow);if(!t)return;let r=e.cropRect?`${e.cropRect.sx},${e.cropRect.sy},${e.cropRect.sw},${e.cropRect.sh}`:"",o=e.isTextType?`${e.raw.renderSrc??""}|${e.raw.text??""}|${e.raw.fontSize??""}`:typeof e.raw.src=="string"?`${e.raw.src}|${r}${Fi(e)}`:r,i=e instanceof ie?`v${e.contentVersion}`:"",s=[gh(t),e.raw.type,e.matrix.join(","),e.dims.x,e.dims.y,Ii(e),o,i].join(";");if(wu()){this.gpuShadowBaker||(this.gpuShadowBaker=new fa(this.host.renderEpoch));let u=this.gpuShadowBaker.render(this.host.gl,e,t,this.host.canvasEl.width,this.host.canvasEl.height);u&&this.host.batch.pushQuad([1,0,0,1,e.matrix[4],e.matrix[5]],u.w,u.h,[1,1,1,e.renderOpacity],u.tex);return}let a=this.shadowBakes.get(e);if(a&&a.sig!==s&&(a.tex&&(this.host.gl.deleteTexture(a.tex),this.liveTexes.delete(a.tex)),a=void 0),!a){let u=yh(e,t);if(!u)return;let c=Ae(this.host.gl,u.canvas,{mipmap:!0});if(!c)return;this.liveTexes.add(c),a={sig:s,tex:c,w:u.w,h:u.h},this.shadowBakes.set(e,a)}if(!a.tex)return;let l=e.matrix;this.host.batch.pushQuad([1,0,0,1,l[4],l[5]],a.w,a.h,[1,1,1,e.renderOpacity],a.tex)}invalidate(){for(let e of this.liveTexes)this.host.gl.deleteTexture(e);this.liveTexes.clear(),this.shadowBakes=new WeakMap,this.host.renderEpoch?.bump("shadow-bake-invalidate"),this.gpuShadowBaker?.invalidate(this.host.gl)}};var Vm=(n,e,t,r)=>{let o=[];for(let T of n){if(!Number.isFinite(T.x)||!Number.isFinite(T.y))return null;let C=o[o.length-1];C&&C.x===T.x&&C.y===T.y||o.push({x:T.x,y:T.y})}if(e&&o.length>1){let T=o[0],C=o[o.length-1];T.x===C.x&&T.y===C.y&&o.pop()}let i=o.length;if(i<(e?3:2))return null;let s=e?i:i-1,a=[],l=[];for(let T=0;T<s;T++){let C=o[T],E=o[(T+1)%i],M=Math.hypot(E.x-C.x,E.y-C.y);if(!(M>1e-12))return null;a.push((E.x-C.x)/M),l.push((E.y-C.y)/M)}let u=[],c=[],h=[],d=[];for(let T=0;T<i;T++){let C=o[T],E=e||T>0,M=e||T<s;if(!E||!M){let D=E?T-1:0,I=-l[D],W=a[D];u.push(C.x+t*I),c.push(C.y+t*W),h.push(C.x-t*I),d.push(C.y-t*W);continue}let k=a[(T-1+s)%s],A=l[(T-1+s)%s],O=a[T%s],F=l[T%s],G=-(k*O+A*F),Y=Math.sqrt(Math.max(0,(1-G)/2));if(1/Math.max(Y,1e-300)>r*(1+1e-9))return null;let _=k*F-A*O;for(let D of[1,-1]){let I=o[(T-1+i)%i].x+t*D*-A,W=o[(T-1+i)%i].y+t*D*k,j=C.x+t*D*-F,H=C.y+t*D*O;if(Math.abs(_)<1e-12){let q=C.x+t*D*-F,U=C.y+t*D*O;if(!Number.isFinite(q)||!Number.isFinite(U))return null;D===1?(u.push(q),c.push(U)):(h.push(q),d.push(U));continue}let X=j-I,z=H-W,$=(X*F-z*O)/_,Z=I+$*k,B=W+$*A;if(!Number.isFinite(Z)||!Number.isFinite(B))return null;D===1?(u.push(Z),c.push(B)):(h.push(Z),d.push(B))}}for(let T=0;T<s;T++){let C=T+1;if((u[C]-u[T])*a[T]+(c[C]-c[T])*l[T]<=0||(h[C]-h[T])*a[T]+(d[C]-d[T])*l[T]<=0)return null}h.reverse(),d.reverse();let f=2*i;if(f>64||f<3)return null;let m=[],p=[],b=(T,C,E)=>{for(let M=0;M+1<T.length;M++)m.push(T[M],T[M+1]),p.push(C[M],C[M+1]);E&&T.length>2&&(m.push(T[T.length-1],T[0]),p.push(C[C.length-1],C[0]))};b(u,c,e),b(h,d,e),e||(m.push(u[u.length-1],h[0]),p.push(c[c.length-1],d[0]),m.push(h[h.length-1],u[0]),p.push(d[d.length-1],c[0]));let x=m.length/2;if(x!==f||x>64)return null;let g=(T,C,E,M,k,A)=>(E-T)*(A-C)-(M-C)*(k-T),y=(T,C)=>{let E=m[T*2],M=p[T*2],k=m[T*2+1],A=p[T*2+1],O=m[C*2],F=p[C*2],G=m[C*2+1],Y=p[C*2+1];if(E===k&&M===A||O===G&&F===Y)return!1;let _=g(E,M,k,A,O,F),D=g(E,M,k,A,G,Y),I=g(O,F,G,Y,E,M),W=g(O,F,G,Y,k,A);return(_>0&&D<0||_<0&&D>0)&&(I>0&&W<0||I<0&&W>0)};for(let T=0;T<x;T++)for(let C=T+2;C<x;C++)if(y(T,C))return null;let v=new Float32Array(x*4),S=0,w=0,R=0,P=0;for(let T=0;T<x;T++)v[T*4]=m[T*2],v[T*4+1]=p[T*2],v[T*4+2]=m[T*2+1],v[T*4+3]=p[T*2+1],S=Math.max(S,Math.abs(m[T*2]),Math.abs(m[T*2+1])),w=Math.max(w,Math.abs(p[T*2]),Math.abs(p[T*2+1]));for(let T of o)R=Math.max(R,Math.abs(T.x)),P=Math.max(P,Math.abs(T.y));return!(R>0)||!(P>0)?null:{segments:{data:v,count:x,hash:Yr(v)},marginX:S-R,marginY:w-P}};var rS=1,oS=2,iS=3,qm=4,sS={butt:0,round:1,square:2},aS=1.5,lS=(n,e,t)=>{let r=e?n.length:n.length-1;if(r<1)return null;let o=[],i=[],s=[],a=[];for(let m=0;m<r;m++){let p=n[m],b=n[(m+1)%n.length],x=b.x-p.x,g=b.y-p.y;x*x+g*g<1e-18||(o.push(p.x),i.push(p.y),s.push(b.x),a.push(b.y))}let l=o.length;if(l<1||l>64)return null;let u=new Float32Array(l*4),c=0,h=0;for(let m=0;m<l;m++)u[m*4]=o[m],u[m*4+1]=i[m],u[m*4+2]=s[m],u[m*4+3]=a[m],c=Math.max(c,Math.abs(o[m]),Math.abs(s[m])),h=Math.max(h,Math.abs(i[m]),Math.abs(a[m]));let d=0,f=0;for(let m of n)d=Math.max(d,Math.abs(m.x)),f=Math.max(f,Math.abs(m.y));return!(d>0)||!(f>0)?null:{segments:{data:u,count:l,hash:Yr(u)},marginX:c+t-d,marginY:h+t-f}},Km=(n,e,t,r)=>{let o=null;if(e.dashArray){if(!li()||e.dashArray.length>2||e.lineCap!=="butt"&&e.lineCap!=="square"||e.uniform)return null;let E=e.dashArray[0],M=e.dashArray.length>1?e.dashArray[1]:E;E+M>0&&(o=[E,E+M,e.dashOffset])}if(e.alignment!=="center")return null;let i=n.raw,s=se(i),a=n.dims;if(s!==L.LINE&&(!(a.x>0)||!(a.y>0)))return null;let l=s===L.LINE?oS:s===L.ELLIPSE||s===L.CIRCLE?iS:s===L.POLYGON||s===L.POLYLINE||s===L.TRIANGLE?qm:rS,u=e.width/2,c,h=null,d=u,f=u,m=0;if(s===L.RECT||s===L.FABRICRECT){let E=it(i,a.x,a.y),M=E?.rx??0,k=E?.ry??0;if(M<1e-4&&k<1e-4&&(e.lineJoin!=="miter"||e.miterLimit<aS)||o&&Math.abs(M-k)>=1e-4)return null;c=[M,k,a.x/2,a.y/2]}else if(s===L.LINE){let E=Number(i.x1),M=Number(i.y1),k=Number(i.x2),A=Number(i.y2);if(!Number.isFinite(E)||!Number.isFinite(M)||!Number.isFinite(k)||!Number.isFinite(A)||E===k&&M===A)return null;c=[E,M,k,A]}else if(s===L.ELLIPSE||s===L.CIRCLE){if(o)return null;c=[0,0,a.x/2,a.y/2]}else if(s===L.POLYGON||s===L.POLYLINE||s===L.TRIANGLE){if(!Cu()||o||e.uniform)return null;let E=s!==L.POLYLINE,M;if(s===L.TRIANGLE){let I=a.x,W=a.y;if(!(I>0)||!(W>0))return null;M=[{x:0,y:-W/2},{x:I/2,y:W/2},{x:-I/2,y:W/2}]}else{let I=Array.isArray(i.points)?i.points:[];if(I.length<(E?3:2))return null;M=[];for(let W of I){let j=Number(W?.x),H=Number(W?.y);if(!Number.isFinite(j)||!Number.isFinite(H))return null;M.push({x:j,y:H})}}let k=1/0,A=1/0,O=-1/0,F=-1/0;for(let I of M)k>I.x&&(k=I.x),A>I.y&&(A=I.y),O<I.x&&(O=I.x),F<I.y&&(F=I.y);let G=(k+O)/2,Y=(A+F)/2,_=M.map(I=>({x:I.x-G,y:I.y-Y})),D=0;if(e.lineJoin==="round"){if(!E&&e.lineCap!=="round")return null;let I=lS(_,E,u);if(!I)return null;h=I.segments,d=I.marginX,f=I.marginY}else if(e.lineJoin==="miter"){if(!E&&e.lineCap!=="butt")return null;let I=Vm(_,E,u,e.miterLimit);if(!I)return null;h=I.segments,d=I.marginX,f=I.marginY,D=1}else return null;c=[0,0,0,0],m=D}else return null;let p=l===qm?m:sS[e.lineCap]??0,b=l+(p<<3)+(e.uniform?64:0),x=n.matrix,g=Math.max(1e-6,t*r),y=Math.hypot(x[0],x[1]),v=Math.hypot(x[2],x[3]),S=Math.max(Math.min(y,v),1e-6),w=1/(S*g),R=(e.uniform?u/S:d)+4*w,P=(e.uniform?u/S:f)+4*w,T=a.x+2*R,C=a.y+2*P;return!Number.isFinite(T)||!Number.isFinite(C)?null:{halfW:u,code:-b,shape:c,quadW:T,quadH:C,dash:o,segments:h}};var cS=2,uS=4,ba={butt:0,round:1,square:2},hS=(n,e,t)=>{let r=Math.max(1e-6,e*t),o=Math.hypot(n[0],n[1]),i=Math.hypot(n[2],n[3]),s=Math.max(Math.min(o,i),1e-6);return{aa:1/(s*r),minAxis:s}},Qm=n=>{if(!n.dashArray)return{dash:null,ok:!0};if(!li())return{dash:null,ok:!1};if(n.dashArray.length>2)return{dash:null,ok:!1};if(n.lineCap!=="butt"&&n.lineCap!=="square")return{dash:null,ok:!1};if(n.uniform)return{dash:null,ok:!1};let e=n.dashArray[0],t=n.dashArray.length>1?n.dashArray[1]:e;return e+t<=0?{dash:null,ok:!0}:{dash:[e,e+t,n.dashOffset],ok:!0}},xa=(n,e,t,r,o,i,s,a,l,u)=>{let c=(n+t)/2,h=(e+r)/2,d=s?o/u:o,f=Math.abs(t-n)+2*(d+l),m=Math.abs(r-e)+2*(d+l);return{centerX:c,centerY:h,shape:[n-c,e-h,t-c,r-h],halfW:o,code:-(cS+(i<<3)+(s?64:0)),quadW:f,quadH:m,dash:a,segments:null}},dS=(n,e)=>{let t=1/0,r=1/0,o=-1/0,i=-1/0;for(let c of n)t>c.x&&(t=c.x),r>c.y&&(r=c.y),o<c.x&&(o=c.x),i<c.y&&(i=c.y);let s=(t+o)/2,a=(r+i)/2,l=[n[0],n[1],n[2],n[0]],u=new Float32Array(12);for(let c=0;c<3;c++)u[c*4]=l[c].x-s,u[c*4+1]=l[c].y-a,u[c*4+2]=l[c+1].x-s,u[c*4+3]=l[c+1].y-a;return{centerX:s,centerY:a,shape:[0,0,0,0],halfW:0,code:-(uS+8),quadW:o-t+2*e,quadH:i-r+2*e,dash:null,segments:{data:u,count:3,hash:Yr(u)}}},fS=n=>{let e=Number(n.x1),t=Number(n.y1),r=Number(n.x2),o=Number(n.y2);return!Number.isFinite(e)||!Number.isFinite(t)||!Number.isFinite(r)||!Number.isFinite(o)||e===r&&t===o?null:{x1:e,y1:t,x2:r,y2:o}},Zm=(n,e,t,r,o)=>{let i=se(n);if(i!==L.ARROW&&i!==L.DIMENSION||!Mu())return null;let s=fS(n);if(!s||e.alignment!=="center")return null;let{aa:a,minAxis:l}=hS(t,r,o),u=4*a,c=e.width,h=(s.x2-s.x1)/Math.hypot(s.x2-s.x1,s.y2-s.y1),d=(s.y2-s.y1)/Math.hypot(s.x2-s.x1,s.y2-s.y1);if(i===L.ARROW){let T=Number(n.arrowWidth)||15,C=Number(n.arrowHeight)||22.5,E=n.arrowType==="start"||n.arrowType==="both"?n.arrowType:"end",M=Math.sqrt(c),k=T*M,A=C*M,O=E==="start"||E==="both",F=E==="end"||E==="both",{dash:G,ok:Y}=Qm(e);if(!Y)return null;let _=s.x1+h*(O?A:0),D=s.y1+d*(O?A:0),I=s.x2-h*(F?A:0),W=s.y2-d*(F?A:0),H=[xa(_,D,I,W,c/2,ba[e.lineCap]??0,e.uniform,G,u,l)],X=(z,$,Z,B)=>{let q=z-Z*A,U=$-B*A;return dS([{x:z,y:$},{x:q+-B*(k/2),y:U+Z*(k/2)},{x:q- -B*(k/2),y:U-Z*(k/2)}],u)};return F&&H.push(X(s.x2,s.y2,h,d)),O&&H.push(X(s.x1,s.y1,-h,-d)),{pieces:H,text:null}}let{dash:f,ok:m}=Qm(e);if(!m)return null;let p=xa(s.x1,s.y1,s.x2,s.y2,c/2,ba[e.lineCap]??0,e.uniform,f,u,l),b=Number(n.textFontSize)||50,x=-d,g=h,y=b/2,v=xa(s.x1-x*y,s.y1-g*y,s.x1+x*y,s.y1+g*y,c/2,ba.round,!1,null,u,l),S=xa(s.x2-x*y,s.y2-g*y,s.x2+x*y,s.y2+g*y,c/2,ba.round,!1,null,u,l),w=typeof n.text=="string"&&n.text.trim()?n.text:"50cm",R=Number(n.textPadding)||4,P=b+c/2+5;return{pieces:[p,v,S],text:{text:w,fontPx:b,w:0,h:b+R*2,cx:(s.x1+s.x2)/2+x*P,cy:(s.y1+s.y2)/2+g*P,angle:Math.atan2(s.y2-s.y1,s.x2-s.x1),color:typeof n.textColor=="string"?n.textColor:"#333333",bg:typeof n.textBackgroundColor=="string"?n.textBackgroundColor:"#ffffff",follow:n.textFollowLine!==!1,pad:R}}};var An=class{constructor(e){this.requestRender=e}requestRender;lastInteractionAt=-1/0;settleTimer=null;noteInteraction(){this.lastInteractionAt=performance.now(),this.settleTimer!==null&&clearTimeout(this.settleTimer),this.settleTimer=window.setTimeout(()=>{this.settleTimer=null,this.requestRender()},160)}isSettling(e=performance.now()){return e-this.lastInteractionAt<160||this.settleTimer!==null}dispose(){this.settleTimer!==null&&clearTimeout(this.settleTimer),this.settleTimer=null,this.lastInteractionAt=-1/0}};var Jm=n=>n?120:6,ep=(n,e,t)=>{if(n===e)return!0;if(!(t>0))return!1;let r=Number(n),o=Number(e);return!Number.isFinite(r)||!Number.isFinite(o)||o<=0?!1:r/o>=t},ga=(n,e,t,r)=>!n.isExporting()&&e.isSettling(r)||r>t.bakeDeadline;var ya=class{host;frame;settle;liveTexes=new Set;strokeBakes=new WeakMap;lineDecoTextBakes=new WeakMap;constructor(e,t,r=new An(()=>e.requestRenderAll())){this.host=e,this.frame=t,this.settle=r}noteVptChange(){this.settle.noteInteraction()}render(e){let t=e.strokeDecl;if(!t)return;let r=Zm(e.raw,t,e.matrix,this.host.zoom,this.host.dpr);if(r&&(!r.pieces.some(h=>h.segments)||this.host.batch.canPushSegments())){let h=t.rgba,d=[h[0],h[1],h[2],h[3]*e.renderOpacity];for(let f of r.pieces){let m=f.centerX===0&&f.centerY===0?e.matrix:V(e.matrix,[1,0,0,1,f.centerX,f.centerY]);this.host.batch.pushQuad(m,f.quadW,f.quadH,d,null,f.shape,[f.halfW,f.code],e,f.dash,f.segments)}r.text&&this.renderLineDecoText(e,r.text);return}let o=Km(e,t,this.host.zoom,this.host.dpr);if(o&&(!o.segments||this.host.batch.canPushSegments())){let h=t.rgba;this.host.batch.pushQuad(e.matrix,o.quadW,o.quadH,[h[0],h[1],h[2],h[3]*e.renderOpacity],null,o.shape,[o.halfW,o.code],e,o.dash,o.segments);return}let i=e.raw,s=e.matrix,a=JSON.stringify([i.type,i.path,i.points,i.rx,i.ry,i.radius,e.dims.x,e.dims.y]),l=(this.host.zoom*this.host.dpr).toFixed(4),u=[ju(t),s.join(","),a].join(";"),c=this.strokeBakes.get(e);if(c&&c.sigBase!==u)this.deleteBakeTex(c.tex),c=void 0;else if(c){let h=this.host.bakeKReuseFloor??0,d=c.k===l&&c.snapped?wi(s,this.host.zoom,this.host.dpr,this.host.viewportTransform,c.sceneW,c.sceneH):null;if(!ep(c.k,l,h)||d&&(d.lx!==c.lx||d.ly!==c.ly)){if(ga(this.host,this.settle,this.frame,performance.now())){this.frame.bakeMore=!0,this.host.batch.pushQuad([1,0,0,1,c.lx+c.w/2,c.ly+c.h/2],c.w,c.h,[1,1,1,e.renderOpacity],c.tex);return}this.deleteBakeTex(c.tex),c=void 0}}if(!c){let h=qu(e,{zoom:this.host.zoom,dpr:this.host.dpr,vpt:this.host.viewportTransform});if(!h){this.strokeBakes.set(e,void 0);return}let d=Ae(this.host.gl,h.canvas);if(!d)return;this.liveTexes.add(d),c={sigBase:u,k:l,tex:d,w:h.w,h:h.h,lx:h.lx,ly:h.ly,sceneW:h.sceneW,sceneH:h.sceneH,snapped:h.snapped},this.strokeBakes.set(e,c)}this.host.batch.pushQuad([1,0,0,1,c.lx+c.w/2,c.ly+c.h/2],c.w,c.h,[1,1,1,e.renderOpacity],c.tex)}deleteBakeTex(e){this.host.gl.deleteTexture(e),this.liveTexes.delete(e)}renderLineDecoText(e,t){let r=`${t.fontPx}px Arial, sans-serif`,o=eo(r,t.text)+t.pad*2;if(!(o>0)||!(t.h>0))return;let i=e.worldScale,s=Wt(this.host.zoom*this.host.dpr*Math.max(i.x,i.y,1e-6)),a=[t.text,t.fontPx,t.color,t.bg,t.follow,t.angle.toFixed(4),t.cx.toFixed(3),t.cy.toFixed(3),s].join(";"),l=this.lineDecoTextBakes.get(e);if(l&&l.sig!==a&&(this.deleteBakeTex(l.tex),l=void 0),!l){let d=document.createElement("canvas");d.width=Math.ceil(o*s),d.height=Math.ceil(t.h*s);let f=d.getContext("2d");if(!f)return;f.setTransform(s,0,0,s,d.width/2,d.height/2),t.bg&&(f.fillStyle=t.bg,f.fillRect(-o/2,-t.h/2,o,t.h)),f.font=r,f.textAlign="center",f.textBaseline="middle",f.fillStyle=t.color,f.fillText(t.text,0,0);let m=Ae(this.host.gl,d);if(!m)return;this.liveTexes.add(m),l={sig:a,tex:m,w:d.width/s,h:d.height/s},this.lineDecoTextBakes.set(e,l)}let u=t.follow?t.angle:0,c=Math.cos(u),h=Math.sin(u);this.host.batch.pushQuad(V(e.matrix,[c,h,-h,c,t.cx,t.cy]),l.w,l.h,[1,1,1,e.renderOpacity],l.tex)}invalidate(){for(let e of this.liveTexes)this.host.gl.deleteTexture(e);this.liveTexes.clear(),this.strokeBakes=new WeakMap,this.lineDecoTextBakes=new WeakMap,this.host.renderEpoch?.bump("stroke-bake-invalidate")}};var mS=new Set([...Xn,L.RECT,L.FABRICRECT]),Gc=n=>{let e=n.raw.clipPath;return!e||typeof e!="object"||Array.isArray(e)||!mS.has(se(e))?null:e},Sa=class{enabled=!1;depth=0;silhouettes=new WeakMap;resetFrame(){this.enabled=Tu(),this.depth=0}begin(e,t,r){if(!this.enabled||!t.batchOrder||r.rasterMask)return!1;let o=this.silhouetteOf(e);if(!o||o.inverted&&this.depth>0)return!1;let i=t.gl,s=++this.depth,a=o.inverted;return t.batchOrder.recordState(()=>{i.enable(i.STENCIL_TEST),i.stencilFunc(i.ALWAYS,s,255),i.stencilOp(i.KEEP,i.KEEP,i.REPLACE),i.colorMask(!1,!1,!1,!1)}),t.meshBatch.pushMesh(o.clipWorld,[1,1,1,1],o.verts,o.triangles,null,e),t.meshBatch.flush(),t.batchOrder.recordState(()=>{i.colorMask(!0,!0,!0,!0),i.stencilFunc(a?i.NOTEQUAL:i.EQUAL,s,255),i.stencilOp(i.KEEP,i.KEEP,i.KEEP)}),!0}end(e){let t=--this.depth,r=e.gl;e.batchOrder?.recordState(()=>{t<=0?r.disable(r.STENCIL_TEST):r.stencilFunc(r.EQUAL,t,255)})}silhouetteOf(e){let t=Gc(e);if(!t)return null;let r=this.silhouettes.get(e);if(r&&r.decl===t&&r.hostMatrix===e.matrix)return r;let o=this.buildSilhouette(e,t);return o&&this.silhouettes.set(e,o),o}buildSilhouette(e,t){let r=Ct(t);if(!r)return null;let i=t.absolutePositioned===!0?r.matrix:V(e.matrix,r.matrix),s=t.inverted===!0,a=r instanceof gn||!r.dims.x||!r.dims.y?null:it(r.raw,r.dims.x,r.dims.y),l=r instanceof gn?r.shapeMesh:a?Iu(r.dims.x,r.dims.y,a.rx,a.ry):null;if(l)return{decl:t,hostMatrix:e.matrix,clipWorld:i,inverted:s,verts:l.verts,triangles:l.triangles};if(r.dims.x>0&&r.dims.y>0){let u=r.dims.x/2,c=r.dims.y/2;return{decl:t,hostMatrix:e.matrix,clipWorld:i,inverted:s,verts:new Float32Array([-u,-c,u,-c,u,c,-u,c]),triangles:new Uint32Array([0,1,2,0,2,3])}}return null}};var pS=`#version 300 es
|
|
412
412
|
out vec2 vUv;
|
|
413
413
|
void main() {
|
|
414
414
|
vec2 p = vec2((gl_VertexID << 1) & 2, gl_VertexID & 2);
|
|
415
415
|
vUv = p;
|
|
416
416
|
gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);
|
|
417
|
-
}`,
|
|
417
|
+
}`,bS=`#version 300 es
|
|
418
418
|
precision mediump float;
|
|
419
419
|
in vec2 vUv;
|
|
420
420
|
uniform sampler2D uClipTex;
|
|
@@ -446,13 +446,13 @@ corner = 1.0 - smoothstep(-1.0, 0.0, dist);
|
|
|
446
446
|
float maskA = inClip ? texture(uMaskTex, vUv).a : 0.0;
|
|
447
447
|
float a = c.a * maskA * corner;
|
|
448
448
|
outColor = vec4(c.rgb, a);
|
|
449
|
-
}`,Vo=4096,fS=(n,e,t,r,o)=>{let i=Math.min(4,Math.max(1,r*t*o)),s=n*i,a=e*i;if(s>0&&a>0){let l=Math.min(1,Vo/Math.max(s,a)),c=Math.min(1,Math.sqrt(Vo*Vo/(s*a)));return i*Math.min(l,c)}return i},mS=(n,e,t)=>{let r=n.raw,o=n.clipImageRaw,i=Number(r.width)||0,s=Number(r.height)||0,a=o?.scaleX??1,l=o?.scaleY??1,c=o?.flipX?-1:1,u=o?.flipY?-1:1,h=(o?.angle??0)*Math.PI/180,d=r.clipX??0,f=r.clipY??0,m=Math.cos(h),p=Math.sin(h),b=[1,0,0,1,i/2,s/2],x=[m,p,-p,m,0,0],g=[a*c,0,0,l*u,0,0],y=[1,0,0,1,d/(a||1),f/(l||1)],v=[1,0,0,1,-e/2,-t/2];return ve($($($($(b,x),g),y),v))},Sa=class{prog=null;targets=new WeakMap;activeThisFrame=!1;ensureProgram(e){if(this.prog)return!0;let t=(s,a)=>{let l=e.createShader(s);return l?(e.shaderSource(l,a),e.compileShader(l),e.getShaderParameter(l,e.COMPILE_STATUS)?l:(console.warn("[MaskCompositeGpu] shader:",e.getShaderInfoLog(l)),e.deleteShader(l),null)):null},r=t(e.VERTEX_SHADER,hS),o=t(e.FRAGMENT_SHADER,dS),i=e.createProgram();return!r||!o||!i?!1:(e.attachShader(i,r),e.attachShader(i,o),e.linkProgram(i),e.deleteShader(r),e.deleteShader(o),e.getProgramParameter(i,e.LINK_STATUS)?(this.prog=i,!0):(console.warn("[MaskCompositeGpu] link:",e.getProgramInfoLog(i)),!1))}ensureTarget(e,t,r,o){let i=this.targets.get(t);if(i&&i.wPx===r&&i.hPx===o)return i;i&&(e.deleteFramebuffer(i.fb),e.deleteTexture(i.tex));let s=e.createTexture(),a=e.createFramebuffer();if(!s||!a)return null;e.bindTexture(e.TEXTURE_2D,s),e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,r,o,0,e.RGBA,e.UNSIGNED_BYTE,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindFramebuffer(e.FRAMEBUFFER,a),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,s,0),e.bindFramebuffer(e.FRAMEBUFFER,null);let l={fb:a,tex:s,wPx:r,hPx:o};return this.targets.set(t,l),l}render(e,t,r,o,i){let s=e.raw,a=e.clipImageRaw;if(!a)return null;let l=Number(s.width)||0,c=Number(s.height)||0;if(l<=0||c<=0||i.clipW<=0||i.clipH<=0||!this.ensureProgram(t))return null;let u=Math.max(Math.abs(a.scaleX??1),Math.abs(a.scaleY??1)),h=fS(l,c,r,o,u),d=64,f=Math.min(Vo,Math.max(d,Math.ceil(l*h/d)*d)),m=Math.min(Vo,Math.max(d,Math.ceil(c*h/d)*d)),p=t.getParameter(t.FRAMEBUFFER_BINDING),b=t.getParameter(t.VIEWPORT),x=t.getParameter(t.BLEND),g=t.getParameter(t.CURRENT_PROGRAM),y=t.getParameter(t.TEXTURE_BINDING_2D),v=this.ensureTarget(t,e,f,m);if(!v)return null;t.bindFramebuffer(t.FRAMEBUFFER,v.fb),t.viewport(0,0,f,m),t.disable(t.BLEND),t.useProgram(this.prog);let S=mS(e,i.clipW,i.clipH);t.uniformMatrix3fv(t.getUniformLocation(this.prog,"uClip"),!1,new Float32Array([S[0],S[1],0,S[2],S[3],0,S[4],S[5],1])),t.uniform1i(t.getUniformLocation(this.prog,"uClipTex"),0),t.uniform1i(t.getUniformLocation(this.prog,"uMaskTex"),1),t.uniform2f(t.getUniformLocation(this.prog,"uClipSize"),i.clipW,i.clipH),t.uniform2f(t.getUniformLocation(this.prog,"uSize"),l,c),t.uniform2f(t.getUniformLocation(this.prog,"uPxSize"),f,m);let w=Math.max(0,Math.min(s.cornerRadius||0,Math.min(l,c)/2));return t.uniform1f(t.getUniformLocation(this.prog,"uRadiusPx"),w*h),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,i.clipTex),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,i.maskTex),t.drawArrays(t.TRIANGLES,0,3),t.bindFramebuffer(t.FRAMEBUFFER,p),t.viewport(b[0],b[1],b[2],b[3]),x&&t.enable(t.BLEND),t.useProgram(g),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,y),this.activeThisFrame=!0,{tex:v.tex,w:l,h:c}}invalidate(){this.targets=new WeakMap,this.prog=null}};var zr=(n,e,t,r,o=0,i=0)=>{let s=e.raw,a=o||i?$(e.matrix,[1,0,0,1,o,i]):e.matrix;if(!n||s.angle||(s.scaleX??1)!==1||(s.scaleY??1)!==1)return{matrix:a,w:t,h:r,uv:[0,0,1,1]};let l=(s.left??0)+o,c=(s.top??0)+i,u=Math.max(l-t/2,-n.hw),h=Math.min(l+t/2,n.hw),d=Math.max(c-r/2,-n.hh),f=Math.min(c+r/2,n.hh);if(!(h-u>0)||!(f-d>0))return null;let m=[(u-(l-t/2))/t,(d-(c-r/2))/r,(h-(l-t/2))/t,(f-(c-r/2))/r],p=(u+h)/2-l,b=(d+f)/2-c,x=a;return{matrix:[x[0],x[1],x[2],x[3],x[0]*p+x[2]*b+x[4],x[1]*p+x[3]*b+x[5]],w:h-u,h:f-d,uv:m}};var Qm=new WeakMap,pS=n=>{let e=Qm.get(n);return e||(e=Object.create(n),Object.defineProperty(e,"matrix",{get:()=>{let t=n.bitmapRect,r=n.matrix;return(t.x!==0||t.y!==0)&&(r=$(r,[1,0,0,1,t.x,t.y])),t.angle&&(r=$(r,kt({angle:-t.angle}))),r}}),Qm.set(n,e)),e},va=class{host;frame;gpu;getPuzzleBox;psdBakes=new WeakMap;settle;blendComposite;cpuTexes=new Set;constructor(e,t,r,o,i=new An(()=>e.requestRenderAll()),s=()=>{}){this.host=e,this.frame=t,this.gpu=r,this.getPuzzleBox=o,this.settle=i,this.blendComposite=s}noteVptScaleChange(){this.settle.noteInteraction()}render(e,t){let r=e.isTextType&&e instanceof Se,o=r&&$t(e)&&e!==this.host.editingNode&&!!e.imageEl,i=e instanceof ae;if(!e.isImageType&&e.typeKey!==L.PATH&&!r&&!i||t==="above"&&!e.isImageType&&!r&&!i&&e.typeKey!==L.PATH||e.isImageType&&!(e instanceof ie)&&!e.imageEl)return;let s=Vt(e.raw.effects,r?{text:!0}:{});if(!s)return;let a=e.cropRect?`${e.cropRect.sx},${e.cropRect.sy},${e.cropRect.sw},${e.cropRect.sh}`:"",l=o?`bmp:${e.raw.renderSrc}`:r?JSON.stringify([e.raw.text,e.raw.styles,e.raw.fontFamily,e.raw.fontSize,e.raw.fontWeight,e.raw.fontStyle,e.raw.lineHeight,e.raw.charSpacing,e.raw.textAlign,e.raw.paragraph??null,e.raw.width,e.raw.height]):typeof e.raw.src=="string"?`${e.raw.src}|${a}${Di(e)}${vh(e)}`:a,c=e instanceof ie?`v${e.contentVersion}`:"",u=r&&!o?Math.max(1,Ot(this.host.zoom*this.host.dpr*Math.max(e.worldScale.x,e.worldScale.y))):1,h=o?pS(e):e,d=h.matrix,f=[Sn(s),`${d[0]},${d[1]},${d[2]},${d[3]}`,`${h.dims.x},${h.dims.y}`,l,c],m=f.join(";"),p=this.host.document?.transformGestureAt??-1/0,x=!this.host.isExporting()&&performance.now()-p<160||xa(this.host,this.settle,this.frame,performance.now()),g=this.psdBakes.get(e),y=v=>{for(let S of v.shadows)this.deleteBakeTex(S.tex);for(let S of v.innerShadows)this.deleteBakeTex(S.tex);for(let S of v.fills)this.deleteBakeTex(S.tex);for(let S of v.strokes)this.deleteBakeTex(S.tex)};if(g&&g.sigBase!==m){if(f[0]===g.sigParts[0]&&f[3]===g.sigParts[3]&&f[4]===g.sigParts[4]&&x){this.frame.bakeMore=!0,this.renderPsdBakeQuads(h,g,t,!0);return}y(g),g=void 0}if(g&&g.bucket!==u){if(x){this.frame.bakeMore=!0,this.renderPsdBakeQuads(h,g,t);return}y(g),g=void 0}if(!g){let v=this.host.gl,S=e instanceof ae?e.imageEl:e instanceof ie?e.paintSource:e.isImageType||o?e.imageEl:null,w=S?1:u,R=S&&!o?1:Math.min(Math.max(2,u),_i(e)),P=S??(r?co(e,w):null),E=S??(r?co(e,R):null),C=!P&&!i&&e.typeKey===L.PATH&&(s.solidFills.length>0||s.innerShadows.length>0)?Ch(h):null,T=P??C,M=S?1:w,k=S?e.cropRect:null,A=za()||Ya()?this.gpu.fx:null,O=!P&&!i,F=[];for(let B of s.dropShadows){let G=F[F.length-1];G&&G.mode===B.blendMode?G.group.push(B):F.push({mode:B.blendMode,group:[B]})}let H=[],z=F.length===1&&!F[0].mode;for(let B of F){if(za()&&A&&z){let X=A.bakeDropShadows(v,h,B.group,{source:P,sourceRect:k,rs:w,pathMode:O,sig:m,viewportW:this.host.canvasEl.width,viewportH:this.host.canvasEl.height});if(X){H.push({tex:X.tex,w:X.w/w,h:X.h/w,mode:void 0});continue}}let G=P?Fi(h,B.group,P,w,k):Eh(e,B.group);if(G){let X=Le(v,G.canvas,{mipmap:!0});X&&(this.cpuTexes.add(X),H.push({tex:X,w:G.quadW,h:G.quadH,mode:B.mode}))}}let _=[];if(T)for(let B of s.innerShadows){let G=yr(h,B,T,M,k);if(!G)continue;let X=Le(v,G);X&&(this.cpuTexes.add(X),_.push({tex:X,mode:B.blendMode}))}let D=[];if(T)for(let B of s.solidFills){if(Ya()&&A&&B.kind==="solid"&&!k&&!B.blendMode&&!jt(h)){let U=Math.max(1,Math.ceil(h.dims.x*w)),q=Math.max(1,Math.ceil(h.dims.y*w)),j=A.uploadLocalSource(v,h,T,`${m}|fillsrc`,U,q),Z=j?A.bakeSolidFill(v,h,B,j,U,q,m,`fill${D.length}`,this.host.canvasEl.width,this.host.canvasEl.height):null;if(Z){D.push({tex:Z,dx:B.offset.x,dy:B.offset.y,mode:void 0});continue}}let G=gr(h,B,T,M,k);if(!G)continue;let X=Le(v,G);X&&(this.cpuTexes.add(X),D.push({tex:X,dx:B.offset.x,dy:B.offset.y,mode:B.blendMode}))}let I=[];if(E){let B=mn(h,s.strokes,E,!r&&!i&&s.solidFills.length===0,R,k,r);for(let G=0;G<B.length;G++){let X=B[G],U=Le(v,X.canvas);U&&(this.cpuTexes.add(U),I.push({tex:U,w:X.quadW,h:X.quadH,dx:X.dx,dy:X.dy,mode:s.strokes[s.strokes.length-1-G]?.blendMode}))}}g={sigBase:m,sigParts:f,bucket:u,basis:{lin:[d[0],d[1],d[2],d[3]],dims:{x:h.dims.x,y:h.dims.y}},shadows:H,innerShadows:_,fills:D,strokes:I},this.psdBakes.set(e,g)}this.renderPsdBakeQuads(h,g,t)}renderPsdBakeQuads(e,t,r,o=!1){let i=e.renderOpacity,s=e.dims,a=o&&t.basis.dims.x>0?s.x/t.basis.dims.x:1,l=o&&t.basis.dims.y>0?s.y/t.basis.dims.y:1,c=null,u=1,h=1;if(o){let g=t.basis.lin,y=e.matrix,v=Math.atan2(y[1],y[0])-Math.atan2(g[1],g[0]),S=Math.cos(v),w=Math.sin(v);c=[S,w,-w,S,y[4],y[5]];let R=Math.abs(g[0])*t.basis.dims.x+Math.abs(g[2])*t.basis.dims.y||1,P=Math.abs(g[1])*t.basis.dims.x+Math.abs(g[3])*t.basis.dims.y||1;u=(Math.abs(y[0])*s.x+Math.abs(y[2])*s.y)/R,h=(Math.abs(y[1])*s.x+Math.abs(y[3])*s.y)/P}let f=e instanceof ae?1:i,m=null,p=[],b=()=>{if(!p.length){m=null;return}let g=m;m=null;let y=p.splice(0);if(g==null){for(let S of y)S();return}let v=ha(g);if(v==null){for(let S of y)S();return}this.blendComposite(v,()=>{for(let S of y)S()})},x=(g,y)=>{g!==m&&(b(),m=g),p.push(y)};if(r==="below")for(let g of t.shadows){let y=e.matrix;if(c){let v=c;x(g.mode,()=>this.host.batch.pushQuad(v,g.w*u,g.h*h,[1,1,1,f],g.tex))}else x(g.mode,()=>this.host.batch.pushQuad([1,0,0,1,y[4],y[5]],g.w,g.h,[1,1,1,f],g.tex))}else{for(let g of t.innerShadows){let y=zr(this.getPuzzleBox(),e,e.dims.x,e.dims.y,0,0);y&&x(g.mode,()=>this.host.batch.pushQuad(y.matrix,y.w,y.h,[1,1,1,f],g.tex,y.uv))}for(let g of t.fills){let y=zr(this.getPuzzleBox(),e,e.dims.x,e.dims.y,g.dx,g.dy);y&&x(g.mode,()=>this.host.batch.pushQuad(y.matrix,y.w,y.h,[1,1,1,f],g.tex,y.uv))}for(let g of t.strokes){let y=zr(this.getPuzzleBox(),e,o?g.w*a:g.w,o?g.h*l:g.h,g.dx,g.dy);y&&x(g.mode,()=>this.host.batch.pushQuad(y.matrix,y.w,y.h,[1,1,1,i],g.tex,y.uv))}}b()}deleteBakeTex(e){this.cpuTexes.has(e)&&(this.host.gl.deleteTexture(e),this.cpuTexes.delete(e))}invalidate(){for(let e of this.cpuTexes)this.host.gl.deleteTexture(e);this.cpuTexes.clear(),this.psdBakes=new WeakMap,this.host.renderEpoch?.bump("psd-bake-invalidate")}};var bS=`#version 300 es
|
|
449
|
+
}`,qo=4096,xS=(n,e,t,r,o)=>{let i=Math.min(4,Math.max(1,r*t*o)),s=n*i,a=e*i;if(s>0&&a>0){let l=Math.min(1,qo/Math.max(s,a)),u=Math.min(1,Math.sqrt(qo*qo/(s*a)));return i*Math.min(l,u)}return i},gS=(n,e,t)=>{let r=n.raw,o=n.clipImageRaw,i=Number(r.width)||0,s=Number(r.height)||0,a=o?.scaleX??1,l=o?.scaleY??1,u=o?.flipX?-1:1,c=o?.flipY?-1:1,h=(o?.angle??0)*Math.PI/180,d=r.clipX??0,f=r.clipY??0,m=Math.cos(h),p=Math.sin(h),b=[1,0,0,1,i/2,s/2],x=[m,p,-p,m,0,0],g=[a*u,0,0,l*c,0,0],y=[1,0,0,1,d/(a||1),f/(l||1)],v=[1,0,0,1,-e/2,-t/2];return ve(V(V(V(V(b,x),g),y),v))},va=class{prog=null;targets=new WeakMap;activeThisFrame=!1;ensureProgram(e){if(this.prog)return!0;let t=(s,a)=>{let l=e.createShader(s);return l?(e.shaderSource(l,a),e.compileShader(l),e.getShaderParameter(l,e.COMPILE_STATUS)?l:(console.warn("[MaskCompositeGpu] shader:",e.getShaderInfoLog(l)),e.deleteShader(l),null)):null},r=t(e.VERTEX_SHADER,pS),o=t(e.FRAGMENT_SHADER,bS),i=e.createProgram();return!r||!o||!i?!1:(e.attachShader(i,r),e.attachShader(i,o),e.linkProgram(i),e.deleteShader(r),e.deleteShader(o),e.getProgramParameter(i,e.LINK_STATUS)?(this.prog=i,!0):(console.warn("[MaskCompositeGpu] link:",e.getProgramInfoLog(i)),!1))}ensureTarget(e,t,r,o){let i=this.targets.get(t);if(i&&i.wPx===r&&i.hPx===o)return i;i&&(e.deleteFramebuffer(i.fb),e.deleteTexture(i.tex));let s=e.createTexture(),a=e.createFramebuffer();if(!s||!a)return null;e.bindTexture(e.TEXTURE_2D,s),e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,r,o,0,e.RGBA,e.UNSIGNED_BYTE,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindFramebuffer(e.FRAMEBUFFER,a),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,s,0),e.bindFramebuffer(e.FRAMEBUFFER,null);let l={fb:a,tex:s,wPx:r,hPx:o};return this.targets.set(t,l),l}render(e,t,r,o,i){let s=e.raw,a=e.clipImageRaw;if(!a)return null;let l=Number(s.width)||0,u=Number(s.height)||0;if(l<=0||u<=0||i.clipW<=0||i.clipH<=0||!this.ensureProgram(t))return null;let c=Math.max(Math.abs(a.scaleX??1),Math.abs(a.scaleY??1)),h=xS(l,u,r,o,c),d=64,f=Math.min(qo,Math.max(d,Math.ceil(l*h/d)*d)),m=Math.min(qo,Math.max(d,Math.ceil(u*h/d)*d)),p=t.getParameter(t.FRAMEBUFFER_BINDING),b=t.getParameter(t.VIEWPORT),x=t.getParameter(t.BLEND),g=t.getParameter(t.CURRENT_PROGRAM),y=t.getParameter(t.TEXTURE_BINDING_2D),v=this.ensureTarget(t,e,f,m);if(!v)return null;t.bindFramebuffer(t.FRAMEBUFFER,v.fb),t.viewport(0,0,f,m),t.disable(t.BLEND),t.useProgram(this.prog);let S=gS(e,i.clipW,i.clipH);t.uniformMatrix3fv(t.getUniformLocation(this.prog,"uClip"),!1,new Float32Array([S[0],S[1],0,S[2],S[3],0,S[4],S[5],1])),t.uniform1i(t.getUniformLocation(this.prog,"uClipTex"),0),t.uniform1i(t.getUniformLocation(this.prog,"uMaskTex"),1),t.uniform2f(t.getUniformLocation(this.prog,"uClipSize"),i.clipW,i.clipH),t.uniform2f(t.getUniformLocation(this.prog,"uSize"),l,u),t.uniform2f(t.getUniformLocation(this.prog,"uPxSize"),f,m);let w=Math.max(0,Math.min(s.cornerRadius||0,Math.min(l,u)/2));return t.uniform1f(t.getUniformLocation(this.prog,"uRadiusPx"),w*h),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,i.clipTex),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,i.maskTex),t.drawArrays(t.TRIANGLES,0,3),t.bindFramebuffer(t.FRAMEBUFFER,p),t.viewport(b[0],b[1],b[2],b[3]),x&&t.enable(t.BLEND),t.useProgram(g),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,y),this.activeThisFrame=!0,{tex:v.tex,w:l,h:u}}invalidate(){this.targets=new WeakMap,this.prog=null}};var Nn=(n,e,t,r,o=0,i=0)=>{let s=e.raw,a=o||i?V(e.matrix,[1,0,0,1,o,i]):e.matrix;if(!n||s.angle||(s.scaleX??1)!==1||(s.scaleY??1)!==1)return{matrix:a,w:t,h:r,uv:[0,0,1,1]};let l=(s.left??0)+o,u=(s.top??0)+i,c=Math.max(l-t/2,-n.hw),h=Math.min(l+t/2,n.hw),d=Math.max(u-r/2,-n.hh),f=Math.min(u+r/2,n.hh);if(!(h-c>0)||!(f-d>0))return null;let m=[(c-(l-t/2))/t,(d-(u-r/2))/r,(h-(l-t/2))/t,(f-(u-r/2))/r],p=(c+h)/2-l,b=(d+f)/2-u,x=a;return{matrix:[x[0],x[1],x[2],x[3],x[0]*p+x[2]*b+x[4],x[1]*p+x[3]*b+x[5]],w:h-c,h:f-d,uv:m}};var tp=new WeakMap,yS=n=>{let e=tp.get(n);return e||(e=Object.create(n),Object.defineProperty(e,"matrix",{get:()=>{let t=n.bitmapRect,r=n.matrix;return(t.x!==0||t.y!==0)&&(r=V(r,[1,0,0,1,t.x,t.y])),t.angle&&(r=V(r,kt({angle:-t.angle}))),r}}),tp.set(n,e)),e},wa=class{host;frame;gpu;getPuzzleBox;psdBakes=new WeakMap;settle;blendComposite;cpuTexes=new Set;constructor(e,t,r,o,i=new An(()=>e.requestRenderAll()),s=()=>{}){this.host=e,this.frame=t,this.gpu=r,this.getPuzzleBox=o,this.settle=i,this.blendComposite=s}noteVptScaleChange(){this.settle.noteInteraction()}render(e,t){let r=e.isTextType&&e instanceof Se,o=r&&Vt(e)&&e!==this.host.editingNode&&!!e.imageEl,i=e instanceof ae;if(!e.isImageType&&e.typeKey!==L.PATH&&!r&&!i||t==="above"&&!e.isImageType&&!r&&!i&&e.typeKey!==L.PATH||e.isImageType&&!(e instanceof ie)&&!e.imageEl)return;let s=Kt(e.raw.effects,r?{text:!0}:{});if(!s)return;let a=e.cropRect?`${e.cropRect.sx},${e.cropRect.sy},${e.cropRect.sw},${e.cropRect.sh}`:"",l=o?`bmp:${e.raw.renderSrc}`:r?JSON.stringify([e.raw.text,e.raw.styles,e.raw.fontFamily,e.raw.fontSize,e.raw.fontWeight,e.raw.fontStyle,e.raw.lineHeight,e.raw.charSpacing,e.raw.textAlign,e.raw.paragraph??null,e.raw.width,e.raw.height]):typeof e.raw.src=="string"?`${e.raw.src}|${a}${Fi(e)}${Eh(e)}`:a,u=e instanceof ie?`v${e.contentVersion}`:"",c=r&&!o?Math.max(1,Wt(this.host.zoom*this.host.dpr*Math.max(e.worldScale.x,e.worldScale.y))):1,h=o?yS(e):e,d=h.matrix,f=[Sn(s),`${d[0]},${d[1]},${d[2]},${d[3]}`,`${h.dims.x},${h.dims.y}`,l,u],m=f.join(";"),p=this.host.document?.transformGestureAt??-1/0,x=!this.host.isExporting()&&performance.now()-p<160||ga(this.host,this.settle,this.frame,performance.now()),g=this.psdBakes.get(e),y=v=>{for(let S of v.shadows)this.deleteBakeTex(S.tex);for(let S of v.innerShadows)this.deleteBakeTex(S.tex);for(let S of v.fills)this.deleteBakeTex(S.tex);for(let S of v.strokes)this.deleteBakeTex(S.tex);v.bevelShadow&&this.deleteBakeTex(v.bevelShadow.tex),v.bevelHighlight&&this.deleteBakeTex(v.bevelHighlight.tex)};if(g&&g.sigBase!==m){if(f[0]===g.sigParts[0]&&f[3]===g.sigParts[3]&&f[4]===g.sigParts[4]&&x){this.frame.bakeMore=!0,this.renderPsdBakeQuads(h,g,t,!0);return}y(g),g=void 0}if(g&&g.bucket!==c){if(x){this.frame.bakeMore=!0,this.renderPsdBakeQuads(h,g,t);return}y(g),g=void 0}if(!g){let v=this.host.gl,S=e instanceof ae?e.imageEl:e instanceof ie?e.paintSource:e.isImageType||o?e.imageEl:null,w=S?1:c,R=S&&!o?1:Math.min(Math.max(2,c),Di(e)),P=S??(r?ho(e,w):null),T=S??(r?ho(e,R):null),C=!P&&!i&&e.typeKey===L.PATH&&(s.solidFills.length>0||s.innerShadows.length>0||s.bevel)?Rh(h):null,E=P??C,M=S?1:w,k=S?e.cropRect:null,A=Ya()||Ua()?this.gpu.fx:null,O=!P&&!i,F=[];for(let H of s.dropShadows){let X=F[F.length-1];X&&X.mode===H.blendMode?X.group.push(H):F.push({mode:H.blendMode,group:[H]})}let G=[],Y=F.length===1&&!F[0].mode;for(let H of F){if(Ya()&&A&&Y){let z=A.bakeDropShadows(v,h,H.group,{source:P,sourceRect:k,rs:w,pathMode:O,sig:m,viewportW:this.host.canvasEl.width,viewportH:this.host.canvasEl.height});if(z){G.push({tex:z.tex,w:z.w/w,h:z.h/w,mode:void 0});continue}}let X=P?Oi(h,H.group,P,w,k):Mh(e,H.group);if(X){let z=Ae(v,X.canvas,{mipmap:!0});z&&(this.cpuTexes.add(z),G.push({tex:z,w:X.quadW,h:X.quadH,mode:H.mode}))}}let _=[];if(E)for(let H of s.innerShadows){let X=vr(h,H,E,M,k);if(!X)continue;let z=Ae(v,X);z&&(this.cpuTexes.add(z),_.push({tex:z,mode:H.blendMode}))}let D,I;if(s.bevel&&(T||C)){let H=Ph(h,s.bevel,T??C,R,k);if(H){let X=Ae(v,H.shadow),z=Ae(v,H.highlight);X&&(this.cpuTexes.add(X),D={tex:X,w:H.quadW,h:H.quadH,mode:s.bevel.shadow.blendMode}),z&&(this.cpuTexes.add(z),I={tex:z,w:H.quadW,h:H.quadH,mode:s.bevel.highlight.blendMode})}}let W=[];if(E)for(let H of s.solidFills){if(Ua()&&A&&H.kind==="solid"&&!k&&!H.blendMode&&!Lt(h)){let $=Math.max(1,Math.ceil(h.dims.x*w)),Z=Math.max(1,Math.ceil(h.dims.y*w)),B=A.uploadLocalSource(v,h,E,`${m}|fillsrc`,$,Z),q=B?A.bakeSolidFill(v,h,H,B,$,Z,m,`fill${W.length}`,this.host.canvasEl.width,this.host.canvasEl.height):null;if(q){W.push({tex:q,dx:H.offset.x,dy:H.offset.y,mode:void 0});continue}}let X=Sr(h,H,E,M,k);if(!X)continue;let z=Ae(v,X);z&&(this.cpuTexes.add(z),W.push({tex:z,dx:H.offset.x,dy:H.offset.y,mode:H.blendMode}))}let j=[];if(T){let H=pn(h,s.strokes,T,!r&&!i&&s.solidFills.length===0,R,k,r);for(let X=0;X<H.length;X++){let z=H[X],$=Ae(v,z.canvas);$&&(this.cpuTexes.add($),j.push({tex:$,w:z.quadW,h:z.quadH,dx:z.dx,dy:z.dy,mode:s.strokes[s.strokes.length-1-X]?.blendMode}))}}g={sigBase:m,sigParts:f,bucket:c,basis:{lin:[d[0],d[1],d[2],d[3]],dims:{x:h.dims.x,y:h.dims.y}},shadows:G,innerShadows:_,fills:W,strokes:j,...D?{bevelShadow:D}:{},...I?{bevelHighlight:I}:{}},this.psdBakes.set(e,g)}this.renderPsdBakeQuads(h,g,t)}renderPsdBakeQuads(e,t,r,o=!1){let i=e.renderOpacity,s=e.dims,a=o&&t.basis.dims.x>0?s.x/t.basis.dims.x:1,l=o&&t.basis.dims.y>0?s.y/t.basis.dims.y:1,u=null,c=1,h=1;if(o){let g=t.basis.lin,y=e.matrix,v=Math.atan2(y[1],y[0])-Math.atan2(g[1],g[0]),S=Math.cos(v),w=Math.sin(v);u=[S,w,-w,S,y[4],y[5]];let R=Math.abs(g[0])*t.basis.dims.x+Math.abs(g[2])*t.basis.dims.y||1,P=Math.abs(g[1])*t.basis.dims.x+Math.abs(g[3])*t.basis.dims.y||1;c=(Math.abs(y[0])*s.x+Math.abs(y[2])*s.y)/R,h=(Math.abs(y[1])*s.x+Math.abs(y[3])*s.y)/P}let f=e instanceof ae?1:i,m=null,p=[],b=()=>{if(!p.length){m=null;return}let g=m;m=null;let y=p.splice(0);if(g==null){for(let S of y)S();return}let v=da(g);if(v==null){for(let S of y)S();return}this.blendComposite(v,()=>{for(let S of y)S()})},x=(g,y)=>{g!==m&&(b(),m=g),p.push(y)};if(r==="below")for(let g of t.shadows){let y=e.matrix;if(u){let v=u;x(g.mode,()=>this.host.batch.pushQuad(v,g.w*c,g.h*h,[1,1,1,f],g.tex))}else x(g.mode,()=>this.host.batch.pushQuad([1,0,0,1,y[4],y[5]],g.w,g.h,[1,1,1,f],g.tex))}else{for(let g of t.innerShadows){let y=Nn(this.getPuzzleBox(),e,e.dims.x,e.dims.y,0,0);y&&x(g.mode,()=>this.host.batch.pushQuad(y.matrix,y.w,y.h,[1,1,1,f],g.tex,y.uv))}if(t.bevelShadow){let g=t.bevelShadow,y=Nn(this.getPuzzleBox(),e,g.w,g.h,0,0);y&&x(g.mode,()=>this.host.batch.pushQuad(y.matrix,y.w,y.h,[1,1,1,f],g.tex,y.uv))}if(t.bevelHighlight){let g=t.bevelHighlight,y=Nn(this.getPuzzleBox(),e,g.w,g.h,0,0);y&&x(g.mode,()=>this.host.batch.pushQuad(y.matrix,y.w,y.h,[1,1,1,f],g.tex,y.uv))}for(let g of t.fills){let y=Nn(this.getPuzzleBox(),e,e.dims.x,e.dims.y,g.dx,g.dy);y&&x(g.mode,()=>this.host.batch.pushQuad(y.matrix,y.w,y.h,[1,1,1,f],g.tex,y.uv))}for(let g of t.strokes){let y=Nn(this.getPuzzleBox(),e,o?g.w*a:g.w,o?g.h*l:g.h,g.dx,g.dy);y&&x(g.mode,()=>this.host.batch.pushQuad(y.matrix,y.w,y.h,[1,1,1,i],g.tex,y.uv))}}b()}deleteBakeTex(e){this.cpuTexes.has(e)&&(this.host.gl.deleteTexture(e),this.cpuTexes.delete(e))}invalidate(){for(let e of this.cpuTexes)this.host.gl.deleteTexture(e);this.cpuTexes.clear(),this.psdBakes=new WeakMap,this.host.renderEpoch?.bump("psd-bake-invalidate")}};var SS=`#version 300 es
|
|
450
450
|
out vec2 vUv;
|
|
451
451
|
void main() {
|
|
452
452
|
vec2 p = vec2((gl_VertexID << 1) & 2, gl_VertexID & 2);
|
|
453
453
|
vUv = p;
|
|
454
454
|
gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);
|
|
455
|
-
}`,
|
|
455
|
+
}`,vS=`#version 300 es
|
|
456
456
|
precision mediump float;
|
|
457
457
|
in vec2 vUv;
|
|
458
458
|
uniform sampler2D uSrc;
|
|
@@ -466,7 +466,7 @@ if (k >= uBoxW) break;
|
|
|
466
466
|
acc += texture(uSrc, vUv + uDir * (float(k) - float(uBoxW - 1) * 0.5)).a;
|
|
467
467
|
}
|
|
468
468
|
outColor = vec4(0.0, 0.0, 0.0, acc / float(uBoxW));
|
|
469
|
-
}`,
|
|
469
|
+
}`,wS=`#version 300 es
|
|
470
470
|
precision mediump float;
|
|
471
471
|
in vec2 vUv;
|
|
472
472
|
uniform sampler2D uMask;
|
|
@@ -476,7 +476,7 @@ out vec4 outColor;
|
|
|
476
476
|
void main() {
|
|
477
477
|
float m = texture(uMask, vUv + uOffUv).a;
|
|
478
478
|
outColor = vec4(uColor.rgb, m * uColor.a);
|
|
479
|
-
}`,
|
|
479
|
+
}`,TS=`#version 300 es
|
|
480
480
|
precision mediump float;
|
|
481
481
|
in vec2 vUv;
|
|
482
482
|
uniform sampler2D uSrc;
|
|
@@ -484,7 +484,7 @@ uniform vec4 uColor;
|
|
|
484
484
|
out vec4 outColor;
|
|
485
485
|
void main() {
|
|
486
486
|
outColor = vec4(uColor.rgb, texture(uSrc, vUv).a * uColor.a);
|
|
487
|
-
}`,
|
|
487
|
+
}`,ES=`#version 300 es
|
|
488
488
|
precision mediump float;
|
|
489
489
|
in vec2 vUv;
|
|
490
490
|
uniform sampler2D uAcc;
|
|
@@ -494,19 +494,19 @@ out vec4 outColor;
|
|
|
494
494
|
void main() {
|
|
495
495
|
vec4 acc = texture(uAcc, vUv);
|
|
496
496
|
outColor = vec4(acc.rgb, acc.a * mix(1.0, 1.0 - texture(uSil, vUv).a, uErase));
|
|
497
|
-
}`,
|
|
497
|
+
}`,CS=`#version 300 es
|
|
498
498
|
in vec2 aPos;
|
|
499
499
|
uniform mat3 uM;
|
|
500
500
|
uniform vec2 uSize;
|
|
501
501
|
void main() {
|
|
502
502
|
vec2 px = (uM * vec3(aPos, 1.0)).xy;
|
|
503
503
|
gl_Position = vec4(px.x / uSize.x * 2.0 - 1.0, 1.0 - px.y / uSize.y * 2.0, 0.0, 1.0);
|
|
504
|
-
}`,
|
|
504
|
+
}`,MS=`#version 300 es
|
|
505
505
|
precision mediump float;
|
|
506
506
|
out vec4 outColor;
|
|
507
507
|
void main() {
|
|
508
508
|
outColor = vec4(1.0, 1.0, 1.0, 1.0);
|
|
509
|
-
}`,
|
|
509
|
+
}`,RS=`#version 300 es
|
|
510
510
|
precision mediump float;
|
|
511
511
|
in vec2 vUv;
|
|
512
512
|
uniform sampler2D uSrc;
|
|
@@ -518,14 +518,14 @@ vec4 b = texture(uSrc, vUv + vec2(uHalfTexel.x, -uHalfTexel.y));
|
|
|
518
518
|
vec4 c = texture(uSrc, vUv + vec2(-uHalfTexel.x, uHalfTexel.y));
|
|
519
519
|
vec4 d = texture(uSrc, vUv + uHalfTexel);
|
|
520
520
|
outColor = (a + b + c + d) * 0.25;
|
|
521
|
-
}`,
|
|
521
|
+
}`,Ta=class{constructor(e){this.epoch=e}epoch;sources=new WeakMap;liveSrcTexes=new Set;liveTargetRts=new Set;targets=new WeakMap;slot(e,t,r,o,i,s){let a=this.targets.get(t);if(a&&a.sigBase!==r){for(let u of a.map.values())e.deleteFramebuffer(u.fb),e.deleteTexture(u.tex),this.liveTargetRts.delete(u);this.epoch?.bump("fx-slot-group-rebuild"),a=void 0}a||(a={sigBase:r,map:new Map},this.targets.set(t,a));let l=a.map.get(o);return l&&l.w===i&&l.h===s&&e.isTexture(l.tex)?l:(l&&(e.deleteFramebuffer(l.fb),e.deleteTexture(l.tex),this.liveTargetRts.delete(l)),l=this.allocTarget(e,i,s),l?(this.liveTargetRts.add(l),a.map.set(o,l),l):null)}maskProg=null;downProg=null;maskRt=null;maskMsaa=null;meshBufs=new WeakMap;blurProg=null;tintProg=null;fillProg=null;finishProg=null;scratch=[];invalidateTextDerivedBakes(e){for(let t of this.liveSrcTexes)e.isTexture(t)&&e.deleteTexture(t);this.liveSrcTexes.clear();for(let t of this.liveTargetRts)e.isTexture(t.tex)&&e.deleteTexture(t.tex),e.isFramebuffer(t.fb)&&e.deleteFramebuffer(t.fb);this.liveTargetRts.clear(),this.sources=new WeakMap,this.targets=new WeakMap}invalidate(e){this.invalidateTextDerivedBakes(e),this.maskProg=null,this.downProg=null,this.blurProg=null,this.tintProg=null,this.fillProg=null,this.finishProg=null,this.maskRt=null,this.maskMsaa=null,this.scratch=[],this.meshBufs=new WeakMap}compile(e,t,r=SS){let o=(l,u)=>{let c=e.createShader(l);return c?(e.shaderSource(c,u),e.compileShader(c),e.getShaderParameter(c,e.COMPILE_STATUS)?c:(console.warn("[GpuFxPainter] shader:",e.getShaderInfoLog(c)),e.deleteShader(c),null)):null},i=o(e.VERTEX_SHADER,r),s=o(e.FRAGMENT_SHADER,t),a=e.createProgram();return!i||!s||!a?null:(e.attachShader(a,i),e.attachShader(a,s),e.linkProgram(a),e.deleteShader(i),e.deleteShader(s),e.getProgramParameter(a,e.LINK_STATUS)?a:(console.warn("[GpuFxPainter] link:",e.getProgramInfoLog(a)),null))}ensurePrograms(e){return this.maskProg&&this.downProg&&this.blurProg&&this.tintProg&&this.fillProg&&this.finishProg?!0:(this.maskProg=this.maskProg??this.compile(e,MS,CS),this.downProg=this.downProg??this.compile(e,RS),this.blurProg=this.blurProg??this.compile(e,vS),this.tintProg=this.tintProg??this.compile(e,wS),this.fillProg=this.fillProg??this.compile(e,TS),this.finishProg=this.finishProg??this.compile(e,ES),!!(this.blurProg&&this.tintProg&&this.fillProg&&this.finishProg))}ensureTarget(e,t,r,o){let i=this.scratch[t];if(i&&i.w===r&&i.h===o)return i;i&&(e.deleteFramebuffer(i.fb),e.deleteTexture(i.tex));let s=this.allocTarget(e,r,o);return s&&(this.scratch[t]=s),s}allocTarget(e,t,r){let o=e.createTexture();if(!o)return null;e.bindTexture(e.TEXTURE_2D,o),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,t,r,0,e.RGBA,e.UNSIGNED_BYTE,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE);let i=e.createFramebuffer();return i?(e.bindFramebuffer(e.FRAMEBUFFER,i),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,o,0),e.bindFramebuffer(e.FRAMEBUFFER,null),{fb:i,tex:o,w:t,h:r}):(e.deleteTexture(o),null)}pass(e,t,r,o,i=!1){e.bindFramebuffer(e.FRAMEBUFFER,r.fb),e.viewport(0,0,r.w,r.h),e.useProgram(t),o(t),i?(e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA)):e.disable(e.BLEND),e.bindVertexArray(null),e.drawArrays(e.TRIANGLES,0,3)}restoreFb=null;restore(e){e.bindFramebuffer(e.FRAMEBUFFER,this.restoreFb),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA)}blurChain(e,t,r,o,i,s,a,l){let u=i<.05?1:Math.max(1,Math.min(64,Math.round(Math.sqrt(4*i*i+1)))),c=[this.ensureTarget(e,s,r,o),this.ensureTarget(e,a,r,o),this.ensureTarget(e,l,r,o)];if(!c[0]||!c[1]||!c[2])return null;let h=(d,f,m,p)=>this.pass(e,this.blurProg,f,b=>{e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,d),e.uniform1i(e.getUniformLocation(b,"uSrc"),0),e.uniform2f(e.getUniformLocation(b,"uDir"),m,p),e.uniform1i(e.getUniformLocation(b,"uBoxW"),u)});return h(t,c[0],1/r,0),h(c[0].tex,c[1],1/r,0),h(c[1].tex,c[0],1/r,0),h(c[0].tex,c[1],0,1/o),h(c[1].tex,c[0],0,1/o),h(c[0].tex,c[1],0,1/o),c[1].tex}source(e,t,r,o,i,s,a,l,u=null){let c=this.sources.get(t);if(c&&(c.sig!==r||!e.isTexture(c.tex))&&(e.deleteTexture(c.tex),c=void 0),!c){let h=document.createElement("canvas");h.width=o,h.height=i;let d=h.getContext("2d");if(!d)return null;let f=t.matrix;if(d.setTransform(f[0]*a,f[1]*a,f[2]*a,f[3]*a,o/2,i/2),l){if(d.fillStyle=Jr(t,d),!xr(d,t))return null;d.fill()}else if(s){let p=t.dims.x,b=t.dims.y;u?d.drawImage(s,u.sx,u.sy,u.sw,u.sh,-p/2,-b/2,p,b):d.drawImage(s,-p/2,-b/2,p,b)}else return null;let m=e.createTexture();if(!m)return null;e.bindTexture(e.TEXTURE_2D,m),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,h),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),c={sig:r,tex:m,w:o,h:i},this.sources.set(t,c)}return c.tex}uploadLocalSource(e,t,r,o,i,s){let a=this.sources.get(t);if(a&&(a.sig!==o||!e.isTexture(a.tex))&&(e.deleteTexture(a.tex),this.liveSrcTexes.delete(a.tex),a=void 0),!a){let l=e.createTexture();if(!l)return null;e.bindTexture(e.TEXTURE_2D,l),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,r),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),this.liveSrcTexes.add(l),a={sig:o,tex:l,w:i,h:s},this.sources.set(t,a)}return a.tex}bakeDropShadows(e,t,r,o){if(this.restoreFb=e.getParameter(e.FRAMEBUFFER_BINDING),!this.ensurePrograms(e)||r.length===0)return null;let{rs:i,pathMode:s}=o,a=t.raw.scaleX??1,l=t.raw.scaleY??1,u=4;for(let T of r){let C=s?{blur:T.blur,offX:T.offsetX,offY:T.offsetY}:Nt(rp(T),a,l);u=Math.max(u,Math.ceil(C.blur*2+Math.max(Math.abs(C.offX),Math.abs(C.offY))+4))}let c=t.matrix,h=Math.abs(c[0])*t.dims.x+Math.abs(c[2])*t.dims.y,d=Math.abs(c[1])*t.dims.x+Math.abs(c[3])*t.dims.y,f=Math.ceil(h+u*2),m=Math.ceil(d+u*2),p=Math.ceil(f*i),b=Math.ceil(m*i);if(!(f>0)||!(m>0)||p>8192||b>8192)return null;let x=Lt(t),g=o.source,y=o.sourceRect??null;x&&g&&(g=uo(g,y,x*i,Math.max(1,Math.ceil(t.dims.x*i)),Math.max(1,Math.ceil(t.dims.y*i))),y=null);let v=this.source(e,t,`${o.sig}|src`,p,b,g,i,s,y);if(!v)return null;let S=this.ensureTarget(e,3,p,b);if(!S)return null;let w=this.slot(e,t,o.sig,"shadow",p,b);if(!w)return null;e.bindFramebuffer(e.FRAMEBUFFER,S.fb),e.viewport(0,0,p,b),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT);for(let T of r){let C=s?{blur:T.blur,offX:T.offsetX,offY:T.offsetY}:Nt(rp(T),a,l),E=this.blurChain(e,v,p,b,C.blur*i/2,0,1,2);if(!E)return null;this.pass(e,this.tintProg,S,M=>{e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,E),e.uniform1i(e.getUniformLocation(M,"uMask"),0),e.uniform2f(e.getUniformLocation(M,"uOffUv"),-C.offX*i/p,-C.offY*i/b),e.uniform4f(e.getUniformLocation(M,"uColor"),T.rgba[0],T.rgba[1],T.rgba[2],T.rgba[3])},!0),this.pass(e,this.fillProg,S,M=>{e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,v),e.uniform1i(e.getUniformLocation(M,"uSrc"),0),e.uniform4f(e.getUniformLocation(M,"uColor"),1,1,1,1)},!0)}let R=S.tex,P=v;return this.pass(e,this.finishProg,w,T=>{e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,R),e.uniform1i(e.getUniformLocation(T,"uAcc"),0),e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,P),e.uniform1i(e.getUniformLocation(T,"uSil"),1),e.uniform1f(e.getUniformLocation(T,"uErase"),s?0:1)}),e.viewport(0,0,o.viewportW,o.viewportH),this.restore(e),{tex:w.tex,w:p,h:b}}bakeSolidFill(e,t,r,o,i,s,a,l,u,c){if(this.restoreFb=e.getParameter(e.FRAMEBUFFER_BINDING),!this.ensurePrograms(e))return null;let h=this.slot(e,t,a,l,i,s);if(!h)return null;let d=o;return this.pass(e,this.fillProg,h,f=>{e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,d),e.uniform1i(e.getUniformLocation(f,"uSrc"),0),e.uniform4f(e.getUniformLocation(f,"uColor"),r.rgba[0],r.rgba[1],r.rgba[2],r.rgba[3])}),e.viewport(0,0,u,c),this.restore(e),h.tex}},rp=n=>({color:n.color,rgba:n.rgba,blur:n.blur,offsetX:n.offsetX,offsetY:n.offsetY,nonScaling:!1});var ip=`attribute vec2 aPosition;
|
|
522
522
|
varying vec2 vTexCoord;
|
|
523
523
|
void main() {
|
|
524
524
|
vTexCoord = aPosition;
|
|
525
525
|
gl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);
|
|
526
526
|
}`,$e=`precision highp float;
|
|
527
527
|
uniform sampler2D uTexture;
|
|
528
|
-
varying vec2 vTexCoord;`,
|
|
528
|
+
varying vec2 vTexCoord;`,op=`
|
|
529
529
|
vec3 rgb2hsl(vec3 c) {
|
|
530
530
|
float maxc = max(c.r, max(c.g, c.b));
|
|
531
531
|
float minc = min(c.r, min(c.g, c.b));
|
|
@@ -567,7 +567,7 @@ vec3 hsl2rgb(vec3 hsl) {
|
|
|
567
567
|
hslChannel(p, q, h - 1.0 / 3.0)
|
|
568
568
|
);
|
|
569
569
|
}
|
|
570
|
-
`,
|
|
570
|
+
`,PS=n=>{let e=n/2;return e<.05?1:Math.max(1,Math.min(64,Math.round(Math.sqrt(4*e*e+1))))};function sp(n,e,t){let r=[];for(let o of n)switch(o.kind){case"Brightness":r.push({source:`${$e}
|
|
571
571
|
uniform float uW;
|
|
572
572
|
void main() {
|
|
573
573
|
vec4 color = texture2D(uTexture, vTexCoord);
|
|
@@ -585,7 +585,7 @@ color.rgb = clamp((color.rgb - 0.5) * uM + 0.5, 0.0, 1.0);
|
|
|
585
585
|
gl_FragColor = color;
|
|
586
586
|
}`,setup:(i,s)=>i.uniform1f(s.uM,o.contrast>=0?1/Math.max(1e-4,1-o.contrast):1+o.contrast)});break;case"Saturation":r.push({source:`${$e}
|
|
587
587
|
uniform float uSat;
|
|
588
|
-
${
|
|
588
|
+
${op}
|
|
589
589
|
void main() {
|
|
590
590
|
vec4 color = texture2D(uTexture, vTexCoord);
|
|
591
591
|
vec3 hsl = rgb2hsl(color.rgb);
|
|
@@ -606,14 +606,14 @@ color.rgb = lum + (color.rgb - lum) * factor;
|
|
|
606
606
|
gl_FragColor = color;
|
|
607
607
|
}`,setup:(i,s)=>i.uniform1f(s.uV,o.vibrance)});break;case"HueRotation":r.push({source:`${$e}
|
|
608
608
|
uniform float uShift;
|
|
609
|
-
${
|
|
609
|
+
${op}
|
|
610
610
|
void main() {
|
|
611
611
|
vec4 color = texture2D(uTexture, vTexCoord);
|
|
612
612
|
vec3 hsl = rgb2hsl(color.rgb);
|
|
613
613
|
hsl.x = fract(hsl.x + uShift / 360.0);
|
|
614
614
|
color.rgb = hsl2rgb(hsl);
|
|
615
615
|
gl_FragColor = color;
|
|
616
|
-
}`,setup:(i,s)=>i.uniform1f(s.uShift,o.rotation*100)});break;case"ColorMatrix":r.push(
|
|
616
|
+
}`,setup:(i,s)=>i.uniform1f(s.uShift,o.rotation*100)});break;case"ColorMatrix":r.push(kS(wh[o.matrixId]));break;case"Grayscale":{let i=o.mode==="lightness"?`
|
|
617
617
|
vec4 col = texture2D(uTexture, vTexCoord);
|
|
618
618
|
float average = (max(max(col.r, col.g),col.b) + min(min(col.r, col.g),col.b)) / 2.0;
|
|
619
619
|
gl_FragColor = vec4(average, average, average, col.a);`:o.mode==="luminosity"?`
|
|
@@ -638,7 +638,7 @@ gl_FragColor = vec4(1.0 - color.r,1.0 -color.g,1.0 - color.b,color.a);
|
|
|
638
638
|
} else {
|
|
639
639
|
gl_FragColor = color;
|
|
640
640
|
}
|
|
641
|
-
}`,setup:(i,s)=>{i.uniform1i(s.uInvert,o.invert?1:0),i.uniform1i(s.uAlpha,o.alphaOnly?1:0)}});break;case"Blur":{let i=
|
|
641
|
+
}`,setup:(i,s)=>{i.uniform1i(s.uInvert,o.invert?1:0),i.uniform1i(s.uAlpha,o.alphaOnly?1:0)}});break;case"Blur":{let i=PS(o.blur),s=`precision highp float;
|
|
642
642
|
uniform sampler2D uTexture;
|
|
643
643
|
uniform vec2 uTexSize;
|
|
644
644
|
uniform vec2 uDir;
|
|
@@ -663,7 +663,7 @@ float t = c0 + float(k);
|
|
|
663
663
|
acc += fetchMix(uDir.x > 0.5 ? vec2(t, pos.y) : vec2(pos.x, t));
|
|
664
664
|
}
|
|
665
665
|
gl_FragColor = acc / uBoxW;
|
|
666
|
-
}`;for(let a=0;a<6;a++){let l=a<3;r.push({source:s,setup:(c
|
|
666
|
+
}`;for(let a=0;a<6;a++){let l=a<3;r.push({source:s,setup:(u,c)=>{u.uniform2f(c.uTexSize,e,t),u.uniform2f(c.uDir,l?1:0,l?0:1),u.uniform1f(c.uBoxW,i)}})}break}case"Noise":r.push({source:`precision highp float;
|
|
667
667
|
uniform sampler2D uTexture;
|
|
668
668
|
uniform float uStepH;
|
|
669
669
|
uniform float uNoise;
|
|
@@ -692,7 +692,7 @@ float fposY = float(posY);
|
|
|
692
692
|
vec2 squareCoords = vec2(fposX * blockW, fposY * blockH);
|
|
693
693
|
vec4 color = texture2D(uTexture, squareCoords);
|
|
694
694
|
gl_FragColor = color;
|
|
695
|
-
}`,setup:(i,s)=>i.uniform1f(s.uBlocksize,o.blocksize)});break;case"Convolute":{let i=Math.round(Math.sqrt(o.matrix.length)),s=(i-1)/2,a=o.opaque?"vec4 color = vec4(0, 0, 0, 0);":"vec4 color = vec4(0, 0, 0, 1);",l=o.opaque?"color += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * "+i+".0 + w)];":"color.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * "+i+".0 + w)];",
|
|
695
|
+
}`,setup:(i,s)=>i.uniform1f(s.uBlocksize,o.blocksize)});break;case"Convolute":{let i=Math.round(Math.sqrt(o.matrix.length)),s=(i-1)/2,a=o.opaque?"vec4 color = vec4(0, 0, 0, 0);":"vec4 color = vec4(0, 0, 0, 1);",l=o.opaque?"color += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * "+i+".0 + w)];":"color.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * "+i+".0 + w)];",u=o.opaque?"gl_FragColor = color;":`float alpha = texture2D(uTexture, vTexCoord).a;
|
|
696
696
|
gl_FragColor = color;
|
|
697
697
|
gl_FragColor.a = alpha;`;r.push({source:`precision highp float;
|
|
698
698
|
uniform sampler2D uTexture;
|
|
@@ -708,8 +708,8 @@ vec2 matrixPos = vec2(uStepW * (w - ${s}.0), uStepH * (h - ${s}.0));
|
|
|
708
708
|
${l}
|
|
709
709
|
}
|
|
710
710
|
}
|
|
711
|
-
${
|
|
712
|
-
}`,setup:(
|
|
711
|
+
${u}
|
|
712
|
+
}`,setup:(c,h)=>c.uniform1fv(h.uMatrix,o.matrix)});break}case"BlendColor":{let i={multiply:`gl_FragColor.rgb *= uColor.rgb;
|
|
713
713
|
`,screen:`gl_FragColor.rgb = 1.0 - (1.0 - gl_FragColor.rgb) * (1.0 - uColor.rgb);
|
|
714
714
|
`,add:`gl_FragColor.rgb += uColor.rgb;
|
|
715
715
|
`,difference:`gl_FragColor.rgb = abs(gl_FragColor.rgb - uColor.rgb);
|
|
@@ -746,7 +746,7 @@ gl_FragColor = color;
|
|
|
746
746
|
if (color.a > 0.0) {
|
|
747
747
|
${i[o.mode]??i.multiply}
|
|
748
748
|
}
|
|
749
|
-
}`,setup:(s,a)=>{let[l,c
|
|
749
|
+
}`,setup:(s,a)=>{let[l,u,c]=mn(o.color);s.uniform4f(a.uColor,o.alpha*l/255,o.alpha*u/255,o.alpha*c/255,o.alpha)}});break}case"Vignette":r.push({source:`${$e}
|
|
750
750
|
uniform float uIntensity;
|
|
751
751
|
void main() {
|
|
752
752
|
vec4 color = texture2D(uTexture, vTexCoord);
|
|
@@ -798,7 +798,7 @@ vec4 color = texture2D(uTexture, vTexCoord);
|
|
|
798
798
|
float gray = dot(color.rgb, vec3(0.299, 0.587, 0.114));
|
|
799
799
|
color.rgb = mix(uColor1, uColor2, gray);
|
|
800
800
|
gl_FragColor = color;
|
|
801
|
-
}`,setup:(i,s)=>{let a=
|
|
801
|
+
}`,setup:(i,s)=>{let a=mn(o.color1).map(u=>u/255),l=mn(o.color2).map(u=>u/255);i.uniform3f(s.uColor1,a[0],a[1],a[2]),i.uniform3f(s.uColor2,l[0],l[1],l[2])}});break;case"Sketch":r.push({source:`precision highp float;
|
|
802
802
|
uniform sampler2D uTexture;
|
|
803
803
|
uniform float uStepW;
|
|
804
804
|
uniform float uStepH;
|
|
@@ -942,7 +942,7 @@ mapped = mix(uColor1, uColor2, (gray - 0.5) * 2.0);
|
|
|
942
942
|
}
|
|
943
943
|
color.rgb = mapped;
|
|
944
944
|
gl_FragColor = color;
|
|
945
|
-
}`,setup:(i,s)=>{let a=
|
|
945
|
+
}`,setup:(i,s)=>{let a=mn(o.color0).map(c=>c/255),l=mn(o.color1).map(c=>c/255),u=mn(o.color2||"#ffffff").map(c=>c/255);i.uniform3f(s.uColor0,a[0],a[1],a[2]),i.uniform3f(s.uColor1,l[0],l[1],l[2]),i.uniform3f(s.uColor2,u[0],u[1],u[2]),i.uniform1f(s.uCount,o.color2?2:1)}});break;case"Levels":r.push({source:`${$e}
|
|
946
946
|
uniform float uBlackPoint;
|
|
947
947
|
uniform float uWhitePoint;
|
|
948
948
|
uniform float uGamma;
|
|
@@ -978,7 +978,7 @@ color.r = curveLookup(color.r);
|
|
|
978
978
|
color.g = curveLookup(color.g);
|
|
979
979
|
color.b = curveLookup(color.b);
|
|
980
980
|
gl_FragColor = color;
|
|
981
|
-
}`,setup:(i,s)=>{let a=new Float32Array(32),l=Math.min(16,o.points.length/2);for(let h=0;h<l;h++)a[h*2]=o.points[h*2]/255,a[h*2+1]=o.points[h*2+1]/255;let
|
|
981
|
+
}`,setup:(i,s)=>{let a=new Float32Array(32),l=Math.min(16,o.points.length/2);for(let h=0;h<l;h++)a[h*2]=o.points[h*2]/255,a[h*2+1]=o.points[h*2+1]/255;let u=l>0?[o.points[0],o.points[1]]:[0,0],c=l>0?[o.points[(l-1)*2],o.points[(l-1)*2+1]]:[255,255];i.uniform2fv(s.uPts,a),i.uniform1f(s.uCount,l),i.uniform2f(s.uFirst,u[0]/255,u[1]/255),i.uniform2f(s.uLast,c[0]/255,c[1]/255)}});break;case"ColorMatrixOp":r.push({source:`precision highp float;
|
|
982
982
|
uniform sampler2D uTexture;
|
|
983
983
|
varying vec2 vTexCoord;
|
|
984
984
|
uniform mat4 uColorMatrix;
|
|
@@ -1024,7 +1024,7 @@ vec3 lin = pow(color.rgb, vec3(2.2));
|
|
|
1024
1024
|
lin = clamp(lin * pow(2.0, uExposure) + vec3(uOffset), 0.0, 1.0);
|
|
1025
1025
|
color.rgb = pow(lin, vec3(1.0 / (max(0.01, uGamma) * 2.2)));
|
|
1026
1026
|
gl_FragColor = color;
|
|
1027
|
-
}`,setup:(i,s)=>{i.uniform1f(s.uExposure,o.exposure),i.uniform1f(s.uOffset,o.offset),i.uniform1f(s.uGamma,o.gamma)}});break}return r}function
|
|
1027
|
+
}`,setup:(i,s)=>{i.uniform1f(s.uExposure,o.exposure),i.uniform1f(s.uOffset,o.offset),i.uniform1f(s.uGamma,o.gamma)}});break}return r}function kS(n){return{source:`precision highp float;
|
|
1028
1028
|
uniform sampler2D uTexture;
|
|
1029
1029
|
varying vec2 vTexCoord;
|
|
1030
1030
|
uniform mat4 uColorMatrix;
|
|
@@ -1034,14 +1034,14 @@ vec4 color = texture2D(uTexture, vTexCoord);
|
|
|
1034
1034
|
color *= uColorMatrix;
|
|
1035
1035
|
color += uConstants;
|
|
1036
1036
|
gl_FragColor = color;
|
|
1037
|
-
}`,setup:(e,t)=>{e.uniformMatrix4fv(t.uColorMatrix,!1,new Float32Array([n[0],n[1],n[2],n[3],n[5],n[6],n[7],n[8],n[10],n[11],n[12],n[13],n[15],n[16],n[17],n[18]])),e.uniform4f(t.uConstants,n[4],n[9],n[14],n[19])}}}var Ta=class{gl;programs=new Map;cache=new WeakMap;quadBuffer=null;vertexShader=null;disposed=!1;constructor(e){this.gl=e}getFilteredTexture(e,t,r,o,i){if(this.disposed||r<=0||o<=0)return null;let s=`${r}x${o}|${Ii(i)}`,a=this.cache.get(e);return a&&a.sig===s&&a.source===t?a.outTex:(a&&(this.gl.deleteTexture(a.sourceTex),this.gl.deleteTexture(a.outTex)),this.runChain(e,t,r,o,i,s))}runChain(e,t,r,o,i,s){let a=this.gl,l=np(i,r,o);if(!l.length)return null;let c=a.getParameter(a.VIEWPORT),u=a.isEnabled(a.BLEND),h=a.getParameter(a.CURRENT_PROGRAM),d=a.getParameter(a.FRAMEBUFFER_BINDING),f=a.getParameter(a.ARRAY_BUFFER_BINDING),m=a.getParameter(a.TEXTURE_BINDING_2D),p=a.getParameter(a.VERTEX_ARRAY_BINDING);a.bindVertexArray(null),a.disable(a.BLEND),a.viewport(0,0,r,o);let b=a.createTexture();if(!b)return null;a.bindTexture(a.TEXTURE_2D,b),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,a.NEAREST),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.NEAREST),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE),a.texImage2D(a.TEXTURE_2D,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,t);let x=()=>{let M=a.createTexture();return M?(a.bindTexture(a.TEXTURE_2D,M),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,a.NEAREST),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.NEAREST),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE),a.texImage2D(a.TEXTURE_2D,0,a.RGBA,r,o,0,a.RGBA,a.UNSIGNED_BYTE,null),M):null},g=x(),y=x(),v=a.createFramebuffer(),S=a.createFramebuffer();if(!g||!y||!v||!S)return null;let w=this.ensureQuad(),R=b,P=g,E=v;for(let M of l){let k=this.ensureProgram(M.source);if(!k)break;a.useProgram(k.program),a.bindFramebuffer(a.FRAMEBUFFER,E),a.framebufferTexture2D(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,P,0),a.activeTexture(a.TEXTURE0),a.bindTexture(a.TEXTURE_2D,R),a.uniform1i(k.uniforms.uTexture,0),k.uniforms.uStepW&&a.uniform1f(k.uniforms.uStepW,1/r),k.uniforms.uStepH&&a.uniform1f(k.uniforms.uStepH,1/o),M.setup(a,k.uniforms),a.bindBuffer(a.ARRAY_BUFFER,w),a.enableVertexAttribArray(k.aPosition),a.vertexAttribPointer(k.aPosition,2,a.FLOAT,!1,0,0),a.drawArrays(a.TRIANGLE_STRIP,0,4),R=P,E===v?(P=y,E=S):(P=g,E=v)}let C=R;a.bindVertexArray(p),a.bindFramebuffer(a.FRAMEBUFFER,d),a.viewport(c[0],c[1],c[2],c[3]),u&&a.enable(a.BLEND),a.useProgram(h),a.bindBuffer(a.ARRAY_BUFFER,f),a.activeTexture(a.TEXTURE0),a.bindTexture(a.TEXTURE_2D,m),a.deleteFramebuffer(v),a.deleteFramebuffer(S);let T=C===g?y:g;return a.deleteTexture(T),a.bindTexture(a.TEXTURE_2D,C),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.LINEAR_MIPMAP_LINEAR),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE),a.generateMipmap(a.TEXTURE_2D),a.bindTexture(a.TEXTURE_2D,m),this.cache.set(e,{sig:s,source:t,sourceTex:b,outTex:C}),C}ensureQuad(){let e=this.gl;return this.quadBuffer||(this.quadBuffer=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.quadBuffer),e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,1]),e.STATIC_DRAW)),this.quadBuffer}ensureProgram(e){let t=this.programs.get(e);if(t)return t;let r=this.gl;if(!this.vertexShader){let h=r.createShader(r.VERTEX_SHADER);if(!h)return null;r.shaderSource(h,tp),r.compileShader(h),this.vertexShader=h}let o=this.vertexShader,i=r.createShader(r.FRAGMENT_SHADER),s=r.createProgram();if(!i||!s)return null;if(r.shaderSource(i,e),r.compileShader(i),r.attachShader(s,o),r.attachShader(s,i),r.linkProgram(s),r.deleteShader(i),!r.getProgramParameter(s,r.LINK_STATUS))return console.warn("[gpuImageFilters] program link failed:",r.getProgramInfoLog(s)),r.deleteProgram(s),null;let l={},c=r.getProgramParameter(s,r.ACTIVE_UNIFORMS);for(let h=0;h<c;h++){let d=r.getActiveUniform(s,h);if(!d)continue;let f=d.name.replace(/\[0\]$/,"");l[f]=r.getUniformLocation(s,d.name)}let u={program:s,aPosition:r.getAttribLocation(s,"aPosition"),uniforms:l};return this.programs.set(e,u),u}invalidate(){this.cache=new WeakMap,this.programs.clear(),this.vertexShader=null,this.quadBuffer=null}dispose(){this.disposed=!0;let e=this.gl;for(let t of this.programs.values())e.deleteProgram(t.program);this.programs.clear(),this.invalidate()}};var Ea=class{constructor(e,t){this.gl=e;this.epoch=t}gl;epoch;fxPainter=null;filterChain=null;get fx(){return this.fxPainter||(this.fxPainter=new wa(this.epoch)),this.fxPainter}get filters(){return this.filterChain||(this.filterChain=new Ta(this.gl)),this.filterChain}invalidate(){this.fxPainter?.invalidate(this.gl),this.filterChain?.invalidate()}invalidateTextDerivedBakes(){this.fxPainter?.invalidateTextDerivedBakes(this.gl)}};var MS=[.914,.914,.914,1],Ca=class{host;sources;text;frame={bakeDeadline:0,bakeMore:!1,animationActive:!1};settle;flatFrame=!0;shadow;psd;stroke;gpu;isolator=null;isolating=!1;blender=null;blendWrapNode=null;clipContentNode=null;cropGhostPreDrawn=null;puzzleBox=null;stencilClip=new ya;maskGpu=new Sa;constructor(e,t,r){this.host=e,this.sources=t,this.text=r,this.gpu=new Ea(e.gl,e.renderEpoch),this.shadow=new fa(e),this.settle=new An(()=>this.host.requestRenderAll()),this.stroke=new ga(e,this.frame,this.settle),this.psd=new va(e,this.frame,this.gpu,()=>this.puzzleBox,this.settle,this.compositeFxBlended)}beginFrame(e){this.frame.animationActive=!1,this.frame.bakeDeadline=e+qm(this.host.isExporting()),this.frame.bakeMore=!1,this.stencilClip.resetFrame(),this.maskGpu.activeThisFrame=!1}noteVptChange(){this.settle.noteInteraction()}noteExternalInteraction(){this.settle.noteInteraction()}groupMask(e){let t=e.raw.mask;if(!t||t.disabled===!0||typeof t.src!="string")return null;let r=this.sources.maskTexture(t.src);if(!r)return null;let o=t.defaultColor===255,i=e.dims.x,s=e.dims.y,a=(Number(t.offsetX)||0)-i/2,l=(Number(t.offsetY)||0)-s/2,c=(Number(t.width)||0)*(Number(t.scaleX)||1),u=(Number(t.height)||0)*(Number(t.scaleY)||1);if(!(c>0)||!(u>0))return null;let h=e.matrix,d=this.host.canvasEl.width,f=this.host.canvasEl.height,m=[d/this.host.dpr,0,0,-f/this.host.dpr,0,f/this.host.dpr],p=ve(this.host.viewportTransform),b=ve(h),x=[1/c,0,0,1/u,-a/c,-l/u];if(!p||!b)return null;let g=$(x,$(b,$(p,m))),y=[g[0],g[1],0,g[2],g[3],0,g[4],g[5],1];return{tex:r,maskInv:y,coversHost:o}}renderPuzzleChildren(e,t){if(!(e instanceof le)){t();return}let r=this.puzzleBox;this.puzzleBox={hw:e.dims.x/2,hh:e.dims.y/2};try{t()}finally{this.puzzleBox=r}}puzzleClampedQuad(e,t,r,o=0,i=0){return zr(this.puzzleBox,e,t,r,o,i)}renderIsolatedGroup(e,t){let r=this.host.gl;this.flatFrame=!1,this.isolator||(this.isolator=new ua),this.host.batchOrder.flushAll();let o=()=>{if(e instanceof J)for(let s of e.children)this.renderSceneNode(s);else this.renderSceneNodeContentOnly(e)};if(!this.isolator.begin(r,this.host.canvasEl.width,this.host.canvasEl.height)){this.renderPuzzleChildren(e,o);return}this.isolating=!0;let i=1;if(e instanceof J){let s=()=>{for(let a of e.children)a.setIsolation(!0);o();for(let a of e.children)a.setIsolation(!1)};this.renderPuzzleChildren(e,s),i=e.renderOpacity}else o();this.host.batchOrder.flushAll(),this.isolating=!1,this.isolator.end(r),r.viewport(0,0,this.host.canvasEl.width,this.host.canvasEl.height),this.isolator.composite(r,i,t)}renderSceneNodeContentOnly(e){this.renderSceneNode(e)}renderBlendedNode(e,t){let r=this.host.gl;this.flatFrame=!1,this.blender||(this.blender=new jo),this.host.batchOrder.flushAll();let o=this.host.canvasEl.width,i=this.host.canvasEl.height,s=this.blendWrapNode;this.blendWrapNode=e;try{if(!this.blender.begin(r,o,i)){this.renderSceneNode(e);return}this.renderSceneNode(e),this.host.batchOrder.flushAll(),this.blender.end(r),r.viewport(0,0,o,i),this.blender.composite(r,t)}finally{this.blendWrapNode=s}}compositeFxBlended=(e,t)=>{let r=this.host.gl;this.flatFrame=!1,this.blender||(this.blender=new jo),this.host.batchOrder.flushAll();let o=this.host.canvasEl.width,i=this.host.canvasEl.height;if(!this.blender.begin(r,o,i)){t();return}t(),this.host.batchOrder.flushAll(),this.blender.end(r),r.viewport(0,0,o,i),this.blender.composite(r,e)};renderSceneNode(e){if(e.visible&&e!==this.host.warpSessionTarget){if(this.blendWrapNode!==e){let t=ha(e.raw.globalCompositeOperation);if(t!==null){this.renderBlendedNode(e,t);return}}if(e instanceof J){if(this.stencilClip.begin(e,this.host,{rasterMask:Co(e)!==null})){let o=this.groupMask(e);!this.isolating&&((e.raw.opacity??1)<1||!!o)?this.renderIsolatedGroup(e,o):this.renderPuzzleChildren(e,()=>{for(let s of e.children)this.renderSceneNode(s)}),this.stencilClip.end(this.host);return}let t=this.groupMask(e);if(!this.isolating&&((e.raw.opacity??1)<1||!!t)){this.renderIsolatedGroup(e,t);return}this.renderPuzzleChildren(e,()=>{for(let o of e.children)this.renderSceneNode(o)});return}if(this.clipContentNode!==e&&Wc(e)){if(this.preDrawCropGhost(e),this.stencilClip.begin(e,this.host,{rasterMask:!1})){let r=this.isolating;this.clipContentNode=e,this.isolating=!0,this.renderSceneNodeContentOnly(e),this.clipContentNode=null,this.isolating=r,this.stencilClip.end(this.host),this.cropGhostPreDrawn=null;return}let t=this.clipContentNode;this.clipContentNode=e,this.renderSceneNodeContentOnly(e),this.clipContentNode=t,this.cropGhostPreDrawn=null;return}if(!this.isolating&&Co(e)){let t=this.groupMask(e);if(t){this.renderIsolatedGroup(e,t);return}}if(e.isTextType){if(this.text.renderTextPathBackground(e,this.host.zoom*this.host.dpr),typeof e.raw.renderSrc=="string"&&e!==this.host.editingNode){let i=e.imageEl?this.host.textures.get(e.imageEl):null;if(i){let s=e.bitmapRect,a=s.x!==0||s.y!==0?$(e.matrix,[1,0,0,1,s.x,s.y]):e.matrix;s.angle&&(a=$(a,kt({angle:-s.angle}))),this.shadow.render(e),this.psd.render(e,"below");let l=Eo(e.raw);this.host.batch.pushQuad(a,s.w,s.h,[1,1,1,e.renderOpacity*l],i,[0,0,1,1],null,e),this.psd.render(e,"above");return}if(this.sources.isImagePending(e)){this.renderImagePlaceholder(e);return}}let t=Mh(e.raw);if(t&&e!==this.host.editingNode){this.text.renderWarpedText(e,t);return}let r=qn(e.raw);if(r&&e!==this.host.editingNode){this.text.renderPsdWarpedText(e,r);return}let o=Ge(e.raw);if(o&&e!==this.host.editingNode){this.text.renderArcText(e,o,this.host.zoom*this.host.dpr);return}this.shadow.render(e),this.psd.render(e,"below"),this.text.renderTextGlyphs(e,this.host.zoom*this.host.dpr),this.psd.render(e,"above");return}if(e.isShapeType){let t=e.strokeDecl,r=e.shapeMesh;if(r||t){this.shadow.render(e),this.psd.render(e,"below");let o=()=>{this.stroke.render(e)};if(t){let i=t.paintFirst==="stroke";if(i&&o(),r){let s=this.paintParams(e);s?this.host.meshBatch.pushMesh(e.matrix,[1,1,1,e.renderOpacity],r.verts,r.triangles,s,e):this.host.meshBatch.pushMesh(e.matrix,e.drawColor,r.verts,r.triangles,void 0,e)}i||o()}else if(r){let i=this.paintParams(e);i?this.host.meshBatch.pushMesh(e.matrix,[1,1,1,e.renderOpacity],r.verts,r.triangles,i,e):this.host.meshBatch.pushMesh(e.matrix,e.drawColor,r.verts,r.triangles,void 0,e)}}this.psd.render(e,"above");return}if(e.isLineType){this.shadow.render(e),this.stroke.render(e);return}if(e instanceof ae){this.renderMaskNode(e);return}if(e instanceof ie&&e.paintSource){this.renderAnimatedNode(e);return}if(e.isImageType&&!e.imageEl){this.sources.isImagePending(e)&&this.renderImagePlaceholder(e);return}this.renderImageFamily(e)}}renderImageFamily(e){if(this.shadow.render(e),this.psd.render(e,"below"),e.isSolidType){let i=e.strokeDecl?.paintFirst==="stroke";i&&this.stroke.render(e);let s=this.paintParams(e);if(s){this.host.batch.pushPaintQuad(e.matrix,e.dims.x,e.dims.y,s,e.renderOpacity,this.solidRadii(e)),i||this.stroke.render(e);return}}let t=this.imageTextureOf(e);e===this.host.cropGhostNode&&e!==this.cropGhostPreDrawn&&e.imageEl&&t&&this.drawCropGhost(e,t);let r=e.cropRect,o=r&&e.imageEl?[r.sx/e.imageEl.naturalWidth,r.sy/e.imageEl.naturalHeight,(r.sx+r.sw)/e.imageEl.naturalWidth,(r.sy+r.sh)/e.imageEl.naturalHeight]:[0,0,1,1];this.host.batch.pushQuad(e.matrix,e.dims.x,e.dims.y,e.drawColor,t,o,this.quadRadii(e),e),e.isSolidType&&e.strokeDecl?.paintFirst!=="stroke"&&this.stroke.render(e),this.psd.render(e,"above")}imageTextureOf(e){let t=e.isImageType&&!(e instanceof ie)?ao(e.raw.filters):[],r=t.length&&e.imageEl?this.gpu.filters.getFilteredTexture(e,e.imageEl,e.imageEl.naturalWidth||e.imageEl.width,e.imageEl.naturalHeight||e.imageEl.height,t):null,o=t.length?e.imageEl:this.sources.svgRasterSource(e,this.host.zoom,this.host.dpr);return r??(o?this.host.textures.get(o):null)}drawCropGhost(e,t){if(!e.imageEl)return;let r=e.dims,o=e.raw.cropX??0,i=e.raw.cropY??0,s=e.imageEl.naturalWidth,a=e.imageEl.naturalHeight,l={x:-r.x/2-o+s/2,y:-r.y/2-i+a/2},c=$(e.matrix,[1,0,0,1,l.x,l.y]);this.host.batch.pushQuad(c,s,a,[1,1,1,.5*e.renderOpacity],t)}preDrawCropGhost(e){if(e!==this.host.cropGhostNode||!e.imageEl)return;let t=this.imageTextureOf(e);t&&(this.cropGhostPreDrawn=e,this.drawCropGhost(e,t))}renderMaskNode(e){let t=e.clipImageRaw;if(e.clipDynamicKind){e.tickDynamicClip(performance.now());let f=e.dynamicClipSource();if(!f||!e.imageEl){this.sources.isImagePending(e)&&this.renderImagePlaceholder(e);return}this.psd.render(e,"below");let m=f;this.host.textures.update(m);let p=this.host.textures.get(m),b=this.host.textures.get(e.imageEl),x=m,g=x.videoWidth||x.width||0,y=x.videoHeight||x.height||0;if(p&&b&&g&&y){let v=this.maskGpu.render(e,this.host.gl,this.host.zoom,this.host.dpr,{maskTex:b,clipTex:p,clipW:g,clipH:y});if(v){this.flatFrame=!1;let S=this.puzzleClampedQuad(e,v.w,v.h);S&&this.host.batch.pushQuad(S.matrix,S.w,S.h,[1,1,1,e.renderOpacity],v.tex,S.uv,null,e),this.psd.render(e,"above"),e.clipAnimating&&(this.frame.animationActive=!0);return}}return}if(!t){if(this.shadow.render(e),!e.imageEl){this.sources.isImagePending(e)&&this.renderImagePlaceholder(e);return}this.psd.render(e,"below");let f=this.sources.svgRasterSource(e,this.host.zoom,this.host.dpr)??e.imageEl,m=this.host.textures.get(f),p=this.puzzleClampedQuad(e,e.dims.x,e.dims.y);p&&this.host.batch.pushQuad(p.matrix,p.w,p.h,[1,1,1,e.renderOpacity],m,p.uv,null,e),this.psd.render(e,"above");return}let r=e.clipImageEl;if(!r||!e.imageEl){this.sources.isImagePending(e)&&this.renderImagePlaceholder(e);return}let o=ao(t.filters),i=r,s=i.naturalWidth||i.videoWidth||i.width||t.width||0,a=i.naturalHeight||i.videoHeight||i.height||t.height||0,l=o.length?this.gpu.filters.getFilteredTexture(e,r,s,a,o):this.host.textures.get(r),c=this.host.textures.get(e.imageEl);if(!l||!c||!s||!a)return;let u=this.maskGpu.render(e,this.host.gl,this.host.zoom,this.host.dpr,{maskTex:c,clipTex:l,clipW:s,clipH:a});if(!u)return;this.psd.render(e,"below");let h=this.puzzleClampedQuad(e,u.w,u.h),d=e===this.host.maskCropNode?.5:1;h&&this.host.batch.pushQuad(h.matrix,h.w,h.h,[1,1,1,d*e.renderOpacity],u.tex,h.uv,null,e),this.psd.render(e,"above")}renderAnimatedNode(e){let t=e.tick(performance.now()),r=e.paintSource;if(!r)return;let o=this.host.textures.get(r);o&&t&&this.host.textures.update(r),this.shadow.render(e),this.psd.render(e,"below"),this.host.batch.pushQuad(e.matrix,e.dims.x,e.dims.y,e.drawColor,o,[0,0,1,1],this.quadRadii(e),e),this.psd.render(e,"above"),e.animating&&(this.frame.animationActive=!0)}renderImagePlaceholder(e){let{x:t,y:r}=e.dims;if(!(t>0)||!(r>0))return;let o=e.renderOpacity,i=oe(e.raw.fill),s=i[3]>0?i:MS;this.host.batch.pushQuad(e.matrix,t,r,[s[0],s[1],s[2],s[3]*o],null,[0,0,1,1],this.quadRadii(e),e)}quadRadii(e){if(e.isSolidType){let t=it(e.raw,e.dims.x,e.dims.y);return t?[t.rx,t.ry]:null}if(e.isImageType&&!(e instanceof ie)){let t=fr(e.raw,e.dims.x,e.dims.y);return t?[t,t]:null}return null}solidRadii(e){let t=it(e.raw,e.dims.x,e.dims.y);return t?[t.rx,t.ry]:null}paintParams(e){let t=e.fillPaint;if(!t)return null;if(t.kind==="gradient"){let r=this.host.gradientRamps.get(t.decl);return r?{kind:"gradient",decl:t.decl,inv:ve(ci(t.decl,e.dims.x,e.dims.y)),tex:r}:null}if(t.kind==="pattern"){let r=this.sources.patternTexture(t.decl.src);return r?{kind:"pattern",inv:ve(fi(t.decl,e.dims.x,e.dims.y)),tex:r.tex,size:[r.w,r.h],repeat:Pu(t.decl.repeat)}:null}return null}invalidateGlResources(){this.shadow.invalidate(),this.psd.invalidate(),this.stroke.invalidate(),this.maskGpu.invalidate(),this.isolator&&(this.isolator.dispose(this.host.gl),this.isolator=null),this.blender&&(this.blender.dispose(this.host.gl),this.blender=null),this.gpu.invalidate()}invalidateTextDerivedBakes(){this.shadow.invalidate(),this.psd.invalidate(),this.stroke.invalidate(),this.gpu.invalidateTextDerivedBakes()}};var Hc=n=>{let e=n.mask;if(!e||typeof e!="object"||Array.isArray(e))return null;let t=e;if(t.disabled===!0||typeof t.src!="string"||!t.src)return null;let r=Number(t.width),o=Number(t.height);return!(r>0)||!(o>0)?null:{src:t.src,width:r,height:o,left:typeof t.left=="number"?t.left:void 0,top:typeof t.top=="number"?t.top:void 0,offsetX:typeof t.offsetX=="number"?t.offsetX:void 0,offsetY:typeof t.offsetY=="number"?t.offsetY:void 0,defaultColor:typeof t.defaultColor=="number"?t.defaultColor:void 0,crossOrigin:typeof t.crossOrigin=="string"?t.crossOrigin:null}},rp=n=>n.startsWith("resource/")?n.replace("resource/","/resource/"):n,op=n=>{for(let e=0;e<n.length;e+=4){let t=n[e],r=n[e+1],o=n[e+2];t===r&&r===o?n[e+3]=t:t===0&&r===0&&o===0&&(n[e+3]=0)}},ip=(n,e,t)=>({x:typeof n.offsetX=="number"&&Number.isFinite(n.offsetX)?n.offsetX:(n.left??e)-e,y:typeof n.offsetY=="number"&&Number.isFinite(n.offsetY)?n.offsetY:(n.top??t)-t}),sp=(n,e,t,r,o,i)=>{if(r<=0&&t<=0&&i+r>=e&&o+t>=n)return[];let s=[];return r>0&&s.push([0,0,n,r]),t>0&&s.push([0,0,t,e]),r+i<e&&s.push([0,r+i,n,e-i-r]),t+o<n&&s.push([t+o,0,n-o-t,e]),s},ap=(n,e,t,r,o,i)=>{let s=Math.max(1,Math.round(e.x)),a=Math.max(1,Math.round(e.y)),l=document.createElement("canvas");l.width=t.width,l.height=t.height;let c=l.getContext("2d",{willReadFrequently:!0}),u=document.createElement("canvas");u.width=s,u.height=a;let h=u.getContext("2d");if(!c||!h)return null;try{c.drawImage(r,0,0);let f=c.getImageData(0,0,t.width,t.height);op(f.data),c.putImageData(f,0,0)}catch{return null}let d=ip(t,o,i);if(h.drawImage(l,d.x,d.y),t.defaultColor===255){h.fillStyle="#000000";for(let[f,m,p,b]of sp(s,a,d.x,d.y,t.width,t.height))h.fillRect(f,m,p,b)}return h.globalCompositeOperation="source-in",h.drawImage(n,0,0),u},lp=n=>new Promise(e=>{n.toBlob(t=>{if(!t){e(null);return}let r=URL.createObjectURL(t),o=new Image;o.onload=()=>{URL.revokeObjectURL(r),e(o)},o.onerror=()=>{URL.revokeObjectURL(r),e(null)},o.src=r})});var qo={create(n,e){if(typeof document<"u"){let t=document.createElement("canvas");return t.width=n,t.height=e,t}if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(n,e);throw new Error("Canvas is not available")}},Nn=n=>{let e=n.getContext("2d");if(!e)throw new Error("Failed to get canvas context");return e},Ko=n=>{n.width=0,n.height=0},cp=n=>{"close"in n?n.close():Ko(n)};var Ma=640,Qo=80,up=async(n,e={})=>{let{parseGIF:t,decompressFrame:r}=await import("gifuct-js"),o=t(n),i=null,s=(o.frames??[]).map(T=>T.image?(!T.gce&&i&&(T.gce=i),i=null,r(T,o.gct,!0)):(T.gce&&(i=T.gce),null)).filter(T=>T!==null);if(!s||!s.length)throw new Error("No frames available");let a=o.lsd,l=a?.width??s[0].dims.width,c=a?.height??s[0].dims.height,u=Math.max(l,c),h=u>Ma?Ma/u:1,d=Math.max(1,Math.round(l*h)),f=Math.max(1,Math.round(c*h)),m=s.reduce((T,M)=>T+(M.delay||0),0)/1e3,p=s.length>Qo?s.slice(0,Qo):s,b=p.reduce((T,M)=>T+(M.delay||0),0),x=p.length>0?b/p.length:100,g=e.canvasFactory??qo,y=g.create(1,1),v=Nn(y),S=g.create(l,c),w=Nn(S),R=g.create(d*p.length,f),P=Nn(R);if(!v||!w||!P)throw new Error("Failed to get canvas context");S.width=l,S.height=c,R.width=d*p.length,R.height=f;let E,C;return p.forEach((T,M)=>{E?.disposalType===2?w.clearRect(E.dims.left,E.dims.top,E.dims.width,E.dims.height):E?.disposalType===3&&C&&w.putImageData(C,0,0),C=T.disposalType===3?w.getImageData(0,0,l,c):void 0,y.width=T.dims.width,y.height=T.dims.height;let k=v.createImageData(T.dims.width,T.dims.height);k.data.set(T.patch),v.putImageData(k,0,0),w.drawImage(y,T.dims.left,T.dims.top),P.drawImage(S,0,0,l,c,d*M,0,d,f),E=T}),Ko(y),Ko(S),{canvas:R,frameWidth:d,framesLength:p.length,delay:x,frameDelays:p.map(T=>T.delay||100),duration:m}},hp=(n,e,t,r,o={})=>{if(!n.length)throw new Error("No frames available");let i=o.canvasFactory??qo,s=Math.max(e,t),a=s>Ma?Ma/s:1,l=Math.max(1,Math.round(e*a)),c=Math.max(1,Math.round(t*a)),u=i.create(e,t),h=Nn(u),d=i.create(l*Math.min(n.length,Qo),c),f=Nn(d);if(!h||!f)throw new Error("Failed to get canvas context");u.width=e,u.height=t,d.width=l*Math.min(n.length,Qo),d.height=c;let m=n.slice(0,Qo);m.forEach((b,x)=>{let g=h.createImageData(e,t);g.data.set(new Uint8ClampedArray(b)),h.putImageData(g,0,0),f.drawImage(u,0,0,e,t,l*x,0,l,c)}),Ko(u);let p=m.map((b,x)=>Math.max(1,r[x]??100));return{canvas:d,frameWidth:l,framesLength:m.length,delay:p.reduce((b,x)=>b+x,0)/p.length,frameDelays:p,duration:p.reduce((b,x)=>b+x,0)/1e3}};var RS=[137,80,78,71,13,10,26,10],Yr=n=>{let e=new Uint8Array(n);if(e.length<8||!RS.every((r,o)=>e[o]===r))return!1;let t=new DataView(n);for(let r=8;r+12<=e.length;){let o=t.getUint32(r),i=r+o+12;if(i>e.length)return!1;let s=String.fromCharCode(...e.subarray(r+4,r+8));if(s==="acTL")return o===8&&t.getUint32(r+8)>0;if(s==="IDAT"||s==="IEND")return!1;r=i}return!1},PS=async n=>Yr(await n.arrayBuffer()),kS=async n=>{try{let e=await fetch(n);return e.ok&&Yr(await e.arrayBuffer())}catch{return!1}},dp=async(n,e={})=>{if(!Yr(n))throw new Error("Not an animated PNG");let{default:t}=await import("upng-js"),r=t.decode(n);return r.frames=r.frames.slice(0,80),hp(t.toRGBA8(r),r.width,r.height,r.frames.map(o=>o.delay),e)};var fp=640,AS=80,Ra=100,Gc=(n,e)=>String.fromCharCode(n[e],n[e+1],n[e+2],n[e+3]),Xc=n=>{if(n.byteLength<12)return!1;let e=new Uint8Array(n,0,12);return Gc(e,0)==="RIFF"&&Gc(e,8)==="WEBP"},pp=n=>{if(!Xc(n))return!1;let e=new Uint8Array(n,0,Math.min(n.byteLength,512)),t=12;for(;t+8<=e.length;){let r=Gc(e,t);if(r==="VP8X")return t+8<e.length&&(e[t+8]&2)!==0;if(r==="ANIM"||r==="ANMF")return!0;if(r==="VP8 "||r==="VP8L")return!1;let o=e[t+4]|e[t+5]<<8|e[t+6]<<16|e[t+7]<<24;if(o<0)return!1;t+=8+o+o%2}return!1},NS=async n=>pp(await n.slice(0,512).arrayBuffer()),LS=async n=>{try{let e=await fetch(n,{headers:{Range:"bytes=0-511"}});return e.ok?pp(await e.arrayBuffer()):!1}catch{return!1}},bp=(n,e,t,r={})=>{let o=(r.canvasFactory??qo).create(n*t,e);o.width=n*t,o.height=e;let i=Nn(o);if(!i)throw new Error("Failed to get canvas context");return{canvas:o,ctx:i}},xp=(n,e)=>{let t=Math.max(n,e),r=t>fp?fp/t:1;return{width:Math.max(1,Math.round(n*r)),height:Math.max(1,Math.round(e*r))}},mp=async(n,e={})=>{let t=URL.createObjectURL(new Blob([n],{type:"image/webp"}));try{let r=await new Promise((l,c)=>{let u=new Image;u.onload=()=>l(u),u.onerror=()=>c(new Error("Failed to load WebP")),u.src=t}),{width:o,height:i}=xp(r.naturalWidth,r.naturalHeight),{canvas:s,ctx:a}=bp(o,i,1,e);return a.drawImage(r,0,0,o,i),{canvas:s,frameWidth:o,framesLength:1,delay:Ra,frameDelays:[Ra],duration:0}}finally{URL.revokeObjectURL(t)}},gp=async(n,e={})=>{let t=globalThis.ImageDecoder;if(!t||!await t.isTypeSupported("image/webp"))return mp(n,e);let r=new t({data:n,type:"image/webp",preferAnimation:!0});try{await r.tracks.ready;let o=r.tracks.selectedTrack;if(!o?.frameCount||o.frameCount<2)return mp(n,e);let i=Math.min(o.frameCount,AS),s=await r.decode({frameIndex:0}),{width:a,height:l}=xp(s.image.displayWidth,s.image.displayHeight),{canvas:c,ctx:u}=bp(a,l,i,e),h=[];for(let d=0;d<i;d++){let{image:f}=d===0?s:await r.decode({frameIndex:d}),m=typeof f.duration=="number"&&f.duration>0?f.duration/1e3:Ra;h.push(m),u.drawImage(f,a*d,0,a,l),f.close()}return{canvas:c,frameWidth:a,framesLength:i,delay:h[0]||Ra,frameDelays:h,duration:h.reduce((d,f)=>d+f,0)/1e3}}finally{r.close()}};var zc=async(n,e={})=>{if(Xc(n))return gp(n,e);if(Yr(n))return dp(n,e);let t=new Uint8Array(n,0,Math.min(6,n.byteLength)),r=String.fromCharCode(...t);if(r==="GIF87a"||r==="GIF89a")return up(n,e);throw new Error("Unsupported animated image (expected GIF, animated WebP or APNG)")};var Pa=class{host;patternSources=new Map;gifSprites=new Map;animatedNodes=new Set;pendingImageNodes=new WeakSet;patternTextures=new Map;maskTextures=new Map;svgRasters=new WeakMap;svgMaxRasterPx;loadGeneration=0;constructor(e){this.host=e;let t=Number(e.gl.getParameter(e.gl.MAX_TEXTURE_SIZE))||4096;this.svgMaxRasterPx=Math.min(t,4096)}async loadGroupMasks(e){let t=new Set,r=s=>{let a=s.raw.mask;a&&a.disabled!==!0&&typeof a.src=="string"&&!this.maskTextures.has(a.src)&&t.add(a.src)},o=s=>{for(let a of s)a instanceof J?(r(a),o(a.children)):Co(a)&&r(a)};if(o(e),t.size===0)return;let i=this.host.gl;await Promise.all([...t].map(async s=>{try{let a=await Je(s,"anonymous"),l=Le(i,a);if(!l)return;this.maskTextures.set(s,l)}catch{console.warn("[engine] group mask skipped (load failed):",s)}}))}async loadAnimatedSources(e){let t=++this.loadGeneration,r=a=>this.host.document.nodes.some(l=>l===a||l instanceof J&&l.containsDeep(a)),o=a=>this.loadGeneration===t&&e.includes(a)&&r(a),i=e.filter(a=>a instanceof ae&&!!a.clipDynamicKind&&!a.hasDynamicClip);for(let a of i)(async()=>{let l=a.clipImageRaw;try{let c=a.clipDynamicKind==="gif"?await this.loadGifSprite(l.src):await this.loadVideoElement(l.src,l.crossOrigin,l.loop===!0);if(!o(a))return;a.clipDynamicKind==="gif"?a.attachClipSprite(c,()=>this.host.requestRenderAll()):a.attachClipVideo(c,()=>this.host.requestRenderAll()),this.dynamicClipMasks.add(a),this.host.requestRenderAll()}catch(c){if(console.warn("[engine] mask dynamic clip skipped (load failed):",c.message),!o(a))return;try{a.clipImageEl=await Je(l.src,l.crossOrigin)}catch{}this.host.requestRenderAll()}})();let s=e.filter(a=>a instanceof ie);s.length!==0&&(await Promise.all(s.map(async a=>{let l=a.raw.src;try{let c=a.animatedKind==="gif"?await this.loadGifSprite(l):await this.loadVideoElement(l,a.raw.crossOrigin,a.raw.loop===!0);if(!o(a))return;a.animatedKind==="gif"?a.attachSprite(c,()=>this.host.requestRenderAll()):a.attachVideo(c,()=>this.host.requestRenderAll()),this.animatedNodes.add(a),this.pendingImageNodes.delete(a),this.host.requestRenderAll()}catch(c){if(console.warn("[engine] animated source skipped (load failed):",c.message),!o(a))return;try{a.imageEl=await Je(l,a.raw.crossOrigin)}catch{}this.pendingImageNodes.delete(a),this.host.requestRenderAll()}})),this.host.document.refreshHitIndex())}loadGifSprite(e){if(this.disposed)return Promise.reject(new Error("SourceManager disposed"));let t=this.gifSprites.get(e);if(t)return t;let r=fetch(e).then(async o=>{if(!o.ok)throw new Error(`GIF load failed: ${o.status} ${o.statusText}`);let i=await o.arrayBuffer(),s=this.host.decodeAnimated;if(s)try{return await s(i)}catch(a){console.warn("[engine] injected animated decoder failed, falling back:",a.message)}return zc(i)}).catch(o=>{throw this.gifSprites.delete(e),o});return this.gifSprites.set(e,r),r}loadVideoElement(e,t,r,o=0){return new Promise((i,s)=>{let a=document.createElement("video");a.crossOrigin=t||"anonymous",a.muted=!0,a.playsInline=!0,a.setAttribute("playsinline","true"),a.setAttribute("webkit-playsinline","true"),a.loop=r,a.preload="auto",a.addEventListener("loadeddata",()=>i(a),{once:!0}),a.addEventListener("error",()=>{a.removeAttribute("src"),a.load(),o<2?setTimeout(()=>{this.loadVideoElement(e,t,r,o+1).then(i,s)},120):s(new Error(`[engine] video load failed: ${e.slice(0,80)}`))},{once:!0}),a.src=e})}releaseAnimatedSources(){this.loadGeneration++;for(let e of[...this.animatedNodes])this.releaseAnimatedNode(e);for(let e of this.dynamicClipMasks)e.detachDynamicClip();this.dynamicClipMasks.clear()}dynamicClipMasks=new Set;releaseAnimatedNode(e){if(!this.animatedNodes.has(e))return;this.animatedNodes.delete(e);let t=e.paintSource;e.detach(),t&&this.host.textures.remove(t)}async loadPatternSources(e){let t=new Set;for(let r of e){let o=r.fillPaint;o?.kind==="pattern"&&t.add(o.decl.src)}t.size!==0&&await Promise.all([...t].map(async r=>{if(!this.patternSources.has(r))try{this.patternSources.set(r,await Je(r,"anonymous"))}catch(o){console.warn("[engine] pattern source skipped (load failed):",o.message)}}))}patternTexture(e){let t=this.patternTextures.get(e);if(t)return t;let r=this.patternSources.get(e);if(!r||!r.naturalWidth)return null;let o=Le(this.host.gl,r,{mipmap:!0,repeat:!0});if(!o)return null;let i={tex:o,w:r.naturalWidth,h:r.naturalHeight};return this.patternTextures.set(e,i),i}maskTexture(e){return this.maskTextures.get(e)??null}markImagePending(e){this.pendingImageNodes.add(e)}isImagePending(e){return this.pendingImageNodes.has(e)}svgRasterSource(e,t,r){let o=e.imageEl;if(!o)return null;if(!Ji(e.raw.src))return o;let i=o.naturalWidth||o.width,s=o.naturalHeight||o.height;if(!(i>0)||!(s>0))return o;let a=e.worldScale,l=this.svgRasters.get(e);l&&(l.source!==o||l.sourceSrc!==o.src)&&(this.svgRasters.delete(e),this.host.textures.remove(l.canvas),l=void 0);let c=ud({w:i,h:s},{w:i*Math.abs(a.x)*t*r,h:s*Math.abs(a.y)*t*r},l?.factor??1,this.svgMaxRasterPx);if(!c.needsRaster)return l?.canvas??o;if(c.factor===1)return l&&(this.svgRasters.delete(e),this.host.textures.remove(l.canvas)),o;let u=hd(o,c.factor);return l&&this.host.textures.remove(l.canvas),this.svgRasters.set(e,{canvas:u,factor:c.factor,source:o,sourceSrc:o.src}),u}svgRasterFactorOf(e){return this.svgRasters.get(e)?.factor??null}async applyImageMask(e,t){let r=Hc(e.raw);if(!r)return!1;try{let o=await Je(rp(r.src),r.crossOrigin),i=e.dims;if(!(i.x>0)||!(i.y>0))return!1;let s=ap(t,i,r,o,e.raw.left??0,e.raw.top??0);if(!s)return!1;let a=await lp(s);return a?(e.imageEl=a,!0):!1}catch(o){return console.warn("[engine] image mask bake skipped (load failed):",o.message),!1}}async reloadNodeImage(e){let t=e.raw.src,r=e.imageEl,o=this.svgRasters.get(e);o&&(this.svgRasters.delete(e),this.host.textures.remove(o.canvas));try{let i=await Je(t,e.raw.crossOrigin);return e.imageEl=i,await this.applyImageMask(e,i),r&&this.host.textures.remove(r),this.host.document.refreshHitIndex(),this.host.requestRenderAll(),e.imageEl}catch(i){return console.warn("[engine] image reload skipped (load failed):",i.message),null}}async reloadMaskClipImage(e){let t=e.clipImageRaw;if(!t||e.clipDynamicKind)return null;let r=e.clipImageEl;try{let o=await Je(t.src,t.crossOrigin??null);return e.clipImageEl=o,r&&this.host.textures.remove(r),this.host.document.refreshHitIndex(),this.host.requestRenderAll(),o}catch(o){return console.warn("[engine] mask clipImage reload skipped (load failed):",o.message),null}}async loadImages(e){let t=s=>s instanceof ie?!1:s instanceof ae?!s.imageEl||!!s.clipImageRaw&&!s.clipDynamicKind&&!s.clipImageEl:s.isTextType?typeof s.raw.renderSrc=="string"&&!s.imageEl:s.isImageType&&!s.imageEl,r=e.filter(t);if(r.length===0)return;let o=new Map,i=!1;await Promise.all(r.map(async s=>{let a=s.isTextType&&typeof s.raw.renderSrc=="string",l=a?s.raw.renderSrc:s.raw.src,c=()=>{this.pendingImageNodes.delete(s),this.host.requestRenderAll()};try{if(s instanceof ae){if(!s.imageEl){let d=o.get(l);d||(d=await Je(l,s.raw.crossOrigin),o.set(l,d)),s.imageEl=d,i=!0}let h=s.clipImageRaw;if(h&&!s.clipDynamicKind&&!s.clipImageEl){let d=h.src,f=o.get(d);f||(f=await Je(d,h.crossOrigin),o.set(d,f)),s.clipImageEl=f}c();return}if(a){let h=o.get(l);h||(h=await Je(l,s.raw.crossOrigin),o.set(l,h)),s.imageEl=h,i=!0,c();return}let u=o.get(l);u||(u=await Je(l,s.raw.crossOrigin),o.set(l,u)),s.imageEl=u,await this.applyImageMask(s,u),i=!0,c()}catch(u){console.warn("[engine] image node skipped (load failed):",u.message),c()}})),i&&this.host.document.refreshHitIndex()}invalidateGlTextures(){for(let{tex:e}of this.patternTextures.values())this.host.gl.deleteTexture(e);this.patternTextures.clear()}dispose(){this.disposed=!0,this.loadGeneration++;for(let e of this.gifSprites.values())e.then(t=>cp(t.canvas),()=>{});this.gifSprites.clear();for(let{tex:e}of this.patternTextures.values())this.host.gl.deleteTexture(e);this.patternTextures.clear(),this.patternSources.clear()}disposed=!1};function Yc(n){let e=[],t=r=>{for(let o of r)e.push(o),o instanceof J&&t(o.children)};return t([...n]),e}async function Uc(n,e,t){for(let r of n)r instanceof ie?r.paintSource||e.markImagePending(r):r instanceof ae?(!r.imageEl||r.clipImageRaw&&!r.clipImageEl)&&e.markImagePending(r):r.isTextType&&typeof r.raw.renderSrc=="string"?r.imageEl||e.markImagePending(r):r.isImageType&&!r.imageEl&&e.markImagePending(r);t(),await e.loadImages(n),await e.loadGroupMasks(n),await e.loadAnimatedSources(n),await e.loadPatternSources(n),t()}var He=2,IS=4*He,_S=384,DS=(n,e,t,r,o,i)=>{let s=1/0,a=-1/0,l=1/0,c=-1/0,u=8;for(let h=0;h<=u;h++){let d=r+(o-r)*h/u;for(let f=0;f<=u;f++){let m=e+(t-e)*f/u,p=Ri(n,m,d),b=i[0]*p.x+i[2]*p.y+i[4],x=i[1]*p.x+i[3]*p.y+i[5];s=Math.min(s,b),a=Math.max(a,b),l=Math.min(l,x),c=Math.max(c,x)}}return{minX:s,maxX:a,minY:l,maxY:c}},$c=(n,e,t=null)=>{let r=n.textLayout,o=Number(n.raw.fontSize)||40,i=typeof n.raw.width=="number"?n.raw.width:r.width,s=typeof n.raw.height=="number"?n.raw.height:r.height;if(!(i>0)||!(s>0))return null;let a=o*.6,l=Math.max(r.width,i,o),c=Math.max(s,o),u=t?Sr(t):0,h=Math.ceil(l+a*2+u*2),d=Math.ceil(c+a*2+u*2),f=h*He,m=d*He;if(!(f>0)||!(m>0)||f>8192||m>8192)return null;let p=cl(e,i,s);if(!p)return null;let b=document.createElement("canvas");b.width=f,b.height=m;let x=b.getContext("2d",{willReadFrequently:!0});if(!x)return null;x.setTransform(He,0,0,He,f/2,m/2),n.raw.vertical===!0?Oi(x,n):uo(x,n),ho(x,n,t);let g=x.getImageData(0,0,f,m),y=new Uint32Array(g.data.buffer),v=f,S=0,w=m,R=0,P=!1;for(let ke=0;ke<m;ke++)for(let Ee=0;Ee<f;Ee++)(y[ke*f+Ee]>>>24&255)>10&&(P=!0,Ee<v&&(v=Ee),Ee>S&&(S=Ee),ke<w&&(w=ke),ke>R&&(R=ke));if(!P)return null;let E=v,C=w,T=S+1-v,M=R+1-w,k=(h-i)/2*He,A=(d-s)/2*He,O=[He,0,0,He,k,A],F=(E-k)/He,H=(E+T-k)/He,z=(C-A)/He,_=(C+M-A)/He,D=F/i,I=H/i,B=z/s,G=_/s,X=DS(p,D,I,B,G,O),U=Math.floor(X.minX)-1,q=Math.floor(X.minY)-1,j=Math.max(1,Math.ceil(X.maxX+1)-U),Z=Math.max(1,Math.ceil(X.maxY+1)-q);if(j>8192||Z>8192)return null;let W=ul(p,0,0,i,s,F,z,H,_,T,M,[He,0,0,He,k-U,A-q],IS,_S);if(!W)return null;let V=x.createImageData(j,Z),Y=new Uint32Array(V.data.buffer),re=new Uint8Array(j*Z),te=(ke,Ee)=>{let ue=Math.min(T-1,Math.max(0,ke)),ge=Math.min(M-1,Math.max(0,Ee)),pe=Math.floor(ue),Te=Math.floor(ge),rt=Math.min(T-1,pe+1),qe=Math.min(M-1,Te+1),Ye=ue-pe,bt=ge-Te,xt=y[(C+Te)*f+(E+pe)],gt=y[(C+Te)*f+(E+rt)],yt=y[(C+qe)*f+(E+rt)],St=y[(C+qe)*f+(E+pe)],_n=xt>>>24&255,Dn=gt>>>24&255,ti=yt>>>24&255,ni=St>>>24&255;if(_n<=10&&Dn<=10&&ti<=10&&ni<=10)return 0;let Ue=(vt,Fa,Oa)=>vt+(Fa-vt)*Oa,hr=Math.round(Ue(Ue(xt&255,gt&255,Ye),Ue(St&255,yt&255,Ye),bt)),Vr=Math.round(Ue(Ue(xt>>>8&255,gt>>>8&255,Ye),Ue(St>>>8&255,yt>>>8&255,Ye),bt)),ri=Math.round(Ue(Ue(xt>>>16&255,gt>>>16&255,Ye),Ue(St>>>16&255,yt>>>16&255,Ye),bt));return Math.round(Ue(Ue(_n,Dn,Ye),Ue(ni,ti,Ye),bt))<<24|ri<<16|Vr<<8|hr};for(let ke=0;ke+1<W.rows;ke++)for(let Ee=0;Ee+1<W.columns;Ee++){let ue=ke*W.columns+Ee,ge=ue+1,pe=ue+W.columns,Te=pe+1,rt=W.docXs[ue],qe=W.docYs[ue],Ye=W.docXs[ge],bt=W.docYs[ge],xt=W.docXs[Te],gt=W.docYs[Te],yt=W.docXs[pe],St=W.docYs[pe],_n=Math.max(0,Math.floor(Math.min(rt,Ye,xt,yt))),Dn=Math.min(j-1,Math.ceil(Math.max(rt,Ye,xt,yt))),ti=Math.max(0,Math.floor(Math.min(qe,bt,gt,St))),ni=Math.min(Z-1,Math.ceil(Math.max(qe,bt,gt,St)));for(let Ue=ti;Ue<=ni;Ue++)for(let hr=_n;hr<=Dn;hr++){let Vr=Ue*j+hr;if(re[Vr])continue;let ri=hl(hr+.5,Ue+.5,rt,qe,Ye,bt,xt,gt,yt,St);if(!ri)continue;re[Vr]=1;let{s:Gt,t:vt}=ri,Fa=(1-Gt)*(1-vt)*W.sourceXs[ue]+Gt*(1-vt)*W.sourceXs[ge]+Gt*vt*W.sourceXs[Te]+(1-Gt)*vt*W.sourceXs[pe],Oa=(1-Gt)*(1-vt)*W.sourceYs[ue]+Gt*(1-vt)*W.sourceYs[ge]+Gt*vt*W.sourceYs[Te]+(1-Gt)*vt*W.sourceYs[pe];Y[Vr]=te(Fa,Oa)}}let de=document.createElement("canvas");de.width=j,de.height=Z;let Pe=de.getContext("2d");if(!Pe)return null;Pe.putImageData(V,0,0);let De=(U+j/2)/He-h/2,nt=(q+Z/2)/He-d/2;return{canvas:de,logicalW:j/He,logicalH:Z/He,offsetX:De,offsetY:nt}};var Sp=new Map,Zo=(n,e)=>{let t=n.worldScale,r=vp(n);return e*Math.max(t.x*Math.abs(r.x),t.y*Math.abs(r.y),1e-6)},vp=n=>{let e=Number(n.raw.textScaleX)||1,t=Number(n.raw.textScaleY)||1;return{x:e,y:t}},lr=n=>{let{x:e,y:t}=vp(n);return e===1&&t===1?n.matrix:$(n.matrix,[e,0,0,t,0,0])},Ur=(n,e)=>{let t=Sp.get(n);if(!t){let r=oe(n);t=[r[0],r[1],r[2],r[3]],Sp.set(n,t)}return[t[0],t[1],t[2],t[3]*e[3]]},ka=class{gl;batch;glyphAtlas;warpBakes=new WeakMap;psdWarpBakes=new WeakMap;arcBakes=new WeakMap;textDashBakes=new WeakMap;scrollBakes=new WeakMap;highlightBakes=new WeakMap;pathBgBakes=new WeakMap;constructor(e,t,r){this.gl=e,this.batch=t,this.glyphAtlas=r}invalidateNodeBakes(e){for(let t of[this.warpBakes,this.psdWarpBakes,this.arcBakes,this.textDashBakes,this.scrollBakes,this.highlightBakes,this.pathBgBakes]){let r=t.get(e);r?.tex&&this.gl.deleteTexture(r.tex),t.delete(e)}}renderWarpedText(e,t){let r=Vt(e.raw.effects,{text:!0}),o=[e.raw.type,e.raw.textTransform,e.raw.text,e.raw.warpStrength,e.raw.fontSize,e.raw.fontFamily,e.raw.width,e.raw.height,e.raw.fill,e.raw.stroke,e.raw.strokeWidth,JSON.stringify(e.raw.styles??null),JSON.stringify(e.raw.paragraph??null),r?Sn(r):""].join(";"),i=this.warpBakes.get(e);if(i&&i.sig!==o&&(this.gl.deleteTexture(i.tex),i=void 0),!i){let s=gl(e,t,r);if(!s){this.warpBakes.set(e,void 0);return}let a=Le(this.gl,s.canvas);if(!a)return;i={sig:o,tex:a,w:s.logicalW,h:s.logicalH},this.warpBakes.set(e,i)}this.batch.pushQuad(e.matrix,i.w,i.h,[1,1,1,e.renderOpacity],i.tex)}renderPsdWarpedText(e,t){let r=Vt(e.raw.effects,{text:!0}),o=[e.raw.type,e.raw.text,JSON.stringify(e.raw.psdWarp??null),e.raw.fontSize,e.raw.fontFamily,e.raw.fontWeight,e.raw.fontStyle,e.raw.width,e.raw.height,e.raw.lineHeight,e.raw.charSpacing,e.raw.vertical===!0?1:0,e.raw.fill,e.raw.stroke,e.raw.strokeWidth,JSON.stringify(e.raw.styles??null),JSON.stringify(e.raw.paragraph??null),r?Sn(r):""].join(";"),i=this.psdWarpBakes.get(e);if(i&&i.sig!==o&&(this.gl.deleteTexture(i.tex),i=void 0),!i){let a=$c(e,t,r);if(!a){this.psdWarpBakes.set(e,void 0);return}let l=Le(this.gl,a.canvas);if(!l)return;i={sig:o,tex:l,w:a.logicalW,h:a.logicalH,offX:a.offsetX,offY:a.offsetY},this.psdWarpBakes.set(e,i)}let s=i.offX!==0||i.offY!==0?$(e.matrix,kt({translateX:i.offX,translateY:i.offY})):e.matrix;this.batch.pushQuad(s,i.w,i.h,[1,1,1,e.renderOpacity],i.tex)}renderArcText(e,t,r){let o=Vt(e.raw.effects,{text:!0}),i=!!o&&(o.dropShadows.length>0||o.solidFills.length>0||o.strokes.length>0);if(wu()&&!i){this.renderArcGlyphs(e,t,r);return}let s=Ot(Zo(e,r)),a=[e.raw.type,e.raw.textTransform,e.raw.text,e.raw.curvature,e.raw.circleSize,e.raw.circleStartAngle,e.raw.circleSweep,e.raw.circleEccentricity,e.raw.circleDirection,e.raw.fontSize,e.raw.fontFamily,e.raw.fontWeight,e.raw.fontStyle,e.raw.lineHeight,e.raw.textAlign,e.raw.fill,e.raw.stroke,e.raw.strokeWidth,e.raw.strokeVisible,e.raw.paintFirst,JSON.stringify(e.raw.styles??null),o?Sn(o):"",s].join(";"),l=this.arcBakes.get(e);if(l&&l.sig!==a&&(this.gl.deleteTexture(l.tex),l=void 0),!l){let c=yl(e,t,o,s);if(!c){this.arcBakes.set(e,void 0);return}let u=Le(this.gl,c.canvas);if(!u)return;l={sig:a,tex:u,w:c.logicalW,h:c.logicalH},this.arcBakes.set(e,l)}this.batch.pushQuad(e.matrix,l.w,l.h,[1,1,1,e.renderOpacity],l.tex)}renderArcGlyphs(e,t,r){let o=Et(e.textLayout,e.raw,e.textStyle.lineHeight??1.16),i=Ot(Zo(e,r)),s=e.textStyle,a=e.textStroke,l=e.raw.strokeVisible===!0,c=e.paintFirst==="stroke",u=typeof e.raw.fill=="string"?e.raw.fill:"",h=e.matrix,d=[1,1,1,e.renderOpacity];for(let f of o.chars){let m=e.textLayout.lines[f.line]?.charStyles[f.index],p=pn(s,m),b=typeof m?.fill=="string"&&m.fill?m.fill:u,x=l?Oe(a,m):null,g=f.x-o.contentOffsetX,y=f.y-o.contentOffsetY,v=Math.cos(f.rotation),S=Math.sin(f.rotation),w=R=>{if(R){if(!x||x.width<=0)return}else if(!b)return;let{rs:P,scale:E}=Js(p.fontSize,i),C=this.glyphAtlas.get(p,P,f.char,R?x:null);if(!C)return;let T=C.wPx/E,M=C.hPx/E,k=(C.inkLeftPx-C.advancePx/2-C.padPx)/E+T/2,A=-(C.ascentPx+C.padPx)/E+M/2,O=Ur(R?x.color:b,d),F=$(h,$([1,0,0,1,g,y],$([v,S,-S,v,0,0],[1,0,0,1,k,A])));this.batch.pushQuad(F,T,M,O,this.glyphAtlas.textureOf(C),[C.u0,C.v0,C.u1,C.v1])};c?(w(!0),w(!1)):(w(!1),w(!0))}}renderTextGlyphs(e,t){if(vr(e.raw)?.enabled){this.renderScrollText(e,t);return}let o=e.textLayout,i=e.textStroke,s=!!e.raw.fill||o.lines.some(l=>l.charStyles.some(c=>c?.fill)),a=Ot(Zo(e,t));this.renderTextBackgrounds(e),this.renderTextDecorations(e,"underline"),this.renderTextHighlight(e,a),i&&e.paintFirst==="stroke"?(this.renderGlyphPass(e,"stroke",a),s&&this.renderGlyphPass(e,"fill",a)):(s&&this.renderGlyphPass(e,"fill",a),i&&this.renderGlyphPass(e,"stroke",a)),this.renderTextDecorations(e,"overline"),this.renderTextDecorations(e,"linethrough")}renderScrollText(e,t){this.renderTextBackgrounds(e),this.renderTextDecorations(e,"underline");let r=Ot(Zo(e,t)),o=e.raw,i=[o.text,o.width,o.height,o.fontSize,o.fontFamily,o.fontWeight,o.fontStyle,o.lineHeight,o.charSpacing,o.textAlign,o.splitByGrapheme,o.vertical,typeof o.fill=="string"?o.fill:"gradient",o.stroke,o.strokeWidth,Array.isArray(o.strokeDashArray)?o.strokeDashArray.join(","):"",o.strokeDashOffset,o.paintFirst,JSON.stringify(o.styles??null),o.scrollDirection,JSON.stringify(o.paragraph??null),e.scrollOffset.toFixed(3),e.textTotalWidth.toFixed(3),r].join(";"),s=this.scrollBakes.get(e);if(s&&s.sig!==i&&(this.gl.deleteTexture(s.tex),s=void 0),!s){let a=Nh(e,r,e.scrollOffset);if(!a){this.scrollBakes.set(e,void 0);return}let l=Le(this.gl,a.canvas);if(!l)return;s={sig:i,tex:l,w:a.logicalW,h:a.logicalH},this.scrollBakes.set(e,s)}this.batch.pushQuad(lr(e),s.w,s.h,[1,1,1,e.renderOpacity],s.tex),this.renderTextDecorations(e,"overline"),this.renderTextDecorations(e,"linethrough")}renderTextPathBackground(e,t){let r=ki(e);if(!r)return;let o=Ot(Zo(e,t)),i=`${r.sigBase};${o}`,s=this.pathBgBakes.get(e);if(s&&s.sig!==i&&(this.gl.deleteTexture(s.tex),s=void 0),!s){let a=mh(r,o);if(!a){this.pathBgBakes.set(e,void 0);return}let l=Le(this.gl,a.canvas);if(!l)return;s={sig:i,tex:l,w:a.logicalW,h:a.logicalH},this.pathBgBakes.set(e,s)}this.batch.pushQuad(e.matrix,s.w,s.h,[1,1,1,e.renderOpacity],s.tex)}renderTextBackgrounds(e){let t=e.textLayout,r=e.renderOpacity,o=lr(e),i=typeof e.raw.textBackgroundColor=="string"?e.raw.textBackgroundColor:"";if(!(!i&&!t.lines.some(s=>s.charStyles.some(a=>a?.textBackgroundColor))))for(let s of t.lines){let a=-t.width/2+s.leftOffset,l=e.contentTopY+s.top,c=m=>s.charStyles[m]?.textBackgroundColor??i,u=0,h=0,d=c(0),f=()=>{if(!d||h<=0)return;let m=a+s.boxes[u].left,p=oe(d),b=[p[0],p[1],p[2],p[3]*r],x=$(o,[1,0,0,1,m+h/2,l+s.implHeight/2]);this.batch.pushQuad(x,h,s.implHeight,b,null)};for(let m=0;m<s.graphemes.length;m++){let p=c(m);p!==d?(f(),u=m,h=s.boxes[m].width,d=p):h+=s.boxes[m].kernedWidth}f()}}renderTextDecorations(e,t){let r=e.textLayout,o=e.decorationDefaults,i=[1,1,1,e.renderOpacity],s=lr(e);for(let a of r.lines){let l=sl(a,t,o);if(l.length===0)continue;let c=-r.width/2+a.leftOffset,u=e.contentTopY+a.baseline;for(let h of l){let d=c+h.x+h.width/2,f=u+h.y+h.thickness/2;this.batch.pushQuad($(s,[1,0,0,1,d,f]),h.width,h.thickness,Ur(h.color,i),null)}}}textHasDashStroke(e){return Array.isArray(e.raw.strokeDashArray)&&e.raw.strokeDashArray.length>0}renderTextDashStroke(e,t){let r=e.textLayout,o=e.textStyle,i=e.raw.strokeDashArray,s=e.textStroke,a=s?s.width:0;if(!s||a<=0)return;let l=Number(e.raw.charSpacing)||0,c=zt(e.raw.textAlign),u=e.raw.textAlign===fe.DISPERSE,h=Number(e.raw.textOffsetY)||0,d=Ju(h,e.textStyle,r.lines),f=a+4+Math.ceil(d),m=Math.ceil(r.width+f*2),p=Math.ceil(r.height+f*2);if(!(m>0)||!(p>0)||m>8192||p>8192)return;let b=[e.raw.text,r.width,r.height,s.color,s.width,i.join(","),Number(e.raw.strokeDashOffset)||0,t,l,c,e.raw.textAlign,e.raw.vertical===!0,h,JSON.stringify(e.raw.paragraph??null)].join(";"),x=this.textDashBakes.get(e);if(x&&x.sig!==b&&(this.gl.deleteTexture(x.tex),x=void 0),!x){let g=document.createElement("canvas");g.width=Math.ceil(m*t),g.height=Math.ceil(p*t);let y=g.getContext("2d");if(!y)return;y.setTransform(t,0,0,t,0,0),y.textBaseline="alphabetic",y.setLineDash(i),y.lineDashOffset=Number(e.raw.strokeDashOffset)||0,y.lineJoin=typeof e.raw.strokeLineJoin=="string"?e.raw.strokeLineJoin:"miter",y.lineCap=typeof e.raw.strokeLineCap=="string"?e.raw.strokeLineCap:"butt",y.miterLimit=Number(e.raw.strokeMiterLimit)||4;let v=r.width/2+f,S=r.height/2+f+e.contentTopY,w=e.raw.vertical===!0,R=0;for(let E of r.lines){let C=-r.width/2+E.leftOffset,T=S+E.baseline;if(w){E.prefix&&Tt(y,E,v+C,T,{stroke:Oe(s,E.charStyles[0])});let D=Yt(E,C,T,o,l);for(let I=0;I<D.length;I++){let B=Oe(s,E.charStyles[I]);if(!B||B.width<=0)continue;let G=un(o,E.charStyles[I]);y.font=Me(G,G.fontSize),y.lineWidth=B.width,y.strokeStyle=B.color,Ut(y,{...D[I],y:D[I].y+wt(h,G.fontSize,R+I)},"strokeText")}R+=E.graphemes.length;continue}let M=eo(e.raw.textAlign)&&E.graphemes.some(D=>oo.test(D)),k="",A=E.prefix?Tt(y,E,v+C,T,{stroke:Oe(s,E.charStyles[0])}):0,O=0,F="",H=null,z,_=D=>{if(!k)return;let I=H;I&&I.width>0&&(y.font=F,y.lineWidth=I.width,y.strokeStyle=I.color,y.strokeText(k,v+C+A,T+O)),k="",D<E.boxes.length&&(A=E.boxes[D].left)};for(let D=0;D<E.graphemes.length;D++){let I=E.charStyles[D],G=I!==void 0&&(I.fontSize!==void 0||I.fontFamily!==void 0||I.fontWeight!==void 0||I.fontStyle!==void 0)&&I?{...o,fontSize:I.fontSize??o.fontSize,fontFamily:I.fontFamily??o.fontFamily,fontWeight:I.fontWeight??o.fontWeight,fontStyle:I.fontStyle??o.fontStyle}:o,X=Me(G,G.fontSize),U=Oe(s,I),q=I?.fill??"",j=H;k&&(X!==F||U?.color!==j?.color||U?.width!==j?.width||q!==z)&&_(D),k||(F=X,H=U,z=q,O=wt(h,G.fontSize,R+D)),k+=E.graphemes[D],(l||h!==0||(c||u)&&/[ \t\r]/.test(E.graphemes[D])||M)&&_(D+1)}_(E.graphemes.length),R+=E.graphemes.length}let P=Le(this.gl,g);if(!P)return;x={sig:b,tex:P,w:m,h:p},this.textDashBakes.set(e,x)}this.batch.pushQuad(lr(e),x.w,x.h,[1,1,1,e.renderOpacity],x.tex)}renderTextHighlight(e,t){let r=e.raw;if(!Array.isArray(r.texts)||r.texts.length===0||r.vertical===!0)return;let o=e.textLayout,i=[r.text,o.width,o.height,r.fontSize,r.fontFamily,r.fontWeight,r.fontStyle,r.lineHeight,r.charSpacing,r.textAlign,r.splitByGrapheme,JSON.stringify(r.styles??null),e.dims.y,JSON.stringify(r.texts??null),JSON.stringify(r.paragraph??null),t].join(";"),s=this.highlightBakes.get(e);if(s&&s.sig!==i&&(this.gl.deleteTexture(s.tex),s=void 0),!s){let a=Kn(r.text??"",o,r.texts,e.contentTopY,e.textStyle.fontSize);if(!a){this.highlightBakes.set(e,void 0);return}let l=fh(a,o,e.contentTopY,t);if(!l)return;let c=Le(this.gl,l.canvas);if(!c)return;s={sig:i,tex:c,w:l.logicalW,h:l.logicalH,centerY:e.contentTopY-a.padY+l.logicalH/2},this.highlightBakes.set(e,s)}this.batch.pushQuad($(lr(e),[1,0,0,1,0,s.centerY]),s.w,s.h,[1,1,1,e.renderOpacity],s.tex)}renderGlyphPass(e,t,r){if(t==="stroke"&&this.textHasDashStroke(e)){this.renderTextDashStroke(e,r);return}let o=e.textLayout,i=e.textStyle,s=lr(e),a=e.renderOpacity,l=e.fillPaint,c=l?.kind==="gradient"?[l.decl.stops[0].color[0],l.decl.stops[0].color[1],l.decl.stops[0].color[2],l.decl.stops[0].color[3]*a]:e.drawColor,u=!!e.raw.fill,h=e.textStroke,d=[1,1,1,a],f=e.raw.vertical===!0,m=f&&i.charSpacing?i.fontSize*i.charSpacing/1e3:0,p=Number(e.raw.textOffsetY)||0,b=0;for(let x of o.lines){let g=-o.width/2+x.leftOffset,y=e.contentTopY+x.baseline;if(x.prefix)if(t==="stroke"){let S=Oe(h,x.charStyles[0]);S&&S.width>0&&this.pushPrefixGlyphs(e,x.prefix,g,y,S,Ur(S.color,d),r)}else{let S=x.charStyles[0]?.fill;(S||u)&&this.pushPrefixGlyphs(e,x.prefix,g,y,null,S?Ur(S,c):c,r)}let v=0;for(let S=0;S<x.graphemes.length;S++){let w=x.charStyles[S],R,P=null;if(t==="stroke"){if(P=Oe(h,w),!P)continue;R=Ur(P.color,d)}else{let _=w?.fill;if(!_&&!u)continue;R=_?Ur(_,c):c}let C=w!==void 0&&(w.fontSize!==void 0||w.fontFamily!==void 0||w.fontWeight!==void 0||w.fontStyle!==void 0)&&w?{...i,fontSize:w.fontSize??i.fontSize,fontFamily:w.fontFamily??i.fontFamily,fontWeight:w.fontWeight??i.fontWeight,fontStyle:w.fontStyle??i.fontStyle}:i,T=wt(p,C.fontSize,b+S),{rs:M,scale:k}=Js(C.fontSize,r),A=this.glyphAtlas.get(C,M,x.graphemes[S],P);if(!A)continue;let O=x.boxes[S],F=A.wPx/k,H=A.hPx/k,z;if(f){let _=x.graphemes[S],D=Un(_),I=C.fontSize,B=$n(_,O,m);if(D==="latin"||D==="bracket"){let X=g+v+(D==="latin"?O.kernedWidth-O.width:0)+(A.inkLeftPx-A.padPx)/k,U=y+T-(A.ascentPx+A.padPx)/k;z=$(s,[1,0,0,1,X+F/2,U+H/2])}else{let G=g+v+an(I),X=y+T+br(D,O,I),U=(A.inkLeftPx-A.padPx)/k+F/2,q=H/2-(A.ascentPx+A.padPx)/k;z=$(s,$([1,0,0,1,G,X],$([0,-1,1,0,0,0],[1,0,0,1,U,q])))}v+=B}else{let D=g+O.left+(A.inkLeftPx-A.padPx)/k,I=y+T-(A.ascentPx+A.padPx)/k;z=$(s,[1,0,0,1,D+F/2,I+H/2])}this.batch.pushQuad(z,F,H,R,this.glyphAtlas.textureOf(A),[A.u0,A.v0,A.u1,A.v1])}b+=x.graphemes.length}}pushPrefixGlyphs(e,t,r,o,i,s,a){let l=At(t.text),c=r;for(let u=0;u<l.length;u++){let{rs:h,scale:d}=Js(t.style.fontSize,a),f=this.glyphAtlas.get(t.style,h,l[u],i);if(f){let m=f.wPx/d,p=f.hPx/d,b=c+(f.inkLeftPx-f.padPx)/d,x=o-(f.ascentPx+f.padPx)/d;this.batch.pushQuad($(lr(e),[1,0,0,1,b+m/2,x+p/2]),m,p,s,this.glyphAtlas.textureOf(f),[f.u0,f.v0,f.u1,f.v1])}c+=t.advances[u]??0}}};var wp=(n,e,t)=>{let r=n.createRenderbuffer();if(!r)throw new Error("Unable to allocate export stencil");return n.bindRenderbuffer(n.RENDERBUFFER,r),n.renderbufferStorage(n.RENDERBUFFER,n.DEPTH24_STENCIL8,e,t),n.framebufferRenderbuffer(n.FRAMEBUFFER,n.DEPTH_STENCIL_ATTACHMENT,n.RENDERBUFFER,r),r},Tp=n=>{let e=n.getParameter(n.RENDERBUFFER_BINDING),t=n.isEnabled(n.STENCIL_TEST),r=n.getParameter(n.STENCIL_CLEAR_VALUE),o=n.getParameter(n.COLOR_WRITEMASK),i=n.isEnabled(n.SCISSOR_TEST),s=[n.STENCIL_FUNC,n.STENCIL_REF,n.STENCIL_VALUE_MASK,n.STENCIL_WRITEMASK,n.STENCIL_FAIL,n.STENCIL_PASS_DEPTH_FAIL,n.STENCIL_PASS_DEPTH_PASS].map(l=>n.getParameter(l)),a=[n.STENCIL_BACK_FUNC,n.STENCIL_BACK_REF,n.STENCIL_BACK_VALUE_MASK,n.STENCIL_BACK_WRITEMASK,n.STENCIL_BACK_FAIL,n.STENCIL_BACK_PASS_DEPTH_FAIL,n.STENCIL_BACK_PASS_DEPTH_PASS].map(l=>n.getParameter(l));return()=>{n.bindRenderbuffer(n.RENDERBUFFER,e),n.clearStencil(r),n.colorMask(o[0],o[1],o[2],o[3]);for(let[l,c]of[[n.FRONT,s],[n.BACK,a]])n.stencilFuncSeparate(l,c[0],c[1],c[2]),n.stencilMaskSeparate(l,c[3]),n.stencilOpSeparate(l,c[4],c[5],c[6]);t?n.enable(n.STENCIL_TEST):n.disable(n.STENCIL_TEST),i?n.enable(n.SCISSOR_TEST):n.disable(n.SCISSOR_TEST)}},Ep=n=>{n.disable(n.SCISSOR_TEST),n.disable(n.STENCIL_TEST),n.colorMask(!0,!0,!0,!0),n.stencilMask(255),n.clearStencil(0),n.clear(n.COLOR_BUFFER_BIT|n.STENCIL_BUFFER_BIT)};var Cp=(n,e)=>{let t=n.multiplier&&n.multiplier>0?n.multiplier:1,r=n.width,o=n.height;if(!(r>0)||!(o>0)||!(e>0))return null;let i=Math.max(1,Math.round(r*t)),s=Math.max(1,Math.round(o*t)),a=Math.max(i,s);if(a>e){let c=e/a;i=Math.max(1,Math.floor(i*c)),s=Math.max(1,Math.floor(s*c))}let l=Math.min(i/r,s/o);return{outWidth:i,outHeight:s,multiplier:l}},jc=(n,e)=>{let t=e.outWidth/n.width,r=e.outHeight/n.height;return[t,0,0,r,-n.left*t,-n.top*r]},Mp=(n,e)=>qr(jc(n,e),e.outWidth,e.outHeight,1),Aa=(n,e,t)=>{let r=new Uint8ClampedArray(e*t*4);for(let o=0;o<t;o++){let i=(t-1-o)*e*4,s=o*e*4;for(let a=0;a<e*4;a+=4){let l=n[i+a+3];if(l===0){r[s+a]=0,r[s+a+1]=0,r[s+a+2]=0,r[s+a+3]=0;continue}let c=u=>Math.min(255,Math.round(u*255/l));r[s+a]=c(n[i+a]),r[s+a+1]=c(n[i+a+1]),r[s+a+2]=c(n[i+a+2]),r[s+a+3]=l}}return r};var Rp=n=>typeof n.fenceSync=="function"&&typeof n.clientWaitSync=="function"&&typeof n.getBufferSubData=="function",Pp=(n,e)=>new Promise(t=>{let r=performance.now(),o=!0,i=()=>{let s;try{s=n.clientWaitSync(e,o?n.SYNC_FLUSH_COMMANDS_BIT:0,0)}catch{return t()}if(o=!1,s===n.ALREADY_SIGNALED||s===n.CONDITION_SATISFIED||s===n.WAIT_FAILED||performance.now()-r>1e3)return t();setTimeout(i,4)};i()}),Na=class{constructor(e){this.host=e}host;exportToPixels(e){let t=this.renderAndStage(e,!1);return t?{width:t.outWidth,height:t.outHeight,data:Aa(t.raw,t.outWidth,t.outHeight)}:null}async exportToPixelsAsync(e){let t=await this.stageAndDrain(e);return t?{width:t.outWidth,height:t.outHeight,data:Aa(t.raw,t.outWidth,t.outHeight)}:null}async exportRawPixelsAsync(e){let t=await this.stageAndDrain(e);return t?{width:t.outWidth,height:t.outHeight,raw:t.raw}:null}async stageAndDrain(e){let t=this.renderAndStage(e,!0);if(!t)return null;if(!t.stagedReadback)return{outWidth:t.outWidth,outHeight:t.outHeight,raw:t.raw};let r=await this.drainStagedReadback(t.stagedReadback);return r?{outWidth:t.outWidth,outHeight:t.outHeight,raw:r}:null}renderRounds(e,t,r){let o=this.host.gl,i=0;do{this.host.renderer.beginFrame(performance.now()),o.bindFramebuffer(o.FRAMEBUFFER,e),o.clearColor(t[0],t[1],t[2],t[3]),Ep(o),this.host.batch.begin(r,this.host.zoom*this.host.dpr),this.host.meshBatch.begin(r);for(let s of this.host.sceneNodes)o.bindFramebuffer(o.FRAMEBUFFER,e),this.host.renderer.renderSceneNode(s);o.bindFramebuffer(o.FRAMEBUFFER,e),this.host.batchOrder.flushAll()}while(this.host.renderer.frame.bakeMore&&++i<64)}renderAndStage(e,t){if(!this.host.exportReady)return null;let r=Cp(e,this.host.capabilities.maxTextureSize);if(!r)return null;let o=this.host.gl,{outWidth:i,outHeight:s}=r,a=e.background??[0,0,0,0],l=i*s*4,c=this.host.bakeKReuseFloor;this.host.bakeKReuseFloor=e.bakeScaleTolerance??0;let u={framebuffer:o.getParameter(o.FRAMEBUFFER_BINDING),viewport:o.getParameter(o.VIEWPORT),clearColor:o.getParameter(o.COLOR_CLEAR_VALUE),program:o.getParameter(o.CURRENT_PROGRAM),activeTexture:o.getParameter(o.ACTIVE_TEXTURE),textureBinding:o.getParameter(o.TEXTURE_BINDING_2D),packBuffer:o.getParameter(o.PIXEL_PACK_BUFFER_BINDING),blendEnabled:o.isEnabled(o.BLEND),blendSrcRgb:o.getParameter(o.BLEND_SRC_RGB),blendDstRgb:o.getParameter(o.BLEND_DST_RGB),blendSrcAlpha:o.getParameter(o.BLEND_SRC_ALPHA),blendDstAlpha:o.getParameter(o.BLEND_DST_ALPHA)},h=Tp(o),d=null,f=o.createTexture(),m=o.createFramebuffer(),p=null,b=new Uint8Array(0),x=null,g=!1;try{if(o.bindTexture(o.TEXTURE_2D,f),o.texImage2D(o.TEXTURE_2D,0,o.RGBA,i,s,0,o.RGBA,o.UNSIGNED_BYTE,null),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,o.LINEAR),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MAG_FILTER,o.LINEAR),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_S,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_T,o.CLAMP_TO_EDGE),o.bindFramebuffer(o.FRAMEBUFFER,m),o.framebufferTexture2D(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.TEXTURE_2D,f,0),d=wp(o,i,s),o.checkFramebufferStatus(o.FRAMEBUFFER)!==o.FRAMEBUFFER_COMPLETE)return null;p=this.host.applyExportViewport(jc(e,r),i,s);let y=Mp(e,r);if(o.viewport(0,0,i,s),this.renderRounds(m,a,y),o.bindFramebuffer(o.FRAMEBUFFER,m),t&&Rp(o)){let v=o.createBuffer();o.bindBuffer(o.PIXEL_PACK_BUFFER,v),o.bufferData(o.PIXEL_PACK_BUFFER,l,o.STREAM_READ),o.readPixels(0,0,i,s,o.RGBA,o.UNSIGNED_BYTE,0);let S=o.fenceSync(o.SYNC_GPU_COMMANDS_COMPLETE,0);o.flush(),o.bindBuffer(o.PIXEL_PACK_BUFFER,u.packBuffer),x={gl:o,pbo:v,fence:S,byteLength:l},g=!0}else b=new Uint8Array(l),o.readPixels(0,0,i,s,o.RGBA,o.UNSIGNED_BYTE,b)}finally{o.bindFramebuffer(o.FRAMEBUFFER,u.framebuffer),o.viewport(u.viewport[0],u.viewport[1],u.viewport[2],u.viewport[3]),o.clearColor(u.clearColor[0],u.clearColor[1],u.clearColor[2],u.clearColor[3]),o.useProgram(u.program),o.activeTexture(u.activeTexture),o.bindTexture(o.TEXTURE_2D,u.textureBinding&&o.isTexture(u.textureBinding)?u.textureBinding:null),o.bindBuffer(o.PIXEL_PACK_BUFFER,u.packBuffer),u.blendEnabled?o.enable(o.BLEND):o.disable(o.BLEND),o.blendFuncSeparate(u.blendSrcRgb,u.blendDstRgb,u.blendSrcAlpha,u.blendDstAlpha),h(),p?.(),d&&o.deleteRenderbuffer(d),m&&o.deleteFramebuffer(m),f&&o.deleteTexture(f),x&&!g&&(o.deleteBuffer(x.pbo),x.fence&&o.deleteSync(x.fence)),this.host.bakeKReuseFloor=c,this.host.requestRenderAll()}return x?{outWidth:i,outHeight:s,raw:b,stagedReadback:x}:b.length?{outWidth:i,outHeight:s,raw:b,stagedReadback:null}:null}async drainGpuBacklog(){let e=this.host.gl;if(!Rp(e))return;let t=null;try{if(t=e.fenceSync(e.SYNC_GPU_COMMANDS_COMPLETE,0),!t)return;await Pp(e,t)}catch{}finally{t&&e.deleteSync(t)}}async drainStagedReadback(e){let{gl:t,pbo:r,fence:o,byteLength:i}=e;try{if(o&&await Pp(t,o),!this.host.exportReady)return null;let s=new Uint8Array(i),a=t.getParameter(t.PIXEL_PACK_BUFFER_BINDING);return t.bindBuffer(t.PIXEL_PACK_BUFFER,r),t.getBufferSubData(t.PIXEL_PACK_BUFFER,0,s),t.bindBuffer(t.PIXEL_PACK_BUFFER,a),s}catch{return null}finally{t.deleteBuffer(r),o&&t.deleteSync(o)}}exportToCanvas(e){let t=this.exportToPixels(e);if(!t)return null;let r=document.createElement("canvas");r.width=t.width,r.height=t.height;let o=r.getContext("2d");if(!o)return null;let i=o.createImageData(t.width,t.height);return i.data.set(t.data),o.putImageData(i,0,0),r}exportToDataURL(e,t="image/png",r){let o=this.exportToCanvas(e);return o?o.toDataURL(t,r):null}};var Vc=[.8705882352941177,.8627450980392157,.8627450980392157],FS=8,OS=`#version 300 es
|
|
1037
|
+
}`,setup:(e,t)=>{e.uniformMatrix4fv(t.uColorMatrix,!1,new Float32Array([n[0],n[1],n[2],n[3],n[5],n[6],n[7],n[8],n[10],n[11],n[12],n[13],n[15],n[16],n[17],n[18]])),e.uniform4f(t.uConstants,n[4],n[9],n[14],n[19])}}}var Ea=class{gl;programs=new Map;cache=new WeakMap;quadBuffer=null;vertexShader=null;disposed=!1;constructor(e){this.gl=e}getFilteredTexture(e,t,r,o,i){if(this.disposed||r<=0||o<=0)return null;let s=`${r}x${o}|${_i(i)}`,a=this.cache.get(e);return a&&a.sig===s&&a.source===t?a.outTex:(a&&(this.gl.deleteTexture(a.sourceTex),this.gl.deleteTexture(a.outTex)),this.runChain(e,t,r,o,i,s))}runChain(e,t,r,o,i,s){let a=this.gl,l=sp(i,r,o);if(!l.length)return null;let u=a.getParameter(a.VIEWPORT),c=a.isEnabled(a.BLEND),h=a.getParameter(a.CURRENT_PROGRAM),d=a.getParameter(a.FRAMEBUFFER_BINDING),f=a.getParameter(a.ARRAY_BUFFER_BINDING),m=a.getParameter(a.TEXTURE_BINDING_2D),p=a.getParameter(a.VERTEX_ARRAY_BINDING);a.bindVertexArray(null),a.disable(a.BLEND),a.viewport(0,0,r,o);let b=a.createTexture();if(!b)return null;a.bindTexture(a.TEXTURE_2D,b),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,a.NEAREST),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.NEAREST),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE),a.texImage2D(a.TEXTURE_2D,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,t);let x=()=>{let M=a.createTexture();return M?(a.bindTexture(a.TEXTURE_2D,M),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,a.NEAREST),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.NEAREST),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE),a.texImage2D(a.TEXTURE_2D,0,a.RGBA,r,o,0,a.RGBA,a.UNSIGNED_BYTE,null),M):null},g=x(),y=x(),v=a.createFramebuffer(),S=a.createFramebuffer();if(!g||!y||!v||!S)return null;let w=this.ensureQuad(),R=b,P=g,T=v;for(let M of l){let k=this.ensureProgram(M.source);if(!k)break;a.useProgram(k.program),a.bindFramebuffer(a.FRAMEBUFFER,T),a.framebufferTexture2D(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,P,0),a.activeTexture(a.TEXTURE0),a.bindTexture(a.TEXTURE_2D,R),a.uniform1i(k.uniforms.uTexture,0),k.uniforms.uStepW&&a.uniform1f(k.uniforms.uStepW,1/r),k.uniforms.uStepH&&a.uniform1f(k.uniforms.uStepH,1/o),M.setup(a,k.uniforms),a.bindBuffer(a.ARRAY_BUFFER,w),a.enableVertexAttribArray(k.aPosition),a.vertexAttribPointer(k.aPosition,2,a.FLOAT,!1,0,0),a.drawArrays(a.TRIANGLE_STRIP,0,4),R=P,T===v?(P=y,T=S):(P=g,T=v)}let C=R;a.bindVertexArray(p),a.bindFramebuffer(a.FRAMEBUFFER,d),a.viewport(u[0],u[1],u[2],u[3]),c&&a.enable(a.BLEND),a.useProgram(h),a.bindBuffer(a.ARRAY_BUFFER,f),a.activeTexture(a.TEXTURE0),a.bindTexture(a.TEXTURE_2D,m),a.deleteFramebuffer(v),a.deleteFramebuffer(S);let E=C===g?y:g;return a.deleteTexture(E),a.bindTexture(a.TEXTURE_2D,C),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.LINEAR_MIPMAP_LINEAR),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE),a.generateMipmap(a.TEXTURE_2D),a.bindTexture(a.TEXTURE_2D,m),this.cache.set(e,{sig:s,source:t,sourceTex:b,outTex:C}),C}ensureQuad(){let e=this.gl;return this.quadBuffer||(this.quadBuffer=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.quadBuffer),e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,1]),e.STATIC_DRAW)),this.quadBuffer}ensureProgram(e){let t=this.programs.get(e);if(t)return t;let r=this.gl;if(!this.vertexShader){let h=r.createShader(r.VERTEX_SHADER);if(!h)return null;r.shaderSource(h,ip),r.compileShader(h),this.vertexShader=h}let o=this.vertexShader,i=r.createShader(r.FRAGMENT_SHADER),s=r.createProgram();if(!i||!s)return null;if(r.shaderSource(i,e),r.compileShader(i),r.attachShader(s,o),r.attachShader(s,i),r.linkProgram(s),r.deleteShader(i),!r.getProgramParameter(s,r.LINK_STATUS))return console.warn("[gpuImageFilters] program link failed:",r.getProgramInfoLog(s)),r.deleteProgram(s),null;let l={},u=r.getProgramParameter(s,r.ACTIVE_UNIFORMS);for(let h=0;h<u;h++){let d=r.getActiveUniform(s,h);if(!d)continue;let f=d.name.replace(/\[0\]$/,"");l[f]=r.getUniformLocation(s,d.name)}let c={program:s,aPosition:r.getAttribLocation(s,"aPosition"),uniforms:l};return this.programs.set(e,c),c}invalidate(){this.cache=new WeakMap,this.programs.clear(),this.vertexShader=null,this.quadBuffer=null}dispose(){this.disposed=!0;let e=this.gl;for(let t of this.programs.values())e.deleteProgram(t.program);this.programs.clear(),this.invalidate()}};var Ca=class{constructor(e,t){this.gl=e;this.epoch=t}gl;epoch;fxPainter=null;filterChain=null;get fx(){return this.fxPainter||(this.fxPainter=new Ta(this.epoch)),this.fxPainter}get filters(){return this.filterChain||(this.filterChain=new Ea(this.gl)),this.filterChain}invalidate(){this.fxPainter?.invalidate(this.gl),this.filterChain?.invalidate()}invalidateTextDerivedBakes(){this.fxPainter?.invalidateTextDerivedBakes(this.gl)}};var AS=[.914,.914,.914,1],Ma=class{host;sources;text;frame={bakeDeadline:0,bakeMore:!1,animationActive:!1};settle;flatFrame=!0;shadow;psd;stroke;gpu;isolator=null;isolating=!1;blender=null;blendWrapNode=null;clipContentNode=null;cropGhostPreDrawn=null;puzzleBox=null;stencilClip=new Sa;maskGpu=new va;constructor(e,t,r){this.host=e,this.sources=t,this.text=r,this.gpu=new Ca(e.gl,e.renderEpoch),this.shadow=new ma(e),this.settle=new An(()=>this.host.requestRenderAll()),this.stroke=new ya(e,this.frame,this.settle),this.psd=new wa(e,this.frame,this.gpu,()=>this.puzzleBox,this.settle,this.compositeFxBlended)}beginFrame(e){this.frame.animationActive=!1,this.frame.bakeDeadline=e+Jm(this.host.isExporting()),this.frame.bakeMore=!1,this.stencilClip.resetFrame(),this.maskGpu.activeThisFrame=!1}noteVptChange(){this.settle.noteInteraction()}noteExternalInteraction(){this.settle.noteInteraction()}groupMask(e){let t=e.raw.mask;if(!t||t.disabled===!0||typeof t.src!="string")return null;let r=this.sources.maskTexture(t.src);if(!r)return null;let o=t.defaultColor===255,i=e.dims.x,s=e.dims.y,a=(Number(t.offsetX)||0)-i/2,l=(Number(t.offsetY)||0)-s/2,u=(Number(t.width)||0)*(Number(t.scaleX)||1),c=(Number(t.height)||0)*(Number(t.scaleY)||1);if(!(u>0)||!(c>0))return null;let h=e.matrix,d=this.host.canvasEl.width,f=this.host.canvasEl.height,m=[d/this.host.dpr,0,0,-f/this.host.dpr,0,f/this.host.dpr],p=ve(this.host.viewportTransform),b=ve(h),x=[1/u,0,0,1/c,-a/u,-l/c];if(!p||!b)return null;let g=V(x,V(b,V(p,m))),y=[g[0],g[1],0,g[2],g[3],0,g[4],g[5],1];return{tex:r,maskInv:y,coversHost:o}}renderPuzzleChildren(e,t){if(!(e instanceof le)){t();return}let r=this.puzzleBox;this.puzzleBox={hw:e.dims.x/2,hh:e.dims.y/2};try{t()}finally{this.puzzleBox=r}}puzzleClampedQuad(e,t,r,o=0,i=0){return Nn(this.puzzleBox,e,t,r,o,i)}renderIsolatedGroup(e,t){let r=this.host.gl;this.flatFrame=!1,this.isolator||(this.isolator=new ha),this.host.batchOrder.flushAll();let o=()=>{if(e instanceof J)for(let s of e.children)this.renderSceneNode(s);else this.renderSceneNodeContentOnly(e)};if(!this.isolator.begin(r,this.host.canvasEl.width,this.host.canvasEl.height)){this.renderPuzzleChildren(e,o);return}this.isolating=!0;let i=1;if(e instanceof J){let s=()=>{for(let a of e.children)a.setIsolation(!0);o();for(let a of e.children)a.setIsolation(!1)};this.renderPuzzleChildren(e,s),i=e.renderOpacity}else o();this.host.batchOrder.flushAll(),this.isolating=!1,this.isolator.end(r),r.viewport(0,0,this.host.canvasEl.width,this.host.canvasEl.height),this.isolator.composite(r,i,t)}renderSceneNodeContentOnly(e){this.renderSceneNode(e)}renderBlendedNode(e,t){let r=this.host.gl;this.flatFrame=!1,this.blender||(this.blender=new Vo),this.host.batchOrder.flushAll();let o=this.host.canvasEl.width,i=this.host.canvasEl.height,s=this.blendWrapNode;this.blendWrapNode=e;try{if(!this.blender.begin(r,o,i)){this.renderSceneNode(e);return}this.renderSceneNode(e),this.host.batchOrder.flushAll(),this.blender.end(r),r.viewport(0,0,o,i),this.blender.composite(r,t)}finally{this.blendWrapNode=s}}compositeFxBlended=(e,t)=>{let r=this.host.gl;this.flatFrame=!1,this.blender||(this.blender=new Vo),this.host.batchOrder.flushAll();let o=this.host.canvasEl.width,i=this.host.canvasEl.height;if(!this.blender.begin(r,o,i)){t();return}t(),this.host.batchOrder.flushAll(),this.blender.end(r),r.viewport(0,0,o,i),this.blender.composite(r,e)};renderSceneNode(e){if(e.visible&&e!==this.host.warpSessionTarget){if(this.blendWrapNode!==e){let t=da(e.raw.globalCompositeOperation);if(t!==null){this.renderBlendedNode(e,t);return}}if(e instanceof J){if(this.stencilClip.begin(e,this.host,{rasterMask:Ro(e)!==null})){let o=this.groupMask(e);!this.isolating&&((e.raw.opacity??1)<1||!!o)?this.renderIsolatedGroup(e,o):this.renderPuzzleChildren(e,()=>{for(let s of e.children)this.renderSceneNode(s)}),this.stencilClip.end(this.host);return}let t=this.groupMask(e);if(!this.isolating&&((e.raw.opacity??1)<1||!!t)){this.renderIsolatedGroup(e,t);return}this.renderPuzzleChildren(e,()=>{for(let o of e.children)this.renderSceneNode(o)});return}if(this.clipContentNode!==e&&Gc(e)){if(this.preDrawCropGhost(e),this.stencilClip.begin(e,this.host,{rasterMask:!1})){let r=this.isolating;this.clipContentNode=e,this.isolating=!0,this.renderSceneNodeContentOnly(e),this.clipContentNode=null,this.isolating=r,this.stencilClip.end(this.host),this.cropGhostPreDrawn=null;return}let t=this.clipContentNode;this.clipContentNode=e,this.renderSceneNodeContentOnly(e),this.clipContentNode=t,this.cropGhostPreDrawn=null;return}if(!this.isolating&&Ro(e)){let t=this.groupMask(e);if(t){this.renderIsolatedGroup(e,t);return}}if(e.isTextType){if(this.text.renderTextPathBackground(e,this.host.zoom*this.host.dpr),typeof e.raw.renderSrc=="string"&&e!==this.host.editingNode){let i=e.imageEl?this.host.textures.get(e.imageEl):null;if(i){let s=e.bitmapRect,a=s.x!==0||s.y!==0?V(e.matrix,[1,0,0,1,s.x,s.y]):e.matrix;s.angle&&(a=V(a,kt({angle:-s.angle}))),this.shadow.render(e),this.psd.render(e,"below");let l=Mo(e.raw);this.host.batch.pushQuad(a,s.w,s.h,[1,1,1,e.renderOpacity*l],i,[0,0,1,1],null,e),this.psd.render(e,"above");return}if(this.sources.isImagePending(e)){this.renderImagePlaceholder(e);return}}let t=kh(e.raw);if(t&&e!==this.host.editingNode){this.text.renderWarpedText(e,t);return}let r=Kn(e.raw);if(r&&e!==this.host.editingNode){this.text.renderPsdWarpedText(e,r);return}let o=Ge(e.raw);if(o&&e!==this.host.editingNode){this.text.renderArcText(e,o,this.host.zoom*this.host.dpr);return}this.shadow.render(e),this.psd.render(e,"below"),this.text.renderTextGlyphs(e,this.host.zoom*this.host.dpr),this.psd.render(e,"above");return}if(e.isShapeType){let t=e.strokeDecl,r=e.shapeMesh;if(r||t){this.shadow.render(e),this.psd.render(e,"below");let o=()=>{this.stroke.render(e)};if(t){let i=t.paintFirst==="stroke";if(i&&o(),r){let s=this.paintParams(e);s?this.host.meshBatch.pushMesh(e.matrix,[1,1,1,e.renderOpacity],r.verts,r.triangles,s,e):this.host.meshBatch.pushMesh(e.matrix,e.drawColor,r.verts,r.triangles,void 0,e)}i||o()}else if(r){let i=this.paintParams(e);i?this.host.meshBatch.pushMesh(e.matrix,[1,1,1,e.renderOpacity],r.verts,r.triangles,i,e):this.host.meshBatch.pushMesh(e.matrix,e.drawColor,r.verts,r.triangles,void 0,e)}}this.psd.render(e,"above");return}if(e.isLineType){this.shadow.render(e),this.stroke.render(e);return}if(e instanceof ae){this.renderMaskNode(e);return}if(e instanceof ie&&e.paintSource){this.renderAnimatedNode(e);return}if(e.isImageType&&!e.imageEl){this.sources.isImagePending(e)&&this.renderImagePlaceholder(e);return}this.renderImageFamily(e)}}renderImageFamily(e){if(this.shadow.render(e),this.psd.render(e,"below"),e.isSolidType){let a=e.strokeDecl?.paintFirst==="stroke";a&&this.stroke.render(e);let l=this.paintParams(e);if(l){this.host.batch.pushPaintQuad(e.matrix,e.dims.x,e.dims.y,l,e.renderOpacity,this.solidRadii(e)),a||this.stroke.render(e);return}}let t=this.imageTextureOf(e);e===this.host.cropGhostNode&&e!==this.cropGhostPreDrawn&&e.imageEl&&t&&this.drawCropGhost(e,t);let r=e.cropRect,o=r&&e.imageEl?[r.sx/e.imageEl.naturalWidth,r.sy/e.imageEl.naturalHeight,(r.sx+r.sw)/e.imageEl.naturalWidth,(r.sy+r.sh)/e.imageEl.naturalHeight]:[0,0,1,1],i=ld(e.raw),s=i===1?e.drawColor:[1,1,1,e.renderOpacity*i];this.host.batch.pushQuad(e.matrix,e.dims.x,e.dims.y,s,t,o,this.quadRadii(e),e),e.isSolidType&&e.strokeDecl?.paintFirst!=="stroke"&&this.stroke.render(e),this.psd.render(e,"above")}imageTextureOf(e){let t=e.isImageType&&!(e instanceof ie)?co(e.raw.filters):[],r=t.length&&e.imageEl?this.gpu.filters.getFilteredTexture(e,e.imageEl,e.imageEl.naturalWidth||e.imageEl.width,e.imageEl.naturalHeight||e.imageEl.height,t):null,o=t.length?e.imageEl:this.sources.svgRasterSource(e,this.host.zoom,this.host.dpr);return r??(o?this.host.textures.get(o):null)}drawCropGhost(e,t){if(!e.imageEl)return;let r=e.dims,o=e.raw.cropX??0,i=e.raw.cropY??0,s=e.imageEl.naturalWidth,a=e.imageEl.naturalHeight,l={x:-r.x/2-o+s/2,y:-r.y/2-i+a/2},u=V(e.matrix,[1,0,0,1,l.x,l.y]);this.host.batch.pushQuad(u,s,a,[1,1,1,.5*e.renderOpacity],t)}preDrawCropGhost(e){if(e!==this.host.cropGhostNode||!e.imageEl)return;let t=this.imageTextureOf(e);t&&(this.cropGhostPreDrawn=e,this.drawCropGhost(e,t))}renderMaskNode(e){let t=e.clipImageRaw;if(e.clipDynamicKind){e.tickDynamicClip(performance.now());let f=e.dynamicClipSource();if(!f||!e.imageEl){this.sources.isImagePending(e)&&this.renderImagePlaceholder(e);return}this.psd.render(e,"below");let m=f;this.host.textures.update(m);let p=this.host.textures.get(m),b=this.host.textures.get(e.imageEl),x=m,g=x.videoWidth||x.width||0,y=x.videoHeight||x.height||0;if(p&&b&&g&&y){let v=this.maskGpu.render(e,this.host.gl,this.host.zoom,this.host.dpr,{maskTex:b,clipTex:p,clipW:g,clipH:y});if(v){this.flatFrame=!1;let S=this.puzzleClampedQuad(e,v.w,v.h);S&&this.host.batch.pushQuad(S.matrix,S.w,S.h,[1,1,1,e.renderOpacity],v.tex,S.uv,null,e),this.psd.render(e,"above"),e.clipAnimating&&(this.frame.animationActive=!0);return}}return}if(!t){if(this.shadow.render(e),!e.imageEl){this.sources.isImagePending(e)&&this.renderImagePlaceholder(e);return}this.psd.render(e,"below");let f=this.sources.svgRasterSource(e,this.host.zoom,this.host.dpr)??e.imageEl,m=this.host.textures.get(f),p=this.puzzleClampedQuad(e,e.dims.x,e.dims.y);p&&this.host.batch.pushQuad(p.matrix,p.w,p.h,[1,1,1,e.renderOpacity],m,p.uv,null,e),this.psd.render(e,"above");return}let r=e.clipImageEl;if(!r||!e.imageEl){this.sources.isImagePending(e)&&this.renderImagePlaceholder(e);return}let o=co(t.filters),i=r,s=i.naturalWidth||i.videoWidth||i.width||t.width||0,a=i.naturalHeight||i.videoHeight||i.height||t.height||0,l=o.length?this.gpu.filters.getFilteredTexture(e,r,s,a,o):this.host.textures.get(r),u=this.host.textures.get(e.imageEl);if(!l||!u||!s||!a)return;let c=this.maskGpu.render(e,this.host.gl,this.host.zoom,this.host.dpr,{maskTex:u,clipTex:l,clipW:s,clipH:a});if(!c)return;this.psd.render(e,"below");let h=this.puzzleClampedQuad(e,c.w,c.h),d=e===this.host.maskCropNode?.5:1;h&&this.host.batch.pushQuad(h.matrix,h.w,h.h,[1,1,1,d*e.renderOpacity],c.tex,h.uv,null,e),this.psd.render(e,"above")}renderAnimatedNode(e){let t=e.tick(performance.now()),r=e.paintSource;if(!r)return;let o=this.host.textures.get(r);o&&t&&this.host.textures.update(r),this.shadow.render(e),this.psd.render(e,"below"),this.host.batch.pushQuad(e.matrix,e.dims.x,e.dims.y,e.drawColor,o,[0,0,1,1],this.quadRadii(e),e),this.psd.render(e,"above"),e.animating&&(this.frame.animationActive=!0)}renderImagePlaceholder(e){let{x:t,y:r}=e.dims;if(!(t>0)||!(r>0))return;let o=e.renderOpacity,i=ee(e.raw.fill),s=i[3]>0?i:AS;this.host.batch.pushQuad(e.matrix,t,r,[s[0],s[1],s[2],s[3]*o],null,[0,0,1,1],this.quadRadii(e),e)}quadRadii(e){if(e.isSolidType){let t=it(e.raw,e.dims.x,e.dims.y);return t?[t.rx,t.ry]:null}if(e.isImageType&&!(e instanceof ie)){let t=pr(e.raw,e.dims.x,e.dims.y);return t?[t,t]:null}return null}solidRadii(e){let t=it(e.raw,e.dims.x,e.dims.y);return t?[t.rx,t.ry]:null}paintParams(e){let t=e.fillPaint;if(!t)return null;if(t.kind==="gradient"){let r=this.host.gradientRamps.get(t.decl);return r?{kind:"gradient",decl:t.decl,inv:ve(ui(t.decl,e.dims.x,e.dims.y)),tex:r}:null}if(t.kind==="pattern"){let r=this.sources.patternTexture(t.decl.src);return r?{kind:"pattern",inv:ve(mi(t.decl,e.dims.x,e.dims.y)),tex:r.tex,size:[r.w,r.h],repeat:Au(t.decl.repeat)}:null}return null}invalidateGlResources(){this.shadow.invalidate(),this.psd.invalidate(),this.stroke.invalidate(),this.maskGpu.invalidate(),this.isolator&&(this.isolator.dispose(this.host.gl),this.isolator=null),this.blender&&(this.blender.dispose(this.host.gl),this.blender=null),this.gpu.invalidate()}invalidateTextDerivedBakes(){this.shadow.invalidate(),this.psd.invalidate(),this.stroke.invalidate(),this.gpu.invalidateTextDerivedBakes()}};var Xc=n=>{let e=n.mask;if(!e||typeof e!="object"||Array.isArray(e))return null;let t=e;if(t.disabled===!0||typeof t.src!="string"||!t.src)return null;let r=Number(t.width),o=Number(t.height);return!(r>0)||!(o>0)?null:{src:t.src,width:r,height:o,left:typeof t.left=="number"?t.left:void 0,top:typeof t.top=="number"?t.top:void 0,offsetX:typeof t.offsetX=="number"?t.offsetX:void 0,offsetY:typeof t.offsetY=="number"?t.offsetY:void 0,defaultColor:typeof t.defaultColor=="number"?t.defaultColor:void 0,crossOrigin:typeof t.crossOrigin=="string"?t.crossOrigin:null}},ap=n=>n.startsWith("resource/")?n.replace("resource/","/resource/"):n,lp=n=>{for(let e=0;e<n.length;e+=4){let t=n[e],r=n[e+1],o=n[e+2];t===r&&r===o?n[e+3]=t:t===0&&r===0&&o===0&&(n[e+3]=0)}},cp=(n,e,t)=>({x:typeof n.offsetX=="number"&&Number.isFinite(n.offsetX)?n.offsetX:(n.left??e)-e,y:typeof n.offsetY=="number"&&Number.isFinite(n.offsetY)?n.offsetY:(n.top??t)-t}),up=(n,e,t,r,o,i)=>{if(r<=0&&t<=0&&i+r>=e&&o+t>=n)return[];let s=[];return r>0&&s.push([0,0,n,r]),t>0&&s.push([0,0,t,e]),r+i<e&&s.push([0,r+i,n,e-i-r]),t+o<n&&s.push([t+o,0,n-o-t,e]),s},hp=(n,e,t,r,o,i)=>{let s=Math.max(1,Math.round(e.x)),a=Math.max(1,Math.round(e.y)),l=document.createElement("canvas");l.width=t.width,l.height=t.height;let u=l.getContext("2d",{willReadFrequently:!0}),c=document.createElement("canvas");c.width=s,c.height=a;let h=c.getContext("2d");if(!u||!h)return null;try{u.drawImage(r,0,0);let f=u.getImageData(0,0,t.width,t.height);lp(f.data),u.putImageData(f,0,0)}catch{return null}let d=cp(t,o,i);if(h.drawImage(l,d.x,d.y),t.defaultColor===255){h.fillStyle="#000000";for(let[f,m,p,b]of up(s,a,d.x,d.y,t.width,t.height))h.fillRect(f,m,p,b)}return h.globalCompositeOperation="source-in",h.drawImage(n,0,0),c},dp=n=>new Promise(e=>{n.toBlob(t=>{if(!t){e(null);return}let r=URL.createObjectURL(t),o=new Image;o.onload=()=>{URL.revokeObjectURL(r),e(o)},o.onerror=()=>{URL.revokeObjectURL(r),e(null)},o.src=r})});var Ko={create(n,e){if(typeof document<"u"){let t=document.createElement("canvas");return t.width=n,t.height=e,t}if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(n,e);throw new Error("Canvas is not available")}},Ln=n=>{let e=n.getContext("2d");if(!e)throw new Error("Failed to get canvas context");return e},Qo=n=>{n.width=0,n.height=0},fp=n=>{"close"in n?n.close():Qo(n)};var Ra=640,Zo=80,mp=async(n,e={})=>{let{parseGIF:t,decompressFrame:r}=await import("gifuct-js"),o=t(n),i=null,s=(o.frames??[]).map(E=>E.image?(!E.gce&&i&&(E.gce=i),i=null,r(E,o.gct,!0)):(E.gce&&(i=E.gce),null)).filter(E=>E!==null);if(!s||!s.length)throw new Error("No frames available");let a=o.lsd,l=a?.width??s[0].dims.width,u=a?.height??s[0].dims.height,c=Math.max(l,u),h=c>Ra?Ra/c:1,d=Math.max(1,Math.round(l*h)),f=Math.max(1,Math.round(u*h)),m=s.reduce((E,M)=>E+(M.delay||0),0)/1e3,p=s.length>Zo?s.slice(0,Zo):s,b=p.reduce((E,M)=>E+(M.delay||0),0),x=p.length>0?b/p.length:100,g=e.canvasFactory??Ko,y=g.create(1,1),v=Ln(y),S=g.create(l,u),w=Ln(S),R=g.create(d*p.length,f),P=Ln(R);if(!v||!w||!P)throw new Error("Failed to get canvas context");S.width=l,S.height=u,R.width=d*p.length,R.height=f;let T,C;return p.forEach((E,M)=>{T?.disposalType===2?w.clearRect(T.dims.left,T.dims.top,T.dims.width,T.dims.height):T?.disposalType===3&&C&&w.putImageData(C,0,0),C=E.disposalType===3?w.getImageData(0,0,l,u):void 0,y.width=E.dims.width,y.height=E.dims.height;let k=v.createImageData(E.dims.width,E.dims.height);k.data.set(E.patch),v.putImageData(k,0,0),w.drawImage(y,E.dims.left,E.dims.top),P.drawImage(S,0,0,l,u,d*M,0,d,f),T=E}),Qo(y),Qo(S),{canvas:R,frameWidth:d,framesLength:p.length,delay:x,frameDelays:p.map(E=>E.delay||100),duration:m}},pp=(n,e,t,r,o={})=>{if(!n.length)throw new Error("No frames available");let i=o.canvasFactory??Ko,s=Math.max(e,t),a=s>Ra?Ra/s:1,l=Math.max(1,Math.round(e*a)),u=Math.max(1,Math.round(t*a)),c=i.create(e,t),h=Ln(c),d=i.create(l*Math.min(n.length,Zo),u),f=Ln(d);if(!h||!f)throw new Error("Failed to get canvas context");c.width=e,c.height=t,d.width=l*Math.min(n.length,Zo),d.height=u;let m=n.slice(0,Zo);m.forEach((b,x)=>{let g=h.createImageData(e,t);g.data.set(new Uint8ClampedArray(b)),h.putImageData(g,0,0),f.drawImage(c,0,0,e,t,l*x,0,l,u)}),Qo(c);let p=m.map((b,x)=>Math.max(1,r[x]??100));return{canvas:d,frameWidth:l,framesLength:m.length,delay:p.reduce((b,x)=>b+x,0)/p.length,frameDelays:p,duration:p.reduce((b,x)=>b+x,0)/1e3}};var NS=[137,80,78,71,13,10,26,10],Ur=n=>{let e=new Uint8Array(n);if(e.length<8||!NS.every((r,o)=>e[o]===r))return!1;let t=new DataView(n);for(let r=8;r+12<=e.length;){let o=t.getUint32(r),i=r+o+12;if(i>e.length)return!1;let s=String.fromCharCode(...e.subarray(r+4,r+8));if(s==="acTL")return o===8&&t.getUint32(r+8)>0;if(s==="IDAT"||s==="IEND")return!1;r=i}return!1},LS=async n=>Ur(await n.arrayBuffer()),IS=async n=>{try{let e=await fetch(n);return e.ok&&Ur(await e.arrayBuffer())}catch{return!1}},bp=async(n,e={})=>{if(!Ur(n))throw new Error("Not an animated PNG");let{default:t}=await import("upng-js"),r=t.decode(n);return r.frames=r.frames.slice(0,80),pp(t.toRGBA8(r),r.width,r.height,r.frames.map(o=>o.delay),e)};var xp=640,_S=80,Pa=100,zc=(n,e)=>String.fromCharCode(n[e],n[e+1],n[e+2],n[e+3]),Yc=n=>{if(n.byteLength<12)return!1;let e=new Uint8Array(n,0,12);return zc(e,0)==="RIFF"&&zc(e,8)==="WEBP"},yp=n=>{if(!Yc(n))return!1;let e=new Uint8Array(n,0,Math.min(n.byteLength,512)),t=12;for(;t+8<=e.length;){let r=zc(e,t);if(r==="VP8X")return t+8<e.length&&(e[t+8]&2)!==0;if(r==="ANIM"||r==="ANMF")return!0;if(r==="VP8 "||r==="VP8L")return!1;let o=e[t+4]|e[t+5]<<8|e[t+6]<<16|e[t+7]<<24;if(o<0)return!1;t+=8+o+o%2}return!1},DS=async n=>yp(await n.slice(0,512).arrayBuffer()),FS=async n=>{try{let e=await fetch(n,{headers:{Range:"bytes=0-511"}});return e.ok?yp(await e.arrayBuffer()):!1}catch{return!1}},Sp=(n,e,t,r={})=>{let o=(r.canvasFactory??Ko).create(n*t,e);o.width=n*t,o.height=e;let i=Ln(o);if(!i)throw new Error("Failed to get canvas context");return{canvas:o,ctx:i}},vp=(n,e)=>{let t=Math.max(n,e),r=t>xp?xp/t:1;return{width:Math.max(1,Math.round(n*r)),height:Math.max(1,Math.round(e*r))}},gp=async(n,e={})=>{let t=URL.createObjectURL(new Blob([n],{type:"image/webp"}));try{let r=await new Promise((l,u)=>{let c=new Image;c.onload=()=>l(c),c.onerror=()=>u(new Error("Failed to load WebP")),c.src=t}),{width:o,height:i}=vp(r.naturalWidth,r.naturalHeight),{canvas:s,ctx:a}=Sp(o,i,1,e);return a.drawImage(r,0,0,o,i),{canvas:s,frameWidth:o,framesLength:1,delay:Pa,frameDelays:[Pa],duration:0}}finally{URL.revokeObjectURL(t)}},wp=async(n,e={})=>{let t=globalThis.ImageDecoder;if(!t||!await t.isTypeSupported("image/webp"))return gp(n,e);let r=new t({data:n,type:"image/webp",preferAnimation:!0});try{await r.tracks.ready;let o=r.tracks.selectedTrack;if(!o?.frameCount||o.frameCount<2)return gp(n,e);let i=Math.min(o.frameCount,_S),s=await r.decode({frameIndex:0}),{width:a,height:l}=vp(s.image.displayWidth,s.image.displayHeight),{canvas:u,ctx:c}=Sp(a,l,i,e),h=[];for(let d=0;d<i;d++){let{image:f}=d===0?s:await r.decode({frameIndex:d}),m=typeof f.duration=="number"&&f.duration>0?f.duration/1e3:Pa;h.push(m),c.drawImage(f,a*d,0,a,l),f.close()}return{canvas:u,frameWidth:a,framesLength:i,delay:h[0]||Pa,frameDelays:h,duration:h.reduce((d,f)=>d+f,0)/1e3}}finally{r.close()}};var Uc=async(n,e={})=>{if(Yc(n))return wp(n,e);if(Ur(n))return bp(n,e);let t=new Uint8Array(n,0,Math.min(6,n.byteLength)),r=String.fromCharCode(...t);if(r==="GIF87a"||r==="GIF89a")return mp(n,e);throw new Error("Unsupported animated image (expected GIF, animated WebP or APNG)")};var ka=class{host;patternSources=new Map;gifSprites=new Map;animatedNodes=new Set;pendingImageNodes=new WeakSet;patternTextures=new Map;maskTextures=new Map;svgRasters=new WeakMap;svgMaxRasterPx;loadGeneration=0;constructor(e){this.host=e;let t=Number(e.gl.getParameter(e.gl.MAX_TEXTURE_SIZE))||4096;this.svgMaxRasterPx=Math.min(t,4096)}async loadGroupMasks(e){let t=new Set,r=s=>{let a=s.raw.mask;a&&a.disabled!==!0&&typeof a.src=="string"&&!this.maskTextures.has(a.src)&&t.add(a.src)},o=s=>{for(let a of s)a instanceof J?(r(a),o(a.children)):Ro(a)&&r(a)};if(o(e),t.size===0)return;let i=this.host.gl;await Promise.all([...t].map(async s=>{try{let a=await Je(s,"anonymous"),l=Ae(i,a);if(!l)return;this.maskTextures.set(s,l)}catch{console.warn("[engine] group mask skipped (load failed):",s)}}))}async loadAnimatedSources(e){let t=++this.loadGeneration,r=a=>this.host.document.nodes.some(l=>l===a||l instanceof J&&l.containsDeep(a)),o=a=>this.loadGeneration===t&&e.includes(a)&&r(a),i=e.filter(a=>a instanceof ae&&!!a.clipDynamicKind&&!a.hasDynamicClip);for(let a of i)(async()=>{let l=a.clipImageRaw;try{let u=a.clipDynamicKind==="gif"?await this.loadGifSprite(l.src):await this.loadVideoElement(l.src,l.crossOrigin,l.loop===!0);if(!o(a))return;a.clipDynamicKind==="gif"?a.attachClipSprite(u,()=>this.host.requestRenderAll()):a.attachClipVideo(u,()=>this.host.requestRenderAll()),this.dynamicClipMasks.add(a),this.host.requestRenderAll()}catch(u){if(console.warn("[engine] mask dynamic clip skipped (load failed):",u.message),!o(a))return;try{a.clipImageEl=await Je(l.src,l.crossOrigin)}catch{}this.host.requestRenderAll()}})();let s=e.filter(a=>a instanceof ie);s.length!==0&&(await Promise.all(s.map(async a=>{let l=a.raw.src;try{let u=a.animatedKind==="gif"?await this.loadGifSprite(l):await this.loadVideoElement(l,a.raw.crossOrigin,a.raw.loop===!0);if(!o(a))return;a.animatedKind==="gif"?a.attachSprite(u,()=>this.host.requestRenderAll()):a.attachVideo(u,()=>this.host.requestRenderAll()),this.animatedNodes.add(a),this.pendingImageNodes.delete(a),this.host.requestRenderAll()}catch(u){if(console.warn("[engine] animated source skipped (load failed):",u.message),!o(a))return;try{a.imageEl=await Je(l,a.raw.crossOrigin)}catch{}this.pendingImageNodes.delete(a),this.host.requestRenderAll()}})),this.host.document.refreshHitIndex())}loadGifSprite(e){if(this.disposed)return Promise.reject(new Error("SourceManager disposed"));let t=this.gifSprites.get(e);if(t)return t;let r=fetch(e).then(async o=>{if(!o.ok)throw new Error(`GIF load failed: ${o.status} ${o.statusText}`);let i=await o.arrayBuffer(),s=this.host.decodeAnimated;if(s)try{return await s(i)}catch(a){console.warn("[engine] injected animated decoder failed, falling back:",a.message)}return Uc(i)}).catch(o=>{throw this.gifSprites.delete(e),o});return this.gifSprites.set(e,r),r}loadVideoElement(e,t,r,o=0){return new Promise((i,s)=>{let a=document.createElement("video");a.crossOrigin=t||"anonymous",a.muted=!0,a.playsInline=!0,a.setAttribute("playsinline","true"),a.setAttribute("webkit-playsinline","true"),a.loop=r,a.preload="auto",a.addEventListener("loadeddata",()=>i(a),{once:!0}),a.addEventListener("error",()=>{a.removeAttribute("src"),a.load(),o<2?setTimeout(()=>{this.loadVideoElement(e,t,r,o+1).then(i,s)},120):s(new Error(`[engine] video load failed: ${e.slice(0,80)}`))},{once:!0}),a.src=e})}releaseAnimatedSources(){this.loadGeneration++;for(let e of[...this.animatedNodes])this.releaseAnimatedNode(e);for(let e of this.dynamicClipMasks)e.detachDynamicClip();this.dynamicClipMasks.clear()}dynamicClipMasks=new Set;releaseAnimatedNode(e){if(!this.animatedNodes.has(e))return;this.animatedNodes.delete(e);let t=e.paintSource;e.detach(),t&&this.host.textures.remove(t)}async loadPatternSources(e){let t=new Set;for(let r of e){let o=r.fillPaint;o?.kind==="pattern"&&t.add(o.decl.src)}t.size!==0&&await Promise.all([...t].map(async r=>{if(!this.patternSources.has(r))try{this.patternSources.set(r,await Je(r,"anonymous"))}catch(o){console.warn("[engine] pattern source skipped (load failed):",o.message)}}))}patternTexture(e){let t=this.patternTextures.get(e);if(t)return t;let r=this.patternSources.get(e);if(!r||!r.naturalWidth)return null;let o=Ae(this.host.gl,r,{mipmap:!0,repeat:!0});if(!o)return null;let i={tex:o,w:r.naturalWidth,h:r.naturalHeight};return this.patternTextures.set(e,i),i}maskTexture(e){return this.maskTextures.get(e)??null}markImagePending(e){this.pendingImageNodes.add(e)}isImagePending(e){return this.pendingImageNodes.has(e)}svgRasterSource(e,t,r){let o=e.imageEl;if(!o)return null;if(!es(e.raw.src))return o;let i=o.naturalWidth||o.width,s=o.naturalHeight||o.height;if(!(i>0)||!(s>0))return o;let a=e.worldScale,l=this.svgRasters.get(e);l&&(l.source!==o||l.sourceSrc!==o.src)&&(this.svgRasters.delete(e),this.host.textures.remove(l.canvas),l=void 0);let u=md({w:i,h:s},{w:i*Math.abs(a.x)*t*r,h:s*Math.abs(a.y)*t*r},l?.factor??1,this.svgMaxRasterPx);if(!u.needsRaster)return l?.canvas??o;if(u.factor===1)return l&&(this.svgRasters.delete(e),this.host.textures.remove(l.canvas)),o;let c=pd(o,u.factor);return l&&this.host.textures.remove(l.canvas),this.svgRasters.set(e,{canvas:c,factor:u.factor,source:o,sourceSrc:o.src}),c}svgRasterFactorOf(e){return this.svgRasters.get(e)?.factor??null}async applyImageMask(e,t){let r=Xc(e.raw);if(!r)return!1;try{let o=await Je(ap(r.src),r.crossOrigin),i=e.dims;if(!(i.x>0)||!(i.y>0))return!1;let s=hp(t,i,r,o,e.raw.left??0,e.raw.top??0);if(!s)return!1;let a=await dp(s);return a?(e.imageEl=a,!0):!1}catch(o){return console.warn("[engine] image mask bake skipped (load failed):",o.message),!1}}async reloadNodeImage(e){let t=e.raw.src,r=e.imageEl,o=this.svgRasters.get(e);o&&(this.svgRasters.delete(e),this.host.textures.remove(o.canvas));try{let i=await Je(t,e.raw.crossOrigin);return e.imageEl=i,await this.applyImageMask(e,i),r&&this.host.textures.remove(r),this.host.document.refreshHitIndex(),this.host.requestRenderAll(),e.imageEl}catch(i){return console.warn("[engine] image reload skipped (load failed):",i.message),null}}async reloadMaskClipImage(e){let t=e.clipImageRaw;if(!t||e.clipDynamicKind)return null;let r=e.clipImageEl;try{let o=await Je(t.src,t.crossOrigin??null);return e.clipImageEl=o,r&&this.host.textures.remove(r),this.host.document.refreshHitIndex(),this.host.requestRenderAll(),o}catch(o){return console.warn("[engine] mask clipImage reload skipped (load failed):",o.message),null}}async loadImages(e){let t=s=>s instanceof ie?!1:s instanceof ae?!s.imageEl||!!s.clipImageRaw&&!s.clipDynamicKind&&!s.clipImageEl:s.isTextType?typeof s.raw.renderSrc=="string"&&!s.imageEl:s.isImageType&&!s.imageEl,r=e.filter(t);if(r.length===0)return;let o=new Map,i=!1;await Promise.all(r.map(async s=>{let a=s.isTextType&&typeof s.raw.renderSrc=="string",l=a?s.raw.renderSrc:s.raw.src,u=()=>{this.pendingImageNodes.delete(s),this.host.requestRenderAll()};try{if(s instanceof ae){if(!s.imageEl){let d=o.get(l);d||(d=await Je(l,s.raw.crossOrigin),o.set(l,d)),s.imageEl=d,i=!0}let h=s.clipImageRaw;if(h&&!s.clipDynamicKind&&!s.clipImageEl){let d=h.src,f=o.get(d);f||(f=await Je(d,h.crossOrigin),o.set(d,f)),s.clipImageEl=f}u();return}if(a){let h=o.get(l);h||(h=await Je(l,s.raw.crossOrigin),o.set(l,h)),s.imageEl=h,i=!0,u();return}let c=o.get(l);c||(c=await Je(l,s.raw.crossOrigin),o.set(l,c)),s.imageEl=c,await this.applyImageMask(s,c),i=!0,u()}catch(c){console.warn("[engine] image node skipped (load failed):",c.message),u()}})),i&&this.host.document.refreshHitIndex()}invalidateGlTextures(){for(let{tex:e}of this.patternTextures.values())this.host.gl.deleteTexture(e);this.patternTextures.clear()}dispose(){this.disposed=!0,this.loadGeneration++;for(let e of this.gifSprites.values())e.then(t=>fp(t.canvas),()=>{});this.gifSprites.clear();for(let{tex:e}of this.patternTextures.values())this.host.gl.deleteTexture(e);this.patternTextures.clear(),this.patternSources.clear()}disposed=!1};function $c(n){let e=[],t=r=>{for(let o of r)e.push(o),o instanceof J&&t(o.children)};return t([...n]),e}async function jc(n,e,t){for(let r of n)r instanceof ie?r.paintSource||e.markImagePending(r):r instanceof ae?(!r.imageEl||r.clipImageRaw&&!r.clipImageEl)&&e.markImagePending(r):r.isTextType&&typeof r.raw.renderSrc=="string"?r.imageEl||e.markImagePending(r):r.isImageType&&!r.imageEl&&e.markImagePending(r);t(),await e.loadImages(n),await e.loadGroupMasks(n),await e.loadAnimatedSources(n),await e.loadPatternSources(n),t()}var He=2,OS=4*He,BS=384,WS=(n,e,t,r,o,i)=>{let s=1/0,a=-1/0,l=1/0,u=-1/0,c=8;for(let h=0;h<=c;h++){let d=r+(o-r)*h/c;for(let f=0;f<=c;f++){let m=e+(t-e)*f/c,p=Pi(n,m,d),b=i[0]*p.x+i[2]*p.y+i[4],x=i[1]*p.x+i[3]*p.y+i[5];s=Math.min(s,b),a=Math.max(a,b),l=Math.min(l,x),u=Math.max(u,x)}}return{minX:s,maxX:a,minY:l,maxY:u}},Vc=(n,e,t=null)=>{let r=n.textLayout,o=Number(n.raw.fontSize)||40,i=typeof n.raw.width=="number"?n.raw.width:r.width,s=typeof n.raw.height=="number"?n.raw.height:r.height;if(!(i>0)||!(s>0))return null;let a=o*.6,l=Math.max(r.width,i,o),u=Math.max(s,o),c=t?wr(t):0,h=Math.ceil(l+a*2+c*2),d=Math.ceil(u+a*2+c*2),f=h*He,m=d*He;if(!(f>0)||!(m>0)||f>8192||m>8192)return null;let p=ul(e,i,s);if(!p)return null;let b=document.createElement("canvas");b.width=f,b.height=m;let x=b.getContext("2d",{willReadFrequently:!0});if(!x)return null;x.setTransform(He,0,0,He,f/2,m/2),n.raw.vertical===!0?Bi(x,n):fo(x,n),mo(x,n,t);let g=x.getImageData(0,0,f,m),y=new Uint32Array(g.data.buffer),v=f,S=0,w=m,R=0,P=!1;for(let ke=0;ke<m;ke++)for(let Ee=0;Ee<f;Ee++)(y[ke*f+Ee]>>>24&255)>10&&(P=!0,Ee<v&&(v=Ee),Ee>S&&(S=Ee),ke<w&&(w=ke),ke>R&&(R=ke));if(!P)return null;let T=v,C=w,E=S+1-v,M=R+1-w,k=(h-i)/2*He,A=(d-s)/2*He,O=[He,0,0,He,k,A],F=(T-k)/He,G=(T+E-k)/He,Y=(C-A)/He,_=(C+M-A)/He,D=F/i,I=G/i,W=Y/s,j=_/s,H=WS(p,D,I,W,j,O),X=Math.floor(H.minX)-1,z=Math.floor(H.minY)-1,$=Math.max(1,Math.ceil(H.maxX+1)-X),Z=Math.max(1,Math.ceil(H.maxY+1)-z);if($>8192||Z>8192)return null;let B=hl(p,0,0,i,s,F,Y,G,_,E,M,[He,0,0,He,k-X,A-z],OS,BS);if(!B)return null;let q=x.createImageData($,Z),U=new Uint32Array(q.data.buffer),oe=new Uint8Array($*Z),ne=(ke,Ee)=>{let ue=Math.min(E-1,Math.max(0,ke)),ge=Math.min(M-1,Math.max(0,Ee)),pe=Math.floor(ue),Te=Math.floor(ge),rt=Math.min(E-1,pe+1),qe=Math.min(M-1,Te+1),Ye=ue-pe,bt=ge-Te,xt=y[(C+Te)*f+(T+pe)],gt=y[(C+Te)*f+(T+rt)],yt=y[(C+qe)*f+(T+rt)],St=y[(C+qe)*f+(T+pe)],Dn=xt>>>24&255,Fn=gt>>>24&255,ni=yt>>>24&255,ri=St>>>24&255;if(Dn<=10&&Fn<=10&&ni<=10&&ri<=10)return 0;let Ue=(vt,Oa,Ba)=>vt+(Oa-vt)*Ba,fr=Math.round(Ue(Ue(xt&255,gt&255,Ye),Ue(St&255,yt&255,Ye),bt)),qr=Math.round(Ue(Ue(xt>>>8&255,gt>>>8&255,Ye),Ue(St>>>8&255,yt>>>8&255,Ye),bt)),oi=Math.round(Ue(Ue(xt>>>16&255,gt>>>16&255,Ye),Ue(St>>>16&255,yt>>>16&255,Ye),bt));return Math.round(Ue(Ue(Dn,Fn,Ye),Ue(ri,ni,Ye),bt))<<24|oi<<16|qr<<8|fr};for(let ke=0;ke+1<B.rows;ke++)for(let Ee=0;Ee+1<B.columns;Ee++){let ue=ke*B.columns+Ee,ge=ue+1,pe=ue+B.columns,Te=pe+1,rt=B.docXs[ue],qe=B.docYs[ue],Ye=B.docXs[ge],bt=B.docYs[ge],xt=B.docXs[Te],gt=B.docYs[Te],yt=B.docXs[pe],St=B.docYs[pe],Dn=Math.max(0,Math.floor(Math.min(rt,Ye,xt,yt))),Fn=Math.min($-1,Math.ceil(Math.max(rt,Ye,xt,yt))),ni=Math.max(0,Math.floor(Math.min(qe,bt,gt,St))),ri=Math.min(Z-1,Math.ceil(Math.max(qe,bt,gt,St)));for(let Ue=ni;Ue<=ri;Ue++)for(let fr=Dn;fr<=Fn;fr++){let qr=Ue*$+fr;if(oe[qr])continue;let oi=dl(fr+.5,Ue+.5,rt,qe,Ye,bt,xt,gt,yt,St);if(!oi)continue;oe[qr]=1;let{s:zt,t:vt}=oi,Oa=(1-zt)*(1-vt)*B.sourceXs[ue]+zt*(1-vt)*B.sourceXs[ge]+zt*vt*B.sourceXs[Te]+(1-zt)*vt*B.sourceXs[pe],Ba=(1-zt)*(1-vt)*B.sourceYs[ue]+zt*(1-vt)*B.sourceYs[ge]+zt*vt*B.sourceYs[Te]+(1-zt)*vt*B.sourceYs[pe];U[qr]=ne(Oa,Ba)}}let de=document.createElement("canvas");de.width=$,de.height=Z;let Pe=de.getContext("2d");if(!Pe)return null;Pe.putImageData(q,0,0);let De=(X+$/2)/He-h/2,nt=(z+Z/2)/He-d/2;return{canvas:de,logicalW:$/He,logicalH:Z/He,offsetX:De,offsetY:nt}};var Ep=new Map,Jo=(n,e)=>{let t=n.worldScale,r=Cp(n);return e*Math.max(t.x*Math.abs(r.x),t.y*Math.abs(r.y),1e-6)},Cp=n=>{let e=Number(n.raw.textScaleX)||1,t=Number(n.raw.textScaleY)||1;return{x:e,y:t}},ur=n=>{let{x:e,y:t}=Cp(n);return e===1&&t===1?n.matrix:V(n.matrix,[e,0,0,t,0,0])},$r=(n,e)=>{let t=Ep.get(n);if(!t){let r=ee(n);t=[r[0],r[1],r[2],r[3]],Ep.set(n,t)}return[t[0],t[1],t[2],t[3]*e[3]]},Aa=class{gl;batch;glyphAtlas;warpBakes=new WeakMap;psdWarpBakes=new WeakMap;arcBakes=new WeakMap;textDashBakes=new WeakMap;scrollBakes=new WeakMap;highlightBakes=new WeakMap;pathBgBakes=new WeakMap;constructor(e,t,r){this.gl=e,this.batch=t,this.glyphAtlas=r}invalidateNodeBakes(e){for(let t of[this.warpBakes,this.psdWarpBakes,this.arcBakes,this.textDashBakes,this.scrollBakes,this.highlightBakes,this.pathBgBakes]){let r=t.get(e);r?.tex&&this.gl.deleteTexture(r.tex),t.delete(e)}}renderWarpedText(e,t){let r=Kt(e.raw.effects,{text:!0}),o=[e.raw.type,e.raw.textTransform,e.raw.text,e.raw.warpStrength,e.raw.fontSize,e.raw.fontFamily,e.raw.width,e.raw.height,e.raw.fill,e.raw.stroke,e.raw.strokeWidth,JSON.stringify(e.raw.styles??null),JSON.stringify(e.raw.paragraph??null),r?Sn(r):""].join(";"),i=this.warpBakes.get(e);if(i&&i.sig!==o&&(this.gl.deleteTexture(i.tex),i=void 0),!i){let s=Sl(e,t,r);if(!s){this.warpBakes.set(e,void 0);return}let a=Ae(this.gl,s.canvas);if(!a)return;i={sig:o,tex:a,w:s.logicalW,h:s.logicalH},this.warpBakes.set(e,i)}this.batch.pushQuad(e.matrix,i.w,i.h,[1,1,1,e.renderOpacity],i.tex)}renderPsdWarpedText(e,t){let r=Kt(e.raw.effects,{text:!0}),o=[e.raw.type,e.raw.text,JSON.stringify(e.raw.psdWarp??null),e.raw.fontSize,e.raw.fontFamily,e.raw.fontWeight,e.raw.fontStyle,e.raw.width,e.raw.height,e.raw.lineHeight,e.raw.charSpacing,e.raw.vertical===!0?1:0,e.raw.fill,e.raw.stroke,e.raw.strokeWidth,JSON.stringify(e.raw.styles??null),JSON.stringify(e.raw.paragraph??null),r?Sn(r):""].join(";"),i=this.psdWarpBakes.get(e);if(i&&i.sig!==o&&(this.gl.deleteTexture(i.tex),i=void 0),!i){let a=Vc(e,t,r);if(!a){this.psdWarpBakes.set(e,void 0);return}let l=Ae(this.gl,a.canvas);if(!l)return;i={sig:o,tex:l,w:a.logicalW,h:a.logicalH,offX:a.offsetX,offY:a.offsetY},this.psdWarpBakes.set(e,i)}let s=i.offX!==0||i.offY!==0?V(e.matrix,kt({translateX:i.offX,translateY:i.offY})):e.matrix;this.batch.pushQuad(s,i.w,i.h,[1,1,1,e.renderOpacity],i.tex)}renderArcText(e,t,r){let o=Kt(e.raw.effects,{text:!0}),i=!!o&&(o.dropShadows.length>0||o.solidFills.length>0||o.strokes.length>0);if(Eu()&&!i){this.renderArcGlyphs(e,t,r);return}let s=Wt(Jo(e,r)),a=[e.raw.type,e.raw.textTransform,e.raw.text,e.raw.curvature,e.raw.circleSize,e.raw.circleStartAngle,e.raw.circleSweep,e.raw.circleEccentricity,e.raw.circleDirection,e.raw.fontSize,e.raw.fontFamily,e.raw.fontWeight,e.raw.fontStyle,e.raw.lineHeight,e.raw.textAlign,e.raw.fill,e.raw.stroke,e.raw.strokeWidth,e.raw.strokeVisible,e.raw.paintFirst,JSON.stringify(e.raw.styles??null),o?Sn(o):"",s].join(";"),l=this.arcBakes.get(e);if(l&&l.sig!==a&&(this.gl.deleteTexture(l.tex),l=void 0),!l){let u=vl(e,t,o,s);if(!u){this.arcBakes.set(e,void 0);return}let c=Ae(this.gl,u.canvas);if(!c)return;l={sig:a,tex:c,w:u.logicalW,h:u.logicalH},this.arcBakes.set(e,l)}this.batch.pushQuad(e.matrix,l.w,l.h,[1,1,1,e.renderOpacity],l.tex)}renderArcGlyphs(e,t,r){let o=Et(e.textLayout,e.raw,e.textStyle.lineHeight??1.16),i=Wt(Jo(e,r)),s=e.textStyle,a=e.textStroke,l=e.raw.strokeVisible===!0,u=e.paintFirst==="stroke",c=typeof e.raw.fill=="string"?e.raw.fill:"",h=e.matrix,d=[1,1,1,e.renderOpacity];for(let f of o.chars){let m=e.textLayout.lines[f.line]?.charStyles[f.index],p=bn(s,m),b=typeof m?.fill=="string"&&m.fill?m.fill:c,x=l?Oe(a,m):null,g=f.x-o.contentOffsetX,y=f.y-o.contentOffsetY,v=Math.cos(f.rotation),S=Math.sin(f.rotation),w=R=>{if(R){if(!x||x.width<=0)return}else if(!b)return;let{rs:P,scale:T}=ea(p.fontSize,i),C=this.glyphAtlas.get(p,P,f.char,R?x:null);if(!C)return;let E=C.wPx/T,M=C.hPx/T,k=(C.inkLeftPx-C.advancePx/2-C.padPx)/T+E/2,A=-(C.ascentPx+C.padPx)/T+M/2,O=$r(R?x.color:b,d),F=V(h,V([1,0,0,1,g,y],V([v,S,-S,v,0,0],[1,0,0,1,k,A])));this.batch.pushQuad(F,E,M,O,this.glyphAtlas.textureOf(C),[C.u0,C.v0,C.u1,C.v1])};u?(w(!0),w(!1)):(w(!1),w(!0))}}renderTextGlyphs(e,t){if(Tr(e.raw)?.enabled){this.renderScrollText(e,t);return}let o=e.textLayout,i=e.textStroke,s=!!e.raw.fill||o.lines.some(l=>l.charStyles.some(u=>u?.fill)),a=Wt(Jo(e,t));this.renderTextBackgrounds(e),this.renderTextDecorations(e,"underline"),this.renderTextHighlight(e,a),i&&e.paintFirst==="stroke"?(this.renderGlyphPass(e,"stroke",a),s&&this.renderGlyphPass(e,"fill",a)):(s&&this.renderGlyphPass(e,"fill",a),i&&this.renderGlyphPass(e,"stroke",a)),this.renderTextDecorations(e,"overline"),this.renderTextDecorations(e,"linethrough")}renderScrollText(e,t){this.renderTextBackgrounds(e),this.renderTextDecorations(e,"underline");let r=Wt(Jo(e,t)),o=e.raw,i=[o.text,o.width,o.height,o.fontSize,o.fontFamily,o.fontWeight,o.fontStyle,o.lineHeight,o.charSpacing,o.textAlign,o.splitByGrapheme,o.vertical,typeof o.fill=="string"?o.fill:"gradient",o.stroke,o.strokeWidth,Array.isArray(o.strokeDashArray)?o.strokeDashArray.join(","):"",o.strokeDashOffset,o.paintFirst,JSON.stringify(o.styles??null),o.scrollDirection,JSON.stringify(o.paragraph??null),e.scrollOffset.toFixed(3),e.textTotalWidth.toFixed(3),r].join(";"),s=this.scrollBakes.get(e);if(s&&s.sig!==i&&(this.gl.deleteTexture(s.tex),s=void 0),!s){let a=_h(e,r,e.scrollOffset);if(!a){this.scrollBakes.set(e,void 0);return}let l=Ae(this.gl,a.canvas);if(!l)return;s={sig:i,tex:l,w:a.logicalW,h:a.logicalH},this.scrollBakes.set(e,s)}this.batch.pushQuad(ur(e),s.w,s.h,[1,1,1,e.renderOpacity],s.tex),this.renderTextDecorations(e,"overline"),this.renderTextDecorations(e,"linethrough")}renderTextPathBackground(e,t){let r=Ai(e);if(!r)return;let o=Wt(Jo(e,t)),i=`${r.sigBase};${o}`,s=this.pathBgBakes.get(e);if(s&&s.sig!==i&&(this.gl.deleteTexture(s.tex),s=void 0),!s){let a=bh(r,o);if(!a){this.pathBgBakes.set(e,void 0);return}let l=Ae(this.gl,a.canvas);if(!l)return;s={sig:i,tex:l,w:a.logicalW,h:a.logicalH},this.pathBgBakes.set(e,s)}this.batch.pushQuad(e.matrix,s.w,s.h,[1,1,1,e.renderOpacity],s.tex)}renderTextBackgrounds(e){let t=e.textLayout,r=e.renderOpacity,o=ur(e),i=typeof e.raw.textBackgroundColor=="string"?e.raw.textBackgroundColor:"";if(!(!i&&!t.lines.some(s=>s.charStyles.some(a=>a?.textBackgroundColor))))for(let s of t.lines){let a=-t.width/2+s.leftOffset,l=e.contentTopY+s.top,u=m=>s.charStyles[m]?.textBackgroundColor??i,c=0,h=0,d=u(0),f=()=>{if(!d||h<=0)return;let m=a+s.boxes[c].left,p=ee(d),b=[p[0],p[1],p[2],p[3]*r],x=V(o,[1,0,0,1,m+h/2,l+s.implHeight/2]);this.batch.pushQuad(x,h,s.implHeight,b,null)};for(let m=0;m<s.graphemes.length;m++){let p=u(m);p!==d?(f(),c=m,h=s.boxes[m].width,d=p):h+=s.boxes[m].kernedWidth}f()}}renderTextDecorations(e,t){let r=e.textLayout,o=e.decorationDefaults,i=[1,1,1,e.renderOpacity],s=ur(e);for(let a of r.lines){let l=al(a,t,o);if(l.length===0)continue;let u=-r.width/2+a.leftOffset,c=e.contentTopY+a.baseline;for(let h of l){let d=u+h.x+h.width/2,f=c+h.y+h.thickness/2;this.batch.pushQuad(V(s,[1,0,0,1,d,f]),h.width,h.thickness,$r(h.color,i),null)}}}textHasDashStroke(e){return Array.isArray(e.raw.strokeDashArray)&&e.raw.strokeDashArray.length>0}renderTextDashStroke(e,t){let r=e.textLayout,o=e.textStyle,i=e.raw.strokeDashArray,s=e.textStroke,a=s?s.width:0;if(!s||a<=0)return;let l=Number(e.raw.charSpacing)||0,u=Ut(e.raw.textAlign),c=e.raw.textAlign===fe.DISPERSE,h=Number(e.raw.textOffsetY)||0,d=th(h,e.textStyle,r.lines),f=a+4+Math.ceil(d),m=Math.ceil(r.width+f*2),p=Math.ceil(r.height+f*2);if(!(m>0)||!(p>0)||m>8192||p>8192)return;let b=[e.raw.text,r.width,r.height,s.color,s.width,i.join(","),Number(e.raw.strokeDashOffset)||0,t,l,u,e.raw.textAlign,e.raw.vertical===!0,h,JSON.stringify(e.raw.paragraph??null)].join(";"),x=this.textDashBakes.get(e);if(x&&x.sig!==b&&(this.gl.deleteTexture(x.tex),x=void 0),!x){let g=document.createElement("canvas");g.width=Math.ceil(m*t),g.height=Math.ceil(p*t);let y=g.getContext("2d");if(!y)return;y.setTransform(t,0,0,t,0,0),y.textBaseline="alphabetic",y.setLineDash(i),y.lineDashOffset=Number(e.raw.strokeDashOffset)||0,y.lineJoin=typeof e.raw.strokeLineJoin=="string"?e.raw.strokeLineJoin:"miter",y.lineCap=typeof e.raw.strokeLineCap=="string"?e.raw.strokeLineCap:"butt",y.miterLimit=Number(e.raw.strokeMiterLimit)||4;let v=r.width/2+f,S=r.height/2+f+e.contentTopY,w=e.raw.vertical===!0,R=0;for(let T of r.lines){let C=-r.width/2+T.leftOffset,E=S+T.baseline;if(w){T.prefix&&Tt(y,T,v+C,E,{stroke:Oe(s,T.charStyles[0])});let D=$t(T,C,E,o,l);for(let I=0;I<D.length;I++){let W=Oe(s,T.charStyles[I]);if(!W||W.width<=0)continue;let j=dn(o,T.charStyles[I]);y.font=Me(j,j.fontSize),y.lineWidth=W.width,y.strokeStyle=W.color,jt(y,{...D[I],y:D[I].y+wt(h,j.fontSize,R+I)},"strokeText")}R+=T.graphemes.length;continue}let M=to(e.raw.textAlign)&&T.graphemes.some(D=>io.test(D)),k="",A=T.prefix?Tt(y,T,v+C,E,{stroke:Oe(s,T.charStyles[0])}):0,O=0,F="",G=null,Y,_=D=>{if(!k)return;let I=G;I&&I.width>0&&(y.font=F,y.lineWidth=I.width,y.strokeStyle=I.color,y.strokeText(k,v+C+A,E+O)),k="",D<T.boxes.length&&(A=T.boxes[D].left)};for(let D=0;D<T.graphemes.length;D++){let I=T.charStyles[D],j=I!==void 0&&(I.fontSize!==void 0||I.fontFamily!==void 0||I.fontWeight!==void 0||I.fontStyle!==void 0)&&I?{...o,fontSize:I.fontSize??o.fontSize,fontFamily:I.fontFamily??o.fontFamily,fontWeight:I.fontWeight??o.fontWeight,fontStyle:I.fontStyle??o.fontStyle}:o,H=Me(j,j.fontSize),X=Oe(s,I),z=I?.fill??"",$=G;k&&(H!==F||X?.color!==$?.color||X?.width!==$?.width||z!==Y)&&_(D),k||(F=H,G=X,Y=z,O=wt(h,j.fontSize,R+D)),k+=T.graphemes[D],(l||h!==0||(u||c)&&/[ \t\r]/.test(T.graphemes[D])||M)&&_(D+1)}_(T.graphemes.length),R+=T.graphemes.length}let P=Ae(this.gl,g);if(!P)return;x={sig:b,tex:P,w:m,h:p},this.textDashBakes.set(e,x)}this.batch.pushQuad(ur(e),x.w,x.h,[1,1,1,e.renderOpacity],x.tex)}renderTextHighlight(e,t){let r=e.raw;if(!Array.isArray(r.texts)||r.texts.length===0||r.vertical===!0)return;let o=e.textLayout,i=[r.text,o.width,o.height,r.fontSize,r.fontFamily,r.fontWeight,r.fontStyle,r.lineHeight,r.charSpacing,r.textAlign,r.splitByGrapheme,JSON.stringify(r.styles??null),e.dims.y,JSON.stringify(r.texts??null),JSON.stringify(r.paragraph??null),t].join(";"),s=this.highlightBakes.get(e);if(s&&s.sig!==i&&(this.gl.deleteTexture(s.tex),s=void 0),!s){let a=Qn(r.text??"",o,r.texts,e.contentTopY,e.textStyle.fontSize);if(!a){this.highlightBakes.set(e,void 0);return}let l=ph(a,o,e.contentTopY,t);if(!l)return;let u=Ae(this.gl,l.canvas);if(!u)return;s={sig:i,tex:u,w:l.logicalW,h:l.logicalH,centerY:e.contentTopY-a.padY+l.logicalH/2},this.highlightBakes.set(e,s)}this.batch.pushQuad(V(ur(e),[1,0,0,1,0,s.centerY]),s.w,s.h,[1,1,1,e.renderOpacity],s.tex)}renderGlyphPass(e,t,r){if(t==="stroke"&&this.textHasDashStroke(e)){this.renderTextDashStroke(e,r);return}let o=e.textLayout,i=e.textStyle,s=ur(e),a=e.renderOpacity,l=e.fillPaint,u=l?.kind==="gradient"?[l.decl.stops[0].color[0],l.decl.stops[0].color[1],l.decl.stops[0].color[2],l.decl.stops[0].color[3]*a]:e.drawColor,c=!!e.raw.fill,h=e.textStroke,d=[1,1,1,a],f=e.raw.vertical===!0,m=f&&i.charSpacing?i.fontSize*i.charSpacing/1e3:0,p=Number(e.raw.textOffsetY)||0,b=0;for(let x of o.lines){let g=-o.width/2+x.leftOffset,y=e.contentTopY+x.baseline;if(x.prefix)if(t==="stroke"){let S=Oe(h,x.charStyles[0]);S&&S.width>0&&this.pushPrefixGlyphs(e,x.prefix,g,y,S,$r(S.color,d),r)}else{let S=x.charStyles[0]?.fill;(S||c)&&this.pushPrefixGlyphs(e,x.prefix,g,y,null,S?$r(S,u):u,r)}let v=0;for(let S=0;S<x.graphemes.length;S++){let w=x.charStyles[S],R,P=null;if(t==="stroke"){if(P=Oe(h,w),!P)continue;R=$r(P.color,d)}else{let _=w?.fill;if(!_&&!c)continue;R=_?$r(_,u):u}let C=w!==void 0&&(w.fontSize!==void 0||w.fontFamily!==void 0||w.fontWeight!==void 0||w.fontStyle!==void 0)&&w?{...i,fontSize:w.fontSize??i.fontSize,fontFamily:w.fontFamily??i.fontFamily,fontWeight:w.fontWeight??i.fontWeight,fontStyle:w.fontStyle??i.fontStyle}:i,E=wt(p,C.fontSize,b+S),{rs:M,scale:k}=ea(C.fontSize,r),A=this.glyphAtlas.get(C,M,x.graphemes[S],P);if(!A)continue;let O=x.boxes[S],F=A.wPx/k,G=A.hPx/k,Y;if(f){let _=x.graphemes[S],D=$n(_),I=C.fontSize,W=jn(_,O,m);if(D==="latin"||D==="bracket"){let H=g+v+(D==="latin"?O.kernedWidth-O.width:0)+(A.inkLeftPx-A.padPx)/k,X=y+E-(A.ascentPx+A.padPx)/k;Y=V(s,[1,0,0,1,H+F/2,X+G/2])}else{let j=g+v+cn(I),H=y+E+gr(D,O,I),X=(A.inkLeftPx-A.padPx)/k+F/2,z=G/2-(A.ascentPx+A.padPx)/k;Y=V(s,V([1,0,0,1,j,H],V([0,-1,1,0,0,0],[1,0,0,1,X,z])))}v+=W}else{let D=g+O.left+(A.inkLeftPx-A.padPx)/k,I=y+E-(A.ascentPx+A.padPx)/k;Y=V(s,[1,0,0,1,D+F/2,I+G/2])}this.batch.pushQuad(Y,F,G,R,this.glyphAtlas.textureOf(A),[A.u0,A.v0,A.u1,A.v1])}b+=x.graphemes.length}}pushPrefixGlyphs(e,t,r,o,i,s,a){let l=At(t.text),u=r;for(let c=0;c<l.length;c++){let{rs:h,scale:d}=ea(t.style.fontSize,a),f=this.glyphAtlas.get(t.style,h,l[c],i);if(f){let m=f.wPx/d,p=f.hPx/d,b=u+(f.inkLeftPx-f.padPx)/d,x=o-(f.ascentPx+f.padPx)/d;this.batch.pushQuad(V(ur(e),[1,0,0,1,b+m/2,x+p/2]),m,p,s,this.glyphAtlas.textureOf(f),[f.u0,f.v0,f.u1,f.v1])}u+=t.advances[c]??0}}};var Mp=(n,e,t)=>{let r=n.createRenderbuffer();if(!r)throw new Error("Unable to allocate export stencil");return n.bindRenderbuffer(n.RENDERBUFFER,r),n.renderbufferStorage(n.RENDERBUFFER,n.DEPTH24_STENCIL8,e,t),n.framebufferRenderbuffer(n.FRAMEBUFFER,n.DEPTH_STENCIL_ATTACHMENT,n.RENDERBUFFER,r),r},Rp=n=>{let e=n.getParameter(n.RENDERBUFFER_BINDING),t=n.isEnabled(n.STENCIL_TEST),r=n.getParameter(n.STENCIL_CLEAR_VALUE),o=n.getParameter(n.COLOR_WRITEMASK),i=n.isEnabled(n.SCISSOR_TEST),s=[n.STENCIL_FUNC,n.STENCIL_REF,n.STENCIL_VALUE_MASK,n.STENCIL_WRITEMASK,n.STENCIL_FAIL,n.STENCIL_PASS_DEPTH_FAIL,n.STENCIL_PASS_DEPTH_PASS].map(l=>n.getParameter(l)),a=[n.STENCIL_BACK_FUNC,n.STENCIL_BACK_REF,n.STENCIL_BACK_VALUE_MASK,n.STENCIL_BACK_WRITEMASK,n.STENCIL_BACK_FAIL,n.STENCIL_BACK_PASS_DEPTH_FAIL,n.STENCIL_BACK_PASS_DEPTH_PASS].map(l=>n.getParameter(l));return()=>{n.bindRenderbuffer(n.RENDERBUFFER,e),n.clearStencil(r),n.colorMask(o[0],o[1],o[2],o[3]);for(let[l,u]of[[n.FRONT,s],[n.BACK,a]])n.stencilFuncSeparate(l,u[0],u[1],u[2]),n.stencilMaskSeparate(l,u[3]),n.stencilOpSeparate(l,u[4],u[5],u[6]);t?n.enable(n.STENCIL_TEST):n.disable(n.STENCIL_TEST),i?n.enable(n.SCISSOR_TEST):n.disable(n.SCISSOR_TEST)}},Pp=n=>{n.disable(n.SCISSOR_TEST),n.disable(n.STENCIL_TEST),n.colorMask(!0,!0,!0,!0),n.stencilMask(255),n.clearStencil(0),n.clear(n.COLOR_BUFFER_BIT|n.STENCIL_BUFFER_BIT)};var kp=(n,e)=>{let t=n.multiplier&&n.multiplier>0?n.multiplier:1,r=n.width,o=n.height;if(!(r>0)||!(o>0)||!(e>0))return null;let i=Math.max(1,Math.round(r*t)),s=Math.max(1,Math.round(o*t)),a=Math.max(i,s);if(a>e){let u=e/a;i=Math.max(1,Math.floor(i*u)),s=Math.max(1,Math.floor(s*u))}let l=Math.min(i/r,s/o);return{outWidth:i,outHeight:s,multiplier:l}},qc=(n,e)=>{let t=e.outWidth/n.width,r=e.outHeight/n.height;return[t,0,0,r,-n.left*t,-n.top*r]},Ap=(n,e)=>Kr(qc(n,e),e.outWidth,e.outHeight,1),Na=(n,e,t)=>{let r=new Uint8ClampedArray(e*t*4);for(let o=0;o<t;o++){let i=(t-1-o)*e*4,s=o*e*4;for(let a=0;a<e*4;a+=4){let l=n[i+a+3];if(l===0){r[s+a]=0,r[s+a+1]=0,r[s+a+2]=0,r[s+a+3]=0;continue}let u=c=>Math.min(255,Math.round(c*255/l));r[s+a]=u(n[i+a]),r[s+a+1]=u(n[i+a+1]),r[s+a+2]=u(n[i+a+2]),r[s+a+3]=l}}return r};var Np=n=>typeof n.fenceSync=="function"&&typeof n.clientWaitSync=="function"&&typeof n.getBufferSubData=="function",Lp=(n,e)=>new Promise(t=>{let r=performance.now(),o=!0,i=()=>{let s;try{s=n.clientWaitSync(e,o?n.SYNC_FLUSH_COMMANDS_BIT:0,0)}catch{return t()}if(o=!1,s===n.ALREADY_SIGNALED||s===n.CONDITION_SATISFIED||s===n.WAIT_FAILED||performance.now()-r>1e3)return t();setTimeout(i,4)};i()}),La=class{constructor(e){this.host=e}host;exportToPixels(e){let t=this.renderAndStage(e,!1);return t?{width:t.outWidth,height:t.outHeight,data:Na(t.raw,t.outWidth,t.outHeight)}:null}async exportToPixelsAsync(e){let t=await this.stageAndDrain(e);return t?{width:t.outWidth,height:t.outHeight,data:Na(t.raw,t.outWidth,t.outHeight)}:null}async exportRawPixelsAsync(e){let t=await this.stageAndDrain(e);return t?{width:t.outWidth,height:t.outHeight,raw:t.raw}:null}async stageAndDrain(e){let t=this.renderAndStage(e,!0);if(!t)return null;if(!t.stagedReadback)return{outWidth:t.outWidth,outHeight:t.outHeight,raw:t.raw};let r=await this.drainStagedReadback(t.stagedReadback);return r?{outWidth:t.outWidth,outHeight:t.outHeight,raw:r}:null}renderRounds(e,t,r){let o=this.host.gl,i=0;do{this.host.renderer.beginFrame(performance.now()),o.bindFramebuffer(o.FRAMEBUFFER,e),o.clearColor(t[0],t[1],t[2],t[3]),Pp(o),this.host.batch.begin(r,this.host.zoom*this.host.dpr),this.host.meshBatch.begin(r);for(let s of this.host.sceneNodes)o.bindFramebuffer(o.FRAMEBUFFER,e),this.host.renderer.renderSceneNode(s);o.bindFramebuffer(o.FRAMEBUFFER,e),this.host.batchOrder.flushAll()}while(this.host.renderer.frame.bakeMore&&++i<64)}renderAndStage(e,t){if(!this.host.exportReady)return null;let r=kp(e,this.host.capabilities.maxTextureSize);if(!r)return null;let o=this.host.gl,{outWidth:i,outHeight:s}=r,a=e.background??[0,0,0,0],l=i*s*4,u=this.host.bakeKReuseFloor;this.host.bakeKReuseFloor=e.bakeScaleTolerance??0;let c={framebuffer:o.getParameter(o.FRAMEBUFFER_BINDING),viewport:o.getParameter(o.VIEWPORT),clearColor:o.getParameter(o.COLOR_CLEAR_VALUE),program:o.getParameter(o.CURRENT_PROGRAM),activeTexture:o.getParameter(o.ACTIVE_TEXTURE),textureBinding:o.getParameter(o.TEXTURE_BINDING_2D),packBuffer:o.getParameter(o.PIXEL_PACK_BUFFER_BINDING),blendEnabled:o.isEnabled(o.BLEND),blendSrcRgb:o.getParameter(o.BLEND_SRC_RGB),blendDstRgb:o.getParameter(o.BLEND_DST_RGB),blendSrcAlpha:o.getParameter(o.BLEND_SRC_ALPHA),blendDstAlpha:o.getParameter(o.BLEND_DST_ALPHA)},h=Rp(o),d=null,f=o.createTexture(),m=o.createFramebuffer(),p=null,b=new Uint8Array(0),x=null,g=!1;try{if(o.bindTexture(o.TEXTURE_2D,f),o.texImage2D(o.TEXTURE_2D,0,o.RGBA,i,s,0,o.RGBA,o.UNSIGNED_BYTE,null),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,o.LINEAR),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MAG_FILTER,o.LINEAR),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_S,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_T,o.CLAMP_TO_EDGE),o.bindFramebuffer(o.FRAMEBUFFER,m),o.framebufferTexture2D(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.TEXTURE_2D,f,0),d=Mp(o,i,s),o.checkFramebufferStatus(o.FRAMEBUFFER)!==o.FRAMEBUFFER_COMPLETE)return null;p=this.host.applyExportViewport(qc(e,r),i,s);let y=Ap(e,r);if(o.viewport(0,0,i,s),this.renderRounds(m,a,y),o.bindFramebuffer(o.FRAMEBUFFER,m),t&&Np(o)){let v=o.createBuffer();o.bindBuffer(o.PIXEL_PACK_BUFFER,v),o.bufferData(o.PIXEL_PACK_BUFFER,l,o.STREAM_READ),o.readPixels(0,0,i,s,o.RGBA,o.UNSIGNED_BYTE,0);let S=o.fenceSync(o.SYNC_GPU_COMMANDS_COMPLETE,0);o.flush(),o.bindBuffer(o.PIXEL_PACK_BUFFER,c.packBuffer),x={gl:o,pbo:v,fence:S,byteLength:l},g=!0}else b=new Uint8Array(l),o.readPixels(0,0,i,s,o.RGBA,o.UNSIGNED_BYTE,b)}finally{o.bindFramebuffer(o.FRAMEBUFFER,c.framebuffer),o.viewport(c.viewport[0],c.viewport[1],c.viewport[2],c.viewport[3]),o.clearColor(c.clearColor[0],c.clearColor[1],c.clearColor[2],c.clearColor[3]),o.useProgram(c.program),o.activeTexture(c.activeTexture),o.bindTexture(o.TEXTURE_2D,c.textureBinding&&o.isTexture(c.textureBinding)?c.textureBinding:null),o.bindBuffer(o.PIXEL_PACK_BUFFER,c.packBuffer),c.blendEnabled?o.enable(o.BLEND):o.disable(o.BLEND),o.blendFuncSeparate(c.blendSrcRgb,c.blendDstRgb,c.blendSrcAlpha,c.blendDstAlpha),h(),p?.(),d&&o.deleteRenderbuffer(d),m&&o.deleteFramebuffer(m),f&&o.deleteTexture(f),x&&!g&&(o.deleteBuffer(x.pbo),x.fence&&o.deleteSync(x.fence)),this.host.bakeKReuseFloor=u,this.host.requestRenderAll()}return x?{outWidth:i,outHeight:s,raw:b,stagedReadback:x}:b.length?{outWidth:i,outHeight:s,raw:b,stagedReadback:null}:null}async drainGpuBacklog(){let e=this.host.gl;if(!Np(e))return;let t=null;try{if(t=e.fenceSync(e.SYNC_GPU_COMMANDS_COMPLETE,0),!t)return;await Lp(e,t)}catch{}finally{t&&e.deleteSync(t)}}async drainStagedReadback(e){let{gl:t,pbo:r,fence:o,byteLength:i}=e;try{if(o&&await Lp(t,o),!this.host.exportReady)return null;let s=new Uint8Array(i),a=t.getParameter(t.PIXEL_PACK_BUFFER_BINDING);return t.bindBuffer(t.PIXEL_PACK_BUFFER,r),t.getBufferSubData(t.PIXEL_PACK_BUFFER,0,s),t.bindBuffer(t.PIXEL_PACK_BUFFER,a),s}catch{return null}finally{t.deleteBuffer(r),o&&t.deleteSync(o)}}exportToCanvas(e){let t=this.exportToPixels(e);if(!t)return null;let r=document.createElement("canvas");r.width=t.width,r.height=t.height;let o=r.getContext("2d");if(!o)return null;let i=o.createImageData(t.width,t.height);return i.data.set(t.data),o.putImageData(i,0,0),r}exportToDataURL(e,t="image/png",r){let o=this.exportToCanvas(e);return o?o.toDataURL(t,r):null}};var Kc=[.8705882352941177,.8627450980392157,.8627450980392157],HS=8,GS=`#version 300 es
|
|
1038
1038
|
layout(location = 0) in vec2 aPos;
|
|
1039
1039
|
uniform mat3 uView;
|
|
1040
1040
|
out vec2 vScene;
|
|
1041
1041
|
void main() {
|
|
1042
1042
|
vScene = aPos;
|
|
1043
1043
|
gl_Position = vec4(uView * vec3(aPos, 1.0), 1.0);
|
|
1044
|
-
}`,
|
|
1044
|
+
}`,XS=`#version 300 es
|
|
1045
1045
|
precision highp float;
|
|
1046
1046
|
in vec2 vScene;
|
|
1047
1047
|
uniform mat3 uVpt;
|
|
@@ -1061,14 +1061,14 @@ float inside = 1.0 - smoothstep(-uAa, uAa, d);
|
|
|
1061
1061
|
vec2 screen = (uVpt * vec3(vScene, 1.0)).xy;
|
|
1062
1062
|
float parity = mod(floor(screen.x / uTile) + floor(screen.y / uTile), 2.0);
|
|
1063
1063
|
outColor = vec4(mix(vec3(1.0), uDark, parity), inside);
|
|
1064
|
-
}`,
|
|
1064
|
+
}`,Ia=class{program=null;vao=null;vertexBuffer=null;corners=new Float32Array(12);invalidate(){this.program=null,this.vao=null,this.vertexBuffer=null}init(e){let t=(s,a)=>{let l=e.createShader(s);return l?(e.shaderSource(l,a),e.compileShader(l),e.getShaderParameter(l,e.COMPILE_STATUS)?l:(console.warn("[WorkspaceChecker] shader:",e.getShaderInfoLog(l)),e.deleteShader(l),null)):null},r=t(e.VERTEX_SHADER,GS),o=t(e.FRAGMENT_SHADER,XS),i=e.createProgram();return!r||!o||!i?(r&&e.deleteShader(r),o&&e.deleteShader(o),!1):(e.attachShader(i,r),e.attachShader(i,o),e.linkProgram(i),e.deleteShader(r),e.deleteShader(o),e.getProgramParameter(i,e.LINK_STATUS)?(this.program=i,this.vao=e.createVertexArray(),e.bindVertexArray(this.vao),this.vertexBuffer=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer),e.bufferData(e.ARRAY_BUFFER,this.corners.byteLength,e.DYNAMIC_DRAW),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,2,e.FLOAT,!1,0,0),e.bindVertexArray(null),!0):(console.warn("[WorkspaceChecker] link:",e.getProgramInfoLog(i)),e.deleteProgram(i),!1))}draw(e,t){if(!this.program&&!this.init(e))return;let{view:r,vpt:o,left:i,top:s,width:a,height:l,zoom:u,dpr:c}=t;if(!(u>0)||!(c>0)||!(a>0)||!(l>0))return;let h=1.5/(u*c),d=i,f=s,m=i+a,p=s+l,b=this.corners;b[0]=d,b[1]=f,b[2]=m,b[3]=f,b[4]=m,b[5]=p,b[6]=d,b[7]=f,b[8]=m,b[9]=p,b[10]=d,b[11]=p;let x=this.program;e.useProgram(x),e.bindVertexArray(this.vao),e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer),e.bufferSubData(e.ARRAY_BUFFER,0,b);let g=new Float32Array([r[0],r[1],0,r[2],r[3],0,r[4],r[5],1]),y=new Float32Array([o[0],o[1],0,o[2],o[3],0,o[4],o[5],1]);e.uniformMatrix3fv(e.getUniformLocation(x,"uView"),!1,g),e.uniformMatrix3fv(e.getUniformLocation(x,"uVpt"),!1,y),e.uniform2f(e.getUniformLocation(x,"uCenter"),i+a/2,s+l/2),e.uniform2f(e.getUniformLocation(x,"uHalf"),a/2,l/2),e.uniform1f(e.getUniformLocation(x,"uAa"),h),e.uniform1f(e.getUniformLocation(x,"uTile"),HS),e.uniform3f(e.getUniformLocation(x,"uDark"),Kc[0],Kc[1],Kc[2]),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),e.drawArrays(e.TRIANGLES,0,6),e.bindVertexArray(null)}};var Qc=[243/255,243/255,243/255],zS=8,YS=.07,US=`#version 300 es
|
|
1065
1065
|
layout(location = 0) in vec2 aPos;
|
|
1066
1066
|
uniform mat3 uView;
|
|
1067
1067
|
out vec2 vScene;
|
|
1068
1068
|
void main() {
|
|
1069
1069
|
vScene = aPos;
|
|
1070
1070
|
gl_Position = vec4(uView * vec3(aPos, 1.0), 1.0);
|
|
1071
|
-
}
|
|
1071
|
+
}`,$S=`#version 300 es
|
|
1072
1072
|
precision highp float;
|
|
1073
1073
|
in vec2 vScene;
|
|
1074
1074
|
uniform vec2 uCenter;
|
|
@@ -1088,9 +1088,9 @@ float outside = smoothstep(-uAa, uAa, d);
|
|
|
1088
1088
|
float t = clamp(d / uBlur, 0.0, 1.0);
|
|
1089
1089
|
float glow = (1.0 - t) * (1.0 - t) * outside;
|
|
1090
1090
|
outColor = vec4(uMask * (1.0 - glow * uGlow), outside);
|
|
1091
|
-
}`,Ia=class{program=null;vao=null;vertexBuffer=null;corners=new Float32Array(12);invalidate(){this.program=null,this.vao=null,this.vertexBuffer=null}init(e){let t=(s,a)=>{let l=e.createShader(s);return l?(e.shaderSource(l,a),e.compileShader(l),e.getShaderParameter(l,e.COMPILE_STATUS)?l:(console.warn("[WorkspaceGlow] shader:",e.getShaderInfoLog(l)),e.deleteShader(l),null)):null},r=t(e.VERTEX_SHADER,GS),o=t(e.FRAGMENT_SHADER,XS),i=e.createProgram();return!r||!o||!i?(r&&e.deleteShader(r),o&&e.deleteShader(o),!1):(e.attachShader(i,r),e.attachShader(i,o),e.linkProgram(i),e.deleteShader(r),e.deleteShader(o),e.getProgramParameter(i,e.LINK_STATUS)?(this.program=i,this.vao=e.createVertexArray(),e.bindVertexArray(this.vao),this.vertexBuffer=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer),e.bufferData(e.ARRAY_BUFFER,this.corners.byteLength,e.DYNAMIC_DRAW),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,2,e.FLOAT,!1,0,0),e.bindVertexArray(null),!0):(console.warn("[WorkspaceGlow] link:",e.getProgramInfoLog(i)),e.deleteProgram(i),!1))}draw(e,t){if(!this.program&&!this.init(e))return;let{view:r,vpt:o,cssWidth:i,cssHeight:s,left:a,top:l,width:c,height:u,zoom:h,dpr:d}=t;if(!(h>0)||!(d>0)||!(c>0)||!(u>0))return;let f=WS/h,m=1.5/(h*d),p=ve(o),b=Q(p,0,0),x=Q(p,i,s),g=Math.min(b.x,x.x),y=Math.min(b.y,x.y),v=Math.max(b.x,x.x),S=Math.max(b.y,x.y),w=this.corners;w[0]=g,w[1]=y,w[2]=v,w[3]=y,w[4]=v,w[5]=S,w[6]=g,w[7]=y,w[8]=v,w[9]=S,w[10]=g,w[11]=S;let R=this.program;e.useProgram(R),e.bindVertexArray(this.vao),e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer),e.bufferSubData(e.ARRAY_BUFFER,0,w);let P=new Float32Array([r[0],r[1],0,r[2],r[3],0,r[4],r[5],1]);e.uniformMatrix3fv(e.getUniformLocation(R,"uView"),!1,P),e.uniform2f(e.getUniformLocation(R,"uCenter"),a+c/2,l+u/2),e.uniform2f(e.getUniformLocation(R,"uHalf"),c/2,u/2),e.uniform1f(e.getUniformLocation(R,"uBlur"),f),e.uniform1f(e.getUniformLocation(R,"uAa"),m),e.uniform3f(e.getUniformLocation(R,"uMask"),qc[0],qc[1],qc[2]),e.uniform1f(e.getUniformLocation(R,"uGlow"),HS),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),e.drawArrays(e.TRIANGLES,0,6),e.bindVertexArray(null)}};var _a=class{constructor(e){this.doc=e}doc;glow=new Ia;checker=new La;invalidate(){this.glow.invalidate(),this.checker.invalidate()}drawChecker(e,t,r){let o=this.findWorkspaceNode()?.bounds;o&&this.checker.draw(e,{view:t,vpt:r.vpt,left:o.left,top:o.top,width:o.width,height:o.height,zoom:Math.hypot(r.vpt[0],r.vpt[1]),dpr:r.dpr})}drawBackdrop(e,t,r){let o=this.findWorkspaceNode()?.bounds;o&&this.glow.draw(e,{view:t,vpt:r.vpt,cssWidth:r.cssWidth,cssHeight:r.cssHeight,left:o.left,top:o.top,width:o.width,height:o.height,zoom:Math.hypot(r.vpt[0],r.vpt[1]),dpr:r.dpr})}findWorkspaceNode(){let e=this.doc.nodes.find(t=>String(t.raw.id??"")===gn);return!e||!e.visible||!(e.bounds.width>0)||!(e.bounds.height>0)?null:e}};var zS=.02,YS=256,Kc=class n{domCanvasEl;exportStandInEl=null;get canvasEl(){return this.exportStandInEl??this.domCanvasEl}isExporting(){return this.exportStandInEl!==null}handle;batch;meshBatch;batchOrder;progressiveLoad=new la({render:()=>this.render(),nodeCount:()=>this.doc.nodes.length,alive:()=>!this.disposed&&!this.contextLost,onProgressiveDone:e=>this.bus.fire("engine:progressive-done",e)});textures;gradientRamps;glyphAtlas;renderEpoch=new Pn;bakeKReuseFloor=0;decodeAnimated=null;sources;textRenderer;renderer;exporter;workspaceBackdrop;bus=new Fn;doc=new Ro;dpr;mobileControls;interactive;vpt=[1,0,0,1,0,0];cssWidth=300;cssHeight=150;background;rafId=null;renderTimerId=null;contextLost=!1;disposed=!1;fontInvalidation;retainedFrame;chromeCache=null;interactions;interactionSuspended=!1;marquee=null;panning=!1;textEditing;tableCellEditing;snapGuide;rulerVisibleValue=!1;cropSessionController;expandSessionController;pathSessionController;warpSessionController;onWarpHistoryChange;animationPlaybackController;cellSelectionSink;constructor(e,t,r){gu(),this.domCanvasEl=e,this.domCanvasEl.style.display="block",this.handle=t,this.batch=new Zt(t.gl),this.meshBatch=new ia(t.gl),this.batchOrder=new oa(this.batch,this.meshBatch),this.batch.order=this.batchOrder,this.meshBatch.order=this.batchOrder,this.textures=new ta(t.gl,{epoch:this.renderEpoch}),this.gradientRamps=new ea(t.gl),this.glyphAtlas=new Zs(t.gl,()=>this.requestRenderAll(),o=>this.fontInvalidation.queueSettle(o),this.renderEpoch),this.dpr=r.dpr??(typeof window<"u"&&window.devicePixelRatio||1),this.mobileControls=r.mobileControls??!1,this.interactive=r.interactive??!0,this.background=r.background??[0,0,0,0],this.sources=new Pa(this),this.textRenderer=new ka(t.gl,this.batch,this.glyphAtlas),this.renderer=new Ca(this,this.sources,this.textRenderer),this.fontInvalidation=new Qs(this,this.textRenderer,this.glyphAtlas,this.renderer),this.retainedFrame=new ca(this),this.exporter=new Na(this),this.workspaceBackdrop=new _a(this.doc),this.textEditing=new qs(this),this.tableCellEditing=new Vs(this),this.snapGuide=new Ys(this,Ua),this.cropSessionController=new Fs(this),this.expandSessionController=new Os(this),this.pathSessionController=new Ws(this),this.warpSessionController=new Hs(this),this.animationPlaybackController=new js(this),this.interactions=new As(this,this.snapGuide,this.sources,this.interactive),this.cellSelectionSink=o=>{this.doc.events.fire("table:cellselection",o)},ee.cellSelectionSink=this.cellSelectionSink}static create(e,t={}){let r=null,o=Tm(e,{onLost:()=>r?.onContextLost(),onRestored:()=>r?.onContextRestored()});return o?(r=new n(e,o,t),r):null}onContextLost(){this.contextLost=!0,this.bus.fire("engine:context-lost")}onContextRestored(){this.contextLost=!1,this.recoverGlResources(),this.bus.fire("engine:context-restored"),this.requestRenderAll()}recoverGlResources(){this.retainedFrame.invalidate(),this.batch.rebuild(),this.meshBatch.rebuild(),this.textures.invalidateAll(),this.gradientRamps.invalidateAll(),this.glyphAtlas.reset(),this.sources.invalidateGlTextures(),this.renderer.invalidateGlResources(),this.workspaceBackdrop.invalidate()}invalidateNodeTextBakes(e){this.fontInvalidation.invalidateNodeTextBakes(e)}handleFontsLoaded(e){this.fontInvalidation.handleFontsLoaded(e)}get engineDisposed(){return this.disposed}get engineContextLost(){return this.contextLost}get pointerActive(){return this.interactions.pointerActive}get events(){return this.bus}get document(){return this.doc}get capabilities(){return{maxTextureSize:this.handle.capabilities.maxTextureSize,renderer:this.handle.capabilities.renderer}}get viewportTransform(){return[...this.vpt]}get zoom(){return this.vpt[0]}get gl(){return this.handle.gl}get viewSize(){return{width:this.cssWidth,height:this.cssHeight}}workspaceRect(){let e=this.doc.nodes.find(t=>String(t.raw.id??"")===gn)?.bounds;return e&&e.width>0&&e.height>0?{left:e.left,top:e.top,width:e.width,height:e.height}:{left:0,top:0,width:0,height:0}}cursorPoint(e){let t=this.canvasEl.getBoundingClientRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}get cropSession(){return this.cropSessionController.active?this.cropSessionController:null}get cropGhostNode(){return this.cropSessionController.target}get maskCropNode(){let e=this.cropSessionController.target;return e instanceof ae?e:null}get expandSession(){return this.expandSessionController.active?this.expandSessionController:null}get pathSession(){return this.pathSessionController.active?this.pathSessionController:null}get warpSession(){return this.warpSessionController.active?this.warpSessionController:null}get warpDebugSample(){return this.warpSessionController.debugBoundsSample}get warpDebugPreview(){return this.warpSessionController.debugPreviewInfo}get warpDebugAnchors(){return this.warpSessionController.debugAnchors}get warpSessionTarget(){return this.warpSessionController.target}get editingNode(){return this.doc.editingNode}get stats(){return{nodeCount:this.doc.nodes.length,skippedTypes:{...this.doc.skippedTypes}}}get diagnostics(){return{glError:this.handle.gl.getError(),drawnInstances:this.batch.drawnInstances,contextLost:this.contextLost}}get textureBudgetInfo(){return{textures:this.textures.stats(),atlas:this.glyphAtlas.stats()}}setTextureBudget(e){this.textures.setBudget(e)}toScene(e,t){return{x:(e-this.vpt[4])/this.vpt[0],y:(t-this.vpt[5])/this.vpt[3]}}toScreen(e,t){return{x:this.vpt[0]*e+this.vpt[4],y:this.vpt[3]*t+this.vpt[5]}}resize(e,t){e<=1||t<=1||(this.cssWidth=Math.max(1,e),this.cssHeight=Math.max(1,t),this.canvasEl.width=Math.round(this.cssWidth*this.dpr),this.canvasEl.height=Math.round(this.cssHeight*this.dpr),this.canvasEl.style.width=`${this.cssWidth}px`,this.canvasEl.style.height=`${this.cssHeight}px`,this.render())}progressiveFirstFrame(e=1e3,t=800){this.progressiveLoad.start(e,t)}async loadObjects(e){this.sources.releaseAnimatedSources(),this.animationPlaybackController.reset(),this.doc.loadObjects(e),await Uc(Yc([...this.doc.nodes]),this.sources,()=>this.requestRenderAll())}async ensureNodeSources(e){await Uc(Yc(e),this.sources,()=>this.requestRenderAll())}setViewportTransform(e){let t=this.vpt[0];this.vpt=[...e],this.renderer.noteVptChange(),e[0]!==t&&this.doc.setViewportZoom(e[0]),this.requestRenderAll()}zoomAt(e,t,r){let o=Math.min(YS,Math.max(zS,this.vpt[0]*r)),i=o/this.vpt[0];this.vpt=[o,0,0,o,e-i*(e-this.vpt[4]),t-i*(t-this.vpt[5])],this.renderer.noteVptChange(),this.doc.setViewportZoom(o),this.requestRenderAll()}pan(e,t){this.vpt[4]+=e,this.vpt[5]+=t,this.renderer.noteVptChange(),this.requestRenderAll()}noteExternalGesture(){this.renderer.noteExternalInteraction()}requestRenderAll(){this.progressiveLoad.absorbExternalRenderRequest(),!(this.rafId!==null||this.renderTimerId!==null||this.disposed||this.contextLost)&&(this.rafId=requestAnimationFrame(()=>{this.rafId=null,this.renderTimerId!==null&&(clearTimeout(this.renderTimerId),this.renderTimerId=null),this.render()}),this.renderTimerId=setTimeout(()=>{this.renderTimerId=null,this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.render()},250))}workspaceChromeNodes(){let e=this.doc.structureVersion;return(!this.chromeCache||this.chromeCache.version!==e)&&(this.chromeCache={version:e,nodes:this.doc.nodes.filter(er)}),this.chromeCache.nodes}render(){if(this.disposed||this.contextLost||!this.batch.valid)return;this.fontInvalidation.consumePendingSettle(),this.textures.markFrame(this.pointerActive),this.glyphAtlas.markFrame(),this.snapGuide.settleMoveSnap();let e=performance.now();this.renderer.beginFrame(e),this.tickAnimation(e),Ga("engine.render",()=>{let t=this.handle.gl;t.viewport(0,0,this.canvasEl.width,this.canvasEl.height),t.clearColor(...this.background),t.clearStencil(0),t.clear(t.COLOR_BUFFER_BIT|t.STENCIL_BUFFER_BIT);let r=qr(this.vpt,this.cssWidth,this.cssHeight,this.dpr);this.workspaceBackdrop.drawChecker(this.handle.gl,r,{vpt:this.vpt,cssWidth:this.cssWidth,cssHeight:this.cssHeight,dpr:this.dpr}),this.batch.begin(r,this.zoom*this.dpr),this.meshBatch.begin(r),this.batch.deferDraws=!0,this.meshBatch.deferDraws=!0,this.batchOrder.reset();let o=this.expandSessionController.active?this.expandSessionController.target:null;if(!(!o&&this.retainedFrame.tryRetainedFrame())){this.batch.begin(r,this.zoom*this.dpr),this.meshBatch.begin(r),this.batch.deferDraws=!0,this.meshBatch.deferDraws=!0,this.batchOrder.reset();let i=this.progressiveLoad.limit>=0?Math.min(this.progressiveLoad.limit,this.doc.nodes.length):this.doc.nodes.length;Hm(this.batch,this.renderer,this.doc.nodes,o?{target:o,underlay:()=>this.expandSessionController.buildUnderlay()}:null,i),this.batchOrder.requestSnapshot=!0,this.batchOrder.flushAll(),this.retainedFrame.captureSnapshot()}this.doc.drainRenderDirty(),this.workspaceBackdrop.drawBackdrop(this.handle.gl,r,{vpt:this.vpt,cssWidth:this.cssWidth,cssHeight:this.cssHeight,dpr:this.dpr}),Gm(this.renderer,this.workspaceChromeNodes()),Xm(this)}),this.retainedFrame.noteFrameRendered(),this.renderer.frame.bakeMore&&this.requestRenderAll(),this.bus.fire("engine:render",performance.now()-e)}readPixels(){return Fd(this.canvasEl)}exportToPixels(e){return this.retainedFrame.invalidate(),this.exporter.exportToPixels(e)}async exportToPixelsAsync(e){return this.retainedFrame.invalidate(),this.exporter.exportToPixelsAsync(e)}async exportRawPixelsAsync(e){return this.retainedFrame.invalidate(),this.exporter.exportRawPixelsAsync(e)}exportToCanvas(e){return this.retainedFrame.invalidate(),this.exporter.exportToCanvas(e)}drainGpuBacklog(){return this.exporter.drainGpuBacklog()}exportToDataURL(e,t="image/png",r){return this.retainedFrame.invalidate(),this.exporter.exportToDataURL(e,t,r)}get exportReady(){return!this.disposed&&!this.contextLost&&this.batch.valid}get sceneNodes(){return this.doc.nodes}applyExportViewport(e,t,r){let o=this.vpt,i=this.exportStandInEl;this.vpt=[...e];let s=document.createElement("canvas");return s.width=t,s.height=r,this.exportStandInEl=s,()=>{this.vpt=o,this.exportStandInEl=i}}measureFrames(e){return Dd(e,()=>this.render())}getSceneSummary(){return _d(this.doc)}getTableCellEditingInfo(){return this.tableCellEditing.info}getTableSelectionInfo(){let e=this.doc.selection.length===1&&this.doc.selection[0]instanceof ee?this.doc.selection[0]:null;return e?{tableId:e.id,cells:e.selectedCells.map(t=>({row:t.row,col:t.col})),anchor:e.cellAnchor?{...e.cellAnchor}:null,range:e.cellRange?{...e.cellRange}:null}:null}getSnapGuideInfo(){return this.snapGuide.info}enterExpandMode(e){this.cropSessionController.active&&this.cropSessionController.exit(),this.pathSessionController.active&&this.pathSessionController.exit();let t=e??this.doc.selection[0];return t?this.expandSessionController.enter(t):!1}exitExpandMode(){this.expandSessionController.exit()}getExpandInfo(){return this.expandSessionController.info}async applyExpandResult(e,t,r){let o=this.findNodeById(e);return!o||!o.isImageType&&!(o instanceof ae)?!1:this.expandSessionController.applyResult(o,t,r)}reloadImageElement(e){return this.sources.reloadNodeImage(e)}findNodeById(e){return this.doc.findNodeDeep(e)?.node??null}async reloadNodeImage(e){let t=this.findNodeById(e);return t?!!await this.sources.reloadNodeImage(t):!1}async reloadMaskClipImage(e){let t=this.findNodeById(e);return t instanceof ae?!!await this.sources.reloadMaskClipImage(t):!1}getCropInfo(){return this.cropSessionController.info}enterCropMode(e,t){this.pathSessionController.active&&this.pathSessionController.exit();let r=e??this.doc.selection[0];return r?this.cropSessionController.enter(r,t):!1}exitCropMode(){this.cropSessionController.exit()}setCropShape(e){this.cropSessionController.setCropShape(e)}updateCropScale(e){return this.cropSessionController.setScale(e)}setCropAspectRatio(e){this.cropSessionController.setAspectRatio(e)}enterPathEditMode(e){this.cropSessionController.active&&this.cropSessionController.exit(),this.expandSessionController.active&&this.expandSessionController.exit();let t=e??this.doc.selection[0];return t?this.pathSessionController.enter(t):!1}async enterWarpMode(e,t){this.cropSessionController.active&&this.cropSessionController.exit(),this.expandSessionController.active&&this.expandSessionController.exit(),this.pathSessionController.active&&this.pathSessionController.exit();let r=e??this.doc.selection[0];return r?this.warpSessionController.enter(r,t):!1}async loadImage(e,t){try{return await Je(e,t??null)}catch{return null}}async exitWarpMode(e){return this.warpSessionController.exit(e)}warpUndo(){return this.warpSessionController.undo()}warpRedo(){return this.warpSessionController.redo()}exitPathEditMode(){this.pathSessionController.exit()}getPathEditInfo(){return this.pathSessionController.info}setPathAnchorType(e,t,r){return this.pathSessionController.target===e?this.pathSessionController.setAnchorType(t,r):!1}highlightPathAnchor(e,t){this.pathSessionController.target===e&&this.pathSessionController.setActiveAnchor(t)}resetPathAnchorStyles(e){this.pathSessionController.target===e&&this.pathSessionController.resetAnchorStyles()}get rulerEnabled(){return this.rulerVisible}get rulerVisible(){return this.rulerVisibleValue}referenceLineDrag=null;rotateDrag=null;setRulerVisible(e){this.rulerVisibleValue!==e&&(this.rulerVisibleValue=e,this.requestRenderAll())}selectAll(){return Od(this.doc,()=>this.requestRenderAll())}deleteSelection(){return Bd(this.doc,()=>this.requestRenderAll())}nudgeSelection(e,t){return Wd(this.doc,e,t,()=>this.requestRenderAll())}getSelectionInfo(){return Nd(this.doc,this.marquee,this.zoom,(e,t)=>this.toScreen(e,t))}getActiveGroupChildInfo(){return Ld(this.doc)}getSvgRasterInfo(){return Id(this.doc,e=>this.sources.svgRasterFactorOf(e))}toObjects(){return this.doc.toObjects()}playAnimations(){this.animationPlaybackController.play()}pauseAnimations(){this.animationPlaybackController.pause()}stopAnimations(){this.animationPlaybackController.stop()}seekAnimations(e){this.animationPlaybackController.seek(e)}getAnimationPlaybackInfo(){return this.animationPlaybackController.info}getScrollTextPlaybackInfo(){return this.animationPlaybackController.scrollTextInfo}playSingleAnimation(e,t,r){return this.animationPlaybackController.playSingleAnimation(e,t,r)}stopSingleAnimation(e){this.animationPlaybackController.stopSingleAnimation(e)}getSingleAnimationPreviewInfo(){return this.animationPlaybackController.singlePreviewInfo}tickAnimation(e){this.animationPlaybackController.tick(e)&&(this.renderer.frame.animationActive=!0)}setEditingSelection(e,t){this.textEditing.setSelection(e,t)}settleMoveSnap(){this.snapGuide.settleMoveSnap()}finishSnapGesture(){this.snapGuide.finishGesture()}registerScalingSnap(e,t){this.snapGuide.registerScaling(e,t)}startCellEditing(e,t,r,o){return this.tableCellEditing.startEditing(e,t,r,o)}enterTextEditingAtClick(e,t,r){this.textEditing.enterEditingAtClick(e,t,r)}dispose(){this.disposed||(this.disposed=!0,this.cellSelectionSink&&ee.cellSelectionSink===this.cellSelectionSink&&(ee.cellSelectionSink=null),this.rafId!==null&&cancelAnimationFrame(this.rafId),this.renderTimerId!==null&&clearTimeout(this.renderTimerId),this.retainedFrame.dispose(),this.progressiveLoad.dispose(),this.interactions.dispose(),this.tableCellEditing.dispose(),this.cropSessionController.dispose(),this.expandSessionController.dispose(),this.pathSessionController.dispose(),this.textEditing.dispose(),this.bus.clear(),this.sources.releaseAnimatedSources(),this.batch.dispose(),this.meshBatch.dispose(),this.textures.dispose(),this.gradientRamps.dispose(),this.sources.dispose(),this.glyphAtlas.dispose(),this.handle.dispose())}};var Jt=class n{constructor(e=0,t=0){this.x=e;this.y=t}x;y;add(e){return new n(this.x+e.x,this.y+e.y)}subtract(e){return new n(this.x-e.x,this.y-e.y)}scalarDivide(e){return new n(this.x/e,this.y/e)}rotate(e,t={x:0,y:0}){let r=Math.sin(e),o=Math.cos(e),i=this.subtract(t);return new n(i.x*o-i.y*r,i.x*r+i.y*o).add(t)}},Qc=class n{constructor(e=0,t=0){typeof e=="number"?(this.x=e,this.y=t):(this.x=e.x,this.y=e.y)}x=0;y=0;add(e){return new n(this.x+e.x,this.y+e.y)}subtract(e){return new n(this.x-e.x,this.y-e.y)}multiply(e){return new n(this.x*e.x,this.y*e.y)}divide(e){return new n(this.x/e.x,this.y/e.y)}scalarAdd(e){return new n(this.x+e,this.y+e)}scalarSubtract(e){return new n(this.x-e,this.y-e)}scalarMultiply(e){return new n(this.x*e,this.y*e)}scalarDivide(e){return new n(this.x/e,this.y/e)}rotate(e){let t=e*Math.PI/180,r=Math.cos(t),o=Math.sin(t);return new n(this.x*r-this.y*o,this.x*o+this.y*r)}dot(e){return this.x*e.x+this.y*e.y}midPointFrom(e){return new n((this.x+e.x)/2,(this.y+e.y)/2)}static lerp(e,t,r){return new n(e.x+(t.x-e.x)*r,e.y+(t.y-e.y)*r)}lerp(e,t){return new n(this.x+(e.x-this.x)*t,this.y+(e.y-this.y)*t)}eq(e){return this.x===e.x&&this.y===e.y}lt(e){return this.x<e.x&&this.y<e.y}gt(e){return this.x>e.x&&this.y>e.y}lte(e){return this.x<=e.x&&this.y<=e.y}gte(e){return this.x>=e.x&&this.y>=e.y}distanceFrom(e){return Math.hypot(this.x-e.x,this.y-e.y)}clone(){return new n(this.x,this.y)}toString(){return`${this.x} ${this.y}`}transform(e,t=!1){return t?new n(e[0]*this.x+e[2]*this.y,e[1]*this.x+e[3]*this.y):new n(e[0]*this.x+e[2]*this.y+e[4],e[1]*this.x+e[3]*this.y+e[5])}};var en=(n,e=0)=>typeof n=="number"&&Number.isFinite(n)?n:e,US=n=>({sx:en(n.scaleX,1)||1,sy:en(n.scaleY,1)||1}),kp=n=>{let e=n.pathOffset;return!e||typeof e.x!="number"||typeof e.y!="number"?null:{x:e.x,y:e.y}},$S=n=>{let e=Ce(n),t=e?Fe(e):null;return t?{x:(t.left+t.right)/2,y:(t.top+t.bottom)/2}:null},jS=n=>{if(n.length===0)return null;let e=1/0,t=1/0,r=-1/0,o=-1/0;for(let i of n)e>i.x&&(e=i.x),t>i.y&&(t=i.y),r<i.x&&(r=i.x),o<i.y&&(o=i.y);return{x:(e+r)/2,y:(t+o)/2}},VS=(n,e,t,r)=>`M ${t} 0 L ${n-t} 0 A ${t} ${r} 0 0 1 ${n} ${r} L ${n} ${e-r} A ${t} ${r} 0 0 1 ${n-t} ${e} L ${t} ${e} A ${t} ${r} 0 0 1 0 ${e-r} L 0 ${r} A ${t} ${r} 0 0 1 ${t} 0 Z`,Ap=(n,e)=>`M 0 ${-e} A ${n} ${e} 0 1 1 0 ${e} A ${n} ${e} 0 1 1 0 ${-e} Z`,Zc=n=>{if(n.isTextType)return;let e=n.raw,t=se(e),{sx:r,sy:o}=US(e);if(t===L.PATH){let a="";if(typeof e.path=="string")a=e.path;else if(Array.isArray(e.path)){let l=[];for(let c of e.path)!Array.isArray(c)||typeof c[0]!="string"||l.push(c.length===1?c[0]:`${c[0]} ${c.slice(1).join(" ")}`);a=l.join(" ")}return a.trim()?{path:a,pathOffset:kp(e)??$S(a)??{x:0,y:0}}:void 0}if(t===L.RECT||t===L.FABRICRECT){let a=n.dims.x*r,l=n.dims.y*o;if(!(a>0)||!(l>0))return;let c=it(e,n.dims.x,n.dims.y),u=c?Math.min(c.rx*r,a/2):0,h=c?Math.min(c.ry*o,l/2):0;return{path:u>0||h>0?VS(a,l,u,h):`M 0 0 L ${a} 0 L ${a} ${l} L 0 ${l} Z`,pathOffset:{x:a/2,y:l/2}}}if(t===L.CIRCLE){let a=en(e.radius);return a>0?{path:Ap(a*r,a*o),pathOffset:{x:0,y:0}}:void 0}if(t===L.ELLIPSE){let a=(en(e.rx)||n.dims.x/2)*r,l=(en(e.ry)||n.dims.y/2)*o;return!(a>0)||!(l>0)?void 0:{path:Ap(a,l),pathOffset:{x:0,y:0}}}if(t===L.TRIANGLE){let a=n.dims.x*r,l=n.dims.y*o;return!(a>0)||!(l>0)?void 0:{path:`M ${-a/2} ${l/2} L 0 ${-l/2} L ${a/2} ${l/2} Z`,pathOffset:{x:0,y:0}}}if(t===L.POLYGON||t===L.POLYLINE){let a=Array.isArray(e.points)?e.points:[];return a.length===0?{path:"M 0 0",pathOffset:{x:0,y:0}}:{path:a.map((c,u)=>`${u===0?"M":"L"} ${c.x} ${c.y}`).join(" ")+(t===L.POLYGON?" Z":""),pathOffset:kp(e)??jS(a)??{x:0,y:0}}}if(t===L.LINE){let a=en(e.x1),l=en(e.y1),c=en(e.x2),u=en(e.y2);return{path:`M ${a} ${l} L ${c} ${u}`,pathOffset:{x:0,y:0}}}let i=n.dims.x*r,s=n.dims.y*o;if(!(!(i>0)||!(s>0)))return{path:`M 0 0 L ${i} 0 L ${i} ${s} L 0 ${s} Z`,pathOffset:{x:i/2,y:s/2}}};var Np=n=>{if(!(!n||n.length<8||n.some(e=>typeof e!="number"||!Number.isFinite(e))))return{tl:{x:n[0],y:n[1]},tr:{x:n[2],y:n[3]},br:{x:n[4],y:n[5]},bl:{x:n[6],y:n[7]}}},Lp=n=>{let e=[n.tl,n.tr,n.br,n.bl],t=Math.min(...e.map(s=>s.x)),r=Math.min(...e.map(s=>s.y)),o=Math.max(...e.map(s=>s.x)),i=Math.max(...e.map(s=>s.y));return{minX:t,minY:r,width:Math.max(1,Math.ceil(o-t)),height:Math.max(1,Math.ceil(i-r))}},Ip=(n,e,t)=>({tl:{x:n.tl.x+e,y:n.tl.y+t},tr:{x:n.tr.x+e,y:n.tr.y+t},br:{x:n.br.x+e,y:n.br.y+t},bl:{x:n.bl.x+e,y:n.bl.y+t}}),_p=n=>{let e=n.tr.x+n.bl.x-n.tl.x,t=n.tr.y+n.bl.y-n.tl.y;return Math.abs(e-n.br.x)<.01&&Math.abs(t-n.br.y)<.01},Jc=n=>{let e=n.tl.x-n.tr.x+n.br.x-n.bl.x,t=n.tl.y-n.tr.y+n.br.y-n.bl.y;if(Math.abs(e)<1e-6&&Math.abs(t)<1e-6)return{a:n.tr.x-n.tl.x,b:n.bl.x-n.tl.x,c:n.tl.x,d:n.tr.y-n.tl.y,e:n.bl.y-n.tl.y,f:n.tl.y,g:0,h:0};let r=n.tr.x-n.br.x,o=n.tr.y-n.br.y,i=n.bl.x-n.br.x,s=n.bl.y-n.br.y,a=r*s-i*o;if(Math.abs(a)<1e-6)return;let l=(e*s-i*t)/a,c=(r*t-e*o)/a;return{a:n.tr.x-n.tl.x+l*n.tr.x,b:n.bl.x-n.tl.x+c*n.bl.x,c:n.tl.x,d:n.tr.y-n.tl.y+l*n.tr.y,e:n.bl.y-n.tl.y+c*n.bl.y,f:n.tl.y,g:l,h:c}},$r=(n,e,t)=>{let r=n.g*e+n.h*t+1;return{x:(n.a*e+n.b*t+n.c)/r,y:(n.d*e+n.e*t+n.f)/r}},Dp=n=>{let{a:e,b:t,c:r,d:o,e:i,f:s,g:a,h:l}=n,c=e*(i-s*l)-t*(o-s*a)+r*(o*l-i*a);if(Math.abs(c)<1e-6)return;let u=(i-s*l)/c,h=(r*l-t)/c,d=(t*s-r*i)/c,f=(s*a-o)/c,m=(e-r*a)/c,p=(r*o-e*s)/c,b=(o*l-i*a)/c,x=(t*a-e*l)/c,g=(e*i-t*o)/c;if(!(Math.abs(g)<1e-6))return{a:u/g,b:h/g,c:d/g,d:f/g,e:m/g,f:p/g,g:b/g,h:x/g}};var Fp=32,Op=120,eu=1e-6,qS=()=>{let n=document.createElement("canvas");if(!n||typeof n.getContext>"u")throw new Error("Failed to create `canvas` element");return n},KS=n=>{let e=qS();return e.width=n.width,e.height=n.height,e.getContext("2d",{willReadFrequently:!0})?.drawImage(n,0,0),e},QS=(n,e,t)=>n.toDataURL?.(`image/${e}`,t),ZS=n=>new Promise((e,t)=>{let r=new FileReader;r.onload=()=>e(String(r.result)),r.onerror=()=>t(r.error),r.readAsDataURL(n)}),Bp=async(n,e,t)=>{try{let r=await new Promise(o=>n.toBlob(o,`image/${e}`,t));if(r)return await ZS(r)}catch{}return QS(n,e,t)},JS=(n,e,t)=>{let r=Math.max(1,n.width),o=Math.max(1,n.height),i=Math.max(1,Math.round(e)),s=Math.max(1,Math.round(t));if(Math.abs(r-i)<eu&&Math.abs(o-s)<eu)return n;let a=document.createElement("canvas");a.width=i,a.height=s;let l=a.getContext("2d");return l?(l.imageSmoothingEnabled=!0,l.imageSmoothingQuality="high",l.drawImage(n,0,0,r,o,0,0,i,s),a):n},ev=(n,e,t,r,o)=>{let i=Math.max(0,Math.min(e-1,r)),s=Math.max(0,Math.min(t-1,o)),a=Math.floor(i),l=Math.floor(s),c=Math.min(e-1,a+1),u=Math.min(t-1,l+1),h=i-a,d=s-l,f=(l*e+a)*4,m=(l*e+c)*4,p=(u*e+a)*4,b=(u*e+c)*4,x=1-d,g=1-h,y=g*x,v=h*x,S=g*d,w=h*d;return[n[f]*y+n[m]*v+n[p]*S+n[b]*w,n[f+1]*y+n[m+1]*v+n[p+1]*S+n[b+1]*w,n[f+2]*y+n[m+2]*v+n[p+2]*S+n[b+2]*w,n[f+3]*y+n[m+3]*v+n[p+3]*S+n[b+3]*w]},tv=(n,e,t)=>{let r=Jc(t),o=r?Dp(r):void 0;if(!o){Hp(n,e,t,Fp);return}let i=Math.max(1,e.width),s=Math.max(1,e.height),a=e.getContext("2d",{willReadFrequently:!0});if(!a){Hp(n,e,t,Fp);return}let l=a.getImageData(0,0,i,s),c=n.createImageData(n.canvas.width,n.canvas.height),u=c.data;for(let h=0;h<n.canvas.height;h++)for(let d=0;d<n.canvas.width;d++){let f=$r(o,d+.5,h+.5);if(f.x<0||f.x>1||f.y<0||f.y>1)continue;let m=f.x*(i-1),p=f.y*(s-1),b=ev(l.data,i,s,m,p),x=(h*n.canvas.width+d)*4;u[x]=b[0],u[x+1]=b[1],u[x+2]=b[2],u[x+3]=b[3]}n.putImageData(c,0,0)},Wp=(n,e,t,r)=>{let[o,i,s]=t,[a,l,c]=r,u=o.x*(i.y-s.y)+i.x*(s.y-o.y)+s.x*(o.y-i.y);if(Math.abs(u)<eu)return;let h=(a.x*(i.y-s.y)+l.x*(s.y-o.y)+c.x*(o.y-i.y))/u,d=(a.y*(i.y-s.y)+l.y*(s.y-o.y)+c.y*(o.y-i.y))/u,f=(a.x*(s.x-i.x)+l.x*(o.x-s.x)+c.x*(i.x-o.x))/u,m=(a.y*(s.x-i.x)+l.y*(o.x-s.x)+c.y*(i.x-o.x))/u,p=(a.x*(i.x*s.y-s.x*i.y)+l.x*(s.x*o.y-o.x*s.y)+c.x*(o.x*i.y-i.x*o.y))/u,b=(a.y*(i.x*s.y-s.x*i.y)+l.y*(s.x*o.y-o.x*s.y)+c.y*(o.x*i.y-i.x*o.y))/u;n.save(),n.beginPath(),n.moveTo(a.x,a.y),n.lineTo(l.x,l.y),n.lineTo(c.x,c.y),n.closePath(),n.clip(),n.setTransform(h,d,f,m,p,b),n.drawImage(e,0,0),n.restore()},Hp=(n,e,t,r)=>{let o=Jc(t);if(!o){n.drawImage(e,0,0,n.canvas.width,n.canvas.height);return}let i=Math.max(1,e.width),s=Math.max(1,e.height),a=Math.min(Op,Math.max(1,Math.ceil(i/r))),l=Math.min(Op,Math.max(1,Math.ceil(s/r)));for(let c=0;c<l;c++){let u=c/l,h=(c+1)/l,d=u*s,f=h*s;for(let m=0;m<a;m++){let p=m/a,b=(m+1)/a,x=p*i,g=b*i,y=$r(o,p,u),v=$r(o,b,u),S=$r(o,b,h),w=$r(o,p,h);Wp(n,e,[{x,y:d},{x:g,y:d},{x:g,y:f}],[y,v,S]),Wp(n,e,[{x,y:d},{x:g,y:f},{x,y:f}],[y,S,w])}}},nv=async(n,e,t={})=>{let r=t.quality??.92,o=t.format||"webp",i=Math.max(1,n.width),s=Math.max(1,n.height),a=Math.max(1,e?.width||i),l=Math.max(1,e?.height||s),c=JS(n,a,l),u=Np(e?.nonAffineTransform||e?.transform);if(!u){let x=KS(n);return{src:await Bp(x,o,r),width:i,height:s,sourceWidth:a,sourceHeight:l}}let h=Lp(u),d=Ip(u,-h.minX,-h.minY),f=t.objectBounds,m=document.createElement("canvas");m.width=h.width,m.height=h.height;let p=m.getContext("2d");if(!p)throw new Error("无法创建智能对象渲染画布");if(p.imageSmoothingEnabled=!0,p.imageSmoothingQuality="high",_p(d)){let x=(d.tr.x-d.tl.x)/a,g=(d.tr.y-d.tl.y)/a,y=(d.bl.x-d.tl.x)/l,v=(d.bl.y-d.tl.y)/l,S=d.tl.x,w=d.tl.y;p.setTransform(x,g,y,v,S,w),p.drawImage(c,0,0)}else tv(p,c,d);let b;if(f){let x=Math.round(f.left-h.minX),g=Math.round(f.top-h.minY),y=Math.max(1,Math.round(f.width)),v=Math.max(1,Math.round(f.height));if(x>=0&&g>=0&&x+y<=h.width+1&&g+v<=h.height+1){b=document.createElement("canvas"),b.width=y,b.height=v;let w=b.getContext("2d");w&&w.drawImage(m,x,g,y,v,0,0,y,v)}else{b=document.createElement("canvas"),b.width=y,b.height=v;let w=b.getContext("2d");w&&(w.imageSmoothingEnabled=!0,w.imageSmoothingQuality="high",w.drawImage(m,0,0,h.width,h.height,0,0,y,v))}}else b=m;return{src:await Bp(b,o,r),width:b.width,height:b.height,sourceWidth:a,sourceHeight:l}};var ce=n=>n.node instanceof ee?n.node:null,Be=n=>n.raw,Pt=n=>{n.canvas?.requestRenderAll?.()},je=(n,e)=>{let t=Be(e);n.set({cellData:t.cellData??[],rows:t.rows,cols:t.cols}),Pt(n)},tu=n=>n.rows??3,nu=n=>n.cols??3,jr=n=>(Array.isArray(n.cellData)||(n.cellData=[]),n.cellData),Jo=(n,e,t)=>{let r=we(n.cellMap,e,t);if(r)return r.isMerged&&r.mergeParent?we(n.cellMap,r.mergeParent.row,r.mergeParent.col):r},Wt=(n,e)=>{let t=ce(n);if(!t||!t.selectedCells.length)return;let r=new Set;for(let o of t.selectedCells){let i=lt(t.cellMap,o.row,o.col),s=`${i.row},${i.col}`;if(r.has(s))continue;r.add(s);let a=we(t.cellMap,i.row,i.col);a&&e(a)}je(n,t)},ru=(n,e,t)=>({get id(){return`${n.id}-r${e.row}c${e.col}-rect`},get _isCell(){return!0},get _row(){return e.row},get _col(){return e.col},get fill(){return e.fill},set fill(r){e.fill=r,t()},get stroke(){return e.stroke},set stroke(r){e.stroke=r,t()},get strokeWidth(){return e.strokeWidth??1},set strokeWidth(r){e.strokeWidth=r,t()},get _colspan(){return e.colspan??1},set _colspan(r){e.colspan=r,t()},get _rowspan(){return e.rowspan??1},set _rowspan(r){e.rowspan=r,t()},get _isMerged(){return e.isMerged??!1},set _isMerged(r){e.isMerged=r,t()},get _mergeParent(){return e.mergeParent??null},set _mergeParent(r){e.mergeParent=r,t()},get _hasCustomFill(){return e.hasCustomFill??!1},set _hasCustomFill(r){e.hasCustomFill=r,t()},get _hasCustomStroke(){return e.hasCustomStroke??!1},set _hasCustomStroke(r){e.hasCustomStroke=r,t()},set(r){for(let[o,i]of Object.entries(r))o!=="dirty"&&(e[o]=i);t()},get(r){return e[r]}}),Gp=(n,e,t)=>({get id(){return`${n.id}-r${e.row}c${e.col}-text`},get _isCellText(){return!0},get _row(){return e.row},get _col(){return e.col},get text(){return e.text??""},set text(r){e.text=r,t()},get fill(){return e.textFill},set fill(r){e.textFill=r,t()},get fontSize(){return e.fontSize??Be(n).fontSize??14},set fontSize(r){e.fontSize=r,t()},get fontWeight(){return e.fontWeight},set fontWeight(r){e.fontWeight=r,t()},get fontFamily(){return e.fontFamily},set fontFamily(r){e.fontFamily=r,t()},get fontStyle(){return e.fontStyle},set fontStyle(r){e.fontStyle=r,t()},get textAlign(){return e.textAlign},set textAlign(r){e.textAlign=r,t()},get underline(){return e.underline??!1},set underline(r){e.underline=r,t()},get linethrough(){return e.linethrough??!1},set linethrough(r){e.linethrough=r,t()},get verticalAlign(){return e.verticalAlign??"middle"},set verticalAlign(r){e.verticalAlign=r,t()},set(r){for(let[o,i]of Object.entries(r))o!=="dirty"&&(o==="fill"?e.textFill=i:e[o]=i);t()},get(r){return r==="fill"?e.textFill:e[r]},setFontFamily(r){e.fontFamily=r,t()},refreshTextDimensions(){}}),rv={canMergeCells(){let n=ce(this);return!!n&&n.selectedCells.length>1},canUseMergeCells(){let n=ce(this);if(!n||!n.selectedCells.length)return!1;let e=new Set,t=!1;for(let{row:r,col:o}of n.selectedCells){let i=Jo(n,r,o);if(!i)return!1;(i.colspan??1)>1||(i.rowspan??1)>1?e.add(`${i.row},${i.col}`):t=!0}return!t&&e.size===1},canSplitRows(){let n=ce(this);if(!n||!n.selectedCells.length)return!1;let e=n.selectedCells[0],t=Jo(n,e.row,e.col);return!!t&&(t.rowspan??1)>1},canSplitColumns(){let n=ce(this);if(!n||!n.selectedCells.length)return!1;let e=n.selectedCells[0],t=Jo(n,e.row,e.col);return!!t&&(t.colspan??1)>1},isSelectColumn(){let n=ce(this);if(!n||!n.selectedCells.length)return!1;let e=new Set(n.selectedCells.map(r=>r.row)),t=new Set(n.selectedCells.map(r=>r.col));if(t.size===1){let r=Array.from(e),o=Math.min(...r),i=Math.max(...r),s=o===0&&i===tu(Be(n))-1,a=e.size>=2,l=!1;for(let c of n.selectedCells)if((Jo(n,c.row,c.col)?.rowspan??1)>1){l=!0;break}return s||a||l}return t.size>1?e.size===1?!1:e.size<=t.size:!1},isSelectRow(){let n=ce(this);if(!n||!n.selectedCells.length)return!1;let e=new Set(n.selectedCells.map(r=>r.row)),t=new Set(n.selectedCells.map(r=>r.col));if(e.size===1){let r=Array.from(t),o=Math.min(...r),i=Math.max(...r),s=o===0&&i===nu(Be(n))-1,a=t.size>=2,l=!1;for(let c of n.selectedCells)if((Jo(n,c.row,c.col)?.colspan??1)>1){l=!0;break}return s||a||l}return e.size>1?t.size===1?!1:e.size>t.size:!1},isRowSelected(n){let e=ce(this);return e?Rr(e.cellMap,e.selectedCells).rows.has(n):!1},isColumnSelected(n){let e=ce(this);return e?Rr(e.cellMap,e.selectedCells).cols.has(n):!1},selectCell(n,e,t=!1){let r=ce(this);if(r){if(t){if(r.cellAnchor){let o=r.cellAnchor,i=bn(r.cellMap,o,{row:n,col:e});r.setCellSelection(i,o,{r1:Math.min(o.row,n),r2:Math.max(o.row,n),c1:Math.min(o.col,e),c2:Math.max(o.col,e)})}}else{let o={row:n,col:e};r.setCellSelection([o],o,{r1:n,r2:n,c1:e,c2:e})}Pt(this)}},selectColumn(n){let e=ce(this);e&&(e.setColumnSelection(n),Pt(this))},selectRow(n){let e=ce(this);e&&(e.setRowSelection(n),Pt(this))},selectAllCells(){let n=ce(this);if(!n)return;let e=n.tableView,t=wo(n.cellMap,e.rows,e.cols);n.setCellSelection(t,t[0]??null,Xe(t)),Pt(this)},clearCellSelection(){let n=ce(this);n&&(n.clearCellSelection(),Pt(this))},buildSelectionRange(n,e){let t=ce(this);return t?bn(t.cellMap,n,e):[]},mergeCells(n,e,t,r){let o=ce(this);if(!o)return;let i=bo(o.raw,n,e,t,r),s={row:i.r1,col:i.c1};o.setCellSelection([s],s,i),je(this,o)},unmergeCells(n,e){let t=ce(this);if(!t||!xo(t.raw,n,e))return;let r={row:n,col:e};t.setCellSelection([r],r,{r1:n,r2:n,c1:e,c2:e}),je(this,t)},addRow(n){let e=ce(this);e&&(go(e.raw,n??tu(Be(e))),je(this,e))},removeRow(n){let e=ce(this);if(!e)return;let t=n??tu(Be(e))-1;if(!Ml(e.raw,t))return;let r=Yi(e.selectedCells,e.cellRange,t,"row");r?e.setCellSelection(r.cells,r.cells[0]??null,r.range):e.clearCellSelection(),je(this,e)},addColumn(n){let e=ce(this);e&&(yo(e.raw,n??nu(Be(e))),je(this,e))},removeColumn(n){let e=ce(this);if(!e)return;let t=n??nu(Be(e))-1;if(!Rl(e.raw,t))return;let r=Yi(e.selectedCells,e.cellRange,t,"col");r?e.setCellSelection(r.cells,r.cells[0]??null,r.range):e.clearCellSelection(),je(this,e)},setColumnWidth(n,e){let t=ce(this);t&&(mo(t.raw,n,e),this.set({columnWidths:Be(t).columnWidths??[]}),Pt(this))},setRowHeight(n,e){let t=ce(this);t&&(po(t.raw,n,e),this.set({manualRowHeights:Be(t).manualRowHeights??[]}),Pt(this))},setSelectWidth(n){let e=ce(this);if(!e)return;let t=e.cellRange,r=Be(e),o=e.tableView;if(!t||o.cols<=0){this.setTableWidth(n);return}let i=r.minCellWidth??40,s=r.cellStrokeWidth??0,a=0;for(let u=t.c1;u<=t.c2;u++)a+=o.columnWidths[u]??0;if(a<=0)return;let l=(n-s-(t.c2-t.c1)*o.cellSpacing)/a,c=[...o.columnWidths];for(let u=t.c1;u<=t.c2;u++)c[u]=Math.max(i,(c[u]??0)*l);this.set({columnWidths:c}),Pt(this)},setSelectHeight(n){let e=ce(this);if(!e)return;let t=e.cellRange,r=Be(e),o=e.tableView;if(!t||o.rows<=0){this.setTableHeight(n);return}let i=r.minCellHeight??40,s=r.cellStrokeWidth??0,a=0;for(let u=t.r1;u<=t.r2;u++)a+=o.rowHeights[u]??0;if(a<=0)return;let l=(n-s-(t.r2-t.r1)*o.cellSpacing)/a,c=Array.from({length:o.rows},(u,h)=>{let d=Array.isArray(r.manualRowHeights)?r.manualRowHeights[h]:null;return typeof d=="number"?d:null});for(let u=t.r1;u<=t.r2;u++)c[u]=Math.max(i,(o.rowHeights[u]??0)*l);this.set({manualRowHeights:c}),Pt(this)},getColumnWidth(n){let e=ce(this);return e?e.tableView.columnWidths[n]??0:0},getRowHeight(n){let e=ce(this);return e?e.tableView.rowHeights[n]??0:0},getRowMinHeight(n){let e=ce(this);return e?e.getRowMinHeight(n):0},relayout(){let n=ce(this);n&&(n.rebuildTable(),Pt(this))},previewLayout(){this.relayout()},getCell(n,e){let t=ce(this);if(!t)return;let r=we(t.cellMap,n,e);return r?ru(t,r,()=>je(this,t)):void 0},getCellText(n,e){let t=ce(this);if(!t)return;let r=we(t.cellMap,n,e);return r?Gp(t,r,()=>je(this,t)):void 0},setSelectionTextAlign(n){Wt(this,e=>{e.textAlign=n})},setSelectionFontSize(n){Wt(this,e=>{e.fontSize=n})},changeSelectionFontSize(n){let e=ce(this);if(!e)return;let t=Be(e).fontSize??14;Wt(this,r=>{let o=Number(r.fontSize)||t;r.fontSize=n==="+"?o+1:Math.max(1,o-1)})},setSelectionFontWeight(n){Wt(this,e=>{e.fontWeight=n})},setSelectionFontStyle(n){Wt(this,e=>{e.fontStyle=n})},setSelectionUnderline(n){Wt(this,e=>{e.underline=n})},setSelectionLinethrough(n){Wt(this,e=>{e.linethrough=n})},setSelectionCellFill(n){Wt(this,e=>{e.fill=n,e.hasCustomFill=!0})},setSelectionCellStroke(n){Wt(this,e=>{e.stroke=n,e.hasCustomStroke=!0})},setSelectionCellStrokeWidth(n){Wt(this,e=>{e.strokeWidth=n,e.hasCustomStroke=!0})},updateCellFill(n){let e=ce(this);if(!e)return;let t=Be(e);t.cellFill=n;for(let r of jr(t))!r.isMerged&&!r.hasCustomFill&&(r.fill=n);je(this,e)},updateCellTextFill(n){let e=ce(this);if(!e)return;let t=Be(e);t.textFill=n;for(let r of jr(t))r.hasCustomTextFill||(r.textFill=n);je(this,e)},updateCellStroke(n){let e=ce(this);if(!e)return;let t=Be(e);t.cellStroke=n;for(let r of jr(t))r.hasCustomStroke||(r.stroke=n);je(this,e)},updateBorderWidth(n){let e=ce(this);e&&(Be(e).cellStrokeWidth=n,je(this,e))},applyTextStylesToAll(n){let e=ce(this);if(!e)return;let t=Be(e),r={...t.textDefaults??{}};for(let[o,i]of Object.entries(n))r[o]=i;t.textDefaults=r;for(let o of jr(t))for(let[i,s]of Object.entries(n))i==="fill"?o.textFill=s:o[i]=s;je(this,e)}},ov={selectedCells(){let n=ce(this);if(n)return n.selectedCells.map(e=>{let t=we(n.cellMap,e.row,e.col);return t?ru(n,t,()=>je(this,n)):void 0}).filter(e=>e!==void 0)},_selectedCells(){let n=ce(this);return n?n.selectedCells:void 0},_selectionRange(){let n=ce(this);return n?n.cellRange:void 0},hasSelection(){let n=ce(this);return n?n.hasCellSelection:!1},selectionCount(){let n=ce(this);return n?n.selectedCells.length:0},cellTexts(){let n=ce(this);if(!n)return;let e=()=>je(this,n);return jr(Be(n)).map(t=>Gp(n,t,e))},cells(){let n=ce(this);if(!n)return;let e=()=>je(this,n);return jr(Be(n)).map(t=>ru(n,t,e))},columnWidths(){let n=ce(this);return n?[...n.tableView.columnWidths]:void 0},rowHeights(){let n=ce(this);return n?[...n.tableView.rowHeights]:void 0}},ou=n=>{for(let[e,t]of Object.entries(rv))Object.assign(n,{[e]:t});for(let[e,t]of Object.entries(ov))Object.defineProperty(n,e,{get:t,configurable:!0,enumerable:!1})};var iu=(n,e,t)=>{let r=Ge(e);if(!r)return null;let o=Et(n,e,t),i=r==="circle"||(typeof e.curvature=="number"?e.curvature:300)>0,s=o.contentOffsetX-o.width/2,a=o.contentOffsetX+o.width/2,l=o.contentOffsetY-o.height/2,c=o.contentOffsetY+o.height/2,u=n.lines.map(()=>[]);for(let h of o.chars){let d=u[h.line];if(!d)continue;let f={char:h.char,charAngle:i?-h.rotation:-(h.rotation+Math.PI),leftAngle:0,rightAngle:0,charRadius:0,bottomRadius:0,topRadius:0,lineRadius:0,cl:{x:h.x,y:h.y},tl:{x:s,y:l},br:{x:a,y:c},bl:{x:h.x,y:h.y},tr:{x:h.x,y:h.y},nl:{x:h.x,y:h.y},nr:{x:h.x,y:h.y},lc:{x:h.x,y:h.y}};d.push(f)}for(let h of u){let d=h[h.length-1];h.push({char:"",charAngle:0,leftAngle:0,rightAngle:0,charRadius:0,bottomRadius:0,topRadius:0,lineRadius:0,cl:d?{...d.cl}:{x:s,y:l},tl:{x:s,y:l},br:{x:a,y:c},bl:{x:s,y:l},tr:{x:a,y:c},nl:{x:s,y:l},nr:{x:a,y:c},lc:{x:s,y:l}})}return u};var iv=n=>{let e=n.textLines,t=n.charBounds,r=n.lineHeights;if(!Array.isArray(e)||!Array.isArray(t)||!Array.isArray(r)||e.length===0||t.length!==e.length||r.length!==e.length)return!1;for(let o=0;o<e.length;o++)if(typeof e[o]!="string"||!Array.isArray(t[o])||t[o].length===0||typeof r[o]!="number"||!Number.isFinite(r[o]))return!1;return!0},cr=class{node;ctx;constructor(e,t){this.node=e,this.ctx=t}set(e,t){let r=typeof e=="string"?{[e]:t}:{...e},o=r.__isCropping&&this.ctx.cropSessionNodeId?.()!==this.node.id?this.toObject():void 0;if("cropAspectRatio"in r){let s={cropAspectRatio:r.cropAspectRatio};delete r.cropAspectRatio,this.ctx.setNodeProps(this.node,s)}if("_cropKey"in r){let s=r._cropKey;delete r._cropKey,this.ctx.applyCropShape?.(this.node,typeof s=="string"&&s?s:null)}if("__isCropping"in r){let s=!!r.__isCropping;delete r.__isCropping,this.clearSessionFlagDirty("__isCropping"),this.__isCropping=s,o&&this.__isCropping&&(this.cropBeforeState=o)}if("__isExpand"in r){let s=!!r.__isExpand;delete r.__isExpand,this.clearSessionFlagDirty("__isExpand"),this.__isExpand=s}if(typeof r.width=="number"&&Dr(this.node)){let s=r.width;delete r.width,this.ctx.setGroupWidth?this.ctx.setGroupWidth(this.node,s):this.ctx.setNodeProps(this.node,{width:s})}this.bumpTextboxWidthToLayoutBox(r),this.bridgeImageSizeProps(r);let i=r;if((typeof r.width=="number"||typeof r.height=="number"||typeof r.scaleX=="number"||typeof r.scaleY=="number")&&!("clipImage"in r)&&ot.has(se(this.node.raw))){let s=Ht(this.node),a=this.node.raw,l=Number(a.width)||0,c=Number(a.height)||0,u=this.node.clipImageEl,h=u?.naturalWidth||Number(s?.width)||0,d=u?.naturalHeight||Number(s?.height)||0;if(s&&l>0&&c>0&&h>0&&d>0){typeof r.scaleX=="number"&&r.scaleX>0&&!("width"in r)&&(r.width=l*r.scaleX,r.scaleX=1),typeof r.scaleY=="number"&&r.scaleY>0&&!("height"in r)&&(r.height=c*r.scaleY,r.scaleY=1);let f=typeof r.width=="number"?r.width:l,m=typeof r.height=="number"?r.height:c;if(f>0&&m>0){let p=(g,y)=>Math.max(g/h,y/d),b=Number(s.scaleX)||1,x=p(f,m)*(b/p(l,c));i={...r,clipImage:{...s,scaleX:x,scaleY:x}}}}}return Object.keys(i).length>0&&this.ctx.setNodeProps(this.node,i),this}bumpTextboxWidthToLayoutBox(e){if(typeof e.width!="number"||!(this.node instanceof Se)||e.width<0||se(this.node.raw)!==L.TEXTBOX||Ge(this.node.raw))return;let r=e.width;delete e.width,this.ctx.setNodeProps(this.node,{width:r});let o=this.node.dims.x;Number.isFinite(o)&&o>r+.01&&this.ctx.setNodeProps(this.node,{width:o})}clearSessionFlagDirty(e){this.node.raw[e]!==void 0&&this.ctx.setNodeProps(this.node,{[e]:void 0})}get(e){return this.node.raw[e]}setCoords(){}getCenterPoint(){return{...this.node.center}}getRelativeCenterPoint(){return new Jt(this.node.center.x,this.node.center.y)}translateToOriginPoint(e,t="center",r="center"){let o=u=>u==="left"||u==="top"?-.5:u==="right"||u==="bottom"?.5:0,i=o(t),s=o(r),a=i||s?this._getTransformedDimensions():new Jt(0,0),l=new Jt(e.x+i*a.x,e.y+s*a.y),c=this.node.raw.angle;return typeof c=="number"&&c&&(l=l.rotate(c*Math.PI/180,e)),l}toPath(){let e=this.ctx.getTextGlyphPath?.(this.node);return e||Zc(this.node)}toPathDecorations(){return this.ctx.getTextDecorations?.(this.node)??[]}toPathEffectLayers(e){return[]}_getTransformedDimensions(){let e=this.node.raw;return new Jt(this.node.dims.x*(e.scaleX??1),this.node.dims.y*(e.scaleY??1))}getBoundingRect(){let e=this.node.bounds;return{left:e.left,top:e.top,width:e.right-e.left,height:e.bottom-e.top}}getInkRect(){let e=Bn(this.node.inkACoords);return{left:e.left,top:e.top,width:e.width,height:e.height}}get aCoords(){return this.node.aCoords}getCoords(){let e=this.node.aCoords;return[e.tl,e.tr,e.br,e.bl]}calcOCoords(){let e=this.ctx.getViewportTransform?.()??[1,0,0,1,0,0],t=o=>({x:e[0]*o.x+e[2]*o.y+e[4],y:e[1]*o.x+e[3]*o.y+e[5]}),r=this.node.aCoords;return{tl:t(r.tl),tr:t(r.tr),br:t(r.br),bl:t(r.bl)}}rotate(e){let{angle:t,left:r,top:o}=this.node.rotateAroundCenter(e);return this.set({angle:t,left:r,top:o})}setPositionByOrigin(e,t,r){let o=this.node.raw,i=typeof o.scaleX=="number"?o.scaleX:1,s=typeof o.scaleY=="number"?o.scaleY:1,a=this.node.dims.x*i,l=this.node.dims.y*s,c=t==="center"?0:t==="right"?.5:-.5,u=r==="center"?0:r==="bottom"?.5:-.5,h=c*a,d=u*l,f=(typeof o.angle=="number"?o.angle:0)*Math.PI/180,m=Math.cos(f),p=Math.sin(f),b={x:e.x-(h*m-d*p),y:e.y-(h*p+d*m)},x=xe({...o},b);return this.set({left:x.x,top:x.y})}scale(e){let t=this.node.raw;return this.set({scaleX:(t.scaleX??1)*e,scaleY:(t.scaleY??1)*e})}getScaledWidth(){return this.node.dims.x*(this.node.raw.scaleX??1)}getScaledHeight(){return this.node.dims.y*(this.node.raw.scaleY??1)}getObjectScaling(){let e=this.node.raw;return{scaleX:e.scaleX??1,scaleY:e.scaleY??1}}get getObjects(){if(this.node instanceof J)return()=>this.node.children.map(e=>this.ctx.wrapNode(e))}get _objects(){if(this.node instanceof J)return this.node.children.map(e=>this.ctx.wrapNode(e))}get ref(){return this}get isImageLikeNode(){let e=se(this.node.raw);return dt.has(e)||ot.has(e)||e===L.GIF||e===L.VIDEO}get getSrc(){if(this.isImageLikeNode)return()=>{let e=this.node.raw;return typeof e.originalSrc=="string"&&e.originalSrc?e.originalSrc:typeof e.src=="string"?e.src:""}}get getRealSrc(){let e=this.getSrc;if(e)return()=>e()}get replaceSrc(){if(this.isImageLikeNode)return async e=>(this.set({src:e,crossOrigin:"anonymous",originalSrc:e}),await this.ctx.reloadNodeImage?.(this.node),this)}get setElement(){if(this.isImageLikeNode)return(e,t)=>(this.node.imageEl=e,t&&this.set(t),this)}get getElement(){if(!this.isImageLikeNode)return;let e=this.node;return e instanceof ie?()=>e.paintSource??e.imageEl:()=>e.imageEl}get _element(){if(this.isImageLikeNode)return this.node.imageEl}get clipImage(){return Ht(this.node)?av(this.node,this.ctx):void 0}set clipImage(e){let t=e&&typeof e=="object"&&typeof e.toObject=="function"?e.toObject(this.serializationProps()):e;this.ctx.setNodeProps(this.node,{clipImage:t})}getWidthHeight(e=!1){let t=this._getTransformedDimensions(),r=(this.node.raw.strokeWidth??0)||0;return{x:t.x-r,y:t.y-r}}getWidth(){return this.getWidthHeight().x}getHeight(){return this.getWidthHeight().y}sourceNaturalSize(){let e=this.node.imageEl;if(e)return{width:e.naturalWidth||e.width||0,height:e.naturalHeight||e.height||0};if(this.node instanceof ie){let t=this.node.paintSource;if(t)return{width:("videoWidth"in t?t.videoWidth:t.width)||t.width||0,height:("videoHeight"in t?t.videoHeight:t.height)||t.height||0}}return{width:0,height:0}}getOriginalElementWidth(){return this.sourceNaturalSize().width}getOriginalElementHeight(){return this.sourceNaturalSize().height}getElementWidth(){return this.sourceNaturalSize().width}getElementHeight(){return this.sourceNaturalSize().height}cropOffset(){if(!this.isImageLikeNode)return{x:0,y:0};let e=this.node.raw;return e.cropSizeMode==="visible"?{x:0,y:0}:{x:Number(e.cropX)||0,y:Number(e.cropY)||0}}get left(){return this.node.raw.left??0}set left(e){this.set({left:e})}get top(){return this.node.raw.top??0}set top(e){this.set({top:e})}get scaleX(){return this.node.raw.scaleX??1}set scaleX(e){this.set({scaleX:e})}get scaleY(){return this.node.raw.scaleY??1}set scaleY(e){this.set({scaleY:e})}get angle(){return this.node.raw.angle??0}set angle(e){this.set({angle:e})}get skewX(){return this.node.raw.skewX??0}set skewX(e){this.set({skewX:e})}get skewY(){return this.node.raw.skewY??0}set skewY(e){this.set({skewY:e})}get flipX(){return this.node.raw.flipX??!1}set flipX(e){this.set({flipX:e})}get flipY(){return this.node.raw.flipY??!1}set flipY(e){this.set({flipY:e})}get originX(){return this.node.raw.originX??"left"}set originX(e){this.set({originX:e})}get originY(){return this.node.raw.originY??"top"}set originY(e){this.set({originY:e})}get width(){return(this.node.raw.width??0)-this.cropOffset().x}set width(e){if(Dr(this.node)){if(this.ctx.setGroupWidth){this.ctx.setGroupWidth(this.node,e);return}this.ctx.setNodeProps(this.node,{width:e});return}let t=this.cropOffset();this.ctx.setNodeProps(this.node,{width:e+t.x})}get height(){return(this.node.raw.height??0)-this.cropOffset().y}set height(e){let t=this.cropOffset();this.ctx.setNodeProps(this.node,{height:e+t.y})}bridgeImageSizeProps(e){if(!this.isImageLikeNode)return;let t=this.node.raw;if(t.cropSizeMode==="visible")return;let r=typeof e.cropX=="number"?e.cropX:Number(t.cropX)||0,o=typeof e.cropY=="number"?e.cropY:Number(t.cropY)||0;typeof e.width=="number"&&r>0&&(e.width=e.width+r),typeof e.height=="number"&&o>0&&(e.height=e.height+o)}cropBeforeState;get __isCropping(){return this.isImageLikeNode&&this.ctx.cropSessionNodeId?.()===this.node.id}set __isCropping(e){if(this.isImageLikeNode)if(e){let t=this.ctx.cropSessionNodeId?.()!==this.node.id;if(t&&(this.cropBeforeState=this.toObject()),!this.ctx.enterCropSession?.(this.node)){t&&(this.cropBeforeState=void 0);return}let r=this.node.raw.cropAspectRatio;typeof r=="number"&&r>0&&this.ctx.setCropSessionAspectRatio?.(r)}else this.ctx.exitCropSession?.(this.node),this.cropBeforeState=void 0}get __isExpand(){return this.isImageLikeNode&&this.ctx.expandSessionNodeId?.()===this.node.id}set __isExpand(e){this.isImageLikeNode&&(e?this.ctx.enterExpandSession?.(this.node):this.ctx.exitExpandSession?.(this.node))}get beforeState(){return this.cropBeforeState}onDeselectEvent(){this.ctx.exitCropSession?.(this.node),this.ctx.exitExpandSession?.(this.node),this.cropBeforeState=void 0}expandOffsetOf(e){let t=this.ctx.expandSessionOffsets?.(this.node);if(t)return t[e];let r=e==="left"?"Left":e==="right"?"Right":e==="top"?"Top":"Bottom",o=this.node.raw[`expand${r}Offset`];return typeof o=="number"?o:void 0}get expandLeftOffset(){return this.isImageLikeNode?this.expandOffsetOf("left"):void 0}get expandRightOffset(){return this.isImageLikeNode?this.expandOffsetOf("right"):void 0}get expandTopOffset(){return this.isImageLikeNode?this.expandOffsetOf("top"):void 0}get expandBottomOffset(){return this.isImageLikeNode?this.expandOffsetOf("bottom"):void 0}setExpandOffset(){let e=this.ctx.expandSessionOffsets?.(this.node);e&&this.set({expandLeftOffset:e.left,expandRightOffset:e.right,expandTopOffset:e.top,expandBottomOffset:e.bottom})}updateCropScale(e){if(!this.__isCropping||!(e>0)||!Number.isFinite(e))return!1;if(this.ctx.updateCropSessionScale)return this.ctx.updateCropSessionScale(e);let t=this.node.imageEl;if(!t)return!1;let r=this.node.raw,o=t.naturalWidth||t.width,i=t.naturalHeight||t.height,s=r.scaleX??1,a=e/s,l=e/(r.scaleY??1),c=this.width,u=this.height,h=c/a,d=u/l,f=(r.cropX??0)+c/2-h/2,m=(r.cropY??0)+u/2-d/2;return h<Math.min(8,o)||d<Math.min(8,i)||f<0||m<0||f+h>o||m+d>i?!1:(this.set({cropScale:e,scaleX:e,scaleY:e,width:h,height:d,cropX:f,cropY:m}),!0)}getMaxEffectPadding(){let e=this.node.raw,t=0,r=e.effects??{},o=u=>(u??[]).filter(h=>h.enabled&&h.showInDialog),i=o(r.solidFill);i.length>0&&(t=Math.max(t,i.reduce((u,h)=>Math.max(u,Math.abs(Number(h.offsetX)||0),Math.abs(Number(h.offsetY)||0)),0)));let s=o(r.dropShadow);s.length>0&&(t=Math.max(t,s.reduce((u,h)=>{let d=(Number(h.blur)||0)*2;return Math.max(u,Math.abs(Number(h.offsetX)||0)+d,Math.abs(Number(h.offsetY)||0)+d)},0)));let a=o(r.stroke);a.length>0&&(t=Math.max(t,a.reduce((u,h)=>{let d=h.size,f=Number(h.strokeWidth)||Number(d?.value)||0;return Math.max(u,f+Math.abs(Number(h.offsetX)||0),f+Math.abs(Number(h.offsetY)||0))},0)));let l=e.shadow;if(l){let u=(Number(l.blur)||0)*2;t=Math.max(t,Math.abs(Number(l.offsetX)||0)+u,Math.abs(Number(l.offsetY)||0)+u)}let c=Number(e.strokeWidth)||0;if(e.stroke&&c){let u=e.strokeAlignment==="outside"?c*2:c;t=Math.max(t,u)}return t}isType(...e){let t=se(this.node.raw);return e.some(r=>r.toLowerCase()===t)}getStyleAtPosition(e){if(!(this.node instanceof Se))return{};let t=typeof this.node.raw.text=="string"?this.node.raw.text:"";if(e<0||e>=t.length)return{};let r=e,o=t.split(`
|
|
1092
|
-
`);for(let i=0;i<o.length;i++){if(r<=o[i].length)return this.objectStyles()?.[i]?.[r]??{};r-=o[i].length+1}return{}}calcTransformMatrix(){return[...this.node.matrix]}setTableWidth(e){if(!(this.node instanceof
|
|
1093
|
-
`);for(let i=0;i<o.length;i++){if(r<=o[i].length)return{line:i,char:r};r-=o[i].length+1}return{line:Math.max(0,o.length-1),char:o[o.length-1]?.length??0}}stylesToEngineForm(e,t){return e}stylesToPersistForm(e,t){return e}serializationProps(){}stylesMap(){let e=this.node.raw;return Array.isArray(e.styles)&&(e.styles=this.stylesToEngineForm(e.styles,typeof e.text=="string"?e.text:"")??{}),e.styles||(e.styles={}),e.styles}objectStyles(){let e=this.node.raw;return Array.isArray(e.styles)&&(e.styles=this.stylesToEngineForm(e.styles,typeof e.text=="string"?e.text:"")??{}),e.styles}get selectionStart(){return this.ctx.getNodeSelectionRange?.(this.node)?.start??0}get selectionEnd(){return this.ctx.getNodeSelectionRange?.(this.node)?.end??0}cleanStyle(e){let t=this.node.raw,r=this.objectStyles();if(!r)return!1;let o=0,i,s,a=!0,l=0;for(let
|
|
1094
|
-
`))l+=c.length;return a&&o===l&&o>0&&s!==void 0?(this.set({[e]:s}),this.removeStyle?.(e),!0):(o>0&&this.set({styles:t.styles}),!1)}removeStyle(e){let t=this.objectStyles();if(t){for(let r in t){let o=t[r];for(let i in o)delete o[i][e],Object.keys(o[i]).length===0&&delete o[i];Object.keys(o).length===0&&delete t[r]}this.set({styles:t})}}setSelectionStyles(e,t,r){if(!(this.node instanceof Se))return;let o=this.ctx.getNodeSelectionRange?.(this.node),i=t??o?.start??0,s=r??o?.end??0;if(s<=i)return;let a=this.stylesMap();for(let l=i;l<s;l++){let{line:c,char:u}=this.cursor2D(l);a[c]||(a[c]={});let d={...a[c][u]??{}};for(let f of Object.keys(e))e[f]!==void 0&&(d[f]=e[f]);a[c][u]=d}this.set({styles:this.stylesMap()})}getSelectionStyles(e,t){if(!(this.node instanceof Se))return[];let r=this.ctx.getNodeSelectionRange?.(this.node),o=e??r?.start??0,i=t??r?.end??o,s=[];for(let a=o;a<i;a++)s.push(this.getStyleAtPosition(a));return s}setFontFamily(e,t){this.set({fontFamily:e})}get fontFamily(){return String(this.node.raw.fontFamily??"")}get type(){return String(this.node.raw.type??"")}initDimensions(){}calcTextWidth(){return this.node instanceof Se?this.node.textLayout.lines.reduce((e,t)=>Math.max(e,t.width),0):0}refreshTextDimensions(){}replaceFontFamily(e,t){let r=this.node.raw,o=!1;if(r.fontFamily===e&&(this.set({fontFamily:t}),o=!0),r.styles){for(let i of Object.values(r.styles))if(i)for(let s of Object.values(i))s?.fontFamily===e&&(s.fontFamily=t,o=!0);o&&this.set({styles:r.styles})}return o}get rawTypeLower(){return se(this.node.raw)}get transformKind(){return Ke(this.node.raw)}get setRadius(){if(this.transformKind==="arc")return e=>this.set({curvature:e})}get setWarpStrength(){let e=this.transformKind;if(!(e!=="arch"&&e!=="waist"&&e!=="flag"))return t=>this.set({warpStrength:Math.max(-1,Math.min(1,t))})}get clearCache(){let e=this.transformKind;if(!(e!=="arch"&&e!=="waist"&&e!=="flag"))return()=>{this.ctx.invalidateNodeBakes?.(this.node),this.ctx.getCanvas?.()?.requestRenderAll?.()}}get setCircleParams(){if(this.transformKind==="circle")return e=>this.set(e)}get setTexts(){if(this.node instanceof Se)return e=>this.set({texts:e})}get texts(){if(!(this.node instanceof Se))return;let e=this.node.raw.texts;return Array.isArray(e)?e:[]}toObject(e){let t={...this.node.toObject()};if(this.isImageLikeNode){let r=this.sourceNaturalSize();t.width===void 0&&r.width>0&&(t.width=r.width),t.height===void 0&&r.height>0&&(t.height=r.height)}if(this.node instanceof Se){let r=this.node.textLayout,o=this.node.textStyle.lineHeight??1.16,i=iu(r,this.node.raw,o);i&&(t.charTransformations=i),r.lines.length>0&&!iv(t)&&(t.textLines=r.lines.map(a=>a.graphemes.join("")),t.charBounds=r.lines.map(a=>{let l=a.boxes.map(c=>({left:c.left,width:c.width,kernedWidth:c.kernedWidth,height:c.height}));if(l.length>0){let c=l.reduce((u,h)=>u+(h.kernedWidth||0),0);l.push({left:c,width:0,kernedWidth:0,height:l[l.length-1].height})}return l}),t.lineHeights=r.lines.map(a=>a.implHeight*o));let s=this.node.raw;t.styles=this.stylesToPersistForm(t.styles,typeof s.text=="string"?s.text:"")}if(e?.length){let r=this.node.raw,o=t;for(let i of e)o[i]===void 0&&r[i]!==void 0&&(o[i]=r[i])}return t}get id(){return this.node.id}get canvas(){return this.ctx.getCanvas?.()}get group(){let e=this.ctx.getCanvas?.(),t=au(e?.document,this.node);return t?this.ctx.wrapNode(t):void 0}get topGroup(){let e=this.ctx.getCanvas?.(),t,r=this.node;for(;;){let o=au(e?.document,r);if(!o)break;t=o,r=o}return t?this.ctx.wrapNode(t):void 0}get parent(){return this.group}get applyMaskParams(){if(this.node instanceof le)return e=>{this.node.applyMaskParams(e),this.ctx.getCanvas?.()?.requestRenderAll?.()}}get updateGapParams(){if(this.node instanceof le)return e=>{this.node.updateGapParams(e),this.ctx.getCanvas?.()?.requestRenderAll?.()}}get updateLayout(){if(this.node instanceof le)return e=>{this.node.updateLayout(e),this.ctx.getCanvas?.()?.requestRenderAll?.()}}get visible(){return this.node.visible}set visible(e){this.set({visible:e})}get opacity(){let e=this.node.raw.opacity;return typeof e=="number"?e:1}set opacity(e){this.set({opacity:e})}get strokeWidth(){let e=this.node.raw.strokeWidth;return typeof e=="number"?e:1}set strokeWidth(e){this.set({strokeWidth:e})}_createCacheCanvas(){}_removeCacheCanvas(){}get isEditing(){return this.ctx.isEditingNode(this.node)}enterEditing(){return this.node.isTextType&&this.ctx.enterNodeEditing(this.node),this}exitEditing(){return this.ctx.exitEditing(),this}bringToFront(){this.ctx.bringToFront(this.node)}sendToBack(){this.ctx.sendToBack(this.node)}bringForward(){this.ctx.bringForward(this.node)}sendBackwards(){this.ctx.sendBackwards(this.node)}moveTo(e){this.ctx.moveNodeTo(this.node,e)}remove(){this.ctx.removeNode(this.node)}get changeControls(){if(Dt(this.node))return(e,t=!0)=>{this.ctx.changeNodeControls(this.node,e)}}get isEditingPath(){return this.ctx.isPathEditingNode(this.node)}get setAnchorPointType(){if(Dt(this.node)==="path")return(e,t)=>this.ctx.setNodeAnchorType(this.node,e,t)}get getActiveAnchorKey(){if(Dt(this.node))return()=>this.ctx.getNodePathEditInfo(this.node)?.activeAnchorKey}get getActiveAnchorIndex(){if(Dt(this.node))return()=>this.ctx.getNodePathEditInfo(this.node)?.activeAnchorIndex}get getAnchorPointStyleByIndex(){if(Dt(this.node)==="path")return e=>Pc(Ce(this.node.raw.path),e)}get highlightAnchor(){if(Dt(this.node))return e=>{this.ctx.highlightNodeAnchor(this.node,e)}}get resetAnchorStyles(){if(Dt(this.node))return()=>{this.ctx.resetNodeAnchorStyles(this.node)}}},Ht=n=>{let e=n.raw;if(!ot.has(se(e)))return null;let t=e.clipImage;return!t||typeof t!="object"||typeof t.src!="string"?null:t},sv=new Set(["_cacheCanvas","dirty","canvas"]),su=class{constructor(e,t){this.node=e;this.ctx=t}node;ctx;set(e){let t=Ht(this.node);if(!t)return this;let r={...t};for(let[o,i]of Object.entries(e))sv.has(o)||(r[o]=i);return this.ctx.setNodeProps(this.node,{clipImage:r}),this}toObject(e){let t=Ht(this.node);return t?{...t}:{}}setCoords(){}getSrc(){let e=Ht(this.node);return e&&typeof e.originalSrc=="string"&&e.originalSrc?e.originalSrc:e&&typeof e.src=="string"?e.src:""}get replaceSrc(){if(Ht(this.node))return async e=>(this.set({src:e,crossOrigin:"anonymous",originalSrc:e}),await this.ctx.reloadMaskClipImage?.(this.node),this)}getRelativeCenterPoint(){let e=Ht(this.node),t=a=>typeof a=="number"?a:0,r=a=>typeof a=="number"?a:1,o=a=>a==="center"?.5:a==="right"||a==="bottom"?1:0,i=t(e?.width)*r(e?.scaleX),s=t(e?.height)*r(e?.scaleY);return new Jt(t(e?.left)+(.5-o(e?.originX))*i,t(e?.top)+(.5-o(e?.originY))*s)}getOriginalElementWidth(){let e=this.node.clipImageEl;return e?.naturalWidth||e?.width||Number(Ht(this.node)?.width)||0}getOriginalElementHeight(){let e=this.node.clipImageEl;return e?.naturalHeight||e?.height||Number(Ht(this.node)?.height)||0}},au=(n,e)=>{if(!n)return;let t=r=>{for(let o of r){if(!(o instanceof J))continue;if(o.children.some(s=>s===e))return o;let i=t(o.children);if(i)return i}};return t(n.nodes)},av=(n,e)=>{let t=new su(n,e);return new Proxy(t,{get(r,o,i){if(typeof o=="symbol")return Reflect.get(r,o,i);if(o==="then")return;if(o in r)return Reflect.get(r,o,i);let s=Ht(r.node);return s?s[o]:void 0},set(r,o,i,s){return typeof o=="symbol"||o in r?(Reflect.set(r,o,i,s),!0):(r.set({[o]:i}),!0)}})};ou(cr.prototype);var lv=n=>{let e=n.raw,t=typeof e.width=="number"?e.width:n.dims.x,r=typeof e.height=="number"?e.height:n.dims.y,o=e.pathOffset;return{left:typeof e.left=="number"?e.left:0,top:typeof e.top=="number"?e.top:0,width:t,height:r,pathOffset:{x:typeof o?.x=="number"?o.x:t/2,y:typeof o?.y=="number"?o.y:r/2}}},cv=(n,e)=>{let t=new cr(n,e);return n instanceof Pr&&(t._calcDimensions=()=>lv(n)),new Proxy(t,{get(r,o,i){return typeof o=="symbol"?Reflect.get(r,o,i):o==="then"?void 0:o in r?Reflect.get(r,o,i):r.node.raw[o]},set(r,o,i,s){return typeof o=="symbol"||o in r?(Reflect.set(r,o,i,s),!0):(r.set({[o]:i}),!0)}})};var uv=(n,e)=>{n.onWarpHistoryChange=(r,o)=>{e.setWarpUndoable(r),e.setWarpRedoable(o)};let t=()=>{let r=n.warpSession;e.setWarpUndoable(r?.undoable??!1),e.setWarpRedoable(r?.redoable??!1)};return{active:()=>!!n.warpSession,async enter(r){let o=r instanceof cr?r.node:r?.node;if(!o)return!1;let i=await n.enterWarpMode(o);return t(),i},undo(){let r=n.warpUndo();return t(),r},redo(){let r=n.warpRedo();return t(),r},async exit(r){let o=await n.exitWarpMode(r).then(i=>!!i?.committed);return t(),o}}};var Jp=new Set([L.ELLIPSE,L.CIRCLE]),hv=new Set([L.TRIANGLE]),uu=new Set([L.POLYGON]),eb=new Set([L.POLYLINE]),zp=new Set([L.ARROW]),dv=new Set([L.DIMENSION]),fv=new Set([L.GROUP,L.PUZZLE]),Yp=new Set([...dt,L.GIF]),Up=new Set([L.TABLE]),lu=new Set(["multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"]),mv=n=>{if(!(Number(n.warpStrength)||0))return null;let t=Ke(n);return t==="arch"||t==="waist"||t==="flag"?t:null},cu=n=>{let e=n.effects;return!!e&&typeof e=="object"&&!Array.isArray(e)},pv=n=>typeof n.textBackgroundColor=="string"&&n.textBackgroundColor?!0:Array.isArray(n.texts)&&n.texts.length>0,bv=new Set(["rect","Rect","fabricrect","ellipse","Ellipse","circle","Circle","polygon","Polygon","polyline","Polyline","Path","path"]),xv=.222,K=(n,e,t)=>{let r=n[e];if(typeof r=="number")return Number.isFinite(r)?r:t;if(typeof r=="string"&&r.trim()!==""){let o=Number(r.trim());if(Number.isFinite(o))return o}return t},Ie=(n,e)=>{let t=n[e];return typeof t=="string"?t:void 0},N=n=>{let e=Math.round(n*1e4)/1e4;return Object.is(e,-0)?"0":String(e)},ne=n=>n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"),gv=/^(#[0-9a-fA-F]{3,8}|rgba?\(\s*[\d.]+\s*,\s*[\d.]+\s*,\s*[\d.]+\s*(,\s*[\d.]+\s*)?\)|[a-zA-Z][a-zA-Z0-9_-]*)$/,nn=n=>gv.test(n.trim())?n.trim():null,In=n=>n==null||n===""||n==="transparent"||n==="rgba(0,0,0,0)"||n==="none",hu=n=>`matrix(${n.map(N).join(",")})`,yv=(n,e)=>[1,0,0,1,n,e],$p=n=>n,jp=(n,e,t)=>On({...n,width:e,height:t}),tn=n=>{let e=n.shadow;if(!e)return null;if(typeof e!="object"||Array.isArray(e))return;let t=e,r=typeof t.color=="string"?t.color:"rgb(0,0,0)";if(nn(r))return{color:r,blur:typeof t.blur=="number"&&Number.isFinite(t.blur)?t.blur:0,offsetX:typeof t.offsetX=="number"&&Number.isFinite(t.offsetX)?t.offsetX:0,offsetY:typeof t.offsetY=="number"&&Number.isFinite(t.offsetY)?t.offsetY:0}},Vp=(n,e)=>{let t=n.pathOffset,r=0,o=0;return t&&typeof t=="object"?(typeof t.x=="number"&&Number.isFinite(t.x)&&(r=t.x),typeof t.y=="number"&&Number.isFinite(t.y)&&(o=t.y)):e&&(r=e.x,o=e.y),r||o?yv(-r,-o):null},Sv=n=>{let e=Fe(n);return e?{x:(e.left+e.right)/2,y:(e.top+e.bottom)/2}:null},vv=n=>{if(!n.length)return null;let e=1/0,t=1/0,r=-1/0,o=-1/0;for(let i of n)e>i.x&&(e=i.x),t>i.y&&(t=i.y),r<i.x&&(r=i.x),o<i.y&&(o=i.y);return{x:(e+r)/2,y:(t+o)/2}},wv=n=>n.map(e=>e.length===1?e[0]:`${e[0]} ${e.slice(1).map(t=>N(Number(t))).join(" ")}`).join(" "),qp=(n,e,t)=>{let r=se(n);if(Xn.has(r)){let o=Math.min(K(n,"rx",0),e/2),i=Math.min(K(n,"ry",0),t/2),s=o>0||i>0?` rx="${N(o)}" ry="${N(i>0?i:o)}"`:"";return{open:`<rect x="${N(-e/2)}" y="${N(-t/2)}" width="${N(e)}" height="${N(t)}"${s}`,internalTransform:null}}if(Jp.has(r))return{open:`<ellipse cx="0" cy="0" rx="${N(e/2)}" ry="${N(t/2)}"`,internalTransform:null};if(hv.has(r))return{open:`<polygon points="${N(-e/2)},${N(t/2)} 0,${N(-t/2)} ${N(e/2)},${N(t/2)}"`,internalTransform:null};if(r===L.PATH){let o=Ce(n.path);return o?{open:`<path d="${ne(wv(o))}"`,internalTransform:Vp(n,Sv(o))}:null}if(uu.has(r)||eb.has(r)){let o=n.points;if(!Array.isArray(o)||o.length===0)return null;let i=[];for(let l of o){let c=l,u=typeof c.x=="number"?c.x:NaN,h=typeof c.y=="number"?c.y:NaN;Number.isFinite(u)&&Number.isFinite(h)&&i.push({x:u,y:h})}if(!i.length)return null;let s=i.map(l=>`${N(l.x)},${N(l.y)}`);return{open:`<${uu.has(r)?"polygon":"polyline"} points="${s.join(" ")}"`,internalTransform:Vp(n,vv(i))}}return ft.has(r)?{open:`<line x1="${N(K(n,"x1",0))}" y1="${N(K(n,"y1",0))}" x2="${N(K(n,"x2",0))}" y2="${N(K(n,"y2",0))}"`,internalTransform:null}:null},Kp=(n,e,t)=>{let r=e&&n.internalTransform?$(e,n.internalTransform):e??n.internalTransform;return`${n.open}${r?` transform="${hu(r)}"`:""}${t}/>`},Tv=(n,e,t)=>{let r="";if(e!==null){r+=` fill="${ne(e)}"`;let o=Ie(n,"fillRule");o&&(r+=` fill-rule="${ne(o)}"`)}else r+=' fill="none"';if(t!==null){r+=` stroke="${ne(t)}"`,r+=` stroke-width="${N(K(n,"strokeWidth",1))}"`;let o=n.strokeDashArray;if(Array.isArray(o)&&o.length>0){let l=o.map(c=>typeof c=="number"&&Number.isFinite(c)?N(c):null).filter(c=>c!==null);l.length&&(r+=` stroke-dasharray="${l.join(",")}"`)}let i=Ie(n,"strokeLineCap");i&&(r+=` stroke-linecap="${ne(i)}"`);let s=Ie(n,"strokeLineJoin");s&&(r+=` stroke-linejoin="${ne(s)}"`);let a=n.strokeMiterLimit;typeof a=="number"&&Number.isFinite(a)&&(r+=` stroke-miterlimit="${N(a)}"`),n.strokeUniform===!0&&(r+=' vector-effect="non-scaling-stroke"'),Ie(n,"paintFirst")==="stroke"&&(r+=' paint-order="stroke"')}return r},Ev=n=>!In(n.stroke)&&K(n,"strokeWidth",1)>0,Qp=n=>{let e=new Map;return(t,r)=>{let o=/([\d.]+)px\s+([\s\S]+)$/.exec(t);if(!o)return 0;let i=Number(o[1]),s=o[2].replace(/^["']+|["']+$/g,""),a=`${s}|${i}|${r}`,l=e.get(a);if(l!==void 0)return l;let c=n.getFont(s)??n.getSubsetFont?.(s,r[0]??"")??null,u=c&&typeof c.getAdvanceWidth=="function"?c.getAdvanceWidth(r,i):0;return e.set(a,u),u}},Cv=(n,e)=>{let t=0;for(let r of n)t+=r.charCodeAt(0)>255?1:.55;return t*e},tb=n=>{let e=n.textLines,t=n.charBounds,r=n.lineHeights;if(!Array.isArray(e)||!Array.isArray(t)||!Array.isArray(r)||e.length===0||t.length!==e.length||r.length!==e.length)return null;for(let o=0;o<e.length;o++)if(typeof e[o]!="string"||!Array.isArray(t[o])||typeof r[o]!="number"||!Number.isFinite(r[o]))return null;return{textLines:e,charBounds:t,lineHeights:r}},nb=n=>{let e=n.map(o=>At(o).length),t=[],r=0;for(let o of e)t.push(r),r+=o;return{starts:t,counts:e}},Mv=(n,e)=>{let{starts:t,counts:r}=n;if(t.length===0||e<0)return null;let o=0,i=t.length-1;for(;o<i;){let a=o+i+1>>1;t[a]<=e?o=a:i=a-1}let s=e-t[o];return s<0||s>=r[o]?null:[o,s]},Rv=(n,e)=>{let t=n.styles;if(!Array.isArray(t))return{};for(let r of t){if(!r||typeof r!="object")continue;let o=r,i=typeof o.start=="number"?o.start:-1,s=typeof o.end=="number"?o.end:-1;if(e>=i&&e<s&&o.style&&typeof o.style=="object")return o.style}return{}},Zp=(n,e)=>{let t=Rv(n,e),r=(o,i)=>t[o]!==void 0?t[o]:i;return{fontFamily:r("fontFamily",Ie(n,"fontFamily")??"Arial"),fontSize:r("fontSize",K(n,"fontSize",40)),fontWeight:r("fontWeight",String(Ie(n,"fontWeight")??"normal")),fontStyle:r("fontStyle",Ie(n,"fontStyle")??"normal"),fill:r("fill",n.fill),stroke:r("stroke",n.stroke),strokeWidth:r("strokeWidth",K(n,"strokeWidth",1)),underline:r("underline",n.underline===!0),linethrough:r("linethrough",n.linethrough===!0),overline:r("overline",n.overline===!0)}},Ln=n=>({fontFamily:n.fontFamily??"Times New Roman",fontSize:n.fontSize??40,fontWeight:n.fontWeight,fontStyle:n.fontStyle??void 0,lineHeight:n.lineHeight??1.16,charSpacing:n.charSpacing??0,textAlign:n.textAlign??fe.LEFT}),ei=(n,e,t)=>({fontFamily:e?.fontFamily??n.fontFamily,fontSize:e?.fontSize??n.fontSize,fontWeight:String(e?.fontWeight??n.fontWeight??"normal"),fontStyle:e?.fontStyle??n.fontStyle??"normal",fill:e?.fill??t.fill,stroke:t.stroke,strokeWidth:K(t,"strokeWidth",1),underline:t.underline===!0,linethrough:t.linethrough===!0,overline:t.overline===!0}),Pv=(n,e)=>{if(!Array.isArray(e)||e.length===0)return e&&typeof e=="object"?e:void 0;let t=nb(n.split(`
|
|
1095
|
-
`)),r={};for(let o of e){if(!o||typeof o!="object")continue;let i=typeof o.start=="number"?o.start:-1,s=typeof o.end=="number"?o.end:-1;if(!(i<0||s<=i||!o.style||typeof o.style!="object"))for(let a=i;a<s;a++){let l=
|
|
1096
|
-
`))return'<text xml:space="preserve"></text>';let p=this.engineLayoutOf(e,!1);return p?this.emitTextFromEngineLayout(e,p):(this.skip("text-layout-missing"),null)}let a=tn(e);if(a===void 0)return this.skip("shadow-unsupported"),null;let l=K(e,"textScaleX",1)||1,c=K(e,"textScaleY",1)||1,u=Math.abs(l-1)>1e-9||Math.abs(c-1)>1e-9,h=rb(e,s,r,o),d=this.emitAnchorGlyphs(h,r,o);if(d===null)return null;let f=d;return a&&(f=`<g filter="url(#${this.emitShadowFilter(a)})">${f}</g>`),u&&(f=`<g transform="scale(${N(l)},${N(c)})">${f}</g>`),this.pathBackgroundMarkup(e)+f}emitAnchorGlyphs(e,t,r){let o=[],i=[],s=[];for(let{char:l,x:c,y:u,rotation:h,centerX:d,scaleY:f,style:m}of e){let p=h!==void 0||d===!0||f!==void 0,b=h!==void 0?h*180/Math.PI:0;if(this.options.textMode==="paths"){if(l.trim()){let x=this.options.fonts?.getFont(m.fontFamily)??this.options.fonts?.getSubsetFont?.(m.fontFamily,l)??null;if(!x)return this.skip(`text-font-missing:${m.fontFamily}`),null;let g=this.resolvePaint(m.fill,t,r);if(g===void 0)return this.skip("text-fill-unsupported"),null;let y=g!==null?` fill="${ne(g)}"`:' fill="none"';if(typeof m.stroke=="string"&&!In(m.stroke)&&m.strokeWidth>0&&(y+=` stroke="${ne(m.stroke)}" stroke-width="${N(m.strokeWidth)}"`),p){let v=d?-((x.getAdvanceWidth?.(l,m.fontSize)??0)/2):0,S=du(x.getPath(l,v,0,m.fontSize).commands),w=`translate(${N(c)},${N(u)})`;h!==void 0&&(w+=` rotate(${N(b)})`),f!==void 0&&(w+=` scale(1,${N(f)})`),o.push(`<g transform="${w}"><path d="${S}"${y}/></g>`)}else{let v=du(x.getPath(l,c,u,m.fontSize).commands);o.push(`<path d="${v}"${y}/>`)}}}else{let x=this.resolvePaint(m.fill,t,r);if(x===void 0)return this.skip("text-fill-unsupported"),null;if(p){let g=` transform="translate(${N(c)},${N(u)})${h!==void 0?` rotate(${N(b)})`:""}${f!==void 0?` scale(1,${N(f)})`:""}"`;d&&(g+=' text-anchor="middle"'),g+=` font-family="${ne(m.fontFamily)}"`,g+=` font-size="${N(m.fontSize)}"`,m.fontWeight!=="normal"&&(g+=` font-weight="${ne(m.fontWeight)}"`),m.fontStyle!=="normal"&&(g+=` font-style="${ne(m.fontStyle)}"`),g+=x!==null?` fill="${ne(x)}"`:' fill="none"',typeof m.stroke=="string"&&!In(m.stroke)&&m.strokeWidth>0&&(g+=` stroke="${ne(m.stroke)}" stroke-width="${N(m.strokeWidth)}"`),s.push(`<text xml:space="preserve"${g}>${ne(l)}</text>`)}else{let g=` x="${N(c)}" y="${N(u)}"`;g+=` font-family="${ne(m.fontFamily)}"`,g+=` font-size="${N(m.fontSize)}"`,m.fontWeight!=="normal"&&(g+=` font-weight="${ne(m.fontWeight)}"`),m.fontStyle!=="normal"&&(g+=` font-style="${ne(m.fontStyle)}"`),g+=x!==null?` fill="${ne(x)}"`:' fill="none"',typeof m.stroke=="string"&&!In(m.stroke)&&m.strokeWidth>0&&(g+=` stroke="${ne(m.stroke)}" stroke-width="${N(m.strokeWidth)}"`);let y=[m.underline?"underline":"",m.overline?"overline":"",m.linethrough?"line-through":""].filter(Boolean);y.length&&(g+=` text-decoration="${y.join(" ")}"`),i.push(`<tspan${g}>${ne(l)}</tspan>`)}}}if(this.options.textMode==="paths")return o.join("");let a=i.length>0?`<text xml:space="preserve">${i.join("")}</text>`:"";return s.length>0?s.join("")+a:a}emitArcText(e){if(cu(e)){let a=this.options.bakeTextBitmap?.(e,Ge(e)??"arc")??null;if(a)return this.emitBakedTextImage(e,a)}if(Array.isArray(e.effects)&&e.effects.length>0)return this.skip("text-effects"),null;let t=this.arcLayoutOf(e);if(!t)return this.skip(`text-font-missing:${Ie(e,"fontFamily")??""}`),null;let r=tn(e);if(r===void 0)return this.skip("shadow-unsupported"),null;let o=Ln(e),i=[];for(let a of t.arc.chars)i.push({char:a.char,x:a.x-t.arc.contentOffsetX,y:a.y-t.arc.contentOffsetY,rotation:a.rotation,centerX:!0,style:ei(o,t.layout.lines[a.line]?.charStyles?.[a.index],e)});let s=this.emitAnchorGlyphs(i,K(e,"width",0)||t.arc.width,t.arc.height);return s===null?null:r?`<g filter="url(#${this.emitShadowFilter(r)})">${s}</g>`:s}emitVerticalText(e){if(cu(e)){let b=this.options.bakeTextBitmap?.(e,"vertical")??null;if(b)return this.emitBakedTextImage(e,b)}if(Array.isArray(e.effects)&&e.effects.length>0)return this.skip("text-effects"),null;let t=this.engineLayoutOf(e,!0);if(!t)return this.skip(`text-font-missing:${Ie(e,"fontFamily")??""}`),null;let r=tn(e);if(r===void 0)return this.skip("shadow-unsupported"),null;let o=Ln(e),i=o.charSpacing?o.fontSize*o.charSpacing/1e3:0,s=Number(e.textOffsetY)||0,a=Math.max(t.height,K(e,"height",0)),l=[],c=0;for(let b of t.lines){let x=-t.width/2+b.leftOffset,g=-a/2+b.baseline,y=0;for(let v=0;v<b.graphemes.length;v++){let S=b.graphemes[v],w=b.charStyles[v],R=w?.fontSize??o.fontSize,P=wt(s,R,c+v),E=b.boxes[v],C=Un(S);if(C==="latin"||C==="bracket"){let T=x+y+(C==="latin"?E.kernedWidth-E.width:0);l.push({char:S,x:T,y:g+P,style:ei(o,w,e)})}else{let T=x+y+an(R),M=g+P+br(C,E,R);l.push({char:S,x:T,y:M,rotation:-Math.PI/2,style:ei(o,w,e)})}y+=$n(S,E,i)}c+=b.graphemes.length}let u=this.emitAnchorGlyphs(l,t.width,a);if(u===null)return null;let h=this.emitTextDecorations(e,t,a),d=K(e,"textScaleX",1)||1,f=K(e,"textScaleY",1)||1,m=u;r&&(m=`<g filter="url(#${this.emitShadowFilter(r)})">${m}</g>`);let p=h+m;return(Math.abs(d-1)>1e-9||Math.abs(f-1)>1e-9)&&(p=`<g transform="scale(${N(d)},${N(f)})">${p}</g>`),p}emitWarpedText(e,t){let r=this.options.bakeTextBitmap?.(e,t)??null;if(r)return this.emitBakedTextImage(e,r);if(Array.isArray(e.effects)&&e.effects.length>0)return this.skip("text-effects"),null;let o=this.engineLayoutOf(e,!1);if(!o)return this.skip(`text-font-missing:${Ie(e,"fontFamily")??""}`),null;let i=tn(e);if(i===void 0)return this.skip("shadow-unsupported"),null;let s=K(e,"fontSize",40)||40,a=Math.max(-1,Math.min(1,K(e,"warpStrength",0)||0)),l=K(e,"width",0),c=K(e,"height",0),u=Math.max(o.height,c),h=Math.max(o.width,l,s),d=t==="flag"?Math.abs(a)*(c||s)*.3:0,f=h/2,m=u/2,p=Ln(e),b=[];for(let S of o.lines){let w=-o.width/2+S.leftOffset,R=-u/2+S.baseline;for(let P=0;P<S.graphemes.length;P++){let E=S.boxes[P],C=ei(p,S.charStyles[P],e),T=w+E.left,M=T+E.width/2,k=f>0?M/f:0;if(t==="flag"){let A=Math.sin(k*Math.PI)*d*a;b.push({char:S.graphemes[P],x:T,y:R+A,style:C})}else if(t==="arch"){let A=Math.max(-1,Math.min(1,k)),O=Math.sqrt(Math.max(0,1-A*A)),F=O*O*(3-2*O),H=a>0?Math.pow(F,2.5):F,z=Math.min(1+Math.max(0,a),Math.max(.05,1+a*H));b.push({char:S.graphemes[P],x:T,y:z*R+m*(1-z),scaleY:z,style:C})}else{let A=Math.min(1+Math.abs(a),Math.max(.4,1+a*(k*k-.5)));b.push({char:S.graphemes[P],x:T,y:A*R,scaleY:A,style:C})}}}let x=this.emitAnchorGlyphs(b,h,u);if(x===null)return null;let g=K(e,"textScaleX",1)||1,y=K(e,"textScaleY",1)||1,v=x;return i&&(v=`<g filter="url(#${this.emitShadowFilter(i)})">${v}</g>`),(Math.abs(g-1)>1e-9||Math.abs(y-1)>1e-9)&&(v=`<g transform="scale(${N(g)},${N(y)})">${v}</g>`),v}emitMask(e){let t=Ie(e,"src");if(!t)return this.skip("image-src-missing"),null;let r=K(e,"width",0),o=K(e,"height",0);if(!(r>0)||!(o>0))return this.skip("image-dims-missing"),null;let i=e.clipImage,s=i&&typeof i=="object"?i:null,a=s?Ie(s,"src"):void 0;if(!s||!a){let w=tn(e);if(w===void 0)return this.skip("shadow-unsupported"),null;let R=`<image href="${ne(t)}" xlink:href="${ne(t)}" x="${N(-r/2)}" y="${N(-o/2)}" width="${N(r)}" height="${N(o)}"/>`;return w&&(R=`<g filter="url(#${this.emitShadowFilter(w)})">${R}</g>`),R}let l=this.options.naturalSizes?.get(a);if(!l||l.width<=0||l.height<=0)return this.skip("image-natural-missing"),null;let c=l.width,u=l.height,h=this.nextId("esvg-mk");this.defs.push(`<mask id="${h}" maskUnits="userSpaceOnUse" mask-type="alpha" x="${N(-r/2)}" y="${N(-o/2)}" width="${N(r)}" height="${N(o)}"><image href="${ne(t)}" xlink:href="${ne(t)}" x="${N(-r/2)}" y="${N(-o/2)}" width="${N(r)}" height="${N(o)}"/></mask>`);let d=`<g transform="translate(${N(-r/2)},${N(-o/2)})" mask="url(#${h})"`,f=Math.max(0,Math.min(K(e,"cornerRadius",0),Math.min(r,o)/2));if(f>0){let w=this.nextId("esvg-mc");this.defs.push(`<clipPath id="${w}"><path d="M ${N(f)} 0 L ${N(r-f)} 0 Q ${N(r)} 0 ${N(r)} ${N(f)} L ${N(r)} ${N(o-f)} Q ${N(r)} ${N(o)} ${N(r-f)} ${N(o)} L ${N(f)} ${N(o)} Q 0 ${N(o)} 0 ${N(o-f)} L 0 ${N(f)} Q 0 0 ${N(f)} 0 Z"/></clipPath>`),d+=` clip-path="url(#${w})"`}d+=">";let m=K(s,"angle",0),p=K(s,"scaleX",1)||1,b=K(s,"scaleY",1)||1,x=s.flipX===!0?-1:1,g=s.flipY===!0?-1:1,y=K(e,"clipX",0),v=K(e,"clipY",0),S=`translate(${N(r/2)},${N(o/2)}) rotate(${N(m)}) scale(${N(p*x)},${N(b*g)}) translate(${N(y/(p||1))},${N(v/(b||1))}) translate(${N(-c/2)},${N(-u/2)})`;return d+`<g transform="${S}"><image href="${ne(a)}" xlink:href="${ne(a)}" x="0" y="0" width="${N(c)}" height="${N(u)}"/></g></g>`}emitTable(e){let t=this.tableLayoutOf(e);if(!t)return this.skip(`text-font-missing:${typeof e.fontFamily=="string"?e.fontFamily:""}`),null;let r=[];for(let o of t.children){if(!o||typeof o!="object"||typeof o.type!="string")continue;let i=this.emitNode(o);if(i===null)return null;i&&r.push(i)}return r.join("")}pathBackgroundMarkup(e,t){let r=so(e);if(!r||!r.fill)return"";let o=t??this.engineLayoutOf(e,!1);if(!o)return"";let i=o.width,s=Math.max(o.height,K(e,"height",0));if(!(i>0)||!(s>0))return"";let a=Ce(r.path);if(!a)return"";let l=Fe(a);if(!l)return"";let c=l.right-l.left,u=l.bottom-l.top;if(!(c>0)||!(u>0))return"";let h=i/r.width,d=s/r.height,f=(l.left+l.right)/2,m=(l.top+l.bottom)/2,[p,b,x,g]=oe(r.fill),y=`rgba(${Math.round(p*255)},${Math.round(b*255)},${Math.round(x*255)},${N(g)})`;return`<path d="${ne(r.path)}" transform="matrix(${N(h)} 0 0 ${N(d)} ${N(-f*h)} ${N(-m*d)})" fill="${y}"/>`}emitTextDecorations(e,t,r){let o=[],i=-r/2,s=typeof e.textBackgroundColor=="string"?e.textBackgroundColor:"";if(s||t.lines.some(a=>a.charStyles.some(l=>l?.textBackgroundColor)))for(let a of t.lines){let l=-t.width/2+a.leftOffset,c=i+a.top,u=p=>a.charStyles[p]?.textBackgroundColor??s,h=0,d=0,f=u(0),m=()=>{if(!f||d<=0)return;let p=nn(f);p&&o.push(`<rect x="${N(l+a.boxes[h].left)}" y="${N(c)}" width="${N(d)}" height="${N(a.implHeight)}" fill="${ne(p)}"/>`)};for(let p=0;p<a.graphemes.length;p++){let b=u(p);b!==f?(m(),h=p,d=a.boxes[p].width,f=b):d+=a.boxes[p].kernedWidth}m()}if(Array.isArray(e.texts)&&e.texts.length>0&&e.vertical!==!0){let a=Kn(e.text??"",t,e.texts,i,Ln(e).fontSize);if(a)for(let l of a.ops){let c=l.isFill?`<path d="${ne(l.d)}" fill="${ne(nn(l.fill)??l.fill)}"/>`:`<path d="${ne(l.d)}" fill="none" stroke="${ne(nn(l.stroke)??l.stroke)}" stroke-width="${N(l.strokeWidth)}"/>`;o.push(`<g transform="translate(${N(l.translateX)},${N(l.translateY)}) scale(${N(l.scaleX)},${N(l.scaleY)})">${c}</g>`)}}return o.join("")}emitTextFromEngineLayout(e,t){let r=tn(e);if(r===void 0)return this.skip("shadow-unsupported"),null;let o=Ln(e),i=Math.max(t.height,K(e,"height",0)),s=[];for(let f of t.lines){let m=-t.width/2+f.leftOffset,p=-i/2+f.baseline;for(let b=0;b<f.graphemes.length;b++)s.push({char:f.graphemes[b],x:m+f.boxes[b].left,y:p,style:ei(o,f.charStyles[b],e)})}let a=this.emitAnchorGlyphs(s,t.width,i);if(a===null)return null;let l=K(e,"textScaleX",1)||1,c=K(e,"textScaleY",1)||1,u=this.emitTextDecorations(e,t,i),h=a;r&&(h=`<g filter="url(#${this.emitShadowFilter(r)})">${h}</g>`);let d=u+h;return(Math.abs(l-1)>1e-9||Math.abs(c-1)>1e-9)&&(d=`<g transform="scale(${N(l)},${N(c)})">${d}</g>`),this.pathBackgroundMarkup(e,t)+d}tableCache=new Map;tableLayoutOf(e){let t=this.tableCache.get(e);if(t!==void 0)return t;if(this.layoutMeasure===void 0&&(this.layoutMeasure=this.options.measure??(this.options.fonts?Qp(this.options.fonts):null)),!this.layoutMeasure)return null;let r;try{r=To(e,this.layoutMeasure)}catch{r=null}return this.tableCache.set(e,r),r}arcCache=new Map;layoutMeasure;engineLayoutOf(e,t){if(this.layoutMeasure===void 0&&(this.layoutMeasure=this.options.measure??(this.options.fonts?Qp(this.options.fonts):null)),!this.layoutMeasure)return null;if(!this.options.measure){let i=Ln(e).fontFamily;if(!this.options.fonts?.getFont(i))return null}let r=e.text??"",o=se(e)===L.TEXTBOX&&Ke(e)===null;return jn(r,Ln(e),{measure:this.layoutMeasure,boxWidth:o?e.width??0:null,styles:Pv(r,e.styles),splitByGrapheme:e.splitByGrapheme===!0,vertical:t,paragraph:Ge(e)?void 0:e.paragraph})}arcLayoutOf(e){let t=this.arcCache.get(e);if(t!==void 0)return t;let r=this.engineLayoutOf(e,!1),o=r?{layout:r,arc:Et(r,e,Ln(e).lineHeight??1.16)}:null;return this.arcCache.set(e,o),o}emitImage(e){let t=Ie(e,"src");if(!t)return this.skip("image-src-missing"),null;if(Array.isArray(e.filters)&&e.filters.length>0)return this.skip("image-filters"),null;if(Array.isArray(e.effects)&&e.effects.length>0)return this.skip("image-effects"),null;let r=Ie(e,"globalCompositeOperation");if(r&&r!=="source-over"&&!lu.has(r))return this.skip("image-gco"),null;let o=Qi($p(e));if(o){let h=this.options.naturalSizes?.get(t);if(!h)return this.skip("image-natural-missing"),null;let d=o.sw,f=o.sh;if(d<=0||f<=0)return this.skip("image-crop-empty"),null;let m=d/o.sw,p=f/o.sh,b=-d/2-o.sx*m,x=-f/2-o.sy*p,g=this.nextId("esvg-ic"),y=K(e,"rx",0),v=K(e,"ry",0),S=y>0||v>0?` rx="${N(y)}" ry="${N(v)}"`:"";return this.defs.push(`<clipPath id="${g}"><rect x="${N(-d/2)}" y="${N(-f/2)}" width="${N(d)}" height="${N(f)}"${S}/></clipPath>`),`<g clip-path="url(#${g})"><image xlink:href="${ne(t)}" x="${N(b)}" y="${N(x)}" width="${N(h.width*m)}" height="${N(h.height*p)}"/></g>`}let i=K(e,"width",NaN),s=K(e,"height",NaN);if(!Number.isFinite(i)||!Number.isFinite(s))return this.skip("image-dims-missing"),null;let a=tn(e);if(a===void 0)return this.skip("shadow-unsupported"),null;let l=`<image xlink:href="${ne(t)}" x="${N(-i/2)}" y="${N(-s/2)}" width="${N(i)}" height="${N(s)}"/>`,c=K(e,"rx",0),u=K(e,"ry",0);if(c>0||u>0){let h=this.nextId("esvg-ir");this.defs.push(`<clipPath id="${h}"><rect x="${N(-i/2)}" y="${N(-s/2)}" width="${N(i)}" height="${N(s)}" rx="${N(c)}" ry="${N(u)}"/></clipPath>`),l=`<g clip-path="url(#${h})">${l}</g>`}return a&&(l=`<g filter="url(#${this.emitShadowFilter(a)})">${l}</g>`),l}emitObjectContent(e,t,r,o){let i=se(e);if(fv.has(i)){let d=e.objects;if(!Array.isArray(d))return this.skip("group-objects-missing"),null;let f=[];for(let m of d){if(!m||typeof m!="object"||typeof m.type!="string")continue;let p=this.emitNode(m);if(p===null)return null;p&&f.push(p)}return f.join("")}if(Up.has(i))return this.emitTable(e);if(ot.has(i))return this.emitMask(e);if(Yp.has(i))return this.emitImage(e);if(i===L.TEXTIMAGE&&typeof e.renderSrc=="string"){let d=e.renderRect,f=typeof d?.w=="number"&&d.w>0?d.w:K(e,"width",NaN),m=typeof d?.h=="number"&&d.h>0?d.h:K(e,"height",NaN);if(!Number.isFinite(f)||!Number.isFinite(m)||f<=0||m<=0)return this.skip("textimage-dims-missing"),null;let p=-f/2+(typeof d?.x=="number"?d.x:0),b=-m/2+(typeof d?.y=="number"?d.y:0),x=Eo(e),g=`<image xlink:href="${ne(Ie(e,"renderSrc")??"")}" x="${N(p)}" y="${N(b)}" width="${N(f)}" height="${N(m)}"${x<1?` opacity="${N(x)}"`:""}/>`,y=typeof d?.angle=="number"&&Number.isFinite(d.angle)?d.angle:0;return y&&(g=`<g transform="rotate(${N(-y)})">${g}</g>`),g}if(rn.has(i))return this.emitText(e);let s=Ie(e,"globalCompositeOperation");if(s&&s!=="source-over"&&!lu.has(s))return this.skip("shape-gco"),null;if(typeof e.strokeAlignment=="string"&&e.strokeAlignment!=="center"&&!In(e.stroke))return this.skip("shape-stroke-alignment"),null;if(zp.has(i)||dv.has(i))return this.emitLineDecoration(e,zp.has(i));let a=qp(e,r,o);if(!a)return this.skip(`type:${String(e.type??"")}`),null;let l=this.resolvePaint(e.fill,r,o);if(l===void 0)return this.skip("fill-unsupported"),null;let c=null;if(Ev(e)){let d=this.resolvePaint(e.stroke,r,o);if(d===void 0)return this.skip("stroke-unsupported"),null;c=d}let u=tn(e);if(u===void 0)return this.skip("shadow-unsupported"),null;let h=Tv(e,l,c)+(u?` filter="url(#${this.emitShadowFilter(u)})"`:"");return Kp(a,null,h)}emitLineDecoration(e,t){let r=K(e,"x1",NaN),o=K(e,"y1",NaN),i=K(e,"x2",NaN),s=K(e,"y2",NaN);if(!Number.isFinite(r)||!Number.isFinite(o)||!Number.isFinite(i)||!Number.isFinite(s))return this.skip(`dims-missing:${String(e.type??"")}`),null;let a=e.stroke,l=typeof a=="string"&&!In(a)?a:"#000000";if(!nn(l))return this.skip("stroke-unsupported"),null;let c=K(e,"strokeWidth",1),u=e.strokeDashArray,h=Array.isArray(u)&&u.length>0?` stroke-dasharray="${u.map(B=>typeof B=="number"&&Number.isFinite(B)?N(B):null).filter(B=>B!==null).join(",")}"`:"",d=i-r,f=s-o,m=Math.atan2(f,d),p=Math.cos(m),b=Math.sin(m);if(t){let B=e.arrowType==="start"||e.arrowType==="both"?e.arrowType:"end",G=B==="start"||B==="both",X=B==="end"||B==="both",U=Math.sqrt(c),q=K(e,"arrowWidth",15)*U,j=K(e,"arrowHeight",22.5)*U,Z=r+p*(G?j:0),W=o+b*(G?j:0),V=i-p*(X?j:0),Y=s-b*(X?j:0),re=` stroke="${ne(l)}" stroke-width="${N(c)}"${h}`,te=[`<line x1="${N(Z)}" y1="${N(W)}" x2="${N(V)}" y2="${N(Y)}"${re} fill="none"/>`],de=(Pe,De,nt)=>{let ke=Math.cos(nt),Ee=Math.sin(nt),ue=Pe-j*ke+q/2*Ee,ge=De-j*Ee-q/2*ke,pe=Pe-j*ke-q/2*Ee,Te=De-j*Ee+q/2*ke;te.push(`<path d="M ${N(Pe)} ${N(De)} L ${N(ue)} ${N(ge)} L ${N(pe)} ${N(Te)} Z" fill="${ne(l)}"/>`)};return X&&de(i,s,m),G&&de(r,o,m+Math.PI),te.join("")}let x=` stroke="${ne(l)}" stroke-width="${N(c)}"${h}`,g=Ie(e,"strokeLineCap");g&&(x+=` stroke-linecap="${ne(g)}"`);let y=Ie(e,"strokeLineJoin");y&&(x+=` stroke-linejoin="${ne(y)}"`);let v=e.strokeMiterLimit;typeof v=="number"&&Number.isFinite(v)&&(x+=` stroke-miterlimit="${N(v)}"`);let S=[`<line x1="${N(r)}" y1="${N(o)}" x2="${N(i)}" y2="${N(s)}"${x} fill="none"/>`],w=(K(e,"textFontSize",50)||50)/2,R=-b,P=p,E=` stroke="${ne(l)}" stroke-width="${N(c)}" stroke-linecap="round"`;for(let[B,G]of[[r,o],[i,s]])S.push(`<line x1="${N(B-R*w)}" y1="${N(G-P*w)}" x2="${N(B+R*w)}" y2="${N(G+P*w)}"${E} fill="none"/>`);let C=K(e,"textFontSize",50)||50,T=typeof e.text=="string"&&e.text.trim()?e.text:"50cm",M=K(e,"textPadding",4),k=Cv(T,C)+M*2,A=C+M*2,O=C+c/2+5,F=(r+i)/2+R*O,H=(o+s)/2+P*O,z=e.textFollowLine===!1?0:m*180/Math.PI,_=typeof e.textColor=="string"&&nn(e.textColor)?e.textColor:"#333333",D=typeof e.textBackgroundColor=="string"?e.textBackgroundColor:"#ffffff",I=nn(D);return S.push(`<g transform="translate(${N(F)},${N(H)}) rotate(${N(z)})">`+(D&&I?`<rect x="${N(-k/2)}" y="${N(-A/2)}" width="${N(k)}" height="${N(A)}" fill="${ne(I)}"/>`:"")+`<text text-anchor="middle" dominant-baseline="central" font-family="Arial, sans-serif" font-size="${N(C)}" fill="${ne(_)}">${ne(T)}</text></g>`),S.join("")}emitNode(e){if(Ar.has(Ie(e,"id")??"")||e.excludeFromExport===!0||e.visible===!1)return"";let t=se(e),r=K(e,"width",NaN),o=K(e,"height",NaN);if(Yp.has(t)){let h=Qi($p(e));if(h)r=h.sw,o=h.sh;else if(!Number.isFinite(r)||!Number.isFinite(o)){let d=this.options.naturalSizes?.get(Ie(e,"src")??"");r=d?.width??NaN,o=d?.height??NaN}}else if(ft.has(t)&&(!Number.isFinite(r)||!Number.isFinite(o)))r=Math.abs(K(e,"x2",0)-K(e,"x1",0)),o=Math.abs(K(e,"y2",0)-K(e,"y1",0));else if(Jp.has(t)&&(!Number.isFinite(r)||!Number.isFinite(o)))if(t===L.CIRCLE){let h=2*K(e,"radius",NaN);Number.isFinite(r)||(r=h),Number.isFinite(o)||(o=h)}else Number.isFinite(r)||(r=2*K(e,"rx",NaN)),Number.isFinite(o)||(o=2*K(e,"ry",NaN));else if((uu.has(t)||eb.has(t))&&(!Number.isFinite(r)||!Number.isFinite(o))){let h=e.points;if(Array.isArray(h)&&h.length>0){let d=1/0,f=1/0,m=-1/0,p=-1/0;for(let b of h){let x=typeof b?.x=="number"&&Number.isFinite(b.x)?b.x:NaN,g=typeof b?.y=="number"&&Number.isFinite(b.y)?b.y:NaN;!Number.isFinite(x)||!Number.isFinite(g)||(d>x&&(d=x),f>g&&(f=g),m<x&&(m=x),p<g&&(p=g))}Number.isFinite(d)&&Number.isFinite(f)&&(Number.isFinite(r)||(r=m-d),Number.isFinite(o)||(o=p-f))}}else if(rn.has(t)&&!Number.isFinite(o))if(Array.isArray(e.lineHeights))o=e.lineHeights.reduce((h,d)=>h+(typeof d=="number"&&Number.isFinite(d)?d:0),0);else{let h=this.engineLayoutOf(e,!1);h&&(o=h.height)}if(Ge(e)){let h=this.arcLayoutOf(e);h&&(r=h.arc.width,o=h.arc.height)}if(Up.has(t)){let h=this.tableLayoutOf(e);h&&(r=h.width,o=h.height)}if(!Number.isFinite(r)||!Number.isFinite(o))return this.skip(`dims-missing:${String(e.type??"")}`),null;let i=jp(e,r,o),s=this.emitObjectContent(e,i,r,o);if(s===null)return null;if(s==="")return"";let a=`<g transform="${hu(i)}"`,l=Ie(e,"globalCompositeOperation");l&&l!=="source-over"&&lu.has(l)&&(a+=` style="mix-blend-mode:${ne(l)}"`);let c=K(e,"opacity",1);c<1&&(a+=` opacity="${N(c)}"`);let u=this.emitClipPath(e,i);return u===null&&e.clipPath?(this.skip("clip-unsupported"),null):(u&&(a+=u),`${a}>${s}</g>`)}},Nv=n=>new Da({textMode:n.textMode,fonts:n.fonts,naturalSizes:n.naturalSizes,measure:n.measure,bakeTextBitmap:n.bakeTextBitmap}).exportPage(n);var ob=n=>n==="center"?0:n==="right"?.5:-.5,ib=n=>typeof n=="number"?n:0,Lv=(n,e={})=>{let t=1/0,r=1/0,o=-1/0,i=-1/0,s=[];for(let p of n){let b=Ct(p);if(!b)continue;s.push(b);let x=b.contentBoxCorners();for(let g of[x.tl,x.tr,x.br,x.bl])g.x<t&&(t=g.x),g.y<r&&(r=g.y),g.x>o&&(o=g.x),g.y>i&&(i=g.y)}let a=!s.length||!Number.isFinite(t),l=a?0:o-t,c=a?0:i-r,u=a?0:(t+o)/2,h=a?0:(r+i)/2,d=n.map(p=>({...p,left:ib(p.left)-u,top:ib(p.top)-h})),f=typeof e.left=="number"?e.left:u+l*ob(e.originX),m=typeof e.top=="number"?e.top:h+c*ob(e.originY);return{...e,type:e.type??"Group",width:l,height:c,left:f,top:m,objects:d}};var ur=n=>n==="center"?0:n==="right"?.5:-.5,Iv=(n,e={})=>{let t=Ce(n),r=t?Fe(t):null,o=r?r.right-r.left:0,i=r?r.bottom-r.top:0,s={x:r?(r.left+r.right)/2:0,y:r?(r.top+r.bottom)/2:0},a=typeof e.strokeWidth=="number"?e.strokeWidth:1,l=typeof e.left=="number"?e.left:s.x+(o+a)*ur(e.originX),c=typeof e.top=="number"?e.top:s.y+(i+a)*ur(e.originY);return{...e,type:e.type??"Path",path:t??[],width:o,height:i,pathOffset:s,left:l,top:c}};var _v=(n,e={})=>{let[t,r,o,i]=n,s=Math.abs(o-t),a=Math.abs(i-r),l=(t+o)/2,c=(r+i)/2,u=typeof e.strokeWidth=="number"?e.strokeWidth:1,h=typeof e.left=="number"?e.left:l+(s+u)*ur(e.originX),d=typeof e.top=="number"?e.top:c+(a+u)*ur(e.originY),f=t<=o?-1:1,m=r<=i?-1:1;return{...e,type:e.type??"Line",width:s,height:a,left:h,top:d,x1:f*s/2||0,y1:m*a/2||0,x2:-f*s/2||0,y2:-m*a/2||0}},Dv=(n,e={},t="Polygon")=>{let r=1/0,o=1/0,i=-1/0,s=-1/0;for(let m of n)m.x<r&&(r=m.x),m.y<o&&(o=m.y),m.x>i&&(i=m.x),m.y>s&&(s=m.y);let a=!Number.isFinite(r),l=a?0:i-r,c=a?0:s-o,u={x:a?0:(r+i)/2,y:a?0:(o+s)/2},h=typeof e.strokeWidth=="number"?e.strokeWidth:1,d=typeof e.left=="number"?e.left:u.x+(l+h)*ur(e.originX),f=typeof e.top=="number"?e.top:u.y+(c+h)*ur(e.originY);return{...e,type:e.type??t,points:n,width:l,height:c,pathOffset:u,left:d,top:f}};export{ie as AnimatedNode,Hg as COMPAT_PROTOCOL_VERSION,Ne as CompatHistoryActions,cr as CompatObject,Jt as CompatPoint,L as ElementTypes,Kc as EngineCanvas,Ro as EngineDocument,Fn as EventBus,pi as GIF_TYPES,J as GroupNode,dt as IMAGE_LIKE_TYPES,ft as LINE_TYPES,kr as LineNode,ot as MASK_TYPES,ae as MaskNode,mi as PUZZLE_TYPES,Pr as PathNode,Qc as Point,le as PuzzleNode,Gn as SHAPE_TYPES,Xn as SOLID_TYPES,ks as ScaleLimit,ct as SceneNode,xn as ShapeNode,Da as SvgExporter,Vb as TEXT_ALIGN_VALUES,rn as TEXT_TYPES,ee as TableNode,fe as TextAlignValues,Se as TextNode,bi as VIDEO_TYPES,qn as activePsdTextWarp,Pc as anchorStyleAt,hh as applyWarpDistortion,Ge as arcTextKind,Lv as assembleGroupRaw,Gg as attachDocumentEventBridge,ou as attachTableFacade,yl as bakeArcText,$c as bakePsdWarpText,Tx as bakeTextEffects,gl as bakeWarpedText,Bn as boundsFromACoors,wo as buildAllSelection,Zc as buildEngineShapePath,_v as buildLineRaw,Iv as buildPathRaw,Dv as buildPolyRaw,Fl as buildScene,bn as buildSelectionRange,Av as buildTextGlyphPathData,ul as buildWarpSurfaceGridOverWindow,og as clearAlphaHitMask,kt as composeMatrix,ho as compositeWarpEffects,Et as computeArcTextLayout,Sl as computePuzzleItems,uv as createEngineWarpvasFacade,Ct as createNode,zc as decodeAnimatedImage,xb as decomposeOwnMatrix,iu as deriveArcCharTransformations,Ri as evaluateWarpMesh,Aa as fboPixelsToImageData,au as findParentGroupOf,cl as generatePsdWarpMesh,uh as generateStyleWarpMesh,Fe as getBoundsOfPath,we as getCellData,un as glyphStyleAt,pn as glyphStyleOf,cn as identityWarpMesh,Hc as imageMaskDeclOf,ip as imageMaskOffset,yo as insertTableColumn,go as insertTableRow,ve as invert,hl as invertBilinearCell,Yr as isAnimatedPng,PS as isAnimatedPngFile,kS as isAnimatedPngUrl,NS as isAnimatedWebPFile,LS as isAnimatedWebPUrl,bu as isCanvasPerfEnabled,gb as isEngineRasterExportEnabled,yb as isEngineSvgExportEnabled,ll as isGeneratableWarpStyle,Dr as isGroupWidthHandleNode,zt as isJustifyFamilyAlign,tl as isJustifyVariantAlign,Ua as isSnapGuideEnabled,eo as isStretchAlign,$t as isTextBitmapState,jn as layoutTextbox,sl as lineDecorationRuns,Je as loadImageElement,xu as markCanvasPerfCounter,sp as maskOutsideRects,op as maskPixelsToAlpha,lt as masterPosition,bo as mergeTableCells,$ as multiply,Yi as normalizeSelectionAfterRemove,Xa as objectACoors,Xt as objectCenter,xe as objectOriginFromCenter,On as objectOwnMatrix,oe as parseColor,Ce as parsePathData,Vt as parsePsdEffects,so as pathBackgroundSpecOf,Dt as pathEditKindOf,Kn as planTextHighlight,oi as recordCanvasPerfDuration,it as rectCornerRadii,ts as refitGroupShells,Rl as removeTableColumn,Ml as removeTableRow,nv as renderPlacedSmartObjectLayer,uo as renderTextRuns,Oi as renderVerticalRuns,Rr as rowColCoverage,qr as sceneToClipMatrix,Xe as selectionBounds,Nv as serializePageToSvg,Kg as setGroupWidth,mo as setTableColumnWidth,po as setTableRowHeight,Eo as textBitmapFillAlpha,Ke as textTransformKindOf,Q as transformPoint,si as transformedDimensions,se as typeKeyOf,xo as unmergeTableCells,Yt as verticalGlyphOps,cv as wrapCompatObject};
|
|
1091
|
+
}`,_a=class{program=null;vao=null;vertexBuffer=null;corners=new Float32Array(12);invalidate(){this.program=null,this.vao=null,this.vertexBuffer=null}init(e){let t=(s,a)=>{let l=e.createShader(s);return l?(e.shaderSource(l,a),e.compileShader(l),e.getShaderParameter(l,e.COMPILE_STATUS)?l:(console.warn("[WorkspaceGlow] shader:",e.getShaderInfoLog(l)),e.deleteShader(l),null)):null},r=t(e.VERTEX_SHADER,US),o=t(e.FRAGMENT_SHADER,$S),i=e.createProgram();return!r||!o||!i?(r&&e.deleteShader(r),o&&e.deleteShader(o),!1):(e.attachShader(i,r),e.attachShader(i,o),e.linkProgram(i),e.deleteShader(r),e.deleteShader(o),e.getProgramParameter(i,e.LINK_STATUS)?(this.program=i,this.vao=e.createVertexArray(),e.bindVertexArray(this.vao),this.vertexBuffer=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer),e.bufferData(e.ARRAY_BUFFER,this.corners.byteLength,e.DYNAMIC_DRAW),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,2,e.FLOAT,!1,0,0),e.bindVertexArray(null),!0):(console.warn("[WorkspaceGlow] link:",e.getProgramInfoLog(i)),e.deleteProgram(i),!1))}draw(e,t){if(!this.program&&!this.init(e))return;let{view:r,vpt:o,cssWidth:i,cssHeight:s,left:a,top:l,width:u,height:c,zoom:h,dpr:d}=t;if(!(h>0)||!(d>0)||!(u>0)||!(c>0))return;let f=zS/h,m=1.5/(h*d),p=ve(o),b=Q(p,0,0),x=Q(p,i,s),g=Math.min(b.x,x.x),y=Math.min(b.y,x.y),v=Math.max(b.x,x.x),S=Math.max(b.y,x.y),w=this.corners;w[0]=g,w[1]=y,w[2]=v,w[3]=y,w[4]=v,w[5]=S,w[6]=g,w[7]=y,w[8]=v,w[9]=S,w[10]=g,w[11]=S;let R=this.program;e.useProgram(R),e.bindVertexArray(this.vao),e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer),e.bufferSubData(e.ARRAY_BUFFER,0,w);let P=new Float32Array([r[0],r[1],0,r[2],r[3],0,r[4],r[5],1]);e.uniformMatrix3fv(e.getUniformLocation(R,"uView"),!1,P),e.uniform2f(e.getUniformLocation(R,"uCenter"),a+u/2,l+c/2),e.uniform2f(e.getUniformLocation(R,"uHalf"),u/2,c/2),e.uniform1f(e.getUniformLocation(R,"uBlur"),f),e.uniform1f(e.getUniformLocation(R,"uAa"),m),e.uniform3f(e.getUniformLocation(R,"uMask"),Qc[0],Qc[1],Qc[2]),e.uniform1f(e.getUniformLocation(R,"uGlow"),YS),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),e.drawArrays(e.TRIANGLES,0,6),e.bindVertexArray(null)}};var Da=class{constructor(e){this.doc=e}doc;glow=new _a;checker=new Ia;invalidate(){this.glow.invalidate(),this.checker.invalidate()}drawChecker(e,t,r){let o=this.findWorkspaceNode()?.bounds;o&&this.checker.draw(e,{view:t,vpt:r.vpt,left:o.left,top:o.top,width:o.width,height:o.height,zoom:Math.hypot(r.vpt[0],r.vpt[1]),dpr:r.dpr})}drawBackdrop(e,t,r){let o=this.findWorkspaceNode()?.bounds;o&&this.glow.draw(e,{view:t,vpt:r.vpt,cssWidth:r.cssWidth,cssHeight:r.cssHeight,left:o.left,top:o.top,width:o.width,height:o.height,zoom:Math.hypot(r.vpt[0],r.vpt[1]),dpr:r.dpr})}findWorkspaceNode(){let e=this.doc.nodes.find(t=>String(t.raw.id??"")===yn);return!e||!e.visible||!(e.bounds.width>0)||!(e.bounds.height>0)?null:e}};var jS=.02,VS=256,Zc=class n{domCanvasEl;exportStandInEl=null;get canvasEl(){return this.exportStandInEl??this.domCanvasEl}isExporting(){return this.exportStandInEl!==null}handle;batch;meshBatch;batchOrder;progressiveLoad=new ca({render:()=>this.render(),nodeCount:()=>this.doc.nodes.length,alive:()=>!this.disposed&&!this.contextLost,onProgressiveDone:e=>this.bus.fire("engine:progressive-done",e)});textures;gradientRamps;glyphAtlas;renderEpoch=new Pn;bakeKReuseFloor=0;decodeAnimated=null;sources;textRenderer;renderer;exporter;workspaceBackdrop;bus=new On;doc=new Po;dpr;mobileControls;interactive;vpt=[1,0,0,1,0,0];cssWidth=300;cssHeight=150;background;rafId=null;renderTimerId=null;contextLost=!1;disposed=!1;fontInvalidation;retainedFrame;chromeCache=null;interactions;interactionSuspended=!1;marquee=null;panning=!1;textEditing;tableCellEditing;snapGuide;rulerVisibleValue=!1;cropSessionController;expandSessionController;pathSessionController;warpSessionController;onWarpHistoryChange;animationPlaybackController;cellSelectionSink;constructor(e,t,r){Su(),this.domCanvasEl=e,this.domCanvasEl.style.display="block",this.handle=t,this.batch=new en(t.gl),this.meshBatch=new sa(t.gl),this.batchOrder=new ia(this.batch,this.meshBatch),this.batch.order=this.batchOrder,this.meshBatch.order=this.batchOrder,this.textures=new na(t.gl,{epoch:this.renderEpoch}),this.gradientRamps=new ta(t.gl),this.glyphAtlas=new Js(t.gl,()=>this.requestRenderAll(),o=>this.fontInvalidation.queueSettle(o),this.renderEpoch),this.dpr=r.dpr??(typeof window<"u"&&window.devicePixelRatio||1),this.mobileControls=r.mobileControls??!1,this.interactive=r.interactive??!0,this.background=r.background??[0,0,0,0],this.sources=new ka(this),this.textRenderer=new Aa(t.gl,this.batch,this.glyphAtlas),this.renderer=new Ma(this,this.sources,this.textRenderer),this.fontInvalidation=new Zs(this,this.textRenderer,this.glyphAtlas,this.renderer),this.retainedFrame=new ua(this),this.exporter=new La(this),this.workspaceBackdrop=new Da(this.doc),this.textEditing=new Ks(this),this.tableCellEditing=new qs(this),this.snapGuide=new Us(this,$a),this.cropSessionController=new Os(this),this.expandSessionController=new Bs(this),this.pathSessionController=new Hs(this),this.warpSessionController=new Gs(this),this.animationPlaybackController=new Vs(this),this.interactions=new Ns(this,this.snapGuide,this.sources,this.interactive),this.cellSelectionSink=o=>{this.doc.events.fire("table:cellselection",o)},te.cellSelectionSink=this.cellSelectionSink}static create(e,t={}){let r=null,o=Rm(e,{onLost:()=>r?.onContextLost(),onRestored:()=>r?.onContextRestored()});return o?(r=new n(e,o,t),r):null}onContextLost(){this.contextLost=!0,this.bus.fire("engine:context-lost")}onContextRestored(){this.contextLost=!1,this.recoverGlResources(),this.bus.fire("engine:context-restored"),this.requestRenderAll()}recoverGlResources(){this.retainedFrame.invalidate(),this.batch.rebuild(),this.meshBatch.rebuild(),this.textures.invalidateAll(),this.gradientRamps.invalidateAll(),this.glyphAtlas.reset(),this.sources.invalidateGlTextures(),this.renderer.invalidateGlResources(),this.workspaceBackdrop.invalidate()}invalidateNodeTextBakes(e){this.fontInvalidation.invalidateNodeTextBakes(e)}handleFontsLoaded(e){this.fontInvalidation.handleFontsLoaded(e)}get engineDisposed(){return this.disposed}get engineContextLost(){return this.contextLost}get pointerActive(){return this.interactions.pointerActive}get events(){return this.bus}get document(){return this.doc}get capabilities(){return{maxTextureSize:this.handle.capabilities.maxTextureSize,renderer:this.handle.capabilities.renderer}}get viewportTransform(){return[...this.vpt]}get zoom(){return this.vpt[0]}get gl(){return this.handle.gl}get viewSize(){return{width:this.cssWidth,height:this.cssHeight}}workspaceRect(){let e=this.doc.nodes.find(t=>String(t.raw.id??"")===yn)?.bounds;return e&&e.width>0&&e.height>0?{left:e.left,top:e.top,width:e.width,height:e.height}:{left:0,top:0,width:0,height:0}}cursorPoint(e){let t=this.canvasEl.getBoundingClientRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}get cropSession(){return this.cropSessionController.active?this.cropSessionController:null}get cropGhostNode(){return this.cropSessionController.target}get maskCropNode(){let e=this.cropSessionController.target;return e instanceof ae?e:null}get expandSession(){return this.expandSessionController.active?this.expandSessionController:null}get pathSession(){return this.pathSessionController.active?this.pathSessionController:null}get warpSession(){return this.warpSessionController.active?this.warpSessionController:null}get warpDebugSample(){return this.warpSessionController.debugBoundsSample}get warpDebugPreview(){return this.warpSessionController.debugPreviewInfo}get warpDebugAnchors(){return this.warpSessionController.debugAnchors}get warpSessionTarget(){return this.warpSessionController.target}get editingNode(){return this.doc.editingNode}get stats(){return{nodeCount:this.doc.nodes.length,skippedTypes:{...this.doc.skippedTypes}}}get diagnostics(){return{glError:this.handle.gl.getError(),drawnInstances:this.batch.drawnInstances,contextLost:this.contextLost}}get textureBudgetInfo(){return{textures:this.textures.stats(),atlas:this.glyphAtlas.stats()}}setTextureBudget(e){this.textures.setBudget(e)}toScene(e,t){return{x:(e-this.vpt[4])/this.vpt[0],y:(t-this.vpt[5])/this.vpt[3]}}toScreen(e,t){return{x:this.vpt[0]*e+this.vpt[4],y:this.vpt[3]*t+this.vpt[5]}}resize(e,t){e<=1||t<=1||(this.cssWidth=Math.max(1,e),this.cssHeight=Math.max(1,t),this.canvasEl.width=Math.round(this.cssWidth*this.dpr),this.canvasEl.height=Math.round(this.cssHeight*this.dpr),this.canvasEl.style.width=`${this.cssWidth}px`,this.canvasEl.style.height=`${this.cssHeight}px`,this.render())}progressiveFirstFrame(e=1e3,t=800){this.progressiveLoad.start(e,t)}async loadObjects(e){this.sources.releaseAnimatedSources(),this.animationPlaybackController.reset(),this.doc.loadObjects(e),await jc($c([...this.doc.nodes]),this.sources,()=>this.requestRenderAll())}async ensureNodeSources(e){await jc($c(e),this.sources,()=>this.requestRenderAll())}setViewportTransform(e){let t=this.vpt[0];this.vpt=[...e],this.renderer.noteVptChange(),e[0]!==t&&this.doc.setViewportZoom(e[0]),this.requestRenderAll()}zoomAt(e,t,r){let o=Math.min(VS,Math.max(jS,this.vpt[0]*r)),i=o/this.vpt[0];this.vpt=[o,0,0,o,e-i*(e-this.vpt[4]),t-i*(t-this.vpt[5])],this.renderer.noteVptChange(),this.doc.setViewportZoom(o),this.requestRenderAll()}pan(e,t){this.vpt[4]+=e,this.vpt[5]+=t,this.renderer.noteVptChange(),this.requestRenderAll()}noteExternalGesture(){this.renderer.noteExternalInteraction()}requestRenderAll(){this.progressiveLoad.absorbExternalRenderRequest(),!(this.rafId!==null||this.renderTimerId!==null||this.disposed||this.contextLost)&&(this.rafId=requestAnimationFrame(()=>{this.rafId=null,this.renderTimerId!==null&&(clearTimeout(this.renderTimerId),this.renderTimerId=null),this.render()}),this.renderTimerId=setTimeout(()=>{this.renderTimerId=null,this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.render()},250))}workspaceChromeNodes(){let e=this.doc.structureVersion;return(!this.chromeCache||this.chromeCache.version!==e)&&(this.chromeCache={version:e,nodes:this.doc.nodes.filter(tr)}),this.chromeCache.nodes}render(){if(this.disposed||this.contextLost||!this.batch.valid)return;this.fontInvalidation.consumePendingSettle(),this.textures.markFrame(this.pointerActive),this.glyphAtlas.markFrame(),this.snapGuide.settleMoveSnap();let e=performance.now();this.renderer.beginFrame(e),this.tickAnimation(e),Xa("engine.render",()=>{let t=this.handle.gl;t.viewport(0,0,this.canvasEl.width,this.canvasEl.height),t.clearColor(...this.background),t.clearStencil(0),t.clear(t.COLOR_BUFFER_BIT|t.STENCIL_BUFFER_BIT);let r=Kr(this.vpt,this.cssWidth,this.cssHeight,this.dpr);this.workspaceBackdrop.drawChecker(this.handle.gl,r,{vpt:this.vpt,cssWidth:this.cssWidth,cssHeight:this.cssHeight,dpr:this.dpr}),this.batch.begin(r,this.zoom*this.dpr),this.meshBatch.begin(r),this.batch.deferDraws=!0,this.meshBatch.deferDraws=!0,this.batchOrder.reset();let o=this.expandSessionController.active?this.expandSessionController.target:null;if(!(!o&&this.retainedFrame.tryRetainedFrame())){this.batch.begin(r,this.zoom*this.dpr),this.meshBatch.begin(r),this.batch.deferDraws=!0,this.meshBatch.deferDraws=!0,this.batchOrder.reset();let i=this.progressiveLoad.limit>=0?Math.min(this.progressiveLoad.limit,this.doc.nodes.length):this.doc.nodes.length;Ym(this.batch,this.renderer,this.doc.nodes,o?{target:o,underlay:()=>this.expandSessionController.buildUnderlay()}:null,i),this.batchOrder.requestSnapshot=!0,this.batchOrder.flushAll(),this.retainedFrame.captureSnapshot()}this.doc.drainRenderDirty(),this.workspaceBackdrop.drawBackdrop(this.handle.gl,r,{vpt:this.vpt,cssWidth:this.cssWidth,cssHeight:this.cssHeight,dpr:this.dpr}),Um(this.renderer,this.workspaceChromeNodes()),$m(this)}),this.retainedFrame.noteFrameRendered(),this.renderer.frame.bakeMore&&this.requestRenderAll(),this.bus.fire("engine:render",performance.now()-e)}readPixels(){return Hd(this.canvasEl)}exportToPixels(e){return this.retainedFrame.invalidate(),this.exporter.exportToPixels(e)}async exportToPixelsAsync(e){return this.retainedFrame.invalidate(),this.exporter.exportToPixelsAsync(e)}async exportRawPixelsAsync(e){return this.retainedFrame.invalidate(),this.exporter.exportRawPixelsAsync(e)}exportToCanvas(e){return this.retainedFrame.invalidate(),this.exporter.exportToCanvas(e)}drainGpuBacklog(){return this.exporter.drainGpuBacklog()}exportToDataURL(e,t="image/png",r){return this.retainedFrame.invalidate(),this.exporter.exportToDataURL(e,t,r)}get exportReady(){return!this.disposed&&!this.contextLost&&this.batch.valid}get sceneNodes(){return this.doc.nodes}applyExportViewport(e,t,r){let o=this.vpt,i=this.exportStandInEl;this.vpt=[...e];let s=document.createElement("canvas");return s.width=t,s.height=r,this.exportStandInEl=s,()=>{this.vpt=o,this.exportStandInEl=i}}measureFrames(e){return Wd(e,()=>this.render())}getSceneSummary(){return Bd(this.doc)}getTableCellEditingInfo(){return this.tableCellEditing.info}getTableSelectionInfo(){let e=this.doc.selection.length===1&&this.doc.selection[0]instanceof te?this.doc.selection[0]:null;return e?{tableId:e.id,cells:e.selectedCells.map(t=>({row:t.row,col:t.col})),anchor:e.cellAnchor?{...e.cellAnchor}:null,range:e.cellRange?{...e.cellRange}:null}:null}getSnapGuideInfo(){return this.snapGuide.info}enterExpandMode(e){this.cropSessionController.active&&this.cropSessionController.exit(),this.pathSessionController.active&&this.pathSessionController.exit();let t=e??this.doc.selection[0];return t?this.expandSessionController.enter(t):!1}exitExpandMode(){this.expandSessionController.exit()}getExpandInfo(){return this.expandSessionController.info}async applyExpandResult(e,t,r){let o=this.findNodeById(e);return!o||!o.isImageType&&!(o instanceof ae)?!1:this.expandSessionController.applyResult(o,t,r)}reloadImageElement(e){return this.sources.reloadNodeImage(e)}findNodeById(e){return this.doc.findNodeDeep(e)?.node??null}async reloadNodeImage(e){let t=this.findNodeById(e);return t?!!await this.sources.reloadNodeImage(t):!1}async reloadMaskClipImage(e){let t=this.findNodeById(e);return t instanceof ae?!!await this.sources.reloadMaskClipImage(t):!1}getCropInfo(){return this.cropSessionController.info}enterCropMode(e,t){this.pathSessionController.active&&this.pathSessionController.exit();let r=e??this.doc.selection[0];return r?this.cropSessionController.enter(r,t):!1}exitCropMode(){this.cropSessionController.exit()}setCropShape(e){this.cropSessionController.setCropShape(e)}updateCropScale(e){return this.cropSessionController.setScale(e)}setCropAspectRatio(e){this.cropSessionController.setAspectRatio(e)}enterPathEditMode(e){this.cropSessionController.active&&this.cropSessionController.exit(),this.expandSessionController.active&&this.expandSessionController.exit();let t=e??this.doc.selection[0];return t?this.pathSessionController.enter(t):!1}async enterWarpMode(e,t){this.cropSessionController.active&&this.cropSessionController.exit(),this.expandSessionController.active&&this.expandSessionController.exit(),this.pathSessionController.active&&this.pathSessionController.exit();let r=e??this.doc.selection[0];return r?this.warpSessionController.enter(r,t):!1}async loadImage(e,t){try{return await Je(e,t??null)}catch{return null}}async exitWarpMode(e){return this.warpSessionController.exit(e)}warpUndo(){return this.warpSessionController.undo()}warpRedo(){return this.warpSessionController.redo()}exitPathEditMode(){this.pathSessionController.exit()}getPathEditInfo(){return this.pathSessionController.info}setPathAnchorType(e,t,r){return this.pathSessionController.target===e?this.pathSessionController.setAnchorType(t,r):!1}highlightPathAnchor(e,t){this.pathSessionController.target===e&&this.pathSessionController.setActiveAnchor(t)}resetPathAnchorStyles(e){this.pathSessionController.target===e&&this.pathSessionController.resetAnchorStyles()}get rulerEnabled(){return this.rulerVisible}get rulerVisible(){return this.rulerVisibleValue}referenceLineDrag=null;rotateDrag=null;setRulerVisible(e){this.rulerVisibleValue!==e&&(this.rulerVisibleValue=e,this.requestRenderAll())}selectAll(){return Gd(this.doc,()=>this.requestRenderAll())}deleteSelection(){return Xd(this.doc,()=>this.requestRenderAll())}nudgeSelection(e,t){return zd(this.doc,e,t,()=>this.requestRenderAll())}getSelectionInfo(){return Dd(this.doc,this.marquee,this.zoom,(e,t)=>this.toScreen(e,t))}getActiveGroupChildInfo(){return Fd(this.doc)}getSvgRasterInfo(){return Od(this.doc,e=>this.sources.svgRasterFactorOf(e))}toObjects(){return this.doc.toObjects()}playAnimations(){this.animationPlaybackController.play()}pauseAnimations(){this.animationPlaybackController.pause()}stopAnimations(){this.animationPlaybackController.stop()}seekAnimations(e){this.animationPlaybackController.seek(e)}getAnimationPlaybackInfo(){return this.animationPlaybackController.info}getScrollTextPlaybackInfo(){return this.animationPlaybackController.scrollTextInfo}playSingleAnimation(e,t,r){return this.animationPlaybackController.playSingleAnimation(e,t,r)}stopSingleAnimation(e){this.animationPlaybackController.stopSingleAnimation(e)}getSingleAnimationPreviewInfo(){return this.animationPlaybackController.singlePreviewInfo}tickAnimation(e){this.animationPlaybackController.tick(e)&&(this.renderer.frame.animationActive=!0)}setEditingSelection(e,t){this.textEditing.setSelection(e,t)}settleMoveSnap(){this.snapGuide.settleMoveSnap()}finishSnapGesture(){this.snapGuide.finishGesture()}registerScalingSnap(e,t){this.snapGuide.registerScaling(e,t)}startCellEditing(e,t,r,o){return this.tableCellEditing.startEditing(e,t,r,o)}enterTextEditingAtClick(e,t,r){this.textEditing.enterEditingAtClick(e,t,r)}dispose(){this.disposed||(this.disposed=!0,this.cellSelectionSink&&te.cellSelectionSink===this.cellSelectionSink&&(te.cellSelectionSink=null),this.rafId!==null&&cancelAnimationFrame(this.rafId),this.renderTimerId!==null&&clearTimeout(this.renderTimerId),this.retainedFrame.dispose(),this.progressiveLoad.dispose(),this.interactions.dispose(),this.tableCellEditing.dispose(),this.cropSessionController.dispose(),this.expandSessionController.dispose(),this.pathSessionController.dispose(),this.textEditing.dispose(),this.bus.clear(),this.sources.releaseAnimatedSources(),this.batch.dispose(),this.meshBatch.dispose(),this.textures.dispose(),this.gradientRamps.dispose(),this.sources.dispose(),this.glyphAtlas.dispose(),this.handle.dispose())}};var tn=class n{constructor(e=0,t=0){this.x=e;this.y=t}x;y;add(e){return new n(this.x+e.x,this.y+e.y)}subtract(e){return new n(this.x-e.x,this.y-e.y)}scalarDivide(e){return new n(this.x/e,this.y/e)}rotate(e,t={x:0,y:0}){let r=Math.sin(e),o=Math.cos(e),i=this.subtract(t);return new n(i.x*o-i.y*r,i.x*r+i.y*o).add(t)}},Jc=class n{constructor(e=0,t=0){typeof e=="number"?(this.x=e,this.y=t):(this.x=e.x,this.y=e.y)}x=0;y=0;add(e){return new n(this.x+e.x,this.y+e.y)}subtract(e){return new n(this.x-e.x,this.y-e.y)}multiply(e){return new n(this.x*e.x,this.y*e.y)}divide(e){return new n(this.x/e.x,this.y/e.y)}scalarAdd(e){return new n(this.x+e,this.y+e)}scalarSubtract(e){return new n(this.x-e,this.y-e)}scalarMultiply(e){return new n(this.x*e,this.y*e)}scalarDivide(e){return new n(this.x/e,this.y/e)}rotate(e){let t=e*Math.PI/180,r=Math.cos(t),o=Math.sin(t);return new n(this.x*r-this.y*o,this.x*o+this.y*r)}dot(e){return this.x*e.x+this.y*e.y}midPointFrom(e){return new n((this.x+e.x)/2,(this.y+e.y)/2)}static lerp(e,t,r){return new n(e.x+(t.x-e.x)*r,e.y+(t.y-e.y)*r)}lerp(e,t){return new n(this.x+(e.x-this.x)*t,this.y+(e.y-this.y)*t)}eq(e){return this.x===e.x&&this.y===e.y}lt(e){return this.x<e.x&&this.y<e.y}gt(e){return this.x>e.x&&this.y>e.y}lte(e){return this.x<=e.x&&this.y<=e.y}gte(e){return this.x>=e.x&&this.y>=e.y}distanceFrom(e){return Math.hypot(this.x-e.x,this.y-e.y)}clone(){return new n(this.x,this.y)}toString(){return`${this.x} ${this.y}`}transform(e,t=!1){return t?new n(e[0]*this.x+e[2]*this.y,e[1]*this.x+e[3]*this.y):new n(e[0]*this.x+e[2]*this.y+e[4],e[1]*this.x+e[3]*this.y+e[5])}};var nn=(n,e=0)=>typeof n=="number"&&Number.isFinite(n)?n:e,qS=n=>({sx:nn(n.scaleX,1)||1,sy:nn(n.scaleY,1)||1}),Ip=n=>{let e=n.pathOffset;return!e||typeof e.x!="number"||typeof e.y!="number"?null:{x:e.x,y:e.y}},KS=n=>{let e=Ce(n),t=e?Fe(e):null;return t?{x:(t.left+t.right)/2,y:(t.top+t.bottom)/2}:null},QS=n=>{if(n.length===0)return null;let e=1/0,t=1/0,r=-1/0,o=-1/0;for(let i of n)e>i.x&&(e=i.x),t>i.y&&(t=i.y),r<i.x&&(r=i.x),o<i.y&&(o=i.y);return{x:(e+r)/2,y:(t+o)/2}},ZS=(n,e,t,r)=>`M ${t} 0 L ${n-t} 0 A ${t} ${r} 0 0 1 ${n} ${r} L ${n} ${e-r} A ${t} ${r} 0 0 1 ${n-t} ${e} L ${t} ${e} A ${t} ${r} 0 0 1 0 ${e-r} L 0 ${r} A ${t} ${r} 0 0 1 ${t} 0 Z`,_p=(n,e)=>`M 0 ${-e} A ${n} ${e} 0 1 1 0 ${e} A ${n} ${e} 0 1 1 0 ${-e} Z`,eu=n=>{if(n.isTextType)return;let e=n.raw,t=se(e),{sx:r,sy:o}=qS(e);if(t===L.PATH){let a="";if(typeof e.path=="string")a=e.path;else if(Array.isArray(e.path)){let l=[];for(let u of e.path)!Array.isArray(u)||typeof u[0]!="string"||l.push(u.length===1?u[0]:`${u[0]} ${u.slice(1).join(" ")}`);a=l.join(" ")}return a.trim()?{path:a,pathOffset:Ip(e)??KS(a)??{x:0,y:0}}:void 0}if(t===L.RECT||t===L.FABRICRECT){let a=n.dims.x*r,l=n.dims.y*o;if(!(a>0)||!(l>0))return;let u=it(e,n.dims.x,n.dims.y),c=u?Math.min(u.rx*r,a/2):0,h=u?Math.min(u.ry*o,l/2):0;return{path:c>0||h>0?ZS(a,l,c,h):`M 0 0 L ${a} 0 L ${a} ${l} L 0 ${l} Z`,pathOffset:{x:a/2,y:l/2}}}if(t===L.CIRCLE){let a=nn(e.radius);return a>0?{path:_p(a*r,a*o),pathOffset:{x:0,y:0}}:void 0}if(t===L.ELLIPSE){let a=(nn(e.rx)||n.dims.x/2)*r,l=(nn(e.ry)||n.dims.y/2)*o;return!(a>0)||!(l>0)?void 0:{path:_p(a,l),pathOffset:{x:0,y:0}}}if(t===L.TRIANGLE){let a=n.dims.x*r,l=n.dims.y*o;return!(a>0)||!(l>0)?void 0:{path:`M ${-a/2} ${l/2} L 0 ${-l/2} L ${a/2} ${l/2} Z`,pathOffset:{x:0,y:0}}}if(t===L.POLYGON||t===L.POLYLINE){let a=Array.isArray(e.points)?e.points:[];return a.length===0?{path:"M 0 0",pathOffset:{x:0,y:0}}:{path:a.map((u,c)=>`${c===0?"M":"L"} ${u.x} ${u.y}`).join(" ")+(t===L.POLYGON?" Z":""),pathOffset:Ip(e)??QS(a)??{x:0,y:0}}}if(t===L.LINE){let a=nn(e.x1),l=nn(e.y1),u=nn(e.x2),c=nn(e.y2);return{path:`M ${a} ${l} L ${u} ${c}`,pathOffset:{x:0,y:0}}}let i=n.dims.x*r,s=n.dims.y*o;if(!(!(i>0)||!(s>0)))return{path:`M 0 0 L ${i} 0 L ${i} ${s} L 0 ${s} Z`,pathOffset:{x:i/2,y:s/2}}};var Dp=n=>{if(!(!n||n.length<8||n.some(e=>typeof e!="number"||!Number.isFinite(e))))return{tl:{x:n[0],y:n[1]},tr:{x:n[2],y:n[3]},br:{x:n[4],y:n[5]},bl:{x:n[6],y:n[7]}}},Fp=n=>{let e=[n.tl,n.tr,n.br,n.bl],t=Math.min(...e.map(s=>s.x)),r=Math.min(...e.map(s=>s.y)),o=Math.max(...e.map(s=>s.x)),i=Math.max(...e.map(s=>s.y));return{minX:t,minY:r,width:Math.max(1,Math.ceil(o-t)),height:Math.max(1,Math.ceil(i-r))}},Op=(n,e,t)=>({tl:{x:n.tl.x+e,y:n.tl.y+t},tr:{x:n.tr.x+e,y:n.tr.y+t},br:{x:n.br.x+e,y:n.br.y+t},bl:{x:n.bl.x+e,y:n.bl.y+t}}),Bp=n=>{let e=n.tr.x+n.bl.x-n.tl.x,t=n.tr.y+n.bl.y-n.tl.y;return Math.abs(e-n.br.x)<.01&&Math.abs(t-n.br.y)<.01},tu=n=>{let e=n.tl.x-n.tr.x+n.br.x-n.bl.x,t=n.tl.y-n.tr.y+n.br.y-n.bl.y;if(Math.abs(e)<1e-6&&Math.abs(t)<1e-6)return{a:n.tr.x-n.tl.x,b:n.bl.x-n.tl.x,c:n.tl.x,d:n.tr.y-n.tl.y,e:n.bl.y-n.tl.y,f:n.tl.y,g:0,h:0};let r=n.tr.x-n.br.x,o=n.tr.y-n.br.y,i=n.bl.x-n.br.x,s=n.bl.y-n.br.y,a=r*s-i*o;if(Math.abs(a)<1e-6)return;let l=(e*s-i*t)/a,u=(r*t-e*o)/a;return{a:n.tr.x-n.tl.x+l*n.tr.x,b:n.bl.x-n.tl.x+u*n.bl.x,c:n.tl.x,d:n.tr.y-n.tl.y+l*n.tr.y,e:n.bl.y-n.tl.y+u*n.bl.y,f:n.tl.y,g:l,h:u}},jr=(n,e,t)=>{let r=n.g*e+n.h*t+1;return{x:(n.a*e+n.b*t+n.c)/r,y:(n.d*e+n.e*t+n.f)/r}},Wp=n=>{let{a:e,b:t,c:r,d:o,e:i,f:s,g:a,h:l}=n,u=e*(i-s*l)-t*(o-s*a)+r*(o*l-i*a);if(Math.abs(u)<1e-6)return;let c=(i-s*l)/u,h=(r*l-t)/u,d=(t*s-r*i)/u,f=(s*a-o)/u,m=(e-r*a)/u,p=(r*o-e*s)/u,b=(o*l-i*a)/u,x=(t*a-e*l)/u,g=(e*i-t*o)/u;if(!(Math.abs(g)<1e-6))return{a:c/g,b:h/g,c:d/g,d:f/g,e:m/g,f:p/g,g:b/g,h:x/g}};var Hp=32,Gp=120,nu=1e-6,JS=()=>{let n=document.createElement("canvas");if(!n||typeof n.getContext>"u")throw new Error("Failed to create `canvas` element");return n},ev=n=>{let e=JS();return e.width=n.width,e.height=n.height,e.getContext("2d",{willReadFrequently:!0})?.drawImage(n,0,0),e},tv=(n,e,t)=>n.toDataURL?.(`image/${e}`,t),nv=n=>new Promise((e,t)=>{let r=new FileReader;r.onload=()=>e(String(r.result)),r.onerror=()=>t(r.error),r.readAsDataURL(n)}),Xp=async(n,e,t)=>{try{let r=await new Promise(o=>n.toBlob(o,`image/${e}`,t));if(r)return await nv(r)}catch{}return tv(n,e,t)},rv=(n,e,t)=>{let r=Math.max(1,n.width),o=Math.max(1,n.height),i=Math.max(1,Math.round(e)),s=Math.max(1,Math.round(t));if(Math.abs(r-i)<nu&&Math.abs(o-s)<nu)return n;let a=document.createElement("canvas");a.width=i,a.height=s;let l=a.getContext("2d");return l?(l.imageSmoothingEnabled=!0,l.imageSmoothingQuality="high",l.drawImage(n,0,0,r,o,0,0,i,s),a):n},ov=(n,e,t,r,o)=>{let i=Math.max(0,Math.min(e-1,r)),s=Math.max(0,Math.min(t-1,o)),a=Math.floor(i),l=Math.floor(s),u=Math.min(e-1,a+1),c=Math.min(t-1,l+1),h=i-a,d=s-l,f=(l*e+a)*4,m=(l*e+u)*4,p=(c*e+a)*4,b=(c*e+u)*4,x=1-d,g=1-h,y=g*x,v=h*x,S=g*d,w=h*d;return[n[f]*y+n[m]*v+n[p]*S+n[b]*w,n[f+1]*y+n[m+1]*v+n[p+1]*S+n[b+1]*w,n[f+2]*y+n[m+2]*v+n[p+2]*S+n[b+2]*w,n[f+3]*y+n[m+3]*v+n[p+3]*S+n[b+3]*w]},iv=(n,e,t)=>{let r=tu(t),o=r?Wp(r):void 0;if(!o){Yp(n,e,t,Hp);return}let i=Math.max(1,e.width),s=Math.max(1,e.height),a=e.getContext("2d",{willReadFrequently:!0});if(!a){Yp(n,e,t,Hp);return}let l=a.getImageData(0,0,i,s),u=n.createImageData(n.canvas.width,n.canvas.height),c=u.data;for(let h=0;h<n.canvas.height;h++)for(let d=0;d<n.canvas.width;d++){let f=jr(o,d+.5,h+.5);if(f.x<0||f.x>1||f.y<0||f.y>1)continue;let m=f.x*(i-1),p=f.y*(s-1),b=ov(l.data,i,s,m,p),x=(h*n.canvas.width+d)*4;c[x]=b[0],c[x+1]=b[1],c[x+2]=b[2],c[x+3]=b[3]}n.putImageData(u,0,0)},zp=(n,e,t,r)=>{let[o,i,s]=t,[a,l,u]=r,c=o.x*(i.y-s.y)+i.x*(s.y-o.y)+s.x*(o.y-i.y);if(Math.abs(c)<nu)return;let h=(a.x*(i.y-s.y)+l.x*(s.y-o.y)+u.x*(o.y-i.y))/c,d=(a.y*(i.y-s.y)+l.y*(s.y-o.y)+u.y*(o.y-i.y))/c,f=(a.x*(s.x-i.x)+l.x*(o.x-s.x)+u.x*(i.x-o.x))/c,m=(a.y*(s.x-i.x)+l.y*(o.x-s.x)+u.y*(i.x-o.x))/c,p=(a.x*(i.x*s.y-s.x*i.y)+l.x*(s.x*o.y-o.x*s.y)+u.x*(o.x*i.y-i.x*o.y))/c,b=(a.y*(i.x*s.y-s.x*i.y)+l.y*(s.x*o.y-o.x*s.y)+u.y*(o.x*i.y-i.x*o.y))/c;n.save(),n.beginPath(),n.moveTo(a.x,a.y),n.lineTo(l.x,l.y),n.lineTo(u.x,u.y),n.closePath(),n.clip(),n.setTransform(h,d,f,m,p,b),n.drawImage(e,0,0),n.restore()},Yp=(n,e,t,r)=>{let o=tu(t);if(!o){n.drawImage(e,0,0,n.canvas.width,n.canvas.height);return}let i=Math.max(1,e.width),s=Math.max(1,e.height),a=Math.min(Gp,Math.max(1,Math.ceil(i/r))),l=Math.min(Gp,Math.max(1,Math.ceil(s/r)));for(let u=0;u<l;u++){let c=u/l,h=(u+1)/l,d=c*s,f=h*s;for(let m=0;m<a;m++){let p=m/a,b=(m+1)/a,x=p*i,g=b*i,y=jr(o,p,c),v=jr(o,b,c),S=jr(o,b,h),w=jr(o,p,h);zp(n,e,[{x,y:d},{x:g,y:d},{x:g,y:f}],[y,v,S]),zp(n,e,[{x,y:d},{x:g,y:f},{x,y:f}],[y,S,w])}}},sv=async(n,e,t={})=>{let r=t.quality??.92,o=t.format||"webp",i=Math.max(1,n.width),s=Math.max(1,n.height),a=Math.max(1,e?.width||i),l=Math.max(1,e?.height||s),u=rv(n,a,l),c=Dp(e?.nonAffineTransform||e?.transform);if(!c){let x=ev(n);return{src:await Xp(x,o,r),width:i,height:s,sourceWidth:a,sourceHeight:l}}let h=Fp(c),d=Op(c,-h.minX,-h.minY),f=t.objectBounds,m=document.createElement("canvas");m.width=h.width,m.height=h.height;let p=m.getContext("2d");if(!p)throw new Error("无法创建智能对象渲染画布");if(p.imageSmoothingEnabled=!0,p.imageSmoothingQuality="high",Bp(d)){let x=(d.tr.x-d.tl.x)/a,g=(d.tr.y-d.tl.y)/a,y=(d.bl.x-d.tl.x)/l,v=(d.bl.y-d.tl.y)/l,S=d.tl.x,w=d.tl.y;p.setTransform(x,g,y,v,S,w),p.drawImage(u,0,0)}else iv(p,u,d);let b;if(f){let x=Math.round(f.left-h.minX),g=Math.round(f.top-h.minY),y=Math.max(1,Math.round(f.width)),v=Math.max(1,Math.round(f.height));if(x>=0&&g>=0&&x+y<=h.width+1&&g+v<=h.height+1){b=document.createElement("canvas"),b.width=y,b.height=v;let w=b.getContext("2d");w&&w.drawImage(m,x,g,y,v,0,0,y,v)}else{b=document.createElement("canvas"),b.width=y,b.height=v;let w=b.getContext("2d");w&&(w.imageSmoothingEnabled=!0,w.imageSmoothingQuality="high",w.drawImage(m,0,0,h.width,h.height,0,0,y,v))}}else b=m;return{src:await Xp(b,o,r),width:b.width,height:b.height,sourceWidth:a,sourceHeight:l}};var ce=n=>n.node instanceof te?n.node:null,Be=n=>n.raw,Pt=n=>{n.canvas?.requestRenderAll?.()},je=(n,e)=>{let t=Be(e);n.set({cellData:t.cellData??[],rows:t.rows,cols:t.cols}),Pt(n)},ru=n=>n.rows??3,ou=n=>n.cols??3,Vr=n=>(Array.isArray(n.cellData)||(n.cellData=[]),n.cellData),ei=(n,e,t)=>{let r=we(n.cellMap,e,t);if(r)return r.isMerged&&r.mergeParent?we(n.cellMap,r.mergeParent.row,r.mergeParent.col):r},Gt=(n,e)=>{let t=ce(n);if(!t||!t.selectedCells.length)return;let r=new Set;for(let o of t.selectedCells){let i=lt(t.cellMap,o.row,o.col),s=`${i.row},${i.col}`;if(r.has(s))continue;r.add(s);let a=we(t.cellMap,i.row,i.col);a&&e(a)}je(n,t)},iu=(n,e,t)=>({get id(){return`${n.id}-r${e.row}c${e.col}-rect`},get _isCell(){return!0},get _row(){return e.row},get _col(){return e.col},get fill(){return e.fill},set fill(r){e.fill=r,t()},get stroke(){return e.stroke},set stroke(r){e.stroke=r,t()},get strokeWidth(){return e.strokeWidth??1},set strokeWidth(r){e.strokeWidth=r,t()},get _colspan(){return e.colspan??1},set _colspan(r){e.colspan=r,t()},get _rowspan(){return e.rowspan??1},set _rowspan(r){e.rowspan=r,t()},get _isMerged(){return e.isMerged??!1},set _isMerged(r){e.isMerged=r,t()},get _mergeParent(){return e.mergeParent??null},set _mergeParent(r){e.mergeParent=r,t()},get _hasCustomFill(){return e.hasCustomFill??!1},set _hasCustomFill(r){e.hasCustomFill=r,t()},get _hasCustomStroke(){return e.hasCustomStroke??!1},set _hasCustomStroke(r){e.hasCustomStroke=r,t()},set(r){for(let[o,i]of Object.entries(r))o!=="dirty"&&(e[o]=i);t()},get(r){return e[r]}}),Up=(n,e,t)=>({get id(){return`${n.id}-r${e.row}c${e.col}-text`},get _isCellText(){return!0},get _row(){return e.row},get _col(){return e.col},get text(){return e.text??""},set text(r){e.text=r,t()},get fill(){return e.textFill},set fill(r){e.textFill=r,t()},get fontSize(){return e.fontSize??Be(n).fontSize??14},set fontSize(r){e.fontSize=r,t()},get fontWeight(){return e.fontWeight},set fontWeight(r){e.fontWeight=r,t()},get fontFamily(){return e.fontFamily},set fontFamily(r){e.fontFamily=r,t()},get fontStyle(){return e.fontStyle},set fontStyle(r){e.fontStyle=r,t()},get textAlign(){return e.textAlign},set textAlign(r){e.textAlign=r,t()},get underline(){return e.underline??!1},set underline(r){e.underline=r,t()},get linethrough(){return e.linethrough??!1},set linethrough(r){e.linethrough=r,t()},get verticalAlign(){return e.verticalAlign??"middle"},set verticalAlign(r){e.verticalAlign=r,t()},set(r){for(let[o,i]of Object.entries(r))o!=="dirty"&&(o==="fill"?e.textFill=i:e[o]=i);t()},get(r){return r==="fill"?e.textFill:e[r]},setFontFamily(r){e.fontFamily=r,t()},refreshTextDimensions(){}}),av={canMergeCells(){let n=ce(this);return!!n&&n.selectedCells.length>1},canUseMergeCells(){let n=ce(this);if(!n||!n.selectedCells.length)return!1;let e=new Set,t=!1;for(let{row:r,col:o}of n.selectedCells){let i=ei(n,r,o);if(!i)return!1;(i.colspan??1)>1||(i.rowspan??1)>1?e.add(`${i.row},${i.col}`):t=!0}return!t&&e.size===1},canSplitRows(){let n=ce(this);if(!n||!n.selectedCells.length)return!1;let e=n.selectedCells[0],t=ei(n,e.row,e.col);return!!t&&(t.rowspan??1)>1},canSplitColumns(){let n=ce(this);if(!n||!n.selectedCells.length)return!1;let e=n.selectedCells[0],t=ei(n,e.row,e.col);return!!t&&(t.colspan??1)>1},isSelectColumn(){let n=ce(this);if(!n||!n.selectedCells.length)return!1;let e=new Set(n.selectedCells.map(r=>r.row)),t=new Set(n.selectedCells.map(r=>r.col));if(t.size===1){let r=Array.from(e),o=Math.min(...r),i=Math.max(...r),s=o===0&&i===ru(Be(n))-1,a=e.size>=2,l=!1;for(let u of n.selectedCells)if((ei(n,u.row,u.col)?.rowspan??1)>1){l=!0;break}return s||a||l}return t.size>1?e.size===1?!1:e.size<=t.size:!1},isSelectRow(){let n=ce(this);if(!n||!n.selectedCells.length)return!1;let e=new Set(n.selectedCells.map(r=>r.row)),t=new Set(n.selectedCells.map(r=>r.col));if(e.size===1){let r=Array.from(t),o=Math.min(...r),i=Math.max(...r),s=o===0&&i===ou(Be(n))-1,a=t.size>=2,l=!1;for(let u of n.selectedCells)if((ei(n,u.row,u.col)?.colspan??1)>1){l=!0;break}return s||a||l}return e.size>1?t.size===1?!1:e.size>t.size:!1},isRowSelected(n){let e=ce(this);return e?kr(e.cellMap,e.selectedCells).rows.has(n):!1},isColumnSelected(n){let e=ce(this);return e?kr(e.cellMap,e.selectedCells).cols.has(n):!1},selectCell(n,e,t=!1){let r=ce(this);if(r){if(t){if(r.cellAnchor){let o=r.cellAnchor,i=xn(r.cellMap,o,{row:n,col:e});r.setCellSelection(i,o,{r1:Math.min(o.row,n),r2:Math.max(o.row,n),c1:Math.min(o.col,e),c2:Math.max(o.col,e)})}}else{let o={row:n,col:e};r.setCellSelection([o],o,{r1:n,r2:n,c1:e,c2:e})}Pt(this)}},selectColumn(n){let e=ce(this);e&&(e.setColumnSelection(n),Pt(this))},selectRow(n){let e=ce(this);e&&(e.setRowSelection(n),Pt(this))},selectAllCells(){let n=ce(this);if(!n)return;let e=n.tableView,t=Eo(n.cellMap,e.rows,e.cols);n.setCellSelection(t,t[0]??null,Xe(t)),Pt(this)},clearCellSelection(){let n=ce(this);n&&(n.clearCellSelection(),Pt(this))},buildSelectionRange(n,e){let t=ce(this);return t?xn(t.cellMap,n,e):[]},mergeCells(n,e,t,r){let o=ce(this);if(!o)return;let i=go(o.raw,n,e,t,r),s={row:i.r1,col:i.c1};o.setCellSelection([s],s,i),je(this,o)},unmergeCells(n,e){let t=ce(this);if(!t||!yo(t.raw,n,e))return;let r={row:n,col:e};t.setCellSelection([r],r,{r1:n,r2:n,c1:e,c2:e}),je(this,t)},addRow(n){let e=ce(this);e&&(So(e.raw,n??ru(Be(e))),je(this,e))},removeRow(n){let e=ce(this);if(!e)return;let t=n??ru(Be(e))-1;if(!Pl(e.raw,t))return;let r=Ui(e.selectedCells,e.cellRange,t,"row");r?e.setCellSelection(r.cells,r.cells[0]??null,r.range):e.clearCellSelection(),je(this,e)},addColumn(n){let e=ce(this);e&&(vo(e.raw,n??ou(Be(e))),je(this,e))},removeColumn(n){let e=ce(this);if(!e)return;let t=n??ou(Be(e))-1;if(!kl(e.raw,t))return;let r=Ui(e.selectedCells,e.cellRange,t,"col");r?e.setCellSelection(r.cells,r.cells[0]??null,r.range):e.clearCellSelection(),je(this,e)},setColumnWidth(n,e){let t=ce(this);t&&(bo(t.raw,n,e),this.set({columnWidths:Be(t).columnWidths??[]}),Pt(this))},setRowHeight(n,e){let t=ce(this);t&&(xo(t.raw,n,e),this.set({manualRowHeights:Be(t).manualRowHeights??[]}),Pt(this))},setSelectWidth(n){let e=ce(this);if(!e)return;let t=e.cellRange,r=Be(e),o=e.tableView;if(!t||o.cols<=0){this.setTableWidth(n);return}let i=r.minCellWidth??40,s=r.cellStrokeWidth??0,a=0;for(let c=t.c1;c<=t.c2;c++)a+=o.columnWidths[c]??0;if(a<=0)return;let l=(n-s-(t.c2-t.c1)*o.cellSpacing)/a,u=[...o.columnWidths];for(let c=t.c1;c<=t.c2;c++)u[c]=Math.max(i,(u[c]??0)*l);this.set({columnWidths:u}),Pt(this)},setSelectHeight(n){let e=ce(this);if(!e)return;let t=e.cellRange,r=Be(e),o=e.tableView;if(!t||o.rows<=0){this.setTableHeight(n);return}let i=r.minCellHeight??40,s=r.cellStrokeWidth??0,a=0;for(let c=t.r1;c<=t.r2;c++)a+=o.rowHeights[c]??0;if(a<=0)return;let l=(n-s-(t.r2-t.r1)*o.cellSpacing)/a,u=Array.from({length:o.rows},(c,h)=>{let d=Array.isArray(r.manualRowHeights)?r.manualRowHeights[h]:null;return typeof d=="number"?d:null});for(let c=t.r1;c<=t.r2;c++)u[c]=Math.max(i,(o.rowHeights[c]??0)*l);this.set({manualRowHeights:u}),Pt(this)},getColumnWidth(n){let e=ce(this);return e?e.tableView.columnWidths[n]??0:0},getRowHeight(n){let e=ce(this);return e?e.tableView.rowHeights[n]??0:0},getRowMinHeight(n){let e=ce(this);return e?e.getRowMinHeight(n):0},relayout(){let n=ce(this);n&&(n.rebuildTable(),Pt(this))},previewLayout(){this.relayout()},getCell(n,e){let t=ce(this);if(!t)return;let r=we(t.cellMap,n,e);return r?iu(t,r,()=>je(this,t)):void 0},getCellText(n,e){let t=ce(this);if(!t)return;let r=we(t.cellMap,n,e);return r?Up(t,r,()=>je(this,t)):void 0},setSelectionTextAlign(n){Gt(this,e=>{e.textAlign=n})},setSelectionFontSize(n){Gt(this,e=>{e.fontSize=n})},changeSelectionFontSize(n){let e=ce(this);if(!e)return;let t=Be(e).fontSize??14;Gt(this,r=>{let o=Number(r.fontSize)||t;r.fontSize=n==="+"?o+1:Math.max(1,o-1)})},setSelectionFontWeight(n){Gt(this,e=>{e.fontWeight=n})},setSelectionFontStyle(n){Gt(this,e=>{e.fontStyle=n})},setSelectionUnderline(n){Gt(this,e=>{e.underline=n})},setSelectionLinethrough(n){Gt(this,e=>{e.linethrough=n})},setSelectionCellFill(n){Gt(this,e=>{e.fill=n,e.hasCustomFill=!0})},setSelectionCellStroke(n){Gt(this,e=>{e.stroke=n,e.hasCustomStroke=!0})},setSelectionCellStrokeWidth(n){Gt(this,e=>{e.strokeWidth=n,e.hasCustomStroke=!0})},updateCellFill(n){let e=ce(this);if(!e)return;let t=Be(e);t.cellFill=n;for(let r of Vr(t))!r.isMerged&&!r.hasCustomFill&&(r.fill=n);je(this,e)},updateCellTextFill(n){let e=ce(this);if(!e)return;let t=Be(e);t.textFill=n;for(let r of Vr(t))r.hasCustomTextFill||(r.textFill=n);je(this,e)},updateCellStroke(n){let e=ce(this);if(!e)return;let t=Be(e);t.cellStroke=n;for(let r of Vr(t))r.hasCustomStroke||(r.stroke=n);je(this,e)},updateBorderWidth(n){let e=ce(this);e&&(Be(e).cellStrokeWidth=n,je(this,e))},applyTextStylesToAll(n){let e=ce(this);if(!e)return;let t=Be(e),r={...t.textDefaults??{}};for(let[o,i]of Object.entries(n))r[o]=i;t.textDefaults=r;for(let o of Vr(t))for(let[i,s]of Object.entries(n))i==="fill"?o.textFill=s:o[i]=s;je(this,e)}},lv={selectedCells(){let n=ce(this);if(n)return n.selectedCells.map(e=>{let t=we(n.cellMap,e.row,e.col);return t?iu(n,t,()=>je(this,n)):void 0}).filter(e=>e!==void 0)},_selectedCells(){let n=ce(this);return n?n.selectedCells:void 0},_selectionRange(){let n=ce(this);return n?n.cellRange:void 0},hasSelection(){let n=ce(this);return n?n.hasCellSelection:!1},selectionCount(){let n=ce(this);return n?n.selectedCells.length:0},cellTexts(){let n=ce(this);if(!n)return;let e=()=>je(this,n);return Vr(Be(n)).map(t=>Up(n,t,e))},cells(){let n=ce(this);if(!n)return;let e=()=>je(this,n);return Vr(Be(n)).map(t=>iu(n,t,e))},columnWidths(){let n=ce(this);return n?[...n.tableView.columnWidths]:void 0},rowHeights(){let n=ce(this);return n?[...n.tableView.rowHeights]:void 0}},su=n=>{for(let[e,t]of Object.entries(av))Object.assign(n,{[e]:t});for(let[e,t]of Object.entries(lv))Object.defineProperty(n,e,{get:t,configurable:!0,enumerable:!1})};var au=(n,e,t)=>{let r=Ge(e);if(!r)return null;let o=Et(n,e,t),i=r==="circle"||(typeof e.curvature=="number"?e.curvature:300)>0,s=o.contentOffsetX-o.width/2,a=o.contentOffsetX+o.width/2,l=o.contentOffsetY-o.height/2,u=o.contentOffsetY+o.height/2,c=n.lines.map(()=>[]);for(let h of o.chars){let d=c[h.line];if(!d)continue;let f={char:h.char,charAngle:i?-h.rotation:-(h.rotation+Math.PI),leftAngle:0,rightAngle:0,charRadius:0,bottomRadius:0,topRadius:0,lineRadius:0,cl:{x:h.x,y:h.y},tl:{x:s,y:l},br:{x:a,y:u},bl:{x:h.x,y:h.y},tr:{x:h.x,y:h.y},nl:{x:h.x,y:h.y},nr:{x:h.x,y:h.y},lc:{x:h.x,y:h.y}};d.push(f)}for(let h of c){let d=h[h.length-1];h.push({char:"",charAngle:0,leftAngle:0,rightAngle:0,charRadius:0,bottomRadius:0,topRadius:0,lineRadius:0,cl:d?{...d.cl}:{x:s,y:l},tl:{x:s,y:l},br:{x:a,y:u},bl:{x:s,y:l},tr:{x:a,y:u},nl:{x:s,y:l},nr:{x:a,y:u},lc:{x:s,y:l}})}return c};var cv=n=>{let e=n.textLines,t=n.charBounds,r=n.lineHeights;if(!Array.isArray(e)||!Array.isArray(t)||!Array.isArray(r)||e.length===0||t.length!==e.length||r.length!==e.length)return!1;for(let o=0;o<e.length;o++)if(typeof e[o]!="string"||!Array.isArray(t[o])||t[o].length===0||typeof r[o]!="number"||!Number.isFinite(r[o]))return!1;return!0},hr=class{node;ctx;constructor(e,t){this.node=e,this.ctx=t}set(e,t){let r=typeof e=="string"?{[e]:t}:{...e},o=r.__isCropping&&this.ctx.cropSessionNodeId?.()!==this.node.id?this.toObject():void 0;if("cropAspectRatio"in r){let s={cropAspectRatio:r.cropAspectRatio};delete r.cropAspectRatio,this.ctx.setNodeProps(this.node,s)}if("_cropKey"in r){let s=r._cropKey;delete r._cropKey,this.ctx.applyCropShape?.(this.node,typeof s=="string"&&s?s:null)}if("__isCropping"in r){let s=!!r.__isCropping;delete r.__isCropping,this.clearSessionFlagDirty("__isCropping"),this.__isCropping=s,o&&this.__isCropping&&(this.cropBeforeState=o)}if("__isExpand"in r){let s=!!r.__isExpand;delete r.__isExpand,this.clearSessionFlagDirty("__isExpand"),this.__isExpand=s}if(typeof r.width=="number"&&Or(this.node)){let s=r.width;delete r.width,this.ctx.setGroupWidth?this.ctx.setGroupWidth(this.node,s):this.ctx.setNodeProps(this.node,{width:s})}this.bumpTextboxWidthToLayoutBox(r),this.bridgeImageSizeProps(r);let i=r;if((typeof r.width=="number"||typeof r.height=="number"||typeof r.scaleX=="number"||typeof r.scaleY=="number")&&!("clipImage"in r)&&ot.has(se(this.node.raw))){let s=Xt(this.node),a=this.node.raw,l=Number(a.width)||0,u=Number(a.height)||0,c=this.node.clipImageEl,h=c?.naturalWidth||Number(s?.width)||0,d=c?.naturalHeight||Number(s?.height)||0;if(s&&l>0&&u>0&&h>0&&d>0){typeof r.scaleX=="number"&&r.scaleX>0&&!("width"in r)&&(r.width=l*r.scaleX,r.scaleX=1),typeof r.scaleY=="number"&&r.scaleY>0&&!("height"in r)&&(r.height=u*r.scaleY,r.scaleY=1);let f=typeof r.width=="number"?r.width:l,m=typeof r.height=="number"?r.height:u;if(f>0&&m>0){let p=(g,y)=>Math.max(g/h,y/d),b=Number(s.scaleX)||1,x=p(f,m)*(b/p(l,u));i={...r,clipImage:{...s,scaleX:x,scaleY:x}}}}}return Object.keys(i).length>0&&this.ctx.setNodeProps(this.node,i),this}bumpTextboxWidthToLayoutBox(e){if(typeof e.width!="number"||!(this.node instanceof Se)||e.width<0||se(this.node.raw)!==L.TEXTBOX||Ge(this.node.raw))return;let r=e.width;delete e.width,this.ctx.setNodeProps(this.node,{width:r});let o=this.node.dims.x;Number.isFinite(o)&&o>r+.01&&this.ctx.setNodeProps(this.node,{width:o})}clearSessionFlagDirty(e){this.node.raw[e]!==void 0&&this.ctx.setNodeProps(this.node,{[e]:void 0})}get(e){return this.node.raw[e]}setCoords(){}getCenterPoint(){return{...this.node.center}}getRelativeCenterPoint(){return new tn(this.node.center.x,this.node.center.y)}translateToOriginPoint(e,t="center",r="center"){let o=c=>c==="left"||c==="top"?-.5:c==="right"||c==="bottom"?.5:0,i=o(t),s=o(r),a=i||s?this._getTransformedDimensions():new tn(0,0),l=new tn(e.x+i*a.x,e.y+s*a.y),u=this.node.raw.angle;return typeof u=="number"&&u&&(l=l.rotate(u*Math.PI/180,e)),l}toPath(){let e=this.ctx.getTextGlyphPath?.(this.node);return e||eu(this.node)}toPathDecorations(){return this.ctx.getTextDecorations?.(this.node)??[]}toPathEffectLayers(e){return[]}_getTransformedDimensions(){let e=this.node.raw;return new tn(this.node.dims.x*(e.scaleX??1),this.node.dims.y*(e.scaleY??1))}getBoundingRect(){let e=this.node.bounds;return{left:e.left,top:e.top,width:e.right-e.left,height:e.bottom-e.top}}getInkRect(){let e=Wn(this.node.inkACoords);return{left:e.left,top:e.top,width:e.width,height:e.height}}get aCoords(){return this.node.aCoords}getCoords(){let e=this.node.aCoords;return[e.tl,e.tr,e.br,e.bl]}calcOCoords(){let e=this.ctx.getViewportTransform?.()??[1,0,0,1,0,0],t=o=>({x:e[0]*o.x+e[2]*o.y+e[4],y:e[1]*o.x+e[3]*o.y+e[5]}),r=this.node.aCoords;return{tl:t(r.tl),tr:t(r.tr),br:t(r.br),bl:t(r.bl)}}rotate(e){let{angle:t,left:r,top:o}=this.node.rotateAroundCenter(e);return this.set({angle:t,left:r,top:o})}setPositionByOrigin(e,t,r){let o=this.node.raw,i=typeof o.scaleX=="number"?o.scaleX:1,s=typeof o.scaleY=="number"?o.scaleY:1,a=this.node.dims.x*i,l=this.node.dims.y*s,u=t==="center"?0:t==="right"?.5:-.5,c=r==="center"?0:r==="bottom"?.5:-.5,h=u*a,d=c*l,f=(typeof o.angle=="number"?o.angle:0)*Math.PI/180,m=Math.cos(f),p=Math.sin(f),b={x:e.x-(h*m-d*p),y:e.y-(h*p+d*m)},x=xe({...o},b);return this.set({left:x.x,top:x.y})}scale(e){let t=this.node.raw;return this.set({scaleX:(t.scaleX??1)*e,scaleY:(t.scaleY??1)*e})}getScaledWidth(){return this.node.dims.x*(this.node.raw.scaleX??1)}getScaledHeight(){return this.node.dims.y*(this.node.raw.scaleY??1)}getObjectScaling(){let e=this.node.raw;return{scaleX:e.scaleX??1,scaleY:e.scaleY??1}}get getObjects(){if(this.node instanceof J)return()=>this.node.children.map(e=>this.ctx.wrapNode(e))}get _objects(){if(this.node instanceof J)return this.node.children.map(e=>this.ctx.wrapNode(e))}get ref(){return this}get isImageLikeNode(){let e=se(this.node.raw);return dt.has(e)||ot.has(e)||e===L.GIF||e===L.VIDEO}get getSrc(){if(this.isImageLikeNode)return()=>{let e=this.node.raw;return typeof e.originalSrc=="string"&&e.originalSrc?e.originalSrc:typeof e.src=="string"?e.src:""}}get getRealSrc(){let e=this.getSrc;if(e)return()=>e()}get replaceSrc(){if(this.isImageLikeNode)return async e=>(this.set({src:e,crossOrigin:"anonymous",originalSrc:e}),await this.ctx.reloadNodeImage?.(this.node),this)}get setElement(){if(this.isImageLikeNode)return(e,t)=>(this.node.imageEl=e,t&&this.set(t),this)}get getElement(){if(!this.isImageLikeNode)return;let e=this.node;return e instanceof ie?()=>e.paintSource??e.imageEl:()=>e.imageEl}get _element(){if(this.isImageLikeNode)return this.node.imageEl}get clipImage(){return Xt(this.node)?hv(this.node,this.ctx):void 0}set clipImage(e){let t=e&&typeof e=="object"&&typeof e.toObject=="function"?e.toObject(this.serializationProps()):e;this.ctx.setNodeProps(this.node,{clipImage:t})}getWidthHeight(e=!1){let t=this._getTransformedDimensions(),r=(this.node.raw.strokeWidth??0)||0;return{x:t.x-r,y:t.y-r}}getWidth(){return this.getWidthHeight().x}getHeight(){return this.getWidthHeight().y}sourceNaturalSize(){let e=this.node.imageEl;if(e)return{width:e.naturalWidth||e.width||0,height:e.naturalHeight||e.height||0};if(this.node instanceof ie){let t=this.node.paintSource;if(t)return{width:("videoWidth"in t?t.videoWidth:t.width)||t.width||0,height:("videoHeight"in t?t.videoHeight:t.height)||t.height||0}}return{width:0,height:0}}getOriginalElementWidth(){return this.sourceNaturalSize().width}getOriginalElementHeight(){return this.sourceNaturalSize().height}getElementWidth(){return this.sourceNaturalSize().width}getElementHeight(){return this.sourceNaturalSize().height}cropOffset(){if(!this.isImageLikeNode)return{x:0,y:0};let e=this.node.raw;return e.cropSizeMode==="visible"?{x:0,y:0}:{x:Number(e.cropX)||0,y:Number(e.cropY)||0}}get left(){return this.node.raw.left??0}set left(e){this.set({left:e})}get top(){return this.node.raw.top??0}set top(e){this.set({top:e})}get scaleX(){return this.node.raw.scaleX??1}set scaleX(e){this.set({scaleX:e})}get scaleY(){return this.node.raw.scaleY??1}set scaleY(e){this.set({scaleY:e})}get angle(){return this.node.raw.angle??0}set angle(e){this.set({angle:e})}get skewX(){return this.node.raw.skewX??0}set skewX(e){this.set({skewX:e})}get skewY(){return this.node.raw.skewY??0}set skewY(e){this.set({skewY:e})}get flipX(){return this.node.raw.flipX??!1}set flipX(e){this.set({flipX:e})}get flipY(){return this.node.raw.flipY??!1}set flipY(e){this.set({flipY:e})}get originX(){return this.node.raw.originX??"left"}set originX(e){this.set({originX:e})}get originY(){return this.node.raw.originY??"top"}set originY(e){this.set({originY:e})}get width(){return(this.node.raw.width??0)-this.cropOffset().x}set width(e){if(Or(this.node)){if(this.ctx.setGroupWidth){this.ctx.setGroupWidth(this.node,e);return}this.ctx.setNodeProps(this.node,{width:e});return}let t=this.cropOffset();this.ctx.setNodeProps(this.node,{width:e+t.x})}get height(){return(this.node.raw.height??0)-this.cropOffset().y}set height(e){let t=this.cropOffset();this.ctx.setNodeProps(this.node,{height:e+t.y})}bridgeImageSizeProps(e){if(!this.isImageLikeNode)return;let t=this.node.raw;if(t.cropSizeMode==="visible")return;let r=typeof e.cropX=="number"?e.cropX:Number(t.cropX)||0,o=typeof e.cropY=="number"?e.cropY:Number(t.cropY)||0;typeof e.width=="number"&&r>0&&(e.width=e.width+r),typeof e.height=="number"&&o>0&&(e.height=e.height+o)}cropBeforeState;get __isCropping(){return this.isImageLikeNode&&this.ctx.cropSessionNodeId?.()===this.node.id}set __isCropping(e){if(this.isImageLikeNode)if(e){let t=this.ctx.cropSessionNodeId?.()!==this.node.id;if(t&&(this.cropBeforeState=this.toObject()),!this.ctx.enterCropSession?.(this.node)){t&&(this.cropBeforeState=void 0);return}let r=this.node.raw.cropAspectRatio;typeof r=="number"&&r>0&&this.ctx.setCropSessionAspectRatio?.(r)}else this.ctx.exitCropSession?.(this.node),this.cropBeforeState=void 0}get __isExpand(){return this.isImageLikeNode&&this.ctx.expandSessionNodeId?.()===this.node.id}set __isExpand(e){this.isImageLikeNode&&(e?this.ctx.enterExpandSession?.(this.node):this.ctx.exitExpandSession?.(this.node))}get beforeState(){return this.cropBeforeState}onDeselectEvent(){this.ctx.exitCropSession?.(this.node),this.ctx.exitExpandSession?.(this.node),this.cropBeforeState=void 0}expandOffsetOf(e){let t=this.ctx.expandSessionOffsets?.(this.node);if(t)return t[e];let r=e==="left"?"Left":e==="right"?"Right":e==="top"?"Top":"Bottom",o=this.node.raw[`expand${r}Offset`];return typeof o=="number"?o:void 0}get expandLeftOffset(){return this.isImageLikeNode?this.expandOffsetOf("left"):void 0}get expandRightOffset(){return this.isImageLikeNode?this.expandOffsetOf("right"):void 0}get expandTopOffset(){return this.isImageLikeNode?this.expandOffsetOf("top"):void 0}get expandBottomOffset(){return this.isImageLikeNode?this.expandOffsetOf("bottom"):void 0}setExpandOffset(){let e=this.ctx.expandSessionOffsets?.(this.node);e&&this.set({expandLeftOffset:e.left,expandRightOffset:e.right,expandTopOffset:e.top,expandBottomOffset:e.bottom})}updateCropScale(e){if(!this.__isCropping||!(e>0)||!Number.isFinite(e))return!1;if(this.ctx.updateCropSessionScale)return this.ctx.updateCropSessionScale(e);let t=this.node.imageEl;if(!t)return!1;let r=this.node.raw,o=t.naturalWidth||t.width,i=t.naturalHeight||t.height,s=r.scaleX??1,a=e/s,l=e/(r.scaleY??1),u=this.width,c=this.height,h=u/a,d=c/l,f=(r.cropX??0)+u/2-h/2,m=(r.cropY??0)+c/2-d/2;return h<Math.min(8,o)||d<Math.min(8,i)||f<0||m<0||f+h>o||m+d>i?!1:(this.set({cropScale:e,scaleX:e,scaleY:e,width:h,height:d,cropX:f,cropY:m}),!0)}getMaxEffectPadding(){let e=this.node.raw,t=0,r=e.effects??{},o=c=>(c??[]).filter(h=>h.enabled&&h.showInDialog),i=o(r.solidFill);i.length>0&&(t=Math.max(t,i.reduce((c,h)=>Math.max(c,Math.abs(Number(h.offsetX)||0),Math.abs(Number(h.offsetY)||0)),0)));let s=o(r.dropShadow);s.length>0&&(t=Math.max(t,s.reduce((c,h)=>{let d=(Number(h.blur)||0)*2;return Math.max(c,Math.abs(Number(h.offsetX)||0)+d,Math.abs(Number(h.offsetY)||0)+d)},0)));let a=o(r.stroke);a.length>0&&(t=Math.max(t,a.reduce((c,h)=>{let d=h.size,f=Number(h.strokeWidth)||Number(d?.value)||0;return Math.max(c,f+Math.abs(Number(h.offsetX)||0),f+Math.abs(Number(h.offsetY)||0))},0)));let l=e.shadow;if(l){let c=(Number(l.blur)||0)*2;t=Math.max(t,Math.abs(Number(l.offsetX)||0)+c,Math.abs(Number(l.offsetY)||0)+c)}let u=Number(e.strokeWidth)||0;if(e.stroke&&u){let c=e.strokeAlignment==="outside"?u*2:u;t=Math.max(t,c)}return t}isType(...e){let t=se(this.node.raw);return e.some(r=>r.toLowerCase()===t)}getStyleAtPosition(e){if(!(this.node instanceof Se))return{};let t=typeof this.node.raw.text=="string"?this.node.raw.text:"";if(e<0||e>=t.length)return{};let r=e,o=t.split(`
|
|
1092
|
+
`);for(let i=0;i<o.length;i++){if(r<=o[i].length)return this.objectStyles()?.[i]?.[r]??{};r-=o[i].length+1}return{}}calcTransformMatrix(){return[...this.node.matrix]}setTableWidth(e){if(!(this.node instanceof te))return;let t=this.node.raw,r=t.cols??0,o=t.columnWidths;if(r<=0||!Array.isArray(o)||o.length===0)return;let i=t.cellStrokeWidth??0,s=t.cellSpacing??0,a=o.reduce((c,h)=>c+h,0);if(a<=0)return;let l=(e-i-(r-1)*s)/a,u=t.minCellWidth??0;this.set({columnWidths:o.map(c=>Math.max(u,c*l))})}setTableHeight(e){if(!(this.node instanceof te))return;let t=this.node.raw,r=t.rows??0,o=t.rowHeights;if(r<=0||!Array.isArray(o)||o.length===0)return;let i=t.cellStrokeWidth??0,s=t.cellSpacing??0,a=o.reduce((c,h)=>c+h,0);if(a<=0)return;let l=(e-i-(r-1)*s)/a,u=t.minCellHeight??0;this.set({manualRowHeights:o.map(c=>Math.max(u,c*l))})}cursor2D(e){let t=typeof this.node.raw.text=="string"?this.node.raw.text:"",r=Math.max(0,Math.min(e,t.length)),o=t.split(`
|
|
1093
|
+
`);for(let i=0;i<o.length;i++){if(r<=o[i].length)return{line:i,char:r};r-=o[i].length+1}return{line:Math.max(0,o.length-1),char:o[o.length-1]?.length??0}}stylesToEngineForm(e,t){return e}stylesToPersistForm(e,t){return e}serializationProps(){}stylesMap(){let e=this.node.raw;return Array.isArray(e.styles)&&(e.styles=this.stylesToEngineForm(e.styles,typeof e.text=="string"?e.text:"")??{}),e.styles||(e.styles={}),e.styles}objectStyles(){let e=this.node.raw;return Array.isArray(e.styles)&&(e.styles=this.stylesToEngineForm(e.styles,typeof e.text=="string"?e.text:"")??{}),e.styles}get selectionStart(){return this.ctx.getNodeSelectionRange?.(this.node)?.start??0}get selectionEnd(){return this.ctx.getNodeSelectionRange?.(this.node)?.end??0}cleanStyle(e){let t=this.node.raw,r=this.objectStyles();if(!r)return!1;let o=0,i,s,a=!0,l=0;for(let u in r){i=0;for(let c in r[u]){let h=r[u][c]||{},d=h[e]!==void 0;o++,d?(s===void 0?s=h[e]:h[e]!==s&&(a=!1),h[e]===t[e]&&delete h[e]):a=!1,Object.keys(h).length!==0?i++:delete r[u][c]}i===0&&delete r[u]}if(typeof t.text=="string")for(let u of t.text.split(`
|
|
1094
|
+
`))l+=u.length;return a&&o===l&&o>0&&s!==void 0?(this.set({[e]:s}),this.removeStyle?.(e),!0):(o>0&&this.set({styles:t.styles}),!1)}removeStyle(e){let t=this.objectStyles();if(t){for(let r in t){let o=t[r];for(let i in o)delete o[i][e],Object.keys(o[i]).length===0&&delete o[i];Object.keys(o).length===0&&delete t[r]}this.set({styles:t})}}setSelectionStyles(e,t,r){if(!(this.node instanceof Se))return;let o=this.ctx.getNodeSelectionRange?.(this.node),i=t??o?.start??0,s=r??o?.end??0;if(s<=i)return;let a=this.stylesMap();for(let l=i;l<s;l++){let{line:u,char:c}=this.cursor2D(l);a[u]||(a[u]={});let d={...a[u][c]??{}};for(let f of Object.keys(e))e[f]!==void 0&&(d[f]=e[f]);a[u][c]=d}this.set({styles:this.stylesMap()})}getSelectionStyles(e,t){if(!(this.node instanceof Se))return[];let r=this.ctx.getNodeSelectionRange?.(this.node),o=e??r?.start??0,i=t??r?.end??o,s=[];for(let a=o;a<i;a++)s.push(this.getStyleAtPosition(a));return s}setFontFamily(e,t){this.set({fontFamily:e})}get fontFamily(){return String(this.node.raw.fontFamily??"")}get type(){return String(this.node.raw.type??"")}initDimensions(){}calcTextWidth(){return this.node instanceof Se?this.node.textLayout.lines.reduce((e,t)=>Math.max(e,t.width),0):0}refreshTextDimensions(){}replaceFontFamily(e,t){let r=this.node.raw,o=!1;if(r.fontFamily===e&&(this.set({fontFamily:t}),o=!0),r.styles){for(let i of Object.values(r.styles))if(i)for(let s of Object.values(i))s?.fontFamily===e&&(s.fontFamily=t,o=!0);o&&this.set({styles:r.styles})}return o}get rawTypeLower(){return se(this.node.raw)}get transformKind(){return Ke(this.node.raw)}get setRadius(){if(this.transformKind==="arc")return e=>this.set({curvature:e})}get setWarpStrength(){let e=this.transformKind;if(!(e!=="arch"&&e!=="waist"&&e!=="flag"))return t=>this.set({warpStrength:Math.max(-1,Math.min(1,t))})}get clearCache(){let e=this.transformKind;if(!(e!=="arch"&&e!=="waist"&&e!=="flag"))return()=>{this.ctx.invalidateNodeBakes?.(this.node),this.ctx.getCanvas?.()?.requestRenderAll?.()}}get setCircleParams(){if(this.transformKind==="circle")return e=>this.set(e)}get setTexts(){if(this.node instanceof Se)return e=>this.set({texts:e})}get texts(){if(!(this.node instanceof Se))return;let e=this.node.raw.texts;return Array.isArray(e)?e:[]}toObject(e){let t={...this.node.toObject()};if(this.isImageLikeNode){let r=this.sourceNaturalSize();t.width===void 0&&r.width>0&&(t.width=r.width),t.height===void 0&&r.height>0&&(t.height=r.height)}if(this.node instanceof Se){let r=this.node.textLayout,o=this.node.textStyle.lineHeight??1.16,i=au(r,this.node.raw,o);i&&(t.charTransformations=i),r.lines.length>0&&!cv(t)&&(t.textLines=r.lines.map(a=>a.graphemes.join("")),t.charBounds=r.lines.map(a=>{let l=a.boxes.map(u=>({left:u.left,width:u.width,kernedWidth:u.kernedWidth,height:u.height}));if(l.length>0){let u=l.reduce((c,h)=>c+(h.kernedWidth||0),0);l.push({left:u,width:0,kernedWidth:0,height:l[l.length-1].height})}return l}),t.lineHeights=r.lines.map(a=>a.implHeight*o));let s=this.node.raw;t.styles=this.stylesToPersistForm(t.styles,typeof s.text=="string"?s.text:"")}if(e?.length){let r=this.node.raw,o=t;for(let i of e)o[i]===void 0&&r[i]!==void 0&&(o[i]=r[i])}return t}get id(){return this.node.id}get canvas(){return this.ctx.getCanvas?.()}get group(){let e=this.ctx.getCanvas?.(),t=cu(e?.document,this.node);return t?this.ctx.wrapNode(t):void 0}get topGroup(){let e=this.ctx.getCanvas?.(),t,r=this.node;for(;;){let o=cu(e?.document,r);if(!o)break;t=o,r=o}return t?this.ctx.wrapNode(t):void 0}get parent(){return this.group}get applyMaskParams(){if(this.node instanceof le)return e=>{this.node.applyMaskParams(e),this.ctx.getCanvas?.()?.requestRenderAll?.()}}get updateGapParams(){if(this.node instanceof le)return e=>{this.node.updateGapParams(e),this.ctx.getCanvas?.()?.requestRenderAll?.()}}get updateLayout(){if(this.node instanceof le)return e=>{this.node.updateLayout(e),this.ctx.getCanvas?.()?.requestRenderAll?.()}}get visible(){return this.node.visible}set visible(e){this.set({visible:e})}get opacity(){let e=this.node.raw.opacity;return typeof e=="number"?e:1}set opacity(e){this.set({opacity:e})}get strokeWidth(){let e=this.node.raw.strokeWidth;return typeof e=="number"?e:1}set strokeWidth(e){this.set({strokeWidth:e})}_createCacheCanvas(){}_removeCacheCanvas(){}get isEditing(){return this.ctx.isEditingNode(this.node)}enterEditing(){return this.node.isTextType&&this.ctx.enterNodeEditing(this.node),this}exitEditing(){return this.ctx.exitEditing(),this}bringToFront(){this.ctx.bringToFront(this.node)}sendToBack(){this.ctx.sendToBack(this.node)}bringForward(){this.ctx.bringForward(this.node)}sendBackwards(){this.ctx.sendBackwards(this.node)}moveTo(e){this.ctx.moveNodeTo(this.node,e)}remove(){this.ctx.removeNode(this.node)}get changeControls(){if(Ot(this.node))return(e,t=!0)=>{this.ctx.changeNodeControls(this.node,e)}}get isEditingPath(){return this.ctx.isPathEditingNode(this.node)}get setAnchorPointType(){if(Ot(this.node)==="path")return(e,t)=>this.ctx.setNodeAnchorType(this.node,e,t)}get getActiveAnchorKey(){if(Ot(this.node))return()=>this.ctx.getNodePathEditInfo(this.node)?.activeAnchorKey}get getActiveAnchorIndex(){if(Ot(this.node))return()=>this.ctx.getNodePathEditInfo(this.node)?.activeAnchorIndex}get getAnchorPointStyleByIndex(){if(Ot(this.node)==="path")return e=>Ac(Ce(this.node.raw.path),e)}get highlightAnchor(){if(Ot(this.node))return e=>{this.ctx.highlightNodeAnchor(this.node,e)}}get resetAnchorStyles(){if(Ot(this.node))return()=>{this.ctx.resetNodeAnchorStyles(this.node)}}},Xt=n=>{let e=n.raw;if(!ot.has(se(e)))return null;let t=e.clipImage;return!t||typeof t!="object"||typeof t.src!="string"?null:t},uv=new Set(["_cacheCanvas","dirty","canvas"]),lu=class{constructor(e,t){this.node=e;this.ctx=t}node;ctx;set(e){let t=Xt(this.node);if(!t)return this;let r={...t};for(let[o,i]of Object.entries(e))uv.has(o)||(r[o]=i);return this.ctx.setNodeProps(this.node,{clipImage:r}),this}toObject(e){let t=Xt(this.node);return t?{...t}:{}}setCoords(){}getSrc(){let e=Xt(this.node);return e&&typeof e.originalSrc=="string"&&e.originalSrc?e.originalSrc:e&&typeof e.src=="string"?e.src:""}get replaceSrc(){if(Xt(this.node))return async e=>(this.set({src:e,crossOrigin:"anonymous",originalSrc:e}),await this.ctx.reloadMaskClipImage?.(this.node),this)}getRelativeCenterPoint(){let e=Xt(this.node),t=a=>typeof a=="number"?a:0,r=a=>typeof a=="number"?a:1,o=a=>a==="center"?.5:a==="right"||a==="bottom"?1:0,i=t(e?.width)*r(e?.scaleX),s=t(e?.height)*r(e?.scaleY);return new tn(t(e?.left)+(.5-o(e?.originX))*i,t(e?.top)+(.5-o(e?.originY))*s)}getOriginalElementWidth(){let e=this.node.clipImageEl;return e?.naturalWidth||e?.width||Number(Xt(this.node)?.width)||0}getOriginalElementHeight(){let e=this.node.clipImageEl;return e?.naturalHeight||e?.height||Number(Xt(this.node)?.height)||0}},cu=(n,e)=>{if(!n)return;let t=r=>{for(let o of r){if(!(o instanceof J))continue;if(o.children.some(s=>s===e))return o;let i=t(o.children);if(i)return i}};return t(n.nodes)},hv=(n,e)=>{let t=new lu(n,e);return new Proxy(t,{get(r,o,i){if(typeof o=="symbol")return Reflect.get(r,o,i);if(o==="then")return;if(o in r)return Reflect.get(r,o,i);let s=Xt(r.node);return s?s[o]:void 0},set(r,o,i,s){return typeof o=="symbol"||o in r?(Reflect.set(r,o,i,s),!0):(r.set({[o]:i}),!0)}})};su(hr.prototype);var dv=n=>{let e=n.raw,t=typeof e.width=="number"?e.width:n.dims.x,r=typeof e.height=="number"?e.height:n.dims.y,o=e.pathOffset;return{left:typeof e.left=="number"?e.left:0,top:typeof e.top=="number"?e.top:0,width:t,height:r,pathOffset:{x:typeof o?.x=="number"?o.x:t/2,y:typeof o?.y=="number"?o.y:r/2}}},fv=(n,e)=>{let t=new hr(n,e);return n instanceof Ar&&(t._calcDimensions=()=>dv(n)),new Proxy(t,{get(r,o,i){return typeof o=="symbol"?Reflect.get(r,o,i):o==="then"?void 0:o in r?Reflect.get(r,o,i):r.node.raw[o]},set(r,o,i,s){return typeof o=="symbol"||o in r?(Reflect.set(r,o,i,s),!0):(r.set({[o]:i}),!0)}})};var mv=(n,e)=>{n.onWarpHistoryChange=(r,o)=>{e.setWarpUndoable(r),e.setWarpRedoable(o)};let t=()=>{let r=n.warpSession;e.setWarpUndoable(r?.undoable??!1),e.setWarpRedoable(r?.redoable??!1)};return{active:()=>!!n.warpSession,async enter(r){let o=r instanceof hr?r.node:r?.node;if(!o)return!1;let i=await n.enterWarpMode(o);return t(),i},undo(){let r=n.warpUndo();return t(),r},redo(){let r=n.warpRedo();return t(),r},async exit(r){let o=await n.exitWarpMode(r).then(i=>!!i?.committed);return t(),o}}};var rb=new Set([L.ELLIPSE,L.CIRCLE]),pv=new Set([L.TRIANGLE]),du=new Set([L.POLYGON]),ob=new Set([L.POLYLINE]),jp=new Set([L.ARROW]),bv=new Set([L.DIMENSION]),xv=new Set([L.GROUP,L.PUZZLE]),Vp=new Set([...dt,L.GIF]),qp=new Set([L.TABLE]),uu=new Set(["multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"]),gv=n=>{if(!(Number(n.warpStrength)||0))return null;let t=Ke(n);return t==="arch"||t==="waist"||t==="flag"?t:null},hu=n=>{let e=n.effects;return!!e&&typeof e=="object"&&!Array.isArray(e)},yv=n=>typeof n.textBackgroundColor=="string"&&n.textBackgroundColor?!0:Array.isArray(n.texts)&&n.texts.length>0,Sv=new Set(["rect","Rect","fabricrect","ellipse","Ellipse","circle","Circle","polygon","Polygon","polyline","Polyline","Path","path"]),vv=.222,K=(n,e,t)=>{let r=n[e];if(typeof r=="number")return Number.isFinite(r)?r:t;if(typeof r=="string"&&r.trim()!==""){let o=Number(r.trim());if(Number.isFinite(o))return o}return t},Ie=(n,e)=>{let t=n[e];return typeof t=="string"?t:void 0},N=n=>{let e=Math.round(n*1e4)/1e4;return Object.is(e,-0)?"0":String(e)},re=n=>n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"),wv=/^(#[0-9a-fA-F]{3,8}|rgba?\(\s*[\d.]+\s*,\s*[\d.]+\s*,\s*[\d.]+\s*(,\s*[\d.]+\s*)?\)|[a-zA-Z][a-zA-Z0-9_-]*)$/,on=n=>wv.test(n.trim())?n.trim():null,_n=n=>n==null||n===""||n==="transparent"||n==="rgba(0,0,0,0)"||n==="none",fu=n=>`matrix(${n.map(N).join(",")})`,Tv=(n,e)=>[1,0,0,1,n,e],Kp=n=>n,Qp=(n,e,t)=>Bn({...n,width:e,height:t}),rn=n=>{let e=n.shadow;if(!e)return null;if(typeof e!="object"||Array.isArray(e))return;let t=e,r=typeof t.color=="string"?t.color:"rgb(0,0,0)";if(on(r))return{color:r,blur:typeof t.blur=="number"&&Number.isFinite(t.blur)?t.blur:0,offsetX:typeof t.offsetX=="number"&&Number.isFinite(t.offsetX)?t.offsetX:0,offsetY:typeof t.offsetY=="number"&&Number.isFinite(t.offsetY)?t.offsetY:0}},Zp=(n,e)=>{let t=n.pathOffset,r=0,o=0;return t&&typeof t=="object"?(typeof t.x=="number"&&Number.isFinite(t.x)&&(r=t.x),typeof t.y=="number"&&Number.isFinite(t.y)&&(o=t.y)):e&&(r=e.x,o=e.y),r||o?Tv(-r,-o):null},Ev=n=>{let e=Fe(n);return e?{x:(e.left+e.right)/2,y:(e.top+e.bottom)/2}:null},Cv=n=>{if(!n.length)return null;let e=1/0,t=1/0,r=-1/0,o=-1/0;for(let i of n)e>i.x&&(e=i.x),t>i.y&&(t=i.y),r<i.x&&(r=i.x),o<i.y&&(o=i.y);return{x:(e+r)/2,y:(t+o)/2}},Mv=n=>n.map(e=>e.length===1?e[0]:`${e[0]} ${e.slice(1).map(t=>N(Number(t))).join(" ")}`).join(" "),Jp=(n,e,t)=>{let r=se(n);if(zn.has(r)){let o=Math.min(K(n,"rx",0),e/2),i=Math.min(K(n,"ry",0),t/2),s=o>0||i>0?` rx="${N(o)}" ry="${N(i>0?i:o)}"`:"";return{open:`<rect x="${N(-e/2)}" y="${N(-t/2)}" width="${N(e)}" height="${N(t)}"${s}`,internalTransform:null}}if(rb.has(r))return{open:`<ellipse cx="0" cy="0" rx="${N(e/2)}" ry="${N(t/2)}"`,internalTransform:null};if(pv.has(r))return{open:`<polygon points="${N(-e/2)},${N(t/2)} 0,${N(-t/2)} ${N(e/2)},${N(t/2)}"`,internalTransform:null};if(r===L.PATH){let o=Ce(n.path);return o?{open:`<path d="${re(Mv(o))}"`,internalTransform:Zp(n,Ev(o))}:null}if(du.has(r)||ob.has(r)){let o=n.points;if(!Array.isArray(o)||o.length===0)return null;let i=[];for(let l of o){let u=l,c=typeof u.x=="number"?u.x:NaN,h=typeof u.y=="number"?u.y:NaN;Number.isFinite(c)&&Number.isFinite(h)&&i.push({x:c,y:h})}if(!i.length)return null;let s=i.map(l=>`${N(l.x)},${N(l.y)}`);return{open:`<${du.has(r)?"polygon":"polyline"} points="${s.join(" ")}"`,internalTransform:Zp(n,Cv(i))}}return ft.has(r)?{open:`<line x1="${N(K(n,"x1",0))}" y1="${N(K(n,"y1",0))}" x2="${N(K(n,"x2",0))}" y2="${N(K(n,"y2",0))}"`,internalTransform:null}:null},eb=(n,e,t)=>{let r=e&&n.internalTransform?V(e,n.internalTransform):e??n.internalTransform;return`${n.open}${r?` transform="${fu(r)}"`:""}${t}/>`},Rv=(n,e,t)=>{let r="";if(e!==null){r+=` fill="${re(e)}"`;let o=Ie(n,"fillRule");o&&(r+=` fill-rule="${re(o)}"`)}else r+=' fill="none"';if(t!==null){r+=` stroke="${re(t)}"`,r+=` stroke-width="${N(K(n,"strokeWidth",1))}"`;let o=n.strokeDashArray;if(Array.isArray(o)&&o.length>0){let l=o.map(u=>typeof u=="number"&&Number.isFinite(u)?N(u):null).filter(u=>u!==null);l.length&&(r+=` stroke-dasharray="${l.join(",")}"`)}let i=Ie(n,"strokeLineCap");i&&(r+=` stroke-linecap="${re(i)}"`);let s=Ie(n,"strokeLineJoin");s&&(r+=` stroke-linejoin="${re(s)}"`);let a=n.strokeMiterLimit;typeof a=="number"&&Number.isFinite(a)&&(r+=` stroke-miterlimit="${N(a)}"`),n.strokeUniform===!0&&(r+=' vector-effect="non-scaling-stroke"'),Ie(n,"paintFirst")==="stroke"&&(r+=' paint-order="stroke"')}return r},Pv=n=>!_n(n.stroke)&&K(n,"strokeWidth",1)>0,tb=n=>{let e=new Map;return(t,r)=>{let o=/([\d.]+)px\s+([\s\S]+)$/.exec(t);if(!o)return 0;let i=Number(o[1]),s=o[2].replace(/^["']+|["']+$/g,""),a=`${s}|${i}|${r}`,l=e.get(a);if(l!==void 0)return l;let u=n.getFont(s)??n.getSubsetFont?.(s,r[0]??"")??null,c=u&&typeof u.getAdvanceWidth=="function"?u.getAdvanceWidth(r,i):0;return e.set(a,c),c}},kv=(n,e)=>{let t=0;for(let r of n)t+=r.charCodeAt(0)>255?1:.55;return t*e},ib=n=>{let e=n.textLines,t=n.charBounds,r=n.lineHeights;if(!Array.isArray(e)||!Array.isArray(t)||!Array.isArray(r)||e.length===0||t.length!==e.length||r.length!==e.length)return null;for(let o=0;o<e.length;o++)if(typeof e[o]!="string"||!Array.isArray(t[o])||typeof r[o]!="number"||!Number.isFinite(r[o]))return null;return{textLines:e,charBounds:t,lineHeights:r}},sb=n=>{let e=n.map(o=>At(o).length),t=[],r=0;for(let o of e)t.push(r),r+=o;return{starts:t,counts:e}},Av=(n,e)=>{let{starts:t,counts:r}=n;if(t.length===0||e<0)return null;let o=0,i=t.length-1;for(;o<i;){let a=o+i+1>>1;t[a]<=e?o=a:i=a-1}let s=e-t[o];return s<0||s>=r[o]?null:[o,s]},Nv=(n,e)=>{let t=n.styles;if(!Array.isArray(t))return{};for(let r of t){if(!r||typeof r!="object")continue;let o=r,i=typeof o.start=="number"?o.start:-1,s=typeof o.end=="number"?o.end:-1;if(e>=i&&e<s&&o.style&&typeof o.style=="object")return o.style}return{}},nb=(n,e)=>{let t=Nv(n,e),r=(o,i)=>t[o]!==void 0?t[o]:i;return{fontFamily:r("fontFamily",Ie(n,"fontFamily")??"Arial"),fontSize:r("fontSize",K(n,"fontSize",40)),fontWeight:r("fontWeight",String(Ie(n,"fontWeight")??"normal")),fontStyle:r("fontStyle",Ie(n,"fontStyle")??"normal"),fill:r("fill",n.fill),stroke:r("stroke",n.stroke),strokeWidth:r("strokeWidth",K(n,"strokeWidth",1)),underline:r("underline",n.underline===!0),linethrough:r("linethrough",n.linethrough===!0),overline:r("overline",n.overline===!0)}},In=n=>({fontFamily:n.fontFamily??"Times New Roman",fontSize:n.fontSize??40,fontWeight:n.fontWeight,fontStyle:n.fontStyle??void 0,lineHeight:n.lineHeight??1.16,charSpacing:n.charSpacing??0,textAlign:n.textAlign??fe.LEFT}),ti=(n,e,t)=>({fontFamily:e?.fontFamily??n.fontFamily,fontSize:e?.fontSize??n.fontSize,fontWeight:String(e?.fontWeight??n.fontWeight??"normal"),fontStyle:e?.fontStyle??n.fontStyle??"normal",fill:e?.fill??t.fill,stroke:t.stroke,strokeWidth:K(t,"strokeWidth",1),underline:t.underline===!0,linethrough:t.linethrough===!0,overline:t.overline===!0}),Lv=(n,e)=>{if(!Array.isArray(e)||e.length===0)return e&&typeof e=="object"?e:void 0;let t=sb(n.split(`
|
|
1095
|
+
`)),r={};for(let o of e){if(!o||typeof o!="object")continue;let i=typeof o.start=="number"?o.start:-1,s=typeof o.end=="number"?o.end:-1;if(!(i<0||s<=i||!o.style||typeof o.style!="object"))for(let a=i;a<s;a++){let l=Av(t,a);l&&((r[l[0]]??={})[l[1]]=o.style)}}return Object.keys(r).length>0?r:void 0},Iv=(n,e,t,r)=>{let o=n??fe.LEFT;return Ut(o)?r?o===fe.JUSTIFY_CENTER?(e-t)/2:o===fe.JUSTIFY_RIGHT?e-t:0:0:o===fe.CENTER?(e-t)/2:o===fe.RIGHT?e-t:0},mu=n=>{let e=[];for(let t of n)switch(t.type){case"M":e.push(`M${N(t.x??0)} ${N(t.y??0)}`);break;case"L":e.push(`L${N(t.x??0)} ${N(t.y??0)}`);break;case"Q":e.push(`Q${N(t.x1??0)} ${N(t.y1??0)} ${N(t.x??0)} ${N(t.y??0)}`);break;case"C":e.push(`C${N(t.x1??0)} ${N(t.y1??0)} ${N(t.x2??0)} ${N(t.y2??0)} ${N(t.x??0)} ${N(t.y??0)}`);break;case"Z":e.push("Z");break;default:break}return e.join("")},ab=(n,e,t,r,o={})=>{let i=-1;for(let f=0;f<e.textLines.length;f++)e.textLines[f].length>0&&(i=f);let s=K(n,"lineHeight",1.16)||1.16,a=Ie(n,"textAlign"),l=-t/2,u=-r/2,c=[],h=sb(e.textLines),d=0;for(let f=0;f<e.textLines.length;f++){let m=e.textLines[f],p=At(m),b=e.charBounds[f],x=e.lineHeights[f],g=x/s,y=u+d+g-x*vv/s,v=0;for(let C of b)!C||typeof C.left!="number"||typeof C.kernedWidth!="number"||(v=Math.max(v,C.left+C.kernedWidth));let S=Iv(a,t,v,f>=i),w=o.lineLefts?.[f]??l+S,R=o.anchor==="boxLeft",P=w,T=0;for(let C=0;C<p.length;C++){let E=p[C],M=b[C];if(!M||typeof M.width!="number"||typeof M.kernedWidth!="number")continue;let k=h.starts[f]+C;if(R){c.push({char:E,x:w+(M.left||0),y,style:nb(n,k)});continue}T===0?(P+=M.kernedWidth-M.width,T=M.width):T+=M.width,c.push({char:E,x:P,y,style:nb(n,k)}),P+=T,T=0}d+=x}return c},_v=(n,e,t={})=>{if(!e)return null;let r=n,o=K(r,"width",NaN),i=K(r,"height",NaN);if(!Number.isFinite(o)||!Number.isFinite(i)||r.vertical===!0||typeof r.direction=="string"&&r.direction!=="ltr")return null;let s=ib(r);if(!s)return null;let a=[];for(let{char:l,x:u,y:c,style:h}of ab(r,s,o,i,t)){if(!l.trim())continue;let d=e.getFont(h.fontFamily)??e.getSubsetFont?.(h.fontFamily,l)??null;if(!d)return null;let f=mu(d.getPath(l,u,c,h.fontSize).commands);a.push(f.endsWith("Z")?f:`${f} Z`)}return a.length>0?{path:a.join(" ")}:null},Fa=class{options;defs=[];idSeq=0;skipped={};constructor(e){this.options=e}exportPage(e){this.defs=[],this.idSeq=0,this.skipped={};let t=[];for(let a of e.objects){if(!a||typeof a!="object"||typeof a.type!="string")continue;let l=this.emitNode(a);l!==null&&l&&t.push(l)}let r=e.background&&!_n(e.background)?on(e.background):null,o=r?`<rect x="${N(e.viewBox.x)}" y="${N(e.viewBox.y)}" width="${N(e.viewBox.width)}" height="${N(e.viewBox.height)}" fill="${re(r)}"/>`:"",i=this.defs.length?`<defs>${this.defs.join("")}</defs>`:"";return{svg:`<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="${N(e.width)}px" height="${N(e.height)}px" viewBox="${N(e.viewBox.x)} ${N(e.viewBox.y)} ${N(e.viewBox.width)} ${N(e.viewBox.height)}" data-engine-svg="1">`+o+i+t.join("")+"</svg>",skippedTypes:this.skipped}}skip(e){this.skipped[e]=(this.skipped[e]??0)+1}nextId(e){return this.idSeq+=1,`${e}${this.idSeq}`}emitGradientDef(e,t,r){let o=this.nextId("esvg-g"),i=ui(e,t,r),s=` gradientTransform="matrix(${N(i[0])},${N(i[1])},${N(i[2])},${N(i[3])},${N(i[4])},${N(i[5])})"`,a=e.stops.map(l=>{let[u,c,h,d]=l.color,f=`rgb(${Math.round(u*255)},${Math.round(c*255)},${Math.round(h*255)})`;return`<stop offset="${N(l.offset)}" stop-color="${f}"${d<1?` stop-opacity="${N(d)}"`:""}/>`}).join("");return e.kind==="linear"?this.defs.push(`<linearGradient id="${o}" gradientUnits="userSpaceOnUse" x1="${N(e.x1)}" y1="${N(e.y1)}" x2="${N(e.x2)}" y2="${N(e.y2)}"${s}>${a}</linearGradient>`):this.defs.push(`<radialGradient id="${o}" gradientUnits="userSpaceOnUse" cx="${N(e.x2)}" cy="${N(e.y2)}" r="${N(e.r2)}" fx="${N(e.x1)}" fy="${N(e.y1)}"${e.r1>0?` fr="${N(e.r1)}"`:""}${s}>${a}</radialGradient>`),`url(#${o})`}resolvePaint(e,t,r){if(_n(e))return null;if(typeof e=="string")return on(e)??void 0;if(!e||typeof e!="object"||Array.isArray(e))return;let o=Gn(e);if(o)return this.emitGradientDef(o,t,r);let i=fi(e);if(i)return this.emitPatternDef(i,t,r)}emitPatternDef(e,t,r){let o=this.options.naturalSizes?.get(e.src);if(!o||o.width<=0||o.height<=0)return;let i=this.nextId("esvg-pt"),s=mi(e,t,r);return this.defs.push(`<pattern id="${i}" patternUnits="userSpaceOnUse" width="${N(o.width)}" height="${N(o.height)}" patternTransform="${fu(s)}"><image href="${re(e.src)}" xlink:href="${re(e.src)}" x="0" y="0" width="${N(o.width)}" height="${N(o.height)}"/></pattern>`),`url(#${i})`}emitShadowFilter(e){let t=this.nextId("esvg-s");return this.defs.push(`<filter id="${t}" x="-50%" y="-50%" width="200%" height="200%"><feDropShadow dx="${N(e.offsetX)}" dy="${N(e.offsetY)}" stdDeviation="${N(e.blur/2)}" flood-color="${re(e.color)}"/></filter>`),t}emitClipPath(e,t){let r=e.clipPath;if(!r||typeof r!="object"||Array.isArray(r))return null;let o=r;if(typeof o.type!="string"||!Sv.has(o.type)||o.inverted===!0)return null;let i=K(o,"width",0),s=K(o,"height",0),a=Jp(o,i,s);if(!a)return null;let l=Qp(o,i,s),u=o.absolutePositioned===!0?V(ve(t),l):l,c=this.nextId("esvg-c");return this.defs.push(`<clipPath id="${c}">${eb(a,u,"")}</clipPath>`),` clip-path="url(#${c})"`}emitBakedTextImage(e,t){let r=rn(e);if(r===void 0)return this.skip("shadow-unsupported"),null;let o=-t.width/2+(t.offsetX??0),i=-t.height/2+(t.offsetY??0),s=`<image href="${re(t.dataUrl)}" xlink:href="${re(t.dataUrl)}" x="${N(o)}" y="${N(i)}" width="${N(t.width)}" height="${N(t.height)}"/>`;r&&(s=`<g filter="url(#${this.emitShadowFilter(r)})">${s}</g>`);let a=K(e,"textScaleX",1)||1,l=K(e,"textScaleY",1)||1;return(Math.abs(a-1)>1e-9||Math.abs(l-1)>1e-9)&&(s=`<g transform="scale(${N(a)},${N(l)})">${s}</g>`),s}emitText(e){if(Ge(e))return this.emitArcText(e);if(e.vertical===!0)return this.emitVerticalText(e);let t=gv(e);if(t)return this.emitWarpedText(e,t);if(Kn(e)){let m=this.options.bakeTextBitmap?.(e,"psd")??null;if(m)return this.emitBakedTextImage(e,m);this.skip("text-psdwarp-bitmap-fallback")}let r=K(e,"width",NaN),o=K(e,"height",NaN);if(!Number.isFinite(r)||!Number.isFinite(o)){if(Number.isFinite(r)&&!Number.isFinite(o)){let m=this.engineLayoutOf(e,!1);if(m)return this.emitTextFromEngineLayout(e,m)}return this.skip("text-dims-missing"),null}if(typeof e.direction=="string"&&e.direction!=="ltr")return this.skip("text-vertical-or-rtl"),null;let i=this.pathBackgroundMarkup(e);if(hu(e)){let m=this.options.bakeTextBitmap?.(e,"plain")??null;if(m)return i+this.emitBakedTextImage(e,m)}if(Array.isArray(e.effects)&&e.effects.length>0)return this.skip("text-effects"),null;if(yv(e)){let m=this.engineLayoutOf(e,!1);if(m)return this.emitTextFromEngineLayout(e,m)}let s=ib(e);if(!s){let m=Ie(e,"text");if(!m||!Array.from(m).some(b=>b!==`
|
|
1096
|
+
`))return'<text xml:space="preserve"></text>';let p=this.engineLayoutOf(e,!1);return p?this.emitTextFromEngineLayout(e,p):(this.skip("text-layout-missing"),null)}let a=rn(e);if(a===void 0)return this.skip("shadow-unsupported"),null;let l=K(e,"textScaleX",1)||1,u=K(e,"textScaleY",1)||1,c=Math.abs(l-1)>1e-9||Math.abs(u-1)>1e-9,h=ab(e,s,r,o),d=this.emitAnchorGlyphs(h,r,o);if(d===null)return null;let f=d;return a&&(f=`<g filter="url(#${this.emitShadowFilter(a)})">${f}</g>`),c&&(f=`<g transform="scale(${N(l)},${N(u)})">${f}</g>`),this.pathBackgroundMarkup(e)+f}emitAnchorGlyphs(e,t,r){let o=[],i=[],s=[];for(let{char:l,x:u,y:c,rotation:h,centerX:d,scaleY:f,style:m}of e){let p=h!==void 0||d===!0||f!==void 0,b=h!==void 0?h*180/Math.PI:0;if(this.options.textMode==="paths"){if(l.trim()){let x=this.options.fonts?.getFont(m.fontFamily)??this.options.fonts?.getSubsetFont?.(m.fontFamily,l)??null;if(!x)return this.skip(`text-font-missing:${m.fontFamily}`),null;let g=this.resolvePaint(m.fill,t,r);if(g===void 0)return this.skip("text-fill-unsupported"),null;let y=g!==null?` fill="${re(g)}"`:' fill="none"';if(typeof m.stroke=="string"&&!_n(m.stroke)&&m.strokeWidth>0&&(y+=` stroke="${re(m.stroke)}" stroke-width="${N(m.strokeWidth)}"`),p){let v=d?-((x.getAdvanceWidth?.(l,m.fontSize)??0)/2):0,S=mu(x.getPath(l,v,0,m.fontSize).commands),w=`translate(${N(u)},${N(c)})`;h!==void 0&&(w+=` rotate(${N(b)})`),f!==void 0&&(w+=` scale(1,${N(f)})`),o.push(`<g transform="${w}"><path d="${S}"${y}/></g>`)}else{let v=mu(x.getPath(l,u,c,m.fontSize).commands);o.push(`<path d="${v}"${y}/>`)}}}else{let x=this.resolvePaint(m.fill,t,r);if(x===void 0)return this.skip("text-fill-unsupported"),null;if(p){let g=` transform="translate(${N(u)},${N(c)})${h!==void 0?` rotate(${N(b)})`:""}${f!==void 0?` scale(1,${N(f)})`:""}"`;d&&(g+=' text-anchor="middle"'),g+=` font-family="${re(m.fontFamily)}"`,g+=` font-size="${N(m.fontSize)}"`,m.fontWeight!=="normal"&&(g+=` font-weight="${re(m.fontWeight)}"`),m.fontStyle!=="normal"&&(g+=` font-style="${re(m.fontStyle)}"`),g+=x!==null?` fill="${re(x)}"`:' fill="none"',typeof m.stroke=="string"&&!_n(m.stroke)&&m.strokeWidth>0&&(g+=` stroke="${re(m.stroke)}" stroke-width="${N(m.strokeWidth)}"`),s.push(`<text xml:space="preserve"${g}>${re(l)}</text>`)}else{let g=` x="${N(u)}" y="${N(c)}"`;g+=` font-family="${re(m.fontFamily)}"`,g+=` font-size="${N(m.fontSize)}"`,m.fontWeight!=="normal"&&(g+=` font-weight="${re(m.fontWeight)}"`),m.fontStyle!=="normal"&&(g+=` font-style="${re(m.fontStyle)}"`),g+=x!==null?` fill="${re(x)}"`:' fill="none"',typeof m.stroke=="string"&&!_n(m.stroke)&&m.strokeWidth>0&&(g+=` stroke="${re(m.stroke)}" stroke-width="${N(m.strokeWidth)}"`);let y=[m.underline?"underline":"",m.overline?"overline":"",m.linethrough?"line-through":""].filter(Boolean);y.length&&(g+=` text-decoration="${y.join(" ")}"`),i.push(`<tspan${g}>${re(l)}</tspan>`)}}}if(this.options.textMode==="paths")return o.join("");let a=i.length>0?`<text xml:space="preserve">${i.join("")}</text>`:"";return s.length>0?s.join("")+a:a}emitArcText(e){if(hu(e)){let a=this.options.bakeTextBitmap?.(e,Ge(e)??"arc")??null;if(a)return this.emitBakedTextImage(e,a)}if(Array.isArray(e.effects)&&e.effects.length>0)return this.skip("text-effects"),null;let t=this.arcLayoutOf(e);if(!t)return this.skip(`text-font-missing:${Ie(e,"fontFamily")??""}`),null;let r=rn(e);if(r===void 0)return this.skip("shadow-unsupported"),null;let o=In(e),i=[];for(let a of t.arc.chars)i.push({char:a.char,x:a.x-t.arc.contentOffsetX,y:a.y-t.arc.contentOffsetY,rotation:a.rotation,centerX:!0,style:ti(o,t.layout.lines[a.line]?.charStyles?.[a.index],e)});let s=this.emitAnchorGlyphs(i,K(e,"width",0)||t.arc.width,t.arc.height);return s===null?null:r?`<g filter="url(#${this.emitShadowFilter(r)})">${s}</g>`:s}emitVerticalText(e){if(hu(e)){let b=this.options.bakeTextBitmap?.(e,"vertical")??null;if(b)return this.emitBakedTextImage(e,b)}if(Array.isArray(e.effects)&&e.effects.length>0)return this.skip("text-effects"),null;let t=this.engineLayoutOf(e,!0);if(!t)return this.skip(`text-font-missing:${Ie(e,"fontFamily")??""}`),null;let r=rn(e);if(r===void 0)return this.skip("shadow-unsupported"),null;let o=In(e),i=o.charSpacing?o.fontSize*o.charSpacing/1e3:0,s=Number(e.textOffsetY)||0,a=Math.max(t.height,K(e,"height",0)),l=[],u=0;for(let b of t.lines){let x=-t.width/2+b.leftOffset,g=-a/2+b.baseline,y=0;for(let v=0;v<b.graphemes.length;v++){let S=b.graphemes[v],w=b.charStyles[v],R=w?.fontSize??o.fontSize,P=wt(s,R,u+v),T=b.boxes[v],C=$n(S);if(C==="latin"||C==="bracket"){let E=x+y+(C==="latin"?T.kernedWidth-T.width:0);l.push({char:S,x:E,y:g+P,style:ti(o,w,e)})}else{let E=x+y+cn(R),M=g+P+gr(C,T,R);l.push({char:S,x:E,y:M,rotation:-Math.PI/2,style:ti(o,w,e)})}y+=jn(S,T,i)}u+=b.graphemes.length}let c=this.emitAnchorGlyphs(l,t.width,a);if(c===null)return null;let h=this.emitTextDecorations(e,t,a),d=K(e,"textScaleX",1)||1,f=K(e,"textScaleY",1)||1,m=c;r&&(m=`<g filter="url(#${this.emitShadowFilter(r)})">${m}</g>`);let p=h+m;return(Math.abs(d-1)>1e-9||Math.abs(f-1)>1e-9)&&(p=`<g transform="scale(${N(d)},${N(f)})">${p}</g>`),p}emitWarpedText(e,t){let r=this.options.bakeTextBitmap?.(e,t)??null;if(r)return this.emitBakedTextImage(e,r);if(Array.isArray(e.effects)&&e.effects.length>0)return this.skip("text-effects"),null;let o=this.engineLayoutOf(e,!1);if(!o)return this.skip(`text-font-missing:${Ie(e,"fontFamily")??""}`),null;let i=rn(e);if(i===void 0)return this.skip("shadow-unsupported"),null;let s=K(e,"fontSize",40)||40,a=Math.max(-1,Math.min(1,K(e,"warpStrength",0)||0)),l=K(e,"width",0),u=K(e,"height",0),c=Math.max(o.height,u),h=Math.max(o.width,l,s),d=t==="flag"?Math.abs(a)*(u||s)*.3:0,f=h/2,m=c/2,p=In(e),b=[];for(let S of o.lines){let w=-o.width/2+S.leftOffset,R=-c/2+S.baseline;for(let P=0;P<S.graphemes.length;P++){let T=S.boxes[P],C=ti(p,S.charStyles[P],e),E=w+T.left,M=E+T.width/2,k=f>0?M/f:0;if(t==="flag"){let A=Math.sin(k*Math.PI)*d*a;b.push({char:S.graphemes[P],x:E,y:R+A,style:C})}else if(t==="arch"){let A=Math.max(-1,Math.min(1,k)),O=Math.sqrt(Math.max(0,1-A*A)),F=O*O*(3-2*O),G=a>0?Math.pow(F,2.5):F,Y=Math.min(1+Math.max(0,a),Math.max(.05,1+a*G));b.push({char:S.graphemes[P],x:E,y:Y*R+m*(1-Y),scaleY:Y,style:C})}else{let A=Math.min(1+Math.abs(a),Math.max(.4,1+a*(k*k-.5)));b.push({char:S.graphemes[P],x:E,y:A*R,scaleY:A,style:C})}}}let x=this.emitAnchorGlyphs(b,h,c);if(x===null)return null;let g=K(e,"textScaleX",1)||1,y=K(e,"textScaleY",1)||1,v=x;return i&&(v=`<g filter="url(#${this.emitShadowFilter(i)})">${v}</g>`),(Math.abs(g-1)>1e-9||Math.abs(y-1)>1e-9)&&(v=`<g transform="scale(${N(g)},${N(y)})">${v}</g>`),v}emitMask(e){let t=Ie(e,"src");if(!t)return this.skip("image-src-missing"),null;let r=K(e,"width",0),o=K(e,"height",0);if(!(r>0)||!(o>0))return this.skip("image-dims-missing"),null;let i=e.clipImage,s=i&&typeof i=="object"?i:null,a=s?Ie(s,"src"):void 0;if(!s||!a){let w=rn(e);if(w===void 0)return this.skip("shadow-unsupported"),null;let R=`<image href="${re(t)}" xlink:href="${re(t)}" x="${N(-r/2)}" y="${N(-o/2)}" width="${N(r)}" height="${N(o)}"/>`;return w&&(R=`<g filter="url(#${this.emitShadowFilter(w)})">${R}</g>`),R}let l=this.options.naturalSizes?.get(a);if(!l||l.width<=0||l.height<=0)return this.skip("image-natural-missing"),null;let u=l.width,c=l.height,h=this.nextId("esvg-mk");this.defs.push(`<mask id="${h}" maskUnits="userSpaceOnUse" mask-type="alpha" x="${N(-r/2)}" y="${N(-o/2)}" width="${N(r)}" height="${N(o)}"><image href="${re(t)}" xlink:href="${re(t)}" x="${N(-r/2)}" y="${N(-o/2)}" width="${N(r)}" height="${N(o)}"/></mask>`);let d=`<g transform="translate(${N(-r/2)},${N(-o/2)})" mask="url(#${h})"`,f=Math.max(0,Math.min(K(e,"cornerRadius",0),Math.min(r,o)/2));if(f>0){let w=this.nextId("esvg-mc");this.defs.push(`<clipPath id="${w}"><path d="M ${N(f)} 0 L ${N(r-f)} 0 Q ${N(r)} 0 ${N(r)} ${N(f)} L ${N(r)} ${N(o-f)} Q ${N(r)} ${N(o)} ${N(r-f)} ${N(o)} L ${N(f)} ${N(o)} Q 0 ${N(o)} 0 ${N(o-f)} L 0 ${N(f)} Q 0 0 ${N(f)} 0 Z"/></clipPath>`),d+=` clip-path="url(#${w})"`}d+=">";let m=K(s,"angle",0),p=K(s,"scaleX",1)||1,b=K(s,"scaleY",1)||1,x=s.flipX===!0?-1:1,g=s.flipY===!0?-1:1,y=K(e,"clipX",0),v=K(e,"clipY",0),S=`translate(${N(r/2)},${N(o/2)}) rotate(${N(m)}) scale(${N(p*x)},${N(b*g)}) translate(${N(y/(p||1))},${N(v/(b||1))}) translate(${N(-u/2)},${N(-c/2)})`;return d+`<g transform="${S}"><image href="${re(a)}" xlink:href="${re(a)}" x="0" y="0" width="${N(u)}" height="${N(c)}"/></g></g>`}emitTable(e){let t=this.tableLayoutOf(e);if(!t)return this.skip(`text-font-missing:${typeof e.fontFamily=="string"?e.fontFamily:""}`),null;let r=[];for(let o of t.children){if(!o||typeof o!="object"||typeof o.type!="string")continue;let i=this.emitNode(o);if(i===null)return null;i&&r.push(i)}return r.join("")}pathBackgroundMarkup(e,t){let r=ao(e);if(!r||!r.fill)return"";let o=t??this.engineLayoutOf(e,!1);if(!o)return"";let i=o.width,s=Math.max(o.height,K(e,"height",0));if(!(i>0)||!(s>0))return"";let a=Ce(r.path);if(!a)return"";let l=Fe(a);if(!l)return"";let u=l.right-l.left,c=l.bottom-l.top;if(!(u>0)||!(c>0))return"";let h=i/r.width,d=s/r.height,f=(l.left+l.right)/2,m=(l.top+l.bottom)/2,[p,b,x,g]=ee(r.fill),y=`rgba(${Math.round(p*255)},${Math.round(b*255)},${Math.round(x*255)},${N(g)})`;return`<path d="${re(r.path)}" transform="matrix(${N(h)} 0 0 ${N(d)} ${N(-f*h)} ${N(-m*d)})" fill="${y}"/>`}emitTextDecorations(e,t,r){let o=[],i=-r/2,s=typeof e.textBackgroundColor=="string"?e.textBackgroundColor:"";if(s||t.lines.some(a=>a.charStyles.some(l=>l?.textBackgroundColor)))for(let a of t.lines){let l=-t.width/2+a.leftOffset,u=i+a.top,c=p=>a.charStyles[p]?.textBackgroundColor??s,h=0,d=0,f=c(0),m=()=>{if(!f||d<=0)return;let p=on(f);p&&o.push(`<rect x="${N(l+a.boxes[h].left)}" y="${N(u)}" width="${N(d)}" height="${N(a.implHeight)}" fill="${re(p)}"/>`)};for(let p=0;p<a.graphemes.length;p++){let b=c(p);b!==f?(m(),h=p,d=a.boxes[p].width,f=b):d+=a.boxes[p].kernedWidth}m()}if(Array.isArray(e.texts)&&e.texts.length>0&&e.vertical!==!0){let a=Qn(e.text??"",t,e.texts,i,In(e).fontSize);if(a)for(let l of a.ops){let u=l.isFill?`<path d="${re(l.d)}" fill="${re(on(l.fill)??l.fill)}"/>`:`<path d="${re(l.d)}" fill="none" stroke="${re(on(l.stroke)??l.stroke)}" stroke-width="${N(l.strokeWidth)}"/>`;o.push(`<g transform="translate(${N(l.translateX)},${N(l.translateY)}) scale(${N(l.scaleX)},${N(l.scaleY)})">${u}</g>`)}}return o.join("")}emitTextFromEngineLayout(e,t){let r=rn(e);if(r===void 0)return this.skip("shadow-unsupported"),null;let o=In(e),i=Math.max(t.height,K(e,"height",0)),s=[];for(let f of t.lines){let m=-t.width/2+f.leftOffset,p=-i/2+f.baseline;for(let b=0;b<f.graphemes.length;b++)s.push({char:f.graphemes[b],x:m+f.boxes[b].left,y:p,style:ti(o,f.charStyles[b],e)})}let a=this.emitAnchorGlyphs(s,t.width,i);if(a===null)return null;let l=K(e,"textScaleX",1)||1,u=K(e,"textScaleY",1)||1,c=this.emitTextDecorations(e,t,i),h=a;r&&(h=`<g filter="url(#${this.emitShadowFilter(r)})">${h}</g>`);let d=c+h;return(Math.abs(l-1)>1e-9||Math.abs(u-1)>1e-9)&&(d=`<g transform="scale(${N(l)},${N(u)})">${d}</g>`),this.pathBackgroundMarkup(e,t)+d}tableCache=new Map;tableLayoutOf(e){let t=this.tableCache.get(e);if(t!==void 0)return t;if(this.layoutMeasure===void 0&&(this.layoutMeasure=this.options.measure??(this.options.fonts?tb(this.options.fonts):null)),!this.layoutMeasure)return null;let r;try{r=Co(e,this.layoutMeasure)}catch{r=null}return this.tableCache.set(e,r),r}arcCache=new Map;layoutMeasure;engineLayoutOf(e,t){if(this.layoutMeasure===void 0&&(this.layoutMeasure=this.options.measure??(this.options.fonts?tb(this.options.fonts):null)),!this.layoutMeasure)return null;if(!this.options.measure){let i=In(e).fontFamily;if(!this.options.fonts?.getFont(i))return null}let r=e.text??"",o=se(e)===L.TEXTBOX&&Ke(e)===null;return Vn(r,In(e),{measure:this.layoutMeasure,boxWidth:o?e.width??0:null,styles:Lv(r,e.styles),splitByGrapheme:e.splitByGrapheme===!0,vertical:t,paragraph:Ge(e)?void 0:e.paragraph})}arcLayoutOf(e){let t=this.arcCache.get(e);if(t!==void 0)return t;let r=this.engineLayoutOf(e,!1),o=r?{layout:r,arc:Et(r,e,In(e).lineHeight??1.16)}:null;return this.arcCache.set(e,o),o}emitImage(e){let t=Ie(e,"src");if(!t)return this.skip("image-src-missing"),null;if(Array.isArray(e.filters)&&e.filters.length>0)return this.skip("image-filters"),null;if(Array.isArray(e.effects)&&e.effects.length>0)return this.skip("image-effects"),null;let r=Ie(e,"globalCompositeOperation");if(r&&r!=="source-over"&&!uu.has(r))return this.skip("image-gco"),null;let o=Zi(Kp(e));if(o){let h=this.options.naturalSizes?.get(t);if(!h)return this.skip("image-natural-missing"),null;let d=o.sw,f=o.sh;if(d<=0||f<=0)return this.skip("image-crop-empty"),null;let m=d/o.sw,p=f/o.sh,b=-d/2-o.sx*m,x=-f/2-o.sy*p,g=this.nextId("esvg-ic"),y=K(e,"rx",0),v=K(e,"ry",0),S=y>0||v>0?` rx="${N(y)}" ry="${N(v)}"`:"";return this.defs.push(`<clipPath id="${g}"><rect x="${N(-d/2)}" y="${N(-f/2)}" width="${N(d)}" height="${N(f)}"${S}/></clipPath>`),`<g clip-path="url(#${g})"><image xlink:href="${re(t)}" x="${N(b)}" y="${N(x)}" width="${N(h.width*m)}" height="${N(h.height*p)}"/></g>`}let i=K(e,"width",NaN),s=K(e,"height",NaN);if(!Number.isFinite(i)||!Number.isFinite(s))return this.skip("image-dims-missing"),null;let a=rn(e);if(a===void 0)return this.skip("shadow-unsupported"),null;let l=`<image xlink:href="${re(t)}" x="${N(-i/2)}" y="${N(-s/2)}" width="${N(i)}" height="${N(s)}"/>`,u=K(e,"rx",0),c=K(e,"ry",0);if(u>0||c>0){let h=this.nextId("esvg-ir");this.defs.push(`<clipPath id="${h}"><rect x="${N(-i/2)}" y="${N(-s/2)}" width="${N(i)}" height="${N(s)}" rx="${N(u)}" ry="${N(c)}"/></clipPath>`),l=`<g clip-path="url(#${h})">${l}</g>`}return a&&(l=`<g filter="url(#${this.emitShadowFilter(a)})">${l}</g>`),l}emitObjectContent(e,t,r,o){let i=se(e);if(xv.has(i)){let d=e.objects;if(!Array.isArray(d))return this.skip("group-objects-missing"),null;let f=[];for(let m of d){if(!m||typeof m!="object"||typeof m.type!="string")continue;let p=this.emitNode(m);if(p===null)return null;p&&f.push(p)}return f.join("")}if(qp.has(i))return this.emitTable(e);if(ot.has(i))return this.emitMask(e);if(Vp.has(i))return this.emitImage(e);if(i===L.TEXTIMAGE&&typeof e.renderSrc=="string"){let d=e.renderRect,f=typeof d?.w=="number"&&d.w>0?d.w:K(e,"width",NaN),m=typeof d?.h=="number"&&d.h>0?d.h:K(e,"height",NaN);if(!Number.isFinite(f)||!Number.isFinite(m)||f<=0||m<=0)return this.skip("textimage-dims-missing"),null;let p=-f/2+(typeof d?.x=="number"?d.x:0),b=-m/2+(typeof d?.y=="number"?d.y:0),x=Mo(e),g=`<image xlink:href="${re(Ie(e,"renderSrc")??"")}" x="${N(p)}" y="${N(b)}" width="${N(f)}" height="${N(m)}"${x<1?` opacity="${N(x)}"`:""}/>`,y=typeof d?.angle=="number"&&Number.isFinite(d.angle)?d.angle:0;return y&&(g=`<g transform="rotate(${N(-y)})">${g}</g>`),g}if(sn.has(i))return this.emitText(e);let s=Ie(e,"globalCompositeOperation");if(s&&s!=="source-over"&&!uu.has(s))return this.skip("shape-gco"),null;if(typeof e.strokeAlignment=="string"&&e.strokeAlignment!=="center"&&!_n(e.stroke))return this.skip("shape-stroke-alignment"),null;if(jp.has(i)||bv.has(i))return this.emitLineDecoration(e,jp.has(i));let a=Jp(e,r,o);if(!a)return this.skip(`type:${String(e.type??"")}`),null;let l=this.resolvePaint(e.fill,r,o);if(l===void 0)return this.skip("fill-unsupported"),null;let u=null;if(Pv(e)){let d=this.resolvePaint(e.stroke,r,o);if(d===void 0)return this.skip("stroke-unsupported"),null;u=d}let c=rn(e);if(c===void 0)return this.skip("shadow-unsupported"),null;let h=Rv(e,l,u)+(c?` filter="url(#${this.emitShadowFilter(c)})"`:"");return eb(a,null,h)}emitLineDecoration(e,t){let r=K(e,"x1",NaN),o=K(e,"y1",NaN),i=K(e,"x2",NaN),s=K(e,"y2",NaN);if(!Number.isFinite(r)||!Number.isFinite(o)||!Number.isFinite(i)||!Number.isFinite(s))return this.skip(`dims-missing:${String(e.type??"")}`),null;let a=e.stroke,l=typeof a=="string"&&!_n(a)?a:"#000000";if(!on(l))return this.skip("stroke-unsupported"),null;let u=K(e,"strokeWidth",1),c=e.strokeDashArray,h=Array.isArray(c)&&c.length>0?` stroke-dasharray="${c.map(W=>typeof W=="number"&&Number.isFinite(W)?N(W):null).filter(W=>W!==null).join(",")}"`:"",d=i-r,f=s-o,m=Math.atan2(f,d),p=Math.cos(m),b=Math.sin(m);if(t){let W=e.arrowType==="start"||e.arrowType==="both"?e.arrowType:"end",j=W==="start"||W==="both",H=W==="end"||W==="both",X=Math.sqrt(u),z=K(e,"arrowWidth",15)*X,$=K(e,"arrowHeight",22.5)*X,Z=r+p*(j?$:0),B=o+b*(j?$:0),q=i-p*(H?$:0),U=s-b*(H?$:0),oe=` stroke="${re(l)}" stroke-width="${N(u)}"${h}`,ne=[`<line x1="${N(Z)}" y1="${N(B)}" x2="${N(q)}" y2="${N(U)}"${oe} fill="none"/>`],de=(Pe,De,nt)=>{let ke=Math.cos(nt),Ee=Math.sin(nt),ue=Pe-$*ke+z/2*Ee,ge=De-$*Ee-z/2*ke,pe=Pe-$*ke-z/2*Ee,Te=De-$*Ee+z/2*ke;ne.push(`<path d="M ${N(Pe)} ${N(De)} L ${N(ue)} ${N(ge)} L ${N(pe)} ${N(Te)} Z" fill="${re(l)}"/>`)};return H&&de(i,s,m),j&&de(r,o,m+Math.PI),ne.join("")}let x=` stroke="${re(l)}" stroke-width="${N(u)}"${h}`,g=Ie(e,"strokeLineCap");g&&(x+=` stroke-linecap="${re(g)}"`);let y=Ie(e,"strokeLineJoin");y&&(x+=` stroke-linejoin="${re(y)}"`);let v=e.strokeMiterLimit;typeof v=="number"&&Number.isFinite(v)&&(x+=` stroke-miterlimit="${N(v)}"`);let S=[`<line x1="${N(r)}" y1="${N(o)}" x2="${N(i)}" y2="${N(s)}"${x} fill="none"/>`],w=(K(e,"textFontSize",50)||50)/2,R=-b,P=p,T=` stroke="${re(l)}" stroke-width="${N(u)}" stroke-linecap="round"`;for(let[W,j]of[[r,o],[i,s]])S.push(`<line x1="${N(W-R*w)}" y1="${N(j-P*w)}" x2="${N(W+R*w)}" y2="${N(j+P*w)}"${T} fill="none"/>`);let C=K(e,"textFontSize",50)||50,E=typeof e.text=="string"&&e.text.trim()?e.text:"50cm",M=K(e,"textPadding",4),k=kv(E,C)+M*2,A=C+M*2,O=C+u/2+5,F=(r+i)/2+R*O,G=(o+s)/2+P*O,Y=e.textFollowLine===!1?0:m*180/Math.PI,_=typeof e.textColor=="string"&&on(e.textColor)?e.textColor:"#333333",D=typeof e.textBackgroundColor=="string"?e.textBackgroundColor:"#ffffff",I=on(D);return S.push(`<g transform="translate(${N(F)},${N(G)}) rotate(${N(Y)})">`+(D&&I?`<rect x="${N(-k/2)}" y="${N(-A/2)}" width="${N(k)}" height="${N(A)}" fill="${re(I)}"/>`:"")+`<text text-anchor="middle" dominant-baseline="central" font-family="Arial, sans-serif" font-size="${N(C)}" fill="${re(_)}">${re(E)}</text></g>`),S.join("")}emitNode(e){if(Lr.has(Ie(e,"id")??"")||e.excludeFromExport===!0||e.visible===!1)return"";let t=se(e),r=K(e,"width",NaN),o=K(e,"height",NaN);if(Vp.has(t)){let h=Zi(Kp(e));if(h)r=h.sw,o=h.sh;else if(!Number.isFinite(r)||!Number.isFinite(o)){let d=this.options.naturalSizes?.get(Ie(e,"src")??"");r=d?.width??NaN,o=d?.height??NaN}}else if(ft.has(t)&&(!Number.isFinite(r)||!Number.isFinite(o)))r=Math.abs(K(e,"x2",0)-K(e,"x1",0)),o=Math.abs(K(e,"y2",0)-K(e,"y1",0));else if(rb.has(t)&&(!Number.isFinite(r)||!Number.isFinite(o)))if(t===L.CIRCLE){let h=2*K(e,"radius",NaN);Number.isFinite(r)||(r=h),Number.isFinite(o)||(o=h)}else Number.isFinite(r)||(r=2*K(e,"rx",NaN)),Number.isFinite(o)||(o=2*K(e,"ry",NaN));else if((du.has(t)||ob.has(t))&&(!Number.isFinite(r)||!Number.isFinite(o))){let h=e.points;if(Array.isArray(h)&&h.length>0){let d=1/0,f=1/0,m=-1/0,p=-1/0;for(let b of h){let x=typeof b?.x=="number"&&Number.isFinite(b.x)?b.x:NaN,g=typeof b?.y=="number"&&Number.isFinite(b.y)?b.y:NaN;!Number.isFinite(x)||!Number.isFinite(g)||(d>x&&(d=x),f>g&&(f=g),m<x&&(m=x),p<g&&(p=g))}Number.isFinite(d)&&Number.isFinite(f)&&(Number.isFinite(r)||(r=m-d),Number.isFinite(o)||(o=p-f))}}else if(sn.has(t)&&!Number.isFinite(o))if(Array.isArray(e.lineHeights))o=e.lineHeights.reduce((h,d)=>h+(typeof d=="number"&&Number.isFinite(d)?d:0),0);else{let h=this.engineLayoutOf(e,!1);h&&(o=h.height)}if(Ge(e)){let h=this.arcLayoutOf(e);h&&(r=h.arc.width,o=h.arc.height)}if(qp.has(t)){let h=this.tableLayoutOf(e);h&&(r=h.width,o=h.height)}if(!Number.isFinite(r)||!Number.isFinite(o))return this.skip(`dims-missing:${String(e.type??"")}`),null;let i=Qp(e,r,o),s=this.emitObjectContent(e,i,r,o);if(s===null)return null;if(s==="")return"";let a=`<g transform="${fu(i)}"`,l=Ie(e,"globalCompositeOperation");l&&l!=="source-over"&&uu.has(l)&&(a+=` style="mix-blend-mode:${re(l)}"`);let u=K(e,"opacity",1);u<1&&(a+=` opacity="${N(u)}"`);let c=this.emitClipPath(e,i);return c===null&&e.clipPath?(this.skip("clip-unsupported"),null):(c&&(a+=c),`${a}>${s}</g>`)}},Dv=n=>new Fa({textMode:n.textMode,fonts:n.fonts,naturalSizes:n.naturalSizes,measure:n.measure,bakeTextBitmap:n.bakeTextBitmap}).exportPage(n);var lb=n=>n==="center"?0:n==="right"?.5:-.5,cb=n=>typeof n=="number"?n:0,Fv=(n,e={})=>{let t=1/0,r=1/0,o=-1/0,i=-1/0,s=[];for(let p of n){let b=Ct(p);if(!b)continue;s.push(b);let x=b.contentBoxCorners();for(let g of[x.tl,x.tr,x.br,x.bl])g.x<t&&(t=g.x),g.y<r&&(r=g.y),g.x>o&&(o=g.x),g.y>i&&(i=g.y)}let a=!s.length||!Number.isFinite(t),l=a?0:o-t,u=a?0:i-r,c=a?0:(t+o)/2,h=a?0:(r+i)/2,d=n.map(p=>({...p,left:cb(p.left)-c,top:cb(p.top)-h})),f=typeof e.left=="number"?e.left:c+l*lb(e.originX),m=typeof e.top=="number"?e.top:h+u*lb(e.originY);return{...e,type:e.type??"Group",width:l,height:u,left:f,top:m,objects:d}};var dr=n=>n==="center"?0:n==="right"?.5:-.5,Ov=(n,e={})=>{let t=Ce(n),r=t?Fe(t):null,o=r?r.right-r.left:0,i=r?r.bottom-r.top:0,s={x:r?(r.left+r.right)/2:0,y:r?(r.top+r.bottom)/2:0},a=typeof e.strokeWidth=="number"?e.strokeWidth:1,l=typeof e.left=="number"?e.left:s.x+(o+a)*dr(e.originX),u=typeof e.top=="number"?e.top:s.y+(i+a)*dr(e.originY);return{...e,type:e.type??"Path",path:t??[],width:o,height:i,pathOffset:s,left:l,top:u}};var Bv=(n,e={})=>{let[t,r,o,i]=n,s=Math.abs(o-t),a=Math.abs(i-r),l=(t+o)/2,u=(r+i)/2,c=typeof e.strokeWidth=="number"?e.strokeWidth:1,h=typeof e.left=="number"?e.left:l+(s+c)*dr(e.originX),d=typeof e.top=="number"?e.top:u+(a+c)*dr(e.originY),f=t<=o?-1:1,m=r<=i?-1:1;return{...e,type:e.type??"Line",width:s,height:a,left:h,top:d,x1:f*s/2||0,y1:m*a/2||0,x2:-f*s/2||0,y2:-m*a/2||0}},Wv=(n,e={},t="Polygon")=>{let r=1/0,o=1/0,i=-1/0,s=-1/0;for(let m of n)m.x<r&&(r=m.x),m.y<o&&(o=m.y),m.x>i&&(i=m.x),m.y>s&&(s=m.y);let a=!Number.isFinite(r),l=a?0:i-r,u=a?0:s-o,c={x:a?0:(r+i)/2,y:a?0:(o+s)/2},h=typeof e.strokeWidth=="number"?e.strokeWidth:1,d=typeof e.left=="number"?e.left:c.x+(l+h)*dr(e.originX),f=typeof e.top=="number"?e.top:c.y+(u+h)*dr(e.originY);return{...e,type:e.type??t,points:n,width:l,height:u,pathOffset:c,left:d,top:f}};export{ie as AnimatedNode,Yg as COMPAT_PROTOCOL_VERSION,Le as CompatHistoryActions,hr as CompatObject,tn as CompatPoint,L as ElementTypes,Zc as EngineCanvas,Po as EngineDocument,On as EventBus,bi as GIF_TYPES,J as GroupNode,dt as IMAGE_LIKE_TYPES,ft as LINE_TYPES,Nr as LineNode,ot as MASK_TYPES,ae as MaskNode,pi as PUZZLE_TYPES,Ar as PathNode,Jc as Point,le as PuzzleNode,Xn as SHAPE_TYPES,zn as SOLID_TYPES,As as ScaleLimit,ct as SceneNode,gn as ShapeNode,Fa as SvgExporter,Zb as TEXT_ALIGN_VALUES,sn as TEXT_TYPES,te as TableNode,fe as TextAlignValues,Se as TextNode,xi as VIDEO_TYPES,Kn as activePsdTextWarp,Ac as anchorStyleAt,fh as applyWarpDistortion,Ge as arcTextKind,Fv as assembleGroupRaw,Ug as attachDocumentEventBridge,su as attachTableFacade,vl as bakeArcText,Vc as bakePsdWarpText,Rx as bakeTextEffects,Sl as bakeWarpedText,Wn as boundsFromACoors,Eo as buildAllSelection,eu as buildEngineShapePath,Bv as buildLineRaw,Ov as buildPathRaw,Wv as buildPolyRaw,Bl as buildScene,xn as buildSelectionRange,_v as buildTextGlyphPathData,hl as buildWarpSurfaceGridOverWindow,lg as clearAlphaHitMask,kt as composeMatrix,mo as compositeWarpEffects,Et as computeArcTextLayout,wl as computePuzzleItems,mv as createEngineWarpvasFacade,Ct as createNode,Uc as decodeAnimatedImage,vb as decomposeOwnMatrix,au as deriveArcCharTransformations,Pi as evaluateWarpMesh,Na as fboPixelsToImageData,cu as findParentGroupOf,ul as generatePsdWarpMesh,dh as generateStyleWarpMesh,Fe as getBoundsOfPath,we as getCellData,dn as glyphStyleAt,bn as glyphStyleOf,hn as identityWarpMesh,Xc as imageMaskDeclOf,cp as imageMaskOffset,vo as insertTableColumn,So as insertTableRow,ve as invert,dl as invertBilinearCell,Ur as isAnimatedPng,LS as isAnimatedPngFile,IS as isAnimatedPngUrl,DS as isAnimatedWebPFile,FS as isAnimatedWebPUrl,gu as isCanvasPerfEnabled,wb as isEngineRasterExportEnabled,Tb as isEngineSvgExportEnabled,cl as isGeneratableWarpStyle,Or as isGroupWidthHandleNode,Ut as isJustifyFamilyAlign,nl as isJustifyVariantAlign,$a as isSnapGuideEnabled,to as isStretchAlign,Vt as isTextBitmapState,Vn as layoutTextbox,al as lineDecorationRuns,Je as loadImageElement,yu as markCanvasPerfCounter,up as maskOutsideRects,lp as maskPixelsToAlpha,lt as masterPosition,go as mergeTableCells,V as multiply,Ui as normalizeSelectionAfterRemove,za as objectACoors,Yt as objectCenter,xe as objectOriginFromCenter,Bn as objectOwnMatrix,ee as parseColor,Ce as parsePathData,Kt as parsePsdEffects,ao as pathBackgroundSpecOf,Ot as pathEditKindOf,Qn as planTextHighlight,ii as recordCanvasPerfDuration,it as rectCornerRadii,ns as refitGroupShells,kl as removeTableColumn,Pl as removeTableRow,sv as renderPlacedSmartObjectLayer,fo as renderTextRuns,Bi as renderVerticalRuns,kr as rowColCoverage,Kr as sceneToClipMatrix,Xe as selectionBounds,Dv as serializePageToSvg,ey as setGroupWidth,bo as setTableColumnWidth,xo as setTableRowHeight,Mo as textBitmapFillAlpha,Ke as textTransformKindOf,Q as transformPoint,ai as transformedDimensions,se as typeKeyOf,yo as unmergeTableCells,$t as verticalGlyphOps,fv as wrapCompatObject};
|