polotno 3.11.0 → 3.12.1

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.
Files changed (72) hide show
  1. package/README.md +57 -22
  2. package/blueprint/side-panel/select-video.d.ts +6 -2
  3. package/canvas/crop-overlay.d.ts +42 -0
  4. package/canvas/crop-overlay.js +1 -0
  5. package/canvas/downscale-bands.d.ts +10 -0
  6. package/canvas/downscale-bands.js +1 -0
  7. package/canvas/downscale-kernel.d.ts +7 -0
  8. package/canvas/downscale-kernel.js +1 -0
  9. package/canvas/downscale-kernel.wasm.d.ts +1 -0
  10. package/canvas/downscale-kernel.wasm.js +1 -0
  11. package/canvas/downscale-passes.d.ts +7 -0
  12. package/canvas/downscale-passes.js +1 -0
  13. package/canvas/downscale.d.ts +16 -2
  14. package/canvas/downscale.js +1 -1
  15. package/canvas/drawing-layer.js +1 -1
  16. package/canvas/element.js +1 -1
  17. package/canvas/gif-element.js +1 -1
  18. package/canvas/hotkeys.js +1 -1
  19. package/canvas/image-element.d.ts +10 -0
  20. package/canvas/image-element.js +1 -1
  21. package/canvas/page.js +1 -1
  22. package/canvas/tooltip.js +1 -1
  23. package/canvas/transform-box.d.ts +9 -0
  24. package/canvas/transform-box.js +1 -0
  25. package/canvas/use-image.d.ts +4 -0
  26. package/canvas/use-image.js +1 -0
  27. package/canvas/video-element.js +1 -1
  28. package/canvas/workspace-canvas.d.ts +3 -1
  29. package/canvas/workspace-canvas.js +1 -1
  30. package/canvas/workspace-style.d.ts +4 -0
  31. package/canvas/workspace-style.js +1 -1
  32. package/model/crop-mode.d.ts +34 -0
  33. package/model/crop-mode.js +1 -0
  34. package/model/figure-model.d.ts +1 -1
  35. package/model/gif-model.d.ts +3 -1
  36. package/model/group-model.d.ts +21 -8
  37. package/model/image-model.d.ts +3 -1
  38. package/model/image-model.js +1 -1
  39. package/model/line-model.d.ts +1 -1
  40. package/model/page-model.d.ts +23 -10
  41. package/model/shape-model.d.ts +2 -2
  42. package/model/shape-model.js +1 -1
  43. package/model/store.d.ts +236 -97
  44. package/model/store.js +1 -1
  45. package/model/svg-model.d.ts +8 -1
  46. package/model/svg-model.js +1 -1
  47. package/model/table-model.d.ts +1 -1
  48. package/model/text-model.d.ts +1 -1
  49. package/model/video-model.d.ts +3 -1
  50. package/package.json +44 -25
  51. package/polotno.bundle.js +180 -194
  52. package/side-panel/draw-panel.js +1 -1
  53. package/side-panel/select-image.js +1 -1
  54. package/side-panel/select-video.d.ts +6 -2
  55. package/toolbar/image-toolbar.d.ts +7 -2
  56. package/toolbar/image-toolbar.js +1 -1
  57. package/toolbar/svg-toolbar.js +1 -1
  58. package/toolbar/toolbar.js +1 -1
  59. package/utils/base64.d.ts +1 -1
  60. package/utils/clipboard.d.ts +2 -2
  61. package/utils/fonts.d.ts +1 -0
  62. package/utils/fonts.js +1 -1
  63. package/utils/html2canvas.js +1 -1
  64. package/utils/l10n.d.ts +4 -0
  65. package/utils/l10n.js +1 -1
  66. package/utils/path-to-svg.d.ts +0 -2
  67. package/utils/path-to-svg.js +1 -1
  68. package/utils/px.d.ts +1 -0
  69. package/utils/px.js +1 -1
  70. package/utils/rich-text-html.d.ts +0 -10
  71. package/utils/rich-text-html.js +1 -1
  72. package/utils/validate-key.js +1 -1
@@ -203,7 +203,7 @@ export declare const TYPES_MAP: {
203
203
  } & {
204
204
  readonly locked: boolean;
205
205
  readonly a: import("./shape-model.js").AnimatedAttrs;
206
- animated(attr: any): any;
206
+ animated(attr: string): any;
207
207
  readonly timeRange: {
208
208
  start: number;
209
209
  end: number;
@@ -217,6 +217,13 @@ export declare const TYPES_MAP: {
217
217
  } & {
218
218
  replaceColor(oldColor: any, newColor: any): void;
219
219
  resetColors(): void;
220
+ } & {
221
+ toggleCropMode(flag?: boolean): void;
222
+ cancelCropMode(): void;
223
+ beforeDestroy(): void;
224
+ } & {
225
+ readonly _cropModeEnabled: boolean;
226
+ readonly _cropEnabled: boolean;
220
227
  }, any, import("mobx-state-tree").ModelSnapshotType<{
221
228
  id: import("mobx-state-tree").ISimpleType<string>;
222
229
  type: import("mobx-state-tree").IType<string | undefined, string, string>;
@@ -384,7 +391,7 @@ export declare const TYPES_MAP: {
384
391
  } & {
385
392
  readonly locked: boolean;
386
393
  readonly a: import("./shape-model.js").AnimatedAttrs;
387
- animated(attr: any): any;
394
+ animated(attr: string): any;
388
395
  readonly timeRange: {
389
396
  start: number;
390
397
  end: number;
@@ -554,7 +561,7 @@ export declare const TYPES_MAP: {
554
561
  } & {
555
562
  readonly locked: boolean;
556
563
  readonly a: import("./shape-model.js").AnimatedAttrs;
557
- animated(attr: any): any;
564
+ animated(attr: string): any;
558
565
  readonly timeRange: {
559
566
  start: number;
560
567
  end: number;
@@ -567,9 +574,11 @@ export declare const TYPES_MAP: {
567
574
  setFilter(type: any, value: any): void;
568
575
  } & {
569
576
  toggleCropMode(flag?: boolean): void;
577
+ cancelCropMode(): void;
570
578
  beforeDestroy(): void;
571
579
  } & {
572
580
  readonly _cropModeEnabled: boolean;
581
+ readonly _cropEnabled: boolean;
573
582
  }, import("mobx-state-tree").ModelCreationType<{
574
583
  id: string;
575
584
  type: string | undefined;
@@ -728,7 +737,7 @@ export declare const TYPES_MAP: {
728
737
  } & {
729
738
  readonly locked: boolean;
730
739
  readonly a: import("./shape-model.js").AnimatedAttrs;
731
- animated(attr: any): any;
740
+ animated(attr: string): any;
732
741
  readonly timeRange: {
733
742
  start: number;
734
743
  end: number;
@@ -912,7 +921,7 @@ export declare const TYPES_MAP: {
912
921
  } & {
913
922
  readonly locked: boolean;
914
923
  readonly a: import("./shape-model.js").AnimatedAttrs;
915
- animated(attr: any): any;
924
+ animated(attr: string): any;
916
925
  readonly timeRange: {
917
926
  start: number;
918
927
  end: number;
@@ -925,9 +934,11 @@ export declare const TYPES_MAP: {
925
934
  setFilter(type: any, value: any): void;
926
935
  } & {
927
936
  toggleCropMode(flag?: boolean): void;
937
+ cancelCropMode(): void;
928
938
  beforeDestroy(): void;
929
939
  } & {
930
940
  readonly _cropModeEnabled: boolean;
941
+ readonly _cropEnabled: boolean;
931
942
  }, import("mobx-state-tree").ModelCreationType<{
932
943
  id: string;
933
944
  type: string | undefined;
@@ -1085,7 +1096,7 @@ export declare const TYPES_MAP: {
1085
1096
  } & {
1086
1097
  readonly locked: boolean;
1087
1098
  readonly a: import("./shape-model.js").AnimatedAttrs;
1088
- animated(attr: any): any;
1099
+ animated(attr: string): any;
1089
1100
  readonly timeRange: {
1090
1101
  start: number;
1091
1102
  end: number;
@@ -1266,7 +1277,7 @@ export declare const TYPES_MAP: {
1266
1277
  } & {
1267
1278
  readonly locked: boolean;
1268
1279
  readonly a: import("./shape-model.js").AnimatedAttrs;
1269
- animated(attr: any): any;
1280
+ animated(attr: string): any;
1270
1281
  readonly timeRange: {
1271
1282
  start: number;
1272
1283
  end: number;
@@ -1279,9 +1290,11 @@ export declare const TYPES_MAP: {
1279
1290
  setFilter(type: any, value: any): void;
1280
1291
  } & {
1281
1292
  toggleCropMode(flag?: boolean): void;
1293
+ cancelCropMode(): void;
1282
1294
  beforeDestroy(): void;
1283
1295
  } & {
1284
1296
  readonly _cropModeEnabled: boolean;
1297
+ readonly _cropEnabled: boolean;
1285
1298
  }, import("mobx-state-tree").ModelCreationType<{
1286
1299
  id: string;
1287
1300
  type: string | undefined;
@@ -1588,7 +1601,7 @@ export declare const TYPES_MAP: {
1588
1601
  } & {
1589
1602
  readonly locked: boolean;
1590
1603
  readonly a: import("./shape-model.js").AnimatedAttrs;
1591
- animated(attr: any): any;
1604
+ animated(attr: string): any;
1592
1605
  readonly timeRange: {
1593
1606
  start: number;
1594
1607
  end: number;
@@ -142,7 +142,7 @@ export declare const ImageElement: import("mobx-state-tree").IModelType<{
142
142
  } & {
143
143
  readonly locked: boolean;
144
144
  readonly a: import("./shape-model.js").AnimatedAttrs;
145
- animated(attr: any): any;
145
+ animated(attr: string): any;
146
146
  readonly timeRange: {
147
147
  start: number;
148
148
  end: number;
@@ -155,9 +155,11 @@ export declare const ImageElement: import("mobx-state-tree").IModelType<{
155
155
  setFilter(type: any, value: any): void;
156
156
  } & {
157
157
  toggleCropMode(flag?: boolean): void;
158
+ cancelCropMode(): void;
158
159
  beforeDestroy(): void;
159
160
  } & {
160
161
  readonly _cropModeEnabled: boolean;
162
+ readonly _cropEnabled: boolean;
161
163
  }, import("mobx-state-tree").ModelCreationType<{
162
164
  id: string;
163
165
  type: string | undefined;
@@ -1 +1 @@
1
- import{observable as e}from"mobx";import{Shape as o}from"./shape-model.js";export const ImageElement=o.named("Image").props({type:"image",width:100,height:100,src:"",cropX:0,cropY:0,cropWidth:1,cropHeight:1,cornerRadius:0,flipX:!1,flipY:!1,clipSrc:"",borderColor:"black",borderSize:0,keepRatio:!1,stretchEnabled:!1}).extend(o=>{const r=e.box(!1);let t=!1;return{views:{get _cropModeEnabled(){return r.get()}},actions:{toggleCropMode(e){var n;const i=null!=e?e:!r.get();r.set(i);const s=null===(n=o.store)||void 0===n?void 0:n.history;s&&(i&&!t?(s.startTransaction(),t=!0):!i&&t&&(s.endTransaction(),t=!1))},beforeDestroy(){t&&(o.store.history.endTransaction(),t=!1)}}}});
1
+ import{Shape as e}from"./shape-model.js";import{cropMode as r}from"./crop-mode.js";export const ImageElement=e.named("Image").props({type:"image",width:100,height:100,src:"",cropX:0,cropY:0,cropWidth:1,cropHeight:1,cornerRadius:0,flipX:!1,flipY:!1,clipSrc:"",borderColor:"black",borderSize:0,keepRatio:!1,stretchEnabled:!1}).extend(r);
@@ -133,7 +133,7 @@ export declare const LineElement: import("mobx-state-tree").IModelType<{
133
133
  } & {
134
134
  readonly locked: boolean;
135
135
  readonly a: import("./shape-model.js").AnimatedAttrs;
136
- animated(attr: any): any;
136
+ animated(attr: string): any;
137
137
  readonly timeRange: {
138
138
  start: number;
139
139
  end: number;
@@ -147,7 +147,7 @@ export declare const Page: import("mobx-state-tree").IModelType<{
147
147
  } & {
148
148
  readonly locked: boolean;
149
149
  readonly a: import("./shape-model.js").AnimatedAttrs;
150
- animated(attr: any): any;
150
+ animated(attr: string): any;
151
151
  readonly timeRange: {
152
152
  start: number;
153
153
  end: number;
@@ -161,6 +161,13 @@ export declare const Page: import("mobx-state-tree").IModelType<{
161
161
  } & {
162
162
  replaceColor(oldColor: any, newColor: any): void;
163
163
  resetColors(): void;
164
+ } & {
165
+ toggleCropMode(flag?: boolean): void;
166
+ cancelCropMode(): void;
167
+ beforeDestroy(): void;
168
+ } & {
169
+ readonly _cropModeEnabled: boolean;
170
+ readonly _cropEnabled: boolean;
164
171
  }, any, import("mobx-state-tree").ModelSnapshotType<{
165
172
  id: import("mobx-state-tree").ISimpleType<string>;
166
173
  type: import("mobx-state-tree").IType<string | undefined, string, string>;
@@ -327,7 +334,7 @@ export declare const Page: import("mobx-state-tree").IModelType<{
327
334
  } & {
328
335
  readonly locked: boolean;
329
336
  readonly a: import("./shape-model.js").AnimatedAttrs;
330
- animated(attr: any): any;
337
+ animated(attr: string): any;
331
338
  readonly timeRange: {
332
339
  start: number;
333
340
  end: number;
@@ -496,7 +503,7 @@ export declare const Page: import("mobx-state-tree").IModelType<{
496
503
  } & {
497
504
  readonly locked: boolean;
498
505
  readonly a: import("./shape-model.js").AnimatedAttrs;
499
- animated(attr: any): any;
506
+ animated(attr: string): any;
500
507
  readonly timeRange: {
501
508
  start: number;
502
509
  end: number;
@@ -509,9 +516,11 @@ export declare const Page: import("mobx-state-tree").IModelType<{
509
516
  setFilter(type: any, value: any): void;
510
517
  } & {
511
518
  toggleCropMode(flag?: boolean): void;
519
+ cancelCropMode(): void;
512
520
  beforeDestroy(): void;
513
521
  } & {
514
522
  readonly _cropModeEnabled: boolean;
523
+ readonly _cropEnabled: boolean;
515
524
  }, import("mobx-state-tree").ModelCreationType<{
516
525
  id: string;
517
526
  type: string | undefined;
@@ -668,7 +677,7 @@ export declare const Page: import("mobx-state-tree").IModelType<{
668
677
  } & {
669
678
  readonly locked: boolean;
670
679
  readonly a: import("./shape-model.js").AnimatedAttrs;
671
- animated(attr: any): any;
680
+ animated(attr: string): any;
672
681
  readonly timeRange: {
673
682
  start: number;
674
683
  end: number;
@@ -851,7 +860,7 @@ export declare const Page: import("mobx-state-tree").IModelType<{
851
860
  } & {
852
861
  readonly locked: boolean;
853
862
  readonly a: import("./shape-model.js").AnimatedAttrs;
854
- animated(attr: any): any;
863
+ animated(attr: string): any;
855
864
  readonly timeRange: {
856
865
  start: number;
857
866
  end: number;
@@ -864,9 +873,11 @@ export declare const Page: import("mobx-state-tree").IModelType<{
864
873
  setFilter(type: any, value: any): void;
865
874
  } & {
866
875
  toggleCropMode(flag?: boolean): void;
876
+ cancelCropMode(): void;
867
877
  beforeDestroy(): void;
868
878
  } & {
869
879
  readonly _cropModeEnabled: boolean;
880
+ readonly _cropEnabled: boolean;
870
881
  }, import("mobx-state-tree").ModelCreationType<{
871
882
  id: string;
872
883
  type: string | undefined;
@@ -1023,7 +1034,7 @@ export declare const Page: import("mobx-state-tree").IModelType<{
1023
1034
  } & {
1024
1035
  readonly locked: boolean;
1025
1036
  readonly a: import("./shape-model.js").AnimatedAttrs;
1026
- animated(attr: any): any;
1037
+ animated(attr: string): any;
1027
1038
  readonly timeRange: {
1028
1039
  start: number;
1029
1040
  end: number;
@@ -1203,7 +1214,7 @@ export declare const Page: import("mobx-state-tree").IModelType<{
1203
1214
  } & {
1204
1215
  readonly locked: boolean;
1205
1216
  readonly a: import("./shape-model.js").AnimatedAttrs;
1206
- animated(attr: any): any;
1217
+ animated(attr: string): any;
1207
1218
  readonly timeRange: {
1208
1219
  start: number;
1209
1220
  end: number;
@@ -1216,9 +1227,11 @@ export declare const Page: import("mobx-state-tree").IModelType<{
1216
1227
  setFilter(type: any, value: any): void;
1217
1228
  } & {
1218
1229
  toggleCropMode(flag?: boolean): void;
1230
+ cancelCropMode(): void;
1219
1231
  beforeDestroy(): void;
1220
1232
  } & {
1221
1233
  readonly _cropModeEnabled: boolean;
1234
+ readonly _cropEnabled: boolean;
1222
1235
  }, import("mobx-state-tree").ModelCreationType<{
1223
1236
  id: string;
1224
1237
  type: string | undefined;
@@ -1524,7 +1537,7 @@ export declare const Page: import("mobx-state-tree").IModelType<{
1524
1537
  } & {
1525
1538
  readonly locked: boolean;
1526
1539
  readonly a: import("./shape-model.js").AnimatedAttrs;
1527
- animated(attr: any): any;
1540
+ animated(attr: string): any;
1528
1541
  readonly timeRange: {
1529
1542
  start: number;
1530
1543
  end: number;
@@ -1724,7 +1737,7 @@ export declare const Page: import("mobx-state-tree").IModelType<{
1724
1737
  } & {
1725
1738
  readonly locked: boolean;
1726
1739
  readonly a: import("./shape-model.js").AnimatedAttrs;
1727
- animated(attr: any): any;
1740
+ animated(attr: string): any;
1728
1741
  readonly timeRange: {
1729
1742
  start: number;
1730
1743
  end: number;
@@ -1861,7 +1874,7 @@ export declare const Page: import("mobx-state-tree").IModelType<{
1861
1874
  } & {
1862
1875
  readonly locked: boolean;
1863
1876
  readonly a: import("./shape-model.js").AnimatedAttrs;
1864
- animated(attr: any): any;
1877
+ animated(attr: string): any;
1865
1878
  readonly timeRange: {
1866
1879
  start: number;
1867
1880
  end: number;
@@ -16,7 +16,7 @@ export declare const Animation: import("mobx-state-tree").IModelType<{
16
16
  name: import("mobx-state-tree").IType<string | undefined, string, string>;
17
17
  data: import("mobx-state-tree").IType<{} | null | undefined, {}, {}>;
18
18
  }, {}, import("mobx-state-tree")._NotCustomized, import("mobx-state-tree")._NotCustomized>;
19
- export declare const getDiff: (obj1: Record<string, any>, obj2: Record<string, any>) => Record<string, any>;
19
+ export declare const getDiff: (obj1: Record<string, unknown>, obj2: Record<string, unknown>) => Record<string, number>;
20
20
  export declare const ShapeFilter: import("mobx-state-tree").IModelType<{
21
21
  intensity: import("mobx-state-tree").IType<number | undefined, number, number>;
22
22
  }, {}, import("mobx-state-tree")._NotCustomized, import("mobx-state-tree")._NotCustomized>;
@@ -147,7 +147,7 @@ export declare const Shape: import("mobx-state-tree").IModelType<{
147
147
  } & {
148
148
  readonly locked: boolean;
149
149
  readonly a: AnimatedAttrs;
150
- animated(attr: any): any;
150
+ animated(attr: string): any;
151
151
  readonly timeRange: {
152
152
  start: number;
153
153
  end: number;
@@ -1 +1 @@
1
- import{types as e,isAlive as t}from"mobx-state-tree";import{animate as i}from"../utils/animations.js";import{observable as n,action as o}from"mobx";import{Node as a}from"./node-model.js";import{getElementTimeRange as r,getPlayheadLocalTime as s}from"../utils/timeline.js";export const Animation=e.model("Animation",{delay:0,duration:500,enabled:!0,type:e.enumeration("Type",["enter","exit","loop"]),name:"none",data:e.frozen({})});export const getDiff=(e,t)=>{const i={};for(const n in t){if("number"==typeof e[n]&&"number"==typeof t[n]){const o=t[n]-e[n];0!==o&&(i[n]=o)}}return i};export const ShapeFilter=e.model("ShapeFilter",{intensity:1});export const INDEPENDENT_FILTERS=["temperature","contrast","highlights","shadows","white","black","saturation","vibrance"];export const Shape=a.named("Shape").props({x:0,y:0,width:100,height:100,rotation:0,opacity:1,animations:e.array(Animation),blurEnabled:!1,blurRadius:10,brightnessEnabled:!1,brightness:0,sepiaEnabled:!1,grayscaleEnabled:!1,filters:e.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(e=>{const t=Object.assign(Object.assign({},e),{x:"x"in e&&e.x||0,y:"y"in e&&e.y||0,filters:"filters"in e?Array.isArray(e.filters)?{}:e.filters:void 0});return"width"in e&&(t.width=t.width||1),"height"in e&&(t.height=t.height||1),"locked"in e&&e.locked&&(t.draggable=!1,t.contentEditable=!1,t.styleEditable=!1,t.resizable=!1,t.removable=!1),t}).views(e=>{var a,l,d,c,p,u;const f=["x","y","width","height","rotation","opacity","color","fontSize","cropX","cropY","cropWidth","cropHeight"],m=e,h={x:null!==(a=m.x)&&void 0!==a?a:0,y:null!==(l=m.y)&&void 0!==l?l:0,width:null!==(d=m.width)&&void 0!==d?d:0,height:null!==(c=m.height)&&void 0!==c?c:0,rotation:null!==(p=m.rotation)&&void 0!==p?p:0,opacity:null!==(u=m.opacity)&&void 0!==u?u:1};for(const t of f){t in e&&(h[t]=m[t])}const g=n(h),b=o(e=>{for(const t in e){g[t]=e[t]}}),y=o(e=>{Object.assign(g,e)}),E=o(e=>{for(const t in e){"number"==typeof g[t]&&(g[t]=g[t]+e[t])}});return{get locked(){return!(e.draggable||e.contentEditable||e.styleEditable||e.resizable)},get a(){if(!t(e)){return g}const n={};for(const e in g){n[e]=m[e]}b(n);const o=s(e);if(null===o){return g}const a=e.store.isEditingPaused&&this.isSelected,r=e.store.animatedElementsIds;if(r.length&&!r.includes(e.id)){return g}const l=e.animations.find(e=>"enter"===e.type),d=(null==l?void 0:l.enabled)&&o<l.delay;d&&y({opacity:0});const c=(null==l?void 0:l.enabled)&&o>=l.delay&&o<=l.delay+l.duration;if(c&&!a){const t=o-l.delay,n=i({element:e,animation:l,dTime:t}),a=getDiff(e,n);E(a)}const p=e.animations.find(e=>"exit"===e.type);if(!d&&!c&&(null==p?void 0:p.enabled)&&o>=e.page.duration-p.duration-p.delay&&o<=e.page.duration-p.delay&&!a){const t=o-(e.page.duration-p.duration-p.delay),n=i({element:e,animation:p,dTime:t}),a=getDiff(e,n);E(a)}(null==p?void 0:p.enabled)&&o>=e.page.duration-p.delay&&y({opacity:0});const u=e.animations.find(e=>"loop"===e.type);if((null==u?void 0:u.enabled)&&!a){const t=i({element:e,animation:u,dTime:o}),n=getDiff(e,t);E(n)}return g},animated(e){return this.a[e]},get timeRange(){return t(e)&&e.page?r(e.animations,e.page.duration):{start:0,end:0}},get active(){if(!t(e)){return!0}const i=s(e);if(null===i){return!0}const{start:n,end:o}=this.timeRange;return i>=n&&i<o},get isSelected(){return!!t(e)&&e.store.selectedShapes.indexOf(e)>=0&&e.selectable},get isSelectedDirectly(){return!!t(e)&&e.store.selectedElements.indexOf(e)>=0&&e.selectable}}}).actions(e=>({setAnimation(t,i){const n=e.animations.find(e=>e.type===t);n?Object.assign(n,i):e.animations.push(Object.assign({type:t},i))},setFilter(t,i){INDEPENDENT_FILTERS.includes(t)||e.filters.forEach((t,i)=>{INDEPENDENT_FILTERS.includes(i.toString())||e.filters.delete(i.toString())}),null==i?e.filters.delete(t):e.filters.set(t,{intensity:i})}}));
1
+ import{types as e,isAlive as t}from"mobx-state-tree";import{animate as n}from"../utils/animations.js";import{computed as i}from"mobx";import{Node as o}from"./node-model.js";import{getElementTimeRange as a,getPlayheadLocalTime as r}from"../utils/timeline.js";export const Animation=e.model("Animation",{delay:0,duration:500,enabled:!0,type:e.enumeration("Type",["enter","exit","loop"]),name:"none",data:e.frozen({})});export const getDiff=(e,t)=>{const n={};for(const i in t){if("number"==typeof e[i]&&"number"==typeof t[i]){const o=t[i]-e[i];0!==o&&(n[i]=o)}}return n};export const ShapeFilter=e.model("ShapeFilter",{intensity:1});export const INDEPENDENT_FILTERS=["temperature","contrast","highlights","shadows","white","black","saturation","vibrance"];export const Shape=o.named("Shape").props({x:0,y:0,width:100,height:100,rotation:0,opacity:1,animations:e.array(Animation),blurEnabled:!1,blurRadius:10,brightnessEnabled:!1,brightness:0,sepiaEnabled:!1,grayscaleEnabled:!1,filters:e.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(e=>{const t=Object.assign(Object.assign({},e),{x:"x"in e&&e.x||0,y:"y"in e&&e.y||0,filters:"filters"in e?Array.isArray(e.filters)?{}:e.filters:void 0});return"width"in e&&(t.width=t.width||1),"height"in e&&(t.height=t.height||1),"locked"in e&&e.locked&&(t.draggable=!1,t.contentEditable=!1,t.styleEditable=!1,t.resizable=!1,t.removable=!1),t}).views(e=>{var o,s,l,d,c,u;const f=["x","y","width","height","rotation","opacity","color","fontSize","cropX","cropY","cropWidth","cropHeight"],p=e,m={x:null!==(o=p.x)&&void 0!==o?o:0,y:null!==(s=p.y)&&void 0!==s?s:0,width:null!==(l=p.width)&&void 0!==l?l:0,height:null!==(d=p.height)&&void 0!==d?d:0,rotation:null!==(c=p.rotation)&&void 0!==c?c:0,opacity:null!==(u=p.opacity)&&void 0!==u?u:1};for(const t of f){t in e&&(m[t]=p[t])}const b=i(()=>{if(!t(e)){return m}const i=Object.assign({},m);for(const e in i){i[e]=p[e]}const o=r(e);if(null===o){return i}const a=e.store.isEditingPaused&&e.isSelected,s=e.store.animatedElementsIds;if(s.length&&!s.includes(e.id)){return i}const l=e.animations.find(e=>"enter"===e.type),d=(null==l?void 0:l.enabled)&&o<l.delay;d&&(i.opacity=0);const c=(null==l?void 0:l.enabled)&&o>=l.delay&&o<=l.delay+l.duration;if(c&&!a){const t=o-l.delay,a=n({element:e,animation:l,dTime:t}),r=getDiff(p,a);for(const e in r){const t=i[e];"number"==typeof t&&(i[e]=t+r[e])}}const u=e.animations.find(e=>"exit"===e.type);if(!d&&!c&&(null==u?void 0:u.enabled)&&o>=e.page.duration-u.duration-u.delay&&o<=e.page.duration-u.delay&&!a){const t=o-(e.page.duration-u.duration-u.delay),a=n({element:e,animation:u,dTime:t}),r=getDiff(p,a);for(const e in r){const t=i[e];"number"==typeof t&&(i[e]=t+r[e])}}(null==u?void 0:u.enabled)&&o>=e.page.duration-u.delay&&(i.opacity=0);const f=e.animations.find(e=>"loop"===e.type);if((null==f?void 0:f.enabled)&&!a){const t=n({element:e,animation:f,dTime:o}),a=getDiff(p,t);for(const e in a){const t=i[e];"number"==typeof t&&(i[e]=t+a[e])}}return i}),g={};for(const t in m){const e=i(()=>b.get()[t]);Object.defineProperty(g,t,{enumerable:!0,get:()=>e.get()})}return{get locked(){return!(e.draggable||e.contentEditable||e.styleEditable||e.resizable)},get a(){return g},animated(e){return this.a[e]},get timeRange(){return t(e)&&e.page?a(e.animations,e.page.duration):{start:0,end:0}},get active(){if(!t(e)){return!0}const n=r(e);if(null===n){return!0}const{start:i,end:o}=this.timeRange;return n>=i&&n<o},get isSelected(){return!!t(e)&&e.store.selectedShapes.indexOf(e)>=0&&e.selectable},get isSelectedDirectly(){return!!t(e)&&e.store.selectedElements.indexOf(e)>=0&&e.selectable}}}).actions(e=>({setAnimation(t,n){const i=e.animations.find(e=>e.type===t);i?Object.assign(i,n):e.animations.push(Object.assign({type:t},n))},setFilter(t,n){INDEPENDENT_FILTERS.includes(t)||e.filters.forEach((t,n)=>{INDEPENDENT_FILTERS.includes(n.toString())||e.filters.delete(n.toString())}),null==n?e.filters.delete(t):e.filters.set(t,{intensity:n})}}));