@polotno/schema 0.6.2 → 0.7.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.
@@ -0,0 +1,3 @@
1
+ export declare const URL_FIELDS: string[];
2
+ /** Visit each asset string in place, including nested groups and font styles. */
3
+ export declare function forEveryUrlField(node: unknown, visit: (node: Record<string, unknown>, key: string, value: string) => void): void;
@@ -0,0 +1,28 @@
1
+ // Asset fields belong to the design format. Keep this walk zod-free so Node
2
+ // renderers and fixture loaders can share it without importing validation.
3
+ // `custom` is arbitrary caller data; its strings must never be rewritten.
4
+ export const URL_FIELDS = ['src', 'clipSrc', 'maskSrc', 'background', 'url'];
5
+ const URL_FIELD_SET = new Set(URL_FIELDS);
6
+ /** Visit each asset string in place, including nested groups and font styles. */
7
+ export function forEveryUrlField(node, visit) {
8
+ if (!node || typeof node !== 'object')
9
+ return;
10
+ if (Array.isArray(node)) {
11
+ for (const item of node)
12
+ forEveryUrlField(item, visit);
13
+ return;
14
+ }
15
+ const record = node;
16
+ for (const key of Object.keys(record)) {
17
+ if (key === 'custom')
18
+ continue;
19
+ const value = record[key];
20
+ if (typeof value === 'string') {
21
+ if (URL_FIELD_SET.has(key))
22
+ visit(record, key, value);
23
+ }
24
+ else {
25
+ forEveryUrlField(value, visit);
26
+ }
27
+ }
28
+ }
package/lib/defaults.d.ts CHANGED
@@ -79,3 +79,5 @@ export declare const MIN_FONT_SIZE = 1;
79
79
  * the table", which is not a size to clamp.
80
80
  */
81
81
  export declare const clampFontSize: <T extends number | undefined>(size: T) => T;
82
+ 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"];
83
+ 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"];
package/lib/defaults.js CHANGED
@@ -127,3 +127,23 @@ export const MIN_FONT_SIZE = 1;
127
127
  * the table", which is not a size to clamp.
128
128
  */
129
129
  export const clampFontSize = (size) => (size != null && size < MIN_FONT_SIZE ? MIN_FONT_SIZE : size);
130
+ export const BLEND_MODES = [
131
+ 'normal',
132
+ 'multiply',
133
+ 'screen',
134
+ 'overlay',
135
+ 'darken',
136
+ 'lighten',
137
+ 'color-dodge',
138
+ 'color-burn',
139
+ 'hard-light',
140
+ 'soft-light',
141
+ 'difference',
142
+ 'exclusion',
143
+ 'hue',
144
+ 'saturation',
145
+ 'color',
146
+ 'luminosity',
147
+ ];
148
+ // A group's default: its children blend through it. Any other mode isolates it.
149
+ export const GROUP_BLEND_MODES = ['pass-through', ...BLEND_MODES];
@@ -235,7 +235,8 @@
235
235
  },
236
236
  "type": {
237
237
  "type": "string",
238
- "const": "text"
238
+ "const": "text",
239
+ "description": "Element type identifier."
239
240
  },
240
241
  "name": {
241
242
  "default": "",
@@ -275,6 +276,28 @@
275
276
  "description": "Opacity level (0-1).",
276
277
  "type": "number"
277
278
  },
279
+ "blendMode": {
280
+ "description": "How the element composites with the content beneath it. Omitted means normal.",
281
+ "type": "string",
282
+ "enum": [
283
+ "normal",
284
+ "multiply",
285
+ "screen",
286
+ "overlay",
287
+ "darken",
288
+ "lighten",
289
+ "color-dodge",
290
+ "color-burn",
291
+ "hard-light",
292
+ "soft-light",
293
+ "difference",
294
+ "exclusion",
295
+ "hue",
296
+ "saturation",
297
+ "color",
298
+ "luminosity"
299
+ ]
300
+ },
278
301
  "animations": {
279
302
  "default": [],
280
303
  "description": "Animation configurations.",
@@ -581,7 +604,8 @@
581
604
  },
582
605
  "type": {
583
606
  "type": "string",
584
- "const": "image"
607
+ "const": "image",
608
+ "description": "Element type identifier."
585
609
  },
586
610
  "name": {
587
611
  "default": "",
@@ -621,6 +645,28 @@
621
645
  "description": "Opacity level (0-1).",
622
646
  "type": "number"
623
647
  },
648
+ "blendMode": {
649
+ "description": "How the element composites with the content beneath it. Omitted means normal.",
650
+ "type": "string",
651
+ "enum": [
652
+ "normal",
653
+ "multiply",
654
+ "screen",
655
+ "overlay",
656
+ "darken",
657
+ "lighten",
658
+ "color-dodge",
659
+ "color-burn",
660
+ "hard-light",
661
+ "soft-light",
662
+ "difference",
663
+ "exclusion",
664
+ "hue",
665
+ "saturation",
666
+ "color",
667
+ "luminosity"
668
+ ]
669
+ },
624
670
  "animations": {
625
671
  "default": [],
626
672
  "description": "Animation configurations.",
@@ -870,7 +916,8 @@
870
916
  },
871
917
  "type": {
872
918
  "type": "string",
873
- "const": "svg"
919
+ "const": "svg",
920
+ "description": "Element type identifier."
874
921
  },
875
922
  "name": {
876
923
  "default": "",
@@ -892,10 +939,12 @@
892
939
  },
893
940
  "width": {
894
941
  "default": 100,
942
+ "description": "Width in pixels.",
895
943
  "type": "number"
896
944
  },
897
945
  "height": {
898
946
  "default": 100,
947
+ "description": "Height in pixels.",
899
948
  "type": "number"
900
949
  },
901
950
  "rotation": {
@@ -908,6 +957,28 @@
908
957
  "description": "Opacity level (0-1).",
909
958
  "type": "number"
910
959
  },
960
+ "blendMode": {
961
+ "description": "How the element composites with the content beneath it. Omitted means normal.",
962
+ "type": "string",
963
+ "enum": [
964
+ "normal",
965
+ "multiply",
966
+ "screen",
967
+ "overlay",
968
+ "darken",
969
+ "lighten",
970
+ "color-dodge",
971
+ "color-burn",
972
+ "hard-light",
973
+ "soft-light",
974
+ "difference",
975
+ "exclusion",
976
+ "hue",
977
+ "saturation",
978
+ "color",
979
+ "luminosity"
980
+ ]
981
+ },
911
982
  "animations": {
912
983
  "default": [],
913
984
  "description": "Animation configurations.",
@@ -1089,18 +1160,22 @@
1089
1160
  },
1090
1161
  "cropX": {
1091
1162
  "default": 0,
1163
+ "description": "Crop X offset as a fraction (0-1).",
1092
1164
  "type": "number"
1093
1165
  },
1094
1166
  "cropY": {
1095
1167
  "default": 0,
1168
+ "description": "Crop Y offset as a fraction (0-1).",
1096
1169
  "type": "number"
1097
1170
  },
1098
1171
  "cropWidth": {
1099
1172
  "default": 1,
1173
+ "description": "Crop width as a fraction (0-1).",
1100
1174
  "type": "number"
1101
1175
  },
1102
1176
  "cropHeight": {
1103
1177
  "default": 1,
1178
+ "description": "Crop height as a fraction (0-1).",
1104
1179
  "type": "number"
1105
1180
  },
1106
1181
  "keepRatio": {
@@ -1110,26 +1185,32 @@
1110
1185
  },
1111
1186
  "stretchEnabled": {
1112
1187
  "default": true,
1188
+ "description": "Whether stretch mode is enabled.",
1113
1189
  "type": "boolean"
1114
1190
  },
1115
1191
  "flipX": {
1116
1192
  "default": false,
1193
+ "description": "Whether the image is flipped horizontally.",
1117
1194
  "type": "boolean"
1118
1195
  },
1119
1196
  "flipY": {
1120
1197
  "default": false,
1198
+ "description": "Whether the image is flipped vertically.",
1121
1199
  "type": "boolean"
1122
1200
  },
1123
1201
  "borderColor": {
1124
1202
  "default": "black",
1203
+ "description": "Border color.",
1125
1204
  "type": "string"
1126
1205
  },
1127
1206
  "borderSize": {
1128
1207
  "default": 0,
1208
+ "description": "Border width in pixels.",
1129
1209
  "type": "number"
1130
1210
  },
1131
1211
  "cornerRadius": {
1132
1212
  "default": 0,
1213
+ "description": "Corner radius in pixels.",
1133
1214
  "type": "number"
1134
1215
  },
1135
1216
  "colorsReplace": {
@@ -1158,7 +1239,8 @@
1158
1239
  },
1159
1240
  "type": {
1160
1241
  "type": "string",
1161
- "const": "line"
1242
+ "const": "line",
1243
+ "description": "Element type identifier."
1162
1244
  },
1163
1245
  "name": {
1164
1246
  "default": "",
@@ -1180,10 +1262,12 @@
1180
1262
  },
1181
1263
  "width": {
1182
1264
  "default": 400,
1265
+ "description": "Width in pixels.",
1183
1266
  "type": "number"
1184
1267
  },
1185
1268
  "height": {
1186
1269
  "default": 10,
1270
+ "description": "Height in pixels.",
1187
1271
  "type": "number"
1188
1272
  },
1189
1273
  "rotation": {
@@ -1196,6 +1280,28 @@
1196
1280
  "description": "Opacity level (0-1).",
1197
1281
  "type": "number"
1198
1282
  },
1283
+ "blendMode": {
1284
+ "description": "How the element composites with the content beneath it. Omitted means normal.",
1285
+ "type": "string",
1286
+ "enum": [
1287
+ "normal",
1288
+ "multiply",
1289
+ "screen",
1290
+ "overlay",
1291
+ "darken",
1292
+ "lighten",
1293
+ "color-dodge",
1294
+ "color-burn",
1295
+ "hard-light",
1296
+ "soft-light",
1297
+ "difference",
1298
+ "exclusion",
1299
+ "hue",
1300
+ "saturation",
1301
+ "color",
1302
+ "luminosity"
1303
+ ]
1304
+ },
1199
1305
  "animations": {
1200
1306
  "default": [],
1201
1307
  "description": "Animation configurations.",
@@ -1403,7 +1509,8 @@
1403
1509
  },
1404
1510
  "type": {
1405
1511
  "type": "string",
1406
- "const": "figure"
1512
+ "const": "figure",
1513
+ "description": "Element type identifier."
1407
1514
  },
1408
1515
  "name": {
1409
1516
  "default": "",
@@ -1443,6 +1550,28 @@
1443
1550
  "description": "Opacity level (0-1).",
1444
1551
  "type": "number"
1445
1552
  },
1553
+ "blendMode": {
1554
+ "description": "How the element composites with the content beneath it. Omitted means normal.",
1555
+ "type": "string",
1556
+ "enum": [
1557
+ "normal",
1558
+ "multiply",
1559
+ "screen",
1560
+ "overlay",
1561
+ "darken",
1562
+ "lighten",
1563
+ "color-dodge",
1564
+ "color-burn",
1565
+ "hard-light",
1566
+ "soft-light",
1567
+ "difference",
1568
+ "exclusion",
1569
+ "hue",
1570
+ "saturation",
1571
+ "color",
1572
+ "luminosity"
1573
+ ]
1574
+ },
1446
1575
  "animations": {
1447
1576
  "default": [],
1448
1577
  "description": "Animation configurations.",
@@ -1632,14 +1761,17 @@
1632
1761
  },
1633
1762
  "strokeWidth": {
1634
1763
  "default": 0,
1764
+ "description": "Stroke width in pixels.",
1635
1765
  "type": "number"
1636
1766
  },
1637
1767
  "stroke": {
1638
1768
  "default": "rgba(98, 197, 255, 1)",
1769
+ "description": "Stroke color.",
1639
1770
  "type": "string"
1640
1771
  },
1641
1772
  "cornerRadius": {
1642
1773
  "default": 0,
1774
+ "description": "Corner radius in pixels.",
1643
1775
  "type": "number"
1644
1776
  }
1645
1777
  },
@@ -1657,7 +1789,8 @@
1657
1789
  },
1658
1790
  "type": {
1659
1791
  "type": "string",
1660
- "const": "gif"
1792
+ "const": "gif",
1793
+ "description": "Element type identifier."
1661
1794
  },
1662
1795
  "name": {
1663
1796
  "default": "",
@@ -1697,6 +1830,28 @@
1697
1830
  "description": "Opacity level (0-1).",
1698
1831
  "type": "number"
1699
1832
  },
1833
+ "blendMode": {
1834
+ "description": "How the element composites with the content beneath it. Omitted means normal.",
1835
+ "type": "string",
1836
+ "enum": [
1837
+ "normal",
1838
+ "multiply",
1839
+ "screen",
1840
+ "overlay",
1841
+ "darken",
1842
+ "lighten",
1843
+ "color-dodge",
1844
+ "color-burn",
1845
+ "hard-light",
1846
+ "soft-light",
1847
+ "difference",
1848
+ "exclusion",
1849
+ "hue",
1850
+ "saturation",
1851
+ "color",
1852
+ "luminosity"
1853
+ ]
1854
+ },
1700
1855
  "animations": {
1701
1856
  "default": [],
1702
1857
  "description": "Animation configurations.",
@@ -1923,6 +2078,7 @@
1923
2078
  },
1924
2079
  "keepRatio": {
1925
2080
  "default": true,
2081
+ "description": "Whether to maintain aspect ratio when resizing.",
1926
2082
  "type": "boolean"
1927
2083
  },
1928
2084
  "stretchEnabled": {
@@ -1950,7 +2106,8 @@
1950
2106
  },
1951
2107
  "type": {
1952
2108
  "type": "string",
1953
- "const": "video"
2109
+ "const": "video",
2110
+ "description": "Element type identifier."
1954
2111
  },
1955
2112
  "name": {
1956
2113
  "default": "",
@@ -1990,6 +2147,28 @@
1990
2147
  "description": "Opacity level (0-1).",
1991
2148
  "type": "number"
1992
2149
  },
2150
+ "blendMode": {
2151
+ "description": "How the element composites with the content beneath it. Omitted means normal.",
2152
+ "type": "string",
2153
+ "enum": [
2154
+ "normal",
2155
+ "multiply",
2156
+ "screen",
2157
+ "overlay",
2158
+ "darken",
2159
+ "lighten",
2160
+ "color-dodge",
2161
+ "color-burn",
2162
+ "hard-light",
2163
+ "soft-light",
2164
+ "difference",
2165
+ "exclusion",
2166
+ "hue",
2167
+ "saturation",
2168
+ "color",
2169
+ "luminosity"
2170
+ ]
2171
+ },
1993
2172
  "animations": {
1994
2173
  "default": [],
1995
2174
  "description": "Animation configurations.",
@@ -2305,6 +2484,28 @@
2305
2484
  "description": "Opacity level (0-1).",
2306
2485
  "type": "number"
2307
2486
  },
2487
+ "blendMode": {
2488
+ "description": "How the element composites with the content beneath it. Omitted means normal.",
2489
+ "type": "string",
2490
+ "enum": [
2491
+ "normal",
2492
+ "multiply",
2493
+ "screen",
2494
+ "overlay",
2495
+ "darken",
2496
+ "lighten",
2497
+ "color-dodge",
2498
+ "color-burn",
2499
+ "hard-light",
2500
+ "soft-light",
2501
+ "difference",
2502
+ "exclusion",
2503
+ "hue",
2504
+ "saturation",
2505
+ "color",
2506
+ "luminosity"
2507
+ ]
2508
+ },
2308
2509
  "animations": {
2309
2510
  "default": [],
2310
2511
  "description": "Animation configurations.",
@@ -2747,43 +2948,78 @@
2747
2948
  "type": "object",
2748
2949
  "properties": {
2749
2950
  "id": {
2750
- "type": "string"
2951
+ "type": "string",
2952
+ "description": "Unique identifier for the element."
2751
2953
  },
2752
2954
  "type": {
2753
2955
  "type": "string",
2754
- "const": "group"
2956
+ "const": "group",
2957
+ "description": "Element type identifier."
2755
2958
  },
2756
2959
  "name": {
2757
2960
  "default": "",
2961
+ "description": "Display name for the element.",
2758
2962
  "type": "string"
2759
2963
  },
2760
- "custom": {},
2964
+ "custom": {
2965
+ "description": "Custom data attached to the element."
2966
+ },
2761
2967
  "opacity": {
2762
2968
  "default": 1,
2969
+ "description": "Opacity level (0-1).",
2763
2970
  "type": "number"
2764
2971
  },
2972
+ "blendMode": {
2973
+ "description": "How the group composites with the content beneath it. Omitted means pass-through: children blend with that content directly. Any other mode composites the children together first.",
2974
+ "type": "string",
2975
+ "enum": [
2976
+ "pass-through",
2977
+ "normal",
2978
+ "multiply",
2979
+ "screen",
2980
+ "overlay",
2981
+ "darken",
2982
+ "lighten",
2983
+ "color-dodge",
2984
+ "color-burn",
2985
+ "hard-light",
2986
+ "soft-light",
2987
+ "difference",
2988
+ "exclusion",
2989
+ "hue",
2990
+ "saturation",
2991
+ "color",
2992
+ "luminosity"
2993
+ ]
2994
+ },
2765
2995
  "visible": {
2766
2996
  "default": true,
2997
+ "description": "Whether the element is visible.",
2767
2998
  "type": "boolean"
2768
2999
  },
2769
3000
  "selectable": {
2770
3001
  "default": true,
3002
+ "description": "Whether the element can be selected.",
2771
3003
  "type": "boolean"
2772
3004
  },
2773
3005
  "removable": {
2774
3006
  "default": true,
3007
+ "description": "Whether the element can be removed.",
2775
3008
  "type": "boolean"
2776
3009
  },
2777
3010
  "alwaysOnTop": {
2778
3011
  "default": false,
3012
+ "description": "Whether the element stays on top of others.",
2779
3013
  "type": "boolean"
2780
3014
  },
2781
3015
  "showInExport": {
2782
3016
  "default": true,
3017
+ "description": "Whether the element appears in exports.",
2783
3018
  "type": "boolean"
2784
3019
  },
2785
3020
  "animations": {
2786
3021
  "default": [],
3022
+ "description": "Animation configurations.",
2787
3023
  "type": "array",
2788
3024
  "items": {
2789
3025
  "type": "object",
package/lib/index.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  export type { PolotnoError, PolotnoErrorCode } from './errors.js';
2
+ export { URL_FIELDS, forEveryUrlField } from './asset-urls.js';
2
3
  export { normalizeDesign, parseDesign } from './normalize.js';
3
4
  export type { ParseOptions } from './normalize.js';
4
5
  export { migrateDesign } from './migrate.js';
5
6
  export type { MigrateOptions } from './migrate.js';
6
7
  export { resolveBleed, ZERO_BLEED } from './bleed.js';
7
8
  export type { ResolvedBleed } from './bleed.js';
8
- export { TEXT_DEFAULTS, TABLE_CELL_OVERRIDABLE_KEYS, resolveTableCellDefaults, resolveTableCellBorder, tableCellBorderInsets, } from './defaults.js';
9
+ export { BLEND_MODES, GROUP_BLEND_MODES, TEXT_DEFAULTS, TABLE_CELL_OVERRIDABLE_KEYS, resolveTableCellDefaults, resolveTableCellBorder, tableCellBorderInsets, } from './defaults.js';
9
10
  export { validateDesign, assertValidDesign, designSchemaLenient, designSchemaCanonical, CURRENT_SCHEMA_VERSION, } from './schema.js';
10
11
  export type { DesignInput, ValidationError, ValidationResult, ValidateOptions, } from './schema.js';
11
12
  export type * from './types.js';
package/lib/index.js CHANGED
@@ -2,9 +2,10 @@
2
2
  // Single source: the zod schema (`./schema`) provides validation, defaults, and
3
3
  // the generated JSON Schema; `./types` are the hand-written public TypeScript
4
4
  // types. zod is a regular dependency (normalize parses with it).
5
+ export { URL_FIELDS, forEveryUrlField } from './asset-urls.js';
5
6
  export { normalizeDesign, parseDesign } from './normalize.js';
6
7
  export { migrateDesign } from './migrate.js';
7
8
  export { resolveBleed, ZERO_BLEED } from './bleed.js';
8
9
  // Also available zod-free via the `@polotno/schema/defaults` subpath.
9
- export { TEXT_DEFAULTS, TABLE_CELL_OVERRIDABLE_KEYS, resolveTableCellDefaults, resolveTableCellBorder, tableCellBorderInsets, } from './defaults.js';
10
+ export { BLEND_MODES, GROUP_BLEND_MODES, TEXT_DEFAULTS, TABLE_CELL_OVERRIDABLE_KEYS, resolveTableCellDefaults, resolveTableCellBorder, tableCellBorderInsets, } from './defaults.js';
10
11
  export { validateDesign, assertValidDesign, designSchemaLenient, designSchemaCanonical, CURRENT_SCHEMA_VERSION, } from './schema.js';
package/lib/schema.d.ts CHANGED
@@ -152,6 +152,24 @@ export declare const leafSchemas: {
152
152
  y: z.ZodDefault<z.ZodNumber>;
153
153
  rotation: z.ZodDefault<z.ZodNumber>;
154
154
  opacity: z.ZodDefault<z.ZodNumber>;
155
+ blendMode: z.ZodOptional<z.ZodEnum<{
156
+ normal: "normal";
157
+ multiply: "multiply";
158
+ screen: "screen";
159
+ overlay: "overlay";
160
+ darken: "darken";
161
+ lighten: "lighten";
162
+ "color-dodge": "color-dodge";
163
+ "color-burn": "color-burn";
164
+ "hard-light": "hard-light";
165
+ "soft-light": "soft-light";
166
+ difference: "difference";
167
+ exclusion: "exclusion";
168
+ hue: "hue";
169
+ saturation: "saturation";
170
+ color: "color";
171
+ luminosity: "luminosity";
172
+ }>>;
155
173
  animations: z.ZodDefault<z.ZodArray<z.ZodObject<{
156
174
  delay: z.ZodDefault<z.ZodNumber>;
157
175
  duration: z.ZodDefault<z.ZodNumber>;
@@ -213,6 +231,24 @@ export declare const leafSchemas: {
213
231
  height: z.ZodDefault<z.ZodNumber>;
214
232
  rotation: z.ZodDefault<z.ZodNumber>;
215
233
  opacity: z.ZodDefault<z.ZodNumber>;
234
+ blendMode: z.ZodOptional<z.ZodEnum<{
235
+ normal: "normal";
236
+ multiply: "multiply";
237
+ screen: "screen";
238
+ overlay: "overlay";
239
+ darken: "darken";
240
+ lighten: "lighten";
241
+ "color-dodge": "color-dodge";
242
+ "color-burn": "color-burn";
243
+ "hard-light": "hard-light";
244
+ "soft-light": "soft-light";
245
+ difference: "difference";
246
+ exclusion: "exclusion";
247
+ hue: "hue";
248
+ saturation: "saturation";
249
+ color: "color";
250
+ luminosity: "luminosity";
251
+ }>>;
216
252
  animations: z.ZodDefault<z.ZodArray<z.ZodObject<{
217
253
  delay: z.ZodDefault<z.ZodNumber>;
218
254
  duration: z.ZodDefault<z.ZodNumber>;
@@ -262,8 +298,6 @@ export declare const leafSchemas: {
262
298
  stretchEnabled: z.ZodDefault<z.ZodBoolean>;
263
299
  flipX: z.ZodDefault<z.ZodBoolean>;
264
300
  flipY: z.ZodDefault<z.ZodBoolean>;
265
- width: z.ZodDefault<z.ZodNumber>;
266
- height: z.ZodDefault<z.ZodNumber>;
267
301
  borderColor: z.ZodDefault<z.ZodString>;
268
302
  borderSize: z.ZodDefault<z.ZodNumber>;
269
303
  cornerRadius: z.ZodDefault<z.ZodNumber>;
@@ -273,8 +307,28 @@ export declare const leafSchemas: {
273
307
  custom: z.ZodOptional<z.ZodUnknown>;
274
308
  x: z.ZodDefault<z.ZodNumber>;
275
309
  y: z.ZodDefault<z.ZodNumber>;
310
+ width: z.ZodDefault<z.ZodNumber>;
311
+ height: z.ZodDefault<z.ZodNumber>;
276
312
  rotation: z.ZodDefault<z.ZodNumber>;
277
313
  opacity: z.ZodDefault<z.ZodNumber>;
314
+ blendMode: z.ZodOptional<z.ZodEnum<{
315
+ normal: "normal";
316
+ multiply: "multiply";
317
+ screen: "screen";
318
+ overlay: "overlay";
319
+ darken: "darken";
320
+ lighten: "lighten";
321
+ "color-dodge": "color-dodge";
322
+ "color-burn": "color-burn";
323
+ "hard-light": "hard-light";
324
+ "soft-light": "soft-light";
325
+ difference: "difference";
326
+ exclusion: "exclusion";
327
+ hue: "hue";
328
+ saturation: "saturation";
329
+ color: "color";
330
+ luminosity: "luminosity";
331
+ }>>;
278
332
  animations: z.ZodDefault<z.ZodArray<z.ZodObject<{
279
333
  delay: z.ZodDefault<z.ZodNumber>;
280
334
  duration: z.ZodDefault<z.ZodNumber>;
@@ -327,6 +381,24 @@ export declare const leafSchemas: {
327
381
  y: z.ZodDefault<z.ZodNumber>;
328
382
  rotation: z.ZodDefault<z.ZodNumber>;
329
383
  opacity: z.ZodDefault<z.ZodNumber>;
384
+ blendMode: z.ZodOptional<z.ZodEnum<{
385
+ normal: "normal";
386
+ multiply: "multiply";
387
+ screen: "screen";
388
+ overlay: "overlay";
389
+ darken: "darken";
390
+ lighten: "lighten";
391
+ "color-dodge": "color-dodge";
392
+ "color-burn": "color-burn";
393
+ "hard-light": "hard-light";
394
+ "soft-light": "soft-light";
395
+ difference: "difference";
396
+ exclusion: "exclusion";
397
+ hue: "hue";
398
+ saturation: "saturation";
399
+ color: "color";
400
+ luminosity: "luminosity";
401
+ }>>;
330
402
  animations: z.ZodDefault<z.ZodArray<z.ZodObject<{
331
403
  delay: z.ZodDefault<z.ZodNumber>;
332
404
  duration: z.ZodDefault<z.ZodNumber>;
@@ -381,6 +453,24 @@ export declare const leafSchemas: {
381
453
  height: z.ZodDefault<z.ZodNumber>;
382
454
  rotation: z.ZodDefault<z.ZodNumber>;
383
455
  opacity: z.ZodDefault<z.ZodNumber>;
456
+ blendMode: z.ZodOptional<z.ZodEnum<{
457
+ normal: "normal";
458
+ multiply: "multiply";
459
+ screen: "screen";
460
+ overlay: "overlay";
461
+ darken: "darken";
462
+ lighten: "lighten";
463
+ "color-dodge": "color-dodge";
464
+ "color-burn": "color-burn";
465
+ "hard-light": "hard-light";
466
+ "soft-light": "soft-light";
467
+ difference: "difference";
468
+ exclusion: "exclusion";
469
+ hue: "hue";
470
+ saturation: "saturation";
471
+ color: "color";
472
+ luminosity: "luminosity";
473
+ }>>;
384
474
  animations: z.ZodDefault<z.ZodArray<z.ZodObject<{
385
475
  delay: z.ZodDefault<z.ZodNumber>;
386
476
  duration: z.ZodDefault<z.ZodNumber>;
@@ -443,6 +533,24 @@ export declare const leafSchemas: {
443
533
  height: z.ZodDefault<z.ZodNumber>;
444
534
  rotation: z.ZodDefault<z.ZodNumber>;
445
535
  opacity: z.ZodDefault<z.ZodNumber>;
536
+ blendMode: z.ZodOptional<z.ZodEnum<{
537
+ normal: "normal";
538
+ multiply: "multiply";
539
+ screen: "screen";
540
+ overlay: "overlay";
541
+ darken: "darken";
542
+ lighten: "lighten";
543
+ "color-dodge": "color-dodge";
544
+ "color-burn": "color-burn";
545
+ "hard-light": "hard-light";
546
+ "soft-light": "soft-light";
547
+ difference: "difference";
548
+ exclusion: "exclusion";
549
+ hue: "hue";
550
+ saturation: "saturation";
551
+ color: "color";
552
+ luminosity: "luminosity";
553
+ }>>;
446
554
  animations: z.ZodDefault<z.ZodArray<z.ZodObject<{
447
555
  delay: z.ZodDefault<z.ZodNumber>;
448
556
  duration: z.ZodDefault<z.ZodNumber>;
@@ -509,6 +617,24 @@ export declare const leafSchemas: {
509
617
  height: z.ZodDefault<z.ZodNumber>;
510
618
  rotation: z.ZodDefault<z.ZodNumber>;
511
619
  opacity: z.ZodDefault<z.ZodNumber>;
620
+ blendMode: z.ZodOptional<z.ZodEnum<{
621
+ normal: "normal";
622
+ multiply: "multiply";
623
+ screen: "screen";
624
+ overlay: "overlay";
625
+ darken: "darken";
626
+ lighten: "lighten";
627
+ "color-dodge": "color-dodge";
628
+ "color-burn": "color-burn";
629
+ "hard-light": "hard-light";
630
+ "soft-light": "soft-light";
631
+ difference: "difference";
632
+ exclusion: "exclusion";
633
+ hue: "hue";
634
+ saturation: "saturation";
635
+ color: "color";
636
+ luminosity: "luminosity";
637
+ }>>;
512
638
  animations: z.ZodDefault<z.ZodArray<z.ZodObject<{
513
639
  delay: z.ZodDefault<z.ZodNumber>;
514
640
  duration: z.ZodDefault<z.ZodNumber>;
@@ -652,6 +778,24 @@ export declare const leafSchemas: {
652
778
  y: z.ZodDefault<z.ZodNumber>;
653
779
  rotation: z.ZodDefault<z.ZodNumber>;
654
780
  opacity: z.ZodDefault<z.ZodNumber>;
781
+ blendMode: z.ZodOptional<z.ZodEnum<{
782
+ normal: "normal";
783
+ multiply: "multiply";
784
+ screen: "screen";
785
+ overlay: "overlay";
786
+ darken: "darken";
787
+ lighten: "lighten";
788
+ "color-dodge": "color-dodge";
789
+ "color-burn": "color-burn";
790
+ "hard-light": "hard-light";
791
+ "soft-light": "soft-light";
792
+ difference: "difference";
793
+ exclusion: "exclusion";
794
+ hue: "hue";
795
+ saturation: "saturation";
796
+ color: "color";
797
+ luminosity: "luminosity";
798
+ }>>;
655
799
  animations: z.ZodDefault<z.ZodArray<z.ZodObject<{
656
800
  delay: z.ZodDefault<z.ZodNumber>;
657
801
  duration: z.ZodDefault<z.ZodNumber>;
package/lib/schema.js CHANGED
@@ -25,7 +25,7 @@
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 { MIN_FONT_SIZE, clampFontSize, TEXT_DEFAULTS } from './defaults.js';
28
+ import { BLEND_MODES, GROUP_BLEND_MODES, MIN_FONT_SIZE, clampFontSize, TEXT_DEFAULTS, } from './defaults.js';
29
29
  export const CURRENT_SCHEMA_VERSION = 4;
30
30
  // Every element type the design format knows. Kept in sync with the
31
31
  // element discriminatedUnion in build() below.
@@ -70,6 +70,10 @@ function build(o) {
70
70
  .describe('Filter intensity (-1 to 1).'),
71
71
  }))
72
72
  .describe('Applied image filters keyed by filter name.');
73
+ const blendMode = z
74
+ .enum(BLEND_MODES)
75
+ .optional()
76
+ .describe('How the element composites with the content beneath it. Omitted means normal.');
73
77
  // Fields shared by every Shape-derived element. Defaults inline.
74
78
  const shapeBase = {
75
79
  id: z.string().describe('Unique identifier for the element.'),
@@ -85,6 +89,7 @@ function build(o) {
85
89
  height: z.number().default(100).describe('Height in pixels.'),
86
90
  rotation: z.number().default(0).describe('Rotation angle in degrees.'),
87
91
  opacity: z.number().default(1).describe('Opacity level (0-1).'),
92
+ blendMode,
88
93
  animations: z
89
94
  .array(animation)
90
95
  .default([])
@@ -198,7 +203,7 @@ function build(o) {
198
203
  };
199
204
  const textShape = {
200
205
  ...shapeBase,
201
- type: z.literal('text'),
206
+ type: z.literal('text').describe('Element type identifier.'),
202
207
  text: z.string().default('').describe('Visible text shown on canvas.'),
203
208
  placeholder: z
204
209
  .string()
@@ -301,31 +306,36 @@ function build(o) {
301
306
  .optional()
302
307
  .describe('Internal compatibility flag stamped by the v2→v3 migration.'),
303
308
  };
304
- const imageShape = { ...shapeBase, ...imageProps, type: z.literal('image') };
309
+ const imageShape = {
310
+ ...shapeBase,
311
+ ...imageProps,
312
+ type: z.literal('image').describe('Element type identifier.'),
313
+ };
305
314
  const svgShape = {
306
315
  ...shapeBase,
307
- type: z.literal('svg'),
316
+ type: z.literal('svg').describe('Element type identifier.'),
308
317
  src: z.string().default('').describe('URL or data URI of the SVG.'),
309
318
  maskSrc: z
310
319
  .string()
311
320
  .default('')
312
321
  .describe('URL or data URI for an SVG mask.'),
313
- cropX: z.number().default(0),
314
- cropY: z.number().default(0),
315
- cropWidth: z.number().default(1),
316
- cropHeight: z.number().default(1),
322
+ cropX: imageProps.cropX,
323
+ cropY: imageProps.cropY,
324
+ cropWidth: imageProps.cropWidth,
325
+ cropHeight: imageProps.cropHeight,
317
326
  keepRatio: z
318
327
  .boolean()
319
328
  .default(true)
320
329
  .describe('Whether to maintain aspect ratio when resizing.'),
321
- stretchEnabled: z.boolean().default(true),
322
- flipX: z.boolean().default(false),
323
- flipY: z.boolean().default(false),
324
- width: z.number().default(100),
325
- height: z.number().default(100),
326
- borderColor: z.string().default('black'),
327
- borderSize: z.number().default(0),
328
- cornerRadius: z.number().default(0),
330
+ stretchEnabled: z
331
+ .boolean()
332
+ .default(true)
333
+ .describe('Whether stretch mode is enabled.'),
334
+ flipX: imageProps.flipX,
335
+ flipY: imageProps.flipY,
336
+ borderColor: imageProps.borderColor,
337
+ borderSize: imageProps.borderSize,
338
+ cornerRadius: imageProps.cornerRadius,
329
339
  colorsReplace: z
330
340
  .record(z.string(), z.string())
331
341
  .default({})
@@ -333,9 +343,9 @@ function build(o) {
333
343
  };
334
344
  const lineShape = {
335
345
  ...shapeBase,
336
- type: z.literal('line'),
337
- width: z.number().default(400),
338
- height: z.number().default(10),
346
+ type: z.literal('line').describe('Element type identifier.'),
347
+ width: z.number().default(400).describe('Width in pixels.'),
348
+ height: z.number().default(10).describe('Height in pixels.'),
339
349
  color: z.string().default('black').describe('Line color.'),
340
350
  dash: z.array(z.number()).default([]).describe('Dash pattern array.'),
341
351
  startHead: z
@@ -349,28 +359,34 @@ function build(o) {
349
359
  };
350
360
  const figureShape = {
351
361
  ...shapeBase,
352
- type: z.literal('figure'),
362
+ type: z.literal('figure').describe('Element type identifier.'),
353
363
  subType: z
354
364
  .string()
355
365
  .default('rect')
356
366
  .describe('Figure subtype: rect, ellipse, triangle, etc.'),
357
367
  fill: z.string().default('rgb(0, 161, 255)').describe('Fill color.'),
358
368
  dash: z.array(z.number()).default([]).describe('Dash pattern array.'),
359
- strokeWidth: z.number().default(0),
360
- stroke: z.string().default('rgba(98, 197, 255, 1)'),
361
- cornerRadius: z.number().default(0),
369
+ strokeWidth: z.number().default(0).describe('Stroke width in pixels.'),
370
+ stroke: z
371
+ .string()
372
+ .default('rgba(98, 197, 255, 1)')
373
+ .describe('Stroke color.'),
374
+ cornerRadius: imageProps.cornerRadius,
362
375
  };
363
376
  const gifShape = {
364
377
  ...shapeBase,
365
378
  ...imageProps,
366
- type: z.literal('gif'),
379
+ type: z.literal('gif').describe('Element type identifier.'),
367
380
  duration: z.number().default(0).describe('GIF duration in milliseconds.'),
368
- keepRatio: z.boolean().default(true),
381
+ keepRatio: z
382
+ .boolean()
383
+ .default(true)
384
+ .describe('Whether to maintain aspect ratio when resizing.'),
369
385
  };
370
386
  const videoShape = {
371
387
  ...shapeBase,
372
388
  ...imageProps,
373
- type: z.literal('video'),
389
+ type: z.literal('video').describe('Element type identifier.'),
374
390
  duration: z.number().default(0).describe('Video duration in milliseconds.'),
375
391
  startTime: z.number().default(0).describe('Start offset (0-1).'),
376
392
  endTime: z.number().default(1).describe('End offset (0-1).'),
@@ -581,17 +597,21 @@ function build(o) {
581
597
  .describe('Default cell padding in pixels.'),
582
598
  };
583
599
  const groupShape = (element) => ({
584
- id: z.string(),
585
- type: z.literal('group'),
586
- name: z.string().default(''),
587
- custom: z.unknown().optional(),
588
- opacity: z.number().default(1),
589
- visible: z.boolean().default(true),
590
- selectable: z.boolean().default(true),
591
- removable: z.boolean().default(true),
592
- alwaysOnTop: z.boolean().default(false),
593
- showInExport: z.boolean().default(true),
594
- animations: z.array(animation).default([]),
600
+ id: shapeBase.id,
601
+ type: z.literal('group').describe('Element type identifier.'),
602
+ name: shapeBase.name,
603
+ custom: shapeBase.custom,
604
+ opacity: shapeBase.opacity,
605
+ blendMode: z
606
+ .enum(GROUP_BLEND_MODES)
607
+ .optional()
608
+ .describe('How the group composites with the content beneath it. Omitted means pass-through: children blend with that content directly. Any other mode composites the children together first.'),
609
+ visible: shapeBase.visible,
610
+ selectable: shapeBase.selectable,
611
+ removable: shapeBase.removable,
612
+ alwaysOnTop: shapeBase.alwaysOnTop,
613
+ showInExport: shapeBase.showInExport,
614
+ animations: shapeBase.animations,
595
615
  children: z
596
616
  .array(element)
597
617
  .default([])
package/lib/types.d.ts CHANGED
@@ -1,3 +1,6 @@
1
+ import type { BLEND_MODES, GROUP_BLEND_MODES } from './defaults.js';
2
+ export type BlendMode = (typeof BLEND_MODES)[number];
3
+ export type GroupBlendMode = (typeof GROUP_BLEND_MODES)[number];
1
4
  export interface Design {
2
5
  /** Schema version for compatibility / migration. */
3
6
  schemaVersion: number;
@@ -120,6 +123,8 @@ export interface ShapeAttributes {
120
123
  rotation: number;
121
124
  /** Opacity (0-1). */
122
125
  opacity: number;
126
+ /** How the element composites with the content beneath it. Omitted means normal. */
127
+ blendMode?: BlendMode;
123
128
  /** Animation configurations. */
124
129
  animations: Animation[];
125
130
  blurEnabled: boolean;
@@ -155,6 +160,8 @@ export interface GroupElement {
155
160
  name: string;
156
161
  custom?: unknown;
157
162
  opacity: number;
163
+ /** How the group composites with the content beneath it. Omitted means pass-through; any other mode composites the children together first. */
164
+ blendMode?: GroupBlendMode;
158
165
  visible: boolean;
159
166
  selectable: boolean;
160
167
  removable: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polotno/schema",
3
- "version": "0.6.2",
3
+ "version": "0.7.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",
@@ -16,6 +16,10 @@
16
16
  "import": "./lib/defaults.js",
17
17
  "types": "./lib/defaults.d.ts"
18
18
  },
19
+ "./asset-urls": {
20
+ "import": "./lib/asset-urls.js",
21
+ "types": "./lib/asset-urls.d.ts"
22
+ },
19
23
  "./json": {
20
24
  "import": "./lib/design.schema.json"
21
25
  },