@polotno/schema 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/defaults.d.ts CHANGED
@@ -82,3 +82,6 @@ export declare const MIN_FONT_SIZE = 1;
82
82
  export declare const clampFontSize: <T extends number | undefined>(size: T) => T;
83
83
  export declare const BLEND_MODES: readonly ["normal", "multiply", "screen", "overlay", "darken", "lighten", "color-dodge", "color-burn", "hard-light", "soft-light", "difference", "exclusion", "hue", "saturation", "color", "luminosity"];
84
84
  export declare const GROUP_BLEND_MODES: readonly ["pass-through", "normal", "multiply", "screen", "overlay", "darken", "lighten", "color-dodge", "color-burn", "hard-light", "soft-light", "difference", "exclusion", "hue", "saturation", "color", "luminosity"];
85
+ /** The page size, on both sides, of a design that names none. */
86
+ export declare const DESIGN_SIZE = 1080;
87
+ export declare const ANIMATION_EASINGS: readonly ["linear", "easeIn", "easeOut", "easeInOut", "backIn", "backOut", "backInOut"];
package/lib/defaults.js CHANGED
@@ -148,3 +148,18 @@ export const BLEND_MODES = [
148
148
  ];
149
149
  // A group's default: its children blend through it. Any other mode isolates it.
150
150
  export const GROUP_BLEND_MODES = ['pass-through', ...BLEND_MODES];
151
+ /** The page size, on both sides, of a design that names none. */
152
+ export const DESIGN_SIZE = 1080;
153
+ // The named timing curves an animation's `easing` may hold. The field itself
154
+ // stays a plain string (see the schema), so a curve added here later never
155
+ // crashes an older SDK: it reads an unknown name as missing, which plays
156
+ // linear. A preset's recommended curve is `@polotno/core/easing`'s.
157
+ export const ANIMATION_EASINGS = [
158
+ 'linear',
159
+ 'easeIn',
160
+ 'easeOut',
161
+ 'easeInOut',
162
+ 'backIn',
163
+ 'backOut',
164
+ 'backInOut',
165
+ ];
@@ -3,7 +3,7 @@
3
3
  "type": "object",
4
4
  "properties": {
5
5
  "schemaVersion": {
6
- "default": 4,
6
+ "default": 5,
7
7
  "description": "Schema version for compatibility / migration.",
8
8
  "type": "number"
9
9
  },
@@ -337,6 +337,10 @@
337
337
  "data": {
338
338
  "default": {},
339
339
  "description": "Animation-specific data."
340
+ },
341
+ "easing": {
342
+ "description": "Timing curve: 'linear' | 'easeIn' | 'easeOut' | 'easeInOut' | 'backIn' | 'backOut' | 'backInOut'. Missing (or unknown) plays linear. Setting a preset in the editor writes its recommended curve: fade, move, zoom, blur, count, rise, flip, growTurn and wipe ease out on enter and ease in on exit, pop overshoots (backOut on enter, backIn on exit), blink and bounce ease in and out on each sweep, kenBurns eases in and out across the element's time, a text preset eases each of its letters, words or lines as the preset it plays, and every other animation is linear.",
343
+ "type": "string"
340
344
  }
341
345
  },
342
346
  "required": [
@@ -732,6 +736,10 @@
732
736
  "data": {
733
737
  "default": {},
734
738
  "description": "Animation-specific data."
739
+ },
740
+ "easing": {
741
+ "description": "Timing curve: 'linear' | 'easeIn' | 'easeOut' | 'easeInOut' | 'backIn' | 'backOut' | 'backInOut'. Missing (or unknown) plays linear. Setting a preset in the editor writes its recommended curve: fade, move, zoom, blur, count, rise, flip, growTurn and wipe ease out on enter and ease in on exit, pop overshoots (backOut on enter, backIn on exit), blink and bounce ease in and out on each sweep, kenBurns eases in and out across the element's time, a text preset eases each of its letters, words or lines as the preset it plays, and every other animation is linear.",
742
+ "type": "string"
735
743
  }
736
744
  },
737
745
  "required": [
@@ -1044,6 +1052,10 @@
1044
1052
  "data": {
1045
1053
  "default": {},
1046
1054
  "description": "Animation-specific data."
1055
+ },
1056
+ "easing": {
1057
+ "description": "Timing curve: 'linear' | 'easeIn' | 'easeOut' | 'easeInOut' | 'backIn' | 'backOut' | 'backInOut'. Missing (or unknown) plays linear. Setting a preset in the editor writes its recommended curve: fade, move, zoom, blur, count, rise, flip, growTurn and wipe ease out on enter and ease in on exit, pop overshoots (backOut on enter, backIn on exit), blink and bounce ease in and out on each sweep, kenBurns eases in and out across the element's time, a text preset eases each of its letters, words or lines as the preset it plays, and every other animation is linear.",
1058
+ "type": "string"
1047
1059
  }
1048
1060
  },
1049
1061
  "required": [
@@ -1367,6 +1379,10 @@
1367
1379
  "data": {
1368
1380
  "default": {},
1369
1381
  "description": "Animation-specific data."
1382
+ },
1383
+ "easing": {
1384
+ "description": "Timing curve: 'linear' | 'easeIn' | 'easeOut' | 'easeInOut' | 'backIn' | 'backOut' | 'backInOut'. Missing (or unknown) plays linear. Setting a preset in the editor writes its recommended curve: fade, move, zoom, blur, count, rise, flip, growTurn and wipe ease out on enter and ease in on exit, pop overshoots (backOut on enter, backIn on exit), blink and bounce ease in and out on each sweep, kenBurns eases in and out across the element's time, a text preset eases each of its letters, words or lines as the preset it plays, and every other animation is linear.",
1385
+ "type": "string"
1370
1386
  }
1371
1387
  },
1372
1388
  "required": [
@@ -1637,6 +1653,10 @@
1637
1653
  "data": {
1638
1654
  "default": {},
1639
1655
  "description": "Animation-specific data."
1656
+ },
1657
+ "easing": {
1658
+ "description": "Timing curve: 'linear' | 'easeIn' | 'easeOut' | 'easeInOut' | 'backIn' | 'backOut' | 'backInOut'. Missing (or unknown) plays linear. Setting a preset in the editor writes its recommended curve: fade, move, zoom, blur, count, rise, flip, growTurn and wipe ease out on enter and ease in on exit, pop overshoots (backOut on enter, backIn on exit), blink and bounce ease in and out on each sweep, kenBurns eases in and out across the element's time, a text preset eases each of its letters, words or lines as the preset it plays, and every other animation is linear.",
1659
+ "type": "string"
1640
1660
  }
1641
1661
  },
1642
1662
  "required": [
@@ -1917,6 +1937,10 @@
1917
1937
  "data": {
1918
1938
  "default": {},
1919
1939
  "description": "Animation-specific data."
1940
+ },
1941
+ "easing": {
1942
+ "description": "Timing curve: 'linear' | 'easeIn' | 'easeOut' | 'easeInOut' | 'backIn' | 'backOut' | 'backInOut'. Missing (or unknown) plays linear. Setting a preset in the editor writes its recommended curve: fade, move, zoom, blur, count, rise, flip, growTurn and wipe ease out on enter and ease in on exit, pop overshoots (backOut on enter, backIn on exit), blink and bounce ease in and out on each sweep, kenBurns eases in and out across the element's time, a text preset eases each of its letters, words or lines as the preset it plays, and every other animation is linear.",
1943
+ "type": "string"
1920
1944
  }
1921
1945
  },
1922
1946
  "required": [
@@ -2234,6 +2258,10 @@
2234
2258
  "data": {
2235
2259
  "default": {},
2236
2260
  "description": "Animation-specific data."
2261
+ },
2262
+ "easing": {
2263
+ "description": "Timing curve: 'linear' | 'easeIn' | 'easeOut' | 'easeInOut' | 'backIn' | 'backOut' | 'backInOut'. Missing (or unknown) plays linear. Setting a preset in the editor writes its recommended curve: fade, move, zoom, blur, count, rise, flip, growTurn and wipe ease out on enter and ease in on exit, pop overshoots (backOut on enter, backIn on exit), blink and bounce ease in and out on each sweep, kenBurns eases in and out across the element's time, a text preset eases each of its letters, words or lines as the preset it plays, and every other animation is linear.",
2264
+ "type": "string"
2237
2265
  }
2238
2266
  },
2239
2267
  "required": [
@@ -2571,6 +2599,10 @@
2571
2599
  "data": {
2572
2600
  "default": {},
2573
2601
  "description": "Animation-specific data."
2602
+ },
2603
+ "easing": {
2604
+ "description": "Timing curve: 'linear' | 'easeIn' | 'easeOut' | 'easeInOut' | 'backIn' | 'backOut' | 'backInOut'. Missing (or unknown) plays linear. Setting a preset in the editor writes its recommended curve: fade, move, zoom, blur, count, rise, flip, growTurn and wipe ease out on enter and ease in on exit, pop overshoots (backOut on enter, backIn on exit), blink and bounce ease in and out on each sweep, kenBurns eases in and out across the element's time, a text preset eases each of its letters, words or lines as the preset it plays, and every other animation is linear.",
2605
+ "type": "string"
2574
2606
  }
2575
2607
  },
2576
2608
  "required": [
@@ -3082,6 +3114,10 @@
3082
3114
  "data": {
3083
3115
  "default": {},
3084
3116
  "description": "Animation-specific data."
3117
+ },
3118
+ "easing": {
3119
+ "description": "Timing curve: 'linear' | 'easeIn' | 'easeOut' | 'easeInOut' | 'backIn' | 'backOut' | 'backInOut'. Missing (or unknown) plays linear. Setting a preset in the editor writes its recommended curve: fade, move, zoom, blur, count, rise, flip, growTurn and wipe ease out on enter and ease in on exit, pop overshoots (backOut on enter, backIn on exit), blink and bounce ease in and out on each sweep, kenBurns eases in and out across the element's time, a text preset eases each of its letters, words or lines as the preset it plays, and every other animation is linear.",
3120
+ "type": "string"
3085
3121
  }
3086
3122
  },
3087
3123
  "required": [
package/lib/migrate.js CHANGED
@@ -33,7 +33,7 @@
33
33
  // decision into the design (`legacyBackground`), so the second pass through any
34
34
  // entry point is a no-op and every renderer reads the same resolved intent.
35
35
  import { CURRENT_SCHEMA_VERSION } from './schema.js';
36
- import { TEXT_DEFAULTS } from './defaults.js';
36
+ import { DESIGN_SIZE, TEXT_DEFAULTS } from './defaults.js';
37
37
  /** Named effects that never used the -100..100 intensity range. */
38
38
  const UNSCALED_FILTERS = ['warm', 'cold', 'natural'];
39
39
  /** The tags Quill actually emitted. Anything else is not evidence. */
@@ -191,6 +191,36 @@ export function migrateDesign(json, options = {}) {
191
191
  }
192
192
  // v3→4 is a marker only: v4 is the video time-anchor render change. Nothing
193
193
  // to transform, but the bump lets a future migration target pre-v4 designs.
194
+ if (from < 5) {
195
+ // A move travelled a fixed 200px. From v5 it travels a share of its page's
196
+ // shorter side (core's `TRAVEL.move`), so scale each saved strength to keep
197
+ // the 200px. Both numbers stay frozen here.
198
+ const MOVE_PX = 200;
199
+ const MOVE_SHARE = 0.2;
200
+ const side = (page, design) => typeof page === 'number' ? page : (design ?? DESIGN_SIZE);
201
+ for (const page of Array.isArray(data.pages) ? data.pages : []) {
202
+ if (!page || typeof page !== 'object')
203
+ continue;
204
+ const unit = Math.min(side(page.width, data.width), side(page.height, data.height));
205
+ if (!(unit > 0))
206
+ continue;
207
+ forEveryElement([page], (element) => {
208
+ if (!Array.isArray(element.animations))
209
+ return;
210
+ for (const animation of element.animations) {
211
+ if (animation?.name !== 'move')
212
+ continue;
213
+ const strength = Number.isFinite(animation.data?.strength)
214
+ ? animation.data.strength
215
+ : 1;
216
+ animation.data = {
217
+ ...animation.data,
218
+ strength: (strength * MOVE_PX) / (MOVE_SHARE * unit),
219
+ };
220
+ }
221
+ });
222
+ }
223
+ }
194
224
  data.schemaVersion = CURRENT_SCHEMA_VERSION;
195
225
  return data;
196
226
  }
package/lib/schema.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- export declare const CURRENT_SCHEMA_VERSION = 4;
2
+ export declare const CURRENT_SCHEMA_VERSION = 5;
3
3
  export declare const ELEMENT_TYPES: readonly ["text", "image", "svg", "line", "figure", "gif", "video", "table", "group"];
4
4
  /** Non-strict: strips unknown keys, fills defaults. `normalizeDesign` uses this. */
5
5
  export declare const designSchemaLenient: z.ZodObject<{
@@ -187,6 +187,7 @@ export declare const leafSchemas: {
187
187
  }>;
188
188
  name: z.ZodDefault<z.ZodString>;
189
189
  data: z.ZodDefault<z.ZodUnknown>;
190
+ easing: z.ZodOptional<z.ZodString>;
190
191
  }, z.core.$strip>>>;
191
192
  blurEnabled: z.ZodDefault<z.ZodBoolean>;
192
193
  blurRadius: z.ZodDefault<z.ZodNumber>;
@@ -266,6 +267,7 @@ export declare const leafSchemas: {
266
267
  }>;
267
268
  name: z.ZodDefault<z.ZodString>;
268
269
  data: z.ZodDefault<z.ZodUnknown>;
270
+ easing: z.ZodOptional<z.ZodString>;
269
271
  }, z.core.$strip>>>;
270
272
  blurEnabled: z.ZodDefault<z.ZodBoolean>;
271
273
  blurRadius: z.ZodDefault<z.ZodNumber>;
@@ -346,6 +348,7 @@ export declare const leafSchemas: {
346
348
  }>;
347
349
  name: z.ZodDefault<z.ZodString>;
348
350
  data: z.ZodDefault<z.ZodUnknown>;
351
+ easing: z.ZodOptional<z.ZodString>;
349
352
  }, z.core.$strip>>>;
350
353
  blurEnabled: z.ZodDefault<z.ZodBoolean>;
351
354
  blurRadius: z.ZodDefault<z.ZodNumber>;
@@ -416,6 +419,7 @@ export declare const leafSchemas: {
416
419
  }>;
417
420
  name: z.ZodDefault<z.ZodString>;
418
421
  data: z.ZodDefault<z.ZodUnknown>;
422
+ easing: z.ZodOptional<z.ZodString>;
419
423
  }, z.core.$strip>>>;
420
424
  blurEnabled: z.ZodDefault<z.ZodBoolean>;
421
425
  blurRadius: z.ZodDefault<z.ZodNumber>;
@@ -488,6 +492,7 @@ export declare const leafSchemas: {
488
492
  }>;
489
493
  name: z.ZodDefault<z.ZodString>;
490
494
  data: z.ZodDefault<z.ZodUnknown>;
495
+ easing: z.ZodOptional<z.ZodString>;
491
496
  }, z.core.$strip>>>;
492
497
  blurEnabled: z.ZodDefault<z.ZodBoolean>;
493
498
  blurRadius: z.ZodDefault<z.ZodNumber>;
@@ -568,6 +573,7 @@ export declare const leafSchemas: {
568
573
  }>;
569
574
  name: z.ZodDefault<z.ZodString>;
570
575
  data: z.ZodDefault<z.ZodUnknown>;
576
+ easing: z.ZodOptional<z.ZodString>;
571
577
  }, z.core.$strip>>>;
572
578
  blurEnabled: z.ZodDefault<z.ZodBoolean>;
573
579
  blurRadius: z.ZodDefault<z.ZodNumber>;
@@ -652,6 +658,7 @@ export declare const leafSchemas: {
652
658
  }>;
653
659
  name: z.ZodDefault<z.ZodString>;
654
660
  data: z.ZodDefault<z.ZodUnknown>;
661
+ easing: z.ZodOptional<z.ZodString>;
655
662
  }, z.core.$strip>>>;
656
663
  blurEnabled: z.ZodDefault<z.ZodBoolean>;
657
664
  blurRadius: z.ZodDefault<z.ZodNumber>;
@@ -813,6 +820,7 @@ export declare const leafSchemas: {
813
820
  }>;
814
821
  name: z.ZodDefault<z.ZodString>;
815
822
  data: z.ZodDefault<z.ZodUnknown>;
823
+ easing: z.ZodOptional<z.ZodString>;
816
824
  }, z.core.$strip>>>;
817
825
  visible: z.ZodDefault<z.ZodBoolean>;
818
826
  draggable: z.ZodDefault<z.ZodBoolean>;
package/lib/schema.js CHANGED
@@ -25,8 +25,8 @@
25
25
  // MIN_FONT_SIZE in ./defaults for what they each decided.
26
26
  import { z } from 'zod';
27
27
  import { polotnoError } from './errors.js';
28
- import { BLEND_MODES, GROUP_BLEND_MODES, MIN_FONT_SIZE, clampFontSize, TEXT_DEFAULTS, } from './defaults.js';
29
- export const CURRENT_SCHEMA_VERSION = 4;
28
+ import { ANIMATION_EASINGS, BLEND_MODES, GROUP_BLEND_MODES, MIN_FONT_SIZE, clampFontSize, DESIGN_SIZE, TEXT_DEFAULTS, } from './defaults.js';
29
+ export const CURRENT_SCHEMA_VERSION = 5;
30
30
  // Every element type the design format knows. Kept in sync with the
31
31
  // element discriminatedUnion in build() below.
32
32
  export const ELEMENT_TYPES = [
@@ -61,6 +61,14 @@ function build(o) {
61
61
  type: z.enum(['enter', 'exit', 'loop']).describe('Animation phase.'),
62
62
  name: z.string().default('none').describe('Animation name identifier.'),
63
63
  data: z.unknown().default({}).describe('Animation-specific data.'),
64
+ // Optional with NO default, so normalizeDesign output stays unchanged for
65
+ // a design that never sets it. A plain string, not an enum, for the reason
66
+ // `textOverflow` gives below: an older SDK must read a curve added later as
67
+ // missing instead of crashing on load.
68
+ easing: z
69
+ .string()
70
+ .optional()
71
+ .describe(`Timing curve: ${ANIMATION_EASINGS.map((e) => `'${e}'`).join(' | ')}. Missing (or unknown) plays linear. Setting a preset in the editor writes its recommended curve: fade, move, zoom, blur, count, rise, flip, growTurn and wipe ease out on enter and ease in on exit, pop overshoots (backOut on enter, backIn on exit), blink and bounce ease in and out on each sweep, kenBurns eases in and out across the element's time, a text preset eases each of its letters, words or lines as the preset it plays, and every other animation is linear.`),
64
72
  });
65
73
  const filters = z
66
74
  .record(z.string(), o({
@@ -747,8 +755,11 @@ function build(o) {
747
755
  .number()
748
756
  .default(CURRENT_SCHEMA_VERSION)
749
757
  .describe('Schema version for compatibility / migration.'),
750
- width: z.number().default(1080).describe('Canvas width in pixels.'),
751
- height: z.number().default(1080).describe('Canvas height in pixels.'),
758
+ width: z.number().default(DESIGN_SIZE).describe('Canvas width in pixels.'),
759
+ height: z
760
+ .number()
761
+ .default(DESIGN_SIZE)
762
+ .describe('Canvas height in pixels.'),
752
763
  unit: z
753
764
  .enum(['px', 'pt', 'mm', 'cm', 'in'])
754
765
  .default('px')
package/lib/types.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import type { BLEND_MODES, GROUP_BLEND_MODES } from './defaults.js';
1
+ import type { ANIMATION_EASINGS, BLEND_MODES, GROUP_BLEND_MODES } from './defaults.js';
2
2
  export type BlendMode = (typeof BLEND_MODES)[number];
3
3
  export type GroupBlendMode = (typeof GROUP_BLEND_MODES)[number];
4
+ export type AnimationEasing = (typeof ANIMATION_EASINGS)[number];
4
5
  export interface Design {
5
6
  /** Schema version for compatibility / migration. */
6
7
  schemaVersion: number;
@@ -100,6 +101,11 @@ export interface Animation {
100
101
  name: string;
101
102
  /** Animation-specific data. */
102
103
  data: unknown;
104
+ /**
105
+ * Timing curve, one of {@link AnimationEasing}. Missing (or unknown) plays
106
+ * linear.
107
+ */
108
+ easing?: string;
103
109
  }
104
110
  /** Properties shared by all non-group elements. */
105
111
  export interface ShapeAttributes {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polotno/schema",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "Canonical Polotno design format: types, normalize, validate, JSON Schema. Authored in zod, DOM-free.",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "type": "module",
@@ -50,12 +50,12 @@
50
50
  },
51
51
  "devDependencies": {
52
52
  "typescript": "~6.0.3",
53
- "vitest": "^5.0.4"
53
+ "vitest": "^5.0.5"
54
54
  },
55
55
  "scripts": {
56
56
  "build": "rm -rf lib && tsc && node scripts/generate-schema.mjs && node ../../scripts/check-pack.mjs",
57
57
  "build:schema": "node scripts/generate-schema.mjs",
58
- "typecheck": "tsc --noEmit",
58
+ "typecheck": "node ../../scripts/typecheck.mjs --noEmit",
59
59
  "test": "vitest run"
60
60
  }
61
61
  }