polotno 3.15.2 → 3.16.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 +2 -0
- 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.js +1 -1
- package/canvas/page.js +1 -1
- package/canvas/render-tag-element.js +1 -1
- package/canvas/rich-editor.d.ts +3 -1
- package/canvas/rich-editor.js +2 -2
- package/canvas/text-element.js +1 -1
- package/canvas/use-color.d.ts +2 -2
- package/canvas/video-element.js +1 -1
- package/model/figure-model.d.ts +1 -0
- package/model/gif-model.d.ts +1 -0
- package/model/group-model.d.ts +12 -0
- package/model/image-model.d.ts +1 -0
- package/model/line-model.d.ts +1 -0
- package/model/node-model.d.ts +1 -0
- package/model/node-model.js +1 -1
- package/model/page-model.d.ts +36 -0
- package/model/page-model.js +1 -1
- package/model/shape-model.d.ts +1 -0
- package/model/store.d.ts +6 -0
- package/model/store.js +1 -1
- package/model/svg-model.d.ts +1 -0
- package/model/table-model.d.ts +1 -0
- package/model/text-model.d.ts +5 -0
- package/model/text-model.js +1 -1
- package/model/video-model.d.ts +1 -0
- package/package.json +21 -21
- package/polotno.bundle.js +166 -165
- package/primitives/numeric-input-delayed.d.ts +12 -0
- package/primitives/numeric-input-delayed.js +1 -0
- package/primitives/popover.js +1 -1
- package/side-panel/effects-panel.js +1 -1
- package/side-panel/layer-selection.d.ts +26 -0
- package/side-panel/layer-selection.js +1 -0
- package/side-panel/layers-panel.js +1 -1
- package/side-panel/select-video.d.ts +2 -0
- package/side-panel/size-panel.js +1 -1
- package/side-panel/text-effect-presets.d.ts +11 -0
- package/side-panel/text-effect-presets.js +1 -0
- package/toolbar/group-toolbar.js +1 -1
- package/toolbar/image-toolbar.d.ts +3 -2
- package/toolbar/image-toolbar.js +1 -1
- package/toolbar/many-toolbar.js +1 -1
- package/toolbar/opacity-picker.d.ts +3 -2
- package/toolbar/opacity-picker.js +1 -1
- package/toolbar/position-picker.js +1 -1
- package/toolbar/selection-colors.d.ts +18 -0
- package/toolbar/selection-colors.js +1 -0
- package/toolbar/selection-size.d.ts +12 -0
- package/toolbar/selection-size.js +1 -0
- package/toolbar/svg-toolbar.js +1 -1
- package/ui.css +1 -1
- package/utils/alignment.d.ts +16 -0
- package/utils/alignment.js +1 -1
- package/utils/array.d.ts +1 -0
- package/utils/array.js +1 -0
- package/utils/clipboard.d.ts +10 -0
- package/utils/duplicate.d.ts +2 -0
- package/utils/duplicate.js +1 -1
- package/utils/file.d.ts +1 -1
- package/utils/flags.d.ts +1 -1
- package/utils/l10n.d.ts +13 -0
- package/utils/l10n.js +1 -1
- package/utils/measure-text.d.ts +6 -3
- package/utils/measure-text.js +1 -1
- package/utils/px.d.ts +11 -18
- package/utils/px.js +1 -1
- package/utils/rich-text-html.d.ts +5 -0
- package/utils/rich-text-html.js +1 -1
- package/utils/selection-colors.d.ts +15 -0
- package/utils/selection-colors.js +1 -0
- package/utils/selection-transform.d.ts +19 -0
- package/utils/selection-transform.js +1 -0
- package/utils/selection.d.ts +3 -0
- package/utils/selection.js +1 -0
- package/utils/text-sizing.d.ts +5 -0
- package/utils/text-sizing.js +1 -0
- package/utils/use-svg-colors.d.ts +1 -0
- package/utils/use-svg-colors.js +1 -1
- package/utils/validate-key.js +1 -1
- package/canvas/text-element/fit-font-size.d.ts +0 -5
- package/canvas/text-element/fit-font-size.js +0 -1
package/model/page-model.d.ts
CHANGED
|
@@ -135,6 +135,7 @@ declare const PageImpl: import("mobx-state-tree").IModelType<{
|
|
|
135
135
|
showInExport: boolean;
|
|
136
136
|
}>>;
|
|
137
137
|
readonly parent: any;
|
|
138
|
+
readonly isHighlighted: boolean;
|
|
138
139
|
readonly zIndex: any;
|
|
139
140
|
} & {
|
|
140
141
|
toJSON(): {
|
|
@@ -301,6 +302,10 @@ declare const PageImpl: import("mobx-state-tree").IModelType<{
|
|
|
301
302
|
legacyBackground: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<boolean>>;
|
|
302
303
|
curveEnabled: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
303
304
|
curvePower: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
305
|
+
textOverflow: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
|
|
306
|
+
maxLines: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
|
|
307
|
+
minFontSize: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
|
|
308
|
+
maxFontSize: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
|
|
304
309
|
}, {
|
|
305
310
|
readonly page: any;
|
|
306
311
|
readonly store: any;
|
|
@@ -365,6 +370,7 @@ declare const PageImpl: import("mobx-state-tree").IModelType<{
|
|
|
365
370
|
showInExport: boolean;
|
|
366
371
|
}>>;
|
|
367
372
|
readonly parent: any;
|
|
373
|
+
readonly isHighlighted: boolean;
|
|
368
374
|
readonly zIndex: any;
|
|
369
375
|
} & {
|
|
370
376
|
toJSON(): {
|
|
@@ -574,6 +580,7 @@ declare const PageImpl: import("mobx-state-tree").IModelType<{
|
|
|
574
580
|
showInExport: boolean;
|
|
575
581
|
}>>;
|
|
576
582
|
readonly parent: any;
|
|
583
|
+
readonly isHighlighted: boolean;
|
|
577
584
|
readonly zIndex: any;
|
|
578
585
|
} & {
|
|
579
586
|
toJSON(): {
|
|
@@ -799,6 +806,7 @@ declare const PageImpl: import("mobx-state-tree").IModelType<{
|
|
|
799
806
|
showInExport: boolean;
|
|
800
807
|
}>>;
|
|
801
808
|
readonly parent: any;
|
|
809
|
+
readonly isHighlighted: boolean;
|
|
802
810
|
readonly zIndex: any;
|
|
803
811
|
} & {
|
|
804
812
|
toJSON(): {
|
|
@@ -1023,6 +1031,7 @@ declare const PageImpl: import("mobx-state-tree").IModelType<{
|
|
|
1023
1031
|
showInExport: boolean;
|
|
1024
1032
|
}>>;
|
|
1025
1033
|
readonly parent: any;
|
|
1034
|
+
readonly isHighlighted: boolean;
|
|
1026
1035
|
readonly zIndex: any;
|
|
1027
1036
|
} & {
|
|
1028
1037
|
toJSON(): {
|
|
@@ -1248,6 +1257,7 @@ declare const PageImpl: import("mobx-state-tree").IModelType<{
|
|
|
1248
1257
|
showInExport: boolean;
|
|
1249
1258
|
}>>;
|
|
1250
1259
|
readonly parent: any;
|
|
1260
|
+
readonly isHighlighted: boolean;
|
|
1251
1261
|
readonly zIndex: any;
|
|
1252
1262
|
} & {
|
|
1253
1263
|
toJSON(): {
|
|
@@ -1469,6 +1479,7 @@ declare const PageImpl: import("mobx-state-tree").IModelType<{
|
|
|
1469
1479
|
showInExport: boolean;
|
|
1470
1480
|
}>>;
|
|
1471
1481
|
readonly parent: any;
|
|
1482
|
+
readonly isHighlighted: boolean;
|
|
1472
1483
|
readonly zIndex: any;
|
|
1473
1484
|
} & {
|
|
1474
1485
|
toJSON(): {
|
|
@@ -1843,6 +1854,7 @@ declare const PageImpl: import("mobx-state-tree").IModelType<{
|
|
|
1843
1854
|
showInExport: boolean;
|
|
1844
1855
|
}>>;
|
|
1845
1856
|
readonly parent: any;
|
|
1857
|
+
readonly isHighlighted: boolean;
|
|
1846
1858
|
readonly zIndex: any;
|
|
1847
1859
|
} & {
|
|
1848
1860
|
toJSON(): {
|
|
@@ -2136,6 +2148,7 @@ declare const PageImpl: import("mobx-state-tree").IModelType<{
|
|
|
2136
2148
|
showInExport: boolean;
|
|
2137
2149
|
}>>;
|
|
2138
2150
|
readonly parent: any;
|
|
2151
|
+
readonly isHighlighted: boolean;
|
|
2139
2152
|
readonly zIndex: any;
|
|
2140
2153
|
} & {
|
|
2141
2154
|
toJSON(): {
|
|
@@ -2302,6 +2315,10 @@ declare const PageImpl: import("mobx-state-tree").IModelType<{
|
|
|
2302
2315
|
legacyBackground: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<boolean>>;
|
|
2303
2316
|
curveEnabled: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
2304
2317
|
curvePower: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
2318
|
+
textOverflow: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
|
|
2319
|
+
maxLines: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
|
|
2320
|
+
minFontSize: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
|
|
2321
|
+
maxFontSize: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
|
|
2305
2322
|
}, {
|
|
2306
2323
|
readonly page: any;
|
|
2307
2324
|
readonly store: any;
|
|
@@ -2366,6 +2383,7 @@ declare const PageImpl: import("mobx-state-tree").IModelType<{
|
|
|
2366
2383
|
showInExport: boolean;
|
|
2367
2384
|
}>>;
|
|
2368
2385
|
readonly parent: any;
|
|
2386
|
+
readonly isHighlighted: boolean;
|
|
2369
2387
|
readonly zIndex: any;
|
|
2370
2388
|
} & {
|
|
2371
2389
|
toJSON(): {
|
|
@@ -2575,6 +2593,7 @@ declare const PageImpl: import("mobx-state-tree").IModelType<{
|
|
|
2575
2593
|
showInExport: boolean;
|
|
2576
2594
|
}>>;
|
|
2577
2595
|
readonly parent: any;
|
|
2596
|
+
readonly isHighlighted: boolean;
|
|
2578
2597
|
readonly zIndex: any;
|
|
2579
2598
|
} & {
|
|
2580
2599
|
toJSON(): {
|
|
@@ -2800,6 +2819,7 @@ declare const PageImpl: import("mobx-state-tree").IModelType<{
|
|
|
2800
2819
|
showInExport: boolean;
|
|
2801
2820
|
}>>;
|
|
2802
2821
|
readonly parent: any;
|
|
2822
|
+
readonly isHighlighted: boolean;
|
|
2803
2823
|
readonly zIndex: any;
|
|
2804
2824
|
} & {
|
|
2805
2825
|
toJSON(): {
|
|
@@ -3024,6 +3044,7 @@ declare const PageImpl: import("mobx-state-tree").IModelType<{
|
|
|
3024
3044
|
showInExport: boolean;
|
|
3025
3045
|
}>>;
|
|
3026
3046
|
readonly parent: any;
|
|
3047
|
+
readonly isHighlighted: boolean;
|
|
3027
3048
|
readonly zIndex: any;
|
|
3028
3049
|
} & {
|
|
3029
3050
|
toJSON(): {
|
|
@@ -3249,6 +3270,7 @@ declare const PageImpl: import("mobx-state-tree").IModelType<{
|
|
|
3249
3270
|
showInExport: boolean;
|
|
3250
3271
|
}>>;
|
|
3251
3272
|
readonly parent: any;
|
|
3273
|
+
readonly isHighlighted: boolean;
|
|
3252
3274
|
readonly zIndex: any;
|
|
3253
3275
|
} & {
|
|
3254
3276
|
toJSON(): {
|
|
@@ -3470,6 +3492,7 @@ declare const PageImpl: import("mobx-state-tree").IModelType<{
|
|
|
3470
3492
|
showInExport: boolean;
|
|
3471
3493
|
}>>;
|
|
3472
3494
|
readonly parent: any;
|
|
3495
|
+
readonly isHighlighted: boolean;
|
|
3473
3496
|
readonly zIndex: any;
|
|
3474
3497
|
} & {
|
|
3475
3498
|
toJSON(): {
|
|
@@ -3844,6 +3867,7 @@ declare const PageImpl: import("mobx-state-tree").IModelType<{
|
|
|
3844
3867
|
showInExport: boolean;
|
|
3845
3868
|
}>>;
|
|
3846
3869
|
readonly parent: any;
|
|
3870
|
+
readonly isHighlighted: boolean;
|
|
3847
3871
|
readonly zIndex: any;
|
|
3848
3872
|
} & {
|
|
3849
3873
|
toJSON(): {
|
|
@@ -4119,6 +4143,7 @@ declare const PageImpl: import("mobx-state-tree").IModelType<{
|
|
|
4119
4143
|
showInExport: boolean;
|
|
4120
4144
|
}>>;
|
|
4121
4145
|
readonly parent: any;
|
|
4146
|
+
readonly isHighlighted: boolean;
|
|
4122
4147
|
readonly zIndex: any;
|
|
4123
4148
|
} & {
|
|
4124
4149
|
toJSON(): {
|
|
@@ -4285,6 +4310,10 @@ declare const PageImpl: import("mobx-state-tree").IModelType<{
|
|
|
4285
4310
|
legacyBackground: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<boolean>>;
|
|
4286
4311
|
curveEnabled: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
4287
4312
|
curvePower: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
4313
|
+
textOverflow: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
|
|
4314
|
+
maxLines: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
|
|
4315
|
+
minFontSize: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
|
|
4316
|
+
maxFontSize: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
|
|
4288
4317
|
}, {
|
|
4289
4318
|
readonly page: any;
|
|
4290
4319
|
readonly store: any;
|
|
@@ -4349,6 +4378,7 @@ declare const PageImpl: import("mobx-state-tree").IModelType<{
|
|
|
4349
4378
|
showInExport: boolean;
|
|
4350
4379
|
}>>;
|
|
4351
4380
|
readonly parent: any;
|
|
4381
|
+
readonly isHighlighted: boolean;
|
|
4352
4382
|
readonly zIndex: any;
|
|
4353
4383
|
} & {
|
|
4354
4384
|
toJSON(): {
|
|
@@ -4558,6 +4588,7 @@ declare const PageImpl: import("mobx-state-tree").IModelType<{
|
|
|
4558
4588
|
showInExport: boolean;
|
|
4559
4589
|
}>>;
|
|
4560
4590
|
readonly parent: any;
|
|
4591
|
+
readonly isHighlighted: boolean;
|
|
4561
4592
|
readonly zIndex: any;
|
|
4562
4593
|
} & {
|
|
4563
4594
|
toJSON(): {
|
|
@@ -4783,6 +4814,7 @@ declare const PageImpl: import("mobx-state-tree").IModelType<{
|
|
|
4783
4814
|
showInExport: boolean;
|
|
4784
4815
|
}>>;
|
|
4785
4816
|
readonly parent: any;
|
|
4817
|
+
readonly isHighlighted: boolean;
|
|
4786
4818
|
readonly zIndex: any;
|
|
4787
4819
|
} & {
|
|
4788
4820
|
toJSON(): {
|
|
@@ -5007,6 +5039,7 @@ declare const PageImpl: import("mobx-state-tree").IModelType<{
|
|
|
5007
5039
|
showInExport: boolean;
|
|
5008
5040
|
}>>;
|
|
5009
5041
|
readonly parent: any;
|
|
5042
|
+
readonly isHighlighted: boolean;
|
|
5010
5043
|
readonly zIndex: any;
|
|
5011
5044
|
} & {
|
|
5012
5045
|
toJSON(): {
|
|
@@ -5232,6 +5265,7 @@ declare const PageImpl: import("mobx-state-tree").IModelType<{
|
|
|
5232
5265
|
showInExport: boolean;
|
|
5233
5266
|
}>>;
|
|
5234
5267
|
readonly parent: any;
|
|
5268
|
+
readonly isHighlighted: boolean;
|
|
5235
5269
|
readonly zIndex: any;
|
|
5236
5270
|
} & {
|
|
5237
5271
|
toJSON(): {
|
|
@@ -5453,6 +5487,7 @@ declare const PageImpl: import("mobx-state-tree").IModelType<{
|
|
|
5453
5487
|
showInExport: boolean;
|
|
5454
5488
|
}>>;
|
|
5455
5489
|
readonly parent: any;
|
|
5490
|
+
readonly isHighlighted: boolean;
|
|
5456
5491
|
readonly zIndex: any;
|
|
5457
5492
|
} & {
|
|
5458
5493
|
toJSON(): {
|
|
@@ -5827,6 +5862,7 @@ declare const PageImpl: import("mobx-state-tree").IModelType<{
|
|
|
5827
5862
|
showInExport: boolean;
|
|
5828
5863
|
}>>;
|
|
5829
5864
|
readonly parent: any;
|
|
5865
|
+
readonly isHighlighted: boolean;
|
|
5830
5866
|
readonly zIndex: any;
|
|
5831
5867
|
} & {
|
|
5832
5868
|
toJSON(): {
|
package/model/page-model.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getParentOfType as e,getSnapshot as t,isAlive as o,types as i}from"mobx-state-tree";import{nanoid as n}from"nanoid";import{resolveBleed as r}from"@polotno/schema";import{hasBlendMode as s}from"@polotno/core/page";import{ElementTypes as d,forEveryChild as a,forEveryNode as m,TYPES_MAP as c,zIndexOps as
|
|
1
|
+
import{getParentOfType as e,getSnapshot as t,isAlive as o,types as i}from"mobx-state-tree";import{nanoid as n}from"nanoid";import{resolveBleed as r}from"@polotno/schema";import{hasBlendMode as s}from"@polotno/core/page";import{ElementTypes as d,forEveryChild as a,forEveryNode as m,TYPES_MAP as c,zIndexOps as l}from"./group-model.js";import{Store as h}from"./store.js";import{getTotalClientRect as p}from"../utils/math.js";import{scaledFontSizeBounds as g}from"../utils/px.js";const u=i.model("Page",{id:i.identifier,children:i.array(i.late(()=>d)),width:i.optional(i.union(i.number,i.literal("auto")),"auto"),height:i.optional(i.union(i.number,i.literal("auto")),"auto"),background:"white",bleed:0,bleedTop:i.maybe(i.number),bleedRight:i.maybe(i.number),bleedBottom:i.maybe(i.number),bleedLeft:i.maybe(i.number),custom:i.frozen(),duration:5e3,_exporting:!1,_rendering:!1,_forceMount:!1}).postProcessSnapshot(e=>{const t=Object.assign({},e),o={};for(var i in t){"_"!==i[0]&&(o[i]=e[i])}return o}).views(t=>({get store(){return e(t,h)}})).views(e=>({get startTime(){let t=0;for(const o of e.store.pages){if(o.id===e.id){return t}t+=o.duration}return t},get _exportingOrRendering(){return e._exporting||e._rendering},get playheadLocalTime(){if(!o(e)){return null}const t=e.store;if(!(null==t?void 0:t.playheadAccurate)){return null}const i=t.effectiveTime-this.startTime;return i<0||i>e.duration?null:Math.min(i,Math.max(0,e.duration-1))}})).views(e=>({get computedWidth(){return"auto"===e.width?e.store.width:e.width},get computedHeight(){return"auto"===e.height?e.store.height:e.height},get computedBleed(){return r(e)},get hasBlendMode(){return s(e.children)}})).actions(e=>({toJSON:()=>JSON.parse(JSON.stringify(t(e)))})).actions(e=>Object.assign(Object.assign({clone(t={}){const o=e.toJSON(),i=new Map;o.children.forEach(e=>{const t=e.id,o=n(10);i.set(t,o),e.id=o,m(e,e=>{const t=e.id,o=n(10);i.set(t,o),e.id=o})}),o.children.forEach(e=>{e.cells&&e.cells.forEach(e=>{e.mergedInto&&i.has(e.mergedInto)&&(e.mergedInto=i.get(e.mergedInto))})});const r=Object.assign(Object.assign(Object.assign({},o),{id:n(10)}),t),s=e.store.selectedPages.includes(e),d=e.store.addPage(r),a=e.store.pages.indexOf(e);return d.setZIndex(a+1),s&&e.store.selectPages([d.id]),d},setZIndex(t){e.store.setPageZIndex(e.id,t)},set(t){Object.assign(e,t)},select(){e.store.selectPage(e.id)},addElement(t,{skipSelect:o=!1}={}){const i=c[t.type];if(!i){return void console.error("Can not find model with type "+t.type)}"children"in t&&Array.isArray(t.children)&&m(t,e=>{e.id=e.id||n(10)});const r=e.children.reduce((e,o)=>{if("group"===o.type){const i=o.children.reduce((e,o)=>{var i;const n=null===(i=o.name)||void 0===i?void 0:i.match(new RegExp(`${t.type}-(\\d+)`));if(n){const t=parseInt(n[1],10);return Math.max(e,t||0)}},0);return Math.max(e,i||0)}{const i=o.name.match(new RegExp(`${t.type}-(\\d+)`));if(i){const t=parseInt(i[1],10);return Math.max(e,t||0)}}return e},0),s=i.create(Object.assign({id:n(10),name:`${t.type}-${r+1}`},t));return e.children.push(s),s.selectable&&!o&&e.store.selectElements([s.id]),s}},l(e)),{setSize({width:t,height:o,useMagic:i,softChange:n}){if(i){const i=[],n=t=>"image"===t.type&&t.x<1&&t.y<1&&t.width>=e.computedWidth-2&&t.height>=e.computedHeight-2;a(e,e=>{"group"!==e.type&&(n(e)||i.push(e))});const r=i.length?p(i):{x:0,y:0,width:e.computedWidth,height:e.computedHeight},s=1/4,d=Math.max(0,Math.min(r.x,e.computedWidth-r.x-r.width)),m=e.computedWidth*s,c=Math.max(0,d-m),l=Math.max(0,Math.min(r.y,e.computedHeight-r.y-r.height)),h=e.computedHeight*s,u=Math.max(0,l-h),f=e.computedWidth-2*c,b=e.computedHeight-2*u,y=t/f,w=o/b,v=Math.min(y,w),x=(t-f*v)/2-c*v,E=(o-b*v)/2-u*v;a(e,e=>{var t;if("group"!==e.type){if(n(e)){e.set({x:e.x*v,y:e.y*v,width:e.width*y,height:e.height*w,cropX:0,cropY:0,cropWidth:1,cropHeight:1})}else if(e.set({x:x+e.x*v,y:E+e.y*v,width:e.width*v,height:e.height*v}),"text"===e.type){e.set(Object.assign({fontSize:e.fontSize*v},g(e,v)))}else if("figure"===e.type){e.set({strokeWidth:e.strokeWidth*v})}else if("table"===e.type){e.set({borderWidth:e.borderWidth*v});for(const o of e.cells){const e={fontSize:o.fontSize*v,cellPadding:o.cellPadding*v};if(o.borders){const i=JSON.parse(JSON.stringify(o.borders));for(const e of["top","right","bottom","left"]){null!=(null===(t=i[e])||void 0===t?void 0:t.width)&&(i[e]=Object.assign(Object.assign({},i[e]),{width:i[e].width*v}))}e.borders=i}o.set(e)}}}})}n||(e.width=t),n||(e.height=o)}})).actions(e=>({moveElementUp(t){console.warn("page.moveElementUp(id) is deprecated. Please use page.moveElementsUp([id1, id2]) instead."),e.moveElementsUp([t])},moveElementDown(t){console.warn("page.moveElementDown(id) is deprecated. Please use page.moveElementsDown([id1, id2]) instead."),e.moveElementsDown([t])},moveElementTop(t){console.warn("page.moveElementTop(id) is deprecated. Please use page.moveElementsTop([id1, id2]) instead."),e.moveElementsTop([t])},moveElementBottom(t){console.warn("page.moveElementBottom(id) is deprecated. Please use page.moveElementsBottom([id1, id2]) instead."),e.moveElementsBottom([t])},play(){e.store.play({startTime:e.startTime,endTime:e.startTime+e.duration})}}));export const Page=u;
|
package/model/shape-model.d.ts
CHANGED
package/model/store.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ export interface ImageExportOptions extends ExportOptions {
|
|
|
33
33
|
export interface GifExportOptions extends ExportOptions {
|
|
34
34
|
fps?: number;
|
|
35
35
|
pageIds?: Array<string>;
|
|
36
|
+
onProgress?: (progress: number, phase: 'rendering' | 'encoding') => void;
|
|
36
37
|
}
|
|
37
38
|
export interface PDFExportOptions extends ExportOptions {
|
|
38
39
|
dpi?: number;
|
|
@@ -220,6 +221,8 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
220
221
|
_forceShowCredit: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
221
222
|
_validated: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
222
223
|
}, {
|
|
224
|
+
highlightedElementId: string | null;
|
|
225
|
+
} & {
|
|
223
226
|
setTool: import("./image-tools.js").SetTool;
|
|
224
227
|
_setImageEditPanelAvailable(value: boolean): void;
|
|
225
228
|
_closeImageTool: (outcome?: import("../image-tools/host.js").CloseOutcome) => void;
|
|
@@ -352,6 +355,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
352
355
|
showInExport: boolean;
|
|
353
356
|
}>>;
|
|
354
357
|
readonly parent: any;
|
|
358
|
+
readonly isHighlighted: boolean;
|
|
355
359
|
readonly zIndex: any;
|
|
356
360
|
} & {
|
|
357
361
|
toJSON(): {
|
|
@@ -517,6 +521,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
517
521
|
showInExport: boolean;
|
|
518
522
|
}>>;
|
|
519
523
|
readonly parent: any;
|
|
524
|
+
readonly isHighlighted: boolean;
|
|
520
525
|
readonly zIndex: any;
|
|
521
526
|
} & {
|
|
522
527
|
toJSON(): {
|
|
@@ -646,6 +651,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
|
|
|
646
651
|
selectPage(id: string): void;
|
|
647
652
|
selectPages(ids: Array<string>): void;
|
|
648
653
|
selectElements(ids: Array<string>): void;
|
|
654
|
+
highlightElement(id: string | null): void;
|
|
649
655
|
toggleBleed(bleedVisible?: boolean): void;
|
|
650
656
|
toggleRulers(rulesVisible?: boolean): void;
|
|
651
657
|
setTimingPreview(mode: "all" | "playhead"): void;
|
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,onSnapshot as s,setLivelinessChecking as r,types as l}from"mobx-state-tree";import{UndoManager as d}from"./history.js";import{nanoid as p}from"nanoid";import c from"konva";import{computed as g}from"mobx";import{ZERO_BLEED as m,migrateDesign as u,CURRENT_SCHEMA_VERSION as f}from"@polotno/schema";import{downloadFile as h}from"../utils/download.js";import{getJsPDF as v}from"../utils/pdf.js";import{createGIF as y}from"../utils/gif-lib.js";import{validateKey as b,setKey as P}from"../utils/validate-key.js";import*as w from"../utils/fonts.js";import{flags as x}from"../utils/flags.js";import{addDpiMetadataToImage as E}from"../utils/image-dpi.js";import{nodeToCanvas as T,createExportCanvases as I,releaseExportCanvases as _}from"../utils/canvas.js";import{whenLoaded as O}from"../utils/loader.js";import{polotnoError as S}from"@polotno/core/errors";import{pxToUnit as k}from"../utils/unit.js";import{deepEqual as j}from"../utils/deep-equal.js";import{waitTillAvailable as F}from"../utils/wait.js";import{jsonToHTML as R}from"@polotno/html-export";import{jsonToSVG as A}from"@polotno/svg-export";import{warnOnceDeprecated as V}from"../utils/deprecation.js";import{Page as C}from"./page-model.js";import{forEveryChild as L,forEveryNode as M}from"./group-model.js";import{Audio as B}from"./audio-model.js";import{imageTools as D}from"./image-tools.js";import{IMAGE_TOOLS as H}from"../image-tools/sessions.js";function W(e){return!!e&&!!e.type&&"tablecell"!==e.type}r("ignore");export const Font=l.model("Font",{fontFamily:l.string,url:l.optional(l.string,""),styles:l.frozen()}).preProcessSnapshot(e=>Object.assign(Object.assign({},e),{fontFamily:e.fontFamily||e.name}));const N=l.model("BrushOptions",{strokeWidth:l.optional(l.number,5),stroke:l.optional(l.string,"#000000"),opacity:l.optional(l.number,1)});export const ROLES={ADMIN:"admin",VIEWER:"viewer"};export const Store=l.model("Store",{role:"",pages:l.array(C),fonts:l.array(Font),audios:l.array(B),width:1080,height:1080,currentTime:0,isPlaying:!1,scale:1,scaleToFit:1,unit:l.optional(l.enumeration("UnitType",["pt","mm","cm","in","px"]),"px"),dpi:72,schemaVersion:f,bleedVisible:!1,rulesVisible:!1,distanceGuidesVisible:!1,timingPreview:l.optional(l.enumeration("TimingPreview",["all","playhead"]),"all"),openedSidePanel:"",previousOpenedSidePanel:"",custom:l.frozen(),tool:l.optional(l.enumeration("Tool",["selection","draw","pan","text","eraser","crop","expand","inpaint","upscale","remove-background"]),"selection"),toolOptions:l.optional(l.model({brushType:l.optional(l.enumeration("BrushType",["brush","highlighter"]),"brush"),brush:l.optional(N,{}),highlighter:l.optional(N,{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:l.array(l.string),animatedElementsIds:l.array(l.string),history:l.optional(d,{targetPath:"../pages"}),_elementsPixelRatio:Math.min(2,"undefined"!=typeof window&&window.devicePixelRatio||1),_activePageId:"",_selectedPagesIds:l.array(l.string),_forceShowCredit:!1,_validated:!1}).extend(D).views(e=>{const t=g(()=>{const t={};return M({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(W)},get children(){return e.pages},get selectedShapes(){const e=[];return L({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 M({children:e.pages},e=>{if(!o&&t(e)){return o=e,!0}}),o},getElementById:t=>e._idsMap[t]})).actions(r=>{let l=0,d=null,g=!1;const f={afterCreate(){r.history.canUndo},setCurrentTime(e){r.currentTime=e},_togglePlaying(e=!r.isPlaying){r.isPlaying=e},play({animatedElementsIds:e=[],startTime:t=0,currentTime:i=0,endTime:n=r.duration,repeat:a=!1}={}){i&&(console.warn("currentTime property of store.play() is deprecated. Please use startTime instead."),t=i),r.animatedElementsIds=o(e),r.currentTime=t,r.isPlaying=!0,l=Date.now(),d=n,g=a,requestAnimationFrame(()=>f.seek())},checkActivePage(){const e=r.pageAtTime(r.currentTime);e&&f.selectPage(e.id)},seek(){if(!r.isPlaying){return}const e=Date.now(),t=e-l;l=e,r.currentTime+=t;const o=d||r.duration;r.currentTime>=o&&!g&&(r.currentTime=o),f.checkActivePage(),r.isPlaying&&r.currentTime<o?requestAnimationFrame(()=>f.seek()):r.isPlaying&&g?(r.currentTime=0,requestAnimationFrame(()=>f.seek())):f.pause()},pause(){r.isPlaying=!1,r.animatedElementsIds=o([])},stop(){f.pause(),r.currentTime=0,f.checkActivePage()},__(){r._validated||(b(r._forceShowCredit),r._validated=!0)},set(e){Object.assign(r,e)},setUnit({unit:e,dpi:t}){r.unit=e||r.unit,r.dpi=t||r.dpi},setRole(e){r.role=e},setToolOptions(t){const{brushType:o}=t,i=e(t,["brushType"]);o&&(r.toolOptions.brushType=o),Object.assign(r.toolOptions.active,i)},addPage(e){const t=C.create(Object.assign({id:p(10)},e));return r.pages.push(t),r._activePageId=t.id,r._selectedPagesIds=o([]),t},selectPage(e){r._activePageId=e,1===r._selectedPagesIds.length&&(r._selectedPagesIds=o([e]))},selectPages(e){r._selectedPagesIds=o(e),1===r._selectedPagesIds.length&&(r._activePageId=r._selectedPagesIds[0])},selectElements(e){r._beforeToolSelection(e);const t=e.map(e=>r.getElementById(e)).filter(W);t.sort((e,t)=>{var o,i,n,a;return(null!==(i=null===(o=e.parent)||void 0===o?void 0:o.children.indexOf(e))&&void 0!==i?i:0)-(null!==(a=null===(n=t.parent)||void 0===n?void 0:n.children.indexOf(t))&&void 0!==a?a:0)}),r.selectedElementsIds=o(t.map(e=>e.id))},toggleBleed(e){r.bleedVisible=null!=e?e:!r.bleedVisible},toggleRulers(e){r.rulesVisible=null!=e?e:!r.rulesVisible},setTimingPreview(e){r.timingPreview=e},toggleDistanceGuides(e){r.distanceGuidesVisible=null!=e?e:!r.distanceGuidesVisible},openSidePanel(e){r.openedSidePanel!==e&&("image-edit"!==e&&r._beforeToolPanel(),r.previousOpenedSidePanel=r.openedSidePanel,r.openedSidePanel=e)},restoreSidePanel(){r._beforeToolPanel();const e=r.previousOpenedSidePanel;e&&e!==r.openedSidePanel?r.openedSidePanel=e:r.openedSidePanel="photos"},setScale(e){r.scale=e},_setScaleToFit(e){r.scaleToFit=e},setElementsPixelRatio(e){r._elementsPixelRatio=e},setSize(e,t,o){r.pages.forEach(i=>{i.setSize({width:e,height:t,useMagic:o,softChange:!0})}),r.width=e,r.height=t},setPageZIndex(e,t){const o=r.pages.find(t=>t.id===e);o&&(n(o),r.pages.remove(o),r.pages.splice(t,0,o))},deletePages(e){const t=r.pages.indexOf(r.activePage);e.forEach(e=>{const t=r.pages.find(t=>t.id===e);i(t)});const n=r._selectedPagesIds.filter(e=>r.pages.some(t=>t.id===e)),a=Math.min(r.pages.length-1,t),s=r.pages[a];s&&(r._activePageId=s.id),f.selectPages(n),r.selectedElementsIds=o(r.selectedElementsIds.filter(e=>r.getElementById(e)))},groupElements(e,t={}){const i=e.map(e=>r.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.")}i.sort((e,t)=>a.children.indexOf(e)-a.children.indexOf(t));const s=a.children.indexOf(i[i.length-1])-i.length+1;i.forEach(e=>n(e));const l=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:p(10),name:`group-${l+1}`,children:i,type:"group"},t);return a.children.splice(s,0,d),r.selectedElementsIds=o([d.id]),a.children.find(e=>e.id===d.id)},ungroupElements(e){const t=e.map(e=>r.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)}}),r.selectedElementsIds=o(i)},deleteElements(e){const t=[];r.find(o=>(e.includes(o.id)&&t.push(o),!1)),t.forEach(e=>{i(e)}),r.selectedElementsIds=o(r.selectedElementsIds.filter(e=>r.getElementById(e)))},on(e,t){if("change"===e){let e=f.toJSON();return s(r,o=>{const i=f.toJSON();!j(e,i)&&(e=i,t(i))})}},async _toCanvas({pixelRatio:e,ignoreBackground:t,pageId:o,mimeType:i,includeBleed:n,_skipTimeout:a,quickMode:s=!1,_exportCanvases:l}={}){var d;const p=e||1;o=o||(null===(d=r.pages[0])||void 0===d?void 0:d.id);const g=r.pages.find(e=>e.id===o);if(!g){throw S("EXPORT_FAILED",`No page for export with id ${o}`,{reason:"page-not-found",pageId:o,availablePageIds:r.pages.map(e=>e.id)})}const u=r._elementsPixelRatio;try{(s?p>r._elementsPixelRatio:p!==r._elementsPixelRatio)&&f.setElementsPixelRatio(p),s?null==g||g.set({_forceMount:!0}):null==g||g.set({_exporting:!0});const e=await F(()=>{const e=c.stages.filter(e=>e.getAttr("pageId")===o);return 0===e.length?null:e});if(!e){throw S("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 d=e[0];await f.waitLoading({_skipTimeout:a});const u=d.findOne(".page-container");if(!u){throw S("EXPORT_FAILED","Export is failed. Canvas was unmounted.",{reason:"unmounted-during-export",pageId:o})}const h=d.position();d.position({x:0,y:0}),d.find("Transformer").forEach(e=>{e.setAttr("oldVisible",e.visible()),e.visible(!1)}),u.find(".page-background").forEach(e=>e.shadowEnabled(!1)),u.find(".page-background").forEach(e=>e.strokeEnabled(!1)),u.find(".highlighter").forEach(e=>e.visible(!1));const v=u.findOne(".page-background-group"),y=v.clip();v.clip({x:null,y:null,width:null,height:null});const b=u.findOne(".elements-container"),P=b.clip();b.clip({x:null,y:null,width:null,height:null});const w=u.find(e=>!e.visible()&&e.getAttr("editModeEnabled")&&!e.getAttr("hideInExport"));w.forEach(e=>{e.setAttr("oldVisible",e.visible()),e.show()});const E=u.find(e=>e.getAttr("hideInExport"));E.forEach(e=>{e.setAttr("oldVisible",e.visible()),e.hide()}),t&&u.find(".page-background").forEach(e=>e.hide());const I=n?g.computedBleed:m;let _=I.left,O=I.top;!r.bleedVisible&&n||(r.bleedVisible||n?r.bleedVisible&&n?(_=0,O=0):r.bleedVisible&&!n&&(_=-g.computedBleed.left,O=-g.computedBleed.top):(_=0,O=0));const k=g.computedWidth+I.left+I.right,j=g.computedHeight+I.top+I.bottom,R=u.scale();u.scale({x:1,y:1});const A=T(u,{x:u.x()-_,y:u.y()-O,width:k,height:j,pixelRatio:p,imageSmoothingQuality:x.imageDownScalingEnabled&&!s?"high":void 0,sceneCanvas:null==l?void 0:l.sceneCanvas});u.scale(R);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&&u.find(".page-background").forEach(e=>e.show()),E.forEach(e=>{e.visible(e.getAttr("oldVisible"))}),w.forEach(e=>{e.visible(e.getAttr("oldVisible"))}),u.find(".page-background").forEach(e=>e.shadowEnabled(!0)),u.find(".page-background").forEach(e=>e.strokeEnabled(!0)),d.find("Transformer").forEach(e=>{e.visible(e.getAttr("oldVisible"))}),u.find(".highlighter").forEach(e=>e.visible(!0)),v.clip(y),b.clip(P),d.position(h),null==g||g.set({_exporting:!1,_forceMount:!1}),await Promise.resolve(),V}finally{f.setElementsPixelRatio(u),null==g||g.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 l=await f._toCanvas(Object.assign({mimeType:o},s)),d=o||"image/png",p=l.toDataURL(d,i);c.Util.releaseCanvas(l);const g=null!=n?n:r.dpi;return"image/png"!==d&&"image/jpeg"!==d||"never"===a||"auto"===a&&72===g?p:E(p,d,g)},async toBlob(t={}){var{mimeType:o,quality:i}=t,n=e(t,["mimeType","quality"]);const a=await f._toCanvas(Object.assign({mimeType:o},n)),s=await new Promise(e=>{a.toBlob(e,o,i)});return c.Util.releaseCanvas(a),s},async saveAsImage(t={}){var{fileName:o}=t,i=e(t,["fileName"]);const n=(i.mimeType||"image/png").split("/")[1];h(await f.toDataURL(i),o||"polotno."+n)},async _toPDF(e){const t=e.dpi||r.dpi,o=e.parallel||1,i=e.unit||("px"===r.unit?"mm":r.unit),n=e.pixelRatio||1,a=e.pageIds||(e.pageId?[e.pageId]:r.pages.map(e=>e.id)),s=r.pages.filter(e=>a.includes(e.id)),l=await v(),d=e=>k({px:e,unit:i,dpi:t}),p=e.cropMarkSize||0,c=d(p),g=s[0]||{},u=e.includeBleed&&g.computedBleed||m,h=d(g.computedWidth+u.left+u.right+2*c),y=d(g.computedHeight+u.top+u.bottom+2*c);var b=new l({unit:i,orientation:h>y?"landscape":"portrait",format:[h,y],compress:!0,putOnlyUsedFonts:!0});b.deletePage(1);const P=((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 r of P){const t=r.map(async t=>{const o=e.includeBleed?t.computedBleed:m,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 f.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})=>{b.addPage([t,o],t>o?"landscape":"portrait");const r=b.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 S("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){b.setLineWidth(d(1));const e=c+d(s.left),i=c+d(s.right),n=c+d(s.top),a=c+d(s.bottom);b.line(e,0,e,c),b.line(0,n,c,n),b.line(t-i,0,t-i,c),b.line(t,n,t-c,n),b.line(0,o-a,c,o-a),b.line(e,o,e,o-c),b.line(t,o-a,t-c,o-a),b.line(t-i,o,t-i,o-c)}b.addImage(e,c,c,t-2*c,o-2*c,void 0,"FAST")})}return b},toPDFDataURL:async e=>(await f._toPDF(Object.assign({mimeType:"image/jpeg"},e))).output("datauristring"),async toGIFDataURL(e={}){const t=e.pixelRatio||1,o=e.pageIds||(e.pageId?[e.pageId]:r.pages.map(e=>e.id)),i=r.pages.filter(e=>o.includes(e.id));if(!i.length){throw S("EXPORT_FAILED","No pages found for GIF export",{reason:"page-not-found",pageId:e.pageId,availablePageIds:r.pages.map(e=>e.id)})}const n=i[0],a=await y({width:n.computedWidth*t,height:n.computedHeight*t}),s=1e3/(e.fps||10),l=I(),d=r._elementsPixelRatio;f.setElementsPixelRatio(t);try{for(const e of i){const o=Math.max(1,Math.floor(e.duration/s));for(let i=0;i<o;i++){const o=e.startTime+i*s||1;f.setCurrentTime(o);for(const t of r.pages){t.set({_rendering:t.id===e.id})}const n=await f._toCanvas({pixelRatio:t,pageId:e.id,_skipTimeout:!0,_exportCanvases:l});a.addFrame(n.getContext("2d"),{delay:s,copy:!0})}}}finally{_(l),f.setElementsPixelRatio(d)}for(const p of r.pages){p.set({_rendering:!1})}return f.stop(),a.render(),new Promise(e=>{a.on("finished",function(t){!function(e,t){var o=new FileReader;o.onload=function(e){t(e.target.result)},o.readAsDataURL(e)}(t,e)})})},async saveAsGIF(t={}){var{fileName:o}=t,i=e(t,["fileName"]);const n=await f.toGIFDataURL(i);h(n,o||"polotno.gif")},async toHTML({elementHook:e}={}){V("store.toHTML","store.toHTML()/saveAsHTML() are deprecated: install @polotno/html-export and call jsonToHTML(store.toJSON()) instead");const t=f.toJSON();return R(t,{elementHook:e,textOverflow:x.textOverflow,textSplitAllowed:x.textSplitAllowed})},async saveAsHTML({fileName:e,elementHook:t}={}){const o=await f.toHTML({elementHook:t}),i="data:text/html;base64,"+window.btoa(unescape(encodeURIComponent(o)));h(i,e||"polotno.html")},async toSVG({elementHook:e,pageId:t,fontEmbedding:o="inline"}={fontEmbedding:"inline"}){var i;V("store.toSVG","store.toSVG()/saveAsSVG() are deprecated: install @polotno/svg-export and call jsonToSVG(store.toJSON()) instead");const n=f.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 A(Object.assign(Object.assign({},n),{pages:a?[a]:[]}),{elementHook:e,fontEmbedding:o})},async saveAsSVG({fileName:e,elementHook:t,pageId:o,fontEmbedding:i="inline"}={}){const n=await f.toSVG({elementHook:t,pageId:o,fontEmbedding:i}),a="data:text/svg;base64,"+window.btoa(unescape(encodeURIComponent(n)));h(a,e||"polotno.svg")},async saveAsPDF(t={}){var{fileName:o}=t,i=e(t,["fileName"]);(await f._toPDF(Object.assign({mimeType:"image/jpeg"},i))).save(o||"polotno.pdf")},async waitLoading({_skipTimeout:e=!1}={}){e||await new Promise(e=>setTimeout(e,50)),await O()},toJSON:()=>({width:r.width,height:r.height,fonts:a(r.fonts),pages:a(r.pages),audios:a(r.audios),unit:r.unit,dpi:r.dpi,custom:r.custom,schemaVersion:r.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,l="boolean"==typeof o||null==o?void 0:o.modernizeTextBackground,d=u(e,{modernTextRenderer:x.htmlRenderEnabled||x.renderTagTextEnabled,modernizeTextBackground:l});delete d.schemaVersion,d.tool in H&&delete d.tool;const p=r.activePage?r.pages.indexOf(r.activePage):0;let c=null===(n=d.pages[p]||d.pages[0])||void 0===n?void 0:n.id;d._activePageId=c,d._selectedPagesIds=[],r._closeImageTool("discard"),L(r,e=>{var t;"pendingEdit"in e&&(null===(t=e.pendingEdit)||void 0===t||t.cancel())});const g=Object.assign({},a(r));Object.assign(g,d),g.history=s?a(r.history):{history:[],undoIdx:-1,targetPath:""},t(r,g)},clear({keepHistory:e=!1}={}){const t=r.pages.map(e=>e.id);f.deletePages(t),r.custom=null,e||r.history.clear()},addFont(e){r.fonts.filter(t=>t.fontFamily===e.fontFamily).forEach(e=>i(e)),r.fonts.push(e),w.injectCustomFont(e)},removeFont(e){r.fonts.filter(t=>t.fontFamily===e).forEach(e=>i(e)),w.removeCustomFont(e)},addAudio(e){const t=B.create(Object.assign({id:p(10)},e));r.audios.push(t)},removeAudio(e){const t=r.audios.find(t=>t.id===e);t&&r.audios.remove(t)},async loadFont(e,t,o,i){const n=r.fonts.find(t=>t.fontFamily===e)||w.globalFonts.find(t=>t.fontFamily===e);let a=[{fontStyle:"normal",fontWeight:"normal"},{fontStyle:"normal",fontWeight:"bold"}];return n?(n.styles&&(a=n.styles.map(e=>({fontStyle:e.fontStyle||"normal",fontWeight:e.fontWeight||"normal"}))),w.injectCustomFont(n)):w.injectGoogleFont(e),t&&o&&!a.some(e=>e.fontStyle===t&&e.fontWeight===o)&&a.push({fontStyle:t,fontWeight:o}),Promise.all(a.map(n=>(n.fontStyle===(null!=t?t:"normal")&&n.fontWeight===(null!=o?o:"normal")?w.loadFont:w.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 f});export function createStore({key:e,showCredit:t}={key:"",showCredit:!1}){return P(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,onSnapshot as s,setLivelinessChecking as r,types as l}from"mobx-state-tree";import{UndoManager as d}from"./history.js";import{nanoid as p}from"nanoid";import c from"konva";import{computed as g}from"mobx";import{ZERO_BLEED as m,migrateDesign as u,CURRENT_SCHEMA_VERSION as f}from"@polotno/schema";import{downloadFile as h}from"../utils/download.js";import{localFileToURL as v}from"../utils/file.js";import{getJsPDF as y}from"../utils/pdf.js";import{createGIF as b}from"../utils/gif-lib.js";import{validateKey as P,setKey as x}from"../utils/validate-key.js";import*as w from"../utils/fonts.js";import{flags as E}from"../utils/flags.js";import{addDpiMetadataToImage as I}from"../utils/image-dpi.js";import{nodeToCanvas as T,createExportCanvases as _,releaseExportCanvases as O}from"../utils/canvas.js";import{whenLoaded as S}from"../utils/loader.js";import{polotnoError as k}from"@polotno/core/errors";import{pxToUnit as j}from"../utils/unit.js";import{deepEqual as F}from"../utils/deep-equal.js";import{waitTillAvailable as R}from"../utils/wait.js";import{jsonToHTML as A}from"@polotno/html-export";import{jsonToSVG as V}from"@polotno/svg-export";import{warnOnceDeprecated as C}from"../utils/deprecation.js";import{Page as L}from"./page-model.js";import{forEveryChild as M,forEveryNode as B}from"./group-model.js";import{Audio as D}from"./audio-model.js";import{imageTools as H}from"./image-tools.js";import{IMAGE_TOOLS as W}from"../image-tools/sessions.js";function N(e){return!!e&&!!e.type&&"tablecell"!==e.type}r("ignore");export const Font=l.model("Font",{fontFamily:l.string,url:l.optional(l.string,""),styles:l.frozen()}).preProcessSnapshot(e=>Object.assign(Object.assign({},e),{fontFamily:e.fontFamily||e.name}));const G=l.model("BrushOptions",{strokeWidth:l.optional(l.number,5),stroke:l.optional(l.string,"#000000"),opacity:l.optional(l.number,1)});export const ROLES={ADMIN:"admin",VIEWER:"viewer"};export const Store=l.model("Store",{role:"",pages:l.array(L),fonts:l.array(Font),audios:l.array(D),width:1080,height:1080,currentTime:0,isPlaying:!1,scale:1,scaleToFit:1,unit:l.optional(l.enumeration("UnitType",["pt","mm","cm","in","px"]),"px"),dpi:72,schemaVersion:f,bleedVisible:!1,rulesVisible:!1,distanceGuidesVisible:!1,timingPreview:l.optional(l.enumeration("TimingPreview",["all","playhead"]),"all"),openedSidePanel:"",previousOpenedSidePanel:"",custom:l.frozen(),tool:l.optional(l.enumeration("Tool",["selection","draw","pan","text","eraser","crop","expand","inpaint","upscale","remove-background"]),"selection"),toolOptions:l.optional(l.model({brushType:l.optional(l.enumeration("BrushType",["brush","highlighter"]),"brush"),brush:l.optional(G,{}),highlighter:l.optional(G,{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:l.array(l.string),animatedElementsIds:l.array(l.string),history:l.optional(d,{targetPath:"../pages"}),_elementsPixelRatio:Math.min(2,"undefined"!=typeof window&&window.devicePixelRatio||1),_activePageId:"",_selectedPagesIds:l.array(l.string),_forceShowCredit:!1,_validated:!1}).volatile(()=>({highlightedElementId:null})).extend(H).views(e=>{const t=g(()=>{const t={};return B({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(N)},get children(){return e.pages},get selectedShapes(){const e=[];return M({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 B({children:e.pages},e=>{if(!o&&t(e)){return o=e,!0}}),o},getElementById:t=>e._idsMap[t]})).actions(r=>{let l=0,d=null,g=!1;const f={afterCreate(){r.history.canUndo},setCurrentTime(e){r.currentTime=e},_togglePlaying(e=!r.isPlaying){r.isPlaying=e},play({animatedElementsIds:e=[],startTime:t=0,currentTime:i=0,endTime:n=r.duration,repeat:a=!1}={}){i&&(console.warn("currentTime property of store.play() is deprecated. Please use startTime instead."),t=i),r.animatedElementsIds=o(e),r.currentTime=t,r.isPlaying=!0,l=Date.now(),d=n,g=a,requestAnimationFrame(()=>f.seek())},checkActivePage(){const e=r.pageAtTime(r.currentTime);e&&f.selectPage(e.id)},seek(){if(!r.isPlaying){return}const e=Date.now(),t=e-l;l=e,r.currentTime+=t;const o=d||r.duration;r.currentTime>=o&&!g&&(r.currentTime=o),f.checkActivePage(),r.isPlaying&&r.currentTime<o?requestAnimationFrame(()=>f.seek()):r.isPlaying&&g?(r.currentTime=0,requestAnimationFrame(()=>f.seek())):f.pause()},pause(){r.isPlaying=!1,r.animatedElementsIds=o([])},stop(){f.pause(),r.currentTime=0,f.checkActivePage()},__(){r._validated||(P(r._forceShowCredit),r._validated=!0)},set(e){Object.assign(r,e)},setUnit({unit:e,dpi:t}){r.unit=e||r.unit,r.dpi=t||r.dpi},setRole(e){r.role=e},setToolOptions(t){const{brushType:o}=t,i=e(t,["brushType"]);o&&(r.toolOptions.brushType=o),Object.assign(r.toolOptions.active,i)},addPage(e){const t=L.create(Object.assign({id:p(10)},e));return r.pages.push(t),r._activePageId=t.id,r._selectedPagesIds=o([]),t},selectPage(e){r._activePageId=e,1===r._selectedPagesIds.length&&(r._selectedPagesIds=o([e]))},selectPages(e){r._selectedPagesIds=o(e),1===r._selectedPagesIds.length&&(r._activePageId=r._selectedPagesIds[0])},selectElements(e){r._beforeToolSelection(e);const t=e.map(e=>r.getElementById(e)).filter(N);t.sort((e,t)=>{var o,i,n,a;return(null!==(i=null===(o=e.parent)||void 0===o?void 0:o.children.indexOf(e))&&void 0!==i?i:0)-(null!==(a=null===(n=t.parent)||void 0===n?void 0:n.children.indexOf(t))&&void 0!==a?a:0)}),r.selectedElementsIds=o(t.map(e=>e.id))},highlightElement(e){r.highlightedElementId=e},toggleBleed(e){r.bleedVisible=null!=e?e:!r.bleedVisible},toggleRulers(e){r.rulesVisible=null!=e?e:!r.rulesVisible},setTimingPreview(e){r.timingPreview=e},toggleDistanceGuides(e){r.distanceGuidesVisible=null!=e?e:!r.distanceGuidesVisible},openSidePanel(e){r.openedSidePanel!==e&&("image-edit"!==e&&r._beforeToolPanel(),r.previousOpenedSidePanel=r.openedSidePanel,r.openedSidePanel=e)},restoreSidePanel(){r._beforeToolPanel();const e=r.previousOpenedSidePanel;e&&e!==r.openedSidePanel?r.openedSidePanel=e:r.openedSidePanel="photos"},setScale(e){r.scale=e},_setScaleToFit(e){r.scaleToFit=e},setElementsPixelRatio(e){r._elementsPixelRatio=e},setSize(e,t,o){r.pages.forEach(i=>{i.setSize({width:e,height:t,useMagic:o,softChange:!0})}),r.width=e,r.height=t},setPageZIndex(e,t){const o=r.pages.find(t=>t.id===e);o&&(n(o),r.pages.remove(o),r.pages.splice(t,0,o))},deletePages(e){const t=r.pages.indexOf(r.activePage);e.forEach(e=>{const t=r.pages.find(t=>t.id===e);i(t)});const n=r._selectedPagesIds.filter(e=>r.pages.some(t=>t.id===e)),a=Math.min(r.pages.length-1,t),s=r.pages[a];s&&(r._activePageId=s.id),f.selectPages(n),r.selectedElementsIds=o(r.selectedElementsIds.filter(e=>r.getElementById(e)))},groupElements(e,t={}){const i=e.map(e=>r.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.")}i.sort((e,t)=>a.children.indexOf(e)-a.children.indexOf(t));const s=a.children.indexOf(i[i.length-1])-i.length+1;i.forEach(e=>n(e));const l=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:p(10),name:`group-${l+1}`,children:i,type:"group"},t);return a.children.splice(s,0,d),r.selectedElementsIds=o([d.id]),a.children.find(e=>e.id===d.id)},ungroupElements(e){const t=e.map(e=>r.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)}}),r.selectedElementsIds=o(i)},deleteElements(e){const t=[];r.find(o=>(e.includes(o.id)&&t.push(o),!1)),t.forEach(e=>{i(e)}),r.selectedElementsIds=o(r.selectedElementsIds.filter(e=>r.getElementById(e)))},on(e,t){if("change"===e){let e=f.toJSON();return s(r,o=>{const i=f.toJSON();!F(e,i)&&(e=i,t(i))})}},async _toCanvas({pixelRatio:e,ignoreBackground:t,pageId:o,mimeType:i,includeBleed:n,_skipTimeout:a,quickMode:s=!1,_exportCanvases:l}={}){var d;const p=e||1;o=o||(null===(d=r.pages[0])||void 0===d?void 0:d.id);const g=r.pages.find(e=>e.id===o);if(!g){throw k("EXPORT_FAILED",`No page for export with id ${o}`,{reason:"page-not-found",pageId:o,availablePageIds:r.pages.map(e=>e.id)})}const u=r._elementsPixelRatio;try{(s?p>r._elementsPixelRatio:p!==r._elementsPixelRatio)&&f.setElementsPixelRatio(p),s?null==g||g.set({_forceMount:!0}):null==g||g.set({_exporting:!0});const e=await R(()=>{const e=c.stages.filter(e=>e.getAttr("pageId")===o);return 0===e.length?null:e});if(!e){throw k("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 d=e[0];await f.waitLoading({_skipTimeout:a});const u=d.findOne(".page-container");if(!u){throw k("EXPORT_FAILED","Export is failed. Canvas was unmounted.",{reason:"unmounted-during-export",pageId:o})}const h=d.position();d.position({x:0,y:0}),d.find("Transformer").forEach(e=>{e.setAttr("oldVisible",e.visible()),e.visible(!1)}),u.find(".page-background").forEach(e=>e.shadowEnabled(!1)),u.find(".page-background").forEach(e=>e.strokeEnabled(!1)),u.find(".highlighter").forEach(e=>e.visible(!1));const v=u.findOne(".page-background-group"),y=v.clip();v.clip({x:null,y:null,width:null,height:null});const b=u.findOne(".elements-container"),P=b.clip();b.clip({x:null,y:null,width:null,height:null});const x=u.find(e=>!e.visible()&&e.getAttr("editModeEnabled")&&!e.getAttr("hideInExport"));x.forEach(e=>{e.setAttr("oldVisible",e.visible()),e.show()});const w=u.find(e=>e.getAttr("hideInExport"));w.forEach(e=>{e.setAttr("oldVisible",e.visible()),e.hide()}),t&&u.find(".page-background").forEach(e=>e.hide());const I=n?g.computedBleed:m;let _=I.left,O=I.top;!r.bleedVisible&&n||(r.bleedVisible||n?r.bleedVisible&&n?(_=0,O=0):r.bleedVisible&&!n&&(_=-g.computedBleed.left,O=-g.computedBleed.top):(_=0,O=0));const S=g.computedWidth+I.left+I.right,j=g.computedHeight+I.top+I.bottom,F=u.scale();u.scale({x:1,y:1});const A=T(u,{x:u.x()-_,y:u.y()-O,width:S,height:j,pixelRatio:p,imageSmoothingQuality:E.imageDownScalingEnabled&&!s?"high":void 0,sceneCanvas:null==l?void 0:l.sceneCanvas});u.scale(F);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&&u.find(".page-background").forEach(e=>e.show()),w.forEach(e=>{e.visible(e.getAttr("oldVisible"))}),x.forEach(e=>{e.visible(e.getAttr("oldVisible"))}),u.find(".page-background").forEach(e=>e.shadowEnabled(!0)),u.find(".page-background").forEach(e=>e.strokeEnabled(!0)),d.find("Transformer").forEach(e=>{e.visible(e.getAttr("oldVisible"))}),u.find(".highlighter").forEach(e=>e.visible(!0)),v.clip(y),b.clip(P),d.position(h),null==g||g.set({_exporting:!1,_forceMount:!1}),await Promise.resolve(),V}finally{f.setElementsPixelRatio(u),null==g||g.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 l=await f._toCanvas(Object.assign({mimeType:o},s)),d=o||"image/png",p=l.toDataURL(d,i);c.Util.releaseCanvas(l);const g=null!=n?n:r.dpi;return"image/png"!==d&&"image/jpeg"!==d||"never"===a||"auto"===a&&72===g?p:I(p,d,g)},async toBlob(t={}){var{mimeType:o,quality:i}=t,n=e(t,["mimeType","quality"]);const a=await f._toCanvas(Object.assign({mimeType:o},n)),s=await new Promise(e=>{a.toBlob(e,o,i)});return c.Util.releaseCanvas(a),s},async saveAsImage(t={}){var{fileName:o}=t,i=e(t,["fileName"]);const n=(i.mimeType||"image/png").split("/")[1];h(await f.toDataURL(i),o||"polotno."+n)},async _toPDF(e){const t=e.dpi||r.dpi,o=e.parallel||1,i=e.unit||("px"===r.unit?"mm":r.unit),n=e.pixelRatio||1,a=e.pageIds||(e.pageId?[e.pageId]:r.pages.map(e=>e.id)),s=r.pages.filter(e=>a.includes(e.id)),l=await y(),d=e=>j({px:e,unit:i,dpi:t}),p=e.cropMarkSize||0,c=d(p),g=s[0]||{},u=e.includeBleed&&g.computedBleed||m,h=d(g.computedWidth+u.left+u.right+2*c),v=d(g.computedHeight+u.top+u.bottom+2*c);var b=new l({unit:i,orientation:h>v?"landscape":"portrait",format:[h,v],compress:!0,putOnlyUsedFonts:!0});b.deletePage(1);const P=((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 x=0;for(const r of P){const t=r.map(async t=>{const o=e.includeBleed?t.computedBleed:m,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 f.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(++x/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})=>{b.addPage([t,o],t>o?"landscape":"portrait");const r=b.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 k("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){b.setLineWidth(d(1));const e=c+d(s.left),i=c+d(s.right),n=c+d(s.top),a=c+d(s.bottom);b.line(e,0,e,c),b.line(0,n,c,n),b.line(t-i,0,t-i,c),b.line(t,n,t-c,n),b.line(0,o-a,c,o-a),b.line(e,o,e,o-c),b.line(t,o-a,t-c,o-a),b.line(t-i,o,t-i,o-c)}b.addImage(e,c,c,t-2*c,o-2*c,void 0,"FAST")})}return b},toPDFDataURL:async e=>(await f._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]:r.pages.map(e=>e.id)),a=r.pages.filter(e=>n.includes(e.id));if(!a.length){throw k("EXPORT_FAILED","No pages found for GIF export",{reason:"page-not-found",pageId:e.pageId,availablePageIds:r.pages.map(e=>e.id)})}null===(t=e.onProgress)||void 0===t||t.call(e,0,"rendering");const s=a[0],l=await b({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=_(),u=r._elementsPixelRatio;f.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;f.setCurrentTime(n);for(const e of r.pages){e.set({_rendering:e.id===t.id})}const s=await f._toCanvas({pixelRatio:i,pageId:t.id,_skipTimeout:!0,_exportCanvases:m});l.addFrame(s.getContext("2d"),{delay:d,copy:!0}),g++,null===(o=e.onProgress)||void 0===o||o.call(e,g/c/2,"rendering")}}}finally{O(m),f.setElementsPixelRatio(u);for(const e of r.pages){e.set({_rendering:!1})}f.stop()}return new Promise((t,o)=>{let i=!1;e.onProgress&&l.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)}}}),l.on("finished",e=>{i||v(e).then(t,o)}),l.render()})},async saveAsGIF(t={}){var{fileName:o}=t,i=e(t,["fileName"]);const n=await f.toGIFDataURL(i);h(n,o||"polotno.gif")},async toHTML({elementHook:e}={}){C("store.toHTML","store.toHTML()/saveAsHTML() are deprecated: install @polotno/html-export and call jsonToHTML(store.toJSON()) instead");const t=f.toJSON();return A(t,{elementHook:e,textOverflow:E.textOverflow,textSplitAllowed:E.textSplitAllowed})},async saveAsHTML({fileName:e,elementHook:t}={}){const o=await f.toHTML({elementHook:t}),i="data:text/html;base64,"+window.btoa(unescape(encodeURIComponent(o)));h(i,e||"polotno.html")},async toSVG({elementHook:e,pageId:t,fontEmbedding:o="inline"}={fontEmbedding:"inline"}){var i;C("store.toSVG","store.toSVG()/saveAsSVG() are deprecated: install @polotno/svg-export and call jsonToSVG(store.toJSON()) instead");const n=f.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 V(Object.assign(Object.assign({},n),{pages:a?[a]:[]}),Object.assign({elementHook:e,fontEmbedding:o,textSplitAllowed:E.textSplitAllowed},"fit"===E.textOverflow&&{textOverflow:"fit"}))},async saveAsSVG({fileName:e,elementHook:t,pageId:o,fontEmbedding:i="inline"}={}){const n=await f.toSVG({elementHook:t,pageId:o,fontEmbedding:i}),a="data:text/svg;base64,"+window.btoa(unescape(encodeURIComponent(n)));h(a,e||"polotno.svg")},async saveAsPDF(t={}){var{fileName:o}=t,i=e(t,["fileName"]);(await f._toPDF(Object.assign({mimeType:"image/jpeg"},i))).save(o||"polotno.pdf")},async waitLoading({_skipTimeout:e=!1}={}){e||await new Promise(e=>setTimeout(e,50)),await S()},toJSON:()=>({width:r.width,height:r.height,fonts:a(r.fonts),pages:a(r.pages),audios:a(r.audios),unit:r.unit,dpi:r.dpi,custom:r.custom,schemaVersion:r.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,l="boolean"==typeof o||null==o?void 0:o.modernizeTextBackground,d=u(e,{modernTextRenderer:E.htmlRenderEnabled||E.renderTagTextEnabled,modernizeTextBackground:l});delete d.schemaVersion,d.tool in W&&delete d.tool;const p=r.activePage?r.pages.indexOf(r.activePage):0;let c=null===(n=d.pages[p]||d.pages[0])||void 0===n?void 0:n.id;d._activePageId=c,d._selectedPagesIds=[],r._closeImageTool("discard"),M(r,e=>{var t;"pendingEdit"in e&&(null===(t=e.pendingEdit)||void 0===t||t.cancel())});const g=Object.assign({},a(r));Object.assign(g,d),g.history=s?a(r.history):{history:[],undoIdx:-1,targetPath:""},t(r,g)},clear({keepHistory:e=!1}={}){const t=r.pages.map(e=>e.id);f.deletePages(t),r.custom=null,e||r.history.clear()},addFont(e){r.fonts.filter(t=>t.fontFamily===e.fontFamily).forEach(e=>i(e)),r.fonts.push(e),w.injectCustomFont(e)},removeFont(e){r.fonts.filter(t=>t.fontFamily===e).forEach(e=>i(e)),w.removeCustomFont(e)},addAudio(e){const t=D.create(Object.assign({id:p(10)},e));r.audios.push(t)},removeAudio(e){const t=r.audios.find(t=>t.id===e);t&&r.audios.remove(t)},async loadFont(e,t,o,i){const n=r.fonts.find(t=>t.fontFamily===e)||w.globalFonts.find(t=>t.fontFamily===e);let a=[{fontStyle:"normal",fontWeight:"normal"},{fontStyle:"normal",fontWeight:"bold"}];return n?(n.styles&&(a=n.styles.map(e=>({fontStyle:e.fontStyle||"normal",fontWeight:e.fontWeight||"normal"}))),w.injectCustomFont(n)):w.injectGoogleFont(e),t&&o&&!a.some(e=>e.fontStyle===t&&e.fontWeight===o)&&a.push({fontStyle:t,fontWeight:o}),Promise.all(a.map(n=>(n.fontStyle===(null!=t?t:"normal")&&n.fontWeight===(null!=o?o:"normal")?w.loadFont:w.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 f});export function createStore({key:e,showCredit:t}={key:"",showCredit:!1}){return x(e),Store.create({_forceShowCredit:t})}export default createStore;
|
package/model/svg-model.d.ts
CHANGED
package/model/table-model.d.ts
CHANGED
package/model/text-model.d.ts
CHANGED
|
@@ -80,6 +80,10 @@ export declare const TextElement: import("mobx-state-tree").IModelType<{
|
|
|
80
80
|
legacyBackground: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<boolean>>;
|
|
81
81
|
curveEnabled: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
82
82
|
curvePower: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
83
|
+
textOverflow: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
|
|
84
|
+
maxLines: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
|
|
85
|
+
minFontSize: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
|
|
86
|
+
maxFontSize: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
|
|
83
87
|
}, {
|
|
84
88
|
readonly page: any;
|
|
85
89
|
readonly store: any;
|
|
@@ -144,6 +148,7 @@ export declare const TextElement: import("mobx-state-tree").IModelType<{
|
|
|
144
148
|
showInExport: boolean;
|
|
145
149
|
}>>;
|
|
146
150
|
readonly parent: any;
|
|
151
|
+
readonly isHighlighted: boolean;
|
|
147
152
|
readonly zIndex: any;
|
|
148
153
|
} & {
|
|
149
154
|
toJSON(): {
|
package/model/text-model.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{types as e,isAlive as t}from"mobx-state-tree";import{clampFontSize as o}from"@polotno/schema/defaults";import{hasMeasuredHeight as n,parseNumericLineHeight as
|
|
1
|
+
import{types as e,isAlive as t}from"mobx-state-tree";import{clampFontSize as o}from"@polotno/schema/defaults";import{hasMeasuredHeight as n,parseNumericLineHeight as i}from"@polotno/core/text-types";import{Shape as r}from"./shape-model.js";const a=e=>{var t;return"string"!=typeof e?e:null!==(t=i(e))&&void 0!==t?t:e};export const TextElement=r.named("Text").props({type:"text",text:"",placeholder:"",fontSize:14,fontFamily:"Roboto",fontStyle:"normal",fontWeight:"normal",textDecoration:"",textTransform:"none",fill:"black",align:"center",width:100,height:0,verticalAlign:"top",strokeWidth:0,stroke:"black",strokeLineJoin:"round",lineHeight:e.optional(e.union(e.number,e.string),1.2),letterSpacing:0,_editModeEnabled:!1,backgroundEnabled:!1,backgroundColor:"#7ED321",backgroundOpacity:1,backgroundCornerRadius:.5,backgroundPadding:.5,borderColor:"black",borderSize:0,legacyBackground:e.maybe(e.boolean),curveEnabled:!1,curvePower:.5,textOverflow:e.maybe(e.string),maxLines:e.maybe(e.number),minFontSize:e.maybe(e.number),maxFontSize:e.maybe(e.number)}).preProcessSnapshot(e=>{const t=Object.assign(Object.assign({},e),{fontSize:o(e.fontSize),minFontSize:o(e.minFontSize),maxFontSize:o(e.maxFontSize),lineHeight:a(e.lineHeight)});return n(t)||delete t.height,t}).actions(e=>{const n=e.set;return{set(e){for(const t of["fontSize","minFontSize","maxFontSize"]){null!=e[t]&&(e=Object.assign(Object.assign({},e),{[t]:o(e[t])}))}"string"==typeof e.lineHeight&&(e=Object.assign(Object.assign({},e),{lineHeight:a(e.lineHeight)})),n(e)},toggleEditMode(o){if(!t(e)){return}const n=null!=o?o:!e._editModeEnabled;n!==e._editModeEnabled&&(e._editModeEnabled=n,e._editModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction())},beforeDestroy(){e._editModeEnabled&&e.store.history.endTransaction()}}});
|
package/model/video-model.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polotno",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.16.0",
|
|
4
4
|
"description": "Design editor SDK: embed a Canva-like editor, generate designs from templates and data, export PNG, PDF, and video in the browser or on a server.",
|
|
5
5
|
"author": "Anton Lavrenov",
|
|
6
6
|
"repository": {
|
|
@@ -112,28 +112,28 @@
|
|
|
112
112
|
"./polotno.blueprint.css": "./blueprint.polotno.css"
|
|
113
113
|
},
|
|
114
114
|
"dependencies": {
|
|
115
|
-
"@base-ui/react": "^1.
|
|
116
|
-
"@polotno/core": "0.
|
|
117
|
-
"@polotno/html-export": "0.
|
|
118
|
-
"@polotno/schema": "0.
|
|
119
|
-
"@polotno/svg-export": "0.
|
|
115
|
+
"@base-ui/react": "^1.9.0",
|
|
116
|
+
"@polotno/core": "0.16.0",
|
|
117
|
+
"@polotno/html-export": "0.9.0",
|
|
118
|
+
"@polotno/schema": "0.9.0",
|
|
119
|
+
"@polotno/svg-export": "0.10.0",
|
|
120
120
|
"class-variance-authority": "^0.7.1",
|
|
121
121
|
"clsx": "^2.1.1",
|
|
122
122
|
"gifuct-js": "^2.1.2",
|
|
123
|
-
"konva": "^10.
|
|
123
|
+
"konva": "^10.8.0",
|
|
124
124
|
"lodash-es": "^4.18.1",
|
|
125
|
-
"lucide-react": "^1.
|
|
126
|
-
"mediabunny": "^1.61.
|
|
125
|
+
"lucide-react": "^1.57.0",
|
|
126
|
+
"mediabunny": "^1.61.4",
|
|
127
127
|
"mobx": "7.0.6",
|
|
128
128
|
"mobx-react-lite": "^5.1.0",
|
|
129
129
|
"mobx-state-tree": "8.0.0",
|
|
130
|
-
"nanoid": "^6.0.
|
|
130
|
+
"nanoid": "^6.0.2",
|
|
131
131
|
"quill": "^2.0.3",
|
|
132
132
|
"react-konva": "18.2.16",
|
|
133
133
|
"react-konva-utils": "^2.1.0",
|
|
134
134
|
"react-sortablejs": "6.1.4",
|
|
135
|
-
"react-window": "^2.3.
|
|
136
|
-
"render-tag": "
|
|
135
|
+
"react-window": "^2.3.4",
|
|
136
|
+
"render-tag": "0.3.2",
|
|
137
137
|
"sortablejs": "^1.15.7",
|
|
138
138
|
"svg-round-corners": "^0.4.3",
|
|
139
139
|
"swr": "^2.5.1",
|
|
@@ -170,8 +170,8 @@
|
|
|
170
170
|
}
|
|
171
171
|
},
|
|
172
172
|
"devDependencies": {
|
|
173
|
-
"@babel/parser": "^8.0.
|
|
174
|
-
"@babel/traverse": "^8.0.
|
|
173
|
+
"@babel/parser": "^8.0.7",
|
|
174
|
+
"@babel/traverse": "^8.0.7",
|
|
175
175
|
"@blueprintjs/core": "6.21.0",
|
|
176
176
|
"@blueprintjs/icons": "^6.14.1",
|
|
177
177
|
"@blueprintjs/select": "6.4.0",
|
|
@@ -180,9 +180,9 @@
|
|
|
180
180
|
"@testing-library/dom": "^10.4.2",
|
|
181
181
|
"@testing-library/react": "^16.3.3",
|
|
182
182
|
"@types/react": "^19.3.0",
|
|
183
|
-
"@vitejs/plugin-react": "^6.1.
|
|
184
|
-
"@vitest/browser": "^5.0.
|
|
185
|
-
"@vitest/browser-playwright": "^5.0.
|
|
183
|
+
"@vitejs/plugin-react": "^6.1.2",
|
|
184
|
+
"@vitest/browser": "^5.0.4",
|
|
185
|
+
"@vitest/browser-playwright": "^5.0.4",
|
|
186
186
|
"assemblyscript": "^0.28.20",
|
|
187
187
|
"assert": "^2.1.0",
|
|
188
188
|
"bippy": "^0.7.3",
|
|
@@ -192,8 +192,8 @@
|
|
|
192
192
|
"glob": "^13.0.6",
|
|
193
193
|
"jest-file-snapshot": "^0.7.0",
|
|
194
194
|
"jsdom": "^30.1.2",
|
|
195
|
-
"playwright": "^1.
|
|
196
|
-
"postcss": "^8.5.
|
|
195
|
+
"playwright": "^1.64.1",
|
|
196
|
+
"postcss": "^8.5.30",
|
|
197
197
|
"postcss-selector-parser": "^7.1.6",
|
|
198
198
|
"pptxgenjs": "^4.0.1",
|
|
199
199
|
"process": "^0.11.10",
|
|
@@ -203,8 +203,8 @@
|
|
|
203
203
|
"terser": "^5.51.2",
|
|
204
204
|
"tw-animate-css": "^1.4.0",
|
|
205
205
|
"typescript": "~6.0.3",
|
|
206
|
-
"vite": "^8.3.
|
|
207
|
-
"vitest": "^5.0.
|
|
206
|
+
"vite": "^8.3.4",
|
|
207
|
+
"vitest": "^5.0.4"
|
|
208
208
|
},
|
|
209
209
|
"homepage": "https://polotno.com/",
|
|
210
210
|
"scripts": {
|