"use strict";var t,e,s=require("fabric");class i extends s.Image{constructor(t,e){super(t,Object.assign({label:"Image"},e))}toObject(t=[]){return super.toObject(t.concat(["label","selectable"]))}}s.classRegistry.setClass(i);class c extends s.Path{set type(t){}constructor(t,e){super(t,Object.assign({label:"Path"},e))}toObject(t=[]){return super.toObject(t.concat(["label","selectable"]))}}s.classRegistry.setClass(c);class r extends s.Rect{constructor(t){super(Object.assign({fill:"#000000",strokeWidth:0,stroke:"#000000",label:"Rect"},t)),this.onScaled=()=>{const t=this.width*this.scaleX,e=this.height*this.scaleY;this.set({width:t,height:e,scaleX:1,scaleY:1})},this.on("scaling",this.onScaled)}toObject(t=[]){return super.toObject(t.concat(["label","selectable"]))}}s.classRegistry.setClass(r),exports.MceVerticalAlign=void 0,(t=exports.MceVerticalAlign||(exports.MceVerticalAlign={}))[t.top=1]="top",t[t.middle=2]="middle",t[t.bottom=3]="bottom",exports.MceTextBackground=void 0,(e=exports.MceTextBackground||(exports.MceTextBackground={}))[e.none=0]="none",e[e.behind=1]="behind";class a extends s.Textbox{constructor(t,e){super(t,Object.assign({label:"Textbox",fill:"#000000",fontSize:30,fontFamily:"serif",verticalAlign:exports.MceVerticalAlign.top,textBackground:exports.MceTextBackground.none,textBackgroundFill:"#ff0000",stroke:"#ff0000",strokeWidth:0,paintFirst:"stroke"},e)),this.onScaled=()=>{const t=this.width*this.scaleX,e=this.maxHeight*this.scaleY;this.set({width:t,maxHeight:e,scaleX:1,scaleY:1})},this.on("scaling",this.onScaled)}setText(t){this.set({text:t})}calcTextHeight(){return this.maxHeight}_getTopOffset(){const t=-this.maxHeight/2;if(this.verticalAlign===exports.MceVerticalAlign.top)return t;const e=this.getHeightOfLine(0)*this.textLines.length,s=Math.max(this.maxHeight-e,0);if(this.verticalAlign===exports.MceVerticalAlign.middle)return t+s/2;if(this.verticalAlign===exports.MceVerticalAlign.bottom)return t+s;throw new Error("Unsupported vertical align")}_renderTextCommon(t,e){t.save();const s=this._getLeftOffset(),i=this._getTopOffset();this.textBackground===exports.MceTextBackground.behind&&(t.fillStyle=this.textBackgroundFill);let c=0;for(let r=0,a=this._textLines.length;rthis.maxHeight)break;const o=a/this.lineHeight,n=this._getLineLeftOffset(r);if(this.textBackground===exports.MceTextBackground.behind){const e=this.__charBounds[r][0],a=this.__charBounds[r][this.__charBounds[r].length-1];t.fillRect(s+n,i+c,a.left-e.left+a.width,o)}this._renderTextLine(e,t,this._textLines[r],s+n,i+c+o,r),c+=a}t.restore()}toObject(t=[]){return super.toObject(t.concat(["label","selectable","verticalAlign","maxHeight","verticalAlign","textBackground","textBackgroundFill"]))}}function o(t,e){const s=Math.max(t.getScaledWidth()/e.width,t.getScaledHeight()/e.height),c=t.getScaledWidth()/s,r=t.getScaledHeight()/s,a=(e.height-t.getScaledHeight()/s)/2,o=(e.width-t.getScaledWidth()/s)/2;return new i(e,{angle:t.angle,left:t.left,top:t.top,width:c,height:r,scaleX:s,scaleY:s,cropY:a,cropX:o})}function n(t,e,s,i){return new(s||(s=Promise))((function(c,r){function a(t){try{n(i.next(t))}catch(t){r(t)}}function o(t){try{n(i.throw(t))}catch(t){r(t)}}function n(t){var e;t.done?c(t.value):(e=t.value,e instanceof s?e:new s((function(t){t(e)}))).then(a,o)}n((i=i.apply(t,e||[])).next())}))}function h(t,e){const s=t.width/e.width,c=t.height/e.height;return new i(e,{angle:t.angle,left:t.left,top:t.top,width:e.width,height:e.height,scaleX:s,scaleY:c})}a.cacheProperties=[...s.Textbox.cacheProperties,"verticalAlign","textBackground","textBackgroundFill"],s.classRegistry.setClass(a),"function"==typeof SuppressedError&&SuppressedError;class l{static create(t){const e=t.getObjects();return new l(t,e)}constructor(t,e){this.canvas=t,this.objects=e}getText(t){return this.objects[t.realIndex].text}replaceText(t,e){const s=this.objects[t.realIndex];s.visible&&s.setText(e)}replaceRectToImage(t,e,i){return n(this,void 0,void 0,(function*(){const c=this.objects[t.realIndex];if(!c.visible)return;var r;let a;switch("string"==typeof e&&(e=yield(r=e,new Promise(((t,e)=>{const i=s.getEnv().document.createElement("img");i.onload=()=>t(i),i.onerror=()=>{const t=r.length>20?r.substring(0,20)+"...":r;e(new Error(`Failed to load image: ${t}`))},i.src=r})))),i){case"stretch":a=h(c,e);break;case"fit":a=o(c,e);break;default:throw new Error(`Unknown mode: ${i}`)}this.canvas.remove(c),this.canvas.insertAt(t.realIndex,a)}))}}function g(){const t=document.createElement("canvas");t.width=10,t.height=10;const e=t.getContext("2d");return e.fillStyle="#ffffff",e.fillRect(0,0,10,10),e.fillStyle="#f0f0f0",e.fillRect(0,0,5,5),e.fillRect(5,5,5,5),t}class d{constructor(t){this.canvas=t,this.getWorkspaceObjects=()=>this.canvas.getObjects().filter((t=>t!==this.canvas.workspaceBackground)),this.getLayers=()=>{var t;const e=this.canvas.getObjects(),s=[];for(let i=0;i