@reqvire-org/ads 0.5.3 → 0.5.4

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.
@@ -1,6 +1,6 @@
1
1
  import { fail, rejecting } from "./design-rejection.mjs";
2
2
  import { CURSORS, ELEMENT_NAMES, FRAME_CORNERS, FRAME_SIDES, GEOMETRY_CHANNELS, OVERFLOW_VALUES, PAINT_CHANNELS, RESIZES, SNAP_ALIGNS, SNAP_TYPES, TEXT_ALIGNS, TEXT_WRAPS, TOUCH_ACTIONS, USER_SELECTS } from "./construction-spec.mjs";
3
- const identifier = /^[a-z][\w-]*$/, profile = /^[a-z][\w-]*(?:\([a-z][\w-]*:\s*[a-z][\w-]*(?:,\s*[a-z][\w-]*:\s*[a-z][\w-]*)*\))?$/, binding = (value) => profile.test(value) || /^profile\([\w-]+-profile\)$/.test(value), wordList = (value) => value.split(/\s+/).every((word) => identifier.test(word)), positive = (value) => /^[1-9]\d*$/.test(value) && Number(value) <= 64, oneOf = (...values) => (value) => values.includes(value), metric = (slot, fields) => (value) => fields.some((field) => value === `profile(${slot}-profile.${field})`), spacing = metric("spacing", ["content-gap", "label-gap", "details-gap", "meta-gap", "section-gap", "indent"]), outsetSpacing = metric("spacing", ["content-gap", "label-gap", "details-gap", "meta-gap", "section-gap", "indent", "outset-block", "outset-inline"]), anchorClear = (value) => value === "profile(layer-profile.clear-block-start)" || value === "profile(spacing-profile.anchor-gap)", overlapSpacing = metric("spacing", ["overlap"]), placement = {
3
+ const identifier = /^[a-z][\w-]*$/, profile = /^[a-z][\w-]*(?:\([a-z][\w-]*:\s*[a-z][\w-]*(?:,\s*[a-z][\w-]*:\s*[a-z][\w-]*)*\))?$/, binding = (value) => profile.test(value) || /^profile\([\w-]+-profile\)$/.test(value), wordList = (value) => value.split(/\s+/).every((word) => identifier.test(word)), positive = (value) => /^[1-9]\d*$/.test(value) && Number(value) <= 64, oneOf = (...values) => (value) => values.includes(value), metric = (slot, fields) => (value) => fields.some((field) => value === `profile(${slot}-profile.${field})`), spacing = metric("spacing", ["content-gap", "label-gap", "details-gap", "meta-gap", "section-gap", "indent", "space-before", "space-after"]), outsetSpacing = metric("spacing", ["content-gap", "label-gap", "details-gap", "meta-gap", "section-gap", "indent", "outset-block", "outset-inline"]), anchorClear = (value) => value === "profile(layer-profile.clear-block-start)" || value === "profile(spacing-profile.anchor-gap)", overlapSpacing = metric("spacing", ["overlap"]), placement = {
4
4
  start: (value) => value === "auto" || positive(value),
5
5
  end: positive,
6
6
  span: (value) => value === "full" || positive(value),
@@ -12,6 +12,7 @@ const identifier = /^[a-z][\w-]*$/, profile = /^[a-z][\w-]*(?:\([a-z][\w-]*:\s*[
12
12
  }, TEXT_ALIGN = oneOf(...TEXT_ALIGNS), OVERFLOW = oneOf(...OVERFLOW_VALUES), ELEMENT = oneOf(...ELEMENT_NAMES), FIELDS = {
13
13
  "ads-recipe": {
14
14
  profile: (value) => profile.test(value),
15
+ markers: wordList,
15
16
  text: binding,
16
17
  surface: binding,
17
18
  align: oneOf("start", "center", "end", "baseline", "stretch"),
@@ -40,6 +41,8 @@ const identifier = /^[a-z][\w-]*$/, profile = /^[a-z][\w-]*(?:\([a-z][\w-]*:\s*[
40
41
  kind: oneOf("text", "visual", "vector", "component"),
41
42
  "space-before": spacing,
42
43
  "space-after": spacing,
44
+ spacing: binding,
45
+ presence: oneOf("visible", "assistive"),
43
46
  scheme: oneOf("light", "dark"),
44
47
  selector: (value) => /^\.[a-z][\w-]*$/.test(value),
45
48
  required: oneOf("true", "false"),
@@ -95,8 +98,11 @@ const identifier = /^[a-z][\w-]*$/, profile = /^[a-z][\w-]*(?:\([a-z][\w-]*:\s*[
95
98
  },
96
99
  motion: binding
97
100
  },
98
- "ads-enter": { surface: binding, motion: binding, translate: metric("motion", ["distance"]), translateInline: metric("motion", ["distance"]), scale: metric("motion", ["scale"]), rotate: metric("motion", ["angle"]) },
99
- "ads-pseudo": { surface: binding },
101
+ "ads-enter": { surface: binding, motion: binding, translate: metric("motion", ["distance"]), "translate-inline": metric("motion", ["distance"]), scale: metric("motion", ["scale"]), rotate: metric("motion", ["angle"]) },
102
+ "ads-pseudo": { surface: binding, text: binding },
103
+ "ads-counter": { reset: () => !0, increment: () => !0 },
104
+ "ads-between": { surface: binding, frame: binding },
105
+ "ads-content": { counter: () => !0, counters: () => !0, style: () => !0, separator: () => !0, prefix: () => !0, suffix: () => !0 },
100
106
  "ads-accessibility": { boundary: () => !0, reason: () => !0 },
101
107
  "ads-focus": { of: () => !0 },
102
108
  "ads-play": { sequence: binding, order: (value) => /^(?:[0-9]|[12][0-9]|3[0-2])$/.test(value) },
@@ -118,6 +118,9 @@ export const PLATFORM_FEATURES = [
118
118
  "box-sizing",
119
119
  "color",
120
120
  "content",
121
+ "counter-reset",
122
+ "counter-increment",
123
+ "clip-path",
121
124
  "display",
122
125
  "flex-basis",
123
126
  "flex-direction",
@@ -253,6 +256,9 @@ export const PLATFORM_FEATURES = [
253
256
  "format()",
254
257
  "local()",
255
258
  "attr()",
259
+ "counter()",
260
+ "counters()",
261
+ "inset()",
256
262
  "cubic-bezier()",
257
263
  "steps()",
258
264
  "linear-gradient()",
@@ -96,7 +96,7 @@ export type Overflow = "clip" | "scroll-block" | "scroll-inline" | "scroll-both"
96
96
  /** A native element the region or part renders, for its closed normalization. */
97
97
  export type NativeElement = "iframe" | "select" | "search-input" | "text-input" | "table" | "header-cell" | "cell" | "list" | "summary";
98
98
  /** A paint a surface treatment can transition. */
99
- export type PaintChannel = "background-color" | "border-color" | "color" | "box-shadow" | "filter" | "backdrop-filter" | "opacity";
99
+ export type PaintChannel = "background-color" | "border-color" | "color" | "text-decoration-color" | "box-shadow" | "filter" | "backdrop-filter" | "opacity";
100
100
  /** Paint channels of one element that change between its state surfaces, timed by a motion profile. */
101
101
  export interface PaintTransition {
102
102
  readonly channels: readonly PaintChannel[];
@@ -137,6 +137,33 @@ export interface Enter {
137
137
  readonly slot: "motion";
138
138
  } | string;
139
139
  }
140
+ /** A counter's number system. */
141
+ export type CounterStyle = "decimal" | "decimal-leading-zero" | "lower-alpha" | "upper-alpha" | "lower-roman" | "upper-roman";
142
+ /**
143
+ * Generated content: a counter's value (`counter`), or every level of a nested counter joined by `separator`
144
+ * (`counters`: 1.1.2), in a number system, between short literals (at most four punctuation marks or spaces).
145
+ */
146
+ export type GeneratedContent = {
147
+ readonly counter: string;
148
+ readonly style?: CounterStyle;
149
+ readonly prefix?: string;
150
+ readonly suffix?: string;
151
+ } | {
152
+ readonly counters: string;
153
+ readonly separator?: string;
154
+ readonly style?: CounterStyle;
155
+ readonly prefix?: string;
156
+ readonly suffix?: string;
157
+ };
158
+ /** A marker's or generated content's treatment: a colour-only surface, a text profile of weight and numerals, content. */
159
+ export interface GeneratedTreatment {
160
+ readonly surface?: string;
161
+ readonly text?: string;
162
+ readonly content?: GeneratedContent;
163
+ readonly when?: Readonly<Record<string, {
164
+ readonly surface: string;
165
+ }>>;
166
+ }
140
167
  /** A colour-only surface on a part's pseudo-element, with owner-state treatments. */
141
168
  export interface PseudoTreatment {
142
169
  readonly surface: ProfileReference;
@@ -345,7 +372,11 @@ export interface RecipeSpec {
345
372
  readonly slot: "spacing";
346
373
  readonly field: "overlap";
347
374
  };
348
- /** In a `when` entry: the spacing profile the element's arrangement reads its gap and overlap from under that state. */
375
+ /**
376
+ * On a part in a flow: its own spacing profile, whose `spaceBefore` and `spaceAfter` are the part's space before and
377
+ * after it (a heading 44 px above and 14 px below). In a `when` entry: the spacing profile the element's arrangement
378
+ * reads its gap and overlap from under that state.
379
+ */
349
380
  readonly spacing?: string;
350
381
  /** The geometry that animates between the element's states: closed channels, timed by a motion profile. */
351
382
  readonly geometryTransition?: {
@@ -408,9 +439,33 @@ export interface RecipeSpec {
408
439
  readonly enter?: Enter;
409
440
  /** Pseudo-element treatments of an `<input>` or `<textarea>` part. */
410
441
  readonly pseudo?: {
411
- readonly placeholder?: PseudoTreatment; /** The filled part of a `<progress>`: a surface with a background; the part's own surface is the track. */
442
+ readonly placeholder?: PseudoTreatment;
443
+ /** The filled part of a `<progress>`: a surface with a background; the part's own surface is the track. */
412
444
  readonly progressValue?: PseudoTreatment;
445
+ /** A list item's marker (`li`, `summary`): its colour, its weight and numerals (`text`), and what it shows (`content`). */
446
+ readonly marker?: GeneratedTreatment;
447
+ /** Generated content before the element (a section number): what it shows, in its colour and weight. */
448
+ readonly before?: GeneratedTreatment & {
449
+ readonly content: GeneratedContent;
450
+ };
451
+ };
452
+ /** CSS counters: where a count starts (`reset`) and what this element counts (`increment`). `list-item` is the browser's own list counter. */
453
+ readonly counter?: {
454
+ readonly reset?: string;
455
+ readonly increment?: string;
456
+ };
457
+ /**
458
+ * A rule between the element's consecutive children: the frame profile's border width and style, painted by the
459
+ * surface's `borderColor` (a hairline between table rows, none after the last).
460
+ */
461
+ readonly between?: {
462
+ readonly surface: string;
463
+ readonly frame: string;
413
464
  };
465
+ /** On a part: `"assistive"` hides it on screen while assistive technology still reads it (a table caption). */
466
+ readonly presence?: "visible" | "assistive";
467
+ /** A list's marker style at each nesting depth, outermost first; deeper lists keep the last. */
468
+ readonly markers?: readonly ("disc" | "circle" | "square" | "none" | CounterStyle)[];
414
469
  /** A top-layer root (recipe root only). */
415
470
  readonly layer?: LayerDeclaration;
416
471
  }
@@ -87,15 +87,15 @@ function buildProfileTree(spec) {
87
87
  required(profileDefinition(node));
88
88
  return root;
89
89
  }
90
- const NESTED = new Set(["layout", "parts", "cells", "at", "when", "frame", "select", "alignRows", "recipe", "normalize", "theme", "paintTransition", "pseudo", "layer", "measured", "paints", "snap", "accessibility", "enter", "sticky", "outset", "play", "focus", "geometryTransition"]), NESTED_IN = {
91
- "ads-part": ["recipe", "when", "frame", "parts", "paintTransition", "pseudo", "at", "measured", "paints", "normalize", "accessibility", "enter", "sticky", "play", "outset", "focus", "geometryTransition"],
90
+ const NESTED = new Set(["layout", "parts", "cells", "at", "when", "frame", "select", "alignRows", "recipe", "normalize", "theme", "paintTransition", "pseudo", "layer", "measured", "paints", "snap", "accessibility", "enter", "sticky", "outset", "play", "focus", "geometryTransition", "counter", "content", "between"]), NESTED_IN = {
91
+ "ads-part": ["recipe", "when", "frame", "parts", "paintTransition", "pseudo", "at", "measured", "paints", "normalize", "accessibility", "enter", "sticky", "play", "outset", "focus", "geometryTransition", "counter", "between"],
92
92
  "ads-cell": ["at"],
93
93
  "ads-at": ["cells", "frame"],
94
94
  "ads-when": ["play", "frame"],
95
- "ads-pseudo": ["when"]
95
+ "ads-pseudo": ["when", "content"]
96
96
  };
97
97
  function body(node, spec) {
98
- 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"] : []] : NESTED_IN[node.name] ?? [];
98
+ 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] ?? [];
99
99
  for (const field of Object.keys(spec))
100
100
  if (NESTED.has(field))
101
101
  check(allowed.includes(field), `Unsupported ${field} in ${node.name}`);
@@ -124,6 +124,12 @@ function body(node, spec) {
124
124
  clause(node, "ads-focus", "", only(spec.focus, ["of"]));
125
125
  if (spec.play !== void 0)
126
126
  clause(node, "ads-play", "", only(spec.play, ["sequence", "order"]));
127
+ if (spec.counter !== void 0)
128
+ clause(node, "ads-counter", "", only(spec.counter, ["reset", "increment"]));
129
+ if (spec.between !== void 0)
130
+ clause(node, "ads-between", "", only(spec.between, ["surface", "frame"]));
131
+ if (spec.content !== void 0)
132
+ clause(node, "ads-content", "", only(spec.content, ["counter", "counters", "style", "separator", "prefix", "suffix"]));
127
133
  const entrance = spec.enter;
128
134
  if (entrance !== void 0) {
129
135
  const { from, motion } = only(entrance, ["from", "motion"]);
@@ -335,34 +335,68 @@ function pseudoColor(treatment, surface, profile, reject) {
335
335
  return reject({ kind: "pseudo-surface-unsupported", pseudo: treatment.pseudo, surface, field: other });
336
336
  return fields.color ?? reject({ kind: "pseudo-surface-unsupported", pseudo: treatment.pseudo, surface, field: null });
337
337
  }
338
- function pseudoRules(part, path, context) {
339
- const { out, profile, reject, foundation } = context, background = (surface) => surface === null ? null : profile.of(surface, "surface").background ?? null, fills = [{ condition: null, value: background(part.surface) }, ...part.when.map(([condition, surface]) => ({ condition, value: background(surface) }))];
340
- for (const treatment of part.pseudo)
338
+ const PSEUDO_TEXT_FIELDS = ["font-weight", "font-feature-settings"];
339
+ function pseudoText(treatment, text, profile, reject) {
340
+ const fields = profile.of(text, "text"), other = Object.keys(fields).find((field) => !PSEUDO_TEXT_FIELDS.includes(field));
341
+ if (other !== void 0)
342
+ return reject({ kind: "pseudo-surface-unsupported", pseudo: treatment.pseudo, surface: text, field: other });
343
+ return { ...fields };
344
+ }
345
+ const cssString = (text) => `"${text.replace(/[\\"]/g, (character) => `\\${character}`)}"`;
346
+ export function contentValue(content) {
347
+ const value = content.kind === "counter" ? `counter(${content.name}, ${content.style})` : `counters(${content.name}, ${cssString(content.separator)}, ${content.style})`;
348
+ return [...content.prefix === "" ? [] : [cssString(content.prefix)], value, ...content.suffix === "" ? [] : [cssString(content.suffix)]].join(" ");
349
+ }
350
+ function writeBetween(out, path, between, axis, profile, reject) {
351
+ if (between === null)
352
+ return;
353
+ const frame = profile.of(between.frame, "frame"), width = frame["border-width"] ?? reject({ kind: "profile-field-missing", profile: between.frame, field: "borderWidth" }), color = profile.of(between.surface, "surface")["border-color"] ?? reject({ kind: "profile-field-missing", profile: between.surface, field: "borderColor" }), side = `border-${axis}-start`;
354
+ out.rule(`${path} > * + *`, { [`${side}-width`]: width, [`${side}-style`]: frame[BORDER_STYLE] ?? "solid", [`${side}-color`]: color });
355
+ }
356
+ const ASSISTIVE_ONLY = { position: "absolute", "inline-size": "1px", "block-size": "1px", overflow: "hidden", "clip-path": "inset(50%)", "white-space": "nowrap" }, counterValues = (counter) => counter === null ? {} : { ...counter.reset === null ? {} : { "counter-reset": counter.reset }, ...counter.increment === null ? {} : { "counter-increment": counter.increment } };
357
+ function writeMarkerStyles(out, styles) {
358
+ styles.forEach((style, depth) => out.rule(`&${" li &".repeat(depth)}`, { "list-style-type": style }));
359
+ }
360
+ function pseudoRules(name, treatments, path, fills, context, hasBox) {
361
+ const { out, profile, reject, foundation } = context;
362
+ for (const treatment of treatments)
341
363
  switch (treatment.pseudo) {
342
364
  case "placeholder": {
343
- const suffix = "::placeholder", base = pseudoColor(treatment, treatment.surface, profile, reject), states = treatment.when.map(([condition, surface]) => ({ condition, value: pseudoColor(treatment, surface, profile, reject) }));
365
+ const suffix = "::placeholder", surface = treatment.surface ?? "", base = pseudoColor(treatment, surface, profile, reject), states = treatment.when.map(([condition, state]) => ({ condition, value: pseudoColor(treatment, state, profile, reject) }));
344
366
  out.rule(`${path}${suffix}`, { color: base, opacity: "1" });
345
367
  for (const { condition, value } of states)
346
368
  out.rule(`${under(condition, path)}${suffix}`, { color: value });
347
- const checked = checkPlaceholderContrast(foundation, part.name, [{ condition: null, value: base }, ...states], fills);
369
+ const checked = checkPlaceholderContrast(foundation, name, [{ condition: null, value: base }, ...states], fills);
348
370
  if (checked.kind === "err")
349
371
  return reject(checked.error);
350
372
  break;
351
373
  }
352
374
  case "progressValue": {
353
- const base = pseudoFill(treatment, treatment.surface, profile, reject), states = treatment.when.map(([condition, surface]) => ({ condition, value: pseudoFill(treatment, surface, profile, reject) }));
354
- out.rule(path, { appearance: "none", "-webkit-appearance": "none", ...part.box === null ? { "border-style": "none" } : {} });
375
+ const surface = treatment.surface ?? "", base = pseudoFill(treatment, surface, profile, reject), states = treatment.when.map(([condition, state]) => ({ condition, value: pseudoFill(treatment, state, profile, reject) }));
376
+ out.rule(path, { appearance: "none", "-webkit-appearance": "none", ...hasBox ? {} : { "border-style": "none" } });
355
377
  out.rule(`${path}::-webkit-progress-bar`, { background: "transparent" });
356
378
  for (const suffix of PROGRESS_FILLS) {
357
379
  out.rule(`${path}${suffix}`, { background: base, "border-radius": "inherit" });
358
380
  for (const { condition, value } of states)
359
381
  out.rule(`${under(condition, path)}${suffix}`, { background: value });
360
382
  }
361
- const checked = checkProgressContrast(foundation, part.name, [{ condition: null, value: base }, ...states], fills);
383
+ const checked = checkProgressContrast(foundation, name, [{ condition: null, value: base }, ...states], fills);
362
384
  if (checked.kind === "err")
363
385
  return reject(checked.error);
364
386
  break;
365
387
  }
388
+ case "marker":
389
+ case "before": {
390
+ const suffix = `::${treatment.pseudo}`, values = {
391
+ ...treatment.content === null ? {} : { content: contentValue(treatment.content) },
392
+ ...treatment.surface === null ? {} : { color: pseudoColor(treatment, treatment.surface, profile, reject) },
393
+ ...treatment.text === null ? {} : pseudoText(treatment, treatment.text, profile, reject)
394
+ };
395
+ out.rule(`${path}${suffix}`, values);
396
+ for (const [condition, state] of treatment.when)
397
+ out.rule(`${under(condition, path)}${suffix}`, { color: pseudoColor(treatment, state, profile, reject) });
398
+ break;
399
+ }
366
400
  }
367
401
  }
368
402
  const PROGRESS_FILLS = ["::-webkit-progress-value", "::-moz-progress-bar"];
@@ -448,23 +482,32 @@ function lowerParts(parts, parent, layout, gap, context, parentGrows = !1, overl
448
482
  });
449
483
  }
450
484
  function writePartSpace(parts, parent, layout, gap, context) {
451
- const spaced = parts.filter((part) => part.spaceBefore !== null || part.spaceAfter !== null);
452
- if (spaced.length === 0)
485
+ const { out, profile, slots } = context, own = (part, side) => {
486
+ const binding = side === "before" ? part.spaceBefore : part.spaceAfter;
487
+ if (binding !== null)
488
+ return profile.field(profile.of(slots["spacing-profile"], "spacing", "space"), "spacing", kebab(binding.field));
489
+ return part.spacing === null ? null : profile.of(part.spacing, "spacing", part.name)[`space-${side}`] ?? null;
490
+ }, spaced = parts.flatMap((part) => {
491
+ const before = own(part, "before"), after = own(part, "after");
492
+ if (part.spacing !== null && before === null && after === null)
493
+ return context.reject({ kind: "profile-field-missing", profile: part.spacing, field: "spaceBefore" });
494
+ return before === null && after === null ? [] : [{ part, before, after }];
495
+ }), [first] = spaced;
496
+ if (first === void 0)
453
497
  return;
454
- const [first] = spaced;
455
- if (layout !== "stack" && layout !== "native" && first !== void 0)
456
- return context.reject({ kind: "space-parent-unsupported", part: first.name, layout });
457
- const { out, profile, slots } = context, spacing = (binding) => profile.field(profile.of(slots["spacing-profile"], "spacing", "space"), "spacing", kebab(binding.field)), between = gap ?? "0px", margin = (space) => ({ "margin-block-start": `calc(${space} - ${between})` });
458
- for (const part of spaced) {
459
- if (part.spaceBefore !== null)
460
- out.rule(`${parent} > * + ${part.selector}`, margin(spacing(part.spaceBefore)));
461
- if (part.spaceAfter !== null)
462
- out.rule(`${parent} > ${part.selector} + :not(:first-child)`, margin(spacing(part.spaceAfter)));
498
+ if (layout !== "stack" && layout !== "native")
499
+ return context.reject({ kind: "space-parent-unsupported", part: first.part.name, layout });
500
+ const between = gap ?? "0px", margin = (space) => ({ "margin-block-start": `calc(${space} - ${between})` });
501
+ for (const { part, before, after } of spaced) {
502
+ if (before !== null)
503
+ out.rule(`${parent} > * + ${part.selector}:not(:first-child)`, margin(before));
504
+ if (after !== null)
505
+ out.rule(`${parent} > ${part.selector} + :not(:first-child):not(:first-child)`, margin(after));
463
506
  }
464
- for (const before of spaced)
465
- for (const after of spaced)
466
- if (before.spaceAfter !== null && after.spaceBefore !== null)
467
- out.rule(`${parent} > ${before.selector} + ${after.selector}:not(:first-child)`, margin(`max(${spacing(before.spaceAfter)}, ${spacing(after.spaceBefore)})`));
507
+ for (const previous of spaced)
508
+ for (const next of spaced)
509
+ if (previous.after !== null && next.before !== null)
510
+ out.rule(`${parent} > ${previous.part.selector} + ${next.part.selector}:not(:first-child):not(:first-child)`, margin(`max(${previous.after}, ${next.before})`));
468
511
  }
469
512
  function lowerPart(part, parent, parentLayout, context, parentGrows, overlapping = null) {
470
513
  const { out, profile, slots, reject } = context, path = `${parent} > ${part.selector}`;
@@ -530,7 +573,7 @@ function lowerPart(part, parent, parentLayout, context, parentGrows, overlapping
530
573
  Object.assign(values, { "box-sizing": "border-box" }, boxFields);
531
574
  let target = null, frameFields = {};
532
575
  if (part.frame !== null) {
533
- const lineHeight = profile.field(text, "text", "line-height"), frame = profile.of(slots["frame-profile"], "frame", "control"), box = controlBox(frame, LINE_BOX, profile.field, reject);
576
+ const lineText = text["line-height"] === void 0 && slots["text-profile"] !== void 0 ? profile.of(slots["text-profile"], "text") : text, lineHeight = profile.field(lineText, "text", "line-height"), frame = profile.of(slots["frame-profile"], "frame", "control"), box = controlBox(frame, LINE_BOX, profile.field, reject);
534
577
  frameFields = controlBoxValues(box);
535
578
  if (part.frame.border.kind === "rules") {
536
579
  const paint = part.surface === null ? void 0 : profile.of(part.surface, "surface")["border-color"], rules = checked(frameRules(part.frame.border, frame["border-width"], { surface: part.surface, color: paint }, slots["frame-profile"] ?? null, frame[BORDER_STYLE]), reject);
@@ -548,7 +591,7 @@ function lowerPart(part, parent, parentLayout, context, parentGrows, overlapping
548
591
  element: part.name,
549
592
  frame: frameTarget(frame, box, profile.field),
550
593
  hitArea,
551
- content: { kind: "field", line: { lineHeight, fontSize: text["font-size"] ?? null } },
594
+ content: { kind: "field", line: { lineHeight, fontSize: lineText["font-size"] ?? null } },
552
595
  measured: measuredBounds(part.measured, values)
553
596
  };
554
597
  context.targets.push(target);
@@ -580,6 +623,9 @@ function lowerPart(part, parent, parentLayout, context, parentGrows, overlapping
580
623
  if (twice !== void 0)
581
624
  return reject({ kind: "extent-conflict", element: part.name, property: twice[0], providers: ["recipe.normalize.when", "normalize"] });
582
625
  add(normalizedDeclarations(part.normalize), "normalize");
626
+ 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"));
627
+ if (context.input.margined?.includes(pathKey) === !0 && !ownMargin)
628
+ out.rule(path, { margin: "0" });
583
629
  const media = part.measured.some((value) => value.type === "position" || value.type === "intrinsic-size") && part.content.kind === "visual" && visualOf(context.input, part.name)?.kind === "content-media" ? covers(profile.of(slots["visual-profile"], "visual", "visual")) ? "cover" : "contain" : null;
584
630
  Object.assign(values, checked(measuredWrites(context.input.scope, part.measured, part.name, values, part.frame !== null ? supplied(slots, frameFields) : null, media), reject));
585
631
  Object.assign(values, paintValues(part.name, part.paints, "box", [part.surface], part.when, context));
@@ -587,7 +633,7 @@ function lowerPart(part, parent, parentLayout, context, parentGrows, overlapping
587
633
  const conditioned = conditionedVisual(part, context);
588
634
  if (part.scheme !== null && visualOf(context.input, part.name)?.kind !== "content-media")
589
635
  return reject({ kind: "scheme-unsupported", part: part.name });
590
- const unrendered = part.content.kind === "visual" && !part.required && visualOf(context.input, part.name) === null;
636
+ const unrendered = part.content.kind === "visual" && (!part.required || context.withinOptional === !0) && visualOf(context.input, part.name) === null;
591
637
  if (part.content.kind === "visual" && !unrendered)
592
638
  lowerVisual(path, context, part.measured.find((value) => value.type === "intrinsic-size") ?? null, conditioned, part.scheme, boxFields, part.name);
593
639
  if (snapped !== null)
@@ -595,8 +641,17 @@ function lowerPart(part, parent, parentLayout, context, parentGrows, overlapping
595
641
  stateRules(out, path, part.when, profile, entering?.blurred ?? !1);
596
642
  for (const [condition, normalized] of part.normalizeWhen)
597
643
  out.rule(under(condition, path), normalizedDeclarations(normalized));
598
- pseudoRules(part, path, context);
599
- lowerParts(part.parts, path, part.arrangement?.layout ?? "native", values.gap, context, growsWithContent(values), partGeometry.overlap, partGeometry.gaps);
644
+ {
645
+ const background = (surface) => surface === null ? null : profile.of(surface, "surface").background ?? null, fills = [{ condition: null, value: background(part.surface) }, ...part.when.map(([condition, surface]) => ({ condition, value: background(surface) }))];
646
+ pseudoRules(part.name, part.pseudo, path, fills, context, part.box !== null);
647
+ const counted = counterValues(part.counter);
648
+ if (Object.keys(counted).length > 0)
649
+ out.rule(path, counted);
650
+ writeBetween(out, path, part.between, part.arrangement?.layout === "inline" ? "inline" : "block", profile, reject);
651
+ if (part.presence === "assistive")
652
+ out.rule(path, { ...ASSISTIVE_ONLY });
653
+ }
654
+ lowerParts(part.parts, path, part.arrangement?.layout ?? "native", values.gap, part.required && context.withinOptional !== !0 ? context : { ...context, withinOptional: !0 }, growsWithContent(values), partGeometry.overlap, partGeometry.gaps);
600
655
  return target;
601
656
  }
602
657
  const visualOf = (input, part) => input.visuals?.get(part) ?? input.visual;
@@ -770,6 +825,13 @@ export function lowerRegion(spec, foundation, input) {
770
825
  const rootGroups = [...press === null ? [] : [press], ...measuredMotion(spec.measured, profile, reject), ...rootGeometry.group === null ? [] : [rootGeometry.group]], entering = writeEnter(out, profile, "&", spec.enter, rootSurface, stateSurfaces("&", spec.when, profile), slots, transitioned(spec.paintTransition, rootGroups), reject);
771
826
  transitionRules("&", spec.paintTransition, surface === null ? null : { name: surface, fields: rootSurface }, spec.when, context, entering === null ? rootGroups : [...rootGroups, entering.group]);
772
827
  writePlays(out, profile, foundation, "&", spec.plays, "&", transitioned(spec.paintTransition, entering === null ? rootGroups : [...rootGroups, entering.group]), reject);
828
+ const rootFill = (name) => name === null ? null : profile.of(name, "surface").background ?? null;
829
+ pseudoRules("&", spec.pseudo, "&", [{ condition: null, value: rootFill(surface) }, ...spec.when.map(([condition, name]) => ({ condition, value: rootFill(name) }))], context, spec.frame !== null);
830
+ const rootCounters = counterValues(spec.counter);
831
+ if (Object.keys(rootCounters).length > 0)
832
+ out.rule("&", rootCounters);
833
+ writeMarkerStyles(out, spec.markers);
834
+ writeBetween(out, "&", spec.between, spec.arrangement.layout === "inline" ? "inline" : "block", profile, reject);
773
835
  const { arrangement } = spec, values = arrangement.layout !== "native" || spec.frame !== null ? { "box-sizing": "border-box", "min-inline-size": "0" } : {};
774
836
  let exposed = null;
775
837
  if (spec.exposeRows.length > 0) {
@@ -141,6 +141,7 @@ declare const tokenRolesByKind: {
141
141
  background: string[];
142
142
  color: string[];
143
143
  "border-color": string[];
144
+ "text-decoration-color": string[];
144
145
  "box-shadow": string[];
145
146
  "background-image": string[];
146
147
  opacity: string[];
@@ -163,6 +164,8 @@ declare const tokenRolesByKind: {
163
164
  "meta-gap": string[];
164
165
  "section-gap": string[];
165
166
  indent: string[];
167
+ "space-before": string[];
168
+ "space-after": string[];
166
169
  overlap: string[];
167
170
  "anchor-gap": string[];
168
171
  "outset-block": string[];
@@ -164,6 +164,7 @@ const tokenRolesByKind = {
164
164
  background: ["paint"],
165
165
  color: ["paint"],
166
166
  "border-color": ["paint"],
167
+ "text-decoration-color": ["paint"],
167
168
  "box-shadow": ["shadow"],
168
169
  "background-image": ["gradient"],
169
170
  opacity: ["opacity"],
@@ -186,6 +187,8 @@ const tokenRolesByKind = {
186
187
  "meta-gap": ["content-gap", "spacing"],
187
188
  "section-gap": ["content-gap", "spacing"],
188
189
  indent: ["content-gap", "spacing"],
190
+ "space-before": ["content-gap", "spacing"],
191
+ "space-after": ["content-gap", "spacing"],
189
192
  overlap: ["overlap", "content-gap", "spacing"],
190
193
  "anchor-gap": ["layout-size", "content-gap", "spacing"],
191
194
  "outset-block": ["content-gap", "spacing", "box-share"],