polotno 4.18.0 → 4.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/blueprint/side-panel/select-video.d.ts +18 -16
  2. package/canvas/animated-shadow.d.ts +11 -0
  3. package/canvas/animated-shadow.js +1 -0
  4. package/canvas/apply-filters.d.ts +5 -1
  5. package/canvas/apply-filters.js +1 -1
  6. package/canvas/downscale.js +1 -1
  7. package/canvas/element.js +1 -1
  8. package/canvas/figure-element.js +1 -1
  9. package/canvas/gif-element.js +1 -1
  10. package/canvas/html-element.js +1 -1
  11. package/canvas/image-element.d.ts +1 -0
  12. package/canvas/image-element.js +1 -1
  13. package/canvas/line-element.js +1 -1
  14. package/canvas/page.js +1 -1
  15. package/canvas/render-tag-element.js +1 -1
  16. package/canvas/rich-editor.d.ts +2 -0
  17. package/canvas/rich-editor.js +8 -5
  18. package/canvas/text-element.js +1 -1
  19. package/canvas/use-animated-blur.d.ts +4 -0
  20. package/canvas/use-animated-blur.js +1 -0
  21. package/canvas/use-color.d.ts +1 -1
  22. package/canvas/use-filtered-source.js +1 -1
  23. package/canvas/use-offscreen-canvas.d.ts +2 -0
  24. package/canvas/use-offscreen-canvas.js +1 -0
  25. package/canvas/use-transformer-snap.js +1 -1
  26. package/canvas/video-element.js +1 -1
  27. package/icons/animation-icons.d.ts +30 -7
  28. package/icons/animation-icons.js +1 -1
  29. package/icons/registry.d.ts +22 -0
  30. package/icons/registry.js +1 -1
  31. package/image-tools/raster.js +1 -1
  32. package/model/figure-model.d.ts +10 -9
  33. package/model/gif-model.d.ts +10 -9
  34. package/model/group-model.d.ts +78 -72
  35. package/model/group-model.js +1 -1
  36. package/model/history.d.ts +3 -0
  37. package/model/history.js +1 -1
  38. package/model/image-model.d.ts +10 -9
  39. package/model/line-model.d.ts +10 -9
  40. package/model/node-model.d.ts +8 -8
  41. package/model/page-model.d.ts +228 -207
  42. package/model/shape-model.d.ts +15 -9
  43. package/model/shape-model.js +1 -1
  44. package/model/store.d.ts +29 -19
  45. package/model/store.js +1 -1
  46. package/model/svg-model.d.ts +9 -8
  47. package/model/table-model.d.ts +8 -7
  48. package/model/text-model.d.ts +9 -8
  49. package/model/video-model.d.ts +10 -9
  50. package/package.json +21 -19
  51. package/pages-timeline/element-track.js +1 -1
  52. package/pages-timeline/page-preview.js +1 -1
  53. package/polotno.bundle.js +181 -163
  54. package/side-panel/animations-panel.js +1 -1
  55. package/side-panel/select-video.d.ts +18 -16
  56. package/toolbar/animations-picker.js +1 -1
  57. package/toolbar/use-copy-style.d.ts +1 -0
  58. package/toolbar/use-copy-style.js +1 -1
  59. package/ui.css +1 -1
  60. package/utils/animations.d.ts +212 -10
  61. package/utils/animations.js +1 -1
  62. package/utils/clipboard.d.ts +17 -15
  63. package/utils/clipboard.js +1 -1
  64. package/utils/fonts.js +1 -1
  65. package/utils/image-edit.js +1 -1
  66. package/utils/l10n.d.ts +44 -0
  67. package/utils/l10n.js +1 -1
  68. package/utils/px.d.ts +1 -0
  69. package/utils/px.js +1 -1
  70. package/utils/timeline.d.ts +3 -1
  71. package/utils/timeline.js +1 -1
  72. package/utils/validate-key.js +1 -1
@@ -1,4 +1,40 @@
1
+ import type { IMSTArray, SnapshotIn, SnapshotOut } from 'mobx-state-tree';
2
+ import { type TextPresetName } from '@polotno/core/animation-presets';
3
+ import type { Animation } from '../model/shape-model.js';
4
+ export type WipeBand = {
5
+ axis: 'x' | 'y';
6
+ from: number;
7
+ to: number;
8
+ };
9
+ export declare const KEN_BURNS_ZOOM = 0.15;
10
+ export declare const KEN_BURNS_PAN: Record<string, {
11
+ x: number;
12
+ y: number;
13
+ }>;
14
+ export declare const glowColor: (element: {
15
+ type: string;
16
+ shadowEnabled: boolean;
17
+ shadowColor: string;
18
+ fill?: unknown;
19
+ color?: unknown;
20
+ }) => string;
21
+ export declare const hasNumber: (html: string) => boolean;
1
22
  export declare const animations: {
23
+ kenBurns: ({ dTime, element, animation }: {
24
+ dTime: any;
25
+ element: any;
26
+ animation: any;
27
+ }) => {
28
+ cropX: any;
29
+ cropY: any;
30
+ cropWidth: number;
31
+ cropHeight: number;
32
+ };
33
+ cameraZoom: ({ dTime, element, animation }: {
34
+ dTime: any;
35
+ element: any;
36
+ animation: any;
37
+ }) => any;
2
38
  none: () => {};
3
39
  fade: ({ dTime, element, animation }: {
4
40
  dTime: any;
@@ -29,26 +65,192 @@ export declare const animations: {
29
65
  dTime: any;
30
66
  element: any;
31
67
  animation: any;
32
- }) => {};
68
+ }) => {
69
+ fontSize?: number | undefined;
70
+ x: number;
71
+ y: number;
72
+ width: number;
73
+ height: number;
74
+ };
33
75
  move: ({ dTime, element, animation }: {
34
76
  dTime: any;
35
77
  element: any;
36
78
  animation: any;
37
- }) => {};
79
+ }) => {
80
+ x: any;
81
+ y: any;
82
+ };
38
83
  zoom: ({ dTime, element, animation }: {
39
84
  dTime: any;
40
85
  element: any;
41
86
  animation: any;
42
- }) => {};
43
- cameraZoom: ({ dTime, element, animation }: {
87
+ }) => {
88
+ fontSize?: number | undefined;
89
+ x: number;
90
+ y: number;
91
+ width: number;
92
+ height: number;
93
+ };
94
+ pop: ({ dTime, element, animation }: {
44
95
  dTime: any;
45
96
  element: any;
46
97
  animation: any;
47
- }) => any;
98
+ }) => {
99
+ opacity: number;
100
+ fontSize?: number | undefined;
101
+ x: number;
102
+ y: number;
103
+ width: number;
104
+ height: number;
105
+ };
106
+ rise: ({ dTime, element, animation }: {
107
+ dTime: any;
108
+ element: any;
109
+ animation: any;
110
+ }) => {
111
+ y: any;
112
+ opacity: number;
113
+ };
114
+ flip: ({ dTime, animation }: {
115
+ dTime: any;
116
+ animation: any;
117
+ }) => {
118
+ flipScale: number;
119
+ };
120
+ growTurn: ({ dTime, element, animation }: {
121
+ dTime: any;
122
+ element: any;
123
+ animation: any;
124
+ }) => {
125
+ opacity: number;
126
+ rotation: number;
127
+ x: number;
128
+ y: number;
129
+ width: number;
130
+ height: number;
131
+ };
132
+ pulse: ({ dTime, element, animation }: {
133
+ dTime: any;
134
+ element: any;
135
+ animation: any;
136
+ }) => {
137
+ fontSize?: number | undefined;
138
+ x: number;
139
+ y: number;
140
+ width: number;
141
+ height: number;
142
+ };
143
+ float: ({ dTime, element, animation }: {
144
+ dTime: any;
145
+ element: any;
146
+ animation: any;
147
+ }) => {
148
+ y: number;
149
+ };
150
+ shake: ({ dTime, element, animation }: {
151
+ dTime: any;
152
+ element: any;
153
+ animation: any;
154
+ }) => {
155
+ x: any;
156
+ };
157
+ wipe: ({ dTime, animation }: {
158
+ dTime: any;
159
+ animation: any;
160
+ }) => {
161
+ wipe: WipeBand;
162
+ };
163
+ glow: ({ dTime, element, animation }: {
164
+ dTime: any;
165
+ element: any;
166
+ animation: any;
167
+ }) => {
168
+ shadowEnabled: boolean;
169
+ shadowColor: string;
170
+ shadowOffsetX: number;
171
+ shadowOffsetY: number;
172
+ shadowBlur: number;
173
+ shadowOpacity: number;
174
+ };
175
+ blur: ({ dTime, element, animation }: {
176
+ dTime: any;
177
+ element: any;
178
+ animation: any;
179
+ }) => {
180
+ blurEnabled: boolean;
181
+ blurRadius: any;
182
+ opacity: number;
183
+ };
184
+ count: ({ dTime, element, animation }: {
185
+ dTime: any;
186
+ element: any;
187
+ animation: any;
188
+ }) => {
189
+ text?: undefined;
190
+ } | {
191
+ text: string;
192
+ };
193
+ };
194
+ export declare const isBuiltIn: (name: string) => boolean;
195
+ type TimedAnimation = {
196
+ type: string;
197
+ name: string;
198
+ duration: number;
199
+ easing?: string;
200
+ };
201
+ type TweenArgs = {
202
+ element: object;
203
+ dTime: number;
204
+ animation: TimedAnimation;
205
+ };
206
+ export type TextUnitsFrame = {
207
+ animation: TimedAnimation & {
208
+ name: TextPresetName;
209
+ data?: {
210
+ strength?: number;
211
+ };
212
+ };
213
+ dTime: number;
214
+ };
215
+ export declare const playsTextUnits: (element: object, animation: {
216
+ type: string;
217
+ name: string;
218
+ }) => boolean;
219
+ export declare const textUnitState: ({ animation, dTime }: TextUnitsFrame, index: number, count: number) => {
220
+ opacity: number;
221
+ y: number;
222
+ scale: number;
223
+ blur: number;
224
+ from: number;
225
+ to: number;
226
+ };
227
+ export type AnimationAttrs = Omit<SnapshotIn<typeof Animation>, 'type'>;
228
+ export declare function setAnimationOf(animations: IMSTArray<typeof Animation>, type: 'enter' | 'exit' | 'loop', attrs: AnimationAttrs): void;
229
+ export type PreviewedAnimation = SnapshotOut<typeof Animation>;
230
+ type PlayedElement = {
231
+ id: string;
232
+ page: {
233
+ duration: number;
234
+ };
235
+ animations: readonly PreviewedAnimation[];
236
+ store?: {
237
+ _animationPreview: Record<string, PreviewedAnimation[]> | null;
238
+ };
239
+ };
240
+ export declare const playedAnimations: (element: PlayedElement) => readonly PreviewedAnimation[];
241
+ export declare const spansElementTime: (name: string) => boolean;
242
+ export declare const loopWindow: (element: PlayedElement, loop: PreviewedAnimation, played: readonly PreviewedAnimation[]) => {
243
+ start: number;
244
+ animation: {
245
+ duration: number;
246
+ delay: number;
247
+ enabled: boolean;
248
+ type: "exit" | "enter" | "loop";
249
+ name: string;
250
+ data: {};
251
+ easing: string | undefined;
252
+ };
48
253
  };
49
- export declare const animate: ({ element, dTime, animation }: {
50
- element: any;
51
- dTime: any;
52
- animation: any;
53
- }) => any;
254
+ export declare const animate: ({ element, dTime, animation }: TweenArgs) => any;
54
255
  export declare const registerAnimation: (name: string, animation: any) => void;
256
+ export {};
@@ -1 +1 @@
1
- import{rotateAroundCenter as t}from"./math.js";const o={right:{from:{x:-200},to:{x:0}},left:{from:{x:200},to:{x:0}},up:{from:{y:200},to:{y:0}},down:{from:{y:-200},to:{y:0}},"bottom-right":{from:{x:-200,y:-200},to:{x:0,y:0}},"bottom-left":{from:{x:200,y:-200},to:{x:0,y:0}},"top-right":{from:{x:-200,y:200},to:{x:0,y:0}},"top-left":{from:{x:200,y:200},to:{x:0,y:0}}},i={right:{cropX:-1},left:{cropX:1},up:{cropY:1},down:{cropY:-1}};export const animations={none:()=>({}),fade:({dTime:t,element:o,animation:i})=>{const n=t/i.duration;return"enter"===i.type?{opacity:n*o.opacity}:{opacity:(1-n)*o.opacity}},rotate:({dTime:o,element:i,animation:n})=>{const e=o/n.duration*360;return t({x:i.x,y:i.y,width:i.width,height:i.height,rotation:i.rotation},e)},blink:({dTime:t,element:o,animation:i})=>{const n=i.duration,e=t%n/(n/2),a=e<=1?e:2-e;return{opacity:o.opacity*a}},bounce:({dTime:t,element:o,animation:i})=>{var n;const e=i.duration,a=e/2,r=null!==(n=i.data.strength)&&void 0!==n?n:1,h={},m={x:o.x+o.width/3*r,y:o.y+o.height/3*r,width:o.width/3*r,height:o.height/3*r,fontSize:o.fontSize/3*r},c={x:o.x,y:o.y,width:o.width,height:o.height,fontSize:o.fontSize},d=t%e/a,p=d<=1?d:2-d;for(let s in m){const t=m[s],o=c[s]-t;h[s]=t+p*o}return h},move:({dTime:t,element:i,animation:n})=>{var e;const a=o[n.data.direction]||o.right,r=null!==(e=n.data.strength)&&void 0!==e?e:1,h={};for(var m in a.from){let o=a.from[m],e=a.to[m];"exit"===n.type&&(o=a.to[m],e=-a.from[m]),o*=r,e*=r;const c=i[m]+o,d=i[m]+e-c;h[m]=c+t/n.duration*d}return h},zoom:({dTime:t,element:o,animation:i})=>{var n;const e={},a=1+(("in"===(i.data.direction||"in")?3/4:5/4)-1)*(null!==(n=i.data.strength)&&void 0!==n?n:1),r=o.rotation*Math.PI/180,h=Math.cos(r),m=Math.sin(r),c=o.width*(1-a),d=o.height*(1-a),p=(c*h-d*m)/2,s=(c*m+d*h)/2,l={x:o.x+p,y:o.y+s,width:o.width*a,height:o.height*a,fontSize:o.fontSize*a},y={x:o.x,y:o.y,width:o.width,height:o.height,fontSize:o.fontSize};for(var f in l){let o=l[f],n=y[f];if("exit"===i.type){const t=o;o=n,n=t}const a=n-o;e[f]=o+t/i.duration*a}return e},cameraZoom:({dTime:t,element:o,animation:n})=>{var e,a,r;const h={},m=n.data.direction||"right",c=i[m]||i.right,d=null!==(e=n.data.movementStrength)&&void 0!==e?e:.1,p=null!==(a=n.data.shakeStrength)&&void 0!==a?a:.015;let s=null!==(r=n.data.zoomStrength)&&void 0!==r?r:.6;const l=t/n.duration,y=p*(1-l),f=Math.sin(12*l)*y*.7+Math.sin(8*l)*y*.3;if("exit"===n.type){const t=Math.max(o.cropWidth||1,o.cropHeight||1);s=Math.min(s,1-t)}n.type;const x=1-Math.pow(1-l,2),g=o.cropX||0,u=o.cropY||0,w=o.cropWidth||1,M=o.cropHeight||1,v=w,S=M;let z,T,X=0,Y=0;if(c.cropX){const t=c.cropX>0?1-(g+w):g;X=Math.min(t,Math.abs(d))*c.cropX}if(c.cropY){const t=c.cropY>0?1-(u+M):u;Y=Math.min(t,Math.abs(d))*c.cropY}return"enter"===n.type?(z=c.cropX?g+X*(1-x):g,T=c.cropY?u+Y*(1-x):u):(z=c.cropX?g+X*x:g,T=c.cropY?u+Y*x:u),h.cropX=Math.max(0,Math.min(1-v,z+f*v)),h.cropY=Math.max(0,Math.min(1-S,T+f*S)),h.cropWidth=v,h.cropHeight=S,h}};export const animate=({element:t,dTime:o,animation:i})=>{const n=animations[i.name];return n?n({element:t,dTime:o,animation:i}):(console.error("Can not find animation type: "+i.name),{})};export const registerAnimation=(t,o)=>{animations[t]&&console.warn(`Animation "${t}" already exists and will be overridden`),animations[t]=o};
1
+ import{EASINGS as t,recommendedEasing as n,resolveEasing as e}from"@polotno/core/easing";import{bounceScale as o,MOVE_OFFSETS as i,zoomStart as a,POP_FADE as r,PULSE_AMOUNT as s,GROW_TURN_ANGLE as l,GROW_TURN_SCALE as d,TEXT_BLUR as c,TEXT_PRESETS as m,TEXT_RISE as p,TEXT_WAVE as u,TRAVEL as h,isTextPreset as g,shakeSwing as x,textLoopStart as y,textUnitTiming as v}from"@polotno/core/animation-presets";import{firstStopColor as f}from"@polotno/core/gradient";import{getCropRect as b}from"@polotno/core/image";import{flags as w}from"./flags.js";import{degToRad as M,rotateAroundCenter as T}from"./math.js";import{getElementTimeRange as O}from"./timeline.js";const j={right:{axis:"x",forward:!0},left:{axis:"x",forward:!1},down:{axis:"y",forward:!0},up:{axis:"y",forward:!1}},S=t=>{var n,e,o,i;const a=null!==(e=null===(n=t.page)||void 0===n?void 0:n.computedWidth)&&void 0!==e?e:0,r=null!==(i=null===(o=t.page)||void 0===o?void 0:o.computedHeight)&&void 0!==i?i:0;return a>0&&r>0?Math.min(a,r):Math.max(t.width,t.height)};export const KEN_BURNS_ZOOM=.15;export const KEN_BURNS_PAN={right:{x:1,y:0},left:{x:-1,y:0},up:{x:0,y:-1},down:{x:0,y:1}};export const glowColor=t=>{if(t.shadowEnabled||"black"!==t.shadowColor){return t.shadowColor}const n="line"===t.type?t.color:t.fill;return"string"==typeof n?f(n):"#000000"};const B=(t,n)=>(1-Math.cos(2*Math.PI*t/n))/2,E=(t,n)=>{const e=t%n/(n/2);return e<=1?e:2-e},X=(t,{type:n,duration:e})=>"exit"===n?1-t/e:t/e,Y=t=>Math.min(1,Math.max(0,t)),k=(t,n)=>{const e=M(t.rotation),o=Math.cos(e),i=Math.sin(e),a=t.width*(1-n),r=t.height*(1-n);return Object.assign({x:t.x+(a*o-r*i)/2,y:t.y+(a*i+r*o)/2,width:t.width*n,height:t.height*n},void 0===t.fontSize?{}:{fontSize:t.fontSize*n})},N=/\d+(?:[.,]\d+)*/,W=t=>{var n,e;const o=[...new Set(null!==(n=t.match(/[.,]/g))&&void 0!==n?n:[])],i=Math.max(t.lastIndexOf("."),t.lastIndexOf(",")),a=t.length-i-1,r=i>=0&&(o.length>1||3!==a),s=r?t[i]:"",l=null!==(e=o.find(t=>t!==s))&&void 0!==e?e:"",d=r?a:0,c=(l?t.split(l).join(""):t).replace(s||".",".");return{value:parseFloat(c),write:t=>{const[n,e]=t.toFixed(d).split("."),o=l?n.replace(/\B(?=(\d{3})+(?!\d))/g,l):n;return e?o+s+e:o}}},I=(t,n)=>{const e=t.split(/(<[^>]*>|&[#\w]+;)/);for(let o=0;o<e.length;o++){if(e[o].startsWith("<")||e[o].startsWith("&")){continue}const t=N.exec(e[o]);if(!t){continue}const{value:i,write:a}=W(t[0]);return e[o]=e[o].slice(0,t.index)+a(n(i))+e[o].slice(t.index+t[0].length),e.join("")}return null};export const hasNumber=t=>null!==I(t,t=>t);const U={right:{cropX:-1},left:{cropX:1},up:{cropY:1},down:{cropY:-1}},_=Object.fromEntries(Object.entries(m).map(([t,{like:n}])=>[t,t=>animations[n](t)]));export const animations=Object.assign(Object.assign({none:()=>({}),fade:({dTime:t,element:n,animation:e})=>{const o=t/e.duration;return"enter"===e.type?{opacity:o*n.opacity}:{opacity:(1-o)*n.opacity}},rotate:({dTime:t,element:n,animation:e})=>{const o=t/e.duration*360;return T({x:n.x,y:n.y,width:n.width,height:n.height,rotation:n.rotation},o)},blink:({dTime:t,element:n,animation:e})=>({opacity:n.opacity*(1-E(t,e.duration))}),bounce:({dTime:t,element:n,animation:e})=>{var i;const a=o(null!==(i=e.data.strength)&&void 0!==i?i:1);return k(n,1-(1-a)*E(t,e.duration))},move:({dTime:t,element:n,animation:e})=>{var o;const a=i[e.data.direction]||i.right,r=null!==(o=e.data.strength)&&void 0!==o?o:1,s=("exit"===e.type?-1:1)*S(n)*h.move*r*(1-X(t,e));return{x:n.x+a.x*s,y:n.y+a.y*s}},zoom:({dTime:t,element:n,animation:e})=>{var o;const i=a(e.data.direction,null!==(o=e.data.strength)&&void 0!==o?o:1),r=X(t,e);return k(n,i+(1-i)*r)},pop:({dTime:t,element:n,animation:e})=>{var o;const i=null!==(o=e.data.strength)&&void 0!==o?o:1,a=Math.max(0,1-i),s=X(t,e);return Object.assign(Object.assign({},k(n,a+(1-a)*s)),{opacity:n.opacity*Y(s/r)})},rise:({dTime:t,element:n,animation:e})=>{var o;const i=null!==(o=e.data.strength)&&void 0!==o?o:1,a=S(n)*h.rise*i,r=X(t,e),s="exit"===e.type?-1:1;return{y:n.y+s*a*(1-r),opacity:n.opacity*r}},flip:({dTime:t,animation:n})=>({flipScale:Math.cos(Math.PI*(1-X(t,n)))}),growTurn:({dTime:t,element:n,animation:e})=>{var o;const i=null!==(o=e.data.strength)&&void 0!==o?o:1,a="exit"===e.type,r=X(t,e),s=k(n,d+(1-d)*r),c=(a?1:-1)*l*i*(1-r);return Object.assign(Object.assign({},T(Object.assign(Object.assign({},s),{rotation:n.rotation}),c)),{opacity:n.opacity*r})},pulse:({dTime:t,element:n,animation:e})=>{var o;const i=null!==(o=e.data.strength)&&void 0!==o?o:1,a=s*i*B(t,e.duration);return k(n,1+a)},float:({dTime:t,element:n,animation:e})=>{var o;const i=null!==(o=e.data.strength)&&void 0!==o?o:1,a=S(n)*h.float*i;return{y:n.y-a*B(t,e.duration)}},shake:({dTime:t,element:n,animation:e})=>{var o;const i=null!==(o=e.data.strength)&&void 0!==o?o:1,a=t/e.duration%1,r=x(a);return{x:n.x+S(n)*h.shake*i*r}},wipe:({dTime:t,animation:n})=>{const{axis:e,forward:o}=j[n.data.direction]||j.right,i=Y(t/n.duration),a=o?i:1-i;return{wipe:o===("exit"===n.type)?{axis:e,from:a,to:1}:{axis:e,from:0,to:a}}},glow:({dTime:t,element:n,animation:e})=>{var o;const i=null!==(o=e.data.strength)&&void 0!==o?o:1;return{shadowEnabled:!0,shadowColor:glowColor(n),shadowOffsetX:0,shadowOffsetY:0,shadowBlur:.02*S(n)*i,shadowOpacity:B(t,e.duration)}},blur:({dTime:t,element:n,animation:e})=>{var o;const i=null!==(o=e.data.strength)&&void 0!==o?o:1,a=n.blurEnabled?n.blurRadius:0,r=X(t,e);return{blurEnabled:!0,blurRadius:a+20*i*(1-r),opacity:n.opacity*r}},count:({dTime:t,element:n,animation:e})=>{var o;if("string"!=typeof n.text){return{}}const i=Number(null!==(o=e.data.from)&&void 0!==o?o:0),a=X(t,e),r=I(n.text,t=>i+(t-i)*a);return null===r?{}:{text:r}}},_),{kenBurns:({dTime:t,element:n,animation:e})=>{var o,i;const a="out"===e.data.zoom,r=Y(t/e.duration),s=.15*(null!==(o=e.data.strength)&&void 0!==o?o:1)*(a?1-r:r),l=Math.max(.05,1-s),d=null!==(i=KEN_BURNS_PAN[e.data.direction])&&void 0!==i?i:{x:0,y:0},c=a?-1:1,m=n._sourceSize,p=m&&b(n,m),[u,h]=p?[p.width/m.width,p.height/m.height]:[n.cropWidth,n.cropHeight],g=u*l,x=h*l;return{cropX:n.cropX+(u-g)*(1+d.x*c)/2,cropY:n.cropY+(h-x)*(1+d.y*c)/2,cropWidth:g,cropHeight:x}},cameraZoom:({dTime:t,element:n,animation:e})=>{var o,i,a;const r={},s=e.data.direction||"right",l=U[s]||U.right,d=null!==(o=e.data.movementStrength)&&void 0!==o?o:.1,c=null!==(i=e.data.shakeStrength)&&void 0!==i?i:.015;let m=null!==(a=e.data.zoomStrength)&&void 0!==a?a:.6;const p=t/e.duration,u=c*(1-p),h=Math.sin(12*p)*u*.7+Math.sin(8*p)*u*.3;if("exit"===e.type){const t=Math.max(n.cropWidth||1,n.cropHeight||1);m=Math.min(m,1-t)}e.type;const g=1-Math.pow(1-p,2),x=n.cropX||0,y=n.cropY||0,v=n.cropWidth||1,f=n.cropHeight||1,b=v,w=f;let M,T,O=0,j=0;if(l.cropX){const t=l.cropX>0?1-(x+v):x;O=Math.min(t,Math.abs(d))*l.cropX}if(l.cropY){const t=l.cropY>0?1-(y+f):y;j=Math.min(t,Math.abs(d))*l.cropY}return"enter"===e.type?(M=l.cropX?x+O*(1-g):x,T=l.cropY?y+j*(1-g):y):(M=l.cropX?x+O*g:x,T=l.cropY?y+j*g:y),r.cropX=Math.max(0,Math.min(1-b,M+h*b)),r.cropY=Math.max(0,Math.min(1-w,T+h*w)),r.cropWidth=b,r.cropHeight=w,r}});const z=new Map(Object.entries(animations));export const isBuiltIn=t=>z.has(t)&&z.get(t)===animations[t];const A=new Set(["blink","bounce"]),C=(n,o)=>{const i=e(o),a=o.duration;if("linear"===i||!(a>0)){return n}const r=t[i];if("loop"!==o.type){return r(Y(n/a))*a}const s=A.has(o.name)?a/2:a,l=Math.floor(n/s)*s;return l+r((n-l)/s)*s};export const playsTextUnits=(t,n)=>{if(!g(n.name)||!isBuiltIn(n.name)){return!1}const e="loop"in m[n.name];return"loop"===n.type===e&&"type"in t&&"text"===t.type&&!("curveEnabled"in t&&t.curveEnabled)&&w.renderTagTextEnabled};export const textUnitState=({animation:n,dTime:o},i,a)=>{var s,l;const{like:d}=m[n.name],h="loop"===n.type,g="exit"===n.type,x=n.duration,y=g?a-1-i:i,{step:f,span:b}=v(n.name,x,a),w=y*f,M=h&&x>0?o%x:o,T=b>0?Y((M-w)/b):M>=w?1:0,O={opacity:1,y:0,scale:1,blur:0,from:0,to:1};if(h){const t=null!==(l=null===(s=n.data)||void 0===s?void 0:s.strength)&&void 0!==l?l:1;return O.y=-u*t*B(T,1),O}const j=t[e(n)](T),S=g?1-j:j;return O.opacity=Y(S),"wipe"===d?(O.opacity=1,g?O.from=1-Y(S):O.to=Y(S)):"rise"===d?O.y=(g?-1:1)*p*(1-S):"pop"===d?(O.scale=Math.max(0,S),O.opacity=Y(S/r)):"blur"===d&&(O.blur=c*Math.max(0,1-S)),O};export function setAnimationOf(t,e,o){const i=t.find(t=>t.type===e),a=void 0===o.name||o.name===(null==i?void 0:i.name)||"easing"in o?o:Object.assign(Object.assign({},o),{easing:n(e,o.name)});i?Object.assign(i,a):t.push(Object.assign({type:e},a))}export const playedAnimations=t=>{var n,e,o;return null!==(o=null===(e=null===(n=t.store)||void 0===n?void 0:n._animationPreview)||void 0===e?void 0:e[t.id])&&void 0!==o?o:t.animations};export const spansElementTime=t=>"kenBurns"===t&&isBuiltIn(t);export const loopWindow=(t,n,e)=>{if("kenBurns"===(o=n.name)&&isBuiltIn(o)){const{start:o,end:i}=O(e,t.page.duration);return{start:o,animation:Object.assign(Object.assign({},n),{duration:Math.max(1,i-o)})}}var o;return{start:playsTextUnits(t,n)?y(n,e,t.page.duration):n.delay,animation:n}};export const animate=({element:t,dTime:n,animation:e})=>{if(playsTextUnits(t,e)){return{textUnits:{animation:e,dTime:n}}}const o=animations[e.name];return o?o({element:t,dTime:C(n,e),animation:e}):(console.error("Can not find animation type: "+e.name),{})};export const registerAnimation=(t,n)=>{animations[t]&&console.warn(`Animation "${t}" already exists and will be overridden`),animations[t]=n};
@@ -11,7 +11,7 @@ export declare const insertTextElement: (store: StoreType, text: string, extra?:
11
11
  type: import("mobx-state-tree").IType<string | undefined, string, string>;
12
12
  name: import("mobx-state-tree").IType<string | undefined, string, string>;
13
13
  opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
14
- blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "overlay" | "saturation" | "screen" | "soft-light">, [undefined]>;
14
+ blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light">, [undefined]>;
15
15
  custom: import("mobx-state-tree").IType<any, any, any>;
16
16
  visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
17
17
  selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
@@ -32,6 +32,7 @@ export declare const insertTextElement: (store: StoreType, text: string, extra?:
32
32
  type: import("mobx-state-tree").ISimpleType<"exit" | "enter" | "loop">;
33
33
  name: import("mobx-state-tree").IType<string | undefined, string, string>;
34
34
  data: import("mobx-state-tree").IType<{} | null | undefined, {}, {}>;
35
+ easing: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
35
36
  }, {}, import("mobx-state-tree")._NotCustomized, import("mobx-state-tree")._NotCustomized>>;
36
37
  blurEnabled: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
37
38
  blurRadius: import("mobx-state-tree").IType<number | undefined, number, number>;
@@ -99,7 +100,7 @@ export declare const insertTextElement: (store: StoreType, text: string, extra?:
99
100
  type: import("mobx-state-tree").IType<string | undefined, string, string>;
100
101
  name: import("mobx-state-tree").IType<string | undefined, string, string>;
101
102
  opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
102
- blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "overlay" | "saturation" | "screen" | "soft-light">, [undefined]>;
103
+ blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light">, [undefined]>;
103
104
  custom: import("mobx-state-tree").IType<any, any, any>;
104
105
  visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
105
106
  selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
@@ -111,7 +112,7 @@ export declare const insertTextElement: (store: StoreType, text: string, extra?:
111
112
  type: import("mobx-state-tree").IType<string | undefined, string, string>;
112
113
  name: import("mobx-state-tree").IType<string | undefined, string, string>;
113
114
  opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
114
- blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "overlay" | "saturation" | "screen" | "soft-light">, [undefined]>;
115
+ blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light">, [undefined]>;
115
116
  custom: import("mobx-state-tree").IType<any, any, any>;
116
117
  visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
117
118
  selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
@@ -123,7 +124,7 @@ export declare const insertTextElement: (store: StoreType, text: string, extra?:
123
124
  type: string | undefined;
124
125
  name: string | undefined;
125
126
  opacity: number | undefined;
126
- blendMode: "normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "overlay" | "saturation" | "screen" | "soft-light" | undefined;
127
+ blendMode: "normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light" | undefined;
127
128
  custom: any;
128
129
  visible: boolean | undefined;
129
130
  selectable: boolean | undefined;
@@ -142,7 +143,7 @@ export declare const insertTextElement: (store: StoreType, text: string, extra?:
142
143
  alwaysOnTop: boolean;
143
144
  showInExport: boolean;
144
145
  } | {
145
- blendMode: "normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "overlay" | "saturation" | "screen" | "soft-light";
146
+ blendMode: "normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light";
146
147
  id: string;
147
148
  type: string;
148
149
  name: string;
@@ -170,7 +171,7 @@ export declare const insertTextElement: (store: StoreType, text: string, extra?:
170
171
  alwaysOnTop: boolean;
171
172
  showInExport: boolean;
172
173
  } | {
173
- blendMode: "normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "overlay" | "saturation" | "screen" | "soft-light";
174
+ blendMode: "normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light";
174
175
  id: string;
175
176
  type: string;
176
177
  name: string;
@@ -205,7 +206,7 @@ export declare const insertTextElement: (store: StoreType, text: string, extra?:
205
206
  readonly isSelected: boolean;
206
207
  readonly isSelectedDirectly: boolean;
207
208
  } & {
208
- setAnimation(type: any, attrs: any): void;
209
+ setAnimation(type: "enter" | "exit" | "loop", attrs: import("./animations.js").AnimationAttrs): void;
209
210
  setFilter(type: any, value: any): void;
210
211
  } & {
211
212
  set(attrs: any): void;
@@ -216,7 +217,7 @@ export declare const insertTextElement: (store: StoreType, text: string, extra?:
216
217
  type: import("mobx-state-tree").IType<string | undefined, string, string>;
217
218
  name: import("mobx-state-tree").IType<string | undefined, string, string>;
218
219
  opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
219
- blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "overlay" | "saturation" | "screen" | "soft-light">, [undefined]>;
220
+ blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light">, [undefined]>;
220
221
  custom: import("mobx-state-tree").IType<any, any, any>;
221
222
  visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
222
223
  selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
@@ -237,6 +238,7 @@ export declare const insertTextElement: (store: StoreType, text: string, extra?:
237
238
  type: import("mobx-state-tree").ISimpleType<"exit" | "enter" | "loop">;
238
239
  name: import("mobx-state-tree").IType<string | undefined, string, string>;
239
240
  data: import("mobx-state-tree").IType<{} | null | undefined, {}, {}>;
241
+ easing: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
240
242
  }, {}, import("mobx-state-tree")._NotCustomized, import("mobx-state-tree")._NotCustomized>>;
241
243
  blurEnabled: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
242
244
  blurRadius: import("mobx-state-tree").IType<number | undefined, number, number>;
@@ -304,7 +306,7 @@ export declare const insertTextElement: (store: StoreType, text: string, extra?:
304
306
  type: import("mobx-state-tree").IType<string | undefined, string, string>;
305
307
  name: import("mobx-state-tree").IType<string | undefined, string, string>;
306
308
  opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
307
- blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "overlay" | "saturation" | "screen" | "soft-light">, [undefined]>;
309
+ blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light">, [undefined]>;
308
310
  custom: import("mobx-state-tree").IType<any, any, any>;
309
311
  visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
310
312
  selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
@@ -316,7 +318,7 @@ export declare const insertTextElement: (store: StoreType, text: string, extra?:
316
318
  type: import("mobx-state-tree").IType<string | undefined, string, string>;
317
319
  name: import("mobx-state-tree").IType<string | undefined, string, string>;
318
320
  opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
319
- blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "overlay" | "saturation" | "screen" | "soft-light">, [undefined]>;
321
+ blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light">, [undefined]>;
320
322
  custom: import("mobx-state-tree").IType<any, any, any>;
321
323
  visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
322
324
  selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
@@ -328,7 +330,7 @@ export declare const insertTextElement: (store: StoreType, text: string, extra?:
328
330
  type: string | undefined;
329
331
  name: string | undefined;
330
332
  opacity: number | undefined;
331
- blendMode: "normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "overlay" | "saturation" | "screen" | "soft-light" | undefined;
333
+ blendMode: "normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light" | undefined;
332
334
  custom: any;
333
335
  visible: boolean | undefined;
334
336
  selectable: boolean | undefined;
@@ -347,7 +349,7 @@ export declare const insertTextElement: (store: StoreType, text: string, extra?:
347
349
  alwaysOnTop: boolean;
348
350
  showInExport: boolean;
349
351
  } | {
350
- blendMode: "normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "overlay" | "saturation" | "screen" | "soft-light";
352
+ blendMode: "normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light";
351
353
  id: string;
352
354
  type: string;
353
355
  name: string;
@@ -375,7 +377,7 @@ export declare const insertTextElement: (store: StoreType, text: string, extra?:
375
377
  alwaysOnTop: boolean;
376
378
  showInExport: boolean;
377
379
  } | {
378
- blendMode: "normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "overlay" | "saturation" | "screen" | "soft-light";
380
+ blendMode: "normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light";
379
381
  id: string;
380
382
  type: string;
381
383
  name: string;
@@ -410,7 +412,7 @@ export declare const insertTextElement: (store: StoreType, text: string, extra?:
410
412
  readonly isSelected: boolean;
411
413
  readonly isSelectedDirectly: boolean;
412
414
  } & {
413
- setAnimation(type: any, attrs: any): void;
415
+ setAnimation(type: "enter" | "exit" | "loop", attrs: import("./animations.js").AnimationAttrs): void;
414
416
  setFilter(type: any, value: any): void;
415
417
  } & {
416
418
  set(attrs: any): void;
@@ -428,7 +430,7 @@ export declare const insertTextElement: (store: StoreType, text: string, extra?:
428
430
  alwaysOnTop: boolean;
429
431
  showInExport: boolean;
430
432
  } | {
431
- blendMode: "normal" | "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "overlay" | "saturation" | "screen" | "soft-light";
433
+ blendMode: "normal" | "color" | "overlay" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "saturation" | "screen" | "soft-light";
432
434
  id: string;
433
435
  type: string;
434
436
  name: string;
@@ -1 +1 @@
1
- import{forEveryChild as e}from"../model/group-model.js";import{nanoid as t}from"nanoid";import{getTotalClientRect as o}from"./math.js";import{removeTags as a}from"@polotno/core/text";import{insertFileIntoPage as r}from"./insert-file.js";import{decodeBase64 as l,encodeBase64 as n}from"./base64.js";let i={data:[],pageId:"",payloadId:""};const d="polotno_clipboard",s=(e,t,o)=>{i={data:JSON.parse(JSON.stringify(e)),pageId:t||"",payloadId:o||""};try{localStorage.setItem(d,JSON.stringify(e)),localStorage.setItem(d+"_page",t||""),localStorage.setItem(d+"_payload",o||"")}catch(a){}},c=()=>{try{const e=localStorage.getItem(d),t=localStorage.getItem(d+"_page"),o=localStorage.getItem(d+"_payload");if(e){return{data:JSON.parse(e),pageId:t,payloadId:o}}}catch(e){}return i},p="data-polotno-clipboard";export const copy=e=>{var t;0!==e.selectedElements.length&&s(e.selectedElements.map(e=>e.toJSON()),null===(t=e.activePage)||void 0===t?void 0:t.id)};export const cut=e=>{if(0===e.selectedElements.length){return}copy(e);const t=e.selectedElements.filter(e=>e.removable).map(e=>e.id);e.deleteElements(t)};const m=(t,a)=>{t.history.transaction(()=>{var r,l;let n=0,i=0;const{data:d,pageId:c,payloadId:p}=a;if(c===(null===(r=t.activePage)||void 0===r?void 0:r.id)){n=t.width/20,i=t.height/20}else{const a=[];e({children:d},e=>{"group"!==e.type&&a.push(e)});const r=o(a);r.maxX>t.width&&(n=-r.minX),r.maxY>t.height&&(i=-r.minY)}const m=[];e({children:d},e=>{delete e.id,"group"!==e.type&&(e.x+=n,e.y+=i)}),d.forEach(e=>{var o;const a=null===(o=t.activePage)||void 0===o?void 0:o.addElement(e);a&&m.push(a.id)}),s(d,null===(l=t.activePage)||void 0===l?void 0:l.id,p),t.selectElements(m)})};export const paste=e=>{m(e,c())};export const isClipboardEmpty=()=>0===c().data.length;export const resetClipboard=()=>{i={data:[],pageId:"",payloadId:""};try{localStorage.removeItem(d),localStorage.removeItem(d+"_page"),localStorage.removeItem(d+"_payload")}catch(e){}};export const copyToEvent=(o,r)=>{var l,i;if(!r.clipboardData||0===o.selectedElements.length){return!1}const d=o.selectedElements.map(e=>e.toJSON()),c=t(),m={v:1,id:c,pageId:(null===(l=o.activePage)||void 0===l?void 0:l.id)||"",elements:d};r.clipboardData.setData("text/html",`<div ${p}="${(e=>n((new TextEncoder).encode(JSON.stringify(e))))(m)}"></div>`);const g=[];return e({children:d},e=>{"text"===e.type&&g.push(a(e.text))}),r.clipboardData.setData("text/plain",g.join("\n")||" "),r.preventDefault(),s(d,null===(i=o.activePage)||void 0===i?void 0:i.id,c),!0};export const cutToEvent=(e,t)=>{const o=copyToEvent(e,t);if(o){const t=e.selectedElements.filter(e=>e.removable).map(e=>e.id);e.deleteElements(t)}return o};export const insertTextElement=(e,t,o={})=>{var a;const r=e.width/2,l=(e.width+e.height)/2160;return null===(a=e.activePage)||void 0===a?void 0:a.addElement(Object.assign({type:"text",x:e.width/2-r/2,y:e.height/2-15,width:r,fontSize:30*l,text:t},o))};export const pasteFromEvent=(e,t,o={})=>{const a=t.clipboardData;if(!a){return!1}const n=a.getData("text/html");if(n&&n.includes(p)){const o=(e=>{var o;try{const t=null===(o=(new DOMParser).parseFromString(e,"text/html").querySelector(`[${p}]`))||void 0===o?void 0:o.getAttribute(p);if(!t){return null}const a=JSON.parse((new TextDecoder).decode(l(t)));return Array.isArray(a.elements)?a:null}catch(t){return null}})(n);if(o){t.preventDefault();const a=c();return o.id&&o.id===a.payloadId?m(e,a):m(e,{data:o.elements,pageId:o.pageId,payloadId:o.id}),!0}}const i=a.files?Array.from(a.files):[];if(i.length>0){return t.preventDefault(),(async()=>{for(const o of i){try{await r({file:o,store:e})}catch(t){console.error("polotno: failed to insert pasted file",t)}}})(),!0}const d=a.getData("text/plain");if(d&&d.trim()){if(t.preventDefault(),o.onText){o.onText(d)}else{const t=insertTextElement(e,(e=>e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"))(d));t&&e.selectElements([t.id])}return!0}return 0===a.types.length&&0!==c().data.length&&(t.preventDefault(),paste(e),!0)};
1
+ import{forEveryChild as e}from"../model/group-model.js";import{nanoid as t}from"nanoid";import{getTotalClientRect as a}from"./math.js";import{removeTags as o}from"@polotno/core/text";import{insertFileIntoPage as r}from"./insert-file.js";import{decodeBase64 as l,encodeBase64 as n}from"./base64.js";let i={data:[],pageId:"",payloadId:""};const s="polotno_clipboard",d=(e,t,a)=>{i={data:JSON.parse(JSON.stringify(e)),pageId:t||"",payloadId:a||""};try{localStorage.setItem(s,JSON.stringify(e)),localStorage.setItem(s+"_page",t||""),localStorage.setItem(s+"_payload",a||"")}catch(o){}},c=()=>{try{const e=localStorage.getItem(s),t=localStorage.getItem(s+"_page"),a=localStorage.getItem(s+"_payload");if(e){return{data:JSON.parse(e),pageId:t,payloadId:a}}}catch(e){}return i},p="data-polotno-clipboard";export const copy=e=>{var t;0!==e.selectedElements.length&&d(e.selectedElements.map(e=>e.toJSON()),null===(t=e.activePage)||void 0===t?void 0:t.id)};export const cut=e=>{if(0===e.selectedElements.length){return}copy(e);const t=e.selectedElements.filter(e=>e.removable).map(e=>e.id);e.deleteElements(t)};const m=(t,o)=>{t.history.transaction(()=>{var r,l;let n=0,i=0;const{data:s,pageId:c,payloadId:p}=o;if(c===(null===(r=t.activePage)||void 0===r?void 0:r.id)){n=t.width/20,i=t.height/20}else{const o=[];e({children:s},e=>{"group"!==e.type&&o.push(e)});const r=a(o);r.maxX>t.width&&(n=-r.minX),r.maxY>t.height&&(i=-r.minY)}const m=[];e({children:s},e=>{delete e.id,"group"!==e.type&&(e.x+=n,e.y+=i)}),s.forEach(e=>{var a;const o=null===(a=t.activePage)||void 0===a?void 0:a.addElement(e);o&&m.push(o.id)}),d(s,null===(l=t.activePage)||void 0===l?void 0:l.id,p),t.selectElements(m)})};export const paste=e=>{m(e,c())};export const isClipboardEmpty=()=>0===c().data.length;export const resetClipboard=()=>{i={data:[],pageId:"",payloadId:""};try{localStorage.removeItem(s),localStorage.removeItem(s+"_page"),localStorage.removeItem(s+"_payload")}catch(e){}};export const copyToEvent=(a,r)=>{var l,i;if(!r.clipboardData||0===a.selectedElements.length){return!1}const s=a.selectedElements.map(e=>e.toJSON()),c=t(),m={v:1,id:c,pageId:(null===(l=a.activePage)||void 0===l?void 0:l.id)||"",elements:s};r.clipboardData.setData("text/html",`<div ${p}="${(e=>n((new TextEncoder).encode(JSON.stringify(e))))(m)}"></div>`);const g=[];return e({children:s},e=>{"text"===e.type&&g.push(o(e.text))}),r.clipboardData.setData("text/plain",g.join("\n")||" "),r.preventDefault(),d(s,null===(i=a.activePage)||void 0===i?void 0:i.id,c),!0};export const cutToEvent=(e,t)=>{const a=copyToEvent(e,t);if(a){const t=e.selectedElements.filter(e=>e.removable).map(e=>e.id);e.deleteElements(t)}return a};export const insertTextElement=(e,t,a={})=>{var o;const r=e.width/2,l=(e.width+e.height)/2160;return null===(o=e.activePage)||void 0===o?void 0:o.addElement(Object.assign({type:"text",x:e.width/2-r/2,y:e.height/2-15,width:r,fontSize:30*l,text:t},a))};export const pasteFromEvent=(e,t,a={})=>{const o=t.clipboardData;if(!o){return!1}const n=o.getData("text/html");if(n&&n.includes(p)){const a=(e=>{var a;try{const t=null===(a=(new DOMParser).parseFromString(e,"text/html").querySelector(`[${p}]`))||void 0===a?void 0:a.getAttribute(p);if(!t){return null}const o=JSON.parse((new TextDecoder).decode(l(t)));return Array.isArray(o.elements)?o:null}catch(t){return null}})(n);if(a){t.preventDefault();const o=c();return a.id&&a.id===o.payloadId?m(e,o):m(e,{data:a.elements,pageId:a.pageId,payloadId:a.id}),!0}}const i=o.getData("text/plain"),s=o.files?Array.from(o.files):[];if(0===s.length&&(e=>{if(!/<svg[\s>]/i.test(e)){return!1}const t=(new DOMParser).parseFromString(e.trim(),"image/svg+xml");return"svg"===t.documentElement.localName&&0===t.getElementsByTagName("parsererror").length})(i)&&s.push(new File([i.trim()],"pasted.svg",{type:"image/svg+xml"})),s.length>0){return t.preventDefault(),(async()=>{for(const a of s){try{await r({file:a,store:e})}catch(t){console.error("polotno: failed to insert pasted file",t)}}})(),!0}if(i&&i.trim()){if(t.preventDefault(),a.onText){a.onText(i)}else{const t=insertTextElement(e,(e=>e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"))(i));t&&e.selectElements([t.id])}return!0}return 0===o.types.length&&0!==c().data.length&&(t.preventDefault(),paste(e),!0)};
package/utils/fonts.js CHANGED
@@ -1 +1 @@
1
- import*as A from"mobx";import{triggerLoadError as t,getFontLoadTimeout as o}from"./loader.js";import{polotnoError as e}from"@polotno/core/errors";import{removeTags as n}from"@polotno/core/text";import{decodeBase64 as r}from"./base64.js";import{DEFAULT_RETRIES as s,retryDelayMs as i}from"@polotno/core/retry";import{getGoogleFontsUrl as c,getGoogleFontsVariants as a}from"@polotno/core/google-fonts-url";import{resolveFontFaceStyles as l,googleFontVariantUrl as u,cssFontFamily as f,parseUnicodeRange as d,rangesCover as m,toNumericWeight as p}from"@polotno/core/fonts";export{setGoogleFontsVariants,getGoogleFontsVariants,getGoogleFontsUrl}from"@polotno/core/google-fonts-url";const g=["Roboto","Amatic SC","Press Start 2P","Marck Script","Rubik Mono One"];let h=A.observable([...g]),F=A.observable({value:!1});export function isGoogleFontChanged(){return F.value}export function setGoogleFonts(A){if("default"===A){return h.replace([...g]),void(F.value=!1)}F.value=!0,h.splice(0,h.length),h.push(...A)}export function getFontsList(){return h}export const globalFonts=A.observable([]);export function addGlobalFont(A){globalFonts.push(A)}export function removeGlobalFont(A){const t=globalFonts.findIndex(t=>t.fontFamily===A);-1!==t&&globalFonts.splice(t,1)}export function replaceGlobalFonts(A){globalFonts.replace(A)}const y="BESbswy 0123456789 Il1Ww";function w(A){const t=function(A=""){const t=n(A).replace(/\s+/g," ").trim();return t?Array.from(t).slice(0,10).join(""):""}(A);return t?`${y} ${t}`:y}export function _getFontProbeTextForTesting(A){return w(A)}const b="PolotnoBlank";let x,B;function $(A,t,o,e){null!=B||(B=document.createElement("canvas"));const n=B.getContext("2d");if(!n){return!1}const r=(A,e)=>{n.font=`${t} ${o} 40px ${A}`;const r=n.measureText(e);return r.width>0||r.actualBoundingBoxLeft+r.actualBoundingBoxRight>0};if(r(b,y)){return!1}const s=`${f(A)}, ${b}`;return e.some(A=>r(s,A))}export function measureFontDom(A,t="sans-serif",o="normal",e="normal",n=y){if("undefined"==typeof document||!document.body){return 0}const r=document.createElement("span");r.textContent=n,r.style.cssText=`\n position:absolute;\n visibility:hidden;\n white-space:nowrap;\n top:-9999px;\n left:-9999px;\n font:${o} ${e} 90px ${f(A)}, ${t};\n `,document.body.appendChild(r);const s=r.getBoundingClientRect().width;return r.remove(),s}const E={Arial:!0},v={};export const isFontLoaded=(A,t,o,e)=>{if(t&&o){const n=`${A}_${t}_${o}`;if(!E[n]){return!1}const r=textChars(e),s=v[n];return!![...r].every(A=>null==s?void 0:s.has(A))||function(A,t,o,e){if("undefined"==typeof document||!document.fonts){return!1}const n="italic"===t?"italic":"normal",r=p(o),s=V(A),i=[...e].map(A=>A.codePointAt(0)),c=new Set;let a=!1;for(const u of document.fonts){if(V(u.family)!==s){continue}if(a=!0,u.style!==n){continue}const[A,t=A]=u.weight.split(/\s+/).map(p);if(r<A||r>t){continue}const o=d(u.unicodeRange),e=i.filter(A=>m(o,A));if(e.length){if("loaded"!==u.status){return!1}e.forEach(A=>c.add(A))}}if(a){return i.every(A=>c.has(A))}try{return document.fonts.check(G(A,t,o),e)}catch(l){return!1}}(A,t,o,r)}return Object.keys(E).some(t=>t.startsWith(A+"_"))||!!E[A]};export function _setFontLoadedForTesting(A,t){t?E[A]=!0:delete E[A]}export async function loadFont(A,t,e,n){var r;const s=performance.now()+o();await loadFontFace(A,t,e,n);const i=textChars(n),c=()=>{var o,n;const r=null!==(o=v[n=`${A}_${t}_${e}`])&&void 0!==o?o:v[n]=new Set;for(const A of i){r.add(A)}};if(!i||!(null===(r=document.fonts)||void 0===r?void 0:r.load)){return c()}let a;await Promise.race([document.fonts.load(G(A,t,e),i).catch(()=>{}).then(c),new Promise(A=>{a=setTimeout(A,Math.max(0,s-performance.now()))})]),clearTimeout(a)}const G=(A,t,o)=>`${t} ${o} 16px ${f(A)}`;export function textChars(A){return[...new Set(n(null!=A?A:"").replace(/\s/g,""))].join("")}export async function loadFontFace(A,n,s,c){var a;const l=`${A}_${n}_${s}`;if(injectGoogleFontVariant(A,n,s),E[l]&&!j(A,n,s)){return}const u=!!(null===(a=document.fonts)||void 0===a?void 0:a.load),f=w(c),d=[...textChars(c)];await(null!=x||(x=(async()=>{if("undefined"==typeof FontFace){return}const A=new FontFace(b,r("AAEAAAAKAIAAAwAgT1MvMlHNUusAAACsAAAAYGNtYXAAIQA0AAABDAAAAChnbHlmAAAAAAAAATQAAAAKaGVhZF8WQOUAAAFAAAAANmhoZWEDIf87AAABeAAAACRobXR4AAAAAAAAAZwAAAAIbG9jYQAFAAAAAAGkAAAABm1heHAAAwAAAAABrAAAACBuYW1lCUoZTgAAAcwAAACMcG9zdAADAAAAAAJYAAAAIAAEAAABkAAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQT0xPAEAAAP//AyD/OAAAAyAAyAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAwAKAAAADAANAAAAAAAcAAAAAAAAAAEAAAAAABD//wAAAAEAAAAAAAAAAAAAAAAAAQAAAAEAAAAAAABfDzz1AAMD6AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAgAAAAAAAAABAAADIP84AAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAFAAAAAQAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQANgADAAEECQABABgAAAADAAEECQACAA4AGAADAAEECQAEABgAJgADAAEECQAGABgAPgBQAG8AbABvAHQAbgBvAEIAbABhAG4AawBSAGUAZwB1AGwAYQByAFAAbwBsAG8AdABuAG8AQgBsAGEAbgBrAFAAbwBsAG8AdABuAG8AQgBsAGEAbgBrAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="));document.fonts.add(A),await A.load()})().catch(A=>{console.error("Polotno could not load its blank probe font: no font can be verified as ready.",A)})),x);const m=o()/60;for(let o=0;o<m;o++){const r=!j(A,n,s);let c=[];if(u){try{c=await document.fonts.load(G(A,n,s),f)}catch(p){}}const a=t=>$(A,n,s,t),m=c.length>0&&c.every(A=>"loaded"===A.status);if(r&&(a([f])||m&&a(d))){return void Q(l,A)}if("missing"===T[A]){if(I(A)){const o=`Font "${A}" not found: not registered and no matching Google Font.`;console.error(o),t(e("FONT_FAILED",o,{family:A,reason:"not-found"}))}return}if(A in C&&!C[A]&&"errored"===T[A]&&injectGoogleFont(A),N[A]&&Y(A)){const n=k(A);if("wait"===n){await new Promise(A=>setTimeout(A,60));continue}if("spent"!==n){W(A);const t=i(n);await new Promise(A=>setTimeout(A,t)),o+=Math.ceil(t/60);continue}if(I(A)){const o=`Failed to load font "${A}": its font file could not be fetched.`;console.error(o),t(e("FONT_FAILED",o,{family:A,reason:"fetch-failed"}))}return}await new Promise(A=>setTimeout(A,60))}console.warn(`Timeout for loading font "${A}". Looks like polotno can't load it. Is it a correct font family?`),t(e("FONT_FAILED",`Timeout for loading font "${A}"`,{family:A,reason:"timeout"}))}const C={},T={},D=new Set;function I(A){return!D.has(A)&&(D.add(A),setTimeout(()=>D.delete(A),o()),!0)}function Q(A,t){E[A]=!0,delete T[t],delete P[t]}const P={};function k(A){const t=P[A],e=!t||Date.now()-t.at>o()?0:t.spent;return e>=s-1?"spent":t&&e>0&&Date.now()-t.at<i(e)?"wait":(P[A]={spent:e+1,at:Date.now()},e+1)}const _={};function j(A,t,o){return"loading"===C[A]||"loading"===_[`${A}|${"italic"===t?1:0}|${parseInt(o,10)}`]}export function injectGoogleFontVariant(A,t,o){const e=parseInt(o,10);if(!Number.isFinite(e)){return}if(function(A){const t=new Set;for(const o of a().split(",")){const e=o.trim().match(/^(\d+)(italic|i)?$/);e&&!!e[2]===A&&t.add(parseInt(e[1],10))}return t}("italic"===t).has(e)){return}if(!(A in C)){return}const n="italic"===t,r=`${A}|${n?1:0}|${e}`;if(_[r]){return}_[r]="loading";const s=document.createElement("link");s.type="text/css",s.href=u(A,n,e),s.rel="stylesheet",s.onload=()=>{_[r]=!0},s.onerror=()=>{_[r]=!0,s.remove()},document.getElementsByTagName("head")[0].appendChild(s)}export function injectGoogleFont(A){if(C[A]){return}const t=c(A),o=document.createElement("link");o.type="text/css",o.href=t,o.rel="stylesheet",o.onload=()=>{C[A]=!0},o.onerror=()=>{o.remove(),C[A]=!1,"errored"===T[A]?function(A){T[A]="probing",fetch(c(A),{mode:"no-cors"}).then(()=>{T[A]="missing"}).catch(()=>{delete T[A]})}(A):T[A]||(T[A]="errored")},document.getElementsByTagName("head")[0].appendChild(o),C[A]="loading"}const N={};let R;function S(){return R||(R=document.getElementById("polotno-font-style"),R||(R=document.createElement("style"),R.id="polotno-font-style",document.head.appendChild(R)),R)}function O(A){const t=A.fontFamily,o=l(A),e=S().sheet;return o.map(A=>{const o=e.insertRule(`\n @font-face{\n font-family:${f(t)};\n src:${A.src};\n font-style:${A.fontStyle};\n font-weight:${A.fontWeight};\n font-display:swap; /* optional but recommended */\n }`,e.cssRules.length);return e.cssRules[o]})}export function injectCustomFont(A){const t=A.fontFamily;if(!A.url&&!A.styles){return}const o=JSON.stringify(l(A)),e=N[t];if(e){if(e.src===o){return}L(e.rules),M(t)}delete T[t],N[t]={font:A,src:o,rules:O(A)}}function L(A){const t=S().sheet;for(const o of A){const A=Array.prototype.indexOf.call(t.cssRules,o);A>=0&&t.deleteRule(A)}}export function removeCustomFont(A){const t=N[A];t&&(L(t.rules),delete N[A],M(A))}function M(A){delete P[A];for(const t of Object.keys(E)){(t===A||t.startsWith(A+"_"))&&(delete E[t],delete v[t])}}function W(A){const t=N[A];t&&(L(t.rules),t.rules=O(t.font))}const V=A=>A.trim().replace(/^["']|["']$/g,"").toLowerCase();function Y(A){const t=document.fonts;if(!t||"function"!=typeof t.forEach){return!1}const o=V(A);let e=!1;return t.forEach(A=>{"error"===A.status&&V(A.family)===o&&(e=!0)}),e}
1
+ import*as A from"mobx";import{triggerLoadError as t,getFontLoadTimeout as o}from"./loader.js";import{polotnoError as e}from"@polotno/core/errors";import{removeTags as n}from"@polotno/core/text";import{decodeBase64 as r}from"./base64.js";import{DEFAULT_RETRIES as s,retryDelayMs as i}from"@polotno/core/retry";import{getGoogleFontsUrl as c,getGoogleFontsVariants as a}from"@polotno/core/google-fonts-url";import{resolveFontFaceStyles as l,googleFontVariantUrl as u,cssFontFamily as f,parseUnicodeRange as d,rangesCover as m,toNumericWeight as p}from"@polotno/core/fonts";export{setGoogleFontsVariants,getGoogleFontsVariants,getGoogleFontsUrl}from"@polotno/core/google-fonts-url";const g=["Roboto","Amatic SC","Press Start 2P","Marck Script","Rubik Mono One"];let h=A.observable([...g]),F=A.observable({value:!1});export function isGoogleFontChanged(){return F.value}export function setGoogleFonts(A){if("default"===A){return h.replace([...g]),void(F.value=!1)}F.value=!0,h.splice(0,h.length),h.push(...A)}export function getFontsList(){return h}export const globalFonts=A.observable([]);export function addGlobalFont(A){globalFonts.push(A)}export function removeGlobalFont(A){const t=globalFonts.findIndex(t=>t.fontFamily===A);-1!==t&&globalFonts.splice(t,1)}export function replaceGlobalFonts(A){globalFonts.replace(A)}const y="BESbswy 0123456789 Il1Ww";function w(A){const t=function(A=""){const t=n(A).replace(/\s+/g," ").trim();return t?Array.from(t).slice(0,10).join(""):""}(A);return t?`${y} ${t}`:y}export function _getFontProbeTextForTesting(A){return w(A)}const b="PolotnoBlank";let x,B;function $(A,t,o,e){null!=B||(B=document.createElement("canvas"));const n=B.getContext("2d");if(!n){return!1}const r=(A,e)=>{n.font=`${t} ${o} 40px ${A}`;const r=n.measureText(e);return r.width>0||r.actualBoundingBoxLeft+r.actualBoundingBoxRight>0};if(r(b,y)){return!1}const s=`${f(A)}, ${b}`;return e.some(A=>r(s,A))}export function measureFontDom(A,t="sans-serif",o="normal",e="normal",n=y){if("undefined"==typeof document||!document.body){return 0}const r=document.createElement("span");r.textContent=n,r.style.cssText=`\n position:absolute;\n visibility:hidden;\n white-space:nowrap;\n top:-9999px;\n left:-9999px;\n font:${o} ${e} 90px ${f(A)}, ${t};\n `,document.body.appendChild(r);const s=r.getBoundingClientRect().width;return r.remove(),s}const E={Arial:!0},v={};export const isFontLoaded=(A,t,o,e)=>{if(t&&o){const n=`${A}_${t}_${o}`;if(!E[n]){return!1}const r=textChars(e),s=v[n];return!![...r].every(A=>null==s?void 0:s.has(A))||function(A,t,o,e){if("undefined"==typeof document||!document.fonts){return!1}const n="italic"===t?"italic":"normal",r=p(o),s=V(A),i=[...e].map(A=>A.codePointAt(0)),c=new Set;let a=!1;for(const u of document.fonts){if(V(u.family)!==s){continue}if(a=!0,u.style!==n){continue}const[A,t=A]=u.weight.split(/\s+/).map(p);if(r<A||r>t){continue}const o=d(u.unicodeRange),e=i.filter(A=>m(o,A));if(e.length){if("loaded"!==u.status){return!1}e.forEach(A=>c.add(A))}}if(a){return i.every(A=>c.has(A))}try{return document.fonts.check(G(A,t,o),e)}catch(l){return!1}}(A,t,o,r)}return Object.keys(E).some(t=>t.startsWith(A+"_"))||!!E[A]};export function _setFontLoadedForTesting(A,t){t?E[A]=!0:delete E[A]}export async function loadFont(A,t,e,n){var r;const s=performance.now()+o();await loadFontFace(A,t,e,n);const i=textChars(n),c=()=>{var o,n;const r=null!==(o=v[n=`${A}_${t}_${e}`])&&void 0!==o?o:v[n]=new Set;for(const A of i){r.add(A)}};if(!i||!(null===(r=document.fonts)||void 0===r?void 0:r.load)){return c()}let a;await Promise.race([document.fonts.load(G(A,t,e),i).catch(()=>{}).then(c),new Promise(A=>{a=setTimeout(A,Math.max(0,s-performance.now()))})]),clearTimeout(a)}const G=(A,t,o)=>`${t} ${o} 16px ${f(A)}`;export function textChars(A){return[...new Set(n(null!=A?A:"").replace(/\s/g,""))].join("")}export async function loadFontFace(A,n,s,c){var a;const l=`${A}_${n}_${s}`;if(injectGoogleFontVariant(A,n,s),E[l]&&!j(A,n,s)){return}const u=!!(null===(a=document.fonts)||void 0===a?void 0:a.load),f=w(c),d=[...textChars(c)];await(null!=x||(x=(async()=>{if("undefined"==typeof FontFace){return}const A=new FontFace(b,r("AAEAAAAKAIAAAwAgT1MvMlHNUusAAACsAAAAYGNtYXAAIQA0AAABDAAAAChnbHlmAAAAAAAAATQAAAAKaGVhZF8WQOUAAAFAAAAANmhoZWEDIf87AAABeAAAACRobXR4AAAAAAAAAZwAAAAIbG9jYQAFAAAAAAGkAAAABm1heHAAAwAAAAABrAAAACBuYW1lCUoZTgAAAcwAAACMcG9zdAADAAAAAAJYAAAAIAAEAAABkAAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQT0xPAEAAAP//AyD/OAAAAyAAyAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAwAKAAAADAANAAAAAAAcAAAAAAAAAAEAAAAAABD//wAAAAEAAAAAAAAAAAAAAAAAAQAAAAEAAAAAAABfDzz1AAMD6AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAgAAAAAAAAABAAADIP84AAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAFAAAAAQAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQANgADAAEECQABABgAAAADAAEECQACAA4AGAADAAEECQAEABgAJgADAAEECQAGABgAPgBQAG8AbABvAHQAbgBvAEIAbABhAG4AawBSAGUAZwB1AGwAYQByAFAAbwBsAG8AdABuAG8AQgBsAGEAbgBrAFAAbwBsAG8AdABuAG8AQgBsAGEAbgBrAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="),{weight:"1 1000"});document.fonts.add(A),await A.load()})().catch(A=>{console.error("Polotno could not load its blank probe font: no font can be verified as ready.",A)})),x);const m=o()/60;for(let o=0;o<m;o++){const r=!j(A,n,s);let c=[];if(u){try{c=await document.fonts.load(G(A,n,s),f)}catch(p){}}const a=t=>$(A,n,s,t),m=c.length>0&&c.every(A=>"loaded"===A.status);if(r&&(a([f])||m&&a(d))){return void Q(l,A)}if("missing"===T[A]){if(I(A)){const o=`Font "${A}" not found: not registered and no matching Google Font.`;console.error(o),t(e("FONT_FAILED",o,{family:A,reason:"not-found"}))}return}if(A in C&&!C[A]&&"errored"===T[A]&&injectGoogleFont(A),N[A]&&Y(A)){const n=k(A);if("wait"===n){await new Promise(A=>setTimeout(A,60));continue}if("spent"!==n){W(A);const t=i(n);await new Promise(A=>setTimeout(A,t)),o+=Math.ceil(t/60);continue}if(I(A)){const o=`Failed to load font "${A}": its font file could not be fetched.`;console.error(o),t(e("FONT_FAILED",o,{family:A,reason:"fetch-failed"}))}return}await new Promise(A=>setTimeout(A,60))}console.warn(`Timeout for loading font "${A}". Looks like polotno can't load it. Is it a correct font family?`),t(e("FONT_FAILED",`Timeout for loading font "${A}"`,{family:A,reason:"timeout"}))}const C={},T={},D=new Set;function I(A){return!D.has(A)&&(D.add(A),setTimeout(()=>D.delete(A),o()),!0)}function Q(A,t){E[A]=!0,delete T[t],delete P[t]}const P={};function k(A){const t=P[A],e=!t||Date.now()-t.at>o()?0:t.spent;return e>=s-1?"spent":t&&e>0&&Date.now()-t.at<i(e)?"wait":(P[A]={spent:e+1,at:Date.now()},e+1)}const _={};function j(A,t,o){return"loading"===C[A]||"loading"===_[`${A}|${"italic"===t?1:0}|${parseInt(o,10)}`]}export function injectGoogleFontVariant(A,t,o){const e=parseInt(o,10);if(!Number.isFinite(e)){return}if(function(A){const t=new Set;for(const o of a().split(",")){const e=o.trim().match(/^(\d+)(italic|i)?$/);e&&!!e[2]===A&&t.add(parseInt(e[1],10))}return t}("italic"===t).has(e)){return}if(!(A in C)){return}const n="italic"===t,r=`${A}|${n?1:0}|${e}`;if(_[r]){return}_[r]="loading";const s=document.createElement("link");s.type="text/css",s.href=u(A,n,e),s.rel="stylesheet",s.onload=()=>{_[r]=!0},s.onerror=()=>{_[r]=!0,s.remove()},document.getElementsByTagName("head")[0].appendChild(s)}export function injectGoogleFont(A){if(C[A]){return}const t=c(A),o=document.createElement("link");o.type="text/css",o.href=t,o.rel="stylesheet",o.onload=()=>{C[A]=!0},o.onerror=()=>{o.remove(),C[A]=!1,"errored"===T[A]?function(A){T[A]="probing",fetch(c(A),{mode:"no-cors"}).then(()=>{T[A]="missing"}).catch(()=>{delete T[A]})}(A):T[A]||(T[A]="errored")},document.getElementsByTagName("head")[0].appendChild(o),C[A]="loading"}const N={};let R;function S(){return R||(R=document.getElementById("polotno-font-style"),R||(R=document.createElement("style"),R.id="polotno-font-style",document.head.appendChild(R)),R)}function O(A){const t=A.fontFamily,o=l(A),e=S().sheet;return o.map(A=>{const o=e.insertRule(`\n @font-face{\n font-family:${f(t)};\n src:${A.src};\n font-style:${A.fontStyle};\n font-weight:${A.fontWeight};\n font-display:swap; /* optional but recommended */\n }`,e.cssRules.length);return e.cssRules[o]})}export function injectCustomFont(A){const t=A.fontFamily;if(!A.url&&!A.styles){return}const o=JSON.stringify(l(A)),e=N[t];if(e){if(e.src===o){return}L(e.rules),M(t)}delete T[t],N[t]={font:A,src:o,rules:O(A)}}function L(A){const t=S().sheet;for(const o of A){const A=Array.prototype.indexOf.call(t.cssRules,o);A>=0&&t.deleteRule(A)}}export function removeCustomFont(A){const t=N[A];t&&(L(t.rules),delete N[A],M(A))}function M(A){delete P[A];for(const t of Object.keys(E)){(t===A||t.startsWith(A+"_"))&&(delete E[t],delete v[t])}}function W(A){const t=N[A];t&&(L(t.rules),t.rules=O(t.font))}const V=A=>A.trim().replace(/^["']|["']$/g,"").toLowerCase();function Y(A){const t=document.fonts;if(!t||"function"!=typeof t.forEach){return!1}const o=V(A);let e=!1;return t.forEach(A=>{"error"===A.status&&V(A.family)===o&&(e=!0)}),e}
@@ -1 +1 @@
1
- import{contains as t,matchesAspect as i,UNIT as e,validRect as a}from"../image-tools/geometry.js";import{encodeRaster as h,rasterCanvas as r,withBlobImage as n,WORKING_MAX_SIDE as o}from"../image-tools/raster.js";const s=t=>new TypeError(`Invalid image preparation option: ${t}`),g=()=>new RangeError("The image cannot fit this pixel layout.");function m(t){let i=!1;for(let e=0;e<t.length;e+=4){if(0!==t[e]&&255!==t[e]||t[e]!==t[e+1]||t[e]!==t[e+2]||255!==t[e+3]){throw s("mask")}i||(i=255===t[e])}return i}async function c(t,i,e=!1){return n(t,async t=>{const{canvas:a,ctx:n}=r(i,e?"resize-mask":"resize");if(n.imageSmoothingEnabled=!e,n.drawImage(t,0,0,i.width,i.height),e&&!m(n.getImageData(0,0,i.width,i.height).data)){throw g()}return h(a,"resize")})}export async function prepareImageInput(h,{maxSide:r=o,roundTo:n=1}={}){if(!Number.isInteger(r)||r<=0){throw s("maxSide")}if(!Number.isInteger(n)||n<=0){throw s("roundTo")}if(![h.size.width,h.size.height].every(t=>Number.isSafeInteger(t)&&t>0)){throw s("size")}const m=Math.min(r,o);if(n>m){throw g()}if(h.frame){const r=function(h,r,n,o){if(!a(r)||!t(r,e)){throw s("frame")}const m={width:h.width*r.width,height:h.height*r.height},c=Math.min(1,n/Math.max(m.width,m.height)),d=Math.max(h.width,h.height);for(let t=Math.floor(d*c);t>0;t--){const e=t/d,a={width:Math.floor(h.width*e),height:Math.floor(h.height*e)};if(!a.width||!a.height){break}const s=Math.max(0,Math.round(-r.x*a.width)),g=Math.max(0,Math.round(-r.y*a.height)),c=Math.max(0,Math.round((r.x+r.width-1)*a.width)),w=Math.max(0,Math.round((r.y+r.height-1)*a.height)),f={width:Math.ceil((s+a.width+c)/o)*o,height:Math.ceil((g+a.height+w)/o)*o};if(Math.max(f.width,f.height)<=n&&i(f,m)){return{size:a,canvas:f,padding:{left:s,top:g,right:f.width-s-a.width,bottom:f.height-g-a.height}}}}throw g()}(h.size,h.frame,m,n);return Object.assign(Object.assign({},r),{image:await c(h.image,r.size)})}const d=Math.max(h.size.width,h.size.height),w=Math.min(h.size.width,h.size.height);for(let t=Math.floor(Math.min(m,d)/n)*n;t>0;t-=n){const e=w*t/d,a=[Math.floor(e/n)*n,Math.ceil(e/n)*n].sort((t,i)=>Math.abs(t-e)-Math.abs(i-e));for(const r of a){if(!r||r>w){continue}const e=h.size.width>=h.size.height?{width:t,height:r}:{width:r,height:t};if(!i(e,h.size)){continue}const a=await c(h.image,e);return h.mask?{image:a,size:e,mask:await c(h.mask,e,!0)}:{image:a,size:e}}}throw g()}export async function padImageForFrame(t){const{size:i,padding:e,canvas:a}=t;if(!Object.values(e).every(t=>Number.isInteger(t)&&t>=0)||e.left+i.width+e.right!==a.width||e.top+i.height+e.bottom!==a.height){throw s("padding")}return n(t.image,async t=>{if(t.naturalWidth!==i.width||t.naturalHeight!==i.height){throw s("size")}const{canvas:n,ctx:o}=r(a,"pad");o.drawImage(t,e.left,e.top);const g=r(a,"padding-mask");return g.ctx.fillStyle="white",g.ctx.fillRect(0,0,a.width,a.height),g.ctx.fillStyle="black",g.ctx.fillRect(e.left,e.top,i.width,i.height),{image:await h(n,"pad"),mask:await h(g.canvas,"padding-mask"),size:Object.assign({},a)}})}export async function formatMask(t,{selection:i}){if(!["white","black","transparent"].includes(i)){throw s("selection")}return n(t,async t=>{const{canvas:e,ctx:a}=r({width:t.naturalWidth,height:t.naturalHeight},"format-mask");a.drawImage(t,0,0);const n=a.getImageData(0,0,e.width,e.height),o=n.data;m(o);for(let h=0;h<o.length;h+=4){const t=255===o[h],e="black"===i?t?0:255:o[h];o[h]=o[h+1]=o[h+2]=e,o[h+3]="transparent"===i&&t?0:255}return a.putImageData(n,0,0),h(e,"format-mask")})}
1
+ import{contains as t,matchesAspect as e,UNIT as i,validRect as a}from"../image-tools/geometry.js";import{encodeRaster as h,rasterCanvas as r,withBlobImage as n,WORKING_MAX_SIDE as o}from"../image-tools/raster.js";const s=t=>new TypeError(`Invalid image preparation option: ${t}`),g=()=>new RangeError("The image cannot fit this pixel layout.");function c(t){let e=!1;for(let i=0;i<t.length;i+=4){if(0!==t[i]&&255!==t[i]||t[i]!==t[i+1]||t[i]!==t[i+2]||255!==t[i+3]){throw s("mask")}e||(e=255===t[i])}return e}async function d(t,e){return n(t,async t=>{const{canvas:i,ctx:a}=r(e,"resize");return a.drawImage(t,0,0,e.width,e.height),h(i,"resize")})}const m=1024;async function w(t,e){return n(t,async t=>{const i={width:t.naturalWidth,height:t.naturalHeight},a=(t,e)=>Array.from({length:t},(i,a)=>Math.floor((a+.5)*e/t)),n=a(e.width,i.width),o=a(e.height,i.height),s=(t,e)=>{const i=t.findIndex(t=>t>=e);return i<0?t.length:i},{canvas:d,ctx:w}=r(e,"resize-mask"),f=w.createImageData(e.width,e.height),l=new Uint32Array(f.data.buffer),u=r({width:Math.min(m,i.width),height:Math.min(m,i.height)},"resize-mask");for(let h=0;h<i.height;h+=m){const a=Math.min(m,i.height-h),[r,g]=[s(o,h),s(o,h+a)];for(let c=0;c<i.width;c+=m){const d=Math.min(m,i.width-c),[w,f]=[s(n,c),s(n,c+d)];u.ctx.clearRect(0,0,d,a),u.ctx.drawImage(t,-c,-h);const M=new Uint32Array(u.ctx.getImageData(0,0,d,a).data.buffer);for(let t=r;t<g;t++){for(let i=w;i<f;i++){l[t*e.width+i]=M[(o[t]-h)*d+n[i]-c]}}}}if(!c(f.data)){throw g()}return w.putImageData(f,0,0),h(d,"resize")})}export async function prepareImageInput(h,{maxSide:r=o,roundTo:n=1}={}){if(!Number.isInteger(r)||r<=0){throw s("maxSide")}if(!Number.isInteger(n)||n<=0){throw s("roundTo")}if(![h.size.width,h.size.height].every(t=>Number.isSafeInteger(t)&&t>0)){throw s("size")}const c=Math.min(r,o);if(n>c){throw g()}if(h.frame){const r=function(h,r,n,o){if(!a(r)||!t(r,i)){throw s("frame")}const c={width:h.width*r.width,height:h.height*r.height},d=Math.min(1,n/Math.max(c.width,c.height)),m=Math.max(h.width,h.height);for(let t=Math.floor(m*d);t>0;t--){const i=t/m,a={width:Math.floor(h.width*i),height:Math.floor(h.height*i)};if(!a.width||!a.height){break}const s=Math.max(0,Math.round(-r.x*a.width)),g=Math.max(0,Math.round(-r.y*a.height)),d=Math.max(0,Math.round((r.x+r.width-1)*a.width)),w=Math.max(0,Math.round((r.y+r.height-1)*a.height)),f={width:Math.ceil((s+a.width+d)/o)*o,height:Math.ceil((g+a.height+w)/o)*o};if(Math.max(f.width,f.height)<=n&&e(f,c)){return{size:a,canvas:f,padding:{left:s,top:g,right:f.width-s-a.width,bottom:f.height-g-a.height}}}}throw g()}(h.size,h.frame,c,n);return Object.assign(Object.assign({},r),{image:await d(h.image,r.size)})}const m=Math.max(h.size.width,h.size.height),f=Math.min(h.size.width,h.size.height);for(let t=Math.floor(Math.min(c,m)/n)*n;t>0;t-=n){const i=f*t/m,a=[Math.floor(i/n)*n,Math.ceil(i/n)*n].sort((t,e)=>Math.abs(t-i)-Math.abs(e-i));for(const r of a){if(!r||r>f){continue}const i=h.size.width>=h.size.height?{width:t,height:r}:{width:r,height:t};if(!e(i,h.size)){continue}const a=await d(h.image,i);return h.mask?{image:a,size:i,mask:await w(h.mask,i)}:{image:a,size:i}}}throw g()}export async function padImageForFrame(t){const{size:e,padding:i,canvas:a}=t;if(!Object.values(i).every(t=>Number.isInteger(t)&&t>=0)||i.left+e.width+i.right!==a.width||i.top+e.height+i.bottom!==a.height){throw s("padding")}return n(t.image,async t=>{if(t.naturalWidth!==e.width||t.naturalHeight!==e.height){throw s("size")}const{canvas:n,ctx:o}=r(a,"pad");o.drawImage(t,i.left,i.top);const g=r(a,"padding-mask");return g.ctx.fillStyle="white",g.ctx.fillRect(0,0,a.width,a.height),g.ctx.fillStyle="black",g.ctx.fillRect(i.left,i.top,e.width,e.height),{image:await h(n,"pad"),mask:await h(g.canvas,"padding-mask"),size:Object.assign({},a)}})}export async function formatMask(t,{selection:e}){if(!["white","black","transparent"].includes(e)){throw s("selection")}return n(t,async t=>{const{canvas:i,ctx:a}=r({width:t.naturalWidth,height:t.naturalHeight},"format-mask");a.drawImage(t,0,0);const n=a.getImageData(0,0,i.width,i.height),o=n.data;c(o);for(let h=0;h<o.length;h+=4){const t=255===o[h],i="black"===e?t?0:255:o[h];o[h]=o[h+1]=o[h+2]=i,o[h+3]="transparent"===e&&t?0:255}return a.putImageData(n,0,0),h(i,"format-mask")})}
package/utils/l10n.d.ts CHANGED
@@ -158,6 +158,26 @@ export declare const getTranslations: () => {
158
158
  none: string;
159
159
  bounce: string;
160
160
  blink: string;
161
+ count: string;
162
+ pop: string;
163
+ rise: string;
164
+ flipAnimation: string;
165
+ growTurn: string;
166
+ spinAnimation: string;
167
+ pulse: string;
168
+ float: string;
169
+ shake: string;
170
+ typewriter: string;
171
+ lineRise: string;
172
+ wordRise: string;
173
+ wordFade: string;
174
+ letterPop: string;
175
+ wordBlur: string;
176
+ wipe: string;
177
+ glow: string;
178
+ lineWipe: string;
179
+ letterWave: string;
180
+ kenBurns: string;
161
181
  strength: string;
162
182
  spaceEvenly: string;
163
183
  horizontalDistribution: string;
@@ -313,6 +333,30 @@ export declare const getTranslations: () => {
313
333
  resize: string;
314
334
  layers: string;
315
335
  animate: string;
336
+ animationEnter: string;
337
+ animationBoth: string;
338
+ animationExit: string;
339
+ animationLoop: string;
340
+ animationGeneral: string;
341
+ animationTextPresets: string;
342
+ animationDuration: string;
343
+ animationRepeatEvery: string;
344
+ animationStartAt: string;
345
+ animationEndAt: string;
346
+ animationDirection: string;
347
+ animationDirections: {
348
+ right: string;
349
+ left: string;
350
+ up: string;
351
+ down: string;
352
+ 'bottom-right': string;
353
+ 'bottom-left': string;
354
+ 'top-right': string;
355
+ 'top-left': string;
356
+ none: string;
357
+ };
358
+ zoomIn: string;
359
+ zoomOut: string;
316
360
  layerTypes: {
317
361
  image: string;
318
362
  text: string;