polotno 2.6.2 → 2.6.4
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/group-model.d.ts +1 -1
- package/model/page-model.d.ts +1 -1
- package/model/store.d.ts +34 -31
- package/model/store.js +1 -1
- package/package.json +13 -13
- package/polotno-app.d.ts +94 -162
- package/polotno.bundle.js +9 -18
- package/side-panel/side-panel.d.ts +94 -162
- package/toolbar/toolbar.js +5 -1
- package/utils/to-svg.js +1 -1
package/model/group-model.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Instance } from 'mobx-state-tree';
|
|
2
2
|
export declare const forEveryChild: (node: any, cb: any) => void;
|
|
3
|
-
export declare const ElementTypes: import("mobx-state-tree").
|
|
3
|
+
export declare const ElementTypes: import("mobx-state-tree").ITypeUnion<any, any, any>;
|
|
4
4
|
export declare const GroupElement: any;
|
|
5
5
|
export declare const TYPES_MAP: any;
|
|
6
6
|
export declare function registerShapeModel(defaultAttributes: any, extendFunc?: any): void;
|
package/model/page-model.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Instance } from 'mobx-state-tree';
|
|
|
2
2
|
import { NodeType } from './node-model';
|
|
3
3
|
export declare const Page: import("mobx-state-tree").IModelType<{
|
|
4
4
|
id: import("mobx-state-tree").ISimpleType<string>;
|
|
5
|
-
children: import("mobx-state-tree").IArrayType<import("mobx-state-tree").
|
|
5
|
+
children: import("mobx-state-tree").IArrayType<import("mobx-state-tree").ITypeUnion<any, any, any>>;
|
|
6
6
|
width: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ITypeUnion<number | "auto", number | "auto", number | "auto">, [undefined]>;
|
|
7
7
|
height: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ITypeUnion<number | "auto", number | "auto", number | "auto">, [undefined]>;
|
|
8
8
|
background: import("mobx-state-tree").IType<string, string, string>;
|
package/model/store.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
30
30
|
role: import("mobx-state-tree").IType<string, string, string>;
|
|
31
31
|
pages: import("mobx-state-tree").IArrayType<import("mobx-state-tree").IModelType<{
|
|
32
32
|
id: import("mobx-state-tree").ISimpleType<string>;
|
|
33
|
-
children: import("mobx-state-tree").IArrayType<import("mobx-state-tree").
|
|
33
|
+
children: import("mobx-state-tree").IArrayType<import("mobx-state-tree").ITypeUnion<any, any, any>>;
|
|
34
34
|
width: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ITypeUnion<number | "auto", number | "auto", number | "auto">, [undefined]>;
|
|
35
35
|
height: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ITypeUnion<number | "auto", number | "auto", number | "auto">, [undefined]>;
|
|
36
36
|
background: import("mobx-state-tree").IType<string, string, string>;
|
|
@@ -127,7 +127,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
127
127
|
readonly selectedElements: any[];
|
|
128
128
|
readonly children: import("mobx-state-tree").IMSTArray<import("mobx-state-tree").IModelType<{
|
|
129
129
|
id: import("mobx-state-tree").ISimpleType<string>;
|
|
130
|
-
children: import("mobx-state-tree").IArrayType<import("mobx-state-tree").
|
|
130
|
+
children: import("mobx-state-tree").IArrayType<import("mobx-state-tree").ITypeUnion<any, any, any>>;
|
|
131
131
|
width: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ITypeUnion<number | "auto", number | "auto", number | "auto">, [undefined]>;
|
|
132
132
|
height: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ITypeUnion<number | "auto", number | "auto", number | "auto">, [undefined]>;
|
|
133
133
|
background: import("mobx-state-tree").IType<string, string, string>;
|
|
@@ -177,7 +177,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
177
177
|
play(): void;
|
|
178
178
|
}, import("mobx-state-tree")._NotCustomized, {}>> & import("mobx-state-tree").IStateTreeNode<import("mobx-state-tree").IArrayType<import("mobx-state-tree").IModelType<{
|
|
179
179
|
id: import("mobx-state-tree").ISimpleType<string>;
|
|
180
|
-
children: import("mobx-state-tree").IArrayType<import("mobx-state-tree").
|
|
180
|
+
children: import("mobx-state-tree").IArrayType<import("mobx-state-tree").ITypeUnion<any, any, any>>;
|
|
181
181
|
width: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ITypeUnion<number | "auto", number | "auto", number | "auto">, [undefined]>;
|
|
182
182
|
height: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ITypeUnion<number | "auto", number | "auto", number | "auto">, [undefined]>;
|
|
183
183
|
background: import("mobx-state-tree").IType<string, string, string>;
|
|
@@ -227,18 +227,18 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
227
227
|
play(): void;
|
|
228
228
|
}, import("mobx-state-tree")._NotCustomized, {}>>>;
|
|
229
229
|
readonly selectedShapes: any[];
|
|
230
|
-
readonly activePage: {
|
|
231
|
-
id: string
|
|
232
|
-
children: import("mobx-state-tree").
|
|
233
|
-
width: number | "auto"
|
|
234
|
-
height: number | "auto"
|
|
235
|
-
background: string
|
|
236
|
-
bleed: number
|
|
237
|
-
custom: any
|
|
238
|
-
duration: number
|
|
239
|
-
_exporting: boolean
|
|
240
|
-
_rendering: boolean
|
|
241
|
-
} &
|
|
230
|
+
readonly activePage: import("mobx-state-tree").ModelInstanceTypeProps<{
|
|
231
|
+
id: import("mobx-state-tree").ISimpleType<string>;
|
|
232
|
+
children: import("mobx-state-tree").IArrayType<import("mobx-state-tree").ITypeUnion<any, any, any>>;
|
|
233
|
+
width: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ITypeUnion<number | "auto", number | "auto", number | "auto">, [undefined]>;
|
|
234
|
+
height: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ITypeUnion<number | "auto", number | "auto", number | "auto">, [undefined]>;
|
|
235
|
+
background: import("mobx-state-tree").IType<string, string, string>;
|
|
236
|
+
bleed: import("mobx-state-tree").IType<number, number, number>;
|
|
237
|
+
custom: import("mobx-state-tree").IType<any, any, any>;
|
|
238
|
+
duration: import("mobx-state-tree").IType<number, number, number>;
|
|
239
|
+
_exporting: import("mobx-state-tree").IType<boolean, boolean, boolean>;
|
|
240
|
+
_rendering: import("mobx-state-tree").IType<boolean, boolean, boolean>;
|
|
241
|
+
}> & {
|
|
242
242
|
readonly store: any;
|
|
243
243
|
readonly startTime: number;
|
|
244
244
|
} & {
|
|
@@ -279,7 +279,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
279
279
|
play(): void;
|
|
280
280
|
} & import("mobx-state-tree").IStateTreeNode<import("mobx-state-tree").IModelType<{
|
|
281
281
|
id: import("mobx-state-tree").ISimpleType<string>;
|
|
282
|
-
children: import("mobx-state-tree").IArrayType<import("mobx-state-tree").
|
|
282
|
+
children: import("mobx-state-tree").IArrayType<import("mobx-state-tree").ITypeUnion<any, any, any>>;
|
|
283
283
|
width: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ITypeUnion<number | "auto", number | "auto", number | "auto">, [undefined]>;
|
|
284
284
|
height: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ITypeUnion<number | "auto", number | "auto", number | "auto">, [undefined]>;
|
|
285
285
|
background: import("mobx-state-tree").IType<string, string, string>;
|
|
@@ -352,18 +352,18 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
352
352
|
dpi: any;
|
|
353
353
|
}): void;
|
|
354
354
|
setRole(role: string): void;
|
|
355
|
-
addPage(attrs?: any): {
|
|
356
|
-
id: string
|
|
357
|
-
children: import("mobx-state-tree").
|
|
358
|
-
width: number | "auto"
|
|
359
|
-
height: number | "auto"
|
|
360
|
-
background: string
|
|
361
|
-
bleed: number
|
|
362
|
-
custom: any
|
|
363
|
-
duration: number
|
|
364
|
-
_exporting: boolean
|
|
365
|
-
_rendering: boolean
|
|
366
|
-
} &
|
|
355
|
+
addPage(attrs?: any): import("mobx-state-tree").ModelInstanceTypeProps<{
|
|
356
|
+
id: import("mobx-state-tree").ISimpleType<string>;
|
|
357
|
+
children: import("mobx-state-tree").IArrayType<import("mobx-state-tree").ITypeUnion<any, any, any>>;
|
|
358
|
+
width: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ITypeUnion<number | "auto", number | "auto", number | "auto">, [undefined]>;
|
|
359
|
+
height: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ITypeUnion<number | "auto", number | "auto", number | "auto">, [undefined]>;
|
|
360
|
+
background: import("mobx-state-tree").IType<string, string, string>;
|
|
361
|
+
bleed: import("mobx-state-tree").IType<number, number, number>;
|
|
362
|
+
custom: import("mobx-state-tree").IType<any, any, any>;
|
|
363
|
+
duration: import("mobx-state-tree").IType<number, number, number>;
|
|
364
|
+
_exporting: import("mobx-state-tree").IType<boolean, boolean, boolean>;
|
|
365
|
+
_rendering: import("mobx-state-tree").IType<boolean, boolean, boolean>;
|
|
366
|
+
}> & {
|
|
367
367
|
readonly store: any;
|
|
368
368
|
readonly startTime: number;
|
|
369
369
|
} & {
|
|
@@ -404,7 +404,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
404
404
|
play(): void;
|
|
405
405
|
} & import("mobx-state-tree").IStateTreeNode<import("mobx-state-tree").IModelType<{
|
|
406
406
|
id: import("mobx-state-tree").ISimpleType<string>;
|
|
407
|
-
children: import("mobx-state-tree").IArrayType<import("mobx-state-tree").
|
|
407
|
+
children: import("mobx-state-tree").IArrayType<import("mobx-state-tree").ITypeUnion<any, any, any>>;
|
|
408
408
|
width: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ITypeUnion<number | "auto", number | "auto", number | "auto">, [undefined]>;
|
|
409
409
|
height: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ITypeUnion<number | "auto", number | "auto", number | "auto">, [undefined]>;
|
|
410
410
|
background: import("mobx-state-tree").IType<string, string, string>;
|
|
@@ -490,9 +490,12 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
490
490
|
saveAsHTML({ fileName }?: {
|
|
491
491
|
fileName?: string;
|
|
492
492
|
}): Promise<void>;
|
|
493
|
-
toSVG(
|
|
494
|
-
|
|
493
|
+
toSVG({ elementHook }?: {
|
|
494
|
+
elementHook: any;
|
|
495
|
+
}): Promise<string>;
|
|
496
|
+
saveAsSVG({ fileName, elementHook, }?: {
|
|
495
497
|
fileName?: string;
|
|
498
|
+
elementHook?: Function;
|
|
496
499
|
}): Promise<void>;
|
|
497
500
|
saveAsPDF({ fileName, ...exportProps }?: ExportOptions & {
|
|
498
501
|
fileName?: string;
|
package/model/store.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,i,a){void 0===a&&(a=i);var o=Object.getOwnPropertyDescriptor(t,i);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,a,o)}:function(e,t,i,a){void 0===a&&(a=i),e[a]=t[i]}),__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 i in e)"default"!==i&&Object.prototype.hasOwnProperty.call(e,i)&&__createBinding(t,e,i);return __setModuleDefault(t,e),t},__rest=this&&this.__rest||function(e,t){var i={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.indexOf(a)<0&&(i[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(a=Object.getOwnPropertySymbols(e);o<a.length;o++)t.indexOf(a[o])<0&&Object.prototype.propertyIsEnumerable.call(e,a[o])&&(i[a[o]]=e[a[o]])}return i},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.createStore=exports.Store=exports.Font=void 0;const mobx_state_tree_1=require("mobx-state-tree"),history_1=require("./history"),nanoid_1=require("nanoid"),konva_1=__importDefault(require("konva")),download_1=require("../utils/download"),pdf_1=require("../utils/pdf"),gif_lib_1=require("../utils/gif-lib"),validate_key_1=require("../utils/validate-key"),fonts=__importStar(require("../utils/fonts")),loader_1=require("../utils/loader"),unit_1=require("../utils/unit"),deep_equal_1=require("../utils/deep-equal"),wait_1=require("../utils/wait"),html_1=require("../utils/html"),to_svg_1=require("../utils/to-svg"),page_model_1=require("./page-model"),group_model_1=require("./group-model");function createStore({key:e,showCredit:t}={key:"",showCredit:!1}){const i=exports.Store.create();return(0,validate_key_1.validateKey)(e,t),i}(0,mobx_state_tree_1.setLivelinessChecking)("ignore"),exports.Font=mobx_state_tree_1.types.model("Font",{fontFamily:mobx_state_tree_1.types.string,url:mobx_state_tree_1.types.optional(mobx_state_tree_1.types.string,""),styles:mobx_state_tree_1.types.frozen()}).preProcessSnapshot((e=>Object.assign(Object.assign({},e),{fontFamily:e.fontFamily||e.name}))),exports.Store=mobx_state_tree_1.types.model("Store",{role:"",pages:mobx_state_tree_1.types.array(page_model_1.Page),fonts:mobx_state_tree_1.types.array(exports.Font),width:1080,height:1080,currentTime:0,isPlaying:!1,scale:1,scaleToFit:1,unit:"px",dpi:72,bleedVisible:!1,rulesVisible:!1,openedSidePanel:"",previousOpenedSidePanel:"",custom:mobx_state_tree_1.types.frozen(),selectedElementsIds:mobx_state_tree_1.types.array(mobx_state_tree_1.types.string),animatedElementsIds:mobx_state_tree_1.types.array(mobx_state_tree_1.types.string),history:mobx_state_tree_1.types.optional(history_1.UndoManager,{targetPath:"../pages"}),_elementsPixelRatio:2,_activePageId:""}).views((e=>({get _bleedVisible(){return console.warn("store._bleedVisible is deprecated. Please use store.bleedVisible instead."),e.bleedVisible},get selectedElements(){return e.selectedElementsIds.map((t=>{for(const i of e.pages)for(const e of i.children)if(e.id===t)return e})).filter((e=>!!e))},get children(){return e.pages},get selectedShapes(){const t=[];return(0,group_model_1.forEveryChild)({children:e.selectedElements},(e=>{"group"!==e.type&&t.push(e)})),t},get activePage(){return e.pages.slice().find((t=>t.id===e._activePageId))||(e.pages.length?e.pages[0]:null)},get duration(){let t=0;return e.pages.forEach((e=>{t+=e.duration})),t},get _hasCroppedImages(){return e.find((e=>"image"===e.type&&e._cropModeEnabled))},find(t){let i;return(0,group_model_1.forEveryChild)({children:e.pages},(e=>{if(!i&&t(e))return i=e,!0})),i},getElementById:t=>e.find((e=>e.id===t))}))).actions((e=>{let t=0,i=null,a=!1;return{afterCreate(){e.history.canUndo},setCurrentTime(t){e.currentTime=t},play({animatedElementsIds:o=[],startTime:n=0,currentTime:s=0,endTime:r=e.duration,repeat:l=!1}={}){s&&(console.warn("currentTime property of store.play() is deprecated. Please use startTime instead."),n=s),e.animatedElementsIds=(0,mobx_state_tree_1.cast)(o),e.currentTime=n,e.isPlaying=!0,t=Date.now(),i=r,a=l,requestAnimationFrame(e.seek)},checkActivePage(){let t=0;for(const i of e.pages){if(e.currentTime>=i.startTime&&e.currentTime<i.startTime+i.duration){e.selectPage(i.id);break}t+=i.duration}},seek(){if(!e.isPlaying)return;const o=Date.now(),n=o-t;t=o,e.currentTime+=n,e.checkActivePage();const s=i||e.duration;e.isPlaying&&e.currentTime<s?requestAnimationFrame(e.seek):e.isPlaying&&a?(e.currentTime=0,requestAnimationFrame(e.seek)):e.stop()},stop(){e.isPlaying=!1,e.currentTime=0,e.animatedElementsIds=(0,mobx_state_tree_1.cast)([]),e.checkActivePage()}}})).actions((e=>({set(t){Object.assign(e,t)},setUnit({unit:t,dpi:i}){e.unit=t||e.unit,e.dpi=i||e.dpi},setRole(t){e.role=t},addPage(t){const i=page_model_1.Page.create(Object.assign({id:(0,nanoid_1.nanoid)(10)},t));return e.pages.push(i),e._activePageId=i.id,i},selectPage(t){e._activePageId=t},selectElements(t){const i=t.map((t=>e.getElementById(t))).sort(((e,t)=>e.page.children.indexOf(e)-e.page.children.indexOf(t))).filter((e=>!!e)).map((e=>e.id));e.selectedElementsIds=(0,mobx_state_tree_1.cast)(i)},toggleBleed(t){e.bleedVisible=null!=t?t:!e.bleedVisible},toggleRulers(t){e.rulesVisible=null!=t?t:!e.rulesVisible},openSidePanel(t){e.openedSidePanel!==t&&(e.previousOpenedSidePanel=e.openedSidePanel,e.openedSidePanel=t)},setScale(t){e.scale=t},_setScaleToFit(t){e.scaleToFit=t},setElementsPixelRatio(t){e._elementsPixelRatio=t},setSize(t,i,a){e.pages.forEach((e=>{e.setSize({width:t,height:i,useMagic:a,softChange:!0})})),e.width=t,e.height=i},setPageZIndex(t,i){const a=e.pages.find((e=>e.id===t));a&&((0,mobx_state_tree_1.detach)(a),e.pages.remove(a),e.pages.splice(i,0,a))},deletePages(t){const i=e.pages.indexOf(e.activePage);t.forEach((t=>{const i=e.pages.find((e=>e.id===t));(0,mobx_state_tree_1.destroy)(i)}));const a=Math.min(e.pages.length-1,i),o=e.pages[a];o&&(e._activePageId=o.id),e.selectedElementsIds=(0,mobx_state_tree_1.cast)(e.selectedElementsIds.filter((t=>e.getElementById(t))))},groupElements(t){const i=t.map((t=>e.getElementById(t)));i.forEach((e=>{e&&(0,mobx_state_tree_1.detach)(e)}));const a=e.activePage,o={id:(0,nanoid_1.nanoid)(10),children:i,type:"group"};return a.children.push(o),e.selectedElementsIds=(0,mobx_state_tree_1.cast)([o.id]),o},ungroupElements(t){const i=t.map((t=>e.getElementById(t))),a=[];i.forEach((e=>{if(e&&"group"===e.type){const t=e.page,i=t.children.indexOf(e);e.children.forEach((e=>{a.push(e.id)})),e.children.forEach((e=>{(0,mobx_state_tree_1.detach)(e),t.children.push(e)})),t.children.splice(i,1)}})),e.selectedElementsIds=(0,mobx_state_tree_1.cast)(a)},deleteElements(t){const i=[];e.find((e=>(t.includes(e.id)&&i.push(e),!1))),i.forEach((e=>{(0,mobx_state_tree_1.destroy)(e)})),e.selectedElementsIds=(0,mobx_state_tree_1.cast)(e.selectedElementsIds.filter((t=>e.getElementById(t))))},on(t,i){if("change"===t){let t=e.toJSON();return(0,mobx_state_tree_1.onSnapshot)(e,(a=>{const o=e.toJSON();!(0,deep_equal_1.deepEqual)(t,o)&&(t=o,i(o))}))}},async _toCanvas({pixelRatio:t,ignoreBackground:i,pageId:a,mimeType:o,includeBleed:n,_skipTimeout:s}={}){var r;const l=t||1;a=a||(null===(r=e.pages[0])||void 0===r?void 0:r.id);const d=e.pages.find((e=>e.id===a));if(!d)throw new Error(`No page for export with id ${a}`);null==d||d.set({_exporting:!0});const c=await(0,wait_1.waitTillAvailable)((()=>konva_1.default.stages.find((e=>e.getAttr("pageId")===a))));if(!c)throw new Error(`Export is failed. Can not find stage for page ${a}. Looks like <Workspace /> component is not mounted, but it is required in order to process the export.`);const p=!!c.findOne(".page-container"),u=e._elementsPixelRatio;l>e._elementsPixelRatio&&e.setElementsPixelRatio(l),await e.waitLoading({_skipTimeout:s});const _=c.findOne(".page-container");if(!_)throw e.setElementsPixelRatio(u),new Error(`Export is failed. Can't find page container. ${p}`);c.find("Transformer").forEach((e=>e.visible(!1))),_.find(".page-background").forEach((e=>e.shadowEnabled(!1))),_.find(".page-background").forEach((e=>e.strokeEnabled(!1))),_.find(".highlighter").forEach((e=>e.visible(!1)));const g=_.findOne(".page-background-group"),m=g.clip();g.clip({x:null,y:null,width:null,height:null});const f=_.findOne(".elements-container"),h=f.clip();f.clip({x:null,y:null,width:null,height:null});const b=_.find((e=>e.getAttr("hideInExport")));b.forEach((e=>{e.setAttr("oldVisible",e.visible()),e.hide()}));const y=_.find((e=>!e.visible()&&e.getAttr("editModeEnabled")));y.forEach((e=>{e.setAttr("oldVisible",e.visible()),e.show()})),i&&_.find(".page-background").forEach((e=>e.hide()));const v=n?d.bleed:0;let x=v;!e.bleedVisible&&n||(e.bleedVisible||n?e.bleedVisible&&n?x=0:e.bleedVisible&&!n&&(x=-d.bleed):x=0);const w=document.createElement("canvas");w.width=Math.round((d.computedWidth+2*v)*l),w.height=Math.round((d.computedHeight+2*v)*l);const E=w.getContext("2d");"image/jpeg"===o&&(E.fillStyle="white",E.fillRect(0,0,w.width,w.height));const P=_.scale();_.scale({x:1,y:1});const O=_.toCanvas({x:_.x()-x,y:_.y()-x,width:d.computedWidth+2*v,height:d.computedHeight+2*v,pixelRatio:l});return _.scale(P),E.drawImage(O,0,0,w.width,w.height),konva_1.default.Util.releaseCanvas(O),i&&_.find(".page-background").forEach((e=>e.show())),b.forEach((e=>{e.visible(e.getAttr("oldVisible"))})),y.forEach((e=>{e.visible(e.getAttr("oldVisible"))})),_.find(".page-background").forEach((e=>e.shadowEnabled(!0))),_.find(".page-background").forEach((e=>e.strokeEnabled(!0))),c.find("Transformer").forEach((e=>e.visible(!0))),_.find(".highlighter").forEach((e=>e.visible(!0))),g.clip(m),f.clip(h),e.setElementsPixelRatio(u),null==d||d.set({_exporting:!1}),w},async toDataURL(t={}){var{mimeType:i,quality:a}=t,o=__rest(t,["mimeType","quality"]);const n=await e._toCanvas(Object.assign({mimeType:i},o)),s=n.toDataURL(i,a);return konva_1.default.Util.releaseCanvas(n),s},async toBlob(t={}){var{mimeType:i,quality:a}=t,o=__rest(t,["mimeType","quality"]);const n=await e._toCanvas(Object.assign({mimeType:i},o)),s=new Promise((e=>{n.toBlob(e,i,a)}));return konva_1.default.Util.releaseCanvas(n),s},async saveAsImage(t={}){var{fileName:i}=t,a=__rest(t,["fileName"]);const o=a.mimeType||"image/png",n=o.split("/")[1];(0,download_1.downloadFile)(await e.toDataURL(a),i||"polotno."+n,o)},async _toPDF(t){const i=t.dpi||e.dpi,a=t.parallel||1,o=t.unit||("px"===e.unit?"mm":e.unit),n=t.pixelRatio||1,s=t.pageIds||e.pages.map((e=>e.id)),r=e.pages.filter((e=>s.includes(e.id))),l=await(0,pdf_1.getJsPDF)(),d=e=>(0,unit_1.pxToUnit)({px:e,unit:o,dpi:i}),c=d(t.cropMarkSize||0),p=r[0]||{},u=t.includeBleed?p.bleed:0,_=d(p.computedWidth+2*u)+2*c,g=d(p.computedHeight+2*u)+2*c;var m=new l({unit:o,orientation:_>g?"landscape":"portrait",format:[_,g],compress:!0,putOnlyUsedFonts:!0});m.deletePage(1);const f=((e,t)=>{for(var i=[],a=0;a<e.length;a+=t)i.push(e.slice(a,a+t));return i})(r,a);for(const i of f){const a=i.map((async i=>{const a=t.includeBleed?i.bleed:0,o=d(i.computedWidth+2*a)+2*c,s=d(i.computedHeight+2*a)+2*c;let r=0,l=n;for(;r<10;){r+=1,2===r&&console.error("Polotno can not export PDF with current settings. Quality is automatically reduced.");const a=await e.toDataURL(Object.assign(Object.assign({},t),{pageId:i.id,pixelRatio:l}));if(a.length>20)return{url:a,width:o,height:s};l*=.8}}));(await Promise.all(a)).forEach((({url:e,width:t,height:i})=>{m.addPage([t,i],t>i?"landscape":"portrait"),c&&(m.setLineWidth(d(1)),m.line(2*c,0,2*c,c),m.line(0,2*c,c,2*c),m.line(t-2*c,0,t-2*c,c),m.line(t,2*c,t-c,2*c),m.line(0,i-2*c,c,i-2*c),m.line(2*c,i,2*c,i-c),m.line(t,i-2*c,t-c,i-2*c),m.line(t-2*c,i,t-2*c,i-c)),m.addImage(e,c,c,t-2*c,i-2*c,void 0,"FAST")}))}return m},toPDFDataURL:async t=>(await e._toPDF(Object.assign({mimeType:"image/jpeg"},t))).output("datauristring"),async toGIFDataURL(t={}){const i=t.pixelRatio||1,a=await(0,gif_lib_1.createGIF)({width:e.width*i,height:e.height*i}),o=1e3/(t.fps||10),n=e.duration/o;for(let t=0;t<n-1;t++){const n=t*o||1;e.setCurrentTime(n);let s=0,r="";for(const t of e.pages)if(s+=t.duration,t.set({_rendering:s>n}),s>n){r=t.id;break}const l=await e._toCanvas({pixelRatio:i,pageId:r,_skipTimeout:!0});a.addFrame(l.getContext("2d"),{delay:o,copy:!0})}for(const t of e.pages)t.set({_rendering:!1});e.stop(),a.render();return new Promise((e=>{a.on("finished",(function(t){!function(e,t){var i=new FileReader;i.onload=function(e){t(e.target.result)},i.readAsDataURL(e)}(t,e)}))}))},async saveAsGIF(t={}){var{fileName:i}=t,a=__rest(t,["fileName"]);const o=await e.toGIFDataURL(a);(0,download_1.downloadFile)(o,i||"polotno.gif")},async toHTML({elementHook:t}={elementHook:void 0}){const i=e.toJSON();return(0,html_1.jsonToHTML)({json:i,elementHook:t})},async saveAsHTML({fileName:t}={}){const i=await e.toHTML(),a="data:text/html;base64,"+window.btoa(unescape(encodeURIComponent(i)));(0,download_1.downloadFile)(a,t||"polotno.html")},async toSVG(){const t=e.toJSON();return(0,to_svg_1.jsonToSVG)({json:t})},async saveAsSVG({fileName:t}={}){const i=await e.toSVG(),a="data:text/svg;base64,"+window.btoa(unescape(encodeURIComponent(i)));(0,download_1.downloadFile)(a,t||"polotno.svg")},async saveAsPDF(t={}){var{fileName:i}=t,a=__rest(t,["fileName"]);(await e._toPDF(Object.assign({mimeType:"image/jpeg"},a))).save(i||"polotno.pdf")},async waitLoading({_skipTimeout:e=!1}={}){e||await new Promise((e=>setTimeout(e,50))),await(0,loader_1.whenLoaded)()},toJSON:()=>({width:e.width,height:e.height,fonts:(0,mobx_state_tree_1.getSnapshot)(e.fonts),pages:(0,mobx_state_tree_1.getSnapshot)(e.pages),unit:e.unit,dpi:e.dpi,custom:e.custom}),loadJSON(t,i=!1){var a;const o=Object.assign({},t),n=e.pages.indexOf(e.activePage);let s=null===(a=o.pages[n]||o.pages[0])||void 0===a?void 0:a.id;o._activePageId=s;const r=Object.assign({},(0,mobx_state_tree_1.getSnapshot)(e));Object.assign(r,o),r.history=i?e.history.toJSON():{history:[],undoIdx:-1},(0,mobx_state_tree_1.applySnapshot)(e,r)},clear({keepHistory:t=!1}={}){const i=e.pages.map((e=>e.id));e.deletePages(i),t||e.history.clear()},addFont(t){e.removeFont(t.fontFamily),e.fonts.push(t),e.loadFont(t.fontFamily)},removeFont(t){e.fonts.filter((e=>e.fontFamily===t)).forEach((e=>(0,mobx_state_tree_1.destroy)(e)))},async loadFont(t){const i=e.fonts.find((e=>e.fontFamily===t))||fonts.globalFonts.find((e=>e.fontFamily===t));i?fonts.injectCustomFont(i):fonts.injectGoogleFont(t),await fonts.loadFont(t)},validate:e=>exports.Store.validate(e,[{path:"",type:exports.Store}]).map((e=>({path:"store"+e.context.map((e=>e.path)).join("."),message:e.message})))}))),exports.createStore=createStore,exports.default=createStore;
|
|
1
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,i,a){void 0===a&&(a=i);var o=Object.getOwnPropertyDescriptor(t,i);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,a,o)}:function(e,t,i,a){void 0===a&&(a=i),e[a]=t[i]}),__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 i in e)"default"!==i&&Object.prototype.hasOwnProperty.call(e,i)&&__createBinding(t,e,i);return __setModuleDefault(t,e),t},__rest=this&&this.__rest||function(e,t){var i={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.indexOf(a)<0&&(i[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(a=Object.getOwnPropertySymbols(e);o<a.length;o++)t.indexOf(a[o])<0&&Object.prototype.propertyIsEnumerable.call(e,a[o])&&(i[a[o]]=e[a[o]])}return i},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.createStore=exports.Store=exports.Font=void 0;const mobx_state_tree_1=require("mobx-state-tree"),history_1=require("./history"),nanoid_1=require("nanoid"),konva_1=__importDefault(require("konva")),download_1=require("../utils/download"),pdf_1=require("../utils/pdf"),gif_lib_1=require("../utils/gif-lib"),validate_key_1=require("../utils/validate-key"),fonts=__importStar(require("../utils/fonts")),loader_1=require("../utils/loader"),unit_1=require("../utils/unit"),deep_equal_1=require("../utils/deep-equal"),wait_1=require("../utils/wait"),html_1=require("../utils/html"),to_svg_1=require("../utils/to-svg"),page_model_1=require("./page-model"),group_model_1=require("./group-model");function createStore({key:e,showCredit:t}={key:"",showCredit:!1}){const i=exports.Store.create();return(0,validate_key_1.validateKey)(e,t),i}(0,mobx_state_tree_1.setLivelinessChecking)("ignore"),exports.Font=mobx_state_tree_1.types.model("Font",{fontFamily:mobx_state_tree_1.types.string,url:mobx_state_tree_1.types.optional(mobx_state_tree_1.types.string,""),styles:mobx_state_tree_1.types.frozen()}).preProcessSnapshot((e=>Object.assign(Object.assign({},e),{fontFamily:e.fontFamily||e.name}))),exports.Store=mobx_state_tree_1.types.model("Store",{role:"",pages:mobx_state_tree_1.types.array(page_model_1.Page),fonts:mobx_state_tree_1.types.array(exports.Font),width:1080,height:1080,currentTime:0,isPlaying:!1,scale:1,scaleToFit:1,unit:"px",dpi:72,bleedVisible:!1,rulesVisible:!1,openedSidePanel:"",previousOpenedSidePanel:"",custom:mobx_state_tree_1.types.frozen(),selectedElementsIds:mobx_state_tree_1.types.array(mobx_state_tree_1.types.string),animatedElementsIds:mobx_state_tree_1.types.array(mobx_state_tree_1.types.string),history:mobx_state_tree_1.types.optional(history_1.UndoManager,{targetPath:"../pages"}),_elementsPixelRatio:2,_activePageId:""}).views((e=>({get _bleedVisible(){return console.warn("store._bleedVisible is deprecated. Please use store.bleedVisible instead."),e.bleedVisible},get selectedElements(){return e.selectedElementsIds.map((t=>{for(const i of e.pages)for(const e of i.children)if(e.id===t)return e})).filter((e=>!!e))},get children(){return e.pages},get selectedShapes(){const t=[];return(0,group_model_1.forEveryChild)({children:e.selectedElements},(e=>{"group"!==e.type&&t.push(e)})),t},get activePage(){return e.pages.slice().find((t=>t.id===e._activePageId))||(e.pages.length?e.pages[0]:null)},get duration(){let t=0;return e.pages.forEach((e=>{t+=e.duration})),t},get _hasCroppedImages(){return e.find((e=>"image"===e.type&&e._cropModeEnabled))},find(t){let i;return(0,group_model_1.forEveryChild)({children:e.pages},(e=>{if(!i&&t(e))return i=e,!0})),i},getElementById:t=>e.find((e=>e.id===t))}))).actions((e=>{let t=0,i=null,a=!1;return{afterCreate(){e.history.canUndo},setCurrentTime(t){e.currentTime=t},play({animatedElementsIds:o=[],startTime:n=0,currentTime:s=0,endTime:r=e.duration,repeat:l=!1}={}){s&&(console.warn("currentTime property of store.play() is deprecated. Please use startTime instead."),n=s),e.animatedElementsIds=(0,mobx_state_tree_1.cast)(o),e.currentTime=n,e.isPlaying=!0,t=Date.now(),i=r,a=l,requestAnimationFrame(e.seek)},checkActivePage(){let t=0;for(const i of e.pages){if(e.currentTime>=i.startTime&&e.currentTime<i.startTime+i.duration){e.selectPage(i.id);break}t+=i.duration}},seek(){if(!e.isPlaying)return;const o=Date.now(),n=o-t;t=o,e.currentTime+=n,e.checkActivePage();const s=i||e.duration;e.isPlaying&&e.currentTime<s?requestAnimationFrame(e.seek):e.isPlaying&&a?(e.currentTime=0,requestAnimationFrame(e.seek)):e.stop()},stop(){e.isPlaying=!1,e.currentTime=0,e.animatedElementsIds=(0,mobx_state_tree_1.cast)([]),e.checkActivePage()}}})).actions((e=>({set(t){Object.assign(e,t)},setUnit({unit:t,dpi:i}){e.unit=t||e.unit,e.dpi=i||e.dpi},setRole(t){e.role=t},addPage(t){const i=page_model_1.Page.create(Object.assign({id:(0,nanoid_1.nanoid)(10)},t));return e.pages.push(i),e._activePageId=i.id,i},selectPage(t){e._activePageId=t},selectElements(t){const i=t.map((t=>e.getElementById(t))).sort(((e,t)=>e.page.children.indexOf(e)-e.page.children.indexOf(t))).filter((e=>!!e)).map((e=>e.id));e.selectedElementsIds=(0,mobx_state_tree_1.cast)(i)},toggleBleed(t){e.bleedVisible=null!=t?t:!e.bleedVisible},toggleRulers(t){e.rulesVisible=null!=t?t:!e.rulesVisible},openSidePanel(t){e.openedSidePanel!==t&&(e.previousOpenedSidePanel=e.openedSidePanel,e.openedSidePanel=t)},setScale(t){e.scale=t},_setScaleToFit(t){e.scaleToFit=t},setElementsPixelRatio(t){e._elementsPixelRatio=t},setSize(t,i,a){e.pages.forEach((e=>{e.setSize({width:t,height:i,useMagic:a,softChange:!0})})),e.width=t,e.height=i},setPageZIndex(t,i){const a=e.pages.find((e=>e.id===t));a&&((0,mobx_state_tree_1.detach)(a),e.pages.remove(a),e.pages.splice(i,0,a))},deletePages(t){const i=e.pages.indexOf(e.activePage);t.forEach((t=>{const i=e.pages.find((e=>e.id===t));(0,mobx_state_tree_1.destroy)(i)}));const a=Math.min(e.pages.length-1,i),o=e.pages[a];o&&(e._activePageId=o.id),e.selectedElementsIds=(0,mobx_state_tree_1.cast)(e.selectedElementsIds.filter((t=>e.getElementById(t))))},groupElements(t){const i=t.map((t=>e.getElementById(t)));i.forEach((e=>{e&&(0,mobx_state_tree_1.detach)(e)}));const a=e.activePage,o={id:(0,nanoid_1.nanoid)(10),children:i,type:"group"};return a.children.push(o),e.selectedElementsIds=(0,mobx_state_tree_1.cast)([o.id]),o},ungroupElements(t){const i=t.map((t=>e.getElementById(t))),a=[];i.forEach((e=>{if(e&&"group"===e.type){const t=e.page,i=t.children.indexOf(e);e.children.forEach((e=>{a.push(e.id)})),e.children.forEach((e=>{(0,mobx_state_tree_1.detach)(e),t.children.push(e)})),t.children.splice(i,1)}})),e.selectedElementsIds=(0,mobx_state_tree_1.cast)(a)},deleteElements(t){const i=[];e.find((e=>(t.includes(e.id)&&i.push(e),!1))),i.forEach((e=>{(0,mobx_state_tree_1.destroy)(e)})),e.selectedElementsIds=(0,mobx_state_tree_1.cast)(e.selectedElementsIds.filter((t=>e.getElementById(t))))},on(t,i){if("change"===t){let t=e.toJSON();return(0,mobx_state_tree_1.onSnapshot)(e,(a=>{const o=e.toJSON();!(0,deep_equal_1.deepEqual)(t,o)&&(t=o,i(o))}))}},async _toCanvas({pixelRatio:t,ignoreBackground:i,pageId:a,mimeType:o,includeBleed:n,_skipTimeout:s}={}){var r;const l=t||1;a=a||(null===(r=e.pages[0])||void 0===r?void 0:r.id);const d=e.pages.find((e=>e.id===a));if(!d)throw new Error(`No page for export with id ${a}`);null==d||d.set({_exporting:!0});const c=await(0,wait_1.waitTillAvailable)((()=>konva_1.default.stages.find((e=>e.getAttr("pageId")===a))));if(!c)throw new Error(`Export is failed. Can not find stage for page ${a}. Looks like <Workspace /> component is not mounted, but it is required in order to process the export.`);const p=!!c.findOne(".page-container"),u=e._elementsPixelRatio;l>e._elementsPixelRatio&&e.setElementsPixelRatio(l),await e.waitLoading({_skipTimeout:s});const _=c.findOne(".page-container");if(!_)throw e.setElementsPixelRatio(u),new Error(`Export is failed. Can't find page container. ${p}`);c.find("Transformer").forEach((e=>e.visible(!1))),_.find(".page-background").forEach((e=>e.shadowEnabled(!1))),_.find(".page-background").forEach((e=>e.strokeEnabled(!1))),_.find(".highlighter").forEach((e=>e.visible(!1)));const g=_.findOne(".page-background-group"),m=g.clip();g.clip({x:null,y:null,width:null,height:null});const f=_.findOne(".elements-container"),h=f.clip();f.clip({x:null,y:null,width:null,height:null});const b=_.find((e=>e.getAttr("hideInExport")));b.forEach((e=>{e.setAttr("oldVisible",e.visible()),e.hide()}));const y=_.find((e=>!e.visible()&&e.getAttr("editModeEnabled")));y.forEach((e=>{e.setAttr("oldVisible",e.visible()),e.show()})),i&&_.find(".page-background").forEach((e=>e.hide()));const v=n?d.bleed:0;let x=v;!e.bleedVisible&&n||(e.bleedVisible||n?e.bleedVisible&&n?x=0:e.bleedVisible&&!n&&(x=-d.bleed):x=0);const w=document.createElement("canvas");w.width=Math.round((d.computedWidth+2*v)*l),w.height=Math.round((d.computedHeight+2*v)*l);const E=w.getContext("2d");"image/jpeg"===o&&(E.fillStyle="white",E.fillRect(0,0,w.width,w.height));const P=_.scale();_.scale({x:1,y:1});const O=_.toCanvas({x:_.x()-x,y:_.y()-x,width:d.computedWidth+2*v,height:d.computedHeight+2*v,pixelRatio:l});return _.scale(P),E.drawImage(O,0,0,w.width,w.height),konva_1.default.Util.releaseCanvas(O),i&&_.find(".page-background").forEach((e=>e.show())),b.forEach((e=>{e.visible(e.getAttr("oldVisible"))})),y.forEach((e=>{e.visible(e.getAttr("oldVisible"))})),_.find(".page-background").forEach((e=>e.shadowEnabled(!0))),_.find(".page-background").forEach((e=>e.strokeEnabled(!0))),c.find("Transformer").forEach((e=>e.visible(!0))),_.find(".highlighter").forEach((e=>e.visible(!0))),g.clip(m),f.clip(h),e.setElementsPixelRatio(u),null==d||d.set({_exporting:!1}),w},async toDataURL(t={}){var{mimeType:i,quality:a}=t,o=__rest(t,["mimeType","quality"]);const n=await e._toCanvas(Object.assign({mimeType:i},o)),s=n.toDataURL(i,a);return konva_1.default.Util.releaseCanvas(n),s},async toBlob(t={}){var{mimeType:i,quality:a}=t,o=__rest(t,["mimeType","quality"]);const n=await e._toCanvas(Object.assign({mimeType:i},o)),s=new Promise((e=>{n.toBlob(e,i,a)}));return konva_1.default.Util.releaseCanvas(n),s},async saveAsImage(t={}){var{fileName:i}=t,a=__rest(t,["fileName"]);const o=a.mimeType||"image/png",n=o.split("/")[1];(0,download_1.downloadFile)(await e.toDataURL(a),i||"polotno."+n,o)},async _toPDF(t){const i=t.dpi||e.dpi,a=t.parallel||1,o=t.unit||("px"===e.unit?"mm":e.unit),n=t.pixelRatio||1,s=t.pageIds||e.pages.map((e=>e.id)),r=e.pages.filter((e=>s.includes(e.id))),l=await(0,pdf_1.getJsPDF)(),d=e=>(0,unit_1.pxToUnit)({px:e,unit:o,dpi:i}),c=d(t.cropMarkSize||0),p=r[0]||{},u=t.includeBleed?p.bleed:0,_=d(p.computedWidth+2*u)+2*c,g=d(p.computedHeight+2*u)+2*c;var m=new l({unit:o,orientation:_>g?"landscape":"portrait",format:[_,g],compress:!0,putOnlyUsedFonts:!0});m.deletePage(1);const f=((e,t)=>{for(var i=[],a=0;a<e.length;a+=t)i.push(e.slice(a,a+t));return i})(r,a);for(const i of f){const a=i.map((async i=>{const a=t.includeBleed?i.bleed:0,o=d(i.computedWidth+2*a)+2*c,s=d(i.computedHeight+2*a)+2*c;let r=0,l=n;for(;r<10;){r+=1,2===r&&console.error("Polotno can not export PDF with current settings. Quality is automatically reduced.");const a=await e.toDataURL(Object.assign(Object.assign({},t),{pageId:i.id,pixelRatio:l}));if(a.length>20)return{url:a,width:o,height:s};l*=.8}}));(await Promise.all(a)).forEach((({url:e,width:t,height:i})=>{m.addPage([t,i],t>i?"landscape":"portrait"),c&&(m.setLineWidth(d(1)),m.line(2*c,0,2*c,c),m.line(0,2*c,c,2*c),m.line(t-2*c,0,t-2*c,c),m.line(t,2*c,t-c,2*c),m.line(0,i-2*c,c,i-2*c),m.line(2*c,i,2*c,i-c),m.line(t,i-2*c,t-c,i-2*c),m.line(t-2*c,i,t-2*c,i-c)),m.addImage(e,c,c,t-2*c,i-2*c,void 0,"FAST")}))}return m},toPDFDataURL:async t=>(await e._toPDF(Object.assign({mimeType:"image/jpeg"},t))).output("datauristring"),async toGIFDataURL(t={}){const i=t.pixelRatio||1,a=await(0,gif_lib_1.createGIF)({width:e.width*i,height:e.height*i}),o=1e3/(t.fps||10),n=e.duration/o;for(let t=0;t<n-1;t++){const n=t*o||1;e.setCurrentTime(n);let s=0,r="";for(const t of e.pages)if(s+=t.duration,t.set({_rendering:s>n}),s>n){r=t.id;break}const l=await e._toCanvas({pixelRatio:i,pageId:r,_skipTimeout:!0});a.addFrame(l.getContext("2d"),{delay:o,copy:!0})}for(const t of e.pages)t.set({_rendering:!1});e.stop(),a.render();return new Promise((e=>{a.on("finished",(function(t){!function(e,t){var i=new FileReader;i.onload=function(e){t(e.target.result)},i.readAsDataURL(e)}(t,e)}))}))},async saveAsGIF(t={}){var{fileName:i}=t,a=__rest(t,["fileName"]);const o=await e.toGIFDataURL(a);(0,download_1.downloadFile)(o,i||"polotno.gif")},async toHTML({elementHook:t}={elementHook:void 0}){const i=e.toJSON();return(0,html_1.jsonToHTML)({json:i,elementHook:t})},async saveAsHTML({fileName:t}={}){const i=await e.toHTML(),a="data:text/html;base64,"+window.btoa(unescape(encodeURIComponent(i)));(0,download_1.downloadFile)(a,t||"polotno.html")},async toSVG({elementHook:t}={elementHook:void 0}){const i=e.toJSON();return(0,to_svg_1.jsonToSVG)({json:i,elementHook:t})},async saveAsSVG({fileName:t,elementHook:i}={}){const a=await e.toSVG({elementHook:i}),o="data:text/svg;base64,"+window.btoa(unescape(encodeURIComponent(a)));(0,download_1.downloadFile)(o,t||"polotno.svg")},async saveAsPDF(t={}){var{fileName:i}=t,a=__rest(t,["fileName"]);(await e._toPDF(Object.assign({mimeType:"image/jpeg"},a))).save(i||"polotno.pdf")},async waitLoading({_skipTimeout:e=!1}={}){e||await new Promise((e=>setTimeout(e,50))),await(0,loader_1.whenLoaded)()},toJSON:()=>({width:e.width,height:e.height,fonts:(0,mobx_state_tree_1.getSnapshot)(e.fonts),pages:(0,mobx_state_tree_1.getSnapshot)(e.pages),unit:e.unit,dpi:e.dpi,custom:e.custom}),loadJSON(t,i=!1){var a;const o=Object.assign({},t),n=e.pages.indexOf(e.activePage);let s=null===(a=o.pages[n]||o.pages[0])||void 0===a?void 0:a.id;o._activePageId=s;const r=Object.assign({},(0,mobx_state_tree_1.getSnapshot)(e));Object.assign(r,o),r.history=i?e.history.toJSON():{history:[],undoIdx:-1},(0,mobx_state_tree_1.applySnapshot)(e,r)},clear({keepHistory:t=!1}={}){const i=e.pages.map((e=>e.id));e.deletePages(i),t||e.history.clear()},addFont(t){e.removeFont(t.fontFamily),e.fonts.push(t),e.loadFont(t.fontFamily)},removeFont(t){e.fonts.filter((e=>e.fontFamily===t)).forEach((e=>(0,mobx_state_tree_1.destroy)(e)))},async loadFont(t){const i=e.fonts.find((e=>e.fontFamily===t))||fonts.globalFonts.find((e=>e.fontFamily===t));i?fonts.injectCustomFont(i):fonts.injectGoogleFont(t),await fonts.loadFont(t)},validate:e=>exports.Store.validate(e,[{path:"",type:exports.Store}]).map((e=>({path:"store"+e.context.map((e=>e.path)).join("."),message:e.message})))}))),exports.createStore=createStore,exports.default=createStore;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polotno",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.4",
|
|
4
4
|
"description": "Design Editor Framework",
|
|
5
5
|
"author": "Anton Lavrenov",
|
|
6
6
|
"keywords": [
|
|
@@ -10,16 +10,16 @@
|
|
|
10
10
|
"design editor"
|
|
11
11
|
],
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@blueprintjs/core": "5.10.
|
|
14
|
-
"@blueprintjs/select": "5.1.
|
|
13
|
+
"@blueprintjs/core": "5.10.3",
|
|
14
|
+
"@blueprintjs/select": "5.1.5",
|
|
15
15
|
"@meronex/icons": "^4.0.0",
|
|
16
16
|
"fast-json-patch": "^3.1.1",
|
|
17
17
|
"functions-have-names": "^1.2.3",
|
|
18
18
|
"gradient-parser": "^1.0.2",
|
|
19
|
-
"konva": "^9.3.
|
|
20
|
-
"mobx": "6.12.
|
|
21
|
-
"mobx-react-lite": "^4.0.
|
|
22
|
-
"mobx-state-tree": "
|
|
19
|
+
"konva": "^9.3.11",
|
|
20
|
+
"mobx": "6.12.3",
|
|
21
|
+
"mobx-react-lite": "^4.0.7",
|
|
22
|
+
"mobx-state-tree": "6.0.0",
|
|
23
23
|
"nanoid": "3.3.4",
|
|
24
24
|
"quill": "^1.3.7",
|
|
25
25
|
"quill-paste-smart": "^1.4.12",
|
|
@@ -62,9 +62,9 @@
|
|
|
62
62
|
],
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@canvas/image": "^2.0.0",
|
|
65
|
-
"@size-limit/preset-big-lib": "^11.1.
|
|
65
|
+
"@size-limit/preset-big-lib": "^11.1.4",
|
|
66
66
|
"@types/jest": "^29",
|
|
67
|
-
"@types/react": "^18.
|
|
67
|
+
"@types/react": "^18.3.3",
|
|
68
68
|
"@types/sanitize-html": "^2.11.0",
|
|
69
69
|
"@vitest/browser": "^0.34.6",
|
|
70
70
|
"assert": "^2.1.0",
|
|
@@ -77,12 +77,12 @@
|
|
|
77
77
|
"process": "^0.11.10",
|
|
78
78
|
"punycode": "^2.3.1",
|
|
79
79
|
"querystring-es3": "^0.2.1",
|
|
80
|
-
"react": "^18.
|
|
81
|
-
"react-dom": "^18.
|
|
82
|
-
"size-limit": "^11.1.
|
|
80
|
+
"react": "^18.3.1",
|
|
81
|
+
"react-dom": "^18.3.1",
|
|
82
|
+
"size-limit": "^11.1.4",
|
|
83
83
|
"svg-path-bounds": "^1.0.2",
|
|
84
84
|
"ts-jest": "^29",
|
|
85
|
-
"typescript": "^5.
|
|
85
|
+
"typescript": "^5.4.5",
|
|
86
86
|
"uglifyjs-folder": "^3.3.0",
|
|
87
87
|
"vitest": "^0.34.6"
|
|
88
88
|
},
|