polotno 2.4.25 → 2.4.26

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.
@@ -1 +1 @@
1
- "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,a,r){void 0===r&&(r=a);var o=Object.getOwnPropertyDescriptor(t,a);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[a]}}),Object.defineProperty(e,r,o)}:function(e,t,a,r){void 0===r&&(r=a),e[r]=t[a]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var a in e)"default"!==a&&Object.prototype.hasOwnProperty.call(e,a)&&__createBinding(t,e,a);return __setModuleDefault(t,e),t},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ImageElement=exports.useImageLoader=exports.setImageLoaderHook=void 0;const react_1=__importDefault(require("react")),mobx_react_lite_1=require("mobx-react-lite"),mobx_1=require("mobx"),react_konva_1=require("react-konva"),use_image_1=__importDefault(require("use-image")),konva_1=__importDefault(require("konva")),react_konva_utils_1=require("react-konva-utils"),highlighter_1=require("./highlighter"),loader_1=require("../utils/loader"),svg=__importStar(require("../utils/svg")),flags_1=require("../utils/flags"),apply_filters_1=require("./apply-filters"),use_fadein_1=require("./use-fadein"),screen_1=require("../utils/screen");function createCanvas(){return document.createElement("canvas")}async function getFixedUrl(e){if(!(e.indexOf("data:image/svg+xml")>=0||e.indexOf(".svg")>=0))return e;const t=await svg.urlToString(e),a=svg.fixSize(t);return svg.svgToURL(a)}const useSizeFixer=e=>{const[t,a]=react_1.default.useState(e);return react_1.default.useEffect((()=>{(async()=>{const r=await getFixedUrl(e);r!==t&&a(r)})()}),[e]),t};function getDistance(e,t){return Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2))}function getCenter(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2}}const useFlip=(e,t,a)=>{const r=react_1.default.useMemo((()=>{var r,o;const{flipX:i,flipY:n}=e,h="svg"===e.type||e.src.indexOf("data:image/svg+xml")>=0||e.src.indexOf(".svg")>=0,c=navigator.userAgent.toLowerCase().indexOf("firefox")>-1&&h||e.maskSrc;if(!i&&!n&&!c)return t;if(!t||!t.width||!t.height)return null;const d=createCanvas();let l=1;"svg"===e.type&&(l=Math.max(e.a.width/t.width*a,e.a.height/t.height*a)),d.width=Math.max(t.width*l,1),d.height=Math.max(t.height*l,1);let s=i?-d.width:0,u=n?-d.height:0;return null===(r=d.getContext("2d"))||void 0===r||r.scale(i?-1:1,n?-1:1),null===(o=d.getContext("2d"))||void 0===o||o.drawImage(t,s,u,d.width,d.height),d}),[e.maskSrc,e.flipX,e.flipY,t,e.a.width,e.a.height,a]);return react_1.default.useEffect((()=>()=>{r&&"CANVAS"===r.nodeName&&konva_1.default.Util.releaseCanvas(r)}),[r]),r};function getCrop(e,t){const a=t.width/t.height;let r,o;a>=e.width/e.height?(r=e.width,o=e.width/a):(r=e.height*a,o=e.height);return{x:(e.width-r)/2,y:(e.height-o)/2,width:r,height:o}}function downsample(e,t,a,r,o,i,n){for(var h=new ImageData(t,a),c=new Int32Array(e.data.buffer),d=e.width,l=new Int32Array(h.data.buffer),s=h.width,u=t/i,g=a/n,f=Math.round(1/u),p=Math.round(1/g),_=f*p,m=0;m<h.height;m++)for(var w=0;w<s;w++){for(var x=r+Math.round(w/u)+(o+Math.round(m/g))*d,v=0,y=0,M=0,b=0,E=0;E<p;E++)for(var k=0;k<f;k++){var C=c[x+k+E*d];v+=C<<24>>>24,y+=C<<16>>>24,M+=C<<8>>>24,b+=C>>>24}v=Math.round(v/_),y=Math.round(y/_),M=Math.round(M/_),b=Math.round(b/_),l[w+m*s]=b<<24|M<<16|y<<8|v}return h}function downScaleCanvas(e,t){var a,r;const o=createCanvas();o.width=e.width,o.height=e.height;const i=Math.max(1,Math.floor(o.width*t)),n=Math.max(1,Math.floor(o.height*t));null===(a=o.getContext("2d"))||void 0===a||a.drawImage(e,0,0,o.width,o.height);const h=downsample(o.getContext("2d").getImageData(0,0,o.width,o.height),i,n,0,0,o.width,o.height);return o.width=i,o.height=n,null===(r=o.getContext("2d"))||void 0===r||r.putImageData(h,0,0),o}const useMask=(e,t)=>{const[a,r]=useImageHook(e.maskSrc,"anonymous"),o=e.maskSrc?r:"loaded";return(0,exports.useImageLoader)(o,e.id+"-mask"),react_1.default.useMemo((()=>{if(!a)return t;if(!t||!t.width||!t.height)return t;const r=createCanvas();r.width=Math.max(t.width,1),r.height=Math.max(t.height,1);const o=r.getContext("2d");if(!o)return t;o.drawImage(t,0,0),o.globalCompositeOperation="source-in";const i=getCrop(a,e);return o.drawImage(a,i.x,i.y,i.width,i.height,0,0,t.width,t.height),r}),[t,a,e.a.width,e.a.height])},useCornerRadiusAndCrop=(e,t,a,r,o=0,i=!1)=>{const n=Math.floor(Math.max(e.a.width*r,1)),h=Math.floor(Math.max(e.a.height*r,1)),c=Math.min(o*r,n/2,h/2),d=Math.max(e.a.width/a.width,e.a.height/a.height)*r,l=e.page._exporting&&flags_1.flags.imageDownScalingEnabled&&d<1&&!i,s=0===a.x&&0===a.y&&a.width===(null==t?void 0:t.width)&&a.height===(null==t?void 0:t.height),u=react_1.default.useMemo((()=>{if(!t||!t.width||!t.height)return;return s&&0===c&&!l?void 0:createCanvas()}),[t,c,l,s]);return react_1.default.useLayoutEffect((()=>{if(!u||!t)return;u.width=n,u.height=h;const e=u.getContext("2d");if(!e)return;c&&(e.beginPath(),e.moveTo(c,0),e.lineTo(n-c,0),e.arc(n-c,c,c,3*Math.PI/2,0,!1),e.lineTo(n,h-c),e.arc(n-c,h-c,c,0,Math.PI/2,!1),e.lineTo(c,h),e.arc(c,h-c,c,Math.PI/2,Math.PI,!1),e.lineTo(0,c),e.arc(c,c,c,Math.PI,3*Math.PI/2,!1),e.clip());const r=l?downScaleCanvas(t,d):t,o=l?{x:Math.floor(a.x*d),y:Math.floor(a.y*d),width:Math.floor(a.width*d),height:Math.floor(a.height*d)}:a;e.drawImage(r,o.x,o.y,o.width,o.height,0,0,u.width,u.height)}),[u,e.a.width,e.a.height,a.x,a.y,a.width,a.height,o,r,i,e.page._exporting,l]),react_1.default.useEffect((()=>()=>{u&&"CANVAS"===u.nodeName&&konva_1.default.Util.releaseCanvas(u)}),[u]),u||t},useClip=(e,t,a,r)=>{const o=useSizeFixer(e.clipSrc||""),[i,n]=useImageHook(o,"anonymous"),h=e.clipSrc?n:"loaded";(0,exports.useImageLoader)(h,e.id+"-clip");const c=react_1.default.useMemo((()=>{if(t&&i)return createCanvas()}),[t,i]);react_1.default.useLayoutEffect((()=>{var r;if(!i)return;if(!t||!t.width||!t.height)return;if(!i||!i.width||!i.height)return;if(!c)return;const o=createCanvas(),n=Math.max(e.a.width/i.width*a,e.a.height/i.height*a);o.width=i.width*n,o.height=i.height*n,null===(r=o.getContext("2d"))||void 0===r||r.drawImage(i,0,0,o.width,o.height),c.width=Math.max(t.width,1),c.height=Math.max(t.height,1);const h=c.getContext("2d");h&&(h.save(),h.drawImage(o,0,0,t.width,t.height),konva_1.default.Util.releaseCanvas(o),h.globalCompositeOperation="source-in",h.drawImage(t,0,0,c.width,c.height),h.restore())}),[c,t,i,e.a.width,e.a.height,a,...r]);return e.clipSrc&&i?c:t},PLACEHOLDER_CANVAS=createCanvas(),LoadingPlaceholder=(0,mobx_react_lite_1.observer)((({element:e})=>{const t=Math.min(30,e.a.width/4,e.a.height/4),a=react_1.default.useRef(null);return react_1.default.useEffect((()=>{const e=a.current;if(!e)return;const t=new konva_1.default.Animation((t=>{e.rotate(((null==t?void 0:t.timeDiff)||0)/2)}),e.getLayer());return t.start(),()=>{t.stop()}})),react_1.default.createElement(react_konva_1.Group,{x:e.x,y:e.y,rotation:e.rotation,listening:!1,opacity:e.a.opacity,hideInExport:!e.showInExport},react_1.default.createElement(react_konva_1.Rect,{width:e.a.width,height:e.a.height,fill:"rgba(124, 173, 212, 0.8)"}),react_1.default.createElement(react_konva_1.Arc,{ref:a,x:e.a.width/2,y:e.a.height/2,fill:"white",outerRadius:Math.abs(t),innerRadius:Math.max(1,t-5),angle:270}))})),ErrorPlaceholder=(0,mobx_react_lite_1.observer)((({element:e})=>{const t="Can not load the image...",a=Math.max(10,Math.min(30,e.a.width/25));return react_1.default.createElement(react_konva_1.Group,{x:e.x,y:e.y,rotation:e.rotation,listening:!1,opacity:e.a.opacity,hideInExport:!e.showInExport},react_1.default.createElement(react_konva_1.Rect,{width:e.a.width,height:e.a.height,fill:"rgba(223, 102, 102, 0.8)"}),react_1.default.createElement(react_konva_1.Text,{text:t,fontSize:a,width:e.a.width,height:e.a.height,align:"center",fill:"white",verticalAlign:"middle",padding:5}))}));let useImageHook=use_image_1.default;const setImageLoaderHook=e=>{useImageHook=e};exports.setImageLoaderHook=setImageLoaderHook;const useImageLoader=(e,t)=>{const a=react_1.default.useRef(),r=()=>{var e;null===(e=a.current)||void 0===e||e.call(a),a.current=void 0};react_1.default.useEffect((()=>r),[]),react_1.default.useLayoutEffect((()=>{"loading"!==e||a.current||(a.current=(0,loader_1.incrementLoader)(`image ${t}`)),"loading"!==e&&r(),"failed"===e&&(0,loader_1.triggerLoadError)(`image ${t}`)}),[e])};exports.useImageLoader=useImageLoader;const usePreviousImage=({image:e,status:t,type:a})=>{const r=react_1.default.useRef();react_1.default.useEffect((()=>{r.current=e||r.current}),[e]);return"failed"!==t||"failed"!==t&&"svg"===a?r.current:void 0},useImageSource=e=>{const[t,a]=react_1.default.useReducer((e=>e+1),0),r=react_1.default.useRef("loading"),o=react_1.default.useRef(e.src),i=react_1.default.useRef(e.src);return i.current!==e.src&&(i.current=e.src,r.current="loading"),react_1.default.useEffect((()=>{if("svg"!==e.type)return;if(!e.src)return;let t=!1;return(async()=>{r.current="loading",a();const i=await svg.urlToString(e.src),n=svg.fixSize(i),h=svg.replaceColors(n,e.colorsReplace);t||(o.current=h,r.current="loaded",a())})(),()=>{t=!0}}),[e.src,JSON.stringify(e.colorsReplace)]),"svg"!==e.type?[e.src,"loaded"]:[o.current,r.current]};exports.ImageElement=(0,mobx_react_lite_1.observer)((({element:e,store:t})=>{var a;const[r,o]=react_1.default.useState(!1),i=react_1.default.useRef(null),n=react_1.default.useRef(null),[h,c]=react_1.default.useState(!1),d=t.selectedElements.indexOf(e)>=0,[l,s]=useImageSource(e),[u,g]=useImageHook(l,"anonymous"),f="svg"!==e.type||"loaded"===s?g:"loading";(0,exports.useImageLoader)(f,e.id);const p=usePreviousImage({image:u,status:g,type:e.type}),_=useMask(e,useFlip(e,u||p,t._elementsPixelRatio))||PLACEHOLDER_CANVAS;let{cropX:m,cropY:w,cropWidth:x,cropHeight:v}=e;"loaded"!==g&&(m=w=0,x=v=1);const y=_.width*x,M=_.height*v,b=e.a.width/e.a.height;let E,k;const C=y/M,I="svg"===e.type;I?(E=y,k=M):b>=C?(E=y,k=y/b):(E=M*b,k=M);const S={x:_.width*m,y:_.height*w,width:E,height:k},R=null!==(a=e.cornerRadius)&&void 0!==a?a:0,O=e.page._exporting?1:Math.min(2,t.scale),D=t._elementsPixelRatio*O;let L=useClip(e,useCornerRadiusAndCrop(e,_,S,D,R,r||e._cropModeEnabled||"svg"===e.type),D,[S,R,D]);const P=Math.max(e.a.width/E,e.a.height/k);react_1.default.useEffect((()=>{var t;if(!e._cropModeEnabled)return;const a=null===(t=i.current)||void 0===t?void 0:t.getStage();function r(t){e._cropModeEnabled&&t.target!==n.current&&e.toggleCropMode(!1)}function o(t){e._cropModeEnabled&&t.target.parentNode!==a.content&&e.toggleCropMode(!1)}return document.body.addEventListener("click",o),null==a||a.on("click",r),null==a||a.on("tap",r),()=>{document.body.removeEventListener("click",o),document.body.removeEventListener("touchstart",o),null==a||a.off("click",r),null==a||a.off("click",r)}}),[e._cropModeEnabled]),react_1.default.useLayoutEffect((()=>{if(r||e._cropModeEnabled)return;(0,apply_filters_1.applyFilter)(i.current,e);return(0,mobx_1.autorun)((()=>{(0,apply_filters_1.applyFilter)(i.current,e)}),{delay:100})}),[_,r,x,v,e._cropModeEnabled]),react_1.default.useLayoutEffect((()=>{var t;r||e._cropModeEnabled?null===(t=i.current)||void 0===t||t.clearCache():(0,apply_filters_1.applyFilter)(i.current,e)}),[r,e.a.width,e.a.height,e._cropModeEnabled]),react_1.default.useEffect((()=>{(0,apply_filters_1.applyFilter)(i.current,e)}),[e.shadowEnabled,e.shadowBlur,e.cornerRadius,e.shadowColor,e.shadowOffsetX,e.shadowOffsetY,e.shadowOpacity]);const X=react_1.default.useRef(null),Y=react_1.default.useRef(null),A=react_1.default.useRef(null);react_1.default.useLayoutEffect((()=>{e._cropModeEnabled&&(Y.current.nodes([X.current]),A.current.nodes([n.current]))}),[e._cropModeEnabled]);var H=react_1.default.useRef(null),T=react_1.default.useRef(0),W=react_1.default.useRef(!1);const q=t=>{var a;(null===(a=t.evt.touches)||void 0===a?void 0:a.length)>2&&t.target.stopDrag(),Math.round(t.target.x())>0&&(t.target.x(0),t.target.scaleX(1)),Math.round(t.target.y())>0&&(t.target.y(0),t.target.scaleY(1));const r=t.target.width()*t.target.scaleX(),o=t.target.height()*t.target.scaleY(),i=Math.min(1,E/r),n=Math.min(1,k/o),h=1-i,c=Math.min(h,Math.max(0,Math.round(-t.target.x())/r)),d=1-n,l=Math.min(d,Math.max(0,Math.round(-t.target.y())/o));t.target.setAttrs({x:-c*_.width,y:-l*_.height,scaleX:1,scaleY:1}),e.set({cropX:c,cropY:l,cropWidth:i,cropHeight:n})},F=()=>{"svg"!==e.type&&e.contentEditable&&setTimeout((()=>{e.toggleCropMode(!0)}))},z="svg"===e.type&&p,B="loading"===g&&!z,N="failed"===g,j=!B&&!N,U=react_1.default.useRef({cropX:0,cropY:0,cropWidth:0,cropHeight:0}),V=j?e.a.opacity:0;(0,use_fadein_1.useFadeIn)(i,V);const G=e.selectable||"admin"===t.role,$=(0,screen_1.useMobile)();return react_1.default.createElement(react_1.default.Fragment,null,B&&react_1.default.createElement(LoadingPlaceholder,{element:e}),N&&react_1.default.createElement(ErrorPlaceholder,{element:e}),react_1.default.createElement(react_konva_1.Image,{ref:i,name:"element",id:e.id,image:L,x:e.a.x,y:e.a.y,width:e.a.width||1,height:e.a.height||1,rotation:e.rotation,opacity:V,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,customCrop:S,listening:G,draggable:$?e.draggable&&d:e.draggable,preventDefault:!$||d,hideInExport:!e.showInExport,onMouseEnter:()=>{c(!0)},onMouseLeave:()=>{c(!1)},onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDblClick:F,onDblTap:F,onTransformStart:()=>{o(!0),U.current={cropX:e.cropX,cropY:e.cropY,cropWidth:e.cropWidth,cropHeight:e.cropHeight}},onTransform:t=>{var a;const r=t.currentTarget,o=Math.abs(r.scaleX()-1)<1e-7?1:r.scaleX(),i=Math.abs(r.scaleY()-1)<1e-7?1:r.scaleY();r.scaleX(1),r.scaleY(1);const n=null===(a=t.target.getStage())||void 0===a?void 0:a.findOne("Transformer"),h=1-E/_.width,c=Math.min(h,Math.max(0,e.cropX)),d=1-k/_.height,l=Math.min(d,Math.max(0,e.cropY)),s=n.getActiveAnchor(),u=!(s.indexOf("middle")>=0||s.indexOf("center")>=0),g=!u&&o<1&&U.current.cropHeight>k/_.height;let f=u?e.cropWidth:e.cropWidth*o;g&&(f=e.cropWidth);const p=!u&&i<1&&U.current.cropWidth>E/_.width;let m=u?e.cropHeight:e.cropHeight*i;p&&(m=e.cropHeight),I&&(f=e.cropWidth,m=e.cropHeight),e.set({cropX:c,cropY:l,x:r.x(),y:r.y(),width:r.width()*o,height:r.height()*i,rotation:t.target.rotation(),cropWidth:Math.min(f,1-c),cropHeight:Math.min(m,1-l)})},onTransformEnd:t=>{const a=t.currentTarget;e.set({width:a.width(),height:a.height(),x:a.x(),y:a.y(),rotation:t.target.rotation(),cropWidth:E/_.width,cropHeight:k/_.height}),o(!1)}}),react_1.default.createElement(react_konva_1.Rect,{x:e.x,y:e.y,width:Math.max(e.a.width-e.borderSize,0),height:Math.max(e.a.height-e.borderSize,0),opacity:V,offsetX:-e.borderSize/2,offsetY:-e.borderSize/2,stroke:e.borderColor,strokeWidth:e.borderSize,listening:!1,visible:!!e.borderSize,rotation:e.rotation,cornerRadius:Math.max(0,R-e.borderSize),hideInExport:!e.showInExport}),e._cropModeEnabled&&react_1.default.createElement(react_konva_utils_1.Portal,{selector:".page-abs-container",enabled:!0},react_1.default.createElement(react_konva_1.Rect,{x:-window.innerWidth/t.scale,y:-window.innerWidth/t.scale,width:window.innerWidth/t.scale*3,height:window.innerWidth/t.scale*3,fill:"rgba(0,0,0,0.3)"}),react_1.default.createElement(react_konva_1.Image,{listening:!1,image:L,x:e.x,y:e.y,width:e.a.width,height:e.a.height,rotation:e.rotation,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur}),react_1.default.createElement(react_konva_1.Group,{x:e.x,y:e.y,rotation:e.rotation,scaleX:P,scaleY:P},react_1.default.createElement(react_konva_1.Image,{image:_,ref:n,opacity:.4,draggable:!0,x:-e.cropX*_.width,y:-e.cropY*_.height,onDragMove:q,onTransform:q,onTouchMove:e=>{e.evt.preventDefault();const t=e.target.getStage().getPointersPositions();var a=t[0],r=t[1];const o=e.target;if(a&&!r&&!o.isDragging()&&W.current&&(o.startDrag(),W.current=!1),a&&r){konva_1.default.hitOnDragEnabled=!0,o.isDragging()&&(W.current=!0,o.stopDrag());const t=e.target.getAbsoluteTransform().copy();t.invert();var i={x:a.x,y:a.y},n={x:r.x,y:r.y};if(!H.current)return void(H.current=getCenter(i,n));var h=getCenter(i,n),c=getDistance(i,n);T.current||(T.current=c);const f=o.position();var d={x:h.x-f.x,y:h.y-f.y},l=c/T.current;o.scaleX(l),o.scaleY(l);const p=t.point(h),_=t.point(H.current);var s=p.x-_.x,u=p.y-_.y,g={x:Math.min(0,h.x-d.x*l+s),y:Math.min(0,h.y-d.y*l+u)};o.position(g),T.current=c,H.current=h,q(e)}},onTouchEnd:e=>{T.current=0,H.current=null,konva_1.default.hitOnDragEnabled=!1}}),react_1.default.createElement(react_konva_1.Transformer,{ref:A,anchorSize:20,enabledAnchors:["top-left","top-right","bottom-left","bottom-right"],boundBoxFunc:(e,t)=>t.width<5||t.height<5?e:t,rotateEnabled:!1,borderEnabled:!1,anchorCornerRadius:10,anchorStrokeWidth:2,borderStrokeWidth:2}),react_1.default.createElement(react_konva_1.Rect,{width:E,height:k,ref:X,listening:!1,onTransform:t=>{t.target.x()<-e.cropX*_.width-1e-9&&(t.target.x(-e.cropX*_.width),t.target.scaleX(1)),t.target.y()<-e.cropY*_.height-1e-9&&(t.target.y(-e.cropY*_.height),t.target.scaleY(1));const a=Math.min(1,Math.max(0,e.cropX+t.target.x()/_.width)),r=Math.min(1,Math.max(0,t.target.y()/_.height+e.cropY)),o=t.target.width()*t.target.scaleX(),i=t.target.height()*t.target.scaleY(),n=Math.min(1-a,o/_.width),h=Math.min(1-r,i/_.height),c=t.target.getAbsolutePosition(t.target.getParent().getParent());t.target.scale({x:1,y:1}),t.target.position({x:0,y:0}),e.set({x:c.x,y:c.y,cropX:a,cropY:r,cropWidth:n,cropHeight:h,width:Math.min(o*P,_.width*(1-a)*P),height:Math.min(i*P,_.height*(1-r)*P)})}}),react_1.default.createElement(react_konva_1.Transformer,{ref:Y,enabledAnchors:["top-left","top-right","bottom-left","bottom-right"],boundBoxFunc:(e,t)=>t.width<5||t.height<5?e:t,visible:e.resizable,keepRatio:!1,rotateEnabled:!1,anchorFill:"rgb(240, 240, 240)",anchorStrokeWidth:2,borderStrokeWidth:2}))),(h||d)&&react_1.default.createElement(highlighter_1.Highlighter,{element:e}))}));
1
+ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,a,r){void 0===r&&(r=a);var o=Object.getOwnPropertyDescriptor(t,a);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[a]}}),Object.defineProperty(e,r,o)}:function(e,t,a,r){void 0===r&&(r=a),e[r]=t[a]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var a in e)"default"!==a&&Object.prototype.hasOwnProperty.call(e,a)&&__createBinding(t,e,a);return __setModuleDefault(t,e),t},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ImageElement=exports.useImageLoader=exports.setImageLoaderHook=void 0;const react_1=__importDefault(require("react")),mobx_react_lite_1=require("mobx-react-lite"),mobx_1=require("mobx"),react_konva_1=require("react-konva"),use_image_1=__importDefault(require("use-image")),konva_1=__importDefault(require("konva")),react_konva_utils_1=require("react-konva-utils"),highlighter_1=require("./highlighter"),loader_1=require("../utils/loader"),svg=__importStar(require("../utils/svg")),flags_1=require("../utils/flags"),apply_filters_1=require("./apply-filters"),use_fadein_1=require("./use-fadein"),screen_1=require("../utils/screen");function createCanvas(){return document.createElement("canvas")}async function getFixedUrl(e){if(!(e.indexOf("data:image/svg+xml")>=0||e.indexOf(".svg")>=0))return e;const t=await svg.urlToString(e),a=svg.fixSize(t);return svg.svgToURL(a)}const useSizeFixer=e=>{const[t,a]=react_1.default.useState(e);return react_1.default.useEffect((()=>{(async()=>{const r=await getFixedUrl(e);r!==t&&a(r)})()}),[e]),t};function getDistance(e,t){return Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2))}function getCenter(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2}}const useFlip=(e,t,a)=>{const r=react_1.default.useMemo((()=>{var r,o;const{flipX:i,flipY:n}=e,h="svg"===e.type||e.src.indexOf("data:image/svg+xml")>=0||e.src.indexOf(".svg")>=0,c=navigator.userAgent.toLowerCase().indexOf("firefox")>-1&&h||e.maskSrc;if(!i&&!n&&!c)return t;if(!t||!t.width||!t.height)return null;const d=createCanvas();let l=1;"svg"===e.type&&(l=Math.max(e.a.width/t.width*a,e.a.height/t.height*a)),d.width=Math.max(t.width*l,1),d.height=Math.max(t.height*l,1);let s=i?-d.width:0,u=n?-d.height:0;return null===(r=d.getContext("2d"))||void 0===r||r.scale(i?-1:1,n?-1:1),null===(o=d.getContext("2d"))||void 0===o||o.drawImage(t,s,u,d.width,d.height),d}),[e.maskSrc,e.flipX,e.flipY,t,e.a.width,e.a.height,a]);return react_1.default.useEffect((()=>()=>{r&&"CANVAS"===r.nodeName&&konva_1.default.Util.releaseCanvas(r)}),[r]),r};function getCrop(e,t){const a=t.width/t.height;let r,o;a>=e.width/e.height?(r=e.width,o=e.width/a):(r=e.height*a,o=e.height);return{x:(e.width-r)/2,y:(e.height-o)/2,width:r,height:o}}function downsample(e,t,a,r,o,i,n){for(var h=new ImageData(t,a),c=new Int32Array(e.data.buffer),d=e.width,l=new Int32Array(h.data.buffer),s=h.width,u=t/i,g=a/n,f=Math.round(1/u),p=Math.round(1/g),_=f*p,m=0;m<h.height;m++)for(var w=0;w<s;w++){for(var x=r+Math.round(w/u)+(o+Math.round(m/g))*d,v=0,y=0,M=0,b=0,E=0;E<p;E++)for(var k=0;k<f;k++){var C=c[x+k+E*d];v+=C<<24>>>24,y+=C<<16>>>24,M+=C<<8>>>24,b+=C>>>24}v=Math.round(v/_),y=Math.round(y/_),M=Math.round(M/_),b=Math.round(b/_),l[w+m*s]=b<<24|M<<16|y<<8|v}return h}function downScaleCanvas(e,t){var a,r;const o=createCanvas();o.width=e.width,o.height=e.height;const i=Math.max(1,Math.floor(o.width*t)),n=Math.max(1,Math.floor(o.height*t));null===(a=o.getContext("2d"))||void 0===a||a.drawImage(e,0,0,o.width,o.height);const h=downsample(o.getContext("2d").getImageData(0,0,o.width,o.height),i,n,0,0,o.width,o.height);return o.width=i,o.height=n,null===(r=o.getContext("2d"))||void 0===r||r.putImageData(h,0,0),o}const useMask=(e,t)=>{const[a,r]=useImageHook(e.maskSrc,"anonymous"),o=e.maskSrc?r:"loaded";return(0,exports.useImageLoader)(o,e.id+"-mask"),react_1.default.useMemo((()=>{if(!a)return t;if(!t||!t.width||!t.height)return t;const r=createCanvas();r.width=Math.max(t.width,1),r.height=Math.max(t.height,1);const o=r.getContext("2d");if(!o)return t;o.drawImage(t,0,0),o.globalCompositeOperation="source-in";const i=getCrop(a,e);return o.drawImage(a,i.x,i.y,i.width,i.height,0,0,t.width,t.height),r}),[t,a,e.a.width,e.a.height])},useCornerRadiusAndCrop=(e,t,a,r,o=0,i=!1)=>{const n=Math.floor(Math.max(e.a.width*r,1)),h=Math.floor(Math.max(e.a.height*r,1)),c=Math.min(o*r,n/2,h/2),d=Math.max(e.a.width/a.width,e.a.height/a.height)*r,l=e.page._exporting&&flags_1.flags.imageDownScalingEnabled&&d<1&&!i,s=0===a.x&&0===a.y&&a.width===(null==t?void 0:t.width)&&a.height===(null==t?void 0:t.height),u=react_1.default.useMemo((()=>{if(!t||!t.width||!t.height)return;return s&&0===c&&!l?void 0:createCanvas()}),[t,c,l,s]);return react_1.default.useLayoutEffect((()=>{if(!u||!t)return;u.width=n,u.height=h;const e=u.getContext("2d");if(!e)return;c&&(e.beginPath(),e.moveTo(c,0),e.lineTo(n-c,0),e.arc(n-c,c,c,3*Math.PI/2,0,!1),e.lineTo(n,h-c),e.arc(n-c,h-c,c,0,Math.PI/2,!1),e.lineTo(c,h),e.arc(c,h-c,c,Math.PI/2,Math.PI,!1),e.lineTo(0,c),e.arc(c,c,c,Math.PI,3*Math.PI/2,!1),e.clip());const r=l?downScaleCanvas(t,d):t,o=l?{x:Math.floor(a.x*d),y:Math.floor(a.y*d),width:Math.floor(a.width*d),height:Math.floor(a.height*d)}:a;e.drawImage(r,o.x,o.y,o.width,o.height,0,0,u.width,u.height)}),[u,e.a.width,e.a.height,a.x,a.y,a.width,a.height,o,r,i,e.page._exporting,l]),react_1.default.useEffect((()=>()=>{u&&"CANVAS"===u.nodeName&&konva_1.default.Util.releaseCanvas(u)}),[u]),u||t},useClip=(e,t,a,r)=>{const o=useSizeFixer(e.clipSrc||""),[i,n]=useImageHook(o,"anonymous"),h=e.clipSrc?n:"loaded";(0,exports.useImageLoader)(h,e.id+"-clip");const c=react_1.default.useMemo((()=>{if(t&&i)return createCanvas()}),[t,i]);react_1.default.useLayoutEffect((()=>{var r;if(!i)return;if(!t||!t.width||!t.height)return;if(!i||!i.width||!i.height)return;if(!c)return;const o=createCanvas(),n=Math.max(e.a.width/i.width*a,e.a.height/i.height*a);o.width=i.width*n,o.height=i.height*n,null===(r=o.getContext("2d"))||void 0===r||r.drawImage(i,0,0,o.width,o.height),c.width=Math.max(t.width,1),c.height=Math.max(t.height,1);const h=c.getContext("2d");h&&(h.save(),h.drawImage(o,0,0,t.width,t.height),konva_1.default.Util.releaseCanvas(o),h.globalCompositeOperation="source-in",h.drawImage(t,0,0,c.width,c.height),h.restore())}),[c,t,i,e.a.width,e.a.height,a,...r]);return e.clipSrc&&i?c:t},PLACEHOLDER_CANVAS=createCanvas(),LoadingPlaceholder=(0,mobx_react_lite_1.observer)((({element:e})=>{const t=Math.min(30,e.a.width/4,e.a.height/4),a=react_1.default.useRef(null);return react_1.default.useEffect((()=>{const e=a.current;if(!e)return;const t=new konva_1.default.Animation((t=>{e.rotate(((null==t?void 0:t.timeDiff)||0)/2)}),e.getLayer());return t.start(),()=>{t.stop()}})),react_1.default.createElement(react_konva_1.Group,{x:e.x,y:e.y,rotation:e.rotation,listening:!1,opacity:e.a.opacity,hideInExport:!e.showInExport},react_1.default.createElement(react_konva_1.Rect,{width:e.a.width,height:e.a.height,fill:"rgba(124, 173, 212, 0.8)"}),react_1.default.createElement(react_konva_1.Arc,{ref:a,x:e.a.width/2,y:e.a.height/2,fill:"white",outerRadius:Math.abs(t),innerRadius:Math.max(1,t-5),angle:270}))})),ErrorPlaceholder=(0,mobx_react_lite_1.observer)((({element:e})=>{const t="Can not load the image...",a=Math.max(10,Math.min(30,e.a.width/25));return react_1.default.createElement(react_konva_1.Group,{x:e.x,y:e.y,rotation:e.rotation,listening:!1,opacity:e.a.opacity,hideInExport:!e.showInExport},react_1.default.createElement(react_konva_1.Rect,{width:e.a.width,height:e.a.height,fill:"rgba(223, 102, 102, 0.8)"}),react_1.default.createElement(react_konva_1.Text,{text:t,fontSize:a,width:e.a.width,height:e.a.height,align:"center",fill:"white",verticalAlign:"middle",padding:5}))}));let useImageHook=use_image_1.default;const setImageLoaderHook=e=>{useImageHook=e};exports.setImageLoaderHook=setImageLoaderHook;const useImageLoader=(e,t)=>{const a=react_1.default.useRef(),r=()=>{var e;null===(e=a.current)||void 0===e||e.call(a),a.current=void 0};react_1.default.useEffect((()=>r),[]),react_1.default.useLayoutEffect((()=>{"loading"!==e||a.current||(a.current=(0,loader_1.incrementLoader)(`image ${t}`)),"loading"!==e&&r(),"failed"===e&&(0,loader_1.triggerLoadError)(`image ${t}`)}),[e])};exports.useImageLoader=useImageLoader;const usePreviousImage=({image:e,status:t,type:a})=>{const r=react_1.default.useRef();react_1.default.useEffect((()=>{r.current=e||r.current}),[e]);return"failed"!==t||"failed"!==t&&"svg"===a?r.current:void 0},useImageSource=e=>{const[t,a]=react_1.default.useReducer((e=>e+1),0),r=react_1.default.useRef("loading"),o=react_1.default.useRef(e.src),i=react_1.default.useRef(e.src);return i.current!==e.src&&(i.current=e.src,r.current="loading"),react_1.default.useEffect((()=>{if("svg"!==e.type)return;if(!e.src)return;let t=!1;return(async()=>{r.current="loading",a();const i=await svg.urlToString(e.src),n=svg.fixSize(i),h=svg.replaceColors(n,e.colorsReplace);t||(o.current=h,r.current="loaded",a())})(),()=>{t=!0}}),[e.src,JSON.stringify(e.colorsReplace)]),"svg"!==e.type?[e.src,"loaded"]:[o.current,r.current]};exports.ImageElement=(0,mobx_react_lite_1.observer)((({element:e,store:t})=>{var a;const[r,o]=react_1.default.useState(!1),i=react_1.default.useRef(null),n=react_1.default.useRef(null),[h,c]=react_1.default.useState(!1),d=t.selectedElements.indexOf(e)>=0,[l,s]=useImageSource(e),[u,g]=useImageHook(l,"anonymous"),f="svg"!==e.type||"loaded"===s?g:"loading";(0,exports.useImageLoader)(f,e.id);const p=usePreviousImage({image:u,status:g,type:e.type}),_=useMask(e,useFlip(e,u||p,t._elementsPixelRatio))||PLACEHOLDER_CANVAS;let{cropX:m,cropY:w,cropWidth:x,cropHeight:v}=e;"loaded"!==g&&(m=w=0,x=v=1);const y=_.width*x,M=_.height*v,b=e.a.width/e.a.height;let E,k;const C=y/M,I="svg"===e.type;I?(E=y,k=M):b>=C?(E=y,k=y/b):(E=M*b,k=M);const S={x:_.width*m,y:_.height*w,width:E,height:k},R=null!==(a=e.cornerRadius)&&void 0!==a?a:0,O=e.page._exporting?1:Math.min(2,t.scale),D=t._elementsPixelRatio*O;let L=useClip(e,useCornerRadiusAndCrop(e,_,S,D,R,r||e._cropModeEnabled||"svg"===e.type),D,[S,R,D]);const P=Math.max(e.a.width/E,e.a.height/k);react_1.default.useEffect((()=>{var t;if(!e._cropModeEnabled)return;const a=null===(t=i.current)||void 0===t?void 0:t.getStage();function r(t){e._cropModeEnabled&&t.target!==n.current&&e.toggleCropMode(!1)}function o(t){e._cropModeEnabled&&t.target.parentNode!==a.content&&e.toggleCropMode(!1)}return document.body.addEventListener("click",o),null==a||a.on("click",r),null==a||a.on("tap",r),()=>{document.body.removeEventListener("click",o),document.body.removeEventListener("touchstart",o),null==a||a.off("click",r),null==a||a.off("click",r)}}),[e._cropModeEnabled]),react_1.default.useLayoutEffect((()=>{if(r||e._cropModeEnabled)return;(0,apply_filters_1.applyFilter)(i.current,e);return(0,mobx_1.autorun)((()=>{(0,apply_filters_1.applyFilter)(i.current,e)}),{delay:100})}),[_,e.page._exporting,r,x,v,e._cropModeEnabled]),react_1.default.useLayoutEffect((()=>{var t;r||e._cropModeEnabled?null===(t=i.current)||void 0===t||t.clearCache():(0,apply_filters_1.applyFilter)(i.current,e)}),[r,e.a.width,e.a.height,e._cropModeEnabled]),react_1.default.useEffect((()=>{(0,apply_filters_1.applyFilter)(i.current,e)}),[e.shadowEnabled,e.shadowBlur,e.cornerRadius,e.shadowColor,e.shadowOffsetX,e.shadowOffsetY,e.shadowOpacity]);const X=react_1.default.useRef(null),Y=react_1.default.useRef(null),A=react_1.default.useRef(null);react_1.default.useLayoutEffect((()=>{e._cropModeEnabled&&(Y.current.nodes([X.current]),A.current.nodes([n.current]))}),[e._cropModeEnabled]);var H=react_1.default.useRef(null),T=react_1.default.useRef(0),W=react_1.default.useRef(!1);const q=t=>{var a;(null===(a=t.evt.touches)||void 0===a?void 0:a.length)>2&&t.target.stopDrag(),Math.round(t.target.x())>0&&(t.target.x(0),t.target.scaleX(1)),Math.round(t.target.y())>0&&(t.target.y(0),t.target.scaleY(1));const r=t.target.width()*t.target.scaleX(),o=t.target.height()*t.target.scaleY(),i=Math.min(1,E/r),n=Math.min(1,k/o),h=1-i,c=Math.min(h,Math.max(0,Math.round(-t.target.x())/r)),d=1-n,l=Math.min(d,Math.max(0,Math.round(-t.target.y())/o));t.target.setAttrs({x:-c*_.width,y:-l*_.height,scaleX:1,scaleY:1}),e.set({cropX:c,cropY:l,cropWidth:i,cropHeight:n})},F=()=>{"svg"!==e.type&&e.contentEditable&&setTimeout((()=>{e.toggleCropMode(!0)}))},z="svg"===e.type&&p,B="loading"===g&&!z,N="failed"===g,j=!B&&!N,U=react_1.default.useRef({cropX:0,cropY:0,cropWidth:0,cropHeight:0}),V=j?e.a.opacity:0;(0,use_fadein_1.useFadeIn)(i,V);const G=e.selectable||"admin"===t.role,$=(0,screen_1.useMobile)();return react_1.default.createElement(react_1.default.Fragment,null,B&&react_1.default.createElement(LoadingPlaceholder,{element:e}),N&&react_1.default.createElement(ErrorPlaceholder,{element:e}),react_1.default.createElement(react_konva_1.Image,{ref:i,name:"element",id:e.id,image:L,x:e.a.x,y:e.a.y,width:e.a.width||1,height:e.a.height||1,rotation:e.rotation,opacity:V,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,customCrop:S,listening:G,draggable:$?e.draggable&&d:e.draggable,preventDefault:!$||d,hideInExport:!e.showInExport,onMouseEnter:()=>{c(!0)},onMouseLeave:()=>{c(!1)},onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDblClick:F,onDblTap:F,onTransformStart:()=>{o(!0),U.current={cropX:e.cropX,cropY:e.cropY,cropWidth:e.cropWidth,cropHeight:e.cropHeight}},onTransform:t=>{var a;const r=t.currentTarget,o=Math.abs(r.scaleX()-1)<1e-7?1:r.scaleX(),i=Math.abs(r.scaleY()-1)<1e-7?1:r.scaleY();r.scaleX(1),r.scaleY(1);const n=null===(a=t.target.getStage())||void 0===a?void 0:a.findOne("Transformer"),h=1-E/_.width,c=Math.min(h,Math.max(0,e.cropX)),d=1-k/_.height,l=Math.min(d,Math.max(0,e.cropY)),s=n.getActiveAnchor(),u=!(s.indexOf("middle")>=0||s.indexOf("center")>=0),g=!u&&o<1&&U.current.cropHeight>k/_.height;let f=u?e.cropWidth:e.cropWidth*o;g&&(f=e.cropWidth);const p=!u&&i<1&&U.current.cropWidth>E/_.width;let m=u?e.cropHeight:e.cropHeight*i;p&&(m=e.cropHeight),I&&(f=e.cropWidth,m=e.cropHeight),e.set({cropX:c,cropY:l,x:r.x(),y:r.y(),width:r.width()*o,height:r.height()*i,rotation:t.target.rotation(),cropWidth:Math.min(f,1-c),cropHeight:Math.min(m,1-l)})},onTransformEnd:t=>{const a=t.currentTarget;e.set({width:a.width(),height:a.height(),x:a.x(),y:a.y(),rotation:t.target.rotation(),cropWidth:E/_.width,cropHeight:k/_.height}),o(!1)}}),react_1.default.createElement(react_konva_1.Rect,{x:e.x,y:e.y,width:Math.max(e.a.width-e.borderSize,0),height:Math.max(e.a.height-e.borderSize,0),opacity:V,offsetX:-e.borderSize/2,offsetY:-e.borderSize/2,stroke:e.borderColor,strokeWidth:e.borderSize,listening:!1,visible:!!e.borderSize,rotation:e.rotation,cornerRadius:Math.max(0,R-e.borderSize),hideInExport:!e.showInExport}),e._cropModeEnabled&&react_1.default.createElement(react_konva_utils_1.Portal,{selector:".page-abs-container",enabled:!0},react_1.default.createElement(react_konva_1.Rect,{x:-window.innerWidth/t.scale,y:-window.innerWidth/t.scale,width:window.innerWidth/t.scale*3,height:window.innerWidth/t.scale*3,fill:"rgba(0,0,0,0.3)"}),react_1.default.createElement(react_konva_1.Image,{listening:!1,image:L,x:e.x,y:e.y,width:e.a.width,height:e.a.height,rotation:e.rotation,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur}),react_1.default.createElement(react_konva_1.Group,{x:e.x,y:e.y,rotation:e.rotation,scaleX:P,scaleY:P},react_1.default.createElement(react_konva_1.Image,{image:_,ref:n,opacity:.4,draggable:!0,x:-e.cropX*_.width,y:-e.cropY*_.height,onDragMove:q,onTransform:q,onTouchMove:e=>{e.evt.preventDefault();const t=e.target.getStage().getPointersPositions();var a=t[0],r=t[1];const o=e.target;if(a&&!r&&!o.isDragging()&&W.current&&(o.startDrag(),W.current=!1),a&&r){konva_1.default.hitOnDragEnabled=!0,o.isDragging()&&(W.current=!0,o.stopDrag());const t=e.target.getAbsoluteTransform().copy();t.invert();var i={x:a.x,y:a.y},n={x:r.x,y:r.y};if(!H.current)return void(H.current=getCenter(i,n));var h=getCenter(i,n),c=getDistance(i,n);T.current||(T.current=c);const f=o.position();var d={x:h.x-f.x,y:h.y-f.y},l=c/T.current;o.scaleX(l),o.scaleY(l);const p=t.point(h),_=t.point(H.current);var s=p.x-_.x,u=p.y-_.y,g={x:Math.min(0,h.x-d.x*l+s),y:Math.min(0,h.y-d.y*l+u)};o.position(g),T.current=c,H.current=h,q(e)}},onTouchEnd:e=>{T.current=0,H.current=null,konva_1.default.hitOnDragEnabled=!1}}),react_1.default.createElement(react_konva_1.Transformer,{ref:A,anchorSize:20,enabledAnchors:["top-left","top-right","bottom-left","bottom-right"],boundBoxFunc:(e,t)=>t.width<5||t.height<5?e:t,rotateEnabled:!1,borderEnabled:!1,anchorCornerRadius:10,anchorStrokeWidth:2,borderStrokeWidth:2}),react_1.default.createElement(react_konva_1.Rect,{width:E,height:k,ref:X,listening:!1,onTransform:t=>{t.target.x()<-e.cropX*_.width-1e-9&&(t.target.x(-e.cropX*_.width),t.target.scaleX(1)),t.target.y()<-e.cropY*_.height-1e-9&&(t.target.y(-e.cropY*_.height),t.target.scaleY(1));const a=Math.min(1,Math.max(0,e.cropX+t.target.x()/_.width)),r=Math.min(1,Math.max(0,t.target.y()/_.height+e.cropY)),o=t.target.width()*t.target.scaleX(),i=t.target.height()*t.target.scaleY(),n=Math.min(1-a,o/_.width),h=Math.min(1-r,i/_.height),c=t.target.getAbsolutePosition(t.target.getParent().getParent());t.target.scale({x:1,y:1}),t.target.position({x:0,y:0}),e.set({x:c.x,y:c.y,cropX:a,cropY:r,cropWidth:n,cropHeight:h,width:Math.min(o*P,_.width*(1-a)*P),height:Math.min(i*P,_.height*(1-r)*P)})}}),react_1.default.createElement(react_konva_1.Transformer,{ref:Y,enabledAnchors:["top-left","top-right","bottom-left","bottom-right"],boundBoxFunc:(e,t)=>t.width<5||t.height<5?e:t,visible:e.resizable,keepRatio:!1,rotateEnabled:!1,anchorFill:"rgb(240, 240, 240)",anchorStrokeWidth:2,borderStrokeWidth:2}))),(h||d)&&react_1.default.createElement(highlighter_1.Highlighter,{element:e}))}));
package/model/store.js CHANGED
@@ -1 +1 @@
1
- "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,a,i){void 0===i&&(i=a);var o=Object.getOwnPropertyDescriptor(t,a);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[a]}}),Object.defineProperty(e,i,o)}:function(e,t,a,i){void 0===i&&(i=a),e[i]=t[a]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var a in e)"default"!==a&&Object.prototype.hasOwnProperty.call(e,a)&&__createBinding(t,e,a);return __setModuleDefault(t,e),t},__rest=this&&this.__rest||function(e,t){var a={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(a[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(e);o<i.length;o++)t.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(e,i[o])&&(a[i[o]]=e[i[o]])}return a},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.createStore=exports.Store=exports.Font=void 0;const mobx_state_tree_1=require("mobx-state-tree"),history_1=require("./history"),nanoid_1=require("nanoid"),konva_1=__importDefault(require("konva")),download_1=require("../utils/download"),pdf_1=require("../utils/pdf"),gif_lib_1=require("../utils/gif-lib"),validate_key_1=require("../utils/validate-key"),fonts=__importStar(require("../utils/fonts")),loader_1=require("../utils/loader"),unit_1=require("../utils/unit"),deep_equal_1=require("../utils/deep-equal"),wait_1=require("../utils/wait"),html_1=require("../utils/html"),to_svg_1=require("../utils/to-svg"),page_model_1=require("./page-model"),group_model_1=require("./group-model");function createStore({key:e,showCredit:t}={key:"",showCredit:!1}){const a=exports.Store.create();return(0,validate_key_1.validateKey)(e,t),a}(0,mobx_state_tree_1.setLivelinessChecking)("ignore"),exports.Font=mobx_state_tree_1.types.model("Font",{fontFamily:mobx_state_tree_1.types.string,url:mobx_state_tree_1.types.optional(mobx_state_tree_1.types.string,""),styles:mobx_state_tree_1.types.frozen()}).preProcessSnapshot((e=>Object.assign(Object.assign({},e),{fontFamily:e.fontFamily||e.name}))),exports.Store=mobx_state_tree_1.types.model("Store",{role:"",pages:mobx_state_tree_1.types.array(page_model_1.Page),fonts:mobx_state_tree_1.types.array(exports.Font),width:1080,height:1080,currentTime:0,isPlaying:!1,scale:1,scaleToFit:1,unit:"px",dpi:72,bleedVisible:!1,rulesVisible:!1,openedSidePanel:"",custom:mobx_state_tree_1.types.frozen(),selectedElementsIds:mobx_state_tree_1.types.array(mobx_state_tree_1.types.string),animatedElementsIds:mobx_state_tree_1.types.array(mobx_state_tree_1.types.string),history:mobx_state_tree_1.types.optional(history_1.UndoManager,{targetPath:"../pages"}),_elementsPixelRatio:2,_activePageId:""}).views((e=>({get _bleedVisible(){return console.warn("store._bleedVisible is deprecated. Please use store.bleedVisible instead."),e.bleedVisible},get selectedElements(){return e.selectedElementsIds.map((t=>{for(const a of e.pages)for(const e of a.children)if(e.id===t)return e})).filter((e=>!!e))},get children(){return e.pages},get selectedShapes(){const t=[];return(0,group_model_1.forEveryChild)({children:e.selectedElements},(e=>{"group"!==e.type&&t.push(e)})),t},get activePage(){return e.pages.slice().find((t=>t.id===e._activePageId))||(e.pages.length?e.pages[0]:null)},get duration(){let t=0;return e.pages.forEach((e=>{t+=e.duration})),t},get _hasCroppedImages(){return e.find((e=>"image"===e.type&&e._cropModeEnabled))},find(t){let a;return(0,group_model_1.forEveryChild)({children:e.pages},(e=>{if(!a&&t(e))return a=e,!0})),a},getElementById:t=>e.find((e=>e.id===t))}))).actions((e=>{let t=0,a=null;return{afterCreate(){e.history.canUndo},setCurrentTime(t){e.currentTime=t},play({animatedElementsIds:i=[],startTime:o=0,currentTime:n=0,endTime:s=e.duration}={}){n&&(console.warn("currentTime property of store.play() is deprecated. Please use startTime instead."),o=n),e.animatedElementsIds=(0,mobx_state_tree_1.cast)(i),e.currentTime=o,e.isPlaying=!0,t=Date.now(),a=s,requestAnimationFrame(e.seek)},checkActivePage(){let t=0;for(const a of e.pages){if(e.currentTime>=a.startTime&&e.currentTime<a.startTime+a.duration){e.selectPage(a.id);break}t+=a.duration}},seek(){if(!e.isPlaying)return;const i=Date.now(),o=i-t;t=i,e.currentTime+=o,e.checkActivePage();const n=a||e.duration;e.isPlaying&&e.currentTime<n?requestAnimationFrame(e.seek):e.stop()},stop(){e.isPlaying=!1,e.currentTime=0,e.animatedElementsIds=(0,mobx_state_tree_1.cast)([]),e.checkActivePage()}}})).actions((e=>({set(t){Object.assign(e,t)},setUnit({unit:t,dpi:a}){e.unit=t||e.unit,e.dpi=a||e.dpi},setRole(t){e.role=t},addPage(t){const a=page_model_1.Page.create(Object.assign({id:(0,nanoid_1.nanoid)(10)},t));return e.pages.push(a),e._activePageId=a.id,a},selectPage(t){e._activePageId=t},selectElements(t){const a=t.map((t=>e.getElementById(t))).sort(((e,t)=>e.page.children.indexOf(e)-e.page.children.indexOf(t))).filter((e=>!!e)).map((e=>e.id));e.selectedElementsIds=(0,mobx_state_tree_1.cast)(a)},toggleBleed(t){e.bleedVisible=null!=t?t:!e.bleedVisible},toggleRulers(t){e.rulesVisible=null!=t?t:!e.rulesVisible},openSidePanel(t){e.openedSidePanel=t},setScale(t){e.scale=t},_setScaleToFit(t){e.scaleToFit=t},setElementsPixelRatio(t){e._elementsPixelRatio=t},setSize(t,a,i){e.pages.forEach((e=>{e.setSize({width:t,height:a,useMagic:i,softChange:!0})})),e.width=t,e.height=a},setPageZIndex(t,a){const i=e.pages.find((e=>e.id===t));i&&((0,mobx_state_tree_1.detach)(i),e.pages.remove(i),e.pages.splice(a,0,i))},deletePages(t){const a=e.pages.indexOf(e.activePage);t.forEach((t=>{const a=e.pages.find((e=>e.id===t));(0,mobx_state_tree_1.destroy)(a)}));const i=Math.min(e.pages.length-1,a),o=e.pages[i];o&&(e._activePageId=o.id),e.selectedElementsIds=(0,mobx_state_tree_1.cast)(e.selectedElementsIds.filter((t=>e.getElementById(t))))},groupElements(t){const a=t.map((t=>e.getElementById(t)));a.forEach((e=>{e&&(0,mobx_state_tree_1.detach)(e)}));const i=e.activePage,o={id:(0,nanoid_1.nanoid)(10),children:a,type:"group"};return i.children.push(o),e.selectedElementsIds=(0,mobx_state_tree_1.cast)([o.id]),o},ungroupElements(t){const a=t.map((t=>e.getElementById(t))),i=[];a.forEach((e=>{if(e&&"group"===e.type){const t=e.page,a=t.children.indexOf(e);e.children.forEach((e=>{i.push(e.id)})),e.children.forEach((e=>{(0,mobx_state_tree_1.detach)(e),t.children.push(e)})),t.children.splice(a,1)}})),e.selectedElementsIds=(0,mobx_state_tree_1.cast)(i)},deleteElements(t){t.forEach((t=>{e.pages.forEach((e=>{const a=e.children.find((e=>e.id===t));a&&(0,mobx_state_tree_1.destroy)(a)}))})),e.selectedElementsIds=(0,mobx_state_tree_1.cast)(e.selectedElementsIds.filter((t=>e.getElementById(t))))},on(t,a){if("change"===t){let t=e.toJSON();return(0,mobx_state_tree_1.onSnapshot)(e,(i=>{const o=e.toJSON();!(0,deep_equal_1.deepEqual)(t,o)&&(t=o,a(o))}))}},async _toCanvas({pixelRatio:t,ignoreBackground:a,pageId:i,mimeType:o,includeBleed:n}={}){var s;const r=t||1;i=i||(null===(s=e.pages[0])||void 0===s?void 0:s.id);const l=e.pages.find((e=>e.id===i));if(!l)throw new Error(`No page for export with id ${i}`);null==l||l.set({_exporting:!0});const d=await(0,wait_1.waitTillAvailable)((()=>konva_1.default.stages.find((e=>e.getAttr("pageId")===i))));if(!d)throw new Error(`Export is failed. Can not find stage for page ${i}. Looks like <Workspace /> component is not mounted, but it is required in order to process the export.`);const c=!!d.findOne(".page-container"),p=e._elementsPixelRatio;r>e._elementsPixelRatio&&e.setElementsPixelRatio(r),await e.waitLoading();const g=d.findOne(".page-container");if(!g)throw new Error(`Export is failed. Can't find page container. ${c}`);d.find("Transformer").forEach((e=>e.visible(!1))),g.find(".page-background").forEach((e=>e.shadowEnabled(!1))),g.find(".page-background").forEach((e=>e.strokeEnabled(!1))),g.find(".highlighter").forEach((e=>e.visible(!1)));const u=g.findOne(".page-background-group"),_=u.clip();u.clip({x:null,y:null,width:null,height:null});const m=g.findOne(".elements-container"),f=m.clip();m.clip({x:null,y:null,width:null,height:null});const h=g.find((e=>e.getAttr("hideInExport")));h.forEach((e=>{e.setAttr("oldVisible",e.visible()),e.hide()}));const b=g.find((e=>!e.visible()&&e.getAttr("editModeEnabled")));b.forEach((e=>{e.setAttr("oldVisible",e.visible()),e.show()})),a&&g.find(".page-background").forEach((e=>e.hide()));const y=n?l.bleed:0;let x=y;!e.bleedVisible&&n||(e.bleedVisible||n?e.bleedVisible&&n?x=0:e.bleedVisible&&!n&&(x=-l.bleed):x=0);const v=document.createElement("canvas");v.width=Math.round((l.computedWidth+2*y)*r),v.height=Math.round((l.computedHeight+2*y)*r);const w=v.getContext("2d");"image/jpeg"===o&&(w.fillStyle="white",w.fillRect(0,0,v.width,v.height));const E=g.scale();g.scale({x:1,y:1});const P=g.toCanvas({x:g.x()-x,y:g.y()-x,width:l.computedWidth+2*y,height:l.computedHeight+2*y,pixelRatio:r});return g.scale(E),w.drawImage(P,0,0,v.width,v.height),konva_1.default.Util.releaseCanvas(P),a&&g.find(".page-background").forEach((e=>e.show())),h.forEach((e=>{e.visible(e.getAttr("oldVisible"))})),b.forEach((e=>{e.visible(e.getAttr("oldVisible"))})),g.find(".page-background").forEach((e=>e.shadowEnabled(!0))),g.find(".page-background").forEach((e=>e.strokeEnabled(!0))),d.find("Transformer").forEach((e=>e.visible(!0))),g.find(".highlighter").forEach((e=>e.visible(!0))),u.clip(_),m.clip(f),e.setElementsPixelRatio(p),null==l||l.set({_exporting:!1}),v},async toDataURL({pixelRatio:t,ignoreBackground:a,pageId:i,mimeType:o,includeBleed:n,quality:s}={}){const r=await e._toCanvas({pixelRatio:t,ignoreBackground:a,pageId:i,mimeType:o,includeBleed:n}),l=r.toDataURL(o,s);return konva_1.default.Util.releaseCanvas(r),l},async toBlob({pixelRatio:t,ignoreBackground:a,pageId:i,mimeType:o,includeBleed:n,quality:s}={}){const r=await e._toCanvas({pixelRatio:t,ignoreBackground:a,pageId:i,mimeType:o,includeBleed:n}),l=new Promise((e=>{r.toBlob(e,o,s)}));return konva_1.default.Util.releaseCanvas(r),l},async saveAsImage(t={}){var{fileName:a}=t,i=__rest(t,["fileName"]);const o=i.mimeType||"image/png",n=o.split("/")[1];(0,download_1.downloadFile)(await e.toDataURL(i),a||"polotno."+n,o)},async _toPDF(t){const a=t.dpi||e.dpi,i=t.parallel||1,o=t.unit||("px"===e.unit?"mm":e.unit),n=t.pixelRatio||1,s=t.pageIds||e.pages.map((e=>e.id)),r=e.pages.filter((e=>s.includes(e.id))),l=await(0,pdf_1.getJsPDF)(),d=e=>(0,unit_1.pxToUnit)({px:e,unit:o,dpi:a}),c=d(t.cropMarkSize||0),p=r[0]||{},g=t.includeBleed?p.bleed:0,u=d(p.computedWidth+2*g)+2*c,_=d(p.computedHeight+2*g)+2*c;var m=new l({unit:o,orientation:u>_?"landscape":"portrait",format:[u,_],compress:!0,putOnlyUsedFonts:!0});m.deletePage(1);const f=((e,t)=>{for(var a=[],i=0;i<e.length;i+=t)a.push(e.slice(i,i+t));return a})(r,i);for(const a of f){const i=a.map((async a=>{const i=t.includeBleed?a.bleed:0,o=d(a.computedWidth+2*i)+2*c,s=d(a.computedHeight+2*i)+2*c;let r=0,l=n;for(;r<10;){r+=1,2===r&&console.error("Polotno can not export PDF with current settings. Quality is automatically reduced.");const i=await e.toDataURL(Object.assign(Object.assign({},t),{pageId:a.id,pixelRatio:l}));if(i.length>20)return{url:i,width:o,height:s};l*=.8}}));(await Promise.all(i)).forEach((({url:e,width:t,height:a})=>{m.addPage([t,a],t>a?"landscape":"portrait"),c&&(m.setLineWidth(d(1)),m.line(2*c,0,2*c,c),m.line(0,2*c,c,2*c),m.line(t-2*c,0,t-2*c,c),m.line(t,2*c,t-c,2*c),m.line(0,a-2*c,c,a-2*c),m.line(2*c,a,2*c,a-c),m.line(t,a-2*c,t-c,a-2*c),m.line(t-2*c,a,t-2*c,a-c)),m.addImage(e,c,c,t-2*c,a-2*c,void 0,"FAST")}))}return m},toPDFDataURL:async t=>(await e._toPDF(Object.assign({mimeType:"image/jpeg"},t))).output("datauristring"),async toGIFDataURL(t={}){const a=t.pixelRatio||1,i=await(0,gif_lib_1.createGIF)({width:e.width*a,height:e.height*a}),o=1e3/(t.fps||10),n=e.duration/o;for(let t=0;t<n-1;t++){const n=t*o||1;e.setCurrentTime(n);let s=0,r="";for(const t of e.pages)if(s+=t.duration,t.set({_rendering:s>n}),s>n){r=t.id;break}const l=await e._toCanvas({pixelRatio:a,pageId:r});i.addFrame(l.getContext("2d"),{delay:o,copy:!0})}for(const t of e.pages)t.set({_rendering:!1});e.stop(),i.render();return new Promise((e=>{i.on("finished",(function(t){!function(e,t){var a=new FileReader;a.onload=function(e){t(e.target.result)},a.readAsDataURL(e)}(t,e)}))}))},async saveAsGIF(t={}){var{fileName:a}=t,i=__rest(t,["fileName"]);const o=await e.toGIFDataURL(i);(0,download_1.downloadFile)(o,a||"polotno.gif")},async toHTML({elementHook:t}={elementHook:void 0}){const a=e.toJSON();return(0,html_1.jsonToHTML)({json:a,elementHook:t})},async saveAsHTML({fileName:t}={}){const a=await e.toHTML(),i="data:text/html;base64,"+window.btoa(unescape(encodeURIComponent(a)));(0,download_1.downloadFile)(i,t||"polotno.html")},async toSVG(){const t=e.toJSON();return(0,to_svg_1.jsonToSVG)({json:t})},async saveAsSVG({fileName:t}={}){const a=await e.toSVG(),i="data:text/svg;base64,"+window.btoa(unescape(encodeURIComponent(a)));(0,download_1.downloadFile)(i,t||"polotno.svg")},async saveAsPDF(t={}){var{fileName:a}=t,i=__rest(t,["fileName"]);(await e._toPDF(Object.assign({mimeType:"image/jpeg"},i))).save(a||"polotno.pdf")},async waitLoading(){await new Promise((e=>setTimeout(e,50))),await(0,loader_1.whenLoaded)()},toJSON:()=>({width:e.width,height:e.height,fonts:(0,mobx_state_tree_1.getSnapshot)(e.fonts),pages:(0,mobx_state_tree_1.getSnapshot)(e.pages),unit:e.unit,dpi:e.dpi,custom:e.custom}),loadJSON(t,a=!1){var i;const o=Object.assign({},t),n=e.pages.indexOf(e.activePage);let s=null===(i=o.pages[n]||o.pages[0])||void 0===i?void 0:i.id;o._activePageId=s;const r=Object.assign({},(0,mobx_state_tree_1.getSnapshot)(e));Object.assign(r,o),r.history=a?e.history.toJSON():{history:[],undoIdx:-1},(0,mobx_state_tree_1.applySnapshot)(e,r)},clear({keepHistory:t=!1}={}){const a=e.pages.map((e=>e.id));e.deletePages(a),t||e.history.clear()},addFont(t){e.removeFont(t.fontFamily),e.fonts.push(t),e.loadFont(t.fontFamily)},removeFont(t){e.fonts.filter((e=>e.fontFamily===t)).forEach((e=>(0,mobx_state_tree_1.destroy)(e)))},async loadFont(t){const a=e.fonts.find((e=>e.fontFamily===t))||fonts.globalFonts.find((e=>e.fontFamily===t));a?fonts.injectCustomFont(a):fonts.injectGoogleFont(t),await fonts.loadFont(t)},validate:e=>exports.Store.validate(e,[{path:"",type:exports.Store}]).map((e=>({path:"store"+e.context.map((e=>e.path)).join("."),message:e.message})))}))),exports.createStore=createStore,exports.default=createStore;
1
+ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,a,i){void 0===i&&(i=a);var o=Object.getOwnPropertyDescriptor(t,a);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[a]}}),Object.defineProperty(e,i,o)}:function(e,t,a,i){void 0===i&&(i=a),e[i]=t[a]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var a in e)"default"!==a&&Object.prototype.hasOwnProperty.call(e,a)&&__createBinding(t,e,a);return __setModuleDefault(t,e),t},__rest=this&&this.__rest||function(e,t){var a={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(a[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(e);o<i.length;o++)t.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(e,i[o])&&(a[i[o]]=e[i[o]])}return a},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.createStore=exports.Store=exports.Font=void 0;const mobx_state_tree_1=require("mobx-state-tree"),history_1=require("./history"),nanoid_1=require("nanoid"),konva_1=__importDefault(require("konva")),download_1=require("../utils/download"),pdf_1=require("../utils/pdf"),gif_lib_1=require("../utils/gif-lib"),validate_key_1=require("../utils/validate-key"),fonts=__importStar(require("../utils/fonts")),loader_1=require("../utils/loader"),unit_1=require("../utils/unit"),deep_equal_1=require("../utils/deep-equal"),wait_1=require("../utils/wait"),html_1=require("../utils/html"),to_svg_1=require("../utils/to-svg"),page_model_1=require("./page-model"),group_model_1=require("./group-model");function createStore({key:e,showCredit:t}={key:"",showCredit:!1}){const a=exports.Store.create();return(0,validate_key_1.validateKey)(e,t),a}(0,mobx_state_tree_1.setLivelinessChecking)("ignore"),exports.Font=mobx_state_tree_1.types.model("Font",{fontFamily:mobx_state_tree_1.types.string,url:mobx_state_tree_1.types.optional(mobx_state_tree_1.types.string,""),styles:mobx_state_tree_1.types.frozen()}).preProcessSnapshot((e=>Object.assign(Object.assign({},e),{fontFamily:e.fontFamily||e.name}))),exports.Store=mobx_state_tree_1.types.model("Store",{role:"",pages:mobx_state_tree_1.types.array(page_model_1.Page),fonts:mobx_state_tree_1.types.array(exports.Font),width:1080,height:1080,currentTime:0,isPlaying:!1,scale:1,scaleToFit:1,unit:"px",dpi:72,bleedVisible:!1,rulesVisible:!1,openedSidePanel:"",custom:mobx_state_tree_1.types.frozen(),selectedElementsIds:mobx_state_tree_1.types.array(mobx_state_tree_1.types.string),animatedElementsIds:mobx_state_tree_1.types.array(mobx_state_tree_1.types.string),history:mobx_state_tree_1.types.optional(history_1.UndoManager,{targetPath:"../pages"}),_elementsPixelRatio:2,_activePageId:""}).views((e=>({get _bleedVisible(){return console.warn("store._bleedVisible is deprecated. Please use store.bleedVisible instead."),e.bleedVisible},get selectedElements(){return e.selectedElementsIds.map((t=>{for(const a of e.pages)for(const e of a.children)if(e.id===t)return e})).filter((e=>!!e))},get children(){return e.pages},get selectedShapes(){const t=[];return(0,group_model_1.forEveryChild)({children:e.selectedElements},(e=>{"group"!==e.type&&t.push(e)})),t},get activePage(){return e.pages.slice().find((t=>t.id===e._activePageId))||(e.pages.length?e.pages[0]:null)},get duration(){let t=0;return e.pages.forEach((e=>{t+=e.duration})),t},get _hasCroppedImages(){return e.find((e=>"image"===e.type&&e._cropModeEnabled))},find(t){let a;return(0,group_model_1.forEveryChild)({children:e.pages},(e=>{if(!a&&t(e))return a=e,!0})),a},getElementById:t=>e.find((e=>e.id===t))}))).actions((e=>{let t=0,a=null;return{afterCreate(){e.history.canUndo},setCurrentTime(t){e.currentTime=t},play({animatedElementsIds:i=[],startTime:o=0,currentTime:n=0,endTime:s=e.duration}={}){n&&(console.warn("currentTime property of store.play() is deprecated. Please use startTime instead."),o=n),e.animatedElementsIds=(0,mobx_state_tree_1.cast)(i),e.currentTime=o,e.isPlaying=!0,t=Date.now(),a=s,requestAnimationFrame(e.seek)},checkActivePage(){let t=0;for(const a of e.pages){if(e.currentTime>=a.startTime&&e.currentTime<a.startTime+a.duration){e.selectPage(a.id);break}t+=a.duration}},seek(){if(!e.isPlaying)return;const i=Date.now(),o=i-t;t=i,e.currentTime+=o,e.checkActivePage();const n=a||e.duration;e.isPlaying&&e.currentTime<n?requestAnimationFrame(e.seek):e.stop()},stop(){e.isPlaying=!1,e.currentTime=0,e.animatedElementsIds=(0,mobx_state_tree_1.cast)([]),e.checkActivePage()}}})).actions((e=>({set(t){Object.assign(e,t)},setUnit({unit:t,dpi:a}){e.unit=t||e.unit,e.dpi=a||e.dpi},setRole(t){e.role=t},addPage(t){const a=page_model_1.Page.create(Object.assign({id:(0,nanoid_1.nanoid)(10)},t));return e.pages.push(a),e._activePageId=a.id,a},selectPage(t){e._activePageId=t},selectElements(t){const a=t.map((t=>e.getElementById(t))).sort(((e,t)=>e.page.children.indexOf(e)-e.page.children.indexOf(t))).filter((e=>!!e)).map((e=>e.id));e.selectedElementsIds=(0,mobx_state_tree_1.cast)(a)},toggleBleed(t){e.bleedVisible=null!=t?t:!e.bleedVisible},toggleRulers(t){e.rulesVisible=null!=t?t:!e.rulesVisible},openSidePanel(t){e.openedSidePanel=t},setScale(t){e.scale=t},_setScaleToFit(t){e.scaleToFit=t},setElementsPixelRatio(t){e._elementsPixelRatio=t},setSize(t,a,i){e.pages.forEach((e=>{e.setSize({width:t,height:a,useMagic:i,softChange:!0})})),e.width=t,e.height=a},setPageZIndex(t,a){const i=e.pages.find((e=>e.id===t));i&&((0,mobx_state_tree_1.detach)(i),e.pages.remove(i),e.pages.splice(a,0,i))},deletePages(t){const a=e.pages.indexOf(e.activePage);t.forEach((t=>{const a=e.pages.find((e=>e.id===t));(0,mobx_state_tree_1.destroy)(a)}));const i=Math.min(e.pages.length-1,a),o=e.pages[i];o&&(e._activePageId=o.id),e.selectedElementsIds=(0,mobx_state_tree_1.cast)(e.selectedElementsIds.filter((t=>e.getElementById(t))))},groupElements(t){const a=t.map((t=>e.getElementById(t)));a.forEach((e=>{e&&(0,mobx_state_tree_1.detach)(e)}));const i=e.activePage,o={id:(0,nanoid_1.nanoid)(10),children:a,type:"group"};return i.children.push(o),e.selectedElementsIds=(0,mobx_state_tree_1.cast)([o.id]),o},ungroupElements(t){const a=t.map((t=>e.getElementById(t))),i=[];a.forEach((e=>{if(e&&"group"===e.type){const t=e.page,a=t.children.indexOf(e);e.children.forEach((e=>{i.push(e.id)})),e.children.forEach((e=>{(0,mobx_state_tree_1.detach)(e),t.children.push(e)})),t.children.splice(a,1)}})),e.selectedElementsIds=(0,mobx_state_tree_1.cast)(i)},deleteElements(t){t.forEach((t=>{e.pages.forEach((e=>{const a=e.children.find((e=>e.id===t));a&&(0,mobx_state_tree_1.destroy)(a)}))})),e.selectedElementsIds=(0,mobx_state_tree_1.cast)(e.selectedElementsIds.filter((t=>e.getElementById(t))))},on(t,a){if("change"===t){let t=e.toJSON();return(0,mobx_state_tree_1.onSnapshot)(e,(i=>{const o=e.toJSON();!(0,deep_equal_1.deepEqual)(t,o)&&(t=o,a(o))}))}},async _toCanvas({pixelRatio:t,ignoreBackground:a,pageId:i,mimeType:o,includeBleed:n}={}){var s;const r=t||1;i=i||(null===(s=e.pages[0])||void 0===s?void 0:s.id);const l=e.pages.find((e=>e.id===i));if(!l)throw new Error(`No page for export with id ${i}`);null==l||l.set({_exporting:!0});const d=await(0,wait_1.waitTillAvailable)((()=>konva_1.default.stages.find((e=>e.getAttr("pageId")===i))));if(!d)throw new Error(`Export is failed. Can not find stage for page ${i}. Looks like <Workspace /> component is not mounted, but it is required in order to process the export.`);const c=!!d.findOne(".page-container"),p=e._elementsPixelRatio;r>e._elementsPixelRatio&&e.setElementsPixelRatio(r),await e.waitLoading();const g=d.findOne(".page-container");if(!g)throw e.setElementsPixelRatio(p),new Error(`Export is failed. Can't find page container. ${c}`);d.find("Transformer").forEach((e=>e.visible(!1))),g.find(".page-background").forEach((e=>e.shadowEnabled(!1))),g.find(".page-background").forEach((e=>e.strokeEnabled(!1))),g.find(".highlighter").forEach((e=>e.visible(!1)));const u=g.findOne(".page-background-group"),_=u.clip();u.clip({x:null,y:null,width:null,height:null});const m=g.findOne(".elements-container"),f=m.clip();m.clip({x:null,y:null,width:null,height:null});const h=g.find((e=>e.getAttr("hideInExport")));h.forEach((e=>{e.setAttr("oldVisible",e.visible()),e.hide()}));const b=g.find((e=>!e.visible()&&e.getAttr("editModeEnabled")));b.forEach((e=>{e.setAttr("oldVisible",e.visible()),e.show()})),a&&g.find(".page-background").forEach((e=>e.hide()));const y=n?l.bleed:0;let x=y;!e.bleedVisible&&n||(e.bleedVisible||n?e.bleedVisible&&n?x=0:e.bleedVisible&&!n&&(x=-l.bleed):x=0);const v=document.createElement("canvas");v.width=Math.round((l.computedWidth+2*y)*r),v.height=Math.round((l.computedHeight+2*y)*r);const w=v.getContext("2d");"image/jpeg"===o&&(w.fillStyle="white",w.fillRect(0,0,v.width,v.height));const E=g.scale();g.scale({x:1,y:1});const P=g.toCanvas({x:g.x()-x,y:g.y()-x,width:l.computedWidth+2*y,height:l.computedHeight+2*y,pixelRatio:r});return g.scale(E),w.drawImage(P,0,0,v.width,v.height),konva_1.default.Util.releaseCanvas(P),a&&g.find(".page-background").forEach((e=>e.show())),h.forEach((e=>{e.visible(e.getAttr("oldVisible"))})),b.forEach((e=>{e.visible(e.getAttr("oldVisible"))})),g.find(".page-background").forEach((e=>e.shadowEnabled(!0))),g.find(".page-background").forEach((e=>e.strokeEnabled(!0))),d.find("Transformer").forEach((e=>e.visible(!0))),g.find(".highlighter").forEach((e=>e.visible(!0))),u.clip(_),m.clip(f),e.setElementsPixelRatio(p),null==l||l.set({_exporting:!1}),v},async toDataURL({pixelRatio:t,ignoreBackground:a,pageId:i,mimeType:o,includeBleed:n,quality:s}={}){const r=await e._toCanvas({pixelRatio:t,ignoreBackground:a,pageId:i,mimeType:o,includeBleed:n}),l=r.toDataURL(o,s);return konva_1.default.Util.releaseCanvas(r),l},async toBlob({pixelRatio:t,ignoreBackground:a,pageId:i,mimeType:o,includeBleed:n,quality:s}={}){const r=await e._toCanvas({pixelRatio:t,ignoreBackground:a,pageId:i,mimeType:o,includeBleed:n}),l=new Promise((e=>{r.toBlob(e,o,s)}));return konva_1.default.Util.releaseCanvas(r),l},async saveAsImage(t={}){var{fileName:a}=t,i=__rest(t,["fileName"]);const o=i.mimeType||"image/png",n=o.split("/")[1];(0,download_1.downloadFile)(await e.toDataURL(i),a||"polotno."+n,o)},async _toPDF(t){const a=t.dpi||e.dpi,i=t.parallel||1,o=t.unit||("px"===e.unit?"mm":e.unit),n=t.pixelRatio||1,s=t.pageIds||e.pages.map((e=>e.id)),r=e.pages.filter((e=>s.includes(e.id))),l=await(0,pdf_1.getJsPDF)(),d=e=>(0,unit_1.pxToUnit)({px:e,unit:o,dpi:a}),c=d(t.cropMarkSize||0),p=r[0]||{},g=t.includeBleed?p.bleed:0,u=d(p.computedWidth+2*g)+2*c,_=d(p.computedHeight+2*g)+2*c;var m=new l({unit:o,orientation:u>_?"landscape":"portrait",format:[u,_],compress:!0,putOnlyUsedFonts:!0});m.deletePage(1);const f=((e,t)=>{for(var a=[],i=0;i<e.length;i+=t)a.push(e.slice(i,i+t));return a})(r,i);for(const a of f){const i=a.map((async a=>{const i=t.includeBleed?a.bleed:0,o=d(a.computedWidth+2*i)+2*c,s=d(a.computedHeight+2*i)+2*c;let r=0,l=n;for(;r<10;){r+=1,2===r&&console.error("Polotno can not export PDF with current settings. Quality is automatically reduced.");const i=await e.toDataURL(Object.assign(Object.assign({},t),{pageId:a.id,pixelRatio:l}));if(i.length>20)return{url:i,width:o,height:s};l*=.8}}));(await Promise.all(i)).forEach((({url:e,width:t,height:a})=>{m.addPage([t,a],t>a?"landscape":"portrait"),c&&(m.setLineWidth(d(1)),m.line(2*c,0,2*c,c),m.line(0,2*c,c,2*c),m.line(t-2*c,0,t-2*c,c),m.line(t,2*c,t-c,2*c),m.line(0,a-2*c,c,a-2*c),m.line(2*c,a,2*c,a-c),m.line(t,a-2*c,t-c,a-2*c),m.line(t-2*c,a,t-2*c,a-c)),m.addImage(e,c,c,t-2*c,a-2*c,void 0,"FAST")}))}return m},toPDFDataURL:async t=>(await e._toPDF(Object.assign({mimeType:"image/jpeg"},t))).output("datauristring"),async toGIFDataURL(t={}){const a=t.pixelRatio||1,i=await(0,gif_lib_1.createGIF)({width:e.width*a,height:e.height*a}),o=1e3/(t.fps||10),n=e.duration/o;for(let t=0;t<n-1;t++){const n=t*o||1;e.setCurrentTime(n);let s=0,r="";for(const t of e.pages)if(s+=t.duration,t.set({_rendering:s>n}),s>n){r=t.id;break}const l=await e._toCanvas({pixelRatio:a,pageId:r});i.addFrame(l.getContext("2d"),{delay:o,copy:!0})}for(const t of e.pages)t.set({_rendering:!1});e.stop(),i.render();return new Promise((e=>{i.on("finished",(function(t){!function(e,t){var a=new FileReader;a.onload=function(e){t(e.target.result)},a.readAsDataURL(e)}(t,e)}))}))},async saveAsGIF(t={}){var{fileName:a}=t,i=__rest(t,["fileName"]);const o=await e.toGIFDataURL(i);(0,download_1.downloadFile)(o,a||"polotno.gif")},async toHTML({elementHook:t}={elementHook:void 0}){const a=e.toJSON();return(0,html_1.jsonToHTML)({json:a,elementHook:t})},async saveAsHTML({fileName:t}={}){const a=await e.toHTML(),i="data:text/html;base64,"+window.btoa(unescape(encodeURIComponent(a)));(0,download_1.downloadFile)(i,t||"polotno.html")},async toSVG(){const t=e.toJSON();return(0,to_svg_1.jsonToSVG)({json:t})},async saveAsSVG({fileName:t}={}){const a=await e.toSVG(),i="data:text/svg;base64,"+window.btoa(unescape(encodeURIComponent(a)));(0,download_1.downloadFile)(i,t||"polotno.svg")},async saveAsPDF(t={}){var{fileName:a}=t,i=__rest(t,["fileName"]);(await e._toPDF(Object.assign({mimeType:"image/jpeg"},i))).save(a||"polotno.pdf")},async waitLoading(){await new Promise((e=>setTimeout(e,50))),await(0,loader_1.whenLoaded)()},toJSON:()=>({width:e.width,height:e.height,fonts:(0,mobx_state_tree_1.getSnapshot)(e.fonts),pages:(0,mobx_state_tree_1.getSnapshot)(e.pages),unit:e.unit,dpi:e.dpi,custom:e.custom}),loadJSON(t,a=!1){var i;const o=Object.assign({},t),n=e.pages.indexOf(e.activePage);let s=null===(i=o.pages[n]||o.pages[0])||void 0===i?void 0:i.id;o._activePageId=s;const r=Object.assign({},(0,mobx_state_tree_1.getSnapshot)(e));Object.assign(r,o),r.history=a?e.history.toJSON():{history:[],undoIdx:-1},(0,mobx_state_tree_1.applySnapshot)(e,r)},clear({keepHistory:t=!1}={}){const a=e.pages.map((e=>e.id));e.deletePages(a),t||e.history.clear()},addFont(t){e.removeFont(t.fontFamily),e.fonts.push(t),e.loadFont(t.fontFamily)},removeFont(t){e.fonts.filter((e=>e.fontFamily===t)).forEach((e=>(0,mobx_state_tree_1.destroy)(e)))},async loadFont(t){const a=e.fonts.find((e=>e.fontFamily===t))||fonts.globalFonts.find((e=>e.fontFamily===t));a?fonts.injectCustomFont(a):fonts.injectGoogleFont(t),await fonts.loadFont(t)},validate:e=>exports.Store.validate(e,[{path:"",type:exports.Store}]).map((e=>({path:"store"+e.context.map((e=>e.path)).join("."),message:e.message})))}))),exports.createStore=createStore,exports.default=createStore;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polotno",
3
- "version": "2.4.25",
3
+ "version": "2.4.26",
4
4
  "description": "Design Editor Framework",
5
5
  "author": "Anton Lavrenov",
6
6
  "keywords": [
package/polotno.bundle.js CHANGED
@@ -39,7 +39,7 @@ For more info see: https://github.com/konvajs/react-konva/issues/194
39
39
  color: ${o.color};
40
40
  opacity: 0.6;
41
41
  }
42
- `;iH.innerHTML="",iH.appendChild(document.createTextNode(n)),JSON.stringify(e)!==JSON.stringify(o)&&a(e)});let u=s(y).useRef(null);s(y).useEffect(()=>{let e=setTimeout(()=>{let e=u.current;if(!e)return;u.current?.focus();let t=i||e.value.length;e.selectionStart=e.selectionEnd=t,r&&(e?.select(),document.execCommand("selectAll",!1,null))});return()=>{clearTimeout(e)}},[]),s(y).useEffect(()=>{window.addEventListener("blur",n);let e=e=>{u.current?.contains(e.target)||n()};return window.addEventListener("touchstart",e),()=>{window.removeEventListener("blur",n),window.removeEventListener("touchstart",e)}},[]);let c=0,d=l.textArr.length*l.lineHeight()*l.fontSize();"middle"===t.verticalAlign&&(c=(t.a.height-d)/2),"bottom"===t.verticalAlign&&(c=t.a.height-d);let h=iL(t.text);return(0,g.jsx)(r4,{children:(0,g.jsx)("textarea",{className:"polotno-input",ref:u,dir:iq(h),style:{...iV,...o,paddingTop:c+"px"},value:h,onChange:e=>{t.set({text:e.target.value})},placeholder:t.placeholder,onBlur:n})})}),iW=e=>{let[t,n]=s(y).useState(!1),r=s(y).useRef(!1);return s(y).useEffect(()=>{var t=!0;return setTimeout(()=>{t&&(e._editModeEnabled&&(r.current=!0),n(!0),setTimeout(()=>{r.current=!1},50))},50),()=>{t=!1}},[]),{editorEnabled:t&&e._editModeEnabled,selectAll:r.current}},i$=(e,t)=>{let[n,r]=s(y).useReducer(e=>e+1,0),i=s(y).useRef(ik(t));return s(y).useLayoutEffect(()=>{if(i.current=ik(t),i.current)return;let n=!0;return(async()=>{i.current=!1,r();let o=im(`text ${t}`);await e.loadFont(t),setTimeout(o,100),n&&(i.current=!0,r())})(),()=>{n=!1}},[t]),[i.current]},iK=({fontLoaded:e,fontFamily:t,fontSize:n,lineHeight:r})=>s(y).useMemo(()=>{if("number"==typeof r)return r;let e=document.createElement("div");e.style.fontFamily=t,e.style.fontSize=n+"px",e.style.lineHeight=r,e.innerText="Test text",document.body.appendChild(e);let i=e.offsetHeight;return document.body.removeChild(e),i/n},[e,t,n,r]);function iY(e){let t=s(y).useRef(e),n=s(y).useRef(e);return s(y).useMemo(()=>{n.current=t.current,t.current=e},[e]),n.current}let iX=T(({element:e,store:t})=>{let n=s(y).useRef(null),r=s(y).useRef(null),{editorEnabled:i,selectAll:o}=iW(e),[a,l]=s(y).useState(!1),[u,c]=s(y).useState(!1),d=s(y).useRef(e.a.height),h=t.selectedElements.indexOf(e)>=0,{textVerticalResizeEnabled:f}=iN,p=iY(e.fontFamily),[m,v]=s(y).useState([]);s(y).useEffect(()=>{let e=n.current?.textArr??[];JSON.stringify(e)!==JSON.stringify(m)&&v(e)}),s(y).useEffect(()=>{if(e.a.width)return;let t=n.current;t.width(600),e.set({width:1.4*t.getTextWidth()})},[]),s(y).useLayoutEffect(()=>(0,b.autorun)(()=>{iI(n.current,e)}));let[w]=i$(t,e.fontFamily),x=iL(e.text),_=()=>{let e=n.current.clone({height:void 0}),t=Math.ceil(e.fontSize()*e.lineHeight()*e.textArr.length+1);return e.destroy(),t};s(y).useLayoutEffect(()=>{if(!w)return;let{textOverflow:r}=iN;if(!e.a.height){let n=_();t.history.ignore(()=>{e.set({height:n})},!1,!0);return}if("change-font-size"!==r||u||t.isPlaying){if("resize"===r){let r=_();f&&e.a.height<r&&t.history.ignore(()=>{(0,iU.isAlive)(e)&&e.set({height:r}),n.current?.height(r)},!1,!0),f||e.a.height===r||t.history.ignore(()=>{(0,iU.isAlive)(e)&&e.set({height:r}),n.current?.height(r)},!1,!0)}}else{let r=function(e,t){let n=e.fontSize(),r=e.height(),i=iL(t.text),o=t.a.fontSize;e.height(void 0);let a=Math.round(2*t.a.fontSize)-1;for(let n=1;n<a;n++){let n=t.a.height&&e.height()>t.a.height,r=i.split("\n").join(" ").split(/[\s-]+/),a=e.textArr.map(e=>e.text).join(";"),l=r.find(e=>!a.includes(e)||(a=a.replace(e,""),!1));if(!(n||l))break;o-=.5,e.fontSize(o)}return e.fontSize(n),e.height(r),o}(n.current,e);if(r!==e.a.fontSize){t.history.ignore(()=>{e.set({fontSize:r})},!1,!0);return}let i=_();e.a.height===i||f||t.history.ignore(()=>{e.set({height:i})},!1,!0)}}),s(y).useLayoutEffect(()=>{let t=n.current;t&&(t.width(t.width()+1e-8),t._setTextData(),iI(t,e))},[w]);let E=s(y).useRef(null),S=s(y).useRef(0),C=n=>{n.evt.preventDefault(),t.selectedShapes.find(t=>t===e)&&e.contentEditable&&(S.current=function(e){var t,n;let r=e.target,i=((t=r.getAbsoluteTransform().copy()).invert(),n=r.getStage().getPointerPosition(),t.point(n)),o=r.textArr,a=Math.floor(i.y/(r.fontSize()*r.lineHeight())),l=o.slice(0,a).reduce((e,t)=>e+t.text.length,a),s=o[a]??o[0],u=0;return"right"===r.align()?u=r.width()-s.width:"center"===r.align()&&(u=r.width()/2-s.width/2),l+Math.round((i.x-u)/s.width*s.text.length)}(n),e.toggleEditMode())},O=!x&&e.placeholder?.6:e.a.opacity;id(n,O);let k=iK({fontLoaded:w,fontFamily:e.fontFamily,fontSize:e.a.fontSize,lineHeight:e.lineHeight}),P=e.selectable||"admin"===t.role,T=iu(e),A=s(y).useMemo(()=>e.backgroundEnabled?function({lines:e,lineHeight:t,width:n,align:r="left",padding:i=0,cornerRadius:o=0}){let a,l;e.forEach((e,t)=>{e.cx=n/2,"right"===r?e.cx=n-e.width/2:"left"===r&&(e.cx=e.width/2),"justify"!==r||e.lastInParagraph||(e.width=n),"justify"===r&&(e.cx=e.width/2)});let s=`M ${e[0]?.cx} ${-i}`;e.forEach((n,r)=>{let{cx:o}=n,a=e[r-1];a&&a.width>n.width?s+=` L ${o+n.width/2+i} ${r*t+i}`:s+=` L ${o+n.width/2+i} ${r*t-i}`;let l=e[r+1];l&&l.width>n.width?s+=` L ${o+n.width/2+i} ${(r+1)*t-i}`:s+=` L ${o+n.width/2+i} ${(r+1)*t+i}`});for(var u,c=e.length-1;c>=0;c--){let n=e[c],{cx:r}=n,o=e[c+1];o&&o.width>n.width?s+=` L ${r-n.width/2-i} ${(c+1)*t-i}`:s+=` L ${r-n.width/2-i} ${(c+1)*t+i}`;let a=e[c-1];a&&a.width>n.width?s+=` L ${r-n.width/2-i} ${c*t+i}`:s+=` L ${r-n.width/2-i} ${c*t-i}`}return(u=function(e){let t=/-?[0-9]*\.?\d+/g;return[...e.matchAll(/[MmLlSsQqLlHhVvCcSsQqTtAaZz]/g)].map(e=>({marker:e[0],index:e.index})).reduceRight((t,n)=>{let r=e.substring(n.index,t.length?t[t.length-1].index:e.length);return t.concat([{marker:n.marker,index:n.index,chunk:r.length>0?r.substr(1,r.length-1):r}])},[]).reverse().flatMap(e=>{let n=e.chunk.match(t),r=n?n.map(parseFloat):[];return function(e,t){let n=[];switch(e.toUpperCase()){case"M":for(let r=0;r<t.length;r+=2){let i;i=e===e.toUpperCase()?0===r?"M":"L":0===r?"m":"l",n.push({marker:i,values:{x:t[r],y:t[r+1]}})}break;case"L":for(let r=0;r<t.length;r+=2)n.push({marker:e,values:{x:t[r],y:t[r+1]}});break;case"H":for(let r=0;r<t.length;r++)n.push({marker:e,values:{x:t[r],y:0}});break;case"V":for(let r=0;r<t.length;r++)n.push({marker:e,values:{x:0,y:t[r]}});break;case"C":for(let r=0;r<t.length;r+=6)n.push({marker:e,values:{x1:t[r],y1:t[r+1],x2:t[r+2],y2:t[r+3],x:t[r+4],y:t[r+5]}});break;case"S":for(let r=0;r<t.length;r+=4)n.push({marker:e,values:{x2:t[r],y2:t[r+1],x:t[r+2],y:t[r+3]}});break;case"Q":for(let r=0;r<t.length;r+=4)n.push({marker:e,values:{x1:t[r],y1:t[r+1],x:t[r+2],y:t[r+3]}});break;case"T":for(let r=0;r<t.length;r+=2)n.push({marker:e,values:{x:t[r],y:t[r+1]}});break;case"A":for(let r=0;r<t.length;r+=7)n.push({marker:e,values:{radiusX:t[r],radiusY:t[r+1],rotation:t[r+2],largeArc:t[r+3],sweep:t[r+4],x:t[r+5],y:t[r+6]}});break;case"Z":n.push({marker:e,values:{x:0,y:0}})}return n}(e.marker,r)}).map(r9)}(s+=" Z"),a=[],l=[],u.forEach(e=>{"M"===e.marker&&a.push([]),a[a.length-1].push(e)}),a.forEach(e=>{e.map(r7),function e(t,n){let r=["x","y"].every(e=>0===Math.round(Math.abs(t[n].values[e]-t[0].values[e])));"L"===t[n].marker&&r&&(t[n].overlap=!0,e(t,n-1)),"Z"===t[n].marker&&e(t,n-1)}(e,e.length-1);let t="Z"==e[e.length-1].marker;e.filter(e=>!e.overlap).map((e,n,r)=>{let i,a,s;let u=function e(t,n,r){var i;let o=n-1,a=r[(o%(i=r.length)+i)%i];return"Z"!==a.marker?a:e(t,o,r)}(e,n,r),c=function e(t,n,r){var i;let o=n+1,a=r[(o%(i=r.length)+i)%i];return"Z"===a.marker?e(t,o,r):a}(e,n,r),d=ie(e.values,u.values),h=ie(e.values,c.values),f=h-d,p=180/Math.PI*f,g=Math.min(o,Math.abs(function(e,t,n){let r=it(e.values,n.values);return Math.min(it(t.values,e.values),r)}(e,u,c)/2*Math.tan(f/2))),m=(a=0,(s=180/Math.PI*f)<0&&s>=-180||s>180&&s<360?i=ir(f/2,-g):(i=ir(f/2,g),a=1,i===1/0&&(i=g)),{offset:i,sweepFlag:a}),v=m.offset,y=m.sweepFlag,b=(0==n||n==r.length-1)&&!t;switch(e.marker){case"M":case"L":let w=[e.values.x+Math.sin(d)*v,e.values.y+Math.cos(d)*v],x=[e.values.x+Math.sin(h)*v,e.values.y+Math.cos(h)*v];b?l.push({marker:e.marker,values:e.values}):l.push({marker:e.marker,values:{x:parseFloat(w[0].toFixed(3)),y:parseFloat(w[1].toFixed(3))}}),b||"L"!==c.marker&&"M"!==c.marker||l.push({marker:"A",radius:g,values:{radiusX:parseFloat(g.toFixed(3)),radiusY:parseFloat(g.toFixed(3)),rotation:p,largeArc:0,sweep:y,x:parseFloat(x[0].toFixed(3)),y:parseFloat(x[1].toFixed(3))}});break;case"C":case"S":case"Q":case"T":case"A":case"Z":l.push({marker:e.marker,values:e.values})}})}),{path:function(e){let t=["radiusX","radiusY","rotation","largeArc","sweep","x1","y1","x2","y2","x","y"];return e.map(e=>{let n="";if("Z"!==e.marker){let r=Object.keys(e.values);n=t.filter(e=>-1!==r.indexOf(e)).map(t=>e.values[t]).join()}return`${e.marker}${n}`}).join("").trim()}(l),commands:l}).path}({lines:JSON.parse(JSON.stringify(m)),cornerRadius:e.backgroundCornerRadius*(e.a.fontSize*k*.5),lineHeight:k*e.a.fontSize,padding:e.backgroundPadding*(e.a.fontSize*k*.5),width:e.a.width,align:e.align}):"",[e.backgroundEnabled,e.backgroundCornerRadius,e.a.fontSize,k,e.backgroundPadding,e.a.width,e.align,m]),N=iB(),j=0;return"middle"===e.verticalAlign?j=(e.a.height-m.length*k*e.a.fontSize)/2:"bottom"===e.verticalAlign&&(j=e.a.height-m.length*k*e.a.fontSize),(0,g.jsxs)(s(y).Fragment,{children:[(0,g.jsx)(rJ,{ref:r,x:e.a.x,y:e.a.y,rotation:e.a.rotation,hideInExport:!e.showInExport||!x,listening:!1,visible:e.backgroundEnabled,opacity:e.backgroundOpacity,data:A,fill:e.backgroundColor,offsetY:-j}),(0,g.jsx)(rQ,{ref:n,id:e.id,name:"element",hideInExport:!e.showInExport||!x,editModeEnabled:e._editModeEnabled,x:e.a.x,y:e.a.y,rotation:e.a.rotation,width:e.a.width,height:e.a.height,text:x||e.placeholder,...T,stroke:e.stroke,lineJoin:"round",strokeWidth:e.strokeWidth,fillAfterStrokeEnabled:!0,fontSize:e.a.fontSize,fontFamily:`"${e.fontFamily}", "${p}"`,fontStyle:e.fontStyle+" "+e.fontWeight,textDecoration:e.textDecoration,align:e.align,verticalAlign:e.verticalAlign,draggable:N?e.draggable&&h:e.draggable,preventDefault:!N||h,opacity:O,visible:!e._editModeEnabled,ellipsis:"ellipsis"===iN.textOverflow,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,lineHeight:k,letterSpacing:e.letterSpacing*e.a.fontSize,listening:P,onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},onMouseEnter:()=>{l(!0)},onMouseLeave:()=>{l(!1)},onClick:C,onTap:C,onTransformStart:()=>{c(!0),d.current=n.current.height()},onTransform:t=>{let n=t.target;r.current?.setAttrs({x:n.x(),y:n.y(),rotation:n.rotation(),scale:n.scale()});let i=(n.getStage()?.findOne("Transformer")).getActiveAnchor();if("middle-left"===i||"middle-right"===i){let t=n.scaleX(),r=n.width()*t,i=e.a.fontSize,o=r;r<i&&(o=i,E.current&&n.position(E.current)),n.width(o),n.scaleX(1),n.scaleY(1);let a=_();if("ellipsis"!==iN.textOverflow){let t=Math.max(a,d.current);n.height(t),e.set({height:n.height()})}e.set({x:n.x(),y:n.y(),width:n.width(),rotation:n.rotation()}),iI(n,e)}if("top-center"===i||"bottom-center"===i){let n="resize"===iN.textOverflow?_():k*e.a.fontSize;t.target.height(Math.max(n,t.target.height()*t.target.scaleY())),t.target.scaleY(1)}E.current=t.target.position()},onTransformEnd:t=>{let n=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),e.set({fontSize:Math.round(e.a.fontSize*n),width:Math.ceil(t.target.width()*n),x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),height:t.target.height()*n,shadowBlur:e.shadowBlur*n,shadowOffsetX:e.shadowOffsetX*n,shadowOffsetY:e.shadowOffsetY*n,strokeWidth:e.strokeWidth*n}),r.current?.setAttrs({scaleX:1,scaleY:1}),c(!1)}}),i&&(0,g.jsx)(r$,{x:e.a.x,y:e.a.y,rotation:e.a.rotation,children:(0,g.jsx)(iG,{textNodeRef:n,element:e,selectAll:o,cursorPosition:S.current,onBlur:()=>{e.toggleEditMode(!1)}})}),!u&&(a||h)&&(0,g.jsx)(iD,{element:e})]})});var y=f("8NFma"),b=f("2SBKn"),y=f("8NFma");function iZ(e){let t={fill:"",stroke:""};if(e.getAttribute("fill")&&"none"!==e.getAttribute("fill")&&(t.fill=e.getAttribute("fill")),!t.fill&&e.style.fill&&"none"!==e.style.fill&&(t.fill=e.style.fill),e.getAttribute("stroke")&&(t.stroke=e.getAttribute("stroke")),!t.stroke&&e.style.stroke&&(t.stroke=e.style.stroke),!t.stroke&&!t.fill){let n=e.ownerSVGElement,r=n&&n!==e&&iZ(n);r?.fill==="currentColor"||r?.stroke==="currentColor"||(t.fill="black")}return t}let iQ=["path","rect","circle"];function iJ(e){for(var t=[],n=e.getElementsByTagName("*"),r=0,i=n.length;r<i;r++){let e=n[r];!function(e){for(;e.parentNode;){if("defs"===e.nodeName)return!0;e=e.parentNode}return!1}(e)&&(null!==e.getAttribute("fill")&&t.push(e),null!==e.getAttribute("stroke")?t.push(e):e.style&&e.style.fill?t.push(e):iQ.indexOf(e.nodeName)>=0&&t.push(e))}return t}async function i0(e){let t=await fetch(e);return i2(await t.text())}async function i1(e){let t=await fetch(e,{mode:"cors"});return await t.text()}function i2(e){return"data:image/svg+xml;base64,"+window.btoa(unescape(encodeURIComponent(e)))}async function i3(e){let t=await i1(e),n=new DOMParser().parseFromString(t,"image/svg+xml").documentElement.getAttribute("viewBox"),[r,i,o,a]=n?.split(" ")||[];return{width:parseFloat(o),height:parseFloat(a)}}function i5(e){var t=new DOMParser().parseFromString(e,"image/svg+xml");let n=t.documentElement.getAttribute("viewBox"),[r,i,o,a]=n?.split(" ")||[],l=t.documentElement.getAttribute("width");l||t.documentElement.setAttribute("width",o+"px");let s=t.documentElement.getAttribute("height");if((!s||s.indexOf("%")>=0)&&t.documentElement.setAttribute("height",a+"px"),l&&l.indexOf("%")>=0&&s&&-1===s.indexOf("%")){let e=parseFloat(s)/parseFloat(a);t.documentElement.setAttribute("width",e*parseFloat(o)+"px")}if(s&&s.indexOf("%")>=0&&l&&-1===l.indexOf("%")){let e=parseFloat(l)/parseFloat(o);t.documentElement.setAttribute("height",e*parseFloat(a)+"px")}return"100%"===l&&"100%"===s&&(t.documentElement.setAttribute("width",o+"px"),t.documentElement.setAttribute("height",a+"px")),new XMLSerializer().serializeToString(t)}let i6=(e,t)=>{if(!e||!t)return!1;if("currentColor"===t&&"black"===e)return!0;let n=s(N).Util.colorToRGBA(e),r=s(N).Util.colorToRGBA(t);if(n&&r)return n.r===r.r&&n.g===r.g&&n.b===r.b&&n.a===r.a};function i4(e,t){var n=new DOMParser().parseFromString(e,"image/svg+xml");let r=iJ(n),i=Array.from(t.keys());return r.forEach(e=>{let{fill:r,stroke:o}=iZ(e);[{prop:"fill",color:r},{prop:"stroke",color:o}].forEach(({prop:r,color:o})=>{let a=i.find(e=>i6(e,o));if(a){let i=t.get(a);if(ia(i)){let{rotation:t,stops:o}=is(i),a=o.map(e=>({offset:100*e.offset+"%","stop-color":e.color})),l="color"+Math.round(1e8*Math.random());(function(e,t,n,r){var i=e.namespaceURI,o=document.createElementNS(i,"linearGradient");let a=s(N).Util.degToRad(n+90),l=(Math.cos(a)+1)/2,u=(Math.sin(a)+1)/2,c=(Math.cos(a+Math.PI)+1)/2,d=(Math.sin(a+Math.PI)+1)/2;o.setAttribute("x1",100*l+"%"),o.setAttribute("y1",100*u+"%"),o.setAttribute("x2",100*c+"%"),o.setAttribute("y2",100*d+"%"),o.setAttribute("gradientUnits","userSpaceOnUse"),o.setAttribute("id",t);for(var h=0;h<r.length;h++){var f=r[h],p=document.createElementNS(i,"stop");for(var g in f)f.hasOwnProperty(g)&&p.setAttribute(g,f[g]);o.appendChild(p)}(e.querySelector("defs")||e.insertBefore(document.createElementNS(i,"defs"),e.firstChild)).appendChild(o)})(n.children[0],l,t,a),e.style[r]=null,e.setAttribute(r,`url('#${l}')`)}else e.style[r]=t.get(a)}})}),i2(new XMLSerializer().serializeToString(n))}let i8=e=>{let[t,n]=s(y).useState([]);return s(y).useEffect(()=>{let t=!1;return(async()=>{n([]);let r=function(e){let t=iJ(new DOMParser().parseFromString(e,"image/svg+xml")),n=[];return t.forEach(e=>{let{fill:t,stroke:r}=iZ(e);[t,r].forEach(e=>{e&&("currentColor"===e&&(e="black"),s(N).Util.colorToRGBA(e)&&-1===n.indexOf(e)&&n.push(e))})}),n}(await i1(e));t||n(r)})(),()=>{t=!0}},[e]),t};function i9(){return document.createElement("canvas")}async function i7(e){return e.indexOf("data:image/svg+xml")>=0||e.indexOf(".svg")>=0?i2(i5(await i1(e))):e}let oe=e=>{let[t,n]=s(y).useState(e);return s(y).useEffect(()=>{(async()=>{let r=await i7(e);r!==t&&n(r)})()},[e]),t};function ot(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2}}let on=(e,t,n)=>{let r=s(y).useMemo(()=>{let{flipX:r,flipY:i}=e,o="svg"===e.type||e.src.indexOf("data:image/svg+xml")>=0||e.src.indexOf(".svg")>=0,a=navigator.userAgent.toLowerCase().indexOf("firefox")>-1&&o||e.maskSrc;if(!r&&!i&&!a)return t;if(!t||!t.width||!t.height)return null;let l=i9(),s=1;"svg"===e.type&&(s=Math.max(e.a.width/t.width*n,e.a.height/t.height*n)),l.width=Math.max(t.width*s,1),l.height=Math.max(t.height*s,1);let u=r?-l.width:0,c=i?-l.height:0;return l.getContext("2d")?.scale(r?-1:1,i?-1:1),l.getContext("2d")?.drawImage(t,u,c,l.width,l.height),l},[e.maskSrc,e.flipX,e.flipY,t,e.a.width,e.a.height,n]);return s(y).useEffect(()=>()=>{r&&"CANVAS"===r.nodeName&&s(N).Util.releaseCanvas(r)},[r]),r},or=(e,t)=>{let[n,r]=ou(e.maskSrc,"anonymous");return oc(e.maskSrc?r:"loaded",e.id+"-mask"),s(y).useMemo(()=>{if(!n||!t||!t.width||!t.height)return t;let r=i9();r.width=Math.max(t.width,1),r.height=Math.max(t.height,1);let i=r.getContext("2d");if(!i)return t;i.drawImage(t,0,0),i.globalCompositeOperation="source-in";let o=function(e,t){let n,r;let i=t.width/t.height;return i>=e.width/e.height?(n=e.width,r=e.width/i):(n=e.height*i,r=e.height),{x:(e.width-n)/2,y:(e.height-r)/2,width:n,height:r}}(n,e);return i.drawImage(n,o.x,o.y,o.width,o.height,0,0,t.width,t.height),r},[t,n,e.a.width,e.a.height])},oi=(e,t,n,r,i=0,o=!1)=>{let a=Math.floor(Math.max(e.a.width*r,1)),l=Math.floor(Math.max(e.a.height*r,1)),u=Math.min(i*r,a/2,l/2),c=Math.max(e.a.width/n.width,e.a.height/n.height)*r,d=e.page._exporting&&iN.imageDownScalingEnabled&&c<1&&!o,h=0===n.x&&0===n.y&&n.width===t?.width&&n.height===t?.height,f=s(y).useMemo(()=>{if(!t||!t.width||!t.height)return;let e=0===u,n=!d;if(!h||!e||!n)return i9()},[t,u,d,h]);return s(y).useLayoutEffect(()=>{if(!f||!t)return;f.width=a,f.height=l;let e=f.getContext("2d");if(!e)return;u&&(e.beginPath(),e.moveTo(u,0),e.lineTo(a-u,0),e.arc(a-u,u,u,3*Math.PI/2,0,!1),e.lineTo(a,l-u),e.arc(a-u,l-u,u,0,Math.PI/2,!1),e.lineTo(u,l),e.arc(u,l-u,u,Math.PI/2,Math.PI,!1),e.lineTo(0,u),e.arc(u,u,u,Math.PI,3*Math.PI/2,!1),e.clip());let r=d?function(e,t){let n=i9();n.width=e.width,n.height=e.height;let r=Math.max(1,Math.floor(n.width*t)),i=Math.max(1,Math.floor(n.height*t));n.getContext("2d")?.drawImage(e,0,0,n.width,n.height);let o=function(e,t,n,r,i,o,a){for(var l=new ImageData(t,n),s=new Int32Array(e.data.buffer),u=e.width,c=new Int32Array(l.data.buffer),d=l.width,h=t/o,f=n/a,p=Math.round(1/h),g=Math.round(1/f),m=p*g,v=0;v<l.height;v++)for(var y=0;y<d;y++){for(var b=0+Math.round(y/h)+(0+Math.round(v/f))*u,w=0,x=0,_=0,E=0,S=0;S<g;S++)for(var C=0;C<p;C++){var O=s[b+C+S*u];w+=O<<24>>>24,x+=O<<16>>>24,_+=O<<8>>>24,E+=O>>>24}w=Math.round(w/m),x=Math.round(x/m),_=Math.round(_/m),E=Math.round(E/m),c[y+v*d]=E<<24|_<<16|x<<8|w}return l}(n.getContext("2d").getImageData(0,0,n.width,n.height),r,i,0,0,n.width,n.height);return n.width=r,n.height=i,n.getContext("2d")?.putImageData(o,0,0),n}(t,c):t,i=d?{x:Math.floor(n.x*c),y:Math.floor(n.y*c),width:Math.floor(n.width*c),height:Math.floor(n.height*c)}:n;e.drawImage(r,i.x,i.y,i.width,i.height,0,0,f.width,f.height)},[f,e.a.width,e.a.height,n.x,n.y,n.width,n.height,i,r,o,e.page._exporting,d]),s(y).useEffect(()=>()=>{f&&"CANVAS"===f.nodeName&&s(N).Util.releaseCanvas(f)},[f]),f||t},oo=(e,t,n,r)=>{let[i,o]=ou(oe(e.clipSrc||""),"anonymous");oc(e.clipSrc?o:"loaded",e.id+"-clip");let a=s(y).useMemo(()=>{if(t&&i)return i9()},[t,i]);return s(y).useLayoutEffect(()=>{if(!i||!t||!t.width||!t.height||!i||!i.width||!i.height||!a)return;let r=i9(),o=Math.max(e.a.width/i.width*n,e.a.height/i.height*n);r.width=i.width*o,r.height=i.height*o,r.getContext("2d")?.drawImage(i,0,0,r.width,r.height),a.width=Math.max(t.width,1),a.height=Math.max(t.height,1);let l=a.getContext("2d");l&&(l.save(),l.drawImage(r,0,0,t.width,t.height),s(N).Util.releaseCanvas(r),l.globalCompositeOperation="source-in",l.drawImage(t,0,0,a.width,a.height),l.restore())},[a,t,i,e.a.width,e.a.height,n,...r]),e.clipSrc&&i?a:t},oa=i9(),ol=T(({element:e})=>{let t=Math.min(30,e.a.width/4,e.a.height/4),n=s(y).useRef(null);return s(y).useEffect(()=>{let e=n.current;if(!e)return;let t=new(s(N)).Animation(t=>{e.rotate((t?.timeDiff||0)/2)},e.getLayer());return t.start(),()=>{t.stop()}}),(0,g.jsxs)(r$,{x:e.x,y:e.y,rotation:e.rotation,listening:!1,opacity:e.a.opacity,hideInExport:!e.showInExport,children:[(0,g.jsx)(rY,{width:e.a.width,height:e.a.height,fill:"rgba(124, 173, 212, 0.8)"}),(0,g.jsx)("Arc",{ref:n,x:e.a.width/2,y:e.a.height/2,fill:"white",outerRadius:Math.abs(t),innerRadius:Math.max(1,t-5),angle:270})]})}),os=T(({element:e})=>{let t="Can not load the image...",n=Math.max(10,Math.min(30,e.a.width/t.length));return(0,g.jsxs)(r$,{x:e.x,y:e.y,rotation:e.rotation,listening:!1,opacity:e.a.opacity,hideInExport:!e.showInExport,children:[(0,g.jsx)(rY,{width:e.a.width,height:e.a.height,fill:"rgba(223, 102, 102, 0.8)"}),(0,g.jsx)(rQ,{text:t,fontSize:n,width:e.a.width,height:e.a.height,align:"center",fill:"white",verticalAlign:"middle",padding:5})]})}),ou=s(r3),oc=(e,t)=>{let n=s(y).useRef(),r=()=>{n.current?.(),n.current=void 0};s(y).useEffect(()=>r,[]),s(y).useLayoutEffect(()=>{"loading"!==e||n.current||(n.current=im(`image ${t}`)),"loading"!==e&&r(),"failed"===e&&ib(`image ${t}`)},[e])},od=({image:e,status:t,type:n})=>{let r=s(y).useRef();return s(y).useEffect(()=>{r.current=e||r.current},[e]),"failed"!==t||"failed"!==t&&"svg"===n?r.current:void 0},oh=e=>{let[t,n]=s(y).useReducer(e=>e+1,0),r=s(y).useRef("loading"),i=s(y).useRef(e.src),o=s(y).useRef(e.src);return(o.current!==e.src&&(o.current=e.src,r.current="loading"),s(y).useEffect(()=>{if("svg"!==e.type||!e.src)return;let t=!1;return(async()=>{r.current="loading",n();let o=i4(i5(await i1(e.src)),e.colorsReplace);t||(i.current=o,r.current="loaded",n())})(),()=>{t=!0}},[e.src,JSON.stringify(e.colorsReplace)]),"svg"!==e.type)?[e.src,"loaded"]:[i.current,r.current]},of=T(({element:e,store:t})=>{let n,r;let[i,o]=s(y).useState(!1),a=s(y).useRef(null),l=s(y).useRef(null),[u,c]=s(y).useState(!1),d=t.selectedElements.indexOf(e)>=0,[h,f]=oh(e),[p,m]=ou(h,"anonymous");oc("svg"!==e.type||"loaded"===f?m:"loading",e.id);let v=od({image:p,status:m,type:e.type}),w=or(e,on(e,p||v,t._elementsPixelRatio))||oa,{cropX:x,cropY:_,cropWidth:E,cropHeight:S}=e;"loaded"!==m&&(x=_=0,E=S=1);let C=w.width*E,O=w.height*S,k=e.a.width/e.a.height,P=C/O,T="svg"===e.type;T?(n=C,r=O):k>=P?(n=C,r=C/k):(n=O*k,r=O);let A={x:w.width*x,y:w.height*_,width:n,height:r},j=e.cornerRadius??0,R=e.page._exporting?1:Math.min(2,t.scale),L=t._elementsPixelRatio*R,I=oo(e,oi(e,w,A,L,j,i||e._cropModeEnabled||"svg"===e.type),L,[A,j,L]),M=Math.max(e.a.width/n,e.a.height/r);s(y).useEffect(()=>{if(!e._cropModeEnabled)return;let t=a.current?.getStage();function n(t){e._cropModeEnabled&&t.target!==l.current&&e.toggleCropMode(!1)}function r(n){e._cropModeEnabled&&n.target.parentNode!==t.content&&e.toggleCropMode(!1)}return document.body.addEventListener("click",r),t?.on("click",n),t?.on("tap",n),()=>{document.body.removeEventListener("click",r),document.body.removeEventListener("touchstart",r),t?.off("click",n),t?.off("click",n)}},[e._cropModeEnabled]),s(y).useLayoutEffect(()=>{if(!i&&!e._cropModeEnabled)return iI(a.current,e),(0,b.autorun)(()=>{iI(a.current,e)},{delay:100})},[w,i,E,S,e._cropModeEnabled]),s(y).useLayoutEffect(()=>{i||e._cropModeEnabled?a.current?.clearCache():iI(a.current,e)},[i,e.a.width,e.a.height,e._cropModeEnabled]),s(y).useEffect(()=>{iI(a.current,e)},[e.shadowEnabled,e.shadowBlur,e.cornerRadius,e.shadowColor,e.shadowOffsetX,e.shadowOffsetY,e.shadowOpacity]);let D=s(y).useRef(null),F=s(y).useRef(null),z=s(y).useRef(null);s(y).useLayoutEffect(()=>{e._cropModeEnabled&&(F.current.nodes([D.current]),z.current.nodes([l.current]))},[e._cropModeEnabled]);var B=s(y).useRef(null),U=s(y).useRef(0),H=s(y).useRef(!1);let V=t=>{t.evt.touches?.length>2&&t.target.stopDrag(),Math.round(t.target.x())>0&&(t.target.x(0),t.target.scaleX(1)),Math.round(t.target.y())>0&&(t.target.y(0),t.target.scaleY(1));let i=t.target.width()*t.target.scaleX(),o=t.target.height()*t.target.scaleY(),a=Math.min(1,n/i),l=Math.min(1,r/o),s=Math.min(1-a,Math.max(0,Math.round(-t.target.x())/i)),u=Math.min(1-l,Math.max(0,Math.round(-t.target.y())/o));t.target.setAttrs({x:-s*w.width,y:-u*w.height,scaleX:1,scaleY:1}),e.set({cropX:s,cropY:u,cropWidth:a,cropHeight:l})},q=()=>{"svg"!==e.type&&e.contentEditable&&setTimeout(()=>{e.toggleCropMode(!0)})},G="svg"===e.type&&v,W="loading"===m&&!G,$="failed"===m,K=!W&&!$,Y=s(y).useRef({cropX:0,cropY:0,cropWidth:0,cropHeight:0}),X=K?e.a.opacity:0;id(a,X);let Z=e.selectable||"admin"===t.role,Q=iB();return(0,g.jsxs)(s(y).Fragment,{children:[W&&(0,g.jsx)(ol,{element:e}),$&&(0,g.jsx)(os,{element:e}),(0,g.jsx)(rZ,{ref:a,name:"element",id:e.id,image:I,x:e.a.x,y:e.a.y,width:e.a.width||1,height:e.a.height||1,rotation:e.rotation,opacity:X,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,customCrop:A,listening:Z,draggable:Q?e.draggable&&d:e.draggable,preventDefault:!Q||d,hideInExport:!e.showInExport,onMouseEnter:()=>{c(!0)},onMouseLeave:()=>{c(!1)},onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDblClick:q,onDblTap:q,onTransformStart:()=>{o(!0),Y.current={cropX:e.cropX,cropY:e.cropY,cropWidth:e.cropWidth,cropHeight:e.cropHeight}},onTransform:t=>{let i=t.currentTarget,o=1e-7>Math.abs(i.scaleX()-1)?1:i.scaleX(),a=1e-7>Math.abs(i.scaleY()-1)?1:i.scaleY();i.scaleX(1),i.scaleY(1);let l=t.target.getStage()?.findOne("Transformer"),s=Math.min(1-n/w.width,Math.max(0,e.cropX)),u=Math.min(1-r/w.height,Math.max(0,e.cropY)),c=l.getActiveAnchor(),d=!(c.indexOf("middle")>=0||c.indexOf("center")>=0),h=!d&&o<1&&Y.current.cropHeight>r/w.height,f=d?e.cropWidth:e.cropWidth*o;h&&(f=e.cropWidth);let p=!d&&a<1&&Y.current.cropWidth>n/w.width,g=d?e.cropHeight:e.cropHeight*a;p&&(g=e.cropHeight),T&&(f=e.cropWidth,g=e.cropHeight),e.set({cropX:s,cropY:u,x:i.x(),y:i.y(),width:i.width()*o,height:i.height()*a,rotation:t.target.rotation(),cropWidth:Math.min(f,1-s),cropHeight:Math.min(g,1-u)})},onTransformEnd:t=>{let i=t.currentTarget;e.set({width:i.width(),height:i.height(),x:i.x(),y:i.y(),rotation:t.target.rotation(),cropWidth:n/w.width,cropHeight:r/w.height}),o(!1)}}),(0,g.jsx)(rY,{x:e.x,y:e.y,width:Math.max(e.a.width-e.borderSize,0),height:Math.max(e.a.height-e.borderSize,0),opacity:X,offsetX:-e.borderSize/2,offsetY:-e.borderSize/2,stroke:e.borderColor,strokeWidth:e.borderSize,listening:!1,visible:!!e.borderSize,rotation:e.rotation,cornerRadius:Math.max(0,j-e.borderSize),hideInExport:!e.showInExport}),e._cropModeEnabled&&(0,g.jsxs)(r8,{selector:".page-abs-container",enabled:!0,children:[(0,g.jsx)(rY,{x:-window.innerWidth/t.scale,y:-window.innerWidth/t.scale,width:window.innerWidth/t.scale*3,height:window.innerWidth/t.scale*3,fill:"rgba(0,0,0,0.3)"}),(0,g.jsx)(rZ,{listening:!1,image:I,x:e.x,y:e.y,width:e.a.width,height:e.a.height,rotation:e.rotation,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur}),(0,g.jsxs)(r$,{x:e.x,y:e.y,rotation:e.rotation,scaleX:M,scaleY:M,children:[(0,g.jsx)(rZ,{image:w,ref:l,opacity:.4,draggable:!0,x:-e.cropX*w.width,y:-e.cropY*w.height,onDragMove:V,onTransform:V,onTouchMove:e=>{e.evt.preventDefault();let t=e.target.getStage().getPointersPositions();var n=t[0],r=t[1];let i=e.target;if(n&&!r&&!i.isDragging()&&H.current&&(i.startDrag(),H.current=!1),n&&r){s(N).hitOnDragEnabled=!0,i.isDragging()&&(H.current=!0,i.stopDrag());let t=e.target.getAbsoluteTransform().copy();t.invert();var o={x:n.x,y:n.y},a={x:r.x,y:r.y};if(!B.current){B.current=ot(o,a);return}var l=ot(o,a),u=Math.sqrt(Math.pow(a.x-o.x,2)+Math.pow(a.y-o.y,2));U.current||(U.current=u);let g=i.position();var c={x:l.x-g.x,y:l.y-g.y},d=u/U.current;i.scaleX(d),i.scaleY(d);let m=t.point(l),v=t.point(B.current);var h=m.x-v.x,f=m.y-v.y,p={x:Math.min(0,l.x-c.x*d+h),y:Math.min(0,l.y-c.y*d+f)};i.position(p),U.current=u,B.current=l,V(e)}},onTouchEnd:e=>{U.current=0,B.current=null,s(N).hitOnDragEnabled=!1}}),(0,g.jsx)(r0,{ref:z,anchorSize:20,enabledAnchors:["top-left","top-right","bottom-left","bottom-right"],boundBoxFunc:(e,t)=>t.width<5||t.height<5?e:t,rotateEnabled:!1,borderEnabled:!1,anchorCornerRadius:10,anchorStrokeWidth:2,borderStrokeWidth:2}),(0,g.jsx)(rY,{width:n,height:r,ref:D,listening:!1,onTransform:t=>{t.target.x()<-e.cropX*w.width-1e-9&&(t.target.x(-e.cropX*w.width),t.target.scaleX(1)),t.target.y()<-e.cropY*w.height-1e-9&&(t.target.y(-e.cropY*w.height),t.target.scaleY(1));let n=Math.min(1,Math.max(0,e.cropX+t.target.x()/w.width)),r=Math.min(1,Math.max(0,t.target.y()/w.height+e.cropY)),i=t.target.width()*t.target.scaleX(),o=t.target.height()*t.target.scaleY(),a=Math.min(1-n,i/w.width),l=Math.min(1-r,o/w.height),s=t.target.getAbsolutePosition(t.target.getParent().getParent());t.target.scale({x:1,y:1}),t.target.position({x:0,y:0}),e.set({x:s.x,y:s.y,cropX:n,cropY:r,cropWidth:a,cropHeight:l,width:Math.min(i*M,w.width*(1-n)*M),height:Math.min(o*M,w.height*(1-r)*M)})}}),(0,g.jsx)(r0,{ref:F,enabledAnchors:["top-left","top-right","bottom-left","bottom-right"],boundBoxFunc:(e,t)=>t.width<5||t.height<5?e:t,visible:e.resizable,keepRatio:!1,rotateEnabled:!1,anchorFill:"rgb(240, 240, 240)",anchorStrokeWidth:2,borderStrokeWidth:2})]})]}),(u||d)&&(0,g.jsx)(iD,{element:e})]})});var y=f("8NFma"),op=f("1BElU");window,kQ=f("1BElU"),function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t||4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,(function(t){return e[t]}).bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(e,t,n){/*! @license DOMPurify 3.0.5 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.0.5/LICENSE */e.exports=function(){let{entries:e,setPrototypeOf:t,isFrozen:n,getPrototypeOf:r,getOwnPropertyDescriptor:i}=Object,{freeze:o,seal:a,create:l}=Object,{apply:s,construct:u}="undefined"!=typeof Reflect&&Reflect;s||(s=function(e,t,n){return e.apply(t,n)}),o||(o=function(e){return e}),a||(a=function(e){return e}),u||(u=function(e,t){return new e(...t)});let c=x(Array.prototype.forEach),d=x(Array.prototype.pop),h=x(Array.prototype.push),f=x(String.prototype.toLowerCase),p=x(String.prototype.toString),g=x(String.prototype.match),m=x(String.prototype.replace),v=x(String.prototype.indexOf),y=x(String.prototype.trim),b=x(RegExp.prototype.test),w=(G=TypeError,function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return u(G,t)});function x(e){return function(t){for(var n=arguments.length,r=Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];return s(e,t,r)}}function _(e,r,i){var o;i=null!==(o=i)&&void 0!==o?o:f,t&&t(e,null);let a=r.length;for(;a--;){let t=r[a];if("string"==typeof t){let e=i(t);e!==t&&(n(r)||(r[a]=e),t=e)}e[t]=!0}return e}function E(t){let n=l(null);for(let[r,i]of e(t))n[r]=i;return n}function S(e,t){for(;null!==e;){let n=i(e,t);if(n){if(n.get)return x(n.get);if("function"==typeof n.value)return x(n.value)}e=r(e)}return function(e){return console.warn("fallback value for",e),null}}let C=o(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dialog","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","section","select","shadow","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]),O=o(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","filter","font","g","glyph","glyphref","hkern","image","line","lineargradient","marker","mask","metadata","mpath","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),k=o(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),P=o(["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"]),T=o(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover","mprescripts"]),A=o(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),N=o(["#text"]),j=o(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","face","for","headers","height","hidden","high","href","hreflang","id","inputmode","integrity","ismap","kind","label","lang","list","loading","loop","low","max","maxlength","media","method","min","minlength","multiple","muted","name","nonce","noshade","novalidate","nowrap","open","optimum","pattern","placeholder","playsinline","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","span","srclang","start","src","srcset","step","style","summary","tabindex","title","translate","type","usemap","valign","value","width","xmlns","slot"]),R=o(["accent-height","accumulate","additive","alignment-baseline","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clippathunits","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dur","edgemode","elevation","end","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","systemlanguage","tabindex","targetx","targety","transform","transform-origin","text-anchor","text-decoration","text-rendering","textlength","type","u1","u2","unicode","values","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]),L=o(["accent","accentunder","align","bevelled","close","columnsalign","columnlines","columnspan","denomalign","depth","dir","display","displaystyle","encoding","fence","frame","height","href","id","largeop","length","linethickness","lspace","lquote","mathbackground","mathcolor","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","numalign","open","rowalign","rowlines","rowspacing","rowspan","rspace","rquote","scriptlevel","scriptminsize","scriptsizemultiplier","selection","separator","separators","stretchy","subscriptshift","supscriptshift","symmetric","voffset","width","xmlns"]),I=o(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),M=a(/\{\{[\w\W]*|[\w\W]*\}\}/gm),D=a(/<%[\w\W]*|[\w\W]*%>/gm),F=a(/\${[\w\W]*}/gm),z=a(/^data-[\-\w.\u00B7-\uFFFF]/),B=a(/^aria-[\-\w]+$/),U=a(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),H=a(/^(?:\w+script|data):/i),V=a(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),q=a(/^html$/i);var G,W=Object.freeze({__proto__:null,MUSTACHE_EXPR:M,ERB_EXPR:D,TMPLIT_EXPR:F,DATA_ATTR:z,ARIA_ATTR:B,IS_ALLOWED_URI:U,IS_SCRIPT_OR_DATA:H,ATTR_WHITESPACE:V,DOCTYPE_NAME:q});let $=()=>"undefined"==typeof window?null:window,K=function(e,t){if("object"!=typeof e||"function"!=typeof e.createPolicy)return null;let n=null;t&&t.hasAttribute("data-tt-policy-suffix")&&(n=t.getAttribute("data-tt-policy-suffix"));let r="dompurify"+(n?"#"+n:"");try{return e.createPolicy(r,{createHTML:e=>e,createScriptURL:e=>e})}catch(e){return console.warn("TrustedTypes policy "+r+" could not be created."),null}};return function t(){let n,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:$(),i=e=>t(e);if(i.version="3.0.5",i.removed=[],!r||!r.document||9!==r.document.nodeType)return i.isSupported=!1,i;let a=r.document,l=a.currentScript,{document:s}=r,{DocumentFragment:u,HTMLTemplateElement:x,Node:M,Element:D,NodeFilter:F,NamedNodeMap:z=r.NamedNodeMap||r.MozNamedAttrMap,HTMLFormElement:B,DOMParser:H,trustedTypes:V}=r,G=D.prototype,Y=S(G,"cloneNode"),X=S(G,"nextSibling"),Z=S(G,"childNodes"),Q=S(G,"parentNode");if("function"==typeof x){let e=s.createElement("template");e.content&&e.content.ownerDocument&&(s=e.content.ownerDocument)}let J,ee="",{implementation:et,createNodeIterator:en,createDocumentFragment:er,getElementsByTagName:ei}=s,{importNode:eo}=a,ea={};i.isSupported="function"==typeof e&&"function"==typeof Q&&et&&void 0!==et.createHTMLDocument;let{MUSTACHE_EXPR:el,ERB_EXPR:es,TMPLIT_EXPR:eu,DATA_ATTR:ec,ARIA_ATTR:ed,IS_SCRIPT_OR_DATA:eh,ATTR_WHITESPACE:ef}=W,{IS_ALLOWED_URI:ep}=W,eg=null,em=_({},[...C,...O,...k,...T,...N]),ev=null,ey=_({},[...j,...R,...L,...I]),eb=Object.seal(Object.create(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),ew=null,ex=null,e_=!0,eE=!0,eS=!1,eC=!0,eO=!1,ek=!1,eP=!1,eT=!1,eA=!1,eN=!1,ej=!1,eR=!0,eL=!1,eI=!0,eM=!1,eD={},eF=null,ez=_({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]),eB=null,eU=_({},["audio","video","img","source","image","track"]),eH=null,eV=_({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),eq="http://www.w3.org/1998/Math/MathML",eG="http://www.w3.org/2000/svg",eW="http://www.w3.org/1999/xhtml",e$=eW,eK=!1,eY=null,eX=_({},[eq,eG,eW],p),eZ=["application/xhtml+xml","text/html"],eQ,eJ=null,e0=s.createElement("form"),e1=function(e){return e instanceof RegExp||e instanceof Function},e2=function(e){if(!eJ||eJ!==e){if(e&&"object"==typeof e||(e={}),e=E(e),eQ="application/xhtml+xml"===(n=n=-1===eZ.indexOf(e.PARSER_MEDIA_TYPE)?"text/html":e.PARSER_MEDIA_TYPE)?p:f,eg="ALLOWED_TAGS"in e?_({},e.ALLOWED_TAGS,eQ):em,ev="ALLOWED_ATTR"in e?_({},e.ALLOWED_ATTR,eQ):ey,eY="ALLOWED_NAMESPACES"in e?_({},e.ALLOWED_NAMESPACES,p):eX,eH="ADD_URI_SAFE_ATTR"in e?_(E(eV),e.ADD_URI_SAFE_ATTR,eQ):eV,eB="ADD_DATA_URI_TAGS"in e?_(E(eU),e.ADD_DATA_URI_TAGS,eQ):eU,eF="FORBID_CONTENTS"in e?_({},e.FORBID_CONTENTS,eQ):ez,ew="FORBID_TAGS"in e?_({},e.FORBID_TAGS,eQ):{},ex="FORBID_ATTR"in e?_({},e.FORBID_ATTR,eQ):{},eD="USE_PROFILES"in e&&e.USE_PROFILES,e_=!1!==e.ALLOW_ARIA_ATTR,eE=!1!==e.ALLOW_DATA_ATTR,eS=e.ALLOW_UNKNOWN_PROTOCOLS||!1,eC=!1!==e.ALLOW_SELF_CLOSE_IN_ATTR,eO=e.SAFE_FOR_TEMPLATES||!1,ek=e.WHOLE_DOCUMENT||!1,eA=e.RETURN_DOM||!1,eN=e.RETURN_DOM_FRAGMENT||!1,ej=e.RETURN_TRUSTED_TYPE||!1,eT=e.FORCE_BODY||!1,eR=!1!==e.SANITIZE_DOM,eL=e.SANITIZE_NAMED_PROPS||!1,eI=!1!==e.KEEP_CONTENT,eM=e.IN_PLACE||!1,ep=e.ALLOWED_URI_REGEXP||U,e$=e.NAMESPACE||eW,eb=e.CUSTOM_ELEMENT_HANDLING||{},e.CUSTOM_ELEMENT_HANDLING&&e1(e.CUSTOM_ELEMENT_HANDLING.tagNameCheck)&&(eb.tagNameCheck=e.CUSTOM_ELEMENT_HANDLING.tagNameCheck),e.CUSTOM_ELEMENT_HANDLING&&e1(e.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)&&(eb.attributeNameCheck=e.CUSTOM_ELEMENT_HANDLING.attributeNameCheck),e.CUSTOM_ELEMENT_HANDLING&&"boolean"==typeof e.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements&&(eb.allowCustomizedBuiltInElements=e.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements),eO&&(eE=!1),eN&&(eA=!0),eD&&(eg=_({},[...N]),ev=[],!0===eD.html&&(_(eg,C),_(ev,j)),!0===eD.svg&&(_(eg,O),_(ev,R),_(ev,I)),!0===eD.svgFilters&&(_(eg,k),_(ev,R),_(ev,I)),!0===eD.mathMl&&(_(eg,T),_(ev,L),_(ev,I))),e.ADD_TAGS&&(eg===em&&(eg=E(eg)),_(eg,e.ADD_TAGS,eQ)),e.ADD_ATTR&&(ev===ey&&(ev=E(ev)),_(ev,e.ADD_ATTR,eQ)),e.ADD_URI_SAFE_ATTR&&_(eH,e.ADD_URI_SAFE_ATTR,eQ),e.FORBID_CONTENTS&&(eF===ez&&(eF=E(eF)),_(eF,e.FORBID_CONTENTS,eQ)),eI&&(eg["#text"]=!0),ek&&_(eg,["html","head","body"]),eg.table&&(_(eg,["tbody"]),delete ew.tbody),e.TRUSTED_TYPES_POLICY){if("function"!=typeof e.TRUSTED_TYPES_POLICY.createHTML)throw w('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if("function"!=typeof e.TRUSTED_TYPES_POLICY.createScriptURL)throw w('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');ee=(J=e.TRUSTED_TYPES_POLICY).createHTML("")}else void 0===J&&(J=K(V,l)),null!==J&&"string"==typeof ee&&(ee=J.createHTML(""));o&&o(e),eJ=e}},e3=_({},["mi","mo","mn","ms","mtext"]),e5=_({},["foreignobject","desc","title","annotation-xml"]),e6=_({},["title","style","font","a","script"]),e4=_({},O);_(e4,k),_(e4,P);let e8=_({},T);_(e8,A);let e9=function(e){let t=Q(e);t&&t.tagName||(t={namespaceURI:e$,tagName:"template"});let r=f(e.tagName),i=f(t.tagName);return!!eY[e.namespaceURI]&&(e.namespaceURI===eG?t.namespaceURI===eW?"svg"===r:t.namespaceURI===eq?"svg"===r&&("annotation-xml"===i||e3[i]):!!e4[r]:e.namespaceURI===eq?t.namespaceURI===eW?"math"===r:t.namespaceURI===eG?"math"===r&&e5[i]:!!e8[r]:e.namespaceURI===eW?!(t.namespaceURI===eG&&!e5[i])&&!(t.namespaceURI===eq&&!e3[i])&&!e8[r]&&(e6[r]||!e4[r]):!("application/xhtml+xml"!==n||!eY[e.namespaceURI]))},e7=function(e){h(i.removed,{element:e});try{e.parentNode.removeChild(e)}catch(t){e.remove()}},te=function(e,t){try{h(i.removed,{attribute:t.getAttributeNode(e),from:t})}catch(e){h(i.removed,{attribute:null,from:t})}if(t.removeAttribute(e),"is"===e&&!ev[e]){if(eA||eN)try{e7(t)}catch(e){}else try{t.setAttribute(e,"")}catch(e){}}},tt=function(e){let t,r;if(eT)e="<remove></remove>"+e;else{let t=g(e,/^[\r\n\t ]+/);r=t&&t[0]}"application/xhtml+xml"===n&&e$===eW&&(e='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+e+"</body></html>");let i=J?J.createHTML(e):e;if(e$===eW)try{t=(new H).parseFromString(i,n)}catch(e){}if(!t||!t.documentElement){t=et.createDocument(e$,"template",null);try{t.documentElement.innerHTML=eK?ee:i}catch(e){}}let o=t.body||t.documentElement;return e&&r&&o.insertBefore(s.createTextNode(r),o.childNodes[0]||null),e$===eW?ei.call(t,ek?"html":"body")[0]:ek?t.documentElement:o},tn=function(e){return en.call(e.ownerDocument||e,e,F.SHOW_ELEMENT|F.SHOW_COMMENT|F.SHOW_TEXT,null,!1)},tr=function(e){return"object"==typeof M?e instanceof M:e&&"object"==typeof e&&"number"==typeof e.nodeType&&"string"==typeof e.nodeName},ti=function(e,t,n){ea[e]&&c(ea[e],e=>{e.call(i,t,n,eJ)})},to=function(e){let t;if(ti("beforeSanitizeElements",e,null),e instanceof B&&("string"!=typeof e.nodeName||"string"!=typeof e.textContent||"function"!=typeof e.removeChild||!(e.attributes instanceof z)||"function"!=typeof e.removeAttribute||"function"!=typeof e.setAttribute||"string"!=typeof e.namespaceURI||"function"!=typeof e.insertBefore||"function"!=typeof e.hasChildNodes))return e7(e),!0;let n=eQ(e.nodeName);if(ti("uponSanitizeElement",e,{tagName:n,allowedTags:eg}),e.hasChildNodes()&&!tr(e.firstElementChild)&&(!tr(e.content)||!tr(e.content.firstElementChild))&&b(/<[/\w]/g,e.innerHTML)&&b(/<[/\w]/g,e.textContent))return e7(e),!0;if(!eg[n]||ew[n]){if(!ew[n]&&tl(n)&&(eb.tagNameCheck instanceof RegExp&&b(eb.tagNameCheck,n)||eb.tagNameCheck instanceof Function&&eb.tagNameCheck(n)))return!1;if(eI&&!eF[n]){let t=Q(e)||e.parentNode,n=Z(e)||e.childNodes;if(n&&t)for(let r=n.length-1;r>=0;--r)t.insertBefore(Y(n[r],!0),X(e))}return e7(e),!0}return e instanceof D&&!e9(e)?(e7(e),!0):("noscript"===n||"noembed"===n||"noframes"===n)&&b(/<\/no(script|embed|frames)/i,e.innerHTML)?(e7(e),!0):(eO&&3===e.nodeType&&(t=m(t=e.textContent,el," "),t=m(t,es," "),t=m(t,eu," "),e.textContent!==t&&(h(i.removed,{element:e.cloneNode()}),e.textContent=t)),ti("afterSanitizeElements",e,null),!1)},ta=function(e,t,n){if(eR&&("id"===t||"name"===t)&&(n in s||n in e0))return!1;if(eE&&!ex[t]&&b(ec,t));else if(e_&&b(ed,t));else if(!ev[t]||ex[t]){if(!(tl(e)&&(eb.tagNameCheck instanceof RegExp&&b(eb.tagNameCheck,e)||eb.tagNameCheck instanceof Function&&eb.tagNameCheck(e))&&(eb.attributeNameCheck instanceof RegExp&&b(eb.attributeNameCheck,t)||eb.attributeNameCheck instanceof Function&&eb.attributeNameCheck(t))||"is"===t&&eb.allowCustomizedBuiltInElements&&(eb.tagNameCheck instanceof RegExp&&b(eb.tagNameCheck,n)||eb.tagNameCheck instanceof Function&&eb.tagNameCheck(n))))return!1}else if(eH[t]);else if(b(ep,m(n,ef,"")));else if("src"!==t&&"xlink:href"!==t&&"href"!==t||"script"===e||0!==v(n,"data:")||!eB[e]){if(eS&&!b(eh,m(n,ef,"")));else if(n)return!1}return!0},tl=function(e){return e.indexOf("-")>0},ts=function(e){let t,n,r,o;ti("beforeSanitizeAttributes",e,null);let{attributes:a}=e;if(!a)return;let l={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:ev};for(o=a.length;o--;){let{name:s,namespaceURI:u}=t=a[o];if(n="value"===s?t.value:y(t.value),r=eQ(s),l.attrName=r,l.attrValue=n,l.keepAttr=!0,l.forceKeepAttr=void 0,ti("uponSanitizeAttribute",e,l),n=l.attrValue,l.forceKeepAttr||(te(s,e),!l.keepAttr))continue;if(!eC&&b(/\/>/i,n)){te(s,e);continue}eO&&(n=m(n,el," "),n=m(n,es," "),n=m(n,eu," "));let c=eQ(e.nodeName);if(ta(c,r,n)){if(eL&&("id"===r||"name"===r)&&(te(s,e),n="user-content-"+n),J&&"object"==typeof V&&"function"==typeof V.getAttributeType){if(u);else switch(V.getAttributeType(c,r)){case"TrustedHTML":n=J.createHTML(n);break;case"TrustedScriptURL":n=J.createScriptURL(n)}}try{u?e.setAttributeNS(u,s,n):e.setAttribute(s,n),d(i.removed)}catch(e){}}}ti("afterSanitizeAttributes",e,null)},tu=function e(t){let n;let r=tn(t);for(ti("beforeSanitizeShadowDOM",t,null);n=r.nextNode();)ti("uponSanitizeShadowNode",n,null),to(n)||(n.content instanceof u&&e(n.content),ts(n));ti("afterSanitizeShadowDOM",t,null)};return i.sanitize=function(e){let t,n,r,o,l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if((eK=!e)&&(e="<!-->"),"string"!=typeof e&&!tr(e)){if("function"!=typeof e.toString)throw w("toString is not a function");if("string"!=typeof(e=e.toString()))throw w("dirty is not a string, aborting")}if(!i.isSupported)return e;if(eP||e2(l),i.removed=[],"string"==typeof e&&(eM=!1),eM){if(e.nodeName){let t=eQ(e.nodeName);if(!eg[t]||ew[t])throw w("root node is forbidden and cannot be sanitized in-place")}}else if(e instanceof M)1===(n=(t=tt("<!---->")).ownerDocument.importNode(e,!0)).nodeType&&"BODY"===n.nodeName||"HTML"===n.nodeName?t=n:t.appendChild(n);else{if(!eA&&!eO&&!ek&&-1===e.indexOf("<"))return J&&ej?J.createHTML(e):e;if(!(t=tt(e)))return eA?null:ej?ee:""}t&&eT&&e7(t.firstChild);let s=tn(eM?e:t);for(;r=s.nextNode();)to(r)||(r.content instanceof u&&tu(r.content),ts(r));if(eM)return e;if(eA){if(eN)for(o=er.call(t.ownerDocument);t.firstChild;)o.appendChild(t.firstChild);else o=t;return(ev.shadowroot||ev.shadowrootmode)&&(o=eo.call(a,o,!0)),o}let c=ek?t.outerHTML:t.innerHTML;return ek&&eg["!doctype"]&&t.ownerDocument&&t.ownerDocument.doctype&&t.ownerDocument.doctype.name&&b(q,t.ownerDocument.doctype.name)&&(c="<!DOCTYPE "+t.ownerDocument.doctype.name+">\n"+c),eO&&(c=m(c,el," "),c=m(c,es," "),c=m(c,eu," ")),J&&ej?J.createHTML(c):c},i.setConfig=function(e){e2(e),eP=!0},i.clearConfig=function(){eJ=null,eP=!1},i.isValidAttribute=function(e,t,n){return eJ||e2({}),ta(eQ(e),eQ(t),n)},i.addHook=function(e,t){"function"==typeof t&&(ea[e]=ea[e]||[],h(ea[e],t))},i.removeHook=function(e){if(ea[e])return d(ea[e])},i.removeHooks=function(e){ea[e]&&(ea[e]=[])},i.removeAllHooks=function(){ea={}},i}()}()},function(e,t){e.exports=kQ},function(e,t,n){n.r(t);var r=n(1),i=n.n(r),o=n(0),a=n.n(o);function l(e){return(l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function s(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function u(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?s(Object(n),!0).forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):s(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function c(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function d(e,t){return(d=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function h(e){return(h=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var f=i.a.import("modules/clipboard"),p=i.a.import("delta"),g=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&d(e,t)}(s,e);var t,n,r,o=(t=function(){if("undefined"==typeof Reflect||!Reflect.construct||Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}(),function(){var e,n=h(s);return e=t?Reflect.construct(n,arguments,h(this).constructor):n.apply(this,arguments),e&&("object"===l(e)||"function"==typeof e)?e:function(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this)});function s(e,t){var n;return function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,s),(n=o.call(this,e,t)).allowed=t.allowed,n.keepSelection=t.keepSelection,n.substituteBlockElements=t.substituteBlockElements,n.magicPasteLinks=t.magicPasteLinks,n.hooks=t.hooks,n}return n=[{key:"onPaste",value:function(e){var t,n,r,o,l,s,u,c,d,h=this;e.preventDefault();var f,g,m,v,y,b=this.quill.getSelection();e.clipboardData&&e.clipboardData.getData||!window.clipboardData||!window.clipboardData.getData?(f=e.clipboardData.getData("text/plain"),g=e.clipboardData.getData("text/html"),m=null===(v=e.clipboardData)||void 0===v||null===(y=v.items)||void 0===y?void 0:y[0]):f=window.clipboardData.getData("Text");var w=(new p).retain(b.index).delete(b.length),x=this.getDOMPurifyOptions(),_=!1,E=f;if(!g&&x.ALLOWED_TAGS.includes("a")&&this.isURL(f)&&b.length>0&&this.magicPasteLinks)E=this.quill.getText(b.index,b.length),w=w.insert(E,{link:f});else if(!g&&x.ALLOWED_TAGS.includes("img")&&m&&"file"===m.kind&&m.type.match(/^image\//i)){var S=m.getAsFile(),C=new FileReader;C.onload=function(e){h.quill.insertEmbed(b.index,"image",e.target.result),h.keepSelection||h.quill.setSelection(b.index+1)},C.readAsDataURL(S)}else g||(_=!0,g=E),"function"==typeof(null===(t=this.hooks)||void 0===t?void 0:t.beforeSanitizeElements)&&a.a.addHook("beforeSanitizeElements",this.hooks.beforeSanitizeElements),"function"==typeof(null===(n=this.hooks)||void 0===n?void 0:n.uponSanitizeElement)&&a.a.addHook("uponSanitizeElement",this.hooks.uponSanitizeElement),"function"==typeof(null===(r=this.hooks)||void 0===r?void 0:r.afterSanitizeElements)&&a.a.addHook("afterSanitizeElements",this.hooks.afterSanitizeElements),"function"==typeof(null===(o=this.hooks)||void 0===o?void 0:o.beforeSanitizeAttributes)&&a.a.addHook("beforeSanitizeAttributes",this.hooks.beforeSanitizeAttributes),"function"==typeof(null===(l=this.hooks)||void 0===l?void 0:l.uponSanitizeAttribute)&&a.a.addHook("uponSanitizeAttribute",this.hooks.uponSanitizeAttribute),"function"==typeof(null===(s=this.hooks)||void 0===s?void 0:s.afterSanitizeAttributes)&&a.a.addHook("afterSanitizeAttributes",this.hooks.afterSanitizeAttributes),"function"==typeof(null===(u=this.hooks)||void 0===u?void 0:u.beforeSanitizeShadowDOM)&&a.a.addHook("beforeSanitizeShadowDOM",this.hooks.beforeSanitizeShadowDOM),"function"==typeof(null===(c=this.hooks)||void 0===c?void 0:c.uponSanitizeShadowNode)&&a.a.addHook("uponSanitizeShadowNode",this.hooks.uponSanitizeShadowNode),"function"==typeof(null===(d=this.hooks)||void 0===d?void 0:d.afterSanitizeShadowDOM)&&a.a.addHook("afterSanitizeShadowDOM",this.hooks.afterSanitizeShadowDOM),_?(E=a.a.sanitize(g,x),w=w.insert(E)):(E=!1!==this.substituteBlockElements?(g=this.substitute(g,x)).innerHTML:a.a.sanitize(g,x),w=w.concat(this.convert(E)));this.quill.updateContents(w,i.a.sources.USER),_||(w=this.convert(E)),this.keepSelection?this.quill.setSelection(b.index,w.length(),i.a.sources.SILENT):this.quill.setSelection(b.index+w.length(),i.a.sources.SILENT),this.quill.scrollIntoView(),a.a.removeAllHooks()}},{key:"getDOMPurifyOptions",value:function(){var e,t,n={};if(null!==(e=this.allowed)&&void 0!==e&&e.tags&&(n.ALLOWED_TAGS=this.allowed.tags),null!==(t=this.allowed)&&void 0!==t&&t.attributes&&(n.ALLOWED_ATTR=this.allowed.attributes),void 0===n.ALLOWED_TAGS||void 0===n.ALLOWED_ATTR){var r,i=!1;void 0===n.ALLOWED_TAGS&&(i=!0,n.ALLOWED_TAGS=["p","br","span"]);var o=!1;void 0===n.ALLOWED_ATTR&&(o=!0,n.ALLOWED_ATTR=["class"]);var a=this.quill.getModule("toolbar");null==a||null===(r=a.controls)||void 0===r||r.forEach(function(e){switch(e[0]){case"bold":i&&(n.ALLOWED_TAGS.push("b"),n.ALLOWED_TAGS.push("strong"));break;case"italic":i&&(n.ALLOWED_TAGS.push("i"),n.ALLOWED_TAGS.push("em"));break;case"underline":i&&n.ALLOWED_TAGS.push("u");break;case"strike":i&&n.ALLOWED_TAGS.push("s");break;case"color":case"background":o&&n.ALLOWED_ATTR.push("style");break;case"script":i&&("super"===e[1].value?n.ALLOWED_TAGS.push("sup"):"sub"===e[1].value&&n.ALLOWED_TAGS.push("sub"));break;case"header":if(i){var t=function(e){"1"===e?n.ALLOWED_TAGS.push("h1"):"2"===e?n.ALLOWED_TAGS.push("h2"):"3"===e?n.ALLOWED_TAGS.push("h3"):"4"===e?n.ALLOWED_TAGS.push("h4"):"5"===e?n.ALLOWED_TAGS.push("h5"):"6"===e&&n.ALLOWED_TAGS.push("h6")};e[1].value?t(e[1].value):e[1].options&&e[1].options.length&&[].forEach.call(e[1].options,function(e){e.value&&t(e.value)})}break;case"code-block":i&&n.ALLOWED_TAGS.push("pre"),o&&n.ALLOWED_ATTR.push("spellcheck");break;case"list":i&&("ordered"===e[1].value?n.ALLOWED_TAGS.push("ol"):"bullet"===e[1].value&&n.ALLOWED_TAGS.push("ul"),n.ALLOWED_TAGS.push("li"));break;case"link":i&&n.ALLOWED_TAGS.push("a"),o&&(n.ALLOWED_ATTR.push("href"),n.ALLOWED_ATTR.push("target"),n.ALLOWED_ATTR.push("rel"));break;case"image":i&&n.ALLOWED_TAGS.push("img"),o&&(n.ALLOWED_ATTR.push("src"),n.ALLOWED_ATTR.push("title"),n.ALLOWED_ATTR.push("alt"));break;case"video":i&&n.ALLOWED_TAGS.push("iframe"),o&&(n.ALLOWED_ATTR.push("frameborder"),n.ALLOWED_ATTR.push("allowfullscreen"),n.ALLOWED_ATTR.push("src"));break;case"blockquote":i&&n.ALLOWED_TAGS.push(e[0])}})}return n}},{key:"substitute",value:function(e,t){var n,r=["h1","h2","h3","h4","h5","h6"],i=["p","div","section","article","fieldset","address","aside","blockquote","canvas","dl","figcaption","figure","footer","form","header","main","nav","noscript","ol","pre","table","tfoot","ul","video"],o=["li","dt","dd","hr"];a.a.addHook("uponSanitizeElement",function(e,a,l){for(var s=0;!n&&s<3;)t.ALLOWED_TAGS.includes(i[s])&&(n=i[s]),++s;if(n&&e.tagName&&!t.ALLOWED_TAGS.includes(e.tagName.toLowerCase())){var u=e.tagName.toLowerCase();r.includes(u)?e.innerHTML="<".concat(n,"><b>").concat(e.innerHTML,"</b></").concat(n,">"):i.includes(u)?e.innerHTML="<".concat(n,">").concat(e.innerHTML,"</").concat(n,">"):o.includes(u)&&(e.innerHTML="".concat(e.innerHTML,"<br>"))}}),e=a.a.sanitize(e,u(u({},t),{RETURN_DOM:!0,WHOLE_DOCUMENT:!1})),a.a.removeAllHooks();var l,s=function(e){var t=document.createElement(e.tagName.toLowerCase()),n=e.attributes;return n.length&&Array.from(n).forEach(function(e){return t.setAttribute(e.nodeName,e.value)}),t},c=0,d=document.createElement("body");return function e(t,n){for(n(t,c),t=c<=1?t.firstChild:void 0;t;)++c,e(t,n),t=t.nextSibling;--c}(e,function(e,t){if(1===t){if(e.tagName&&i.includes(e.tagName.toLowerCase())){l&&(l=void 0);var r=s(e);r.innerHTML=e.innerHTML,d.appendChild(r)}else if(void 0===l&&(l=document.createElement(n),d.appendChild(l)),e.tagName){var o=s(e);e.innerHTML&&(o.innerHTML=e.innerHTML),l.appendChild(o)}else{var a=document.createTextNode(e.textContent);l.appendChild(a)}}}),d}},{key:"isURL",value:function(e){return!!/^(?:(?:http[s\u017F]?|ftp):\/\/)(?:(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+(?::(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?@)?(?:(?!10(?:\.[0-9]{1,3}){3})(?!127(?:\.[0-9]{1,3}){3})(?!169\.254(?:\.[0-9]{1,3}){2})(?!192\.168(?:\.[0-9]{1,3}){2})(?!172\.(?:1[6-9]|2[0-9]|3[01])(?:\.[0-9]{1,3}){2})(?:[1-9][0-9]?|1[0-9][0-9]|2[01][0-9]|22[0-3])(?:\.(?:1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])){2}(?:\.(?:[1-9][0-9]?|1[0-9][0-9]|2[0-4][0-9]|25[0-4]))|(?:(?:(?:[0-9KSa-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+\x2D?)*(?:[0-9KSa-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)(?:\.(?:(?:[0-9KSa-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+\x2D?)*(?:[0-9KSa-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)*(?:\.(?:(?:[KSa-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]){2,})))(?::[0-9]{2,5})?(?:\/(?:(?![\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])[\s\S])*)?$/i.test(e)}}],c(s.prototype,n),r&&c(s,r),s}(f);i.a.register("modules/clipboard",g,!0),t.default=g}]);var b=f("2SBKn"),og={};k5=og,k6=function(e,t,n,r){var i,o,a,l,s,u,c,d,h,f,p,g,m,v,y,b,w,x,_,E,S,C,O,k,P,T,A,N,j,R,L,I,M,D,F,z,B,U,H,V,q,G,W,$,K,Y,X,Z,Q,J,ee,et,en=(o=[],(i={}).joinUrl=function(t,n){return t?e.resolve(t,n):n},i.getConstantUniqueIdFor=function(e){return 0>o.indexOf(e)&&o.push(e),o.indexOf(e)},i.clone=function(e){var t,n={};for(t in e)e.hasOwnProperty(t)&&(n[t]=e[t]);return n},a=function(e){return"object"==typeof e&&null!==e&&Object.prototype.toString.apply(e).match(/\[object (Canvas|HTMLCanvasElement)\]/i)},i.parseOptionalParameters=function(e){var t={canvas:null,options:{}};return null==e[0]||a(e[0])?(t.canvas=e[0]||null,t.options=i.clone(e[1])):t.options=i.clone(e[0]),t},i),er=(l={},s=function(e,t,n){var r=e[t];return e[t]=function(){var e=Array.prototype.slice.call(arguments);return n.apply(this,[e,r])},r},l.baseUrlRespectingXhr=function(e,t){return function(){var n=new e;return s(n,"open",function(e,n){var r=e.shift(),i=e.shift(),o=en.joinUrl(t,i);return n.apply(this,[r,o].concat(e))}),n}},l.finishNotifyingXhr=function(e){var t,n=0,r=0,i=!1,o=new Promise(function(e){t=function(){n-r<=0&&i&&e({totalCount:n})}}),a=function(){var i=new e;return s(i,"send",function(e,t){return n+=1,t.apply(this,arguments)}),i.addEventListener("load",function(){r+=1,t()}),i};return a.waitForRequestsToFinish=function(){return i=!0,t(),o},a},l),ei=(u={},c=function(e){return Array.prototype.slice.call(e)},u.addClassName=function(e,t){e.className+=" "+t},u.addClassNameRecursively=function(e,t){u.addClassName(e,t),e.parentNode!==e.ownerDocument&&u.addClassNameRecursively(e.parentNode,t)},d=function(e,t){var n=e.parentStyleSheet,r=c(n.cssRules).indexOf(e);n.insertRule(t,r+1),n.deleteRule(r)},h=function(e,t){var n=e.cssText.replace(/^[^\{]+/,"");d(e,t+" "+n)},f=function(e){e.textContent=c(e.sheet.cssRules).reduce(function(e,t){return e+t.cssText},"")},p=function(e){var t=document.implementation.createHTMLDocument(""),n=document.createElement("style");n.textContent=e.textContent,t.body.appendChild(n),e.sheet=n.sheet},g=function(e,t,n){var r="((?:^|[^.#:\\w])|(?=\\W))("+t.join("|")+")(?=\\W|$)";c(e.querySelectorAll("style")).forEach(function(e){void 0===e.sheet&&p(e);var t=c(e.sheet.cssRules).filter(function(e){return e.selectorText&&RegExp(r,"i").test(e.selectorText)});t.length&&(t.forEach(function(e){var t=e.selectorText.replace(RegExp(r,"gi"),function(e,t,r){return t+n(r)});t!==e.selectorText&&h(e,t)}),f(e))})},u.rewriteCssSelectorWith=function(e,t,n){g(e,[t],function(){return n})},u.lowercaseCssTypeSelectors=function(e,t){g(e,t,function(e){return e.toLowerCase()})},u.findHtmlOnlyNodeNames=function(e){var t,n=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_ELEMENT),r={},i={};do t=n.currentNode.tagName.toLowerCase(),"http://www.w3.org/1999/xhtml"===n.currentNode.namespaceURI?r[t]=!0:i[t]=!0;while(n.nextNode())return Object.keys(r).filter(function(e){return!i[e]})},m={},v=function(e){return Array.prototype.slice.call(e)},y={active:!0,hover:!0,focus:!1,target:!1},m.fakeUserAction=function(e,t,n){var r=e.querySelector(t),i="rasterizehtml"+n;r&&(y[n]?u.addClassNameRecursively(r,i):u.addClassName(r,i),u.rewriteCssSelectorWith(e,":"+n,"."+i))},m.persistInputValues=function(e){var t=e.querySelectorAll("input"),n=e.querySelectorAll("textarea"),r=function(e){return"checkbox"===e.type||"radio"===e.type};v(t).filter(r).forEach(function(e){e.checked?e.setAttribute("checked",""):e.removeAttribute("checked")}),v(t).filter(function(e){return!r(e)}).forEach(function(e){e.setAttribute("value",e.value)}),v(n).forEach(function(e){e.textContent=e.value})},m.rewriteTagNameSelectorsToLowerCase=function(e){u.lowercaseCssTypeSelectors(e,u.findHtmlOnlyNodeNames(e))},m),eo=(b=window,w={},x=function(e,t,n,r){var i=e.createElement(t);return i.style.visibility="hidden",i.style.width=n+"px",i.style.height=r+"px",i.style.position="absolute",i.style.top=-1e4-r+"px",i.style.left=-1e4-n+"px",e.getElementsByTagName("body")[0].appendChild(i),i},w.executeJavascript=function(e,t){return new Promise(function(n){var r=x(b.document,"iframe",t.width,t.height),i=e.outerHTML,o=[],a=t.executeJsTimeout||0,l=function(){b.document.getElementsByTagName("body")[0].removeChild(r)},s=function(){n({document:r.contentDocument,errors:o,cleanUp:l})},u=r.contentWindow.XMLHttpRequest,c=er.finishNotifyingXhr(u),d=er.baseUrlRespectingXhr(c,t.baseUrl);r.onload=function(){(a>0?new Promise(function(e){setTimeout(e,a)}):Promise.resolve()).then(c.waitForRequestsToFinish).then(s)},r.contentDocument.open(),r.contentWindow.XMLHttpRequest=d,r.contentWindow.onerror=function(e){o.push({resourceType:"scriptExecution",msg:e})},r.contentDocument.write("<!DOCTYPE html>"),r.contentDocument.write(i),r.contentDocument.close()})},_=function(e,t,n){var r=e.createElement("iframe");return r.style.width=t+"px",r.style.height=n+"px",r.style.visibility="hidden",r.style.position="absolute",r.style.top=-1e4-n+"px",r.style.left=-1e4-t+"px",r.style.borderWidth=0,r.sandbox="allow-same-origin",r.scrolling="no",r},E=function(e,t,n){var r=Math.floor(e/n),i=Math.floor(t/n);return _(b.document,r,i)},S=function(e,t){var n=e.querySelector(t);if(n)return n;if(e.ownerDocument.querySelector(t)===e)return e;throw{message:"Clipping selector not found"}},C=function(e,t,n,r,i){var o,a,l,s,u,c,d,h,f=Math.max(e.scrollWidth,e.clientWidth),p=Math.max(e.scrollHeight,e.clientHeight);return t?(a=(d=S(e,t).getBoundingClientRect()).top,l=d.left,s=d.width,u=d.height):(a=0,l=0,s=f,u=p),h={width:Math.max((o={width:s,height:u}).width*i,n),height:Math.max(o.height*i,r)},c=b.getComputedStyle(e.ownerDocument.documentElement).fontSize,{left:l,top:a,width:h.width,height:h.height,viewportWidth:f,viewportHeight:p,rootFontSize:c}},O=function(e,t){var n=e.tagName;return t.querySelector(n)},k=function(e){var t=e.tagName.toLowerCase();return"html"===t||"body"===t?e.outerHTML:'<body style="margin: 0;">'+e.outerHTML+"</body>"},w.calculateDocumentContentSize=function(e,t){return new Promise(function(n,r){var i,o=t.zoom||1;i=E(t.width,t.height,o),b.document.getElementsByTagName("body")[0].appendChild(i),i.onload=function(){var a,l=i.contentDocument;try{a=C(O(e,l),t.clip,t.width,t.height,o),n(a)}catch(e){r(e)}finally{b.document.getElementsByTagName("body")[0].removeChild(i)}},i.contentDocument.open(),i.contentDocument.write("<!DOCTYPE html>"),i.contentDocument.write(k(e)),i.contentDocument.close()})},w.parseHtmlFragment=function(e){var t=b.document.implementation.createHTMLDocument("");t.documentElement.innerHTML=e;var n=t.querySelector("body").firstChild;if(!n)throw"Invalid source";return n},P=function(e,t){var n,r,i,o,a=/<html((?:\s+[^>]*)?)>/im.exec(t),l=b.document.implementation.createHTMLDocument("");if(a)for(r=0,n="<div"+a[1]+"></div>",l.documentElement.innerHTML=n,i=l.querySelector("div");r<i.attributes.length;r++)o=i.attributes[r],e.documentElement.setAttribute(o.name,o.value)},w.parseHTML=function(e){var t=b.document.implementation.createHTMLDocument("");return t.documentElement.innerHTML=e,P(t,e),t},T=function(e){try{return n.failOnParseError(e)}catch(e){throw{message:"Invalid source",originalError:e}}},w.validateXHTML=function(e){T(new DOMParser().parseFromString(e,"application/xml"))},A=null,w.loadDocument=function(e,t){return new Promise(function(n,r){var i,o,a=new window.XMLHttpRequest,l=(i=en.joinUrl(t.baseUrl,e),"none"===(o=t.cache)||"repeated"===o?((null===A||"repeated"!==o)&&(A=Date.now()),i+"?_="+A):i),s=function(e){r({message:"Unable to load page",originalError:e})};a.addEventListener("load",function(){200===a.status||0===a.status?n(a.responseXML):s(a.statusText)},!1),a.addEventListener("error",function(e){s(e)},!1);try{a.open("GET",l,!0),a.responseType="document",a.send(null)}catch(e){s(e)}}).then(function(e){return T(e)})},w),ea=(N=window,R={},L=function(e,t){return t?URL.createObjectURL(new Blob([e],{type:"image/svg+xml"})):"data:image/svg+xml;charset=utf-8,"+encodeURIComponent(e)},I=function(e){e instanceof Blob&&URL.revokeObjectURL(e)},M='<svg xmlns="http://www.w3.org/2000/svg" width="1" height="1"><foreignObject></foreignObject></svg>',D=function(e){return new Promise(function(t,n){var r=document.createElement("canvas"),i=new Image;i.onload=function(){var e=r.getContext("2d");try{e.drawImage(i,0,0),r.toDataURL("image/png"),t(!0)}catch(e){t(!1)}},i.onerror=n,i.src=e})},F=function(){var e=L(M,!0);return D(e).then(function(t){return I(e),!t&&D(L(M,!1)).then(function(e){return e})},function(){return!1})},z=function(){if(N.Blob)try{return new Blob(["<b></b>"],{type:"text/xml"}),!0}catch(e){}return!1},R.renderSvg=function(e){return new Promise(function(t,n){var r,i,o=function(){i.onload=null,i.onerror=null},a=function(){r&&I(r)};(i=new Image).onload=function(){o(),a(),t(i)},i.onerror=function(){a(),n()},(void 0===j&&(j=new Promise(function(e,t){z()&&N.URL?F().then(function(t){e(!t)},function(){t()}):e(!1)})),j).then(function(t){return L(e,t)}).then(function(e){r=e,i.src=r},n)})},R),el=(B={},U=function(e,t){var n=t||1,r={width:e.width,height:e.height,"font-size":e.rootFontSize};return 1!==n&&(r.style="transform:scale("+n+"); transform-origin: 0 0;"),r},H=function(e){var t,n;return t=Math.round(e.viewportWidth),n=Math.round(e.viewportHeight),{x:-e.left,y:-e.top,width:t,height:n}},V=function(e){var t=e.style||"";e.style=t+"float: left;"},q=function(e){e.externalResourcesRequired=!0},G=function(e){var t=Object.keys(e);return t.length?" "+t.map(function(t){return t+'="'+e[t]+'"'}).join(" "):""},W=function(e,n,r){var i=t.serializeToString(e);eo.validateXHTML(i);var o=H(n);return V(o),q(o),'<svg xmlns="http://www.w3.org/2000/svg"'+G(U(n,r))+'><style scoped="">html::-webkit-scrollbar { display: none; }</style><foreignObject'+G(o)+">"+i+"</foreignObject></svg>"},B.getSvgForDocument=function(e,t,n){return ei.rewriteTagNameSelectorsToLowerCase(e),W(e,t,n)},B.drawDocumentAsSvg=function(e,t){return["hover","active","focus","target"].forEach(function(n){t[n]&&ei.fakeUserAction(e,t[n],n)}),eo.calculateDocumentContentSize(e,t).then(function(n){return B.getSvgForDocument(e,n,t.zoom)})},B),es=($={},K=function(e){return{message:"Error rendering page",originalError:e}},Y=function(e){return ea.renderSvg(e).then(function(t){return{image:t,svg:e}},function(e){throw K(e)})},X=function(e,t){try{t.getContext("2d").drawImage(e,0,0)}catch(e){throw K(e)}},$.rasterize=function(e,t,n){var i;return(i=en.clone(n)).inlineScripts=!0===n.executeJs,r.inlineReferences(e,i).then(function(t){return n.executeJs?eo.executeJavascript(e,n).then(function(e){var t=e.document;return ei.persistInputValues(t),{document:t,errors:e.errors,cleanUp:e.cleanUp}}).then(function(e){return{element:e.document.documentElement,errors:t.concat(e.errors),cleanUp:e.cleanUp}}):{element:e,errors:t,cleanUp:function(){}}}).then(function(e){var r;return(r=e.element,el.drawDocumentAsSvg(r,n).then(Y).then(function(e){return t&&X(e.image,t),e})).then(function(t){return e.cleanUp(),{image:t.image,svg:t.svg,errors:e.errors}})})},$);return Z={},Q=function(e,t){var n=e?e.width:300,r=e?e.height:200;return{width:void 0!==t.width?t.width:n,height:void 0!==t.height?t.height:r}},J=function(e){var t,n=Q(e.canvas,e.options);return(t=en.clone(e.options)).width=n.width,t.height=n.height,t},Z.drawDocument=function(){var e=arguments[0],t=Array.prototype.slice.call(arguments,1),n=en.parseOptionalParameters(t),r=e.documentElement?e.documentElement:e;return es.rasterize(r,n.canvas,J(n))},ee=function(e,t,n){var r=eo.parseHTML(e);return Z.drawDocument(r,t,n)},Z.drawHTML=function(){var e=arguments[0],t=Array.prototype.slice.call(arguments,1),n=en.parseOptionalParameters(t);return ee(e,n.canvas,n.options)},et=function(e,t,n){var r=document.implementation.createHTMLDocument("");r.replaceChild(e.documentElement,r.documentElement);var i=n?en.clone(n):{};return n.baseUrl||(i.baseUrl=t),{document:r,options:i}},Z.drawURL=function(){var e,t,n=arguments[0],r=Array.prototype.slice.call(arguments,1),i=en.parseOptionalParameters(r);return e=i.canvas,t=i.options,eo.loadDocument(n,t).then(function(r){var i=et(r,n,t);return Z.drawDocument(i.document,e,i.options)})},Z},void 0===k5&&void 0!==window&&(k5=window),"function"==typeof define&&define.amd?define(["url","xmlserializer","sane-domparser-error","inlineresources"],function(e,t,n,r){return k5.rasterizeHTML=k6(e,t,n,r)}):og?og=k6(f("kRFNf"),f("l4MZj"),f("lDFX4"),f("6cJtK")):k5.rasterizeHTML=k6(k5.url,k5.xmlserializer,k5.sanedomparsererror,k5.inlineresources);let om=`
42
+ `;iH.innerHTML="",iH.appendChild(document.createTextNode(n)),JSON.stringify(e)!==JSON.stringify(o)&&a(e)});let u=s(y).useRef(null);s(y).useEffect(()=>{let e=setTimeout(()=>{let e=u.current;if(!e)return;u.current?.focus();let t=i||e.value.length;e.selectionStart=e.selectionEnd=t,r&&(e?.select(),document.execCommand("selectAll",!1,null))});return()=>{clearTimeout(e)}},[]),s(y).useEffect(()=>{window.addEventListener("blur",n);let e=e=>{u.current?.contains(e.target)||n()};return window.addEventListener("touchstart",e),()=>{window.removeEventListener("blur",n),window.removeEventListener("touchstart",e)}},[]);let c=0,d=l.textArr.length*l.lineHeight()*l.fontSize();"middle"===t.verticalAlign&&(c=(t.a.height-d)/2),"bottom"===t.verticalAlign&&(c=t.a.height-d);let h=iL(t.text);return(0,g.jsx)(r4,{children:(0,g.jsx)("textarea",{className:"polotno-input",ref:u,dir:iq(h),style:{...iV,...o,paddingTop:c+"px"},value:h,onChange:e=>{t.set({text:e.target.value})},placeholder:t.placeholder,onBlur:n})})}),iW=e=>{let[t,n]=s(y).useState(!1),r=s(y).useRef(!1);return s(y).useEffect(()=>{var t=!0;return setTimeout(()=>{t&&(e._editModeEnabled&&(r.current=!0),n(!0),setTimeout(()=>{r.current=!1},50))},50),()=>{t=!1}},[]),{editorEnabled:t&&e._editModeEnabled,selectAll:r.current}},i$=(e,t)=>{let[n,r]=s(y).useReducer(e=>e+1,0),i=s(y).useRef(ik(t));return s(y).useLayoutEffect(()=>{if(i.current=ik(t),i.current)return;let n=!0;return(async()=>{i.current=!1,r();let o=im(`text ${t}`);await e.loadFont(t),setTimeout(o,100),n&&(i.current=!0,r())})(),()=>{n=!1}},[t]),[i.current]},iK=({fontLoaded:e,fontFamily:t,fontSize:n,lineHeight:r})=>s(y).useMemo(()=>{if("number"==typeof r)return r;let e=document.createElement("div");e.style.fontFamily=t,e.style.fontSize=n+"px",e.style.lineHeight=r,e.innerText="Test text",document.body.appendChild(e);let i=e.offsetHeight;return document.body.removeChild(e),i/n},[e,t,n,r]);function iY(e){let t=s(y).useRef(e),n=s(y).useRef(e);return s(y).useMemo(()=>{n.current=t.current,t.current=e},[e]),n.current}let iX=T(({element:e,store:t})=>{let n=s(y).useRef(null),r=s(y).useRef(null),{editorEnabled:i,selectAll:o}=iW(e),[a,l]=s(y).useState(!1),[u,c]=s(y).useState(!1),d=s(y).useRef(e.a.height),h=t.selectedElements.indexOf(e)>=0,{textVerticalResizeEnabled:f}=iN,p=iY(e.fontFamily),[m,v]=s(y).useState([]);s(y).useEffect(()=>{let e=n.current?.textArr??[];JSON.stringify(e)!==JSON.stringify(m)&&v(e)}),s(y).useEffect(()=>{if(e.a.width)return;let t=n.current;t.width(600),e.set({width:1.4*t.getTextWidth()})},[]),s(y).useLayoutEffect(()=>(0,b.autorun)(()=>{iI(n.current,e)}));let[w]=i$(t,e.fontFamily),x=iL(e.text),_=()=>{let e=n.current.clone({height:void 0}),t=Math.ceil(e.fontSize()*e.lineHeight()*e.textArr.length+1);return e.destroy(),t};s(y).useLayoutEffect(()=>{if(!w)return;let{textOverflow:r}=iN;if(!e.a.height){let n=_();t.history.ignore(()=>{e.set({height:n})},!1,!0);return}if("change-font-size"!==r||u||t.isPlaying){if("resize"===r){let r=_();f&&e.a.height<r&&t.history.ignore(()=>{(0,iU.isAlive)(e)&&e.set({height:r}),n.current?.height(r)},!1,!0),f||e.a.height===r||t.history.ignore(()=>{(0,iU.isAlive)(e)&&e.set({height:r}),n.current?.height(r)},!1,!0)}}else{let r=function(e,t){let n=e.fontSize(),r=e.height(),i=iL(t.text),o=t.a.fontSize;e.height(void 0);let a=Math.round(2*t.a.fontSize)-1;for(let n=1;n<a;n++){let n=t.a.height&&e.height()>t.a.height,r=i.split("\n").join(" ").split(/[\s-]+/),a=e.textArr.map(e=>e.text).join(";"),l=r.find(e=>!a.includes(e)||(a=a.replace(e,""),!1));if(!(n||l))break;o-=.5,e.fontSize(o)}return e.fontSize(n),e.height(r),o}(n.current,e);if(r!==e.a.fontSize){t.history.ignore(()=>{e.set({fontSize:r})},!1,!0);return}let i=_();e.a.height===i||f||t.history.ignore(()=>{e.set({height:i})},!1,!0)}}),s(y).useLayoutEffect(()=>{let t=n.current;t&&(t.width(t.width()+1e-8),t._setTextData(),iI(t,e))},[w]);let E=s(y).useRef(null),S=s(y).useRef(0),C=n=>{n.evt.preventDefault(),t.selectedShapes.find(t=>t===e)&&e.contentEditable&&(S.current=function(e){var t,n;let r=e.target,i=((t=r.getAbsoluteTransform().copy()).invert(),n=r.getStage().getPointerPosition(),t.point(n)),o=r.textArr,a=Math.floor(i.y/(r.fontSize()*r.lineHeight())),l=o.slice(0,a).reduce((e,t)=>e+t.text.length,a),s=o[a]??o[0],u=0;return"right"===r.align()?u=r.width()-s.width:"center"===r.align()&&(u=r.width()/2-s.width/2),l+Math.round((i.x-u)/s.width*s.text.length)}(n),e.toggleEditMode())},O=!x&&e.placeholder?.6:e.a.opacity;id(n,O);let k=iK({fontLoaded:w,fontFamily:e.fontFamily,fontSize:e.a.fontSize,lineHeight:e.lineHeight}),P=e.selectable||"admin"===t.role,T=iu(e),A=s(y).useMemo(()=>e.backgroundEnabled?function({lines:e,lineHeight:t,width:n,align:r="left",padding:i=0,cornerRadius:o=0}){let a,l;e.forEach((e,t)=>{e.cx=n/2,"right"===r?e.cx=n-e.width/2:"left"===r&&(e.cx=e.width/2),"justify"!==r||e.lastInParagraph||(e.width=n),"justify"===r&&(e.cx=e.width/2)});let s=`M ${e[0]?.cx} ${-i}`;e.forEach((n,r)=>{let{cx:o}=n,a=e[r-1];a&&a.width>n.width?s+=` L ${o+n.width/2+i} ${r*t+i}`:s+=` L ${o+n.width/2+i} ${r*t-i}`;let l=e[r+1];l&&l.width>n.width?s+=` L ${o+n.width/2+i} ${(r+1)*t-i}`:s+=` L ${o+n.width/2+i} ${(r+1)*t+i}`});for(var u,c=e.length-1;c>=0;c--){let n=e[c],{cx:r}=n,o=e[c+1];o&&o.width>n.width?s+=` L ${r-n.width/2-i} ${(c+1)*t-i}`:s+=` L ${r-n.width/2-i} ${(c+1)*t+i}`;let a=e[c-1];a&&a.width>n.width?s+=` L ${r-n.width/2-i} ${c*t+i}`:s+=` L ${r-n.width/2-i} ${c*t-i}`}return(u=function(e){let t=/-?[0-9]*\.?\d+/g;return[...e.matchAll(/[MmLlSsQqLlHhVvCcSsQqTtAaZz]/g)].map(e=>({marker:e[0],index:e.index})).reduceRight((t,n)=>{let r=e.substring(n.index,t.length?t[t.length-1].index:e.length);return t.concat([{marker:n.marker,index:n.index,chunk:r.length>0?r.substr(1,r.length-1):r}])},[]).reverse().flatMap(e=>{let n=e.chunk.match(t),r=n?n.map(parseFloat):[];return function(e,t){let n=[];switch(e.toUpperCase()){case"M":for(let r=0;r<t.length;r+=2){let i;i=e===e.toUpperCase()?0===r?"M":"L":0===r?"m":"l",n.push({marker:i,values:{x:t[r],y:t[r+1]}})}break;case"L":for(let r=0;r<t.length;r+=2)n.push({marker:e,values:{x:t[r],y:t[r+1]}});break;case"H":for(let r=0;r<t.length;r++)n.push({marker:e,values:{x:t[r],y:0}});break;case"V":for(let r=0;r<t.length;r++)n.push({marker:e,values:{x:0,y:t[r]}});break;case"C":for(let r=0;r<t.length;r+=6)n.push({marker:e,values:{x1:t[r],y1:t[r+1],x2:t[r+2],y2:t[r+3],x:t[r+4],y:t[r+5]}});break;case"S":for(let r=0;r<t.length;r+=4)n.push({marker:e,values:{x2:t[r],y2:t[r+1],x:t[r+2],y:t[r+3]}});break;case"Q":for(let r=0;r<t.length;r+=4)n.push({marker:e,values:{x1:t[r],y1:t[r+1],x:t[r+2],y:t[r+3]}});break;case"T":for(let r=0;r<t.length;r+=2)n.push({marker:e,values:{x:t[r],y:t[r+1]}});break;case"A":for(let r=0;r<t.length;r+=7)n.push({marker:e,values:{radiusX:t[r],radiusY:t[r+1],rotation:t[r+2],largeArc:t[r+3],sweep:t[r+4],x:t[r+5],y:t[r+6]}});break;case"Z":n.push({marker:e,values:{x:0,y:0}})}return n}(e.marker,r)}).map(r9)}(s+=" Z"),a=[],l=[],u.forEach(e=>{"M"===e.marker&&a.push([]),a[a.length-1].push(e)}),a.forEach(e=>{e.map(r7),function e(t,n){let r=["x","y"].every(e=>0===Math.round(Math.abs(t[n].values[e]-t[0].values[e])));"L"===t[n].marker&&r&&(t[n].overlap=!0,e(t,n-1)),"Z"===t[n].marker&&e(t,n-1)}(e,e.length-1);let t="Z"==e[e.length-1].marker;e.filter(e=>!e.overlap).map((e,n,r)=>{let i,a,s;let u=function e(t,n,r){var i;let o=n-1,a=r[(o%(i=r.length)+i)%i];return"Z"!==a.marker?a:e(t,o,r)}(e,n,r),c=function e(t,n,r){var i;let o=n+1,a=r[(o%(i=r.length)+i)%i];return"Z"===a.marker?e(t,o,r):a}(e,n,r),d=ie(e.values,u.values),h=ie(e.values,c.values),f=h-d,p=180/Math.PI*f,g=Math.min(o,Math.abs(function(e,t,n){let r=it(e.values,n.values);return Math.min(it(t.values,e.values),r)}(e,u,c)/2*Math.tan(f/2))),m=(a=0,(s=180/Math.PI*f)<0&&s>=-180||s>180&&s<360?i=ir(f/2,-g):(i=ir(f/2,g),a=1,i===1/0&&(i=g)),{offset:i,sweepFlag:a}),v=m.offset,y=m.sweepFlag,b=(0==n||n==r.length-1)&&!t;switch(e.marker){case"M":case"L":let w=[e.values.x+Math.sin(d)*v,e.values.y+Math.cos(d)*v],x=[e.values.x+Math.sin(h)*v,e.values.y+Math.cos(h)*v];b?l.push({marker:e.marker,values:e.values}):l.push({marker:e.marker,values:{x:parseFloat(w[0].toFixed(3)),y:parseFloat(w[1].toFixed(3))}}),b||"L"!==c.marker&&"M"!==c.marker||l.push({marker:"A",radius:g,values:{radiusX:parseFloat(g.toFixed(3)),radiusY:parseFloat(g.toFixed(3)),rotation:p,largeArc:0,sweep:y,x:parseFloat(x[0].toFixed(3)),y:parseFloat(x[1].toFixed(3))}});break;case"C":case"S":case"Q":case"T":case"A":case"Z":l.push({marker:e.marker,values:e.values})}})}),{path:function(e){let t=["radiusX","radiusY","rotation","largeArc","sweep","x1","y1","x2","y2","x","y"];return e.map(e=>{let n="";if("Z"!==e.marker){let r=Object.keys(e.values);n=t.filter(e=>-1!==r.indexOf(e)).map(t=>e.values[t]).join()}return`${e.marker}${n}`}).join("").trim()}(l),commands:l}).path}({lines:JSON.parse(JSON.stringify(m)),cornerRadius:e.backgroundCornerRadius*(e.a.fontSize*k*.5),lineHeight:k*e.a.fontSize,padding:e.backgroundPadding*(e.a.fontSize*k*.5),width:e.a.width,align:e.align}):"",[e.backgroundEnabled,e.backgroundCornerRadius,e.a.fontSize,k,e.backgroundPadding,e.a.width,e.align,m]),N=iB(),j=0;return"middle"===e.verticalAlign?j=(e.a.height-m.length*k*e.a.fontSize)/2:"bottom"===e.verticalAlign&&(j=e.a.height-m.length*k*e.a.fontSize),(0,g.jsxs)(s(y).Fragment,{children:[(0,g.jsx)(rJ,{ref:r,x:e.a.x,y:e.a.y,rotation:e.a.rotation,hideInExport:!e.showInExport||!x,listening:!1,visible:e.backgroundEnabled,opacity:e.backgroundOpacity,data:A,fill:e.backgroundColor,offsetY:-j}),(0,g.jsx)(rQ,{ref:n,id:e.id,name:"element",hideInExport:!e.showInExport||!x,editModeEnabled:e._editModeEnabled,x:e.a.x,y:e.a.y,rotation:e.a.rotation,width:e.a.width,height:e.a.height,text:x||e.placeholder,...T,stroke:e.stroke,lineJoin:"round",strokeWidth:e.strokeWidth,fillAfterStrokeEnabled:!0,fontSize:e.a.fontSize,fontFamily:`"${e.fontFamily}", "${p}"`,fontStyle:e.fontStyle+" "+e.fontWeight,textDecoration:e.textDecoration,align:e.align,verticalAlign:e.verticalAlign,draggable:N?e.draggable&&h:e.draggable,preventDefault:!N||h,opacity:O,visible:!e._editModeEnabled,ellipsis:"ellipsis"===iN.textOverflow,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,lineHeight:k,letterSpacing:e.letterSpacing*e.a.fontSize,listening:P,onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},onMouseEnter:()=>{l(!0)},onMouseLeave:()=>{l(!1)},onClick:C,onTap:C,onTransformStart:()=>{c(!0),d.current=n.current.height()},onTransform:t=>{let n=t.target;r.current?.setAttrs({x:n.x(),y:n.y(),rotation:n.rotation(),scale:n.scale()});let i=(n.getStage()?.findOne("Transformer")).getActiveAnchor();if("middle-left"===i||"middle-right"===i){let t=n.scaleX(),r=n.width()*t,i=e.a.fontSize,o=r;r<i&&(o=i,E.current&&n.position(E.current)),n.width(o),n.scaleX(1),n.scaleY(1);let a=_();if("ellipsis"!==iN.textOverflow){let t=Math.max(a,d.current);n.height(t),e.set({height:n.height()})}e.set({x:n.x(),y:n.y(),width:n.width(),rotation:n.rotation()}),iI(n,e)}if("top-center"===i||"bottom-center"===i){let n="resize"===iN.textOverflow?_():k*e.a.fontSize;t.target.height(Math.max(n,t.target.height()*t.target.scaleY())),t.target.scaleY(1)}E.current=t.target.position()},onTransformEnd:t=>{let n=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),e.set({fontSize:Math.round(e.a.fontSize*n),width:Math.ceil(t.target.width()*n),x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),height:t.target.height()*n,shadowBlur:e.shadowBlur*n,shadowOffsetX:e.shadowOffsetX*n,shadowOffsetY:e.shadowOffsetY*n,strokeWidth:e.strokeWidth*n}),r.current?.setAttrs({scaleX:1,scaleY:1}),c(!1)}}),i&&(0,g.jsx)(r$,{x:e.a.x,y:e.a.y,rotation:e.a.rotation,children:(0,g.jsx)(iG,{textNodeRef:n,element:e,selectAll:o,cursorPosition:S.current,onBlur:()=>{e.toggleEditMode(!1)}})}),!u&&(a||h)&&(0,g.jsx)(iD,{element:e})]})});var y=f("8NFma"),b=f("2SBKn"),y=f("8NFma");function iZ(e){let t={fill:"",stroke:""};if(e.getAttribute("fill")&&"none"!==e.getAttribute("fill")&&(t.fill=e.getAttribute("fill")),!t.fill&&e.style.fill&&"none"!==e.style.fill&&(t.fill=e.style.fill),e.getAttribute("stroke")&&(t.stroke=e.getAttribute("stroke")),!t.stroke&&e.style.stroke&&(t.stroke=e.style.stroke),!t.stroke&&!t.fill){let n=e.ownerSVGElement,r=n&&n!==e&&iZ(n);r?.fill==="currentColor"||r?.stroke==="currentColor"||(t.fill="black")}return t}let iQ=["path","rect","circle"];function iJ(e){for(var t=[],n=e.getElementsByTagName("*"),r=0,i=n.length;r<i;r++){let e=n[r];!function(e){for(;e.parentNode;){if("defs"===e.nodeName)return!0;e=e.parentNode}return!1}(e)&&(null!==e.getAttribute("fill")&&t.push(e),null!==e.getAttribute("stroke")?t.push(e):e.style&&e.style.fill?t.push(e):iQ.indexOf(e.nodeName)>=0&&t.push(e))}return t}async function i0(e){let t=await fetch(e);return i2(await t.text())}async function i1(e){let t=await fetch(e,{mode:"cors"});return await t.text()}function i2(e){return"data:image/svg+xml;base64,"+window.btoa(unescape(encodeURIComponent(e)))}async function i3(e){let t=await i1(e),n=new DOMParser().parseFromString(t,"image/svg+xml").documentElement.getAttribute("viewBox"),[r,i,o,a]=n?.split(" ")||[];return{width:parseFloat(o),height:parseFloat(a)}}function i5(e){var t=new DOMParser().parseFromString(e,"image/svg+xml");let n=t.documentElement.getAttribute("viewBox"),[r,i,o,a]=n?.split(" ")||[],l=t.documentElement.getAttribute("width");l||t.documentElement.setAttribute("width",o+"px");let s=t.documentElement.getAttribute("height");if((!s||s.indexOf("%")>=0)&&t.documentElement.setAttribute("height",a+"px"),l&&l.indexOf("%")>=0&&s&&-1===s.indexOf("%")){let e=parseFloat(s)/parseFloat(a);t.documentElement.setAttribute("width",e*parseFloat(o)+"px")}if(s&&s.indexOf("%")>=0&&l&&-1===l.indexOf("%")){let e=parseFloat(l)/parseFloat(o);t.documentElement.setAttribute("height",e*parseFloat(a)+"px")}return"100%"===l&&"100%"===s&&(t.documentElement.setAttribute("width",o+"px"),t.documentElement.setAttribute("height",a+"px")),new XMLSerializer().serializeToString(t)}let i6=(e,t)=>{if(!e||!t)return!1;if("currentColor"===t&&"black"===e)return!0;let n=s(N).Util.colorToRGBA(e),r=s(N).Util.colorToRGBA(t);if(n&&r)return n.r===r.r&&n.g===r.g&&n.b===r.b&&n.a===r.a};function i4(e,t){var n=new DOMParser().parseFromString(e,"image/svg+xml");let r=iJ(n),i=Array.from(t.keys());return r.forEach(e=>{let{fill:r,stroke:o}=iZ(e);[{prop:"fill",color:r},{prop:"stroke",color:o}].forEach(({prop:r,color:o})=>{let a=i.find(e=>i6(e,o));if(a){let i=t.get(a);if(ia(i)){let{rotation:t,stops:o}=is(i),a=o.map(e=>({offset:100*e.offset+"%","stop-color":e.color})),l="color"+Math.round(1e8*Math.random());(function(e,t,n,r){var i=e.namespaceURI,o=document.createElementNS(i,"linearGradient");let a=s(N).Util.degToRad(n+90),l=(Math.cos(a)+1)/2,u=(Math.sin(a)+1)/2,c=(Math.cos(a+Math.PI)+1)/2,d=(Math.sin(a+Math.PI)+1)/2;o.setAttribute("x1",100*l+"%"),o.setAttribute("y1",100*u+"%"),o.setAttribute("x2",100*c+"%"),o.setAttribute("y2",100*d+"%"),o.setAttribute("gradientUnits","userSpaceOnUse"),o.setAttribute("id",t);for(var h=0;h<r.length;h++){var f=r[h],p=document.createElementNS(i,"stop");for(var g in f)f.hasOwnProperty(g)&&p.setAttribute(g,f[g]);o.appendChild(p)}(e.querySelector("defs")||e.insertBefore(document.createElementNS(i,"defs"),e.firstChild)).appendChild(o)})(n.children[0],l,t,a),e.style[r]=null,e.setAttribute(r,`url('#${l}')`)}else e.style[r]=t.get(a)}})}),i2(new XMLSerializer().serializeToString(n))}let i8=e=>{let[t,n]=s(y).useState([]);return s(y).useEffect(()=>{let t=!1;return(async()=>{n([]);let r=function(e){let t=iJ(new DOMParser().parseFromString(e,"image/svg+xml")),n=[];return t.forEach(e=>{let{fill:t,stroke:r}=iZ(e);[t,r].forEach(e=>{e&&("currentColor"===e&&(e="black"),s(N).Util.colorToRGBA(e)&&-1===n.indexOf(e)&&n.push(e))})}),n}(await i1(e));t||n(r)})(),()=>{t=!0}},[e]),t};function i9(){return document.createElement("canvas")}async function i7(e){return e.indexOf("data:image/svg+xml")>=0||e.indexOf(".svg")>=0?i2(i5(await i1(e))):e}let oe=e=>{let[t,n]=s(y).useState(e);return s(y).useEffect(()=>{(async()=>{let r=await i7(e);r!==t&&n(r)})()},[e]),t};function ot(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2}}let on=(e,t,n)=>{let r=s(y).useMemo(()=>{let{flipX:r,flipY:i}=e,o="svg"===e.type||e.src.indexOf("data:image/svg+xml")>=0||e.src.indexOf(".svg")>=0,a=navigator.userAgent.toLowerCase().indexOf("firefox")>-1&&o||e.maskSrc;if(!r&&!i&&!a)return t;if(!t||!t.width||!t.height)return null;let l=i9(),s=1;"svg"===e.type&&(s=Math.max(e.a.width/t.width*n,e.a.height/t.height*n)),l.width=Math.max(t.width*s,1),l.height=Math.max(t.height*s,1);let u=r?-l.width:0,c=i?-l.height:0;return l.getContext("2d")?.scale(r?-1:1,i?-1:1),l.getContext("2d")?.drawImage(t,u,c,l.width,l.height),l},[e.maskSrc,e.flipX,e.flipY,t,e.a.width,e.a.height,n]);return s(y).useEffect(()=>()=>{r&&"CANVAS"===r.nodeName&&s(N).Util.releaseCanvas(r)},[r]),r},or=(e,t)=>{let[n,r]=ou(e.maskSrc,"anonymous");return oc(e.maskSrc?r:"loaded",e.id+"-mask"),s(y).useMemo(()=>{if(!n||!t||!t.width||!t.height)return t;let r=i9();r.width=Math.max(t.width,1),r.height=Math.max(t.height,1);let i=r.getContext("2d");if(!i)return t;i.drawImage(t,0,0),i.globalCompositeOperation="source-in";let o=function(e,t){let n,r;let i=t.width/t.height;return i>=e.width/e.height?(n=e.width,r=e.width/i):(n=e.height*i,r=e.height),{x:(e.width-n)/2,y:(e.height-r)/2,width:n,height:r}}(n,e);return i.drawImage(n,o.x,o.y,o.width,o.height,0,0,t.width,t.height),r},[t,n,e.a.width,e.a.height])},oi=(e,t,n,r,i=0,o=!1)=>{let a=Math.floor(Math.max(e.a.width*r,1)),l=Math.floor(Math.max(e.a.height*r,1)),u=Math.min(i*r,a/2,l/2),c=Math.max(e.a.width/n.width,e.a.height/n.height)*r,d=e.page._exporting&&iN.imageDownScalingEnabled&&c<1&&!o,h=0===n.x&&0===n.y&&n.width===t?.width&&n.height===t?.height,f=s(y).useMemo(()=>{if(!t||!t.width||!t.height)return;let e=0===u,n=!d;if(!h||!e||!n)return i9()},[t,u,d,h]);return s(y).useLayoutEffect(()=>{if(!f||!t)return;f.width=a,f.height=l;let e=f.getContext("2d");if(!e)return;u&&(e.beginPath(),e.moveTo(u,0),e.lineTo(a-u,0),e.arc(a-u,u,u,3*Math.PI/2,0,!1),e.lineTo(a,l-u),e.arc(a-u,l-u,u,0,Math.PI/2,!1),e.lineTo(u,l),e.arc(u,l-u,u,Math.PI/2,Math.PI,!1),e.lineTo(0,u),e.arc(u,u,u,Math.PI,3*Math.PI/2,!1),e.clip());let r=d?function(e,t){let n=i9();n.width=e.width,n.height=e.height;let r=Math.max(1,Math.floor(n.width*t)),i=Math.max(1,Math.floor(n.height*t));n.getContext("2d")?.drawImage(e,0,0,n.width,n.height);let o=function(e,t,n,r,i,o,a){for(var l=new ImageData(t,n),s=new Int32Array(e.data.buffer),u=e.width,c=new Int32Array(l.data.buffer),d=l.width,h=t/o,f=n/a,p=Math.round(1/h),g=Math.round(1/f),m=p*g,v=0;v<l.height;v++)for(var y=0;y<d;y++){for(var b=0+Math.round(y/h)+(0+Math.round(v/f))*u,w=0,x=0,_=0,E=0,S=0;S<g;S++)for(var C=0;C<p;C++){var O=s[b+C+S*u];w+=O<<24>>>24,x+=O<<16>>>24,_+=O<<8>>>24,E+=O>>>24}w=Math.round(w/m),x=Math.round(x/m),_=Math.round(_/m),E=Math.round(E/m),c[y+v*d]=E<<24|_<<16|x<<8|w}return l}(n.getContext("2d").getImageData(0,0,n.width,n.height),r,i,0,0,n.width,n.height);return n.width=r,n.height=i,n.getContext("2d")?.putImageData(o,0,0),n}(t,c):t,i=d?{x:Math.floor(n.x*c),y:Math.floor(n.y*c),width:Math.floor(n.width*c),height:Math.floor(n.height*c)}:n;e.drawImage(r,i.x,i.y,i.width,i.height,0,0,f.width,f.height)},[f,e.a.width,e.a.height,n.x,n.y,n.width,n.height,i,r,o,e.page._exporting,d]),s(y).useEffect(()=>()=>{f&&"CANVAS"===f.nodeName&&s(N).Util.releaseCanvas(f)},[f]),f||t},oo=(e,t,n,r)=>{let[i,o]=ou(oe(e.clipSrc||""),"anonymous");oc(e.clipSrc?o:"loaded",e.id+"-clip");let a=s(y).useMemo(()=>{if(t&&i)return i9()},[t,i]);return s(y).useLayoutEffect(()=>{if(!i||!t||!t.width||!t.height||!i||!i.width||!i.height||!a)return;let r=i9(),o=Math.max(e.a.width/i.width*n,e.a.height/i.height*n);r.width=i.width*o,r.height=i.height*o,r.getContext("2d")?.drawImage(i,0,0,r.width,r.height),a.width=Math.max(t.width,1),a.height=Math.max(t.height,1);let l=a.getContext("2d");l&&(l.save(),l.drawImage(r,0,0,t.width,t.height),s(N).Util.releaseCanvas(r),l.globalCompositeOperation="source-in",l.drawImage(t,0,0,a.width,a.height),l.restore())},[a,t,i,e.a.width,e.a.height,n,...r]),e.clipSrc&&i?a:t},oa=i9(),ol=T(({element:e})=>{let t=Math.min(30,e.a.width/4,e.a.height/4),n=s(y).useRef(null);return s(y).useEffect(()=>{let e=n.current;if(!e)return;let t=new(s(N)).Animation(t=>{e.rotate((t?.timeDiff||0)/2)},e.getLayer());return t.start(),()=>{t.stop()}}),(0,g.jsxs)(r$,{x:e.x,y:e.y,rotation:e.rotation,listening:!1,opacity:e.a.opacity,hideInExport:!e.showInExport,children:[(0,g.jsx)(rY,{width:e.a.width,height:e.a.height,fill:"rgba(124, 173, 212, 0.8)"}),(0,g.jsx)("Arc",{ref:n,x:e.a.width/2,y:e.a.height/2,fill:"white",outerRadius:Math.abs(t),innerRadius:Math.max(1,t-5),angle:270})]})}),os=T(({element:e})=>{let t="Can not load the image...",n=Math.max(10,Math.min(30,e.a.width/t.length));return(0,g.jsxs)(r$,{x:e.x,y:e.y,rotation:e.rotation,listening:!1,opacity:e.a.opacity,hideInExport:!e.showInExport,children:[(0,g.jsx)(rY,{width:e.a.width,height:e.a.height,fill:"rgba(223, 102, 102, 0.8)"}),(0,g.jsx)(rQ,{text:t,fontSize:n,width:e.a.width,height:e.a.height,align:"center",fill:"white",verticalAlign:"middle",padding:5})]})}),ou=s(r3),oc=(e,t)=>{let n=s(y).useRef(),r=()=>{n.current?.(),n.current=void 0};s(y).useEffect(()=>r,[]),s(y).useLayoutEffect(()=>{"loading"!==e||n.current||(n.current=im(`image ${t}`)),"loading"!==e&&r(),"failed"===e&&ib(`image ${t}`)},[e])},od=({image:e,status:t,type:n})=>{let r=s(y).useRef();return s(y).useEffect(()=>{r.current=e||r.current},[e]),"failed"!==t||"failed"!==t&&"svg"===n?r.current:void 0},oh=e=>{let[t,n]=s(y).useReducer(e=>e+1,0),r=s(y).useRef("loading"),i=s(y).useRef(e.src),o=s(y).useRef(e.src);return(o.current!==e.src&&(o.current=e.src,r.current="loading"),s(y).useEffect(()=>{if("svg"!==e.type||!e.src)return;let t=!1;return(async()=>{r.current="loading",n();let o=i4(i5(await i1(e.src)),e.colorsReplace);t||(i.current=o,r.current="loaded",n())})(),()=>{t=!0}},[e.src,JSON.stringify(e.colorsReplace)]),"svg"!==e.type)?[e.src,"loaded"]:[i.current,r.current]},of=T(({element:e,store:t})=>{let n,r;let[i,o]=s(y).useState(!1),a=s(y).useRef(null),l=s(y).useRef(null),[u,c]=s(y).useState(!1),d=t.selectedElements.indexOf(e)>=0,[h,f]=oh(e),[p,m]=ou(h,"anonymous");oc("svg"!==e.type||"loaded"===f?m:"loading",e.id);let v=od({image:p,status:m,type:e.type}),w=or(e,on(e,p||v,t._elementsPixelRatio))||oa,{cropX:x,cropY:_,cropWidth:E,cropHeight:S}=e;"loaded"!==m&&(x=_=0,E=S=1);let C=w.width*E,O=w.height*S,k=e.a.width/e.a.height,P=C/O,T="svg"===e.type;T?(n=C,r=O):k>=P?(n=C,r=C/k):(n=O*k,r=O);let A={x:w.width*x,y:w.height*_,width:n,height:r},j=e.cornerRadius??0,R=e.page._exporting?1:Math.min(2,t.scale),L=t._elementsPixelRatio*R,I=oo(e,oi(e,w,A,L,j,i||e._cropModeEnabled||"svg"===e.type),L,[A,j,L]),M=Math.max(e.a.width/n,e.a.height/r);s(y).useEffect(()=>{if(!e._cropModeEnabled)return;let t=a.current?.getStage();function n(t){e._cropModeEnabled&&t.target!==l.current&&e.toggleCropMode(!1)}function r(n){e._cropModeEnabled&&n.target.parentNode!==t.content&&e.toggleCropMode(!1)}return document.body.addEventListener("click",r),t?.on("click",n),t?.on("tap",n),()=>{document.body.removeEventListener("click",r),document.body.removeEventListener("touchstart",r),t?.off("click",n),t?.off("click",n)}},[e._cropModeEnabled]),s(y).useLayoutEffect(()=>{if(!i&&!e._cropModeEnabled)return iI(a.current,e),(0,b.autorun)(()=>{iI(a.current,e)},{delay:100})},[w,e.page._exporting,i,E,S,e._cropModeEnabled]),s(y).useLayoutEffect(()=>{i||e._cropModeEnabled?a.current?.clearCache():iI(a.current,e)},[i,e.a.width,e.a.height,e._cropModeEnabled]),s(y).useEffect(()=>{iI(a.current,e)},[e.shadowEnabled,e.shadowBlur,e.cornerRadius,e.shadowColor,e.shadowOffsetX,e.shadowOffsetY,e.shadowOpacity]);let D=s(y).useRef(null),F=s(y).useRef(null),z=s(y).useRef(null);s(y).useLayoutEffect(()=>{e._cropModeEnabled&&(F.current.nodes([D.current]),z.current.nodes([l.current]))},[e._cropModeEnabled]);var B=s(y).useRef(null),U=s(y).useRef(0),H=s(y).useRef(!1);let V=t=>{t.evt.touches?.length>2&&t.target.stopDrag(),Math.round(t.target.x())>0&&(t.target.x(0),t.target.scaleX(1)),Math.round(t.target.y())>0&&(t.target.y(0),t.target.scaleY(1));let i=t.target.width()*t.target.scaleX(),o=t.target.height()*t.target.scaleY(),a=Math.min(1,n/i),l=Math.min(1,r/o),s=Math.min(1-a,Math.max(0,Math.round(-t.target.x())/i)),u=Math.min(1-l,Math.max(0,Math.round(-t.target.y())/o));t.target.setAttrs({x:-s*w.width,y:-u*w.height,scaleX:1,scaleY:1}),e.set({cropX:s,cropY:u,cropWidth:a,cropHeight:l})},q=()=>{"svg"!==e.type&&e.contentEditable&&setTimeout(()=>{e.toggleCropMode(!0)})},G="svg"===e.type&&v,W="loading"===m&&!G,$="failed"===m,K=!W&&!$,Y=s(y).useRef({cropX:0,cropY:0,cropWidth:0,cropHeight:0}),X=K?e.a.opacity:0;id(a,X);let Z=e.selectable||"admin"===t.role,Q=iB();return(0,g.jsxs)(s(y).Fragment,{children:[W&&(0,g.jsx)(ol,{element:e}),$&&(0,g.jsx)(os,{element:e}),(0,g.jsx)(rZ,{ref:a,name:"element",id:e.id,image:I,x:e.a.x,y:e.a.y,width:e.a.width||1,height:e.a.height||1,rotation:e.rotation,opacity:X,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,customCrop:A,listening:Z,draggable:Q?e.draggable&&d:e.draggable,preventDefault:!Q||d,hideInExport:!e.showInExport,onMouseEnter:()=>{c(!0)},onMouseLeave:()=>{c(!1)},onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDblClick:q,onDblTap:q,onTransformStart:()=>{o(!0),Y.current={cropX:e.cropX,cropY:e.cropY,cropWidth:e.cropWidth,cropHeight:e.cropHeight}},onTransform:t=>{let i=t.currentTarget,o=1e-7>Math.abs(i.scaleX()-1)?1:i.scaleX(),a=1e-7>Math.abs(i.scaleY()-1)?1:i.scaleY();i.scaleX(1),i.scaleY(1);let l=t.target.getStage()?.findOne("Transformer"),s=Math.min(1-n/w.width,Math.max(0,e.cropX)),u=Math.min(1-r/w.height,Math.max(0,e.cropY)),c=l.getActiveAnchor(),d=!(c.indexOf("middle")>=0||c.indexOf("center")>=0),h=!d&&o<1&&Y.current.cropHeight>r/w.height,f=d?e.cropWidth:e.cropWidth*o;h&&(f=e.cropWidth);let p=!d&&a<1&&Y.current.cropWidth>n/w.width,g=d?e.cropHeight:e.cropHeight*a;p&&(g=e.cropHeight),T&&(f=e.cropWidth,g=e.cropHeight),e.set({cropX:s,cropY:u,x:i.x(),y:i.y(),width:i.width()*o,height:i.height()*a,rotation:t.target.rotation(),cropWidth:Math.min(f,1-s),cropHeight:Math.min(g,1-u)})},onTransformEnd:t=>{let i=t.currentTarget;e.set({width:i.width(),height:i.height(),x:i.x(),y:i.y(),rotation:t.target.rotation(),cropWidth:n/w.width,cropHeight:r/w.height}),o(!1)}}),(0,g.jsx)(rY,{x:e.x,y:e.y,width:Math.max(e.a.width-e.borderSize,0),height:Math.max(e.a.height-e.borderSize,0),opacity:X,offsetX:-e.borderSize/2,offsetY:-e.borderSize/2,stroke:e.borderColor,strokeWidth:e.borderSize,listening:!1,visible:!!e.borderSize,rotation:e.rotation,cornerRadius:Math.max(0,j-e.borderSize),hideInExport:!e.showInExport}),e._cropModeEnabled&&(0,g.jsxs)(r8,{selector:".page-abs-container",enabled:!0,children:[(0,g.jsx)(rY,{x:-window.innerWidth/t.scale,y:-window.innerWidth/t.scale,width:window.innerWidth/t.scale*3,height:window.innerWidth/t.scale*3,fill:"rgba(0,0,0,0.3)"}),(0,g.jsx)(rZ,{listening:!1,image:I,x:e.x,y:e.y,width:e.a.width,height:e.a.height,rotation:e.rotation,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur}),(0,g.jsxs)(r$,{x:e.x,y:e.y,rotation:e.rotation,scaleX:M,scaleY:M,children:[(0,g.jsx)(rZ,{image:w,ref:l,opacity:.4,draggable:!0,x:-e.cropX*w.width,y:-e.cropY*w.height,onDragMove:V,onTransform:V,onTouchMove:e=>{e.evt.preventDefault();let t=e.target.getStage().getPointersPositions();var n=t[0],r=t[1];let i=e.target;if(n&&!r&&!i.isDragging()&&H.current&&(i.startDrag(),H.current=!1),n&&r){s(N).hitOnDragEnabled=!0,i.isDragging()&&(H.current=!0,i.stopDrag());let t=e.target.getAbsoluteTransform().copy();t.invert();var o={x:n.x,y:n.y},a={x:r.x,y:r.y};if(!B.current){B.current=ot(o,a);return}var l=ot(o,a),u=Math.sqrt(Math.pow(a.x-o.x,2)+Math.pow(a.y-o.y,2));U.current||(U.current=u);let g=i.position();var c={x:l.x-g.x,y:l.y-g.y},d=u/U.current;i.scaleX(d),i.scaleY(d);let m=t.point(l),v=t.point(B.current);var h=m.x-v.x,f=m.y-v.y,p={x:Math.min(0,l.x-c.x*d+h),y:Math.min(0,l.y-c.y*d+f)};i.position(p),U.current=u,B.current=l,V(e)}},onTouchEnd:e=>{U.current=0,B.current=null,s(N).hitOnDragEnabled=!1}}),(0,g.jsx)(r0,{ref:z,anchorSize:20,enabledAnchors:["top-left","top-right","bottom-left","bottom-right"],boundBoxFunc:(e,t)=>t.width<5||t.height<5?e:t,rotateEnabled:!1,borderEnabled:!1,anchorCornerRadius:10,anchorStrokeWidth:2,borderStrokeWidth:2}),(0,g.jsx)(rY,{width:n,height:r,ref:D,listening:!1,onTransform:t=>{t.target.x()<-e.cropX*w.width-1e-9&&(t.target.x(-e.cropX*w.width),t.target.scaleX(1)),t.target.y()<-e.cropY*w.height-1e-9&&(t.target.y(-e.cropY*w.height),t.target.scaleY(1));let n=Math.min(1,Math.max(0,e.cropX+t.target.x()/w.width)),r=Math.min(1,Math.max(0,t.target.y()/w.height+e.cropY)),i=t.target.width()*t.target.scaleX(),o=t.target.height()*t.target.scaleY(),a=Math.min(1-n,i/w.width),l=Math.min(1-r,o/w.height),s=t.target.getAbsolutePosition(t.target.getParent().getParent());t.target.scale({x:1,y:1}),t.target.position({x:0,y:0}),e.set({x:s.x,y:s.y,cropX:n,cropY:r,cropWidth:a,cropHeight:l,width:Math.min(i*M,w.width*(1-n)*M),height:Math.min(o*M,w.height*(1-r)*M)})}}),(0,g.jsx)(r0,{ref:F,enabledAnchors:["top-left","top-right","bottom-left","bottom-right"],boundBoxFunc:(e,t)=>t.width<5||t.height<5?e:t,visible:e.resizable,keepRatio:!1,rotateEnabled:!1,anchorFill:"rgb(240, 240, 240)",anchorStrokeWidth:2,borderStrokeWidth:2})]})]}),(u||d)&&(0,g.jsx)(iD,{element:e})]})});var y=f("8NFma"),op=f("1BElU");window,kQ=f("1BElU"),function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t||4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,(function(t){return e[t]}).bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(e,t,n){/*! @license DOMPurify 3.0.5 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.0.5/LICENSE */e.exports=function(){let{entries:e,setPrototypeOf:t,isFrozen:n,getPrototypeOf:r,getOwnPropertyDescriptor:i}=Object,{freeze:o,seal:a,create:l}=Object,{apply:s,construct:u}="undefined"!=typeof Reflect&&Reflect;s||(s=function(e,t,n){return e.apply(t,n)}),o||(o=function(e){return e}),a||(a=function(e){return e}),u||(u=function(e,t){return new e(...t)});let c=x(Array.prototype.forEach),d=x(Array.prototype.pop),h=x(Array.prototype.push),f=x(String.prototype.toLowerCase),p=x(String.prototype.toString),g=x(String.prototype.match),m=x(String.prototype.replace),v=x(String.prototype.indexOf),y=x(String.prototype.trim),b=x(RegExp.prototype.test),w=(G=TypeError,function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return u(G,t)});function x(e){return function(t){for(var n=arguments.length,r=Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];return s(e,t,r)}}function _(e,r,i){var o;i=null!==(o=i)&&void 0!==o?o:f,t&&t(e,null);let a=r.length;for(;a--;){let t=r[a];if("string"==typeof t){let e=i(t);e!==t&&(n(r)||(r[a]=e),t=e)}e[t]=!0}return e}function E(t){let n=l(null);for(let[r,i]of e(t))n[r]=i;return n}function S(e,t){for(;null!==e;){let n=i(e,t);if(n){if(n.get)return x(n.get);if("function"==typeof n.value)return x(n.value)}e=r(e)}return function(e){return console.warn("fallback value for",e),null}}let C=o(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dialog","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","section","select","shadow","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]),O=o(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","filter","font","g","glyph","glyphref","hkern","image","line","lineargradient","marker","mask","metadata","mpath","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),k=o(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),P=o(["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"]),T=o(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover","mprescripts"]),A=o(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),N=o(["#text"]),j=o(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","face","for","headers","height","hidden","high","href","hreflang","id","inputmode","integrity","ismap","kind","label","lang","list","loading","loop","low","max","maxlength","media","method","min","minlength","multiple","muted","name","nonce","noshade","novalidate","nowrap","open","optimum","pattern","placeholder","playsinline","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","span","srclang","start","src","srcset","step","style","summary","tabindex","title","translate","type","usemap","valign","value","width","xmlns","slot"]),R=o(["accent-height","accumulate","additive","alignment-baseline","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clippathunits","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dur","edgemode","elevation","end","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","systemlanguage","tabindex","targetx","targety","transform","transform-origin","text-anchor","text-decoration","text-rendering","textlength","type","u1","u2","unicode","values","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]),L=o(["accent","accentunder","align","bevelled","close","columnsalign","columnlines","columnspan","denomalign","depth","dir","display","displaystyle","encoding","fence","frame","height","href","id","largeop","length","linethickness","lspace","lquote","mathbackground","mathcolor","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","numalign","open","rowalign","rowlines","rowspacing","rowspan","rspace","rquote","scriptlevel","scriptminsize","scriptsizemultiplier","selection","separator","separators","stretchy","subscriptshift","supscriptshift","symmetric","voffset","width","xmlns"]),I=o(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),M=a(/\{\{[\w\W]*|[\w\W]*\}\}/gm),D=a(/<%[\w\W]*|[\w\W]*%>/gm),F=a(/\${[\w\W]*}/gm),z=a(/^data-[\-\w.\u00B7-\uFFFF]/),B=a(/^aria-[\-\w]+$/),U=a(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),H=a(/^(?:\w+script|data):/i),V=a(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),q=a(/^html$/i);var G,W=Object.freeze({__proto__:null,MUSTACHE_EXPR:M,ERB_EXPR:D,TMPLIT_EXPR:F,DATA_ATTR:z,ARIA_ATTR:B,IS_ALLOWED_URI:U,IS_SCRIPT_OR_DATA:H,ATTR_WHITESPACE:V,DOCTYPE_NAME:q});let $=()=>"undefined"==typeof window?null:window,K=function(e,t){if("object"!=typeof e||"function"!=typeof e.createPolicy)return null;let n=null;t&&t.hasAttribute("data-tt-policy-suffix")&&(n=t.getAttribute("data-tt-policy-suffix"));let r="dompurify"+(n?"#"+n:"");try{return e.createPolicy(r,{createHTML:e=>e,createScriptURL:e=>e})}catch(e){return console.warn("TrustedTypes policy "+r+" could not be created."),null}};return function t(){let n,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:$(),i=e=>t(e);if(i.version="3.0.5",i.removed=[],!r||!r.document||9!==r.document.nodeType)return i.isSupported=!1,i;let a=r.document,l=a.currentScript,{document:s}=r,{DocumentFragment:u,HTMLTemplateElement:x,Node:M,Element:D,NodeFilter:F,NamedNodeMap:z=r.NamedNodeMap||r.MozNamedAttrMap,HTMLFormElement:B,DOMParser:H,trustedTypes:V}=r,G=D.prototype,Y=S(G,"cloneNode"),X=S(G,"nextSibling"),Z=S(G,"childNodes"),Q=S(G,"parentNode");if("function"==typeof x){let e=s.createElement("template");e.content&&e.content.ownerDocument&&(s=e.content.ownerDocument)}let J,ee="",{implementation:et,createNodeIterator:en,createDocumentFragment:er,getElementsByTagName:ei}=s,{importNode:eo}=a,ea={};i.isSupported="function"==typeof e&&"function"==typeof Q&&et&&void 0!==et.createHTMLDocument;let{MUSTACHE_EXPR:el,ERB_EXPR:es,TMPLIT_EXPR:eu,DATA_ATTR:ec,ARIA_ATTR:ed,IS_SCRIPT_OR_DATA:eh,ATTR_WHITESPACE:ef}=W,{IS_ALLOWED_URI:ep}=W,eg=null,em=_({},[...C,...O,...k,...T,...N]),ev=null,ey=_({},[...j,...R,...L,...I]),eb=Object.seal(Object.create(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),ew=null,ex=null,e_=!0,eE=!0,eS=!1,eC=!0,eO=!1,ek=!1,eP=!1,eT=!1,eA=!1,eN=!1,ej=!1,eR=!0,eL=!1,eI=!0,eM=!1,eD={},eF=null,ez=_({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]),eB=null,eU=_({},["audio","video","img","source","image","track"]),eH=null,eV=_({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),eq="http://www.w3.org/1998/Math/MathML",eG="http://www.w3.org/2000/svg",eW="http://www.w3.org/1999/xhtml",e$=eW,eK=!1,eY=null,eX=_({},[eq,eG,eW],p),eZ=["application/xhtml+xml","text/html"],eQ,eJ=null,e0=s.createElement("form"),e1=function(e){return e instanceof RegExp||e instanceof Function},e2=function(e){if(!eJ||eJ!==e){if(e&&"object"==typeof e||(e={}),e=E(e),eQ="application/xhtml+xml"===(n=n=-1===eZ.indexOf(e.PARSER_MEDIA_TYPE)?"text/html":e.PARSER_MEDIA_TYPE)?p:f,eg="ALLOWED_TAGS"in e?_({},e.ALLOWED_TAGS,eQ):em,ev="ALLOWED_ATTR"in e?_({},e.ALLOWED_ATTR,eQ):ey,eY="ALLOWED_NAMESPACES"in e?_({},e.ALLOWED_NAMESPACES,p):eX,eH="ADD_URI_SAFE_ATTR"in e?_(E(eV),e.ADD_URI_SAFE_ATTR,eQ):eV,eB="ADD_DATA_URI_TAGS"in e?_(E(eU),e.ADD_DATA_URI_TAGS,eQ):eU,eF="FORBID_CONTENTS"in e?_({},e.FORBID_CONTENTS,eQ):ez,ew="FORBID_TAGS"in e?_({},e.FORBID_TAGS,eQ):{},ex="FORBID_ATTR"in e?_({},e.FORBID_ATTR,eQ):{},eD="USE_PROFILES"in e&&e.USE_PROFILES,e_=!1!==e.ALLOW_ARIA_ATTR,eE=!1!==e.ALLOW_DATA_ATTR,eS=e.ALLOW_UNKNOWN_PROTOCOLS||!1,eC=!1!==e.ALLOW_SELF_CLOSE_IN_ATTR,eO=e.SAFE_FOR_TEMPLATES||!1,ek=e.WHOLE_DOCUMENT||!1,eA=e.RETURN_DOM||!1,eN=e.RETURN_DOM_FRAGMENT||!1,ej=e.RETURN_TRUSTED_TYPE||!1,eT=e.FORCE_BODY||!1,eR=!1!==e.SANITIZE_DOM,eL=e.SANITIZE_NAMED_PROPS||!1,eI=!1!==e.KEEP_CONTENT,eM=e.IN_PLACE||!1,ep=e.ALLOWED_URI_REGEXP||U,e$=e.NAMESPACE||eW,eb=e.CUSTOM_ELEMENT_HANDLING||{},e.CUSTOM_ELEMENT_HANDLING&&e1(e.CUSTOM_ELEMENT_HANDLING.tagNameCheck)&&(eb.tagNameCheck=e.CUSTOM_ELEMENT_HANDLING.tagNameCheck),e.CUSTOM_ELEMENT_HANDLING&&e1(e.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)&&(eb.attributeNameCheck=e.CUSTOM_ELEMENT_HANDLING.attributeNameCheck),e.CUSTOM_ELEMENT_HANDLING&&"boolean"==typeof e.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements&&(eb.allowCustomizedBuiltInElements=e.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements),eO&&(eE=!1),eN&&(eA=!0),eD&&(eg=_({},[...N]),ev=[],!0===eD.html&&(_(eg,C),_(ev,j)),!0===eD.svg&&(_(eg,O),_(ev,R),_(ev,I)),!0===eD.svgFilters&&(_(eg,k),_(ev,R),_(ev,I)),!0===eD.mathMl&&(_(eg,T),_(ev,L),_(ev,I))),e.ADD_TAGS&&(eg===em&&(eg=E(eg)),_(eg,e.ADD_TAGS,eQ)),e.ADD_ATTR&&(ev===ey&&(ev=E(ev)),_(ev,e.ADD_ATTR,eQ)),e.ADD_URI_SAFE_ATTR&&_(eH,e.ADD_URI_SAFE_ATTR,eQ),e.FORBID_CONTENTS&&(eF===ez&&(eF=E(eF)),_(eF,e.FORBID_CONTENTS,eQ)),eI&&(eg["#text"]=!0),ek&&_(eg,["html","head","body"]),eg.table&&(_(eg,["tbody"]),delete ew.tbody),e.TRUSTED_TYPES_POLICY){if("function"!=typeof e.TRUSTED_TYPES_POLICY.createHTML)throw w('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if("function"!=typeof e.TRUSTED_TYPES_POLICY.createScriptURL)throw w('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');ee=(J=e.TRUSTED_TYPES_POLICY).createHTML("")}else void 0===J&&(J=K(V,l)),null!==J&&"string"==typeof ee&&(ee=J.createHTML(""));o&&o(e),eJ=e}},e3=_({},["mi","mo","mn","ms","mtext"]),e5=_({},["foreignobject","desc","title","annotation-xml"]),e6=_({},["title","style","font","a","script"]),e4=_({},O);_(e4,k),_(e4,P);let e8=_({},T);_(e8,A);let e9=function(e){let t=Q(e);t&&t.tagName||(t={namespaceURI:e$,tagName:"template"});let r=f(e.tagName),i=f(t.tagName);return!!eY[e.namespaceURI]&&(e.namespaceURI===eG?t.namespaceURI===eW?"svg"===r:t.namespaceURI===eq?"svg"===r&&("annotation-xml"===i||e3[i]):!!e4[r]:e.namespaceURI===eq?t.namespaceURI===eW?"math"===r:t.namespaceURI===eG?"math"===r&&e5[i]:!!e8[r]:e.namespaceURI===eW?!(t.namespaceURI===eG&&!e5[i])&&!(t.namespaceURI===eq&&!e3[i])&&!e8[r]&&(e6[r]||!e4[r]):!("application/xhtml+xml"!==n||!eY[e.namespaceURI]))},e7=function(e){h(i.removed,{element:e});try{e.parentNode.removeChild(e)}catch(t){e.remove()}},te=function(e,t){try{h(i.removed,{attribute:t.getAttributeNode(e),from:t})}catch(e){h(i.removed,{attribute:null,from:t})}if(t.removeAttribute(e),"is"===e&&!ev[e]){if(eA||eN)try{e7(t)}catch(e){}else try{t.setAttribute(e,"")}catch(e){}}},tt=function(e){let t,r;if(eT)e="<remove></remove>"+e;else{let t=g(e,/^[\r\n\t ]+/);r=t&&t[0]}"application/xhtml+xml"===n&&e$===eW&&(e='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+e+"</body></html>");let i=J?J.createHTML(e):e;if(e$===eW)try{t=(new H).parseFromString(i,n)}catch(e){}if(!t||!t.documentElement){t=et.createDocument(e$,"template",null);try{t.documentElement.innerHTML=eK?ee:i}catch(e){}}let o=t.body||t.documentElement;return e&&r&&o.insertBefore(s.createTextNode(r),o.childNodes[0]||null),e$===eW?ei.call(t,ek?"html":"body")[0]:ek?t.documentElement:o},tn=function(e){return en.call(e.ownerDocument||e,e,F.SHOW_ELEMENT|F.SHOW_COMMENT|F.SHOW_TEXT,null,!1)},tr=function(e){return"object"==typeof M?e instanceof M:e&&"object"==typeof e&&"number"==typeof e.nodeType&&"string"==typeof e.nodeName},ti=function(e,t,n){ea[e]&&c(ea[e],e=>{e.call(i,t,n,eJ)})},to=function(e){let t;if(ti("beforeSanitizeElements",e,null),e instanceof B&&("string"!=typeof e.nodeName||"string"!=typeof e.textContent||"function"!=typeof e.removeChild||!(e.attributes instanceof z)||"function"!=typeof e.removeAttribute||"function"!=typeof e.setAttribute||"string"!=typeof e.namespaceURI||"function"!=typeof e.insertBefore||"function"!=typeof e.hasChildNodes))return e7(e),!0;let n=eQ(e.nodeName);if(ti("uponSanitizeElement",e,{tagName:n,allowedTags:eg}),e.hasChildNodes()&&!tr(e.firstElementChild)&&(!tr(e.content)||!tr(e.content.firstElementChild))&&b(/<[/\w]/g,e.innerHTML)&&b(/<[/\w]/g,e.textContent))return e7(e),!0;if(!eg[n]||ew[n]){if(!ew[n]&&tl(n)&&(eb.tagNameCheck instanceof RegExp&&b(eb.tagNameCheck,n)||eb.tagNameCheck instanceof Function&&eb.tagNameCheck(n)))return!1;if(eI&&!eF[n]){let t=Q(e)||e.parentNode,n=Z(e)||e.childNodes;if(n&&t)for(let r=n.length-1;r>=0;--r)t.insertBefore(Y(n[r],!0),X(e))}return e7(e),!0}return e instanceof D&&!e9(e)?(e7(e),!0):("noscript"===n||"noembed"===n||"noframes"===n)&&b(/<\/no(script|embed|frames)/i,e.innerHTML)?(e7(e),!0):(eO&&3===e.nodeType&&(t=m(t=e.textContent,el," "),t=m(t,es," "),t=m(t,eu," "),e.textContent!==t&&(h(i.removed,{element:e.cloneNode()}),e.textContent=t)),ti("afterSanitizeElements",e,null),!1)},ta=function(e,t,n){if(eR&&("id"===t||"name"===t)&&(n in s||n in e0))return!1;if(eE&&!ex[t]&&b(ec,t));else if(e_&&b(ed,t));else if(!ev[t]||ex[t]){if(!(tl(e)&&(eb.tagNameCheck instanceof RegExp&&b(eb.tagNameCheck,e)||eb.tagNameCheck instanceof Function&&eb.tagNameCheck(e))&&(eb.attributeNameCheck instanceof RegExp&&b(eb.attributeNameCheck,t)||eb.attributeNameCheck instanceof Function&&eb.attributeNameCheck(t))||"is"===t&&eb.allowCustomizedBuiltInElements&&(eb.tagNameCheck instanceof RegExp&&b(eb.tagNameCheck,n)||eb.tagNameCheck instanceof Function&&eb.tagNameCheck(n))))return!1}else if(eH[t]);else if(b(ep,m(n,ef,"")));else if("src"!==t&&"xlink:href"!==t&&"href"!==t||"script"===e||0!==v(n,"data:")||!eB[e]){if(eS&&!b(eh,m(n,ef,"")));else if(n)return!1}return!0},tl=function(e){return e.indexOf("-")>0},ts=function(e){let t,n,r,o;ti("beforeSanitizeAttributes",e,null);let{attributes:a}=e;if(!a)return;let l={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:ev};for(o=a.length;o--;){let{name:s,namespaceURI:u}=t=a[o];if(n="value"===s?t.value:y(t.value),r=eQ(s),l.attrName=r,l.attrValue=n,l.keepAttr=!0,l.forceKeepAttr=void 0,ti("uponSanitizeAttribute",e,l),n=l.attrValue,l.forceKeepAttr||(te(s,e),!l.keepAttr))continue;if(!eC&&b(/\/>/i,n)){te(s,e);continue}eO&&(n=m(n,el," "),n=m(n,es," "),n=m(n,eu," "));let c=eQ(e.nodeName);if(ta(c,r,n)){if(eL&&("id"===r||"name"===r)&&(te(s,e),n="user-content-"+n),J&&"object"==typeof V&&"function"==typeof V.getAttributeType){if(u);else switch(V.getAttributeType(c,r)){case"TrustedHTML":n=J.createHTML(n);break;case"TrustedScriptURL":n=J.createScriptURL(n)}}try{u?e.setAttributeNS(u,s,n):e.setAttribute(s,n),d(i.removed)}catch(e){}}}ti("afterSanitizeAttributes",e,null)},tu=function e(t){let n;let r=tn(t);for(ti("beforeSanitizeShadowDOM",t,null);n=r.nextNode();)ti("uponSanitizeShadowNode",n,null),to(n)||(n.content instanceof u&&e(n.content),ts(n));ti("afterSanitizeShadowDOM",t,null)};return i.sanitize=function(e){let t,n,r,o,l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if((eK=!e)&&(e="<!-->"),"string"!=typeof e&&!tr(e)){if("function"!=typeof e.toString)throw w("toString is not a function");if("string"!=typeof(e=e.toString()))throw w("dirty is not a string, aborting")}if(!i.isSupported)return e;if(eP||e2(l),i.removed=[],"string"==typeof e&&(eM=!1),eM){if(e.nodeName){let t=eQ(e.nodeName);if(!eg[t]||ew[t])throw w("root node is forbidden and cannot be sanitized in-place")}}else if(e instanceof M)1===(n=(t=tt("<!---->")).ownerDocument.importNode(e,!0)).nodeType&&"BODY"===n.nodeName||"HTML"===n.nodeName?t=n:t.appendChild(n);else{if(!eA&&!eO&&!ek&&-1===e.indexOf("<"))return J&&ej?J.createHTML(e):e;if(!(t=tt(e)))return eA?null:ej?ee:""}t&&eT&&e7(t.firstChild);let s=tn(eM?e:t);for(;r=s.nextNode();)to(r)||(r.content instanceof u&&tu(r.content),ts(r));if(eM)return e;if(eA){if(eN)for(o=er.call(t.ownerDocument);t.firstChild;)o.appendChild(t.firstChild);else o=t;return(ev.shadowroot||ev.shadowrootmode)&&(o=eo.call(a,o,!0)),o}let c=ek?t.outerHTML:t.innerHTML;return ek&&eg["!doctype"]&&t.ownerDocument&&t.ownerDocument.doctype&&t.ownerDocument.doctype.name&&b(q,t.ownerDocument.doctype.name)&&(c="<!DOCTYPE "+t.ownerDocument.doctype.name+">\n"+c),eO&&(c=m(c,el," "),c=m(c,es," "),c=m(c,eu," ")),J&&ej?J.createHTML(c):c},i.setConfig=function(e){e2(e),eP=!0},i.clearConfig=function(){eJ=null,eP=!1},i.isValidAttribute=function(e,t,n){return eJ||e2({}),ta(eQ(e),eQ(t),n)},i.addHook=function(e,t){"function"==typeof t&&(ea[e]=ea[e]||[],h(ea[e],t))},i.removeHook=function(e){if(ea[e])return d(ea[e])},i.removeHooks=function(e){ea[e]&&(ea[e]=[])},i.removeAllHooks=function(){ea={}},i}()}()},function(e,t){e.exports=kQ},function(e,t,n){n.r(t);var r=n(1),i=n.n(r),o=n(0),a=n.n(o);function l(e){return(l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function s(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function u(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?s(Object(n),!0).forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):s(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function c(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function d(e,t){return(d=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function h(e){return(h=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var f=i.a.import("modules/clipboard"),p=i.a.import("delta"),g=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&d(e,t)}(s,e);var t,n,r,o=(t=function(){if("undefined"==typeof Reflect||!Reflect.construct||Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}(),function(){var e,n=h(s);return e=t?Reflect.construct(n,arguments,h(this).constructor):n.apply(this,arguments),e&&("object"===l(e)||"function"==typeof e)?e:function(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this)});function s(e,t){var n;return function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,s),(n=o.call(this,e,t)).allowed=t.allowed,n.keepSelection=t.keepSelection,n.substituteBlockElements=t.substituteBlockElements,n.magicPasteLinks=t.magicPasteLinks,n.hooks=t.hooks,n}return n=[{key:"onPaste",value:function(e){var t,n,r,o,l,s,u,c,d,h=this;e.preventDefault();var f,g,m,v,y,b=this.quill.getSelection();e.clipboardData&&e.clipboardData.getData||!window.clipboardData||!window.clipboardData.getData?(f=e.clipboardData.getData("text/plain"),g=e.clipboardData.getData("text/html"),m=null===(v=e.clipboardData)||void 0===v||null===(y=v.items)||void 0===y?void 0:y[0]):f=window.clipboardData.getData("Text");var w=(new p).retain(b.index).delete(b.length),x=this.getDOMPurifyOptions(),_=!1,E=f;if(!g&&x.ALLOWED_TAGS.includes("a")&&this.isURL(f)&&b.length>0&&this.magicPasteLinks)E=this.quill.getText(b.index,b.length),w=w.insert(E,{link:f});else if(!g&&x.ALLOWED_TAGS.includes("img")&&m&&"file"===m.kind&&m.type.match(/^image\//i)){var S=m.getAsFile(),C=new FileReader;C.onload=function(e){h.quill.insertEmbed(b.index,"image",e.target.result),h.keepSelection||h.quill.setSelection(b.index+1)},C.readAsDataURL(S)}else g||(_=!0,g=E),"function"==typeof(null===(t=this.hooks)||void 0===t?void 0:t.beforeSanitizeElements)&&a.a.addHook("beforeSanitizeElements",this.hooks.beforeSanitizeElements),"function"==typeof(null===(n=this.hooks)||void 0===n?void 0:n.uponSanitizeElement)&&a.a.addHook("uponSanitizeElement",this.hooks.uponSanitizeElement),"function"==typeof(null===(r=this.hooks)||void 0===r?void 0:r.afterSanitizeElements)&&a.a.addHook("afterSanitizeElements",this.hooks.afterSanitizeElements),"function"==typeof(null===(o=this.hooks)||void 0===o?void 0:o.beforeSanitizeAttributes)&&a.a.addHook("beforeSanitizeAttributes",this.hooks.beforeSanitizeAttributes),"function"==typeof(null===(l=this.hooks)||void 0===l?void 0:l.uponSanitizeAttribute)&&a.a.addHook("uponSanitizeAttribute",this.hooks.uponSanitizeAttribute),"function"==typeof(null===(s=this.hooks)||void 0===s?void 0:s.afterSanitizeAttributes)&&a.a.addHook("afterSanitizeAttributes",this.hooks.afterSanitizeAttributes),"function"==typeof(null===(u=this.hooks)||void 0===u?void 0:u.beforeSanitizeShadowDOM)&&a.a.addHook("beforeSanitizeShadowDOM",this.hooks.beforeSanitizeShadowDOM),"function"==typeof(null===(c=this.hooks)||void 0===c?void 0:c.uponSanitizeShadowNode)&&a.a.addHook("uponSanitizeShadowNode",this.hooks.uponSanitizeShadowNode),"function"==typeof(null===(d=this.hooks)||void 0===d?void 0:d.afterSanitizeShadowDOM)&&a.a.addHook("afterSanitizeShadowDOM",this.hooks.afterSanitizeShadowDOM),_?(E=a.a.sanitize(g,x),w=w.insert(E)):(E=!1!==this.substituteBlockElements?(g=this.substitute(g,x)).innerHTML:a.a.sanitize(g,x),w=w.concat(this.convert(E)));this.quill.updateContents(w,i.a.sources.USER),_||(w=this.convert(E)),this.keepSelection?this.quill.setSelection(b.index,w.length(),i.a.sources.SILENT):this.quill.setSelection(b.index+w.length(),i.a.sources.SILENT),this.quill.scrollIntoView(),a.a.removeAllHooks()}},{key:"getDOMPurifyOptions",value:function(){var e,t,n={};if(null!==(e=this.allowed)&&void 0!==e&&e.tags&&(n.ALLOWED_TAGS=this.allowed.tags),null!==(t=this.allowed)&&void 0!==t&&t.attributes&&(n.ALLOWED_ATTR=this.allowed.attributes),void 0===n.ALLOWED_TAGS||void 0===n.ALLOWED_ATTR){var r,i=!1;void 0===n.ALLOWED_TAGS&&(i=!0,n.ALLOWED_TAGS=["p","br","span"]);var o=!1;void 0===n.ALLOWED_ATTR&&(o=!0,n.ALLOWED_ATTR=["class"]);var a=this.quill.getModule("toolbar");null==a||null===(r=a.controls)||void 0===r||r.forEach(function(e){switch(e[0]){case"bold":i&&(n.ALLOWED_TAGS.push("b"),n.ALLOWED_TAGS.push("strong"));break;case"italic":i&&(n.ALLOWED_TAGS.push("i"),n.ALLOWED_TAGS.push("em"));break;case"underline":i&&n.ALLOWED_TAGS.push("u");break;case"strike":i&&n.ALLOWED_TAGS.push("s");break;case"color":case"background":o&&n.ALLOWED_ATTR.push("style");break;case"script":i&&("super"===e[1].value?n.ALLOWED_TAGS.push("sup"):"sub"===e[1].value&&n.ALLOWED_TAGS.push("sub"));break;case"header":if(i){var t=function(e){"1"===e?n.ALLOWED_TAGS.push("h1"):"2"===e?n.ALLOWED_TAGS.push("h2"):"3"===e?n.ALLOWED_TAGS.push("h3"):"4"===e?n.ALLOWED_TAGS.push("h4"):"5"===e?n.ALLOWED_TAGS.push("h5"):"6"===e&&n.ALLOWED_TAGS.push("h6")};e[1].value?t(e[1].value):e[1].options&&e[1].options.length&&[].forEach.call(e[1].options,function(e){e.value&&t(e.value)})}break;case"code-block":i&&n.ALLOWED_TAGS.push("pre"),o&&n.ALLOWED_ATTR.push("spellcheck");break;case"list":i&&("ordered"===e[1].value?n.ALLOWED_TAGS.push("ol"):"bullet"===e[1].value&&n.ALLOWED_TAGS.push("ul"),n.ALLOWED_TAGS.push("li"));break;case"link":i&&n.ALLOWED_TAGS.push("a"),o&&(n.ALLOWED_ATTR.push("href"),n.ALLOWED_ATTR.push("target"),n.ALLOWED_ATTR.push("rel"));break;case"image":i&&n.ALLOWED_TAGS.push("img"),o&&(n.ALLOWED_ATTR.push("src"),n.ALLOWED_ATTR.push("title"),n.ALLOWED_ATTR.push("alt"));break;case"video":i&&n.ALLOWED_TAGS.push("iframe"),o&&(n.ALLOWED_ATTR.push("frameborder"),n.ALLOWED_ATTR.push("allowfullscreen"),n.ALLOWED_ATTR.push("src"));break;case"blockquote":i&&n.ALLOWED_TAGS.push(e[0])}})}return n}},{key:"substitute",value:function(e,t){var n,r=["h1","h2","h3","h4","h5","h6"],i=["p","div","section","article","fieldset","address","aside","blockquote","canvas","dl","figcaption","figure","footer","form","header","main","nav","noscript","ol","pre","table","tfoot","ul","video"],o=["li","dt","dd","hr"];a.a.addHook("uponSanitizeElement",function(e,a,l){for(var s=0;!n&&s<3;)t.ALLOWED_TAGS.includes(i[s])&&(n=i[s]),++s;if(n&&e.tagName&&!t.ALLOWED_TAGS.includes(e.tagName.toLowerCase())){var u=e.tagName.toLowerCase();r.includes(u)?e.innerHTML="<".concat(n,"><b>").concat(e.innerHTML,"</b></").concat(n,">"):i.includes(u)?e.innerHTML="<".concat(n,">").concat(e.innerHTML,"</").concat(n,">"):o.includes(u)&&(e.innerHTML="".concat(e.innerHTML,"<br>"))}}),e=a.a.sanitize(e,u(u({},t),{RETURN_DOM:!0,WHOLE_DOCUMENT:!1})),a.a.removeAllHooks();var l,s=function(e){var t=document.createElement(e.tagName.toLowerCase()),n=e.attributes;return n.length&&Array.from(n).forEach(function(e){return t.setAttribute(e.nodeName,e.value)}),t},c=0,d=document.createElement("body");return function e(t,n){for(n(t,c),t=c<=1?t.firstChild:void 0;t;)++c,e(t,n),t=t.nextSibling;--c}(e,function(e,t){if(1===t){if(e.tagName&&i.includes(e.tagName.toLowerCase())){l&&(l=void 0);var r=s(e);r.innerHTML=e.innerHTML,d.appendChild(r)}else if(void 0===l&&(l=document.createElement(n),d.appendChild(l)),e.tagName){var o=s(e);e.innerHTML&&(o.innerHTML=e.innerHTML),l.appendChild(o)}else{var a=document.createTextNode(e.textContent);l.appendChild(a)}}}),d}},{key:"isURL",value:function(e){return!!/^(?:(?:http[s\u017F]?|ftp):\/\/)(?:(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+(?::(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?@)?(?:(?!10(?:\.[0-9]{1,3}){3})(?!127(?:\.[0-9]{1,3}){3})(?!169\.254(?:\.[0-9]{1,3}){2})(?!192\.168(?:\.[0-9]{1,3}){2})(?!172\.(?:1[6-9]|2[0-9]|3[01])(?:\.[0-9]{1,3}){2})(?:[1-9][0-9]?|1[0-9][0-9]|2[01][0-9]|22[0-3])(?:\.(?:1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])){2}(?:\.(?:[1-9][0-9]?|1[0-9][0-9]|2[0-4][0-9]|25[0-4]))|(?:(?:(?:[0-9KSa-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+\x2D?)*(?:[0-9KSa-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)(?:\.(?:(?:[0-9KSa-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+\x2D?)*(?:[0-9KSa-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)*(?:\.(?:(?:[KSa-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]){2,})))(?::[0-9]{2,5})?(?:\/(?:(?![\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])[\s\S])*)?$/i.test(e)}}],c(s.prototype,n),r&&c(s,r),s}(f);i.a.register("modules/clipboard",g,!0),t.default=g}]);var b=f("2SBKn"),og={};k5=og,k6=function(e,t,n,r){var i,o,a,l,s,u,c,d,h,f,p,g,m,v,y,b,w,x,_,E,S,C,O,k,P,T,A,N,j,R,L,I,M,D,F,z,B,U,H,V,q,G,W,$,K,Y,X,Z,Q,J,ee,et,en=(o=[],(i={}).joinUrl=function(t,n){return t?e.resolve(t,n):n},i.getConstantUniqueIdFor=function(e){return 0>o.indexOf(e)&&o.push(e),o.indexOf(e)},i.clone=function(e){var t,n={};for(t in e)e.hasOwnProperty(t)&&(n[t]=e[t]);return n},a=function(e){return"object"==typeof e&&null!==e&&Object.prototype.toString.apply(e).match(/\[object (Canvas|HTMLCanvasElement)\]/i)},i.parseOptionalParameters=function(e){var t={canvas:null,options:{}};return null==e[0]||a(e[0])?(t.canvas=e[0]||null,t.options=i.clone(e[1])):t.options=i.clone(e[0]),t},i),er=(l={},s=function(e,t,n){var r=e[t];return e[t]=function(){var e=Array.prototype.slice.call(arguments);return n.apply(this,[e,r])},r},l.baseUrlRespectingXhr=function(e,t){return function(){var n=new e;return s(n,"open",function(e,n){var r=e.shift(),i=e.shift(),o=en.joinUrl(t,i);return n.apply(this,[r,o].concat(e))}),n}},l.finishNotifyingXhr=function(e){var t,n=0,r=0,i=!1,o=new Promise(function(e){t=function(){n-r<=0&&i&&e({totalCount:n})}}),a=function(){var i=new e;return s(i,"send",function(e,t){return n+=1,t.apply(this,arguments)}),i.addEventListener("load",function(){r+=1,t()}),i};return a.waitForRequestsToFinish=function(){return i=!0,t(),o},a},l),ei=(u={},c=function(e){return Array.prototype.slice.call(e)},u.addClassName=function(e,t){e.className+=" "+t},u.addClassNameRecursively=function(e,t){u.addClassName(e,t),e.parentNode!==e.ownerDocument&&u.addClassNameRecursively(e.parentNode,t)},d=function(e,t){var n=e.parentStyleSheet,r=c(n.cssRules).indexOf(e);n.insertRule(t,r+1),n.deleteRule(r)},h=function(e,t){var n=e.cssText.replace(/^[^\{]+/,"");d(e,t+" "+n)},f=function(e){e.textContent=c(e.sheet.cssRules).reduce(function(e,t){return e+t.cssText},"")},p=function(e){var t=document.implementation.createHTMLDocument(""),n=document.createElement("style");n.textContent=e.textContent,t.body.appendChild(n),e.sheet=n.sheet},g=function(e,t,n){var r="((?:^|[^.#:\\w])|(?=\\W))("+t.join("|")+")(?=\\W|$)";c(e.querySelectorAll("style")).forEach(function(e){void 0===e.sheet&&p(e);var t=c(e.sheet.cssRules).filter(function(e){return e.selectorText&&RegExp(r,"i").test(e.selectorText)});t.length&&(t.forEach(function(e){var t=e.selectorText.replace(RegExp(r,"gi"),function(e,t,r){return t+n(r)});t!==e.selectorText&&h(e,t)}),f(e))})},u.rewriteCssSelectorWith=function(e,t,n){g(e,[t],function(){return n})},u.lowercaseCssTypeSelectors=function(e,t){g(e,t,function(e){return e.toLowerCase()})},u.findHtmlOnlyNodeNames=function(e){var t,n=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_ELEMENT),r={},i={};do t=n.currentNode.tagName.toLowerCase(),"http://www.w3.org/1999/xhtml"===n.currentNode.namespaceURI?r[t]=!0:i[t]=!0;while(n.nextNode())return Object.keys(r).filter(function(e){return!i[e]})},m={},v=function(e){return Array.prototype.slice.call(e)},y={active:!0,hover:!0,focus:!1,target:!1},m.fakeUserAction=function(e,t,n){var r=e.querySelector(t),i="rasterizehtml"+n;r&&(y[n]?u.addClassNameRecursively(r,i):u.addClassName(r,i),u.rewriteCssSelectorWith(e,":"+n,"."+i))},m.persistInputValues=function(e){var t=e.querySelectorAll("input"),n=e.querySelectorAll("textarea"),r=function(e){return"checkbox"===e.type||"radio"===e.type};v(t).filter(r).forEach(function(e){e.checked?e.setAttribute("checked",""):e.removeAttribute("checked")}),v(t).filter(function(e){return!r(e)}).forEach(function(e){e.setAttribute("value",e.value)}),v(n).forEach(function(e){e.textContent=e.value})},m.rewriteTagNameSelectorsToLowerCase=function(e){u.lowercaseCssTypeSelectors(e,u.findHtmlOnlyNodeNames(e))},m),eo=(b=window,w={},x=function(e,t,n,r){var i=e.createElement(t);return i.style.visibility="hidden",i.style.width=n+"px",i.style.height=r+"px",i.style.position="absolute",i.style.top=-1e4-r+"px",i.style.left=-1e4-n+"px",e.getElementsByTagName("body")[0].appendChild(i),i},w.executeJavascript=function(e,t){return new Promise(function(n){var r=x(b.document,"iframe",t.width,t.height),i=e.outerHTML,o=[],a=t.executeJsTimeout||0,l=function(){b.document.getElementsByTagName("body")[0].removeChild(r)},s=function(){n({document:r.contentDocument,errors:o,cleanUp:l})},u=r.contentWindow.XMLHttpRequest,c=er.finishNotifyingXhr(u),d=er.baseUrlRespectingXhr(c,t.baseUrl);r.onload=function(){(a>0?new Promise(function(e){setTimeout(e,a)}):Promise.resolve()).then(c.waitForRequestsToFinish).then(s)},r.contentDocument.open(),r.contentWindow.XMLHttpRequest=d,r.contentWindow.onerror=function(e){o.push({resourceType:"scriptExecution",msg:e})},r.contentDocument.write("<!DOCTYPE html>"),r.contentDocument.write(i),r.contentDocument.close()})},_=function(e,t,n){var r=e.createElement("iframe");return r.style.width=t+"px",r.style.height=n+"px",r.style.visibility="hidden",r.style.position="absolute",r.style.top=-1e4-n+"px",r.style.left=-1e4-t+"px",r.style.borderWidth=0,r.sandbox="allow-same-origin",r.scrolling="no",r},E=function(e,t,n){var r=Math.floor(e/n),i=Math.floor(t/n);return _(b.document,r,i)},S=function(e,t){var n=e.querySelector(t);if(n)return n;if(e.ownerDocument.querySelector(t)===e)return e;throw{message:"Clipping selector not found"}},C=function(e,t,n,r,i){var o,a,l,s,u,c,d,h,f=Math.max(e.scrollWidth,e.clientWidth),p=Math.max(e.scrollHeight,e.clientHeight);return t?(a=(d=S(e,t).getBoundingClientRect()).top,l=d.left,s=d.width,u=d.height):(a=0,l=0,s=f,u=p),h={width:Math.max((o={width:s,height:u}).width*i,n),height:Math.max(o.height*i,r)},c=b.getComputedStyle(e.ownerDocument.documentElement).fontSize,{left:l,top:a,width:h.width,height:h.height,viewportWidth:f,viewportHeight:p,rootFontSize:c}},O=function(e,t){var n=e.tagName;return t.querySelector(n)},k=function(e){var t=e.tagName.toLowerCase();return"html"===t||"body"===t?e.outerHTML:'<body style="margin: 0;">'+e.outerHTML+"</body>"},w.calculateDocumentContentSize=function(e,t){return new Promise(function(n,r){var i,o=t.zoom||1;i=E(t.width,t.height,o),b.document.getElementsByTagName("body")[0].appendChild(i),i.onload=function(){var a,l=i.contentDocument;try{a=C(O(e,l),t.clip,t.width,t.height,o),n(a)}catch(e){r(e)}finally{b.document.getElementsByTagName("body")[0].removeChild(i)}},i.contentDocument.open(),i.contentDocument.write("<!DOCTYPE html>"),i.contentDocument.write(k(e)),i.contentDocument.close()})},w.parseHtmlFragment=function(e){var t=b.document.implementation.createHTMLDocument("");t.documentElement.innerHTML=e;var n=t.querySelector("body").firstChild;if(!n)throw"Invalid source";return n},P=function(e,t){var n,r,i,o,a=/<html((?:\s+[^>]*)?)>/im.exec(t),l=b.document.implementation.createHTMLDocument("");if(a)for(r=0,n="<div"+a[1]+"></div>",l.documentElement.innerHTML=n,i=l.querySelector("div");r<i.attributes.length;r++)o=i.attributes[r],e.documentElement.setAttribute(o.name,o.value)},w.parseHTML=function(e){var t=b.document.implementation.createHTMLDocument("");return t.documentElement.innerHTML=e,P(t,e),t},T=function(e){try{return n.failOnParseError(e)}catch(e){throw{message:"Invalid source",originalError:e}}},w.validateXHTML=function(e){T(new DOMParser().parseFromString(e,"application/xml"))},A=null,w.loadDocument=function(e,t){return new Promise(function(n,r){var i,o,a=new window.XMLHttpRequest,l=(i=en.joinUrl(t.baseUrl,e),"none"===(o=t.cache)||"repeated"===o?((null===A||"repeated"!==o)&&(A=Date.now()),i+"?_="+A):i),s=function(e){r({message:"Unable to load page",originalError:e})};a.addEventListener("load",function(){200===a.status||0===a.status?n(a.responseXML):s(a.statusText)},!1),a.addEventListener("error",function(e){s(e)},!1);try{a.open("GET",l,!0),a.responseType="document",a.send(null)}catch(e){s(e)}}).then(function(e){return T(e)})},w),ea=(N=window,R={},L=function(e,t){return t?URL.createObjectURL(new Blob([e],{type:"image/svg+xml"})):"data:image/svg+xml;charset=utf-8,"+encodeURIComponent(e)},I=function(e){e instanceof Blob&&URL.revokeObjectURL(e)},M='<svg xmlns="http://www.w3.org/2000/svg" width="1" height="1"><foreignObject></foreignObject></svg>',D=function(e){return new Promise(function(t,n){var r=document.createElement("canvas"),i=new Image;i.onload=function(){var e=r.getContext("2d");try{e.drawImage(i,0,0),r.toDataURL("image/png"),t(!0)}catch(e){t(!1)}},i.onerror=n,i.src=e})},F=function(){var e=L(M,!0);return D(e).then(function(t){return I(e),!t&&D(L(M,!1)).then(function(e){return e})},function(){return!1})},z=function(){if(N.Blob)try{return new Blob(["<b></b>"],{type:"text/xml"}),!0}catch(e){}return!1},R.renderSvg=function(e){return new Promise(function(t,n){var r,i,o=function(){i.onload=null,i.onerror=null},a=function(){r&&I(r)};(i=new Image).onload=function(){o(),a(),t(i)},i.onerror=function(){a(),n()},(void 0===j&&(j=new Promise(function(e,t){z()&&N.URL?F().then(function(t){e(!t)},function(){t()}):e(!1)})),j).then(function(t){return L(e,t)}).then(function(e){r=e,i.src=r},n)})},R),el=(B={},U=function(e,t){var n=t||1,r={width:e.width,height:e.height,"font-size":e.rootFontSize};return 1!==n&&(r.style="transform:scale("+n+"); transform-origin: 0 0;"),r},H=function(e){var t,n;return t=Math.round(e.viewportWidth),n=Math.round(e.viewportHeight),{x:-e.left,y:-e.top,width:t,height:n}},V=function(e){var t=e.style||"";e.style=t+"float: left;"},q=function(e){e.externalResourcesRequired=!0},G=function(e){var t=Object.keys(e);return t.length?" "+t.map(function(t){return t+'="'+e[t]+'"'}).join(" "):""},W=function(e,n,r){var i=t.serializeToString(e);eo.validateXHTML(i);var o=H(n);return V(o),q(o),'<svg xmlns="http://www.w3.org/2000/svg"'+G(U(n,r))+'><style scoped="">html::-webkit-scrollbar { display: none; }</style><foreignObject'+G(o)+">"+i+"</foreignObject></svg>"},B.getSvgForDocument=function(e,t,n){return ei.rewriteTagNameSelectorsToLowerCase(e),W(e,t,n)},B.drawDocumentAsSvg=function(e,t){return["hover","active","focus","target"].forEach(function(n){t[n]&&ei.fakeUserAction(e,t[n],n)}),eo.calculateDocumentContentSize(e,t).then(function(n){return B.getSvgForDocument(e,n,t.zoom)})},B),es=($={},K=function(e){return{message:"Error rendering page",originalError:e}},Y=function(e){return ea.renderSvg(e).then(function(t){return{image:t,svg:e}},function(e){throw K(e)})},X=function(e,t){try{t.getContext("2d").drawImage(e,0,0)}catch(e){throw K(e)}},$.rasterize=function(e,t,n){var i;return(i=en.clone(n)).inlineScripts=!0===n.executeJs,r.inlineReferences(e,i).then(function(t){return n.executeJs?eo.executeJavascript(e,n).then(function(e){var t=e.document;return ei.persistInputValues(t),{document:t,errors:e.errors,cleanUp:e.cleanUp}}).then(function(e){return{element:e.document.documentElement,errors:t.concat(e.errors),cleanUp:e.cleanUp}}):{element:e,errors:t,cleanUp:function(){}}}).then(function(e){var r;return(r=e.element,el.drawDocumentAsSvg(r,n).then(Y).then(function(e){return t&&X(e.image,t),e})).then(function(t){return e.cleanUp(),{image:t.image,svg:t.svg,errors:e.errors}})})},$);return Z={},Q=function(e,t){var n=e?e.width:300,r=e?e.height:200;return{width:void 0!==t.width?t.width:n,height:void 0!==t.height?t.height:r}},J=function(e){var t,n=Q(e.canvas,e.options);return(t=en.clone(e.options)).width=n.width,t.height=n.height,t},Z.drawDocument=function(){var e=arguments[0],t=Array.prototype.slice.call(arguments,1),n=en.parseOptionalParameters(t),r=e.documentElement?e.documentElement:e;return es.rasterize(r,n.canvas,J(n))},ee=function(e,t,n){var r=eo.parseHTML(e);return Z.drawDocument(r,t,n)},Z.drawHTML=function(){var e=arguments[0],t=Array.prototype.slice.call(arguments,1),n=en.parseOptionalParameters(t);return ee(e,n.canvas,n.options)},et=function(e,t,n){var r=document.implementation.createHTMLDocument("");r.replaceChild(e.documentElement,r.documentElement);var i=n?en.clone(n):{};return n.baseUrl||(i.baseUrl=t),{document:r,options:i}},Z.drawURL=function(){var e,t,n=arguments[0],r=Array.prototype.slice.call(arguments,1),i=en.parseOptionalParameters(r);return e=i.canvas,t=i.options,eo.loadDocument(n,t).then(function(r){var i=et(r,n,t);return Z.drawDocument(i.document,e,i.options)})},Z},void 0===k5&&void 0!==window&&(k5=window),"function"==typeof define&&define.amd?define(["url","xmlserializer","sane-domparser-error","inlineresources"],function(e,t,n,r){return k5.rasterizeHTML=k6(e,t,n,r)}):og?og=k6(f("kRFNf"),f("l4MZj"),f("lDFX4"),f("6cJtK")):k5.rasterizeHTML=k6(k5.url,k5.xmlserializer,k5.sanedomparsererror,k5.inlineresources);let om=`
43
43
  <style>
44
44
  html, body {
45
45
  padding: 0;
@@ -110,7 +110,7 @@ For more info see: https://github.com/konvajs/react-konva/issues/194
110
110
  `}(e,n):(console.error(`Polotno error: Can not convert ${e.subType} figure to svg.`),o8(e))}let at=e=>T(({element:t,fillProps:n,strokeProps:r})=>{let i=e({width:t.a.width,height:t.a.height,cornerRadius:t.cornerRadius}),o=1,a=1;"string"!=typeof i&&(o=i.scaleX,a=i.scaleY,i=i.path);let l=s(y).useRef(null);return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(rY,{width:t.width,height:t.height,fill:"transparent"}),(0,g.jsx)(rJ,{...n,ref:l,data:i,scaleX:o,scaleY:a}),(0,g.jsx)(r$,{clipFunc:e=>{let t=l.current;if(t){var n=t.dataArray;e.beginPath();for(var r=0;r<n.length;r++){var i=n[r].command,o=n[r].points;switch(i){case"L":e.lineTo(o[0],o[1]);break;case"M":e.moveTo(o[0],o[1]);break;case"C":e.bezierCurveTo(o[0],o[1],o[2],o[3],o[4],o[5]);break;case"Q":e.quadraticCurveTo(o[0],o[1],o[2],o[3]);break;case"A":var a=o[0],s=o[1],u=o[2],c=o[3],d=o[4],h=o[5],f=o[6],p=o[7],g=u>c?u:c,m=u>c?1:u/c,v=u>c?c/u:1;e.translate(a,s),e.rotate(f),e.scale(m,v),e.arc(0,0,g,d,d+h,1-p),e.scale(1/m,1/v),e.rotate(-f),e.translate(-a,-s);break;case"z":e.closePath()}}}},scaleX:o,scaleY:a,children:(0,g.jsx)(rJ,{...r,x:0,y:0,data:i,strokeWidth:2*r.strokeWidth,dash:r.dash.map(e=>e)})})]})}),an={},ar=e=>(an[e]||(an[e]=at(o7[e]||o8)),an[e]),ai={text:iX,image:of,svg:of,line:o$,video:o4,figure:T(({element:e,store:t})=>{let n=e.selectable||"admin"===t.role,r=iB(),[i,o]=s(y).useState(!1),a=t.selectedElements.indexOf(e)>=0&&1===t.selectedElements.length,l=Math.min(e.strokeWidth,e.width/2,e.height/2),u=Math.max(0,Math.min(e.width/2,e.height/2,e.cornerRadius)),c=iu(e,e.a.fill,"fill"),d={width:e.a.width,height:e.a.height,...c,cornerRadius:u,opacity:e.animated("opacity"),shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,listening:n,preventDefault:!r||a,hideInExport:!e.showInExport},h=iu(e,e.stroke,"stroke"),f={visible:l>0,x:l/2,y:l/2,width:e.a.width-l,height:e.a.height-l,...h,strokeWidth:l,cornerRadius:Math.max(0,u-l),dash:e.dash.map(e=>e*l),opacity:e.animated("opacity"),hideInExport:!e.showInExport,listening:!1},p=ar(e.subType)||r$;return(0,g.jsxs)(s(y).Fragment,{children:[(0,g.jsx)(r$,{id:e.id,x:e.a.x,y:e.a.y,rotation:e.a.rotation,opacity:e.a.opacity,draggable:r?e.draggable&&a:e.draggable,name:"element",onMouseEnter:()=>{o(!0)},onMouseLeave:()=>{o(!1)},onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},onTransform:t=>{let n=t.target.scale();t.target.scaleX(1),t.target.scaleY(1),e.set({width:e.width*n.x,height:e.height*n.y,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation()})},children:(0,g.jsx)(p,{element:e,fillProps:d,strokeProps:f})}),i&&!a&&(0,g.jsx)(iD,{element:e})]})}),group:T(e=>{let{element:t,store:n}=e,{children:r}=t,i=t.selectable||"admin"===n.role;return(0,g.jsx)(r$,{opacity:t.opacity,listening:i,hideInExport:!t.showInExport,children:r.map(t=>(0,y.createElement)(ao,{...e,key:t.id,store:n,element:t}))})})},ao=T(e=>{let t=ai[e.element.type];return("text"===e.element.type&&iN.htmlRenderEnabled&&(t=oD),e.element.visible)?t?(0,g.jsx)(t,{...e}):(console.error("Can not find component for "+e.element.type),null):null});var b=f("2SBKn");let aa="https://api.polotno.com/api",al=(e,t,n)=>e.replace(RegExp(t,"g"),n),as=({query:e,page:t=1})=>`${aa}/get-unsplash?query=${e}&per_page=20&page=${t}&KEY=${ax()}`,au=e=>`${aa}/download-unsplash?id=${e}&KEY=${ax()}`,ac=({query:e,page:t=1,sizeQuery:n})=>`${aa}/get-templates?${n}&query=${e}&per_page=30&page=${t}&KEY=${ax()}`,ad=()=>`${aa}/get-google-fonts?KEY=${ax()}`,ah=e=>`https://api.polotno.com/google-fonts-previews/black/${al(e," ","-")}.png`,af=()=>`${aa}/remove-image-background?KEY=${ax()}`,ap=e=>ac(e),ag=()=>`${aa}/get-text-templates?KEY=${ax()}`,am=e=>as(e),av=e=>au(e),ay=b.observable({value:!1}),ab=b.action(()=>{ay.value=!0}),aw="",ax=()=>aw||"",a_=window.location.origin,aE=navigator.userAgent.indexOf("Headless")>-1,aS=navigator.userAgent.indexOf("Electron")>-1;"file://"===a_&&aE&&(a_="headless"),"file://"===a_&&aS&&(a_="electron");let aC=`%cPolotno error! Current domain is not allowed. It may lead to unexpected behavior and stop working. Please add "${a_}" here: https://polotno.com/cabinet`;async function aO(e){for(let t=0;t<5;t++)try{let t=await fetch(aa+"/validate-key",{method:"POST",body:JSON.stringify({key:e,site:location.host})});if(!e)return console.warn("Polotno API is initialized without API key. It may lead to unexpected behavior and stop working. Please create API key here: https://polotno.com/cabinet"),!1;if(200!==t.status){await new Promise(e=>setTimeout(e,3e3));continue}let n=await t.json();return n.is_valid||console.warn("Polotno API key is not valid. Please get new API key here: https://polotno.com/cabinet"),n.is_paid||console.log("%cPolotno Free Version. Development or non-commercial usage only. https://polotno.com/","background: rgb(0, 161, 255); color: white; padding: 5px; margin: 5px;"),n.is_domain_valid||console.log(aC,"background: rgba(247, 101, 68, 1); color: white; padding: 5px; margin: 5px;"),ij(n.remove_background_enabled),n.is_paid||!1}catch(e){await new Promise(e=>setTimeout(e,3e3))}return console.error("Can not validate Polotno API key. Please report to anton@polotno.com immediately."),!0}async function ak(e,t){aw=e,(!await aO(e)||t)&&ab()}let aP=({px:e,unit:t="px",dpi:n})=>{switch(t){case"pt":default:return e;case"mm":return e/(n/25.4);case"cm":return e/(n/2.54);case"in":return e/n}},aT=({px:e,precious:t=2,dpi:n=72,unit:r="px"})=>parseFloat(aP({px:e,dpi:n,unit:r}).toFixed(t)),aA=({unitVal:e,dpi:t,unit:n})=>e/aP({px:1,unit:n,dpi:t}),aN=e=>{let t=parseFloat(aP(e).toFixed(1));switch(e.unit){case"pt":return`${Math.round(t)}pt`;case"mm":return`${t}mm`;case"cm":return`${t}cm`;case"in":return`${t}in`;default:return`${Math.round(t)}px`}},aj=s(N).DD._drag;window.removeEventListener("mousemove",aj),s(N).DD._drag=function(e){(0,b.runInAction)(()=>{aj.call(this,e)})},window.addEventListener("mousemove",s(N).DD._drag);let aR=new(s(N)).Group;aR.add(new(s(N)).Rect({width:20,height:20,fill:"white"})),aR.add(new(s(N)).Path({scaleX:20/24,scaleY:20/24,data:"M4.98313549,11.0001422 C5.49589839,10.9914935 5.92501998,11.3703506 5.99116425,11.8666444 L5.99985778,11.9831355 L6.00348884,12.2068855 C6.11245031,15.4321748 8.76323537,17.9999971 11.9999971,17.9999971 C12.1869612,17.9999971 12.3726725,17.9914753 12.5567465,17.9745765 L12.2928932,17.7071068 C11.9023689,17.3165825 11.9023689,16.6834175 12.2928932,16.2928932 C12.6834175,15.9023689 13.3165825,15.9023689 13.7071068,16.2928932 L15.7071068,18.2928932 C16.0976311,18.6834175 16.0976311,19.3165825 15.7071068,19.7071068 L13.7071068,21.7071068 C13.3165825,22.0976311 12.6834175,22.0976311 12.2928932,21.7071068 C11.9023689,21.3165825 11.9023689,20.6834175 12.2928932,20.2928932 L12.6111505,19.9769552 C12.4086045,19.9922816 12.2047796,19.9999971 11.9999971,19.9999971 C7.7687005,19.9999971 4.28886152,16.7094374 4.01666425,12.5105203 L4.00420123,12.2575143 L4.00014222,12.0168645 C3.9908282,11.4646583 4.43092928,11.0094562 4.98313549,11.0001422 Z M11.7071068,2.29289322 C12.0675907,2.65337718 12.0953203,3.22060824 11.7902954,3.61289944 L11.7071068,3.70710678 L11.3891629,4.0230186 C11.5916051,4.00770767 11.7953244,4 12,4 C16.418278,4 20,7.581722 20,12 C20,12.5522847 19.5522847,13 19,13 C18.4477153,13 18,12.5522847 18,12 C18,8.6862915 15.3137085,6 12,6 C11.8129339,6 11.6271216,6.00853145 11.4429483,6.02544919 L11.7071068,6.29289322 C12.0976311,6.68341751 12.0976311,7.31658249 11.7071068,7.70710678 C11.3466228,8.06759074 10.7793918,8.09532028 10.3871006,7.79029539 L10.2928932,7.70710678 L8.29289322,5.70710678 C7.93240926,5.34662282 7.90467972,4.77939176 8.20970461,4.38710056 L8.29289322,4.29289322 L10.2928932,2.29289322 C10.6834175,1.90236893 11.3165825,1.90236893 11.7071068,2.29289322 Z",fill:"black"}));let aL=aR.toCanvas({pixelRatio:2,width:20,height:20}),aI={enabledAnchors:["top-left","top-center","top-right","middle-left","bottom-left","bottom-right","bottom-center","middle-right"],borderEnabled:!0,rotateEnabled:!0,rotationSnaps:[0,45,90,135,180,225,270,315],ignoreStroke:!0,flipEnabled:!1,anchorStrokeWidth:2,borderStrokeWidth:2,rotateAnchorOffset:30,anchorStyleFunc:e=>{e.hasName("rotater")&&e.setAttrs({width:20,height:20,cornerRadius:10,offsetX:10,offsetY:10,fillPatternImage:aL,fillPatternScaleX:.5,fillPatternScaleY:.5,fillPriority:"pattern",fillPatternRepeat:"no-repeat"})}},aM={text:{enabledAnchors:["top-left","top-right","middle-left","bottom-left","bottom-right","middle-right"]},svg:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},line:{enabledAnchors:[],borderEnabled:!1,rotateEnabled:!1},image:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},many:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},group:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]}},aD=e=>(0,g.jsx)(rY,{...e,preventDefault:!1}),aF=({url:e,...t})=>{let[n,r]=s(r3)(e,"anonymous"),i=n?function(e,t,n="scale"){let r,i;let o=t.width/t.height;o>=e.width/e.height?(r=e.width,i=e.width/o):(r=e.height*o,i=e.height);let a=0,l=0;return"left-top"===n?(a=0,l=0):"left-middle"===n?(a=0,l=(e.height-i)/2):"left-bottom"===n?(a=0,l=e.height-i):"center-top"===n?(a=(e.width-r)/2,l=0):"center-middle"===n?(a=(e.width-r)/2,l=(e.height-i)/2):"center-bottom"===n?(a=(e.width-r)/2,l=e.height-i):"right-top"===n?(a=e.width-r,l=0):"right-middle"===n?(a=e.width-r,l=(e.height-i)/2):"right-bottom"===n?(a=e.width-r,l=e.height-i):"scale"===n?(a=0,l=0,r=e.width,i=e.height):console.error(Error("Unknown clip position property - "+n)),{cropX:a,cropY:l,cropWidth:r,cropHeight:i}}(n,{width:t.width,height:t.height},"center-middle"):{};return oc(r,"background"),(0,g.jsx)(rZ,{image:n,...t,...i})},az=e=>(0,g.jsx)(rY,{...e}),aB=e=>{let{background:t,scale:n,borderColor:r,...i}=e,o=s(y).useMemo(()=>!!s(N).Util.colorToRGBA(t),[t]),a=s(y).useMemo(()=>{let e=document.createElement("canvas");e.width=60,e.height=60;let t=e.getContext("2d");return t&&(t.fillStyle="black",t.fillRect(30,0,30,30),t.fillRect(0,30,30,30)),e},[]);return(0,g.jsxs)(s(y).Fragment,{children:[(0,g.jsx)(rY,{fillPatternImage:a,...i,opacity:.1,hideInExport:!0}),o?(0,g.jsx)(az,{fill:t,...i}):(0,g.jsx)(aF,{url:t,...i})]})},aU=T(({selection:e})=>e.visible?(0,g.jsx)(rY,{name:"selection",x:Math.min(e.x1,e.x2),y:Math.min(e.y1,e.y2),width:Math.abs(e.x1-e.x2),height:Math.abs(e.y1-e.y2),fill:"rgba(0, 161, 255, 0.3)"}):null),aH=T(({x:e,y:t,width:n,height:r,rotation:i,anchor:o,store:a})=>{let l=oz({x:e,y:t,width:n,height:r,rotation:s(N).Util.radToDeg(i)});if(void 0===o)return null;let u=(r/2+70)*Math.cos(i-Math.PI/2),c=(r/2+70)*Math.sin(i-Math.PI/2),d=aT({unit:a.unit,dpi:a.dpi,px:n/a.scale,precious:"px"===a.unit?0:1})+" x "+aT({unit:a.unit,dpi:a.dpi,px:r/a.scale,precious:"px"===a.unit?0:1})+("px"===a.unit?"":" "+a.unit);return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(rK,{x:(l.minX+l.maxX)/2+u,y:(l.minY+l.maxY)/2+c,offsetX:14,offsetY:14,visible:"rotater"===o,children:[(0,g.jsx)("Tag",{cornerRadius:5,fill:"rgb(0, 161, 255)"}),(0,g.jsx)(rQ,{align:"center",verticalAlign:"middle",fill:"white",padding:8,text:Math.round(s(N).Util.radToDeg(i)).toString()+"°"})]}),(0,g.jsxs)(rK,{x:(l.minX+l.maxX)/2,y:l.maxY+20,visible:"rotater"!==o,children:[(0,g.jsx)("Tag",{cornerRadius:5,fill:"rgb(0, 161, 255)",pointerDirection:"up",pointerHeight:0,pointerWidth:0}),(0,g.jsx)(rQ,{align:"center",verticalAlign:"middle",fill:"white",padding:8,text:d})]})]})}),aV=T(({elements:e,store:t})=>{let n=e.filter(e=>e.alwaysOnTop),r=e.filter(e=>!e.alwaysOnTop).concat(n);return(0,g.jsx)(s(y).Fragment,{children:r.map(e=>(0,g.jsx)(ao,{store:t,element:e,onClick:()=>{console.warn("Polotno warning: onClick callback is deprecated. Just stop using it. Polotno will do selection automatically.")}},e.id))})}),aq=null,aG=e=>{aq=e};var aW=T(({store:e,page:t,width:n,height:r,pageControlsEnabled:i,backColor:o,pageBorderColor:a,activePageBorderColor:l,components:u,bleedColor:c,altCloneEnabled:d})=>{var h;let f=e.bleedVisible?t.bleed:0,p=t.computedWidth+2*f,m=t.computedHeight+2*f,v=(n-p*e.scale)/2,w=(r-m*e.scale)/2,x=s(y).useRef(null),_=s(y).useRef(null),E=s(y).useRef(null),[S,C]=s(y).useState(null),[O,k]=s(y).useState({}),P=e.selectedElements.find(e=>e._cropModeEnabled),T=e.selectedShapes.filter(e=>!e.resizable).length>0,A=e.selectedShapes.filter(e=>!e.draggable).length>0,j=e.selectedElements.filter(e=>!e.visible).length>0;s(y).useLayoutEffect(()=>{if(!x.current)return;let t=x.current.getStage(),n=e.selectedShapes.map(e=>e._cropModeEnabled?null:t.findOne("#"+e.id)).filter(e=>e),r=1===e.selectedElements.length&&e.selectedElements[0]?.type||"many";aM[r]?(x.current.setAttrs({...aI,...aM[r]}),"svg"!==r&&"image"!==r||e.selectedElements[0].keepRatio||x.current.setAttrs({enabledAnchors:aI.enabledAnchors}),"text"===r&&iN.textVerticalResizeEnabled&&x.current.setAttrs({enabledAnchors:aM.text.enabledAnchors?.concat(["bottom-center"])})):x.current.setAttrs(aI),T&&x.current.enabledAnchors([]),A&&x.current.rotateEnabled(!1),n.find(e=>e?.isDragging())&&n.forEach(e=>{e.isDragging()||e?.startDrag()}),x.current.nodes(n),x.current.getLayer()?.batchDraw()},[e.selectedElements,P,T,j,A]);let R=(h=()=>({visible:!1,x1:0,y1:0,x2:0,y2:0}),(0,y.useState)(function(){return(0,b.observable)(h(),void 0,{autoBind:!0})})[0]),L=s(y).useRef(!1),I=iB(),M=(0,b.action)(e=>{if(I)return;L.current=!1;let t=e.target.findAncestor(".elements-container"),n=e.target.findAncestor("Transformer"),r=e.target.findAncestor(".page-abs-container");if(t||n||r)return;let i=e.target.getStage()?.getPointerPosition();i&&(R.visible=!0,R.x1=i.x,R.y1=i.y,R.x2=i.x,R.y2=i.y,e.target.getStage()?.getPointersPositions().length>=2&&(R.visible=!1))});s(y).useEffect(()=>{let t=(0,b.action)(e=>{if(!R.visible)return;_.current?.setPointersPositions(e);let t=_.current?.getPointerPosition()||{x:R.x2,y:R.y2};R.x2=t.x,R.y2=t.y}),n=(0,b.action)(()=>{if(!R.visible||!_.current)return;let t=_.current.findOne(".selection"),n=t?t.getClientRect():{width:0,height:0,x:0,y:0};if(n.width&&n.height){let t=[];_.current.find(".element").forEach(r=>{let i=r.getClientRect(),o=e.getElementById(r.id()),a=o?.draggable,l=o?.selectable;s(N).Util.haveIntersection(n,i)&&a&&l&&t.push(o.top.id)});let r=[...new Set(t)];e.selectElements(r)}R.visible=!1,L.current=!0});return window.addEventListener("mousemove",t),window.addEventListener("touchmove",t),window.addEventListener("mouseup",n),window.addEventListener("touchend",n),()=>{window.removeEventListener("mousemove",t),window.removeEventListener("touchmove",t),window.removeEventListener("mouseup",n),window.removeEventListener("touchend",n)}},[]);let D=n=>{if(e.activePage!==t&&t.select(),L.current)return;let r=n.evt.ctrlKey||n.evt.metaKey||n.evt.shiftKey,i=n.target.findAncestor(".elements-container"),o=n.target.findAncestor(".page-abs-container"),a=n.target.findAncestor("Transformer");if(!r&&!i&&!a&&!o){e.selectElements([]);return}let l=n.target.findAncestor(".element",!0),s=e.getElementById(l?.id()),u=s?.top,c=u?.id,d=e.selectedElementsIds.indexOf(c)>=0;c&&r&&!d?e.selectElements(e.selectedElementsIds.concat([c])):c&&r&&d?e.selectElements(e.selectedElementsIds.filter(e=>e!==c)):!c||r||d||e.selectElements([c])};!function(e){let t=e=>e.hasName("element")||e.hasName("page-background")||e.hasName("elements-area");function n(n){let r=e.current?.getStage();var i=[],o=[];return r.find(t).forEach(e=>{if(!(n.indexOf(e)>=0)){var t=e.getClientRect({skipShadow:!0,skipStroke:!0});i.push(t.x,t.x+t.width,t.x+t.width/2),o.push(t.y,t.y+t.height,t.y+t.height/2)}}),{vertical:i,horizontal:o}}function r(t){let n=e.current?.getLayer(),r=n?.children.find(e=>"line-guides"===e.name());t.forEach(e=>{if("H"===e.orientation){var t=new(s(N)).Line({points:[-6e3,e.lineGuide,6e3,e.lineGuide],stroke:"rgb(0, 161, 255)",strokeWidth:1,name:"guid-line",dash:[4,6]});r?.add(t),n.batchDraw()}else if("V"===e.orientation){var t=new(s(N)).Line({points:[e.lineGuide,-6e3,e.lineGuide,6e3],stroke:"rgb(0, 161, 255)",strokeWidth:1,name:"guid-line",dash:[4,6]});r?.add(t)}})}let i=e=>{e.target.getLayer().children.find(e=>"line-guides"===e.name()).destroyChildren();var t=oU(n(e.target.nodes()),function(e){let t=e.__getNodeRect(),n=oz({...t,rotation:s(N).Util.radToDeg(t.rotation)}),r=e.getAbsolutePosition();return{vertical:[{guide:n.x,offset:r.x-n.x,snap:"start"},{guide:n.x+n.width/2,offset:r.x-n.x-n.width/2,snap:"center"},{guide:n.x+n.width,offset:r.x-n.x-n.width,snap:"end"}],horizontal:[{guide:n.y,offset:r.y-n.y,snap:"start"},{guide:n.y+n.height/2,offset:r.y-n.y-n.height/2,snap:"center"},{guide:n.y+n.height,offset:r.y-n.y-n.height,snap:"end"}]}}(e.target));if(!t.length)return;r(t);let i=e.target.getAbsolutePosition(),o={...i};t.forEach(e=>{switch(e.snap){case"start":case"center":case"end":switch(e.orientation){case"V":o.x=e.lineGuide+e.offset;break;case"H":o.y=e.lineGuide+e.offset}}});let a=o.x-i.x,l=o.y-i.y;e.evt.ctrlKey||e.evt.metaKey||e.target.nodes().forEach(e=>{let t=e.getAbsolutePosition();e.setAbsolutePosition({x:t.x+a,y:t.y+l})})},o=(t,i,o)=>{let a=e.current,l=a.getLayer();if(l.children.find(e=>"line-guides"===e.name()).destroyChildren(),"rotater"===a.getActiveAnchor()||Math.sqrt(Math.pow(i.x-t.x,2)+Math.pow(i.y-t.y,2))>50||!l)return i;var s=oU(n(a.nodes()),{vertical:[{guide:i.x,offset:0,snap:"start"}],horizontal:[{guide:i.y,offset:0,snap:"start"}]});if(!s.length||(r(s),o.ctrlKey||o.metaKey))return i;let u=i.x,c=i.x;s.forEach(e=>{switch(e.orientation){case"V":u=e.lineGuide;break;case"H":c=e.lineGuide}});let d=Math.abs(i.x-u),h=Math.abs(i.y-c),f=d<10,p=h<10;return f&&!p?{x:u,y:t.y}:p&&!f?{x:t.x,y:c}:f&&p?{x:u,y:c}:i},a=e=>{if(!e.target)return;let t=e.target.getLayer();t.children.find(e=>"line-guides"===e.name()).destroyChildren(),t.batchDraw()};s(y).useEffect(()=>{e.current&&(e.current.anchorDragBoundFunc(o),e.current.on("dragstart",()=>{setTimeout(()=>{let e=[...s(N).DD._dragElements.entries()];e.reverse(),s(N).DD._dragElements.clear(),e.forEach(([e,t])=>{s(N).DD._dragElements.set(e,t)})})}),e.current.on("dragmove",i),e.current.on("dragend",a),e.current.on("transformend",a),e.current.on("transform",t=>{t.evt.ctrlKey||t.evt.metaKey?e.current?.rotationSnapTolerance(0):e.current?.rotationSnapTolerance(5)}))},[])}(x);let F=e.activePage===t,z=u?.PageControls,B=u?.Tooltip,U=1/e.scale,H=0/e.scale;return(0,g.jsxs)("div",{ref:E,onDragOver:e=>e.preventDefault(),onDrop:n=>{if(n.preventDefault(),!_.current)return;_.current.setPointersPositions(n);let r=_.current.findOne(".elements-container").getRelativePointerPosition(),i=_.current.getPointerPosition(),o=[...new Set(_.current.getAllIntersections(i).map(e=>e.findAncestor(".element",!0)).filter(Boolean).reverse())].map(t=>e.getElementById(t.id())),a=o[0];aq&&(aq(r,a,{elements:o,page:t}),aq=null)},style:{position:"relative",width:n+"px"},className:"polotno-page-container"+(F?" active-page":""),children:[(0,g.jsx)(r2,{ref:_,width:Math.min(n,4*window.innerWidth),height:Math.min(r,4*window.innerHeight),onClick:D,onTap:D,onMouseDown:M,onMouseMove:n=>{if(!n.evt.altKey&&S){C(null);return}if(!n.evt.altKey)return;let r=n.target.findAncestor(".element",!0),i=r?.id();if(!e.selectedElements[0]||e.selectedElementsIds.includes(i))return;let o=oB(e.selectedShapes),a=oz(i?e.getElementById(i):{x:0,y:0,width:t.computedWidth,height:t.computedHeight,rotation:0}),l=[];o.minX>a.maxX&&l.push({distance:o.minX-a.maxX,box1:o,box2:a,points:[{x:o.minX,y:o.minY+o.height/2},{x:a.maxX,y:o.minY+o.height/2},{x:a.maxX,y:a.minY+a.height/2}]}),o.maxX<a.minX&&l.push({distance:a.minX-o.maxX,box1:o,box2:a,points:[{x:o.maxX,y:o.minY+o.height/2},{x:a.minX,y:o.minY+o.height/2},{x:a.minX,y:a.minY+a.height/2}]}),o.minY>a.maxY&&l.push({box1:o,box2:a,distance:o.minY-a.maxY,points:[{x:o.minX+o.width/2,y:o.minY},{x:o.minX+o.width/2,y:a.maxY},{x:a.minX+a.width/2,y:a.maxY}]}),o.maxY<a.minY&&l.push({box1:o,box2:a,distance:a.minY-o.maxY,points:[{x:o.minX+o.width/2,y:o.maxY},{x:o.minX+o.width/2,y:a.minY},{x:a.minX+a.width/2,y:a.minY}]}),o.minX>=a.minX&&o.maxX<=a.maxX&&o.minY>=a.minY&&o.maxY<=a.maxY&&(l.push({distance:o.minX-a.minX,box1:o,box2:a,points:[{x:o.minX,y:o.minY+o.height/2},{x:a.minX,y:o.minY+o.height/2},{x:a.minX,y:a.minY+a.height/2}]}),l.push({distance:a.maxX-o.maxX,box1:o,box2:a,points:[{x:o.maxX,y:o.minY+o.height/2},{x:a.maxX,y:o.minY+o.height/2},{x:a.maxX,y:a.minY+a.height/2}]}),l.push({box1:o,box2:a,distance:o.minY-a.minY,points:[{x:o.minX+o.width/2,y:o.minY},{x:o.minX+o.width/2,y:a.minY},{x:a.minX+a.width/2,y:a.minY}]}),l.push({box1:o,box2:a,distance:a.maxY-o.maxY,points:[{x:o.minX+o.width/2,y:o.maxY},{x:o.minX+o.width/2,y:a.maxY},{x:a.minX+a.width/2,y:a.maxY}]})),JSON.stringify(S)!==JSON.stringify(l)&&C(l)},onTouchStart:M,onDragStart:t=>{let n=t.target.findAncestor(".element",!0);if(n){let r=e.getElementById(n?.id()),i=r?.top,o=i?.id;!(e.selectedElementsIds.indexOf(o)>=0)&&o&&(e.selectElements([o]),t.target.stopDrag(),t.target.startDrag(t),x.current?.startDrag(t))}S&&C(null)},pageId:t.id,style:{position:"relative"},children:(0,g.jsxs)("Layer",{children:[(0,g.jsx)(aD,{width:n,height:r,fill:o}),(0,g.jsx)(r$,{x:v,y:w,scaleX:e.scale,scaleY:e.scale,name:"page-container",children:(0,g.jsxs)(r$,{name:"page-container-2",children:[(0,g.jsx)(r$,{name:"page-background-group",x:f,y:f,children:(0,g.jsx)(aB,{x:-t.bleed,y:-t.bleed,width:t.computedWidth+2*t.bleed,height:t.computedHeight+2*t.bleed,background:t.background,shadowBlur:10,shadowColor:"lightgrey",name:"page-background",preventDefault:!1,scale:e.scale})}),(0,g.jsxs)(r$,{x:f,y:f,name:"elements-container",listening:!e.isPlaying,children:[(0,g.jsx)(rY,{name:"elements-area",width:t.computedWidth,height:t.computedHeight,listening:!1}),(0,g.jsx)(aV,{elements:t.children,store:e})]}),(0,g.jsx)(rY,{stroke:c,name:"bleed",strokeWidth:t.bleed,x:t.bleed/2,y:t.bleed/2,width:t.computedWidth+t.bleed,height:t.computedHeight+t.bleed,listening:!1,visible:t.bleed>0&&e.bleedVisible,hideInExport:!0})]})}),(0,g.jsx)(rX,{name:"workspace-background",points:[0,0,n,0,n,r,0,r,0,0,v,w,v,r-w,n-v,r-w,n-v,w,v,w],listening:!1,closed:!0,fill:o}),(0,g.jsx)(r$,{x:v,y:w,scaleX:e.scale,scaleY:e.scale,children:(0,g.jsx)(rY,{name:"page-highlight",hideInExport:!0,x:-U/2-H,y:-U/2-H,width:p+U+2*H,height:m+U+2*H,stroke:F&&e.pages.length>1?l:a,strokeWidth:2,listening:!1,strokeScaleEnabled:!1})}),(0,g.jsxs)(r$,{x:v+f*e.scale,y:w+f*e.scale,scaleX:e.scale,scaleY:e.scale,name:"page-abs-container",children:[(0,g.jsx)(r0,{ref:x,onDragStart:n=>{n.evt?.altKey&&d&&e.selectedElements.forEach(e=>{let n=e.clone({},{skipSelect:!0}),r=t.children.indexOf(e);t.setElementZIndex(n.id,r)}),e.history.startTransaction()},onDragEnd:()=>{e.history.endTransaction()},onTransformStart:()=>{e.history.startTransaction()},boundBoxFunc:(e,t)=>{let n=1>Math.abs(t.width)||1>Math.abs(t.height),r=1>Math.abs(e.width)||1>Math.abs(e.height);return n&&!r?e:t},onTransform:e=>{let t=x.current.nodes(),n=t[t.length-1];if(e.target!==n)return;let r=x.current?.__getNodeRect();k({anchor:x.current?.getActiveAnchor(),x:r.x,y:r.y,rotation:r.rotation,width:r.width,height:r.height})},onTransformEnd:t=>{k({}),e.history.endTransaction()},visible:!e.isPlaying}),S&&S.map(({points:t,distance:n,box1:r,box2:i},o)=>(0,g.jsxs)(r$,{name:"distances-container",hideInExport:!0,listening:!1,children:[(0,g.jsx)(rY,{...r,stroke:"rgb(0, 161, 255)",strokeWidth:1,strokeScaleEnabled:!1}),(0,g.jsx)(rY,{...i,stroke:"rgb(0, 161, 255)",strokeWidth:1,strokeScaleEnabled:!1}),(0,g.jsx)(rX,{points:[t[0].x,t[0].y,t[1].x,t[1].y],stroke:"rgb(0, 161, 255)",strokeWidth:1,strokeScaleEnabled:!1}),(0,g.jsx)(rX,{points:[t[1].x,t[1].y,t[2].x,t[2].y],stroke:"rgb(0, 161, 255)",strokeWidth:1,strokeScaleEnabled:!1}),(0,g.jsxs)(rK,{x:(t[0].x+t[1].x)/2,y:(t[0].y+t[1].y)/2,offsetY:-10,scaleX:1/e.scale,scaleY:1/e.scale,children:[(0,g.jsx)("Tag",{cornerRadius:5,fill:"rgb(0, 161, 255)",pointerDirection:"down"}),(0,g.jsx)(rQ,{align:"center",verticalAlign:"middle",fill:"white",padding:5,text:aN({unit:e.unit,dpi:e.dpi,px:n})})]})]},o)),t._rendering&&(0,g.jsxs)(r$,{children:[(0,g.jsx)(rY,{width:p,height:m,fill:"rgba(255,255,255,0.9)"}),(0,g.jsx)(rQ,{text:"Rendering...",fontSize:60,width:p,height:m,align:"center",verticalAlign:"middle"})]}),B&&(0,g.jsx)(B,{components:u,store:e,page:t,stageRef:_})]}),(0,g.jsx)(aH,{...O,store:e}),(0,g.jsx)(aU,{selection:R}),ay.value&&(0,g.jsx)(rQ,{text:"Powered by polotno.com",fontSize:14,fill:"rgba(0,0,0,0.6)",x:n-170,y:r-18,onMouseEnter:e=>{e.target.getStage().container().style.cursor="pointer"},onMouseLeave:e=>{e.target.getStage().container().style.cursor=""},onTouchStart:e=>{e.cancelBubble=!0},onMouseDown:e=>{e.cancelBubble=!0},onClick:()=>{window.open("https://polotno.com")},onTap:()=>{window.open("https://polotno.com")}}),(0,g.jsx)(r$,{name:"line-guides"})]})}),(i??!0)&&F&&z&&(0,g.jsx)(z,{store:e,page:t,xPadding:v,yPadding:w})]})}),y=f("8NFma");let a$=[.1,.2,.5,1,2,5,10,20,25,50,100,200,500,1e3,2e3,5e3,1e4],aK=e=>a$.find(t=>e(t)>30)||1e4,aY=T(({store:e,width:t,height:n})=>{let r=s(y).useRef(null);if(!e.activePage)return null;let i=e.activePage;e.bleedVisible&&i.bleed;let o=i.computedWidth*e.scale,a=i.computedHeight*e.scale,l=(t-o)/2,u=aK(t=>aA({unitVal:t,dpi:e.dpi,unit:e.unit})*e.scale),c=aA({unitVal:u,dpi:e.dpi,unit:e.unit})*e.scale,d=Math.round(o/c)+1,h=Math.round(a/c)+1,f=oB(e.selectedShapes);return(0,g.jsxs)("div",{style:{position:"absolute",top:0,left:0,pointerEvents:"none"},ref:r,children:[(0,g.jsxs)("div",{style:{width:t+"px",height:"14px",position:"sticky",fontSize:"8px",lineHeight:"14px",top:"0px",left:"0px",color:"grey",borderBottom:"1px solid grey",backgroundColor:"#e8e8e8",overflow:"hidden"},children:[[...Array(d)].map((t,n)=>(0,g.jsx)("div",{style:{position:"absolute",left:l+n*c+"px",borderLeft:"1px solid grey",paddingLeft:"2px",width:c+"px"},children:"px"===e.unit||u>=1?Math.round(u*n):(u*n).toFixed(1)},n)),!!e.selectedShapes.length&&(0,g.jsx)("div",{style:{position:"absolute",left:l+f.x*e.scale+"px",height:"14px",width:f.width*e.scale,backgroundColor:"rgba(0,0,0,0.15)"}})]}),e.pages.map((t,r)=>{let i=(n-t.computedHeight*e.scale)/2;return(0,g.jsxs)("div",{style:{left:"0px",width:"14px",height:n+"px",position:"sticky",fontSize:"8px",lineHeight:"14px",color:"grey",borderRight:"1px solid grey",backgroundColor:"#e8e8e8",overflow:"hidden"},children:[[...Array(h)].map((t,n)=>(0,g.jsx)("div",{style:{position:"absolute",left:"14px",top:i+n*c-14+"px",borderLeft:"1px solid grey",paddingLeft:"2px",transform:"rotate(90deg)",transformOrigin:"left top",width:c+"px",overflow:"hidden"},children:"px"===e.unit||u>=1?Math.round(u*n):(u*n).toFixed(1)},n)),e.selectedShapes[0]?.page===t&&(0,g.jsx)("div",{style:{position:"absolute",top:i+f.y*e.scale-14+"px",width:"14px",height:f.height*e.scale,backgroundColor:"rgba(0,0,0,0.15)"}})]},t.id)})]})});var iU=(f("58B0H"),f("58B0H"));let aX=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((e,t)=>((t&=63)<36?e+=t.toString(36):t<62?e+=(t-26).toString(36).toUpperCase():t>62?e+="-":e+="_",e),"");var iU=(f("58B0H"),f("58B0H"));let aZ=function(e,t){if(e===t)return!0;if("object"!=typeof e||null==e||"object"!=typeof t||null==t||Object.keys(e).length!=Object.keys(t).length)return!1;for(var n in e)if(!t.hasOwnProperty(n)||!aZ(e[n],t[n]))return!1;return!0};Object.assign(iU.types);let aQ=(0,iU.types).model("UndoManager",{history:(0,iU.types).array((0,iU.types).frozen()),undoIdx:-1,targetPath:""}).views(e=>({get canUndo(){return e.undoIdx>0},get canRedo(){return e.undoIdx<e.history.length-1}})).actions(e=>{let t,n;let r=!1,i=null,o=0,a=0,l=()=>a>0;function s(){let e=(0,iU.getSnapshot)(t);return{pages:e.pages,width:e.width,height:e.height}}function u(e){aZ(t.pages.map(e=>e.id),e.pages.map(e=>e.id))?t.pages.forEach((t,n)=>{(0,iU.applySnapshot)(t,e.pages[n])}):(0,iU.applySnapshot)(t.pages,e.pages),t.setSize(e.width,e.height)}return{startTransaction(){a++},endTransaction(e){a--,e||this.requestAddState(s())},async ignore(t,n=!1,r=!1){r&&await new Promise(e=>setTimeout(e,10)),o&&e.addUndoState();let i=l();e.startTransaction();let s=a;try{await t()}catch(e){setTimeout(()=>{throw e})}let u=s!==a;e.endTransaction(!u),n||i||e.replaceState(),u||(clearTimeout(o),o=0)},async transaction(t){await e.ignore(t,!0),this.addUndoState()},requestAddState(e){if(i=e,!o&&!l()){if(r){r=!1;return}o=setTimeout(()=>{clearTimeout(o=0),l()||this.addUndoState()},100)}},addUndoState(){if(r){r=!1;return}let t=e.history[e.undoIdx];aZ(i,t)||(clearTimeout(o),o=0,e.history.splice(e.undoIdx+1),e.history.push(i),e.undoIdx=e.history.length-1)},afterCreate(){if(!(t=(0,iU.resolvePath)(e,"..")))throw Error("Failed to find target store for UndoManager. Please provide `targetPath` property, or a `targetStore` in the environment");n=(0,iU.onSnapshot)(t,()=>{this.requestAddState(s())}),0===e.history.length&&this.requestAddState(s())},clear(){clearTimeout(o),o=0,e.history.splice(0,e.history.length),e.undoIdx=-1,e.addUndoState(s())},beforeDestroy(){n()},undo(){if(o&&this.addUndoState(),!e.canUndo){console.warn("No undo history. Please check `store.history.canUndo` before calling undo action.");return}e.undoIdx--,r=!0,u(e.history[e.undoIdx])},redo(){if(o&&this.addUndoState(),!e.canRedo){console.warn("No redo history. Please check `store.history.canRedo` before calling redo action.");return}e.undoIdx++,r=!0,u(e.history[e.undoIdx])},replaceState(){e.history[e.undoIdx]=s()}}});async function aJ(e,t){let n=await (await fetch(e)).blob(),r=document.createElement("a"),i=URL.createObjectURL(n);r.href=i,r.download=t,document.body.appendChild(r),r.click(),setTimeout(function(){document.body.removeChild(r),window.URL.revokeObjectURL(i)},0)}async function a0({width:e,height:t}){return new(await (window.GIF?Promise.resolve(window.GIF):new Promise(e=>{var t=document.createElement("script");t.onload=function(){e(window.GIF)},t.src="https://cdnjs.cloudflare.com/ajax/libs/gif.js/0.2.0/gif.js",document.head.appendChild(t)})))({workers:4,width:e,height:t,workerScript:URL.createObjectURL(new Blob([`// gif.worker.js 0.2.0 - https://github.com/jnordberg/gif.js
111
111
  (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){var NeuQuant=require("./TypedNeuQuant.js");var LZWEncoder=require("./LZWEncoder.js");function ByteArray(){this.page=-1;this.pages=[];this.newPage()}ByteArray.pageSize=4096;ByteArray.charMap={};for(var i=0;i<256;i++)ByteArray.charMap[i]=String.fromCharCode(i);ByteArray.prototype.newPage=function(){this.pages[++this.page]=new Uint8Array(ByteArray.pageSize);this.cursor=0};ByteArray.prototype.getData=function(){var rv="";for(var p=0;p<this.pages.length;p++){for(var i=0;i<ByteArray.pageSize;i++){rv+=ByteArray.charMap[this.pages[p][i]]}}return rv};ByteArray.prototype.writeByte=function(val){if(this.cursor>=ByteArray.pageSize)this.newPage();this.pages[this.page][this.cursor++]=val};ByteArray.prototype.writeUTFBytes=function(string){for(var l=string.length,i=0;i<l;i++)this.writeByte(string.charCodeAt(i))};ByteArray.prototype.writeBytes=function(array,offset,length){for(var l=length||array.length,i=offset||0;i<l;i++)this.writeByte(array[i])};function GIFEncoder(width,height){this.width=~~width;this.height=~~height;this.transparent=null;this.transIndex=0;this.repeat=-1;this.delay=0;this.image=null;this.pixels=null;this.indexedPixels=null;this.colorDepth=null;this.colorTab=null;this.neuQuant=null;this.usedEntry=new Array;this.palSize=7;this.dispose=-1;this.firstFrame=true;this.sample=10;this.dither=false;this.globalPalette=false;this.out=new ByteArray}GIFEncoder.prototype.setDelay=function(milliseconds){this.delay=Math.round(milliseconds/10)};GIFEncoder.prototype.setFrameRate=function(fps){this.delay=Math.round(100/fps)};GIFEncoder.prototype.setDispose=function(disposalCode){if(disposalCode>=0)this.dispose=disposalCode};GIFEncoder.prototype.setRepeat=function(repeat){this.repeat=repeat};GIFEncoder.prototype.setTransparent=function(color){this.transparent=color};GIFEncoder.prototype.addFrame=function(imageData){this.image=imageData;this.colorTab=this.globalPalette&&this.globalPalette.slice?this.globalPalette:null;this.getImagePixels();this.analyzePixels();if(this.globalPalette===true)this.globalPalette=this.colorTab;if(this.firstFrame){this.writeLSD();this.writePalette();if(this.repeat>=0){this.writeNetscapeExt()}}this.writeGraphicCtrlExt();this.writeImageDesc();if(!this.firstFrame&&!this.globalPalette)this.writePalette();this.writePixels();this.firstFrame=false};GIFEncoder.prototype.finish=function(){this.out.writeByte(59)};GIFEncoder.prototype.setQuality=function(quality){if(quality<1)quality=1;this.sample=quality};GIFEncoder.prototype.setDither=function(dither){if(dither===true)dither="FloydSteinberg";this.dither=dither};GIFEncoder.prototype.setGlobalPalette=function(palette){this.globalPalette=palette};GIFEncoder.prototype.getGlobalPalette=function(){return this.globalPalette&&this.globalPalette.slice&&this.globalPalette.slice(0)||this.globalPalette};GIFEncoder.prototype.writeHeader=function(){this.out.writeUTFBytes("GIF89a")};GIFEncoder.prototype.analyzePixels=function(){if(!this.colorTab){this.neuQuant=new NeuQuant(this.pixels,this.sample);this.neuQuant.buildColormap();this.colorTab=this.neuQuant.getColormap()}if(this.dither){this.ditherPixels(this.dither.replace("-serpentine",""),this.dither.match(/-serpentine/)!==null)}else{this.indexPixels()}this.pixels=null;this.colorDepth=8;this.palSize=7;if(this.transparent!==null){this.transIndex=this.findClosest(this.transparent,true)}};GIFEncoder.prototype.indexPixels=function(imgq){var nPix=this.pixels.length/3;this.indexedPixels=new Uint8Array(nPix);var k=0;for(var j=0;j<nPix;j++){var index=this.findClosestRGB(this.pixels[k++]&255,this.pixels[k++]&255,this.pixels[k++]&255);this.usedEntry[index]=true;this.indexedPixels[j]=index}};GIFEncoder.prototype.ditherPixels=function(kernel,serpentine){var kernels={FalseFloydSteinberg:[[3/8,1,0],[3/8,0,1],[2/8,1,1]],FloydSteinberg:[[7/16,1,0],[3/16,-1,1],[5/16,0,1],[1/16,1,1]],Stucki:[[8/42,1,0],[4/42,2,0],[2/42,-2,1],[4/42,-1,1],[8/42,0,1],[4/42,1,1],[2/42,2,1],[1/42,-2,2],[2/42,-1,2],[4/42,0,2],[2/42,1,2],[1/42,2,2]],Atkinson:[[1/8,1,0],[1/8,2,0],[1/8,-1,1],[1/8,0,1],[1/8,1,1],[1/8,0,2]]};if(!kernel||!kernels[kernel]){throw"Unknown dithering kernel: "+kernel}var ds=kernels[kernel];var index=0,height=this.height,width=this.width,data=this.pixels;var direction=serpentine?-1:1;this.indexedPixels=new Uint8Array(this.pixels.length/3);for(var y=0;y<height;y++){if(serpentine)direction=direction*-1;for(var x=direction==1?0:width-1,xend=direction==1?width:0;x!==xend;x+=direction){index=y*width+x;var idx=index*3;var r1=data[idx];var g1=data[idx+1];var b1=data[idx+2];idx=this.findClosestRGB(r1,g1,b1);this.usedEntry[idx]=true;this.indexedPixels[index]=idx;idx*=3;var r2=this.colorTab[idx];var g2=this.colorTab[idx+1];var b2=this.colorTab[idx+2];var er=r1-r2;var eg=g1-g2;var eb=b1-b2;for(var i=direction==1?0:ds.length-1,end=direction==1?ds.length:0;i!==end;i+=direction){var x1=ds[i][1];var y1=ds[i][2];if(x1+x>=0&&x1+x<width&&y1+y>=0&&y1+y<height){var d=ds[i][0];idx=index+x1+y1*width;idx*=3;data[idx]=Math.max(0,Math.min(255,data[idx]+er*d));data[idx+1]=Math.max(0,Math.min(255,data[idx+1]+eg*d));data[idx+2]=Math.max(0,Math.min(255,data[idx+2]+eb*d))}}}}};GIFEncoder.prototype.findClosest=function(c,used){return this.findClosestRGB((c&16711680)>>16,(c&65280)>>8,c&255,used)};GIFEncoder.prototype.findClosestRGB=function(r,g,b,used){if(this.colorTab===null)return-1;if(this.neuQuant&&!used){return this.neuQuant.lookupRGB(r,g,b)}var c=b|g<<8|r<<16;var minpos=0;var dmin=256*256*256;var len=this.colorTab.length;for(var i=0,index=0;i<len;index++){var dr=r-(this.colorTab[i++]&255);var dg=g-(this.colorTab[i++]&255);var db=b-(this.colorTab[i++]&255);var d=dr*dr+dg*dg+db*db;if((!used||this.usedEntry[index])&&d<dmin){dmin=d;minpos=index}}return minpos};GIFEncoder.prototype.getImagePixels=function(){var w=this.width;var h=this.height;this.pixels=new Uint8Array(w*h*3);var data=this.image;var srcPos=0;var count=0;for(var i=0;i<h;i++){for(var j=0;j<w;j++){this.pixels[count++]=data[srcPos++];this.pixels[count++]=data[srcPos++];this.pixels[count++]=data[srcPos++];srcPos++}}};GIFEncoder.prototype.writeGraphicCtrlExt=function(){this.out.writeByte(33);this.out.writeByte(249);this.out.writeByte(4);var transp,disp;if(this.transparent===null){transp=0;disp=0}else{transp=1;disp=2}if(this.dispose>=0){disp=dispose&7}disp<<=2;this.out.writeByte(0|disp|0|transp);this.writeShort(this.delay);this.out.writeByte(this.transIndex);this.out.writeByte(0)};GIFEncoder.prototype.writeImageDesc=function(){this.out.writeByte(44);this.writeShort(0);this.writeShort(0);this.writeShort(this.width);this.writeShort(this.height);if(this.firstFrame||this.globalPalette){this.out.writeByte(0)}else{this.out.writeByte(128|0|0|0|this.palSize)}};GIFEncoder.prototype.writeLSD=function(){this.writeShort(this.width);this.writeShort(this.height);this.out.writeByte(128|112|0|this.palSize);this.out.writeByte(0);this.out.writeByte(0)};GIFEncoder.prototype.writeNetscapeExt=function(){this.out.writeByte(33);this.out.writeByte(255);this.out.writeByte(11);this.out.writeUTFBytes("NETSCAPE2.0");this.out.writeByte(3);this.out.writeByte(1);this.writeShort(this.repeat);this.out.writeByte(0)};GIFEncoder.prototype.writePalette=function(){this.out.writeBytes(this.colorTab);var n=3*256-this.colorTab.length;for(var i=0;i<n;i++)this.out.writeByte(0)};GIFEncoder.prototype.writeShort=function(pValue){this.out.writeByte(pValue&255);this.out.writeByte(pValue>>8&255)};GIFEncoder.prototype.writePixels=function(){var enc=new LZWEncoder(this.width,this.height,this.indexedPixels,this.colorDepth);enc.encode(this.out)};GIFEncoder.prototype.stream=function(){return this.out};module.exports=GIFEncoder},{"./LZWEncoder.js":2,"./TypedNeuQuant.js":3}],2:[function(require,module,exports){var EOF=-1;var BITS=12;var HSIZE=5003;var masks=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535];function LZWEncoder(width,height,pixels,colorDepth){var initCodeSize=Math.max(2,colorDepth);var accum=new Uint8Array(256);var htab=new Int32Array(HSIZE);var codetab=new Int32Array(HSIZE);var cur_accum,cur_bits=0;var a_count;var free_ent=0;var maxcode;var clear_flg=false;var g_init_bits,ClearCode,EOFCode;function char_out(c,outs){accum[a_count++]=c;if(a_count>=254)flush_char(outs)}function cl_block(outs){cl_hash(HSIZE);free_ent=ClearCode+2;clear_flg=true;output(ClearCode,outs)}function cl_hash(hsize){for(var i=0;i<hsize;++i)htab[i]=-1}function compress(init_bits,outs){var fcode,c,i,ent,disp,hsize_reg,hshift;g_init_bits=init_bits;clear_flg=false;n_bits=g_init_bits;maxcode=MAXCODE(n_bits);ClearCode=1<<init_bits-1;EOFCode=ClearCode+1;free_ent=ClearCode+2;a_count=0;ent=nextPixel();hshift=0;for(fcode=HSIZE;fcode<65536;fcode*=2)++hshift;hshift=8-hshift;hsize_reg=HSIZE;cl_hash(hsize_reg);output(ClearCode,outs);outer_loop:while((c=nextPixel())!=EOF){fcode=(c<<BITS)+ent;i=c<<hshift^ent;if(htab[i]===fcode){ent=codetab[i];continue}else if(htab[i]>=0){disp=hsize_reg-i;if(i===0)disp=1;do{if((i-=disp)<0)i+=hsize_reg;if(htab[i]===fcode){ent=codetab[i];continue outer_loop}}while(htab[i]>=0)}output(ent,outs);ent=c;if(free_ent<1<<BITS){codetab[i]=free_ent++;htab[i]=fcode}else{cl_block(outs)}}output(ent,outs);output(EOFCode,outs)}function encode(outs){outs.writeByte(initCodeSize);remaining=width*height;curPixel=0;compress(initCodeSize+1,outs);outs.writeByte(0)}function flush_char(outs){if(a_count>0){outs.writeByte(a_count);outs.writeBytes(accum,0,a_count);a_count=0}}function MAXCODE(n_bits){return(1<<n_bits)-1}function nextPixel(){if(remaining===0)return EOF;--remaining;var pix=pixels[curPixel++];return pix&255}function output(code,outs){cur_accum&=masks[cur_bits];if(cur_bits>0)cur_accum|=code<<cur_bits;else cur_accum=code;cur_bits+=n_bits;while(cur_bits>=8){char_out(cur_accum&255,outs);cur_accum>>=8;cur_bits-=8}if(free_ent>maxcode||clear_flg){if(clear_flg){maxcode=MAXCODE(n_bits=g_init_bits);clear_flg=false}else{++n_bits;if(n_bits==BITS)maxcode=1<<BITS;else maxcode=MAXCODE(n_bits)}}if(code==EOFCode){while(cur_bits>0){char_out(cur_accum&255,outs);cur_accum>>=8;cur_bits-=8}flush_char(outs)}}this.encode=encode}module.exports=LZWEncoder},{}],3:[function(require,module,exports){var ncycles=100;var netsize=256;var maxnetpos=netsize-1;var netbiasshift=4;var intbiasshift=16;var intbias=1<<intbiasshift;var gammashift=10;var gamma=1<<gammashift;var betashift=10;var beta=intbias>>betashift;var betagamma=intbias<<gammashift-betashift;var initrad=netsize>>3;var radiusbiasshift=6;var radiusbias=1<<radiusbiasshift;var initradius=initrad*radiusbias;var radiusdec=30;var alphabiasshift=10;var initalpha=1<<alphabiasshift;var alphadec;var radbiasshift=8;var radbias=1<<radbiasshift;var alpharadbshift=alphabiasshift+radbiasshift;var alpharadbias=1<<alpharadbshift;var prime1=499;var prime2=491;var prime3=487;var prime4=503;var minpicturebytes=3*prime4;function NeuQuant(pixels,samplefac){var network;var netindex;var bias;var freq;var radpower;function init(){network=[];netindex=new Int32Array(256);bias=new Int32Array(netsize);freq=new Int32Array(netsize);radpower=new Int32Array(netsize>>3);var i,v;for(i=0;i<netsize;i++){v=(i<<netbiasshift+8)/netsize;network[i]=new Float64Array([v,v,v,0]);freq[i]=intbias/netsize;bias[i]=0}}function unbiasnet(){for(var i=0;i<netsize;i++){network[i][0]>>=netbiasshift;network[i][1]>>=netbiasshift;network[i][2]>>=netbiasshift;network[i][3]=i}}function altersingle(alpha,i,b,g,r){network[i][0]-=alpha*(network[i][0]-b)/initalpha;network[i][1]-=alpha*(network[i][1]-g)/initalpha;network[i][2]-=alpha*(network[i][2]-r)/initalpha}function alterneigh(radius,i,b,g,r){var lo=Math.abs(i-radius);var hi=Math.min(i+radius,netsize);var j=i+1;var k=i-1;var m=1;var p,a;while(j<hi||k>lo){a=radpower[m++];if(j<hi){p=network[j++];p[0]-=a*(p[0]-b)/alpharadbias;p[1]-=a*(p[1]-g)/alpharadbias;p[2]-=a*(p[2]-r)/alpharadbias}if(k>lo){p=network[k--];p[0]-=a*(p[0]-b)/alpharadbias;p[1]-=a*(p[1]-g)/alpharadbias;p[2]-=a*(p[2]-r)/alpharadbias}}}function contest(b,g,r){var bestd=~(1<<31);var bestbiasd=bestd;var bestpos=-1;var bestbiaspos=bestpos;var i,n,dist,biasdist,betafreq;for(i=0;i<netsize;i++){n=network[i];dist=Math.abs(n[0]-b)+Math.abs(n[1]-g)+Math.abs(n[2]-r);if(dist<bestd){bestd=dist;bestpos=i}biasdist=dist-(bias[i]>>intbiasshift-netbiasshift);if(biasdist<bestbiasd){bestbiasd=biasdist;bestbiaspos=i}betafreq=freq[i]>>betashift;freq[i]-=betafreq;bias[i]+=betafreq<<gammashift}freq[bestpos]+=beta;bias[bestpos]-=betagamma;return bestbiaspos}function inxbuild(){var i,j,p,q,smallpos,smallval,previouscol=0,startpos=0;for(i=0;i<netsize;i++){p=network[i];smallpos=i;smallval=p[1];for(j=i+1;j<netsize;j++){q=network[j];if(q[1]<smallval){smallpos=j;smallval=q[1]}}q=network[smallpos];if(i!=smallpos){j=q[0];q[0]=p[0];p[0]=j;j=q[1];q[1]=p[1];p[1]=j;j=q[2];q[2]=p[2];p[2]=j;j=q[3];q[3]=p[3];p[3]=j}if(smallval!=previouscol){netindex[previouscol]=startpos+i>>1;for(j=previouscol+1;j<smallval;j++)netindex[j]=i;previouscol=smallval;startpos=i}}netindex[previouscol]=startpos+maxnetpos>>1;for(j=previouscol+1;j<256;j++)netindex[j]=maxnetpos}function inxsearch(b,g,r){var a,p,dist;var bestd=1e3;var best=-1;var i=netindex[g];var j=i-1;while(i<netsize||j>=0){if(i<netsize){p=network[i];dist=p[1]-g;if(dist>=bestd)i=netsize;else{i++;if(dist<0)dist=-dist;a=p[0]-b;if(a<0)a=-a;dist+=a;if(dist<bestd){a=p[2]-r;if(a<0)a=-a;dist+=a;if(dist<bestd){bestd=dist;best=p[3]}}}}if(j>=0){p=network[j];dist=g-p[1];if(dist>=bestd)j=-1;else{j--;if(dist<0)dist=-dist;a=p[0]-b;if(a<0)a=-a;dist+=a;if(dist<bestd){a=p[2]-r;if(a<0)a=-a;dist+=a;if(dist<bestd){bestd=dist;best=p[3]}}}}}return best}function learn(){var i;var lengthcount=pixels.length;var alphadec=30+(samplefac-1)/3;var samplepixels=lengthcount/(3*samplefac);var delta=~~(samplepixels/ncycles);var alpha=initalpha;var radius=initradius;var rad=radius>>radiusbiasshift;if(rad<=1)rad=0;for(i=0;i<rad;i++)radpower[i]=alpha*((rad*rad-i*i)*radbias/(rad*rad));var step;if(lengthcount<minpicturebytes){samplefac=1;step=3}else if(lengthcount%prime1!==0){step=3*prime1}else if(lengthcount%prime2!==0){step=3*prime2}else if(lengthcount%prime3!==0){step=3*prime3}else{step=3*prime4}var b,g,r,j;var pix=0;i=0;while(i<samplepixels){b=(pixels[pix]&255)<<netbiasshift;g=(pixels[pix+1]&255)<<netbiasshift;r=(pixels[pix+2]&255)<<netbiasshift;j=contest(b,g,r);altersingle(alpha,j,b,g,r);if(rad!==0)alterneigh(rad,j,b,g,r);pix+=step;if(pix>=lengthcount)pix-=lengthcount;i++;if(delta===0)delta=1;if(i%delta===0){alpha-=alpha/alphadec;radius-=radius/radiusdec;rad=radius>>radiusbiasshift;if(rad<=1)rad=0;for(j=0;j<rad;j++)radpower[j]=alpha*((rad*rad-j*j)*radbias/(rad*rad))}}}function buildColormap(){init();learn();unbiasnet();inxbuild()}this.buildColormap=buildColormap;function getColormap(){var map=[];var index=[];for(var i=0;i<netsize;i++)index[network[i][3]]=i;var k=0;for(var l=0;l<netsize;l++){var j=index[l];map[k++]=network[j][0];map[k++]=network[j][1];map[k++]=network[j][2]}return map}this.getColormap=getColormap;this.lookupRGB=inxsearch}module.exports=NeuQuant},{}],4:[function(require,module,exports){var GIFEncoder,renderFrame;GIFEncoder=require("./GIFEncoder.js");renderFrame=function(frame){var encoder,page,stream,transfer;encoder=new GIFEncoder(frame.width,frame.height);if(frame.index===0){encoder.writeHeader()}else{encoder.firstFrame=false}encoder.setTransparent(frame.transparent);encoder.setRepeat(frame.repeat);encoder.setDelay(frame.delay);encoder.setQuality(frame.quality);encoder.setDither(frame.dither);encoder.setGlobalPalette(frame.globalPalette);encoder.addFrame(frame.data);if(frame.last){encoder.finish()}if(frame.globalPalette===true){frame.globalPalette=encoder.getGlobalPalette()}stream=encoder.stream();frame.data=stream.pages;frame.cursor=stream.cursor;frame.pageSize=stream.constructor.pageSize;if(frame.canTransfer){transfer=function(){var i,len,ref,results;ref=frame.data;results=[];for(i=0,len=ref.length;i<len;i++){page=ref[i];results.push(page.buffer)}return results}();return self.postMessage(frame,transfer)}else{return self.postMessage(frame)}};self.onmessage=function(event){return renderFrame(event.data)}},{"./GIFEncoder.js":1}]},{},[4]);
112
112
  `],{type:"application/javascript"}))})}async function a1(e){for(let t=0;t<30;t++){let t=await e();if(t)return t;await new Promise(e=>setTimeout(e,50))}}function a2(e){return new Promise(t=>{let n=document.createElement("img");n.onload=async()=>{0===n.width||0===n.height?t(await i3(e)):t({width:n.width,height:n.height})},n.crossOrigin="anonymous",n.src=e})}function a3(e){return new Promise((t,n)=>{let r=document.createElement("img");r.onload=()=>{t(r)},r.onerror=e=>{n(e)},r.crossOrigin="anonymous",r.src=e})}async function a5(e,t){let n,r;let i=await a3(e),o=document.createElement("canvas");o.width=2*i.width,o.height=2*i.height,o.getContext("2d").drawImage(i,0,0,o.width,o.height);let a=document.createElement("canvas");a.width=t.width,a.height=t.height;let l=a.getContext("2d"),{cropX:s,cropY:u}=t,c=o.width*t.cropWidth,d=o.height*t.cropHeight,h=t.width/t.height,f=c/d;return"svg"===t.type?(n=c,r=d):h>=f?(n=c,r=c/h):(n=d*h,r=d),l.drawImage(o,s*o.width,u*o.height,n,r,0,0,a.width,a.height),a.toDataURL("image/png")}function a6(e,t){let n,r;let{width:i,height:o}=e,a=i/o;a>=t.width/t.height?(n=t.width,r=t.width/a):(n=t.height*a,r=t.height);let l=(t.width-n)/2,s=(t.height-r)/2;return{cropX:l/t.width,cropY:s/t.height,cropWidth:n/t.width,cropHeight:r/t.height}}let a4=(e,t,...n)=>({type:e,props:t,children:n||[]}),a8=async({element:e,page:t,store:n})=>{let r,i,{src:o}=e;"svg"===e.type&&Object.keys(e.colorsReplace).length&&(o=i4(await i1(o),new Map(Object.entries(e.colorsReplace))));let a="";e.flipX&&(a+="scaleX(-1)"),e.flipY&&(a+="scaleY(-1)"),a||(a="none");let l={};if(e.clipSrc){let t=await i0(e.clipSrc);l["clip-path"]=`url(${t})`}let s=await a3(o),u=s.width*e.cropWidth,c=s.height*e.cropHeight,d=e.width/e.height;"svg"===e.type?(r=u,i=c):d>=u/c?(r=u,i=u/d):(r=c*d,i=c);let h=r/s.width,f=i/s.height,p=r/i>e.width/e.height?e.height/i:e.width/r,g=r*p/h,m=i*p/f,v=e.cropX*p*s.width,y=e.cropY*p*s.height;return a4("div",{style:{...l,width:"100%",height:"100%","border-radius":e.cornerRadius+"px",border:e.borderSize?`${e.borderSize}px solid ${e.borderColor}`:"none",background:`url(${o})`,transform:a,"background-size":`${Math.round(g)}px ${Math.round(m)}px`,"background-position-x":`${-Math.round(v)}px`,"background-position-y":`${-Math.round(y)}px`}})},a9=({element:e,type:t})=>{let n={"stroke-width":e.height,stroke:e.color,"line-cap":"round","stroke-linejoin":"round",opacity:e.opacity};return"arrow"===t||"triangle"===t?a4("polyline",{points:`${3*e.height},${-(2*e.height)} 0,0 ${3*e.height},${2*e.height}`,...n}):"bar"===t?a4("polyline",{points:`0,${-(2*e.height)} 0,${2*e.height}`,...n}):"circle"===t?a4("circle",{r:e.height,...n}):"square"===t?a4("polyline",{points:`${-e.height},${-e.height} ${-e.height},${e.height} ${e.height},${e.height} ${e.height},${-e.height}`,...n}):null},a7={image:a8,svg:a8,text:async({element:e,page:t,store:n})=>{let r={};e.fill.indexOf("gradient")>=0&&(r={...r,"background-color":e.fill,"background-image":e.fill,"background-clip":"text","text-fill-color":"transparent","-webkit-background-clip":"text","-webkit-text-fill-color":"transparent"});let i=e.backgroundPadding*(e.fontSize*e.lineHeight),o=a4("div",{style:{position:"absolute",top:-i/2+"px",left:-i/2+"px",display:e.backgroundEnabled?"block":"none",width:e.width+i+"px",height:e.height+i+"px","background-color":e.backgroundColor,"border-radius":e.backgroundCornerRadius*(e.fontSize*e.lineHeight*.5)+"px"}}),a=a4("div",{style:{...r,position:"absolute",top:0,left:0,width:e.width+"px",color:e.fill,"white-space":"pre-wrap","font-size":e.fontSize+"px","text-align":e.align,"font-family":e.fontFamily,"text-decoration":e.textDecoration||"none","line-height":e.lineHeight,"letter-spacing":e.letterSpacing+"em","font-style":e.fontStyle,"font-weight":e.fontWeight,"-webkit-text-stroke":`${e.strokeWidth}px ${e.stroke}`,"text-stroke":`${e.strokeWidth}px ${e.stroke}`}},e.text.split("\n").join("<br />"));return a4("div",{style:{position:"relative"}},o,a)},line:async({element:e,page:t,store:n})=>a4("svg",{style:{width:"100%",height:"100%",contain:"layout style size",overflow:"visible"}},a4("rect",{x:0,y:0,width:e.width,height:e.height,fill:e.color}),a4("g",{transform:`translate(0 ${e.height/2})`},a9({element:e,type:e.startHead})),a4("g",{transform:`translate(${e.width} ${e.height/2}) rotate(180)`},a9({element:e,type:e.endHead}))),figure:async({element:e,page:t,store:n,elementHook:r})=>{let i=a4("div",{innerHTML:ae(e)});return r&&r({dom:i,element:e})||i},group:async({element:e,page:t,store:n,elementHook:r})=>{let i=await Promise.all(e.children.map(e=>le({element:e,page:t,store:n,elementHook:r}))),o=a4("div",{style:{"transform-origin":"top left",opacity:e.opacity}},...i);return r&&r({dom:o,element:e})||o}};async function le({element:e,page:t,store:n,elementHook:r}){let i=await a7[e.type];i||(i=()=>a4("div",{}),console.error(`HTML export does not support ${e.type} type...`));let o=await i({element:e,page:t,store:n}),a=[];e.blurEnabled&&a.push(`blur(${e.blurRadius/2}px)`),e.brightnessEnabled&&a.push(`brightness(${100*e.brightness+100}%)`),e.sepiaEnabled&&a.push("sepia()"),e.grayscaleEnabled&&a.push("grayscale()"),e.shadowEnabled&&a.push(`drop-shadow(${e.shadowOffsetX}px ${e.shadowOffsetY}px ${e.shadowBlur}px ${e.shadowColor})`);let l=a4("div",{style:{position:"absolute",left:e.x+"px",top:e.y+"px",width:e.width+"px",height:e.height+"px",transform:`rotate(${e.rotation}deg)`,"transform-origin":"top left",opacity:e.opacity,filter:a.join(" ")||"none"}},o);return r&&r({dom:l,element:e})||l}async function lt({page:e,store:t,elementHook:n}){let r=await Promise.all(e.children.map(r=>le({element:r,page:e,store:t,elementHook:n}))),i="auto"===e.width?t.width:e.width,o="auto"===e.height?t.height:e.height,a={};if(e.background.indexOf("url")>=0||e.background.indexOf("http")>=0||e.background.indexOf(".jpg")>=0||e.background.indexOf(".png")>=0||e.background.indexOf(".jpeg")>=0){let{width:n,height:i}=await a3(e.background),o=await a8({element:{x:0,y:0,width:n,height:i,src:e.background,cornerRadius:0,...a6({width:n,height:i},{width:n,height:i})},page:e,store:t});r.unshift(o)}else a={...a,"background-color":e.background};return a4("div",{className:"page",style:{...a,width:i+"px",height:o+"px",border:"1px solid grey",overflow:"hidden",position:"relative"}},...r)}async function ln({json:e,elementHook:t}){let n=await Promise.all(e.pages.map(n=>lt({page:n,store:e,elementHook:t}))),r=[];e.pages.forEach(e=>{e.children.forEach(e=>{"text"===e.type&&-1===r.indexOf(e.fontFamily)&&r.push(e.fontFamily)})});let i=r.map(t=>e.fonts.find(e=>e.fontFamily===t)?a4("style",{},""):a4("link",{href:`https://fonts.googleapis.com/css?family=${t}`,rel:"stylesheet"}));return a4("div",{className:"design"},...i,...n)}let lr=(e,t)=>"object"==typeof t?`${e}="${Object.keys(t).map(e=>`${e}:${t[e]};`).join(" ")}"`:`${e}="${t}"`,li=({dom:e})=>{if("string"==typeof e)return e;if(!e)return"";let{innerHTML:t,...n}=e.props;return`<${e.type} ${Object.keys(n).map(t=>lr(t,e.props[t])).join(" ")}>${t||e.children.map(e=>li({dom:e})).join("")}</${e.type}>`};async function lo({json:e,elementHook:t}){return li({dom:await ln({json:e,elementHook:t})})}let la=(e,t,...n)=>({type:e,props:t,children:n||[]}),ll=async e=>{let t=await a3(e),n=document.createElement("canvas");return n.width=t.width,n.height=t.height,n.getContext("2d").drawImage(t,0,0),n.toDataURL("image/png")},ls=async({element:e,page:t,store:n})=>{let r,i,{src:o}=e;"svg"===e.type&&(o=i4(await i1(o),new Map(Object.entries(e.colorsReplace))));let a="";e.flipX&&(a+="scaleX(-1)"),e.flipY&&(a+="scaleY(-1)");let l={};if(e.clipSrc){let t=await i0(e.clipSrc);l["clip-path"]=`url(${t})`}let s=await a3(o),u=s.width*e.cropWidth,c=s.height*e.cropHeight,d=e.width/e.height;"svg"===e.type?(r=u,i=c):d>=u/c?(r=u,i=u/d):(r=c*d,i=c);let h=r/s.width,f=i/s.height,p=r/i>e.width/e.height?e.height/i:e.width/r,g=r*p/h,m=i*p/f,v=e.cropX*p*s.width,y=e.cropY*p*s.height,b=`clip-${Math.random()}`;return la("g",{style:{"clip-path":l["clip-path"],transform:a}},la("defs",{},la("clipPath",{id:b},la("rect",{x:v,y:y,width:g,height:m}))),la("image",{"xlink:href":await ll(o),width:e.width,height:e.height,preserveAspectRatio:"none","clip-path":`url(#${b})`}))},lu=({element:e,type:t})=>{let n={"stroke-width":e.height,stroke:e.color,"line-cap":"round","stroke-linejoin":"round",opacity:e.opacity};return"arrow"===t||"triangle"===t?la("polyline",{points:`${3*e.height},${-(2*e.height)} 0,0 ${3*e.height},${2*e.height}`,...n}):"bar"===t?la("polyline",{points:`0,${-(2*e.height)} 0,${2*e.height}`,...n}):"circle"===t?la("circle",{r:e.height,...n}):"square"===t?la("polyline",{points:`${-e.height},${-e.height} ${-e.height},${e.height} ${e.height},${e.height} ${e.height},${-e.height}`,...n}):null},lc={image:ls,svg:ls,text:async({element:e,page:t,store:n})=>{let r={};e.fill.indexOf("gradient")>=0&&(r={...r,"background-color":e.fill,"background-image":e.fill,"background-clip":"text","text-fill-color":"transparent","-webkit-background-clip":"text","-webkit-text-fill-color":"transparent"});let i=e.backgroundPadding*(e.fontSize*e.lineHeight),o=la("div",{style:{position:"absolute",top:-i/2+"px",left:-i/2+"px",display:e.backgroundEnabled?"block":"none",width:e.width+i+"px",height:e.height+i+"px","background-color":e.backgroundColor,"border-radius":e.backgroundCornerRadius*(e.fontSize*e.lineHeight*.5)+"px"}}),a=la("div",{style:{...r,position:"absolute",top:0,left:0,width:e.width+"px",color:e.fill,"white-space":"pre-wrap","font-size":e.fontSize+"px","text-align":e.align,"font-family":e.fontFamily,"text-decoration":e.textDecoration||"none","line-height":e.lineHeight,"letter-spacing":e.letterSpacing+"em","font-style":e.fontStyle,"font-weight":e.fontWeight,"-webkit-text-stroke":`${e.strokeWidth}px ${e.stroke}`,"text-stroke":`${e.strokeWidth}px ${e.stroke}`}},e.text.split("\n").join("<br />"));return la("foreignObject",{width:e.width,height:e.height},la("div",{style:{position:"relative"},xmlns:"http://www.w3.org/1999/xhtml"},o,a))},line:async({element:e,page:t,store:n})=>la("svg",{style:{width:"100%",height:"100%",contain:"layout style size",overflow:"visible"}},la("rect",{x:0,y:0,width:e.width,height:e.height,fill:e.color}),la("g",{transform:`translate(0 ${e.height/2})`},lu({element:e,type:e.startHead})),la("g",{transform:`translate(${e.width} ${e.height/2}) rotate(180)`},lu({element:e,type:e.endHead}))),group:async({element:e,page:t,store:n,elementHook:r})=>{let i=await Promise.all(e.children.map(e=>ld({element:e,page:t,store:n,elementHook:r}))),o=la("g",{opacity:e.opacity,style:{"transform-origin":"top left"}},...i);return r&&r({dom:o,element:e})||o}};async function ld({element:e,page:t,store:n,elementHook:r}){let i=await lc[e.type];i||(i=()=>la("div",{}),console.error(`HTML export does not support ${e.type} type...`));let o=await i({element:e,page:t,store:n}),a=[];e.blurEnabled&&a.push(`blur(${e.blurRadius/2}px)`),e.brightnessEnabled&&a.push(`brightness(${100*e.brightness+100}%)`),e.sepiaEnabled&&a.push("sepia()"),e.grayscaleEnabled&&a.push("grayscale()"),e.shadowEnabled&&a.push(`drop-shadow(${e.shadowOffsetX}px ${e.shadowOffsetY}px ${e.shadowBlur}px ${e.shadowColor})`);let l=la("g",{transform:`translate(${e.x}, ${e.y}) rotate(${e.rotation})`,rotation:e.rotation,width:e.width,height:e.height,opacity:e.opacity,style:{"transform-origin":"top left",filter:a.join(" ")}},o);return r&&r({dom:l,element:e})||l}async function lh({page:e,store:t,elementHook:n}){let r=await Promise.all(e.children.map(r=>ld({element:r,page:e,store:t,elementHook:n}))),i={};if(e.background.indexOf("url")>=0||e.background.indexOf("http")>=0||e.background.indexOf(".jpg")>=0||e.background.indexOf(".png")>=0||e.background.indexOf(".jpeg")>=0){let n=await a3(e.background),r=await a5(e.background,{width:t.width,height:t.height,x:0,y:0,...a6({width:t.width,height:t.height},{width:n.width,height:n.height})});i={...i,"background-image":`url(${r})`}}return la("g",{className:"page",style:{...i,background:e.background}},la("rect",{x:0,y:0,width:t.width,height:t.height,fill:e.background}),...r)}async function lf({json:e,elementHook:t}){let n=await Promise.all(e.pages.map(n=>lh({page:n,store:e,elementHook:t}))),r=[];e.pages.forEach(e=>{e.children.forEach(e=>{"text"===e.type&&-1===r.indexOf(e.fontFamily)&&r.push(e.fontFamily)})});let i=r.map(t=>e.fonts.find(e=>e.fontFamily===t)?la("style",{},""):la("link",{href:`https://fonts.googleapis.com/css?family=${t}`,rel:"stylesheet"}));return la("svg",{xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink",viewBox:`0 0 ${e.width} ${e.height}`,preserveAspectRatio:"xMidYMin slice"},...i,...n)}let lp=(e,t)=>"object"==typeof t?`${e}="${Object.keys(t).map(e=>`${e}:${t[e]};`).join(" ")}"`:`${e}="${t}"`,lg=({dom:e})=>"string"==typeof e?e:e?`<${e.type} ${Object.keys(e.props).map(t=>lp(t,e.props[t])).join(" ")}>${e.children.map(e=>lg({dom:e})).join("")}</${e.type}>
113
- `:"";async function lm({json:e,elementHook:t}){return lg({dom:await lf({json:e,elementHook:t})})}var iU=f("58B0H");let lv=(0,iU.types).model("Page",{id:iU.types.identifier,children:(0,iU.types).array((0,iU.types).late(()=>lL)),width:(0,iU.types).optional((0,iU.types).union(iU.types.number,(0,iU.types).literal("auto")),"auto"),height:(0,iU.types).optional((0,iU.types).union(iU.types.number,(0,iU.types).literal("auto")),"auto"),background:"white",bleed:0,custom:(0,iU.types).frozen(),duration:5e3,_exporting:!1,_rendering:!1}).postProcessSnapshot(e=>{let t={...e},n={};for(var r in t)"_"!==r[0]&&(n[r]=e[r]);return n}).views(e=>({get store(){return(0,iU.getParentOfType)(e,lb)},get startTime(){let t=0;for(let n of e.store.pages){if(n.id===e.id)break;t+=n.duration}return t}})).views(e=>({get computedWidth(){if("auto"===e.width)return e.store.width;return e.width},get computedHeight(){if("auto"===e.height)return e.store.height;return e.height}})).actions(e=>({toJSON:()=>JSON.parse(JSON.stringify((0,iU.getSnapshot)(e))),_forEachElementUp(t,n){let r=t.map(t=>({id:t,index:e.children.findIndex(e=>e.id===t)}));for(let{index:i}of(r.sort((e,t)=>t.index-e.index),r)){if(-1==i)continue;let r=i<e.children.length-1&&e.children[i+1],o=t.indexOf(r?.id)>=0;i===e.children.length-1||o||n(i)}},_forEachElementDown(t,n){let r=t.map(t=>({id:t,index:e.children.findIndex(e=>e.id===t)}));for(let{index:i}of(r.sort((e,t)=>e.index-t.index),r)){if(-1==i)continue;let r=i>0&&e.children[i-1],o=t.indexOf(r?.id)>=0;0===i||o||n(i)}return!1}})).actions(e=>({clone(t={}){let n=e.toJSON();n.children.forEach(e=>{e.id=aX(10),lj(e,e=>{e.id=aX(10)})});let r={...n,id:aX(10),...t},i=e.store.addPage(r),o=e.store.pages.indexOf(e);i.setZIndex(o+1),i.select()},setZIndex(t){e.store.setPageZIndex(e.id,t)},set(t){Object.assign(e,t)},select(){e.store.selectPage(e.id)},addElement(t,{skipSelect:n=!1}={}){let r=lD[t.type];if(!r){console.error("Can not find model with type "+t.type);return}t.children&&t.children.forEach(e=>{e.id=aX(10)});let i=r.create({id:aX(10),...t});return e.children.push(i),i.selectable&&!n&&e.store.selectElements([i.id]),i},canMoveElementsUp(t){let n=!1;return e._forEachElementUp(t,()=>{n=n||!0}),n},moveElementsUp(t){e._forEachElementUp(t,t=>{let n=e.children[t];(0,iU.detach)(n),e.children.splice(t+1,0,n)})},canMoveElementsTop(e){return this.canMoveElementsUp(e)},moveElementsTop(t){let n=[],r=[];e.children.forEach(e=>{t.indexOf(e.id)>=0?n.push(e):r.push(e)}),e.children.replace(r.concat(n))},canMoveElementsDown(t){let n=!1;return e._forEachElementDown(t,()=>{n=n||!0}),n},moveElementsDown(t){e._forEachElementDown(t,t=>{let n=e.children[t];(0,iU.detach)(n),e.children.splice(t-1,0,n)})},canMoveElementsBottom(e){return this.canMoveElementsDown(e)},moveElementsBottom(t){let n=[],r=[];e.children.forEach(e=>{t.indexOf(e.id)>=0?n.push(e):r.push(e)}),e.children.replace(n.concat(r))},setElementZIndex(t,n){let r=e.children.find(e=>e.id===t);r&&((0,iU.detach)(r),e.children.remove(r),e.children.splice(n,0,r))},setSize({width:t,height:n,useMagic:r,softChange:i}){if(r){let r=t/e.computedWidth,i=n/e.computedHeight,o=Math.min(r,i),a=Math.max(0,(t-e.computedWidth*o)/2),l=Math.max(0,(n-e.computedHeight*o)/2);lj(e,t=>{"group"!==t.type&&("image"===t.type&&t.x<1&&t.y<1&&t.width>=e.computedWidth-2&&t.height>=e.computedHeight-2?t.set({x:t.x*o,y:t.y*o,width:t.width*r,height:t.height*i,cropX:0,cropY:0,cropWidth:1,cropHeight:1}):(t.set({x:a+t.x*o,y:l+t.y*o,width:t.width*o,height:t.height*o}),"text"===t.type?t.set({fontSize:t.fontSize*o}):"figure"===t.type&&t.set({strokeWidth:t.strokeWidth*o})))})}i||(e.width=t),i||(e.height=n)}})).actions(e=>({moveElementUp(t){console.warn("page.moveElementUp(id) is deprecated. Please use page.moveElementsUp([id1, id2]) instead."),e.moveElementsUp([t])},moveElementDown(t){console.warn("page.moveElementDown(id) is deprecated. Please use page.moveElementsDown([id1, id2]) instead."),e.moveElementsDown([t])},moveElementTop(t){console.warn("page.moveElementTop(id) is deprecated. Please use page.moveElementsTop([id1, id2]) instead."),e.moveElementsTop([t])},moveElementBottom(t){console.warn("page.moveElementBottom(id) is deprecated. Please use page.moveElementsBottom([id1, id2]) instead."),e.moveElementsBottom([t])},play(){e.store.play({startTime:e.startTime,endTime:e.startTime+e.duration})}}));(0,iU.setLivelinessChecking)("ignore");let ly=(0,iU.types).model("Font",{fontFamily:iU.types.string,url:(0,iU.types).optional(iU.types.string,""),styles:(0,iU.types).frozen()}).preProcessSnapshot(e=>({...e,fontFamily:e.fontFamily||e.name})),lb=(0,iU.types).model("Store",{role:"",pages:(0,iU.types).array(lv),fonts:(0,iU.types).array(ly),width:1080,height:1080,currentTime:0,isPlaying:!1,scale:1,scaleToFit:1,unit:"px",dpi:72,bleedVisible:!1,rulesVisible:!1,openedSidePanel:"",custom:(0,iU.types).frozen(),selectedElementsIds:(0,iU.types).array(iU.types.string),animatedElementsIds:(0,iU.types).array(iU.types.string),history:(0,iU.types).optional(aQ,{targetPath:"../pages"}),_elementsPixelRatio:2,_activePageId:""}).views(e=>({get _bleedVisible(){return console.warn("store._bleedVisible is deprecated. Please use store.bleedVisible instead."),e.bleedVisible},get selectedElements(){return e.selectedElementsIds.map(t=>{for(let n of e.pages)for(let e of n.children)if(e.id===t)return e}).filter(e=>!!e)},get children(){return e.pages},get selectedShapes(){let t=[];return lj({children:e.selectedElements},e=>{"group"!==e.type&&t.push(e)}),t},get activePage(){return e.pages.slice().find(t=>t.id===e._activePageId)||(e.pages.length?e.pages[0]:null)},get duration(){let t=0;return e.pages.forEach(e=>{t+=e.duration}),t},get _hasCroppedImages(){return e.find(e=>"image"===e.type&&e._cropModeEnabled)},find(t){let n;return lj({children:e.pages},e=>{if(!n&&t(e))return n=e,!0}),n},getElementById:t=>e.find(e=>e.id===t)})).actions(e=>{let t=0,n=null;return{afterCreate(){e.history.canUndo},setCurrentTime(t){e.currentTime=t},play({animatedElementsIds:r=[],startTime:i=0,currentTime:o=0,endTime:a=e.duration}={}){o&&(console.warn("currentTime property of store.play() is deprecated. Please use startTime instead."),i=o),e.animatedElementsIds=(0,iU.cast)(r),e.currentTime=i,e.isPlaying=!0,t=Date.now(),n=a,requestAnimationFrame(e.seek)},checkActivePage(){for(let t of e.pages){if(e.currentTime>=t.startTime&&e.currentTime<t.startTime+t.duration){e.selectPage(t.id);break}t.duration}},seek(){if(!e.isPlaying)return;let r=Date.now(),i=r-t;t=r,e.currentTime+=i,e.checkActivePage();let o=n||e.duration;e.isPlaying&&e.currentTime<o?requestAnimationFrame(e.seek):e.stop()},stop(){e.isPlaying=!1,e.currentTime=0,e.animatedElementsIds=(0,iU.cast)([]),e.checkActivePage()}}}).actions(e=>({set(t){Object.assign(e,t)},setUnit({unit:t,dpi:n}){e.unit=t||e.unit,e.dpi=n||e.dpi},setRole(t){e.role=t},addPage(t){let n=lv.create({id:aX(10),...t});return e.pages.push(n),e._activePageId=n.id,n},selectPage(t){e._activePageId=t},selectElements(t){let n=t.map(t=>e.getElementById(t)).sort((e,t)=>e.page.children.indexOf(e)-e.page.children.indexOf(t)).filter(e=>!!e).map(e=>e.id);e.selectedElementsIds=(0,iU.cast)(n)},toggleBleed(t){e.bleedVisible=t??!e.bleedVisible},toggleRulers(t){e.rulesVisible=t??!e.rulesVisible},openSidePanel(t){e.openedSidePanel=t},setScale(t){e.scale=t},_setScaleToFit(t){e.scaleToFit=t},setElementsPixelRatio(t){e._elementsPixelRatio=t},setSize(t,n,r){e.pages.forEach(e=>{e.setSize({width:t,height:n,useMagic:r,softChange:!0})}),e.width=t,e.height=n},setPageZIndex(t,n){let r=e.pages.find(e=>e.id===t);r&&((0,iU.detach)(r),e.pages.remove(r),e.pages.splice(n,0,r))},deletePages(t){let n=e.pages.indexOf(e.activePage);t.forEach(t=>{let n=e.pages.find(e=>e.id===t);(0,iU.destroy)(n)});let r=Math.min(e.pages.length-1,n),i=e.pages[r];i&&(e._activePageId=i.id),e.selectedElementsIds=(0,iU.cast)(e.selectedElementsIds.filter(t=>e.getElementById(t)))},groupElements(t){let n=t.map(t=>e.getElementById(t));n.forEach(e=>{e&&(0,iU.detach)(e)});let r=e.activePage,i={id:aX(10),children:n,type:"group"};return r.children.push(i),e.selectedElementsIds=(0,iU.cast)([i.id]),i},ungroupElements(t){let n=t.map(t=>e.getElementById(t)),r=[];n.forEach(e=>{if(e&&"group"===e.type){let t=e.page,n=t.children.indexOf(e);e.children.forEach(e=>{r.push(e.id)}),e.children.forEach(e=>{(0,iU.detach)(e),t.children.push(e)}),t.children.splice(n,1)}}),e.selectedElementsIds=(0,iU.cast)(r)},deleteElements(t){t.forEach(t=>{e.pages.forEach(e=>{let n=e.children.find(e=>e.id===t);n&&(0,iU.destroy)(n)})}),e.selectedElementsIds=(0,iU.cast)(e.selectedElementsIds.filter(t=>e.getElementById(t)))},on(t,n){if("change"===t){let t=e.toJSON();return(0,iU.onSnapshot)(e,r=>{let i=e.toJSON();aZ(t,i)||(t=i,n(i))})}},async _toCanvas({pixelRatio:t,ignoreBackground:n,pageId:r,mimeType:i,includeBleed:o}={}){let a=t||1;r=r||e.pages[0]?.id;let l=e.pages.find(e=>e.id===r);if(!l)throw Error(`No page for export with id ${r}`);l?.set({_exporting:!0});let u=await a1(()=>s(N).stages.find(e=>e.getAttr("pageId")===r));if(!u)throw Error(`Export is failed. Can not find stage for page ${r}. Looks like <Workspace /> component is not mounted, but it is required in order to process the export.`);let c=!!u.findOne(".page-container"),d=e._elementsPixelRatio;a>e._elementsPixelRatio&&e.setElementsPixelRatio(a),await e.waitLoading();let h=u.findOne(".page-container");if(!h)throw Error(`Export is failed. Can't find page container. ${c}`);u.find("Transformer").forEach(e=>e.visible(!1)),h.find(".page-background").forEach(e=>e.shadowEnabled(!1)),h.find(".page-background").forEach(e=>e.strokeEnabled(!1)),h.find(".highlighter").forEach(e=>e.visible(!1));let f=h.findOne(".page-background-group"),p=f.clip();f.clip({x:null,y:null,width:null,height:null});let g=h.findOne(".elements-container"),m=g.clip();g.clip({x:null,y:null,width:null,height:null});let v=h.find(e=>e.getAttr("hideInExport"));v.forEach(e=>{e.setAttr("oldVisible",e.visible()),e.hide()});let y=h.find(e=>!e.visible()&&e.getAttr("editModeEnabled"));y.forEach(e=>{e.setAttr("oldVisible",e.visible()),e.show()}),n&&h.find(".page-background").forEach(e=>e.hide());let b=o?l.bleed:0,w=b;!e.bleedVisible&&o||(e.bleedVisible||o?e.bleedVisible&&o?w=0:e.bleedVisible&&!o&&(w=-l.bleed):w=0);let x=document.createElement("canvas");x.width=Math.round((l.computedWidth+2*b)*a),x.height=Math.round((l.computedHeight+2*b)*a);let _=x.getContext("2d");"image/jpeg"===i&&(_.fillStyle="white",_.fillRect(0,0,x.width,x.height));let E=h.scale();h.scale({x:1,y:1});let S=h.toCanvas({x:h.x()-w,y:h.y()-w,width:l.computedWidth+2*b,height:l.computedHeight+2*b,pixelRatio:a});return h.scale(E),_.drawImage(S,0,0,x.width,x.height),s(N).Util.releaseCanvas(S),n&&h.find(".page-background").forEach(e=>e.show()),v.forEach(e=>{e.visible(e.getAttr("oldVisible"))}),y.forEach(e=>{e.visible(e.getAttr("oldVisible"))}),h.find(".page-background").forEach(e=>e.shadowEnabled(!0)),h.find(".page-background").forEach(e=>e.strokeEnabled(!0)),u.find("Transformer").forEach(e=>e.visible(!0)),h.find(".highlighter").forEach(e=>e.visible(!0)),f.clip(p),g.clip(m),e.setElementsPixelRatio(d),l?.set({_exporting:!1}),x},async toDataURL({pixelRatio:t,ignoreBackground:n,pageId:r,mimeType:i,includeBleed:o,quality:a}={}){let l=await e._toCanvas({pixelRatio:t,ignoreBackground:n,pageId:r,mimeType:i,includeBleed:o}),u=l.toDataURL(i,a);return s(N).Util.releaseCanvas(l),u},async toBlob({pixelRatio:t,ignoreBackground:n,pageId:r,mimeType:i,includeBleed:o,quality:a}={}){let l=await e._toCanvas({pixelRatio:t,ignoreBackground:n,pageId:r,mimeType:i,includeBleed:o}),u=new Promise(e=>{l.toBlob(e,i,a)});return s(N).Util.releaseCanvas(l),u},async saveAsImage({fileName:t,...n}={}){let r=n.mimeType||"image/png",i=r.split("/")[1];aJ(await e.toDataURL(n),t||"polotno."+i,r)},async _toPDF(n){let r=n.dpi||e.dpi,i=n.parallel||1,o=n.unit||("px"===e.unit?"mm":e.unit),a=n.pixelRatio||1,l=n.pageIds||e.pages.map(e=>e.id),s=e.pages.filter(e=>l.includes(e.id)),u=await (t?Promise.resolve(t):new Promise(e=>{var n=document.createElement("script");n.onload=function(){e(t=window.jspdf.jsPDF)},n.src="https://unpkg.com/jspdf@2.2.0/dist/jspdf.umd.min.js",document.head.appendChild(n)})),c=e=>aP({px:e,unit:o,dpi:r}),d=c(n.cropMarkSize||0),h=s[0]||{},f=n.includeBleed?h.bleed:0,p=c(h.computedWidth+2*f)+2*d,g=c(h.computedHeight+2*f)+2*d;var m=new u({unit:o,orientation:p>g?"landscape":"portrait",format:[p,g],compress:!0,putOnlyUsedFonts:!0});for(let t of(m.deletePage(1),((e,t)=>{for(var n=[],r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n})(s,i))){let r=t.map(async t=>{let r=n.includeBleed?t.bleed:0,i=c(t.computedWidth+2*r)+2*d,o=c(t.computedHeight+2*r)+2*d,l=0,s=a;for(;l<10;){2===(l+=1)&&console.error("Polotno can not export PDF with current settings. Quality is automatically reduced.");let r=await e.toDataURL({...n,pageId:t.id,pixelRatio:s});if(r.length>20)return{url:r,width:i,height:o};s*=.8}});(await Promise.all(r)).forEach(({url:e,width:t,height:n})=>{m.addPage([t,n],t>n?"landscape":"portrait"),d&&(m.setLineWidth(c(1)),m.line(2*d,0,2*d,d),m.line(0,2*d,d,2*d),m.line(t-2*d,0,t-2*d,d),m.line(t,2*d,t-d,2*d),m.line(0,n-2*d,d,n-2*d),m.line(2*d,n,2*d,n-d),m.line(t,n-2*d,t-d,n-2*d),m.line(t-2*d,n,t-2*d,n-d)),m.addImage(e,d,d,t-2*d,n-2*d,void 0,"FAST")})}return m},toPDFDataURL:async t=>(await e._toPDF({mimeType:"image/jpeg",...t})).output("datauristring"),async toGIFDataURL(t={}){let n=t.pixelRatio||1,r=await a0({width:e.width*n,height:e.height*n}),i=1e3/(t.fps||10),o=e.duration/i;for(let t=0;t<o-1;t++){let o=t*i||1;e.setCurrentTime(o);let a=0,l="";for(let t of e.pages)if(a+=t.duration,t.set({_rendering:a>o}),a>o){l=t.id;break}let s=await e._toCanvas({pixelRatio:n,pageId:l});r.addFrame(s.getContext("2d"),{delay:i,copy:!0})}for(let t of e.pages)t.set({_rendering:!1});return e.stop(),r.render(),new Promise(e=>{r.on("finished",function(t){var n;(n=new FileReader).onload=function(t){e(t.target.result)},n.readAsDataURL(t)})})},async saveAsGIF({fileName:t,...n}={}){aJ(await e.toGIFDataURL(n),t||"polotno.gif")},toHTML:async({elementHook:t}={elementHook:void 0})=>lo({json:e.toJSON(),elementHook:t}),async saveAsHTML({fileName:t}={}){let n=await e.toHTML();aJ("data:text/html;base64,"+window.btoa(unescape(encodeURIComponent(n))),t||"polotno.html")},toSVG:async()=>lm({json:e.toJSON()}),async saveAsSVG({fileName:t}={}){let n=await e.toSVG();aJ("data:text/svg;base64,"+window.btoa(unescape(encodeURIComponent(n))),t||"polotno.svg")},async saveAsPDF({fileName:t,...n}={}){(await e._toPDF({mimeType:"image/jpeg",...n})).save(t||"polotno.pdf")},async waitLoading(){await new Promise(e=>setTimeout(e,50)),await new Promise(e=>{var t;return t=()=>{ic()?setTimeout(e,300):e(!0)},void(0===ih?t():ip.push(t))})},toJSON:()=>({width:e.width,height:e.height,fonts:(0,iU.getSnapshot)(e.fonts),pages:(0,iU.getSnapshot)(e.pages),unit:e.unit,dpi:e.dpi,custom:e.custom}),loadJSON(t,n=!1){let r={...t},i=e.pages.indexOf(e.activePage),o=(r.pages[i]||r.pages[0])?.id;r._activePageId=o;let a={...(0,iU.getSnapshot)(e)};Object.assign(a,r),n?a.history=e.history.toJSON():a.history={history:[],undoIdx:-1},(0,iU.applySnapshot)(e,a)},clear({keepHistory:t=!1}={}){let n=e.pages.map(e=>e.id);e.deletePages(n),t||e.history.clear()},addFont(t){e.removeFont(t.fontFamily),e.fonts.push(t),e.loadFont(t.fontFamily)},removeFont(t){e.fonts.filter(e=>e.fontFamily===t).forEach(e=>(0,iU.destroy)(e))},async loadFont(t){let n=e.fonts.find(e=>e.fontFamily===t)||iE.find(e=>e.fontFamily===t);n?function(e){let t=e.fontFamily;if(iA[t]||!e.url&&!e.styles)return;let n=document.createElement("style");n.type="text/css";let r=e.styles||(e.url?[{src:`url("${e.url}")`}]:[]),i="";r.forEach(e=>{i+=`
113
+ `:"";async function lm({json:e,elementHook:t}){return lg({dom:await lf({json:e,elementHook:t})})}var iU=f("58B0H");let lv=(0,iU.types).model("Page",{id:iU.types.identifier,children:(0,iU.types).array((0,iU.types).late(()=>lL)),width:(0,iU.types).optional((0,iU.types).union(iU.types.number,(0,iU.types).literal("auto")),"auto"),height:(0,iU.types).optional((0,iU.types).union(iU.types.number,(0,iU.types).literal("auto")),"auto"),background:"white",bleed:0,custom:(0,iU.types).frozen(),duration:5e3,_exporting:!1,_rendering:!1}).postProcessSnapshot(e=>{let t={...e},n={};for(var r in t)"_"!==r[0]&&(n[r]=e[r]);return n}).views(e=>({get store(){return(0,iU.getParentOfType)(e,lb)},get startTime(){let t=0;for(let n of e.store.pages){if(n.id===e.id)break;t+=n.duration}return t}})).views(e=>({get computedWidth(){if("auto"===e.width)return e.store.width;return e.width},get computedHeight(){if("auto"===e.height)return e.store.height;return e.height}})).actions(e=>({toJSON:()=>JSON.parse(JSON.stringify((0,iU.getSnapshot)(e))),_forEachElementUp(t,n){let r=t.map(t=>({id:t,index:e.children.findIndex(e=>e.id===t)}));for(let{index:i}of(r.sort((e,t)=>t.index-e.index),r)){if(-1==i)continue;let r=i<e.children.length-1&&e.children[i+1],o=t.indexOf(r?.id)>=0;i===e.children.length-1||o||n(i)}},_forEachElementDown(t,n){let r=t.map(t=>({id:t,index:e.children.findIndex(e=>e.id===t)}));for(let{index:i}of(r.sort((e,t)=>e.index-t.index),r)){if(-1==i)continue;let r=i>0&&e.children[i-1],o=t.indexOf(r?.id)>=0;0===i||o||n(i)}return!1}})).actions(e=>({clone(t={}){let n=e.toJSON();n.children.forEach(e=>{e.id=aX(10),lj(e,e=>{e.id=aX(10)})});let r={...n,id:aX(10),...t},i=e.store.addPage(r),o=e.store.pages.indexOf(e);i.setZIndex(o+1),i.select()},setZIndex(t){e.store.setPageZIndex(e.id,t)},set(t){Object.assign(e,t)},select(){e.store.selectPage(e.id)},addElement(t,{skipSelect:n=!1}={}){let r=lD[t.type];if(!r){console.error("Can not find model with type "+t.type);return}t.children&&t.children.forEach(e=>{e.id=aX(10)});let i=r.create({id:aX(10),...t});return e.children.push(i),i.selectable&&!n&&e.store.selectElements([i.id]),i},canMoveElementsUp(t){let n=!1;return e._forEachElementUp(t,()=>{n=n||!0}),n},moveElementsUp(t){e._forEachElementUp(t,t=>{let n=e.children[t];(0,iU.detach)(n),e.children.splice(t+1,0,n)})},canMoveElementsTop(e){return this.canMoveElementsUp(e)},moveElementsTop(t){let n=[],r=[];e.children.forEach(e=>{t.indexOf(e.id)>=0?n.push(e):r.push(e)}),e.children.replace(r.concat(n))},canMoveElementsDown(t){let n=!1;return e._forEachElementDown(t,()=>{n=n||!0}),n},moveElementsDown(t){e._forEachElementDown(t,t=>{let n=e.children[t];(0,iU.detach)(n),e.children.splice(t-1,0,n)})},canMoveElementsBottom(e){return this.canMoveElementsDown(e)},moveElementsBottom(t){let n=[],r=[];e.children.forEach(e=>{t.indexOf(e.id)>=0?n.push(e):r.push(e)}),e.children.replace(n.concat(r))},setElementZIndex(t,n){let r=e.children.find(e=>e.id===t);r&&((0,iU.detach)(r),e.children.remove(r),e.children.splice(n,0,r))},setSize({width:t,height:n,useMagic:r,softChange:i}){if(r){let r=t/e.computedWidth,i=n/e.computedHeight,o=Math.min(r,i),a=Math.max(0,(t-e.computedWidth*o)/2),l=Math.max(0,(n-e.computedHeight*o)/2);lj(e,t=>{"group"!==t.type&&("image"===t.type&&t.x<1&&t.y<1&&t.width>=e.computedWidth-2&&t.height>=e.computedHeight-2?t.set({x:t.x*o,y:t.y*o,width:t.width*r,height:t.height*i,cropX:0,cropY:0,cropWidth:1,cropHeight:1}):(t.set({x:a+t.x*o,y:l+t.y*o,width:t.width*o,height:t.height*o}),"text"===t.type?t.set({fontSize:t.fontSize*o}):"figure"===t.type&&t.set({strokeWidth:t.strokeWidth*o})))})}i||(e.width=t),i||(e.height=n)}})).actions(e=>({moveElementUp(t){console.warn("page.moveElementUp(id) is deprecated. Please use page.moveElementsUp([id1, id2]) instead."),e.moveElementsUp([t])},moveElementDown(t){console.warn("page.moveElementDown(id) is deprecated. Please use page.moveElementsDown([id1, id2]) instead."),e.moveElementsDown([t])},moveElementTop(t){console.warn("page.moveElementTop(id) is deprecated. Please use page.moveElementsTop([id1, id2]) instead."),e.moveElementsTop([t])},moveElementBottom(t){console.warn("page.moveElementBottom(id) is deprecated. Please use page.moveElementsBottom([id1, id2]) instead."),e.moveElementsBottom([t])},play(){e.store.play({startTime:e.startTime,endTime:e.startTime+e.duration})}}));(0,iU.setLivelinessChecking)("ignore");let ly=(0,iU.types).model("Font",{fontFamily:iU.types.string,url:(0,iU.types).optional(iU.types.string,""),styles:(0,iU.types).frozen()}).preProcessSnapshot(e=>({...e,fontFamily:e.fontFamily||e.name})),lb=(0,iU.types).model("Store",{role:"",pages:(0,iU.types).array(lv),fonts:(0,iU.types).array(ly),width:1080,height:1080,currentTime:0,isPlaying:!1,scale:1,scaleToFit:1,unit:"px",dpi:72,bleedVisible:!1,rulesVisible:!1,openedSidePanel:"",custom:(0,iU.types).frozen(),selectedElementsIds:(0,iU.types).array(iU.types.string),animatedElementsIds:(0,iU.types).array(iU.types.string),history:(0,iU.types).optional(aQ,{targetPath:"../pages"}),_elementsPixelRatio:2,_activePageId:""}).views(e=>({get _bleedVisible(){return console.warn("store._bleedVisible is deprecated. Please use store.bleedVisible instead."),e.bleedVisible},get selectedElements(){return e.selectedElementsIds.map(t=>{for(let n of e.pages)for(let e of n.children)if(e.id===t)return e}).filter(e=>!!e)},get children(){return e.pages},get selectedShapes(){let t=[];return lj({children:e.selectedElements},e=>{"group"!==e.type&&t.push(e)}),t},get activePage(){return e.pages.slice().find(t=>t.id===e._activePageId)||(e.pages.length?e.pages[0]:null)},get duration(){let t=0;return e.pages.forEach(e=>{t+=e.duration}),t},get _hasCroppedImages(){return e.find(e=>"image"===e.type&&e._cropModeEnabled)},find(t){let n;return lj({children:e.pages},e=>{if(!n&&t(e))return n=e,!0}),n},getElementById:t=>e.find(e=>e.id===t)})).actions(e=>{let t=0,n=null;return{afterCreate(){e.history.canUndo},setCurrentTime(t){e.currentTime=t},play({animatedElementsIds:r=[],startTime:i=0,currentTime:o=0,endTime:a=e.duration}={}){o&&(console.warn("currentTime property of store.play() is deprecated. Please use startTime instead."),i=o),e.animatedElementsIds=(0,iU.cast)(r),e.currentTime=i,e.isPlaying=!0,t=Date.now(),n=a,requestAnimationFrame(e.seek)},checkActivePage(){for(let t of e.pages){if(e.currentTime>=t.startTime&&e.currentTime<t.startTime+t.duration){e.selectPage(t.id);break}t.duration}},seek(){if(!e.isPlaying)return;let r=Date.now(),i=r-t;t=r,e.currentTime+=i,e.checkActivePage();let o=n||e.duration;e.isPlaying&&e.currentTime<o?requestAnimationFrame(e.seek):e.stop()},stop(){e.isPlaying=!1,e.currentTime=0,e.animatedElementsIds=(0,iU.cast)([]),e.checkActivePage()}}}).actions(e=>({set(t){Object.assign(e,t)},setUnit({unit:t,dpi:n}){e.unit=t||e.unit,e.dpi=n||e.dpi},setRole(t){e.role=t},addPage(t){let n=lv.create({id:aX(10),...t});return e.pages.push(n),e._activePageId=n.id,n},selectPage(t){e._activePageId=t},selectElements(t){let n=t.map(t=>e.getElementById(t)).sort((e,t)=>e.page.children.indexOf(e)-e.page.children.indexOf(t)).filter(e=>!!e).map(e=>e.id);e.selectedElementsIds=(0,iU.cast)(n)},toggleBleed(t){e.bleedVisible=t??!e.bleedVisible},toggleRulers(t){e.rulesVisible=t??!e.rulesVisible},openSidePanel(t){e.openedSidePanel=t},setScale(t){e.scale=t},_setScaleToFit(t){e.scaleToFit=t},setElementsPixelRatio(t){e._elementsPixelRatio=t},setSize(t,n,r){e.pages.forEach(e=>{e.setSize({width:t,height:n,useMagic:r,softChange:!0})}),e.width=t,e.height=n},setPageZIndex(t,n){let r=e.pages.find(e=>e.id===t);r&&((0,iU.detach)(r),e.pages.remove(r),e.pages.splice(n,0,r))},deletePages(t){let n=e.pages.indexOf(e.activePage);t.forEach(t=>{let n=e.pages.find(e=>e.id===t);(0,iU.destroy)(n)});let r=Math.min(e.pages.length-1,n),i=e.pages[r];i&&(e._activePageId=i.id),e.selectedElementsIds=(0,iU.cast)(e.selectedElementsIds.filter(t=>e.getElementById(t)))},groupElements(t){let n=t.map(t=>e.getElementById(t));n.forEach(e=>{e&&(0,iU.detach)(e)});let r=e.activePage,i={id:aX(10),children:n,type:"group"};return r.children.push(i),e.selectedElementsIds=(0,iU.cast)([i.id]),i},ungroupElements(t){let n=t.map(t=>e.getElementById(t)),r=[];n.forEach(e=>{if(e&&"group"===e.type){let t=e.page,n=t.children.indexOf(e);e.children.forEach(e=>{r.push(e.id)}),e.children.forEach(e=>{(0,iU.detach)(e),t.children.push(e)}),t.children.splice(n,1)}}),e.selectedElementsIds=(0,iU.cast)(r)},deleteElements(t){t.forEach(t=>{e.pages.forEach(e=>{let n=e.children.find(e=>e.id===t);n&&(0,iU.destroy)(n)})}),e.selectedElementsIds=(0,iU.cast)(e.selectedElementsIds.filter(t=>e.getElementById(t)))},on(t,n){if("change"===t){let t=e.toJSON();return(0,iU.onSnapshot)(e,r=>{let i=e.toJSON();aZ(t,i)||(t=i,n(i))})}},async _toCanvas({pixelRatio:t,ignoreBackground:n,pageId:r,mimeType:i,includeBleed:o}={}){let a=t||1;r=r||e.pages[0]?.id;let l=e.pages.find(e=>e.id===r);if(!l)throw Error(`No page for export with id ${r}`);l?.set({_exporting:!0});let u=await a1(()=>s(N).stages.find(e=>e.getAttr("pageId")===r));if(!u)throw Error(`Export is failed. Can not find stage for page ${r}. Looks like <Workspace /> component is not mounted, but it is required in order to process the export.`);let c=!!u.findOne(".page-container"),d=e._elementsPixelRatio;a>e._elementsPixelRatio&&e.setElementsPixelRatio(a),await e.waitLoading();let h=u.findOne(".page-container");if(!h)throw e.setElementsPixelRatio(d),Error(`Export is failed. Can't find page container. ${c}`);u.find("Transformer").forEach(e=>e.visible(!1)),h.find(".page-background").forEach(e=>e.shadowEnabled(!1)),h.find(".page-background").forEach(e=>e.strokeEnabled(!1)),h.find(".highlighter").forEach(e=>e.visible(!1));let f=h.findOne(".page-background-group"),p=f.clip();f.clip({x:null,y:null,width:null,height:null});let g=h.findOne(".elements-container"),m=g.clip();g.clip({x:null,y:null,width:null,height:null});let v=h.find(e=>e.getAttr("hideInExport"));v.forEach(e=>{e.setAttr("oldVisible",e.visible()),e.hide()});let y=h.find(e=>!e.visible()&&e.getAttr("editModeEnabled"));y.forEach(e=>{e.setAttr("oldVisible",e.visible()),e.show()}),n&&h.find(".page-background").forEach(e=>e.hide());let b=o?l.bleed:0,w=b;!e.bleedVisible&&o||(e.bleedVisible||o?e.bleedVisible&&o?w=0:e.bleedVisible&&!o&&(w=-l.bleed):w=0);let x=document.createElement("canvas");x.width=Math.round((l.computedWidth+2*b)*a),x.height=Math.round((l.computedHeight+2*b)*a);let _=x.getContext("2d");"image/jpeg"===i&&(_.fillStyle="white",_.fillRect(0,0,x.width,x.height));let E=h.scale();h.scale({x:1,y:1});let S=h.toCanvas({x:h.x()-w,y:h.y()-w,width:l.computedWidth+2*b,height:l.computedHeight+2*b,pixelRatio:a});return h.scale(E),_.drawImage(S,0,0,x.width,x.height),s(N).Util.releaseCanvas(S),n&&h.find(".page-background").forEach(e=>e.show()),v.forEach(e=>{e.visible(e.getAttr("oldVisible"))}),y.forEach(e=>{e.visible(e.getAttr("oldVisible"))}),h.find(".page-background").forEach(e=>e.shadowEnabled(!0)),h.find(".page-background").forEach(e=>e.strokeEnabled(!0)),u.find("Transformer").forEach(e=>e.visible(!0)),h.find(".highlighter").forEach(e=>e.visible(!0)),f.clip(p),g.clip(m),e.setElementsPixelRatio(d),l?.set({_exporting:!1}),x},async toDataURL({pixelRatio:t,ignoreBackground:n,pageId:r,mimeType:i,includeBleed:o,quality:a}={}){let l=await e._toCanvas({pixelRatio:t,ignoreBackground:n,pageId:r,mimeType:i,includeBleed:o}),u=l.toDataURL(i,a);return s(N).Util.releaseCanvas(l),u},async toBlob({pixelRatio:t,ignoreBackground:n,pageId:r,mimeType:i,includeBleed:o,quality:a}={}){let l=await e._toCanvas({pixelRatio:t,ignoreBackground:n,pageId:r,mimeType:i,includeBleed:o}),u=new Promise(e=>{l.toBlob(e,i,a)});return s(N).Util.releaseCanvas(l),u},async saveAsImage({fileName:t,...n}={}){let r=n.mimeType||"image/png",i=r.split("/")[1];aJ(await e.toDataURL(n),t||"polotno."+i,r)},async _toPDF(n){let r=n.dpi||e.dpi,i=n.parallel||1,o=n.unit||("px"===e.unit?"mm":e.unit),a=n.pixelRatio||1,l=n.pageIds||e.pages.map(e=>e.id),s=e.pages.filter(e=>l.includes(e.id)),u=await (t?Promise.resolve(t):new Promise(e=>{var n=document.createElement("script");n.onload=function(){e(t=window.jspdf.jsPDF)},n.src="https://unpkg.com/jspdf@2.2.0/dist/jspdf.umd.min.js",document.head.appendChild(n)})),c=e=>aP({px:e,unit:o,dpi:r}),d=c(n.cropMarkSize||0),h=s[0]||{},f=n.includeBleed?h.bleed:0,p=c(h.computedWidth+2*f)+2*d,g=c(h.computedHeight+2*f)+2*d;var m=new u({unit:o,orientation:p>g?"landscape":"portrait",format:[p,g],compress:!0,putOnlyUsedFonts:!0});for(let t of(m.deletePage(1),((e,t)=>{for(var n=[],r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n})(s,i))){let r=t.map(async t=>{let r=n.includeBleed?t.bleed:0,i=c(t.computedWidth+2*r)+2*d,o=c(t.computedHeight+2*r)+2*d,l=0,s=a;for(;l<10;){2===(l+=1)&&console.error("Polotno can not export PDF with current settings. Quality is automatically reduced.");let r=await e.toDataURL({...n,pageId:t.id,pixelRatio:s});if(r.length>20)return{url:r,width:i,height:o};s*=.8}});(await Promise.all(r)).forEach(({url:e,width:t,height:n})=>{m.addPage([t,n],t>n?"landscape":"portrait"),d&&(m.setLineWidth(c(1)),m.line(2*d,0,2*d,d),m.line(0,2*d,d,2*d),m.line(t-2*d,0,t-2*d,d),m.line(t,2*d,t-d,2*d),m.line(0,n-2*d,d,n-2*d),m.line(2*d,n,2*d,n-d),m.line(t,n-2*d,t-d,n-2*d),m.line(t-2*d,n,t-2*d,n-d)),m.addImage(e,d,d,t-2*d,n-2*d,void 0,"FAST")})}return m},toPDFDataURL:async t=>(await e._toPDF({mimeType:"image/jpeg",...t})).output("datauristring"),async toGIFDataURL(t={}){let n=t.pixelRatio||1,r=await a0({width:e.width*n,height:e.height*n}),i=1e3/(t.fps||10),o=e.duration/i;for(let t=0;t<o-1;t++){let o=t*i||1;e.setCurrentTime(o);let a=0,l="";for(let t of e.pages)if(a+=t.duration,t.set({_rendering:a>o}),a>o){l=t.id;break}let s=await e._toCanvas({pixelRatio:n,pageId:l});r.addFrame(s.getContext("2d"),{delay:i,copy:!0})}for(let t of e.pages)t.set({_rendering:!1});return e.stop(),r.render(),new Promise(e=>{r.on("finished",function(t){var n;(n=new FileReader).onload=function(t){e(t.target.result)},n.readAsDataURL(t)})})},async saveAsGIF({fileName:t,...n}={}){aJ(await e.toGIFDataURL(n),t||"polotno.gif")},toHTML:async({elementHook:t}={elementHook:void 0})=>lo({json:e.toJSON(),elementHook:t}),async saveAsHTML({fileName:t}={}){let n=await e.toHTML();aJ("data:text/html;base64,"+window.btoa(unescape(encodeURIComponent(n))),t||"polotno.html")},toSVG:async()=>lm({json:e.toJSON()}),async saveAsSVG({fileName:t}={}){let n=await e.toSVG();aJ("data:text/svg;base64,"+window.btoa(unescape(encodeURIComponent(n))),t||"polotno.svg")},async saveAsPDF({fileName:t,...n}={}){(await e._toPDF({mimeType:"image/jpeg",...n})).save(t||"polotno.pdf")},async waitLoading(){await new Promise(e=>setTimeout(e,50)),await new Promise(e=>{var t;return t=()=>{ic()?setTimeout(e,300):e(!0)},void(0===ih?t():ip.push(t))})},toJSON:()=>({width:e.width,height:e.height,fonts:(0,iU.getSnapshot)(e.fonts),pages:(0,iU.getSnapshot)(e.pages),unit:e.unit,dpi:e.dpi,custom:e.custom}),loadJSON(t,n=!1){let r={...t},i=e.pages.indexOf(e.activePage),o=(r.pages[i]||r.pages[0])?.id;r._activePageId=o;let a={...(0,iU.getSnapshot)(e)};Object.assign(a,r),n?a.history=e.history.toJSON():a.history={history:[],undoIdx:-1},(0,iU.applySnapshot)(e,a)},clear({keepHistory:t=!1}={}){let n=e.pages.map(e=>e.id);e.deletePages(n),t||e.history.clear()},addFont(t){e.removeFont(t.fontFamily),e.fonts.push(t),e.loadFont(t.fontFamily)},removeFont(t){e.fonts.filter(e=>e.fontFamily===t).forEach(e=>(0,iU.destroy)(e))},async loadFont(t){let n=e.fonts.find(e=>e.fontFamily===t)||iE.find(e=>e.fontFamily===t);n?function(e){let t=e.fontFamily;if(iA[t]||!e.url&&!e.styles)return;let n=document.createElement("style");n.type="text/css";let r=e.styles||(e.url?[{src:`url("${e.url}")`}]:[]),i="";r.forEach(e=>{i+=`
114
114
  @font-face {
115
115
  font-family: '${t}';
116
116
  src: ${e.src};