polotno 1.7.5 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/canvas/element.js +1 -1
- package/canvas/html-element.js +1 -1
- package/canvas/video-element.d.ts +12 -0
- package/canvas/video-element.js +1 -0
- package/canvas/workspace.js +1 -1
- package/model/store.d.ts +99 -0
- package/model/store.js +1 -1
- package/package.json +3 -1
- package/polotno-app.d.ts +194 -0
- package/polotno.bundle.js +52 -49
- package/side-panel/side-panel.js +5 -2
- package/toolbar/html-toolbar.js +1 -1
- package/utils/html.js +1 -1
- package/utils/html2canvas.d.ts +2 -1
- package/utils/html2canvas.js +1 -1
package/canvas/element.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.registerShapeComponent=void 0;const react_1=__importDefault(require("react")),mobx_react_lite_1=require("mobx-react-lite"),text_element_1=require("./text-element"),image_element_1=require("./image-element"),html_element_1=require("./html-element"),line_element_1=require("./line-element"),react_konva_1=require("react-konva"),flags_1=require("../utils/flags"),GroupElement=(0,mobx_react_lite_1.observer)((e=>{const{element:t,store:n}=e,{children:l}=t,r=t.selectable||"admin"===n.role;return react_1.default.createElement(react_konva_1.Group,{opacity:t.opacity,listening:r},l.map((t=>react_1.default.createElement(Element,Object.assign({},e,{key:t.id,store:n,element:t})))))})),SHAPES_TYPES={text:text_element_1.TextElement,image:image_element_1.ImageElement,svg:image_element_1.ImageElement,line:line_element_1.LineElement,group:GroupElement};function registerShapeComponent(e,t){SHAPES_TYPES[e]=t}exports.registerShapeComponent=registerShapeComponent;const Element=(0,mobx_react_lite_1.observer)((e=>{let t=SHAPES_TYPES[e.element.type];return"text"===e.element.type&&flags_1.flags.htmlRenderEnabled&&(t=html_element_1.HTMLElement),e.element.visible?t?react_1.default.createElement(t,Object.assign({},e)):(console.error("Can not find component for "+e.element.type),null):null}));exports.default=Element;
|
|
1
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.registerShapeComponent=void 0;const react_1=__importDefault(require("react")),mobx_react_lite_1=require("mobx-react-lite"),text_element_1=require("./text-element"),image_element_1=require("./image-element"),html_element_1=require("./html-element"),line_element_1=require("./line-element"),video_element_1=require("./video-element"),react_konva_1=require("react-konva"),flags_1=require("../utils/flags"),GroupElement=(0,mobx_react_lite_1.observer)((e=>{const{element:t,store:n}=e,{children:l}=t,r=t.selectable||"admin"===n.role;return react_1.default.createElement(react_konva_1.Group,{opacity:t.opacity,listening:r},l.map((t=>react_1.default.createElement(Element,Object.assign({},e,{key:t.id,store:n,element:t})))))})),SHAPES_TYPES={text:text_element_1.TextElement,image:image_element_1.ImageElement,svg:image_element_1.ImageElement,line:line_element_1.LineElement,video:video_element_1.VideoElement,group:GroupElement};function registerShapeComponent(e,t){SHAPES_TYPES[e]=t}exports.registerShapeComponent=registerShapeComponent;const Element=(0,mobx_react_lite_1.observer)((e=>{let t=SHAPES_TYPES[e.element.type];return"text"===e.element.type&&flags_1.flags.htmlRenderEnabled&&(t=html_element_1.HTMLElement),e.element.visible?t?react_1.default.createElement(t,Object.assign({},e)):(console.error("Can not find component for "+e.element.type),null):null}));exports.default=Element;
|
package/canvas/html-element.js
CHANGED
|
@@ -16,4 +16,4 @@
|
|
|
16
16
|
.ql-direction-rtl {
|
|
17
17
|
direction: rtl;
|
|
18
18
|
}
|
|
19
|
-
`,RichEditor=({html:e,onBlur:t,onChange:i,element:r})=>{const n=react_1.default.useRef(null);react_1.default.useEffect((()=>{if(!n.current)return;const e=new quill_1.default(n.current,{toolbar:!1,keyboard:!1,clipboard:{matchVisual:!1},formats:["background","bold","color","font","italic","size","strike","underline","indent","align","direction"]});return exports.quillRef.editor.instance=e,window.__polotnoQuill=e,e.on("text-change",(()=>{e.getSelection()&&(exports.quillRef.currentFormat=e.getFormat()),setTimeout((()=>{var e;i(null===(e=n.current)||void 0===e?void 0:e.childNodes[0].innerHTML)}),10)})),e.setSelection(0,0,"api"),e.on("selection-change",(i=>{i||t(),i&&(exports.quillRef.currentFormat=e.getFormat())})),n.current.childNodes[0].addEventListener("blur",(e=>{var i;(null===(i=e.relatedTarget)||void 0===i?void 0:i.classList.contains("ql-clipboard"))||t()})),()=>{exports.quillRef.editor.instance=null,exports.quillRef.currentFormat={},delete window.__polotnoQuill}}),[]),react_1.default.useEffect((()=>{var t;const i=exports.quillRef.editor.instance;if(!i)return;const o=i.getSelection();if(!((null===(t=n.current)||void 0===t?void 0:t.childNodes[0].innerHTML)===r.text)){var a=i.clipboard.convert("<div class='ql-editor' style='outline: none;'>"+e+"<p><br></p></div>");i.setContents(a),i.history.clear(),o&&(i.setSelection(o.index,o.length),exports.quillRef.currentFormat=i.getFormat())}}),[r.text]);const o=(0,text_element_1.useTextColor)(r).fill;return react_1.default.createElement(RichTextContainer,{ref:n,style:{fontSize:r.fontSize,color:o,width:r.width,fontFamily:r.fontFamily,lineHeight:r.lineHeight,letterSpacing:r.letterSpacing+"rem",textAlign:r.align},dir:(0,text_element_1.getDir)((0,text_1.removeTags)(r.text))})};function useHtmlSize(e,t,i){return react_1.default.useMemo((()=>(0,html2canvas_1.detectSize)(e)),[e,t.width,i])}function getHtml(e,{fontFamily:t="",color:i="black"}={}){let r=`color: ${i||e.fill}`;return`<div style="white-space: unset; width: ${Math.round(e.width||100)}px; ${r}; font-size: ${e.fontSize}px; font-family: '${t}'; text-decoration: ${e.textDecoration}; text-align: ${e.align}; line-height: ${e.lineHeight}; letter-spacing: ${e.letterSpacing}rem; font-style: ${e.fontStyle}; font-weight: ${e.fontWeight}; -webkit-text-stroke: ${e.strokeWidth}px ${e.stroke};" contentEditable dir="${(0,text_element_1.getDir)((0,text_1.removeTags)(e.text))}">${e.text}</div>`}const findFitFontSize=e=>{let t=e.fontSize;for(let i=1;i<50;i++){const i=getHtml(Object.assign(Object.assign({},e.toJSON()),{fontSize:t}),{fontFamily:e.fontFamily}),{height:r}=(0,html2canvas_1.detectSize)(i);if(!(e.height&&r>e.height))break;t-=.5}return t},isSafari=/^((?!chrome|android).)*safari/i.test(navigator.userAgent);exports.HTMLElement=(0,mobx_react_lite_1.observer)((({element:e,store:t})=>{const i=react_1.default.useRef(null),[r,n]=react_1.default.useState(),[o,a]=react_1.default.useState(!1),[l,s]=react_1.default.useState(!0),[c,d]=react_1.default.useState(!1),[u,f]=react_1.default.useState(!1),h=react_1.default.useRef(e.height),g=t.selectedElements.indexOf(e)>=0,_=e.fontSize/
|
|
19
|
+
`,RichEditor=({html:e,onBlur:t,onChange:i,element:r})=>{const n=react_1.default.useRef(null);react_1.default.useEffect((()=>{if(!n.current)return;const e=new quill_1.default(n.current,{toolbar:!1,keyboard:!1,clipboard:{matchVisual:!1},formats:["background","bold","color","font","italic","size","strike","underline","indent","align","direction"]});return exports.quillRef.editor.instance=e,window.__polotnoQuill=e,e.on("text-change",(()=>{e.getSelection()&&(exports.quillRef.currentFormat=e.getFormat()),setTimeout((()=>{var e;i(null===(e=n.current)||void 0===e?void 0:e.childNodes[0].innerHTML)}),10)})),e.setSelection(0,0,"api"),e.on("selection-change",(i=>{i||t(),i&&(exports.quillRef.currentFormat=e.getFormat())})),n.current.childNodes[0].addEventListener("blur",(e=>{var i;(null===(i=e.relatedTarget)||void 0===i?void 0:i.classList.contains("ql-clipboard"))||t()})),()=>{exports.quillRef.editor.instance=null,exports.quillRef.currentFormat={},delete window.__polotnoQuill}}),[]),react_1.default.useEffect((()=>{var t;const i=exports.quillRef.editor.instance;if(!i)return;const o=i.getSelection();if(!((null===(t=n.current)||void 0===t?void 0:t.childNodes[0].innerHTML)===r.text)){var a=i.clipboard.convert("<div class='ql-editor' style='outline: none;'>"+e+"<p><br></p></div>");i.setContents(a),i.history.clear(),o&&(i.setSelection(o.index,o.length),exports.quillRef.currentFormat=i.getFormat())}}),[r.text]);const o=(0,text_element_1.useTextColor)(r).fill;return react_1.default.createElement(RichTextContainer,{ref:n,style:{fontSize:r.fontSize,color:o,width:r.width,fontFamily:r.fontFamily,lineHeight:r.lineHeight,letterSpacing:r.letterSpacing+"rem",textAlign:r.align},dir:(0,text_element_1.getDir)((0,text_1.removeTags)(r.text))})};function useHtmlSize(e,t,i){return react_1.default.useMemo((()=>(0,html2canvas_1.detectSize)(e)),[e,t.width,i])}function getHtml(e,{fontFamily:t="",color:i="black"}={}){let r=`color: ${i||e.fill}`;return`<div style="white-space: unset; width: ${Math.round(e.width||100)}px; ${r}; font-size: ${e.fontSize}px; font-family: '${t}'; text-decoration: ${e.textDecoration}; text-align: ${e.align}; line-height: ${e.lineHeight}; letter-spacing: ${e.letterSpacing}rem; font-style: ${e.fontStyle}; font-weight: ${e.fontWeight}; -webkit-text-stroke: ${e.strokeWidth}px ${e.stroke};" contentEditable dir="${(0,text_element_1.getDir)((0,text_1.removeTags)(e.text))}">${e.text}</div>`}const findFitFontSize=e=>{let t=e.fontSize;for(let i=1;i<50;i++){const i=getHtml(Object.assign(Object.assign({},e.toJSON()),{fontSize:t}),{fontFamily:e.fontFamily}),{height:r}=(0,html2canvas_1.detectSize)(i);if(!(e.height&&r>e.height))break;t-=.5}return t},isSafari=/^((?!chrome|android).)*safari/i.test(navigator.userAgent);exports.HTMLElement=(0,mobx_react_lite_1.observer)((({element:e,store:t})=>{const i=react_1.default.useRef(null),[r,n]=react_1.default.useState(),[o,a]=react_1.default.useState(!1),[l,s]=react_1.default.useState(!0),[c,d]=react_1.default.useState(!1),[u,f]=react_1.default.useState(!1),h=react_1.default.useRef(e.height),g=t.selectedElements.indexOf(e)>=0,_=e.fontSize/3,{textVerticalResizeEnabled:m}=flags_1.flags,[x]=(0,text_element_1.useFontLoader)(t,e.fontFamily);(0,use_fadein_1.useFadeIn)(i);const p=x?e.fontFamily:"Arial",y=(0,text_element_1.useTextColor)(e).fill,b=getHtml(e,{fontFamily:p,color:y}),{width:v,height:w}=useHtmlSize(b,e,x);react_1.default.useEffect((()=>{if(!x)return;if(!e.height)return void e.set({height:w});const{textOverflow:i}=flags_1.flags;if("change-font-size"!==i||o)"resize"===i&&(m&&e.height<w&&t.history.ignore((()=>{e.set({height:w})})),m||e.height===w||t.history.ignore((()=>{e.set({height:w})})));else{const i=findFitFontSize(e);i!==e.fontSize?t.history.ignore((()=>{e.set({fontSize:i})})):e.height!==w&&t.history.ignore((()=>{e.set({height:w})}))}}));const S=react_1.default.useRef(0),E=async()=>{S.current++;const i=S.current,r=(0,loader_1.incrementLoader)(`text ${e.id}`);s(!0),await new Promise((e=>setTimeout(e,0)));const o=await(0,html2canvas_1.htmlToCanvas)({html:b,width:e.width||1,height:e.height||w||1,fontFamily:p,padding:_,pixelRatio:t._elementsPixelRatio,font:t.fonts.find((e=>e.fontFamily===p))||fonts.globalFonts.find((e=>e.fontFamily===p))});i===S.current?(n(o),s(!1),konva_1.default.Util.requestAnimFrame(r)):r()};react_1.default.useEffect((()=>{o||c||E()}),[b,o,w,c,p,e.height,t._elementsPixelRatio]),react_1.default.useEffect((()=>{if(!x)return;if(!isSafari)return;const e=setTimeout((()=>{E()}),100);return()=>clearTimeout(e)}),[x,p]);const q=o||l;react_1.default.useEffect((()=>mobx.autorun((()=>{const t=i.current;(0,apply_filters_1.applyFilter)(t,e)}))),[r,q,e.shadowColor,e.shadowOffsetX,e.shadowOffsetY,e.shadowOpacity]);let z=0;"middle"===e.verticalAlign&&(z=(e.height-w)/2),"bottom"===e.verticalAlign&&(z=e.height-w);const k=(0,text_element_1.getLineHeight)({fontLoaded:x,fontFamily:e.fontFamily,fontSize:e.fontSize,lineHeight:e.lineHeight}),F=(0,screen_1.useMobile)();return react_1.default.createElement(react_1.default.Fragment,null,react_1.default.createElement(react_konva_1.Rect,{x:e.x,y:e.y,offsetX:e.backgroundPadding*(e.fontSize*k*.5),offsetY:e.backgroundPadding*(e.fontSize*k*.5),rotation:e.rotation,hideInExport:!e.showInExport||!e.text,listening:!1,visible:e.backgroundEnabled,opacity:e.backgroundOpacity,fill:e.backgroundColor,width:e.width+e.backgroundPadding*(e.fontSize*k),height:e.height+e.backgroundPadding*(e.fontSize*k),cornerRadius:e.backgroundCornerRadius*(e.fontSize*k*.5)}),react_1.default.createElement(react_konva_1.Rect,{ref:i,name:"element",x:e.x,y:e.y,listening:e.selectable,rotation:e.rotation,width:e.width,height:e.height,visible:!q,draggable:F?e.draggable&&g:e.draggable,preventDefault:!F||g,opacity:c?0:e.opacity,hideInExport:!e.showInExport,onMouseEnter:()=>{f(!0)},onMouseLeave:()=>{f(!1)},onDragStart:()=>{t.history.startTransaction()},onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:i=>{e.set({x:i.target.x(),y:i.target.y()}),t.history.endTransaction()},id:e.id,onDblClick:()=>{e.contentEditable&&d(!0)},onDblTap:()=>{e.contentEditable&&d(!0)},onTransformStart:t=>{a(!0),h.current=e.height},onTransform:t=>{var i;const r=t.target,n=(null===(i=r.getStage())||void 0===i?void 0:i.findOne("Transformer")).getActiveAnchor(),o="middle-left"===n||"middle-right"===n,a="top-center"===n||"bottom-center"===n,l=r.scaleX();if(o){const t=r.scaleX(),i=Math.max(r.width()*t,e.fontSize);if(r.width(i),r.scaleX(1),flags_1.flags.textVerticalResizeEnabled){const t=Math.max(w,h.current);e.set({height:t})}e.set({width:i,x:r.x(),y:r.y()})}else if(a){let i="resize"===flags_1.flags.textOverflow?w:e.lineHeight*e.fontSize;const n=Math.max(i,t.target.height()*t.target.scaleY());r.scaleY(1),e.set({x:r.x(),y:r.y(),height:n,rotation:r.rotation()})}else r.scaleX(1),r.scaleY(1),e.set({fontSize:e.fontSize*l,width:r.width()*l,x:r.x(),y:r.y(),rotation:r.rotation(),height:r.height()*l})},onTransformEnd:t=>{a(!1),s(!0);const i=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),e.set({fontSize:e.fontSize*i,width:t.target.width()*i,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation()})}}),react_1.default.createElement(react_konva_1.Image,{ref:i,image:r,x:e.x,y:e.y,offsetX:_,offsetY:_-z,listening:!1,rotation:e.rotation,width:e.width+2*_,height:e.height+2*_,visible:!q,opacity:c?0:e.opacity,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,hideInExport:!e.showInExport}),q&&react_1.default.createElement(react_konva_1.Group,{x:e.x,y:e.y,rotation:e.rotation,offsetY:-z},react_1.default.createElement(react_konva_utils_1.Html,{divProps:{style:{pointerEvents:"none"}}},react_1.default.createElement(RichTextContainer,{dangerouslySetInnerHTML:{__html:b},style:{pointerEvents:"none",display:"inline-block"}}))),c&&react_1.default.createElement(react_konva_1.Group,{x:e.x,y:e.y,rotation:e.rotation,offsetY:-z},react_1.default.createElement(react_konva_utils_1.Html,null,react_1.default.createElement(RichEditor,{html:b,element:e,onChange:t=>{e.set({text:t})},onBlur:e=>{d(!1)}}))),(g||u)&&react_1.default.createElement(highlighter_1.Highlighter,{element:e}))}));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { VideoElementType, StoreType } from '../model/store';
|
|
3
|
+
type ImageProps = {
|
|
4
|
+
store: StoreType;
|
|
5
|
+
element: VideoElementType;
|
|
6
|
+
};
|
|
7
|
+
export declare const setImageLoaderHook: (customImageLoaderHook: any) => void;
|
|
8
|
+
export declare const useImageLoader: (status: string, id: string) => void;
|
|
9
|
+
export declare const VideoElement: (({ element, store }: ImageProps) => JSX.Element) & {
|
|
10
|
+
displayName: string;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,a){void 0===a&&(a=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,a,o)}:function(e,t,r,a){void 0===a&&(a=r),e[a]=t[r]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&__createBinding(t,e,r);return __setModuleDefault(t,e),t},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.VideoElement=exports.useImageLoader=exports.setImageLoaderHook=void 0;const react_1=__importDefault(require("react")),mobx_react_lite_1=require("mobx-react-lite"),mobx_1=require("mobx"),react_konva_1=require("react-konva"),use_image_1=__importDefault(require("use-image")),konva_1=__importDefault(require("konva")),svg=__importStar(require("../utils/svg")),react_konva_utils_1=require("react-konva-utils"),highlighter_1=require("./highlighter"),loader_1=require("../utils/loader"),flags_1=require("../utils/flags"),apply_filters_1=require("./apply-filters"),use_fadein_1=require("./use-fadein"),screen_1=require("../utils/screen");function createCanvas(){return document.createElement("canvas")}async function getFixedUrl(e){if(!(e.indexOf("data:image/svg+xml")>=0||e.indexOf(".svg")>=0))return e;const t=await svg.urlToString(e),r=svg.fixSize(t);return svg.svgToURL(r)}const useSizeFixer=e=>{const[t,r]=react_1.default.useState(e);return react_1.default.useEffect((()=>{(async()=>{const a=await getFixedUrl(e);a!==t&&r(a)})()}),[e]),t},playIcon=new window.Image;playIcon.src=svg.svgToURL('\n <svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <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"/>\n <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"/>\n </svg>\n');const pauseIcon=new window.Image;pauseIcon.src=svg.svgToURL('\n <svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <path opacity="0.6" d="M14 19L14 5C14 3.89543 14.8954 3 16 3L17 3C18.1046 3 19 3.89543 19 5L19 19C19 20.1046 18.1046 21 17 21L16 21C14.8954 21 14 20.1046 14 19Z" fill="white"/>\n <path opacity="0.6" d="M10 19L10 5C10 3.89543 9.10457 3 8 3L7 3C5.89543 3 5 3.89543 5 5L5 19C5 20.1046 5.89543 21 7 21L8 21C9.10457 21 10 20.1046 10 19Z" fill="white"/>\n <path d="M14 19L14 5C14 3.89543 14.8954 3 16 3L17 3C18.1046 3 19 3.89543 19 5L19 19C19 20.1046 18.1046 21 17 21L16 21C14.8954 21 14 20.1046 14 19Z" stroke="#323232" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n <path d="M10 19L10 5C10 3.89543 9.10457 3 8 3L7 3C5.89543 3 5 3.89543 5 5L5 19C5 20.1046 5.89543 21 7 21L8 21C9.10457 21 10 20.1046 10 19Z" stroke="#323232" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>\n');const useFlip=(e,t,r)=>{const a=react_1.default.useMemo((()=>{var a,o;const{flipX:i,flipY:n}=e,c="svg"===e.type||e.src.indexOf("data:image/svg+xml")>=0||e.src.indexOf(".svg")>=0,d=navigator.userAgent.toLowerCase().indexOf("firefox")>-1&&c||e.maskSrc;if(!i&&!n&&!d)return t;if(!t||!t.width||!t.height)return null;const h=createCanvas();let l=1;"svg"===e.type&&(l=Math.max(e.width/t.width*r,e.height/t.height*r)),h.width=Math.max(t.width*l,1),h.height=Math.max(t.height*l,1);let s=i?-h.width:0,u=n?-h.height:0;return null===(a=h.getContext("2d"))||void 0===a||a.scale(i?-1:1,n?-1:1),null===(o=h.getContext("2d"))||void 0===o||o.drawImage(t,s,u,h.width,h.height),h}),[e.maskSrc,e.flipX,e.flipY,t,e.width,e.height,r]);return react_1.default.useEffect((()=>()=>{a&&"CANVAS"===a.nodeName&&konva_1.default.Util.releaseCanvas(a)}),[a]),a};function getCrop(e,t){const r=t.width/t.height;let a,o;r>=e.width/e.height?(a=e.width,o=e.width/r):(a=e.height*r,o=e.height);return{x:(e.width-a)/2,y:(e.height-o)/2,width:a,height:o}}function downsample(e,t,r,a,o,i,n){for(var c=new ImageData(t,r),d=new Int32Array(e.data.buffer),h=e.width,l=new Int32Array(c.data.buffer),s=c.width,u=t/i,g=r/n,f=Math.round(1/u),p=Math.round(1/g),_=f*p,m=0;m<c.height;m++)for(var w=0;w<s;w++){for(var v=a+Math.round(w/u)+(o+Math.round(m/g))*h,x=0,y=0,M=0,E=0,b=0;b<p;b++)for(var C=0;C<f;C++){var k=d[v+C+b*h];x+=k<<24>>>24,y+=k<<16>>>24,M+=k<<8>>>24,E+=k>>>24}x=Math.round(x/_),y=Math.round(y/_),M=Math.round(M/_),E=Math.round(E/_),l[w+m*s]=E<<24|M<<16|y<<8|x}return c}function downScaleCanvas(e,t){var r,a;const o=createCanvas();o.width=e.width,o.height=e.height,null===(r=o.getContext("2d"))||void 0===r||r.drawImage(e,0,0,o.width,o.height);const i=downsample(o.getContext("2d").getImageData(0,0,o.width,o.height),Math.floor(o.width*t),Math.floor(o.height*t),0,0,o.width,o.height);return o.width=Math.floor(o.width*t),o.height=Math.floor(o.height*t),null===(a=o.getContext("2d"))||void 0===a||a.putImageData(i,0,0),o}const useCornerRadiusAndCrop=(e,t,r,a,o=0,i=!1)=>{const n=Math.floor(Math.max(e.width*a,1)),c=Math.floor(Math.max(e.height*a,1)),d=Math.min(o*a,n/2,c/2),h=Math.max(e.width/r.width,e.height/r.height)*a,l=e.page._exporting&&flags_1.flags.imageDownScalingEnabled&&h<1&&!i,s=0===r.x&&0===r.y&&r.width===(null==t?void 0:t.width)&&r.height===(null==t?void 0:t.height),u=react_1.default.useMemo((()=>{if(!t||!t.width||!t.height)return;return s&&0===d&&!l?void 0:createCanvas()}),[t,d,l,s]);return react_1.default.useLayoutEffect((()=>{if(!u||!t)return;u.width=n,u.height=c;const e=u.getContext("2d");if(!e)return;d&&(e.beginPath(),e.moveTo(d,0),e.lineTo(n-d,0),e.arc(n-d,d,d,3*Math.PI/2,0,!1),e.lineTo(n,c-d),e.arc(n-d,c-d,d,0,Math.PI/2,!1),e.lineTo(d,c),e.arc(d,c-d,d,Math.PI/2,Math.PI,!1),e.lineTo(0,d),e.arc(d,d,d,Math.PI,3*Math.PI/2,!1),e.clip());const a=l?downScaleCanvas(t,h):t,o=l?{x:Math.floor(r.x*h),y:Math.floor(r.y*h),width:Math.floor(r.width*h),height:Math.floor(r.height*h)}:r;e.drawImage(a,o.x,o.y,o.width,o.height,0,0,u.width,u.height)}),[u,e.width,e.height,r.x,r.y,r.width,r.height,o,a,i,e.page._exporting,l]),react_1.default.useEffect((()=>()=>{u&&"CANVAS"===u.nodeName&&konva_1.default.Util.releaseCanvas(u)}),[u]),u||t},useClip=(e,t,r,a)=>{const o=useSizeFixer(e.clipSrc||""),[i,n]=useImageHook(o,"anonymous"),c=e.clipSrc?n:"loaded";(0,exports.useImageLoader)(c,e.id+"-clip");const d=react_1.default.useMemo((()=>{if(t&&i)return createCanvas()}),[t,i]);react_1.default.useLayoutEffect((()=>{var a;if(!i)return;if(!t||!t.width||!t.height)return;if(!i||!i.width||!i.height)return;if(!d)return;const o=createCanvas(),n=Math.max(e.width/i.width*r,e.height/i.height*r);o.width=i.width*n,o.height=i.height*n,null===(a=o.getContext("2d"))||void 0===a||a.drawImage(i,0,0,o.width,o.height),d.width=Math.max(t.width,1),d.height=Math.max(t.height,1);const c=d.getContext("2d");c&&(c.save(),c.drawImage(o,0,0,t.width,t.height),konva_1.default.Util.releaseCanvas(o),c.globalCompositeOperation="source-in",c.drawImage(t,0,0,d.width,d.height),c.restore())}),[d,t,i,e.width,e.height,r,...a]);return e.clipSrc&&i?d:t},PLACEHOLDER_CANVAS=createCanvas(),LoadingPlaceholder=(0,mobx_react_lite_1.observer)((({element:e})=>{const t=Math.min(30,e.width/4,e.height/4),r=react_1.default.useRef(null);return react_1.default.useEffect((()=>{const e=r.current;if(!e)return;const t=new konva_1.default.Animation((t=>{e.rotate(((null==t?void 0:t.timeDiff)||0)/2)}),e.getLayer());return t.start(),()=>{t.stop()}})),react_1.default.createElement(react_konva_1.Group,{x:e.x,y:e.y,rotation:e.rotation,listening:!1,opacity:e.a.opacity,hideInExport:!e.showInExport},react_1.default.createElement(react_konva_1.Rect,{width:e.width,height:e.height,fill:"rgba(124, 173, 212, 0.8)"}),react_1.default.createElement(react_konva_1.Arc,{ref:r,x:e.width/2,y:e.height/2,fill:"white",outerRadius:Math.abs(t),innerRadius:Math.max(1,t-5),angle:270}))})),ErrorPlaceholder=(0,mobx_react_lite_1.observer)((({element:e})=>{const t="Can not load the image...",r=Math.max(10,Math.min(30,e.width/t.length));return react_1.default.createElement(react_konva_1.Group,{x:e.x,y:e.y,rotation:e.rotation,listening:!1,opacity:e.a.opacity,hideInExport:!e.showInExport},react_1.default.createElement(react_konva_1.Rect,{width:e.width,height:e.height,fill:"rgba(223, 102, 102, 0.8)"}),react_1.default.createElement(react_konva_1.Text,{text:t,fontSize:r,width:e.width,height:e.height,align:"center",fill:"white",verticalAlign:"middle",padding:5}))}));let useImageHook=use_image_1.default;const setImageLoaderHook=e=>{useImageHook=e};exports.setImageLoaderHook=setImageLoaderHook;const useImageLoader=(e,t)=>{const r=react_1.default.useRef(),a=()=>{var e;null===(e=r.current)||void 0===e||e.call(r),r.current=void 0};react_1.default.useEffect((()=>a),[]),react_1.default.useLayoutEffect((()=>{"loading"!==e||r.current||(r.current=(0,loader_1.incrementLoader)(`image ${t}`)),"loading"!==e&&a(),"failed"===e&&(0,loader_1.triggerLoadError)(`image ${t}`)}),[e])};exports.useImageLoader=useImageLoader;const usePreviousImage=({image:e,status:t,type:r})=>{const a=react_1.default.useRef();react_1.default.useEffect((()=>{a.current=e||a.current}),[e]);return"failed"!==t||"failed"!==t&&"svg"===r?a.current:void 0},useImageSource=e=>{const[t,r]=react_1.default.useReducer((e=>e+1),0),a=react_1.default.useRef("loading"),o=react_1.default.useRef(e.src),i=react_1.default.useRef(e.src);return i.current!==e.src&&(i.current=e.src,a.current="loading"),react_1.default.useEffect((()=>{if("image"===e.type)return;if(!e.src)return;let t=!1;return(async()=>{a.current="loading",r();const i=await svg.urlToString(e.src),n=svg.fixSize(i),c=svg.replaceColors(n,e.colorsReplace);t||(o.current=c,a.current="loaded",r())})(),()=>{t=!0}}),[e.src,JSON.stringify(e.colorsReplace)]),"image"===e.type?[e.src,"loaded"]:[o.current,a.current]};function useVideo(e,t,r){const a=react_1.default.useRef("loading"),o=react_1.default.useRef(),[i,n]=react_1.default.useState(0),c=react_1.default.useRef(),d=react_1.default.useRef(),h=react_1.default.useRef();return c.current===e&&d.current===t&&h.current===r||(a.current="loading",o.current=void 0,c.current=e,d.current=t,h.current=r),react_1.default.useLayoutEffect((function(){if(e){var i=document.createElement("video");return i.addEventListener("canplay",c),i.addEventListener("error",d),t&&(i.crossOrigin=t),r&&(i.referrerpolicy=r),i.src=e,function(){i.removeEventListener("canplay",c),i.removeEventListener("error",d)}}function c(){a.current="loaded",o.current=i,n(Math.random())}function d(){a.current="failed",o.current=void 0,n(Math.random())}}),[e,t,r]),[o.current,a.current]}exports.VideoElement=(0,mobx_react_lite_1.observer)((({element:e,store:t})=>{var r;const[a,o]=react_1.default.useState(!1),i=react_1.default.useRef(null),n=react_1.default.useRef(null),[c,d]=react_1.default.useState(!1),h=t.selectedElements.indexOf(e)>=0,[l,s]=react_1.default.useState(!1),[u,g]=useVideo(e.src,"anonymous");u&&(u.muted=!0,u.width=u.videoWidth,u.height=u.videoHeight);const f=u||PLACEHOLDER_CANVAS;react_1.default.useEffect((()=>{u&&t.history.ignore((()=>{e.set({duration:1e3*u.duration})}))}),[u]),react_1.default.useEffect((()=>{var e;if(!u)return;const r=t.isPlaying||l;if(!r)return void u.pause();r&&u.play();const a=new konva_1.default.Animation((()=>{}),null===(e=i.current)||void 0===e?void 0:e.getLayer());a.start();const o=()=>{s(!1),u.currentTime=0};return u.addEventListener("ended",o),()=>{a.stop(),u.removeEventListener("ended",o)}}),[u,l,t.isPlaying]),react_1.default.useEffect((()=>(0,mobx_1.autorun)((()=>{var r,a;if(u){const o=t.currentTime%e.duration;console.log("rest",o),u.currentTime=o/1e3,null===(a=null===(r=i.current)||void 0===r?void 0:r.getLayer())||void 0===a||a.batchDraw()}}))),[t,u]);let{cropX:p,cropY:_,cropWidth:m,cropHeight:w}=e;"loaded"!==g&&(p=_=0,m=w=1);const v=f.width*m,x=f.height*w,y=e.width/e.height;let M,E;const b=v/x,C="svg"===e.type;C?(M=v,E=x):y>=b?(M=v,E=v/y):(M=x*y,E=x);const k={x:f.width*p,y:f.height*_,width:M,height:E},L=null!==(r=e.cornerRadius)&&void 0!==r?r:0;let I=useClip(e,useCornerRadiusAndCrop(e,f,k,t._elementsPixelRatio,L,a||e._cropModeEnabled||"svg"===e.type),t._elementsPixelRatio,[k,L,t._elementsPixelRatio]);const S=Math.max(e.width/M,e.height/E);react_1.default.useEffect((()=>{var t;if(!e._cropModeEnabled)return;const r=null===(t=i.current)||void 0===t?void 0:t.getStage();function a(t){e._cropModeEnabled&&t.target!==n.current&&e.toggleCropMode(!1)}function o(t){e._cropModeEnabled&&"CANVAS"!==t.target.nodeName&&e.toggleCropMode(!1)}return document.body.addEventListener("click",o),null==r||r.on("click",a),null==r||r.on("tap",a),()=>{document.body.removeEventListener("click",o),document.body.removeEventListener("touchstart",o),null==r||r.off("click",a),null==r||r.off("click",a)}}),[e._cropModeEnabled]),react_1.default.useLayoutEffect((()=>{if(a||e._cropModeEnabled)return;(0,apply_filters_1.applyFilter)(i.current,e);return(0,mobx_1.autorun)((()=>{(0,apply_filters_1.applyFilter)(i.current,e)}),{delay:100})}),[f,a,m,w,e._cropModeEnabled]),react_1.default.useLayoutEffect((()=>{var t;a||e._cropModeEnabled?null===(t=i.current)||void 0===t||t.clearCache():(0,apply_filters_1.applyFilter)(i.current,e)}),[a,e.width,e.height,e._cropModeEnabled]),react_1.default.useEffect((()=>{(0,apply_filters_1.applyFilter)(i.current,e)}),[e.shadowEnabled,e.shadowBlur,e.cornerRadius,e.shadowColor,e.shadowOffsetX,e.shadowOffsetY,e.shadowOpacity]);const R=react_1.default.useRef(null),O=react_1.default.useRef(null),T=react_1.default.useRef(null);react_1.default.useLayoutEffect((()=>{e._cropModeEnabled&&(O.current.nodes([R.current]),T.current.nodes([n.current]))}),[e._cropModeEnabled]);const P=t=>{Math.round(t.target.x())>0&&(t.target.x(0),t.target.scaleX(1)),Math.round(t.target.y())>0&&(t.target.y(0),t.target.scaleY(1));const r=t.target.width()*t.target.scaleX(),a=t.target.height()*t.target.scaleY(),o=Math.min(1,M/r),i=Math.min(1,E/a),n=1-o,c=Math.min(n,Math.max(0,Math.round(-t.target.x())/r)),d=1-i,h=Math.min(d,Math.max(0,Math.round(-t.target.y())/a));t.target.setAttrs({x:-c*f.width,y:-h*f.height,scaleX:1,scaleY:1}),e.set({cropX:c,cropY:h,cropWidth:o,cropHeight:i})},X=()=>{"svg"!==e.type&&e.contentEditable&&setTimeout((()=>{e.toggleCropMode(!0)}))},Y="svg"===e.type&&oldImage,A="loading"===g&&!Y,H="failed"===g,D=!A&&!H,W=react_1.default.useRef({cropX:0,cropY:0,cropWidth:0,cropHeight:0}),q=D?e.a.opacity:0;(0,use_fadein_1.useFadeIn)(i,q);const F=e.selectable||"admin"===t.role,z=(0,screen_1.useMobile)();return react_1.default.createElement(react_1.default.Fragment,null,A&&react_1.default.createElement(LoadingPlaceholder,{element:e}),H&&react_1.default.createElement(ErrorPlaceholder,{element:e}),react_1.default.createElement(react_konva_1.Image,{ref:i,name:"element",id:e.id,image:f,x:e.x,y:e.y,width:e.width||1,height:e.height||1,rotation:e.rotation,opacity:q,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,customCrop:k,listening:F,cropX:k.x,cropY:k.y,cropWidth:k.width,cropHeight:k.height,draggable:z?e.draggable&&h:e.draggable,preventDefault:!z||h,hideInExport:!e.showInExport,onMouseEnter:()=>{d(!0)},onMouseLeave:()=>{d(!1)},onDragStart:()=>{t.history.startTransaction()},onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:r=>{e.set({x:r.target.x(),y:r.target.y()}),t.history.endTransaction()},onDblClick:X,onDblTap:X,onTransformStart:()=>{o(!0),t.history.startTransaction(),W.current={cropX:e.cropX,cropY:e.cropY,cropWidth:e.cropWidth,cropHeight:e.cropHeight}},onTransform:t=>{var r;const a=t.currentTarget,o=Math.abs(a.scaleX()-1)<1e-7?1:a.scaleX(),i=Math.abs(a.scaleY()-1)<1e-7?1:a.scaleY();a.scaleX(1),a.scaleY(1);const n=null===(r=t.target.getStage())||void 0===r?void 0:r.findOne("Transformer"),c=1-M/f.width,d=Math.min(c,Math.max(0,e.cropX)),h=1-E/f.height,l=Math.min(h,Math.max(0,e.cropY)),s=n.getActiveAnchor(),u=!(s.indexOf("middle")>=0||s.indexOf("center")>=0),g=!u&&o<1&&W.current.cropHeight>E/f.height;let p=u?e.cropWidth:e.cropWidth*o;g&&(p=e.cropWidth);const _=!u&&i<1&&W.current.cropWidth>M/f.width;let m=u?e.cropHeight:e.cropHeight*i;_&&(m=e.cropHeight),C&&(p=e.cropWidth,m=e.cropHeight),e.set({cropX:d,cropY:l,x:a.x(),y:a.y(),width:a.width()*o,height:a.height()*i,rotation:t.target.rotation(),cropWidth:Math.min(p,1-d),cropHeight:Math.min(m,1-l)})},onTransformEnd:r=>{const a=r.currentTarget;e.set({width:a.width(),height:a.height(),x:a.x(),y:a.y(),rotation:r.target.rotation(),cropWidth:M/f.width,cropHeight:E/f.height}),o(!1),t.history.endTransaction()}}),react_1.default.createElement(react_konva_1.Rect,{x:e.x,y:e.y,width:Math.max(e.width-e.borderSize,0),height:Math.max(e.height-e.borderSize,0),opacity:q,offsetX:-e.borderSize/2,offsetY:-e.borderSize/2,stroke:e.borderColor,strokeWidth:e.borderSize,listening:!1,visible:!!e.borderSize,rotation:e.rotation,cornerRadius:Math.max(0,L-e.borderSize),hideInExport:!e.showInExport}),!l&&react_1.default.createElement(react_konva_1.Image,{image:playIcon,x:e.x+e.width/2-20,y:e.y+e.height/2-20,width:40,height:40,hideInExport:!0,onClick:()=>{s(!0)}}),l&&react_1.default.createElement(react_konva_1.Image,{image:pauseIcon,x:e.x+e.width/2-20,y:e.y+e.height/2-20,width:40,height:40,hideInExport:!0,onClick:()=>{s(!1)}}),e._cropModeEnabled&&react_1.default.createElement(react_konva_utils_1.Portal,{selector:".page-abs-container",enabled:!0},react_1.default.createElement(react_konva_1.Rect,{x:-window.innerWidth/t.scale,y:-window.innerWidth/t.scale,width:window.innerWidth/t.scale*3,height:window.innerWidth/t.scale*3,fill:"rgba(0,0,0,0.3)"}),react_1.default.createElement(react_konva_1.Image,{listening:!1,image:I,x:e.x,y:e.y,width:e.width,height:e.height,rotation:e.rotation,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur}),react_1.default.createElement(react_konva_1.Group,{x:e.x,y:e.y,rotation:e.rotation,scaleX:S,scaleY:S},react_1.default.createElement(react_konva_1.Image,{image:f,ref:n,opacity:.4,draggable:!0,x:-e.cropX*f.width,y:-e.cropY*f.height,onDragMove:P,onTransform:P}),react_1.default.createElement(react_konva_1.Transformer,{ref:T,anchorSize:20,enabledAnchors:["top-left","top-right","bottom-left","bottom-right"],boundBoxFunc:(e,t)=>t.width<5||t.height<5?e:t,rotateEnabled:!1,borderEnabled:!1,anchorCornerRadius:10,anchorStrokeWidth:2,borderStrokeWidth:2}),react_1.default.createElement(react_konva_1.Rect,{width:M,height:E,ref:R,listening:!1,onTransform:t=>{t.target.x()<-e.cropX*f.width-1e-9&&(t.target.x(-e.cropX*f.width),t.target.scaleX(1)),t.target.y()<-e.cropY*f.height-1e-9&&(t.target.y(-e.cropY*f.height),t.target.scaleY(1));const r=Math.min(1,Math.max(0,e.cropX+t.target.x()/f.width)),a=Math.min(1,Math.max(0,t.target.y()/f.height+e.cropY)),o=t.target.width()*t.target.scaleX(),i=t.target.height()*t.target.scaleY(),n=Math.min(1-r,o/f.width),c=Math.min(1-a,i/f.height),d=t.target.getAbsolutePosition(t.target.getParent().getParent());t.target.scale({x:1,y:1}),t.target.position({x:0,y:0}),e.set({x:d.x,y:d.y,cropX:r,cropY:a,cropWidth:n,cropHeight:c,width:Math.min(o*S,f.width*(1-r)*S),height:Math.min(i*S,f.height*(1-a)*S)})}}),react_1.default.createElement(react_konva_1.Transformer,{ref:O,enabledAnchors:["top-left","top-right","bottom-left","bottom-right"],boundBoxFunc:(e,t)=>t.width<5||t.height<5?e:t,keepRatio:!1,rotateEnabled:!1,anchorFill:"rgb(240, 240, 240)",anchorStrokeWidth:2,borderStrokeWidth:2}))),(c||h)&&react_1.default.createElement(highlighter_1.Highlighter,{element:e}))}));
|
package/canvas/workspace.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Workspace=void 0;const react_1=__importDefault(require("react")),mobx_react_lite_1=require("mobx-react-lite"),page_1=__importDefault(require("./page")),rules_1=require("./rules"),hotkeys_1=require("./hotkeys"),l10n_1=require("../utils/l10n"),limit=(e,t,r)=>Math.max(t,Math.min(r,e)),ZERO_SIZE_WARNING="Polotno warning: <Workspace /> component can not automatically detect its size.\nWidth or height of parent elements is equal 0.\nPlease make sure it has non-zero size. You may need to adjust it with your styles. <Workspace /> will automatically fit into parent container.\nFor simpler debugging here is the log of the parent element:",useSaveScrollOnScaleChange=(e,t,r,a,n,l)=>{const o=react_1.default.useRef({width:t,height:r}),c=react_1.default.useRef({top:0,left:0}),s=react_1.default.useRef(!1),i=react_1.default.useRef(n.pages.length);s.current=i.current!==n.pages.length,i.current=n.pages.length,react_1.default.useEffect((()=>{const t=e.current,r=e=>{c.current={top:t.scrollTop,left:t.scrollLeft}};return t.addEventListener("scroll",r),()=>{t.removeEventListener("scroll",r)}}),[]),react_1.default.useLayoutEffect((()=>{if(!e.current)return;if(s.current)return;const a=e.current,n=(c.current.left+a.offsetWidth/2)/o.current.width,i=(c.current.top+a.offsetHeight/2)/o.current.height;l.current=!0,a.scrollLeft=n*t-a.offsetWidth/2,a.scrollTop=i*r-a.offsetHeight/2,o.current={width:t,height:r}}),[a,t,r])},useScrollOnActiveChange=(e,t,r,a,n)=>{const l=react_1.default.useRef(!1),o=react_1.default.useRef(null);react_1.default.useEffect((()=>{const t=e.current,r=()=>{n.current};return t.addEventListener("scroll",r),()=>{t.removeEventListener("scroll",r)}}),[]);const c=r.pages.indexOf(r.activePage);react_1.default.useLayoutEffect((()=>{if(!r.activePage)return;if(!e.current)return;if(l.current)return;const a=e.current,o=r.pages.indexOf(r.activePage)*t;Math.abs(o-a.scrollTop)>.
|
|
1
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Workspace=void 0;const react_1=__importDefault(require("react")),mobx_react_lite_1=require("mobx-react-lite"),page_1=__importDefault(require("./page")),rules_1=require("./rules"),hotkeys_1=require("./hotkeys"),l10n_1=require("../utils/l10n"),limit=(e,t,r)=>Math.max(t,Math.min(r,e)),ZERO_SIZE_WARNING="Polotno warning: <Workspace /> component can not automatically detect its size.\nWidth or height of parent elements is equal 0.\nPlease make sure it has non-zero size. You may need to adjust it with your styles. <Workspace /> will automatically fit into parent container.\nFor simpler debugging here is the log of the parent element:",useSaveScrollOnScaleChange=(e,t,r,a,n,l)=>{const o=react_1.default.useRef({width:t,height:r}),c=react_1.default.useRef({top:0,left:0}),s=react_1.default.useRef(!1),i=react_1.default.useRef(n.pages.length);s.current=i.current!==n.pages.length,i.current=n.pages.length,react_1.default.useEffect((()=>{const t=e.current,r=e=>{c.current={top:t.scrollTop,left:t.scrollLeft}};return t.addEventListener("scroll",r),()=>{t.removeEventListener("scroll",r)}}),[]),react_1.default.useLayoutEffect((()=>{if(!e.current)return;if(s.current)return;const a=e.current,n=(c.current.left+a.offsetWidth/2)/o.current.width,i=(c.current.top+a.offsetHeight/2)/o.current.height;l.current=!0,a.scrollLeft=n*t-a.offsetWidth/2,a.scrollTop=i*r-a.offsetHeight/2,o.current={width:t,height:r}}),[a,t,r])},useScrollOnActiveChange=(e,t,r,a,n)=>{const l=react_1.default.useRef(!1),o=react_1.default.useRef(null);react_1.default.useEffect((()=>{const t=e.current,r=()=>{n.current};return t.addEventListener("scroll",r),()=>{t.removeEventListener("scroll",r)}}),[]);const c=r.pages.indexOf(r.activePage);react_1.default.useLayoutEffect((()=>{if(!r.activePage)return;if(!e.current)return;if(l.current)return;const a=e.current,o=r.pages.indexOf(r.activePage)*t;Math.abs(o-a.scrollTop)>.5*t&&(n.current=!0,a.scrollTop=o)}),[r.activePage,c]);return{handleScroll:e=>{if(n.current)return void(n.current=!1);l.current=!0,clearTimeout(o.current),o.current=setTimeout((()=>{l.current=!1}),300);const t=e.currentTarget.childNodes[0].offsetHeight,c=e.currentTarget.scrollTop,s=Math.floor((c+a.height/3)/t),i=r.pages[s];i&&i.select()}}},NoPages=({store:e})=>react_1.default.createElement("div",{style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",textAlign:"center"}},react_1.default.createElement("p",null,(0,l10n_1.t)("workspace.noPages")),react_1.default.createElement("button",{onClick:()=>{e.addPage()}},(0,l10n_1.t)("workspace.addPage")));exports.Workspace=(0,mobx_react_lite_1.observer)((({store:e,pageControlsEnabled:t,backgroundColor:r,pageBorderColor:a,activePageBorderColor:n,bleedColor:l,components:o,onKeyDown:c})=>{const[s,i]=react_1.default.useState({width:100,height:100}),u=react_1.default.useRef(s),d=react_1.default.useRef(null),h=react_1.default.useRef(null),f=e.bleedVisible?Math.max(0,...e.pages.map((e=>e.bleed))):0,g=Math.max(...e.pages.map((e=>e.computedWidth))),p=Math.max(...e.pages.map((e=>e.computedHeight))),_=g+2*f,m=p+2*f,v=()=>{if(null===d.current)return;const t=d.current.getBoundingClientRect();0!==t.width&&0!==t.height||(console.warn(ZERO_SIZE_WARNING),console.log(d.current));const r=h.current.clientWidth||t.width,a={width:r,height:t.height};(u.current.width!==a.width||u.current.height!==a.height)&&(i(a),u.current=a);const n=(r-40)/_,l=(t.height-110)/m,o=Math.max(Math.min(n,l),.01);e.scaleToFit!==o&&(e.setScale(o),e._setScaleToFit(o))};react_1.default.useEffect(v,[_,m]),react_1.default.useEffect((()=>{const e=d.current;if(window.ResizeObserver){const t=new ResizeObserver(v);return t.observe(e),()=>t.unobserve(e)}{const e=setInterval(v,100);return()=>clearInterval(e)}}),[_,m]);const w=Math.max(20,(s.width-_*e.scale)/2),b=m*e.scale*e.pages.length,x=Math.max(55,(s.height-b)/e.pages.length/2);react_1.default.useEffect((()=>{const t=t=>{(c||hotkeys_1.handleHotkey)(t,e)};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)}),[]),react_1.default.useEffect((()=>{var t;const r=t=>{if(t.ctrlKey||t.metaKey){t.preventDefault();const l=Math.max(2,e.scaleToFit),o=Math.min(.5,e.scaleToFit),c=(r=t.deltaY<0?1.05*e.scale:e.scale/1.05,a=o,n=l,Math.max(a,Math.min(n,r)));e.setScale(c)}else var r,a,n};return null===(t=h.current)||void 0===t||t.addEventListener("wheel",r),()=>{var e;return null===(e=h.current)||void 0===e?void 0:e.removeEventListener("wheel",r)}}),[]);const E=react_1.default.useRef(!1);useSaveScrollOnScaleChange(h,_*e.scale+2*w,m*e.scale+2*x,e.scale,e,E);const{handleScroll:y}=useScrollOnActiveChange(h,m*e.scale+2*x,e,s,E),k=s.width>=_*e.scale+2*w,P=r||"rgba(232, 232, 232, 0.9)",C=e.pages.indexOf(e.activePage),R=(null==o?void 0:o.NoPages)||NoPages;return react_1.default.createElement("div",{ref:d,style:{width:"100%",height:"100%",position:"relative",outline:"none",flex:1,backgroundColor:P},tabIndex:0,className:"polotno-workspace-container"},react_1.default.createElement("div",{ref:h,onScroll:y,style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",overflow:"auto",overflowX:k?"hidden":"auto"},className:"polotno-workspace-inner"},e.pages.map(((r,c)=>Math.abs(c-C)<=1||r._exporting?react_1.default.createElement(page_1.default,{key:r.id,page:r,xPadding:w,yPadding:x,width:_*e.scale+2*w,height:m*e.scale+2*x,store:e,pageControlsEnabled:t,backColor:P,pageBorderColor:a||"lightgrey",activePageBorderColor:n||"rgb(0, 161, 255)",bleedColor:l||"rgba(255, 0, 0, 0.1)",components:o}):react_1.default.createElement("div",{key:r.id,style:{width:_*e.scale+2*w+"px",height:m*e.scale+2*x+"px",backgroundColor:P,paddingLeft:w+"px",paddingRight:w+"px",paddingTop:x+"px",paddingBottom:x+"px"}},react_1.default.createElement("div",{style:{width:" 100%",height:"100%",backgroundColor:"white"}})))),e.rulesVisible&&react_1.default.createElement(rules_1.TopRules,{store:e,xPadding:w,yPadding:x,width:_*e.scale+2*w,height:m*e.scale+2*x}),0===e.pages.length&&react_1.default.createElement(R,{store:e})))})),exports.default=exports.Workspace;
|
package/model/store.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export declare const TextElement: any;
|
|
|
7
7
|
export type TextElementType = Instance<typeof TextElement>;
|
|
8
8
|
export declare const ImageElement: any;
|
|
9
9
|
export type ImageElementType = Instance<typeof ImageElement>;
|
|
10
|
+
export declare const VideoElement: any;
|
|
11
|
+
export type VideoElementType = Instance<typeof VideoElement>;
|
|
10
12
|
export declare const LineElement: any;
|
|
11
13
|
export type LineElementType = Instance<typeof LineElement>;
|
|
12
14
|
export declare const SVGElement: any;
|
|
@@ -136,6 +138,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
136
138
|
width: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
137
139
|
height: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
138
140
|
currentTime: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
141
|
+
isPlaying: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
139
142
|
scale: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
140
143
|
scaleToFit: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
141
144
|
unit: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
@@ -170,6 +173,97 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
170
173
|
}, {
|
|
171
174
|
readonly _bleedVisible: boolean;
|
|
172
175
|
readonly selectedElements: any[];
|
|
176
|
+
readonly children: import("mobx-state-tree").IMSTArray<import("mobx-state-tree").IModelType<{
|
|
177
|
+
id: import("mobx-state-tree").ISimpleType<string>;
|
|
178
|
+
children: import("mobx-state-tree").IArrayType<any>;
|
|
179
|
+
width: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ITypeUnion<number | "auto", number | "auto", number | "auto">, [undefined]>;
|
|
180
|
+
height: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ITypeUnion<number | "auto", number | "auto", number | "auto">, [undefined]>;
|
|
181
|
+
background: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
182
|
+
bleed: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
183
|
+
custom: import("mobx-state-tree").IType<any, any, any>;
|
|
184
|
+
_exporting: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
185
|
+
}, {
|
|
186
|
+
readonly store: any;
|
|
187
|
+
readonly animatedChildren: void;
|
|
188
|
+
} & {
|
|
189
|
+
readonly computedWidth: any;
|
|
190
|
+
readonly computedHeight: any;
|
|
191
|
+
} & {
|
|
192
|
+
toJSON(): any;
|
|
193
|
+
_forEachElementUp(ids: Array<string>, callback: Function): void;
|
|
194
|
+
_forEachElementDown(ids: Array<string>, callback: Function): false;
|
|
195
|
+
} & {
|
|
196
|
+
clone(attrs?: {}): any;
|
|
197
|
+
setZIndex(zIndex: any): void;
|
|
198
|
+
set(attrs: any): void;
|
|
199
|
+
select(): void;
|
|
200
|
+
addElement(attrs: any): ElementType | undefined;
|
|
201
|
+
canMoveElementsUp(ids: Array<string>): false;
|
|
202
|
+
moveElementsUp(ids: Array<string>): void;
|
|
203
|
+
canMoveElementsTop(ids: Array<string>): any;
|
|
204
|
+
moveElementsTop(ids: Array<string>): void;
|
|
205
|
+
canMoveElementsDown(ids: Array<string>): false;
|
|
206
|
+
moveElementsDown(ids: Array<string>): void;
|
|
207
|
+
canMoveElementsBottom(ids: Array<string>): any;
|
|
208
|
+
moveElementsBottom(ids: Array<string>): void;
|
|
209
|
+
setElementZIndex(id: any, zIndex: any): void;
|
|
210
|
+
setSize({ width, height, useMagic, softChange, }: {
|
|
211
|
+
width: number;
|
|
212
|
+
height: number;
|
|
213
|
+
useMagic?: boolean | undefined;
|
|
214
|
+
softChange?: boolean | undefined;
|
|
215
|
+
}): void;
|
|
216
|
+
} & {
|
|
217
|
+
moveElementUp(id: any): void;
|
|
218
|
+
moveElementDown(id: any): void;
|
|
219
|
+
moveElementTop(id: any): void;
|
|
220
|
+
moveElementBottom(id: any): void;
|
|
221
|
+
}, import("mobx-state-tree")._NotCustomized, {}>> & import("mobx-state-tree").IStateTreeNode<import("mobx-state-tree").IArrayType<import("mobx-state-tree").IModelType<{
|
|
222
|
+
id: import("mobx-state-tree").ISimpleType<string>;
|
|
223
|
+
children: import("mobx-state-tree").IArrayType<any>;
|
|
224
|
+
width: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ITypeUnion<number | "auto", number | "auto", number | "auto">, [undefined]>;
|
|
225
|
+
height: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ITypeUnion<number | "auto", number | "auto", number | "auto">, [undefined]>;
|
|
226
|
+
background: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
227
|
+
bleed: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
228
|
+
custom: import("mobx-state-tree").IType<any, any, any>;
|
|
229
|
+
_exporting: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
230
|
+
}, {
|
|
231
|
+
readonly store: any;
|
|
232
|
+
readonly animatedChildren: void;
|
|
233
|
+
} & {
|
|
234
|
+
readonly computedWidth: any;
|
|
235
|
+
readonly computedHeight: any;
|
|
236
|
+
} & {
|
|
237
|
+
toJSON(): any;
|
|
238
|
+
_forEachElementUp(ids: Array<string>, callback: Function): void;
|
|
239
|
+
_forEachElementDown(ids: Array<string>, callback: Function): false;
|
|
240
|
+
} & {
|
|
241
|
+
clone(attrs?: {}): any;
|
|
242
|
+
setZIndex(zIndex: any): void;
|
|
243
|
+
set(attrs: any): void;
|
|
244
|
+
select(): void;
|
|
245
|
+
addElement(attrs: any): ElementType | undefined;
|
|
246
|
+
canMoveElementsUp(ids: Array<string>): false;
|
|
247
|
+
moveElementsUp(ids: Array<string>): void;
|
|
248
|
+
canMoveElementsTop(ids: Array<string>): any;
|
|
249
|
+
moveElementsTop(ids: Array<string>): void;
|
|
250
|
+
canMoveElementsDown(ids: Array<string>): false;
|
|
251
|
+
moveElementsDown(ids: Array<string>): void;
|
|
252
|
+
canMoveElementsBottom(ids: Array<string>): any;
|
|
253
|
+
moveElementsBottom(ids: Array<string>): void;
|
|
254
|
+
setElementZIndex(id: any, zIndex: any): void;
|
|
255
|
+
setSize({ width, height, useMagic, softChange, }: {
|
|
256
|
+
width: number;
|
|
257
|
+
height: number;
|
|
258
|
+
useMagic?: boolean | undefined;
|
|
259
|
+
softChange?: boolean | undefined;
|
|
260
|
+
}): void;
|
|
261
|
+
} & {
|
|
262
|
+
moveElementUp(id: any): void;
|
|
263
|
+
moveElementDown(id: any): void;
|
|
264
|
+
moveElementTop(id: any): void;
|
|
265
|
+
moveElementBottom(id: any): void;
|
|
266
|
+
}, import("mobx-state-tree")._NotCustomized, {}>>>;
|
|
173
267
|
readonly selectedShapes: any[];
|
|
174
268
|
readonly activePage: ({
|
|
175
269
|
id: string;
|
|
@@ -262,9 +356,13 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
262
356
|
moveElementTop(id: any): void;
|
|
263
357
|
moveElementBottom(id: any): void;
|
|
264
358
|
}, import("mobx-state-tree")._NotCustomized, {}>>) | null;
|
|
359
|
+
readonly duration: number;
|
|
265
360
|
} & {
|
|
266
361
|
afterCreate(): void;
|
|
267
362
|
setCurrentTime(time: any): void;
|
|
363
|
+
play(): void;
|
|
364
|
+
seek(): void;
|
|
365
|
+
stop(): void;
|
|
268
366
|
setUnit({ unit, dpi }: {
|
|
269
367
|
unit: any;
|
|
270
368
|
dpi: any;
|
|
@@ -390,6 +488,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
390
488
|
saveAsHTML({ filename }?: {
|
|
391
489
|
filename?: string | undefined;
|
|
392
490
|
}): Promise<void>;
|
|
491
|
+
saveAsGIF(): Promise<void>;
|
|
393
492
|
saveAsPDF({ fileName, ...exportProps }?: ExportOptions & {
|
|
394
493
|
fileName?: string | undefined;
|
|
395
494
|
dpi?: number | undefined;
|
package/model/store.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,o,n){void 0===n&&(n=o);var a=Object.getOwnPropertyDescriptor(t,o);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[o]}}),Object.defineProperty(e,n,a)}:function(e,t,o,n){void 0===n&&(n=o),e[n]=t[o]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var o in e)"default"!==o&&Object.prototype.hasOwnProperty.call(e,o)&&__createBinding(t,e,o);return __setModuleDefault(t,e),t},__rest=this&&this.__rest||function(e,t){var o={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(n=Object.getOwnPropertySymbols(e);a<n.length;a++)t.indexOf(n[a])<0&&Object.prototype.propertyIsEnumerable.call(e,n[a])&&(o[n[a]]=e[n[a]])}return o},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.createStore=exports.Store=exports.Font=exports.Page=exports.GroupElement=exports.registerShapeModel=exports.SVGElement=exports.LineElement=exports.ImageElement=exports.TextElement=exports.Element=exports.Node=void 0;const mobx_state_tree_1=require("mobx-state-tree"),history_1=require("./history"),nanoid_1=require("nanoid"),konva_1=__importDefault(require("konva")),download_1=require("../utils/download"),pdf_1=require("../utils/pdf"),validate_key_1=require("../utils/validate-key"),fonts=__importStar(require("../utils/fonts")),loader_1=require("../utils/loader"),unit_1=require("../utils/unit"),deep_equal_1=require("../utils/deep-equal"),wait_1=require("../utils/wait"),html_1=require("../utils/html");(0,mobx_state_tree_1.setLivelinessChecking)("ignore");const forEveryChild=(e,t)=>{e.children&&e.children.forEach((e=>{t(e),forEveryChild(e,t)}))};exports.Node=mobx_state_tree_1.types.model("Node",{id:mobx_state_tree_1.types.identifier,type:"none",name:"",opacity:1,animations:mobx_state_tree_1.types.array(mobx_state_tree_1.types.frozen()),custom:mobx_state_tree_1.types.frozen(),visible:!0,selectable:!0,removable:!0,alwaysOnTop:!1,showInExport:!0}).postProcessSnapshot((e=>{const t=Object.assign({},e),o={};for(var n in t)"_"!==n[0]&&(o[n]=e[n]);return o})).views((e=>({get locked(){return!(e.draggable||e.contentEditable||e.styleEditable||e.resizable)},get page(){return(0,mobx_state_tree_1.getParentOfType)(e,exports.Page)},get store(){return(0,mobx_state_tree_1.getParentOfType)(e,exports.Store)},get top(){let t=e;for(;;){if(!(0,mobx_state_tree_1.hasParentOfType)(t,exports.GroupElement))return t;t=(0,mobx_state_tree_1.getParentOfType)(t,exports.GroupElement)}},get parent(){return(0,mobx_state_tree_1.hasParentOfType)(e,exports.GroupElement)?(0,mobx_state_tree_1.getParentOfType)(e,exports.GroupElement):(0,mobx_state_tree_1.hasParentOfType)(e,exports.Page)?(0,mobx_state_tree_1.getParentOfType)(e,exports.Page):(0,mobx_state_tree_1.hasParentOfType)(e,exports.Store)?(0,mobx_state_tree_1.getParentOfType)(e,exports.Store):null}}))).actions((e=>({toJSON:()=>Object.assign({},(0,mobx_state_tree_1.getSnapshot)(e))}))).actions((e=>({clone(t={}){const o=e.toJSON();return t.id=t.id||(0,nanoid_1.nanoid)(10),forEveryChild(o,(e=>{e.id=(0,nanoid_1.nanoid)(10)})),Object.assign(o,t),e.page.addElement(o)},set(t){Object.assign(e,t)},moveUp(){e.page.moveElementsUp([e.id])},moveTop(){e.page.moveElementsTop([e.id])},moveDown(){e.page.moveElementsDown([e.id])},moveBottom(){e.page.moveElementsBottom([e.id])},beforeDestroy(){e.store.history.endTransaction()}}))),exports.Element=exports.Node.named("Element").props({x:0,y:0,width:100,height:100,rotation:0,opacity:1,blurEnabled:!1,blurRadius:10,brightnessEnabled:!1,brightness:0,sepiaEnabled:!1,grayscaleEnabled:!1,shadowEnabled:!1,shadowBlur:5,shadowOffsetX:0,shadowOffsetY:0,shadowColor:"black",shadowOpacity:1,visible:!0,draggable:!0,resizable:!0,selectable:!0,contentEditable:!0,styleEditable:!0,alwaysOnTop:!1,showInExport:!0}).preProcessSnapshot((e=>{const t=Object.assign(Object.assign({},e),{x:e.x||0,y:e.y||0});return"width"in e&&(t.width=t.width||1),"height"in e&&(t.height=t.height||1),e.locked&&(t.draggable=!1,t.contentEditable=!1,t.styleEditable=!1,t.resizable=!1),t})).views((e=>({get a(){return e},animated:t=>e[t]}))),exports.TextElement=exports.Element.named("Text").props({type:"text",text:"",placeholder:"",fontSize:14,fontFamily:"Roboto",fontStyle:"normal",fontWeight:"normal",textDecoration:"",fill:"black",align:"center",width:100,height:0,verticalAlign:"top",strokeWidth:0,stroke:"black",lineHeight:mobx_state_tree_1.types.optional(mobx_state_tree_1.types.union(mobx_state_tree_1.types.number,mobx_state_tree_1.types.string),1.2),letterSpacing:0,_editModeEnabled:!1,backgroundEnabled:!1,backgroundColor:"#7ED321",backgroundOpacity:1,backgroundCornerRadius:.5,backgroundPadding:.5}).preProcessSnapshot((e=>Object.assign({},e))).actions((e=>({toggleEditMode(t){e._editModeEnabled=null!=t?t:!e._editModeEnabled,e._editModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction()}}))),exports.ImageElement=exports.Element.named("Image").props({type:"image",width:100,height:100,src:"",cropX:0,cropY:0,cropWidth:1,cropHeight:1,cornerRadius:0,flipX:!1,flipY:!1,clipSrc:"",borderColor:"black",borderSize:0,keepRatio:!1,_cropModeEnabled:!1}).actions((e=>({toggleCropMode(t){e._cropModeEnabled=null!=t?t:!e._cropModeEnabled,e._cropModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction()}}))),exports.LineElement=exports.Element.named("Line").props({type:"line",width:400,height:10,color:"black",dash:mobx_state_tree_1.types.array(mobx_state_tree_1.types.number),startHead:"",endHead:""}).actions((e=>({}))),exports.SVGElement=exports.Element.named("SVG").props({type:"svg",src:"",maskSrc:"",cropX:0,cropY:0,cropWidth:1,cropHeight:1,keepRatio:!0,flipX:!1,flipY:!1,width:100,height:100,borderColor:"black",borderSize:0,cornerRadius:0,colorsReplace:mobx_state_tree_1.types.map(mobx_state_tree_1.types.string)}).preProcessSnapshot((e=>Object.assign(Object.assign({},e),{src:e.src||e.svgSource}))).actions((e=>({replaceColor(t,o){e.colorsReplace.set(t,o)}})));const ADDITIONAL_TYPES=[];function registerShapeModel(e){const t=e.type;if(!t)throw new Error('You must pass "type" attribute to custom model.');const o=exports.Element.named(t).props(e);TYPES_MAP[t]=o,ADDITIONAL_TYPES.push(o)}exports.registerShapeModel=registerShapeModel;const additionalTypesUnion=[...new Array(20)].map(((e,t)=>mobx_state_tree_1.types.late((()=>ADDITIONAL_TYPES[t])))),ElementTypes=mobx_state_tree_1.types.union({dispatcher:e=>{const t=TYPES_MAP[e.type];if(!t)throw new Error(`Unknown element type: "${e.type}"`);return t}},exports.SVGElement,exports.TextElement,exports.ImageElement,exports.LineElement,mobx_state_tree_1.types.late((()=>exports.GroupElement)),...additionalTypesUnion);exports.GroupElement=exports.Node.named("Group").props({type:"group",children:mobx_state_tree_1.types.array(ElementTypes)}).views((e=>({get draggable(){let t=!0;return forEveryChild(e,(e=>{e.draggable||(t=!1)})),t},get resizable(){let t=!0;return forEveryChild(e,(e=>{e.resizable||(t=!1)})),t},get contentEditable(){let t=!0;return forEveryChild(e,(e=>{e.contentEditable||(t=!1)})),t},get styleEditable(){let t=!0;return forEveryChild(e,(e=>{e.styleEditable||(t=!1)})),t},get locked(){let t=!0;return forEveryChild(e,(e=>{e.locked||(t=!1)})),t}}))).actions((e=>({set(t){var{draggable:o,contentEditable:n,styleEditable:a,resizable:s}=t,i=__rest(t,["draggable","contentEditable","styleEditable","resizable"]);void 0!==o&&forEveryChild(e,(e=>{e.set({draggable:o})})),void 0!==n&&forEveryChild(e,(e=>{e.set({contentEditable:n})})),void 0!==a&&forEveryChild(e,(e=>{e.set({styleEditable:a})})),void 0!==s&&forEveryChild(e,(e=>{e.set({resizable:s})})),Object.assign(e,i)}})));const TYPES_MAP={svg:exports.SVGElement,text:exports.TextElement,image:exports.ImageElement,group:exports.GroupElement,line:exports.LineElement};function createStore({key:e,showCredit:t}={key:"",showCredit:!1}){const o=exports.Store.create();return(0,validate_key_1.validateKey)(e,t),o}exports.Page=mobx_state_tree_1.types.model("Page",{id:mobx_state_tree_1.types.identifier,children:mobx_state_tree_1.types.array(ElementTypes),width:mobx_state_tree_1.types.optional(mobx_state_tree_1.types.union(mobx_state_tree_1.types.number,mobx_state_tree_1.types.literal("auto")),"auto"),height:mobx_state_tree_1.types.optional(mobx_state_tree_1.types.union(mobx_state_tree_1.types.number,mobx_state_tree_1.types.literal("auto")),"auto"),background:"white",bleed:0,custom:mobx_state_tree_1.types.frozen(),_exporting:!1}).postProcessSnapshot((e=>{const t=Object.assign({},e),o={};for(var n in t)"_"!==n[0]&&(o[n]=e[n]);return o})).views((e=>({get store(){return(0,mobx_state_tree_1.getParentOfType)(e,exports.Store)},get animatedChildren(){}}))).views((e=>({get computedWidth(){return"auto"===e.width?e.store.width:e.width},get computedHeight(){return"auto"===e.height?e.store.height:e.height}}))).actions((e=>({toJSON:()=>JSON.parse(JSON.stringify((0,mobx_state_tree_1.getSnapshot)(e))),_forEachElementUp(t,o){const n=t.map((t=>({id:t,index:e.children.findIndex((e=>e.id===t))})));n.sort(((e,t)=>t.index-e.index));for(const{index:a}of n){if(-1==a)continue;const n=a<e.children.length-1&&e.children[a+1],s=t.indexOf(null==n?void 0:n.id)>=0;a===e.children.length-1||s||o(a)}},_forEachElementDown(t,o){const n=t.map((t=>({id:t,index:e.children.findIndex((e=>e.id===t))})));n.sort(((e,t)=>e.index-t.index));for(const{index:a}of n){if(-1==a)continue;const n=a>0&&e.children[a-1],s=t.indexOf(null==n?void 0:n.id)>=0;0===a||s||o(a)}return!1}}))).actions((e=>({clone(t={}){const o=e.toJSON();o.children.forEach((e=>{e.id=(0,nanoid_1.nanoid)(10),forEveryChild(e,(e=>{e.id=(0,nanoid_1.nanoid)(10)}))}));const n=Object.assign(Object.assign(Object.assign({},o),{id:(0,nanoid_1.nanoid)(10)}),t),a=e.store.addPage(n),s=e.store.pages.indexOf(e);a.setZIndex(s+1),a.select()},setZIndex(t){e.store.setPageZIndex(e.id,t)},set(t){Object.assign(e,t)},select(){e.store.selectPage(e.id)},addElement(t){const o=TYPES_MAP[t.type];if(!o)return void console.error("Can not find model with type "+t.type);t.children&&t.children.forEach((e=>{e.id=(0,nanoid_1.nanoid)(10)}));const n=o.create(Object.assign({id:(0,nanoid_1.nanoid)(10)},t));return e.children.push(n),n.selectable&&e.store.selectElements([n.id]),n},canMoveElementsUp(t){let o=!1;return e._forEachElementUp(t,(()=>{o=o||!0})),o},moveElementsUp(t){e._forEachElementUp(t,(t=>{const o=e.children[t];(0,mobx_state_tree_1.detach)(o),e.children.splice(t+1,0,o)}))},canMoveElementsTop(e){return this.canMoveElementsUp(e)},moveElementsTop(t){const o=[],n=[];e.children.forEach((e=>{t.indexOf(e.id)>=0?o.push(e):n.push(e)})),e.children.replace(n.concat(o))},canMoveElementsDown(t){let o=!1;return e._forEachElementDown(t,(()=>{o=o||!0})),o},moveElementsDown(t){e._forEachElementDown(t,(t=>{const o=e.children[t];(0,mobx_state_tree_1.detach)(o),e.children.splice(t-1,0,o)}))},canMoveElementsBottom(e){return this.canMoveElementsDown(e)},moveElementsBottom(t){const o=[],n=[];e.children.forEach((e=>{t.indexOf(e.id)>=0?o.push(e):n.push(e)})),e.children.replace(o.concat(n))},setElementZIndex(t,o){const n=e.children.find((e=>e.id===t));n&&((0,mobx_state_tree_1.detach)(n),e.children.remove(n),e.children.splice(o,0,n))},setSize({width:t,height:o,useMagic:n,softChange:a}){if(n){const n=t/e.computedWidth,a=o/e.computedHeight;for(const t of e.children)t.set({x:t.x*n,y:t.y*a}),"text"===t.type?t.set({fontSize:t.fontSize*n,width:Math.max(t.width*n,2)}):"image"===t.type?t.set({width:t.width*n,height:t.height*a}):"svg"===t.type&&t.set({width:Math.max(t.width*n,2),height:Math.max(t.height*n,2)})}"auto"!==e.width||a||(e.width=t),"auto"!==e.height||a||(e.height=o)}}))).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])}}))),exports.Font=mobx_state_tree_1.types.model("Font",{fontFamily:mobx_state_tree_1.types.string,url:mobx_state_tree_1.types.optional(mobx_state_tree_1.types.string,""),styles:mobx_state_tree_1.types.frozen()}).preProcessSnapshot((e=>Object.assign(Object.assign({},e),{fontFamily:e.fontFamily||e.name}))),exports.Store=mobx_state_tree_1.types.model("Store",{role:"",pages:mobx_state_tree_1.types.array(exports.Page),fonts:mobx_state_tree_1.types.array(exports.Font),width:1080,height:1080,currentTime:0,scale:1,scaleToFit:1,unit:"px",dpi:72,bleedVisible:!1,rulesVisible:!1,openedSidePanel:"",selectedElementsIds:mobx_state_tree_1.types.array(mobx_state_tree_1.types.string),history:mobx_state_tree_1.types.optional(history_1.UndoManager,{targetPath:"../pages"}),_elementsPixelRatio:2,_activePageId:""}).views((e=>({get _bleedVisible(){return console.warn("store._bleedVisible is deprecated. Please use store.bleedVisible instead."),e.bleedVisible},get selectedElements(){return e.selectedElementsIds.map((t=>{for(const o of e.pages)for(const e of o.children)if(e.id===t)return e})).filter((e=>!!e))},get selectedShapes(){const t=[];return e.selectedElementsIds.forEach((o=>{for(const n of e.pages)for(const e of n.children)e.id===o&&"group"!==e.type&&t.push(e),"group"===e.type&&e.id===o&&t.push(...e.children)})),t},get activePage(){return e.pages.slice().find((t=>t.id===e._activePageId))||(e.pages.length?e.pages[0]:null)}}))).actions((e=>({afterCreate(){e.history.canUndo},setCurrentTime(t){e.currentTime=t},setUnit({unit:t,dpi:o}){e.unit=t||e.unit,e.dpi=o||e.dpi},setRole(t){e.role=t},find(t){let o;return forEveryChild({children:e.pages},(e=>{!o&&t(e)&&(o=e)})),o},getElementById:t=>e.find((e=>e.id===t)),addPage(t){const o=exports.Page.create(Object.assign({id:(0,nanoid_1.nanoid)(10)},t));return e.pages.push(o),e._activePageId=o.id,o},selectPage(t){e._activePageId=t},selectElements(t){const o=t.map((t=>e.getElementById(t))).sort(((e,t)=>e.page.children.indexOf(e)-e.page.children.indexOf(t))).filter((e=>!!e)).map((e=>e.id));e.selectedElementsIds=(0,mobx_state_tree_1.cast)(o)},toggleBleed(t){e.bleedVisible=null!=t?t:!e.bleedVisible},toggleRulers(t){e.rulesVisible=null!=t?t:!e.rulesVisible},openSidePanel(t){e.openedSidePanel=t},setScale(t){e.scale=t},_setScaleToFit(t){e.scaleToFit=t},setElementsPixelRatio(t){e._elementsPixelRatio=t},setSize(t,o,n){e.pages.forEach((e=>{e.setSize({width:t,height:o,useMagic:n,softChange:!0})})),e.width=t,e.height=o},setPageZIndex(t,o){const n=e.pages.find((e=>e.id===t));n&&((0,mobx_state_tree_1.detach)(n),e.pages.remove(n),e.pages.splice(o,0,n))},deletePages(t){const o=e.pages.indexOf(e.activePage);t.forEach((t=>{const o=e.pages.find((e=>e.id===t));(0,mobx_state_tree_1.destroy)(o)}));const n=Math.min(e.pages.length-1,o),a=e.pages[n];a&&(e._activePageId=a.id),e.selectedElementsIds=(0,mobx_state_tree_1.cast)(e.selectedElementsIds.filter((t=>e.getElementById(t))))},groupElements(t){const o=t.map((t=>e.getElementById(t)));o.forEach((e=>{e&&(0,mobx_state_tree_1.detach)(e)}));const n=e.activePage,a=exports.GroupElement.create({id:(0,nanoid_1.nanoid)(10),children:(0,mobx_state_tree_1.cast)(o)});return n.children.push(a),e.selectedElementsIds=(0,mobx_state_tree_1.cast)([a.id]),a},ungroupElements(t){const o=t.map((t=>e.getElementById(t))),n=[];o.forEach((e=>{if(e&&"group"===e.type){const t=e.page,o=t.children.indexOf(e);e.children.forEach((e=>{n.push(e.id)})),e.children.forEach((e=>{(0,mobx_state_tree_1.detach)(e),t.children.push(e)})),t.children.splice(o,1)}})),e.selectedElementsIds=(0,mobx_state_tree_1.cast)(n)},deleteElements(t){t.forEach((t=>{e.pages.forEach((e=>{const o=e.children.find((e=>e.id===t));o&&(0,mobx_state_tree_1.destroy)(o)}))})),e.selectedElementsIds=(0,mobx_state_tree_1.cast)(e.selectedElementsIds.filter((t=>e.getElementById(t))))},on(t,o){if("change"===t){let t=e.toJSON();return(0,mobx_state_tree_1.onSnapshot)(e,(n=>{const a=e.toJSON();!(0,deep_equal_1.deepEqual)(t,a)&&(t=a,o(a))}))}},async _toCanvas({pixelRatio:t,ignoreBackground:o,pageId:n,mimeType:a,includeBleed:s}={}){var i;const r=t||1;n=n||(null===(i=e.pages[0])||void 0===i?void 0:i.id);const l=e.pages.find((e=>e.id===n));if(!l)throw new Error(`No page for export with id ${n}`);null==l||l.set({_exporting:!0});const d=await(0,wait_1.waitTillAvailable)((()=>konva_1.default.stages.find((e=>e.getAttr("pageId")===n))));if(!d)throw new Error(`Export is failed. Can not find stage for page ${n}. Looks like <Workspace /> component is not mounted, but it is required in order to process the export.`);await e.waitLoading();const c=d.findOne(".page-container");d.find("Transformer").forEach((e=>e.visible(!1))),c.find(".page-background").forEach((e=>e.shadowEnabled(!1))),c.find(".page-background").forEach((e=>e.strokeEnabled(!1))),c.find(".highlighter").forEach((e=>e.visible(!1)));const p=c.findOne(".page-background-group"),m=p.clip();p.clip({x:null,y:null,width:null,height:null});const _=c.findOne(".elements-container"),g=_.clip();_.clip({x:null,y:null,width:null,height:null});const h=c.find((e=>e.getAttr("hideInExport")));h.forEach((e=>{e.setAttr("oldVisible",e.visible()),e.hide()}));const u=c.find((e=>!e.visible()&&e.getAttr("editModeEnabled")));u.forEach((e=>{e.setAttr("oldVisible",e.visible()),e.show()})),o&&c.find(".page-background").forEach((e=>e.hide()));const b=s?l.bleed:0;let f=b;e.bleedVisible&&s?f=0:e.bleedVisible&&!s&&(f=-l.bleed);const x=document.createElement("canvas");x.width=(l.computedWidth+2*b)*r,x.height=(l.computedHeight+2*b)*r;const y=x.getContext("2d");"image/jpeg"===a&&(y.fillStyle="white",y.fillRect(0,0,x.width,x.height));const E=c.toCanvas({x:c.x()-f*c.scaleX(),y:c.y()-f*c.scaleY(),width:(l.computedWidth+2*b)*c.scaleX(),height:(l.computedHeight+2*b)*c.scaleY(),pixelRatio:1/c.scaleX()*r});return y.drawImage(E,0,0),konva_1.default.Util.releaseCanvas(E),o&&c.find(".page-background").forEach((e=>e.show())),h.forEach((e=>{e.visible(e.getAttr("oldVisible"))})),u.forEach((e=>{e.visible(e.getAttr("oldVisible"))})),c.find(".page-background").forEach((e=>e.shadowEnabled(!0))),c.find(".page-background").forEach((e=>e.strokeEnabled(!0))),d.find("Transformer").forEach((e=>e.visible(!0))),c.find(".highlighter").forEach((e=>e.visible(!0))),p.clip(m),_.clip(g),null==l||l.set({_exporting:!1}),x},async toDataURL({pixelRatio:t,ignoreBackground:o,pageId:n,mimeType:a,includeBleed:s,quality:i}={}){const r=await e._toCanvas({pixelRatio:t,ignoreBackground:o,pageId:n,mimeType:a,includeBleed:s}),l=r.toDataURL(a,i);return konva_1.default.Util.releaseCanvas(r),l},async toBlob({pixelRatio:t,ignoreBackground:o,pageId:n,mimeType:a,includeBleed:s,quality:i}={}){const r=await e._toCanvas({pixelRatio:t,ignoreBackground:o,pageId:n,mimeType:a,includeBleed:s}),l=new Promise((e=>{r.toBlob(e,a,i)}));return konva_1.default.Util.releaseCanvas(r),l},async saveAsImage(t={}){var{fileName:o}=t,n=__rest(t,["fileName"]);const a=n.mimeType||"image/png",s=a.split("/")[1];(0,download_1.downloadFile)(await e.toDataURL(n),o||"polotno."+s,a)},async _toPDF(t){const o=t.dpi||e.dpi,n=t.parallel||1,a=t.unit||("px"===e.unit?"mm":e.unit),s=t.pixelRatio||1,i=t.pageIds||e.pages.map((e=>e.id)),r=e.pages.filter((e=>i.includes(e.id))),l=await(0,pdf_1.getJsPDF)(),d=e=>(0,unit_1.pxToUnit)({px:e,unit:a,dpi:o}),c=r[0]||{},p=t.includeBleed?c.bleed:0,m=d(c.computedWidth+2*p),_=d(c.computedHeight+2*p);var g=new l({unit:a,orientation:m>_?"landscape":"portrait",format:[m,_],compress:!0,putOnlyUsedFonts:!0});g.deletePage(1);const h=e._elementsPixelRatio;e.setElementsPixelRatio(s),await new Promise((e=>setTimeout(e)));const u=((e,t)=>{for(var o=[],n=0;n<e.length;n+=t)o.push(e.slice(n,n+t));return o})(r,n);for(const o of u){const n=o.map((async o=>{const n=t.includeBleed?o.bleed:0,a=d(o.computedWidth+2*n),i=d(o.computedHeight+2*n);let r=0,l=s;for(;r<10;){r+=1,2===r&&console.error("Polotno can not export PDF with current settings. Quality is automatically reduced.");const n=await e.toDataURL(Object.assign(Object.assign({},t),{pageId:o.id,pixelRatio:l}));if(n.length>20)return{url:n,width:a,height:i};l*=.8}}));(await Promise.all(n)).forEach((({url:e,width:t,height:o})=>{g.addPage([t,o],t>o?"landscape":"portrait"),g.addImage(e,0,0,t,o,void 0,"FAST")}))}return e.setElementsPixelRatio(h),g},toPDFDataURL:async t=>(await e._toPDF(Object.assign({mimeType:"image/jpeg"},t))).output("datauristring"),async toHTML(){const t=e.toJSON();return(0,html_1.jsonToHTML)({json:t})},async saveAsHTML({filename:t}={}){const o=await e.toHTML(),n="data:text/html;base64,"+window.btoa(unescape(encodeURIComponent(o)));(0,download_1.downloadFile)(n,t||"polotno.html")},async saveAsPDF(t={}){var{fileName:o}=t,n=__rest(t,["fileName"]);(await e._toPDF(Object.assign({mimeType:"image/jpeg"},n))).save(o||"polotno.pdf")},async waitLoading(){await new Promise((e=>setTimeout(e,50))),await(0,loader_1.whenLoaded)()},toJSON:()=>({width:e.width,height:e.height,fonts:(0,mobx_state_tree_1.getSnapshot)(e.fonts),pages:(0,mobx_state_tree_1.getSnapshot)(e.pages),unit:e.unit,dpi:e.dpi}),loadJSON(t,o=!1){var n;const a=Object.assign({},t),s=e.pages.indexOf(e.activePage);let i=null===(n=a.pages[s]||a.pages[0])||void 0===n?void 0:n.id;a._activePageId=i;const r=Object.assign({},(0,mobx_state_tree_1.getSnapshot)(e));Object.assign(r,a),r.history=o?e.history.toJSON():{history:[],undoIdx:-1},(0,mobx_state_tree_1.applySnapshot)(e,r)},addFont(t){e.removeFont(t.fontFamily),e.fonts.push(t),e.loadFont(t.fontFamily)},removeFont(t){e.fonts.filter((e=>e.fontFamily===t)).forEach((e=>(0,mobx_state_tree_1.destroy)(e)))},async loadFont(t){const o=e.fonts.find((e=>e.fontFamily===t))||fonts.globalFonts.find((e=>e.fontFamily===t));o?fonts.injectCustomFont(o):fonts.injectGoogleFont(t),await fonts.loadFont(t)}}))),exports.createStore=createStore,exports.default=createStore;
|
|
1
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,o,n){void 0===n&&(n=o);var a=Object.getOwnPropertyDescriptor(t,o);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[o]}}),Object.defineProperty(e,n,a)}:function(e,t,o,n){void 0===n&&(n=o),e[n]=t[o]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var o in e)"default"!==o&&Object.prototype.hasOwnProperty.call(e,o)&&__createBinding(t,e,o);return __setModuleDefault(t,e),t},__rest=this&&this.__rest||function(e,t){var o={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(n=Object.getOwnPropertySymbols(e);a<n.length;a++)t.indexOf(n[a])<0&&Object.prototype.propertyIsEnumerable.call(e,n[a])&&(o[n[a]]=e[n[a]])}return o},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.createStore=exports.Store=exports.Font=exports.Page=exports.GroupElement=exports.registerShapeModel=exports.SVGElement=exports.LineElement=exports.VideoElement=exports.ImageElement=exports.TextElement=exports.Element=exports.Node=void 0;const mobx_state_tree_1=require("mobx-state-tree"),history_1=require("./history"),nanoid_1=require("nanoid"),konva_1=__importDefault(require("konva")),AnimatedGIF_1=__importDefault(require("gifshot/src/modules/core/AnimatedGIF")),getBase64GIF_1=__importDefault(require("gifshot/src/modules/core/getBase64GIF")),download_1=require("../utils/download"),pdf_1=require("../utils/pdf"),validate_key_1=require("../utils/validate-key"),fonts=__importStar(require("../utils/fonts")),loader_1=require("../utils/loader"),unit_1=require("../utils/unit"),deep_equal_1=require("../utils/deep-equal"),wait_1=require("../utils/wait"),html_1=require("../utils/html");(0,mobx_state_tree_1.setLivelinessChecking)("ignore");const forEveryChild=(e,t)=>{e.children&&e.children.forEach((e=>{t(e),forEveryChild(e,t)}))};exports.Node=mobx_state_tree_1.types.model("Node",{id:mobx_state_tree_1.types.identifier,type:"none",name:"",opacity:1,animations:mobx_state_tree_1.types.array(mobx_state_tree_1.types.frozen()),custom:mobx_state_tree_1.types.frozen(),visible:!0,selectable:!0,removable:!0,alwaysOnTop:!1,showInExport:!0}).postProcessSnapshot((e=>{const t=Object.assign({},e),o={};for(var n in t)"_"!==n[0]&&(o[n]=e[n]);return o})).views((e=>({get locked(){return!(e.draggable||e.contentEditable||e.styleEditable||e.resizable)},get page(){return(0,mobx_state_tree_1.getParentOfType)(e,exports.Page)},get store(){return(0,mobx_state_tree_1.getParentOfType)(e,exports.Store)},get top(){let t=e;for(;;){if(!(0,mobx_state_tree_1.hasParentOfType)(t,exports.GroupElement))return t;t=(0,mobx_state_tree_1.getParentOfType)(t,exports.GroupElement)}},get parent(){return(0,mobx_state_tree_1.hasParentOfType)(e,exports.GroupElement)?(0,mobx_state_tree_1.getParentOfType)(e,exports.GroupElement):(0,mobx_state_tree_1.hasParentOfType)(e,exports.Page)?(0,mobx_state_tree_1.getParentOfType)(e,exports.Page):(0,mobx_state_tree_1.hasParentOfType)(e,exports.Store)?(0,mobx_state_tree_1.getParentOfType)(e,exports.Store):null}}))).actions((e=>({toJSON:()=>Object.assign({},(0,mobx_state_tree_1.getSnapshot)(e))}))).actions((e=>({clone(t={}){const o=e.toJSON();return t.id=t.id||(0,nanoid_1.nanoid)(10),forEveryChild(o,(e=>{e.id=(0,nanoid_1.nanoid)(10)})),Object.assign(o,t),e.page.addElement(o)},set(t){Object.assign(e,t)},moveUp(){e.page.moveElementsUp([e.id])},moveTop(){e.page.moveElementsTop([e.id])},moveDown(){e.page.moveElementsDown([e.id])},moveBottom(){e.page.moveElementsBottom([e.id])},beforeDestroy(){e.store.history.endTransaction()}}))),exports.Element=exports.Node.named("Element").props({x:0,y:0,width:100,height:100,rotation:0,opacity:1,blurEnabled:!1,blurRadius:10,brightnessEnabled:!1,brightness:0,sepiaEnabled:!1,grayscaleEnabled:!1,shadowEnabled:!1,shadowBlur:5,shadowOffsetX:0,shadowOffsetY:0,shadowColor:"black",shadowOpacity:1,visible:!0,draggable:!0,resizable:!0,selectable:!0,contentEditable:!0,styleEditable:!0,alwaysOnTop:!1,showInExport:!0}).preProcessSnapshot((e=>{const t=Object.assign(Object.assign({},e),{x:e.x||0,y:e.y||0});return"width"in e&&(t.width=t.width||1),"height"in e&&(t.height=t.height||1),e.locked&&(t.draggable=!1,t.contentEditable=!1,t.styleEditable=!1,t.resizable=!1),t})).views((e=>({get a(){return e},animated:t=>e[t]}))),exports.TextElement=exports.Element.named("Text").props({type:"text",text:"",placeholder:"",fontSize:14,fontFamily:"Roboto",fontStyle:"normal",fontWeight:"normal",textDecoration:"",fill:"black",align:"center",width:100,height:0,verticalAlign:"top",strokeWidth:0,stroke:"black",lineHeight:mobx_state_tree_1.types.optional(mobx_state_tree_1.types.union(mobx_state_tree_1.types.number,mobx_state_tree_1.types.string),1.2),letterSpacing:0,_editModeEnabled:!1,backgroundEnabled:!1,backgroundColor:"#7ED321",backgroundOpacity:1,backgroundCornerRadius:.5,backgroundPadding:.5}).preProcessSnapshot((e=>Object.assign({},e))).actions((e=>({toggleEditMode(t){e._editModeEnabled=null!=t?t:!e._editModeEnabled,e._editModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction()}}))),exports.ImageElement=exports.Element.named("Image").props({type:"image",width:100,height:100,src:"",cropX:0,cropY:0,cropWidth:1,cropHeight:1,cornerRadius:0,flipX:!1,flipY:!1,clipSrc:"",borderColor:"black",borderSize:0,keepRatio:!1,_cropModeEnabled:!1}).actions((e=>({toggleCropMode(t){e._cropModeEnabled=null!=t?t:!e._cropModeEnabled,e._cropModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction()}}))),exports.VideoElement=exports.ImageElement.named("Video").props({type:"video",duration:0}),exports.LineElement=exports.Element.named("Line").props({type:"line",width:400,height:10,color:"black",dash:mobx_state_tree_1.types.array(mobx_state_tree_1.types.number),startHead:"",endHead:""}).actions((e=>({}))),exports.SVGElement=exports.Element.named("SVG").props({type:"svg",src:"",maskSrc:"",cropX:0,cropY:0,cropWidth:1,cropHeight:1,keepRatio:!0,flipX:!1,flipY:!1,width:100,height:100,borderColor:"black",borderSize:0,cornerRadius:0,colorsReplace:mobx_state_tree_1.types.map(mobx_state_tree_1.types.string)}).preProcessSnapshot((e=>Object.assign(Object.assign({},e),{src:e.src||e.svgSource}))).actions((e=>({replaceColor(t,o){e.colorsReplace.set(t,o)}})));const ADDITIONAL_TYPES=[];function registerShapeModel(e){const t=e.type;if(!t)throw new Error('You must pass "type" attribute to custom model.');const o=exports.Element.named(t).props(e);TYPES_MAP[t]=o,ADDITIONAL_TYPES.push(o)}exports.registerShapeModel=registerShapeModel;const additionalTypesUnion=[...new Array(20)].map(((e,t)=>mobx_state_tree_1.types.late((()=>ADDITIONAL_TYPES[t])))),ElementTypes=mobx_state_tree_1.types.union({dispatcher:e=>{const t=TYPES_MAP[e.type];if(!t)throw new Error(`Unknown element type: "${e.type}"`);return t}},exports.SVGElement,exports.TextElement,exports.ImageElement,exports.LineElement,exports.VideoElement,mobx_state_tree_1.types.late((()=>exports.GroupElement)),...additionalTypesUnion);exports.GroupElement=exports.Node.named("Group").props({type:"group",children:mobx_state_tree_1.types.array(ElementTypes)}).views((e=>({get draggable(){let t=!0;return forEveryChild(e,(e=>{e.draggable||(t=!1)})),t},get resizable(){let t=!0;return forEveryChild(e,(e=>{e.resizable||(t=!1)})),t},get contentEditable(){let t=!0;return forEveryChild(e,(e=>{e.contentEditable||(t=!1)})),t},get styleEditable(){let t=!0;return forEveryChild(e,(e=>{e.styleEditable||(t=!1)})),t},get locked(){let t=!0;return forEveryChild(e,(e=>{e.locked||(t=!1)})),t}}))).actions((e=>({set(t){var{draggable:o,contentEditable:n,styleEditable:a,resizable:i}=t,s=__rest(t,["draggable","contentEditable","styleEditable","resizable"]);void 0!==o&&forEveryChild(e,(e=>{e.set({draggable:o})})),void 0!==n&&forEveryChild(e,(e=>{e.set({contentEditable:n})})),void 0!==a&&forEveryChild(e,(e=>{e.set({styleEditable:a})})),void 0!==i&&forEveryChild(e,(e=>{e.set({resizable:i})})),Object.assign(e,s)}})));const TYPES_MAP={svg:exports.SVGElement,text:exports.TextElement,image:exports.ImageElement,group:exports.GroupElement,line:exports.LineElement,video:exports.VideoElement};function createStore({key:e,showCredit:t}={key:"",showCredit:!1}){const o=exports.Store.create();return(0,validate_key_1.validateKey)(e,t),o}exports.Page=mobx_state_tree_1.types.model("Page",{id:mobx_state_tree_1.types.identifier,children:mobx_state_tree_1.types.array(ElementTypes),width:mobx_state_tree_1.types.optional(mobx_state_tree_1.types.union(mobx_state_tree_1.types.number,mobx_state_tree_1.types.literal("auto")),"auto"),height:mobx_state_tree_1.types.optional(mobx_state_tree_1.types.union(mobx_state_tree_1.types.number,mobx_state_tree_1.types.literal("auto")),"auto"),background:"white",bleed:0,custom:mobx_state_tree_1.types.frozen(),_exporting:!1}).postProcessSnapshot((e=>{const t=Object.assign({},e),o={};for(var n in t)"_"!==n[0]&&(o[n]=e[n]);return o})).views((e=>({get store(){return(0,mobx_state_tree_1.getParentOfType)(e,exports.Store)},get animatedChildren(){}}))).views((e=>({get computedWidth(){return"auto"===e.width?e.store.width:e.width},get computedHeight(){return"auto"===e.height?e.store.height:e.height}}))).actions((e=>({toJSON:()=>JSON.parse(JSON.stringify((0,mobx_state_tree_1.getSnapshot)(e))),_forEachElementUp(t,o){const n=t.map((t=>({id:t,index:e.children.findIndex((e=>e.id===t))})));n.sort(((e,t)=>t.index-e.index));for(const{index:a}of n){if(-1==a)continue;const n=a<e.children.length-1&&e.children[a+1],i=t.indexOf(null==n?void 0:n.id)>=0;a===e.children.length-1||i||o(a)}},_forEachElementDown(t,o){const n=t.map((t=>({id:t,index:e.children.findIndex((e=>e.id===t))})));n.sort(((e,t)=>e.index-t.index));for(const{index:a}of n){if(-1==a)continue;const n=a>0&&e.children[a-1],i=t.indexOf(null==n?void 0:n.id)>=0;0===a||i||o(a)}return!1}}))).actions((e=>({clone(t={}){const o=e.toJSON();o.children.forEach((e=>{e.id=(0,nanoid_1.nanoid)(10),forEveryChild(e,(e=>{e.id=(0,nanoid_1.nanoid)(10)}))}));const n=Object.assign(Object.assign(Object.assign({},o),{id:(0,nanoid_1.nanoid)(10)}),t),a=e.store.addPage(n),i=e.store.pages.indexOf(e);a.setZIndex(i+1),a.select()},setZIndex(t){e.store.setPageZIndex(e.id,t)},set(t){Object.assign(e,t)},select(){e.store.selectPage(e.id)},addElement(t){const o=TYPES_MAP[t.type];if(!o)return void console.error("Can not find model with type "+t.type);t.children&&t.children.forEach((e=>{e.id=(0,nanoid_1.nanoid)(10)}));const n=o.create(Object.assign({id:(0,nanoid_1.nanoid)(10)},t));return e.children.push(n),n.selectable&&e.store.selectElements([n.id]),n},canMoveElementsUp(t){let o=!1;return e._forEachElementUp(t,(()=>{o=o||!0})),o},moveElementsUp(t){e._forEachElementUp(t,(t=>{const o=e.children[t];(0,mobx_state_tree_1.detach)(o),e.children.splice(t+1,0,o)}))},canMoveElementsTop(e){return this.canMoveElementsUp(e)},moveElementsTop(t){const o=[],n=[];e.children.forEach((e=>{t.indexOf(e.id)>=0?o.push(e):n.push(e)})),e.children.replace(n.concat(o))},canMoveElementsDown(t){let o=!1;return e._forEachElementDown(t,(()=>{o=o||!0})),o},moveElementsDown(t){e._forEachElementDown(t,(t=>{const o=e.children[t];(0,mobx_state_tree_1.detach)(o),e.children.splice(t-1,0,o)}))},canMoveElementsBottom(e){return this.canMoveElementsDown(e)},moveElementsBottom(t){const o=[],n=[];e.children.forEach((e=>{t.indexOf(e.id)>=0?o.push(e):n.push(e)})),e.children.replace(o.concat(n))},setElementZIndex(t,o){const n=e.children.find((e=>e.id===t));n&&((0,mobx_state_tree_1.detach)(n),e.children.remove(n),e.children.splice(o,0,n))},setSize({width:t,height:o,useMagic:n,softChange:a}){if(n){const n=t/e.computedWidth,a=o/e.computedHeight;for(const t of e.children)t.set({x:t.x*n,y:t.y*a}),"text"===t.type?t.set({fontSize:t.fontSize*n,width:Math.max(t.width*n,2)}):"image"===t.type?t.set({width:t.width*n,height:t.height*a}):"svg"===t.type&&t.set({width:Math.max(t.width*n,2),height:Math.max(t.height*n,2)})}"auto"!==e.width||a||(e.width=t),"auto"!==e.height||a||(e.height=o)}}))).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])}}))),exports.Font=mobx_state_tree_1.types.model("Font",{fontFamily:mobx_state_tree_1.types.string,url:mobx_state_tree_1.types.optional(mobx_state_tree_1.types.string,""),styles:mobx_state_tree_1.types.frozen()}).preProcessSnapshot((e=>Object.assign(Object.assign({},e),{fontFamily:e.fontFamily||e.name}))),exports.Store=mobx_state_tree_1.types.model("Store",{role:"",pages:mobx_state_tree_1.types.array(exports.Page),fonts:mobx_state_tree_1.types.array(exports.Font),width:1080,height:1080,currentTime:0,isPlaying:!1,scale:1,scaleToFit:1,unit:"px",dpi:72,bleedVisible:!1,rulesVisible:!1,openedSidePanel:"",selectedElementsIds:mobx_state_tree_1.types.array(mobx_state_tree_1.types.string),history:mobx_state_tree_1.types.optional(history_1.UndoManager,{targetPath:"../pages"}),_elementsPixelRatio:2,_activePageId:""}).views((e=>({get _bleedVisible(){return console.warn("store._bleedVisible is deprecated. Please use store.bleedVisible instead."),e.bleedVisible},get selectedElements(){return e.selectedElementsIds.map((t=>{for(const o of e.pages)for(const e of o.children)if(e.id===t)return e})).filter((e=>!!e))},get children(){return e.pages},get selectedShapes(){const t=[];return e.selectedElementsIds.forEach((o=>{for(const n of e.pages)for(const e of n.children)e.id===o&&"group"!==e.type&&t.push(e),"group"===e.type&&e.id===o&&t.push(...e.children)})),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 forEveryChild(e,(e=>{"video"===e.type&&(t=Math.max(t,e.duration))})),t}}))).actions((e=>({afterCreate(){e.history.canUndo},setCurrentTime(t){e.currentTime=t},play(){e.currentTime=0,e.isPlaying=!0,requestAnimationFrame(e.seek)},seek(){e.currentTime+=1e3/60,e.isPlaying&&e.currentTime<e.duration?requestAnimationFrame(e.seek):e.stop()},stop(){e.isPlaying=!1,e.currentTime=0},setUnit({unit:t,dpi:o}){e.unit=t||e.unit,e.dpi=o||e.dpi},setRole(t){e.role=t},find(t){let o;return forEveryChild({children:e.pages},(e=>{!o&&t(e)&&(o=e)})),o},getElementById:t=>e.find((e=>e.id===t)),addPage(t){const o=exports.Page.create(Object.assign({id:(0,nanoid_1.nanoid)(10)},t));return e.pages.push(o),e._activePageId=o.id,o},selectPage(t){e._activePageId=t},selectElements(t){const o=t.map((t=>e.getElementById(t))).sort(((e,t)=>e.page.children.indexOf(e)-e.page.children.indexOf(t))).filter((e=>!!e)).map((e=>e.id));e.selectedElementsIds=(0,mobx_state_tree_1.cast)(o)},toggleBleed(t){e.bleedVisible=null!=t?t:!e.bleedVisible},toggleRulers(t){e.rulesVisible=null!=t?t:!e.rulesVisible},openSidePanel(t){e.openedSidePanel=t},setScale(t){e.scale=t},_setScaleToFit(t){e.scaleToFit=t},setElementsPixelRatio(t){e._elementsPixelRatio=t},setSize(t,o,n){e.pages.forEach((e=>{e.setSize({width:t,height:o,useMagic:n,softChange:!0})})),e.width=t,e.height=o},setPageZIndex(t,o){const n=e.pages.find((e=>e.id===t));n&&((0,mobx_state_tree_1.detach)(n),e.pages.remove(n),e.pages.splice(o,0,n))},deletePages(t){const o=e.pages.indexOf(e.activePage);t.forEach((t=>{const o=e.pages.find((e=>e.id===t));(0,mobx_state_tree_1.destroy)(o)}));const n=Math.min(e.pages.length-1,o),a=e.pages[n];a&&(e._activePageId=a.id),e.selectedElementsIds=(0,mobx_state_tree_1.cast)(e.selectedElementsIds.filter((t=>e.getElementById(t))))},groupElements(t){const o=t.map((t=>e.getElementById(t)));o.forEach((e=>{e&&(0,mobx_state_tree_1.detach)(e)}));const n=e.activePage,a=exports.GroupElement.create({id:(0,nanoid_1.nanoid)(10),children:(0,mobx_state_tree_1.cast)(o)});return n.children.push(a),e.selectedElementsIds=(0,mobx_state_tree_1.cast)([a.id]),a},ungroupElements(t){const o=t.map((t=>e.getElementById(t))),n=[];o.forEach((e=>{if(e&&"group"===e.type){const t=e.page,o=t.children.indexOf(e);e.children.forEach((e=>{n.push(e.id)})),e.children.forEach((e=>{(0,mobx_state_tree_1.detach)(e),t.children.push(e)})),t.children.splice(o,1)}})),e.selectedElementsIds=(0,mobx_state_tree_1.cast)(n)},deleteElements(t){t.forEach((t=>{e.pages.forEach((e=>{const o=e.children.find((e=>e.id===t));o&&(0,mobx_state_tree_1.destroy)(o)}))})),e.selectedElementsIds=(0,mobx_state_tree_1.cast)(e.selectedElementsIds.filter((t=>e.getElementById(t))))},on(t,o){if("change"===t){let t=e.toJSON();return(0,mobx_state_tree_1.onSnapshot)(e,(n=>{const a=e.toJSON();!(0,deep_equal_1.deepEqual)(t,a)&&(t=a,o(a))}))}},async _toCanvas({pixelRatio:t,ignoreBackground:o,pageId:n,mimeType:a,includeBleed:i}={}){var s;const r=t||1;n=n||(null===(s=e.pages[0])||void 0===s?void 0:s.id);const l=e.pages.find((e=>e.id===n));if(!l)throw new Error(`No page for export with id ${n}`);null==l||l.set({_exporting:!0});const d=await(0,wait_1.waitTillAvailable)((()=>konva_1.default.stages.find((e=>e.getAttr("pageId")===n))));if(!d)throw new Error(`Export is failed. Can not find stage for page ${n}. Looks like <Workspace /> component is not mounted, but it is required in order to process the export.`);await e.waitLoading();const c=d.findOne(".page-container");d.find("Transformer").forEach((e=>e.visible(!1))),c.find(".page-background").forEach((e=>e.shadowEnabled(!1))),c.find(".page-background").forEach((e=>e.strokeEnabled(!1))),c.find(".highlighter").forEach((e=>e.visible(!1)));const p=c.findOne(".page-background-group"),m=p.clip();p.clip({x:null,y:null,width:null,height:null});const _=c.findOne(".elements-container"),g=_.clip();_.clip({x:null,y:null,width:null,height:null});const h=c.find((e=>e.getAttr("hideInExport")));h.forEach((e=>{e.setAttr("oldVisible",e.visible()),e.hide()}));const u=c.find((e=>!e.visible()&&e.getAttr("editModeEnabled")));u.forEach((e=>{e.setAttr("oldVisible",e.visible()),e.show()})),o&&c.find(".page-background").forEach((e=>e.hide()));const b=i?l.bleed:0;let f=b;e.bleedVisible&&i?f=0:e.bleedVisible&&!i&&(f=-l.bleed);const x=document.createElement("canvas");x.width=(l.computedWidth+2*b)*r,x.height=(l.computedHeight+2*b)*r;const y=x.getContext("2d");"image/jpeg"===a&&(y.fillStyle="white",y.fillRect(0,0,x.width,x.height));const E=c.toCanvas({x:c.x()-f*c.scaleX(),y:c.y()-f*c.scaleY(),width:(l.computedWidth+2*b)*c.scaleX(),height:(l.computedHeight+2*b)*c.scaleY(),pixelRatio:1/c.scaleX()*r});return y.drawImage(E,0,0),konva_1.default.Util.releaseCanvas(E),o&&c.find(".page-background").forEach((e=>e.show())),h.forEach((e=>{e.visible(e.getAttr("oldVisible"))})),u.forEach((e=>{e.visible(e.getAttr("oldVisible"))})),c.find(".page-background").forEach((e=>e.shadowEnabled(!0))),c.find(".page-background").forEach((e=>e.strokeEnabled(!0))),d.find("Transformer").forEach((e=>e.visible(!0))),c.find(".highlighter").forEach((e=>e.visible(!0))),p.clip(m),_.clip(g),null==l||l.set({_exporting:!1}),x},async toDataURL({pixelRatio:t,ignoreBackground:o,pageId:n,mimeType:a,includeBleed:i,quality:s}={}){const r=await e._toCanvas({pixelRatio:t,ignoreBackground:o,pageId:n,mimeType:a,includeBleed:i}),l=r.toDataURL(a,s);return konva_1.default.Util.releaseCanvas(r),l},async toBlob({pixelRatio:t,ignoreBackground:o,pageId:n,mimeType:a,includeBleed:i,quality:s}={}){const r=await e._toCanvas({pixelRatio:t,ignoreBackground:o,pageId:n,mimeType:a,includeBleed:i}),l=new Promise((e=>{r.toBlob(e,a,s)}));return konva_1.default.Util.releaseCanvas(r),l},async saveAsImage(t={}){var{fileName:o}=t,n=__rest(t,["fileName"]);const a=n.mimeType||"image/png",i=a.split("/")[1];(0,download_1.downloadFile)(await e.toDataURL(n),o||"polotno."+i,a)},async _toPDF(t){const o=t.dpi||e.dpi,n=t.parallel||1,a=t.unit||("px"===e.unit?"mm":e.unit),i=t.pixelRatio||1,s=t.pageIds||e.pages.map((e=>e.id)),r=e.pages.filter((e=>s.includes(e.id))),l=await(0,pdf_1.getJsPDF)(),d=e=>(0,unit_1.pxToUnit)({px:e,unit:a,dpi:o}),c=r[0]||{},p=t.includeBleed?c.bleed:0,m=d(c.computedWidth+2*p),_=d(c.computedHeight+2*p);var g=new l({unit:a,orientation:m>_?"landscape":"portrait",format:[m,_],compress:!0,putOnlyUsedFonts:!0});g.deletePage(1);const h=e._elementsPixelRatio;e.setElementsPixelRatio(i),await new Promise((e=>setTimeout(e)));const u=((e,t)=>{for(var o=[],n=0;n<e.length;n+=t)o.push(e.slice(n,n+t));return o})(r,n);for(const o of u){const n=o.map((async o=>{const n=t.includeBleed?o.bleed:0,a=d(o.computedWidth+2*n),s=d(o.computedHeight+2*n);let r=0,l=i;for(;r<10;){r+=1,2===r&&console.error("Polotno can not export PDF with current settings. Quality is automatically reduced.");const n=await e.toDataURL(Object.assign(Object.assign({},t),{pageId:o.id,pixelRatio:l}));if(n.length>20)return{url:n,width:a,height:s};l*=.8}}));(await Promise.all(n)).forEach((({url:e,width:t,height:o})=>{g.addPage([t,o],t>o?"landscape":"portrait"),g.addImage(e,0,0,t,o,void 0,"FAST")}))}return e.setElementsPixelRatio(h),g},toPDFDataURL:async t=>(await e._toPDF(Object.assign({mimeType:"image/jpeg"},t))).output("datauristring"),async toHTML(){const t=e.toJSON();return(0,html_1.jsonToHTML)({json:t})},async saveAsHTML({filename:t}={}){const o=await e.toHTML(),n="data:text/html;base64,"+window.btoa(unescape(encodeURIComponent(o)));(0,download_1.downloadFile)(n,t||"polotno.html")},async saveAsGIF(){const t=new AnimatedGIF_1.default({numWorkers:1,gifWidth:e.width,gifHeight:e.height});for(let o=0;o<3;o++){e.setCurrentTime(1*o);const n=await e._toCanvas();t.addFrame(n)}const o=await new Promise((e=>{console.log(1),(0,getBase64GIF_1.default)(t,(t=>{console.log(2),e(t)}))}));(0,download_1.downloadFile)(o,"polotno.gif")},async saveAsPDF(t={}){var{fileName:o}=t,n=__rest(t,["fileName"]);(await e._toPDF(Object.assign({mimeType:"image/jpeg"},n))).save(o||"polotno.pdf")},async waitLoading(){await new Promise((e=>setTimeout(e,50))),await(0,loader_1.whenLoaded)()},toJSON:()=>({width:e.width,height:e.height,fonts:(0,mobx_state_tree_1.getSnapshot)(e.fonts),pages:(0,mobx_state_tree_1.getSnapshot)(e.pages),unit:e.unit,dpi:e.dpi}),loadJSON(t,o=!1){var n;const a=Object.assign({},t),i=e.pages.indexOf(e.activePage);let s=null===(n=a.pages[i]||a.pages[0])||void 0===n?void 0:n.id;a._activePageId=s;const r=Object.assign({},(0,mobx_state_tree_1.getSnapshot)(e));Object.assign(r,a),r.history=o?e.history.toJSON():{history:[],undoIdx:-1},(0,mobx_state_tree_1.applySnapshot)(e,r)},addFont(t){e.removeFont(t.fontFamily),e.fonts.push(t),e.loadFont(t.fontFamily)},removeFont(t){e.fonts.filter((e=>e.fontFamily===t)).forEach((e=>(0,mobx_state_tree_1.destroy)(e)))},async loadFont(t){const o=e.fonts.find((e=>e.fontFamily===t))||fonts.globalFonts.find((e=>e.fontFamily===t));o?fonts.injectCustomFont(o):fonts.injectGoogleFont(t),await fonts.loadFont(t)}}))),exports.createStore=createStore,exports.default=createStore;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polotno",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Design Editor Framework",
|
|
5
5
|
"author": "Anton Lavrenov",
|
|
6
6
|
"keywords": [
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
"@blueprintjs/popover2": "^1.13.3",
|
|
15
15
|
"@blueprintjs/select": "^4.9.3",
|
|
16
16
|
"@meronex/icons": "^4.0.0",
|
|
17
|
+
"gif.js": "^0.2.0",
|
|
18
|
+
"gifshot": "^0.4.5",
|
|
17
19
|
"gradient-parser": "^1.0.2",
|
|
18
20
|
"konva": "^8.4.2",
|
|
19
21
|
"mobx": "6.8.0",
|