desen-core 1.0.0-draft.24 → 1.0.0-draft.29
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/.turbo/turbo-build.log +1 -1
- package/dist/schemas/composition.d.ts +49 -1
- package/dist/schemas/composition.js +30 -1
- package/dist/schemas/style.d.ts +127 -1
- package/dist/schemas/style.js +26 -1
- package/package.json +2 -2
- package/src/schemas/composition.ts +34 -1
- package/src/schemas/style.ts +28 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -10,10 +10,11 @@ export declare const positioningSpec: z.ZodObject<{
|
|
|
10
10
|
}, {
|
|
11
11
|
type: "relative" | "sticky" | "absolute";
|
|
12
12
|
}>;
|
|
13
|
-
export declare const layoutSpec: z.ZodObject<{
|
|
13
|
+
export declare const layoutSpec: z.ZodEffects<z.ZodObject<{
|
|
14
14
|
kind: z.ZodEnum<["stack", "grid"]>;
|
|
15
15
|
direction: z.ZodOptional<z.ZodEnum<["vertical", "horizontal"]>>;
|
|
16
16
|
gap: z.ZodOptional<z.ZodNumber>;
|
|
17
|
+
gap_token: z.ZodOptional<z.ZodString>;
|
|
17
18
|
columns: z.ZodOptional<z.ZodNumber>;
|
|
18
19
|
align: z.ZodOptional<z.ZodEnum<["start", "center", "end", "stretch"]>>;
|
|
19
20
|
align_content: z.ZodOptional<z.ZodEnum<["start", "center", "end", "space-between", "space-around", "stretch"]>>;
|
|
@@ -34,6 +35,7 @@ export declare const layoutSpec: z.ZodObject<{
|
|
|
34
35
|
bottom?: number | undefined;
|
|
35
36
|
left?: number | undefined;
|
|
36
37
|
}>>;
|
|
38
|
+
padding_token: z.ZodOptional<z.ZodString>;
|
|
37
39
|
sizing_h: z.ZodOptional<z.ZodEnum<["hug", "fill", "fixed"]>>;
|
|
38
40
|
sizing_v: z.ZodOptional<z.ZodEnum<["hug", "fill", "fixed"]>>;
|
|
39
41
|
positioning: z.ZodOptional<z.ZodObject<{
|
|
@@ -51,8 +53,10 @@ export declare const layoutSpec: z.ZodObject<{
|
|
|
51
53
|
bottom?: number | undefined;
|
|
52
54
|
left?: number | undefined;
|
|
53
55
|
} | undefined;
|
|
56
|
+
padding_token?: string | undefined;
|
|
54
57
|
direction?: "vertical" | "horizontal" | undefined;
|
|
55
58
|
gap?: number | undefined;
|
|
59
|
+
gap_token?: string | undefined;
|
|
56
60
|
columns?: number | undefined;
|
|
57
61
|
align?: "start" | "center" | "end" | "stretch" | undefined;
|
|
58
62
|
align_content?: "start" | "center" | "end" | "stretch" | "space-between" | "space-around" | undefined;
|
|
@@ -70,8 +74,52 @@ export declare const layoutSpec: z.ZodObject<{
|
|
|
70
74
|
bottom?: number | undefined;
|
|
71
75
|
left?: number | undefined;
|
|
72
76
|
} | undefined;
|
|
77
|
+
padding_token?: string | undefined;
|
|
73
78
|
direction?: "vertical" | "horizontal" | undefined;
|
|
74
79
|
gap?: number | undefined;
|
|
80
|
+
gap_token?: string | undefined;
|
|
81
|
+
columns?: number | undefined;
|
|
82
|
+
align?: "start" | "center" | "end" | "stretch" | undefined;
|
|
83
|
+
align_content?: "start" | "center" | "end" | "stretch" | "space-between" | "space-around" | undefined;
|
|
84
|
+
align_items?: "start" | "center" | "end" | "stretch" | undefined;
|
|
85
|
+
sizing_h?: "fill" | "hug" | "fixed" | undefined;
|
|
86
|
+
sizing_v?: "fill" | "hug" | "fixed" | undefined;
|
|
87
|
+
positioning?: {
|
|
88
|
+
type: "relative" | "sticky" | "absolute";
|
|
89
|
+
} | undefined;
|
|
90
|
+
}>, {
|
|
91
|
+
kind: "stack" | "grid";
|
|
92
|
+
padding?: {
|
|
93
|
+
top?: number | undefined;
|
|
94
|
+
right?: number | undefined;
|
|
95
|
+
bottom?: number | undefined;
|
|
96
|
+
left?: number | undefined;
|
|
97
|
+
} | undefined;
|
|
98
|
+
padding_token?: string | undefined;
|
|
99
|
+
direction?: "vertical" | "horizontal" | undefined;
|
|
100
|
+
gap?: number | undefined;
|
|
101
|
+
gap_token?: string | undefined;
|
|
102
|
+
columns?: number | undefined;
|
|
103
|
+
align?: "start" | "center" | "end" | "stretch" | undefined;
|
|
104
|
+
align_content?: "start" | "center" | "end" | "stretch" | "space-between" | "space-around" | undefined;
|
|
105
|
+
align_items?: "start" | "center" | "end" | "stretch" | undefined;
|
|
106
|
+
sizing_h?: "fill" | "hug" | "fixed" | undefined;
|
|
107
|
+
sizing_v?: "fill" | "hug" | "fixed" | undefined;
|
|
108
|
+
positioning?: {
|
|
109
|
+
type: "relative" | "sticky" | "absolute";
|
|
110
|
+
} | undefined;
|
|
111
|
+
}, {
|
|
112
|
+
kind: "stack" | "grid";
|
|
113
|
+
padding?: {
|
|
114
|
+
top?: number | undefined;
|
|
115
|
+
right?: number | undefined;
|
|
116
|
+
bottom?: number | undefined;
|
|
117
|
+
left?: number | undefined;
|
|
118
|
+
} | undefined;
|
|
119
|
+
padding_token?: string | undefined;
|
|
120
|
+
direction?: "vertical" | "horizontal" | undefined;
|
|
121
|
+
gap?: number | undefined;
|
|
122
|
+
gap_token?: string | undefined;
|
|
75
123
|
columns?: number | undefined;
|
|
76
124
|
align?: "start" | "center" | "end" | "stretch" | undefined;
|
|
77
125
|
align_content?: "start" | "center" | "end" | "stretch" | "space-between" | "space-around" | undefined;
|
|
@@ -9,12 +9,14 @@ const telemetry_1 = require("./telemetry");
|
|
|
9
9
|
exports.positioningSpec = zod_1.z.object({
|
|
10
10
|
type: zod_1.z.enum(["relative", "sticky", "absolute"]),
|
|
11
11
|
});
|
|
12
|
+
const dtcgTokenPath = zod_1.z.string().min(1);
|
|
12
13
|
// ─── layoutSpec ──────────────────────────────────────────────────
|
|
13
14
|
// SPEC.md §2.3: kind REQUIRED, rest optional
|
|
14
15
|
exports.layoutSpec = zod_1.z.object({
|
|
15
16
|
kind: zod_1.z.enum(["stack", "grid"]),
|
|
16
17
|
direction: zod_1.z.enum(["vertical", "horizontal"]).optional(),
|
|
17
18
|
gap: zod_1.z.number().optional(),
|
|
19
|
+
gap_token: dtcgTokenPath.optional(),
|
|
18
20
|
columns: zod_1.z.number().int().min(1).optional(),
|
|
19
21
|
align: zod_1.z.enum(["start", "center", "end", "stretch"]).optional(),
|
|
20
22
|
align_content: zod_1.z.enum(["start", "center", "end", "space-between", "space-around", "stretch"]).optional(),
|
|
@@ -25,10 +27,37 @@ exports.layoutSpec = zod_1.z.object({
|
|
|
25
27
|
bottom: zod_1.z.number().optional(),
|
|
26
28
|
left: zod_1.z.number().optional()
|
|
27
29
|
}).strict().optional(),
|
|
30
|
+
padding_token: dtcgTokenPath.optional(),
|
|
28
31
|
sizing_h: zod_1.z.enum(["hug", "fill", "fixed"]).optional(),
|
|
29
32
|
sizing_v: zod_1.z.enum(["hug", "fill", "fixed"]).optional(),
|
|
30
33
|
positioning: exports.positioningSpec.optional(),
|
|
31
|
-
}).strict()
|
|
34
|
+
}).strict().superRefine((data, ctx) => {
|
|
35
|
+
// Fail-Closed Governance: Enforce tokens for spacing values if literal exists and > 0.
|
|
36
|
+
const rules = [
|
|
37
|
+
{ literal: 'gap', token: 'gap_token' },
|
|
38
|
+
{ literal: 'padding', token: 'padding_token' }
|
|
39
|
+
];
|
|
40
|
+
rules.forEach(({ literal, token }) => {
|
|
41
|
+
const literalValue = data[literal];
|
|
42
|
+
// Only enforce token if literal is actually providing a >0 spacing value.
|
|
43
|
+
// E.g. gap: 0 or padding: 0 object is generally fine to pass through without tracking.
|
|
44
|
+
let isSignificantValue = false;
|
|
45
|
+
if (typeof literalValue === 'number') {
|
|
46
|
+
isSignificantValue = literalValue > 0;
|
|
47
|
+
}
|
|
48
|
+
else if (literalValue && typeof literalValue === 'object') {
|
|
49
|
+
isSignificantValue = Object.values(literalValue).some(v => typeof v === 'number' && v > 0);
|
|
50
|
+
}
|
|
51
|
+
if (isSignificantValue && data[token] === undefined) {
|
|
52
|
+
ctx.addIssue({
|
|
53
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
54
|
+
message: `Fail-Closed Governance: Unbound Spacing Value. Layout declares physical [${literal}] but is missing [${token}]. Hardcoded layouts are rejected.`,
|
|
55
|
+
path: [literal],
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
return true;
|
|
60
|
+
});
|
|
32
61
|
// ─── Composition types ───────────────────────────────────────────
|
|
33
62
|
const compositionTypeEnum = zod_1.z.enum(["Card", "Stack", "Grid", "Header", "Footer"]);
|
|
34
63
|
const compositionTypes = new Set(["Card", "Stack", "Grid", "Header", "Footer"]);
|
package/dist/schemas/style.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
export declare const styleSpec: z.ZodObject<{
|
|
2
|
+
export declare const styleSpec: z.ZodEffects<z.ZodObject<{
|
|
3
3
|
bg_color: z.ZodOptional<z.ZodString>;
|
|
4
4
|
bg_color_token: z.ZodOptional<z.ZodString>;
|
|
5
5
|
text_color: z.ZodOptional<z.ZodString>;
|
|
@@ -188,5 +188,131 @@ export declare const styleSpec: z.ZodObject<{
|
|
|
188
188
|
height_token: z.ZodOptional<z.ZodString>;
|
|
189
189
|
opacity: z.ZodOptional<z.ZodNumber>;
|
|
190
190
|
opacity_token: z.ZodOptional<z.ZodString>;
|
|
191
|
+
}, z.ZodTypeAny, "passthrough">>, z.objectOutputType<{
|
|
192
|
+
bg_color: z.ZodOptional<z.ZodString>;
|
|
193
|
+
bg_color_token: z.ZodOptional<z.ZodString>;
|
|
194
|
+
text_color: z.ZodOptional<z.ZodString>;
|
|
195
|
+
text_color_token: z.ZodOptional<z.ZodString>;
|
|
196
|
+
border_color: z.ZodOptional<z.ZodString>;
|
|
197
|
+
border_color_token: z.ZodOptional<z.ZodString>;
|
|
198
|
+
font_family: z.ZodOptional<z.ZodString>;
|
|
199
|
+
font_family_token: z.ZodOptional<z.ZodString>;
|
|
200
|
+
font_size: z.ZodOptional<z.ZodNumber>;
|
|
201
|
+
font_size_token: z.ZodOptional<z.ZodString>;
|
|
202
|
+
font_weight: z.ZodOptional<z.ZodNumber>;
|
|
203
|
+
font_weight_token: z.ZodOptional<z.ZodString>;
|
|
204
|
+
line_height: z.ZodOptional<z.ZodNumber>;
|
|
205
|
+
line_height_token: z.ZodOptional<z.ZodString>;
|
|
206
|
+
padding: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodObject<{
|
|
207
|
+
top: z.ZodOptional<z.ZodNumber>;
|
|
208
|
+
right: z.ZodOptional<z.ZodNumber>;
|
|
209
|
+
bottom: z.ZodOptional<z.ZodNumber>;
|
|
210
|
+
left: z.ZodOptional<z.ZodNumber>;
|
|
211
|
+
}, "strip", z.ZodTypeAny, {
|
|
212
|
+
top?: number | undefined;
|
|
213
|
+
right?: number | undefined;
|
|
214
|
+
bottom?: number | undefined;
|
|
215
|
+
left?: number | undefined;
|
|
216
|
+
}, {
|
|
217
|
+
top?: number | undefined;
|
|
218
|
+
right?: number | undefined;
|
|
219
|
+
bottom?: number | undefined;
|
|
220
|
+
left?: number | undefined;
|
|
221
|
+
}>]>>;
|
|
222
|
+
padding_token: z.ZodOptional<z.ZodString>;
|
|
223
|
+
margin: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodObject<{
|
|
224
|
+
top: z.ZodOptional<z.ZodNumber>;
|
|
225
|
+
right: z.ZodOptional<z.ZodNumber>;
|
|
226
|
+
bottom: z.ZodOptional<z.ZodNumber>;
|
|
227
|
+
left: z.ZodOptional<z.ZodNumber>;
|
|
228
|
+
}, "strip", z.ZodTypeAny, {
|
|
229
|
+
top?: number | undefined;
|
|
230
|
+
right?: number | undefined;
|
|
231
|
+
bottom?: number | undefined;
|
|
232
|
+
left?: number | undefined;
|
|
233
|
+
}, {
|
|
234
|
+
top?: number | undefined;
|
|
235
|
+
right?: number | undefined;
|
|
236
|
+
bottom?: number | undefined;
|
|
237
|
+
left?: number | undefined;
|
|
238
|
+
}>]>>;
|
|
239
|
+
margin_token: z.ZodOptional<z.ZodString>;
|
|
240
|
+
border_radius: z.ZodOptional<z.ZodNumber>;
|
|
241
|
+
border_radius_token: z.ZodOptional<z.ZodString>;
|
|
242
|
+
border_width: z.ZodOptional<z.ZodNumber>;
|
|
243
|
+
border_width_token: z.ZodOptional<z.ZodString>;
|
|
244
|
+
min_height: z.ZodOptional<z.ZodNumber>;
|
|
245
|
+
min_height_token: z.ZodOptional<z.ZodString>;
|
|
246
|
+
min_width: z.ZodOptional<z.ZodNumber>;
|
|
247
|
+
min_width_token: z.ZodOptional<z.ZodString>;
|
|
248
|
+
width: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodString]>>;
|
|
249
|
+
width_token: z.ZodOptional<z.ZodString>;
|
|
250
|
+
height: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodString]>>;
|
|
251
|
+
height_token: z.ZodOptional<z.ZodString>;
|
|
252
|
+
opacity: z.ZodOptional<z.ZodNumber>;
|
|
253
|
+
opacity_token: z.ZodOptional<z.ZodString>;
|
|
254
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
255
|
+
bg_color: z.ZodOptional<z.ZodString>;
|
|
256
|
+
bg_color_token: z.ZodOptional<z.ZodString>;
|
|
257
|
+
text_color: z.ZodOptional<z.ZodString>;
|
|
258
|
+
text_color_token: z.ZodOptional<z.ZodString>;
|
|
259
|
+
border_color: z.ZodOptional<z.ZodString>;
|
|
260
|
+
border_color_token: z.ZodOptional<z.ZodString>;
|
|
261
|
+
font_family: z.ZodOptional<z.ZodString>;
|
|
262
|
+
font_family_token: z.ZodOptional<z.ZodString>;
|
|
263
|
+
font_size: z.ZodOptional<z.ZodNumber>;
|
|
264
|
+
font_size_token: z.ZodOptional<z.ZodString>;
|
|
265
|
+
font_weight: z.ZodOptional<z.ZodNumber>;
|
|
266
|
+
font_weight_token: z.ZodOptional<z.ZodString>;
|
|
267
|
+
line_height: z.ZodOptional<z.ZodNumber>;
|
|
268
|
+
line_height_token: z.ZodOptional<z.ZodString>;
|
|
269
|
+
padding: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodObject<{
|
|
270
|
+
top: z.ZodOptional<z.ZodNumber>;
|
|
271
|
+
right: z.ZodOptional<z.ZodNumber>;
|
|
272
|
+
bottom: z.ZodOptional<z.ZodNumber>;
|
|
273
|
+
left: z.ZodOptional<z.ZodNumber>;
|
|
274
|
+
}, "strip", z.ZodTypeAny, {
|
|
275
|
+
top?: number | undefined;
|
|
276
|
+
right?: number | undefined;
|
|
277
|
+
bottom?: number | undefined;
|
|
278
|
+
left?: number | undefined;
|
|
279
|
+
}, {
|
|
280
|
+
top?: number | undefined;
|
|
281
|
+
right?: number | undefined;
|
|
282
|
+
bottom?: number | undefined;
|
|
283
|
+
left?: number | undefined;
|
|
284
|
+
}>]>>;
|
|
285
|
+
padding_token: z.ZodOptional<z.ZodString>;
|
|
286
|
+
margin: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodObject<{
|
|
287
|
+
top: z.ZodOptional<z.ZodNumber>;
|
|
288
|
+
right: z.ZodOptional<z.ZodNumber>;
|
|
289
|
+
bottom: z.ZodOptional<z.ZodNumber>;
|
|
290
|
+
left: z.ZodOptional<z.ZodNumber>;
|
|
291
|
+
}, "strip", z.ZodTypeAny, {
|
|
292
|
+
top?: number | undefined;
|
|
293
|
+
right?: number | undefined;
|
|
294
|
+
bottom?: number | undefined;
|
|
295
|
+
left?: number | undefined;
|
|
296
|
+
}, {
|
|
297
|
+
top?: number | undefined;
|
|
298
|
+
right?: number | undefined;
|
|
299
|
+
bottom?: number | undefined;
|
|
300
|
+
left?: number | undefined;
|
|
301
|
+
}>]>>;
|
|
302
|
+
margin_token: z.ZodOptional<z.ZodString>;
|
|
303
|
+
border_radius: z.ZodOptional<z.ZodNumber>;
|
|
304
|
+
border_radius_token: z.ZodOptional<z.ZodString>;
|
|
305
|
+
border_width: z.ZodOptional<z.ZodNumber>;
|
|
306
|
+
border_width_token: z.ZodOptional<z.ZodString>;
|
|
307
|
+
min_height: z.ZodOptional<z.ZodNumber>;
|
|
308
|
+
min_height_token: z.ZodOptional<z.ZodString>;
|
|
309
|
+
min_width: z.ZodOptional<z.ZodNumber>;
|
|
310
|
+
min_width_token: z.ZodOptional<z.ZodString>;
|
|
311
|
+
width: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodString]>>;
|
|
312
|
+
width_token: z.ZodOptional<z.ZodString>;
|
|
313
|
+
height: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodString]>>;
|
|
314
|
+
height_token: z.ZodOptional<z.ZodString>;
|
|
315
|
+
opacity: z.ZodOptional<z.ZodNumber>;
|
|
316
|
+
opacity_token: z.ZodOptional<z.ZodString>;
|
|
191
317
|
}, z.ZodTypeAny, "passthrough">>;
|
|
192
318
|
export type StyleSpec = z.infer<typeof styleSpec>;
|
package/dist/schemas/style.js
CHANGED
|
@@ -66,4 +66,29 @@ exports.styleSpec = zod_1.z.object({
|
|
|
66
66
|
// ── Opacity ──
|
|
67
67
|
opacity: zod_1.z.number().min(0).max(1).optional(),
|
|
68
68
|
opacity_token: dtcgTokenPath.optional(),
|
|
69
|
-
}).passthrough()
|
|
69
|
+
}).passthrough().superRefine((data, ctx) => {
|
|
70
|
+
// Fail-Closed Governance: If a literal style value exists, its corresponding token MUST exist.
|
|
71
|
+
const rules = [
|
|
72
|
+
{ literal: 'bg_color', token: 'bg_color_token' },
|
|
73
|
+
{ literal: 'text_color', token: 'text_color_token' },
|
|
74
|
+
{ literal: 'border_color', token: 'border_color_token' },
|
|
75
|
+
{ literal: 'font_family', token: 'font_family_token' },
|
|
76
|
+
{ literal: 'font_size', token: 'font_size_token' },
|
|
77
|
+
{ literal: 'font_weight', token: 'font_weight_token' },
|
|
78
|
+
{ literal: 'line_height', token: 'line_height_token' },
|
|
79
|
+
{ literal: 'padding', token: 'padding_token' },
|
|
80
|
+
{ literal: 'margin', token: 'margin_token' },
|
|
81
|
+
{ literal: 'border_radius', token: 'border_radius_token' },
|
|
82
|
+
{ literal: 'border_width', token: 'border_width_token' }
|
|
83
|
+
];
|
|
84
|
+
rules.forEach(({ literal, token }) => {
|
|
85
|
+
if (data[literal] !== undefined && data[token] === undefined) {
|
|
86
|
+
ctx.addIssue({
|
|
87
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
88
|
+
message: `Fail-Closed Governance: Unbound Literal Value. Element declares [${literal}] but is missing [${token}]. Hardcoded visual styles are rejected by the design system.`,
|
|
89
|
+
path: [literal],
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
return true;
|
|
94
|
+
}); // Allow vendor extensions (§2.9)
|
package/package.json
CHANGED
|
@@ -17,12 +17,15 @@ export const positioningSpec = z.object({
|
|
|
17
17
|
type: z.enum(["relative", "sticky", "absolute"]),
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
+
const dtcgTokenPath = z.string().min(1);
|
|
21
|
+
|
|
20
22
|
// ─── layoutSpec ──────────────────────────────────────────────────
|
|
21
23
|
// SPEC.md §2.3: kind REQUIRED, rest optional
|
|
22
24
|
export const layoutSpec = z.object({
|
|
23
25
|
kind: z.enum(["stack", "grid"]),
|
|
24
26
|
direction: z.enum(["vertical", "horizontal"]).optional(),
|
|
25
27
|
gap: z.number().optional(),
|
|
28
|
+
gap_token: dtcgTokenPath.optional(),
|
|
26
29
|
columns: z.number().int().min(1).optional(),
|
|
27
30
|
align: z.enum(["start", "center", "end", "stretch"]).optional(),
|
|
28
31
|
align_content: z.enum(["start", "center", "end", "space-between", "space-around", "stretch"]).optional(),
|
|
@@ -33,10 +36,40 @@ export const layoutSpec = z.object({
|
|
|
33
36
|
bottom: z.number().optional(),
|
|
34
37
|
left: z.number().optional()
|
|
35
38
|
}).strict().optional(),
|
|
39
|
+
padding_token: dtcgTokenPath.optional(),
|
|
36
40
|
sizing_h: z.enum(["hug", "fill", "fixed"]).optional(),
|
|
37
41
|
sizing_v: z.enum(["hug", "fill", "fixed"]).optional(),
|
|
38
42
|
positioning: positioningSpec.optional(),
|
|
39
|
-
}).strict()
|
|
43
|
+
}).strict().superRefine((data, ctx) => {
|
|
44
|
+
// Fail-Closed Governance: Enforce tokens for spacing values if literal exists and > 0.
|
|
45
|
+
const rules = [
|
|
46
|
+
{ literal: 'gap', token: 'gap_token' },
|
|
47
|
+
{ literal: 'padding', token: 'padding_token' }
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
rules.forEach(({ literal, token }) => {
|
|
51
|
+
const literalValue = data[literal as keyof typeof data];
|
|
52
|
+
// Only enforce token if literal is actually providing a >0 spacing value.
|
|
53
|
+
// E.g. gap: 0 or padding: 0 object is generally fine to pass through without tracking.
|
|
54
|
+
let isSignificantValue = false;
|
|
55
|
+
|
|
56
|
+
if (typeof literalValue === 'number') {
|
|
57
|
+
isSignificantValue = literalValue > 0;
|
|
58
|
+
} else if (literalValue && typeof literalValue === 'object') {
|
|
59
|
+
isSignificantValue = Object.values(literalValue).some(v => typeof v === 'number' && v > 0);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (isSignificantValue && data[token as keyof typeof data] === undefined) {
|
|
63
|
+
ctx.addIssue({
|
|
64
|
+
code: z.ZodIssueCode.custom,
|
|
65
|
+
message: `Fail-Closed Governance: Unbound Spacing Value. Layout declares physical [${literal}] but is missing [${token}]. Hardcoded layouts are rejected.`,
|
|
66
|
+
path: [literal],
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
return true;
|
|
72
|
+
});
|
|
40
73
|
|
|
41
74
|
// ─── Composition types ───────────────────────────────────────────
|
|
42
75
|
const compositionTypeEnum = z.enum(["Card", "Stack", "Grid", "Header", "Footer"]);
|
package/src/schemas/style.ts
CHANGED
|
@@ -71,7 +71,34 @@ export const styleSpec = z.object({
|
|
|
71
71
|
// ── Opacity ──
|
|
72
72
|
opacity: z.number().min(0).max(1).optional(),
|
|
73
73
|
opacity_token: dtcgTokenPath.optional(),
|
|
74
|
-
}).passthrough()
|
|
74
|
+
}).passthrough().superRefine((data, ctx) => {
|
|
75
|
+
// Fail-Closed Governance: If a literal style value exists, its corresponding token MUST exist.
|
|
76
|
+
const rules = [
|
|
77
|
+
{ literal: 'bg_color', token: 'bg_color_token' },
|
|
78
|
+
{ literal: 'text_color', token: 'text_color_token' },
|
|
79
|
+
{ literal: 'border_color', token: 'border_color_token' },
|
|
80
|
+
{ literal: 'font_family', token: 'font_family_token' },
|
|
81
|
+
{ literal: 'font_size', token: 'font_size_token' },
|
|
82
|
+
{ literal: 'font_weight', token: 'font_weight_token' },
|
|
83
|
+
{ literal: 'line_height', token: 'line_height_token' },
|
|
84
|
+
{ literal: 'padding', token: 'padding_token' },
|
|
85
|
+
{ literal: 'margin', token: 'margin_token' },
|
|
86
|
+
{ literal: 'border_radius', token: 'border_radius_token' },
|
|
87
|
+
{ literal: 'border_width', token: 'border_width_token' }
|
|
88
|
+
];
|
|
89
|
+
|
|
90
|
+
rules.forEach(({ literal, token }) => {
|
|
91
|
+
if (data[literal as keyof typeof data] !== undefined && data[token as keyof typeof data] === undefined) {
|
|
92
|
+
ctx.addIssue({
|
|
93
|
+
code: z.ZodIssueCode.custom,
|
|
94
|
+
message: `Fail-Closed Governance: Unbound Literal Value. Element declares [${literal}] but is missing [${token}]. Hardcoded visual styles are rejected by the design system.`,
|
|
95
|
+
path: [literal],
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
return true;
|
|
101
|
+
}); // Allow vendor extensions (§2.9)
|
|
75
102
|
|
|
76
103
|
// ─── Types ───────────────────────────────────────────────────────
|
|
77
104
|
export type StyleSpec = z.infer<typeof styleSpec>;
|