@reqvire-org/ads 0.5.4 → 0.5.6
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/dist/ads-errors.mjs +105 -8
- package/dist/analysis/client-directive.mjs +26 -0
- package/dist/analysis/externals.mjs +47 -0
- package/dist/analysis/module-graph.mjs +6 -0
- package/dist/analysis/owner-analysis-key.mjs +1 -1
- package/dist/analysis/owner-choices.mjs +12 -2
- package/dist/analysis/owner-composition.mjs +19 -4
- package/dist/analysis/owner-source.mjs +112 -15
- package/dist/border-paint.mjs +34 -0
- package/dist/check.mjs +2 -0
- package/dist/composed-contrast.mjs +10 -7
- package/dist/construction-output.mjs +52 -27
- package/dist/construction-spec.d.mts +40 -10
- package/dist/construction-spec.mjs +41 -19
- package/dist/corner-overpaint.mjs +3 -1
- package/dist/design-foundation.mjs +14 -0
- package/dist/emit/owner-emission-cache.mjs +1 -1
- package/dist/end-alignment.mjs +75 -0
- package/dist/external-macro.d.mts +20 -0
- package/dist/external-macro.mjs +12 -0
- package/dist/finding-rules.mjs +3 -0
- package/dist/forced-colors.mjs +81 -0
- package/dist/frame-regions.mjs +2 -2
- package/dist/grid-facts.mjs +1 -1
- package/dist/guard/externals.mjs +64 -0
- package/dist/guard/run.mjs +9 -5
- package/dist/inventories.mjs +1 -1
- package/dist/lowering-emitter.mjs +2 -1
- package/dist/lowering-layer.mjs +39 -4
- package/dist/lowering-overlaps.mjs +7 -0
- package/dist/lowering-properties.mjs +2 -0
- package/dist/lowering-region-layout.mjs +23 -3
- package/dist/lowering-session.mjs +1 -1
- package/dist/mcp/preview-http.bundle.js +2 -2
- package/dist/mcp/preview-widget.bundle.js +12 -12
- package/dist/measured-geometry.mjs +8 -2
- package/dist/owner-analysis-check.mjs +190 -11
- package/dist/owner-errors.mjs +3 -0
- package/dist/owner-lowering.mjs +3 -2
- package/dist/ownership-model.mjs +6 -3
- package/dist/platform-features.mjs +2 -0
- package/dist/preview-bun.mjs +15 -2
- package/dist/profile-macro.d.mts +18 -0
- package/dist/recipe-macro.d.mts +49 -6
- package/dist/recipe-model.mjs +13 -5
- package/dist/region-lowering.mjs +115 -22
- package/dist/render-audit/axe-run.page.mjs +40 -1
- package/dist/render-audit/forced-states.page.mjs +37 -0
- package/dist/render-audit/layout-overflow.page.mjs +52 -2
- package/dist/render-audit/non-text-contrast.page.mjs +14 -10
- package/dist/render-audit/worker.mjs +38 -0
- package/dist/render-audit.mjs +42 -5
- package/dist/role-vocabulary.d.mts +2 -2
- package/dist/role-vocabulary.mjs +3 -3
- package/dist/scenario-kit.d.mts +2 -2
- package/dist/showcase/assets-view.mjs +17 -47
- package/dist/showcase/client.bundle.js +54 -54
- package/dist/showcase/http-client.bundle.js +18 -18
- package/dist/showcase/token-sample.mjs +16 -6
- package/dist/showcase/ui/ui.css +1 -1
- package/dist/showcase/ui/ui.js +13 -13
- package/dist/skills/ads-designer/references/accessibility.md +21 -1
- package/dist/skills/ads-designer/references/branding.md +4 -0
- package/dist/skills/ads-designer/references/design-data.md +6 -0
- package/dist/skills/ads-designer/references/layers.md +5 -0
- package/dist/skills/ads-designer/references/layout.md +8 -1
- package/dist/skills/ads-designer/references/recipes.md +36 -0
- package/dist/skills/ads-designer/references/runtimes.md +4 -0
- package/dist/skills/ads-designer/references/scenarios.md +2 -0
- package/dist/skills/ads-import/references/design-data.md +6 -0
- package/dist/skills/ads-import/references/layers.md +5 -0
- package/dist/skills/ads-import/references/layout.md +8 -1
- package/dist/skills/ads-import/references/recipes.md +36 -0
- package/dist/skills/ads-import/references/runtimes.md +4 -0
- package/dist/skills/ads-import/references/scenarios.md +2 -0
- package/dist/skills/ads-migrate/SKILL.md +1 -0
- package/dist/skills/ads-migrate/references/0.5.4-to-0.5.5.md +61 -0
- package/dist/skills/ads-port/references/design-data.md +6 -0
- package/dist/skills/ads-port/references/layers.md +5 -0
- package/dist/skills/ads-port/references/layout.md +8 -1
- package/dist/skills/ads-port/references/recipes.md +36 -0
- package/dist/skills/ads-port/references/runtimes.md +4 -0
- package/dist/skills/ads-port/references/scenarios.md +2 -0
- package/dist/spatial-model.mjs +37 -10
- package/dist/system-colors.d.mts +9 -0
- package/dist/system-colors.mjs +1 -0
- package/dist/target-size.mjs +14 -1
- package/dist/tsconfig.declarations.json +1 -0
- package/docs/ADS.md +23 -1
- package/docs/ASSETS.md +21 -0
- package/docs/CACHING.md +1 -1
- package/docs/CHANGELOG.md +184 -27
- package/docs/GUIDE.md +31 -20
- package/docs/LANGUAGE.md +122 -6
- package/docs/PROFILE-KINDS.md +50 -4
- package/docs/RULES.md +21 -8
- package/package.json +7 -1
|
@@ -9,7 +9,7 @@ export const ACCESSIBILITY_BOUNDARIES = ["visible-label", "boundary-on-interacti
|
|
|
9
9
|
translateInline: { channel: "translate", field: "distance" },
|
|
10
10
|
translateBlock: { channel: "translate", field: "distance" },
|
|
11
11
|
rotate: { channel: "rotate", field: "angle" }
|
|
12
|
-
}, scaleValue = (effect, value) => effect === "scale" ? value : effect === "scaleInline" || effect === "scale-inline" ? `${value} 1` : `1 ${value}`, STICKY_EDGES = ["block-start", "block-end"], ENTER_MOVEMENTS = { translate: "distance", translateInline: "distance", scale: "scale", rotate: "angle" }, PSEUDO_ELEMENTS = ["placeholder", "progressValue", "marker", "before"], REPLACED_ELEMENTS = ["img", "input", "select", "textarea", "video", "iframe", "br", "hr", "svg"], PSEUDO_HOSTS = { placeholder: ["input", "textarea"], progressValue: ["progress"], marker: ["li", "summary"], before: "non-replaced" }, pseudoHosted = (pseudo, element) => {
|
|
12
|
+
}, scaleValue = (effect, value) => effect === "scale" ? value : effect === "scaleInline" || effect === "scale-inline" ? `${value} 1` : `1 ${value}`, STICKY_EDGES = ["block-start", "block-end"], ENTER_MOVEMENTS = { translate: "distance", translateInline: "distance", scale: "scale", rotate: "angle" }, PSEUDO_ELEMENTS = ["placeholder", "progressValue", "marker", "before", "sliderTrack", "sliderThumb"], REPLACED_ELEMENTS = ["img", "input", "select", "textarea", "video", "iframe", "br", "hr", "svg"], PSEUDO_HOSTS = { placeholder: ["input", "textarea"], progressValue: ["progress"], marker: ["li", "summary"], before: "non-replaced", sliderTrack: ["input"], sliderThumb: ["input"] }, pseudoHosted = (pseudo, element) => {
|
|
13
13
|
const hosts = PSEUDO_HOSTS[pseudo];
|
|
14
14
|
return hosts === "non-replaced" ? !REPLACED_ELEMENTS.includes(element) : hosts.includes(element);
|
|
15
15
|
}, MARKER_STYLES = ["disc", "circle", "square", "none", "decimal", "decimal-leading-zero", "lower-alpha", "upper-alpha", "lower-roman", "upper-roman"], COUNTER_STYLES = ["decimal", "decimal-leading-zero", "lower-alpha", "upper-alpha", "lower-roman", "upper-roman"], SNAP_TYPES = ["inline mandatory", "inline proximity", "block mandatory", "block proximity", "both mandatory", "both proximity"], SNAP_ALIGNS = ["start", "center", "end"], GEOMETRY_CHANNELS = ["size", "inset", "gap", "radius", "border-width", "overlap"], FRAME_SIDES = ["block-start", "block-end", "inline-start", "inline-end"], FRAME_CORNERS = ["start-start", "start-end", "end-start", "end-end"], CORNER_RADIUS_FIELDS = {
|
|
@@ -17,7 +17,7 @@ export const ACCESSIBILITY_BOUNDARIES = ["visible-label", "boundary-on-interacti
|
|
|
17
17
|
"start-end": "start-end-radius",
|
|
18
18
|
"end-start": "end-start-radius",
|
|
19
19
|
"end-end": "end-end-radius"
|
|
20
|
-
}, cornerRadius = (field, corner) => field(CORNER_RADIUS_FIELDS[corner]) ?? field("radius"), OVERFLOW_VALUES = ["clip", "scroll-block", "scroll-inline", "scroll-both"], ELEMENT_NAMES = ["iframe", "select", "search-input", "text-input", "table", "header-cell", "cell", "list", "summary"], TEXT_WRAPS = ["anywhere", "never", "truncate", "balance", "pretty"], TEXT_ALIGNS = ["start", "center", "end"], MEASURED_TYPES = ["length", "transform", "size-track", "position", "intrinsic-size"], GRID_FIELDS = ["columns", "weights", "gutter", "margin", "bound", "rows", "context", "align"];
|
|
20
|
+
}, cornerRadius = (field, corner) => field(CORNER_RADIUS_FIELDS[corner]) ?? field("radius"), OVERFLOW_VALUES = ["clip", "scroll-block", "scroll-inline", "scroll-both"], ELEMENT_NAMES = ["iframe", "select", "search-input", "text-input", "table", "header-cell", "cell", "list", "summary", "document"], TEXT_WRAPS = ["anywhere", "never", "truncate", "balance", "pretty", "preserve"], TEXT_ALIGNS = ["start", "center", "end"], MEASURED_TYPES = ["length", "transform", "scale", "size-track", "position", "intrinsic-size"], GRID_FIELDS = ["columns", "weights", "gutter", "margin", "bound", "rows", "context", "align", "contentFrom"];
|
|
21
21
|
export function elementTags(element) {
|
|
22
22
|
switch (element.kind) {
|
|
23
23
|
case "iframe":
|
|
@@ -30,6 +30,8 @@ export function elementTags(element) {
|
|
|
30
30
|
return [element.header ? "th" : "td"];
|
|
31
31
|
case "list":
|
|
32
32
|
return ["ul", "ol"];
|
|
33
|
+
case "document":
|
|
34
|
+
return ["html"];
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
37
|
export const CONTROL_TEXT_TAGS = ["button", "label", "legend", "summary", "select", "option", "input", "textarea"], VECTOR_SHAPES = ["line", "path", "circle", "rect", "polyline"];
|
|
@@ -376,26 +378,29 @@ function artwork(spec, read) {
|
|
|
376
378
|
}
|
|
377
379
|
const REGION_LAYOUTS = ["inline", "stack", "flow", "layered"], ROOT_LAYOUTS = REGION_LAYOUTS;
|
|
378
380
|
export const ROOT_EXTENTS = ["content", "container"];
|
|
379
|
-
function rootExtent(value, layout, layer, read) {
|
|
381
|
+
function rootExtent(value, layout, layer, read, table = !1) {
|
|
380
382
|
if (value === void 0)
|
|
381
383
|
return "content";
|
|
382
|
-
if (layout !== "inline" || layer !== null)
|
|
384
|
+
if (layout !== "inline" && !table || layer !== null)
|
|
383
385
|
return read.reject({ kind: "field-unsupported", construction: "region", path: "recipe.extent" });
|
|
384
386
|
return read.literal(value, "recipe.extent", ROOT_EXTENTS);
|
|
385
387
|
}
|
|
386
388
|
function arrangement(spec, read, path, layout) {
|
|
387
|
-
const gap = spec.gap ?? spec.rowGap;
|
|
389
|
+
const gap = spec.gap ?? spec.rowGap, rowGap = spec.gap !== void 0 && spec.rowGap !== void 0 ? spec.rowGap : void 0;
|
|
388
390
|
if (layout === "layered") {
|
|
389
391
|
for (const field of ["gap", "rowGap", "wrap"])
|
|
390
392
|
if (spec[field] !== void 0)
|
|
391
393
|
read.reject({ kind: "field-unsupported", construction: "region", path: `${path}.${field}` });
|
|
392
394
|
}
|
|
395
|
+
if (layout === "layered" && typeof spec.justify === "string" && spec.justify.startsWith("space-"))
|
|
396
|
+
read.reject({ kind: "field-unsupported", construction: "region", path: `${path}.justify` });
|
|
393
397
|
return {
|
|
394
398
|
layout,
|
|
395
399
|
align: read.optionalString(spec.align, `${path}.align`),
|
|
396
400
|
justify: read.optionalString(spec.justify, `${path}.justify`),
|
|
397
401
|
wrap: read.boolean(spec.wrap, `${path}.wrap`),
|
|
398
402
|
gap: gap === void 0 ? null : read.slot(gap, `${path}.gap`, "spacing"),
|
|
403
|
+
...rowGap === void 0 ? {} : { rowGap: read.slot(rowGap, `${path}.rowGap`, "spacing") },
|
|
399
404
|
overlap: overlapSpec(spec, read, path, layout),
|
|
400
405
|
snap: snap(spec.snap, `${path}.snap`, read)
|
|
401
406
|
};
|
|
@@ -480,8 +485,6 @@ function rootWhen(spec, read, geometry = !1) {
|
|
|
480
485
|
if (fields.surface !== void 0)
|
|
481
486
|
when.push([state, read.string(fields.surface, `${at}.surface`)]);
|
|
482
487
|
if (fields.scale !== void 0) {
|
|
483
|
-
if (pressed.length > 0)
|
|
484
|
-
read.invalid(`${at}.scale`, "one press `scale` endpoint per root");
|
|
485
488
|
const field = read.literal(read.slot(fields.scale, `${at}.scale`, "motion").field, `${at}.scale.field`, ["scale"]);
|
|
486
489
|
pressed.push({ condition: state, field, path: `${at}.scale` });
|
|
487
490
|
}
|
|
@@ -661,14 +664,15 @@ function pseudoTreatments(value, path, read) {
|
|
|
661
664
|
if (value === void 0)
|
|
662
665
|
return [];
|
|
663
666
|
return Object.entries(read.object(value, path)).map(([name, treatment]) => {
|
|
664
|
-
const at = `${path}.${name}`, pseudo = read.literal(name, at, PSEUDO_ELEMENTS), fields = read.object(treatment, at), generated = pseudo === "marker" || pseudo === "before";
|
|
665
|
-
read.only(fields, at, generated ? ["surface", "text", "content", "when"] : ["surface", "when"]);
|
|
667
|
+
const at = `${path}.${name}`, pseudo = read.literal(name, at, PSEUDO_ELEMENTS), fields = read.object(treatment, at), generated = pseudo === "marker" || pseudo === "before", slider = pseudo === "sliderTrack" || pseudo === "sliderThumb";
|
|
668
|
+
read.only(fields, at, generated ? ["surface", "text", "content", "when"] : slider ? ["surface", "frame", "when"] : ["surface", "when"]);
|
|
666
669
|
const surface = generated ? read.optionalString(fields.surface, `${at}.surface`) : read.string(fields.surface, `${at}.surface`), text = read.optionalString(fields.text, `${at}.text`), content = generatedContent(fields.content, `${at}.content`, read);
|
|
667
670
|
if (pseudo === "before" && content === null)
|
|
668
671
|
read.invalid(`${at}.content`, "the generated content `before` shows (a counter)");
|
|
669
672
|
if (pseudo === "marker" && surface === null && text === null && content === null)
|
|
670
673
|
read.invalid(at, "a `surface`, a `text`, a `content` or several");
|
|
671
|
-
|
|
674
|
+
const frame = slider ? read.string(fields.frame, `${at}.frame`) : null;
|
|
675
|
+
return { pseudo, surface, text, content, ...slider ? { frame } : {}, when: treatments(fields.when, `${at}.when`, read) };
|
|
672
676
|
});
|
|
673
677
|
}
|
|
674
678
|
function frameBorder(value, path, read) {
|
|
@@ -847,7 +851,9 @@ function overflow(value, path, read) {
|
|
|
847
851
|
return { kind: "scroll", axis: "both" };
|
|
848
852
|
}
|
|
849
853
|
}
|
|
850
|
-
function elementKind(value, marker, path, read) {
|
|
854
|
+
function elementKind(value, marker, path, read, align) {
|
|
855
|
+
if (align !== void 0 && value !== "cell" && value !== "header-cell")
|
|
856
|
+
read.reject({ kind: "field-unsupported", construction: "region", path: `${path}.align` });
|
|
851
857
|
if (value === void 0) {
|
|
852
858
|
if (marker !== void 0)
|
|
853
859
|
read.reject({ kind: "field-unsupported", construction: "region", path: `${path}.marker` });
|
|
@@ -862,14 +868,17 @@ function elementKind(value, marker, path, read) {
|
|
|
862
868
|
case "table":
|
|
863
869
|
case "list":
|
|
864
870
|
return { kind: name };
|
|
871
|
+
case "document":
|
|
872
|
+
if (path !== "recipe")
|
|
873
|
+
read.reject({ kind: "field-unsupported", construction: "region", path: `${path}.element` });
|
|
874
|
+
return { kind: name };
|
|
865
875
|
case "search-input":
|
|
866
876
|
return { kind: "input", type: "search" };
|
|
867
877
|
case "text-input":
|
|
868
878
|
return { kind: "input", type: "text" };
|
|
869
879
|
case "header-cell":
|
|
870
|
-
return { kind: "cell", header: !0 };
|
|
871
880
|
case "cell":
|
|
872
|
-
return { kind: "cell", header:
|
|
881
|
+
return { kind: "cell", header: name === "header-cell", align: align === void 0 ? "center" : read.literal(align, `${path}.align`, ["start", "center", "end"]) };
|
|
873
882
|
case "summary":
|
|
874
883
|
return { kind: "summary", marker: marker === void 0 ? "native" : read.literal(marker, `${path}.marker`, ["native", "none"]) };
|
|
875
884
|
}
|
|
@@ -966,6 +975,15 @@ function measuredValues(value, path, read) {
|
|
|
966
975
|
read.only(offset, `${at}.fallback`, ["x", "y"]);
|
|
967
976
|
return { type, name, property, fallback: { x: pixels(offset.x, `${at}.fallback.x`, read), y: pixels(offset.y, `${at}.fallback.y`, read) }, motion };
|
|
968
977
|
}
|
|
978
|
+
case "scale": {
|
|
979
|
+
read.only(fields, at, ["type", "property", "fallback", "motion"]);
|
|
980
|
+
if (fallback === void 0)
|
|
981
|
+
return { type, name, property, fallback: null, motion };
|
|
982
|
+
const factors = read.object(fallback, `${at}.fallback`);
|
|
983
|
+
read.only(factors, `${at}.fallback`, ["x", "y"]);
|
|
984
|
+
const factor = (value, path) => typeof value === "number" && Number.isFinite(value) && value > 0 ? value : read.invalid(path, "a positive scale factor");
|
|
985
|
+
return { type, name, property, fallback: { x: factor(factors.x, `${at}.fallback.x`), y: factor(factors.y, `${at}.fallback.y`) }, motion };
|
|
986
|
+
}
|
|
969
987
|
case "size-track": {
|
|
970
988
|
read.only(fields, at, ["type", "property", "track", "fallback", "motion"]);
|
|
971
989
|
const track = fields.track;
|
|
@@ -1056,6 +1074,7 @@ function regionPart(name, value, read, path, nested) {
|
|
|
1056
1074
|
"at",
|
|
1057
1075
|
"element",
|
|
1058
1076
|
"marker",
|
|
1077
|
+
"align",
|
|
1059
1078
|
"media",
|
|
1060
1079
|
"stroke",
|
|
1061
1080
|
"accessibility",
|
|
@@ -1104,7 +1123,7 @@ function regionPart(name, value, read, path, nested) {
|
|
|
1104
1123
|
overflow: overflow(part.overflow, `${path}.overflow`, read),
|
|
1105
1124
|
extent: extent(part.extent, `${path}.extent`, read),
|
|
1106
1125
|
at: partConditions(part.at, `${path}.at`, read),
|
|
1107
|
-
element: elementKind(part.element, part.marker, path, read),
|
|
1126
|
+
element: elementKind(part.element, part.marker, path, read, part.align),
|
|
1108
1127
|
text: textBinding(part.text, `${path}.text`, read),
|
|
1109
1128
|
surface: read.optionalString(part.surface, `${path}.surface`),
|
|
1110
1129
|
frame: boxed === null ? controlFrame(part.frame, `${path}.frame`, read) : null,
|
|
@@ -1243,6 +1262,7 @@ function region(authored, read) {
|
|
|
1243
1262
|
"counter",
|
|
1244
1263
|
"markers",
|
|
1245
1264
|
"between",
|
|
1265
|
+
"carry",
|
|
1246
1266
|
"parts",
|
|
1247
1267
|
"exposeRows",
|
|
1248
1268
|
"layer",
|
|
@@ -1274,16 +1294,17 @@ function region(authored, read) {
|
|
|
1274
1294
|
counter: counterSpec(spec.counter, "recipe.counter", read),
|
|
1275
1295
|
markers: markerStyles(spec.markers, "recipe.markers", read),
|
|
1276
1296
|
between: betweenRule(spec.between, "recipe.between", read),
|
|
1297
|
+
carry: read.boolean(spec.carry, "recipe.carry"),
|
|
1277
1298
|
profile: read.optionalString(spec.profile, "recipe.profile"),
|
|
1278
1299
|
select: Object.fromEntries(spec.select === void 0 ? [] : read.stringRecord(spec.select, "recipe.select")),
|
|
1279
1300
|
arrangement: arrangement(spec, read, "recipe", layout),
|
|
1280
|
-
extent: rootExtent(spec.extent, layout, layer, read),
|
|
1301
|
+
extent: rootExtent(spec.extent, layout, layer, read, spec.element === "table"),
|
|
1281
1302
|
frame: regionFrame(spec.frame, read),
|
|
1282
1303
|
surface: read.optionalString(spec.surface, "recipe.surface"),
|
|
1283
1304
|
text: textBinding(spec.text, "recipe.text", read),
|
|
1284
1305
|
textAlign: spec.textAlign === void 0 ? null : read.literal(spec.textAlign, "recipe.textAlign", TEXT_ALIGNS),
|
|
1285
1306
|
overflow: overflow(spec.overflow, "recipe.overflow", read),
|
|
1286
|
-
element: elementKind(spec.element, spec.marker, "recipe", read),
|
|
1307
|
+
element: elementKind(spec.element, spec.marker, "recipe", read, spec.element === "cell" || spec.element === "header-cell" ? spec.align : void 0),
|
|
1287
1308
|
normalize: normalized.values,
|
|
1288
1309
|
normalizeWhen: normalized.when,
|
|
1289
1310
|
when: rootStates.when,
|
|
@@ -1304,7 +1325,7 @@ function region(authored, read) {
|
|
|
1304
1325
|
paints
|
|
1305
1326
|
};
|
|
1306
1327
|
}
|
|
1307
|
-
const EDGES = ["start", "end"];
|
|
1328
|
+
const EDGES = ["start", "end"], DIALOG_EDGES = ["start", "end", "center", "block-start"];
|
|
1308
1329
|
function layerSpec(value, read) {
|
|
1309
1330
|
if (value === void 0)
|
|
1310
1331
|
return null;
|
|
@@ -1314,15 +1335,16 @@ function layerSpec(value, read) {
|
|
|
1314
1335
|
read.only(layer, path, ["element", "edge", "backdrop", "motion", "modalBelow"]);
|
|
1315
1336
|
const backdrop = read.object(layer.backdrop, `${path}.backdrop`);
|
|
1316
1337
|
read.only(backdrop, `${path}.backdrop`, ["surface", "dismiss"]);
|
|
1338
|
+
const edge = read.literal(layer.edge, `${path}.edge`, DIALOG_EDGES), card = edge === "center" || edge === "block-start";
|
|
1317
1339
|
return {
|
|
1318
1340
|
kind: "modal-sheet",
|
|
1319
1341
|
element,
|
|
1320
|
-
edge
|
|
1342
|
+
edge,
|
|
1321
1343
|
backdrop: {
|
|
1322
1344
|
surface: read.string(backdrop.surface, `${path}.backdrop.surface`),
|
|
1323
1345
|
dismiss: backdrop.dismiss === void 0 ? "none" : read.literal(backdrop.dismiss, `${path}.backdrop.dismiss`, ["press", "none"])
|
|
1324
1346
|
},
|
|
1325
|
-
motion: layer.motion === void 0 ? null : read.literal(layer.motion, `${path}.motion`, ["slide"]),
|
|
1347
|
+
motion: layer.motion === void 0 ? null : card ? read.literal(layer.motion, `${path}.motion`, ["fade"]) : read.literal(layer.motion, `${path}.motion`, ["slide"]),
|
|
1326
1348
|
modalBelow: read.optionalString(layer.modalBelow, `${path}.modalBelow`)
|
|
1327
1349
|
};
|
|
1328
1350
|
}
|
|
@@ -47,9 +47,11 @@ function overpaintUnder(foundation, spec, under) {
|
|
|
47
47
|
const corners = reached(index);
|
|
48
48
|
if (corners.length === 0)
|
|
49
49
|
continue;
|
|
50
|
-
const box = fieldsOf(foundation, framedUnder(
|
|
50
|
+
const own = part.box ?? (part.frame !== null ? slots.get("frame-profile") ?? null : null), box = fieldsOf(foundation, framedUnder(own, part.geometryWhen, under), "frame");
|
|
51
51
|
if (box !== null && corners.every((corner) => cornerRadius((field) => box.get(field), corner) !== void 0))
|
|
52
52
|
continue;
|
|
53
|
+
if (box?.get("border-width") !== void 0 && box.get("border-style") !== "forced-only")
|
|
54
|
+
return { kind: "corner-overpaint", part: part.name, surface: part.surface ?? "", state: null, corners, under, paint: "border" };
|
|
53
55
|
for (const [state, name] of [[null, part.surface], ...part.when]) {
|
|
54
56
|
const background = fieldsOf(foundation, name, "surface")?.get("background");
|
|
55
57
|
if (name === null || background === void 0)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FORCED_PREFIX, SYSTEM_COLORS } from "./forced-colors.mjs";
|
|
1
2
|
import path from "node:path";
|
|
2
3
|
import postcss, { CssSyntaxError } from "postcss";
|
|
3
4
|
import { readTokenRegistrations } from "./token-registrations.mjs";
|
|
@@ -128,6 +129,11 @@ export function readFoundation(captured, contexts) {
|
|
|
128
129
|
}
|
|
129
130
|
continue;
|
|
130
131
|
}
|
|
132
|
+
if (field.startsWith(FORCED_PREFIX)) {
|
|
133
|
+
if (!SYSTEM_COLORS.includes(value))
|
|
134
|
+
return reject({ kind: "forced-color-invalid", profile: name, field, value });
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
131
137
|
const expected = roles?.[field];
|
|
132
138
|
if (expected === void 0)
|
|
133
139
|
continue;
|
|
@@ -210,6 +216,7 @@ function slotArguments(spec, file, declaration) {
|
|
|
210
216
|
return Object.entries(objectAt(value.select)).map(([choice, option]) => ({ file, declaration, path: [...path, field, "select", choice], profile, reference, choice, option: String(option) }));
|
|
211
217
|
}));
|
|
212
218
|
}
|
|
219
|
+
const DOCUMENT_TEXT_FIELDS = ["font-family", "font-size", "line-height"];
|
|
213
220
|
export function documentProfiles(foundation, references) {
|
|
214
221
|
const fields = (field) => {
|
|
215
222
|
const reference = references[field], profile = selectedProfile(foundation, reference);
|
|
@@ -221,6 +228,9 @@ export function documentProfiles(foundation, references) {
|
|
|
221
228
|
}, text = fields("text");
|
|
222
229
|
if (text.kind === "err")
|
|
223
230
|
return text;
|
|
231
|
+
const missing = DOCUMENT_TEXT_FIELDS.filter((field) => !text.value.has(field));
|
|
232
|
+
if (missing.length > 0)
|
|
233
|
+
return err({ kind: "document-text-incomplete", reference: references.text, missing });
|
|
224
234
|
const surface = fields("surface");
|
|
225
235
|
if (surface.kind === "err")
|
|
226
236
|
return surface;
|
|
@@ -530,6 +540,10 @@ export function describeFoundationFailure(failure) {
|
|
|
530
540
|
return `Wrong role ${failure.profile}.${failure.field}: ${failure.token}`;
|
|
531
541
|
case "provided-role-self":
|
|
532
542
|
return `Profile ${failure.profile} provides ${failure.token} and reads it in ${failure.field}`;
|
|
543
|
+
case "forced-color-invalid":
|
|
544
|
+
return `Profile ${failure.profile} ${failure.field}: ${failure.value} is not a CSS system colour`;
|
|
545
|
+
case "document-text-incomplete":
|
|
546
|
+
return `foundation.ads.ts text: ${failure.reference} states no ${failure.missing.join(", ")}`;
|
|
533
547
|
case "document-profile-kind":
|
|
534
548
|
return `foundation.ads.ts ${failure.field}: ${failure.reference} is a ${failure.actual} profile, not a ${failure.field} profile`;
|
|
535
549
|
}
|
|
@@ -49,4 +49,4 @@ export function outcomeDigest(owner, root) {
|
|
|
49
49
|
outcomeDigests.set(owner, computed);
|
|
50
50
|
return computed;
|
|
51
51
|
}
|
|
52
|
-
export const ownerEmissionKey = (inputs) => digest(["ads-owner-emission/
|
|
52
|
+
export const ownerEmissionKey = (inputs) => digest(["ads-owner-emission/2", inputs.analysisKey, outcomeDigest(inputs.outcome, inputs.root), inputs.classes]);
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { selectedProfile } from "./design-foundation.mjs";
|
|
2
|
+
import { frameInlineInsets, sideWidth } from "./lowering-region-layout.mjs";
|
|
3
|
+
const tokenOf = (value) => value === void 0 ? void 0 : value.startsWith("--") ? `var(${value})` : value;
|
|
4
|
+
function borderedAtEnd(fields, border) {
|
|
5
|
+
if (border !== null && border.kind === "rules")
|
|
6
|
+
return border.sides.includes("inline-end") && fields.has("border-width");
|
|
7
|
+
const width = sideWidth(Object.fromEntries(fields), "inline-end");
|
|
8
|
+
return width !== void 0 && !/^0(px)?$/.test(width.trim());
|
|
9
|
+
}
|
|
10
|
+
export function endInsetOf(foundation, spec) {
|
|
11
|
+
switch (spec.kind) {
|
|
12
|
+
case "region": {
|
|
13
|
+
if (spec.frame === null || spec.profile === null)
|
|
14
|
+
return [];
|
|
15
|
+
const selected = selectedProfile(foundation, spec.profile, spec.select);
|
|
16
|
+
if (selected.kind === "err")
|
|
17
|
+
return null;
|
|
18
|
+
const frameName = selected.value.kind === "frame" ? spec.profile : selected.value.kind === "composite" ? selected.value.fields.get("frame-profile") : void 0;
|
|
19
|
+
if (frameName === void 0)
|
|
20
|
+
return [];
|
|
21
|
+
const frame = frameName === spec.profile ? selected : selectedProfile(foundation, frameName);
|
|
22
|
+
if (frame.kind === "err" || frame.value.kind !== "frame")
|
|
23
|
+
return null;
|
|
24
|
+
const surfaceName = spec.surface ?? (selected.value.kind === "composite" ? selected.value.fields.get("surface-profile") : void 0), surface = surfaceName === void 0 ? null : selectedProfile(foundation, surfaceName);
|
|
25
|
+
if (surface !== null && surface.kind === "ok" && surface.value.kind === "surface" && surface.value.fields.has("background") || borderedAtEnd(frame.value.fields, spec.frame?.border ?? null))
|
|
26
|
+
return [];
|
|
27
|
+
const end = frameInlineInsets(Object.fromEntries(frame.value.fields)).end;
|
|
28
|
+
return end === void 0 ? [] : [end];
|
|
29
|
+
}
|
|
30
|
+
case "grid": {
|
|
31
|
+
if (spec.mode !== "fluid" && spec.mode !== "hybrid")
|
|
32
|
+
return null;
|
|
33
|
+
const mode = spec.layout.find(([key]) => key === "gutter")?.[1] ?? "wide";
|
|
34
|
+
if (mode === "none")
|
|
35
|
+
return [];
|
|
36
|
+
const named = selectedProfile(foundation, spec.profile);
|
|
37
|
+
if (named.kind === "err")
|
|
38
|
+
return null;
|
|
39
|
+
const reference = named.value.kind === "spatial" ? spec.profile : named.value.fields.get("spatial-profile");
|
|
40
|
+
if (reference === void 0)
|
|
41
|
+
return null;
|
|
42
|
+
const spatial = reference === spec.profile ? named : selectedProfile(foundation, reference);
|
|
43
|
+
if (spatial.kind === "err" || spatial.value.kind !== "spatial")
|
|
44
|
+
return null;
|
|
45
|
+
const gutter = spatial.value.clauses.get(`ads-gutter ${String(mode)}`);
|
|
46
|
+
if (gutter === void 0)
|
|
47
|
+
return null;
|
|
48
|
+
if (gutter.get("gap") !== void 0)
|
|
49
|
+
return [];
|
|
50
|
+
const end = tokenOf(gutter.get("end"));
|
|
51
|
+
return end === void 0 ? null : [end];
|
|
52
|
+
}
|
|
53
|
+
case "control":
|
|
54
|
+
case "artwork":
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export function stackPartsOf(foundation, spec) {
|
|
59
|
+
if (spec.kind !== "region" || spec.arrangement.layout !== "stack")
|
|
60
|
+
return [];
|
|
61
|
+
return spec.parts.flatMap((part) => {
|
|
62
|
+
if (part.content.kind === "component")
|
|
63
|
+
return [{ part: part.name, kind: "component", inset: [] }];
|
|
64
|
+
if (part.box === null)
|
|
65
|
+
return [];
|
|
66
|
+
const frame = selectedProfile(foundation, part.box);
|
|
67
|
+
if (frame.kind === "err" || frame.value.kind !== "frame")
|
|
68
|
+
return [];
|
|
69
|
+
const surface = part.surface === null ? null : selectedProfile(foundation, part.surface);
|
|
70
|
+
if (surface !== null && surface.kind === "ok" && surface.value.kind === "surface" && surface.value.fields.has("background") || borderedAtEnd(frame.value.fields, null))
|
|
71
|
+
return [{ part: part.name, kind: "box", inset: [] }];
|
|
72
|
+
const end = frameInlineInsets(Object.fromEntries(frame.value.fields)).end;
|
|
73
|
+
return [{ part: part.name, kind: "box", inset: end === void 0 ? [] : [end] }];
|
|
74
|
+
});
|
|
75
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** What an external renders and where it comes from. */
|
|
2
|
+
export interface ExternalSpec {
|
|
3
|
+
/** The module that exports it: `"next/link"`. */
|
|
4
|
+
readonly from: string;
|
|
5
|
+
/** Its export: `"default"` (the default) or a named export (`"Html"` of `next/document`). */
|
|
6
|
+
readonly name?: string;
|
|
7
|
+
/** The one element it renders (`"a"`): ADS checks owners as if they wrote that element. */
|
|
8
|
+
readonly renders: string;
|
|
9
|
+
/** The library component needs the client (state, effects): owners that render it are "use client". */
|
|
10
|
+
readonly client?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/** The props every external takes beside its declared ones: the owner's class and what it holds. */
|
|
13
|
+
export interface ExternalBaseProps {
|
|
14
|
+
readonly className?: string;
|
|
15
|
+
readonly children?: unknown;
|
|
16
|
+
}
|
|
17
|
+
/** A declared external, typed as a component of its props. Never called by ADS: owners render the real one. */
|
|
18
|
+
export type External<Props> = (props: Props & ExternalBaseProps) => never;
|
|
19
|
+
/** Declares an external component. */
|
|
20
|
+
export declare function external<Props>(spec: ExternalSpec): External<Props>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const MODULE = /^(?:@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*(?:\/[\w.-]+)*$/, ELEMENT = /^[a-z][a-z0-9-]*$/;
|
|
2
|
+
export function external(spec) {
|
|
3
|
+
if (!MODULE.test(spec.from))
|
|
4
|
+
throw Error(`external: "${spec.from}" is not a package module (a bare specifier such as "next/link").`);
|
|
5
|
+
if (!ELEMENT.test(spec.renders))
|
|
6
|
+
throw Error(`external: renders "${spec.renders}" is not an element name.`);
|
|
7
|
+
if (spec.name !== void 0 && !/^[A-Za-z_$][\w$]*$/.test(spec.name))
|
|
8
|
+
throw Error(`external: name "${spec.name}" is not an export name.`);
|
|
9
|
+
return () => {
|
|
10
|
+
throw Error(`external ${spec.from}: an ADS declaration is not rendered; the emitted design system re-exports the real component.`);
|
|
11
|
+
};
|
|
12
|
+
}
|
package/dist/finding-rules.mjs
CHANGED
|
@@ -5,6 +5,7 @@ export const findingRules = Object.freeze({
|
|
|
5
5
|
"a11y-text-scale": "error",
|
|
6
6
|
"a11y-text-spacing-override": "error",
|
|
7
7
|
"a11y-reflow": "error",
|
|
8
|
+
"a11y-forced-colors-render": "error",
|
|
8
9
|
"render-audit": "error",
|
|
9
10
|
"a11y-focus": "error",
|
|
10
11
|
"a11y-icon-label": "error",
|
|
@@ -13,6 +14,8 @@ export const findingRules = Object.freeze({
|
|
|
13
14
|
"a11y-text-resize": "error",
|
|
14
15
|
"a11y-focus-unresolved": "review",
|
|
15
16
|
"a11y-target-size-unresolved": "review",
|
|
17
|
+
"a11y-forced-colors": "error",
|
|
18
|
+
"a11y-forced-colors-review": "review",
|
|
16
19
|
"a11y-keyboard": "review",
|
|
17
20
|
"a11y-motion-endless": "info",
|
|
18
21
|
"a11y-incomplete": "info",
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { selectedProfile } from "./design-foundation.mjs";
|
|
2
|
+
export { SYSTEM_COLORS } from "./system-colors.mjs";
|
|
3
|
+
export const FORCED_FIELDS = {
|
|
4
|
+
"forced-colors-background": "background",
|
|
5
|
+
"forced-colors-color": "color",
|
|
6
|
+
"forced-colors-border": "border-color"
|
|
7
|
+
}, FORCED_PREFIX = "forced-colors-";
|
|
8
|
+
export { FORCED_KEYS } from "./system-colors.mjs";
|
|
9
|
+
export const FORCED_ONLY = "forced-only", declaresForced = (fields) => [...fields instanceof Map ? fields.keys() : Object.keys(fields)].some((field) => field.startsWith(FORCED_PREFIX));
|
|
10
|
+
const fieldsOf = (foundation, name, kind, select = {}) => {
|
|
11
|
+
if (name === null || name === void 0)
|
|
12
|
+
return null;
|
|
13
|
+
const selected = selectedProfile(foundation, name, select);
|
|
14
|
+
return selected.kind === "ok" && selected.value.kind === kind ? selected.value.fields : null;
|
|
15
|
+
};
|
|
16
|
+
function slotsOf(foundation, profile, select) {
|
|
17
|
+
if (profile === null)
|
|
18
|
+
return new Map;
|
|
19
|
+
const selected = selectedProfile(foundation, profile, select);
|
|
20
|
+
if (selected.kind === "err")
|
|
21
|
+
return new Map;
|
|
22
|
+
return selected.value.kind === "composite" ? selected.value.fields : new Map([[`${selected.value.kind}-profile`, profile]]);
|
|
23
|
+
}
|
|
24
|
+
const borderless = (frame) => frame?.get("border-width") === void 0 ? "every context" : null;
|
|
25
|
+
export function forcedBoundaryMissing(foundation, spec) {
|
|
26
|
+
switch (spec.kind) {
|
|
27
|
+
case "control": {
|
|
28
|
+
const name = slotsOf(foundation, spec.profile, spec.select).get("frame-profile") ?? null, context = borderless(fieldsOf(foundation, name, "frame"));
|
|
29
|
+
return context === null ? null : { kind: "forced-boundary-missing", element: "&", frame: name, context };
|
|
30
|
+
}
|
|
31
|
+
case "region": {
|
|
32
|
+
const name = slotsOf(foundation, spec.profile, spec.select).get("frame-profile") ?? null;
|
|
33
|
+
for (const part of spec.parts) {
|
|
34
|
+
if (part.frame === null)
|
|
35
|
+
continue;
|
|
36
|
+
const context = borderless(fieldsOf(foundation, name, "frame"));
|
|
37
|
+
if (context !== null)
|
|
38
|
+
return { kind: "forced-boundary-missing", element: part.name, frame: name, context };
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
case "artwork":
|
|
43
|
+
case "grid":
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const FILL_FIELDS = new Set(["background", "background-color", "background-image", "box-shadow", "group-shadow", "shape-shadow"]), MEANT = /aria-(selected|pressed|checked|current)|:checked\b/;
|
|
48
|
+
function fillOnly(base, state) {
|
|
49
|
+
const own = (fields) => new Map([...fields ?? new Map].filter(([field]) => !field.startsWith(FORCED_PREFIX) && field !== "state")), before = own(base), after = own(state), changed = new Set([...before.keys(), ...after.keys()].filter((field) => before.get(field) !== after.get(field)));
|
|
50
|
+
return changed.size > 0 && [...changed].every((field) => FILL_FIELDS.has(field));
|
|
51
|
+
}
|
|
52
|
+
export function forcedStateFillOnly(foundation, spec) {
|
|
53
|
+
const found = [], visit = (element, base, when) => {
|
|
54
|
+
const baseFields = fieldsOf(foundation, base, "surface");
|
|
55
|
+
for (const [condition, surface] of when) {
|
|
56
|
+
if (surface === null || !MEANT.test(condition))
|
|
57
|
+
continue;
|
|
58
|
+
const fields = fieldsOf(foundation, surface, "surface");
|
|
59
|
+
if (fields === null || declaresForced(fields))
|
|
60
|
+
continue;
|
|
61
|
+
if (fillOnly(baseFields, fields))
|
|
62
|
+
found.push({ kind: "forced-state-fill-only", element, condition, surface });
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
switch (spec.kind) {
|
|
66
|
+
case "control":
|
|
67
|
+
visit("&", spec.surface, spec.when);
|
|
68
|
+
break;
|
|
69
|
+
case "region": {
|
|
70
|
+
const slots = slotsOf(foundation, spec.profile, spec.select);
|
|
71
|
+
visit("&", spec.surface ?? slots.get("surface-profile") ?? null, spec.when);
|
|
72
|
+
for (const part of spec.parts)
|
|
73
|
+
visit(part.name, part.surface, part.when);
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
case "artwork":
|
|
77
|
+
case "grid":
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
return found;
|
|
81
|
+
}
|
package/dist/frame-regions.mjs
CHANGED
|
@@ -185,7 +185,7 @@ function frameRegionOf(foundation, place, spec, regions, moved, under) {
|
|
|
185
185
|
context: context.label
|
|
186
186
|
}), placed = (bounds) => bounds[cell] ?? [], lowest = moved.has(cell) && conditions.length > 0 ? Math.min(...conditions.map((item) => item.boundPx)) : -1 / 0;
|
|
187
187
|
for (const bound of placed(cells)) {
|
|
188
|
-
if (bound.kind === "hidden")
|
|
188
|
+
if (bound.kind === "hidden" || bound.kind === "content")
|
|
189
189
|
continue;
|
|
190
190
|
if (bound.kind === "unbounded") {
|
|
191
191
|
review(`its ${px(need.px)} ${need.field} sits in inherited tracks at ${bound.tier}, which the grid algebra does not bound here`, context.label);
|
|
@@ -204,7 +204,7 @@ function frameRegionOf(foundation, place, spec, regions, moved, under) {
|
|
|
204
204
|
for (const bound of placed(condition.cells)) {
|
|
205
205
|
if (bound.kind === "hidden" || bound.fromPx >= condition.boundPx)
|
|
206
206
|
continue;
|
|
207
|
-
if (bound.kind === "unbounded")
|
|
207
|
+
if (bound.kind === "unbounded" || bound.kind === "content")
|
|
208
208
|
continue;
|
|
209
209
|
if (need.px > space(bound) + 0.01)
|
|
210
210
|
return exceeds(bound, condition.condition);
|
package/dist/grid-facts.mjs
CHANGED
|
@@ -50,7 +50,7 @@ function gridOf(foundation, name, withExamples) {
|
|
|
50
50
|
fineUnitPx: px(definition.fineUnit),
|
|
51
51
|
scalePx: definition.scale.map(px),
|
|
52
52
|
maxWidthPx: px(definition.maxWidth),
|
|
53
|
-
gutters: Object.fromEntries(Object.entries(definition.gutters).map(([mode, edges]) => [mode, { startPx:
|
|
53
|
+
gutters: Object.fromEntries(Object.entries(definition.gutters).map(([mode, edges]) => [mode, { startPx: edges.start === void 0 ? 0 : px(edges.start), endPx: edges.end === void 0 ? 0 : px(edges.end) }]))
|
|
54
54
|
}, expand = (mode, values, cells, fail) => {
|
|
55
55
|
const layout = postcss.atRule({ name: "ads-layout", params: mode, nodes: [] });
|
|
56
56
|
for (const [prop, value] of values)
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
const MARK = /export \{ ([\w$]+)(?: as ([\w$]+))? \} from "([^"]+)";\n\/\* ads-external (\{[^*]*\}) \*\//g, PROBE = "ads-external-probe";
|
|
6
|
+
function declared(folder) {
|
|
7
|
+
const found = [], visit = (directory, depth) => {
|
|
8
|
+
if (depth > 6)
|
|
9
|
+
return;
|
|
10
|
+
for (const entry of readdirSync(directory)) {
|
|
11
|
+
if (entry === "node_modules" || entry.startsWith("."))
|
|
12
|
+
continue;
|
|
13
|
+
const file = path.join(directory, entry);
|
|
14
|
+
if (statSync(file).isDirectory())
|
|
15
|
+
visit(file, depth + 1);
|
|
16
|
+
else if (/\.ads\.[cm]?[jt]s$/.test(entry))
|
|
17
|
+
for (const match of readFileSync(file, "utf8").matchAll(MARK)) {
|
|
18
|
+
const mark = JSON.parse(match[4] ?? "{}");
|
|
19
|
+
if (mark.name !== void 0 && mark.renders !== void 0)
|
|
20
|
+
found.push({ name: mark.name, exportName: match[1] ?? "default", from: match[3] ?? "", renders: mark.renders });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
visit(folder, 0);
|
|
25
|
+
return found;
|
|
26
|
+
}
|
|
27
|
+
export async function verifyExternals(root, entry) {
|
|
28
|
+
const externals = declared(path.dirname(entry));
|
|
29
|
+
if (externals.length === 0)
|
|
30
|
+
return [];
|
|
31
|
+
const require = createRequire(path.join(root, "package.json"));
|
|
32
|
+
let react, server;
|
|
33
|
+
try {
|
|
34
|
+
react = require("react");
|
|
35
|
+
server = require("react-dom/server");
|
|
36
|
+
} catch {
|
|
37
|
+
return externals.map((external) => ({ ...external, problem: "the application has no react and react-dom/server to render it with: verify it by hand" }));
|
|
38
|
+
}
|
|
39
|
+
const checks = [];
|
|
40
|
+
for (const external of externals) {
|
|
41
|
+
let problem = null;
|
|
42
|
+
try {
|
|
43
|
+
const module = await import(pathToFileURL(require.resolve(external.from)).href), exported = external.exportName === "default" ? module.default?.default ?? module.default : module[external.exportName];
|
|
44
|
+
if (exported === void 0)
|
|
45
|
+
problem = `${external.from} exports no ${external.exportName}`;
|
|
46
|
+
else {
|
|
47
|
+
const markup = server.renderToStaticMarkup(react.createElement(exported, { className: PROBE, href: "/", children: "probe" })).replace(/^(?:<link[^>]*\brel="(?:preload|modulepreload|preconnect|dns-prefetch)"[^>]*\/?>)+/, ""), root = /^<([a-z][\w-]*)([^>]*)>/.exec(markup), closes = root === null ? !1 : markup.endsWith(`</${root[1]}>`) || markup.endsWith("/>");
|
|
48
|
+
if (root === null || !closes)
|
|
49
|
+
problem = `it renders ${markup.slice(0, 80)}, not one element`;
|
|
50
|
+
else if (root[1] !== external.renders)
|
|
51
|
+
problem = `it renders <${root[1]}>, not the declared <${external.renders}>`;
|
|
52
|
+
else if (!new RegExp(`class="[^"]*\\b${PROBE}\\b`).test(root[2] ?? ""))
|
|
53
|
+
problem = "it does not put the class it is given on its element";
|
|
54
|
+
else if (/\sstyle="/.test(root[2] ?? ""))
|
|
55
|
+
problem = "it brings a style of its own: it carries design (use its data function instead)";
|
|
56
|
+
}
|
|
57
|
+
} catch (error) {
|
|
58
|
+
problem = `it could not be rendered: ${error instanceof Error ? error.message.split(`
|
|
59
|
+
`)[0] : String(error)}`;
|
|
60
|
+
}
|
|
61
|
+
checks.push({ name: external.name, from: external.from, renders: external.renders, problem });
|
|
62
|
+
}
|
|
63
|
+
return checks;
|
|
64
|
+
}
|
package/dist/guard/run.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { checkDesignUsage, designSystemEntry } from "../design-usage.mjs";
|
|
|
5
5
|
import { err, ok } from "../result.mjs";
|
|
6
6
|
import { readGuardConfig } from "./config.mjs";
|
|
7
7
|
import { guardScope } from "./files.mjs";
|
|
8
|
+
import { verifyExternals } from "./externals.mjs";
|
|
8
9
|
const ENTRY_NAMES = ["index.ts", "index.tsx", "index.mts", "index.js", "index.mjs"];
|
|
9
10
|
function entryFile(root, config) {
|
|
10
11
|
if (config.entry !== void 0) {
|
|
@@ -29,15 +30,16 @@ export async function runGuard(root) {
|
|
|
29
30
|
const located = entryFile(absolute, config.value);
|
|
30
31
|
if (located.kind === "err")
|
|
31
32
|
return err([located.error]);
|
|
32
|
-
const entry = await designSystemEntry(config.value.designSystem, located.value), folder = path.dirname(located.value), scope = guardScope(absolute, config.value.include, config.value.exclude, folder.startsWith(absolute + path.sep) ? folder : null), sources = scope.files.map((file) => ({ file, text: readFileSync(path.join(absolute, file), "utf8") })), findings = await checkDesignUsage(sources, entry, { components: config.value.allow, metadata: !0 }), inside = located.value.startsWith(absolute + path.sep);
|
|
33
|
+
const entry = await designSystemEntry(config.value.designSystem, located.value), folder = path.dirname(located.value), scope = guardScope(absolute, config.value.include, config.value.exclude, folder.startsWith(absolute + path.sep) ? folder : null), sources = scope.files.map((file) => ({ file, text: readFileSync(path.join(absolute, file), "utf8") })), findings = await checkDesignUsage(sources, entry, { components: config.value.allow, metadata: !0 }), inside = located.value.startsWith(absolute + path.sep), externals = await verifyExternals(absolute, located.value);
|
|
33
34
|
return ok({
|
|
34
|
-
ok: findings.length === 0,
|
|
35
|
+
ok: findings.length === 0 && externals.every((item) => item.problem === null),
|
|
35
36
|
designSystem: config.value.designSystem,
|
|
36
37
|
entry: inside ? path.relative(absolute, located.value).split(path.sep).join("/") : located.value,
|
|
37
38
|
patterns: entry.patterns.size,
|
|
38
39
|
checked: scope.files.length,
|
|
39
40
|
scope: { excluded: scope.excluded, tests: scope.tests, designSystem: scope.designSystem },
|
|
40
|
-
findings
|
|
41
|
+
findings,
|
|
42
|
+
externals
|
|
41
43
|
});
|
|
42
44
|
}
|
|
43
45
|
export function guardText(report) {
|
|
@@ -50,7 +52,9 @@ export function guardText(report) {
|
|
|
50
52
|
left.push(`${report.scope.tests} test file${report.scope.tests === 1 ? "" : "s"}`);
|
|
51
53
|
if (report.scope.designSystem > 0)
|
|
52
54
|
left.push(`${report.scope.designSystem} file${report.scope.designSystem === 1 ? "" : "s"} of the design system`);
|
|
53
|
-
const summary = `Checked ${report.checked} file${report.checked === 1 ? "" : "s"} against ${report.designSystem} (${report.patterns} pattern${report.patterns === 1 ? "" : "s"})${left.length ? `; not checked: ${left.join("; ")}` : ""}.`,
|
|
54
|
-
|
|
55
|
+
const summary = `Checked ${report.checked} file${report.checked === 1 ? "" : "s"} against ${report.designSystem} (${report.patterns} pattern${report.patterns === 1 ? "" : "s"})${left.length ? `; not checked: ${left.join("; ")}` : ""}.`, externals = report.externals.map((item) => item.problem === null ? `external ${item.name} (${item.from}) renders <${item.renders}> as declared` : `external ${item.name} (${item.from}) external-mismatch
|
|
56
|
+
${item.problem}
|
|
57
|
+
Declare what it renders, or use a component that renders one element with the given class and no style of its own.`), failing = report.findings.length + report.externals.filter((item) => item.problem !== null).length, verdict = report.ok ? "The source uses the design system only." : `${failing} finding${failing === 1 ? "" : "s"}.`;
|
|
58
|
+
return [...lines, ...externals, summary, verdict].join(`
|
|
55
59
|
`);
|
|
56
60
|
}
|
package/dist/inventories.mjs
CHANGED
|
@@ -58,7 +58,7 @@ export function revisionTokenInventory(options) {
|
|
|
58
58
|
}
|
|
59
59
|
const used = new Set;
|
|
60
60
|
for (const construction of outcome.owner.styles.values())
|
|
61
|
-
for (const token of construction.used)
|
|
61
|
+
for (const token of [...construction.used, ...construction.scriptTokens ?? []])
|
|
62
62
|
used.add(token);
|
|
63
63
|
tokens.push({ owner: path.posix.join(designSystem, name), tokens: used });
|
|
64
64
|
}
|