@polotno/schema 0.11.0 → 0.13.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/README.md +4 -0
- package/lib/defaults.d.ts +32 -16
- package/lib/defaults.js +26 -7
- package/lib/design.schema.json +1 -1
- package/lib/errors.d.ts +2 -2
- package/lib/errors.js +2 -2
- package/lib/migrate.js +1 -1
- package/lib/normalize.js +39 -5
- package/lib/schema.d.ts +246 -166
- package/lib/schema.js +47 -12
- package/lib/types.d.ts +6 -3
- package/package.json +4 -5
package/lib/schema.js
CHANGED
|
@@ -22,7 +22,9 @@
|
|
|
22
22
|
// text and table models clamp it at every door, so it is an invariant of the
|
|
23
23
|
// format rather than a behavior of one entry point. Leaving it out did not keep
|
|
24
24
|
// the schema neutral, it just moved the decision into each renderer — see
|
|
25
|
-
// MIN_FONT_SIZE in ./defaults for what they each decided.
|
|
25
|
+
// MIN_FONT_SIZE in ./defaults for what they each decided. The element size
|
|
26
|
+
// floor (MIN_ELEMENT_SIZE) is the same kind of rule, but normalize applies it
|
|
27
|
+
// before this schema runs, because it also reads a null size as 1.
|
|
26
28
|
//
|
|
27
29
|
// A type used in more than one place takes `.meta({ id })`, so the generated
|
|
28
30
|
// JSON Schema defines it once under `$defs` and `$ref`s it, rather than copying
|
|
@@ -43,6 +45,7 @@ export const ELEMENT_TYPES = [
|
|
|
43
45
|
'line',
|
|
44
46
|
'figure',
|
|
45
47
|
'gif',
|
|
48
|
+
'lottie',
|
|
46
49
|
'video',
|
|
47
50
|
'table',
|
|
48
51
|
'group',
|
|
@@ -80,7 +83,7 @@ function build(o) {
|
|
|
80
83
|
"If the two together are longer than the element's time on the page, both play faster by the same factor to fit.",
|
|
81
84
|
"On 'loop': the length of one cycle. Cycles repeat until the element disappears or the page ends.",
|
|
82
85
|
"kenBurns ignores it and plays once across the element's whole time on the page.",
|
|
83
|
-
'The default suits a transition of the whole element. Picking a preset in the editor sets a longer one: 1000 for lineRise, wordRise, wordFade, letterPop, wordBlur and
|
|
86
|
+
'The default suits a transition of the whole element. Picking a preset in the editor sets a longer one: 1000 for lineRise, wordRise, wordFade, letterPop, wordBlur, lineWipe and linePeek, 50 per letter from 1000 to 4000 for typewriter, 4000 for rotate, 2500 for float, 2000 for letterWave and glow, 1500 for blink and pulse, and 1000 for shake.',
|
|
84
87
|
].join(' ')),
|
|
85
88
|
enabled: z
|
|
86
89
|
.boolean()
|
|
@@ -94,7 +97,7 @@ function build(o) {
|
|
|
94
97
|
.default('none')
|
|
95
98
|
.describe([
|
|
96
99
|
'Preset to play. Which names are valid depends on `type`.',
|
|
97
|
-
"On 'enter' and 'exit': 'none' | 'fade' | 'move' | 'zoom' | 'pop' | 'rise' | 'flip' | 'growTurn' | 'wipe' | 'blur' | 'count' | 'typewriter' | 'lineRise' | 'wordRise' | 'wordFade' | 'letterPop' | 'wordBlur' | 'lineWipe'.",
|
|
100
|
+
"On 'enter' and 'exit': 'none' | 'fade' | 'move' | 'zoom' | 'pop' | 'rise' | 'flip' | 'growTurn' | 'wipe' | 'blur' | 'count' | 'typewriter' | 'lineRise' | 'wordRise' | 'wordFade' | 'letterPop' | 'wordBlur' | 'lineWipe' | 'linePeek'.",
|
|
98
101
|
"On 'loop': 'none' | 'rotate' | 'blink' | 'bounce' | 'pulse' | 'float' | 'shake' | 'glow' | 'kenBurns' | 'letterWave'.",
|
|
99
102
|
"Use a name only on its own type: a fade on 'loop' plays once and leaves the element hidden.",
|
|
100
103
|
'An unknown name passes validation, logs a console error and does not animate.',
|
|
@@ -102,9 +105,9 @@ function build(o) {
|
|
|
102
105
|
'As entrances: fade fades in, move slides in along a straight line, zoom scales into place, pop grows into place and fades in over its first third, rise moves up into place while fading in, flip turns half round about its vertical center line from its mirrored back, growTurn turns into place from half size while fading in, wipe shows the element behind a travelling edge, blur comes into focus while fading in, and count counts the first number in the text up to its value, keeping the style of the text and the format of the number, such as its thousands separator.',
|
|
103
106
|
'An exit plays the same preset backwards, except that move, rise, growTurn and wipe carry on the way they were going.',
|
|
104
107
|
'Presets that scale keep the center of the element in place.',
|
|
105
|
-
|
|
108
|
+
"The text presets play on each unit of the text in turn, and `duration` covers them all: typewriter shows letters, letterPop pops letters, wordRise, wordFade and wordBlur play rise, fade and blur on words, lineRise and lineWipe play rise and wipe on lines, and linePeek slides each line into place behind a wipe's edge, clipped to the line's own row. An exit runs from the last unit back to the first, and a linePeek line carries on the way it came.",
|
|
106
109
|
'As loops: rotate turns clockwise once per cycle, blink fades out and back, pulse grows a little and back, float lifts and settles, shake swings side to side and dies out within the cycle, glow swells and fades a halo around the element, letterWave bobs each letter in turn, and kenBurns zooms, and can pan, inside the frame of the element. bounce shrinks and grows back: the editor no longer offers it, so prefer pulse.',
|
|
107
|
-
"Element limits: count, the text presets and letterWave are for 'text' elements. count plays nothing without a number in the text. Curved text or any other element plays a text preset whole, as its base preset: typewriter and wordFade as fade, lineRise and wordRise as rise, letterPop as pop, wordBlur as blur, lineWipe as wipe and letterWave as float.",
|
|
110
|
+
"Element limits: count, the text presets and letterWave are for 'text' elements. count plays nothing without a number in the text. Curved text or any other element plays a text preset whole, as its base preset: typewriter and wordFade as fade, lineRise and wordRise as rise, letterPop as pop, wordBlur as blur, lineWipe and linePeek as wipe and letterWave as float.",
|
|
108
111
|
"blur blurs only 'text', 'image', 'svg', 'video' and 'gif', and any other element only fades.",
|
|
109
112
|
"glow plays nothing on 'table' and 'group'. kenBurns plays on the crop, so only on 'image', 'svg', 'video' and 'gif'.",
|
|
110
113
|
'Every other preset plays on every element, groups included.',
|
|
@@ -121,6 +124,8 @@ function build(o) {
|
|
|
121
124
|
'rise: `strength` 1 travels 5% of the shorter side of the page.',
|
|
122
125
|
'growTurn: `strength` 1 turns 180 degrees.',
|
|
123
126
|
"wipe: `direction` 'right' | 'left' | 'up' | 'down', default 'right', the way its edge travels.",
|
|
127
|
+
'lineWipe: `direction` as wipe; without one, each line wipes in its own reading direction.',
|
|
128
|
+
"linePeek: `direction` 'right' | 'left' | 'up' | 'down', default 'up', the way each line travels.",
|
|
124
129
|
'blur: `strength` 1 adds 20 to `blurRadius` at its most blurred.',
|
|
125
130
|
"count: `from`, a number, default 0, where the count starts on 'enter' and ends on 'exit'.",
|
|
126
131
|
'bounce: `strength` 1 shrinks to a third of the size, and 0.5 to half.',
|
|
@@ -166,8 +171,14 @@ function build(o) {
|
|
|
166
171
|
.describe('Custom data attached to the element.'),
|
|
167
172
|
x: z.number().default(0).describe('X position in pixels.'),
|
|
168
173
|
y: z.number().default(0).describe('Y position in pixels.'),
|
|
169
|
-
width: z
|
|
170
|
-
|
|
174
|
+
width: z
|
|
175
|
+
.number()
|
|
176
|
+
.default(100)
|
|
177
|
+
.describe('Width in pixels. A value of 0 or less reads as 1.'),
|
|
178
|
+
height: z
|
|
179
|
+
.number()
|
|
180
|
+
.default(100)
|
|
181
|
+
.describe('Height in pixels. A value of 0 or less reads as 1.'),
|
|
171
182
|
rotation: z.number().default(0).describe('Rotation angle in degrees.'),
|
|
172
183
|
opacity: z.number().default(1).describe('Opacity level (0-1).'),
|
|
173
184
|
blendMode,
|
|
@@ -328,7 +339,10 @@ function build(o) {
|
|
|
328
339
|
.string()
|
|
329
340
|
.default(TEXT_DEFAULTS.align)
|
|
330
341
|
.describe('Horizontal alignment (commonly left | center | right | justify).'),
|
|
331
|
-
width: z
|
|
342
|
+
width: z
|
|
343
|
+
.number()
|
|
344
|
+
.default(100)
|
|
345
|
+
.describe('Width in pixels. A value of 0 or less reads as 1.'),
|
|
332
346
|
height: z
|
|
333
347
|
.number()
|
|
334
348
|
.default(0)
|
|
@@ -456,8 +470,14 @@ function build(o) {
|
|
|
456
470
|
const lineShape = {
|
|
457
471
|
...shapeBase,
|
|
458
472
|
type: z.literal('line').describe('Element type identifier.'),
|
|
459
|
-
width: z
|
|
460
|
-
|
|
473
|
+
width: z
|
|
474
|
+
.number()
|
|
475
|
+
.default(400)
|
|
476
|
+
.describe('Width in pixels. A value of 0 or less reads as 1.'),
|
|
477
|
+
height: z
|
|
478
|
+
.number()
|
|
479
|
+
.default(10)
|
|
480
|
+
.describe('Height in pixels. A value of 0 or less reads as 1.'),
|
|
461
481
|
color: z.string().default('black').describe('Line color.'),
|
|
462
482
|
dash: z.array(z.number()).default([]).describe('Dash pattern array.'),
|
|
463
483
|
startHead: z
|
|
@@ -495,6 +515,12 @@ function build(o) {
|
|
|
495
515
|
.default(true)
|
|
496
516
|
.describe('Whether to maintain aspect ratio when resizing.'),
|
|
497
517
|
};
|
|
518
|
+
const lottieShape = {
|
|
519
|
+
...shapeBase,
|
|
520
|
+
...imageProps,
|
|
521
|
+
type: z.literal('lottie').describe('Element type identifier.'),
|
|
522
|
+
keepRatio: gifShape.keepRatio,
|
|
523
|
+
};
|
|
498
524
|
const videoShape = {
|
|
499
525
|
...shapeBase,
|
|
500
526
|
...imageProps,
|
|
@@ -624,8 +650,14 @@ function build(o) {
|
|
|
624
650
|
const tableShape = {
|
|
625
651
|
...shapeBaseNoEffects,
|
|
626
652
|
type: z.literal('table').describe('Element type identifier.'),
|
|
627
|
-
width: z
|
|
628
|
-
|
|
653
|
+
width: z
|
|
654
|
+
.number()
|
|
655
|
+
.default(300)
|
|
656
|
+
.describe('Width in pixels. A value of 0 or less reads as 1.'),
|
|
657
|
+
height: z
|
|
658
|
+
.number()
|
|
659
|
+
.default(200)
|
|
660
|
+
.describe('Height in pixels. A value of 0 or less reads as 1.'),
|
|
629
661
|
rows: z.number().default(3).describe('Number of rows.'),
|
|
630
662
|
cols: z.number().default(3).describe('Number of columns.'),
|
|
631
663
|
colWidths: z
|
|
@@ -738,6 +770,7 @@ function build(o) {
|
|
|
738
770
|
o(lineShape),
|
|
739
771
|
o(figureShape),
|
|
740
772
|
o(gifShape),
|
|
773
|
+
o(lottieShape),
|
|
741
774
|
o(videoShape),
|
|
742
775
|
o(tableShape),
|
|
743
776
|
o(groupShape(element)),
|
|
@@ -865,6 +898,7 @@ function build(o) {
|
|
|
865
898
|
line: lineShape,
|
|
866
899
|
figure: figureShape,
|
|
867
900
|
gif: gifShape,
|
|
901
|
+
lottie: lottieShape,
|
|
868
902
|
video: videoShape,
|
|
869
903
|
table: tableShape,
|
|
870
904
|
font: fontShape,
|
|
@@ -893,6 +927,7 @@ export const leafSchemas = {
|
|
|
893
927
|
line: z.object(lenient.shapes.line),
|
|
894
928
|
figure: z.object(lenient.shapes.figure),
|
|
895
929
|
gif: z.object(lenient.shapes.gif),
|
|
930
|
+
lottie: z.object(lenient.shapes.lottie),
|
|
896
931
|
video: z.object(lenient.shapes.video),
|
|
897
932
|
table: z.object(lenient.shapes.table),
|
|
898
933
|
font: z.object(lenient.shapes.font),
|
package/lib/types.d.ts
CHANGED
|
@@ -86,7 +86,7 @@ export interface Page {
|
|
|
86
86
|
/** Elements on this page. */
|
|
87
87
|
children: Element[];
|
|
88
88
|
}
|
|
89
|
-
export type Element = TextElement | ImageElement | SVGElement | LineElement | VideoElement | FigureElement | GifElement | GroupElement | TableElement;
|
|
89
|
+
export type Element = TextElement | ImageElement | SVGElement | LineElement | VideoElement | FigureElement | GifElement | LottieElement | GroupElement | TableElement;
|
|
90
90
|
export type ElementType = Element['type'];
|
|
91
91
|
/**
|
|
92
92
|
* The JSON Schema's descriptions (`design.schema.json`) are the full reference:
|
|
@@ -128,9 +128,9 @@ export interface ShapeAttributes {
|
|
|
128
128
|
x: number;
|
|
129
129
|
/** Y position in pixels. */
|
|
130
130
|
y: number;
|
|
131
|
-
/** Width in pixels. */
|
|
131
|
+
/** Width in pixels. A value of 0 or less reads as 1. */
|
|
132
132
|
width: number;
|
|
133
|
-
/** Height in pixels. */
|
|
133
|
+
/** Height in pixels. A value of 0 or less reads as 1, except on text. */
|
|
134
134
|
height: number;
|
|
135
135
|
/** Rotation in degrees. */
|
|
136
136
|
rotation: number;
|
|
@@ -302,6 +302,9 @@ export interface GifElement extends ShapeAttributes, BaseImageProps {
|
|
|
302
302
|
/** Duration in milliseconds. */
|
|
303
303
|
duration: number;
|
|
304
304
|
}
|
|
305
|
+
export interface LottieElement extends ShapeAttributes, BaseImageProps {
|
|
306
|
+
type: 'lottie';
|
|
307
|
+
}
|
|
305
308
|
export interface VideoElement extends ShapeAttributes, BaseImageProps {
|
|
306
309
|
type: 'video';
|
|
307
310
|
/** Duration in milliseconds. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polotno/schema",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.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",
|
|
@@ -49,13 +49,12 @@
|
|
|
49
49
|
"zod": "^4.6.7"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"typescript": "~
|
|
53
|
-
"vitest": "^5.0
|
|
52
|
+
"typescript": "~7.0.2",
|
|
53
|
+
"vitest": "^5.1.0"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
56
|
"build": "rm -rf lib && tsc && node scripts/generate-schema.mjs && node ../../scripts/check-pack.mjs",
|
|
57
|
-
"
|
|
58
|
-
"typecheck": "node ../../scripts/typecheck.mjs --noEmit",
|
|
57
|
+
"typecheck": "tsc --noEmit && tsc -p tests/tsconfig.json",
|
|
59
58
|
"test": "vitest run"
|
|
60
59
|
}
|
|
61
60
|
}
|