polotno 0.36.4 → 0.36.5

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/model/store.d.ts CHANGED
@@ -648,7 +648,6 @@ export declare const Page: import("mobx-state-tree").IModelType<{
648
648
  id: import("mobx-state-tree").ISimpleType<string>;
649
649
  children: import("mobx-state-tree").IArrayType<import("mobx-state-tree").IAnyType>;
650
650
  background: import("mobx-state-tree").IType<string | undefined, string, string>;
651
- bleed: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").IArrayType<import("mobx-state-tree").ISimpleType<number>>, [undefined]>;
652
651
  _exporting: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
653
652
  custom: import("mobx-state-tree").IType<any, any, any>;
654
653
  }, {
@@ -687,7 +686,6 @@ export declare const Store: import("mobx-state-tree").IModelType<{
687
686
  id: import("mobx-state-tree").ISimpleType<string>;
688
687
  children: import("mobx-state-tree").IArrayType<import("mobx-state-tree").IAnyType>;
689
688
  background: import("mobx-state-tree").IType<string | undefined, string, string>;
690
- bleed: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").IArrayType<import("mobx-state-tree").ISimpleType<number>>, [undefined]>;
691
689
  _exporting: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
692
690
  custom: import("mobx-state-tree").IType<any, any, any>;
693
691
  }, {
@@ -1011,7 +1009,6 @@ export declare const Store: import("mobx-state-tree").IModelType<{
1011
1009
  id: string;
1012
1010
  children: import("mobx-state-tree").IMSTArray<import("mobx-state-tree").IAnyType> & import("mobx-state-tree").IStateTreeNode<import("mobx-state-tree").IArrayType<import("mobx-state-tree").IAnyType>>;
1013
1011
  background: string;
1014
- bleed: import("mobx-state-tree").IMSTArray<import("mobx-state-tree").ISimpleType<number>> & import("mobx-state-tree").IStateTreeNode<import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").IArrayType<import("mobx-state-tree").ISimpleType<number>>, [undefined]>>;
1015
1012
  _exporting: boolean;
1016
1013
  custom: any;
1017
1014
  } & import("mobx-state-tree/dist/internal").NonEmptyObject & {
@@ -1031,7 +1028,6 @@ export declare const Store: import("mobx-state-tree").IModelType<{
1031
1028
  id: import("mobx-state-tree").ISimpleType<string>;
1032
1029
  children: import("mobx-state-tree").IArrayType<import("mobx-state-tree").IAnyType>;
1033
1030
  background: import("mobx-state-tree").IType<string | undefined, string, string>;
1034
- bleed: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").IArrayType<import("mobx-state-tree").ISimpleType<number>>, [undefined]>;
1035
1031
  _exporting: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
1036
1032
  custom: import("mobx-state-tree").IType<any, any, any>;
1037
1033
  }, {
@@ -1057,7 +1053,6 @@ export declare const Store: import("mobx-state-tree").IModelType<{
1057
1053
  id: string;
1058
1054
  children: import("mobx-state-tree").IMSTArray<import("mobx-state-tree").IAnyType> & import("mobx-state-tree").IStateTreeNode<import("mobx-state-tree").IArrayType<import("mobx-state-tree").IAnyType>>;
1059
1055
  background: string;
1060
- bleed: import("mobx-state-tree").IMSTArray<import("mobx-state-tree").ISimpleType<number>> & import("mobx-state-tree").IStateTreeNode<import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").IArrayType<import("mobx-state-tree").ISimpleType<number>>, [undefined]>>;
1061
1056
  _exporting: boolean;
1062
1057
  custom: any;
1063
1058
  } & import("mobx-state-tree/dist/internal").NonEmptyObject & {
@@ -1077,7 +1072,6 @@ export declare const Store: import("mobx-state-tree").IModelType<{
1077
1072
  id: import("mobx-state-tree").ISimpleType<string>;
1078
1073
  children: import("mobx-state-tree").IArrayType<import("mobx-state-tree").IAnyType>;
1079
1074
  background: import("mobx-state-tree").IType<string | undefined, string, string>;
1080
- bleed: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").IArrayType<import("mobx-state-tree").ISimpleType<number>>, [undefined]>;
1081
1075
  _exporting: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
1082
1076
  custom: import("mobx-state-tree").IType<any, any, any>;
1083
1077
  }, {
package/model/store.js CHANGED
@@ -1 +1 @@
1
- "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,o,s){void 0===s&&(s=o),Object.defineProperty(e,s,{enumerable:!0,get:function(){return t[o]}})}:function(e,t,o,s){void 0===s&&(s=o),e[s]=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 s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(o[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(s=Object.getOwnPropertySymbols(e);r<s.length;r++)t.indexOf(s[r])<0&&Object.prototype.propertyIsEnumerable.call(e,s[r])&&(o[s[r]]=e[s[r]])}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.registerShapeModel=exports.SVGElement=exports.ImageElement=exports.TextElement=exports.Element=void 0;const mobx_state_tree_1=require("mobx-state-tree"),undo_manager_1=require("./undo-manager"),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")),svg_1=require("../utils/svg"),loader_1=require("../utils/loader");(0,mobx_state_tree_1.setLivelinessChecking)("ignore"),exports.Element=mobx_state_tree_1.types.model("Element",{id:mobx_state_tree_1.types.identifier,type:"none",x:0,y:0,rotation:0,opacity:1,visible:!0,locked:!1,blurEnabled:!1,blurRadius:10,brightnessEnabled:!1,brightness:0,sepiaEnabled:!1,grayscaleEnabled:!1,shadowEnabled:!1,shadowBlur:5,shadowOffsetX:0,shadowOffsetY:0,shadowColor:"black",custom:mobx_state_tree_1.types.frozen(),selectable:!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),t})).postProcessSnapshot((e=>{const t=Object.assign({},e),o={};for(var s in t)"_"!==s[0]&&(o[s]=e[s]);return o})).views((e=>({get page(){return(0,mobx_state_tree_1.getParentOfType)(e,exports.Page)},get store(){return(0,mobx_state_tree_1.getParentOfType)(e,exports.Store)}}))).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),Object.assign(o,t),e.page.addElement(o)},set(t){Object.assign(e,t)},moveUp(){e.page.moveElementUp(e.id)},moveTop(){e.page.moveElementTop(e.id)},moveDown(){e.page.moveElementDown(e.id)},moveBottom(){e.page.moveElementBottom(e.id)},beforeDestroy(){e.store.history.endTransaction()}}))),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:14,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}).preProcessSnapshot((e=>Object.assign(Object.assign({},e),{fontSize:e.fontSize||0}))).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,_cropModeEnabled:!1}).actions((e=>({toggleCropMode(t){e._cropModeEnabled=null!=t?t:!e._cropModeEnabled,e._cropModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction()}}))),exports.SVGElement=exports.Element.named("SVG").props({type:"svg",src:"",maskSrc:"",__svgString:"",cropX:0,cropY:0,cropWidth:1,cropHeight:1,keepRatio:!0,flipX:!1,flipY:!1,width:100,height:100,borderColor:"black",borderSize: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}))).views((e=>({get colors(){return e.__svgString?(0,svg_1.getColors)(e.__svgString):[]},get __finalSrc(){return e.__svgString?(0,svg_1.replaceColors)(e.__svgString,e.colorsReplace):this.src},get __isLoaded(){if(!e.__svgString)return!1;return!(Array.from(e.colorsReplace.keys()).length>0)||e.__finalSrc!==e.src}}))).actions((e=>{let t=()=>{};return{async _loadSVG(){if(!e.src)return;const t=await(0,svg_1.urlToString)(e.src);(0,mobx_state_tree_1.isAlive)(e)&&(0,mobx_state_tree_1.hasParent)(e)&&e.store.history.ignore((()=>{e.set({__svgString:(0,svg_1.fixSize)(t)})}))},async afterCreate(){e._loadSVG();let o=e.src;t=(0,mobx_state_tree_1.onSnapshot)(e,(t=>{t.src===o&&e.__svgString||(e._loadSVG(),o=e.src)}))},beforeDestroy(){t()},replaceColor(t,o){e.colorsReplace.set(t,o)}}}));const TYPES_MAP={svg:exports.SVGElement,text:exports.TextElement,image:exports.ImageElement},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,...additionalTypesUnion),ChildrenType=mobx_state_tree_1.types.array(ElementTypes);function createStore({key:e,showCredit:t}={key:"",showCredit:!1}){const o=exports.Store.create();return o.__checkKey(e,t),o}exports.Page=mobx_state_tree_1.types.model("Page",{id:mobx_state_tree_1.types.identifier,children:ChildrenType,background:"white",bleed:mobx_state_tree_1.types.optional(mobx_state_tree_1.types.array(mobx_state_tree_1.types.number),[0,0,0,0]),_exporting:!1,custom:mobx_state_tree_1.types.frozen()}).postProcessSnapshot((e=>{const t=Object.assign({},e),o={};for(var s in t)"_"!==s[0]&&(o[s]=e[s]);return o})).views((e=>({get store(){return(0,mobx_state_tree_1.getParentOfType)(e,exports.Store)}}))).actions((e=>({toJSON:()=>Object.assign({},(0,mobx_state_tree_1.getSnapshot)(e)),clone(t){const o=e.children.map((e=>{const t=e.toJSON();return t.id=(0,nanoid_1.nanoid)(10),t})),s=Object.assign({id:(0,nanoid_1.nanoid)(10),children:o,background:e.background},t),r=e.store.addPage(s),n=e.store.pages.indexOf(e);r.setZIndex(n+1),r.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);const s=o.create(Object.assign({id:(0,nanoid_1.nanoid)(10)},t));return e.children.push(s),s.selectable&&e.store.selectElements([s.id]),s},moveElementUp(t){const o=e.children.findIndex((e=>e.id===t)),s=e.children[o];(0,mobx_state_tree_1.detach)(s),e.children.remove(s),e.children.splice(o+1,0,s)},moveElementDown(t){const o=e.children.findIndex((e=>e.id===t)),s=e.children[o];(0,mobx_state_tree_1.detach)(s),e.children.remove(s),e.children.splice(o-1,0,s)},moveElementTop(t){const o=e.children.findIndex((e=>e.id===t)),s=e.children[o];(0,mobx_state_tree_1.detach)(s),e.children.remove(s),e.children.push(s)},moveElementBottom(t){const o=e.children.findIndex((e=>e.id===t)),s=e.children[o];(0,mobx_state_tree_1.detach)(s),e.children.remove(s),e.children.splice(0,0,s)}}))),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,scale:1,scaleToFit:1,openedSidePanel:"",selectedElementsIds:mobx_state_tree_1.types.array(mobx_state_tree_1.types.string),history:mobx_state_tree_1.types.optional(undo_manager_1.UndoManager,{targetPath:"../pages"}),_elementsPixelRatio:2,_showCredit:!1,_activePageId:""}).views((e=>({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 activePage(){return e.pages.slice().find((t=>t.id===e._activePageId))||(e.pages.length?e.pages[0]:null)}}))).actions((e=>({async __checkKey(t,o){const s=await(0,validate_key_1.validateKey)(t);e.__(s,o)},__(t,o){e._showCredit=!t||o},setRole(t){e.role=t},getElementById(t){for(const o of e.pages)for(const e of o.children)if(e.id===t)return e},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){e.selectedElementsIds=(0,mobx_state_tree_1.cast)(t)},openSidePanel(t){e.openedSidePanel=t},setScale(t){e.scale=t},_setScaleToFit(t){e.scaleToFit=t},setElementsPixelRatio(t){e._elementsPixelRatio=t},setSize(t,o,s){if(s){const s=t/e.width,r=o/e.height;for(const t of e.pages)for(const e of t.children)e.set({x:e.x*s,y:e.y*r}),"text"===e.type?e.set({fontSize:e.fontSize*s,width:Math.max(e.width*s,2)}):"image"===e.type?e.set({width:e.width*s,height:e.height*r}):"svg"===e.type&&e.set({width:Math.max(e.width*s,2),height:Math.max(e.height*s,2)})}e.width=t,e.height=o},setPageZIndex(t,o){const s=e.pages.find((e=>e.id===t));s&&((0,mobx_state_tree_1.detach)(s),e.pages.remove(s),e.pages.splice(o,0,s))},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 s=Math.min(e.pages.length-1,o),r=e.pages[s];r&&(e._activePageId=r.id),e.selectedElementsIds=(0,mobx_state_tree_1.cast)(e.selectedElementsIds.filter((t=>e.getElementById(t))))},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)([])},on(t,o){if("change"===t){let t=e.toJSON();return(0,mobx_state_tree_1.onSnapshot)(e,(s=>{const r=e.toJSON();JSON.stringify(r)!==JSON.stringify(t)&&(t=r,o(r))}))}},async toDataURL({pixelRatio:t,ignoreBackground:o,pageId:s,mimeType:r}={}){const n=t||1;s=s||e.pages[0].id;const a=e.pages.find((e=>e.id===s));null==a||a.set({_exporting:!0}),await new Promise((e=>{setTimeout(e,0)})),await e.waitLoading();const i=konva_1.default.stages.find((e=>e.getAttr("pageId")===s));if(!i)throw new Error(`Export is failed. Can not find stage for page ${s}. Looks like <Workspace /> component is not mounted, but it is required in order to process the export.`);const d=i.findOne(".page-container");i.find("Transformer").forEach((e=>e.visible(!1))),d.findOne(".page-background").shadowEnabled(!1),d.findOne(".page-background").strokeEnabled(!1),d.find(".highlighter").forEach((e=>e.visible(!1)));const l=d.find((e=>e.getAttr("hideInExport")));l.forEach((e=>{e.setAttr("oldVisible",e.visible()),e.hide()})),o&&d.findOne(".page-background").hide();const c=d.toDataURL({x:d.x(),y:d.y(),width:e.width*d.scaleX(),height:e.height*d.scaleY(),pixelRatio:1/d.scaleX()*n,mimeType:r});return o&&d.findOne(".page-background").show(),l.forEach((e=>{e.visible(e.getAttr("oldVisible"))})),d.findOne(".page-background").shadowEnabled(!0),d.findOne(".page-background").strokeEnabled(!0),i.find("Transformer").forEach((e=>e.visible(!0))),d.find(".highlighter").forEach((e=>e.visible(!0))),null==a||a.set({_exporting:!1}),c},async saveAsImage(t={}){var{fileName:o}=t,s=__rest(t,["fileName"]);const r=s.mimeType||"image/png",n=r.split("/")[1];(0,download_1.downloadFile)(await e.toDataURL(s),o||"polotno."+n,r)},async _toPDF(t){const o=t.dpi||300,s=e=>.75*e;var r=new(await(0,pdf_1.getJsPDF)())({unit:"pt",orientation:e.width>e.height?"landscape":"portrait",format:[s(e.width),s(e.height)]}),n=r.internal.pageSize.getWidth(),a=r.internal.pageSize.getHeight();const i=e._elementsPixelRatio,d=o/72;e.setElementsPixelRatio(d),await new Promise((e=>setTimeout(e)));for(const o of e.pages){0!==e.pages.indexOf(o)&&r.addPage(),r.addImage(await e.toDataURL(Object.assign(Object.assign({},t),{pageId:o.id,pixelRatio:d})),0,0,n,a,void 0,"MEDIUM")}return e.setElementsPixelRatio(i),r},toPDFDataURL:async t=>(await e._toPDF(Object.assign({mimeType:"image/jpg"},t))).output("datauristring"),async saveAsPDF(t={}){var{fileName:o,dpi:s}=t,r=__rest(t,["fileName","dpi"]);(await e._toPDF(Object.assign({mimeType:"image/jpg"},r))).save(o||"polotno.pdf")},async waitLoading(){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)}),loadJSON(t,o=!1){var s;e.pages.forEach((e=>e.children.forEach((e=>(0,mobx_state_tree_1.detach)(e))))),e.pages=(0,mobx_state_tree_1.cast)([]),t._activePageId=null===(s=t.pages[0])||void 0===s?void 0:s.id,t.scale=e.scale,t._isKeyValid=e._isKeyValid,t.openedSidePanel=e.openedSidePanel,o&&(t.history=e.history.toJSON()),(0,mobx_state_tree_1.applySnapshot)(e,t)},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,s){void 0===s&&(s=o),Object.defineProperty(e,s,{enumerable:!0,get:function(){return t[o]}})}:function(e,t,o,s){void 0===s&&(s=o),e[s]=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 s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(o[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(s=Object.getOwnPropertySymbols(e);n<s.length;n++)t.indexOf(s[n])<0&&Object.prototype.propertyIsEnumerable.call(e,s[n])&&(o[s[n]]=e[s[n]])}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.registerShapeModel=exports.SVGElement=exports.ImageElement=exports.TextElement=exports.Element=void 0;const mobx_state_tree_1=require("mobx-state-tree"),undo_manager_1=require("./undo-manager"),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")),svg_1=require("../utils/svg"),loader_1=require("../utils/loader");(0,mobx_state_tree_1.setLivelinessChecking)("ignore"),exports.Element=mobx_state_tree_1.types.model("Element",{id:mobx_state_tree_1.types.identifier,type:"none",x:0,y:0,rotation:0,opacity:1,visible:!0,locked:!1,blurEnabled:!1,blurRadius:10,brightnessEnabled:!1,brightness:0,sepiaEnabled:!1,grayscaleEnabled:!1,shadowEnabled:!1,shadowBlur:5,shadowOffsetX:0,shadowOffsetY:0,shadowColor:"black",custom:mobx_state_tree_1.types.frozen(),selectable:!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),t})).postProcessSnapshot((e=>{const t=Object.assign({},e),o={};for(var s in t)"_"!==s[0]&&(o[s]=e[s]);return o})).views((e=>({get page(){return(0,mobx_state_tree_1.getParentOfType)(e,exports.Page)},get store(){return(0,mobx_state_tree_1.getParentOfType)(e,exports.Store)}}))).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),Object.assign(o,t),e.page.addElement(o)},set(t){Object.assign(e,t)},moveUp(){e.page.moveElementUp(e.id)},moveTop(){e.page.moveElementTop(e.id)},moveDown(){e.page.moveElementDown(e.id)},moveBottom(){e.page.moveElementBottom(e.id)},beforeDestroy(){e.store.history.endTransaction()}}))),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:14,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}).preProcessSnapshot((e=>Object.assign(Object.assign({},e),{fontSize:e.fontSize||0}))).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,_cropModeEnabled:!1}).actions((e=>({toggleCropMode(t){e._cropModeEnabled=null!=t?t:!e._cropModeEnabled,e._cropModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction()}}))),exports.SVGElement=exports.Element.named("SVG").props({type:"svg",src:"",maskSrc:"",__svgString:"",cropX:0,cropY:0,cropWidth:1,cropHeight:1,keepRatio:!0,flipX:!1,flipY:!1,width:100,height:100,borderColor:"black",borderSize: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}))).views((e=>({get colors(){return e.__svgString?(0,svg_1.getColors)(e.__svgString):[]},get __finalSrc(){return e.__svgString?(0,svg_1.replaceColors)(e.__svgString,e.colorsReplace):this.src},get __isLoaded(){if(!e.__svgString)return!1;return!(Array.from(e.colorsReplace.keys()).length>0)||e.__finalSrc!==e.src}}))).actions((e=>{let t=()=>{};return{async _loadSVG(){if(!e.src)return;const t=await(0,svg_1.urlToString)(e.src);(0,mobx_state_tree_1.isAlive)(e)&&(0,mobx_state_tree_1.hasParent)(e)&&e.store.history.ignore((()=>{e.set({__svgString:(0,svg_1.fixSize)(t)})}))},async afterCreate(){e._loadSVG();let o=e.src;t=(0,mobx_state_tree_1.onSnapshot)(e,(t=>{t.src===o&&e.__svgString||(e._loadSVG(),o=e.src)}))},beforeDestroy(){t()},replaceColor(t,o){e.colorsReplace.set(t,o)}}}));const TYPES_MAP={svg:exports.SVGElement,text:exports.TextElement,image:exports.ImageElement},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,...additionalTypesUnion),ChildrenType=mobx_state_tree_1.types.array(ElementTypes);function createStore({key:e,showCredit:t}={key:"",showCredit:!1}){const o=exports.Store.create();return o.__checkKey(e,t),o}exports.Page=mobx_state_tree_1.types.model("Page",{id:mobx_state_tree_1.types.identifier,children:ChildrenType,background:"white",_exporting:!1,custom:mobx_state_tree_1.types.frozen()}).postProcessSnapshot((e=>{const t=Object.assign({},e),o={};for(var s in t)"_"!==s[0]&&(o[s]=e[s]);return o})).views((e=>({get store(){return(0,mobx_state_tree_1.getParentOfType)(e,exports.Store)}}))).actions((e=>({toJSON:()=>Object.assign({},(0,mobx_state_tree_1.getSnapshot)(e)),clone(t){const o=e.children.map((e=>{const t=e.toJSON();return t.id=(0,nanoid_1.nanoid)(10),t})),s=Object.assign({id:(0,nanoid_1.nanoid)(10),children:o,background:e.background},t),n=e.store.addPage(s),r=e.store.pages.indexOf(e);n.setZIndex(r+1),n.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);const s=o.create(Object.assign({id:(0,nanoid_1.nanoid)(10)},t));return e.children.push(s),s.selectable&&e.store.selectElements([s.id]),s},moveElementUp(t){const o=e.children.findIndex((e=>e.id===t)),s=e.children[o];(0,mobx_state_tree_1.detach)(s),e.children.remove(s),e.children.splice(o+1,0,s)},moveElementDown(t){const o=e.children.findIndex((e=>e.id===t)),s=e.children[o];(0,mobx_state_tree_1.detach)(s),e.children.remove(s),e.children.splice(o-1,0,s)},moveElementTop(t){const o=e.children.findIndex((e=>e.id===t)),s=e.children[o];(0,mobx_state_tree_1.detach)(s),e.children.remove(s),e.children.push(s)},moveElementBottom(t){const o=e.children.findIndex((e=>e.id===t)),s=e.children[o];(0,mobx_state_tree_1.detach)(s),e.children.remove(s),e.children.splice(0,0,s)}}))),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,scale:1,scaleToFit:1,openedSidePanel:"",selectedElementsIds:mobx_state_tree_1.types.array(mobx_state_tree_1.types.string),history:mobx_state_tree_1.types.optional(undo_manager_1.UndoManager,{targetPath:"../pages"}),_elementsPixelRatio:2,_showCredit:!1,_activePageId:""}).views((e=>({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 activePage(){return e.pages.slice().find((t=>t.id===e._activePageId))||(e.pages.length?e.pages[0]:null)}}))).actions((e=>({async __checkKey(t,o){const s=await(0,validate_key_1.validateKey)(t);e.__(s,o)},__(t,o){e._showCredit=!t||o},setRole(t){e.role=t},getElementById(t){for(const o of e.pages)for(const e of o.children)if(e.id===t)return e},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){e.selectedElementsIds=(0,mobx_state_tree_1.cast)(t)},openSidePanel(t){e.openedSidePanel=t},setScale(t){e.scale=t},_setScaleToFit(t){e.scaleToFit=t},setElementsPixelRatio(t){e._elementsPixelRatio=t},setSize(t,o,s){if(s){const s=t/e.width,n=o/e.height;for(const t of e.pages)for(const e of t.children)e.set({x:e.x*s,y:e.y*n}),"text"===e.type?e.set({fontSize:e.fontSize*s,width:Math.max(e.width*s,2)}):"image"===e.type?e.set({width:e.width*s,height:e.height*n}):"svg"===e.type&&e.set({width:Math.max(e.width*s,2),height:Math.max(e.height*s,2)})}e.width=t,e.height=o},setPageZIndex(t,o){const s=e.pages.find((e=>e.id===t));s&&((0,mobx_state_tree_1.detach)(s),e.pages.remove(s),e.pages.splice(o,0,s))},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 s=Math.min(e.pages.length-1,o),n=e.pages[s];n&&(e._activePageId=n.id),e.selectedElementsIds=(0,mobx_state_tree_1.cast)(e.selectedElementsIds.filter((t=>e.getElementById(t))))},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)([])},on(t,o){if("change"===t){let t=e.toJSON();return(0,mobx_state_tree_1.onSnapshot)(e,(s=>{const n=e.toJSON();JSON.stringify(n)!==JSON.stringify(t)&&(t=n,o(n))}))}},async toDataURL({pixelRatio:t,ignoreBackground:o,pageId:s,mimeType:n}={}){const r=t||1;s=s||e.pages[0].id;const a=e.pages.find((e=>e.id===s));null==a||a.set({_exporting:!0}),await new Promise((e=>{setTimeout(e,0)})),await e.waitLoading();const i=konva_1.default.stages.find((e=>e.getAttr("pageId")===s));if(!i)throw new Error(`Export is failed. Can not find stage for page ${s}. Looks like <Workspace /> component is not mounted, but it is required in order to process the export.`);const d=i.findOne(".page-container");i.find("Transformer").forEach((e=>e.visible(!1))),d.findOne(".page-background").shadowEnabled(!1),d.findOne(".page-background").strokeEnabled(!1),d.find(".highlighter").forEach((e=>e.visible(!1)));const l=d.find((e=>e.getAttr("hideInExport")));l.forEach((e=>{e.setAttr("oldVisible",e.visible()),e.hide()})),o&&d.findOne(".page-background").hide();const c=d.toDataURL({x:d.x(),y:d.y(),width:e.width*d.scaleX(),height:e.height*d.scaleY(),pixelRatio:1/d.scaleX()*r,mimeType:n});return o&&d.findOne(".page-background").show(),l.forEach((e=>{e.visible(e.getAttr("oldVisible"))})),d.findOne(".page-background").shadowEnabled(!0),d.findOne(".page-background").strokeEnabled(!0),i.find("Transformer").forEach((e=>e.visible(!0))),d.find(".highlighter").forEach((e=>e.visible(!0))),null==a||a.set({_exporting:!1}),c},async saveAsImage(t={}){var{fileName:o}=t,s=__rest(t,["fileName"]);const n=s.mimeType||"image/png",r=n.split("/")[1];(0,download_1.downloadFile)(await e.toDataURL(s),o||"polotno."+r,n)},async _toPDF(t){const o=t.dpi||300,s=e=>.75*e;var n=new(await(0,pdf_1.getJsPDF)())({unit:"pt",orientation:e.width>e.height?"landscape":"portrait",format:[s(e.width),s(e.height)]}),r=n.internal.pageSize.getWidth(),a=n.internal.pageSize.getHeight();const i=e._elementsPixelRatio,d=o/72;e.setElementsPixelRatio(d),await new Promise((e=>setTimeout(e)));for(const o of e.pages){0!==e.pages.indexOf(o)&&n.addPage(),n.addImage(await e.toDataURL(Object.assign(Object.assign({},t),{pageId:o.id,pixelRatio:d})),0,0,r,a,void 0,"MEDIUM")}return e.setElementsPixelRatio(i),n},toPDFDataURL:async t=>(await e._toPDF(Object.assign({mimeType:"image/jpg"},t))).output("datauristring"),async saveAsPDF(t={}){var{fileName:o,dpi:s}=t,n=__rest(t,["fileName","dpi"]);(await e._toPDF(Object.assign({mimeType:"image/jpg"},n))).save(o||"polotno.pdf")},async waitLoading(){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)}),loadJSON(t,o=!1){var s;e.pages.forEach((e=>e.children.forEach((e=>(0,mobx_state_tree_1.detach)(e))))),e.pages=(0,mobx_state_tree_1.cast)([]),t._activePageId=null===(s=t.pages[0])||void 0===s?void 0:s.id,t.scale=e.scale,t._isKeyValid=e._isKeyValid,t.openedSidePanel=e.openedSidePanel,o&&(t.history=e.history.toJSON()),(0,mobx_state_tree_1.applySnapshot)(e,t)},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": "0.36.4",
3
+ "version": "0.36.5",
4
4
  "description": "Design Editor Framework",
5
5
  "author": "Anton Lavrenov",
6
6
  "keywords": [
package/polotno.bundle.js CHANGED
@@ -288,7 +288,7 @@ PERFORMANCE OF THIS SOFTWARE.
288
288
  @media screen and (max-width: 500px) {
289
289
  display: none;
290
290
  }
291
- `,uj=Vr.observer((({store:e})=>{const t=Math.max(2,e.scaleToFit),n=Math.min(.5,e.scaleToFit),r=e.scale<t,i=e.scale>n;return A.jsxs(qy.Group,{align:pl,children:[A.jsx(dy,{icon:"zoom-out",minimal:!0,onClick:()=>{e.setScale(e.scale/1.2)},disabled:!i}),A.jsx(dy,{minimal:!0,onClick:()=>{e.setScale(e.scaleToFit)},children:ex("scale.reset")}),A.jsx(dy,{icon:"zoom-in",minimal:!0,onClick:()=>{e.setScale(1.2*e.scale)},disabled:!r})]})}));var hj=Vr.observer((({store:e})=>A.jsx(cj,{children:A.jsx(qy,{children:A.jsx(uj,{store:e})})})));const fj=DD.model("UndoManager",{history:DD.array(DD.frozen()),undoIdx:-1,targetPath:""}).views((e=>({get canUndo(){return e.undoIdx>0},get canRedo(){return e.undoIdx<e.history.length-1}}))).actions((e=>{let t,n,r=!1,i=null,o=0,a=!1;function A(){const e=vR(t);return{pages:e.pages,width:e.width,height:e.height}}function s(e){pR(t.pages,e.pages),t.setSize(e.width,e.height)}return{startTransaction(){a=!0},endTransaction(e){a=!1,e||this.requestAddState(A())},async ignore(t){e.startTransaction();try{await t()}catch(e){setTimeout((()=>{throw e}))}e.endTransaction(!0),o=0,clearTimeout(o)},async transaction(t){await e.ignore(t),this.addUndoState()},requestAddState(e){i=e,o||a||(r?r=!1:o=setTimeout((()=>{o=0,clearTimeout(o),a||this.addUndoState()}),100))},addUndoState(){if(r)return void(r=!1);const t=e.history[e.undoIdx];JSON.stringify(t)!==JSON.stringify(i)&&(e.history.splice(e.undoIdx+1),e.history.push(i),e.undoIdx=e.history.length-1)},afterCreate(){if(t=function(e,t){rV(e,1),kV();var n=AV(iV(e),t);return n?n.value:void 0}(e,".."),!t)throw new Error("Failed to find target store for UndoManager. Please provide `targetPath` property, or a `targetStore` in the environment");n=fR(t,(()=>this.requestAddState(A()))),0===e.history.length&&this.requestAddState(A())},clear(){clearTimeout(o),o=0,e.history.splice(0,e.history.length),e.undoIdx=-1,e.addUndoState(A())},beforeDestroy(){n()},undo(){o&&this.addUndoState(),e.canUndo?(e.undoIdx--,r=!0,s(e.history[e.undoIdx])):console.warn("No undo history. Please check `store.history.canUndo` before calling undo action.")},redo(){o&&this.addUndoState(),e.canRedo?(e.undoIdx++,r=!0,s(e.history[e.undoIdx])):console.warn("No redo history. Please check `store.history.canRedo` before calling redo action.")},replaceState(){e.history[e.undoIdx]=A()}}}));let dj=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e));for(;e--;){let r=63&n[e];t+=r<36?r.toString(36):r<62?(r-26).toString(36).toUpperCase():r<63?"_":"-"}return t};let pj;oR("ignore");const vj=DD.model("Element",{id:DD.identifier,type:"none",x:0,y:0,rotation:0,opacity:1,visible:!0,locked:!1,blurEnabled:!1,blurRadius:10,brightnessEnabled:!1,brightness:0,sepiaEnabled:!1,grayscaleEnabled:!1,shadowEnabled:!1,shadowBlur:5,shadowOffsetX:0,shadowOffsetY:0,shadowColor:"black",custom:DD.frozen(),selectable:!0,alwaysOnTop:!1,showInExport:!0}).preProcessSnapshot((e=>{const t={...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),t})).postProcessSnapshot((e=>{const t={...e},n={};for(var r in t)"_"!==r[0]&&(n[r]=e[r]);return n})).views((e=>({get page(){return gR(e,xj)},get store(){return gR(e,Sj)}}))).actions((e=>({toJSON:()=>({...vR(e)})}))).actions((e=>({clone(t){const n=e.toJSON();return t.id=t.id||dj(10),Object.assign(n,t),e.page.addElement(n)},set(t){Object.assign(e,t)},moveUp(){e.page.moveElementUp(e.id)},moveTop(){e.page.moveElementTop(e.id)},moveDown(){e.page.moveElementDown(e.id)},moveBottom(){e.page.moveElementBottom(e.id)},beforeDestroy(){e.store.history.endTransaction()}}))),gj=vj.named("Text").props({type:"text",text:"",placeholder:"",fontSize:14,fontFamily:"Roboto",fontStyle:"normal",fontWeight:"normal",textDecoration:"",fill:"black",align:"center",width:100,height:14,strokeWidth:0,stroke:"black",lineHeight:DD.optional(DD.union(DD.number,DD.string),1.2),letterSpacing:0,_editModeEnabled:!1}).preProcessSnapshot((e=>({...e,fontSize:e.fontSize||0}))).actions((e=>({toggleEditMode(t){e._editModeEnabled=t??!e._editModeEnabled,e._editModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction()}}))),mj=vj.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,_cropModeEnabled:!1}).actions((e=>({toggleCropMode(t){e._cropModeEnabled=t??!e._cropModeEnabled,e._cropModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction()}}))),yj=vj.named("SVG").props({type:"svg",src:"",maskSrc:"",__svgString:"",cropX:0,cropY:0,cropWidth:1,cropHeight:1,keepRatio:!0,flipX:!1,flipY:!1,width:100,height:100,borderColor:"black",borderSize:0,colorsReplace:DD.map(DD.string)}).preProcessSnapshot((e=>({...e,src:e.src||e.svgSource}))).views((e=>({get colors(){return e.__svgString?function(e){const t=nC((new DOMParser).parseFromString(e,"image/svg+xml")),n=[];return t.forEach((e=>{const{fill:t,stroke:r}=eC(e);[t,r].forEach((e=>{e&&nA.Util.colorToRGBA(e)&&-1===n.indexOf(e)&&n.push(e)}))})),n}(e.__svgString):[]},get __finalSrc(){return e.__svgString?AC(e.__svgString,e.colorsReplace):this.src},get __isLoaded(){if(!e.__svgString)return!1;return!(Array.from(e.colorsReplace.keys()).length>0)||e.__finalSrc!==e.src}}))).actions((e=>{let t=()=>{};return{async _loadSVG(){if(!e.src)return;const t=await iC(e.src);wR(e)&&function(e,t){void 0===t&&(t=1),rV(e,1),FV(0,0,0);for(var n=iV(e).parent;n;){if(0==--t)return!0;n=n.parent}return!1}(e)&&e.store.history.ignore((()=>{e.set({__svgString:aC(t)})}))},async afterCreate(){e._loadSVG();let n=e.src;t=fR(e,(t=>{t.src===n&&e.__svgString||(e._loadSVG(),n=e.src)}))},beforeDestroy(){t()},replaceColor(t,n){e.colorsReplace.set(t,n)}}})),bj={svg:yj,text:gj,image:mj},wj=[];const Bj=[...new Array(20)].map(((e,t)=>DD.late((()=>wj[t])))),Cj=DD.union({dispatcher:e=>{const t=bj[e.type];if(!t)throw new Error(`Unknown element type: "${e.type}"`);return t}},yj,gj,mj,...Bj),Ej=DD.array(Cj),xj=DD.model("Page",{id:DD.identifier,children:Ej,background:"white",bleed:DD.optional(DD.array(DD.number),[0,0,0,0]),_exporting:!1,custom:DD.frozen()}).postProcessSnapshot((e=>{const t={...e},n={};for(var r in t)"_"!==r[0]&&(n[r]=e[r]);return n})).views((e=>({get store(){return gR(e,Sj)}}))).actions((e=>({toJSON:()=>({...vR(e)}),clone(t){const n=e.children.map((e=>{const t=e.toJSON();return t.id=dj(10),t})),r={id:dj(10),children:n,background:e.background,...t},i=e.store.addPage(r),o=e.store.pages.indexOf(e);i.setZIndex(o+1),i.select()},setZIndex(t){e.store.setPageZIndex(e.id,t)},set(t){Object.assign(e,t)},select(){e.store.selectPage(e.id)},addElement(t){const n=bj[t.type];if(!n)return void console.error("Can not find model with type "+t.type);const r=n.create({id:dj(10),...t});return e.children.push(r),r.selectable&&e.store.selectElements([r.id]),r},moveElementUp(t){const n=e.children.findIndex((e=>e.id===t)),r=e.children[n];yR(r),e.children.remove(r),e.children.splice(n+1,0,r)},moveElementDown(t){const n=e.children.findIndex((e=>e.id===t)),r=e.children[n];yR(r),e.children.remove(r),e.children.splice(n-1,0,r)},moveElementTop(t){const n=e.children.findIndex((e=>e.id===t)),r=e.children[n];yR(r),e.children.remove(r),e.children.push(r)},moveElementBottom(t){const n=e.children.findIndex((e=>e.id===t)),r=e.children[n];yR(r),e.children.remove(r),e.children.splice(0,0,r)}}))),_j=DD.model("Font",{fontFamily:DD.string,url:DD.optional(DD.string,""),styles:DD.frozen()}).preProcessSnapshot((e=>({...e,fontFamily:e.fontFamily||e.name}))),Sj=DD.model("Store",{role:"",pages:DD.array(xj),fonts:DD.array(_j),width:1080,height:1080,scale:1,scaleToFit:1,openedSidePanel:"",selectedElementsIds:DD.array(DD.string),history:DD.optional(fj,{targetPath:"../pages"}),_elementsPixelRatio:2,_showCredit:!1,_activePageId:""}).views((e=>({get selectedElements(){return e.selectedElementsIds.map((t=>{for(const n of e.pages)for(const e of n.children)if(e.id===t)return e})).filter((e=>!!e))},get activePage(){return e.pages.slice().find((t=>t.id===e._activePageId))||(e.pages.length?e.pages[0]:null)}}))).actions((e=>({async __checkKey(t,n){const r=await async function(e){L_=e;for(let t=0;t<5;t++)try{const t=await fetch(Q_+"/validate-key",{method:"POST",body:JSON.stringify({key:e,site:location.host+location.pathname})});if(!e)return console.warn("Polotno API is initialized without API key. It may lead to unexpected behavior and stop working. Please create API key here: https://polotno.dev/cabinet"),!1;if(200!==t.status){await new Promise((e=>setTimeout(e,3e3)));continue}const n=await t.json();return n.is_valid||console.warn("Polotno API key is not valid. Please get new API key here: https://polotno.dev/cabinet"),n.is_paid||console.log("%cPolotno Free Version. Development or non-commercial usage only. https://polotno.dev/","background: rgb(0, 161, 255); color: white; padding: 5px; margin: 5px;"),n.is_domain_valid||U_||console.log(k_,"background: rgba(247, 101, 68, 1); color: white; padding: 5px; margin: 5px;"),n.is_paid||!1}catch(e){await new Promise((e=>setTimeout(e,3e3)))}return console.error("Can not validate Polotno API key. Please report to anton@polotno.dev immediately."),!0}(t);e.__(r,n)},__(t,n){e._showCredit=!t||n},setRole(t){e.role=t},getElementById(t){for(const n of e.pages)for(const e of n.children)if(e.id===t)return e},addPage(t){const n=xj.create({id:dj(10),...t});return e.pages.push(n),e._activePageId=n.id,n},selectPage(t){e._activePageId=t},selectElements(t){e.selectedElementsIds=t},openSidePanel(t){e.openedSidePanel=t},setScale(t){e.scale=t},_setScaleToFit(t){e.scaleToFit=t},setElementsPixelRatio(t){e._elementsPixelRatio=t},setSize(t,n,r){if(r){const r=t/e.width,i=n/e.height;for(const t of e.pages)for(const e of t.children)e.set({x:e.x*r,y:e.y*i}),"text"===e.type?e.set({fontSize:e.fontSize*r,width:Math.max(e.width*r,2)}):"image"===e.type?e.set({width:e.width*r,height:e.height*i}):"svg"===e.type&&e.set({width:Math.max(e.width*r,2),height:Math.max(e.height*r,2)})}e.width=t,e.height=n},setPageZIndex(t,n){const r=e.pages.find((e=>e.id===t));r&&(yR(r),e.pages.remove(r),e.pages.splice(n,0,r))},deletePages(t){const n=e.pages.indexOf(e.activePage);t.forEach((t=>{bR(e.pages.find((e=>e.id===t)))}));const r=Math.min(e.pages.length-1,n),i=e.pages[r];i&&(e._activePageId=i.id),e.selectedElementsIds=e.selectedElementsIds.filter((t=>e.getElementById(t)))},deleteElements(t){t.forEach((t=>{e.pages.forEach((e=>{const n=e.children.find((e=>e.id===t));n&&bR(n)}))})),e.selectedElementsIds=[]},on(t,n){if("change"===t){let t=e.toJSON();return fR(e,(r=>{const i=e.toJSON();JSON.stringify(i)!==JSON.stringify(t)&&(t=i,n(i))}))}},async toDataURL({pixelRatio:t,ignoreBackground:n,pageId:r,mimeType:i}={}){const o=t||1;r=r||e.pages[0].id;const a=e.pages.find((e=>e.id===r));a?.set({_exporting:!0}),await new Promise((e=>{setTimeout(e,0)})),await e.waitLoading();const A=nA.stages.find((e=>e.getAttr("pageId")===r));if(!A)throw new Error(`Export is failed. Can not find stage for page ${r}. Looks like <Workspace /> component is not mounted, but it is required in order to process the export.`);const s=A.findOne(".page-container");A.find("Transformer").forEach((e=>e.visible(!1))),s.findOne(".page-background").shadowEnabled(!1),s.findOne(".page-background").strokeEnabled(!1),s.find(".highlighter").forEach((e=>e.visible(!1)));const l=s.find((e=>e.getAttr("hideInExport")));l.forEach((e=>{e.setAttr("oldVisible",e.visible()),e.hide()})),n&&s.findOne(".page-background").hide();const c=s.toDataURL({x:s.x(),y:s.y(),width:e.width*s.scaleX(),height:e.height*s.scaleY(),pixelRatio:1/s.scaleX()*o,mimeType:i});return n&&s.findOne(".page-background").show(),l.forEach((e=>{e.visible(e.getAttr("oldVisible"))})),s.findOne(".page-background").shadowEnabled(!0),s.findOne(".page-background").strokeEnabled(!0),A.find("Transformer").forEach((e=>e.visible(!0))),s.find(".highlighter").forEach((e=>e.visible(!0))),a?.set({_exporting:!1}),c},async saveAsImage({fileName:t,...n}={}){const r=n.mimeType||"image/png",i=r.split("/")[1];!async function(e,t,n){const r=await(await fetch(e)).blob(),i=document.createElement("a"),o=URL.createObjectURL(r);i.href=o,i.download=t,document.body.appendChild(i),i.click(),setTimeout((function(){document.body.removeChild(i),window.URL.revokeObjectURL(o)}),0)}(await e.toDataURL(n),t||"polotno."+i)},async _toPDF(t){const n=t.dpi||300,r=e=>.75*e;var i=new(await(pj?Promise.resolve(pj):new Promise((e=>{var t=document.createElement("script");t.onload=function(){pj=window.jspdf.jsPDF,e(pj)},t.src="https://unpkg.com/jspdf@2.2.0/dist/jspdf.umd.min.js",document.head.appendChild(t)}))))({unit:"pt",orientation:e.width>e.height?"landscape":"portrait",format:[r(e.width),r(e.height)]}),o=i.internal.pageSize.getWidth(),a=i.internal.pageSize.getHeight();const A=e._elementsPixelRatio,s=n/72;e.setElementsPixelRatio(s),await new Promise((e=>setTimeout(e)));for(const n of e.pages){0!==e.pages.indexOf(n)&&i.addPage(),i.addImage(await e.toDataURL({...t,pageId:n.id,pixelRatio:s}),0,0,o,a,void 0,"MEDIUM")}return e.setElementsPixelRatio(A),i},toPDFDataURL:async t=>(await e._toPDF({mimeType:"image/jpg",...t})).output("datauristring"),async saveAsPDF({fileName:t,dpi:n,...r}={}){(await e._toPDF({mimeType:"image/jpg",...r})).save(t||"polotno.pdf")},async waitLoading(){await IB()},toJSON:()=>({width:e.width,height:e.height,fonts:vR(e.fonts),pages:vR(e.pages)}),loadJSON(t,n=!1){e.pages.forEach((e=>e.children.forEach((e=>yR(e))))),e.pages=[],t._activePageId=t.pages[0]?.id,t.scale=e.scale,t._isKeyValid=e._isKeyValid,t.openedSidePanel=e.openedSidePanel,n&&(t.history=e.history.toJSON()),pR(e,t)},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=>bR(e)))},async loadFont(t){const n=e.fonts.find((e=>e.fontFamily===t))||x_.find((e=>e.fontFamily===t));n?function(e){const t=e.fontFamily;if(M_[t])return;if(!e.url&&!e.styles)return;const n=document.createElement("style");n.type="text/css";const r=e.styles||(e.url?[{src:`url("${e.url}")`}]:[]);let i="";r.forEach((e=>{i+=`\n @font-face {\n font-family: '${t}';\n src: ${e.src};\n font-style: ${e.fontStyle||"normal"};\n font-weight: ${e.fontWeight||"normal"};\n }\n `})),n.innerHTML=i,document.getElementsByTagName("head")[0].appendChild(n),M_[e.fontFamily]=!0}(n):function(e){if(H_[e])return;const t=`https://fonts.googleapis.com/css?family=${e.replace(/ /g,"+")}`,n=document.createElement("link");n.type="text/css",n.href=t,n.rel="stylesheet",document.getElementsByTagName("head")[0].appendChild(n),H_[e]=!0}(t),await z_(t)}})));function Oj({key:e,showCredit:t}={key:"",showCredit:!1}){const n=Sj.create();return n.__checkKey(e,t),n}const zj=IE("div")`
291
+ `,uj=Vr.observer((({store:e})=>{const t=Math.max(2,e.scaleToFit),n=Math.min(.5,e.scaleToFit),r=e.scale<t,i=e.scale>n;return A.jsxs(qy.Group,{align:pl,children:[A.jsx(dy,{icon:"zoom-out",minimal:!0,onClick:()=>{e.setScale(e.scale/1.2)},disabled:!i}),A.jsx(dy,{minimal:!0,onClick:()=>{e.setScale(e.scaleToFit)},children:ex("scale.reset")}),A.jsx(dy,{icon:"zoom-in",minimal:!0,onClick:()=>{e.setScale(1.2*e.scale)},disabled:!r})]})}));var hj=Vr.observer((({store:e})=>A.jsx(cj,{children:A.jsx(qy,{children:A.jsx(uj,{store:e})})})));const fj=DD.model("UndoManager",{history:DD.array(DD.frozen()),undoIdx:-1,targetPath:""}).views((e=>({get canUndo(){return e.undoIdx>0},get canRedo(){return e.undoIdx<e.history.length-1}}))).actions((e=>{let t,n,r=!1,i=null,o=0,a=!1;function A(){const e=vR(t);return{pages:e.pages,width:e.width,height:e.height}}function s(e){pR(t.pages,e.pages),t.setSize(e.width,e.height)}return{startTransaction(){a=!0},endTransaction(e){a=!1,e||this.requestAddState(A())},async ignore(t){e.startTransaction();try{await t()}catch(e){setTimeout((()=>{throw e}))}e.endTransaction(!0),o=0,clearTimeout(o)},async transaction(t){await e.ignore(t),this.addUndoState()},requestAddState(e){i=e,o||a||(r?r=!1:o=setTimeout((()=>{o=0,clearTimeout(o),a||this.addUndoState()}),100))},addUndoState(){if(r)return void(r=!1);const t=e.history[e.undoIdx];JSON.stringify(t)!==JSON.stringify(i)&&(e.history.splice(e.undoIdx+1),e.history.push(i),e.undoIdx=e.history.length-1)},afterCreate(){if(t=function(e,t){rV(e,1),kV();var n=AV(iV(e),t);return n?n.value:void 0}(e,".."),!t)throw new Error("Failed to find target store for UndoManager. Please provide `targetPath` property, or a `targetStore` in the environment");n=fR(t,(()=>this.requestAddState(A()))),0===e.history.length&&this.requestAddState(A())},clear(){clearTimeout(o),o=0,e.history.splice(0,e.history.length),e.undoIdx=-1,e.addUndoState(A())},beforeDestroy(){n()},undo(){o&&this.addUndoState(),e.canUndo?(e.undoIdx--,r=!0,s(e.history[e.undoIdx])):console.warn("No undo history. Please check `store.history.canUndo` before calling undo action.")},redo(){o&&this.addUndoState(),e.canRedo?(e.undoIdx++,r=!0,s(e.history[e.undoIdx])):console.warn("No redo history. Please check `store.history.canRedo` before calling redo action.")},replaceState(){e.history[e.undoIdx]=A()}}}));let dj=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e));for(;e--;){let r=63&n[e];t+=r<36?r.toString(36):r<62?(r-26).toString(36).toUpperCase():r<63?"_":"-"}return t};let pj;oR("ignore");const vj=DD.model("Element",{id:DD.identifier,type:"none",x:0,y:0,rotation:0,opacity:1,visible:!0,locked:!1,blurEnabled:!1,blurRadius:10,brightnessEnabled:!1,brightness:0,sepiaEnabled:!1,grayscaleEnabled:!1,shadowEnabled:!1,shadowBlur:5,shadowOffsetX:0,shadowOffsetY:0,shadowColor:"black",custom:DD.frozen(),selectable:!0,alwaysOnTop:!1,showInExport:!0}).preProcessSnapshot((e=>{const t={...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),t})).postProcessSnapshot((e=>{const t={...e},n={};for(var r in t)"_"!==r[0]&&(n[r]=e[r]);return n})).views((e=>({get page(){return gR(e,xj)},get store(){return gR(e,Sj)}}))).actions((e=>({toJSON:()=>({...vR(e)})}))).actions((e=>({clone(t){const n=e.toJSON();return t.id=t.id||dj(10),Object.assign(n,t),e.page.addElement(n)},set(t){Object.assign(e,t)},moveUp(){e.page.moveElementUp(e.id)},moveTop(){e.page.moveElementTop(e.id)},moveDown(){e.page.moveElementDown(e.id)},moveBottom(){e.page.moveElementBottom(e.id)},beforeDestroy(){e.store.history.endTransaction()}}))),gj=vj.named("Text").props({type:"text",text:"",placeholder:"",fontSize:14,fontFamily:"Roboto",fontStyle:"normal",fontWeight:"normal",textDecoration:"",fill:"black",align:"center",width:100,height:14,strokeWidth:0,stroke:"black",lineHeight:DD.optional(DD.union(DD.number,DD.string),1.2),letterSpacing:0,_editModeEnabled:!1}).preProcessSnapshot((e=>({...e,fontSize:e.fontSize||0}))).actions((e=>({toggleEditMode(t){e._editModeEnabled=t??!e._editModeEnabled,e._editModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction()}}))),mj=vj.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,_cropModeEnabled:!1}).actions((e=>({toggleCropMode(t){e._cropModeEnabled=t??!e._cropModeEnabled,e._cropModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction()}}))),yj=vj.named("SVG").props({type:"svg",src:"",maskSrc:"",__svgString:"",cropX:0,cropY:0,cropWidth:1,cropHeight:1,keepRatio:!0,flipX:!1,flipY:!1,width:100,height:100,borderColor:"black",borderSize:0,colorsReplace:DD.map(DD.string)}).preProcessSnapshot((e=>({...e,src:e.src||e.svgSource}))).views((e=>({get colors(){return e.__svgString?function(e){const t=nC((new DOMParser).parseFromString(e,"image/svg+xml")),n=[];return t.forEach((e=>{const{fill:t,stroke:r}=eC(e);[t,r].forEach((e=>{e&&nA.Util.colorToRGBA(e)&&-1===n.indexOf(e)&&n.push(e)}))})),n}(e.__svgString):[]},get __finalSrc(){return e.__svgString?AC(e.__svgString,e.colorsReplace):this.src},get __isLoaded(){if(!e.__svgString)return!1;return!(Array.from(e.colorsReplace.keys()).length>0)||e.__finalSrc!==e.src}}))).actions((e=>{let t=()=>{};return{async _loadSVG(){if(!e.src)return;const t=await iC(e.src);wR(e)&&function(e,t){void 0===t&&(t=1),rV(e,1),FV(0,0,0);for(var n=iV(e).parent;n;){if(0==--t)return!0;n=n.parent}return!1}(e)&&e.store.history.ignore((()=>{e.set({__svgString:aC(t)})}))},async afterCreate(){e._loadSVG();let n=e.src;t=fR(e,(t=>{t.src===n&&e.__svgString||(e._loadSVG(),n=e.src)}))},beforeDestroy(){t()},replaceColor(t,n){e.colorsReplace.set(t,n)}}})),bj={svg:yj,text:gj,image:mj},wj=[];const Bj=[...new Array(20)].map(((e,t)=>DD.late((()=>wj[t])))),Cj=DD.union({dispatcher:e=>{const t=bj[e.type];if(!t)throw new Error(`Unknown element type: "${e.type}"`);return t}},yj,gj,mj,...Bj),Ej=DD.array(Cj),xj=DD.model("Page",{id:DD.identifier,children:Ej,background:"white",_exporting:!1,custom:DD.frozen()}).postProcessSnapshot((e=>{const t={...e},n={};for(var r in t)"_"!==r[0]&&(n[r]=e[r]);return n})).views((e=>({get store(){return gR(e,Sj)}}))).actions((e=>({toJSON:()=>({...vR(e)}),clone(t){const n=e.children.map((e=>{const t=e.toJSON();return t.id=dj(10),t})),r={id:dj(10),children:n,background:e.background,...t},i=e.store.addPage(r),o=e.store.pages.indexOf(e);i.setZIndex(o+1),i.select()},setZIndex(t){e.store.setPageZIndex(e.id,t)},set(t){Object.assign(e,t)},select(){e.store.selectPage(e.id)},addElement(t){const n=bj[t.type];if(!n)return void console.error("Can not find model with type "+t.type);const r=n.create({id:dj(10),...t});return e.children.push(r),r.selectable&&e.store.selectElements([r.id]),r},moveElementUp(t){const n=e.children.findIndex((e=>e.id===t)),r=e.children[n];yR(r),e.children.remove(r),e.children.splice(n+1,0,r)},moveElementDown(t){const n=e.children.findIndex((e=>e.id===t)),r=e.children[n];yR(r),e.children.remove(r),e.children.splice(n-1,0,r)},moveElementTop(t){const n=e.children.findIndex((e=>e.id===t)),r=e.children[n];yR(r),e.children.remove(r),e.children.push(r)},moveElementBottom(t){const n=e.children.findIndex((e=>e.id===t)),r=e.children[n];yR(r),e.children.remove(r),e.children.splice(0,0,r)}}))),_j=DD.model("Font",{fontFamily:DD.string,url:DD.optional(DD.string,""),styles:DD.frozen()}).preProcessSnapshot((e=>({...e,fontFamily:e.fontFamily||e.name}))),Sj=DD.model("Store",{role:"",pages:DD.array(xj),fonts:DD.array(_j),width:1080,height:1080,scale:1,scaleToFit:1,openedSidePanel:"",selectedElementsIds:DD.array(DD.string),history:DD.optional(fj,{targetPath:"../pages"}),_elementsPixelRatio:2,_showCredit:!1,_activePageId:""}).views((e=>({get selectedElements(){return e.selectedElementsIds.map((t=>{for(const n of e.pages)for(const e of n.children)if(e.id===t)return e})).filter((e=>!!e))},get activePage(){return e.pages.slice().find((t=>t.id===e._activePageId))||(e.pages.length?e.pages[0]:null)}}))).actions((e=>({async __checkKey(t,n){const r=await async function(e){L_=e;for(let t=0;t<5;t++)try{const t=await fetch(Q_+"/validate-key",{method:"POST",body:JSON.stringify({key:e,site:location.host+location.pathname})});if(!e)return console.warn("Polotno API is initialized without API key. It may lead to unexpected behavior and stop working. Please create API key here: https://polotno.dev/cabinet"),!1;if(200!==t.status){await new Promise((e=>setTimeout(e,3e3)));continue}const n=await t.json();return n.is_valid||console.warn("Polotno API key is not valid. Please get new API key here: https://polotno.dev/cabinet"),n.is_paid||console.log("%cPolotno Free Version. Development or non-commercial usage only. https://polotno.dev/","background: rgb(0, 161, 255); color: white; padding: 5px; margin: 5px;"),n.is_domain_valid||U_||console.log(k_,"background: rgba(247, 101, 68, 1); color: white; padding: 5px; margin: 5px;"),n.is_paid||!1}catch(e){await new Promise((e=>setTimeout(e,3e3)))}return console.error("Can not validate Polotno API key. Please report to anton@polotno.dev immediately."),!0}(t);e.__(r,n)},__(t,n){e._showCredit=!t||n},setRole(t){e.role=t},getElementById(t){for(const n of e.pages)for(const e of n.children)if(e.id===t)return e},addPage(t){const n=xj.create({id:dj(10),...t});return e.pages.push(n),e._activePageId=n.id,n},selectPage(t){e._activePageId=t},selectElements(t){e.selectedElementsIds=t},openSidePanel(t){e.openedSidePanel=t},setScale(t){e.scale=t},_setScaleToFit(t){e.scaleToFit=t},setElementsPixelRatio(t){e._elementsPixelRatio=t},setSize(t,n,r){if(r){const r=t/e.width,i=n/e.height;for(const t of e.pages)for(const e of t.children)e.set({x:e.x*r,y:e.y*i}),"text"===e.type?e.set({fontSize:e.fontSize*r,width:Math.max(e.width*r,2)}):"image"===e.type?e.set({width:e.width*r,height:e.height*i}):"svg"===e.type&&e.set({width:Math.max(e.width*r,2),height:Math.max(e.height*r,2)})}e.width=t,e.height=n},setPageZIndex(t,n){const r=e.pages.find((e=>e.id===t));r&&(yR(r),e.pages.remove(r),e.pages.splice(n,0,r))},deletePages(t){const n=e.pages.indexOf(e.activePage);t.forEach((t=>{bR(e.pages.find((e=>e.id===t)))}));const r=Math.min(e.pages.length-1,n),i=e.pages[r];i&&(e._activePageId=i.id),e.selectedElementsIds=e.selectedElementsIds.filter((t=>e.getElementById(t)))},deleteElements(t){t.forEach((t=>{e.pages.forEach((e=>{const n=e.children.find((e=>e.id===t));n&&bR(n)}))})),e.selectedElementsIds=[]},on(t,n){if("change"===t){let t=e.toJSON();return fR(e,(r=>{const i=e.toJSON();JSON.stringify(i)!==JSON.stringify(t)&&(t=i,n(i))}))}},async toDataURL({pixelRatio:t,ignoreBackground:n,pageId:r,mimeType:i}={}){const o=t||1;r=r||e.pages[0].id;const a=e.pages.find((e=>e.id===r));a?.set({_exporting:!0}),await new Promise((e=>{setTimeout(e,0)})),await e.waitLoading();const A=nA.stages.find((e=>e.getAttr("pageId")===r));if(!A)throw new Error(`Export is failed. Can not find stage for page ${r}. Looks like <Workspace /> component is not mounted, but it is required in order to process the export.`);const s=A.findOne(".page-container");A.find("Transformer").forEach((e=>e.visible(!1))),s.findOne(".page-background").shadowEnabled(!1),s.findOne(".page-background").strokeEnabled(!1),s.find(".highlighter").forEach((e=>e.visible(!1)));const l=s.find((e=>e.getAttr("hideInExport")));l.forEach((e=>{e.setAttr("oldVisible",e.visible()),e.hide()})),n&&s.findOne(".page-background").hide();const c=s.toDataURL({x:s.x(),y:s.y(),width:e.width*s.scaleX(),height:e.height*s.scaleY(),pixelRatio:1/s.scaleX()*o,mimeType:i});return n&&s.findOne(".page-background").show(),l.forEach((e=>{e.visible(e.getAttr("oldVisible"))})),s.findOne(".page-background").shadowEnabled(!0),s.findOne(".page-background").strokeEnabled(!0),A.find("Transformer").forEach((e=>e.visible(!0))),s.find(".highlighter").forEach((e=>e.visible(!0))),a?.set({_exporting:!1}),c},async saveAsImage({fileName:t,...n}={}){const r=n.mimeType||"image/png",i=r.split("/")[1];!async function(e,t,n){const r=await(await fetch(e)).blob(),i=document.createElement("a"),o=URL.createObjectURL(r);i.href=o,i.download=t,document.body.appendChild(i),i.click(),setTimeout((function(){document.body.removeChild(i),window.URL.revokeObjectURL(o)}),0)}(await e.toDataURL(n),t||"polotno."+i)},async _toPDF(t){const n=t.dpi||300,r=e=>.75*e;var i=new(await(pj?Promise.resolve(pj):new Promise((e=>{var t=document.createElement("script");t.onload=function(){pj=window.jspdf.jsPDF,e(pj)},t.src="https://unpkg.com/jspdf@2.2.0/dist/jspdf.umd.min.js",document.head.appendChild(t)}))))({unit:"pt",orientation:e.width>e.height?"landscape":"portrait",format:[r(e.width),r(e.height)]}),o=i.internal.pageSize.getWidth(),a=i.internal.pageSize.getHeight();const A=e._elementsPixelRatio,s=n/72;e.setElementsPixelRatio(s),await new Promise((e=>setTimeout(e)));for(const n of e.pages){0!==e.pages.indexOf(n)&&i.addPage(),i.addImage(await e.toDataURL({...t,pageId:n.id,pixelRatio:s}),0,0,o,a,void 0,"MEDIUM")}return e.setElementsPixelRatio(A),i},toPDFDataURL:async t=>(await e._toPDF({mimeType:"image/jpg",...t})).output("datauristring"),async saveAsPDF({fileName:t,dpi:n,...r}={}){(await e._toPDF({mimeType:"image/jpg",...r})).save(t||"polotno.pdf")},async waitLoading(){await IB()},toJSON:()=>({width:e.width,height:e.height,fonts:vR(e.fonts),pages:vR(e.pages)}),loadJSON(t,n=!1){e.pages.forEach((e=>e.children.forEach((e=>yR(e))))),e.pages=[],t._activePageId=t.pages[0]?.id,t.scale=e.scale,t._isKeyValid=e._isKeyValid,t.openedSidePanel=e.openedSidePanel,n&&(t.history=e.history.toJSON()),pR(e,t)},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=>bR(e)))},async loadFont(t){const n=e.fonts.find((e=>e.fontFamily===t))||x_.find((e=>e.fontFamily===t));n?function(e){const t=e.fontFamily;if(M_[t])return;if(!e.url&&!e.styles)return;const n=document.createElement("style");n.type="text/css";const r=e.styles||(e.url?[{src:`url("${e.url}")`}]:[]);let i="";r.forEach((e=>{i+=`\n @font-face {\n font-family: '${t}';\n src: ${e.src};\n font-style: ${e.fontStyle||"normal"};\n font-weight: ${e.fontWeight||"normal"};\n }\n `})),n.innerHTML=i,document.getElementsByTagName("head")[0].appendChild(n),M_[e.fontFamily]=!0}(n):function(e){if(H_[e])return;const t=`https://fonts.googleapis.com/css?family=${e.replace(/ /g,"+")}`,n=document.createElement("link");n.type="text/css",n.href=t,n.rel="stylesheet",document.getElementsByTagName("head")[0].appendChild(n),H_[e]=!0}(t),await z_(t)}})));function Oj({key:e,showCredit:t}={key:"",showCredit:!1}){const n=Sj.create();return n.__checkKey(e,t),n}const zj=IE("div")`
292
292
  display: flex;
293
293
  height: 100%;
294
294
  width: 100%;