@yft-design/engine 0.0.21 → 0.0.22

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/index.js CHANGED
@@ -1,10 +1,10 @@
1
- var _e={enabled:!1,metrics:new Map,counters:new Map,sampleRate:1,reportIntervalMs:5e3,reportTimer:null},Qc=()=>performance.now(),Np=()=>typeof window>"u"?!1:window.location.search.includes("canvasPerf=1"),Lp=n=>{let e=_e.metrics.get(n);return e||(e={count:0,total:0,max:0,last:0},_e.metrics.set(n,e)),e},Ip=(n,e)=>e>0?n/e:0,Ma=()=>[..._e.metrics.entries()].map(([n,e])=>({name:n,count:e.count,totalMs:Number(e.total.toFixed(2)),avgMs:Number(Ip(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),Ca=()=>[..._e.counters.entries()].map(([n,e])=>({name:n,count:e})).sort((n,e)=>e.count-n.count),_p=()=>({type:"canvas-perf",timestamp:new Date().toISOString(),enabled:_e.enabled,metrics:Ma(),counters:Ca()}),Zc=()=>JSON.stringify(_p()),Dp=()=>{let n=Ma(),e=Ca(),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
- `)},Jc=()=>{let n=Zc();if(!_e.enabled)return n;let e=Ma(),t=Ca();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},Fp=()=>{typeof window>"u"||!_e.enabled||_e.reportTimer!=null||(_e.reportTimer=window.setInterval(Jc,_e.reportIntervalMs))},Op=()=>{_e.reportTimer!=null&&(window.clearInterval(_e.reportTimer),_e.reportTimer=null)},Ea=n=>{_e.enabled=n,n?(Fp(),console.info("[canvas-perf] enabled")):(Op(),console.info("[canvas-perf] disabled"))},eu=()=>_e.enabled,Bp=()=>{_e.metrics.clear(),_e.counters.clear()},tu=(n,e=1)=>{_e.enabled&&_e.counters.set(n,(_e.counters.get(n)||0)+e)},Bo=(n,e)=>{if(!_e.enabled)return;let t=Lp(n);t.count+=1,t.total+=e,t.max=Math.max(t.max,e),t.last=e},Ra=(n,e)=>{if(!_e.enabled)return e();let t=Qc();try{return e()}finally{Bo(n,Qc()-t)}};var nu=()=>{typeof window>"u"||window.__YFT_CANVAS_PERF__||(window.__YFT_CANVAS_PERF__={enable:()=>Ea(!0),disable:()=>Ea(!1),report:Jc,reportJson:Zc,reportText:Dp,reset:Bp,mark:tu,time:Ra,isEnabled:eu},Np()&&Ea(!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()}},kt=class{constructor(e,t){this.subscribe=t;this.current=e,this.off=t(e)}subscribe;off;current;retarget(e){e!==this.current&&(this.off(),this.current=e,this.off=this.subscribe(e))}dispose(){this.off()}};var cr=n=>n*Math.PI/180,Y=(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]],Te=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},V=(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])}),Hp=n=>n[0]===1&&n[1]===0&&n[2]===0&&n[3]===1&&n[4]===0&&n[5]===0,Ho=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}},Wp=n=>{let e=cr(n),t=Math.cos(e),r=Math.sin(e);return[t,r,-r,t,0,0]},ru=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=Y(a,[1,0,Math.tan(cr(i)),1,0,0],!0)),s&&(a=Y(a,[1,Math.tan(cr(s)),0,1,0,0],!0)),a},At=n=>{let{translateX:e=0,translateY:t=0,angle:r=0}=n,o=[1,0,0,1,e,t];r&&(o=Y(o,Wp(r)));let i=ru(n);return Hp(i)||(o=Y(o,i)),o},Gp=(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=V(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)}},Wo=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=Gp(h,d,ru(n)),{x:f.x+u,y:f.y+u}},On=n=>{let e=Yt(n);return At({...n,translateX:e.x,translateY:e.y})},Yt=n=>{let e=Wo(n),t=-Ho(n.originX??"left")*e.x,r=-Ho(n.originY??"top")*e.y,o=n.angle??0;if(o){let i=cr(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}},ge=(n,e)=>{let t=Wo(n),r=-Ho(n.originX??"left")*t.x,o=-Ho(n.originY??"top")*t.y,i=n.angle??0;if(i){let s=cr(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}},Xp=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]}}},Pa=n=>{let e=Yt(n),t=cr(n.angle??0),r=Math.cos(t),o=Math.sin(t),i=Wo(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)}},ka=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}},Nt=(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 Y(s,Y([r,0,0,r,0,0],n))};var dt=(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},ou=()=>dt("gpuShadow",!0),Aa=()=>dt("gpuPsdShadow",!0),Na=()=>dt("gpuPsdFill",!0),iu=()=>dt("gpuClipMask"),La=()=>{if(typeof window>"u")return!0;let n=new URLSearchParams(window.location.search).get("snapGuide");return!(n==="0"||n==="false")},su=()=>dt("arcGlyph",!0),zp=()=>dt("export",!0),Ia=()=>dt("retained",!0),Bn=()=>dt("retainedDebug",!1),Go=()=>dt("sdfDash",!0),au=()=>dt("sdfPolygon",!0),lu=()=>dt("sdfLineDeco",!0),Yp=()=>dt("svgexport",!0);var Up={transparent:[0,0,0,0],black:[0,0,0,1],white:[1,1,1,1],red:[1,0,0,1],green:[0,.5019607843137255,0,1],blue:[0,0,1,1],gray:[.5019607843137255,.5019607843137255,.5019607843137255,1],grey:[.5019607843137255,.5019607843137255,.5019607843137255,1],pink:[1,.7529411764705882,.796078431372549,1]},Hr=n=>Math.min(1,Math.max(0,n)),$p=65536,Xo=new Map,ae=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=Xo.get(n);if(e)return e;let t=Vp(n);return Xo.size>=$p&&Xo.clear(),Xo.set(n,t),t},Vp=n=>{let e=n.trim().toLowerCase(),t=Up[e];if(t)return t;if(e.startsWith("#")){let o=e.slice(1);if(o.length===3||o.length===4){let i=parseInt(o[0]+o[0],16)/255,s=parseInt(o[1]+o[1],16)/255,a=parseInt(o[2]+o[2],16)/255,l=o.length===4?parseInt(o[3]+o[3],16)/255:1;return[i,s,a,l]}if(o.length===6||o.length===8){let i=parseInt(o.slice(0,2),16)/255,s=parseInt(o.slice(2,4),16)/255,a=parseInt(o.slice(4,6),16)/255,l=o.length===8?parseInt(o.slice(6,8),16)/255:1;return[i,s,a,l]}return[0,0,0,0]}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[Hr(i(o[0])/255),Hr(i(o[1])/255),Hr(i(o[2])/255),o[3]!==void 0?Hr(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?Hr(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 ur=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=ae(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})},zo=(n,e,t)=>{let r=[1,0,0,1,-e/2+n.offsetX,-t/2+n.offsetY];return n.gradientUnits==="percentage"&&(r=Y(r,[e,0,0,t,0,0])),n.gradientTransform&&(r=Y(r,n.gradientTransform)),r};var cu=(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},uu=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 jp=["repeat","repeat-x","repeat-y","no-repeat"],Yo=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=jp.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}},Uo=(n,e,t)=>{let r=[1,0,0,1,-e/2+n.offsetX,-t/2+n.offsetY];return n.patternTransform&&(r=Y(r,n.patternTransform)),r},hu=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"},J=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]),ft=new Set([L.IMAGE,L.SVGIMAGE,L.CROPIMAGE,L.QRCODE,L.BARCODE,L.ECHART,L.FABRIC_ECHART]),Hn=new Set([L.ELLIPSE,L.CIRCLE,L.POLYGON,L.POLYLINE,L.PATH,L.TRIANGLE]),mt=new Set([L.LINE,L.ARROW,L.DIMENSION,L.REFERENCELINE]),Wn=new Set([L.RECT,L.FABRICRECT]),nt=new Set([L.MASK]),$o=new Set([L.PUZZLE]),Vo=new Set([L.GIF]),jo=new Set([L.VIDEO]);var on=1-.5522847498,_a=new Set([L.FABRICRECT]),sn=(n,e)=>typeof n=="number"&&Number.isFinite(n)?n:e,Da=(n,e,t)=>{let r=sn(n,0);return r>0?{rx:r/(sn(e,1)||1),ry:r/(sn(t,1)||1)}:null},du=n=>{if(!_a.has(J(n)))return;let e=Da(n.radius,n.scaleX,n.scaleY);e&&(n.rx=e.rx,n.ry=e.ry)},fu=(n,e)=>{if(!_a.has(J(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=Da(i,s,a);return e.rx=l?l.rx:0,e.ry=l?l.ry:0,!0},rt=(n,e,t)=>{if(!(e>0)||!(t>0))return null;let r=_a.has(J(n))?Da(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},qo=(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},Wr=(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()},mu=(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,g,b]of c)for(let x=0;x<l;x++){let y=b+x/l*(Math.PI/2);u.push(f+p*Math.cos(y),m+g*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 qp from"rbush";var Ne=1e-12,Kp=96,Ko=(n,e,t,r,o,i)=>(t-n)*(i-e)-(r-e)*(o-n),Fa=(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},hr=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},pu=(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=Ko(t.x,t.y,r.x,r.y,i.x,i.y),a=Ko(r.x,r.y,o.x,o.y,i.x,i.y),l=Ko(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:Fa(t,r,i,s)||Fa(r,o,i,a)||Fa(o,t,i,l)},Oa=n=>{let e=n.length;if(e<3)return[];let t=hr(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,c=null,u=null;if(e>=Kp){l=new qp,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],g=n[f],b=n[m],x=Ko(p.x,p.y,g.x,g.y,b.x,b.y);if(x>Ne){let y=!1;if(l&&c){let S=Math.min(p.x,g.x,b.x)-Ne,v=Math.max(p.x,g.x,b.x)+Ne,M=Math.min(p.y,g.y,b.y)-Ne,C=Math.max(p.y,g.y,b.y)+Ne,R=l.search({minX:S,minY:M,maxX:v,maxY:C});for(let w=0;w<R.length;w++){let T=R[w].v;if(u[T]&&!(T===d||T===f||T===m)&&pu(n,T,p,g,b)){y=!0;break}}}else for(let S=3;S<i;S++){let v=r[(a+S)%i];if(pu(n,v,p,g,b)){y=!0;break}}if(!y){o.push(d,f,m);let S=r.splice((a+1)%i,1)[0];i--,u&&(u[S]=0),h=0;continue}}else if(x>=-Ne){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 Qo=Math.PI,Qp=Math.PI/180,Tu=Math.PI/2,Ha=n=>{if(n===0)return 1;switch(Math.abs(n)/Tu){case 1:case 3:return 0;case 2:return-1}return Math.cos(n)},Wa=n=>{if(n===0)return 0;let e=n/Tu,t=Math.sign(n);switch(e){case 1:return t;case 2:return 0;case 3:return-t}return Math.sin(n)},Zp=/[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/gi,Jp=/[mzlhvcsqta][^mzlhvcsqta]*/gi,Gn=/\s*,?\s*/,Gr="([-+]?(?:\\d*\\.\\d+|\\d+\\.?)(?:[eE][-+]?\\d+)?)",Ba=new RegExp(`${Gn.source}${Gr}${Gn.source}${Gr}${Gn.source}${Gr}${Gn.source}([01])${Gn.source}([01])${Gn.source}${Gr}${Gn.source}${Gr}`,"g"),Eu={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},eb={m:"l",M:"L"},tb=n=>{let e=[],t=n.match(Jp)??[];for(let r of t){let o=r[0];if(o==="z"||o==="Z"){e.push([o]);continue}let i=Eu[o.toLowerCase()],s=[];if(o==="a"||o==="A"){Ba.lastIndex=0;for(let a=Ba.exec(r);a;a=Ba.exec(r))s=s.concat(a.slice(1))}else s=r.match(Zp)??[];for(let a=0;a<s.length;a+=i){let l=new Array(i),c=eb[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},bu=(n,e,t,r)=>{let o=Math.atan2(e,n),i=Math.atan2(r,t);return i>=o?i-o:2*Qo-(o-i)},nb=(n,e,t,r,o,i,s,a,l,c,u)=>{let h=Ha(n),d=Wa(n),f=Ha(e),m=Wa(e),p=t*o*f-r*i*m+s,g=r*o*f+t*i*m+a,b=c+l*(-t*o*d-r*i*h),x=u+l*(-r*o*d+t*i*h),y=p+l*(t*o*m+r*i*f),S=g+l*(r*o*m-t*i*f);return["C",b,x,y,S,p,g]},rb=(n,e,t,r,o,i,s)=>{if(t===0||r===0)return[];let a=0,l=0,c=0,u=s*Qp,h=Wa(u),d=Ha(u),f=.5*(-d*n-h*e),m=.5*(-d*e+h*n),p=t**2,g=r**2,b=m**2,x=f**2,y=p*g-p*b-g*x,S=Math.abs(t),v=Math.abs(r);if(y<0){let W=Math.sqrt(1-y/(p*g));S*=W,v*=W}else c=(o===i?-1:1)*Math.sqrt(y/(p*b+g*x));let M=c*S*m/v,C=-c*v*f/S,R=d*M-h*C+n*.5,w=h*M+d*C+e*.5,T=bu(1,0,(f-M)/S,(m-C)/v),E=bu((f-M)/S,(m-C)/v,(-f-M)/S,(-m-C)/v);i===0&&E>0?E-=2*Qo:i===1&&E<0&&(E+=2*Qo);let P=Math.ceil(Math.abs(E/Qo*2)),A=[],k=E/P,O=8/3*Math.sin(k/4)*Math.sin(k/4)/Math.sin(k/2),F=T+k;for(let W=0;W<P;W++)A[W]=nb(T,F,d,h,S,v,R,w,O,a,l),a=A[W][5],l=A[W][6],T=F,F+=k;return A},ob=(n,e,t,r,o,i,s,a,l)=>rb(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)),gu=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 ob(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},Ae=n=>{if(typeof n=="string"){if(!n)return null;let e=tb(n);return e.length>0?gu(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"||Eu[r]!==void 0)&&e.push(t)}return e.length===0?null:gu(e)}return null},xu=(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 S=-f/h;0<S&&S<1&&l.push(S);continue}let g=h*h-4*f*d;if(g<0)continue;let b=Math.sqrt(g),x=(-h+b)/(2*d);0<x&&x<1&&l.push(x);let y=(-h-b)/(2*d);0<y&&y<1&&l.push(y)}let m=l.length;for(let p=0;p<m;p++){let g=l[p],b=g**3,x=3*g**2*(1-g),y=3*g*(1-g)**2,S=(1-g)**3;c.push(s*b+o*x+t*y+n*S),u.push(a*b+i*x+r*y+e*S)}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)}]},je=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 xu(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 xu(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}},ib=(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)},Zo=(n,e,t,r,o,i,s,a,l,c,u)=>{if(u>24){n.push({x:a,y:l});return}if(ib(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,g=(s+l)/2,b=(h+f)/2,x=(d+m)/2,y=(f+p)/2,S=(m+g)/2,v=(b+y)/2,M=(x+S)/2;Zo(n,e,t,h,d,b,x,v,M,c,u+1),Zo(n,v,M,y,S,p,g,a,l,c,u+1)},Mu=(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":{Zo(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":{Zo(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},yu=(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},sb=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()},ab=(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)},Cu=(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},lb=(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},Ga=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}},vu=(n,e,t)=>e.x>=n.minX-t&&e.x<=n.maxX+t&&e.y>=n.minY-t&&e.y<=n.maxY+t,cb=n=>{let e=n.length,t=Ga(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 g=s[m*r+p];if(g){for(let b of g)if(!(b.pa===c||b.pb===c)&&Cu(l,c,b.pa,b.pb))return!0}}return!1}}},ub=(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 S=n[y],v=Math.hypot(S.x-i.x,S.y-i.y);if(v>=a)continue;let M=t.blockedExcept(i,S);if(!M){for(let C=0;C<e.length;C++)if(!(C===o||(C+1)%e.length===o)&&Cu(i,S,e[C],e[(C+1)%e.length])){M=!0;break}}M||(a=v,s=y)}if(s>=0){let y=[];for(let S=s;S<r;S++)y.push(n[S]);for(let S=0;S<s;S++)y.push(n[S]);y.push(n[s]),y.push(i);for(let S=1;S<e.length;S++)y.push(e[(o+S)%e.length]);return y.push(i),Su(t,n[s],i,e),y}let l=1/0,c=-1;for(let y=0;y<r;y++){let S=n[y],v=n[(y+1)%r];if(S.y!==v.y&&i.y>=Math.min(S.y,v.y)&&i.y<Math.max(S.y,v.y)){let M=(i.y-S.y)/(v.y-S.y),C=S.x+M*(v.x-S.x);C>=i.x&&C<l&&(l=C,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,g=Math.hypot(m,p)||1,b=-1/0;for(let y=0;y<r;y++){if(y===s)continue;let S=n[y];if(!ab(i,f,d,S))continue;let v=S.x-i.x,M=S.y-i.y,C=Math.hypot(v,M)||1,R=(v*m+M*p)/(C*g);(R>b+1e-12||Math.abs(R-b)<=1e-12&&C<a)&&(b=R,a=C,d=S,s=y)}let x=[];for(let y=s;y<r;y++)x.push(n[y]);for(let y=0;y<s;y++)x.push(n[y]);x.push(n[s]),x.push(i);for(let y=1;y<e.length;y++)x.push(e[(o+y)%e.length]);return x.push(i),Su(t,n[s],i,e),x},Su=(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])},Ru=(n,e="evenodd")=>{let t=n.map(c=>sb(c.points)).filter(c=>c.length>=3);if(t.length===0)return[];let r=t.map(c=>Ga(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&&vu(r[h],u,1e-6)&&(lb(u,t[h],1e-6)||yu(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=hr(t[c])>0?1:-1;for(let h=0;h<t.length;h++)h!==c&&i[h][c]&&(u+=hr(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&&vu(f.bbox,u,0)&&yu(u,f.ring));if(!h)continue;hr(h.ring)*hr(c.ring)>0&&(c.ring=c.ring.slice().reverse()),h.grid??=cb(h.ring),h.ring=ub(h.ring,c.ring,h.grid);let d=Ga(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 hb=new Set(["miter","round","bevel"]),db=new Set(["butt","round","square"]),Jo=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"&&hb.has(n.strokeLineJoin)?n.strokeLineJoin:"miter",o=typeof n.strokeLineCap=="string"&&db.has(n.strokeLineCap)?n.strokeLineCap:"butt";return{color:n.stroke,rgba:ae(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||J(n)===L.PATH}},Pu=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 fb=(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)},mb=625e4,ku=(n,e,t)=>Math.min(n,8192/e,8192/t,Math.sqrt(mb/(e*t))),ei=(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}},Xn=(n,e)=>{let t=e.raw,r=J(t);if(n.beginPath(),r===L.PATH){let o=Ae(t.path);if(!o)return!1;let i=je(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=rt(t,o,i);return s?Wr(n,o,i,s.rx,s.ry):n.rect(-o/2,-i/2,o,i),!0}return!1},Au=(n,e)=>{let t=Jo(n.raw);if(!t)return null;let r=J(n.raw);if(r===L.ARROW||r===L.DIMENSION)return gb(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=fb(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=ku(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,g=e&&u===c?ei(p,e.zoom,e.dpr,e.vpt,a,l):null,b=g?g.lx:p[4]-a/2,x=g?g.ly:p[5]-l/2,y=h/u,S=d/u,v=[p[0]*u,p[1]*u,p[2]*u,p[3]*u,(p[4]-b)*u,(p[5]-x)*u];if(m.setTransform(v[0],v[1],v[2],v[3],v[4],v[5]),!Xn(m,n))return null;let M=v;if(t.uniform){let C=Math.hypot(p[0],p[1])||1,R=Math.hypot(p[2],p[3])||1;M=Y(v,[1/C,0,0,1/R,0,0])}if(m.setTransform(M[0],M[1],M[2],M[3],M[4],M[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 C=Xr(n,m);typeof n.raw.fill=="string"&&n.raw.fill!==""&&n.raw.fill!=="transparent"||m.clip(),m.fillStyle=C,m.fill(),m.globalCompositeOperation="source-over"}return{canvas:f,w:y,h:S,lx:b,ly:x,sceneW:a,sceneH:l,snapped:!!g}}return m.stroke(),{canvas:f,w:y,h:S,lx:b,ly:x,sceneW:a,sceneH:l,snapped:!!g}},Xr=(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 pb(n)},pb=n=>{let e=n.raw.stroke;return typeof e=="string"&&e?e:"#000"},bb=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}},gb=(n,e,t)=>{let r=bb(n);if(!r)return null;let o=n.raw,s=J(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),g=d*p,b=f*p;if(s)u=Math.ceil(u+b+g);else{let K=Number(o.textFontSize)||50,G=typeof o.text=="string"&&o.text.trim()?o.text:"50cm",Z=Number(o.textPadding)||4,B=`${K}px Arial, sans-serif`,j=zr(B,G)+Z*2,Q=Math.atan2(r.y2-r.y1,r.x2-r.x1),ie=-Math.sin(Q),ce=Math.cos(Q),me=K+a/2+5;h={text:G,fontPx:K,w:j,h:K+Z*2,cx:(r.x1+r.x2)/2+ie*me,cy:(r.y1+r.y2)/2+ce*me,angle:o.textFollowLine===!1?0:Q,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+me+Math.max(j,K*2)*.75)}let x=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,S=x+u*2,v=y+u*2;if(!(S>0)||!(v>0)||S>8192||v>8192)return null;let M=t?t.zoom*t.dpr:1,C=ku(M,S,v),R=Math.ceil(S*C),w=Math.ceil(v*C);if(!(R>0)||!(w>0))return null;let T=document.createElement("canvas");T.width=R,T.height=w;let E=T.getContext("2d");if(!E)return null;let P=n.matrix,A=t&&C===M?ei(P,t.zoom,t.dpr,t.vpt,S,v):null,k=A?A.lx:P[4]-S/2,O=A?A.ly:P[5]-v/2,F=[P[0]*C,P[1]*C,P[2]*C,P[3]*C,(P[4]-k)*C,(P[5]-O)*C];E.setTransform(F[0],F[1],F[2],F[3],F[4],F[5]);let W=r.x2-r.x1,X=r.y2-r.y1,_=Math.atan2(X,W),D=Math.cos(_),I=Math.sin(_);if(s){let K=m==="start"||m==="both",G=m==="end"||m==="both",Z=r.x1+D*(K?b:0),B=r.y1+I*(K?b:0),j=r.x2-D*(G?b:0),Q=r.y2-I*(G?b:0);E.lineWidth=a,E.strokeStyle=l,c&&c.length>0?E.setLineDash(c):E.setLineDash([]),E.beginPath(),E.moveTo(Z,B),E.lineTo(j,Q),E.stroke(),E.setLineDash([]);let ie=(ce,me,Re)=>{E.save(),E.translate(ce,me),E.rotate(Re),E.beginPath(),E.moveTo(0,0),E.lineTo(-b,-g/2),E.lineTo(-b,g/2),E.closePath(),E.fillStyle=l,E.fill(),E.restore()};return G&&ie(r.x2,r.y2,_),K&&ie(r.x1,r.y1,_+Math.PI),{canvas:T,w:R/C,h:w/C,lx:k,ly:O,sceneW:S,sceneH:v,snapped:!!A}}E.beginPath(),E.moveTo(r.x1,r.y1),E.lineTo(r.x2,r.y2);let H=F;if(e.uniform){let K=Math.hypot(P[0],P[1])||1,G=Math.hypot(P[2],P[3])||1;H=Y(F,[1/K,0,0,1/G,0,0])}E.setTransform(H[0],H[1],H[2],H[3],H[4],H[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 z=-I,U=D,$=(Number(o.textFontSize)||50)/2;E.lineWidth=a,E.lineCap="round",e.dashArray&&E.setLineDash([]),E.strokeStyle=l;for(let[K,G]of[[r.x1,r.y1],[r.x2,r.y2]])E.beginPath(),E.moveTo(K-z*$,G-U*$),E.lineTo(K+z*$,G+U*$),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:T,w:R/C,h:w/C,lx:k,ly:O,sceneW:S,sceneH:v,snapped:!!A}},zr=(n,e)=>{let t=document.createElement("canvas").getContext("2d");return t?(t.font=n,t.measureText(e).width):e.length*50};var pe={LEFT:"left",CENTER:"center",RIGHT:"right",JUSTIFY:"justify",JUSTIFY_LEFT:"justify-left",JUSTIFY_CENTER:"justify-center",JUSTIFY_RIGHT:"justify-right",DISPERSE:"disperse"},xb=Object.values(pe),Ut=n=>n===pe.JUSTIFY||n===pe.JUSTIFY_LEFT||n===pe.JUSTIFY_CENTER||n===pe.JUSTIFY_RIGHT,Xa=n=>n===pe.JUSTIFY_LEFT||n===pe.JUSTIFY_CENTER||n===pe.JUSTIFY_RIGHT,Yr=n=>n===pe.JUSTIFY||n===pe.DISPERSE;var Nu=400,ti=1.13,ni=.222,yb=2,vb={underline:.1,linethrough:-.28167,overline:-.81333},Sb=66.667,wb=/[a-zA-Z.\s]+/,Tb=/[0-9]/,Eb=/[()[\]{}></:;:,.?!]/,Vr=n=>wb.test(n)||Tb.test(n)||Eb.test(n),Mb=new Set(["ー","「","」","『","』","(",")","〔","〕","[","]","{","}","⦅","⦆","〈","〉","《","》","【","】","〖","〗","〘","〙","〚","〛","゛","゜","。","、","・","゠","=","〜","…","•","‥","◦","﹅","﹆"]),Cb=new Set(["「","」","『","』","〔","〕","[","]","{","}","⦅","⦆","〈","〉","《","》","【","】","〖","〗","〘","〙","〚","〛","(",")"]),Yn=n=>Vr(n)?"latin":Cb.has(n)?"bracket":Mb.has(n)?"symbol":"cjk",Un=(n,e,t)=>Vr(n)?e.width:e.height+t,an=n=>n/1.1,dr=(n,e,t)=>n==="symbol"?-t/3.14:e.height/2-t/3.14,Tt=(n,e,t)=>n===0||t%2===0?0:n/300*e*.5,Fu=(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},Ur=null,Ou=(n,e,t)=>{let r={left:0,right:0,ascent:t*.88,descent:t*.24};if(typeof document>"u")return r;if(!Ur){let i=document.createElement("canvas");i.width=8,i.height=8,Ur=i.getContext("2d")}if(!Ur)return r;Ur.font=n;let o=Ur.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}},Lu=new WeakMap,Ua=new Set,Iu=(n,e,t)=>{let r=Lu.get(n);r||(r=new Map,Lu.set(n,r),Ua.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},Rb=(n,e,t=Ou)=>{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=Hu(e,n.charStyles[a]),h=Yn(l),d,f;if(h==="latin"||h==="bracket"){let m=h==="latin"?c.kernedWidth-c.width:0,p=Iu(t,u,l);d=p.left+m,f=p.right+m}else{let m=Iu(t,u,l);d=an(u.fontSize)-m.ascent,f=an(u.fontSize)+m.descent}a===0&&(i=d),s=o+f,o+=Un(l,c,r)}return{start:i,end:s}},$a=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"]),Me=(n,e)=>{let t=n.fontFamily,r=t.includes("'")||t.includes('"')||t.includes(",")||$a.has(t.toLowerCase())?t:`"${t}"`;return`${n.fontStyle??"normal"} ${n.fontWeight??"normal"} ${e}px ${r}`},Pb=(n,e)=>{if(n)return n.id===0?`${e+1}`:n.content||void 0},Fe=(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}},jr=/[\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},Et=(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},Va=(n,e,t)=>{let r=[],o=!!t[e],i=y=>!!(n.charStyles[y]?.[e]??o);if(!n.graphemes.some((y,S)=>i(S)))return r;let s=y=>n.charStyles[y]?.fill??t.fill??"",a=y=>n.charStyles[y]?.textDecorationThickness??t.textDecorationThickness??Sb,l=y=>n.charStyles[y]?.fontSize??t.fontSize,c=vb[e],u=e==="linethrough"?.5:e==="overline"?1:0,h=t.charSpacing?t.fontSize*t.charSpacing/1e3:0,d=(y,S,v,M,C,R)=>{if(!y||!S||!v||R<=0)return;let w=t.fontSize*v/1e3;r.push({x:C,width:R,y:c*M-u*w,thickness:w,color:S})},f=0,m=0,p=i(0),g=s(0),b=a(0),x=l(0);for(let y=0;y<n.graphemes.length;y++){let S=i(y),v=s(y),M=a(y),C=l(y),R=n.boxes[y],w=t.vertical?Vr(n.graphemes[y])?R.kernedWidth:R.height:R.kernedWidth;(S!==p||v!==g||M!==b||C!==x)&&m>0?(d(p,g,b,x,f,m),f=R.left,m=t.vertical?w:R.width,p=S,g=v,b=M,x=C):m+=t.vertical?w:R.kernedWidth}return d(p,g,b,x,f,m-h),r},$r=null,kb=(n,e)=>{if(typeof document>"u")return 0;if(!$r){let t=document.createElement("canvas");if(t.width=8,t.height=8,$r=t.getContext("2d"),!$r)return 0}return $r.font=n,$r.measureText(e).width},zn=n=>Array.from(n),Ab=n=>n.split(/[ \t\r]/),za=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}},_u=new WeakMap,Nb=(n,e)=>{let t=_u.get(e);t||(t=new Map,_u.set(e,t),Ua.add(t));let r=t.get(n);return r||(r=new za(n,e),t.set(n,r)),r},Bu=()=>{for(let n of Ua)n.clear()},Hu=(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},Ya=(n,e,t,r,o)=>{let i=Nb(Me(e,Nu),n),s=e.fontSize/Nu,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}},Wu=n=>n.charSpacing?n.fontSize*n.charSpacing/1e3:0,Du=(n,e,t,r,o,i,s,a=!1)=>{let l=Wu(o),c=[],u=" ",h=0,d=[],f=0,m=!0,p=0,g=Math.max(e,r,yb),b=t[n];for(let x=0;x<b.length;x++){let y=b[x].graphemes,S=b[x].width;p+=y.length,h+=(a?0:f)+S-l,h>g&&!m?(c.push(d),d=[],h=S,m=!0):h+=l,!m&&!a&&d.push(u),d=d.concat(y),f=a?0:Ya(s,i(n,p),u).kernedWidth+l,p++,m=!1}return b.length&&c.push(d),c},$n=(n,e,t={})=>{let r=t.measure??kb,o=t.inkMeasure??Ou,i=t.styles,s=(E,P)=>Hu(e,i?.[E]?.[P]),a=Wu(e),l=e.lineHeight??1.16,c=(E,P,A)=>{let k=0,O;for(let F=0;F<E.length;F++){let W=Ya(r,s(P,A+F),E[F],O,F>0?s(P,A+F-1):void 0);k+=W.kernedWidth+a,O=E[F]}return k},u=(n??"").split(`
3
- `),h,d=0;if(t.boxWidth==null)h=u.map(E=>zn(E));else if(t.splitByGrapheme){let E=[];for(let P=0;P<u.length;P++){let A=zn(u[P]);if(A.length===0){E.push([{graphemes:[],width:0,charOffset:0}]);continue}let k=A.map((O,F)=>{let W=c([O],P,F);return d=Math.max(W,d),{graphemes:[O],width:W,charOffset:F}});E.push(k)}h=[];for(let P=0;P<E.length;P++)h.push(...Du(P,t.boxWidth,E,d,e,s,r,!0))}else{let E=[];for(let P=0;P<u.length;P++){let A=[],k=0;for(let O of Ab(u[P])){let F=zn(O),W=c(F,P,k);d=Math.max(W,d),A.push({graphemes:F,width:W,charOffset:k}),k+=F.length+1}E.push(A)}h=[];for(let P=0;P<E.length;P++)h.push(...Du(P,t.boxWidth,E,d,e,s,r))}let f=zn(n??""),m=[];{let E=0,P=0,A=0;for(let k=0;k<h.length;k++){let O=f[A];O===`
4
- `&&k>0?(P=0,A++,E++):k>0&&!t.splitByGrapheme&&/[ \t\r]/.test(O??"")&&(P++,A++),m[k]={line:E,offset:P,flatStart:A},A+=h[k].length,P+=h[k].length}}let p=h.map((E,P)=>{let A=m[P],k=[],O=0;for(let _=0;_<E.length;_++){let D=Ya(r,s(A.line,A.offset+_),E[_],_>0?E[_-1]:void 0,_>0?s(A.line,A.offset+_-1):void 0),I={left:0,width:D.width+a,kernedWidth:D.kernedWidth+a,height:s(A.line,A.offset+_).fontSize};_>0&&(I.left=k[_-1].left+k[_-1].width+D.kernedWidth-D.width),k.push(I),t.vertical&&!Vr(E[_])?O+=I.height:O+=I.kernedWidth}a!==0&&(O-=a),O<0&&(O=0);let F=E.map((_,D)=>i?.[A.line]?.[A.offset+D]),W=0;if(E.length>0)for(let _=0;_<E.length;_++)W=Math.max(W,i?.[A.line]?.[A.offset+_]?.fontSize??e.fontSize);else W=i?.[A.line]?.[A.offset]?.fontSize??e.fontSize;let X;if(t.paragraph){let _=Pb(t.paragraph,P);if(_){let D=s(A.line,A.offset),I=Me(D,D.fontSize),H=r(I,_);if(H>0){X={text:_,width:H,advances:zn(_).map(z=>r(I,z)),style:D};for(let z of k)z.left+=X.width;O+=X.width}}}return{graphemes:E,boxes:k,width:O,leftOffset:0,baseline:0,top:0,implHeight:W*ti,styleMap:A,charStyles:F,prefix:X}}),g=0,b=0;for(let E=0;E<p.length;E++){let P=p[E].implHeight,A=E===p.length-1;p[E].top=b,p[E].baseline=b+P*(1-ni),b+=P*l,g+=A?P:P*l}let x=t.boxWidth!=null?Math.max(t.boxWidth,d-a):0,y=()=>{let E=0;for(let P of p){let A=0;for(let k=0;k<P.graphemes.length;k++)A+=Vr(P.graphemes[k])?P.boxes[k].width+a:P.boxes[k].height+a;E=Math.max(E,A)}return E+2},S=t.vertical?y():void 0,v=t.boxWidth!=null?x:t.vertical?S:Math.max(0,...p.map(E=>E.width)),M=e.textAlign??pe.LEFT,C=E=>{if(t.boxWidth==null)return E===p.length-1;let P=p[E+1]?.styleMap;return!P||P.line!==p[E].styleMap.line};for(let E=0;E<p.length;E++){let P=M===pe.CENTER||M===pe.JUSTIFY_CENTER&&C(E),A=M===pe.RIGHT||M===pe.JUSTIFY_RIGHT&&C(E);if(t.vertical&&(P||A)&&p[E].graphemes.length>0){let O=Rb(p[E],e,o);p[E].leftOffset=P?(v-O.start-O.end)/2:v-O.end;continue}let k=v-p[E].width;P?p[E].leftOffset=k/2:A&&(p[E].leftOffset=k)}let R=M===pe.DISPERSE;if((Ut(M)||R)&&!t.vertical)for(let E=0;E<p.length;E++){let P=p[E],A=Xa(M);if(A&&(E===p.length-1||C(E))||!A&&!R&&E===p.length-1||P.width>=v)continue;let k=!A&&P.graphemes.some(X=>jr.test(X)),O=k?P.graphemes.length-1:P.graphemes.reduce((X,_)=>/[ \t\r]/.test(_)?X+1:X,0);if(O<=0)continue;let F=(v-P.width)/O,W=0;for(let X=0;X<P.graphemes.length;X++){let _=P.boxes[X],D=k?X<P.graphemes.length-1:/[ \t\r]/.test(P.graphemes[X]);_.left+=W,D&&(_.width+=F,_.kernedWidth+=F,W+=F)}}let w=[],T=0;for(let E of f)w.push(T),T+=E.length;return w.push(T),{lines:p,width:v,height:g,graphemeCodeUnitOffsets:w,verticalWidth:S}};var Lb=1e4,qr=2,Gu=(n,e)=>{let t=e-n;for(;t>=2*Math.PI;)t-=2*Math.PI;for(;t<=0;)t+=2*Math.PI;return t},ri=(n,e,t)=>Gu(n,e)+Gu(e,t)<2*Math.PI,oi=(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(ri(l,0,c)){let u=t.x+r;u>s&&(s=u)}if(ri(l,Math.PI/2,c)){let u=t.y+r;u>a&&(a=u)}if(ri(l,Math.PI,c)){let u=t.x-r;u<o&&(o=u)}if(ri(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}},qe=n=>J(n)===L.ARCTEXT?"arc":J(n)===L.CIRCLETEXT?"circle":null,Xu=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}),Ib=(n,e,t)=>{let r=Xu(n),o=n.width,i=R=>n.lines[R].implHeight*e,s=0;for(let R=0;R<n.lines.length;R++)s+=i(R);let a=Math.abs(t),l=a*Math.PI/180,c=0;for(let R=0;R<n.lines.length;R++)c+=n.lines[R].width;let u=l>0?c/l:0,h=Math.max(Lb/Math.max(a,.1),u),d=0,f=t>0?s/2+h:-s/2+h,m=t>0?s:0,p=1/0,g=-1/0,b=1/0,x=-1/0,y=[];for(let R=0;R<r.length;R++){let w=-o/2+n.lines[R].leftOffset,T=i(R),E=T-T/e+T*ni/e;m+=t>0?-T:T;let P=Math.abs(h)+m,A=t>0?P+T-T/e:P-T+T/e,k=[];for(let D=0;D<r[R].length;D++){let I=r[R][D],H,z,U,$,K,G,Z;t>0?(H=P,z=P+T,U=P+E,$=(H*3+z*2)/5,K=-(w+I.left)/$,G=-(w+I.left+I.width)/$,Z=-(w+I.left+I.width/2)/$):(H=P,z=P-T,U=P-E,$=(H*2+z*3)/5,K=Math.PI+(w+I.left)/$,G=Math.PI+(w+I.left+I.width)/$,Z=Math.PI+(w+I.left+I.width/2)/$);let B=Math.sin(G),j=Math.cos(G),Q=Math.sin(K),ie=Math.cos(K),ce=Math.sin(Z),me=Math.cos(Z);k.push({tl:{x:d-z*Q,y:f-z*ie},tr:{x:d-z*B,y:f-z*j},nl:{x:d-A*Q,y:f-A*ie},nr:{x:d-A*B,y:f-A*j}});let Re=n.lines[R].graphemes[D];Re!==void 0&&y.push({char:Re,line:R,index:D,x:d-U*ce,y:f-U*me,rotation:t>0?-Z:-Z-Math.PI})}let O=k[0],F=k[k.length-1];if(!O||!F)continue;let W={x:d,y:f},X=t>0?oi(O.tl,F.tr,W,P+T):oi(F.tr,O.tl,W,P-T),_=t>0?oi(O.nl,F.nr,W,P):oi(F.nr,O.nl,W,P);p=Math.min(p,X.x,_.x),g=Math.max(g,X.x+X.width,_.x+_.width),b=Math.min(b,X.y,_.y),x=Math.max(x,X.y+X.height,_.y+_.height)}Number.isFinite(p)||(p=g=b=x=0);let S=-p-o/2,v=g-o/2,M=-b-s/2,C=x-s/2;return{width:Math.max(o+S+v,qr),height:s+M+C,contentOffsetX:v/2-S/2,contentOffsetY:C/2-M/2,chars:y}},_b=(n,e,t)=>{let r=Xu(n),o=T=>n.lines[T].implHeight*e,i=0;for(let T=0;T<n.lines.length;T++)i+=o(T);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 T=0;T<n.lines.length;T++)f+=n.lines[T].width;let m=0,p=0;if(f<=0||r.length===0)return{width:qr,height:Math.max(i,qr),contentOffsetX:0,contentOffsetY:0,chars:[]};let g=1/0,b=-1/0,x=1/0,y=-1/0,S=[],v=0;for(let T=0;T<r.length;T++){let E=o(T),P=E-E/e+E*ni/e,A=E-P;for(let k=0;k<r[T].length;k++){let O=r[T][k],W=(v+O.left+O.width/2)/f,X=h-W*u,_=Math.sin(X),D=Math.cos(X),I=m-a*_,H=p-c*D,z,U,$,K,G;if(d)z=0,U=1,$=0,K=0,G=-1;else{let Q=a*D,ie=-c*_,ce=Math.hypot(Q,ie)||1;U=Q/ce,$=ie/ce;let me=-c*_,Re=-a*D,De=Math.hypot(me,Re)||1;K=me/De,G=Re/De,z=Math.atan2(ie,Q)}let Z=-z,B=O.width/2;g=Math.min(g,I-K*P-U*B,I-K*P+U*B,I+K*A-U*B,I+K*A+U*B),b=Math.max(b,I-K*P-U*B,I-K*P+U*B,I+K*A-U*B,I+K*A+U*B),x=Math.min(x,H-G*P-$*B,H-G*P+$*B,H+G*A-$*B,H+G*A+$*B),y=Math.max(y,H-G*P-$*B,H-G*P+$*B,H+G*A-$*B,H+G*A+$*B);let j=n.lines[T].graphemes[k];j!==void 0&&S.push({char:j,line:T,index:k,x:I,y:H,rotation:-Z})}v+=n.lines[T].width}Number.isFinite(g)||(g=b=x=y=0);let M=-g-s/2,C=b-s/2,R=-x-i/2,w=y-i/2;return{width:Math.max(b-g,qr),height:Math.max(y-x,qr),contentOffsetX:C/2-M/2,contentOffsetY:w/2-R/2,chars:S}},Mt=(n,e,t)=>J(e)===L.CIRCLETEXT?_b(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"}):Ib(n,t,typeof e.curvature=="number"?e.curvature:300);var Vn=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},ja=(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 g=p.colSpan??1,b=p.rowSpan??1,x=Math.max(c*g+e.hGap*(g-1),0),y=Math.max(u*b+e.vGap*(b-1),0),S=p.col+(g-1)/2,v=p.row+(b-1)/2;return{w:x,h:y,cx:(S-f)*h,cy:(v-m)*d}})},Db=(n,e)=>e&&e.naturalWidth&&e.naturalHeight?{w:e.naturalWidth,h:e.naturalHeight}:{w:n?.width??0,h:n?.height??0},zu=(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,g=s?(c.top||0)*o:c.top;if(c.left=p,c.top=g,c.width=f,c.height=m,c.clip){let b=i&&h?f/h:1,x=s&&d?m/d:1,y=t?.[u]??Db(c.clip,null);if(y.w&&y.h){let S=Math.max(h/y.w,d/y.h),v=Math.max(f/y.w,m/y.h),M=c.clip.scaleX||c.clip.scaleY||1,C=S?M/S:1,R=v*(C||1);c.clip.scaleX=R,c.clip.scaleY=R}c.clip.clipX=(c.clip.clipX||0)*b,c.clip.clipY=(c.clip.clipY||0)*x}}),!0},ii=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 Fb=(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},Ob=(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}),fr=(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},Yu=(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=Fb(i,n.cols)*d;if(t<f)return!1;let m=l-f,p=Math.min(t,Math.max(c,m)),g=Lt(i),b=n.hGap||0,x=[],y=null,S=5,v=.3;n.masks.forEach((B,j)=>{if(j===e)return;let Q=Lt(B),ie=Math.min(g.bottom,Q.bottom)-Math.max(g.top,Q.top);if(!(ie<=0||ie<Math.min(i.height,B.height)*v))if(r==="right"){if(Q.left<=i.left)return;let ce=Q.left;y===null||ce<y-S?(y=ce,x.length=0,x.push(j)):Math.abs(ce-y)<=S&&x.push(j)}else{if(Q.right>=i.left)return;let ce=Q.right;y===null||ce>y+S?(y=ce,x.length=0,x.push(j)):Math.abs(ce-y)<=S&&x.push(j)}});let M=B=>o?.[B]??null;if(!x.length){let B=l/2,j=r==="right"?B-g.left:g.right+B,Q=Math.max(s,Math.min(p,Math.max(s,j)));return Q===u?!1:(i.left=r==="right"?g.left+Q/2:g.right-Q/2,i.width=Q,fr(i,u,h,M(e)),!0)}let C=1/0,R=-1/0;for(let B of x){let j=Lt(n.masks[B]);j.left<C&&(C=j.left),j.right>R&&(R=j.right)}let w=r==="right"?g.left:g.right,T=B=>{let j=Lt(n.masks[B]);return r==="right"?j.right:j.left},E=1/0;for(let B of x){let j=(r==="right"?T(B)-w:w-T(B))-b-s;j<E&&(E=j)}let P=Math.max(s,Math.min(p,Math.max(s,E))),A=r==="right"?w+P:w-P;for(let B of x)if((r==="right"?T(B)-A:A-T(B))-b<s-1e-6)return!1;if(P<=0)return!1;i.left=r==="right"?w+P/2:w-P/2,i.width=P;let k=new Map;k.set(e,{width:u,height:h});for(let B of x){let j=n.masks[B];k.set(B,{width:j.width,height:j.height});let Q=T(B);r==="right"?(j.width=Q-A-b,j.left=(A+b+Q)/2):(j.width=A-b-Q,j.left=(A-b+Q)/2)}for(let B of[e,...x]){let j=k.get(B);fr(n.masks[B],j.width,j.height,M(B))}let O=Lt(i),F=O.left,W=O.right,X=Lt(n.masks[x[0]]),_=X.left,D=X.right,I=r==="right"?g.right:g.left,H=r==="right"?W:F,z=new Set(x),U=typeof i.colStart=="number"&&typeof i.colEnd=="number"?{colStart:i.colStart,colEnd:i.colEnd}:null,$=n.masks[x[0]],K=$&&typeof $.colStart=="number"&&typeof $.colEnd=="number"?{colStart:$.colStart,colEnd:$.colEnd}:null,G=n.cols>0&&!!U&&!!K,Z=(B,j,Q)=>{let ie=n.masks[B],ce=ie.width,me=ie.height,Re=Math.max(c,Q-j);ie.left=(j+Q)/2,ie.width=Re,fr(ie,ce,me,M(B))};return n.masks.forEach((B,j)=>{if(j===e||z.has(j))return;let Q=Lt(B),ie=Q.left,ce=Q.right;if(G&&U&&K&&typeof B.colStart=="number"&&typeof B.colEnd=="number"){if(B.colStart===U.colStart&&B.colEnd===U.colEnd){Z(j,F,W);return}if(B.colStart===K.colStart&&B.colEnd===K.colEnd){Z(j,_,D);return}let Ee=r==="right"?U.colEnd+1:U.colStart,ue=B.colStart===Ee,ye=B.colEnd+1===Ee;if(!ue&&!ye)return;let fe=ue?H+(r==="right"?b:0):ie,we=ye?H-(r==="left"?b:0):ce;if(we-fe<=0)return;Z(j,fe,we);return}let me=.5;if(Math.abs(ie-g.left)<me&&Math.abs(ce-g.right)<me){Z(j,F,W);return}if(Math.abs(ie-C)<me&&Math.abs(ce-R)<me){Z(j,_,D);return}let Re=Math.abs(ie-I)<me,De=Math.abs(ce-I)<me;if(!Re&&!De)return;let et=Re?H:ie,Pe=De?H:ce;Pe-et<=0||Z(j,et,Pe)}),i.width!==u},Uu=(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=Ob(i,n.rows)*d;if(t<f)return!1;let m=l-f,p=Math.min(t,Math.max(c,m)),g=Lt(i),b=n.vGap||0,x=-1,y=0,S=0,v=.3;n.masks.forEach((ue,ye)=>{if(ye===e)return;let fe=Lt(ue),we=Math.min(g.right,fe.right)-Math.max(g.left,fe.left);if(!(we<=0||we<Math.min(i.width,ue.width)*v))if(r==="bottom"){if(fe.top<=i.top)return;(x===-1||fe.top<y)&&(x=ye,y=fe.top,S=fe.bottom)}else{if(fe.bottom>=i.top)return;(x===-1||fe.bottom>S)&&(x=ye,y=fe.top,S=fe.bottom)}});let M=ue=>o?.[ue]??null;if(x===-1){let ue=l/2,ye=r==="bottom"?ue-g.top:g.bottom+ue,fe=Math.max(s,Math.min(p,Math.max(s,ye)));return fe===u?!1:(i.top=r==="bottom"?g.top+fe/2:g.bottom-fe/2,i.height=fe,fr(i,h,u,M(e)),!0)}let C=r==="bottom"?g.top:y,R=r==="bottom"?S:g.bottom,w=R-C,T=Math.max(s,w-b-s),E=Math.max(s,Math.min(p,T)),P=w-b-E;if(P<s){let ue=w-b-s;if(ue<s||(E=Math.max(s,Math.min(p,ue)),P=w-b-E,P<s))return!1}if(E<=0||P<=0)return!1;let A,k;r==="bottom"?(A=C+E/2,k=R-P/2):(k=C+P/2,A=R-E/2);let O=new Map;O.set(e,{width:h,height:u}),O.set(x,{width:n.masks[x].width,height:n.masks[x].height}),i.top=A,i.height=E;let F=n.masks[x];F.top=k,F.height=P;for(let ue of[e,x]){let ye=O.get(ue);fr(n.masks[ue],ye.width,ye.height,M(ue))}let W=A-E/2,X=A+E/2,_=k-P/2,D=k+P/2,I=r==="bottom",H=I?W:_,z=I?X:D,U=I?_:W,$=I?D:X,K=I?g.top:y,G=I?g.bottom:S,Z=I?y:g.top,B=I?S:g.bottom,j=r==="bottom"?g.bottom:g.top,Q=r==="bottom"?X:W,ie=typeof i.rowStart=="number"&&typeof i.rowEnd=="number"?{rowStart:i.rowStart,rowEnd:i.rowEnd}:null,ce=n.masks[x],me=ce&&typeof ce.rowStart=="number"&&typeof ce.rowEnd=="number"?{rowStart:ce.rowStart,rowEnd:ce.rowEnd}:null,Re=n.rows>0&&!!ie&&!!me,De=Re&&ie&&me?ie.rowStart<=me.rowStart?ie:me:null,et=Re&&ie&&me?De===ie?me:ie:null,Pe=De?De.rowEnd+1:void 0,Ee=(ue,ye,fe)=>{let we=n.masks[ue],tt=we.width,Ve=we.height,Xe=Math.max(c,fe-ye);we.top=(ye+fe)/2,we.height=Xe,fr(we,tt,Ve,M(ue))};return n.masks.forEach((ue,ye)=>{if(ye===e||ye===x)return;let fe=Lt(ue),we=fe.top,tt=fe.bottom;if(Re&&De&&et&&Pe!==void 0&&typeof ue.rowStart=="number"&&typeof ue.rowEnd=="number"){if(ue.rowStart===De.rowStart&&ue.rowEnd===De.rowEnd){Ee(ye,H,z);return}if(ue.rowStart===et.rowStart&&ue.rowEnd===et.rowEnd){Ee(ye,U,$);return}let vt=ue.rowStart===Pe,St=ue.rowEnd+1===Pe;if(!vt&&!St)return;let _n=vt?Q+(r==="bottom"?b:0):we,Dn=St?Q-(r==="top"?b:0):tt;if(Dn-_n<=0)return;Ee(ye,_n,Dn);return}let Ve=.5;if(Math.abs(we-K)<Ve&&Math.abs(tt-G)<Ve){Ee(ye,H,z);return}if(Math.abs(we-Z)<Ve&&Math.abs(tt-B)<Ve){Ee(ye,U,$);return}let Xe=Math.abs(we-j)<Ve,gt=Math.abs(tt-j)<Ve;if(!Xe&&!gt)return;let xt=Xe?Q:we,yt=gt?Q:tt;yt-xt<=0||Ee(ye,xt,yt)}),i.height!==u};var $u=(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:ii(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}},Vu=(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}},ju=(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}},qu=(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},Se=(n,e,t)=>n.get(`${e},${t}`),lt=(n,e,t)=>{let r=Se(n,e,t);return r?.isMerged&&r.mergeParent?{row:r.mergeParent.row,col:r.mergeParent.col}:{row:e,col:t}},br=n=>{let e=Array.isArray(n.cellData)?n.cellData:null;if(e)return e;let t=[];return n.cellData=t,t},gr=n=>n.rows??3,ai=n=>n.cols??3,Ka=n=>n.minCellHeight??40,qa=n=>n.minCellWidth??40,Qa=n=>{let e=ai(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},Kr=(n,e)=>{let t=Array.isArray(n.columnWidths)?n.columnWidths:null;t?(t.length=0,t.push(...e)):n.columnWidths=e},Zu=(n,e,t,r)=>{let o=gr(n),i=Ka(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},Ju=(n,e,t,r)=>{let o=gr(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},Qr=(n,e,t)=>{let r=Qa(n);e<0||e>=r.length||(r[e]=Math.max(qa(n),t),Kr(n,r))},Zr=(n,e,t)=>{let r=gr(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(Ka(n),t),n.manualRowHeights=i},Za=(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=Se(n,s,a);if(l){if(l.isMerged&&l.mergeParent){let c=Se(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}},Bb=(n,e,t)=>{for(let r=t.r1;r<=t.r2;r++)for(let o=t.c1;o<=t.c2;o++){let i=Se(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}},Hb=(n,e)=>{let t=[];for(let r=e.r1;r<=e.r2;r++)for(let o=e.c1;o<=e.c2;o++){let i=Se(n,r,o)?.text;i&&i.trim()&&t.push(i.trim())}return t.join(`
5
- `)},Ja=(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=Se(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=""}},Jr=(n,e,t,r,o)=>{let i=br(n),s=It(i),a=Za(s,Math.min(e,r),Math.max(e,r),Math.min(t,o),Math.max(t,o));Bb(i,s,a);let l=Se(s,a.r1,a.c1);return l&&(l.text=Hb(s,a),l.colspan=a.c2-a.c1+1,l.rowspan=a.r2-a.r1+1,Ja(i,s,a.r1,a.c1,l.rowspan,l.colspan)),a},eo=(n,e,t)=>{let r=It(br(n)),o=Se(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=Se(r,a,l);c&&(c.isMerged=!1,c.mergeParent=null)}return!0},eh=n=>({cellFill:n.cellFill,textFill:n.textFill,fontSize:n.fontSize,fontWeight:n.fontWeight,fontFamily:n.fontFamily,fontStyle:n.fontStyle,textAlign:n.textAlign}),th=(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}),li=(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)},nh=(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},to=(n,e)=>{let t=gr(n),r=ai(n),o=br(n),i=It(o),s=Math.max(0,Math.min(e,t)),a=nh(o,"row",s),l=s>0?s-1:s<t?s:null;li(o,"row",s,1);for(let u=0;u<r;u++){let h=l!==null?Se(i,l,u):void 0;o.push(th(h,eh(n),s,u))}Zu(n,s,0,Ka(n)),Ju(n,s,0,null),n.rows=t+1;let c=It(o);for(let u of a)u.rowspan=(u.rowspan??1)+1,Ja(o,c,u.row,u.col,u.rowspan??1,u.colspan??1)},el=(n,e)=>{let t=gr(n);if(t<=1)return!1;let r=Math.max(0,Math.min(e,t-1)),o=br(n),i=0;for(let s of o)s.row!==r&&(o[i++]=s);return o.length=i,li(o,"row",r+1,-1),Zu(n,r,1),Ju(n,r,1),n.rows=t-1,!0},no=(n,e)=>{let t=gr(n),r=ai(n),o=br(n),i=It(o),s=Qa(n),a=Math.max(0,Math.min(e,r)),l=nh(o,"col",a),c=a>0?a-1:a<r?a:null;li(o,"col",a,1);for(let d=0;d<t;d++){let f=c!==null?Se(i,d,c):void 0;o.push(th(f,eh(n),d,a))}n.cols=r+1;let u=Math.max(qa(n),c!==null?s[c]:qa(n));s.splice(a,0,u),Kr(n,s);let h=It(o);for(let d of l)d.colspan=(d.colspan??1)+1,Ja(o,h,d.row,d.col,d.rowspan??1,d.colspan??1)},tl=(n,e)=>{let t=ai(n);if(t<=1)return!1;let r=Math.max(0,Math.min(e,t-1)),o=br(n),i=Qa(n),s=0;for(let a of o)a.col!==r&&(o[s++]=a);return o.length=s,li(o,"col",r+1,-1),n.cols=t-1,i.splice(r,1),Kr(n,i),!0},jn=n=>n.columnWidths.reduce((e,t)=>e+t,0)+(n.cols-1)*n.cellSpacing,qn=n=>n.rowHeights.reduce((e,t)=>e+t,0)+(n.rows-1)*n.cellSpacing,mr=(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},pr=(n,e,t)=>{let r=e==="col"?n.columnWidths:n.rowHeights,o=e==="col"?jn(n):qn(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},Ku=(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},Qu=(n,e,t,r)=>{if(e==="col"){let i=Se(n,r,t-1);if(!i)return!1;if(i.isMerged&&i.mergeParent){let s=Se(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=Se(n,t-1,r);if(!o)return!1;if(o.isMerged&&o.mergeParent){let i=Se(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},nl=(n,e,t,r,o,i)=>{let s=t+jn(n)/2,a=r+qn(n)/2,l=o,c=i,u=mr(n.rowHeights,n.cellSpacing,a),h=mr(n.columnWidths,n.cellSpacing,s),d=Ku(n.columnWidths,n.cellSpacing,s,l,a,qn(n));if(d>0&&u>=0&&!Qu(e,"col",d,u))return{type:"col",index:d,position:pr(n,"col",d)};let f=Ku(n.rowHeights,n.cellSpacing,a,c,s,jn(n));return f>0&&h>=0&&!Qu(e,"row",f,h)?{type:"row",index:f,position:pr(n,"row",f)}:null},rh=(n,e,t,r)=>{let o=t+jn(n)/2,i=r+qn(n)/2,s=mr(n.columnWidths,n.cellSpacing,o);if(s<0)return null;let a=mr(n.rowHeights,n.cellSpacing,i);return a<0?null:lt(e,a,s)},oh=(n,e,t,r,o)=>{let i=o.indicatorOffset??15,s=o.indicatorRadius??8,a=qn(n)/2,l=jn(n)/2;for(let u=1;u<=n.cols;u++){let h=pr(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=pr(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=nl(n,e,t,r,o.thresholdX,o.thresholdY);return c?{border:c,inCircle:!1}:null},ro=(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=qn(n)/2;return{left:t-s,top:o-a,width:r,height:i}},oo=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},cn=(n,e,t)=>oo((()=>{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})()),ci=(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 oo(r)},ui=(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 oo(r)},io=(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 oo(r)},We=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}},hi=(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=oo(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=We(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}},ih=(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,Wb=["ew","nwse","ns","nesw"],sh=(n,e)=>{let t=e==="col"?0:2,r=(n%180+180)%180,o=Math.round(r/45)%4;return`${Wb[(t+o)%4]}-resize`};var si=(n,e)=>{let t=Math.abs(n)*Math.max(e,1e-6);return t>1e-6?20/t:20},ah=(n,e,t,r,o,i={x:1,y:1},s=1)=>{if(o<-t/2&&o>=-t/2-si(i.y,s)){let a=mr(n.columnWidths,n.cellSpacing,r+jn(n)/2);if(a>=0)return{kind:"col-strip",col:a}}if(r<-e/2&&r>=-e/2-si(i.x,s)){let a=mr(n.rowHeights,n.cellSpacing,o+qn(n)/2);if(a>=0)return{kind:"row-strip",row:a}}return null},lh=(n,e,t,r,o={x:1,y:1},i=1)=>{let s=si(o.x,i),a=si(o.y,i);return t>=-n/2-s&&t<-n/2&&r>=-e/2-a&&r<-e/2};var ch=(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},xr=(n,e)=>{let t=new Set,r=new Set;for(let o of e){let i=lt(n,o.row,o.col),s=Se(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 di=14,uh=(n,e,t)=>{let r=[0];for(let o=0;o<n-1;o++)r.push(r[o]+e[o]+t);return r},rl=(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},so=(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||"仓耳小丸子",g=Array.isArray(n.manualRowHeights)?n.manualRowHeights:[],b=Array.from({length:r},(_,D)=>typeof g[D]=="number"?g[D]:null),x=Array.isArray(n.cellData)?n.cellData:[],y=It(x),S=new Map;for(let _ of x){if(_.isMerged)continue;let D=Math.max(0,rl(_.col,_.colspan??1,a,u)-c*2);S.set(`${_.row},${_.col}`,{layout:$n(_.text??"",{fontFamily:_.fontFamily||p,fontSize:_.fontSize??di,fontWeight:_.fontWeight,fontStyle:_.fontStyle,lineHeight:1.16,charSpacing:0,textAlign:_.textAlign??pe.CENTER},{boxWidth:D,splitByGrapheme:!0,measure:e}),data:_})}let v=di*ti,M=[],C=[];for(let _=0;_<r;_++){let D=0;for(let U=0;U<o;U++){if(y.get(`${_},${U}`)?.isMerged)continue;let $=S.get(`${_},${U}`);D=Math.max(D,$?$.layout.height:v)}let I=b[_],H=D+c*2,z=I!==null?I:l;C.push(H),M.push(Math.max(z,H))}let R=a.reduce((_,D)=>_+D,0)+(o-1)*u,w=M.reduce((_,D)=>_+D,0)+(r-1)*u,T=uh(o,a,u),E=uh(r,M,u),P=typeof n.id=="string"&&n.id?n.id:"table",A=[];for(let _=0;_<r;_++)for(let D=0;D<o;D++){let I=y.get(`${_},${D}`);if(I?.isMerged)continue;let H=I?.colspan??1,z=I?.rowspan??1,U=rl(D,H,a,u),$=rl(_,z,M,u),K=T[D]-R/2+U/2,G=E[_]-w/2+$/2;A.push({type:"rect",id:`${P}-r${_}c${D}-rect`,left:K,top:G,width:U,height:$,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?S.get(`${_},${D}`):void 0,B=t?.hideTextCell!==void 0&&t.hideTextCell.row===_&&t.hideTextCell.col===D;if(Z&&!B&&(I?.text??"")!==""){let j=Z.layout.height,Q=I?.verticalAlign??"middle",ie=G;Q==="top"?ie=G-$/2+j/2+c:Q==="bottom"&&(ie=G+$/2-j/2-c),A.push({type:"textbox",id:`${P}-r${_}c${D}-text`,left:K,top:ie,width:Math.max(0,U-c*2),text:I?.text??"",fill:I?.textFill??m,fontFamily:I?.fontFamily||p,fontSize:I?.fontSize??di,fontWeight:I?.fontWeight,fontStyle:I?.fontStyle,textAlign:I?.textAlign??pe.CENTER,lineHeight:1.16,splitByGrapheme:!0,originX:"center",originY:"center",scaleX:1,scaleY:1,angle:0,opacity:1,visible:!0})}}let k=Math.max(l,di*ti+c*2),O=o*s+(o-1)*u+h,F=r*k+(r-1)*u+h,W=R+h,X=w+h;return{rowHeights:M,rowTextFloors:C,columnWidths:a,contentWidth:R,contentHeight:w,width:W,height:X,children:A,constructorDims:{width:O,height:F}}};var _t="WorkSpaceDrawType",Dt=new Set(["WorkSpaceDrawType","WorkSpaceClipType","WorkSpaceSafeType","WorkSpaceMaskType","WorkSpaceLineType","WorkSpaceShadowType"]),$t=n=>n.isTextType&&typeof n.raw.renderSrc=="string",ao=n=>{let e=n.fill;return typeof e!="string"||!e?1:Math.max(0,Math.min(1,ae(e)[3]))},Gb=new Set(["left","top","angle","scaleX","scaleY","skewX","skewY","flipX","flipY","originX","originY"]),Xb=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"]),sl=n=>{for(let e in n)if(!Gb.has(e))return!1;return!0},mi=999999,Ke=n=>n.isReferenceLine,ph=(n,e)=>({type:"ReferenceLine",id:`referenceline-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`,name:"ReferenceLine",axis:n,x1:n==="horizontal"?-mi:0,y1:n==="horizontal"?0:-mi,x2:n==="horizontal"?mi:0,y2:n==="horizontal"?0:mi,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"}),zb=["type","left","top","width","height","angle","scaleX","scaleY","skewX","skewY","flipX","flipY","originX","originY","strokeWidth","strokeUniform","fill","opacity","visible","src","crossOrigin","id","name"],ut=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},du(this.raw),this._typeKey=J(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=Jo(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){fu(this.raw,e),Object.assign(this.raw,e),this.invalidateGeometryCache(),sl(e)||(this._fillPaint=void 0,this._strokeDecl=void 0),"type"in e&&(this._typeKey=J(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 ft.has(this.typeKey)}get isMaskType(){return nt.has(this.typeKey)}get isSolidType(){return Wn.has(this.typeKey)}get isTextType(){return rn.has(this.typeKey)}get isLineType(){return mt.has(this.typeKey)}get isShapeType(){return Hn.has(this.typeKey)}get visible(){return this.raw.visible!==!1}get fillPaint(){if(this._fillPaint===void 0){let e=ur(this.raw.fill),t=e?null:Yo(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:ae(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=ae(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=On(this.transformProps)),this._parentMatrix?Y(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=Pa(this.transformProps)),!this._parentMatrix)return this._aCoords;let e=this._parentMatrix;return{tl:V(e,this._aCoords.tl.x,this._aCoords.tl.y),tr:V(e,this._aCoords.tr.x,this._aCoords.tr.y),br:V(e,this._aCoords.br.x,this._aCoords.br.y),bl:V(e,this._aCoords.bl.x,this._aCoords.bl.y)}}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 ee)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=ka(this.aCoords)),this._bounds}containsPoint(e,t,r=0){if(this.isSolidType&&!gi(this))return al(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))<=ll(this,r)}localPoint(e,t){return V(Te(this.matrix),e,t)}rotateAroundCenter(e,t=this.center){let r=ge({...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 xi(this.raw)}toObject(){let e={};for(let t of zb)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}},Yb=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}},Ub=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}},xe=class extends ut{_layout=null;_arcDims=null;_scrollOffset=0;constructor(e){super(e)}set(e){super.set(e),sl(e)||(this.invalidateTextLayout(),typeof this.raw.renderSrc=="string"&&Object.keys(e).some(t=>Xb.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??pe.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;this._layout=$n(e.text??"",this.textStyle,{boxWidth:J(e)===L.TEXTBOX||J(e)===L.TEXTIMAGE?e.width??0:null,styles:e.styles,splitByGrapheme:e.splitByGrapheme===!0,vertical:e.vertical===!0,paragraph:qe(e)?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(qe(this.raw)){if(!this._arcDims){let t=Mt(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(){if(typeof this.raw.renderSrc=="string"){let e=this.bitmapRect,t=Ub(e)??Yb(e);if(t||e.angle!==0||e.x!==0||e.y!==0){let r=this.ownMatrix;(e.x!==0||e.y!==0)&&(r=Y(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=Y(r,[1,0,0,1,e.fx,e.fy])),!t&&e.angle!==0&&(r=Y(r,At({angle:-e.angle})));let o=this.parentMatrix,i=(l,c)=>{let u=V(r,l,c);return o?V(o,u.x,u.y):u},s=(t?t.w:e.w)/2,a=(t?t.h:e.h)/2;return{tl:i(-s,-a),tr:i(s,-a),br:i(s,a),bl:i(-s,a)}}}return super.aCoords}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===`
6
- `,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]}},$b=(n,e)=>Math.max(24,Math.min(128,Math.ceil((n+e)*.6))),hh=(n,e)=>{if(!(n>0)||!(e>0))return null;let t=$b(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}},dh=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=Oa(c);return u.length>0?{verts:l,triangles:new Uint32Array(u)}:null},Vb=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 Oa(i))r.push(s+o);o+=i.length}return r.length>0?{verts:t,triangles:new Uint32Array(r)}:null},jb=n=>{let e=Ae(n);if(!e)return{contours:[],dims:{x:0,y:0}};let t=je(e),r=Mu(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}}},un=class extends ut{_mesh;set(e){super.set(e),sl(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=hh(e.rx??0,e.ry??0);else if(t===L.CIRCLE){let r=e.radius??0;this._mesh=hh(r,r)}else t===L.TRIANGLE?this._mesh=dh(fh(e)):this._mesh=dh(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}:qb(e.points)}containsPoint(e,t,r=0){if(!gi(this))return al(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?mh(s.verts,o.x,o.y):ol(this.raw.points,o,i===L.POLYGON,Math.max((Number(this.raw.strokeWidth)||1)/2,3,r)):s?mh(s.verts,o.x,o.y):!1}outlineStrokeHitAt(e,t,r=0){let o=this.localPoint(e,t),i=this.shapeKind,s=ll(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?ol(fh(this.raw),o,!0,s):ol(this.raw.points,o,i===L.POLYGON,s)}},fh=n=>{let e=n.width??0,t=n.height??0;return[{x:e/2,y:0},{x:e,y:t},{x:0,y:t}]},qb=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}},bi=10,il=n=>Math.min(1,Math.max(0,n)),Kb=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},gi=n=>{let e=Kb(n);return e===null||e*255>bi},al=n=>{let e=n.raw.stroke;return typeof e=="object"&&e!==null?!0:typeof e!="string"||!e||Number(n.raw.strokeWidth)===0?!1:il(ae(e)[3])*n.renderOpacity*255>bi},ll=(n,e)=>Math.max((Number(n.raw.strokeWidth)||1)/2,3,e),cl=8,bh=n=>{let e=n.typeKey;return e===L.LINE||e===L.ARROW||e===L.DIMENSION||e===L.POLYLINE?!0:(n.isShapeType||n.isSolidType)&&!gi(n)},pi=(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},ol=(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(pi(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(pi(e.x,e.y,d.x-c,d.y-u,o[0].x-c,o[0].y-u)<=h)return!0}return!1},yr=class extends un{_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=jb(this.raw.path)),this._pathGeo}get fillPolygons(){if(this._fillPolys===void 0){let e=this.raw.fillRule==="evenodd"?"evenodd":"nonzero";this._fillPolys=Ru(this.pathGeometry.contours,e)}return this._fillPolys}get shapeMesh(){return this._pathMesh===void 0&&(this._pathMesh=Vb(this.fillPolygons)),this._pathMesh}get dims(){return this.pathGeometry.dims}containsPoint(e,t,r=0){return gi(this)?ut.prototype.containsPoint.call(this,e,t):al(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=ll(this,r)**2;for(let a of i){let l=a.points;for(let c=0;c+1<l.length;c++)if(pi(o.x,o.y,l[c].x,l[c].y,l[c+1].x,l[c+1].y)<=s)return!0}return!1}},Qb=(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),g=Math.sin(m),b=e.x-d,x=e.y-f,y=b*p+x*g,S=-b*g+x*p;return y<-c||y>0?!1:Math.abs(S)<=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))},Zb=(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=zr(`${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[C,R]of[[t.x1,t.y1],[t.x2,t.y2]])if(pi(e.x,e.y,C-c*h,R-u*h,C+c*h,R+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,g=n.textFollowLine===!1?0:l,b=Math.cos(g),x=Math.sin(g),y=e.x-m,S=e.y-p,v=y*b+S*x,M=-y*x+S*b;return Math.abs(v)<=a/2&&Math.abs(M)<=(o+i*2)/2},vr=class extends ut{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?Qb(this.raw,i,o):f===L.DIMENSION?Zb(this.raw,i,o,d):!1}},re=class extends ut{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}}},mh=(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},ee=class n extends ut{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}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 se)?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 ee{_layout;_childFactory;_placedShift;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=so(e),o=Yt({...e,width:r.constructorDims.width,height:r.constructorDims.height}),i=ge({...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 rh(this.tableView,this.cellMap,r.x,r.y)}borderHit(e,t){let r=this.localPoint(e,t),o=this.objectScale;return nl(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 oh(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 ah(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 lh(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??We(this.selectedCells);return e?Za(this.cellMap,e.r1,e.r2,e.c1,e.c2):null}get selectionBoundsRect(){let e=this.expandedCellRange;return e?ro(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 ch(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=ui(this.cellMap,this.tableView.cols,e);this.setCellSelection(t,t[0]??null,We(t))}setColumnSelection(e){let t=ci(this.cellMap,this.tableView.rows,e);this.setCellSelection(t,t[0]??null,We(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=Se(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 ro(o,{r1:e,r2:e+s-1,c1:t,c2:t+i-1})}cellSceneCenter(e,t){let r=this.cellBounds(e,t);return r?V(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=(g,b)=>({x:e==="left"?-g/2:e==="right"?g/2:0,y:t==="top"?-b/2:t==="bottom"?b/2:0}),o=this.dims.x,i=this.dims.y,s=On({...this.raw,width:o,height:i}),a=V(s,r(o,i).x,r(o,i).y),l=so(this.raw,void 0,this.editingCell?{hideTextCell:this.editingCell}:void 0);this._layout=l;let c=[];for(let g of l.children){let b=this._childFactory(g);b&&c.push(b)}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=ge({...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=ge({...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)}}},le=class extends ut{_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=J(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(()=>{})}},se=class extends ee{constructor(e,t){super(e,t);let r=this.layoutParams,o=Vn(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()}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 g=d.x0<=f.x0?s[u]:s[h],b=g===s[u]?s[h]:s[u],x=l(g),y=l(b);if(x.x1>y.x0+i){if(Math.abs(x.x1-r)<i&&y.x0<r-i){let R=a.get(g)??{};R.right=y.x0-e,a.set(g,R)}else if(Math.abs(y.x0+r)<i&&x.x1>-r+i){let R=a.get(b)??{};R.left=x.x1+e,a.set(b,R)}}let S=d.y0<=f.y0?s[u]:s[h],v=S===s[u]?s[h]:s[u],M=l(S),C=l(v);if(M.y1>C.y0+i){if(Math.abs(M.y1-o)<i&&C.y0<o-i){let R=a.get(S)??{};R.bottom=C.y0-t,a.set(S,R)}else if(Math.abs(C.y0+o)<i&&M.y1>-o+i){let R=a.get(v)??{};R.top=M.y1+t,a.set(v,R)}}}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,g=h.bottom??d.y1;if(!(m-f>i)||!(g-p>i))continue;let b={left:(f+m)/2,width:m-f,top:(p+g)/2,height:g-p};u.set(b),c.push(`${String(u.raw.id)}→${Math.round(b.left)},${Math.round(b.top)},${Math.round(b.width)}×${Math.round(b.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 le)}containsPoint(e,t,r=0){return super.containsPoint(e,t,r)?!0:this.visible?ut.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=Vn(this.raw.layoutConfig);r&&this.relayoutFromConfig(r,this.layoutParams)}updateLayout(e){let t=Vn(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=Vn(this.raw.layoutConfig);if(!t||t.pieces.length!==this.maskChildren.length)return!1;let r=Vu(t.pieces,t.cols,e);return r?(t.cols-=1,this.applyPuzzleRemoval(t,r.removed)):!1}removeRow(e){let t=Vn(this.raw.layoutConfig);if(!t||t.pieces.length!==this.maskChildren.length)return!1;let r=ju(t.pieces,t.rows,e);return r?(t.rows-=1,this.applyPuzzleRemoval(t,r.removed)):!1}removePiece(e){let t=Vn(this.raw.layoutConfig);if(!t||t.pieces.length!==this.maskChildren.length)return!1;let r=qu(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 le&&r.has(this.maskChildren.indexOf(s)))),i=o.filter(s=>s instanceof le).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=ja(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,g=f*(p||1);o.set({clipImage:{...c,scaleX:g,scaleY:g}})}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})}},xi=n=>{if(!ft.has(J(n)))return null;let e=Number(n.cropX)||0,t=Number(n.cropY)||0;if(!(e>0||t>0)||typeof n.width!="number"||typeof n.height!="number")return null;let r=n.cropSizeMode==="visible";return{sx:e,sy:t,sw:Math.max(0,r?n.width:n.width-e),sh:Math.max(0,r?n.height:n.height-t)}},ct=n=>{if(!n||typeof n.type!="string")return null;let e=J(n);return e===L.TABLE?new te(n,ct):$o.has(e)?new se(n,ct):nt.has(e)&&typeof n.src=="string"?new le(n):e===L.GROUP?new ee(n,ct):Vo.has(e)&&typeof n.src=="string"?new re(n,"gif"):jo.has(e)&&typeof n.src=="string"?new re(n,"video"):ft.has(e)&&typeof n.src=="string"?new ut(n):Wn.has(e)?new ut(n):rn.has(e)&&typeof n.text=="string"?new xe(n):e===L.PATH?new yr(n):mt.has(e)?new vr(n):Hn.has(e)?new un(n):null},ul=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}},Qe=(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}),yi=n=>{if(n instanceof ee||n instanceof le||n instanceof re||n.isImageType)return null;let e=n.raw.mask;return!e||e.disabled===!0||typeof e.src!="string"||!e.src?null:e.src};var vi=n=>typeof n!="string"||n.length===0?!1:/^data:image\/svg\+xml/i.test(n)?!0:/\.svg(?:[?#]|$)/i.test(n),gh=(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}},xh=(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 Si=(n,e)=>{if(n.children.includes(e))return[n];for(let t of n.children)if(t instanceof ee&&!(t instanceof te)&&!(t instanceof se)){let r=Si(t,e);if(r.length)return[...r,n]}return[]},yh=n=>{let e=n.matrix,t=n.ownMatrix,r=Te(e),o=(i,s,a)=>V(i,s,a,!0);return(i,s)=>{let a=o(r,i,s);return o(t,a.x,a.y)}},vh=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=typeof i.raw.strokeWidth=="number"?i.raw.strokeWidth:0,a=i.dims.x/2,l=i.dims.y/2,c=i.raw.strokeUniform===!0?a:a+s/2,u=i.raw.strokeUniform===!0?l:l+s/2,h=i.raw.strokeUniform===!0?s/2:0,d=i.ownMatrix;for(let f of[-c,c])for(let m of[-u,u]){let p=V(d,f,m);p.x-h<e&&(e=p.x-h),p.y-h<t&&(t=p.y-h),p.x+h>r&&(r=p.x+h),p.y+h>o&&(o=p.y+h)}}return Number.isFinite(e)?{minX:e,minY:t,maxX:r,maxY:o}:null},Sh=n=>{let e=vh(n);if(!e)return null;let t=n.matrix;return{tl:V(t,e.minX,e.minY),tr:V(t,e.maxX,e.minY),br:V(t,e.maxX,e.maxY),bl:V(t,e.minX,e.maxY)}},hl=n=>{let e=[];for(let t=0;t<n.length;t++){let r=n[t],o=vh(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=V(r.matrix,a.x,a.y),u=n[t+1]??null,h=u?V(Te(u.matrix),c.x,c.y):c,d=ge({...r.raw,width:i,height:s},h);r.set({width:i,height:s,left:d.x,top:d.y});let f=Te(r.matrix);for(let m of r.children){let p=l.get(m);if(!p)continue;let g=V(f,p.x,p.y),b=ge({...m.raw,width:m.dims.x,height:m.dims.y},g);m.set({left:b.x,top:b.y})}e.push(r,...r.children)}return e};var dl=["tl","tr","bl","br"],hn=new Set(dl),wi=["tlS","trS","blS","brS"],Jb=new Set(wi),lo={tlS:"tl",trS:"tr",blS:"bl",brS:"br"},eg=new Set(["ml","mr","mt","mb"]),Kn={ml:"x",mr:"x",mt:"y",mb:"y"},Ti={ml:"left",mr:"right",mt:"top",mb:"bottom"},Qn=n=>eg.has(n),Ei=n=>hn.has(n),Sr=n=>Jb.has(n);var bn=8,Zn=12,Ct=1.5,wh=24,tg=["lockMovementX","lockMovementY","lockScalingX","lockScalingY","lockSkewingX","lockSkewingY","lockRotation"],it=n=>{let e=n.raw;return tg.some(t=>!!e[t])},ki=28,fl=null,ng=()=>{if(fl)return fl;let n=document.createElement("canvas");n.width=ki*2,n.height=ki*2;let e=n.getContext("2d");if(e){e.scale(2,2);let t=ki/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 fl=n,n},Ai=28,rg="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",ml=null,og=()=>{if(ml)return ml;let n=document.createElement("canvas");n.width=Ai*2,n.height=Ai*2;let e=n.getContext("2d");if(e){e.scale(2,2);let t=Ai/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(rg)))}return ml=n,n};var ig=24,Ni=20,Eh=16,sg="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",pl=null,ag=()=>{if(pl)return pl;let n=document.createElement("canvas");n.width=Ni*2,n.height=Ni*2;let e=n.getContext("2d");if(e){e.scale(2,2);let t=Ni/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(sg)))}return pl=n,n},yl=n=>{if(n.selection.length!==1)return null;let e=n.selection[0];if(e instanceof te||e instanceof se)return null;let t=e.typeKey;return mt.has(t)||nt.has(t)||it(e)?null:e},vl=(n,e,t)=>Fi(n,e,t,{x:.5,y:0,offsetX:ig,offsetY:0}),fn=3,bl=new Map,lg=n=>{let e=bl.get(n);if(e)return e;let t=document.createElement("canvas"),r=t.getContext("2d"),o=`bold ${14*fn}px Helvetica, Arial, sans-serif`;if(!r)return t.width=Math.max(1,Math.round((n.length*14*.6+16)*fn)),t.height=Math.round(30*fn),bl.set(n,t),t;r.font=o;let i=r.measureText(n).width,s=8*fn;t.width=Math.max(1,Math.ceil(i)+s*2),t.height=Math.ceil(30*fn),r.font=o;let a=6*fn;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),bl.set(n,t),t},cg=(n,e,t)=>{let r=lg(`${Math.round(e)}°`);return{matrix:[1,0,0,1,n.x,n.y],dims:{x:r.width/fn/t,y:r.height/fn/t},color:[1,1,1,1],texture:r}},ot=ae("#2f6fed"),co=ae("#ffffff"),Mi=ae("#2f6fed"),Sl=ot,Ci=(n,e)=>({x:(n.x+e.x)/2,y:(n.y+e.y)/2}),Ce=(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}},mn=(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}},ug=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)}},Ze=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:ug(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}},Tr=(n,e,t=1,r)=>{let o=Ci(n.tl,n.tr),i=Ci(n.tr,n.br),s=Ci(n.bl,n.br),a=Ci(n.tl,n.bl),l=Mg(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?pg(r,t):[];return u.length?[...u,...c]:c},hg=32,dg=.25,Ii=14,Mh=n=>n<=0?0:Math.min(hg,n*dg),Ch=(n,e)=>{if(e<=0)return 0;let t=Math.max(0,Math.min(e,n)),r=Mh(e);return r<=0||e<=r?t:r+t/e*(e-r)},wl=(n,e)=>{if(e<=0)return 0;let t=Math.max(0,Math.min(e,n)),r=Mh(e);return r<=0||e<=r?t:t<=r?0:(t-r)/(e-r)*e},_i=n=>!!n&&n.typeKey===L.FABRICRECT,fg=new Set([L.QRCODE,L.BARCODE,L.ECHART,L.FABRIC_ECHART]),uo=n=>{if(!n)return!1;let e=J(n.raw);return!fg.has(e)&&(e===L.IMAGE||e===L.SVGIMAGE||e===L.CROPIMAGE)},Rh=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>wr&&o>wr},pg=(n,e)=>mg(n,e)?_i(n)?bg(n,e):uo(n)?gg(n,e):[]:[],bg=(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=Ch(u,c),d=Math.max(0,(Ii-h*e)/e),f=Math.max(0,(Ii-h*e)/e),m=h+Math.min(d,Math.max(0,a-h)),p=h+Math.min(f,Math.max(0,l-h)),g=n.matrix;return wi.map(b=>{let x=lo[b],y=x==="tl"||x==="bl",S=x==="tl"||x==="tr",v=(y?-a+m:a-m)/r,M=(S?-l+p:l-p)/o;return{id:b,x:g[0]*v+g[2]*M+g[4],y:g[1]*v+g[3]*M+g[5]}})},gg=(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=Ch(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,(Ii-a*u)/u),Math.max(0,r-a)),f=Math.min(Math.max(0,(Ii-a*h)/h),Math.max(0,o-a)),m=n.matrix;return wi.map(p=>{let g=lo[p],b=g==="tl"||g==="bl",x=g==="tl"||g==="tr",y=b?-r+a+d:r-a-d,S=x?-o+a+f:o-a-f;return{id:p,x:m[0]*y+m[2]*S+m[4],y:m[1]*y+m[3]*S+m[5]}})},Li=12,Ri=null,xg=()=>{if(Ri)return Ri;let n=document.createElement("canvas");n.width=Li*2,n.height=Li*2;let e=n.getContext("2d");if(e){e.scale(2,2);let t=Li/2,r=bn/2;e.beginPath(),e.arc(t,t,r+Ct,0,Math.PI*2),e.fillStyle=`rgb(${ot[0]*255},${ot[1]*255},${ot[2]*255})`,e.fill(),e.beginPath(),e.arc(t,t,r,0,Math.PI*2),e.fillStyle=`rgb(${co[0]*255},${co[1]*255},${co[2]*255})`,e.fill()}return Ri=n,Ri},Ph=16,dn=4,Th={tlr:{x:-.5,y:-.5,offsetX:-dn,offsetY:-dn},trr:{x:.5,y:-.5,offsetX:dn,offsetY:-dn},brr:{x:.5,y:.5,offsetX:dn,offsetY:dn},blr:{x:-.5,y:.5,offsetX:-dn,offsetY:dn}},Tl={tlr:0,trr:90,brr:180,blr:270},wr=50,El=(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}),yg=(n,e)=>{let{width:t,height:r}=El(n,e);return t>wr&&r>wr},vg=new Set(["mr","br","mtr"]),Sg=new Set(["mr","br"]),wg=new Set(["mr","br","mtr"]),Tg=new Set(["ml","mr","tl","tr","bl","br","tlS","trS","blS","brS"]),Eg=new Set(["mt","mb","tl","tr","bl","br","mtr","tlS","trS","blS","brS"]),kh=(n,e,t)=>{let r=e<=wr,o=t<=wr;return!r&&!o?!0:r&&o?vg.has(n):!(r&&Tg.has(n)&&!Sg.has(n)||o&&Eg.has(n)&&!wg.has(n))},Ah=n=>n instanceof se||n instanceof te||nt.has(n.typeKey),ho=(n,e,t,r,o)=>{let i=Tr(e,t,r,o),s=n.selection.length===1?n.selection[0]:null;if(!s||Ah(s))return i;let a=mt.has(s.typeKey),l=El(e,r);return i.filter(c=>a&&(c.id==="ml"||c.id==="mr")||kh(c.id,l.width,l.height))},Ml=(n,e)=>{let t=n.aCoords,r=n.worldAngle,o=Tr(t,r,e);if(Ah(n))return o;let i=mt.has(n.typeKey),s=El(t,e);return o.filter(a=>i&&(a.id==="ml"||a.id==="mr")||kh(a.id,s.width,s.height))},Nh=(n,e,t)=>yg(n,t)?Object.keys(Th).map(r=>{let o=Fi(n,e,t,Th[r]);return{id:r,x:o.x,y:o.y}}):[],Di=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*wh,offsetY:0}}let o=Math.sign(r);return{x:0,y:o/2,offsetX:0,offsetY:o*wh}},Fi=(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}},Mg=(n,e,t)=>Fi(n,e,t,Di(e)),pn=(n,e)=>{let t=Ct/e;return[Ce(n.tl,n.tr,t,ot),Ce(n.tr,n.br,t,ot),Ce(n.br,n.bl,t,ot),Ce(n.bl,n.tl,t,ot)]},Cg=3,Pi=(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=Cg/o,h=[];for(let d=0;d<a;d+=u*2){let f=Math.min(d+u,a);h.push(Ce({x:n.x+l*d,y:n.y+c*d},{x:n.x+l*f,y:n.y+c*f},t,r))}return h},Oi=(n,e)=>{let t=Ct/e;return[...Pi(n.tl,n.tr,t,ot,e),...Pi(n.tr,n.br,t,ot,e),...Pi(n.br,n.bl,t,ot,e),...Pi(n.bl,n.tl,t,ot,e)]},Rg=(n,e,t,r)=>{let o=Ct/r,i=bn/r;for(let s of e)s.id==="mtr"?n.push({...mn(s,Ai/r,[1,1,1,1],t),texture:og()}):Sr(s.id)?n.push({...mn(s,Li/r,[1,1,1,1],t),texture:xg()}):(n.push(mn(s,i,ot,t)),n.push(mn(s,i-2*o,co,t)))},gl=(n,e,t,r,o,i)=>{if(i?.spec){let s=e.find(l=>l.id==="mtr"),a=Fi(t,r,o,i.spec);s.x=a.x,s.y=a.y}Rg(n,e,r,o),i&&n.push(cg(i.center,r,o))},Lh=(n,e,t=null,r=!1)=>{if(n.selection.length===1&&Ke(n.selection[0]))return[];let o=Ze(n);if(!o)return[];let{quad:i,angle:s}=o,a=[],l=n.activeGroupChild,c=l&&n.groupEditing&&n.selection[0]instanceof ee&&!(n.selection[0]instanceof te)&&!(n.selection[0]instanceof se)?n.selection[0]:null,h=(c?Sh(c):null)??i;if(l)a.push(...pn(l.aCoords,e)),a.push(...Oi(h,e));else{if(n.selection.length>=2)for(let d of n.selection)a.push(...pn(d.aCoords,e));a.push(...pn(i,e))}if(n.selection.length===1&&it(n.selection[0]))return a.push({...mn(i.br,ki/e,[1,1,1,1],s),texture:ng()}),a;if(gl(a,ho(n,h,s,e,fo(n)),h,s,e,t?.onChild?null:t),l&&n.groupEditing&&gl(a,Ml(l,e),l.aCoords,l.worldAngle,e,t?.onChild?t:null),r&&yl(n)){let d=vl(h,s,e);a.push({...mn(d,Ni/e,[1,1,1,1],0),texture:ag()})}return a},fo=n=>{if(n.selection.length!==1)return null;let e=n.selection[0];return _i(e)||uo(e)?e:null},Ih=(n,e)=>{let t=Ct/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[Ce(r,o,t,Mi),Ce(o,i,t,Mi),Ce(i,s,t,Mi),Ce(s,r,t,Mi)]},mo=n=>{let e=n.editingMask;if(!e)return[];let t=e.aCoords;return Tr(t,e.worldAngle).filter(o=>Qn(o.id)?!n.maskEdgeOnOuterBorder(e,Ti[o.id]):!1)},_h=(n,e,t=null)=>{let r=n.editingMask;if(!r)return[];let o=r.worldAngle,i=pn(r.aCoords,e),s=Ct/e,a=bn/e;for(let c of mo(n))i.push(mn(c,a,ot,o)),i.push(mn(c,a-2*s,co,o));let l=n.raw.angle??0;return i.push(...Oi(n.aCoords,e)),gl(i,Tr(n.aCoords,l),n.aCoords,l,e,t),i},Pg=2.5,xl=(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;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}},Cl=n=>{let e=[];for(let i of n.maskChildren)i.visible&&(n.maskEdgeOnOuterBorder(i,"right")||e.push(xl(n,i,"mr")),n.maskEdgeOnOuterBorder(i,"bottom")||e.push(xl(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,g=Math.min(m,p),b=Math.max(m,p);return g<=u+r&&b>=-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},Dh=(n,e,t)=>Cl(n).find(o=>o.mask===e&&o.handle===t)??xl(n,e,t),Fh=(n,e)=>[Ce(n.p1,n.p2,Pg/e,Sl)],kg=ae("#3c7eff"),Ag=2,Ng=(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}},Bi=(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)=>Ng(c,r[(u+1)%4],o)),s=n.bounds,a=Math.min(Ag,(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(Ce({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,kg))}return l};function Oh(n,e,t,r){let o=n.selection.map(l=>l.id),i=Ze(n);if(!i||n.editingNode||e)return{ids:o,handles:[]};let s=n.selection.length===1&&n.selection[0]instanceof se?n.selection[0]:null,a=s?.editingMask?[...mo(s).map(l=>{let c=r(l.x,l.y);return{id:l.id,x:c.x,y:c.y}}),...Tr(i.quad,i.angle,t).map(l=>{let c=r(l.x,l.y);return{id:l.id,x:c.x,y:c.y}})]:ho(n,i.quad,i.angle,t,fo(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 Bh(n){let e=n.activeGroupChild;if(!e)return null;let t=n.selection[0];return!(t instanceof ee)||!t.containsDeep(e)?null:{rootId:t.id,childId:e.id}}function Hh(n,e){let t=[],r=o=>{for(let i of o){if(i instanceof ee&&r(i.children),!i.imageEl||!vi(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 Wh(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 Gh(n,e){e();let t=performance.now();for(let o=0;o<n;o++)e();let r=(performance.now()-t)/n;return Bo("engine.render.avgMeasured",r),r}function Xh(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 Lg=2,Le={drag:"drag",scale:"scale",rotate:"rotate",cornerRadius:"cornerRadius",crop:"crop",tableCellEdit:"table-cell-edit",warpImage:"warpvas-image"},Ig=(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((b,x)=>b.syntheticOwner?-1:x).filter(b=>b>=0);if(!d.length)return;let f=d.map(b=>r(u[b])),m=h?.before,p=m?.length?d.map(b=>m[b]).filter(b=>!!b):void 0,g=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:g,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 zh(n,e){let t=n.nodes.filter(r=>r.visible&&!Dt.has(String(r.raw.id??""))&&!Ke(r));return n.setSelection(t),e(),t.length}function Yh(n,e){let t=[...n.selection];for(let r of t)n.remove(r);return t.length&&e(),t.length}function Uh(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 Gi=20,Vh={ruleSize:Gi,backgroundColor:ae("#ffffff"),tickColor:ae("#A1A7AF"),textColor:"#444444",highlightColor:ae("#165dff3b"),fontSize:8,unitName:"px"},_g=.6,Ge=3,jh="'Arial Narrow', 'Segoe UI', sans-serif",$h=[.02,.03,.05,.1,.2,.5,1,2,5],Dg=[5e3,2500,1e3,500,200,100,50,20,10],Fg=n=>{let e=0;for(;e<$h.length&&$h[e]<n;)e++;return Dg[e-1]??1e4},Og=(n,e,t,r)=>{let o=Fg(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}},Bg=(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},Rl=new Map,Hg=(n,e=Vh)=>{let t=Rl.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*Ge)),r.height=Math.max(1,Math.round(e.fontSize*1.4*Ge)),Rl.set(n,r),r;let i=`${e.fontSize*Ge}px ${jh}`;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*Ge*1.25),o.font=i,o.textBaseline="top",o.fillStyle=e.textColor,o.fillText(n,1,Math.round(e.fontSize*Ge*.15)),Rl.set(n,r),r},Pl=new Map,Hi=10,Wi=4,Wg=n=>{let e=Pl.get(n);if(e)return e;let t=Hi*Ge,r=Wi*Ge,o=document.createElement("canvas"),i=o.getContext("2d");if(!i)return o.width=Math.max(1,Math.round((n.length*Hi*.6+Wi*2)*Ge)),o.height=Math.max(1,Math.round((Hi+Wi*2)*Ge)),Pl.set(n,o),o;let s=`${t}px ${jh}`;i.font=s;let a=i.measureText(n).width,l=3*Ge;return o.width=Math.max(1,Math.ceil(a)+r*2),o.height=Math.ceil((Hi+Wi*2)*Ge),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*Ge,i.stroke(),i.fillStyle="#fff",i.textBaseline="top",i.fillText(n,r,r),Pl.set(n,o),o},qh=n=>{let e={...Vh,...n.style},{vpt:t,cssWidth:r,cssHeight:o}=n,i=t[0],s=n.digitCanvas??(g=>Hg(g,e)),a=[],l=g=>(g-t[4])/i,c=g=>(g-t[5])/i,u=1/i,h=(g,b,x,y,S)=>({matrix:[u,0,0,u,l(g+x/2),c(b+y/2)],dims:{x,y},color:S}),d=(g,b,x,y=!1)=>{let S=s(g),v=S.width/Ge,M=S.height/Ge;return{matrix:y?[0,u,-u,0,l(b+M/2),c(x-v/2)]:[u,0,0,u,l(b+v/2),c(x+M/2)],dims:{x:v,y:M},color:[1,1,1,1],texture:S}},f=e.ruleSize,m=g=>{let b=g?r:o;a.push(g?h(0,0,r,f,e.backgroundColor):h(0,0,f,o,e.backgroundColor));let x=n.workspaceRect,y=x?g?[x.left,x.left+x.width]:[x.top,x.top+x.height]:null,S=g?-t[4]/i:-t[5]/i,v=Og(S,b/i,y,i),M=[e.tickColor[0],e.tickColor[1],e.tickColor[2],e.tickColor[3]*_g],C=R=>(R-S)*i;for(let R of v.majors){let w=Math.round(C(R));a.push(g?h(w,0,1,f,M):h(0,w,f,1,M))}for(let R of v.minors){let w=Math.round(C(R));a.push(g?h(w,f-8,1,8,M):h(f-8,w,8,1,M))}for(let R of v.majors){let w=C(R),T=String(Math.round(R));g?a.push(d(T,w+6,2.5)):a.push(d(T,2.5,w-6,!0))}for(let R of Bg(n.selectionRects,g)){let w=(R.start-S)*i,T=R.length*i;a.push(g?h(w,0,T,f,e.highlightColor):h(0,w,f,T,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/Ge/2,f/2-p.height/Ge/2)),n.referenceLine){let g=Wg(String(Math.round(n.referenceLine.position))),b=g.width/Ge,x=g.height/Ge,y,S;if(n.referenceLine.axis==="horizontal"){let v=n.referenceLine.position*i+t[5];y=f+5,S=v+x/2,S<0&&(S=2),S+x>o&&(S=o-x-2)}else y=n.referenceLine.position*i+t[4]+b/2,S=f+5,y<0&&(y=2),y+b>r&&(y=r-b-2);a.push({matrix:[u,0,0,u,l(y+b/2),c(S+x/2)],dims:{x:b,y:x},color:[1,1,1,1],texture:g})}return a};var Xi=n=>n*180/Math.PI,ve=n=>n*Math.PI/180,zi=n=>({x:(n.tl.x+n.br.x)/2,y:(n.tl.y+n.br.y)/2}),Yi=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)}),kl={mr:0,br:45,mb:90,bl:135,ml:180,tl:225,mt:270,tr:315},Al=["ew-resize","nwse-resize","ns-resize","nesw-resize"],Ui=5,Kh=4,Vt=(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"}}},Nl=(n,e,t)=>V([Math.cos(ve(n)),-Math.sin(ve(n)),Math.sin(ve(n)),Math.cos(ve(n)),0,0],e.x-t.x,e.y-t.y,!0),Ll=(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 Gg=n=>n instanceof xe&&(n.typeKey===L.TEXTBOX||n.typeKey===L.TEXTIMAGE&&!$t(n));function Il(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:Gg(h)})),l=V(s,i.x,i.y),c=n.parentMatrix,u=c?V(Te(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 Qh(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=ge({...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,g=ge({...d.node.raw,width:p.x,height:p.y},{x:f,y:d.centerY});n.setProps(d.node,{left:g.x,top:g.y},{deferIndexRebuild:!0})}else{let m=d.scaleX*r;n.setProps(d.node,{scaleX:m},{deferIndexRebuild:!0});let p=d.node.dims,g=ge({...d.node.raw,width:p.x,height:p.y,scaleX:m},{x:f,y:d.centerY});n.setProps(d.node,{left:g.x,top:g.y},{deferIndexRebuild:!0})}}}function Zh(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);Qh(n,e,i)}function Xg(n,e,t){if(!(t>0))return;let r=Il(e,1);Qh(n,r,t)}function Er(n){return n instanceof ee&&!(n instanceof te)&&!(n instanceof se)}function Dl(n,e,t){let r=n.raw,o=n.dims.x,i=n.dims.y,{u:s,a,axis:l}=Vt(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=V(h,a.x,a.y),f=n.parentMatrix,m=f?V(Te(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 xe||void 0};return Er(n)&&(e==="ml"||e==="mr")&&(p.bakeGroup=Il(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&&hn.has(e)&&n instanceof xe&&(p.bakeFont={fontSize0:n.textStyle.fontSize,styles0:r.styles??null}),p}function nd(n,e,t,r=!1){let o=Nl(e.angle,t,e.anchorScene);if(e.bakeFont){Yg(n,e,o);return}if(e.bakeWidth){Ug(n,e,o);return}if(e.bakeHeight){$g(n,e,o);return}if(e.bakeGroup){Zh(n,e.bakeGroup,o);return}if(e.bakeMaskWidth){Jh(n,e,o,"width");return}if(e.bakeMaskHeight){Jh(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}=Ll(e,o));let a=Math.cos(ve(e.angle)),l=Math.sin(ve(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=ge({...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 rd(n,e,t){let{quad:r,angle:o}=t,i=zi(r),{width:s,height:a}=Yi(r),{u:l,a:c,axis:u}=Vt(e,s,a),h=Math.cos(ve(o)),d=Math.sin(ve(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 od(n,e,t,r=!1){let o=Nl(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}=Ll({...e,scaleX:1,scaleY:1},o));let a=Math.cos(ve(e.angle)),l=Math.sin(ve(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(b=>b.node===h),f=zg(e,c,i,s,d,a,l),m=d.scaleX*i,p=d.scaleY*s,g=ge({...h.raw,width:d.dims.x,height:d.dims.y,scaleX:m,scaleY:p},f);return{scaleX:m,scaleY:p,left:g.x,top:g.y}},"scaling"),n.setSelectionFrame({center:c,width:e.width*i,height:e.height*s,angle:e.angle})}function zg(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 id(n,e,t){let r=Math.atan2(t.y-e.center.y,t.x-e.center.x),o=Xi(r-e.startAngle),i=Math.cos(ve(o)),s=Math.sin(ve(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 _l=n=>{if(n===null||typeof n!="object")return typeof n=="function"?void 0:n;if(Array.isArray(n))return n.map(_l);let e={};for(let t of Object.keys(n)){let r=_l(n[t]);r!==void 0&&(e[t]=r)}return e};function Yg(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};e.node.typeKey===L.TEXTBOX&&(c.width=Math.max(e.width*a,1)),c.height=Math.max(e.height*a,1);let u=r.styles0;if(u){let b=_l(u);for(let x of Object.values(b))if(x)for(let[y,S]of Object.entries(x)){let v=S;v&&typeof v.fontSize=="number"&&(x[y]={...v,fontSize:v.fontSize*a})}c.styles=b}let h=Math.cos(ve(e.angle)),d=Math.sin(ve(e.angle)),f=h*(e.scaleX*e.anchorLocal.x*a)-d*(e.scaleY*e.anchorLocal.y*a),m=d*(e.scaleX*e.anchorLocal.x*a)+h*(e.scaleY*e.anchorLocal.y*a),p={x:e.anchorWrite.x-f,y:e.anchorWrite.y-m},g=ge({...e.node.raw,width:e.width*a,height:e.height*a,scaleX:e.scaleX,scaleY:e.scaleY},p);c.left=g.x,c.top=g.y,n.setProps(e.node,c,{deferIndexRebuild:!0})}function Ug(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(ve(e.angle)),d=Math.sin(ve(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},g=ge({...e.node.raw,width:l,height:c,scaleX:e.scaleX,scaleY:e.scaleY},p);n.setProps(e.node,{left:g.x,top:g.y},{deferIndexRebuild:!0})}function $g(n,e,t){let r=e.node;if(!(r instanceof xe))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(ve(e.angle)),u=Math.sin(ve(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=ge({...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 Jh(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=td(i,h,d,u,d);n.setProps(e.node,{width:u,...f??{}},{deferIndexRebuild:!0});let m={x:-l*u/2,y:0},p=ed(e,m),g=ge({...s,width:u,height:d,scaleX:e.scaleX,scaleY:e.scaleY},p);n.setProps(e.node,{left:g.x,top:g.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=td(i,h,d,h,u);n.setProps(e.node,{height:u,...f??{}},{deferIndexRebuild:!0});let m={x:0,y:-l*u/2},p=ed(e,m),g=ge({...s,width:h,height:u,scaleX:e.scaleX,scaleY:e.scaleY},p);n.setProps(e.node,{left:g.x,top:g.y},{deferIndexRebuild:!0})}}function ed(n,e){let t=Math.cos(ve(n.angle)),r=Math.sin(ve(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 td(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 sd=(n,e)=>e.length>=2&&(e.includes(n-1)||e.includes(n));function ld(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 cd(n,e){let t=n.node.raw,r=V(Te(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(sd(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);Kr(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(sd(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=pr(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=ih(n.startBorderPos,i,s,a);n.node.hoveredBorder={type:n.border.type,index:n.border.index,position:i+l}}function ud(n,e){let t=Vt(e,n.dims.x,n.dims.y).a;return{type:"table-edge-resize",node:n,handle:e,anchorScene:V(n.matrix,t.x,t.y)}}function hd(n,e){let t=Vt(e,n.dims.x,n.dims.y).a;return{type:"puzzle-edge-resize",node:n,handle:e,anchorScene:V(n.matrix,t.x,t.y)}}function $i(n,e,t,r){for(let o of mo(e)){let i=n(o.x,o.y);if(Qn(o.id)&&Math.hypot(i.x-t,i.y-r)<=Zn)return o.id}return null}function jg(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 po(n,e,t,r){for(let o of Cl(e)){let i=n(o.p1.x,o.p1.y),s=n(o.p2.x,o.p2.y);if(jg(t,r,i,s)<=Zn)return{mask:o.mask,handle:o.handle}}return null}function Fl(n,e,t){let r=n.maskChildren.indexOf(e);if(r<0)return null;let o=$u(n.raw,n.maskChildren.map(s=>s.raw),n.maskChildren.map(s=>s.clipImageEl)),i=Vt(t,e.dims.x,e.dims.y).a;return{type:"puzzle-mask-edge-resize",node:n,maskIdx:r,handle:t,anchorScene:V(e.matrix,i.x,i.y),state:o.state,pieces:o.pieces,clipSizes:o.clipSizes}}function qg(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 dd(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(ve(-o)),u=Math.sin(ve(-o)),h=s;s=c*h-u*a,a=u*h+c*a}let l=Ti[n.handle];if(l==="left"||l==="right"){let c=(r.strokeWidth??0)/(r.strokeUniform===!0?i.x:1);Yu(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);Uu(n.state,n.maskIdx,Math.abs(a)/i.y-c,l,n.clipSizes)}qg(n.node,n.state)}function ad(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:ii(s.raw)}))},i=r.map(s=>s.clipImageEl?{w:s.clipImageEl.naturalWidth,h:s.clipImageEl.naturalHeight}:null);zu(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 fd(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(ve(-i)),p=Math.sin(ve(-i)),g=s;s=m*g-p*a,a=p*g+m*a}let l=e.node.layoutParams;if(Kn[e.handle]==="x"){let m=(r.strokeWidth??0)/(r.strokeUniform===!0?o.x:1),p=Math.max(Math.abs(s)/o.x-m,1);ad(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);ad(e.node,{heightRatio:p/(l.height||1)})}let c=Vt(e.handle,e.node.dims.x,e.node.dims.y).a,u=Math.cos(ve(i)),h=Math.sin(ve(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=ge({...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 md(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(ve(-s)),g=Math.sin(ve(-s)),b=a;a=p*b-g*l,l=g*b+p*l}let c=r.cellStrokeWidth??1;if(Kn[e.handle]==="x"){let p=Math.abs(a)/i.x-o.cellSpacing*(o.cols-1)-c,g=e.handle==="ml"?0:o.cols-1,b=o.columnWidths.reduce((x,y,S)=>S===g?x:x+y,0);Qr(r,g,p-b)}else{let p=Math.abs(l)/i.y-o.cellSpacing*(o.rows-1)-c,g=e.handle==="mt"?0:o.rows-1,b=o.rowHeights.reduce((x,y,S)=>S===g?x:x+y,0);Zr(r,g,p-b)}e.node.rebuildTable();let u=Vt(e.handle,e.node.dims.x,e.node.dims.y).a,h=Math.cos(ve(s)),d=Math.sin(ve(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=ge({...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 pd(n,e,t){let r=Math.max(0,t.index);if(t.type==="col"){no(e.raw,r),e.rebuildTable();let o=e.tableView,i=ci(e.cellMap,o.rows,Math.min(r,o.cols-1));e.setCellSelection(i,i[0]??null,We(i))}else{to(e.raw,r),e.rebuildTable();let o=e.tableView,i=ui(e.cellMap,o.cols,Math.min(r,o.rows-1));e.setCellSelection(i,i[0]??null,We(i))}n.applyTransform([e],()=>({}),"modified")}var Kg=n=>n.kind==="col-strip"?{kind:"col",index:n.col}:{kind:"row",index:n.row},Qg=(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=Rh(n),m=Math.max(0,Math.min(f,wl(Math.min(h,d),f))),p=r.radius??0;return Math.abs(m-p)<.001?null:m},Zg=(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,wl(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},Ol=(n,e)=>n<Gi?"vertical":e<Gi?"horizontal":null,bo=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`,Be=n=>{let e=new Map;for(let t of n)e.set(t,t.toObject());return e},Vi=class{host;el;gesture={type:"none"};performed=!1;hoveredTable=null;lastHoverDoc=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=Ze(this.host.document);if(!r||this.host.document.selection.length===1&&it(this.host.document.selection[0]))return null;for(let o of ho(this.host.document,r.quad,r.angle,this.host.zoom,fo(this.host.document))){let i=this.host.toScreen(o.x,o.y);if(Math.hypot(i.x-e,i.y-t)<=Zn)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 Ml(o,this.host.zoom)){let s=this.host.toScreen(i.x,i.y);if(Math.hypot(s.x-e,s.y-t)<=Zn)return i.id}return null}hitLockControl(e,t){let r=this.host.document;if(r.selection.length!==1||!it(r.selection[0]))return null;let o=Ze(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)<=Zn?r.selection[0]:null}hitMoveControl(e,t){if(this.host.mobileControls!==!0||!yl(this.host.document))return!1;let r=Ze(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)<=Eh}hitCornerRotateZone(e,t){let r=this.host.document;if(r.selection.length!==1)return null;let o=r.selection[0];if(o instanceof te||it(o))return null;let i=Ze(r);if(!i)return null;let s=i.angle*Math.PI/180,a=Math.cos(s),l=Math.sin(s),c=Ph/2;for(let u of Nh(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:Di(e),center:{x:t.x,y:t.y},onChild:!0}:{spec:Di(e),center:{x:t.x,y:t.y}})}hoverCursor(e,t,r,o=this.host.document){if(this.host.rulerVisible){let p=Ol(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 se?o.selection[0]:null;if(c?.editingMask){let p=$i((b,x)=>this.host.toScreen(b,x),c,e,t);if(p)return Kn[p]==="x"?"ew-resize":"ns-resize";let g=po((b,x)=>this.host.toScreen(b,x),c,e,t);if(g)return Kn[g.handle]==="x"?"ew-resize":"ns-resize"}else if(c){let p=po((g,b)=>this.host.toScreen(g,b),c,e,t);if(p)return Kn[p.handle]==="x"?"ew-resize":"ns-resize"}let u=o.selection.length===1&&o.selection[0]instanceof te?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 g=u.stripHit(r.x,r.y,this.host.zoom);if(g)return this.updateTableHover(u,null,!1,{strip:Kg(g)}),"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 bo(p.worldAngle+225)}if(h){let p=o.activeGroupChild,g=kl[h];if(typeof g=="number"){let b=g+p.worldAngle;return Al[(Math.round(b/45)%4+4)%4]}}if(this.hitMoveControl(e,t))return"move";let d=this.hitHandle(e,t);if(d==="mtr")return bo((Ze(o)?.angle??0)+225);if(d&&Sr(d))return d==="tlS"||d==="brS"?"nwse-resize":"nesw-resize";if(d){let p=kl[d]+(Ze(o)?.angle??0);return Al[(Math.round(p/45)%4+4)%4]}let f=this.hitCornerRotateZone(e,t);if(f)return bo((Ze(o)?.angle??0)+Tl[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),g="move";return p?.inCircle?g="pointer":p?.border&&o.selection.includes(m)&&(g=sh(m.tableAngle,p.border.type)),this.updateTableHover(m,p,!0),g}if(this.updateTableHover(null,null,!1),!this.host.cropSession&&!this.host.expandSession&&!this.host.pathSession&&!this.host.warpSession){let p=o.nodes.find(g=>Ke(g)&&g.visible&&g.raw.visible!==!1&&g.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,o=this.host.document){o!==this.lastHoverDoc&&(this.lastHoverDoc?.setHovered(null),this.hoveredTable=null,this.lastHoverDoc=o,this.host.requestRenderAll());let i=null,s=null,a=o.nodes.find(d=>d instanceof se&&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 ee&&!(d instanceof te)&&!(d instanceof se)){let f=o.activeGroupChild;if(!(f!==null&&o.selection.length===1&&o.selection[0]===d))o.selection.includes(d)||(i=d);else{let p=d.childAtPoint(r.x,r.y);i=p&&p!==f?p:null}}else d&&!o.selection.includes(d)&&(i=d)}if(i&&i===o.editingNode&&(i=null),c&&!(a&&$i((d,f)=>this.host.toScreen(d,f),a,e,t))){let d=o.selection.length===1&&o.selection[0]instanceof se?o.selection[0]:null;if(d){let f=po((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.lastHoverDoc&&this.lastHoverDoc!==s&&this.lastHoverDoc.setHovered(null),this.lastHoverDoc=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){if(this.host.resolvePointerTarget){let v=this.host.toSceneAbs?this.host.toSceneAbs(e,t):this.host.toScene(e,t),M=this.host.resolvePointerTarget(v.x,v.y);if(!M){this.host.document.clearSelection(),this.host.requestRenderAll();return}M.doc!==this.host.document&&this.host.activateRoutedDocument?.(M.doc)}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 v=s.hitHandle(e,t);v?this.gesture={type:"crop-handle",handle:v}: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 v=a.hitHandle(e,t);v?this.gesture={type:"expand-handle",handle:v}: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 v=l.hitAnchor(e,t);if(v&&l.startAnchorDrag(v)){this.gesture={type:"path-anchor-drag",key:v},this.host.requestRenderAll();return}let M=l.findInsertCandidate(i.x,i.y);if(M){let C=l.insertAnchor(M);if(C){this.gesture={type:"path-anchor-drag",key:C},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 v=c.hitAnchor(e,t);v&&(this.gesture={type:"warp-anchor-drag",anchor:v},c.applyAnchorDrag(v,i)),this.host.requestRenderAll();return}if(this.host.rulerVisible){let v=Ol(e,t);if(v){let M=ph(v,v==="horizontal"?i.y:i.x),C=ct(M);C&&(o.add(C),o.clearSelection(),this.gesture={type:"reference-line",node:C,axis:v,creating:!0,historyBefore:Be([C])}),this.host.requestRenderAll();return}}let u=o.editingNode,h=!1;if(u){if(u.containsPoint(i.x,i.y)){let v=u.localPoint(i.x,i.y),M=u.cursorIndexAt(v.x,v.y);this.host.setEditingSelection(M,M),this.gesture={type:"text-select",anchorIdx:M};return}o.exitEditing(),h=!0}if(!h&&o.selection.length===1&&o.selection[0]instanceof te){let v=o.selection[0],M=o.findTarget(i.x,i.y)?null:v.borderOrIndicatorHit(i.x,i.y,this.host.zoom);if(M?.inCircle){this.gesture={type:"table-indicator-click",node:v,border:M.border};return}let C=o.findTarget(i.x,i.y)?null:v.stripHit(i.x,i.y,this.host.zoom);if(C){this.gesture=C.kind==="col-strip"?{type:"table-strip-click",node:v,kind:"col",index:C.col}:{type:"table-strip-click",node:v,kind:"row",index:C.row};return}}if(!h&&o.selection.length===1&&o.selection[0]instanceof te){let v=o.selection[0];if(o.findTarget(i.x,i.y)===v&&v.rangeHandleHit(i.x,i.y,this.host.zoom)){let M=v.expandedCellRange;if(M){this.gesture={type:"table-range-drag",node:v,anchor:{row:M.r1,col:M.c1}};return}}}let d=h?null:o.nodes.find(v=>v instanceof se&&v.editingMask)??null,f=!!d;if(f&&d){let v=$i((M,C)=>this.host.toScreen(M,C),d,e,t);if(v&&d.editingMask){let M=Fl(d,d.editingMask,v);M&&(this.gesture=M);return}}{let v=o.selection.length===1&&o.selection[0]instanceof se?o.selection[0]:null;if(v){let M=po((C,R)=>this.host.toScreen(C,R),v,e,t);if(M){let C=Fl(v,M.mask,M.handle);C&&(this.gesture=C);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 v=this.hitActiveChildHandle(e,t),M=o.activeGroupChild,C=o.selection.length===1?o.selection[0]:null;if(v&&M&&C instanceof ee&&!(C instanceof te)&&!(C instanceof se)){let R=Si(C,M);if(R.length){let w=[M,...R,...R.flatMap(T=>T.children)];if(v==="mtr"){let T=M.aCoords,E={x:(T.tl.x+T.br.x)/2,y:(T.tl.y+T.br.y)/2};this.freezeRotateHandle(M.raw.angle??0,E,!0),this.gesture={type:"rotate",center:E,startAngle:Math.atan2(i.y-E.y,i.x-E.x),snapshot:{node:M,angle0:M.raw.angle??0},cursorOffset:225,childTransform:{child:M,shells:R,pivotLocal:{...M.center}},historyBefore:Be(w)}}else if(!Sr(v))this.gesture={type:"scale",handle:v,snapshot:Dl(M,v,o),freeScale:r&&hn.has(v),childTransform:{child:M,shells:R},historyBefore:Be(w)};else return;this.host.requestRenderAll();return}}}if(!h&&p&&this.hitMoveControl(e,t)){let v=o.selection[0],M=new Map;M.set(v,{left:v.raw.left??0,top:v.raw.top??0}),this.gesture={type:"move",start:i,startCss:{x:e,y:t},snapshot:M,historyBefore:Be([v])},this.host.requestRenderAll();return}let g=h||!p?null:this.hitHandle(e,t);if(g){if(o.selection.length===1){let v=o.selection[0];if(g==="mtr"){let M=v.center;this.freezeRotateHandle(v.raw.angle??0,M),this.gesture={type:"rotate",center:M,startAngle:Math.atan2(i.y-M.y,i.x-M.x),snapshot:{node:v,angle0:v.raw.angle??0},cursorOffset:225,historyBefore:Be([v])}}else if(Sr(g)&&(_i(v)||uo(v)))this.gesture={type:"cornerRadius",node:v,corner:lo[g],model:uo(v)?"image":"rect",historyBefore:Be([v])};else if(v instanceof te&&Qn(g)){let M=ud(v,g);M.historyBefore=Be([v]),this.gesture=M}else if(v instanceof se&&Qn(g)){let M=hd(v,g);M.historyBefore=Be([v]),this.gesture=M}else this.gesture={type:"scale",handle:g,snapshot:Dl(v,g,o),freeScale:r&&hn.has(g),historyBefore:Be([v])}}else{let v=Ze(o),M=o.selection.filter(C=>!it(C));if(g==="mtr"){let C=zi(v.quad);M.length&&this.freezeRotateHandle(v.angle,C),this.gesture={type:"multi-rotate",center:C,startAngle:Math.atan2(i.y-C.y,i.x-C.x),frameAngle0:v.angle,frame:Yi(v.quad),snapshot:{members:M.map(R=>({node:R,angle0:R.raw.angle??0,center0:{...R.center}}))},historyBefore:Be(o.selection)}}else this.gesture={type:"multi-scale",snapshot:rd(M,g,v),freeScale:r&&hn.has(g),historyBefore:Be(o.selection)}}return}let b=h||!p?null:this.hitCornerRotateZone(e,t);if(b){let v=o.selection[0],M=v.center;this.host.rotateDrag!==void 0&&(this.host.rotateDrag={spec:null,center:{x:M.x,y:M.y}}),this.gesture={type:"rotate",center:M,startAngle:Math.atan2(i.y-M.y,i.x-M.x),snapshot:{node:v,angle0:v.raw.angle??0},cursorOffset:Tl[b],historyBefore:Be([v])};return}if(!h&&o.selection.length===1&&o.selection[0]instanceof te){let v=o.selection[0];if(!o.findTarget(i.x,i.y)&&v.dragHandleHit(i.x,i.y,this.host.zoom)){let M=new Map;for(let C of o.selection)M.set(C,{left:C.raw.left??0,top:C.raw.top??0});this.gesture={type:"move",start:i,startCss:{x:e,y:t},snapshot:M,historyBefore:Be(o.selection)},this.host.requestRenderAll();return}}if(!r){let v=o.nodes.find(M=>Ke(M)&&M.visible&&M.raw.visible!==!1&&M.containsPoint(i.x,i.y));if(v){o.setSelection([v],"create"),this.gesture={type:"reference-line",node:v,axis:v.dims.y===0?"horizontal":"vertical",creating:!1,historyBefore:Be([v])},this.host.requestRenderAll();return}}let x=o.findTarget(i.x,i.y),y=x instanceof te?x:null;if(y){let v=y.borderOrIndicatorHit(i.x,i.y,this.host.zoom);if(v?.inCircle){this.gesture={type:"table-indicator-click",node:y,border:v.border};return}let M=y.borderHit(i.x,i.y);if(M&&o.selection.includes(y)){let R=ld(y,M,i);R.historyBefore=Be([y]),this.gesture=R;return}let C=y.cellHit(i.x,i.y);if(C){o.selection.includes(y)?!r&&o.selection.length>1&&(this.deferredClickSwitch=y):o.setSelection([y],"create");let R=new Map;for(let w of o.selection)it(w)||R.set(w,{left:w.raw.left??0,top:w.raw.top??0});this.gesture={type:"table-cell-click",node:y,start:i,anchorCell:C,shift:r,moveSnapshot:R,frame0:o.selection.length>1&&o.selectionFrame?{...o.selectionFrame}:void 0,historyBefore:Be(o.selection)},this.host.requestRenderAll();return}}if(f&&d){if(x===d){let v=d.maskChildren.find(M=>M.visible&&M.containsPoint(i.x,i.y));if(v){v!==d.editingMask&&(d.editingMask=v),o.setActiveGroupChild(v);let M=new Map;for(let C of o.selection)it(C)||M.set(C,{left:C.raw.left??0,top:C.raw.top??0});this.gesture={type:"move",start:i,startCss:{x:e,y:t},snapshot:M,frame0:void 0,historyBefore:Be(o.selection)}}else d.exitMaskEditing(),o.setActiveGroupChild(null);this.host.requestRenderAll();return}d.exitMaskEditing(),this.host.requestRenderAll()}let S=x instanceof te?null:x;if(S){let v=o.selection.includes(S),M=o.groupEditing;if(r){let C=(o.selection.includes(S)?o.selection.filter(R=>R!==S):[...o.selection,S]).filter(R=>!it(R));o.setSelection(C,"update")}else o.selection.includes(S)?o.selection.length>1&&(this.deferredClickSwitch=S):o.setSelection([S],"create");if(S instanceof ee&&!(S instanceof te)&&!(S instanceof se))o.setActiveGroupChild(S.childAtPoint(i.x,i.y));else if(S instanceof se&&v&&o.selection.length===1){let C=S.maskChildren.find(R=>R.visible&&R.containsPoint(i.x,i.y))??null;o.setActiveGroupChild(C),C?S.editingMask=C:S.exitMaskEditing()}else o.activeGroupChild&&o.setActiveGroupChild(null);if(o.selection.includes(S))if(it(S)&&v&&o.selection.length===1&&o.selection[0]===S)this.gesture={type:"marquee",anchor:i,additive:r,hold:!0};else{let C=o.activeGroupChild,R=M&&C&&S instanceof ee&&!(S instanceof te)&&!(S instanceof se)&&o.selection.length===1&&o.selection[0]===S?Si(S,C):[],w=R.length&&C?{child:C,toLocal:yh(C),shells:R}:null;if(w){let T=new Map;T.set(w.child,{left:w.child.raw.left??0,top:w.child.raw.top??0});let E=[w.child,...w.shells,...w.shells.flatMap(P=>P.children)];this.gesture={type:"move",start:i,startCss:{x:e,y:t},snapshot:T,childMove:w,historyBefore:Be(E)}}else{let T=new Map;for(let E of o.selection)it(E)||T.set(E,{left:E.raw.left??0,top:E.raw.top??0});this.gesture={type:"move",start:i,startCss:{x:e,y:t},snapshot:T,frame0:o.selection.length>1&&o.selectionFrame?{...o.selectionFrame}:void 0,historyBefore:Be(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"){if(this.host.resolvePointerTarget){let s=this.host.toSceneAbs?this.host.toSceneAbs(e,t):this.host.toScene(e,t),a=this.host.resolvePointerTarget(s.x,s.y);if(!a){this.lastHoverDoc&&(this.lastHoverDoc.setHovered(null),this.lastHoverDoc=null,this.host.requestRenderAll()),this.el.style.cursor="default";return}this.el.style.cursor=this.hoverCursor(e,t,a.local,a.doc),this.updateHover(e,t,a.local,a.doc);return}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)<=Kh)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,nd(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=Zg(i.node,i.corner,o);s&&(this.performed=!0,r.applyTransform([i.node],()=>s,"cornerRadius"))}else{let s=Qg(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,od(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+Xi(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=bo((i.snapshot.node.raw.angle??0)+(i.cursorOffset??225))}else if(i.type==="multi-rotate")i.snapshot.members.length&&(this.performed=!0,id(r,i,o),this.el.style.cursor=bo((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)<=Ui)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=>!it(l)),a=(i.additive?[...new Set([...r.selection,...s])]:s).filter(l=>!it(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,cd(i,o);else if(i.type==="table-edge-resize")this.performed=!0,md(r,i,o);else if(i.type==="puzzle-edge-resize")this.performed=!0,fd(r,i,o);else if(i.type==="puzzle-mask-edge-resize")this.performed=!0,dd(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=cn(i.node.cellMap,i.anchor,s);i.node.setCellSelection(a,i.anchor,We(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=cn(i.node.cellMap,a,s);i.node.setCellSelection(l,a,We(l))}}else if(Math.hypot(o.x-i.start.x,o.y-i.start.y)>Ui)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=hl(o.childMove.shells),s=[...new Set([o.childMove.child,...i])];r.applyTransform(s,()=>({}),"modified",{action:Le.drag,before:o.historyBefore})}else{let i=[...o.snapshot.keys()];this.host.transferDraggedNodes?.(i,o.historyBefore,e,t)||r.applyTransform(i,()=>({}),"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?Ol(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=hl(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&&pd(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)<=Ui)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=cn(o.node.cellMap,a,s);o.node.setCellSelection(l,a,We(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 Jg=new Set(["qrcode","barcode"]),ex=n=>{let e=n.raw.type;return typeof e=="string"&&Jg.has(e.toLowerCase())},ji=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();if(e.resolvePointerTarget){let a=e.toSceneAbs?e.toSceneAbs(r.clientX-o.left,r.clientY-o.top):e.toScene(r.clientX-o.left,r.clientY-o.top),l=e.resolvePointerTarget(a.x,a.y);if(!l)return;l.doc!==e.document&&e.activateRoutedDocument?.(l.doc)}let i=e.toScene(r.clientX-o.left,r.clientY-o.top),s=e.document.findTarget(i.x,i.y);if(s instanceof ee&&!(s instanceof te)&&!(s instanceof se)){let a=s.childAtPoint(i.x,i.y);a&&!(a instanceof te)&&!(a instanceof se)&&(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 se){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 xe){this.host.enterTextEditingAtClick(e,t,r);return}if(e?.isImageType&&!ex(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 qi=class n{host;onKeydown;docBus;disposed=!1;constructor(e){this.host=e,this.onKeydown=t=>this.handleKey(t),window.addEventListener("keydown",this.onKeydown),this.docBus=new kt(e.document.events,t=>{let r=()=>this.pruneCellState(),o=[t.on("selection:created",r),t.on("selection:updated",r),t.on("selection:cleared",r)];return()=>o.forEach(i=>i())})}retargetDoc(e){this.docBus.retarget(e.events)}dispose(){this.disposed||(this.disposed=!0,window.removeEventListener("keydown",this.onKeydown),this.docBus.dispose())}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=io(t.cellMap,i.rows,i.cols);t.setCellSelection(s,s[0]??null,We(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=We(e.selectedCells);if(!t)return;let r=Jr(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(eo(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=Se(t,o.row,o.col);i&&!i.isMerged&&i.text&&(i.text="",r=!0)}r&&this.commit(e)}};var Bl=(n,e,t)=>Math.max(e,Math.min(t,n)),Ki={min:.05,max:5},Mr=60,bd=(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 k=Math.abs(h)<10?h*2:h/3,O=e.viewportTransform[0],F=Bl(O*(1-k/200),Ki.min,Ki.max),W=e.cursorPoint(n);e.zoomAt(W.x,W.y,F/O);return}let d=o===0&&Math.abs(t)<=10&&Math.abs(r)<=10,f=Bl(e.viewportTransform[0],.1,Ki.max),m=Math.max(1,f)*1.25,p=20*m,g=k=>Bl(k,-60,60),b=0,x=0;if(l||Math.abs(u)>Math.abs(h)){let k=u!==0?u:h;k!==0&&(b=d?-g(k)*m:k>0?-p:p)}else h!==0&&(x=d?-g(h)*m:h>0?-p:p);if(b===0&&x===0)return;let S=e.scrollViewportTransform??e.viewportTransform,{width:v,height:M}=e.viewSize,C=e.workspaceSize(),R=C.width*f,w=C.height*f,T=S[4],E=S[5],P=Mr-R;T+b<P&&(b=P-T),T+b>v-Mr&&(b=v-Mr-T);let A=Mr-w;E+x<A&&(x=A-E),E+x>M-Mr&&(x=M-Mr-E),!(b===0&&x===0)&&(e.pan(b,x),x!==0&&e.followScrolledPage?.())};function gd(n,e){if(e.length<2)return;let t=n.scrollViewportTransform,r=-t[5]/t[3],o=r+n.viewSize.height/t[3],i=c=>Math.max(0,Math.min(o,c.top+c.height)-Math.max(r,c.top)),s=n.activePageIndex,a=e.find(c=>c.index===s),l=a?i(a):0;for(let c of e){let u=i(c);u>l+.01&&(s=c.index,l=u)}s!==n.activePageIndex&&(n.ensurePageBuilt(s),n.setActivePage(s))}var Qi=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 Vi(i,e,this.interactive),this.tableInteraction=new qi(e);let s=d=>{if(d.key!=="Escape")return;let f=e.document.selection;f.length===1&&f[0]instanceof se&&f[0].editingMask&&(f[0].exitMaskEditing(),e.document.setActiveGroupChild(null),e.requestRenderAll())};this.interactive&&window.addEventListener("keydown",s),this.docBus=new kt(e.document.events,d=>{let f=()=>e.requestRenderAll(),m=[d.on("selection:created",f),d.on("selection:updated",f),d.on("selection:cleared",f),d.on("object:modified",f),d.on("object:moving",p=>this.snapGuide.registerMove(p)),d.on("object:removed",p=>{p instanceof re&&this.sources.releaseAnimatedNode(p)})];return()=>m.forEach(p=>p())}),this.dblClick=new ji(e,this.interactive);let a=d=>{bd(d,e)},l=d=>{if(d.button===1){d.preventDefault(),e.panning=!0,this.lastPanPointer={x:d.clientX,y:d.clientY},i.style.cursor="grab";try{i.setPointerCapture(d.pointerId)}catch{}}},c=d=>{if(!e.panning||!this.lastPanPointer)return;let f=d.clientX-this.lastPanPointer.x,m=d.clientY-this.lastPanPointer.y;this.lastPanPointer={x:d.clientX,y:d.clientY},e.pan(f,m),i.style.cursor="grab"},u=d=>{e.panning&&(e.panning=!1,this.lastPanPointer=null,i.hasPointerCapture(d.pointerId)&&i.releasePointerCapture(d.pointerId),i.style.cursor="default")},h=d=>e.handleFontsLoaded(d.fontfaces??[]);document.fonts?.addEventListener?.("loadingdone",h),this.interactive&&(i.addEventListener("wheel",a,{passive:!1}),i.addEventListener("pointerdown",l),window.addEventListener("pointermove",c),window.addEventListener("pointerup",u)),this.detachListeners=()=>{document.fonts?.removeEventListener?.("loadingdone",h),i.removeEventListener("wheel",a),i.removeEventListener("pointerdown",l),window.removeEventListener("pointermove",c),window.removeEventListener("pointerup",u),window.removeEventListener("keydown",s)}}host;snapGuide;sources;interactive;pointer;tableInteraction;dblClick;detachListeners=null;docBus=null;lastPanPointer=null;get pointerActive(){return this.pointer.active}retargetDoc(e){this.docBus?.retarget(e.events),this.tableInteraction.retargetDoc(e)}dispose(){this.detachListeners?.(),this.docBus?.dispose(),this.pointer.dispose(),this.dblClick.dispose(),this.tableInteraction.dispose()}};var tx=(n,e)=>({w:e.naturalWidth||e.width||(n.width??0),h:e.naturalHeight||e.height||(n.height??0)}),nx=(n,e,t)=>({w:e*Math.abs((n.scaleX??1)||1),h:t*Math.abs((n.scaleY??1)||1)}),rx=(n,e,t,r,o,i)=>({cropX:Math.max(0,t/2-o/2-n),cropY:Math.max(0,r/2-i/2-e)}),ox=(n,e,t,r,o,i)=>({clipX:t/2-o/2-n,clipY:r/2-i/2-e}),xd=(n,e,t)=>{let r=tx(e,t),o=nx(e,r.w,r.h),i=n.width??0,s=n.height??0,{cropX:a,cropY:l}=rx(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"}},yd=n=>{let{clipX:e,clipY:t}=ox(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 ix={left:-.5,top:-.5,center:0,bottom:.5,right:.5},Ft=n=>typeof n=="string"?ix[n]??0:n-.5,Hl=(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}},sx=n=>({x:n.width*n.scaleX,y:n.height*n.scaleY}),Ji=sx,go=n=>n*Math.PI/180,Wl=(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=Hl(c,go(o),n)),c},Gl=(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=Hl(c,go(o),n)),c},vd=(n,e,t,r,o)=>Wl(n,Ft(e),Ft(t),r,o),Xl=(n,e,t,r,o,i)=>Gl({x:n,y:e},Ft(t),Ft(r),o,i),Cr=(n,e,t=0,r=0)=>{let o=Xl(n.left,n.top,n.originX,n.originY,Ji(n),n.angle),i=e;n.angle&&(i=Hl(i,-go(n.angle),o));let s=Ji(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}},gn=(n,e,t,r)=>{let o=Ji(n),i=Xl(n.left,n.top,n.originX,n.originY,o,n.angle),s=Wl(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=Gl(s,e,t,c,n.angle,n.flipX,n.flipY),h=vd(u,n.originX,n.originY,c,n.angle);return{...n,...r,scaleX:a,scaleY:l,left:h.x,top:h.y}},ax=(n,e)=>{let{width:t,cropX:r}=n,i=Cr(n,e).x/n.scaleX- -(t/2),s=t-i;return r+i<0&&(i=-r,s=t+r),s<=0&&(i+=s,s=0),gn(n,.5,0,{width:s,height:n.height,cropX:r+i,cropY:n.cropY})};var lx=(n,e)=>{let{width:t,cropX:r}=n,o=Cr(n,e),i=t-(t/2-o.x/n.scaleX);return i+r>n.naturalWidth&&(i=n.naturalWidth-r),i<0&&(i=0),gn(n,-.5,0,{width:i,height:n.height,cropX:r,cropY:n.cropY})};var cx=(n,e)=>{let{height:t,cropY:r}=n,i=Cr(n,e).y/n.scaleY- -(t/2),s=t-i;return r+i<0&&(i=-r,s=t+r),s<=0&&(i+=s,s=0),gn(n,0,.5,{width:n.width,height:s,cropX:n.cropX,cropY:r+i})};var ux=(n,e)=>{let{height:t,cropY:r}=n,o=Cr(n,e),i=t-(t/2-o.y/n.scaleY);return i+r>n.naturalHeight&&(i=n.naturalHeight-r),i<0&&(i=0),gn(n,0,-.5,{width:n.width,height:i,cropX:n.cropX,cropY:r})};var es=(n,e,t)=>e==="left"||e==="right"?e==="left"?ax(n,t):lx(n,t):e==="top"?cx(n,t):ux(n,t),Sd=(n,e,t)=>{let r=e==="tl"||e==="bl"?"left":"right",o=e==="tl"||e==="tr"?"top":"bottom",i=es(n,r,t);return es(i,o,t)},Zi=(n,e,t)=>{let r=e/t;return n<=r?{width:n,height:n*t}:{width:e/t,height:e}},wd=(n,e,t,r)=>{let o=Cr(n,t),i=o.x/n.scaleX,s=o.y/n.scaleY;if(e==="br"){let d=i- -n.width/2,f=s- -n.height/2;if(d=Math.min(d,n.naturalWidth-n.cropX),f=Math.min(f,n.naturalHeight-n.cropY),d<=0||f<=0)return null;let{width:m,height:p}=Zi(d,f,r);return gn(n,-.5,-.5,{width:m,height:p,cropX:n.cropX,cropY:n.cropY})}if(e==="tl"){let d=n.width/2-i,f=n.height/2-s;if(d=Math.min(d,n.width+n.cropX),f=Math.min(f,n.height+n.cropY),d<=0||f<=0)return null;let{width:m,height:p}=Zi(d,f,r),g=n.width-m,b=n.height-p;return n.cropX+g<0||n.cropY+b<0?null:gn(n,.5,.5,{width:m,height:p,cropX:n.cropX+g,cropY:n.cropY+b})}if(e==="tr"){let d=i- -n.width/2,f=n.height/2-s;if(d=Math.min(d,n.naturalWidth-n.cropX),f=Math.min(f,n.height+n.cropY),d<=0||f<=0)return null;let{width:m,height:p}=Zi(d,f,r),g=n.height-p;return n.cropY+g<0?null:gn(n,-.5,.5,{width:m,height:p,cropX:n.cropX,cropY:n.cropY+g})}let a=n.width/2-i,l=s- -n.height/2;if(a=Math.min(a,n.width+n.cropX),l=Math.min(l,n.naturalHeight-n.cropY),a<=0||l<=0)return null;let{width:c,height:u}=Zi(a,l,r),h=n.width-c;return n.cropX+h<0?null:gn(n,.5,-.5,{width:c,height:u,cropX:n.cropX+h,cropY:n.cropY})},hx=(n,e,t,r,o)=>{let i=Math.abs(n.x/t),s=Math.abs(n.y/e);return Math.min(i,s)},Td=(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=Cr(n,t,Ft(a),Ft(l)),u=hx(c,o,r,n.flipX,n.flipY),h=u/n.scaleX,d=u/n.scaleY,f=n.width/h,m=n.height/d,p=i/h,g=s/d,b,x;if(e==="br"){if(b=n.cropX/h,x=n.cropY/d,b+f>r||x+m>o)return null}else if(e==="tl"){if(b=r-f-p,x=o-m-g,f+p>r||m+g>o)return null}else if(e==="tr"){if(b=n.cropX/h,x=o-m-g,b+f>r||g+m>o)return null}else if(b=r-f-p,x=n.cropY/d,f+p>r||m+x>o)return null;let y,S;e==="br"?(y=-b/f,S=-x/m):e==="tl"?(y=1+p/f,S=1+g/m):e==="tr"?(y=-b/f,S=1+g/m):(y=1+p/f,S=-x/m);let v=Ji(n),M=Xl(n.left,n.top,n.originX,n.originY,v,n.angle),C=Wl(M,Ft(a),Ft(l),v,n.angle,n.flipX,n.flipY),R={x:f*u,y:m*u},w=Gl(C,Ft(y),Ft(S),R,n.angle,n.flipX,n.flipY),T=vd(w,n.originX,n.originY,R,n.angle);return{...n,width:f,height:m,cropX:b,cropY:x,scaleX:u,scaleY:u,left:T.x,top:T.y}},Ed=(n,e)=>{let t=Math.cos(go(n.angle)),r=Math.sin(go(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}},Md=(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}},Cd=(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"}},Rd=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}},xn={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}},xo=(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 Pd=12,dx=14,kd=7,fx=1,mx=1,Ad=ae("#f6f7fa"),Nd=ae("#2f6fed"),px=["e","se","s","sw","w","nw","n","ne","e"],Ld=["tl","tr","bl","br"],Id=["tl","tr","bl","br"],_d=["left","right","top","bottom"],zl=null,bx=()=>{if(zl)return zl;let n=Math.ceil((kd+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,kd,0,Math.PI*2),t.fillStyle="#ffffff",t.fill(),t.lineWidth=1.5,t.strokeStyle="#2f6fed",t.stroke(),zl=e,e},rs=30,os=7,Yl={x:28,y:16},Ul={x:14,y:4},$l=2,Od=(n,e)=>{let t=document.createElement("canvas");t.width=n*$l,t.height=e*$l;let r=t.getContext("2d");return r?{canvas:t,ctx:r}:null},Je=n=>n*$l,ts=null,gx=()=>{if(ts)return ts;let n=Od(rs,rs);if(!n)return ts=document.createElement("canvas");let{canvas:e,ctx:t}=n;return t.translate(Je(os),Je(os)),t.shadowColor="rgba(12, 18, 28, 0.38)",t.shadowBlur=Je(4),t.shadowOffsetX=Je(2),t.shadowOffsetY=Je(2),t.beginPath(),t.lineWidth=Je(6),t.lineCap="round",t.strokeStyle="#dfe2e8",t.moveTo(0,Je(10)),t.lineTo(0,0),t.lineTo(Je(10),0),t.stroke(),ts=e,e},ns=null,xx=()=>{if(ns)return ns;let n=Od(Yl.x,Yl.y);if(!n)return ns=document.createElement("canvas");let{canvas:e,ctx:t}=n;return t.translate(Je(Ul.x),Je(Ul.y)),t.shadowColor="rgba(12, 18, 28, 0.38)",t.shadowBlur=Je(4),t.shadowOffsetX=0,t.shadowOffsetY=Je(2),t.beginPath(),t.lineWidth=Je(4),t.lineCap="round",t.strokeStyle="#dfe2e8",t.moveTo(Je(-6),0),t.lineTo(Je(6),0),t.stroke(),ns=e,e},Bd=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]},Dd=(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]=Bd(n),p=n[0]*e+n[2]*t+n[4],g=n[1]*e+n[3]*t+n[5],b=Y([h,d,f,m,0,0],[c,u,-u,c,0,0],!0),x=(i.x-o.x/2)/s,y=(i.y-o.y/2)/s;return{matrix:[b[0],b[1],b[2],b[3],p-(b[0]*x+b[2]*y),g-(b[1]*x+b[3]*y)],dims:{x:o.x/s,y:o.y/s},color:[1,1,1,1],texture:a}},Fd=(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},is=class{constructor(e){this.host=e}host;node=null;circlesVisible=!0;ratio=null;detachKey=null;get active(){return this.node!==null}get target(){return this.node}get info(){let e=this.node;if(!e||!(e instanceof le?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 le}}enter(e){if(this.node&&this.exit(),e instanceof le){if(!this.host.document.nodes.includes(e)||e.clipDynamicKind||!e.clipImageRaw||!e.clipImageEl)return!1}else if(e instanceof re||!e.isImageType||!e.imageEl)return!1;this.node=e,this.ratio=null;let t=Math.abs(e.raw.scaleX??1),r=Math.abs(e.raw.scaleY??1);if(this.circlesVisible=t===r,this.host.document.exitEditing(),this.host.document.setSelection([e],"update"),!(e instanceof le)){let o=i=>{i.key==="Escape"&&this.node&&this.exit()};window.addEventListener("keydown",o),this.detachKey=()=>window.removeEventListener("keydown",o)}return this.host.requestRenderAll(),!0}exit(){if(!this.node)return;let e=this.node;this.node=null,this.ratio=null,this.detachKey?.(),this.detachKey=null,this.host.document.applyTransform([e],()=>({}),"modified",{action:Le.crop}),this.host.requestRenderAll()}exitByOutsideClick(){this.exit()}setAspectRatio(e){if(this.node){if(this.ratio=e,e&&e>0){let t=Md(this.liveState(),e);this.writeBack(t)}this.host.requestRenderAll()}}hitHandle(e,t){let r=this.node;if(!r)return null;let o=r.matrix,i=this.liveState();for(let s of Ld){let a=xn[s],l=V(o,a.x*i.width,a.y*i.height),c=this.host.toScreen(l.x,l.y);if(Math.hypot(c.x-e,c.y-t)<=Pd)return s}if(!this.ratio)for(let s of _d){let a=xn[s],l=V(o,a.x*i.width,a.y*i.height),c=this.host.toScreen(l.x,l.y);if(Math.hypot(c.x-e,c.y-t)<=Pd)return s}if(this.circlesVisible)for(let s of Id){let a=xo(i,s),l=V(o,a.x,a.y),c=this.host.toScreen(l.x,l.y);if(Math.hypot(c.x-e,c.y-t)<=dx)return`${s}S`}return null}hitRect(e,t){let r=this.node;if(!r)return!1;let o=this.liveState(),i=r.matrix;if(!(r instanceof le)){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 V(i,d,f)});return Fd({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=V(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 Fd(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?Td(o,e.slice(0,2),t):null:Ei(e)?i=this.ratio?wd(o,e,t,this.ratio):Sd(o,e,t):this.ratio||(i=es(o,e,t)),i&&this.writeBack(i),this.host.requestRenderAll()}moveImageBy(e){if(!this.node)return;let r=this.liveState(),{cropX:o,cropY:i}=Ed(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=xn[o.slice(0,2)],a=((this.node.raw.angle??0)+Math.atan2(i.y,i.x)*180/Math.PI+360)%360;return`${px[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=(g,b)=>V(o,g,b),a=r.width,l=r.height,c=fx/e;for(let g of[1,2]){let b=-a/2+g*a/3,x=s(b,-l/2),y=s(b,l/2);i.push(Ce(x,y,c,Ad))}for(let g of[1,2]){let b=-l/2+g*l/3,x=s(-a/2,b),y=s(a/2,b);i.push(Ce(x,y,c,Ad))}let u=mx/e,h=["tl","tr","br","bl"].map(g=>s(xo(r,g).x,xo(r,g).y));for(let g=0;g<4;g++)i.push(Ce(h[g],h[(g+1)%4],u,Nd));let d=1.5/e,f=["tl","tr","br","bl"].map(g=>s(xn[g].x*a,xn[g].y*l));for(let g=0;g<4;g++)i.push(Ce(f[g],f[(g+1)%4],d,Nd));if(this.circlesVisible){let g=bx(),[b,x,y,S]=Bd(o),v=g.width/e;for(let M of Id){let C=xo(r,M);i.push({matrix:[b,x,y,S,o[0]*C.x+o[2]*C.y+o[4],o[1]*C.x+o[3]*C.y+o[5]],dims:{x:v,y:v},color:[1,1,1,1],texture:g})}}if(!this.ratio){let g={top:0,right:90,bottom:180,left:270},b=xx();for(let x of _d){let y=xn[x];i.push(Dd(o,y.x*a,y.y*l,g[x],Yl,Ul,e,b))}}let m={tl:0,tr:90,br:180,bl:270},p=gx();for(let g of Ld){let b=xn[g];i.push(Dd(o,b.x*a,b.y*l,m[g],{x:rs,y:rs},{x:os,y:os},e,p))}return i}dispose(){this.detachKey?.(),this.detachKey=null,this.node=null}liveState(){let e=this.node;if(e instanceof le)return xd(e.raw,e.clipImageRaw,e.clipImageEl);let t=e.imageEl;return Cd(e.raw,t.naturalWidth,t.naturalHeight)}writeBack(e){let t=this.node,r=t instanceof le?yd(e):Rd(e);this.host.document.setProps(t,r,{deferIndexRebuild:!0})}};var Hd={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}},Wd=(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}},Gd=(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,g=-u,b=u,x=-h,y=h;o.left&&(g=Math.min(m,b-1)),o.right&&(b=Math.max(m,g+1)),o.top&&(x=Math.min(p,y-1)),o.bottom&&(y=Math.max(p,x+1));let S=o.right,v=o.left,M=o.bottom,C=o.top,R=e.centerX-l,w=e.centerY-c,T=R*s+w*a,E=-R*a+w*s,P=T-e.scaledWidth/2,A=T+e.scaledWidth/2,k=E-e.scaledHeight/2,O=E+e.scaledHeight/2;!S&&P<g&&(g=P),!v&&A>b&&(b=A),!M&&k<x&&(x=k),!C&&O>y&&(y=O);let F=(g+b)/2,W=(x+y)/2;return{width:b-g,height:y-x,centerX:l+F*s-W*a,centerY:c+F*a+W*s}},Vl=(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,g=n.height/2,b=Math.max(0,h-f+p),x=Math.max(0,p-h-f),y=Math.max(0,d-m+g),S=Math.max(0,g-d-m);return{left:Math.floor(b*a),right:Math.floor(x*a),top:Math.floor(y*l),bottom:Math.floor(S*l)}},Xd=(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}},Jn={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}};var ss=n=>n*Math.PI/180,yx=12,vx=8,Sx=1,wx=(()=>{let n=ae("#3788ff");return[n[0],n[1],n[2],.5]})(),Tx=ae("#3788ff"),Ex=ae("#ffffff"),Mx=(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},as=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 re?!1:(e.isImageType||e instanceof le)&&!!e.imageEl&&!(e instanceof le&&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=Vl(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(){this.exit()}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=ge({...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=ss(r.angle),i=Math.cos(o),s=Math.sin(o);for(let a of Object.keys(Jn)){let l=Jn[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)<=yx)return a}return null}hitRect(e,t){let r=this.view(),o=ss(r.angle),i=Math.cos(o),s=Math.sin(o),a=["tl","tr","br","bl"].map(l=>{let c=Jn[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 Mx({x:e,y:t},a)}applyHandle(e,t){let r=this.node;if(!r)return;let o=this.view(),i=Gd(o.rect,o.img,o.angle,t,Hd[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=Xd(r.rect,r.img,r.angle,{x:r.img.centerX+e.x,y:r.img.centerY+e.y}),i=ge({...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){return this.hitHandle(e,t)?"pointer":this.hitRect(r,o)?"move":""}buildUnderlay(){let e=this.view(),t=ss(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:wx}]}buildOverlay(e){let t=this.view(),r=[],o=ss(t.angle),i=[Math.cos(o),Math.sin(o),-Math.sin(o),Math.cos(o),t.rect.centerX,t.rect.centerY],s=u=>{let h=Jn[u];return V(i,h.x*t.rect.width,h.y*t.rect.height)},a=Sx/e,l=["tl","tr","br","bl"].map(s);for(let u=0;u<4;u++)r.push(Ce(l[u],l[(u+1)%4],a,Tx));let c=vx/e;for(let u of Object.keys(Jn)){let h=Jn[u],d=h.x*t.rect.width,f=h.y*t.rect.height,m=[i[0],i[1],i[2],i[3],i[4]+d*i[0]+f*i[2],i[5]+d*i[1]+f*i[3]];r.push({matrix:m,dims:{x:c,y:c},color:Ex})}return r}dispose(){this.detachKey?.(),this.detachKey=null,this.node=null}view(){let e=this.node;return this.expandViewOf(e,e.imageEl)}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=Wd(r,s,{width:a,height:l}),h=r.angle??0,d=t?Vl(u,c,h,{width:t.naturalWidth,height:t.naturalHeight}):null;return{rect:u,img:c,angle:h,offsets:d}}};var Cx=8,Rx=6;var tr=n=>{if(!n)return null;let e=je(n);return e?{x:(e.left+e.right)/2,y:(e.top+e.bottom)/2}:null},zd=(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}},er=(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}},Px=n=>n==="C"?5:n==="Q"?3:1,ht=(n,e,t)=>({x:n[e]-t.x,y:n[e+1]-t.y}),jl=(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:ht(o,o.length-2,e)}),s==="C"){let a=ht(o,1,e),l=ht(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?ht(n[i-1],Px(c),e):a;r.push({from:a,to:u},{from:l,to:ht(o,5,e)})}else if(s==="Q"){let a=ht(o,1,e);t.push({key:`c_${i}_Q_CP_1`,kind:"handle",commandIndex:i,pointIndex:1,local:a}),r.push({from:a,to:ht(o,3,e)})}}),{handles:t,connections:r}},$d=(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}})),ls=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}},kx=(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)}},Ax=(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}},Yd=(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}},Ud=(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}},Nx=(n,e,t)=>({x:n.x+(e.x-n.x)*t,y:n.y+(e.y-n.y)*t}),Vd=(n,e,t,r,o)=>{let i=Cx/o,s=Rx/o,a=h=>V(r,h.x,h.y),l=(h,d)=>a(ht(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 M={x:er(n,d).x-e.x,y:er(n,d).y-e.y},C=a(M),R=l(h,1),w=f==="C"?ht(h,5,e):ht(h,3,e),T=a(w),P=Ax(t,f==="C"?F=>Yd(C,R,l(h,3),T,F):F=>Ud(C,R,T,F));if(P.distance>i||P.length<=s*2||P.distance>=u)return;let A=s/P.length;if(P.t<=A||P.t>=1-A)return;let k=er(n,d),O=f==="C"?(()=>{let F={x:k.x-e.x,y:k.y-e.y},W=ht(h,1,e),X=ht(h,3,e),_={x:h[5]-e.x,y:h[6]-e.y};return Yd(F,W,X,_,P.t)})():(()=>{let F={x:k.x-e.x,y:k.y-e.y},W=ht(h,1,e),X={x:h[3]-e.x,y:h[4]-e.y};return Ud(F,W,X,P.t)})();u=P.distance,c={commandIndex:d,commandType:f,t:P.t,local:O,scene:P.point};return}if(f!=="L"&&f!=="Z")return;let m=f==="L"?er(n,d):zd(n,Math.max(0,d-1)),p=zd(n,d),g=a({x:m.x-e.x,y:m.y-e.y}),b=a({x:p.x-e.x,y:p.y-e.y}),x=kx(t,g,b);if(x.distance>i||x.length<=s*2||x.distance>=u)return;let y=s/x.length;if(x.t<=y||x.t>=1-y)return;u=x.distance;let S={x:m.x-e.x,y:m.y-e.y},v={x:p.x-e.x,y:p.y-e.y};c={commandIndex:d,commandType:f,t:x.t,local:Nx(S,v,x.t),scene:x.point}}),c},jd=(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}),qd=(n,e,t,r)=>n.map((o,i)=>i===e?{x:t.x+r.x,y:t.y+r.y}:o),Kd=(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=er(n,s),c=t.t,u=a[1],h=a[2],d=a[3],f=a[4],m=a[5],p=a[6],g=l.x+(u-l.x)*c,b=l.y+(h-l.y)*c,x=u+(d-u)*c,y=h+(f-h)*c,S=d+(m-d)*c,v=f+(p-f)*c,M=g+(x-g)*c,C=b+(y-b)*c,R=x+(S-x)*c,w=y+(v-y)*c;return r[s]=["C",g,b,M,C,o,i],r.splice(s+1,0,["C",R,w,S,v,m,p]),r}if(t.commandType==="Q"){let a=r[s],l=er(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,g=u+(d-u)*c,b=h+(f-h)*c;return r[s]=["Q",m,p,o,i],r.splice(s+1,0,["Q",g,b,d,f]),r}return t.commandType==="Z"?(r.splice(s,1,["L",o,i],["Z"]),r):null},Qd=(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=er(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}},ql=(n,e)=>{let t=n?.[e]?.[0];return t&&["C","Q","S","T","A"].includes(String(t).toUpperCase())?"smooth":"line"},Zd=(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 Lx=12,yo=ae("#2254f4"),Jd=ae("#ffffff"),ef=7,tf=5,Ix=1,Kl=null,_x=()=>{if(Kl)return Kl;let n=Math.ceil((tf+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,tf,0,Math.PI*2),t.fillStyle="#ffffff",t.fill(),t.lineWidth=1.5,t.strokeStyle="#2254f4",t.stroke(),Kl=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},cs=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=V(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"&&!Ae(e.raw.path)||t==="poly"&&!Array.isArray(e.raw.points)||t==="line"&&!(e instanceof vr))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=Lx;for(let a of this.currentHandles()){let l=V(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=Ae(r.raw.path),i=tr(o);return!o||!i?null:Vd(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=V(Te(s),t.x,t.y);if(o==="path"){let l=Ae(r.raw.path),c=tr(l);if(!l||!c)return;let u=jd(l,i.commandIndex,i.pointIndex,a,c);this.writeBackWithCompensation(r,u,c,tr(u),je(u))}else if(o==="poly"){let l=r.raw.points,c=ls(l);if(!c)return;let u=qd(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,ls(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=ge({...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=Ae(t.raw.path),o=tr(r);if(!r||!o)return null;let i=Kd(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=Ae(r.raw.path);if(!o)return!1;let i=Qd(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=[...pn(t.aCoords,e)],s=a=>V(o,a.x,a.y);if(r==="path"){let a=Ae(t.raw.path),l=tr(a);if(!a||!l)return i;let{handles:c,connections:u}=jl(a,l),h=Ix/e;for(let p of u)i.push(Ce(s(p.from),s(p.to),h,yo));let d=ef/e,f=_x(),m=f.width/2*2*(1/e);for(let p of c){let g=s(p.local);if(p.kind==="handle")i.push({matrix:[1,0,0,1,g.x,g.y],dims:{x:m,y:m},color:[1,1,1,1],texture:f});else{let b=p.key===this.activeAnchorKey;i.push({matrix:[1,0,0,1,g.x,g.y],dims:{x:d,y:d},color:yo}),i.push({matrix:[1,0,0,1,g.x,g.y],dims:{x:d-2/e,y:d-2/e},color:b?yo:Jd})}}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=ef/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:yo}),i.push({matrix:[1,0,0,1,c.x,c.y],dims:{x:a-2/e,y:a-2/e},color:u?yo:Jd})}}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=Ae(e.raw.path),l=tr(a);return!a||!l?[]:jl(a,l).handles}if(t==="poly"){let a=e.raw.points,l=ls(a);return!Array.isArray(a)||!l?[]:$d(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=Zd(e.center,r,o,[s[0],s[1],s[2],s[3]]),l=ge({...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 Dx}from"warpvas";var nf=12,Fx=5,Ox=4,Bx=1,rf=3,of=2e3,sf=10,Hx=[.2,.2,.2,.6],Wx=[.11,.35,.96,1],Gx=[1,1,1,.9],us=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 Ql){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 re||!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 Dx(s,t?.gridRows??rf,t?.gridCols??rf);l.setInputLimitSize({width:of,height:of}),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 af){let u=lf(l,c);if(!u)continue;let h=this.screenDist(u,e,t);h<=nf&&(!i||h<i.dist)&&(i={anchor:{kind:"vertex",row:s,col:a,pos:c},dist:h})}else for(let c of Ql){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<=nf&&(!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 Ql){let c=a[l];if(!c||c.length<4)continue;let u=this.toScene(c[0]);for(let h=1;h<=sf;h++){let d=this.toScene(Xx(c[0],c[1],c[2],c[3],h/sf));t.push(Ce(u,d,Bx/e,Hx)),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(cf(this.toScene(d),Ox,Gx,e)))}}for(let l of af){let c=lf(a,l);if(!c)continue;let u=`${Math.round(c.x)},${Math.round(c.y)}`;o.has(u)||(o.add(u),t.push(cf(this.toScene(c),Fx,Wx,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},g=ge({...r.raw,width:d,height:f},p),b={x:l.width/2-l.offsetX,y:l.height/2-l.offsetY};i={dataURL:a,state:c,nextWidth:d,nextHeight:f,left:g.x,top:g.y,originalSrc:this.originalSrc,displayScale:{x:this.displayScale.x,y:this.displayScale.y},coreAnchor:b}}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 zx(this.node.matrix,e,t)}toScene(e){let t=this.node;return V(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)}},af=["tl","tr","bl","br"],Ql=["top","right","bottom","left"],lf=(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},Xx=(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}},cf=(n,e,t,r)=>({matrix:[1,0,0,1,n.x,n.y],dims:{x:e*2/r,y:e*2/r},color:t}),zx=(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 Rr=([n,e],[t,r])=>n<=t?e>=t:n>=t?r>=n:!1,hs=([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)},df=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}},Yx=(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},uf=(n,e,t,r,o,i,s)=>{let a=[],l=(c,u,h,d,f,m)=>{let p=u;for(let g of d){let b=Yx(c,u,g[u]-h),x=g[u]+h,y=m[p];a.length=0;for(let S=b;S<c.length;S++){let v=c[S];if(v.p[u]>x)break;let M=v.p[u]-g[u],C=Math.abs(M);C<=y&&(C<y&&(y=C,a.length=0),a.push({p:v.p,i:v.i,offset:M}))}a.sort((S,v)=>S.i-v.i);for(let S of a)jt(f,S.offset,m,p,{type:"point",points:[g,S.p],offset:S.offset})}};l(e.byX,"x",t,n,i,o),l(e.byY,"y",r,n,s,o)},Jl=n=>({x:he(n.x),y:he(n.y)}),Zl=n=>({left:he(n.left),top:he(n.top),right:he(n.right),bottom:he(n.bottom)}),fs=n=>[n.tl,n.tr,n.br,n.bl,n.c].map(Jl),ff=n=>n.flatMap(fs);var mf=n=>{let e=n.map(Zl).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 Ux=(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=(w,T,E,P)=>({startBounds:w,endBounds:T,startSide:[{x:w.right,y:w.top},{x:w.right,y:w.bottom}],endSide:[{x:T.left,y:T.top},{x:T.left,y:T.bottom}],length:P,overlap:E}),g=(w,T,E,P)=>({startBounds:w,endBounds:T,startSide:[{x:w.left,y:w.bottom},{x:w.right,y:w.bottom}],endSide:[{x:T.left,y:T.top},{x:T.right,y:T.top}],length:P,overlap:E}),b=(w,T)=>{if(!(w.right<T.left&&Rr([w.top,w.bottom],[T.top,T.bottom])))return;let E=hs([w.top,w.bottom],[T.top,T.bottom]);if(!Rr([s,l],E))return;let P=T.left-w.right,A=he(w.right+P/2-c);if(P>f&&Math.abs(A)<=t.x){jt(r,A,t,"x",{type:"gap",direction:"center_horizontal",gap:p(w,T,E,P),offset:A});return}let k=he(P-(i-T.right));if(Math.abs(k)<=t.x){jt(r,k,t,"x",{type:"gap",direction:"side_right",gap:p(w,T,E,P),offset:k});return}let O=he(w.left-a-P);Math.abs(O)<=t.x&&jt(r,O,t,"x",{type:"gap",direction:"side_left",gap:p(w,T,E,P),offset:O})},x=(w,T)=>{if(!(w.bottom<T.top&&Rr([w.left,w.right],[T.left,T.right])))return;let E=hs([w.left,w.right],[T.left,T.right]);if(!Rr([i,a],E))return;let P=T.top-w.bottom,A=he(w.bottom+P/2-u);if(P>m&&Math.abs(A)<=t.y){jt(o,A,t,"y",{type:"gap",direction:"center_vertical",gap:g(w,T,E,P),offset:A});return}let k=he(w.top-l-P);if(Math.abs(k)<=t.y){jt(o,k,t,"y",{type:"gap",direction:"side_top",gap:g(w,T,E,P),offset:k});return}let O=he(s-T.bottom),F=P-O;Math.abs(F)<=t.y&&jt(o,F,t,"y",{type:"gap",direction:"side_bottom",gap:g(w,T,E,P),offset:F})},y=e.byLeft,S=e.byRight,v=e.byTop,M=e.byBottom,C=h+1e-6,R=d+1e-6;{let w=y.length;for(let T of S){if(T.bounds.right>=c+h+.001)break;let E=2*c-T.bounds.right,P=E+2*C,A=E-2*C;for(;w>0&&y[w-1].bounds.left>P;)w--;for(let k=w-1;k>=0&&y[k].bounds.left>=A;k--)b(T.bounds,y[k].bounds)}}{let w=0;for(let T of e.byLeftPlusRight){if(T.bounds.right>=i+h+.001)continue;let E=T.bounds.left+T.bounds.right-i,P=E-C,A=E+C;for(;w<S.length&&S[w].bounds.right<P;)w++;for(let k=w;k<S.length&&S[k].bounds.right<=A;k++)b(S[k].bounds,T.bounds)}}{let w=0;for(let T of e.byLeftPlusRight){if(T.bounds.left<=a-h-.001)continue;let E=T.bounds.left+T.bounds.right-a,P=E-C,A=E+C;for(;w<y.length&&y[w].bounds.left<P;)w++;for(let k=w;k<y.length&&y[k].bounds.left<=A;k++)b(T.bounds,y[k].bounds)}}{let w=v.length;for(let T of M){if(T.bounds.bottom>=u+d+.001)break;let E=2*u-T.bounds.bottom,P=E+2*R,A=E-2*R;for(;w>0&&v[w-1].bounds.top>P;)w--;for(let k=w-1;k>=0&&v[k].bounds.top>=A;k--)x(T.bounds,v[k].bounds)}}{let w=0;for(let T of e.byTopPlusBottom){if(T.bounds.top<=l-d-.001)continue;let E=T.bounds.top+T.bounds.bottom-l,P=E-R,A=E+R;for(;w<v.length&&v[w].bounds.top<P;)w++;for(let k=w;k<v.length&&v[k].bounds.top<=A;k++)x(T.bounds,v[k].bounds)}}{let T=0;for(let E of e.byTopPlusBottom){if(E.bounds.bottom>=s+d+.001)continue;let P=E.bounds.top-he(s-E.bounds.bottom),A=P-R,k=P+R;for(;T<M.length&&M[T].bounds.bottom<A-1e-5;)T++;for(let O=T;O<M.length&&M[O].bounds.bottom<=k;O++)x(M[O].bounds,E.bounds)}}},ds=(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})}},$x=(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(!Rr([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,g=he(h.length-p);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_right",gap:h,offset:g});continue}let b=h.startBounds.left-a,x=he(b-h.length);if(Math.abs(x)<=t.x){Math.abs(x)<t.x&&(r.length=0),t.x=Math.abs(x),r.push({type:"gap",direction:"side_left",gap:h,offset:x});continue}}for(let h of e.verticalGaps){if(!Rr([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,g=he(p-h.length);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_top",gap:h,offset:g});continue}let b=he(s-h.endBounds.bottom),x=h.length-b;if(Math.abs(x)<=t.y){Math.abs(x)<t.y&&(o.length=0),t.y=Math.abs(x),o.push({type:"gap",direction:"side_bottom",gap:h,offset:x});continue}}},hf=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())},pf=(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:hf(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:hf(a.map(l=>({x:l.x,y:Number(s)})).sort((l,c)=>l.x-c.x))}));return[...o,...i]},Vx=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())},jx=(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=hs([r,i],a.gap.overlap),h=hs([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 Vx(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)}]})))},bf=(n,e,t,r,o,i)=>{let s=(b,x,y)=>{"byLeft"in r?Ux(b,r,l,x,y):$x(b,r,l,x,y)},a=Zl(e),l={x:o,y:o},c=[],u=[];i?uf(n,i,o,o,l,c,u):ds(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(b=>Jl({x:b.x+h.x,y:b.y+h.y})),f=Zl({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?uf(d,i,0,0,l,c,u):ds(d,t,l,c,u),s(f,c,u);let m=pf(c,u),p=[...c,...u].filter(b=>b.type==="gap"),g=jx(f,p);return{snapOffset:h,pointSnapLines:m,gapSnapLines:g}},gf=(n,e,t)=>{let r={x:t,y:t},o=[],i=[];ds(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=>Jl({x:c.x+s.x,y:c.y+s.y}));ds(a,e,r,o,i);let l=pf(o,i);return{snapOffset:s,pointSnapLines:l}};var qx=200,xf=8,Kx=1,Qx=3,Zx=8,Jx=ae("#F68066"),yf=new Set(["WorkSpaceClipType","WorkSpaceSafeType","WorkSpaceMaskType","WorkSpaceLineType","WorkSpaceShadowType"]),ey="WorkSpaceDrawType",Pr=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)}),vf=(n,e)=>!(Pr(n).right<e.minX||Pr(n).left>e.maxX||Pr(n).bottom<e.minY||Pr(n).top>e.maxY),ty=n=>({x:(n.tl.x+n.br.x)/2,y:(n.tl.y+n.br.y)/2}),ms=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=Ze(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:ty(r.quad)},i=xf/this.host.zoom,{snapOffset:s,pointSnapLines:a,gapSnapLines:l}=bf(fs(o),Pr(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=Ze(r);if(!o||!this.scalingPoints.length)return;let s=(Ei(t)?[t]:[...dl]).map(c=>({x:o.quad[c].x,y:o.quad[c].y})),a=xf/this.host.zoom,{pointSnapLines:l}=gf(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=Kx/e,o=(i,s)=>t.push(Ce(i,s,r,Jx));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=Qx/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=Zx/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)||yf.has(l.id))continue;let c=this.nodeCoords(l);a&&!vf(c,a)||this.referenceCoords.push(c)}this.referencePoints=ff(this.referenceCoords),this.axisIndex=df(this.referencePoints),this.gapIndex=mf(this.referenceCoords.map(Pr))}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)||yf.has(s.id))continue;let a=this.nodeCoords(s);o&&!vf(a,o)||i.push(...fs(a))}this.scalingPoints=i}ensureWorkspaceInfo(){if(this.workspaceResolved)return;this.workspaceResolved=!0;let e=this.host.document.nodes.find(o=>o.id===ey);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=qx/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 Sf=n=>{let e=n?.animates;return Array.isArray(e)?e.filter(t=>!!t&&typeof t=="object"&&typeof t.key=="string"):[]},ny={width:0,height:0},be=(n,e={})=>({originX:"center",originY:"center",left:n.center.x,top:n.center.y,...e}),Bt=(n,e,t=ny,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}),ry=[{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})}],oy=[{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})}],iy=[{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})}],sy=[...ry,...oy,...iy],ec=new Map(sy.map(n=>[n.key,n])),ay=n=>ec.get(n),ps=n=>{let e=ec.get(n);return e?e.category==="entrance"?0:e.category==="emphasis"?1:2:Number.MAX_SAFE_INTEGER},wf=n=>ps(n)===1,ly=n=>{let e=n.duration??0;return!wf(n.key)||!n.single?e:Math.floor(e/n.single)*n.single},cy=n=>{let e=[...n].sort((r,o)=>{let i=ps(r.key)-ps(o.key);return i!==0?i:ps(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})},Tf=.2,Ef=(n,e)=>{let t=[];for(let s of n)for(let a of cy(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=ly(s.animate),h=c+Tf,d=h+u;r.push({target:s.target,animate:s.animate,definition:ec.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}},tc=(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;wf(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:Mf(l.key,h,d,u)})}),r},Mf=(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},uy=n=>1-Math.cos(Math.min(Math.max(n,0),1)*Math.PI/2),Cf=(n,e,t)=>{let r=ay(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:Tf,loopDuration:l,loopCount:a}},nc=(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:Mf(e.key,a,l,uy(s)),done:!1}},bs=n=>n.scrollSpeed?(n.textTotalWidth+n.viewWidth)/n.scrollSpeed:0,hy=(n,e,t)=>{if(e<=0)return 0;let r=Math.max(n,0);return t==="loop"?r%e:Math.min(r,e)},Rf=(n,e,t="loop")=>{if(!n.scrollEnabled)return 0;let r=bs(n);if(r<=0)return 0;let o=hy(e,r,t)/r,i=n.textTotalWidth+n.viewWidth;return n.scrollDirection==="left-to-right"?o*i:-o*i},vo=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")}},rc=(n,e)=>Math.max(n,...e,0);var Pf=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:ae(i),blur:t,offsetX:r,offsetY:o,nonScaling:!!e.nonScaling}},Ht=(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}},gs=n=>Math.ceil(n.blur*2+Math.max(Math.abs(n.offX),Math.abs(n.offY))+4),kf=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 qt=(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=Yn(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+dr(d,u,h)}),a+=Un(c,u,s)}return i},Kt=(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()},yn=(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 oc=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}},ic=(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&&Et(n,l,c,u,{fill:"keep"}),i){let h=qt(l,c,u,o,o.charSpacing??0);for(let d=0;d<h.length;d++){let f=yn(o,l.charStyles[d]);n.font=Me(f,f.fontSize),Kt(n,{...h[d],y:h[d].y+Tt(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=yn(o,d);n.font=Me(f,f.fontSize),n.fillText(l.graphemes[h],c+l.boxes[h].left,u+Tt(s,f.fontSize,a+h))}a+=l.graphemes.length}},xs=(n,e,t)=>{let r=e.dims.x,o=e.dims.y;if(e.isSolidType){n.fillStyle=t;let i=rt(e.raw,r,o);if(i){Wr(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(J(i)===L.ELLIPSE||J(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 re){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 re)?qo(e.raw,r,o):null;s&&(n.save(),Wr(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 xe){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}ic(n,e,t)}},Af=(n,e)=>{let t=Ht(e,n.raw.scaleX??1,n.raw.scaleY??1),r=gs(t)+(n.isTextType?Math.ceil((n.raw.fontSize??40)*.5):0),o=oc(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,xs(l,n,u),l.shadowColor="rgba(0,0,0,0)",l.shadowBlur=0,l.shadowOffsetX=0,l.shadowOffsetY=0,l.globalCompositeOperation="destination-out",xs(l,n,u),{canvas:a,w:i,h:s}};var sc=(n,e,t)=>{let r=e+t,o=n,i=new Array(e*t).fill(0);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,g)=>Math.floor((m*m-f*f+g*g-p*p)/(2*(m-f))),l=new Array(e*t).fill(0),c=new Array(e).fill(0),u=new Array(e).fill(0),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},Nf=(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 Lf={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]},de=(n,e)=>typeof n=="number"&&Number.isFinite(n)?n:e,vn=(n,e)=>typeof n=="string"&&n?n:e,ac=(n,e)=>typeof n=="boolean"?n:e;function dy(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(fy(r,s))})}return o}function fy(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 my(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 dy(e))t.push(r.input,r.output);return t}function So(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?de(r.brightness,0)/100:de(r.brightness,0)});break;case"Contrast":e.push({kind:"Contrast",contrast:o?de(r.contrast,0)/100:de(r.contrast,0)});break;case"Saturation":e.push({kind:"Saturation",saturation:o?de(r.saturation,0)/100:de(r.saturation,0)});break;case"Vibrance":e.push({kind:"Vibrance",vibrance:o?de(r.vibrance,0)/100:de(r.vibrance,0)});break;case"HueRotation":e.push({kind:"HueRotation",rotation:o?de(r.hue,0)/100:de(r.rotation,0)});break;case"Grayscale":{let i=vn(r.mode,"average");e.push({kind:"Grayscale",mode:i==="lightness"||i==="luminosity"?i:"average"});break}case"Invert":e.push({kind:"Invert",invert:ac(r.invert,!0),alphaOnly:ac(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:de(o?r.radius:r.blur,0)});break;case"Noise":e.push({kind:"Noise",noise:de(r.noise,0)});break;case"Pixelate":e.push({kind:"Pixelate",blocksize:de(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:ac(r.opaque,!1)});break}case"BlendColor":{let i=vn(r.mode,"multiply"),s=["multiply","screen","add","difference","subtract","darken","lighten","overlay","exclusion","tint"];e.push({kind:"BlendColor",color:vn(r.color,"#000000"),mode:s.includes(i)?i:"multiply",alpha:de(r.alpha,1)});break}case"Vignette":e.push({kind:"Vignette",intensity:de(r.intensity,0)});break;case"Temperature":{if(o){let i=Sn(vn(r.color,"#ffb86b")),s=i[0]>=i[2];e.push({kind:"Temperature",temperature:de(r.density,0)/100*(s?1:-1)})}else e.push({kind:"Temperature",temperature:de(r.temperature,0)});break}case"Posterize":e.push({kind:"Posterize",levels:de(r.levels,20)});break;case"FilmGrain":e.push({kind:"FilmGrain",intensity:de(r.intensity,0),seed:de(r.seed,0)});break;case"Duotone":e.push({kind:"Duotone",color1:vn(r.color1,"#000000"),color2:vn(r.color2,"#ffffff")});break;case"Sketch":e.push({kind:"Sketch"});break;case"ChromaticAberration":e.push({kind:"ChromaticAberration",offset:de(r.offset,4)});break;case"SoftFocus":e.push({kind:"SoftFocus",blend:de(r.blend,.5)});break;case"Threshold":e.push({kind:"Threshold",threshold:de(r.threshold,128)});break;case"UnsharpMask":e.push({kind:"UnsharpMask",amount:o?de(r.amount,100)/100:de(r.amount,1)});break;case"MotionBlur":e.push({kind:"MotionBlur",distance:de(r.distance,0),angle:de(r.angle,0)});break;case"LensFlare":e.push({kind:"LensFlare",intensity:de(r.intensity,.8)});break;case"GradientMap":e.push({kind:"GradientMap",color0:vn(r.color0,"#000000"),color1:vn(r.color1,"#888888"),color2:typeof r.color2=="string"&&r.color2?r.color2:""});break;case"Levels":e.push({kind:"Levels",blackPoint:de(r.blackPoint,0),whitePoint:de(r.whitePoint,255),gamma:de(r.gamma,1)});break;case"Curves":e.push({kind:"Curves",points:my(r.points)});break;case"SurfaceBlur":e.push({kind:"SurfaceBlur",radius:de(r.radius,3),threshold:o?de(r.threshold,51)/255:de(r.threshold,.2)});break;case"Exposure":e.push({kind:"Exposure",exposure:de(r.exposure,0),offset:de(r.offset,0),gamma:de(r.gamma,1)});break;default:break}}return e}function nr(n){return JSON.stringify(n)}var IE=Math.PI/2;function Sn(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 ys=(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)},py=6e5,vs=n=>Math.max(1,Math.floor(Math.sqrt(py/Math.max(1,n.dims.x*n.dims.y)))),Ss=n=>{if(!n.isImageType||n instanceof re)return"";let e=So(n.raw.filters);return e.length?`|f${nr(e)}`:""},by=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}},If=n=>({color:n.color,rgba:n.rgba,blur:n.blur,offsetX:n.offsetX,offsetY:n.offsetY,nonScaling:!1}),wo=(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),ic(i,n,"#ffffff"),o):null},ws=(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 x of e){let y=Ht(If(x),i,s);a=Math.max(a,Math.ceil(y.blur*2+Math.max(Math.abs(y.offX),Math.abs(y.offY))+4))}let l=by(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=document.createElement("canvas");f.width=h,f.height=d;let m=f.getContext("2d");if(!m)return null;let p=n.matrix;m.setTransform(p[0]*r,p[1]*r,p[2]*r,p[3]*r,h/2,d/2);let g=n.dims.x,b=n.dims.y;for(let x of e){let y=Ht(If(x),i,s);m.filter=`drop-shadow(${y.offX*r}px ${y.offY*r}px ${y.blur*r}px ${x.color})`,ys(m,t,o,-g/2,-b/2,g,b)}return m.filter="none",m.globalCompositeOperation="destination-out",ys(m,t,o,-g/2,-b/2,g,b),{canvas:f,w:h,h:d,quadW:c,quadH:u}},gy=(n,e,t)=>{let r=[1,0,0,1,n.offsetX,n.offsetY];return n.gradientUnits==="percentage"&&(r=Y(r,[e,0,0,t,0,0])),n.gradientTransform&&(r=Y(r,n.gradientTransform)),r},kr=(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 h=e.decl,d=gy(h,a,l);u.setTransform(d[0],d[1],d[2],d[3],d[4],d[5]);let f=h.kind==="linear"?u.createLinearGradient(h.x1,h.y1,h.x2,h.y2):u.createRadialGradient(h.x1,h.y1,h.r1,h.x2,h.y2,h.r2);for(let m of h.stops){let p=Math.min(1,Math.max(0,m.offset));f.addColorStop(p,`rgba(${Math.round(m.color[0]*255)}, ${Math.round(m.color[1]*255)}, ${Math.round(m.color[2]*255)}, ${m.color[3]})`)}if(u.fillStyle=f,h.gradientUnits==="percentage")u.fillRect(-2,-2,5,5);else{let m=Te(d),p=[V(m,0,0),V(m,a,0),V(m,0,l),V(m,a,l)];if(p.every(g=>isFinite(g.x)&&isFinite(g.y))){let g=Math.min(...p.map(S=>S.x))-2,b=Math.max(...p.map(S=>S.x))+2,x=Math.min(...p.map(S=>S.y))-2,y=Math.max(...p.map(S=>S.y))+2;u.fillRect(g,x,b-g,y-x)}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);return u.globalCompositeOperation="destination-in",ys(u,t,o,0,0,a,l),c},_f=(n,e)=>{if(e.length===0)return null;let t=n.raw.fill;if(typeof t!="string"||!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=Xr(n,c),!Xn(c,n))return null;c.fill()}return c.filter="none",{canvas:l,w:s,h:a,quadW:s,quadH:a}},wn=(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[];ys(h,t,i,(l-n.dims.x*a)/2,(c-n.dims.y*a)/2,n.dims.x*a,n.dims.y*a);let d=[];for(let f=e.length-1;f>=0;f--){let m=e[f],p=m.width,g=m.alignment,b=g==="outside"?p:g==="center"?Math.ceil(p/2):0,x=b*a,y=Math.floor(l+x*2),S=Math.floor(c+x*2);if(y<=0||S<=0)continue;let v=document.createElement("canvas");v.width=y,v.height=S;let M=v.getContext("2d",{willReadFrequently:!0});if(!M)continue;M.drawImage(u,x,x);let C=Nf(M.getImageData(0,0,y,S).data),R=sc(C,y,S),w=new Uint8Array(C.length);for(let G=0;G<C.length;G++)w[G]=C[G]?0:1;for(let G=0;G<y;G++)w[G]=1,w[G+(S-1)*y]=1;for(let G=0;G<S;G++)w[G*y]=1,w[y-1+G*y]=1;let T=sc(w,y,S),E=y*S,P=new Int32Array(E);for(let G=0;G<E;G++)P[G]=C[G]?-T[G]:R[G];let A=s?.5*a:0,k,O;g==="inside"?(k=-p*a-A,O=A):g==="center"?(k=-p/2*a-A,O=p/2*a+A):(k=-A,O=p*a+A);let F=Math.round(m.rgba[0]*255),W=Math.round(m.rgba[1]*255),X=Math.round(m.rgba[2]*255),_=Math.round(m.rgba[3]*255),D=document.createElement("canvas");D.width=y,D.height=S;let I=D.getContext("2d");if(!I)continue;let H=I.createImageData(y,S),z=H.data;for(let G=0;G<E;G++){let Z=P[G];if(Z>=k&&Z<O){let B=G*4;z[B]=F,z[B+1]=W,z[B+2]=X,z[B+3]=_}}I.putImageData(H,0,0);let U=document.createElement("canvas");U.width=y,U.height=S;let $=U.getContext("2d");if(!$)continue;r&&$.drawImage(u,x,x),$.drawImage(D,0,0);let K=g==="outside"?p:g==="center"?p/2:0;d.push({canvas:U,w:y,h:S,quadW:y/a,quadH:S/a,dx:b-K+m.offset.x,dy:b-K+m.offset.y})}return d};var Df=n=>{if(!(Number(n.warpStrength)||0))return null;let t=J(n);return t===L.ARCHTEXT?"arch":t===L.WAISTTEXT?"waist":t===L.FLAGTEXT?"flag":null},st=2,To=(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?Et(n,i,s,a,{fill:c,stroke:Fe(o,l)}):0,d="",f="",m=null,p=g=>{if(!u)return;n.font=d;let b=s+h;typeof f=="string"&&f?(n.fillStyle=f,n.fillText(u,b,a)):typeof e.raw.fill=="string"&&e.raw.fill&&(n.fillStyle=e.raw.fill,n.fillText(u,b,a)),m&&m.width>0&&(n.lineWidth=m.width,n.strokeStyle=m.color,n.strokeText(u,b,a)),u="",g<i.boxes.length&&(h=i.boxes[g].left)};for(let g=0;g<i.graphemes.length;g++){let b=i.charStyles[g],y=b!==void 0&&(b.fontSize!==void 0||b.fontFamily!==void 0||b.fontWeight!==void 0||b.fontStyle!==void 0)&&b?{...r,fontSize:b.fontSize??r.fontSize,fontFamily:b.fontFamily??r.fontFamily,fontWeight:b.fontWeight??r.fontWeight,fontStyle:b.fontStyle??r.fontStyle}:r,S=Me(y,y.fontSize),v=Fe(o,b),M=typeof b?.fill=="string"?b.fill:"",C=m;u&&(S!==d||v?.color!==C?.color||v?.width!==C?.width||M!==f)&&p(g),u||(d=S,m=v,f=M),u+=i.graphemes[g]}p(i.graphemes.length)}},Ar=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},lc=(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}},Eo=(n,e,t)=>{if(!t||t.dropShadows.length===0&&t.solidFills.length===0&&t.strokes.length===0)return;let r=wo(e,st);if(!r)return;let o=e.dims.x,i=e.dims.y;if(t.dropShadows.length){let s=lc(t.dropShadows,r,st);s&&(n.save(),n.globalCompositeOperation="destination-over",n.drawImage(s.canvas,-s.w/2,-s.h/2,s.w,s.h),n.restore())}for(let s of t.solidFills){let a=kr(e,s,r,st);a&&n.drawImage(a,-o/2+s.offset.x,-i/2+s.offset.y,o,i)}for(let s of wn(e,t.strokes,r,!1,Math.min(2,st),null,!0))n.drawImage(s.canvas,-s.quadW/2+s.dx,-s.quadH/2+s.dy,s.quadW,s.quadH)},cc=(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?Ar(t):0,p=Math.ceil(c+l*2+m*2),g=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),b=p*st,x=g*st;if(!(b>0)||!(x>0)||b>8192||x>8192)return null;let y=document.createElement("canvas");y.width=b,y.height=x;let S=y.getContext("2d",{willReadFrequently:!0});if(!S)return null;let v=e==="arch"?h/2*st:0;S.setTransform(st,0,0,st,b/2,x/2+v),To(S,n),Eo(S,n,t);let M=S.getImageData(0,0,b,x),C=new Uint32Array(M.data.buffer),R=b,w=0,T=x,E=0,P=!1;for(let _=0;_<x;_++)for(let D=0;D<b;D++)(C[_*b+D]>>>24&255)>10&&(P=!0,D<R&&(R=D),D>w&&(w=D),_<T&&(T=_),_>E&&(E=_));let A=P?(R+w)/2:b/2,k=P?E:x-1,O=P?Math.max(1,w-R)/2:b/2,F=S.createImageData(b,x),W=new Uint32Array(F.data.buffer),X=(_,D)=>{let I=Math.floor(D),H=I+1;if(I<0||H>=x)return 0;let z=D-I,U=C[I*b+_],$=C[H*b+_],K=U>>>24&255,G=$>>>24&255;if(K<=10&&G<=10)return 0;let Z=Math.round((U&255)*(1-z)+($&255)*z),B=Math.round((U>>>8&255)*(1-z)+($>>>8&255)*z),j=Math.round((U>>>16&255)*(1-z)+($>>>16&255)*z);return Math.round(K*(1-z)+G*z)<<24|j<<16|B<<8|Z};if(e==="flag")for(let _=0;_<b;_++){let D=O>0?(_-A)/O:0,I=Math.sin(D*Math.PI)*d*st*i;for(let H=0;H<x;H++)W[H*b+_]=X(_,H+I)}else if(e==="arch")for(let _=0;_<b;_++){let D=Math.max(-1,Math.min(1,(_-A)/O)),I=Math.sqrt(Math.max(0,1-D*D)),H=I*I*(3-2*I),z=i>0?Math.pow(H,2.5):H,U=Math.min(1+Math.max(0,i),Math.max(.05,1+i*z));for(let $=0;$<=k;$++){let K=k-$;W[$*b+_]=X(_,k-K/U)}}else{let _=P?(T+E)/2:x/2;for(let D=0;D<b;D++){let I=O>0?(D-A)/O:0,H=1+i*(I*I-.5);H=Math.min(1+Math.abs(i),Math.max(.4,H));for(let z=0;z<x;z++)W[z*b+D]=X(D,_+(z-_)/H)}}return S.setTransform(1,0,0,1,0,0),S.clearRect(0,0,b,x),S.putImageData(F,0,0),{canvas:y,logicalW:p,logicalH:g}},Ts=(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&&Et(n,l,c,u,{fill:d,stroke:Fe(o,h)});let f=qt(l,c,u,r,r.charSpacing??0);for(let m=0;m<f.length;m++){let p=l.charStyles[m],g=yn(r,p);n.font=Me(g,g.fontSize);let b=typeof p?.fill=="string"&&p.fill?p.fill:i,x=Fe(o,p),y={...f[m],y:f[m].y+Tt(s,g.fontSize,a+m)};b&&(n.fillStyle=b,Kt(n,y,"fillText")),x&&x.width>0&&(n.lineWidth=x.width,n.strokeStyle=x.color,Kt(n,y,"strokeText"))}a+=l.graphemes.length}},xy=(n,e)=>{let t=e?Ar(e):0,r=Math.ceil(n.dims.x+t*2),o=Math.ceil(n.dims.y+t*2),i=r*st,s=o*st;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(st,0,0,st,i/2,s/2),n.raw.vertical===!0?Ts(l,n):To(l,n),Eo(l,n,e),{canvas:a,logicalW:r,logicalH:o}):null};var Of=2,Tn=(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,Bf=(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=Tn(o,u),d=r==="silhouette"?"#ffffff":typeof u?.fill=="string"&&u.fill?u.fill:l,f=r==="silhouette"?null:s?Fe(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))},g=()=>{f&&f.width>0&&(n.lineWidth=f.width,n.strokeStyle=f.color,n.strokeText(c.char,0,0))};a?(g(),p()):(p(),g()),n.restore()}},Ff=(n,e,t=Of)=>{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",Bf(s,n,e,"silhouette"),i):null},yy=(n,e,t,r,o)=>{if(r.dropShadows.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;if(r.dropShadows.length||r.solidFills.length){let c=Ff(e,t,o);if(c){if(r.dropShadows.length){let u=lc(r.dropShadows,c,o);u&&(n.save(),n.globalCompositeOperation="destination-over",n.drawImage(u.canvas,a-u.w/2,l-u.h/2,u.w,u.h),n.restore())}for(let u of r.solidFills){let h=kr(e,u,c,o);h&&n.drawImage(h,a-i/2+u.offset.x,l-s/2+u.offset.y,i,s)}}}if(r.strokes.length){let c=Math.min(Math.max(2,o),vs(e)),u=Ff(e,t,c);if(u)for(let h of wn(e,r.strokes,u,!1,c,null,!0))n.drawImage(h.canvas,a-h.quadW/2+h.dx,l-h.quadH/2+h.dy,h.quadW,h.quadH)}},uc=(n,e,t=null,r=Of)=>{let o=Mt(n.textLayout,n.raw,n.textStyle.lineHeight??1.16),i=t?Ar(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",Bf(h,n,o,"render"),t&&yy(h,n,o,t,r),{canvas:u,logicalW:s,logicalH:a}):null};var Es=n=>{let e=n.type;if(e!=="ScrollText"&&e!=="scrollText")return null;let t=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:t,enabled:n.scrollEnabled===void 0?!0:n.scrollEnabled===!0}},vy=(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}},Hf=n=>{let e=Es(n.raw);return e?{target:n,viewWidth:n.dims.x,textTotalWidth:n.textTotalWidth,scrollSpeed:e.speed,scrollDirection:e.direction,scrollEnabled:e.enabled}:null},Sy=n=>`rgba(${Math.round(n.color[0]*255)},${Math.round(n.color[1]*255)},${Math.round(n.color[2]*255)},${n.color[3]})`,Wf=(n,e,t)=>{let r=Es(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}=vy(r,o,h,t);for(let m of[d,f])u.save(),u.translate(m,0),wy(u,n),u.restore();return{canvas:c,logicalW:o,logicalH:i}},wy=(n,e)=>{let t=e.paintFirst==="stroke"?["stroke","fill"]:["fill","stroke"];for(let r of t)Ty(n,e,r)},Ty=(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?Sy(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,g=f.prefix?.width??0;if(f.prefix){let b=f.charStyles[0];if(t==="fill"){let x=typeof b?.fill=="string"&&b.fill?b.fill:l;x&&Et(n,f,m,p,{fill:x})}else Et(n,f,m,p,{stroke:Fe(i,b)})}if(c){let b=qt(f,m,p,o,u);for(let x=0;x<b.length;x++){let y=f.charStyles[x];if(t==="fill"){let v=typeof y?.fill=="string"&&y.fill?y.fill:l;if(!v)continue;n.fillStyle=v}else{let v=Fe(i,y);if(!v||v.width<=0)continue;d(v)}let S=Tn(o,y);n.font=Me(S,S.fontSize),Kt(n,b[x],t==="fill"?"fillText":"strokeText")}continue}if(h&&h.length){let b="",x=g,y="",S=null,v,M=T=>{if(!b)return;let E=S;E&&E.width>0&&(n.font=y,d(E),n.strokeText(b,m+x,p)),b="",T<f.boxes.length&&(x=f.boxes[T].left)},C=Ut(s.textAlign),R=s.textAlign===pe.DISPERSE,w=Yr(s.textAlign)&&f.graphemes.some(T=>jr.test(T));for(let T=0;T<f.graphemes.length;T++){let E=f.charStyles[T],P=Tn(o,E),A=Me(P,P.fontSize),k=Fe(i,E),O=E?.fill??"",F=S;b&&(A!==y||k?.color!==F?.color||k?.width!==F?.width||O!==v)&&M(T),b||(y=A,S=k,v=O),b+=f.graphemes[T],(u||(C||R)&&/[ \t\r]/.test(f.graphemes[T])||w)&&M(T+1)}M(f.graphemes.length);continue}for(let b=0;b<f.graphemes.length;b++){let x=f.charStyles[b];if(t==="fill"){let v=typeof x?.fill=="string"&&x.fill?x.fill:l;if(!v)continue;n.fillStyle=v}else{let v=Fe(i,x);if(!v||v.width<=0)continue;d(v)}let y=Tn(o,x);n.font=Me(y,y.fontSize);let S=m+f.boxes[b].left;t==="fill"?n.fillText(f.graphemes[b],S,p):n.strokeText(f.graphemes[b],S,p)}}};var Ms=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=rc(this.playback?.duration??0,e),this.player?this.player.retargetDuration(this.totalDuration):this.player=new vo(this.totalDuration),this.player.play(performance.now());for(let t of this.host.document.nodes)t instanceof re?t.play():t instanceof le&&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 re?e.pause():e instanceof le&&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 re?e.stop():e instanceof le&&e.syncClipMediaToTime(0,!1);this.host.requestRenderAll()}seek(e){if(this.cancelPreviews(),!this.player){this.rebuild();let t=[...this.collectMediaDurations(),...this.collectScrollTextDurations()];this.totalDuration=rc(this.playback?.duration??0,t),this.player=new vo(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=Cf(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=nc(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=nc(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:bs(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 tc(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 tc(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=Sf(t.raw);r.length&&e.push({target:t,view:this.targetView(t),animates:r})}this.playback=Ef(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===_t)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 xe))continue;let r=Hf(t);r&&e.push({node:t,input:r})}return e}collectScrollTextDurations(){return this.scrollTextTracks().map(({input:e})=>e.scrollEnabled?bs(e):0)}applyScrollTextOffsets(e){for(let{node:t,input:r}of this.scrollTextTracks())t.setScrollOffset(Rf(r,e,"loop"))}collectMediaDurations(){let e=[],t=r=>{for(let o of r)o instanceof re?e.push(o.mediaDuration):o instanceof le?o.clipMediaDuration>0&&e.push(o.clipMediaDuration):o instanceof ee&&t(o.children)};return t(this.host.document.nodes),e}syncVideosToTime(e,t){let r=o=>{for(let i of o)i instanceof re?i.syncVideoToTime(e,t):i instanceof le?i.syncClipMediaToTime(e,t):i instanceof ee&&r(i.children)};r(this.host.document.nodes)}};var Gf=14,Xf=n=>n.fontFamily||"仓耳小丸子",Cs=class{host;session=null;docBus;disposed=!1;constructor(e){this.host=e,this.docBus=new kt(e.document.events,t=>{let r=[t.on("text:changed",o=>this.onTextChanged(o)),t.on("text:editing:exited",()=>this.finish()),t.on("object:removed",o=>this.onOverlayRemoved(o))];return()=>r.forEach(o=>o())})}retargetDoc(e){this.docBus.retarget(e.events)}dispose(){this.disposed||(this.disposed=!0,this.docBus.dispose())}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=Se(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??Gf,fontWeight:h?.fontWeight,fontStyle:h?.fontStyle,fontFamily:h?.fontFamily||Xf(c),textAlign:h?.textAlign??pe.CENTER,lineHeight:1.16,splitByGrapheme:!0,opacity:1,visible:!0},m=new xe(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:Gf,fontWeight:"normal",fontStyle:"normal",fontFamily:Xf(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 Ey=530,zf=[.1,.1,.1,1],My=[.18,.44,.96,.3],Rs=class{host;textarea=null;blinkTimer=null;caretVisible=!0;onSelectionChange=null;docBus;inComposition=!1;compositionRange=null;constructor(e){this.host=e,this.docBus=new kt(e.document.events,t=>{let r=[t.on("text:changed",()=>{this.positionAtCaret(),this.host.requestRenderAll()}),t.on("text:editing:entered",()=>this.startUi()),t.on("text:editing:exited",()=>this.stopUi())];return()=>r.forEach(o=>o())})}retargetDoc(e){this.docBus.retarget(e.events)}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)),g=m+(f<h?c.boxes[f-u].left:ln(c));if(g>p){let b=e.contentTopY+c.top;l.push({matrix:Y(s,[1,0,0,1,(p+g)/2,b+c.implHeight/2]),dims:{x:g-p,y:c.implHeight},color:My})}}}if(o===i&&this.caretVisible&&!this.inComposition){let c=e.cursorCoord(o);if(c){let u=2/this.host.zoom/a;l.push({matrix:Y(s,[1,0,0,1,c.x+u/2,c.y+c.height/2]),dims:{x:u,y:c.height},color:zf})}}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)),b=e.contentTopY+h.baseline+e.textStyle.fontSize*.14;l.push({matrix:Y(s,[1,0,0,1,(m+p)/2,b]),dims:{x:Math.max(0,p-m),y:1.5/this.host.zoom/a},color:zf})}}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()},Ey),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 g=0;g<r.lines.length;g++){let b=r.lines[g].styleMap.flatStart;if(p<=b+r.lines[g].graphemes.length)return g}return r.lines.length-1},h=(p,g)=>{let b=r.lines[p],x=g-b.styleMap.flatStart;return-r.width/2+b.leftOffset+(x<b.boxes.length?b.boxes[x].left:ln(b))},d=(p,g)=>{let b=r.lines[p],x=-r.width/2+b.leftOffset;for(let y=0;y<b.boxes.length;y++)if(g<x+b.boxes[y].left+b.boxes[y].width/2)return b.styleMap.flatStart+y;return b.styleMap.flatStart+b.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),g=e.key==="ArrowUp"?p-1:p+1;if(g<0||g>=r.lines.length)return null;f=d(g,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.docBus.dispose(),this.onSelectionChange&&document.removeEventListener("selectionchange",this.onSelectionChange),this.blinkTimer!==null&&window.clearInterval(this.blinkTimer),this.textarea?.remove(),this.textarea=null}};var Yf=(n,e={})=>{let t=n.getContext("webgl2",{alpha:!0,premultipliedAlpha:!0,antialias:!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 Ps=n=>n.trim().replace(/^['"]|['"]$/g,"").toLowerCase(),Uf=n=>{let e=new Set;for(let t of n){let r=Ps(t?.family??"");r&&e.add(r)}return e},Cy=n=>{let e=new Set,t=o=>{if(!(typeof o!="string"||!o))for(let i of o.split(",")){let s=Ps(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},$f=(n,e)=>{let t=[],r=o=>{for(let i of o)if(i instanceof xe){for(let s of Cy(i))if(e.has(s)){t.push(i);break}}else i instanceof ee&&r(i.children)};return r(n),t};var ks=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=Uf(e);t.size===0||!this.invalidateTextCachesFor(t)||(this.glyphAtlas.reset(),this.host.requestRenderAll(),this.host.render())}invalidateTextCachesFor(e){let t=this.host.documentNodes?this.host.documentNodes():[this.host.document],r=[];for(let o of t)r=r.concat($f(o.nodes,e));if(r.length===0)return!1;for(let o of r)o.invalidateTextLayout(),this.textRenderer.invalidateNodeBakes(o);return Bu(),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 En=class{_value=0;_lastReason="";get value(){return this._value}get lastReason(){return this._lastReason}bump(e){this._value++,this._lastReason=e}};var pt=1024,Ry=2,Py=256,Qt=n=>{let e=[.5,1,2,4];for(let t of e)if(n<=t+1e-6)return t;return e[e.length-1]},ky=256,Ns=(n,e)=>{let t=Math.max(6,Math.ceil(n*e)),r=Math.max(ky,Math.ceil(n));return t<=r?{rs:t,scale:e}:{rs:r,scale:r/Math.max(1,n)}},As=class{gl;pages=[];cells=new Map;tmpCanvas;disposed=!1;pageCap=12;pendingReset=!1;_generation=0;provisionalCells=new Map;onCellsInvalidated;onProvisionalSettled;detachFontsListener=null;epoch;constructor(e,t,r,o=new En){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(",")||$a.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){let t=this.fontSet();if(!(!t||typeof t.load!="function"))try{t.load(e).catch(()=>{})}catch{}}dropProvisionalCells(){if(!(this.disposed||this.provisionalCells.size===0)){for(let e of this.provisionalCells.keys())this.cells.delete(e);this.provisionalCells.clear(),this.onCellsInvalidated?.()}}markFrame(){this.pendingReset&&(this.pendingReset=!1,this.reset()),this.settleProvisionalCells()}settleProvisionalCells(){if(this.disposed||this.provisionalCells.size===0)return;let e=!1,t=new Set;for(let[r,o]of this.provisionalCells){let i=Me(o.style,o.rasterSize);if(!this.isFacePending(i,o.style)){this.cells.delete(r),this.provisionalCells.delete(r),e=!0;let s=Ps(o.style.fontFamily??"");s&&t.add(s)}}e&&(this.onCellsInvalidated?.(),t.size>0&&this.onProvisionalSettled?.([...t]))}reset(){let e=this.pages.length>0;if(!this.disposed&&e)for(let t of this.pages)this.gl.deleteTexture(t.texture);this.pages.length=0,this.cells.clear(),this.provisionalCells.clear(),e&&(this._generation++,this.epoch.bump("atlas-reset"),Bn()&&console.warn("[retained] GlyphAtlas.reset → generation",this._generation,new Error("reset 调用栈取证").stack))}get generation(){return this._generation}stats(){return{pages:this.pages.length,cells:this.cells.size,pageCap:this.pageCap,pendingReset:this.pendingReset,generation:this._generation}}get(e,t,r,o=null){if(this.disposed||r===" "||r===""||r===`
7
- `||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 s;let a=Me(e,t),l=this.isFacePending(a,e);l&&this.kickFaceLoad(a);let c=this.rasterize(e,t,r,o);return c&&(this.cells.set(i,c),l&&this.provisionalCells.set(i,{style:{fontFamily:e.fontFamily,fontSize:e.fontSize,fontWeight:e.fontWeight,fontStyle:e.fontStyle},rasterSize:t})),c}rasterize(e,t,r,o){let i=this.pages[this.pages.length-1];i||(i=this.newPage());let s=this.pages.length-1,a=i.ctx;a.font=Me(e,t),a.textBaseline="alphabetic",a.textAlign="left",a.fillStyle="#ffffff";let l=a.measureText(r);if(!isFinite(l.width)||l.width<=0&&r.trim()==="")return null;let c=l.actualBoundingBoxLeft??0,u=l.actualBoundingBoxRight??l.width,h=l.actualBoundingBoxAscent??t*.88,d=l.actualBoundingBoxDescent??t*.24,f=t/Math.max(1,e.fontSize),m=o?Math.max(.5,o.width*f):0,p=o?Math.min(m*Math.max(1,o.miterLimit??4)/2,Py):0,g=Ry+(o?Math.ceil(p)+1:0),b=Math.max(1,Math.ceil(c+u)+g*2),x=Math.max(1,Math.ceil(h+d)+g*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(),s=this.pages.length-1);let y=i.ctx;y.font=Me(e,t),y.textBaseline="alphabetic",y.textAlign="left",y.fillStyle="#ffffff";let S=i.cursorX,v=i.cursorY,M=S+g+c,C=v+g+h;y.save(),o?(y.lineWidth=m,y.lineJoin=o.lineJoin??"miter",y.lineCap=o.lineCap??"butt",y.miterLimit=Math.max(1,o.miterLimit??4),y.strokeStyle="#ffffff",y.strokeText(r,M,C)):y.fillText(r,M,C),y.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,S,v,b,x,0,0,b,x),this.gl.bindTexture(this.gl.TEXTURE_2D,i.texture),this.gl.texSubImage2D(this.gl.TEXTURE_2D,0,S,v,b,x,this.gl.RGBA,this.gl.UNSIGNED_BYTE,this.tmpCanvas),i.cursorX+=b,i.rowHeight=Math.max(i.rowHeight,x),{pageIndex:s,u0:S/pt,v0:v/pt,u1:(S+b)/pt,v1:(v+x)/pt,wPx:b,hPx:x,inkLeftPx:-c,ascentPx:h,padPx:g,advancePx:l.width}}textureOf(e){return this.pages[e.pageIndex]?.texture??null}newPage(){this.pages.length>=this.pageCap&&(this.pendingReset=!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={canvas:e,ctx:t,texture:r,cursorX:0,cursorY:0,rowHeight:0};return this.pages.push(o),o}dispose(){if(!this.disposed){this.disposed=!0,this.detachFontsListener?.(),this.detachFontsListener=null;for(let e of this.pages)this.gl.deleteTexture(e.texture);this.pages.length=0,this.cells.clear(),this.provisionalCells.clear()}}};var Nr=(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)},Ls=class{gl;cache=new Map;disposed=!1;constructor(e){this.gl=e}get(e){if(this.disposed)return null;let t=uu(e),r=this.cache.get(t);if(r)return r;let o=this.gl,i=o.createTexture();if(!i)return null;let s=cu(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 Ay=512*1024*1024,Ny=2048,Ly=30,Iy=32*1024*1024,Is=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??Ay,this.maxEntries=t.maxEntries??Ny,this.evictGraceFrames=t.evictGraceFrames??Ly,this.epoch=t.epoch??new En}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=_y(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>=Iy))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())}},_y=(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 Vf=`#version 300 es
1
+ var _e={enabled:!1,metrics:new Map,counters:new Map,sampleRate:1,reportIntervalMs:5e3,reportTimer:null},tu=()=>performance.now(),Xp=()=>typeof window>"u"?!1:window.location.search.includes("canvasPerf=1"),zp=n=>{let e=_e.metrics.get(n);return e||(e={count:0,total:0,max:0,last:0},_e.metrics.set(n,e)),e},Yp=(n,e)=>e>0?n/e:0,Ma=()=>[..._e.metrics.entries()].map(([n,e])=>({name:n,count:e.count,totalMs:Number(e.total.toFixed(2)),avgMs:Number(Yp(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),Ca=()=>[..._e.counters.entries()].map(([n,e])=>({name:n,count:e})).sort((n,e)=>e.count-n.count),Up=()=>({type:"canvas-perf",timestamp:new Date().toISOString(),enabled:_e.enabled,metrics:Ma(),counters:Ca()}),nu=()=>JSON.stringify(Up()),$p=()=>{let n=Ma(),e=Ca(),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
+ `)},ru=()=>{let n=nu();if(!_e.enabled)return n;let e=Ma(),t=Ca();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},Vp=()=>{typeof window>"u"||!_e.enabled||_e.reportTimer!=null||(_e.reportTimer=window.setInterval(ru,_e.reportIntervalMs))},jp=()=>{_e.reportTimer!=null&&(window.clearInterval(_e.reportTimer),_e.reportTimer=null)},Ea=n=>{_e.enabled=n,n?(Vp(),console.info("[canvas-perf] enabled")):(jp(),console.info("[canvas-perf] disabled"))},ou=()=>_e.enabled,qp=()=>{_e.metrics.clear(),_e.counters.clear()},iu=(n,e=1)=>{_e.enabled&&_e.counters.set(n,(_e.counters.get(n)||0)+e)},Ho=(n,e)=>{if(!_e.enabled)return;let t=zp(n);t.count+=1,t.total+=e,t.max=Math.max(t.max,e),t.last=e},Ra=(n,e)=>{if(!_e.enabled)return e();let t=tu();try{return e()}finally{Ho(n,tu()-t)}};var su=()=>{typeof window>"u"||window.__YFT_CANVAS_PERF__||(window.__YFT_CANVAS_PERF__={enable:()=>Ea(!0),disable:()=>Ea(!1),report:ru,reportJson:nu,reportText:$p,reset:qp,mark:iu,time:Ra,isEnabled:ou},Xp()&&Ea(!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()}},kt=class{constructor(e,t){this.subscribe=t;this.current=e,this.off=t(e)}subscribe;off;current;retarget(e){e!==this.current&&(this.off(),this.current=e,this.off=this.subscribe(e))}dispose(){this.off()}};var ur=n=>n*Math.PI/180,Y=(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]],Te=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},V=(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])}),Kp=n=>n[0]===1&&n[1]===0&&n[2]===0&&n[3]===1&&n[4]===0&&n[5]===0,Wo=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}},Qp=n=>{let e=ur(n),t=Math.cos(e),r=Math.sin(e);return[t,r,-r,t,0,0]},au=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=Y(a,[1,0,Math.tan(ur(i)),1,0,0],!0)),s&&(a=Y(a,[1,Math.tan(ur(s)),0,1,0,0],!0)),a},At=n=>{let{translateX:e=0,translateY:t=0,angle:r=0}=n,o=[1,0,0,1,e,t];r&&(o=Y(o,Qp(r)));let i=au(n);return Kp(i)||(o=Y(o,i)),o},Zp=(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=V(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)}},Go=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=Zp(h,d,au(n)),{x:f.x+u,y:f.y+u}},Bn=n=>{let e=Yt(n);return At({...n,translateX:e.x,translateY:e.y})},Yt=n=>{let e=Go(n),t=-Wo(n.originX??"left")*e.x,r=-Wo(n.originY??"top")*e.y,o=n.angle??0;if(o){let i=ur(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=Go(n),r=-Wo(n.originX??"left")*t.x,o=-Wo(n.originY??"top")*t.y,i=n.angle??0;if(i){let s=ur(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}},Jp=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]}}},Pa=n=>{let e=Yt(n),t=ur(n.angle??0),r=Math.cos(t),o=Math.sin(t),i=Go(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)}},ka=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}},Nt=(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 Y(s,Y([r,0,0,r,0,0],n))};var dt=(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},lu=()=>dt("gpuShadow",!0),Aa=()=>dt("gpuPsdShadow",!0),Na=()=>dt("gpuPsdFill",!0),cu=()=>dt("gpuClipMask"),La=()=>{if(typeof window>"u")return!0;let n=new URLSearchParams(window.location.search).get("snapGuide");return!(n==="0"||n==="false")},uu=()=>dt("arcGlyph",!0),eb=()=>dt("export",!0),Ia=()=>dt("retained",!0),Hn=()=>dt("retainedDebug",!1),Xo=()=>dt("sdfDash",!0),hu=()=>dt("sdfPolygon",!0),du=()=>dt("sdfLineDeco",!0),tb=()=>dt("svgexport",!0);var nb={transparent:[0,0,0,0],black:[0,0,0,1],white:[1,1,1,1],red:[1,0,0,1],green:[0,.5019607843137255,0,1],blue:[0,0,1,1],gray:[.5019607843137255,.5019607843137255,.5019607843137255,1],grey:[.5019607843137255,.5019607843137255,.5019607843137255,1],pink:[1,.7529411764705882,.796078431372549,1]},Hr=n=>Math.min(1,Math.max(0,n)),rb=65536,zo=new Map,ae=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=zo.get(n);if(e)return e;let t=ob(n);return zo.size>=rb&&zo.clear(),zo.set(n,t),t},ob=n=>{let e=n.trim().toLowerCase(),t=nb[e];if(t)return t;if(e.startsWith("#")){let o=e.slice(1);if(o.length===3||o.length===4){let i=parseInt(o[0]+o[0],16)/255,s=parseInt(o[1]+o[1],16)/255,a=parseInt(o[2]+o[2],16)/255,l=o.length===4?parseInt(o[3]+o[3],16)/255:1;return[i,s,a,l]}if(o.length===6||o.length===8){let i=parseInt(o.slice(0,2),16)/255,s=parseInt(o.slice(2,4),16)/255,a=parseInt(o.slice(4,6),16)/255,l=o.length===8?parseInt(o.slice(6,8),16)/255:1;return[i,s,a,l]}return[0,0,0,0]}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[Hr(i(o[0])/255),Hr(i(o[1])/255),Hr(i(o[2])/255),o[3]!==void 0?Hr(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?Hr(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 hr=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=ae(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})},Yo=(n,e,t)=>{let r=[1,0,0,1,-e/2+n.offsetX,-t/2+n.offsetY];return n.gradientUnits==="percentage"&&(r=Y(r,[e,0,0,t,0,0])),n.gradientTransform&&(r=Y(r,n.gradientTransform)),r};var fu=(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},mu=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 ib=["repeat","repeat-x","repeat-y","no-repeat"],Uo=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=ib.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}},$o=(n,e,t)=>{let r=[1,0,0,1,-e/2+n.offsetX,-t/2+n.offsetY];return n.patternTransform&&(r=Y(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"},ee=n=>{let e=n?.type;return typeof e=="string"?e.toLowerCase():""},on=new Set([L.TEXTBOX,L.INPUTTEXT,L.ITEXT,L.TEXT,L.ARCHTEXT,L.WAISTTEXT,L.FLAGTEXT,L.ARCTEXT,L.CIRCLETEXT,L.SCROLLTEXT,L.TEXTIMAGE]),ft=new Set([L.IMAGE,L.SVGIMAGE,L.CROPIMAGE,L.QRCODE,L.BARCODE,L.ECHART,L.FABRIC_ECHART]),Wn=new Set([L.ELLIPSE,L.CIRCLE,L.POLYGON,L.POLYLINE,L.PATH,L.TRIANGLE]),mt=new Set([L.LINE,L.ARROW,L.DIMENSION,L.REFERENCELINE]),Gn=new Set([L.RECT,L.FABRICRECT]),rt=new Set([L.MASK]),Vo=new Set([L.PUZZLE]),jo=new Set([L.GIF]),qo=new Set([L.VIDEO]);var sn=1-.5522847498,_a=new Set([L.FABRICRECT]),an=(n,e)=>typeof n=="number"&&Number.isFinite(n)?n:e,Da=(n,e,t)=>{let r=an(n,0);return r>0?{rx:r/(an(e,1)||1),ry:r/(an(t,1)||1)}:null},bu=n=>{if(!_a.has(ee(n)))return;let e=Da(n.radius,n.scaleX,n.scaleY);e&&(n.rx=e.rx,n.ry=e.ry)},gu=(n,e)=>{if(!_a.has(ee(n)))return!1;let t="radius"in e,r="scaleX"in e||"scaleY"in e,o=an(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=Da(i,s,a);return e.rx=l?l.rx:0,e.ry=l?l.ry:0,!0},ot=(n,e,t)=>{if(!(e>0)||!(t>0))return null;let r=_a.has(ee(n))?Da(n.radius,n.scaleX,n.scaleY):null,o=r?r.rx:an(n.rx,0),i=r?r.ry:an(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},Ko=(n,e,t)=>{if(!(e>0)||!(t>0))return null;let r=Math.min(Math.max(an(n.rx,0),an(n.ry,0)),e/2,t/2);return r>0?r:null},Wr=(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-sn*a,u,c+i,u+sn*l,c+i,u+l),n.lineTo(c+i,u+s-l),h&&n.bezierCurveTo(c+i,u+s-sn*l,c+i-sn*a,u+s,c+i-a,u+s),n.lineTo(c+a,u+s),h&&n.bezierCurveTo(c+sn*a,u+s,c,u+s-sn*l,c,u+s-l),n.lineTo(c,u+l),h&&n.bezierCurveTo(c,u+sn*l,c+sn*a,u,c+a,u),n.closePath()},xu=(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,g,b]of c)for(let x=0;x<l;x++){let y=b+x/l*(Math.PI/2);u.push(f+p*Math.cos(y),m+g*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 sb from"rbush";var Ne=1e-12,ab=96,Qo=(n,e,t,r,o,i)=>(t-n)*(i-e)-(r-e)*(o-n),Fa=(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},dr=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},yu=(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=Qo(t.x,t.y,r.x,r.y,i.x,i.y),a=Qo(r.x,r.y,o.x,o.y,i.x,i.y),l=Qo(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:Fa(t,r,i,s)||Fa(r,o,i,a)||Fa(o,t,i,l)},Oa=n=>{let e=n.length;if(e<3)return[];let t=dr(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,c=null,u=null;if(e>=ab){l=new sb,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],g=n[f],b=n[m],x=Qo(p.x,p.y,g.x,g.y,b.x,b.y);if(x>Ne){let y=!1;if(l&&c){let S=Math.min(p.x,g.x,b.x)-Ne,v=Math.max(p.x,g.x,b.x)+Ne,T=Math.min(p.y,g.y,b.y)-Ne,C=Math.max(p.y,g.y,b.y)+Ne,R=l.search({minX:S,minY:T,maxX:v,maxY:C});for(let w=0;w<R.length;w++){let E=R[w].v;if(u[E]&&!(E===d||E===f||E===m)&&yu(n,E,p,g,b)){y=!0;break}}}else for(let S=3;S<i;S++){let v=r[(a+S)%i];if(yu(n,v,p,g,b)){y=!0;break}}if(!y){o.push(d,f,m);let S=r.splice((a+1)%i,1)[0];i--,u&&(u[S]=0),h=0;continue}}else if(x>=-Ne){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 Zo=Math.PI,lb=Math.PI/180,Ru=Math.PI/2,Ha=n=>{if(n===0)return 1;switch(Math.abs(n)/Ru){case 1:case 3:return 0;case 2:return-1}return Math.cos(n)},Wa=n=>{if(n===0)return 0;let e=n/Ru,t=Math.sign(n);switch(e){case 1:return t;case 2:return 0;case 3:return-t}return Math.sin(n)},cb=/[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/gi,ub=/[mzlhvcsqta][^mzlhvcsqta]*/gi,Xn=/\s*,?\s*/,Gr="([-+]?(?:\\d*\\.\\d+|\\d+\\.?)(?:[eE][-+]?\\d+)?)",Ba=new RegExp(`${Xn.source}${Gr}${Xn.source}${Gr}${Xn.source}${Gr}${Xn.source}([01])${Xn.source}([01])${Xn.source}${Gr}${Xn.source}${Gr}`,"g"),Pu={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},hb={m:"l",M:"L"},db=n=>{let e=[],t=n.match(ub)??[];for(let r of t){let o=r[0];if(o==="z"||o==="Z"){e.push([o]);continue}let i=Pu[o.toLowerCase()],s=[];if(o==="a"||o==="A"){Ba.lastIndex=0;for(let a=Ba.exec(r);a;a=Ba.exec(r))s=s.concat(a.slice(1))}else s=r.match(cb)??[];for(let a=0;a<s.length;a+=i){let l=new Array(i),c=hb[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},vu=(n,e,t,r)=>{let o=Math.atan2(e,n),i=Math.atan2(r,t);return i>=o?i-o:2*Zo-(o-i)},fb=(n,e,t,r,o,i,s,a,l,c,u)=>{let h=Ha(n),d=Wa(n),f=Ha(e),m=Wa(e),p=t*o*f-r*i*m+s,g=r*o*f+t*i*m+a,b=c+l*(-t*o*d-r*i*h),x=u+l*(-r*o*d+t*i*h),y=p+l*(t*o*m+r*i*f),S=g+l*(r*o*m-t*i*f);return["C",b,x,y,S,p,g]},mb=(n,e,t,r,o,i,s)=>{if(t===0||r===0)return[];let a=0,l=0,c=0,u=s*lb,h=Wa(u),d=Ha(u),f=.5*(-d*n-h*e),m=.5*(-d*e+h*n),p=t**2,g=r**2,b=m**2,x=f**2,y=p*g-p*b-g*x,S=Math.abs(t),v=Math.abs(r);if(y<0){let W=Math.sqrt(1-y/(p*g));S*=W,v*=W}else c=(o===i?-1:1)*Math.sqrt(y/(p*b+g*x));let T=c*S*m/v,C=-c*v*f/S,R=d*T-h*C+n*.5,w=h*T+d*C+e*.5,E=vu(1,0,(f-T)/S,(m-C)/v),M=vu((f-T)/S,(m-C)/v,(-f-T)/S,(-m-C)/v);i===0&&M>0?M-=2*Zo:i===1&&M<0&&(M+=2*Zo);let P=Math.ceil(Math.abs(M/Zo*2)),A=[],k=M/P,O=8/3*Math.sin(k/4)*Math.sin(k/4)/Math.sin(k/2),F=E+k;for(let W=0;W<P;W++)A[W]=fb(E,F,d,h,S,v,R,w,O,a,l),a=A[W][5],l=A[W][6],E=F,F+=k;return A},pb=(n,e,t,r,o,i,s,a,l)=>mb(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)),Su=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 pb(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},Ae=n=>{if(typeof n=="string"){if(!n)return null;let e=db(n);return e.length>0?Su(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"||Pu[r]!==void 0)&&e.push(t)}return e.length===0?null:Su(e)}return null},wu=(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 S=-f/h;0<S&&S<1&&l.push(S);continue}let g=h*h-4*f*d;if(g<0)continue;let b=Math.sqrt(g),x=(-h+b)/(2*d);0<x&&x<1&&l.push(x);let y=(-h-b)/(2*d);0<y&&y<1&&l.push(y)}let m=l.length;for(let p=0;p<m;p++){let g=l[p],b=g**3,x=3*g**2*(1-g),y=3*g*(1-g)**2,S=(1-g)**3;c.push(s*b+o*x+t*y+n*S),u.push(a*b+i*x+r*y+e*S)}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)}]},qe=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 wu(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 wu(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}},bb=(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)},Jo=(n,e,t,r,o,i,s,a,l,c,u)=>{if(u>24){n.push({x:a,y:l});return}if(bb(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,g=(s+l)/2,b=(h+f)/2,x=(d+m)/2,y=(f+p)/2,S=(m+g)/2,v=(b+y)/2,T=(x+S)/2;Jo(n,e,t,h,d,b,x,v,T,c,u+1),Jo(n,v,T,y,S,p,g,a,l,c,u+1)},ku=(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":{Jo(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":{Jo(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},Tu=(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},gb=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()},xb=(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)},Au=(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},yb=(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},Ga=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}},Eu=(n,e,t)=>e.x>=n.minX-t&&e.x<=n.maxX+t&&e.y>=n.minY-t&&e.y<=n.maxY+t,vb=n=>{let e=n.length,t=Ga(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 g=s[m*r+p];if(g){for(let b of g)if(!(b.pa===c||b.pb===c)&&Au(l,c,b.pa,b.pb))return!0}}return!1}}},Sb=(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 S=n[y],v=Math.hypot(S.x-i.x,S.y-i.y);if(v>=a)continue;let T=t.blockedExcept(i,S);if(!T){for(let C=0;C<e.length;C++)if(!(C===o||(C+1)%e.length===o)&&Au(i,S,e[C],e[(C+1)%e.length])){T=!0;break}}T||(a=v,s=y)}if(s>=0){let y=[];for(let S=s;S<r;S++)y.push(n[S]);for(let S=0;S<s;S++)y.push(n[S]);y.push(n[s]),y.push(i);for(let S=1;S<e.length;S++)y.push(e[(o+S)%e.length]);return y.push(i),Mu(t,n[s],i,e),y}let l=1/0,c=-1;for(let y=0;y<r;y++){let S=n[y],v=n[(y+1)%r];if(S.y!==v.y&&i.y>=Math.min(S.y,v.y)&&i.y<Math.max(S.y,v.y)){let T=(i.y-S.y)/(v.y-S.y),C=S.x+T*(v.x-S.x);C>=i.x&&C<l&&(l=C,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,g=Math.hypot(m,p)||1,b=-1/0;for(let y=0;y<r;y++){if(y===s)continue;let S=n[y];if(!xb(i,f,d,S))continue;let v=S.x-i.x,T=S.y-i.y,C=Math.hypot(v,T)||1,R=(v*m+T*p)/(C*g);(R>b+1e-12||Math.abs(R-b)<=1e-12&&C<a)&&(b=R,a=C,d=S,s=y)}let x=[];for(let y=s;y<r;y++)x.push(n[y]);for(let y=0;y<s;y++)x.push(n[y]);x.push(n[s]),x.push(i);for(let y=1;y<e.length;y++)x.push(e[(o+y)%e.length]);return x.push(i),Mu(t,n[s],i,e),x},Mu=(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])},Nu=(n,e="evenodd")=>{let t=n.map(c=>gb(c.points)).filter(c=>c.length>=3);if(t.length===0)return[];let r=t.map(c=>Ga(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&&Eu(r[h],u,1e-6)&&(yb(u,t[h],1e-6)||Tu(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=dr(t[c])>0?1:-1;for(let h=0;h<t.length;h++)h!==c&&i[h][c]&&(u+=dr(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)=>Cu(u.ring)-Cu(c.ring));for(let c of l){let u=c.ring[0],h=a.find(f=>o[f.index]===c.depth-1&&Eu(f.bbox,u,0)&&Tu(u,f.ring));if(!h)continue;dr(h.ring)*dr(c.ring)>0&&(c.ring=c.ring.slice().reverse()),h.grid??=vb(h.ring),h.ring=Sb(h.ring,c.ring,h.grid);let d=Ga(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)},Cu=n=>{let e=-1/0;for(let t of n)t.x>e&&(e=t.x);return e};var wb=new Set(["miter","round","bevel"]),Tb=new Set(["butt","round","square"]),ei=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"&&wb.has(n.strokeLineJoin)?n.strokeLineJoin:"miter",o=typeof n.strokeLineCap=="string"&&Tb.has(n.strokeLineCap)?n.strokeLineCap:"butt";return{color:n.stroke,rgba:ae(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||ee(n)===L.PATH}},Lu=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 Eb=(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)},Mb=625e4,Iu=(n,e,t)=>Math.min(n,8192/e,8192/t,Math.sqrt(Mb/(e*t))),ti=(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}},zn=(n,e)=>{let t=e.raw,r=ee(t);if(n.beginPath(),r===L.PATH){let o=Ae(t.path);if(!o)return!1;let i=qe(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=ot(t,o,i);return s?Wr(n,o,i,s.rx,s.ry):n.rect(-o/2,-i/2,o,i),!0}return!1},_u=(n,e)=>{let t=ei(n.raw);if(!t)return null;let r=ee(n.raw);if(r===L.ARROW||r===L.DIMENSION)return Pb(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=Eb(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=Iu(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,g=e&&u===c?ti(p,e.zoom,e.dpr,e.vpt,a,l):null,b=g?g.lx:p[4]-a/2,x=g?g.ly:p[5]-l/2,y=h/u,S=d/u,v=[p[0]*u,p[1]*u,p[2]*u,p[3]*u,(p[4]-b)*u,(p[5]-x)*u];if(m.setTransform(v[0],v[1],v[2],v[3],v[4],v[5]),!zn(m,n))return null;let T=v;if(t.uniform){let C=Math.hypot(p[0],p[1])||1,R=Math.hypot(p[2],p[3])||1;T=Y(v,[1/C,0,0,1/R,0,0])}if(m.setTransform(T[0],T[1],T[2],T[3],T[4],T[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 C=Xr(n,m);typeof n.raw.fill=="string"&&n.raw.fill!==""&&n.raw.fill!=="transparent"||m.clip(),m.fillStyle=C,m.fill(),m.globalCompositeOperation="source-over"}return{canvas:f,w:y,h:S,lx:b,ly:x,sceneW:a,sceneH:l,snapped:!!g}}return m.stroke(),{canvas:f,w:y,h:S,lx:b,ly:x,sceneW:a,sceneH:l,snapped:!!g}},Xr=(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 Cb(n)},Cb=n=>{let e=n.raw.stroke;return typeof e=="string"&&e?e:"#000"},Rb=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}},Pb=(n,e,t)=>{let r=Rb(n);if(!r)return null;let o=n.raw,s=ee(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),g=d*p,b=f*p;if(s)u=Math.ceil(u+b+g);else{let K=Number(o.textFontSize)||50,G=typeof o.text=="string"&&o.text.trim()?o.text:"50cm",J=Number(o.textPadding)||4,B=`${K}px Arial, sans-serif`,j=zr(B,G)+J*2,Q=Math.atan2(r.y2-r.y1,r.x2-r.x1),ie=-Math.sin(Q),ce=Math.cos(Q),me=K+a/2+5;h={text:G,fontPx:K,w:j,h:K+J*2,cx:(r.x1+r.x2)/2+ie*me,cy:(r.y1+r.y2)/2+ce*me,angle:o.textFollowLine===!1?0:Q,color:typeof o.textColor=="string"?o.textColor:"#333333",bg:typeof o.textBackgroundColor=="string"?o.textBackgroundColor:"#ffffff",pad:J,follow:o.textFollowLine!==!1},u=Math.ceil(u+me+Math.max(j,K*2)*.75)}let x=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,S=x+u*2,v=y+u*2;if(!(S>0)||!(v>0)||S>8192||v>8192)return null;let T=t?t.zoom*t.dpr:1,C=Iu(T,S,v),R=Math.ceil(S*C),w=Math.ceil(v*C);if(!(R>0)||!(w>0))return null;let E=document.createElement("canvas");E.width=R,E.height=w;let M=E.getContext("2d");if(!M)return null;let P=n.matrix,A=t&&C===T?ti(P,t.zoom,t.dpr,t.vpt,S,v):null,k=A?A.lx:P[4]-S/2,O=A?A.ly:P[5]-v/2,F=[P[0]*C,P[1]*C,P[2]*C,P[3]*C,(P[4]-k)*C,(P[5]-O)*C];M.setTransform(F[0],F[1],F[2],F[3],F[4],F[5]);let W=r.x2-r.x1,X=r.y2-r.y1,_=Math.atan2(X,W),D=Math.cos(_),I=Math.sin(_);if(s){let K=m==="start"||m==="both",G=m==="end"||m==="both",J=r.x1+D*(K?b:0),B=r.y1+I*(K?b:0),j=r.x2-D*(G?b:0),Q=r.y2-I*(G?b:0);M.lineWidth=a,M.strokeStyle=l,c&&c.length>0?M.setLineDash(c):M.setLineDash([]),M.beginPath(),M.moveTo(J,B),M.lineTo(j,Q),M.stroke(),M.setLineDash([]);let ie=(ce,me,Re)=>{M.save(),M.translate(ce,me),M.rotate(Re),M.beginPath(),M.moveTo(0,0),M.lineTo(-b,-g/2),M.lineTo(-b,g/2),M.closePath(),M.fillStyle=l,M.fill(),M.restore()};return G&&ie(r.x2,r.y2,_),K&&ie(r.x1,r.y1,_+Math.PI),{canvas:E,w:R/C,h:w/C,lx:k,ly:O,sceneW:S,sceneH:v,snapped:!!A}}M.beginPath(),M.moveTo(r.x1,r.y1),M.lineTo(r.x2,r.y2);let H=F;if(e.uniform){let K=Math.hypot(P[0],P[1])||1,G=Math.hypot(P[2],P[3])||1;H=Y(F,[1/K,0,0,1/G,0,0])}M.setTransform(H[0],H[1],H[2],H[3],H[4],H[5]),M.lineWidth=e.width,M.lineCap=e.lineCap,M.lineDashOffset=e.dashOffset,M.lineJoin=e.lineJoin,M.miterLimit=e.miterLimit,e.dashArray&&M.setLineDash(e.dashArray),M.strokeStyle=l,M.stroke(),M.setTransform(F[0],F[1],F[2],F[3],F[4],F[5]);let z=-I,U=D,$=(Number(o.textFontSize)||50)/2;M.lineWidth=a,M.lineCap="round",e.dashArray&&M.setLineDash([]),M.strokeStyle=l;for(let[K,G]of[[r.x1,r.y1],[r.x2,r.y2]])M.beginPath(),M.moveTo(K-z*$,G-U*$),M.lineTo(K+z*$,G+U*$),M.stroke();return h&&(M.save(),M.translate(h.cx,h.cy),h.follow&&M.rotate(h.angle),M.font=`${h.fontPx}px Arial, sans-serif`,M.textAlign="center",M.textBaseline="middle",h.bg&&(M.fillStyle=h.bg,M.fillRect(-h.w/2,-h.h/2,h.w,h.h)),M.fillStyle=h.color,M.fillText(h.text,0,0),M.restore()),{canvas:E,w:R/C,h:w/C,lx:k,ly:O,sceneW:S,sceneH:v,snapped:!!A}},zr=(n,e)=>{let t=document.createElement("canvas").getContext("2d");return t?(t.font=n,t.measureText(e).width):e.length*50};var pe={LEFT:"left",CENTER:"center",RIGHT:"right",JUSTIFY:"justify",JUSTIFY_LEFT:"justify-left",JUSTIFY_CENTER:"justify-center",JUSTIFY_RIGHT:"justify-right",DISPERSE:"disperse"},kb=Object.values(pe),Ut=n=>n===pe.JUSTIFY||n===pe.JUSTIFY_LEFT||n===pe.JUSTIFY_CENTER||n===pe.JUSTIFY_RIGHT,Xa=n=>n===pe.JUSTIFY_LEFT||n===pe.JUSTIFY_CENTER||n===pe.JUSTIFY_RIGHT,Yr=n=>n===pe.JUSTIFY||n===pe.DISPERSE;var Du=400,ni=1.13,ri=.222,Ab=2,Nb={underline:.1,linethrough:-.28167,overline:-.81333},Lb=66.667,Ib=/[a-zA-Z.\s]+/,_b=/[0-9]/,Db=/[()[\]{}></:;:,.?!]/,Vr=n=>Ib.test(n)||_b.test(n)||Db.test(n),Fb=new Set(["ー","「","」","『","』","(",")","〔","〕","[","]","{","}","⦅","⦆","〈","〉","《","》","【","】","〖","〗","〘","〙","〚","〛","゛","゜","。","、","・","゠","=","〜","…","•","‥","◦","﹅","﹆"]),Ob=new Set(["「","」","『","』","〔","〕","[","]","{","}","⦅","⦆","〈","〉","《","》","【","】","〖","〗","〘","〙","〚","〛","(",")"]),Un=n=>Vr(n)?"latin":Ob.has(n)?"bracket":Fb.has(n)?"symbol":"cjk",$n=(n,e,t)=>Vr(n)?e.width:e.height+t,ln=n=>n/1.1,fr=(n,e,t)=>n==="symbol"?-t/3.14:e.height/2-t/3.14,Tt=(n,e,t)=>n===0||t%2===0?0:n/300*e*.5,Wu=(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},Ur=null,Gu=(n,e,t)=>{let r={left:0,right:0,ascent:t*.88,descent:t*.24};if(typeof document>"u")return r;if(!Ur){let i=document.createElement("canvas");i.width=8,i.height=8,Ur=i.getContext("2d")}if(!Ur)return r;Ur.font=n;let o=Ur.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}},Fu=new WeakMap,Ua=new Set,Ou=(n,e,t)=>{let r=Fu.get(n);r||(r=new Map,Fu.set(n,r),Ua.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},Bb=(n,e,t=Gu)=>{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=zu(e,n.charStyles[a]),h=Un(l),d,f;if(h==="latin"||h==="bracket"){let m=h==="latin"?c.kernedWidth-c.width:0,p=Ou(t,u,l);d=p.left+m,f=p.right+m}else{let m=Ou(t,u,l);d=ln(u.fontSize)-m.ascent,f=ln(u.fontSize)+m.descent}a===0&&(i=d),s=o+f,o+=$n(l,c,r)}return{start:i,end:s}},$a=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"]),Me=(n,e)=>{let t=n.fontFamily,r=t.includes("'")||t.includes('"')||t.includes(",")||$a.has(t.toLowerCase())?t:`"${t}"`;return`${n.fontStyle??"normal"} ${n.fontWeight??"normal"} ${e}px ${r}`},Hb=(n,e)=>{if(n)return n.id===0?`${e+1}`:n.content||void 0},Fe=(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}},jr=/[\u4e00-\u9fa5\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af]/,cn=n=>{let e=n.boxes[n.boxes.length-1];return e?e.left+e.width:0},Et=(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},Va=(n,e,t)=>{let r=[],o=!!t[e],i=y=>!!(n.charStyles[y]?.[e]??o);if(!n.graphemes.some((y,S)=>i(S)))return r;let s=y=>n.charStyles[y]?.fill??t.fill??"",a=y=>n.charStyles[y]?.textDecorationThickness??t.textDecorationThickness??Lb,l=y=>n.charStyles[y]?.fontSize??t.fontSize,c=Nb[e],u=e==="linethrough"?.5:e==="overline"?1:0,h=t.charSpacing?t.fontSize*t.charSpacing/1e3:0,d=(y,S,v,T,C,R)=>{if(!y||!S||!v||R<=0)return;let w=t.fontSize*v/1e3;r.push({x:C,width:R,y:c*T-u*w,thickness:w,color:S})},f=0,m=0,p=i(0),g=s(0),b=a(0),x=l(0);for(let y=0;y<n.graphemes.length;y++){let S=i(y),v=s(y),T=a(y),C=l(y),R=n.boxes[y],w=t.vertical?Vr(n.graphemes[y])?R.kernedWidth:R.height:R.kernedWidth;(S!==p||v!==g||T!==b||C!==x)&&m>0?(d(p,g,b,x,f,m),f=R.left,m=t.vertical?w:R.width,p=S,g=v,b=T,x=C):m+=t.vertical?w:R.kernedWidth}return d(p,g,b,x,f,m-h),r},$r=null,Wb=(n,e)=>{if(typeof document>"u")return 0;if(!$r){let t=document.createElement("canvas");if(t.width=8,t.height=8,$r=t.getContext("2d"),!$r)return 0}return $r.font=n,$r.measureText(e).width},Yn=n=>Array.from(n),Gb=n=>n.split(/[ \t\r]/),za=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}},Bu=new WeakMap,Xb=(n,e)=>{let t=Bu.get(e);t||(t=new Map,Bu.set(e,t),Ua.add(t));let r=t.get(n);return r||(r=new za(n,e),t.set(n,r)),r},Xu=()=>{for(let n of Ua)n.clear()},zu=(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},Ya=(n,e,t,r,o)=>{let i=Xb(Me(e,Du),n),s=e.fontSize/Du,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}},Yu=n=>n.charSpacing?n.fontSize*n.charSpacing/1e3:0,Hu=(n,e,t,r,o,i,s,a=!1)=>{let l=Yu(o),c=[],u=" ",h=0,d=[],f=0,m=!0,p=0,g=Math.max(e,r,Ab),b=t[n];for(let x=0;x<b.length;x++){let y=b[x].graphemes,S=b[x].width;p+=y.length,h+=(a?0:f)+S-l,h>g&&!m?(c.push(d),d=[],h=S,m=!0):h+=l,!m&&!a&&d.push(u),d=d.concat(y),f=a?0:Ya(s,i(n,p),u).kernedWidth+l,p++,m=!1}return b.length&&c.push(d),c},Vn=(n,e,t={})=>{let r=t.measure??Wb,o=t.inkMeasure??Gu,i=t.styles,s=(M,P)=>zu(e,i?.[M]?.[P]),a=Yu(e),l=e.lineHeight??1.16,c=(M,P,A)=>{let k=0,O;for(let F=0;F<M.length;F++){let W=Ya(r,s(P,A+F),M[F],O,F>0?s(P,A+F-1):void 0);k+=W.kernedWidth+a,O=M[F]}return k},u=(n??"").split(`
3
+ `),h,d=0;if(t.boxWidth==null)h=u.map(M=>Yn(M));else if(t.splitByGrapheme){let M=[];for(let P=0;P<u.length;P++){let A=Yn(u[P]);if(A.length===0){M.push([{graphemes:[],width:0,charOffset:0}]);continue}let k=A.map((O,F)=>{let W=c([O],P,F);return d=Math.max(W,d),{graphemes:[O],width:W,charOffset:F}});M.push(k)}h=[];for(let P=0;P<M.length;P++)h.push(...Hu(P,t.boxWidth,M,d,e,s,r,!0))}else{let M=[];for(let P=0;P<u.length;P++){let A=[],k=0;for(let O of Gb(u[P])){let F=Yn(O),W=c(F,P,k);d=Math.max(W,d),A.push({graphemes:F,width:W,charOffset:k}),k+=F.length+1}M.push(A)}h=[];for(let P=0;P<M.length;P++)h.push(...Hu(P,t.boxWidth,M,d,e,s,r))}let f=Yn(n??""),m=[];{let M=0,P=0,A=0;for(let k=0;k<h.length;k++){let O=f[A];O===`
4
+ `&&k>0?(P=0,A++,M++):k>0&&!t.splitByGrapheme&&/[ \t\r]/.test(O??"")&&(P++,A++),m[k]={line:M,offset:P,flatStart:A},A+=h[k].length,P+=h[k].length}}let p=h.map((M,P)=>{let A=m[P],k=[],O=0;for(let _=0;_<M.length;_++){let D=Ya(r,s(A.line,A.offset+_),M[_],_>0?M[_-1]:void 0,_>0?s(A.line,A.offset+_-1):void 0),I={left:0,width:D.width+a,kernedWidth:D.kernedWidth+a,height:s(A.line,A.offset+_).fontSize};_>0&&(I.left=k[_-1].left+k[_-1].width+D.kernedWidth-D.width),k.push(I),t.vertical&&!Vr(M[_])?O+=I.height:O+=I.kernedWidth}a!==0&&(O-=a),O<0&&(O=0);let F=M.map((_,D)=>i?.[A.line]?.[A.offset+D]),W=0;if(M.length>0)for(let _=0;_<M.length;_++)W=Math.max(W,i?.[A.line]?.[A.offset+_]?.fontSize??e.fontSize);else W=i?.[A.line]?.[A.offset]?.fontSize??e.fontSize;let X;if(t.paragraph){let _=Hb(t.paragraph,P);if(_){let D=s(A.line,A.offset),I=Me(D,D.fontSize),H=r(I,_);if(H>0){X={text:_,width:H,advances:Yn(_).map(z=>r(I,z)),style:D};for(let z of k)z.left+=X.width;O+=X.width}}}return{graphemes:M,boxes:k,width:O,leftOffset:0,baseline:0,top:0,implHeight:W*ni,styleMap:A,charStyles:F,prefix:X}}),g=0,b=0;for(let M=0;M<p.length;M++){let P=p[M].implHeight,A=M===p.length-1;p[M].top=b,p[M].baseline=b+P*(1-ri),b+=P*l,g+=A?P:P*l}let x=t.boxWidth!=null?Math.max(t.boxWidth,d-a):0,y=()=>{let M=0;for(let P of p){let A=0;for(let k=0;k<P.graphemes.length;k++)A+=Vr(P.graphemes[k])?P.boxes[k].width+a:P.boxes[k].height+a;M=Math.max(M,A)}return M+2},S=t.vertical?y():void 0,v=t.boxWidth!=null?x:t.vertical?S:Math.max(0,...p.map(M=>M.width)),T=e.textAlign??pe.LEFT,C=M=>{if(t.boxWidth==null)return M===p.length-1;let P=p[M+1]?.styleMap;return!P||P.line!==p[M].styleMap.line};for(let M=0;M<p.length;M++){let P=T===pe.CENTER||T===pe.JUSTIFY_CENTER&&C(M),A=T===pe.RIGHT||T===pe.JUSTIFY_RIGHT&&C(M);if(t.vertical&&(P||A)&&p[M].graphemes.length>0){let O=Bb(p[M],e,o);p[M].leftOffset=P?(v-O.start-O.end)/2:v-O.end;continue}let k=v-p[M].width;P?p[M].leftOffset=k/2:A&&(p[M].leftOffset=k)}let R=T===pe.DISPERSE;if((Ut(T)||R)&&!t.vertical)for(let M=0;M<p.length;M++){let P=p[M],A=Xa(T);if(A&&(M===p.length-1||C(M))||!A&&!R&&M===p.length-1||P.width>=v)continue;let k=!A&&P.graphemes.some(X=>jr.test(X)),O=k?P.graphemes.length-1:P.graphemes.reduce((X,_)=>/[ \t\r]/.test(_)?X+1:X,0);if(O<=0)continue;let F=(v-P.width)/O,W=0;for(let X=0;X<P.graphemes.length;X++){let _=P.boxes[X],D=k?X<P.graphemes.length-1:/[ \t\r]/.test(P.graphemes[X]);_.left+=W,D&&(_.width+=F,_.kernedWidth+=F,W+=F)}}let w=[],E=0;for(let M of f)w.push(E),E+=M.length;return w.push(E),{lines:p,width:v,height:g,graphemeCodeUnitOffsets:w,verticalWidth:S}};var zb=1e4,qr=2,Uu=(n,e)=>{let t=e-n;for(;t>=2*Math.PI;)t-=2*Math.PI;for(;t<=0;)t+=2*Math.PI;return t},oi=(n,e,t)=>Uu(n,e)+Uu(e,t)<2*Math.PI,ii=(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(oi(l,0,c)){let u=t.x+r;u>s&&(s=u)}if(oi(l,Math.PI/2,c)){let u=t.y+r;u>a&&(a=u)}if(oi(l,Math.PI,c)){let u=t.x-r;u<o&&(o=u)}if(oi(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}},Ke=n=>ee(n)===L.ARCTEXT?"arc":ee(n)===L.CIRCLETEXT?"circle":null,$u=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}),Yb=(n,e,t)=>{let r=$u(n),o=n.width,i=R=>n.lines[R].implHeight*e,s=0;for(let R=0;R<n.lines.length;R++)s+=i(R);let a=Math.abs(t),l=a*Math.PI/180,c=0;for(let R=0;R<n.lines.length;R++)c+=n.lines[R].width;let u=l>0?c/l:0,h=Math.max(zb/Math.max(a,.1),u),d=0,f=t>0?s/2+h:-s/2+h,m=t>0?s:0,p=1/0,g=-1/0,b=1/0,x=-1/0,y=[];for(let R=0;R<r.length;R++){let w=-o/2+n.lines[R].leftOffset,E=i(R),M=E-E/e+E*ri/e;m+=t>0?-E:E;let P=Math.abs(h)+m,A=t>0?P+E-E/e:P-E+E/e,k=[];for(let D=0;D<r[R].length;D++){let I=r[R][D],H,z,U,$,K,G,J;t>0?(H=P,z=P+E,U=P+M,$=(H*3+z*2)/5,K=-(w+I.left)/$,G=-(w+I.left+I.width)/$,J=-(w+I.left+I.width/2)/$):(H=P,z=P-E,U=P-M,$=(H*2+z*3)/5,K=Math.PI+(w+I.left)/$,G=Math.PI+(w+I.left+I.width)/$,J=Math.PI+(w+I.left+I.width/2)/$);let B=Math.sin(G),j=Math.cos(G),Q=Math.sin(K),ie=Math.cos(K),ce=Math.sin(J),me=Math.cos(J);k.push({tl:{x:d-z*Q,y:f-z*ie},tr:{x:d-z*B,y:f-z*j},nl:{x:d-A*Q,y:f-A*ie},nr:{x:d-A*B,y:f-A*j}});let Re=n.lines[R].graphemes[D];Re!==void 0&&y.push({char:Re,line:R,index:D,x:d-U*ce,y:f-U*me,rotation:t>0?-J:-J-Math.PI})}let O=k[0],F=k[k.length-1];if(!O||!F)continue;let W={x:d,y:f},X=t>0?ii(O.tl,F.tr,W,P+E):ii(F.tr,O.tl,W,P-E),_=t>0?ii(O.nl,F.nr,W,P):ii(F.nr,O.nl,W,P);p=Math.min(p,X.x,_.x),g=Math.max(g,X.x+X.width,_.x+_.width),b=Math.min(b,X.y,_.y),x=Math.max(x,X.y+X.height,_.y+_.height)}Number.isFinite(p)||(p=g=b=x=0);let S=-p-o/2,v=g-o/2,T=-b-s/2,C=x-s/2;return{width:Math.max(o+S+v,qr),height:s+T+C,contentOffsetX:v/2-S/2,contentOffsetY:C/2-T/2,chars:y}},Ub=(n,e,t)=>{let r=$u(n),o=E=>n.lines[E].implHeight*e,i=0;for(let E=0;E<n.lines.length;E++)i+=o(E);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 E=0;E<n.lines.length;E++)f+=n.lines[E].width;let m=0,p=0;if(f<=0||r.length===0)return{width:qr,height:Math.max(i,qr),contentOffsetX:0,contentOffsetY:0,chars:[]};let g=1/0,b=-1/0,x=1/0,y=-1/0,S=[],v=0;for(let E=0;E<r.length;E++){let M=o(E),P=M-M/e+M*ri/e,A=M-P;for(let k=0;k<r[E].length;k++){let O=r[E][k],W=(v+O.left+O.width/2)/f,X=h-W*u,_=Math.sin(X),D=Math.cos(X),I=m-a*_,H=p-c*D,z,U,$,K,G;if(d)z=0,U=1,$=0,K=0,G=-1;else{let Q=a*D,ie=-c*_,ce=Math.hypot(Q,ie)||1;U=Q/ce,$=ie/ce;let me=-c*_,Re=-a*D,De=Math.hypot(me,Re)||1;K=me/De,G=Re/De,z=Math.atan2(ie,Q)}let J=-z,B=O.width/2;g=Math.min(g,I-K*P-U*B,I-K*P+U*B,I+K*A-U*B,I+K*A+U*B),b=Math.max(b,I-K*P-U*B,I-K*P+U*B,I+K*A-U*B,I+K*A+U*B),x=Math.min(x,H-G*P-$*B,H-G*P+$*B,H+G*A-$*B,H+G*A+$*B),y=Math.max(y,H-G*P-$*B,H-G*P+$*B,H+G*A-$*B,H+G*A+$*B);let j=n.lines[E].graphemes[k];j!==void 0&&S.push({char:j,line:E,index:k,x:I,y:H,rotation:-J})}v+=n.lines[E].width}Number.isFinite(g)||(g=b=x=y=0);let T=-g-s/2,C=b-s/2,R=-x-i/2,w=y-i/2;return{width:Math.max(b-g,qr),height:Math.max(y-x,qr),contentOffsetX:C/2-T/2,contentOffsetY:w/2-R/2,chars:S}},Mt=(n,e,t)=>ee(e)===L.CIRCLETEXT?Ub(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"}):Yb(n,t,typeof e.curvature=="number"?e.curvature:300);var jn=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},ja=(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 g=p.colSpan??1,b=p.rowSpan??1,x=Math.max(c*g+e.hGap*(g-1),0),y=Math.max(u*b+e.vGap*(b-1),0),S=p.col+(g-1)/2,v=p.row+(b-1)/2;return{w:x,h:y,cx:(S-f)*h,cy:(v-m)*d}})},$b=(n,e)=>e&&e.naturalWidth&&e.naturalHeight?{w:e.naturalWidth,h:e.naturalHeight}:{w:n?.width??0,h:n?.height??0},Vu=(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,g=s?(c.top||0)*o:c.top;if(c.left=p,c.top=g,c.width=f,c.height=m,c.clip){let b=i&&h?f/h:1,x=s&&d?m/d:1,y=t?.[u]??$b(c.clip,null);if(y.w&&y.h){let S=Math.max(h/y.w,d/y.h),v=Math.max(f/y.w,m/y.h),T=c.clip.scaleX||c.clip.scaleY||1,C=S?T/S:1,R=v*(C||1);c.clip.scaleX=R,c.clip.scaleY=R}c.clip.clipX=(c.clip.clipX||0)*b,c.clip.clipY=(c.clip.clipY||0)*x}}),!0},si=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 Vb=(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},jb=(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}),mr=(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},ju=(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=Vb(i,n.cols)*d;if(t<f)return!1;let m=l-f,p=Math.min(t,Math.max(c,m)),g=Lt(i),b=n.hGap||0,x=[],y=null,S=5,v=.3;n.masks.forEach((B,j)=>{if(j===e)return;let Q=Lt(B),ie=Math.min(g.bottom,Q.bottom)-Math.max(g.top,Q.top);if(!(ie<=0||ie<Math.min(i.height,B.height)*v))if(r==="right"){if(Q.left<=i.left)return;let ce=Q.left;y===null||ce<y-S?(y=ce,x.length=0,x.push(j)):Math.abs(ce-y)<=S&&x.push(j)}else{if(Q.right>=i.left)return;let ce=Q.right;y===null||ce>y+S?(y=ce,x.length=0,x.push(j)):Math.abs(ce-y)<=S&&x.push(j)}});let T=B=>o?.[B]??null;if(!x.length){let B=l/2,j=r==="right"?B-g.left:g.right+B,Q=Math.max(s,Math.min(p,Math.max(s,j)));return Q===u?!1:(i.left=r==="right"?g.left+Q/2:g.right-Q/2,i.width=Q,mr(i,u,h,T(e)),!0)}let C=1/0,R=-1/0;for(let B of x){let j=Lt(n.masks[B]);j.left<C&&(C=j.left),j.right>R&&(R=j.right)}let w=r==="right"?g.left:g.right,E=B=>{let j=Lt(n.masks[B]);return r==="right"?j.right:j.left},M=1/0;for(let B of x){let j=(r==="right"?E(B)-w:w-E(B))-b-s;j<M&&(M=j)}let P=Math.max(s,Math.min(p,Math.max(s,M))),A=r==="right"?w+P:w-P;for(let B of x)if((r==="right"?E(B)-A:A-E(B))-b<s-1e-6)return!1;if(P<=0)return!1;i.left=r==="right"?w+P/2:w-P/2,i.width=P;let k=new Map;k.set(e,{width:u,height:h});for(let B of x){let j=n.masks[B];k.set(B,{width:j.width,height:j.height});let Q=E(B);r==="right"?(j.width=Q-A-b,j.left=(A+b+Q)/2):(j.width=A-b-Q,j.left=(A-b+Q)/2)}for(let B of[e,...x]){let j=k.get(B);mr(n.masks[B],j.width,j.height,T(B))}let O=Lt(i),F=O.left,W=O.right,X=Lt(n.masks[x[0]]),_=X.left,D=X.right,I=r==="right"?g.right:g.left,H=r==="right"?W:F,z=new Set(x),U=typeof i.colStart=="number"&&typeof i.colEnd=="number"?{colStart:i.colStart,colEnd:i.colEnd}:null,$=n.masks[x[0]],K=$&&typeof $.colStart=="number"&&typeof $.colEnd=="number"?{colStart:$.colStart,colEnd:$.colEnd}:null,G=n.cols>0&&!!U&&!!K,J=(B,j,Q)=>{let ie=n.masks[B],ce=ie.width,me=ie.height,Re=Math.max(c,Q-j);ie.left=(j+Q)/2,ie.width=Re,mr(ie,ce,me,T(B))};return n.masks.forEach((B,j)=>{if(j===e||z.has(j))return;let Q=Lt(B),ie=Q.left,ce=Q.right;if(G&&U&&K&&typeof B.colStart=="number"&&typeof B.colEnd=="number"){if(B.colStart===U.colStart&&B.colEnd===U.colEnd){J(j,F,W);return}if(B.colStart===K.colStart&&B.colEnd===K.colEnd){J(j,_,D);return}let Ee=r==="right"?U.colEnd+1:U.colStart,ue=B.colStart===Ee,ye=B.colEnd+1===Ee;if(!ue&&!ye)return;let fe=ue?H+(r==="right"?b:0):ie,we=ye?H-(r==="left"?b:0):ce;if(we-fe<=0)return;J(j,fe,we);return}let me=.5;if(Math.abs(ie-g.left)<me&&Math.abs(ce-g.right)<me){J(j,F,W);return}if(Math.abs(ie-C)<me&&Math.abs(ce-R)<me){J(j,_,D);return}let Re=Math.abs(ie-I)<me,De=Math.abs(ce-I)<me;if(!Re&&!De)return;let tt=Re?H:ie,Pe=De?H:ce;Pe-tt<=0||J(j,tt,Pe)}),i.width!==u},qu=(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=jb(i,n.rows)*d;if(t<f)return!1;let m=l-f,p=Math.min(t,Math.max(c,m)),g=Lt(i),b=n.vGap||0,x=-1,y=0,S=0,v=.3;n.masks.forEach((ue,ye)=>{if(ye===e)return;let fe=Lt(ue),we=Math.min(g.right,fe.right)-Math.max(g.left,fe.left);if(!(we<=0||we<Math.min(i.width,ue.width)*v))if(r==="bottom"){if(fe.top<=i.top)return;(x===-1||fe.top<y)&&(x=ye,y=fe.top,S=fe.bottom)}else{if(fe.bottom>=i.top)return;(x===-1||fe.bottom>S)&&(x=ye,y=fe.top,S=fe.bottom)}});let T=ue=>o?.[ue]??null;if(x===-1){let ue=l/2,ye=r==="bottom"?ue-g.top:g.bottom+ue,fe=Math.max(s,Math.min(p,Math.max(s,ye)));return fe===u?!1:(i.top=r==="bottom"?g.top+fe/2:g.bottom-fe/2,i.height=fe,mr(i,h,u,T(e)),!0)}let C=r==="bottom"?g.top:y,R=r==="bottom"?S:g.bottom,w=R-C,E=Math.max(s,w-b-s),M=Math.max(s,Math.min(p,E)),P=w-b-M;if(P<s){let ue=w-b-s;if(ue<s||(M=Math.max(s,Math.min(p,ue)),P=w-b-M,P<s))return!1}if(M<=0||P<=0)return!1;let A,k;r==="bottom"?(A=C+M/2,k=R-P/2):(k=C+P/2,A=R-M/2);let O=new Map;O.set(e,{width:h,height:u}),O.set(x,{width:n.masks[x].width,height:n.masks[x].height}),i.top=A,i.height=M;let F=n.masks[x];F.top=k,F.height=P;for(let ue of[e,x]){let ye=O.get(ue);mr(n.masks[ue],ye.width,ye.height,T(ue))}let W=A-M/2,X=A+M/2,_=k-P/2,D=k+P/2,I=r==="bottom",H=I?W:_,z=I?X:D,U=I?_:W,$=I?D:X,K=I?g.top:y,G=I?g.bottom:S,J=I?y:g.top,B=I?S:g.bottom,j=r==="bottom"?g.bottom:g.top,Q=r==="bottom"?X:W,ie=typeof i.rowStart=="number"&&typeof i.rowEnd=="number"?{rowStart:i.rowStart,rowEnd:i.rowEnd}:null,ce=n.masks[x],me=ce&&typeof ce.rowStart=="number"&&typeof ce.rowEnd=="number"?{rowStart:ce.rowStart,rowEnd:ce.rowEnd}:null,Re=n.rows>0&&!!ie&&!!me,De=Re&&ie&&me?ie.rowStart<=me.rowStart?ie:me:null,tt=Re&&ie&&me?De===ie?me:ie:null,Pe=De?De.rowEnd+1:void 0,Ee=(ue,ye,fe)=>{let we=n.masks[ue],nt=we.width,je=we.height,Xe=Math.max(c,fe-ye);we.top=(ye+fe)/2,we.height=Xe,mr(we,nt,je,T(ue))};return n.masks.forEach((ue,ye)=>{if(ye===e||ye===x)return;let fe=Lt(ue),we=fe.top,nt=fe.bottom;if(Re&&De&&tt&&Pe!==void 0&&typeof ue.rowStart=="number"&&typeof ue.rowEnd=="number"){if(ue.rowStart===De.rowStart&&ue.rowEnd===De.rowEnd){Ee(ye,H,z);return}if(ue.rowStart===tt.rowStart&&ue.rowEnd===tt.rowEnd){Ee(ye,U,$);return}let vt=ue.rowStart===Pe,St=ue.rowEnd+1===Pe;if(!vt&&!St)return;let Dn=vt?Q+(r==="bottom"?b:0):we,Fn=St?Q-(r==="top"?b:0):nt;if(Fn-Dn<=0)return;Ee(ye,Dn,Fn);return}let je=.5;if(Math.abs(we-K)<je&&Math.abs(nt-G)<je){Ee(ye,H,z);return}if(Math.abs(we-J)<je&&Math.abs(nt-B)<je){Ee(ye,U,$);return}let Xe=Math.abs(we-j)<je,gt=Math.abs(nt-j)<je;if(!Xe&&!gt)return;let xt=Xe?Q:we,yt=gt?Q:nt;yt-xt<=0||Ee(ye,xt,yt)}),i.height!==u};var Ku=(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:si(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}},Qu=(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}},Zu=(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}},Ju=(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},Se=(n,e,t)=>n.get(`${e},${t}`),lt=(n,e,t)=>{let r=Se(n,e,t);return r?.isMerged&&r.mergeParent?{row:r.mergeParent.row,col:r.mergeParent.col}:{row:e,col:t}},gr=n=>{let e=Array.isArray(n.cellData)?n.cellData:null;if(e)return e;let t=[];return n.cellData=t,t},xr=n=>n.rows??3,li=n=>n.cols??3,Ka=n=>n.minCellHeight??40,qa=n=>n.minCellWidth??40,Qa=n=>{let e=li(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},Kr=(n,e)=>{let t=Array.isArray(n.columnWidths)?n.columnWidths:null;t?(t.length=0,t.push(...e)):n.columnWidths=e},nh=(n,e,t,r)=>{let o=xr(n),i=Ka(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},rh=(n,e,t,r)=>{let o=xr(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},Qr=(n,e,t)=>{let r=Qa(n);e<0||e>=r.length||(r[e]=Math.max(qa(n),t),Kr(n,r))},Zr=(n,e,t)=>{let r=xr(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(Ka(n),t),n.manualRowHeights=i},Za=(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=Se(n,s,a);if(l){if(l.isMerged&&l.mergeParent){let c=Se(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}},qb=(n,e,t)=>{for(let r=t.r1;r<=t.r2;r++)for(let o=t.c1;o<=t.c2;o++){let i=Se(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}},Kb=(n,e)=>{let t=[];for(let r=e.r1;r<=e.r2;r++)for(let o=e.c1;o<=e.c2;o++){let i=Se(n,r,o)?.text;i&&i.trim()&&t.push(i.trim())}return t.join(`
5
+ `)},Ja=(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=Se(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=""}},Jr=(n,e,t,r,o)=>{let i=gr(n),s=It(i),a=Za(s,Math.min(e,r),Math.max(e,r),Math.min(t,o),Math.max(t,o));qb(i,s,a);let l=Se(s,a.r1,a.c1);return l&&(l.text=Kb(s,a),l.colspan=a.c2-a.c1+1,l.rowspan=a.r2-a.r1+1,Ja(i,s,a.r1,a.c1,l.rowspan,l.colspan)),a},eo=(n,e,t)=>{let r=It(gr(n)),o=Se(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=Se(r,a,l);c&&(c.isMerged=!1,c.mergeParent=null)}return!0},oh=n=>({cellFill:n.cellFill,textFill:n.textFill,fontSize:n.fontSize,fontWeight:n.fontWeight,fontFamily:n.fontFamily,fontStyle:n.fontStyle,textAlign:n.textAlign}),ih=(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}),ci=(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)},sh=(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},to=(n,e)=>{let t=xr(n),r=li(n),o=gr(n),i=It(o),s=Math.max(0,Math.min(e,t)),a=sh(o,"row",s),l=s>0?s-1:s<t?s:null;ci(o,"row",s,1);for(let u=0;u<r;u++){let h=l!==null?Se(i,l,u):void 0;o.push(ih(h,oh(n),s,u))}nh(n,s,0,Ka(n)),rh(n,s,0,null),n.rows=t+1;let c=It(o);for(let u of a)u.rowspan=(u.rowspan??1)+1,Ja(o,c,u.row,u.col,u.rowspan??1,u.colspan??1)},el=(n,e)=>{let t=xr(n);if(t<=1)return!1;let r=Math.max(0,Math.min(e,t-1)),o=gr(n),i=0;for(let s of o)s.row!==r&&(o[i++]=s);return o.length=i,ci(o,"row",r+1,-1),nh(n,r,1),rh(n,r,1),n.rows=t-1,!0},no=(n,e)=>{let t=xr(n),r=li(n),o=gr(n),i=It(o),s=Qa(n),a=Math.max(0,Math.min(e,r)),l=sh(o,"col",a),c=a>0?a-1:a<r?a:null;ci(o,"col",a,1);for(let d=0;d<t;d++){let f=c!==null?Se(i,d,c):void 0;o.push(ih(f,oh(n),d,a))}n.cols=r+1;let u=Math.max(qa(n),c!==null?s[c]:qa(n));s.splice(a,0,u),Kr(n,s);let h=It(o);for(let d of l)d.colspan=(d.colspan??1)+1,Ja(o,h,d.row,d.col,d.rowspan??1,d.colspan??1)},tl=(n,e)=>{let t=li(n);if(t<=1)return!1;let r=Math.max(0,Math.min(e,t-1)),o=gr(n),i=Qa(n),s=0;for(let a of o)a.col!==r&&(o[s++]=a);return o.length=s,ci(o,"col",r+1,-1),n.cols=t-1,i.splice(r,1),Kr(n,i),!0},qn=n=>n.columnWidths.reduce((e,t)=>e+t,0)+(n.cols-1)*n.cellSpacing,Kn=n=>n.rowHeights.reduce((e,t)=>e+t,0)+(n.rows-1)*n.cellSpacing,pr=(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},br=(n,e,t)=>{let r=e==="col"?n.columnWidths:n.rowHeights,o=e==="col"?qn(n):Kn(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},eh=(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},th=(n,e,t,r)=>{if(e==="col"){let i=Se(n,r,t-1);if(!i)return!1;if(i.isMerged&&i.mergeParent){let s=Se(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=Se(n,t-1,r);if(!o)return!1;if(o.isMerged&&o.mergeParent){let i=Se(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},nl=(n,e,t,r,o,i)=>{let s=t+qn(n)/2,a=r+Kn(n)/2,l=o,c=i,u=pr(n.rowHeights,n.cellSpacing,a),h=pr(n.columnWidths,n.cellSpacing,s),d=eh(n.columnWidths,n.cellSpacing,s,l,a,Kn(n));if(d>0&&u>=0&&!th(e,"col",d,u))return{type:"col",index:d,position:br(n,"col",d)};let f=eh(n.rowHeights,n.cellSpacing,a,c,s,qn(n));return f>0&&h>=0&&!th(e,"row",f,h)?{type:"row",index:f,position:br(n,"row",f)}:null},ah=(n,e,t,r)=>{let o=t+qn(n)/2,i=r+Kn(n)/2,s=pr(n.columnWidths,n.cellSpacing,o);if(s<0)return null;let a=pr(n.rowHeights,n.cellSpacing,i);return a<0?null:lt(e,a,s)},lh=(n,e,t,r,o)=>{let i=o.indicatorOffset??15,s=o.indicatorRadius??8,a=Kn(n)/2,l=qn(n)/2;for(let u=1;u<=n.cols;u++){let h=br(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=br(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=nl(n,e,t,r,o.thresholdX,o.thresholdY);return c?{border:c,inCircle:!1}:null},ro=(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=qn(n)/2,a=Kn(n)/2;return{left:t-s,top:o-a,width:r,height:i}},oo=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},un=(n,e,t)=>oo((()=>{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})()),ui=(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 oo(r)},hi=(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 oo(r)},io=(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 oo(r)},We=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}},di=(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=oo(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=We(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}},ch=(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,Qb=["ew","nwse","ns","nesw"],uh=(n,e)=>{let t=e==="col"?0:2,r=(n%180+180)%180,o=Math.round(r/45)%4;return`${Qb[(t+o)%4]}-resize`};var ai=(n,e)=>{let t=Math.abs(n)*Math.max(e,1e-6);return t>1e-6?20/t:20},hh=(n,e,t,r,o,i={x:1,y:1},s=1)=>{if(o<-t/2&&o>=-t/2-ai(i.y,s)){let a=pr(n.columnWidths,n.cellSpacing,r+qn(n)/2);if(a>=0)return{kind:"col-strip",col:a}}if(r<-e/2&&r>=-e/2-ai(i.x,s)){let a=pr(n.rowHeights,n.cellSpacing,o+Kn(n)/2);if(a>=0)return{kind:"row-strip",row:a}}return null},dh=(n,e,t,r,o={x:1,y:1},i=1)=>{let s=ai(o.x,i),a=ai(o.y,i);return t>=-n/2-s&&t<-n/2&&r>=-e/2-a&&r<-e/2};var fh=(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},yr=(n,e)=>{let t=new Set,r=new Set;for(let o of e){let i=lt(n,o.row,o.col),s=Se(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 fi=14,mh=(n,e,t)=>{let r=[0];for(let o=0;o<n-1;o++)r.push(r[o]+e[o]+t);return r},rl=(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},so=(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||"仓耳小丸子",g=Array.isArray(n.manualRowHeights)?n.manualRowHeights:[],b=Array.from({length:r},(_,D)=>typeof g[D]=="number"?g[D]:null),x=Array.isArray(n.cellData)?n.cellData:[],y=It(x),S=new Map;for(let _ of x){if(_.isMerged)continue;let D=Math.max(0,rl(_.col,_.colspan??1,a,u)-c*2);S.set(`${_.row},${_.col}`,{layout:Vn(_.text??"",{fontFamily:_.fontFamily||p,fontSize:_.fontSize??fi,fontWeight:_.fontWeight,fontStyle:_.fontStyle,lineHeight:1.16,charSpacing:0,textAlign:_.textAlign??pe.CENTER},{boxWidth:D,splitByGrapheme:!0,measure:e}),data:_})}let v=fi*ni,T=[],C=[];for(let _=0;_<r;_++){let D=0;for(let U=0;U<o;U++){if(y.get(`${_},${U}`)?.isMerged)continue;let $=S.get(`${_},${U}`);D=Math.max(D,$?$.layout.height:v)}let I=b[_],H=D+c*2,z=I!==null?I:l;C.push(H),T.push(Math.max(z,H))}let R=a.reduce((_,D)=>_+D,0)+(o-1)*u,w=T.reduce((_,D)=>_+D,0)+(r-1)*u,E=mh(o,a,u),M=mh(r,T,u),P=typeof n.id=="string"&&n.id?n.id:"table",A=[];for(let _=0;_<r;_++)for(let D=0;D<o;D++){let I=y.get(`${_},${D}`);if(I?.isMerged)continue;let H=I?.colspan??1,z=I?.rowspan??1,U=rl(D,H,a,u),$=rl(_,z,T,u),K=E[D]-R/2+U/2,G=M[_]-w/2+$/2;A.push({type:"rect",id:`${P}-r${_}c${D}-rect`,left:K,top:G,width:U,height:$,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 J=I?S.get(`${_},${D}`):void 0,B=t?.hideTextCell!==void 0&&t.hideTextCell.row===_&&t.hideTextCell.col===D;if(J&&!B&&(I?.text??"")!==""){let j=J.layout.height,Q=I?.verticalAlign??"middle",ie=G;Q==="top"?ie=G-$/2+j/2+c:Q==="bottom"&&(ie=G+$/2-j/2-c),A.push({type:"textbox",id:`${P}-r${_}c${D}-text`,left:K,top:ie,width:Math.max(0,U-c*2),text:I?.text??"",fill:I?.textFill??m,fontFamily:I?.fontFamily||p,fontSize:I?.fontSize??fi,fontWeight:I?.fontWeight,fontStyle:I?.fontStyle,textAlign:I?.textAlign??pe.CENTER,lineHeight:1.16,splitByGrapheme:!0,originX:"center",originY:"center",scaleX:1,scaleY:1,angle:0,opacity:1,visible:!0})}}let k=Math.max(l,fi*ni+c*2),O=o*s+(o-1)*u+h,F=r*k+(r-1)*u+h,W=R+h,X=w+h;return{rowHeights:T,rowTextFloors:C,columnWidths:a,contentWidth:R,contentHeight:w,width:W,height:X,children:A,constructorDims:{width:O,height:F}}};var _t="WorkSpaceDrawType",Dt=new Set(["WorkSpaceDrawType","WorkSpaceClipType","WorkSpaceSafeType","WorkSpaceMaskType","WorkSpaceLineType","WorkSpaceShadowType"]),$t=n=>n.isTextType&&typeof n.raw.renderSrc=="string",ao=n=>{let e=n.fill;return typeof e!="string"||!e?1:Math.max(0,Math.min(1,ae(e)[3]))},Zb=new Set(["left","top","angle","scaleX","scaleY","skewX","skewY","flipX","flipY","originX","originY"]),Jb=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"]),sl=n=>{for(let e in n)if(!Zb.has(e))return!1;return!0},pi=999999,Qe=n=>n.isReferenceLine,yh=(n,e)=>({type:"ReferenceLine",id:`referenceline-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`,name:"ReferenceLine",axis:n,x1:n==="horizontal"?-pi:0,y1:n==="horizontal"?0:-pi,x2:n==="horizontal"?pi:0,y2:n==="horizontal"?0:pi,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"}),eg=["type","left","top","width","height","angle","scaleX","scaleY","skewX","skewY","flipX","flipY","originX","originY","strokeWidth","strokeUniform","fill","opacity","visible","src","crossOrigin","id","name"],ut=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},bu(this.raw),this._typeKey=ee(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=ei(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){gu(this.raw,e),Object.assign(this.raw,e),this.invalidateGeometryCache(),sl(e)||(this._fillPaint=void 0,this._strokeDecl=void 0),"type"in e&&(this._typeKey=ee(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 ft.has(this.typeKey)}get isMaskType(){return rt.has(this.typeKey)}get isSolidType(){return Gn.has(this.typeKey)}get isTextType(){return on.has(this.typeKey)}get isLineType(){return mt.has(this.typeKey)}get isShapeType(){return Wn.has(this.typeKey)}get visible(){return this.raw.visible!==!1}get fillPaint(){if(this._fillPaint===void 0){let e=hr(this.raw.fill),t=e?null:Uo(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:ae(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=ae(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?Y(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=Pa(this.transformProps)),!this._parentMatrix)return this._aCoords;let e=this._parentMatrix;return{tl:V(e,this._aCoords.tl.x,this._aCoords.tl.y),tr:V(e,this._aCoords.tr.x,this._aCoords.tr.y),br:V(e,this._aCoords.br.x,this._aCoords.br.y),bl:V(e,this._aCoords.bl.x,this._aCoords.bl.y)}}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 Z)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=ka(this.aCoords)),this._bounds}containsPoint(e,t,r=0){if(this.isSolidType&&!xi(this))return al(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))<=ll(this,r)}localPoint(e,t){return V(Te(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 yi(this.raw)}toObject(){let e={};for(let t of eg)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}},tg=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}},ng=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}},ge=class extends ut{_layout=null;_arcDims=null;_scrollOffset=0;constructor(e){super(e)}set(e){super.set(e),sl(e)||(this.invalidateTextLayout(),typeof this.raw.renderSrc=="string"&&Object.keys(e).some(t=>Jb.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??pe.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;this._layout=Vn(e.text??"",this.textStyle,{boxWidth:ee(e)===L.TEXTBOX||ee(e)===L.TEXTIMAGE?e.width??0:null,styles:e.styles,splitByGrapheme:e.splitByGrapheme===!0,vertical:e.vertical===!0,paragraph:Ke(e)?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(Ke(this.raw)){if(!this._arcDims){let t=Mt(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(){if(typeof this.raw.renderSrc=="string"){let e=this.bitmapRect,t=ng(e)??tg(e);if(t||e.angle!==0||e.x!==0||e.y!==0){let r=this.ownMatrix;(e.x!==0||e.y!==0)&&(r=Y(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=Y(r,[1,0,0,1,e.fx,e.fy])),!t&&e.angle!==0&&(r=Y(r,At({angle:-e.angle})));let o=this.parentMatrix,i=(l,c)=>{let u=V(r,l,c);return o?V(o,u.x,u.y):u},s=(t?t.w:e.w)/2,a=(t?t.h:e.h)/2;return{tl:i(-s,-a),tr:i(s,-a),br:i(s,a),bl:i(-s,a)}}}return super.aCoords}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:cn(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===`
6
+ `,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]}},rg=(n,e)=>Math.max(24,Math.min(128,Math.ceil((n+e)*.6))),ph=(n,e)=>{if(!(n>0)||!(e>0))return null;let t=rg(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}},bh=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=Oa(c);return u.length>0?{verts:l,triangles:new Uint32Array(u)}:null},og=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 Oa(i))r.push(s+o);o+=i.length}return r.length>0?{verts:t,triangles:new Uint32Array(r)}:null},ig=n=>{let e=Ae(n);if(!e)return{contours:[],dims:{x:0,y:0}};let t=qe(e),r=ku(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}}},hn=class extends ut{_mesh;set(e){super.set(e),sl(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=ph(e.rx??0,e.ry??0);else if(t===L.CIRCLE){let r=e.radius??0;this._mesh=ph(r,r)}else t===L.TRIANGLE?this._mesh=bh(gh(e)):this._mesh=bh(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}:sg(e.points)}containsPoint(e,t,r=0){if(!xi(this))return al(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?xh(s.verts,o.x,o.y):ol(this.raw.points,o,i===L.POLYGON,Math.max((Number(this.raw.strokeWidth)||1)/2,3,r)):s?xh(s.verts,o.x,o.y):!1}outlineStrokeHitAt(e,t,r=0){let o=this.localPoint(e,t),i=this.shapeKind,s=ll(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?ol(gh(this.raw),o,!0,s):ol(this.raw.points,o,i===L.POLYGON,s)}},gh=n=>{let e=n.width??0,t=n.height??0;return[{x:e/2,y:0},{x:e,y:t},{x:0,y:t}]},sg=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}},gi=10,il=n=>Math.min(1,Math.max(0,n)),ag=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},xi=n=>{let e=ag(n);return e===null||e*255>gi},al=n=>{let e=n.raw.stroke;return typeof e=="object"&&e!==null?!0:typeof e!="string"||!e||Number(n.raw.strokeWidth)===0?!1:il(ae(e)[3])*n.renderOpacity*255>gi},ll=(n,e)=>Math.max((Number(n.raw.strokeWidth)||1)/2,3,e),cl=8,vh=n=>{let e=n.typeKey;return e===L.LINE||e===L.ARROW||e===L.DIMENSION||e===L.POLYLINE?!0:(n.isShapeType||n.isSolidType)&&!xi(n)},bi=(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},ol=(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(bi(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(bi(e.x,e.y,d.x-c,d.y-u,o[0].x-c,o[0].y-u)<=h)return!0}return!1},vr=class extends hn{_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=ig(this.raw.path)),this._pathGeo}get fillPolygons(){if(this._fillPolys===void 0){let e=this.raw.fillRule==="evenodd"?"evenodd":"nonzero";this._fillPolys=Nu(this.pathGeometry.contours,e)}return this._fillPolys}get shapeMesh(){return this._pathMesh===void 0&&(this._pathMesh=og(this.fillPolygons)),this._pathMesh}get dims(){return this.pathGeometry.dims}containsPoint(e,t,r=0){return xi(this)?ut.prototype.containsPoint.call(this,e,t):al(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=ll(this,r)**2;for(let a of i){let l=a.points;for(let c=0;c+1<l.length;c++)if(bi(o.x,o.y,l[c].x,l[c].y,l[c+1].x,l[c+1].y)<=s)return!0}return!1}},lg=(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),g=Math.sin(m),b=e.x-d,x=e.y-f,y=b*p+x*g,S=-b*g+x*p;return y<-c||y>0?!1:Math.abs(S)<=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))},cg=(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=zr(`${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[C,R]of[[t.x1,t.y1],[t.x2,t.y2]])if(bi(e.x,e.y,C-c*h,R-u*h,C+c*h,R+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,g=n.textFollowLine===!1?0:l,b=Math.cos(g),x=Math.sin(g),y=e.x-m,S=e.y-p,v=y*b+S*x,T=-y*x+S*b;return Math.abs(v)<=a/2&&Math.abs(T)<=(o+i*2)/2},Sr=class extends ut{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?lg(this.raw,i,o):f===L.DIMENSION?cg(this.raw,i,o,d):!1}},re=class extends ut{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}}},xh=(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},Z=class n extends ut{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}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 se)?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 Z{_layout;_childFactory;_placedShift;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=so(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 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 ah(this.tableView,this.cellMap,r.x,r.y)}borderHit(e,t){let r=this.localPoint(e,t),o=this.objectScale;return nl(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 lh(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 hh(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 dh(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??We(this.selectedCells);return e?Za(this.cellMap,e.r1,e.r2,e.c1,e.c2):null}get selectionBoundsRect(){let e=this.expandedCellRange;return e?ro(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 fh(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=hi(this.cellMap,this.tableView.cols,e);this.setCellSelection(t,t[0]??null,We(t))}setColumnSelection(e){let t=ui(this.cellMap,this.tableView.rows,e);this.setCellSelection(t,t[0]??null,We(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=Se(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 ro(o,{r1:e,r2:e+s-1,c1:t,c2:t+i-1})}cellSceneCenter(e,t){let r=this.cellBounds(e,t);return r?V(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=(g,b)=>({x:e==="left"?-g/2:e==="right"?g/2:0,y:t==="top"?-b/2:t==="bottom"?b/2:0}),o=this.dims.x,i=this.dims.y,s=Bn({...this.raw,width:o,height:i}),a=V(s,r(o,i).x,r(o,i).y),l=so(this.raw,void 0,this.editingCell?{hideTextCell:this.editingCell}:void 0);this._layout=l;let c=[];for(let g of l.children){let b=this._childFactory(g);b&&c.push(b)}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=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)}}},le=class extends ut{_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=ee(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(()=>{})}},se=class extends Z{constructor(e,t){super(e,t);let r=this.layoutParams,o=jn(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()}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 g=d.x0<=f.x0?s[u]:s[h],b=g===s[u]?s[h]:s[u],x=l(g),y=l(b);if(x.x1>y.x0+i){if(Math.abs(x.x1-r)<i&&y.x0<r-i){let R=a.get(g)??{};R.right=y.x0-e,a.set(g,R)}else if(Math.abs(y.x0+r)<i&&x.x1>-r+i){let R=a.get(b)??{};R.left=x.x1+e,a.set(b,R)}}let S=d.y0<=f.y0?s[u]:s[h],v=S===s[u]?s[h]:s[u],T=l(S),C=l(v);if(T.y1>C.y0+i){if(Math.abs(T.y1-o)<i&&C.y0<o-i){let R=a.get(S)??{};R.bottom=C.y0-t,a.set(S,R)}else if(Math.abs(C.y0+o)<i&&T.y1>-o+i){let R=a.get(v)??{};R.top=T.y1+t,a.set(v,R)}}}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,g=h.bottom??d.y1;if(!(m-f>i)||!(g-p>i))continue;let b={left:(f+m)/2,width:m-f,top:(p+g)/2,height:g-p};u.set(b),c.push(`${String(u.raw.id)}→${Math.round(b.left)},${Math.round(b.top)},${Math.round(b.width)}×${Math.round(b.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 le)}containsPoint(e,t,r=0){return super.containsPoint(e,t,r)?!0:this.visible?ut.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=jn(this.raw.layoutConfig);r&&this.relayoutFromConfig(r,this.layoutParams)}updateLayout(e){let t=jn(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=jn(this.raw.layoutConfig);if(!t||t.pieces.length!==this.maskChildren.length)return!1;let r=Qu(t.pieces,t.cols,e);return r?(t.cols-=1,this.applyPuzzleRemoval(t,r.removed)):!1}removeRow(e){let t=jn(this.raw.layoutConfig);if(!t||t.pieces.length!==this.maskChildren.length)return!1;let r=Zu(t.pieces,t.rows,e);return r?(t.rows-=1,this.applyPuzzleRemoval(t,r.removed)):!1}removePiece(e){let t=jn(this.raw.layoutConfig);if(!t||t.pieces.length!==this.maskChildren.length)return!1;let r=Ju(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 le&&r.has(this.maskChildren.indexOf(s)))),i=o.filter(s=>s instanceof le).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=ja(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,g=f*(p||1);o.set({clipImage:{...c,scaleX:g,scaleY:g}})}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})}},yi=n=>{if(!ft.has(ee(n)))return null;let e=Number(n.cropX)||0,t=Number(n.cropY)||0;if(!(e>0||t>0)||typeof n.width!="number"||typeof n.height!="number")return null;let r=n.cropSizeMode==="visible";return{sx:e,sy:t,sw:Math.max(0,r?n.width:n.width-e),sh:Math.max(0,r?n.height:n.height-t)}},ct=n=>{if(!n||typeof n.type!="string")return null;let e=ee(n);return e===L.TABLE?new te(n,ct):Vo.has(e)?new se(n,ct):rt.has(e)&&typeof n.src=="string"?new le(n):e===L.GROUP?new Z(n,ct):jo.has(e)&&typeof n.src=="string"?new re(n,"gif"):qo.has(e)&&typeof n.src=="string"?new re(n,"video"):ft.has(e)&&typeof n.src=="string"?new ut(n):Gn.has(e)?new ut(n):on.has(e)&&typeof n.text=="string"?new ge(n):e===L.PATH?new vr(n):mt.has(e)?new Sr(n):Wn.has(e)?new hn(n):null},ul=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}},Ze=(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}),vi=n=>{if(n instanceof Z||n instanceof le||n instanceof re||n.isImageType)return null;let e=n.raw.mask;return!e||e.disabled===!0||typeof e.src!="string"||!e.src?null:e.src};var Si=n=>typeof n!="string"||n.length===0?!1:/^data:image\/svg\+xml/i.test(n)?!0:/\.svg(?:[?#]|$)/i.test(n),Sh=(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}},wh=(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 wi=(n,e)=>{if(n.children.includes(e))return[n];for(let t of n.children)if(t instanceof Z&&!(t instanceof te)&&!(t instanceof se)){let r=wi(t,e);if(r.length)return[...r,n]}return[]},Th=n=>{let e=n.matrix,t=n.ownMatrix,r=Te(e),o=(i,s,a)=>V(i,s,a,!0);return(i,s)=>{let a=o(r,i,s);return o(t,a.x,a.y)}},Eh=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=typeof i.raw.strokeWidth=="number"?i.raw.strokeWidth:0,a=i.dims.x/2,l=i.dims.y/2,c=i.raw.strokeUniform===!0?a:a+s/2,u=i.raw.strokeUniform===!0?l:l+s/2,h=i.raw.strokeUniform===!0?s/2:0,d=i.ownMatrix;for(let f of[-c,c])for(let m of[-u,u]){let p=V(d,f,m);p.x-h<e&&(e=p.x-h),p.y-h<t&&(t=p.y-h),p.x+h>r&&(r=p.x+h),p.y+h>o&&(o=p.y+h)}}return Number.isFinite(e)?{minX:e,minY:t,maxX:r,maxY:o}:null},Mh=n=>{let e=Eh(n);if(!e)return null;let t=n.matrix;return{tl:V(t,e.minX,e.minY),tr:V(t,e.maxX,e.minY),br:V(t,e.maxX,e.maxY),bl:V(t,e.minX,e.maxY)}},hl=n=>{let e=[];for(let t=0;t<n.length;t++){let r=n[t],o=Eh(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=V(r.matrix,a.x,a.y),u=n[t+1]??null,h=u?V(Te(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=Te(r.matrix);for(let m of r.children){let p=l.get(m);if(!p)continue;let g=V(f,p.x,p.y),b=xe({...m.raw,width:m.dims.x,height:m.dims.y},g);m.set({left:b.x,top:b.y})}e.push(r,...r.children)}return e};var dl=["tl","tr","bl","br"],dn=new Set(dl),Ti=["tlS","trS","blS","brS"],ug=new Set(Ti),lo={tlS:"tl",trS:"tr",blS:"bl",brS:"br"},hg=new Set(["ml","mr","mt","mb"]),Qn={ml:"x",mr:"x",mt:"y",mb:"y"},Ei={ml:"left",mr:"right",mt:"top",mb:"bottom"},Zn=n=>hg.has(n),Mi=n=>dn.has(n),wr=n=>ug.has(n);var gn=8,Jn=12,Ct=1.5,Ch=24,dg=["lockMovementX","lockMovementY","lockScalingX","lockScalingY","lockSkewingX","lockSkewingY","lockRotation"],st=n=>{let e=n.raw;return dg.some(t=>!!e[t])},Ai=28,fl=null,fg=()=>{if(fl)return fl;let n=document.createElement("canvas");n.width=Ai*2,n.height=Ai*2;let e=n.getContext("2d");if(e){e.scale(2,2);let t=Ai/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 fl=n,n},Ni=28,mg="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",ml=null,pg=()=>{if(ml)return ml;let n=document.createElement("canvas");n.width=Ni*2,n.height=Ni*2;let e=n.getContext("2d");if(e){e.scale(2,2);let t=Ni/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(mg)))}return ml=n,n};var bg=24,Li=20,Ph=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",pl=null,xg=()=>{if(pl)return pl;let n=document.createElement("canvas");n.width=Li*2,n.height=Li*2;let e=n.getContext("2d");if(e){e.scale(2,2);let t=Li/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 pl=n,n},yl=n=>{if(n.selection.length!==1)return null;let e=n.selection[0];if(e instanceof te||e instanceof se)return null;let t=e.typeKey;return mt.has(t)||rt.has(t)||st(e)?null:e},vl=(n,e,t)=>Oi(n,e,t,{x:.5,y:0,offsetX:bg,offsetY:0}),mn=3,bl=new Map,yg=n=>{let e=bl.get(n);if(e)return e;let t=document.createElement("canvas"),r=t.getContext("2d"),o=`bold ${14*mn}px Helvetica, Arial, sans-serif`;if(!r)return t.width=Math.max(1,Math.round((n.length*14*.6+16)*mn)),t.height=Math.round(30*mn),bl.set(n,t),t;r.font=o;let i=r.measureText(n).width,s=8*mn;t.width=Math.max(1,Math.ceil(i)+s*2),t.height=Math.ceil(30*mn),r.font=o;let a=6*mn;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),bl.set(n,t),t},vg=(n,e,t)=>{let r=yg(`${Math.round(e)}°`);return{matrix:[1,0,0,1,n.x,n.y],dims:{x:r.width/mn/t,y:r.height/mn/t},color:[1,1,1,1],texture:r}},it=ae("#2f6fed"),co=ae("#ffffff"),Ci=ae("#2f6fed"),Sl=it,Ri=(n,e)=>({x:(n.x+e.x)/2,y:(n.y+e.y)/2}),Ce=(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}},pn=(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}},Sg=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)}},Je=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:Sg(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}},Er=(n,e,t=1,r)=>{let o=Ri(n.tl,n.tr),i=Ri(n.tr,n.br),s=Ri(n.bl,n.br),a=Ri(n.tl,n.bl),l=Fg(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?Cg(r,t):[];return u.length?[...u,...c]:c},wg=32,Tg=.25,_i=14,kh=n=>n<=0?0:Math.min(wg,n*Tg),Ah=(n,e)=>{if(e<=0)return 0;let t=Math.max(0,Math.min(e,n)),r=kh(e);return r<=0||e<=r?t:r+t/e*(e-r)},wl=(n,e)=>{if(e<=0)return 0;let t=Math.max(0,Math.min(e,n)),r=kh(e);return r<=0||e<=r?t:t<=r?0:(t-r)/(e-r)*e},Di=n=>!!n&&n.typeKey===L.FABRICRECT,Eg=new Set([L.QRCODE,L.BARCODE,L.ECHART,L.FABRIC_ECHART]),uo=n=>{if(!n)return!1;let e=ee(n.raw);return!Eg.has(e)&&(e===L.IMAGE||e===L.SVGIMAGE||e===L.CROPIMAGE)},Nh=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>Tr&&o>Tr},Cg=(n,e)=>Mg(n,e)?Di(n)?Rg(n,e):uo(n)?Pg(n,e):[]:[],Rg=(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=Ah(u,c),d=Math.max(0,(_i-h*e)/e),f=Math.max(0,(_i-h*e)/e),m=h+Math.min(d,Math.max(0,a-h)),p=h+Math.min(f,Math.max(0,l-h)),g=n.matrix;return Ti.map(b=>{let x=lo[b],y=x==="tl"||x==="bl",S=x==="tl"||x==="tr",v=(y?-a+m:a-m)/r,T=(S?-l+p:l-p)/o;return{id:b,x:g[0]*v+g[2]*T+g[4],y:g[1]*v+g[3]*T+g[5]}})},Pg=(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=Ah(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,(_i-a*u)/u),Math.max(0,r-a)),f=Math.min(Math.max(0,(_i-a*h)/h),Math.max(0,o-a)),m=n.matrix;return Ti.map(p=>{let g=lo[p],b=g==="tl"||g==="bl",x=g==="tl"||g==="tr",y=b?-r+a+d:r-a-d,S=x?-o+a+f:o-a-f;return{id:p,x:m[0]*y+m[2]*S+m[4],y:m[1]*y+m[3]*S+m[5]}})},Ii=12,Pi=null,kg=()=>{if(Pi)return Pi;let n=document.createElement("canvas");n.width=Ii*2,n.height=Ii*2;let e=n.getContext("2d");if(e){e.scale(2,2);let t=Ii/2,r=gn/2;e.beginPath(),e.arc(t,t,r+Ct,0,Math.PI*2),e.fillStyle=`rgb(${it[0]*255},${it[1]*255},${it[2]*255})`,e.fill(),e.beginPath(),e.arc(t,t,r,0,Math.PI*2),e.fillStyle=`rgb(${co[0]*255},${co[1]*255},${co[2]*255})`,e.fill()}return Pi=n,Pi},Lh=16,fn=4,Rh={tlr:{x:-.5,y:-.5,offsetX:-fn,offsetY:-fn},trr:{x:.5,y:-.5,offsetX:fn,offsetY:-fn},brr:{x:.5,y:.5,offsetX:fn,offsetY:fn},blr:{x:-.5,y:.5,offsetX:-fn,offsetY:fn}},Tl={tlr:0,trr:90,brr:180,blr:270},Tr=50,El=(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}),Ag=(n,e)=>{let{width:t,height:r}=El(n,e);return t>Tr&&r>Tr},Ng=new Set(["mr","br","mtr"]),Lg=new Set(["mr","br"]),Ig=new Set(["mr","br","mtr"]),_g=new Set(["ml","mr","tl","tr","bl","br","tlS","trS","blS","brS"]),Dg=new Set(["mt","mb","tl","tr","bl","br","mtr","tlS","trS","blS","brS"]),Ih=(n,e,t)=>{let r=e<=Tr,o=t<=Tr;return!r&&!o?!0:r&&o?Ng.has(n):!(r&&_g.has(n)&&!Lg.has(n)||o&&Dg.has(n)&&!Ig.has(n))},_h=n=>n instanceof se||n instanceof te||rt.has(n.typeKey),ho=(n,e,t,r,o)=>{let i=Er(e,t,r,o),s=n.selection.length===1?n.selection[0]:null;if(!s||_h(s))return i;let a=mt.has(s.typeKey),l=El(e,r);return i.filter(c=>a&&(c.id==="ml"||c.id==="mr")||Ih(c.id,l.width,l.height))},Ml=(n,e)=>{let t=n.aCoords,r=n.worldAngle,o=Er(t,r,e);if(_h(n))return o;let i=mt.has(n.typeKey),s=El(t,e);return o.filter(a=>i&&(a.id==="ml"||a.id==="mr")||Ih(a.id,s.width,s.height))},Dh=(n,e,t)=>Ag(n,t)?Object.keys(Rh).map(r=>{let o=Oi(n,e,t,Rh[r]);return{id:r,x:o.x,y:o.y}}):[],Fi=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*Ch,offsetY:0}}let o=Math.sign(r);return{x:0,y:o/2,offsetX:0,offsetY:o*Ch}},Oi=(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}},Fg=(n,e,t)=>Oi(n,e,t,Fi(e)),bn=(n,e)=>{let t=Ct/e;return[Ce(n.tl,n.tr,t,it),Ce(n.tr,n.br,t,it),Ce(n.br,n.bl,t,it),Ce(n.bl,n.tl,t,it)]},Og=3,ki=(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=Og/o,h=[];for(let d=0;d<a;d+=u*2){let f=Math.min(d+u,a);h.push(Ce({x:n.x+l*d,y:n.y+c*d},{x:n.x+l*f,y:n.y+c*f},t,r))}return h},Bi=(n,e)=>{let t=Ct/e;return[...ki(n.tl,n.tr,t,it,e),...ki(n.tr,n.br,t,it,e),...ki(n.br,n.bl,t,it,e),...ki(n.bl,n.tl,t,it,e)]},Bg=(n,e,t,r)=>{let o=Ct/r,i=gn/r;for(let s of e)s.id==="mtr"?n.push({...pn(s,Ni/r,[1,1,1,1],t),texture:pg()}):wr(s.id)?n.push({...pn(s,Ii/r,[1,1,1,1],t),texture:kg()}):(n.push(pn(s,i,it,t)),n.push(pn(s,i-2*o,co,t)))},gl=(n,e,t,r,o,i)=>{if(i?.spec){let s=e.find(l=>l.id==="mtr"),a=Oi(t,r,o,i.spec);s.x=a.x,s.y=a.y}Bg(n,e,r,o),i&&n.push(vg(i.center,r,o))},Fh=(n,e,t=null,r=!1)=>{if(n.selection.length===1&&Qe(n.selection[0]))return[];let o=Je(n);if(!o)return[];let{quad:i,angle:s}=o,a=[],l=n.activeGroupChild,c=l&&n.groupEditing&&n.selection[0]instanceof Z&&!(n.selection[0]instanceof te)&&!(n.selection[0]instanceof se)?n.selection[0]:null,h=(c?Mh(c):null)??i;if(l)a.push(...bn(l.aCoords,e)),a.push(...Bi(h,e));else{if(n.selection.length>=2)for(let d of n.selection)a.push(...bn(d.aCoords,e));a.push(...bn(i,e))}if(n.selection.length===1&&st(n.selection[0]))return a.push({...pn(i.br,Ai/e,[1,1,1,1],s),texture:fg()}),a;if(gl(a,ho(n,h,s,e,fo(n)),h,s,e,t?.onChild?null:t),l&&n.groupEditing&&gl(a,Ml(l,e),l.aCoords,l.worldAngle,e,t?.onChild?t:null),r&&yl(n)){let d=vl(h,s,e);a.push({...pn(d,Li/e,[1,1,1,1],0),texture:xg()})}return a},fo=n=>{if(n.selection.length!==1)return null;let e=n.selection[0];return Di(e)||uo(e)?e:null},Oh=(n,e)=>{let t=Ct/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[Ce(r,o,t,Ci),Ce(o,i,t,Ci),Ce(i,s,t,Ci),Ce(s,r,t,Ci)]},mo=n=>{let e=n.editingMask;if(!e)return[];let t=e.aCoords;return Er(t,e.worldAngle).filter(o=>Zn(o.id)?!n.maskEdgeOnOuterBorder(e,Ei[o.id]):!1)},Bh=(n,e,t=null)=>{let r=n.editingMask;if(!r)return[];let o=r.worldAngle,i=bn(r.aCoords,e),s=Ct/e,a=gn/e;for(let c of mo(n))i.push(pn(c,a,it,o)),i.push(pn(c,a-2*s,co,o));let l=n.raw.angle??0;return i.push(...Bi(n.aCoords,e)),gl(i,Er(n.aCoords,l),n.aCoords,l,e,t),i},Hg=2.5,xl=(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;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}},Cl=n=>{let e=[];for(let i of n.maskChildren)i.visible&&(n.maskEdgeOnOuterBorder(i,"right")||e.push(xl(n,i,"mr")),n.maskEdgeOnOuterBorder(i,"bottom")||e.push(xl(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,g=Math.min(m,p),b=Math.max(m,p);return g<=u+r&&b>=-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},Hh=(n,e,t)=>Cl(n).find(o=>o.mask===e&&o.handle===t)??xl(n,e,t),Wh=(n,e)=>[Ce(n.p1,n.p2,Hg/e,Sl)],Wg=ae("#3c7eff"),Gg=2,Xg=(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}},Hi=(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)=>Xg(c,r[(u+1)%4],o)),s=n.bounds,a=Math.min(Gg,(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(Ce({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,Wg))}return l};function Gh(n,e,t,r){let o=n.selection.map(l=>l.id),i=Je(n);if(!i||n.editingNode||e)return{ids:o,handles:[]};let s=n.selection.length===1&&n.selection[0]instanceof se?n.selection[0]:null,a=s?.editingMask?[...mo(s).map(l=>{let c=r(l.x,l.y);return{id:l.id,x:c.x,y:c.y}}),...Er(i.quad,i.angle,t).map(l=>{let c=r(l.x,l.y);return{id:l.id,x:c.x,y:c.y}})]:ho(n,i.quad,i.angle,t,fo(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 Xh(n){let e=n.activeGroupChild;if(!e)return null;let t=n.selection[0];return!(t instanceof Z)||!t.containsDeep(e)?null:{rootId:t.id,childId:e.id}}function zh(n,e){let t=[],r=o=>{for(let i of o){if(i instanceof Z&&r(i.children),!i.imageEl||!Si(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 Yh(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 Uh(n,e){e();let t=performance.now();for(let o=0;o<n;o++)e();let r=(performance.now()-t)/n;return Ho("engine.render.avgMeasured",r),r}function $h(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 zg=2,Le={drag:"drag",scale:"scale",rotate:"rotate",cornerRadius:"cornerRadius",crop:"crop",tableCellEdit:"table-cell-edit",warpImage:"warpvas-image"},Yg=(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((b,x)=>b.syntheticOwner?-1:x).filter(b=>b>=0);if(!d.length)return;let f=d.map(b=>r(u[b])),m=h?.before,p=m?.length?d.map(b=>m[b]).filter(b=>!!b):void 0,g=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:g,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 Vh(n,e){let t=n.nodes.filter(r=>r.visible&&!Dt.has(String(r.raw.id??""))&&!Qe(r));return n.setSelection(t),e(),t.length}function jh(n,e){let t=[...n.selection];for(let r of t)n.remove(r);return t.length&&e(),t.length}function qh(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 Xi=20,Qh={ruleSize:Xi,backgroundColor:ae("#ffffff"),tickColor:ae("#A1A7AF"),textColor:"#444444",highlightColor:ae("#165dff3b"),fontSize:8,unitName:"px"},Ug=.6,Ge=3,Zh="'Arial Narrow', 'Segoe UI', sans-serif",Kh=[.02,.03,.05,.1,.2,.5,1,2,5],$g=[5e3,2500,1e3,500,200,100,50,20,10],Vg=n=>{let e=0;for(;e<Kh.length&&Kh[e]<n;)e++;return $g[e-1]??1e4},jg=(n,e,t,r)=>{let o=Vg(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}},qg=(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},Rl=new Map,Kg=(n,e=Qh)=>{let t=Rl.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*Ge)),r.height=Math.max(1,Math.round(e.fontSize*1.4*Ge)),Rl.set(n,r),r;let i=`${e.fontSize*Ge}px ${Zh}`;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*Ge*1.25),o.font=i,o.textBaseline="top",o.fillStyle=e.textColor,o.fillText(n,1,Math.round(e.fontSize*Ge*.15)),Rl.set(n,r),r},Pl=new Map,Wi=10,Gi=4,Qg=n=>{let e=Pl.get(n);if(e)return e;let t=Wi*Ge,r=Gi*Ge,o=document.createElement("canvas"),i=o.getContext("2d");if(!i)return o.width=Math.max(1,Math.round((n.length*Wi*.6+Gi*2)*Ge)),o.height=Math.max(1,Math.round((Wi+Gi*2)*Ge)),Pl.set(n,o),o;let s=`${t}px ${Zh}`;i.font=s;let a=i.measureText(n).width,l=3*Ge;return o.width=Math.max(1,Math.ceil(a)+r*2),o.height=Math.ceil((Wi+Gi*2)*Ge),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*Ge,i.stroke(),i.fillStyle="#fff",i.textBaseline="top",i.fillText(n,r,r),Pl.set(n,o),o},Jh=n=>{let e={...Qh,...n.style},{vpt:t,cssWidth:r,cssHeight:o}=n,i=t[0],s=n.digitCanvas??(g=>Kg(g,e)),a=[],l=g=>(g-t[4])/i,c=g=>(g-t[5])/i,u=1/i,h=(g,b,x,y,S)=>({matrix:[u,0,0,u,l(g+x/2),c(b+y/2)],dims:{x,y},color:S}),d=(g,b,x,y=!1)=>{let S=s(g),v=S.width/Ge,T=S.height/Ge;return{matrix:y?[0,u,-u,0,l(b+T/2),c(x-v/2)]:[u,0,0,u,l(b+v/2),c(x+T/2)],dims:{x:v,y:T},color:[1,1,1,1],texture:S}},f=e.ruleSize,m=g=>{let b=g?r:o;a.push(g?h(0,0,r,f,e.backgroundColor):h(0,0,f,o,e.backgroundColor));let x=n.workspaceRect,y=x?g?[x.left,x.left+x.width]:[x.top,x.top+x.height]:null,S=g?-t[4]/i:-t[5]/i,v=jg(S,b/i,y,i),T=[e.tickColor[0],e.tickColor[1],e.tickColor[2],e.tickColor[3]*Ug],C=R=>(R-S)*i;for(let R of v.majors){let w=Math.round(C(R));a.push(g?h(w,0,1,f,T):h(0,w,f,1,T))}for(let R of v.minors){let w=Math.round(C(R));a.push(g?h(w,f-8,1,8,T):h(f-8,w,8,1,T))}for(let R of v.majors){let w=C(R),E=String(Math.round(R));g?a.push(d(E,w+6,2.5)):a.push(d(E,2.5,w-6,!0))}for(let R of qg(n.selectionRects,g)){let w=(R.start-S)*i,E=R.length*i;a.push(g?h(w,0,E,f,e.highlightColor):h(0,w,f,E,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/Ge/2,f/2-p.height/Ge/2)),n.referenceLine){let g=Qg(String(Math.round(n.referenceLine.position))),b=g.width/Ge,x=g.height/Ge,y,S;if(n.referenceLine.axis==="horizontal"){let v=n.referenceLine.position*i+t[5];y=f+5,S=v+x/2,S<0&&(S=2),S+x>o&&(S=o-x-2)}else y=n.referenceLine.position*i+t[4]+b/2,S=f+5,y<0&&(y=2),y+b>r&&(y=r-b-2);a.push({matrix:[u,0,0,u,l(y+b/2),c(S+x/2)],dims:{x:b,y:x},color:[1,1,1,1],texture:g})}return a};var zi=n=>n*180/Math.PI,ve=n=>n*Math.PI/180,Yi=n=>({x:(n.tl.x+n.br.x)/2,y:(n.tl.y+n.br.y)/2}),Ui=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)}),kl={mr:0,br:45,mb:90,bl:135,ml:180,tl:225,mt:270,tr:315},Al=["ew-resize","nwse-resize","ns-resize","nesw-resize"],$i=5,ed=4,Vt=(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"}}},Nl=(n,e,t)=>V([Math.cos(ve(n)),-Math.sin(ve(n)),Math.sin(ve(n)),Math.cos(ve(n)),0,0],e.x-t.x,e.y-t.y,!0),Ll=(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 Zg=n=>n instanceof ge&&(n.typeKey===L.TEXTBOX||n.typeKey===L.TEXTIMAGE&&!$t(n));function Il(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:Zg(h)})),l=V(s,i.x,i.y),c=n.parentMatrix,u=c?V(Te(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 td(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,g=xe({...d.node.raw,width:p.x,height:p.y},{x:f,y:d.centerY});n.setProps(d.node,{left:g.x,top:g.y},{deferIndexRebuild:!0})}else{let m=d.scaleX*r;n.setProps(d.node,{scaleX:m},{deferIndexRebuild:!0});let p=d.node.dims,g=xe({...d.node.raw,width:p.x,height:p.y,scaleX:m},{x:f,y:d.centerY});n.setProps(d.node,{left:g.x,top:g.y},{deferIndexRebuild:!0})}}}function nd(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);td(n,e,i)}function Jg(n,e,t){if(!(t>0))return;let r=Il(e,1);td(n,r,t)}function Mr(n){return n instanceof Z&&!(n instanceof te)&&!(n instanceof se)}function Dl(n,e,t){let r=n.raw,o=n.dims.x,i=n.dims.y,{u:s,a,axis:l}=Vt(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=V(h,a.x,a.y),f=n.parentMatrix,m=f?V(Te(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 ge||void 0};return Mr(n)&&(e==="ml"||e==="mr")&&(p.bakeGroup=Il(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&&dn.has(e)&&n instanceof ge&&(p.bakeFont={fontSize0:n.textStyle.fontSize,styles0:r.styles??null}),p}function sd(n,e,t,r=!1){let o=Nl(e.angle,t,e.anchorScene);if(e.bakeFont){tx(n,e,o);return}if(e.bakeWidth){nx(n,e,o);return}if(e.bakeHeight){rx(n,e,o);return}if(e.bakeGroup){nd(n,e.bakeGroup,o);return}if(e.bakeMaskWidth){rd(n,e,o,"width");return}if(e.bakeMaskHeight){rd(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}=Ll(e,o));let a=Math.cos(ve(e.angle)),l=Math.sin(ve(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 ad(n,e,t){let{quad:r,angle:o}=t,i=Yi(r),{width:s,height:a}=Ui(r),{u:l,a:c,axis:u}=Vt(e,s,a),h=Math.cos(ve(o)),d=Math.sin(ve(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 ld(n,e,t,r=!1){let o=Nl(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}=Ll({...e,scaleX:1,scaleY:1},o));let a=Math.cos(ve(e.angle)),l=Math.sin(ve(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(b=>b.node===h),f=ex(e,c,i,s,d,a,l),m=d.scaleX*i,p=d.scaleY*s,g=xe({...h.raw,width:d.dims.x,height:d.dims.y,scaleX:m,scaleY:p},f);return{scaleX:m,scaleY:p,left:g.x,top:g.y}},"scaling"),n.setSelectionFrame({center:c,width:e.width*i,height:e.height*s,angle:e.angle})}function ex(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 cd(n,e,t){let r=Math.atan2(t.y-e.center.y,t.x-e.center.x),o=zi(r-e.startAngle),i=Math.cos(ve(o)),s=Math.sin(ve(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 _l=n=>{if(n===null||typeof n!="object")return typeof n=="function"?void 0:n;if(Array.isArray(n))return n.map(_l);let e={};for(let t of Object.keys(n)){let r=_l(n[t]);r!==void 0&&(e[t]=r)}return e};function tx(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};e.node.typeKey===L.TEXTBOX&&(c.width=Math.max(e.width*a,1)),c.height=Math.max(e.height*a,1);let u=r.styles0;if(u){let b=_l(u);for(let x of Object.values(b))if(x)for(let[y,S]of Object.entries(x)){let v=S;v&&typeof v.fontSize=="number"&&(x[y]={...v,fontSize:v.fontSize*a})}c.styles=b}let h=Math.cos(ve(e.angle)),d=Math.sin(ve(e.angle)),f=h*(e.scaleX*e.anchorLocal.x*a)-d*(e.scaleY*e.anchorLocal.y*a),m=d*(e.scaleX*e.anchorLocal.x*a)+h*(e.scaleY*e.anchorLocal.y*a),p={x:e.anchorWrite.x-f,y:e.anchorWrite.y-m},g=xe({...e.node.raw,width:e.width*a,height:e.height*a,scaleX:e.scaleX,scaleY:e.scaleY},p);c.left=g.x,c.top=g.y,n.setProps(e.node,c,{deferIndexRebuild:!0})}function nx(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(ve(e.angle)),d=Math.sin(ve(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},g=xe({...e.node.raw,width:l,height:c,scaleX:e.scaleX,scaleY:e.scaleY},p);n.setProps(e.node,{left:g.x,top:g.y},{deferIndexRebuild:!0})}function rx(n,e,t){let r=e.node;if(!(r instanceof ge))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(ve(e.angle)),u=Math.sin(ve(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 rd(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=id(i,h,d,u,d);n.setProps(e.node,{width:u,...f??{}},{deferIndexRebuild:!0});let m={x:-l*u/2,y:0},p=od(e,m),g=xe({...s,width:u,height:d,scaleX:e.scaleX,scaleY:e.scaleY},p);n.setProps(e.node,{left:g.x,top:g.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=id(i,h,d,h,u);n.setProps(e.node,{height:u,...f??{}},{deferIndexRebuild:!0});let m={x:0,y:-l*u/2},p=od(e,m),g=xe({...s,width:h,height:u,scaleX:e.scaleX,scaleY:e.scaleY},p);n.setProps(e.node,{left:g.x,top:g.y},{deferIndexRebuild:!0})}}function od(n,e){let t=Math.cos(ve(n.angle)),r=Math.sin(ve(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 id(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 ud=(n,e)=>e.length>=2&&(e.includes(n-1)||e.includes(n));function dd(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 fd(n,e){let t=n.node.raw,r=V(Te(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(ud(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);Kr(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(ud(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=br(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=ch(n.startBorderPos,i,s,a);n.node.hoveredBorder={type:n.border.type,index:n.border.index,position:i+l}}function md(n,e){let t=Vt(e,n.dims.x,n.dims.y).a;return{type:"table-edge-resize",node:n,handle:e,anchorScene:V(n.matrix,t.x,t.y)}}function pd(n,e){let t=Vt(e,n.dims.x,n.dims.y).a;return{type:"puzzle-edge-resize",node:n,handle:e,anchorScene:V(n.matrix,t.x,t.y)}}function Vi(n,e,t,r){for(let o of mo(e)){let i=n(o.x,o.y);if(Zn(o.id)&&Math.hypot(i.x-t,i.y-r)<=Jn)return o.id}return null}function ix(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 po(n,e,t,r){for(let o of Cl(e)){let i=n(o.p1.x,o.p1.y),s=n(o.p2.x,o.p2.y);if(ix(t,r,i,s)<=Jn)return{mask:o.mask,handle:o.handle}}return null}function Fl(n,e,t){let r=n.maskChildren.indexOf(e);if(r<0)return null;let o=Ku(n.raw,n.maskChildren.map(s=>s.raw),n.maskChildren.map(s=>s.clipImageEl)),i=Vt(t,e.dims.x,e.dims.y).a;return{type:"puzzle-mask-edge-resize",node:n,maskIdx:r,handle:t,anchorScene:V(e.matrix,i.x,i.y),state:o.state,pieces:o.pieces,clipSizes:o.clipSizes}}function sx(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 bd(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(ve(-o)),u=Math.sin(ve(-o)),h=s;s=c*h-u*a,a=u*h+c*a}let l=Ei[n.handle];if(l==="left"||l==="right"){let c=(r.strokeWidth??0)/(r.strokeUniform===!0?i.x:1);ju(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);qu(n.state,n.maskIdx,Math.abs(a)/i.y-c,l,n.clipSizes)}sx(n.node,n.state)}function hd(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:si(s.raw)}))},i=r.map(s=>s.clipImageEl?{w:s.clipImageEl.naturalWidth,h:s.clipImageEl.naturalHeight}:null);Vu(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 gd(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(ve(-i)),p=Math.sin(ve(-i)),g=s;s=m*g-p*a,a=p*g+m*a}let l=e.node.layoutParams;if(Qn[e.handle]==="x"){let m=(r.strokeWidth??0)/(r.strokeUniform===!0?o.x:1),p=Math.max(Math.abs(s)/o.x-m,1);hd(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);hd(e.node,{heightRatio:p/(l.height||1)})}let c=Vt(e.handle,e.node.dims.x,e.node.dims.y).a,u=Math.cos(ve(i)),h=Math.sin(ve(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 xd(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(ve(-s)),g=Math.sin(ve(-s)),b=a;a=p*b-g*l,l=g*b+p*l}let c=r.cellStrokeWidth??1;if(Qn[e.handle]==="x"){let p=Math.abs(a)/i.x-o.cellSpacing*(o.cols-1)-c,g=e.handle==="ml"?0:o.cols-1,b=o.columnWidths.reduce((x,y,S)=>S===g?x:x+y,0);Qr(r,g,p-b)}else{let p=Math.abs(l)/i.y-o.cellSpacing*(o.rows-1)-c,g=e.handle==="mt"?0:o.rows-1,b=o.rowHeights.reduce((x,y,S)=>S===g?x:x+y,0);Zr(r,g,p-b)}e.node.rebuildTable();let u=Vt(e.handle,e.node.dims.x,e.node.dims.y).a,h=Math.cos(ve(s)),d=Math.sin(ve(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 yd(n,e,t){let r=Math.max(0,t.index);if(t.type==="col"){no(e.raw,r),e.rebuildTable();let o=e.tableView,i=ui(e.cellMap,o.rows,Math.min(r,o.cols-1));e.setCellSelection(i,i[0]??null,We(i))}else{to(e.raw,r),e.rebuildTable();let o=e.tableView,i=hi(e.cellMap,o.cols,Math.min(r,o.rows-1));e.setCellSelection(i,i[0]??null,We(i))}n.applyTransform([e],()=>({}),"modified")}var ax=n=>n.kind==="col-strip"?{kind:"col",index:n.col}:{kind:"row",index:n.row},lx=(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=Nh(n),m=Math.max(0,Math.min(f,wl(Math.min(h,d),f))),p=r.radius??0;return Math.abs(m-p)<.001?null:m},cx=(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,wl(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},Ol=(n,e)=>n<Xi?"vertical":e<Xi?"horizontal":null,bo=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`,Be=n=>{let e=new Map;for(let t of n)e.set(t,t.toObject());return e},ji=class{host;el;gesture={type:"none"};performed=!1;hoveredTable=null;lastHoverDoc=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=Je(this.host.document);if(!r||this.host.document.selection.length===1&&st(this.host.document.selection[0]))return null;for(let o of ho(this.host.document,r.quad,r.angle,this.host.zoom,fo(this.host.document))){let i=this.host.toScreen(o.x,o.y);if(Math.hypot(i.x-e,i.y-t)<=Jn)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 Ml(o,this.host.zoom)){let s=this.host.toScreen(i.x,i.y);if(Math.hypot(s.x-e,s.y-t)<=Jn)return i.id}return null}hitLockControl(e,t){let r=this.host.document;if(r.selection.length!==1||!st(r.selection[0]))return null;let o=Je(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)<=Jn?r.selection[0]:null}hitMoveControl(e,t){if(this.host.mobileControls!==!0||!yl(this.host.document))return!1;let r=Je(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)<=Ph}hitCornerRotateZone(e,t){let r=this.host.document;if(r.selection.length!==1)return null;let o=r.selection[0];if(o instanceof te||st(o))return null;let i=Je(r);if(!i)return null;let s=i.angle*Math.PI/180,a=Math.cos(s),l=Math.sin(s),c=Lh/2;for(let u of Dh(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:Fi(e),center:{x:t.x,y:t.y},onChild:!0}:{spec:Fi(e),center:{x:t.x,y:t.y}})}hoverCursor(e,t,r,o=this.host.document){if(this.host.rulerVisible){let p=Ol(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 se?o.selection[0]:null;if(c?.editingMask){let p=Vi((b,x)=>this.host.toScreen(b,x),c,e,t);if(p)return Qn[p]==="x"?"ew-resize":"ns-resize";let g=po((b,x)=>this.host.toScreen(b,x),c,e,t);if(g)return Qn[g.handle]==="x"?"ew-resize":"ns-resize"}else if(c){let p=po((g,b)=>this.host.toScreen(g,b),c,e,t);if(p)return Qn[p.handle]==="x"?"ew-resize":"ns-resize"}let u=o.selection.length===1&&o.selection[0]instanceof te?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 g=u.stripHit(r.x,r.y,this.host.zoom);if(g)return this.updateTableHover(u,null,!1,{strip:ax(g)}),"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 bo(p.worldAngle+225)}if(h){let p=o.activeGroupChild,g=kl[h];if(typeof g=="number"){let b=g+p.worldAngle;return Al[(Math.round(b/45)%4+4)%4]}}if(this.hitMoveControl(e,t))return"move";let d=this.hitHandle(e,t);if(d==="mtr")return bo((Je(o)?.angle??0)+225);if(d&&wr(d))return d==="tlS"||d==="brS"?"nwse-resize":"nesw-resize";if(d){let p=kl[d]+(Je(o)?.angle??0);return Al[(Math.round(p/45)%4+4)%4]}let f=this.hitCornerRotateZone(e,t);if(f)return bo((Je(o)?.angle??0)+Tl[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),g="move";return p?.inCircle?g="pointer":p?.border&&o.selection.includes(m)&&(g=uh(m.tableAngle,p.border.type)),this.updateTableHover(m,p,!0),g}if(this.updateTableHover(null,null,!1),!this.host.cropSession&&!this.host.expandSession&&!this.host.pathSession&&!this.host.warpSession){let p=o.nodes.find(g=>Qe(g)&&g.visible&&g.raw.visible!==!1&&g.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,o=this.host.document){o!==this.lastHoverDoc&&(this.lastHoverDoc?.setHovered(null),this.hoveredTable=null,this.lastHoverDoc=o,this.host.requestRenderAll());let i=null,s=null,a=o.nodes.find(d=>d instanceof se&&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 Z&&!(d instanceof te)&&!(d instanceof se)){let f=o.activeGroupChild;if(!(f!==null&&o.selection.length===1&&o.selection[0]===d))o.selection.includes(d)||(i=d);else{let p=d.childAtPoint(r.x,r.y);i=p&&p!==f?p:null}}else d&&!o.selection.includes(d)&&(i=d)}if(i&&i===o.editingNode&&(i=null),c&&!(a&&Vi((d,f)=>this.host.toScreen(d,f),a,e,t))){let d=o.selection.length===1&&o.selection[0]instanceof se?o.selection[0]:null;if(d){let f=po((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.lastHoverDoc&&this.lastHoverDoc!==s&&this.lastHoverDoc.setHovered(null),this.lastHoverDoc=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){if(this.host.resolvePointerTarget){let v=this.host.toSceneAbs?this.host.toSceneAbs(e,t):this.host.toScene(e,t),T=this.host.resolvePointerTarget(v.x,v.y);if(!T){this.host.document.clearSelection(),this.host.requestRenderAll();return}T.doc!==this.host.document&&this.host.activateRoutedDocument?.(T.doc)}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 v=s.hitHandle(e,t);v?this.gesture={type:"crop-handle",handle:v}: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 v=a.hitHandle(e,t);v?this.gesture={type:"expand-handle",handle:v}: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 v=l.hitAnchor(e,t);if(v&&l.startAnchorDrag(v)){this.gesture={type:"path-anchor-drag",key:v},this.host.requestRenderAll();return}let T=l.findInsertCandidate(i.x,i.y);if(T){let C=l.insertAnchor(T);if(C){this.gesture={type:"path-anchor-drag",key:C},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 v=c.hitAnchor(e,t);v&&(this.gesture={type:"warp-anchor-drag",anchor:v},c.applyAnchorDrag(v,i)),this.host.requestRenderAll();return}if(this.host.rulerVisible){let v=Ol(e,t);if(v){let T=yh(v,v==="horizontal"?i.y:i.x),C=ct(T);C&&(o.add(C),o.clearSelection(),this.gesture={type:"reference-line",node:C,axis:v,creating:!0,historyBefore:Be([C])}),this.host.requestRenderAll();return}}let u=o.editingNode,h=!1;if(u){if(u.containsPoint(i.x,i.y)){let v=u.localPoint(i.x,i.y),T=u.cursorIndexAt(v.x,v.y);this.host.setEditingSelection(T,T),this.gesture={type:"text-select",anchorIdx:T};return}o.exitEditing(),h=!0}if(!h&&o.selection.length===1&&o.selection[0]instanceof te){let v=o.selection[0],T=o.findTarget(i.x,i.y)?null:v.borderOrIndicatorHit(i.x,i.y,this.host.zoom);if(T?.inCircle){this.gesture={type:"table-indicator-click",node:v,border:T.border};return}let C=o.findTarget(i.x,i.y)?null:v.stripHit(i.x,i.y,this.host.zoom);if(C){this.gesture=C.kind==="col-strip"?{type:"table-strip-click",node:v,kind:"col",index:C.col}:{type:"table-strip-click",node:v,kind:"row",index:C.row};return}}if(!h&&o.selection.length===1&&o.selection[0]instanceof te){let v=o.selection[0];if(o.findTarget(i.x,i.y)===v&&v.rangeHandleHit(i.x,i.y,this.host.zoom)){let T=v.expandedCellRange;if(T){this.gesture={type:"table-range-drag",node:v,anchor:{row:T.r1,col:T.c1}};return}}}let d=h?null:o.nodes.find(v=>v instanceof se&&v.editingMask)??null,f=!!d;if(f&&d){let v=Vi((T,C)=>this.host.toScreen(T,C),d,e,t);if(v&&d.editingMask){let T=Fl(d,d.editingMask,v);T&&(this.gesture=T);return}}{let v=o.selection.length===1&&o.selection[0]instanceof se?o.selection[0]:null;if(v){let T=po((C,R)=>this.host.toScreen(C,R),v,e,t);if(T){let C=Fl(v,T.mask,T.handle);C&&(this.gesture=C);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 v=this.hitActiveChildHandle(e,t),T=o.activeGroupChild,C=o.selection.length===1?o.selection[0]:null;if(v&&T&&C instanceof Z&&!(C instanceof te)&&!(C instanceof se)){let R=wi(C,T);if(R.length){let w=[T,...R,...R.flatMap(E=>E.children)];if(v==="mtr"){let E=T.aCoords,M={x:(E.tl.x+E.br.x)/2,y:(E.tl.y+E.br.y)/2};this.freezeRotateHandle(T.raw.angle??0,M,!0),this.gesture={type:"rotate",center:M,startAngle:Math.atan2(i.y-M.y,i.x-M.x),snapshot:{node:T,angle0:T.raw.angle??0},cursorOffset:225,childTransform:{child:T,shells:R,pivotLocal:{...T.center}},historyBefore:Be(w)}}else if(!wr(v))this.gesture={type:"scale",handle:v,snapshot:Dl(T,v,o),freeScale:r&&dn.has(v),childTransform:{child:T,shells:R},historyBefore:Be(w)};else return;this.host.requestRenderAll();return}}}if(!h&&p&&this.hitMoveControl(e,t)){let v=o.selection[0],T=new Map;T.set(v,{left:v.raw.left??0,top:v.raw.top??0}),this.gesture={type:"move",start:i,startCss:{x:e,y:t},snapshot:T,historyBefore:Be([v])},this.host.requestRenderAll();return}let g=h||!p?null:this.hitHandle(e,t);if(g){if(o.selection.length===1){let v=o.selection[0];if(g==="mtr"){let T=v.center;this.freezeRotateHandle(v.raw.angle??0,T),this.gesture={type:"rotate",center:T,startAngle:Math.atan2(i.y-T.y,i.x-T.x),snapshot:{node:v,angle0:v.raw.angle??0},cursorOffset:225,historyBefore:Be([v])}}else if(wr(g)&&(Di(v)||uo(v)))this.gesture={type:"cornerRadius",node:v,corner:lo[g],model:uo(v)?"image":"rect",historyBefore:Be([v])};else if(v instanceof te&&Zn(g)){let T=md(v,g);T.historyBefore=Be([v]),this.gesture=T}else if(v instanceof se&&Zn(g)){let T=pd(v,g);T.historyBefore=Be([v]),this.gesture=T}else this.gesture={type:"scale",handle:g,snapshot:Dl(v,g,o),freeScale:r&&dn.has(g),historyBefore:Be([v])}}else{let v=Je(o),T=o.selection.filter(C=>!st(C));if(g==="mtr"){let C=Yi(v.quad);T.length&&this.freezeRotateHandle(v.angle,C),this.gesture={type:"multi-rotate",center:C,startAngle:Math.atan2(i.y-C.y,i.x-C.x),frameAngle0:v.angle,frame:Ui(v.quad),snapshot:{members:T.map(R=>({node:R,angle0:R.raw.angle??0,center0:{...R.center}}))},historyBefore:Be(o.selection)}}else this.gesture={type:"multi-scale",snapshot:ad(T,g,v),freeScale:r&&dn.has(g),historyBefore:Be(o.selection)}}return}let b=h||!p?null:this.hitCornerRotateZone(e,t);if(b){let v=o.selection[0],T=v.center;this.host.rotateDrag!==void 0&&(this.host.rotateDrag={spec:null,center:{x:T.x,y:T.y}}),this.gesture={type:"rotate",center:T,startAngle:Math.atan2(i.y-T.y,i.x-T.x),snapshot:{node:v,angle0:v.raw.angle??0},cursorOffset:Tl[b],historyBefore:Be([v])};return}if(!h&&o.selection.length===1&&o.selection[0]instanceof te){let v=o.selection[0];if(!o.findTarget(i.x,i.y)&&v.dragHandleHit(i.x,i.y,this.host.zoom)){let T=new Map;for(let C of o.selection)T.set(C,{left:C.raw.left??0,top:C.raw.top??0});this.gesture={type:"move",start:i,startCss:{x:e,y:t},snapshot:T,historyBefore:Be(o.selection)},this.host.requestRenderAll();return}}if(!r){let v=o.nodes.find(T=>Qe(T)&&T.visible&&T.raw.visible!==!1&&T.containsPoint(i.x,i.y));if(v){o.setSelection([v],"create"),this.gesture={type:"reference-line",node:v,axis:v.dims.y===0?"horizontal":"vertical",creating:!1,historyBefore:Be([v])},this.host.requestRenderAll();return}}let x=o.findTarget(i.x,i.y),y=x instanceof te?x:null;if(y){let v=y.borderOrIndicatorHit(i.x,i.y,this.host.zoom);if(v?.inCircle){this.gesture={type:"table-indicator-click",node:y,border:v.border};return}let T=y.borderHit(i.x,i.y);if(T&&o.selection.includes(y)){let R=dd(y,T,i);R.historyBefore=Be([y]),this.gesture=R;return}let C=y.cellHit(i.x,i.y);if(C){o.selection.includes(y)?!r&&o.selection.length>1&&(this.deferredClickSwitch=y):o.setSelection([y],"create");let R=new Map;for(let w of o.selection)st(w)||R.set(w,{left:w.raw.left??0,top:w.raw.top??0});this.gesture={type:"table-cell-click",node:y,start:i,anchorCell:C,shift:r,moveSnapshot:R,frame0:o.selection.length>1&&o.selectionFrame?{...o.selectionFrame}:void 0,historyBefore:Be(o.selection)},this.host.requestRenderAll();return}}if(f&&d){if(x===d){let v=d.maskChildren.find(T=>T.visible&&T.containsPoint(i.x,i.y));if(v){v!==d.editingMask&&(d.editingMask=v),o.setActiveGroupChild(v);let T=new Map;for(let C of o.selection)st(C)||T.set(C,{left:C.raw.left??0,top:C.raw.top??0});this.gesture={type:"move",start:i,startCss:{x:e,y:t},snapshot:T,frame0:void 0,historyBefore:Be(o.selection)}}else d.exitMaskEditing(),o.setActiveGroupChild(null);this.host.requestRenderAll();return}d.exitMaskEditing(),this.host.requestRenderAll()}let S=x instanceof te?null:x;if(S){let v=o.selection.includes(S),T=o.groupEditing;if(r){let C=(o.selection.includes(S)?o.selection.filter(R=>R!==S):[...o.selection,S]).filter(R=>!st(R));o.setSelection(C,"update")}else o.selection.includes(S)?o.selection.length>1&&(this.deferredClickSwitch=S):o.setSelection([S],"create");if(S instanceof Z&&!(S instanceof te)&&!(S instanceof se))o.setActiveGroupChild(S.childAtPoint(i.x,i.y));else if(S instanceof se&&v&&o.selection.length===1){let C=S.maskChildren.find(R=>R.visible&&R.containsPoint(i.x,i.y))??null;o.setActiveGroupChild(C),C?S.editingMask=C:S.exitMaskEditing()}else o.activeGroupChild&&o.setActiveGroupChild(null);if(o.selection.includes(S))if(st(S)&&v&&o.selection.length===1&&o.selection[0]===S)this.gesture={type:"marquee",anchor:i,additive:r,hold:!0};else{let C=o.activeGroupChild,R=T&&C&&S instanceof Z&&!(S instanceof te)&&!(S instanceof se)&&o.selection.length===1&&o.selection[0]===S?wi(S,C):[],w=R.length&&C?{child:C,toLocal:Th(C),shells:R}:null;if(w){let E=new Map;E.set(w.child,{left:w.child.raw.left??0,top:w.child.raw.top??0});let M=[w.child,...w.shells,...w.shells.flatMap(P=>P.children)];this.gesture={type:"move",start:i,startCss:{x:e,y:t},snapshot:E,childMove:w,historyBefore:Be(M)}}else{let E=new Map;for(let M of o.selection)st(M)||E.set(M,{left:M.raw.left??0,top:M.raw.top??0});this.gesture={type:"move",start:i,startCss:{x:e,y:t},snapshot:E,frame0:o.selection.length>1&&o.selectionFrame?{...o.selectionFrame}:void 0,historyBefore:Be(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"){if(this.host.resolvePointerTarget){let s=this.host.toSceneAbs?this.host.toSceneAbs(e,t):this.host.toScene(e,t),a=this.host.resolvePointerTarget(s.x,s.y);if(!a){this.lastHoverDoc&&(this.lastHoverDoc.setHovered(null),this.lastHoverDoc=null,this.host.requestRenderAll()),this.el.style.cursor="default";return}this.el.style.cursor=this.hoverCursor(e,t,a.local,a.doc),this.updateHover(e,t,a.local,a.doc);return}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)<=ed)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,sd(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=cx(i.node,i.corner,o);s&&(this.performed=!0,r.applyTransform([i.node],()=>s,"cornerRadius"))}else{let s=lx(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,ld(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+zi(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=bo((i.snapshot.node.raw.angle??0)+(i.cursorOffset??225))}else if(i.type==="multi-rotate")i.snapshot.members.length&&(this.performed=!0,cd(r,i,o),this.el.style.cursor=bo((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)<=$i)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=>!st(l)),a=(i.additive?[...new Set([...r.selection,...s])]:s).filter(l=>!st(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,fd(i,o);else if(i.type==="table-edge-resize")this.performed=!0,xd(r,i,o);else if(i.type==="puzzle-edge-resize")this.performed=!0,gd(r,i,o);else if(i.type==="puzzle-mask-edge-resize")this.performed=!0,bd(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=un(i.node.cellMap,i.anchor,s);i.node.setCellSelection(a,i.anchor,We(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=un(i.node.cellMap,a,s);i.node.setCellSelection(l,a,We(l))}}else if(Math.hypot(o.x-i.start.x,o.y-i.start.y)>$i)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=hl(o.childMove.shells),s=[...new Set([o.childMove.child,...i])];r.applyTransform(s,()=>({}),"modified",{action:Le.drag,before:o.historyBefore})}else{let i=[...o.snapshot.keys()];this.host.transferDraggedNodes?.(i,o.historyBefore,e,t)||r.applyTransform(i,()=>({}),"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?Ol(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=hl(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&&yd(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)<=$i)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=un(o.node.cellMap,a,s);o.node.setCellSelection(l,a,We(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 ux=new Set(["qrcode","barcode"]),hx=n=>{let e=n.raw.type;return typeof e=="string"&&ux.has(e.toLowerCase())},qi=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();if(e.resolvePointerTarget){let a=e.toSceneAbs?e.toSceneAbs(r.clientX-o.left,r.clientY-o.top):e.toScene(r.clientX-o.left,r.clientY-o.top),l=e.resolvePointerTarget(a.x,a.y);if(!l)return;l.doc!==e.document&&e.activateRoutedDocument?.(l.doc)}let i=e.toScene(r.clientX-o.left,r.clientY-o.top),s=e.document.findTarget(i.x,i.y);if(s instanceof Z&&!(s instanceof te)&&!(s instanceof se)){let a=s.childAtPoint(i.x,i.y);a&&!(a instanceof te)&&!(a instanceof se)&&(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 se){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 ge){this.host.enterTextEditingAtClick(e,t,r);return}if(e?.isImageType&&!hx(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 Ki=class n{host;onKeydown;docBus;disposed=!1;constructor(e){this.host=e,this.onKeydown=t=>this.handleKey(t),window.addEventListener("keydown",this.onKeydown),this.docBus=new kt(e.document.events,t=>{let r=()=>this.pruneCellState(),o=[t.on("selection:created",r),t.on("selection:updated",r),t.on("selection:cleared",r)];return()=>o.forEach(i=>i())})}retargetDoc(e){this.docBus.retarget(e.events)}dispose(){this.disposed||(this.disposed=!0,window.removeEventListener("keydown",this.onKeydown),this.docBus.dispose())}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=io(t.cellMap,i.rows,i.cols);t.setCellSelection(s,s[0]??null,We(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=We(e.selectedCells);if(!t)return;let r=Jr(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(eo(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=Se(t,o.row,o.col);i&&!i.isMerged&&i.text&&(i.text="",r=!0)}r&&this.commit(e)}};var Bl=(n,e,t)=>Math.max(e,Math.min(t,n)),Qi={min:.05,max:5},Cr=60,vd=(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 k=Math.abs(h)<10?h*2:h/3,O=e.viewportTransform[0],F=Bl(O*(1-k/200),Qi.min,Qi.max),W=e.cursorPoint(n);e.zoomAt(W.x,W.y,F/O);return}let d=o===0&&Math.abs(t)<=10&&Math.abs(r)<=10,f=Bl(e.viewportTransform[0],.1,Qi.max),m=Math.max(1,f)*1.25,p=20*m,g=k=>Bl(k,-60,60),b=0,x=0;if(l||Math.abs(u)>Math.abs(h)){let k=u!==0?u:h;k!==0&&(b=d?-g(k)*m:k>0?-p:p)}else h!==0&&(x=d?-g(h)*m:h>0?-p:p);if(b===0&&x===0)return;let S=e.scrollViewportTransform??e.viewportTransform,{width:v,height:T}=e.viewSize,C=e.workspaceSize(),R=C.width*f,w=C.height*f,E=S[4],M=S[5],P=Cr-R;E+b<P&&(b=P-E),E+b>v-Cr&&(b=v-Cr-E);let A=Cr-w;M+x<A&&(x=A-M),M+x>T-Cr&&(x=T-Cr-M),!(b===0&&x===0)&&(e.pan(b,x),x!==0&&e.followScrolledPage?.())};function Sd(n,e){if(e.length<2)return;let t=n.scrollViewportTransform,r=-t[5]/t[3],o=r+n.viewSize.height/t[3],i=c=>Math.max(0,Math.min(o,c.top+c.height)-Math.max(r,c.top)),s=n.activePageIndex,a=e.find(c=>c.index===s),l=a?i(a):0;for(let c of e){let u=i(c);u>l+.01&&(s=c.index,l=u)}s!==n.activePageIndex&&(n.ensurePageBuilt(s),n.setActivePage(s))}var Zi=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 ji(i,e,this.interactive),this.tableInteraction=new Ki(e);let s=d=>{if(d.key!=="Escape")return;let f=e.document.selection;f.length===1&&f[0]instanceof se&&f[0].editingMask&&(f[0].exitMaskEditing(),e.document.setActiveGroupChild(null),e.requestRenderAll())};this.interactive&&window.addEventListener("keydown",s),this.docBus=new kt(e.document.events,d=>{let f=()=>e.requestRenderAll(),m=[d.on("selection:created",f),d.on("selection:updated",f),d.on("selection:cleared",f),d.on("object:modified",f),d.on("object:moving",p=>this.snapGuide.registerMove(p)),d.on("object:removed",p=>{p instanceof re&&this.sources.releaseAnimatedNode(p)})];return()=>m.forEach(p=>p())}),this.dblClick=new qi(e,this.interactive);let a=d=>{vd(d,e)},l=d=>{if(d.button===1){d.preventDefault(),e.panning=!0,this.lastPanPointer={x:d.clientX,y:d.clientY},i.style.cursor="grab";try{i.setPointerCapture(d.pointerId)}catch{}}},c=d=>{if(!e.panning||!this.lastPanPointer)return;let f=d.clientX-this.lastPanPointer.x,m=d.clientY-this.lastPanPointer.y;this.lastPanPointer={x:d.clientX,y:d.clientY},e.pan(f,m),i.style.cursor="grab"},u=d=>{e.panning&&(e.panning=!1,this.lastPanPointer=null,i.hasPointerCapture(d.pointerId)&&i.releasePointerCapture(d.pointerId),i.style.cursor="default")},h=d=>e.handleFontsLoaded(d.fontfaces??[]);document.fonts?.addEventListener?.("loadingdone",h),this.interactive&&(i.addEventListener("wheel",a,{passive:!1}),i.addEventListener("pointerdown",l),window.addEventListener("pointermove",c),window.addEventListener("pointerup",u)),this.detachListeners=()=>{document.fonts?.removeEventListener?.("loadingdone",h),i.removeEventListener("wheel",a),i.removeEventListener("pointerdown",l),window.removeEventListener("pointermove",c),window.removeEventListener("pointerup",u),window.removeEventListener("keydown",s)}}host;snapGuide;sources;interactive;pointer;tableInteraction;dblClick;detachListeners=null;docBus=null;lastPanPointer=null;get pointerActive(){return this.pointer.active}retargetDoc(e){this.docBus?.retarget(e.events),this.tableInteraction.retargetDoc(e)}dispose(){this.detachListeners?.(),this.docBus?.dispose(),this.pointer.dispose(),this.dblClick.dispose(),this.tableInteraction.dispose()}};var dx=(n,e)=>({w:e.naturalWidth||e.width||(n.width??0),h:e.naturalHeight||e.height||(n.height??0)}),fx=(n,e,t)=>({w:e*Math.abs((n.scaleX??1)||1),h:t*Math.abs((n.scaleY??1)||1)}),mx=(n,e,t,r,o,i)=>({cropX:Math.max(0,t/2-o/2-n),cropY:Math.max(0,r/2-i/2-e)}),px=(n,e,t,r,o,i)=>({clipX:t/2-o/2-n,clipY:r/2-i/2-e}),wd=(n,e,t)=>{let r=dx(e,t),o=fx(e,r.w,r.h),i=n.width??0,s=n.height??0,{cropX:a,cropY:l}=mx(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"}},Td=n=>{let{clipX:e,clipY:t}=px(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 bx={left:-.5,top:-.5,center:0,bottom:.5,right:.5},Ft=n=>typeof n=="string"?bx[n]??0:n-.5,Hl=(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}},gx=n=>({x:n.width*n.scaleX,y:n.height*n.scaleY}),es=gx,go=n=>n*Math.PI/180,Wl=(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=Hl(c,go(o),n)),c},Gl=(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=Hl(c,go(o),n)),c},Ed=(n,e,t,r,o)=>Wl(n,Ft(e),Ft(t),r,o),Xl=(n,e,t,r,o,i)=>Gl({x:n,y:e},Ft(t),Ft(r),o,i),Rr=(n,e,t=0,r=0)=>{let o=Xl(n.left,n.top,n.originX,n.originY,es(n),n.angle),i=e;n.angle&&(i=Hl(i,-go(n.angle),o));let s=es(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}},xn=(n,e,t,r)=>{let o=es(n),i=Xl(n.left,n.top,n.originX,n.originY,o,n.angle),s=Wl(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=Gl(s,e,t,c,n.angle,n.flipX,n.flipY),h=Ed(u,n.originX,n.originY,c,n.angle);return{...n,...r,scaleX:a,scaleY:l,left:h.x,top:h.y}},xx=(n,e)=>{let{width:t,cropX:r}=n,i=Rr(n,e).x/n.scaleX- -(t/2),s=t-i;return r+i<0&&(i=-r,s=t+r),s<=0&&(i+=s,s=0),xn(n,.5,0,{width:s,height:n.height,cropX:r+i,cropY:n.cropY})};var yx=(n,e)=>{let{width:t,cropX:r}=n,o=Rr(n,e),i=t-(t/2-o.x/n.scaleX);return i+r>n.naturalWidth&&(i=n.naturalWidth-r),i<0&&(i=0),xn(n,-.5,0,{width:i,height:n.height,cropX:r,cropY:n.cropY})};var vx=(n,e)=>{let{height:t,cropY:r}=n,i=Rr(n,e).y/n.scaleY- -(t/2),s=t-i;return r+i<0&&(i=-r,s=t+r),s<=0&&(i+=s,s=0),xn(n,0,.5,{width:n.width,height:s,cropX:n.cropX,cropY:r+i})};var Sx=(n,e)=>{let{height:t,cropY:r}=n,o=Rr(n,e),i=t-(t/2-o.y/n.scaleY);return i+r>n.naturalHeight&&(i=n.naturalHeight-r),i<0&&(i=0),xn(n,0,-.5,{width:n.width,height:i,cropX:n.cropX,cropY:r})};var ts=(n,e,t)=>e==="left"||e==="right"?e==="left"?xx(n,t):yx(n,t):e==="top"?vx(n,t):Sx(n,t),Md=(n,e,t)=>{let r=e==="tl"||e==="bl"?"left":"right",o=e==="tl"||e==="tr"?"top":"bottom",i=ts(n,r,t);return ts(i,o,t)},Ji=(n,e,t)=>{let r=e/t;return n<=r?{width:n,height:n*t}:{width:e/t,height:e}},Cd=(n,e,t,r)=>{let o=Rr(n,t),i=o.x/n.scaleX,s=o.y/n.scaleY;if(e==="br"){let d=i- -n.width/2,f=s- -n.height/2;if(d=Math.min(d,n.naturalWidth-n.cropX),f=Math.min(f,n.naturalHeight-n.cropY),d<=0||f<=0)return null;let{width:m,height:p}=Ji(d,f,r);return xn(n,-.5,-.5,{width:m,height:p,cropX:n.cropX,cropY:n.cropY})}if(e==="tl"){let d=n.width/2-i,f=n.height/2-s;if(d=Math.min(d,n.width+n.cropX),f=Math.min(f,n.height+n.cropY),d<=0||f<=0)return null;let{width:m,height:p}=Ji(d,f,r),g=n.width-m,b=n.height-p;return n.cropX+g<0||n.cropY+b<0?null:xn(n,.5,.5,{width:m,height:p,cropX:n.cropX+g,cropY:n.cropY+b})}if(e==="tr"){let d=i- -n.width/2,f=n.height/2-s;if(d=Math.min(d,n.naturalWidth-n.cropX),f=Math.min(f,n.height+n.cropY),d<=0||f<=0)return null;let{width:m,height:p}=Ji(d,f,r),g=n.height-p;return n.cropY+g<0?null:xn(n,-.5,.5,{width:m,height:p,cropX:n.cropX,cropY:n.cropY+g})}let a=n.width/2-i,l=s- -n.height/2;if(a=Math.min(a,n.width+n.cropX),l=Math.min(l,n.naturalHeight-n.cropY),a<=0||l<=0)return null;let{width:c,height:u}=Ji(a,l,r),h=n.width-c;return n.cropX+h<0?null:xn(n,.5,-.5,{width:c,height:u,cropX:n.cropX+h,cropY:n.cropY})},wx=(n,e,t,r,o)=>{let i=Math.abs(n.x/t),s=Math.abs(n.y/e);return Math.min(i,s)},Rd=(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=Rr(n,t,Ft(a),Ft(l)),u=wx(c,o,r,n.flipX,n.flipY),h=u/n.scaleX,d=u/n.scaleY,f=n.width/h,m=n.height/d,p=i/h,g=s/d,b,x;if(e==="br"){if(b=n.cropX/h,x=n.cropY/d,b+f>r||x+m>o)return null}else if(e==="tl"){if(b=r-f-p,x=o-m-g,f+p>r||m+g>o)return null}else if(e==="tr"){if(b=n.cropX/h,x=o-m-g,b+f>r||g+m>o)return null}else if(b=r-f-p,x=n.cropY/d,f+p>r||m+x>o)return null;let y,S;e==="br"?(y=-b/f,S=-x/m):e==="tl"?(y=1+p/f,S=1+g/m):e==="tr"?(y=-b/f,S=1+g/m):(y=1+p/f,S=-x/m);let v=es(n),T=Xl(n.left,n.top,n.originX,n.originY,v,n.angle),C=Wl(T,Ft(a),Ft(l),v,n.angle,n.flipX,n.flipY),R={x:f*u,y:m*u},w=Gl(C,Ft(y),Ft(S),R,n.angle,n.flipX,n.flipY),E=Ed(w,n.originX,n.originY,R,n.angle);return{...n,width:f,height:m,cropX:b,cropY:x,scaleX:u,scaleY:u,left:E.x,top:E.y}},Pd=(n,e)=>{let t=Math.cos(go(n.angle)),r=Math.sin(go(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}},kd=(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}},Ad=(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"}},Nd=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}},yn={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}},xo=(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 Ld=12,Tx=14,Id=7,Ex=1,Mx=1,_d=ae("#f6f7fa"),Dd=ae("#2f6fed"),Cx=["e","se","s","sw","w","nw","n","ne","e"],Fd=["tl","tr","bl","br"],Od=["tl","tr","bl","br"],Bd=["left","right","top","bottom"],zl=null,Rx=()=>{if(zl)return zl;let n=Math.ceil((Id+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,Id,0,Math.PI*2),t.fillStyle="#ffffff",t.fill(),t.lineWidth=1.5,t.strokeStyle="#2f6fed",t.stroke(),zl=e,e},os=30,is=7,Yl={x:28,y:16},Ul={x:14,y:4},$l=2,Gd=(n,e)=>{let t=document.createElement("canvas");t.width=n*$l,t.height=e*$l;let r=t.getContext("2d");return r?{canvas:t,ctx:r}:null},et=n=>n*$l,ns=null,Px=()=>{if(ns)return ns;let n=Gd(os,os);if(!n)return ns=document.createElement("canvas");let{canvas:e,ctx:t}=n;return t.translate(et(is),et(is)),t.shadowColor="rgba(12, 18, 28, 0.38)",t.shadowBlur=et(4),t.shadowOffsetX=et(2),t.shadowOffsetY=et(2),t.beginPath(),t.lineWidth=et(6),t.lineCap="round",t.strokeStyle="#dfe2e8",t.moveTo(0,et(10)),t.lineTo(0,0),t.lineTo(et(10),0),t.stroke(),ns=e,e},rs=null,kx=()=>{if(rs)return rs;let n=Gd(Yl.x,Yl.y);if(!n)return rs=document.createElement("canvas");let{canvas:e,ctx:t}=n;return t.translate(et(Ul.x),et(Ul.y)),t.shadowColor="rgba(12, 18, 28, 0.38)",t.shadowBlur=et(4),t.shadowOffsetX=0,t.shadowOffsetY=et(2),t.beginPath(),t.lineWidth=et(4),t.lineCap="round",t.strokeStyle="#dfe2e8",t.moveTo(et(-6),0),t.lineTo(et(6),0),t.stroke(),rs=e,e},Xd=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]},Hd=(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]=Xd(n),p=n[0]*e+n[2]*t+n[4],g=n[1]*e+n[3]*t+n[5],b=Y([h,d,f,m,0,0],[c,u,-u,c,0,0],!0),x=(i.x-o.x/2)/s,y=(i.y-o.y/2)/s;return{matrix:[b[0],b[1],b[2],b[3],p-(b[0]*x+b[2]*y),g-(b[1]*x+b[3]*y)],dims:{x:o.x/s,y:o.y/s},color:[1,1,1,1],texture:a}},Wd=(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},ss=class{constructor(e){this.host=e}host;node=null;circlesVisible=!0;ratio=null;detachKey=null;get active(){return this.node!==null}get target(){return this.node}get info(){let e=this.node;if(!e||!(e instanceof le?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 le}}enter(e){if(this.node&&this.exit(),e instanceof le){if(!this.host.document.nodes.includes(e)||e.clipDynamicKind||!e.clipImageRaw||!e.clipImageEl)return!1}else if(e instanceof re||!e.isImageType||!e.imageEl)return!1;this.node=e,this.ratio=null;let t=Math.abs(e.raw.scaleX??1),r=Math.abs(e.raw.scaleY??1);if(this.circlesVisible=t===r,this.host.document.exitEditing(),this.host.document.setSelection([e],"update"),!(e instanceof le)){let o=i=>{i.key==="Escape"&&this.node&&this.exit()};window.addEventListener("keydown",o),this.detachKey=()=>window.removeEventListener("keydown",o)}return this.host.requestRenderAll(),!0}exit(){if(!this.node)return;let e=this.node;this.node=null,this.ratio=null,this.detachKey?.(),this.detachKey=null,this.host.document.applyTransform([e],()=>({}),"modified",{action:Le.crop}),this.host.requestRenderAll()}exitByOutsideClick(){this.exit()}setAspectRatio(e){if(this.node){if(this.ratio=e,e&&e>0){let t=kd(this.liveState(),e);this.writeBack(t)}this.host.requestRenderAll()}}hitHandle(e,t){let r=this.node;if(!r)return null;let o=r.matrix,i=this.liveState();for(let s of Fd){let a=yn[s],l=V(o,a.x*i.width,a.y*i.height),c=this.host.toScreen(l.x,l.y);if(Math.hypot(c.x-e,c.y-t)<=Ld)return s}if(!this.ratio)for(let s of Bd){let a=yn[s],l=V(o,a.x*i.width,a.y*i.height),c=this.host.toScreen(l.x,l.y);if(Math.hypot(c.x-e,c.y-t)<=Ld)return s}if(this.circlesVisible)for(let s of Od){let a=xo(i,s),l=V(o,a.x,a.y),c=this.host.toScreen(l.x,l.y);if(Math.hypot(c.x-e,c.y-t)<=Tx)return`${s}S`}return null}hitRect(e,t){let r=this.node;if(!r)return!1;let o=this.liveState(),i=r.matrix;if(!(r instanceof le)){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 V(i,d,f)});return Wd({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=V(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 Wd(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?Rd(o,e.slice(0,2),t):null:Mi(e)?i=this.ratio?Cd(o,e,t,this.ratio):Md(o,e,t):this.ratio||(i=ts(o,e,t)),i&&this.writeBack(i),this.host.requestRenderAll()}moveImageBy(e){if(!this.node)return;let r=this.liveState(),{cropX:o,cropY:i}=Pd(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=yn[o.slice(0,2)],a=((this.node.raw.angle??0)+Math.atan2(i.y,i.x)*180/Math.PI+360)%360;return`${Cx[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=(g,b)=>V(o,g,b),a=r.width,l=r.height,c=Ex/e;for(let g of[1,2]){let b=-a/2+g*a/3,x=s(b,-l/2),y=s(b,l/2);i.push(Ce(x,y,c,_d))}for(let g of[1,2]){let b=-l/2+g*l/3,x=s(-a/2,b),y=s(a/2,b);i.push(Ce(x,y,c,_d))}let u=Mx/e,h=["tl","tr","br","bl"].map(g=>s(xo(r,g).x,xo(r,g).y));for(let g=0;g<4;g++)i.push(Ce(h[g],h[(g+1)%4],u,Dd));let d=1.5/e,f=["tl","tr","br","bl"].map(g=>s(yn[g].x*a,yn[g].y*l));for(let g=0;g<4;g++)i.push(Ce(f[g],f[(g+1)%4],d,Dd));if(this.circlesVisible){let g=Rx(),[b,x,y,S]=Xd(o),v=g.width/e;for(let T of Od){let C=xo(r,T);i.push({matrix:[b,x,y,S,o[0]*C.x+o[2]*C.y+o[4],o[1]*C.x+o[3]*C.y+o[5]],dims:{x:v,y:v},color:[1,1,1,1],texture:g})}}if(!this.ratio){let g={top:0,right:90,bottom:180,left:270},b=kx();for(let x of Bd){let y=yn[x];i.push(Hd(o,y.x*a,y.y*l,g[x],Yl,Ul,e,b))}}let m={tl:0,tr:90,br:180,bl:270},p=Px();for(let g of Fd){let b=yn[g];i.push(Hd(o,b.x*a,b.y*l,m[g],{x:os,y:os},{x:is,y:is},e,p))}return i}dispose(){this.detachKey?.(),this.detachKey=null,this.node=null}liveState(){let e=this.node;if(e instanceof le)return wd(e.raw,e.clipImageRaw,e.clipImageEl);let t=e.imageEl;return Ad(e.raw,t.naturalWidth,t.naturalHeight)}writeBack(e){let t=this.node,r=t instanceof le?Td(e):Nd(e);this.host.document.setProps(t,r,{deferIndexRebuild:!0})}};var zd={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}},Yd=(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}},Ud=(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,g=-u,b=u,x=-h,y=h;o.left&&(g=Math.min(m,b-1)),o.right&&(b=Math.max(m,g+1)),o.top&&(x=Math.min(p,y-1)),o.bottom&&(y=Math.max(p,x+1));let S=o.right,v=o.left,T=o.bottom,C=o.top,R=e.centerX-l,w=e.centerY-c,E=R*s+w*a,M=-R*a+w*s,P=E-e.scaledWidth/2,A=E+e.scaledWidth/2,k=M-e.scaledHeight/2,O=M+e.scaledHeight/2;!S&&P<g&&(g=P),!v&&A>b&&(b=A),!T&&k<x&&(x=k),!C&&O>y&&(y=O);let F=(g+b)/2,W=(x+y)/2;return{width:b-g,height:y-x,centerX:l+F*s-W*a,centerY:c+F*a+W*s}},Vl=(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,g=n.height/2,b=Math.max(0,h-f+p),x=Math.max(0,p-h-f),y=Math.max(0,d-m+g),S=Math.max(0,g-d-m);return{left:Math.floor(b*a),right:Math.floor(x*a),top:Math.floor(y*l),bottom:Math.floor(S*l)}},$d=(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}},er={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}};var as=n=>n*Math.PI/180,Ax=12,Nx=8,Lx=1,Ix=(()=>{let n=ae("#3788ff");return[n[0],n[1],n[2],.5]})(),_x=ae("#3788ff"),Dx=ae("#ffffff"),Fx=(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},ls=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 re?!1:(e.isImageType||e instanceof le)&&!!e.imageEl&&!(e instanceof le&&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=Vl(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(){this.exit()}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=as(r.angle),i=Math.cos(o),s=Math.sin(o);for(let a of Object.keys(er)){let l=er[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)<=Ax)return a}return null}hitRect(e,t){let r=this.view(),o=as(r.angle),i=Math.cos(o),s=Math.sin(o),a=["tl","tr","br","bl"].map(l=>{let c=er[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 Fx({x:e,y:t},a)}applyHandle(e,t){let r=this.node;if(!r)return;let o=this.view(),i=Ud(o.rect,o.img,o.angle,t,zd[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=$d(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){return this.hitHandle(e,t)?"pointer":this.hitRect(r,o)?"move":""}buildUnderlay(){let e=this.view(),t=as(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:Ix}]}buildOverlay(e){let t=this.view(),r=[],o=as(t.angle),i=[Math.cos(o),Math.sin(o),-Math.sin(o),Math.cos(o),t.rect.centerX,t.rect.centerY],s=u=>{let h=er[u];return V(i,h.x*t.rect.width,h.y*t.rect.height)},a=Lx/e,l=["tl","tr","br","bl"].map(s);for(let u=0;u<4;u++)r.push(Ce(l[u],l[(u+1)%4],a,_x));let c=Nx/e;for(let u of Object.keys(er)){let h=er[u],d=h.x*t.rect.width,f=h.y*t.rect.height,m=[i[0],i[1],i[2],i[3],i[4]+d*i[0]+f*i[2],i[5]+d*i[1]+f*i[3]];r.push({matrix:m,dims:{x:c,y:c},color:Dx})}return r}dispose(){this.detachKey?.(),this.detachKey=null,this.node=null}view(){let e=this.node;return this.expandViewOf(e,e.imageEl)}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=Yd(r,s,{width:a,height:l}),h=r.angle??0,d=t?Vl(u,c,h,{width:t.naturalWidth,height:t.naturalHeight}):null;return{rect:u,img:c,angle:h,offsets:d}}};var Ox=8,Bx=6;var nr=n=>{if(!n)return null;let e=qe(n);return e?{x:(e.left+e.right)/2,y:(e.top+e.bottom)/2}:null},Vd=(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}},tr=(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}},Hx=n=>n==="C"?5:n==="Q"?3:1,ht=(n,e,t)=>({x:n[e]-t.x,y:n[e+1]-t.y}),jl=(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:ht(o,o.length-2,e)}),s==="C"){let a=ht(o,1,e),l=ht(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?ht(n[i-1],Hx(c),e):a;r.push({from:a,to:u},{from:l,to:ht(o,5,e)})}else if(s==="Q"){let a=ht(o,1,e);t.push({key:`c_${i}_Q_CP_1`,kind:"handle",commandIndex:i,pointIndex:1,local:a}),r.push({from:a,to:ht(o,3,e)})}}),{handles:t,connections:r}},Kd=(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}})),cs=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}},Wx=(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)}},Gx=(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}},jd=(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}},qd=(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}},Xx=(n,e,t)=>({x:n.x+(e.x-n.x)*t,y:n.y+(e.y-n.y)*t}),Qd=(n,e,t,r,o)=>{let i=Ox/o,s=Bx/o,a=h=>V(r,h.x,h.y),l=(h,d)=>a(ht(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 T={x:tr(n,d).x-e.x,y:tr(n,d).y-e.y},C=a(T),R=l(h,1),w=f==="C"?ht(h,5,e):ht(h,3,e),E=a(w),P=Gx(t,f==="C"?F=>jd(C,R,l(h,3),E,F):F=>qd(C,R,E,F));if(P.distance>i||P.length<=s*2||P.distance>=u)return;let A=s/P.length;if(P.t<=A||P.t>=1-A)return;let k=tr(n,d),O=f==="C"?(()=>{let F={x:k.x-e.x,y:k.y-e.y},W=ht(h,1,e),X=ht(h,3,e),_={x:h[5]-e.x,y:h[6]-e.y};return jd(F,W,X,_,P.t)})():(()=>{let F={x:k.x-e.x,y:k.y-e.y},W=ht(h,1,e),X={x:h[3]-e.x,y:h[4]-e.y};return qd(F,W,X,P.t)})();u=P.distance,c={commandIndex:d,commandType:f,t:P.t,local:O,scene:P.point};return}if(f!=="L"&&f!=="Z")return;let m=f==="L"?tr(n,d):Vd(n,Math.max(0,d-1)),p=Vd(n,d),g=a({x:m.x-e.x,y:m.y-e.y}),b=a({x:p.x-e.x,y:p.y-e.y}),x=Wx(t,g,b);if(x.distance>i||x.length<=s*2||x.distance>=u)return;let y=s/x.length;if(x.t<=y||x.t>=1-y)return;u=x.distance;let S={x:m.x-e.x,y:m.y-e.y},v={x:p.x-e.x,y:p.y-e.y};c={commandIndex:d,commandType:f,t:x.t,local:Xx(S,v,x.t),scene:x.point}}),c},Zd=(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}),Jd=(n,e,t,r)=>n.map((o,i)=>i===e?{x:t.x+r.x,y:t.y+r.y}:o),ef=(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=tr(n,s),c=t.t,u=a[1],h=a[2],d=a[3],f=a[4],m=a[5],p=a[6],g=l.x+(u-l.x)*c,b=l.y+(h-l.y)*c,x=u+(d-u)*c,y=h+(f-h)*c,S=d+(m-d)*c,v=f+(p-f)*c,T=g+(x-g)*c,C=b+(y-b)*c,R=x+(S-x)*c,w=y+(v-y)*c;return r[s]=["C",g,b,T,C,o,i],r.splice(s+1,0,["C",R,w,S,v,m,p]),r}if(t.commandType==="Q"){let a=r[s],l=tr(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,g=u+(d-u)*c,b=h+(f-h)*c;return r[s]=["Q",m,p,o,i],r.splice(s+1,0,["Q",g,b,d,f]),r}return t.commandType==="Z"?(r.splice(s,1,["L",o,i],["Z"]),r):null},tf=(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=tr(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}},ql=(n,e)=>{let t=n?.[e]?.[0];return t&&["C","Q","S","T","A"].includes(String(t).toUpperCase())?"smooth":"line"},nf=(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 zx=12,yo=ae("#2254f4"),rf=ae("#ffffff"),of=7,sf=5,Yx=1,Kl=null,Ux=()=>{if(Kl)return Kl;let n=Math.ceil((sf+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,sf,0,Math.PI*2),t.fillStyle="#ffffff",t.fill(),t.lineWidth=1.5,t.strokeStyle="#2254f4",t.stroke(),Kl=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},us=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=V(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"&&!Ae(e.raw.path)||t==="poly"&&!Array.isArray(e.raw.points)||t==="line"&&!(e instanceof Sr))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=zx;for(let a of this.currentHandles()){let l=V(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=Ae(r.raw.path),i=nr(o);return!o||!i?null:Qd(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=V(Te(s),t.x,t.y);if(o==="path"){let l=Ae(r.raw.path),c=nr(l);if(!l||!c)return;let u=Zd(l,i.commandIndex,i.pointIndex,a,c);this.writeBackWithCompensation(r,u,c,nr(u),qe(u))}else if(o==="poly"){let l=r.raw.points,c=cs(l);if(!c)return;let u=Jd(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,cs(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=Ae(t.raw.path),o=nr(r);if(!r||!o)return null;let i=ef(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=Ae(r.raw.path);if(!o)return!1;let i=tf(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=[...bn(t.aCoords,e)],s=a=>V(o,a.x,a.y);if(r==="path"){let a=Ae(t.raw.path),l=nr(a);if(!a||!l)return i;let{handles:c,connections:u}=jl(a,l),h=Yx/e;for(let p of u)i.push(Ce(s(p.from),s(p.to),h,yo));let d=of/e,f=Ux(),m=f.width/2*2*(1/e);for(let p of c){let g=s(p.local);if(p.kind==="handle")i.push({matrix:[1,0,0,1,g.x,g.y],dims:{x:m,y:m},color:[1,1,1,1],texture:f});else{let b=p.key===this.activeAnchorKey;i.push({matrix:[1,0,0,1,g.x,g.y],dims:{x:d,y:d},color:yo}),i.push({matrix:[1,0,0,1,g.x,g.y],dims:{x:d-2/e,y:d-2/e},color:b?yo:rf})}}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=of/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:yo}),i.push({matrix:[1,0,0,1,c.x,c.y],dims:{x:a-2/e,y:a-2/e},color:u?yo:rf})}}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=Ae(e.raw.path),l=nr(a);return!a||!l?[]:jl(a,l).handles}if(t==="poly"){let a=e.raw.points,l=cs(a);return!Array.isArray(a)||!l?[]:Kd(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=nf(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 $x}from"warpvas";var af=12,Vx=5,jx=4,qx=1,lf=3,cf=2e3,uf=10,Kx=[.2,.2,.2,.6],Qx=[.11,.35,.96,1],Zx=[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 Ql){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 re||!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 $x(s,t?.gridRows??lf,t?.gridCols??lf);l.setInputLimitSize({width:cf,height:cf}),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 hf){let u=df(l,c);if(!u)continue;let h=this.screenDist(u,e,t);h<=af&&(!i||h<i.dist)&&(i={anchor:{kind:"vertex",row:s,col:a,pos:c},dist:h})}else for(let c of Ql){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<=af&&(!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 Ql){let c=a[l];if(!c||c.length<4)continue;let u=this.toScene(c[0]);for(let h=1;h<=uf;h++){let d=this.toScene(Jx(c[0],c[1],c[2],c[3],h/uf));t.push(Ce(u,d,qx/e,Kx)),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(ff(this.toScene(d),jx,Zx,e)))}}for(let l of hf){let c=df(a,l);if(!c)continue;let u=`${Math.round(c.x)},${Math.round(c.y)}`;o.has(u)||(o.add(u),t.push(ff(this.toScene(c),Vx,Qx,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},g=xe({...r.raw,width:d,height:f},p),b={x:l.width/2-l.offsetX,y:l.height/2-l.offsetY};i={dataURL:a,state:c,nextWidth:d,nextHeight:f,left:g.x,top:g.y,originalSrc:this.originalSrc,displayScale:{x:this.displayScale.x,y:this.displayScale.y},coreAnchor:b}}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 ey(this.node.matrix,e,t)}toScene(e){let t=this.node;return V(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)}},hf=["tl","tr","bl","br"],Ql=["top","right","bottom","left"],df=(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},Jx=(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}},ff=(n,e,t,r)=>({matrix:[1,0,0,1,n.x,n.y],dims:{x:e*2/r,y:e*2/r},color:t}),ey=(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 Pr=([n,e],[t,r])=>n<=t?e>=t:n>=t?r>=n:!1,ds=([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)},bf=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}},ty=(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},mf=(n,e,t,r,o,i,s)=>{let a=[],l=(c,u,h,d,f,m)=>{let p=u;for(let g of d){let b=ty(c,u,g[u]-h),x=g[u]+h,y=m[p];a.length=0;for(let S=b;S<c.length;S++){let v=c[S];if(v.p[u]>x)break;let T=v.p[u]-g[u],C=Math.abs(T);C<=y&&(C<y&&(y=C,a.length=0),a.push({p:v.p,i:v.i,offset:T}))}a.sort((S,v)=>S.i-v.i);for(let S of a)jt(f,S.offset,m,p,{type:"point",points:[g,S.p],offset:S.offset})}};l(e.byX,"x",t,n,i,o),l(e.byY,"y",r,n,s,o)},Jl=n=>({x:he(n.x),y:he(n.y)}),Zl=n=>({left:he(n.left),top:he(n.top),right:he(n.right),bottom:he(n.bottom)}),ms=n=>[n.tl,n.tr,n.br,n.bl,n.c].map(Jl),gf=n=>n.flatMap(ms);var xf=n=>{let e=n.map(Zl).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 ny=(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=(w,E,M,P)=>({startBounds:w,endBounds:E,startSide:[{x:w.right,y:w.top},{x:w.right,y:w.bottom}],endSide:[{x:E.left,y:E.top},{x:E.left,y:E.bottom}],length:P,overlap:M}),g=(w,E,M,P)=>({startBounds:w,endBounds:E,startSide:[{x:w.left,y:w.bottom},{x:w.right,y:w.bottom}],endSide:[{x:E.left,y:E.top},{x:E.right,y:E.top}],length:P,overlap:M}),b=(w,E)=>{if(!(w.right<E.left&&Pr([w.top,w.bottom],[E.top,E.bottom])))return;let M=ds([w.top,w.bottom],[E.top,E.bottom]);if(!Pr([s,l],M))return;let P=E.left-w.right,A=he(w.right+P/2-c);if(P>f&&Math.abs(A)<=t.x){jt(r,A,t,"x",{type:"gap",direction:"center_horizontal",gap:p(w,E,M,P),offset:A});return}let k=he(P-(i-E.right));if(Math.abs(k)<=t.x){jt(r,k,t,"x",{type:"gap",direction:"side_right",gap:p(w,E,M,P),offset:k});return}let O=he(w.left-a-P);Math.abs(O)<=t.x&&jt(r,O,t,"x",{type:"gap",direction:"side_left",gap:p(w,E,M,P),offset:O})},x=(w,E)=>{if(!(w.bottom<E.top&&Pr([w.left,w.right],[E.left,E.right])))return;let M=ds([w.left,w.right],[E.left,E.right]);if(!Pr([i,a],M))return;let P=E.top-w.bottom,A=he(w.bottom+P/2-u);if(P>m&&Math.abs(A)<=t.y){jt(o,A,t,"y",{type:"gap",direction:"center_vertical",gap:g(w,E,M,P),offset:A});return}let k=he(w.top-l-P);if(Math.abs(k)<=t.y){jt(o,k,t,"y",{type:"gap",direction:"side_top",gap:g(w,E,M,P),offset:k});return}let O=he(s-E.bottom),F=P-O;Math.abs(F)<=t.y&&jt(o,F,t,"y",{type:"gap",direction:"side_bottom",gap:g(w,E,M,P),offset:F})},y=e.byLeft,S=e.byRight,v=e.byTop,T=e.byBottom,C=h+1e-6,R=d+1e-6;{let w=y.length;for(let E of S){if(E.bounds.right>=c+h+.001)break;let M=2*c-E.bounds.right,P=M+2*C,A=M-2*C;for(;w>0&&y[w-1].bounds.left>P;)w--;for(let k=w-1;k>=0&&y[k].bounds.left>=A;k--)b(E.bounds,y[k].bounds)}}{let w=0;for(let E of e.byLeftPlusRight){if(E.bounds.right>=i+h+.001)continue;let M=E.bounds.left+E.bounds.right-i,P=M-C,A=M+C;for(;w<S.length&&S[w].bounds.right<P;)w++;for(let k=w;k<S.length&&S[k].bounds.right<=A;k++)b(S[k].bounds,E.bounds)}}{let w=0;for(let E of e.byLeftPlusRight){if(E.bounds.left<=a-h-.001)continue;let M=E.bounds.left+E.bounds.right-a,P=M-C,A=M+C;for(;w<y.length&&y[w].bounds.left<P;)w++;for(let k=w;k<y.length&&y[k].bounds.left<=A;k++)b(E.bounds,y[k].bounds)}}{let w=v.length;for(let E of T){if(E.bounds.bottom>=u+d+.001)break;let M=2*u-E.bounds.bottom,P=M+2*R,A=M-2*R;for(;w>0&&v[w-1].bounds.top>P;)w--;for(let k=w-1;k>=0&&v[k].bounds.top>=A;k--)x(E.bounds,v[k].bounds)}}{let w=0;for(let E of e.byTopPlusBottom){if(E.bounds.top<=l-d-.001)continue;let M=E.bounds.top+E.bounds.bottom-l,P=M-R,A=M+R;for(;w<v.length&&v[w].bounds.top<P;)w++;for(let k=w;k<v.length&&v[k].bounds.top<=A;k++)x(E.bounds,v[k].bounds)}}{let E=0;for(let M of e.byTopPlusBottom){if(M.bounds.bottom>=s+d+.001)continue;let P=M.bounds.top-he(s-M.bounds.bottom),A=P-R,k=P+R;for(;E<T.length&&T[E].bounds.bottom<A-1e-5;)E++;for(let O=E;O<T.length&&T[O].bounds.bottom<=k;O++)x(T[O].bounds,M.bounds)}}},fs=(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})}},ry=(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(!Pr([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,g=he(h.length-p);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_right",gap:h,offset:g});continue}let b=h.startBounds.left-a,x=he(b-h.length);if(Math.abs(x)<=t.x){Math.abs(x)<t.x&&(r.length=0),t.x=Math.abs(x),r.push({type:"gap",direction:"side_left",gap:h,offset:x});continue}}for(let h of e.verticalGaps){if(!Pr([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,g=he(p-h.length);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_top",gap:h,offset:g});continue}let b=he(s-h.endBounds.bottom),x=h.length-b;if(Math.abs(x)<=t.y){Math.abs(x)<t.y&&(o.length=0),t.y=Math.abs(x),o.push({type:"gap",direction:"side_bottom",gap:h,offset:x});continue}}},pf=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())},yf=(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:pf(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:pf(a.map(l=>({x:l.x,y:Number(s)})).sort((l,c)=>l.x-c.x))}));return[...o,...i]},oy=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())},iy=(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=ds([r,i],a.gap.overlap),h=ds([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 oy(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)}]})))},vf=(n,e,t,r,o,i)=>{let s=(b,x,y)=>{"byLeft"in r?ny(b,r,l,x,y):ry(b,r,l,x,y)},a=Zl(e),l={x:o,y:o},c=[],u=[];i?mf(n,i,o,o,l,c,u):fs(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(b=>Jl({x:b.x+h.x,y:b.y+h.y})),f=Zl({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?mf(d,i,0,0,l,c,u):fs(d,t,l,c,u),s(f,c,u);let m=yf(c,u),p=[...c,...u].filter(b=>b.type==="gap"),g=iy(f,p);return{snapOffset:h,pointSnapLines:m,gapSnapLines:g}},Sf=(n,e,t)=>{let r={x:t,y:t},o=[],i=[];fs(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=>Jl({x:c.x+s.x,y:c.y+s.y}));fs(a,e,r,o,i);let l=yf(o,i);return{snapOffset:s,pointSnapLines:l}};var sy=200,wf=8,ay=1,ly=3,cy=8,uy=ae("#F68066"),Tf=new Set(["WorkSpaceClipType","WorkSpaceSafeType","WorkSpaceMaskType","WorkSpaceLineType","WorkSpaceShadowType"]),hy="WorkSpaceDrawType",kr=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)}),Ef=(n,e)=>!(kr(n).right<e.minX||kr(n).left>e.maxX||kr(n).bottom<e.minY||kr(n).top>e.maxY),dy=n=>({x:(n.tl.x+n.br.x)/2,y:(n.tl.y+n.br.y)/2}),ps=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=Je(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:dy(r.quad)},i=wf/this.host.zoom,{snapOffset:s,pointSnapLines:a,gapSnapLines:l}=vf(ms(o),kr(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=Je(r);if(!o||!this.scalingPoints.length)return;let s=(Mi(t)?[t]:[...dl]).map(c=>({x:o.quad[c].x,y:o.quad[c].y})),a=wf/this.host.zoom,{pointSnapLines:l}=Sf(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=ay/e,o=(i,s)=>t.push(Ce(i,s,r,uy));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=ly/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=cy/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)||Tf.has(l.id))continue;let c=this.nodeCoords(l);a&&!Ef(c,a)||this.referenceCoords.push(c)}this.referencePoints=gf(this.referenceCoords),this.axisIndex=bf(this.referencePoints),this.gapIndex=xf(this.referenceCoords.map(kr))}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)||Tf.has(s.id))continue;let a=this.nodeCoords(s);o&&!Ef(a,o)||i.push(...ms(a))}this.scalingPoints=i}ensureWorkspaceInfo(){if(this.workspaceResolved)return;this.workspaceResolved=!0;let e=this.host.document.nodes.find(o=>o.id===hy);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=sy/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 Mf=n=>{let e=n?.animates;return Array.isArray(e)?e.filter(t=>!!t&&typeof t=="object"&&typeof t.key=="string"):[]},fy={width:0,height:0},be=(n,e={})=>({originX:"center",originY:"center",left:n.center.x,top:n.center.y,...e}),Bt=(n,e,t=fy,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}),my=[{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})}],py=[{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})}],by=[{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})}],gy=[...my,...py,...by],ec=new Map(gy.map(n=>[n.key,n])),xy=n=>ec.get(n),bs=n=>{let e=ec.get(n);return e?e.category==="entrance"?0:e.category==="emphasis"?1:2:Number.MAX_SAFE_INTEGER},Cf=n=>bs(n)===1,yy=n=>{let e=n.duration??0;return!Cf(n.key)||!n.single?e:Math.floor(e/n.single)*n.single},vy=n=>{let e=[...n].sort((r,o)=>{let i=bs(r.key)-bs(o.key);return i!==0?i:bs(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})},Rf=.2,Pf=(n,e)=>{let t=[];for(let s of n)for(let a of vy(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=yy(s.animate),h=c+Rf,d=h+u;r.push({target:s.target,animate:s.animate,definition:ec.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}},tc=(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;Cf(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:kf(l.key,h,d,u)})}),r},kf=(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},Sy=n=>1-Math.cos(Math.min(Math.max(n,0),1)*Math.PI/2),Af=(n,e,t)=>{let r=xy(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:Rf,loopDuration:l,loopCount:a}},nc=(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:kf(e.key,a,l,Sy(s)),done:!1}},gs=n=>n.scrollSpeed?(n.textTotalWidth+n.viewWidth)/n.scrollSpeed:0,wy=(n,e,t)=>{if(e<=0)return 0;let r=Math.max(n,0);return t==="loop"?r%e:Math.min(r,e)},Nf=(n,e,t="loop")=>{if(!n.scrollEnabled)return 0;let r=gs(n);if(r<=0)return 0;let o=wy(e,r,t)/r,i=n.textTotalWidth+n.viewWidth;return n.scrollDirection==="left-to-right"?o*i:-o*i},vo=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")}},rc=(n,e)=>Math.max(n,...e,0);var Lf=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:ae(i),blur:t,offsetX:r,offsetY:o,nonScaling:!!e.nonScaling}},Ht=(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}},xs=n=>Math.ceil(n.blur*2+Math.max(Math.abs(n.offX),Math.abs(n.offY))+4),If=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 qt=(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+ln(h),y:t+fr(d,u,h)}),a+=$n(c,u,s)}return i},Kt=(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()},vn=(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 oc=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}},ic=(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&&Et(n,l,c,u,{fill:"keep"}),i){let h=qt(l,c,u,o,o.charSpacing??0);for(let d=0;d<h.length;d++){let f=vn(o,l.charStyles[d]);n.font=Me(f,f.fontSize),Kt(n,{...h[d],y:h[d].y+Tt(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=vn(o,d);n.font=Me(f,f.fontSize),n.fillText(l.graphemes[h],c+l.boxes[h].left,u+Tt(s,f.fontSize,a+h))}a+=l.graphemes.length}},ys=(n,e,t)=>{let r=e.dims.x,o=e.dims.y;if(e.isSolidType){n.fillStyle=t;let i=ot(e.raw,r,o);if(i){Wr(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(ee(i)===L.ELLIPSE||ee(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 re){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 re)?Ko(e.raw,r,o):null;s&&(n.save(),Wr(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 ge){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}ic(n,e,t)}},_f=(n,e)=>{let t=Ht(e,n.raw.scaleX??1,n.raw.scaleY??1),r=xs(t)+(n.isTextType?Math.ceil((n.raw.fontSize??40)*.5):0),o=oc(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,ys(l,n,u),l.shadowColor="rgba(0,0,0,0)",l.shadowBlur=0,l.shadowOffsetX=0,l.shadowOffsetY=0,l.globalCompositeOperation="destination-out",ys(l,n,u),{canvas:a,w:i,h:s}};var sc=(n,e,t)=>{let r=e+t,o=n,i=new Array(e*t).fill(0);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,g)=>Math.floor((m*m-f*f+g*g-p*p)/(2*(m-f))),l=new Array(e*t).fill(0),c=new Array(e).fill(0),u=new Array(e).fill(0),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},Df=(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 Ff={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]},de=(n,e)=>typeof n=="number"&&Number.isFinite(n)?n:e,Sn=(n,e)=>typeof n=="string"&&n?n:e,ac=(n,e)=>typeof n=="boolean"?n:e;function Ty(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(Ey(r,s))})}return o}function Ey(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 My(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 Ty(e))t.push(r.input,r.output);return t}function So(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?de(r.brightness,0)/100:de(r.brightness,0)});break;case"Contrast":e.push({kind:"Contrast",contrast:o?de(r.contrast,0)/100:de(r.contrast,0)});break;case"Saturation":e.push({kind:"Saturation",saturation:o?de(r.saturation,0)/100:de(r.saturation,0)});break;case"Vibrance":e.push({kind:"Vibrance",vibrance:o?de(r.vibrance,0)/100:de(r.vibrance,0)});break;case"HueRotation":e.push({kind:"HueRotation",rotation:o?de(r.hue,0)/100:de(r.rotation,0)});break;case"Grayscale":{let i=Sn(r.mode,"average");e.push({kind:"Grayscale",mode:i==="lightness"||i==="luminosity"?i:"average"});break}case"Invert":e.push({kind:"Invert",invert:ac(r.invert,!0),alphaOnly:ac(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:de(o?r.radius:r.blur,0)});break;case"Noise":e.push({kind:"Noise",noise:de(r.noise,0)});break;case"Pixelate":e.push({kind:"Pixelate",blocksize:de(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:ac(r.opaque,!1)});break}case"BlendColor":{let i=Sn(r.mode,"multiply"),s=["multiply","screen","add","difference","subtract","darken","lighten","overlay","exclusion","tint"];e.push({kind:"BlendColor",color:Sn(r.color,"#000000"),mode:s.includes(i)?i:"multiply",alpha:de(r.alpha,1)});break}case"Vignette":e.push({kind:"Vignette",intensity:de(r.intensity,0)});break;case"Temperature":{if(o){let i=wn(Sn(r.color,"#ffb86b")),s=i[0]>=i[2];e.push({kind:"Temperature",temperature:de(r.density,0)/100*(s?1:-1)})}else e.push({kind:"Temperature",temperature:de(r.temperature,0)});break}case"Posterize":e.push({kind:"Posterize",levels:de(r.levels,20)});break;case"FilmGrain":e.push({kind:"FilmGrain",intensity:de(r.intensity,0),seed:de(r.seed,0)});break;case"Duotone":e.push({kind:"Duotone",color1:Sn(r.color1,"#000000"),color2:Sn(r.color2,"#ffffff")});break;case"Sketch":e.push({kind:"Sketch"});break;case"ChromaticAberration":e.push({kind:"ChromaticAberration",offset:de(r.offset,4)});break;case"SoftFocus":e.push({kind:"SoftFocus",blend:de(r.blend,.5)});break;case"Threshold":e.push({kind:"Threshold",threshold:de(r.threshold,128)});break;case"UnsharpMask":e.push({kind:"UnsharpMask",amount:o?de(r.amount,100)/100:de(r.amount,1)});break;case"MotionBlur":e.push({kind:"MotionBlur",distance:de(r.distance,0),angle:de(r.angle,0)});break;case"LensFlare":e.push({kind:"LensFlare",intensity:de(r.intensity,.8)});break;case"GradientMap":e.push({kind:"GradientMap",color0:Sn(r.color0,"#000000"),color1:Sn(r.color1,"#888888"),color2:typeof r.color2=="string"&&r.color2?r.color2:""});break;case"Levels":e.push({kind:"Levels",blackPoint:de(r.blackPoint,0),whitePoint:de(r.whitePoint,255),gamma:de(r.gamma,1)});break;case"Curves":e.push({kind:"Curves",points:My(r.points)});break;case"SurfaceBlur":e.push({kind:"SurfaceBlur",radius:de(r.radius,3),threshold:o?de(r.threshold,51)/255:de(r.threshold,.2)});break;case"Exposure":e.push({kind:"Exposure",exposure:de(r.exposure,0),offset:de(r.offset,0),gamma:de(r.gamma,1)});break;default:break}}return e}function rr(n){return JSON.stringify(n)}var $E=Math.PI/2;function wn(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 vs=(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)},Cy=6e5,Ss=n=>Math.max(1,Math.floor(Math.sqrt(Cy/Math.max(1,n.dims.x*n.dims.y)))),ws=n=>{if(!n.isImageType||n instanceof re)return"";let e=So(n.raw.filters);return e.length?`|f${rr(e)}`:""},Ry=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}},Of=n=>({color:n.color,rgba:n.rgba,blur:n.blur,offsetX:n.offsetX,offsetY:n.offsetY,nonScaling:!1}),wo=(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),ic(i,n,"#ffffff"),o):null},Ts=(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 x of e){let y=Ht(Of(x),i,s);a=Math.max(a,Math.ceil(y.blur*2+Math.max(Math.abs(y.offX),Math.abs(y.offY))+4))}let l=Ry(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=document.createElement("canvas");f.width=h,f.height=d;let m=f.getContext("2d");if(!m)return null;let p=n.matrix;m.setTransform(p[0]*r,p[1]*r,p[2]*r,p[3]*r,h/2,d/2);let g=n.dims.x,b=n.dims.y;for(let x of e){let y=Ht(Of(x),i,s);m.filter=`drop-shadow(${y.offX*r}px ${y.offY*r}px ${y.blur*r}px ${x.color})`,vs(m,t,o,-g/2,-b/2,g,b)}return m.filter="none",m.globalCompositeOperation="destination-out",vs(m,t,o,-g/2,-b/2,g,b),{canvas:f,w:h,h:d,quadW:c,quadH:u}},Py=(n,e,t)=>{let r=[1,0,0,1,n.offsetX,n.offsetY];return n.gradientUnits==="percentage"&&(r=Y(r,[e,0,0,t,0,0])),n.gradientTransform&&(r=Y(r,n.gradientTransform)),r},Ar=(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 h=e.decl,d=Py(h,a,l);u.setTransform(d[0],d[1],d[2],d[3],d[4],d[5]);let f=h.kind==="linear"?u.createLinearGradient(h.x1,h.y1,h.x2,h.y2):u.createRadialGradient(h.x1,h.y1,h.r1,h.x2,h.y2,h.r2);for(let m of h.stops){let p=Math.min(1,Math.max(0,m.offset));f.addColorStop(p,`rgba(${Math.round(m.color[0]*255)}, ${Math.round(m.color[1]*255)}, ${Math.round(m.color[2]*255)}, ${m.color[3]})`)}if(u.fillStyle=f,h.gradientUnits==="percentage")u.fillRect(-2,-2,5,5);else{let m=Te(d),p=[V(m,0,0),V(m,a,0),V(m,0,l),V(m,a,l)];if(p.every(g=>isFinite(g.x)&&isFinite(g.y))){let g=Math.min(...p.map(S=>S.x))-2,b=Math.max(...p.map(S=>S.x))+2,x=Math.min(...p.map(S=>S.y))-2,y=Math.max(...p.map(S=>S.y))+2;u.fillRect(g,x,b-g,y-x)}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);return u.globalCompositeOperation="destination-in",vs(u,t,o,0,0,a,l),c},Bf=(n,e)=>{if(e.length===0)return null;let t=n.raw.fill;if(typeof t!="string"||!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=Xr(n,c),!zn(c,n))return null;c.fill()}return c.filter="none",{canvas:l,w:s,h:a,quadW:s,quadH:a}},Tn=(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[];vs(h,t,i,(l-n.dims.x*a)/2,(c-n.dims.y*a)/2,n.dims.x*a,n.dims.y*a);let d=[];for(let f=e.length-1;f>=0;f--){let m=e[f],p=m.width,g=m.alignment,b=g==="outside"?p:g==="center"?Math.ceil(p/2):0,x=b*a,y=Math.floor(l+x*2),S=Math.floor(c+x*2);if(y<=0||S<=0)continue;let v=document.createElement("canvas");v.width=y,v.height=S;let T=v.getContext("2d",{willReadFrequently:!0});if(!T)continue;T.drawImage(u,x,x);let C=Df(T.getImageData(0,0,y,S).data),R=sc(C,y,S),w=new Uint8Array(C.length);for(let G=0;G<C.length;G++)w[G]=C[G]?0:1;for(let G=0;G<y;G++)w[G]=1,w[G+(S-1)*y]=1;for(let G=0;G<S;G++)w[G*y]=1,w[y-1+G*y]=1;let E=sc(w,y,S),M=y*S,P=new Int32Array(M);for(let G=0;G<M;G++)P[G]=C[G]?-E[G]:R[G];let A=s?.5*a:0,k,O;g==="inside"?(k=-p*a-A,O=A):g==="center"?(k=-p/2*a-A,O=p/2*a+A):(k=-A,O=p*a+A);let F=Math.round(m.rgba[0]*255),W=Math.round(m.rgba[1]*255),X=Math.round(m.rgba[2]*255),_=Math.round(m.rgba[3]*255),D=document.createElement("canvas");D.width=y,D.height=S;let I=D.getContext("2d");if(!I)continue;let H=I.createImageData(y,S),z=H.data;for(let G=0;G<M;G++){let J=P[G];if(J>=k&&J<O){let B=G*4;z[B]=F,z[B+1]=W,z[B+2]=X,z[B+3]=_}}I.putImageData(H,0,0);let U=document.createElement("canvas");U.width=y,U.height=S;let $=U.getContext("2d");if(!$)continue;r&&$.drawImage(u,x,x),$.drawImage(D,0,0);let K=g==="outside"?p:g==="center"?p/2:0;d.push({canvas:U,w:y,h:S,quadW:y/a,quadH:S/a,dx:b-K+m.offset.x,dy:b-K+m.offset.y})}return d};var Hf=n=>{if(!(Number(n.warpStrength)||0))return null;let t=ee(n);return t===L.ARCHTEXT?"arch":t===L.WAISTTEXT?"waist":t===L.FLAGTEXT?"flag":null},at=2,To=(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?Et(n,i,s,a,{fill:c,stroke:Fe(o,l)}):0,d="",f="",m=null,p=g=>{if(!u)return;n.font=d;let b=s+h;typeof f=="string"&&f?(n.fillStyle=f,n.fillText(u,b,a)):typeof e.raw.fill=="string"&&e.raw.fill&&(n.fillStyle=e.raw.fill,n.fillText(u,b,a)),m&&m.width>0&&(n.lineWidth=m.width,n.strokeStyle=m.color,n.strokeText(u,b,a)),u="",g<i.boxes.length&&(h=i.boxes[g].left)};for(let g=0;g<i.graphemes.length;g++){let b=i.charStyles[g],y=b!==void 0&&(b.fontSize!==void 0||b.fontFamily!==void 0||b.fontWeight!==void 0||b.fontStyle!==void 0)&&b?{...r,fontSize:b.fontSize??r.fontSize,fontFamily:b.fontFamily??r.fontFamily,fontWeight:b.fontWeight??r.fontWeight,fontStyle:b.fontStyle??r.fontStyle}:r,S=Me(y,y.fontSize),v=Fe(o,b),T=typeof b?.fill=="string"?b.fill:"",C=m;u&&(S!==d||v?.color!==C?.color||v?.width!==C?.width||T!==f)&&p(g),u||(d=S,m=v,f=T),u+=i.graphemes[g]}p(i.graphemes.length)}},Nr=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},lc=(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}},Eo=(n,e,t)=>{if(!t||t.dropShadows.length===0&&t.solidFills.length===0&&t.strokes.length===0)return;let r=wo(e,at);if(!r)return;let o=e.dims.x,i=e.dims.y;if(t.dropShadows.length){let s=lc(t.dropShadows,r,at);s&&(n.save(),n.globalCompositeOperation="destination-over",n.drawImage(s.canvas,-s.w/2,-s.h/2,s.w,s.h),n.restore())}for(let s of t.solidFills){let a=Ar(e,s,r,at);a&&n.drawImage(a,-o/2+s.offset.x,-i/2+s.offset.y,o,i)}for(let s of Tn(e,t.strokes,r,!1,Math.min(2,at),null,!0))n.drawImage(s.canvas,-s.quadW/2+s.dx,-s.quadH/2+s.dy,s.quadW,s.quadH)},cc=(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?Nr(t):0,p=Math.ceil(c+l*2+m*2),g=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),b=p*at,x=g*at;if(!(b>0)||!(x>0)||b>8192||x>8192)return null;let y=document.createElement("canvas");y.width=b,y.height=x;let S=y.getContext("2d",{willReadFrequently:!0});if(!S)return null;let v=e==="arch"?h/2*at:0;S.setTransform(at,0,0,at,b/2,x/2+v),To(S,n),Eo(S,n,t);let T=S.getImageData(0,0,b,x),C=new Uint32Array(T.data.buffer),R=b,w=0,E=x,M=0,P=!1;for(let _=0;_<x;_++)for(let D=0;D<b;D++)(C[_*b+D]>>>24&255)>10&&(P=!0,D<R&&(R=D),D>w&&(w=D),_<E&&(E=_),_>M&&(M=_));let A=P?(R+w)/2:b/2,k=P?M:x-1,O=P?Math.max(1,w-R)/2:b/2,F=S.createImageData(b,x),W=new Uint32Array(F.data.buffer),X=(_,D)=>{let I=Math.floor(D),H=I+1;if(I<0||H>=x)return 0;let z=D-I,U=C[I*b+_],$=C[H*b+_],K=U>>>24&255,G=$>>>24&255;if(K<=10&&G<=10)return 0;let J=Math.round((U&255)*(1-z)+($&255)*z),B=Math.round((U>>>8&255)*(1-z)+($>>>8&255)*z),j=Math.round((U>>>16&255)*(1-z)+($>>>16&255)*z);return Math.round(K*(1-z)+G*z)<<24|j<<16|B<<8|J};if(e==="flag")for(let _=0;_<b;_++){let D=O>0?(_-A)/O:0,I=Math.sin(D*Math.PI)*d*at*i;for(let H=0;H<x;H++)W[H*b+_]=X(_,H+I)}else if(e==="arch")for(let _=0;_<b;_++){let D=Math.max(-1,Math.min(1,(_-A)/O)),I=Math.sqrt(Math.max(0,1-D*D)),H=I*I*(3-2*I),z=i>0?Math.pow(H,2.5):H,U=Math.min(1+Math.max(0,i),Math.max(.05,1+i*z));for(let $=0;$<=k;$++){let K=k-$;W[$*b+_]=X(_,k-K/U)}}else{let _=P?(E+M)/2:x/2;for(let D=0;D<b;D++){let I=O>0?(D-A)/O:0,H=1+i*(I*I-.5);H=Math.min(1+Math.abs(i),Math.max(.4,H));for(let z=0;z<x;z++)W[z*b+D]=X(D,_+(z-_)/H)}}return S.setTransform(1,0,0,1,0,0),S.clearRect(0,0,b,x),S.putImageData(F,0,0),{canvas:y,logicalW:p,logicalH:g}},Es=(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&&Et(n,l,c,u,{fill:d,stroke:Fe(o,h)});let f=qt(l,c,u,r,r.charSpacing??0);for(let m=0;m<f.length;m++){let p=l.charStyles[m],g=vn(r,p);n.font=Me(g,g.fontSize);let b=typeof p?.fill=="string"&&p.fill?p.fill:i,x=Fe(o,p),y={...f[m],y:f[m].y+Tt(s,g.fontSize,a+m)};b&&(n.fillStyle=b,Kt(n,y,"fillText")),x&&x.width>0&&(n.lineWidth=x.width,n.strokeStyle=x.color,Kt(n,y,"strokeText"))}a+=l.graphemes.length}},ky=(n,e)=>{let t=e?Nr(e):0,r=Math.ceil(n.dims.x+t*2),o=Math.ceil(n.dims.y+t*2),i=r*at,s=o*at;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(at,0,0,at,i/2,s/2),n.raw.vertical===!0?Es(l,n):To(l,n),Eo(l,n,e),{canvas:a,logicalW:r,logicalH:o}):null};var Gf=2,En=(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,Xf=(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=En(o,u),d=r==="silhouette"?"#ffffff":typeof u?.fill=="string"&&u.fill?u.fill:l,f=r==="silhouette"?null:s?Fe(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))},g=()=>{f&&f.width>0&&(n.lineWidth=f.width,n.strokeStyle=f.color,n.strokeText(c.char,0,0))};a?(g(),p()):(p(),g()),n.restore()}},Wf=(n,e,t=Gf)=>{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",Xf(s,n,e,"silhouette"),i):null},Ay=(n,e,t,r,o)=>{if(r.dropShadows.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;if(r.dropShadows.length||r.solidFills.length){let c=Wf(e,t,o);if(c){if(r.dropShadows.length){let u=lc(r.dropShadows,c,o);u&&(n.save(),n.globalCompositeOperation="destination-over",n.drawImage(u.canvas,a-u.w/2,l-u.h/2,u.w,u.h),n.restore())}for(let u of r.solidFills){let h=Ar(e,u,c,o);h&&n.drawImage(h,a-i/2+u.offset.x,l-s/2+u.offset.y,i,s)}}}if(r.strokes.length){let c=Math.min(Math.max(2,o),Ss(e)),u=Wf(e,t,c);if(u)for(let h of Tn(e,r.strokes,u,!1,c,null,!0))n.drawImage(h.canvas,a-h.quadW/2+h.dx,l-h.quadH/2+h.dy,h.quadW,h.quadH)}},uc=(n,e,t=null,r=Gf)=>{let o=Mt(n.textLayout,n.raw,n.textStyle.lineHeight??1.16),i=t?Nr(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",Xf(h,n,o,"render"),t&&Ay(h,n,o,t,r),{canvas:u,logicalW:s,logicalH:a}):null};var Ms=n=>{let e=n.type;if(e!=="ScrollText"&&e!=="scrollText")return null;let t=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:t,enabled:n.scrollEnabled===void 0?!0:n.scrollEnabled===!0}},Ny=(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}},zf=n=>{let e=Ms(n.raw);return e?{target:n,viewWidth:n.dims.x,textTotalWidth:n.textTotalWidth,scrollSpeed:e.speed,scrollDirection:e.direction,scrollEnabled:e.enabled}:null},Ly=n=>`rgba(${Math.round(n.color[0]*255)},${Math.round(n.color[1]*255)},${Math.round(n.color[2]*255)},${n.color[3]})`,Yf=(n,e,t)=>{let r=Ms(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}=Ny(r,o,h,t);for(let m of[d,f])u.save(),u.translate(m,0),Iy(u,n),u.restore();return{canvas:c,logicalW:o,logicalH:i}},Iy=(n,e)=>{let t=e.paintFirst==="stroke"?["stroke","fill"]:["fill","stroke"];for(let r of t)_y(n,e,r)},_y=(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?Ly(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,g=f.prefix?.width??0;if(f.prefix){let b=f.charStyles[0];if(t==="fill"){let x=typeof b?.fill=="string"&&b.fill?b.fill:l;x&&Et(n,f,m,p,{fill:x})}else Et(n,f,m,p,{stroke:Fe(i,b)})}if(c){let b=qt(f,m,p,o,u);for(let x=0;x<b.length;x++){let y=f.charStyles[x];if(t==="fill"){let v=typeof y?.fill=="string"&&y.fill?y.fill:l;if(!v)continue;n.fillStyle=v}else{let v=Fe(i,y);if(!v||v.width<=0)continue;d(v)}let S=En(o,y);n.font=Me(S,S.fontSize),Kt(n,b[x],t==="fill"?"fillText":"strokeText")}continue}if(h&&h.length){let b="",x=g,y="",S=null,v,T=E=>{if(!b)return;let M=S;M&&M.width>0&&(n.font=y,d(M),n.strokeText(b,m+x,p)),b="",E<f.boxes.length&&(x=f.boxes[E].left)},C=Ut(s.textAlign),R=s.textAlign===pe.DISPERSE,w=Yr(s.textAlign)&&f.graphemes.some(E=>jr.test(E));for(let E=0;E<f.graphemes.length;E++){let M=f.charStyles[E],P=En(o,M),A=Me(P,P.fontSize),k=Fe(i,M),O=M?.fill??"",F=S;b&&(A!==y||k?.color!==F?.color||k?.width!==F?.width||O!==v)&&T(E),b||(y=A,S=k,v=O),b+=f.graphemes[E],(u||(C||R)&&/[ \t\r]/.test(f.graphemes[E])||w)&&T(E+1)}T(f.graphemes.length);continue}for(let b=0;b<f.graphemes.length;b++){let x=f.charStyles[b];if(t==="fill"){let v=typeof x?.fill=="string"&&x.fill?x.fill:l;if(!v)continue;n.fillStyle=v}else{let v=Fe(i,x);if(!v||v.width<=0)continue;d(v)}let y=En(o,x);n.font=Me(y,y.fontSize);let S=m+f.boxes[b].left;t==="fill"?n.fillText(f.graphemes[b],S,p):n.strokeText(f.graphemes[b],S,p)}}};var Cs=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=rc(this.playback?.duration??0,e),this.player?this.player.retargetDuration(this.totalDuration):this.player=new vo(this.totalDuration),this.player.play(performance.now());for(let t of this.host.document.nodes)t instanceof re?t.play():t instanceof le&&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 re?e.pause():e instanceof le&&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 re?e.stop():e instanceof le&&e.syncClipMediaToTime(0,!1);this.host.requestRenderAll()}seek(e){if(this.cancelPreviews(),!this.player){this.rebuild();let t=[...this.collectMediaDurations(),...this.collectScrollTextDurations()];this.totalDuration=rc(this.playback?.duration??0,t),this.player=new vo(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=Af(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=nc(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=nc(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:gs(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 tc(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 tc(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=Mf(t.raw);r.length&&e.push({target:t,view:this.targetView(t),animates:r})}this.playback=Pf(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===_t)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 ge))continue;let r=zf(t);r&&e.push({node:t,input:r})}return e}collectScrollTextDurations(){return this.scrollTextTracks().map(({input:e})=>e.scrollEnabled?gs(e):0)}applyScrollTextOffsets(e){for(let{node:t,input:r}of this.scrollTextTracks())t.setScrollOffset(Nf(r,e,"loop"))}collectMediaDurations(){let e=[],t=r=>{for(let o of r)o instanceof re?e.push(o.mediaDuration):o instanceof le?o.clipMediaDuration>0&&e.push(o.clipMediaDuration):o instanceof Z&&t(o.children)};return t(this.host.document.nodes),e}syncVideosToTime(e,t){let r=o=>{for(let i of o)i instanceof re?i.syncVideoToTime(e,t):i instanceof le?i.syncClipMediaToTime(e,t):i instanceof Z&&r(i.children)};r(this.host.document.nodes)}};var Uf=14,$f=n=>n.fontFamily||"仓耳小丸子",Rs=class{host;session=null;docBus;disposed=!1;constructor(e){this.host=e,this.docBus=new kt(e.document.events,t=>{let r=[t.on("text:changed",o=>this.onTextChanged(o)),t.on("text:editing:exited",()=>this.finish()),t.on("object:removed",o=>this.onOverlayRemoved(o))];return()=>r.forEach(o=>o())})}retargetDoc(e){this.docBus.retarget(e.events)}dispose(){this.disposed||(this.disposed=!0,this.docBus.dispose())}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=Se(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??Uf,fontWeight:h?.fontWeight,fontStyle:h?.fontStyle,fontFamily:h?.fontFamily||$f(c),textAlign:h?.textAlign??pe.CENTER,lineHeight:1.16,splitByGrapheme:!0,opacity:1,visible:!0},m=new ge(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:Uf,fontWeight:"normal",fontStyle:"normal",fontFamily:$f(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 Dy=530,Vf=[.1,.1,.1,1],Fy=[.18,.44,.96,.3],Ps=class{host;textarea=null;blinkTimer=null;caretVisible=!0;onSelectionChange=null;docBus;inComposition=!1;compositionRange=null;constructor(e){this.host=e,this.docBus=new kt(e.document.events,t=>{let r=[t.on("text:changed",()=>{this.positionAtCaret(),this.host.requestRenderAll()}),t.on("text:editing:entered",()=>this.startUi()),t.on("text:editing:exited",()=>this.stopUi())];return()=>r.forEach(o=>o())})}retargetDoc(e){this.docBus.retarget(e.events)}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:cn(c)),g=m+(f<h?c.boxes[f-u].left:cn(c));if(g>p){let b=e.contentTopY+c.top;l.push({matrix:Y(s,[1,0,0,1,(p+g)/2,b+c.implHeight/2]),dims:{x:g-p,y:c.implHeight},color:Fy})}}}if(o===i&&this.caretVisible&&!this.inComposition){let c=e.cursorCoord(o);if(c){let u=2/this.host.zoom/a;l.push({matrix:Y(s,[1,0,0,1,c.x+u/2,c.y+c.height/2]),dims:{x:u,y:c.height},color:Vf})}}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:cn(h)),p=f+(u-d<h.boxes.length?h.boxes[u-d].left:cn(h)),b=e.contentTopY+h.baseline+e.textStyle.fontSize*.14;l.push({matrix:Y(s,[1,0,0,1,(m+p)/2,b]),dims:{x:Math.max(0,p-m),y:1.5/this.host.zoom/a},color:Vf})}}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()},Dy),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 g=0;g<r.lines.length;g++){let b=r.lines[g].styleMap.flatStart;if(p<=b+r.lines[g].graphemes.length)return g}return r.lines.length-1},h=(p,g)=>{let b=r.lines[p],x=g-b.styleMap.flatStart;return-r.width/2+b.leftOffset+(x<b.boxes.length?b.boxes[x].left:cn(b))},d=(p,g)=>{let b=r.lines[p],x=-r.width/2+b.leftOffset;for(let y=0;y<b.boxes.length;y++)if(g<x+b.boxes[y].left+b.boxes[y].width/2)return b.styleMap.flatStart+y;return b.styleMap.flatStart+b.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),g=e.key==="ArrowUp"?p-1:p+1;if(g<0||g>=r.lines.length)return null;f=d(g,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.docBus.dispose(),this.onSelectionChange&&document.removeEventListener("selectionchange",this.onSelectionChange),this.blinkTimer!==null&&window.clearInterval(this.blinkTimer),this.textarea?.remove(),this.textarea=null}};var jf=(n,e={})=>{let t=n.getContext("webgl2",{alpha:!0,premultipliedAlpha:!0,antialias:!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(),qf=n=>{let e=new Set;for(let t of n){let r=ks(t?.family??"");r&&e.add(r)}return e},Oy=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},Kf=(n,e)=>{let t=[],r=o=>{for(let i of o)if(i instanceof ge){for(let s of Oy(i))if(e.has(s)){t.push(i);break}}else i instanceof Z&&r(i.children)};return r(n),t};var As=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=qf(e);t.size===0||!this.invalidateTextCachesFor(t)||(this.glyphAtlas.reset(),this.host.requestRenderAll(),this.host.render())}invalidateTextCachesFor(e){let t=this.host.documentNodes?this.host.documentNodes():[this.host.document],r=[];for(let o of t)r=r.concat(Kf(o.nodes,e));if(r.length===0)return!1;for(let o of r)o.invalidateTextLayout(),this.textRenderer.invalidateNodeBakes(o);return Xu(),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 Mn=class{_value=0;_lastReason="";get value(){return this._value}get lastReason(){return this._lastReason}bump(e){this._value++,this._lastReason=e}};var pt=1024,By=2,Hy=256,Qt=n=>{let e=[.5,1,2,4];for(let t of e)if(n<=t+1e-6)return t;return e[e.length-1]},Wy=256,Ls=(n,e)=>{let t=Math.max(6,Math.ceil(n*e)),r=Math.max(Wy,Math.ceil(n));return t<=r?{rs:t,scale:e}:{rs:r,scale:r/Math.max(1,n)}},Ns=class{gl;pages=[];cells=new Map;tmpCanvas;disposed=!1;pageCap=12;pendingReset=!1;_generation=0;provisionalCells=new Map;onCellsInvalidated;onProvisionalSettled;detachFontsListener=null;epoch;constructor(e,t,r,o=new Mn){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(",")||$a.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){let t=this.fontSet();if(!(!t||typeof t.load!="function"))try{t.load(e).catch(()=>{})}catch{}}dropProvisionalCells(){if(!(this.disposed||this.provisionalCells.size===0)){for(let e of this.provisionalCells.keys())this.cells.delete(e);this.provisionalCells.clear(),this.onCellsInvalidated?.()}}markFrame(){this.pendingReset&&(this.pendingReset=!1,this.reset()),this.settleProvisionalCells()}settleProvisionalCells(){if(this.disposed||this.provisionalCells.size===0)return;let e=!1,t=new Set;for(let[r,o]of this.provisionalCells){let i=Me(o.style,o.rasterSize);if(!this.isFacePending(i,o.style)){this.cells.delete(r),this.provisionalCells.delete(r),e=!0;let s=ks(o.style.fontFamily??"");s&&t.add(s)}}e&&(this.onCellsInvalidated?.(),t.size>0&&this.onProvisionalSettled?.([...t]))}reset(){let e=this.pages.length>0;if(!this.disposed&&e)for(let t of this.pages)this.gl.deleteTexture(t.texture);this.pages.length=0,this.cells.clear(),this.provisionalCells.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.length,cells:this.cells.size,pageCap:this.pageCap,pendingReset:this.pendingReset,generation:this._generation}}get(e,t,r,o=null){if(this.disposed||r===" "||r===""||r===`
7
+ `||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 s;let a=Me(e,t),l=this.isFacePending(a,e);l&&this.kickFaceLoad(a);let c=this.rasterize(e,t,r,o);return c&&(this.cells.set(i,c),l&&this.provisionalCells.set(i,{style:{fontFamily:e.fontFamily,fontSize:e.fontSize,fontWeight:e.fontWeight,fontStyle:e.fontStyle},rasterSize:t})),c}rasterize(e,t,r,o){let i=this.pages[this.pages.length-1];i||(i=this.newPage());let s=this.pages.length-1,a=i.ctx;a.font=Me(e,t),a.textBaseline="alphabetic",a.textAlign="left",a.fillStyle="#ffffff";let l=a.measureText(r);if(!isFinite(l.width)||l.width<=0&&r.trim()==="")return null;let c=l.actualBoundingBoxLeft??0,u=l.actualBoundingBoxRight??l.width,h=l.actualBoundingBoxAscent??t*.88,d=l.actualBoundingBoxDescent??t*.24,f=t/Math.max(1,e.fontSize),m=o?Math.max(.5,o.width*f):0,p=o?Math.min(m*Math.max(1,o.miterLimit??4)/2,Hy):0,g=By+(o?Math.ceil(p)+1:0),b=Math.max(1,Math.ceil(c+u)+g*2),x=Math.max(1,Math.ceil(h+d)+g*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(),s=this.pages.length-1);let y=i.ctx;y.font=Me(e,t),y.textBaseline="alphabetic",y.textAlign="left",y.fillStyle="#ffffff";let S=i.cursorX,v=i.cursorY,T=S+g+c,C=v+g+h;y.save(),o?(y.lineWidth=m,y.lineJoin=o.lineJoin??"miter",y.lineCap=o.lineCap??"butt",y.miterLimit=Math.max(1,o.miterLimit??4),y.strokeStyle="#ffffff",y.strokeText(r,T,C)):y.fillText(r,T,C),y.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,S,v,b,x,0,0,b,x),this.gl.bindTexture(this.gl.TEXTURE_2D,i.texture),this.gl.texSubImage2D(this.gl.TEXTURE_2D,0,S,v,b,x,this.gl.RGBA,this.gl.UNSIGNED_BYTE,this.tmpCanvas),i.cursorX+=b,i.rowHeight=Math.max(i.rowHeight,x),{pageIndex:s,u0:S/pt,v0:v/pt,u1:(S+b)/pt,v1:(v+x)/pt,wPx:b,hPx:x,inkLeftPx:-c,ascentPx:h,padPx:g,advancePx:l.width}}textureOf(e){return this.pages[e.pageIndex]?.texture??null}newPage(){this.pages.length>=this.pageCap&&(this.pendingReset=!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={canvas:e,ctx:t,texture:r,cursorX:0,cursorY:0,rowHeight:0};return this.pages.push(o),o}dispose(){if(!this.disposed){this.disposed=!0,this.detachFontsListener?.(),this.detachFontsListener=null;for(let e of this.pages)this.gl.deleteTexture(e.texture);this.pages.length=0,this.cells.clear(),this.provisionalCells.clear()}}};var Lr=(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)},Is=class{gl;cache=new Map;disposed=!1;constructor(e){this.gl=e}get(e){if(this.disposed)return null;let t=mu(e),r=this.cache.get(t);if(r)return r;let o=this.gl,i=o.createTexture();if(!i)return null;let s=fu(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 Gy=512*1024*1024,Xy=2048,zy=30,Yy=32*1024*1024,_s=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??Gy,this.maxEntries=t.maxEntries??Xy,this.evictGraceFrames=t.evictGraceFrames??zy,this.epoch=t.epoch??new Mn}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=Uy(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>=Yy))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())}},Uy=(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 Qf=`#version 300 es
8
8
  layout(location = 0) in vec2 aCorner;
9
9
  layout(location = 1) in vec2 aRow0;
10
10
  layout(location = 2) in vec2 aRow1;
@@ -37,7 +37,7 @@ vHalf = aDim * 0.5;
37
37
  vShape = aUv;
38
38
  vDash = aDash;
39
39
  vSeg = aSeg;
40
- }`,jf=`uniform int uPaintMode;
40
+ }`,Zf=`uniform int uPaintMode;
41
41
  uniform mat3 uPaintInv;
42
42
  uniform vec4 uPaintA;
43
43
  uniform vec4 uPaintB;
@@ -69,7 +69,7 @@ float disc = max(b * b - 4.0 * a * c, 0.0);
69
69
  t = abs(a) > 1e-9 ? (-b - sqrt(disc)) / (2.0 * a) : (abs(b) > 1e-9 ? -c / b : 0.0);
70
70
  }
71
71
  return texture(uFillTex, vec2(clamp(t, 0.0, 1.0), 0.5));
72
- }`,qf=`#version 300 es
72
+ }`,Jf=`#version 300 es
73
73
  precision highp float;
74
74
  in vec2 vUv;
75
75
  in vec4 vColor;
@@ -83,7 +83,7 @@ uniform sampler2D uTex;
83
83
  uniform float uPenScale;
84
84
  uniform sampler2D uSegTex;
85
85
  const int MAX_QUAD_SEG = 64;
86
- ${jf}
86
+ ${Zf}
87
87
  out vec4 fragColor;
88
88
  float sdRoundBoxDist(vec2 p, vec2 halfSize, vec2 r) {
89
89
  vec2 q = (abs(p) - (halfSize - r)) / max(r, vec2(1e-6));
@@ -231,7 +231,7 @@ return cov;
231
231
  void main() {
232
232
  fragColor = paintColor(vLocal, texture(uTex, vUv)) * vColor;
233
233
  fragColor.a *= -vRadius.y > 0.5 ? strokeCoverage(vLocal, vRadius, vShape, vDash, vSeg, uPenScale) : roundedCoverage(vLocal, vHalf, vRadius);
234
- }`,Kf=`#version 300 es
234
+ }`,em=`#version 300 es
235
235
  layout(location = 0) in vec2 aPos;
236
236
  layout(location = 1) in vec4 aColor;
237
237
  layout(location = 2) in vec2 aLocal;
@@ -243,21 +243,21 @@ vec3 clip = uView * vec3(aPos, 1.0);
243
243
  gl_Position = vec4(clip.xy, 0.0, 1.0);
244
244
  vColor = aColor;
245
245
  vLocal = aLocal;
246
- }`,Qf=`#version 300 es
246
+ }`,tm=`#version 300 es
247
247
  precision mediump float;
248
248
  in vec4 vColor;
249
249
  in vec2 vLocal;
250
- ${jf}
250
+ ${Zf}
251
251
  out vec4 fragColor;
252
252
  void main() {
253
253
  fragColor = paintColor(vLocal, vColor);
254
- }`,_s=(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 Lr=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},Ds=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 $e=24,Zf=new Float32Array(9),Dy=4096,Fy=new Float32Array([0,0,1,0,1,1,0,1]),Oy=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(Dy*$e);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=_s(e,Vf,qf),!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,Fy,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,Oy,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=$e*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*$e+$e>this.instanceData.length&&this.grow();let h=this.instanceCount*$e,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:$e,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+$e)})),u&&this.segmentTable?.writeRow(d,l??null,u);let g=l?this.gpuRecords.get(l):void 0,b=m||!g||g.startFloat!==h||g.floatCount!==$e;if(this.pendingSegments.push({owner:l??null,startFloat:h,floatCount:$e,dirty:b}),b){let x=this.pendingUploads[this.pendingUploads.length-1];x&&x[1]===h?x[1]=h+$e:this.pendingUploads.push([h,h+$e])}if(this.instanceCount+=1,l){let x=this.frameSlots??=new Map,y=x.get(l);y&&y.start+y.count===this.instanceCount-1?y.count+=1:x.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),Nr(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=$e*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),Zf.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,Zf),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),Nr(t,o,e.gradient,1),t.bindBuffer(t.ARRAY_BUFFER,this.instanceBuffer);let i=$e*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*$e]],e.bindBuffer(e.ARRAY_BUFFER,this.instanceBuffer),e.bufferData(e.ARRAY_BUFFER,this.instanceData.byteLength,e.DYNAMIC_DRAW),this.segmentTable?.ensureRows(this.instanceData.length/$e)}canPushSegments(){return this.valid?(this.segmentTable||(this.segmentTable=new Ds(this.gl)),this.segmentTable.ensureRows(this.instanceData.length/$e)):!1}get drawnInstances(){return this.instanceCount}get instanceTotal(){return this.instanceCount}dispose(){this.disposed||(this.disposed=!0,this.release())}};var Fs=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})}hasRecordedCommands(){return this.deferred.length>0}hasNovelPaintReferences(e){if(this.quad.pushedTextures.size){let t=new Set;for(let r of e.commands)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)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)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)t.batch instanceof Zt,t.batch.drawDeferred(t.cmd)}};var Jf=new Float32Array(9),Rt=8,By=8192,Os=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(By*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=_s(e,Kf,Qf),!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,g=this.vertexData,b=c;for(let x=0;x<o.length;x++){let y=o[x]*2,S=r[y],v=r[y+1];g[b]=p[0]*S+p[2]*v+p[4],g[b+1]=p[1]*S+p[3]*v+p[5],g[b+2]=t[0],g[b+3]=t[1],g[b+4]=t[2],g[b+5]=t[3],g[b+6]=S,g[b+7]=v,b+=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,g=a*3,b=p.get(s);b&&b.start+b.count===this.vertexCount-g?b.count+=g:p.set(s,{start:this.vertexCount-g,count:g})}}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),Nr(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),Jf.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,Jf),Nr(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 Wt=Sl,Wy=[Wt[0],Wt[1],Wt[2],.14],hc=[1,1,1,1],Gy=2,nm=[238/255,238/255,238/255,128/255],rm=[24/255,144/255,1,128/255],Mo=20,Mn=20,Bs=null,Xy=()=>{if(Bs)return Bs;let n=e=>{let t=document.createElement("canvas");t.width=Mo,t.height=Mo;let r=t.getContext("2d");if(!r)return t;let o=Mo/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 Bs={normal:n(!1),hover:n(!0)},Bs},zy=n=>n.columnWidths.reduce((e,t)=>e+t,0)+(n.cols-1)*n.cellSpacing,Yy=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},Hs=null,Uy=()=>{if(Hs)return Hs;let n=e=>{let t=document.createElement("canvas");t.width=Mn*2,t.height=Mn*2;let r=t.getContext("2d");if(!r)return t;r.scale(2,2),r.fillStyle=e?"#1890ff20":"#eeeeee99",r.fillRect(0,0,Mn-1,Mn-1);let o=Mn/2-.5,i=Mn/2-.5,s=Mn*.25,a=Mn*.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 Hs={normal:n(!1),hover:n(!0)},Hs},im=(n,e)=>{let t=[],r=n.tableView,o=n.cellMap,i=n.matrix,s=n.objectScale,a=zy(r)/2,l=Yy(r)/2,c=Ct/e/Math.max(s.x,1e-6),u=Ct/e/Math.max(s.y,1e-6);for(let b of n.selectedCells){let x=o.get(`${b.row},${b.col}`);if(x?.isMerged)continue;let y=x?.rowspan??1,S=x?.colspan??1,v=ro(r,{r1:b.row,r2:b.row+y-1,c1:b.col,c2:b.col+S-1}),M=v.left+v.width/2,C=v.top+v.height/2;t.push({matrix:Y(i,[1,0,0,1,M,C]),dims:{x:v.width,y:v.height},color:Wy}),t.push({matrix:Y(i,[1,0,0,1,M,v.top]),dims:{x:v.width+2*c,y:u},color:Wt}),t.push({matrix:Y(i,[1,0,0,1,M,v.top+v.height]),dims:{x:v.width+2*c,y:u},color:Wt}),t.push({matrix:Y(i,[1,0,0,1,v.left,C]),dims:{x:c,y:v.height+2*u},color:Wt}),t.push({matrix:Y(i,[1,0,0,1,v.left+v.width,C]),dims:{x:c,y:v.height+2*u},color:Wt})}if(n.hoveredBorder){let{type:b,position:x}=n.hoveredBorder,y=b==="col"?V(i,x,-l):V(i,-a,x),S=b==="col"?V(i,x,l):V(i,a,x);t.push(Ce(y,S,Gy/e,Wt))}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=xr(o,n.selectedCells);for(let b=0;b<r.rows;b++){let x=om(r.rowHeights,r.cellSpacing,b)-l,y=r.rowHeights[b],S=n.hoveredStrip?.kind==="row"&&n.hoveredStrip.index===b?!0:p.rows.has(b);t.push({matrix:Y(i,[1,0,0,1,h-f/2,x+y/2]),dims:{x:f,y},color:S?rm:nm})}for(let b=0;b<r.cols;b++){let x=om(r.columnWidths,r.cellSpacing,b)-a,y=r.columnWidths[b],S=n.hoveredStrip?.kind==="col"&&n.hoveredStrip.index===b?!0:p.cols.has(b);t.push({matrix:Y(i,[1,0,0,1,x+y/2,d-m/2]),dims:{x:y,y:m},color:S?rm:nm})}{let b=Uy();t.push({matrix:Y(i,[1,0,0,1,h-f/2,d-m/2]),dims:{x:f,y:m},color:hc,texture:n.hoveredDragHandle?b.hover:b.normal})}let g=n.hoveredIndicator??(n.borderDragging?null:n.hoveredBorder);if(g){let b=Xy(),x=g.type==="col";t.push({matrix:Y(i,[1,0,0,1,x?g.position:-a-15,x?-l-15:g.position]),dims:{x:Mo/(e*Math.max(s.x,1e-6)),y:Mo/(e*Math.max(s.y,1e-6))},color:hc,texture:n.hoveredIndicator?b.hover:b.normal})}if(n.selectedCells.length&&!n.editingCell&&!n.isFullCellSelection){let b=n.selectionBoundsRect;if(b){let x=b.left+b.width,y=b.top+b.height,S=bn/e/Math.max(s.x,1e-6),v=bn/e/Math.max(s.y,1e-6),M=(bn-2*Ct)/e/Math.max(s.x,1e-6),C=(bn-2*Ct)/e/Math.max(s.y,1e-6);t.push({matrix:Y(i,[1,0,0,1,x,y]),dims:{x:S,y:v},color:Wt}),t.push({matrix:Y(i,[1,0,0,1,x,y]),dims:{x:M,y:C},color:n.hoveredRangeHandle?Wt:hc})}}return t};var $y=(n,e,t,r)=>{let o=n.nodes.filter(h=>Ke(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=ae(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],g=Math.max(Number(d.strokeWidth)||1,1.2/i),b=h.bounds;if(h.dims.y===0){let x=(b.top+b.bottom)/2;u.push({matrix:[1,0,0,1,s+l/2,x],dims:{x:l,y:g},color:p})}else if(h.dims.x===0){let x=(b.left+b.right)/2;u.push({matrix:[1,0,0,1,x,a+c/2],dims:{x:g,y:c},color:p})}}return u},sm=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 se?e.selection[0]:null,u=l?[...n.cellEditOverlayOnly?[]:pn(l.aCoords,t),...o.quads]:r?Ih(r,t):c?.editingMask?_h(c,t,a):Lh(e,t,a,n.mobileControls===!0),h=l&&e.selection.length===1?e.selection[0]:null;l&&h instanceof ee&&h.containsDeep(l)&&(u=[...u,...Oi(h.aCoords,t)]),!l&&!r&&e.selection.length===1&&e.selection[0]instanceof te&&(u=[...u,...im(e.selection[0],t)]);let d=e.seamHover;if(c&&d&&d.puzzle===c&&(u=[...u,...Fh(Dh(d.puzzle,d.mask,d.handle),t)]),e.hovered&&!r&&!Ke(e.hovered)&&(u=[...u,...Bi(e.hovered,t)]),u=[...u,...i],s){u=[...u,...$y(e,s.vpt,s.cssWidth,s.cssHeight)];let f=e.nodes.find(p=>p.raw.id===_t),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,...qh({vpt:s.vpt,cssWidth:s.cssWidth,cssHeight:s.cssHeight,workspaceRect:m,referenceLine:s.referenceLine??null,selectionRects:e.selection.filter(p=>!Ke(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 Ws(n,e,t,r,o){for(let i=0;i<o;i++){let s=t[i];if(!Ke(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 dc(n){let e=n.doc.editingNode;if(n.cropSessionController.active){Co(n,n.cropSessionController.buildOverlay(n.zoom))&&n.requestRenderAll();return}if(n.expandSessionController.active){Co(n,n.expandSessionController.buildOverlay(n.zoom))&&n.requestRenderAll();return}if(n.pathSessionController.active){Co(n,n.pathSessionController.buildOverlay(n.zoom))&&n.requestRenderAll();return}if(n.warpSessionController.active){Co(n,n.warpSessionController.buildOverlay())&&n.requestRenderAll();return}let t=sm({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.viewportTransform,cssWidth:n.cssWidth,cssHeight:n.cssHeight,referenceLine:n.referenceLineDrag}:null});Co(n,t),n.renderer.frame.animationActive&&n.requestRenderAll()}function Co(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 Vy=n=>typeof n!="string"||!n||/^cmyk\(/i.test(n)?null:n,Ir=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 Vy(n)},fc=n=>n?.offsetEnable?{x:Number(n.offsetX)||0,y:Number(n.offsetY)||0}:{x:0,y:0},Jt=(n,e={})=>{if(!n||typeof n!="object"||Array.isArray(n))return null;let t=n,r=a=>{if(!a||typeof a!="object")return!1;let l=a;return l.enabled!==!1&&l.showInDialog!==!1},o=[];if(Array.isArray(t.dropShadow))for(let a of t.dropShadow){if(!r(a))continue;let l=Ir(a?.fill)??Ir(a?.color)??"rgba(0,0,0,0.5)",c=Number(a?.blur)||0,u=Number(a?.offsetX)||0,h=Number(a?.offsetY)||0;!c&&!u&&!h||o.push({color:l,rgba:ae(l),blur:c,offsetX:u,offsetY:h})}let i=[];if(Array.isArray(t.solidFill))for(let a of t.solidFill){if(!r(a))continue;let l=Number(a?.fillType)||0;if(l===1){if(!a?.fill||typeof a.fill!="object")continue;let u=ur(a.fill);if(!u)continue;i.push({kind:"gradient",decl:u,offset:fc(a)});continue}if(l!==0)continue;let c=Ir(a?.fill)??Ir(a?.color);c&&i.push({kind:"solid",color:c,rgba:ae(c),offset:fc(a)})}let s=[];if(Array.isArray(t.stroke))for(let a of t.stroke){if(!r(a))continue;let l=a?.size&&typeof a.size=="object"?Number(a.size.value):0,c=e.text?l:Number(a?.strokeWidth)||l||0;if(!c)continue;let u=Ir(a?.fill)??Ir(a?.color)??"#666666",h=a?.position||a?.strokeAlignment||(e.text?"center":"outside");s.push({color:u,rgba:ae(u),width:c,alignment:h,offset:fc(a)})}return o.length===0&&i.length===0&&s.length===0?null:{dropShadows:o,solidFills:i,strokes:s}},Cn=n=>{let e=a=>String(Math.round(a*1e4)/1e4),t=a=>a.map(e).join(","),r=n.dropShadows.map(a=>`${t(a.rgba)}:${e(a.blur)}:${e(a.offsetX)}:${e(a.offsetY)}`).join(";"),o=a=>{let l=`@${e(a.offset.x)},${e(a.offset.y)}`;if(a.kind==="solid")return t(a.rgba)+l;let c=a.decl,u=c.stops.map(d=>`${e(d.offset)}@${d.color.map(e).join(",")}`).join(","),h=c.gradientTransform?c.gradientTransform.map(e).join(","):"-";return`g${c.kind[0]}:${e(c.x1)},${e(c.y1)},${e(c.x2)},${e(c.y2)},${e(c.r1)},${e(c.r2)},${c.gradientUnits},${h};${u}${l}`},i=n.solidFills.map(o).join(";"),s=n.strokes.map(a=>`${t(a.rgba)}:${e(a.width)}:${a.alignment}@${e(a.offset.x)},${e(a.offset.y)}`).join(";");return`psd|${r}|${i}|${s}`};var jy=512,qy=new Set([L.QRCODE,L.BARCODE,L.ECHART,L.FABRIC_ECHART]),lm=n=>{let e=Jt(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:Cn(e)}},Ky=n=>n?`${n.sx},${n.sy},${n.sw},${n.sh}`:"none",mc=new WeakMap,am=n=>Math.max(1,Math.min(jy,Math.floor(n))),Qy=(n,e,t,r,o)=>{let i=lm(n);if(!i)return;let s=n.imageEl;if(!s)return;let a=n.dims,l=null;if(i.shadows.length){let h=ws(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 wn(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),g=Math.round(u[1]*f+u[3]*m+l.h/2);if(p>=0&&g>=0&&p<l.w&&g<l.h&&l.data[(g*l.w+p)*4+3]>o){e[h*t+d]=1;continue}}for(let p of c){let g=Math.round(f-p.dx+p.w/2),b=Math.round(m-p.dy+p.h/2);if(g>=0&&b>=0&&g<p.w&&b<p.h&&p.data[(b*p.w+g)*4+3]>o){e[h*t+d]=1;break}}}},Zy=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=am(t.x),a=am(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,bi/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);Qy(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}},Jy=n=>{let e=`${n.dims.x},${n.dims.y}|${Ky(n.cropRect)}|${n.renderOpacity}`,t=lm(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])}`},e0=n=>{let e=Jy(n),t=mc.get(n);if(t&&t.stamp===e&&t.element===n.imageEl)return t.rec;let r=Zy(n);return mc.set(n,{element:n.imageEl,stamp:e,rec:r}),r},t0=(n,e,t)=>{let r=e0(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},n0=(n,e,t,r)=>{for(let o of n.children)if(!(!o.visible||!o.containsPoint(e,t,r.strokeBandOf?.(o)??0))&&!pc(o,e,t,r))return!0;return!1},pc=(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 se||n instanceof le||n instanceof re||n.isTextType||n.isLineType?!1:n instanceof ee?!n0(n,e,t,r):!n.isImageType||qy.has(n.typeKey)||typeof n.raw.name=="string"&&n.raw.name.toLowerCase()==="qrcode"||!ft.has(n.typeKey)?!1:t0(n,e,t)},r0=n=>{mc.delete(n)};import o0 from"rbush";var bc=0,i0=()=>(bc=(bc+1)%4294967295,`tx-${Date.now().toString(36)}-${bc.toString(36)}`),rr=class{events=new Fn;_nodes=[];_index=new o0;_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 ee&&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 ee?this._selection[0]:null);this._groupEditingGroup=r&&!(r instanceof te)&&!(r instanceof se)?r:null}_hovered=null;get hovered(){return this._hovered}setHovered(e){let r=e!==null&&this._nodes.some(o=>o===e||o instanceof ee&&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}=ul(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 ee)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 ee&&!(s instanceof te)){let a=t(s.children,s);if(a)return a}}return null};return t(this._nodes,null)}setProps(e,t,r={}){e.set(t),"visible"in t&&this.bumpStructure(),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 cl/this._hitZoom}strokeHitBand(e){return bh(e)?Math.max(Number(e.raw.padding)||0,cl)/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))&&!pc(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&&!Dt.has(String(a.raw.id??""))&&!Ke(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"))}applyTransform(e,t,r,o){if(e.length){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??i0();this.events.fire("object:modified",e,{...t,transactionId:r})}enterEditing(e,t={}){let r=this._nodes.find(i=>i===e||i instanceof ee&&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=cm(r,e),this.editSelection.end=cm(r,t)}toObjects(){return this._nodes.filter(e=>!e.syntheticOwner).map(e=>e.toObject())}},cm=(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};function um(n,e,t,r,o){let i=V(e,n.left,n.top),s=V(e,n.left+n.width,n.top+n.height),a=Math.floor(Math.min(i.x,s.x)*o),l=Math.ceil(Math.max(i.x,s.x)*o),c=Math.min(i.y,s.y),u=Math.max(i.y,s.y),h=Math.floor((r-u)*o),d=Math.ceil((r-c)*o),f=Math.max(0,a),m=Math.max(0,h),p=Math.min(Math.ceil(t*o),l),g=Math.min(Math.ceil(r*o),d);return{x:f,y:m,w:Math.max(0,p-f),h:Math.max(0,g-m)}}function hm(n,e){n.enable(n.SCISSOR_TEST),n.scissor(e.x,e.y,e.w,e.h)}function dm(n){n.disable(n.SCISSOR_TEST)}function Rn(n){let e=n.isEnabled(n.SCISSOR_TEST);e&&n.disable(n.SCISSOR_TEST);let t=!1;return()=>{t||(t=!0,e&&n.enable(n.SCISSOR_TEST))}}var fm=56;function Xs(n){let e=n.nodes.find(t=>String(t.raw.id??"")===_t);return!e||!e.visible||!(e.bounds.width>0)||!(e.bounds.height>0)?null:e}var Gs=class{entries=[{doc:new rr,origin:{x:0,y:0},workspaceNode:null,pendingRaw:null,placeholderRect:null}];viewportZoom=1;activeIndexValue=0;get pageCount(){return this.entries.length}get activeIndex(){return this.activeIndexValue}get activeDoc(){return this.entries[this.activeIndexValue].doc}pageAt(e){return this.entries[e]??null}setActiveIndex(e){return e<0||e>=this.entries.length||e===this.activeIndexValue?!1:(this.activeIndexValue=e,!0)}insert(e){let t=Math.max(0,Math.min(this.entries.length,e));return this.entries.splice(t,0,{doc:new rr,origin:{x:0,y:0},workspaceNode:null,pendingRaw:null,placeholderRect:null}),this.activeIndexValue>=t&&this.activeIndexValue++,this.refreshAll(),t}rebuildAroundActive(e,t){if(e<1)return;let r=Math.max(0,Math.min(t,e-1)),o=[];for(let i=0;i<e;i++)o.push(i===r?{doc:this.activeDoc,origin:{x:0,y:0},workspaceNode:null,pendingRaw:null,placeholderRect:null}:{doc:new rr,origin:{x:0,y:0},workspaceNode:null,pendingRaw:null,placeholderRect:null});this.entries=o,this.activeIndexValue=r,this.refreshAll()}remove(e){return this.entries.length<=1||e<0||e>=this.entries.length?!1:(this.entries.splice(e,1),this.activeIndexValue>=this.entries.length&&(this.activeIndexValue=this.entries.length-1),this.refreshAll(),!0)}refresh(e){let t=this.entries[e];t&&(t.workspaceNode=Xs(t.doc))}isBuilt(e){return this.entries[e]?.pendingRaw==null}setPageRaw(e,t){let r=this.entries[e];return r?(r.pendingRaw=t,r.placeholderRect=s0(t),r.doc.nodes.length>0&&r.doc.loadObjects([]),r.workspaceNode=null,!0):!1}markBuilt(e){let t=this.entries[e];t&&(t.pendingRaw=null,t.placeholderRect=null,this.refresh(e))}documentBounds(){let e=1/0,t=1/0,r=-1/0,o=-1/0;for(let i of this.layout()){let s=i.rect.left+i.entry.origin.x,a=i.rect.top+i.entry.origin.y;e=Math.min(e,s),t=Math.min(t,a),r=Math.max(r,s+i.rect.width),o=Math.max(o,a+i.rect.height)}return e===1/0?null:{left:e,top:t,width:r-e,height:o-t}}refreshAll(){for(let e=0;e<this.entries.length;e++)this.refresh(e)}layout(){let e=[],t=0;for(let o=0;o<this.entries.length;o++){let i=this.entries[o],s=i.workspaceNode?{...i.workspaceNode.bounds}:i.pendingRaw?i.placeholderRect:a0(i.doc);s&&(t=Math.max(t,s.width),e.push({index:o,entry:i,rect:s}))}let r=0;for(let{entry:o,rect:i}of e)o.origin.x=(t-i.width)/2-i.left||0,o.origin.y=r-i.top||0,r+=i.height+fm/(this.viewportZoom||1);return e}pageRectAt(e){let t=this.layout().find(r=>r.index===e);return t?{left:t.rect.left+t.entry.origin.x,top:t.rect.top+t.entry.origin.y,width:t.rect.width,height:t.rect.height}:null}route(e,t){for(let r of this.layout()){let o=r.rect.left+r.entry.origin.x,i=r.rect.top+r.entry.origin.y;if(e>=o&&e<=o+r.rect.width&&t>=i&&t<=i+r.rect.height)return{index:r.index,doc:r.entry.doc,local:{x:e-r.entry.origin.x,y:t-r.entry.origin.y}}}return null}visibleEntries(e,t=0){let r=[];for(let o of this.layout()){let i={left:o.rect.left+o.entry.origin.x,top:o.rect.top+o.entry.origin.y,width:o.rect.width,height:o.rect.height};i.left-t<=e.r&&i.left+i.width+t>=e.l&&i.top-t<=e.b&&i.top+i.height+t>=e.t&&r.push({index:o.index,entry:o.entry,rect:i})}return r}originAt(e){this.layout();let t=this.entries[e]?.origin;return t?{x:t.x,y:t.y}:{x:0,y:0}}indexOfDoc(e){return this.entries.findIndex(t=>t.doc===e)}allDocs(){return this.entries.map(e=>e.doc)}pageVpt(e,t){this.layout();let r=this.entries[t];return r?Y(e,[1,0,0,1,r.origin.x,r.origin.y]):[...e]}zoomViewportAt(e,t,r,o){let i=(t-e[4])/e[0],s=(r-e[5])/e[3],a=this.route(i,s)?.index??this.activeIndex,l=this.pageRectAt(a),c=l?l.left+l.width/2:i,u=l?l.top+l.height/2:s,h=V(e,c,u);this.viewportZoom=o;let d=this.pageRectAt(a);return[o,0,0,o,h.x-o*(d?d.left+d.width/2:c),h.y-o*(d?d.top+d.height/2:u)]}drainAll(){for(let e of this.entries)e.doc.drainRenderDirty()}};function s0(n){for(let i of n){if(String(i.id??"")!==_t)continue;let s=Number(i.left??0),a=Number(i.top??0),l=Number(i.width??0),c=Number(i.height??0);return Number.isFinite(s)&&Number.isFinite(a)&&l>0&&c>0?{left:s,top:a,width:l,height:c}:null}let e=1/0,t=1/0,r=-1/0,o=-1/0;for(let i of n){let s=String(i.id??"");if(s!==_t&&Dt.has(s)||J(i)===L.REFERENCELINE)continue;let a=Number(i.left??0),l=Number(i.top??0),c=Number(i.width??0),u=Number(i.height??0);!Number.isFinite(a)||!Number.isFinite(l)||!(c>0)||!(u>0)||(e=Math.min(e,a),t=Math.min(t,l),r=Math.max(r,a+c),o=Math.max(o,l+u))}return e===1/0?{left:0,top:0,width:750,height:500}:{left:e,top:t,width:r-e,height:o-t}}function mm(n,e,t,r){if(!t||!(t.width>0)||!(t.height>0))return r;let o=t.left+t.width/2,i=t.top+t.height/2,s=V(n,o,i);return[e,0,0,e,s.x-e*o,s.y-e*i]}function a0(n){let e=1/0,t=1/0,r=-1/0,o=-1/0;for(let i of n.nodes){let s=i.bounds;!Number.isFinite(s.left)||!Number.isFinite(s.top)||(e=Math.min(e,s.left),t=Math.min(t,s.top),r=Math.max(r,s.left+s.width),o=Math.max(o,s.top+s.height))}return e===1/0?null:{left:e,top:t,width:r-e,height:o-t}}function pm(n,e){n.layout();let t=Te(e.vpt),r=V(t,0,0),o=V(t,e.cssWidth,e.cssHeight),i={l:Math.min(r.x,o.x),t:Math.min(r.y,o.y),r:Math.max(r.x,o.x),b:Math.max(r.y,o.y)},s=16/e.zoom,a=n.visibleEntries(i,s);for(let m of a)n.isBuilt(m.index)||e.onPageVisible(m.index);let l=a.map(m=>m.rect),c=Nt(e.vpt,e.cssWidth,e.cssHeight,e.dpr),u={vpt:e.vpt,cssWidth:e.cssWidth,cssHeight:e.cssHeight,dpr:e.dpr};e.workspaceBackdrop.drawChecker(e.gl,c,u,l);let h=e.zoom*e.dpr,d=e.expandUnderlay();try{for(let m of a){e.batchOrder.flushAll(),hm(e.gl,um(m.rect,e.vpt,e.cssWidth,e.cssHeight,e.dpr));let p=n.pageVpt(e.vpt,m.index),g=Nt(p,e.cssWidth,e.cssHeight,e.dpr);e.batch.begin(g,h),e.meshBatch.begin(g),e.batch.deferDraws=!0,e.meshBatch.deferDraws=!0,e.batchOrder.reset(),e.withPageViewport(p,()=>Ws(e.batch,e.renderer,m.entry.doc.nodes,d,m.entry.doc.nodes.length))}e.batchOrder.flushAll()}finally{dm(e.gl)}n.drainAll(),e.workspaceBackdrop.drawBackdrop(e.gl,c,u,l);let f=Nt(n.pageVpt(e.vpt,n.activeIndex),e.cssWidth,e.cssHeight,e.dpr);e.batch.begin(f,h),e.meshBatch.begin(f),e.batch.deferDraws=!0,e.meshBatch.deferDraws=!0,e.batchOrder.reset(),e.finishOverlay();for(let m of a){if(m.index===n.activeIndex)continue;let p=m.entry.doc.hovered;if(!p)continue;let g=Bi(p,e.zoom);if(!g.length)continue;let b=Nt(n.pageVpt(e.vpt,m.index),e.cssWidth,e.cssHeight,e.dpr);e.batch.begin(b,h),e.meshBatch.begin(b),e.batch.deferDraws=!0,e.meshBatch.deferDraws=!0,e.batchOrder.reset();for(let x of g)e.batch.pushQuad(x.matrix,x.dims.x,x.dims.y,x.color,x.texture?e.textures.get(x.texture):null);e.batch.flush(),e.batch.deferDraws=!1,e.meshBatch.deferDraws=!1,e.batchOrder.executeDeferred()}}var zs=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 Ys=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,!Ia())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)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.batchOrder.replaySnapshot(r),this.gateOk(),!0)}captureSnapshot(){let{host:e}=this;if(!Ia()){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&&Bn()){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,Bn()&&console.info("[retained] 门链回退:",e)),!1}gateOk(){this.lastGateReason!==null&&(this.lastGateReason=null,Bn()&&console.info("[retained] 保留式帧恢复生效"))}logDebug(e){Bn()&&console.info("[retained]",e)}};var Ro=new WeakMap;function or(n){return Ro.get(n)??n.viewportTransform}function bm(n,e,t){let r=Ro.get(n);Ro.set(n,e);try{t()}finally{r?Ro.set(n,r):Ro.delete(n)}}var gm=(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]},Pn=(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},Us=(n,e,t)=>{let r=gm(n.uOrder,e),o=gm(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}},ir=(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)},bt=(n,e,t)=>{n.xs.push(0,e/3,2*e/3,e),n.ys.push(t,t,t,t)},gc=(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},l0=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},xm=(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?Pn(0,0,t,r,4,2):(bt(a,t,0),ir(a,0,t,r,i,o<0),n==="arcUpper"?gc(a,r):a);if(n==="fish")return bt(a,t,0),bt(a,t,r),a.ys[1]-=s,a.ys[2]+=s,a.ys[5]+=s,a.ys[6]-=s,a;if(n==="fisheye"){a=Pn(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=Pn(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=Pn(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 Pn(0,0,t,r,4,4);let l=Math.sin(i),c=Math.cos(i);if(a={uOrder:4,vOrder:4,xs:[],ys:[]},bt(a,t,0),bt(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),ir(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),ir(a,0,t,r,i,!0)}return n==="shellUpper"?gc(a,r):a}if(n==="arc"){if(Math.abs(o)<1e-9)return Pn(0,0,t,r,4,2);let l=Math.sin(i);return ir(a,-r*l,t+r*l,r*(1-Math.cos(i)),i,!0),ir(a,0,t,r,i,!0),o<0?gc(a,r):a}if(n==="arch"||n==="bulge"){if(Math.abs(o)<1e-9)return Pn(0,0,t,r,4,2);let l=o>0;return ir(a,0,t,0,i,l),ir(a,0,t,r,i,n==="bulge"?!l:l),a}if(n==="flag")return bt(a,t,0),bt(a,t,r),a.ys[1]-=s,a.ys[2]+=s,a.ys[5]-=s,a.ys[6]+=s,a;if(n==="wave")return bt(a,t,0),bt(a,t,r/2),bt(a,t,r),a.ys[5]+=s,a.ys[6]-=s,a;if(n==="rise")return bt(a,t,0),bt(a,t,r),a.ys[0]+=s,a.ys[1]+=s,a.ys[4]+=s,a.ys[5]+=s,a},xc=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",ym=(n,e,t,r,o)=>{if(!xc(n)||r<=0||o<=0)return;if(!t||n==="twist")return xm(n,e,r,o);let i=xm(n,e,o,r);return i?l0(i):void 0},vm=(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}}},yc=(n,e,t)=>{let r=ym(n.style,n.bend,n.rotate==="vertical",e,t);if(r)return vm(r,n.horizontal,n.vertical),r},Po=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(!xc(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"}},vc=(n,e,t,r,o,i,s,a,l,c,u,h,d,f)=>{let m=r-e,p=o-t,g=a-i,b=l-s;if(m<=0||p<=0||g<=0||b<=0||c<=0||u<=0||d<=0||n.xs.length===0)return;let x=(i-e)/m,y=(a-e)/m,S=(s-t)/p,v=(l-t)/p,M=(W,X)=>{let _=Us(n,W,X);return{x:h[0]*_.x+h[2]*_.y+h[4],y:h[1]*_.x+h[3]*_.y+h[5]}},C=0,R=0,w=0,T=0,E=!0,P=8;for(let W=0;W<=P;W++){let X=S+(v-S)*W/P;for(let _=0;_<=P;_++){let D=x+(y-x)*_/P,I=M(D,X);E?(C=R=I.x,w=T=I.y,E=!1):(C=Math.min(C,I.x),R=Math.max(R,I.x),w=Math.min(w,I.y),T=Math.max(T,I.y))}}let A=Math.max(8,f),k=Math.min(A,Math.max(8,Math.ceil((R-C)/d))),O=Math.min(A,Math.max(8,Math.ceil((T-w)/d))),F={columns:k+1,rows:O+1,docXs:[],docYs:[],sourceXs:[],sourceYs:[]};for(let W=0;W<F.rows;W++){let X=W/O;for(let _=0;_<F.columns;_++){let D=_/k,I=M(x+(y-x)*D,S+(v-S)*X);F.docXs.push(I.x),F.docYs.push(I.y),F.sourceXs.push(D*c),F.sourceYs.push(X*u)}}return F},Sc=(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,g=n-t,b=e-r,x=u*p-h*m,y=u*f-h*d-(g*p-b*m),S=-(g*f-b*d),v;if(Math.abs(x)<1e-9){if(Math.abs(y)<1e-9)return;v=-S/y}else{let w=y*y-4*x*S;if(w<0)return;let T=Math.sqrt(w),E=(-y+T)/(2*x),P=(-y-T)/(2*x),A=E>=-1e-9&&E<=1+1e-9,k=P>=-1e-9&&P<=1+1e-9;if(A&&k)v=Math.min(Math.max(E,0),1);else if(A)v=E;else if(k)v=P;else return}let M=d+m*v,C=f+p*v,R;if(Math.abs(M)>=Math.abs(C)){if(Math.abs(M)<1e-9)return;R=(g-u*v)/M}else{if(Math.abs(C)<1e-9)return;R=(b-h*v)/C}if(!(v<-1e-9||v>1.000000001||R<-1e-9||R>1.000000001))return{s:Math.min(Math.max(v,0),1),t:Math.min(Math.max(R,0),1)}};var c0=`#version 300 es
254
+ }`,Ds=(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 Ir=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},Fs=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 $e=24,nm=new Float32Array(9),$y=4096,Vy=new Float32Array([0,0,1,0,1,1,0,1]),jy=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($y*$e);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=Ds(e,Qf,Jf),!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,Vy,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,jy,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=$e*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*$e+$e>this.instanceData.length&&this.grow();let h=this.instanceCount*$e,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:$e,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+$e)})),u&&this.segmentTable?.writeRow(d,l??null,u);let g=l?this.gpuRecords.get(l):void 0,b=m||!g||g.startFloat!==h||g.floatCount!==$e;if(this.pendingSegments.push({owner:l??null,startFloat:h,floatCount:$e,dirty:b}),b){let x=this.pendingUploads[this.pendingUploads.length-1];x&&x[1]===h?x[1]=h+$e:this.pendingUploads.push([h,h+$e])}if(this.instanceCount+=1,l){let x=this.frameSlots??=new Map,y=x.get(l);y&&y.start+y.count===this.instanceCount-1?y.count+=1:x.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),Lr(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=$e*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),Lr(t,o,e.gradient,1),t.bindBuffer(t.ARRAY_BUFFER,this.instanceBuffer);let i=$e*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*$e]],e.bindBuffer(e.ARRAY_BUFFER,this.instanceBuffer),e.bufferData(e.ARRAY_BUFFER,this.instanceData.byteLength,e.DYNAMIC_DRAW),this.segmentTable?.ensureRows(this.instanceData.length/$e)}canPushSegments(){return this.valid?(this.segmentTable||(this.segmentTable=new Fs(this.gl)),this.segmentTable.ensureRows(this.instanceData.length/$e)):!1}get drawnInstances(){return this.instanceCount}get instanceTotal(){return this.instanceCount}dispose(){this.disposed||(this.disposed=!0,this.release())}};var Os=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})}hasRecordedCommands(){return this.deferred.length>0}hasNovelPaintReferences(e){if(this.quad.pushedTextures.size){let t=new Set;for(let r of e.commands)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)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)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)t.batch instanceof Zt,t.batch.drawDeferred(t.cmd)}};var rm=new Float32Array(9),Rt=8,qy=8192,Bs=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(qy*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=Ds(e,em,tm),!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,g=this.vertexData,b=c;for(let x=0;x<o.length;x++){let y=o[x]*2,S=r[y],v=r[y+1];g[b]=p[0]*S+p[2]*v+p[4],g[b+1]=p[1]*S+p[3]*v+p[5],g[b+2]=t[0],g[b+3]=t[1],g[b+4]=t[2],g[b+5]=t[3],g[b+6]=S,g[b+7]=v,b+=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,g=a*3,b=p.get(s);b&&b.start+b.count===this.vertexCount-g?b.count+=g:p.set(s,{start:this.vertexCount-g,count:g})}}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),Lr(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),rm.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,rm),Lr(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 Wt=Sl,Qy=[Wt[0],Wt[1],Wt[2],.14],hc=[1,1,1,1],Zy=2,sm=[238/255,238/255,238/255,128/255],am=[24/255,144/255,1,128/255],Mo=20,Cn=20,Hs=null,Jy=()=>{if(Hs)return Hs;let n=e=>{let t=document.createElement("canvas");t.width=Mo,t.height=Mo;let r=t.getContext("2d");if(!r)return t;let o=Mo/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 Hs={normal:n(!1),hover:n(!0)},Hs},e0=n=>n.columnWidths.reduce((e,t)=>e+t,0)+(n.cols-1)*n.cellSpacing,t0=n=>n.rowHeights.reduce((e,t)=>e+t,0)+(n.rows-1)*n.cellSpacing,lm=(n,e,t)=>{let r=0;for(let o=0;o<t;o++)r+=n[o]+e;return r},Ws=null,n0=()=>{if(Ws)return Ws;let n=e=>{let t=document.createElement("canvas");t.width=Cn*2,t.height=Cn*2;let r=t.getContext("2d");if(!r)return t;r.scale(2,2),r.fillStyle=e?"#1890ff20":"#eeeeee99",r.fillRect(0,0,Cn-1,Cn-1);let o=Cn/2-.5,i=Cn/2-.5,s=Cn*.25,a=Cn*.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 Ws={normal:n(!1),hover:n(!0)},Ws},cm=(n,e)=>{let t=[],r=n.tableView,o=n.cellMap,i=n.matrix,s=n.objectScale,a=e0(r)/2,l=t0(r)/2,c=Ct/e/Math.max(s.x,1e-6),u=Ct/e/Math.max(s.y,1e-6);for(let b of n.selectedCells){let x=o.get(`${b.row},${b.col}`);if(x?.isMerged)continue;let y=x?.rowspan??1,S=x?.colspan??1,v=ro(r,{r1:b.row,r2:b.row+y-1,c1:b.col,c2:b.col+S-1}),T=v.left+v.width/2,C=v.top+v.height/2;t.push({matrix:Y(i,[1,0,0,1,T,C]),dims:{x:v.width,y:v.height},color:Qy}),t.push({matrix:Y(i,[1,0,0,1,T,v.top]),dims:{x:v.width+2*c,y:u},color:Wt}),t.push({matrix:Y(i,[1,0,0,1,T,v.top+v.height]),dims:{x:v.width+2*c,y:u},color:Wt}),t.push({matrix:Y(i,[1,0,0,1,v.left,C]),dims:{x:c,y:v.height+2*u},color:Wt}),t.push({matrix:Y(i,[1,0,0,1,v.left+v.width,C]),dims:{x:c,y:v.height+2*u},color:Wt})}if(n.hoveredBorder){let{type:b,position:x}=n.hoveredBorder,y=b==="col"?V(i,x,-l):V(i,-a,x),S=b==="col"?V(i,x,l):V(i,a,x);t.push(Ce(y,S,Zy/e,Wt))}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=yr(o,n.selectedCells);for(let b=0;b<r.rows;b++){let x=lm(r.rowHeights,r.cellSpacing,b)-l,y=r.rowHeights[b],S=n.hoveredStrip?.kind==="row"&&n.hoveredStrip.index===b?!0:p.rows.has(b);t.push({matrix:Y(i,[1,0,0,1,h-f/2,x+y/2]),dims:{x:f,y},color:S?am:sm})}for(let b=0;b<r.cols;b++){let x=lm(r.columnWidths,r.cellSpacing,b)-a,y=r.columnWidths[b],S=n.hoveredStrip?.kind==="col"&&n.hoveredStrip.index===b?!0:p.cols.has(b);t.push({matrix:Y(i,[1,0,0,1,x+y/2,d-m/2]),dims:{x:y,y:m},color:S?am:sm})}{let b=n0();t.push({matrix:Y(i,[1,0,0,1,h-f/2,d-m/2]),dims:{x:f,y:m},color:hc,texture:n.hoveredDragHandle?b.hover:b.normal})}let g=n.hoveredIndicator??(n.borderDragging?null:n.hoveredBorder);if(g){let b=Jy(),x=g.type==="col";t.push({matrix:Y(i,[1,0,0,1,x?g.position:-a-15,x?-l-15:g.position]),dims:{x:Mo/(e*Math.max(s.x,1e-6)),y:Mo/(e*Math.max(s.y,1e-6))},color:hc,texture:n.hoveredIndicator?b.hover:b.normal})}if(n.selectedCells.length&&!n.editingCell&&!n.isFullCellSelection){let b=n.selectionBoundsRect;if(b){let x=b.left+b.width,y=b.top+b.height,S=gn/e/Math.max(s.x,1e-6),v=gn/e/Math.max(s.y,1e-6),T=(gn-2*Ct)/e/Math.max(s.x,1e-6),C=(gn-2*Ct)/e/Math.max(s.y,1e-6);t.push({matrix:Y(i,[1,0,0,1,x,y]),dims:{x:S,y:v},color:Wt}),t.push({matrix:Y(i,[1,0,0,1,x,y]),dims:{x:T,y:C},color:n.hoveredRangeHandle?Wt:hc})}}return t};var r0=(n,e,t,r)=>{let o=n.nodes.filter(h=>Qe(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=ae(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],g=Math.max(Number(d.strokeWidth)||1,1.2/i),b=h.bounds;if(h.dims.y===0){let x=(b.top+b.bottom)/2;u.push({matrix:[1,0,0,1,s+l/2,x],dims:{x:l,y:g},color:p})}else if(h.dims.x===0){let x=(b.left+b.right)/2;u.push({matrix:[1,0,0,1,x,a+c/2],dims:{x:g,y:c},color:p})}}return u},um=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 se?e.selection[0]:null,u=l?[...n.cellEditOverlayOnly?[]:bn(l.aCoords,t),...o.quads]:r?Oh(r,t):c?.editingMask?Bh(c,t,a):Fh(e,t,a,n.mobileControls===!0),h=l&&e.selection.length===1?e.selection[0]:null;l&&h instanceof Z&&h.containsDeep(l)&&(u=[...u,...Bi(h.aCoords,t)]),!l&&!r&&e.selection.length===1&&e.selection[0]instanceof te&&(u=[...u,...cm(e.selection[0],t)]);let d=e.seamHover;if(c&&d&&d.puzzle===c&&(u=[...u,...Wh(Hh(d.puzzle,d.mask,d.handle),t)]),e.hovered&&!r&&!Qe(e.hovered)&&(u=[...u,...Hi(e.hovered,t)]),u=[...u,...i],s){u=[...u,...r0(e,s.vpt,s.cssWidth,s.cssHeight)];let f=e.nodes.find(p=>p.raw.id===_t),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,...Jh({vpt:s.vpt,cssWidth:s.cssWidth,cssHeight:s.cssHeight,workspaceRect:m,referenceLine:s.referenceLine??null,selectionRects:e.selection.filter(p=>!Qe(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 Gs(n,e,t,r,o){for(let i=0;i<o;i++){let s=t[i];if(!Qe(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 dc(n){let e=n.doc.editingNode;if(n.cropSessionController.active){Co(n,n.cropSessionController.buildOverlay(n.zoom))&&n.requestRenderAll();return}if(n.expandSessionController.active){Co(n,n.expandSessionController.buildOverlay(n.zoom))&&n.requestRenderAll();return}if(n.pathSessionController.active){Co(n,n.pathSessionController.buildOverlay(n.zoom))&&n.requestRenderAll();return}if(n.warpSessionController.active){Co(n,n.warpSessionController.buildOverlay())&&n.requestRenderAll();return}let t=um({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.viewportTransform,cssWidth:n.cssWidth,cssHeight:n.cssHeight,referenceLine:n.referenceLineDrag}:null});Co(n,t),n.renderer.frame.animationActive&&n.requestRenderAll()}function Co(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 o0=n=>typeof n!="string"||!n||/^cmyk\(/i.test(n)?null:n,_r=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 o0(n)},fc=n=>n?.offsetEnable?{x:Number(n.offsetX)||0,y:Number(n.offsetY)||0}:{x:0,y:0},Jt=(n,e={})=>{if(!n||typeof n!="object"||Array.isArray(n))return null;let t=n,r=a=>{if(!a||typeof a!="object")return!1;let l=a;return l.enabled!==!1&&l.showInDialog!==!1},o=[];if(Array.isArray(t.dropShadow))for(let a of t.dropShadow){if(!r(a))continue;let l=_r(a?.fill)??_r(a?.color)??"rgba(0,0,0,0.5)",c=Number(a?.blur)||0,u=Number(a?.offsetX)||0,h=Number(a?.offsetY)||0;!c&&!u&&!h||o.push({color:l,rgba:ae(l),blur:c,offsetX:u,offsetY:h})}let i=[];if(Array.isArray(t.solidFill))for(let a of t.solidFill){if(!r(a))continue;let l=Number(a?.fillType)||0;if(l===1){if(!a?.fill||typeof a.fill!="object")continue;let u=hr(a.fill);if(!u)continue;i.push({kind:"gradient",decl:u,offset:fc(a)});continue}if(l!==0)continue;let c=_r(a?.fill)??_r(a?.color);c&&i.push({kind:"solid",color:c,rgba:ae(c),offset:fc(a)})}let s=[];if(Array.isArray(t.stroke))for(let a of t.stroke){if(!r(a))continue;let l=a?.size&&typeof a.size=="object"?Number(a.size.value):0,c=e.text?l:Number(a?.strokeWidth)||l||0;if(!c)continue;let u=_r(a?.fill)??_r(a?.color)??"#666666",h=a?.position||a?.strokeAlignment||(e.text?"center":"outside");s.push({color:u,rgba:ae(u),width:c,alignment:h,offset:fc(a)})}return o.length===0&&i.length===0&&s.length===0?null:{dropShadows:o,solidFills:i,strokes:s}},Rn=n=>{let e=a=>String(Math.round(a*1e4)/1e4),t=a=>a.map(e).join(","),r=n.dropShadows.map(a=>`${t(a.rgba)}:${e(a.blur)}:${e(a.offsetX)}:${e(a.offsetY)}`).join(";"),o=a=>{let l=`@${e(a.offset.x)},${e(a.offset.y)}`;if(a.kind==="solid")return t(a.rgba)+l;let c=a.decl,u=c.stops.map(d=>`${e(d.offset)}@${d.color.map(e).join(",")}`).join(","),h=c.gradientTransform?c.gradientTransform.map(e).join(","):"-";return`g${c.kind[0]}:${e(c.x1)},${e(c.y1)},${e(c.x2)},${e(c.y2)},${e(c.r1)},${e(c.r2)},${c.gradientUnits},${h};${u}${l}`},i=n.solidFills.map(o).join(";"),s=n.strokes.map(a=>`${t(a.rgba)}:${e(a.width)}:${a.alignment}@${e(a.offset.x)},${e(a.offset.y)}`).join(";");return`psd|${r}|${i}|${s}`};var i0=512,s0=new Set([L.QRCODE,L.BARCODE,L.ECHART,L.FABRIC_ECHART]),dm=n=>{let e=Jt(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:Rn(e)}},a0=n=>n?`${n.sx},${n.sy},${n.sw},${n.sh}`:"none",mc=new WeakMap,hm=n=>Math.max(1,Math.min(i0,Math.floor(n))),l0=(n,e,t,r,o)=>{let i=dm(n);if(!i)return;let s=n.imageEl;if(!s)return;let a=n.dims,l=null;if(i.shadows.length){let h=Ts(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 Tn(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),g=Math.round(u[1]*f+u[3]*m+l.h/2);if(p>=0&&g>=0&&p<l.w&&g<l.h&&l.data[(g*l.w+p)*4+3]>o){e[h*t+d]=1;continue}}for(let p of c){let g=Math.round(f-p.dx+p.w/2),b=Math.round(m-p.dy+p.h/2);if(g>=0&&b>=0&&g<p.w&&b<p.h&&p.data[(b*p.w+g)*4+3]>o){e[h*t+d]=1;break}}}},c0=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=hm(t.x),a=hm(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,gi/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);l0(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}},u0=n=>{let e=`${n.dims.x},${n.dims.y}|${a0(n.cropRect)}|${n.renderOpacity}`,t=dm(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])}`},h0=n=>{let e=u0(n),t=mc.get(n);if(t&&t.stamp===e&&t.element===n.imageEl)return t.rec;let r=c0(n);return mc.set(n,{element:n.imageEl,stamp:e,rec:r}),r},d0=(n,e,t)=>{let r=h0(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},f0=(n,e,t,r)=>{for(let o of n.children)if(!(!o.visible||!o.containsPoint(e,t,r.strokeBandOf?.(o)??0))&&!pc(o,e,t,r))return!0;return!1},pc=(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 se||n instanceof le||n instanceof re||n.isTextType||n.isLineType?!1:n instanceof Z?!f0(n,e,t,r):!n.isImageType||s0.has(n.typeKey)||typeof n.raw.name=="string"&&n.raw.name.toLowerCase()==="qrcode"||!ft.has(n.typeKey)?!1:d0(n,e,t)},m0=n=>{mc.delete(n)};import p0 from"rbush";var bc=0,b0=()=>(bc=(bc+1)%4294967295,`tx-${Date.now().toString(36)}-${bc.toString(36)}`),or=class{events=new On;_nodes=[];_index=new p0;_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 Z&&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 Z?this._selection[0]:null);this._groupEditingGroup=r&&!(r instanceof te)&&!(r instanceof se)?r:null}_hovered=null;get hovered(){return this._hovered}setHovered(e){let r=e!==null&&this._nodes.some(o=>o===e||o instanceof Z&&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}=ul(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 Z)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 Z&&!(s instanceof te)){let a=t(s.children,s);if(a)return a}}return null};return t(this._nodes,null)}setProps(e,t,r={}){e.set(t),"visible"in t&&this.bumpStructure(),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 cl/this._hitZoom}strokeHitBand(e){return vh(e)?Math.max(Number(e.raw.padding)||0,cl)/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))&&!pc(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&&!Dt.has(String(a.raw.id??""))&&!Qe(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"))}applyTransform(e,t,r,o){if(e.length){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??b0();this.events.fire("object:modified",e,{...t,transactionId:r})}enterEditing(e,t={}){let r=this._nodes.find(i=>i===e||i instanceof Z&&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=fm(r,e),this.editSelection.end=fm(r,t)}toObjects(){return this._nodes.filter(e=>!e.syntheticOwner).map(e=>e.toObject())}},fm=(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};function mm(n,e,t,r,o){let i=V(e,n.left,n.top),s=V(e,n.left+n.width,n.top+n.height),a=Math.floor(Math.min(i.x,s.x)*o),l=Math.ceil(Math.max(i.x,s.x)*o),c=Math.min(i.y,s.y),u=Math.max(i.y,s.y),h=Math.floor((r-u)*o),d=Math.ceil((r-c)*o),f=Math.max(0,a),m=Math.max(0,h),p=Math.min(Math.ceil(t*o),l),g=Math.min(Math.ceil(r*o),d);return{x:f,y:m,w:Math.max(0,p-f),h:Math.max(0,g-m)}}function pm(n,e){n.enable(n.SCISSOR_TEST),n.scissor(e.x,e.y,e.w,e.h)}function bm(n){n.disable(n.SCISSOR_TEST)}function Pn(n){let e=n.isEnabled(n.SCISSOR_TEST);e&&n.disable(n.SCISSOR_TEST);let t=!1;return()=>{t||(t=!0,e&&n.enable(n.SCISSOR_TEST))}}var gm=56;function zs(n){let e=n.nodes.find(t=>String(t.raw.id??"")===_t);return!e||!e.visible||!(e.bounds.width>0)||!(e.bounds.height>0)?null:e}var Xs=class{entries=[{doc:new or,origin:{x:0,y:0},workspaceNode:null,pendingRaw:null,placeholderRect:null}];viewportZoom=1;activeIndexValue=0;get pageCount(){return this.entries.length}get activeIndex(){return this.activeIndexValue}get activeDoc(){return this.entries[this.activeIndexValue].doc}pageAt(e){return this.entries[e]??null}setActiveIndex(e){return e<0||e>=this.entries.length||e===this.activeIndexValue?!1:(this.activeIndexValue=e,!0)}insert(e){let t=Math.max(0,Math.min(this.entries.length,e));return this.entries.splice(t,0,{doc:new or,origin:{x:0,y:0},workspaceNode:null,pendingRaw:null,placeholderRect:null}),this.activeIndexValue>=t&&this.activeIndexValue++,this.refreshAll(),t}rebuildAroundActive(e,t){if(e<1)return;let r=Math.max(0,Math.min(t,e-1)),o=[];for(let i=0;i<e;i++)o.push(i===r?{doc:this.activeDoc,origin:{x:0,y:0},workspaceNode:null,pendingRaw:null,placeholderRect:null}:{doc:new or,origin:{x:0,y:0},workspaceNode:null,pendingRaw:null,placeholderRect:null});this.entries=o,this.activeIndexValue=r,this.refreshAll()}remove(e){return this.entries.length<=1||e<0||e>=this.entries.length?!1:(this.entries.splice(e,1),this.activeIndexValue>=this.entries.length&&(this.activeIndexValue=this.entries.length-1),this.refreshAll(),!0)}refresh(e){let t=this.entries[e];t&&(t.workspaceNode=zs(t.doc))}isBuilt(e){return this.entries[e]?.pendingRaw==null}setPageRaw(e,t){let r=this.entries[e];return r?(r.pendingRaw=t,r.placeholderRect=g0(t),r.doc.nodes.length>0&&r.doc.loadObjects([]),r.workspaceNode=null,!0):!1}markBuilt(e){let t=this.entries[e];t&&(t.pendingRaw=null,t.placeholderRect=null,this.refresh(e))}documentBounds(){let e=1/0,t=1/0,r=-1/0,o=-1/0;for(let i of this.layout()){let s=i.rect.left+i.entry.origin.x,a=i.rect.top+i.entry.origin.y;e=Math.min(e,s),t=Math.min(t,a),r=Math.max(r,s+i.rect.width),o=Math.max(o,a+i.rect.height)}return e===1/0?null:{left:e,top:t,width:r-e,height:o-t}}refreshAll(){for(let e=0;e<this.entries.length;e++)this.refresh(e)}layout(){let e=[],t=0;for(let o=0;o<this.entries.length;o++){let i=this.entries[o],s=i.workspaceNode?{...i.workspaceNode.bounds}:i.pendingRaw?i.placeholderRect:x0(i.doc);s&&(t=Math.max(t,s.width),e.push({index:o,entry:i,rect:s}))}let r=0;for(let{entry:o,rect:i}of e)o.origin.x=(t-i.width)/2-i.left||0,o.origin.y=r-i.top||0,r+=i.height+gm/(this.viewportZoom||1);return e}pageRectAt(e){let t=this.layout().find(r=>r.index===e);return t?{left:t.rect.left+t.entry.origin.x,top:t.rect.top+t.entry.origin.y,width:t.rect.width,height:t.rect.height}:null}route(e,t){for(let r of this.layout()){let o=r.rect.left+r.entry.origin.x,i=r.rect.top+r.entry.origin.y;if(e>=o&&e<=o+r.rect.width&&t>=i&&t<=i+r.rect.height)return{index:r.index,doc:r.entry.doc,local:{x:e-r.entry.origin.x,y:t-r.entry.origin.y}}}return null}visibleEntries(e,t=0){let r=[];for(let o of this.layout()){let i={left:o.rect.left+o.entry.origin.x,top:o.rect.top+o.entry.origin.y,width:o.rect.width,height:o.rect.height};i.left-t<=e.r&&i.left+i.width+t>=e.l&&i.top-t<=e.b&&i.top+i.height+t>=e.t&&r.push({index:o.index,entry:o.entry,rect:i})}return r}originAt(e){this.layout();let t=this.entries[e]?.origin;return t?{x:t.x,y:t.y}:{x:0,y:0}}indexOfDoc(e){return this.entries.findIndex(t=>t.doc===e)}allDocs(){return this.entries.map(e=>e.doc)}pageVpt(e,t){this.layout();let r=this.entries[t];return r?Y(e,[1,0,0,1,r.origin.x,r.origin.y]):[...e]}zoomViewportAt(e,t,r,o){let i=(t-e[4])/e[0],s=(r-e[5])/e[3],a=this.route(i,s)?.index??this.activeIndex,l=this.pageRectAt(a),c=l?l.left+l.width/2:i,u=l?l.top+l.height/2:s,h=V(e,c,u);this.viewportZoom=o;let d=this.pageRectAt(a),f=s+(d?.top??0)-(l?.top??0);return[o,0,0,o,h.x-o*(d?d.left+d.width/2:c),r-o*f]}drainAll(){for(let e of this.entries)e.doc.drainRenderDirty()}};function g0(n){for(let i of n){if(String(i.id??"")!==_t)continue;let s=Number(i.left??0),a=Number(i.top??0),l=Number(i.width??0),c=Number(i.height??0);return Number.isFinite(s)&&Number.isFinite(a)&&l>0&&c>0?{left:s,top:a,width:l,height:c}:null}let e=1/0,t=1/0,r=-1/0,o=-1/0;for(let i of n){let s=String(i.id??"");if(s!==_t&&Dt.has(s)||ee(i)===L.REFERENCELINE)continue;let a=Number(i.left??0),l=Number(i.top??0),c=Number(i.width??0),u=Number(i.height??0);!Number.isFinite(a)||!Number.isFinite(l)||!(c>0)||!(u>0)||(e=Math.min(e,a),t=Math.min(t,l),r=Math.max(r,a+c),o=Math.max(o,l+u))}return e===1/0?{left:0,top:0,width:750,height:500}:{left:e,top:t,width:r-e,height:o-t}}function xm(n,e,t,r){if(!t||!(t.width>0)||!(t.height>0))return r;let o=t.left+t.width/2,i=t.top+t.height/2,s=V(n,o,i);return[e,0,0,e,s.x-e*o,r[5]]}function x0(n){let e=1/0,t=1/0,r=-1/0,o=-1/0;for(let i of n.nodes){let s=i.bounds;!Number.isFinite(s.left)||!Number.isFinite(s.top)||(e=Math.min(e,s.left),t=Math.min(t,s.top),r=Math.max(r,s.left+s.width),o=Math.max(o,s.top+s.height))}return e===1/0?null:{left:e,top:t,width:r-e,height:o-t}}function ym(n,e){n.layout();let t=Te(e.vpt),r=V(t,0,0),o=V(t,e.cssWidth,e.cssHeight),i={l:Math.min(r.x,o.x),t:Math.min(r.y,o.y),r:Math.max(r.x,o.x),b:Math.max(r.y,o.y)},s=16/e.zoom,a=n.visibleEntries(i,s);for(let m of a)n.isBuilt(m.index)||e.onPageVisible(m.index);let l=a.map(m=>m.rect),c=Nt(e.vpt,e.cssWidth,e.cssHeight,e.dpr),u={vpt:e.vpt,cssWidth:e.cssWidth,cssHeight:e.cssHeight,dpr:e.dpr};e.workspaceBackdrop.drawChecker(e.gl,c,u,l);let h=e.zoom*e.dpr,d=e.expandUnderlay();try{for(let m of a){e.batchOrder.flushAll(),pm(e.gl,mm(m.rect,e.vpt,e.cssWidth,e.cssHeight,e.dpr));let p=n.pageVpt(e.vpt,m.index),g=Nt(p,e.cssWidth,e.cssHeight,e.dpr);e.batch.begin(g,h),e.meshBatch.begin(g),e.batch.deferDraws=!0,e.meshBatch.deferDraws=!0,e.batchOrder.reset(),e.withPageViewport(p,()=>Gs(e.batch,e.renderer,m.entry.doc.nodes,d,m.entry.doc.nodes.length))}e.batchOrder.flushAll()}finally{bm(e.gl)}n.drainAll(),e.workspaceBackdrop.drawBackdrop(e.gl,c,u,l);let f=Nt(n.pageVpt(e.vpt,n.activeIndex),e.cssWidth,e.cssHeight,e.dpr);e.batch.begin(f,h),e.meshBatch.begin(f),e.batch.deferDraws=!0,e.meshBatch.deferDraws=!0,e.batchOrder.reset(),e.finishOverlay();for(let m of a){if(m.index===n.activeIndex)continue;let p=m.entry.doc.hovered;if(!p)continue;let g=Hi(p,e.zoom);if(!g.length)continue;let b=Nt(n.pageVpt(e.vpt,m.index),e.cssWidth,e.cssHeight,e.dpr);e.batch.begin(b,h),e.meshBatch.begin(b),e.batch.deferDraws=!0,e.meshBatch.deferDraws=!0,e.batchOrder.reset();for(let x of g)e.batch.pushQuad(x.matrix,x.dims.x,x.dims.y,x.color,x.texture?e.textures.get(x.texture):null);e.batch.flush(),e.batch.deferDraws=!1,e.meshBatch.deferDraws=!1,e.batchOrder.executeDeferred()}}var Ys=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 Us=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,!Ia())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)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.batchOrder.replaySnapshot(r),this.gateOk(),!0)}captureSnapshot(){let{host:e}=this;if(!Ia()){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 Ro=new WeakMap;function ir(n){return Ro.get(n)??n.viewportTransform}function vm(n,e,t){let r=Ro.get(n);Ro.set(n,e);try{t()}finally{r?Ro.set(n,r):Ro.delete(n)}}var Sm=(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]},kn=(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},$s=(n,e,t)=>{let r=Sm(n.uOrder,e),o=Sm(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}},sr=(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)},bt=(n,e,t)=>{n.xs.push(0,e/3,2*e/3,e),n.ys.push(t,t,t,t)},gc=(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},y0=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},wm=(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?kn(0,0,t,r,4,2):(bt(a,t,0),sr(a,0,t,r,i,o<0),n==="arcUpper"?gc(a,r):a);if(n==="fish")return bt(a,t,0),bt(a,t,r),a.ys[1]-=s,a.ys[2]+=s,a.ys[5]+=s,a.ys[6]-=s,a;if(n==="fisheye"){a=kn(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=kn(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=kn(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 kn(0,0,t,r,4,4);let l=Math.sin(i),c=Math.cos(i);if(a={uOrder:4,vOrder:4,xs:[],ys:[]},bt(a,t,0),bt(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),sr(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),sr(a,0,t,r,i,!0)}return n==="shellUpper"?gc(a,r):a}if(n==="arc"){if(Math.abs(o)<1e-9)return kn(0,0,t,r,4,2);let l=Math.sin(i);return sr(a,-r*l,t+r*l,r*(1-Math.cos(i)),i,!0),sr(a,0,t,r,i,!0),o<0?gc(a,r):a}if(n==="arch"||n==="bulge"){if(Math.abs(o)<1e-9)return kn(0,0,t,r,4,2);let l=o>0;return sr(a,0,t,0,i,l),sr(a,0,t,r,i,n==="bulge"?!l:l),a}if(n==="flag")return bt(a,t,0),bt(a,t,r),a.ys[1]-=s,a.ys[2]+=s,a.ys[5]-=s,a.ys[6]+=s,a;if(n==="wave")return bt(a,t,0),bt(a,t,r/2),bt(a,t,r),a.ys[5]+=s,a.ys[6]-=s,a;if(n==="rise")return bt(a,t,0),bt(a,t,r),a.ys[0]+=s,a.ys[1]+=s,a.ys[4]+=s,a.ys[5]+=s,a},xc=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",Tm=(n,e,t,r,o)=>{if(!xc(n)||r<=0||o<=0)return;if(!t||n==="twist")return wm(n,e,r,o);let i=wm(n,e,o,r);return i?y0(i):void 0},Em=(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}}},yc=(n,e,t)=>{let r=Tm(n.style,n.bend,n.rotate==="vertical",e,t);if(r)return Em(r,n.horizontal,n.vertical),r},Po=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(!xc(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"}},vc=(n,e,t,r,o,i,s,a,l,c,u,h,d,f)=>{let m=r-e,p=o-t,g=a-i,b=l-s;if(m<=0||p<=0||g<=0||b<=0||c<=0||u<=0||d<=0||n.xs.length===0)return;let x=(i-e)/m,y=(a-e)/m,S=(s-t)/p,v=(l-t)/p,T=(W,X)=>{let _=$s(n,W,X);return{x:h[0]*_.x+h[2]*_.y+h[4],y:h[1]*_.x+h[3]*_.y+h[5]}},C=0,R=0,w=0,E=0,M=!0,P=8;for(let W=0;W<=P;W++){let X=S+(v-S)*W/P;for(let _=0;_<=P;_++){let D=x+(y-x)*_/P,I=T(D,X);M?(C=R=I.x,w=E=I.y,M=!1):(C=Math.min(C,I.x),R=Math.max(R,I.x),w=Math.min(w,I.y),E=Math.max(E,I.y))}}let A=Math.max(8,f),k=Math.min(A,Math.max(8,Math.ceil((R-C)/d))),O=Math.min(A,Math.max(8,Math.ceil((E-w)/d))),F={columns:k+1,rows:O+1,docXs:[],docYs:[],sourceXs:[],sourceYs:[]};for(let W=0;W<F.rows;W++){let X=W/O;for(let _=0;_<F.columns;_++){let D=_/k,I=T(x+(y-x)*D,S+(v-S)*X);F.docXs.push(I.x),F.docYs.push(I.y),F.sourceXs.push(D*c),F.sourceYs.push(X*u)}}return F},Sc=(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,g=n-t,b=e-r,x=u*p-h*m,y=u*f-h*d-(g*p-b*m),S=-(g*f-b*d),v;if(Math.abs(x)<1e-9){if(Math.abs(y)<1e-9)return;v=-S/y}else{let w=y*y-4*x*S;if(w<0)return;let E=Math.sqrt(w),M=(-y+E)/(2*x),P=(-y-E)/(2*x),A=M>=-1e-9&&M<=1+1e-9,k=P>=-1e-9&&P<=1+1e-9;if(A&&k)v=Math.min(Math.max(M,0),1);else if(A)v=M;else if(k)v=P;else return}let T=d+m*v,C=f+p*v,R;if(Math.abs(T)>=Math.abs(C)){if(Math.abs(T)<1e-9)return;R=(g-u*v)/T}else{if(Math.abs(C)<1e-9)return;R=(b-h*v)/C}if(!(v<-1e-9||v>1.000000001||R<-1e-9||R>1.000000001))return{s:Math.min(Math.max(v,0),1),t:Math.min(Math.max(R,0),1)}};var v0=`#version 300 es
255
255
  out vec2 vUv;
256
256
  void main() {
257
257
  vec2 p = vec2((gl_VertexID << 1) & 2, gl_VertexID & 2);
258
258
  vUv = p;
259
259
  gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);
260
- }`,u0=`#version 300 es
260
+ }`,S0=`#version 300 es
261
261
  precision mediump float;
262
262
  in vec2 vUv;
263
263
  uniform sampler2D uSrc;
@@ -282,13 +282,13 @@ ma = uCovers;
282
282
  factor *= mix(ma, 1.0 - ma, uInvert);
283
283
  }
284
284
  outColor = vec4(src.rgb * factor, src.a * factor);
285
- }`,$s=class{fb=null;tex=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("[GLIsolator] shader:",e.getShaderInfoLog(l)),e.deleteShader(l),null)):null},r=t(e.VERTEX_SHADER,c0),o=t(e.FRAGMENT_SHADER,u0),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.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),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:(e.bindFramebuffer(e.FRAMEBUFFER,this.fb),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),!0)}end(e){e.bindFramebuffer(e.FRAMEBUFFER,this.boundFb)}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 wc=["multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],h0=new Map(wc.map((n,e)=>[n,e])),Sm=n=>typeof n!="string"?null:h0.get(n)??null;var d0=`#version 300 es
285
+ }`,Vs=class{fb=null;tex=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("[GLIsolator] shader:",e.getShaderInfoLog(l)),e.deleteShader(l),null)):null},r=t(e.VERTEX_SHADER,v0),o=t(e.FRAGMENT_SHADER,S0),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.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),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:(e.bindFramebuffer(e.FRAMEBUFFER,this.fb),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),!0)}end(e){e.bindFramebuffer(e.FRAMEBUFFER,this.boundFb)}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 wc=["multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],w0=new Map(wc.map((n,e)=>[n,e])),Mm=n=>typeof n!="string"?null:w0.get(n)??null;var T0=`#version 300 es
286
286
  out vec2 vUv;
287
287
  void main() {
288
288
  vec2 p = vec2((gl_VertexID << 1) & 2, gl_VertexID & 2);
289
289
  vUv = p;
290
290
  gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);
291
- }`,f0=`#version 300 es
291
+ }`,E0=`#version 300 es
292
292
  precision mediump float;
293
293
  in vec2 vUv;
294
294
  uniform sampler2D uSrc;
@@ -370,14 +370,14 @@ vec3 b = blendB(cb, cs, uMode);
370
370
  vec3 co = (1.0 - ab) * src.rgb + b * (as * ab) + (1.0 - as) * dst.rgb;
371
371
  float ao = as + ab * (1.0 - as);
372
372
  outColor = vec4(co, ao);
373
- }`,Vs=class{fb=null;tex=null;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,d0),o=t(e.FRAGMENT_SHADER,f0),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.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:(e.bindFramebuffer(e.FRAMEBUFFER,this.fb),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),!0)}end(e){e.bindFramebuffer(e.FRAMEBUFFER,this.boundFb)}composite(e,t){!this.prog||!this.tex||!this.dstTex||t<0||t>=wc.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 ke=(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 Gt=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 wm=n=>n?120:6,js=(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},_r=(n,e,t,r)=>!n.isExporting()&&e.isSettling(r)||r>t.bakeDeadline;var qs=n=>n?n.length>200?`${n.substring(0,50)}...${n.substring(n.length-50)}`:n:"",Tc=4096,m0=(n,e)=>{let t=n.raw,r=n.clipImageRaw,o=Math.max(Math.abs(r?.scaleX??1),Math.abs(r?.scaleY??1)),i=Math.min(4,Math.max(1,e.dpr*e.zoom*o)),s=e.clipEl;return{sigBase:[qs(r?.src),s.naturalWidth??s.videoWidth??s.width??0,s.naturalHeight??s.videoHeight??s.height??0,e.frameVersion??0,r?.angle??0,r?.scaleX??1,r?.scaleY??1,r?.flipX?1:0,r?.flipY?1:0,t.clipX??0,t.clipY??0,t.width??0,t.height??0,t.cornerRadius??0,qs(t.src),e.clipFiltersKey??""].join("|"),k:i.toFixed(4)}},p0=(n,e)=>{let t=n.raw,r=n.clipImageRaw;if(!r)return null;let o=Number(t.width)||0,i=Number(t.height)||0;if(o<=0||i<=0)return null;let s=e.clipEl,a=s.naturalWidth||s.videoWidth||s.width||r.width||0,l=s.naturalHeight||s.videoHeight||s.height||r.height||0;if(!a||!l)return null;let c=r.scaleX??1,u=r.scaleY??1,h=Math.max(Math.abs(c),Math.abs(u)),d=Math.min(4,Math.max(1,e.dpr*e.zoom*h)),f=o*d,m=i*d,p=d;if(f>0&&m>0){let C=Math.min(1,Tc/Math.max(f,m)),R=Math.min(1,Math.sqrt(Tc*Tc/(f*m)));p=d*Math.min(C,R)}let g=document.createElement("canvas");g.width=Math.max(1,Math.round(o*p)),g.height=Math.max(1,Math.round(i*p));let b=g.getContext("2d");if(!b)return null;b.save(),b.setTransform(p,0,0,p,0,0),b.imageSmoothingEnabled=!0,b.imageSmoothingQuality="high";let x=Math.max(0,Math.min(t.cornerRadius||0,Math.min(o,i)/2));if(x>0){b.beginPath();let C=0,R=0;b.moveTo(C+x,R),b.lineTo(C+o-x,R),b.quadraticCurveTo(C+o,R,C+o,R+x),b.lineTo(C+o,R+i-x),b.quadraticCurveTo(C+o,R+i,C+o-x,R+i),b.lineTo(C+x,R+i),b.quadraticCurveTo(C,R+i,C,R+i-x),b.lineTo(C,R+x),b.quadraticCurveTo(C,R,C+x,R),b.closePath(),b.clip()}b.translate(o/2,i/2),b.rotate((r.angle??0)*Math.PI/180);let y=r.flipX?-1:1,S=r.flipY?-1:1;b.scale(c*y,u*S);let v=t.clipX??0,M=t.clipY??0;return b.translate(v/(c||1),M/(u||1)),b.translate(-a/2,-l/2),b.drawImage(e.clipEl,0,0,a,l),b.globalCompositeOperation="destination-in",b.setTransform(p,0,0,p,0,0),b.drawImage(e.maskEl,0,0,o,i),b.restore(),{canvas:g,w:o,h:i}},Ks=class{host;frame;bakes=new WeakMap;settle;constructor(e,t,r=new Gt(()=>e.requestRenderAll())){this.host=e,this.frame=t,this.settle=r}noteVptChange(){this.settle.noteInteraction()}bake(e,t){let r={...t,zoom:this.host.zoom,dpr:this.host.dpr},{sigBase:o,k:i}=m0(e,r),s=this.bakes.get(e);if(s&&s.sigBase===o&&js(s.k,i,this.host.bakeKReuseFloor??0))return s;if(s)if(s.sigBase!==o)this.host.gl.deleteTexture(s.tex);else{if(_r(this.host,this.settle,this.frame,performance.now()))return this.frame.bakeMore=!0,s;this.host.gl.deleteTexture(s.tex)}let a=p0(e,r);if(!a)return null;let l=ke(this.host.gl,a.canvas,{mipmap:!0});if(!l)return null;let c={sigBase:o,k:i,tex:l,w:a.w,h:a.h};return this.bakes.set(e,c),c}invalidate(){this.bakes=new WeakMap}};var Em=`attribute vec2 aPosition;
373
+ }`,js=class{fb=null;tex=null;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,T0),o=t(e.FRAGMENT_SHADER,E0),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.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:(e.bindFramebuffer(e.FRAMEBUFFER,this.fb),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),!0)}end(e){e.bindFramebuffer(e.FRAMEBUFFER,this.boundFb)}composite(e,t){!this.prog||!this.tex||!this.dstTex||t<0||t>=wc.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 ke=(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 Gt=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 Cm=n=>n?120:6,qs=(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},An=(n,e,t,r)=>!n.isExporting()&&e.isSettling(r)||r>t.bakeDeadline;var Ks=n=>n?n.length>200?`${n.substring(0,50)}...${n.substring(n.length-50)}`:n:"",Tc=4096,M0=(n,e)=>{let t=n.raw,r=n.clipImageRaw,o=Math.max(Math.abs(r?.scaleX??1),Math.abs(r?.scaleY??1)),i=Math.min(4,Math.max(1,e.dpr*e.zoom*o)),s=e.clipEl;return{sigBase:[Ks(r?.src),s.naturalWidth??s.videoWidth??s.width??0,s.naturalHeight??s.videoHeight??s.height??0,e.frameVersion??0,r?.angle??0,r?.scaleX??1,r?.scaleY??1,r?.flipX?1:0,r?.flipY?1:0,t.clipX??0,t.clipY??0,t.width??0,t.height??0,t.cornerRadius??0,Ks(t.src),e.clipFiltersKey??""].join("|"),k:i.toFixed(4)}},C0=(n,e)=>{let t=n.raw,r=n.clipImageRaw;if(!r)return null;let o=Number(t.width)||0,i=Number(t.height)||0;if(o<=0||i<=0)return null;let s=e.clipEl,a=s.naturalWidth||s.videoWidth||s.width||r.width||0,l=s.naturalHeight||s.videoHeight||s.height||r.height||0;if(!a||!l)return null;let c=r.scaleX??1,u=r.scaleY??1,h=Math.max(Math.abs(c),Math.abs(u)),d=Math.min(4,Math.max(1,e.dpr*e.zoom*h)),f=o*d,m=i*d,p=d;if(f>0&&m>0){let C=Math.min(1,Tc/Math.max(f,m)),R=Math.min(1,Math.sqrt(Tc*Tc/(f*m)));p=d*Math.min(C,R)}let g=document.createElement("canvas");g.width=Math.max(1,Math.round(o*p)),g.height=Math.max(1,Math.round(i*p));let b=g.getContext("2d");if(!b)return null;b.save(),b.setTransform(p,0,0,p,0,0),b.imageSmoothingEnabled=!0,b.imageSmoothingQuality="high";let x=Math.max(0,Math.min(t.cornerRadius||0,Math.min(o,i)/2));if(x>0){b.beginPath();let C=0,R=0;b.moveTo(C+x,R),b.lineTo(C+o-x,R),b.quadraticCurveTo(C+o,R,C+o,R+x),b.lineTo(C+o,R+i-x),b.quadraticCurveTo(C+o,R+i,C+o-x,R+i),b.lineTo(C+x,R+i),b.quadraticCurveTo(C,R+i,C,R+i-x),b.lineTo(C,R+x),b.quadraticCurveTo(C,R,C+x,R),b.closePath(),b.clip()}b.translate(o/2,i/2),b.rotate((r.angle??0)*Math.PI/180);let y=r.flipX?-1:1,S=r.flipY?-1:1;b.scale(c*y,u*S);let v=t.clipX??0,T=t.clipY??0;return b.translate(v/(c||1),T/(u||1)),b.translate(-a/2,-l/2),b.drawImage(e.clipEl,0,0,a,l),b.globalCompositeOperation="destination-in",b.setTransform(p,0,0,p,0,0),b.drawImage(e.maskEl,0,0,o,i),b.restore(),{canvas:g,w:o,h:i}},Qs=class{host;frame;bakes=new WeakMap;settle;constructor(e,t,r=new Gt(()=>e.requestRenderAll())){this.host=e,this.frame=t,this.settle=r}noteVptChange(){this.settle.noteInteraction()}bake(e,t){let r={...t,zoom:this.host.zoom,dpr:this.host.dpr},{sigBase:o,k:i}=M0(e,r),s=this.bakes.get(e);if(s&&s.sigBase===o&&qs(s.k,i,this.host.bakeKReuseFloor??0))return s;if(s)if(s.sigBase!==o)this.host.gl.deleteTexture(s.tex);else{if(An(this.host,this.settle,this.frame,performance.now()))return this.frame.bakeMore=!0,s;this.host.gl.deleteTexture(s.tex)}let a=C0(e,r);if(!a)return null;let l=ke(this.host.gl,a.canvas,{mipmap:!0});if(!l)return null;let c={sigBase:o,k:i,tex:l,w:a.w,h:a.h};return this.bakes.set(e,c),c}invalidate(){this.bakes=new WeakMap}};var Pm=`attribute vec2 aPosition;
374
374
  varying vec2 vTexCoord;
375
375
  void main() {
376
376
  vTexCoord = aPosition;
377
377
  gl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);
378
378
  }`,Ye=`precision highp float;
379
379
  uniform sampler2D uTexture;
380
- varying vec2 vTexCoord;`,Tm=`
380
+ varying vec2 vTexCoord;`,Rm=`
381
381
  vec3 rgb2hsl(vec3 c) {
382
382
  float maxc = max(c.r, max(c.g, c.b));
383
383
  float minc = min(c.r, min(c.g, c.b));
@@ -419,7 +419,7 @@ vec3 hsl2rgb(vec3 hsl) {
419
419
  hslChannel(p, q, h - 1.0 / 3.0)
420
420
  );
421
421
  }
422
- `,b0=n=>{let e=n/2;return e<.05?1:Math.max(1,Math.min(64,Math.round(Math.sqrt(4*e*e+1))))};function Mm(n,e,t){let r=[];for(let o of n)switch(o.kind){case"Brightness":r.push({source:`${Ye}
422
+ `,R0=n=>{let e=n/2;return e<.05?1:Math.max(1,Math.min(64,Math.round(Math.sqrt(4*e*e+1))))};function km(n,e,t){let r=[];for(let o of n)switch(o.kind){case"Brightness":r.push({source:`${Ye}
423
423
  uniform float uW;
424
424
  void main() {
425
425
  vec4 color = texture2D(uTexture, vTexCoord);
@@ -437,7 +437,7 @@ color.rgb = clamp((color.rgb - 0.5) * uM + 0.5, 0.0, 1.0);
437
437
  gl_FragColor = color;
438
438
  }`,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:`${Ye}
439
439
  uniform float uSat;
440
- ${Tm}
440
+ ${Rm}
441
441
  void main() {
442
442
  vec4 color = texture2D(uTexture, vTexCoord);
443
443
  vec3 hsl = rgb2hsl(color.rgb);
@@ -458,14 +458,14 @@ color.rgb = lum + (color.rgb - lum) * factor;
458
458
  gl_FragColor = color;
459
459
  }`,setup:(i,s)=>i.uniform1f(s.uV,o.vibrance)});break;case"HueRotation":r.push({source:`${Ye}
460
460
  uniform float uShift;
461
- ${Tm}
461
+ ${Rm}
462
462
  void main() {
463
463
  vec4 color = texture2D(uTexture, vTexCoord);
464
464
  vec3 hsl = rgb2hsl(color.rgb);
465
465
  hsl.x = fract(hsl.x + uShift / 360.0);
466
466
  color.rgb = hsl2rgb(hsl);
467
467
  gl_FragColor = color;
468
- }`,setup:(i,s)=>i.uniform1f(s.uShift,o.rotation*100)});break;case"ColorMatrix":r.push(g0(Lf[o.matrixId]));break;case"Grayscale":{let i=o.mode==="lightness"?`
468
+ }`,setup:(i,s)=>i.uniform1f(s.uShift,o.rotation*100)});break;case"ColorMatrix":r.push(P0(Ff[o.matrixId]));break;case"Grayscale":{let i=o.mode==="lightness"?`
469
469
  vec4 col = texture2D(uTexture, vTexCoord);
470
470
  float average = (max(max(col.r, col.g),col.b) + min(min(col.r, col.g),col.b)) / 2.0;
471
471
  gl_FragColor = vec4(average, average, average, col.a);`:o.mode==="luminosity"?`
@@ -490,7 +490,7 @@ gl_FragColor = vec4(1.0 - color.r,1.0 -color.g,1.0 - color.b,color.a);
490
490
  } else {
491
491
  gl_FragColor = color;
492
492
  }
493
- }`,setup:(i,s)=>{i.uniform1i(s.uInvert,o.invert?1:0),i.uniform1i(s.uAlpha,o.alphaOnly?1:0)}});break;case"Blur":{let i=b0(o.blur),s=`precision highp float;
493
+ }`,setup:(i,s)=>{i.uniform1i(s.uInvert,o.invert?1:0),i.uniform1i(s.uAlpha,o.alphaOnly?1:0)}});break;case"Blur":{let i=R0(o.blur),s=`precision highp float;
494
494
  uniform sampler2D uTexture;
495
495
  uniform vec2 uTexSize;
496
496
  uniform vec2 uDir;
@@ -598,7 +598,7 @@ gl_FragColor = color;
598
598
  if (color.a > 0.0) {
599
599
  ${i[o.mode]??i.multiply}
600
600
  }
601
- }`,setup:(s,a)=>{let[l,c,u]=Sn(o.color);s.uniform4f(a.uColor,o.alpha*l/255,o.alpha*c/255,o.alpha*u/255,o.alpha)}});break}case"Vignette":r.push({source:`${Ye}
601
+ }`,setup:(s,a)=>{let[l,c,u]=wn(o.color);s.uniform4f(a.uColor,o.alpha*l/255,o.alpha*c/255,o.alpha*u/255,o.alpha)}});break}case"Vignette":r.push({source:`${Ye}
602
602
  uniform float uIntensity;
603
603
  void main() {
604
604
  vec4 color = texture2D(uTexture, vTexCoord);
@@ -650,7 +650,7 @@ vec4 color = texture2D(uTexture, vTexCoord);
650
650
  float gray = dot(color.rgb, vec3(0.299, 0.587, 0.114));
651
651
  color.rgb = mix(uColor1, uColor2, gray);
652
652
  gl_FragColor = color;
653
- }`,setup:(i,s)=>{let a=Sn(o.color1).map(c=>c/255),l=Sn(o.color2).map(c=>c/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;
653
+ }`,setup:(i,s)=>{let a=wn(o.color1).map(c=>c/255),l=wn(o.color2).map(c=>c/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;
654
654
  uniform sampler2D uTexture;
655
655
  uniform float uStepW;
656
656
  uniform float uStepH;
@@ -794,7 +794,7 @@ mapped = mix(uColor1, uColor2, (gray - 0.5) * 2.0);
794
794
  }
795
795
  color.rgb = mapped;
796
796
  gl_FragColor = color;
797
- }`,setup:(i,s)=>{let a=Sn(o.color0).map(u=>u/255),l=Sn(o.color1).map(u=>u/255),c=Sn(o.color2||"#ffffff").map(u=>u/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,c[0],c[1],c[2]),i.uniform1f(s.uCount,o.color2?2:1)}});break;case"Levels":r.push({source:`${Ye}
797
+ }`,setup:(i,s)=>{let a=wn(o.color0).map(u=>u/255),l=wn(o.color1).map(u=>u/255),c=wn(o.color2||"#ffffff").map(u=>u/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,c[0],c[1],c[2]),i.uniform1f(s.uCount,o.color2?2:1)}});break;case"Levels":r.push({source:`${Ye}
798
798
  uniform float uBlackPoint;
799
799
  uniform float uWhitePoint;
800
800
  uniform float uGamma;
@@ -876,7 +876,7 @@ vec3 lin = pow(color.rgb, vec3(2.2));
876
876
  lin = clamp(lin * pow(2.0, uExposure) + vec3(uOffset), 0.0, 1.0);
877
877
  color.rgb = pow(lin, vec3(1.0 / (max(0.01, uGamma) * 2.2)));
878
878
  gl_FragColor = color;
879
- }`,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 g0(n){return{source:`precision highp float;
879
+ }`,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 P0(n){return{source:`precision highp float;
880
880
  uniform sampler2D uTexture;
881
881
  varying vec2 vTexCoord;
882
882
  uniform mat4 uColorMatrix;
@@ -886,13 +886,13 @@ vec4 color = texture2D(uTexture, vTexCoord);
886
886
  color *= uColorMatrix;
887
887
  color += uConstants;
888
888
  gl_FragColor = color;
889
- }`,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 Qs=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}|${nr(i)}`,a=this.cache.get(e);return a&&a.sig===s?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=Mm(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 g=a.createTexture();if(!g)return null;a.bindTexture(a.TEXTURE_2D,g),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 b=()=>{let A=a.createTexture();return A?(a.bindTexture(a.TEXTURE_2D,A),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),A):null},x=b(),y=b(),S=a.createFramebuffer(),v=a.createFramebuffer();if(!x||!y||!S||!v)return null;let M=this.ensureQuad(),C=Rn(a),R=g,w=x,T=S;for(let A of l){let k=this.ensureProgram(A.source);if(!k)break;a.useProgram(k.program),a.bindFramebuffer(a.FRAMEBUFFER,T),a.framebufferTexture2D(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,w,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),A.setup(a,k.uniforms),a.bindBuffer(a.ARRAY_BUFFER,M),a.enableVertexAttribArray(k.aPosition),a.vertexAttribPointer(k.aPosition,2,a.FLOAT,!1,0,0),a.drawArrays(a.TRIANGLE_STRIP,0,4),R=w,T===S?(w=y,T=v):(w=x,T=S)}let E=R;C(),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(S),a.deleteFramebuffer(v);let P=E===x?y:x;return a.deleteTexture(P),a.bindTexture(a.TEXTURE_2D,E),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,sourceTex:g,outTex:E}),E}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,Em),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()}},x0=(n,e,t)=>{let r=new Uint8ClampedArray(e*t*4),o=e*4;for(let i=0;i<t;i++)r.set(n.subarray((t-1-i)*o,(t-i)*o),i*o);return r},Cm=(n,e,t,r)=>{if(!(t>0)||!(r>0))return null;let o=n.createFramebuffer();if(!o)return null;let i=n.getParameter(n.FRAMEBUFFER_BINDING);n.bindFramebuffer(n.FRAMEBUFFER,o);try{if(n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,e,0),n.checkFramebufferStatus(n.FRAMEBUFFER)!==n.FRAMEBUFFER_COMPLETE)return null;let s=new Uint8Array(t*r*4);n.readPixels(0,0,t,r,n.RGBA,n.UNSIGNED_BYTE,s);let a=document.createElement("canvas");a.width=t,a.height=r;let l=a.getContext("2d");if(!l)return null;let c=l.createImageData(t,r);return c.data.set(x0(s,t,r)),l.putImageData(c,0,0),a}finally{n.bindFramebuffer(n.FRAMEBUFFER,i),n.deleteFramebuffer(o)}};var Rm=`#version 300 es
889
+ }`,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 Zs=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}|${rr(i)}`,a=this.cache.get(e);return a&&a.sig===s?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=km(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 g=a.createTexture();if(!g)return null;a.bindTexture(a.TEXTURE_2D,g),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 b=()=>{let A=a.createTexture();return A?(a.bindTexture(a.TEXTURE_2D,A),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),A):null},x=b(),y=b(),S=a.createFramebuffer(),v=a.createFramebuffer();if(!x||!y||!S||!v)return null;let T=this.ensureQuad(),C=Pn(a),R=g,w=x,E=S;for(let A of l){let k=this.ensureProgram(A.source);if(!k)break;a.useProgram(k.program),a.bindFramebuffer(a.FRAMEBUFFER,E),a.framebufferTexture2D(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,w,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),A.setup(a,k.uniforms),a.bindBuffer(a.ARRAY_BUFFER,T),a.enableVertexAttribArray(k.aPosition),a.vertexAttribPointer(k.aPosition,2,a.FLOAT,!1,0,0),a.drawArrays(a.TRIANGLE_STRIP,0,4),R=w,E===S?(w=y,E=v):(w=x,E=S)}let M=R;C(),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(S),a.deleteFramebuffer(v);let P=M===x?y:x;return a.deleteTexture(P),a.bindTexture(a.TEXTURE_2D,M),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,sourceTex:g,outTex:M}),M}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,Pm),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()}},k0=(n,e,t)=>{let r=new Uint8ClampedArray(e*t*4),o=e*4;for(let i=0;i<t;i++)r.set(n.subarray((t-1-i)*o,(t-i)*o),i*o);return r},Am=(n,e,t,r)=>{if(!(t>0)||!(r>0))return null;let o=n.createFramebuffer();if(!o)return null;let i=n.getParameter(n.FRAMEBUFFER_BINDING);n.bindFramebuffer(n.FRAMEBUFFER,o);try{if(n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,e,0),n.checkFramebufferStatus(n.FRAMEBUFFER)!==n.FRAMEBUFFER_COMPLETE)return null;let s=new Uint8Array(t*r*4);n.readPixels(0,0,t,r,n.RGBA,n.UNSIGNED_BYTE,s);let a=document.createElement("canvas");a.width=t,a.height=r;let l=a.getContext("2d");if(!l)return null;let c=l.createImageData(t,r);return c.data.set(k0(s,t,r)),l.putImageData(c,0,0),a}finally{n.bindFramebuffer(n.FRAMEBUFFER,i),n.deleteFramebuffer(o)}};var Nm=`#version 300 es
890
890
  out vec2 vUv;
891
891
  void main() {
892
892
  vec2 p = vec2((gl_VertexID << 1) & 2, gl_VertexID & 2);
893
893
  vUv = p;
894
894
  gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);
895
- }`,y0=`#version 300 es
895
+ }`,A0=`#version 300 es
896
896
  precision mediump float;
897
897
  in vec2 vUv;
898
898
  uniform sampler2D uSrc;
@@ -906,7 +906,7 @@ if (k >= uBoxW) break;
906
906
  acc += texture(uSrc, vUv + uDir * (float(k) - float(uBoxW - 1) * 0.5)).a;
907
907
  }
908
908
  outColor = vec4(0.0, 0.0, 0.0, acc / float(uBoxW));
909
- }`,v0=`#version 300 es
909
+ }`,N0=`#version 300 es
910
910
  precision mediump float;
911
911
  in vec2 vUv;
912
912
  uniform sampler2D uBlur;
@@ -918,13 +918,13 @@ void main() {
918
918
  float bl = texture(uBlur, vUv + uOffUv).a;
919
919
  float sil = texture(uSil, vUv).a;
920
920
  outColor = vec4(uColor.rgb, bl * (1.0 - sil) * uColor.a);
921
- }`,S0=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 re?`v${n.contentVersion}`:"";return`${n.raw.type};${t};${r}`},w0=(n,e,t,r)=>{let o=n.matrix;return[S0(n),n.dims.x,n.dims.y,T0(e),t,r,o[0].toFixed(4),o[1].toFixed(4),o[2].toFixed(4),o[3].toFixed(4)].join(";")},T0=n=>[n.rgba.join(","),n.blur,n.offsetX,n.offsetY,n.nonScaling?1:0].join("|"),Zs=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,Rm,y0),this.finalProg=this.finalProg??this.compile(e,Rm,v0),!!(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),xs(l,t,"#ffffff");let u=ke(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=Ht(r,t.raw.scaleX??1,t.raw.scaleY??1),l=gs(a)+(t.isTextType?Math.ceil((t.raw.fontSize??40)*.5):0),c=oc(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=w0(t,r,u,h),f=Rn(e);try{let m=this.targets.get(t);if(m&&m.sig!==d&&(e.deleteFramebuffer(m.rt.fb),e.deleteTexture(m.rt.tex),this.liveRts.delete(m.rt),this.epoch?.bump("gpu-shadow-rebake"),m=void 0),!m){let v=this.ensureTarget(e,null,u,h);if(!v)return null;m={sig:d,rt:v},this.targets.set(t,m)}let p=this.silhouette(e,t,d,u,h);if(!p)return null;this.b1=this.ensureTarget(e,this.b1,u,h),this.b2=this.ensureTarget(e,this.b2,u,h);let g=this.b1,b=this.b2;if(!g||!b)return null;let x=a.blur/2,y=x<.05?1:Math.max(1,Math.min(64,Math.round(Math.sqrt(4*x*x+1)))),S=(v,M,C,R)=>{this.fullscreenPass(e,this.blurProg,M,w=>{e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,v),e.uniform1i(e.getUniformLocation(w,"uSrc"),0),e.uniform2f(e.getUniformLocation(w,"uDir"),C,R),e.uniform1i(e.getUniformLocation(w,"uBoxW"),y)})};return S(p,g,1/u,0),S(g.tex,b,1/u,0),S(b.tex,g,1/u,0),S(g.tex,b,0,1/h),S(b.tex,g,0,1/h),S(g.tex,b,0,1/h),this.fullscreenPass(e,this.finalProg,m.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,p),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:m.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),f()}}};var Js=class{host;shadowBakes=new WeakMap;liveTexes=new Set;gpuShadowBaker=null;constructor(e){this.host=e}render(e){let t=Pf(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}${Ss(e)}`:r,i=e instanceof re?`v${e.contentVersion}`:"",s=[kf(t),e.raw.type,e.matrix.join(","),e.dims.x,e.dims.y,o,i].join(";");if(ou()){this.gpuShadowBaker||(this.gpuShadowBaker=new Zs(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=Af(e,t);if(!c)return;let u=ke(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 Pm=(n,e,t,r)=>{let o=[];for(let w of n){if(!Number.isFinite(w.x)||!Number.isFinite(w.y))return null;let T=o[o.length-1];T&&T.x===w.x&&T.y===w.y||o.push({x:w.x,y:w.y})}if(e&&o.length>1){let w=o[0],T=o[o.length-1];w.x===T.x&&w.y===T.y&&o.pop()}let i=o.length;if(i<(e?3:2))return null;let s=e?i:i-1,a=[],l=[];for(let w=0;w<s;w++){let T=o[w],E=o[(w+1)%i],P=Math.hypot(E.x-T.x,E.y-T.y);if(!(P>1e-12))return null;a.push((E.x-T.x)/P),l.push((E.y-T.y)/P)}let c=[],u=[],h=[],d=[];for(let w=0;w<i;w++){let T=o[w],E=e||w>0,P=e||w<s;if(!E||!P){let D=E?w-1:0,I=-l[D],H=a[D];c.push(T.x+t*I),u.push(T.y+t*H),h.push(T.x-t*I),d.push(T.y-t*H);continue}let A=a[(w-1+s)%s],k=l[(w-1+s)%s],O=a[w%s],F=l[w%s],W=-(A*O+k*F),X=Math.sqrt(Math.max(0,(1-W)/2));if(1/Math.max(X,1e-300)>r*(1+1e-9))return null;let _=A*F-k*O;for(let D of[1,-1]){let I=o[(w-1+i)%i].x+t*D*-k,H=o[(w-1+i)%i].y+t*D*A,z=T.x+t*D*-F,U=T.y+t*D*O;if(Math.abs(_)<1e-12){let j=T.x+t*D*-F,Q=T.y+t*D*O;if(!Number.isFinite(j)||!Number.isFinite(Q))return null;D===1?(c.push(j),u.push(Q)):(h.push(j),d.push(Q));continue}let $=z-I,K=U-H,G=($*F-K*O)/_,Z=I+G*A,B=H+G*k;if(!Number.isFinite(Z)||!Number.isFinite(B))return null;D===1?(c.push(Z),u.push(B)):(h.push(Z),d.push(B))}}for(let w=0;w<s;w++){let T=w+1;if((c[T]-c[w])*a[w]+(u[T]-u[w])*l[w]<=0||(h[T]-h[w])*a[w]+(d[T]-d[w])*l[w]<=0)return null}h.reverse(),d.reverse();let f=2*i;if(f>64||f<3)return null;let m=[],p=[],g=(w,T,E)=>{for(let P=0;P+1<w.length;P++)m.push(w[P],w[P+1]),p.push(T[P],T[P+1]);E&&w.length>2&&(m.push(w[w.length-1],w[0]),p.push(T[T.length-1],T[0]))};g(c,u,e),g(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 b=m.length/2;if(b!==f||b>64)return null;let x=(w,T,E,P,A,k)=>(E-w)*(k-T)-(P-T)*(A-w),y=(w,T)=>{let E=m[w*2],P=p[w*2],A=m[w*2+1],k=p[w*2+1],O=m[T*2],F=p[T*2],W=m[T*2+1],X=p[T*2+1];if(E===A&&P===k||O===W&&F===X)return!1;let _=x(E,P,A,k,O,F),D=x(E,P,A,k,W,X),I=x(O,F,W,X,E,P),H=x(O,F,W,X,A,k);return(_>0&&D<0||_<0&&D>0)&&(I>0&&H<0||I<0&&H>0)};for(let w=0;w<b;w++)for(let T=w+2;T<b;T++)if(y(w,T))return null;let S=new Float32Array(b*4),v=0,M=0,C=0,R=0;for(let w=0;w<b;w++)S[w*4]=m[w*2],S[w*4+1]=p[w*2],S[w*4+2]=m[w*2+1],S[w*4+3]=p[w*2+1],v=Math.max(v,Math.abs(m[w*2]),Math.abs(m[w*2+1])),M=Math.max(M,Math.abs(p[w*2]),Math.abs(p[w*2+1]));for(let w of o)C=Math.max(C,Math.abs(w.x)),R=Math.max(R,Math.abs(w.y));return!(C>0)||!(R>0)?null:{segments:{data:S,count:b,hash:Lr(S)},marginX:v-C,marginY:M-R}};var E0=1,M0=2,C0=3,km=4,R0={butt:0,round:1,square:2},P0=1.5,k0=(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],g=n[(m+1)%n.length],b=g.x-p.x,x=g.y-p.y;b*b+x*x<1e-18||(o.push(p.x),i.push(p.y),s.push(g.x),a.push(g.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:Lr(c)},marginX:u+t-d,marginY:h+t-f}},Am=(n,e,t,r)=>{let o=null;if(e.dashArray){if(!Go()||e.dashArray.length>2||e.lineCap!=="butt"&&e.lineCap!=="square"||e.uniform)return null;let E=e.dashArray[0],P=e.dashArray.length>1?e.dashArray[1]:E;E+P>0&&(o=[E,E+P,e.dashOffset])}if(e.alignment!=="center")return null;let i=n.raw,s=J(i),a=n.dims;if(s!==L.LINE&&(!(a.x>0)||!(a.y>0)))return null;let l=s===L.LINE?M0:s===L.ELLIPSE||s===L.CIRCLE?C0:s===L.POLYGON||s===L.POLYLINE||s===L.TRIANGLE?km:E0,c=e.width/2,u,h=null,d=c,f=c,m=0;if(s===L.RECT||s===L.FABRICRECT){let E=rt(i,a.x,a.y),P=E?.rx??0,A=E?.ry??0;if(P<1e-4&&A<1e-4&&(e.lineJoin!=="miter"||e.miterLimit<P0)||o&&Math.abs(P-A)>=1e-4)return null;u=[P,A,a.x/2,a.y/2]}else if(s===L.LINE){let E=Number(i.x1),P=Number(i.y1),A=Number(i.x2),k=Number(i.y2);if(!Number.isFinite(E)||!Number.isFinite(P)||!Number.isFinite(A)||!Number.isFinite(k)||E===A&&P===k)return null;u=[E,P,A,k]}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(!au()||o||e.uniform)return null;let E=s!==L.POLYLINE,P;if(s===L.TRIANGLE){let I=a.x,H=a.y;if(!(I>0)||!(H>0))return null;P=[{x:0,y:-H/2},{x:I/2,y:H/2},{x:-I/2,y:H/2}]}else{let I=Array.isArray(i.points)?i.points:[];if(I.length<(E?3:2))return null;P=[];for(let H of I){let z=Number(H?.x),U=Number(H?.y);if(!Number.isFinite(z)||!Number.isFinite(U))return null;P.push({x:z,y:U})}}let A=1/0,k=1/0,O=-1/0,F=-1/0;for(let I of P)A>I.x&&(A=I.x),k>I.y&&(k=I.y),O<I.x&&(O=I.x),F<I.y&&(F=I.y);let W=(A+O)/2,X=(k+F)/2,_=P.map(I=>({x:I.x-W,y:I.y-X})),D=0;if(e.lineJoin==="round"){if(!E&&e.lineCap!=="round")return null;let I=k0(_,E,c);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=Pm(_,E,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===km?m:R0[e.lineCap]??0,g=l+(p<<3)+(e.uniform?64:0),b=n.matrix,x=Math.max(1e-6,t*r),y=Math.hypot(b[0],b[1]),S=Math.hypot(b[2],b[3]),v=Math.max(Math.min(y,S),1e-6),M=1/(v*x),C=(e.uniform?c/v:d)+4*M,R=(e.uniform?c/v:f)+4*M,w=a.x+2*C,T=a.y+2*R;return!Number.isFinite(w)||!Number.isFinite(T)?null:{halfW:c,code:-g,shape:u,quadW:w,quadH:T,dash:o,segments:h}};var A0=2,N0=4,ta={butt:0,round:1,square:2},L0=(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}},Nm=n=>{if(!n.dashArray)return{dash:null,ok:!0};if(!Go())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}},na=(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:-(A0+(i<<3)+(s?64:0)),quadW:f,quadH:m,dash:a,segments:null}},I0=(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:-(N0+8),quadW:o-t+2*e,quadH:i-r+2*e,dash:null,segments:{data:c,count:3,hash:Lr(c)}}},_0=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}},Lm=(n,e,t,r,o)=>{let i=J(n);if(i!==L.ARROW&&i!==L.DIMENSION||!lu())return null;let s=_0(n);if(!s||e.alignment!=="center")return null;let{aa:a,minAxis:l}=L0(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 w=Number(n.arrowWidth)||15,T=Number(n.arrowHeight)||22.5,E=n.arrowType==="start"||n.arrowType==="both"?n.arrowType:"end",P=Math.sqrt(u),A=w*P,k=T*P,O=E==="start"||E==="both",F=E==="end"||E==="both",{dash:W,ok:X}=Nm(e);if(!X)return null;let _=s.x1+h*(O?k:0),D=s.y1+d*(O?k:0),I=s.x2-h*(F?k:0),H=s.y2-d*(F?k:0),U=[na(_,D,I,H,u/2,ta[e.lineCap]??0,e.uniform,W,c,l)],$=(K,G,Z,B)=>{let j=K-Z*k,Q=G-B*k;return I0([{x:K,y:G},{x:j+-B*(A/2),y:Q+Z*(A/2)},{x:j- -B*(A/2),y:Q-Z*(A/2)}],c)};return F&&U.push($(s.x2,s.y2,h,d)),O&&U.push($(s.x1,s.y1,-h,-d)),{pieces:U,text:null}}let{dash:f,ok:m}=Nm(e);if(!m)return null;let p=na(s.x1,s.y1,s.x2,s.y2,u/2,ta[e.lineCap]??0,e.uniform,f,c,l),g=Number(n.textFontSize)||50,b=-d,x=h,y=g/2,S=na(s.x1-b*y,s.y1-x*y,s.x1+b*y,s.y1+x*y,u/2,ta.round,!1,null,c,l),v=na(s.x2-b*y,s.y2-x*y,s.x2+b*y,s.y2+x*y,u/2,ta.round,!1,null,c,l),M=typeof n.text=="string"&&n.text.trim()?n.text:"50cm",C=Number(n.textPadding)||4,R=g+u/2+5;return{pieces:[p,S,v],text:{text:M,fontPx:g,w:0,h:g+C*2,cx:(s.x1+s.x2)/2+b*R,cy:(s.y1+s.y2)/2+x*R,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:C}}};var ra=class{host;frame;settle;liveTexes=new Set;strokeBakes=new WeakMap;lineDecoTextBakes=new WeakMap;constructor(e,t,r=new Gt(()=>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=Lm(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:Y(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=Am(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=[Pu(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?ei(s,this.host.zoom,this.host.dpr,or(this.host),u.sceneW,u.sceneH):null;if(!js(u.k,l,h)||d&&(d.lx!==u.lx||d.ly!==u.ly)){if(_r(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=Au(e,{zoom:this.host.zoom,dpr:this.host.dpr,vpt:or(this.host)});if(!h){this.strokeBakes.set(e,void 0);return}let d=ke(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=zr(r,t.text)+t.pad*2;if(!(o>0)||!(t.h>0))return;let i=e.worldScale,s=Qt(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=ke(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(Y(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 D0=new Set([...Hn,L.RECT,L.FABRICRECT]),F0=(n,e,t,r)=>[n,e[0],e[1],e[2],e[3],t,r].join(";"),O0=(n,e,t,r,o)=>{let i=Math.round(e),s=Math.round(t);if(i===0&&s===0)return n;let a=[...n];return a[6]-=i/r,a[7]-=s/o,a},Im=(n,e)=>{if(!(n.x>0)||!(n.y>0))return null;let t=n.x/2,r=n.y/2,o=1/0,i=1/0,s=-1/0,a=-1/0;for(let[l,c]of[[-t,-r],[t,-r],[t,r],[-t,r]]){let u=e[0]*l+e[2]*c+e[4],h=e[1]*l+e[3]*c+e[5];o>u&&(o=u),i>h&&(i=h),s<u&&(s=u),a<h&&(a=h)}return{minX:o,minY:i,maxX:s,maxY:a}},B0=(n,e,t,r)=>{let o=Im(n,e);return o?o.maxX>=0&&o.minX<=t&&o.maxY>=0&&o.minY<=r:!1},H0=(n,e,t)=>{let r=Math.min(n.minX,0),o=Math.min(n.minY,0);return{bx0:r,by0:o,bw:Math.max(n.maxX,e)-r,bh:Math.max(n.maxY,t)-o}},W0=(n,e,t)=>[e/n.bw,0,0,0,-t/n.bh,0,-n.bx0/n.bw,(t-n.by0)/n.bh,1],Ec=n=>{let e=n.raw.clipPath;return!e||typeof e!="object"||Array.isArray(e)||!D0.has(J(e))?null:e},oa=class{host;gpu;clipBakes=new WeakMap;constructor(e,t){this.host=e,this.gpu=t}mask(e){let t=Ec(e);if(!t)return null;let r=ct(t);if(!r)return null;let i=t.absolutePositioned===!0?r.matrix:Y(e.matrix,r.matrix),s=this.host.canvasEl.width,a=this.host.canvasEl.height,l=or(this.host);if(iu()){let p=this.gpu.fx,g=Y([this.host.dpr,0,0,this.host.dpr,0,0],l),b=r instanceof un||!r.dims.x||!r.dims.y?null:rt(r.raw,r.dims.x,r.dims.y),x=r instanceof un?r.shapeMesh:b?mu(r.dims.x,r.dims.y,b.rx,b.ry):null,y=x||!r.dims.x||!r.dims.y?null:{x:r.dims.x,y:r.dims.y},S=p.renderClipMask(this.host.gl,x,y,{m:Y(g,i),w:s,h:a},s,a);return S?{tex:S,maskInv:[1,0,0,0,1,0,0,0,1],coversHost:!1,invert:t.inverted===!0}:null}let c=JSON.stringify({...t,objects:void 0}),u=Y([this.host.dpr,0,0,this.host.dpr,0,0],l),h=Y(u,i);if(!B0(r.dims,h,s,a))return null;let d=F0(c,h,s,a),f=this.clipBakes.get(e);if(f&&f.sig!==d&&(this.host.gl.deleteTexture(f.mask.tex),f=void 0),!f){let p=Im(r.dims,h);if(!p)return null;let g=H0(p,s,a);if(!(g.bw>0)||!(g.bh>0)||g.bw>8192||g.bh>8192)return null;let b=document.createElement("canvas");b.width=Math.ceil(g.bw),b.height=Math.ceil(g.bh);let x=b.getContext("2d");if(!x||(x.setTransform(h[0],h[1],h[2],h[3],h[4]-g.bx0,h[5]-g.by0),x.fillStyle="#ffffff",!Xn(x,r)))return null;x.fill();let y=ke(this.host.gl,b);if(!y)return null;f={sig:d,panX:h[4],panY:h[5],bw:g.bw,bh:g.bh,mask:{tex:y,maskInv:W0(g,s,a),coversHost:!1,invert:t.inverted===!0}},this.clipBakes.set(e,f)}let m=O0(f.mask.maskInv,h[4]-f.panX,h[5]-f.panY,f.bw,f.bh);return m===f.mask.maskInv?f.mask:{...f.mask,maskInv:m}}invalidate(){this.clipBakes=new WeakMap}};var ko=(n,e,t,r,o=0,i=0)=>{let s=e.raw,a=o||i?Y(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,g=(d+f)/2-c,b=a;return{matrix:[b[0],b[1],b[2],b[3],b[0]*p+b[2]*g+b[4],b[1]*p+b[3]*g+b[5]],w:h-u,h:f-d,uv:m}};var _m=new WeakMap,G0=n=>{let e=_m.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=Y(r,[1,0,0,1,t.x,t.y])),t.angle&&(r=Y(r,At({angle:-t.angle}))),r}}),_m.set(n,e)),e},ia=class{host;frame;gpu;getPuzzleBox;psdBakes=new WeakMap;settle;cpuTexes=new Set;constructor(e,t,r,o,i=new Gt(()=>e.requestRenderAll())){this.host=e,this.frame=t,this.gpu=r,this.getPuzzleBox=o,this.settle=i}noteVptScaleChange(){this.settle.noteInteraction()}render(e,t){let r=e.isTextType&&e instanceof xe,o=r&&$t(e)&&e!==this.host.editingNode&&!!e.imageEl,i=e instanceof le;if(!e.isImageType&&e.typeKey!==L.PATH&&!r&&!i||t==="above"&&!e.isImageType&&!r&&!i||e.isImageType&&!(e instanceof re)&&!e.imageEl)return;let s=Jt(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]):typeof e.raw.src=="string"?`${e.raw.src}|${a}${Ss(e)}`:a,c=e instanceof re?`v${e.contentVersion}`:"",u=r&&!o?Math.max(1,Qt(this.host.zoom*this.host.dpr*Math.max(e.worldScale.x,e.worldScale.y))):1,h=o?G0(e):e,d=[Cn(s),h.matrix.join(","),h.dims.x,h.dims.y,l,c].join(";"),f=this.psdBakes.get(e);if(f&&f.sigBase!==d){f.shadow&&this.deleteBakeTex(f.shadow.tex);for(let m of f.fills)this.deleteBakeTex(m.tex);for(let m of f.strokes)this.deleteBakeTex(m.tex);f=void 0}if(f&&f.bucket!==u){if(_r(this.host,this.settle,this.frame,performance.now())){this.frame.bakeMore=!0,this.renderPsdBakeQuads(h,f,t);return}f.shadow&&this.deleteBakeTex(f.shadow.tex);for(let m of f.fills)this.deleteBakeTex(m.tex);for(let m of f.strokes)this.deleteBakeTex(m.tex);f=void 0}if(!f){let m=this.host.gl,p=e instanceof le?e.imageEl:e instanceof re?e.paintSource:e.isImageType||o?e.imageEl:null,g=p?1:u,b=p?1:Math.min(Math.max(2,u),vs(e)),x=p??(r?wo(e,g):null),y=p??(r?wo(e,b):null),S=p?e.cropRect:null,v=Aa()||Na()?this.gpu.fx:null,M=!x&&!i,C=null;if(Aa()&&v){let T=v.bakeDropShadows(m,h,s.dropShadows,{source:x,sourceRect:S,rs:g,pathMode:M,sig:d,viewportW:this.host.canvasEl.width,viewportH:this.host.canvasEl.height});T&&(C={tex:T.tex,w:T.w/g,h:T.h/g})}if(!C){let T=x?ws(h,s.dropShadows,x,g,S):_f(e,s.dropShadows);if(T){let E=ke(m,T.canvas,{mipmap:!0});E&&(this.cpuTexes.add(E),C={tex:E,w:T.quadW,h:T.quadH})}}let R=[];if(x)for(let T of s.solidFills){if(Na()&&v&&T.kind==="solid"&&!S){let A=Math.max(1,Math.ceil(h.dims.x*g)),k=Math.max(1,Math.ceil(h.dims.y*g)),O=v.uploadLocalSource(m,h,x,`${d}|fillsrc`,A,k),F=O?v.bakeSolidFill(m,h,T,O,A,k,d,`fill${R.length}`,this.host.canvasEl.width,this.host.canvasEl.height):null;if(F){R.push({tex:F,dx:T.offset.x,dy:T.offset.y});continue}}let E=kr(h,T,x,g,S);if(!E)continue;let P=ke(m,E);P&&(this.cpuTexes.add(P),R.push({tex:P,dx:T.offset.x,dy:T.offset.y}))}let w=[];if(y)for(let T of wn(h,s.strokes,y,!r&&!i,b,S,r&&!o)){let E=ke(m,T.canvas);E&&(this.cpuTexes.add(E),w.push({tex:E,w:T.quadW,h:T.quadH,dx:T.dx,dy:T.dy}))}f={sigBase:d,bucket:u,shadow:C,fills:R,strokes:w},this.psdBakes.set(e,f)}this.renderPsdBakeQuads(h,f,t)}renderPsdBakeQuads(e,t,r){let o=e.renderOpacity,s=e instanceof le?1:o;if(r==="below"){if(t.shadow){let a=e.matrix;this.host.batch.pushQuad([1,0,0,1,a[4],a[5]],t.shadow.w,t.shadow.h,[1,1,1,s],t.shadow.tex)}}else{for(let a of t.fills){let l=ko(this.getPuzzleBox(),e,e.dims.x,e.dims.y,a.dx,a.dy);l&&this.host.batch.pushQuad(l.matrix,l.w,l.h,[1,1,1,s],a.tex,l.uv)}for(let a of t.strokes){let l=ko(this.getPuzzleBox(),e,a.w,a.h,a.dx,a.dy);l&&this.host.batch.pushQuad(l.matrix,l.w,l.h,[1,1,1,o],a.tex,l.uv)}}}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 X0=`#version 300 es
921
+ }`,L0=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 re?`v${n.contentVersion}`:"";return`${n.raw.type};${t};${r}`},I0=(n,e,t,r)=>{let o=n.matrix;return[L0(n),n.dims.x,n.dims.y,_0(e),t,r,o[0].toFixed(4),o[1].toFixed(4),o[2].toFixed(4),o[3].toFixed(4)].join(";")},_0=n=>[n.rgba.join(","),n.blur,n.offsetX,n.offsetY,n.nonScaling?1:0].join("|"),Js=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,Nm,A0),this.finalProg=this.finalProg??this.compile(e,Nm,N0),!!(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),ys(l,t,"#ffffff");let u=ke(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=Ht(r,t.raw.scaleX??1,t.raw.scaleY??1),l=xs(a)+(t.isTextType?Math.ceil((t.raw.fontSize??40)*.5):0),c=oc(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=I0(t,r,u,h),f=Pn(e);try{let m=this.targets.get(t);if(m&&m.sig!==d&&(e.deleteFramebuffer(m.rt.fb),e.deleteTexture(m.rt.tex),this.liveRts.delete(m.rt),this.epoch?.bump("gpu-shadow-rebake"),m=void 0),!m){let v=this.ensureTarget(e,null,u,h);if(!v)return null;m={sig:d,rt:v},this.targets.set(t,m)}let p=this.silhouette(e,t,d,u,h);if(!p)return null;this.b1=this.ensureTarget(e,this.b1,u,h),this.b2=this.ensureTarget(e,this.b2,u,h);let g=this.b1,b=this.b2;if(!g||!b)return null;let x=a.blur/2,y=x<.05?1:Math.max(1,Math.min(64,Math.round(Math.sqrt(4*x*x+1)))),S=(v,T,C,R)=>{this.fullscreenPass(e,this.blurProg,T,w=>{e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,v),e.uniform1i(e.getUniformLocation(w,"uSrc"),0),e.uniform2f(e.getUniformLocation(w,"uDir"),C,R),e.uniform1i(e.getUniformLocation(w,"uBoxW"),y)})};return S(p,g,1/u,0),S(g.tex,b,1/u,0),S(b.tex,g,1/u,0),S(g.tex,b,0,1/h),S(b.tex,g,0,1/h),S(g.tex,b,0,1/h),this.fullscreenPass(e,this.finalProg,m.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,p),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:m.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),f()}}};var ea=class{host;shadowBakes=new WeakMap;liveTexes=new Set;gpuShadowBaker=null;constructor(e){this.host=e}render(e){let t=Lf(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}${ws(e)}`:r,i=e instanceof re?`v${e.contentVersion}`:"",s=[If(t),e.raw.type,e.matrix.join(","),e.dims.x,e.dims.y,o,i].join(";");if(lu()){this.gpuShadowBaker||(this.gpuShadowBaker=new Js(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=_f(e,t);if(!c)return;let u=ke(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 Lm=(n,e,t,r)=>{let o=[];for(let w of n){if(!Number.isFinite(w.x)||!Number.isFinite(w.y))return null;let E=o[o.length-1];E&&E.x===w.x&&E.y===w.y||o.push({x:w.x,y:w.y})}if(e&&o.length>1){let w=o[0],E=o[o.length-1];w.x===E.x&&w.y===E.y&&o.pop()}let i=o.length;if(i<(e?3:2))return null;let s=e?i:i-1,a=[],l=[];for(let w=0;w<s;w++){let E=o[w],M=o[(w+1)%i],P=Math.hypot(M.x-E.x,M.y-E.y);if(!(P>1e-12))return null;a.push((M.x-E.x)/P),l.push((M.y-E.y)/P)}let c=[],u=[],h=[],d=[];for(let w=0;w<i;w++){let E=o[w],M=e||w>0,P=e||w<s;if(!M||!P){let D=M?w-1:0,I=-l[D],H=a[D];c.push(E.x+t*I),u.push(E.y+t*H),h.push(E.x-t*I),d.push(E.y-t*H);continue}let A=a[(w-1+s)%s],k=l[(w-1+s)%s],O=a[w%s],F=l[w%s],W=-(A*O+k*F),X=Math.sqrt(Math.max(0,(1-W)/2));if(1/Math.max(X,1e-300)>r*(1+1e-9))return null;let _=A*F-k*O;for(let D of[1,-1]){let I=o[(w-1+i)%i].x+t*D*-k,H=o[(w-1+i)%i].y+t*D*A,z=E.x+t*D*-F,U=E.y+t*D*O;if(Math.abs(_)<1e-12){let j=E.x+t*D*-F,Q=E.y+t*D*O;if(!Number.isFinite(j)||!Number.isFinite(Q))return null;D===1?(c.push(j),u.push(Q)):(h.push(j),d.push(Q));continue}let $=z-I,K=U-H,G=($*F-K*O)/_,J=I+G*A,B=H+G*k;if(!Number.isFinite(J)||!Number.isFinite(B))return null;D===1?(c.push(J),u.push(B)):(h.push(J),d.push(B))}}for(let w=0;w<s;w++){let E=w+1;if((c[E]-c[w])*a[w]+(u[E]-u[w])*l[w]<=0||(h[E]-h[w])*a[w]+(d[E]-d[w])*l[w]<=0)return null}h.reverse(),d.reverse();let f=2*i;if(f>64||f<3)return null;let m=[],p=[],g=(w,E,M)=>{for(let P=0;P+1<w.length;P++)m.push(w[P],w[P+1]),p.push(E[P],E[P+1]);M&&w.length>2&&(m.push(w[w.length-1],w[0]),p.push(E[E.length-1],E[0]))};g(c,u,e),g(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 b=m.length/2;if(b!==f||b>64)return null;let x=(w,E,M,P,A,k)=>(M-w)*(k-E)-(P-E)*(A-w),y=(w,E)=>{let M=m[w*2],P=p[w*2],A=m[w*2+1],k=p[w*2+1],O=m[E*2],F=p[E*2],W=m[E*2+1],X=p[E*2+1];if(M===A&&P===k||O===W&&F===X)return!1;let _=x(M,P,A,k,O,F),D=x(M,P,A,k,W,X),I=x(O,F,W,X,M,P),H=x(O,F,W,X,A,k);return(_>0&&D<0||_<0&&D>0)&&(I>0&&H<0||I<0&&H>0)};for(let w=0;w<b;w++)for(let E=w+2;E<b;E++)if(y(w,E))return null;let S=new Float32Array(b*4),v=0,T=0,C=0,R=0;for(let w=0;w<b;w++)S[w*4]=m[w*2],S[w*4+1]=p[w*2],S[w*4+2]=m[w*2+1],S[w*4+3]=p[w*2+1],v=Math.max(v,Math.abs(m[w*2]),Math.abs(m[w*2+1])),T=Math.max(T,Math.abs(p[w*2]),Math.abs(p[w*2+1]));for(let w of o)C=Math.max(C,Math.abs(w.x)),R=Math.max(R,Math.abs(w.y));return!(C>0)||!(R>0)?null:{segments:{data:S,count:b,hash:Ir(S)},marginX:v-C,marginY:T-R}};var D0=1,F0=2,O0=3,Im=4,B0={butt:0,round:1,square:2},H0=1.5,W0=(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],g=n[(m+1)%n.length],b=g.x-p.x,x=g.y-p.y;b*b+x*x<1e-18||(o.push(p.x),i.push(p.y),s.push(g.x),a.push(g.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:Ir(c)},marginX:u+t-d,marginY:h+t-f}},_m=(n,e,t,r)=>{let o=null;if(e.dashArray){if(!Xo()||e.dashArray.length>2||e.lineCap!=="butt"&&e.lineCap!=="square"||e.uniform)return null;let M=e.dashArray[0],P=e.dashArray.length>1?e.dashArray[1]:M;M+P>0&&(o=[M,M+P,e.dashOffset])}if(e.alignment!=="center")return null;let i=n.raw,s=ee(i),a=n.dims;if(s!==L.LINE&&(!(a.x>0)||!(a.y>0)))return null;let l=s===L.LINE?F0:s===L.ELLIPSE||s===L.CIRCLE?O0:s===L.POLYGON||s===L.POLYLINE||s===L.TRIANGLE?Im:D0,c=e.width/2,u,h=null,d=c,f=c,m=0;if(s===L.RECT||s===L.FABRICRECT){let M=ot(i,a.x,a.y),P=M?.rx??0,A=M?.ry??0;if(P<1e-4&&A<1e-4&&(e.lineJoin!=="miter"||e.miterLimit<H0)||o&&Math.abs(P-A)>=1e-4)return null;u=[P,A,a.x/2,a.y/2]}else if(s===L.LINE){let M=Number(i.x1),P=Number(i.y1),A=Number(i.x2),k=Number(i.y2);if(!Number.isFinite(M)||!Number.isFinite(P)||!Number.isFinite(A)||!Number.isFinite(k)||M===A&&P===k)return null;u=[M,P,A,k]}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(!hu()||o||e.uniform)return null;let M=s!==L.POLYLINE,P;if(s===L.TRIANGLE){let I=a.x,H=a.y;if(!(I>0)||!(H>0))return null;P=[{x:0,y:-H/2},{x:I/2,y:H/2},{x:-I/2,y:H/2}]}else{let I=Array.isArray(i.points)?i.points:[];if(I.length<(M?3:2))return null;P=[];for(let H of I){let z=Number(H?.x),U=Number(H?.y);if(!Number.isFinite(z)||!Number.isFinite(U))return null;P.push({x:z,y:U})}}let A=1/0,k=1/0,O=-1/0,F=-1/0;for(let I of P)A>I.x&&(A=I.x),k>I.y&&(k=I.y),O<I.x&&(O=I.x),F<I.y&&(F=I.y);let W=(A+O)/2,X=(k+F)/2,_=P.map(I=>({x:I.x-W,y:I.y-X})),D=0;if(e.lineJoin==="round"){if(!M&&e.lineCap!=="round")return null;let I=W0(_,M,c);if(!I)return null;h=I.segments,d=I.marginX,f=I.marginY}else if(e.lineJoin==="miter"){if(!M&&e.lineCap!=="butt")return null;let I=Lm(_,M,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===Im?m:B0[e.lineCap]??0,g=l+(p<<3)+(e.uniform?64:0),b=n.matrix,x=Math.max(1e-6,t*r),y=Math.hypot(b[0],b[1]),S=Math.hypot(b[2],b[3]),v=Math.max(Math.min(y,S),1e-6),T=1/(v*x),C=(e.uniform?c/v:d)+4*T,R=(e.uniform?c/v:f)+4*T,w=a.x+2*C,E=a.y+2*R;return!Number.isFinite(w)||!Number.isFinite(E)?null:{halfW:c,code:-g,shape:u,quadW:w,quadH:E,dash:o,segments:h}};var G0=2,X0=4,na={butt:0,round:1,square:2},z0=(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}},Dm=n=>{if(!n.dashArray)return{dash:null,ok:!0};if(!Xo())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}},ra=(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:-(G0+(i<<3)+(s?64:0)),quadW:f,quadH:m,dash:a,segments:null}},Y0=(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:-(X0+8),quadW:o-t+2*e,quadH:i-r+2*e,dash:null,segments:{data:c,count:3,hash:Ir(c)}}},U0=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}},Fm=(n,e,t,r,o)=>{let i=ee(n);if(i!==L.ARROW&&i!==L.DIMENSION||!du())return null;let s=U0(n);if(!s||e.alignment!=="center")return null;let{aa:a,minAxis:l}=z0(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 w=Number(n.arrowWidth)||15,E=Number(n.arrowHeight)||22.5,M=n.arrowType==="start"||n.arrowType==="both"?n.arrowType:"end",P=Math.sqrt(u),A=w*P,k=E*P,O=M==="start"||M==="both",F=M==="end"||M==="both",{dash:W,ok:X}=Dm(e);if(!X)return null;let _=s.x1+h*(O?k:0),D=s.y1+d*(O?k:0),I=s.x2-h*(F?k:0),H=s.y2-d*(F?k:0),U=[ra(_,D,I,H,u/2,na[e.lineCap]??0,e.uniform,W,c,l)],$=(K,G,J,B)=>{let j=K-J*k,Q=G-B*k;return Y0([{x:K,y:G},{x:j+-B*(A/2),y:Q+J*(A/2)},{x:j- -B*(A/2),y:Q-J*(A/2)}],c)};return F&&U.push($(s.x2,s.y2,h,d)),O&&U.push($(s.x1,s.y1,-h,-d)),{pieces:U,text:null}}let{dash:f,ok:m}=Dm(e);if(!m)return null;let p=ra(s.x1,s.y1,s.x2,s.y2,u/2,na[e.lineCap]??0,e.uniform,f,c,l),g=Number(n.textFontSize)||50,b=-d,x=h,y=g/2,S=ra(s.x1-b*y,s.y1-x*y,s.x1+b*y,s.y1+x*y,u/2,na.round,!1,null,c,l),v=ra(s.x2-b*y,s.y2-x*y,s.x2+b*y,s.y2+x*y,u/2,na.round,!1,null,c,l),T=typeof n.text=="string"&&n.text.trim()?n.text:"50cm",C=Number(n.textPadding)||4,R=g+u/2+5;return{pieces:[p,S,v],text:{text:T,fontPx:g,w:0,h:g+C*2,cx:(s.x1+s.x2)/2+b*R,cy:(s.y1+s.y2)/2+x*R,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:C}}};var oa=class{host;frame;settle;liveTexes=new Set;strokeBakes=new WeakMap;lineDecoTextBakes=new WeakMap;constructor(e,t,r=new Gt(()=>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=Fm(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:Y(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=[Lu(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?ti(s,this.host.zoom,this.host.dpr,ir(this.host),u.sceneW,u.sceneH):null;if(!qs(u.k,l,h)||d&&(d.lx!==u.lx||d.ly!==u.ly)){if(An(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=_u(e,{zoom:this.host.zoom,dpr:this.host.dpr,vpt:ir(this.host)});if(!h){this.strokeBakes.set(e,void 0);return}let d=ke(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=zr(r,t.text)+t.pad*2;if(!(o>0)||!(t.h>0))return;let i=e.worldScale,s=Qt(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=ke(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(Y(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 $0=new Set([...Wn,L.RECT,L.FABRICRECT]),V0=(n,e,t,r)=>{let o=Math.hypot(e[0],e[1]),i=Math.hypot(e[2],e[3]),s=a=>Math.round(a*1e4)/1e4;return{sigBase:[n,s(e[0]/o),s(e[1]/o),s(e[2]/i),s(e[3]/i),t,r].join(";"),k:`${s(o)}×${s(i)}`}},j0=(n,e,t,r,o)=>{let i=(t.maxX-t.minX)/(n.maxX-n.minX||1),s=(t.maxY-t.minY)/(n.maxY-n.minY||1);return Bm({bx0:t.minX-(n.minX-e.bx0)*i,by0:t.minY-(n.minY-e.by0)*s,bw:e.bw*i,bh:e.bh*s},r,o)},Om=new WeakMap,q0=n=>{let e=Om.get(n);return e===void 0&&(e=JSON.stringify({...n,objects:void 0}),Om.set(n,e)),e},K0=(n,e,t,r,o)=>{let i=Math.round(e),s=Math.round(t);if(i===0&&s===0)return n;let a=[...n];return a[6]-=i/r,a[7]-=s/o,a},Ec=(n,e)=>{if(!(n.x>0)||!(n.y>0))return null;let t=n.x/2,r=n.y/2,o=1/0,i=1/0,s=-1/0,a=-1/0;for(let[l,c]of[[-t,-r],[t,-r],[t,r],[-t,r]]){let u=e[0]*l+e[2]*c+e[4],h=e[1]*l+e[3]*c+e[5];o>u&&(o=u),i>h&&(i=h),s<u&&(s=u),a<h&&(a=h)}return{minX:o,minY:i,maxX:s,maxY:a}},Q0=(n,e,t,r)=>{let o=Ec(n,e);return o?o.maxX>=0&&o.minX<=t&&o.maxY>=0&&o.minY<=r:!1},Z0=(n,e,t,r)=>{if(!n||!(n.right-n.left>0)||!(n.bottom-n.top>0))return!1;let o=1/0,i=1/0,s=-1/0,a=-1/0;for(let[l,c]of[[n.left,n.top],[n.right,n.top],[n.right,n.bottom],[n.left,n.bottom]]){let u=e[0]*l+e[2]*c+e[4],h=e[1]*l+e[3]*c+e[5];o>u&&(o=u),i>h&&(i=h),s<u&&(s=u),a<h&&(a=h)}return s>=0&&o<=t&&a>=0&&i<=r},J0=(n,e,t)=>{let r=Math.min(n.minX,0),o=Math.min(n.minY,0);return{bx0:r,by0:o,bw:Math.max(n.maxX,e)-r,bh:Math.max(n.maxY,t)-o}},Bm=(n,e,t)=>[e/n.bw,0,0,0,-t/n.bh,0,-n.bx0/n.bw,(t-n.by0)/n.bh,1],Mc=n=>{let e=n.raw.clipPath;return!e||typeof e!="object"||Array.isArray(e)||!$0.has(ee(e))?null:e},ia=class{host;gpu;frame;settle;clipBakes=new WeakMap;constructor(e,t,r,o){this.host=e,this.gpu=t,this.frame=r,this.settle=o}mask(e){let t=Mc(e);if(!t)return null;let r=ct(t);if(!r)return null;let i=t.absolutePositioned===!0?r.matrix:Y(e.matrix,r.matrix),s=this.host.canvasEl.width,a=this.host.canvasEl.height,l=ir(this.host);if(cu()){let g=this.gpu.fx,b=Y([this.host.dpr,0,0,this.host.dpr,0,0],l),x=r instanceof hn||!r.dims.x||!r.dims.y?null:ot(r.raw,r.dims.x,r.dims.y),y=r instanceof hn?r.shapeMesh:x?xu(r.dims.x,r.dims.y,x.rx,x.ry):null,S=y||!r.dims.x||!r.dims.y?null:{x:r.dims.x,y:r.dims.y},v=g.renderClipMask(this.host.gl,y,S,{m:Y(b,i),w:s,h:a},s,a);return v?{tex:v,maskInv:[1,0,0,0,1,0,0,0,1],coversHost:!1,invert:t.inverted===!0}:null}let c=q0(t),u=Y([this.host.dpr,0,0,this.host.dpr,0,0],l),h=Y(u,i);if(!Q0(r.dims,h,s,a)&&!Z0(e.bounds,u,s,a))return null;let{sigBase:d,k:f}=V0(c,h,s,a),m=this.clipBakes.get(e);if(m&&m.sigBase!==d&&(this.host.gl.deleteTexture(m.mask.tex),m=void 0),m&&m.k!==f){if(An(this.host,this.settle,this.frame,performance.now())){this.frame.bakeMore=!0;let g=Ec(r.dims,h);if(!g)return null;let b=j0(m.bb,m.dom,g,s,a);return{...m.mask,maskInv:b}}this.host.gl.deleteTexture(m.mask.tex),m=void 0}if(!m){let g=Ec(r.dims,h);if(!g)return null;let b=J0(g,s,a);if(!(b.bw>0)||!(b.bh>0)||b.bw>8192||b.bh>8192)return null;let x=document.createElement("canvas");x.width=Math.ceil(b.bw),x.height=Math.ceil(b.bh);let y=x.getContext("2d");if(!y||(y.setTransform(h[0],h[1],h[2],h[3],h[4]-b.bx0,h[5]-b.by0),y.fillStyle="#ffffff",!zn(y,r)))return null;y.fill(t.fillRule==="evenodd"?"evenodd":"nonzero");let S=ke(this.host.gl,x);if(!S)return null;m={sigBase:d,k:f,panX:h[4],panY:h[5],bb:g,dom:b,mask:{tex:S,maskInv:Bm(b,s,a),coversHost:!1,invert:t.inverted===!0}},this.clipBakes.set(e,m)}let p=K0(m.mask.maskInv,h[4]-m.panX,h[5]-m.panY,m.dom.bw,m.dom.bh);return p===m.mask.maskInv?m.mask:{...m.mask,maskInv:p}}invalidate(){this.clipBakes=new WeakMap}};var ko=(n,e,t,r,o=0,i=0)=>{let s=e.raw,a=o||i?Y(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,g=(d+f)/2-c,b=a;return{matrix:[b[0],b[1],b[2],b[3],b[0]*p+b[2]*g+b[4],b[1]*p+b[3]*g+b[5]],w:h-u,h:f-d,uv:m}};var Hm=new WeakMap,ev=n=>{let e=Hm.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=Y(r,[1,0,0,1,t.x,t.y])),t.angle&&(r=Y(r,At({angle:-t.angle}))),r}}),Hm.set(n,e)),e},sa=class{host;frame;gpu;getPuzzleBox;psdBakes=new WeakMap;settle;cpuTexes=new Set;constructor(e,t,r,o,i=new Gt(()=>e.requestRenderAll())){this.host=e,this.frame=t,this.gpu=r,this.getPuzzleBox=o,this.settle=i}noteVptScaleChange(){this.settle.noteInteraction()}render(e,t){let r=e.isTextType&&e instanceof ge,o=r&&$t(e)&&e!==this.host.editingNode&&!!e.imageEl,i=e instanceof le;if(!e.isImageType&&e.typeKey!==L.PATH&&!r&&!i||t==="above"&&!e.isImageType&&!r&&!i||e.isImageType&&!(e instanceof re)&&!e.imageEl)return;let s=Jt(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]):typeof e.raw.src=="string"?`${e.raw.src}|${a}${ws(e)}`:a,c=e instanceof re?`v${e.contentVersion}`:"",u=r&&!o?Math.max(1,Qt(this.host.zoom*this.host.dpr*Math.max(e.worldScale.x,e.worldScale.y))):1,h=o?ev(e):e,d=[Rn(s),h.matrix.join(","),h.dims.x,h.dims.y,l,c].join(";"),f=this.psdBakes.get(e);if(f&&f.sigBase!==d){f.shadow&&this.deleteBakeTex(f.shadow.tex);for(let m of f.fills)this.deleteBakeTex(m.tex);for(let m of f.strokes)this.deleteBakeTex(m.tex);f=void 0}if(f&&f.bucket!==u){if(An(this.host,this.settle,this.frame,performance.now())){this.frame.bakeMore=!0,this.renderPsdBakeQuads(h,f,t);return}f.shadow&&this.deleteBakeTex(f.shadow.tex);for(let m of f.fills)this.deleteBakeTex(m.tex);for(let m of f.strokes)this.deleteBakeTex(m.tex);f=void 0}if(!f){let m=this.host.gl,p=e instanceof le?e.imageEl:e instanceof re?e.paintSource:e.isImageType||o?e.imageEl:null,g=p?1:u,b=p?1:Math.min(Math.max(2,u),Ss(e)),x=p??(r?wo(e,g):null),y=p??(r?wo(e,b):null),S=p?e.cropRect:null,v=Aa()||Na()?this.gpu.fx:null,T=!x&&!i,C=null;if(Aa()&&v){let E=v.bakeDropShadows(m,h,s.dropShadows,{source:x,sourceRect:S,rs:g,pathMode:T,sig:d,viewportW:this.host.canvasEl.width,viewportH:this.host.canvasEl.height});E&&(C={tex:E.tex,w:E.w/g,h:E.h/g})}if(!C){let E=x?Ts(h,s.dropShadows,x,g,S):Bf(e,s.dropShadows);if(E){let M=ke(m,E.canvas,{mipmap:!0});M&&(this.cpuTexes.add(M),C={tex:M,w:E.quadW,h:E.quadH})}}let R=[];if(x)for(let E of s.solidFills){if(Na()&&v&&E.kind==="solid"&&!S){let A=Math.max(1,Math.ceil(h.dims.x*g)),k=Math.max(1,Math.ceil(h.dims.y*g)),O=v.uploadLocalSource(m,h,x,`${d}|fillsrc`,A,k),F=O?v.bakeSolidFill(m,h,E,O,A,k,d,`fill${R.length}`,this.host.canvasEl.width,this.host.canvasEl.height):null;if(F){R.push({tex:F,dx:E.offset.x,dy:E.offset.y});continue}}let M=Ar(h,E,x,g,S);if(!M)continue;let P=ke(m,M);P&&(this.cpuTexes.add(P),R.push({tex:P,dx:E.offset.x,dy:E.offset.y}))}let w=[];if(y)for(let E of Tn(h,s.strokes,y,!r&&!i,b,S,r&&!o)){let M=ke(m,E.canvas);M&&(this.cpuTexes.add(M),w.push({tex:M,w:E.quadW,h:E.quadH,dx:E.dx,dy:E.dy}))}f={sigBase:d,bucket:u,shadow:C,fills:R,strokes:w},this.psdBakes.set(e,f)}this.renderPsdBakeQuads(h,f,t)}renderPsdBakeQuads(e,t,r){let o=e.renderOpacity,s=e instanceof le?1:o;if(r==="below"){if(t.shadow){let a=e.matrix;this.host.batch.pushQuad([1,0,0,1,a[4],a[5]],t.shadow.w,t.shadow.h,[1,1,1,s],t.shadow.tex)}}else{for(let a of t.fills){let l=ko(this.getPuzzleBox(),e,e.dims.x,e.dims.y,a.dx,a.dy);l&&this.host.batch.pushQuad(l.matrix,l.w,l.h,[1,1,1,s],a.tex,l.uv)}for(let a of t.strokes){let l=ko(this.getPuzzleBox(),e,a.w,a.h,a.dx,a.dy);l&&this.host.batch.pushQuad(l.matrix,l.w,l.h,[1,1,1,o],a.tex,l.uv)}}}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 tv=`#version 300 es
922
922
  out vec2 vUv;
923
923
  void main() {
924
924
  vec2 p = vec2((gl_VertexID << 1) & 2, gl_VertexID & 2);
925
925
  vUv = p;
926
926
  gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);
927
- }`,z0=`#version 300 es
927
+ }`,nv=`#version 300 es
928
928
  precision mediump float;
929
929
  in vec2 vUv;
930
930
  uniform sampler2D uSrc;
@@ -938,7 +938,7 @@ if (k >= uBoxW) break;
938
938
  acc += texture(uSrc, vUv + uDir * (float(k) - float(uBoxW - 1) * 0.5)).a;
939
939
  }
940
940
  outColor = vec4(0.0, 0.0, 0.0, acc / float(uBoxW));
941
- }`,Y0=`#version 300 es
941
+ }`,rv=`#version 300 es
942
942
  precision mediump float;
943
943
  in vec2 vUv;
944
944
  uniform sampler2D uMask;
@@ -948,7 +948,7 @@ out vec4 outColor;
948
948
  void main() {
949
949
  float m = texture(uMask, vUv + uOffUv).a;
950
950
  outColor = vec4(uColor.rgb, m * uColor.a);
951
- }`,U0=`#version 300 es
951
+ }`,ov=`#version 300 es
952
952
  precision mediump float;
953
953
  in vec2 vUv;
954
954
  uniform sampler2D uSrc;
@@ -956,7 +956,7 @@ uniform vec4 uColor;
956
956
  out vec4 outColor;
957
957
  void main() {
958
958
  outColor = vec4(uColor.rgb, texture(uSrc, vUv).a * uColor.a);
959
- }`,$0=`#version 300 es
959
+ }`,iv=`#version 300 es
960
960
  precision mediump float;
961
961
  in vec2 vUv;
962
962
  uniform sampler2D uAcc;
@@ -966,19 +966,19 @@ out vec4 outColor;
966
966
  void main() {
967
967
  vec4 acc = texture(uAcc, vUv);
968
968
  outColor = vec4(acc.rgb, acc.a * mix(1.0, 1.0 - texture(uSil, vUv).a, uErase));
969
- }`,V0=`#version 300 es
969
+ }`,sv=`#version 300 es
970
970
  in vec2 aPos;
971
971
  uniform mat3 uM;
972
972
  uniform vec2 uSize;
973
973
  void main() {
974
974
  vec2 px = (uM * vec3(aPos, 1.0)).xy;
975
975
  gl_Position = vec4(px.x / uSize.x * 2.0 - 1.0, 1.0 - px.y / uSize.y * 2.0, 0.0, 1.0);
976
- }`,j0=`#version 300 es
976
+ }`,av=`#version 300 es
977
977
  precision mediump float;
978
978
  out vec4 outColor;
979
979
  void main() {
980
980
  outColor = vec4(1.0, 1.0, 1.0, 1.0);
981
- }`,q0=`#version 300 es
981
+ }`,lv=`#version 300 es
982
982
  precision mediump float;
983
983
  in vec2 vUv;
984
984
  uniform sampler2D uSrc;
@@ -990,16 +990,16 @@ vec4 b = texture(uSrc, vUv + vec2(uHalfTexel.x, -uHalfTexel.y));
990
990
  vec4 c = texture(uSrc, vUv + vec2(-uHalfTexel.x, uHalfTexel.y));
991
991
  vec4 d = texture(uSrc, vUv + uHalfTexel);
992
992
  outColor = (a + b + c + d) * 0.25;
993
- }`,sa=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 c of a.map.values())e.deleteFramebuffer(c.fb),e.deleteTexture(c.tex),this.liveTargetRts.delete(c);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=X0){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("[GpuFxPainter] shader:",e.getShaderInfoLog(u)),e.deleteShader(u),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,j0,V0),this.downProg=this.downProg??this.compile(e,q0),this.blurProg=this.blurProg??this.compile(e,z0),this.tintProg=this.tintProg??this.compile(e,Y0),this.fillProg=this.fillProg??this.compile(e,U0),this.finishProg=this.finishProg??this.compile(e,$0),!!(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 c=i<.05?1:Math.max(1,Math.min(64,Math.round(Math.sqrt(4*i*i+1)))),u=[this.ensureTarget(e,s,r,o),this.ensureTarget(e,a,r,o),this.ensureTarget(e,l,r,o)];if(!u[0]||!u[1]||!u[2])return null;let h=(d,f,m,p)=>this.pass(e,this.blurProg,f,g=>{e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,d),e.uniform1i(e.getUniformLocation(g,"uSrc"),0),e.uniform2f(e.getUniformLocation(g,"uDir"),m,p),e.uniform1i(e.getUniformLocation(g,"uBoxW"),c)});return h(t,u[0],1/r,0),h(u[0].tex,u[1],1/r,0),h(u[1].tex,u[0],1/r,0),h(u[0].tex,u[1],0,1/o),h(u[1].tex,u[0],0,1/o),h(u[0].tex,u[1],0,1/o),u[1].tex}source(e,t,r,o,i,s,a,l,c=null){let u=this.sources.get(t);if(u&&(u.sig!==r||!e.isTexture(u.tex))&&(e.deleteTexture(u.tex),u=void 0),!u){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=Xr(t,d),!Xn(d,t))return null;d.fill()}else if(s){let p=t.dims.x,g=t.dims.y;c?d.drawImage(s,c.sx,c.sy,c.sw,c.sh,-p/2,-g/2,p,g):d.drawImage(s,-p/2,-g/2,p,g)}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),u={sig:r,tex:m,w:o,h:i},this.sources.set(t,u)}return u.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}renderClipMask(e,t,r,o,i,s){if(this.restoreFb=e.getParameter(e.FRAMEBUFFER_BINDING),!this.ensurePrograms(e))return null;let a=2,l=o.w*a,c=o.h*a;if(!(l>0)||!(c>0)||l>8192||c>8192||(this.maskRt=this.ensureTarget(e,5,o.w,o.h)??this.maskRt,!this.maskRt||this.maskRt.w!==o.w||this.maskRt.h!==o.h))return null;if(!this.maskMsaa||this.maskMsaa.w!==l||this.maskMsaa.h!==c){this.maskMsaa&&(e.deleteFramebuffer(this.maskMsaa.fb),e.deleteRenderbuffer(this.maskMsaa.rb));let x=e.getParameter(e.MAX_SAMPLES),y=Math.min(8,Math.max(4,x)),S=e.createRenderbuffer();if(!S)return null;e.bindRenderbuffer(e.RENDERBUFFER,S),e.renderbufferStorageMultisample(e.RENDERBUFFER,y,e.RGBA8,l,c);let v=e.createFramebuffer();if(!v)return e.deleteRenderbuffer(S),null;e.bindFramebuffer(e.FRAMEBUFFER,v),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.RENDERBUFFER,S),e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindRenderbuffer(e.RENDERBUFFER,null),this.maskMsaa={fb:v,rb:S,samples:y,w:l,h:c}}let u=this.maskMsaa,h=this.ensureTarget(e,6,l,c);if(!h)return null;let d=t;if(!d&&r){let x=r.x/2,y=r.y/2;d={verts:new Float32Array([-x,-y,x,-y,x,y,-x,y]),triangles:new Uint32Array([0,1,2,0,2,3])}}if(!d)return null;let f=e.createVertexArray();if(!f)return null;e.bindVertexArray(f);let m=this.meshBufs.get(d);if(!m){let x=e.createBuffer(),y=e.createBuffer();if(!x||!y)return x&&e.deleteBuffer(x),y&&e.deleteBuffer(y),e.bindVertexArray(null),e.deleteVertexArray(f),null;e.bindBuffer(e.ARRAY_BUFFER,x),e.bufferData(e.ARRAY_BUFFER,d.verts,e.STATIC_DRAW),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,y),e.bufferData(e.ELEMENT_ARRAY_BUFFER,d.triangles,e.STATIC_DRAW),m={vbo:x,ibo:y,count:d.triangles.length},this.meshBufs.set(d,m)}e.bindBuffer(e.ARRAY_BUFFER,m.vbo);let p=e.getAttribLocation(this.maskProg,"aPos");e.enableVertexAttribArray(p),e.vertexAttribPointer(p,2,e.FLOAT,!1,0,0),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,m.ibo);let g=Rn(e);e.bindFramebuffer(e.FRAMEBUFFER,u.fb),e.viewport(0,0,l,c),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),e.useProgram(this.maskProg),e.disable(e.BLEND),e.uniformMatrix3fv(e.getUniformLocation(this.maskProg,"uM"),!1,[o.m[0]*a,o.m[1]*a,0,o.m[2]*a,o.m[3]*a,0,o.m[4]*a,o.m[5]*a,1]),e.uniform2f(e.getUniformLocation(this.maskProg,"uSize"),l,c),e.drawElements(e.TRIANGLES,m.count,e.UNSIGNED_INT,0),e.bindVertexArray(null),e.deleteVertexArray(f),e.bindFramebuffer(e.READ_FRAMEBUFFER,u.fb),e.bindFramebuffer(e.DRAW_FRAMEBUFFER,h.fb),e.blitFramebuffer(0,0,l,c,0,0,l,c,e.COLOR_BUFFER_BIT,e.NEAREST),e.bindFramebuffer(e.READ_FRAMEBUFFER,null),e.bindFramebuffer(e.DRAW_FRAMEBUFFER,null);let b=h.tex;return this.pass(e,this.downProg,this.maskRt,x=>{e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,b),e.uniform1i(e.getUniformLocation(x,"uSrc"),0),e.uniform2f(e.getUniformLocation(x,"uHalfTexel"),.25/o.w,.25/o.h)}),e.bindFramebuffer(e.READ_FRAMEBUFFER,null),e.bindFramebuffer(e.DRAW_FRAMEBUFFER,null),e.viewport(0,0,i,s),this.restore(e),g(),this.maskRt.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,c=4;for(let C of r){let R=s?{blur:C.blur,offX:C.offsetX,offY:C.offsetY}:Ht(Dm(C),a,l);c=Math.max(c,Math.ceil(R.blur*2+Math.max(Math.abs(R.offX),Math.abs(R.offY))+4))}let u=t.matrix,h=Math.abs(u[0])*t.dims.x+Math.abs(u[2])*t.dims.y,d=Math.abs(u[1])*t.dims.x+Math.abs(u[3])*t.dims.y,f=Math.ceil(h+c*2),m=Math.ceil(d+c*2),p=Math.ceil(f*i),g=Math.ceil(m*i);if(!(f>0)||!(m>0)||p>8192||g>8192)return null;let b=this.source(e,t,`${o.sig}|src`,p,g,o.source,i,s,o.sourceRect??null);if(!b)return null;let x=this.ensureTarget(e,3,p,g);if(!x)return null;let y=this.slot(e,t,o.sig,"shadow",p,g);if(!y)return null;let S=Rn(e);e.bindFramebuffer(e.FRAMEBUFFER,x.fb),e.viewport(0,0,p,g),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT);for(let C of r){let R=s?{blur:C.blur,offX:C.offsetX,offY:C.offsetY}:Ht(Dm(C),a,l),w=this.blurChain(e,b,p,g,R.blur*i/2,0,1,2);if(!w)return e.viewport(0,0,o.viewportW,o.viewportH),this.restore(e),S(),null;this.pass(e,this.tintProg,x,T=>{e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,w),e.uniform1i(e.getUniformLocation(T,"uMask"),0),e.uniform2f(e.getUniformLocation(T,"uOffUv"),-R.offX*i/p,-R.offY*i/g),e.uniform4f(e.getUniformLocation(T,"uColor"),C.rgba[0],C.rgba[1],C.rgba[2],C.rgba[3])},!0),this.pass(e,this.fillProg,x,T=>{e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,b),e.uniform1i(e.getUniformLocation(T,"uSrc"),0),e.uniform4f(e.getUniformLocation(T,"uColor"),1,1,1,1)},!0)}let v=x.tex,M=b;return this.pass(e,this.finishProg,y,C=>{e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,v),e.uniform1i(e.getUniformLocation(C,"uAcc"),0),e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,M),e.uniform1i(e.getUniformLocation(C,"uSil"),1),e.uniform1f(e.getUniformLocation(C,"uErase"),s?0:1)}),e.viewport(0,0,o.viewportW,o.viewportH),this.restore(e),S(),{tex:y.tex,w:p,h:g}}bakeSolidFill(e,t,r,o,i,s,a,l,c,u){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,f=Rn(e);return this.pass(e,this.fillProg,h,m=>{e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,d),e.uniform1i(e.getUniformLocation(m,"uSrc"),0),e.uniform4f(e.getUniformLocation(m,"uColor"),r.rgba[0],r.rgba[1],r.rgba[2],r.rgba[3])}),e.viewport(0,0,c,u),this.restore(e),f(),h.tex}},Dm=n=>({color:n.color,rgba:n.rgba,blur:n.blur,offsetX:n.offsetX,offsetY:n.offsetY,nonScaling:!1});var aa=class{constructor(e,t){this.gl=e;this.epoch=t}gl;epoch;fxPainter=null;filterChain=null;get fx(){return this.fxPainter||(this.fxPainter=new sa(this.epoch)),this.fxPainter}get filters(){return this.filterChain||(this.filterChain=new Qs(this.gl)),this.filterChain}invalidate(){this.fxPainter?.invalidate(this.gl),this.filterChain?.invalidate()}invalidateTextDerivedBakes(){this.fxPainter?.invalidateTextDerivedBakes(this.gl)}};var K0=[.914,.914,.914,1],la=class{host;sources;text;frame={bakeDeadline:0,bakeMore:!1,animationActive:!1};settle;flatFrame=!0;shadow;psd;stroke;clip;maskBake;gpu;maskClipFilterBakes=new WeakMap;isolator=null;isolating=!1;blender=null;blendWrapNode=null;puzzleBox=null;constructor(e,t,r){this.host=e,this.sources=t,this.text=r,this.gpu=new aa(e.gl,e.renderEpoch),this.shadow=new Js(e),this.settle=new Gt(()=>this.host.requestRenderAll()),this.stroke=new ra(e,this.frame,this.settle),this.clip=new oa(e,this.gpu),this.psd=new ia(e,this.frame,this.gpu,()=>this.puzzleBox,this.settle),this.maskBake=new Ks(e,this.frame,this.settle)}beginFrame(e){this.frame.animationActive=!1,this.frame.bakeDeadline=e+wm(this.host.isExporting()),this.frame.bakeMore=!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=Te(or(this.host)),g=Te(h),b=[1/c,0,0,1/u,-a/c,-l/u];if(!p||!g)return null;let x=Y(b,Y(g,Y(p,m))),y=[x[0],x[1],0,x[2],x[3],0,x[4],x[5],1];return{tex:r,maskInv:y,coversHost:o}}renderPuzzleChildren(e,t){if(!(e instanceof se)){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 ko(this.puzzleBox,e,t,r,o,i)}renderIsolatedGroup(e,t){let r=this.host.gl;this.flatFrame=!1,this.isolator||(this.isolator=new $s),this.host.batchOrder.flushAll();let o=()=>{if(e instanceof ee)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 ee){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 Vs),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}}renderSceneNode(e){if(e.visible&&e!==this.host.warpSessionTarget){if(this.blendWrapNode!==e){let t=Sm(e.raw.globalCompositeOperation);if(t!==null){this.renderBlendedNode(e,t);return}}if(e instanceof ee){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.isolating&&Ec(e)){let t=this.clip.mask(e);if(t){this.renderIsolatedGroup(e,t);return}}if(!this.isolating&&yi(e)){let t=this.groupMask(e);if(t){this.renderIsolatedGroup(e,t);return}}if(e.isTextType){if(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?Y(e.matrix,[1,0,0,1,s.x,s.y]):e.matrix;s.angle&&(a=Y(a,At({angle:-s.angle}))),this.shadow.render(e),this.psd.render(e,"below");let l=ao(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=Df(e.raw);if(t&&e!==this.host.editingNode){this.text.renderWarpedText(e,t);return}let r=Po(e.raw);if(r&&e!==this.host.editingNode){this.text.renderPsdWarpedText(e,r);return}let o=qe(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)}}return}if(e.isLineType){this.shadow.render(e),this.stroke.render(e);return}if(e instanceof le){this.renderMaskNode(e);return}if(e instanceof re&&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 l=e.strokeDecl?.paintFirst==="stroke";l&&this.stroke.render(e);let c=this.paintParams(e);if(c){this.host.batch.pushPaintQuad(e.matrix,e.dims.x,e.dims.y,c,e.renderOpacity,this.solidRadii(e)),l||this.stroke.render(e);return}}let t=e.isImageType&&!(e instanceof re)?So(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),i=r??(o?this.host.textures.get(o):null);if(e===this.host.cropGhostNode&&e.imageEl&&i){let l=e.dims,c=e.raw.cropX??0,u=e.raw.cropY??0,h=e.imageEl.naturalWidth,d=e.imageEl.naturalHeight,f={x:-l.x/2-c+h/2,y:-l.y/2-u+d/2},m=Y(e.matrix,[1,0,0,1,f.x,f.y]);this.host.batch.pushQuad(m,h,d,[1,1,1,.5*e.renderOpacity],i)}let s=e.cropRect,a=s&&e.imageEl?[s.sx/e.imageEl.naturalWidth,s.sy/e.imageEl.naturalHeight,(s.sx+s.sw)/e.imageEl.naturalWidth,(s.sy+s.sh)/e.imageEl.naturalHeight]:[0,0,1,1];this.host.batch.pushQuad(e.matrix,e.dims.x,e.dims.y,e.drawColor,i,a,this.quadRadii(e),e),e.isSolidType&&e.strokeDecl?.paintFirst!=="stroke"&&this.stroke.render(e),this.psd.render(e,"above")}renderMaskNode(e){let t=e.clipImageRaw;if(e.clipDynamicKind){e.tickDynamicClip(performance.now());let u=e.dynamicClipSource();if(!u||!e.imageEl){this.sources.isImagePending(e)&&this.renderImagePlaceholder(e);return}this.psd.render(e,"below");let h=this.maskBake.bake(e,{maskEl:e.imageEl,clipEl:u,frameVersion:e.clipDynamicVersion});if(!h)return;let d=this.puzzleClampedQuad(e,h.w,h.h);d&&this.host.batch.pushQuad(d.matrix,d.w,d.h,[1,1,1,e.renderOpacity],h.tex,d.uv),this.psd.render(e,"above"),e.clipAnimating&&(this.frame.animationActive=!0);return}if(!t){if(this.shadow.render(e),!e.imageEl){this.sources.isImagePending(e)&&this.renderImagePlaceholder(e);return}this.psd.render(e,"below");let u=this.sources.svgRasterSource(e,this.host.zoom,this.host.dpr)??e.imageEl,h=this.host.textures.get(u),d=this.puzzleClampedQuad(e,e.dims.x,e.dims.y);d&&this.host.batch.pushQuad(d.matrix,d.w,d.h,[1,1,1,e.renderOpacity],h,d.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=So(t.filters),s=(o.length?this.maskClipFilteredEl(e,t.src,r,o):null)??r;this.psd.render(e,"below");let a=this.maskBake.bake(e,{maskEl:e.imageEl,clipEl:s,clipFiltersKey:o.length?nr(o):void 0});if(!a)return;let l=this.puzzleClampedQuad(e,a.w,a.h),c=e===this.host.maskCropNode?.5:1;l&&this.host.batch.pushQuad(l.matrix,l.w,l.h,[1,1,1,c*e.renderOpacity],a.tex,l.uv),this.psd.render(e,"above")}maskClipFilteredEl(e,t,r,o){let i=r,s=i.naturalWidth??i.videoWidth??i.width??0,a=i.naturalHeight??i.videoHeight??i.height??0;if(!s||!a)return null;let l=`${qs(t)}|${s}x${a}|${nr(o)}`,c=this.maskClipFilterBakes.get(e);if(c&&c.sig===l)return c.canvas;let h=this.gpu.filters.getFilteredTexture(e,r,s,a,o);if(!h)return null;let d=Cm(this.host.gl,h,s,a);return d?(this.maskClipFilterBakes.set(e,{sig:l,canvas:d}),d):null}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=ae(e.raw.fill),s=i[3]>0?i:K0;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=rt(e.raw,e.dims.x,e.dims.y);return t?[t.rx,t.ry]:null}if(e.isImageType&&!(e instanceof re)){let t=qo(e.raw,e.dims.x,e.dims.y);return t?[t,t]:null}return null}solidRadii(e){let t=rt(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:Te(zo(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:Te(Uo(t.decl,e.dims.x,e.dims.y)),tex:r.tex,size:[r.w,r.h],repeat:hu(t.decl.repeat)}:null}return null}invalidateGlResources(){this.shadow.invalidate(),this.psd.invalidate(),this.clip.invalidate(),this.stroke.invalidate(),this.maskBake.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 Mc=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}},Fm=n=>n.startsWith("resource/")?n.replace("resource/","/resource/"):n,Om=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)}},Bm=(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}),Hm=(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},Wm=(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);Om(f.data),c.putImageData(f,0,0)}catch{return null}let d=Bm(t,o,i);if(h.drawImage(l,d.x,d.y),t.defaultColor===255){h.fillStyle="#000000";for(let[f,m,p,g]of Hm(s,a,d.x,d.y,t.width,t.height))h.fillRect(f,m,p,g)}return h.globalCompositeOperation="source-in",h.drawImage(n,0,0),u},Gm=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 Xm=async n=>{let{parseGIF:e,decompressFrame:t}=await import("gifuct-js"),r=e(n),o=null,i=(r.frames??[]).map(w=>w.image?(!w.gce&&o&&(w.gce=o),o=null,t(w,r.gct,!0)):(w.gce&&(o=w.gce),null)).filter(w=>w!==null);if(!i||!i.length)throw new Error("No frames available");let s=r.lsd,a=s?.width??i[0].dims.width,l=s?.height??i[0].dims.height,c=Math.max(a,l),u=c>640?640/c:1,h=Math.max(1,Math.round(a*u)),d=Math.max(1,Math.round(l*u)),f=i.reduce((w,T)=>w+(T.delay||0),0)/1e3,m=i.length>80?i.slice(0,80):i,p=m.reduce((w,T)=>w+(T.delay||0),0),g=m.length>0?p/m.length:100,b=document.createElement("canvas"),x=b.getContext("2d"),y=document.createElement("canvas"),S=y.getContext("2d"),v=document.createElement("canvas"),M=v.getContext("2d");if(!x||!S||!M)throw new Error("Failed to get canvas context");y.width=a,y.height=l,v.width=h*m.length,v.height=d;let C,R;return m.forEach((w,T)=>{C?.disposalType===2?S.clearRect(C.dims.left,C.dims.top,C.dims.width,C.dims.height):C?.disposalType===3&&R&&S.putImageData(R,0,0),R=w.disposalType===3?S.getImageData(0,0,a,l):void 0,b.width=w.dims.width,b.height=w.dims.height;let E=x.createImageData(w.dims.width,w.dims.height);E.data.set(w.patch),x.putImageData(E,0,0),S.drawImage(b,w.dims.left,w.dims.top),M.drawImage(y,0,0,a,l,h*T,0,h,d),C=w}),b.remove(),y.remove(),{canvas:v,frameWidth:h,framesLength:m.length,delay:g,frameDelays:m.map(w=>w.delay||100),duration:f}};var Cc=(n,e)=>String.fromCharCode(n[e],n[e+1],n[e+2],n[e+3]),Rc=n=>{if(n.byteLength<12)return!1;let e=new Uint8Array(n,0,12);return Cc(e,0)==="RIFF"&&Cc(e,8)==="WEBP"},Ym=n=>{if(!Rc(n))return!1;let e=new Uint8Array(n,0,Math.min(n.byteLength,512)),t=12;for(;t+8<=e.length;){let r=Cc(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},Q0=async n=>Ym(await n.slice(0,512).arrayBuffer()),Z0=async n=>{try{let e=await fetch(n,{headers:{Range:"bytes=0-511"}});return e.ok?Ym(await e.arrayBuffer()):!1}catch{return!1}},Um=(n,e,t)=>{let r=document.createElement("canvas");r.width=n*t,r.height=e;let o=r.getContext("2d");if(!o)throw new Error("Failed to get canvas context");return{canvas:r,ctx:o}},$m=(n,e)=>{let t=Math.max(n,e),r=t>640?640/t:1;return{width:Math.max(1,Math.round(n*r)),height:Math.max(1,Math.round(e*r))}},zm=async n=>{let e=URL.createObjectURL(new Blob([n],{type:"image/webp"}));try{let t=await new Promise((a,l)=>{let c=new Image;c.onload=()=>a(c),c.onerror=()=>l(new Error("Failed to load WebP")),c.src=e}),{width:r,height:o}=$m(t.naturalWidth,t.naturalHeight),{canvas:i,ctx:s}=Um(r,o,1);return s.drawImage(t,0,0,r,o),{canvas:i,frameWidth:r,framesLength:1,delay:100,frameDelays:[100],duration:0}}finally{URL.revokeObjectURL(e)}},Vm=async n=>{let e=window.ImageDecoder;if(!e||!await e.isTypeSupported("image/webp"))return zm(n);let t=new e({data:n,type:"image/webp",preferAnimation:!0});try{await t.tracks.ready;let r=t.tracks.selectedTrack;if(!r?.frameCount||r.frameCount<2)return zm(n);let o=Math.min(r.frameCount,80),i=await t.decode({frameIndex:0}),{width:s,height:a}=$m(i.image.displayWidth,i.image.displayHeight),{canvas:l,ctx:c}=Um(s,a,o),u=[];for(let h=0;h<o;h++){let{image:d}=h===0?i:await t.decode({frameIndex:h}),f=typeof d.duration=="number"&&d.duration>0?d.duration/1e3:100;u.push(f),c.drawImage(d,s*h,0,s,a),d.close()}return{canvas:l,frameWidth:s,framesLength:o,delay:u[0]||100,frameDelays:u,duration:u.reduce((h,d)=>h+d,0)/1e3}}finally{t.close()}};var ca=class{host;patternSources=new Map;gifSprites=new Map;animatedNodes=new Set;pendingImageNodes=new WeakSet;patternTextures=new Map;maskTextures=new Map;svgRasters=new WeakMap;svgMaxRasterPx;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 ee?(r(a),o(a.children)):yi(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 Qe(s,"anonymous"),l=ke(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=e.filter(o=>o instanceof le&&!!o.clipDynamicKind&&!o.hasDynamicClip);for(let o of t)(async()=>{let i=o.clipImageRaw;try{o.clipDynamicKind==="gif"?o.attachClipSprite(await this.loadGifSprite(i.src),()=>this.host.requestRenderAll()):o.attachClipVideo(await this.loadVideoElement(i.src,i.crossOrigin,i.loop===!0),()=>this.host.requestRenderAll()),this.dynamicClipMasks.add(o),this.host.requestRenderAll()}catch(s){console.warn("[engine] mask dynamic clip skipped (load failed):",s.message);try{o.clipImageEl=await Qe(i.src,i.crossOrigin)}catch{}this.host.requestRenderAll()}})();let r=e.filter(o=>o instanceof re);r.length!==0&&(await Promise.all(r.map(async o=>{let i=o.raw.src;try{o.animatedKind==="gif"?o.attachSprite(await this.loadGifSprite(i),()=>this.host.requestRenderAll()):o.attachVideo(await this.loadVideoElement(i,o.raw.crossOrigin,o.raw.loop===!0),()=>this.host.requestRenderAll()),this.animatedNodes.add(o),this.pendingImageNodes.delete(o),this.host.requestRenderAll()}catch(s){console.warn("[engine] animated source skipped (load failed):",s.message);try{o.imageEl=await Qe(i,o.raw.crossOrigin)}catch{}this.pendingImageNodes.delete(o),this.host.requestRenderAll()}})),this.host.document.refreshHitIndex())}loadGifSprite(e){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();return Rc(i)?Vm(i):Xm(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(){for(let e of[...this.animatedNodes])this.releaseAnimatedNode(e);for(let e of this.dynamicClipMasks)e.detachDynamicClip();this.dynamicClipMasks.clear()}releaseAnimatedSourcesOfDoc(e){for(let t of[...this.animatedNodes])e.nodes.includes(t)&&this.releaseAnimatedNode(t);for(let t of[...this.dynamicClipMasks])e.nodes.includes(t)&&(t.detachDynamicClip(),this.dynamicClipMasks.delete(t))}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 Qe(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=ke(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(!vi(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),c=gh({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=xh(o,c.factor);return l&&this.host.textures.remove(l.canvas),this.svgRasters.set(e,{canvas:u,factor:c.factor}),u}svgRasterFactorOf(e){return this.svgRasters.get(e)?.factor??null}async applyImageMask(e,t){let r=Mc(e.raw);if(!r)return!1;try{let o=await Qe(Fm(r.src),r.crossOrigin),i=e.dims;if(!(i.x>0)||!(i.y>0))return!1;let s=Wm(t,i,r,o,e.raw.left??0,e.raw.top??0);if(!s)return!1;let a=await Gm(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 Qe(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 Qe(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 re?!1:s instanceof le?!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 le){if(!s.imageEl){let d=o.get(l);d||(d=await Qe(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 Qe(d,h.crossOrigin),o.set(d,f)),s.clipImageEl=f}c();return}if(a){let h=o.get(l);h||(h=await Qe(l,s.raw.crossOrigin),o.set(l,h)),s.imageEl=h,i=!0,c();return}let u=o.get(l);u||(u=await Qe(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.gifSprites.clear();for(let{tex:e}of this.patternTextures.values())this.host.gl.deleteTexture(e);this.patternTextures.clear(),this.patternSources.clear()}};function Ao(n){let e=[],t=r=>{for(let o of r)e.push(o),o instanceof ee&&t(o.children)};return t([...n]),e}async function No(n,e,t){for(let r of n)r instanceof re?r.paintSource||e.markImagePending(r):r instanceof le?(!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()}function qm(n,e,t,r,o){if(n.pageCount<2)return null;let i=n.route(r.x,r.y),s=n.activeIndex;if(!i||i.index===s)return null;let a=n.activeDoc,l=new Set(e),c=a.nodes.filter(b=>l.has(b)&&!b.syntheticOwner&&!Dt.has(b.id));if(!c.length||c.length!==l.size)return null;o(i.index);let u=i.doc,h=n.originAt(s),d=n.originAt(i.index),f=a.nodes.filter(b=>!b.syntheticOwner),m=c.map(b=>({index:f.indexOf(b),before:t?.get(b)??b.toObject(),after:b.toObject()})),p=new Set,g=(b,x)=>{if(x(b),b instanceof ee)for(let y of b.children)g(y,x)};for(let b of u.nodes)g(b,x=>{x.id&&p.add(x.id)});for(let b of c)a.remove(b),g(b,x=>{if(x.id&&p.has(x.id)){let y=x.id,S=1;for(;p.has(`${y}-transfer-${S}`);)S++;x.set({id:`${y}-transfer-${S}`})}x.id&&p.add(x.id)}),b.set({left:Number(b.raw.left??0)+h.x-d.x,top:Number(b.raw.top??0)+h.y-d.y}),u.add(b);return a.clearSelection(),c.forEach((b,x)=>{m[x].after=b.toObject()}),{sourceIndex:s,targetIndex:i.index,source:a,target:u,nodes:c,items:m}}var J0=(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}},ua=(n,e,t)=>e<0?null:e<n.boxes.length?n.boxes[e]:e===n.boxes.length?J0(n,t):null,ev=(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]===`
993
+ }`,aa=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 c of a.map.values())e.deleteFramebuffer(c.fb),e.deleteTexture(c.tex),this.liveTargetRts.delete(c);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=tv){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("[GpuFxPainter] shader:",e.getShaderInfoLog(u)),e.deleteShader(u),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,av,sv),this.downProg=this.downProg??this.compile(e,lv),this.blurProg=this.blurProg??this.compile(e,nv),this.tintProg=this.tintProg??this.compile(e,rv),this.fillProg=this.fillProg??this.compile(e,ov),this.finishProg=this.finishProg??this.compile(e,iv),!!(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 c=i<.05?1:Math.max(1,Math.min(64,Math.round(Math.sqrt(4*i*i+1)))),u=[this.ensureTarget(e,s,r,o),this.ensureTarget(e,a,r,o),this.ensureTarget(e,l,r,o)];if(!u[0]||!u[1]||!u[2])return null;let h=(d,f,m,p)=>this.pass(e,this.blurProg,f,g=>{e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,d),e.uniform1i(e.getUniformLocation(g,"uSrc"),0),e.uniform2f(e.getUniformLocation(g,"uDir"),m,p),e.uniform1i(e.getUniformLocation(g,"uBoxW"),c)});return h(t,u[0],1/r,0),h(u[0].tex,u[1],1/r,0),h(u[1].tex,u[0],1/r,0),h(u[0].tex,u[1],0,1/o),h(u[1].tex,u[0],0,1/o),h(u[0].tex,u[1],0,1/o),u[1].tex}source(e,t,r,o,i,s,a,l,c=null){let u=this.sources.get(t);if(u&&(u.sig!==r||!e.isTexture(u.tex))&&(e.deleteTexture(u.tex),u=void 0),!u){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=Xr(t,d),!zn(d,t))return null;d.fill()}else if(s){let p=t.dims.x,g=t.dims.y;c?d.drawImage(s,c.sx,c.sy,c.sw,c.sh,-p/2,-g/2,p,g):d.drawImage(s,-p/2,-g/2,p,g)}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),u={sig:r,tex:m,w:o,h:i},this.sources.set(t,u)}return u.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}renderClipMask(e,t,r,o,i,s){if(this.restoreFb=e.getParameter(e.FRAMEBUFFER_BINDING),!this.ensurePrograms(e))return null;let a=2,l=o.w*a,c=o.h*a;if(!(l>0)||!(c>0)||l>8192||c>8192||(this.maskRt=this.ensureTarget(e,5,o.w,o.h)??this.maskRt,!this.maskRt||this.maskRt.w!==o.w||this.maskRt.h!==o.h))return null;if(!this.maskMsaa||this.maskMsaa.w!==l||this.maskMsaa.h!==c){this.maskMsaa&&(e.deleteFramebuffer(this.maskMsaa.fb),e.deleteRenderbuffer(this.maskMsaa.rb));let x=e.getParameter(e.MAX_SAMPLES),y=Math.min(8,Math.max(4,x)),S=e.createRenderbuffer();if(!S)return null;e.bindRenderbuffer(e.RENDERBUFFER,S),e.renderbufferStorageMultisample(e.RENDERBUFFER,y,e.RGBA8,l,c);let v=e.createFramebuffer();if(!v)return e.deleteRenderbuffer(S),null;e.bindFramebuffer(e.FRAMEBUFFER,v),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.RENDERBUFFER,S),e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindRenderbuffer(e.RENDERBUFFER,null),this.maskMsaa={fb:v,rb:S,samples:y,w:l,h:c}}let u=this.maskMsaa,h=this.ensureTarget(e,6,l,c);if(!h)return null;let d=t;if(!d&&r){let x=r.x/2,y=r.y/2;d={verts:new Float32Array([-x,-y,x,-y,x,y,-x,y]),triangles:new Uint32Array([0,1,2,0,2,3])}}if(!d)return null;let f=e.createVertexArray();if(!f)return null;e.bindVertexArray(f);let m=this.meshBufs.get(d);if(!m){let x=e.createBuffer(),y=e.createBuffer();if(!x||!y)return x&&e.deleteBuffer(x),y&&e.deleteBuffer(y),e.bindVertexArray(null),e.deleteVertexArray(f),null;e.bindBuffer(e.ARRAY_BUFFER,x),e.bufferData(e.ARRAY_BUFFER,d.verts,e.STATIC_DRAW),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,y),e.bufferData(e.ELEMENT_ARRAY_BUFFER,d.triangles,e.STATIC_DRAW),m={vbo:x,ibo:y,count:d.triangles.length},this.meshBufs.set(d,m)}e.bindBuffer(e.ARRAY_BUFFER,m.vbo);let p=e.getAttribLocation(this.maskProg,"aPos");e.enableVertexAttribArray(p),e.vertexAttribPointer(p,2,e.FLOAT,!1,0,0),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,m.ibo);let g=Pn(e);e.bindFramebuffer(e.FRAMEBUFFER,u.fb),e.viewport(0,0,l,c),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),e.useProgram(this.maskProg),e.disable(e.BLEND),e.uniformMatrix3fv(e.getUniformLocation(this.maskProg,"uM"),!1,[o.m[0]*a,o.m[1]*a,0,o.m[2]*a,o.m[3]*a,0,o.m[4]*a,o.m[5]*a,1]),e.uniform2f(e.getUniformLocation(this.maskProg,"uSize"),l,c),e.drawElements(e.TRIANGLES,m.count,e.UNSIGNED_INT,0),e.bindVertexArray(null),e.deleteVertexArray(f),e.bindFramebuffer(e.READ_FRAMEBUFFER,u.fb),e.bindFramebuffer(e.DRAW_FRAMEBUFFER,h.fb),e.blitFramebuffer(0,0,l,c,0,0,l,c,e.COLOR_BUFFER_BIT,e.NEAREST),e.bindFramebuffer(e.READ_FRAMEBUFFER,null),e.bindFramebuffer(e.DRAW_FRAMEBUFFER,null);let b=h.tex;return this.pass(e,this.downProg,this.maskRt,x=>{e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,b),e.uniform1i(e.getUniformLocation(x,"uSrc"),0),e.uniform2f(e.getUniformLocation(x,"uHalfTexel"),.25/o.w,.25/o.h)}),e.bindFramebuffer(e.READ_FRAMEBUFFER,null),e.bindFramebuffer(e.DRAW_FRAMEBUFFER,null),e.viewport(0,0,i,s),this.restore(e),g(),this.maskRt.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,c=4;for(let C of r){let R=s?{blur:C.blur,offX:C.offsetX,offY:C.offsetY}:Ht(Wm(C),a,l);c=Math.max(c,Math.ceil(R.blur*2+Math.max(Math.abs(R.offX),Math.abs(R.offY))+4))}let u=t.matrix,h=Math.abs(u[0])*t.dims.x+Math.abs(u[2])*t.dims.y,d=Math.abs(u[1])*t.dims.x+Math.abs(u[3])*t.dims.y,f=Math.ceil(h+c*2),m=Math.ceil(d+c*2),p=Math.ceil(f*i),g=Math.ceil(m*i);if(!(f>0)||!(m>0)||p>8192||g>8192)return null;let b=this.source(e,t,`${o.sig}|src`,p,g,o.source,i,s,o.sourceRect??null);if(!b)return null;let x=this.ensureTarget(e,3,p,g);if(!x)return null;let y=this.slot(e,t,o.sig,"shadow",p,g);if(!y)return null;let S=Pn(e);e.bindFramebuffer(e.FRAMEBUFFER,x.fb),e.viewport(0,0,p,g),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT);for(let C of r){let R=s?{blur:C.blur,offX:C.offsetX,offY:C.offsetY}:Ht(Wm(C),a,l),w=this.blurChain(e,b,p,g,R.blur*i/2,0,1,2);if(!w)return e.viewport(0,0,o.viewportW,o.viewportH),this.restore(e),S(),null;this.pass(e,this.tintProg,x,E=>{e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,w),e.uniform1i(e.getUniformLocation(E,"uMask"),0),e.uniform2f(e.getUniformLocation(E,"uOffUv"),-R.offX*i/p,-R.offY*i/g),e.uniform4f(e.getUniformLocation(E,"uColor"),C.rgba[0],C.rgba[1],C.rgba[2],C.rgba[3])},!0),this.pass(e,this.fillProg,x,E=>{e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,b),e.uniform1i(e.getUniformLocation(E,"uSrc"),0),e.uniform4f(e.getUniformLocation(E,"uColor"),1,1,1,1)},!0)}let v=x.tex,T=b;return this.pass(e,this.finishProg,y,C=>{e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,v),e.uniform1i(e.getUniformLocation(C,"uAcc"),0),e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,T),e.uniform1i(e.getUniformLocation(C,"uSil"),1),e.uniform1f(e.getUniformLocation(C,"uErase"),s?0:1)}),e.viewport(0,0,o.viewportW,o.viewportH),this.restore(e),S(),{tex:y.tex,w:p,h:g}}bakeSolidFill(e,t,r,o,i,s,a,l,c,u){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,f=Pn(e);return this.pass(e,this.fillProg,h,m=>{e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,d),e.uniform1i(e.getUniformLocation(m,"uSrc"),0),e.uniform4f(e.getUniformLocation(m,"uColor"),r.rgba[0],r.rgba[1],r.rgba[2],r.rgba[3])}),e.viewport(0,0,c,u),this.restore(e),f(),h.tex}},Wm=n=>({color:n.color,rgba:n.rgba,blur:n.blur,offsetX:n.offsetX,offsetY:n.offsetY,nonScaling:!1});var la=class{constructor(e,t){this.gl=e;this.epoch=t}gl;epoch;fxPainter=null;filterChain=null;get fx(){return this.fxPainter||(this.fxPainter=new aa(this.epoch)),this.fxPainter}get filters(){return this.filterChain||(this.filterChain=new Zs(this.gl)),this.filterChain}invalidate(){this.fxPainter?.invalidate(this.gl),this.filterChain?.invalidate()}invalidateTextDerivedBakes(){this.fxPainter?.invalidateTextDerivedBakes(this.gl)}};var cv=[.914,.914,.914,1],ca=class{host;sources;text;frame={bakeDeadline:0,bakeMore:!1,animationActive:!1};settle;flatFrame=!0;shadow;psd;stroke;clip;maskBake;gpu;maskClipFilterBakes=new WeakMap;isolator=null;isolating=!1;blender=null;blendWrapNode=null;puzzleBox=null;constructor(e,t,r){this.host=e,this.sources=t,this.text=r,this.gpu=new la(e.gl,e.renderEpoch),this.shadow=new ea(e),this.settle=new Gt(()=>this.host.requestRenderAll()),this.stroke=new oa(e,this.frame,this.settle),this.clip=new ia(e,this.gpu,this.frame,this.settle),this.psd=new sa(e,this.frame,this.gpu,()=>this.puzzleBox,this.settle),this.maskBake=new Qs(e,this.frame,this.settle)}beginFrame(e){this.frame.animationActive=!1,this.frame.bakeDeadline=e+Cm(this.host.isExporting()),this.frame.bakeMore=!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=Te(ir(this.host)),g=Te(h),b=[1/c,0,0,1/u,-a/c,-l/u];if(!p||!g)return null;let x=Y(b,Y(g,Y(p,m))),y=[x[0],x[1],0,x[2],x[3],0,x[4],x[5],1];return{tex:r,maskInv:y,coversHost:o}}renderPuzzleChildren(e,t){if(!(e instanceof se)){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 ko(this.puzzleBox,e,t,r,o,i)}renderIsolatedGroup(e,t){let r=this.host.gl;this.flatFrame=!1,this.isolator||(this.isolator=new Vs),this.host.batchOrder.flushAll();let o=()=>{if(e instanceof Z)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 Z){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 js),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}}renderSceneNode(e){if(e.visible&&e!==this.host.warpSessionTarget){if(this.blendWrapNode!==e){let t=Mm(e.raw.globalCompositeOperation);if(t!==null){this.renderBlendedNode(e,t);return}}if(e instanceof Z){let t=this.isolating?null:this.groupMask(e)??this.clip.mask(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.isolating&&Mc(e)){let t=this.clip.mask(e);if(t){this.renderIsolatedGroup(e,t);return}}if(!this.isolating&&vi(e)){let t=this.groupMask(e);if(t){this.renderIsolatedGroup(e,t);return}}if(e.isTextType){if(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?Y(e.matrix,[1,0,0,1,s.x,s.y]):e.matrix;s.angle&&(a=Y(a,At({angle:-s.angle}))),this.shadow.render(e),this.psd.render(e,"below");let l=ao(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=Hf(e.raw);if(t&&e!==this.host.editingNode){this.text.renderWarpedText(e,t);return}let r=Po(e.raw);if(r&&e!==this.host.editingNode){this.text.renderPsdWarpedText(e,r);return}let o=Ke(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)}}return}if(e.isLineType){this.shadow.render(e),this.stroke.render(e);return}if(e instanceof le){this.renderMaskNode(e);return}if(e instanceof re&&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 l=e.strokeDecl?.paintFirst==="stroke";l&&this.stroke.render(e);let c=this.paintParams(e);if(c){this.host.batch.pushPaintQuad(e.matrix,e.dims.x,e.dims.y,c,e.renderOpacity,this.solidRadii(e)),l||this.stroke.render(e);return}}let t=e.isImageType&&!(e instanceof re)?So(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),i=r??(o?this.host.textures.get(o):null);if(e===this.host.cropGhostNode&&e.imageEl&&i){let l=e.dims,c=e.raw.cropX??0,u=e.raw.cropY??0,h=e.imageEl.naturalWidth,d=e.imageEl.naturalHeight,f={x:-l.x/2-c+h/2,y:-l.y/2-u+d/2},m=Y(e.matrix,[1,0,0,1,f.x,f.y]);this.host.batch.pushQuad(m,h,d,[1,1,1,.5*e.renderOpacity],i)}let s=e.cropRect,a=s&&e.imageEl?[s.sx/e.imageEl.naturalWidth,s.sy/e.imageEl.naturalHeight,(s.sx+s.sw)/e.imageEl.naturalWidth,(s.sy+s.sh)/e.imageEl.naturalHeight]:[0,0,1,1];this.host.batch.pushQuad(e.matrix,e.dims.x,e.dims.y,e.drawColor,i,a,this.quadRadii(e),e),e.isSolidType&&e.strokeDecl?.paintFirst!=="stroke"&&this.stroke.render(e),this.psd.render(e,"above")}renderMaskNode(e){let t=e.clipImageRaw;if(e.clipDynamicKind){e.tickDynamicClip(performance.now());let u=e.dynamicClipSource();if(!u||!e.imageEl){this.sources.isImagePending(e)&&this.renderImagePlaceholder(e);return}this.psd.render(e,"below");let h=this.maskBake.bake(e,{maskEl:e.imageEl,clipEl:u,frameVersion:e.clipDynamicVersion});if(!h)return;let d=this.puzzleClampedQuad(e,h.w,h.h);d&&this.host.batch.pushQuad(d.matrix,d.w,d.h,[1,1,1,e.renderOpacity],h.tex,d.uv),this.psd.render(e,"above"),e.clipAnimating&&(this.frame.animationActive=!0);return}if(!t){if(this.shadow.render(e),!e.imageEl){this.sources.isImagePending(e)&&this.renderImagePlaceholder(e);return}this.psd.render(e,"below");let u=this.sources.svgRasterSource(e,this.host.zoom,this.host.dpr)??e.imageEl,h=this.host.textures.get(u),d=this.puzzleClampedQuad(e,e.dims.x,e.dims.y);d&&this.host.batch.pushQuad(d.matrix,d.w,d.h,[1,1,1,e.renderOpacity],h,d.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=So(t.filters),s=(o.length?this.maskClipFilteredEl(e,t.src,r,o):null)??r;this.psd.render(e,"below");let a=this.maskBake.bake(e,{maskEl:e.imageEl,clipEl:s,clipFiltersKey:o.length?rr(o):void 0});if(!a)return;let l=this.puzzleClampedQuad(e,a.w,a.h),c=e===this.host.maskCropNode?.5:1;l&&this.host.batch.pushQuad(l.matrix,l.w,l.h,[1,1,1,c*e.renderOpacity],a.tex,l.uv),this.psd.render(e,"above")}maskClipFilteredEl(e,t,r,o){let i=r,s=i.naturalWidth??i.videoWidth??i.width??0,a=i.naturalHeight??i.videoHeight??i.height??0;if(!s||!a)return null;let l=`${Ks(t)}|${s}x${a}|${rr(o)}`,c=this.maskClipFilterBakes.get(e);if(c&&c.sig===l)return c.canvas;let h=this.gpu.filters.getFilteredTexture(e,r,s,a,o);if(!h)return null;let d=Am(this.host.gl,h,s,a);return d?(this.maskClipFilterBakes.set(e,{sig:l,canvas:d}),d):null}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=ae(e.raw.fill),s=i[3]>0?i:cv;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=ot(e.raw,e.dims.x,e.dims.y);return t?[t.rx,t.ry]:null}if(e.isImageType&&!(e instanceof re)){let t=Ko(e.raw,e.dims.x,e.dims.y);return t?[t,t]:null}return null}solidRadii(e){let t=ot(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:Te(Yo(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:Te($o(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.clip.invalidate(),this.stroke.invalidate(),this.maskBake.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 Cc=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}},Gm=n=>n.startsWith("resource/")?n.replace("resource/","/resource/"):n,Xm=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)}},zm=(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}),Ym=(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},Um=(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);Xm(f.data),c.putImageData(f,0,0)}catch{return null}let d=zm(t,o,i);if(h.drawImage(l,d.x,d.y),t.defaultColor===255){h.fillStyle="#000000";for(let[f,m,p,g]of Ym(s,a,d.x,d.y,t.width,t.height))h.fillRect(f,m,p,g)}return h.globalCompositeOperation="source-in",h.drawImage(n,0,0),u},$m=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 Vm=async n=>{let{parseGIF:e,decompressFrame:t}=await import("gifuct-js"),r=e(n),o=null,i=(r.frames??[]).map(w=>w.image?(!w.gce&&o&&(w.gce=o),o=null,t(w,r.gct,!0)):(w.gce&&(o=w.gce),null)).filter(w=>w!==null);if(!i||!i.length)throw new Error("No frames available");let s=r.lsd,a=s?.width??i[0].dims.width,l=s?.height??i[0].dims.height,c=Math.max(a,l),u=c>640?640/c:1,h=Math.max(1,Math.round(a*u)),d=Math.max(1,Math.round(l*u)),f=i.reduce((w,E)=>w+(E.delay||0),0)/1e3,m=i.length>80?i.slice(0,80):i,p=m.reduce((w,E)=>w+(E.delay||0),0),g=m.length>0?p/m.length:100,b=document.createElement("canvas"),x=b.getContext("2d"),y=document.createElement("canvas"),S=y.getContext("2d"),v=document.createElement("canvas"),T=v.getContext("2d");if(!x||!S||!T)throw new Error("Failed to get canvas context");y.width=a,y.height=l,v.width=h*m.length,v.height=d;let C,R;return m.forEach((w,E)=>{C?.disposalType===2?S.clearRect(C.dims.left,C.dims.top,C.dims.width,C.dims.height):C?.disposalType===3&&R&&S.putImageData(R,0,0),R=w.disposalType===3?S.getImageData(0,0,a,l):void 0,b.width=w.dims.width,b.height=w.dims.height;let M=x.createImageData(w.dims.width,w.dims.height);M.data.set(w.patch),x.putImageData(M,0,0),S.drawImage(b,w.dims.left,w.dims.top),T.drawImage(y,0,0,a,l,h*E,0,h,d),C=w}),b.remove(),y.remove(),{canvas:v,frameWidth:h,framesLength:m.length,delay:g,frameDelays:m.map(w=>w.delay||100),duration:f}};var Rc=(n,e)=>String.fromCharCode(n[e],n[e+1],n[e+2],n[e+3]),Pc=n=>{if(n.byteLength<12)return!1;let e=new Uint8Array(n,0,12);return Rc(e,0)==="RIFF"&&Rc(e,8)==="WEBP"},qm=n=>{if(!Pc(n))return!1;let e=new Uint8Array(n,0,Math.min(n.byteLength,512)),t=12;for(;t+8<=e.length;){let r=Rc(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},uv=async n=>qm(await n.slice(0,512).arrayBuffer()),hv=async n=>{try{let e=await fetch(n,{headers:{Range:"bytes=0-511"}});return e.ok?qm(await e.arrayBuffer()):!1}catch{return!1}},Km=(n,e,t)=>{let r=document.createElement("canvas");r.width=n*t,r.height=e;let o=r.getContext("2d");if(!o)throw new Error("Failed to get canvas context");return{canvas:r,ctx:o}},Qm=(n,e)=>{let t=Math.max(n,e),r=t>640?640/t:1;return{width:Math.max(1,Math.round(n*r)),height:Math.max(1,Math.round(e*r))}},jm=async n=>{let e=URL.createObjectURL(new Blob([n],{type:"image/webp"}));try{let t=await new Promise((a,l)=>{let c=new Image;c.onload=()=>a(c),c.onerror=()=>l(new Error("Failed to load WebP")),c.src=e}),{width:r,height:o}=Qm(t.naturalWidth,t.naturalHeight),{canvas:i,ctx:s}=Km(r,o,1);return s.drawImage(t,0,0,r,o),{canvas:i,frameWidth:r,framesLength:1,delay:100,frameDelays:[100],duration:0}}finally{URL.revokeObjectURL(e)}},Zm=async n=>{let e=window.ImageDecoder;if(!e||!await e.isTypeSupported("image/webp"))return jm(n);let t=new e({data:n,type:"image/webp",preferAnimation:!0});try{await t.tracks.ready;let r=t.tracks.selectedTrack;if(!r?.frameCount||r.frameCount<2)return jm(n);let o=Math.min(r.frameCount,80),i=await t.decode({frameIndex:0}),{width:s,height:a}=Qm(i.image.displayWidth,i.image.displayHeight),{canvas:l,ctx:c}=Km(s,a,o),u=[];for(let h=0;h<o;h++){let{image:d}=h===0?i:await t.decode({frameIndex:h}),f=typeof d.duration=="number"&&d.duration>0?d.duration/1e3:100;u.push(f),c.drawImage(d,s*h,0,s,a),d.close()}return{canvas:l,frameWidth:s,framesLength:o,delay:u[0]||100,frameDelays:u,duration:u.reduce((h,d)=>h+d,0)/1e3}}finally{t.close()}};var ua=class{host;patternSources=new Map;gifSprites=new Map;animatedNodes=new Set;pendingImageNodes=new WeakSet;patternTextures=new Map;maskTextures=new Map;svgRasters=new WeakMap;svgMaxRasterPx;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 Z?(r(a),o(a.children)):vi(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 Ze(s,"anonymous"),l=ke(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=e.filter(o=>o instanceof le&&!!o.clipDynamicKind&&!o.hasDynamicClip);for(let o of t)(async()=>{let i=o.clipImageRaw;try{o.clipDynamicKind==="gif"?o.attachClipSprite(await this.loadGifSprite(i.src),()=>this.host.requestRenderAll()):o.attachClipVideo(await this.loadVideoElement(i.src,i.crossOrigin,i.loop===!0),()=>this.host.requestRenderAll()),this.dynamicClipMasks.add(o),this.host.requestRenderAll()}catch(s){console.warn("[engine] mask dynamic clip skipped (load failed):",s.message);try{o.clipImageEl=await Ze(i.src,i.crossOrigin)}catch{}this.host.requestRenderAll()}})();let r=e.filter(o=>o instanceof re);r.length!==0&&(await Promise.all(r.map(async o=>{let i=o.raw.src;try{o.animatedKind==="gif"?o.attachSprite(await this.loadGifSprite(i),()=>this.host.requestRenderAll()):o.attachVideo(await this.loadVideoElement(i,o.raw.crossOrigin,o.raw.loop===!0),()=>this.host.requestRenderAll()),this.animatedNodes.add(o),this.pendingImageNodes.delete(o),this.host.requestRenderAll()}catch(s){console.warn("[engine] animated source skipped (load failed):",s.message);try{o.imageEl=await Ze(i,o.raw.crossOrigin)}catch{}this.pendingImageNodes.delete(o),this.host.requestRenderAll()}})),this.host.document.refreshHitIndex())}loadGifSprite(e){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();return Pc(i)?Zm(i):Vm(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(){for(let e of[...this.animatedNodes])this.releaseAnimatedNode(e);for(let e of this.dynamicClipMasks)e.detachDynamicClip();this.dynamicClipMasks.clear()}releaseAnimatedSourcesOfDoc(e){for(let t of[...this.animatedNodes])e.nodes.includes(t)&&this.releaseAnimatedNode(t);for(let t of[...this.dynamicClipMasks])e.nodes.includes(t)&&(t.detachDynamicClip(),this.dynamicClipMasks.delete(t))}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 Ze(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=ke(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(!Si(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),c=Sh({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=wh(o,c.factor);return l&&this.host.textures.remove(l.canvas),this.svgRasters.set(e,{canvas:u,factor:c.factor}),u}svgRasterFactorOf(e){return this.svgRasters.get(e)?.factor??null}async applyImageMask(e,t){let r=Cc(e.raw);if(!r)return!1;try{let o=await Ze(Gm(r.src),r.crossOrigin),i=e.dims;if(!(i.x>0)||!(i.y>0))return!1;let s=Um(t,i,r,o,e.raw.left??0,e.raw.top??0);if(!s)return!1;let a=await $m(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 Ze(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 Ze(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 re?!1:s instanceof le?!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 le){if(!s.imageEl){let d=o.get(l);d||(d=await Ze(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 Ze(d,h.crossOrigin),o.set(d,f)),s.clipImageEl=f}c();return}if(a){let h=o.get(l);h||(h=await Ze(l,s.raw.crossOrigin),o.set(l,h)),s.imageEl=h,i=!0,c();return}let u=o.get(l);u||(u=await Ze(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.gifSprites.clear();for(let{tex:e}of this.patternTextures.values())this.host.gl.deleteTexture(e);this.patternTextures.clear(),this.patternSources.clear()}};function Ao(n){let e=[],t=r=>{for(let o of r)e.push(o),o instanceof Z&&t(o.children)};return t([...n]),e}async function No(n,e,t){for(let r of n)r instanceof re?r.paintSource||e.markImagePending(r):r instanceof le?(!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 da=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}},Ve=new WeakMap,ha=new WeakMap,ep=(n,e)=>n.nodes.includes(e),en=(n,e)=>{let t=Ve.get(e);if(!t)return!1;let r=e.raw,o=da(r);if(!o||e.visible===!1)return n.setProps(t,{visible:!1}),!0;let i=e.dims;if(!i.x||!i.y)return!1;let s=e.center;return n.setProps(t,{left:s.x,top:s.y,originX:"center",originY:"center",angle:Number(r.angle)||0,flipX:r.flipX===!0,flipY:r.flipY===!0,scaleX:(r.scaleX??1)*(i.x/o.width),scaleY:(r.scaleY??1)*(i.y/o.height),opacity:r.opacity??1,visible:!0}),!0},Lo=(n,e)=>{if(!(e instanceof ge))return null;if(Ve.has(e))return en(n,e),Ve.get(e)??null;let t=da(e.raw);if(!t)return null;let r=ct({type:"Path",id:`${e.id||"text"}__pathbg`,path:t.path,...t.fill?{fill:t.fill}:{},evented:!1,selectable:!1,visible:!1});if(!r)return null;r.syntheticOwner=e.id||"text",Ve.set(e,r),ha.set(r,e);let o=n.nodes.indexOf(e);return n.insertAt(o<0?n.nodes.length:o,r),en(n,e),r},dv=n=>{let e=0;for(let t of[...n.nodes])t.syntheticOwner||Lo(n,t)&&e++;return e},fv=(n,e)=>{if(Ve.has(e)){en(n,e);return}e instanceof ge&&da(e.raw)&&Lo(n,e)},tp=(n,e)=>{let t=Ve.get(e);if(!t)return;let r=n.nodes.indexOf(e);if(r<0)return;let o=n.nodes.indexOf(t);if(o===r-1)return;if(o<0){n.insertAt(r,t);return}let i=o<r?r-1:r;n.moveNodeTo(t,i)},kc=(n,e)=>{let t=Ve.get(e);t&&ep(n,t)&&n.remove(t)},Ac=(n,e)=>{if(!(e instanceof ge))return;let t=Ve.get(e)??Lo(n,e);if(!t)return;let r=n.nodes.indexOf(e);if(!(r<0)){if(n.nodes.includes(t)){tp(n,e);return}n.insertAt(r,t),en(n,e)}},mv=(n,e)=>{let t=Ve.get(e);t&&(Ve.delete(e),ha.delete(t),ep(n,t)&&n.remove(t))},pv=(n,e={})=>{let t=()=>e.requestRender?.(),r=n.events,o=s=>{Ve.has(s)&&en(n,s);for(let a of n.selection)a!==s&&Ve.has(a)&&en(n,a)},i=[r.on("object:added",s=>{s.syntheticOwner||Lo(n,s)&&t()}),r.on("object:removed",s=>{let a=ha.get(s);if(a){Ve.delete(a),ha.delete(s);return}Ve.has(s)&&mv(n,s)}),r.on("object:moving",s=>{o(s)}),r.on("object:scaling",s=>{o(s)}),r.on("object:rotating",s=>{o(s)}),r.on("object:modified",s=>{let a=!1;for(let l of s)Ve.has(l)&&(en(n,l),a=!0);a&&t()}),r.on("text:changed",s=>{Ve.has(s)&&(en(n,s),t())})];return()=>i.forEach(s=>s())};function rp(n,e,t,r,o){if(n.pageCount<2)return null;let i=n.route(r.x,r.y),s=n.activeIndex;if(!i||i.index===s)return null;let a=n.activeDoc,l=new Set(e),c=a.nodes.filter(b=>l.has(b)&&!b.syntheticOwner&&!Dt.has(b.id));if(!c.length||c.length!==l.size)return null;o(i.index);let u=i.doc,h=n.originAt(s),d=n.originAt(i.index),f=a.nodes.filter(b=>!b.syntheticOwner),m=c.map(b=>({index:f.indexOf(b),before:t?.get(b)??b.toObject(),after:b.toObject()})),p=new Set,g=(b,x)=>{if(x(b),b instanceof Z)for(let y of b.children)g(y,x)};for(let b of u.nodes)g(b,x=>{x.id&&p.add(x.id)});for(let b of c)a.remove(b),g(b,x=>{if(x.id&&p.has(x.id)){let y=x.id,S=1;for(;p.has(`${y}-transfer-${S}`);)S++;x.set({id:`${y}-transfer-${S}`})}x.id&&p.add(x.id)}),b.set({left:Number(b.raw.left??0)+h.x-d.x,top:Number(b.raw.top??0)+h.y-d.y}),u.add(b);return a.clearSelection(),c.forEach((b,x)=>{m[x].after=b.toObject()}),{sourceIndex:s,targetIndex:i.index,source:a,target:u,nodes:c,items:m}}var np=n=>Number.isFinite(Number(n.left))&&Number.isFinite(Number(n.top)),bv=(n,e)=>{let t=0;for(let r of n)r.id===e&&t++;return t},op=n=>{let e=n.objects;return Array.isArray(e)?e:[]},ip=(n,e)=>{if(!(n instanceof Z))return!0;let t=op(e);if(n.children.length!==t.length)return!1;for(let r=0;r<t.length;r++)if(!ip(n.children[r],t[r]))return!1;return!0},sp=(n,e)=>{let t=e.id;if(typeof t=="string"&&t&&n.id!==t&&n.set({id:t}),n instanceof Z){let r=op(e);for(let o=0;o<n.children.length;o++)r[o]&&sp(n.children[o],r[o])}},gv=(n,e)=>{let t=0;for(let r=0;r<n.nodes.length;r++)if(!n.nodes[r].syntheticOwner){if(t===e)return r;t++}return n.nodes.length};function Nc(n,e,t,r,o){if(n.pageCount<2||!Number.isSafeInteger(e)||!Number.isSafeInteger(t)||e<0||e>=n.pageCount||t<0||t>=n.pageCount||e===t||!r.length)return null;let i=n.pageAt(e),s=n.pageAt(t);if(!i||!s||i.pendingRaw||s.pendingRaw)return null;let a=i.doc,l=s.doc,c=[],u=[],h=new Set;for(let v of r){let T=v.before?.id,C=v.after?.id;if(typeof T!="string"||!T||typeof C!="string"||!C||!Number.isSafeInteger(v.index)||v.index<0||h.has(v.index)||!np(v.before)||!np(v.after))return null;c.push(T),u.push(C),h.add(v.index)}if(new Set(c).size!==r.length||new Set(u).size!==r.length)return null;let d=a.toObjects(),f=l.toObjects(),m=(v,T,C)=>v.every(R=>bv(T,R)===C),p=m(c,d,1)&&m(u,f,0),g=m(u,f,1)&&m(c,d,0);if(o?g:p)return{source:d,target:f};if(!(o?p:g))return null;let b=o?a:l,x=o?l:a,y=[];for(let v of r){let T=o?v.before.id:v.after.id,C=b.nodes.find(R=>R.id===T&&!R.syntheticOwner);if(!C||!ip(C,o?v.after:v.before))return null;y.push({node:C,item:v})}let S=o?y:[...y].sort((v,T)=>v.item.index-T.item.index);if(!o){let v=d.length;for(let{item:T}of S){if(T.index>v)return null;v++}}for(let{node:v,item:T}of S){let C=Number(T.after.left)-Number(T.before.left),R=Number(T.after.top)-Number(T.before.top),w=o?1:-1;kc(b,v),b.remove(v),sp(v,o?T.after:T.before),v.set({left:Number(v.raw.left??0)+w*C,top:Number(v.raw.top??0)+w*R}),o?x.add(v):x.insertAt(gv(x,T.index),v),Ac(x,v)}return{source:a.toObjects(),target:l.toObjects()}}var xv=(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}},fa=(n,e,t)=>e<0?null:e<n.boxes.length?n.boxes[e]:e===n.boxes.length?xv(n,t):null,yv=(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]===`
994
994
  `?s.push(-1):a<o.length?(s.push(a),a++):s.push(-1);let l=[],c=h=>{let d=s[h];return d===void 0||d===-1||d>=o.length?-1:d},u=0;for(let h of t){if(h.text.length===0)continue;if(h.text===`
995
- `){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,g=m,b=0,x=y=>{if(p>=y)return;let S=c(u+p),v=c(u+b);S===-1||v===-1||l.push({lineIndex:g,start:i[S],end:i[v]+1,info:d})};for(let y=0;y<h.text.length;y++){let S=c(u+y);if(S===-1){x(y),p=y+1;continue}let v=o[S];v!==m&&(x(y),p=y,m=v),g=v,b=y}x(h.text.length),u+=h.text.length}return l},Pc=(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},Km=n=>{let e=Ae(n);if(!e)return null;let t=je(e);return t?{left:t.left,top:t.top,width:t.right-t.left,height:t.bottom-t.top}:null},tv=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`},Lo=(n,e,t,r,o)=>{let i=ev(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,g=f.isFill?0:(f.strokeWidth||0)*Math.abs(f.scaleY)/2,b=f.translateX+m.left*f.scaleX-p,x=f.translateY+m.top*f.scaleY-g,y=f.translateX+(m.left+m.width)*f.scaleX+p,S=f.translateY+(m.top+m.height)*f.scaleY+g;b<a.minX&&(a.minX=b),x<a.minY&&(a.minY=x),y>a.maxX&&(a.maxX=y),S>a.maxY&&(a.maxY=S)};for(let f of i){let m=e.lines[f.lineIndex];if(!m)continue;let p=f.info,g=typeof p.path=="string"?p.path:"";if(!g)continue;let b=p.alignVertical||"center",x=p.isFill===!0,y=p.strokeWidth||0,S=-e.width/2+m.leftOffset,v=r+m.top,M=ua(m,f.start,o);if(!M)continue;if(p.isSingle===!0){let X=tv(g);if(!X)continue;let _=Km(X);if(!_||!Number.isFinite(_.width)||!Number.isFinite(_.height))continue;let D=X;for(let I=f.start;I<f.end;I++){let H=m.graphemes[I];if(!H||/^\s$/.test(H))continue;let z=ua(m,I,o),U=ua(m,I+1,o);if(!z)continue;let $=S+z.left,K=v,G=z.kernedWidth||z.width||(U?U.left:z.left)-z.left,Z=z.height,B=_.height;B||(B=Z);let j=_.width?G/_.width:1,Q=B?Z/B:1,ie=p.scale||1,ce=Math.min(j,Q)*ie,me=(_.width||0)*ce,Re=$+(G-me)/2-_.left*ce,De=b==="bottom"?K+Z-_.top*ce:Pc(K,Z,_.top,B,ce,b),et={d:D,translateX:Re,translateY:De,scaleX:ce,scaleY:ce,isFill:x,fill:p.fill||"#9FFFFC",stroke:p.stroke||"#9FFFFC",strokeWidth:y};s.push(et),l(et,_)}continue}let C=ua(m,f.end,o);if(!C)continue;let R=S+M.left,w=C.left-M.left,T=M.height,E=Km(g);if(!E||!Number.isFinite(E.width)||!Number.isFinite(E.height)||E.width===0)continue;let P=E.height;P||(P=T);let A=w/E.width,k=T/P,O=R-E.left*A,F=Pc(v,T,E.top,P,k,b);if(b==="bottom"||b==="top"){let X=E.top+P,_=X>0?X:P||1;k=T/_,F=Pc(v,T,E.top,P,k,b)}E.height||(F+=T/2);let W={d:g,translateX:O,translateY:F,scaleX:A,scaleY:k,isFill:x,fill:p.fill||"#9FFFFC",stroke:p.stroke||"#9FFFFC",strokeWidth:y};s.push(W),l(W,E)}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}},Qm=(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 He=2,nv=4*He,rv=384,ov=(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=Us(n,m,d),g=i[0]*p.x+i[2]*p.y+i[4],b=i[1]*p.x+i[3]*p.y+i[5];s=Math.min(s,g),a=Math.max(a,g),l=Math.min(l,b),c=Math.max(c,b)}}return{minX:s,maxX:a,minY:l,maxY:c}},kc=(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?Ar(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=yc(e,i,s);if(!p)return null;let g=document.createElement("canvas");g.width=f,g.height=m;let b=g.getContext("2d",{willReadFrequently:!0});if(!b)return null;b.setTransform(He,0,0,He,f/2,m/2),n.raw.vertical===!0?Ts(b,n):To(b,n),Eo(b,n,t);let x=b.getImageData(0,0,f,m),y=new Uint32Array(x.data.buffer),S=f,v=0,M=m,C=0,R=!1;for(let Pe=0;Pe<m;Pe++)for(let Ee=0;Ee<f;Ee++)(y[Pe*f+Ee]>>>24&255)>10&&(R=!0,Ee<S&&(S=Ee),Ee>v&&(v=Ee),Pe<M&&(M=Pe),Pe>C&&(C=Pe));if(!R)return null;let w=S,T=M,E=v+1-S,P=C+1-M,A=(h-i)/2*He,k=(d-s)/2*He,O=[He,0,0,He,A,k],F=(w-A)/He,W=(w+E-A)/He,X=(T-k)/He,_=(T+P-k)/He,D=F/i,I=W/i,H=X/s,z=_/s,U=ov(p,D,I,H,z,O),$=Math.floor(U.minX)-1,K=Math.floor(U.minY)-1,G=Math.max(1,Math.ceil(U.maxX+1)-$),Z=Math.max(1,Math.ceil(U.maxY+1)-K);if(G>8192||Z>8192)return null;let B=vc(p,0,0,i,s,F,X,W,_,E,P,[He,0,0,He,A-$,k-K],nv,rv);if(!B)return null;let j=b.createImageData(G,Z),Q=new Uint32Array(j.data.buffer),ie=new Uint8Array(G*Z),ce=(Pe,Ee)=>{let ue=Math.min(E-1,Math.max(0,Pe)),ye=Math.min(P-1,Math.max(0,Ee)),fe=Math.floor(ue),we=Math.floor(ye),tt=Math.min(E-1,fe+1),Ve=Math.min(P-1,we+1),Xe=ue-fe,gt=ye-we,xt=y[(T+we)*f+(w+fe)],yt=y[(T+we)*f+(w+tt)],vt=y[(T+Ve)*f+(w+tt)],St=y[(T+Ve)*f+(w+fe)],_n=xt>>>24&255,Dn=yt>>>24&255,Do=vt>>>24&255,Fo=St>>>24&255;if(_n<=10&&Dn<=10&&Do<=10&&Fo<=10)return 0;let ze=(wt,wa,Ta)=>wt+(wa-wt)*Ta,lr=Math.round(ze(ze(xt&255,yt&255,Xe),ze(St&255,vt&255,Xe),gt)),Br=Math.round(ze(ze(xt>>>8&255,yt>>>8&255,Xe),ze(St>>>8&255,vt>>>8&255,Xe),gt)),Oo=Math.round(ze(ze(xt>>>16&255,yt>>>16&255,Xe),ze(St>>>16&255,vt>>>16&255,Xe),gt));return Math.round(ze(ze(_n,Dn,Xe),ze(Fo,Do,Xe),gt))<<24|Oo<<16|Br<<8|lr};for(let Pe=0;Pe+1<B.rows;Pe++)for(let Ee=0;Ee+1<B.columns;Ee++){let ue=Pe*B.columns+Ee,ye=ue+1,fe=ue+B.columns,we=fe+1,tt=B.docXs[ue],Ve=B.docYs[ue],Xe=B.docXs[ye],gt=B.docYs[ye],xt=B.docXs[we],yt=B.docYs[we],vt=B.docXs[fe],St=B.docYs[fe],_n=Math.max(0,Math.floor(Math.min(tt,Xe,xt,vt))),Dn=Math.min(G-1,Math.ceil(Math.max(tt,Xe,xt,vt))),Do=Math.max(0,Math.floor(Math.min(Ve,gt,yt,St))),Fo=Math.min(Z-1,Math.ceil(Math.max(Ve,gt,yt,St)));for(let ze=Do;ze<=Fo;ze++)for(let lr=_n;lr<=Dn;lr++){let Br=ze*G+lr;if(ie[Br])continue;let Oo=Sc(lr+.5,ze+.5,tt,Ve,Xe,gt,xt,yt,vt,St);if(!Oo)continue;ie[Br]=1;let{s:zt,t:wt}=Oo,wa=(1-zt)*(1-wt)*B.sourceXs[ue]+zt*(1-wt)*B.sourceXs[ye]+zt*wt*B.sourceXs[we]+(1-zt)*wt*B.sourceXs[fe],Ta=(1-zt)*(1-wt)*B.sourceYs[ue]+zt*(1-wt)*B.sourceYs[ye]+zt*wt*B.sourceYs[we]+(1-zt)*wt*B.sourceYs[fe];Q[Br]=ce(wa,Ta)}}let me=document.createElement("canvas");me.width=G,me.height=Z;let Re=me.getContext("2d");if(!Re)return null;Re.putImageData(j,0,0);let De=($+G/2)/He-h/2,et=(K+Z/2)/He-d/2;return{canvas:me,logicalW:G/He,logicalH:Z/He,offsetX:De,offsetY:et}};var Zm=new Map,ha=(n,e)=>{let t=n.worldScale;return e*Math.max(t.x,t.y,1e-6)},Dr=(n,e)=>{let t=Zm.get(n);if(!t){let r=ae(n);t=[r[0],r[1],r[2],r[3]],Zm.set(n,t)}return[t[0],t[1],t[2],t[3]*e[3]]},da=class{gl;batch;glyphAtlas;warpBakes=new WeakMap;psdWarpBakes=new WeakMap;arcBakes=new WeakMap;textDashBakes=new WeakMap;scrollBakes=new WeakMap;highlightBakes=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]){let r=t.get(e);r?.tex&&this.gl.deleteTexture(r.tex),t.delete(e)}}renderWarpedText(e,t){let r=Jt(e.raw.effects,{text:!0}),o=[e.raw.type,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?Cn(r):""].join(";"),i=this.warpBakes.get(e);if(i&&i.sig!==o&&(this.gl.deleteTexture(i.tex),i=void 0),!i){let s=cc(e,t,r);if(!s){this.warpBakes.set(e,void 0);return}let a=ke(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=Jt(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?Cn(r):""].join(";"),i=this.psdWarpBakes.get(e);if(i&&i.sig!==o&&(this.gl.deleteTexture(i.tex),i=void 0),!i){let a=kc(e,t,r);if(!a){this.psdWarpBakes.set(e,void 0);return}let l=ke(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?Y(e.matrix,At({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=Jt(e.raw.effects,{text:!0}),i=!!o&&(o.dropShadows.length>0||o.solidFills.length>0||o.strokes.length>0);if(su()&&!i){this.renderArcGlyphs(e,t,r);return}let s=Qt(ha(e,r)),a=[e.raw.type,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?Cn(o):"",s].join(";"),l=this.arcBakes.get(e);if(l&&l.sig!==a&&(this.gl.deleteTexture(l.tex),l=void 0),!l){let c=uc(e,t,o,s);if(!c){this.arcBakes.set(e,void 0);return}let u=ke(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=Mt(e.textLayout,e.raw,e.textStyle.lineHeight??1.16),i=Qt(ha(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=Tn(s,m),g=typeof m?.fill=="string"&&m.fill?m.fill:u,b=l?Fe(a,m):null,x=f.x-o.contentOffsetX,y=f.y-o.contentOffsetY,S=Math.cos(f.rotation),v=Math.sin(f.rotation),M=C=>{if(C){if(!b||b.width<=0)return}else if(!g)return;let{rs:R,scale:w}=Ns(p.fontSize,i),T=this.glyphAtlas.get(p,R,f.char,C?b:null);if(!T)return;let E=T.wPx/w,P=T.hPx/w,A=(T.inkLeftPx-T.advancePx/2-T.padPx)/w+E/2,k=-(T.ascentPx+T.padPx)/w+P/2,O=Dr(C?b.color:g,d),F=Y(h,Y([1,0,0,1,x,y],Y([S,v,-v,S,0,0],[1,0,0,1,A,k])));this.batch.pushQuad(F,E,P,O,this.glyphAtlas.textureOf(T),[T.u0,T.v0,T.u1,T.v1])};c?(M(!0),M(!1)):(M(!1),M(!0))}}renderTextGlyphs(e,t){if(Es(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=Qt(ha(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=Qt(ha(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=Wf(e,r,e.scrollOffset);if(!a){this.scrollBakes.set(e,void 0);return}let l=ke(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(e.matrix,s.w,s.h,[1,1,1,e.renderOpacity],s.tex),this.renderTextDecorations(e,"overline"),this.renderTextDecorations(e,"linethrough")}renderTextBackgrounds(e){let t=e.textLayout,r=e.renderOpacity,o=e.matrix,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=ae(d),g=[p[0],p[1],p[2],p[3]*r],b=Y(o,[1,0,0,1,m+h/2,l+s.implHeight/2]);this.batch.pushQuad(b,h,s.implHeight,g,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=e.matrix;for(let a of r.lines){let l=Va(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(Y(s,[1,0,0,1,d,f]),h.width,h.thickness,Dr(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=Ut(e.raw.textAlign),u=e.raw.textAlign===pe.DISPERSE,h=Number(e.raw.textOffsetY)||0,d=Fu(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 g=[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(";"),b=this.textDashBakes.get(e);if(b&&b.sig!==g&&(this.gl.deleteTexture(b.tex),b=void 0),!b){let x=document.createElement("canvas");x.width=Math.ceil(m*t),x.height=Math.ceil(p*t);let y=x.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 S=r.width/2+f,v=r.height/2+f+e.contentTopY,M=e.raw.vertical===!0,C=0;for(let w of r.lines){let T=-r.width/2+w.leftOffset,E=v+w.baseline;if(M){w.prefix&&Et(y,w,S+T,E,{stroke:Fe(s,w.charStyles[0])});let D=qt(w,T,E,o,l);for(let I=0;I<D.length;I++){let H=Fe(s,w.charStyles[I]);if(!H||H.width<=0)continue;let z=yn(o,w.charStyles[I]);y.font=Me(z,z.fontSize),y.lineWidth=H.width,y.strokeStyle=H.color,Kt(y,{...D[I],y:D[I].y+Tt(h,z.fontSize,C+I)},"strokeText")}C+=w.graphemes.length;continue}let P=Yr(e.raw.textAlign)&&w.graphemes.some(D=>jr.test(D)),A="",k=w.prefix?Et(y,w,S+T,E,{stroke:Fe(s,w.charStyles[0])}):0,O=0,F="",W=null,X,_=D=>{if(!A)return;let I=W;I&&I.width>0&&(y.font=F,y.lineWidth=I.width,y.strokeStyle=I.color,y.strokeText(A,S+T+k,E+O)),A="",D<w.boxes.length&&(k=w.boxes[D].left)};for(let D=0;D<w.graphemes.length;D++){let I=w.charStyles[D],z=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,U=Me(z,z.fontSize),$=Fe(s,I),K=I?.fill??"",G=W;A&&(U!==F||$?.color!==G?.color||$?.width!==G?.width||K!==X)&&_(D),A||(F=U,W=$,X=K,O=Tt(h,z.fontSize,C+D)),A+=w.graphemes[D],(l||h!==0||(c||u)&&/[ \t\r]/.test(w.graphemes[D])||P)&&_(D+1)}_(w.graphemes.length),C+=w.graphemes.length}let R=ke(this.gl,x);if(!R)return;b={sig:g,tex:R,w:m,h:p},this.textDashBakes.set(e,b)}this.batch.pushQuad(e.matrix,b.w,b.h,[1,1,1,e.renderOpacity],b.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=Lo(r.text??"",o,r.texts,e.contentTopY,e.textStyle.fontSize);if(!a){this.highlightBakes.set(e,void 0);return}let l=Qm(a,o,e.contentTopY,t);if(!l)return;let c=ke(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(Y(e.matrix,[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=e.matrix,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,g=0;for(let b of o.lines){let x=-o.width/2+b.leftOffset,y=e.contentTopY+b.baseline;if(b.prefix)if(t==="stroke"){let v=Fe(h,b.charStyles[0]);v&&v.width>0&&this.pushPrefixGlyphs(e,b.prefix,x,y,v,Dr(v.color,d),r)}else{let v=b.charStyles[0]?.fill;(v||u)&&this.pushPrefixGlyphs(e,b.prefix,x,y,null,v?Dr(v,c):c,r)}let S=0;for(let v=0;v<b.graphemes.length;v++){let M=b.charStyles[v],C,R=null;if(t==="stroke"){if(R=Fe(h,M),!R)continue;C=Dr(R.color,d)}else{let _=M?.fill;if(!_&&!u)continue;C=_?Dr(_,c):c}let T=M!==void 0&&(M.fontSize!==void 0||M.fontFamily!==void 0||M.fontWeight!==void 0||M.fontStyle!==void 0)&&M?{...i,fontSize:M.fontSize??i.fontSize,fontFamily:M.fontFamily??i.fontFamily,fontWeight:M.fontWeight??i.fontWeight,fontStyle:M.fontStyle??i.fontStyle}:i,E=Tt(p,T.fontSize,g+v),{rs:P,scale:A}=Ns(T.fontSize,r),k=this.glyphAtlas.get(T,P,b.graphemes[v],R);if(!k)continue;let O=b.boxes[v],F=k.wPx/A,W=k.hPx/A,X;if(f){let _=b.graphemes[v],D=Yn(_),I=T.fontSize,H=Un(_,O,m);if(D==="latin"||D==="bracket"){let U=x+S+(D==="latin"?O.kernedWidth-O.width:0)+(k.inkLeftPx-k.padPx)/A,$=y+E-(k.ascentPx+k.padPx)/A;X=Y(s,[1,0,0,1,U+F/2,$+W/2])}else{let z=x+S+an(I),U=y+E+dr(D,O,I),$=(k.inkLeftPx-k.padPx)/A+F/2,K=W/2-(k.ascentPx+k.padPx)/A;X=Y(s,Y([1,0,0,1,z,U],Y([0,-1,1,0,0,0],[1,0,0,1,$,K])))}S+=H}else{let D=x+O.left+(k.inkLeftPx-k.padPx)/A,I=y+E-(k.ascentPx+k.padPx)/A;X=Y(s,[1,0,0,1,D+F/2,I+W/2])}this.batch.pushQuad(X,F,W,C,this.glyphAtlas.textureOf(k),[k.u0,k.v0,k.u1,k.v1])}g+=b.graphemes.length}}pushPrefixGlyphs(e,t,r,o,i,s,a){let l=zn(t.text),c=r;for(let u=0;u<l.length;u++){let{rs:h,scale:d}=Ns(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,g=c+(f.inkLeftPx-f.padPx)/d,b=o-(f.ascentPx+f.padPx)/d;this.batch.pushQuad(Y(e.matrix,[1,0,0,1,g+m/2,b+p/2]),m,p,s,this.glyphAtlas.textureOf(f),[f.u0,f.v0,f.u1,f.v1])}c+=t.advances[u]??0}}};var Jm=(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}},Ac=(n,e)=>{let t=e.outWidth/n.width,r=e.outHeight/n.height;return[t,0,0,r,-n.left*t,-n.top*r]},ep=(n,e)=>Nt(Ac(n,e),e.outWidth,e.outHeight,1),fa=(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 iv=n=>typeof n.fenceSync=="function"&&typeof n.clientWaitSync=="function"&&typeof n.getBufferSubData=="function",sv=(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()}),ma=class{constructor(e){this.host=e}host;exportToPixels(e){let t=this.renderAndStage(e,!1);return t?{width:t.outWidth,height:t.outHeight,data:fa(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:fa(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]),o.clear(o.COLOR_BUFFER_BIT),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=Jm(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=o.createTexture(),d=o.createFramebuffer(),f=null,m=new Uint8Array(0),p=null,g=!1;try{if(o.bindTexture(o.TEXTURE_2D,h),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,d),o.framebufferTexture2D(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.TEXTURE_2D,h,0),o.checkFramebufferStatus(o.FRAMEBUFFER)!==o.FRAMEBUFFER_COMPLETE)return null;f=this.host.applyExportViewport(Ac(e,r),i,s);let b=ep(e,r);if(o.viewport(0,0,i,s),this.renderRounds(d,a,b),o.bindFramebuffer(o.FRAMEBUFFER,d),t&&iv(o)){let x=o.createBuffer();o.bindBuffer(o.PIXEL_PACK_BUFFER,x),o.bufferData(o.PIXEL_PACK_BUFFER,l,o.STREAM_READ),o.readPixels(0,0,i,s,o.RGBA,o.UNSIGNED_BYTE,0);let y=o.fenceSync(o.SYNC_GPU_COMMANDS_COMPLETE,0);o.flush(),o.bindBuffer(o.PIXEL_PACK_BUFFER,u.packBuffer),p={gl:o,pbo:x,fence:y,byteLength:l},g=!0}else m=new Uint8Array(l),o.readPixels(0,0,i,s,o.RGBA,o.UNSIGNED_BYTE,m)}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),f?.(),d&&o.deleteFramebuffer(d),h&&o.deleteTexture(h),p&&!g&&(o.deleteBuffer(p.pbo),p.fence&&o.deleteSync(p.fence)),this.host.bakeKReuseFloor=c,this.host.requestRenderAll()}return p?{outWidth:i,outHeight:s,raw:m,stagedReadback:p}:m.length?{outWidth:i,outHeight:s,raw:m,stagedReadback:null}:null}async drainStagedReadback(e){let{gl:t,pbo:r,fence:o,byteLength:i}=e;try{if(o&&await sv(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 Nc=[.8705882352941177,.8627450980392157,.8627450980392157],av=8,lv=`#version 300 es
995
+ `){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,g=m,b=0,x=y=>{if(p>=y)return;let S=c(u+p),v=c(u+b);S===-1||v===-1||l.push({lineIndex:g,start:i[S],end:i[v]+1,info:d})};for(let y=0;y<h.text.length;y++){let S=c(u+y);if(S===-1){x(y),p=y+1;continue}let v=o[S];v!==m&&(x(y),p=y,m=v),g=v,b=y}x(h.text.length),u+=h.text.length}return l},Lc=(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},ap=n=>{let e=Ae(n);if(!e)return null;let t=qe(e);return t?{left:t.left,top:t.top,width:t.right-t.left,height:t.bottom-t.top}:null},vv=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`},Io=(n,e,t,r,o)=>{let i=yv(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,g=f.isFill?0:(f.strokeWidth||0)*Math.abs(f.scaleY)/2,b=f.translateX+m.left*f.scaleX-p,x=f.translateY+m.top*f.scaleY-g,y=f.translateX+(m.left+m.width)*f.scaleX+p,S=f.translateY+(m.top+m.height)*f.scaleY+g;b<a.minX&&(a.minX=b),x<a.minY&&(a.minY=x),y>a.maxX&&(a.maxX=y),S>a.maxY&&(a.maxY=S)};for(let f of i){let m=e.lines[f.lineIndex];if(!m)continue;let p=f.info,g=typeof p.path=="string"?p.path:"";if(!g)continue;let b=p.alignVertical||"center",x=p.isFill===!0,y=p.strokeWidth||0,S=-e.width/2+m.leftOffset,v=r+m.top,T=fa(m,f.start,o);if(!T)continue;if(p.isSingle===!0){let X=vv(g);if(!X)continue;let _=ap(X);if(!_||!Number.isFinite(_.width)||!Number.isFinite(_.height))continue;let D=X;for(let I=f.start;I<f.end;I++){let H=m.graphemes[I];if(!H||/^\s$/.test(H))continue;let z=fa(m,I,o),U=fa(m,I+1,o);if(!z)continue;let $=S+z.left,K=v,G=z.kernedWidth||z.width||(U?U.left:z.left)-z.left,J=z.height,B=_.height;B||(B=J);let j=_.width?G/_.width:1,Q=B?J/B:1,ie=p.scale||1,ce=Math.min(j,Q)*ie,me=(_.width||0)*ce,Re=$+(G-me)/2-_.left*ce,De=b==="bottom"?K+J-_.top*ce:Lc(K,J,_.top,B,ce,b),tt={d:D,translateX:Re,translateY:De,scaleX:ce,scaleY:ce,isFill:x,fill:p.fill||"#9FFFFC",stroke:p.stroke||"#9FFFFC",strokeWidth:y};s.push(tt),l(tt,_)}continue}let C=fa(m,f.end,o);if(!C)continue;let R=S+T.left,w=C.left-T.left,E=T.height,M=ap(g);if(!M||!Number.isFinite(M.width)||!Number.isFinite(M.height)||M.width===0)continue;let P=M.height;P||(P=E);let A=w/M.width,k=E/P,O=R-M.left*A,F=Lc(v,E,M.top,P,k,b);if(b==="bottom"||b==="top"){let X=M.top+P,_=X>0?X:P||1;k=E/_,F=Lc(v,E,M.top,P,k,b)}M.height||(F+=E/2);let W={d:g,translateX:O,translateY:F,scaleX:A,scaleY:k,isFill:x,fill:p.fill||"#9FFFFC",stroke:p.stroke||"#9FFFFC",strokeWidth:y};s.push(W),l(W,M)}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}},lp=(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 He=2,Sv=4*He,wv=384,Tv=(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=$s(n,m,d),g=i[0]*p.x+i[2]*p.y+i[4],b=i[1]*p.x+i[3]*p.y+i[5];s=Math.min(s,g),a=Math.max(a,g),l=Math.min(l,b),c=Math.max(c,b)}}return{minX:s,maxX:a,minY:l,maxY:c}},Ic=(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?Nr(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=yc(e,i,s);if(!p)return null;let g=document.createElement("canvas");g.width=f,g.height=m;let b=g.getContext("2d",{willReadFrequently:!0});if(!b)return null;b.setTransform(He,0,0,He,f/2,m/2),n.raw.vertical===!0?Es(b,n):To(b,n),Eo(b,n,t);let x=b.getImageData(0,0,f,m),y=new Uint32Array(x.data.buffer),S=f,v=0,T=m,C=0,R=!1;for(let Pe=0;Pe<m;Pe++)for(let Ee=0;Ee<f;Ee++)(y[Pe*f+Ee]>>>24&255)>10&&(R=!0,Ee<S&&(S=Ee),Ee>v&&(v=Ee),Pe<T&&(T=Pe),Pe>C&&(C=Pe));if(!R)return null;let w=S,E=T,M=v+1-S,P=C+1-T,A=(h-i)/2*He,k=(d-s)/2*He,O=[He,0,0,He,A,k],F=(w-A)/He,W=(w+M-A)/He,X=(E-k)/He,_=(E+P-k)/He,D=F/i,I=W/i,H=X/s,z=_/s,U=Tv(p,D,I,H,z,O),$=Math.floor(U.minX)-1,K=Math.floor(U.minY)-1,G=Math.max(1,Math.ceil(U.maxX+1)-$),J=Math.max(1,Math.ceil(U.maxY+1)-K);if(G>8192||J>8192)return null;let B=vc(p,0,0,i,s,F,X,W,_,M,P,[He,0,0,He,A-$,k-K],Sv,wv);if(!B)return null;let j=b.createImageData(G,J),Q=new Uint32Array(j.data.buffer),ie=new Uint8Array(G*J),ce=(Pe,Ee)=>{let ue=Math.min(M-1,Math.max(0,Pe)),ye=Math.min(P-1,Math.max(0,Ee)),fe=Math.floor(ue),we=Math.floor(ye),nt=Math.min(M-1,fe+1),je=Math.min(P-1,we+1),Xe=ue-fe,gt=ye-we,xt=y[(E+we)*f+(w+fe)],yt=y[(E+we)*f+(w+nt)],vt=y[(E+je)*f+(w+nt)],St=y[(E+je)*f+(w+fe)],Dn=xt>>>24&255,Fn=yt>>>24&255,Fo=vt>>>24&255,Oo=St>>>24&255;if(Dn<=10&&Fn<=10&&Fo<=10&&Oo<=10)return 0;let ze=(wt,wa,Ta)=>wt+(wa-wt)*Ta,cr=Math.round(ze(ze(xt&255,yt&255,Xe),ze(St&255,vt&255,Xe),gt)),Br=Math.round(ze(ze(xt>>>8&255,yt>>>8&255,Xe),ze(St>>>8&255,vt>>>8&255,Xe),gt)),Bo=Math.round(ze(ze(xt>>>16&255,yt>>>16&255,Xe),ze(St>>>16&255,vt>>>16&255,Xe),gt));return Math.round(ze(ze(Dn,Fn,Xe),ze(Oo,Fo,Xe),gt))<<24|Bo<<16|Br<<8|cr};for(let Pe=0;Pe+1<B.rows;Pe++)for(let Ee=0;Ee+1<B.columns;Ee++){let ue=Pe*B.columns+Ee,ye=ue+1,fe=ue+B.columns,we=fe+1,nt=B.docXs[ue],je=B.docYs[ue],Xe=B.docXs[ye],gt=B.docYs[ye],xt=B.docXs[we],yt=B.docYs[we],vt=B.docXs[fe],St=B.docYs[fe],Dn=Math.max(0,Math.floor(Math.min(nt,Xe,xt,vt))),Fn=Math.min(G-1,Math.ceil(Math.max(nt,Xe,xt,vt))),Fo=Math.max(0,Math.floor(Math.min(je,gt,yt,St))),Oo=Math.min(J-1,Math.ceil(Math.max(je,gt,yt,St)));for(let ze=Fo;ze<=Oo;ze++)for(let cr=Dn;cr<=Fn;cr++){let Br=ze*G+cr;if(ie[Br])continue;let Bo=Sc(cr+.5,ze+.5,nt,je,Xe,gt,xt,yt,vt,St);if(!Bo)continue;ie[Br]=1;let{s:zt,t:wt}=Bo,wa=(1-zt)*(1-wt)*B.sourceXs[ue]+zt*(1-wt)*B.sourceXs[ye]+zt*wt*B.sourceXs[we]+(1-zt)*wt*B.sourceXs[fe],Ta=(1-zt)*(1-wt)*B.sourceYs[ue]+zt*(1-wt)*B.sourceYs[ye]+zt*wt*B.sourceYs[we]+(1-zt)*wt*B.sourceYs[fe];Q[Br]=ce(wa,Ta)}}let me=document.createElement("canvas");me.width=G,me.height=J;let Re=me.getContext("2d");if(!Re)return null;Re.putImageData(j,0,0);let De=($+G/2)/He-h/2,tt=(K+J/2)/He-d/2;return{canvas:me,logicalW:G/He,logicalH:J/He,offsetX:De,offsetY:tt}};var cp=new Map,ma=(n,e)=>{let t=n.worldScale;return e*Math.max(t.x,t.y,1e-6)},Dr=(n,e)=>{let t=cp.get(n);if(!t){let r=ae(n);t=[r[0],r[1],r[2],r[3]],cp.set(n,t)}return[t[0],t[1],t[2],t[3]*e[3]]},pa=class{gl;batch;glyphAtlas;warpBakes=new WeakMap;psdWarpBakes=new WeakMap;arcBakes=new WeakMap;textDashBakes=new WeakMap;scrollBakes=new WeakMap;highlightBakes=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]){let r=t.get(e);r?.tex&&this.gl.deleteTexture(r.tex),t.delete(e)}}renderWarpedText(e,t){let r=Jt(e.raw.effects,{text:!0}),o=[e.raw.type,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?Rn(r):""].join(";"),i=this.warpBakes.get(e);if(i&&i.sig!==o&&(this.gl.deleteTexture(i.tex),i=void 0),!i){let s=cc(e,t,r);if(!s){this.warpBakes.set(e,void 0);return}let a=ke(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=Jt(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?Rn(r):""].join(";"),i=this.psdWarpBakes.get(e);if(i&&i.sig!==o&&(this.gl.deleteTexture(i.tex),i=void 0),!i){let a=Ic(e,t,r);if(!a){this.psdWarpBakes.set(e,void 0);return}let l=ke(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?Y(e.matrix,At({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=Jt(e.raw.effects,{text:!0}),i=!!o&&(o.dropShadows.length>0||o.solidFills.length>0||o.strokes.length>0);if(uu()&&!i){this.renderArcGlyphs(e,t,r);return}let s=Qt(ma(e,r)),a=[e.raw.type,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?Rn(o):"",s].join(";"),l=this.arcBakes.get(e);if(l&&l.sig!==a&&(this.gl.deleteTexture(l.tex),l=void 0),!l){let c=uc(e,t,o,s);if(!c){this.arcBakes.set(e,void 0);return}let u=ke(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=Mt(e.textLayout,e.raw,e.textStyle.lineHeight??1.16),i=Qt(ma(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=En(s,m),g=typeof m?.fill=="string"&&m.fill?m.fill:u,b=l?Fe(a,m):null,x=f.x-o.contentOffsetX,y=f.y-o.contentOffsetY,S=Math.cos(f.rotation),v=Math.sin(f.rotation),T=C=>{if(C){if(!b||b.width<=0)return}else if(!g)return;let{rs:R,scale:w}=Ls(p.fontSize,i),E=this.glyphAtlas.get(p,R,f.char,C?b:null);if(!E)return;let M=E.wPx/w,P=E.hPx/w,A=(E.inkLeftPx-E.advancePx/2-E.padPx)/w+M/2,k=-(E.ascentPx+E.padPx)/w+P/2,O=Dr(C?b.color:g,d),F=Y(h,Y([1,0,0,1,x,y],Y([S,v,-v,S,0,0],[1,0,0,1,A,k])));this.batch.pushQuad(F,M,P,O,this.glyphAtlas.textureOf(E),[E.u0,E.v0,E.u1,E.v1])};c?(T(!0),T(!1)):(T(!1),T(!0))}}renderTextGlyphs(e,t){if(Ms(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=Qt(ma(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=Qt(ma(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=Yf(e,r,e.scrollOffset);if(!a){this.scrollBakes.set(e,void 0);return}let l=ke(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(e.matrix,s.w,s.h,[1,1,1,e.renderOpacity],s.tex),this.renderTextDecorations(e,"overline"),this.renderTextDecorations(e,"linethrough")}renderTextBackgrounds(e){let t=e.textLayout,r=e.renderOpacity,o=e.matrix,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=ae(d),g=[p[0],p[1],p[2],p[3]*r],b=Y(o,[1,0,0,1,m+h/2,l+s.implHeight/2]);this.batch.pushQuad(b,h,s.implHeight,g,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=e.matrix;for(let a of r.lines){let l=Va(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(Y(s,[1,0,0,1,d,f]),h.width,h.thickness,Dr(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=Ut(e.raw.textAlign),u=e.raw.textAlign===pe.DISPERSE,h=Number(e.raw.textOffsetY)||0,d=Wu(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 g=[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(";"),b=this.textDashBakes.get(e);if(b&&b.sig!==g&&(this.gl.deleteTexture(b.tex),b=void 0),!b){let x=document.createElement("canvas");x.width=Math.ceil(m*t),x.height=Math.ceil(p*t);let y=x.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 S=r.width/2+f,v=r.height/2+f+e.contentTopY,T=e.raw.vertical===!0,C=0;for(let w of r.lines){let E=-r.width/2+w.leftOffset,M=v+w.baseline;if(T){w.prefix&&Et(y,w,S+E,M,{stroke:Fe(s,w.charStyles[0])});let D=qt(w,E,M,o,l);for(let I=0;I<D.length;I++){let H=Fe(s,w.charStyles[I]);if(!H||H.width<=0)continue;let z=vn(o,w.charStyles[I]);y.font=Me(z,z.fontSize),y.lineWidth=H.width,y.strokeStyle=H.color,Kt(y,{...D[I],y:D[I].y+Tt(h,z.fontSize,C+I)},"strokeText")}C+=w.graphemes.length;continue}let P=Yr(e.raw.textAlign)&&w.graphemes.some(D=>jr.test(D)),A="",k=w.prefix?Et(y,w,S+E,M,{stroke:Fe(s,w.charStyles[0])}):0,O=0,F="",W=null,X,_=D=>{if(!A)return;let I=W;I&&I.width>0&&(y.font=F,y.lineWidth=I.width,y.strokeStyle=I.color,y.strokeText(A,S+E+k,M+O)),A="",D<w.boxes.length&&(k=w.boxes[D].left)};for(let D=0;D<w.graphemes.length;D++){let I=w.charStyles[D],z=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,U=Me(z,z.fontSize),$=Fe(s,I),K=I?.fill??"",G=W;A&&(U!==F||$?.color!==G?.color||$?.width!==G?.width||K!==X)&&_(D),A||(F=U,W=$,X=K,O=Tt(h,z.fontSize,C+D)),A+=w.graphemes[D],(l||h!==0||(c||u)&&/[ \t\r]/.test(w.graphemes[D])||P)&&_(D+1)}_(w.graphemes.length),C+=w.graphemes.length}let R=ke(this.gl,x);if(!R)return;b={sig:g,tex:R,w:m,h:p},this.textDashBakes.set(e,b)}this.batch.pushQuad(e.matrix,b.w,b.h,[1,1,1,e.renderOpacity],b.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=Io(r.text??"",o,r.texts,e.contentTopY,e.textStyle.fontSize);if(!a){this.highlightBakes.set(e,void 0);return}let l=lp(a,o,e.contentTopY,t);if(!l)return;let c=ke(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(Y(e.matrix,[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=e.matrix,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,g=0;for(let b of o.lines){let x=-o.width/2+b.leftOffset,y=e.contentTopY+b.baseline;if(b.prefix)if(t==="stroke"){let v=Fe(h,b.charStyles[0]);v&&v.width>0&&this.pushPrefixGlyphs(e,b.prefix,x,y,v,Dr(v.color,d),r)}else{let v=b.charStyles[0]?.fill;(v||u)&&this.pushPrefixGlyphs(e,b.prefix,x,y,null,v?Dr(v,c):c,r)}let S=0;for(let v=0;v<b.graphemes.length;v++){let T=b.charStyles[v],C,R=null;if(t==="stroke"){if(R=Fe(h,T),!R)continue;C=Dr(R.color,d)}else{let _=T?.fill;if(!_&&!u)continue;C=_?Dr(_,c):c}let E=T!==void 0&&(T.fontSize!==void 0||T.fontFamily!==void 0||T.fontWeight!==void 0||T.fontStyle!==void 0)&&T?{...i,fontSize:T.fontSize??i.fontSize,fontFamily:T.fontFamily??i.fontFamily,fontWeight:T.fontWeight??i.fontWeight,fontStyle:T.fontStyle??i.fontStyle}:i,M=Tt(p,E.fontSize,g+v),{rs:P,scale:A}=Ls(E.fontSize,r),k=this.glyphAtlas.get(E,P,b.graphemes[v],R);if(!k)continue;let O=b.boxes[v],F=k.wPx/A,W=k.hPx/A,X;if(f){let _=b.graphemes[v],D=Un(_),I=E.fontSize,H=$n(_,O,m);if(D==="latin"||D==="bracket"){let U=x+S+(D==="latin"?O.kernedWidth-O.width:0)+(k.inkLeftPx-k.padPx)/A,$=y+M-(k.ascentPx+k.padPx)/A;X=Y(s,[1,0,0,1,U+F/2,$+W/2])}else{let z=x+S+ln(I),U=y+M+fr(D,O,I),$=(k.inkLeftPx-k.padPx)/A+F/2,K=W/2-(k.ascentPx+k.padPx)/A;X=Y(s,Y([1,0,0,1,z,U],Y([0,-1,1,0,0,0],[1,0,0,1,$,K])))}S+=H}else{let D=x+O.left+(k.inkLeftPx-k.padPx)/A,I=y+M-(k.ascentPx+k.padPx)/A;X=Y(s,[1,0,0,1,D+F/2,I+W/2])}this.batch.pushQuad(X,F,W,C,this.glyphAtlas.textureOf(k),[k.u0,k.v0,k.u1,k.v1])}g+=b.graphemes.length}}pushPrefixGlyphs(e,t,r,o,i,s,a){let l=Yn(t.text),c=r;for(let u=0;u<l.length;u++){let{rs:h,scale:d}=Ls(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,g=c+(f.inkLeftPx-f.padPx)/d,b=o-(f.ascentPx+f.padPx)/d;this.batch.pushQuad(Y(e.matrix,[1,0,0,1,g+m/2,b+p/2]),m,p,s,this.glyphAtlas.textureOf(f),[f.u0,f.v0,f.u1,f.v1])}c+=t.advances[u]??0}}};var up=(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}},_c=(n,e)=>{let t=e.outWidth/n.width,r=e.outHeight/n.height;return[t,0,0,r,-n.left*t,-n.top*r]},hp=(n,e)=>Nt(_c(n,e),e.outWidth,e.outHeight,1),ba=(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 Ev=n=>typeof n.fenceSync=="function"&&typeof n.clientWaitSync=="function"&&typeof n.getBufferSubData=="function",Mv=(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()}),ga=class{constructor(e){this.host=e}host;exportToPixels(e){let t=this.renderAndStage(e,!1);return t?{width:t.outWidth,height:t.outHeight,data:ba(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:ba(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]),o.clear(o.COLOR_BUFFER_BIT),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=up(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=o.createTexture(),d=o.createFramebuffer(),f=null,m=new Uint8Array(0),p=null,g=!1;try{if(o.bindTexture(o.TEXTURE_2D,h),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,d),o.framebufferTexture2D(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.TEXTURE_2D,h,0),o.checkFramebufferStatus(o.FRAMEBUFFER)!==o.FRAMEBUFFER_COMPLETE)return null;f=this.host.applyExportViewport(_c(e,r),i,s);let b=hp(e,r);if(o.viewport(0,0,i,s),this.renderRounds(d,a,b),o.bindFramebuffer(o.FRAMEBUFFER,d),t&&Ev(o)){let x=o.createBuffer();o.bindBuffer(o.PIXEL_PACK_BUFFER,x),o.bufferData(o.PIXEL_PACK_BUFFER,l,o.STREAM_READ),o.readPixels(0,0,i,s,o.RGBA,o.UNSIGNED_BYTE,0);let y=o.fenceSync(o.SYNC_GPU_COMMANDS_COMPLETE,0);o.flush(),o.bindBuffer(o.PIXEL_PACK_BUFFER,u.packBuffer),p={gl:o,pbo:x,fence:y,byteLength:l},g=!0}else m=new Uint8Array(l),o.readPixels(0,0,i,s,o.RGBA,o.UNSIGNED_BYTE,m)}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),f?.(),d&&o.deleteFramebuffer(d),h&&o.deleteTexture(h),p&&!g&&(o.deleteBuffer(p.pbo),p.fence&&o.deleteSync(p.fence)),this.host.bakeKReuseFloor=c,this.host.requestRenderAll()}return p?{outWidth:i,outHeight:s,raw:m,stagedReadback:p}:m.length?{outWidth:i,outHeight:s,raw:m,stagedReadback:null}:null}async drainStagedReadback(e){let{gl:t,pbo:r,fence:o,byteLength:i}=e;try{if(o&&await Mv(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 Dc=[.8705882352941177,.8627450980392157,.8627450980392157],Cv=8,Rv=`#version 300 es
996
996
  layout(location = 0) in vec2 aPos;
997
997
  uniform mat3 uView;
998
998
  out vec2 vScene;
999
999
  void main() {
1000
1000
  vScene = aPos;
1001
1001
  gl_Position = vec4(uView * vec3(aPos, 1.0), 1.0);
1002
- }`,cv=`#version 300 es
1002
+ }`,Pv=`#version 300 es
1003
1003
  precision highp float;
1004
1004
  in vec2 vScene;
1005
1005
  uniform mat3 uVpt;
@@ -1019,14 +1019,14 @@ float inside = 1.0 - smoothstep(-uAa, uAa, d);
1019
1019
  vec2 screen = (uVpt * vec3(vScene, 1.0)).xy;
1020
1020
  float parity = mod(floor(screen.x / uTile) + floor(screen.y / uTile), 2.0);
1021
1021
  outColor = vec4(mix(vec3(1.0), uDark, parity), inside);
1022
- }`,pa=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,lv),o=t(e.FRAGMENT_SHADER,cv),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:c,dpr:u}=t;if(!(c>0)||!(u>0)||!(a>0)||!(l>0))return;let h=1.5/(c*u),d=i,f=s,m=i+a,p=s+l,g=this.corners;g[0]=d,g[1]=f,g[2]=m,g[3]=f,g[4]=m,g[5]=p,g[6]=d,g[7]=f,g[8]=m,g[9]=p,g[10]=d,g[11]=p;let b=this.program;e.useProgram(b),e.bindVertexArray(this.vao),e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer),e.bufferSubData(e.ARRAY_BUFFER,0,g);let x=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(b,"uView"),!1,x),e.uniformMatrix3fv(e.getUniformLocation(b,"uVpt"),!1,y),e.uniform2f(e.getUniformLocation(b,"uCenter"),i+a/2,s+l/2),e.uniform2f(e.getUniformLocation(b,"uHalf"),a/2,l/2),e.uniform1f(e.getUniformLocation(b,"uAa"),h),e.uniform1f(e.getUniformLocation(b,"uTile"),av),e.uniform3f(e.getUniformLocation(b,"uDark"),Nc[0],Nc[1],Nc[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 Lc=[243/255,243/255,243/255],uv=8,hv=.07,tp=16,dv=`#version 300 es
1022
+ }`,xa=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,Rv),o=t(e.FRAGMENT_SHADER,Pv),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:c,dpr:u}=t;if(!(c>0)||!(u>0)||!(a>0)||!(l>0))return;let h=1.5/(c*u),d=i,f=s,m=i+a,p=s+l,g=this.corners;g[0]=d,g[1]=f,g[2]=m,g[3]=f,g[4]=m,g[5]=p,g[6]=d,g[7]=f,g[8]=m,g[9]=p,g[10]=d,g[11]=p;let b=this.program;e.useProgram(b),e.bindVertexArray(this.vao),e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer),e.bufferSubData(e.ARRAY_BUFFER,0,g);let x=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(b,"uView"),!1,x),e.uniformMatrix3fv(e.getUniformLocation(b,"uVpt"),!1,y),e.uniform2f(e.getUniformLocation(b,"uCenter"),i+a/2,s+l/2),e.uniform2f(e.getUniformLocation(b,"uHalf"),a/2,l/2),e.uniform1f(e.getUniformLocation(b,"uAa"),h),e.uniform1f(e.getUniformLocation(b,"uTile"),Cv),e.uniform3f(e.getUniformLocation(b,"uDark"),Dc[0],Dc[1],Dc[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 Fc=[243/255,243/255,243/255],kv=8,Av=.07,dp=16,Nv=`#version 300 es
1023
1023
  layout(location = 0) in vec2 aPos;
1024
1024
  uniform mat3 uView;
1025
1025
  out vec2 vScene;
1026
1026
  void main() {
1027
1027
  vScene = aPos;
1028
1028
  gl_Position = vec4(uView * vec3(aPos, 1.0), 1.0);
1029
- }`,fv=`#version 300 es
1029
+ }`,Lv=`#version 300 es
1030
1030
  precision highp float;
1031
1031
  in vec2 vScene;
1032
1032
  uniform vec4 uRects[MAX_PAGE_RECTS];
@@ -1051,10 +1051,10 @@ float outside = smoothstep(-uAa, uAa, d);
1051
1051
  float t = clamp(d / uBlur, 0.0, 1.0);
1052
1052
  float glow = (1.0 - t) * (1.0 - t) * outside;
1053
1053
  outColor = vec4(uMask * (1.0 - glow * uGlow), outside);
1054
- }`.replaceAll("MAX_PAGE_RECTS",String(tp)),ba=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,dv),o=t(e.FRAGMENT_SHADER,fv),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,rects:a,zoom:l,dpr:c}=t;if(!(l>0)||!(c>0))return;let u=a.filter(R=>R.width>0&&R.height>0).slice(0,tp);if(u.length===0)return;let h=uv/l,d=1.5/(l*c),f=Te(o),m=V(f,0,0),p=V(f,i,s),g=Math.min(m.x,p.x),b=Math.min(m.y,p.y),x=Math.max(m.x,p.x),y=Math.max(m.y,p.y),S=this.corners;S[0]=g,S[1]=b,S[2]=x,S[3]=b,S[4]=x,S[5]=y,S[6]=g,S[7]=b,S[8]=x,S[9]=y,S[10]=g,S[11]=y;let v=new Float32Array(u.length*4);for(let R=0;R<u.length;R++){let w=u[R];v[R*4]=w.left+w.width/2,v[R*4+1]=w.top+w.height/2,v[R*4+2]=w.width/2,v[R*4+3]=w.height/2}let M=this.program;e.useProgram(M),e.bindVertexArray(this.vao),e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer),e.bufferSubData(e.ARRAY_BUFFER,0,S);let C=new Float32Array([r[0],r[1],0,r[2],r[3],0,r[4],r[5],1]);e.uniformMatrix3fv(e.getUniformLocation(M,"uView"),!1,C),e.uniform4fv(e.getUniformLocation(M,"uRects[0]"),v),e.uniform1i(e.getUniformLocation(M,"uRectCount"),u.length),e.uniform1f(e.getUniformLocation(M,"uBlur"),h),e.uniform1f(e.getUniformLocation(M,"uAa"),d),e.uniform3f(e.getUniformLocation(M,"uMask"),Lc[0],Lc[1],Lc[2]),e.uniform1f(e.getUniformLocation(M,"uGlow"),hv),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 ga=class{glow=new ba;checker=new pa;invalidate(){this.glow.invalidate(),this.checker.invalidate()}drawChecker(e,t,r,o){let i=Math.hypot(r.vpt[0],r.vpt[1]);for(let s of o)!(s.width>0)||!(s.height>0)||this.checker.draw(e,{view:t,vpt:r.vpt,left:s.left,top:s.top,width:s.width,height:s.height,zoom:i,dpr:r.dpr})}drawBackdrop(e,t,r,o){o.length!==0&&this.glow.draw(e,{view:t,vpt:r.vpt,cssWidth:r.cssWidth,cssHeight:r.cssHeight,rects:o,zoom:Math.hypot(r.vpt[0],r.vpt[1]),dpr:r.dpr})}};var mv=.02,pv=256,Ic=class n{domCanvasEl;exportStandInEl=null;get canvasEl(){return this.exportStandInEl??this.domCanvasEl}isExporting(){return this.exportStandInEl!==null}handle;batch;meshBatch;batchOrder;progressiveLoad=new zs({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 En;bakeKReuseFloor=0;sources;textRenderer;renderer;exporter;workspaceBackdrop;bus=new Fn;multiPage=new Gs;documentFlowEnabled=!1;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;interactions;interactionSuspended=!1;marquee=null;panning=!1;textEditing;tableCellEditing;snapGuide;rulerVisibleValue=!1;cropSessionController;expandSessionController;pathSessionController;warpSessionController;onWarpHistoryChange;animationPlaybackController;cellSelectionSink;constructor(e,t,r){nu(),this.domCanvasEl=e,this.domCanvasEl.style.display="block",this.handle=t,this.batch=new Zt(t.gl),this.meshBatch=new Os(t.gl),this.batchOrder=new Fs(this.batch,this.meshBatch),this.batch.order=this.batchOrder,this.meshBatch.order=this.batchOrder,this.textures=new Is(t.gl,{epoch:this.renderEpoch}),this.gradientRamps=new Ls(t.gl),this.glyphAtlas=new As(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 ca(this),this.textRenderer=new da(t.gl,this.batch,this.glyphAtlas),this.renderer=new la(this,this.sources,this.textRenderer),this.fontInvalidation=new ks(this,this.textRenderer,this.glyphAtlas,this.renderer),this.retainedFrame=new Ys(this),this.exporter=new ma(this),this.workspaceBackdrop=new ga,this.textEditing=new Rs(this),this.tableCellEditing=new Cs(this),this.snapGuide=new ms(this,La),this.cropSessionController=new is(this),this.expandSessionController=new as(this),this.pathSessionController=new cs(this),this.warpSessionController=new us(this),this.animationPlaybackController=new Ms(this),this.interactions=new Qi(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=Yf(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}documentNodes(){return this.multiPage.pageCount>1?this.multiPage.allDocs():[this.doc]}get pointerActive(){return this.interactions.pointerActive}get events(){return this.bus}get doc(){return this.multiPage.activeDoc}get document(){return this.doc}get capabilities(){return{maxTextureSize:this.handle.capabilities.maxTextureSize,renderer:this.handle.capabilities.renderer}}get viewportTransform(){return this.multiPage.pageCount>1?this.multiPage.pageVpt(this.vpt,this.multiPage.activeIndex):[...this.vpt]}get scrollViewportTransform(){return[...this.vpt]}get zoom(){return this.vpt[0]}get gl(){return this.handle.gl}get viewSize(){return{width:this.cssWidth,height:this.cssHeight}}workspaceSize(){if(this.multiPage.pageCount>1){let t=this.multiPage.documentBounds();return t&&t.width>0&&t.height>0?{width:t.width,height:t.height}:{width:0,height:0}}let e=this.doc.nodes.find(t=>String(t.raw.id??"")===_t)?.bounds;return e&&e.width>0&&e.height>0?{width:e.width,height:e.height}:{width:0,height:0}}cursorPoint(e){let t=this.canvasEl.getBoundingClientRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}followScrolledPage(){this.multiPage.pageCount<2||gd(this,this.multiPage.layout().map(({index:e,rect:t,entry:r})=>({index:e,top:t.top+r.origin.y,height:t.height})))}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 le?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)}get activePageOrigin(){return this.multiPage.pageCount>1?this.multiPage.originAt(this.multiPage.activeIndex):{x:0,y:0}}toSceneAbs(e,t){return{x:(e-this.vpt[4])/this.vpt[0],y:(t-this.vpt[5])/this.vpt[3]}}toScene(e,t){let r=this.toSceneAbs(e,t),o=this.activePageOrigin;return{x:r.x-o.x,y:r.y-o.y}}toScreen(e,t){let r=this.activePageOrigin;return{x:this.vpt[0]*(e+r.x)+this.vpt[4],y:this.vpt[3]*(t+r.y)+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.multiPage.pageCount>1?this.sources.releaseAnimatedSourcesOfDoc(this.multiPage.activeDoc):this.sources.releaseAnimatedSources(),this.animationPlaybackController.reset(),this.doc.loadObjects(e),this.multiPage.markBuilt(this.multiPage.activeIndex),await No(Ao([...this.doc.nodes]),this.sources,()=>this.requestRenderAll())}async ensureNodeSources(e){await No(Ao(e),this.sources,()=>this.requestRenderAll())}get pageCount(){return this.multiPage.pageCount}get activePageIndex(){return this.multiPage.activeIndex}setActivePage(e){if(this.interactions.pointerActive||e<0||e>=this.multiPage.pageCount||e===this.multiPage.activeIndex)return;let t=this.multiPage.activeDoc;this.animationPlaybackController.stop(),this.bus.fire("engine:active-page-changing",e),this.multiPage.setActiveIndex(e),t.setHovered(null),t.editingNode&&t.exitEditing(),this.cropSessionController.active&&this.cropSessionController.exit(),this.expandSessionController.active&&this.expandSessionController.exit(),this.pathSessionController.active&&this.pathSessionController.exit(),this.warpSessionController.active&&this.warpSessionController.exit(!0).catch(()=>{}),this.marquee=null,this.rotateDrag=null,this.referenceLineDrag=null;let r=this.multiPage.activeDoc;this.textEditing.retargetDoc(r),this.tableCellEditing.retargetDoc(r),this.interactions.retargetDoc(r),this.bus.fire("engine:active-page-changed",e),this.requestRenderAll()}resolvePointerTarget(e,t){if(this.multiPage.pageCount===1)return{doc:this.doc,local:{x:e,y:t},routed:!1};let r=this.cropSessionController.active||this.expandSessionController.active||this.pathSessionController.active||this.warpSessionController.active,o=this.multiPage.route(e,t);if(r||!o){let i=this.multiPage.originAt(this.multiPage.activeIndex);return{doc:this.multiPage.activeDoc,local:{x:e-i.x,y:t-i.y},routed:!1}}return{doc:o.doc,local:o.local,routed:!0}}activateRoutedDocument(e){let t=this.multiPage.indexOfDoc(e);t>=0&&this.setActivePage(t)}transferDraggedNodes(e,t,r,o){let i=qm(this.multiPage,e,t,this.toSceneAbs(r,o),s=>{this.ensurePageBuilt(s)});return i?(this.setActivePage(i.targetIndex),i.target.setSelection(i.nodes),this.bus.fire("engine:page-transfer",i),this.requestRenderAll(),!0):!1}async insertPage(e,t=[]){let r=this.multiPage.insert(e);return this.retainedFrame.invalidate(),await this.loadPageObjects(r,t),r}removePage(e){let t=this.multiPage.remove(e);return t&&(this.retainedFrame.invalidate(),this.requestRenderAll()),t}async loadPageObjects(e,t){let r=this.multiPage.pageAt(e);if(r){if(e===this.multiPage.activeIndex){await this.loadObjects(t);return}r.doc.loadObjects(t),this.multiPage.markBuilt(e),await No(Ao([...r.doc.nodes]),this.sources,()=>this.requestRenderAll()),this.requestRenderAll()}}setPageRaw(e,t){let r=this.multiPage.setPageRaw(e,t);return r&&this.requestRenderAll(),r}insertPageRaw(e,t){let r=this.multiPage.insert(e);return this.retainedFrame.invalidate(),this.setPageRaw(r,t),r}isPageBuilt(e){return this.multiPage.isBuilt(e)}async ensurePageBuilt(e){let t=this.multiPage.pageAt(e);!t||!t.pendingRaw||(t.doc.loadObjects(t.pendingRaw),this.multiPage.markBuilt(e),this.bus.fire("engine:page-built",e,t.doc),await No(Ao([...t.doc.nodes]),this.sources,()=>this.requestRenderAll()),this.requestRenderAll())}pageRectAt(e){return this.multiPage.pageRectAt(e)}rebuildAroundActive(e,t){this.retainedFrame.invalidate(),this.multiPage.rebuildAroundActive(e,t),this.requestRenderAll()}multiPageFrameHost(){return{gl:this.handle.gl,vpt:this.vpt,cssWidth:this.cssWidth,cssHeight:this.cssHeight,dpr:this.dpr,zoom:this.zoom,batch:this.batch,meshBatch:this.meshBatch,batchOrder:this.batchOrder,renderer:this.renderer,withPageViewport:(e,t)=>bm(this,e,t),workspaceBackdrop:this.workspaceBackdrop,textures:this.textures,expandUnderlay:()=>{let e=this.expandSessionController.active?this.expandSessionController.target:null;return e?{target:e,underlay:()=>this.expandSessionController.buildUnderlay()}:null},finishOverlay:()=>dc(this),onPageVisible:e=>{this.ensurePageBuilt(e)}}}setViewportTransform(e){let t=this.vpt[0];this.vpt=[...e],this.multiPage.viewportZoom=this.vpt[0],this.renderer.noteVptChange(),this.vpt[0]!==t&&this.doc.setViewportZoom(this.vpt[0]),this.requestRenderAll()}zoomAt(e,t,r){let o=Math.min(pv,Math.max(mv,this.vpt[0]*r)),i=o/this.vpt[0],s=[o,0,0,o,e-i*(e-this.vpt[4]),t-i*(t-this.vpt[5])];this.vpt=this.multiPage.pageCount>1?this.multiPage.zoomViewportAt(this.vpt,e,t,o):this.documentFlowEnabled?mm(this.vpt,o,Xs(this.doc)?.bounds??null,s):s,this.multiPage.viewportZoom=o,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))}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),Ra("engine.render",()=>{let t=this.handle.gl;if(t.viewport(0,0,this.canvasEl.width,this.canvasEl.height),t.clearColor(...this.background),t.clear(t.COLOR_BUFFER_BIT),this.multiPage.pageCount>1){pm(this.multiPage,this.multiPageFrameHost());return}let r=Nt(this.vpt,this.cssWidth,this.cssHeight,this.dpr),o=Xs(this.doc)?.bounds,i=o?[o]:[];this.workspaceBackdrop.drawChecker(this.handle.gl,r,{vpt:this.vpt,cssWidth:this.cssWidth,cssHeight:this.cssHeight,dpr:this.dpr},i),this.batch.begin(r,this.zoom*this.dpr),this.meshBatch.begin(r),this.batch.deferDraws=!0,this.meshBatch.deferDraws=!0,this.batchOrder.reset();let s=this.expandSessionController.active?this.expandSessionController.target:null;if(!(!s&&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 a=this.progressiveLoad.limit>=0?Math.min(this.progressiveLoad.limit,this.doc.nodes.length):this.doc.nodes.length;Ws(this.batch,this.renderer,this.doc.nodes,s?{target:s,underlay:()=>this.expandSessionController.buildUnderlay()}:null,a),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},i),dc(this)}),this.retainedFrame.noteFrameRendered(),this.renderer.frame.bakeMore&&this.requestRenderAll(),this.bus.fire("engine:render",performance.now()-e)}readPixels(){return Xh(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)}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 Gh(e,()=>this.render())}getSceneSummary(){return Wh(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 le)?!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 le?!!await this.sources.reloadMaskClipImage(t):!1}getCropInfo(){return this.cropSessionController.info}enterCropMode(e){this.pathSessionController.active&&this.pathSessionController.exit();let t=e??this.doc.selection[0];return t?this.cropSessionController.enter(t):!1}exitCropMode(){this.cropSessionController.exit()}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 Qe(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 zh(this.doc,()=>this.requestRenderAll())}deleteSelection(){return Yh(this.doc,()=>this.requestRenderAll())}nudgeSelection(e,t){return Uh(this.doc,e,t,()=>this.requestRenderAll())}getSelectionInfo(){return Oh(this.doc,this.marquee,this.zoom,(e,t)=>this.toScreen(e,t))}getActiveGroupChildInfo(){return Bh(this.doc)}getSvgRasterInfo(){return Hh(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 kn=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)}},_c=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,bv=n=>({sx:en(n.scaleX,1)||1,sy:en(n.scaleY,1)||1}),np=n=>{let e=n.pathOffset;return!e||typeof e.x!="number"||typeof e.y!="number"?null:{x:e.x,y:e.y}},gv=n=>{let e=Ae(n),t=e?je(e):null;return t?{x:(t.left+t.right)/2,y:(t.top+t.bottom)/2}:null},xv=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}},yv=(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`,rp=(n,e)=>`M 0 ${-e} A ${n} ${e} 0 1 1 0 ${e} A ${n} ${e} 0 1 1 0 ${-e} Z`,Dc=n=>{if(n.isTextType)return;let e=n.raw,t=J(e),{sx:r,sy:o}=bv(e);if(t===L.PATH){let a=typeof e.path=="string"?e.path:"";return a.trim()?{path:a,pathOffset:np(e)??gv(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=rt(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?yv(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:rp(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:rp(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:np(e)??xv(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 op=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]}}},ip=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))}},sp=(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}}),ap=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},Fc=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}},Fr=(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}},lp=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,g=(o*l-i*a)/c,b=(t*a-e*l)/c,x=(e*i-t*o)/c;if(!(Math.abs(x)<1e-6))return{a:u/x,b:h/x,c:d/x,d:f/x,e:m/x,f:p/x,g:g/x,h:b/x}};var cp=32,up=120,Oc=1e-6,vv=()=>{let n=document.createElement("canvas");if(!n||typeof n.getContext>"u")throw new Error("Failed to create `canvas` element");return n},Sv=n=>{let e=vv();return e.width=n.width,e.height=n.height,e.getContext("2d",{willReadFrequently:!0})?.drawImage(n,0,0),e},wv=(n,e,t)=>n.toDataURL?.(`image/${e}`,t),Tv=n=>new Promise((e,t)=>{let r=new FileReader;r.onload=()=>e(String(r.result)),r.onerror=()=>t(r.error),r.readAsDataURL(n)}),hp=async(n,e,t)=>{try{let r=await new Promise(o=>n.toBlob(o,`image/${e}`,t));if(r)return await Tv(r)}catch{}return wv(n,e,t)},Ev=(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)<Oc&&Math.abs(o-s)<Oc)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},Mv=(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,g=(u*e+c)*4,b=1-d,x=1-h,y=x*b,S=h*b,v=x*d,M=h*d;return[n[f]*y+n[m]*S+n[p]*v+n[g]*M,n[f+1]*y+n[m+1]*S+n[p+1]*v+n[g+1]*M,n[f+2]*y+n[m+2]*S+n[p+2]*v+n[g+2]*M,n[f+3]*y+n[m+3]*S+n[p+3]*v+n[g+3]*M]},Cv=(n,e,t)=>{let r=Fc(t),o=r?lp(r):void 0;if(!o){fp(n,e,t,cp);return}let i=Math.max(1,e.width),s=Math.max(1,e.height),a=e.getContext("2d",{willReadFrequently:!0});if(!a){fp(n,e,t,cp);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=Fr(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),g=Mv(l.data,i,s,m,p),b=(h*n.canvas.width+d)*4;u[b]=g[0],u[b+1]=g[1],u[b+2]=g[2],u[b+3]=g[3]}n.putImageData(c,0,0)},dp=(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)<Oc)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,g=(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,g),n.drawImage(e,0,0),n.restore()},fp=(n,e,t,r)=>{let o=Fc(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(up,Math.max(1,Math.ceil(i/r))),l=Math.min(up,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,g=(m+1)/a,b=p*i,x=g*i,y=Fr(o,p,u),S=Fr(o,g,u),v=Fr(o,g,h),M=Fr(o,p,h);dp(n,e,[{x:b,y:d},{x,y:d},{x,y:f}],[y,S,v]),dp(n,e,[{x:b,y:d},{x,y:f},{x:b,y:f}],[y,v,M])}}},Rv=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=Ev(n,a,l),u=op(e?.nonAffineTransform||e?.transform);if(!u){let b=Sv(n);return{src:await hp(b,o,r),width:i,height:s,sourceWidth:a,sourceHeight:l}}let h=ip(u),d=sp(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",ap(d)){let b=(d.tr.x-d.tl.x)/a,x=(d.tr.y-d.tl.y)/a,y=(d.bl.x-d.tl.x)/l,S=(d.bl.y-d.tl.y)/l,v=d.tl.x,M=d.tl.y;p.setTransform(b,x,y,S,v,M),p.drawImage(c,0,0)}else Cv(p,c,d);let g;if(f){let b=Math.round(f.left-h.minX),x=Math.round(f.top-h.minY),y=Math.max(1,Math.round(f.width)),S=Math.max(1,Math.round(f.height));if(b>=0&&x>=0&&b+y<=h.width+1&&x+S<=h.height+1){g=document.createElement("canvas"),g.width=y,g.height=S;let M=g.getContext("2d");M&&M.drawImage(m,b,x,y,S,0,0,y,S)}else{g=document.createElement("canvas"),g.width=y,g.height=S;let M=g.getContext("2d");M&&(M.imageSmoothingEnabled=!0,M.imageSmoothingQuality="high",M.drawImage(m,0,0,h.width,h.height,0,0,y,S))}}else g=m;return{src:await hp(g,o,r),width:g.width,height:g.height,sourceWidth:a,sourceHeight:l}};var oe=n=>n.node instanceof te?n.node:null,Oe=n=>n.raw,Pt=n=>{n.canvas?.requestRenderAll?.()},Ue=(n,e)=>{let t=Oe(e);n.set({cellData:t.cellData??[],rows:t.rows,cols:t.cols}),Pt(n)},Bc=n=>n.rows??3,Hc=n=>n.cols??3,Or=n=>(Array.isArray(n.cellData)||(n.cellData=[]),n.cellData),Io=(n,e,t)=>{let r=Se(n.cellMap,e,t);if(r)return r.isMerged&&r.mergeParent?Se(n.cellMap,r.mergeParent.row,r.mergeParent.col):r},Xt=(n,e)=>{let t=oe(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=Se(t.cellMap,i.row,i.col);a&&e(a)}Ue(n,t)},Wc=(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]}}),mp=(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??Oe(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(){}}),Pv={canMergeCells(){let n=oe(this);return!!n&&n.selectedCells.length>1},canUseMergeCells(){let n=oe(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=Io(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=oe(this);if(!n||!n.selectedCells.length)return!1;let e=n.selectedCells[0],t=Io(n,e.row,e.col);return!!t&&(t.rowspan??1)>1},canSplitColumns(){let n=oe(this);if(!n||!n.selectedCells.length)return!1;let e=n.selectedCells[0],t=Io(n,e.row,e.col);return!!t&&(t.colspan??1)>1},isSelectColumn(){let n=oe(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===Bc(Oe(n))-1,a=e.size>=2,l=!1;for(let c of n.selectedCells)if((Io(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=oe(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===Hc(Oe(n))-1,a=t.size>=2,l=!1;for(let c of n.selectedCells)if((Io(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=oe(this);return e?xr(e.cellMap,e.selectedCells).rows.has(n):!1},isColumnSelected(n){let e=oe(this);return e?xr(e.cellMap,e.selectedCells).cols.has(n):!1},selectCell(n,e,t=!1){let r=oe(this);if(r){if(t){if(r.cellAnchor){let o=r.cellAnchor,i=cn(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=oe(this);e&&(e.setColumnSelection(n),Pt(this))},selectRow(n){let e=oe(this);e&&(e.setRowSelection(n),Pt(this))},selectAllCells(){let n=oe(this);if(!n)return;let e=n.tableView,t=io(n.cellMap,e.rows,e.cols);n.setCellSelection(t,t[0]??null,We(t)),Pt(this)},clearCellSelection(){let n=oe(this);n&&(n.clearCellSelection(),Pt(this))},buildSelectionRange(n,e){let t=oe(this);return t?cn(t.cellMap,n,e):[]},mergeCells(n,e,t,r){let o=oe(this);if(!o)return;let i=Jr(o.raw,n,e,t,r),s={row:i.r1,col:i.c1};o.setCellSelection([s],s,i),Ue(this,o)},unmergeCells(n,e){let t=oe(this);if(!t||!eo(t.raw,n,e))return;let r={row:n,col:e};t.setCellSelection([r],r,{r1:n,r2:n,c1:e,c2:e}),Ue(this,t)},addRow(n){let e=oe(this);e&&(to(e.raw,n??Bc(Oe(e))),Ue(this,e))},removeRow(n){let e=oe(this);if(!e)return;let t=n??Bc(Oe(e))-1;if(!el(e.raw,t))return;let r=hi(e.selectedCells,e.cellRange,t,"row");r?e.setCellSelection(r.cells,r.cells[0]??null,r.range):e.clearCellSelection(),Ue(this,e)},addColumn(n){let e=oe(this);e&&(no(e.raw,n??Hc(Oe(e))),Ue(this,e))},removeColumn(n){let e=oe(this);if(!e)return;let t=n??Hc(Oe(e))-1;if(!tl(e.raw,t))return;let r=hi(e.selectedCells,e.cellRange,t,"col");r?e.setCellSelection(r.cells,r.cells[0]??null,r.range):e.clearCellSelection(),Ue(this,e)},setColumnWidth(n,e){let t=oe(this);t&&(Qr(t.raw,n,e),this.set({columnWidths:Oe(t).columnWidths??[]}),Pt(this))},setRowHeight(n,e){let t=oe(this);t&&(Zr(t.raw,n,e),this.set({manualRowHeights:Oe(t).manualRowHeights??[]}),Pt(this))},setSelectWidth(n){let e=oe(this);if(!e)return;let t=e.cellRange,r=Oe(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=oe(this);if(!e)return;let t=e.cellRange,r=Oe(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=oe(this);return e?e.tableView.columnWidths[n]??0:0},getRowHeight(n){let e=oe(this);return e?e.tableView.rowHeights[n]??0:0},getRowMinHeight(n){let e=oe(this);return e?e.getRowMinHeight(n):0},relayout(){let n=oe(this);n&&(n.rebuildTable(),Pt(this))},previewLayout(){this.relayout()},getCell(n,e){let t=oe(this);if(!t)return;let r=Se(t.cellMap,n,e);return r?Wc(t,r,()=>Ue(this,t)):void 0},getCellText(n,e){let t=oe(this);if(!t)return;let r=Se(t.cellMap,n,e);return r?mp(t,r,()=>Ue(this,t)):void 0},setSelectionTextAlign(n){Xt(this,e=>{e.textAlign=n})},setSelectionFontSize(n){Xt(this,e=>{e.fontSize=n})},changeSelectionFontSize(n){let e=oe(this);if(!e)return;let t=Oe(e).fontSize??14;Xt(this,r=>{let o=Number(r.fontSize)||t;r.fontSize=n==="+"?o+1:Math.max(1,o-1)})},setSelectionFontWeight(n){Xt(this,e=>{e.fontWeight=n})},setSelectionFontStyle(n){Xt(this,e=>{e.fontStyle=n})},setSelectionUnderline(n){Xt(this,e=>{e.underline=n})},setSelectionLinethrough(n){Xt(this,e=>{e.linethrough=n})},setSelectionCellFill(n){Xt(this,e=>{e.fill=n,e.hasCustomFill=!0})},setSelectionCellStroke(n){Xt(this,e=>{e.stroke=n,e.hasCustomStroke=!0})},setSelectionCellStrokeWidth(n){Xt(this,e=>{e.strokeWidth=n,e.hasCustomStroke=!0})},updateCellFill(n){let e=oe(this);if(!e)return;let t=Oe(e);t.cellFill=n;for(let r of Or(t))!r.isMerged&&!r.hasCustomFill&&(r.fill=n);Ue(this,e)},updateCellTextFill(n){let e=oe(this);if(!e)return;let t=Oe(e);t.textFill=n;for(let r of Or(t))r.hasCustomTextFill||(r.textFill=n);Ue(this,e)},updateCellStroke(n){let e=oe(this);if(!e)return;let t=Oe(e);t.cellStroke=n;for(let r of Or(t))r.hasCustomStroke||(r.stroke=n);Ue(this,e)},updateBorderWidth(n){let e=oe(this);e&&(Oe(e).cellStrokeWidth=n,Ue(this,e))},applyTextStylesToAll(n){let e=oe(this);if(!e)return;let t=Oe(e),r={...t.textDefaults??{}};for(let[o,i]of Object.entries(n))r[o]=i;t.textDefaults=r;for(let o of Or(t))for(let[i,s]of Object.entries(n))i==="fill"?o.textFill=s:o[i]=s;Ue(this,e)}},kv={selectedCells(){let n=oe(this);if(n)return n.selectedCells.map(e=>{let t=Se(n.cellMap,e.row,e.col);return t?Wc(n,t,()=>Ue(this,n)):void 0}).filter(e=>e!==void 0)},_selectedCells(){let n=oe(this);return n?n.selectedCells:void 0},_selectionRange(){let n=oe(this);return n?n.cellRange:void 0},hasSelection(){let n=oe(this);return n?n.hasCellSelection:!1},selectionCount(){let n=oe(this);return n?n.selectedCells.length:0},cellTexts(){let n=oe(this);if(!n)return;let e=()=>Ue(this,n);return Or(Oe(n)).map(t=>mp(n,t,e))},cells(){let n=oe(this);if(!n)return;let e=()=>Ue(this,n);return Or(Oe(n)).map(t=>Wc(n,t,e))},columnWidths(){let n=oe(this);return n?[...n.tableView.columnWidths]:void 0},rowHeights(){let n=oe(this);return n?[...n.tableView.rowHeights]:void 0}},Gc=n=>{for(let[e,t]of Object.entries(Pv))Object.assign(n,{[e]:t});for(let[e,t]of Object.entries(kv))Object.defineProperty(n,e,{get:t,configurable:!0,enumerable:!1})};var Xc=(n,e,t)=>{let r=qe(e);if(!r)return null;let o=Mt(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 pp=new Set([L.ARCHTEXT,L.WAISTTEXT,L.FLAGTEXT]),Av=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},sr=class{node;ctx;constructor(e,t){this.node=e,this.ctx=t}set(e,t){let r=typeof e=="string"?{[e]:t}:e;if("cropAspectRatio"in r){let i={cropAspectRatio:r.cropAspectRatio};delete r.cropAspectRatio,this.ctx.setNodeProps(this.node,i)}if("__isCropping"in r){let i=!!r.__isCropping;delete r.__isCropping,this.clearSessionFlagDirty("__isCropping"),this.__isCropping=i}if("__isExpand"in r){let i=!!r.__isExpand;delete r.__isExpand,this.clearSessionFlagDirty("__isExpand"),this.__isExpand=i}if(typeof r.width=="number"&&Er(this.node)){let i=r.width;delete r.width,this.ctx.setGroupWidth?this.ctx.setGroupWidth(this.node,i):this.ctx.setNodeProps(this.node,{width:i})}this.bumpTextboxWidthToLayoutBox(r),this.bridgeImageSizeProps(r);let o=r;if((typeof r.width=="number"||typeof r.height=="number")&&!("clipImage"in r)&&nt.has(J(this.node.raw))){let i=An(this.node),s=this.node.raw,a=Number(s.width)||0,l=Number(s.height)||0,c=typeof r.width=="number"?r.width:a,u=typeof r.height=="number"?r.height:l,h=this.node.clipImageEl,d=h?.naturalWidth||Number(i?.width)||0,f=h?.naturalHeight||Number(i?.height)||0;if(i&&a>0&&l>0&&c>0&&u>0&&d>0&&f>0){let m=(b,x)=>Math.max(b/d,x/f),p=Number(i.scaleX)||1,g=m(c,u)*(p/m(a,l));o={...r,clipImage:{...i,scaleX:g,scaleY:g}}}}return Object.keys(o).length>0&&this.ctx.setNodeProps(this.node,o),this}bumpTextboxWidthToLayoutBox(e){if(typeof e.width!="number"||!(this.node instanceof xe)||e.width<0||J(this.node.raw)!==L.TEXTBOX||qe(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 kn(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 kn(0,0),l=new kn(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||Dc(this.node)}toPathDecorations(){return this.ctx.getTextDecorations?.(this.node)??[]}toPathEffectLayers(e){return[]}_getTransformedDimensions(){let e=this.node.raw;return new kn(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}}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),g={x:e.x-(h*m-d*p),y:e.y-(h*p+d*m)},b=ge({...o},g);return this.set({left:b.x,top:b.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 ee)return()=>this.node.children.map(e=>this.ctx.wrapNode(e))}get _objects(){if(this.node instanceof ee)return this.node.children.map(e=>this.ctx.wrapNode(e))}get ref(){return this}get isImageLikeNode(){let e=J(this.node.raw);return ft.has(e)||nt.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 re?()=>e.paintSource??e.imageEl:()=>e.imageEl}get _element(){if(this.isImageLikeNode)return this.node.imageEl}get clipImage(){return An(this.node)?Lv(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 re){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(Er(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(!this.ctx.enterCropSession?.(this.node))return;t&&(this.cropBeforeState=this.toObject());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)return!1;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 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)*5;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)*5;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+20}isType(...e){let t=J(this.node.raw);return e.some(r=>r.toLowerCase()===t)}getStyleAtPosition(e){if(!(this.node instanceof xe))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(`
1054
+ }`.replaceAll("MAX_PAGE_RECTS",String(dp)),ya=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,Nv),o=t(e.FRAGMENT_SHADER,Lv),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,rects:a,zoom:l,dpr:c}=t;if(!(l>0)||!(c>0))return;let u=a.filter(R=>R.width>0&&R.height>0).slice(0,dp);if(u.length===0)return;let h=kv/l,d=1.5/(l*c),f=Te(o),m=V(f,0,0),p=V(f,i,s),g=Math.min(m.x,p.x),b=Math.min(m.y,p.y),x=Math.max(m.x,p.x),y=Math.max(m.y,p.y),S=this.corners;S[0]=g,S[1]=b,S[2]=x,S[3]=b,S[4]=x,S[5]=y,S[6]=g,S[7]=b,S[8]=x,S[9]=y,S[10]=g,S[11]=y;let v=new Float32Array(u.length*4);for(let R=0;R<u.length;R++){let w=u[R];v[R*4]=w.left+w.width/2,v[R*4+1]=w.top+w.height/2,v[R*4+2]=w.width/2,v[R*4+3]=w.height/2}let T=this.program;e.useProgram(T),e.bindVertexArray(this.vao),e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer),e.bufferSubData(e.ARRAY_BUFFER,0,S);let C=new Float32Array([r[0],r[1],0,r[2],r[3],0,r[4],r[5],1]);e.uniformMatrix3fv(e.getUniformLocation(T,"uView"),!1,C),e.uniform4fv(e.getUniformLocation(T,"uRects[0]"),v),e.uniform1i(e.getUniformLocation(T,"uRectCount"),u.length),e.uniform1f(e.getUniformLocation(T,"uBlur"),h),e.uniform1f(e.getUniformLocation(T,"uAa"),d),e.uniform3f(e.getUniformLocation(T,"uMask"),Fc[0],Fc[1],Fc[2]),e.uniform1f(e.getUniformLocation(T,"uGlow"),Av),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 va=class{glow=new ya;checker=new xa;invalidate(){this.glow.invalidate(),this.checker.invalidate()}drawChecker(e,t,r,o){let i=Math.hypot(r.vpt[0],r.vpt[1]);for(let s of o)!(s.width>0)||!(s.height>0)||this.checker.draw(e,{view:t,vpt:r.vpt,left:s.left,top:s.top,width:s.width,height:s.height,zoom:i,dpr:r.dpr})}drawBackdrop(e,t,r,o){o.length!==0&&this.glow.draw(e,{view:t,vpt:r.vpt,cssWidth:r.cssWidth,cssHeight:r.cssHeight,rects:o,zoom:Math.hypot(r.vpt[0],r.vpt[1]),dpr:r.dpr})}};var Iv=.02,_v=256,Oc=class n{domCanvasEl;exportStandInEl=null;get canvasEl(){return this.exportStandInEl??this.domCanvasEl}isExporting(){return this.exportStandInEl!==null}handle;batch;meshBatch;batchOrder;progressiveLoad=new Ys({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 Mn;bakeKReuseFloor=0;sources;textRenderer;renderer;exporter;workspaceBackdrop;bus=new On;multiPage=new Xs;documentFlowEnabled=!1;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;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 Zt(t.gl),this.meshBatch=new Bs(t.gl),this.batchOrder=new Os(this.batch,this.meshBatch),this.batch.order=this.batchOrder,this.meshBatch.order=this.batchOrder,this.textures=new _s(t.gl,{epoch:this.renderEpoch}),this.gradientRamps=new Is(t.gl),this.glyphAtlas=new Ns(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 ua(this),this.textRenderer=new pa(t.gl,this.batch,this.glyphAtlas),this.renderer=new ca(this,this.sources,this.textRenderer),this.fontInvalidation=new As(this,this.textRenderer,this.glyphAtlas,this.renderer),this.retainedFrame=new Us(this),this.exporter=new ga(this),this.workspaceBackdrop=new va,this.textEditing=new Ps(this),this.tableCellEditing=new Rs(this),this.snapGuide=new ps(this,La),this.cropSessionController=new ss(this),this.expandSessionController=new ls(this),this.pathSessionController=new us(this),this.warpSessionController=new hs(this),this.animationPlaybackController=new Cs(this),this.interactions=new Zi(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=jf(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}documentNodes(){return this.multiPage.pageCount>1?this.multiPage.allDocs():[this.doc]}get pointerActive(){return this.interactions.pointerActive}get events(){return this.bus}get doc(){return this.multiPage.activeDoc}get document(){return this.doc}get capabilities(){return{maxTextureSize:this.handle.capabilities.maxTextureSize,renderer:this.handle.capabilities.renderer}}get viewportTransform(){return this.multiPage.pageCount>1?this.multiPage.pageVpt(this.vpt,this.multiPage.activeIndex):[...this.vpt]}get scrollViewportTransform(){return[...this.vpt]}get zoom(){return this.vpt[0]}get gl(){return this.handle.gl}get viewSize(){return{width:this.cssWidth,height:this.cssHeight}}workspaceSize(){if(this.multiPage.pageCount>1){let t=this.multiPage.documentBounds();return t&&t.width>0&&t.height>0?{width:t.width,height:t.height}:{width:0,height:0}}let e=this.doc.nodes.find(t=>String(t.raw.id??"")===_t)?.bounds;return e&&e.width>0&&e.height>0?{width:e.width,height:e.height}:{width:0,height:0}}cursorPoint(e){let t=this.canvasEl.getBoundingClientRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}followScrolledPage(){this.multiPage.pageCount<2||Sd(this,this.multiPage.layout().map(({index:e,rect:t,entry:r})=>({index:e,top:t.top+r.origin.y,height:t.height})))}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 le?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)}get activePageOrigin(){return this.multiPage.pageCount>1?this.multiPage.originAt(this.multiPage.activeIndex):{x:0,y:0}}toSceneAbs(e,t){return{x:(e-this.vpt[4])/this.vpt[0],y:(t-this.vpt[5])/this.vpt[3]}}toScene(e,t){let r=this.toSceneAbs(e,t),o=this.activePageOrigin;return{x:r.x-o.x,y:r.y-o.y}}toScreen(e,t){let r=this.activePageOrigin;return{x:this.vpt[0]*(e+r.x)+this.vpt[4],y:this.vpt[3]*(t+r.y)+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.multiPage.pageCount>1?this.sources.releaseAnimatedSourcesOfDoc(this.multiPage.activeDoc):this.sources.releaseAnimatedSources(),this.animationPlaybackController.reset(),this.doc.loadObjects(e),this.multiPage.markBuilt(this.multiPage.activeIndex),await No(Ao([...this.doc.nodes]),this.sources,()=>this.requestRenderAll())}async ensureNodeSources(e){await No(Ao(e),this.sources,()=>this.requestRenderAll())}get pageCount(){return this.multiPage.pageCount}get activePageIndex(){return this.multiPage.activeIndex}setActivePage(e){if(this.interactions.pointerActive||e<0||e>=this.multiPage.pageCount||e===this.multiPage.activeIndex)return;let t=this.multiPage.activeDoc;this.animationPlaybackController.stop(),this.bus.fire("engine:active-page-changing",e),this.multiPage.setActiveIndex(e),t.setHovered(null),t.editingNode&&t.exitEditing(),this.cropSessionController.active&&this.cropSessionController.exit(),this.expandSessionController.active&&this.expandSessionController.exit(),this.pathSessionController.active&&this.pathSessionController.exit(),this.warpSessionController.active&&this.warpSessionController.exit(!0).catch(()=>{}),this.marquee=null,this.rotateDrag=null,this.referenceLineDrag=null;let r=this.multiPage.activeDoc;this.textEditing.retargetDoc(r),this.tableCellEditing.retargetDoc(r),this.interactions.retargetDoc(r),this.bus.fire("engine:active-page-changed",e),this.requestRenderAll()}resolvePointerTarget(e,t){if(this.multiPage.pageCount===1)return{doc:this.doc,local:{x:e,y:t},routed:!1};let r=this.cropSessionController.active||this.expandSessionController.active||this.pathSessionController.active||this.warpSessionController.active,o=this.multiPage.route(e,t);if(r||!o){let i=this.multiPage.originAt(this.multiPage.activeIndex);return{doc:this.multiPage.activeDoc,local:{x:e-i.x,y:t-i.y},routed:!1}}return{doc:o.doc,local:o.local,routed:!0}}activateRoutedDocument(e){let t=this.multiPage.indexOfDoc(e);t>=0&&this.setActivePage(t)}transferDraggedNodes(e,t,r,o){let i=rp(this.multiPage,e,t,this.toSceneAbs(r,o),s=>{this.ensurePageBuilt(s)});return i?(this.setActivePage(i.targetIndex),i.target.setSelection(i.nodes),this.bus.fire("engine:page-transfer",i),this.requestRenderAll(),!0):!1}replayPageTransfer(e,t,r,o){let i=Nc(this.multiPage,e,t,r,o);return i&&(this.retainedFrame.invalidate(),this.requestRenderAll()),i}async insertPage(e,t=[]){let r=this.multiPage.insert(e);return this.retainedFrame.invalidate(),await this.loadPageObjects(r,t),r}removePage(e){let t=this.multiPage.remove(e);return t&&(this.retainedFrame.invalidate(),this.requestRenderAll()),t}async loadPageObjects(e,t){let r=this.multiPage.pageAt(e);if(r){if(e===this.multiPage.activeIndex){await this.loadObjects(t);return}r.doc.loadObjects(t),this.multiPage.markBuilt(e),await No(Ao([...r.doc.nodes]),this.sources,()=>this.requestRenderAll()),this.requestRenderAll()}}setPageRaw(e,t){let r=this.multiPage.setPageRaw(e,t);return r&&this.requestRenderAll(),r}insertPageRaw(e,t){let r=this.multiPage.insert(e);return this.retainedFrame.invalidate(),this.setPageRaw(r,t),r}isPageBuilt(e){return this.multiPage.isBuilt(e)}async ensurePageBuilt(e){let t=this.multiPage.pageAt(e);!t||!t.pendingRaw||(t.doc.loadObjects(t.pendingRaw),this.multiPage.markBuilt(e),this.bus.fire("engine:page-built",e,t.doc),await No(Ao([...t.doc.nodes]),this.sources,()=>this.requestRenderAll()),this.requestRenderAll())}pageRectAt(e){return this.multiPage.pageRectAt(e)}rebuildAroundActive(e,t){this.retainedFrame.invalidate(),this.multiPage.rebuildAroundActive(e,t),this.requestRenderAll()}multiPageFrameHost(){return{gl:this.handle.gl,vpt:this.vpt,cssWidth:this.cssWidth,cssHeight:this.cssHeight,dpr:this.dpr,zoom:this.zoom,batch:this.batch,meshBatch:this.meshBatch,batchOrder:this.batchOrder,renderer:this.renderer,withPageViewport:(e,t)=>vm(this,e,t),workspaceBackdrop:this.workspaceBackdrop,textures:this.textures,expandUnderlay:()=>{let e=this.expandSessionController.active?this.expandSessionController.target:null;return e?{target:e,underlay:()=>this.expandSessionController.buildUnderlay()}:null},finishOverlay:()=>dc(this),onPageVisible:e=>{this.ensurePageBuilt(e)}}}setViewportTransform(e){let t=this.vpt[0];this.vpt=[...e],this.multiPage.viewportZoom=this.vpt[0],this.renderer.noteVptChange(),this.vpt[0]!==t&&this.doc.setViewportZoom(this.vpt[0]),this.requestRenderAll()}zoomAt(e,t,r){let o=Math.min(_v,Math.max(Iv,this.vpt[0]*r)),i=o/this.vpt[0],s=[o,0,0,o,e-i*(e-this.vpt[4]),t-i*(t-this.vpt[5])];this.vpt=this.multiPage.pageCount>1?this.multiPage.zoomViewportAt(this.vpt,e,t,o):this.documentFlowEnabled?xm(this.vpt,o,zs(this.doc)?.bounds??null,s):s,this.multiPage.viewportZoom=o,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))}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),Ra("engine.render",()=>{let t=this.handle.gl;if(t.viewport(0,0,this.canvasEl.width,this.canvasEl.height),t.clearColor(...this.background),t.clear(t.COLOR_BUFFER_BIT),this.multiPage.pageCount>1){ym(this.multiPage,this.multiPageFrameHost());return}let r=Nt(this.vpt,this.cssWidth,this.cssHeight,this.dpr),o=zs(this.doc)?.bounds,i=o?[o]:[];this.workspaceBackdrop.drawChecker(this.handle.gl,r,{vpt:this.vpt,cssWidth:this.cssWidth,cssHeight:this.cssHeight,dpr:this.dpr},i),this.batch.begin(r,this.zoom*this.dpr),this.meshBatch.begin(r),this.batch.deferDraws=!0,this.meshBatch.deferDraws=!0,this.batchOrder.reset();let s=this.expandSessionController.active?this.expandSessionController.target:null;if(!(!s&&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 a=this.progressiveLoad.limit>=0?Math.min(this.progressiveLoad.limit,this.doc.nodes.length):this.doc.nodes.length;Gs(this.batch,this.renderer,this.doc.nodes,s?{target:s,underlay:()=>this.expandSessionController.buildUnderlay()}:null,a),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},i),dc(this)}),this.retainedFrame.noteFrameRendered(),this.renderer.frame.bakeMore&&this.requestRenderAll(),this.bus.fire("engine:render",performance.now()-e)}readPixels(){return $h(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)}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 Uh(e,()=>this.render())}getSceneSummary(){return Yh(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 le)?!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 le?!!await this.sources.reloadMaskClipImage(t):!1}getCropInfo(){return this.cropSessionController.info}enterCropMode(e){this.pathSessionController.active&&this.pathSessionController.exit();let t=e??this.doc.selection[0];return t?this.cropSessionController.enter(t):!1}exitCropMode(){this.cropSessionController.exit()}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 Ze(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 Vh(this.doc,()=>this.requestRenderAll())}deleteSelection(){return jh(this.doc,()=>this.requestRenderAll())}nudgeSelection(e,t){return qh(this.doc,e,t,()=>this.requestRenderAll())}getSelectionInfo(){return Gh(this.doc,this.marquee,this.zoom,(e,t)=>this.toScreen(e,t))}getActiveGroupChildInfo(){return Xh(this.doc)}getSvgRasterInfo(){return zh(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 Nn=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)}},Bc=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 tn=(n,e=0)=>typeof n=="number"&&Number.isFinite(n)?n:e,Dv=n=>({sx:tn(n.scaleX,1)||1,sy:tn(n.scaleY,1)||1}),fp=n=>{let e=n.pathOffset;return!e||typeof e.x!="number"||typeof e.y!="number"?null:{x:e.x,y:e.y}},Fv=n=>{let e=Ae(n),t=e?qe(e):null;return t?{x:(t.left+t.right)/2,y:(t.top+t.bottom)/2}:null},Ov=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}},Bv=(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`,mp=(n,e)=>`M 0 ${-e} A ${n} ${e} 0 1 1 0 ${e} A ${n} ${e} 0 1 1 0 ${-e} Z`,Hc=n=>{if(n.isTextType)return;let e=n.raw,t=ee(e),{sx:r,sy:o}=Dv(e);if(t===L.PATH){let a=typeof e.path=="string"?e.path:"";return a.trim()?{path:a,pathOffset:fp(e)??Fv(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=ot(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?Bv(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=tn(e.radius);return a>0?{path:mp(a*r,a*o),pathOffset:{x:0,y:0}}:void 0}if(t===L.ELLIPSE){let a=(tn(e.rx)||n.dims.x/2)*r,l=(tn(e.ry)||n.dims.y/2)*o;return!(a>0)||!(l>0)?void 0:{path:mp(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:fp(e)??Ov(a)??{x:0,y:0}}}if(t===L.LINE){let a=tn(e.x1),l=tn(e.y1),c=tn(e.x2),u=tn(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 pp=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]}}},bp=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))}},gp=(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}}),xp=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},Wc=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}},Fr=(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}},yp=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,g=(o*l-i*a)/c,b=(t*a-e*l)/c,x=(e*i-t*o)/c;if(!(Math.abs(x)<1e-6))return{a:u/x,b:h/x,c:d/x,d:f/x,e:m/x,f:p/x,g:g/x,h:b/x}};var vp=32,Sp=120,Gc=1e-6,Hv=()=>{let n=document.createElement("canvas");if(!n||typeof n.getContext>"u")throw new Error("Failed to create `canvas` element");return n},Wv=n=>{let e=Hv();return e.width=n.width,e.height=n.height,e.getContext("2d",{willReadFrequently:!0})?.drawImage(n,0,0),e},Gv=(n,e,t)=>n.toDataURL?.(`image/${e}`,t),Xv=n=>new Promise((e,t)=>{let r=new FileReader;r.onload=()=>e(String(r.result)),r.onerror=()=>t(r.error),r.readAsDataURL(n)}),wp=async(n,e,t)=>{try{let r=await new Promise(o=>n.toBlob(o,`image/${e}`,t));if(r)return await Xv(r)}catch{}return Gv(n,e,t)},zv=(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)<Gc&&Math.abs(o-s)<Gc)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},Yv=(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,g=(u*e+c)*4,b=1-d,x=1-h,y=x*b,S=h*b,v=x*d,T=h*d;return[n[f]*y+n[m]*S+n[p]*v+n[g]*T,n[f+1]*y+n[m+1]*S+n[p+1]*v+n[g+1]*T,n[f+2]*y+n[m+2]*S+n[p+2]*v+n[g+2]*T,n[f+3]*y+n[m+3]*S+n[p+3]*v+n[g+3]*T]},Uv=(n,e,t)=>{let r=Wc(t),o=r?yp(r):void 0;if(!o){Ep(n,e,t,vp);return}let i=Math.max(1,e.width),s=Math.max(1,e.height),a=e.getContext("2d",{willReadFrequently:!0});if(!a){Ep(n,e,t,vp);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=Fr(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),g=Yv(l.data,i,s,m,p),b=(h*n.canvas.width+d)*4;u[b]=g[0],u[b+1]=g[1],u[b+2]=g[2],u[b+3]=g[3]}n.putImageData(c,0,0)},Tp=(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)<Gc)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,g=(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,g),n.drawImage(e,0,0),n.restore()},Ep=(n,e,t,r)=>{let o=Wc(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(Sp,Math.max(1,Math.ceil(i/r))),l=Math.min(Sp,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,g=(m+1)/a,b=p*i,x=g*i,y=Fr(o,p,u),S=Fr(o,g,u),v=Fr(o,g,h),T=Fr(o,p,h);Tp(n,e,[{x:b,y:d},{x,y:d},{x,y:f}],[y,S,v]),Tp(n,e,[{x:b,y:d},{x,y:f},{x:b,y:f}],[y,v,T])}}},$v=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=zv(n,a,l),u=pp(e?.nonAffineTransform||e?.transform);if(!u){let b=Wv(n);return{src:await wp(b,o,r),width:i,height:s,sourceWidth:a,sourceHeight:l}}let h=bp(u),d=gp(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",xp(d)){let b=(d.tr.x-d.tl.x)/a,x=(d.tr.y-d.tl.y)/a,y=(d.bl.x-d.tl.x)/l,S=(d.bl.y-d.tl.y)/l,v=d.tl.x,T=d.tl.y;p.setTransform(b,x,y,S,v,T),p.drawImage(c,0,0)}else Uv(p,c,d);let g;if(f){let b=Math.round(f.left-h.minX),x=Math.round(f.top-h.minY),y=Math.max(1,Math.round(f.width)),S=Math.max(1,Math.round(f.height));if(b>=0&&x>=0&&b+y<=h.width+1&&x+S<=h.height+1){g=document.createElement("canvas"),g.width=y,g.height=S;let T=g.getContext("2d");T&&T.drawImage(m,b,x,y,S,0,0,y,S)}else{g=document.createElement("canvas"),g.width=y,g.height=S;let T=g.getContext("2d");T&&(T.imageSmoothingEnabled=!0,T.imageSmoothingQuality="high",T.drawImage(m,0,0,h.width,h.height,0,0,y,S))}}else g=m;return{src:await wp(g,o,r),width:g.width,height:g.height,sourceWidth:a,sourceHeight:l}};var oe=n=>n.node instanceof te?n.node:null,Oe=n=>n.raw,Pt=n=>{n.canvas?.requestRenderAll?.()},Ue=(n,e)=>{let t=Oe(e);n.set({cellData:t.cellData??[],rows:t.rows,cols:t.cols}),Pt(n)},Xc=n=>n.rows??3,zc=n=>n.cols??3,Or=n=>(Array.isArray(n.cellData)||(n.cellData=[]),n.cellData),_o=(n,e,t)=>{let r=Se(n.cellMap,e,t);if(r)return r.isMerged&&r.mergeParent?Se(n.cellMap,r.mergeParent.row,r.mergeParent.col):r},Xt=(n,e)=>{let t=oe(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=Se(t.cellMap,i.row,i.col);a&&e(a)}Ue(n,t)},Yc=(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]}}),Mp=(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??Oe(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(){}}),Vv={canMergeCells(){let n=oe(this);return!!n&&n.selectedCells.length>1},canUseMergeCells(){let n=oe(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=_o(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=oe(this);if(!n||!n.selectedCells.length)return!1;let e=n.selectedCells[0],t=_o(n,e.row,e.col);return!!t&&(t.rowspan??1)>1},canSplitColumns(){let n=oe(this);if(!n||!n.selectedCells.length)return!1;let e=n.selectedCells[0],t=_o(n,e.row,e.col);return!!t&&(t.colspan??1)>1},isSelectColumn(){let n=oe(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===Xc(Oe(n))-1,a=e.size>=2,l=!1;for(let c of n.selectedCells)if((_o(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=oe(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===zc(Oe(n))-1,a=t.size>=2,l=!1;for(let c of n.selectedCells)if((_o(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=oe(this);return e?yr(e.cellMap,e.selectedCells).rows.has(n):!1},isColumnSelected(n){let e=oe(this);return e?yr(e.cellMap,e.selectedCells).cols.has(n):!1},selectCell(n,e,t=!1){let r=oe(this);if(r){if(t){if(r.cellAnchor){let o=r.cellAnchor,i=un(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=oe(this);e&&(e.setColumnSelection(n),Pt(this))},selectRow(n){let e=oe(this);e&&(e.setRowSelection(n),Pt(this))},selectAllCells(){let n=oe(this);if(!n)return;let e=n.tableView,t=io(n.cellMap,e.rows,e.cols);n.setCellSelection(t,t[0]??null,We(t)),Pt(this)},clearCellSelection(){let n=oe(this);n&&(n.clearCellSelection(),Pt(this))},buildSelectionRange(n,e){let t=oe(this);return t?un(t.cellMap,n,e):[]},mergeCells(n,e,t,r){let o=oe(this);if(!o)return;let i=Jr(o.raw,n,e,t,r),s={row:i.r1,col:i.c1};o.setCellSelection([s],s,i),Ue(this,o)},unmergeCells(n,e){let t=oe(this);if(!t||!eo(t.raw,n,e))return;let r={row:n,col:e};t.setCellSelection([r],r,{r1:n,r2:n,c1:e,c2:e}),Ue(this,t)},addRow(n){let e=oe(this);e&&(to(e.raw,n??Xc(Oe(e))),Ue(this,e))},removeRow(n){let e=oe(this);if(!e)return;let t=n??Xc(Oe(e))-1;if(!el(e.raw,t))return;let r=di(e.selectedCells,e.cellRange,t,"row");r?e.setCellSelection(r.cells,r.cells[0]??null,r.range):e.clearCellSelection(),Ue(this,e)},addColumn(n){let e=oe(this);e&&(no(e.raw,n??zc(Oe(e))),Ue(this,e))},removeColumn(n){let e=oe(this);if(!e)return;let t=n??zc(Oe(e))-1;if(!tl(e.raw,t))return;let r=di(e.selectedCells,e.cellRange,t,"col");r?e.setCellSelection(r.cells,r.cells[0]??null,r.range):e.clearCellSelection(),Ue(this,e)},setColumnWidth(n,e){let t=oe(this);t&&(Qr(t.raw,n,e),this.set({columnWidths:Oe(t).columnWidths??[]}),Pt(this))},setRowHeight(n,e){let t=oe(this);t&&(Zr(t.raw,n,e),this.set({manualRowHeights:Oe(t).manualRowHeights??[]}),Pt(this))},setSelectWidth(n){let e=oe(this);if(!e)return;let t=e.cellRange,r=Oe(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=oe(this);if(!e)return;let t=e.cellRange,r=Oe(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=oe(this);return e?e.tableView.columnWidths[n]??0:0},getRowHeight(n){let e=oe(this);return e?e.tableView.rowHeights[n]??0:0},getRowMinHeight(n){let e=oe(this);return e?e.getRowMinHeight(n):0},relayout(){let n=oe(this);n&&(n.rebuildTable(),Pt(this))},previewLayout(){this.relayout()},getCell(n,e){let t=oe(this);if(!t)return;let r=Se(t.cellMap,n,e);return r?Yc(t,r,()=>Ue(this,t)):void 0},getCellText(n,e){let t=oe(this);if(!t)return;let r=Se(t.cellMap,n,e);return r?Mp(t,r,()=>Ue(this,t)):void 0},setSelectionTextAlign(n){Xt(this,e=>{e.textAlign=n})},setSelectionFontSize(n){Xt(this,e=>{e.fontSize=n})},changeSelectionFontSize(n){let e=oe(this);if(!e)return;let t=Oe(e).fontSize??14;Xt(this,r=>{let o=Number(r.fontSize)||t;r.fontSize=n==="+"?o+1:Math.max(1,o-1)})},setSelectionFontWeight(n){Xt(this,e=>{e.fontWeight=n})},setSelectionFontStyle(n){Xt(this,e=>{e.fontStyle=n})},setSelectionUnderline(n){Xt(this,e=>{e.underline=n})},setSelectionLinethrough(n){Xt(this,e=>{e.linethrough=n})},setSelectionCellFill(n){Xt(this,e=>{e.fill=n,e.hasCustomFill=!0})},setSelectionCellStroke(n){Xt(this,e=>{e.stroke=n,e.hasCustomStroke=!0})},setSelectionCellStrokeWidth(n){Xt(this,e=>{e.strokeWidth=n,e.hasCustomStroke=!0})},updateCellFill(n){let e=oe(this);if(!e)return;let t=Oe(e);t.cellFill=n;for(let r of Or(t))!r.isMerged&&!r.hasCustomFill&&(r.fill=n);Ue(this,e)},updateCellTextFill(n){let e=oe(this);if(!e)return;let t=Oe(e);t.textFill=n;for(let r of Or(t))r.hasCustomTextFill||(r.textFill=n);Ue(this,e)},updateCellStroke(n){let e=oe(this);if(!e)return;let t=Oe(e);t.cellStroke=n;for(let r of Or(t))r.hasCustomStroke||(r.stroke=n);Ue(this,e)},updateBorderWidth(n){let e=oe(this);e&&(Oe(e).cellStrokeWidth=n,Ue(this,e))},applyTextStylesToAll(n){let e=oe(this);if(!e)return;let t=Oe(e),r={...t.textDefaults??{}};for(let[o,i]of Object.entries(n))r[o]=i;t.textDefaults=r;for(let o of Or(t))for(let[i,s]of Object.entries(n))i==="fill"?o.textFill=s:o[i]=s;Ue(this,e)}},jv={selectedCells(){let n=oe(this);if(n)return n.selectedCells.map(e=>{let t=Se(n.cellMap,e.row,e.col);return t?Yc(n,t,()=>Ue(this,n)):void 0}).filter(e=>e!==void 0)},_selectedCells(){let n=oe(this);return n?n.selectedCells:void 0},_selectionRange(){let n=oe(this);return n?n.cellRange:void 0},hasSelection(){let n=oe(this);return n?n.hasCellSelection:!1},selectionCount(){let n=oe(this);return n?n.selectedCells.length:0},cellTexts(){let n=oe(this);if(!n)return;let e=()=>Ue(this,n);return Or(Oe(n)).map(t=>Mp(n,t,e))},cells(){let n=oe(this);if(!n)return;let e=()=>Ue(this,n);return Or(Oe(n)).map(t=>Yc(n,t,e))},columnWidths(){let n=oe(this);return n?[...n.tableView.columnWidths]:void 0},rowHeights(){let n=oe(this);return n?[...n.tableView.rowHeights]:void 0}},Uc=n=>{for(let[e,t]of Object.entries(Vv))Object.assign(n,{[e]:t});for(let[e,t]of Object.entries(jv))Object.defineProperty(n,e,{get:t,configurable:!0,enumerable:!1})};var $c=(n,e,t)=>{let r=Ke(e);if(!r)return null;let o=Mt(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 Cp=new Set([L.ARCHTEXT,L.WAISTTEXT,L.FLAGTEXT]),qv=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},ar=class{node;ctx;constructor(e,t){this.node=e,this.ctx=t}set(e,t){let r=typeof e=="string"?{[e]:t}:e;if("cropAspectRatio"in r){let i={cropAspectRatio:r.cropAspectRatio};delete r.cropAspectRatio,this.ctx.setNodeProps(this.node,i)}if("__isCropping"in r){let i=!!r.__isCropping;delete r.__isCropping,this.clearSessionFlagDirty("__isCropping"),this.__isCropping=i}if("__isExpand"in r){let i=!!r.__isExpand;delete r.__isExpand,this.clearSessionFlagDirty("__isExpand"),this.__isExpand=i}if(typeof r.width=="number"&&Mr(this.node)){let i=r.width;delete r.width,this.ctx.setGroupWidth?this.ctx.setGroupWidth(this.node,i):this.ctx.setNodeProps(this.node,{width:i})}this.bumpTextboxWidthToLayoutBox(r),this.bridgeImageSizeProps(r);let o=r;if((typeof r.width=="number"||typeof r.height=="number")&&!("clipImage"in r)&&rt.has(ee(this.node.raw))){let i=Ln(this.node),s=this.node.raw,a=Number(s.width)||0,l=Number(s.height)||0,c=typeof r.width=="number"?r.width:a,u=typeof r.height=="number"?r.height:l,h=this.node.clipImageEl,d=h?.naturalWidth||Number(i?.width)||0,f=h?.naturalHeight||Number(i?.height)||0;if(i&&a>0&&l>0&&c>0&&u>0&&d>0&&f>0){let m=(b,x)=>Math.max(b/d,x/f),p=Number(i.scaleX)||1,g=m(c,u)*(p/m(a,l));o={...r,clipImage:{...i,scaleX:g,scaleY:g}}}}return Object.keys(o).length>0&&this.ctx.setNodeProps(this.node,o),this}bumpTextboxWidthToLayoutBox(e){if(typeof e.width!="number"||!(this.node instanceof ge)||e.width<0||ee(this.node.raw)!==L.TEXTBOX||Ke(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 Nn(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 Nn(0,0),l=new Nn(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||Hc(this.node)}toPathDecorations(){return this.ctx.getTextDecorations?.(this.node)??[]}toPathEffectLayers(e){return[]}_getTransformedDimensions(){let e=this.node.raw;return new Nn(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}}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),g={x:e.x-(h*m-d*p),y:e.y-(h*p+d*m)},b=xe({...o},g);return this.set({left:b.x,top:b.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 Z)return()=>this.node.children.map(e=>this.ctx.wrapNode(e))}get _objects(){if(this.node instanceof Z)return this.node.children.map(e=>this.ctx.wrapNode(e))}get ref(){return this}get isImageLikeNode(){let e=ee(this.node.raw);return ft.has(e)||rt.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 re?()=>e.paintSource??e.imageEl:()=>e.imageEl}get _element(){if(this.isImageLikeNode)return this.node.imageEl}get clipImage(){return Ln(this.node)?Qv(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 re){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(Mr(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(!this.ctx.enterCropSession?.(this.node))return;t&&(this.cropBeforeState=this.toObject());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)return!1;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 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)*5;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)*5;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+20}isType(...e){let t=ee(this.node.raw);return e.some(r=>r.toLowerCase()===t)}getStyleAtPosition(e){if(!(this.node instanceof ge))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(`
1055
1055
  `);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((u,h)=>u+h,0);if(a<=0)return;let l=(e-i-(r-1)*s)/a,c=t.minCellWidth??0;this.set({columnWidths:o.map(u=>Math.max(c,u*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((u,h)=>u+h,0);if(a<=0)return;let l=(e-i-(r-1)*s)/a,c=t.minCellHeight??0;this.set({manualRowHeights:o.map(u=>Math.max(c,u*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(`
1056
1056
  `);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 c in r){i=0;for(let u in r[c]){let h=r[c][u]||{},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[c][u]}i===0&&delete r[c]}if(typeof t.text=="string")for(let c of t.text.split(`
1057
- `))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 xe))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 xe))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 xe?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 J(this.node.raw)}get setRadius(){if(this.rawTypeLower===L.ARCTEXT)return e=>this.set({curvature:e})}get setWarpStrength(){if(pp.has(this.rawTypeLower))return e=>this.set({warpStrength:Math.max(-1,Math.min(1,e))})}get clearCache(){if(pp.has(this.rawTypeLower))return()=>{this.ctx.invalidateNodeBakes?.(this.node),this.ctx.getCanvas?.()?.requestRenderAll?.()}}get setCircleParams(){if(this.rawTypeLower===L.CIRCLETEXT)return e=>this.set(e)}get setTexts(){if(this.node instanceof xe)return e=>this.set({texts:e})}get texts(){if(!(this.node instanceof xe))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 xe){let r=this.node.textLayout,o=this.node.textStyle.lineHeight??1.16,i=Xc(r,this.node.raw,o);i&&(t.charTransformations=i),r.lines.length>0&&!Av(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=Yc(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=Yc(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 se)return e=>{this.node.applyMaskParams(e),this.ctx.getCanvas?.()?.requestRenderAll?.()}}get updateGapParams(){if(this.node instanceof se)return e=>{this.node.updateGapParams(e),this.ctx.getCanvas?.()?.requestRenderAll?.()}}get updateLayout(){if(this.node instanceof se)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=>ql(Ae(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)}}},An=n=>{let e=n.raw;if(!nt.has(J(e)))return null;let t=e.clipImage;return!t||typeof t!="object"||typeof t.src!="string"?null:t},Nv=new Set(["_cacheCanvas","dirty","canvas"]),zc=class{constructor(e,t){this.node=e;this.ctx=t}node;ctx;set(e){let t=An(this.node);if(!t)return this;let r={...t};for(let[o,i]of Object.entries(e))Nv.has(o)||(r[o]=i);return this.ctx.setNodeProps(this.node,{clipImage:r}),this}toObject(e){let t=An(this.node);return t?{...t}:{}}setCoords(){}getSrc(){let e=An(this.node);return e&&typeof e.originalSrc=="string"&&e.originalSrc?e.originalSrc:e&&typeof e.src=="string"?e.src:""}getOriginalElementWidth(){let e=this.node.clipImageEl;return e?.naturalWidth||e?.width||Number(An(this.node)?.width)||0}getOriginalElementHeight(){let e=this.node.clipImageEl;return e?.naturalHeight||e?.height||Number(An(this.node)?.height)||0}},Yc=(n,e)=>{if(!n)return;let t=r=>{for(let o of r){if(!(o instanceof ee))continue;if(o.children.some(s=>s===e))return o;let i=t(o.children);if(i)return i}};return t(n.nodes)},Lv=(n,e)=>{let t=new zc(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=An(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)}})};Gc(sr.prototype);var Iv=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}}},_v=(n,e)=>{let t=new sr(n,e);return n instanceof yr&&(t._calcDimensions=()=>Iv(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 Dv=(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 sr?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 ya=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}},at=new WeakMap,xa=new WeakMap,Fv=(n,e)=>n.nodes.includes(e),Nn=(n,e)=>{let t=at.get(e);if(!t)return!1;let r=e.raw,o=ya(r);if(!o||e.visible===!1)return n.setProps(t,{visible:!1}),!0;let i=e.dims;if(!i.x||!i.y)return!1;let s=e.center;return n.setProps(t,{left:s.x,top:s.y,originX:"center",originY:"center",angle:Number(r.angle)||0,flipX:r.flipX===!0,flipY:r.flipY===!0,scaleX:(r.scaleX??1)*(i.x/o.width),scaleY:(r.scaleY??1)*(i.y/o.height),opacity:r.opacity??1,visible:!0}),!0},va=(n,e)=>{if(!(e instanceof xe))return null;if(at.has(e))return Nn(n,e),at.get(e)??null;let t=ya(e.raw);if(!t)return null;let r=ct({type:"Path",id:`${e.id||"text"}__pathbg`,path:t.path,...t.fill?{fill:t.fill}:{},evented:!1,selectable:!1,visible:!1});if(!r)return null;r.syntheticOwner=e.id||"text",at.set(e,r),xa.set(r,e);let o=n.nodes.indexOf(e);return n.insertAt(o<0?n.nodes.length:o,r),Nn(n,e),r},Ov=n=>{let e=0;for(let t of[...n.nodes])t.syntheticOwner||va(n,t)&&e++;return e},Bv=(n,e)=>{if(at.has(e)){Nn(n,e);return}e instanceof xe&&ya(e.raw)&&va(n,e)},Hv=(n,e)=>{let t=at.get(e);if(!t)return;let r=n.nodes.indexOf(e);if(r<0)return;let o=n.nodes.indexOf(t);if(o===r-1)return;if(o<0){n.insertAt(r,t);return}let i=o<r?r-1:r;n.moveNodeTo(t,i)},Wv=(n,e)=>{let t=at.get(e);t&&(at.delete(e),xa.delete(t),Fv(n,t)&&n.remove(t))},Gv=(n,e={})=>{let t=()=>e.requestRender?.(),r=n.events,o=s=>{at.has(s)&&Nn(n,s);for(let a of n.selection)a!==s&&at.has(a)&&Nn(n,a)},i=[r.on("object:added",s=>{s.syntheticOwner||va(n,s)&&t()}),r.on("object:removed",s=>{let a=xa.get(s);if(a){at.delete(a),xa.delete(s);return}at.has(s)&&Wv(n,s)}),r.on("object:moving",s=>{o(s)}),r.on("object:scaling",s=>{o(s)}),r.on("object:rotating",s=>{o(s)}),r.on("object:modified",s=>{let a=!1;for(let l of s)at.has(l)&&(Nn(n,l),a=!0);a&&t()}),r.on("text:changed",s=>{at.has(s)&&(Nn(n,s),t())})];return()=>i.forEach(s=>s())};var Cp=new Set([L.ELLIPSE,L.CIRCLE]),Xv=new Set([L.TRIANGLE]),Vc=new Set([L.POLYGON]),Rp=new Set([L.POLYLINE]),bp=new Set([L.ARROW]),zv=new Set([L.DIMENSION]),Yv=new Set([L.GROUP,L.PUZZLE]),gp=new Set([...ft,L.GIF]),xp=new Set([L.TABLE]),Uc=new Set(["multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"]),Uv=n=>{if(!(Number(n.warpStrength)||0))return null;let t=J(n);return t===L.ARCHTEXT?"arch":t===L.WAISTTEXT?"waist":t===L.FLAGTEXT?"flag":null},$c=n=>{let e=n.effects;return!!e&&typeof e=="object"&&!Array.isArray(e)},$v=n=>typeof n.textBackgroundColor=="string"&&n.textBackgroundColor?!0:Array.isArray(n.texts)&&n.texts.length>0,Vv=new Set(["rect","Rect","fabricrect","ellipse","Ellipse","circle","Circle","polygon","Polygon","polyline","Polyline","Path","path"]),jv=.222,q=(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,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;"),qv=/^(#[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=>qv.test(n.trim())?n.trim():null,In=n=>n==null||n===""||n==="transparent"||n==="rgba(0,0,0,0)"||n==="none",jc=n=>`matrix(${n.map(N).join(",")})`,Kv=(n,e)=>[1,0,0,1,n,e],yp=n=>n,vp=(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}},Sp=n=>{let e=n.pathOffset;if(!e||typeof e!="object")return null;let t=typeof e.x=="number"&&Number.isFinite(e.x)?e.x:0,r=typeof e.y=="number"&&Number.isFinite(e.y)?e.y:0;return t||r?Kv(-t,-r):null},Qv=n=>n.map(e=>e.length===1?e[0]:`${e[0]} ${e.slice(1).map(t=>N(Number(t))).join(" ")}`).join(" "),wp=(n,e,t)=>{let r=J(n);if(Wn.has(r)){let o=Math.min(q(n,"rx",0),e/2),i=Math.min(q(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(Cp.has(r))return{open:`<ellipse cx="0" cy="0" rx="${N(e/2)}" ry="${N(t/2)}"`,internalTransform:null};if(Xv.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=Ae(n.path);return o?{open:`<path d="${ne(Qv(o))}"`,internalTransform:Sp(n)}:null}if(Vc.has(r)||Rp.has(r)){let o=n.points;if(!Array.isArray(o)||o.length===0)return null;let i=o.map(a=>{let l=a,c=typeof l.x=="number"?l.x:NaN,u=typeof l.y=="number"?l.y:NaN;return Number.isFinite(c)&&Number.isFinite(u)?`${N(c)},${N(u)}`:null}).filter(a=>a!==null);return i.length?{open:`<${Vc.has(r)?"polygon":"polyline"} points="${i.join(" ")}"`,internalTransform:Sp(n)}:null}return mt.has(r)?{open:`<line x1="${N(q(n,"x1",0))}" y1="${N(q(n,"y1",0))}" x2="${N(q(n,"x2",0))}" y2="${N(q(n,"y2",0))}"`,internalTransform:null}:null},Tp=(n,e,t)=>{let r=e&&n.internalTransform?Y(e,n.internalTransform):e??n.internalTransform;return`${n.open}${r?` transform="${jc(r)}"`:""}${t}/>`},Zv=(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(q(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},Jv=n=>!In(n.stroke)&&q(n,"strokeWidth",1)>0,Ep=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}},eS=(n,e)=>{let t=0;for(let r of n)t+=r.charCodeAt(0)>255?1:.55;return t*e},Pp=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}},tS=(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{}},Mp=(n,e,t,r)=>{let o=t;for(let a=0;a<e;a++)o+=r.textLines[a].length+1;let i=tS(n,o),s=(a,l)=>i[a]!==void 0?i[a]:l;return{fontFamily:s("fontFamily",Ie(n,"fontFamily")??"Arial"),fontSize:s("fontSize",q(n,"fontSize",40)),fontWeight:s("fontWeight",String(Ie(n,"fontWeight")??"normal")),fontStyle:s("fontStyle",Ie(n,"fontStyle")??"normal"),fill:s("fill",n.fill),stroke:s("stroke",n.stroke),strokeWidth:s("strokeWidth",q(n,"strokeWidth",1)),underline:s("underline",n.underline===!0),linethrough:s("linethrough",n.linethrough===!0),overline:s("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??pe.LEFT}),_o=(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:q(t,"strokeWidth",1),underline:t.underline===!0,linethrough:t.linethrough===!0,overline:t.overline===!0}),nS=(n,e)=>{if(!Array.isArray(e)||e.length===0)return e&&typeof e=="object"?e:void 0;let t=[0];for(let i=0;i<n.length;i++)n[i]===`
1057
+ `))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 ge))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 ge))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 ge?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 ee(this.node.raw)}get setRadius(){if(this.rawTypeLower===L.ARCTEXT)return e=>this.set({curvature:e})}get setWarpStrength(){if(Cp.has(this.rawTypeLower))return e=>this.set({warpStrength:Math.max(-1,Math.min(1,e))})}get clearCache(){if(Cp.has(this.rawTypeLower))return()=>{this.ctx.invalidateNodeBakes?.(this.node),this.ctx.getCanvas?.()?.requestRenderAll?.()}}get setCircleParams(){if(this.rawTypeLower===L.CIRCLETEXT)return e=>this.set(e)}get setTexts(){if(this.node instanceof ge)return e=>this.set({texts:e})}get texts(){if(!(this.node instanceof ge))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 ge){let r=this.node.textLayout,o=this.node.textStyle.lineHeight??1.16,i=$c(r,this.node.raw,o);i&&(t.charTransformations=i),r.lines.length>0&&!qv(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=jc(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=jc(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 se)return e=>{this.node.applyMaskParams(e),this.ctx.getCanvas?.()?.requestRenderAll?.()}}get updateGapParams(){if(this.node instanceof se)return e=>{this.node.updateGapParams(e),this.ctx.getCanvas?.()?.requestRenderAll?.()}}get updateLayout(){if(this.node instanceof se)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=>ql(Ae(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)}}},Ln=n=>{let e=n.raw;if(!rt.has(ee(e)))return null;let t=e.clipImage;return!t||typeof t!="object"||typeof t.src!="string"?null:t},Kv=new Set(["_cacheCanvas","dirty","canvas"]),Vc=class{constructor(e,t){this.node=e;this.ctx=t}node;ctx;set(e){let t=Ln(this.node);if(!t)return this;let r={...t};for(let[o,i]of Object.entries(e))Kv.has(o)||(r[o]=i);return this.ctx.setNodeProps(this.node,{clipImage:r}),this}toObject(e){let t=Ln(this.node);return t?{...t}:{}}setCoords(){}getSrc(){let e=Ln(this.node);return e&&typeof e.originalSrc=="string"&&e.originalSrc?e.originalSrc:e&&typeof e.src=="string"?e.src:""}getOriginalElementWidth(){let e=this.node.clipImageEl;return e?.naturalWidth||e?.width||Number(Ln(this.node)?.width)||0}getOriginalElementHeight(){let e=this.node.clipImageEl;return e?.naturalHeight||e?.height||Number(Ln(this.node)?.height)||0}},jc=(n,e)=>{if(!n)return;let t=r=>{for(let o of r){if(!(o instanceof Z))continue;if(o.children.some(s=>s===e))return o;let i=t(o.children);if(i)return i}};return t(n.nodes)},Qv=(n,e)=>{let t=new Vc(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=Ln(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)}})};Uc(ar.prototype);var Zv=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}}},Jv=(n,e)=>{let t=new ar(n,e);return n instanceof vr&&(t._calcDimensions=()=>Zv(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 eS=(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 ar?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 Op=new Set([L.ELLIPSE,L.CIRCLE]),tS=new Set([L.TRIANGLE]),Qc=new Set([L.POLYGON]),Bp=new Set([L.POLYLINE]),Rp=new Set([L.ARROW]),nS=new Set([L.DIMENSION]),rS=new Set([L.GROUP,L.PUZZLE]),Pp=new Set([...ft,L.GIF]),kp=new Set([L.TABLE]),qc=new Set(["multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"]),oS=n=>{if(!(Number(n.warpStrength)||0))return null;let t=ee(n);return t===L.ARCHTEXT?"arch":t===L.WAISTTEXT?"waist":t===L.FLAGTEXT?"flag":null},Kc=n=>{let e=n.effects;return!!e&&typeof e=="object"&&!Array.isArray(e)},iS=n=>typeof n.textBackgroundColor=="string"&&n.textBackgroundColor?!0:Array.isArray(n.texts)&&n.texts.length>0,sS=new Set(["rect","Rect","fabricrect","ellipse","Ellipse","circle","Circle","polygon","Polygon","polyline","Polyline","Path","path"]),aS=.222,q=(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,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;"),lS=/^(#[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_-]*)$/,rn=n=>lS.test(n.trim())?n.trim():null,_n=n=>n==null||n===""||n==="transparent"||n==="rgba(0,0,0,0)"||n==="none",Zc=n=>`matrix(${n.map(N).join(",")})`,cS=(n,e)=>[1,0,0,1,n,e],Ap=n=>n,Np=(n,e,t)=>Bn({...n,width:e,height:t}),nn=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(rn(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}},Lp=n=>{let e=n.pathOffset;if(!e||typeof e!="object")return null;let t=typeof e.x=="number"&&Number.isFinite(e.x)?e.x:0,r=typeof e.y=="number"&&Number.isFinite(e.y)?e.y:0;return t||r?cS(-t,-r):null},uS=n=>n.map(e=>e.length===1?e[0]:`${e[0]} ${e.slice(1).map(t=>N(Number(t))).join(" ")}`).join(" "),Ip=(n,e,t)=>{let r=ee(n);if(Gn.has(r)){let o=Math.min(q(n,"rx",0),e/2),i=Math.min(q(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(Op.has(r))return{open:`<ellipse cx="0" cy="0" rx="${N(e/2)}" ry="${N(t/2)}"`,internalTransform:null};if(tS.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=Ae(n.path);return o?{open:`<path d="${ne(uS(o))}"`,internalTransform:Lp(n)}:null}if(Qc.has(r)||Bp.has(r)){let o=n.points;if(!Array.isArray(o)||o.length===0)return null;let i=o.map(a=>{let l=a,c=typeof l.x=="number"?l.x:NaN,u=typeof l.y=="number"?l.y:NaN;return Number.isFinite(c)&&Number.isFinite(u)?`${N(c)},${N(u)}`:null}).filter(a=>a!==null);return i.length?{open:`<${Qc.has(r)?"polygon":"polyline"} points="${i.join(" ")}"`,internalTransform:Lp(n)}:null}return mt.has(r)?{open:`<line x1="${N(q(n,"x1",0))}" y1="${N(q(n,"y1",0))}" x2="${N(q(n,"x2",0))}" y2="${N(q(n,"y2",0))}"`,internalTransform:null}:null},_p=(n,e,t)=>{let r=e&&n.internalTransform?Y(e,n.internalTransform):e??n.internalTransform;return`${n.open}${r?` transform="${Zc(r)}"`:""}${t}/>`},hS=(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(q(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},dS=n=>!_n(n.stroke)&&q(n,"strokeWidth",1)>0,Dp=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}},fS=(n,e)=>{let t=0;for(let r of n)t+=r.charCodeAt(0)>255?1:.55;return t*e},Hp=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}},mS=(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{}},Fp=(n,e,t,r)=>{let o=t;for(let a=0;a<e;a++)o+=r.textLines[a].length+1;let i=mS(n,o),s=(a,l)=>i[a]!==void 0?i[a]:l;return{fontFamily:s("fontFamily",Ie(n,"fontFamily")??"Arial"),fontSize:s("fontSize",q(n,"fontSize",40)),fontWeight:s("fontWeight",String(Ie(n,"fontWeight")??"normal")),fontStyle:s("fontStyle",Ie(n,"fontStyle")??"normal"),fill:s("fill",n.fill),stroke:s("stroke",n.stroke),strokeWidth:s("strokeWidth",q(n,"strokeWidth",1)),underline:s("underline",n.underline===!0),linethrough:s("linethrough",n.linethrough===!0),overline:s("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??pe.LEFT}),Do=(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:q(t,"strokeWidth",1),underline:t.underline===!0,linethrough:t.linethrough===!0,overline:t.overline===!0}),pS=(n,e)=>{if(!Array.isArray(e)||e.length===0)return e&&typeof e=="object"?e:void 0;let t=[0];for(let i=0;i<n.length;i++)n[i]===`
1058
1058
  `&&t.push(i+1);let r=i=>{let s=-1;for(let a=0;a<t.length;a++)i>=t[a]&&(s=a);return s<0?null:[s,i-t[s]]},o={};for(let i of e){if(!i||typeof i!="object")continue;let s=typeof i.start=="number"?i.start:-1,a=typeof i.end=="number"?i.end:-1;if(!(s<0||a<=s||!i.style||typeof i.style!="object"))for(let l=s;l<a&&l<n.length;l++){if(n[l]===`
1059
- `)continue;let c=r(l);c&&((o[c[0]]??={})[c[1]]=i.style)}}return Object.keys(o).length>0?o:void 0},rS=(n,e,t,r)=>{let o=n??pe.LEFT;return Ut(o)?r?o===pe.JUSTIFY_CENTER?(e-t)/2:o===pe.JUSTIFY_RIGHT?e-t:0:0:o===pe.CENTER?(e-t)/2:o===pe.RIGHT?e-t:0},qc=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("")},kp=(n,e,t,r,o={})=>{let i=-1;for(let d=0;d<e.textLines.length;d++)e.textLines[d].length>0&&(i=d);let s=q(n,"lineHeight",1.16)||1.16,a=Ie(n,"textAlign"),l=-t/2,c=-r/2,u=[],h=0;for(let d=0;d<e.textLines.length;d++){let f=e.textLines[d],m=e.charBounds[d],p=e.lineHeights[d],g=p/s,b=c+h+g-p*jv/s,x=0;for(let R of m)!R||typeof R.left!="number"||typeof R.kernedWidth!="number"||(x=Math.max(x,R.left+R.kernedWidth));let y=rS(a,t,x,d>=i),S=o.lineLefts?.[d]??l+y,v=o.anchor==="boxLeft",M=S,C=0;for(let R=0;R<=f.length-1;R++){let w=f[R],T=m[R];if(!(!T||typeof T.width!="number"||typeof T.kernedWidth!="number")){if(v){u.push({char:w,x:S+(T.left||0),y:b,style:Mp(n,d,R,e)});continue}C===0?(M+=T.kernedWidth-T.width,C=T.width):C+=T.width,u.push({char:w,x:M,y:b,style:Mp(n,d,R,e)}),M+=C,C=0}}h+=p}return u},oS=(n,e,t={})=>{if(!e)return null;let r=n,o=q(r,"width",NaN),i=q(r,"height",NaN);if(!Number.isFinite(o)||!Number.isFinite(i)||r.vertical===!0||typeof r.direction=="string"&&r.direction!=="ltr")return null;let s=Pp(r);if(!s)return null;let a=[];for(let{char:l,x:c,y:u,style:h}of kp(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=qc(d.getPath(l,c,u,h.fontSize).commands);a.push(f.endsWith("Z")?f:`${f} Z`)}return a.length>0?{path:a.join(" ")}:null},Sa=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&&!In(e.background)?nn(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="${ne(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=zo(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[c,u,h,d]=l.color,f=`rgb(${Math.round(c*255)},${Math.round(u*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(In(e))return null;if(typeof e=="string")return nn(e)??void 0;if(!e||typeof e!="object"||Array.isArray(e))return;let o=ur(e);if(o)return this.emitGradientDef(o,t,r);let i=Yo(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=Uo(e,t,r);return this.defs.push(`<pattern id="${i}" patternUnits="userSpaceOnUse" width="${N(o.width)}" height="${N(o.height)}" patternTransform="${jc(s)}"><image href="${ne(e.src)}" xlink:href="${ne(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="${ne(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"||!Vv.has(o.type)||o.inverted===!0)return null;let i=q(o,"width",0),s=q(o,"height",0),a=wp(o,i,s);if(!a)return null;let l=vp(o,i,s),c=o.absolutePositioned===!0?Y(Te(t),l):l,u=this.nextId("esvg-c");return this.defs.push(`<clipPath id="${u}">${Tp(a,c,"")}</clipPath>`),` clip-path="url(#${u})"`}emitBakedTextImage(e,t){let r=tn(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="${ne(t.dataUrl)}" xlink:href="${ne(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=q(e,"textScaleX",1)||1,l=q(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(qe(e))return this.emitArcText(e);if(e.vertical===!0)return this.emitVerticalText(e);let t=Uv(e);if(t)return this.emitWarpedText(e,t);if(Po(e)){let f=this.options.bakeTextBitmap?.(e,"psd")??null;if(f)return this.emitBakedTextImage(e,f);this.skip("text-psdwarp-bitmap-fallback")}let r=q(e,"width",NaN),o=q(e,"height",NaN);if(!Number.isFinite(r)||!Number.isFinite(o)){if(Number.isFinite(r)&&!Number.isFinite(o)){let f=this.engineLayoutOf(e,!1);if(f)return this.emitTextFromEngineLayout(e,f)}return this.skip("text-dims-missing"),null}if(typeof e.direction=="string"&&e.direction!=="ltr")return this.skip("text-vertical-or-rtl"),null;if($c(e)){let f=this.options.bakeTextBitmap?.(e,"plain")??null;if(f)return this.emitBakedTextImage(e,f)}if(Array.isArray(e.effects)&&e.effects.length>0)return this.skip("text-effects"),null;if($v(e)){let f=this.engineLayoutOf(e,!1);if(f)return this.emitTextFromEngineLayout(e,f)}let i=Pp(e);if(!i){let f=Ie(e,"text");if(!f||!Array.from(f).some(p=>p!==`
1060
- `))return'<text xml:space="preserve"></text>';let m=this.engineLayoutOf(e,!1);return m?this.emitTextFromEngineLayout(e,m):(this.skip("text-layout-missing"),null)}let s=tn(e);if(s===void 0)return this.skip("shadow-unsupported"),null;let a=q(e,"textScaleX",1)||1,l=q(e,"textScaleY",1)||1,c=Math.abs(a-1)>1e-9||Math.abs(l-1)>1e-9,u=kp(e,i,r,o),h=this.emitAnchorGlyphs(u,r,o);if(h===null)return null;let d=h;return s&&(d=`<g filter="url(#${this.emitShadowFilter(s)})">${d}</g>`),c&&(d=`<g transform="scale(${N(a)},${N(l)})">${d}</g>`),d}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,g=h!==void 0?h*180/Math.PI:0;if(this.options.textMode==="paths"){if(l.trim()){let b=this.options.fonts?.getFont(m.fontFamily)??this.options.fonts?.getSubsetFont?.(m.fontFamily,l)??null;if(!b)return this.skip(`text-font-missing:${m.fontFamily}`),null;let x=this.resolvePaint(m.fill,t,r);if(x===void 0)return this.skip("text-fill-unsupported"),null;let y=x!==null?` fill="${ne(x)}"`:' 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 S=d?-((b.getAdvanceWidth?.(l,m.fontSize)??0)/2):0,v=qc(b.getPath(l,S,0,m.fontSize).commands),M=`translate(${N(c)},${N(u)})`;h!==void 0&&(M+=` rotate(${N(g)})`),f!==void 0&&(M+=` scale(1,${N(f)})`),o.push(`<g transform="${M}"><path d="${v}"${y}/></g>`)}else{let S=qc(b.getPath(l,c,u,m.fontSize).commands);o.push(`<path d="${S}"${y}/>`)}}}else{let b=this.resolvePaint(m.fill,t,r);if(b===void 0)return this.skip("text-fill-unsupported"),null;if(p){let x=` transform="translate(${N(c)},${N(u)})${h!==void 0?` rotate(${N(g)})`:""}${f!==void 0?` scale(1,${N(f)})`:""}"`;d&&(x+=' text-anchor="middle"'),x+=` font-family="${ne(m.fontFamily)}"`,x+=` font-size="${N(m.fontSize)}"`,m.fontWeight!=="normal"&&(x+=` font-weight="${ne(m.fontWeight)}"`),m.fontStyle!=="normal"&&(x+=` font-style="${ne(m.fontStyle)}"`),x+=b!==null?` fill="${ne(b)}"`:' fill="none"',typeof m.stroke=="string"&&!In(m.stroke)&&m.strokeWidth>0&&(x+=` stroke="${ne(m.stroke)}" stroke-width="${N(m.strokeWidth)}"`),s.push(`<text xml:space="preserve"${x}>${ne(l)}</text>`)}else{let x=` x="${N(c)}" y="${N(u)}"`;x+=` font-family="${ne(m.fontFamily)}"`,x+=` font-size="${N(m.fontSize)}"`,m.fontWeight!=="normal"&&(x+=` font-weight="${ne(m.fontWeight)}"`),m.fontStyle!=="normal"&&(x+=` font-style="${ne(m.fontStyle)}"`),x+=b!==null?` fill="${ne(b)}"`:' fill="none"',typeof m.stroke=="string"&&!In(m.stroke)&&m.strokeWidth>0&&(x+=` 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&&(x+=` text-decoration="${y.join(" ")}"`),i.push(`<tspan${x}>${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($c(e)){let a=this.options.bakeTextBitmap?.(e,qe(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:_o(o,t.layout.lines[a.line]?.charStyles?.[a.index],e)});let s=this.emitAnchorGlyphs(i,q(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($c(e)){let g=this.options.bakeTextBitmap?.(e,"vertical")??null;if(g)return this.emitBakedTextImage(e,g)}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,q(e,"height",0)),l=[],c=0;for(let g of t.lines){let b=-t.width/2+g.leftOffset,x=-a/2+g.baseline,y=0;for(let S=0;S<g.graphemes.length;S++){let v=g.graphemes[S],M=g.charStyles[S],C=M?.fontSize??o.fontSize,R=Tt(s,C,c+S),w=g.boxes[S],T=Yn(v);if(T==="latin"||T==="bracket"){let E=b+y+(T==="latin"?w.kernedWidth-w.width:0);l.push({char:v,x:E,y:x+R,style:_o(o,M,e)})}else{let E=b+y+an(C),P=x+R+dr(T,w,C);l.push({char:v,x:E,y:P,rotation:-Math.PI/2,style:_o(o,M,e)})}y+=Un(v,w,i)}c+=g.graphemes.length}let u=this.emitAnchorGlyphs(l,t.width,a);if(u===null)return null;let h=this.emitTextDecorations(e,t,a),d=q(e,"textScaleX",1)||1,f=q(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=q(e,"fontSize",40)||40,a=Math.max(-1,Math.min(1,q(e,"warpStrength",0)||0)),l=q(e,"width",0),c=q(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),g=[];for(let v of o.lines){let M=-o.width/2+v.leftOffset,C=-u/2+v.baseline;for(let R=0;R<v.graphemes.length;R++){let w=v.boxes[R],T=_o(p,v.charStyles[R],e),E=M+w.left,P=E+w.width/2,A=f>0?P/f:0;if(t==="flag"){let k=Math.sin(A*Math.PI)*d*a;g.push({char:v.graphemes[R],x:E,y:C+k,style:T})}else if(t==="arch"){let k=Math.max(-1,Math.min(1,A)),O=Math.sqrt(Math.max(0,1-k*k)),F=O*O*(3-2*O),W=a>0?Math.pow(F,2.5):F,X=Math.min(1+Math.max(0,a),Math.max(.05,1+a*W));g.push({char:v.graphemes[R],x:E,y:X*C+m*(1-X),scaleY:X,style:T})}else{let k=Math.min(1+Math.abs(a),Math.max(.4,1+a*(A*A-.5)));g.push({char:v.graphemes[R],x:E,y:k*C,scaleY:k,style:T})}}}let b=this.emitAnchorGlyphs(g,h,u);if(b===null)return null;let x=q(e,"textScaleX",1)||1,y=q(e,"textScaleY",1)||1,S=b;return i&&(S=`<g filter="url(#${this.emitShadowFilter(i)})">${S}</g>`),(Math.abs(x-1)>1e-9||Math.abs(y-1)>1e-9)&&(S=`<g transform="scale(${N(x)},${N(y)})">${S}</g>`),S}emitMask(e){let t=Ie(e,"src");if(!t)return this.skip("image-src-missing"),null;let r=q(e,"width",0),o=q(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 M=tn(e);if(M===void 0)return this.skip("shadow-unsupported"),null;let C=`<image href="${ne(t)}" xlink:href="${ne(t)}" x="${N(-r/2)}" y="${N(-o/2)}" width="${N(r)}" height="${N(o)}"/>`;return M&&(C=`<g filter="url(#${this.emitShadowFilter(M)})">${C}</g>`),C}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(q(e,"cornerRadius",0),Math.min(r,o)/2));if(f>0){let M=this.nextId("esvg-mc");this.defs.push(`<clipPath id="${M}"><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(#${M})"`}d+=">";let m=q(s,"angle",0),p=q(s,"scaleX",1)||1,g=q(s,"scaleY",1)||1,b=s.flipX===!0?-1:1,x=s.flipY===!0?-1:1,y=q(e,"clipX",0),S=q(e,"clipY",0),v=`translate(${N(r/2)},${N(o/2)}) rotate(${N(m)}) scale(${N(p*b)},${N(g*x)}) translate(${N(y/(p||1))},${N(S/(g||1))}) translate(${N(-c/2)},${N(-u/2)})`;return d+`<g transform="${v}"><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("")}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 g=u(p);g!==f?(m(),h=p,d=a.boxes[p].width,f=g):d+=a.boxes[p].kernedWidth}m()}if(Array.isArray(e.texts)&&e.texts.length>0&&e.vertical!==!0){let a=Lo(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,q(e,"height",0)),s=[];for(let f of t.lines){let m=-t.width/2+f.leftOffset,p=-i/2+f.baseline;for(let g=0;g<f.graphemes.length;g++)s.push({char:f.graphemes[g],x:m+f.boxes[g].left,y:p,style:_o(o,f.charStyles[g],e)})}let a=this.emitAnchorGlyphs(s,t.width,i);if(a===null)return null;let l=q(e,"textScaleX",1)||1,c=q(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>`),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?Ep(this.options.fonts):null)),!this.layoutMeasure)return null;let r;try{r=so(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?Ep(this.options.fonts):null)),!this.layoutMeasure)return null;if(!this.options.measure){let o=Ln(e).fontFamily;if(!this.options.fonts?.getFont(o))return null}let r=e.text??"";return $n(r,Ln(e),{measure:this.layoutMeasure,boxWidth:J(e)===L.TEXTBOX?e.width??0:null,styles:nS(r,e.styles),splitByGrapheme:e.splitByGrapheme===!0,vertical:t,paragraph:qe(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:Mt(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"&&!Uc.has(r))return this.skip("image-gco"),null;let o=xi(yp(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,g=-d/2-o.sx*m,b=-f/2-o.sy*p,x=this.nextId("esvg-ic"),y=q(e,"rx",0),S=q(e,"ry",0),v=y>0||S>0?` rx="${N(y)}" ry="${N(S)}"`:"";return this.defs.push(`<clipPath id="${x}"><rect x="${N(-d/2)}" y="${N(-f/2)}" width="${N(d)}" height="${N(f)}"${v}/></clipPath>`),`<g clip-path="url(#${x})"><image xlink:href="${ne(t)}" x="${N(g)}" y="${N(b)}" width="${N(h.width*m)}" height="${N(h.height*p)}"/></g>`}let i=q(e,"width",NaN),s=q(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=q(e,"rx",0),u=q(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=J(e);if(Yv.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(xp.has(i))return this.emitTable(e);if(nt.has(i))return this.emitMask(e);if(gp.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:q(e,"width",NaN),m=typeof d?.h=="number"&&d.h>0?d.h:q(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),g=-m/2+(typeof d?.y=="number"?d.y:0),b=ao(e),x=`<image xlink:href="${ne(Ie(e,"renderSrc")??"")}" x="${N(p)}" y="${N(g)}" width="${N(f)}" height="${N(m)}"${b<1?` opacity="${N(b)}"`:""}/>`,y=typeof d?.angle=="number"&&Number.isFinite(d.angle)?d.angle:0;return y&&(x=`<g transform="rotate(${N(-y)})">${x}</g>`),x}if(rn.has(i))return this.emitText(e);let s=Ie(e,"globalCompositeOperation");if(s&&s!=="source-over"&&!Uc.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(bp.has(i)||zv.has(i))return this.emitLineDecoration(e,bp.has(i));let a=wp(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(Jv(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=Zv(e,l,c)+(u?` filter="url(#${this.emitShadowFilter(u)})"`:"");return Tp(a,null,h)}emitLineDecoration(e,t){let r=q(e,"x1",NaN),o=q(e,"y1",NaN),i=q(e,"x2",NaN),s=q(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=q(e,"strokeWidth",1),u=e.strokeDashArray,h=Array.isArray(u)&&u.length>0?` stroke-dasharray="${u.map(H=>typeof H=="number"&&Number.isFinite(H)?N(H):null).filter(H=>H!==null).join(",")}"`:"",d=i-r,f=s-o,m=Math.atan2(f,d),p=Math.cos(m),g=Math.sin(m);if(t){let H=e.arrowType==="start"||e.arrowType==="both"?e.arrowType:"end",z=H==="start"||H==="both",U=H==="end"||H==="both",$=Math.sqrt(c),K=q(e,"arrowWidth",15)*$,G=q(e,"arrowHeight",22.5)*$,Z=r+p*(z?G:0),B=o+g*(z?G:0),j=i-p*(U?G:0),Q=s-g*(U?G:0),ie=` stroke="${ne(l)}" stroke-width="${N(c)}"${h}`,ce=[`<line x1="${N(Z)}" y1="${N(B)}" x2="${N(j)}" y2="${N(Q)}"${ie} fill="none"/>`],me=(Re,De,et)=>{let Pe=Math.cos(et),Ee=Math.sin(et),ue=Re-G*Pe+K/2*Ee,ye=De-G*Ee-K/2*Pe,fe=Re-G*Pe-K/2*Ee,we=De-G*Ee+K/2*Pe;ce.push(`<path d="M ${N(Re)} ${N(De)} L ${N(ue)} ${N(ye)} L ${N(fe)} ${N(we)} Z" fill="${ne(l)}"/>`)};return U&&me(i,s,m),z&&me(r,o,m+Math.PI),ce.join("")}let b=` stroke="${ne(l)}" stroke-width="${N(c)}"${h}`,x=Ie(e,"strokeLineCap");x&&(b+=` stroke-linecap="${ne(x)}"`);let y=Ie(e,"strokeLineJoin");y&&(b+=` stroke-linejoin="${ne(y)}"`);let S=e.strokeMiterLimit;typeof S=="number"&&Number.isFinite(S)&&(b+=` stroke-miterlimit="${N(S)}"`);let v=[`<line x1="${N(r)}" y1="${N(o)}" x2="${N(i)}" y2="${N(s)}"${b} fill="none"/>`],M=(q(e,"textFontSize",50)||50)/2,C=-g,R=p,w=` stroke="${ne(l)}" stroke-width="${N(c)}" stroke-linecap="round"`;for(let[H,z]of[[r,o],[i,s]])v.push(`<line x1="${N(H-C*M)}" y1="${N(z-R*M)}" x2="${N(H+C*M)}" y2="${N(z+R*M)}"${w} fill="none"/>`);let T=q(e,"textFontSize",50)||50,E=typeof e.text=="string"&&e.text.trim()?e.text:"50cm",P=q(e,"textPadding",4),A=eS(E,T)+P*2,k=T+P*2,O=T+c/2+5,F=(r+i)/2+C*O,W=(o+s)/2+R*O,X=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 v.push(`<g transform="translate(${N(F)},${N(W)}) rotate(${N(X)})">`+(D&&I?`<rect x="${N(-A/2)}" y="${N(-k/2)}" width="${N(A)}" height="${N(k)}" fill="${ne(I)}"/>`:"")+`<text text-anchor="middle" dominant-baseline="central" font-family="Arial, sans-serif" font-size="${N(T)}" fill="${ne(_)}">${ne(E)}</text></g>`),v.join("")}emitNode(e){if(Dt.has(Ie(e,"id")??"")||e.excludeFromExport===!0||e.visible===!1)return"";let t=J(e),r=q(e,"width",NaN),o=q(e,"height",NaN);if(gp.has(t)){let h=xi(yp(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(mt.has(t)&&(!Number.isFinite(r)||!Number.isFinite(o)))r=Math.abs(q(e,"x2",0)-q(e,"x1",0)),o=Math.abs(q(e,"y2",0)-q(e,"y1",0));else if(Cp.has(t)&&(!Number.isFinite(r)||!Number.isFinite(o)))if(t===L.CIRCLE){let h=2*q(e,"radius",NaN);Number.isFinite(r)||(r=h),Number.isFinite(o)||(o=h)}else Number.isFinite(r)||(r=2*q(e,"rx",NaN)),Number.isFinite(o)||(o=2*q(e,"ry",NaN));else if((Vc.has(t)||Rp.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 g of h){let b=typeof g?.x=="number"&&Number.isFinite(g.x)?g.x:NaN,x=typeof g?.y=="number"&&Number.isFinite(g.y)?g.y:NaN;!Number.isFinite(b)||!Number.isFinite(x)||(d>b&&(d=b),f>x&&(f=x),m<b&&(m=b),p<x&&(p=x))}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(qe(e)){let h=this.arcLayoutOf(e);h&&(r=h.arc.width,o=h.arc.height)}if(xp.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=vp(e,r,o),s=this.emitObjectContent(e,i,r,o);if(s===null)return null;if(s==="")return"";let a=`<g transform="${jc(i)}"`,l=Ie(e,"globalCompositeOperation");l&&l!=="source-over"&&Uc.has(l)&&(a+=` style="mix-blend-mode:${ne(l)}"`);let c=q(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>`)}},iS=n=>new Sa({textMode:n.textMode,fonts:n.fonts,naturalSizes:n.naturalSizes,measure:n.measure,bakeTextBitmap:n.bakeTextBitmap}).exportPage(n);var Ap=n=>n==="center"?0:n==="right"?.5:-.5,Kc=n=>typeof n=="number"?n:0,sS=(n,e={})=>{let t=1/0,r=1/0,o=-1/0,i=-1/0,s=[];for(let p of n){let g=ct(p);if(!g)continue;s.push(g);let b=Kc(g.raw.strokeWidth),x=g.ownMatrix,y=g.dims.x/2,S=g.dims.y/2,v=g.raw.strokeUniform===!0?y:y+b/2,M=g.raw.strokeUniform===!0?S:S+b/2,C=g.raw.strokeUniform===!0?b/2:0,R=g.raw.strokeUniform===!0?b/2:0;for(let w of[-v,v])for(let T of[-M,M]){let E=V(x,w,T),P=E.x,A=E.y;P-C<t&&(t=P-C),A-R<r&&(r=A-R),P+C>o&&(o=P+C),A+R>i&&(i=A+R)}}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:Kc(p.left)-u,top:Kc(p.top)-h})),f=typeof e.left=="number"?e.left:u+l*Ap(e.originX),m=typeof e.top=="number"?e.top:h+c*Ap(e.originY);return{...e,type:e.type??"Group",width:l,height:c,left:f,top:m,objects:d}};var ar=n=>n==="center"?0:n==="right"?.5:-.5,aS=(n,e={})=>{let t=Ae(n),r=t?je(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)*ar(e.originX),c=typeof e.top=="number"?e.top:s.y+(i+a)*ar(e.originY);return{...e,type:e.type??"Path",path:t??[],width:o,height:i,pathOffset:s,left:l,top:c}};var lS=(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)*ar(e.originX),d=typeof e.top=="number"?e.top:c+(a+u)*ar(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}},cS=(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)*ar(e.originX),f=typeof e.top=="number"?e.top:u.y+(c+h)*ar(e.originY);return{...e,type:e.type??t,points:n,width:l,height:c,pathOffset:u,left:d,top:f}};export{re as AnimatedNode,Lg as COMPAT_PROTOCOL_VERSION,Le as CompatHistoryActions,sr as CompatObject,kn as CompatPoint,L as ElementTypes,Ic as EngineCanvas,rr as EngineDocument,Fn as EventBus,Vo as GIF_TYPES,ee as GroupNode,ft as IMAGE_LIKE_TYPES,mt as LINE_TYPES,vr as LineNode,nt as MASK_TYPES,le as MaskNode,fm as PAGE_GAP_CSS_PX,$o as PUZZLE_TYPES,yr as PathNode,_c as Point,se as PuzzleNode,Hn as SHAPE_TYPES,Wn as SOLID_TYPES,Ki as ScaleLimit,ut as SceneNode,un as ShapeNode,Sa as SvgExporter,xb as TEXT_ALIGN_VALUES,rn as TEXT_TYPES,te as TableNode,pe as TextAlignValues,xe as TextNode,jo as VIDEO_TYPES,Po as activePsdTextWarp,ql as anchorStyleAt,vm as applyWarpDistortion,qe as arcTextKind,sS as assembleGroupRaw,Ig as attachDocumentEventBridge,Gv as attachPathBackgroundController,Gc as attachTableFacade,uc as bakeArcText,kc as bakePsdWarpText,xy as bakeTextEffects,cc as bakeWarpedText,ka as boundsFromACoors,io as buildAllSelection,Dc as buildEngineShapePath,lS as buildLineRaw,aS as buildPathRaw,cS as buildPolyRaw,ul as buildScene,cn as buildSelectionRange,oS as buildTextGlyphPathData,vc as buildWarpSurfaceGridOverWindow,r0 as clearAlphaHitMask,At as composeMatrix,Eo as compositeWarpEffects,Mt as computeArcTextLayout,ja as computePuzzleItems,Dv as createEngineWarpvasFacade,ct as createNode,Xp as decomposeOwnMatrix,Xc as deriveArcCharTransformations,va as ensurePathBackgroundNode,Us as evaluateWarpMesh,fa as fboPixelsToImageData,Yc as findParentGroupOf,yc as generatePsdWarpMesh,ym as generateStyleWarpMesh,je as getBoundsOfPath,Se as getCellData,yn as glyphStyleAt,Tn as glyphStyleOf,Pn as identityWarpMesh,Mc as imageMaskDeclOf,Bm as imageMaskOffset,no as insertTableColumn,to as insertTableRow,Te as invert,Sc as invertBilinearCell,Q0 as isAnimatedWebPFile,Z0 as isAnimatedWebPUrl,eu as isCanvasPerfEnabled,zp as isEngineRasterExportEnabled,Yp as isEngineSvgExportEnabled,xc as isGeneratableWarpStyle,Er as isGroupWidthHandleNode,Ut as isJustifyFamilyAlign,Xa as isJustifyVariantAlign,La as isSnapGuideEnabled,Yr as isStretchAlign,$t as isTextBitmapState,$n as layoutTextbox,Va as lineDecorationRuns,Qe as loadImageElement,tu as markCanvasPerfCounter,Hm as maskOutsideRects,Om as maskPixelsToAlpha,lt as masterPosition,Jr as mergeTableCells,Y as multiply,hi as normalizeSelectionAfterRemove,Pa as objectACoors,Yt as objectCenter,ge as objectOriginFromCenter,On as objectOwnMatrix,ae as parseColor,Ae as parsePathData,Jt as parsePsdEffects,ya as pathBackgroundSpecOf,Ot as pathEditKindOf,Lo as planTextHighlight,Bo as recordCanvasPerfDuration,rt as rectCornerRadii,tl as removeTableColumn,el as removeTableRow,Rv as renderPlacedSmartObjectLayer,To as renderTextRuns,Ts as renderVerticalRuns,Hv as repositionPathBackgroundNode,xr as rowColCoverage,Nt as sceneToClipMatrix,We as selectionBounds,iS as serializePageToSvg,Xg as setGroupWidth,Qr as setTableColumnWidth,Zr as setTableRowHeight,Bv as syncAfterPropWrite,Nn as syncPathBackgroundNode,Ov as synthesizePathBackgroundNodes,ao as textBitmapFillAlpha,V as transformPoint,Wo as transformedDimensions,J as typeKeyOf,eo as unmergeTableCells,qt as verticalGlyphOps,_v as wrapCompatObject};
1059
+ `)continue;let c=r(l);c&&((o[c[0]]??={})[c[1]]=i.style)}}return Object.keys(o).length>0?o:void 0},bS=(n,e,t,r)=>{let o=n??pe.LEFT;return Ut(o)?r?o===pe.JUSTIFY_CENTER?(e-t)/2:o===pe.JUSTIFY_RIGHT?e-t:0:0:o===pe.CENTER?(e-t)/2:o===pe.RIGHT?e-t:0},Jc=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("")},Wp=(n,e,t,r,o={})=>{let i=-1;for(let d=0;d<e.textLines.length;d++)e.textLines[d].length>0&&(i=d);let s=q(n,"lineHeight",1.16)||1.16,a=Ie(n,"textAlign"),l=-t/2,c=-r/2,u=[],h=0;for(let d=0;d<e.textLines.length;d++){let f=e.textLines[d],m=e.charBounds[d],p=e.lineHeights[d],g=p/s,b=c+h+g-p*aS/s,x=0;for(let R of m)!R||typeof R.left!="number"||typeof R.kernedWidth!="number"||(x=Math.max(x,R.left+R.kernedWidth));let y=bS(a,t,x,d>=i),S=o.lineLefts?.[d]??l+y,v=o.anchor==="boxLeft",T=S,C=0;for(let R=0;R<=f.length-1;R++){let w=f[R],E=m[R];if(!(!E||typeof E.width!="number"||typeof E.kernedWidth!="number")){if(v){u.push({char:w,x:S+(E.left||0),y:b,style:Fp(n,d,R,e)});continue}C===0?(T+=E.kernedWidth-E.width,C=E.width):C+=E.width,u.push({char:w,x:T,y:b,style:Fp(n,d,R,e)}),T+=C,C=0}}h+=p}return u},gS=(n,e,t={})=>{if(!e)return null;let r=n,o=q(r,"width",NaN),i=q(r,"height",NaN);if(!Number.isFinite(o)||!Number.isFinite(i)||r.vertical===!0||typeof r.direction=="string"&&r.direction!=="ltr")return null;let s=Hp(r);if(!s)return null;let a=[];for(let{char:l,x:c,y:u,style:h}of Wp(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=Jc(d.getPath(l,c,u,h.fontSize).commands);a.push(f.endsWith("Z")?f:`${f} Z`)}return a.length>0?{path:a.join(" ")}:null},Sa=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)?rn(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="${ne(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=Yo(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[c,u,h,d]=l.color,f=`rgb(${Math.round(c*255)},${Math.round(u*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 rn(e)??void 0;if(!e||typeof e!="object"||Array.isArray(e))return;let o=hr(e);if(o)return this.emitGradientDef(o,t,r);let i=Uo(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=$o(e,t,r);return this.defs.push(`<pattern id="${i}" patternUnits="userSpaceOnUse" width="${N(o.width)}" height="${N(o.height)}" patternTransform="${Zc(s)}"><image href="${ne(e.src)}" xlink:href="${ne(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="${ne(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"||!sS.has(o.type)||o.inverted===!0)return null;let i=q(o,"width",0),s=q(o,"height",0),a=Ip(o,i,s);if(!a)return null;let l=Np(o,i,s),c=o.absolutePositioned===!0?Y(Te(t),l):l,u=this.nextId("esvg-c");return this.defs.push(`<clipPath id="${u}">${_p(a,c,"")}</clipPath>`),` clip-path="url(#${u})"`}emitBakedTextImage(e,t){let r=nn(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="${ne(t.dataUrl)}" xlink:href="${ne(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=q(e,"textScaleX",1)||1,l=q(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(Ke(e))return this.emitArcText(e);if(e.vertical===!0)return this.emitVerticalText(e);let t=oS(e);if(t)return this.emitWarpedText(e,t);if(Po(e)){let f=this.options.bakeTextBitmap?.(e,"psd")??null;if(f)return this.emitBakedTextImage(e,f);this.skip("text-psdwarp-bitmap-fallback")}let r=q(e,"width",NaN),o=q(e,"height",NaN);if(!Number.isFinite(r)||!Number.isFinite(o)){if(Number.isFinite(r)&&!Number.isFinite(o)){let f=this.engineLayoutOf(e,!1);if(f)return this.emitTextFromEngineLayout(e,f)}return this.skip("text-dims-missing"),null}if(typeof e.direction=="string"&&e.direction!=="ltr")return this.skip("text-vertical-or-rtl"),null;if(Kc(e)){let f=this.options.bakeTextBitmap?.(e,"plain")??null;if(f)return this.emitBakedTextImage(e,f)}if(Array.isArray(e.effects)&&e.effects.length>0)return this.skip("text-effects"),null;if(iS(e)){let f=this.engineLayoutOf(e,!1);if(f)return this.emitTextFromEngineLayout(e,f)}let i=Hp(e);if(!i){let f=Ie(e,"text");if(!f||!Array.from(f).some(p=>p!==`
1060
+ `))return'<text xml:space="preserve"></text>';let m=this.engineLayoutOf(e,!1);return m?this.emitTextFromEngineLayout(e,m):(this.skip("text-layout-missing"),null)}let s=nn(e);if(s===void 0)return this.skip("shadow-unsupported"),null;let a=q(e,"textScaleX",1)||1,l=q(e,"textScaleY",1)||1,c=Math.abs(a-1)>1e-9||Math.abs(l-1)>1e-9,u=Wp(e,i,r,o),h=this.emitAnchorGlyphs(u,r,o);if(h===null)return null;let d=h;return s&&(d=`<g filter="url(#${this.emitShadowFilter(s)})">${d}</g>`),c&&(d=`<g transform="scale(${N(a)},${N(l)})">${d}</g>`),d}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,g=h!==void 0?h*180/Math.PI:0;if(this.options.textMode==="paths"){if(l.trim()){let b=this.options.fonts?.getFont(m.fontFamily)??this.options.fonts?.getSubsetFont?.(m.fontFamily,l)??null;if(!b)return this.skip(`text-font-missing:${m.fontFamily}`),null;let x=this.resolvePaint(m.fill,t,r);if(x===void 0)return this.skip("text-fill-unsupported"),null;let y=x!==null?` fill="${ne(x)}"`:' fill="none"';if(typeof m.stroke=="string"&&!_n(m.stroke)&&m.strokeWidth>0&&(y+=` stroke="${ne(m.stroke)}" stroke-width="${N(m.strokeWidth)}"`),p){let S=d?-((b.getAdvanceWidth?.(l,m.fontSize)??0)/2):0,v=Jc(b.getPath(l,S,0,m.fontSize).commands),T=`translate(${N(c)},${N(u)})`;h!==void 0&&(T+=` rotate(${N(g)})`),f!==void 0&&(T+=` scale(1,${N(f)})`),o.push(`<g transform="${T}"><path d="${v}"${y}/></g>`)}else{let S=Jc(b.getPath(l,c,u,m.fontSize).commands);o.push(`<path d="${S}"${y}/>`)}}}else{let b=this.resolvePaint(m.fill,t,r);if(b===void 0)return this.skip("text-fill-unsupported"),null;if(p){let x=` transform="translate(${N(c)},${N(u)})${h!==void 0?` rotate(${N(g)})`:""}${f!==void 0?` scale(1,${N(f)})`:""}"`;d&&(x+=' text-anchor="middle"'),x+=` font-family="${ne(m.fontFamily)}"`,x+=` font-size="${N(m.fontSize)}"`,m.fontWeight!=="normal"&&(x+=` font-weight="${ne(m.fontWeight)}"`),m.fontStyle!=="normal"&&(x+=` font-style="${ne(m.fontStyle)}"`),x+=b!==null?` fill="${ne(b)}"`:' fill="none"',typeof m.stroke=="string"&&!_n(m.stroke)&&m.strokeWidth>0&&(x+=` stroke="${ne(m.stroke)}" stroke-width="${N(m.strokeWidth)}"`),s.push(`<text xml:space="preserve"${x}>${ne(l)}</text>`)}else{let x=` x="${N(c)}" y="${N(u)}"`;x+=` font-family="${ne(m.fontFamily)}"`,x+=` font-size="${N(m.fontSize)}"`,m.fontWeight!=="normal"&&(x+=` font-weight="${ne(m.fontWeight)}"`),m.fontStyle!=="normal"&&(x+=` font-style="${ne(m.fontStyle)}"`),x+=b!==null?` fill="${ne(b)}"`:' fill="none"',typeof m.stroke=="string"&&!_n(m.stroke)&&m.strokeWidth>0&&(x+=` 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&&(x+=` text-decoration="${y.join(" ")}"`),i.push(`<tspan${x}>${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(Kc(e)){let a=this.options.bakeTextBitmap?.(e,Ke(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=nn(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:Do(o,t.layout.lines[a.line]?.charStyles?.[a.index],e)});let s=this.emitAnchorGlyphs(i,q(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(Kc(e)){let g=this.options.bakeTextBitmap?.(e,"vertical")??null;if(g)return this.emitBakedTextImage(e,g)}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=nn(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,q(e,"height",0)),l=[],c=0;for(let g of t.lines){let b=-t.width/2+g.leftOffset,x=-a/2+g.baseline,y=0;for(let S=0;S<g.graphemes.length;S++){let v=g.graphemes[S],T=g.charStyles[S],C=T?.fontSize??o.fontSize,R=Tt(s,C,c+S),w=g.boxes[S],E=Un(v);if(E==="latin"||E==="bracket"){let M=b+y+(E==="latin"?w.kernedWidth-w.width:0);l.push({char:v,x:M,y:x+R,style:Do(o,T,e)})}else{let M=b+y+ln(C),P=x+R+fr(E,w,C);l.push({char:v,x:M,y:P,rotation:-Math.PI/2,style:Do(o,T,e)})}y+=$n(v,w,i)}c+=g.graphemes.length}let u=this.emitAnchorGlyphs(l,t.width,a);if(u===null)return null;let h=this.emitTextDecorations(e,t,a),d=q(e,"textScaleX",1)||1,f=q(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=nn(e);if(i===void 0)return this.skip("shadow-unsupported"),null;let s=q(e,"fontSize",40)||40,a=Math.max(-1,Math.min(1,q(e,"warpStrength",0)||0)),l=q(e,"width",0),c=q(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=In(e),g=[];for(let v of o.lines){let T=-o.width/2+v.leftOffset,C=-u/2+v.baseline;for(let R=0;R<v.graphemes.length;R++){let w=v.boxes[R],E=Do(p,v.charStyles[R],e),M=T+w.left,P=M+w.width/2,A=f>0?P/f:0;if(t==="flag"){let k=Math.sin(A*Math.PI)*d*a;g.push({char:v.graphemes[R],x:M,y:C+k,style:E})}else if(t==="arch"){let k=Math.max(-1,Math.min(1,A)),O=Math.sqrt(Math.max(0,1-k*k)),F=O*O*(3-2*O),W=a>0?Math.pow(F,2.5):F,X=Math.min(1+Math.max(0,a),Math.max(.05,1+a*W));g.push({char:v.graphemes[R],x:M,y:X*C+m*(1-X),scaleY:X,style:E})}else{let k=Math.min(1+Math.abs(a),Math.max(.4,1+a*(A*A-.5)));g.push({char:v.graphemes[R],x:M,y:k*C,scaleY:k,style:E})}}}let b=this.emitAnchorGlyphs(g,h,u);if(b===null)return null;let x=q(e,"textScaleX",1)||1,y=q(e,"textScaleY",1)||1,S=b;return i&&(S=`<g filter="url(#${this.emitShadowFilter(i)})">${S}</g>`),(Math.abs(x-1)>1e-9||Math.abs(y-1)>1e-9)&&(S=`<g transform="scale(${N(x)},${N(y)})">${S}</g>`),S}emitMask(e){let t=Ie(e,"src");if(!t)return this.skip("image-src-missing"),null;let r=q(e,"width",0),o=q(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 T=nn(e);if(T===void 0)return this.skip("shadow-unsupported"),null;let C=`<image href="${ne(t)}" xlink:href="${ne(t)}" x="${N(-r/2)}" y="${N(-o/2)}" width="${N(r)}" height="${N(o)}"/>`;return T&&(C=`<g filter="url(#${this.emitShadowFilter(T)})">${C}</g>`),C}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(q(e,"cornerRadius",0),Math.min(r,o)/2));if(f>0){let T=this.nextId("esvg-mc");this.defs.push(`<clipPath id="${T}"><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(#${T})"`}d+=">";let m=q(s,"angle",0),p=q(s,"scaleX",1)||1,g=q(s,"scaleY",1)||1,b=s.flipX===!0?-1:1,x=s.flipY===!0?-1:1,y=q(e,"clipX",0),S=q(e,"clipY",0),v=`translate(${N(r/2)},${N(o/2)}) rotate(${N(m)}) scale(${N(p*b)},${N(g*x)}) translate(${N(y/(p||1))},${N(S/(g||1))}) translate(${N(-c/2)},${N(-u/2)})`;return d+`<g transform="${v}"><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("")}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=rn(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 g=u(p);g!==f?(m(),h=p,d=a.boxes[p].width,f=g):d+=a.boxes[p].kernedWidth}m()}if(Array.isArray(e.texts)&&e.texts.length>0&&e.vertical!==!0){let a=Io(e.text??"",t,e.texts,i,In(e).fontSize);if(a)for(let l of a.ops){let c=l.isFill?`<path d="${ne(l.d)}" fill="${ne(rn(l.fill)??l.fill)}"/>`:`<path d="${ne(l.d)}" fill="none" stroke="${ne(rn(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=nn(e);if(r===void 0)return this.skip("shadow-unsupported"),null;let o=In(e),i=Math.max(t.height,q(e,"height",0)),s=[];for(let f of t.lines){let m=-t.width/2+f.leftOffset,p=-i/2+f.baseline;for(let g=0;g<f.graphemes.length;g++)s.push({char:f.graphemes[g],x:m+f.boxes[g].left,y:p,style:Do(o,f.charStyles[g],e)})}let a=this.emitAnchorGlyphs(s,t.width,i);if(a===null)return null;let l=q(e,"textScaleX",1)||1,c=q(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>`),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?Dp(this.options.fonts):null)),!this.layoutMeasure)return null;let r;try{r=so(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?Dp(this.options.fonts):null)),!this.layoutMeasure)return null;if(!this.options.measure){let o=In(e).fontFamily;if(!this.options.fonts?.getFont(o))return null}let r=e.text??"";return Vn(r,In(e),{measure:this.layoutMeasure,boxWidth:ee(e)===L.TEXTBOX?e.width??0:null,styles:pS(r,e.styles),splitByGrapheme:e.splitByGrapheme===!0,vertical:t,paragraph:Ke(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:Mt(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"&&!qc.has(r))return this.skip("image-gco"),null;let o=yi(Ap(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,g=-d/2-o.sx*m,b=-f/2-o.sy*p,x=this.nextId("esvg-ic"),y=q(e,"rx",0),S=q(e,"ry",0),v=y>0||S>0?` rx="${N(y)}" ry="${N(S)}"`:"";return this.defs.push(`<clipPath id="${x}"><rect x="${N(-d/2)}" y="${N(-f/2)}" width="${N(d)}" height="${N(f)}"${v}/></clipPath>`),`<g clip-path="url(#${x})"><image xlink:href="${ne(t)}" x="${N(g)}" y="${N(b)}" width="${N(h.width*m)}" height="${N(h.height*p)}"/></g>`}let i=q(e,"width",NaN),s=q(e,"height",NaN);if(!Number.isFinite(i)||!Number.isFinite(s))return this.skip("image-dims-missing"),null;let a=nn(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=q(e,"rx",0),u=q(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=ee(e);if(rS.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(kp.has(i))return this.emitTable(e);if(rt.has(i))return this.emitMask(e);if(Pp.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:q(e,"width",NaN),m=typeof d?.h=="number"&&d.h>0?d.h:q(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),g=-m/2+(typeof d?.y=="number"?d.y:0),b=ao(e),x=`<image xlink:href="${ne(Ie(e,"renderSrc")??"")}" x="${N(p)}" y="${N(g)}" width="${N(f)}" height="${N(m)}"${b<1?` opacity="${N(b)}"`:""}/>`,y=typeof d?.angle=="number"&&Number.isFinite(d.angle)?d.angle:0;return y&&(x=`<g transform="rotate(${N(-y)})">${x}</g>`),x}if(on.has(i))return this.emitText(e);let s=Ie(e,"globalCompositeOperation");if(s&&s!=="source-over"&&!qc.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(Rp.has(i)||nS.has(i))return this.emitLineDecoration(e,Rp.has(i));let a=Ip(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(dS(e)){let d=this.resolvePaint(e.stroke,r,o);if(d===void 0)return this.skip("stroke-unsupported"),null;c=d}let u=nn(e);if(u===void 0)return this.skip("shadow-unsupported"),null;let h=hS(e,l,c)+(u?` filter="url(#${this.emitShadowFilter(u)})"`:"");return _p(a,null,h)}emitLineDecoration(e,t){let r=q(e,"x1",NaN),o=q(e,"y1",NaN),i=q(e,"x2",NaN),s=q(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(!rn(l))return this.skip("stroke-unsupported"),null;let c=q(e,"strokeWidth",1),u=e.strokeDashArray,h=Array.isArray(u)&&u.length>0?` stroke-dasharray="${u.map(H=>typeof H=="number"&&Number.isFinite(H)?N(H):null).filter(H=>H!==null).join(",")}"`:"",d=i-r,f=s-o,m=Math.atan2(f,d),p=Math.cos(m),g=Math.sin(m);if(t){let H=e.arrowType==="start"||e.arrowType==="both"?e.arrowType:"end",z=H==="start"||H==="both",U=H==="end"||H==="both",$=Math.sqrt(c),K=q(e,"arrowWidth",15)*$,G=q(e,"arrowHeight",22.5)*$,J=r+p*(z?G:0),B=o+g*(z?G:0),j=i-p*(U?G:0),Q=s-g*(U?G:0),ie=` stroke="${ne(l)}" stroke-width="${N(c)}"${h}`,ce=[`<line x1="${N(J)}" y1="${N(B)}" x2="${N(j)}" y2="${N(Q)}"${ie} fill="none"/>`],me=(Re,De,tt)=>{let Pe=Math.cos(tt),Ee=Math.sin(tt),ue=Re-G*Pe+K/2*Ee,ye=De-G*Ee-K/2*Pe,fe=Re-G*Pe-K/2*Ee,we=De-G*Ee+K/2*Pe;ce.push(`<path d="M ${N(Re)} ${N(De)} L ${N(ue)} ${N(ye)} L ${N(fe)} ${N(we)} Z" fill="${ne(l)}"/>`)};return U&&me(i,s,m),z&&me(r,o,m+Math.PI),ce.join("")}let b=` stroke="${ne(l)}" stroke-width="${N(c)}"${h}`,x=Ie(e,"strokeLineCap");x&&(b+=` stroke-linecap="${ne(x)}"`);let y=Ie(e,"strokeLineJoin");y&&(b+=` stroke-linejoin="${ne(y)}"`);let S=e.strokeMiterLimit;typeof S=="number"&&Number.isFinite(S)&&(b+=` stroke-miterlimit="${N(S)}"`);let v=[`<line x1="${N(r)}" y1="${N(o)}" x2="${N(i)}" y2="${N(s)}"${b} fill="none"/>`],T=(q(e,"textFontSize",50)||50)/2,C=-g,R=p,w=` stroke="${ne(l)}" stroke-width="${N(c)}" stroke-linecap="round"`;for(let[H,z]of[[r,o],[i,s]])v.push(`<line x1="${N(H-C*T)}" y1="${N(z-R*T)}" x2="${N(H+C*T)}" y2="${N(z+R*T)}"${w} fill="none"/>`);let E=q(e,"textFontSize",50)||50,M=typeof e.text=="string"&&e.text.trim()?e.text:"50cm",P=q(e,"textPadding",4),A=fS(M,E)+P*2,k=E+P*2,O=E+c/2+5,F=(r+i)/2+C*O,W=(o+s)/2+R*O,X=e.textFollowLine===!1?0:m*180/Math.PI,_=typeof e.textColor=="string"&&rn(e.textColor)?e.textColor:"#333333",D=typeof e.textBackgroundColor=="string"?e.textBackgroundColor:"#ffffff",I=rn(D);return v.push(`<g transform="translate(${N(F)},${N(W)}) rotate(${N(X)})">`+(D&&I?`<rect x="${N(-A/2)}" y="${N(-k/2)}" width="${N(A)}" height="${N(k)}" fill="${ne(I)}"/>`:"")+`<text text-anchor="middle" dominant-baseline="central" font-family="Arial, sans-serif" font-size="${N(E)}" fill="${ne(_)}">${ne(M)}</text></g>`),v.join("")}emitNode(e){if(Dt.has(Ie(e,"id")??"")||e.excludeFromExport===!0||e.visible===!1)return"";let t=ee(e),r=q(e,"width",NaN),o=q(e,"height",NaN);if(Pp.has(t)){let h=yi(Ap(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(mt.has(t)&&(!Number.isFinite(r)||!Number.isFinite(o)))r=Math.abs(q(e,"x2",0)-q(e,"x1",0)),o=Math.abs(q(e,"y2",0)-q(e,"y1",0));else if(Op.has(t)&&(!Number.isFinite(r)||!Number.isFinite(o)))if(t===L.CIRCLE){let h=2*q(e,"radius",NaN);Number.isFinite(r)||(r=h),Number.isFinite(o)||(o=h)}else Number.isFinite(r)||(r=2*q(e,"rx",NaN)),Number.isFinite(o)||(o=2*q(e,"ry",NaN));else if((Qc.has(t)||Bp.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 g of h){let b=typeof g?.x=="number"&&Number.isFinite(g.x)?g.x:NaN,x=typeof g?.y=="number"&&Number.isFinite(g.y)?g.y:NaN;!Number.isFinite(b)||!Number.isFinite(x)||(d>b&&(d=b),f>x&&(f=x),m<b&&(m=b),p<x&&(p=x))}Number.isFinite(d)&&Number.isFinite(f)&&(Number.isFinite(r)||(r=m-d),Number.isFinite(o)||(o=p-f))}}else if(on.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(Ke(e)){let h=this.arcLayoutOf(e);h&&(r=h.arc.width,o=h.arc.height)}if(kp.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=Np(e,r,o),s=this.emitObjectContent(e,i,r,o);if(s===null)return null;if(s==="")return"";let a=`<g transform="${Zc(i)}"`,l=Ie(e,"globalCompositeOperation");l&&l!=="source-over"&&qc.has(l)&&(a+=` style="mix-blend-mode:${ne(l)}"`);let c=q(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>`)}},xS=n=>new Sa({textMode:n.textMode,fonts:n.fonts,naturalSizes:n.naturalSizes,measure:n.measure,bakeTextBitmap:n.bakeTextBitmap}).exportPage(n);var Gp=n=>n==="center"?0:n==="right"?.5:-.5,eu=n=>typeof n=="number"?n:0,yS=(n,e={})=>{let t=1/0,r=1/0,o=-1/0,i=-1/0,s=[];for(let p of n){let g=ct(p);if(!g)continue;s.push(g);let b=eu(g.raw.strokeWidth),x=g.ownMatrix,y=g.dims.x/2,S=g.dims.y/2,v=g.raw.strokeUniform===!0?y:y+b/2,T=g.raw.strokeUniform===!0?S:S+b/2,C=g.raw.strokeUniform===!0?b/2:0,R=g.raw.strokeUniform===!0?b/2:0;for(let w of[-v,v])for(let E of[-T,T]){let M=V(x,w,E),P=M.x,A=M.y;P-C<t&&(t=P-C),A-R<r&&(r=A-R),P+C>o&&(o=P+C),A+R>i&&(i=A+R)}}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:eu(p.left)-u,top:eu(p.top)-h})),f=typeof e.left=="number"?e.left:u+l*Gp(e.originX),m=typeof e.top=="number"?e.top:h+c*Gp(e.originY);return{...e,type:e.type??"Group",width:l,height:c,left:f,top:m,objects:d}};var lr=n=>n==="center"?0:n==="right"?.5:-.5,vS=(n,e={})=>{let t=Ae(n),r=t?qe(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)*lr(e.originX),c=typeof e.top=="number"?e.top:s.y+(i+a)*lr(e.originY);return{...e,type:e.type??"Path",path:t??[],width:o,height:i,pathOffset:s,left:l,top:c}};var SS=(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)*lr(e.originX),d=typeof e.top=="number"?e.top:c+(a+u)*lr(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}},wS=(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)*lr(e.originX),f=typeof e.top=="number"?e.top:u.y+(c+h)*lr(e.originY);return{...e,type:e.type??t,points:n,width:l,height:c,pathOffset:u,left:d,top:f}};export{re as AnimatedNode,zg as COMPAT_PROTOCOL_VERSION,Le as CompatHistoryActions,ar as CompatObject,Nn as CompatPoint,L as ElementTypes,Oc as EngineCanvas,or as EngineDocument,On as EventBus,jo as GIF_TYPES,Z as GroupNode,ft as IMAGE_LIKE_TYPES,mt as LINE_TYPES,Sr as LineNode,rt as MASK_TYPES,le as MaskNode,gm as PAGE_GAP_CSS_PX,Vo as PUZZLE_TYPES,vr as PathNode,Bc as Point,se as PuzzleNode,Wn as SHAPE_TYPES,Gn as SOLID_TYPES,Qi as ScaleLimit,ut as SceneNode,hn as ShapeNode,Sa as SvgExporter,kb as TEXT_ALIGN_VALUES,on as TEXT_TYPES,te as TableNode,pe as TextAlignValues,ge as TextNode,qo as VIDEO_TYPES,Po as activePsdTextWarp,ql as anchorStyleAt,Em as applyWarpDistortion,Ke as arcTextKind,yS as assembleGroupRaw,Yg as attachDocumentEventBridge,Ac as attachPathBackgroundBelowHost,pv as attachPathBackgroundController,Uc as attachTableFacade,uc as bakeArcText,Ic as bakePsdWarpText,ky as bakeTextEffects,cc as bakeWarpedText,ka as boundsFromACoors,io as buildAllSelection,Hc as buildEngineShapePath,SS as buildLineRaw,vS as buildPathRaw,wS as buildPolyRaw,ul as buildScene,un as buildSelectionRange,gS as buildTextGlyphPathData,vc as buildWarpSurfaceGridOverWindow,m0 as clearAlphaHitMask,At as composeMatrix,Eo as compositeWarpEffects,Mt as computeArcTextLayout,ja as computePuzzleItems,eS as createEngineWarpvasFacade,ct as createNode,Jp as decomposeOwnMatrix,$c as deriveArcCharTransformations,kc as detachPathBackgroundOf,Lo as ensurePathBackgroundNode,$s as evaluateWarpMesh,ba as fboPixelsToImageData,jc as findParentGroupOf,yc as generatePsdWarpMesh,Tm as generateStyleWarpMesh,qe as getBoundsOfPath,Se as getCellData,vn as glyphStyleAt,En as glyphStyleOf,kn as identityWarpMesh,Cc as imageMaskDeclOf,zm as imageMaskOffset,no as insertTableColumn,to as insertTableRow,Te as invert,Sc as invertBilinearCell,uv as isAnimatedWebPFile,hv as isAnimatedWebPUrl,ou as isCanvasPerfEnabled,eb as isEngineRasterExportEnabled,tb as isEngineSvgExportEnabled,xc as isGeneratableWarpStyle,Mr as isGroupWidthHandleNode,Ut as isJustifyFamilyAlign,Xa as isJustifyVariantAlign,La as isSnapGuideEnabled,Yr as isStretchAlign,$t as isTextBitmapState,Vn as layoutTextbox,Va as lineDecorationRuns,Ze as loadImageElement,iu as markCanvasPerfCounter,Ym as maskOutsideRects,Xm as maskPixelsToAlpha,lt as masterPosition,Jr as mergeTableCells,Y as multiply,di as normalizeSelectionAfterRemove,Pa as objectACoors,Yt as objectCenter,xe as objectOriginFromCenter,Bn as objectOwnMatrix,ae as parseColor,Ae as parsePathData,Jt as parsePsdEffects,da as pathBackgroundSpecOf,Ot as pathEditKindOf,Io as planTextHighlight,Ho as recordCanvasPerfDuration,ot as rectCornerRadii,tl as removeTableColumn,el as removeTableRow,$v as renderPlacedSmartObjectLayer,To as renderTextRuns,Es as renderVerticalRuns,Nc as replayPageTransferLive,tp as repositionPathBackgroundNode,yr as rowColCoverage,Nt as sceneToClipMatrix,We as selectionBounds,xS as serializePageToSvg,Jg as setGroupWidth,Qr as setTableColumnWidth,Zr as setTableRowHeight,fv as syncAfterPropWrite,en as syncPathBackgroundNode,dv as synthesizePathBackgroundNodes,ao as textBitmapFillAlpha,V as transformPoint,Go as transformedDimensions,ee as typeKeyOf,eo as unmergeTableCells,qt as verticalGlyphOps,Jv as wrapCompatObject};