@polotno/schema 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -3
- package/lib/defaults.d.ts +26 -0
- package/lib/defaults.js +26 -0
- package/lib/design.schema.json +4 -3
- package/lib/schema.js +26 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -46,9 +46,26 @@ const complete = normalizeDesign(partial);
|
|
|
46
46
|
// every default filled in, unknown keys stripped
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
-
Idempotent and exact for current-format input. It
|
|
50
|
-
`schemaVersion` documents, and it leaves render-derived
|
|
51
|
-
auto-height) for the editor to compute.
|
|
49
|
+
Idempotent and exact for current-format input. It migrates older
|
|
50
|
+
`schemaVersion` documents up first (see below), and it leaves render-derived
|
|
51
|
+
values (e.g. text auto-height) for the editor to compute.
|
|
52
|
+
|
|
53
|
+
## Schema versions
|
|
54
|
+
|
|
55
|
+
Every design carries a `schemaVersion`. `normalizeDesign` / `parseDesign` migrate
|
|
56
|
+
an older document up to the current version before validating, so a consumer
|
|
57
|
+
never has to handle an old shape. A **missing** `schemaVersion` means 0 — the
|
|
58
|
+
oldest format, not the newest.
|
|
59
|
+
|
|
60
|
+
| Version | What changed |
|
|
61
|
+
| ------- | ----------------------------------------------------------------------------------------------------------------------- |
|
|
62
|
+
| 1 | `letterSpacing` is a ratio of the element's own `fontSize`, no longer of a 16px root. |
|
|
63
|
+
| 2 | Filter `intensity` moved from `-100..100` to `-1..1`. |
|
|
64
|
+
| 3 | Text backgrounds render as per-line polygons; pre-v3 rich text is stamped `legacyBackground` to keep the old full rect. |
|
|
65
|
+
| 4 | Video time anchoring changed. Marker only — no document transform. |
|
|
66
|
+
|
|
67
|
+
Steps 1 and 3 apply only to the modern text renderers, which every converter
|
|
68
|
+
uses.
|
|
52
69
|
|
|
53
70
|
## JSON Schema
|
|
54
71
|
|
package/lib/defaults.d.ts
CHANGED
|
@@ -53,3 +53,29 @@ export declare const TEXT_DEFAULTS: {
|
|
|
53
53
|
readonly curveEnabled: false;
|
|
54
54
|
readonly curvePower: 0.5;
|
|
55
55
|
};
|
|
56
|
+
/**
|
|
57
|
+
* The smallest font size a text element, a table or a table cell can hold. Not
|
|
58
|
+
* a rendering preference — an INVARIANT of the format: each of those models
|
|
59
|
+
* clamps `fontSize` below it at both doors, a loaded snapshot and `set()`, so
|
|
60
|
+
* no element the canvas has ever touched holds less. Clamping one door only is
|
|
61
|
+
* how the table path drifted: `set()` held the floor while a loaded design
|
|
62
|
+
* kept its sub-1 size, and the canvas and the exporters disagreed again.
|
|
63
|
+
* `schema-equivalence.test.ts` is the seam that proves they no longer do.
|
|
64
|
+
*
|
|
65
|
+
* The schema clamps to it for the same reason: a renderer that meets a smaller
|
|
66
|
+
* value has no canvas behavior to mirror, so it invents one. pdf-export read
|
|
67
|
+
* `font-size: 0px` as *absent* and inherited a 16px root default, svg-export's
|
|
68
|
+
* shrink loop walked to `-1px`, html-export emitted an invisible `0px`. Three
|
|
69
|
+
* renderers, three answers, none of them the canvas.
|
|
70
|
+
*
|
|
71
|
+
* @polotno/core's `FIT_MIN_FONT_SIZE` (the floor its fit loops converge to) and
|
|
72
|
+
* the editor's model clamps both derive from this — one rule, stated once.
|
|
73
|
+
*/
|
|
74
|
+
export declare const MIN_FONT_SIZE = 1;
|
|
75
|
+
/**
|
|
76
|
+
* Apply that floor. The one implementation: the zod schema, the text model and
|
|
77
|
+
* the table model all call this, so the rule cannot be spelled two ways.
|
|
78
|
+
* `undefined` passes through — an omitted table-cell size means "inherit from
|
|
79
|
+
* the table", which is not a size to clamp.
|
|
80
|
+
*/
|
|
81
|
+
export declare const clampFontSize: <T extends number | undefined>(size: T) => T;
|
package/lib/defaults.js
CHANGED
|
@@ -101,3 +101,29 @@ export const TEXT_DEFAULTS = {
|
|
|
101
101
|
curveEnabled: false,
|
|
102
102
|
curvePower: 0.5,
|
|
103
103
|
};
|
|
104
|
+
/**
|
|
105
|
+
* The smallest font size a text element, a table or a table cell can hold. Not
|
|
106
|
+
* a rendering preference — an INVARIANT of the format: each of those models
|
|
107
|
+
* clamps `fontSize` below it at both doors, a loaded snapshot and `set()`, so
|
|
108
|
+
* no element the canvas has ever touched holds less. Clamping one door only is
|
|
109
|
+
* how the table path drifted: `set()` held the floor while a loaded design
|
|
110
|
+
* kept its sub-1 size, and the canvas and the exporters disagreed again.
|
|
111
|
+
* `schema-equivalence.test.ts` is the seam that proves they no longer do.
|
|
112
|
+
*
|
|
113
|
+
* The schema clamps to it for the same reason: a renderer that meets a smaller
|
|
114
|
+
* value has no canvas behavior to mirror, so it invents one. pdf-export read
|
|
115
|
+
* `font-size: 0px` as *absent* and inherited a 16px root default, svg-export's
|
|
116
|
+
* shrink loop walked to `-1px`, html-export emitted an invisible `0px`. Three
|
|
117
|
+
* renderers, three answers, none of them the canvas.
|
|
118
|
+
*
|
|
119
|
+
* @polotno/core's `FIT_MIN_FONT_SIZE` (the floor its fit loops converge to) and
|
|
120
|
+
* the editor's model clamps both derive from this — one rule, stated once.
|
|
121
|
+
*/
|
|
122
|
+
export const MIN_FONT_SIZE = 1;
|
|
123
|
+
/**
|
|
124
|
+
* Apply that floor. The one implementation: the zod schema, the text model and
|
|
125
|
+
* the table model all call this, so the rule cannot be spelled two ways.
|
|
126
|
+
* `undefined` passes through — an omitted table-cell size means "inherit from
|
|
127
|
+
* the table", which is not a size to clamp.
|
|
128
|
+
*/
|
|
129
|
+
export const clampFontSize = (size) => (size != null && size < MIN_FONT_SIZE ? MIN_FONT_SIZE : size);
|
package/lib/design.schema.json
CHANGED
|
@@ -456,7 +456,7 @@
|
|
|
456
456
|
},
|
|
457
457
|
"fontSize": {
|
|
458
458
|
"default": 14,
|
|
459
|
-
"description": "Font size in pixels.",
|
|
459
|
+
"description": "Font size in pixels (minimum 1).",
|
|
460
460
|
"type": "number"
|
|
461
461
|
},
|
|
462
462
|
"fontFamily": {
|
|
@@ -1109,6 +1109,7 @@
|
|
|
1109
1109
|
},
|
|
1110
1110
|
"keepRatio": {
|
|
1111
1111
|
"default": true,
|
|
1112
|
+
"description": "Whether to maintain aspect ratio when resizing.",
|
|
1112
1113
|
"type": "boolean"
|
|
1113
1114
|
},
|
|
1114
1115
|
"stretchEnabled": {
|
|
@@ -2573,7 +2574,7 @@
|
|
|
2573
2574
|
}
|
|
2574
2575
|
},
|
|
2575
2576
|
"fontSize": {
|
|
2576
|
-
"description": "Font size in pixels (inherits from the table when omitted).",
|
|
2577
|
+
"description": "Font size in pixels (inherits from the table when omitted, minimum 1).",
|
|
2577
2578
|
"type": "number"
|
|
2578
2579
|
},
|
|
2579
2580
|
"fontFamily": {
|
|
@@ -2668,7 +2669,7 @@
|
|
|
2668
2669
|
},
|
|
2669
2670
|
"fontSize": {
|
|
2670
2671
|
"default": 30,
|
|
2671
|
-
"description": "Default font size in pixels for cells.",
|
|
2672
|
+
"description": "Default font size in pixels for cells (minimum 1).",
|
|
2672
2673
|
"type": "number"
|
|
2673
2674
|
},
|
|
2674
2675
|
"fontFamily": {
|
package/lib/schema.js
CHANGED
|
@@ -15,11 +15,17 @@
|
|
|
15
15
|
// `validateDesign({ mode: 'canonical' })`.
|
|
16
16
|
//
|
|
17
17
|
// Defaults match the core MST models. We do NOT reproduce loadJSON's imperative
|
|
18
|
-
// quirk handling (locked shorthand, svgSource fallback,
|
|
19
|
-
//
|
|
18
|
+
// quirk handling (locked shorthand, svgSource fallback, cell stripping) —
|
|
19
|
+
// normalize is "fill defaults + validate", exact for clean input.
|
|
20
|
+
//
|
|
21
|
+
// The fontSize floor is the ONE exception, and it is not a loadJSON quirk: the
|
|
22
|
+
// text and table models clamp it at every door, so it is an invariant of the
|
|
23
|
+
// format rather than a behavior of one entry point. Leaving it out did not keep
|
|
24
|
+
// the schema neutral, it just moved the decision into each renderer — see
|
|
25
|
+
// MIN_FONT_SIZE in ./defaults for what they each decided.
|
|
20
26
|
import { z } from 'zod';
|
|
21
27
|
import { polotnoError } from './errors.js';
|
|
22
|
-
import { TEXT_DEFAULTS } from './defaults.js';
|
|
28
|
+
import { MIN_FONT_SIZE, clampFontSize, TEXT_DEFAULTS } from './defaults.js';
|
|
23
29
|
export const CURRENT_SCHEMA_VERSION = 4;
|
|
24
30
|
// Every element type the design format knows. Kept in sync with the
|
|
25
31
|
// element discriminatedUnion in build() below.
|
|
@@ -198,10 +204,18 @@ function build(o) {
|
|
|
198
204
|
.string()
|
|
199
205
|
.default('')
|
|
200
206
|
.describe('Placeholder text shown when empty.'),
|
|
207
|
+
// Every authored font size is clamped (see clampFontSize in ./defaults) — a
|
|
208
|
+
// clamp and not a `.min()` refusal, because the editor accepts these
|
|
209
|
+
// designs and rejecting them here would make the schema stricter than the
|
|
210
|
+
// canvas. `.overwrite()` and not `.transform()`: it keeps the node a
|
|
211
|
+
// ZodNumber, so `.default()`/`.optional()` still chain onto it, `z.infer`
|
|
212
|
+
// stays `number` (types-parity.ts fails on a ZodPipe here), and the JSON
|
|
213
|
+
// Schema generator still has a number to emit.
|
|
201
214
|
fontSize: z
|
|
202
215
|
.number()
|
|
216
|
+
.overwrite(clampFontSize)
|
|
203
217
|
.default(TEXT_DEFAULTS.fontSize)
|
|
204
|
-
.describe(
|
|
218
|
+
.describe(`Font size in pixels (minimum ${MIN_FONT_SIZE}).`),
|
|
205
219
|
fontFamily: z
|
|
206
220
|
.string()
|
|
207
221
|
.default(TEXT_DEFAULTS.fontFamily)
|
|
@@ -300,7 +314,10 @@ function build(o) {
|
|
|
300
314
|
cropY: z.number().default(0),
|
|
301
315
|
cropWidth: z.number().default(1),
|
|
302
316
|
cropHeight: z.number().default(1),
|
|
303
|
-
keepRatio: z
|
|
317
|
+
keepRatio: z
|
|
318
|
+
.boolean()
|
|
319
|
+
.default(true)
|
|
320
|
+
.describe('Whether to maintain aspect ratio when resizing.'),
|
|
304
321
|
stretchEnabled: z.boolean().default(true),
|
|
305
322
|
flipX: z.boolean().default(false),
|
|
306
323
|
flipY: z.boolean().default(false),
|
|
@@ -413,8 +430,9 @@ function build(o) {
|
|
|
413
430
|
.describe('Per-side border overrides for this cell.'),
|
|
414
431
|
fontSize: z
|
|
415
432
|
.number()
|
|
433
|
+
.overwrite(clampFontSize)
|
|
416
434
|
.optional()
|
|
417
|
-
.describe(
|
|
435
|
+
.describe(`Font size in pixels (inherits from the table when omitted, minimum ${MIN_FONT_SIZE}).`),
|
|
418
436
|
fontFamily: z
|
|
419
437
|
.string()
|
|
420
438
|
.optional()
|
|
@@ -508,8 +526,9 @@ function build(o) {
|
|
|
508
526
|
.describe('Default border style.'),
|
|
509
527
|
fontSize: z
|
|
510
528
|
.number()
|
|
529
|
+
.overwrite(clampFontSize)
|
|
511
530
|
.default(30)
|
|
512
|
-
.describe(
|
|
531
|
+
.describe(`Default font size in pixels for cells (minimum ${MIN_FONT_SIZE}).`),
|
|
513
532
|
fontFamily: z
|
|
514
533
|
.string()
|
|
515
534
|
.default('Roboto')
|
package/package.json
CHANGED