polotno 4.17.0 → 4.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/blueprint/side-panel/select-video.d.ts +18 -16
- package/canvas/animated-shadow.d.ts +11 -0
- package/canvas/animated-shadow.js +1 -0
- package/canvas/apply-filters.d.ts +5 -1
- package/canvas/apply-filters.js +1 -1
- package/canvas/downscale.js +1 -1
- package/canvas/element.js +1 -1
- package/canvas/figure-element.js +1 -1
- package/canvas/gif-element.js +1 -1
- package/canvas/html-element.js +1 -1
- package/canvas/image-element.d.ts +1 -0
- package/canvas/image-element.js +1 -1
- package/canvas/line-element.js +1 -1
- package/canvas/page.js +1 -1
- package/canvas/render-tag-element.js +1 -1
- package/canvas/rich-editor.d.ts +2 -0
- package/canvas/rich-editor.js +8 -5
- package/canvas/text-element.js +1 -1
- package/canvas/use-animated-blur.d.ts +4 -0
- package/canvas/use-animated-blur.js +1 -0
- package/canvas/use-color.d.ts +1 -1
- package/canvas/use-filtered-source.js +1 -1
- package/canvas/use-offscreen-canvas.d.ts +2 -0
- package/canvas/use-offscreen-canvas.js +1 -0
- package/canvas/use-transformer-snap.js +1 -1
- package/canvas/video-element.js +1 -1
- package/icons/animation-icons.d.ts +30 -7
- package/icons/animation-icons.js +1 -1
- package/icons/registry.d.ts +22 -0
- package/icons/registry.js +1 -1
- package/image-tools/raster.js +1 -1
- package/model/figure-model.d.ts +10 -9
- package/model/gif-model.d.ts +10 -9
- package/model/group-model.d.ts +78 -68
- package/model/group-model.js +1 -1
- package/model/history.d.ts +3 -0
- package/model/history.js +1 -1
- package/model/image-model.d.ts +10 -9
- package/model/line-model.d.ts +10 -9
- package/model/node-model.d.ts +8 -8
- package/model/page-model.d.ts +228 -204
- package/model/shape-model.d.ts +15 -9
- package/model/shape-model.js +1 -1
- package/model/store.d.ts +31 -17
- package/model/store.js +1 -1
- package/model/svg-model.d.ts +9 -8
- package/model/table-model.d.ts +8 -7
- package/model/text-model.d.ts +9 -8
- package/model/video-model.d.ts +10 -9
- package/package.json +24 -21
- package/pages-timeline/element-track.js +1 -1
- package/pages-timeline/page-preview.js +1 -1
- package/polotno.bundle.js +195 -177
- package/side-panel/animations-panel.js +1 -1
- package/side-panel/select-video.d.ts +18 -16
- package/side-panel/text-panel.js +1 -1
- package/side-panel/text-template.js +1 -1
- package/toolbar/animations-picker.js +1 -1
- package/toolbar/use-copy-style.d.ts +1 -0
- package/toolbar/use-copy-style.js +1 -1
- package/ui.css +1 -1
- package/utils/animations.d.ts +212 -10
- package/utils/animations.js +1 -1
- package/utils/clipboard.d.ts +17 -15
- package/utils/clipboard.js +1 -1
- package/utils/duplicate.js +1 -1
- package/utils/fonts.js +1 -1
- package/utils/from-svg.js +1 -1
- package/utils/image-dpi.js +1 -1
- package/utils/image-edit.js +1 -1
- package/utils/l10n.d.ts +44 -0
- package/utils/l10n.js +1 -1
- package/utils/px.d.ts +1 -0
- package/utils/px.js +1 -1
- package/utils/timeline.d.ts +3 -1
- package/utils/timeline.js +1 -1
- package/utils/validate-key.js +1 -1
package/model/shape-model.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Instance } from 'mobx-state-tree';
|
|
2
|
+
import { type AnimationAttrs, type TextUnitsFrame, type WipeBand } from '../utils/animations.js';
|
|
2
3
|
export type AnimatedAttrs = {
|
|
3
4
|
x: number;
|
|
4
5
|
y: number;
|
|
@@ -6,6 +7,9 @@ export type AnimatedAttrs = {
|
|
|
6
7
|
height: number;
|
|
7
8
|
rotation: number;
|
|
8
9
|
opacity: number;
|
|
10
|
+
textUnits?: TextUnitsFrame;
|
|
11
|
+
wipe?: WipeBand;
|
|
12
|
+
flipScale?: number;
|
|
9
13
|
[key: string]: any;
|
|
10
14
|
};
|
|
11
15
|
export declare const Animation: import("mobx-state-tree").IModelType<{
|
|
@@ -15,6 +19,7 @@ export declare const Animation: import("mobx-state-tree").IModelType<{
|
|
|
15
19
|
type: import("mobx-state-tree").ISimpleType<"exit" | "enter" | "loop">;
|
|
16
20
|
name: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
17
21
|
data: import("mobx-state-tree").IType<{} | null | undefined, {}, {}>;
|
|
22
|
+
easing: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
|
|
18
23
|
}, {}, import("mobx-state-tree")._NotCustomized, import("mobx-state-tree")._NotCustomized>;
|
|
19
24
|
export declare const getDiff: (obj1: Record<string, unknown>, obj2: Record<string, unknown>) => Record<string, number>;
|
|
20
25
|
export declare const ShapeFilter: import("mobx-state-tree").IModelType<{
|
|
@@ -26,7 +31,7 @@ export declare const Shape: import("mobx-state-tree").IModelType<{
|
|
|
26
31
|
type: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
27
32
|
name: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
28
33
|
opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
29
|
-
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "
|
|
34
|
+
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light">, [undefined]>;
|
|
30
35
|
custom: import("mobx-state-tree").IType<any, any, any>;
|
|
31
36
|
visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
32
37
|
selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
@@ -47,6 +52,7 @@ export declare const Shape: import("mobx-state-tree").IModelType<{
|
|
|
47
52
|
type: import("mobx-state-tree").ISimpleType<"exit" | "enter" | "loop">;
|
|
48
53
|
name: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
49
54
|
data: import("mobx-state-tree").IType<{} | null | undefined, {}, {}>;
|
|
55
|
+
easing: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
|
|
50
56
|
}, {}, import("mobx-state-tree")._NotCustomized, import("mobx-state-tree")._NotCustomized>>;
|
|
51
57
|
blurEnabled: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
52
58
|
blurRadius: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
@@ -79,7 +85,7 @@ export declare const Shape: import("mobx-state-tree").IModelType<{
|
|
|
79
85
|
type: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
80
86
|
name: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
81
87
|
opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
82
|
-
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "
|
|
88
|
+
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light">, [undefined]>;
|
|
83
89
|
custom: import("mobx-state-tree").IType<any, any, any>;
|
|
84
90
|
visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
85
91
|
selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
@@ -91,7 +97,7 @@ export declare const Shape: import("mobx-state-tree").IModelType<{
|
|
|
91
97
|
type: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
92
98
|
name: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
93
99
|
opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
94
|
-
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "
|
|
100
|
+
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light">, [undefined]>;
|
|
95
101
|
custom: import("mobx-state-tree").IType<any, any, any>;
|
|
96
102
|
visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
97
103
|
selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
@@ -103,7 +109,7 @@ export declare const Shape: import("mobx-state-tree").IModelType<{
|
|
|
103
109
|
type: string | undefined;
|
|
104
110
|
name: string | undefined;
|
|
105
111
|
opacity: number | undefined;
|
|
106
|
-
blendMode: "normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "
|
|
112
|
+
blendMode: "normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light" | undefined;
|
|
107
113
|
custom: any;
|
|
108
114
|
visible: boolean | undefined;
|
|
109
115
|
selectable: boolean | undefined;
|
|
@@ -122,7 +128,7 @@ export declare const Shape: import("mobx-state-tree").IModelType<{
|
|
|
122
128
|
alwaysOnTop: boolean;
|
|
123
129
|
showInExport: boolean;
|
|
124
130
|
} | {
|
|
125
|
-
blendMode: "normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "
|
|
131
|
+
blendMode: "normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light";
|
|
126
132
|
id: string;
|
|
127
133
|
type: string;
|
|
128
134
|
name: string;
|
|
@@ -150,7 +156,7 @@ export declare const Shape: import("mobx-state-tree").IModelType<{
|
|
|
150
156
|
alwaysOnTop: boolean;
|
|
151
157
|
showInExport: boolean;
|
|
152
158
|
} | {
|
|
153
|
-
blendMode: "normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "
|
|
159
|
+
blendMode: "normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light";
|
|
154
160
|
id: string;
|
|
155
161
|
type: string;
|
|
156
162
|
name: string;
|
|
@@ -185,14 +191,14 @@ export declare const Shape: import("mobx-state-tree").IModelType<{
|
|
|
185
191
|
readonly isSelected: boolean;
|
|
186
192
|
readonly isSelectedDirectly: boolean;
|
|
187
193
|
} & {
|
|
188
|
-
setAnimation(type:
|
|
194
|
+
setAnimation(type: "enter" | "exit" | "loop", attrs: AnimationAttrs): void;
|
|
189
195
|
setFilter(type: any, value: any): void;
|
|
190
196
|
}, import("mobx-state-tree").ModelCreationType<{
|
|
191
197
|
id: string;
|
|
192
198
|
type: string | undefined;
|
|
193
199
|
name: string | undefined;
|
|
194
200
|
opacity: number | undefined;
|
|
195
|
-
blendMode: "normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "
|
|
201
|
+
blendMode: "normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light" | undefined;
|
|
196
202
|
custom: any;
|
|
197
203
|
visible: boolean | undefined;
|
|
198
204
|
selectable: boolean | undefined;
|
|
@@ -211,7 +217,7 @@ export declare const Shape: import("mobx-state-tree").IModelType<{
|
|
|
211
217
|
alwaysOnTop: boolean;
|
|
212
218
|
showInExport: boolean;
|
|
213
219
|
} | {
|
|
214
|
-
blendMode: "normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "
|
|
220
|
+
blendMode: "normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light";
|
|
215
221
|
id: string;
|
|
216
222
|
type: string;
|
|
217
223
|
name: string;
|
package/model/shape-model.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{types as
|
|
1
|
+
import{types as t,isAlive as e}from"mobx-state-tree";import{animate as i,isBuiltIn as n,loopWindow as o,playedAnimations as a,setAnimationOf as r}from"../utils/animations.js";import{computed as s}from"mobx";import{transitionWindows as l}from"@polotno/core/animation-presets";import{Node as d}from"./node-model.js";import{getElementTimeRange as c,getPlayheadLocalTime as h}from"../utils/timeline.js";import{degToRad as m,getCenter as p}from"../utils/math.js";export const Animation=t.model("Animation",{delay:0,duration:500,enabled:!0,type:t.enumeration("Type",["enter","exit","loop"]),name:"none",data:t.frozen({}),easing:t.maybe(t.string)});export const getDiff=(t,e)=>{const i={};for(const n in e){if("number"==typeof t[n]&&"number"==typeof e[n]){const o=e[n]-t[n];0!==o&&(i[n]=o)}}return i};const f=["x","y","width","height","rotation"];export const ShapeFilter=t.model("ShapeFilter",{intensity:1});export const INDEPENDENT_FILTERS=["temperature","contrast","highlights","shadows","white","black","saturation","vibrance"];export const Shape=d.named("Shape").props({x:0,y:0,width:100,height:100,rotation:0,opacity:1,animations:t.array(Animation),blurEnabled:!1,blurRadius:10,brightnessEnabled:!1,brightness:0,sepiaEnabled:!1,grayscaleEnabled:!1,filters:t.map(ShapeFilter),shadowEnabled:!1,shadowBlur:5,shadowOffsetX:0,shadowOffsetY:0,shadowColor:"black",shadowOpacity:1,visible:!0,draggable:!0,resizable:!0,selectable:!0,contentEditable:!0,styleEditable:!0,alwaysOnTop:!1,showInExport:!0}).preProcessSnapshot(t=>{const e=Object.assign(Object.assign({},t),{x:"x"in t&&t.x||0,y:"y"in t&&t.y||0,filters:"filters"in t?Array.isArray(t.filters)?{}:t.filters:void 0});return"width"in t&&(e.width=e.width||1),"height"in t&&(e.height=e.height||1),"locked"in t&&t.locked&&(e.draggable=!1,e.contentEditable=!1,e.styleEditable=!1,e.resizable=!1,e.removable=!1),e}).views(t=>{var r,d,u,g,b,y;const x=["x","y","width","height","rotation","opacity","color","fontSize","cropX","cropY","cropWidth","cropHeight","blurEnabled","blurRadius","shadowEnabled","shadowBlur","shadowOffsetX","shadowOffsetY","shadowColor","shadowOpacity","text"],w=t,E={x:null!==(r=w.x)&&void 0!==r?r:0,y:null!==(d=w.y)&&void 0!==d?d:0,width:null!==(u=w.width)&&void 0!==u?u:0,height:null!==(g=w.height)&&void 0!==g?g:0,rotation:null!==(b=w.rotation)&&void 0!==b?b:0,opacity:null!==(y=w.opacity)&&void 0!==y?y:1};for(const e of x){e in t&&(E[e]=w[e])}E.wipe=E.flipScale=E.textUnits=void 0;const v=(t,e)=>{const i=getDiff(w,e);for(const n in i){const e=t[n];"number"==typeof e&&(t[n]=e+i[n])}for(const n in e){n in t&&"number"!=typeof t[n]&&void 0!==e[n]&&(t[n]=e[n])}},S=t=>{var e;const i={};for(const n of f){const o=t[n];i[n]="number"==typeof o?o:null!==(e=w[n])&&void 0!==e?e:0}return i},O=t=>f.some(e=>"number"==typeof t[e]&&t[e]!==w[e]),T=s(()=>{if(!e(t)){return E}const r=Object.assign({},E);for(const t in r){r[t]=w[t]}const s=h(t);if(null===s){return r}const d=t.store.isEditingPaused&&t.isSelected,c=t.store.animatedElementsIds;if(c.length&&!c.includes(t.id)){return r}const f=a(t),u=f.find(t=>"enter"===t.type),g=(null==u?void 0:u.enabled)&&s<u.delay;g&&(r.opacity=0);const b=l(f,t.page.duration),y=b.enter&&s>=b.enter.start&&s<=b.enter.end;if(y&&!d){const e=(s-b.enter.start)/b.pace;v(r,i({element:t,animation:u,dTime:e}))}const x=f.find(t=>"exit"===t.type);if(!g&&!y&&b.exit&&s>=b.exit.start&&s<=b.exit.end&&!d){const e=(s-b.exit.start)/b.pace;v(r,i({element:t,animation:x,dTime:e}))}(null==x?void 0:x.enabled)&&s>=t.page.duration-x.delay&&(r.opacity=0);const T=f.find(t=>"loop"===t.type),j=(null==T?void 0:T.enabled)&&o(t,T,f);if(j&&s>=j.start&&!d){const e=s-j.start,o=i({element:t,animation:j.animation,dTime:e});r.textUnits&&delete o.textUnits;const a=n(j.animation.name)&&O(r)&&O(o)?S(r):null;v(r,o),a&&Object.assign(r,((t,e,i)=>{const n=t.width?i.width*e.width/t.width:i.width,o=t.height?i.height*e.height/t.height:i.height,a=i.rotation+e.rotation-t.rotation,r=p(i),s=p(e),l=p(t),d=r.x+s.x-l.x,c=r.y+s.y-l.y,h=m(a);return{width:n,height:o,rotation:a,x:d-n/2*Math.cos(h)+o/2*Math.sin(h),y:c-o/2*Math.cos(h)-n/2*Math.sin(h)}})(S(w),S(o),a))}return r.opacity=Math.min(1,Math.max(0,r.opacity)),r}),j={};for(const e in E){const t=s(()=>T.get()[e]);Object.defineProperty(j,e,{enumerable:!0,get:()=>t.get()})}return{get locked(){return!(t.draggable||t.contentEditable||t.styleEditable||t.resizable)},get a(){return j},animated(t){return this.a[t]},get timeRange(){return e(t)&&t.page?c(t.animations,t.page.duration):{start:0,end:0}},get active(){if(!e(t)){return!0}const i=h(t);if(null===i){return!0}const{start:n,end:o}=this.timeRange;return i>=n&&i<o},get isSelected(){return!!e(t)&&t.store.selectedShapes.indexOf(t)>=0&&t.selectable},get isSelectedDirectly(){return!!e(t)&&t.store.selectedElements.indexOf(t)>=0&&t.selectable}}}).actions(t=>({setAnimation(e,i){r(t.animations,e,i)},setFilter(e,i){INDEPENDENT_FILTERS.includes(e)||t.filters.forEach((e,i)=>{INDEPENDENT_FILTERS.includes(i.toString())||t.filters.delete(i.toString())}),null==i?t.filters.delete(e):t.filters.set(e,{intensity:i})}}));
|
package/model/store.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Instance, SnapshotIn } from 'mobx-state-tree';
|
|
|
2
2
|
import * as fonts from '../utils/fonts.js';
|
|
3
3
|
import { createExportCanvases } from '../utils/canvas.js';
|
|
4
4
|
import { UnitType } from '../utils/unit.js';
|
|
5
|
+
import type { PreviewedAnimation } from '../utils/animations.js';
|
|
5
6
|
import { Page, PageType } from './page-model.js';
|
|
6
7
|
import { ElementsArray, ElementType } from './group-model.js';
|
|
7
8
|
import { NodeType } from './node-model.js';
|
|
@@ -193,6 +194,8 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
193
194
|
readonly canUndo: boolean;
|
|
194
195
|
readonly canRedo: boolean;
|
|
195
196
|
} & {
|
|
197
|
+
_onChange(listener: () => void): import("mobx-state-tree").IDisposer;
|
|
198
|
+
_applyDocument(apply: () => void): void;
|
|
196
199
|
startTransaction(): void;
|
|
197
200
|
endTransaction(skipSave?: boolean): void;
|
|
198
201
|
ignore(func: any, skipStateReplacement?: boolean, delayed?: boolean): Promise<void>;
|
|
@@ -222,6 +225,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
222
225
|
}, {
|
|
223
226
|
highlightedElementId: string | null;
|
|
224
227
|
_workspaces: number;
|
|
228
|
+
_animationPreview: Record<string, PreviewedAnimation[]> | null;
|
|
225
229
|
} & {
|
|
226
230
|
setTool: import("./image-tools.js").SetTool;
|
|
227
231
|
_setImageEditPanelAvailable(value: boolean): void;
|
|
@@ -246,7 +250,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
246
250
|
type: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
247
251
|
name: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
248
252
|
opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
249
|
-
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "
|
|
253
|
+
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light">, [undefined]>;
|
|
250
254
|
custom: import("mobx-state-tree").IType<any, any, any>;
|
|
251
255
|
visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
252
256
|
selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
@@ -267,6 +271,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
267
271
|
type: import("mobx-state-tree").ISimpleType<"exit" | "enter" | "loop">;
|
|
268
272
|
name: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
269
273
|
data: import("mobx-state-tree").IType<{} | null | undefined, {}, {}>;
|
|
274
|
+
easing: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
|
|
270
275
|
}, {}, import("mobx-state-tree")._NotCustomized, import("mobx-state-tree")._NotCustomized>>;
|
|
271
276
|
blurEnabled: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
272
277
|
blurRadius: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
@@ -299,7 +304,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
299
304
|
type: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
300
305
|
name: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
301
306
|
opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
302
|
-
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "
|
|
307
|
+
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light">, [undefined]>;
|
|
303
308
|
custom: import("mobx-state-tree").IType<any, any, any>;
|
|
304
309
|
visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
305
310
|
selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
@@ -311,7 +316,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
311
316
|
type: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
312
317
|
name: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
313
318
|
opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
314
|
-
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "
|
|
319
|
+
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light">, [undefined]>;
|
|
315
320
|
custom: import("mobx-state-tree").IType<any, any, any>;
|
|
316
321
|
visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
317
322
|
selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
@@ -323,7 +328,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
323
328
|
type: string | undefined;
|
|
324
329
|
name: string | undefined;
|
|
325
330
|
opacity: number | undefined;
|
|
326
|
-
blendMode: "normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "
|
|
331
|
+
blendMode: "normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light" | undefined;
|
|
327
332
|
custom: any;
|
|
328
333
|
visible: boolean | undefined;
|
|
329
334
|
selectable: boolean | undefined;
|
|
@@ -342,7 +347,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
342
347
|
alwaysOnTop: boolean;
|
|
343
348
|
showInExport: boolean;
|
|
344
349
|
} | {
|
|
345
|
-
blendMode: "normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "
|
|
350
|
+
blendMode: "normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light";
|
|
346
351
|
id: string;
|
|
347
352
|
type: string;
|
|
348
353
|
name: string;
|
|
@@ -370,7 +375,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
370
375
|
alwaysOnTop: boolean;
|
|
371
376
|
showInExport: boolean;
|
|
372
377
|
} | {
|
|
373
|
-
blendMode: "normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "
|
|
378
|
+
blendMode: "normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light";
|
|
374
379
|
id: string;
|
|
375
380
|
type: string;
|
|
376
381
|
name: string;
|
|
@@ -405,14 +410,14 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
405
410
|
readonly isSelected: boolean;
|
|
406
411
|
readonly isSelectedDirectly: boolean;
|
|
407
412
|
} & {
|
|
408
|
-
setAnimation(type:
|
|
413
|
+
setAnimation(type: "enter" | "exit" | "loop", attrs: import("../utils/animations.js").AnimationAttrs): void;
|
|
409
414
|
setFilter(type: any, value: any): void;
|
|
410
415
|
} & import("mobx-state-tree").IStateTreeNode<import("mobx-state-tree").IModelType<{
|
|
411
416
|
id: import("mobx-state-tree").ISimpleType<string>;
|
|
412
417
|
type: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
413
418
|
name: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
414
419
|
opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
415
|
-
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "
|
|
420
|
+
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light">, [undefined]>;
|
|
416
421
|
custom: import("mobx-state-tree").IType<any, any, any>;
|
|
417
422
|
visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
418
423
|
selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
@@ -433,6 +438,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
433
438
|
type: import("mobx-state-tree").ISimpleType<"exit" | "enter" | "loop">;
|
|
434
439
|
name: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
435
440
|
data: import("mobx-state-tree").IType<{} | null | undefined, {}, {}>;
|
|
441
|
+
easing: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
|
|
436
442
|
}, {}, import("mobx-state-tree")._NotCustomized, import("mobx-state-tree")._NotCustomized>>;
|
|
437
443
|
blurEnabled: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
438
444
|
blurRadius: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
@@ -465,7 +471,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
465
471
|
type: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
466
472
|
name: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
467
473
|
opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
468
|
-
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "
|
|
474
|
+
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light">, [undefined]>;
|
|
469
475
|
custom: import("mobx-state-tree").IType<any, any, any>;
|
|
470
476
|
visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
471
477
|
selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
@@ -477,7 +483,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
477
483
|
type: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
478
484
|
name: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
479
485
|
opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
480
|
-
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "
|
|
486
|
+
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light">, [undefined]>;
|
|
481
487
|
custom: import("mobx-state-tree").IType<any, any, any>;
|
|
482
488
|
visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
483
489
|
selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
@@ -489,7 +495,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
489
495
|
type: string | undefined;
|
|
490
496
|
name: string | undefined;
|
|
491
497
|
opacity: number | undefined;
|
|
492
|
-
blendMode: "normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "
|
|
498
|
+
blendMode: "normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light" | undefined;
|
|
493
499
|
custom: any;
|
|
494
500
|
visible: boolean | undefined;
|
|
495
501
|
selectable: boolean | undefined;
|
|
@@ -508,7 +514,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
508
514
|
alwaysOnTop: boolean;
|
|
509
515
|
showInExport: boolean;
|
|
510
516
|
} | {
|
|
511
|
-
blendMode: "normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "
|
|
517
|
+
blendMode: "normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light";
|
|
512
518
|
id: string;
|
|
513
519
|
type: string;
|
|
514
520
|
name: string;
|
|
@@ -536,7 +542,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
536
542
|
alwaysOnTop: boolean;
|
|
537
543
|
showInExport: boolean;
|
|
538
544
|
} | {
|
|
539
|
-
blendMode: "normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "
|
|
545
|
+
blendMode: "normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light";
|
|
540
546
|
id: string;
|
|
541
547
|
type: string;
|
|
542
548
|
name: string;
|
|
@@ -571,14 +577,14 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
571
577
|
readonly isSelected: boolean;
|
|
572
578
|
readonly isSelectedDirectly: boolean;
|
|
573
579
|
} & {
|
|
574
|
-
setAnimation(type:
|
|
580
|
+
setAnimation(type: "enter" | "exit" | "loop", attrs: import("../utils/animations.js").AnimationAttrs): void;
|
|
575
581
|
setFilter(type: any, value: any): void;
|
|
576
582
|
}, import("mobx-state-tree").ModelCreationType<{
|
|
577
583
|
id: string;
|
|
578
584
|
type: string | undefined;
|
|
579
585
|
name: string | undefined;
|
|
580
586
|
opacity: number | undefined;
|
|
581
|
-
blendMode: "normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "
|
|
587
|
+
blendMode: "normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light" | undefined;
|
|
582
588
|
custom: any;
|
|
583
589
|
visible: boolean | undefined;
|
|
584
590
|
selectable: boolean | undefined;
|
|
@@ -597,7 +603,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
597
603
|
alwaysOnTop: boolean;
|
|
598
604
|
showInExport: boolean;
|
|
599
605
|
} | {
|
|
600
|
-
blendMode: "normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "
|
|
606
|
+
blendMode: "normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light";
|
|
601
607
|
id: string;
|
|
602
608
|
type: string;
|
|
603
609
|
name: string;
|
|
@@ -630,6 +636,13 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
630
636
|
endTime?: number | undefined;
|
|
631
637
|
repeat?: boolean | undefined;
|
|
632
638
|
}): void;
|
|
639
|
+
_previewAnimation({ preview, animatedElementsIds, startTime, endTime, }: {
|
|
640
|
+
preview?: Record<string, PreviewedAnimation[]> | null;
|
|
641
|
+
animatedElementsIds: string[];
|
|
642
|
+
startTime: number;
|
|
643
|
+
endTime: number;
|
|
644
|
+
}): void;
|
|
645
|
+
_endAnimationPreview(): void;
|
|
633
646
|
checkActivePage(): void;
|
|
634
647
|
seek(): void;
|
|
635
648
|
pause(): void;
|
|
@@ -669,7 +682,8 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
669
682
|
deleteElements(ids: Array<string>): void;
|
|
670
683
|
on(event: any, callback: any): import("mobx-state-tree").IDisposer | undefined;
|
|
671
684
|
_toCanvas({ pixelRatio, ignoreBackground, pageId, mimeType, includeBleed, quickMode, _exportCanvases, }?: ExportOptions): Promise<HTMLCanvasElement>;
|
|
672
|
-
|
|
685
|
+
_toDataURL({ mimeType, quality, dpi, dpiMetadata, ...rest }?: ImageExportOptions): Promise<string>;
|
|
686
|
+
toDataURL(exportProps?: ImageExportOptions): Promise<string>;
|
|
673
687
|
toBlob({ mimeType, quality, ...rest }?: ExportOptions): Promise<Blob>;
|
|
674
688
|
saveAsImage({ fileName, ...exportProps }?: ImageExportOptions & {
|
|
675
689
|
fileName?: string;
|
package/model/store.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=this&&this.__rest||function(e,t){var o={};for(var i in e){Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(o[i]=e[i])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(i=Object.getOwnPropertySymbols(e);n<i.length;n++){t.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(e,i[n])&&(o[i[n]]=e[i[n]])}}return o};import{applySnapshot as t,cast as o,destroy as i,detach as n,getSnapshot as a,isAlive as s,onSnapshot as r,setLivelinessChecking as l,types as d}from"mobx-state-tree";import{UndoManager as p}from"./history.js";import{nanoid as c}from"nanoid";import g from"konva";import{computed as m,when as u}from"mobx";import{ZERO_BLEED as f,migrateDesign as h,CURRENT_SCHEMA_VERSION as v}from"@polotno/schema";import{downloadFile as y}from"../utils/download.js";import{localFileToURL as b}from"../utils/file.js";import{getJsPDF as P}from"../utils/pdf.js";import{createGIF as w}from"../utils/gif-lib.js";import{validateKey as x,setKey as E}from"../utils/validate-key.js";import*as I from"../utils/fonts.js";import{flags as T}from"../utils/flags.js";import{addDpiMetadataToImage as _}from"../utils/image-dpi.js";import{nodeToCanvas as S,createExportCanvases as O,releaseExportCanvases as k}from"../utils/canvas.js";import{whenLoaded as j,getAssetLoadTimeout as F}from"../utils/loader.js";import{polotnoError as R}from"@polotno/core/errors";import{pxToUnit as A}from"../utils/unit.js";import{deepEqual as V}from"../utils/deep-equal.js";import{jsonToHTML as C}from"@polotno/html-export";import{jsonToSVG as L}from"@polotno/svg-export";import{warnOnceDeprecated as M}from"../utils/deprecation.js";import{Page as B}from"./page-model.js";import{forEveryChild as D,forEveryNode as H}from"./group-model.js";import{Audio as W}from"./audio-model.js";import{imageTools as N}from"./image-tools.js";import{IMAGE_TOOLS as G}from"../image-tools/sessions.js";function U(e){return!!e&&!!e.type&&"tablecell"!==e.type}function q(e){const t=new Map;for(const o of e){const e=o.parent;if(!e||t.has(o)){continue}let i=0;for(const o of e.children){t.set(o,i++)}}e.sort((e,o)=>{var i,n;return(null!==(i=t.get(e))&&void 0!==i?i:0)-(null!==(n=t.get(o))&&void 0!==n?n:0)})}l("ignore");export const Font=d.model("Font",{fontFamily:d.string,url:d.optional(d.string,""),styles:d.frozen()}).preProcessSnapshot(e=>Object.assign(Object.assign({},e),{fontFamily:e.fontFamily||e.name}));const X=d.model("BrushOptions",{strokeWidth:d.optional(d.number,5),stroke:d.optional(d.string,"#000000"),opacity:d.optional(d.number,1)});export const ROLES={ADMIN:"admin",VIEWER:"viewer"};export const Store=d.model("Store",{role:"",pages:d.array(B),fonts:d.array(Font),audios:d.array(W),width:1080,height:1080,currentTime:0,isPlaying:!1,scale:1,scaleToFit:1,unit:d.optional(d.enumeration("UnitType",["pt","mm","cm","in","px"]),"px"),dpi:72,schemaVersion:v,bleedVisible:!1,rulesVisible:!1,distanceGuidesVisible:!1,timingPreview:d.optional(d.enumeration("TimingPreview",["all","playhead"]),"all"),openedSidePanel:"",previousOpenedSidePanel:"",custom:d.frozen(),tool:d.optional(d.enumeration("Tool",["selection","draw","pan","text","eraser","crop","expand","inpaint","upscale","remove-background"]),"selection"),toolOptions:d.optional(d.model({brushType:d.optional(d.enumeration("BrushType",["brush","highlighter"]),"brush"),brush:d.optional(X,{}),highlighter:d.optional(X,{strokeWidth:30,opacity:.5})}).views(e=>({get active(){return e[e.brushType]}})).views(e=>({get strokeWidth(){return e.active.strokeWidth},get stroke(){return e.active.stroke},get opacity(){return e.active.opacity}})),{}),selectedElementsIds:d.array(d.string),animatedElementsIds:d.array(d.string),history:d.optional(p,{targetPath:"../pages"}),_elementsPixelRatio:Math.min(2,"undefined"!=typeof window&&window.devicePixelRatio||1),_activePageId:"",_selectedPagesIds:d.array(d.string),_forceShowCredit:!1,_validated:!1}).volatile(()=>({highlightedElementId:null,_workspaces:0})).extend(N).views(e=>{const t=m(()=>{const t={};return H({children:e.pages},e=>(t[e.id]=e,!1)),t},{keepAlive:!0});return{get _idsMap(){return t.get()}}}).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=>e._idsMap[t]).filter(U)},get children(){return e.pages},get selectedShapes(){const e=[];return D({children:this.selectedElements},t=>{"group"!==t.type&&e.push(t)}),e},get activePage(){return e.pages.slice().find(t=>t.id===e._activePageId)||(e.pages.length?e.pages[0]:null)},get selectedPages(){return e._selectedPagesIds.map(t=>e.pages.find(e=>e.id===t))},get duration(){let t=0;return e.pages.forEach(e=>{t+=e.duration}),t},pageAtTime(t){for(const o of e.pages){if(t>=o.startTime&&t<o.startTime+o.duration){return o}}return e.pages.length&&t>=this.duration?e.pages[e.pages.length-1]:null},get effectiveTime(){if(e.isPlaying){return e.currentTime}const t=this.activePage;return t&&this.pageAtTime(e.currentTime)!==t?t.startTime:e.currentTime},get playheadAccurate(){return e.isPlaying||"playhead"===e.timingPreview},get isEditingPaused(){var t;return!e.isPlaying&&!(null===(t=this.activePage)||void 0===t?void 0:t._exportingOrRendering)},get _hasCroppedImages(){const t=e.activeTool;return"crop"===(null==t?void 0:t.name)?this.getElementById(t.elementId):void 0},find(t){let o;return H({children:e.pages},e=>{if(!o&&t(e)){return o=e,!0}}),o},getElementById:t=>e._idsMap[t]})).actions(l=>{let d=0,p=null,m=!1;const v={afterCreate(){l.history.canUndo},setCurrentTime(e){l.currentTime=e},_togglePlaying(e=!l.isPlaying){l.isPlaying=e},play({animatedElementsIds:e=[],startTime:t=0,currentTime:i=0,endTime:n=l.duration,repeat:a=!1}={}){i&&(console.warn("currentTime property of store.play() is deprecated. Please use startTime instead."),t=i),l.animatedElementsIds=o(e),l.currentTime=t,l.isPlaying=!0,d=Date.now(),p=n,m=a,requestAnimationFrame(()=>v.seek())},checkActivePage(){const e=l.pageAtTime(l.currentTime);e&&v.selectPage(e.id)},seek(){if(!l.isPlaying){return}const e=Date.now(),t=e-d;d=e,l.currentTime+=t;const o=p||l.duration;l.currentTime>=o&&!m&&(l.currentTime=o),v.checkActivePage(),l.isPlaying&&l.currentTime<o?requestAnimationFrame(()=>v.seek()):l.isPlaying&&m?(l.currentTime=0,requestAnimationFrame(()=>v.seek())):v.pause()},pause(){l.isPlaying=!1,l.animatedElementsIds=o([])},stop(){v.pause(),l.currentTime=0,v.checkActivePage()},__(){l._validated||(x(l._forceShowCredit),l._validated=!0)},set(e){Object.assign(l,e)},setUnit({unit:e,dpi:t}){l.unit=e||l.unit,l.dpi=t||l.dpi},setRole(e){l.role=e},setToolOptions(t){const{brushType:o}=t,i=e(t,["brushType"]);o&&(l.toolOptions.brushType=o),Object.assign(l.toolOptions.active,i)},addPage(e){const t=B.create(Object.assign({id:c(10)},e));return l.pages.push(t),l._activePageId=t.id,l._selectedPagesIds=o([]),t},selectPage(e){l._activePageId=e,1===l._selectedPagesIds.length&&(l._selectedPagesIds=o([e]))},selectPages(e){l._selectedPagesIds=o(e),1===l._selectedPagesIds.length&&(l._activePageId=l._selectedPagesIds[0])},selectElements(e){l._beforeToolSelection(e);const t=e.map(e=>l.getElementById(e)).filter(U);q(t),l.selectedElementsIds=o(t.map(e=>e.id))},highlightElement(e){l.highlightedElementId=e},toggleBleed(e){l.bleedVisible=null!=e?e:!l.bleedVisible},toggleRulers(e){l.rulesVisible=null!=e?e:!l.rulesVisible},setTimingPreview(e){l.timingPreview=e},toggleDistanceGuides(e){l.distanceGuidesVisible=null!=e?e:!l.distanceGuidesVisible},openSidePanel(e){l.openedSidePanel!==e&&("image-edit"!==e&&l._beforeToolPanel(),l.previousOpenedSidePanel=l.openedSidePanel,l.openedSidePanel=e)},restoreSidePanel(){l._beforeToolPanel();const e=l.previousOpenedSidePanel;e&&e!==l.openedSidePanel?l.openedSidePanel=e:l.openedSidePanel="photos"},setScale(e){l.scale=e},_setScaleToFit(e){l.scaleToFit=e},setElementsPixelRatio(e){l._elementsPixelRatio=e},setSize(e,t,o){l.pages.forEach(i=>{i.setSize({width:e,height:t,useMagic:o,softChange:!0})}),l.width=e,l.height=t},setPageZIndex(e,t){const o=l.pages.find(t=>t.id===e);o&&(n(o),l.pages.remove(o),l.pages.splice(t,0,o))},deletePages(e){const t=l.pages.indexOf(l.activePage);e.forEach(e=>{const t=l.pages.find(t=>t.id===e);i(t)});const n=l._selectedPagesIds.filter(e=>l.pages.some(t=>t.id===e)),a=Math.min(l.pages.length-1,t),s=l.pages[a];s&&(l._activePageId=s.id),v.selectPages(n),l.selectedElementsIds=o(l.selectedElementsIds.filter(e=>l.getElementById(e)))},groupElements(e,t={}){const i=e.map(e=>l.getElementById(e)).filter(e=>!!e);if(!i.length){return}const a=i[0].parent;if(!a){return}if(!i.every(e=>e.parent===a)){return void console.warn("store.groupElements: refusing to group elements that do not share a parent. Pass ids whose elements all live under the same page or the same group.")}q(i);const s=a.children.indexOf(i[i.length-1])-i.length+1;i.forEach(e=>n(e));const r=a.children.reduce((e,t)=>{var o;if("group"===t.type){const i=null===(o=t.name)||void 0===o?void 0:o.match(/group-(\d+)/);if(i){const t=parseInt(i[1],10);return Math.max(e,t)}}return e},0),d=Object.assign({id:c(10),name:`group-${r+1}`,children:i,type:"group"},t);return a.children.splice(s,0,d),l.selectedElementsIds=o([d.id]),a.children.find(e=>e.id===d.id)},ungroupElements(e){const t=e.map(e=>l.getElementById(e)),i=[];t.forEach(e=>{if(e&&"group"===e.type){const t=e.parent;if(!t){return}const o=t.children.indexOf(e);e.children.forEach(e=>{i.push(e.id)});const a=e.children.slice();a.forEach(t=>{t.set({opacity:t.opacity*e.opacity}),n(t)}),t.children.splice(o,1,...a)}}),l.selectedElementsIds=o(i)},deleteElements(e){const t=[];l.find(o=>(e.includes(o.id)&&t.push(o),!1)),t.forEach(e=>{i(e)}),l.selectedElementsIds=o(l.selectedElementsIds.filter(e=>l.getElementById(e)))},on(e,t){if("change"===e){let e=v.toJSON();return r(l,o=>{const i=v.toJSON();!V(e,i)&&(e=i,t(i))})}},async _toCanvas({pixelRatio:e,ignoreBackground:t,pageId:o,mimeType:i,includeBleed:n,quickMode:a=!1,_exportCanvases:r}={}){var d;const p=e||1;o=o||(null===(d=l.pages[0])||void 0===d?void 0:d.id);const c=l.pages.find(e=>e.id===o);if(!c){throw R("EXPORT_FAILED",`No page for export with id ${o}`,{reason:"page-not-found",pageId:o,availablePageIds:l.pages.map(e=>e.id)})}const m=l._elementsPixelRatio;try{(a?p>l._elementsPixelRatio:p!==l._elementsPixelRatio)&&v.setElementsPixelRatio(p),c.set(a?{_forceMount:!0}:{_exporting:!0}),await u(()=>c._exportRendered||0===l._workspaces||!l.pages.includes(c),{timeout:F()}).catch(()=>{}),await j();const e=g.stages.filter(e=>e.getAttr("pageId")===o);if(!c._exportRendered||0===e.length){throw R("EXPORT_FAILED",`Export is failed. Can not find stage for page ${o}. Looks like <Workspace /> component is not mounted, but it is required in order to process the export.`,{reason:"workspace-not-mounted",pageId:o})}e.length>1&&console.error(`Polotno error: Detected several canvas elements for page "${o}" in the document. This is not supported and will lead to incorrect export. Make sure to use unique ids for all pages and make sure you unmount <Workspace /> when it is not needed.`);const s=e[0],d=s.findOne(".page-container");if(!d){throw R("EXPORT_FAILED","Export is failed. Canvas was unmounted.",{reason:"unmounted-during-export",pageId:o})}const m=s.position();s.position({x:0,y:0}),s.find("Transformer").forEach(e=>{e.setAttr("oldVisible",e.visible()),e.visible(!1)}),d.find(".page-background").forEach(e=>e.shadowEnabled(!1)),d.find(".page-background").forEach(e=>e.strokeEnabled(!1)),d.find(".highlighter").forEach(e=>e.visible(!1));const h=d.findOne(".page-background-group"),y=h.clip();h.clip({x:null,y:null,width:null,height:null});const b=d.findOne(".elements-container"),P=b.clip();b.clip({x:null,y:null,width:null,height:null});const w=d.find(e=>!e.visible()&&e.getAttr("editModeEnabled")&&!e.getAttr("hideInExport"));w.forEach(e=>{e.setAttr("oldVisible",e.visible()),e.show()});const x=d.find(e=>e.getAttr("hideInExport"));x.forEach(e=>{e.setAttr("oldVisible",e.visible()),e.hide()}),t&&d.find(".page-background").forEach(e=>e.hide());const E=n?c.computedBleed:f;let I=E.left,_=E.top;!l.bleedVisible&&n||(l.bleedVisible||n?l.bleedVisible&&n?(I=0,_=0):l.bleedVisible&&!n&&(I=-c.computedBleed.left,_=-c.computedBleed.top):(I=0,_=0));const O=c.computedWidth+E.left+E.right,k=c.computedHeight+E.top+E.bottom,A=d.scale();d.scale({x:1,y:1});const V=S(d,{x:d.x()-I,y:d.y()-_,width:O,height:k,pixelRatio:p,imageSmoothingQuality:T.imageDownScalingEnabled&&!a?"high":void 0,sceneCanvas:null==r?void 0:r.sceneCanvas});d.scale(A);const C=V._canvas;if("image/jpeg"===i){const e=C.getContext("2d");e.save(),e.globalCompositeOperation="destination-over",e.fillStyle="white",e.fillRect(0,0,C.width,C.height),e.restore()}return t&&d.find(".page-background").forEach(e=>e.show()),x.forEach(e=>{e.visible(e.getAttr("oldVisible"))}),w.forEach(e=>{e.visible(e.getAttr("oldVisible"))}),d.find(".page-background").forEach(e=>e.shadowEnabled(!0)),d.find(".page-background").forEach(e=>e.strokeEnabled(!0)),s.find("Transformer").forEach(e=>{e.visible(e.getAttr("oldVisible"))}),d.find(".highlighter").forEach(e=>e.visible(!0)),h.clip(y),b.clip(P),s.position(m),null==c||c.set({_exporting:!1,_forceMount:!1}),await Promise.resolve(),C}finally{v.setElementsPixelRatio(m),s(c)&&c.set({_forceMount:!1,_exporting:!1})}},async toDataURL(t={}){var{mimeType:o,quality:i,dpi:n,dpiMetadata:a="auto"}=t,s=e(t,["mimeType","quality","dpi","dpiMetadata"]);const r=await v._toCanvas(Object.assign({mimeType:o},s)),d=o||"image/png",p=r.toDataURL(d,i);g.Util.releaseCanvas(r);const c=null!=n?n:l.dpi;return"image/png"!==d&&"image/jpeg"!==d||"never"===a||"auto"===a&&72===c?p:_(p,d,c)},async toBlob(t={}){var{mimeType:o,quality:i}=t,n=e(t,["mimeType","quality"]);const a=await v._toCanvas(Object.assign({mimeType:o},n)),s=await new Promise(e=>{a.toBlob(e,o,i)});return g.Util.releaseCanvas(a),s},async saveAsImage(t={}){var{fileName:o}=t,i=e(t,["fileName"]);const n=(i.mimeType||"image/png").split("/")[1];y(await v.toDataURL(i),o||"polotno."+n)},async _toPDF(e){const t=e.dpi||l.dpi,o=e.parallel||1,i=e.unit||("px"===l.unit?"mm":l.unit),n=e.pixelRatio||1,a=e.pageIds||(e.pageId?[e.pageId]:l.pages.map(e=>e.id)),s=l.pages.filter(e=>a.includes(e.id)),r=await P(),d=e=>A({px:e,unit:i,dpi:t}),p=e.cropMarkSize||0,c=d(p),g=s[0]||{},m=e.includeBleed&&g.computedBleed||f,u=d(g.computedWidth+m.left+m.right+2*c),h=d(g.computedHeight+m.top+m.bottom+2*c);var y=new r({unit:i,orientation:u>h?"landscape":"portrait",format:[u,h],compress:!0,putOnlyUsedFonts:!0});y.deletePage(1);const b=((e,t)=>{const o=[];for(let i=0;i<e.length;i+=t){o.push(e.slice(i,i+t))}return o})(s,o);let w=0;for(const l of b){const t=l.map(async t=>{const o=e.includeBleed?t.computedBleed:f,i=t.computedWidth+o.left+o.right+2*p,s=t.computedHeight+o.top+o.bottom+2*p,r=d(i),l=d(s);let c=0,g=n;for(;c<10;){c+=1;const d=await v.toDataURL(Object.assign(Object.assign({},e),{pageId:t.id,pixelRatio:g,dpiMetadata:"never"}));if(d.length>20){return g!==n&&console.error(`Polotno can not export PDF with current settings. Quality is automatically reduced. pixelRatio was reduced to ${parseFloat(g.toFixed(3))}.`),e.onProgress&&e.onProgress(++w/a.length*.9),{url:d,width:r,height:l,widthPx:i,heightPx:s,cb:o}}g*=.8}});(await Promise.all(t)).filter(e=>void 0!==e).forEach(({url:e,width:t,height:o,widthPx:n,heightPx:a,cb:s})=>{y.addPage([t,o],t>o?"landscape":"portrait");const r=y.getCurrentPageInfo();var l;switch(i){case"pt":l=1;break;case"mm":l=72/25.4;break;case"cm":l=72/2.54;break;case"in":l=72;break;case"px":l=.75;break;default:throw R("EXPORT_FAILED","Invalid unit: "+i,{reason:"invalid-options",option:"unit",value:i})}if(r.pageContext.cropBox={bottomLeftX:0,bottomLeftY:0,topRightX:t*l,topRightY:o*l},r.pageContext.artBox={bottomLeftX:d(p+s.left)*l,bottomLeftY:d(p+s.bottom)*l,topRightX:d(n-p-s.right)*l,topRightY:d(a-p-s.top)*l},r.pageContext.bleedBox={bottomLeftX:d(p+s.left)*l,bottomLeftY:d(p+s.bottom)*l,topRightX:d(n-p-s.right)*l,topRightY:d(a-p-s.top)*l},c){y.setLineWidth(d(1));const e=c+d(s.left),i=c+d(s.right),n=c+d(s.top),a=c+d(s.bottom);y.line(e,0,e,c),y.line(0,n,c,n),y.line(t-i,0,t-i,c),y.line(t,n,t-c,n),y.line(0,o-a,c,o-a),y.line(e,o,e,o-c),y.line(t,o-a,t-c,o-a),y.line(t-i,o,t-i,o-c)}y.addImage(e,c,c,t-2*c,o-2*c,void 0,"FAST")})}return y},toPDFDataURL:async e=>(await v._toPDF(Object.assign({mimeType:"image/jpeg"},e))).output("datauristring"),async toGIFDataURL(e={}){var t,o;const i=e.pixelRatio||1,n=e.pageIds||(e.pageId?[e.pageId]:l.pages.map(e=>e.id)),a=l.pages.filter(e=>n.includes(e.id));if(!a.length){throw R("EXPORT_FAILED","No pages found for GIF export",{reason:"page-not-found",pageId:e.pageId,availablePageIds:l.pages.map(e=>e.id)})}null===(t=e.onProgress)||void 0===t||t.call(e,0,"rendering");const s=a[0],r=await w({width:s.computedWidth*i,height:s.computedHeight*i}),d=1e3/(e.fps||10),p=a.map(e=>({page:e,frames:Math.max(1,Math.floor(e.duration/d))})),c=p.reduce((e,{frames:t})=>e+t,0);let g=0;const m=O(),u=l._elementsPixelRatio;v.setElementsPixelRatio(i);try{for(const{page:t,frames:n}of p){for(let a=0;a<n;a++){const n=t.startTime+a*d||1;v.setCurrentTime(n);for(const e of l.pages){e.set({_rendering:e.id===t.id})}const s=await v._toCanvas({pixelRatio:i,pageId:t.id,_exportCanvases:m});r.addFrame(s.getContext("2d"),{delay:d,copy:!0}),g++,null===(o=e.onProgress)||void 0===o||o.call(e,g/c/2,"rendering")}}}finally{k(m),v.setElementsPixelRatio(u);for(const e of l.pages){e.set({_rendering:!1})}v.stop()}return new Promise((t,o)=>{let i=!1;e.onProgress&&r.on("progress",t=>{var n;if(!i){try{null===(n=e.onProgress)||void 0===n||n.call(e,.5+t/2,"encoding")}catch(a){i=!0,o(a)}}}),r.on("finished",e=>{i||b(e).then(t,o)}),r.render()})},async saveAsGIF(t={}){var{fileName:o}=t,i=e(t,["fileName"]);const n=await v.toGIFDataURL(i);y(n,o||"polotno.gif")},async toHTML({elementHook:e}={}){M("store.toHTML","store.toHTML()/saveAsHTML() are deprecated: install @polotno/html-export and call jsonToHTML(store.toJSON()) instead");const t=v.toJSON();return C(t,{elementHook:e,textOverflow:T.textOverflow,textSplitAllowed:T.textSplitAllowed})},async saveAsHTML({fileName:e,elementHook:t}={}){const o=await v.toHTML({elementHook:t}),i="data:text/html;base64,"+window.btoa(unescape(encodeURIComponent(o)));y(i,e||"polotno.html")},async toSVG({elementHook:e,pageId:t,fontEmbedding:o="inline"}={fontEmbedding:"inline"}){var i;M("store.toSVG","store.toSVG()/saveAsSVG() are deprecated: install @polotno/svg-export and call jsonToSVG(store.toJSON()) instead");const n=v.toJSON();t=t||(null===(i=n.pages[0])||void 0===i?void 0:i.id);const a=n.pages.find(e=>e.id===t);return L(Object.assign(Object.assign({},n),{pages:a?[a]:[]}),Object.assign({elementHook:e,fontEmbedding:o,textSplitAllowed:T.textSplitAllowed},"fit"===T.textOverflow&&{textOverflow:"fit"}))},async saveAsSVG({fileName:e,elementHook:t,pageId:o,fontEmbedding:i="inline"}={}){const n=await v.toSVG({elementHook:t,pageId:o,fontEmbedding:i}),a="data:text/svg;base64,"+window.btoa(unescape(encodeURIComponent(n)));y(a,e||"polotno.svg")},async saveAsPDF(t={}){var{fileName:o}=t,i=e(t,["fileName"]);(await v._toPDF(Object.assign({mimeType:"image/jpeg"},i))).save(o||"polotno.pdf")},_setWorkspaceMounted(e){l._workspaces+=e?1:-1},async waitLoading(){await j()},toJSON:()=>({width:l.width,height:l.height,fonts:a(l.fonts),pages:a(l.pages),audios:a(l.audios),unit:l.unit,dpi:l.dpi,custom:l.custom,schemaVersion:l.schemaVersion}),loadJSON(e,o=!1){var i,n;const s="boolean"==typeof o?o:null!==(i=null==o?void 0:o.keepHistory)&&void 0!==i&&i,r="boolean"==typeof o||null==o?void 0:o.modernizeTextBackground,d=h(e,{modernTextRenderer:T.htmlRenderEnabled||T.renderTagTextEnabled,modernizeTextBackground:r});delete d.schemaVersion,d.tool in G&&delete d.tool;const p=l.activePage?l.pages.indexOf(l.activePage):0;let c=null===(n=d.pages[p]||d.pages[0])||void 0===n?void 0:n.id;d._activePageId=c,d._selectedPagesIds=[],l._closeImageTool("discard"),D(l,e=>{var t;"pendingEdit"in e&&(null===(t=e.pendingEdit)||void 0===t||t.cancel())});const g=Object.assign({},a(l));Object.assign(g,d),g.history=s?a(l.history):{history:[],undoIdx:-1,targetPath:""},t(l,g)},clear({keepHistory:e=!1}={}){const t=l.pages.map(e=>e.id);v.deletePages(t),l.custom=null,e||l.history.clear()},addFont(e){l.fonts.filter(t=>t.fontFamily===e.fontFamily).forEach(e=>i(e)),l.fonts.push(e),I.injectCustomFont(e)},removeFont(e){l.fonts.filter(t=>t.fontFamily===e).forEach(e=>i(e)),I.removeCustomFont(e)},addAudio(e){const t=W.create(Object.assign({id:c(10)},e));l.audios.push(t)},removeAudio(e){const t=l.audios.find(t=>t.id===e);t&&l.audios.remove(t)},async loadFont(e,t,o,i){var n,a;const s=l.fonts.find(t=>t.fontFamily===e)||I.globalFonts.find(t=>t.fontFamily===e);if(s?I.injectCustomFont(s):I.injectGoogleFont(e),T.renderTagTextEnabled){return I.loadFont(e,null!=t?t:"normal",null!=o?o:"normal",i)}const r=null!==(a=null===(n=null==s?void 0:s.styles)||void 0===n?void 0:n.map(e=>({fontStyle:e.fontStyle||"normal",fontWeight:e.fontWeight||"normal"})))&&void 0!==a?a:[{fontStyle:"normal",fontWeight:"normal"},{fontStyle:"normal",fontWeight:"bold"}];return t&&o&&!r.some(e=>e.fontStyle===t&&e.fontWeight===o)&&r.push({fontStyle:t,fontWeight:o}),Promise.all(r.map(n=>(n.fontStyle===(null!=t?t:"normal")&&n.fontWeight===(null!=o?o:"normal")?I.loadFont:I.loadFontFace)(e,n.fontStyle,n.fontWeight,i)))},validate:e=>Store.validate(e,[{path:"",type:Store}]).map(e=>({path:"store"+e.context.map(e=>e.path).join("."),message:e.message}))};return v});export function createStore({key:e,showCredit:t}={key:"",showCredit:!1}){return E(e),Store.create({_forceShowCredit:t})}export default createStore;
|
|
1
|
+
var e=this&&this.__rest||function(e,t){var o={};for(var i in e){Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(o[i]=e[i])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(i=Object.getOwnPropertySymbols(e);n<i.length;n++){t.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(e,i[n])&&(o[i[n]]=e[i[n]])}}return o};import{applySnapshot as t,cast as o,destroy as i,detach as n,getSnapshot as a,isAlive as s,onSnapshot as r,setLivelinessChecking as l,types as d}from"mobx-state-tree";import{UndoManager as p}from"./history.js";import{nanoid as c}from"nanoid";import g from"konva";import{computed as m,when as u}from"mobx";import{ZERO_BLEED as f,migrateDesign as h,CURRENT_SCHEMA_VERSION as v}from"@polotno/schema";import{downloadFile as y}from"../utils/download.js";import{localFileToURL as b}from"../utils/file.js";import{getJsPDF as P}from"../utils/pdf.js";import{createGIF as w}from"../utils/gif-lib.js";import{validateKey as x,setKey as E}from"../utils/validate-key.js";import*as T from"../utils/fonts.js";import{flags as I}from"../utils/flags.js";import{addDpiMetadataToImage as _}from"../utils/image-dpi.js";import{nodeToCanvas as O,createExportCanvases as S,releaseExportCanvases as k}from"../utils/canvas.js";import{whenLoaded as R,getAssetLoadTimeout as j}from"../utils/loader.js";import{polotnoError as F}from"@polotno/core/errors";import{pxToUnit as A}from"../utils/unit.js";import{deepEqual as V}from"../utils/deep-equal.js";import{jsonToHTML as C}from"@polotno/html-export";import{jsonToSVG as L}from"@polotno/svg-export";import{warnOnceDeprecated as M}from"../utils/deprecation.js";import{Page as D}from"./page-model.js";import{forEveryChild as B,forEveryNode as H}from"./group-model.js";import{Audio as W}from"./audio-model.js";import{imageTools as N}from"./image-tools.js";import{IMAGE_TOOLS as U}from"../image-tools/sessions.js";function G(e){return!!e&&!!e.type&&"tablecell"!==e.type}function X(e){const t=new Map;for(const o of e){const e=o.parent;if(!e||t.has(o)){continue}let i=0;for(const o of e.children){t.set(o,i++)}}e.sort((e,o)=>{var i,n;return(null!==(i=t.get(e))&&void 0!==i?i:0)-(null!==(n=t.get(o))&&void 0!==n?n:0)})}l("ignore");export const Font=d.model("Font",{fontFamily:d.string,url:d.optional(d.string,""),styles:d.frozen()}).preProcessSnapshot(e=>Object.assign(Object.assign({},e),{fontFamily:e.fontFamily||e.name}));const q=d.model("BrushOptions",{strokeWidth:d.optional(d.number,5),stroke:d.optional(d.string,"#000000"),opacity:d.optional(d.number,1)}),J="data:,";export const ROLES={ADMIN:"admin",VIEWER:"viewer"};export const Store=d.model("Store",{role:"",pages:d.array(D),fonts:d.array(Font),audios:d.array(W),width:1080,height:1080,currentTime:0,isPlaying:!1,scale:1,scaleToFit:1,unit:d.optional(d.enumeration("UnitType",["pt","mm","cm","in","px"]),"px"),dpi:72,schemaVersion:v,bleedVisible:!1,rulesVisible:!1,distanceGuidesVisible:!1,timingPreview:d.optional(d.enumeration("TimingPreview",["all","playhead"]),"all"),openedSidePanel:"",previousOpenedSidePanel:"",custom:d.frozen(),tool:d.optional(d.enumeration("Tool",["selection","draw","pan","text","eraser","crop","expand","inpaint","upscale","remove-background"]),"selection"),toolOptions:d.optional(d.model({brushType:d.optional(d.enumeration("BrushType",["brush","highlighter"]),"brush"),brush:d.optional(q,{}),highlighter:d.optional(q,{strokeWidth:30,opacity:.5})}).views(e=>({get active(){return e[e.brushType]}})).views(e=>({get strokeWidth(){return e.active.strokeWidth},get stroke(){return e.active.stroke},get opacity(){return e.active.opacity}})),{}),selectedElementsIds:d.array(d.string),animatedElementsIds:d.array(d.string),history:d.optional(p,{targetPath:"../pages"}),_elementsPixelRatio:Math.min(2,"undefined"!=typeof window&&window.devicePixelRatio||1),_activePageId:"",_selectedPagesIds:d.array(d.string),_forceShowCredit:!1,_validated:!1}).volatile(()=>({highlightedElementId:null,_workspaces:0,_animationPreview:null})).extend(N).views(e=>{const t=m(()=>{const t={};return H({children:e.pages},e=>(t[e.id]=e,!1)),t},{keepAlive:!0});return{get _idsMap(){return t.get()}}}).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=>e._idsMap[t]).filter(G)},get children(){return e.pages},get selectedShapes(){const e=[];return B({children:this.selectedElements},t=>{"group"!==t.type&&e.push(t)}),e},get activePage(){return e.pages.slice().find(t=>t.id===e._activePageId)||(e.pages.length?e.pages[0]:null)},get selectedPages(){return e._selectedPagesIds.map(t=>e.pages.find(e=>e.id===t))},get duration(){let t=0;return e.pages.forEach(e=>{t+=e.duration}),t},pageAtTime(t){for(const o of e.pages){if(t>=o.startTime&&t<o.startTime+o.duration){return o}}return e.pages.length&&t>=this.duration?e.pages[e.pages.length-1]:null},get effectiveTime(){if(e.isPlaying){return e.currentTime}const t=this.activePage;return t&&this.pageAtTime(e.currentTime)!==t?t.startTime:e.currentTime},get playheadAccurate(){return e.isPlaying||"playhead"===e.timingPreview},get isEditingPaused(){var t;return!e.isPlaying&&!(null===(t=this.activePage)||void 0===t?void 0:t._exportingOrRendering)},get _hasCroppedImages(){const t=e.activeTool;return"crop"===(null==t?void 0:t.name)?this.getElementById(t.elementId):void 0},find(t){let o;return H({children:e.pages},e=>{if(!o&&t(e)){return o=e,!0}}),o},getElementById:t=>e._idsMap[t]})).actions(l=>{let d=0,p=null,m=!1,v=null;const E=()=>{v&&z(),v=null,l._animationPreview=null},H=()=>{v&&(v.pageId=void 0,$._endAnimationPreview())},N=e=>{l._activePageId=e,1===l._selectedPagesIds.length&&(l._selectedPagesIds=o([e]))},q=(e,t,i,n)=>{l.animatedElementsIds=o(e),l.currentTime=t,l.isPlaying=!0,d=Date.now(),p=i,m=n,requestAnimationFrame(()=>$.seek())},z=()=>{l.isPlaying=!1,l.animatedElementsIds=o([])},Y=({pageId:e,mimeType:t="image/png",pixelRatio:o=1})=>{var i;return F("EXPORT_FAILED",`The browser could not encode the page as ${t}. The canvas is probably too large; try a lower pixelRatio.`,{reason:"empty-output",pageId:e||(null===(i=l.pages[0])||void 0===i?void 0:i.id),mimeType:t,pixelRatio:o})},$={afterCreate(){l.history.canUndo},setCurrentTime(e){E(),l.currentTime=e},_togglePlaying(e=!l.isPlaying){l.isPlaying=e},play({animatedElementsIds:e=[],startTime:t=0,currentTime:o=0,endTime:i=l.duration,repeat:n=!1}={}){o&&(console.warn("currentTime property of store.play() is deprecated. Please use startTime instead."),t=o),E(),q(e,t,i,n)},_previewAnimation({preview:e=null,animatedElementsIds:t,startTime:o,endTime:i}){var n;l.isPlaying&&!v||(null!=v||(v={pageId:null===(n=l.activePage)||void 0===n?void 0:n.id,time:l.currentTime}),l._animationPreview=e,q(t,o,i,!1))},_endAnimationPreview(){if(!v){return}const{pageId:e,time:t}=v;E(),l.currentTime=t;const o=l.pages.find(t=>t.id===e);o&&N(o.id)},checkActivePage(){const e=l.pageAtTime(l.currentTime);e&&N(e.id)},seek(){if(!l.isPlaying){return}const e=Date.now(),t=e-d;d=e,l.currentTime+=t;const o=p||l.duration;l.currentTime>=o&&!m&&(l.currentTime=o),$.checkActivePage(),l.isPlaying&&l.currentTime<o?requestAnimationFrame(()=>$.seek()):l.isPlaying&&m?(l.currentTime=0,requestAnimationFrame(()=>$.seek())):v?$._endAnimationPreview():$.pause()},pause(){E(),z()},stop(){$.pause(),l.currentTime=0,$.checkActivePage()},__(){l._validated||(x(l._forceShowCredit),l._validated=!0)},set(e){Object.assign(l,e)},setUnit({unit:e,dpi:t}){l.unit=e||l.unit,l.dpi=t||l.dpi},setRole(e){l.role=e},setToolOptions(t){const{brushType:o}=t,i=e(t,["brushType"]);o&&(l.toolOptions.brushType=o),Object.assign(l.toolOptions.active,i)},addPage(e){const t=D.create(Object.assign({id:c(10)},e));return l.pages.push(t),H(),l._activePageId=t.id,l._selectedPagesIds=o([]),t},selectPage(e){H(),N(e)},selectPages(e){l._selectedPagesIds=o(e),1===l._selectedPagesIds.length&&(H(),l._activePageId=l._selectedPagesIds[0])},selectElements(e){l._beforeToolSelection(e);const t=e.map(e=>l.getElementById(e)).filter(G);X(t),l.selectedElementsIds=o(t.map(e=>e.id))},highlightElement(e){l.highlightedElementId=e},toggleBleed(e){l.bleedVisible=null!=e?e:!l.bleedVisible},toggleRulers(e){l.rulesVisible=null!=e?e:!l.rulesVisible},setTimingPreview(e){l.timingPreview=e},toggleDistanceGuides(e){l.distanceGuidesVisible=null!=e?e:!l.distanceGuidesVisible},openSidePanel(e){l.openedSidePanel!==e&&("image-edit"!==e&&l._beforeToolPanel(),l.previousOpenedSidePanel=l.openedSidePanel,l.openedSidePanel=e)},restoreSidePanel(){l._beforeToolPanel();const e=l.previousOpenedSidePanel;e&&e!==l.openedSidePanel?l.openedSidePanel=e:l.openedSidePanel="photos"},setScale(e){l.scale=e},_setScaleToFit(e){l.scaleToFit=e},setElementsPixelRatio(e){l._elementsPixelRatio=e},setSize(e,t,o){l.pages.forEach(i=>{i.setSize({width:e,height:t,useMagic:o,softChange:!0})}),l.width=e,l.height=t},setPageZIndex(e,t){const o=l.pages.find(t=>t.id===e);o&&(n(o),l.pages.remove(o),l.pages.splice(t,0,o))},deletePages(e){const t=l.pages.indexOf(l.activePage);e.forEach(e=>{const t=l.pages.find(t=>t.id===e);i(t)});const n=l._selectedPagesIds.filter(e=>l.pages.some(t=>t.id===e)),a=Math.min(l.pages.length-1,t),s=l.pages[a];s&&(l._activePageId=s.id),$.selectPages(n),l.selectedElementsIds=o(l.selectedElementsIds.filter(e=>l.getElementById(e)))},groupElements(e,t={}){const i=e.map(e=>l.getElementById(e)).filter(e=>!!e);if(!i.length){return}const a=i[0].parent;if(!a){return}if(!i.every(e=>e.parent===a)){return void console.warn("store.groupElements: refusing to group elements that do not share a parent. Pass ids whose elements all live under the same page or the same group.")}X(i);const s=a.children.indexOf(i[i.length-1])-i.length+1;i.forEach(e=>n(e));const r=a.children.reduce((e,t)=>{var o;if("group"===t.type){const i=null===(o=t.name)||void 0===o?void 0:o.match(/group-(\d+)/);if(i){const t=parseInt(i[1],10);return Math.max(e,t)}}return e},0),d=Object.assign({id:c(10),name:`group-${r+1}`,children:i,type:"group"},t);return a.children.splice(s,0,d),l.selectedElementsIds=o([d.id]),a.children.find(e=>e.id===d.id)},ungroupElements(e){const t=e.map(e=>l.getElementById(e)),i=[];t.forEach(e=>{if(e&&"group"===e.type){const t=e.parent;if(!t){return}const o=t.children.indexOf(e);e.children.forEach(e=>{i.push(e.id)});const a=e.children.slice();a.forEach(t=>{t.set({opacity:t.opacity*e.opacity}),n(t)}),t.children.splice(o,1,...a)}}),l.selectedElementsIds=o(i)},deleteElements(e){const t=[];l.find(o=>(e.includes(o.id)&&t.push(o),!1)),t.forEach(e=>{i(e)}),l.selectedElementsIds=o(l.selectedElementsIds.filter(e=>l.getElementById(e)))},on(e,t){if("change"===e){let e=$.toJSON();return r(l,o=>{const i=$.toJSON();!V(e,i)&&(e=i,t(i))})}},async _toCanvas({pixelRatio:e,ignoreBackground:t,pageId:o,mimeType:i,includeBleed:n,quickMode:a=!1,_exportCanvases:r}={}){var d;const p=e||1;o=o||(null===(d=l.pages[0])||void 0===d?void 0:d.id);const c=l.pages.find(e=>e.id===o);if(!c){throw F("EXPORT_FAILED",`No page for export with id ${o}`,{reason:"page-not-found",pageId:o,availablePageIds:l.pages.map(e=>e.id)})}const m=l._elementsPixelRatio;try{(a?p>l._elementsPixelRatio:p!==l._elementsPixelRatio)&&$.setElementsPixelRatio(p),c.set(a?{_forceMount:!0}:{_exporting:!0}),await u(()=>c._exportRendered||0===l._workspaces||!l.pages.includes(c),{timeout:j()}).catch(()=>{}),await R();const e=g.stages.filter(e=>e.getAttr("pageId")===o);if(!c._exportRendered||0===e.length){throw F("EXPORT_FAILED",`Export is failed. Can not find stage for page ${o}. Looks like <Workspace /> component is not mounted, but it is required in order to process the export.`,{reason:"workspace-not-mounted",pageId:o})}e.length>1&&console.error(`Polotno error: Detected several canvas elements for page "${o}" in the document. This is not supported and will lead to incorrect export. Make sure to use unique ids for all pages and make sure you unmount <Workspace /> when it is not needed.`);const s=e[0],d=s.findOne(".page-container");if(!d){throw F("EXPORT_FAILED","Export is failed. Canvas was unmounted.",{reason:"unmounted-during-export",pageId:o})}const m=s.position();s.position({x:0,y:0}),s.find("Transformer").forEach(e=>{e.setAttr("oldVisible",e.visible()),e.visible(!1)}),d.find(".page-background").forEach(e=>e.shadowEnabled(!1)),d.find(".page-background").forEach(e=>e.strokeEnabled(!1)),d.find(".highlighter").forEach(e=>e.visible(!1));const h=d.findOne(".page-background-group"),v=h.clip();h.clip({x:null,y:null,width:null,height:null});const y=d.findOne(".elements-container"),b=y.clip();y.clip({x:null,y:null,width:null,height:null});const P=d.find(e=>!e.visible()&&e.getAttr("editModeEnabled")&&!e.getAttr("hideInExport"));P.forEach(e=>{e.setAttr("oldVisible",e.visible()),e.show()});const w=d.find(e=>e.getAttr("hideInExport"));w.forEach(e=>{e.setAttr("oldVisible",e.visible()),e.hide()}),t&&d.find(".page-background").forEach(e=>e.hide());const x=n?c.computedBleed:f;let E=x.left,T=x.top;!l.bleedVisible&&n||(l.bleedVisible||n?l.bleedVisible&&n?(E=0,T=0):l.bleedVisible&&!n&&(E=-c.computedBleed.left,T=-c.computedBleed.top):(E=0,T=0));const _=c.computedWidth+x.left+x.right,S=c.computedHeight+x.top+x.bottom,k=d.scale();d.scale({x:1,y:1});const A=O(d,{x:d.x()-E,y:d.y()-T,width:_,height:S,pixelRatio:p,imageSmoothingQuality:I.imageDownScalingEnabled&&!a?"high":void 0,sceneCanvas:null==r?void 0:r.sceneCanvas});d.scale(k);const V=A._canvas;if("image/jpeg"===i){const e=V.getContext("2d");e.save(),e.globalCompositeOperation="destination-over",e.fillStyle="white",e.fillRect(0,0,V.width,V.height),e.restore()}return t&&d.find(".page-background").forEach(e=>e.show()),w.forEach(e=>{e.visible(e.getAttr("oldVisible"))}),P.forEach(e=>{e.visible(e.getAttr("oldVisible"))}),d.find(".page-background").forEach(e=>e.shadowEnabled(!0)),d.find(".page-background").forEach(e=>e.strokeEnabled(!0)),s.find("Transformer").forEach(e=>{e.visible(e.getAttr("oldVisible"))}),d.find(".highlighter").forEach(e=>e.visible(!0)),h.clip(v),y.clip(b),s.position(m),null==c||c.set({_exporting:!1,_forceMount:!1}),await Promise.resolve(),V}finally{$.setElementsPixelRatio(m),s(c)&&c.set({_forceMount:!1,_exporting:!1})}},async _toDataURL(t={}){var{mimeType:o,quality:i,dpi:n,dpiMetadata:a="auto"}=t,s=e(t,["mimeType","quality","dpi","dpiMetadata"]);const r=await $._toCanvas(Object.assign({mimeType:o},s)),d=o||"image/png",p=r.toDataURL(d,i);g.Util.releaseCanvas(r);const c=null!=n?n:l.dpi;return"image/png"!==d&&"image/jpeg"!==d||"never"===a||"auto"===a&&72===c?p:_(p,d,c)},async toDataURL(e={}){const t=await $._toDataURL(e);if(t===J){throw Y(e)}return t},async toBlob(t={}){var{mimeType:o,quality:i}=t,n=e(t,["mimeType","quality"]);const a=await $._toCanvas(Object.assign({mimeType:o},n)),s=await new Promise(e=>{a.toBlob(e,o,i)});if(g.Util.releaseCanvas(a),!s){throw Y(Object.assign({mimeType:o},n))}return s},async saveAsImage(t={}){var{fileName:o}=t,i=e(t,["fileName"]);const n=(i.mimeType||"image/png").split("/")[1];y(await $.toDataURL(i),o||"polotno."+n)},async _toPDF(e){const t=e.dpi||l.dpi,o=e.parallel||1,i=e.unit||("px"===l.unit?"mm":l.unit),n=e.pixelRatio||1,a=e.pageIds||(e.pageId?[e.pageId]:l.pages.map(e=>e.id)),s=l.pages.filter(e=>a.includes(e.id)),r=await P(),d=e=>A({px:e,unit:i,dpi:t}),p=e.cropMarkSize||0,c=d(p),g=s[0]||{},m=e.includeBleed&&g.computedBleed||f,u=d(g.computedWidth+m.left+m.right+2*c),h=d(g.computedHeight+m.top+m.bottom+2*c);var v=new r({unit:i,orientation:u>h?"landscape":"portrait",format:[u,h],compress:!0,putOnlyUsedFonts:!0});v.deletePage(1);const y=((e,t)=>{const o=[];for(let i=0;i<e.length;i+=t){o.push(e.slice(i,i+t))}return o})(s,o);let b=0;for(const l of y){const t=l.map(async t=>{const o=e.includeBleed?t.computedBleed:f,i=t.computedWidth+o.left+o.right+2*p,s=t.computedHeight+o.top+o.bottom+2*p,r=d(i),l=d(s);let c=0,g=n;for(;c<10;){c+=1;const d=await $._toDataURL(Object.assign(Object.assign({},e),{pageId:t.id,pixelRatio:g,dpiMetadata:"never"}));if(d!==J){return g!==n&&console.error(`Polotno can not export PDF with current settings. Quality is automatically reduced. pixelRatio was reduced to ${parseFloat(g.toFixed(3))}.`),e.onProgress&&e.onProgress(++b/a.length*.9),{url:d,width:r,height:l,widthPx:i,heightPx:s,cb:o}}g*=.8}});(await Promise.all(t)).filter(e=>void 0!==e).forEach(({url:e,width:t,height:o,widthPx:n,heightPx:a,cb:s})=>{v.addPage([t,o],t>o?"landscape":"portrait");const r=v.getCurrentPageInfo();var l;switch(i){case"pt":l=1;break;case"mm":l=72/25.4;break;case"cm":l=72/2.54;break;case"in":l=72;break;case"px":l=.75;break;default:throw F("EXPORT_FAILED","Invalid unit: "+i,{reason:"invalid-options",option:"unit",value:i})}if(r.pageContext.cropBox={bottomLeftX:0,bottomLeftY:0,topRightX:t*l,topRightY:o*l},r.pageContext.artBox={bottomLeftX:d(p+s.left)*l,bottomLeftY:d(p+s.bottom)*l,topRightX:d(n-p-s.right)*l,topRightY:d(a-p-s.top)*l},r.pageContext.bleedBox={bottomLeftX:d(p+s.left)*l,bottomLeftY:d(p+s.bottom)*l,topRightX:d(n-p-s.right)*l,topRightY:d(a-p-s.top)*l},c){v.setLineWidth(d(1));const e=c+d(s.left),i=c+d(s.right),n=c+d(s.top),a=c+d(s.bottom);v.line(e,0,e,c),v.line(0,n,c,n),v.line(t-i,0,t-i,c),v.line(t,n,t-c,n),v.line(0,o-a,c,o-a),v.line(e,o,e,o-c),v.line(t,o-a,t-c,o-a),v.line(t-i,o,t-i,o-c)}v.addImage(e,c,c,t-2*c,o-2*c,void 0,"FAST")})}return v},toPDFDataURL:async e=>(await $._toPDF(Object.assign({mimeType:"image/jpeg"},e))).output("datauristring"),async toGIFDataURL(e={}){var t,o;const i=e.pixelRatio||1,n=e.pageIds||(e.pageId?[e.pageId]:l.pages.map(e=>e.id)),a=l.pages.filter(e=>n.includes(e.id));if(!a.length){throw F("EXPORT_FAILED","No pages found for GIF export",{reason:"page-not-found",pageId:e.pageId,availablePageIds:l.pages.map(e=>e.id)})}null===(t=e.onProgress)||void 0===t||t.call(e,0,"rendering");const s=a[0],r=await w({width:s.computedWidth*i,height:s.computedHeight*i}),d=1e3/(e.fps||10),p=a.map(e=>({page:e,frames:Math.max(1,Math.floor(e.duration/d))})),c=p.reduce((e,{frames:t})=>e+t,0);let g=0;const m=S(),u=l._elementsPixelRatio;$.setElementsPixelRatio(i);const f=l.timingPreview;$.setTimingPreview("playhead");try{for(const{page:t,frames:n}of p){for(let a=0;a<n;a++){const n=t.startTime+a*d||1;$.setCurrentTime(n);for(const e of l.pages){e.set({_rendering:e.id===t.id})}const s=await $._toCanvas({pixelRatio:i,pageId:t.id,_exportCanvases:m});r.addFrame(s.getContext("2d"),{delay:d,copy:!0}),g++,null===(o=e.onProgress)||void 0===o||o.call(e,g/c/2,"rendering")}}}finally{k(m),$.setElementsPixelRatio(u),$.setTimingPreview(f);for(const e of l.pages){e.set({_rendering:!1})}$.stop()}return new Promise((t,o)=>{let i=!1;e.onProgress&&r.on("progress",t=>{var n;if(!i){try{null===(n=e.onProgress)||void 0===n||n.call(e,.5+t/2,"encoding")}catch(a){i=!0,o(a)}}}),r.on("finished",e=>{i||b(e).then(t,o)}),r.render()})},async saveAsGIF(t={}){var{fileName:o}=t,i=e(t,["fileName"]);const n=await $.toGIFDataURL(i);y(n,o||"polotno.gif")},async toHTML({elementHook:e}={}){M("store.toHTML","store.toHTML()/saveAsHTML() are deprecated: install @polotno/html-export and call jsonToHTML(store.toJSON()) instead");const t=$.toJSON();return C(t,{elementHook:e,textOverflow:I.textOverflow,textSplitAllowed:I.textSplitAllowed})},async saveAsHTML({fileName:e,elementHook:t}={}){const o=await $.toHTML({elementHook:t}),i="data:text/html;base64,"+window.btoa(unescape(encodeURIComponent(o)));y(i,e||"polotno.html")},async toSVG({elementHook:e,pageId:t,fontEmbedding:o="inline"}={fontEmbedding:"inline"}){var i;M("store.toSVG","store.toSVG()/saveAsSVG() are deprecated: install @polotno/svg-export and call jsonToSVG(store.toJSON()) instead");const n=$.toJSON();t=t||(null===(i=n.pages[0])||void 0===i?void 0:i.id);const a=n.pages.find(e=>e.id===t);return L(Object.assign(Object.assign({},n),{pages:a?[a]:[]}),Object.assign({elementHook:e,fontEmbedding:o,textSplitAllowed:I.textSplitAllowed},"fit"===I.textOverflow&&{textOverflow:"fit"}))},async saveAsSVG({fileName:e,elementHook:t,pageId:o,fontEmbedding:i="inline"}={}){const n=await $.toSVG({elementHook:t,pageId:o,fontEmbedding:i}),a="data:text/svg;base64,"+window.btoa(unescape(encodeURIComponent(n)));y(a,e||"polotno.svg")},async saveAsPDF(t={}){var{fileName:o}=t,i=e(t,["fileName"]);(await $._toPDF(Object.assign({mimeType:"image/jpeg"},i))).save(o||"polotno.pdf")},_setWorkspaceMounted(e){l._workspaces+=e?1:-1},async waitLoading(){await R()},toJSON:()=>({width:l.width,height:l.height,fonts:a(l.fonts),pages:a(l.pages),audios:a(l.audios),unit:l.unit,dpi:l.dpi,custom:l.custom,schemaVersion:l.schemaVersion}),loadJSON(e,o=!1){var i,n;const s="boolean"==typeof o?o:null!==(i=null==o?void 0:o.keepHistory)&&void 0!==i&&i,r="boolean"==typeof o||null==o?void 0:o.modernizeTextBackground,d=h(e,{modernTextRenderer:I.htmlRenderEnabled||I.renderTagTextEnabled,modernizeTextBackground:r});delete d.schemaVersion,d.tool in U&&delete d.tool;const p=l.activePage?l.pages.indexOf(l.activePage):0;let c=null===(n=d.pages[p]||d.pages[0])||void 0===n?void 0:n.id;d._activePageId=c,d._selectedPagesIds=[],l._closeImageTool("discard"),B(l,e=>{var t;"pendingEdit"in e&&(null===(t=e.pendingEdit)||void 0===t||t.cancel())});const g=Object.assign({},a(l));Object.assign(g,d),g.history=s?a(l.history):{history:[],undoIdx:-1,targetPath:""},l.history._applyDocument(()=>t(l,g))},clear({keepHistory:e=!1}={}){const t=l.pages.map(e=>e.id);$.deletePages(t),l.custom=null,e||l.history.clear()},addFont(e){l.fonts.filter(t=>t.fontFamily===e.fontFamily).forEach(e=>i(e)),l.fonts.push(e),T.injectCustomFont(e)},removeFont(e){l.fonts.filter(t=>t.fontFamily===e).forEach(e=>i(e)),T.removeCustomFont(e)},addAudio(e){const t=W.create(Object.assign({id:c(10)},e));l.audios.push(t)},removeAudio(e){const t=l.audios.find(t=>t.id===e);t&&l.audios.remove(t)},async loadFont(e,t,o,i){var n,a;const s=l.fonts.find(t=>t.fontFamily===e)||T.globalFonts.find(t=>t.fontFamily===e);if(s?T.injectCustomFont(s):T.injectGoogleFont(e),I.renderTagTextEnabled){return T.loadFont(e,null!=t?t:"normal",null!=o?o:"normal",i)}const r=null!==(a=null===(n=null==s?void 0:s.styles)||void 0===n?void 0:n.map(e=>({fontStyle:e.fontStyle||"normal",fontWeight:e.fontWeight||"normal"})))&&void 0!==a?a:[{fontStyle:"normal",fontWeight:"normal"},{fontStyle:"normal",fontWeight:"bold"}];return t&&o&&!r.some(e=>e.fontStyle===t&&e.fontWeight===o)&&r.push({fontStyle:t,fontWeight:o}),Promise.all(r.map(n=>(n.fontStyle===(null!=t?t:"normal")&&n.fontWeight===(null!=o?o:"normal")?T.loadFont:T.loadFontFace)(e,n.fontStyle,n.fontWeight,i)))},validate:e=>Store.validate(e,[{path:"",type:Store}]).map(e=>({path:"store"+e.context.map(e=>e.path).join("."),message:e.message}))};return $});export function createStore({key:e,showCredit:t}={key:"",showCredit:!1}){return E(e),Store.create({_forceShowCredit:t})}export default createStore;
|
package/model/svg-model.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export declare const SVGElement: import("mobx-state-tree").IModelType<{
|
|
|
4
4
|
type: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
5
5
|
name: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
6
6
|
opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
7
|
-
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "
|
|
7
|
+
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light">, [undefined]>;
|
|
8
8
|
custom: import("mobx-state-tree").IType<any, any, any>;
|
|
9
9
|
visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
10
10
|
selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
@@ -25,6 +25,7 @@ export declare const SVGElement: import("mobx-state-tree").IModelType<{
|
|
|
25
25
|
type: import("mobx-state-tree").ISimpleType<"exit" | "enter" | "loop">;
|
|
26
26
|
name: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
27
27
|
data: import("mobx-state-tree").IType<{} | null | undefined, {}, {}>;
|
|
28
|
+
easing: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
|
|
28
29
|
}, {}, import("mobx-state-tree")._NotCustomized, import("mobx-state-tree")._NotCustomized>>;
|
|
29
30
|
blurEnabled: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
30
31
|
blurRadius: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
@@ -75,7 +76,7 @@ export declare const SVGElement: import("mobx-state-tree").IModelType<{
|
|
|
75
76
|
type: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
76
77
|
name: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
77
78
|
opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
78
|
-
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "
|
|
79
|
+
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light">, [undefined]>;
|
|
79
80
|
custom: import("mobx-state-tree").IType<any, any, any>;
|
|
80
81
|
visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
81
82
|
selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
@@ -87,7 +88,7 @@ export declare const SVGElement: import("mobx-state-tree").IModelType<{
|
|
|
87
88
|
type: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
88
89
|
name: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
89
90
|
opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
90
|
-
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "
|
|
91
|
+
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light">, [undefined]>;
|
|
91
92
|
custom: import("mobx-state-tree").IType<any, any, any>;
|
|
92
93
|
visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
93
94
|
selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
@@ -99,7 +100,7 @@ export declare const SVGElement: import("mobx-state-tree").IModelType<{
|
|
|
99
100
|
type: string | undefined;
|
|
100
101
|
name: string | undefined;
|
|
101
102
|
opacity: number | undefined;
|
|
102
|
-
blendMode: "normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "
|
|
103
|
+
blendMode: "normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light" | undefined;
|
|
103
104
|
custom: any;
|
|
104
105
|
visible: boolean | undefined;
|
|
105
106
|
selectable: boolean | undefined;
|
|
@@ -118,7 +119,7 @@ export declare const SVGElement: import("mobx-state-tree").IModelType<{
|
|
|
118
119
|
alwaysOnTop: boolean;
|
|
119
120
|
showInExport: boolean;
|
|
120
121
|
} | {
|
|
121
|
-
blendMode: "normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "
|
|
122
|
+
blendMode: "normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light";
|
|
122
123
|
id: string;
|
|
123
124
|
type: string;
|
|
124
125
|
name: string;
|
|
@@ -146,7 +147,7 @@ export declare const SVGElement: import("mobx-state-tree").IModelType<{
|
|
|
146
147
|
alwaysOnTop: boolean;
|
|
147
148
|
showInExport: boolean;
|
|
148
149
|
} | {
|
|
149
|
-
blendMode: "normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "
|
|
150
|
+
blendMode: "normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light";
|
|
150
151
|
id: string;
|
|
151
152
|
type: string;
|
|
152
153
|
name: string;
|
|
@@ -181,7 +182,7 @@ export declare const SVGElement: import("mobx-state-tree").IModelType<{
|
|
|
181
182
|
readonly isSelected: boolean;
|
|
182
183
|
readonly isSelectedDirectly: boolean;
|
|
183
184
|
} & {
|
|
184
|
-
setAnimation(type:
|
|
185
|
+
setAnimation(type: "enter" | "exit" | "loop", attrs: import("../utils/animations.js").AnimationAttrs): void;
|
|
185
186
|
setFilter(type: any, value: any): void;
|
|
186
187
|
} & {
|
|
187
188
|
replaceColor(oldColor: any, newColor: any): void;
|
|
@@ -206,7 +207,7 @@ export declare const SVGElement: import("mobx-state-tree").IModelType<{
|
|
|
206
207
|
alwaysOnTop: boolean;
|
|
207
208
|
showInExport: boolean;
|
|
208
209
|
} | {
|
|
209
|
-
blendMode: "normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "
|
|
210
|
+
blendMode: "normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light";
|
|
210
211
|
id: string;
|
|
211
212
|
type: string;
|
|
212
213
|
name: string;
|