polotno 2.23.6 → 2.23.7
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/canvas/html-element.js +1 -1
- package/model/store.js +1 -1
- package/package.json +1 -1
- package/polotno.bundle.js +2 -2
- package/utils/validate-key.js +1 -1
package/canvas/html-element.js
CHANGED
|
@@ -12,4 +12,4 @@ var e,t=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&
|
|
|
12
12
|
.ql-direction-rtl {
|
|
13
13
|
direction: rtl;
|
|
14
14
|
}
|
|
15
|
-
`;let z=["bold","color","font","italic","size","strike","underline","indent","list","direction"];exports.setQuillFormats=e=>{z=e},exports.createQuill=e=>new s.default(e,{toolbar:!1,keyboard:!1,clipboard:{matchVisual:!1},formats:z}),exports.setQuillContent=(e,t)=>{var r=e.clipboard.convert("<div class='ql-editor' style='outline: none;'>"+t+"<p><br></p></div>");e.setContents(r),e.history.clear()};const O=({html:e,onBlur:t,onChange:r,element:n})=>{const i=o.default.useRef(null);o.default.useEffect((()=>{if(!i.current){return}const e=(0,exports.createQuill)(i.current);return u.runInAction((()=>{exports.quillRef.editor.instance=e})),window.__polotnoQuill=e,e.on("text-change",(()=>{e.getSelection()&&u.runInAction((()=>{exports.quillRef.currentFormat=e.getFormat()})),setTimeout((()=>{var e;const t=null===(e=i.current)||void 0===e?void 0:e.childNodes[0];r(t.innerHTML)}),10)})),e.setSelection(0,0,"api"),e.on("selection-change",((t,r,n)=>{t&&u.runInAction((()=>{exports.quillRef.currentFormat=e.getFormat()}))})),i.current.childNodes[0].addEventListener("blur",(e=>{var r;if(null===(r=e.relatedTarget)||void 0===r?void 0:r.classList.contains("ql-clipboard")){return}const n=function(e){return!!e&&!!e.closest(".sketch-picker")}(e.relatedTarget);n||t()})),()=>{u.runInAction((()=>{exports.quillRef.editor.instance=null,exports.quillRef.currentFormat={}})),delete window.__polotnoQuill}}),[]),o.default.useEffect((()=>(0,E.reaction)((()=>n.text),(()=>{var t;const r=exports.quillRef.editor.instance;if(!r){return}const o=r.getSelection();(null===(t=i.current)||void 0===t?void 0:t.childNodes[0].innerHTML)===n.text||((0,exports.setQuillContent)(r,e),o&&(r.setSelection(o.index,o.length),u.runInAction((()=>{exports.quillRef.currentFormat=r.getFormat()}))))}),{fireImmediately:!0})),[]);const a={color:n.fill};return n.fill.indexOf("gradient")>=0&&(a.backgroundColor=n.fill,a.backgroundImage=n.fill,a.backgroundSize="100% 100%",a.backgroundRepeat="repeat",a.webkitBackgroundClip="text",a.MozBackgroundClip="text",a.WebkitTextFillColor="transparent",a.MozTextFillColor="transparent"),o.default.createElement(k,{ref:i,style:Object.assign(Object.assign({},a),{fontSize:n.fontSize,fontWeight:n.fontWeight,width:n.a.width,fontFamily:'"'+n.fontFamily+'"',lineHeight:n.lineHeight,letterSpacing:n.letterSpacing*n.fontSize+"px",textAlign:n.align,opacity:Math.max(n.a.opacity,.2)}),dir:(0,f.getDir)((0,y.removeTags)(n.text))})},q=(e,t=100,r=!1,n="")=>{const[i,a]=o.default.useState(e),l=o.default.useRef(null);return o.default.useEffect((()=>e===r?(l.current&&(clearTimeout(l.current),l.current=null),void a(r)):(l.current&&clearTimeout(l.current),l.current=setTimeout((()=>{a(e),l.current=null}),t),()=>{l.current&&clearTimeout(l.current)})),[e,t]),[i,a]};function F(e,{fontFamily:t="",color:r="black"}={}){let n=`color: ${r||e.fill}`;return e.fill.indexOf("gradient")>=0&&(n=`\n background-color: ${r};\n background-image: ${e.fill};\n background-size: 100% 100%;\n background-repeat: repeat;\n -webkit-background-clip: text;\n -moz-background-clip: text;\n -webkit-text-fill-color: transparent;\n -moz-text-fill-color: transparent;\n `),`<div style="${["white-space: pre-wrap",`width: ${Math.round(e.width||100)}px`,n,`font-size: ${e.fontSize}px`,`font-family: '${t}'`,`text-align: ${e.align}`,e.textDecoration?`text-decoration: ${e.textDecoration}; text-decoration-color: ${r||e.fill}; text-decoration-layer: over`:"",e.lineHeight?`line-height: ${e.lineHeight}`:"",e.letterSpacing?`letter-spacing: ${e.letterSpacing*e.fontSize}px`:"",e.fontStyle?`font-style: ${e.fontStyle}`:"",e.fontWeight?`font-weight: ${e.fontWeight}`:"",e.strokeWidth?`-webkit-text-stroke: ${e.strokeWidth}px ${e.stroke}`:"",e.strokeWidth?"paint-order: stroke fill":""].filter(Boolean).join("; ")}" contentEditable dir="${(0,f.getDir)((0,y.removeTags)(e.text))}">${(0,y.sanitizeHtml)(e.text).replace(/\n/g,"</br>")}</div>`}const R=/^((?!chrome|android).)*safari/i.test(navigator.userAgent);exports.HTMLElement=(0,a.observer)((({element:e,store:t})=>{const r=o.default.useRef(null),[n,i]=o.default.useState(),[a,s]=o.default.useState(!1),[x,E]=o.default.useState(!0),z=o.default.useRef(e.height),T=t.selectedShapes.indexOf(e)>=0&&e.selectable,_=e.fontSize/3,{textVerticalResizeEnabled:C}=c.flags,M=(0,f.usePrevious)(e.fontFamily),[$]=(0,f.useFontLoader)(t,e.fontFamily),I=e._editModeEnabled;(0,m.useFadeIn)(r);const A=$?e.fontFamily:M!==e.fontFamily?M:"Arial",H=(0,g.useColor)(e).fill,j=F(e,{fontFamily:A,color:H}),{width:P,height:D}=function(e,t,r){return o.default.useMemo((()=>(0,h.detectSize)(e)),[e,t.width,r])}(j,e,$);o.default.useEffect((()=>{if(!$){return}if(!e.height){return void e.set({height:D})}const{textOverflow:r}=c.flags;if("change-font-size"!==r||a){"resize"===r&&(C&&e.height<D&&t.history.ignore((()=>{e.set({height:D})})),C||e.height===D||t.history.ignore((()=>{e.set({height:D})})))}else{const r=(e=>{let t=e.fontSize;for(let r=1;r<50;r++){const r=F(Object.assign(Object.assign({},e.toJSON()),{fontSize:t}),{fontFamily:e.fontFamily}),{height:n}=(0,h.detectSize)(r),i=e.height&&n>e.height,o=(0,h.isContentWrapping)({html:r});if(!i&&!o){break}t-=.5}return t})(e);r!==e.fontSize?t.history.ignore((()=>{e.set({fontSize:r})})):e.height!==D&&(C&&e.height<D?t.history.ignore((()=>{e.set({height:D})})):C||t.history.ignore((()=>{e.set({height:D})})))}}));const L=o.default.useRef(0),X=o.default.useMemo((()=>{const e={lastArgs:null,lastResult:null};return async function(t){return e.lastArgs&&e.lastResult&&(r=e.lastArgs,n=t,JSON.stringify(r)===JSON.stringify(n))||(e.lastResult=await(0,h.htmlToCanvas)(t),e.lastArgs=Object.assign({},t)),e.lastResult;var r,n}}),[]),Y=o.default.useRef(null);o.default.useEffect((()=>{a||I||(async()=>{L.current++;const r=L.current,n=(0,b.incrementLoader)(`text ${e.id}`);Y.current=n,E(!0);let o=null;const a=R?5:1;for(let i=0;i<a;i++){const a=i>0?X:h.htmlToCanvas;try{if(o=await a({skipCache:i>0,html:j,width:e.width||1,height:e.height||D||1,fontFamily:A,padding:_,pixelRatio:t._elementsPixelRatio,font:t.fonts.find((e=>e.fontFamily===A))||w.globalFonts.find((e=>e.fontFamily===A))}),r!==L.current){return void n()}if(!function(e){const t=e.getContext("2d").getImageData(0,0,e.width,e.height).data;for(let r=0;r<t.length;r+=4){if(0!==t[r+3]){return!0}}return!1}(o)&&R){await new Promise((e=>setTimeout(e,50*(i+1))));continue}}catch(l){(0,b.triggerLoadError)(`Error rendering rich text with id ${e.id}`);break}}if(!o){return Y.current=null,void n()}i(o),E(!1)})()}),[j,a,D,I,A,e.height,t._elementsPixelRatio,$]);const[W,B]=q(x),[Q]=q(a,100,!0),N=Q||W;o.default.useEffect((()=>{if(!N){return u.autorun((()=>{const t=r.current;(0,d.applyFilter)(t,e)}))}}),[n,N,e.shadowColor,e.shadowOffsetX,e.shadowOffsetY,e.shadowOpacity]),o.default.useEffect((()=>{n&&!x&&Y.current&&(Y.current(),Y.current=null)}),[n,x]);let J=0;"middle"===e.verticalAlign&&(J=(e.height-D)/2),"bottom"===e.verticalAlign&&(J=e.height-D);const V=(0,f.getLineHeight)({fontLoaded:$,fontFamily:e.fontFamily,fontSize:e.fontSize,lineHeight:e.lineHeight}),G=(0,v.isTouchDevice)();return o.default.createElement(o.default.Fragment,null,o.default.createElement(l.Rect,{x:e.a.x,y:e.a.y,offsetX:e.backgroundPadding*(e.fontSize*V*.5),offsetY:e.backgroundPadding*(e.fontSize*V*.5),rotation:e.a.rotation,hideInExport:!e.showInExport,listening:!1,visible:e.backgroundEnabled,opacity:e.backgroundOpacity*e.a.opacity,fill:e.backgroundColor,width:e.a.width+e.backgroundPadding*(e.fontSize*V),height:e.a.height+e.backgroundPadding*(e.fontSize*V),cornerRadius:e.backgroundCornerRadius*(e.fontSize*V*.5)}),o.default.createElement(l.Rect,{ref:r,name:"element",x:e.a.x,y:e.a.y,listening:e.selectable,rotation:e.a.rotation,width:e.a.width,height:e.a.height,visible:!N,draggable:G?e.draggable&&T:e.draggable,preventDefault:!G||T,opacity:I?0:e.a.opacity,hideInExport:!e.showInExport,onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},id:e.id,onDblClick:()=>{e.contentEditable&&e.toggleEditMode(!0)},onDblTap:()=>{e.contentEditable&&e.toggleEditMode(!0)},onTransformStart:t=>{s(!0),z.current=e.height},onTransform:t=>{var r;const n=t.target,i=(null===(r=n.getStage())||void 0===r?void 0:r.findOne("Transformer")).getActiveAnchor(),o="middle-left"===i||"middle-right"===i,a="top-center"===i||"bottom-center"===i,l=n.scaleX();if(o){const t=n.scaleX(),r=Math.max(n.width()*t,e.fontSize);if(n.width(r),n.scaleX(1),c.flags.textVerticalResizeEnabled){const t=Math.max(D,z.current);e.set({height:t})}e.set({width:r,x:n.x(),y:n.y()})}else if(a){let r="resize"===c.flags.textOverflow?D:e.lineHeight*e.fontSize;const i=Math.max(r,t.target.height()*t.target.scaleY());n.scaleY(1),e.set({x:n.x(),y:n.y(),height:i,rotation:n.rotation()})}else{n.scaleX(1),n.scaleY(1),e.set({fontSize:e.fontSize*l,letterSpacing:e.letterSpacing,width:n.width()*l,x:n.x(),y:n.y(),rotation:n.rotation(),height:n.height()*l})}},onTransformEnd:t=>{s(!1),E(!0);const r=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),e.set({fontSize:e.fontSize*r,width:t.target.width()*r,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),shadowBlur:e.shadowBlur*r,shadowOffsetX:e.shadowOffsetX*r,shadowOffsetY:e.shadowOffsetY*r,strokeWidth:e.strokeWidth*r})}}),o.default.createElement(l.Image,{ref:r,image:n,x:e.a.x,y:e.a.y,offsetX:_,offsetY:_-J,listening:!1,rotation:e.a.rotation,width:e.a.width+2*_,height:e.a.height+2*_,visible:!N,opacity:I?0:e.a.opacity,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,hideInExport:!e.showInExport}),N&&o.default.createElement(l.Group,{x:e.a.x,y:e.a.y,rotation:e.a.rotation,offsetY:-J},o.default.createElement(p.Html,{divProps:{style:{pointerEvents:"none"}}},o.default.createElement(k,{dangerouslySetInnerHTML:{__html:j},style:{pointerEvents:"none",opacity:e.a.opacity}}))),I&&o.default.createElement(l.Group,{x:e.a.x,y:e.a.y,rotation:e.a.rotation,offsetY:-J},o.default.createElement(p.Html,null,o.default.createElement(O,{html:j,element:e,onChange:t=>{const r=(0,S.getLimitedFontSize)({oldText:(0,y.removeTags)(e.text),newText:(0,y.removeTags)(t),element:e});e.set({text:t,fontSize:r})},onBlur:r=>{e.toggleEditMode(!1),B(!0),""===(0,y.removeTags)(e.text)&&e.removable&&!e.placeholder&&t.deleteElements([e.id])}}))))}));
|
|
15
|
+
`;let z=["bold","color","font","italic","size","strike","underline","indent","list","direction"];exports.setQuillFormats=e=>{z=e},exports.createQuill=e=>new s.default(e,{toolbar:!1,keyboard:!1,clipboard:{matchVisual:!1},formats:z}),exports.setQuillContent=(e,t)=>{var r=e.clipboard.convert("<div class='ql-editor' style='outline: none;'>"+t+"<p><br></p></div>");e.setContents(r),e.history.clear()};const O=({html:e,onBlur:t,onChange:r,element:n})=>{const i=o.default.useRef(null);o.default.useEffect((()=>{if(!i.current){return}const e=(0,exports.createQuill)(i.current);return u.runInAction((()=>{exports.quillRef.editor.instance=e})),window.__polotnoQuill=e,e.on("text-change",(()=>{e.getSelection()&&u.runInAction((()=>{exports.quillRef.currentFormat=e.getFormat()})),setTimeout((()=>{var e;const t=null===(e=i.current)||void 0===e?void 0:e.childNodes[0];r(t.innerHTML)}),10)})),e.setSelection(0,0,"api"),e.on("selection-change",((t,r,n)=>{t&&u.runInAction((()=>{exports.quillRef.currentFormat=e.getFormat()}))})),i.current.childNodes[0].addEventListener("blur",(e=>{var r;if(null===(r=e.relatedTarget)||void 0===r?void 0:r.classList.contains("ql-clipboard")){return}const n=function(e){return!!e&&!!e.closest(".sketch-picker")}(e.relatedTarget);n||t()})),()=>{u.runInAction((()=>{exports.quillRef.editor.instance=null,exports.quillRef.currentFormat={}})),delete window.__polotnoQuill}}),[]),o.default.useEffect((()=>(0,E.reaction)((()=>n.text),(()=>{var t;const r=exports.quillRef.editor.instance;if(!r){return}const o=r.getSelection();(null===(t=i.current)||void 0===t?void 0:t.childNodes[0].innerHTML)===n.text||((0,exports.setQuillContent)(r,e),o&&(r.setSelection(o.index,o.length),u.runInAction((()=>{exports.quillRef.currentFormat=r.getFormat()}))))}),{fireImmediately:!0})),[]);const a={color:n.fill};return n.fill.indexOf("gradient")>=0&&(a.backgroundColor=n.fill,a.backgroundImage=n.fill,a.backgroundSize="100% 100%",a.backgroundRepeat="repeat",a.webkitBackgroundClip="text",a.MozBackgroundClip="text",a.WebkitTextFillColor="transparent",a.MozTextFillColor="transparent"),o.default.createElement(k,{ref:i,style:Object.assign(Object.assign({},a),{fontSize:n.fontSize,fontWeight:n.fontWeight,width:n.a.width,fontFamily:'"'+n.fontFamily+'"',lineHeight:n.lineHeight,letterSpacing:n.letterSpacing*n.fontSize+"px",textAlign:n.align,opacity:Math.max(n.a.opacity,.2)}),dir:(0,f.getDir)((0,y.removeTags)(n.text))})},q=(e,t=100,r=!1,n="")=>{const[i,a]=o.default.useState(e),l=o.default.useRef(null);return o.default.useEffect((()=>e===r?(l.current&&(clearTimeout(l.current),l.current=null),void a(r)):(l.current&&clearTimeout(l.current),l.current=setTimeout((()=>{a(e),l.current=null}),t),()=>{l.current&&clearTimeout(l.current)})),[e,t]),[i,a]};function F(e,{fontFamily:t="",color:r="black"}={}){let n=`color: ${r||e.fill}`;return e.fill.indexOf("gradient")>=0&&(n=`\n background-color: ${r};\n background-image: ${e.fill};\n background-size: 100% 100%;\n background-repeat: repeat;\n -webkit-background-clip: text;\n -moz-background-clip: text;\n -webkit-text-fill-color: transparent;\n -moz-text-fill-color: transparent;\n `),`<div style="${["white-space: pre-wrap",`width: ${Math.round(e.width||100)}px`,n,`font-size: ${e.fontSize}px`,`font-family: '${t}'`,`text-align: ${e.align}`,e.textDecoration?`text-decoration: ${e.textDecoration}; text-decoration-color: ${r||e.fill}; text-decoration-layer: over`:"",e.lineHeight?`line-height: ${e.lineHeight}`:"",e.letterSpacing?`letter-spacing: ${e.letterSpacing*e.fontSize}px`:"",e.fontStyle?`font-style: ${e.fontStyle}`:"",e.fontWeight?`font-weight: ${e.fontWeight}`:"",e.strokeWidth?`-webkit-text-stroke: ${e.strokeWidth}px ${e.stroke}`:"",e.strokeWidth?"paint-order: stroke fill":""].filter(Boolean).join("; ")}" contentEditable dir="${(0,f.getDir)((0,y.removeTags)(e.text))}">${(0,y.sanitizeHtml)(e.text).replace(/\n/g,"</br>")}</div>`}const R=/^((?!chrome|android).)*safari/i.test(navigator.userAgent);exports.HTMLElement=(0,a.observer)((({element:e,store:t})=>{const r=o.default.useRef(null),[n,i]=o.default.useState(),[a,s]=o.default.useState(!1),[x,E]=o.default.useState(!0),z=o.default.useRef(e.height),T=t.selectedShapes.indexOf(e)>=0&&e.selectable,_=e.fontSize/3,{textVerticalResizeEnabled:C}=c.flags,M=(0,f.usePrevious)(e.fontFamily),[$]=(0,f.useFontLoader)(t,e.fontFamily),I=e._editModeEnabled;(0,m.useFadeIn)(r);const A=$?e.fontFamily:M!==e.fontFamily?M:"Arial",H=(0,g.useColor)(e).fill,j=F(e,{fontFamily:A,color:H}),{width:P,height:D}=function(e,t,r){return o.default.useMemo((()=>(0,h.detectSize)(e)),[e,t.width,r])}(j,e,$);o.default.useEffect((()=>{if(!$){return}if(!e.height){return void e.set({height:D})}const{textOverflow:r}=c.flags;if("change-font-size"!==r||a){"resize"===r&&(C&&e.height<D&&t.history.ignore((()=>{e.set({height:D})})),C||e.height===D||t.history.ignore((()=>{e.set({height:D})})))}else{const r=(e=>{let t=e.fontSize;for(let r=1;r<50;r++){const r=F(Object.assign(Object.assign({},e.toJSON()),{fontSize:t}),{fontFamily:e.fontFamily}),{height:n}=(0,h.detectSize)(r),i=e.height&&n>e.height,o=(0,h.isContentWrapping)({html:r});if(!i&&!o){break}t-=.5}return t})(e);r!==e.fontSize?t.history.ignore((()=>{e.set({fontSize:r})})):e.height!==D&&(C&&e.height<D?t.history.ignore((()=>{e.set({height:D})})):C||t.history.ignore((()=>{e.set({height:D})})))}}));const L=o.default.useRef(0),X=o.default.useMemo((()=>{const e={lastArgs:null,lastResult:null};return async function(t){return e.lastArgs&&e.lastResult&&(r=e.lastArgs,n=t,JSON.stringify(r)===JSON.stringify(n))||(e.lastResult=await(0,h.htmlToCanvas)(t),e.lastArgs=Object.assign({},t)),e.lastResult;var r,n}}),[]),Y=o.default.useRef(null);o.default.useEffect((()=>{a||I||(async()=>{L.current++;const r=L.current,n=(0,b.incrementLoader)(`text ${e.id}`);Y.current=n,E(!0);let o=null;const a=R?5:1;for(let i=0;i<a;i++){const a=i>0?X:h.htmlToCanvas;try{if(o=await a({skipCache:i>0,html:j,width:e.width||1,height:e.height||D||1,fontFamily:A,padding:_,pixelRatio:t._elementsPixelRatio,font:t.fonts.find((e=>e.fontFamily===A))||w.globalFonts.find((e=>e.fontFamily===A))}),r!==L.current){return void n()}if(!function(e){const t=e.getContext("2d").getImageData(0,0,e.width,e.height).data;for(let r=0;r<t.length;r+=4){if(0!==t[r+3]){return!0}}return!1}(o)&&R){await new Promise((e=>setTimeout(e,50*(i+1))));continue}}catch(l){(0,b.triggerLoadError)(`Error rendering rich text with id ${e.id}`);break}}if(!o){return Y.current=null,void n()}i(o),E(!1)})()}),[j,a,D,I,A,e.height,t._elementsPixelRatio,$]);const[W,B]=q(x),[Q]=q(a,100,!0),N=Q||W;o.default.useEffect((()=>{if(!N){return u.autorun((()=>{const t=r.current;(0,d.applyFilter)(t,e)}))}}),[n,N,e.shadowColor,e.shadowOffsetX,e.shadowOffsetY,e.shadowOpacity]),o.default.useEffect((()=>{n&&!x&&Y.current&&(Y.current(),Y.current=null)}),[n,x]),o.default.useEffect((()=>()=>{Y.current&&Y.current()}),[]);let J=0;"middle"===e.verticalAlign&&(J=(e.height-D)/2),"bottom"===e.verticalAlign&&(J=e.height-D);const V=(0,f.getLineHeight)({fontLoaded:$,fontFamily:e.fontFamily,fontSize:e.fontSize,lineHeight:e.lineHeight}),G=(0,v.isTouchDevice)();return o.default.createElement(o.default.Fragment,null,o.default.createElement(l.Rect,{x:e.a.x,y:e.a.y,offsetX:e.backgroundPadding*(e.fontSize*V*.5),offsetY:e.backgroundPadding*(e.fontSize*V*.5),rotation:e.a.rotation,hideInExport:!e.showInExport,listening:!1,visible:e.backgroundEnabled,opacity:e.backgroundOpacity*e.a.opacity,fill:e.backgroundColor,width:e.a.width+e.backgroundPadding*(e.fontSize*V),height:e.a.height+e.backgroundPadding*(e.fontSize*V),cornerRadius:e.backgroundCornerRadius*(e.fontSize*V*.5)}),o.default.createElement(l.Rect,{ref:r,name:"element",x:e.a.x,y:e.a.y,listening:e.selectable,rotation:e.a.rotation,width:e.a.width,height:e.a.height,visible:!N,draggable:G?e.draggable&&T:e.draggable,preventDefault:!G||T,opacity:I?0:e.a.opacity,hideInExport:!e.showInExport,onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},id:e.id,onDblClick:()=>{e.contentEditable&&e.toggleEditMode(!0)},onDblTap:()=>{e.contentEditable&&e.toggleEditMode(!0)},onTransformStart:t=>{s(!0),z.current=e.height},onTransform:t=>{var r;const n=t.target,i=(null===(r=n.getStage())||void 0===r?void 0:r.findOne("Transformer")).getActiveAnchor(),o="middle-left"===i||"middle-right"===i,a="top-center"===i||"bottom-center"===i,l=n.scaleX();if(o){const t=n.scaleX(),r=Math.max(n.width()*t,e.fontSize);if(n.width(r),n.scaleX(1),c.flags.textVerticalResizeEnabled){const t=Math.max(D,z.current);e.set({height:t})}e.set({width:r,x:n.x(),y:n.y()})}else if(a){let r="resize"===c.flags.textOverflow?D:e.lineHeight*e.fontSize;const i=Math.max(r,t.target.height()*t.target.scaleY());n.scaleY(1),e.set({x:n.x(),y:n.y(),height:i,rotation:n.rotation()})}else{n.scaleX(1),n.scaleY(1),e.set({fontSize:e.fontSize*l,letterSpacing:e.letterSpacing,width:n.width()*l,x:n.x(),y:n.y(),rotation:n.rotation(),height:n.height()*l})}},onTransformEnd:t=>{s(!1),E(!0);const r=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),e.set({fontSize:e.fontSize*r,width:t.target.width()*r,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),shadowBlur:e.shadowBlur*r,shadowOffsetX:e.shadowOffsetX*r,shadowOffsetY:e.shadowOffsetY*r,strokeWidth:e.strokeWidth*r})}}),o.default.createElement(l.Image,{ref:r,image:n,x:e.a.x,y:e.a.y,offsetX:_,offsetY:_-J,listening:!1,rotation:e.a.rotation,width:e.a.width+2*_,height:e.a.height+2*_,visible:!N,opacity:I?0:e.a.opacity,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,hideInExport:!e.showInExport}),N&&o.default.createElement(l.Group,{x:e.a.x,y:e.a.y,rotation:e.a.rotation,offsetY:-J},o.default.createElement(p.Html,{divProps:{style:{pointerEvents:"none"}}},o.default.createElement(k,{dangerouslySetInnerHTML:{__html:j},style:{pointerEvents:"none",opacity:e.a.opacity}}))),I&&o.default.createElement(l.Group,{x:e.a.x,y:e.a.y,rotation:e.a.rotation,offsetY:-J},o.default.createElement(p.Html,null,o.default.createElement(O,{html:j,element:e,onChange:t=>{const r=(0,S.getLimitedFontSize)({oldText:(0,y.removeTags)(e.text),newText:(0,y.removeTags)(t),element:e});e.set({text:t,fontSize:r})},onBlur:r=>{e.toggleEditMode(!1),B(!0),""===(0,y.removeTags)(e.text)&&e.removable&&!e.placeholder&&t.deleteElements([e.id])}}))))}));
|
package/model/store.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e,t=this&&this.__createBinding||(Object.create?function(e,t,i,o){void 0===o&&(o=i);var n=Object.getOwnPropertyDescriptor(t,i);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,o,n)}:function(e,t,i,o){void 0===o&&(o=i),e[o]=t[i]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||(e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var i in e){Object.prototype.hasOwnProperty.call(e,i)&&(t[t.length]=i)}return t},e(t)},function(o){if(o&&o.__esModule){return o}var n={};if(null!=o){for(var a=e(o),s=0;s<a.length;s++){"default"!==a[s]&&t(n,o,a[s])}}return i(n,o),n}),n=this&&this.__rest||function(e,t){var i={};for(var o in e){Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(i[o]=e[o])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(e);n<o.length;n++){t.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(e,o[n])&&(i[o[n]]=e[o[n]])}}return i},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Store=exports.Font=void 0,exports.createStore=O;const s=require("mobx-state-tree"),r=require("./history"),l=require("nanoid"),d=a(require("konva")),c=require("../utils/download"),p=require("../utils/pdf"),u=require("../utils/gif-lib"),g=require("../utils/validate-key"),h=o(require("../utils/fonts")),m=require("../utils/flags"),f=require("../utils/loader"),y=require("../utils/unit"),b=require("../utils/deep-equal"),v=require("../utils/wait"),w=require("../utils/to-html"),P=require("../utils/to-svg"),x=require("./page-model"),E=require("./group-model"),_=require("./audio-model");function O({key:e,showCredit:t}={key:"",showCredit:!1}){return exports.Store.create({_forceShowCredit:t,_key:e})}(0,s.setLivelinessChecking)("ignore"),exports.Font=s.types.model("Font",{fontFamily:s.types.string,url:s.types.optional(s.types.string,""),styles:s.types.frozen()}).preProcessSnapshot((e=>Object.assign(Object.assign({},e),{fontFamily:e.fontFamily||e.name}))),exports.Store=s.types.model("Store",{role:"",pages:s.types.array(x.Page),fonts:s.types.array(exports.Font),audios:s.types.array(_.Audio),width:1080,height:1080,currentTime:0,isPlaying:!1,scale:1,scaleToFit:1,unit:"px",dpi:72,schemaVersion:1,bleedVisible:!1,rulesVisible:!1,openedSidePanel:"",previousOpenedSidePanel:"",custom:s.types.frozen(),selectedElementsIds:s.types.array(s.types.string),animatedElementsIds:s.types.array(s.types.string),history:s.types.optional(r.UndoManager,{targetPath:"../pages"}),_elementsPixelRatio:Math.min(2,window.devicePixelRatio||1),_activePageId:"",_forceShowCredit:!1,_key:"",_validated:!1}).views((e=>({get _bleedVisible(){return console.warn("store._bleedVisible is deprecated. Please use store.bleedVisible instead."),e.bleedVisible},get selectedElements(){return e.selectedElementsIds.map((t=>{for(const i of e.pages){for(const e of i.children){if(e.id===t){return e}}}})).filter((e=>!!e))},get children(){return e.pages},get selectedShapes(){const t=[];return(0,E.forEveryChild)({children:e.selectedElements},(e=>{"group"!==e.type&&t.push(e)})),t},get activePage(){return e.pages.slice().find((t=>t.id===e._activePageId))||(e.pages.length?e.pages[0]:null)},get duration(){let t=0;return e.pages.forEach((e=>{t+=e.duration})),t},get _hasCroppedImages(){return e.find((e=>"image"===e.type&&e._cropModeEnabled))},find(t){let i;return(0,E.forEveryChild)({children:e.pages},(e=>{if(!i&&t(e)){return i=e,!0}})),i},getElementById:t=>e.find((e=>e.id===t))}))).actions((e=>{let t=0,i=null,o=!1;return{afterCreate(){e.history.canUndo},setCurrentTime(t){e.currentTime=t},_togglePlaying(t=!e.isPlaying){e.isPlaying=t},play({animatedElementsIds:n=[],startTime:a=0,currentTime:r=0,endTime:l=e.duration,repeat:d=!1}={}){r&&(console.warn("currentTime property of store.play() is deprecated. Please use startTime instead."),a=r),e.animatedElementsIds=(0,s.cast)(n),e.currentTime=a,e.isPlaying=!0,t=Date.now(),i=l,o=d,requestAnimationFrame(e.seek)},checkActivePage(){let t=0;for(const i of e.pages){if(e.currentTime>=i.startTime&&e.currentTime<i.startTime+i.duration){e.selectPage(i.id);break}t+=i.duration}},seek(){if(!e.isPlaying){return}const n=Date.now(),a=n-t;t=n,e.currentTime+=a,e.checkActivePage();const s=i||e.duration;e.isPlaying&&e.currentTime<s?requestAnimationFrame(e.seek):e.isPlaying&&o?(e.currentTime=0,requestAnimationFrame(e.seek)):e.stop()},stop(){e.isPlaying=!1,e.currentTime=0,e.animatedElementsIds=(0,s.cast)([]),e.checkActivePage()}}})).actions((e=>({__(){e._validated||((0,g.validateKey)(e._key,e._forceShowCredit),e._validated=!0)},set(t){Object.assign(e,t)},setUnit({unit:t,dpi:i}){e.unit=t||e.unit,e.dpi=i||e.dpi},setRole(t){e.role=t},addPage(t){const i=x.Page.create(Object.assign({id:(0,l.nanoid)(10)},t));return e.pages.push(i),e._activePageId=i.id,i},selectPage(t){e._activePageId=t},selectElements(t){const i=t.map((t=>e.getElementById(t))).sort(((e,t)=>e.page.children.indexOf(e)-e.page.children.indexOf(t))).filter((e=>!!e)).map((e=>e.id));e.selectedElementsIds=(0,s.cast)(i)},toggleBleed(t){e.bleedVisible=null!=t?t:!e.bleedVisible},toggleRulers(t){e.rulesVisible=null!=t?t:!e.rulesVisible},openSidePanel(t){e.openedSidePanel!==t&&(e.previousOpenedSidePanel=e.openedSidePanel,e.openedSidePanel=t)},setScale(t){e.scale=t},_setScaleToFit(t){e.scaleToFit=t},setElementsPixelRatio(t){e._elementsPixelRatio=t},setSize(t,i,o){e.pages.forEach((e=>{e.setSize({width:t,height:i,useMagic:o,softChange:!0})})),e.width=t,e.height=i},setPageZIndex(t,i){const o=e.pages.find((e=>e.id===t));o&&((0,s.detach)(o),e.pages.remove(o),e.pages.splice(i,0,o))},deletePages(t){const i=e.pages.indexOf(e.activePage);t.forEach((t=>{const i=e.pages.find((e=>e.id===t));(0,s.destroy)(i)}));const o=Math.min(e.pages.length-1,i),n=e.pages[o];n&&(e._activePageId=n.id),e.selectedElementsIds=(0,s.cast)(e.selectedElementsIds.filter((t=>e.getElementById(t))))},groupElements(t,i={}){const o=t.map((t=>e.getElementById(t))),n=o[0].page;if(o.forEach((e=>{e&&(0,s.detach)(e)})),!o.length){return}const a=Object.assign({id:(0,l.nanoid)(10),children:o,type:"group"},i);return n.children.push(a),e.selectedElementsIds=(0,s.cast)([a.id]),n.children.find((e=>e.id===a.id))},ungroupElements(t){const i=t.map((t=>e.getElementById(t))),o=[];i.forEach((e=>{if(e&&"group"===e.type){const t=e.page,i=t.children.indexOf(e);e.children.forEach((e=>{o.push(e.id)})),e.children.forEach((e=>{(0,s.detach)(e),t.children.push(e)})),t.children.splice(i,1)}})),e.selectedElementsIds=(0,s.cast)(o)},deleteElements(t){const i=[];e.find((e=>(t.includes(e.id)&&i.push(e),!1))),i.forEach((e=>{(0,s.destroy)(e)})),e.selectedElementsIds=(0,s.cast)(e.selectedElementsIds.filter((t=>e.getElementById(t))))},on(t,i){if("change"===t){let t=e.toJSON();return(0,s.onSnapshot)(e,(o=>{const n=e.toJSON();!(0,b.deepEqual)(t,n)&&(t=n,i(n))}))}},async _toCanvas({pixelRatio:t,ignoreBackground:i,pageId:o,mimeType:n,includeBleed:a,_skipTimeout:s,quickMode:r=!1}={}){var l;const c=t||1;o=o||(null===(l=e.pages[0])||void 0===l?void 0:l.id);const p=e.pages.find((e=>e.id===o));if(!p){throw new Error(`No page for export with id ${o}`)}r?null==p||p.set({_forceMount:!0}):null==p||p.set({_exporting:!0});const u=await(0,v.waitTillAvailable)((()=>d.default.stages.find((e=>e.getAttr("pageId")===o))));if(!u){throw null==p||p.set({_forceMount:!1,_exporting:!1}),new Error(`Export is failed. Can not find stage for page ${o}. Looks like <Workspace /> component is not mounted, but it is required in order to process the export.`)}const g=e._elementsPixelRatio;c>e._elementsPixelRatio&&e.setElementsPixelRatio(c),await e.waitLoading({_skipTimeout:s});const h=u.findOne(".page-container");if(!h){throw e.setElementsPixelRatio(g),null==p||p.set({_forceMount:!1,_exporting:!1}),new Error("Export is failed. Canvas was unmounted.")}const m=u.position();u.position({x:0,y:0}),u.find("Transformer").forEach((e=>{e.setAttr("oldVisible",e.visible()),e.visible(!1)})),h.find(".page-background").forEach((e=>e.shadowEnabled(!1))),h.find(".page-background").forEach((e=>e.strokeEnabled(!1))),h.find(".highlighter").forEach((e=>e.visible(!1)));const f=h.findOne(".page-background-group"),y=f.clip();f.clip({x:null,y:null,width:null,height:null});const b=h.findOne(".elements-container"),w=b.clip();b.clip({x:null,y:null,width:null,height:null});const P=h.find((e=>e.getAttr("hideInExport")));P.forEach((e=>{e.setAttr("oldVisible",e.visible()),e.hide()}));const x=h.find((e=>!e.visible()&&e.getAttr("editModeEnabled")));x.forEach((e=>{e.setAttr("oldVisible",e.visible()),e.show()})),i&&h.find(".page-background").forEach((e=>e.hide()));const E=a?p.bleed:0;let _=E;!e.bleedVisible&&a||(e.bleedVisible||a?e.bleedVisible&&a?_=0:e.bleedVisible&&!a&&(_=-p.bleed):_=0);const O=document.createElement("canvas");O.width=Math.round((p.computedWidth+2*E)*c),O.height=Math.round((p.computedHeight+2*E)*c);const S=O.getContext("2d");"image/jpeg"===n&&(S.fillStyle="white",S.fillRect(0,0,O.width,O.height));const k=h.scale();h.scale({x:1,y:1});const I=h.toCanvas({x:h.x()-_,y:h.y()-_,width:p.computedWidth+2*E,height:p.computedHeight+2*E,pixelRatio:c});return h.scale(k),S.drawImage(I,0,0,O.width,O.height),d.default.Util.releaseCanvas(I),i&&h.find(".page-background").forEach((e=>e.show())),P.forEach((e=>{e.visible(e.getAttr("oldVisible"))})),x.forEach((e=>{e.visible(e.getAttr("oldVisible"))})),h.find(".page-background").forEach((e=>e.shadowEnabled(!0))),h.find(".page-background").forEach((e=>e.strokeEnabled(!0))),u.find("Transformer").forEach((e=>{e.visible(e.getAttr("oldVisible"))})),h.find(".highlighter").forEach((e=>e.visible(!0))),f.clip(y),b.clip(w),u.position(m),e.setElementsPixelRatio(g),null==p||p.set({_exporting:!1,_forceMount:!1}),O},async toDataURL(t={}){var{mimeType:i,quality:o}=t,a=n(t,["mimeType","quality"]);const s=await e._toCanvas(Object.assign({mimeType:i},a)),r=s.toDataURL(i,o);return d.default.Util.releaseCanvas(s),r},async toBlob(t={}){var{mimeType:i,quality:o}=t,a=n(t,["mimeType","quality"]);const s=await e._toCanvas(Object.assign({mimeType:i},a)),r=await new Promise((e=>{s.toBlob(e,i,o)}));return d.default.Util.releaseCanvas(s),r},async saveAsImage(t={}){var{fileName:i}=t,o=n(t,["fileName"]);const a=o.mimeType||"image/png",s=a.split("/")[1];(0,c.downloadFile)(await e.toDataURL(o),i||"polotno."+s,a)},async _toPDF(t){const i=t.dpi||e.dpi,o=t.parallel||1,n=t.unit||("px"===e.unit?"mm":e.unit),a=t.pixelRatio||1,s=t.pageIds||e.pages.map((e=>e.id)),r=e.pages.filter((e=>s.includes(e.id))),l=await(0,p.getJsPDF)(),d=e=>(0,y.pxToUnit)({px:e,unit:n,dpi:i}),c=t.cropMarkSize||0,u=d(c),g=r[0]||{},h=t.includeBleed?g.bleed:0,m=d(g.computedWidth+2*h+2*u),f=d(g.computedHeight+2*h+2*u);var b=new l({unit:n,orientation:m>f?"landscape":"portrait",format:[m,f],compress:!0,putOnlyUsedFonts:!0});b.deletePage(1);const v=((e,t)=>{for(var i=[],o=0;o<e.length;o+=t){i.push(e.slice(o,o+t))}return i})(r,o);let w=0;for(const p of v){const i=p.map((async i=>{const o=t.includeBleed?i.bleed:0,n=i.computedWidth+2*o+2*c,r=i.computedHeight+2*o+2*c,l=d(n),p=d(r);let u=0,g=a;for(;u<10;){u+=1,2===u&&console.error("Polotno can not export PDF with current settings. Quality is automatically reduced.");const o=await e.toDataURL(Object.assign(Object.assign({},t),{pageId:i.id,pixelRatio:g}));if(o.length>20){return t.onProgress&&t.onProgress(++w/s.length*.9),{url:o,width:l,height:p,widthPx:n,heightPx:r}}g*=.8}}));(await Promise.all(i)).forEach((({url:e,width:t,height:i,widthPx:o,heightPx:a})=>{b.addPage([t,i],t>i?"landscape":"portrait");const s=b.getCurrentPageInfo();var r;switch(n){case"pt":r=1;break;case"mm":r=72/25.4;break;case"cm":r=72/2.54;break;case"in":r=72;break;case"px":r=.75;break;case"pc":case"em":r=12;break;case"ex":r=6;break;default:throw"Invalid unit: "+n}if(s.pageContext.cropBox={bottomLeftX:0,bottomLeftY:0,topRightX:t*r,topRightY:i*r},s.pageContext.artBox={bottomLeftX:d(c+h)*r,bottomLeftY:d(c+h)*r,topRightX:d(o-c-h)*r,topRightY:d(a-c-h)*r},s.pageContext.bleedBox={bottomLeftX:d(c+h)*r,bottomLeftY:d(c+h)*r,topRightX:d(o-c-h)*r,topRightY:d(a-c-h)*r},u){b.setLineWidth(d(1));const e=u+d(h);b.line(e,0,e,u),b.line(0,e,u,e),b.line(t-e,0,t-e,u),b.line(t,e,t-u,e),b.line(0,i-e,u,i-e),b.line(e,i,e,i-u),b.line(t,i-e,t-u,i-e),b.line(t-e,i,t-e,i-u)}b.addImage(e,u,u,t-2*u,i-2*u,void 0,"FAST")}))}return b},toPDFDataURL:async t=>(await e._toPDF(Object.assign({mimeType:"image/jpeg"},t))).output("datauristring"),async toGIFDataURL(t={}){const i=t.pixelRatio||1,o=await(0,u.createGIF)({width:e.width*i,height:e.height*i}),n=1e3/(t.fps||10),a=e.duration/n;for(let s=0;s<a-1;s++){const t=s*n||1;e.setCurrentTime(t);let a=0,r="";for(const i of e.pages){if(a+=i.duration,i.set({_rendering:a>t}),a>t){r=i.id;break}}const l=await e._toCanvas({pixelRatio:i,pageId:r,_skipTimeout:!0});o.addFrame(l.getContext("2d"),{delay:n,copy:!0})}for(const s of e.pages){s.set({_rendering:!1})}return e.stop(),o.render(),new Promise((e=>{o.on("finished",(function(t){!function(e,t){var i=new FileReader;i.onload=function(e){t(e.target.result)},i.readAsDataURL(e)}(t,e)}))}))},async saveAsGIF(t={}){var{fileName:i}=t,o=n(t,["fileName"]);const a=await e.toGIFDataURL(o);(0,c.downloadFile)(a,i||"polotno.gif")},async toHTML({elementHook:t}={elementHook:void 0}){const i=e.toJSON();return(0,w.jsonToHTML)({json:i,elementHook:t})},async saveAsHTML({fileName:t}={}){const i=await e.toHTML(),o="data:text/html;base64,"+window.btoa(unescape(encodeURIComponent(i)));(0,c.downloadFile)(o,t||"polotno.html")},async toSVG({elementHook:t,pageId:i}={elementHook:void 0,pageId:void 0}){var o;const n=e.toJSON();i=i||(null===(o=n.pages[0])||void 0===o?void 0:o.id);const a=n.pages.find((e=>e.id===i));return(0,P.jsonToSVG)({json:Object.assign(Object.assign({},n),{pages:a?[a]:[]}),elementHook:t})},async saveAsSVG({fileName:t,elementHook:i,pageId:o}={}){const n=await e.toSVG({elementHook:i,pageId:o}),a="data:text/svg;base64,"+window.btoa(unescape(encodeURIComponent(n)));(0,c.downloadFile)(a,t||"polotno.svg")},async saveAsPDF(t={}){var{fileName:i}=t,o=n(t,["fileName"]);(await e._toPDF(Object.assign({mimeType:"image/jpeg"},o))).save(i||"polotno.pdf")},async waitLoading({_skipTimeout:e=!1}={}){e||await new Promise((e=>setTimeout(e,50))),await(0,f.whenLoaded)()},toJSON:()=>({width:e.width,height:e.height,fonts:(0,s.getSnapshot)(e.fonts),pages:(0,s.getSnapshot)(e.pages),audios:(0,s.getSnapshot)(e.audios),unit:e.unit,dpi:e.dpi,custom:e.custom,schemaVersion:e.schemaVersion}),loadJSON(t,i=!1){var o;const n=Object.assign({},t);void 0===n.schemaVersion&&m.flags.htmlRenderEnabled&&(0,E.forEveryChild)({children:n.pages},(e=>{if("text"===e.type){const t=16,i=e.letterSpacing*t;e.letterSpacing=i/e.fontSize}}));const a=e.pages.indexOf(e.activePage);let r=null===(o=n.pages[a]||n.pages[0])||void 0===o?void 0:o.id;n._activePageId=r;const l=Object.assign({},(0,s.getSnapshot)(e));Object.assign(l,n),l.history=i?e.history.toJSON():{history:[],undoIdx:-1},(0,s.applySnapshot)(e,l)},clear({keepHistory:t=!1}={}){const i=e.pages.map((e=>e.id));e.deletePages(i),e.custom=null,t||e.history.clear()},addFont(t){e.removeFont(t.fontFamily),e.fonts.push(t),e.loadFont(t.fontFamily)},removeFont(t){e.fonts.filter((e=>e.fontFamily===t)).forEach((e=>(0,s.destroy)(e)))},addAudio(t){const i=_.Audio.create(Object.assign({id:(0,l.nanoid)(10)},t));e.audios.push(i)},removeAudio(t){const i=e.audios.find((e=>e.id===t));i&&e.audios.remove(i)},async loadFont(t){const i=e.fonts.find((e=>e.fontFamily===t))||h.globalFonts.find((e=>e.fontFamily===t));let o=[{fontStyle:"normal",fontWeight:"normal"}];return i?(i.styles&&(o=i.styles.map((e=>({fontStyle:e.fontStyle||"normal",fontWeight:e.fontWeight||"normal"})))),h.injectCustomFont(i)):h.injectGoogleFont(t),Promise.all(o.map((e=>h.loadFont(t,e.fontStyle,e.fontWeight))))},validate:e=>exports.Store.validate(e,[{path:"",type:exports.Store}]).map((e=>({path:"store"+e.context.map((e=>e.path)).join("."),message:e.message})))}))),exports.default=O;
|
|
1
|
+
var e,t=this&&this.__createBinding||(Object.create?function(e,t,i,o){void 0===o&&(o=i);var n=Object.getOwnPropertyDescriptor(t,i);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,o,n)}:function(e,t,i,o){void 0===o&&(o=i),e[o]=t[i]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||(e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var i in e){Object.prototype.hasOwnProperty.call(e,i)&&(t[t.length]=i)}return t},e(t)},function(o){if(o&&o.__esModule){return o}var n={};if(null!=o){for(var a=e(o),s=0;s<a.length;s++){"default"!==a[s]&&t(n,o,a[s])}}return i(n,o),n}),n=this&&this.__rest||function(e,t){var i={};for(var o in e){Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(i[o]=e[o])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(e);n<o.length;n++){t.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(e,o[n])&&(i[o[n]]=e[o[n]])}}return i},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Store=exports.Font=void 0,exports.createStore=O;const s=require("mobx-state-tree"),r=require("./history"),l=require("nanoid"),d=a(require("konva")),c=require("../utils/download"),p=require("../utils/pdf"),u=require("../utils/gif-lib"),g=require("../utils/validate-key"),m=o(require("../utils/fonts")),h=require("../utils/flags"),f=require("../utils/loader"),y=require("../utils/unit"),b=require("../utils/deep-equal"),v=require("../utils/wait"),w=require("../utils/to-html"),P=require("../utils/to-svg"),x=require("./page-model"),E=require("./group-model"),_=require("./audio-model");function O({key:e,showCredit:t}={key:"",showCredit:!1}){return exports.Store.create({_forceShowCredit:t,_key:e})}(0,s.setLivelinessChecking)("ignore"),exports.Font=s.types.model("Font",{fontFamily:s.types.string,url:s.types.optional(s.types.string,""),styles:s.types.frozen()}).preProcessSnapshot((e=>Object.assign(Object.assign({},e),{fontFamily:e.fontFamily||e.name}))),exports.Store=s.types.model("Store",{role:"",pages:s.types.array(x.Page),fonts:s.types.array(exports.Font),audios:s.types.array(_.Audio),width:1080,height:1080,currentTime:0,isPlaying:!1,scale:1,scaleToFit:1,unit:"px",dpi:72,schemaVersion:1,bleedVisible:!1,rulesVisible:!1,openedSidePanel:"",previousOpenedSidePanel:"",custom:s.types.frozen(),selectedElementsIds:s.types.array(s.types.string),animatedElementsIds:s.types.array(s.types.string),history:s.types.optional(r.UndoManager,{targetPath:"../pages"}),_elementsPixelRatio:Math.min(2,window.devicePixelRatio||1),_activePageId:"",_forceShowCredit:!1,_key:"",_validated:!1}).views((e=>({get _bleedVisible(){return console.warn("store._bleedVisible is deprecated. Please use store.bleedVisible instead."),e.bleedVisible},get selectedElements(){return e.selectedElementsIds.map((t=>{for(const i of e.pages){for(const e of i.children){if(e.id===t){return e}}}})).filter((e=>!!e))},get children(){return e.pages},get selectedShapes(){const t=[];return(0,E.forEveryChild)({children:e.selectedElements},(e=>{"group"!==e.type&&t.push(e)})),t},get activePage(){return e.pages.slice().find((t=>t.id===e._activePageId))||(e.pages.length?e.pages[0]:null)},get duration(){let t=0;return e.pages.forEach((e=>{t+=e.duration})),t},get _hasCroppedImages(){return e.find((e=>"image"===e.type&&e._cropModeEnabled))},find(t){let i;return(0,E.forEveryChild)({children:e.pages},(e=>{if(!i&&t(e)){return i=e,!0}})),i},getElementById:t=>e.find((e=>e.id===t))}))).actions((e=>{let t=0,i=null,o=!1;return{afterCreate(){e.history.canUndo},setCurrentTime(t){e.currentTime=t},_togglePlaying(t=!e.isPlaying){e.isPlaying=t},play({animatedElementsIds:n=[],startTime:a=0,currentTime:r=0,endTime:l=e.duration,repeat:d=!1}={}){r&&(console.warn("currentTime property of store.play() is deprecated. Please use startTime instead."),a=r),e.animatedElementsIds=(0,s.cast)(n),e.currentTime=a,e.isPlaying=!0,t=Date.now(),i=l,o=d,requestAnimationFrame(e.seek)},checkActivePage(){let t=0;for(const i of e.pages){if(e.currentTime>=i.startTime&&e.currentTime<i.startTime+i.duration){e.selectPage(i.id);break}t+=i.duration}},seek(){if(!e.isPlaying){return}const n=Date.now(),a=n-t;t=n,e.currentTime+=a,e.checkActivePage();const s=i||e.duration;e.isPlaying&&e.currentTime<s?requestAnimationFrame(e.seek):e.isPlaying&&o?(e.currentTime=0,requestAnimationFrame(e.seek)):e.stop()},stop(){e.isPlaying=!1,e.currentTime=0,e.animatedElementsIds=(0,s.cast)([]),e.checkActivePage()}}})).actions((e=>({__(){e._validated||((0,g.validateKey)(e._key,e._forceShowCredit),e._validated=!0)},set(t){Object.assign(e,t)},setUnit({unit:t,dpi:i}){e.unit=t||e.unit,e.dpi=i||e.dpi},setRole(t){e.role=t},addPage(t){const i=x.Page.create(Object.assign({id:(0,l.nanoid)(10)},t));return e.pages.push(i),e._activePageId=i.id,i},selectPage(t){e._activePageId=t},selectElements(t){const i=t.map((t=>e.getElementById(t))).sort(((e,t)=>e.page.children.indexOf(e)-e.page.children.indexOf(t))).filter((e=>!!e)).map((e=>e.id));e.selectedElementsIds=(0,s.cast)(i)},toggleBleed(t){e.bleedVisible=null!=t?t:!e.bleedVisible},toggleRulers(t){e.rulesVisible=null!=t?t:!e.rulesVisible},openSidePanel(t){e.openedSidePanel!==t&&(e.previousOpenedSidePanel=e.openedSidePanel,e.openedSidePanel=t)},setScale(t){e.scale=t},_setScaleToFit(t){e.scaleToFit=t},setElementsPixelRatio(t){e._elementsPixelRatio=t},setSize(t,i,o){e.pages.forEach((e=>{e.setSize({width:t,height:i,useMagic:o,softChange:!0})})),e.width=t,e.height=i},setPageZIndex(t,i){const o=e.pages.find((e=>e.id===t));o&&((0,s.detach)(o),e.pages.remove(o),e.pages.splice(i,0,o))},deletePages(t){const i=e.pages.indexOf(e.activePage);t.forEach((t=>{const i=e.pages.find((e=>e.id===t));(0,s.destroy)(i)}));const o=Math.min(e.pages.length-1,i),n=e.pages[o];n&&(e._activePageId=n.id),e.selectedElementsIds=(0,s.cast)(e.selectedElementsIds.filter((t=>e.getElementById(t))))},groupElements(t,i={}){const o=t.map((t=>e.getElementById(t))),n=o[0].page;if(o.forEach((e=>{e&&(0,s.detach)(e)})),!o.length){return}const a=Object.assign({id:(0,l.nanoid)(10),children:o,type:"group"},i);return n.children.push(a),e.selectedElementsIds=(0,s.cast)([a.id]),n.children.find((e=>e.id===a.id))},ungroupElements(t){const i=t.map((t=>e.getElementById(t))),o=[];i.forEach((e=>{if(e&&"group"===e.type){const t=e.page,i=t.children.indexOf(e);e.children.forEach((e=>{o.push(e.id)})),e.children.forEach((e=>{(0,s.detach)(e),t.children.push(e)})),t.children.splice(i,1)}})),e.selectedElementsIds=(0,s.cast)(o)},deleteElements(t){const i=[];e.find((e=>(t.includes(e.id)&&i.push(e),!1))),i.forEach((e=>{(0,s.destroy)(e)})),e.selectedElementsIds=(0,s.cast)(e.selectedElementsIds.filter((t=>e.getElementById(t))))},on(t,i){if("change"===t){let t=e.toJSON();return(0,s.onSnapshot)(e,(o=>{const n=e.toJSON();!(0,b.deepEqual)(t,n)&&(t=n,i(n))}))}},async _toCanvas({pixelRatio:t,ignoreBackground:i,pageId:o,mimeType:n,includeBleed:a,_skipTimeout:s,quickMode:r=!1}={}){var l;const c=t||1;o=o||(null===(l=e.pages[0])||void 0===l?void 0:l.id);const p=e.pages.find((e=>e.id===o));if(!p){throw new Error(`No page for export with id ${o}`)}const u=e._elementsPixelRatio;c>e._elementsPixelRatio&&e.setElementsPixelRatio(c),r?null==p||p.set({_forceMount:!0}):null==p||p.set({_exporting:!0});const g=await(0,v.waitTillAvailable)((()=>d.default.stages.find((e=>e.getAttr("pageId")===o))));if(!g){throw null==p||p.set({_forceMount:!1,_exporting:!1}),e.setElementsPixelRatio(u),new Error(`Export is failed. Can not find stage for page ${o}. Looks like <Workspace /> component is not mounted, but it is required in order to process the export.`)}await e.waitLoading({_skipTimeout:s});const m=g.findOne(".page-container");if(!m){throw e.setElementsPixelRatio(u),null==p||p.set({_forceMount:!1,_exporting:!1}),new Error("Export is failed. Canvas was unmounted.")}const h=g.position();g.position({x:0,y:0}),g.find("Transformer").forEach((e=>{e.setAttr("oldVisible",e.visible()),e.visible(!1)})),m.find(".page-background").forEach((e=>e.shadowEnabled(!1))),m.find(".page-background").forEach((e=>e.strokeEnabled(!1))),m.find(".highlighter").forEach((e=>e.visible(!1)));const f=m.findOne(".page-background-group"),y=f.clip();f.clip({x:null,y:null,width:null,height:null});const b=m.findOne(".elements-container"),w=b.clip();b.clip({x:null,y:null,width:null,height:null});const P=m.find((e=>e.getAttr("hideInExport")));P.forEach((e=>{e.setAttr("oldVisible",e.visible()),e.hide()}));const x=m.find((e=>!e.visible()&&e.getAttr("editModeEnabled")));x.forEach((e=>{e.setAttr("oldVisible",e.visible()),e.show()})),i&&m.find(".page-background").forEach((e=>e.hide()));const E=a?p.bleed:0;let _=E;!e.bleedVisible&&a||(e.bleedVisible||a?e.bleedVisible&&a?_=0:e.bleedVisible&&!a&&(_=-p.bleed):_=0);const O=document.createElement("canvas");O.width=Math.round((p.computedWidth+2*E)*c),O.height=Math.round((p.computedHeight+2*E)*c);const S=O.getContext("2d");"image/jpeg"===n&&(S.fillStyle="white",S.fillRect(0,0,O.width,O.height));const k=m.scale();m.scale({x:1,y:1});const I=m.toCanvas({x:m.x()-_,y:m.y()-_,width:p.computedWidth+2*E,height:p.computedHeight+2*E,pixelRatio:c});return m.scale(k),S.drawImage(I,0,0,O.width,O.height),d.default.Util.releaseCanvas(I),i&&m.find(".page-background").forEach((e=>e.show())),P.forEach((e=>{e.visible(e.getAttr("oldVisible"))})),x.forEach((e=>{e.visible(e.getAttr("oldVisible"))})),m.find(".page-background").forEach((e=>e.shadowEnabled(!0))),m.find(".page-background").forEach((e=>e.strokeEnabled(!0))),g.find("Transformer").forEach((e=>{e.visible(e.getAttr("oldVisible"))})),m.find(".highlighter").forEach((e=>e.visible(!0))),f.clip(y),b.clip(w),g.position(h),null==p||p.set({_exporting:!1,_forceMount:!1}),await new Promise((e=>setTimeout(e))),e.setElementsPixelRatio(u),O},async toDataURL(t={}){var{mimeType:i,quality:o}=t,a=n(t,["mimeType","quality"]);const s=await e._toCanvas(Object.assign({mimeType:i},a)),r=s.toDataURL(i,o);return d.default.Util.releaseCanvas(s),r},async toBlob(t={}){var{mimeType:i,quality:o}=t,a=n(t,["mimeType","quality"]);const s=await e._toCanvas(Object.assign({mimeType:i},a)),r=await new Promise((e=>{s.toBlob(e,i,o)}));return d.default.Util.releaseCanvas(s),r},async saveAsImage(t={}){var{fileName:i}=t,o=n(t,["fileName"]);const a=o.mimeType||"image/png",s=a.split("/")[1];(0,c.downloadFile)(await e.toDataURL(o),i||"polotno."+s,a)},async _toPDF(t){const i=t.dpi||e.dpi,o=t.parallel||1,n=t.unit||("px"===e.unit?"mm":e.unit),a=t.pixelRatio||1,s=t.pageIds||e.pages.map((e=>e.id)),r=e.pages.filter((e=>s.includes(e.id))),l=await(0,p.getJsPDF)(),d=e=>(0,y.pxToUnit)({px:e,unit:n,dpi:i}),c=t.cropMarkSize||0,u=d(c),g=r[0]||{},m=t.includeBleed?g.bleed:0,h=d(g.computedWidth+2*m+2*u),f=d(g.computedHeight+2*m+2*u);var b=new l({unit:n,orientation:h>f?"landscape":"portrait",format:[h,f],compress:!0,putOnlyUsedFonts:!0});b.deletePage(1);const v=((e,t)=>{for(var i=[],o=0;o<e.length;o+=t){i.push(e.slice(o,o+t))}return i})(r,o);let w=0;for(const p of v){const i=p.map((async i=>{const o=t.includeBleed?i.bleed:0,n=i.computedWidth+2*o+2*c,r=i.computedHeight+2*o+2*c,l=d(n),p=d(r);let u=0,g=a;for(;u<10;){u+=1,2===u&&console.error("Polotno can not export PDF with current settings. Quality is automatically reduced.");const o=await e.toDataURL(Object.assign(Object.assign({},t),{pageId:i.id,pixelRatio:g}));if(o.length>20){return t.onProgress&&t.onProgress(++w/s.length*.9),{url:o,width:l,height:p,widthPx:n,heightPx:r}}g*=.8}}));(await Promise.all(i)).forEach((({url:e,width:t,height:i,widthPx:o,heightPx:a})=>{b.addPage([t,i],t>i?"landscape":"portrait");const s=b.getCurrentPageInfo();var r;switch(n){case"pt":r=1;break;case"mm":r=72/25.4;break;case"cm":r=72/2.54;break;case"in":r=72;break;case"px":r=.75;break;case"pc":case"em":r=12;break;case"ex":r=6;break;default:throw"Invalid unit: "+n}if(s.pageContext.cropBox={bottomLeftX:0,bottomLeftY:0,topRightX:t*r,topRightY:i*r},s.pageContext.artBox={bottomLeftX:d(c+m)*r,bottomLeftY:d(c+m)*r,topRightX:d(o-c-m)*r,topRightY:d(a-c-m)*r},s.pageContext.bleedBox={bottomLeftX:d(c+m)*r,bottomLeftY:d(c+m)*r,topRightX:d(o-c-m)*r,topRightY:d(a-c-m)*r},u){b.setLineWidth(d(1));const e=u+d(m);b.line(e,0,e,u),b.line(0,e,u,e),b.line(t-e,0,t-e,u),b.line(t,e,t-u,e),b.line(0,i-e,u,i-e),b.line(e,i,e,i-u),b.line(t,i-e,t-u,i-e),b.line(t-e,i,t-e,i-u)}b.addImage(e,u,u,t-2*u,i-2*u,void 0,"FAST")}))}return b},toPDFDataURL:async t=>(await e._toPDF(Object.assign({mimeType:"image/jpeg"},t))).output("datauristring"),async toGIFDataURL(t={}){const i=t.pixelRatio||1,o=await(0,u.createGIF)({width:e.width*i,height:e.height*i}),n=1e3/(t.fps||10),a=e.duration/n;for(let s=0;s<a-1;s++){const t=s*n||1;e.setCurrentTime(t);let a=0,r="";for(const i of e.pages){if(a+=i.duration,i.set({_rendering:a>t}),a>t){r=i.id;break}}const l=await e._toCanvas({pixelRatio:i,pageId:r,_skipTimeout:!0});o.addFrame(l.getContext("2d"),{delay:n,copy:!0})}for(const s of e.pages){s.set({_rendering:!1})}return e.stop(),o.render(),new Promise((e=>{o.on("finished",(function(t){!function(e,t){var i=new FileReader;i.onload=function(e){t(e.target.result)},i.readAsDataURL(e)}(t,e)}))}))},async saveAsGIF(t={}){var{fileName:i}=t,o=n(t,["fileName"]);const a=await e.toGIFDataURL(o);(0,c.downloadFile)(a,i||"polotno.gif")},async toHTML({elementHook:t}={elementHook:void 0}){const i=e.toJSON();return(0,w.jsonToHTML)({json:i,elementHook:t})},async saveAsHTML({fileName:t}={}){const i=await e.toHTML(),o="data:text/html;base64,"+window.btoa(unescape(encodeURIComponent(i)));(0,c.downloadFile)(o,t||"polotno.html")},async toSVG({elementHook:t,pageId:i}={elementHook:void 0,pageId:void 0}){var o;const n=e.toJSON();i=i||(null===(o=n.pages[0])||void 0===o?void 0:o.id);const a=n.pages.find((e=>e.id===i));return(0,P.jsonToSVG)({json:Object.assign(Object.assign({},n),{pages:a?[a]:[]}),elementHook:t})},async saveAsSVG({fileName:t,elementHook:i,pageId:o}={}){const n=await e.toSVG({elementHook:i,pageId:o}),a="data:text/svg;base64,"+window.btoa(unescape(encodeURIComponent(n)));(0,c.downloadFile)(a,t||"polotno.svg")},async saveAsPDF(t={}){var{fileName:i}=t,o=n(t,["fileName"]);(await e._toPDF(Object.assign({mimeType:"image/jpeg"},o))).save(i||"polotno.pdf")},async waitLoading({_skipTimeout:e=!1}={}){e||await new Promise((e=>setTimeout(e,50))),await(0,f.whenLoaded)()},toJSON:()=>({width:e.width,height:e.height,fonts:(0,s.getSnapshot)(e.fonts),pages:(0,s.getSnapshot)(e.pages),audios:(0,s.getSnapshot)(e.audios),unit:e.unit,dpi:e.dpi,custom:e.custom,schemaVersion:e.schemaVersion}),loadJSON(t,i=!1){var o;const n=Object.assign({},t);void 0===n.schemaVersion&&h.flags.htmlRenderEnabled&&(0,E.forEveryChild)({children:n.pages},(e=>{if("text"===e.type){const t=16,i=e.letterSpacing*t;e.letterSpacing=i/e.fontSize}}));const a=e.pages.indexOf(e.activePage);let r=null===(o=n.pages[a]||n.pages[0])||void 0===o?void 0:o.id;n._activePageId=r;const l=Object.assign({},(0,s.getSnapshot)(e));Object.assign(l,n),l.history=i?e.history.toJSON():{history:[],undoIdx:-1},(0,s.applySnapshot)(e,l)},clear({keepHistory:t=!1}={}){const i=e.pages.map((e=>e.id));e.deletePages(i),e.custom=null,t||e.history.clear()},addFont(t){e.removeFont(t.fontFamily),e.fonts.push(t),e.loadFont(t.fontFamily)},removeFont(t){e.fonts.filter((e=>e.fontFamily===t)).forEach((e=>(0,s.destroy)(e)))},addAudio(t){const i=_.Audio.create(Object.assign({id:(0,l.nanoid)(10)},t));e.audios.push(i)},removeAudio(t){const i=e.audios.find((e=>e.id===t));i&&e.audios.remove(i)},async loadFont(t){const i=e.fonts.find((e=>e.fontFamily===t))||m.globalFonts.find((e=>e.fontFamily===t));let o=[{fontStyle:"normal",fontWeight:"normal"}];return i?(i.styles&&(o=i.styles.map((e=>({fontStyle:e.fontStyle||"normal",fontWeight:e.fontWeight||"normal"})))),m.injectCustomFont(i)):m.injectGoogleFont(t),Promise.all(o.map((e=>m.loadFont(t,e.fontStyle,e.fontWeight))))},validate:e=>exports.Store.validate(e,[{path:"",type:exports.Store}]).map((e=>({path:"store"+e.context.map((e=>e.path)).join("."),message:e.message})))}))),exports.default=O;
|
package/package.json
CHANGED
package/polotno.bundle.js
CHANGED
|
@@ -135,7 +135,7 @@ For more info see: https://github.com/konvajs/react-konva/issues/194
|
|
|
135
135
|
-moz-background-clip: text;
|
|
136
136
|
-webkit-text-fill-color: transparent;
|
|
137
137
|
-moz-text-fill-color: transparent;
|
|
138
|
-
`);let o=["white-space: pre-wrap",`width: ${Math.round(e.width||100)}px`,i,`font-size: ${e.fontSize}px`,`font-family: '${t}'`,`text-align: ${e.align}`,e.textDecoration?`text-decoration: ${e.textDecoration}; text-decoration-color: ${n||e.fill}; text-decoration-layer: over`:"",e.lineHeight?`line-height: ${e.lineHeight}`:"",e.letterSpacing?`letter-spacing: ${e.letterSpacing*e.fontSize}px`:"",e.fontStyle?`font-style: ${e.fontStyle}`:"",e.fontWeight?`font-weight: ${e.fontWeight}`:"",e.strokeWidth?`-webkit-text-stroke: ${e.strokeWidth}px ${e.stroke}`:"",e.strokeWidth?"paint-order: stroke fill":""].filter(Boolean).join("; ");return`<div style="${o}" contentEditable dir="${iY(iz(e.text))}">${((r=e.text)?/<[a-z][a-z0-9]*(\s[^>]*)?>[^<]*<\/[a-z][a-z0-9]*>/i.test(r)?r=(r=r.replace(/<(?![a-z/!])/gi,"<")).replace(/([^a-z0-9"'\s/])>/gi,"$1>"):r.replace(/</g,"<").replace(/>/g,">"):"").replace(/\n/g,"</br>")}</div>`}let aR=e=>{let t=e.fontSize;for(let n=1;n<50;n++){let n=aN({...e.toJSON(),fontSize:t},{fontFamily:e.fontFamily}),{height:r}=au(n),i=e.height&&r>e.height,o=function({html:e}){let t=document.createElement("div");t.innerHTML=e,t.style.display="inline-block",t.style.position="fixed",t.style.top="0px",t.style.left="0px",t.style.zIndex="1000",t.style.whiteSpace="nowrap",t.style.visibility="hidden";let n=as();n.appendChild(t);let r=t.textContent,i=t.childNodes[0],o=r.split(/\s+/),a=!1;for(let e=0;e<o.length&&(i.textContent=o[e],!(a=i.scrollWidth>t.clientWidth));e++);return n.removeChild(t),a}({html:n});if(!(i||o))break;t-=.5}return t},aL=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),aM=R(({element:e,store:t})=>{let n=h(C).useRef(null),[r,i]=h(C).useState(),[o,a]=h(C).useState(!1),[l,s]=h(C).useState(!0),u=h(C).useRef(e.height),c=t.selectedShapes.indexOf(e)>=0&&e.selectable,d=e.fontSize/3,{textVerticalResizeEnabled:f}=iM,p=i1(e.fontFamily),[g]=iJ(t,e.fontFamily),m=e._editModeEnabled;ip(n);let v=g?e.fontFamily:p!==e.fontFamily?p:"Arial",y=id(e).fill,x=aN(e,{fontFamily:v,color:y}),{width:w,height:S}=h(C).useMemo(()=>au(x),[x,e.width,g]);h(C).useEffect(()=>{if(!g)return;if(!e.height){e.set({height:S});return}let{textOverflow:n}=iM;if("change-font-size"!==n||o)"resize"!==n||(f&&e.height<S&&t.history.ignore(()=>{e.set({height:S})}),f||e.height===S||t.history.ignore(()=>{e.set({height:S})}));else{let n=aR(e);n!==e.fontSize?t.history.ignore(()=>{e.set({fontSize:n})}):e.height===S||(f&&e.height<S?t.history.ignore(()=>{e.set({height:S})}):f||t.history.ignore(()=>{e.set({height:S})}))}});let E=h(C).useRef(0),k=h(C).useMemo(()=>{let e={lastArgs:null,lastResult:null};return async function(t){return e.lastArgs&&e.lastResult&&JSON.stringify(e.lastArgs)===JSON.stringify(t)||(e.lastResult=await af(t),e.lastArgs={...t}),e.lastResult}},[]),O=h(C).useRef(null),P=async()=>{E.current++;let n=E.current,r=iy(`text ${e.id}`);O.current=r,s(!0);let o=null,a=aL?5:1;for(let i=0;i<a;i++){let a=i>0?k:af;try{var l;if(o=await a({skipCache:i>0,html:x,width:e.width||1,height:e.height||S||1,fontFamily:v,padding:d,pixelRatio:t._elementsPixelRatio,font:t.fonts.find(e=>e.fontFamily===v)||iE.find(e=>e.fontFamily===v)}),n!==E.current){r();return}if(l=o,!function(e){let t=e.getContext("2d").getImageData(0,0,e.width,e.height).data;for(let e=0;e<t.length;e+=4)if(0!==t[e+3])return!0;return!1}(l)&&aL){await new Promise(e=>setTimeout(e,50*(i+1)));continue}}catch(t){iw(`Error rendering rich text with id ${e.id}`);break}}if(!o){O.current=null,r();return}i(o),s(!1)};h(C).useEffect(()=>{o||m||P()},[x,o,S,m,v,e.height,t._elementsPixelRatio,g]);let[T,A]=aj(l),[j]=aj(o,100,!0),N=j||T;h(C).useEffect(()=>{if(!N)return _.autorun(()=>{iB(n.current,e)})},[r,N,e.shadowColor,e.shadowOffsetX,e.shadowOffsetY,e.shadowOpacity]),h(C).useEffect(()=>{r&&!l&&O.current&&(O.current(),O.current=null)},[r,l]);let R=0;"middle"===e.verticalAlign&&(R=(e.height-S)/2),"bottom"===e.verticalAlign&&(R=e.height-S);let L=i0({fontLoaded:g,fontFamily:e.fontFamily,fontSize:e.fontSize,lineHeight:e.lineHeight}),M=iU();return(0,b.jsxs)(h(C).Fragment,{children:[(0,b.jsx)(rX,{x:e.a.x,y:e.a.y,offsetX:e.backgroundPadding*(e.fontSize*L*.5),offsetY:e.backgroundPadding*(e.fontSize*L*.5),rotation:e.a.rotation,hideInExport:!e.showInExport,listening:!1,visible:e.backgroundEnabled,opacity:e.backgroundOpacity*e.a.opacity,fill:e.backgroundColor,width:e.a.width+e.backgroundPadding*(e.fontSize*L),height:e.a.height+e.backgroundPadding*(e.fontSize*L),cornerRadius:e.backgroundCornerRadius*(e.fontSize*L*.5)}),(0,b.jsx)(rX,{ref:n,name:"element",x:e.a.x,y:e.a.y,listening:e.selectable,rotation:e.a.rotation,width:e.a.width,height:e.a.height,visible:!N,draggable:M?e.draggable&&c:e.draggable,preventDefault:!M||c,opacity:m?0:e.a.opacity,hideInExport:!e.showInExport,onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},id:e.id,onDblClick:()=>{e.contentEditable&&e.toggleEditMode(!0)},onDblTap:()=>{e.contentEditable&&e.toggleEditMode(!0)},onTransformStart:t=>{a(!0),u.current=e.height},onTransform:t=>{let n=t.target,r=(n.getStage()?.findOne("Transformer")).getActiveAnchor(),i=n.scaleX();if("middle-left"===r||"middle-right"===r){let t=n.scaleX(),r=Math.max(n.width()*t,e.fontSize);if(n.width(r),n.scaleX(1),iM.textVerticalResizeEnabled){let t=Math.max(S,u.current);e.set({height:t})}e.set({width:r,x:n.x(),y:n.y()})}else if("top-center"===r||"bottom-center"===r){let r=Math.max("resize"===iM.textOverflow?S:e.lineHeight*e.fontSize,t.target.height()*t.target.scaleY());n.scaleY(1),e.set({x:n.x(),y:n.y(),height:r,rotation:n.rotation()})}else n.scaleX(1),n.scaleY(1),e.set({fontSize:e.fontSize*i,letterSpacing:e.letterSpacing,width:n.width()*i,x:n.x(),y:n.y(),rotation:n.rotation(),height:n.height()*i})},onTransformEnd:t=>{a(!1),s(!0);let n=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),e.set({fontSize:e.fontSize*n,width:t.target.width()*n,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),shadowBlur:e.shadowBlur*n,shadowOffsetX:e.shadowOffsetX*n,shadowOffsetY:e.shadowOffsetY*n,strokeWidth:e.strokeWidth*n})}}),(0,b.jsx)(rQ,{ref:n,image:r,x:e.a.x,y:e.a.y,offsetX:d,offsetY:d-R,listening:!1,rotation:e.a.rotation,width:e.a.width+2*d,height:e.a.height+2*d,visible:!N,opacity:m?0:e.a.opacity,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,hideInExport:!e.showInExport}),N&&(0,b.jsx)(rK,{x:e.a.x,y:e.a.y,rotation:e.a.rotation,offsetY:-R,children:(0,b.jsx)(r5,{divProps:{style:{pointerEvents:"none"}},children:(0,b.jsx)(ak,{dangerouslySetInnerHTML:{__html:x},style:{pointerEvents:"none",opacity:e.a.opacity}})})}),m&&(0,b.jsx)(rK,{x:e.a.x,y:e.a.y,rotation:e.a.rotation,offsetY:-R,children:(0,b.jsx)(r5,{children:(0,b.jsx)(aA,{html:x,element:e,onChange:t=>{let n=iW({oldText:iz(e.text),newText:iz(t),element:e});e.set({text:t,fontSize:n})},onBlur:n=>{e.toggleEditMode(!1),A(!0),""===iz(e.text)&&e.removable&&!e.placeholder&&t.deleteElements([e.id])}})})})]})});var C=(v("8NFma"),v("8NFma"));function aI(e){return e/180*Math.PI}function aD(e,t,n,r,i){let o=Math.sqrt(n*n+r*r);return{x:e+o*Math.cos(i+=Math.atan2(r,n)),y:t+o*Math.sin(i)}}function az(e){let{x:t,y:n,width:r,height:i}=e,o=aI(e.rotation),a=aD(t,n,0,0,o),l=aD(t,n,r,0,o),s=aD(t,n,r,i,o),u=aD(t,n,0,i,o),c=Math.min(a.x,l.x,s.x,u.x),d=Math.min(a.y,l.y,s.y,u.y),h=Math.max(a.x,l.x,s.x,u.x),f=Math.max(a.y,l.y,s.y,u.y);return{x:c,y:d,width:h-c,height:f-d,minX:c,minY:d,maxX:h,maxY:f}}function aF(e){let t=e.map(e=>az(e)),n=Math.min(...t.map(e=>e.minX)),r=Math.min(...t.map(e=>e.minY)),i=Math.max(...t.map(e=>e.maxX)),o=Math.max(...t.map(e=>e.maxY));return{x:n,y:r,width:i-n,height:o-r,minX:n,minY:r,maxX:i,maxY:o}}let aB=({targetKonvaNodes:e,guideKonvaNode:t,distance:n,snapDirection:r})=>n<5;function aH(e,t){var n=[],r=[];e.vertical.forEach(e=>{t.vertical.forEach(t=>{var r=Math.abs(e.offset-t.guide);aB({targetKonvaNodes:t.nodes,guideKonvaNode:e.node,distance:r,snapDirection:e.snap})&&n.push({lineGuide:e.offset,diff:r,snap:t.snap,offset:t.offset})})}),e.horizontal.forEach(e=>{t.horizontal.forEach(t=>{var n=Math.abs(e.offset-t.guide);aB({targetKonvaNodes:t.nodes,guideKonvaNode:e.node,distance:n,snapDirection:e.snap})&&r.push({lineGuide:e.offset,diff:n,snap:t.snap,offset:t.offset})})});var i=[];let o=n.sort((e,t)=>e.diff-t.diff),a=r.sort((e,t)=>e.diff-t.diff);var l=o[0],s=a[0];return l&&o.filter(e=>.1>Math.abs(e.diff-l.diff)).forEach(e=>{i.push({orientation:"V",...e})}),s&&a.filter(e=>.1>Math.abs(e.diff-s.diff)).forEach(e=>{i.push({orientation:"H",...e})}),i}function aV(e,t,n){let r=e=>e.hasName("element")||e.hasName("line-anchor")||e.hasName("page-background")||e.hasName("elements-area"),i=n=>{let i=n.target.getLayer().children.find(e=>"line-guides"===e.name());i?.destroyChildren();var o,a=aH(function(t){let n=e.current?.getStage();var i=[],o=[];return n.find(r).forEach(e=>{if(!(t.indexOf(e)>=0)){var n=e.getClientRect({skipShadow:!0,skipStroke:!0});e.hasName("line-anchor")&&(n={x:e.absolutePosition().x,y:e.absolutePosition().y,width:0,height:0}),i.push({offset:n.x,node:e,snap:"start"},{offset:n.x+n.width,node:e,snap:"end"},{offset:n.x+n.width/2,node:e,snap:"center"}),o.push({offset:n.y,node:e,snap:"start"},{offset:n.y+n.height,node:e,snap:"end"},{offset:n.y+n.height/2,node:e,snap:"center"})}}),{vertical:i,horizontal:o}}([n.target,...t.map(e=>e.current)]),{vertical:[{guide:(o=n.target).absolutePosition().x,offset:0,snap:"center",nodes:[o]}],horizontal:[{guide:o.absolutePosition().y,offset:0,snap:"center",nodes:[o]}]});if(!a.length)return;!function(t){let n=e.current?.getLayer(),r=n?.children.find(e=>"line-guides"===e.name());t.forEach(e=>{if("H"===e.orientation){var t=new(h(M)).Line({points:[-6e3,e.lineGuide,6e3,e.lineGuide],stroke:"rgb(0, 161, 255)",strokeWidth:1,name:"guid-line",dash:[4,6]});r?.add(t),n.batchDraw()}else if("V"===e.orientation){var t=new(h(M)).Line({points:[e.lineGuide,-6e3,e.lineGuide,6e3],stroke:"rgb(0, 161, 255)",strokeWidth:1,name:"guid-line",dash:[4,6]});r?.add(t)}})}(a);let l=n.target.getAbsolutePosition(),s={...l};a.forEach(e=>{switch(e.snap){case"start":case"center":case"end":switch(e.orientation){case"V":s.x=e.lineGuide+e.offset;break;case"H":s.y=e.lineGuide+e.offset}}});let u=s.x-l.x,c=s.y-l.y;if(!(n.evt.ctrlKey||n.evt.metaKey)){let e=n.target.getAbsolutePosition();n.target.absolutePosition({x:e.x+u,y:e.y+c})}},o=e=>{if(!e.target)return;let t=e.target.getLayer(),n=t.children.find(e=>"line-guides"===e.name());n?.destroyChildren(),t.batchDraw()};h(C).useEffect(()=>{e.current&&(e.current.on("dragmove",i),e.current.on("dragend",o))},n)}function aU(e,t){return e.x*t.x+e.y*t.y}let aG={"top-left":"bottom-right","top-center":"bottom-center","top-right":"bottom-left","middle-right":"middle-left","bottom-right":"top-left","bottom-center":"top-center","bottom-left":"top-right","middle-left":"middle-right"};function aq(e){let{x:t,y:n,width:r,height:i,rotation:o}=e.a,a=o*Math.PI/180,l={x:t+i/2*Math.cos(a+Math.PI/2),y:n+i/2*Math.sin(a+Math.PI/2)},s={x:l.x+r*Math.cos(a),y:l.y+r*Math.sin(a)};return{middleLeft:l,middleRight:s}}function aW(e,t,n){let r=Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2)),i=Math.atan2(t.y-e.y,t.x-e.x),o=180*i/Math.PI;return{x:e.x+Math.cos(i-Math.PI/2)*n/2,y:e.y+Math.sin(i-Math.PI/2)*n/2,width:r,height:n,rotation:o}}let a$=(e,t)=>({offsetX:5/e,offsetY:5/e,width:10/e,height:10/e,fill:"white",stroke:"rgb(0, 161, 255)",strokeWidth:2,strokeScaleEnabled:!1,draggable:!0,dragDistance:0,onMouseEnter:e=>{e.target.getStage().container().style.cursor="crosshair"},onMouseLeave:e=>{e.target.getStage().container().style.cursor=""},onDragStart:e=>{t.history.startTransaction()},onDragEnd:e=>{t.history.endTransaction()}}),aK=R(({element:e,type:t})=>{let n=id(e,e.a.color,"fill"),r=id(e,e.a.color,"stroke"),i={strokeWidth:e.height,lineCap:"round",lineJoin:"round",...r,...n,opacity:e.a.opacity,hideInExport:!e.showInExport};return(0,b.jsxs)(b.Fragment,{children:["arrow"===t&&(0,b.jsx)(rZ,{points:[3*e.height,-(2*e.height),0,0,3*e.height,2*e.height],...i}),"triangle"===t&&(0,b.jsx)(rZ,{points:[3*e.height,-(2*e.height),0,0,3*e.height,2*e.height],closed:!0,...i}),"bar"===t&&(0,b.jsx)(rZ,{points:[0,-(2*e.height),0,2*e.height],closed:!0,...i}),"square"===t&&(0,b.jsx)(rZ,{points:[0,-(2*e.height),4*e.height,-(2*e.height),4*e.height,2*e.height,0,2*e.height],closed:!0,...i}),"circle"===t&&(0,b.jsx)("Circle",{x:2*e.height,y:0,radius:2*e.height,...i})]})}),aY=R(({element:e,store:t})=>{let n=h(C).useRef(null),r=h(C).useRef(null),i=h(C).useRef(null),o=e.selectable||"admin"===t.role,a=iU(),l=t.selectedElements.indexOf(e)>=0&&1===t.selectedElements.length,s=t.selectedShapes.indexOf(e)>=0&&e.selectable,{middleLeft:u,middleRight:c}=aq(e);aV(r,[n],[l]),aV(i,[n],[l]);let d=id(e,e.a.color,"stroke");return(0,b.jsxs)(h(C).Fragment,{children:[(0,b.jsx)(rZ,{ref:n,name:"element",id:e.id,x:e.a.x,y:e.a.y,points:[0,0,e.a.width,0],offsetY:-e.a.height/2,strokeWidth:e.a.height,hitStrokeWidth:Math.max(e.a.height,20),dash:e.dash.map(t=>t*e.a.height),...d,rotation:e.a.rotation,opacity:e.animated("opacity"),shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,listening:o,draggable:a?e.draggable&&s:e.draggable,preventDefault:!a||s,hideInExport:!e.showInExport,onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},onTransform:t=>{let n=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),e.set({height:e.height*n,width:e.width*n,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation()})}}),(0,b.jsx)(rK,{x:u.x,y:u.y,rotation:e.rotation,hideInExport:!e.showInExport,children:(0,b.jsx)(aK,{element:e,type:e.startHead})}),(0,b.jsx)(rK,{x:c.x,y:c.y,rotation:e.rotation+180,children:(0,b.jsx)(aK,{element:e,type:e.endHead})}),l&&e.resizable&&(0,b.jsx)(r9,{selector:".page-abs-container",enabled:!0,children:(0,b.jsxs)(rK,{visible:l,children:[(0,b.jsx)(rX,{x:u.x,y:u.y,ref:r,name:"line-anchor",...a$(t.scale,t),onDragMove:t=>{let n=aW(t.target.position(),c,e.height);e.set({x:n.x,y:n.y,width:n.width,rotation:n.rotation})}}),(0,b.jsx)(rX,{x:c.x,y:c.y,ref:i,name:"line-anchor",...a$(t.scale,t),onDragMove:t=>{let n=aW(u,t.target.position(),e.height);e.set({x:n.x,y:n.y,width:n.width,rotation:n.rotation})}})]})})]})});var C=v("8NFma"),_=v("2SBKn");function aX(){return document.createElement("canvas")}async function aZ(e){return e.indexOf("data:image/svg+xml")>=0||e.indexOf(".svg")>=0?oe(on(await i7(e))):e}let aQ=e=>{let[t,n]=h(C).useState(e);return h(C).useEffect(()=>{(async()=>{let r=await aZ(e);r!==t&&n(r)})()},[e]),t},aJ=new window.Image;aJ.src=oe(`
|
|
138
|
+
`);let o=["white-space: pre-wrap",`width: ${Math.round(e.width||100)}px`,i,`font-size: ${e.fontSize}px`,`font-family: '${t}'`,`text-align: ${e.align}`,e.textDecoration?`text-decoration: ${e.textDecoration}; text-decoration-color: ${n||e.fill}; text-decoration-layer: over`:"",e.lineHeight?`line-height: ${e.lineHeight}`:"",e.letterSpacing?`letter-spacing: ${e.letterSpacing*e.fontSize}px`:"",e.fontStyle?`font-style: ${e.fontStyle}`:"",e.fontWeight?`font-weight: ${e.fontWeight}`:"",e.strokeWidth?`-webkit-text-stroke: ${e.strokeWidth}px ${e.stroke}`:"",e.strokeWidth?"paint-order: stroke fill":""].filter(Boolean).join("; ");return`<div style="${o}" contentEditable dir="${iY(iz(e.text))}">${((r=e.text)?/<[a-z][a-z0-9]*(\s[^>]*)?>[^<]*<\/[a-z][a-z0-9]*>/i.test(r)?r=(r=r.replace(/<(?![a-z/!])/gi,"<")).replace(/([^a-z0-9"'\s/])>/gi,"$1>"):r.replace(/</g,"<").replace(/>/g,">"):"").replace(/\n/g,"</br>")}</div>`}let aR=e=>{let t=e.fontSize;for(let n=1;n<50;n++){let n=aN({...e.toJSON(),fontSize:t},{fontFamily:e.fontFamily}),{height:r}=au(n),i=e.height&&r>e.height,o=function({html:e}){let t=document.createElement("div");t.innerHTML=e,t.style.display="inline-block",t.style.position="fixed",t.style.top="0px",t.style.left="0px",t.style.zIndex="1000",t.style.whiteSpace="nowrap",t.style.visibility="hidden";let n=as();n.appendChild(t);let r=t.textContent,i=t.childNodes[0],o=r.split(/\s+/),a=!1;for(let e=0;e<o.length&&(i.textContent=o[e],!(a=i.scrollWidth>t.clientWidth));e++);return n.removeChild(t),a}({html:n});if(!(i||o))break;t-=.5}return t},aL=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),aM=R(({element:e,store:t})=>{let n=h(C).useRef(null),[r,i]=h(C).useState(),[o,a]=h(C).useState(!1),[l,s]=h(C).useState(!0),u=h(C).useRef(e.height),c=t.selectedShapes.indexOf(e)>=0&&e.selectable,d=e.fontSize/3,{textVerticalResizeEnabled:f}=iM,p=i1(e.fontFamily),[g]=iJ(t,e.fontFamily),m=e._editModeEnabled;ip(n);let v=g?e.fontFamily:p!==e.fontFamily?p:"Arial",y=id(e).fill,x=aN(e,{fontFamily:v,color:y}),{width:w,height:S}=h(C).useMemo(()=>au(x),[x,e.width,g]);h(C).useEffect(()=>{if(!g)return;if(!e.height){e.set({height:S});return}let{textOverflow:n}=iM;if("change-font-size"!==n||o)"resize"!==n||(f&&e.height<S&&t.history.ignore(()=>{e.set({height:S})}),f||e.height===S||t.history.ignore(()=>{e.set({height:S})}));else{let n=aR(e);n!==e.fontSize?t.history.ignore(()=>{e.set({fontSize:n})}):e.height===S||(f&&e.height<S?t.history.ignore(()=>{e.set({height:S})}):f||t.history.ignore(()=>{e.set({height:S})}))}});let E=h(C).useRef(0),k=h(C).useMemo(()=>{let e={lastArgs:null,lastResult:null};return async function(t){return e.lastArgs&&e.lastResult&&JSON.stringify(e.lastArgs)===JSON.stringify(t)||(e.lastResult=await af(t),e.lastArgs={...t}),e.lastResult}},[]),O=h(C).useRef(null),P=async()=>{E.current++;let n=E.current,r=iy(`text ${e.id}`);O.current=r,s(!0);let o=null,a=aL?5:1;for(let i=0;i<a;i++){let a=i>0?k:af;try{var l;if(o=await a({skipCache:i>0,html:x,width:e.width||1,height:e.height||S||1,fontFamily:v,padding:d,pixelRatio:t._elementsPixelRatio,font:t.fonts.find(e=>e.fontFamily===v)||iE.find(e=>e.fontFamily===v)}),n!==E.current){r();return}if(l=o,!function(e){let t=e.getContext("2d").getImageData(0,0,e.width,e.height).data;for(let e=0;e<t.length;e+=4)if(0!==t[e+3])return!0;return!1}(l)&&aL){await new Promise(e=>setTimeout(e,50*(i+1)));continue}}catch(t){iw(`Error rendering rich text with id ${e.id}`);break}}if(!o){O.current=null,r();return}i(o),s(!1)};h(C).useEffect(()=>{o||m||P()},[x,o,S,m,v,e.height,t._elementsPixelRatio,g]);let[T,A]=aj(l),[j]=aj(o,100,!0),N=j||T;h(C).useEffect(()=>{if(!N)return _.autorun(()=>{iB(n.current,e)})},[r,N,e.shadowColor,e.shadowOffsetX,e.shadowOffsetY,e.shadowOpacity]),h(C).useEffect(()=>{r&&!l&&O.current&&(O.current(),O.current=null)},[r,l]),h(C).useEffect(()=>()=>{O.current&&O.current()},[]);let R=0;"middle"===e.verticalAlign&&(R=(e.height-S)/2),"bottom"===e.verticalAlign&&(R=e.height-S);let L=i0({fontLoaded:g,fontFamily:e.fontFamily,fontSize:e.fontSize,lineHeight:e.lineHeight}),M=iU();return(0,b.jsxs)(h(C).Fragment,{children:[(0,b.jsx)(rX,{x:e.a.x,y:e.a.y,offsetX:e.backgroundPadding*(e.fontSize*L*.5),offsetY:e.backgroundPadding*(e.fontSize*L*.5),rotation:e.a.rotation,hideInExport:!e.showInExport,listening:!1,visible:e.backgroundEnabled,opacity:e.backgroundOpacity*e.a.opacity,fill:e.backgroundColor,width:e.a.width+e.backgroundPadding*(e.fontSize*L),height:e.a.height+e.backgroundPadding*(e.fontSize*L),cornerRadius:e.backgroundCornerRadius*(e.fontSize*L*.5)}),(0,b.jsx)(rX,{ref:n,name:"element",x:e.a.x,y:e.a.y,listening:e.selectable,rotation:e.a.rotation,width:e.a.width,height:e.a.height,visible:!N,draggable:M?e.draggable&&c:e.draggable,preventDefault:!M||c,opacity:m?0:e.a.opacity,hideInExport:!e.showInExport,onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},id:e.id,onDblClick:()=>{e.contentEditable&&e.toggleEditMode(!0)},onDblTap:()=>{e.contentEditable&&e.toggleEditMode(!0)},onTransformStart:t=>{a(!0),u.current=e.height},onTransform:t=>{let n=t.target,r=(n.getStage()?.findOne("Transformer")).getActiveAnchor(),i=n.scaleX();if("middle-left"===r||"middle-right"===r){let t=n.scaleX(),r=Math.max(n.width()*t,e.fontSize);if(n.width(r),n.scaleX(1),iM.textVerticalResizeEnabled){let t=Math.max(S,u.current);e.set({height:t})}e.set({width:r,x:n.x(),y:n.y()})}else if("top-center"===r||"bottom-center"===r){let r=Math.max("resize"===iM.textOverflow?S:e.lineHeight*e.fontSize,t.target.height()*t.target.scaleY());n.scaleY(1),e.set({x:n.x(),y:n.y(),height:r,rotation:n.rotation()})}else n.scaleX(1),n.scaleY(1),e.set({fontSize:e.fontSize*i,letterSpacing:e.letterSpacing,width:n.width()*i,x:n.x(),y:n.y(),rotation:n.rotation(),height:n.height()*i})},onTransformEnd:t=>{a(!1),s(!0);let n=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),e.set({fontSize:e.fontSize*n,width:t.target.width()*n,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),shadowBlur:e.shadowBlur*n,shadowOffsetX:e.shadowOffsetX*n,shadowOffsetY:e.shadowOffsetY*n,strokeWidth:e.strokeWidth*n})}}),(0,b.jsx)(rQ,{ref:n,image:r,x:e.a.x,y:e.a.y,offsetX:d,offsetY:d-R,listening:!1,rotation:e.a.rotation,width:e.a.width+2*d,height:e.a.height+2*d,visible:!N,opacity:m?0:e.a.opacity,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,hideInExport:!e.showInExport}),N&&(0,b.jsx)(rK,{x:e.a.x,y:e.a.y,rotation:e.a.rotation,offsetY:-R,children:(0,b.jsx)(r5,{divProps:{style:{pointerEvents:"none"}},children:(0,b.jsx)(ak,{dangerouslySetInnerHTML:{__html:x},style:{pointerEvents:"none",opacity:e.a.opacity}})})}),m&&(0,b.jsx)(rK,{x:e.a.x,y:e.a.y,rotation:e.a.rotation,offsetY:-R,children:(0,b.jsx)(r5,{children:(0,b.jsx)(aA,{html:x,element:e,onChange:t=>{let n=iW({oldText:iz(e.text),newText:iz(t),element:e});e.set({text:t,fontSize:n})},onBlur:n=>{e.toggleEditMode(!1),A(!0),""===iz(e.text)&&e.removable&&!e.placeholder&&t.deleteElements([e.id])}})})})]})});var C=(v("8NFma"),v("8NFma"));function aI(e){return e/180*Math.PI}function aD(e,t,n,r,i){let o=Math.sqrt(n*n+r*r);return{x:e+o*Math.cos(i+=Math.atan2(r,n)),y:t+o*Math.sin(i)}}function az(e){let{x:t,y:n,width:r,height:i}=e,o=aI(e.rotation),a=aD(t,n,0,0,o),l=aD(t,n,r,0,o),s=aD(t,n,r,i,o),u=aD(t,n,0,i,o),c=Math.min(a.x,l.x,s.x,u.x),d=Math.min(a.y,l.y,s.y,u.y),h=Math.max(a.x,l.x,s.x,u.x),f=Math.max(a.y,l.y,s.y,u.y);return{x:c,y:d,width:h-c,height:f-d,minX:c,minY:d,maxX:h,maxY:f}}function aF(e){let t=e.map(e=>az(e)),n=Math.min(...t.map(e=>e.minX)),r=Math.min(...t.map(e=>e.minY)),i=Math.max(...t.map(e=>e.maxX)),o=Math.max(...t.map(e=>e.maxY));return{x:n,y:r,width:i-n,height:o-r,minX:n,minY:r,maxX:i,maxY:o}}let aB=({targetKonvaNodes:e,guideKonvaNode:t,distance:n,snapDirection:r})=>n<5;function aH(e,t){var n=[],r=[];e.vertical.forEach(e=>{t.vertical.forEach(t=>{var r=Math.abs(e.offset-t.guide);aB({targetKonvaNodes:t.nodes,guideKonvaNode:e.node,distance:r,snapDirection:e.snap})&&n.push({lineGuide:e.offset,diff:r,snap:t.snap,offset:t.offset})})}),e.horizontal.forEach(e=>{t.horizontal.forEach(t=>{var n=Math.abs(e.offset-t.guide);aB({targetKonvaNodes:t.nodes,guideKonvaNode:e.node,distance:n,snapDirection:e.snap})&&r.push({lineGuide:e.offset,diff:n,snap:t.snap,offset:t.offset})})});var i=[];let o=n.sort((e,t)=>e.diff-t.diff),a=r.sort((e,t)=>e.diff-t.diff);var l=o[0],s=a[0];return l&&o.filter(e=>.1>Math.abs(e.diff-l.diff)).forEach(e=>{i.push({orientation:"V",...e})}),s&&a.filter(e=>.1>Math.abs(e.diff-s.diff)).forEach(e=>{i.push({orientation:"H",...e})}),i}function aV(e,t,n){let r=e=>e.hasName("element")||e.hasName("line-anchor")||e.hasName("page-background")||e.hasName("elements-area"),i=n=>{let i=n.target.getLayer().children.find(e=>"line-guides"===e.name());i?.destroyChildren();var o,a=aH(function(t){let n=e.current?.getStage();var i=[],o=[];return n.find(r).forEach(e=>{if(!(t.indexOf(e)>=0)){var n=e.getClientRect({skipShadow:!0,skipStroke:!0});e.hasName("line-anchor")&&(n={x:e.absolutePosition().x,y:e.absolutePosition().y,width:0,height:0}),i.push({offset:n.x,node:e,snap:"start"},{offset:n.x+n.width,node:e,snap:"end"},{offset:n.x+n.width/2,node:e,snap:"center"}),o.push({offset:n.y,node:e,snap:"start"},{offset:n.y+n.height,node:e,snap:"end"},{offset:n.y+n.height/2,node:e,snap:"center"})}}),{vertical:i,horizontal:o}}([n.target,...t.map(e=>e.current)]),{vertical:[{guide:(o=n.target).absolutePosition().x,offset:0,snap:"center",nodes:[o]}],horizontal:[{guide:o.absolutePosition().y,offset:0,snap:"center",nodes:[o]}]});if(!a.length)return;!function(t){let n=e.current?.getLayer(),r=n?.children.find(e=>"line-guides"===e.name());t.forEach(e=>{if("H"===e.orientation){var t=new(h(M)).Line({points:[-6e3,e.lineGuide,6e3,e.lineGuide],stroke:"rgb(0, 161, 255)",strokeWidth:1,name:"guid-line",dash:[4,6]});r?.add(t),n.batchDraw()}else if("V"===e.orientation){var t=new(h(M)).Line({points:[e.lineGuide,-6e3,e.lineGuide,6e3],stroke:"rgb(0, 161, 255)",strokeWidth:1,name:"guid-line",dash:[4,6]});r?.add(t)}})}(a);let l=n.target.getAbsolutePosition(),s={...l};a.forEach(e=>{switch(e.snap){case"start":case"center":case"end":switch(e.orientation){case"V":s.x=e.lineGuide+e.offset;break;case"H":s.y=e.lineGuide+e.offset}}});let u=s.x-l.x,c=s.y-l.y;if(!(n.evt.ctrlKey||n.evt.metaKey)){let e=n.target.getAbsolutePosition();n.target.absolutePosition({x:e.x+u,y:e.y+c})}},o=e=>{if(!e.target)return;let t=e.target.getLayer(),n=t.children.find(e=>"line-guides"===e.name());n?.destroyChildren(),t.batchDraw()};h(C).useEffect(()=>{e.current&&(e.current.on("dragmove",i),e.current.on("dragend",o))},n)}function aU(e,t){return e.x*t.x+e.y*t.y}let aG={"top-left":"bottom-right","top-center":"bottom-center","top-right":"bottom-left","middle-right":"middle-left","bottom-right":"top-left","bottom-center":"top-center","bottom-left":"top-right","middle-left":"middle-right"};function aq(e){let{x:t,y:n,width:r,height:i,rotation:o}=e.a,a=o*Math.PI/180,l={x:t+i/2*Math.cos(a+Math.PI/2),y:n+i/2*Math.sin(a+Math.PI/2)},s={x:l.x+r*Math.cos(a),y:l.y+r*Math.sin(a)};return{middleLeft:l,middleRight:s}}function aW(e,t,n){let r=Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2)),i=Math.atan2(t.y-e.y,t.x-e.x),o=180*i/Math.PI;return{x:e.x+Math.cos(i-Math.PI/2)*n/2,y:e.y+Math.sin(i-Math.PI/2)*n/2,width:r,height:n,rotation:o}}let a$=(e,t)=>({offsetX:5/e,offsetY:5/e,width:10/e,height:10/e,fill:"white",stroke:"rgb(0, 161, 255)",strokeWidth:2,strokeScaleEnabled:!1,draggable:!0,dragDistance:0,onMouseEnter:e=>{e.target.getStage().container().style.cursor="crosshair"},onMouseLeave:e=>{e.target.getStage().container().style.cursor=""},onDragStart:e=>{t.history.startTransaction()},onDragEnd:e=>{t.history.endTransaction()}}),aK=R(({element:e,type:t})=>{let n=id(e,e.a.color,"fill"),r=id(e,e.a.color,"stroke"),i={strokeWidth:e.height,lineCap:"round",lineJoin:"round",...r,...n,opacity:e.a.opacity,hideInExport:!e.showInExport};return(0,b.jsxs)(b.Fragment,{children:["arrow"===t&&(0,b.jsx)(rZ,{points:[3*e.height,-(2*e.height),0,0,3*e.height,2*e.height],...i}),"triangle"===t&&(0,b.jsx)(rZ,{points:[3*e.height,-(2*e.height),0,0,3*e.height,2*e.height],closed:!0,...i}),"bar"===t&&(0,b.jsx)(rZ,{points:[0,-(2*e.height),0,2*e.height],closed:!0,...i}),"square"===t&&(0,b.jsx)(rZ,{points:[0,-(2*e.height),4*e.height,-(2*e.height),4*e.height,2*e.height,0,2*e.height],closed:!0,...i}),"circle"===t&&(0,b.jsx)("Circle",{x:2*e.height,y:0,radius:2*e.height,...i})]})}),aY=R(({element:e,store:t})=>{let n=h(C).useRef(null),r=h(C).useRef(null),i=h(C).useRef(null),o=e.selectable||"admin"===t.role,a=iU(),l=t.selectedElements.indexOf(e)>=0&&1===t.selectedElements.length,s=t.selectedShapes.indexOf(e)>=0&&e.selectable,{middleLeft:u,middleRight:c}=aq(e);aV(r,[n],[l]),aV(i,[n],[l]);let d=id(e,e.a.color,"stroke");return(0,b.jsxs)(h(C).Fragment,{children:[(0,b.jsx)(rZ,{ref:n,name:"element",id:e.id,x:e.a.x,y:e.a.y,points:[0,0,e.a.width,0],offsetY:-e.a.height/2,strokeWidth:e.a.height,hitStrokeWidth:Math.max(e.a.height,20),dash:e.dash.map(t=>t*e.a.height),...d,rotation:e.a.rotation,opacity:e.animated("opacity"),shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,listening:o,draggable:a?e.draggable&&s:e.draggable,preventDefault:!a||s,hideInExport:!e.showInExport,onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},onTransform:t=>{let n=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),e.set({height:e.height*n,width:e.width*n,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation()})}}),(0,b.jsx)(rK,{x:u.x,y:u.y,rotation:e.rotation,hideInExport:!e.showInExport,children:(0,b.jsx)(aK,{element:e,type:e.startHead})}),(0,b.jsx)(rK,{x:c.x,y:c.y,rotation:e.rotation+180,children:(0,b.jsx)(aK,{element:e,type:e.endHead})}),l&&e.resizable&&(0,b.jsx)(r9,{selector:".page-abs-container",enabled:!0,children:(0,b.jsxs)(rK,{visible:l,children:[(0,b.jsx)(rX,{x:u.x,y:u.y,ref:r,name:"line-anchor",...a$(t.scale,t),onDragMove:t=>{let n=aW(t.target.position(),c,e.height);e.set({x:n.x,y:n.y,width:n.width,rotation:n.rotation})}}),(0,b.jsx)(rX,{x:c.x,y:c.y,ref:i,name:"line-anchor",...a$(t.scale,t),onDragMove:t=>{let n=aW(u,t.target.position(),e.height);e.set({x:n.x,y:n.y,width:n.width,rotation:n.rotation})}})]})})]})});var C=v("8NFma"),_=v("2SBKn");function aX(){return document.createElement("canvas")}async function aZ(e){return e.indexOf("data:image/svg+xml")>=0||e.indexOf(".svg")>=0?oe(on(await i7(e))):e}let aQ=e=>{let[t,n]=h(C).useState(e);return h(C).useEffect(()=>{(async()=>{let r=await aZ(e);r!==t&&n(r)})()},[e]),t},aJ=new window.Image;aJ.src=oe(`
|
|
139
139
|
<svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
140
140
|
<path opacity="0.6" d="M4 5.49683V18.5032C4 20.05 5.68077 21.0113 7.01404 20.227L18.0694 13.7239C19.384 12.9506 19.384 11.0494 18.0694 10.2761L7.01404 3.77296C5.68077 2.98869 4 3.95 4 5.49683Z" fill="white"/>
|
|
141
141
|
<path d="M4 5.49683V18.5032C4 20.05 5.68077 21.0113 7.01404 20.227L18.0694 13.7239C19.384 12.9506 19.384 11.0494 18.0694 10.2761L7.01404 3.77296C5.68077 2.98869 4 3.95 4 5.49683Z" stroke="#323232" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
|
@@ -234,7 +234,7 @@ https://polotno.com/docs/server-api`,lR={unsplashList:({query:e,page:t=1})=>`${l
|
|
|
234
234
|
font-weight: ${l};
|
|
235
235
|
src: url(${n});
|
|
236
236
|
}`}));return sv("style",{},o.join("\n"))}catch(e){return console.error("Error embedding Google Font:",e),sv("defs",{},sv("style",{type:"text/css",innerHTML:`@import url('${t}');`.replace(/&/g,"&")}))}}}))}async function sk({json:e,elementHook:t}){let n=await Promise.all(e.pages.map(n=>s_({page:n,store:e,elementHook:t}))),r=[];sm({children:e.pages},e=>{"text"===e.type&&-1===r.indexOf(e.fontFamily)&&r.push(e.fontFamily)});let i=await sE(r,e.fonts);return sv("svg",{xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink",viewBox:`0 0 ${e.width} ${e.height}`,width:e.width,height:e.height},...i,...n)}let sO=(e,t)=>"object"==typeof t?`${e}="${Object.keys(t).map(e=>`${e}:${t[e]};`).join(" ")}"`:null==t||""===t?"":`${e}="${t}"`,sP=({dom:e,nestLevel:t=0})=>{if("string"==typeof e)return e;if(!e)return"";let{innerHTML:n,...r}=e.props,i=" ".repeat(t);return`${i}<${e.type} ${Object.keys(r).map(e=>sO(e,r[e])).join(" ")}>${n||"\n"+e.children.map(e=>sP({dom:e,nestLevel:t+1})).join("")}${i}</${e.type}>
|
|
237
|
-
`};async function sT({json:e,elementHook:t}){return sP({dom:await sk({json:e,elementHook:t})})}var iq=v("58B0H");let sA=(0,iq.types).model("Page",{id:iq.types.identifier,children:(0,iq.types).array((0,iq.types).late(()=>sJ)),width:(0,iq.types).optional((0,iq.types).union(iq.types.number,(0,iq.types).literal("auto")),"auto"),height:(0,iq.types).optional((0,iq.types).union(iq.types.number,(0,iq.types).literal("auto")),"auto"),background:"white",bleed:0,custom:(0,iq.types).frozen(),duration:5e3,_exporting:!1,_rendering:!1,_forceMount:!1}).postProcessSnapshot(e=>{let t={...e},n={};for(var r in t)"_"!==r[0]&&(n[r]=e[r]);return n}).views(e=>({get store(){return(0,iq.getParentOfType)(e,sR)}})).views(e=>({get startTime(){let t=0;for(let n of e.store.pages){if(n.id===e.id)break;t+=n.duration}return t},get _exportingOrRendering(){return e._exporting||e._rendering}})).views(e=>({get computedWidth(){if("auto"===e.width)return e.store.width;return e.width},get computedHeight(){if("auto"===e.height)return e.store.height;return e.height}})).actions(e=>({toJSON:()=>JSON.parse(JSON.stringify((0,iq.getSnapshot)(e))),_forEachElementUp(t,n){let r=t.map(t=>({id:t,index:e.children.findIndex(e=>e.id===t)}));for(let{index:i}of(r.sort((e,t)=>t.index-e.index),r)){if(-1==i)continue;let r=i<e.children.length-1&&e.children[i+1],o=t.indexOf(r?.id)>=0;i===e.children.length-1||o||n(i)}},_forEachElementDown(t,n){let r=t.map(t=>({id:t,index:e.children.findIndex(e=>e.id===t)}));for(let{index:i}of(r.sort((e,t)=>e.index-t.index),r)){if(-1==i)continue;let r=i>0&&e.children[i-1],o=t.indexOf(r?.id)>=0;0===i||o||n(i)}return!1}})).actions(e=>({clone(t={}){let n=e.toJSON();n.children.forEach(e=>{e.id=lw(10),sZ(e,e=>{e.id=lw(10)})});let r={...n,id:lw(10),...t},i=e.store.addPage(r),o=e.store.pages.indexOf(e);return i.setZIndex(o+1),i.select(),i},setZIndex(t){e.store.setPageZIndex(e.id,t)},set(t){Object.assign(e,t)},select(){e.store.selectPage(e.id)},addElement(t,{skipSelect:n=!1}={}){let r=s2[t.type];if(!r){console.error("Can not find model with type "+t.type);return}"children"in t&&Array.isArray(t.children)&&sZ(t,e=>{e.id=e.id||lw(10)});let i=r.create({id:lw(10),...t});return e.children.push(i),i.selectable&&!n&&e.store.selectElements([i.id]),i},canMoveElementsUp(t){let n=!1;return e._forEachElementUp(t,()=>{n=n||!0}),n},moveElementsUp(t){e._forEachElementUp(t,t=>{let n=e.children[t];(0,iq.detach)(n),e.children.splice(t+1,0,n)})},canMoveElementsTop(e){return this.canMoveElementsUp(e)},moveElementsTop(t){let n=[],r=[];e.children.forEach(e=>{t.indexOf(e.id)>=0?n.push(e):r.push(e)}),e.children.replace(r.concat(n))},canMoveElementsDown(t){let n=!1;return e._forEachElementDown(t,()=>{n=n||!0}),n},moveElementsDown(t){e._forEachElementDown(t,t=>{let n=e.children[t];(0,iq.detach)(n),e.children.splice(t-1,0,n)})},canMoveElementsBottom(e){return this.canMoveElementsDown(e)},moveElementsBottom(t){let n=[],r=[];e.children.forEach(e=>{t.indexOf(e.id)>=0?n.push(e):r.push(e)}),e.children.replace(n.concat(r))},setElementZIndex(t,n){let r=e.children.find(e=>e.id===t);r&&((0,iq.detach)(r),e.children.remove(r),e.children.splice(n,0,r))},setSize({width:t,height:n,useMagic:r,softChange:i}){if(r){let r=[],i=t=>"image"===t.type&&t.x<1&&t.y<1&&t.width>=e.computedWidth-2&&t.height>=e.computedHeight-2;sZ(e,e=>{"group"!==e.type&&(i(e)||r.push(e))});let o=r.length?aF(r):{x:0,y:0,width:e.computedWidth,height:e.computedHeight},a=1/4,l=Math.max(0,Math.max(0,Math.min(o.x,e.computedWidth-o.x-o.width))-e.computedWidth*a),s=Math.max(0,Math.max(0,Math.min(o.y,e.computedHeight-o.y-o.height))-e.computedHeight*a),u=e.computedWidth-2*l,c=e.computedHeight-2*s,d=t/u,h=n/c,f=Math.min(d,h),p=(t-u*f)/2-l*f,g=(n-c*f)/2-s*f;sZ(e,e=>{"group"!==e.type&&(i(e)?e.set({x:e.x*f,y:e.y*f,width:e.width*d,height:e.height*h,cropX:0,cropY:0,cropWidth:1,cropHeight:1}):(e.set({x:p+e.x*f,y:g+e.y*f,width:e.width*f,height:e.height*f}),"text"===e.type?e.set({fontSize:e.fontSize*f}):"figure"===e.type&&e.set({strokeWidth:e.strokeWidth*f})))})}i||(e.width=t),i||(e.height=n)}})).actions(e=>({moveElementUp(t){console.warn("page.moveElementUp(id) is deprecated. Please use page.moveElementsUp([id1, id2]) instead."),e.moveElementsUp([t])},moveElementDown(t){console.warn("page.moveElementDown(id) is deprecated. Please use page.moveElementsDown([id1, id2]) instead."),e.moveElementsDown([t])},moveElementTop(t){console.warn("page.moveElementTop(id) is deprecated. Please use page.moveElementsTop([id1, id2]) instead."),e.moveElementsTop([t])},moveElementBottom(t){console.warn("page.moveElementBottom(id) is deprecated. Please use page.moveElementsBottom([id1, id2]) instead."),e.moveElementsBottom([t])},play(){e.store.play({startTime:e.startTime,endTime:e.startTime+e.duration})}}));var iq=v("58B0H");let sj=(0,iq.types).model("Audio",{id:iq.types.identifier,src:"",duration:0,startTime:0,endTime:1,volume:1,delay:0}).actions(e=>({toJSON:()=>({...(0,iq.getSnapshot)(e)})})).actions(e=>({set(t){Object.assign(e,t)}}));(0,iq.setLivelinessChecking)("ignore");let sN=(0,iq.types).model("Font",{fontFamily:iq.types.string,url:(0,iq.types).optional(iq.types.string,""),styles:(0,iq.types).frozen()}).preProcessSnapshot(e=>({...e,fontFamily:e.fontFamily||e.name})),sR=(0,iq.types).model("Store",{role:"",pages:(0,iq.types).array(sA),fonts:(0,iq.types).array(sN),audios:(0,iq.types).array(sj),width:1080,height:1080,currentTime:0,isPlaying:!1,scale:1,scaleToFit:1,unit:"px",dpi:72,schemaVersion:1,bleedVisible:!1,rulesVisible:!1,openedSidePanel:"",previousOpenedSidePanel:"",custom:(0,iq.types).frozen(),selectedElementsIds:(0,iq.types).array(iq.types.string),animatedElementsIds:(0,iq.types).array(iq.types.string),history:(0,iq.types).optional(l_,{targetPath:"../pages"}),_elementsPixelRatio:Math.min(2,window.devicePixelRatio||1),_activePageId:"",_forceShowCredit:!1,_key:"",_validated:!1}).views(e=>({get _bleedVisible(){return console.warn("store._bleedVisible is deprecated. Please use store.bleedVisible instead."),e.bleedVisible},get selectedElements(){return e.selectedElementsIds.map(t=>{for(let n of e.pages)for(let e of n.children)if(e.id===t)return e}).filter(e=>!!e)},get children(){return e.pages},get selectedShapes(){let t=[];return sZ({children:e.selectedElements},e=>{"group"!==e.type&&t.push(e)}),t},get activePage(){return e.pages.slice().find(t=>t.id===e._activePageId)||(e.pages.length?e.pages[0]:null)},get duration(){let t=0;return e.pages.forEach(e=>{t+=e.duration}),t},get _hasCroppedImages(){return e.find(e=>"image"===e.type&&e._cropModeEnabled)},find(t){let n;return sZ({children:e.pages},e=>{if(!n&&t(e))return n=e,!0}),n},getElementById:t=>e.find(e=>e.id===t)})).actions(e=>{let t=0,n=null,r=!1;return{afterCreate(){e.history.canUndo},setCurrentTime(t){e.currentTime=t},_togglePlaying(t=!e.isPlaying){e.isPlaying=t},play({animatedElementsIds:i=[],startTime:o=0,currentTime:a=0,endTime:l=e.duration,repeat:s=!1}={}){a&&(console.warn("currentTime property of store.play() is deprecated. Please use startTime instead."),o=a),e.animatedElementsIds=(0,iq.cast)(i),e.currentTime=o,e.isPlaying=!0,t=Date.now(),n=l,r=s,requestAnimationFrame(e.seek)},checkActivePage(){for(let t of e.pages){if(e.currentTime>=t.startTime&&e.currentTime<t.startTime+t.duration){e.selectPage(t.id);break}t.duration}},seek(){if(!e.isPlaying)return;let i=Date.now(),o=i-t;t=i,e.currentTime+=o,e.checkActivePage();let a=n||e.duration;e.isPlaying&&e.currentTime<a?requestAnimationFrame(e.seek):e.isPlaying&&r?(e.currentTime=0,requestAnimationFrame(e.seek)):e.stop()},stop(){e.isPlaying=!1,e.currentTime=0,e.animatedElementsIds=(0,iq.cast)([]),e.checkActivePage()}}}).actions(e=>({__(){e._validated||(l0(e._key,e._forceShowCredit),e._validated=!0)},set(t){Object.assign(e,t)},setUnit({unit:t,dpi:n}){e.unit=t||e.unit,e.dpi=n||e.dpi},setRole(t){e.role=t},addPage(t){let n=sA.create({id:lw(10),...t});return e.pages.push(n),e._activePageId=n.id,n},selectPage(t){e._activePageId=t},selectElements(t){let n=t.map(t=>e.getElementById(t)).sort((e,t)=>e.page.children.indexOf(e)-e.page.children.indexOf(t)).filter(e=>!!e).map(e=>e.id);e.selectedElementsIds=(0,iq.cast)(n)},toggleBleed(t){e.bleedVisible=t??!e.bleedVisible},toggleRulers(t){e.rulesVisible=t??!e.rulesVisible},openSidePanel(t){e.openedSidePanel!==t&&(e.previousOpenedSidePanel=e.openedSidePanel,e.openedSidePanel=t)},setScale(t){e.scale=t},_setScaleToFit(t){e.scaleToFit=t},setElementsPixelRatio(t){e._elementsPixelRatio=t},setSize(t,n,r){e.pages.forEach(e=>{e.setSize({width:t,height:n,useMagic:r,softChange:!0})}),e.width=t,e.height=n},setPageZIndex(t,n){let r=e.pages.find(e=>e.id===t);r&&((0,iq.detach)(r),e.pages.remove(r),e.pages.splice(n,0,r))},deletePages(t){let n=e.pages.indexOf(e.activePage);t.forEach(t=>{let n=e.pages.find(e=>e.id===t);(0,iq.destroy)(n)});let r=Math.min(e.pages.length-1,n),i=e.pages[r];i&&(e._activePageId=i.id),e.selectedElementsIds=(0,iq.cast)(e.selectedElementsIds.filter(t=>e.getElementById(t)))},groupElements(t,n={}){let r=t.map(t=>e.getElementById(t)),i=r[0].page;if(r.forEach(e=>{e&&(0,iq.detach)(e)}),!r.length)return;let o={id:lw(10),children:r,type:"group",...n};return i.children.push(o),e.selectedElementsIds=(0,iq.cast)([o.id]),i.children.find(e=>e.id===o.id)},ungroupElements(t){let n=t.map(t=>e.getElementById(t)),r=[];n.forEach(e=>{if(e&&"group"===e.type){let t=e.page,n=t.children.indexOf(e);e.children.forEach(e=>{r.push(e.id)}),e.children.forEach(e=>{(0,iq.detach)(e),t.children.push(e)}),t.children.splice(n,1)}}),e.selectedElementsIds=(0,iq.cast)(r)},deleteElements(t){let n=[];e.find(e=>(t.includes(e.id)&&n.push(e),!1)),n.forEach(e=>{(0,iq.destroy)(e)}),e.selectedElementsIds=(0,iq.cast)(e.selectedElementsIds.filter(t=>e.getElementById(t)))},on(t,n){if("change"===t){let t=e.toJSON();return(0,iq.onSnapshot)(e,r=>{let i=e.toJSON();lC(t,i)||(t=i,n(i))})}},async _toCanvas({pixelRatio:t,ignoreBackground:n,pageId:r,mimeType:i,includeBleed:o,_skipTimeout:a,quickMode:l=!1}={}){let s=t||1;r=r||e.pages[0]?.id;let u=e.pages.find(e=>e.id===r);if(!u)throw Error(`No page for export with id ${r}`);l?u?.set({_forceMount:!0}):u?.set({_exporting:!0});let c=await l8(()=>h(M).stages.find(e=>e.getAttr("pageId")===r));if(!c)throw u?.set({_forceMount:!1,_exporting:!1}),Error(`Export is failed. Can not find stage for page ${r}. Looks like <Workspace /> component is not mounted, but it is required in order to process the export.`);let d=e._elementsPixelRatio;s>e._elementsPixelRatio&&e.setElementsPixelRatio(s),await e.waitLoading({_skipTimeout:a});let f=c.findOne(".page-container");if(!f)throw e.setElementsPixelRatio(d),u?.set({_forceMount:!1,_exporting:!1}),Error("Export is failed. Canvas was unmounted.");let p=c.position();c.position({x:0,y:0}),c.find("Transformer").forEach(e=>{e.setAttr("oldVisible",e.visible()),e.visible(!1)}),f.find(".page-background").forEach(e=>e.shadowEnabled(!1)),f.find(".page-background").forEach(e=>e.strokeEnabled(!1)),f.find(".highlighter").forEach(e=>e.visible(!1));let g=f.findOne(".page-background-group"),m=g.clip();g.clip({x:null,y:null,width:null,height:null});let v=f.findOne(".elements-container"),y=v.clip();v.clip({x:null,y:null,width:null,height:null});let b=f.find(e=>e.getAttr("hideInExport"));b.forEach(e=>{e.setAttr("oldVisible",e.visible()),e.hide()});let x=f.find(e=>!e.visible()&&e.getAttr("editModeEnabled"));x.forEach(e=>{e.setAttr("oldVisible",e.visible()),e.show()}),n&&f.find(".page-background").forEach(e=>e.hide());let w=o?u.bleed:0,C=w;!e.bleedVisible&&o||(e.bleedVisible||o?e.bleedVisible&&o?C=0:e.bleedVisible&&!o&&(C=-u.bleed):C=0);let _=document.createElement("canvas");_.width=Math.round((u.computedWidth+2*w)*s),_.height=Math.round((u.computedHeight+2*w)*s);let S=_.getContext("2d");"image/jpeg"===i&&(S.fillStyle="white",S.fillRect(0,0,_.width,_.height));let E=f.scale();f.scale({x:1,y:1});let k=f.toCanvas({x:f.x()-C,y:f.y()-C,width:u.computedWidth+2*w,height:u.computedHeight+2*w,pixelRatio:s});return f.scale(E),S.drawImage(k,0,0,_.width,_.height),h(M).Util.releaseCanvas(k),n&&f.find(".page-background").forEach(e=>e.show()),b.forEach(e=>{e.visible(e.getAttr("oldVisible"))}),x.forEach(e=>{e.visible(e.getAttr("oldVisible"))}),f.find(".page-background").forEach(e=>e.shadowEnabled(!0)),f.find(".page-background").forEach(e=>e.strokeEnabled(!0)),c.find("Transformer").forEach(e=>{e.visible(e.getAttr("oldVisible"))}),f.find(".highlighter").forEach(e=>e.visible(!0)),g.clip(m),v.clip(y),c.position(p),e.setElementsPixelRatio(d),u?.set({_exporting:!1,_forceMount:!1}),_},async toDataURL({mimeType:t,quality:n,...r}={}){let i=await e._toCanvas({mimeType:t,...r}),o=i.toDataURL(t,n);return h(M).Util.releaseCanvas(i),o},async toBlob({mimeType:t,quality:n,...r}={}){let i=await e._toCanvas({mimeType:t,...r}),o=await new Promise(e=>{i.toBlob(e,t,n)});return h(M).Util.releaseCanvas(i),o},async saveAsImage({fileName:t,...n}={}){let r=n.mimeType||"image/png",i=r.split("/")[1];lS(await e.toDataURL(n),t||"polotno."+i,r)},async _toPDF(t){let n=t.dpi||e.dpi,r=t.parallel||1,i=t.unit||("px"===e.unit?"mm":e.unit),o=t.pixelRatio||1,a=t.pageIds||e.pages.map(e=>e.id),l=e.pages.filter(e=>a.includes(e.id)),s=await (window.jspdf?.jsPDF?Promise.resolve(window.jspdf.jsPDF):lE||(lE=new Promise(e=>{var t=document.createElement("script");t.onload=function(){e(window.jspdf.jsPDF)},t.src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/3.0.1/jspdf.umd.min.js",document.head.appendChild(t)}))),u=e=>l1({px:e,unit:i,dpi:n}),c=t.cropMarkSize||0,d=u(c),h=l[0]||{},f=t.includeBleed?h.bleed:0,p=u(h.computedWidth+2*f+2*d),g=u(h.computedHeight+2*f+2*d);var m=new s({unit:i,orientation:p>g?"landscape":"portrait",format:[p,g],compress:!0,putOnlyUsedFonts:!0});m.deletePage(1);let v=((e,t)=>{for(var n=[],r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n})(l,r),y=0;for(let n of v){let r=n.map(async n=>{let r=t.includeBleed?n.bleed:0,i=n.computedWidth+2*r+2*c,l=n.computedHeight+2*r+2*c,s=u(i),d=u(l),h=0,f=o;for(;h<10;){2===(h+=1)&&console.error("Polotno can not export PDF with current settings. Quality is automatically reduced.");let r=await e.toDataURL({...t,pageId:n.id,pixelRatio:f});if(r.length>20)return t.onProgress&&t.onProgress(++y/a.length*.9),{url:r,width:s,height:d,widthPx:i,heightPx:l};f*=.8}});(await Promise.all(r)).forEach(({url:e,width:t,height:n,widthPx:r,heightPx:o})=>{var a;m.addPage([t,n],t>n?"landscape":"portrait");let l=m.getCurrentPageInfo();switch(i){case"pt":a=1;break;case"mm":a=72/25.4;break;case"cm":a=72/2.54;break;case"in":a=72;break;case"px":a=.75;break;case"pc":case"em":a=12;break;case"ex":a=6;break;default:throw"Invalid unit: "+i}if(l.pageContext.cropBox={bottomLeftX:0,bottomLeftY:0,topRightX:t*a,topRightY:n*a},l.pageContext.artBox={bottomLeftX:u(c+f)*a,bottomLeftY:u(c+f)*a,topRightX:u(r-c-f)*a,topRightY:u(o-c-f)*a},l.pageContext.bleedBox={bottomLeftX:u(c+f)*a,bottomLeftY:u(c+f)*a,topRightX:u(r-c-f)*a,topRightY:u(o-c-f)*a},d){m.setLineWidth(u(1));let e=d+u(f);m.line(e,0,e,d),m.line(0,e,d,e),m.line(t-e,0,t-e,d),m.line(t,e,t-d,e),m.line(0,n-e,d,n-e),m.line(e,n,e,n-d),m.line(t,n-e,t-d,n-e),m.line(t-e,n,t-e,n-d)}m.addImage(e,d,d,t-2*d,n-2*d,void 0,"FAST")})}return m},toPDFDataURL:async t=>(await e._toPDF({mimeType:"image/jpeg",...t})).output("datauristring"),async toGIFDataURL(t={}){let n=t.pixelRatio||1,r=await lk({width:e.width*n,height:e.height*n}),i=1e3/(t.fps||10),o=e.duration/i;for(let t=0;t<o-1;t++){let o=t*i||1;e.setCurrentTime(o);let a=0,l="";for(let t of e.pages)if(a+=t.duration,t.set({_rendering:a>o}),a>o){l=t.id;break}let s=await e._toCanvas({pixelRatio:n,pageId:l,_skipTimeout:!0});r.addFrame(s.getContext("2d"),{delay:i,copy:!0})}for(let t of e.pages)t.set({_rendering:!1});return e.stop(),r.render(),new Promise(e=>{r.on("finished",function(t){var n;(n=new FileReader).onload=function(t){e(t.target.result)},n.readAsDataURL(t)})})},async saveAsGIF({fileName:t,...n}={}){lS(await e.toGIFDataURL(n),t||"polotno.gif")},toHTML:async({elementHook:t}={elementHook:void 0})=>sg({json:e.toJSON(),elementHook:t}),async saveAsHTML({fileName:t}={}){let n=await e.toHTML();lS("data:text/html;base64,"+window.btoa(unescape(encodeURIComponent(n))),t||"polotno.html")},async toSVG({elementHook:t,pageId:n}={elementHook:void 0,pageId:void 0}){let r=e.toJSON();n=n||r.pages[0]?.id;let i=r.pages.find(e=>e.id===n);return sT({json:{...r,pages:i?[i]:[]},elementHook:t})},async saveAsSVG({fileName:t,elementHook:n,pageId:r}={}){let i=await e.toSVG({elementHook:n,pageId:r});lS("data:text/svg;base64,"+window.btoa(unescape(encodeURIComponent(i))),t||"polotno.svg")},async saveAsPDF({fileName:t,...n}={}){(await e._toPDF({mimeType:"image/jpeg",...n})).save(t||"polotno.pdf")},async waitLoading({_skipTimeout:e=!1}={}){e||await new Promise(e=>setTimeout(e,50)),await new Promise(e=>{var t;return t=()=>{ih()?setTimeout(e,300):e(!0)},void(0===ig?t():im.push(t))})},toJSON:()=>({width:e.width,height:e.height,fonts:(0,iq.getSnapshot)(e.fonts),pages:(0,iq.getSnapshot)(e.pages),audios:(0,iq.getSnapshot)(e.audios),unit:e.unit,dpi:e.dpi,custom:e.custom,schemaVersion:e.schemaVersion}),loadJSON(t,n=!1){let r={...t};void 0===r.schemaVersion&&iM.htmlRenderEnabled&&sZ({children:r.pages},e=>{if("text"===e.type){let t=16*e.letterSpacing;e.letterSpacing=t/e.fontSize}});let i=e.pages.indexOf(e.activePage),o=(r.pages[i]||r.pages[0])?.id;r._activePageId=o;let a={...(0,iq.getSnapshot)(e)};Object.assign(a,r),n?a.history=e.history.toJSON():a.history={history:[],undoIdx:-1},(0,iq.applySnapshot)(e,a)},clear({keepHistory:t=!1}={}){let n=e.pages.map(e=>e.id);e.deletePages(n),e.custom=null,t||e.history.clear()},addFont(t){e.removeFont(t.fontFamily),e.fonts.push(t),e.loadFont(t.fontFamily)},removeFont(t){e.fonts.filter(e=>e.fontFamily===t).forEach(e=>(0,iq.destroy)(e))},addAudio(t){let n=sj.create({id:lw(10),...t});e.audios.push(n)},removeAudio(t){let n=e.audios.find(e=>e.id===t);n&&e.audios.remove(n)},async loadFont(t){let n=e.fonts.find(e=>e.fontFamily===t)||iE.find(e=>e.fontFamily===t),r=[{fontStyle:"normal",fontWeight:"normal"}];return n?(n.styles&&(r=n.styles.map(e=>({fontStyle:e.fontStyle||"normal",fontWeight:e.fontWeight||"normal"}))),function(e){let t=e.fontFamily;if(iL[t]||!e.url&&!e.styles)return;let n=document.createElement("style");n.type="text/css";let r=e.styles||(e.url?[{src:`url("${e.url}")`}]:[]),i="";r.forEach(e=>{i+=`
|
|
237
|
+
`};async function sT({json:e,elementHook:t}){return sP({dom:await sk({json:e,elementHook:t})})}var iq=v("58B0H");let sA=(0,iq.types).model("Page",{id:iq.types.identifier,children:(0,iq.types).array((0,iq.types).late(()=>sJ)),width:(0,iq.types).optional((0,iq.types).union(iq.types.number,(0,iq.types).literal("auto")),"auto"),height:(0,iq.types).optional((0,iq.types).union(iq.types.number,(0,iq.types).literal("auto")),"auto"),background:"white",bleed:0,custom:(0,iq.types).frozen(),duration:5e3,_exporting:!1,_rendering:!1,_forceMount:!1}).postProcessSnapshot(e=>{let t={...e},n={};for(var r in t)"_"!==r[0]&&(n[r]=e[r]);return n}).views(e=>({get store(){return(0,iq.getParentOfType)(e,sR)}})).views(e=>({get startTime(){let t=0;for(let n of e.store.pages){if(n.id===e.id)break;t+=n.duration}return t},get _exportingOrRendering(){return e._exporting||e._rendering}})).views(e=>({get computedWidth(){if("auto"===e.width)return e.store.width;return e.width},get computedHeight(){if("auto"===e.height)return e.store.height;return e.height}})).actions(e=>({toJSON:()=>JSON.parse(JSON.stringify((0,iq.getSnapshot)(e))),_forEachElementUp(t,n){let r=t.map(t=>({id:t,index:e.children.findIndex(e=>e.id===t)}));for(let{index:i}of(r.sort((e,t)=>t.index-e.index),r)){if(-1==i)continue;let r=i<e.children.length-1&&e.children[i+1],o=t.indexOf(r?.id)>=0;i===e.children.length-1||o||n(i)}},_forEachElementDown(t,n){let r=t.map(t=>({id:t,index:e.children.findIndex(e=>e.id===t)}));for(let{index:i}of(r.sort((e,t)=>e.index-t.index),r)){if(-1==i)continue;let r=i>0&&e.children[i-1],o=t.indexOf(r?.id)>=0;0===i||o||n(i)}return!1}})).actions(e=>({clone(t={}){let n=e.toJSON();n.children.forEach(e=>{e.id=lw(10),sZ(e,e=>{e.id=lw(10)})});let r={...n,id:lw(10),...t},i=e.store.addPage(r),o=e.store.pages.indexOf(e);return i.setZIndex(o+1),i.select(),i},setZIndex(t){e.store.setPageZIndex(e.id,t)},set(t){Object.assign(e,t)},select(){e.store.selectPage(e.id)},addElement(t,{skipSelect:n=!1}={}){let r=s2[t.type];if(!r){console.error("Can not find model with type "+t.type);return}"children"in t&&Array.isArray(t.children)&&sZ(t,e=>{e.id=e.id||lw(10)});let i=r.create({id:lw(10),...t});return e.children.push(i),i.selectable&&!n&&e.store.selectElements([i.id]),i},canMoveElementsUp(t){let n=!1;return e._forEachElementUp(t,()=>{n=n||!0}),n},moveElementsUp(t){e._forEachElementUp(t,t=>{let n=e.children[t];(0,iq.detach)(n),e.children.splice(t+1,0,n)})},canMoveElementsTop(e){return this.canMoveElementsUp(e)},moveElementsTop(t){let n=[],r=[];e.children.forEach(e=>{t.indexOf(e.id)>=0?n.push(e):r.push(e)}),e.children.replace(r.concat(n))},canMoveElementsDown(t){let n=!1;return e._forEachElementDown(t,()=>{n=n||!0}),n},moveElementsDown(t){e._forEachElementDown(t,t=>{let n=e.children[t];(0,iq.detach)(n),e.children.splice(t-1,0,n)})},canMoveElementsBottom(e){return this.canMoveElementsDown(e)},moveElementsBottom(t){let n=[],r=[];e.children.forEach(e=>{t.indexOf(e.id)>=0?n.push(e):r.push(e)}),e.children.replace(n.concat(r))},setElementZIndex(t,n){let r=e.children.find(e=>e.id===t);r&&((0,iq.detach)(r),e.children.remove(r),e.children.splice(n,0,r))},setSize({width:t,height:n,useMagic:r,softChange:i}){if(r){let r=[],i=t=>"image"===t.type&&t.x<1&&t.y<1&&t.width>=e.computedWidth-2&&t.height>=e.computedHeight-2;sZ(e,e=>{"group"!==e.type&&(i(e)||r.push(e))});let o=r.length?aF(r):{x:0,y:0,width:e.computedWidth,height:e.computedHeight},a=1/4,l=Math.max(0,Math.max(0,Math.min(o.x,e.computedWidth-o.x-o.width))-e.computedWidth*a),s=Math.max(0,Math.max(0,Math.min(o.y,e.computedHeight-o.y-o.height))-e.computedHeight*a),u=e.computedWidth-2*l,c=e.computedHeight-2*s,d=t/u,h=n/c,f=Math.min(d,h),p=(t-u*f)/2-l*f,g=(n-c*f)/2-s*f;sZ(e,e=>{"group"!==e.type&&(i(e)?e.set({x:e.x*f,y:e.y*f,width:e.width*d,height:e.height*h,cropX:0,cropY:0,cropWidth:1,cropHeight:1}):(e.set({x:p+e.x*f,y:g+e.y*f,width:e.width*f,height:e.height*f}),"text"===e.type?e.set({fontSize:e.fontSize*f}):"figure"===e.type&&e.set({strokeWidth:e.strokeWidth*f})))})}i||(e.width=t),i||(e.height=n)}})).actions(e=>({moveElementUp(t){console.warn("page.moveElementUp(id) is deprecated. Please use page.moveElementsUp([id1, id2]) instead."),e.moveElementsUp([t])},moveElementDown(t){console.warn("page.moveElementDown(id) is deprecated. Please use page.moveElementsDown([id1, id2]) instead."),e.moveElementsDown([t])},moveElementTop(t){console.warn("page.moveElementTop(id) is deprecated. Please use page.moveElementsTop([id1, id2]) instead."),e.moveElementsTop([t])},moveElementBottom(t){console.warn("page.moveElementBottom(id) is deprecated. Please use page.moveElementsBottom([id1, id2]) instead."),e.moveElementsBottom([t])},play(){e.store.play({startTime:e.startTime,endTime:e.startTime+e.duration})}}));var iq=v("58B0H");let sj=(0,iq.types).model("Audio",{id:iq.types.identifier,src:"",duration:0,startTime:0,endTime:1,volume:1,delay:0}).actions(e=>({toJSON:()=>({...(0,iq.getSnapshot)(e)})})).actions(e=>({set(t){Object.assign(e,t)}}));(0,iq.setLivelinessChecking)("ignore");let sN=(0,iq.types).model("Font",{fontFamily:iq.types.string,url:(0,iq.types).optional(iq.types.string,""),styles:(0,iq.types).frozen()}).preProcessSnapshot(e=>({...e,fontFamily:e.fontFamily||e.name})),sR=(0,iq.types).model("Store",{role:"",pages:(0,iq.types).array(sA),fonts:(0,iq.types).array(sN),audios:(0,iq.types).array(sj),width:1080,height:1080,currentTime:0,isPlaying:!1,scale:1,scaleToFit:1,unit:"px",dpi:72,schemaVersion:1,bleedVisible:!1,rulesVisible:!1,openedSidePanel:"",previousOpenedSidePanel:"",custom:(0,iq.types).frozen(),selectedElementsIds:(0,iq.types).array(iq.types.string),animatedElementsIds:(0,iq.types).array(iq.types.string),history:(0,iq.types).optional(l_,{targetPath:"../pages"}),_elementsPixelRatio:Math.min(2,window.devicePixelRatio||1),_activePageId:"",_forceShowCredit:!1,_key:"",_validated:!1}).views(e=>({get _bleedVisible(){return console.warn("store._bleedVisible is deprecated. Please use store.bleedVisible instead."),e.bleedVisible},get selectedElements(){return e.selectedElementsIds.map(t=>{for(let n of e.pages)for(let e of n.children)if(e.id===t)return e}).filter(e=>!!e)},get children(){return e.pages},get selectedShapes(){let t=[];return sZ({children:e.selectedElements},e=>{"group"!==e.type&&t.push(e)}),t},get activePage(){return e.pages.slice().find(t=>t.id===e._activePageId)||(e.pages.length?e.pages[0]:null)},get duration(){let t=0;return e.pages.forEach(e=>{t+=e.duration}),t},get _hasCroppedImages(){return e.find(e=>"image"===e.type&&e._cropModeEnabled)},find(t){let n;return sZ({children:e.pages},e=>{if(!n&&t(e))return n=e,!0}),n},getElementById:t=>e.find(e=>e.id===t)})).actions(e=>{let t=0,n=null,r=!1;return{afterCreate(){e.history.canUndo},setCurrentTime(t){e.currentTime=t},_togglePlaying(t=!e.isPlaying){e.isPlaying=t},play({animatedElementsIds:i=[],startTime:o=0,currentTime:a=0,endTime:l=e.duration,repeat:s=!1}={}){a&&(console.warn("currentTime property of store.play() is deprecated. Please use startTime instead."),o=a),e.animatedElementsIds=(0,iq.cast)(i),e.currentTime=o,e.isPlaying=!0,t=Date.now(),n=l,r=s,requestAnimationFrame(e.seek)},checkActivePage(){for(let t of e.pages){if(e.currentTime>=t.startTime&&e.currentTime<t.startTime+t.duration){e.selectPage(t.id);break}t.duration}},seek(){if(!e.isPlaying)return;let i=Date.now(),o=i-t;t=i,e.currentTime+=o,e.checkActivePage();let a=n||e.duration;e.isPlaying&&e.currentTime<a?requestAnimationFrame(e.seek):e.isPlaying&&r?(e.currentTime=0,requestAnimationFrame(e.seek)):e.stop()},stop(){e.isPlaying=!1,e.currentTime=0,e.animatedElementsIds=(0,iq.cast)([]),e.checkActivePage()}}}).actions(e=>({__(){e._validated||(l0(e._key,e._forceShowCredit),e._validated=!0)},set(t){Object.assign(e,t)},setUnit({unit:t,dpi:n}){e.unit=t||e.unit,e.dpi=n||e.dpi},setRole(t){e.role=t},addPage(t){let n=sA.create({id:lw(10),...t});return e.pages.push(n),e._activePageId=n.id,n},selectPage(t){e._activePageId=t},selectElements(t){let n=t.map(t=>e.getElementById(t)).sort((e,t)=>e.page.children.indexOf(e)-e.page.children.indexOf(t)).filter(e=>!!e).map(e=>e.id);e.selectedElementsIds=(0,iq.cast)(n)},toggleBleed(t){e.bleedVisible=t??!e.bleedVisible},toggleRulers(t){e.rulesVisible=t??!e.rulesVisible},openSidePanel(t){e.openedSidePanel!==t&&(e.previousOpenedSidePanel=e.openedSidePanel,e.openedSidePanel=t)},setScale(t){e.scale=t},_setScaleToFit(t){e.scaleToFit=t},setElementsPixelRatio(t){e._elementsPixelRatio=t},setSize(t,n,r){e.pages.forEach(e=>{e.setSize({width:t,height:n,useMagic:r,softChange:!0})}),e.width=t,e.height=n},setPageZIndex(t,n){let r=e.pages.find(e=>e.id===t);r&&((0,iq.detach)(r),e.pages.remove(r),e.pages.splice(n,0,r))},deletePages(t){let n=e.pages.indexOf(e.activePage);t.forEach(t=>{let n=e.pages.find(e=>e.id===t);(0,iq.destroy)(n)});let r=Math.min(e.pages.length-1,n),i=e.pages[r];i&&(e._activePageId=i.id),e.selectedElementsIds=(0,iq.cast)(e.selectedElementsIds.filter(t=>e.getElementById(t)))},groupElements(t,n={}){let r=t.map(t=>e.getElementById(t)),i=r[0].page;if(r.forEach(e=>{e&&(0,iq.detach)(e)}),!r.length)return;let o={id:lw(10),children:r,type:"group",...n};return i.children.push(o),e.selectedElementsIds=(0,iq.cast)([o.id]),i.children.find(e=>e.id===o.id)},ungroupElements(t){let n=t.map(t=>e.getElementById(t)),r=[];n.forEach(e=>{if(e&&"group"===e.type){let t=e.page,n=t.children.indexOf(e);e.children.forEach(e=>{r.push(e.id)}),e.children.forEach(e=>{(0,iq.detach)(e),t.children.push(e)}),t.children.splice(n,1)}}),e.selectedElementsIds=(0,iq.cast)(r)},deleteElements(t){let n=[];e.find(e=>(t.includes(e.id)&&n.push(e),!1)),n.forEach(e=>{(0,iq.destroy)(e)}),e.selectedElementsIds=(0,iq.cast)(e.selectedElementsIds.filter(t=>e.getElementById(t)))},on(t,n){if("change"===t){let t=e.toJSON();return(0,iq.onSnapshot)(e,r=>{let i=e.toJSON();lC(t,i)||(t=i,n(i))})}},async _toCanvas({pixelRatio:t,ignoreBackground:n,pageId:r,mimeType:i,includeBleed:o,_skipTimeout:a,quickMode:l=!1}={}){let s=t||1;r=r||e.pages[0]?.id;let u=e.pages.find(e=>e.id===r);if(!u)throw Error(`No page for export with id ${r}`);let c=e._elementsPixelRatio;s>e._elementsPixelRatio&&e.setElementsPixelRatio(s),l?u?.set({_forceMount:!0}):u?.set({_exporting:!0});let d=await l8(()=>h(M).stages.find(e=>e.getAttr("pageId")===r));if(!d)throw u?.set({_forceMount:!1,_exporting:!1}),e.setElementsPixelRatio(c),Error(`Export is failed. Can not find stage for page ${r}. Looks like <Workspace /> component is not mounted, but it is required in order to process the export.`);await e.waitLoading({_skipTimeout:a});let f=d.findOne(".page-container");if(!f)throw e.setElementsPixelRatio(c),u?.set({_forceMount:!1,_exporting:!1}),Error("Export is failed. Canvas was unmounted.");let p=d.position();d.position({x:0,y:0}),d.find("Transformer").forEach(e=>{e.setAttr("oldVisible",e.visible()),e.visible(!1)}),f.find(".page-background").forEach(e=>e.shadowEnabled(!1)),f.find(".page-background").forEach(e=>e.strokeEnabled(!1)),f.find(".highlighter").forEach(e=>e.visible(!1));let g=f.findOne(".page-background-group"),m=g.clip();g.clip({x:null,y:null,width:null,height:null});let v=f.findOne(".elements-container"),y=v.clip();v.clip({x:null,y:null,width:null,height:null});let b=f.find(e=>e.getAttr("hideInExport"));b.forEach(e=>{e.setAttr("oldVisible",e.visible()),e.hide()});let x=f.find(e=>!e.visible()&&e.getAttr("editModeEnabled"));x.forEach(e=>{e.setAttr("oldVisible",e.visible()),e.show()}),n&&f.find(".page-background").forEach(e=>e.hide());let w=o?u.bleed:0,C=w;!e.bleedVisible&&o||(e.bleedVisible||o?e.bleedVisible&&o?C=0:e.bleedVisible&&!o&&(C=-u.bleed):C=0);let _=document.createElement("canvas");_.width=Math.round((u.computedWidth+2*w)*s),_.height=Math.round((u.computedHeight+2*w)*s);let S=_.getContext("2d");"image/jpeg"===i&&(S.fillStyle="white",S.fillRect(0,0,_.width,_.height));let E=f.scale();f.scale({x:1,y:1});let k=f.toCanvas({x:f.x()-C,y:f.y()-C,width:u.computedWidth+2*w,height:u.computedHeight+2*w,pixelRatio:s});return f.scale(E),S.drawImage(k,0,0,_.width,_.height),h(M).Util.releaseCanvas(k),n&&f.find(".page-background").forEach(e=>e.show()),b.forEach(e=>{e.visible(e.getAttr("oldVisible"))}),x.forEach(e=>{e.visible(e.getAttr("oldVisible"))}),f.find(".page-background").forEach(e=>e.shadowEnabled(!0)),f.find(".page-background").forEach(e=>e.strokeEnabled(!0)),d.find("Transformer").forEach(e=>{e.visible(e.getAttr("oldVisible"))}),f.find(".highlighter").forEach(e=>e.visible(!0)),g.clip(m),v.clip(y),d.position(p),u?.set({_exporting:!1,_forceMount:!1}),await new Promise(e=>setTimeout(e)),e.setElementsPixelRatio(c),_},async toDataURL({mimeType:t,quality:n,...r}={}){let i=await e._toCanvas({mimeType:t,...r}),o=i.toDataURL(t,n);return h(M).Util.releaseCanvas(i),o},async toBlob({mimeType:t,quality:n,...r}={}){let i=await e._toCanvas({mimeType:t,...r}),o=await new Promise(e=>{i.toBlob(e,t,n)});return h(M).Util.releaseCanvas(i),o},async saveAsImage({fileName:t,...n}={}){let r=n.mimeType||"image/png",i=r.split("/")[1];lS(await e.toDataURL(n),t||"polotno."+i,r)},async _toPDF(t){let n=t.dpi||e.dpi,r=t.parallel||1,i=t.unit||("px"===e.unit?"mm":e.unit),o=t.pixelRatio||1,a=t.pageIds||e.pages.map(e=>e.id),l=e.pages.filter(e=>a.includes(e.id)),s=await (window.jspdf?.jsPDF?Promise.resolve(window.jspdf.jsPDF):lE||(lE=new Promise(e=>{var t=document.createElement("script");t.onload=function(){e(window.jspdf.jsPDF)},t.src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/3.0.1/jspdf.umd.min.js",document.head.appendChild(t)}))),u=e=>l1({px:e,unit:i,dpi:n}),c=t.cropMarkSize||0,d=u(c),h=l[0]||{},f=t.includeBleed?h.bleed:0,p=u(h.computedWidth+2*f+2*d),g=u(h.computedHeight+2*f+2*d);var m=new s({unit:i,orientation:p>g?"landscape":"portrait",format:[p,g],compress:!0,putOnlyUsedFonts:!0});m.deletePage(1);let v=((e,t)=>{for(var n=[],r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n})(l,r),y=0;for(let n of v){let r=n.map(async n=>{let r=t.includeBleed?n.bleed:0,i=n.computedWidth+2*r+2*c,l=n.computedHeight+2*r+2*c,s=u(i),d=u(l),h=0,f=o;for(;h<10;){2===(h+=1)&&console.error("Polotno can not export PDF with current settings. Quality is automatically reduced.");let r=await e.toDataURL({...t,pageId:n.id,pixelRatio:f});if(r.length>20)return t.onProgress&&t.onProgress(++y/a.length*.9),{url:r,width:s,height:d,widthPx:i,heightPx:l};f*=.8}});(await Promise.all(r)).forEach(({url:e,width:t,height:n,widthPx:r,heightPx:o})=>{var a;m.addPage([t,n],t>n?"landscape":"portrait");let l=m.getCurrentPageInfo();switch(i){case"pt":a=1;break;case"mm":a=72/25.4;break;case"cm":a=72/2.54;break;case"in":a=72;break;case"px":a=.75;break;case"pc":case"em":a=12;break;case"ex":a=6;break;default:throw"Invalid unit: "+i}if(l.pageContext.cropBox={bottomLeftX:0,bottomLeftY:0,topRightX:t*a,topRightY:n*a},l.pageContext.artBox={bottomLeftX:u(c+f)*a,bottomLeftY:u(c+f)*a,topRightX:u(r-c-f)*a,topRightY:u(o-c-f)*a},l.pageContext.bleedBox={bottomLeftX:u(c+f)*a,bottomLeftY:u(c+f)*a,topRightX:u(r-c-f)*a,topRightY:u(o-c-f)*a},d){m.setLineWidth(u(1));let e=d+u(f);m.line(e,0,e,d),m.line(0,e,d,e),m.line(t-e,0,t-e,d),m.line(t,e,t-d,e),m.line(0,n-e,d,n-e),m.line(e,n,e,n-d),m.line(t,n-e,t-d,n-e),m.line(t-e,n,t-e,n-d)}m.addImage(e,d,d,t-2*d,n-2*d,void 0,"FAST")})}return m},toPDFDataURL:async t=>(await e._toPDF({mimeType:"image/jpeg",...t})).output("datauristring"),async toGIFDataURL(t={}){let n=t.pixelRatio||1,r=await lk({width:e.width*n,height:e.height*n}),i=1e3/(t.fps||10),o=e.duration/i;for(let t=0;t<o-1;t++){let o=t*i||1;e.setCurrentTime(o);let a=0,l="";for(let t of e.pages)if(a+=t.duration,t.set({_rendering:a>o}),a>o){l=t.id;break}let s=await e._toCanvas({pixelRatio:n,pageId:l,_skipTimeout:!0});r.addFrame(s.getContext("2d"),{delay:i,copy:!0})}for(let t of e.pages)t.set({_rendering:!1});return e.stop(),r.render(),new Promise(e=>{r.on("finished",function(t){var n;(n=new FileReader).onload=function(t){e(t.target.result)},n.readAsDataURL(t)})})},async saveAsGIF({fileName:t,...n}={}){lS(await e.toGIFDataURL(n),t||"polotno.gif")},toHTML:async({elementHook:t}={elementHook:void 0})=>sg({json:e.toJSON(),elementHook:t}),async saveAsHTML({fileName:t}={}){let n=await e.toHTML();lS("data:text/html;base64,"+window.btoa(unescape(encodeURIComponent(n))),t||"polotno.html")},async toSVG({elementHook:t,pageId:n}={elementHook:void 0,pageId:void 0}){let r=e.toJSON();n=n||r.pages[0]?.id;let i=r.pages.find(e=>e.id===n);return sT({json:{...r,pages:i?[i]:[]},elementHook:t})},async saveAsSVG({fileName:t,elementHook:n,pageId:r}={}){let i=await e.toSVG({elementHook:n,pageId:r});lS("data:text/svg;base64,"+window.btoa(unescape(encodeURIComponent(i))),t||"polotno.svg")},async saveAsPDF({fileName:t,...n}={}){(await e._toPDF({mimeType:"image/jpeg",...n})).save(t||"polotno.pdf")},async waitLoading({_skipTimeout:e=!1}={}){e||await new Promise(e=>setTimeout(e,50)),await new Promise(e=>{var t;return t=()=>{ih()?setTimeout(e,300):e(!0)},void(0===ig?t():im.push(t))})},toJSON:()=>({width:e.width,height:e.height,fonts:(0,iq.getSnapshot)(e.fonts),pages:(0,iq.getSnapshot)(e.pages),audios:(0,iq.getSnapshot)(e.audios),unit:e.unit,dpi:e.dpi,custom:e.custom,schemaVersion:e.schemaVersion}),loadJSON(t,n=!1){let r={...t};void 0===r.schemaVersion&&iM.htmlRenderEnabled&&sZ({children:r.pages},e=>{if("text"===e.type){let t=16*e.letterSpacing;e.letterSpacing=t/e.fontSize}});let i=e.pages.indexOf(e.activePage),o=(r.pages[i]||r.pages[0])?.id;r._activePageId=o;let a={...(0,iq.getSnapshot)(e)};Object.assign(a,r),n?a.history=e.history.toJSON():a.history={history:[],undoIdx:-1},(0,iq.applySnapshot)(e,a)},clear({keepHistory:t=!1}={}){let n=e.pages.map(e=>e.id);e.deletePages(n),e.custom=null,t||e.history.clear()},addFont(t){e.removeFont(t.fontFamily),e.fonts.push(t),e.loadFont(t.fontFamily)},removeFont(t){e.fonts.filter(e=>e.fontFamily===t).forEach(e=>(0,iq.destroy)(e))},addAudio(t){let n=sj.create({id:lw(10),...t});e.audios.push(n)},removeAudio(t){let n=e.audios.find(e=>e.id===t);n&&e.audios.remove(n)},async loadFont(t){let n=e.fonts.find(e=>e.fontFamily===t)||iE.find(e=>e.fontFamily===t),r=[{fontStyle:"normal",fontWeight:"normal"}];return n?(n.styles&&(r=n.styles.map(e=>({fontStyle:e.fontStyle||"normal",fontWeight:e.fontWeight||"normal"}))),function(e){let t=e.fontFamily;if(iL[t]||!e.url&&!e.styles)return;let n=document.createElement("style");n.type="text/css";let r=e.styles||(e.url?[{src:`url("${e.url}")`}]:[]),i="";r.forEach(e=>{i+=`
|
|
238
238
|
@font-face {
|
|
239
239
|
font-family: '${t}';
|
|
240
240
|
src: ${e.src};
|
package/utils/validate-key.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e,t=this&&this.__createBinding||(Object.create?function(e,t,o,n){void 0===n&&(n=o);var r=Object.getOwnPropertyDescriptor(t,o);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[o]}}),Object.defineProperty(e,n,r)}:function(e,t,o,n){void 0===n&&(n=o),e[n]=t[o]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),n=this&&this.__importStar||(e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var o in e){Object.prototype.hasOwnProperty.call(e,o)&&(t[t.length]=o)}return t},e(t)},function(n){if(n&&n.__esModule){return n}var r={};if(null!=n){for(var i=e(n),a=0;a<i.length;a++){"default"!==i[a]&&t(r,n,i[a])}}return o(r,n),r});Object.defineProperty(exports,"__esModule",{value:!0}),exports.__=exports.getKey=exports.isCreditVisible=exports.___=void 0,exports.isKeyPaid=w,exports.validateKey=async function(e,t){u=e,await w(e)&&!t||c()};const r=n(require("mobx")),i=require("./api"),a=require("./flags"),s=r.observable({value:!1}),l=r.observable({value:"v1"});exports.___=()=>l.value,exports.isCreditVisible=()=>s.value;const c=r.action((()=>{s.value=!0}));let u="";exports.getKey=()=>u||"";const d=5,p=3e3,g="Polotno API is initialized without API key. It may lead to unexpected behavior and stop working. Please create API key here: https://polotno.com/cabinet",v="Polotno API key is not valid. Please get new API key here: https://polotno.com/cabinet",f="Can not validate Polotno API key. Please report to anton@polotno.com immediately.",b="%cPolotno Free Version. Development or non-commercial usage only. https://polotno.com/";let _=window.location.origin;const m=navigator.userAgent.indexOf("Headless")>-1,h=navigator.userAgent.indexOf("Electron")>-1;"file://"===_&&m&&(_="headless"),"file://"===_&&h&&(_="electron");const y=`%cPolotno error! Current domain is not allowed. It may lead to unexpected behavior and stop working. Please add "${_}" here: https://polotno.com/cabinet`;let P=fetch;async function w(e){for(let o=0;o<d;o++){try{const t=await P((0,i.getAPI)()+"/validate-key",{method:"POST",body:JSON.stringify({key:e,site:location.host,skdVersion:"2.23.
|
|
1
|
+
var e,t=this&&this.__createBinding||(Object.create?function(e,t,o,n){void 0===n&&(n=o);var r=Object.getOwnPropertyDescriptor(t,o);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[o]}}),Object.defineProperty(e,n,r)}:function(e,t,o,n){void 0===n&&(n=o),e[n]=t[o]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),n=this&&this.__importStar||(e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var o in e){Object.prototype.hasOwnProperty.call(e,o)&&(t[t.length]=o)}return t},e(t)},function(n){if(n&&n.__esModule){return n}var r={};if(null!=n){for(var i=e(n),a=0;a<i.length;a++){"default"!==i[a]&&t(r,n,i[a])}}return o(r,n),r});Object.defineProperty(exports,"__esModule",{value:!0}),exports.__=exports.getKey=exports.isCreditVisible=exports.___=void 0,exports.isKeyPaid=w,exports.validateKey=async function(e,t){u=e,await w(e)&&!t||c()};const r=n(require("mobx")),i=require("./api"),a=require("./flags"),s=r.observable({value:!1}),l=r.observable({value:"v1"});exports.___=()=>l.value,exports.isCreditVisible=()=>s.value;const c=r.action((()=>{s.value=!0}));let u="";exports.getKey=()=>u||"";const d=5,p=3e3,g="Polotno API is initialized without API key. It may lead to unexpected behavior and stop working. Please create API key here: https://polotno.com/cabinet",v="Polotno API key is not valid. Please get new API key here: https://polotno.com/cabinet",f="Can not validate Polotno API key. Please report to anton@polotno.com immediately.",b="%cPolotno Free Version. Development or non-commercial usage only. https://polotno.com/";let _=window.location.origin;const m=navigator.userAgent.indexOf("Headless")>-1,h=navigator.userAgent.indexOf("Electron")>-1;"file://"===_&&m&&(_="headless"),"file://"===_&&h&&(_="electron");const y=`%cPolotno error! Current domain is not allowed. It may lead to unexpected behavior and stop working. Please add "${_}" here: https://polotno.com/cabinet`;let P=fetch;async function w(e){for(let o=0;o<d;o++){try{const t=await P((0,i.getAPI)()+"/validate-key",{method:"POST",body:JSON.stringify({key:e,site:location.host,skdVersion:"2.23.7"})});if(l.value=t.headers.get("x-api-version"),!e){return console.warn(g),!1}if(200!==t.status){await new Promise((e=>setTimeout(e,p)));continue}const o=await t.json();return o.is_valid||console.warn(v),o.is_paid||console.log(b,"background: rgb(0, 161, 255); color: white; padding: 5px; margin: 5px;"),o.is_domain_valid||console.log(y,"background: rgba(247, 101, 68, 1); color: white; padding: 5px; margin: 5px;"),(0,a.useRemoveBackground)(o.remove_background_enabled),o.is_paid||!1}catch(t){await new Promise((e=>setTimeout(e,p)))}}return console.error(f),!0}exports.__=e=>{P=e};
|