@reqvire-org/ads 0.5.5 → 0.5.7

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.
@@ -649,6 +649,13 @@ export const choiceErrors = {
649
649
  message: (failure) => `Part "${failure.part}" ends its content ${Math.abs(failure.distancePx)}px ${failure.distancePx > 0 ? "past" : "short of"} the line part "${failure.other}" ends on, under ${failure.context}: it is probably not on the same grid or gutter.`,
650
650
  repair: "Put the block on the same tracks and gutter as its siblings, or give its frame the inline end padding that ends its content on their line."
651
651
  },
652
+ "focus-unshown": {
653
+ group: "accessibility-semantics",
654
+ rule: 'Focus stays visible (WCAG 2.2 2.4.7). A field that shows no outline of its own (`focus: { shownBy: "container" }`) is shown by a container in the same component whose root names it: `focus: { within: ".field" }` draws the focus profile\'s outline around the whole field while it has keyboard focus.',
655
+ guides: [RECIPES, "ads://guides/accessibility"],
656
+ message: (failure) => `${failure.selector} shows no focus outline of its own, and no root in this component shows its focus (\`focus: { within: "${failure.selector}" }\`): its keyboard focus is invisible.`,
657
+ repair: 'Give the box around the field `focus: { within: "<the field\'s class>" }`, or remove `shownBy` so the field draws its own outline.'
658
+ },
652
659
  "document-duplicate": {
653
660
  group: "conflict",
654
661
  rule: 'A design system has at most one document pattern (`element: "document"`): it is the page\'s `<html>`.',
@@ -3486,6 +3493,20 @@ export const runtimeErrors = {
3486
3493
  message: (review) => `Summary ${review.part === "&" ? "root" : `part "${review.part}"`} removes its marker and renders no artwork.`,
3487
3494
  repair: "Render a chevron (a visual part or a public Icon) chosen by the controlled open state, or keep the native marker."
3488
3495
  },
3496
+ "text-layout-inline": {
3497
+ group: "conflict",
3498
+ rule: 'Text alignment and block wrapping (`textAlign`, `wrap: "truncate" | "balance" | "pretty"`) apply to a block of text: on a part rendered as an inline element (a <span>, <a>, <code>) that has no arrangement or box of its own, they change nothing.',
3499
+ guides: [RECIPES],
3500
+ message: (review) => `Part "${review.part}" sets ${review.setting} on an inline <${review.element}>, where it has no effect.`,
3501
+ repair: "Render the part as a block element (a <p> or <div>), give it an arrangement or a box, or set the alignment on the block that holds it."
3502
+ },
3503
+ "text-profile-unreached": {
3504
+ group: "conflict",
3505
+ rule: "A composite's text profile styles its text parts (and a root that binds its own `text`): on a root with neither, it reaches no element.",
3506
+ guides: [RECIPES],
3507
+ message: (review) => `The profile's text profile "${review.profile}" reaches no element: the root binds no \`text\` and has no text parts.`,
3508
+ repair: 'Declare the text as a `kind: "text"` part, bind `text` on the root, or remove the text profile from the composite.'
3509
+ },
3489
3510
  "border-paint-missing": {
3490
3511
  group: "conflict",
3491
3512
  rule: "A frame that draws a border (`borderWidth`) has a paint for it: a surface of the element, at rest or under a state, sets `borderColor` (or a side's colour). Without one CSS paints the border in the text colour, almost always a forgotten paint. Listed for review: the text colour may be meant.",
@@ -2,7 +2,7 @@ import path from "node:path";
2
2
  import { SyntaxKind, isExportAssignment, isExportDeclaration, isImportDeclaration } from "typescript/ast";
3
3
  import { digest } from "../digest.mjs";
4
4
  import { memoProgram } from "./context.mjs";
5
- export const OWNER_ANALYSIS_SCHEMA = "ads-owner-analysis/14";
5
+ export const OWNER_ANALYSIS_SCHEMA = "ads-owner-analysis/15";
6
6
  export function canonical(value) {
7
7
  return JSON.stringify(value, (_key, item) => {
8
8
  if (item instanceof Map)
@@ -207,7 +207,7 @@ function insideMap(node, ancestor) {
207
207
  return !0;
208
208
  return !1;
209
209
  }
210
- const isLoop = (node) => isForStatement(node) || isForOfStatement(node) || isForInStatement(node) || isWhileStatement(node) || isDoStatement(node), NO_CLASSES = { fragments: [], calls: [], markers: [], placement: [], bindings: [] };
210
+ const isLoop = (node) => isForStatement(node) || isForOfStatement(node) || isForInStatement(node) || isWhileStatement(node) || isDoStatement(node), INLINE_TEXT_TAGS = ["span", "a", "code", "strong", "em", "b", "i", "small", "abbr", "cite", "q", "kbd", "mark", "time", "sub", "sup", "s", "u", "label"], NO_CLASSES = { fragments: [], calls: [], markers: [], placement: [], bindings: [] };
211
211
  function validateReferences(foundation, spec) {
212
212
  if (typeof spec !== "object" || spec === null)
213
213
  return null;
@@ -942,6 +942,11 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
942
942
  await pointerTransparent(opening, "&", context, resolve);
943
943
  if (region.overflow.kind === "scroll")
944
944
  scrollReview(opening, "&", node);
945
+ if (region.profile !== null && region.text === null) {
946
+ const selected = selectedProfile(foundation, region.profile, region.select), textProfile = selected.kind === "ok" && selected.value.kind === "composite" ? selected.value.fields.get("text-profile") : void 0, hasText = (list) => list.some((part) => part.content.kind === "text" || part.frame !== null || part.text !== null || hasText(part.parts));
947
+ if (textProfile !== void 0 && !hasText(region.parts))
948
+ review(opening, { kind: "text-profile-unreached", profile: textProfile });
949
+ }
945
950
  }
946
951
  const matched = new Map([["", opening]]), tinted = new Set(parsed.value.kind === "region" ? surfacedElements(foundation, parsed.value).flatMap((element) => element.visual && (element.surface !== null || element.when.length > 0) ? [element.element] : []) : []), decorative = new Set, margined = new Set;
947
952
  let schemed = !1;
@@ -987,8 +992,11 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
987
992
  const element = values.tag(match.opening);
988
993
  if (UA_MARGIN_TAGS.includes(element))
989
994
  margined.add([...part.within, part.selector].join(" "));
990
- if (UA_CONTROL_TAGS.includes(element))
995
+ if (UA_CONTROL_TAGS.includes(element) && match.classes.fragments.length === 0)
991
996
  native.add([...part.within, part.selector].join(" "));
997
+ const domParent = elementOf(match.opening).parent, parentClass = parent === opening ? void 0 : expression(attr(parent, "className")), parentRecipes = parentClass === void 0 ? 0 : split(await resolve(parentClass, context), parentClass).fragments.length;
998
+ if (domParent !== void 0 && openingOf(domParent) === parent && parentRecipes === 0 && INLINE_TEXT_TAGS.includes(element) && part.blockText !== null)
999
+ review(match.opening, { kind: "text-layout-inline", part: part.name, element, setting: part.blockText });
992
1000
  const hostless = part.pseudo.find((pseudo) => !pseudoHosted(pseudo, element));
993
1001
  if (hostless !== void 0)
994
1002
  return fail(match.opening, { kind: "pseudo-host-unsupported", part: part.name, pseudo: hostless, element });
@@ -707,6 +707,11 @@ export interface RegionPart {
707
707
  * of a checkbox whose `<input>` is hidden) and shows the focus indicator while that control has keyboard focus.
708
708
  */
709
709
  readonly focusOf: string | null;
710
+ /**
711
+ * `focus: { shownBy: "container" }`: this part (a text field inside a composer's box) shows no focus outline of its
712
+ * own; the container that names it with `focus: { within }` draws the indicator around the whole field.
713
+ */
714
+ readonly focusShownBy: boolean;
710
715
  /**
711
716
  * `drawnBy: "<sibling part>"`: this part is a native control (a checkbox's `<input>`) that the named part draws.
712
717
  * It is invisible and takes no room, laid over that part at its frame's size, so pointer and keyboard still
@@ -891,6 +896,11 @@ export interface RegionSpec {
891
896
  /** The root's entrance; never on a top-layer root, whose layer motion is its entrance. */
892
897
  readonly enter: EnterSpec | null;
893
898
  /** The root stays at an edge of its scrolling container; never on a top-layer root, which the top layer places. */
899
+ /**
900
+ * `focus: { within: ".field" }`: the nearest focus profile's indicator on this root while the named field inside it
901
+ * has keyboard focus (`&:has(.field:focus-visible)`): a composer's box around its text field.
902
+ */
903
+ readonly focusWithin: string | null;
894
904
  readonly sticky: StickySpec | null;
895
905
  readonly parts: readonly RegionPart[];
896
906
  /** Parts exposed as public rows, in row order, for a parent's `alignRows`. */
@@ -974,6 +984,11 @@ export interface DeclaredPart {
974
984
  readonly playsAlways: readonly string[];
975
985
  /** A scroll container: it should be reachable by keyboard. */
976
986
  readonly scrolls: boolean;
987
+ /**
988
+ * A text part's setting that needs a block of text (`textAlign: "end"`, `wrap: "truncate"`), where the part has no
989
+ * arrangement, box or frame of its own: on an inline element it changes nothing. `null` otherwise.
990
+ */
991
+ readonly blockText: string | null;
977
992
  /** An `accessibility` declaration: its element must be a text-entry control (`<input>` of a text type, `<textarea>`, `<select>`). */
978
993
  readonly declaresBoundary: boolean;
979
994
  /** Whether the part declares `normalize.resize`: its element is a `<textarea>`. */
@@ -73,12 +73,23 @@ export function declaredParts(spec) {
73
73
  case "artwork":
74
74
  return [{ ...plainPart, name: spec.part.name, path: `recipe.parts.${spec.part.name}`, selector: spec.part.selector, required: spec.part.required, kind: "visual" }];
75
75
  case "region":
76
- return regionParts(spec.parts, [], "recipe");
76
+ return regionParts(spec.parts, [], "recipe", spec.arrangement.layout);
77
77
  case "grid":
78
78
  return [];
79
79
  }
80
80
  }
81
- const plainPart = { repeat: !1, within: [], pseudo: [], element: null, media: "bound", truncated: !1, clamped: !1, balanced: !1, scrolls: !1, declaresBoundary: !1, resizes: !1, playsAlways: [], scheme: null }, regionParts = (parts, within, parent) => parts.flatMap((part) => [
81
+ const plainPart = { repeat: !1, within: [], pseudo: [], element: null, media: "bound", truncated: !1, clamped: !1, balanced: !1, scrolls: !1, blockText: null, declaresBoundary: !1, resizes: !1, playsAlways: [], scheme: null };
82
+ function blockText(part, parentLayout) {
83
+ if (parentLayout !== null && parentLayout !== "native")
84
+ return null;
85
+ if (part.content.kind !== "text" || part.arrangement !== null || part.box !== null || part.frame !== null)
86
+ return null;
87
+ if (part.textLayout.align !== null)
88
+ return `textAlign: "${part.textLayout.align}"`;
89
+ const wrap = part.textLayout.wrap;
90
+ return wrap === "truncate" || wrap === "balance" || wrap === "pretty" ? `wrap: "${wrap}"` : null;
91
+ }
92
+ const regionParts = (parts, within, parent, parentLayout) => parts.flatMap((part) => [
82
93
  {
83
94
  name: part.name,
84
95
  path: `${parent}.parts.${part.name}`,
@@ -94,12 +105,13 @@ const plainPart = { repeat: !1, within: [], pseudo: [], element: null, media: "b
94
105
  clamped: part.textLayout.lines !== null,
95
106
  balanced: part.textLayout.wrap === "balance",
96
107
  scrolls: part.overflow.kind === "scroll",
108
+ blockText: blockText(part, parentLayout),
97
109
  declaresBoundary: part.accessibility !== null,
98
110
  resizes: part.normalize.some(([property]) => property === "resize"),
99
111
  scheme: part.scheme,
100
112
  playsAlways: part.plays.flatMap((play) => play.condition === null ? [play.sequence] : [])
101
113
  },
102
- ...regionParts(part.parts, [...within, part.selector], `${parent}.parts.${part.name}`)
114
+ ...regionParts(part.parts, [...within, part.selector], `${parent}.parts.${part.name}`, part.arrangement?.layout ?? null)
103
115
  ]);
104
116
  export function declaredMeasured(spec) {
105
117
  switch (spec.kind) {
@@ -485,8 +497,6 @@ function rootWhen(spec, read, geometry = !1) {
485
497
  if (fields.surface !== void 0)
486
498
  when.push([state, read.string(fields.surface, `${at}.surface`)]);
487
499
  if (fields.scale !== void 0) {
488
- if (pressed.length > 0)
489
- read.invalid(`${at}.scale`, "one press `scale` endpoint per root");
490
500
  const field = read.literal(read.slot(fields.scale, `${at}.scale`, "motion").field, `${at}.scale.field`, ["scale"]);
491
501
  pressed.push({ condition: state, field, path: `${at}.scale` });
492
502
  }
@@ -1145,6 +1155,7 @@ function regionPart(name, value, read, path, nested) {
1145
1155
  sticky: stickySpec(part.sticky, `${path}.sticky`, read),
1146
1156
  outset: outsetSpec(part.outset, `${path}.outset`, read),
1147
1157
  focusOf: focusSource(part.focus, `${path}.focus`, read),
1158
+ focusShownBy: focusShownBy(part.focus, `${path}.focus`, read),
1148
1159
  drawnBy: part.drawnBy === void 0 ? null : read.string(part.drawnBy, `${path}.drawnBy`),
1149
1160
  anchorClear: anchorClear(part.anchorClear, `${path}.anchorClear`, read),
1150
1161
  scheme: partScheme(part, content, path, read),
@@ -1170,9 +1181,28 @@ function focusSource(value, path, read) {
1170
1181
  if (value === void 0)
1171
1182
  return null;
1172
1183
  const declared = read.object(value, path);
1173
- read.only(declared, path, ["of"]);
1184
+ read.only(declared, path, ["of", "shownBy"]);
1185
+ if (declared.shownBy !== void 0)
1186
+ return declared.of === void 0 ? null : read.invalid(path, "`of` or `shownBy`, not both");
1174
1187
  return read.string(declared.of, `${path}.of`);
1175
1188
  }
1189
+ function focusShownBy(value, path, read) {
1190
+ if (value === void 0)
1191
+ return !1;
1192
+ const declared = read.object(value, path);
1193
+ if (declared.shownBy === void 0)
1194
+ return !1;
1195
+ read.literal(declared.shownBy, `${path}.shownBy`, ["container"]);
1196
+ return !0;
1197
+ }
1198
+ function focusWithin(value, read) {
1199
+ if (value === void 0)
1200
+ return null;
1201
+ const declared = read.object(value, "recipe.focus");
1202
+ read.only(declared, "recipe.focus", ["within"]);
1203
+ const selector = read.string(declared.within, "recipe.focus.within");
1204
+ return /^\.[A-Za-z_][\w-]*$/.test(selector) ? selector : read.invalid("recipe.focus.within", 'one class selector (".ds-composer-field")');
1205
+ }
1176
1206
  function parseParts(value, read, path, nested) {
1177
1207
  if (value === void 0)
1178
1208
  return [];
@@ -1277,7 +1307,8 @@ function region(authored, read) {
1277
1307
  "extent",
1278
1308
  "anchorClear",
1279
1309
  "overlap",
1280
- "geometryTransition"
1310
+ "geometryTransition",
1311
+ "focus"
1281
1312
  ]);
1282
1313
  const layout = spec.layout === void 0 ? "native" : read.literal(spec.layout, "recipe.layout", ROOT_LAYOUTS), normalized = normalization(spec.normalize, "recipe.normalize", REGION_NORMALIZE, REGION_NORMALIZE, "selector", read), parts = parseParts(spec.parts, read, "recipe", !1), measured = measuredValues(spec.measured, "recipe.measured", read);
1283
1314
  uniqueMeasured(measured, parts, read);
@@ -1320,6 +1351,7 @@ function region(authored, read) {
1320
1351
  frameAt: frameCondition(spec.at, regionFrame(spec.frame, read), read),
1321
1352
  plays: layer !== null && rootStates.plays.length > 0 ? read.reject({ kind: "field-unsupported", construction: "region", path: "recipe.play" }) : rootStates.plays,
1322
1353
  sticky: layer !== null && spec.sticky !== void 0 ? read.reject({ kind: "field-unsupported", construction: "region", path: "recipe.sticky" }) : stickySpec(spec.sticky, "recipe.sticky", read),
1354
+ focusWithin: focusWithin(spec.focus, read),
1323
1355
  parts,
1324
1356
  exposeRows,
1325
1357
  layer,
@@ -1,6 +1,19 @@
1
1
  import { selectedProfile } from "./design-foundation.mjs";
2
- import { frameInlineInsets } from "./lowering-region-layout.mjs";
2
+ import { frameInlineInsets, sideWidth } from "./lowering-region-layout.mjs";
3
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
+ function endsRagged(arrangement, parts) {
11
+ if (arrangement === null || arrangement.layout !== "inline")
12
+ return !1;
13
+ if (arrangement.justify !== null && /end|space-/.test(arrangement.justify))
14
+ return !1;
15
+ return !parts.some((part) => part.extent.kind === "fill");
16
+ }
4
17
  export function endInsetOf(foundation, spec) {
5
18
  switch (spec.kind) {
6
19
  case "region": {
@@ -16,8 +29,10 @@ export function endInsetOf(foundation, spec) {
16
29
  if (frame.kind === "err" || frame.value.kind !== "frame")
17
30
  return null;
18
31
  const surfaceName = spec.surface ?? (selected.value.kind === "composite" ? selected.value.fields.get("surface-profile") : void 0), surface = surfaceName === void 0 ? null : selectedProfile(foundation, surfaceName);
19
- if (surface !== null && surface.kind === "ok" && surface.value.kind === "surface" && surface.value.fields.has("background") || frame.value.fields.has("border-width"))
32
+ if (surface !== null && surface.kind === "ok" && surface.value.kind === "surface" && surface.value.fields.has("background") || borderedAtEnd(frame.value.fields, spec.frame?.border ?? null))
20
33
  return [];
34
+ if (endsRagged(spec.arrangement, spec.parts))
35
+ return null;
21
36
  const end = frameInlineInsets(Object.fromEntries(frame.value.fields)).end;
22
37
  return end === void 0 ? [] : [end];
23
38
  }
@@ -61,8 +76,10 @@ export function stackPartsOf(foundation, spec) {
61
76
  if (frame.kind === "err" || frame.value.kind !== "frame")
62
77
  return [];
63
78
  const surface = part.surface === null ? null : selectedProfile(foundation, part.surface);
64
- if (surface !== null && surface.kind === "ok" && surface.value.kind === "surface" && surface.value.fields.has("background") || frame.value.fields.has("border-width"))
79
+ if (surface !== null && surface.kind === "ok" && surface.value.kind === "surface" && surface.value.fields.has("background") || borderedAtEnd(frame.value.fields, null))
65
80
  return [{ part: part.name, kind: "box", inset: [] }];
81
+ if (endsRagged(part.arrangement, part.parts))
82
+ return [];
66
83
  const end = frameInlineInsets(Object.fromEntries(frame.value.fields)).end;
67
84
  return [{ part: part.name, kind: "box", inset: end === void 0 ? [] : [end] }];
68
85
  });
@@ -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: px(edges.start ?? "0"), endPx: px(edges.end ?? "0") }]))
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)
@@ -1,8 +1,9 @@
1
1
  import { err, ok } from "./result.mjs";
2
2
  import { KEYFRAME_PROPERTIES } from "./lowering-properties.mjs";
3
+ const OWNED_DOCUMENT = /^:root:has\(&:[a-z-]+\)$/;
3
4
  export function declareRule(registry, request) {
4
5
  const { selector, conditions, values, important, origin } = request;
5
- if (!selector.startsWith("&"))
6
+ if (!selector.startsWith("&") && !OWNED_DOCUMENT.test(selector))
6
7
  return err({ kind: "selector-not-owned", selector, origin });
7
8
  const declarations = [];
8
9
  for (const [property, value] of values) {
@@ -30,7 +30,7 @@ function sheetRules(sheet, backdrop, own, motion, margin) {
30
30
  return err({ kind: "backdrop-surface-unsupported", surface: backdrop.name, field: field ?? null });
31
31
  const blur = backdrop.fields["backdrop-blur"], veil = { background, ...blur === void 0 ? {} : { "-webkit-backdrop-filter": `blur(${blur})`, "backdrop-filter": `blur(${blur})` } };
32
32
  if (sheet.edge === "center" || sheet.edge === "block-start")
33
- return ok(cardRules(sheet, veil, own, motion, margin ?? "0px"));
33
+ return ok(cardRules(sheet, veil, own, motion, margin ?? { inline: "0px", block: "0px" }));
34
34
  const placement = {
35
35
  position: "fixed",
36
36
  "inset-block-start": "0",
@@ -67,20 +67,21 @@ function cardRules(sheet, veil, own, motion, margin) {
67
67
  "inset-block-end": "0",
68
68
  "inset-inline-start": "0",
69
69
  "inset-inline-end": "0",
70
- "margin-block-start": sheet.edge === "block-start" ? margin : "auto",
70
+ "margin-block-start": sheet.edge === "block-start" ? margin.block : "auto",
71
71
  "margin-block-end": "auto",
72
72
  "margin-inline-start": "auto",
73
73
  "margin-inline-end": "auto",
74
74
  "block-size": "fit-content",
75
- "max-block-size": `calc(100dvh - ${margin} * 2)`,
76
- "max-inline-size": inlineCap(margin, own)
77
- }, paint = { selector: "&::backdrop", values: veil, condition: null };
75
+ "max-block-size": `calc(100dvh - ${margin.block} * 2)`,
76
+ "max-inline-size": inlineCap(margin.inline, own)
77
+ }, paint = { selector: "&::backdrop", values: veil, condition: null }, gutter = { selector: ":root:has(&:modal)", values: { "scrollbar-gutter": "stable" }, condition: null };
78
78
  if (motion === null || sheet.motion === null)
79
- return { root: placement, rules: [paint] };
79
+ return { root: placement, rules: [paint, gutter] };
80
80
  return {
81
81
  root: { ...placement, ...transition("opacity", motion) },
82
82
  rules: [
83
83
  paint,
84
+ gutter,
84
85
  { selector: "&:not([open])", values: { opacity: "0" }, condition: null },
85
86
  { selector: "&[open]", values: { opacity: "0" }, condition: STARTING },
86
87
  { selector: "&::backdrop", values: transition("opacity", motion), condition: null },
@@ -128,6 +128,7 @@ export const FAMILIES = [
128
128
  "overflow-wrap",
129
129
  "overlay",
130
130
  "position",
131
+ "scrollbar-gutter",
131
132
  "rotate",
132
133
  "scale",
133
134
  "text-box-edge",
@@ -148,7 +148,7 @@ export function textLayoutValues(layout, part, hasText) {
148
148
  export function growsWithContent(values) {
149
149
  return values["min-block-size"] !== void 0 && values["min-block-size"] !== "0" && values["block-size"] === void 0 && values["max-block-size"] === void 0 && values["aspect-ratio"] === void 0 && values.overflow === void 0;
150
150
  }
151
- export function extentValues(extent, parent, part, parentGrows = !1) {
151
+ export function extentValues(extent, parent, part, parentGrows = !1, parentWraps = !1) {
152
152
  switch (extent.kind) {
153
153
  case "content":
154
154
  return ok({});
@@ -156,7 +156,9 @@ export function extentValues(extent, parent, part, parentGrows = !1) {
156
156
  if (parent !== "stack" && parent !== "inline")
157
157
  return err({ kind: "extent-parent-unsupported", part, layout: parent });
158
158
  const main = parent === "stack" ? "block" : "inline", values = { "flex-grow": "1", "flex-shrink": "1", "flex-basis": parent === "stack" ? "auto" : "0" };
159
- if (!(parent === "stack" && parentGrows))
159
+ if (parent === "inline" && parentWraps)
160
+ values["min-inline-size"] = "min-content";
161
+ else if (!(parent === "stack" && parentGrows))
160
162
  values[`min-${main}-size`] = "0";
161
163
  if (extent.axis === "both")
162
164
  values["align-self"] = "stretch";
@@ -174,7 +176,8 @@ export function nativeReset(values) {
174
176
  unless("text-align", "start");
175
177
  unless("color", "inherit");
176
178
  unless("background", "transparent");
177
- unless("border-style", "none", ["border"]);
179
+ if (!Object.keys(values).some((key) => key === "border" || /^border(-(top|right|bottom|left|block|inline)(-(start|end))?)?-(style|width)$/.test(key)))
180
+ reset["border-style"] = "none";
178
181
  unless("margin", "0");
179
182
  return reset;
180
183
  }
@@ -466,6 +466,7 @@ export function checkFindings(inputs, check, publics = null) {
466
466
  advisories.push(...counterFindings(inputs, analyzedOwners(check.outcomes)));
467
467
  diagnostics.push(...documentFindings(inputs, analyzedOwners(check.outcomes)));
468
468
  diagnostics.push(...endAlignmentFindings(inputs, analyzedOwners(check.outcomes), check.foundation));
469
+ diagnostics.push(...focusShownFindings(inputs, analyzedOwners(check.outcomes)));
469
470
  return { diagnostics: distinct(diagnostics), advisories };
470
471
  }
471
472
  function targetFindings(inputs, owners, foundation, spacing) {
@@ -495,6 +496,27 @@ function targetFindings(inputs, owners, foundation, spacing) {
495
496
  }
496
497
  return { diagnostics, advisories: [...advisories.values()] };
497
498
  }
499
+ function focusShownFindings(inputs, owners) {
500
+ const findings = [];
501
+ for (const facts of owners.values()) {
502
+ const shown = new Set;
503
+ for (const style of facts.styles.values())
504
+ for (const match of style.css.matchAll(/:has\((\.[\w-]+):focus-visible\)/g))
505
+ shown.add(match[1] ?? "");
506
+ for (const style of facts.styles.values()) {
507
+ const [first] = style.origins;
508
+ if (first?.kind !== "point")
509
+ continue;
510
+ for (const match of style.css.matchAll(/>\s*(\.[\w-]+):focus-visible\s*\{\s*outline-style:\s*none/g)) {
511
+ const selector = match[1] ?? "";
512
+ if (shown.has(selector))
513
+ continue;
514
+ findings.push(...findingsOf(inputs, { kind: "owner", failure: { kind: "source", origin: { ...first, file: path.join(inputs.dsRoot, first.file) }, problem: { kind: "focus-unshown", selector } } }));
515
+ }
516
+ }
517
+ }
518
+ return findings;
519
+ }
498
520
  function endAlignmentFindings(inputs, owners, foundation) {
499
521
  const insets = new Map;
500
522
  for (const facts of owners.values())
@@ -107,7 +107,7 @@ const identifier = /^[a-z][\w-]*$/, profile = /^[a-z][\w-]*(?:\([a-z][\w-]*:\s*[
107
107
  "ads-between": { surface: binding, frame: binding },
108
108
  "ads-content": { counter: () => !0, counters: () => !0, style: () => !0, separator: () => !0, prefix: () => !0, suffix: () => !0 },
109
109
  "ads-accessibility": { boundary: () => !0, reason: () => !0 },
110
- "ads-focus": { of: () => !0 },
110
+ "ads-focus": { of: () => !0, "shown-by": oneOf("container"), within: (value) => /^\.[A-Za-z_][\w-]*$/.test(value) },
111
111
  "ads-play": { sequence: binding, order: (value) => /^(?:[0-9]|[12][0-9]|3[0-2])$/.test(value) },
112
112
  "ads-outset": { block: outsetSpacing, inline: outsetSpacing },
113
113
  "ads-sticky": { edge: oneOf("block-start", "block-end"), clear: oneOf("none", "block-start") },
@@ -68,6 +68,7 @@ export const PLATFORM_FEATURES = [
68
68
  css: ["overlay", "transition-property: overlay"],
69
69
  degrades: "The top-layer exit animation is cut: where overlay cannot be transitioned, the element leaves the top layer at once and closes instantly."
70
70
  },
71
+ { id: "scrollbar-gutter", css: ["scrollbar-gutter"], degrades: "The page behind an open modal card shifts sideways by the scrollbar's width when the scroll lock hides it." },
71
72
  { id: "popover", css: [":popover-open"], degrades: "Required by popovers and menus: without the Popover API the overlay never enters the top layer, is not hidden while closed and is not light-dismissed." },
72
73
  { id: "prefers-color-scheme", css: ["@media (prefers-color-scheme)"], degrades: "The operating system's colour scheme is not followed: the default theme applies." },
73
74
  { id: "prefers-contrast", css: ["@media (prefers-contrast)"], degrades: "A requested contrast preference is not followed." },
@@ -388,8 +388,17 @@ export interface RecipeSpec {
388
388
  * This part is the drawn stand-in of a native control beside it (the box of a checkbox whose `<input>`
389
389
  * is visually hidden): it shows the focus profile's indicator while the named sibling part has keyboard focus.
390
390
  */
391
+ /**
392
+ * `{ of: "<sibling part>" }`: a drawn stand-in shows a hidden native control's focus. `{ shownBy: "container" }`: a
393
+ * text field whose focus the container around it shows. `{ within: ".field" }` (a root): while that field inside it
394
+ * has keyboard focus, the root draws the nearest focus profile's outline (a composer's box around its textarea).
395
+ */
391
396
  readonly focus?: {
392
397
  readonly of: string;
398
+ } | {
399
+ readonly shownBy: "container";
400
+ } | {
401
+ readonly within: string;
393
402
  };
394
403
  /**
395
404
  * A native control (a checkbox's `<input>`) that the named sibling part draws: invisible and taking no room, it
@@ -103,7 +103,7 @@ const NESTED = new Set(["layout", "parts", "cells", "at", "when", "frame", "sele
103
103
  "ads-pseudo": ["when", "content"]
104
104
  };
105
105
  function body(node, spec) {
106
- const allowed = node.name === "ads-recipe" ? ["layout", "parts", "cells", "at", "when", "frame", "select", "alignRows", "paintTransition", "geometryTransition", "snap", ...node.parent?.type === "root" ? ["normalize", "theme", "layer", "measured", "paints", "enter", "sticky", "play", "pseudo", "counter", "between"] : []] : NESTED_IN[node.name] ?? [], nestedKey = (key) => NESTED.has(key) && !(node.name === "ads-pseudo" && key === "frame");
106
+ const allowed = node.name === "ads-recipe" ? ["layout", "parts", "cells", "at", "when", "frame", "select", "alignRows", "paintTransition", "geometryTransition", "snap", ...node.parent?.type === "root" ? ["normalize", "theme", "layer", "measured", "paints", "enter", "sticky", "play", "pseudo", "counter", "between", "focus"] : []] : NESTED_IN[node.name] ?? [], nestedKey = (key) => NESTED.has(key) && !(node.name === "ads-pseudo" && key === "frame");
107
107
  for (const field of Object.keys(spec))
108
108
  if (nestedKey(field))
109
109
  check(allowed.includes(field), `Unsupported ${field} in ${node.name}`);
@@ -129,7 +129,7 @@ function body(node, spec) {
129
129
  if (spec.outset !== void 0)
130
130
  clause(node, "ads-outset", "", only(spec.outset, ["block", "inline"]));
131
131
  if (spec.focus !== void 0)
132
- clause(node, "ads-focus", "", only(spec.focus, ["of"]));
132
+ clause(node, "ads-focus", "", only(spec.focus, ["of", "shownBy", "within"]));
133
133
  if (spec.play !== void 0)
134
134
  clause(node, "ads-play", "", only(spec.play, ["sequence", "order"]));
135
135
  if (spec.counter !== void 0)
@@ -28,7 +28,7 @@ import {
28
28
  } from "./construction-output.mjs";
29
29
  import { settled } from "./lowering-enter.mjs";
30
30
  import { checkPlaceholderContrast, checkProgressContrast } from "./placeholder-contrast.mjs";
31
- import { fixedLength, lowerLayer, openState, ownsPlacement } from "./lowering-layer.mjs";
31
+ import { fixedLength, lowerLayer, ownsPlacement } from "./lowering-layer.mjs";
32
32
  import { RATIO_SUFFIX, focalPosition, intrinsicInlineSize, measuredFallback, measuredProperty, measuredWrites, positions } from "./measured-geometry.mjs";
33
33
  import { paintProperty, paintTokens, paintWrites } from "./runtime-paint.mjs";
34
34
  import { conditionBound, conditionQueries, geometryOf, tierBelowQuery } from "./spatial-reading.mjs";
@@ -482,7 +482,7 @@ function lowerVector(part, stroke, path, context) {
482
482
  out.rule(under(condition, path), { ...checked(vectorStateValues(part.name, surface, profile.of(surface, "surface")), reject) });
483
483
  writeConditioned(part, path, {}, context);
484
484
  }
485
- function lowerParts(parts, parent, layout, gap, context, parentGrows = !1, overlapping = null, stateGaps = []) {
485
+ function lowerParts(parts, parent, layout, gap, context, parentGrows = !1, overlapping = null, stateGaps = [], parentWraps = !1) {
486
486
  for (const part of parts) {
487
487
  const source = part.focusOf === null ? void 0 : parts.find((other) => other.name === part.focusOf);
488
488
  if (source === void 0)
@@ -495,6 +495,9 @@ function lowerParts(parts, parent, layout, gap, context, parentGrows = !1, overl
495
495
  "outline-style": "solid"
496
496
  });
497
497
  }
498
+ for (const part of parts)
499
+ if (part.focusShownBy)
500
+ context.out.rule(`${parent} > ${part.selector}:focus-visible`, { "outline-style": "none" });
498
501
  for (const part of parts) {
499
502
  const drawing = part.drawnBy === null ? void 0 : parts.find((other) => other.name === part.drawnBy);
500
503
  if (drawing === void 0)
@@ -505,7 +508,7 @@ function lowerParts(parts, parent, layout, gap, context, parentGrows = !1, overl
505
508
  context.out.rule(`${parent} > ${part.selector}`, { position: "absolute", "inline-size": inline, "block-size": block, "margin-block": "0", "margin-inline": "0", opacity: "0", "z-index": "1" });
506
509
  }
507
510
  writePartSpace(parts, parent, layout, gap, context, context.carry);
508
- const lowered = parts.map((part) => lowerPart(part, parent, layout, context, parentGrows, overlapping));
511
+ const lowered = parts.map((part) => lowerPart(part, parent, layout, context, parentGrows, overlapping, parentWraps));
509
512
  if (layout !== "inline" && layout !== "stack")
510
513
  return;
511
514
  const axes = layout === "inline" ? ["inline"] : ["block"], pairs = lowered.flatMap((first, index) => {
@@ -575,15 +578,15 @@ function writePartSpace(parts, parent, layout, gap, context, carry = !1) {
575
578
  out.rule(`&:not(:last-child):has(> ${part.selector}:last-child)`, { "margin-block-end": `max(0px, calc(${after} - var(${FLOW_GAP}, 0px)))` });
576
579
  }
577
580
  }
578
- const FLOW_GAP = "--ads-flow-gap";
579
- function lowerPart(part, parent, parentLayout, context, parentGrows, overlapping = null) {
581
+ const FLOW_GAP = "--ads-flow-gap", keepsWords = (part) => part.textLayout.wrap !== "truncate" && part.textLayout.wrap !== "anywhere" && part.frame === null && part.box === null;
582
+ function lowerPart(part, parent, parentLayout, context, parentGrows, overlapping = null, parentWraps = !1) {
580
583
  const { out, profile, slots, reject } = context, path = `${parent} > ${part.selector}`;
581
584
  if (part.content.kind === "vector") {
582
585
  lowerVector(part, part.content.stroke, path, context);
583
586
  return null;
584
587
  }
585
588
  if (part.content.kind === "component") {
586
- writeConditioned(part, path, checked(extentValues(part.extent, parentLayout, part.name, parentGrows), reject), context);
589
+ writeConditioned(part, path, checked(extentValues(part.extent, parentLayout, part.name, parentGrows, parentWraps && keepsWords(part)), reject), context);
587
590
  return null;
588
591
  }
589
592
  const partSurface = part.surface === null ? {} : profile.of(part.surface, "surface"), moving = partMotion(path, part.effects, context), collapsible = part.collapsed || part.geometryWhen.some((state) => state.collapsed !== null), axis = parentLayout === "inline" ? "inline" : parentLayout === "stack" ? "block" : null;
@@ -677,7 +680,7 @@ function lowerPart(part, parent, parentLayout, context, parentGrows, overlapping
677
680
  const partSnap = part.arrangement?.snap ?? null, snapped = partSnap === null ? null : checked(snapValues(partSnap, part.overflow, part.name), reject);
678
681
  if (snapped !== null)
679
682
  add(snapped.container, "snap");
680
- add(checked(extentValues(part.extent, parentLayout, part.name, parentGrows), reject), "extent");
683
+ add(checked(extentValues(part.extent, parentLayout, part.name, parentGrows, parentWraps && keepsWords(part) && values["min-inline-size"] === void 0), reject), "extent");
681
684
  if (parentLayout === "layered")
682
685
  add(LAYER, "layer");
683
686
  if (part.outset !== null) {
@@ -724,7 +727,7 @@ function lowerPart(part, parent, parentLayout, context, parentGrows, overlapping
724
727
  if (part.presence === "assistive")
725
728
  out.rule(path, { ...ASSISTIVE_ONLY });
726
729
  }
727
- lowerParts(part.parts, path, part.arrangement?.layout ?? "native", values.gap ?? values["column-gap"], part.required && context.withinOptional !== !0 ? context : { ...context, withinOptional: !0 }, growsWithContent(values), partGeometry.overlap, partGeometry.gaps);
730
+ lowerParts(part.parts, path, part.arrangement?.layout ?? "native", values.gap ?? values["column-gap"], part.required && context.withinOptional !== !0 ? context : { ...context, withinOptional: !0 }, growsWithContent(values), partGeometry.overlap, partGeometry.gaps, values["flex-wrap"] === "wrap");
728
731
  return target;
729
732
  }
730
733
  const visualOf = (input, part) => input.visuals?.get(part) ?? input.visual;
@@ -821,7 +824,7 @@ function layerInput(layer, spec, root, slots, profile, foundation, reject) {
821
824
  switch (layer.kind) {
822
825
  case "modal-sheet":
823
826
  sheetQuery(layer, slots, profile, foundation, reject);
824
- const margin = layer.edge === "center" || layer.edge === "block-start" ? profile.field(profile.of(slots["layer-profile"], "layer", "layer"), "layer", "viewport-margin") : null;
827
+ const layerFields = layer.edge === "center" || layer.edge === "block-start" ? profile.of(slots["layer-profile"], "layer", "layer") : null, inline = layerFields === null ? null : profile.field(layerFields, "layer", "viewport-margin"), margin = inline === null || layerFields === null ? null : { inline, block: layer.edge === "block-start" ? layerFields["edge-gap"] ?? inline : inline };
825
828
  return { kind: "modal-sheet", sheet: layer, backdrop: { name: layer.backdrop.surface, fields: profile.of(layer.backdrop.surface, "surface") }, root, motion, margin };
826
829
  case "measured-popover": {
827
830
  const fields = profile.of(slots["layer-profile"], "layer", "layer");
@@ -982,14 +985,12 @@ export function lowerRegion(spec, foundation, input) {
982
985
  const placing = layer.kind === "measured-popover" ? void 0 : spec.measured.find((value) => positions(value.property));
983
986
  if (placing !== void 0)
984
987
  return reject({ kind: "measured-property-unsupported", element: "&", name: placing.name, property: placing.property, type: placing.type, reason: "layer-placement" });
985
- out.rule("&", { ...layered.value.root, ...rootPaints });
988
+ const measured = checked(measuredWrites(input.scope, spec.measured, "&", layered.value.root, frameSupplied), reject);
989
+ out.rule("&", { ...layered.value.root, ...measured, ...rootPaints });
986
990
  for (const rule of layered.value.rules)
987
991
  out.rule(rule.selector, { ...rule.values }, rule.condition ?? void 0);
988
992
  for (const rule of layered.value.documents)
989
993
  out.document(rule);
990
- const measured = checked(measuredWrites(input.scope, spec.measured, "&", layered.value.root, frameSupplied), reject);
991
- if (Object.keys(measured).length > 0)
992
- out.rule(openState(layer.kind), measured);
993
994
  } else {
994
995
  Object.assign(values, stickyValues(spec.sticky, context), anchorClearValues(spec.anchorClear, context), checked(measuredWrites(input.scope, spec.measured, "&", values, frameSupplied), reject), rootPaints);
995
996
  if (Object.keys(values).length > 0)
@@ -1009,7 +1010,16 @@ export function lowerRegion(spec, foundation, input) {
1009
1010
  out.rule(selector, normalizedDeclarations(normalized));
1010
1011
  stateRules(out, "&", spec.when, profile, entering?.blurred ?? !1);
1011
1012
  const partLayout = spec.exposeRows.length > 0 ? "grid" : arrangement.layout;
1012
- lowerParts(spec.parts, "&", partLayout, values.gap ?? values["column-gap"], context, growsWithContent(values), rootGeometry.overlap, rootGeometry.gaps);
1013
+ lowerParts(spec.parts, "&", partLayout, values.gap ?? values["column-gap"], context, growsWithContent(values), rootGeometry.overlap, rootGeometry.gaps, values["flex-wrap"] === "wrap");
1014
+ if (spec.focusWithin !== null) {
1015
+ const focus = context.profile.of(context.slots["focus-profile"], "focus", "recipe.focus");
1016
+ context.out.rule(`&:has(${spec.focusWithin}:focus-visible)`, {
1017
+ "outline-width": context.profile.field(focus, "focus", "width"),
1018
+ "outline-color": context.profile.field(focus, "focus", "color"),
1019
+ "outline-offset": context.profile.field(focus, "focus", "offset"),
1020
+ "outline-style": "solid"
1021
+ });
1022
+ }
1013
1023
  if (spec.carry) {
1014
1024
  if (partLayout !== "stack")
1015
1025
  return reject({ kind: "space-parent-unsupported", part: "&", layout: partLayout });
@@ -161,7 +161,12 @@ export function mountAssets(container, facts) {
161
161
  aliases: [...asset.aliases],
162
162
  findings: [],
163
163
  grid: drawing === void 0 ? null : { x: drawing.box[0], y: drawing.box[1], width: drawing.box[2], height: drawing.box[3] },
164
- drawing: (height) => element(asset, asset.drawings.find((own) => own.size !== null && sizes.some((item) => item.token === own.size && item.px === height)) ?? drawing, height),
164
+ drawing: (height) => {
165
+ const chosen = asset.drawings.find((own) => own.size !== null && sizes.some((item) => item.token === own.size && item.px === height)) ?? drawing, drawn = element(asset, chosen, height);
166
+ if (drawn !== null && chosen !== void 0)
167
+ drawn.setAttribute("width", String(+(height * chosen.box[2] / chosen.box[3]).toFixed(2)));
168
+ return drawn;
169
+ },
165
170
  note: assetNote(asset, pixels)
166
171
  };
167
172
  }),