@snowcone-app/design 0.0.0-stage → 0.2.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,496 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * The design format: the JSON every Snowcone editor writes and the server reads (ADR-0115 part 1). Zod schemas for
5
+ * every artboard, element type and effect, and the types inferred from them. Moved out of `@snowcone-app/canvas`
6
+ * (`state/CanvasStateV1.ts`) unchanged: a saved design that validated there validates here, byte for byte.
7
+ *
8
+ * Version 1. Within a major only additive changes (a new optional field, a new element type the server renders); a
9
+ * breaking change is a new major with a migration (`migrateDesign`), and the server accepts the current major and the
10
+ * one before it.
11
+ */
12
+
13
+ /**
14
+ * A custom (brand) font a design depends on: `{ family, url }` of a host-stored font binary plus optional
15
+ * weight/style descriptors (`customFonts` on the design).
16
+ */
17
+ interface CustomFont {
18
+ /** Family name, registered as-is (a family that collides with a Google Fonts family shadows it). */
19
+ family: string;
20
+ /** Host-stored font binary URL (must allow cross-origin GET). */
21
+ url: string;
22
+ /** CSS font-weight the file provides. Defaults to 400. */
23
+ weight?: number;
24
+ /** CSS font-style the file provides. Defaults to 'normal'. */
25
+ style?: "normal" | "italic";
26
+ }
27
+ declare const PointSchema: z.ZodObject<{
28
+ x: z.ZodNumber;
29
+ y: z.ZodNumber;
30
+ }, z.core.$strip>;
31
+ declare const StrokeConfigSchema: z.ZodObject<{
32
+ enabled: z.ZodBoolean;
33
+ color: z.ZodString;
34
+ width: z.ZodNumber;
35
+ dashArray: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
36
+ lineCap: z.ZodOptional<z.ZodEnum<{
37
+ butt: "butt";
38
+ round: "round";
39
+ square: "square";
40
+ }>>;
41
+ lineJoin: z.ZodOptional<z.ZodEnum<{
42
+ round: "round";
43
+ miter: "miter";
44
+ bevel: "bevel";
45
+ }>>;
46
+ miterLimit: z.ZodOptional<z.ZodNumber>;
47
+ opacity: z.ZodOptional<z.ZodNumber>;
48
+ feather: z.ZodOptional<z.ZodNumber>;
49
+ }, z.core.$strip>;
50
+ declare const ShadowConfigSchema: z.ZodObject<{
51
+ enabled: z.ZodBoolean;
52
+ color: z.ZodString;
53
+ blur: z.ZodNumber;
54
+ offsetX: z.ZodNumber;
55
+ offsetY: z.ZodNumber;
56
+ opacity: z.ZodOptional<z.ZodNumber>;
57
+ }, z.core.$strip>;
58
+ declare const KnockoutConfigSchema: z.ZodObject<{
59
+ fill: z.ZodOptional<z.ZodBoolean>;
60
+ stroke: z.ZodOptional<z.ZodBoolean>;
61
+ scope: z.ZodOptional<z.ZodEnum<{
62
+ group: "group";
63
+ artboard: "artboard";
64
+ }>>;
65
+ }, z.core.$strip>;
66
+ declare const DistressEffectSchema: z.ZodObject<{
67
+ enabled: z.ZodBoolean;
68
+ style: z.ZodEnum<{
69
+ custom: "custom";
70
+ worn: "worn";
71
+ cracked: "cracked";
72
+ grunge: "grunge";
73
+ retro: "retro";
74
+ }>;
75
+ intensity: z.ZodNumber;
76
+ fadeAmount: z.ZodOptional<z.ZodNumber>;
77
+ grainAmount: z.ZodOptional<z.ZodNumber>;
78
+ scratchAmount: z.ZodOptional<z.ZodNumber>;
79
+ edgeWear: z.ZodOptional<z.ZodNumber>;
80
+ textureUrl: z.ZodOptional<z.ZodString>;
81
+ textureOpacity: z.ZodOptional<z.ZodNumber>;
82
+ textureBlendMode: z.ZodOptional<z.ZodEnum<{
83
+ multiply: "multiply";
84
+ screen: "screen";
85
+ overlay: "overlay";
86
+ }>>;
87
+ seed: z.ZodOptional<z.ZodNumber>;
88
+ }, z.core.$strip>;
89
+ declare const MaskDefinitionSchema: z.ZodObject<{
90
+ id: z.ZodString;
91
+ type: z.ZodEnum<{
92
+ clip: "clip";
93
+ alpha: "alpha";
94
+ luma: "luma";
95
+ distress: "distress";
96
+ }>;
97
+ maskElement: z.ZodLazy<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
98
+ inverted: z.ZodOptional<z.ZodBoolean>;
99
+ feather: z.ZodOptional<z.ZodNumber>;
100
+ opacity: z.ZodOptional<z.ZodNumber>;
101
+ blendMode: z.ZodOptional<z.ZodString>;
102
+ }, z.core.$strip>;
103
+ declare const CharacterStyleSchema: z.ZodObject<{
104
+ color: z.ZodOptional<z.ZodString>;
105
+ fontFamily: z.ZodOptional<z.ZodString>;
106
+ fontSize: z.ZodOptional<z.ZodNumber>;
107
+ bold: z.ZodOptional<z.ZodBoolean>;
108
+ italic: z.ZodOptional<z.ZodBoolean>;
109
+ underline: z.ZodOptional<z.ZodBoolean>;
110
+ strikethrough: z.ZodOptional<z.ZodBoolean>;
111
+ letterSpacing: z.ZodOptional<z.ZodNumber>;
112
+ }, z.core.$strip>;
113
+ declare const TextSpanSchema: z.ZodObject<{
114
+ text: z.ZodString;
115
+ style: z.ZodObject<{
116
+ color: z.ZodOptional<z.ZodString>;
117
+ fontFamily: z.ZodOptional<z.ZodString>;
118
+ fontSize: z.ZodOptional<z.ZodNumber>;
119
+ bold: z.ZodOptional<z.ZodBoolean>;
120
+ italic: z.ZodOptional<z.ZodBoolean>;
121
+ underline: z.ZodOptional<z.ZodBoolean>;
122
+ strikethrough: z.ZodOptional<z.ZodBoolean>;
123
+ letterSpacing: z.ZodOptional<z.ZodNumber>;
124
+ }, z.core.$strip>;
125
+ }, z.core.$strip>;
126
+ declare const RichTextSchema: z.ZodObject<{
127
+ spans: z.ZodArray<z.ZodObject<{
128
+ text: z.ZodString;
129
+ style: z.ZodObject<{
130
+ color: z.ZodOptional<z.ZodString>;
131
+ fontFamily: z.ZodOptional<z.ZodString>;
132
+ fontSize: z.ZodOptional<z.ZodNumber>;
133
+ bold: z.ZodOptional<z.ZodBoolean>;
134
+ italic: z.ZodOptional<z.ZodBoolean>;
135
+ underline: z.ZodOptional<z.ZodBoolean>;
136
+ strikethrough: z.ZodOptional<z.ZodBoolean>;
137
+ letterSpacing: z.ZodOptional<z.ZodNumber>;
138
+ }, z.core.$strip>;
139
+ }, z.core.$strip>>;
140
+ }, z.core.$strip>;
141
+ declare const GlyphOverrideSchema: z.ZodObject<{
142
+ charIndex: z.ZodNumber;
143
+ glyphIndex: z.ZodNumber;
144
+ unicode: z.ZodString;
145
+ alternateName: z.ZodOptional<z.ZodString>;
146
+ }, z.core.$strip>;
147
+ declare const OpenTypeFeaturesSchema: z.ZodObject<{
148
+ liga: z.ZodOptional<z.ZodBoolean>;
149
+ dlig: z.ZodOptional<z.ZodBoolean>;
150
+ calt: z.ZodOptional<z.ZodBoolean>;
151
+ swsh: z.ZodOptional<z.ZodBoolean>;
152
+ smcp: z.ZodOptional<z.ZodBoolean>;
153
+ c2sc: z.ZodOptional<z.ZodBoolean>;
154
+ onum: z.ZodOptional<z.ZodBoolean>;
155
+ lnum: z.ZodOptional<z.ZodBoolean>;
156
+ tnum: z.ZodOptional<z.ZodBoolean>;
157
+ pnum: z.ZodOptional<z.ZodBoolean>;
158
+ ss01: z.ZodOptional<z.ZodBoolean>;
159
+ ss02: z.ZodOptional<z.ZodBoolean>;
160
+ ss03: z.ZodOptional<z.ZodBoolean>;
161
+ ss04: z.ZodOptional<z.ZodBoolean>;
162
+ ss05: z.ZodOptional<z.ZodBoolean>;
163
+ ss06: z.ZodOptional<z.ZodBoolean>;
164
+ ss07: z.ZodOptional<z.ZodBoolean>;
165
+ ss08: z.ZodOptional<z.ZodBoolean>;
166
+ ss09: z.ZodOptional<z.ZodBoolean>;
167
+ ss10: z.ZodOptional<z.ZodBoolean>;
168
+ ss11: z.ZodOptional<z.ZodBoolean>;
169
+ ss12: z.ZodOptional<z.ZodBoolean>;
170
+ ss13: z.ZodOptional<z.ZodBoolean>;
171
+ ss14: z.ZodOptional<z.ZodBoolean>;
172
+ ss15: z.ZodOptional<z.ZodBoolean>;
173
+ ss16: z.ZodOptional<z.ZodBoolean>;
174
+ ss17: z.ZodOptional<z.ZodBoolean>;
175
+ ss18: z.ZodOptional<z.ZodBoolean>;
176
+ ss19: z.ZodOptional<z.ZodBoolean>;
177
+ ss20: z.ZodOptional<z.ZodBoolean>;
178
+ cv01: z.ZodOptional<z.ZodBoolean>;
179
+ cv02: z.ZodOptional<z.ZodBoolean>;
180
+ cv03: z.ZodOptional<z.ZodBoolean>;
181
+ cv04: z.ZodOptional<z.ZodBoolean>;
182
+ cv05: z.ZodOptional<z.ZodBoolean>;
183
+ ccmp: z.ZodOptional<z.ZodBoolean>;
184
+ locl: z.ZodOptional<z.ZodBoolean>;
185
+ kern: z.ZodOptional<z.ZodBoolean>;
186
+ mark: z.ZodOptional<z.ZodBoolean>;
187
+ mkmk: z.ZodOptional<z.ZodBoolean>;
188
+ }, z.core.$strip>;
189
+ declare const AnyTransformDataSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
190
+ type: z.ZodLiteral<"custom">;
191
+ controlPoints: z.ZodArray<z.ZodObject<{
192
+ x: z.ZodNumber;
193
+ y: z.ZodNumber;
194
+ }, z.core.$strip>>;
195
+ }, z.core.$loose>, z.ZodObject<{
196
+ type: z.ZodLiteral<"distort">;
197
+ }, z.core.$loose>, z.ZodObject<{
198
+ type: z.ZodLiteral<"circle">;
199
+ radius: z.ZodNumber;
200
+ scale: z.ZodNumber;
201
+ reverse: z.ZodBoolean;
202
+ }, z.core.$strip>, z.ZodObject<{
203
+ type: z.ZodLiteral<"lean">;
204
+ leanAmount: z.ZodNumber;
205
+ }, z.core.$loose>, z.ZodObject<{
206
+ type: z.ZodLiteral<"arch">;
207
+ archHeight: z.ZodNumber;
208
+ }, z.core.$loose>, z.ZodObject<{
209
+ type: z.ZodLiteral<"ascend">;
210
+ ascendAngle: z.ZodNumber;
211
+ }, z.core.$loose>, z.ZodObject<{
212
+ type: z.ZodLiteral<"wave">;
213
+ amplitude: z.ZodNumber;
214
+ frequency: z.ZodNumber;
215
+ }, z.core.$loose>, z.ZodObject<{
216
+ type: z.ZodLiteral<"flag">;
217
+ amplitude: z.ZodNumber;
218
+ frequency: z.ZodNumber;
219
+ }, z.core.$loose>, z.ZodObject<{
220
+ type: z.ZodLiteral<"image">;
221
+ width: z.ZodNumber;
222
+ height: z.ZodNumber;
223
+ cropX: z.ZodNumber;
224
+ cropY: z.ZodNumber;
225
+ cropWidth: z.ZodNumber;
226
+ cropHeight: z.ZodNumber;
227
+ flipHorizontal: z.ZodBoolean;
228
+ flipVertical: z.ZodBoolean;
229
+ borderRadius: z.ZodNumber;
230
+ maskedCrop: z.ZodOptional<z.ZodLiteral<"frame">>;
231
+ engrave: z.ZodOptional<z.ZodObject<{
232
+ style: z.ZodEnum<{
233
+ photo: "photo";
234
+ drawing: "drawing";
235
+ solid: "solid";
236
+ original: "original";
237
+ }>;
238
+ amount: z.ZodNumber;
239
+ invert: z.ZodBoolean;
240
+ sourceUrl: z.ZodString;
241
+ cutLight: z.ZodBoolean;
242
+ }, z.core.$strip>>;
243
+ adjustments: z.ZodOptional<z.ZodObject<{
244
+ brightness: z.ZodNumber;
245
+ contrast: z.ZodNumber;
246
+ saturation: z.ZodNumber;
247
+ }, z.core.$strip>>;
248
+ }, z.core.$strip>, z.ZodObject<{
249
+ type: z.ZodLiteral<"group">;
250
+ }, z.core.$strip>, z.ZodObject<{
251
+ type: z.ZodLiteral<"shape">;
252
+ shapeType: z.ZodEnum<{
253
+ circle: "circle";
254
+ rectangle: "rectangle";
255
+ ellipse: "ellipse";
256
+ triangle: "triangle";
257
+ polygon: "polygon";
258
+ star: "star";
259
+ line: "line";
260
+ }>;
261
+ width: z.ZodNumber;
262
+ height: z.ZodNumber;
263
+ borderRadius: z.ZodOptional<z.ZodNumber>;
264
+ radiusX: z.ZodOptional<z.ZodNumber>;
265
+ radiusY: z.ZodOptional<z.ZodNumber>;
266
+ sides: z.ZodOptional<z.ZodNumber>;
267
+ points: z.ZodOptional<z.ZodNumber>;
268
+ innerRadius: z.ZodOptional<z.ZodNumber>;
269
+ fillColor: z.ZodOptional<z.ZodString>;
270
+ fillOpacity: z.ZodOptional<z.ZodNumber>;
271
+ fill: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
272
+ type: z.ZodLiteral<"solid">;
273
+ color: z.ZodString;
274
+ }, z.core.$strip>, z.ZodObject<{
275
+ type: z.ZodLiteral<"linear">;
276
+ angle: z.ZodNumber;
277
+ stops: z.ZodArray<z.ZodObject<{
278
+ offset: z.ZodNumber;
279
+ color: z.ZodString;
280
+ }, z.core.$strip>>;
281
+ }, z.core.$strip>, z.ZodObject<{
282
+ type: z.ZodLiteral<"radial">;
283
+ stops: z.ZodArray<z.ZodObject<{
284
+ offset: z.ZodNumber;
285
+ color: z.ZodString;
286
+ }, z.core.$strip>>;
287
+ }, z.core.$strip>], "type">>;
288
+ }, z.core.$strip>, z.ZodObject<{
289
+ type: z.ZodLiteral<"path">;
290
+ points: z.ZodArray<z.ZodObject<{
291
+ id: z.ZodString;
292
+ x: z.ZodNumber;
293
+ y: z.ZodNumber;
294
+ type: z.ZodEnum<{
295
+ corner: "corner";
296
+ smooth: "smooth";
297
+ bezier: "bezier";
298
+ }>;
299
+ handleIn: z.ZodOptional<z.ZodObject<{
300
+ x: z.ZodNumber;
301
+ y: z.ZodNumber;
302
+ }, z.core.$strip>>;
303
+ handleOut: z.ZodOptional<z.ZodObject<{
304
+ x: z.ZodNumber;
305
+ y: z.ZodNumber;
306
+ }, z.core.$strip>>;
307
+ }, z.core.$strip>>;
308
+ closed: z.ZodBoolean;
309
+ width: z.ZodNumber;
310
+ height: z.ZodNumber;
311
+ fillEnabled: z.ZodOptional<z.ZodBoolean>;
312
+ fillColor: z.ZodOptional<z.ZodString>;
313
+ fillOpacity: z.ZodOptional<z.ZodNumber>;
314
+ strokeEnabled: z.ZodOptional<z.ZodBoolean>;
315
+ strokeColor: z.ZodOptional<z.ZodString>;
316
+ strokeWidth: z.ZodOptional<z.ZodNumber>;
317
+ }, z.core.$strip>], "type">;
318
+ /**
319
+ * Discriminated union of all element config schemas.
320
+ * Discriminant field: `transformType`.
321
+ */
322
+ declare const AnyElementConfigSchema: z.ZodType;
323
+ declare const ClipShapeSchema: z.ZodUnion<readonly [z.ZodLiteral<"rectangle">, z.ZodLiteral<"circle">, z.ZodObject<{
324
+ type: z.ZodLiteral<"rounded">;
325
+ radius: z.ZodNumber;
326
+ }, z.core.$strip>, z.ZodObject<{
327
+ type: z.ZodLiteral<"path">;
328
+ d: z.ZodString;
329
+ }, z.core.$strip>, z.ZodObject<{
330
+ type: z.ZodLiteral<"composite-path">;
331
+ pieces: z.ZodArray<z.ZodObject<{
332
+ d: z.ZodString;
333
+ x: z.ZodNumber;
334
+ y: z.ZodNumber;
335
+ rotation: z.ZodOptional<z.ZodNumber>;
336
+ baseWidth: z.ZodOptional<z.ZodNumber>;
337
+ baseHeight: z.ZodOptional<z.ZodNumber>;
338
+ }, z.core.$strip>>;
339
+ }, z.core.$strip>]>;
340
+ declare const ArtboardImageMaskSchema: z.ZodObject<{
341
+ enabled: z.ZodBoolean;
342
+ imageUrl: z.ZodString;
343
+ maskType: z.ZodEnum<{
344
+ clip: "clip";
345
+ alpha: "alpha";
346
+ luma: "luma";
347
+ }>;
348
+ opacity: z.ZodNumber;
349
+ inverted: z.ZodOptional<z.ZodBoolean>;
350
+ }, z.core.$strip>;
351
+ declare const SerializedArtboardSchema: z.ZodObject<{
352
+ id: z.ZodString;
353
+ name: z.ZodString;
354
+ x: z.ZodNumber;
355
+ y: z.ZodNumber;
356
+ width: z.ZodNumber;
357
+ height: z.ZodNumber;
358
+ backgroundColor: z.ZodString;
359
+ backgroundType: z.ZodOptional<z.ZodEnum<{
360
+ color: "color";
361
+ transparent: "transparent";
362
+ texture: "texture";
363
+ }>>;
364
+ backgroundTexture: z.ZodOptional<z.ZodString>;
365
+ exportBackground: z.ZodOptional<z.ZodBoolean>;
366
+ clipShape: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"rectangle">, z.ZodLiteral<"circle">, z.ZodObject<{
367
+ type: z.ZodLiteral<"rounded">;
368
+ radius: z.ZodNumber;
369
+ }, z.core.$strip>, z.ZodObject<{
370
+ type: z.ZodLiteral<"path">;
371
+ d: z.ZodString;
372
+ }, z.core.$strip>, z.ZodObject<{
373
+ type: z.ZodLiteral<"composite-path">;
374
+ pieces: z.ZodArray<z.ZodObject<{
375
+ d: z.ZodString;
376
+ x: z.ZodNumber;
377
+ y: z.ZodNumber;
378
+ rotation: z.ZodOptional<z.ZodNumber>;
379
+ baseWidth: z.ZodOptional<z.ZodNumber>;
380
+ baseHeight: z.ZodOptional<z.ZodNumber>;
381
+ }, z.core.$strip>>;
382
+ }, z.core.$strip>]>>;
383
+ previewBackgroundColor: z.ZodOptional<z.ZodString>;
384
+ distressTexture: z.ZodOptional<z.ZodObject<{
385
+ enabled: z.ZodBoolean;
386
+ textureUrl: z.ZodString;
387
+ intensity: z.ZodNumber;
388
+ }, z.core.$strip>>;
389
+ imageMask: z.ZodOptional<z.ZodObject<{
390
+ enabled: z.ZodBoolean;
391
+ imageUrl: z.ZodString;
392
+ maskType: z.ZodEnum<{
393
+ clip: "clip";
394
+ alpha: "alpha";
395
+ luma: "luma";
396
+ }>;
397
+ opacity: z.ZodNumber;
398
+ inverted: z.ZodOptional<z.ZodBoolean>;
399
+ }, z.core.$strip>>;
400
+ role: z.ZodOptional<z.ZodEnum<{
401
+ cover: "cover";
402
+ "front-matter": "front-matter";
403
+ repeating: "repeating";
404
+ "back-matter": "back-matter";
405
+ }>>;
406
+ elementIds: z.ZodArray<z.ZodString>;
407
+ }, z.core.$strip>;
408
+ /**
409
+ * A custom (brand) font dependency of the design — `{ family, url }` of a
410
+ * host-stored font binary plus optional weight/style descriptors. Saved
411
+ * designs carry these so every consumer (live editor, export worker, server
412
+ * render) can load the exact file. Families are stored as-is; a family that
413
+ * collides with a Google Fonts family deterministically SHADOWS it (see
414
+ * `utils/custom-fonts.ts` for the resolution contract).
415
+ */
416
+ declare const CustomFontSchema: z.ZodType<CustomFont>;
417
+ /**
418
+ * Top-level CanvasStateV1 schema.
419
+ *
420
+ * - `version` is always `1` (literal).
421
+ * - `artboards` contains serialized artboard configs with `elementIds`.
422
+ * - `elements` is a flat array of all elements across all artboards.
423
+ * - `activeArtboardId` identifies which artboard is currently active.
424
+ * - `customFonts` (optional) lists the design's custom-font dependencies.
425
+ */
426
+ declare const CanvasStateV1Schema: z.ZodObject<{
427
+ version: z.ZodLiteral<1>;
428
+ artboards: z.ZodArray<z.ZodObject<{
429
+ id: z.ZodString;
430
+ name: z.ZodString;
431
+ x: z.ZodNumber;
432
+ y: z.ZodNumber;
433
+ width: z.ZodNumber;
434
+ height: z.ZodNumber;
435
+ backgroundColor: z.ZodString;
436
+ backgroundType: z.ZodOptional<z.ZodEnum<{
437
+ color: "color";
438
+ transparent: "transparent";
439
+ texture: "texture";
440
+ }>>;
441
+ backgroundTexture: z.ZodOptional<z.ZodString>;
442
+ exportBackground: z.ZodOptional<z.ZodBoolean>;
443
+ clipShape: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"rectangle">, z.ZodLiteral<"circle">, z.ZodObject<{
444
+ type: z.ZodLiteral<"rounded">;
445
+ radius: z.ZodNumber;
446
+ }, z.core.$strip>, z.ZodObject<{
447
+ type: z.ZodLiteral<"path">;
448
+ d: z.ZodString;
449
+ }, z.core.$strip>, z.ZodObject<{
450
+ type: z.ZodLiteral<"composite-path">;
451
+ pieces: z.ZodArray<z.ZodObject<{
452
+ d: z.ZodString;
453
+ x: z.ZodNumber;
454
+ y: z.ZodNumber;
455
+ rotation: z.ZodOptional<z.ZodNumber>;
456
+ baseWidth: z.ZodOptional<z.ZodNumber>;
457
+ baseHeight: z.ZodOptional<z.ZodNumber>;
458
+ }, z.core.$strip>>;
459
+ }, z.core.$strip>]>>;
460
+ previewBackgroundColor: z.ZodOptional<z.ZodString>;
461
+ distressTexture: z.ZodOptional<z.ZodObject<{
462
+ enabled: z.ZodBoolean;
463
+ textureUrl: z.ZodString;
464
+ intensity: z.ZodNumber;
465
+ }, z.core.$strip>>;
466
+ imageMask: z.ZodOptional<z.ZodObject<{
467
+ enabled: z.ZodBoolean;
468
+ imageUrl: z.ZodString;
469
+ maskType: z.ZodEnum<{
470
+ clip: "clip";
471
+ alpha: "alpha";
472
+ luma: "luma";
473
+ }>;
474
+ opacity: z.ZodNumber;
475
+ inverted: z.ZodOptional<z.ZodBoolean>;
476
+ }, z.core.$strip>>;
477
+ role: z.ZodOptional<z.ZodEnum<{
478
+ cover: "cover";
479
+ "front-matter": "front-matter";
480
+ repeating: "repeating";
481
+ "back-matter": "back-matter";
482
+ }>>;
483
+ elementIds: z.ZodArray<z.ZodString>;
484
+ }, z.core.$strip>>;
485
+ elements: z.ZodArray<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
486
+ activeArtboardId: z.ZodString;
487
+ customFonts: z.ZodOptional<z.ZodArray<z.ZodType<CustomFont, unknown, z.core.$ZodTypeInternals<CustomFont, unknown>>>>;
488
+ }, z.core.$strip>;
489
+ /** A serialized artboard (artboard config + elementIds, no nested elements). */
490
+ type SerializedArtboard = z.infer<typeof SerializedArtboardSchema>;
491
+ /** A serialized element (discriminated union on `transformType`). */
492
+ type SerializedElement = z.infer<typeof AnyElementConfigSchema>;
493
+ /** The full versioned state document. */
494
+ type CanvasStateV1 = z.infer<typeof CanvasStateV1Schema>;
495
+
496
+ export { AnyElementConfigSchema as A, type CanvasStateV1 as C, DistressEffectSchema as D, GlyphOverrideSchema as G, KnockoutConfigSchema as K, MaskDefinitionSchema as M, OpenTypeFeaturesSchema as O, PointSchema as P, RichTextSchema as R, type SerializedArtboard as S, TextSpanSchema as T, AnyTransformDataSchema as a, ArtboardImageMaskSchema as b, CanvasStateV1Schema as c, CharacterStyleSchema as d, ClipShapeSchema as e, type CustomFont as f, CustomFontSchema as g, SerializedArtboardSchema as h, type SerializedElement as i, ShadowConfigSchema as j, StrokeConfigSchema as k };
@@ -0,0 +1,161 @@
1
+ 'use strict';
2
+
3
+ // src/wire/adjustments.ts
4
+ var NEUTRAL_ADJUSTMENTS = Object.freeze({
5
+ brightness: 1,
6
+ contrast: 1,
7
+ saturation: 1
8
+ });
9
+ var EPSILON = 1e-3;
10
+ function isNeutralAdjustments(adjustments) {
11
+ if (!adjustments) return true;
12
+ return Math.abs(adjustments.brightness - 1) < EPSILON && Math.abs(adjustments.contrast - 1) < EPSILON && Math.abs(adjustments.saturation - 1) < EPSILON;
13
+ }
14
+
15
+ // src/wire/crop.ts
16
+ var MASKED_CROP_FRAME = "frame";
17
+ var FULL_CROP = Object.freeze({ cropX: 0, cropY: 0, cropWidth: 1, cropHeight: 1 });
18
+ function isFullCrop(c) {
19
+ const e = 1e-9;
20
+ return Math.abs(c.cropX ?? 0) < e && Math.abs(c.cropY ?? 0) < e && Math.abs((c.cropWidth ?? 1) - 1) < e && Math.abs((c.cropHeight ?? 1) - 1) < e;
21
+ }
22
+ function isLegacyMaskedCrop(td, hasMasks) {
23
+ return hasMasks && td?.maskedCrop !== MASKED_CROP_FRAME;
24
+ }
25
+ function effectiveImageCrop(td, hasMasks) {
26
+ if (!td || isLegacyMaskedCrop(td, hasMasks)) return { ...FULL_CROP };
27
+ return {
28
+ cropX: td.cropX ?? 0,
29
+ cropY: td.cropY ?? 0,
30
+ cropWidth: td.cropWidth ?? 1,
31
+ cropHeight: td.cropHeight ?? 1
32
+ };
33
+ }
34
+ function imageFrameSize(td, hasMasks) {
35
+ const c = effectiveImageCrop(td, hasMasks);
36
+ return { width: (td?.width ?? 0) * c.cropWidth, height: (td?.height ?? 0) * c.cropHeight };
37
+ }
38
+ function hasImageMasks(el) {
39
+ return Array.isArray(el?.masks) && el.masks.length > 0;
40
+ }
41
+
42
+ // src/wire/index.ts
43
+ var CANVAS_STATE_SCHEMA_VERSION = 1;
44
+ function q(n) {
45
+ return typeof n === "number" && Number.isFinite(n) ? Math.round(n * 100) / 100 : n;
46
+ }
47
+ function quantizeGeometry(el) {
48
+ return {
49
+ ...el,
50
+ ...el.x !== void 0 && { x: q(el.x) },
51
+ ...el.y !== void 0 && { y: q(el.y) },
52
+ ...el.width !== void 0 && { width: q(el.width) },
53
+ ...el.height !== void 0 && { height: q(el.height) },
54
+ ...el.rotation !== void 0 && { rotation: q(el.rotation) }
55
+ };
56
+ }
57
+ function serializeStateForServer(state) {
58
+ const srcArtboards = state.artboards?.length ? state.artboards : [{ name: "Front", width: 800, height: 800 }];
59
+ const elementsByArtboard = srcArtboards.map(() => []);
60
+ for (const el of state.elements || []) {
61
+ const tag = el?.artboard;
62
+ const idx = typeof tag === "string" ? srcArtboards.findIndex((ab) => (ab.name || "Front") === tag) : -1;
63
+ if (el?.visible === false) continue;
64
+ elementsByArtboard[idx >= 0 ? idx : 0].push(serializeElement(el));
65
+ }
66
+ return {
67
+ schemaVersion: CANVAS_STATE_SCHEMA_VERSION,
68
+ artboards: srcArtboards.map((srcArtboard, i) => ({
69
+ id: `artboard-${i + 1}`,
70
+ name: srcArtboard.name || "Front",
71
+ x: 0,
72
+ y: 0,
73
+ width: q(srcArtboard.width || 800),
74
+ height: q(srcArtboard.height || 800),
75
+ backgroundColor: srcArtboard.backgroundColor || "transparent",
76
+ // Pass the artboard's flag through — the server worker only paints the
77
+ // background when this is true. Hardcoding `false` here silently dropped
78
+ // explicitly-set artboard backgrounds from every realtime mockup while
79
+ // the editor kept showing them (WYSIWYG drift).
80
+ exportBackground: srcArtboard.exportBackground ?? false,
81
+ elements: elementsByArtboard[i],
82
+ distressTexture: srcArtboard.distressTexture,
83
+ imageMask: srcArtboard.imageMask
84
+ })),
85
+ // Custom (brand) font dependencies ride the wire so the server worker can
86
+ // load them — without this, server renders of custom-font designs fall
87
+ // back to the wrong family even when the bundle supports custom fonts.
88
+ ...state.customFonts?.length ? { customFonts: state.customFonts } : {}
89
+ };
90
+ }
91
+ function serializeElement(el) {
92
+ const type = el.type || el.transformType;
93
+ if (type === "image") {
94
+ return serializeImageElement(el);
95
+ }
96
+ const { artboard: _artboard, ...rest } = el;
97
+ if (type === "group" && Array.isArray(el.children)) {
98
+ rest.children = el.children.filter((c) => c && c.visible !== false).map(serializeElement);
99
+ }
100
+ return quantizeGeometry({
101
+ ...rest,
102
+ type
103
+ });
104
+ }
105
+ function serializeImageElement(el) {
106
+ const td = el.transformData || {};
107
+ const hasMasks = hasImageMasks(el);
108
+ const crop = effectiveImageCrop(td, hasMasks);
109
+ const fullWidth = td.width || 0;
110
+ const fullHeight = td.height || 0;
111
+ const visibleWidth = fullWidth * crop.cropWidth;
112
+ const visibleHeight = fullHeight * crop.cropHeight;
113
+ const serialized = {
114
+ id: el.id,
115
+ type: "image",
116
+ x: el.x || 0,
117
+ y: el.y || 0,
118
+ width: visibleWidth,
119
+ height: visibleHeight,
120
+ rotation: el.rotation || 0,
121
+ imageUrl: el.imageUrl,
122
+ imageAspectRatio: el.imageAspectRatio
123
+ };
124
+ if (!isFullCrop(crop)) {
125
+ serialized.cropX = crop.cropX;
126
+ serialized.cropY = crop.cropY;
127
+ serialized.cropWidth = crop.cropWidth;
128
+ serialized.cropHeight = crop.cropHeight;
129
+ serialized.needsCropPixelConversion = true;
130
+ }
131
+ if (td.flipHorizontal) serialized.flipHorizontal = td.flipHorizontal;
132
+ if (td.flipVertical) serialized.flipVertical = td.flipVertical;
133
+ if (td.borderRadius) serialized.borderRadius = td.borderRadius;
134
+ if (el.shadow) serialized.shadow = el.shadow;
135
+ if (!isNeutralAdjustments(td.adjustments)) serialized.adjustments = { ...td.adjustments };
136
+ if (el.opacity !== void 0) serialized.opacity = el.opacity;
137
+ if (el.distressEffect) serialized.distressEffect = el.distressEffect;
138
+ if (el.masks?.length > 0) serialized.masks = el.masks;
139
+ if (el.blendMode) serialized.blendMode = el.blendMode;
140
+ if (el.knockoutParts) serialized.knockoutParts = el.knockoutParts;
141
+ if (el.stroke) serialized.stroke = el.stroke;
142
+ return quantizeGeometry(serialized);
143
+ }
144
+ var RENDER_WIRE_VERSION = CANVAS_STATE_SCHEMA_VERSION;
145
+ var toRenderWire = serializeStateForServer;
146
+
147
+ exports.CANVAS_STATE_SCHEMA_VERSION = CANVAS_STATE_SCHEMA_VERSION;
148
+ exports.FULL_CROP = FULL_CROP;
149
+ exports.MASKED_CROP_FRAME = MASKED_CROP_FRAME;
150
+ exports.NEUTRAL_ADJUSTMENTS = NEUTRAL_ADJUSTMENTS;
151
+ exports.RENDER_WIRE_VERSION = RENDER_WIRE_VERSION;
152
+ exports.effectiveImageCrop = effectiveImageCrop;
153
+ exports.hasImageMasks = hasImageMasks;
154
+ exports.imageFrameSize = imageFrameSize;
155
+ exports.isFullCrop = isFullCrop;
156
+ exports.isLegacyMaskedCrop = isLegacyMaskedCrop;
157
+ exports.isNeutralAdjustments = isNeutralAdjustments;
158
+ exports.serializeStateForServer = serializeStateForServer;
159
+ exports.toRenderWire = toRenderWire;
160
+ //# sourceMappingURL=index.cjs.map
161
+ //# sourceMappingURL=index.cjs.map