@snowcone-app/design 0.0.0-stage → 0.2.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/CHANGELOG.md +19 -0
- package/README.md +58 -2
- package/dist/conformance/index.cjs +234 -0
- package/dist/conformance/index.cjs.map +1 -0
- package/dist/conformance/index.d.cts +39 -0
- package/dist/conformance/index.d.ts +39 -0
- package/dist/conformance/index.js +228 -0
- package/dist/conformance/index.js.map +1 -0
- package/dist/index.cjs +674 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +238 -0
- package/dist/index.d.ts +238 -0
- package/dist/index.js +638 -0
- package/dist/index.js.map +1 -0
- package/dist/saved-BOsUdd8W.d.cts +2464 -0
- package/dist/saved-BOsUdd8W.d.ts +2464 -0
- package/dist/wire/index.cjs +161 -0
- package/dist/wire/index.cjs.map +1 -0
- package/dist/wire/index.d.cts +168 -0
- package/dist/wire/index.d.ts +168 -0
- package/dist/wire/index.js +147 -0
- package/dist/wire/index.js.map +1 -0
- package/package.json +80 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,638 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// src/schema.ts
|
|
4
|
+
var PointSchema = z.object({
|
|
5
|
+
x: z.number(),
|
|
6
|
+
y: z.number()
|
|
7
|
+
});
|
|
8
|
+
var StrokeConfigSchema = z.object({
|
|
9
|
+
enabled: z.boolean(),
|
|
10
|
+
color: z.string(),
|
|
11
|
+
width: z.number(),
|
|
12
|
+
dashArray: z.array(z.number()).optional(),
|
|
13
|
+
lineCap: z.enum(["butt", "round", "square"]).optional(),
|
|
14
|
+
lineJoin: z.enum(["miter", "round", "bevel"]).optional(),
|
|
15
|
+
miterLimit: z.number().optional(),
|
|
16
|
+
opacity: z.number().optional(),
|
|
17
|
+
feather: z.number().optional()
|
|
18
|
+
});
|
|
19
|
+
var ShadowConfigSchema = z.object({
|
|
20
|
+
enabled: z.boolean(),
|
|
21
|
+
color: z.string(),
|
|
22
|
+
blur: z.number(),
|
|
23
|
+
offsetX: z.number(),
|
|
24
|
+
offsetY: z.number(),
|
|
25
|
+
opacity: z.number().optional()
|
|
26
|
+
});
|
|
27
|
+
var KnockoutConfigSchema = z.object({
|
|
28
|
+
fill: z.boolean().optional(),
|
|
29
|
+
stroke: z.boolean().optional(),
|
|
30
|
+
scope: z.enum(["group", "artboard"]).optional()
|
|
31
|
+
});
|
|
32
|
+
var DistressEffectSchema = z.object({
|
|
33
|
+
enabled: z.boolean(),
|
|
34
|
+
style: z.enum(["worn", "cracked", "grunge", "retro", "custom"]),
|
|
35
|
+
intensity: z.number(),
|
|
36
|
+
fadeAmount: z.number().optional(),
|
|
37
|
+
grainAmount: z.number().optional(),
|
|
38
|
+
scratchAmount: z.number().optional(),
|
|
39
|
+
edgeWear: z.number().optional(),
|
|
40
|
+
textureUrl: z.string().optional(),
|
|
41
|
+
textureOpacity: z.number().optional(),
|
|
42
|
+
textureBlendMode: z.enum(["multiply", "screen", "overlay"]).optional(),
|
|
43
|
+
seed: z.number().optional()
|
|
44
|
+
});
|
|
45
|
+
var MaskDefinitionSchema = z.object({
|
|
46
|
+
id: z.string(),
|
|
47
|
+
type: z.enum(["clip", "alpha", "luma", "distress"]),
|
|
48
|
+
// maskElement is a nested element config -- use lazy to break the cycle
|
|
49
|
+
maskElement: z.lazy(() => AnyElementConfigSchema),
|
|
50
|
+
inverted: z.boolean().optional(),
|
|
51
|
+
feather: z.number().optional(),
|
|
52
|
+
opacity: z.number().optional(),
|
|
53
|
+
blendMode: z.string().optional()
|
|
54
|
+
});
|
|
55
|
+
var CharacterStyleSchema = z.object({
|
|
56
|
+
color: z.string().optional(),
|
|
57
|
+
fontFamily: z.string().optional(),
|
|
58
|
+
fontSize: z.number().optional(),
|
|
59
|
+
bold: z.boolean().optional(),
|
|
60
|
+
italic: z.boolean().optional(),
|
|
61
|
+
underline: z.boolean().optional(),
|
|
62
|
+
strikethrough: z.boolean().optional(),
|
|
63
|
+
letterSpacing: z.number().optional()
|
|
64
|
+
});
|
|
65
|
+
var TextSpanSchema = z.object({
|
|
66
|
+
text: z.string(),
|
|
67
|
+
style: CharacterStyleSchema
|
|
68
|
+
});
|
|
69
|
+
var RichTextSchema = z.object({
|
|
70
|
+
spans: z.array(TextSpanSchema)
|
|
71
|
+
});
|
|
72
|
+
var GlyphOverrideSchema = z.object({
|
|
73
|
+
charIndex: z.number(),
|
|
74
|
+
glyphIndex: z.number(),
|
|
75
|
+
unicode: z.string(),
|
|
76
|
+
alternateName: z.string().optional()
|
|
77
|
+
});
|
|
78
|
+
var OpenTypeFeaturesSchema = z.object({
|
|
79
|
+
liga: z.boolean().optional(),
|
|
80
|
+
dlig: z.boolean().optional(),
|
|
81
|
+
calt: z.boolean().optional(),
|
|
82
|
+
swsh: z.boolean().optional(),
|
|
83
|
+
smcp: z.boolean().optional(),
|
|
84
|
+
c2sc: z.boolean().optional(),
|
|
85
|
+
onum: z.boolean().optional(),
|
|
86
|
+
lnum: z.boolean().optional(),
|
|
87
|
+
tnum: z.boolean().optional(),
|
|
88
|
+
pnum: z.boolean().optional(),
|
|
89
|
+
ss01: z.boolean().optional(),
|
|
90
|
+
ss02: z.boolean().optional(),
|
|
91
|
+
ss03: z.boolean().optional(),
|
|
92
|
+
ss04: z.boolean().optional(),
|
|
93
|
+
ss05: z.boolean().optional(),
|
|
94
|
+
ss06: z.boolean().optional(),
|
|
95
|
+
ss07: z.boolean().optional(),
|
|
96
|
+
ss08: z.boolean().optional(),
|
|
97
|
+
ss09: z.boolean().optional(),
|
|
98
|
+
ss10: z.boolean().optional(),
|
|
99
|
+
ss11: z.boolean().optional(),
|
|
100
|
+
ss12: z.boolean().optional(),
|
|
101
|
+
ss13: z.boolean().optional(),
|
|
102
|
+
ss14: z.boolean().optional(),
|
|
103
|
+
ss15: z.boolean().optional(),
|
|
104
|
+
ss16: z.boolean().optional(),
|
|
105
|
+
ss17: z.boolean().optional(),
|
|
106
|
+
ss18: z.boolean().optional(),
|
|
107
|
+
ss19: z.boolean().optional(),
|
|
108
|
+
ss20: z.boolean().optional(),
|
|
109
|
+
cv01: z.boolean().optional(),
|
|
110
|
+
cv02: z.boolean().optional(),
|
|
111
|
+
cv03: z.boolean().optional(),
|
|
112
|
+
cv04: z.boolean().optional(),
|
|
113
|
+
cv05: z.boolean().optional(),
|
|
114
|
+
ccmp: z.boolean().optional(),
|
|
115
|
+
locl: z.boolean().optional(),
|
|
116
|
+
kern: z.boolean().optional(),
|
|
117
|
+
mark: z.boolean().optional(),
|
|
118
|
+
mkmk: z.boolean().optional()
|
|
119
|
+
});
|
|
120
|
+
var CustomTransformDataSchema = z.object({
|
|
121
|
+
type: z.literal("custom"),
|
|
122
|
+
controlPoints: z.array(PointSchema)
|
|
123
|
+
}).passthrough();
|
|
124
|
+
var DistortTransformDataSchema = z.object({
|
|
125
|
+
type: z.literal("distort")
|
|
126
|
+
}).passthrough();
|
|
127
|
+
var CircleTransformDataSchema = z.object({
|
|
128
|
+
type: z.literal("circle"),
|
|
129
|
+
radius: z.number(),
|
|
130
|
+
scale: z.number(),
|
|
131
|
+
reverse: z.boolean()
|
|
132
|
+
});
|
|
133
|
+
var LeanTransformDataSchema = z.object({
|
|
134
|
+
type: z.literal("lean"),
|
|
135
|
+
leanAmount: z.number()
|
|
136
|
+
}).passthrough();
|
|
137
|
+
var ArchTransformDataSchema = z.object({
|
|
138
|
+
type: z.literal("arch"),
|
|
139
|
+
archHeight: z.number()
|
|
140
|
+
}).passthrough();
|
|
141
|
+
var AscendTransformDataSchema = z.object({
|
|
142
|
+
type: z.literal("ascend"),
|
|
143
|
+
ascendAngle: z.number()
|
|
144
|
+
}).passthrough();
|
|
145
|
+
var WaveTransformDataSchema = z.object({
|
|
146
|
+
type: z.literal("wave"),
|
|
147
|
+
amplitude: z.number(),
|
|
148
|
+
frequency: z.number()
|
|
149
|
+
}).passthrough();
|
|
150
|
+
var FlagTransformDataSchema = z.object({
|
|
151
|
+
type: z.literal("flag"),
|
|
152
|
+
amplitude: z.number(),
|
|
153
|
+
frequency: z.number()
|
|
154
|
+
}).passthrough();
|
|
155
|
+
var ImageTransformDataSchema = z.object({
|
|
156
|
+
type: z.literal("image"),
|
|
157
|
+
width: z.number(),
|
|
158
|
+
height: z.number(),
|
|
159
|
+
cropX: z.number(),
|
|
160
|
+
cropY: z.number(),
|
|
161
|
+
cropWidth: z.number(),
|
|
162
|
+
cropHeight: z.number(),
|
|
163
|
+
flipHorizontal: z.boolean(),
|
|
164
|
+
flipVertical: z.boolean(),
|
|
165
|
+
borderRadius: z.number(),
|
|
166
|
+
// How crop combines with masks: 'frame' = the element box is the frame and every mask is fitted to it. ABSENT on a
|
|
167
|
+
// masked image = saved before 2026-11, when crop was ignored under masks (renderers treat its crop as the full
|
|
168
|
+
// picture). Every image the editor builds sets it; dropping it changes how a masked image renders.
|
|
169
|
+
maskedCrop: z.literal("frame").optional(),
|
|
170
|
+
// The picture was made for ENGRAVING: `imageUrl` is the result (black = cut), `sourceUrl` the picture before.
|
|
171
|
+
engrave: z.object({
|
|
172
|
+
style: z.enum(["photo", "drawing", "solid", "original"]),
|
|
173
|
+
amount: z.number(),
|
|
174
|
+
invert: z.boolean(),
|
|
175
|
+
sourceUrl: z.string(),
|
|
176
|
+
cutLight: z.boolean()
|
|
177
|
+
}).optional(),
|
|
178
|
+
// Brightness/contrast/saturation (1 = neutral) — optional; the canonical
|
|
179
|
+
// neutral state is ABSENCE, so saved states never carry {1,1,1}.
|
|
180
|
+
adjustments: z.object({
|
|
181
|
+
brightness: z.number(),
|
|
182
|
+
contrast: z.number(),
|
|
183
|
+
saturation: z.number()
|
|
184
|
+
}).optional()
|
|
185
|
+
});
|
|
186
|
+
var GroupTransformDataSchema = z.object({
|
|
187
|
+
type: z.literal("group")
|
|
188
|
+
});
|
|
189
|
+
var GradientStopSchema = z.object({
|
|
190
|
+
offset: z.number().min(0).max(1),
|
|
191
|
+
color: z.string()
|
|
192
|
+
});
|
|
193
|
+
var ShapeFillSchema = z.discriminatedUnion("type", [
|
|
194
|
+
z.object({ type: z.literal("solid"), color: z.string() }),
|
|
195
|
+
z.object({ type: z.literal("linear"), angle: z.number(), stops: z.array(GradientStopSchema).min(2) }),
|
|
196
|
+
z.object({ type: z.literal("radial"), stops: z.array(GradientStopSchema).min(2) })
|
|
197
|
+
]);
|
|
198
|
+
var ShapeTransformDataSchema = z.object({
|
|
199
|
+
type: z.literal("shape"),
|
|
200
|
+
shapeType: z.enum(["rectangle", "circle", "ellipse", "triangle", "polygon", "star", "line"]),
|
|
201
|
+
width: z.number(),
|
|
202
|
+
height: z.number(),
|
|
203
|
+
borderRadius: z.number().optional(),
|
|
204
|
+
radiusX: z.number().optional(),
|
|
205
|
+
radiusY: z.number().optional(),
|
|
206
|
+
sides: z.number().optional(),
|
|
207
|
+
points: z.number().optional(),
|
|
208
|
+
innerRadius: z.number().optional(),
|
|
209
|
+
fillColor: z.string().optional(),
|
|
210
|
+
fillOpacity: z.number().optional(),
|
|
211
|
+
fill: ShapeFillSchema.optional()
|
|
212
|
+
});
|
|
213
|
+
var PathPointSchema = z.object({
|
|
214
|
+
id: z.string(),
|
|
215
|
+
x: z.number(),
|
|
216
|
+
y: z.number(),
|
|
217
|
+
type: z.enum(["corner", "smooth", "bezier"]),
|
|
218
|
+
handleIn: PointSchema.optional(),
|
|
219
|
+
handleOut: PointSchema.optional()
|
|
220
|
+
});
|
|
221
|
+
var PathTransformDataSchema = z.object({
|
|
222
|
+
type: z.literal("path"),
|
|
223
|
+
points: z.array(PathPointSchema),
|
|
224
|
+
closed: z.boolean(),
|
|
225
|
+
width: z.number(),
|
|
226
|
+
height: z.number(),
|
|
227
|
+
fillEnabled: z.boolean().optional(),
|
|
228
|
+
fillColor: z.string().optional(),
|
|
229
|
+
fillOpacity: z.number().optional(),
|
|
230
|
+
strokeEnabled: z.boolean().optional(),
|
|
231
|
+
strokeColor: z.string().optional(),
|
|
232
|
+
strokeWidth: z.number().optional()
|
|
233
|
+
});
|
|
234
|
+
var AnyTransformDataSchema = z.discriminatedUnion("type", [
|
|
235
|
+
CustomTransformDataSchema,
|
|
236
|
+
DistortTransformDataSchema,
|
|
237
|
+
CircleTransformDataSchema,
|
|
238
|
+
LeanTransformDataSchema,
|
|
239
|
+
ArchTransformDataSchema,
|
|
240
|
+
AscendTransformDataSchema,
|
|
241
|
+
WaveTransformDataSchema,
|
|
242
|
+
FlagTransformDataSchema,
|
|
243
|
+
ImageTransformDataSchema,
|
|
244
|
+
GroupTransformDataSchema,
|
|
245
|
+
ShapeTransformDataSchema,
|
|
246
|
+
PathTransformDataSchema
|
|
247
|
+
]);
|
|
248
|
+
var BaseElementPropsSchema = z.object({
|
|
249
|
+
id: z.string(),
|
|
250
|
+
x: z.number(),
|
|
251
|
+
y: z.number(),
|
|
252
|
+
rotation: z.number(),
|
|
253
|
+
opacity: z.number(),
|
|
254
|
+
// Layer properties
|
|
255
|
+
name: z.string().optional(),
|
|
256
|
+
visible: z.boolean().optional(),
|
|
257
|
+
locked: z.boolean().optional(),
|
|
258
|
+
isClipping: z.boolean().optional(),
|
|
259
|
+
// Effects
|
|
260
|
+
blendMode: z.enum(["normal", "knockout", "clip"]).optional(),
|
|
261
|
+
knockoutParts: KnockoutConfigSchema.optional(),
|
|
262
|
+
stroke: StrokeConfigSchema.optional(),
|
|
263
|
+
masks: z.array(MaskDefinitionSchema).optional(),
|
|
264
|
+
distressEffect: DistressEffectSchema.optional(),
|
|
265
|
+
shadow: ShadowConfigSchema.optional(),
|
|
266
|
+
// The element's kind as the export worker names it; the editor writes it beside transformType (same value).
|
|
267
|
+
type: z.string().optional(),
|
|
268
|
+
// The artboard (by name) the element is on, stamped by the editor's change event: the saved design's way to keep a
|
|
269
|
+
// multi-placement design's elements on their own placements.
|
|
270
|
+
artboard: z.string().optional()
|
|
271
|
+
});
|
|
272
|
+
var TextElementPropsSchema = BaseElementPropsSchema.extend({
|
|
273
|
+
// Rich text
|
|
274
|
+
richText: RichTextSchema.optional(),
|
|
275
|
+
// Legacy plain text
|
|
276
|
+
text: z.string().optional(),
|
|
277
|
+
// Element-level style defaults
|
|
278
|
+
fontSize: z.number().optional(),
|
|
279
|
+
fontFamily: z.string().optional(),
|
|
280
|
+
color: z.string().optional(),
|
|
281
|
+
textAlign: z.enum(["left", "center", "right"]).optional(),
|
|
282
|
+
bold: z.boolean().optional(),
|
|
283
|
+
italic: z.boolean().optional(),
|
|
284
|
+
underline: z.boolean().optional(),
|
|
285
|
+
strikethrough: z.boolean().optional(),
|
|
286
|
+
// Typography
|
|
287
|
+
letterSpacing: z.number().optional(),
|
|
288
|
+
lineHeight: z.number().optional(),
|
|
289
|
+
glyphOverrides: z.array(GlyphOverrideSchema).optional(),
|
|
290
|
+
openTypeFeatures: OpenTypeFeaturesSchema.optional()
|
|
291
|
+
});
|
|
292
|
+
var CustomElementConfigSchema = TextElementPropsSchema.extend({
|
|
293
|
+
transformType: z.literal("custom"),
|
|
294
|
+
transformData: CustomTransformDataSchema.optional()
|
|
295
|
+
});
|
|
296
|
+
var DistortElementConfigSchema = TextElementPropsSchema.extend({
|
|
297
|
+
transformType: z.literal("distort"),
|
|
298
|
+
transformData: DistortTransformDataSchema.optional()
|
|
299
|
+
});
|
|
300
|
+
var CircleElementConfigSchema = TextElementPropsSchema.extend({
|
|
301
|
+
transformType: z.literal("circle"),
|
|
302
|
+
transformData: CircleTransformDataSchema.optional()
|
|
303
|
+
});
|
|
304
|
+
var LeanElementConfigSchema = TextElementPropsSchema.extend({
|
|
305
|
+
transformType: z.literal("lean"),
|
|
306
|
+
transformData: LeanTransformDataSchema.optional()
|
|
307
|
+
});
|
|
308
|
+
var ArchElementConfigSchema = TextElementPropsSchema.extend({
|
|
309
|
+
transformType: z.literal("arch"),
|
|
310
|
+
transformData: ArchTransformDataSchema.optional()
|
|
311
|
+
});
|
|
312
|
+
var AscendElementConfigSchema = TextElementPropsSchema.extend({
|
|
313
|
+
transformType: z.literal("ascend"),
|
|
314
|
+
transformData: AscendTransformDataSchema.optional()
|
|
315
|
+
});
|
|
316
|
+
var WaveElementConfigSchema = TextElementPropsSchema.extend({
|
|
317
|
+
transformType: z.literal("wave"),
|
|
318
|
+
transformData: WaveTransformDataSchema.optional()
|
|
319
|
+
});
|
|
320
|
+
var FlagElementConfigSchema = TextElementPropsSchema.extend({
|
|
321
|
+
transformType: z.literal("flag"),
|
|
322
|
+
transformData: FlagTransformDataSchema.optional()
|
|
323
|
+
});
|
|
324
|
+
var ImageElementConfigSchema = BaseElementPropsSchema.extend({
|
|
325
|
+
transformType: z.literal("image"),
|
|
326
|
+
transformData: ImageTransformDataSchema.optional(),
|
|
327
|
+
imageUrl: z.string().optional(),
|
|
328
|
+
imageAspectRatio: z.number().optional(),
|
|
329
|
+
// A dimension lock (a cover crop): width/height are kept when the picture loads.
|
|
330
|
+
preserveDimensions: z.boolean().optional()
|
|
331
|
+
});
|
|
332
|
+
var GroupElementConfigSchema = BaseElementPropsSchema.extend({
|
|
333
|
+
transformType: z.literal("group"),
|
|
334
|
+
transformData: GroupTransformDataSchema.optional(),
|
|
335
|
+
children: z.lazy(() => z.array(AnyElementConfigSchema)).optional()
|
|
336
|
+
});
|
|
337
|
+
var ShapeElementConfigSchema = BaseElementPropsSchema.extend({
|
|
338
|
+
transformType: z.literal("shape"),
|
|
339
|
+
transformData: ShapeTransformDataSchema.optional()
|
|
340
|
+
});
|
|
341
|
+
var PathElementConfigSchema = BaseElementPropsSchema.extend({
|
|
342
|
+
transformType: z.literal("path"),
|
|
343
|
+
transformData: PathTransformDataSchema.optional()
|
|
344
|
+
});
|
|
345
|
+
var AnyElementConfigSchema = z.discriminatedUnion("transformType", [
|
|
346
|
+
CustomElementConfigSchema,
|
|
347
|
+
DistortElementConfigSchema,
|
|
348
|
+
CircleElementConfigSchema,
|
|
349
|
+
LeanElementConfigSchema,
|
|
350
|
+
ArchElementConfigSchema,
|
|
351
|
+
AscendElementConfigSchema,
|
|
352
|
+
WaveElementConfigSchema,
|
|
353
|
+
FlagElementConfigSchema,
|
|
354
|
+
ImageElementConfigSchema,
|
|
355
|
+
GroupElementConfigSchema,
|
|
356
|
+
ShapeElementConfigSchema,
|
|
357
|
+
PathElementConfigSchema
|
|
358
|
+
]);
|
|
359
|
+
var ClipShapeSchema = z.union([
|
|
360
|
+
z.literal("rectangle"),
|
|
361
|
+
z.literal("circle"),
|
|
362
|
+
z.object({ type: z.literal("rounded"), radius: z.number() }),
|
|
363
|
+
z.object({ type: z.literal("path"), d: z.string() }),
|
|
364
|
+
z.object({
|
|
365
|
+
type: z.literal("composite-path"),
|
|
366
|
+
pieces: z.array(
|
|
367
|
+
z.object({
|
|
368
|
+
d: z.string(),
|
|
369
|
+
x: z.number(),
|
|
370
|
+
y: z.number(),
|
|
371
|
+
// degrees clockwise, any multiple of 45 (utils/pieceRotation.ts — 45 = a bandana's folded view)
|
|
372
|
+
rotation: z.number().refine((n) => Number.isFinite(n) && n % 45 === 0, { message: "rotation must be a multiple of 45 (degrees clockwise)" }).optional(),
|
|
373
|
+
baseWidth: z.number().optional(),
|
|
374
|
+
baseHeight: z.number().optional()
|
|
375
|
+
})
|
|
376
|
+
)
|
|
377
|
+
})
|
|
378
|
+
]);
|
|
379
|
+
var ArtboardDistressTextureSchema = z.object({
|
|
380
|
+
enabled: z.boolean(),
|
|
381
|
+
textureUrl: z.string(),
|
|
382
|
+
intensity: z.number()
|
|
383
|
+
});
|
|
384
|
+
var ArtboardImageMaskSchema = z.object({
|
|
385
|
+
enabled: z.boolean(),
|
|
386
|
+
imageUrl: z.string(),
|
|
387
|
+
maskType: z.enum(["clip", "alpha", "luma"]),
|
|
388
|
+
opacity: z.number(),
|
|
389
|
+
inverted: z.boolean().optional()
|
|
390
|
+
});
|
|
391
|
+
var SerializedArtboardSchema = z.object({
|
|
392
|
+
id: z.string(),
|
|
393
|
+
name: z.string(),
|
|
394
|
+
x: z.number(),
|
|
395
|
+
y: z.number(),
|
|
396
|
+
width: z.number(),
|
|
397
|
+
height: z.number(),
|
|
398
|
+
backgroundColor: z.string(),
|
|
399
|
+
backgroundType: z.enum(["color", "transparent", "texture"]).optional(),
|
|
400
|
+
backgroundTexture: z.string().optional(),
|
|
401
|
+
exportBackground: z.boolean().optional(),
|
|
402
|
+
clipShape: ClipShapeSchema.optional(),
|
|
403
|
+
previewBackgroundColor: z.string().optional(),
|
|
404
|
+
distressTexture: ArtboardDistressTextureSchema.optional(),
|
|
405
|
+
imageMask: ArtboardImageMaskSchema.optional(),
|
|
406
|
+
// Pacing role for multi-page templates (ADR-0086) — template metadata,
|
|
407
|
+
// stripped from the server render wire by serializeStateForServer
|
|
408
|
+
role: z.enum(["cover", "front-matter", "repeating", "back-matter"]).optional(),
|
|
409
|
+
elementIds: z.array(z.string())
|
|
410
|
+
});
|
|
411
|
+
var CustomFontSchema = z.object({
|
|
412
|
+
family: z.string().min(1),
|
|
413
|
+
url: z.string().min(1),
|
|
414
|
+
weight: z.number().optional(),
|
|
415
|
+
style: z.enum(["normal", "italic"]).optional()
|
|
416
|
+
});
|
|
417
|
+
var CanvasStateV1Schema = z.object({
|
|
418
|
+
version: z.literal(1),
|
|
419
|
+
artboards: z.array(SerializedArtboardSchema),
|
|
420
|
+
elements: z.array(AnyElementConfigSchema),
|
|
421
|
+
activeArtboardId: z.string(),
|
|
422
|
+
customFonts: z.array(CustomFontSchema).optional()
|
|
423
|
+
});
|
|
424
|
+
var ElementConfigSchemas = {
|
|
425
|
+
custom: CustomElementConfigSchema,
|
|
426
|
+
distort: DistortElementConfigSchema,
|
|
427
|
+
circle: CircleElementConfigSchema,
|
|
428
|
+
lean: LeanElementConfigSchema,
|
|
429
|
+
arch: ArchElementConfigSchema,
|
|
430
|
+
ascend: AscendElementConfigSchema,
|
|
431
|
+
wave: WaveElementConfigSchema,
|
|
432
|
+
flag: FlagElementConfigSchema,
|
|
433
|
+
image: ImageElementConfigSchema,
|
|
434
|
+
group: GroupElementConfigSchema,
|
|
435
|
+
shape: ShapeElementConfigSchema,
|
|
436
|
+
path: PathElementConfigSchema
|
|
437
|
+
};
|
|
438
|
+
var SavedArtboardSchema = z.object({
|
|
439
|
+
/** The placement label (unique in a design): elements name it in their `artboard` tag. */
|
|
440
|
+
name: z.string(),
|
|
441
|
+
width: z.number(),
|
|
442
|
+
height: z.number(),
|
|
443
|
+
backgroundColor: z.string().optional(),
|
|
444
|
+
exportBackground: z.boolean().optional(),
|
|
445
|
+
clipShape: ClipShapeSchema.optional(),
|
|
446
|
+
role: z.enum(["cover", "front-matter", "repeating", "back-matter"]).optional(),
|
|
447
|
+
distressTexture: ArtboardDistressTextureSchema.optional(),
|
|
448
|
+
imageMask: ArtboardImageMaskSchema.optional()
|
|
449
|
+
});
|
|
450
|
+
var SavedDesignSchema = z.object({
|
|
451
|
+
elements: z.array(AnyElementConfigSchema),
|
|
452
|
+
artboards: z.array(SavedArtboardSchema),
|
|
453
|
+
/** The artboard on screen when it was saved (its name). */
|
|
454
|
+
activeArtboard: z.string().optional(),
|
|
455
|
+
customFonts: z.array(CustomFontSchema).optional()
|
|
456
|
+
});
|
|
457
|
+
var ImageWireElementSchema = z.object({
|
|
458
|
+
id: z.string(),
|
|
459
|
+
type: z.literal("image"),
|
|
460
|
+
x: z.number(),
|
|
461
|
+
y: z.number(),
|
|
462
|
+
/** The visible (cropped) size, design px. */
|
|
463
|
+
width: z.number(),
|
|
464
|
+
height: z.number(),
|
|
465
|
+
rotation: z.number(),
|
|
466
|
+
imageUrl: z.string().optional(),
|
|
467
|
+
imageAspectRatio: z.number().optional(),
|
|
468
|
+
cropX: z.number().optional(),
|
|
469
|
+
cropY: z.number().optional(),
|
|
470
|
+
cropWidth: z.number().optional(),
|
|
471
|
+
cropHeight: z.number().optional(),
|
|
472
|
+
/** Set with a crop: the server converts the 0..1 crop to source px once it has the picture. */
|
|
473
|
+
needsCropPixelConversion: z.literal(true).optional(),
|
|
474
|
+
flipHorizontal: z.boolean().optional(),
|
|
475
|
+
flipVertical: z.boolean().optional(),
|
|
476
|
+
borderRadius: z.number().optional(),
|
|
477
|
+
shadow: ShadowConfigSchema.optional(),
|
|
478
|
+
adjustments: z.object({ brightness: z.number(), contrast: z.number(), saturation: z.number() }).optional(),
|
|
479
|
+
opacity: z.number().optional(),
|
|
480
|
+
distressEffect: DistressEffectSchema.optional(),
|
|
481
|
+
masks: z.array(MaskDefinitionSchema).optional(),
|
|
482
|
+
blendMode: z.enum(["normal", "knockout", "clip"]).optional(),
|
|
483
|
+
knockoutParts: KnockoutConfigSchema.optional(),
|
|
484
|
+
stroke: StrokeConfigSchema.optional()
|
|
485
|
+
});
|
|
486
|
+
var nonImage = Object.keys(ElementConfigSchemas).filter((t) => t !== "image").map((t) => {
|
|
487
|
+
const base = ElementConfigSchemas[t].extend({ type: z.literal(t) });
|
|
488
|
+
return t === "group" ? base.extend({ children: z.lazy(() => z.array(WireElementSchema)).optional() }) : base;
|
|
489
|
+
});
|
|
490
|
+
var WireElementSchema = z.discriminatedUnion("type", [
|
|
491
|
+
ImageWireElementSchema,
|
|
492
|
+
...nonImage
|
|
493
|
+
]);
|
|
494
|
+
var WireArtboardSchema = z.object({
|
|
495
|
+
id: z.string(),
|
|
496
|
+
name: z.string(),
|
|
497
|
+
x: z.number(),
|
|
498
|
+
y: z.number(),
|
|
499
|
+
width: z.number(),
|
|
500
|
+
height: z.number(),
|
|
501
|
+
backgroundColor: z.string(),
|
|
502
|
+
exportBackground: z.boolean(),
|
|
503
|
+
elements: z.array(WireElementSchema),
|
|
504
|
+
distressTexture: ArtboardDistressTextureSchema.optional(),
|
|
505
|
+
imageMask: ArtboardImageMaskSchema.optional()
|
|
506
|
+
});
|
|
507
|
+
var RenderWireSchema = z.object({
|
|
508
|
+
/** The wire's major (RENDER_WIRE_VERSION); a renderer refuses a newer major than it reads. */
|
|
509
|
+
schemaVersion: z.number().int().min(1),
|
|
510
|
+
artboards: z.array(WireArtboardSchema),
|
|
511
|
+
customFonts: z.array(CustomFontSchema).optional()
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
// src/errors.ts
|
|
515
|
+
var DESIGN_DOC_SLUG = "design-format";
|
|
516
|
+
var DesignError = class extends Error {
|
|
517
|
+
code;
|
|
518
|
+
data;
|
|
519
|
+
docSlug = DESIGN_DOC_SLUG;
|
|
520
|
+
constructor(code, data, message) {
|
|
521
|
+
super(`${code}: ${message}`);
|
|
522
|
+
this.name = "DesignError";
|
|
523
|
+
this.code = code;
|
|
524
|
+
this.data = data;
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
function describeIssues(issues, max = 8) {
|
|
528
|
+
const lines = issues.slice(0, max).map((i) => `${i.path || "(the document)"}: ${i.message}${i.valid ? ` (valid: ${i.valid.join(" | ")})` : ""}`);
|
|
529
|
+
return lines.join("; ") + (issues.length > max ? `; \u2026 ${issues.length - max} more` : "");
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
// src/validate.ts
|
|
533
|
+
var DESIGN_VERSION = 1;
|
|
534
|
+
var SUPPORTED_DESIGN_VERSIONS = [1];
|
|
535
|
+
function issuesOf(error) {
|
|
536
|
+
return error.issues.map((issue) => {
|
|
537
|
+
const raw = issue;
|
|
538
|
+
const valid = (raw.values ?? raw.options)?.filter((v) => typeof v === "string" || typeof v === "number").map(String);
|
|
539
|
+
return { path: issue.path.join("."), message: issue.message, ...valid && valid.length ? { valid } : {} };
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
function validateDesign(data) {
|
|
543
|
+
const result = CanvasStateV1Schema.safeParse(data);
|
|
544
|
+
if (result.success) return { success: true, data: result.data };
|
|
545
|
+
const issues = issuesOf(result.error);
|
|
546
|
+
return { success: false, errors: issues.map(({ path, message }) => ({ path, message })), issues };
|
|
547
|
+
}
|
|
548
|
+
function assertDesign(data) {
|
|
549
|
+
const r = validateDesign(data);
|
|
550
|
+
if (r.success) return r.data;
|
|
551
|
+
throw new DesignError(
|
|
552
|
+
"E_DESIGN_INVALID",
|
|
553
|
+
{ issues: r.issues },
|
|
554
|
+
`not a valid design (version ${DESIGN_VERSION}): ${describeIssues(r.issues)}. Fix each path, or produce the design with an editor that writes this format (@snowcone-app/canvas serializeState) and check it with validateDesign().`
|
|
555
|
+
);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
// src/migrate.ts
|
|
559
|
+
function migrateDesign(data) {
|
|
560
|
+
if (typeof data !== "object" || data === null) {
|
|
561
|
+
throw new DesignError("E_DESIGN_INVALID", { issues: [{ path: "", message: "not an object" }] }, "a design is a JSON object; got " + (data === null ? "null" : typeof data));
|
|
562
|
+
}
|
|
563
|
+
const record = data;
|
|
564
|
+
if (record.version === DESIGN_VERSION) {
|
|
565
|
+
const v = validateDesign(data);
|
|
566
|
+
if (v.success) return v.data;
|
|
567
|
+
throw new DesignError("E_DESIGN_INVALID", { issues: v.issues }, `invalid version ${DESIGN_VERSION} design: ${describeIssues(v.issues)}`);
|
|
568
|
+
}
|
|
569
|
+
if (typeof record.metadata === "object" && record.metadata !== null && "version" in record.metadata) {
|
|
570
|
+
return migrateFromCanvasDocument(record);
|
|
571
|
+
}
|
|
572
|
+
const found = record.version;
|
|
573
|
+
const newer = typeof found === "number" && found > DESIGN_VERSION;
|
|
574
|
+
throw new DesignError(
|
|
575
|
+
"E_DESIGN_VERSION",
|
|
576
|
+
{ found, supported: SUPPORTED_DESIGN_VERSIONS },
|
|
577
|
+
`design version ${JSON.stringify(found ?? null)} is not read here (this package reads ${SUPPORTED_DESIGN_VERSIONS.join(", ")}). ` + (newer ? "It is newer than this package: upgrade @snowcone-app/design." : "A design without a version is not a Snowcone design; one older than the previous major must be migrated with the release that read it.")
|
|
578
|
+
);
|
|
579
|
+
}
|
|
580
|
+
function migrateFromCanvasDocument(doc) {
|
|
581
|
+
const metadata = doc.metadata;
|
|
582
|
+
const version = metadata.version;
|
|
583
|
+
if (version === "1.0.0") {
|
|
584
|
+
const canvas = doc.canvas ?? {};
|
|
585
|
+
const rawElements = doc.elements ?? [];
|
|
586
|
+
const artboardId = "artboard-migrated";
|
|
587
|
+
return {
|
|
588
|
+
version: 1,
|
|
589
|
+
artboards: [
|
|
590
|
+
{
|
|
591
|
+
id: artboardId,
|
|
592
|
+
name: "Artboard 1",
|
|
593
|
+
x: 0,
|
|
594
|
+
y: 0,
|
|
595
|
+
width: canvas.width ?? 1920,
|
|
596
|
+
height: canvas.height ?? 1080,
|
|
597
|
+
backgroundColor: canvas.backgroundColor ?? "#ffffff",
|
|
598
|
+
elementIds: rawElements.map((el) => el.id).filter(Boolean)
|
|
599
|
+
}
|
|
600
|
+
],
|
|
601
|
+
elements: rawElements,
|
|
602
|
+
activeArtboardId: artboardId
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
if (version === "2.0.0") {
|
|
606
|
+
const rawArtboards = doc.artboards ?? [];
|
|
607
|
+
const allElements = [];
|
|
608
|
+
const serializedArtboards = rawArtboards.map((ab) => {
|
|
609
|
+
const abElements = ab.elements ?? [];
|
|
610
|
+
allElements.push(...abElements);
|
|
611
|
+
return {
|
|
612
|
+
id: ab.id,
|
|
613
|
+
name: ab.name,
|
|
614
|
+
x: ab.x,
|
|
615
|
+
y: ab.y,
|
|
616
|
+
width: ab.width,
|
|
617
|
+
height: ab.height,
|
|
618
|
+
backgroundColor: ab.backgroundColor,
|
|
619
|
+
elementIds: abElements.map((el) => el.id).filter(Boolean)
|
|
620
|
+
};
|
|
621
|
+
});
|
|
622
|
+
return {
|
|
623
|
+
version: 1,
|
|
624
|
+
artboards: serializedArtboards,
|
|
625
|
+
elements: allElements,
|
|
626
|
+
activeArtboardId: doc.activeArtboardId ?? serializedArtboards[0]?.id ?? ""
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
throw new DesignError(
|
|
630
|
+
"E_DESIGN_VERSION",
|
|
631
|
+
{ found: version, supported: SUPPORTED_DESIGN_VERSIONS },
|
|
632
|
+
`unsupported CanvasDocument version "${version}" (read: "1.0.0", "2.0.0")`
|
|
633
|
+
);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
export { AnyElementConfigSchema, AnyTransformDataSchema, ArtboardDistressTextureSchema, ArtboardImageMaskSchema, CanvasStateV1Schema, CharacterStyleSchema, ClipShapeSchema, CustomFontSchema, DESIGN_DOC_SLUG, DESIGN_VERSION, DesignError, CanvasStateV1Schema as DesignSchema, DistressEffectSchema, ElementConfigSchemas, GlyphOverrideSchema, ImageWireElementSchema, KnockoutConfigSchema, MaskDefinitionSchema, OpenTypeFeaturesSchema, PointSchema, RenderWireSchema, RichTextSchema, SUPPORTED_DESIGN_VERSIONS, SavedArtboardSchema, SavedDesignSchema, SerializedArtboardSchema, ShadowConfigSchema, StrokeConfigSchema, TextSpanSchema, WireArtboardSchema, WireElementSchema, assertDesign, describeIssues, migrateDesign, validateDesign };
|
|
637
|
+
//# sourceMappingURL=index.js.map
|
|
638
|
+
//# sourceMappingURL=index.js.map
|