@reqvire-org/ads 0.5.6 → 0.5.8

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) {
@@ -1143,6 +1155,7 @@ function regionPart(name, value, read, path, nested) {
1143
1155
  sticky: stickySpec(part.sticky, `${path}.sticky`, read),
1144
1156
  outset: outsetSpec(part.outset, `${path}.outset`, read),
1145
1157
  focusOf: focusSource(part.focus, `${path}.focus`, read),
1158
+ focusShownBy: focusShownBy(part.focus, `${path}.focus`, read),
1146
1159
  drawnBy: part.drawnBy === void 0 ? null : read.string(part.drawnBy, `${path}.drawnBy`),
1147
1160
  anchorClear: anchorClear(part.anchorClear, `${path}.anchorClear`, read),
1148
1161
  scheme: partScheme(part, content, path, read),
@@ -1168,9 +1181,28 @@ function focusSource(value, path, read) {
1168
1181
  if (value === void 0)
1169
1182
  return null;
1170
1183
  const declared = read.object(value, path);
1171
- 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");
1172
1187
  return read.string(declared.of, `${path}.of`);
1173
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
+ }
1174
1206
  function parseParts(value, read, path, nested) {
1175
1207
  if (value === void 0)
1176
1208
  return [];
@@ -1275,7 +1307,8 @@ function region(authored, read) {
1275
1307
  "extent",
1276
1308
  "anchorClear",
1277
1309
  "overlap",
1278
- "geometryTransition"
1310
+ "geometryTransition",
1311
+ "focus"
1279
1312
  ]);
1280
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);
1281
1314
  uniqueMeasured(measured, parts, read);
@@ -1318,6 +1351,7 @@ function region(authored, read) {
1318
1351
  frameAt: frameCondition(spec.at, regionFrame(spec.frame, read), read),
1319
1352
  plays: layer !== null && rootStates.plays.length > 0 ? read.reject({ kind: "field-unsupported", construction: "region", path: "recipe.play" }) : rootStates.plays,
1320
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),
1321
1355
  parts,
1322
1356
  exposeRows,
1323
1357
  layer,
@@ -217,7 +217,7 @@ function slotArguments(spec, file, declaration) {
217
217
  }));
218
218
  }
219
219
  const DOCUMENT_TEXT_FIELDS = ["font-family", "font-size", "line-height"];
220
- export function documentProfiles(foundation, references) {
220
+ export function documentProfiles(foundation, references, scrollbarGutter = null) {
221
221
  const fields = (field) => {
222
222
  const reference = references[field], profile = selectedProfile(foundation, reference);
223
223
  if (profile.kind === "err")
@@ -237,7 +237,7 @@ export function documentProfiles(foundation, references) {
237
237
  const focus = fields("focus");
238
238
  if (focus.kind === "err")
239
239
  return focus;
240
- return ok({ text: text.value, surface: surface.value, focus: focus.value, names: { ...references } });
240
+ return ok({ text: text.value, surface: surface.value, focus: focus.value, names: { ...references }, scrollbarGutter });
241
241
  }
242
242
  export function selectedProfile(foundation, reference, select = {}) {
243
243
  const chosen = foundation.model.select(reference, Object.entries(select));
@@ -40,7 +40,7 @@ export function readDesignInputs(captured, { dsRoot }) {
40
40
  const contexts = ok(declared.value.contexts), foundation = readFoundation(texts, { kind: "declared", ...contexts.value });
41
41
  if (foundation.kind === "err")
42
42
  return err({ kind: "foundation", failure: foundation.error });
43
- const document = documentProfiles(foundation.value, documentReferences(declaration ?? ""));
43
+ const document = documentProfiles(foundation.value, documentReferences(declaration ?? ""), documentGutter(declaration ?? ""));
44
44
  if (document.kind === "err")
45
45
  return err({ kind: "foundation", failure: document.error });
46
46
  const declarations = [];
@@ -111,6 +111,10 @@ function documentReferences(declaration) {
111
111
  throw Error("A validated foundation declaration names its text, surface and focus profiles.");
112
112
  return { text, surface, focus };
113
113
  }
114
+ function documentGutter(declaration) {
115
+ const specs = exampleDeclarations(declaration, FOUNDATION_DECLARATION, "foundation"), spec = specs.kind === "ok" ? specs.value[0] : void 0;
116
+ return isRecordValue(spec) && spec.scrollbarGutter === "stable" ? "stable" : null;
117
+ }
114
118
  const isRecordValue = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
115
119
  export function capturedDesignFiles(dsRoot) {
116
120
  const files = [];
@@ -31,6 +31,8 @@ export function foundationSheet({ foundation, document, themes, fonts, documents
31
31
  const [base] = themes;
32
32
  if (base !== void 0)
33
33
  root.append(rule(":root", schemeScope(base.scheme)));
34
+ if (document.scrollbarGutter !== null)
35
+ root.append(rule("html", [["scrollbar-gutter", document.scrollbarGutter]]));
34
36
  for (const theme of themes)
35
37
  root.append(rule(`:root[data-theme=${JSON.stringify(theme.name)}]`, schemeScope(theme.scheme)));
36
38
  if (sectionsDeclared(foundation))
@@ -7,6 +7,13 @@ function borderedAtEnd(fields, border) {
7
7
  const width = sideWidth(Object.fromEntries(fields), "inline-end");
8
8
  return width !== void 0 && !/^0(px)?$/.test(width.trim());
9
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
+ }
10
17
  export function endInsetOf(foundation, spec) {
11
18
  switch (spec.kind) {
12
19
  case "region": {
@@ -24,6 +31,8 @@ export function endInsetOf(foundation, spec) {
24
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);
25
32
  if (surface !== null && surface.kind === "ok" && surface.value.kind === "surface" && surface.value.fields.has("background") || borderedAtEnd(frame.value.fields, spec.frame?.border ?? null))
26
33
  return [];
34
+ if (endsRagged(spec.arrangement, spec.parts))
35
+ return null;
27
36
  const end = frameInlineInsets(Object.fromEntries(frame.value.fields)).end;
28
37
  return end === void 0 ? [] : [end];
29
38
  }
@@ -69,6 +78,8 @@ export function stackPartsOf(foundation, spec) {
69
78
  const surface = part.surface === null ? null : selectedProfile(foundation, part.surface);
70
79
  if (surface !== null && surface.kind === "ok" && surface.value.kind === "surface" && surface.value.fields.has("background") || borderedAtEnd(frame.value.fields, null))
71
80
  return [{ part: part.name, kind: "box", inset: [] }];
81
+ if (endsRagged(part.arrangement, part.parts))
82
+ return [];
72
83
  const end = frameInlineInsets(Object.fromEntries(frame.value.fields)).end;
73
84
  return [{ part: part.name, kind: "box", inset: end === void 0 ? [] : [end] }];
74
85
  });
@@ -42,6 +42,11 @@ export interface FoundationSpec {
42
42
  * each export) and writes `app-icons.ts` with the links and web manifest entries.
43
43
  */
44
44
  readonly appIcon?: AppIconDeclaration;
45
+ /**
46
+ * `"stable"`: the page keeps its scrollbar's room at all times (`scrollbar-gutter: stable` on the document), so a
47
+ * modal's scroll lock, which hides the scrollbar, shifts nothing; omitted, the browser decides.
48
+ */
49
+ readonly scrollbarGutter?: "stable";
45
50
  }
46
51
  /** A paint-role token, by name. */
47
52
  export type PaintToken = `--${string}`;
@@ -1,9 +1,8 @@
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-]+\)$/;
4
3
  export function declareRule(registry, request) {
5
4
  const { selector, conditions, values, important, origin } = request;
6
- if (!selector.startsWith("&") && !OWNED_DOCUMENT.test(selector))
5
+ if (!selector.startsWith("&"))
7
6
  return err({ kind: "selector-not-owned", selector, origin });
8
7
  const declarations = [];
9
8
  for (const [property, value] of values) {
@@ -74,14 +74,13 @@ function cardRules(sheet, veil, own, motion, margin) {
74
74
  "block-size": "fit-content",
75
75
  "max-block-size": `calc(100dvh - ${margin.block} * 2)`,
76
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 };
77
+ }, paint = { selector: "&::backdrop", values: veil, condition: null };
78
78
  if (motion === null || sheet.motion === null)
79
- return { root: placement, rules: [paint, gutter] };
79
+ return { root: placement, rules: [paint] };
80
80
  return {
81
81
  root: { ...placement, ...transition("opacity", motion) },
82
82
  rules: [
83
83
  paint,
84
- gutter,
85
84
  { selector: "&:not([open])", values: { opacity: "0" }, condition: null },
86
85
  { selector: "&[open]", values: { opacity: "0" }, condition: STARTING },
87
86
  { selector: "&::backdrop", values: transition("opacity", motion), condition: null },
@@ -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";
@@ -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") },
@@ -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)
@@ -217,7 +217,8 @@ export const combineRecipes = (...inputs) => rejecting(() => {
217
217
  };
218
218
  return makeRecipe(inputs.reduce((result, input) => merge(result, input.spec, "recipe"), {}));
219
219
  }), foundation = (spec) => rejecting(() => {
220
- only(spec, ["tokens", "text", "surface", "focus", "reset", "themes", "brands", "palette", "followSystemTheme", "sections", "appIcon"]);
220
+ only(spec, ["tokens", "text", "surface", "focus", "reset", "themes", "brands", "palette", "followSystemTheme", "sections", "appIcon", "scrollbarGutter"]);
221
+ check(spec.scrollbarGutter === void 0 || spec.scrollbarGutter === "stable", `Foundation's scrollbarGutter is "stable", or omitted`);
221
222
  check(spec.tokens === "./tokens", "Foundation uses the owned role directory");
222
223
  check(typeof spec.text === "string" && typeof spec.surface === "string", "Foundation needs text and surface profiles");
223
224
  check(typeof spec.focus === "string", "Foundation needs a focus profile for the document's default focus indicator");
@@ -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) => {
@@ -541,13 +544,14 @@ function lowerParts(parts, parent, layout, gap, context, parentGrows = !1, overl
541
544
  context.neighbours.push({ axis, gap: between, first, second });
542
545
  });
543
546
  }
547
+ function ownSpace(part, side, context) {
548
+ const { profile, slots } = context, binding = side === "before" ? part.spaceBefore : part.spaceAfter;
549
+ if (binding !== null)
550
+ return profile.field(profile.of(slots["spacing-profile"], "spacing", "space"), "spacing", kebab(binding.field));
551
+ return part.spacing === null ? null : profile.of(part.spacing, "spacing", part.name)[`space-${side}`] ?? null;
552
+ }
544
553
  function writePartSpace(parts, parent, layout, gap, context, carry = !1) {
545
- const { out, profile, slots } = context, own = (part, side) => {
546
- const binding = side === "before" ? part.spaceBefore : part.spaceAfter;
547
- if (binding !== null)
548
- return profile.field(profile.of(slots["spacing-profile"], "spacing", "space"), "spacing", kebab(binding.field));
549
- return part.spacing === null ? null : profile.of(part.spacing, "spacing", part.name)[`space-${side}`] ?? null;
550
- }, spaced = parts.flatMap((part) => {
554
+ const { out } = context, own = (part, side) => ownSpace(part, side, context), spaced = parts.flatMap((part) => {
551
555
  const before = own(part, "before"), after = own(part, "after");
552
556
  if (part.spacing !== null && before === null && after === null)
553
557
  return context.reject({ kind: "profile-field-missing", profile: part.spacing, field: "spaceBefore" });
@@ -557,6 +561,8 @@ function writePartSpace(parts, parent, layout, gap, context, carry = !1) {
557
561
  return;
558
562
  if (layout !== "stack" && layout !== "native")
559
563
  return context.reject({ kind: "space-parent-unsupported", part: first.part.name, layout });
564
+ if (layout === "native")
565
+ return;
560
566
  const between = gap ?? "0px", margin = (space) => ({ "margin-block-start": `calc(${space} - ${between})` });
561
567
  for (const { part, before, after } of spaced) {
562
568
  if (before !== null)
@@ -575,15 +581,15 @@ function writePartSpace(parts, parent, layout, gap, context, carry = !1) {
575
581
  out.rule(`&:not(:last-child):has(> ${part.selector}:last-child)`, { "margin-block-end": `max(0px, calc(${after} - var(${FLOW_GAP}, 0px)))` });
576
582
  }
577
583
  }
578
- const FLOW_GAP = "--ads-flow-gap";
579
- function lowerPart(part, parent, parentLayout, context, parentGrows, overlapping = null) {
584
+ const FLOW_GAP = "--ads-flow-gap", keepsWords = (part) => part.textLayout.wrap !== "truncate" && part.textLayout.wrap !== "anywhere" && part.frame === null && part.box === null;
585
+ function lowerPart(part, parent, parentLayout, context, parentGrows, overlapping = null, parentWraps = !1) {
580
586
  const { out, profile, slots, reject } = context, path = `${parent} > ${part.selector}`;
581
587
  if (part.content.kind === "vector") {
582
588
  lowerVector(part, part.content.stroke, path, context);
583
589
  return null;
584
590
  }
585
591
  if (part.content.kind === "component") {
586
- writeConditioned(part, path, checked(extentValues(part.extent, parentLayout, part.name, parentGrows), reject), context);
592
+ writeConditioned(part, path, checked(extentValues(part.extent, parentLayout, part.name, parentGrows, parentWraps && keepsWords(part)), reject), context);
587
593
  return null;
588
594
  }
589
595
  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 +683,7 @@ function lowerPart(part, parent, parentLayout, context, parentGrows, overlapping
677
683
  const partSnap = part.arrangement?.snap ?? null, snapped = partSnap === null ? null : checked(snapValues(partSnap, part.overflow, part.name), reject);
678
684
  if (snapped !== null)
679
685
  add(snapped.container, "snap");
680
- add(checked(extentValues(part.extent, parentLayout, part.name, parentGrows), reject), "extent");
686
+ add(checked(extentValues(part.extent, parentLayout, part.name, parentGrows, parentWraps && keepsWords(part) && values["min-inline-size"] === void 0), reject), "extent");
681
687
  if (parentLayout === "layered")
682
688
  add(LAYER, "layer");
683
689
  if (part.outset !== null) {
@@ -691,7 +697,13 @@ function lowerPart(part, parent, parentLayout, context, parentGrows, overlapping
691
697
  if (twice !== void 0)
692
698
  return reject({ kind: "extent-conflict", element: part.name, property: twice[0], providers: ["recipe.normalize.when", "normalize"] });
693
699
  add(normalizedDeclarations(part.normalize), "normalize");
694
- const pathKey = path.split(" > ").slice(1).join(" "), ownMargin = Object.keys(values).some((property) => property.startsWith("margin")) || (context.rootNormalized.get(path) ?? []).some((property) => property.startsWith("margin"));
700
+ const pathKey = path.split(" > ").slice(1).join(" ");
701
+ if (parentLayout === "native") {
702
+ const before = ownSpace(part, "before", context), after = ownSpace(part, "after", context);
703
+ if (before !== null || after !== null)
704
+ add({ "margin-block-start": before ?? "0", "margin-block-end": after ?? "0" }, "space");
705
+ }
706
+ const ownMargin = Object.keys(values).some((property) => property.startsWith("margin")) || (context.rootNormalized.get(path) ?? []).some((property) => property.startsWith("margin"));
695
707
  if (context.input.margined?.includes(pathKey) === !0 && !ownMargin)
696
708
  out.rule(path, { margin: "0" });
697
709
  if (context.input.native?.includes(pathKey) === !0) {
@@ -724,7 +736,7 @@ function lowerPart(part, parent, parentLayout, context, parentGrows, overlapping
724
736
  if (part.presence === "assistive")
725
737
  out.rule(path, { ...ASSISTIVE_ONLY });
726
738
  }
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);
739
+ 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
740
  return target;
729
741
  }
730
742
  const visualOf = (input, part) => input.visuals?.get(part) ?? input.visual;
@@ -982,14 +994,12 @@ export function lowerRegion(spec, foundation, input) {
982
994
  const placing = layer.kind === "measured-popover" ? void 0 : spec.measured.find((value) => positions(value.property));
983
995
  if (placing !== void 0)
984
996
  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 });
997
+ const measured = checked(measuredWrites(input.scope, spec.measured, "&", layered.value.root, frameSupplied), reject);
998
+ out.rule("&", { ...layered.value.root, ...measured, ...rootPaints });
986
999
  for (const rule of layered.value.rules)
987
1000
  out.rule(rule.selector, { ...rule.values }, rule.condition ?? void 0);
988
1001
  for (const rule of layered.value.documents)
989
1002
  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
1003
  } else {
994
1004
  Object.assign(values, stickyValues(spec.sticky, context), anchorClearValues(spec.anchorClear, context), checked(measuredWrites(input.scope, spec.measured, "&", values, frameSupplied), reject), rootPaints);
995
1005
  if (Object.keys(values).length > 0)
@@ -1009,7 +1019,16 @@ export function lowerRegion(spec, foundation, input) {
1009
1019
  out.rule(selector, normalizedDeclarations(normalized));
1010
1020
  stateRules(out, "&", spec.when, profile, entering?.blurred ?? !1);
1011
1021
  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);
1022
+ lowerParts(spec.parts, "&", partLayout, values.gap ?? values["column-gap"], context, growsWithContent(values), rootGeometry.overlap, rootGeometry.gaps, values["flex-wrap"] === "wrap");
1023
+ if (spec.focusWithin !== null) {
1024
+ const focus = context.profile.of(context.slots["focus-profile"], "focus", "recipe.focus");
1025
+ context.out.rule(`&:has(${spec.focusWithin}:focus-visible)`, {
1026
+ "outline-width": context.profile.field(focus, "focus", "width"),
1027
+ "outline-color": context.profile.field(focus, "focus", "color"),
1028
+ "outline-offset": context.profile.field(focus, "focus", "offset"),
1029
+ "outline-style": "solid"
1030
+ });
1031
+ }
1013
1032
  if (spec.carry) {
1014
1033
  if (partLayout !== "stack")
1015
1034
  return reject({ kind: "space-parent-unsupported", part: "&", layout: partLayout });