@polotno/schema 0.2.0 → 0.4.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 (55) hide show
  1. package/README.md +2 -2
  2. package/lib/bleed.d.ts +0 -1
  3. package/lib/bleed.js +0 -1
  4. package/lib/defaults.d.ts +44 -434
  5. package/lib/defaults.js +92 -243
  6. package/lib/design.schema.json +5 -0
  7. package/lib/errors.d.ts +23 -6
  8. package/lib/errors.js +5 -1
  9. package/lib/index.d.ts +3 -1
  10. package/lib/index.js +3 -1
  11. package/lib/migrate.d.ts +18 -3
  12. package/lib/migrate.js +120 -45
  13. package/lib/normalize.d.ts +20 -3
  14. package/lib/normalize.js +196 -50
  15. package/lib/schema.d.ts +14 -1
  16. package/lib/schema.js +537 -134
  17. package/lib/types-parity.d.ts +0 -1
  18. package/lib/types-parity.js +0 -1
  19. package/lib/types.d.ts +2 -1
  20. package/lib/types.js +0 -1
  21. package/package.json +8 -8
  22. package/lib/bleed.d.ts.map +0 -1
  23. package/lib/bleed.js.map +0 -1
  24. package/lib/constants.d.ts +0 -6
  25. package/lib/constants.d.ts.map +0 -1
  26. package/lib/constants.js +0 -61
  27. package/lib/constants.js.map +0 -1
  28. package/lib/defaults.d.ts.map +0 -1
  29. package/lib/defaults.js.map +0 -1
  30. package/lib/errors.d.ts.map +0 -1
  31. package/lib/errors.js.map +0 -1
  32. package/lib/index.d.ts.map +0 -1
  33. package/lib/index.js.map +0 -1
  34. package/lib/migrate.d.ts.map +0 -1
  35. package/lib/migrate.js.map +0 -1
  36. package/lib/normalize.d.ts.map +0 -1
  37. package/lib/normalize.js.map +0 -1
  38. package/lib/processors.d.ts +0 -13
  39. package/lib/processors.d.ts.map +0 -1
  40. package/lib/processors.js +0 -170
  41. package/lib/processors.js.map +0 -1
  42. package/lib/schema.d.ts.map +0 -1
  43. package/lib/schema.js.map +0 -1
  44. package/lib/traverse.d.ts +0 -3
  45. package/lib/traverse.d.ts.map +0 -1
  46. package/lib/traverse.js +0 -32
  47. package/lib/traverse.js.map +0 -1
  48. package/lib/types-parity.d.ts.map +0 -1
  49. package/lib/types-parity.js.map +0 -1
  50. package/lib/types.d.ts.map +0 -1
  51. package/lib/types.js.map +0 -1
  52. package/lib/validate.d.ts +0 -19
  53. package/lib/validate.d.ts.map +0 -1
  54. package/lib/validate.js +0 -383
  55. package/lib/validate.js.map +0 -1
package/README.md CHANGED
@@ -26,8 +26,8 @@ npm install @polotno/schema
26
26
  ```ts
27
27
  import { validateDesign, assertValidDesign } from '@polotno/schema';
28
28
 
29
- validateDesign(json, { mode: 'partial' }); // lenient — defaults may be missing
30
- validateDesign(json, { mode: 'canonical' }); // strict — rejects unknown keys
29
+ validateDesign(json, { mode: 'partial' }); // lenient — defaults may be missing
30
+ validateDesign(json, { mode: 'canonical' }); // strict — rejects unknown keys
31
31
  // → { valid: boolean, errors: { path: string, message: string }[] }
32
32
 
33
33
  assertValidDesign(json); // throws on invalid
package/lib/bleed.d.ts CHANGED
@@ -12,4 +12,3 @@ export declare function resolveBleed(p: {
12
12
  bleedLeft?: number;
13
13
  }): ResolvedBleed;
14
14
  export declare const ZERO_BLEED: ResolvedBleed;
15
- //# sourceMappingURL=bleed.d.ts.map
package/lib/bleed.js CHANGED
@@ -24,4 +24,3 @@ export const ZERO_BLEED = Object.freeze({
24
24
  bottom: 0,
25
25
  left: 0,
26
26
  });
27
- //# sourceMappingURL=bleed.js.map
package/lib/defaults.d.ts CHANGED
@@ -1,445 +1,55 @@
1
- export declare const NODE_DEFAULTS: {
2
- readonly type: "none";
3
- readonly name: "";
4
- readonly opacity: 1;
5
- readonly visible: true;
6
- readonly selectable: true;
7
- readonly removable: true;
8
- readonly alwaysOnTop: false;
9
- readonly showInExport: true;
10
- };
11
- export declare const SHAPE_DEFAULTS: {
12
- readonly x: 0;
13
- readonly y: 0;
14
- readonly width: 100;
15
- readonly height: 100;
16
- readonly rotation: 0;
17
- readonly opacity: 1;
18
- readonly blurEnabled: false;
19
- readonly blurRadius: 10;
20
- readonly brightnessEnabled: false;
21
- readonly brightness: 0;
22
- readonly sepiaEnabled: false;
23
- readonly grayscaleEnabled: false;
24
- readonly shadowEnabled: false;
25
- readonly shadowBlur: 5;
26
- readonly shadowOffsetX: 0;
27
- readonly shadowOffsetY: 0;
28
- readonly shadowColor: "black";
29
- readonly shadowOpacity: 1;
30
- readonly visible: true;
31
- readonly draggable: true;
32
- readonly resizable: true;
33
- readonly selectable: true;
34
- readonly contentEditable: true;
35
- readonly styleEditable: true;
36
- readonly alwaysOnTop: false;
37
- readonly showInExport: true;
38
- readonly type: "none";
39
- readonly name: "";
40
- readonly removable: true;
41
- };
42
- export declare const IMAGE_DEFAULTS: {
43
- readonly type: "image";
44
- readonly width: 100;
45
- readonly height: 100;
46
- readonly src: "";
47
- readonly cropX: 0;
48
- readonly cropY: 0;
49
- readonly cropWidth: 1;
50
- readonly cropHeight: 1;
51
- readonly cornerRadius: 0;
52
- readonly flipX: false;
53
- readonly flipY: false;
54
- readonly clipSrc: "";
55
- readonly borderColor: "black";
56
- readonly borderSize: 0;
57
- readonly keepRatio: false;
58
- readonly stretchEnabled: false;
59
- readonly x: 0;
60
- readonly y: 0;
61
- readonly rotation: 0;
62
- readonly opacity: 1;
63
- readonly blurEnabled: false;
64
- readonly blurRadius: 10;
65
- readonly brightnessEnabled: false;
66
- readonly brightness: 0;
67
- readonly sepiaEnabled: false;
68
- readonly grayscaleEnabled: false;
69
- readonly shadowEnabled: false;
70
- readonly shadowBlur: 5;
71
- readonly shadowOffsetX: 0;
72
- readonly shadowOffsetY: 0;
73
- readonly shadowColor: "black";
74
- readonly shadowOpacity: 1;
75
- readonly visible: true;
76
- readonly draggable: true;
77
- readonly resizable: true;
78
- readonly selectable: true;
79
- readonly contentEditable: true;
80
- readonly styleEditable: true;
81
- readonly alwaysOnTop: false;
82
- readonly showInExport: true;
83
- readonly name: "";
84
- readonly removable: true;
1
+ export declare const TABLE_CELL_OVERRIDABLE_KEYS: readonly ["fontSize", "fontFamily", "fontWeight", "fontStyle", "textDecoration", "textTransform", "fill", "align", "verticalAlign", "lineHeight", "letterSpacing", "strokeWidth", "stroke", "cellBackground", "cellPadding"];
2
+ /**
3
+ * Resolve cell inheritance: every overridable text property a cell leaves
4
+ * undefined is filled from the table element (canvas parity — no fallback
5
+ * literals downstream). Returns shallow clones; the input is untouched
6
+ * (source may be frozen JSON).
7
+ */
8
+ export declare const resolveTableCellDefaults: (element: Record<string, any>) => any[];
9
+ /**
10
+ * Per-side border resolution: a cell's `borders[side]` overrides win over
11
+ * the table element's `border{Width,Style,Color}` (canvas table-model
12
+ * parity). Shared by the svg/html/pdf exporters.
13
+ */
14
+ export declare const resolveTableCellBorder: (cell: Record<string, any>, element: Record<string, any>, side: string) => {
15
+ width: number;
16
+ style: string;
17
+ color: string;
18
+ };
19
+ /**
20
+ * How many pixels each border eats from a cell's interior — the inset between
21
+ * the cell rect and the box its text is laid out in.
22
+ *
23
+ * Outer perimeter borders are fully inset (the whole stroke lies inside the
24
+ * cell); inner gridlines are centred on the shared boundary, so only half the
25
+ * stroke intrudes and the other half lives in the neighbour. `cell` must carry
26
+ * its grid position (`row`, `col`, and the spans when it spans).
27
+ *
28
+ * Mirrors the editor's `TableCell.borderInsets` (polotno's table-model.ts),
29
+ * which is what the canvas places cell text with — that model still owns its
30
+ * own copy because it resolves borders through MST views with an isAlive
31
+ * guard.
32
+ */
33
+ export declare const tableCellBorderInsets: (cell: Record<string, any>, element: Record<string, any>) => {
34
+ top: number;
35
+ right: number;
36
+ bottom: number;
37
+ left: number;
85
38
  };
86
39
  export declare const TEXT_DEFAULTS: {
87
- readonly type: "text";
88
- readonly text: "";
89
- readonly placeholder: "";
90
40
  readonly fontSize: 14;
91
41
  readonly fontFamily: "Roboto";
92
- readonly fontStyle: "normal";
93
42
  readonly fontWeight: "normal";
94
- readonly textDecoration: "";
95
- readonly textTransform: "none";
96
- readonly fill: "black";
97
- readonly align: "center";
98
- readonly width: 100;
99
- readonly height: 0;
100
- readonly verticalAlign: "top";
101
- readonly strokeWidth: 0;
102
- readonly stroke: "black";
43
+ readonly fontStyle: "normal";
103
44
  readonly lineHeight: 1.2;
104
45
  readonly letterSpacing: 0;
105
- readonly backgroundEnabled: false;
106
- readonly backgroundColor: "#7ED321";
107
- readonly backgroundOpacity: 1;
108
- readonly backgroundCornerRadius: 0.5;
109
- readonly backgroundPadding: 0.5;
110
- readonly curveEnabled: false;
111
- readonly curvePower: 0.5;
112
- readonly x: 0;
113
- readonly y: 0;
114
- readonly rotation: 0;
115
- readonly opacity: 1;
116
- readonly blurEnabled: false;
117
- readonly blurRadius: 10;
118
- readonly brightnessEnabled: false;
119
- readonly brightness: 0;
120
- readonly sepiaEnabled: false;
121
- readonly grayscaleEnabled: false;
122
- readonly shadowEnabled: false;
123
- readonly shadowBlur: 5;
124
- readonly shadowOffsetX: 0;
125
- readonly shadowOffsetY: 0;
126
- readonly shadowColor: "black";
127
- readonly shadowOpacity: 1;
128
- readonly visible: true;
129
- readonly draggable: true;
130
- readonly resizable: true;
131
- readonly selectable: true;
132
- readonly contentEditable: true;
133
- readonly styleEditable: true;
134
- readonly alwaysOnTop: false;
135
- readonly showInExport: true;
136
- readonly name: "";
137
- readonly removable: true;
138
- };
139
- export declare const SVG_DEFAULTS: {
140
- readonly type: "svg";
141
- readonly src: "";
142
- readonly maskSrc: "";
143
- readonly cropX: 0;
144
- readonly cropY: 0;
145
- readonly cropWidth: 1;
146
- readonly cropHeight: 1;
147
- readonly keepRatio: true;
148
- readonly stretchEnabled: true;
149
- readonly flipX: false;
150
- readonly flipY: false;
151
- readonly width: 100;
152
- readonly height: 100;
153
- readonly borderColor: "black";
154
- readonly borderSize: 0;
155
- readonly cornerRadius: 0;
156
- readonly x: 0;
157
- readonly y: 0;
158
- readonly rotation: 0;
159
- readonly opacity: 1;
160
- readonly blurEnabled: false;
161
- readonly blurRadius: 10;
162
- readonly brightnessEnabled: false;
163
- readonly brightness: 0;
164
- readonly sepiaEnabled: false;
165
- readonly grayscaleEnabled: false;
166
- readonly shadowEnabled: false;
167
- readonly shadowBlur: 5;
168
- readonly shadowOffsetX: 0;
169
- readonly shadowOffsetY: 0;
170
- readonly shadowColor: "black";
171
- readonly shadowOpacity: 1;
172
- readonly visible: true;
173
- readonly draggable: true;
174
- readonly resizable: true;
175
- readonly selectable: true;
176
- readonly contentEditable: true;
177
- readonly styleEditable: true;
178
- readonly alwaysOnTop: false;
179
- readonly showInExport: true;
180
- readonly name: "";
181
- readonly removable: true;
182
- };
183
- export declare const LINE_DEFAULTS: {
184
- readonly type: "line";
185
- readonly width: 400;
186
- readonly height: 10;
187
- readonly color: "black";
188
- readonly startHead: "";
189
- readonly endHead: "";
190
- readonly x: 0;
191
- readonly y: 0;
192
- readonly rotation: 0;
193
- readonly opacity: 1;
194
- readonly blurEnabled: false;
195
- readonly blurRadius: 10;
196
- readonly brightnessEnabled: false;
197
- readonly brightness: 0;
198
- readonly sepiaEnabled: false;
199
- readonly grayscaleEnabled: false;
200
- readonly shadowEnabled: false;
201
- readonly shadowBlur: 5;
202
- readonly shadowOffsetX: 0;
203
- readonly shadowOffsetY: 0;
204
- readonly shadowColor: "black";
205
- readonly shadowOpacity: 1;
206
- readonly visible: true;
207
- readonly draggable: true;
208
- readonly resizable: true;
209
- readonly selectable: true;
210
- readonly contentEditable: true;
211
- readonly styleEditable: true;
212
- readonly alwaysOnTop: false;
213
- readonly showInExport: true;
214
- readonly name: "";
215
- readonly removable: true;
216
- };
217
- export declare const FIGURE_DEFAULTS: {
218
- readonly type: "figure";
219
- readonly subType: "rect";
220
- readonly fill: "rgb(0, 161, 255)";
221
- readonly strokeWidth: 0;
222
- readonly stroke: "rgba(98, 197, 255, 1)";
223
- readonly cornerRadius: 0;
224
- readonly x: 0;
225
- readonly y: 0;
226
- readonly width: 100;
227
- readonly height: 100;
228
- readonly rotation: 0;
229
- readonly opacity: 1;
230
- readonly blurEnabled: false;
231
- readonly blurRadius: 10;
232
- readonly brightnessEnabled: false;
233
- readonly brightness: 0;
234
- readonly sepiaEnabled: false;
235
- readonly grayscaleEnabled: false;
236
- readonly shadowEnabled: false;
237
- readonly shadowBlur: 5;
238
- readonly shadowOffsetX: 0;
239
- readonly shadowOffsetY: 0;
240
- readonly shadowColor: "black";
241
- readonly shadowOpacity: 1;
242
- readonly visible: true;
243
- readonly draggable: true;
244
- readonly resizable: true;
245
- readonly selectable: true;
246
- readonly contentEditable: true;
247
- readonly styleEditable: true;
248
- readonly alwaysOnTop: false;
249
- readonly showInExport: true;
250
- readonly name: "";
251
- readonly removable: true;
252
- };
253
- export declare const GIF_DEFAULTS: {
254
- readonly type: "gif";
255
- readonly duration: 0;
256
- readonly keepRatio: true;
257
- readonly width: 100;
258
- readonly height: 100;
259
- readonly src: "";
260
- readonly cropX: 0;
261
- readonly cropY: 0;
262
- readonly cropWidth: 1;
263
- readonly cropHeight: 1;
264
- readonly cornerRadius: 0;
265
- readonly flipX: false;
266
- readonly flipY: false;
267
- readonly clipSrc: "";
268
- readonly borderColor: "black";
269
- readonly borderSize: 0;
270
- readonly stretchEnabled: false;
271
- readonly x: 0;
272
- readonly y: 0;
273
- readonly rotation: 0;
274
- readonly opacity: 1;
275
- readonly blurEnabled: false;
276
- readonly blurRadius: 10;
277
- readonly brightnessEnabled: false;
278
- readonly brightness: 0;
279
- readonly sepiaEnabled: false;
280
- readonly grayscaleEnabled: false;
281
- readonly shadowEnabled: false;
282
- readonly shadowBlur: 5;
283
- readonly shadowOffsetX: 0;
284
- readonly shadowOffsetY: 0;
285
- readonly shadowColor: "black";
286
- readonly shadowOpacity: 1;
287
- readonly visible: true;
288
- readonly draggable: true;
289
- readonly resizable: true;
290
- readonly selectable: true;
291
- readonly contentEditable: true;
292
- readonly styleEditable: true;
293
- readonly alwaysOnTop: false;
294
- readonly showInExport: true;
295
- readonly name: "";
296
- readonly removable: true;
297
- };
298
- export declare const VIDEO_DEFAULTS: {
299
- readonly type: "video";
300
- readonly duration: 0;
301
- readonly startTime: 0;
302
- readonly endTime: 1;
303
- readonly volume: 1;
304
- readonly speed: 1;
305
- readonly width: 100;
306
- readonly height: 100;
307
- readonly src: "";
308
- readonly cropX: 0;
309
- readonly cropY: 0;
310
- readonly cropWidth: 1;
311
- readonly cropHeight: 1;
312
- readonly cornerRadius: 0;
313
- readonly flipX: false;
314
- readonly flipY: false;
315
- readonly clipSrc: "";
316
- readonly borderColor: "black";
317
- readonly borderSize: 0;
318
- readonly keepRatio: false;
319
- readonly stretchEnabled: false;
320
- readonly x: 0;
321
- readonly y: 0;
322
- readonly rotation: 0;
323
- readonly opacity: 1;
324
- readonly blurEnabled: false;
325
- readonly blurRadius: 10;
326
- readonly brightnessEnabled: false;
327
- readonly brightness: 0;
328
- readonly sepiaEnabled: false;
329
- readonly grayscaleEnabled: false;
330
- readonly shadowEnabled: false;
331
- readonly shadowBlur: 5;
332
- readonly shadowOffsetX: 0;
333
- readonly shadowOffsetY: 0;
334
- readonly shadowColor: "black";
335
- readonly shadowOpacity: 1;
336
- readonly visible: true;
337
- readonly draggable: true;
338
- readonly resizable: true;
339
- readonly selectable: true;
340
- readonly contentEditable: true;
341
- readonly styleEditable: true;
342
- readonly alwaysOnTop: false;
343
- readonly showInExport: true;
344
- readonly name: "";
345
- readonly removable: true;
346
- };
347
- export declare const TABLE_DEFAULTS: {
348
- readonly type: "table";
349
- readonly width: 300;
350
- readonly height: 200;
351
- readonly rows: 3;
352
- readonly cols: 3;
353
- readonly borderColor: "#000000";
354
- readonly borderWidth: 1;
355
- readonly borderStyle: "solid";
356
- readonly fontSize: 30;
357
- readonly fontFamily: "Roboto";
358
- readonly fontWeight: "normal";
359
- readonly fontStyle: "normal";
360
- readonly textDecoration: "";
361
46
  readonly textTransform: "none";
362
- readonly fill: "black";
47
+ readonly textDecoration: "";
363
48
  readonly align: "center";
364
- readonly verticalAlign: "middle";
365
- readonly lineHeight: 1.2;
366
- readonly letterSpacing: 0;
367
- readonly strokeWidth: 0;
49
+ readonly fill: "black";
368
50
  readonly stroke: "black";
369
- readonly cellBackground: "transparent";
370
- readonly cellPadding: 4;
371
- readonly x: 0;
372
- readonly y: 0;
373
- readonly rotation: 0;
374
- readonly opacity: 1;
375
- readonly blurEnabled: false;
376
- readonly blurRadius: 10;
377
- readonly brightnessEnabled: false;
378
- readonly brightness: 0;
379
- readonly sepiaEnabled: false;
380
- readonly grayscaleEnabled: false;
381
- readonly shadowEnabled: false;
382
- readonly shadowBlur: 5;
383
- readonly shadowOffsetX: 0;
384
- readonly shadowOffsetY: 0;
385
- readonly shadowColor: "black";
386
- readonly shadowOpacity: 1;
387
- readonly visible: true;
388
- readonly draggable: true;
389
- readonly resizable: true;
390
- readonly selectable: true;
391
- readonly contentEditable: true;
392
- readonly styleEditable: true;
393
- readonly alwaysOnTop: false;
394
- readonly showInExport: true;
395
- readonly name: "";
396
- readonly removable: true;
397
- };
398
- export declare const GROUP_DEFAULTS: {
399
- readonly type: "group";
400
- readonly name: "";
401
- readonly opacity: 1;
402
- readonly visible: true;
403
- readonly selectable: true;
404
- readonly removable: true;
405
- readonly alwaysOnTop: false;
406
- readonly showInExport: true;
407
- };
408
- export declare const TABLE_CELL_DEFAULTS: {
409
- readonly type: "tablecell";
410
- readonly text: "";
411
- readonly opacity: 1;
412
- readonly rowSpan: 1;
413
- readonly colSpan: 1;
414
- readonly name: "";
415
- };
416
- export declare const PAGE_DEFAULTS: {
417
- readonly width: "auto";
418
- readonly height: "auto";
419
- readonly background: "white";
420
- readonly bleed: 0;
421
- readonly duration: 5000;
422
- };
423
- export declare const AUDIO_DEFAULTS: {
424
- readonly src: "";
425
- readonly duration: 0;
426
- readonly startTime: 0;
427
- readonly endTime: 1;
428
- readonly volume: 1;
429
- readonly delay: 0;
430
- readonly speed: 1;
431
- };
432
- export declare const FONT_DEFAULTS: {
433
- readonly url: "";
434
- };
435
- export declare const STORE_DEFAULTS: {
436
- readonly width: 1080;
437
- readonly height: 1080;
438
- readonly unit: "px";
439
- readonly dpi: 72;
440
- readonly schemaVersion: 4;
51
+ readonly strokeWidth: 0;
52
+ readonly strokeLineJoin: "round";
53
+ readonly curveEnabled: false;
54
+ readonly curvePower: 0.5;
441
55
  };
442
- export declare const CURRENT_SCHEMA_VERSION = 4;
443
- export declare const DEFAULTS_BY_TYPE: Record<string, Record<string, unknown>>;
444
- export declare const STRUCTURAL_DEFAULTS_BY_TYPE: Record<string, Record<string, unknown>>;
445
- //# sourceMappingURL=defaults.d.ts.map