@yft-design/engine 0.0.50 → 0.0.51
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 +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1088,7 +1088,7 @@ float outside = smoothstep(-uAa, uAa, d);
|
|
|
1088
1088
|
float t = clamp(d / uBlur, 0.0, 1.0);
|
|
1089
1089
|
float glow = (1.0 - t) * (1.0 - t) * outside;
|
|
1090
1090
|
outColor = vec4(uMask * (1.0 - glow * uGlow), outside);
|
|
1091
|
-
}`,Ia=class{program=null;vao=null;vertexBuffer=null;corners=new Float32Array(12);invalidate(){this.program=null,this.vao=null,this.vertexBuffer=null}init(e){let t=(s,a)=>{let l=e.createShader(s);return l?(e.shaderSource(l,a),e.compileShader(l),e.getShaderParameter(l,e.COMPILE_STATUS)?l:(console.warn("[WorkspaceGlow] shader:",e.getShaderInfoLog(l)),e.deleteShader(l),null)):null},r=t(e.VERTEX_SHADER,HS),o=t(e.FRAGMENT_SHADER,GS),i=e.createProgram();return!r||!o||!i?(r&&e.deleteShader(r),o&&e.deleteShader(o),!1):(e.attachShader(i,r),e.attachShader(i,o),e.linkProgram(i),e.deleteShader(r),e.deleteShader(o),e.getProgramParameter(i,e.LINK_STATUS)?(this.program=i,this.vao=e.createVertexArray(),e.bindVertexArray(this.vao),this.vertexBuffer=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer),e.bufferData(e.ARRAY_BUFFER,this.corners.byteLength,e.DYNAMIC_DRAW),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,2,e.FLOAT,!1,0,0),e.bindVertexArray(null),!0):(console.warn("[WorkspaceGlow] link:",e.getProgramInfoLog(i)),e.deleteProgram(i),!1))}draw(e,t){if(!this.program&&!this.init(e))return;let{view:r,vpt:o,cssWidth:i,cssHeight:s,left:a,top:l,width:c,height:u,zoom:h,dpr:d}=t;if(!(h>0)||!(d>0)||!(c>0)||!(u>0))return;let f=BS/h,m=1.5/(h*d),p=ve(o),b=Q(p,0,0),x=Q(p,i,s),g=Math.min(b.x,x.x),y=Math.min(b.y,x.y),v=Math.max(b.x,x.x),S=Math.max(b.y,x.y),w=this.corners;w[0]=g,w[1]=y,w[2]=v,w[3]=y,w[4]=v,w[5]=S,w[6]=g,w[7]=y,w[8]=v,w[9]=S,w[10]=g,w[11]=S;let R=this.program;e.useProgram(R),e.bindVertexArray(this.vao),e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer),e.bufferSubData(e.ARRAY_BUFFER,0,w);let P=new Float32Array([r[0],r[1],0,r[2],r[3],0,r[4],r[5],1]);e.uniformMatrix3fv(e.getUniformLocation(R,"uView"),!1,P),e.uniform2f(e.getUniformLocation(R,"uCenter"),a+c/2,l+u/2),e.uniform2f(e.getUniformLocation(R,"uHalf"),c/2,u/2),e.uniform1f(e.getUniformLocation(R,"uBlur"),f),e.uniform1f(e.getUniformLocation(R,"uAa"),m),e.uniform3f(e.getUniformLocation(R,"uMask"),qc[0],qc[1],qc[2]),e.uniform1f(e.getUniformLocation(R,"uGlow"),WS),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),e.drawArrays(e.TRIANGLES,0,6),e.bindVertexArray(null)}};var _a=class{constructor(e){this.doc=e}doc;glow=new Ia;checker=new La;invalidate(){this.glow.invalidate(),this.checker.invalidate()}drawChecker(e,t,r){let o=this.findWorkspaceNode()?.bounds;o&&this.checker.draw(e,{view:t,vpt:r.vpt,left:o.left,top:o.top,width:o.width,height:o.height,zoom:Math.hypot(r.vpt[0],r.vpt[1]),dpr:r.dpr})}drawBackdrop(e,t,r){let o=this.findWorkspaceNode()?.bounds;o&&this.glow.draw(e,{view:t,vpt:r.vpt,cssWidth:r.cssWidth,cssHeight:r.cssHeight,left:o.left,top:o.top,width:o.width,height:o.height,zoom:Math.hypot(r.vpt[0],r.vpt[1]),dpr:r.dpr})}findWorkspaceNode(){let e=this.doc.nodes.find(t=>String(t.raw.id??"")===gn);return!e||!e.visible||!(e.bounds.width>0)||!(e.bounds.height>0)?null:e}};var XS=.02,zS=256,Kc=class n{domCanvasEl;exportStandInEl=null;get canvasEl(){return this.exportStandInEl??this.domCanvasEl}isExporting(){return this.exportStandInEl!==null}handle;batch;meshBatch;batchOrder;progressiveLoad=new la({render:()=>this.render(),nodeCount:()=>this.doc.nodes.length,alive:()=>!this.disposed&&!this.contextLost,onProgressiveDone:e=>this.bus.fire("engine:progressive-done",e)});textures;gradientRamps;glyphAtlas;renderEpoch=new Pn;bakeKReuseFloor=0;decodeAnimated=null;sources;textRenderer;renderer;exporter;workspaceBackdrop;bus=new Fn;doc=new Ro;dpr;mobileControls;interactive;vpt=[1,0,0,1,0,0];cssWidth=300;cssHeight=150;background;rafId=null;renderTimerId=null;contextLost=!1;disposed=!1;fontInvalidation;retainedFrame;chromeCache=null;interactions;interactionSuspended=!1;marquee=null;panning=!1;textEditing;tableCellEditing;snapGuide;rulerVisibleValue=!1;cropSessionController;expandSessionController;pathSessionController;warpSessionController;onWarpHistoryChange;animationPlaybackController;cellSelectionSink;constructor(e,t,r){gu(),this.domCanvasEl=e,this.domCanvasEl.style.display="block",this.handle=t,this.batch=new Zt(t.gl),this.meshBatch=new ia(t.gl),this.batchOrder=new oa(this.batch,this.meshBatch),this.batch.order=this.batchOrder,this.meshBatch.order=this.batchOrder,this.textures=new ta(t.gl,{epoch:this.renderEpoch}),this.gradientRamps=new ea(t.gl),this.glyphAtlas=new Zs(t.gl,()=>this.requestRenderAll(),o=>this.fontInvalidation.queueSettle(o),this.renderEpoch),this.dpr=r.dpr??(typeof window<"u"&&window.devicePixelRatio||1),this.mobileControls=r.mobileControls??!1,this.interactive=r.interactive??!0,this.background=r.background??[0,0,0,0],this.sources=new Pa(this),this.textRenderer=new ka(t.gl,this.batch,this.glyphAtlas),this.renderer=new Ca(this,this.sources,this.textRenderer),this.fontInvalidation=new Qs(this,this.textRenderer,this.glyphAtlas,this.renderer),this.retainedFrame=new ca(this),this.exporter=new Na(this),this.workspaceBackdrop=new _a(this.doc),this.textEditing=new qs(this),this.tableCellEditing=new Vs(this),this.snapGuide=new Ys(this,Ua),this.cropSessionController=new Fs(this),this.expandSessionController=new Os(this),this.pathSessionController=new Ws(this),this.warpSessionController=new Hs(this),this.animationPlaybackController=new js(this),this.interactions=new As(this,this.snapGuide,this.sources,this.interactive),this.cellSelectionSink=o=>{this.doc.events.fire("table:cellselection",o)},ee.cellSelectionSink=this.cellSelectionSink}static create(e,t={}){let r=null,o=Tm(e,{onLost:()=>r?.onContextLost(),onRestored:()=>r?.onContextRestored()});return o?(r=new n(e,o,t),r):null}onContextLost(){this.contextLost=!0,this.bus.fire("engine:context-lost")}onContextRestored(){this.contextLost=!1,this.recoverGlResources(),this.bus.fire("engine:context-restored"),this.requestRenderAll()}recoverGlResources(){this.retainedFrame.invalidate(),this.batch.rebuild(),this.meshBatch.rebuild(),this.textures.invalidateAll(),this.gradientRamps.invalidateAll(),this.glyphAtlas.reset(),this.sources.invalidateGlTextures(),this.renderer.invalidateGlResources(),this.workspaceBackdrop.invalidate()}invalidateNodeTextBakes(e){this.fontInvalidation.invalidateNodeTextBakes(e)}handleFontsLoaded(e){this.fontInvalidation.handleFontsLoaded(e)}get engineDisposed(){return this.disposed}get engineContextLost(){return this.contextLost}get pointerActive(){return this.interactions.pointerActive}get events(){return this.bus}get document(){return this.doc}get capabilities(){return{maxTextureSize:this.handle.capabilities.maxTextureSize,renderer:this.handle.capabilities.renderer}}get viewportTransform(){return[...this.vpt]}get zoom(){return this.vpt[0]}get gl(){return this.handle.gl}get viewSize(){return{width:this.cssWidth,height:this.cssHeight}}workspaceSize(){let e=this.doc.nodes.find(t=>String(t.raw.id??"")===gn)?.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}}get cropSession(){return this.cropSessionController.active?this.cropSessionController:null}get cropGhostNode(){return this.cropSessionController.target}get maskCropNode(){let e=this.cropSessionController.target;return e instanceof ae?e:null}get expandSession(){return this.expandSessionController.active?this.expandSessionController:null}get pathSession(){return this.pathSessionController.active?this.pathSessionController:null}get warpSession(){return this.warpSessionController.active?this.warpSessionController:null}get warpDebugSample(){return this.warpSessionController.debugBoundsSample}get warpDebugPreview(){return this.warpSessionController.debugPreviewInfo}get warpDebugAnchors(){return this.warpSessionController.debugAnchors}get warpSessionTarget(){return this.warpSessionController.target}get editingNode(){return this.doc.editingNode}get stats(){return{nodeCount:this.doc.nodes.length,skippedTypes:{...this.doc.skippedTypes}}}get diagnostics(){return{glError:this.handle.gl.getError(),drawnInstances:this.batch.drawnInstances,contextLost:this.contextLost}}get textureBudgetInfo(){return{textures:this.textures.stats(),atlas:this.glyphAtlas.stats()}}setTextureBudget(e){this.textures.setBudget(e)}toScene(e,t){return{x:(e-this.vpt[4])/this.vpt[0],y:(t-this.vpt[5])/this.vpt[3]}}toScreen(e,t){return{x:this.vpt[0]*e+this.vpt[4],y:this.vpt[3]*t+this.vpt[5]}}resize(e,t){e<=1||t<=1||(this.cssWidth=Math.max(1,e),this.cssHeight=Math.max(1,t),this.canvasEl.width=Math.round(this.cssWidth*this.dpr),this.canvasEl.height=Math.round(this.cssHeight*this.dpr),this.canvasEl.style.width=`${this.cssWidth}px`,this.canvasEl.style.height=`${this.cssHeight}px`,this.render())}progressiveFirstFrame(e=1e3,t=800){this.progressiveLoad.start(e,t)}async loadObjects(e){this.sources.releaseAnimatedSources(),this.animationPlaybackController.reset(),this.doc.loadObjects(e),await Uc(Yc([...this.doc.nodes]),this.sources,()=>this.requestRenderAll())}async ensureNodeSources(e){await Uc(Yc(e),this.sources,()=>this.requestRenderAll())}setViewportTransform(e){let t=this.vpt[0];this.vpt=[...e],this.renderer.noteVptChange(),e[0]!==t&&this.doc.setViewportZoom(e[0]),this.requestRenderAll()}zoomAt(e,t,r){let o=Math.min(zS,Math.max(XS,this.vpt[0]*r)),i=o/this.vpt[0];this.vpt=[o,0,0,o,e-i*(e-this.vpt[4]),t-i*(t-this.vpt[5])],this.renderer.noteVptChange(),this.doc.setViewportZoom(o),this.requestRenderAll()}pan(e,t){this.vpt[4]+=e,this.vpt[5]+=t,this.renderer.noteVptChange(),this.requestRenderAll()}noteExternalGesture(){this.renderer.noteExternalInteraction()}requestRenderAll(){this.progressiveLoad.absorbExternalRenderRequest(),!(this.rafId!==null||this.renderTimerId!==null||this.disposed||this.contextLost)&&(this.rafId=requestAnimationFrame(()=>{this.rafId=null,this.renderTimerId!==null&&(clearTimeout(this.renderTimerId),this.renderTimerId=null),this.render()}),this.renderTimerId=setTimeout(()=>{this.renderTimerId=null,this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.render()},250))}workspaceChromeNodes(){let e=this.doc.structureVersion;return(!this.chromeCache||this.chromeCache.version!==e)&&(this.chromeCache={version:e,nodes:this.doc.nodes.filter(er)}),this.chromeCache.nodes}render(){if(this.disposed||this.contextLost||!this.batch.valid)return;this.fontInvalidation.consumePendingSettle(),this.textures.markFrame(this.pointerActive),this.glyphAtlas.markFrame(),this.snapGuide.settleMoveSnap();let e=performance.now();this.renderer.beginFrame(e),this.tickAnimation(e),Ga("engine.render",()=>{let t=this.handle.gl;t.viewport(0,0,this.canvasEl.width,this.canvasEl.height),t.clearColor(...this.background),t.clearStencil(0),t.clear(t.COLOR_BUFFER_BIT|t.STENCIL_BUFFER_BIT);let r=qr(this.vpt,this.cssWidth,this.cssHeight,this.dpr);this.workspaceBackdrop.drawChecker(this.handle.gl,r,{vpt:this.vpt,cssWidth:this.cssWidth,cssHeight:this.cssHeight,dpr:this.dpr}),this.batch.begin(r,this.zoom*this.dpr),this.meshBatch.begin(r),this.batch.deferDraws=!0,this.meshBatch.deferDraws=!0,this.batchOrder.reset();let o=this.expandSessionController.active?this.expandSessionController.target:null;if(!(!o&&this.retainedFrame.tryRetainedFrame())){this.batch.begin(r,this.zoom*this.dpr),this.meshBatch.begin(r),this.batch.deferDraws=!0,this.meshBatch.deferDraws=!0,this.batchOrder.reset();let i=this.progressiveLoad.limit>=0?Math.min(this.progressiveLoad.limit,this.doc.nodes.length):this.doc.nodes.length;Hm(this.batch,this.renderer,this.doc.nodes,o?{target:o,underlay:()=>this.expandSessionController.buildUnderlay()}:null,i),this.batchOrder.requestSnapshot=!0,this.batchOrder.flushAll(),this.retainedFrame.captureSnapshot()}this.doc.drainRenderDirty(),this.workspaceBackdrop.drawBackdrop(this.handle.gl,r,{vpt:this.vpt,cssWidth:this.cssWidth,cssHeight:this.cssHeight,dpr:this.dpr}),Gm(this.renderer,this.workspaceChromeNodes()),Xm(this)}),this.retainedFrame.noteFrameRendered(),this.renderer.frame.bakeMore&&this.requestRenderAll(),this.bus.fire("engine:render",performance.now()-e)}readPixels(){return Fd(this.canvasEl)}exportToPixels(e){return this.retainedFrame.invalidate(),this.exporter.exportToPixels(e)}async exportToPixelsAsync(e){return this.retainedFrame.invalidate(),this.exporter.exportToPixelsAsync(e)}async exportRawPixelsAsync(e){return this.retainedFrame.invalidate(),this.exporter.exportRawPixelsAsync(e)}exportToCanvas(e){return this.retainedFrame.invalidate(),this.exporter.exportToCanvas(e)}drainGpuBacklog(){return this.exporter.drainGpuBacklog()}exportToDataURL(e,t="image/png",r){return this.retainedFrame.invalidate(),this.exporter.exportToDataURL(e,t,r)}get exportReady(){return!this.disposed&&!this.contextLost&&this.batch.valid}get sceneNodes(){return this.doc.nodes}applyExportViewport(e,t,r){let o=this.vpt,i=this.exportStandInEl;this.vpt=[...e];let s=document.createElement("canvas");return s.width=t,s.height=r,this.exportStandInEl=s,()=>{this.vpt=o,this.exportStandInEl=i}}measureFrames(e){return Dd(e,()=>this.render())}getSceneSummary(){return _d(this.doc)}getTableCellEditingInfo(){return this.tableCellEditing.info}getTableSelectionInfo(){let e=this.doc.selection.length===1&&this.doc.selection[0]instanceof ee?this.doc.selection[0]:null;return e?{tableId:e.id,cells:e.selectedCells.map(t=>({row:t.row,col:t.col})),anchor:e.cellAnchor?{...e.cellAnchor}:null,range:e.cellRange?{...e.cellRange}:null}:null}getSnapGuideInfo(){return this.snapGuide.info}enterExpandMode(e){this.cropSessionController.active&&this.cropSessionController.exit(),this.pathSessionController.active&&this.pathSessionController.exit();let t=e??this.doc.selection[0];return t?this.expandSessionController.enter(t):!1}exitExpandMode(){this.expandSessionController.exit()}getExpandInfo(){return this.expandSessionController.info}async applyExpandResult(e,t,r){let o=this.findNodeById(e);return!o||!o.isImageType&&!(o instanceof ae)?!1:this.expandSessionController.applyResult(o,t,r)}reloadImageElement(e){return this.sources.reloadNodeImage(e)}findNodeById(e){return this.doc.findNodeDeep(e)?.node??null}async reloadNodeImage(e){let t=this.findNodeById(e);return t?!!await this.sources.reloadNodeImage(t):!1}async reloadMaskClipImage(e){let t=this.findNodeById(e);return t instanceof ae?!!await this.sources.reloadMaskClipImage(t):!1}getCropInfo(){return this.cropSessionController.info}enterCropMode(e,t){this.pathSessionController.active&&this.pathSessionController.exit();let r=e??this.doc.selection[0];return r?this.cropSessionController.enter(r,t):!1}exitCropMode(){this.cropSessionController.exit()}setCropShape(e){this.cropSessionController.setCropShape(e)}updateCropScale(e){return this.cropSessionController.setScale(e)}setCropAspectRatio(e){this.cropSessionController.setAspectRatio(e)}enterPathEditMode(e){this.cropSessionController.active&&this.cropSessionController.exit(),this.expandSessionController.active&&this.expandSessionController.exit();let t=e??this.doc.selection[0];return t?this.pathSessionController.enter(t):!1}async enterWarpMode(e,t){this.cropSessionController.active&&this.cropSessionController.exit(),this.expandSessionController.active&&this.expandSessionController.exit(),this.pathSessionController.active&&this.pathSessionController.exit();let r=e??this.doc.selection[0];return r?this.warpSessionController.enter(r,t):!1}async loadImage(e,t){try{return await Je(e,t??null)}catch{return null}}async exitWarpMode(e){return this.warpSessionController.exit(e)}warpUndo(){return this.warpSessionController.undo()}warpRedo(){return this.warpSessionController.redo()}exitPathEditMode(){this.pathSessionController.exit()}getPathEditInfo(){return this.pathSessionController.info}setPathAnchorType(e,t,r){return this.pathSessionController.target===e?this.pathSessionController.setAnchorType(t,r):!1}highlightPathAnchor(e,t){this.pathSessionController.target===e&&this.pathSessionController.setActiveAnchor(t)}resetPathAnchorStyles(e){this.pathSessionController.target===e&&this.pathSessionController.resetAnchorStyles()}get rulerEnabled(){return this.rulerVisible}get rulerVisible(){return this.rulerVisibleValue}referenceLineDrag=null;rotateDrag=null;setRulerVisible(e){this.rulerVisibleValue!==e&&(this.rulerVisibleValue=e,this.requestRenderAll())}selectAll(){return Od(this.doc,()=>this.requestRenderAll())}deleteSelection(){return Bd(this.doc,()=>this.requestRenderAll())}nudgeSelection(e,t){return Wd(this.doc,e,t,()=>this.requestRenderAll())}getSelectionInfo(){return Nd(this.doc,this.marquee,this.zoom,(e,t)=>this.toScreen(e,t))}getActiveGroupChildInfo(){return Ld(this.doc)}getSvgRasterInfo(){return Id(this.doc,e=>this.sources.svgRasterFactorOf(e))}toObjects(){return this.doc.toObjects()}playAnimations(){this.animationPlaybackController.play()}pauseAnimations(){this.animationPlaybackController.pause()}stopAnimations(){this.animationPlaybackController.stop()}seekAnimations(e){this.animationPlaybackController.seek(e)}getAnimationPlaybackInfo(){return this.animationPlaybackController.info}getScrollTextPlaybackInfo(){return this.animationPlaybackController.scrollTextInfo}playSingleAnimation(e,t,r){return this.animationPlaybackController.playSingleAnimation(e,t,r)}stopSingleAnimation(e){this.animationPlaybackController.stopSingleAnimation(e)}getSingleAnimationPreviewInfo(){return this.animationPlaybackController.singlePreviewInfo}tickAnimation(e){this.animationPlaybackController.tick(e)&&(this.renderer.frame.animationActive=!0)}setEditingSelection(e,t){this.textEditing.setSelection(e,t)}settleMoveSnap(){this.snapGuide.settleMoveSnap()}finishSnapGesture(){this.snapGuide.finishGesture()}registerScalingSnap(e,t){this.snapGuide.registerScaling(e,t)}startCellEditing(e,t,r,o){return this.tableCellEditing.startEditing(e,t,r,o)}enterTextEditingAtClick(e,t,r){this.textEditing.enterEditingAtClick(e,t,r)}dispose(){this.disposed||(this.disposed=!0,this.cellSelectionSink&&ee.cellSelectionSink===this.cellSelectionSink&&(ee.cellSelectionSink=null),this.rafId!==null&&cancelAnimationFrame(this.rafId),this.renderTimerId!==null&&clearTimeout(this.renderTimerId),this.retainedFrame.dispose(),this.progressiveLoad.dispose(),this.interactions.dispose(),this.tableCellEditing.dispose(),this.cropSessionController.dispose(),this.expandSessionController.dispose(),this.pathSessionController.dispose(),this.textEditing.dispose(),this.bus.clear(),this.sources.releaseAnimatedSources(),this.batch.dispose(),this.meshBatch.dispose(),this.textures.dispose(),this.gradientRamps.dispose(),this.sources.dispose(),this.glyphAtlas.dispose(),this.handle.dispose())}};var Jt=class n{constructor(e=0,t=0){this.x=e;this.y=t}x;y;add(e){return new n(this.x+e.x,this.y+e.y)}subtract(e){return new n(this.x-e.x,this.y-e.y)}scalarDivide(e){return new n(this.x/e,this.y/e)}rotate(e,t={x:0,y:0}){let r=Math.sin(e),o=Math.cos(e),i=this.subtract(t);return new n(i.x*o-i.y*r,i.x*r+i.y*o).add(t)}},Qc=class n{constructor(e=0,t=0){typeof e=="number"?(this.x=e,this.y=t):(this.x=e.x,this.y=e.y)}x=0;y=0;add(e){return new n(this.x+e.x,this.y+e.y)}subtract(e){return new n(this.x-e.x,this.y-e.y)}multiply(e){return new n(this.x*e.x,this.y*e.y)}divide(e){return new n(this.x/e.x,this.y/e.y)}scalarAdd(e){return new n(this.x+e,this.y+e)}scalarSubtract(e){return new n(this.x-e,this.y-e)}scalarMultiply(e){return new n(this.x*e,this.y*e)}scalarDivide(e){return new n(this.x/e,this.y/e)}rotate(e){let t=e*Math.PI/180,r=Math.cos(t),o=Math.sin(t);return new n(this.x*r-this.y*o,this.x*o+this.y*r)}dot(e){return this.x*e.x+this.y*e.y}midPointFrom(e){return new n((this.x+e.x)/2,(this.y+e.y)/2)}static lerp(e,t,r){return new n(e.x+(t.x-e.x)*r,e.y+(t.y-e.y)*r)}lerp(e,t){return new n(this.x+(e.x-this.x)*t,this.y+(e.y-this.y)*t)}eq(e){return this.x===e.x&&this.y===e.y}lt(e){return this.x<e.x&&this.y<e.y}gt(e){return this.x>e.x&&this.y>e.y}lte(e){return this.x<=e.x&&this.y<=e.y}gte(e){return this.x>=e.x&&this.y>=e.y}distanceFrom(e){return Math.hypot(this.x-e.x,this.y-e.y)}clone(){return new n(this.x,this.y)}toString(){return`${this.x} ${this.y}`}transform(e,t=!1){return t?new n(e[0]*this.x+e[2]*this.y,e[1]*this.x+e[3]*this.y):new n(e[0]*this.x+e[2]*this.y+e[4],e[1]*this.x+e[3]*this.y+e[5])}};var en=(n,e=0)=>typeof n=="number"&&Number.isFinite(n)?n:e,YS=n=>({sx:en(n.scaleX,1)||1,sy:en(n.scaleY,1)||1}),kp=n=>{let e=n.pathOffset;return!e||typeof e.x!="number"||typeof e.y!="number"?null:{x:e.x,y:e.y}},US=n=>{let e=Ce(n),t=e?Fe(e):null;return t?{x:(t.left+t.right)/2,y:(t.top+t.bottom)/2}:null},$S=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}},jS=(n,e,t,r)=>`M ${t} 0 L ${n-t} 0 A ${t} ${r} 0 0 1 ${n} ${r} L ${n} ${e-r} A ${t} ${r} 0 0 1 ${n-t} ${e} L ${t} ${e} A ${t} ${r} 0 0 1 0 ${e-r} L 0 ${r} A ${t} ${r} 0 0 1 ${t} 0 Z`,Ap=(n,e)=>`M 0 ${-e} A ${n} ${e} 0 1 1 0 ${e} A ${n} ${e} 0 1 1 0 ${-e} Z`,Zc=n=>{if(n.isTextType)return;let e=n.raw,t=se(e),{sx:r,sy:o}=YS(e);if(t===L.PATH){let a="";if(typeof e.path=="string")a=e.path;else if(Array.isArray(e.path)){let l=[];for(let c of e.path)!Array.isArray(c)||typeof c[0]!="string"||l.push(c.length===1?c[0]:`${c[0]} ${c.slice(1).join(" ")}`);a=l.join(" ")}return a.trim()?{path:a,pathOffset:kp(e)??US(a)??{x:0,y:0}}:void 0}if(t===L.RECT||t===L.FABRICRECT){let a=n.dims.x*r,l=n.dims.y*o;if(!(a>0)||!(l>0))return;let c=it(e,n.dims.x,n.dims.y),u=c?Math.min(c.rx*r,a/2):0,h=c?Math.min(c.ry*o,l/2):0;return{path:u>0||h>0?jS(a,l,u,h):`M 0 0 L ${a} 0 L ${a} ${l} L 0 ${l} Z`,pathOffset:{x:a/2,y:l/2}}}if(t===L.CIRCLE){let a=en(e.radius);return a>0?{path:Ap(a*r,a*o),pathOffset:{x:0,y:0}}:void 0}if(t===L.ELLIPSE){let a=(en(e.rx)||n.dims.x/2)*r,l=(en(e.ry)||n.dims.y/2)*o;return!(a>0)||!(l>0)?void 0:{path:Ap(a,l),pathOffset:{x:0,y:0}}}if(t===L.TRIANGLE){let a=n.dims.x*r,l=n.dims.y*o;return!(a>0)||!(l>0)?void 0:{path:`M ${-a/2} ${l/2} L 0 ${-l/2} L ${a/2} ${l/2} Z`,pathOffset:{x:0,y:0}}}if(t===L.POLYGON||t===L.POLYLINE){let a=Array.isArray(e.points)?e.points:[];return a.length===0?{path:"M 0 0",pathOffset:{x:0,y:0}}:{path:a.map((c,u)=>`${u===0?"M":"L"} ${c.x} ${c.y}`).join(" ")+(t===L.POLYGON?" Z":""),pathOffset:kp(e)??$S(a)??{x:0,y:0}}}if(t===L.LINE){let a=en(e.x1),l=en(e.y1),c=en(e.x2),u=en(e.y2);return{path:`M ${a} ${l} L ${c} ${u}`,pathOffset:{x:0,y:0}}}let i=n.dims.x*r,s=n.dims.y*o;if(!(!(i>0)||!(s>0)))return{path:`M 0 0 L ${i} 0 L ${i} ${s} L 0 ${s} Z`,pathOffset:{x:i/2,y:s/2}}};var Np=n=>{if(!(!n||n.length<8||n.some(e=>typeof e!="number"||!Number.isFinite(e))))return{tl:{x:n[0],y:n[1]},tr:{x:n[2],y:n[3]},br:{x:n[4],y:n[5]},bl:{x:n[6],y:n[7]}}},Lp=n=>{let e=[n.tl,n.tr,n.br,n.bl],t=Math.min(...e.map(s=>s.x)),r=Math.min(...e.map(s=>s.y)),o=Math.max(...e.map(s=>s.x)),i=Math.max(...e.map(s=>s.y));return{minX:t,minY:r,width:Math.max(1,Math.ceil(o-t)),height:Math.max(1,Math.ceil(i-r))}},Ip=(n,e,t)=>({tl:{x:n.tl.x+e,y:n.tl.y+t},tr:{x:n.tr.x+e,y:n.tr.y+t},br:{x:n.br.x+e,y:n.br.y+t},bl:{x:n.bl.x+e,y:n.bl.y+t}}),_p=n=>{let e=n.tr.x+n.bl.x-n.tl.x,t=n.tr.y+n.bl.y-n.tl.y;return Math.abs(e-n.br.x)<.01&&Math.abs(t-n.br.y)<.01},Jc=n=>{let e=n.tl.x-n.tr.x+n.br.x-n.bl.x,t=n.tl.y-n.tr.y+n.br.y-n.bl.y;if(Math.abs(e)<1e-6&&Math.abs(t)<1e-6)return{a:n.tr.x-n.tl.x,b:n.bl.x-n.tl.x,c:n.tl.x,d:n.tr.y-n.tl.y,e:n.bl.y-n.tl.y,f:n.tl.y,g:0,h:0};let r=n.tr.x-n.br.x,o=n.tr.y-n.br.y,i=n.bl.x-n.br.x,s=n.bl.y-n.br.y,a=r*s-i*o;if(Math.abs(a)<1e-6)return;let l=(e*s-i*t)/a,c=(r*t-e*o)/a;return{a:n.tr.x-n.tl.x+l*n.tr.x,b:n.bl.x-n.tl.x+c*n.bl.x,c:n.tl.x,d:n.tr.y-n.tl.y+l*n.tr.y,e:n.bl.y-n.tl.y+c*n.bl.y,f:n.tl.y,g:l,h:c}},$r=(n,e,t)=>{let r=n.g*e+n.h*t+1;return{x:(n.a*e+n.b*t+n.c)/r,y:(n.d*e+n.e*t+n.f)/r}},Dp=n=>{let{a:e,b:t,c:r,d:o,e:i,f:s,g:a,h:l}=n,c=e*(i-s*l)-t*(o-s*a)+r*(o*l-i*a);if(Math.abs(c)<1e-6)return;let u=(i-s*l)/c,h=(r*l-t)/c,d=(t*s-r*i)/c,f=(s*a-o)/c,m=(e-r*a)/c,p=(r*o-e*s)/c,b=(o*l-i*a)/c,x=(t*a-e*l)/c,g=(e*i-t*o)/c;if(!(Math.abs(g)<1e-6))return{a:u/g,b:h/g,c:d/g,d:f/g,e:m/g,f:p/g,g:b/g,h:x/g}};var Fp=32,Op=120,eu=1e-6,VS=()=>{let n=document.createElement("canvas");if(!n||typeof n.getContext>"u")throw new Error("Failed to create `canvas` element");return n},qS=n=>{let e=VS();return e.width=n.width,e.height=n.height,e.getContext("2d",{willReadFrequently:!0})?.drawImage(n,0,0),e},KS=(n,e,t)=>n.toDataURL?.(`image/${e}`,t),QS=n=>new Promise((e,t)=>{let r=new FileReader;r.onload=()=>e(String(r.result)),r.onerror=()=>t(r.error),r.readAsDataURL(n)}),Bp=async(n,e,t)=>{try{let r=await new Promise(o=>n.toBlob(o,`image/${e}`,t));if(r)return await QS(r)}catch{}return KS(n,e,t)},ZS=(n,e,t)=>{let r=Math.max(1,n.width),o=Math.max(1,n.height),i=Math.max(1,Math.round(e)),s=Math.max(1,Math.round(t));if(Math.abs(r-i)<eu&&Math.abs(o-s)<eu)return n;let a=document.createElement("canvas");a.width=i,a.height=s;let l=a.getContext("2d");return l?(l.imageSmoothingEnabled=!0,l.imageSmoothingQuality="high",l.drawImage(n,0,0,r,o,0,0,i,s),a):n},JS=(n,e,t,r,o)=>{let i=Math.max(0,Math.min(e-1,r)),s=Math.max(0,Math.min(t-1,o)),a=Math.floor(i),l=Math.floor(s),c=Math.min(e-1,a+1),u=Math.min(t-1,l+1),h=i-a,d=s-l,f=(l*e+a)*4,m=(l*e+c)*4,p=(u*e+a)*4,b=(u*e+c)*4,x=1-d,g=1-h,y=g*x,v=h*x,S=g*d,w=h*d;return[n[f]*y+n[m]*v+n[p]*S+n[b]*w,n[f+1]*y+n[m+1]*v+n[p+1]*S+n[b+1]*w,n[f+2]*y+n[m+2]*v+n[p+2]*S+n[b+2]*w,n[f+3]*y+n[m+3]*v+n[p+3]*S+n[b+3]*w]},ev=(n,e,t)=>{let r=Jc(t),o=r?Dp(r):void 0;if(!o){Hp(n,e,t,Fp);return}let i=Math.max(1,e.width),s=Math.max(1,e.height),a=e.getContext("2d",{willReadFrequently:!0});if(!a){Hp(n,e,t,Fp);return}let l=a.getImageData(0,0,i,s),c=n.createImageData(n.canvas.width,n.canvas.height),u=c.data;for(let h=0;h<n.canvas.height;h++)for(let d=0;d<n.canvas.width;d++){let f=$r(o,d+.5,h+.5);if(f.x<0||f.x>1||f.y<0||f.y>1)continue;let m=f.x*(i-1),p=f.y*(s-1),b=JS(l.data,i,s,m,p),x=(h*n.canvas.width+d)*4;u[x]=b[0],u[x+1]=b[1],u[x+2]=b[2],u[x+3]=b[3]}n.putImageData(c,0,0)},Wp=(n,e,t,r)=>{let[o,i,s]=t,[a,l,c]=r,u=o.x*(i.y-s.y)+i.x*(s.y-o.y)+s.x*(o.y-i.y);if(Math.abs(u)<eu)return;let h=(a.x*(i.y-s.y)+l.x*(s.y-o.y)+c.x*(o.y-i.y))/u,d=(a.y*(i.y-s.y)+l.y*(s.y-o.y)+c.y*(o.y-i.y))/u,f=(a.x*(s.x-i.x)+l.x*(o.x-s.x)+c.x*(i.x-o.x))/u,m=(a.y*(s.x-i.x)+l.y*(o.x-s.x)+c.y*(i.x-o.x))/u,p=(a.x*(i.x*s.y-s.x*i.y)+l.x*(s.x*o.y-o.x*s.y)+c.x*(o.x*i.y-i.x*o.y))/u,b=(a.y*(i.x*s.y-s.x*i.y)+l.y*(s.x*o.y-o.x*s.y)+c.y*(o.x*i.y-i.x*o.y))/u;n.save(),n.beginPath(),n.moveTo(a.x,a.y),n.lineTo(l.x,l.y),n.lineTo(c.x,c.y),n.closePath(),n.clip(),n.setTransform(h,d,f,m,p,b),n.drawImage(e,0,0),n.restore()},Hp=(n,e,t,r)=>{let o=Jc(t);if(!o){n.drawImage(e,0,0,n.canvas.width,n.canvas.height);return}let i=Math.max(1,e.width),s=Math.max(1,e.height),a=Math.min(Op,Math.max(1,Math.ceil(i/r))),l=Math.min(Op,Math.max(1,Math.ceil(s/r)));for(let c=0;c<l;c++){let u=c/l,h=(c+1)/l,d=u*s,f=h*s;for(let m=0;m<a;m++){let p=m/a,b=(m+1)/a,x=p*i,g=b*i,y=$r(o,p,u),v=$r(o,b,u),S=$r(o,b,h),w=$r(o,p,h);Wp(n,e,[{x,y:d},{x:g,y:d},{x:g,y:f}],[y,v,S]),Wp(n,e,[{x,y:d},{x:g,y:f},{x,y:f}],[y,S,w])}}},tv=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=ZS(n,a,l),u=Np(e?.nonAffineTransform||e?.transform);if(!u){let x=qS(n);return{src:await Bp(x,o,r),width:i,height:s,sourceWidth:a,sourceHeight:l}}let h=Lp(u),d=Ip(u,-h.minX,-h.minY),f=t.objectBounds,m=document.createElement("canvas");m.width=h.width,m.height=h.height;let p=m.getContext("2d");if(!p)throw new Error("无法创建智能对象渲染画布");if(p.imageSmoothingEnabled=!0,p.imageSmoothingQuality="high",_p(d)){let x=(d.tr.x-d.tl.x)/a,g=(d.tr.y-d.tl.y)/a,y=(d.bl.x-d.tl.x)/l,v=(d.bl.y-d.tl.y)/l,S=d.tl.x,w=d.tl.y;p.setTransform(x,g,y,v,S,w),p.drawImage(c,0,0)}else ev(p,c,d);let b;if(f){let x=Math.round(f.left-h.minX),g=Math.round(f.top-h.minY),y=Math.max(1,Math.round(f.width)),v=Math.max(1,Math.round(f.height));if(x>=0&&g>=0&&x+y<=h.width+1&&g+v<=h.height+1){b=document.createElement("canvas"),b.width=y,b.height=v;let w=b.getContext("2d");w&&w.drawImage(m,x,g,y,v,0,0,y,v)}else{b=document.createElement("canvas"),b.width=y,b.height=v;let w=b.getContext("2d");w&&(w.imageSmoothingEnabled=!0,w.imageSmoothingQuality="high",w.drawImage(m,0,0,h.width,h.height,0,0,y,v))}}else b=m;return{src:await Bp(b,o,r),width:b.width,height:b.height,sourceWidth:a,sourceHeight:l}};var ce=n=>n.node instanceof ee?n.node:null,Be=n=>n.raw,Pt=n=>{n.canvas?.requestRenderAll?.()},je=(n,e)=>{let t=Be(e);n.set({cellData:t.cellData??[],rows:t.rows,cols:t.cols}),Pt(n)},tu=n=>n.rows??3,nu=n=>n.cols??3,jr=n=>(Array.isArray(n.cellData)||(n.cellData=[]),n.cellData),Jo=(n,e,t)=>{let r=we(n.cellMap,e,t);if(r)return r.isMerged&&r.mergeParent?we(n.cellMap,r.mergeParent.row,r.mergeParent.col):r},Wt=(n,e)=>{let t=ce(n);if(!t||!t.selectedCells.length)return;let r=new Set;for(let o of t.selectedCells){let i=lt(t.cellMap,o.row,o.col),s=`${i.row},${i.col}`;if(r.has(s))continue;r.add(s);let a=we(t.cellMap,i.row,i.col);a&&e(a)}je(n,t)},ru=(n,e,t)=>({get id(){return`${n.id}-r${e.row}c${e.col}-rect`},get _isCell(){return!0},get _row(){return e.row},get _col(){return e.col},get fill(){return e.fill},set fill(r){e.fill=r,t()},get stroke(){return e.stroke},set stroke(r){e.stroke=r,t()},get strokeWidth(){return e.strokeWidth??1},set strokeWidth(r){e.strokeWidth=r,t()},get _colspan(){return e.colspan??1},set _colspan(r){e.colspan=r,t()},get _rowspan(){return e.rowspan??1},set _rowspan(r){e.rowspan=r,t()},get _isMerged(){return e.isMerged??!1},set _isMerged(r){e.isMerged=r,t()},get _mergeParent(){return e.mergeParent??null},set _mergeParent(r){e.mergeParent=r,t()},get _hasCustomFill(){return e.hasCustomFill??!1},set _hasCustomFill(r){e.hasCustomFill=r,t()},get _hasCustomStroke(){return e.hasCustomStroke??!1},set _hasCustomStroke(r){e.hasCustomStroke=r,t()},set(r){for(let[o,i]of Object.entries(r))o!=="dirty"&&(e[o]=i);t()},get(r){return e[r]}}),Gp=(n,e,t)=>({get id(){return`${n.id}-r${e.row}c${e.col}-text`},get _isCellText(){return!0},get _row(){return e.row},get _col(){return e.col},get text(){return e.text??""},set text(r){e.text=r,t()},get fill(){return e.textFill},set fill(r){e.textFill=r,t()},get fontSize(){return e.fontSize??Be(n).fontSize??14},set fontSize(r){e.fontSize=r,t()},get fontWeight(){return e.fontWeight},set fontWeight(r){e.fontWeight=r,t()},get fontFamily(){return e.fontFamily},set fontFamily(r){e.fontFamily=r,t()},get fontStyle(){return e.fontStyle},set fontStyle(r){e.fontStyle=r,t()},get textAlign(){return e.textAlign},set textAlign(r){e.textAlign=r,t()},get underline(){return e.underline??!1},set underline(r){e.underline=r,t()},get linethrough(){return e.linethrough??!1},set linethrough(r){e.linethrough=r,t()},get verticalAlign(){return e.verticalAlign??"middle"},set verticalAlign(r){e.verticalAlign=r,t()},set(r){for(let[o,i]of Object.entries(r))o!=="dirty"&&(o==="fill"?e.textFill=i:e[o]=i);t()},get(r){return r==="fill"?e.textFill:e[r]},setFontFamily(r){e.fontFamily=r,t()},refreshTextDimensions(){}}),nv={canMergeCells(){let n=ce(this);return!!n&&n.selectedCells.length>1},canUseMergeCells(){let n=ce(this);if(!n||!n.selectedCells.length)return!1;let e=new Set,t=!1;for(let{row:r,col:o}of n.selectedCells){let i=Jo(n,r,o);if(!i)return!1;(i.colspan??1)>1||(i.rowspan??1)>1?e.add(`${i.row},${i.col}`):t=!0}return!t&&e.size===1},canSplitRows(){let n=ce(this);if(!n||!n.selectedCells.length)return!1;let e=n.selectedCells[0],t=Jo(n,e.row,e.col);return!!t&&(t.rowspan??1)>1},canSplitColumns(){let n=ce(this);if(!n||!n.selectedCells.length)return!1;let e=n.selectedCells[0],t=Jo(n,e.row,e.col);return!!t&&(t.colspan??1)>1},isSelectColumn(){let n=ce(this);if(!n||!n.selectedCells.length)return!1;let e=new Set(n.selectedCells.map(r=>r.row)),t=new Set(n.selectedCells.map(r=>r.col));if(t.size===1){let r=Array.from(e),o=Math.min(...r),i=Math.max(...r),s=o===0&&i===tu(Be(n))-1,a=e.size>=2,l=!1;for(let c of n.selectedCells)if((Jo(n,c.row,c.col)?.rowspan??1)>1){l=!0;break}return s||a||l}return t.size>1?e.size===1?!1:e.size<=t.size:!1},isSelectRow(){let n=ce(this);if(!n||!n.selectedCells.length)return!1;let e=new Set(n.selectedCells.map(r=>r.row)),t=new Set(n.selectedCells.map(r=>r.col));if(e.size===1){let r=Array.from(t),o=Math.min(...r),i=Math.max(...r),s=o===0&&i===nu(Be(n))-1,a=t.size>=2,l=!1;for(let c of n.selectedCells)if((Jo(n,c.row,c.col)?.colspan??1)>1){l=!0;break}return s||a||l}return e.size>1?t.size===1?!1:e.size>t.size:!1},isRowSelected(n){let e=ce(this);return e?Rr(e.cellMap,e.selectedCells).rows.has(n):!1},isColumnSelected(n){let e=ce(this);return e?Rr(e.cellMap,e.selectedCells).cols.has(n):!1},selectCell(n,e,t=!1){let r=ce(this);if(r){if(t){if(r.cellAnchor){let o=r.cellAnchor,i=bn(r.cellMap,o,{row:n,col:e});r.setCellSelection(i,o,{r1:Math.min(o.row,n),r2:Math.max(o.row,n),c1:Math.min(o.col,e),c2:Math.max(o.col,e)})}}else{let o={row:n,col:e};r.setCellSelection([o],o,{r1:n,r2:n,c1:e,c2:e})}Pt(this)}},selectColumn(n){let e=ce(this);e&&(e.setColumnSelection(n),Pt(this))},selectRow(n){let e=ce(this);e&&(e.setRowSelection(n),Pt(this))},selectAllCells(){let n=ce(this);if(!n)return;let e=n.tableView,t=wo(n.cellMap,e.rows,e.cols);n.setCellSelection(t,t[0]??null,Xe(t)),Pt(this)},clearCellSelection(){let n=ce(this);n&&(n.clearCellSelection(),Pt(this))},buildSelectionRange(n,e){let t=ce(this);return t?bn(t.cellMap,n,e):[]},mergeCells(n,e,t,r){let o=ce(this);if(!o)return;let i=bo(o.raw,n,e,t,r),s={row:i.r1,col:i.c1};o.setCellSelection([s],s,i),je(this,o)},unmergeCells(n,e){let t=ce(this);if(!t||!xo(t.raw,n,e))return;let r={row:n,col:e};t.setCellSelection([r],r,{r1:n,r2:n,c1:e,c2:e}),je(this,t)},addRow(n){let e=ce(this);e&&(go(e.raw,n??tu(Be(e))),je(this,e))},removeRow(n){let e=ce(this);if(!e)return;let t=n??tu(Be(e))-1;if(!Ml(e.raw,t))return;let r=Yi(e.selectedCells,e.cellRange,t,"row");r?e.setCellSelection(r.cells,r.cells[0]??null,r.range):e.clearCellSelection(),je(this,e)},addColumn(n){let e=ce(this);e&&(yo(e.raw,n??nu(Be(e))),je(this,e))},removeColumn(n){let e=ce(this);if(!e)return;let t=n??nu(Be(e))-1;if(!Rl(e.raw,t))return;let r=Yi(e.selectedCells,e.cellRange,t,"col");r?e.setCellSelection(r.cells,r.cells[0]??null,r.range):e.clearCellSelection(),je(this,e)},setColumnWidth(n,e){let t=ce(this);t&&(mo(t.raw,n,e),this.set({columnWidths:Be(t).columnWidths??[]}),Pt(this))},setRowHeight(n,e){let t=ce(this);t&&(po(t.raw,n,e),this.set({manualRowHeights:Be(t).manualRowHeights??[]}),Pt(this))},setSelectWidth(n){let e=ce(this);if(!e)return;let t=e.cellRange,r=Be(e),o=e.tableView;if(!t||o.cols<=0){this.setTableWidth(n);return}let i=r.minCellWidth??40,s=r.cellStrokeWidth??0,a=0;for(let u=t.c1;u<=t.c2;u++)a+=o.columnWidths[u]??0;if(a<=0)return;let l=(n-s-(t.c2-t.c1)*o.cellSpacing)/a,c=[...o.columnWidths];for(let u=t.c1;u<=t.c2;u++)c[u]=Math.max(i,(c[u]??0)*l);this.set({columnWidths:c}),Pt(this)},setSelectHeight(n){let e=ce(this);if(!e)return;let t=e.cellRange,r=Be(e),o=e.tableView;if(!t||o.rows<=0){this.setTableHeight(n);return}let i=r.minCellHeight??40,s=r.cellStrokeWidth??0,a=0;for(let u=t.r1;u<=t.r2;u++)a+=o.rowHeights[u]??0;if(a<=0)return;let l=(n-s-(t.r2-t.r1)*o.cellSpacing)/a,c=Array.from({length:o.rows},(u,h)=>{let d=Array.isArray(r.manualRowHeights)?r.manualRowHeights[h]:null;return typeof d=="number"?d:null});for(let u=t.r1;u<=t.r2;u++)c[u]=Math.max(i,(o.rowHeights[u]??0)*l);this.set({manualRowHeights:c}),Pt(this)},getColumnWidth(n){let e=ce(this);return e?e.tableView.columnWidths[n]??0:0},getRowHeight(n){let e=ce(this);return e?e.tableView.rowHeights[n]??0:0},getRowMinHeight(n){let e=ce(this);return e?e.getRowMinHeight(n):0},relayout(){let n=ce(this);n&&(n.rebuildTable(),Pt(this))},previewLayout(){this.relayout()},getCell(n,e){let t=ce(this);if(!t)return;let r=we(t.cellMap,n,e);return r?ru(t,r,()=>je(this,t)):void 0},getCellText(n,e){let t=ce(this);if(!t)return;let r=we(t.cellMap,n,e);return r?Gp(t,r,()=>je(this,t)):void 0},setSelectionTextAlign(n){Wt(this,e=>{e.textAlign=n})},setSelectionFontSize(n){Wt(this,e=>{e.fontSize=n})},changeSelectionFontSize(n){let e=ce(this);if(!e)return;let t=Be(e).fontSize??14;Wt(this,r=>{let o=Number(r.fontSize)||t;r.fontSize=n==="+"?o+1:Math.max(1,o-1)})},setSelectionFontWeight(n){Wt(this,e=>{e.fontWeight=n})},setSelectionFontStyle(n){Wt(this,e=>{e.fontStyle=n})},setSelectionUnderline(n){Wt(this,e=>{e.underline=n})},setSelectionLinethrough(n){Wt(this,e=>{e.linethrough=n})},setSelectionCellFill(n){Wt(this,e=>{e.fill=n,e.hasCustomFill=!0})},setSelectionCellStroke(n){Wt(this,e=>{e.stroke=n,e.hasCustomStroke=!0})},setSelectionCellStrokeWidth(n){Wt(this,e=>{e.strokeWidth=n,e.hasCustomStroke=!0})},updateCellFill(n){let e=ce(this);if(!e)return;let t=Be(e);t.cellFill=n;for(let r of jr(t))!r.isMerged&&!r.hasCustomFill&&(r.fill=n);je(this,e)},updateCellTextFill(n){let e=ce(this);if(!e)return;let t=Be(e);t.textFill=n;for(let r of jr(t))r.hasCustomTextFill||(r.textFill=n);je(this,e)},updateCellStroke(n){let e=ce(this);if(!e)return;let t=Be(e);t.cellStroke=n;for(let r of jr(t))r.hasCustomStroke||(r.stroke=n);je(this,e)},updateBorderWidth(n){let e=ce(this);e&&(Be(e).cellStrokeWidth=n,je(this,e))},applyTextStylesToAll(n){let e=ce(this);if(!e)return;let t=Be(e),r={...t.textDefaults??{}};for(let[o,i]of Object.entries(n))r[o]=i;t.textDefaults=r;for(let o of jr(t))for(let[i,s]of Object.entries(n))i==="fill"?o.textFill=s:o[i]=s;je(this,e)}},rv={selectedCells(){let n=ce(this);if(n)return n.selectedCells.map(e=>{let t=we(n.cellMap,e.row,e.col);return t?ru(n,t,()=>je(this,n)):void 0}).filter(e=>e!==void 0)},_selectedCells(){let n=ce(this);return n?n.selectedCells:void 0},_selectionRange(){let n=ce(this);return n?n.cellRange:void 0},hasSelection(){let n=ce(this);return n?n.hasCellSelection:!1},selectionCount(){let n=ce(this);return n?n.selectedCells.length:0},cellTexts(){let n=ce(this);if(!n)return;let e=()=>je(this,n);return jr(Be(n)).map(t=>Gp(n,t,e))},cells(){let n=ce(this);if(!n)return;let e=()=>je(this,n);return jr(Be(n)).map(t=>ru(n,t,e))},columnWidths(){let n=ce(this);return n?[...n.tableView.columnWidths]:void 0},rowHeights(){let n=ce(this);return n?[...n.tableView.rowHeights]:void 0}},ou=n=>{for(let[e,t]of Object.entries(nv))Object.assign(n,{[e]:t});for(let[e,t]of Object.entries(rv))Object.defineProperty(n,e,{get:t,configurable:!0,enumerable:!1})};var iu=(n,e,t)=>{let r=Ge(e);if(!r)return null;let o=Et(n,e,t),i=r==="circle"||(typeof e.curvature=="number"?e.curvature:300)>0,s=o.contentOffsetX-o.width/2,a=o.contentOffsetX+o.width/2,l=o.contentOffsetY-o.height/2,c=o.contentOffsetY+o.height/2,u=n.lines.map(()=>[]);for(let h of o.chars){let d=u[h.line];if(!d)continue;let f={char:h.char,charAngle:i?-h.rotation:-(h.rotation+Math.PI),leftAngle:0,rightAngle:0,charRadius:0,bottomRadius:0,topRadius:0,lineRadius:0,cl:{x:h.x,y:h.y},tl:{x:s,y:l},br:{x:a,y:c},bl:{x:h.x,y:h.y},tr:{x:h.x,y:h.y},nl:{x:h.x,y:h.y},nr:{x:h.x,y:h.y},lc:{x:h.x,y:h.y}};d.push(f)}for(let h of u){let d=h[h.length-1];h.push({char:"",charAngle:0,leftAngle:0,rightAngle:0,charRadius:0,bottomRadius:0,topRadius:0,lineRadius:0,cl:d?{...d.cl}:{x:s,y:l},tl:{x:s,y:l},br:{x:a,y:c},bl:{x:s,y:l},tr:{x:a,y:c},nl:{x:s,y:l},nr:{x:a,y:c},lc:{x:s,y:l}})}return u};var ov=n=>{let e=n.textLines,t=n.charBounds,r=n.lineHeights;if(!Array.isArray(e)||!Array.isArray(t)||!Array.isArray(r)||e.length===0||t.length!==e.length||r.length!==e.length)return!1;for(let o=0;o<e.length;o++)if(typeof e[o]!="string"||!Array.isArray(t[o])||t[o].length===0||typeof r[o]!="number"||!Number.isFinite(r[o]))return!1;return!0},cr=class{node;ctx;constructor(e,t){this.node=e,this.ctx=t}set(e,t){let r=typeof e=="string"?{[e]:t}:{...e},o=r.__isCropping&&this.ctx.cropSessionNodeId?.()!==this.node.id?this.toObject():void 0;if("cropAspectRatio"in r){let s={cropAspectRatio:r.cropAspectRatio};delete r.cropAspectRatio,this.ctx.setNodeProps(this.node,s)}if("_cropKey"in r){let s=r._cropKey;delete r._cropKey,this.ctx.applyCropShape?.(this.node,typeof s=="string"&&s?s:null)}if("__isCropping"in r){let s=!!r.__isCropping;delete r.__isCropping,this.clearSessionFlagDirty("__isCropping"),this.__isCropping=s,o&&this.__isCropping&&(this.cropBeforeState=o)}if("__isExpand"in r){let s=!!r.__isExpand;delete r.__isExpand,this.clearSessionFlagDirty("__isExpand"),this.__isExpand=s}if(typeof r.width=="number"&&Dr(this.node)){let s=r.width;delete r.width,this.ctx.setGroupWidth?this.ctx.setGroupWidth(this.node,s):this.ctx.setNodeProps(this.node,{width:s})}this.bumpTextboxWidthToLayoutBox(r),this.bridgeImageSizeProps(r);let i=r;if((typeof r.width=="number"||typeof r.height=="number")&&!("clipImage"in r)&&ot.has(se(this.node.raw))){let s=Ht(this.node),a=this.node.raw,l=Number(a.width)||0,c=Number(a.height)||0,u=typeof r.width=="number"?r.width:l,h=typeof r.height=="number"?r.height:c,d=this.node.clipImageEl,f=d?.naturalWidth||Number(s?.width)||0,m=d?.naturalHeight||Number(s?.height)||0;if(s&&l>0&&c>0&&u>0&&h>0&&f>0&&m>0){let p=(g,y)=>Math.max(g/f,y/m),b=Number(s.scaleX)||1,x=p(u,h)*(b/p(l,c));i={...r,clipImage:{...s,scaleX:x,scaleY:x}}}}return Object.keys(i).length>0&&this.ctx.setNodeProps(this.node,i),this}bumpTextboxWidthToLayoutBox(e){if(typeof e.width!="number"||!(this.node instanceof Se)||e.width<0||se(this.node.raw)!==L.TEXTBOX||Ge(this.node.raw))return;let r=e.width;delete e.width,this.ctx.setNodeProps(this.node,{width:r});let o=this.node.dims.x;Number.isFinite(o)&&o>r+.01&&this.ctx.setNodeProps(this.node,{width:o})}clearSessionFlagDirty(e){this.node.raw[e]!==void 0&&this.ctx.setNodeProps(this.node,{[e]:void 0})}get(e){return this.node.raw[e]}setCoords(){}getCenterPoint(){return{...this.node.center}}getRelativeCenterPoint(){return new Jt(this.node.center.x,this.node.center.y)}translateToOriginPoint(e,t="center",r="center"){let o=u=>u==="left"||u==="top"?-.5:u==="right"||u==="bottom"?.5:0,i=o(t),s=o(r),a=i||s?this._getTransformedDimensions():new Jt(0,0),l=new Jt(e.x+i*a.x,e.y+s*a.y),c=this.node.raw.angle;return typeof c=="number"&&c&&(l=l.rotate(c*Math.PI/180,e)),l}toPath(){let e=this.ctx.getTextGlyphPath?.(this.node);return e||Zc(this.node)}toPathDecorations(){return this.ctx.getTextDecorations?.(this.node)??[]}toPathEffectLayers(e){return[]}_getTransformedDimensions(){let e=this.node.raw;return new Jt(this.node.dims.x*(e.scaleX??1),this.node.dims.y*(e.scaleY??1))}getBoundingRect(){let e=this.node.bounds;return{left:e.left,top:e.top,width:e.right-e.left,height:e.bottom-e.top}}getInkRect(){let e=Bn(this.node.inkACoords);return{left:e.left,top:e.top,width:e.width,height:e.height}}get aCoords(){return this.node.aCoords}getCoords(){let e=this.node.aCoords;return[e.tl,e.tr,e.br,e.bl]}calcOCoords(){let e=this.ctx.getViewportTransform?.()??[1,0,0,1,0,0],t=o=>({x:e[0]*o.x+e[2]*o.y+e[4],y:e[1]*o.x+e[3]*o.y+e[5]}),r=this.node.aCoords;return{tl:t(r.tl),tr:t(r.tr),br:t(r.br),bl:t(r.bl)}}rotate(e){let{angle:t,left:r,top:o}=this.node.rotateAroundCenter(e);return this.set({angle:t,left:r,top:o})}setPositionByOrigin(e,t,r){let o=this.node.raw,i=typeof o.scaleX=="number"?o.scaleX:1,s=typeof o.scaleY=="number"?o.scaleY:1,a=this.node.dims.x*i,l=this.node.dims.y*s,c=t==="center"?0:t==="right"?.5:-.5,u=r==="center"?0:r==="bottom"?.5:-.5,h=c*a,d=u*l,f=(typeof o.angle=="number"?o.angle:0)*Math.PI/180,m=Math.cos(f),p=Math.sin(f),b={x:e.x-(h*m-d*p),y:e.y-(h*p+d*m)},x=xe({...o},b);return this.set({left:x.x,top:x.y})}scale(e){let t=this.node.raw;return this.set({scaleX:(t.scaleX??1)*e,scaleY:(t.scaleY??1)*e})}getScaledWidth(){return this.node.dims.x*(this.node.raw.scaleX??1)}getScaledHeight(){return this.node.dims.y*(this.node.raw.scaleY??1)}getObjectScaling(){let e=this.node.raw;return{scaleX:e.scaleX??1,scaleY:e.scaleY??1}}get getObjects(){if(this.node instanceof J)return()=>this.node.children.map(e=>this.ctx.wrapNode(e))}get _objects(){if(this.node instanceof J)return this.node.children.map(e=>this.ctx.wrapNode(e))}get ref(){return this}get isImageLikeNode(){let e=se(this.node.raw);return dt.has(e)||ot.has(e)||e===L.GIF||e===L.VIDEO}get getSrc(){if(this.isImageLikeNode)return()=>{let e=this.node.raw;return typeof e.originalSrc=="string"&&e.originalSrc?e.originalSrc:typeof e.src=="string"?e.src:""}}get getRealSrc(){let e=this.getSrc;if(e)return()=>e()}get replaceSrc(){if(this.isImageLikeNode)return async e=>(this.set({src:e,crossOrigin:"anonymous",originalSrc:e}),await this.ctx.reloadNodeImage?.(this.node),this)}get setElement(){if(this.isImageLikeNode)return(e,t)=>(this.node.imageEl=e,t&&this.set(t),this)}get getElement(){if(!this.isImageLikeNode)return;let e=this.node;return e instanceof ie?()=>e.paintSource??e.imageEl:()=>e.imageEl}get _element(){if(this.isImageLikeNode)return this.node.imageEl}get clipImage(){return Ht(this.node)?sv(this.node,this.ctx):void 0}set clipImage(e){let t=e&&typeof e=="object"&&typeof e.toObject=="function"?e.toObject(this.serializationProps()):e;this.ctx.setNodeProps(this.node,{clipImage:t})}getWidthHeight(e=!1){let t=this._getTransformedDimensions(),r=(this.node.raw.strokeWidth??0)||0;return{x:t.x-r,y:t.y-r}}getWidth(){return this.getWidthHeight().x}getHeight(){return this.getWidthHeight().y}sourceNaturalSize(){let e=this.node.imageEl;if(e)return{width:e.naturalWidth||e.width||0,height:e.naturalHeight||e.height||0};if(this.node instanceof ie){let t=this.node.paintSource;if(t)return{width:("videoWidth"in t?t.videoWidth:t.width)||t.width||0,height:("videoHeight"in t?t.videoHeight:t.height)||t.height||0}}return{width:0,height:0}}getOriginalElementWidth(){return this.sourceNaturalSize().width}getOriginalElementHeight(){return this.sourceNaturalSize().height}getElementWidth(){return this.sourceNaturalSize().width}getElementHeight(){return this.sourceNaturalSize().height}cropOffset(){if(!this.isImageLikeNode)return{x:0,y:0};let e=this.node.raw;return e.cropSizeMode==="visible"?{x:0,y:0}:{x:Number(e.cropX)||0,y:Number(e.cropY)||0}}get left(){return this.node.raw.left??0}set left(e){this.set({left:e})}get top(){return this.node.raw.top??0}set top(e){this.set({top:e})}get scaleX(){return this.node.raw.scaleX??1}set scaleX(e){this.set({scaleX:e})}get scaleY(){return this.node.raw.scaleY??1}set scaleY(e){this.set({scaleY:e})}get angle(){return this.node.raw.angle??0}set angle(e){this.set({angle:e})}get skewX(){return this.node.raw.skewX??0}set skewX(e){this.set({skewX:e})}get skewY(){return this.node.raw.skewY??0}set skewY(e){this.set({skewY:e})}get flipX(){return this.node.raw.flipX??!1}set flipX(e){this.set({flipX:e})}get flipY(){return this.node.raw.flipY??!1}set flipY(e){this.set({flipY:e})}get originX(){return this.node.raw.originX??"left"}set originX(e){this.set({originX:e})}get originY(){return this.node.raw.originY??"top"}set originY(e){this.set({originY:e})}get width(){return(this.node.raw.width??0)-this.cropOffset().x}set width(e){if(Dr(this.node)){if(this.ctx.setGroupWidth){this.ctx.setGroupWidth(this.node,e);return}this.ctx.setNodeProps(this.node,{width:e});return}let t=this.cropOffset();this.ctx.setNodeProps(this.node,{width:e+t.x})}get height(){return(this.node.raw.height??0)-this.cropOffset().y}set height(e){let t=this.cropOffset();this.ctx.setNodeProps(this.node,{height:e+t.y})}bridgeImageSizeProps(e){if(!this.isImageLikeNode)return;let t=this.node.raw;if(t.cropSizeMode==="visible")return;let r=typeof e.cropX=="number"?e.cropX:Number(t.cropX)||0,o=typeof e.cropY=="number"?e.cropY:Number(t.cropY)||0;typeof e.width=="number"&&r>0&&(e.width=e.width+r),typeof e.height=="number"&&o>0&&(e.height=e.height+o)}cropBeforeState;get __isCropping(){return this.isImageLikeNode&&this.ctx.cropSessionNodeId?.()===this.node.id}set __isCropping(e){if(this.isImageLikeNode)if(e){let t=this.ctx.cropSessionNodeId?.()!==this.node.id;if(t&&(this.cropBeforeState=this.toObject()),!this.ctx.enterCropSession?.(this.node)){t&&(this.cropBeforeState=void 0);return}let r=this.node.raw.cropAspectRatio;typeof r=="number"&&r>0&&this.ctx.setCropSessionAspectRatio?.(r)}else this.ctx.exitCropSession?.(this.node),this.cropBeforeState=void 0}get __isExpand(){return this.isImageLikeNode&&this.ctx.expandSessionNodeId?.()===this.node.id}set __isExpand(e){this.isImageLikeNode&&(e?this.ctx.enterExpandSession?.(this.node):this.ctx.exitExpandSession?.(this.node))}get beforeState(){return this.cropBeforeState}onDeselectEvent(){this.ctx.exitCropSession?.(this.node),this.ctx.exitExpandSession?.(this.node),this.cropBeforeState=void 0}expandOffsetOf(e){let t=this.ctx.expandSessionOffsets?.(this.node);if(t)return t[e];let r=e==="left"?"Left":e==="right"?"Right":e==="top"?"Top":"Bottom",o=this.node.raw[`expand${r}Offset`];return typeof o=="number"?o:void 0}get expandLeftOffset(){return this.isImageLikeNode?this.expandOffsetOf("left"):void 0}get expandRightOffset(){return this.isImageLikeNode?this.expandOffsetOf("right"):void 0}get expandTopOffset(){return this.isImageLikeNode?this.expandOffsetOf("top"):void 0}get expandBottomOffset(){return this.isImageLikeNode?this.expandOffsetOf("bottom"):void 0}setExpandOffset(){let e=this.ctx.expandSessionOffsets?.(this.node);e&&this.set({expandLeftOffset:e.left,expandRightOffset:e.right,expandTopOffset:e.top,expandBottomOffset:e.bottom})}updateCropScale(e){if(!this.__isCropping||!(e>0)||!Number.isFinite(e))return!1;if(this.ctx.updateCropSessionScale)return this.ctx.updateCropSessionScale(e);let t=this.node.imageEl;if(!t)return!1;let r=this.node.raw,o=t.naturalWidth||t.width,i=t.naturalHeight||t.height,s=r.scaleX??1,a=e/s,l=e/(r.scaleY??1),c=this.width,u=this.height,h=c/a,d=u/l,f=(r.cropX??0)+c/2-h/2,m=(r.cropY??0)+u/2-d/2;return h<Math.min(8,o)||d<Math.min(8,i)||f<0||m<0||f+h>o||m+d>i?!1:(this.set({cropScale:e,scaleX:e,scaleY:e,width:h,height:d,cropX:f,cropY:m}),!0)}getMaxEffectPadding(){let e=this.node.raw,t=0,r=e.effects??{},o=u=>(u??[]).filter(h=>h.enabled&&h.showInDialog),i=o(r.solidFill);i.length>0&&(t=Math.max(t,i.reduce((u,h)=>Math.max(u,Math.abs(Number(h.offsetX)||0),Math.abs(Number(h.offsetY)||0)),0)));let s=o(r.dropShadow);s.length>0&&(t=Math.max(t,s.reduce((u,h)=>{let d=(Number(h.blur)||0)*2;return Math.max(u,Math.abs(Number(h.offsetX)||0)+d,Math.abs(Number(h.offsetY)||0)+d)},0)));let a=o(r.stroke);a.length>0&&(t=Math.max(t,a.reduce((u,h)=>{let d=h.size,f=Number(h.strokeWidth)||Number(d?.value)||0;return Math.max(u,f+Math.abs(Number(h.offsetX)||0),f+Math.abs(Number(h.offsetY)||0))},0)));let l=e.shadow;if(l){let u=(Number(l.blur)||0)*2;t=Math.max(t,Math.abs(Number(l.offsetX)||0)+u,Math.abs(Number(l.offsetY)||0)+u)}let c=Number(e.strokeWidth)||0;if(e.stroke&&c){let u=e.strokeAlignment==="outside"?c*2:c;t=Math.max(t,u)}return t}isType(...e){let t=se(this.node.raw);return e.some(r=>r.toLowerCase()===t)}getStyleAtPosition(e){if(!(this.node instanceof Se))return{};let t=typeof this.node.raw.text=="string"?this.node.raw.text:"";if(e<0||e>=t.length)return{};let r=e,o=t.split(`
|
|
1091
|
+
}`,Ia=class{program=null;vao=null;vertexBuffer=null;corners=new Float32Array(12);invalidate(){this.program=null,this.vao=null,this.vertexBuffer=null}init(e){let t=(s,a)=>{let l=e.createShader(s);return l?(e.shaderSource(l,a),e.compileShader(l),e.getShaderParameter(l,e.COMPILE_STATUS)?l:(console.warn("[WorkspaceGlow] shader:",e.getShaderInfoLog(l)),e.deleteShader(l),null)):null},r=t(e.VERTEX_SHADER,HS),o=t(e.FRAGMENT_SHADER,GS),i=e.createProgram();return!r||!o||!i?(r&&e.deleteShader(r),o&&e.deleteShader(o),!1):(e.attachShader(i,r),e.attachShader(i,o),e.linkProgram(i),e.deleteShader(r),e.deleteShader(o),e.getProgramParameter(i,e.LINK_STATUS)?(this.program=i,this.vao=e.createVertexArray(),e.bindVertexArray(this.vao),this.vertexBuffer=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer),e.bufferData(e.ARRAY_BUFFER,this.corners.byteLength,e.DYNAMIC_DRAW),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,2,e.FLOAT,!1,0,0),e.bindVertexArray(null),!0):(console.warn("[WorkspaceGlow] link:",e.getProgramInfoLog(i)),e.deleteProgram(i),!1))}draw(e,t){if(!this.program&&!this.init(e))return;let{view:r,vpt:o,cssWidth:i,cssHeight:s,left:a,top:l,width:c,height:u,zoom:h,dpr:d}=t;if(!(h>0)||!(d>0)||!(c>0)||!(u>0))return;let f=BS/h,m=1.5/(h*d),p=ve(o),b=Q(p,0,0),x=Q(p,i,s),g=Math.min(b.x,x.x),y=Math.min(b.y,x.y),v=Math.max(b.x,x.x),S=Math.max(b.y,x.y),w=this.corners;w[0]=g,w[1]=y,w[2]=v,w[3]=y,w[4]=v,w[5]=S,w[6]=g,w[7]=y,w[8]=v,w[9]=S,w[10]=g,w[11]=S;let R=this.program;e.useProgram(R),e.bindVertexArray(this.vao),e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer),e.bufferSubData(e.ARRAY_BUFFER,0,w);let P=new Float32Array([r[0],r[1],0,r[2],r[3],0,r[4],r[5],1]);e.uniformMatrix3fv(e.getUniformLocation(R,"uView"),!1,P),e.uniform2f(e.getUniformLocation(R,"uCenter"),a+c/2,l+u/2),e.uniform2f(e.getUniformLocation(R,"uHalf"),c/2,u/2),e.uniform1f(e.getUniformLocation(R,"uBlur"),f),e.uniform1f(e.getUniformLocation(R,"uAa"),m),e.uniform3f(e.getUniformLocation(R,"uMask"),qc[0],qc[1],qc[2]),e.uniform1f(e.getUniformLocation(R,"uGlow"),WS),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),e.drawArrays(e.TRIANGLES,0,6),e.bindVertexArray(null)}};var _a=class{constructor(e){this.doc=e}doc;glow=new Ia;checker=new La;invalidate(){this.glow.invalidate(),this.checker.invalidate()}drawChecker(e,t,r){let o=this.findWorkspaceNode()?.bounds;o&&this.checker.draw(e,{view:t,vpt:r.vpt,left:o.left,top:o.top,width:o.width,height:o.height,zoom:Math.hypot(r.vpt[0],r.vpt[1]),dpr:r.dpr})}drawBackdrop(e,t,r){let o=this.findWorkspaceNode()?.bounds;o&&this.glow.draw(e,{view:t,vpt:r.vpt,cssWidth:r.cssWidth,cssHeight:r.cssHeight,left:o.left,top:o.top,width:o.width,height:o.height,zoom:Math.hypot(r.vpt[0],r.vpt[1]),dpr:r.dpr})}findWorkspaceNode(){let e=this.doc.nodes.find(t=>String(t.raw.id??"")===gn);return!e||!e.visible||!(e.bounds.width>0)||!(e.bounds.height>0)?null:e}};var XS=.02,zS=256,Kc=class n{domCanvasEl;exportStandInEl=null;get canvasEl(){return this.exportStandInEl??this.domCanvasEl}isExporting(){return this.exportStandInEl!==null}handle;batch;meshBatch;batchOrder;progressiveLoad=new la({render:()=>this.render(),nodeCount:()=>this.doc.nodes.length,alive:()=>!this.disposed&&!this.contextLost,onProgressiveDone:e=>this.bus.fire("engine:progressive-done",e)});textures;gradientRamps;glyphAtlas;renderEpoch=new Pn;bakeKReuseFloor=0;decodeAnimated=null;sources;textRenderer;renderer;exporter;workspaceBackdrop;bus=new Fn;doc=new Ro;dpr;mobileControls;interactive;vpt=[1,0,0,1,0,0];cssWidth=300;cssHeight=150;background;rafId=null;renderTimerId=null;contextLost=!1;disposed=!1;fontInvalidation;retainedFrame;chromeCache=null;interactions;interactionSuspended=!1;marquee=null;panning=!1;textEditing;tableCellEditing;snapGuide;rulerVisibleValue=!1;cropSessionController;expandSessionController;pathSessionController;warpSessionController;onWarpHistoryChange;animationPlaybackController;cellSelectionSink;constructor(e,t,r){gu(),this.domCanvasEl=e,this.domCanvasEl.style.display="block",this.handle=t,this.batch=new Zt(t.gl),this.meshBatch=new ia(t.gl),this.batchOrder=new oa(this.batch,this.meshBatch),this.batch.order=this.batchOrder,this.meshBatch.order=this.batchOrder,this.textures=new ta(t.gl,{epoch:this.renderEpoch}),this.gradientRamps=new ea(t.gl),this.glyphAtlas=new Zs(t.gl,()=>this.requestRenderAll(),o=>this.fontInvalidation.queueSettle(o),this.renderEpoch),this.dpr=r.dpr??(typeof window<"u"&&window.devicePixelRatio||1),this.mobileControls=r.mobileControls??!1,this.interactive=r.interactive??!0,this.background=r.background??[0,0,0,0],this.sources=new Pa(this),this.textRenderer=new ka(t.gl,this.batch,this.glyphAtlas),this.renderer=new Ca(this,this.sources,this.textRenderer),this.fontInvalidation=new Qs(this,this.textRenderer,this.glyphAtlas,this.renderer),this.retainedFrame=new ca(this),this.exporter=new Na(this),this.workspaceBackdrop=new _a(this.doc),this.textEditing=new qs(this),this.tableCellEditing=new Vs(this),this.snapGuide=new Ys(this,Ua),this.cropSessionController=new Fs(this),this.expandSessionController=new Os(this),this.pathSessionController=new Ws(this),this.warpSessionController=new Hs(this),this.animationPlaybackController=new js(this),this.interactions=new As(this,this.snapGuide,this.sources,this.interactive),this.cellSelectionSink=o=>{this.doc.events.fire("table:cellselection",o)},ee.cellSelectionSink=this.cellSelectionSink}static create(e,t={}){let r=null,o=Tm(e,{onLost:()=>r?.onContextLost(),onRestored:()=>r?.onContextRestored()});return o?(r=new n(e,o,t),r):null}onContextLost(){this.contextLost=!0,this.bus.fire("engine:context-lost")}onContextRestored(){this.contextLost=!1,this.recoverGlResources(),this.bus.fire("engine:context-restored"),this.requestRenderAll()}recoverGlResources(){this.retainedFrame.invalidate(),this.batch.rebuild(),this.meshBatch.rebuild(),this.textures.invalidateAll(),this.gradientRamps.invalidateAll(),this.glyphAtlas.reset(),this.sources.invalidateGlTextures(),this.renderer.invalidateGlResources(),this.workspaceBackdrop.invalidate()}invalidateNodeTextBakes(e){this.fontInvalidation.invalidateNodeTextBakes(e)}handleFontsLoaded(e){this.fontInvalidation.handleFontsLoaded(e)}get engineDisposed(){return this.disposed}get engineContextLost(){return this.contextLost}get pointerActive(){return this.interactions.pointerActive}get events(){return this.bus}get document(){return this.doc}get capabilities(){return{maxTextureSize:this.handle.capabilities.maxTextureSize,renderer:this.handle.capabilities.renderer}}get viewportTransform(){return[...this.vpt]}get zoom(){return this.vpt[0]}get gl(){return this.handle.gl}get viewSize(){return{width:this.cssWidth,height:this.cssHeight}}workspaceSize(){let e=this.doc.nodes.find(t=>String(t.raw.id??"")===gn)?.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}}get cropSession(){return this.cropSessionController.active?this.cropSessionController:null}get cropGhostNode(){return this.cropSessionController.target}get maskCropNode(){let e=this.cropSessionController.target;return e instanceof ae?e:null}get expandSession(){return this.expandSessionController.active?this.expandSessionController:null}get pathSession(){return this.pathSessionController.active?this.pathSessionController:null}get warpSession(){return this.warpSessionController.active?this.warpSessionController:null}get warpDebugSample(){return this.warpSessionController.debugBoundsSample}get warpDebugPreview(){return this.warpSessionController.debugPreviewInfo}get warpDebugAnchors(){return this.warpSessionController.debugAnchors}get warpSessionTarget(){return this.warpSessionController.target}get editingNode(){return this.doc.editingNode}get stats(){return{nodeCount:this.doc.nodes.length,skippedTypes:{...this.doc.skippedTypes}}}get diagnostics(){return{glError:this.handle.gl.getError(),drawnInstances:this.batch.drawnInstances,contextLost:this.contextLost}}get textureBudgetInfo(){return{textures:this.textures.stats(),atlas:this.glyphAtlas.stats()}}setTextureBudget(e){this.textures.setBudget(e)}toScene(e,t){return{x:(e-this.vpt[4])/this.vpt[0],y:(t-this.vpt[5])/this.vpt[3]}}toScreen(e,t){return{x:this.vpt[0]*e+this.vpt[4],y:this.vpt[3]*t+this.vpt[5]}}resize(e,t){e<=1||t<=1||(this.cssWidth=Math.max(1,e),this.cssHeight=Math.max(1,t),this.canvasEl.width=Math.round(this.cssWidth*this.dpr),this.canvasEl.height=Math.round(this.cssHeight*this.dpr),this.canvasEl.style.width=`${this.cssWidth}px`,this.canvasEl.style.height=`${this.cssHeight}px`,this.render())}progressiveFirstFrame(e=1e3,t=800){this.progressiveLoad.start(e,t)}async loadObjects(e){this.sources.releaseAnimatedSources(),this.animationPlaybackController.reset(),this.doc.loadObjects(e),await Uc(Yc([...this.doc.nodes]),this.sources,()=>this.requestRenderAll())}async ensureNodeSources(e){await Uc(Yc(e),this.sources,()=>this.requestRenderAll())}setViewportTransform(e){let t=this.vpt[0];this.vpt=[...e],this.renderer.noteVptChange(),e[0]!==t&&this.doc.setViewportZoom(e[0]),this.requestRenderAll()}zoomAt(e,t,r){let o=Math.min(zS,Math.max(XS,this.vpt[0]*r)),i=o/this.vpt[0];this.vpt=[o,0,0,o,e-i*(e-this.vpt[4]),t-i*(t-this.vpt[5])],this.renderer.noteVptChange(),this.doc.setViewportZoom(o),this.requestRenderAll()}pan(e,t){this.vpt[4]+=e,this.vpt[5]+=t,this.renderer.noteVptChange(),this.requestRenderAll()}noteExternalGesture(){this.renderer.noteExternalInteraction()}requestRenderAll(){this.progressiveLoad.absorbExternalRenderRequest(),!(this.rafId!==null||this.renderTimerId!==null||this.disposed||this.contextLost)&&(this.rafId=requestAnimationFrame(()=>{this.rafId=null,this.renderTimerId!==null&&(clearTimeout(this.renderTimerId),this.renderTimerId=null),this.render()}),this.renderTimerId=setTimeout(()=>{this.renderTimerId=null,this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.render()},250))}workspaceChromeNodes(){let e=this.doc.structureVersion;return(!this.chromeCache||this.chromeCache.version!==e)&&(this.chromeCache={version:e,nodes:this.doc.nodes.filter(er)}),this.chromeCache.nodes}render(){if(this.disposed||this.contextLost||!this.batch.valid)return;this.fontInvalidation.consumePendingSettle(),this.textures.markFrame(this.pointerActive),this.glyphAtlas.markFrame(),this.snapGuide.settleMoveSnap();let e=performance.now();this.renderer.beginFrame(e),this.tickAnimation(e),Ga("engine.render",()=>{let t=this.handle.gl;t.viewport(0,0,this.canvasEl.width,this.canvasEl.height),t.clearColor(...this.background),t.clearStencil(0),t.clear(t.COLOR_BUFFER_BIT|t.STENCIL_BUFFER_BIT);let r=qr(this.vpt,this.cssWidth,this.cssHeight,this.dpr);this.workspaceBackdrop.drawChecker(this.handle.gl,r,{vpt:this.vpt,cssWidth:this.cssWidth,cssHeight:this.cssHeight,dpr:this.dpr}),this.batch.begin(r,this.zoom*this.dpr),this.meshBatch.begin(r),this.batch.deferDraws=!0,this.meshBatch.deferDraws=!0,this.batchOrder.reset();let o=this.expandSessionController.active?this.expandSessionController.target:null;if(!(!o&&this.retainedFrame.tryRetainedFrame())){this.batch.begin(r,this.zoom*this.dpr),this.meshBatch.begin(r),this.batch.deferDraws=!0,this.meshBatch.deferDraws=!0,this.batchOrder.reset();let i=this.progressiveLoad.limit>=0?Math.min(this.progressiveLoad.limit,this.doc.nodes.length):this.doc.nodes.length;Hm(this.batch,this.renderer,this.doc.nodes,o?{target:o,underlay:()=>this.expandSessionController.buildUnderlay()}:null,i),this.batchOrder.requestSnapshot=!0,this.batchOrder.flushAll(),this.retainedFrame.captureSnapshot()}this.doc.drainRenderDirty(),this.workspaceBackdrop.drawBackdrop(this.handle.gl,r,{vpt:this.vpt,cssWidth:this.cssWidth,cssHeight:this.cssHeight,dpr:this.dpr}),Gm(this.renderer,this.workspaceChromeNodes()),Xm(this)}),this.retainedFrame.noteFrameRendered(),this.renderer.frame.bakeMore&&this.requestRenderAll(),this.bus.fire("engine:render",performance.now()-e)}readPixels(){return Fd(this.canvasEl)}exportToPixels(e){return this.retainedFrame.invalidate(),this.exporter.exportToPixels(e)}async exportToPixelsAsync(e){return this.retainedFrame.invalidate(),this.exporter.exportToPixelsAsync(e)}async exportRawPixelsAsync(e){return this.retainedFrame.invalidate(),this.exporter.exportRawPixelsAsync(e)}exportToCanvas(e){return this.retainedFrame.invalidate(),this.exporter.exportToCanvas(e)}drainGpuBacklog(){return this.exporter.drainGpuBacklog()}exportToDataURL(e,t="image/png",r){return this.retainedFrame.invalidate(),this.exporter.exportToDataURL(e,t,r)}get exportReady(){return!this.disposed&&!this.contextLost&&this.batch.valid}get sceneNodes(){return this.doc.nodes}applyExportViewport(e,t,r){let o=this.vpt,i=this.exportStandInEl;this.vpt=[...e];let s=document.createElement("canvas");return s.width=t,s.height=r,this.exportStandInEl=s,()=>{this.vpt=o,this.exportStandInEl=i}}measureFrames(e){return Dd(e,()=>this.render())}getSceneSummary(){return _d(this.doc)}getTableCellEditingInfo(){return this.tableCellEditing.info}getTableSelectionInfo(){let e=this.doc.selection.length===1&&this.doc.selection[0]instanceof ee?this.doc.selection[0]:null;return e?{tableId:e.id,cells:e.selectedCells.map(t=>({row:t.row,col:t.col})),anchor:e.cellAnchor?{...e.cellAnchor}:null,range:e.cellRange?{...e.cellRange}:null}:null}getSnapGuideInfo(){return this.snapGuide.info}enterExpandMode(e){this.cropSessionController.active&&this.cropSessionController.exit(),this.pathSessionController.active&&this.pathSessionController.exit();let t=e??this.doc.selection[0];return t?this.expandSessionController.enter(t):!1}exitExpandMode(){this.expandSessionController.exit()}getExpandInfo(){return this.expandSessionController.info}async applyExpandResult(e,t,r){let o=this.findNodeById(e);return!o||!o.isImageType&&!(o instanceof ae)?!1:this.expandSessionController.applyResult(o,t,r)}reloadImageElement(e){return this.sources.reloadNodeImage(e)}findNodeById(e){return this.doc.findNodeDeep(e)?.node??null}async reloadNodeImage(e){let t=this.findNodeById(e);return t?!!await this.sources.reloadNodeImage(t):!1}async reloadMaskClipImage(e){let t=this.findNodeById(e);return t instanceof ae?!!await this.sources.reloadMaskClipImage(t):!1}getCropInfo(){return this.cropSessionController.info}enterCropMode(e,t){this.pathSessionController.active&&this.pathSessionController.exit();let r=e??this.doc.selection[0];return r?this.cropSessionController.enter(r,t):!1}exitCropMode(){this.cropSessionController.exit()}setCropShape(e){this.cropSessionController.setCropShape(e)}updateCropScale(e){return this.cropSessionController.setScale(e)}setCropAspectRatio(e){this.cropSessionController.setAspectRatio(e)}enterPathEditMode(e){this.cropSessionController.active&&this.cropSessionController.exit(),this.expandSessionController.active&&this.expandSessionController.exit();let t=e??this.doc.selection[0];return t?this.pathSessionController.enter(t):!1}async enterWarpMode(e,t){this.cropSessionController.active&&this.cropSessionController.exit(),this.expandSessionController.active&&this.expandSessionController.exit(),this.pathSessionController.active&&this.pathSessionController.exit();let r=e??this.doc.selection[0];return r?this.warpSessionController.enter(r,t):!1}async loadImage(e,t){try{return await Je(e,t??null)}catch{return null}}async exitWarpMode(e){return this.warpSessionController.exit(e)}warpUndo(){return this.warpSessionController.undo()}warpRedo(){return this.warpSessionController.redo()}exitPathEditMode(){this.pathSessionController.exit()}getPathEditInfo(){return this.pathSessionController.info}setPathAnchorType(e,t,r){return this.pathSessionController.target===e?this.pathSessionController.setAnchorType(t,r):!1}highlightPathAnchor(e,t){this.pathSessionController.target===e&&this.pathSessionController.setActiveAnchor(t)}resetPathAnchorStyles(e){this.pathSessionController.target===e&&this.pathSessionController.resetAnchorStyles()}get rulerEnabled(){return this.rulerVisible}get rulerVisible(){return this.rulerVisibleValue}referenceLineDrag=null;rotateDrag=null;setRulerVisible(e){this.rulerVisibleValue!==e&&(this.rulerVisibleValue=e,this.requestRenderAll())}selectAll(){return Od(this.doc,()=>this.requestRenderAll())}deleteSelection(){return Bd(this.doc,()=>this.requestRenderAll())}nudgeSelection(e,t){return Wd(this.doc,e,t,()=>this.requestRenderAll())}getSelectionInfo(){return Nd(this.doc,this.marquee,this.zoom,(e,t)=>this.toScreen(e,t))}getActiveGroupChildInfo(){return Ld(this.doc)}getSvgRasterInfo(){return Id(this.doc,e=>this.sources.svgRasterFactorOf(e))}toObjects(){return this.doc.toObjects()}playAnimations(){this.animationPlaybackController.play()}pauseAnimations(){this.animationPlaybackController.pause()}stopAnimations(){this.animationPlaybackController.stop()}seekAnimations(e){this.animationPlaybackController.seek(e)}getAnimationPlaybackInfo(){return this.animationPlaybackController.info}getScrollTextPlaybackInfo(){return this.animationPlaybackController.scrollTextInfo}playSingleAnimation(e,t,r){return this.animationPlaybackController.playSingleAnimation(e,t,r)}stopSingleAnimation(e){this.animationPlaybackController.stopSingleAnimation(e)}getSingleAnimationPreviewInfo(){return this.animationPlaybackController.singlePreviewInfo}tickAnimation(e){this.animationPlaybackController.tick(e)&&(this.renderer.frame.animationActive=!0)}setEditingSelection(e,t){this.textEditing.setSelection(e,t)}settleMoveSnap(){this.snapGuide.settleMoveSnap()}finishSnapGesture(){this.snapGuide.finishGesture()}registerScalingSnap(e,t){this.snapGuide.registerScaling(e,t)}startCellEditing(e,t,r,o){return this.tableCellEditing.startEditing(e,t,r,o)}enterTextEditingAtClick(e,t,r){this.textEditing.enterEditingAtClick(e,t,r)}dispose(){this.disposed||(this.disposed=!0,this.cellSelectionSink&&ee.cellSelectionSink===this.cellSelectionSink&&(ee.cellSelectionSink=null),this.rafId!==null&&cancelAnimationFrame(this.rafId),this.renderTimerId!==null&&clearTimeout(this.renderTimerId),this.retainedFrame.dispose(),this.progressiveLoad.dispose(),this.interactions.dispose(),this.tableCellEditing.dispose(),this.cropSessionController.dispose(),this.expandSessionController.dispose(),this.pathSessionController.dispose(),this.textEditing.dispose(),this.bus.clear(),this.sources.releaseAnimatedSources(),this.batch.dispose(),this.meshBatch.dispose(),this.textures.dispose(),this.gradientRamps.dispose(),this.sources.dispose(),this.glyphAtlas.dispose(),this.handle.dispose())}};var Jt=class n{constructor(e=0,t=0){this.x=e;this.y=t}x;y;add(e){return new n(this.x+e.x,this.y+e.y)}subtract(e){return new n(this.x-e.x,this.y-e.y)}scalarDivide(e){return new n(this.x/e,this.y/e)}rotate(e,t={x:0,y:0}){let r=Math.sin(e),o=Math.cos(e),i=this.subtract(t);return new n(i.x*o-i.y*r,i.x*r+i.y*o).add(t)}},Qc=class n{constructor(e=0,t=0){typeof e=="number"?(this.x=e,this.y=t):(this.x=e.x,this.y=e.y)}x=0;y=0;add(e){return new n(this.x+e.x,this.y+e.y)}subtract(e){return new n(this.x-e.x,this.y-e.y)}multiply(e){return new n(this.x*e.x,this.y*e.y)}divide(e){return new n(this.x/e.x,this.y/e.y)}scalarAdd(e){return new n(this.x+e,this.y+e)}scalarSubtract(e){return new n(this.x-e,this.y-e)}scalarMultiply(e){return new n(this.x*e,this.y*e)}scalarDivide(e){return new n(this.x/e,this.y/e)}rotate(e){let t=e*Math.PI/180,r=Math.cos(t),o=Math.sin(t);return new n(this.x*r-this.y*o,this.x*o+this.y*r)}dot(e){return this.x*e.x+this.y*e.y}midPointFrom(e){return new n((this.x+e.x)/2,(this.y+e.y)/2)}static lerp(e,t,r){return new n(e.x+(t.x-e.x)*r,e.y+(t.y-e.y)*r)}lerp(e,t){return new n(this.x+(e.x-this.x)*t,this.y+(e.y-this.y)*t)}eq(e){return this.x===e.x&&this.y===e.y}lt(e){return this.x<e.x&&this.y<e.y}gt(e){return this.x>e.x&&this.y>e.y}lte(e){return this.x<=e.x&&this.y<=e.y}gte(e){return this.x>=e.x&&this.y>=e.y}distanceFrom(e){return Math.hypot(this.x-e.x,this.y-e.y)}clone(){return new n(this.x,this.y)}toString(){return`${this.x} ${this.y}`}transform(e,t=!1){return t?new n(e[0]*this.x+e[2]*this.y,e[1]*this.x+e[3]*this.y):new n(e[0]*this.x+e[2]*this.y+e[4],e[1]*this.x+e[3]*this.y+e[5])}};var en=(n,e=0)=>typeof n=="number"&&Number.isFinite(n)?n:e,YS=n=>({sx:en(n.scaleX,1)||1,sy:en(n.scaleY,1)||1}),kp=n=>{let e=n.pathOffset;return!e||typeof e.x!="number"||typeof e.y!="number"?null:{x:e.x,y:e.y}},US=n=>{let e=Ce(n),t=e?Fe(e):null;return t?{x:(t.left+t.right)/2,y:(t.top+t.bottom)/2}:null},$S=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}},jS=(n,e,t,r)=>`M ${t} 0 L ${n-t} 0 A ${t} ${r} 0 0 1 ${n} ${r} L ${n} ${e-r} A ${t} ${r} 0 0 1 ${n-t} ${e} L ${t} ${e} A ${t} ${r} 0 0 1 0 ${e-r} L 0 ${r} A ${t} ${r} 0 0 1 ${t} 0 Z`,Ap=(n,e)=>`M 0 ${-e} A ${n} ${e} 0 1 1 0 ${e} A ${n} ${e} 0 1 1 0 ${-e} Z`,Zc=n=>{if(n.isTextType)return;let e=n.raw,t=se(e),{sx:r,sy:o}=YS(e);if(t===L.PATH){let a="";if(typeof e.path=="string")a=e.path;else if(Array.isArray(e.path)){let l=[];for(let c of e.path)!Array.isArray(c)||typeof c[0]!="string"||l.push(c.length===1?c[0]:`${c[0]} ${c.slice(1).join(" ")}`);a=l.join(" ")}return a.trim()?{path:a,pathOffset:kp(e)??US(a)??{x:0,y:0}}:void 0}if(t===L.RECT||t===L.FABRICRECT){let a=n.dims.x*r,l=n.dims.y*o;if(!(a>0)||!(l>0))return;let c=it(e,n.dims.x,n.dims.y),u=c?Math.min(c.rx*r,a/2):0,h=c?Math.min(c.ry*o,l/2):0;return{path:u>0||h>0?jS(a,l,u,h):`M 0 0 L ${a} 0 L ${a} ${l} L 0 ${l} Z`,pathOffset:{x:a/2,y:l/2}}}if(t===L.CIRCLE){let a=en(e.radius);return a>0?{path:Ap(a*r,a*o),pathOffset:{x:0,y:0}}:void 0}if(t===L.ELLIPSE){let a=(en(e.rx)||n.dims.x/2)*r,l=(en(e.ry)||n.dims.y/2)*o;return!(a>0)||!(l>0)?void 0:{path:Ap(a,l),pathOffset:{x:0,y:0}}}if(t===L.TRIANGLE){let a=n.dims.x*r,l=n.dims.y*o;return!(a>0)||!(l>0)?void 0:{path:`M ${-a/2} ${l/2} L 0 ${-l/2} L ${a/2} ${l/2} Z`,pathOffset:{x:0,y:0}}}if(t===L.POLYGON||t===L.POLYLINE){let a=Array.isArray(e.points)?e.points:[];return a.length===0?{path:"M 0 0",pathOffset:{x:0,y:0}}:{path:a.map((c,u)=>`${u===0?"M":"L"} ${c.x} ${c.y}`).join(" ")+(t===L.POLYGON?" Z":""),pathOffset:kp(e)??$S(a)??{x:0,y:0}}}if(t===L.LINE){let a=en(e.x1),l=en(e.y1),c=en(e.x2),u=en(e.y2);return{path:`M ${a} ${l} L ${c} ${u}`,pathOffset:{x:0,y:0}}}let i=n.dims.x*r,s=n.dims.y*o;if(!(!(i>0)||!(s>0)))return{path:`M 0 0 L ${i} 0 L ${i} ${s} L 0 ${s} Z`,pathOffset:{x:i/2,y:s/2}}};var Np=n=>{if(!(!n||n.length<8||n.some(e=>typeof e!="number"||!Number.isFinite(e))))return{tl:{x:n[0],y:n[1]},tr:{x:n[2],y:n[3]},br:{x:n[4],y:n[5]},bl:{x:n[6],y:n[7]}}},Lp=n=>{let e=[n.tl,n.tr,n.br,n.bl],t=Math.min(...e.map(s=>s.x)),r=Math.min(...e.map(s=>s.y)),o=Math.max(...e.map(s=>s.x)),i=Math.max(...e.map(s=>s.y));return{minX:t,minY:r,width:Math.max(1,Math.ceil(o-t)),height:Math.max(1,Math.ceil(i-r))}},Ip=(n,e,t)=>({tl:{x:n.tl.x+e,y:n.tl.y+t},tr:{x:n.tr.x+e,y:n.tr.y+t},br:{x:n.br.x+e,y:n.br.y+t},bl:{x:n.bl.x+e,y:n.bl.y+t}}),_p=n=>{let e=n.tr.x+n.bl.x-n.tl.x,t=n.tr.y+n.bl.y-n.tl.y;return Math.abs(e-n.br.x)<.01&&Math.abs(t-n.br.y)<.01},Jc=n=>{let e=n.tl.x-n.tr.x+n.br.x-n.bl.x,t=n.tl.y-n.tr.y+n.br.y-n.bl.y;if(Math.abs(e)<1e-6&&Math.abs(t)<1e-6)return{a:n.tr.x-n.tl.x,b:n.bl.x-n.tl.x,c:n.tl.x,d:n.tr.y-n.tl.y,e:n.bl.y-n.tl.y,f:n.tl.y,g:0,h:0};let r=n.tr.x-n.br.x,o=n.tr.y-n.br.y,i=n.bl.x-n.br.x,s=n.bl.y-n.br.y,a=r*s-i*o;if(Math.abs(a)<1e-6)return;let l=(e*s-i*t)/a,c=(r*t-e*o)/a;return{a:n.tr.x-n.tl.x+l*n.tr.x,b:n.bl.x-n.tl.x+c*n.bl.x,c:n.tl.x,d:n.tr.y-n.tl.y+l*n.tr.y,e:n.bl.y-n.tl.y+c*n.bl.y,f:n.tl.y,g:l,h:c}},$r=(n,e,t)=>{let r=n.g*e+n.h*t+1;return{x:(n.a*e+n.b*t+n.c)/r,y:(n.d*e+n.e*t+n.f)/r}},Dp=n=>{let{a:e,b:t,c:r,d:o,e:i,f:s,g:a,h:l}=n,c=e*(i-s*l)-t*(o-s*a)+r*(o*l-i*a);if(Math.abs(c)<1e-6)return;let u=(i-s*l)/c,h=(r*l-t)/c,d=(t*s-r*i)/c,f=(s*a-o)/c,m=(e-r*a)/c,p=(r*o-e*s)/c,b=(o*l-i*a)/c,x=(t*a-e*l)/c,g=(e*i-t*o)/c;if(!(Math.abs(g)<1e-6))return{a:u/g,b:h/g,c:d/g,d:f/g,e:m/g,f:p/g,g:b/g,h:x/g}};var Fp=32,Op=120,eu=1e-6,VS=()=>{let n=document.createElement("canvas");if(!n||typeof n.getContext>"u")throw new Error("Failed to create `canvas` element");return n},qS=n=>{let e=VS();return e.width=n.width,e.height=n.height,e.getContext("2d",{willReadFrequently:!0})?.drawImage(n,0,0),e},KS=(n,e,t)=>n.toDataURL?.(`image/${e}`,t),QS=n=>new Promise((e,t)=>{let r=new FileReader;r.onload=()=>e(String(r.result)),r.onerror=()=>t(r.error),r.readAsDataURL(n)}),Bp=async(n,e,t)=>{try{let r=await new Promise(o=>n.toBlob(o,`image/${e}`,t));if(r)return await QS(r)}catch{}return KS(n,e,t)},ZS=(n,e,t)=>{let r=Math.max(1,n.width),o=Math.max(1,n.height),i=Math.max(1,Math.round(e)),s=Math.max(1,Math.round(t));if(Math.abs(r-i)<eu&&Math.abs(o-s)<eu)return n;let a=document.createElement("canvas");a.width=i,a.height=s;let l=a.getContext("2d");return l?(l.imageSmoothingEnabled=!0,l.imageSmoothingQuality="high",l.drawImage(n,0,0,r,o,0,0,i,s),a):n},JS=(n,e,t,r,o)=>{let i=Math.max(0,Math.min(e-1,r)),s=Math.max(0,Math.min(t-1,o)),a=Math.floor(i),l=Math.floor(s),c=Math.min(e-1,a+1),u=Math.min(t-1,l+1),h=i-a,d=s-l,f=(l*e+a)*4,m=(l*e+c)*4,p=(u*e+a)*4,b=(u*e+c)*4,x=1-d,g=1-h,y=g*x,v=h*x,S=g*d,w=h*d;return[n[f]*y+n[m]*v+n[p]*S+n[b]*w,n[f+1]*y+n[m+1]*v+n[p+1]*S+n[b+1]*w,n[f+2]*y+n[m+2]*v+n[p+2]*S+n[b+2]*w,n[f+3]*y+n[m+3]*v+n[p+3]*S+n[b+3]*w]},ev=(n,e,t)=>{let r=Jc(t),o=r?Dp(r):void 0;if(!o){Hp(n,e,t,Fp);return}let i=Math.max(1,e.width),s=Math.max(1,e.height),a=e.getContext("2d",{willReadFrequently:!0});if(!a){Hp(n,e,t,Fp);return}let l=a.getImageData(0,0,i,s),c=n.createImageData(n.canvas.width,n.canvas.height),u=c.data;for(let h=0;h<n.canvas.height;h++)for(let d=0;d<n.canvas.width;d++){let f=$r(o,d+.5,h+.5);if(f.x<0||f.x>1||f.y<0||f.y>1)continue;let m=f.x*(i-1),p=f.y*(s-1),b=JS(l.data,i,s,m,p),x=(h*n.canvas.width+d)*4;u[x]=b[0],u[x+1]=b[1],u[x+2]=b[2],u[x+3]=b[3]}n.putImageData(c,0,0)},Wp=(n,e,t,r)=>{let[o,i,s]=t,[a,l,c]=r,u=o.x*(i.y-s.y)+i.x*(s.y-o.y)+s.x*(o.y-i.y);if(Math.abs(u)<eu)return;let h=(a.x*(i.y-s.y)+l.x*(s.y-o.y)+c.x*(o.y-i.y))/u,d=(a.y*(i.y-s.y)+l.y*(s.y-o.y)+c.y*(o.y-i.y))/u,f=(a.x*(s.x-i.x)+l.x*(o.x-s.x)+c.x*(i.x-o.x))/u,m=(a.y*(s.x-i.x)+l.y*(o.x-s.x)+c.y*(i.x-o.x))/u,p=(a.x*(i.x*s.y-s.x*i.y)+l.x*(s.x*o.y-o.x*s.y)+c.x*(o.x*i.y-i.x*o.y))/u,b=(a.y*(i.x*s.y-s.x*i.y)+l.y*(s.x*o.y-o.x*s.y)+c.y*(o.x*i.y-i.x*o.y))/u;n.save(),n.beginPath(),n.moveTo(a.x,a.y),n.lineTo(l.x,l.y),n.lineTo(c.x,c.y),n.closePath(),n.clip(),n.setTransform(h,d,f,m,p,b),n.drawImage(e,0,0),n.restore()},Hp=(n,e,t,r)=>{let o=Jc(t);if(!o){n.drawImage(e,0,0,n.canvas.width,n.canvas.height);return}let i=Math.max(1,e.width),s=Math.max(1,e.height),a=Math.min(Op,Math.max(1,Math.ceil(i/r))),l=Math.min(Op,Math.max(1,Math.ceil(s/r)));for(let c=0;c<l;c++){let u=c/l,h=(c+1)/l,d=u*s,f=h*s;for(let m=0;m<a;m++){let p=m/a,b=(m+1)/a,x=p*i,g=b*i,y=$r(o,p,u),v=$r(o,b,u),S=$r(o,b,h),w=$r(o,p,h);Wp(n,e,[{x,y:d},{x:g,y:d},{x:g,y:f}],[y,v,S]),Wp(n,e,[{x,y:d},{x:g,y:f},{x,y:f}],[y,S,w])}}},tv=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=ZS(n,a,l),u=Np(e?.nonAffineTransform||e?.transform);if(!u){let x=qS(n);return{src:await Bp(x,o,r),width:i,height:s,sourceWidth:a,sourceHeight:l}}let h=Lp(u),d=Ip(u,-h.minX,-h.minY),f=t.objectBounds,m=document.createElement("canvas");m.width=h.width,m.height=h.height;let p=m.getContext("2d");if(!p)throw new Error("无法创建智能对象渲染画布");if(p.imageSmoothingEnabled=!0,p.imageSmoothingQuality="high",_p(d)){let x=(d.tr.x-d.tl.x)/a,g=(d.tr.y-d.tl.y)/a,y=(d.bl.x-d.tl.x)/l,v=(d.bl.y-d.tl.y)/l,S=d.tl.x,w=d.tl.y;p.setTransform(x,g,y,v,S,w),p.drawImage(c,0,0)}else ev(p,c,d);let b;if(f){let x=Math.round(f.left-h.minX),g=Math.round(f.top-h.minY),y=Math.max(1,Math.round(f.width)),v=Math.max(1,Math.round(f.height));if(x>=0&&g>=0&&x+y<=h.width+1&&g+v<=h.height+1){b=document.createElement("canvas"),b.width=y,b.height=v;let w=b.getContext("2d");w&&w.drawImage(m,x,g,y,v,0,0,y,v)}else{b=document.createElement("canvas"),b.width=y,b.height=v;let w=b.getContext("2d");w&&(w.imageSmoothingEnabled=!0,w.imageSmoothingQuality="high",w.drawImage(m,0,0,h.width,h.height,0,0,y,v))}}else b=m;return{src:await Bp(b,o,r),width:b.width,height:b.height,sourceWidth:a,sourceHeight:l}};var ce=n=>n.node instanceof ee?n.node:null,Be=n=>n.raw,Pt=n=>{n.canvas?.requestRenderAll?.()},je=(n,e)=>{let t=Be(e);n.set({cellData:t.cellData??[],rows:t.rows,cols:t.cols}),Pt(n)},tu=n=>n.rows??3,nu=n=>n.cols??3,jr=n=>(Array.isArray(n.cellData)||(n.cellData=[]),n.cellData),Jo=(n,e,t)=>{let r=we(n.cellMap,e,t);if(r)return r.isMerged&&r.mergeParent?we(n.cellMap,r.mergeParent.row,r.mergeParent.col):r},Wt=(n,e)=>{let t=ce(n);if(!t||!t.selectedCells.length)return;let r=new Set;for(let o of t.selectedCells){let i=lt(t.cellMap,o.row,o.col),s=`${i.row},${i.col}`;if(r.has(s))continue;r.add(s);let a=we(t.cellMap,i.row,i.col);a&&e(a)}je(n,t)},ru=(n,e,t)=>({get id(){return`${n.id}-r${e.row}c${e.col}-rect`},get _isCell(){return!0},get _row(){return e.row},get _col(){return e.col},get fill(){return e.fill},set fill(r){e.fill=r,t()},get stroke(){return e.stroke},set stroke(r){e.stroke=r,t()},get strokeWidth(){return e.strokeWidth??1},set strokeWidth(r){e.strokeWidth=r,t()},get _colspan(){return e.colspan??1},set _colspan(r){e.colspan=r,t()},get _rowspan(){return e.rowspan??1},set _rowspan(r){e.rowspan=r,t()},get _isMerged(){return e.isMerged??!1},set _isMerged(r){e.isMerged=r,t()},get _mergeParent(){return e.mergeParent??null},set _mergeParent(r){e.mergeParent=r,t()},get _hasCustomFill(){return e.hasCustomFill??!1},set _hasCustomFill(r){e.hasCustomFill=r,t()},get _hasCustomStroke(){return e.hasCustomStroke??!1},set _hasCustomStroke(r){e.hasCustomStroke=r,t()},set(r){for(let[o,i]of Object.entries(r))o!=="dirty"&&(e[o]=i);t()},get(r){return e[r]}}),Gp=(n,e,t)=>({get id(){return`${n.id}-r${e.row}c${e.col}-text`},get _isCellText(){return!0},get _row(){return e.row},get _col(){return e.col},get text(){return e.text??""},set text(r){e.text=r,t()},get fill(){return e.textFill},set fill(r){e.textFill=r,t()},get fontSize(){return e.fontSize??Be(n).fontSize??14},set fontSize(r){e.fontSize=r,t()},get fontWeight(){return e.fontWeight},set fontWeight(r){e.fontWeight=r,t()},get fontFamily(){return e.fontFamily},set fontFamily(r){e.fontFamily=r,t()},get fontStyle(){return e.fontStyle},set fontStyle(r){e.fontStyle=r,t()},get textAlign(){return e.textAlign},set textAlign(r){e.textAlign=r,t()},get underline(){return e.underline??!1},set underline(r){e.underline=r,t()},get linethrough(){return e.linethrough??!1},set linethrough(r){e.linethrough=r,t()},get verticalAlign(){return e.verticalAlign??"middle"},set verticalAlign(r){e.verticalAlign=r,t()},set(r){for(let[o,i]of Object.entries(r))o!=="dirty"&&(o==="fill"?e.textFill=i:e[o]=i);t()},get(r){return r==="fill"?e.textFill:e[r]},setFontFamily(r){e.fontFamily=r,t()},refreshTextDimensions(){}}),nv={canMergeCells(){let n=ce(this);return!!n&&n.selectedCells.length>1},canUseMergeCells(){let n=ce(this);if(!n||!n.selectedCells.length)return!1;let e=new Set,t=!1;for(let{row:r,col:o}of n.selectedCells){let i=Jo(n,r,o);if(!i)return!1;(i.colspan??1)>1||(i.rowspan??1)>1?e.add(`${i.row},${i.col}`):t=!0}return!t&&e.size===1},canSplitRows(){let n=ce(this);if(!n||!n.selectedCells.length)return!1;let e=n.selectedCells[0],t=Jo(n,e.row,e.col);return!!t&&(t.rowspan??1)>1},canSplitColumns(){let n=ce(this);if(!n||!n.selectedCells.length)return!1;let e=n.selectedCells[0],t=Jo(n,e.row,e.col);return!!t&&(t.colspan??1)>1},isSelectColumn(){let n=ce(this);if(!n||!n.selectedCells.length)return!1;let e=new Set(n.selectedCells.map(r=>r.row)),t=new Set(n.selectedCells.map(r=>r.col));if(t.size===1){let r=Array.from(e),o=Math.min(...r),i=Math.max(...r),s=o===0&&i===tu(Be(n))-1,a=e.size>=2,l=!1;for(let c of n.selectedCells)if((Jo(n,c.row,c.col)?.rowspan??1)>1){l=!0;break}return s||a||l}return t.size>1?e.size===1?!1:e.size<=t.size:!1},isSelectRow(){let n=ce(this);if(!n||!n.selectedCells.length)return!1;let e=new Set(n.selectedCells.map(r=>r.row)),t=new Set(n.selectedCells.map(r=>r.col));if(e.size===1){let r=Array.from(t),o=Math.min(...r),i=Math.max(...r),s=o===0&&i===nu(Be(n))-1,a=t.size>=2,l=!1;for(let c of n.selectedCells)if((Jo(n,c.row,c.col)?.colspan??1)>1){l=!0;break}return s||a||l}return e.size>1?t.size===1?!1:e.size>t.size:!1},isRowSelected(n){let e=ce(this);return e?Rr(e.cellMap,e.selectedCells).rows.has(n):!1},isColumnSelected(n){let e=ce(this);return e?Rr(e.cellMap,e.selectedCells).cols.has(n):!1},selectCell(n,e,t=!1){let r=ce(this);if(r){if(t){if(r.cellAnchor){let o=r.cellAnchor,i=bn(r.cellMap,o,{row:n,col:e});r.setCellSelection(i,o,{r1:Math.min(o.row,n),r2:Math.max(o.row,n),c1:Math.min(o.col,e),c2:Math.max(o.col,e)})}}else{let o={row:n,col:e};r.setCellSelection([o],o,{r1:n,r2:n,c1:e,c2:e})}Pt(this)}},selectColumn(n){let e=ce(this);e&&(e.setColumnSelection(n),Pt(this))},selectRow(n){let e=ce(this);e&&(e.setRowSelection(n),Pt(this))},selectAllCells(){let n=ce(this);if(!n)return;let e=n.tableView,t=wo(n.cellMap,e.rows,e.cols);n.setCellSelection(t,t[0]??null,Xe(t)),Pt(this)},clearCellSelection(){let n=ce(this);n&&(n.clearCellSelection(),Pt(this))},buildSelectionRange(n,e){let t=ce(this);return t?bn(t.cellMap,n,e):[]},mergeCells(n,e,t,r){let o=ce(this);if(!o)return;let i=bo(o.raw,n,e,t,r),s={row:i.r1,col:i.c1};o.setCellSelection([s],s,i),je(this,o)},unmergeCells(n,e){let t=ce(this);if(!t||!xo(t.raw,n,e))return;let r={row:n,col:e};t.setCellSelection([r],r,{r1:n,r2:n,c1:e,c2:e}),je(this,t)},addRow(n){let e=ce(this);e&&(go(e.raw,n??tu(Be(e))),je(this,e))},removeRow(n){let e=ce(this);if(!e)return;let t=n??tu(Be(e))-1;if(!Ml(e.raw,t))return;let r=Yi(e.selectedCells,e.cellRange,t,"row");r?e.setCellSelection(r.cells,r.cells[0]??null,r.range):e.clearCellSelection(),je(this,e)},addColumn(n){let e=ce(this);e&&(yo(e.raw,n??nu(Be(e))),je(this,e))},removeColumn(n){let e=ce(this);if(!e)return;let t=n??nu(Be(e))-1;if(!Rl(e.raw,t))return;let r=Yi(e.selectedCells,e.cellRange,t,"col");r?e.setCellSelection(r.cells,r.cells[0]??null,r.range):e.clearCellSelection(),je(this,e)},setColumnWidth(n,e){let t=ce(this);t&&(mo(t.raw,n,e),this.set({columnWidths:Be(t).columnWidths??[]}),Pt(this))},setRowHeight(n,e){let t=ce(this);t&&(po(t.raw,n,e),this.set({manualRowHeights:Be(t).manualRowHeights??[]}),Pt(this))},setSelectWidth(n){let e=ce(this);if(!e)return;let t=e.cellRange,r=Be(e),o=e.tableView;if(!t||o.cols<=0){this.setTableWidth(n);return}let i=r.minCellWidth??40,s=r.cellStrokeWidth??0,a=0;for(let u=t.c1;u<=t.c2;u++)a+=o.columnWidths[u]??0;if(a<=0)return;let l=(n-s-(t.c2-t.c1)*o.cellSpacing)/a,c=[...o.columnWidths];for(let u=t.c1;u<=t.c2;u++)c[u]=Math.max(i,(c[u]??0)*l);this.set({columnWidths:c}),Pt(this)},setSelectHeight(n){let e=ce(this);if(!e)return;let t=e.cellRange,r=Be(e),o=e.tableView;if(!t||o.rows<=0){this.setTableHeight(n);return}let i=r.minCellHeight??40,s=r.cellStrokeWidth??0,a=0;for(let u=t.r1;u<=t.r2;u++)a+=o.rowHeights[u]??0;if(a<=0)return;let l=(n-s-(t.r2-t.r1)*o.cellSpacing)/a,c=Array.from({length:o.rows},(u,h)=>{let d=Array.isArray(r.manualRowHeights)?r.manualRowHeights[h]:null;return typeof d=="number"?d:null});for(let u=t.r1;u<=t.r2;u++)c[u]=Math.max(i,(o.rowHeights[u]??0)*l);this.set({manualRowHeights:c}),Pt(this)},getColumnWidth(n){let e=ce(this);return e?e.tableView.columnWidths[n]??0:0},getRowHeight(n){let e=ce(this);return e?e.tableView.rowHeights[n]??0:0},getRowMinHeight(n){let e=ce(this);return e?e.getRowMinHeight(n):0},relayout(){let n=ce(this);n&&(n.rebuildTable(),Pt(this))},previewLayout(){this.relayout()},getCell(n,e){let t=ce(this);if(!t)return;let r=we(t.cellMap,n,e);return r?ru(t,r,()=>je(this,t)):void 0},getCellText(n,e){let t=ce(this);if(!t)return;let r=we(t.cellMap,n,e);return r?Gp(t,r,()=>je(this,t)):void 0},setSelectionTextAlign(n){Wt(this,e=>{e.textAlign=n})},setSelectionFontSize(n){Wt(this,e=>{e.fontSize=n})},changeSelectionFontSize(n){let e=ce(this);if(!e)return;let t=Be(e).fontSize??14;Wt(this,r=>{let o=Number(r.fontSize)||t;r.fontSize=n==="+"?o+1:Math.max(1,o-1)})},setSelectionFontWeight(n){Wt(this,e=>{e.fontWeight=n})},setSelectionFontStyle(n){Wt(this,e=>{e.fontStyle=n})},setSelectionUnderline(n){Wt(this,e=>{e.underline=n})},setSelectionLinethrough(n){Wt(this,e=>{e.linethrough=n})},setSelectionCellFill(n){Wt(this,e=>{e.fill=n,e.hasCustomFill=!0})},setSelectionCellStroke(n){Wt(this,e=>{e.stroke=n,e.hasCustomStroke=!0})},setSelectionCellStrokeWidth(n){Wt(this,e=>{e.strokeWidth=n,e.hasCustomStroke=!0})},updateCellFill(n){let e=ce(this);if(!e)return;let t=Be(e);t.cellFill=n;for(let r of jr(t))!r.isMerged&&!r.hasCustomFill&&(r.fill=n);je(this,e)},updateCellTextFill(n){let e=ce(this);if(!e)return;let t=Be(e);t.textFill=n;for(let r of jr(t))r.hasCustomTextFill||(r.textFill=n);je(this,e)},updateCellStroke(n){let e=ce(this);if(!e)return;let t=Be(e);t.cellStroke=n;for(let r of jr(t))r.hasCustomStroke||(r.stroke=n);je(this,e)},updateBorderWidth(n){let e=ce(this);e&&(Be(e).cellStrokeWidth=n,je(this,e))},applyTextStylesToAll(n){let e=ce(this);if(!e)return;let t=Be(e),r={...t.textDefaults??{}};for(let[o,i]of Object.entries(n))r[o]=i;t.textDefaults=r;for(let o of jr(t))for(let[i,s]of Object.entries(n))i==="fill"?o.textFill=s:o[i]=s;je(this,e)}},rv={selectedCells(){let n=ce(this);if(n)return n.selectedCells.map(e=>{let t=we(n.cellMap,e.row,e.col);return t?ru(n,t,()=>je(this,n)):void 0}).filter(e=>e!==void 0)},_selectedCells(){let n=ce(this);return n?n.selectedCells:void 0},_selectionRange(){let n=ce(this);return n?n.cellRange:void 0},hasSelection(){let n=ce(this);return n?n.hasCellSelection:!1},selectionCount(){let n=ce(this);return n?n.selectedCells.length:0},cellTexts(){let n=ce(this);if(!n)return;let e=()=>je(this,n);return jr(Be(n)).map(t=>Gp(n,t,e))},cells(){let n=ce(this);if(!n)return;let e=()=>je(this,n);return jr(Be(n)).map(t=>ru(n,t,e))},columnWidths(){let n=ce(this);return n?[...n.tableView.columnWidths]:void 0},rowHeights(){let n=ce(this);return n?[...n.tableView.rowHeights]:void 0}},ou=n=>{for(let[e,t]of Object.entries(nv))Object.assign(n,{[e]:t});for(let[e,t]of Object.entries(rv))Object.defineProperty(n,e,{get:t,configurable:!0,enumerable:!1})};var iu=(n,e,t)=>{let r=Ge(e);if(!r)return null;let o=Et(n,e,t),i=r==="circle"||(typeof e.curvature=="number"?e.curvature:300)>0,s=o.contentOffsetX-o.width/2,a=o.contentOffsetX+o.width/2,l=o.contentOffsetY-o.height/2,c=o.contentOffsetY+o.height/2,u=n.lines.map(()=>[]);for(let h of o.chars){let d=u[h.line];if(!d)continue;let f={char:h.char,charAngle:i?-h.rotation:-(h.rotation+Math.PI),leftAngle:0,rightAngle:0,charRadius:0,bottomRadius:0,topRadius:0,lineRadius:0,cl:{x:h.x,y:h.y},tl:{x:s,y:l},br:{x:a,y:c},bl:{x:h.x,y:h.y},tr:{x:h.x,y:h.y},nl:{x:h.x,y:h.y},nr:{x:h.x,y:h.y},lc:{x:h.x,y:h.y}};d.push(f)}for(let h of u){let d=h[h.length-1];h.push({char:"",charAngle:0,leftAngle:0,rightAngle:0,charRadius:0,bottomRadius:0,topRadius:0,lineRadius:0,cl:d?{...d.cl}:{x:s,y:l},tl:{x:s,y:l},br:{x:a,y:c},bl:{x:s,y:l},tr:{x:a,y:c},nl:{x:s,y:l},nr:{x:a,y:c},lc:{x:s,y:l}})}return u};var ov=n=>{let e=n.textLines,t=n.charBounds,r=n.lineHeights;if(!Array.isArray(e)||!Array.isArray(t)||!Array.isArray(r)||e.length===0||t.length!==e.length||r.length!==e.length)return!1;for(let o=0;o<e.length;o++)if(typeof e[o]!="string"||!Array.isArray(t[o])||t[o].length===0||typeof r[o]!="number"||!Number.isFinite(r[o]))return!1;return!0},cr=class{node;ctx;constructor(e,t){this.node=e,this.ctx=t}set(e,t){let r=typeof e=="string"?{[e]:t}:{...e},o=r.__isCropping&&this.ctx.cropSessionNodeId?.()!==this.node.id?this.toObject():void 0;if("cropAspectRatio"in r){let s={cropAspectRatio:r.cropAspectRatio};delete r.cropAspectRatio,this.ctx.setNodeProps(this.node,s)}if("_cropKey"in r){let s=r._cropKey;delete r._cropKey,this.ctx.applyCropShape?.(this.node,typeof s=="string"&&s?s:null)}if("__isCropping"in r){let s=!!r.__isCropping;delete r.__isCropping,this.clearSessionFlagDirty("__isCropping"),this.__isCropping=s,o&&this.__isCropping&&(this.cropBeforeState=o)}if("__isExpand"in r){let s=!!r.__isExpand;delete r.__isExpand,this.clearSessionFlagDirty("__isExpand"),this.__isExpand=s}if(typeof r.width=="number"&&Dr(this.node)){let s=r.width;delete r.width,this.ctx.setGroupWidth?this.ctx.setGroupWidth(this.node,s):this.ctx.setNodeProps(this.node,{width:s})}this.bumpTextboxWidthToLayoutBox(r),this.bridgeImageSizeProps(r);let i=r;if((typeof r.width=="number"||typeof r.height=="number"||typeof r.scaleX=="number"||typeof r.scaleY=="number")&&!("clipImage"in r)&&ot.has(se(this.node.raw))){let s=Ht(this.node),a=this.node.raw,l=Number(a.width)||0,c=Number(a.height)||0,u=this.node.clipImageEl,h=u?.naturalWidth||Number(s?.width)||0,d=u?.naturalHeight||Number(s?.height)||0;if(s&&l>0&&c>0&&h>0&&d>0){typeof r.scaleX=="number"&&r.scaleX>0&&!("width"in r)&&(r.width=l*r.scaleX,r.scaleX=1),typeof r.scaleY=="number"&&r.scaleY>0&&!("height"in r)&&(r.height=c*r.scaleY,r.scaleY=1);let f=typeof r.width=="number"?r.width:l,m=typeof r.height=="number"?r.height:c;if(f>0&&m>0){let p=(g,y)=>Math.max(g/h,y/d),b=Number(s.scaleX)||1,x=p(f,m)*(b/p(l,c));i={...r,clipImage:{...s,scaleX:x,scaleY:x}}}}}return Object.keys(i).length>0&&this.ctx.setNodeProps(this.node,i),this}bumpTextboxWidthToLayoutBox(e){if(typeof e.width!="number"||!(this.node instanceof Se)||e.width<0||se(this.node.raw)!==L.TEXTBOX||Ge(this.node.raw))return;let r=e.width;delete e.width,this.ctx.setNodeProps(this.node,{width:r});let o=this.node.dims.x;Number.isFinite(o)&&o>r+.01&&this.ctx.setNodeProps(this.node,{width:o})}clearSessionFlagDirty(e){this.node.raw[e]!==void 0&&this.ctx.setNodeProps(this.node,{[e]:void 0})}get(e){return this.node.raw[e]}setCoords(){}getCenterPoint(){return{...this.node.center}}getRelativeCenterPoint(){return new Jt(this.node.center.x,this.node.center.y)}translateToOriginPoint(e,t="center",r="center"){let o=u=>u==="left"||u==="top"?-.5:u==="right"||u==="bottom"?.5:0,i=o(t),s=o(r),a=i||s?this._getTransformedDimensions():new Jt(0,0),l=new Jt(e.x+i*a.x,e.y+s*a.y),c=this.node.raw.angle;return typeof c=="number"&&c&&(l=l.rotate(c*Math.PI/180,e)),l}toPath(){let e=this.ctx.getTextGlyphPath?.(this.node);return e||Zc(this.node)}toPathDecorations(){return this.ctx.getTextDecorations?.(this.node)??[]}toPathEffectLayers(e){return[]}_getTransformedDimensions(){let e=this.node.raw;return new Jt(this.node.dims.x*(e.scaleX??1),this.node.dims.y*(e.scaleY??1))}getBoundingRect(){let e=this.node.bounds;return{left:e.left,top:e.top,width:e.right-e.left,height:e.bottom-e.top}}getInkRect(){let e=Bn(this.node.inkACoords);return{left:e.left,top:e.top,width:e.width,height:e.height}}get aCoords(){return this.node.aCoords}getCoords(){let e=this.node.aCoords;return[e.tl,e.tr,e.br,e.bl]}calcOCoords(){let e=this.ctx.getViewportTransform?.()??[1,0,0,1,0,0],t=o=>({x:e[0]*o.x+e[2]*o.y+e[4],y:e[1]*o.x+e[3]*o.y+e[5]}),r=this.node.aCoords;return{tl:t(r.tl),tr:t(r.tr),br:t(r.br),bl:t(r.bl)}}rotate(e){let{angle:t,left:r,top:o}=this.node.rotateAroundCenter(e);return this.set({angle:t,left:r,top:o})}setPositionByOrigin(e,t,r){let o=this.node.raw,i=typeof o.scaleX=="number"?o.scaleX:1,s=typeof o.scaleY=="number"?o.scaleY:1,a=this.node.dims.x*i,l=this.node.dims.y*s,c=t==="center"?0:t==="right"?.5:-.5,u=r==="center"?0:r==="bottom"?.5:-.5,h=c*a,d=u*l,f=(typeof o.angle=="number"?o.angle:0)*Math.PI/180,m=Math.cos(f),p=Math.sin(f),b={x:e.x-(h*m-d*p),y:e.y-(h*p+d*m)},x=xe({...o},b);return this.set({left:x.x,top:x.y})}scale(e){let t=this.node.raw;return this.set({scaleX:(t.scaleX??1)*e,scaleY:(t.scaleY??1)*e})}getScaledWidth(){return this.node.dims.x*(this.node.raw.scaleX??1)}getScaledHeight(){return this.node.dims.y*(this.node.raw.scaleY??1)}getObjectScaling(){let e=this.node.raw;return{scaleX:e.scaleX??1,scaleY:e.scaleY??1}}get getObjects(){if(this.node instanceof J)return()=>this.node.children.map(e=>this.ctx.wrapNode(e))}get _objects(){if(this.node instanceof J)return this.node.children.map(e=>this.ctx.wrapNode(e))}get ref(){return this}get isImageLikeNode(){let e=se(this.node.raw);return dt.has(e)||ot.has(e)||e===L.GIF||e===L.VIDEO}get getSrc(){if(this.isImageLikeNode)return()=>{let e=this.node.raw;return typeof e.originalSrc=="string"&&e.originalSrc?e.originalSrc:typeof e.src=="string"?e.src:""}}get getRealSrc(){let e=this.getSrc;if(e)return()=>e()}get replaceSrc(){if(this.isImageLikeNode)return async e=>(this.set({src:e,crossOrigin:"anonymous",originalSrc:e}),await this.ctx.reloadNodeImage?.(this.node),this)}get setElement(){if(this.isImageLikeNode)return(e,t)=>(this.node.imageEl=e,t&&this.set(t),this)}get getElement(){if(!this.isImageLikeNode)return;let e=this.node;return e instanceof ie?()=>e.paintSource??e.imageEl:()=>e.imageEl}get _element(){if(this.isImageLikeNode)return this.node.imageEl}get clipImage(){return Ht(this.node)?sv(this.node,this.ctx):void 0}set clipImage(e){let t=e&&typeof e=="object"&&typeof e.toObject=="function"?e.toObject(this.serializationProps()):e;this.ctx.setNodeProps(this.node,{clipImage:t})}getWidthHeight(e=!1){let t=this._getTransformedDimensions(),r=(this.node.raw.strokeWidth??0)||0;return{x:t.x-r,y:t.y-r}}getWidth(){return this.getWidthHeight().x}getHeight(){return this.getWidthHeight().y}sourceNaturalSize(){let e=this.node.imageEl;if(e)return{width:e.naturalWidth||e.width||0,height:e.naturalHeight||e.height||0};if(this.node instanceof ie){let t=this.node.paintSource;if(t)return{width:("videoWidth"in t?t.videoWidth:t.width)||t.width||0,height:("videoHeight"in t?t.videoHeight:t.height)||t.height||0}}return{width:0,height:0}}getOriginalElementWidth(){return this.sourceNaturalSize().width}getOriginalElementHeight(){return this.sourceNaturalSize().height}getElementWidth(){return this.sourceNaturalSize().width}getElementHeight(){return this.sourceNaturalSize().height}cropOffset(){if(!this.isImageLikeNode)return{x:0,y:0};let e=this.node.raw;return e.cropSizeMode==="visible"?{x:0,y:0}:{x:Number(e.cropX)||0,y:Number(e.cropY)||0}}get left(){return this.node.raw.left??0}set left(e){this.set({left:e})}get top(){return this.node.raw.top??0}set top(e){this.set({top:e})}get scaleX(){return this.node.raw.scaleX??1}set scaleX(e){this.set({scaleX:e})}get scaleY(){return this.node.raw.scaleY??1}set scaleY(e){this.set({scaleY:e})}get angle(){return this.node.raw.angle??0}set angle(e){this.set({angle:e})}get skewX(){return this.node.raw.skewX??0}set skewX(e){this.set({skewX:e})}get skewY(){return this.node.raw.skewY??0}set skewY(e){this.set({skewY:e})}get flipX(){return this.node.raw.flipX??!1}set flipX(e){this.set({flipX:e})}get flipY(){return this.node.raw.flipY??!1}set flipY(e){this.set({flipY:e})}get originX(){return this.node.raw.originX??"left"}set originX(e){this.set({originX:e})}get originY(){return this.node.raw.originY??"top"}set originY(e){this.set({originY:e})}get width(){return(this.node.raw.width??0)-this.cropOffset().x}set width(e){if(Dr(this.node)){if(this.ctx.setGroupWidth){this.ctx.setGroupWidth(this.node,e);return}this.ctx.setNodeProps(this.node,{width:e});return}let t=this.cropOffset();this.ctx.setNodeProps(this.node,{width:e+t.x})}get height(){return(this.node.raw.height??0)-this.cropOffset().y}set height(e){let t=this.cropOffset();this.ctx.setNodeProps(this.node,{height:e+t.y})}bridgeImageSizeProps(e){if(!this.isImageLikeNode)return;let t=this.node.raw;if(t.cropSizeMode==="visible")return;let r=typeof e.cropX=="number"?e.cropX:Number(t.cropX)||0,o=typeof e.cropY=="number"?e.cropY:Number(t.cropY)||0;typeof e.width=="number"&&r>0&&(e.width=e.width+r),typeof e.height=="number"&&o>0&&(e.height=e.height+o)}cropBeforeState;get __isCropping(){return this.isImageLikeNode&&this.ctx.cropSessionNodeId?.()===this.node.id}set __isCropping(e){if(this.isImageLikeNode)if(e){let t=this.ctx.cropSessionNodeId?.()!==this.node.id;if(t&&(this.cropBeforeState=this.toObject()),!this.ctx.enterCropSession?.(this.node)){t&&(this.cropBeforeState=void 0);return}let r=this.node.raw.cropAspectRatio;typeof r=="number"&&r>0&&this.ctx.setCropSessionAspectRatio?.(r)}else this.ctx.exitCropSession?.(this.node),this.cropBeforeState=void 0}get __isExpand(){return this.isImageLikeNode&&this.ctx.expandSessionNodeId?.()===this.node.id}set __isExpand(e){this.isImageLikeNode&&(e?this.ctx.enterExpandSession?.(this.node):this.ctx.exitExpandSession?.(this.node))}get beforeState(){return this.cropBeforeState}onDeselectEvent(){this.ctx.exitCropSession?.(this.node),this.ctx.exitExpandSession?.(this.node),this.cropBeforeState=void 0}expandOffsetOf(e){let t=this.ctx.expandSessionOffsets?.(this.node);if(t)return t[e];let r=e==="left"?"Left":e==="right"?"Right":e==="top"?"Top":"Bottom",o=this.node.raw[`expand${r}Offset`];return typeof o=="number"?o:void 0}get expandLeftOffset(){return this.isImageLikeNode?this.expandOffsetOf("left"):void 0}get expandRightOffset(){return this.isImageLikeNode?this.expandOffsetOf("right"):void 0}get expandTopOffset(){return this.isImageLikeNode?this.expandOffsetOf("top"):void 0}get expandBottomOffset(){return this.isImageLikeNode?this.expandOffsetOf("bottom"):void 0}setExpandOffset(){let e=this.ctx.expandSessionOffsets?.(this.node);e&&this.set({expandLeftOffset:e.left,expandRightOffset:e.right,expandTopOffset:e.top,expandBottomOffset:e.bottom})}updateCropScale(e){if(!this.__isCropping||!(e>0)||!Number.isFinite(e))return!1;if(this.ctx.updateCropSessionScale)return this.ctx.updateCropSessionScale(e);let t=this.node.imageEl;if(!t)return!1;let r=this.node.raw,o=t.naturalWidth||t.width,i=t.naturalHeight||t.height,s=r.scaleX??1,a=e/s,l=e/(r.scaleY??1),c=this.width,u=this.height,h=c/a,d=u/l,f=(r.cropX??0)+c/2-h/2,m=(r.cropY??0)+u/2-d/2;return h<Math.min(8,o)||d<Math.min(8,i)||f<0||m<0||f+h>o||m+d>i?!1:(this.set({cropScale:e,scaleX:e,scaleY:e,width:h,height:d,cropX:f,cropY:m}),!0)}getMaxEffectPadding(){let e=this.node.raw,t=0,r=e.effects??{},o=u=>(u??[]).filter(h=>h.enabled&&h.showInDialog),i=o(r.solidFill);i.length>0&&(t=Math.max(t,i.reduce((u,h)=>Math.max(u,Math.abs(Number(h.offsetX)||0),Math.abs(Number(h.offsetY)||0)),0)));let s=o(r.dropShadow);s.length>0&&(t=Math.max(t,s.reduce((u,h)=>{let d=(Number(h.blur)||0)*2;return Math.max(u,Math.abs(Number(h.offsetX)||0)+d,Math.abs(Number(h.offsetY)||0)+d)},0)));let a=o(r.stroke);a.length>0&&(t=Math.max(t,a.reduce((u,h)=>{let d=h.size,f=Number(h.strokeWidth)||Number(d?.value)||0;return Math.max(u,f+Math.abs(Number(h.offsetX)||0),f+Math.abs(Number(h.offsetY)||0))},0)));let l=e.shadow;if(l){let u=(Number(l.blur)||0)*2;t=Math.max(t,Math.abs(Number(l.offsetX)||0)+u,Math.abs(Number(l.offsetY)||0)+u)}let c=Number(e.strokeWidth)||0;if(e.stroke&&c){let u=e.strokeAlignment==="outside"?c*2:c;t=Math.max(t,u)}return t}isType(...e){let t=se(this.node.raw);return e.some(r=>r.toLowerCase()===t)}getStyleAtPosition(e){if(!(this.node instanceof Se))return{};let t=typeof this.node.raw.text=="string"?this.node.raw.text:"";if(e<0||e>=t.length)return{};let r=e,o=t.split(`
|
|
1092
1092
|
`);for(let i=0;i<o.length;i++){if(r<=o[i].length)return this.objectStyles()?.[i]?.[r]??{};r-=o[i].length+1}return{}}calcTransformMatrix(){return[...this.node.matrix]}setTableWidth(e){if(!(this.node instanceof ee))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 ee))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(`
|
|
1093
1093
|
`);for(let i=0;i<o.length;i++){if(r<=o[i].length)return{line:i,char:r};r-=o[i].length+1}return{line:Math.max(0,o.length-1),char:o[o.length-1]?.length??0}}stylesToEngineForm(e,t){return e}stylesToPersistForm(e,t){return e}serializationProps(){}stylesMap(){let e=this.node.raw;return Array.isArray(e.styles)&&(e.styles=this.stylesToEngineForm(e.styles,typeof e.text=="string"?e.text:"")??{}),e.styles||(e.styles={}),e.styles}objectStyles(){let e=this.node.raw;return Array.isArray(e.styles)&&(e.styles=this.stylesToEngineForm(e.styles,typeof e.text=="string"?e.text:"")??{}),e.styles}get selectionStart(){return this.ctx.getNodeSelectionRange?.(this.node)?.start??0}get selectionEnd(){return this.ctx.getNodeSelectionRange?.(this.node)?.end??0}cleanStyle(e){let t=this.node.raw,r=this.objectStyles();if(!r)return!1;let o=0,i,s,a=!0,l=0;for(let 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(`
|
|
1094
1094
|
`))l+=c.length;return a&&o===l&&o>0&&s!==void 0?(this.set({[e]:s}),this.removeStyle?.(e),!0):(o>0&&this.set({styles:t.styles}),!1)}removeStyle(e){let t=this.objectStyles();if(t){for(let r in t){let o=t[r];for(let i in o)delete o[i][e],Object.keys(o[i]).length===0&&delete o[i];Object.keys(o).length===0&&delete t[r]}this.set({styles:t})}}setSelectionStyles(e,t,r){if(!(this.node instanceof Se))return;let o=this.ctx.getNodeSelectionRange?.(this.node),i=t??o?.start??0,s=r??o?.end??0;if(s<=i)return;let a=this.stylesMap();for(let l=i;l<s;l++){let{line:c,char:u}=this.cursor2D(l);a[c]||(a[c]={});let d={...a[c][u]??{}};for(let f of Object.keys(e))e[f]!==void 0&&(d[f]=e[f]);a[c][u]=d}this.set({styles:this.stylesMap()})}getSelectionStyles(e,t){if(!(this.node instanceof Se))return[];let r=this.ctx.getNodeSelectionRange?.(this.node),o=e??r?.start??0,i=t??r?.end??o,s=[];for(let a=o;a<i;a++)s.push(this.getStyleAtPosition(a));return s}setFontFamily(e,t){this.set({fontFamily:e})}get fontFamily(){return String(this.node.raw.fontFamily??"")}get type(){return String(this.node.raw.type??"")}initDimensions(){}calcTextWidth(){return this.node instanceof Se?this.node.textLayout.lines.reduce((e,t)=>Math.max(e,t.width),0):0}refreshTextDimensions(){}replaceFontFamily(e,t){let r=this.node.raw,o=!1;if(r.fontFamily===e&&(this.set({fontFamily:t}),o=!0),r.styles){for(let i of Object.values(r.styles))if(i)for(let s of Object.values(i))s?.fontFamily===e&&(s.fontFamily=t,o=!0);o&&this.set({styles:r.styles})}return o}get rawTypeLower(){return se(this.node.raw)}get transformKind(){return Ke(this.node.raw)}get setRadius(){if(this.transformKind==="arc")return e=>this.set({curvature:e})}get setWarpStrength(){let e=this.transformKind;if(!(e!=="arch"&&e!=="waist"&&e!=="flag"))return t=>this.set({warpStrength:Math.max(-1,Math.min(1,t))})}get clearCache(){let e=this.transformKind;if(!(e!=="arch"&&e!=="waist"&&e!=="flag"))return()=>{this.ctx.invalidateNodeBakes?.(this.node),this.ctx.getCanvas?.()?.requestRenderAll?.()}}get setCircleParams(){if(this.transformKind==="circle")return e=>this.set(e)}get setTexts(){if(this.node instanceof Se)return e=>this.set({texts:e})}get texts(){if(!(this.node instanceof Se))return;let e=this.node.raw.texts;return Array.isArray(e)?e:[]}toObject(e){let t={...this.node.toObject()};if(this.isImageLikeNode){let r=this.sourceNaturalSize();t.width===void 0&&r.width>0&&(t.width=r.width),t.height===void 0&&r.height>0&&(t.height=r.height)}if(this.node instanceof Se){let r=this.node.textLayout,o=this.node.textStyle.lineHeight??1.16,i=iu(r,this.node.raw,o);i&&(t.charTransformations=i),r.lines.length>0&&!ov(t)&&(t.textLines=r.lines.map(a=>a.graphemes.join("")),t.charBounds=r.lines.map(a=>{let l=a.boxes.map(c=>({left:c.left,width:c.width,kernedWidth:c.kernedWidth,height:c.height}));if(l.length>0){let c=l.reduce((u,h)=>u+(h.kernedWidth||0),0);l.push({left:c,width:0,kernedWidth:0,height:l[l.length-1].height})}return l}),t.lineHeights=r.lines.map(a=>a.implHeight*o));let s=this.node.raw;t.styles=this.stylesToPersistForm(t.styles,typeof s.text=="string"?s.text:"")}if(e?.length){let r=this.node.raw,o=t;for(let i of e)o[i]===void 0&&r[i]!==void 0&&(o[i]=r[i])}return t}get id(){return this.node.id}get canvas(){return this.ctx.getCanvas?.()}get group(){let e=this.ctx.getCanvas?.(),t=au(e?.document,this.node);return t?this.ctx.wrapNode(t):void 0}get topGroup(){let e=this.ctx.getCanvas?.(),t,r=this.node;for(;;){let o=au(e?.document,r);if(!o)break;t=o,r=o}return t?this.ctx.wrapNode(t):void 0}get parent(){return this.group}get applyMaskParams(){if(this.node instanceof le)return e=>{this.node.applyMaskParams(e),this.ctx.getCanvas?.()?.requestRenderAll?.()}}get updateGapParams(){if(this.node instanceof le)return e=>{this.node.updateGapParams(e),this.ctx.getCanvas?.()?.requestRenderAll?.()}}get updateLayout(){if(this.node instanceof le)return e=>{this.node.updateLayout(e),this.ctx.getCanvas?.()?.requestRenderAll?.()}}get visible(){return this.node.visible}set visible(e){this.set({visible:e})}get opacity(){let e=this.node.raw.opacity;return typeof e=="number"?e:1}set opacity(e){this.set({opacity:e})}get strokeWidth(){let e=this.node.raw.strokeWidth;return typeof e=="number"?e:1}set strokeWidth(e){this.set({strokeWidth:e})}_createCacheCanvas(){}_removeCacheCanvas(){}get isEditing(){return this.ctx.isEditingNode(this.node)}enterEditing(){return this.node.isTextType&&this.ctx.enterNodeEditing(this.node),this}exitEditing(){return this.ctx.exitEditing(),this}bringToFront(){this.ctx.bringToFront(this.node)}sendToBack(){this.ctx.sendToBack(this.node)}bringForward(){this.ctx.bringForward(this.node)}sendBackwards(){this.ctx.sendBackwards(this.node)}moveTo(e){this.ctx.moveNodeTo(this.node,e)}remove(){this.ctx.removeNode(this.node)}get changeControls(){if(Dt(this.node))return(e,t=!0)=>{this.ctx.changeNodeControls(this.node,e)}}get isEditingPath(){return this.ctx.isPathEditingNode(this.node)}get setAnchorPointType(){if(Dt(this.node)==="path")return(e,t)=>this.ctx.setNodeAnchorType(this.node,e,t)}get getActiveAnchorKey(){if(Dt(this.node))return()=>this.ctx.getNodePathEditInfo(this.node)?.activeAnchorKey}get getActiveAnchorIndex(){if(Dt(this.node))return()=>this.ctx.getNodePathEditInfo(this.node)?.activeAnchorIndex}get getAnchorPointStyleByIndex(){if(Dt(this.node)==="path")return e=>Pc(Ce(this.node.raw.path),e)}get highlightAnchor(){if(Dt(this.node))return e=>{this.ctx.highlightNodeAnchor(this.node,e)}}get resetAnchorStyles(){if(Dt(this.node))return()=>{this.ctx.resetNodeAnchorStyles(this.node)}}},Ht=n=>{let e=n.raw;if(!ot.has(se(e)))return null;let t=e.clipImage;return!t||typeof t!="object"||typeof t.src!="string"?null:t},iv=new Set(["_cacheCanvas","dirty","canvas"]),su=class{constructor(e,t){this.node=e;this.ctx=t}node;ctx;set(e){let t=Ht(this.node);if(!t)return this;let r={...t};for(let[o,i]of Object.entries(e))iv.has(o)||(r[o]=i);return this.ctx.setNodeProps(this.node,{clipImage:r}),this}toObject(e){let t=Ht(this.node);return t?{...t}:{}}setCoords(){}getSrc(){let e=Ht(this.node);return e&&typeof e.originalSrc=="string"&&e.originalSrc?e.originalSrc:e&&typeof e.src=="string"?e.src:""}get replaceSrc(){if(Ht(this.node))return async e=>(this.set({src:e,crossOrigin:"anonymous",originalSrc:e}),await this.ctx.reloadMaskClipImage?.(this.node),this)}getRelativeCenterPoint(){let e=Ht(this.node),t=a=>typeof a=="number"?a:0,r=a=>typeof a=="number"?a:1,o=a=>a==="center"?.5:a==="right"||a==="bottom"?1:0,i=t(e?.width)*r(e?.scaleX),s=t(e?.height)*r(e?.scaleY);return new Jt(t(e?.left)+(.5-o(e?.originX))*i,t(e?.top)+(.5-o(e?.originY))*s)}getOriginalElementWidth(){let e=this.node.clipImageEl;return e?.naturalWidth||e?.width||Number(Ht(this.node)?.width)||0}getOriginalElementHeight(){let e=this.node.clipImageEl;return e?.naturalHeight||e?.height||Number(Ht(this.node)?.height)||0}},au=(n,e)=>{if(!n)return;let t=r=>{for(let o of r){if(!(o instanceof J))continue;if(o.children.some(s=>s===e))return o;let i=t(o.children);if(i)return i}};return t(n.nodes)},sv=(n,e)=>{let t=new su(n,e);return new Proxy(t,{get(r,o,i){if(typeof o=="symbol")return Reflect.get(r,o,i);if(o==="then")return;if(o in r)return Reflect.get(r,o,i);let s=Ht(r.node);return s?s[o]:void 0},set(r,o,i,s){return typeof o=="symbol"||o in r?(Reflect.set(r,o,i,s),!0):(r.set({[o]:i}),!0)}})};ou(cr.prototype);var av=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}}},lv=(n,e)=>{let t=new cr(n,e);return n instanceof Pr&&(t._calcDimensions=()=>av(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 cv=(n,e)=>{n.onWarpHistoryChange=(r,o)=>{e.setWarpUndoable(r),e.setWarpRedoable(o)};let t=()=>{let r=n.warpSession;e.setWarpUndoable(r?.undoable??!1),e.setWarpRedoable(r?.redoable??!1)};return{active:()=>!!n.warpSession,async enter(r){let o=r instanceof cr?r.node:r?.node;if(!o)return!1;let i=await n.enterWarpMode(o);return t(),i},undo(){let r=n.warpUndo();return t(),r},redo(){let r=n.warpRedo();return t(),r},async exit(r){let o=await n.exitWarpMode(r).then(i=>!!i?.committed);return t(),o}}};var Jp=new Set([L.ELLIPSE,L.CIRCLE]),uv=new Set([L.TRIANGLE]),uu=new Set([L.POLYGON]),eb=new Set([L.POLYLINE]),zp=new Set([L.ARROW]),hv=new Set([L.DIMENSION]),dv=new Set([L.GROUP,L.PUZZLE]),Yp=new Set([...dt,L.GIF]),Up=new Set([L.TABLE]),lu=new Set(["multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"]),fv=n=>{if(!(Number(n.warpStrength)||0))return null;let t=Ke(n);return t==="arch"||t==="waist"||t==="flag"?t:null},cu=n=>{let e=n.effects;return!!e&&typeof e=="object"&&!Array.isArray(e)},mv=n=>typeof n.textBackgroundColor=="string"&&n.textBackgroundColor?!0:Array.isArray(n.texts)&&n.texts.length>0,pv=new Set(["rect","Rect","fabricrect","ellipse","Ellipse","circle","Circle","polygon","Polygon","polyline","Polyline","Path","path"]),bv=.222,K=(n,e,t)=>{let r=n[e];if(typeof r=="number")return Number.isFinite(r)?r:t;if(typeof r=="string"&&r.trim()!==""){let o=Number(r.trim());if(Number.isFinite(o))return o}return t},Ie=(n,e)=>{let t=n[e];return typeof t=="string"?t:void 0},N=n=>{let e=Math.round(n*1e4)/1e4;return Object.is(e,-0)?"0":String(e)},ne=n=>n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"),xv=/^(#[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=>xv.test(n.trim())?n.trim():null,In=n=>n==null||n===""||n==="transparent"||n==="rgba(0,0,0,0)"||n==="none",hu=n=>`matrix(${n.map(N).join(",")})`,gv=(n,e)=>[1,0,0,1,n,e],$p=n=>n,jp=(n,e,t)=>On({...n,width:e,height:t}),tn=n=>{let e=n.shadow;if(!e)return null;if(typeof e!="object"||Array.isArray(e))return;let t=e,r=typeof t.color=="string"?t.color:"rgb(0,0,0)";if(nn(r))return{color:r,blur:typeof t.blur=="number"&&Number.isFinite(t.blur)?t.blur:0,offsetX:typeof t.offsetX=="number"&&Number.isFinite(t.offsetX)?t.offsetX:0,offsetY:typeof t.offsetY=="number"&&Number.isFinite(t.offsetY)?t.offsetY:0}},Vp=(n,e)=>{let t=n.pathOffset,r=0,o=0;return t&&typeof t=="object"?(typeof t.x=="number"&&Number.isFinite(t.x)&&(r=t.x),typeof t.y=="number"&&Number.isFinite(t.y)&&(o=t.y)):e&&(r=e.x,o=e.y),r||o?gv(-r,-o):null},yv=n=>{let e=Fe(n);return e?{x:(e.left+e.right)/2,y:(e.top+e.bottom)/2}:null},Sv=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}},vv=n=>n.map(e=>e.length===1?e[0]:`${e[0]} ${e.slice(1).map(t=>N(Number(t))).join(" ")}`).join(" "),qp=(n,e,t)=>{let r=se(n);if(Xn.has(r)){let o=Math.min(K(n,"rx",0),e/2),i=Math.min(K(n,"ry",0),t/2),s=o>0||i>0?` rx="${N(o)}" ry="${N(i>0?i:o)}"`:"";return{open:`<rect x="${N(-e/2)}" y="${N(-t/2)}" width="${N(e)}" height="${N(t)}"${s}`,internalTransform:null}}if(Jp.has(r))return{open:`<ellipse cx="0" cy="0" rx="${N(e/2)}" ry="${N(t/2)}"`,internalTransform:null};if(uv.has(r))return{open:`<polygon points="${N(-e/2)},${N(t/2)} 0,${N(-t/2)} ${N(e/2)},${N(t/2)}"`,internalTransform:null};if(r===L.PATH){let o=Ce(n.path);return o?{open:`<path d="${ne(vv(o))}"`,internalTransform:Vp(n,yv(o))}:null}if(uu.has(r)||eb.has(r)){let o=n.points;if(!Array.isArray(o)||o.length===0)return null;let i=[];for(let l of o){let c=l,u=typeof c.x=="number"?c.x:NaN,h=typeof c.y=="number"?c.y:NaN;Number.isFinite(u)&&Number.isFinite(h)&&i.push({x:u,y:h})}if(!i.length)return null;let s=i.map(l=>`${N(l.x)},${N(l.y)}`);return{open:`<${uu.has(r)?"polygon":"polyline"} points="${s.join(" ")}"`,internalTransform:Vp(n,Sv(i))}}return ft.has(r)?{open:`<line x1="${N(K(n,"x1",0))}" y1="${N(K(n,"y1",0))}" x2="${N(K(n,"x2",0))}" y2="${N(K(n,"y2",0))}"`,internalTransform:null}:null},Kp=(n,e,t)=>{let r=e&&n.internalTransform?$(e,n.internalTransform):e??n.internalTransform;return`${n.open}${r?` transform="${hu(r)}"`:""}${t}/>`},wv=(n,e,t)=>{let r="";if(e!==null){r+=` fill="${ne(e)}"`;let o=Ie(n,"fillRule");o&&(r+=` fill-rule="${ne(o)}"`)}else r+=' fill="none"';if(t!==null){r+=` stroke="${ne(t)}"`,r+=` stroke-width="${N(K(n,"strokeWidth",1))}"`;let o=n.strokeDashArray;if(Array.isArray(o)&&o.length>0){let l=o.map(c=>typeof c=="number"&&Number.isFinite(c)?N(c):null).filter(c=>c!==null);l.length&&(r+=` stroke-dasharray="${l.join(",")}"`)}let i=Ie(n,"strokeLineCap");i&&(r+=` stroke-linecap="${ne(i)}"`);let s=Ie(n,"strokeLineJoin");s&&(r+=` stroke-linejoin="${ne(s)}"`);let a=n.strokeMiterLimit;typeof a=="number"&&Number.isFinite(a)&&(r+=` stroke-miterlimit="${N(a)}"`),n.strokeUniform===!0&&(r+=' vector-effect="non-scaling-stroke"'),Ie(n,"paintFirst")==="stroke"&&(r+=' paint-order="stroke"')}return r},Tv=n=>!In(n.stroke)&&K(n,"strokeWidth",1)>0,Qp=n=>{let e=new Map;return(t,r)=>{let o=/([\d.]+)px\s+([\s\S]+)$/.exec(t);if(!o)return 0;let i=Number(o[1]),s=o[2].replace(/^["']+|["']+$/g,""),a=`${s}|${i}|${r}`,l=e.get(a);if(l!==void 0)return l;let c=n.getFont(s)??n.getSubsetFont?.(s,r[0]??"")??null,u=c&&typeof c.getAdvanceWidth=="function"?c.getAdvanceWidth(r,i):0;return e.set(a,u),u}},Ev=(n,e)=>{let t=0;for(let r of n)t+=r.charCodeAt(0)>255?1:.55;return t*e},tb=n=>{let e=n.textLines,t=n.charBounds,r=n.lineHeights;if(!Array.isArray(e)||!Array.isArray(t)||!Array.isArray(r)||e.length===0||t.length!==e.length||r.length!==e.length)return null;for(let o=0;o<e.length;o++)if(typeof e[o]!="string"||!Array.isArray(t[o])||typeof r[o]!="number"||!Number.isFinite(r[o]))return null;return{textLines:e,charBounds:t,lineHeights:r}},nb=n=>{let e=n.map(o=>At(o).length),t=[],r=0;for(let o of e)t.push(r),r+=o;return{starts:t,counts:e}},Cv=(n,e)=>{let{starts:t,counts:r}=n;if(t.length===0||e<0)return null;let o=0,i=t.length-1;for(;o<i;){let a=o+i+1>>1;t[a]<=e?o=a:i=a-1}let s=e-t[o];return s<0||s>=r[o]?null:[o,s]},Mv=(n,e)=>{let t=n.styles;if(!Array.isArray(t))return{};for(let r of t){if(!r||typeof r!="object")continue;let o=r,i=typeof o.start=="number"?o.start:-1,s=typeof o.end=="number"?o.end:-1;if(e>=i&&e<s&&o.style&&typeof o.style=="object")return o.style}return{}},Zp=(n,e)=>{let t=Mv(n,e),r=(o,i)=>t[o]!==void 0?t[o]:i;return{fontFamily:r("fontFamily",Ie(n,"fontFamily")??"Arial"),fontSize:r("fontSize",K(n,"fontSize",40)),fontWeight:r("fontWeight",String(Ie(n,"fontWeight")??"normal")),fontStyle:r("fontStyle",Ie(n,"fontStyle")??"normal"),fill:r("fill",n.fill),stroke:r("stroke",n.stroke),strokeWidth:r("strokeWidth",K(n,"strokeWidth",1)),underline:r("underline",n.underline===!0),linethrough:r("linethrough",n.linethrough===!0),overline:r("overline",n.overline===!0)}},Ln=n=>({fontFamily:n.fontFamily??"Times New Roman",fontSize:n.fontSize??40,fontWeight:n.fontWeight,fontStyle:n.fontStyle??void 0,lineHeight:n.lineHeight??1.16,charSpacing:n.charSpacing??0,textAlign:n.textAlign??fe.LEFT}),ei=(n,e,t)=>({fontFamily:e?.fontFamily??n.fontFamily,fontSize:e?.fontSize??n.fontSize,fontWeight:String(e?.fontWeight??n.fontWeight??"normal"),fontStyle:e?.fontStyle??n.fontStyle??"normal",fill:e?.fill??t.fill,stroke:t.stroke,strokeWidth:K(t,"strokeWidth",1),underline:t.underline===!0,linethrough:t.linethrough===!0,overline:t.overline===!0}),Rv=(n,e)=>{if(!Array.isArray(e)||e.length===0)return e&&typeof e=="object"?e:void 0;let t=nb(n.split(`
|