@oim-media/core 1.27.9 → 1.27.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -1
- package/dist/compatibility.d.ts +1 -1
- package/dist/compatibility.js +2 -1
- package/dist/v2/geometry-outline.d.ts +23 -0
- package/dist/v2/geometry-outline.js +35 -0
- package/dist/v2/index.d.ts +10 -0
- package/dist/v2/index.js +11 -0
- package/dist/v2/layer-blocks.d.ts +11 -0
- package/dist/v2/layer-blocks.js +34 -0
- package/dist/v2/paint-css.d.ts +46 -0
- package/dist/v2/paint-css.js +109 -0
- package/dist/v2/schema.d.ts +1180 -0
- package/dist/v2/schema.js +433 -0
- package/dist/v2/upgrade/animations.d.ts +7 -0
- package/dist/v2/upgrade/animations.js +255 -0
- package/dist/v2/upgrade/box.d.ts +10 -0
- package/dist/v2/upgrade/box.js +119 -0
- package/dist/v2/upgrade/context.d.ts +42 -0
- package/dist/v2/upgrade/context.js +54 -0
- package/dist/v2/upgrade/effects.d.ts +25 -0
- package/dist/v2/upgrade/effects.js +204 -0
- package/dist/v2/upgrade/geometry.d.ts +9 -0
- package/dist/v2/upgrade/geometry.js +162 -0
- package/dist/v2/upgrade/gradient.d.ts +14 -0
- package/dist/v2/upgrade/gradient.js +79 -0
- package/dist/v2/upgrade/keys.d.ts +9 -0
- package/dist/v2/upgrade/keys.js +31 -0
- package/dist/v2/upgrade/mask.d.ts +7 -0
- package/dist/v2/upgrade/mask.js +64 -0
- package/dist/v2/upgrade/paints.d.ts +21 -0
- package/dist/v2/upgrade/paints.js +258 -0
- package/dist/v2/upgrade/root.d.ts +21 -0
- package/dist/v2/upgrade/root.js +94 -0
- package/dist/v2/upgrade/svg-paths.d.ts +38 -0
- package/dist/v2/upgrade/svg-paths.js +225 -0
- package/dist/v2/upgrade/text.d.ts +7 -0
- package/dist/v2/upgrade/text.js +132 -0
- package/dist/v2/upgrade/tree.d.ts +15 -0
- package/dist/v2/upgrade/tree.js +49 -0
- package/dist/v2/upgrade/variables.d.ts +8 -0
- package/dist/v2/upgrade/variables.js +24 -0
- package/dist/v2/upgrade/zones.d.ts +12 -0
- package/dist/v2/upgrade/zones.js +63 -0
- package/dist/v2/upgrade.d.ts +17 -0
- package/dist/v2/upgrade.js +143 -0
- package/dist/v2/version.d.ts +6 -0
- package/dist/v2/version.js +7 -0
- package/package.json +5 -1
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2026 Xue Studios LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
// The 2.0 document. Three rules shape everything below:
|
|
7
|
+
// - one block per idea, the same in every layer that admits it;
|
|
8
|
+
// - an absent field is its default, so no object carries switched-off values;
|
|
9
|
+
// - every object is strict, so a block on the wrong layer type is an error.
|
|
10
|
+
// The only open map is `extensions`.
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
import { cssColorSchema, dropCapSchema, embeddedFontSchema, generativeFillSchema, keyframeEasingSchema, textHighlightSchema, textMarkSchema, textRunsSchema, } from "../schema.js";
|
|
13
|
+
import { LAYER_BLOCKS } from "./layer-blocks.js";
|
|
14
|
+
export { DOCUMENT_VERSION } from "./version.js";
|
|
15
|
+
const id = z.string().min(1).max(128);
|
|
16
|
+
const unit = z.number().min(0).max(1);
|
|
17
|
+
const extensions = z.record(z.string(), z.unknown());
|
|
18
|
+
// --- values -----------------------------------------------------------------
|
|
19
|
+
const varName = z.string().min(1).max(64);
|
|
20
|
+
/**
|
|
21
|
+
* A literal, a binding to a variable, or a literal with per-mode exceptions.
|
|
22
|
+
* A binding may carry a `fallback`: what is painted when nobody (the document's
|
|
23
|
+
* variables or the host page) gives the variable a value.
|
|
24
|
+
*/
|
|
25
|
+
export function scalar(literal) {
|
|
26
|
+
const binding = z.object({ var: varName, fallback: literal.optional() }).strict();
|
|
27
|
+
return z.union([literal, binding, z.object({ value: literal, modes: z.record(z.string(), literal) }).strict()]);
|
|
28
|
+
}
|
|
29
|
+
const color = scalar(cssColorSchema);
|
|
30
|
+
const length = scalar(z.number());
|
|
31
|
+
// --- paint ------------------------------------------------------------------
|
|
32
|
+
const crop = z.object({ x: z.number().min(0).max(100), y: z.number().min(0).max(100), zoom: z.number().min(1).max(10) }).strict();
|
|
33
|
+
const fit = z.enum(["contain", "cover", "fill", "none", "scale-down"]);
|
|
34
|
+
export const imageFiltersSchema = z
|
|
35
|
+
.object({
|
|
36
|
+
preset: z.string().max(64).optional(),
|
|
37
|
+
blur: z.number().min(0).optional(),
|
|
38
|
+
brightness: z.number().min(0).optional(),
|
|
39
|
+
contrast: z.number().min(0).optional(),
|
|
40
|
+
saturate: z.number().min(0).optional(),
|
|
41
|
+
hueRotate: z.number().optional(),
|
|
42
|
+
})
|
|
43
|
+
.strict();
|
|
44
|
+
const gradientStop = z.object({ color, at: unit.optional() }).strict();
|
|
45
|
+
export const gradientSchema = z
|
|
46
|
+
.object({
|
|
47
|
+
type: z.enum(["linear", "radial", "conic"]),
|
|
48
|
+
angle: z.number().optional(),
|
|
49
|
+
stops: z.array(gradientStop).min(2).max(32),
|
|
50
|
+
})
|
|
51
|
+
.strict();
|
|
52
|
+
const patternMotion = z
|
|
53
|
+
.object({
|
|
54
|
+
direction: z.enum(["right", "left", "up", "down", "zoom-in", "zoom-out", "pulse"]),
|
|
55
|
+
period: z.number().positive().optional(),
|
|
56
|
+
speed: z.number().optional(),
|
|
57
|
+
})
|
|
58
|
+
.strict();
|
|
59
|
+
export const patternSchema = z
|
|
60
|
+
.object({
|
|
61
|
+
preset: z.string().max(64).optional(),
|
|
62
|
+
colors: z.array(color).max(16).optional(),
|
|
63
|
+
bg: color.optional(),
|
|
64
|
+
scale: z.number().optional(),
|
|
65
|
+
sizes: z.array(z.number()).max(16).optional(),
|
|
66
|
+
counts: z.array(z.number()).max(16).optional(),
|
|
67
|
+
dispersions: z.array(z.number()).max(16).optional(),
|
|
68
|
+
svgs: z.array(z.string()).max(16).optional(),
|
|
69
|
+
fit: z.string().max(32).optional(),
|
|
70
|
+
motion: patternMotion.optional(),
|
|
71
|
+
})
|
|
72
|
+
.strict();
|
|
73
|
+
/** A drawn texture over the canvas: lines or dots, with their own colour. */
|
|
74
|
+
export const textureSchema = z
|
|
75
|
+
.object({
|
|
76
|
+
type: z.string().min(1).max(32),
|
|
77
|
+
color: color.optional(),
|
|
78
|
+
angle: z.number().optional(),
|
|
79
|
+
crossed: z.boolean().optional(),
|
|
80
|
+
thickness: z.number().min(0).optional(),
|
|
81
|
+
size: z.number().min(0).optional(),
|
|
82
|
+
})
|
|
83
|
+
.strict();
|
|
84
|
+
const paintOpacity = { opacity: unit.optional() };
|
|
85
|
+
export const paintSchema = z.union([
|
|
86
|
+
z.object({ kind: z.literal("color"), value: color, ...paintOpacity }).strict(),
|
|
87
|
+
z
|
|
88
|
+
.object({
|
|
89
|
+
kind: z.literal("gradient"),
|
|
90
|
+
gradient: gradientSchema.optional(),
|
|
91
|
+
preset: z.string().max(64).optional(),
|
|
92
|
+
...paintOpacity,
|
|
93
|
+
})
|
|
94
|
+
.strict()
|
|
95
|
+
.refine((p) => (p.gradient === undefined) !== (p.preset === undefined), "a gradient paint has a gradient or a preset"),
|
|
96
|
+
z
|
|
97
|
+
.object({
|
|
98
|
+
kind: z.literal("image"),
|
|
99
|
+
src: z.string().min(1),
|
|
100
|
+
fit: fit.optional(),
|
|
101
|
+
crop: crop.optional(),
|
|
102
|
+
flipX: z.boolean().optional(),
|
|
103
|
+
flipY: z.boolean().optional(),
|
|
104
|
+
filters: imageFiltersSchema.optional(),
|
|
105
|
+
...paintOpacity,
|
|
106
|
+
})
|
|
107
|
+
.strict(),
|
|
108
|
+
z.object({ kind: z.literal("pattern"), pattern: patternSchema, ...paintOpacity }).strict(),
|
|
109
|
+
z.object({ kind: z.literal("generative"), generative: generativeFillSchema, ...paintOpacity }).strict(),
|
|
110
|
+
z.object({ kind: z.literal("texture"), texture: textureSchema, ...paintOpacity }).strict(),
|
|
111
|
+
z.object({ ref: id }).strict(),
|
|
112
|
+
]);
|
|
113
|
+
export const strokeSchema = z
|
|
114
|
+
.object({
|
|
115
|
+
paint: paintSchema,
|
|
116
|
+
width: length,
|
|
117
|
+
align: z.enum(["center", "inside", "outside"]).optional(),
|
|
118
|
+
style: z.enum(["solid", "dashed", "dotted"]).optional(),
|
|
119
|
+
})
|
|
120
|
+
.strict();
|
|
121
|
+
// --- effects ----------------------------------------------------------------
|
|
122
|
+
export const effectSchema = z.discriminatedUnion("kind", [
|
|
123
|
+
z
|
|
124
|
+
.object({
|
|
125
|
+
kind: z.literal("shadow"),
|
|
126
|
+
x: z.number().optional(),
|
|
127
|
+
y: z.number().optional(),
|
|
128
|
+
blur: z.number().min(0).optional(),
|
|
129
|
+
spread: z.number().optional(),
|
|
130
|
+
color: color.optional(),
|
|
131
|
+
opacity: unit.optional(),
|
|
132
|
+
inner: z.boolean().optional(),
|
|
133
|
+
})
|
|
134
|
+
.strict(),
|
|
135
|
+
z.object({ kind: z.literal("glow"), radius: z.number().min(0), color: color.optional(), intensity: z.number().optional() }).strict(),
|
|
136
|
+
z.object({ kind: z.literal("blur"), radius: z.number().min(0) }).strict(),
|
|
137
|
+
// `backdrop` filters what is behind the layer; `filter`, the layer itself.
|
|
138
|
+
z.object({ kind: z.literal("backdrop") }).extend(imageFiltersSchema.shape).strict(),
|
|
139
|
+
z.object({ kind: z.literal("filter") }).extend(imageFiltersSchema.shape).strict(),
|
|
140
|
+
z
|
|
141
|
+
.object({
|
|
142
|
+
kind: z.literal("grain"),
|
|
143
|
+
intensity: z.number().min(0).max(100).optional(),
|
|
144
|
+
size: z.number().min(0).optional(),
|
|
145
|
+
blend: z.string().max(32).optional(),
|
|
146
|
+
color: color.optional(),
|
|
147
|
+
})
|
|
148
|
+
.strict(),
|
|
149
|
+
z.object({ kind: z.literal("color-grade"), preset: z.string().min(1).max(64), intensity: z.number().min(0).max(100).optional() }).strict(),
|
|
150
|
+
z
|
|
151
|
+
.object({
|
|
152
|
+
kind: z.literal("texture"),
|
|
153
|
+
preset: z.string().min(1).max(64),
|
|
154
|
+
intensity: z.number().min(0).max(100).optional(),
|
|
155
|
+
blend: z.string().max(32).optional(),
|
|
156
|
+
scale: z.number().optional(),
|
|
157
|
+
color: color.optional(),
|
|
158
|
+
})
|
|
159
|
+
.strict(),
|
|
160
|
+
]);
|
|
161
|
+
// --- text -------------------------------------------------------------------
|
|
162
|
+
export const textSchema = z
|
|
163
|
+
.object({
|
|
164
|
+
content: z.record(z.string(), z.string()),
|
|
165
|
+
font: z
|
|
166
|
+
.object({
|
|
167
|
+
family: z.string().max(256).optional(),
|
|
168
|
+
size: length.optional(),
|
|
169
|
+
weight: z.union([z.number(), z.string().max(16)]).optional(),
|
|
170
|
+
italic: z.boolean().optional(),
|
|
171
|
+
})
|
|
172
|
+
.strict()
|
|
173
|
+
.optional(),
|
|
174
|
+
align: z.enum(["left", "center", "right", "justify"]).optional(),
|
|
175
|
+
lineHeight: z.union([z.number(), z.string().max(16)]).optional(),
|
|
176
|
+
letterSpacing: z.number().optional(),
|
|
177
|
+
transform: z.enum(["uppercase", "lowercase", "capitalize"]).optional(),
|
|
178
|
+
decoration: z.string().max(64).optional(),
|
|
179
|
+
maxWidth: length.optional(),
|
|
180
|
+
marks: z.record(z.string(), textMarkSchema).optional(),
|
|
181
|
+
runs: textRunsSchema.optional(),
|
|
182
|
+
highlight: textHighlightSchema.optional(),
|
|
183
|
+
dropCap: dropCapSchema.optional(),
|
|
184
|
+
artistic: z
|
|
185
|
+
.object({
|
|
186
|
+
preset: z.string().max(64).optional(),
|
|
187
|
+
curve: z.object({ type: z.enum(["arc", "wave", "arch"]), amount: z.number() }).strict().optional(),
|
|
188
|
+
extrusion: z
|
|
189
|
+
.object({ depth: z.number().min(0), angle: z.number().optional(), color: color.optional(), shading: z.boolean().optional() })
|
|
190
|
+
.strict()
|
|
191
|
+
.optional(),
|
|
192
|
+
})
|
|
193
|
+
.strict()
|
|
194
|
+
.optional(),
|
|
195
|
+
})
|
|
196
|
+
.strict();
|
|
197
|
+
// --- geometry ---------------------------------------------------------------
|
|
198
|
+
const pathEntry = z
|
|
199
|
+
.object({
|
|
200
|
+
d: z.string().min(1),
|
|
201
|
+
fillRule: z.literal("evenodd").optional(),
|
|
202
|
+
fill: z.string().max(128).optional(),
|
|
203
|
+
stroke: z.string().max(128).optional(),
|
|
204
|
+
strokeWidth: z.number().min(0).optional(),
|
|
205
|
+
cap: z.enum(["round", "square"]).optional(),
|
|
206
|
+
join: z.enum(["round", "bevel"]).optional(),
|
|
207
|
+
opacity: unit.optional(),
|
|
208
|
+
transform: z.array(z.number()).length(6).optional(),
|
|
209
|
+
})
|
|
210
|
+
.strict();
|
|
211
|
+
// How much of the outline is drawn, as shares of its length. It is the value at
|
|
212
|
+
// rest: the `trimStart` and `trimEnd` tracks animate towards it, and a reader
|
|
213
|
+
// that runs no animation still draws the stroke trimmed.
|
|
214
|
+
const trim = z.object({ start: unit.optional(), end: unit.optional() }).strict();
|
|
215
|
+
export const geometrySchema = z.discriminatedUnion("kind", [
|
|
216
|
+
z.object({ kind: z.literal("rect"), trim: trim.optional() }).strict(),
|
|
217
|
+
z.object({ kind: z.literal("ellipse"), trim: trim.optional() }).strict(),
|
|
218
|
+
z.object({ kind: z.literal("line"), trim: trim.optional() }).strict(),
|
|
219
|
+
z.object({ kind: z.literal("polygon"), sides: z.number().int().min(3).max(64), trim: trim.optional() }).strict(),
|
|
220
|
+
z.object({ kind: z.literal("star"), points: z.number().int().min(3).max(64), inner: unit.optional(), trim: trim.optional() }).strict(),
|
|
221
|
+
z.object({ kind: z.literal("preset"), name: z.string().min(1).max(64), trim: trim.optional() }).strict(),
|
|
222
|
+
z
|
|
223
|
+
.object({
|
|
224
|
+
kind: z.literal("paths"),
|
|
225
|
+
viewBox: z.array(z.number()).length(4),
|
|
226
|
+
paths: z.array(pathEntry).min(1).max(2000),
|
|
227
|
+
trim: trim.optional(),
|
|
228
|
+
})
|
|
229
|
+
.strict(),
|
|
230
|
+
]);
|
|
231
|
+
const corners = z.union([z.number().min(0), z.array(z.number().min(0)).length(4)]);
|
|
232
|
+
export const imageSchema = z
|
|
233
|
+
.object({
|
|
234
|
+
// "oim:base" is the PNG of the file itself. A language can have its own
|
|
235
|
+
// picture; an empty one means that language shows none.
|
|
236
|
+
src: z.union([z.string().min(1), z.object({ value: z.string().min(1), modes: z.record(z.string(), z.string()) }).strict()]),
|
|
237
|
+
fit: fit.optional(),
|
|
238
|
+
crop: crop.optional(),
|
|
239
|
+
filters: imageFiltersSchema.optional(),
|
|
240
|
+
})
|
|
241
|
+
.strict();
|
|
242
|
+
export const maskSchema = z
|
|
243
|
+
.object({
|
|
244
|
+
mode: z.enum(["window", "cutout"]).optional(),
|
|
245
|
+
invert: z.boolean().optional(),
|
|
246
|
+
feather: z.number().min(0).optional(),
|
|
247
|
+
scope: z.enum(["group", "canvas"]).optional(),
|
|
248
|
+
})
|
|
249
|
+
.strict();
|
|
250
|
+
// --- animation --------------------------------------------------------------
|
|
251
|
+
export const ANIMATABLE = ["opacity", "x", "y", "scale", "rotation", "blur", "trimStart", "trimEnd"];
|
|
252
|
+
const track = z
|
|
253
|
+
.object({
|
|
254
|
+
property: z.enum(ANIMATABLE),
|
|
255
|
+
keyframes: z
|
|
256
|
+
.array(z.object({ t: unit, v: z.number(), e: keyframeEasingSchema.optional() }).strict())
|
|
257
|
+
.min(2)
|
|
258
|
+
.max(240),
|
|
259
|
+
})
|
|
260
|
+
.strict();
|
|
261
|
+
function animationFor(targets) {
|
|
262
|
+
return z
|
|
263
|
+
.object({
|
|
264
|
+
on: z.enum(["load", "loop", "enter", "hover", "press", "action"]),
|
|
265
|
+
target: z.enum(targets).optional(),
|
|
266
|
+
preset: z.string().min(1).max(64).optional(),
|
|
267
|
+
params: z.record(z.string(), z.unknown()).optional(),
|
|
268
|
+
tracks: z.array(track).min(1).max(16).optional(),
|
|
269
|
+
duration: z.number().min(0),
|
|
270
|
+
delay: z.number().min(0).optional(),
|
|
271
|
+
stagger: z.number().min(0).optional(),
|
|
272
|
+
easing: keyframeEasingSchema.optional(),
|
|
273
|
+
})
|
|
274
|
+
.strict()
|
|
275
|
+
.refine((a) => (a.preset === undefined) !== (a.tracks === undefined), "an animation carries a preset or tracks");
|
|
276
|
+
}
|
|
277
|
+
export const animationSchema = animationFor(["layer", "chars", "words", "lines"]);
|
|
278
|
+
const layerOnlyAnimation = animationFor(["layer"]);
|
|
279
|
+
// A layer that scrolls forever, like a background repeating sideways. It is
|
|
280
|
+
// the only motion 2.0 keeps: the parallax that followed the pointer is retired.
|
|
281
|
+
const loop = z
|
|
282
|
+
.object({
|
|
283
|
+
speedPxSec: z.number().min(-500).max(500),
|
|
284
|
+
direction: z.enum(["left_to_right", "right_to_left"]).optional(),
|
|
285
|
+
// Every other copy mirrored, so the seam does not show. On unless said.
|
|
286
|
+
mirror: z.boolean().optional(),
|
|
287
|
+
pauseOnHover: z.boolean().optional(),
|
|
288
|
+
})
|
|
289
|
+
.strict();
|
|
290
|
+
export const motionSchema = z.object({ loop: loop.optional() }).strict();
|
|
291
|
+
export const interactionSchema = z
|
|
292
|
+
.object({
|
|
293
|
+
on: z.enum(["press", "hover"]),
|
|
294
|
+
actions: z
|
|
295
|
+
.array(z
|
|
296
|
+
.object({
|
|
297
|
+
type: z.enum(["show", "hide", "toggle", "setText", "play"]),
|
|
298
|
+
target: id,
|
|
299
|
+
value: z.string().max(10000).optional(),
|
|
300
|
+
})
|
|
301
|
+
.strict())
|
|
302
|
+
.min(1)
|
|
303
|
+
.max(64),
|
|
304
|
+
})
|
|
305
|
+
.strict();
|
|
306
|
+
const a11y = z.object({ alt: z.record(z.string(), z.string()).optional(), decorative: z.boolean().optional() }).strict();
|
|
307
|
+
// --- layer ------------------------------------------------------------------
|
|
308
|
+
/** Which point of the box sits at `x, y`. Absent is the top-left corner. */
|
|
309
|
+
export const ANCHORS = ["top-left", "top", "top-right", "left", "center", "right", "bottom-left", "bottom", "bottom-right"];
|
|
310
|
+
const boxSchema = z
|
|
311
|
+
.object({
|
|
312
|
+
x: z.number(),
|
|
313
|
+
y: z.number(),
|
|
314
|
+
// Left out, the layer fits its content, grown from its anchor. A width alone
|
|
315
|
+
// is a reference width (what an endless loop measures its copies by).
|
|
316
|
+
width: z.number().min(0).optional(),
|
|
317
|
+
height: z.number().min(0).optional(),
|
|
318
|
+
anchor: z.enum(ANCHORS).optional(),
|
|
319
|
+
rotation: z.number().optional(),
|
|
320
|
+
flipX: z.boolean().optional(),
|
|
321
|
+
flipY: z.boolean().optional(),
|
|
322
|
+
})
|
|
323
|
+
.strict();
|
|
324
|
+
const BLEND = ["multiply", "screen", "overlay", "darken", "lighten", "color-dodge", "color-burn", "difference"];
|
|
325
|
+
function blockShape(type) {
|
|
326
|
+
const animations = z.array(type === "text" ? animationSchema : layerOnlyAnimation).max(16);
|
|
327
|
+
const all = {
|
|
328
|
+
fills: z.array(paintSchema).max(8),
|
|
329
|
+
strokes: z.array(strokeSchema).max(8),
|
|
330
|
+
effects: z.array(effectSchema).max(16),
|
|
331
|
+
animations,
|
|
332
|
+
motion: motionSchema,
|
|
333
|
+
mask: maskSchema,
|
|
334
|
+
geometry: geometrySchema,
|
|
335
|
+
corners,
|
|
336
|
+
text: textSchema,
|
|
337
|
+
image: imageSchema,
|
|
338
|
+
a11y,
|
|
339
|
+
interactions: z.array(interactionSchema).max(8),
|
|
340
|
+
children: z.array(z.lazy(() => layerSchema)).max(150),
|
|
341
|
+
};
|
|
342
|
+
// What a type cannot exist without is required; every other block is optional.
|
|
343
|
+
const required = { text: "text", shape: "geometry", image: "image", group: "children" };
|
|
344
|
+
const shape = {};
|
|
345
|
+
for (const block of LAYER_BLOCKS[type]) {
|
|
346
|
+
shape[block] = required[type] === block ? all[block] : all[block].optional();
|
|
347
|
+
}
|
|
348
|
+
return shape;
|
|
349
|
+
}
|
|
350
|
+
function layerOf(type, own = {}) {
|
|
351
|
+
return z
|
|
352
|
+
.object({
|
|
353
|
+
id,
|
|
354
|
+
type: z.literal(type),
|
|
355
|
+
name: z.string().max(256).optional(),
|
|
356
|
+
box: boxSchema,
|
|
357
|
+
opacity: unit.optional(),
|
|
358
|
+
visible: z.boolean().optional(),
|
|
359
|
+
blend: z.enum(BLEND).optional(),
|
|
360
|
+
// Shown only in these languages; absent means every language.
|
|
361
|
+
languages: z.array(z.string().min(1).max(16)).min(1).max(64).optional(),
|
|
362
|
+
extensions: extensions.optional(),
|
|
363
|
+
...blockShape(type),
|
|
364
|
+
...own,
|
|
365
|
+
})
|
|
366
|
+
.strict();
|
|
367
|
+
}
|
|
368
|
+
const lottie = z.object({ src: z.string().min(1).optional(), loop: z.boolean().optional() }).strict();
|
|
369
|
+
export const layerSchema = z.lazy(() => z.discriminatedUnion("type", [
|
|
370
|
+
layerOf("text"),
|
|
371
|
+
layerOf("shape"),
|
|
372
|
+
layerOf("image"),
|
|
373
|
+
layerOf("lottie", { lottie: lottie.optional() }),
|
|
374
|
+
layerOf("group"),
|
|
375
|
+
]));
|
|
376
|
+
// --- document ---------------------------------------------------------------
|
|
377
|
+
const variableValue = z.union([z.string().max(256), z.number()]);
|
|
378
|
+
export const variablesSchema = z
|
|
379
|
+
.object({
|
|
380
|
+
modes: z.record(z.string(), z.array(z.string().min(1).max(64)).min(1).max(64)).optional(),
|
|
381
|
+
defaults: z.record(z.string(), z.string()).optional(),
|
|
382
|
+
values: z.record(z.string(), z.union([variableValue, z.record(z.string(), variableValue)])).optional(),
|
|
383
|
+
})
|
|
384
|
+
.strict();
|
|
385
|
+
function duplicatedIds(layers, seen, out) {
|
|
386
|
+
if (!Array.isArray(layers))
|
|
387
|
+
return;
|
|
388
|
+
for (const layer of layers) {
|
|
389
|
+
if (!layer || typeof layer !== "object")
|
|
390
|
+
continue;
|
|
391
|
+
const layerId = layer.id;
|
|
392
|
+
if (typeof layerId === "string") {
|
|
393
|
+
if (seen.has(layerId))
|
|
394
|
+
out.push(layerId);
|
|
395
|
+
seen.add(layerId);
|
|
396
|
+
}
|
|
397
|
+
duplicatedIds(layer.children, seen, out);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
export const documentSchema = z
|
|
401
|
+
.object({
|
|
402
|
+
oim: z.string().regex(/^2\.\d+\.\d+(-[\w.]+)?$/),
|
|
403
|
+
id: z.string().max(128).optional(),
|
|
404
|
+
name: z.string().max(256).optional(),
|
|
405
|
+
// What the whole work shows, per language, for screen readers.
|
|
406
|
+
description: z.record(z.string(), z.string().max(1000)).optional(),
|
|
407
|
+
// `fills` is the background of the canvas: the same paints a layer uses.
|
|
408
|
+
canvas: z
|
|
409
|
+
.object({ width: z.number().positive(), height: z.number().positive(), fills: z.array(paintSchema).max(8).optional() })
|
|
410
|
+
.strict(),
|
|
411
|
+
languages: z.array(z.string().min(1).max(16)).min(1).max(64),
|
|
412
|
+
variables: variablesSchema.optional(),
|
|
413
|
+
resources: z.record(z.string(), paintSchema).optional(),
|
|
414
|
+
fonts: z.array(embeddedFontSchema).optional(),
|
|
415
|
+
layers: z.array(layerSchema).max(150),
|
|
416
|
+
reedit: z.enum(["public", "author_only", "sealed"]).optional(),
|
|
417
|
+
extensionsUsed: z.array(z.string().max(64)).optional(),
|
|
418
|
+
extensionsRequired: z.array(z.string().max(64)).optional(),
|
|
419
|
+
extensions: extensions.optional(),
|
|
420
|
+
image_hash: z.string().optional(),
|
|
421
|
+
image_hash_alg: z.string().optional(),
|
|
422
|
+
signature: z.string().optional(),
|
|
423
|
+
key_version: z.string().optional(),
|
|
424
|
+
signed_at: z.string().optional(),
|
|
425
|
+
})
|
|
426
|
+
.strict()
|
|
427
|
+
.superRefine((document, ctx) => {
|
|
428
|
+
const repeated = [];
|
|
429
|
+
duplicatedIds(document.layers, new Set(), repeated);
|
|
430
|
+
for (const layerId of repeated) {
|
|
431
|
+
ctx.addIssue({ code: "custom", path: ["layers"], message: `layer id "${layerId}" is used more than once` });
|
|
432
|
+
}
|
|
433
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2026 Xue Studios LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { type DraftLayer, type UpgradeContext, type V1Slot } from "./context.js";
|
|
7
|
+
export declare function convertAnimations(ctx: UpgradeContext, slot: V1Slot, layer: DraftLayer): void;
|