polotno-node 2.4.1 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -231,6 +231,28 @@ const url = await instance.run(async (json) => {
231
231
  }, json);
232
232
  ```
233
233
 
234
+ ## Video export
235
+
236
+ **This part is currently under development and API will change.**
237
+
238
+ ```js
239
+ import { createInstance } from 'polotno-node';
240
+ import { jsonToVideo } from 'polotno/video';
241
+
242
+ // create working instance
243
+ const instance = await createInstance({
244
+ key: '...key...',
245
+ });
246
+
247
+ // load sample json
248
+ const json = JSON.parse(fs.readFileSync('./test-data/video.json'));
249
+ const page = await instance.createPage();
250
+
251
+ await jsonToVideo(page, json, { out: 'out.mp4' });
252
+
253
+ await instance.close();
254
+ ```
255
+
234
256
  ## Your own client
235
257
 
236
258
  By default `polotno-node` ships with the default Polotno Editor with its (hopefully) last version. If you use experimental API such as `unstable_registerShapeModel` and `unstable_registerShapeComponent`, the rendering may fail if you use unknown elements types.
@@ -86,7 +86,7 @@ For more info see: https://github.com/konvajs/react-konva/issues/194
86
86
  opacity: 0.6;
87
87
  }
88
88
  `;g.innerHTML="",g.appendChild(document.createTextNode(ne)),JSON.stringify(te)!==JSON.stringify(J)&&Z(te)});const U=i.default.useRef(null);i.default.useEffect(()=>{const te=setTimeout(()=>{var ne;const ce=U.current;if(!ce)return;(ne=U.current)===null||ne===void 0||ne.focus();const le=Y||ce.value.length;ce.selectionStart=ce.selectionEnd=le,B&&(ce==null||ce.select(),document.execCommand("selectAll",!1,null))});return()=>{clearTimeout(te)}},[]);let W=0;const X=K.textArr.length*K.lineHeight()*K.fontSize();P.verticalAlign==="middle"&&(W=(P.a.height-X)/2),P.verticalAlign==="bottom"&&(W=P.a.height-X);const ee=(0,w.removeTags)(P.text);return i.default.createElement(s.Html,null,i.default.createElement("textarea",{className:"polotno-input",ref:U,dir:L(ee),style:Object.assign(Object.assign(Object.assign({},M),J),{paddingTop:W+"px"}),value:ee,onChange:te=>{P.set({text:te.target.value})},placeholder:P.placeholder,onBlur:F}))}),A=R=>{const[P,F]=i.default.useState(!1),B=i.default.useRef(!1);return i.default.useEffect(()=>{var Y=!0;return setTimeout(()=>{Y&&(R._editModeEnabled&&(B.current=!0),F(!0),setTimeout(()=>{B.current=!1},50))},50),()=>{Y=!1}},[]),{editorEnabled:P&&R._editModeEnabled,selectAll:B.current}},z=(R,P)=>{const[F,B]=i.default.useReducer(J=>J+1,0),Y=i.default.useRef(!1);return Y.current=!!(0,d.isFontLoaded)(P),i.default.useLayoutEffect(()=>{if(Y.current)return;let J=!0;return(async()=>{Y.current=!1,B();const Z=(0,h.incrementLoader)(`text ${P}`);await R.loadFont(P),u.default.Util.requestAnimFrame(Z),J&&(Y.current=!0,B())})(),()=>{J=!1}},[P]),[Y.current]};e.useFontLoader=z;const I=({fontLoaded:R,fontFamily:P,fontSize:F,lineHeight:B})=>i.default.useMemo(()=>{if(typeof B=="number")return B;const Y=document.createElement("div");Y.style.fontFamily=P,Y.style.fontSize=F+"px",Y.style.lineHeight=B,Y.innerText="Test text",document.body.appendChild(Y);const J=Y.offsetHeight;return document.body.removeChild(Y),J/F},[R,P,F,B]);function H(R){var P=R.getAbsoluteTransform().copy();P.invert();var F=R.getStage().getPointerPosition();return P.point(F)}function N(R){var P;const F=R.target,B=H(F),Y=F.textArr,J=Math.floor(B.y/(F.fontSize()*F.lineHeight())),Z=Y.slice(0,J).reduce((W,X)=>W+X.text.length,J),K=(P=Y[J])!==null&&P!==void 0?P:Y[0];let U=0;return F.align()==="right"?U=F.width()-K.width:F.align()==="center"&&(U=F.width()/2-K.width/2),Z+Math.round((B.x-U)/K.width*K.text.length)}function G(R){const P=i.default.useRef(R),F=i.default.useRef(R);return i.default.useMemo(()=>{F.current=P.current,P.current=R},[R]),F.current}function D(R,P){const F=R.fontSize(),B=R.height(),Y=(0,w.removeTags)(P.text);let J=P.a.fontSize;R.height(void 0);const Z=Math.round(2*P.a.fontSize)-1;for(let K=1;K<Z;K++){const U=P.a.height&&R.height()>P.a.height,W=Y.split(`
89
- `).join(" ").split(/[\s-]+/);let X=R.textArr.map(te=>te.text).join(";");const ee=W.find(te=>!X.includes(te)||(X=X.replace(te,""),!1));if(!(U||ee))break;J-=.5,R.fontSize(J)}return R.fontSize(F),R.height(B),J}function q({lines:R,lineHeight:P,width:F,align:B="left",padding:Y=0,cornerRadius:J=0}){var Z;R.forEach((X,ee)=>{X.cx=F/2,B==="right"?X.cx=F-X.width/2:B==="left"&&(X.cx=X.width/2),B!=="justify"||X.lastInParagraph||(X.width=F),B==="justify"&&(X.cx=X.width/2)});let K=`M ${(Z=R[0])===null||Z===void 0?void 0:Z.cx} ${-Y}`;R.forEach((X,ee)=>{const{cx:te}=X,ne=R[ee-1];ne&&ne.width>X.width?K+=` L ${te+X.width/2+Y} ${ee*P+Y}`:K+=` L ${te+X.width/2+Y} ${ee*P-Y}`;const ce=R[ee+1];ce&&ce.width>X.width?K+=` L ${te+X.width/2+Y} ${(ee+1)*P-Y}`:K+=` L ${te+X.width/2+Y} ${(ee+1)*P+Y}`});for(var U=R.length-1;U>=0;U--){const X=R[U],{cx:ee}=X,te=R[U+1];te&&te.width>X.width?K+=` L ${ee-X.width/2-Y} ${(U+1)*P-Y}`:K+=` L ${ee-X.width/2-Y} ${(U+1)*P+Y}`;const ne=R[U-1];ne&&ne.width>X.width?K+=` L ${ee-X.width/2-Y} ${U*P+Y}`:K+=` L ${ee-X.width/2-Y} ${U*P-Y}`}K+=" Z";const W=(0,p.parsePath)(K);return(0,p.roundCommands)(W,J).path}e.getLineHeight=I,e.usePrevious=G;const V=R=>i.default.useMemo(()=>{if(!S.isGradient(R.fill))return{fill:R.fill};const{stops:P,rotation:F}=S.parseColor(R.fill),B={x:R.a.width/2,y:R.a.height/2},Y=Math.sqrt(Math.pow(B.x,2)+Math.pow(B.y,2)),J=u.default.Util.degToRad(F)-Math.PI/2,Z=[];return P.forEach(({offset:K,color:U})=>{Z.push(K,U)}),{fillLinearGradientStartPointX:B.x-Y*Math.cos(J),fillLinearGradientStartPointY:B.y-Y*Math.sin(J),fillLinearGradientColorStops:Z,fillLinearGradientEndPointX:B.x+Y*Math.cos(J),fillLinearGradientEndPointY:B.y+Y*Math.sin(J),fill:P[1].color,fillPriority:"linear-gradient"}},[R.fill]);e.useTextColor=V,e.TextElement=(0,o.observer)(({element:R,store:P})=>{const F=i.default.useRef(null),B=i.default.useRef(null),{editorEnabled:Y,selectAll:J}=A(R),[Z,K]=i.default.useState(!1),[U,W]=i.default.useState(!1),X=i.default.useRef(R.a.height),ee=P.selectedElements.indexOf(R)>=0,{textVerticalResizeEnabled:te}=E.flags,ne=G(R.fontFamily),[ce,le]=i.default.useState([]);i.default.useEffect(()=>{var ke,Ge;const lt=(Ge=(ke=F.current)===null||ke===void 0?void 0:ke.textArr)!==null&&Ge!==void 0?Ge:[];JSON.stringify(lt)!==JSON.stringify(ce)&&le(lt)}),i.default.useEffect(()=>{if(R.a.width)return;const ke=F.current;ke.width(600),R.set({width:1.4*ke.getTextWidth()})},[]),i.default.useLayoutEffect(()=>(0,c.autorun)(()=>{const ke=F.current;(0,_.applyFilter)(ke,R)}));const[Te]=(0,e.useFontLoader)(P,R.fontFamily),Ce=(0,w.removeTags)(R.text),se=()=>{const ke=F.current.clone({height:void 0}),Ge=Math.ceil(ke.fontSize()*ke.lineHeight()*ke.textArr.length+1);return ke.destroy(),Ge};i.default.useLayoutEffect(()=>{if(!Te)return;const{textOverflow:ke}=E.flags;if(R.a.height)if(ke!=="change-font-size"||U){if(ke==="resize"){const Ge=se();te&&R.a.height<Ge&&P.history.ignore(()=>{R.set({height:Ge}),F.current.height(Ge)}),te||R.a.height===Ge||P.history.ignore(()=>{R.set({height:Ge}),F.current.height(Ge)})}}else{const Ge=D(F.current,R);if(Ge!==R.a.fontSize)return void P.history.ignore(()=>{R.set({fontSize:Ge})});const lt=se();R.a.height===lt||te||P.history.ignore(()=>{R.set({height:lt})})}else{const Ge=se();P.history.ignore(()=>{R.set({height:Ge})})}}),i.default.useLayoutEffect(()=>{const ke=F.current;ke&&(ke.width(ke.width()+1e-8),ke._setTextData(),(0,_.applyFilter)(ke,R))},[Te]);const de=i.default.useRef(null),_e=i.default.useRef(0),Oe=ke=>{ke.evt.preventDefault(),P.selectedShapes.find(lt=>lt===R)&&R.contentEditable&&(_e.current=N(ke),R.toggleEditMode())},ae=!Ce&&R.placeholder?.6:R.a.opacity;(0,y.useFadeIn)(F,ae);const me=(0,e.getLineHeight)({fontLoaded:Te,fontFamily:R.fontFamily,fontSize:R.a.fontSize,lineHeight:R.lineHeight}),ve=R.selectable||P.role==="admin",ye=(0,e.useTextColor)(R),Ie=i.default.useMemo(()=>R.backgroundEnabled?q({lines:ce,cornerRadius:R.backgroundCornerRadius*(R.a.fontSize*me*.5),lineHeight:me*R.a.fontSize,padding:R.backgroundPadding*(R.a.fontSize*me*.5),width:R.a.width,align:R.align}):"",[R.backgroundEnabled,R.backgroundCornerRadius,R.a.fontSize,me,R.backgroundPadding,R.a.width,R.align,ce]),nt=(0,b.useMobile)();let Qe=0;return R.verticalAlign==="middle"?Qe=(R.a.height-ce.length*me*R.a.fontSize)/2:R.verticalAlign==="bottom"&&(Qe=R.a.height-ce.length*me*R.a.fontSize),i.default.createElement(i.default.Fragment,null,i.default.createElement(l.Path,{ref:B,x:R.a.x,y:R.a.y,rotation:R.a.rotation,hideInExport:!R.showInExport||!Ce,listening:!1,visible:R.backgroundEnabled,opacity:R.backgroundOpacity,data:Ie,fill:R.backgroundColor,offsetY:-Qe}),i.default.createElement(l.Text,Object.assign({ref:F,id:R.id,name:"element",hideInExport:!R.showInExport||!Ce,editModeEnabled:R._editModeEnabled,x:R.a.x,y:R.a.y,rotation:R.a.rotation,width:R.a.width,height:R.a.height,text:Ce||R.placeholder},ye,{stroke:R.stroke,lineJoin:"round",strokeWidth:R.strokeWidth,fillAfterStrokeEnabled:!0,fontSize:R.a.fontSize,fontFamily:`"${R.fontFamily}", "${ne}"`,fontStyle:R.fontStyle+" "+R.fontWeight,textDecoration:R.textDecoration,align:R.align,verticalAlign:R.verticalAlign,draggable:nt?R.draggable&&ee:R.draggable,preventDefault:!nt||ee,opacity:ae,visible:!R._editModeEnabled,ellipsis:E.flags.textOverflow==="ellipsis",shadowEnabled:R.shadowEnabled,shadowBlur:R.shadowBlur,shadowOffsetX:R.shadowOffsetX,shadowOffsetY:R.shadowOffsetY,shadowColor:R.shadowColor,shadowOpacity:R.shadowOpacity,lineHeight:me,letterSpacing:R.letterSpacing*R.a.fontSize,listening:ve,onDragStart:()=>{P.history.startTransaction()},onDragMove:ke=>{R.set({x:ke.target.x(),y:ke.target.y()})},onDragEnd:ke=>{R.set({x:ke.target.x(),y:ke.target.y()}),P.history.endTransaction()},onMouseEnter:()=>{K(!0)},onMouseLeave:()=>{K(!1)},onClick:Oe,onTap:Oe,onTransformStart:()=>{W(!0),P.history.startTransaction(),X.current=F.current.height()},onTransform:ke=>{var Ge,lt;const st=ke.target;(Ge=B.current)===null||Ge===void 0||Ge.setAttrs({x:st.x(),y:st.y(),rotation:st.rotation(),scale:st.scale()});const ie=((lt=st.getStage())===null||lt===void 0?void 0:lt.findOne("Transformer")).getActiveAnchor();if(ie==="middle-left"||ie==="middle-right"){const fe=st.scaleX(),He=st.width()*fe,we=R.a.fontSize;let Ke=He;He<we&&(Ke=we,de.current&&st.position(de.current)),st.width(Ke),st.scaleX(1),st.scaleY(1);const Se=se();if(E.flags.textOverflow!=="ellipsis"){const et=Math.max(Se,X.current);st.height(et),R.set({height:st.height()})}R.set({x:st.x(),y:st.y(),width:st.width(),rotation:st.rotation()}),(0,_.applyFilter)(st,R)}if(ie==="top-center"||ie==="bottom-center"){let fe=E.flags.textOverflow==="resize"?se():me*R.a.fontSize;ke.target.height(Math.max(fe,ke.target.height()*ke.target.scaleY())),ke.target.scaleY(1)}ke.target.strokeWidth(R.strokeWidth/ke.target.scaleX()),de.current=ke.target.position()},onTransformEnd:ke=>{var Ge;const lt=ke.target.scaleX();ke.target.scaleX(1),ke.target.scaleY(1),ke.target.strokeWidth(R.strokeWidth),R.set({fontSize:Math.round(R.a.fontSize*lt),width:Math.ceil(ke.target.width()*lt),x:ke.target.x(),y:ke.target.y(),rotation:ke.target.rotation(),height:ke.target.height()*lt}),(Ge=B.current)===null||Ge===void 0||Ge.setAttrs({scaleX:1,scaleY:1}),P.history.endTransaction(),W(!1)}})),Y&&i.default.createElement(l.Group,{x:R.a.x,y:R.a.y,rotation:R.a.rotation},i.default.createElement(T,{textNodeRef:F,element:R,selectAll:J,cursorPosition:_e.current,onBlur:()=>{R.toggleEditMode(!1)}})),!U&&(Z||ee)&&i.default.createElement(v.Highlighter,{element:R}))})})(ty);var vp={},xs={};(function(e){var t=ue&&ue.__importDefault||function(v){return v&&v.__esModule?v:{default:v}};Object.defineProperty(e,"__esModule",{value:!0}),e.useSvgColors=e.replaceColors=e.sameColors=e.fixSize=e.getSvgSize=e.svgToURL=e.getColors=e.urlToString=e.urlToBase64=void 0;const n=t(F1),r=t(j),a=pp;function i(v){for(;v.parentNode;){if(v.nodeName==="defs")return!0;v=v.parentNode}return!1}function o(v){const b={fill:"",stroke:""};return v.getAttribute("fill")&&v.getAttribute("fill")!=="none"&&(b.fill=v.getAttribute("fill")),!b.fill&&v.style.fill&&v.style.fill!=="none"&&(b.fill=v.style.fill),v.getAttribute("stroke")&&(b.stroke=v.getAttribute("stroke")),!b.stroke&&v.style.stroke&&(b.stroke=v.style.stroke),b.stroke||b.fill||(b.fill="black"),b}const l=["path","rect","circle"];function s(v){for(var b=[],g=v.getElementsByTagName("*"),M=0,C=g.length;M<C;M++){const O=g[M];i(O)||(O.getAttribute("fill")!==null&&b.push(O),(O.getAttribute("stroke")!==null||O.style&&O.style.fill||l.indexOf(O.nodeName)>=0)&&b.push(O))}return b}async function c(v){const b=await fetch(v);return h(await b.text())}async function u(v){return await(await fetch(v,{mode:"cors"})).text()}function p(v){const b=s(new DOMParser().parseFromString(v,"image/svg+xml")),g=[];return b.forEach(M=>{const{fill:C,stroke:O}=o(M);[C,O].forEach(L=>{L&&n.default.Util.colorToRGBA(L)&&g.indexOf(L)===-1&&g.push(L)})}),g}function h(v){return"data:image/svg+xml;base64,"+window.btoa(unescape(encodeURIComponent(v)))}async function d(v){const b=await u(v),g=new DOMParser().parseFromString(b,"image/svg+xml").documentElement.getAttribute("viewBox"),[M,C,O,L]=(g==null?void 0:g.split(" "))||[];return{width:parseFloat(O),height:parseFloat(L)}}function E(v){var b=new DOMParser().parseFromString(v,"image/svg+xml");const g=b.documentElement.getAttribute("viewBox"),[M,C,O,L]=(g==null?void 0:g.split(" "))||[],T=b.documentElement.getAttribute("width");!T&&b.documentElement.setAttribute("width",O+"px");const A=b.documentElement.getAttribute("height");if((!A||A.indexOf("%")>=0)&&b.documentElement.setAttribute("height",L+"px"),T&&T.indexOf("%")>=0&&A&&A.indexOf("%")===-1){const z=parseFloat(A)/parseFloat(L);b.documentElement.setAttribute("width",z*parseFloat(O)+"px")}if(A&&A.indexOf("%")>=0&&T&&T.indexOf("%")===-1){const z=parseFloat(T)/parseFloat(O);b.documentElement.setAttribute("height",z*parseFloat(L)+"px")}return new XMLSerializer().serializeToString(b)}e.urlToBase64=c,e.urlToString=u,e.getColors=p,e.svgToURL=h,e.getSvgSize=d,e.fixSize=E;const w=(v,b)=>{if(!v||!b)return!1;const g=n.default.Util.colorToRGBA(v),M=n.default.Util.colorToRGBA(b);return g&&M?g.r===M.r&&g.g===M.g&&g.b===M.b&&g.a===M.a:void 0};function S(v,b,g,M){var C=v.namespaceURI,O=document.createElementNS(C,"linearGradient");const L=n.default.Util.degToRad(g+90),T=(Math.cos(L)+1)/2,A=(Math.sin(L)+1)/2,z=(Math.cos(L+Math.PI)+1)/2,I=(Math.sin(L+Math.PI)+1)/2;O.setAttribute("x1",100*T+"%"),O.setAttribute("y1",100*A+"%"),O.setAttribute("x2",100*z+"%"),O.setAttribute("y2",100*I+"%"),O.setAttribute("gradientUnits","userSpaceOnUse"),O.setAttribute("id",b);for(var H=0;H<M.length;H++){var N=M[H],G=document.createElementNS(C,"stop");for(var D in N)N.hasOwnProperty(D)&&G.setAttribute(D,N[D]);O.appendChild(G)}return(v.querySelector("defs")||v.insertBefore(document.createElementNS(C,"defs"),v.firstChild)).appendChild(O)}function _(v,b){var g=new DOMParser().parseFromString(v,"image/svg+xml");const M=s(g),C=Array.from(b.keys());return M.forEach(O=>{const{fill:L,stroke:T}=o(O);[{prop:"fill",color:L},{prop:"stroke",color:T}].forEach(({prop:A,color:z})=>{const I=C.find(H=>(0,e.sameColors)(H,z));if(I){const H=b.get(I);if((0,a.isGradient)(H)){const{rotation:N,stops:G}=(0,a.parseColor)(H),D=G.map(V=>({offset:100*V.offset+"%","stop-color":V.color})),q="color"+Math.round(1e8*Math.random());S(g.children[0],q,N,D),O.style[A]=null,O.setAttribute(A,`url('#${q}')`)}else O.style[A]=b.get(I)}})}),h(new XMLSerializer().serializeToString(g))}e.sameColors=w,e.replaceColors=_;const y=v=>{const[b,g]=r.default.useState([]);return r.default.useEffect(()=>{let M=!1;return(async()=>{g([]);const C=p(await u(v));M||g(C)})(),()=>{M=!0}},[v]),b};e.useSvgColors=y})(xs);(function(e){var t=ue&&ue.__createBinding||(Object.create?function(P,F,B,Y){Y===void 0&&(Y=B);var J=Object.getOwnPropertyDescriptor(F,B);J&&!("get"in J?!F.__esModule:J.writable||J.configurable)||(J={enumerable:!0,get:function(){return F[B]}}),Object.defineProperty(P,Y,J)}:function(P,F,B,Y){Y===void 0&&(Y=B),P[Y]=F[B]}),n=ue&&ue.__setModuleDefault||(Object.create?function(P,F){Object.defineProperty(P,"default",{enumerable:!0,value:F})}:function(P,F){P.default=F}),r=ue&&ue.__importStar||function(P){if(P&&P.__esModule)return P;var F={};if(P!=null)for(var B in P)B!=="default"&&Object.prototype.hasOwnProperty.call(P,B)&&t(F,P,B);return n(F,P),F},a=ue&&ue.__importDefault||function(P){return P&&P.__esModule?P:{default:P}};Object.defineProperty(e,"__esModule",{value:!0}),e.ImageElement=e.useImageLoader=e.setImageLoaderHook=void 0;const i=a(j),o=Rt,l=ki,s=nl,c=a(hp),u=a(F1),p=D2,h=Yc,d=rl,E=r(xs),w=mn,S=F2,_=al,y=ma;function v(){return document.createElement("canvas")}async function b(P){if(!(P.indexOf("data:image/svg+xml")>=0||P.indexOf(".svg")>=0))return P;const F=await E.urlToString(P),B=E.fixSize(F);return E.svgToURL(B)}const g=P=>{const[F,B]=i.default.useState(P);return i.default.useEffect(()=>{(async()=>{const Y=await b(P);Y!==F&&B(Y)})()},[P]),F},M=(P,F,B)=>{const Y=i.default.useMemo(()=>{var J,Z;const{flipX:K,flipY:U}=P,W=P.type==="svg"||P.src.indexOf("data:image/svg+xml")>=0||P.src.indexOf(".svg")>=0,X=navigator.userAgent.toLowerCase().indexOf("firefox")>-1&&W||P.maskSrc;if(!K&&!U&&!X)return F;if(!F||!F.width||!F.height)return null;const ee=v();let te=1;P.type==="svg"&&(te=Math.max(P.a.width/F.width*B,P.a.height/F.height*B)),ee.width=Math.max(F.width*te,1),ee.height=Math.max(F.height*te,1);let ne=K?-ee.width:0,ce=U?-ee.height:0;return(J=ee.getContext("2d"))===null||J===void 0||J.scale(K?-1:1,U?-1:1),(Z=ee.getContext("2d"))===null||Z===void 0||Z.drawImage(F,ne,ce,ee.width,ee.height),ee},[P.maskSrc,P.flipX,P.flipY,F,P.a.width,P.a.height,B]);return i.default.useEffect(()=>()=>{Y&&Y.nodeName==="CANVAS"&&u.default.Util.releaseCanvas(Y)},[Y]),Y};function C(P,F){const B=F.width/F.height;let Y,J;return B>=P.width/P.height?(Y=P.width,J=P.width/B):(Y=P.height*B,J=P.height),{x:(P.width-Y)/2,y:(P.height-J)/2,width:Y,height:J}}function O(P,F,B,Y,J,Z,K){for(var U=new ImageData(F,B),W=new Int32Array(P.data.buffer),X=P.width,ee=new Int32Array(U.data.buffer),te=U.width,ne=F/Z,ce=B/K,le=Math.round(1/ne),Te=Math.round(1/ce),Ce=le*Te,se=0;se<U.height;se++)for(var de=0;de<te;de++){for(var _e=Y+Math.round(de/ne)+(J+Math.round(se/ce))*X,Oe=0,ae=0,me=0,ve=0,ye=0;ye<Te;ye++)for(var Ie=0;Ie<le;Ie++){var nt=W[_e+Ie+ye*X];Oe+=nt<<24>>>24,ae+=nt<<16>>>24,me+=nt<<8>>>24,ve+=nt>>>24}Oe=Math.round(Oe/Ce),ae=Math.round(ae/Ce),me=Math.round(me/Ce),ve=Math.round(ve/Ce),ee[de+se*te]=ve<<24|me<<16|ae<<8|Oe}return U}function L(P,F){var B,Y;const J=v();J.width=P.width,J.height=P.height,(B=J.getContext("2d"))===null||B===void 0||B.drawImage(P,0,0,J.width,J.height);const Z=O(J.getContext("2d").getImageData(0,0,J.width,J.height),Math.floor(J.width*F),Math.floor(J.height*F),0,0,J.width,J.height);return J.width=Math.floor(J.width*F),J.height=Math.floor(J.height*F),(Y=J.getContext("2d"))===null||Y===void 0||Y.putImageData(Z,0,0),J}const T=(P,F)=>{const[B,Y]=G(P.maskSrc,"anonymous"),J=P.maskSrc?Y:"loaded";return(0,e.useImageLoader)(J,P.id+"-mask"),i.default.useMemo(()=>{if(!B||!F||!F.width||!F.height)return F;const Z=v();Z.width=Math.max(F.width,1),Z.height=Math.max(F.height,1);const K=Z.getContext("2d");if(!K)return F;K.drawImage(F,0,0),K.globalCompositeOperation="source-in";const U=C(B,P);return K.drawImage(B,U.x,U.y,U.width,U.height,0,0,F.width,F.height),Z},[F,B,P.a.width,P.a.height])},A=(P,F,B,Y,J=0,Z=!1)=>{const K=Math.floor(Math.max(P.a.width*Y,1)),U=Math.floor(Math.max(P.a.height*Y,1)),W=Math.min(J*Y,K/2,U/2),X=Math.max(P.a.width/B.width,P.a.height/B.height)*Y,ee=P.page._exporting&&w.flags.imageDownScalingEnabled&&X<1&&!Z,te=B.x===0&&B.y===0&&B.width===(F==null?void 0:F.width)&&B.height===(F==null?void 0:F.height),ne=i.default.useMemo(()=>{if(!(!F||!F.width||!F.height))return te&&W===0&&!ee?void 0:v()},[F,W,ee,te]);return i.default.useLayoutEffect(()=>{if(!ne||!F)return;ne.width=K,ne.height=U;const ce=ne.getContext("2d");if(!ce)return;W&&(ce.beginPath(),ce.moveTo(W,0),ce.lineTo(K-W,0),ce.arc(K-W,W,W,3*Math.PI/2,0,!1),ce.lineTo(K,U-W),ce.arc(K-W,U-W,W,0,Math.PI/2,!1),ce.lineTo(W,U),ce.arc(W,U-W,W,Math.PI/2,Math.PI,!1),ce.lineTo(0,W),ce.arc(W,W,W,Math.PI,3*Math.PI/2,!1),ce.clip());const le=ee?L(F,X):F,Te=ee?{x:Math.floor(B.x*X),y:Math.floor(B.y*X),width:Math.floor(B.width*X),height:Math.floor(B.height*X)}:B;ce.drawImage(le,Te.x,Te.y,Te.width,Te.height,0,0,ne.width,ne.height)},[ne,P.a.width,P.a.height,B.x,B.y,B.width,B.height,J,Y,Z,P.page._exporting,ee]),i.default.useEffect(()=>()=>{ne&&ne.nodeName==="CANVAS"&&u.default.Util.releaseCanvas(ne)},[ne]),ne||F},z=(P,F,B,Y)=>{const J=g(P.clipSrc||""),[Z,K]=G(J,"anonymous"),U=P.clipSrc?K:"loaded";(0,e.useImageLoader)(U,P.id+"-clip");const W=i.default.useMemo(()=>{if(F&&Z)return v()},[F,Z]);return i.default.useLayoutEffect(()=>{var X;if(!Z||!F||!F.width||!F.height||!Z||!Z.width||!Z.height||!W)return;const ee=v(),te=Math.max(P.a.width/Z.width*B,P.a.height/Z.height*B);ee.width=Z.width*te,ee.height=Z.height*te,(X=ee.getContext("2d"))===null||X===void 0||X.drawImage(Z,0,0,ee.width,ee.height),W.width=Math.max(F.width,1),W.height=Math.max(F.height,1);const ne=W.getContext("2d");ne&&(ne.save(),ne.drawImage(ee,0,0,F.width,F.height),u.default.Util.releaseCanvas(ee),ne.globalCompositeOperation="source-in",ne.drawImage(F,0,0,W.width,W.height),ne.restore())},[W,F,Z,P.a.width,P.a.height,B,...Y]),P.clipSrc&&Z?W:F},I=v(),H=(0,o.observer)(({element:P})=>{const F=Math.min(30,P.a.width/4,P.a.height/4),B=i.default.useRef(null);return i.default.useEffect(()=>{const Y=B.current;if(!Y)return;const J=new u.default.Animation(Z=>{Y.rotate(((Z==null?void 0:Z.timeDiff)||0)/2)},Y.getLayer());return J.start(),()=>{J.stop()}}),i.default.createElement(s.Group,{x:P.x,y:P.y,rotation:P.rotation,listening:!1,opacity:P.a.opacity,hideInExport:!P.showInExport},i.default.createElement(s.Rect,{width:P.a.width,height:P.a.height,fill:"rgba(124, 173, 212, 0.8)"}),i.default.createElement(s.Arc,{ref:B,x:P.a.width/2,y:P.a.height/2,fill:"white",outerRadius:Math.abs(F),innerRadius:Math.max(1,F-5),angle:270}))}),N=(0,o.observer)(({element:P})=>{const F="Can not load the image...",B=Math.max(10,Math.min(30,P.a.width/25));return i.default.createElement(s.Group,{x:P.x,y:P.y,rotation:P.rotation,listening:!1,opacity:P.a.opacity,hideInExport:!P.showInExport},i.default.createElement(s.Rect,{width:P.a.width,height:P.a.height,fill:"rgba(223, 102, 102, 0.8)"}),i.default.createElement(s.Text,{text:F,fontSize:B,width:P.a.width,height:P.a.height,align:"center",fill:"white",verticalAlign:"middle",padding:5}))});let G=c.default;const D=P=>{G=P};e.setImageLoaderHook=D;const q=(P,F)=>{const B=i.default.useRef(),Y=()=>{var J;(J=B.current)===null||J===void 0||J.call(B),B.current=void 0};i.default.useEffect(()=>Y,[]),i.default.useLayoutEffect(()=>{P!=="loading"||B.current||(B.current=(0,d.incrementLoader)(`image ${F}`)),P!=="loading"&&Y(),P==="failed"&&(0,d.triggerLoadError)(`image ${F}`)},[P])};e.useImageLoader=q;const V=({image:P,status:F,type:B})=>{const Y=i.default.useRef();return i.default.useEffect(()=>{Y.current=P||Y.current},[P]),F!=="failed"||F!=="failed"&&B==="svg"?Y.current:void 0},R=P=>{const[F,B]=i.default.useReducer(K=>K+1,0),Y=i.default.useRef("loading"),J=i.default.useRef(P.src),Z=i.default.useRef(P.src);return Z.current!==P.src&&(Z.current=P.src,Y.current="loading"),i.default.useEffect(()=>{if(P.type==="image"||!P.src)return;let K=!1;return(async()=>{Y.current="loading",B();const U=await E.urlToString(P.src),W=E.fixSize(U),X=E.replaceColors(W,P.colorsReplace);K||(J.current=X,Y.current="loaded",B())})(),()=>{K=!0}},[P.src,JSON.stringify(P.colorsReplace)]),P.type==="image"?[P.src,"loaded"]:[J.current,Y.current]};e.ImageElement=(0,o.observer)(({element:P,store:F})=>{var B;const[Y,J]=i.default.useState(!1),Z=i.default.useRef(null),K=i.default.useRef(null),[U,W]=i.default.useState(!1),X=F.selectedElements.indexOf(P)>=0,[ee,te]=R(P),[ne,ce]=G(ee,"anonymous"),le=P.type!=="svg"||te==="loaded"?ce:"loading";(0,e.useImageLoader)(le,P.id);const Te=V({image:ne,status:ce,type:P.type}),Ce=T(P,M(P,ne||Te,F._elementsPixelRatio))||I;let{cropX:se,cropY:de,cropWidth:_e,cropHeight:Oe}=P;ce!=="loaded"&&(se=de=0,_e=Oe=1);const ae=Ce.width*_e,me=Ce.height*Oe,ve=P.a.width/P.a.height;let ye,Ie;const nt=ae/me,Qe=P.type==="svg";Qe?(ye=ae,Ie=me):ve>=nt?(ye=ae,Ie=ae/ve):(ye=me*ve,Ie=me);const ke={x:Ce.width*se,y:Ce.height*de,width:ye,height:Ie},Ge=(B=P.cornerRadius)!==null&&B!==void 0?B:0;let lt=z(P,A(P,Ce,ke,F._elementsPixelRatio,Ge,Y||P._cropModeEnabled||P.type==="svg"),F._elementsPixelRatio,[ke,Ge,F._elementsPixelRatio]);const st=Math.max(P.a.width/ye,P.a.height/Ie);i.default.useEffect(()=>{var Be;if(!P._cropModeEnabled)return;const ot=(Be=Z.current)===null||Be===void 0?void 0:Be.getStage();function wt(pn){P._cropModeEnabled&&pn.target!==K.current&&P.toggleCropMode(!1)}function Ft(pn){P._cropModeEnabled&&pn.target.nodeName!=="CANVAS"&&P.toggleCropMode(!1)}return document.body.addEventListener("click",Ft),ot==null||ot.on("click",wt),ot==null||ot.on("tap",wt),()=>{document.body.removeEventListener("click",Ft),document.body.removeEventListener("touchstart",Ft),ot==null||ot.off("click",wt),ot==null||ot.off("click",wt)}},[P._cropModeEnabled]),i.default.useLayoutEffect(()=>{if(!(Y||P._cropModeEnabled))return(0,S.applyFilter)(Z.current,P),(0,l.autorun)(()=>{(0,S.applyFilter)(Z.current,P)},{delay:100})},[Ce,Y,_e,Oe,P._cropModeEnabled]),i.default.useLayoutEffect(()=>{var Be;Y||P._cropModeEnabled?(Be=Z.current)===null||Be===void 0||Be.clearCache():(0,S.applyFilter)(Z.current,P)},[Y,P.a.width,P.a.height,P._cropModeEnabled]),i.default.useEffect(()=>{(0,S.applyFilter)(Z.current,P)},[P.shadowEnabled,P.shadowBlur,P.cornerRadius,P.shadowColor,P.shadowOffsetX,P.shadowOffsetY,P.shadowOpacity]);const ie=i.default.useRef(null),fe=i.default.useRef(null),He=i.default.useRef(null);i.default.useLayoutEffect(()=>{P._cropModeEnabled&&(fe.current.nodes([ie.current]),He.current.nodes([K.current]))},[P._cropModeEnabled]);const we=Be=>{Math.round(Be.target.x())>0&&(Be.target.x(0),Be.target.scaleX(1)),Math.round(Be.target.y())>0&&(Be.target.y(0),Be.target.scaleY(1));const ot=Be.target.width()*Be.target.scaleX(),wt=Be.target.height()*Be.target.scaleY(),Ft=Math.min(1,ye/ot),pn=Math.min(1,Ie/wt),Er=1-Ft,Yn=Math.min(Er,Math.max(0,Math.round(-Be.target.x())/ot)),lr=1-pn,Sr=Math.min(lr,Math.max(0,Math.round(-Be.target.y())/wt));Be.target.setAttrs({x:-Yn*Ce.width,y:-Sr*Ce.height,scaleX:1,scaleY:1}),P.set({cropX:Yn,cropY:Sr,cropWidth:Ft,cropHeight:pn})},Ke=()=>{P.type!=="svg"&&P.contentEditable&&setTimeout(()=>{P.toggleCropMode(!0)})},Se=P.type==="svg"&&Te,et=ce==="loading"&&!Se,ln=ce==="failed",Pe=!et&&!ln,Ye=i.default.useRef({cropX:0,cropY:0,cropWidth:0,cropHeight:0}),mt=Pe?P.a.opacity:0;(0,_.useFadeIn)(Z,mt);const Ht=P.selectable||F.role==="admin",At=(0,y.useMobile)();return i.default.createElement(i.default.Fragment,null,et&&i.default.createElement(H,{element:P}),ln&&i.default.createElement(N,{element:P}),i.default.createElement(s.Image,{ref:Z,name:"element",id:P.id,image:lt,x:P.a.x,y:P.a.y,width:P.a.width||1,height:P.a.height||1,rotation:P.rotation,opacity:mt,shadowEnabled:P.shadowEnabled,shadowBlur:P.shadowBlur,shadowOffsetX:P.shadowOffsetX,shadowOffsetY:P.shadowOffsetY,shadowColor:P.shadowColor,shadowOpacity:P.shadowOpacity,customCrop:ke,listening:Ht,draggable:At?P.draggable&&X:P.draggable,preventDefault:!At||X,hideInExport:!P.showInExport,onMouseEnter:()=>{W(!0)},onMouseLeave:()=>{W(!1)},onDragStart:()=>{F.history.startTransaction()},onDragMove:Be=>{P.set({x:Be.target.x(),y:Be.target.y()})},onDragEnd:Be=>{P.set({x:Be.target.x(),y:Be.target.y()}),F.history.endTransaction()},onDblClick:Ke,onDblTap:Ke,onTransformStart:()=>{J(!0),F.history.startTransaction(),Ye.current={cropX:P.cropX,cropY:P.cropY,cropWidth:P.cropWidth,cropHeight:P.cropHeight}},onTransform:Be=>{var ot;const wt=Be.currentTarget,Ft=Math.abs(wt.scaleX()-1)<1e-7?1:wt.scaleX(),pn=Math.abs(wt.scaleY()-1)<1e-7?1:wt.scaleY();wt.scaleX(1),wt.scaleY(1);const Er=(ot=Be.target.getStage())===null||ot===void 0?void 0:ot.findOne("Transformer"),Yn=1-ye/Ce.width,lr=Math.min(Yn,Math.max(0,P.cropX)),Sr=1-Ie/Ce.height,Ja=Math.min(Sr,Math.max(0,P.cropY)),m1=Er.getActiveAnchor(),g1=!(m1.indexOf("middle")>=0||m1.indexOf("center")>=0),pl=!g1&&Ft<1&&Ye.current.cropHeight>Ie/Ce.height;let Wi=g1?P.cropWidth:P.cropWidth*Ft;pl&&(Wi=P.cropWidth);const gu=!g1&&pn<1&&Ye.current.cropWidth>ye/Ce.width;let ei=g1?P.cropHeight:P.cropHeight*pn;gu&&(ei=P.cropHeight),Qe&&(Wi=P.cropWidth,ei=P.cropHeight),P.set({cropX:lr,cropY:Ja,x:wt.x(),y:wt.y(),width:wt.width()*Ft,height:wt.height()*pn,rotation:Be.target.rotation(),cropWidth:Math.min(Wi,1-lr),cropHeight:Math.min(ei,1-Ja)})},onTransformEnd:Be=>{const ot=Be.currentTarget;P.set({width:ot.width(),height:ot.height(),x:ot.x(),y:ot.y(),rotation:Be.target.rotation(),cropWidth:ye/Ce.width,cropHeight:Ie/Ce.height}),J(!1),F.history.endTransaction()}}),i.default.createElement(s.Rect,{x:P.x,y:P.y,width:Math.max(P.a.width-P.borderSize,0),height:Math.max(P.a.height-P.borderSize,0),opacity:mt,offsetX:-P.borderSize/2,offsetY:-P.borderSize/2,stroke:P.borderColor,strokeWidth:P.borderSize,listening:!1,visible:!!P.borderSize,rotation:P.rotation,cornerRadius:Math.max(0,Ge-P.borderSize),hideInExport:!P.showInExport}),P._cropModeEnabled&&i.default.createElement(p.Portal,{selector:".page-abs-container",enabled:!0},i.default.createElement(s.Rect,{x:-window.innerWidth/F.scale,y:-window.innerWidth/F.scale,width:window.innerWidth/F.scale*3,height:window.innerWidth/F.scale*3,fill:"rgba(0,0,0,0.3)"}),i.default.createElement(s.Image,{listening:!1,image:lt,x:P.x,y:P.y,width:P.a.width,height:P.a.height,rotation:P.rotation,shadowEnabled:P.shadowEnabled,shadowBlur:P.shadowBlur}),i.default.createElement(s.Group,{x:P.x,y:P.y,rotation:P.rotation,scaleX:st,scaleY:st},i.default.createElement(s.Image,{image:Ce,ref:K,opacity:.4,draggable:!0,x:-P.cropX*Ce.width,y:-P.cropY*Ce.height,onDragMove:we,onTransform:we}),i.default.createElement(s.Transformer,{ref:He,anchorSize:20,enabledAnchors:["top-left","top-right","bottom-left","bottom-right"],boundBoxFunc:(Be,ot)=>ot.width<5||ot.height<5?Be:ot,rotateEnabled:!1,borderEnabled:!1,anchorCornerRadius:10,anchorStrokeWidth:2,borderStrokeWidth:2}),i.default.createElement(s.Rect,{width:ye,height:Ie,ref:ie,listening:!1,onTransform:Be=>{Be.target.x()<-P.cropX*Ce.width-1e-9&&(Be.target.x(-P.cropX*Ce.width),Be.target.scaleX(1)),Be.target.y()<-P.cropY*Ce.height-1e-9&&(Be.target.y(-P.cropY*Ce.height),Be.target.scaleY(1));const ot=Math.min(1,Math.max(0,P.cropX+Be.target.x()/Ce.width)),wt=Math.min(1,Math.max(0,Be.target.y()/Ce.height+P.cropY)),Ft=Be.target.width()*Be.target.scaleX(),pn=Be.target.height()*Be.target.scaleY(),Er=Math.min(1-ot,Ft/Ce.width),Yn=Math.min(1-wt,pn/Ce.height),lr=Be.target.getAbsolutePosition(Be.target.getParent().getParent());Be.target.scale({x:1,y:1}),Be.target.position({x:0,y:0}),P.set({x:lr.x,y:lr.y,cropX:ot,cropY:wt,cropWidth:Er,cropHeight:Yn,width:Math.min(Ft*st,Ce.width*(1-ot)*st),height:Math.min(pn*st,Ce.height*(1-wt)*st)})}}),i.default.createElement(s.Transformer,{ref:fe,enabledAnchors:["top-left","top-right","bottom-left","bottom-right"],boundBoxFunc:(Be,ot)=>ot.width<5||ot.height<5?Be:ot,keepRatio:!1,rotateEnabled:!1,anchorFill:"rgb(240, 240, 240)",anchorStrokeWidth:2,borderStrokeWidth:2}))),(U||X)&&i.default.createElement(h.Highlighter,{element:P}))})})(vp);var ay={},aL={exports:{}};/*!
89
+ `).join(" ").split(/[\s-]+/);let X=R.textArr.map(te=>te.text).join(";");const ee=W.find(te=>!X.includes(te)||(X=X.replace(te,""),!1));if(!(U||ee))break;J-=.5,R.fontSize(J)}return R.fontSize(F),R.height(B),J}function q({lines:R,lineHeight:P,width:F,align:B="left",padding:Y=0,cornerRadius:J=0}){var Z;R.forEach((X,ee)=>{X.cx=F/2,B==="right"?X.cx=F-X.width/2:B==="left"&&(X.cx=X.width/2),B!=="justify"||X.lastInParagraph||(X.width=F),B==="justify"&&(X.cx=X.width/2)});let K=`M ${(Z=R[0])===null||Z===void 0?void 0:Z.cx} ${-Y}`;R.forEach((X,ee)=>{const{cx:te}=X,ne=R[ee-1];ne&&ne.width>X.width?K+=` L ${te+X.width/2+Y} ${ee*P+Y}`:K+=` L ${te+X.width/2+Y} ${ee*P-Y}`;const ce=R[ee+1];ce&&ce.width>X.width?K+=` L ${te+X.width/2+Y} ${(ee+1)*P-Y}`:K+=` L ${te+X.width/2+Y} ${(ee+1)*P+Y}`});for(var U=R.length-1;U>=0;U--){const X=R[U],{cx:ee}=X,te=R[U+1];te&&te.width>X.width?K+=` L ${ee-X.width/2-Y} ${(U+1)*P-Y}`:K+=` L ${ee-X.width/2-Y} ${(U+1)*P+Y}`;const ne=R[U-1];ne&&ne.width>X.width?K+=` L ${ee-X.width/2-Y} ${U*P+Y}`:K+=` L ${ee-X.width/2-Y} ${U*P-Y}`}K+=" Z";const W=(0,p.parsePath)(K);return(0,p.roundCommands)(W,J).path}e.getLineHeight=I,e.usePrevious=G;const V=R=>i.default.useMemo(()=>{if(!S.isGradient(R.fill))return{fill:R.fill};const{stops:P,rotation:F}=S.parseColor(R.fill),B={x:R.a.width/2,y:R.a.height/2},Y=Math.sqrt(Math.pow(B.x,2)+Math.pow(B.y,2)),J=u.default.Util.degToRad(F)-Math.PI/2,Z=[];return P.forEach(({offset:K,color:U})=>{Z.push(K,U)}),{fillLinearGradientStartPointX:B.x-Y*Math.cos(J),fillLinearGradientStartPointY:B.y-Y*Math.sin(J),fillLinearGradientColorStops:Z,fillLinearGradientEndPointX:B.x+Y*Math.cos(J),fillLinearGradientEndPointY:B.y+Y*Math.sin(J),fill:P[1].color,fillPriority:"linear-gradient"}},[R.fill]);e.useTextColor=V,e.TextElement=(0,o.observer)(({element:R,store:P})=>{const F=i.default.useRef(null),B=i.default.useRef(null),{editorEnabled:Y,selectAll:J}=A(R),[Z,K]=i.default.useState(!1),[U,W]=i.default.useState(!1),X=i.default.useRef(R.a.height),ee=P.selectedElements.indexOf(R)>=0,{textVerticalResizeEnabled:te}=E.flags,ne=G(R.fontFamily),[ce,le]=i.default.useState([]);i.default.useEffect(()=>{var ke,Ge;const lt=(Ge=(ke=F.current)===null||ke===void 0?void 0:ke.textArr)!==null&&Ge!==void 0?Ge:[];JSON.stringify(lt)!==JSON.stringify(ce)&&le(lt)}),i.default.useEffect(()=>{if(R.a.width)return;const ke=F.current;ke.width(600),R.set({width:1.4*ke.getTextWidth()})},[]),i.default.useLayoutEffect(()=>(0,c.autorun)(()=>{const ke=F.current;(0,_.applyFilter)(ke,R)}));const[Te]=(0,e.useFontLoader)(P,R.fontFamily),Ce=(0,w.removeTags)(R.text),se=()=>{const ke=F.current.clone({height:void 0}),Ge=Math.ceil(ke.fontSize()*ke.lineHeight()*ke.textArr.length+1);return ke.destroy(),Ge};i.default.useLayoutEffect(()=>{if(!Te)return;const{textOverflow:ke}=E.flags;if(R.a.height)if(ke!=="change-font-size"||U){if(ke==="resize"){const Ge=se();te&&R.a.height<Ge&&P.history.ignore(()=>{R.set({height:Ge}),F.current.height(Ge)}),te||R.a.height===Ge||P.history.ignore(()=>{R.set({height:Ge}),F.current.height(Ge)})}}else{const Ge=D(F.current,R);if(Ge!==R.a.fontSize)return void P.history.ignore(()=>{R.set({fontSize:Ge})});const lt=se();R.a.height===lt||te||P.history.ignore(()=>{R.set({height:lt})})}else{const Ge=se();P.history.ignore(()=>{R.set({height:Ge})})}}),i.default.useLayoutEffect(()=>{const ke=F.current;ke&&(ke.width(ke.width()+1e-8),ke._setTextData(),(0,_.applyFilter)(ke,R))},[Te]);const de=i.default.useRef(null),_e=i.default.useRef(0),Oe=ke=>{ke.evt.preventDefault(),P.selectedShapes.find(lt=>lt===R)&&R.contentEditable&&(_e.current=N(ke),R.toggleEditMode())},ae=!Ce&&R.placeholder?.6:R.a.opacity;(0,y.useFadeIn)(F,ae);const me=(0,e.getLineHeight)({fontLoaded:Te,fontFamily:R.fontFamily,fontSize:R.a.fontSize,lineHeight:R.lineHeight}),ve=R.selectable||P.role==="admin",ye=(0,e.useTextColor)(R),Ie=i.default.useMemo(()=>R.backgroundEnabled?q({lines:JSON.parse(JSON.stringify(ce)),cornerRadius:R.backgroundCornerRadius*(R.a.fontSize*me*.5),lineHeight:me*R.a.fontSize,padding:R.backgroundPadding*(R.a.fontSize*me*.5),width:R.a.width,align:R.align}):"",[R.backgroundEnabled,R.backgroundCornerRadius,R.a.fontSize,me,R.backgroundPadding,R.a.width,R.align,ce]),nt=(0,b.useMobile)();let Qe=0;return R.verticalAlign==="middle"?Qe=(R.a.height-ce.length*me*R.a.fontSize)/2:R.verticalAlign==="bottom"&&(Qe=R.a.height-ce.length*me*R.a.fontSize),i.default.createElement(i.default.Fragment,null,i.default.createElement(l.Path,{ref:B,x:R.a.x,y:R.a.y,rotation:R.a.rotation,hideInExport:!R.showInExport||!Ce,listening:!1,visible:R.backgroundEnabled,opacity:R.backgroundOpacity,data:Ie,fill:R.backgroundColor,offsetY:-Qe}),i.default.createElement(l.Text,Object.assign({ref:F,id:R.id,name:"element",hideInExport:!R.showInExport||!Ce,editModeEnabled:R._editModeEnabled,x:R.a.x,y:R.a.y,rotation:R.a.rotation,width:R.a.width,height:R.a.height,text:Ce||R.placeholder},ye,{stroke:R.stroke,lineJoin:"round",strokeWidth:R.strokeWidth,fillAfterStrokeEnabled:!0,fontSize:R.a.fontSize,fontFamily:`"${R.fontFamily}", "${ne}"`,fontStyle:R.fontStyle+" "+R.fontWeight,textDecoration:R.textDecoration,align:R.align,verticalAlign:R.verticalAlign,draggable:nt?R.draggable&&ee:R.draggable,preventDefault:!nt||ee,opacity:ae,visible:!R._editModeEnabled,ellipsis:E.flags.textOverflow==="ellipsis",shadowEnabled:R.shadowEnabled,shadowBlur:R.shadowBlur,shadowOffsetX:R.shadowOffsetX,shadowOffsetY:R.shadowOffsetY,shadowColor:R.shadowColor,shadowOpacity:R.shadowOpacity,lineHeight:me,letterSpacing:R.letterSpacing*R.a.fontSize,listening:ve,onDragStart:()=>{P.history.startTransaction()},onDragMove:ke=>{R.set({x:ke.target.x(),y:ke.target.y()})},onDragEnd:ke=>{R.set({x:ke.target.x(),y:ke.target.y()}),P.history.endTransaction()},onMouseEnter:()=>{K(!0)},onMouseLeave:()=>{K(!1)},onClick:Oe,onTap:Oe,onTransformStart:()=>{W(!0),P.history.startTransaction(),X.current=F.current.height()},onTransform:ke=>{var Ge,lt;const st=ke.target;(Ge=B.current)===null||Ge===void 0||Ge.setAttrs({x:st.x(),y:st.y(),rotation:st.rotation(),scale:st.scale()});const ie=((lt=st.getStage())===null||lt===void 0?void 0:lt.findOne("Transformer")).getActiveAnchor();if(ie==="middle-left"||ie==="middle-right"){const fe=st.scaleX(),He=st.width()*fe,we=R.a.fontSize;let Ke=He;He<we&&(Ke=we,de.current&&st.position(de.current)),st.width(Ke),st.scaleX(1),st.scaleY(1);const Se=se();if(E.flags.textOverflow!=="ellipsis"){const et=Math.max(Se,X.current);st.height(et),R.set({height:st.height()})}R.set({x:st.x(),y:st.y(),width:st.width(),rotation:st.rotation()}),(0,_.applyFilter)(st,R)}if(ie==="top-center"||ie==="bottom-center"){let fe=E.flags.textOverflow==="resize"?se():me*R.a.fontSize;ke.target.height(Math.max(fe,ke.target.height()*ke.target.scaleY())),ke.target.scaleY(1)}ke.target.strokeWidth(R.strokeWidth/ke.target.scaleX()),de.current=ke.target.position()},onTransformEnd:ke=>{var Ge;const lt=ke.target.scaleX();ke.target.scaleX(1),ke.target.scaleY(1),ke.target.strokeWidth(R.strokeWidth),R.set({fontSize:Math.round(R.a.fontSize*lt),width:Math.ceil(ke.target.width()*lt),x:ke.target.x(),y:ke.target.y(),rotation:ke.target.rotation(),height:ke.target.height()*lt}),(Ge=B.current)===null||Ge===void 0||Ge.setAttrs({scaleX:1,scaleY:1}),P.history.endTransaction(),W(!1)}})),Y&&i.default.createElement(l.Group,{x:R.a.x,y:R.a.y,rotation:R.a.rotation},i.default.createElement(T,{textNodeRef:F,element:R,selectAll:J,cursorPosition:_e.current,onBlur:()=>{R.toggleEditMode(!1)}})),!U&&(Z||ee)&&i.default.createElement(v.Highlighter,{element:R}))})})(ty);var vp={},xs={};(function(e){var t=ue&&ue.__importDefault||function(v){return v&&v.__esModule?v:{default:v}};Object.defineProperty(e,"__esModule",{value:!0}),e.useSvgColors=e.replaceColors=e.sameColors=e.fixSize=e.getSvgSize=e.svgToURL=e.getColors=e.urlToString=e.urlToBase64=void 0;const n=t(F1),r=t(j),a=pp;function i(v){for(;v.parentNode;){if(v.nodeName==="defs")return!0;v=v.parentNode}return!1}function o(v){const b={fill:"",stroke:""};return v.getAttribute("fill")&&v.getAttribute("fill")!=="none"&&(b.fill=v.getAttribute("fill")),!b.fill&&v.style.fill&&v.style.fill!=="none"&&(b.fill=v.style.fill),v.getAttribute("stroke")&&(b.stroke=v.getAttribute("stroke")),!b.stroke&&v.style.stroke&&(b.stroke=v.style.stroke),b.stroke||b.fill||(b.fill="black"),b}const l=["path","rect","circle"];function s(v){for(var b=[],g=v.getElementsByTagName("*"),M=0,C=g.length;M<C;M++){const O=g[M];i(O)||(O.getAttribute("fill")!==null&&b.push(O),(O.getAttribute("stroke")!==null||O.style&&O.style.fill||l.indexOf(O.nodeName)>=0)&&b.push(O))}return b}async function c(v){const b=await fetch(v);return h(await b.text())}async function u(v){return await(await fetch(v,{mode:"cors"})).text()}function p(v){const b=s(new DOMParser().parseFromString(v,"image/svg+xml")),g=[];return b.forEach(M=>{const{fill:C,stroke:O}=o(M);[C,O].forEach(L=>{L&&n.default.Util.colorToRGBA(L)&&g.indexOf(L)===-1&&g.push(L)})}),g}function h(v){return"data:image/svg+xml;base64,"+window.btoa(unescape(encodeURIComponent(v)))}async function d(v){const b=await u(v),g=new DOMParser().parseFromString(b,"image/svg+xml").documentElement.getAttribute("viewBox"),[M,C,O,L]=(g==null?void 0:g.split(" "))||[];return{width:parseFloat(O),height:parseFloat(L)}}function E(v){var b=new DOMParser().parseFromString(v,"image/svg+xml");const g=b.documentElement.getAttribute("viewBox"),[M,C,O,L]=(g==null?void 0:g.split(" "))||[],T=b.documentElement.getAttribute("width");!T&&b.documentElement.setAttribute("width",O+"px");const A=b.documentElement.getAttribute("height");if((!A||A.indexOf("%")>=0)&&b.documentElement.setAttribute("height",L+"px"),T&&T.indexOf("%")>=0&&A&&A.indexOf("%")===-1){const z=parseFloat(A)/parseFloat(L);b.documentElement.setAttribute("width",z*parseFloat(O)+"px")}if(A&&A.indexOf("%")>=0&&T&&T.indexOf("%")===-1){const z=parseFloat(T)/parseFloat(O);b.documentElement.setAttribute("height",z*parseFloat(L)+"px")}return new XMLSerializer().serializeToString(b)}e.urlToBase64=c,e.urlToString=u,e.getColors=p,e.svgToURL=h,e.getSvgSize=d,e.fixSize=E;const w=(v,b)=>{if(!v||!b)return!1;const g=n.default.Util.colorToRGBA(v),M=n.default.Util.colorToRGBA(b);return g&&M?g.r===M.r&&g.g===M.g&&g.b===M.b&&g.a===M.a:void 0};function S(v,b,g,M){var C=v.namespaceURI,O=document.createElementNS(C,"linearGradient");const L=n.default.Util.degToRad(g+90),T=(Math.cos(L)+1)/2,A=(Math.sin(L)+1)/2,z=(Math.cos(L+Math.PI)+1)/2,I=(Math.sin(L+Math.PI)+1)/2;O.setAttribute("x1",100*T+"%"),O.setAttribute("y1",100*A+"%"),O.setAttribute("x2",100*z+"%"),O.setAttribute("y2",100*I+"%"),O.setAttribute("gradientUnits","userSpaceOnUse"),O.setAttribute("id",b);for(var H=0;H<M.length;H++){var N=M[H],G=document.createElementNS(C,"stop");for(var D in N)N.hasOwnProperty(D)&&G.setAttribute(D,N[D]);O.appendChild(G)}return(v.querySelector("defs")||v.insertBefore(document.createElementNS(C,"defs"),v.firstChild)).appendChild(O)}function _(v,b){var g=new DOMParser().parseFromString(v,"image/svg+xml");const M=s(g),C=Array.from(b.keys());return M.forEach(O=>{const{fill:L,stroke:T}=o(O);[{prop:"fill",color:L},{prop:"stroke",color:T}].forEach(({prop:A,color:z})=>{const I=C.find(H=>(0,e.sameColors)(H,z));if(I){const H=b.get(I);if((0,a.isGradient)(H)){const{rotation:N,stops:G}=(0,a.parseColor)(H),D=G.map(V=>({offset:100*V.offset+"%","stop-color":V.color})),q="color"+Math.round(1e8*Math.random());S(g.children[0],q,N,D),O.style[A]=null,O.setAttribute(A,`url('#${q}')`)}else O.style[A]=b.get(I)}})}),h(new XMLSerializer().serializeToString(g))}e.sameColors=w,e.replaceColors=_;const y=v=>{const[b,g]=r.default.useState([]);return r.default.useEffect(()=>{let M=!1;return(async()=>{g([]);const C=p(await u(v));M||g(C)})(),()=>{M=!0}},[v]),b};e.useSvgColors=y})(xs);(function(e){var t=ue&&ue.__createBinding||(Object.create?function(P,F,B,Y){Y===void 0&&(Y=B);var J=Object.getOwnPropertyDescriptor(F,B);J&&!("get"in J?!F.__esModule:J.writable||J.configurable)||(J={enumerable:!0,get:function(){return F[B]}}),Object.defineProperty(P,Y,J)}:function(P,F,B,Y){Y===void 0&&(Y=B),P[Y]=F[B]}),n=ue&&ue.__setModuleDefault||(Object.create?function(P,F){Object.defineProperty(P,"default",{enumerable:!0,value:F})}:function(P,F){P.default=F}),r=ue&&ue.__importStar||function(P){if(P&&P.__esModule)return P;var F={};if(P!=null)for(var B in P)B!=="default"&&Object.prototype.hasOwnProperty.call(P,B)&&t(F,P,B);return n(F,P),F},a=ue&&ue.__importDefault||function(P){return P&&P.__esModule?P:{default:P}};Object.defineProperty(e,"__esModule",{value:!0}),e.ImageElement=e.useImageLoader=e.setImageLoaderHook=void 0;const i=a(j),o=Rt,l=ki,s=nl,c=a(hp),u=a(F1),p=D2,h=Yc,d=rl,E=r(xs),w=mn,S=F2,_=al,y=ma;function v(){return document.createElement("canvas")}async function b(P){if(!(P.indexOf("data:image/svg+xml")>=0||P.indexOf(".svg")>=0))return P;const F=await E.urlToString(P),B=E.fixSize(F);return E.svgToURL(B)}const g=P=>{const[F,B]=i.default.useState(P);return i.default.useEffect(()=>{(async()=>{const Y=await b(P);Y!==F&&B(Y)})()},[P]),F},M=(P,F,B)=>{const Y=i.default.useMemo(()=>{var J,Z;const{flipX:K,flipY:U}=P,W=P.type==="svg"||P.src.indexOf("data:image/svg+xml")>=0||P.src.indexOf(".svg")>=0,X=navigator.userAgent.toLowerCase().indexOf("firefox")>-1&&W||P.maskSrc;if(!K&&!U&&!X)return F;if(!F||!F.width||!F.height)return null;const ee=v();let te=1;P.type==="svg"&&(te=Math.max(P.a.width/F.width*B,P.a.height/F.height*B)),ee.width=Math.max(F.width*te,1),ee.height=Math.max(F.height*te,1);let ne=K?-ee.width:0,ce=U?-ee.height:0;return(J=ee.getContext("2d"))===null||J===void 0||J.scale(K?-1:1,U?-1:1),(Z=ee.getContext("2d"))===null||Z===void 0||Z.drawImage(F,ne,ce,ee.width,ee.height),ee},[P.maskSrc,P.flipX,P.flipY,F,P.a.width,P.a.height,B]);return i.default.useEffect(()=>()=>{Y&&Y.nodeName==="CANVAS"&&u.default.Util.releaseCanvas(Y)},[Y]),Y};function C(P,F){const B=F.width/F.height;let Y,J;return B>=P.width/P.height?(Y=P.width,J=P.width/B):(Y=P.height*B,J=P.height),{x:(P.width-Y)/2,y:(P.height-J)/2,width:Y,height:J}}function O(P,F,B,Y,J,Z,K){for(var U=new ImageData(F,B),W=new Int32Array(P.data.buffer),X=P.width,ee=new Int32Array(U.data.buffer),te=U.width,ne=F/Z,ce=B/K,le=Math.round(1/ne),Te=Math.round(1/ce),Ce=le*Te,se=0;se<U.height;se++)for(var de=0;de<te;de++){for(var _e=Y+Math.round(de/ne)+(J+Math.round(se/ce))*X,Oe=0,ae=0,me=0,ve=0,ye=0;ye<Te;ye++)for(var Ie=0;Ie<le;Ie++){var nt=W[_e+Ie+ye*X];Oe+=nt<<24>>>24,ae+=nt<<16>>>24,me+=nt<<8>>>24,ve+=nt>>>24}Oe=Math.round(Oe/Ce),ae=Math.round(ae/Ce),me=Math.round(me/Ce),ve=Math.round(ve/Ce),ee[de+se*te]=ve<<24|me<<16|ae<<8|Oe}return U}function L(P,F){var B,Y;const J=v();J.width=P.width,J.height=P.height,(B=J.getContext("2d"))===null||B===void 0||B.drawImage(P,0,0,J.width,J.height);const Z=O(J.getContext("2d").getImageData(0,0,J.width,J.height),Math.floor(J.width*F),Math.floor(J.height*F),0,0,J.width,J.height);return J.width=Math.floor(J.width*F),J.height=Math.floor(J.height*F),(Y=J.getContext("2d"))===null||Y===void 0||Y.putImageData(Z,0,0),J}const T=(P,F)=>{const[B,Y]=G(P.maskSrc,"anonymous"),J=P.maskSrc?Y:"loaded";return(0,e.useImageLoader)(J,P.id+"-mask"),i.default.useMemo(()=>{if(!B||!F||!F.width||!F.height)return F;const Z=v();Z.width=Math.max(F.width,1),Z.height=Math.max(F.height,1);const K=Z.getContext("2d");if(!K)return F;K.drawImage(F,0,0),K.globalCompositeOperation="source-in";const U=C(B,P);return K.drawImage(B,U.x,U.y,U.width,U.height,0,0,F.width,F.height),Z},[F,B,P.a.width,P.a.height])},A=(P,F,B,Y,J=0,Z=!1)=>{const K=Math.floor(Math.max(P.a.width*Y,1)),U=Math.floor(Math.max(P.a.height*Y,1)),W=Math.min(J*Y,K/2,U/2),X=Math.max(P.a.width/B.width,P.a.height/B.height)*Y,ee=P.page._exporting&&w.flags.imageDownScalingEnabled&&X<1&&!Z,te=B.x===0&&B.y===0&&B.width===(F==null?void 0:F.width)&&B.height===(F==null?void 0:F.height),ne=i.default.useMemo(()=>{if(!(!F||!F.width||!F.height))return te&&W===0&&!ee?void 0:v()},[F,W,ee,te]);return i.default.useLayoutEffect(()=>{if(!ne||!F)return;ne.width=K,ne.height=U;const ce=ne.getContext("2d");if(!ce)return;W&&(ce.beginPath(),ce.moveTo(W,0),ce.lineTo(K-W,0),ce.arc(K-W,W,W,3*Math.PI/2,0,!1),ce.lineTo(K,U-W),ce.arc(K-W,U-W,W,0,Math.PI/2,!1),ce.lineTo(W,U),ce.arc(W,U-W,W,Math.PI/2,Math.PI,!1),ce.lineTo(0,W),ce.arc(W,W,W,Math.PI,3*Math.PI/2,!1),ce.clip());const le=ee?L(F,X):F,Te=ee?{x:Math.floor(B.x*X),y:Math.floor(B.y*X),width:Math.floor(B.width*X),height:Math.floor(B.height*X)}:B;ce.drawImage(le,Te.x,Te.y,Te.width,Te.height,0,0,ne.width,ne.height)},[ne,P.a.width,P.a.height,B.x,B.y,B.width,B.height,J,Y,Z,P.page._exporting,ee]),i.default.useEffect(()=>()=>{ne&&ne.nodeName==="CANVAS"&&u.default.Util.releaseCanvas(ne)},[ne]),ne||F},z=(P,F,B,Y)=>{const J=g(P.clipSrc||""),[Z,K]=G(J,"anonymous"),U=P.clipSrc?K:"loaded";(0,e.useImageLoader)(U,P.id+"-clip");const W=i.default.useMemo(()=>{if(F&&Z)return v()},[F,Z]);return i.default.useLayoutEffect(()=>{var X;if(!Z||!F||!F.width||!F.height||!Z||!Z.width||!Z.height||!W)return;const ee=v(),te=Math.max(P.a.width/Z.width*B,P.a.height/Z.height*B);ee.width=Z.width*te,ee.height=Z.height*te,(X=ee.getContext("2d"))===null||X===void 0||X.drawImage(Z,0,0,ee.width,ee.height),W.width=Math.max(F.width,1),W.height=Math.max(F.height,1);const ne=W.getContext("2d");ne&&(ne.save(),ne.drawImage(ee,0,0,F.width,F.height),u.default.Util.releaseCanvas(ee),ne.globalCompositeOperation="source-in",ne.drawImage(F,0,0,W.width,W.height),ne.restore())},[W,F,Z,P.a.width,P.a.height,B,...Y]),P.clipSrc&&Z?W:F},I=v(),H=(0,o.observer)(({element:P})=>{const F=Math.min(30,P.a.width/4,P.a.height/4),B=i.default.useRef(null);return i.default.useEffect(()=>{const Y=B.current;if(!Y)return;const J=new u.default.Animation(Z=>{Y.rotate(((Z==null?void 0:Z.timeDiff)||0)/2)},Y.getLayer());return J.start(),()=>{J.stop()}}),i.default.createElement(s.Group,{x:P.x,y:P.y,rotation:P.rotation,listening:!1,opacity:P.a.opacity,hideInExport:!P.showInExport},i.default.createElement(s.Rect,{width:P.a.width,height:P.a.height,fill:"rgba(124, 173, 212, 0.8)"}),i.default.createElement(s.Arc,{ref:B,x:P.a.width/2,y:P.a.height/2,fill:"white",outerRadius:Math.abs(F),innerRadius:Math.max(1,F-5),angle:270}))}),N=(0,o.observer)(({element:P})=>{const F="Can not load the image...",B=Math.max(10,Math.min(30,P.a.width/25));return i.default.createElement(s.Group,{x:P.x,y:P.y,rotation:P.rotation,listening:!1,opacity:P.a.opacity,hideInExport:!P.showInExport},i.default.createElement(s.Rect,{width:P.a.width,height:P.a.height,fill:"rgba(223, 102, 102, 0.8)"}),i.default.createElement(s.Text,{text:F,fontSize:B,width:P.a.width,height:P.a.height,align:"center",fill:"white",verticalAlign:"middle",padding:5}))});let G=c.default;const D=P=>{G=P};e.setImageLoaderHook=D;const q=(P,F)=>{const B=i.default.useRef(),Y=()=>{var J;(J=B.current)===null||J===void 0||J.call(B),B.current=void 0};i.default.useEffect(()=>Y,[]),i.default.useLayoutEffect(()=>{P!=="loading"||B.current||(B.current=(0,d.incrementLoader)(`image ${F}`)),P!=="loading"&&Y(),P==="failed"&&(0,d.triggerLoadError)(`image ${F}`)},[P])};e.useImageLoader=q;const V=({image:P,status:F,type:B})=>{const Y=i.default.useRef();return i.default.useEffect(()=>{Y.current=P||Y.current},[P]),F!=="failed"||F!=="failed"&&B==="svg"?Y.current:void 0},R=P=>{const[F,B]=i.default.useReducer(K=>K+1,0),Y=i.default.useRef("loading"),J=i.default.useRef(P.src),Z=i.default.useRef(P.src);return Z.current!==P.src&&(Z.current=P.src,Y.current="loading"),i.default.useEffect(()=>{if(P.type==="image"||!P.src)return;let K=!1;return(async()=>{Y.current="loading",B();const U=await E.urlToString(P.src),W=E.fixSize(U),X=E.replaceColors(W,P.colorsReplace);K||(J.current=X,Y.current="loaded",B())})(),()=>{K=!0}},[P.src,JSON.stringify(P.colorsReplace)]),P.type==="image"?[P.src,"loaded"]:[J.current,Y.current]};e.ImageElement=(0,o.observer)(({element:P,store:F})=>{var B;const[Y,J]=i.default.useState(!1),Z=i.default.useRef(null),K=i.default.useRef(null),[U,W]=i.default.useState(!1),X=F.selectedElements.indexOf(P)>=0,[ee,te]=R(P),[ne,ce]=G(ee,"anonymous"),le=P.type!=="svg"||te==="loaded"?ce:"loading";(0,e.useImageLoader)(le,P.id);const Te=V({image:ne,status:ce,type:P.type}),Ce=T(P,M(P,ne||Te,F._elementsPixelRatio))||I;let{cropX:se,cropY:de,cropWidth:_e,cropHeight:Oe}=P;ce!=="loaded"&&(se=de=0,_e=Oe=1);const ae=Ce.width*_e,me=Ce.height*Oe,ve=P.a.width/P.a.height;let ye,Ie;const nt=ae/me,Qe=P.type==="svg";Qe?(ye=ae,Ie=me):ve>=nt?(ye=ae,Ie=ae/ve):(ye=me*ve,Ie=me);const ke={x:Ce.width*se,y:Ce.height*de,width:ye,height:Ie},Ge=(B=P.cornerRadius)!==null&&B!==void 0?B:0;let lt=z(P,A(P,Ce,ke,F._elementsPixelRatio,Ge,Y||P._cropModeEnabled||P.type==="svg"),F._elementsPixelRatio,[ke,Ge,F._elementsPixelRatio]);const st=Math.max(P.a.width/ye,P.a.height/Ie);i.default.useEffect(()=>{var Be;if(!P._cropModeEnabled)return;const ot=(Be=Z.current)===null||Be===void 0?void 0:Be.getStage();function wt(pn){P._cropModeEnabled&&pn.target!==K.current&&P.toggleCropMode(!1)}function Ft(pn){P._cropModeEnabled&&pn.target.nodeName!=="CANVAS"&&P.toggleCropMode(!1)}return document.body.addEventListener("click",Ft),ot==null||ot.on("click",wt),ot==null||ot.on("tap",wt),()=>{document.body.removeEventListener("click",Ft),document.body.removeEventListener("touchstart",Ft),ot==null||ot.off("click",wt),ot==null||ot.off("click",wt)}},[P._cropModeEnabled]),i.default.useLayoutEffect(()=>{if(!(Y||P._cropModeEnabled))return(0,S.applyFilter)(Z.current,P),(0,l.autorun)(()=>{(0,S.applyFilter)(Z.current,P)},{delay:100})},[Ce,Y,_e,Oe,P._cropModeEnabled]),i.default.useLayoutEffect(()=>{var Be;Y||P._cropModeEnabled?(Be=Z.current)===null||Be===void 0||Be.clearCache():(0,S.applyFilter)(Z.current,P)},[Y,P.a.width,P.a.height,P._cropModeEnabled]),i.default.useEffect(()=>{(0,S.applyFilter)(Z.current,P)},[P.shadowEnabled,P.shadowBlur,P.cornerRadius,P.shadowColor,P.shadowOffsetX,P.shadowOffsetY,P.shadowOpacity]);const ie=i.default.useRef(null),fe=i.default.useRef(null),He=i.default.useRef(null);i.default.useLayoutEffect(()=>{P._cropModeEnabled&&(fe.current.nodes([ie.current]),He.current.nodes([K.current]))},[P._cropModeEnabled]);const we=Be=>{Math.round(Be.target.x())>0&&(Be.target.x(0),Be.target.scaleX(1)),Math.round(Be.target.y())>0&&(Be.target.y(0),Be.target.scaleY(1));const ot=Be.target.width()*Be.target.scaleX(),wt=Be.target.height()*Be.target.scaleY(),Ft=Math.min(1,ye/ot),pn=Math.min(1,Ie/wt),Er=1-Ft,Yn=Math.min(Er,Math.max(0,Math.round(-Be.target.x())/ot)),lr=1-pn,Sr=Math.min(lr,Math.max(0,Math.round(-Be.target.y())/wt));Be.target.setAttrs({x:-Yn*Ce.width,y:-Sr*Ce.height,scaleX:1,scaleY:1}),P.set({cropX:Yn,cropY:Sr,cropWidth:Ft,cropHeight:pn})},Ke=()=>{P.type!=="svg"&&P.contentEditable&&setTimeout(()=>{P.toggleCropMode(!0)})},Se=P.type==="svg"&&Te,et=ce==="loading"&&!Se,ln=ce==="failed",Pe=!et&&!ln,Ye=i.default.useRef({cropX:0,cropY:0,cropWidth:0,cropHeight:0}),mt=Pe?P.a.opacity:0;(0,_.useFadeIn)(Z,mt);const Ht=P.selectable||F.role==="admin",At=(0,y.useMobile)();return i.default.createElement(i.default.Fragment,null,et&&i.default.createElement(H,{element:P}),ln&&i.default.createElement(N,{element:P}),i.default.createElement(s.Image,{ref:Z,name:"element",id:P.id,image:lt,x:P.a.x,y:P.a.y,width:P.a.width||1,height:P.a.height||1,rotation:P.rotation,opacity:mt,shadowEnabled:P.shadowEnabled,shadowBlur:P.shadowBlur,shadowOffsetX:P.shadowOffsetX,shadowOffsetY:P.shadowOffsetY,shadowColor:P.shadowColor,shadowOpacity:P.shadowOpacity,customCrop:ke,listening:Ht,draggable:At?P.draggable&&X:P.draggable,preventDefault:!At||X,hideInExport:!P.showInExport,onMouseEnter:()=>{W(!0)},onMouseLeave:()=>{W(!1)},onDragStart:()=>{F.history.startTransaction()},onDragMove:Be=>{P.set({x:Be.target.x(),y:Be.target.y()})},onDragEnd:Be=>{P.set({x:Be.target.x(),y:Be.target.y()}),F.history.endTransaction()},onDblClick:Ke,onDblTap:Ke,onTransformStart:()=>{J(!0),F.history.startTransaction(),Ye.current={cropX:P.cropX,cropY:P.cropY,cropWidth:P.cropWidth,cropHeight:P.cropHeight}},onTransform:Be=>{var ot;const wt=Be.currentTarget,Ft=Math.abs(wt.scaleX()-1)<1e-7?1:wt.scaleX(),pn=Math.abs(wt.scaleY()-1)<1e-7?1:wt.scaleY();wt.scaleX(1),wt.scaleY(1);const Er=(ot=Be.target.getStage())===null||ot===void 0?void 0:ot.findOne("Transformer"),Yn=1-ye/Ce.width,lr=Math.min(Yn,Math.max(0,P.cropX)),Sr=1-Ie/Ce.height,Ja=Math.min(Sr,Math.max(0,P.cropY)),m1=Er.getActiveAnchor(),g1=!(m1.indexOf("middle")>=0||m1.indexOf("center")>=0),pl=!g1&&Ft<1&&Ye.current.cropHeight>Ie/Ce.height;let Wi=g1?P.cropWidth:P.cropWidth*Ft;pl&&(Wi=P.cropWidth);const gu=!g1&&pn<1&&Ye.current.cropWidth>ye/Ce.width;let ei=g1?P.cropHeight:P.cropHeight*pn;gu&&(ei=P.cropHeight),Qe&&(Wi=P.cropWidth,ei=P.cropHeight),P.set({cropX:lr,cropY:Ja,x:wt.x(),y:wt.y(),width:wt.width()*Ft,height:wt.height()*pn,rotation:Be.target.rotation(),cropWidth:Math.min(Wi,1-lr),cropHeight:Math.min(ei,1-Ja)})},onTransformEnd:Be=>{const ot=Be.currentTarget;P.set({width:ot.width(),height:ot.height(),x:ot.x(),y:ot.y(),rotation:Be.target.rotation(),cropWidth:ye/Ce.width,cropHeight:Ie/Ce.height}),J(!1),F.history.endTransaction()}}),i.default.createElement(s.Rect,{x:P.x,y:P.y,width:Math.max(P.a.width-P.borderSize,0),height:Math.max(P.a.height-P.borderSize,0),opacity:mt,offsetX:-P.borderSize/2,offsetY:-P.borderSize/2,stroke:P.borderColor,strokeWidth:P.borderSize,listening:!1,visible:!!P.borderSize,rotation:P.rotation,cornerRadius:Math.max(0,Ge-P.borderSize),hideInExport:!P.showInExport}),P._cropModeEnabled&&i.default.createElement(p.Portal,{selector:".page-abs-container",enabled:!0},i.default.createElement(s.Rect,{x:-window.innerWidth/F.scale,y:-window.innerWidth/F.scale,width:window.innerWidth/F.scale*3,height:window.innerWidth/F.scale*3,fill:"rgba(0,0,0,0.3)"}),i.default.createElement(s.Image,{listening:!1,image:lt,x:P.x,y:P.y,width:P.a.width,height:P.a.height,rotation:P.rotation,shadowEnabled:P.shadowEnabled,shadowBlur:P.shadowBlur}),i.default.createElement(s.Group,{x:P.x,y:P.y,rotation:P.rotation,scaleX:st,scaleY:st},i.default.createElement(s.Image,{image:Ce,ref:K,opacity:.4,draggable:!0,x:-P.cropX*Ce.width,y:-P.cropY*Ce.height,onDragMove:we,onTransform:we}),i.default.createElement(s.Transformer,{ref:He,anchorSize:20,enabledAnchors:["top-left","top-right","bottom-left","bottom-right"],boundBoxFunc:(Be,ot)=>ot.width<5||ot.height<5?Be:ot,rotateEnabled:!1,borderEnabled:!1,anchorCornerRadius:10,anchorStrokeWidth:2,borderStrokeWidth:2}),i.default.createElement(s.Rect,{width:ye,height:Ie,ref:ie,listening:!1,onTransform:Be=>{Be.target.x()<-P.cropX*Ce.width-1e-9&&(Be.target.x(-P.cropX*Ce.width),Be.target.scaleX(1)),Be.target.y()<-P.cropY*Ce.height-1e-9&&(Be.target.y(-P.cropY*Ce.height),Be.target.scaleY(1));const ot=Math.min(1,Math.max(0,P.cropX+Be.target.x()/Ce.width)),wt=Math.min(1,Math.max(0,Be.target.y()/Ce.height+P.cropY)),Ft=Be.target.width()*Be.target.scaleX(),pn=Be.target.height()*Be.target.scaleY(),Er=Math.min(1-ot,Ft/Ce.width),Yn=Math.min(1-wt,pn/Ce.height),lr=Be.target.getAbsolutePosition(Be.target.getParent().getParent());Be.target.scale({x:1,y:1}),Be.target.position({x:0,y:0}),P.set({x:lr.x,y:lr.y,cropX:ot,cropY:wt,cropWidth:Er,cropHeight:Yn,width:Math.min(Ft*st,Ce.width*(1-ot)*st),height:Math.min(pn*st,Ce.height*(1-wt)*st)})}}),i.default.createElement(s.Transformer,{ref:fe,enabledAnchors:["top-left","top-right","bottom-left","bottom-right"],boundBoxFunc:(Be,ot)=>ot.width<5||ot.height<5?Be:ot,keepRatio:!1,rotateEnabled:!1,anchorFill:"rgb(240, 240, 240)",anchorStrokeWidth:2,borderStrokeWidth:2}))),(U||X)&&i.default.createElement(h.Highlighter,{element:P}))})})(vp);var ay={},aL={exports:{}};/*!
90
90
  * Quill Editor v1.3.7
91
91
  * https://quilljs.com/
92
92
  * Copyright (c) 2014, Jason Chen
@@ -244,7 +244,7 @@ PERFORMANCE OF THIS SOFTWARE.
244
244
  `)}var Mbe=0,zbe=function(){function e(){Object.defineProperty(this,"cacheId",{enumerable:!0,configurable:!0,writable:!0,value:Mbe++}),Object.defineProperty(this,"cache",{enumerable:!0,configurable:!0,writable:!0,value:Bt.map()}),Object.defineProperty(this,"lastCacheModificationPerId",{enumerable:!0,configurable:!0,writable:!0,value:Bt.map()})}return Object.defineProperty(e.prototype,"updateLastCacheModificationPerId",{enumerable:!1,configurable:!0,writable:!0,value:function(t){var n=this.lastCacheModificationPerId.get(t);this.lastCacheModificationPerId.set(t,n===void 0?1:n+1)}}),Object.defineProperty(e.prototype,"getLastCacheModificationPerId",{enumerable:!1,configurable:!0,writable:!0,value:function(t){var n=this.lastCacheModificationPerId.get(t)||0;return this.cacheId+"-"+n}}),Object.defineProperty(e.prototype,"addNodeToCache",{enumerable:!1,configurable:!0,writable:!0,value:function(t,n){if(n===void 0&&(n=!0),t.identifierAttribute){var r=t.identifier;this.cache.has(r)||this.cache.set(r,Bt.array([],Vp));var a=this.cache.get(r);if(a.indexOf(t)!==-1)throw $e("Already registered");a.push(t),n&&this.updateLastCacheModificationPerId(r)}}}),Object.defineProperty(e.prototype,"mergeCache",{enumerable:!1,configurable:!0,writable:!0,value:function(t){var n=this;zg(t.identifierCache.cache).forEach(function(r){return r.forEach(function(a){n.addNodeToCache(a)})})}}),Object.defineProperty(e.prototype,"notifyDied",{enumerable:!1,configurable:!0,writable:!0,value:function(t){if(t.identifierAttribute){var n=t.identifier,r=this.cache.get(n);r&&(r.remove(t),r.length||this.cache.delete(n),this.updateLastCacheModificationPerId(t.identifier))}}}),Object.defineProperty(e.prototype,"splitCache",{enumerable:!1,configurable:!0,writable:!0,value:function(t){var n=this,r=new e,a=t.path;return jx(this.cache).forEach(function(i){for(var o=Ib(i,2),l=o[0],s=o[1],c=!1,u=s.length-1;u>=0;u--)s[u].path.indexOf(a)===0&&(r.addNodeToCache(s[u],!1),s.splice(u,1),c=!0);c&&n.updateLastCacheModificationPerId(l)}),r}}),Object.defineProperty(e.prototype,"has",{enumerable:!1,configurable:!0,writable:!0,value:function(t,n){var r=this.cache.get(n);return r?r.some(function(a){return t.isAssignableFrom(a.type)}):!1}}),Object.defineProperty(e.prototype,"resolve",{enumerable:!1,configurable:!0,writable:!0,value:function(t,n){var r=this.cache.get(n);if(!r)return null;var a=r.filter(function(i){return t.isAssignableFrom(i.type)});switch(a.length){case 0:return null;case 1:return a[0];default:throw $e("Cannot resolve a reference to type '"+t.name+"' with id: '"+n+"' unambigously, there are multiple candidates: "+a.map(function(i){return i.path}).join(", "))}}}),e}();function Fb(e,t,n,r,a){var i=DH(a);if(i){if(i.parent)throw $e("Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '"+(t?t.path:"")+"/"+n+"', but it lives already at '"+i.path+"'");return t&&i.setParent(t,n),i}return new u1(e,t,n,r,a)}function $s(e,t,n,r,a){return new u2(e,t,n,r,a)}function Tbe(e){return e instanceof u2||e instanceof u1}var Jn;(function(e){e[e.INITIALIZING=0]="INITIALIZING",e[e.CREATED=1]="CREATED",e[e.FINALIZED=2]="FINALIZED",e[e.DETACHING=3]="DETACHING",e[e.DEAD=4]="DEAD"})(Jn||(Jn={}));function Nt(e){return!!(e&&e.$treenode)}function qe(e){if(!Nt(e))throw $e("Value "+e+" is no MST Node");return e.$treenode}function DH(e){return e&&e.$treenode||null}function Pbe(){return qe(this).snapshot}var xbe=function(e){return".."};function FH(e,t){if(e.root!==t.root)throw $e("Cannot calculate relative path: objects '"+e+"' and '"+t+"' are not part of the same object tree");for(var n=kc(e.path),r=kc(t.path),a=0;a<n.length&&n[a]===r[a];a++);return n.slice(a).map(xbe).join("/")+V4(r.slice(a))}function $H(e,t,n){return n===void 0&&(n=!0),BH(e,kc(t),n)}function BH(e,t,n){n===void 0&&(n=!0);for(var r=e,a=0;a<t.length;a++){var i=t[a];if(i===".."){if(r=r.parent,r)continue}else{if(i===".")continue;if(r){if(r instanceof u2)try{var o=r.value;Nt(o)&&(r=qe(o))}catch(s){if(!n)return;throw s}if(r instanceof u1){var l=r.getChildType(i);if(l&&(r=r.getChildNode(i),r))continue}}}if(n)throw $e("Could not resolve '"+i+"' in path '"+(V4(t.slice(0,a))||"/")+"' while resolving '"+V4(t)+"'");return}return r}function jH(e){if(!e)return Ic;var t=Object.keys(e);if(!t.length)return Ic;var n=new Array(t.length);return t.forEach(function(r,a){n[a]=e[r]}),n}function Abe(e){return qH(),KH(e)}var Lbe=Object.toString(),Ic=Object.freeze([]),vs=Object.freeze({}),Vp=yx().useProxies?{deep:!1}:{deep:!1,proxy:!1};Object.freeze(Vp);function $e(e){return e===void 0&&(e="Illegal state"),new Error("[mobx-state-tree] "+e)}function Rbe(e){return e}var Ibe=Number.isInteger||function(e){return typeof e=="number"&&isFinite(e)&&Math.floor(e)===e};function $b(e){return Array.isArray(e)||Rr(e)}function Bb(e){return e?$b(e)?e:[e]:Ic}function Nbe(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];for(var r=0;r<t.length;r++){var a=t[r];for(var i in a)e[i]=a[i]}return e}function Ul(e){var t;if(e===null||typeof e!="object")return!1;var n=Object.getPrototypeOf(e);return n==null?!0:((t=n.constructor)===null||t===void 0?void 0:t.toString())===Lbe}function UH(e){return e!==null&&typeof e=="object"&&!(e instanceof Date)&&!(e instanceof RegExp)}function Nc(e,t){return t===void 0&&(t=!0),e==null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"||t&&e instanceof Date}function kbe(e){return typeof e!="function"}function Hbe(e,t,n){Wn(e)?Pg(e,t,n):Object.defineProperty(e,t,n)}function es(e,t,n){Hbe(e,t,{enumerable:!1,writable:!1,configurable:!0,value:n})}var Vbe=function(){function e(){Object.defineProperty(this,"handlers",{enumerable:!0,configurable:!0,writable:!0,value:[]})}return Object.defineProperty(e.prototype,"hasSubscribers",{get:function(){return this.handlers.length>0},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"register",{enumerable:!1,configurable:!0,writable:!0,value:function(t,n){var r=this;return n===void 0&&(n=!1),n?this.handlers.unshift(t):this.handlers.push(t),function(){r.unregister(t)}}}),Object.defineProperty(e.prototype,"has",{enumerable:!1,configurable:!0,writable:!0,value:function(t){return this.handlers.indexOf(t)>=0}}),Object.defineProperty(e.prototype,"unregister",{enumerable:!1,configurable:!0,writable:!0,value:function(t){var n=this.handlers.indexOf(t);n>=0&&this.handlers.splice(n,1)}}),Object.defineProperty(e.prototype,"clear",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.handlers.length=0}}),Object.defineProperty(e.prototype,"emit",{enumerable:!1,configurable:!0,writable:!0,value:function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var r=this.handlers.slice();r.forEach(function(a){return a.apply(void 0,ul(t))})}}),e}(),GH=function(){function e(){Object.defineProperty(this,"eventHandlers",{enumerable:!0,configurable:!0,writable:!0,value:void 0})}return Object.defineProperty(e.prototype,"hasSubscribers",{enumerable:!1,configurable:!0,writable:!0,value:function(t){var n=this.eventHandlers&&this.eventHandlers[t];return!!n&&n.hasSubscribers}}),Object.defineProperty(e.prototype,"register",{enumerable:!1,configurable:!0,writable:!0,value:function(t,n,r){r===void 0&&(r=!1),this.eventHandlers||(this.eventHandlers={});var a=this.eventHandlers[t];return a||(a=this.eventHandlers[t]=new Vbe),a.register(n,r)}}),Object.defineProperty(e.prototype,"has",{enumerable:!1,configurable:!0,writable:!0,value:function(t,n){var r=this.eventHandlers&&this.eventHandlers[t];return!!r&&r.has(n)}}),Object.defineProperty(e.prototype,"unregister",{enumerable:!1,configurable:!0,writable:!0,value:function(t,n){var r=this.eventHandlers&&this.eventHandlers[t];r&&r.unregister(n)}}),Object.defineProperty(e.prototype,"clear",{enumerable:!1,configurable:!0,writable:!0,value:function(t){this.eventHandlers&&delete this.eventHandlers[t]}}),Object.defineProperty(e.prototype,"clearAll",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.eventHandlers=void 0}}),Object.defineProperty(e.prototype,"emit",{enumerable:!1,configurable:!0,writable:!0,value:function(t){for(var n,r=[],a=1;a<arguments.length;a++)r[a-1]=arguments[a];var i=this.eventHandlers&&this.eventHandlers[t];i&&(n=i).emit.apply(n,ul(r))}}),e}();function WH(e){for(var t=new Array(e.length),n=0;n<e.length;n++)t[n]=e[n];return t}function jm(e,t){return e.indexOf(t)===0}var qH=function(e,t){};qH.ids={};function Dbe(e){console.warn(new Error("[mobx-state-tree] "+e))}function Fbe(){return typeof process<"u"&&process.env&&{}.ENABLE_TYPE_CHECK==="true"}function Um(e){typeof queueMicrotask=="function"?queueMicrotask(e):typeof setImmediate=="function"?setImmediate(e):setTimeout(e,1)}function KH(e){return Ube(e.name,e)}function $be(e){return e}function Bbe(e){return function(){var t,n=[];for(t=0;t<arguments.length;t++)n[t]=arguments[t];return bH(this,function(r){switch(r.label){case 0:return[4,e.apply(void 0,ul(n))];case 1:return[2,r.sent()]}})}}function jbe(e){return bH(this,function(t){switch(t.label){case 0:return[4,e];case 1:return[2,t.sent()]}})}function Ube(e,t){var n=function(){var a=RH(),i=Hb();if(!i)throw $e("a mst flow must always have a parent context");var o=IH(i);if(!o)throw $e("a mst flow must always have a parent action context");var l={name:e,id:a,tree:i.tree,context:i.context,parentId:i.id,allParentIds:ul(i.allParentIds,[i.id]),rootId:i.rootId,parentEvent:i,parentActionEvent:o},s=arguments;function c(u,p,h){return u.$mst_middleware=n.$mst_middleware,e8(Ur(Ur({},l),{type:p,args:[h]}),u)}return new Promise(function(u,p){var h,d=function(){h=t.apply(null,arguments),E(void 0)};d.$mst_middleware=n.$mst_middleware,e8(Ur(Ur({},l),{type:"flow_spawn",args:WH(s)}),d);function E(_){var y;try{var v=c(function(b){y=h.next(b)},"flow_resume",_);v instanceof Error&&(y=h.throw(v))}catch(b){Um(function(){c(function(g){p(b)},"flow_throw",b)});return}S(y)}function w(_){var y;try{c(function(v){y=h.throw(v)},"flow_resume_error",_)}catch(v){Um(function(){c(function(b){p(v)},"flow_throw",v)});return}S(y)}function S(_){if(_.done){Um(function(){c(function(y){u(y)},"flow_return",_.value)});return}if(!_.value||typeof _.value.then!="function")throw $e("Only promises can be yielded to `async`, got: "+_);return _.value.then(E,w)}})};return n}function Gbe(e){if(!("oldValue"in e))throw $e("Patches without `oldValue` field cannot be inversed");return[Wbe(e),qbe(e)]}function Wbe(e){switch(e.op){case"add":return{op:"add",path:e.path,value:e.value};case"remove":return{op:"remove",path:e.path};case"replace":return{op:"replace",path:e.path,value:e.value}}}function qbe(e){switch(e.op){case"add":return{op:"remove",path:e.path};case"remove":return{op:"add",path:e.path,value:e.oldValue};case"replace":return{op:"replace",path:e.path,value:e.oldValue}}}function Kbe(e){return typeof e=="number"}function Ao(e){return Kbe(e)===!0?""+e:e.indexOf("/")===-1&&e.indexOf("~")===-1?e:e.replace(/~/g,"~0").replace(/\//g,"~1")}function YH(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function V4(e){if(e.length===0)return"";var t=function(n){return n.map(Ao).join("/")};return e[0]==="."||e[0]===".."?t(e):"/"+t(e)}function kc(e){var t=e.split("/").map(YH),n=e===""||e==="."||e===".."||jm(e,"/")||jm(e,"./")||jm(e,"../");if(!n)throw $e("a json path must be either rooted, empty or relative, but got '"+e+"'");return t[0]===""&&t.shift(),t}var Gm=Symbol("$preProcessorFailed"),Ybe=function(e){on(t,e);function t(n,r,a){var i=e.call(this,a||n.name)||this;return Object.defineProperty(i,"_subtype",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(i,"_processors",{enumerable:!0,configurable:!0,writable:!0,value:r}),i}return Object.defineProperty(t.prototype,"flags",{get:function(){return this._subtype.flags|vt.SnapshotProcessor},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return"snapshotProcessor("+this._subtype.describe()+")"}}),Object.defineProperty(t.prototype,"preProcessSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(n){return this._processors.preProcessor?this._processors.preProcessor.call(null,n):n}}),Object.defineProperty(t.prototype,"preProcessSnapshotSafe",{enumerable:!1,configurable:!0,writable:!0,value:function(n){try{return this.preProcessSnapshot(n)}catch{return Gm}}}),Object.defineProperty(t.prototype,"postProcessSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(n){return this._processors.postProcessor?this._processors.postProcessor.call(null,n):n}}),Object.defineProperty(t.prototype,"_fixNode",{enumerable:!1,configurable:!0,writable:!0,value:function(n){var r=this;Xbe(n.type,this,"create");var a=n.getSnapshot;n.getSnapshot=function(){return r.postProcessSnapshot(a.call(n))},lV(this._subtype)||(n.getReconciliationType=function(){return r})}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r,a,i){var o=Nt(i)?i:this.preProcessSnapshot(i),l=this._subtype.instantiate(n,r,a,o);return this._fixNode(l),l}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r,a,i){var o=this._subtype.reconcile(n,Nt(r)?r:this.preProcessSnapshot(r),a,i);return o!==n&&this._fixNode(o),o}}),Object.defineProperty(t.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){r===void 0&&(r=!0);var a=this._subtype.getSnapshot(n);return r?this.postProcessSnapshot(a):a}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){var a=this.preProcessSnapshotSafe(n);return a===Gm?p1(r,n,"Failed to preprocess value"):this._subtype.validate(a,r)}}),Object.defineProperty(t.prototype,"getSubTypes",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subtype}}),Object.defineProperty(t.prototype,"is",{enumerable:!1,configurable:!0,writable:!0,value:function(n){var r=_r(n)?this._subtype:Nt(n)?Nb(n,!1):this.preProcessSnapshotSafe(n);return r===Gm?!1:this._subtype.validate(r,[{path:"",type:this._subtype}]).length===0}}),Object.defineProperty(t.prototype,"isAssignableFrom",{enumerable:!1,configurable:!0,writable:!0,value:function(n){return this._subtype.isAssignableFrom(n)}}),Object.defineProperty(t.prototype,"isMatchingSnapshotId",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){if(!(this._subtype instanceof Rc))return!1;var a=this.preProcessSnapshot(r);return this._subtype.isMatchingSnapshotId(n,a)}}),t}(Li);function Xbe(e,t){for(var n,r,a=[],i=2;i<arguments.length;i++)a[i-2]=arguments[i];try{for(var o=H4(a),l=o.next();!l.done;l=o.next()){var s=l.value;e[s]=t[s].bind(t)}}catch(c){n={error:c}}finally{try{l&&!l.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}}function Qbe(e,t,n){return new Ybe(e,t,n)}var uM="Map.put can only be used to store complex values that have an identifier type attribute";function XH(e,t){var n,r,a=e.getSubTypes();if(a===xH)return!1;if(a){var i=Bb(a);try{for(var o=H4(i),l=o.next();!l.done;l=o.next()){var s=l.value;if(!XH(s,t))return!1}}catch(c){n={error:c}}finally{try{l&&!l.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}}return e instanceof d2&&t.push(e),!0}var mo;(function(e){e[e.UNKNOWN=0]="UNKNOWN",e[e.YES=1]="YES",e[e.NO=2]="NO"})(mo||(mo={}));var Zbe=function(e){on(t,e);function t(n){return e.call(this,n,Bt.ref.enhancer)||this}return Object.defineProperty(t.prototype,"get",{enumerable:!1,configurable:!0,writable:!0,value:function(n){return e.prototype.get.call(this,""+n)}}),Object.defineProperty(t.prototype,"has",{enumerable:!1,configurable:!0,writable:!0,value:function(n){return e.prototype.has.call(this,""+n)}}),Object.defineProperty(t.prototype,"delete",{enumerable:!1,configurable:!0,writable:!0,value:function(n){return e.prototype.delete.call(this,""+n)}}),Object.defineProperty(t.prototype,"set",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){return e.prototype.set.call(this,""+n,r)}}),Object.defineProperty(t.prototype,"put",{enumerable:!1,configurable:!0,writable:!0,value:function(n){if(!n)throw $e("Map.put cannot be used to set empty values");if(Nt(n)){var r=qe(n);if(r.identifier===null)throw $e(uM);return this.set(r.identifier,n),n}else if(UH(n)){var a=qe(this),i=a.type;if(i.identifierMode!==mo.YES)throw $e(uM);var o=i.mapIdentifierAttribute,l=n[o];if(!Ub(l)){var s=this.put(i.getChildType().create(n,a.environment));return this.put(Nb(s))}var c=lu(l);return this.set(c,n),this.get(c)}else throw $e("Map.put can only be used to store complex values")}}),t}(b3),D4=function(e){on(t,e);function t(n,r,a){a===void 0&&(a=[]);var i=e.call(this,n)||this;return Object.defineProperty(i,"_subType",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(i,"identifierMode",{enumerable:!0,configurable:!0,writable:!0,value:mo.UNKNOWN}),Object.defineProperty(i,"mapIdentifierAttribute",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,"flags",{enumerable:!0,configurable:!0,writable:!0,value:vt.Map}),Object.defineProperty(i,"hookInitializers",{enumerable:!0,configurable:!0,writable:!0,value:[]}),i._determineIdentifierMode(),i.hookInitializers=a,i}return Object.defineProperty(t.prototype,"hooks",{enumerable:!1,configurable:!0,writable:!0,value:function(n){var r=this.hookInitializers.length>0?this.hookInitializers.concat(n):[n];return new t(this.name,this._subType,r)}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r,a,i){return this._determineIdentifierMode(),Fb(this,n,r,a,i)}}),Object.defineProperty(t.prototype,"_determineIdentifierMode",{enumerable:!1,configurable:!0,writable:!0,value:function(){if(this.identifierMode===mo.UNKNOWN){var n=[];if(XH(this._subType,n)){var r=n.reduce(function(a,i){if(!i.identifierAttribute)return a;if(a&&a!==i.identifierAttribute)throw $e("The objects in a map should all have the same identifier attribute, expected '"+a+"', but child of type '"+i.name+"' declared attribute '"+i.identifierAttribute+"' as identifier");return i.identifierAttribute},void 0);r?(this.identifierMode=mo.YES,this.mapIdentifierAttribute=r):this.identifierMode=mo.NO}}}}),Object.defineProperty(t.prototype,"initializeChildNodes",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){r===void 0&&(r={});var a=n.type._subType,i={};return Object.keys(r).forEach(function(o){i[o]=a.instantiate(n,o,void 0,r[o])}),i}}),Object.defineProperty(t.prototype,"createNewInstance",{enumerable:!1,configurable:!0,writable:!0,value:function(n){return new Zbe(n)}}),Object.defineProperty(t.prototype,"finalizeNewInstance",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){Mg(r,n.unbox);var a=n.type;a.hookInitializers.forEach(function(i){var o=i(r);Object.keys(o).forEach(function(l){var s=o[l],c=f2(r,l,s);es(r,l,c)})}),m3(r,this.willChange),y3(r,this.didChange)}}),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return"Map<string, "+this._subType.describe()+">"}}),Object.defineProperty(t.prototype,"getChildren",{enumerable:!1,configurable:!0,writable:!0,value:function(n){return zg(n.storedValue)}}),Object.defineProperty(t.prototype,"getChildNode",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){var a=n.storedValue.get(""+r);if(!a)throw $e("Not a child "+r);return a}}),Object.defineProperty(t.prototype,"willChange",{enumerable:!1,configurable:!0,writable:!0,value:function(n){var r=qe(n.object),a=n.name;r.assertWritable({subpath:a});var i=r.type,o=i._subType;switch(n.type){case"update":{var l=n.newValue,s=n.object.get(a);if(l===s)return null;Ei(o,l),n.newValue=o.reconcile(r.getChildNode(a),n.newValue,r,a),i.processIdentifier(a,n.newValue)}break;case"add":Ei(o,n.newValue),n.newValue=o.instantiate(r,a,void 0,n.newValue),i.processIdentifier(a,n.newValue);break}return n}}),Object.defineProperty(t.prototype,"processIdentifier",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){if(this.identifierMode===mo.YES&&r instanceof u1){var a=r.identifier;if(a!==n)throw $e("A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '"+a+"', but expected: '"+n+"'")}}}),Object.defineProperty(t.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(n){var r={};return n.getChildren().forEach(function(a){r[a.subpath]=a.snapshot}),r}}),Object.defineProperty(t.prototype,"processInitialSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(n){var r={};return Object.keys(n).forEach(function(a){r[a]=n[a].getSnapshot()}),r}}),Object.defineProperty(t.prototype,"didChange",{enumerable:!1,configurable:!0,writable:!0,value:function(n){var r=qe(n.object);switch(n.type){case"update":return void r.emitPatch({op:"replace",path:Ao(n.name),value:n.newValue.snapshot,oldValue:n.oldValue?n.oldValue.snapshot:void 0},r);case"add":return void r.emitPatch({op:"add",path:Ao(n.name),value:n.newValue.snapshot,oldValue:void 0},r);case"delete":var a=n.oldValue.snapshot;return n.oldValue.die(),void r.emitPatch({op:"remove",path:Ao(n.name),oldValue:a},r)}}}),Object.defineProperty(t.prototype,"applyPatchLocally",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r,a){var i=n.storedValue;switch(a.op){case"add":case"replace":i.set(r,a.value);break;case"remove":i.delete(r);break}}}),Object.defineProperty(t.prototype,"applySnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){Ei(this,r);var a=n.storedValue,i={};if(Array.from(a.keys()).forEach(function(l){i[l]=!1}),r)for(var o in r)a.set(o,r[o]),i[""+o]=!0;Object.keys(i).forEach(function(l){i[l]===!1&&a.delete(l)})}}),Object.defineProperty(t.prototype,"getChildType",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subType}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){var a=this;return Ul(n)?Hp(Object.keys(n).map(function(i){return a._subType.validate(n[i],Db(r,i,a._subType))})):p1(r,n,"Value is not a plain object")}}),Object.defineProperty(t.prototype,"getDefaultSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(){return vs}}),Object.defineProperty(t.prototype,"removeChild",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){n.storedValue.delete(r)}}),t}(Rc);D4.prototype.applySnapshot=Rn(D4.prototype.applySnapshot);function Jbe(e){return new D4("map<string, "+e.name+">",e)}function e_e(e){return _r(e)&&(e.flags&vt.Map)>0}var F4=function(e){on(t,e);function t(n,r,a){a===void 0&&(a=[]);var i=e.call(this,n)||this;return Object.defineProperty(i,"_subType",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(i,"flags",{enumerable:!0,configurable:!0,writable:!0,value:vt.Array}),Object.defineProperty(i,"hookInitializers",{enumerable:!0,configurable:!0,writable:!0,value:[]}),i.hookInitializers=a,i}return Object.defineProperty(t.prototype,"hooks",{enumerable:!1,configurable:!0,writable:!0,value:function(n){var r=this.hookInitializers.length>0?this.hookInitializers.concat(n):[n];return new t(this.name,this._subType,r)}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r,a,i){return Fb(this,n,r,a,i)}}),Object.defineProperty(t.prototype,"initializeChildNodes",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){r===void 0&&(r=[]);var a=n.type._subType,i={};return r.forEach(function(o,l){var s=""+l;i[s]=a.instantiate(n,s,void 0,o)}),i}}),Object.defineProperty(t.prototype,"createNewInstance",{enumerable:!1,configurable:!0,writable:!0,value:function(n){return Bt.array(jH(n),Vp)}}),Object.defineProperty(t.prototype,"finalizeNewInstance",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){da(r).dehancer=n.unbox;var a=n.type;a.hookInitializers.forEach(function(i){var o=i(r);Object.keys(o).forEach(function(l){var s=o[l],c=f2(r,l,s);es(r,l,c)})}),m3(r,this.willChange),y3(r,this.didChange)}}),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subType.describe()+"[]"}}),Object.defineProperty(t.prototype,"getChildren",{enumerable:!1,configurable:!0,writable:!0,value:function(n){return n.storedValue.slice()}}),Object.defineProperty(t.prototype,"getChildNode",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){var a=Number(r);if(a<n.storedValue.length)return n.storedValue[a];throw $e("Not a child: "+r)}}),Object.defineProperty(t.prototype,"willChange",{enumerable:!1,configurable:!0,writable:!0,value:function(n){var r=qe(n.object);r.assertWritable({subpath:""+n.index});var a=r.type._subType,i=r.getChildren();switch(n.type){case"update":{if(n.newValue===n.object[n.index])return null;var o=fM(r,a,[i[n.index]],[n.newValue],[n.index]);if(!o)return null;n.newValue=o[0]}break;case"splice":{var l=n.index,s=n.removedCount,c=n.added,u=fM(r,a,i.slice(l,l+s),c,c.map(function(h,d){return l+d}));if(!u)return null;n.added=u;for(var p=l+s;p<i.length;p++)i[p].setParent(r,""+(p+c.length-s))}break}return n}}),Object.defineProperty(t.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(n){return n.getChildren().map(function(r){return r.snapshot})}}),Object.defineProperty(t.prototype,"processInitialSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(n){var r=[];return Object.keys(n).forEach(function(a){r.push(n[a].getSnapshot())}),r}}),Object.defineProperty(t.prototype,"didChange",{enumerable:!1,configurable:!0,writable:!0,value:function(n){var r=qe(n.object);switch(n.type){case"update":return void r.emitPatch({op:"replace",path:""+n.index,value:n.newValue.snapshot,oldValue:n.oldValue?n.oldValue.snapshot:void 0},r);case"splice":for(var a=n.removedCount-1;a>=0;a--)r.emitPatch({op:"remove",path:""+(n.index+a),oldValue:n.removed[a].snapshot},r);for(var a=0;a<n.addedCount;a++)r.emitPatch({op:"add",path:""+(n.index+a),value:r.getChildNode(""+(n.index+a)).snapshot,oldValue:void 0},r);return}}}),Object.defineProperty(t.prototype,"applyPatchLocally",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r,a){var i=n.storedValue,o=r==="-"?i.length:Number(r);switch(a.op){case"replace":i[o]=a.value;break;case"add":i.splice(o,0,a.value);break;case"remove":i.splice(o,1);break}}}),Object.defineProperty(t.prototype,"applySnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){Ei(this,r);var a=n.storedValue;a.replace(r)}}),Object.defineProperty(t.prototype,"getChildType",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subType}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){var a=this;return $b(n)?Hp(n.map(function(i,o){return a._subType.validate(i,Db(r,""+o,a._subType))})):p1(r,n,"Value is not an array")}}),Object.defineProperty(t.prototype,"getDefaultSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(){return Ic}}),Object.defineProperty(t.prototype,"removeChild",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){n.storedValue.splice(Number(r),1)}}),t}(Rc);F4.prototype.applySnapshot=Rn(F4.prototype.applySnapshot);function t_e(e){return new F4(e.name+"[]",e)}function fM(e,t,n,r,a){for(var i=!0,o=0;;o++){var l=o<=r.length-1,s=n[o],c=l?r[o]:void 0,u=""+a[o];if(Tbe(c)&&(c=c.storedValue),!s&&!l)break;if(!l)i=!1,n.splice(o,1),s instanceof u1&&s.createObservableInstanceIfNeeded(),s.die(),o--;else if(s)if(dM(s,c))n[o]=Wm(t,e,u,c,s);else{for(var h=void 0,d=o;d<n.length;d++)if(dM(n[d],c)){h=n.splice(d,1)[0];break}i=!1;var p=Wm(t,e,u,c,h);n.splice(o,0,p)}else{if(Nt(c)&&qe(c).parent===e)throw $e("Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '"+e.path+"/"+u+"', but it lives already at '"+qe(c).path+"'");i=!1;var p=Wm(t,e,u,c);n.splice(o,0,p)}}return i?null:n}function Wm(e,t,n,r,a){Ei(e,r);function i(){if(Nt(r)){var l=qe(r);if(l.assertAlive(vs),l.parent!==null&&l.parent===t)return l.setParent(t,n),l}return a?e.reconcile(a,r,t,n):e.instantiate(t,n,void 0,r)}var o=i();return a&&a!==o&&(a instanceof u1&&a.createObservableInstanceIfNeeded(),a.die()),o}function dM(e,t){if(!e.isAlive)return!1;if(Nt(t)){var n=qe(t);return n.isAlive&&n===e}if(e.snapshot===t)return!0;if(!(e instanceof u1))return!1;var r=e.getReconciliationType();return e.identifier!==null&&e.identifierAttribute&&Ul(t)&&r.is(t)&&r.isMatchingSnapshotId(e,t)}function n_e(e){return _r(e)&&(e.flags&vt.Array)>0}var hM="preProcessSnapshot",pM="postProcessSnapshot";function r_e(){return qe(this).toString()}var vM={name:"AnonymousModel",properties:{},initializers:Ic};function a_e(e){return Object.keys(e).reduce(function(t,n){var r,a,i;if(n in Un)throw $e("Hook '"+n+"' was defined as property. Hooks should be defined as part of the actions");var o=Object.getOwnPropertyDescriptor(t,n);if("get"in o)throw $e("Getters are not supported as properties. Please use views instead");var l=o.value;if(l==null)throw $e("The default value of an attribute cannot be null or undefined as the type cannot be inferred. Did you mean `types.maybe(someType)`?");if(Nc(l))return Object.assign({},t,(r={},r[n]=ts(s_e(l),l),r));if(l instanceof D4)return Object.assign({},t,(a={},a[n]=ts(l,{}),a));if(l instanceof F4)return Object.assign({},t,(i={},i[n]=ts(l,[]),i));if(_r(l))return t;throw $e("Invalid type definition for property '"+n+"', cannot infer a type from a value like '"+l+"' ("+typeof l+")")},e)}var d2=function(e){on(t,e);function t(n){var r=e.call(this,n.name||vM.name)||this;return Object.defineProperty(r,"flags",{enumerable:!0,configurable:!0,writable:!0,value:vt.Object}),Object.defineProperty(r,"initializers",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"properties",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"preProcessor",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"postProcessor",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"propertyNames",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"named",{enumerable:!0,configurable:!0,writable:!0,value:function(a){return r.cloneAndEnhance({name:a})}}),Object.defineProperty(r,"props",{enumerable:!0,configurable:!0,writable:!0,value:function(a){return r.cloneAndEnhance({properties:a})}}),Object.defineProperty(r,"preProcessSnapshot",{enumerable:!0,configurable:!0,writable:!0,value:function(a){var i=r.preProcessor;return i?r.cloneAndEnhance({preProcessor:function(o){return i(a(o))}}):r.cloneAndEnhance({preProcessor:a})}}),Object.defineProperty(r,"postProcessSnapshot",{enumerable:!0,configurable:!0,writable:!0,value:function(a){var i=r.postProcessor;return i?r.cloneAndEnhance({postProcessor:function(o){return a(i(o))}}):r.cloneAndEnhance({postProcessor:a})}}),Object.assign(r,vM,n),r.properties=a_e(r.properties),r.properties,r.propertyNames=Object.keys(r.properties),r.identifierAttribute=r._getIdentifierAttribute(),r}return Object.defineProperty(t.prototype,"_getIdentifierAttribute",{enumerable:!1,configurable:!0,writable:!0,value:function(){var n=void 0;return this.forAllProps(function(r,a){if(a.flags&vt.Identifier){if(n)throw $e("Cannot define property '"+r+"' as object identifier, property '"+n+"' is already defined as identifier property");n=r}}),n}}),Object.defineProperty(t.prototype,"cloneAndEnhance",{enumerable:!1,configurable:!0,writable:!0,value:function(n){return new t({name:n.name||this.name,properties:Object.assign({},this.properties,n.properties),initializers:this.initializers.concat(n.initializers||[]),preProcessor:n.preProcessor||this.preProcessor,postProcessor:n.postProcessor||this.postProcessor})}}),Object.defineProperty(t.prototype,"actions",{enumerable:!1,configurable:!0,writable:!0,value:function(n){var r=this,a=function(i){return r.instantiateActions(i,n(i)),i};return this.cloneAndEnhance({initializers:[a]})}}),Object.defineProperty(t.prototype,"instantiateActions",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){if(!Ul(r))throw $e("actions initializer should return a plain object containing actions");Object.keys(r).forEach(function(a){if(a===hM)throw $e("Cannot define action '"+hM+"', it should be defined using 'type.preProcessSnapshot(fn)' instead");if(a===pM)throw $e("Cannot define action '"+pM+"', it should be defined using 'type.postProcessSnapshot(fn)' instead");var i=r[a],o=n[a];if(a in Un&&o){var l=i;i=function(){o.apply(null,arguments),l.apply(null,arguments)}}var s=i.$mst_middleware,c=i.bind(r);c.$mst_middleware=s;var u=f2(n,a,c);r[a]=u,es(n,a,u)})}}),Object.defineProperty(t.prototype,"volatile",{enumerable:!1,configurable:!0,writable:!0,value:function(n){var r=this;if(typeof n!="function")throw $e("You passed an "+typeof n+" to volatile state as an argument, when function is expected");var a=function(i){return r.instantiateVolatileState(i,n(i)),i};return this.cloneAndEnhance({initializers:[a]})}}),Object.defineProperty(t.prototype,"instantiateVolatileState",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){if(!Ul(r))throw $e("volatile state initializer should return a plain object containing state");Tg(n,r)}}),Object.defineProperty(t.prototype,"extend",{enumerable:!1,configurable:!0,writable:!0,value:function(n){var r=this,a=function(i){var o=n(i),l=o.actions,s=o.views,c=o.state,u=Lye(o,["actions","views","state"]);for(var p in u)throw $e("The `extend` function should return an object with a subset of the fields 'actions', 'views' and 'state'. Found invalid key '"+p+"'");return c&&r.instantiateVolatileState(i,c),s&&r.instantiateViews(i,s),l&&r.instantiateActions(i,l),i};return this.cloneAndEnhance({initializers:[a]})}}),Object.defineProperty(t.prototype,"views",{enumerable:!1,configurable:!0,writable:!0,value:function(n){var r=this,a=function(i){return r.instantiateViews(i,n(i)),i};return this.cloneAndEnhance({initializers:[a]})}}),Object.defineProperty(t.prototype,"instantiateViews",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){if(!Ul(r))throw $e("views initializer should return a plain object containing views");Object.getOwnPropertyNames(r).forEach(function(a){var i,o=Object.getOwnPropertyDescriptor(r,a);if("get"in o)Pg(n,a,o),xg(n,(i={},i[a]=ys,i));else if(typeof o.value=="function")es(n,a,o.value);else throw $e("A view member should either be a function or getter based property")})}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r,a,i){var o=Nt(i)?i:this.applySnapshotPreProcessor(i);return Fb(this,n,r,a,o)}}),Object.defineProperty(t.prototype,"initializeChildNodes",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){r===void 0&&(r={});var a=n.type,i={};return a.forAllProps(function(o,l){i[o]=l.instantiate(n,o,void 0,r[o])}),i}}),Object.defineProperty(t.prototype,"createNewInstance",{enumerable:!1,configurable:!0,writable:!0,value:function(n){return Bt.object(n,vs,Vp)}}),Object.defineProperty(t.prototype,"finalizeNewInstance",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){es(r,"toString",r_e),this.forAllProps(function(a){Mg(r,a,n.unbox)}),this.initializers.reduce(function(a,i){return i(a)},r),m3(r,this.willChange),y3(r,this.didChange)}}),Object.defineProperty(t.prototype,"willChange",{enumerable:!1,configurable:!0,writable:!0,value:function(n){var r=n,a=qe(r.object),i=r.name;a.assertWritable({subpath:i});var o=a.type.properties[i];return o&&(Ei(o,r.newValue),r.newValue=o.reconcile(a.getChildNode(i),r.newValue,a,i)),r}}),Object.defineProperty(t.prototype,"didChange",{enumerable:!1,configurable:!0,writable:!0,value:function(n){var r=n,a=qe(r.object),i=a.type.properties[r.name];if(i){var o=r.oldValue?r.oldValue.snapshot:void 0;a.emitPatch({op:"replace",path:Ao(r.name),value:r.newValue.snapshot,oldValue:o},a)}}}),Object.defineProperty(t.prototype,"getChildren",{enumerable:!1,configurable:!0,writable:!0,value:function(n){var r=this,a=[];return this.forAllProps(function(i){a.push(r.getChildNode(n,i))}),a}}),Object.defineProperty(t.prototype,"getChildNode",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){if(!(r in this.properties))throw $e("Not a value property: "+r);var a=da(n.storedValue,r),i=a.raw();if(!i)throw $e("Node not available for property "+r);return i}}),Object.defineProperty(t.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){var a=this;r===void 0&&(r=!0);var i={};return this.forAllProps(function(o,l){H1(n.storedValue,o).reportObserved(),i[o]=a.getChildNode(n,o).snapshot}),r?this.applySnapshotPostProcessor(i):i}}),Object.defineProperty(t.prototype,"processInitialSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(n){var r={};return Object.keys(n).forEach(function(a){r[a]=n[a].getSnapshot()}),this.applySnapshotPostProcessor(r)}}),Object.defineProperty(t.prototype,"applyPatchLocally",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r,a){if(!(a.op==="replace"||a.op==="add"))throw $e("object does not support operation "+a.op);n.storedValue[r]=a.value}}),Object.defineProperty(t.prototype,"applySnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){Ei(this,r);var a=this.applySnapshotPreProcessor(r);this.forAllProps(function(i){n.storedValue[i]=a[i]})}}),Object.defineProperty(t.prototype,"applySnapshotPreProcessor",{enumerable:!1,configurable:!0,writable:!0,value:function(n){var r=this.preProcessor;return r?r.call(null,n):n}}),Object.defineProperty(t.prototype,"applySnapshotPostProcessor",{enumerable:!1,configurable:!0,writable:!0,value:function(n){var r=this.postProcessor;return r?r.call(null,n):n}}),Object.defineProperty(t.prototype,"getChildType",{enumerable:!1,configurable:!0,writable:!0,value:function(n){return this.properties[n]}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){var a=this,i=this.applySnapshotPreProcessor(n);return Ul(i)?Hp(this.propertyNames.map(function(o){return a.properties[o].validate(i[o],Db(r,o,a.properties[o]))})):p1(r,i,"Value is not a plain object")}}),Object.defineProperty(t.prototype,"forAllProps",{enumerable:!1,configurable:!0,writable:!0,value:function(n){var r=this;this.propertyNames.forEach(function(a){return n(a,r.properties[a])})}}),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){var n=this;return"{ "+this.propertyNames.map(function(r){return r+": "+n.properties[r].describe()}).join("; ")+" }"}}),Object.defineProperty(t.prototype,"getDefaultSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(){return vs}}),Object.defineProperty(t.prototype,"removeChild",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){n.storedValue[r]=void 0}}),t}(Rc);d2.prototype.applySnapshot=Rn(d2.prototype.applySnapshot);function i_e(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=typeof e[0]=="string"?e.shift():"AnonymousModel",r=e.shift()||{};return new d2({name:n,properties:r})}function o_e(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=typeof e[0]=="string",r=n?e[0]:"AnonymousModel";return n&&e.shift(),e.reduce(function(a,i){return a.cloneAndEnhance({name:a.name+"_"+i.name,properties:i.properties,initializers:i.initializers,preProcessor:function(o){return i.applySnapshotPreProcessor(a.applySnapshotPreProcessor(o))},postProcessor:function(o){return i.applySnapshotPostProcessor(a.applySnapshotPostProcessor(o))}})}).named(r)}function QH(e){return _r(e)&&(e.flags&vt.Object)>0}var Bs=function(e){on(t,e);function t(n,r,a,i){i===void 0&&(i=Rbe);var o=e.call(this,n)||this;return Object.defineProperty(o,"flags",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(o,"checker",{enumerable:!0,configurable:!0,writable:!0,value:a}),Object.defineProperty(o,"initializer",{enumerable:!0,configurable:!0,writable:!0,value:i}),o.flags=r,o}return Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.name}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r,a,i){return $s(this,n,r,a,i)}}),Object.defineProperty(t.prototype,"createNewInstance",{enumerable:!1,configurable:!0,writable:!0,value:function(n){return this.initializer(n)}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){if(Nc(n)&&this.checker(n))return f1();var a=this.name==="Date"?"Date or a unix milliseconds timestamp":this.name;return p1(r,n,"Value is not a "+a)}}),t}(ou),ZH=new Bs("string",vt.String,function(e){return typeof e=="string"}),JH=new Bs("number",vt.Number,function(e){return typeof e=="number"}),l_e=new Bs("integer",vt.Integer,function(e){return Ibe(e)}),eV=new Bs("boolean",vt.Boolean,function(e){return typeof e=="boolean"}),tV=new Bs("null",vt.Null,function(e){return e===null}),nV=new Bs("undefined",vt.Undefined,function(e){return e===void 0}),rV=new Bs("Date",vt.Date,function(e){return typeof e=="number"||e instanceof Date},function(e){return e instanceof Date?e:new Date(e)});rV.getSnapshot=function(e){return e.storedValue.getTime()};var aV=rV;function s_e(e){switch(typeof e){case"string":return ZH;case"number":return JH;case"boolean":return eV;case"object":if(e instanceof Date)return aV}throw $e("Cannot determine primitive type from value "+e)}function iV(e){return _r(e)&&(e.flags&(vt.String|vt.Number|vt.Integer|vt.Boolean|vt.Date))>0}var c_e=function(e){on(t,e);function t(n){var r=e.call(this,JSON.stringify(n))||this;return Object.defineProperty(r,"value",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"flags",{enumerable:!0,configurable:!0,writable:!0,value:vt.Literal}),r.value=n,r}return Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r,a,i){return $s(this,n,r,a,i)}}),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return JSON.stringify(this.value)}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){return Nc(n)&&n===this.value?f1():p1(r,n,"Value is not a literal "+JSON.stringify(this.value))}}),t}(ou);function oV(e){return new c_e(e)}function u_e(e){return _r(e)&&(e.flags&vt.Literal)>0}var f_e=function(e){on(t,e);function t(n,r,a,i){var o=e.call(this,n)||this;return Object.defineProperty(o,"_subtype",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(o,"_predicate",{enumerable:!0,configurable:!0,writable:!0,value:a}),Object.defineProperty(o,"_message",{enumerable:!0,configurable:!0,writable:!0,value:i}),o}return Object.defineProperty(t.prototype,"flags",{get:function(){return this._subtype.flags|vt.Refinement},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.name}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r,a,i){return this._subtype.instantiate(n,r,a,i)}}),Object.defineProperty(t.prototype,"isAssignableFrom",{enumerable:!1,configurable:!0,writable:!0,value:function(n){return this._subtype.isAssignableFrom(n)}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){var a=this._subtype.validate(n,r);if(a.length>0)return a;var i=Nt(n)?qe(n).snapshot:n;return this._predicate(i)?f1():p1(r,n,this._message(n))}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r,a,i){return this._subtype.reconcile(n,r,a,i)}}),Object.defineProperty(t.prototype,"getSubTypes",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subtype}}),t}(Li);function d_e(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=typeof e[0]=="string"?e.shift():_r(e[0])?e[0].name:null,r=e[0],a=e[1],i=e[2]?e[2]:function(o){return"Value does not respect the refinement predicate"};return new f_e(n,r,a,i)}function h_e(e){return(e.flags&vt.Refinement)>0}function p_e(e,t){var n=typeof e=="string"?t:e,r=Dp.apply(void 0,ul(n.map(function(a){return oV(""+a)})));return typeof e=="string"&&(r.name=e),r}var v_e=function(e){on(t,e);function t(n,r,a){var i=e.call(this,n)||this;return Object.defineProperty(i,"_types",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(i,"_dispatcher",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,"_eager",{enumerable:!0,configurable:!0,writable:!0,value:!0}),a=Ur({eager:!0,dispatcher:void 0},a),i._dispatcher=a.dispatcher,a.eager||(i._eager=!1),i}return Object.defineProperty(t.prototype,"flags",{get:function(){var n=vt.Union;return this._types.forEach(function(r){n|=r.flags}),n},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isAssignableFrom",{enumerable:!1,configurable:!0,writable:!0,value:function(n){return this._types.some(function(r){return r.isAssignableFrom(n)})}}),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return"("+this._types.map(function(n){return n.describe()}).join(" | ")+")"}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r,a,i){var o=this.determineType(i,void 0);if(!o)throw $e("No matching type for union "+this.describe());return o.instantiate(n,r,a,i)}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r,a,i){var o=this.determineType(r,n.getReconciliationType());if(!o)throw $e("No matching type for union "+this.describe());return o.reconcile(n,r,a,i)}}),Object.defineProperty(t.prototype,"determineType",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){return this._dispatcher?this._dispatcher(n):r?r.is(n)?r:this._types.filter(function(a){return a!==r}).find(function(a){return a.is(n)}):this._types.find(function(a){return a.is(n)})}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){if(this._dispatcher)return this._dispatcher(n).validate(n,r);for(var a=[],i=0,o=0;o<this._types.length;o++){var l=this._types[o],s=l.validate(n,r);if(s.length===0){if(this._eager)return f1();i++}else a.push(s)}return i===1?f1():p1(r,n,"No type is applicable for the union").concat(Hp(a))}}),Object.defineProperty(t.prototype,"getSubTypes",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._types}}),t}(Li);function Dp(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];var r=_r(e)?void 0:e,a=_r(e)?ul([e],t):t,i="("+a.map(function(o){return o.name}).join(" | ")+")";return new v_e(i,a,r)}function lV(e){return(e.flags&vt.Union)>0}var m_e=function(e){on(t,e);function t(n,r,a){var i=e.call(this,n.name)||this;return Object.defineProperty(i,"_subtype",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(i,"_defaultValue",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(i,"optionalValues",{enumerable:!0,configurable:!0,writable:!0,value:a}),i}return Object.defineProperty(t.prototype,"flags",{get:function(){return this._subtype.flags|vt.Optional},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subtype.describe()+"?"}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r,a,i){if(this.optionalValues.indexOf(i)>=0){var o=this.getDefaultInstanceOrSnapshot();return this._subtype.instantiate(n,r,a,o)}return this._subtype.instantiate(n,r,a,i)}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r,a,i){return this._subtype.reconcile(n,this.optionalValues.indexOf(r)<0&&this._subtype.is(r)?r:this.getDefaultInstanceOrSnapshot(),a,i)}}),Object.defineProperty(t.prototype,"getDefaultInstanceOrSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(){var n=typeof this._defaultValue=="function"?this._defaultValue():this._defaultValue;return typeof this._defaultValue=="function"&&Ei(this,n),n}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){return this.optionalValues.indexOf(n)>=0?f1():this._subtype.validate(n,r)}}),Object.defineProperty(t.prototype,"isAssignableFrom",{enumerable:!1,configurable:!0,writable:!0,value:function(n){return this._subtype.isAssignableFrom(n)}}),Object.defineProperty(t.prototype,"getSubTypes",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subtype}}),t}(Li);function g_e(e,t){if(typeof t!="function"&&Nt(t))throw $e("default value cannot be an instance, pass a snapshot or a function that creates an instance/snapshot instead")}function ts(e,t,n){return g_e(e,t),new m_e(e,t,n||y_e)}var y_e=[void 0];function b_e(e){return _r(e)&&(e.flags&vt.Optional)>0}var __e=ts(nV,void 0),w_e=ts(tV,null);function sV(e){return Dp(e,__e)}function E_e(e){return Dp(e,w_e)}var S_e=function(e){on(t,e);function t(n,r){var a=e.call(this,n)||this;return Object.defineProperty(a,"_definition",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(a,"_subType",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),a}return Object.defineProperty(t.prototype,"flags",{get:function(){return(this._subType?this._subType.flags:0)|vt.Late},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"getSubType",{enumerable:!1,configurable:!0,writable:!0,value:function(n){if(!this._subType){var r=void 0;try{r=this._definition()}catch(a){if(a instanceof ReferenceError)r=void 0;else throw a}if(n&&r===void 0)throw $e("Late type seems to be used too early, the definition (still) returns undefined");r&&(this._subType=r)}return this._subType}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r,a,i){return this.getSubType(!0).instantiate(n,r,a,i)}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r,a,i){return this.getSubType(!0).reconcile(n,r,a,i)}}),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){var n=this.getSubType(!1);return n?n.name:"<uknown late type>"}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){var a=this.getSubType(!1);return a?a.validate(n,r):f1()}}),Object.defineProperty(t.prototype,"isAssignableFrom",{enumerable:!1,configurable:!0,writable:!0,value:function(n){var r=this.getSubType(!1);return r?r.isAssignableFrom(n):!1}}),Object.defineProperty(t.prototype,"getSubTypes",{enumerable:!1,configurable:!0,writable:!0,value:function(){var n=this.getSubType(!1);return n||xH}}),t}(Li);function C_e(e,t){var n=typeof e=="string"?e:"late("+e.toString()+")",r=typeof e=="string"?t:e;return new S_e(n,r)}function O_e(e){return _r(e)&&(e.flags&vt.Late)>0}var cV=function(e){on(t,e);function t(n){var r=e.call(this,n?"frozen("+n.name+")":"frozen")||this;return Object.defineProperty(r,"subType",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(r,"flags",{enumerable:!0,configurable:!0,writable:!0,value:vt.Frozen}),r}return Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return"<any immutable value>"}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r,a,i){return $s(this,n,r,a,i)}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){return kbe(n)?this.subType?this.subType.validate(n,r):f1():p1(r,n,"Value is not serializable and cannot be frozen")}}),t}(ou),mM=new cV;function M_e(e){return arguments.length===0?mM:_r(e)?new cV(e):ts(mM,e)}function z_e(e){return _r(e)&&(e.flags&vt.Frozen)>0}function T_e(e){switch(e){case Un.beforeDestroy:return"destroy";case Un.beforeDetach:return"detach";default:return}}var P_e=function(){function e(t,n){if(Object.defineProperty(this,"targetType",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"identifier",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"node",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"resolvedReference",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Ub(t))this.identifier=t;else if(Nt(t)){var r=qe(t);if(!r.identifierAttribute)throw $e("Can only store references with a defined identifier attribute.");var a=r.unnormalizedIdentifier;if(a==null)throw $e("Can only store references to tree nodes with a defined identifier.");this.identifier=a}else throw $e("Can only store references to tree nodes or identifiers, got: '"+t+"'")}return Object.defineProperty(e.prototype,"updateResolvedReference",{enumerable:!1,configurable:!0,writable:!0,value:function(t){var n=lu(this.identifier),r=t.root,a=r.identifierCache.getLastCacheModificationPerId(n);if(!this.resolvedReference||this.resolvedReference.lastCacheModification!==a){var i=this.targetType,o=r.identifierCache.resolve(i,n);if(!o)throw new jb("[mobx-state-tree] Failed to resolve reference '"+this.identifier+"' to type '"+this.targetType.name+"' (from node: "+t.path+")");this.resolvedReference={node:o,lastCacheModification:a}}}}),Object.defineProperty(e.prototype,"resolvedValue",{get:function(){return this.updateResolvedReference(this.node),this.resolvedReference.node.value},enumerable:!1,configurable:!0}),e}(),jb=function(e){on(t,e);function t(n){var r=e.call(this,n)||this;return Object.setPrototypeOf(r,t.prototype),r}return t}(Error),uV=function(e){on(t,e);function t(n,r){var a=e.call(this,"reference("+n.name+")")||this;return Object.defineProperty(a,"targetType",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(a,"onInvalidated",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(a,"flags",{enumerable:!0,configurable:!0,writable:!0,value:vt.Reference}),a}return Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.name}}),Object.defineProperty(t.prototype,"isAssignableFrom",{enumerable:!1,configurable:!0,writable:!0,value:function(n){return this.targetType.isAssignableFrom(n)}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){return Ub(n)?f1():p1(r,n,"Value is not a valid identifier, which is a string or a number")}}),Object.defineProperty(t.prototype,"fireInvalidated",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r,a,i){var o=r.parent;if(!(!o||!o.isAlive)){var l=o.storedValue;l&&this.onInvalidated({cause:n,parent:l,invalidTarget:i?i.storedValue:void 0,invalidId:a,replaceRef:function(s){Lc(r.root.storedValue,{op:"replace",value:s,path:r.path})},removeRef:function(){QH(o.type)?this.replaceRef(void 0):Lc(r.root.storedValue,{op:"remove",path:r.path})}})}}}),Object.defineProperty(t.prototype,"addTargetNodeWatcher",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){var a=this,i=this.getValue(n);if(i){var o=qe(i),l=function(u,p){var h=T_e(p);h&&a.fireInvalidated(h,n,r,o)},s=o.registerHook(Un.beforeDetach,l),c=o.registerHook(Un.beforeDestroy,l);return function(){s(),c()}}}}),Object.defineProperty(t.prototype,"watchTargetNodeForInvalidations",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r,a){var i=this;if(this.onInvalidated){var o;n.registerHook(Un.beforeDestroy,function(){o&&o()});var l=function(s){o&&o();var c=n.parent,u=c&&c.storedValue;if(c&&c.isAlive&&u){var p=void 0;a?p=!!a.get(r,u):p=n.root.identifierCache.has(i.targetType,lu(r)),p?o=i.addTargetNodeWatcher(n,r):s||i.fireInvalidated("invalidSnapshotReference",n,r,null)}};n.state===Jn.FINALIZED?l(!0):(n.isRoot||n.root.registerHook(Un.afterCreationFinalization,function(){n.parent&&n.parent.createObservableInstanceIfNeeded()}),n.registerHook(Un.afterAttach,function(){l(!1)}))}}}),t}(ou),x_e=function(e){on(t,e);function t(n,r){return e.call(this,n,r)||this}return Object.defineProperty(t.prototype,"getValue",{enumerable:!1,configurable:!0,writable:!0,value:function(n){if(n.isAlive){var r=n.storedValue;return r.resolvedValue}}}),Object.defineProperty(t.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(n){var r=n.storedValue;return r.identifier}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r,a,i){var o=Nt(i)?CH(i):i,l=new P_e(i,this.targetType),s=$s(this,n,r,a,l);return l.node=s,this.watchTargetNodeForInvalidations(s,o,void 0),s}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r,a,i){if(!n.isDetaching&&n.type===this){var o=Nt(r),l=n.storedValue;if(!o&&l.identifier===r||o&&l.resolvedValue===r)return n.setParent(a,i),n}var s=this.instantiate(a,i,void 0,r);return n.die(),s}}),t}(uV),A_e=function(e){on(t,e);function t(n,r,a){var i=e.call(this,n,a)||this;return Object.defineProperty(i,"options",{enumerable:!0,configurable:!0,writable:!0,value:r}),i}return Object.defineProperty(t.prototype,"getValue",{enumerable:!1,configurable:!0,writable:!0,value:function(n){if(n.isAlive){var r=this.options.get(n.storedValue,n.parent?n.parent.storedValue:null);return r}}}),Object.defineProperty(t.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(n){return n.storedValue}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r,a,i){var o=Nt(i)?this.options.set(i,n?n.storedValue:null):i,l=$s(this,n,r,a,o);return this.watchTargetNodeForInvalidations(l,o,this.options),l}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r,a,i){var o=Nt(r)?this.options.set(r,n?n.storedValue:null):r;if(!n.isDetaching&&n.type===this&&n.storedValue===o)return n.setParent(a,i),n;var l=this.instantiate(a,i,void 0,o);return n.die(),l}}),t}(uV);function fV(e,t){var n=t||void 0,r=t?t.onInvalidated:void 0;return n&&(n.get||n.set)?new A_e(e,{get:n.get,set:n.set},r):new x_e(e,r)}function L_e(e){return(e.flags&vt.Reference)>0}function R_e(e,t){var n=fV(e,Ur(Ur({},t),{onInvalidated:function(r){t&&t.onInvalidated&&t.onInvalidated(r),r.removeRef()}}));return t&&t.acceptsUndefined===!1?n:sV(n)}var dV=function(e){on(t,e);function t(n,r){var a=e.call(this,n)||this;return Object.defineProperty(a,"validType",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(a,"flags",{enumerable:!0,configurable:!0,writable:!0,value:vt.Identifier}),a}return Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r,a,i){if(!n||!(n.type instanceof d2))throw $e("Identifier types can only be instantiated as direct child of a model type");return $s(this,n,r,a,i)}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r,a,i){if(n.storedValue!==r)throw $e("Tried to change identifier from '"+n.storedValue+"' to '"+r+"'. Changing identifiers is not allowed.");return n.setParent(a,i),n}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){return typeof n!==this.validType?p1(r,n,"Value is not a valid "+this.describe()+", expected a "+this.validType):f1()}}),t}(ou),I_e=function(e){on(t,e);function t(){var n=e.call(this,"identifier","string")||this;return Object.defineProperty(n,"flags",{enumerable:!0,configurable:!0,writable:!0,value:vt.Identifier}),n}return Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return"identifier"}}),t}(dV),N_e=function(e){on(t,e);function t(){return e.call(this,"identifierNumber","number")||this}return Object.defineProperty(t.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(n){return n.storedValue}}),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return"identifierNumber"}}),t}(dV),k_e=new I_e,H_e=new N_e;function V_e(e){return _r(e)&&(e.flags&vt.Identifier)>0}function lu(e){return""+e}function Ub(e){return typeof e=="string"||typeof e=="number"}function D_e(e){return new F_e(e)}var F_e=function(e){on(t,e);function t(n){var r=e.call(this,n.name)||this;return Object.defineProperty(r,"options",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(r,"flags",{enumerable:!0,configurable:!0,writable:!0,value:vt.Custom}),r}return Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.name}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){if(this.options.isTargetType(n))return f1();var a=this.options.getValidationMessage(n);return a?p1(r,n,"Invalid value for type '"+this.name+"': "+a):f1()}}),Object.defineProperty(t.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(n){return this.options.toSnapshot(n.storedValue)}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r,a,i){var o=this.options.isTargetType(i)?i:this.options.fromSnapshot(i,n&&n.root.environment);return $s(this,n,r,a,o)}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r,a,i){var o=!this.options.isTargetType(r);if(!n.isDetaching){var l=n.type===this&&(o?r===n.snapshot:r===n.storedValue);if(l)return n.setParent(a,i),n}var s=o?this.options.fromSnapshot(r,a.root.environment):r,c=this.instantiate(a,i,void 0,s);return n.die(),c}}),t}(ou),$_e={enumeration:p_e,model:i_e,compose:o_e,custom:D_e,reference:fV,safeReference:R_e,union:Dp,optional:ts,literal:oV,maybe:sV,maybeNull:E_e,refinement:d_e,string:ZH,boolean:eV,number:JH,integer:l_e,Date:aV,map:Jbe,array:t_e,frozen:M_e,identifier:k_e,identifierNumber:H_e,late:C_e,undefined:nV,null:tV,snapshotProcessor:Qbe};const B_e=Object.freeze(Object.defineProperty({__proto__:null,addDisposer:Jye,addMiddleware:NH,applyAction:AH,applyPatch:Lc,applySnapshot:wH,cast:nbe,castFlowReturn:$be,castToReferenceSnapshot:abe,castToSnapshot:rbe,clone:Xye,createActionTrackingMiddleware:cbe,createActionTrackingMiddleware2:fbe,decorate:gbe,destroy:Zye,detach:Qye,escapeJsonPath:Ao,flow:KH,getChildType:Rye,getEnv:ebe,getIdentifier:CH,getLivelinessChecking:yH,getMembers:tbe,getNodeId:ibe,getParent:Fye,getParentOfType:Bye,getPath:SH,getPathParts:jye,getPropertyMembers:zH,getRelativePath:Yye,getRoot:EH,getRunningActionContext:Vb,getSnapshot:Nb,getType:uf,hasParent:Dye,hasParentOfType:$ye,isActionContextChildOf:_be,isActionContextThisOrChildOf:wbe,isAlive:kb,isArrayType:n_e,isFrozenType:z_e,isIdentifierType:V_e,isLateType:O_e,isLiteralType:u_e,isMapType:e_e,isModelType:QH,isOptionalType:b_e,isPrimitiveType:iV,isProtected:Vye,isReferenceType:L_e,isRefinementType:h_e,isRoot:Uye,isStateTreeNode:Nt,isType:_r,isUnionType:lV,isValidReference:Kye,joinJsonPath:V4,onAction:LH,onPatch:_H,onSnapshot:Iye,process:Abe,protect:kye,recordActions:vbe,recordPatches:Nye,resolveIdentifier:Wye,resolvePath:Gye,setLivelinessChecking:gH,setLivelynessChecking:Aye,splitJsonPath:kc,toGenerator:jbe,toGeneratorFunction:Bbe,tryReference:qye,tryResolve:OH,typecheck:VH,types:$_e,unescapeJsonPath:YH,unprotect:Hye,walk:MH},Symbol.toStringTag,{value:"Module"})),hV=xr(B_e);var pV={},Gb={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.deepEqual=void 0;const t=function(n,r){if(n===r)return!0;if(typeof n=="object"&&n!=null&&typeof r=="object"&&r!=null){if(Object.keys(n).length!=Object.keys(r).length)return!1;for(var a in n)if(!r.hasOwnProperty(a)||!(0,e.deepEqual)(n[a],r[a]))return!1;return!0}return!1};e.deepEqual=t})(Gb);(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.UndoManager=void 0;const t=hV,n=Gb;Object.assign(t.types),e.UndoManager=t.types.model("UndoManager",{history:t.types.array(t.types.frozen()),undoIdx:-1,targetPath:""}).views(r=>({get canUndo(){return r.undoIdx>0},get canRedo(){return r.undoIdx<r.history.length-1}})).actions(r=>{let a,i,o=!1,l=null,s=0,c=!1;function u(){const h=(0,t.getSnapshot)(a);return{pages:h.pages,width:h.width,height:h.height}}function p(h){(0,t.applySnapshot)(a.pages,h.pages),a.setSize(h.width,h.height)}return{startTransaction(){c=!0},endTransaction(h){c=!1,h||this.requestAddState(u())},async ignore(h,d=!1){s&&r.addUndoState();let E=c;E||r.startTransaction();try{await h()}catch(w){setTimeout(()=>{throw w})}E||r.endTransaction(!0),d||E||r.replaceState(),clearTimeout(s),s=0},async transaction(h){await r.ignore(h,!0),this.addUndoState()},requestAddState(h){l=h,s||c||(o?o=!1:s=setTimeout(()=>{s=0,clearTimeout(s),c||this.addUndoState()},100))},addUndoState(){if(o)return void(o=!1);const h=r.history[r.undoIdx];!(0,n.deepEqual)(l,h)&&(clearTimeout(s),s=0,r.history.splice(r.undoIdx+1),r.history.push(l),r.undoIdx=r.history.length-1)},afterCreate(){if(a=(0,t.resolvePath)(r,".."),!a)throw new Error("Failed to find target store for UndoManager. Please provide `targetPath` property, or a `targetStore` in the environment");i=(0,t.onSnapshot)(a,()=>{this.requestAddState(u())}),r.history.length===0&&this.requestAddState(u())},clear(){clearTimeout(s),s=0,r.history.splice(0,r.history.length),r.undoIdx=-1,r.addUndoState(u())},beforeDestroy(){i()},undo(){s&&this.addUndoState(),r.canUndo?(r.undoIdx--,o=!0,p(r.history[r.undoIdx])):console.warn("No undo history. Please check `store.history.canUndo` before calling undo action.")},redo(){s&&this.addUndoState(),r.canRedo?(r.undoIdx++,o=!0,p(r.history[r.undoIdx])):console.warn("No redo history. Please check `store.history.canRedo` before calling redo action.")},replaceState(){r.history[r.undoIdx]=u()}}}),e.default=e.UndoManager})(pV);let j_e="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",vV=e=>crypto.getRandomValues(new Uint8Array(e)),mV=(e,t,n)=>{let r=(2<<Math.log(e.length-1)/Math.LN2)-1,a=-~(1.6*r*t/e.length);return(i=t)=>{let o="";for(;;){let l=n(a),s=a;for(;s--;)if(o+=e[l[s]&r]||"",o.length===i)return o}}},U_e=(e,t=21)=>mV(e,t,vV),G_e=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((t,n)=>(n&=63,n<36?t+=n.toString(36):n<62?t+=(n-26).toString(36).toUpperCase():n>62?t+="-":t+="_",t),"");const W_e=Object.freeze(Object.defineProperty({__proto__:null,customAlphabet:U_e,customRandom:mV,nanoid:G_e,random:vV,urlAlphabet:j_e},Symbol.toStringTag,{value:"Module"})),q_e=xr(W_e);var gV={};(function(e){async function t(n,r){const a=await(await fetch(n)).blob(),i=document.createElement("a"),o=URL.createObjectURL(a);i.href=o,i.download=r,document.body.appendChild(i),i.click(),setTimeout(function(){document.body.removeChild(i),window.URL.revokeObjectURL(o)},0)}Object.defineProperty(e,"__esModule",{value:!0}),e.downloadFile=void 0,e.downloadFile=t})(gV);var yV={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.getJsPDF=void 0;const t="https://unpkg.com/jspdf@2.2.0/dist/jspdf.umd.min.js";let n;function r(){return n?Promise.resolve(n):new Promise(a=>{var i=document.createElement("script");i.onload=function(){n=window.jspdf.jsPDF,a(n)},i.src=t,document.head.appendChild(i)})}e.getJsPDF=r})(yV);var bV={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.createGIF=e.getGIF=void 0;const t="https://cdnjs.cloudflare.com/ajax/libs/gif.js/0.2.0/gif.js";function n(){return window.GIF?Promise.resolve(window.GIF):new Promise(a=>{var i=document.createElement("script");i.onload=function(){a(window.GIF)},i.src=t,document.head.appendChild(i)})}async function r({width:a,height:i}){return new(await n())({workers:4,width:a,height:i,workerScript:URL.createObjectURL(new Blob([`// gif.worker.js 0.2.0 - https://github.com/jnordberg/gif.js
245
245
  (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]);
246
246
  `],{type:"application/javascript"}))})}e.getGIF=n,e.createGIF=r})(bV);var _V={};(function(e){async function t(n){for(let r=0;r<30;r++){const a=await n();if(a)return a;await new Promise(i=>setTimeout(i,50))}}Object.defineProperty(e,"__esModule",{value:!0}),e.waitTillAvailable=void 0,e.waitTillAvailable=t})(_V);var wV={},h2={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.getCrop=e.cropImage=e.loadImage=e.getImageSize=void 0;const t=xs;function n(o){return new Promise(l=>{const s=document.createElement("img");s.onload=async()=>{s.width===0||s.height===0?l(await(0,t.getSvgSize)(o)):l({width:s.width,height:s.height})},s.crossOrigin="anonymous",s.src=o})}function r(o){return new Promise((l,s)=>{const c=document.createElement("img");c.onload=()=>{l(c)},c.onerror=u=>{s(u)},c.crossOrigin="anonymous",c.src=o})}async function a(o,l){const s=await r(o),c=document.createElement("canvas");c.width=2*s.width,c.height=2*s.height,c.getContext("2d").drawImage(s,0,0,c.width,c.height);const u=document.createElement("canvas");u.width=l.width,u.height=l.height;const p=u.getContext("2d");let{cropX:h,cropY:d}=l;const E=c.width*l.cropWidth,w=c.height*l.cropHeight,S=l.width/l.height;let _,y;const v=E/w;return l.type==="svg"?(_=E,y=w):S>=v?(_=E,y=E/S):(_=w*S,y=w),p.drawImage(c,h*c.width,d*c.height,_,y,0,0,u.width,u.height),u.toDataURL("image/png")}function i(o,l){const{width:s,height:c}=o,u=s/c;let p,h;u>=l.width/l.height?(p=l.width,h=l.width/u):(p=l.height*u,h=l.height);const d=(l.width-p)/2,E=(l.height-h)/2;return{cropX:d/l.width,cropY:E/l.height,cropWidth:p/l.width,cropHeight:h/l.height}}e.getImageSize=n,e.loadImage=r,e.cropImage=a,e.getCrop=i})(h2);(function(e){var t=ue&&ue.__createBinding||(Object.create?function(g,M,C,O){O===void 0&&(O=C);var L=Object.getOwnPropertyDescriptor(M,C);L&&!("get"in L?!M.__esModule:L.writable||L.configurable)||(L={enumerable:!0,get:function(){return M[C]}}),Object.defineProperty(g,O,L)}:function(g,M,C,O){O===void 0&&(O=C),g[O]=M[C]}),n=ue&&ue.__setModuleDefault||(Object.create?function(g,M){Object.defineProperty(g,"default",{enumerable:!0,value:M})}:function(g,M){g.default=M}),r=ue&&ue.__importStar||function(g){if(g&&g.__esModule)return g;var M={};if(g!=null)for(var C in g)C!=="default"&&Object.prototype.hasOwnProperty.call(g,C)&&t(M,g,C);return n(M,g),M};Object.defineProperty(e,"__esModule",{value:!0}),e.jsonToHTML=e.jsonToDOM=e.fixRatio=void 0;const a=h2,i=r(xs),o=h2,l=(g,M,...C)=>({type:g,props:M,children:C||[]});function s(g){var M=new DOMParser().parseFromString(g,"image/svg+xml");return M.documentElement.setAttribute("preserveAspectRatio","none"),new XMLSerializer().serializeToString(M)}e.fixRatio=s;const c=async({element:g,page:M,store:C})=>{let{src:O}=g;if(g.type==="svg"){const J=await i.urlToString(O);O=i.replaceColors(J,new Map(Object.entries(g.colorsReplace)))}let L="";g.flipX&&(L+="scaleX(-1)"),g.flipY&&(L+="scaleY(-1)");const T={};if(g.clipSrc){const J=await i.urlToBase64(g.clipSrc);T["clip-path"]=`url(${J})`}const A=await(0,o.loadImage)(O),z=A.width*g.cropWidth,I=A.height*g.cropHeight,H=g.width/g.height;let N,G;const D=z/I;g.type==="svg"?(N=z,G=I):H>=D?(N=z,G=z/H):(N=I*H,G=I);const q=N/A.width,V=G/A.height,R=N/G>g.width/g.height?g.height/G:g.width/N,P=N*R/q,F=G*R/V,B=g.cropX*R*A.width,Y=g.cropY*R*A.height;return l("div",{src:O,style:Object.assign(Object.assign({},T),{width:"100%",height:"100%","border-radius":g.cornerRadius+"px",border:g.borderSize?`${g.borderSize}px solid ${g.borderColor}`:"none",background:`url(${O})`,transform:L,"background-size":`${Math.round(P)}px ${Math.round(F)}px`,"background-position-x":`${Math.round(B)}px`,"background-position-y":`${Math.round(Y)}px`})})},u=async({element:g,page:M,store:C})=>{let O={};g.fill.indexOf("gradient")>=0&&(O=Object.assign(Object.assign({},O),{"background-color":g.fill,"background-image":g.fill,"background-clip":"text","text-fill-color":"transparent","-webkit-background-clip":"text","-webkit-text-fill-color":"transparent"}));const L=g.backgroundPadding*(g.fontSize*g.lineHeight),T=l("div",{style:{position:"absolute",top:-L/2+"px",left:-L/2+"px",display:g.backgroundEnabled?"block":"none",width:g.width+L+"px",height:g.height+L+"px","background-color":g.backgroundColor,"border-radius":g.backgroundCornerRadius*(g.fontSize*g.lineHeight*.5)+"px"}}),A=l("div",{style:Object.assign(Object.assign({},O),{position:"absolute",top:0,left:0,width:g.width+"px",color:g.fill,"white-space":"pre-wrap","font-size":g.fontSize+"px","text-align":g.align,"font-family":g.fontFamily,"text-decoration":g.textDecoration||"none","line-height":g.lineHeight,"letter-spacing":g.letterSpacing+"em","font-style":g.fontStyle,"font-weight":g.fontWeight,"-webkit-text-stroke":`${g.strokeWidth}px ${g.stroke}`,"text-stroke":`${g.strokeWidth}px ${g.stroke}`})},g.text.split(`
247
- `).join("<br />"));return l("div",{style:{position:"relative"}},T,A)},p=({element:g,type:M})=>{const C={"stroke-width":g.height,stroke:g.color,"line-cap":"round","stroke-linejoin":"round",opacity:g.opacity};return M==="arrow"||M==="triangle"?l("polyline",Object.assign({points:`${3*g.height},${2*-g.height} 0,0 ${3*g.height},${2*g.height}`},C)):M==="bar"?l("polyline",Object.assign({points:`0,${2*-g.height} 0,${2*g.height}`},C)):M==="circle"?l("circle",Object.assign({r:g.height},C)):M==="square"?l("polyline",Object.assign({points:`${-g.height},${-g.height} ${-g.height},${g.height} ${g.height},${g.height} ${g.height},${-g.height}`},C)):null},h=async({element:g,page:M,store:C})=>l("svg",{style:{width:"100%",height:"100%",contain:"layout style size",overflow:"visible"}},l("rect",{x:0,y:0,width:g.width,height:g.height,fill:g.color}),l("g",{transform:`translate(0 ${g.height/2})`},p({element:g,type:g.startHead})),l("g",{transform:`translate(${g.width} ${g.height/2}) rotate(180)`},p({element:g,type:g.endHead}))),d=async({element:g,page:M,store:C,elementHook:O})=>{const L=await Promise.all(g.children.map(A=>w({element:A,page:M,store:C,elementHook:O}))),T=l("div",{style:{"transform-origin":"top left",opacity:g.opacity}},...L);return O&&O({dom:T,element:g})||T},E={image:c,svg:c,text:u,line:h,group:d};async function w({element:g,page:M,store:C,elementHook:O}){let L=await E[g.type];L||(L=()=>l("div",{}),console.error(`HTML export does not support ${g.type} type...`));const T=await L({element:g,page:M,store:C}),A=[];g.blurEnabled&&A.push(`blur(${g.blurRadius/2}px)`),g.brightnessEnabled&&A.push(`brightness(${100*g.brightness+100}%)`),g.sepiaEnabled&&A.push("sepia()"),g.grayscaleEnabled&&A.push("grayscale()"),g.shadowEnabled&&A.push(`drop-shadow(${g.shadowOffsetX}px ${g.shadowOffsetY}px ${g.shadowBlur}px ${g.shadowColor})`);const z=l("div",{style:{position:"absolute",left:g.x+"px",top:g.y+"px",width:g.width+"px",height:g.height+"px",transform:`rotate(${g.rotation}deg)`,"transform-origin":"top left",opacity:g.opacity,filter:A.join(" ")}},T);return O&&O({dom:z,element:g})||z}async function S({page:g,store:M,elementHook:C}){const O=await Promise.all(g.children.map(T=>w({element:T,page:g,store:M,elementHook:C})));let L={};if(g.background.indexOf("url")>=0||g.background.indexOf("http")>=0||g.background.indexOf(".jpg")>=0||g.background.indexOf(".png")>=0||g.background.indexOf(".jpeg")>=0){const T=await(0,o.loadImage)(g.background),A=await(0,o.cropImage)(g.background,Object.assign({width:M.width,height:M.height,x:0,y:0},(0,a.getCrop)({width:M.width,height:M.height},{width:T.width,height:T.height})));L=Object.assign(Object.assign({},L),{"background-image":`url(${A})`})}return l("div",{className:"page",style:Object.assign(Object.assign({},L),{width:M.width+"px",height:M.height+"px",background:g.background,border:"1px solid grey",overflow:"hidden",position:"relative"})},...O)}async function _({json:g,elementHook:M}){const C=await Promise.all(g.pages.map(T=>S({page:T,store:g,elementHook:M}))),O=[];g.pages.forEach(T=>{T.children.forEach(A=>{A.type==="text"&&O.indexOf(A.fontFamily)===-1&&O.push(A.fontFamily)})});const L=O.map(T=>g.fonts.find(A=>A.fontFamily===T)?l("style",{},""):l("link",{href:`https://fonts.googleapis.com/css?family=${T}`,rel:"stylesheet"}));return l("div",{className:"design"},...L,...C)}e.jsonToDOM=_;const y=(g,M)=>typeof M=="object"?`${g}="${Object.keys(M).map(C=>`${C}:${M[C]};`).join(" ")}"`:`${g}="${M}"`,v=({dom:g})=>typeof g=="string"?g:g?`<${g.type} ${Object.keys(g.props).map(M=>y(M,g.props[M])).join(" ")}>${g.children.map(M=>v({dom:M})).join("")}</${g.type}>`:"";async function b({json:g,elementHook:M}){const C=await _({json:g,elementHook:M});return v({dom:C})}e.jsonToHTML=b})(wV);var EV={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.registerAnimation=e.animate=e.animations=void 0;const t={right:{from:{x:-200},to:{x:0}},left:{from:{x:200},to:{x:0}},up:{from:{y:200},to:{y:0}},down:{from:{y:-200},to:{y:0}},"bottom-right":{from:{x:-200,y:-200},to:{x:0,y:0}},"bottom-left":{from:{x:200,y:-200},to:{x:0,y:0}},"top-right":{from:{x:-200,y:200},to:{x:0,y:0}},"top-left":{from:{x:200,y:200},to:{x:0,y:0}}};e.animations={fade:({dTime:a,element:i,animation:o})=>{const l=a/o.duration;return o.type==="enter"?{opacity:l*i.opacity}:{opacity:(1-l)*i.opacity}},move:({dTime:a,element:i,animation:o})=>{const l=t[o.data.direction]||t.right,s={};for(var c in l.from){let u=i[c]+l.from[c],p=i[c]+l.to[c];if(o.type==="exit"){const d=u;u=p,p=-d}const h=p-u;s[c]=u+a/o.duration*h}return s},zoom:({dTime:a,element:i,animation:o})=>{const l={},s={x:i.x+i.width/3,y:i.y+i.height/3,width:i.width/3,height:i.height/3,fontSize:i.fontSize/3},c={x:i.x,y:i.y,width:i.width,height:i.height,fontSize:i.fontSize};for(var u in s){let p=s[u],h=c[u];if(o.type==="exit"){const E=p;p=h,h=E}const d=h-p;l[u]=p+a/o.duration*d}return l}};const n=({element:a,dTime:i,animation:o})=>{const l=e.animations[o.name];return l?l({element:a,dTime:i,animation:o}):(console.error("Can not find animation type: "+o.name),{})};e.animate=n;const r=(a,i)=>{};e.registerAnimation=r})(EV);(function(e){var t=ue&&ue.__createBinding||(Object.create?function(z,I,H,N){N===void 0&&(N=H);var G=Object.getOwnPropertyDescriptor(I,H);G&&!("get"in G?!I.__esModule:G.writable||G.configurable)||(G={enumerable:!0,get:function(){return I[H]}}),Object.defineProperty(z,N,G)}:function(z,I,H,N){N===void 0&&(N=H),z[N]=I[H]}),n=ue&&ue.__setModuleDefault||(Object.create?function(z,I){Object.defineProperty(z,"default",{enumerable:!0,value:I})}:function(z,I){z.default=I}),r=ue&&ue.__importStar||function(z){if(z&&z.__esModule)return z;var I={};if(z!=null)for(var H in z)H!=="default"&&Object.prototype.hasOwnProperty.call(z,H)&&t(I,z,H);return n(I,z),I},a=ue&&ue.__rest||function(z,I){var H={};for(var N in z)Object.prototype.hasOwnProperty.call(z,N)&&I.indexOf(N)<0&&(H[N]=z[N]);if(z!=null&&typeof Object.getOwnPropertySymbols=="function"){var G=0;for(N=Object.getOwnPropertySymbols(z);G<N.length;G++)I.indexOf(N[G])<0&&Object.prototype.propertyIsEnumerable.call(z,N[G])&&(H[N[G]]=z[N[G]])}return H},i=ue&&ue.__importDefault||function(z){return z&&z.__esModule?z:{default:z}};Object.defineProperty(e,"__esModule",{value:!0}),e.createStore=e.Store=e.Font=e.Page=e.GroupElement=e.registerShapeModel=e.SVGElement=e.LineElement=e.VideoElement=e.ImageElement=e.TextElement=e.Element=e.Animation=e.Node=void 0;const o=hV,l=pV,s=q_e,c=i(F1),u=gV,p=yV,h=bV,d=Lb(),E=r(Ts),w=rl,S=kp,_=Gb,y=_V,v=wV,b=EV;(0,o.setLivelinessChecking)("ignore");const g=(z,I)=>{z.children&&z.children.forEach(H=>{I(H),g(H,I)})};e.Node=o.types.model("Node",{id:o.types.identifier,type:"none",name:"",opacity:1,custom:o.types.frozen(),visible:!0,selectable:!0,removable:!0,alwaysOnTop:!1,showInExport:!0}).postProcessSnapshot(z=>{const I=Object.assign({},z),H={};for(var N in I)N[0]!=="_"&&(H[N]=z[N]);return H}).views(z=>({get locked(){return!(z.draggable||z.contentEditable||z.styleEditable||z.resizable)},get page(){return(0,o.getParentOfType)(z,e.Page)},get store(){return(0,o.getParentOfType)(z,e.Store)},get top(){let I=z;for(;;){if(!(0,o.hasParentOfType)(I,e.GroupElement))return I;I=(0,o.getParentOfType)(I,e.GroupElement)}},get parent(){return(0,o.hasParentOfType)(z,e.GroupElement)?(0,o.getParentOfType)(z,e.GroupElement):(0,o.hasParentOfType)(z,e.Page)?(0,o.getParentOfType)(z,e.Page):(0,o.hasParentOfType)(z,e.Store)?(0,o.getParentOfType)(z,e.Store):null}})).actions(z=>({toJSON:()=>Object.assign({},(0,o.getSnapshot)(z))})).actions(z=>({clone(I={}){const H=z.toJSON();return I.id=I.id||(0,s.nanoid)(10),g(H,N=>{N.id=(0,s.nanoid)(10)}),Object.assign(H,I),z.page.addElement(H)},set(I){Object.assign(z,I)},moveUp(){z.page.moveElementsUp([z.id])},moveTop(){z.page.moveElementsTop([z.id])},moveDown(){z.page.moveElementsDown([z.id])},moveBottom(){z.page.moveElementsBottom([z.id])},beforeDestroy(){z.store.history.endTransaction()}})),e.Animation=o.types.model("Animation",{delay:0,duration:500,enabled:!0,type:o.types.enumeration("Type",["enter","exit"]),name:"none",data:o.types.frozen({})}),e.Element=e.Node.named("Element").props({x:0,y:0,width:100,height:100,rotation:0,opacity:1,animations:o.types.array(e.Animation),blurEnabled:!1,blurRadius:10,brightnessEnabled:!1,brightness:0,sepiaEnabled:!1,grayscaleEnabled:!1,shadowEnabled:!1,shadowBlur:5,shadowOffsetX:0,shadowOffsetY:0,shadowColor:"black",shadowOpacity:1,visible:!0,draggable:!0,resizable:!0,selectable:!0,contentEditable:!0,styleEditable:!0,alwaysOnTop:!1,showInExport:!0}).preProcessSnapshot(z=>{const I=Object.assign(Object.assign({},z),{x:z.x||0,y:z.y||0});return"width"in z&&(I.width=I.width||1),"height"in z&&(I.height=I.height||1),z.locked&&(I.draggable=!1,I.contentEditable=!1,I.styleEditable=!1,I.resizable=!1),I}).views(z=>({get a(){const{currentTime:I}=z.store,H={x:z.x,y:z.y,width:z.width,height:z.height,rotation:z.rotation,opacity:z.opacity,color:z.color,fontSize:z.fontSize};if(I===0)return H;const N=I-z.page.startTime;if(N>z.page.duration||N<0)return H;const G=z.store.animatedElementsIds;if(G.length&&!G.includes(z.id))return H;const D=z.animations.find(V=>V.type==="enter");if(D!=null&&D.enabled&&N<D.delay&&(H.opacity=0),D!=null&&D.enabled&&N>=D.delay&&N<=D.delay+D.duration){const V=N-D.delay,R=(0,b.animate)({element:z,animation:D,dTime:V});Object.assign(H,R)}const q=z.animations.find(V=>V.type==="exit");if(q!=null&&q.enabled&&N>=z.page.duration-q.duration){const V=N-(z.page.duration-q.duration),R=(0,b.animate)({element:z,animation:q,dTime:V});Object.assign(H,R)}return H},animated:I=>z.a[I]})).actions(z=>({setAnimation(I,H){const N=z.animations.find(G=>G.type===I);N?Object.assign(N,H):z.animations.push(Object.assign({type:I},H))}})),e.TextElement=e.Element.named("Text").props({type:"text",text:"",placeholder:"",fontSize:14,fontFamily:"Roboto",fontStyle:"normal",fontWeight:"normal",textDecoration:"",fill:"black",align:"center",width:100,height:0,verticalAlign:"top",strokeWidth:0,stroke:"black",lineHeight:o.types.optional(o.types.union(o.types.number,o.types.string),1.2),letterSpacing:0,_editModeEnabled:!1,backgroundEnabled:!1,backgroundColor:"#7ED321",backgroundOpacity:1,backgroundCornerRadius:.5,backgroundPadding:.5}).preProcessSnapshot(z=>Object.assign({},z)).actions(z=>({toggleEditMode(I){z._editModeEnabled=I??!z._editModeEnabled,z._editModeEnabled?z.store.history.startTransaction():z.store.history.endTransaction()}})),e.ImageElement=e.Element.named("Image").props({type:"image",width:100,height:100,src:"",cropX:0,cropY:0,cropWidth:1,cropHeight:1,cornerRadius:0,flipX:!1,flipY:!1,clipSrc:"",borderColor:"black",borderSize:0,keepRatio:!1,_cropModeEnabled:!1}).actions(z=>({toggleCropMode(I){z._cropModeEnabled=I??!z._cropModeEnabled,z._cropModeEnabled?z.store.history.startTransaction():z.store.history.endTransaction()}})),e.VideoElement=e.ImageElement.named("Video").props({type:"video",duration:0}),e.LineElement=e.Element.named("Line").props({type:"line",width:400,height:10,color:"black",dash:o.types.array(o.types.number),startHead:"",endHead:""}).actions(z=>({})),e.SVGElement=e.Element.named("SVG").props({type:"svg",src:"",maskSrc:"",cropX:0,cropY:0,cropWidth:1,cropHeight:1,keepRatio:!0,flipX:!1,flipY:!1,width:100,height:100,borderColor:"black",borderSize:0,cornerRadius:0,colorsReplace:o.types.map(o.types.string)}).preProcessSnapshot(z=>Object.assign(Object.assign({},z),{src:z.src||z.svgSource})).actions(z=>({replaceColor(I,H){z.colorsReplace.set(I,H)}}));const M=[];function C(z){const I=z.type;if(!I)throw new Error('You must pass "type" attribute to custom model.');const H=e.Element.named(I).props(z);T[I]=H,M.push(H)}e.registerShapeModel=C;const O=[...new Array(20)].map((z,I)=>o.types.late(()=>M[I])),L=o.types.union({dispatcher:z=>{const I=T[z.type];if(!I)throw new Error(`Unknown element type: "${z.type}"`);return I}},e.SVGElement,e.TextElement,e.ImageElement,e.LineElement,e.VideoElement,o.types.late(()=>e.GroupElement),...O);e.GroupElement=e.Node.named("Group").props({type:"group",children:o.types.array(L)}).views(z=>({get draggable(){let I=!0;return g(z,H=>{H.draggable||(I=!1)}),I},get resizable(){let I=!0;return g(z,H=>{H.resizable||(I=!1)}),I},get contentEditable(){let I=!0;return g(z,H=>{H.contentEditable||(I=!1)}),I},get styleEditable(){let I=!0;return g(z,H=>{H.styleEditable||(I=!1)}),I},get locked(){let I=!0;return g(z,H=>{H.locked||(I=!1)}),I}})).actions(z=>({set(I){var{draggable:H,contentEditable:N,styleEditable:G,resizable:D}=I,q=a(I,["draggable","contentEditable","styleEditable","resizable"]);H!==void 0&&g(z,V=>{V.set({draggable:H})}),N!==void 0&&g(z,V=>{V.set({contentEditable:N})}),G!==void 0&&g(z,V=>{V.set({styleEditable:G})}),D!==void 0&&g(z,V=>{V.set({resizable:D})}),Object.assign(z,q)}}));const T={svg:e.SVGElement,text:e.TextElement,image:e.ImageElement,group:e.GroupElement,line:e.LineElement,video:e.VideoElement};function A({key:z,showCredit:I}={key:"",showCredit:!1}){const H=e.Store.create();return(0,d.validateKey)(z,I),H}e.Page=o.types.model("Page",{id:o.types.identifier,children:o.types.array(L),width:o.types.optional(o.types.union(o.types.number,o.types.literal("auto")),"auto"),height:o.types.optional(o.types.union(o.types.number,o.types.literal("auto")),"auto"),background:"white",bleed:0,custom:o.types.frozen(),duration:5e3,_exporting:!1,_rendering:!1}).postProcessSnapshot(z=>{const I=Object.assign({},z),H={};for(var N in I)N[0]!=="_"&&(H[N]=z[N]);return H}).views(z=>({get store(){return(0,o.getParentOfType)(z,e.Store)},get startTime(){let I=0;for(const H of z.store.pages){if(H.id===z.id)return I;I+=H.duration}return I}})).views(z=>({get computedWidth(){return z.width==="auto"?z.store.width:z.width},get computedHeight(){return z.height==="auto"?z.store.height:z.height}})).actions(z=>({toJSON:()=>JSON.parse(JSON.stringify((0,o.getSnapshot)(z))),_forEachElementUp(I,H){const N=I.map(G=>({id:G,index:z.children.findIndex(D=>D.id===G)}));N.sort((G,D)=>D.index-G.index);for(const{index:G}of N){if(G==-1)continue;const D=G<z.children.length-1&&z.children[G+1],q=I.indexOf(D==null?void 0:D.id)>=0;G===z.children.length-1||q||H(G)}},_forEachElementDown(I,H){const N=I.map(G=>({id:G,index:z.children.findIndex(D=>D.id===G)}));N.sort((G,D)=>G.index-D.index);for(const{index:G}of N){if(G==-1)continue;const D=G>0&&z.children[G-1],q=I.indexOf(D==null?void 0:D.id)>=0;G===0||q||H(G)}return!1}})).actions(z=>({clone(I={}){const H=z.toJSON();H.children.forEach(q=>{q.id=(0,s.nanoid)(10),g(q,V=>{V.id=(0,s.nanoid)(10)})});const N=Object.assign(Object.assign(Object.assign({},H),{id:(0,s.nanoid)(10)}),I),G=z.store.addPage(N),D=z.store.pages.indexOf(z);G.setZIndex(D+1),G.select()},setZIndex(I){z.store.setPageZIndex(z.id,I)},set(I){Object.assign(z,I)},select(){z.store.selectPage(z.id)},addElement(I){const H=T[I.type];if(!H)return void console.error("Can not find model with type "+I.type);I.children&&I.children.forEach(G=>{G.id=(0,s.nanoid)(10)});const N=H.create(Object.assign({id:(0,s.nanoid)(10)},I));return z.children.push(N),N.selectable&&z.store.selectElements([N.id]),N},canMoveElementsUp(I){let H=!1;return z._forEachElementUp(I,()=>{H=H||!0}),H},moveElementsUp(I){z._forEachElementUp(I,H=>{const N=z.children[H];(0,o.detach)(N),z.children.splice(H+1,0,N)})},canMoveElementsTop(I){return this.canMoveElementsUp(I)},moveElementsTop(I){const H=[],N=[];z.children.forEach(G=>{I.indexOf(G.id)>=0?H.push(G):N.push(G)}),z.children.replace(N.concat(H))},canMoveElementsDown(I){let H=!1;return z._forEachElementDown(I,()=>{H=H||!0}),H},moveElementsDown(I){z._forEachElementDown(I,H=>{const N=z.children[H];(0,o.detach)(N),z.children.splice(H-1,0,N)})},canMoveElementsBottom(I){return this.canMoveElementsDown(I)},moveElementsBottom(I){const H=[],N=[];z.children.forEach(G=>{I.indexOf(G.id)>=0?H.push(G):N.push(G)}),z.children.replace(H.concat(N))},setElementZIndex(I,H){const N=z.children.find(G=>G.id===I);N&&((0,o.detach)(N),z.children.remove(N),z.children.splice(H,0,N))},setSize({width:I,height:H,useMagic:N,softChange:G}){if(N){const D=I/z.computedWidth,q=H/z.computedHeight;for(const V of z.children)V.set({x:V.x*D,y:V.y*q}),V.type==="text"?V.set({fontSize:V.fontSize*D,width:Math.max(V.width*D,2)}):V.type==="image"?V.set({width:V.width*D,height:V.height*q}):V.type==="svg"&&V.set({width:Math.max(V.width*D,2),height:Math.max(V.height*D,2)})}G||(z.width=I),G||(z.height=H)}})).actions(z=>({moveElementUp(I){console.warn("page.moveElementUp(id) is deprecated. Please use page.moveElementsUp([id1, id2]) instead."),z.moveElementsUp([I])},moveElementDown(I){console.warn("page.moveElementDown(id) is deprecated. Please use page.moveElementsDown([id1, id2]) instead."),z.moveElementsDown([I])},moveElementTop(I){console.warn("page.moveElementTop(id) is deprecated. Please use page.moveElementsTop([id1, id2]) instead."),z.moveElementsTop([I])},moveElementBottom(I){console.warn("page.moveElementBottom(id) is deprecated. Please use page.moveElementsBottom([id1, id2]) instead."),z.moveElementsBottom([I])}})),e.Font=o.types.model("Font",{fontFamily:o.types.string,url:o.types.optional(o.types.string,""),styles:o.types.frozen()}).preProcessSnapshot(z=>Object.assign(Object.assign({},z),{fontFamily:z.fontFamily||z.name})),e.Store=o.types.model("Store",{role:"",pages:o.types.array(e.Page),fonts:o.types.array(e.Font),width:1080,height:1080,currentTime:0,isPlaying:!1,scale:1,scaleToFit:1,unit:"px",dpi:72,bleedVisible:!1,rulesVisible:!1,openedSidePanel:"",selectedElementsIds:o.types.array(o.types.string),animatedElementsIds:o.types.array(o.types.string),history:o.types.optional(l.UndoManager,{targetPath:"../pages"}),_elementsPixelRatio:2,_activePageId:""}).views(z=>({get _bleedVisible(){return console.warn("store._bleedVisible is deprecated. Please use store.bleedVisible instead."),z.bleedVisible},get selectedElements(){return z.selectedElementsIds.map(I=>{for(const H of z.pages)for(const N of H.children)if(N.id===I)return N}).filter(I=>!!I)},get children(){return z.pages},get selectedShapes(){const I=[];return z.selectedElementsIds.forEach(H=>{for(const N of z.pages)for(const G of N.children)G.id===H&&G.type!=="group"&&I.push(G),G.type==="group"&&G.id===H&&I.push(...G.children)}),I},get activePage(){return z.pages.slice().find(I=>I.id===z._activePageId)||(z.pages.length?z.pages[0]:null)},get duration(){let I=0;return z.pages.forEach(H=>{I+=H.duration}),I}})).actions(z=>{let I=0;return{afterCreate(){z.history.canUndo},setCurrentTime(H){z.currentTime=H},play({animatedElementsIds:H=[],currentTime:N=0}={}){z.animatedElementsIds=(0,o.cast)(H),z.currentTime=N,z.isPlaying=!0,I=Date.now(),requestAnimationFrame(z.seek)},seek(){if(!z.isPlaying)return;const H=Date.now(),N=H-I;I=H,z.currentTime+=N;let G=0;for(const D of z.pages){if(z.currentTime>=D.startTime&&z.currentTime<D.startTime+D.duration){z.selectPage(D.id);break}G+=D.duration}z.isPlaying&&z.currentTime<z.duration?requestAnimationFrame(z.seek):z.stop()},stop(){z.isPlaying=!1,z.currentTime=0,z.animatedElementsIds=(0,o.cast)([])}}}).actions(z=>({setUnit({unit:I,dpi:H}){z.unit=I||z.unit,z.dpi=H||z.dpi},setRole(I){z.role=I},find(I){let H;return g({children:z.pages},N=>{!H&&I(N)&&(H=N)}),H},getElementById:I=>z.find(H=>H.id===I),addPage(I){const H=e.Page.create(Object.assign({id:(0,s.nanoid)(10)},I));return z.pages.push(H),z._activePageId=H.id,H},selectPage(I){z._activePageId=I},selectElements(I){const H=I.map(N=>z.getElementById(N)).sort((N,G)=>N.page.children.indexOf(N)-N.page.children.indexOf(G)).filter(N=>!!N).map(N=>N.id);z.selectedElementsIds=(0,o.cast)(H)},toggleBleed(I){z.bleedVisible=I??!z.bleedVisible},toggleRulers(I){z.rulesVisible=I??!z.rulesVisible},openSidePanel(I){z.openedSidePanel=I},setScale(I){z.scale=I},_setScaleToFit(I){z.scaleToFit=I},setElementsPixelRatio(I){z._elementsPixelRatio=I},setSize(I,H,N){z.pages.forEach(G=>{G.setSize({width:I,height:H,useMagic:N,softChange:!0})}),z.width=I,z.height=H},setPageZIndex(I,H){const N=z.pages.find(G=>G.id===I);N&&((0,o.detach)(N),z.pages.remove(N),z.pages.splice(H,0,N))},deletePages(I){const H=z.pages.indexOf(z.activePage);I.forEach(D=>{const q=z.pages.find(V=>V.id===D);(0,o.destroy)(q)});const N=Math.min(z.pages.length-1,H),G=z.pages[N];G&&(z._activePageId=G.id),z.selectedElementsIds=(0,o.cast)(z.selectedElementsIds.filter(D=>z.getElementById(D)))},groupElements(I){const H=I.map(D=>z.getElementById(D));H.forEach(D=>{D&&(0,o.detach)(D)});const N=z.activePage,G=e.GroupElement.create({id:(0,s.nanoid)(10),children:(0,o.cast)(H)});return N.children.push(G),z.selectedElementsIds=(0,o.cast)([G.id]),G},ungroupElements(I){const H=I.map(G=>z.getElementById(G)),N=[];H.forEach(G=>{if(G&&G.type==="group"){const D=G.page,q=D.children.indexOf(G);G.children.forEach(V=>{N.push(V.id)}),G.children.forEach(V=>{(0,o.detach)(V),D.children.push(V)}),D.children.splice(q,1)}}),z.selectedElementsIds=(0,o.cast)(N)},deleteElements(I){I.forEach(H=>{z.pages.forEach(N=>{const G=N.children.find(D=>D.id===H);G&&(0,o.destroy)(G)})}),z.selectedElementsIds=(0,o.cast)(z.selectedElementsIds.filter(H=>z.getElementById(H)))},on(I,H){if(I==="change"){let N=z.toJSON();return(0,o.onSnapshot)(z,G=>{const D=z.toJSON();!(0,_.deepEqual)(N,D)&&(N=D,H(D))})}},async _toCanvas({pixelRatio:I,ignoreBackground:H,pageId:N,mimeType:G,includeBleed:D}={}){var q;const V=I||1;N=N||((q=z.pages[0])===null||q===void 0?void 0:q.id);const R=z.pages.find(le=>le.id===N);if(!R)throw new Error(`No page for export with id ${N}`);R==null||R.set({_exporting:!0});const P=await(0,y.waitTillAvailable)(()=>c.default.stages.find(le=>le.getAttr("pageId")===N));if(!P)throw new Error(`Export is failed. Can not find stage for page ${N}. Looks like <Workspace /> component is not mounted, but it is required in order to process the export.`);const F=!!P.findOne(".page-container");await z.waitLoading();const B=P.findOne(".page-container");if(!B)throw new Error(`Export is failed. Can't find page container. ${F}`);P.find("Transformer").forEach(le=>le.visible(!1)),B.find(".page-background").forEach(le=>le.shadowEnabled(!1)),B.find(".page-background").forEach(le=>le.strokeEnabled(!1)),B.find(".highlighter").forEach(le=>le.visible(!1));const Y=B.findOne(".page-background-group"),J=Y.clip();Y.clip({x:null,y:null,width:null,height:null});const Z=B.findOne(".elements-container"),K=Z.clip();Z.clip({x:null,y:null,width:null,height:null});const U=B.find(le=>le.getAttr("hideInExport"));U.forEach(le=>{le.setAttr("oldVisible",le.visible()),le.hide()});const W=B.find(le=>!le.visible()&&le.getAttr("editModeEnabled"));W.forEach(le=>{le.setAttr("oldVisible",le.visible()),le.show()}),H&&B.find(".page-background").forEach(le=>le.hide());const X=D?R.bleed:0;let ee=X;z.bleedVisible&&D?ee=0:z.bleedVisible&&!D&&(ee=-R.bleed);const te=document.createElement("canvas");te.width=(R.computedWidth+2*X)*V,te.height=(R.computedHeight+2*X)*V;const ne=te.getContext("2d");G==="image/jpeg"&&(ne.fillStyle="white",ne.fillRect(0,0,te.width,te.height));const ce=B.toCanvas({x:B.x()-ee*B.scaleX(),y:B.y()-ee*B.scaleY(),width:(R.computedWidth+2*X)*B.scaleX(),height:(R.computedHeight+2*X)*B.scaleY(),pixelRatio:1/B.scaleX()*V});return ne.drawImage(ce,0,0),c.default.Util.releaseCanvas(ce),H&&B.find(".page-background").forEach(le=>le.show()),U.forEach(le=>{le.visible(le.getAttr("oldVisible"))}),W.forEach(le=>{le.visible(le.getAttr("oldVisible"))}),B.find(".page-background").forEach(le=>le.shadowEnabled(!0)),B.find(".page-background").forEach(le=>le.strokeEnabled(!0)),P.find("Transformer").forEach(le=>le.visible(!0)),B.find(".highlighter").forEach(le=>le.visible(!0)),Y.clip(J),Z.clip(K),R==null||R.set({_exporting:!1}),te},async toDataURL({pixelRatio:I,ignoreBackground:H,pageId:N,mimeType:G,includeBleed:D,quality:q}={}){const V=await z._toCanvas({pixelRatio:I,ignoreBackground:H,pageId:N,mimeType:G,includeBleed:D}),R=V.toDataURL(G,q);return c.default.Util.releaseCanvas(V),R},async toBlob({pixelRatio:I,ignoreBackground:H,pageId:N,mimeType:G,includeBleed:D,quality:q}={}){const V=await z._toCanvas({pixelRatio:I,ignoreBackground:H,pageId:N,mimeType:G,includeBleed:D}),R=new Promise(P=>{V.toBlob(P,G,q)});return c.default.Util.releaseCanvas(V),R},async saveAsImage(I={}){var{fileName:H}=I,N=a(I,["fileName"]);const G=N.mimeType||"image/png",D=G.split("/")[1];(0,u.downloadFile)(await z.toDataURL(N),H||"polotno."+D,G)},async _toPDF(I){const H=I.dpi||z.dpi,N=I.parallel||1,G=I.unit||(z.unit==="px"?"mm":z.unit),D=I.pixelRatio||1,q=I.pageIds||z.pages.map(W=>W.id),V=z.pages.filter(W=>q.includes(W.id)),R=await(0,p.getJsPDF)(),P=W=>(0,S.pxToUnit)({px:W,unit:G,dpi:H}),F=V[0]||{},B=I.includeBleed?F.bleed:0,Y=P(F.computedWidth+2*B),J=P(F.computedHeight+2*B);var Z=new R({unit:G,orientation:Y>J?"landscape":"portrait",format:[Y,J],compress:!0,putOnlyUsedFonts:!0});Z.deletePage(1);const K=z._elementsPixelRatio;z.setElementsPixelRatio(D),await new Promise(W=>setTimeout(W));const U=((W,X)=>{for(var ee=[],te=0;te<W.length;te+=X)ee.push(W.slice(te,te+X));return ee})(V,N);for(const W of U){const X=W.map(async ee=>{const te=I.includeBleed?ee.bleed:0,ne=P(ee.computedWidth+2*te),ce=P(ee.computedHeight+2*te);let le=0,Te=D;for(;le<10;){le+=1,le===2&&console.error("Polotno can not export PDF with current settings. Quality is automatically reduced.");const Ce=await z.toDataURL(Object.assign(Object.assign({},I),{pageId:ee.id,pixelRatio:Te}));if(Ce.length>20)return{url:Ce,width:ne,height:ce};Te*=.8}});(await Promise.all(X)).forEach(({url:ee,width:te,height:ne})=>{Z.addPage([te,ne],te>ne?"landscape":"portrait"),Z.addImage(ee,0,0,te,ne,void 0,"FAST")})}return z.setElementsPixelRatio(K),Z},toPDFDataURL:async I=>(await z._toPDF(Object.assign({mimeType:"image/jpeg"},I))).output("datauristring"),async toGIFDataURL(I={}){const H=I.pixelRatio||1,N=await(0,h.createGIF)({width:z.width*H,height:z.height*H}),G=1e3/(I.fps||10),D=z.duration/G;for(let q=0;q<D-1;q++){const V=q*G||1;z.setCurrentTime(V);let R=0,P="";for(const B of z.pages)if(R+=B.duration,B.set({_rendering:R>V}),R>V){P=B.id;break}const F=await z._toCanvas({pixelRatio:H,pageId:P});N.addFrame(F.getContext("2d"),{delay:G,copy:!0})}for(const q of z.pages)q.set({_rendering:!1});return z.stop(),N.render(),new Promise(q=>{N.on("finished",function(V){(function(R,P){var F=new FileReader;F.onload=function(B){P(B.target.result)},F.readAsDataURL(R)})(V,q)})})},async saveAsGIF(I={}){var{fileName:H}=I,N=a(I,["fileName"]);const G=await z.toGIFDataURL(N);(0,u.downloadFile)(G,H||"polotno.gif")},async toHTML(){const I=z.toJSON();return(0,v.jsonToHTML)({json:I})},async saveAsHTML({filename:I}={}){const H=await z.toHTML(),N="data:text/html;base64,"+window.btoa(unescape(encodeURIComponent(H)));(0,u.downloadFile)(N,I||"polotno.html")},async saveAsPDF(I={}){var{fileName:H}=I,N=a(I,["fileName"]);(await z._toPDF(Object.assign({mimeType:"image/jpeg"},N))).save(H||"polotno.pdf")},async waitLoading(){await new Promise(I=>setTimeout(I,50)),await(0,w.whenLoaded)()},toJSON:()=>({width:z.width,height:z.height,fonts:(0,o.getSnapshot)(z.fonts),pages:(0,o.getSnapshot)(z.pages),unit:z.unit,dpi:z.dpi}),loadJSON(I,H=!1){var N;const G=Object.assign({},I),D=z.pages.indexOf(z.activePage);let q=(N=G.pages[D]||G.pages[0])===null||N===void 0?void 0:N.id;G._activePageId=q;const V=Object.assign({},(0,o.getSnapshot)(z));Object.assign(V,G),V.history=H?z.history.toJSON():{history:[],undoIdx:-1},(0,o.applySnapshot)(z,V)},clear({keepHistory:I=!1}={}){const H=z.pages.map(N=>N.id);z.deletePages(H),I||z.history.clear()},addFont(I){z.removeFont(I.fontFamily),z.fonts.push(I),z.loadFont(I.fontFamily)},removeFont(I){z.fonts.filter(H=>H.fontFamily===I).forEach(H=>(0,o.destroy)(H))},async loadFont(I){const H=z.fonts.find(N=>N.fontFamily===I)||E.globalFonts.find(N=>N.fontFamily===I);H?E.injectCustomFont(H):E.injectGoogleFont(I),await E.loadFont(I)}})),e.createStore=A,e.default=A})(Rb);var kl={},SV={},CV={};(function(e){async function t(n){return new Promise((r,a)=>{const i=new FileReader;i.readAsDataURL(n),i.onload=()=>r(i.result),i.onerror=o=>a(o)})}Object.defineProperty(e,"__esModule",{value:!0}),e.localFileToURL=void 0,e.localFileToURL=t})(CV);var OV={};(function(e){var t=ue&&ue.__importDefault||function(_){return _&&_.__esModule?_:{default:_}};Object.defineProperty(e,"__esModule",{value:!0}),e.ImagesGrid=void 0;const n=t(j),r=t($i),a=Ut,i=_n,o=X5,l=ma,s=(0,r.default)("div",n.default.forwardRef)`
247
+ `).join("<br />"));return l("div",{style:{position:"relative"}},T,A)},p=({element:g,type:M})=>{const C={"stroke-width":g.height,stroke:g.color,"line-cap":"round","stroke-linejoin":"round",opacity:g.opacity};return M==="arrow"||M==="triangle"?l("polyline",Object.assign({points:`${3*g.height},${2*-g.height} 0,0 ${3*g.height},${2*g.height}`},C)):M==="bar"?l("polyline",Object.assign({points:`0,${2*-g.height} 0,${2*g.height}`},C)):M==="circle"?l("circle",Object.assign({r:g.height},C)):M==="square"?l("polyline",Object.assign({points:`${-g.height},${-g.height} ${-g.height},${g.height} ${g.height},${g.height} ${g.height},${-g.height}`},C)):null},h=async({element:g,page:M,store:C})=>l("svg",{style:{width:"100%",height:"100%",contain:"layout style size",overflow:"visible"}},l("rect",{x:0,y:0,width:g.width,height:g.height,fill:g.color}),l("g",{transform:`translate(0 ${g.height/2})`},p({element:g,type:g.startHead})),l("g",{transform:`translate(${g.width} ${g.height/2}) rotate(180)`},p({element:g,type:g.endHead}))),d=async({element:g,page:M,store:C,elementHook:O})=>{const L=await Promise.all(g.children.map(A=>w({element:A,page:M,store:C,elementHook:O}))),T=l("div",{style:{"transform-origin":"top left",opacity:g.opacity}},...L);return O&&O({dom:T,element:g})||T},E={image:c,svg:c,text:u,line:h,group:d};async function w({element:g,page:M,store:C,elementHook:O}){let L=await E[g.type];L||(L=()=>l("div",{}),console.error(`HTML export does not support ${g.type} type...`));const T=await L({element:g,page:M,store:C}),A=[];g.blurEnabled&&A.push(`blur(${g.blurRadius/2}px)`),g.brightnessEnabled&&A.push(`brightness(${100*g.brightness+100}%)`),g.sepiaEnabled&&A.push("sepia()"),g.grayscaleEnabled&&A.push("grayscale()"),g.shadowEnabled&&A.push(`drop-shadow(${g.shadowOffsetX}px ${g.shadowOffsetY}px ${g.shadowBlur}px ${g.shadowColor})`);const z=l("div",{style:{position:"absolute",left:g.x+"px",top:g.y+"px",width:g.width+"px",height:g.height+"px",transform:`rotate(${g.rotation}deg)`,"transform-origin":"top left",opacity:g.opacity,filter:A.join(" ")}},T);return O&&O({dom:z,element:g})||z}async function S({page:g,store:M,elementHook:C}){const O=await Promise.all(g.children.map(T=>w({element:T,page:g,store:M,elementHook:C})));let L={};if(g.background.indexOf("url")>=0||g.background.indexOf("http")>=0||g.background.indexOf(".jpg")>=0||g.background.indexOf(".png")>=0||g.background.indexOf(".jpeg")>=0){const T=await(0,o.loadImage)(g.background),A=await(0,o.cropImage)(g.background,Object.assign({width:M.width,height:M.height,x:0,y:0},(0,a.getCrop)({width:M.width,height:M.height},{width:T.width,height:T.height})));L=Object.assign(Object.assign({},L),{"background-image":`url(${A})`})}return l("div",{className:"page",style:Object.assign(Object.assign({},L),{width:M.width+"px",height:M.height+"px",background:g.background,border:"1px solid grey",overflow:"hidden",position:"relative"})},...O)}async function _({json:g,elementHook:M}){const C=await Promise.all(g.pages.map(T=>S({page:T,store:g,elementHook:M}))),O=[];g.pages.forEach(T=>{T.children.forEach(A=>{A.type==="text"&&O.indexOf(A.fontFamily)===-1&&O.push(A.fontFamily)})});const L=O.map(T=>g.fonts.find(A=>A.fontFamily===T)?l("style",{},""):l("link",{href:`https://fonts.googleapis.com/css?family=${T}`,rel:"stylesheet"}));return l("div",{className:"design"},...L,...C)}e.jsonToDOM=_;const y=(g,M)=>typeof M=="object"?`${g}="${Object.keys(M).map(C=>`${C}:${M[C]};`).join(" ")}"`:`${g}="${M}"`,v=({dom:g})=>typeof g=="string"?g:g?`<${g.type} ${Object.keys(g.props).map(M=>y(M,g.props[M])).join(" ")}>${g.children.map(M=>v({dom:M})).join("")}</${g.type}>`:"";async function b({json:g,elementHook:M}){const C=await _({json:g,elementHook:M});return v({dom:C})}e.jsonToHTML=b})(wV);var EV={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.registerAnimation=e.animate=e.animations=void 0;const t={right:{from:{x:-200},to:{x:0}},left:{from:{x:200},to:{x:0}},up:{from:{y:200},to:{y:0}},down:{from:{y:-200},to:{y:0}},"bottom-right":{from:{x:-200,y:-200},to:{x:0,y:0}},"bottom-left":{from:{x:200,y:-200},to:{x:0,y:0}},"top-right":{from:{x:-200,y:200},to:{x:0,y:0}},"top-left":{from:{x:200,y:200},to:{x:0,y:0}}};e.animations={fade:({dTime:a,element:i,animation:o})=>{const l=a/o.duration;return o.type==="enter"?{opacity:l*i.opacity}:{opacity:(1-l)*i.opacity}},move:({dTime:a,element:i,animation:o})=>{const l=t[o.data.direction]||t.right,s={};for(var c in l.from){let u=i[c]+l.from[c],p=i[c]+l.to[c];if(o.type==="exit"){const d=u;u=p,p=-d}const h=p-u;s[c]=u+a/o.duration*h}return s},zoom:({dTime:a,element:i,animation:o})=>{const l={},s={x:i.x+i.width/3,y:i.y+i.height/3,width:i.width/3,height:i.height/3,fontSize:i.fontSize/3},c={x:i.x,y:i.y,width:i.width,height:i.height,fontSize:i.fontSize};for(var u in s){let p=s[u],h=c[u];if(o.type==="exit"){const E=p;p=h,h=E}const d=h-p;l[u]=p+a/o.duration*d}return l}};const n=({element:a,dTime:i,animation:o})=>{const l=e.animations[o.name];return l?l({element:a,dTime:i,animation:o}):(console.error("Can not find animation type: "+o.name),{})};e.animate=n;const r=(a,i)=>{};e.registerAnimation=r})(EV);(function(e){var t=ue&&ue.__createBinding||(Object.create?function(z,I,H,N){N===void 0&&(N=H);var G=Object.getOwnPropertyDescriptor(I,H);G&&!("get"in G?!I.__esModule:G.writable||G.configurable)||(G={enumerable:!0,get:function(){return I[H]}}),Object.defineProperty(z,N,G)}:function(z,I,H,N){N===void 0&&(N=H),z[N]=I[H]}),n=ue&&ue.__setModuleDefault||(Object.create?function(z,I){Object.defineProperty(z,"default",{enumerable:!0,value:I})}:function(z,I){z.default=I}),r=ue&&ue.__importStar||function(z){if(z&&z.__esModule)return z;var I={};if(z!=null)for(var H in z)H!=="default"&&Object.prototype.hasOwnProperty.call(z,H)&&t(I,z,H);return n(I,z),I},a=ue&&ue.__rest||function(z,I){var H={};for(var N in z)Object.prototype.hasOwnProperty.call(z,N)&&I.indexOf(N)<0&&(H[N]=z[N]);if(z!=null&&typeof Object.getOwnPropertySymbols=="function"){var G=0;for(N=Object.getOwnPropertySymbols(z);G<N.length;G++)I.indexOf(N[G])<0&&Object.prototype.propertyIsEnumerable.call(z,N[G])&&(H[N[G]]=z[N[G]])}return H},i=ue&&ue.__importDefault||function(z){return z&&z.__esModule?z:{default:z}};Object.defineProperty(e,"__esModule",{value:!0}),e.createStore=e.Store=e.Font=e.Page=e.GroupElement=e.registerShapeModel=e.SVGElement=e.LineElement=e.VideoElement=e.ImageElement=e.TextElement=e.Element=e.Animation=e.Node=void 0;const o=hV,l=pV,s=q_e,c=i(F1),u=gV,p=yV,h=bV,d=Lb(),E=r(Ts),w=rl,S=kp,_=Gb,y=_V,v=wV,b=EV;(0,o.setLivelinessChecking)("ignore");const g=(z,I)=>{z.children&&z.children.forEach(H=>{I(H),g(H,I)})};e.Node=o.types.model("Node",{id:o.types.identifier,type:"none",name:"",opacity:1,custom:o.types.frozen(),visible:!0,selectable:!0,removable:!0,alwaysOnTop:!1,showInExport:!0}).postProcessSnapshot(z=>{const I=Object.assign({},z),H={};for(var N in I)N[0]!=="_"&&(H[N]=z[N]);return H}).views(z=>({get locked(){return!(z.draggable||z.contentEditable||z.styleEditable||z.resizable)},get page(){return(0,o.getParentOfType)(z,e.Page)},get store(){return(0,o.getParentOfType)(z,e.Store)},get top(){let I=z;for(;;){if(!(0,o.hasParentOfType)(I,e.GroupElement))return I;I=(0,o.getParentOfType)(I,e.GroupElement)}},get parent(){return(0,o.hasParentOfType)(z,e.GroupElement)?(0,o.getParentOfType)(z,e.GroupElement):(0,o.hasParentOfType)(z,e.Page)?(0,o.getParentOfType)(z,e.Page):(0,o.hasParentOfType)(z,e.Store)?(0,o.getParentOfType)(z,e.Store):null}})).actions(z=>({toJSON:()=>Object.assign({},(0,o.getSnapshot)(z))})).actions(z=>({clone(I={}){const H=z.toJSON();return I.id=I.id||(0,s.nanoid)(10),g(H,N=>{N.id=(0,s.nanoid)(10)}),Object.assign(H,I),z.page.addElement(H)},set(I){Object.assign(z,I)},moveUp(){z.page.moveElementsUp([z.id])},moveTop(){z.page.moveElementsTop([z.id])},moveDown(){z.page.moveElementsDown([z.id])},moveBottom(){z.page.moveElementsBottom([z.id])},beforeDestroy(){z.store.history.endTransaction()}})),e.Animation=o.types.model("Animation",{delay:0,duration:500,enabled:!0,type:o.types.enumeration("Type",["enter","exit"]),name:"none",data:o.types.frozen({})}),e.Element=e.Node.named("Element").props({x:0,y:0,width:100,height:100,rotation:0,opacity:1,animations:o.types.array(e.Animation),blurEnabled:!1,blurRadius:10,brightnessEnabled:!1,brightness:0,sepiaEnabled:!1,grayscaleEnabled:!1,shadowEnabled:!1,shadowBlur:5,shadowOffsetX:0,shadowOffsetY:0,shadowColor:"black",shadowOpacity:1,visible:!0,draggable:!0,resizable:!0,selectable:!0,contentEditable:!0,styleEditable:!0,alwaysOnTop:!1,showInExport:!0}).preProcessSnapshot(z=>{const I=Object.assign(Object.assign({},z),{x:z.x||0,y:z.y||0});return"width"in z&&(I.width=I.width||1),"height"in z&&(I.height=I.height||1),z.locked&&(I.draggable=!1,I.contentEditable=!1,I.styleEditable=!1,I.resizable=!1),I}).views(z=>({get a(){const{currentTime:I}=z.store,H={x:z.x,y:z.y,width:z.width,height:z.height,rotation:z.rotation,opacity:z.opacity,color:z.color,fontSize:z.fontSize};if(I===0)return H;const N=I-z.page.startTime;if(N>z.page.duration||N<0)return H;const G=z.store.animatedElementsIds;if(G.length&&!G.includes(z.id))return H;const D=z.animations.find(V=>V.type==="enter");if(D!=null&&D.enabled&&N<D.delay&&(H.opacity=0),D!=null&&D.enabled&&N>=D.delay&&N<=D.delay+D.duration){const V=N-D.delay,R=(0,b.animate)({element:z,animation:D,dTime:V});Object.assign(H,R)}const q=z.animations.find(V=>V.type==="exit");if(q!=null&&q.enabled&&N>=z.page.duration-q.duration){const V=N-(z.page.duration-q.duration),R=(0,b.animate)({element:z,animation:q,dTime:V});Object.assign(H,R)}return H},animated:I=>z.a[I]})).actions(z=>({setAnimation(I,H){const N=z.animations.find(G=>G.type===I);N?Object.assign(N,H):z.animations.push(Object.assign({type:I},H))}})),e.TextElement=e.Element.named("Text").props({type:"text",text:"",placeholder:"",fontSize:14,fontFamily:"Roboto",fontStyle:"normal",fontWeight:"normal",textDecoration:"",fill:"black",align:"center",width:100,height:0,verticalAlign:"top",strokeWidth:0,stroke:"black",lineHeight:o.types.optional(o.types.union(o.types.number,o.types.string),1.2),letterSpacing:0,_editModeEnabled:!1,backgroundEnabled:!1,backgroundColor:"#7ED321",backgroundOpacity:1,backgroundCornerRadius:.5,backgroundPadding:.5}).preProcessSnapshot(z=>Object.assign({},z)).actions(z=>({toggleEditMode(I){z._editModeEnabled=I??!z._editModeEnabled,z._editModeEnabled?z.store.history.startTransaction():z.store.history.endTransaction()}})),e.ImageElement=e.Element.named("Image").props({type:"image",width:100,height:100,src:"",cropX:0,cropY:0,cropWidth:1,cropHeight:1,cornerRadius:0,flipX:!1,flipY:!1,clipSrc:"",borderColor:"black",borderSize:0,keepRatio:!1,_cropModeEnabled:!1}).actions(z=>({toggleCropMode(I){z._cropModeEnabled=I??!z._cropModeEnabled,z._cropModeEnabled?z.store.history.startTransaction():z.store.history.endTransaction()}})),e.VideoElement=e.ImageElement.named("Video").props({type:"video",duration:0}),e.LineElement=e.Element.named("Line").props({type:"line",width:400,height:10,color:"black",dash:o.types.array(o.types.number),startHead:"",endHead:""}).actions(z=>({})),e.SVGElement=e.Element.named("SVG").props({type:"svg",src:"",maskSrc:"",cropX:0,cropY:0,cropWidth:1,cropHeight:1,keepRatio:!0,flipX:!1,flipY:!1,width:100,height:100,borderColor:"black",borderSize:0,cornerRadius:0,colorsReplace:o.types.map(o.types.string)}).preProcessSnapshot(z=>Object.assign(Object.assign({},z),{src:z.src||z.svgSource})).actions(z=>({replaceColor(I,H){z.colorsReplace.set(I,H)}}));const M=[];function C(z){const I=z.type;if(!I)throw new Error('You must pass "type" attribute to custom model.');const H=e.Element.named(I).props(z);T[I]=H,M.push(H)}e.registerShapeModel=C;const O=[...new Array(20)].map((z,I)=>o.types.late(()=>M[I])),L=o.types.union({dispatcher:z=>{const I=T[z.type];if(!I)throw new Error(`Unknown element type: "${z.type}"`);return I}},e.SVGElement,e.TextElement,e.ImageElement,e.LineElement,e.VideoElement,o.types.late(()=>e.GroupElement),...O);e.GroupElement=e.Node.named("Group").props({type:"group",children:o.types.array(L)}).views(z=>({get draggable(){let I=!0;return g(z,H=>{H.draggable||(I=!1)}),I},get resizable(){let I=!0;return g(z,H=>{H.resizable||(I=!1)}),I},get contentEditable(){let I=!0;return g(z,H=>{H.contentEditable||(I=!1)}),I},get styleEditable(){let I=!0;return g(z,H=>{H.styleEditable||(I=!1)}),I},get locked(){let I=!0;return g(z,H=>{H.locked||(I=!1)}),I}})).actions(z=>({set(I){var{draggable:H,contentEditable:N,styleEditable:G,resizable:D}=I,q=a(I,["draggable","contentEditable","styleEditable","resizable"]);H!==void 0&&g(z,V=>{V.set({draggable:H})}),N!==void 0&&g(z,V=>{V.set({contentEditable:N})}),G!==void 0&&g(z,V=>{V.set({styleEditable:G})}),D!==void 0&&g(z,V=>{V.set({resizable:D})}),Object.assign(z,q)}}));const T={svg:e.SVGElement,text:e.TextElement,image:e.ImageElement,group:e.GroupElement,line:e.LineElement,video:e.VideoElement};function A({key:z,showCredit:I}={key:"",showCredit:!1}){const H=e.Store.create();return(0,d.validateKey)(z,I),H}e.Page=o.types.model("Page",{id:o.types.identifier,children:o.types.array(L),width:o.types.optional(o.types.union(o.types.number,o.types.literal("auto")),"auto"),height:o.types.optional(o.types.union(o.types.number,o.types.literal("auto")),"auto"),background:"white",bleed:0,custom:o.types.frozen(),duration:5e3,_exporting:!1,_rendering:!1}).postProcessSnapshot(z=>{const I=Object.assign({},z),H={};for(var N in I)N[0]!=="_"&&(H[N]=z[N]);return H}).views(z=>({get store(){return(0,o.getParentOfType)(z,e.Store)},get startTime(){let I=0;for(const H of z.store.pages){if(H.id===z.id)return I;I+=H.duration}return I}})).views(z=>({get computedWidth(){return z.width==="auto"?z.store.width:z.width},get computedHeight(){return z.height==="auto"?z.store.height:z.height}})).actions(z=>({toJSON:()=>JSON.parse(JSON.stringify((0,o.getSnapshot)(z))),_forEachElementUp(I,H){const N=I.map(G=>({id:G,index:z.children.findIndex(D=>D.id===G)}));N.sort((G,D)=>D.index-G.index);for(const{index:G}of N){if(G==-1)continue;const D=G<z.children.length-1&&z.children[G+1],q=I.indexOf(D==null?void 0:D.id)>=0;G===z.children.length-1||q||H(G)}},_forEachElementDown(I,H){const N=I.map(G=>({id:G,index:z.children.findIndex(D=>D.id===G)}));N.sort((G,D)=>G.index-D.index);for(const{index:G}of N){if(G==-1)continue;const D=G>0&&z.children[G-1],q=I.indexOf(D==null?void 0:D.id)>=0;G===0||q||H(G)}return!1}})).actions(z=>({clone(I={}){const H=z.toJSON();H.children.forEach(q=>{q.id=(0,s.nanoid)(10),g(q,V=>{V.id=(0,s.nanoid)(10)})});const N=Object.assign(Object.assign(Object.assign({},H),{id:(0,s.nanoid)(10)}),I),G=z.store.addPage(N),D=z.store.pages.indexOf(z);G.setZIndex(D+1),G.select()},setZIndex(I){z.store.setPageZIndex(z.id,I)},set(I){Object.assign(z,I)},select(){z.store.selectPage(z.id)},addElement(I){const H=T[I.type];if(!H)return void console.error("Can not find model with type "+I.type);I.children&&I.children.forEach(G=>{G.id=(0,s.nanoid)(10)});const N=H.create(Object.assign({id:(0,s.nanoid)(10)},I));return z.children.push(N),N.selectable&&z.store.selectElements([N.id]),N},canMoveElementsUp(I){let H=!1;return z._forEachElementUp(I,()=>{H=H||!0}),H},moveElementsUp(I){z._forEachElementUp(I,H=>{const N=z.children[H];(0,o.detach)(N),z.children.splice(H+1,0,N)})},canMoveElementsTop(I){return this.canMoveElementsUp(I)},moveElementsTop(I){const H=[],N=[];z.children.forEach(G=>{I.indexOf(G.id)>=0?H.push(G):N.push(G)}),z.children.replace(N.concat(H))},canMoveElementsDown(I){let H=!1;return z._forEachElementDown(I,()=>{H=H||!0}),H},moveElementsDown(I){z._forEachElementDown(I,H=>{const N=z.children[H];(0,o.detach)(N),z.children.splice(H-1,0,N)})},canMoveElementsBottom(I){return this.canMoveElementsDown(I)},moveElementsBottom(I){const H=[],N=[];z.children.forEach(G=>{I.indexOf(G.id)>=0?H.push(G):N.push(G)}),z.children.replace(H.concat(N))},setElementZIndex(I,H){const N=z.children.find(G=>G.id===I);N&&((0,o.detach)(N),z.children.remove(N),z.children.splice(H,0,N))},setSize({width:I,height:H,useMagic:N,softChange:G}){if(N){const D=I/z.computedWidth,q=H/z.computedHeight;for(const V of z.children)V.set({x:V.x*D,y:V.y*q}),V.type==="text"?V.set({fontSize:V.fontSize*D,width:Math.max(V.width*D,2)}):V.type==="image"?V.set({width:V.width*D,height:V.height*q}):V.type==="svg"&&V.set({width:Math.max(V.width*D,2),height:Math.max(V.height*D,2)})}G||(z.width=I),G||(z.height=H)}})).actions(z=>({moveElementUp(I){console.warn("page.moveElementUp(id) is deprecated. Please use page.moveElementsUp([id1, id2]) instead."),z.moveElementsUp([I])},moveElementDown(I){console.warn("page.moveElementDown(id) is deprecated. Please use page.moveElementsDown([id1, id2]) instead."),z.moveElementsDown([I])},moveElementTop(I){console.warn("page.moveElementTop(id) is deprecated. Please use page.moveElementsTop([id1, id2]) instead."),z.moveElementsTop([I])},moveElementBottom(I){console.warn("page.moveElementBottom(id) is deprecated. Please use page.moveElementsBottom([id1, id2]) instead."),z.moveElementsBottom([I])}})),e.Font=o.types.model("Font",{fontFamily:o.types.string,url:o.types.optional(o.types.string,""),styles:o.types.frozen()}).preProcessSnapshot(z=>Object.assign(Object.assign({},z),{fontFamily:z.fontFamily||z.name})),e.Store=o.types.model("Store",{role:"",pages:o.types.array(e.Page),fonts:o.types.array(e.Font),width:1080,height:1080,currentTime:0,isPlaying:!1,scale:1,scaleToFit:1,unit:"px",dpi:72,bleedVisible:!1,rulesVisible:!1,openedSidePanel:"",selectedElementsIds:o.types.array(o.types.string),animatedElementsIds:o.types.array(o.types.string),history:o.types.optional(l.UndoManager,{targetPath:"../pages"}),_elementsPixelRatio:2,_activePageId:""}).views(z=>({get _bleedVisible(){return console.warn("store._bleedVisible is deprecated. Please use store.bleedVisible instead."),z.bleedVisible},get selectedElements(){return z.selectedElementsIds.map(I=>{for(const H of z.pages)for(const N of H.children)if(N.id===I)return N}).filter(I=>!!I)},get children(){return z.pages},get selectedShapes(){const I=[];return z.selectedElementsIds.forEach(H=>{for(const N of z.pages)for(const G of N.children)G.id===H&&G.type!=="group"&&I.push(G),G.type==="group"&&G.id===H&&I.push(...G.children)}),I},get activePage(){return z.pages.slice().find(I=>I.id===z._activePageId)||(z.pages.length?z.pages[0]:null)},get duration(){let I=0;return z.pages.forEach(H=>{I+=H.duration}),I}})).actions(z=>{let I=0;return{afterCreate(){z.history.canUndo},setCurrentTime(H){z.currentTime=H},play({animatedElementsIds:H=[],currentTime:N=0}={}){z.animatedElementsIds=(0,o.cast)(H),z.currentTime=N,z.isPlaying=!0,I=Date.now(),requestAnimationFrame(z.seek)},seek(){if(!z.isPlaying)return;const H=Date.now(),N=H-I;I=H,z.currentTime+=N;let G=0;for(const D of z.pages){if(z.currentTime>=D.startTime&&z.currentTime<D.startTime+D.duration){z.selectPage(D.id);break}G+=D.duration}z.isPlaying&&z.currentTime<z.duration?requestAnimationFrame(z.seek):z.stop()},stop(){z.isPlaying=!1,z.currentTime=0,z.animatedElementsIds=(0,o.cast)([])}}}).actions(z=>({setUnit({unit:I,dpi:H}){z.unit=I||z.unit,z.dpi=H||z.dpi},setRole(I){z.role=I},find(I){let H;return g({children:z.pages},N=>{!H&&I(N)&&(H=N)}),H},getElementById:I=>z.find(H=>H.id===I),addPage(I){const H=e.Page.create(Object.assign({id:(0,s.nanoid)(10)},I));return z.pages.push(H),z._activePageId=H.id,H},selectPage(I){z._activePageId=I},selectElements(I){const H=I.map(N=>z.getElementById(N)).sort((N,G)=>N.page.children.indexOf(N)-N.page.children.indexOf(G)).filter(N=>!!N).map(N=>N.id);z.selectedElementsIds=(0,o.cast)(H)},toggleBleed(I){z.bleedVisible=I??!z.bleedVisible},toggleRulers(I){z.rulesVisible=I??!z.rulesVisible},openSidePanel(I){z.openedSidePanel=I},setScale(I){z.scale=I},_setScaleToFit(I){z.scaleToFit=I},setElementsPixelRatio(I){z._elementsPixelRatio=I},setSize(I,H,N){z.pages.forEach(G=>{G.setSize({width:I,height:H,useMagic:N,softChange:!0})}),z.width=I,z.height=H},setPageZIndex(I,H){const N=z.pages.find(G=>G.id===I);N&&((0,o.detach)(N),z.pages.remove(N),z.pages.splice(H,0,N))},deletePages(I){const H=z.pages.indexOf(z.activePage);I.forEach(D=>{const q=z.pages.find(V=>V.id===D);(0,o.destroy)(q)});const N=Math.min(z.pages.length-1,H),G=z.pages[N];G&&(z._activePageId=G.id),z.selectedElementsIds=(0,o.cast)(z.selectedElementsIds.filter(D=>z.getElementById(D)))},groupElements(I){const H=I.map(D=>z.getElementById(D));H.forEach(D=>{D&&(0,o.detach)(D)});const N=z.activePage,G=e.GroupElement.create({id:(0,s.nanoid)(10),children:(0,o.cast)(H)});return N.children.push(G),z.selectedElementsIds=(0,o.cast)([G.id]),G},ungroupElements(I){const H=I.map(G=>z.getElementById(G)),N=[];H.forEach(G=>{if(G&&G.type==="group"){const D=G.page,q=D.children.indexOf(G);G.children.forEach(V=>{N.push(V.id)}),G.children.forEach(V=>{(0,o.detach)(V),D.children.push(V)}),D.children.splice(q,1)}}),z.selectedElementsIds=(0,o.cast)(N)},deleteElements(I){I.forEach(H=>{z.pages.forEach(N=>{const G=N.children.find(D=>D.id===H);G&&(0,o.destroy)(G)})}),z.selectedElementsIds=(0,o.cast)(z.selectedElementsIds.filter(H=>z.getElementById(H)))},on(I,H){if(I==="change"){let N=z.toJSON();return(0,o.onSnapshot)(z,G=>{const D=z.toJSON();!(0,_.deepEqual)(N,D)&&(N=D,H(D))})}},async _toCanvas({pixelRatio:I,ignoreBackground:H,pageId:N,mimeType:G,includeBleed:D}={}){var q;const V=I||1;N=N||((q=z.pages[0])===null||q===void 0?void 0:q.id);const R=z.pages.find(le=>le.id===N);if(!R)throw new Error(`No page for export with id ${N}`);R==null||R.set({_exporting:!0});const P=await(0,y.waitTillAvailable)(()=>c.default.stages.find(le=>le.getAttr("pageId")===N));if(!P)throw new Error(`Export is failed. Can not find stage for page ${N}. Looks like <Workspace /> component is not mounted, but it is required in order to process the export.`);const F=!!P.findOne(".page-container");await z.waitLoading();const B=P.findOne(".page-container");if(!B)throw new Error(`Export is failed. Can't find page container. ${F}`);P.find("Transformer").forEach(le=>le.visible(!1)),B.find(".page-background").forEach(le=>le.shadowEnabled(!1)),B.find(".page-background").forEach(le=>le.strokeEnabled(!1)),B.find(".highlighter").forEach(le=>le.visible(!1));const Y=B.findOne(".page-background-group"),J=Y.clip();Y.clip({x:null,y:null,width:null,height:null});const Z=B.findOne(".elements-container"),K=Z.clip();Z.clip({x:null,y:null,width:null,height:null});const U=B.find(le=>le.getAttr("hideInExport"));U.forEach(le=>{le.setAttr("oldVisible",le.visible()),le.hide()});const W=B.find(le=>!le.visible()&&le.getAttr("editModeEnabled"));W.forEach(le=>{le.setAttr("oldVisible",le.visible()),le.show()}),H&&B.find(".page-background").forEach(le=>le.hide());const X=D?R.bleed:0;let ee=X;z.bleedVisible&&D?ee=0:z.bleedVisible&&!D&&(ee=-R.bleed);const te=document.createElement("canvas");te.width=(R.computedWidth+2*X)*V,te.height=(R.computedHeight+2*X)*V;const ne=te.getContext("2d");G==="image/jpeg"&&(ne.fillStyle="white",ne.fillRect(0,0,te.width,te.height));const ce=B.toCanvas({x:B.x()-ee*B.scaleX(),y:B.y()-ee*B.scaleY(),width:(R.computedWidth+2*X)*B.scaleX(),height:(R.computedHeight+2*X)*B.scaleY(),pixelRatio:1/B.scaleX()*V});return ne.drawImage(ce,0,0),c.default.Util.releaseCanvas(ce),H&&B.find(".page-background").forEach(le=>le.show()),U.forEach(le=>{le.visible(le.getAttr("oldVisible"))}),W.forEach(le=>{le.visible(le.getAttr("oldVisible"))}),B.find(".page-background").forEach(le=>le.shadowEnabled(!0)),B.find(".page-background").forEach(le=>le.strokeEnabled(!0)),P.find("Transformer").forEach(le=>le.visible(!0)),B.find(".highlighter").forEach(le=>le.visible(!0)),Y.clip(J),Z.clip(K),R==null||R.set({_exporting:!1}),te},async toDataURL({pixelRatio:I,ignoreBackground:H,pageId:N,mimeType:G,includeBleed:D,quality:q}={}){const V=await z._toCanvas({pixelRatio:I,ignoreBackground:H,pageId:N,mimeType:G,includeBleed:D}),R=V.toDataURL(G,q);return c.default.Util.releaseCanvas(V),R},async toBlob({pixelRatio:I,ignoreBackground:H,pageId:N,mimeType:G,includeBleed:D,quality:q}={}){const V=await z._toCanvas({pixelRatio:I,ignoreBackground:H,pageId:N,mimeType:G,includeBleed:D}),R=new Promise(P=>{V.toBlob(P,G,q)});return c.default.Util.releaseCanvas(V),R},async saveAsImage(I={}){var{fileName:H}=I,N=a(I,["fileName"]);const G=N.mimeType||"image/png",D=G.split("/")[1];(0,u.downloadFile)(await z.toDataURL(N),H||"polotno."+D,G)},async _toPDF(I){const H=I.dpi||z.dpi,N=I.parallel||1,G=I.unit||(z.unit==="px"?"mm":z.unit),D=I.pixelRatio||1,q=I.pageIds||z.pages.map(W=>W.id),V=z.pages.filter(W=>q.includes(W.id)),R=await(0,p.getJsPDF)(),P=W=>(0,S.pxToUnit)({px:W,unit:G,dpi:H}),F=V[0]||{},B=I.includeBleed?F.bleed:0,Y=P(F.computedWidth+2*B),J=P(F.computedHeight+2*B);var Z=new R({unit:G,orientation:Y>J?"landscape":"portrait",format:[Y,J],compress:!0,putOnlyUsedFonts:!0});Z.deletePage(1);const K=z._elementsPixelRatio;z.setElementsPixelRatio(D),await new Promise(W=>setTimeout(W));const U=((W,X)=>{for(var ee=[],te=0;te<W.length;te+=X)ee.push(W.slice(te,te+X));return ee})(V,N);for(const W of U){const X=W.map(async ee=>{const te=I.includeBleed?ee.bleed:0,ne=P(ee.computedWidth+2*te),ce=P(ee.computedHeight+2*te);let le=0,Te=D;for(;le<10;){le+=1,le===2&&console.error("Polotno can not export PDF with current settings. Quality is automatically reduced.");const Ce=await z.toDataURL(Object.assign(Object.assign({},I),{pageId:ee.id,pixelRatio:Te}));if(Ce.length>20)return{url:Ce,width:ne,height:ce};Te*=.8}});(await Promise.all(X)).forEach(({url:ee,width:te,height:ne})=>{Z.addPage([te,ne],te>ne?"landscape":"portrait"),Z.addImage(ee,0,0,te,ne,void 0,"FAST")})}return z.setElementsPixelRatio(K),Z},toPDFDataURL:async I=>(await z._toPDF(Object.assign({mimeType:"image/jpeg"},I))).output("datauristring"),async toGIFDataURL(I={}){const H=I.pixelRatio||1,N=await(0,h.createGIF)({width:z.width*H,height:z.height*H}),G=1e3/(I.fps||10),D=z.duration/G;for(let q=0;q<D-1;q++){const V=q*G||1;z.setCurrentTime(V);let R=0,P="";for(const B of z.pages)if(R+=B.duration,B.set({_rendering:R>V}),R>V){P=B.id;break}const F=await z._toCanvas({pixelRatio:H,pageId:P});N.addFrame(F.getContext("2d"),{delay:G,copy:!0})}for(const q of z.pages)q.set({_rendering:!1});return z.stop(),N.render(),new Promise(q=>{N.on("finished",function(V){(function(R,P){var F=new FileReader;F.onload=function(B){P(B.target.result)},F.readAsDataURL(R)})(V,q)})})},async saveAsGIF(I={}){var{fileName:H}=I,N=a(I,["fileName"]);const G=await z.toGIFDataURL(N);(0,u.downloadFile)(G,H||"polotno.gif")},async toHTML(){const I=z.toJSON();return(0,v.jsonToHTML)({json:I})},async saveAsHTML({fileName:I}={}){const H=await z.toHTML(),N="data:text/html;base64,"+window.btoa(unescape(encodeURIComponent(H)));(0,u.downloadFile)(N,I||"polotno.html")},async saveAsPDF(I={}){var{fileName:H}=I,N=a(I,["fileName"]);(await z._toPDF(Object.assign({mimeType:"image/jpeg"},N))).save(H||"polotno.pdf")},async waitLoading(){await new Promise(I=>setTimeout(I,50)),await(0,w.whenLoaded)()},toJSON:()=>({width:z.width,height:z.height,fonts:(0,o.getSnapshot)(z.fonts),pages:(0,o.getSnapshot)(z.pages),unit:z.unit,dpi:z.dpi}),loadJSON(I,H=!1){var N;const G=Object.assign({},I),D=z.pages.indexOf(z.activePage);let q=(N=G.pages[D]||G.pages[0])===null||N===void 0?void 0:N.id;G._activePageId=q;const V=Object.assign({},(0,o.getSnapshot)(z));Object.assign(V,G),V.history=H?z.history.toJSON():{history:[],undoIdx:-1},(0,o.applySnapshot)(z,V)},clear({keepHistory:I=!1}={}){const H=z.pages.map(N=>N.id);z.deletePages(H),I||z.history.clear()},addFont(I){z.removeFont(I.fontFamily),z.fonts.push(I),z.loadFont(I.fontFamily)},removeFont(I){z.fonts.filter(H=>H.fontFamily===I).forEach(H=>(0,o.destroy)(H))},async loadFont(I){const H=z.fonts.find(N=>N.fontFamily===I)||E.globalFonts.find(N=>N.fontFamily===I);H?E.injectCustomFont(H):E.injectGoogleFont(I),await E.loadFont(I)}})),e.createStore=A,e.default=A})(Rb);var kl={},SV={},CV={};(function(e){async function t(n){return new Promise((r,a)=>{const i=new FileReader;i.readAsDataURL(n),i.onload=()=>r(i.result),i.onerror=o=>a(o)})}Object.defineProperty(e,"__esModule",{value:!0}),e.localFileToURL=void 0,e.localFileToURL=t})(CV);var OV={};(function(e){var t=ue&&ue.__importDefault||function(_){return _&&_.__esModule?_:{default:_}};Object.defineProperty(e,"__esModule",{value:!0}),e.ImagesGrid=void 0;const n=t(j),r=t($i),a=Ut,i=_n,o=X5,l=ma,s=(0,r.default)("div",n.default.forwardRef)`
248
248
  height: 100%;
249
249
  overflow: auto;
250
250
  `,c=(0,r.default)("div")`
package/dist/index.html CHANGED
@@ -8,7 +8,7 @@
8
8
  }
9
9
  </style>
10
10
  <meta name="viewport" content="width=device-width, initial-scale=1" />
11
- <script type="module" crossorigin src="./assets/index-054ff984.js"></script>
11
+ <script type="module" crossorigin src="./assets/index-b6906396.js"></script>
12
12
  </head>
13
13
  <body class="bp3-dark">
14
14
  <div id="root"></div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polotno-node",
3
- "version": "2.4.1",
3
+ "version": "2.5.0",
4
4
  "description": "Polotno workflow from NodeJS",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -23,7 +23,7 @@
23
23
  "gifencoder": "^2.0.1",
24
24
  "pixelmatch": "^5.3.0",
25
25
  "pngjs": "^7.0.0",
26
- "polotno": "^1.12.5",
26
+ "polotno": "^1.12.6",
27
27
  "react": "^18.2.0",
28
28
  "react-dom": "^18.2.0",
29
29
  "vite": "^4.4.8"