@polotno/schema 0.10.0 → 0.11.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 +1 -0
- package/lib/design.schema.json +1 -3147
- package/lib/schema.js +83 -10
- package/lib/types.d.ts +13 -6
- package/package.json +1 -1
package/lib/schema.js
CHANGED
|
@@ -23,6 +23,13 @@
|
|
|
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
25
|
// MIN_FONT_SIZE in ./defaults for what they each decided.
|
|
26
|
+
//
|
|
27
|
+
// A type used in more than one place takes `.meta({ id })`, so the generated
|
|
28
|
+
// JSON Schema defines it once under `$defs` and `$ref`s it, rather than copying
|
|
29
|
+
// it into every element (Animation alone was ~6 KB of descriptions, nine
|
|
30
|
+
// times). It changes the JSON only: zod drops `id` from the output, and the two
|
|
31
|
+
// `build()` variants are never converted together. Keep the id on the type and
|
|
32
|
+
// the `.describe()` on each use, so every property still has a description.
|
|
26
33
|
import { z } from 'zod';
|
|
27
34
|
import { polotnoError } from './errors.js';
|
|
28
35
|
import { ANIMATION_EASINGS, BLEND_MODES, GROUP_BLEND_MODES, MIN_FONT_SIZE, clampFontSize, DESIGN_SIZE, TEXT_DEFAULTS, } from './defaults.js';
|
|
@@ -45,22 +52,86 @@ export const ELEMENT_TYPES = [
|
|
|
45
52
|
// — a `strict ? z.strictObject : z.object` ternary would widen to a union and
|
|
46
53
|
// break `z.infer` of the leaf schemas (and thus the type-drift guard).
|
|
47
54
|
function build(o) {
|
|
55
|
+
// These descriptions are the public reference for writing an animation by
|
|
56
|
+
// hand: polotno.com/docs/schema/animation prints each one in a table cell of
|
|
57
|
+
// an MDX page. So a description stays on one line, with no raw `{` or `<`,
|
|
58
|
+
// and the object itself takes none (it would land in unquoted YAML
|
|
59
|
+
// frontmatter). They mirror what the canvas plays (polotno
|
|
60
|
+
// `utils/animations.ts`) and what the Animate panel offers per element type.
|
|
61
|
+
// `cameraZoom` stays out: it is going away (`docs/next-major.md`).
|
|
48
62
|
const animation = o({
|
|
49
63
|
delay: z
|
|
50
64
|
.number()
|
|
51
65
|
.default(0)
|
|
52
|
-
.describe(
|
|
66
|
+
.describe([
|
|
67
|
+
"Time in milliseconds, measured on the element's page, not on the whole design.",
|
|
68
|
+
"On 'enter': how long after the page starts the element appears. It is hidden until then.",
|
|
69
|
+
"On 'exit': how long before the page ends the element disappears. The exit finishes at that moment, and the element stays hidden after it.",
|
|
70
|
+
"On 'loop': how long after the page starts the first cycle begins. It does not wait for the entrance, so a loop can be mid-cycle when the element appears. Until then the element is at rest.",
|
|
71
|
+
'kenBurns ignores it, and letterWave also waits for an entrance that is a text preset to finish.',
|
|
72
|
+
].join(' ')),
|
|
53
73
|
duration: z
|
|
54
74
|
.number()
|
|
55
75
|
.default(500)
|
|
56
|
-
.describe(
|
|
76
|
+
.describe([
|
|
77
|
+
'Time in milliseconds.',
|
|
78
|
+
"On 'enter': how long the entrance plays, from its `delay`.",
|
|
79
|
+
"On 'exit': how long the exit plays, up to the moment the element disappears.",
|
|
80
|
+
"If the two together are longer than the element's time on the page, both play faster by the same factor to fit.",
|
|
81
|
+
"On 'loop': the length of one cycle. Cycles repeat until the element disappears or the page ends.",
|
|
82
|
+
"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 lineWipe, 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
|
+
].join(' ')),
|
|
57
85
|
enabled: z
|
|
58
86
|
.boolean()
|
|
59
87
|
.default(true)
|
|
60
|
-
.describe(
|
|
61
|
-
type: z
|
|
62
|
-
|
|
63
|
-
|
|
88
|
+
.describe("Whether the animation plays. A disabled 'enter' or 'exit' also loses its `delay`, so the element is on the page from its start or to its end. To time an element with no transition, keep it enabled with the name 'none'."),
|
|
89
|
+
type: z
|
|
90
|
+
.enum(['enter', 'exit', 'loop'])
|
|
91
|
+
.describe("Animation phase: 'enter' brings the element onto the page, 'exit' takes it off, and 'loop' repeats while it is there, also during the entrance and the exit."),
|
|
92
|
+
name: z
|
|
93
|
+
.string()
|
|
94
|
+
.default('none')
|
|
95
|
+
.describe([
|
|
96
|
+
'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'.",
|
|
98
|
+
"On 'loop': 'none' | 'rotate' | 'blink' | 'bounce' | 'pulse' | 'float' | 'shake' | 'glow' | 'kenBurns' | 'letterWave'.",
|
|
99
|
+
"Use a name only on its own type: a fade on 'loop' plays once and leaves the element hidden.",
|
|
100
|
+
'An unknown name passes validation, logs a console error and does not animate.',
|
|
101
|
+
'none is a hard cut: the element still appears or disappears at its `delay`, with no transition, and `duration` is ignored.',
|
|
102
|
+
'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
|
+
'An exit plays the same preset backwards, except that move, rise, growTurn and wipe carry on the way they were going.',
|
|
104
|
+
'Presets that scale keep the center of the element in place.',
|
|
105
|
+
'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, and lineRise and lineWipe play rise and wipe on lines. An exit runs from the last unit back to the first.',
|
|
106
|
+
'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.",
|
|
108
|
+
"blur blurs only 'text', 'image', 'svg', 'video' and 'gif', and any other element only fades.",
|
|
109
|
+
"glow plays nothing on 'table' and 'group'. kenBurns plays on the crop, so only on 'image', 'svg', 'video' and 'gif'.",
|
|
110
|
+
'Every other preset plays on every element, groups included.',
|
|
111
|
+
].join(' ')),
|
|
112
|
+
data: z
|
|
113
|
+
.unknown()
|
|
114
|
+
.default({})
|
|
115
|
+
.describe([
|
|
116
|
+
'Object of options for the preset in `name`. Every option is optional, and a preset not listed here takes none.',
|
|
117
|
+
'`strength` is always a multiplier, default 1, and the editor offers 0.1 to 3.',
|
|
118
|
+
"move: `direction` 'right' | 'left' | 'up' | 'down' | 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left', default 'right', the way the element travels on both 'enter' and 'exit'. `strength` 1 travels 20% of the shorter side of the page: it covers that distance, not the way to the edge of the page.",
|
|
119
|
+
"zoom: `direction` 'in' | 'out', default 'in'. 'in' starts smaller and grows into place, 'out' starts larger and shrinks into place, and any other value plays as 'out'. `strength` 1 starts 25% away from full size.",
|
|
120
|
+
'pop: `strength` 1 starts from nothing, and 0.5 from half size.',
|
|
121
|
+
'rise: `strength` 1 travels 5% of the shorter side of the page.',
|
|
122
|
+
'growTurn: `strength` 1 turns 180 degrees.',
|
|
123
|
+
"wipe: `direction` 'right' | 'left' | 'up' | 'down', default 'right', the way its edge travels.",
|
|
124
|
+
'blur: `strength` 1 adds 20 to `blurRadius` at its most blurred.',
|
|
125
|
+
"count: `from`, a number, default 0, where the count starts on 'enter' and ends on 'exit'.",
|
|
126
|
+
'bounce: `strength` 1 shrinks to a third of the size, and 0.5 to half.',
|
|
127
|
+
'pulse: `strength` 1 grows 8%.',
|
|
128
|
+
'float: `strength` 1 lifts 2% of the shorter side of the page.',
|
|
129
|
+
'shake: `strength` 1 swings 1.5% of the shorter side of the page.',
|
|
130
|
+
'letterWave: `strength` 1 lifts each letter 0.3 of its font size.',
|
|
131
|
+
"glow: `strength` 1 spreads 2% of the shorter side of the page. It has no color option: it uses the element's `shadowColor` when `shadowEnabled` is true or `shadowColor` is not 'black', else its `fill` (`color` on a line), else black. So a `shadowColor` with `shadowEnabled` false glows in that color and shows no shadow at rest.",
|
|
132
|
+
"kenBurns: `zoom` 'in' | 'out', default 'in'. 'in' narrows the saved crop, and 'out' widens to it. `direction` 'none' | 'right' | 'left' | 'up' | 'down', default 'none', the way the view pans. `strength` 1 narrows the crop by 15%.",
|
|
133
|
+
'A design below `schemaVersion` 5, or with none, has its move `strength` rescaled on load to keep the fixed 200px those versions travelled.',
|
|
134
|
+
].join(' ')),
|
|
64
135
|
// Optional with NO default, so normalizeDesign output stays unchanged for
|
|
65
136
|
// a design that never sets it. A plain string, not an enum, for the reason
|
|
66
137
|
// `textOverflow` gives below: an older SDK must read a curve added later as
|
|
@@ -69,7 +140,7 @@ function build(o) {
|
|
|
69
140
|
.string()
|
|
70
141
|
.optional()
|
|
71
142
|
.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.`),
|
|
72
|
-
});
|
|
143
|
+
}).meta({ id: 'Animation' });
|
|
73
144
|
const filters = z
|
|
74
145
|
.record(z.string(), o({
|
|
75
146
|
intensity: z
|
|
@@ -77,9 +148,11 @@ function build(o) {
|
|
|
77
148
|
.default(1)
|
|
78
149
|
.describe('Filter intensity (-1 to 1).'),
|
|
79
150
|
}))
|
|
151
|
+
.meta({ id: 'Filters' })
|
|
80
152
|
.describe('Applied image filters keyed by filter name.');
|
|
81
153
|
const blendMode = z
|
|
82
154
|
.enum(BLEND_MODES)
|
|
155
|
+
.meta({ id: 'BlendMode' })
|
|
83
156
|
.optional()
|
|
84
157
|
.describe('How the element composites with the content beneath it. Omitted means normal.');
|
|
85
158
|
// Fields shared by every Shape-derived element. Defaults inline.
|
|
@@ -101,7 +174,7 @@ function build(o) {
|
|
|
101
174
|
animations: z
|
|
102
175
|
.array(animation)
|
|
103
176
|
.default([])
|
|
104
|
-
.describe('
|
|
177
|
+
.describe("The element's animations, at most one of each `type`, so an 'enter', an 'exit' and a 'loop' can play together. A group's animations play on top of its children's."),
|
|
105
178
|
blurEnabled: z
|
|
106
179
|
.boolean()
|
|
107
180
|
.default(false)
|
|
@@ -445,7 +518,7 @@ function build(o) {
|
|
|
445
518
|
.enum(['solid', 'dashed', 'dotted', 'none'])
|
|
446
519
|
.optional()
|
|
447
520
|
.describe('Border style for this side.'),
|
|
448
|
-
});
|
|
521
|
+
}).meta({ id: 'BorderSide' });
|
|
449
522
|
// Cell styling fields are optional (inherit from the table when omitted).
|
|
450
523
|
const tableCell = o({
|
|
451
524
|
id: z.string().describe('Unique identifier for the cell.'),
|
|
@@ -754,7 +827,7 @@ function build(o) {
|
|
|
754
827
|
schemaVersion: z
|
|
755
828
|
.number()
|
|
756
829
|
.default(CURRENT_SCHEMA_VERSION)
|
|
757
|
-
.describe('Schema version for compatibility / migration.'),
|
|
830
|
+
.describe('Schema version for compatibility / migration. A design without it counts as version 0, the oldest format, and is migrated on load, so write the current version in new JSON.'),
|
|
758
831
|
width: z.number().default(DESIGN_SIZE).describe('Canvas width in pixels.'),
|
|
759
832
|
height: z
|
|
760
833
|
.number()
|
package/lib/types.d.ts
CHANGED
|
@@ -88,18 +88,25 @@ export interface Page {
|
|
|
88
88
|
}
|
|
89
89
|
export type Element = TextElement | ImageElement | SVGElement | LineElement | VideoElement | FigureElement | GifElement | GroupElement | TableElement;
|
|
90
90
|
export type ElementType = Element['type'];
|
|
91
|
+
/**
|
|
92
|
+
* The JSON Schema's descriptions (`design.schema.json`) are the full reference:
|
|
93
|
+
* the preset names for each `type`, their options and element limits.
|
|
94
|
+
*/
|
|
91
95
|
export interface Animation {
|
|
92
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
* Milliseconds on the element's page: after its start on `enter` and `loop`,
|
|
98
|
+
* before its end on `exit`.
|
|
99
|
+
*/
|
|
93
100
|
delay: number;
|
|
94
|
-
/**
|
|
101
|
+
/** Length in milliseconds: of the transition, or of one `loop` cycle. */
|
|
95
102
|
duration: number;
|
|
96
|
-
/** Whether
|
|
103
|
+
/** Whether it plays. A disabled `enter` or `exit` also loses its `delay`. */
|
|
97
104
|
enabled: boolean;
|
|
98
105
|
/** Animation phase. */
|
|
99
106
|
type: 'enter' | 'exit' | 'loop';
|
|
100
|
-
/**
|
|
107
|
+
/** Preset to play. Which names are valid depends on `type`. */
|
|
101
108
|
name: string;
|
|
102
|
-
/**
|
|
109
|
+
/** Options for the preset in `name`. */
|
|
103
110
|
data: unknown;
|
|
104
111
|
/**
|
|
105
112
|
* Timing curve, one of {@link AnimationEasing}. Missing (or unknown) plays
|
|
@@ -131,7 +138,7 @@ export interface ShapeAttributes {
|
|
|
131
138
|
opacity: number;
|
|
132
139
|
/** How the element composites with the content beneath it. Omitted means normal. */
|
|
133
140
|
blendMode?: BlendMode;
|
|
134
|
-
/**
|
|
141
|
+
/** The element's animations, at most one of each `type`. */
|
|
135
142
|
animations: Animation[];
|
|
136
143
|
blurEnabled: boolean;
|
|
137
144
|
blurRadius: number;
|
package/package.json
CHANGED