@reqvire-org/ads 0.5.10 → 0.5.12

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.
@@ -975,7 +975,7 @@ export const choiceErrors = {
975
975
  },
976
976
  "condition-unsupported": {
977
977
  group: "wrong-value",
978
- rule: "A `when` condition selects a state of the owner's root: `&` followed by interaction or form pseudo-classes (:hover, :active, :focus, :focus-visible, :focus-within, :disabled, :enabled, :checked, :indeterminate), `[aria-*]`, `[data-*]` or `[open]` attributes with an optional quoted value, each optionally inside :not(). A state of one of the recipe's own direct parts is written `:has(> .part:state)` with :checked, :indeterminate, :focus-visible, :hover or :disabled (a checkbox's native input, a textarea's own hover). Pseudo-elements, combinators, classes and other selectors are not states.",
978
+ rule: "A `when` condition selects a state of the owner's root: `&` followed by interaction or form pseudo-classes (:hover, :active, :focus, :focus-visible, :focus-within, :disabled, :enabled, :checked, :indeterminate), `[aria-*]`, `[data-*]` or `[open]` attributes with an optional quoted value, each optionally inside :not(). `&` is always the owner's root, also in a part's `when`. A state of one of the recipe's own parts is written `:has(> .part:state)`, a nested part by its path from the root (`:has(> .box > .control:focus-visible)`), with :checked, :indeterminate, :focus-visible, :hover or :disabled (a checkbox's native input, a text field's own focus). Pseudo-elements, combinators, classes and other selectors are not states.",
979
979
  guides: [RECIPES],
980
980
  message: (failure) => `${failure.construction} spec: condition ${failure.condition} at ${failure.path} ${conditionProblem(failure.problem)}.`,
981
981
  repair: "Write the condition as owner states only. Style a pseudo-element with the part's `pseudo` treatment (for example `pseudo: { placeholder: { surface } }`), and a child through its own part."
@@ -1012,9 +1012,9 @@ function conditionProblem(problem) {
1012
1012
  case "state-repeated":
1013
1013
  return `repeats ${problem.state}`;
1014
1014
  case "part-state-unsupported":
1015
- return `has ${problem.text}; a part's state is written \`:has(> .part:state)\` with one of :checked, :indeterminate, :focus-visible, :hover or :disabled`;
1015
+ return `has ${problem.text}; a part's state is written \`:has(> .part:state)\` (a nested part by its path, \`:has(> .box > .part:state)\`) with one of :checked, :indeterminate, :focus-visible, :hover or :disabled`;
1016
1016
  case "part-unknown":
1017
- return `reads a state of ${problem.part}, which is not a direct part of this recipe`;
1017
+ return `reads a state of ${problem.part}, which is not the path of a part of this recipe from its root (a nested part is named through its parents, \`.box > .part\`)`;
1018
1018
  }
1019
1019
  }
1020
1020
  export const constructionErrors = {
@@ -1055,9 +1055,13 @@ export const constructionErrors = {
1055
1055
  return `Surface ${failure.surface} declares mask, but it is applied to a container that does not scroll: its content, text included, would fade where it stands.`;
1056
1056
  case "brightness-off-visual":
1057
1057
  return `Surface ${failure.surface} declares ${failure.field}, but it is not applied to a visual part: the text it covers would change colour without a contrast check.`;
1058
+ case "scrollbar-off-scroller":
1059
+ return `Surface ${failure.surface} declares ${failure.field}, but it is applied to an element that does not scroll, which has no scrollbar.`;
1060
+ case "scrollbar-pair":
1061
+ return `Surface ${failure.surface} declares a scrollbar ${failure.field === "scrollbar-thumb" ? "track without its thumb" : "thumb without its track"}: a scrollbar's colours are set together.`;
1058
1062
  }
1059
1063
  },
1060
- repair: "On a visual part use `shapeShadow`; on a container use `boxShadow` for the shadow of its box, or `groupShadow` when one shadow for everything inside it is what you want. Put a `mask` on a visual part, or on an element whose `overflow` scrolls. Put `brightness` on a visual part (the picture itself). Give each element its own surface profile where they differ."
1064
+ repair: "On a visual part use `shapeShadow`; on a container use `boxShadow` for the shadow of its box, or `groupShadow` when one shadow for everything inside it is what you want. Put a `mask` on a visual part, or on an element whose `overflow` scrolls. Put scrollbar colours and width on an element whose `overflow` scrolls, with the thumb and track together. Put `brightness` on a visual part (the picture itself). Give each element its own surface profile where they differ."
1061
1065
  },
1062
1066
  "surface-shadow-layer": {
1063
1067
  group: "wrong-value",
@@ -1340,9 +1344,9 @@ export const constructionErrors = {
1340
1344
  },
1341
1345
  "progress-contrast-insufficient": {
1342
1346
  group: "accessibility-semantics",
1343
- rule: "A progress bar's fill, and a range slider's thumb, has at least 3:1 contrast against its track in every theme, brand and state (WCAG 1.4.11): the progress part's own background, the slider track's surface.",
1347
+ rule: "A progress bar's fill, a range slider's thumb and a scrollbar's thumb have at least 3:1 contrast against their track in every theme, brand and state (WCAG 1.4.11): the progress part's own background, the slider track's surface.",
1344
1348
  guides: [RECIPES, "ads://guides/accessibility", "ads://guides/tokens"],
1345
- message: (failure) => `The ${failure.subject === "slider-thumb" ? "slider thumb" : "progress fill"} of part "${failure.part}" has contrast ${failure.ratio}:1 (minimum ${failure.minimum}:1) against its track in ${failure.context}, fill state ${failure.states[0] ?? "base"}, track state ${failure.states[1] ?? "base"}.`,
1349
+ message: (failure) => `The ${failure.subject === "slider-thumb" ? "slider thumb" : failure.subject === "scrollbar-thumb" ? "scrollbar thumb" : "progress fill"} of ${failure.subject === "scrollbar-thumb" ? "surface" : "part"} "${failure.part}" has contrast ${failure.ratio}:1 (minimum ${failure.minimum}:1) against its track in ${failure.context}, fill state ${failure.states[0] ?? "base"}, track state ${failure.states[1] ?? "base"}.`,
1346
1350
  repair: "Choose a fill surface whose background token contrasts enough with the part's own background in that context, or adjust the token's value there."
1347
1351
  },
1348
1352
  "progress-contrast-unresolved": {
@@ -1497,10 +1501,10 @@ export const constructionErrors = {
1497
1501
  },
1498
1502
  "extent-parent-unsupported": {
1499
1503
  group: "unsupported",
1500
- rule: "A part fills its parent's main axis only in a `stack` or `inline` arrangement; a layered part already fills its area, and grids place cells.",
1504
+ rule: "A part fills its parent's main axis only in a `stack` or `inline` arrangement, or, in block flow, the width of its container when it arranges its children (a row becomes a block); a layered part already fills its area, and grids place cells.",
1501
1505
  guides: [RECIPES, "ads://guides/layout"],
1502
1506
  message: (failure) => `Part "${failure.part}" declares extent fill, but its parent's layout is ${failure.layout}.`,
1503
- repair: "Arrange the parent as a stack or inline, or remove `extent` (use grid rows `fill` for a grid cell)."
1507
+ repair: "Arrange the parent as a stack or inline, give the part in block flow a `recipe` of its own, or remove `extent` (use grid rows `fill` for a grid cell)."
1504
1508
  },
1505
1509
  "extent-row-hugs": {
1506
1510
  group: "structure-mismatch",
@@ -646,9 +646,9 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
646
646
  return fail(opening, { kind: "part-element-mismatch", part: partName, expected: tags.map((expected) => `<${expected}>`), actual: `<${tag}>` });
647
647
  switch (element.kind) {
648
648
  case "input": {
649
- const type = attr(opening, "type"), value = type === void 0 ? void 0 : await resolve(expression(type), context);
650
- if (value !== element.type)
651
- return fail(type ?? opening, { kind: "part-element-mismatch", part: partName, expected: [`<input type="${element.type}">`], actual: `<input type=${JSON.stringify(value ?? null)}>` });
649
+ const type = attr(opening, "type"), value = type === void 0 ? element.type === "text" ? "text" : void 0 : await resolve(expression(type), context), accepted = element.type === "search" ? ["search"] : [...TEXT_ENTRY_TYPES].filter((entry) => entry !== "search");
650
+ if (typeof value !== "string" || !accepted.includes(value))
651
+ return fail(type ?? opening, { kind: "part-element-mismatch", part: partName, expected: accepted.map((entry) => `<input type="${entry}">`), actual: `<input type=${JSON.stringify(value ?? null)}>` });
652
652
  return;
653
653
  }
654
654
  case "summary": {
@@ -2,6 +2,7 @@ import { createLoweringSession, reviewedLoweringContext } from "./lowering-sessi
2
2
  import { selectAsset } from "./asset-model.mjs";
3
3
  import { REDUCED_MOTION, paintTransitionRules, transitionSetRules } from "./lowering-transitions.mjs";
4
4
  import { reducedMotionPolicy } from "./lowering-motion.mjs";
5
+ import { checkProgressContrast } from "./placeholder-contrast.mjs";
5
6
  import { BORDER_STYLE, BORDER_STYLES, INACTIVE_STATE, SURFACE_STATE, TEXT_TRANSFORM, TEXT_TRANSFORMS, sequenceStepTokenRoles } from "./role-vocabulary.mjs";
6
7
  import { FORCED_FIELDS, FORCED_ONLY, FORCED_PREFIX } from "./forced-colors.mjs";
7
8
  import { controlFrameInsets } from "./lowering-region-layout.mjs";
@@ -11,7 +12,7 @@ import { inspectMotion } from "./motion-model.mjs";
11
12
  import { references, selectedProfile, tokenValueContexts } from "./design-foundation.mjs";
12
13
  import { enterRules } from "./lowering-enter.mjs";
13
14
  import { SEQUENCE_REPEATS, sequenceRules } from "./lowering-sequence.mjs";
14
- import { GROUP_SHADOW, SHAPE_SHADOW, effectDeclarations, effectMisplaced, shadowLayerFinding } from "./surface-effects.mjs";
15
+ import { GROUP_SHADOW, SCROLLBAR_THUMB, SCROLLBAR_TRACK, SHAPE_SHADOW, effectDeclarations, effectMisplaced, shadowLayerFinding } from "./surface-effects.mjs";
15
16
  export const NO_REGIONS = { cells: {}, conditions: [], tilePx: null, contexts: [] }, LIGHT = { name: "light", scheme: "light" };
16
17
  export { REFERENCE_ROOT_PX } from "./css-length.mjs";
17
18
  const context = reviewedLoweringContext();
@@ -156,6 +157,12 @@ export function checkSurfaceEffects(foundation, profile, surfaces, place, reject
156
157
  const fields = profile.of(surface, "surface"), misplaced = effectMisplaced(fields, place);
157
158
  if (misplaced !== null)
158
159
  return reject({ kind: "surface-effect-misplaced", surface, field: misplaced.field, reason: misplaced.reason });
160
+ const thumb = fields[SCROLLBAR_THUMB], track = fields[SCROLLBAR_TRACK];
161
+ if (thumb !== void 0 && track !== void 0) {
162
+ const checked = checkProgressContrast(foundation, surface, [{ condition: null, value: thumb }], [{ condition: null, value: track }]);
163
+ if (checked.kind === "err")
164
+ return reject({ ...checked.error, subject: "scrollbar-thumb" });
165
+ }
159
166
  for (const field of [SHAPE_SHADOW, GROUP_SHADOW]) {
160
167
  const value = fields[field];
161
168
  if (value === void 0)
@@ -356,6 +363,7 @@ export function controlBox(frame, envelope, field, reject) {
356
363
  insets: { blockStart, blockEnd, inlineStart, inlineEnd },
357
364
  padding: { blockStart: blockPadding(blockStart), blockEnd: blockPadding(blockEnd), inlineStart, inlineEnd },
358
365
  border: b,
366
+ borderStyle: frame[BORDER_STYLE] ?? "solid",
359
367
  radius: field(frame, "frame", "radius")
360
368
  };
361
369
  }
@@ -396,5 +404,9 @@ export const controlBoxValues = (box) => ({
396
404
  "padding-block-start": box.padding.blockStart,
397
405
  "padding-block-end": box.padding.blockEnd,
398
406
  ...border(box.border),
407
+ "border-top-style": box.borderStyle,
408
+ "border-right-style": box.borderStyle,
409
+ "border-bottom-style": box.borderStyle,
410
+ "border-left-style": box.borderStyle,
399
411
  "border-radius": box.radius
400
412
  });
@@ -89,7 +89,7 @@ export function parseConstruction(spec) {
89
89
  case "grid":
90
90
  return grid(spec, read);
91
91
  }
92
- })(), direct = new Set(declaredParts(parsed).flatMap((part) => part.within.length === 0 ? [part.selector] : []));
92
+ })(), direct = new Set(declaredParts(parsed).map((part) => [...part.within, part.selector].join(" > ")));
93
93
  for (const use of partStates)
94
94
  if (!direct.has(use.part))
95
95
  return reject({ kind: "condition-unsupported", construction, path: use.path, condition: use.condition, problem: { kind: "part-unknown", part: use.part } });
@@ -138,6 +138,8 @@ export const FAMILIES = [
138
138
  "overlay",
139
139
  "position",
140
140
  "scrollbar-gutter",
141
+ "scrollbar-color",
142
+ "scrollbar-width",
141
143
  "rotate",
142
144
  "scale",
143
145
  "text-box-edge",
@@ -148,11 +148,13 @@ 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, parentWraps = !1) {
151
+ export function extentValues(extent, parent, part, parentGrows = !1, parentWraps = !1, arranged = !1) {
152
152
  switch (extent.kind) {
153
153
  case "content":
154
154
  return ok({});
155
155
  case "fill": {
156
+ if (parent === "native" && arranged && extent.axis !== "both")
157
+ return ok({});
156
158
  if (parent !== "stack" && parent !== "inline")
157
159
  return err({ kind: "extent-parent-unsupported", part, layout: parent });
158
160
  const main = parent === "stack" ? "block" : "inline", values = { "flex-grow": "1", "flex-shrink": "1", "flex-basis": parent === "stack" ? "auto" : "0" };
@@ -70,6 +70,7 @@ export const PLATFORM_FEATURES = [
70
70
  css: ["overlay", "transition-property: overlay"],
71
71
  degrades: "The top-layer exit animation is cut: where overlay cannot be transitioned, the element leaves the top layer at once and closes instantly."
72
72
  },
73
+ { id: "scrollbar-color", css: ["scrollbar-color", "scrollbar-width"], degrades: "A scrolling element keeps the browser's own scrollbar colours and width." },
73
74
  { 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." },
74
75
  { 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." },
75
76
  { id: "prefers-color-scheme", css: ["@media (prefers-color-scheme)"], degrades: "The operating system's colour scheme is not followed: the default theme applies." },
@@ -947,7 +947,7 @@ function lowerPart(part, parent, parentLayout, context, parentGrows, overlapping
947
947
  transitionRules(path, part.paintTransition, part.surface === null ? null : { name: part.surface, fields: partSurface }, part.when, context, entering === null ? partGroups : [...partGroups, entering.group]);
948
948
  writePlays(out, profile, context.foundation, part.name, part.plays, path, [...transitioned(part.paintTransition, entering === null ? [] : [entering.group]), ...moved], reject);
949
949
  const values = part.arrangement === null ? {} : { "box-sizing": "border-box", "min-inline-size": "0", ...arrangementValues(part.arrangement, slots, profile, part.overflow) };
950
- if (parentLayout === "native" && part.arrangement?.layout === "inline" && Object.keys(flowSpace(part, context)).length > 0) {
950
+ if (parentLayout === "native" && part.arrangement?.layout === "inline" && (Object.keys(flowSpace(part, context)).length > 0 || part.extent.kind === "fill")) {
951
951
  values.display = "flex";
952
952
  if (part.extent.kind !== "fill")
953
953
  values["inline-size"] = "fit-content";
@@ -984,8 +984,10 @@ function lowerPart(part, parent, parentLayout, context, parentGrows, overlapping
984
984
  frameFields = controlBoxValues(box);
985
985
  if (part.frame.border.kind === "rules") {
986
986
  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);
987
- for (const side of ["top", "right", "bottom", "left"])
987
+ for (const side of ["top", "right", "bottom", "left"]) {
988
988
  delete frameFields[`border-${side}-width`];
989
+ delete frameFields[`border-${side}-style`];
990
+ }
989
991
  Object.assign(frameFields, rules);
990
992
  for (const side of ["block-start", "block-end", "inline-start", "inline-end"])
991
993
  if (!part.frame.border.sides.includes(side))
@@ -1017,7 +1019,7 @@ function lowerPart(part, parent, parentLayout, context, parentGrows, overlapping
1017
1019
  const partSnap = part.arrangement?.snap ?? null, snapped = partSnap === null ? null : checked(snapValues(partSnap, part.overflow, part.name), reject);
1018
1020
  if (snapped !== null)
1019
1021
  add(snapped.container, "snap");
1020
- add(checked(extentValues(part.extent, parentLayout, part.name, parentGrows, parentWraps && keepsWords(part) && values["min-inline-size"] === void 0), reject), "extent");
1022
+ add(checked(extentValues(part.extent, parentLayout, part.name, parentGrows, parentWraps && keepsWords(part) && values["min-inline-size"] === void 0, part.arrangement !== null && part.arrangement.layout !== "native"), reject), "extent");
1021
1023
  if (parentLayout === "layered" && part.decoration === null)
1022
1024
  add(LAYER, "layer");
1023
1025
  if (part.parts.some((child) => child.decoration !== null))
@@ -263,7 +263,7 @@ export function applyDerived({ target, condition }) {
263
263
  return { applied: !1, reason: `${part} on <${element.localName}>` };
264
264
  continue;
265
265
  }
266
- const has = /^:has\(>\s*(\.[\w-]+)(?::(checked|indeterminate|disabled))?\)$/.exec(part);
266
+ const has = /^:has\(>\s*(\.[\w-]+(?:\s*>\s*\.[\w-]+)*)(?::(checked|indeterminate|disabled))?\)$/.exec(part);
267
267
  if (has !== null) {
268
268
  const selector = `:scope > ${has[1] ?? ""}`, child = element.querySelector(selector);
269
269
  if (child === null)
@@ -17,7 +17,7 @@ export type ValueBound = {
17
17
  /** The CSS numeric types a quantity shape admits. A unitless zero is also a length. */
18
18
  export type QuantityType = "length" | "percentage" | "number" | "time" | "angle";
19
19
  /** CSS properties whose value grammar a non-numeric shape borrows (validated by css-tree). */
20
- export type GrammarProperty = "box-shadow" | "font-family" | "font-feature-settings" | "font-variation-settings" | "transition-timing-function";
20
+ export type GrammarProperty = "box-shadow" | "font-family" | "font-feature-settings" | "font-variation-settings" | "transition-timing-function" | "scrollbar-width";
21
21
  /** What one shape admits. `unregistrable` says why no registered CSS type describes it. */
22
22
  export type ShapeGrammar =
23
23
  /**
@@ -73,6 +73,7 @@ export declare const tokenShapeGrammars: {
73
73
  readonly "opentype-features-or-normal": ShapeGrammar;
74
74
  readonly "opentype-axes-or-normal": ShapeGrammar;
75
75
  readonly "timing-function": ShapeGrammar;
76
+ readonly "scrollbar-width-keyword": ShapeGrammar;
76
77
  };
77
78
  /** A token role's value shape. */
78
79
  export type TokenShape = keyof typeof tokenShapeGrammars;
@@ -159,6 +160,9 @@ declare const tokenRolesByKind: {
159
160
  "border-block-end-color": string[];
160
161
  "shape-shadow": string[];
161
162
  "group-shadow": string[];
163
+ "scrollbar-thumb": string[];
164
+ "scrollbar-track": string[];
165
+ "scrollbar-width": string[];
162
166
  };
163
167
  spacing: {
164
168
  "content-gap": string[];
@@ -23,7 +23,8 @@ export const tokenShapeGrammars = {
23
23
  "font-family-list": property("font-family", "no registered CSS type describes font-family lists"),
24
24
  "opentype-features-or-normal": property("font-feature-settings", "no registered CSS type describes OpenType feature settings"),
25
25
  "opentype-axes-or-normal": property("font-variation-settings", "no registered CSS type describes OpenType axis settings"),
26
- "timing-function": property("transition-timing-function", "no registered CSS type describes timing functions")
26
+ "timing-function": property("transition-timing-function", "no registered CSS type describes timing functions"),
27
+ "scrollbar-width-keyword": property("scrollbar-width", "no registered CSS type describes scrollbar widths")
27
28
  }, tokenRoleShapes = Object.freeze({
28
29
  spacing: "nonnegative-length",
29
30
  "content-gap": "nonnegative-length",
@@ -48,6 +49,7 @@ export const tokenShapeGrammars = {
48
49
  brightness: "nonnegative-percentage",
49
50
  grayscale: "nonnegative-percentage",
50
51
  invert: "nonnegative-percentage",
52
+ "scrollbar-width": "scrollbar-width-keyword",
51
53
  "box-share": "nonnegative-percentage",
52
54
  overlap: "nonnegative-length",
53
55
  "font-family": "font-family-list",
@@ -90,6 +92,7 @@ export const tokenRoleGuides = Object.freeze({
90
92
  brightness: { purpose: "How bright a drawing is shown, as a filter: a picture with no dark version, dimmed in the dark theme.", write: "a percentage: 100% leaves it as it is, below 100% dims it, 0% is black" },
91
93
  grayscale: { purpose: "How grey a drawing is shown, as a filter: colour artwork made quiet, or prepared for inverting on a dark page.", write: "a percentage: 0% leaves its colours, 100% is fully grey" },
92
94
  invert: { purpose: "How far a drawing's tones are inverted, as a filter: dark marks made for a light page shown light on a dark one.", write: "a percentage: 0% leaves it as it is, 100% inverts it fully" },
95
+ "scrollbar-width": { purpose: "How wide a scrolling element's scrollbar is drawn: the platform's, a thin one, or none.", write: "auto, thin or none" },
93
96
  "box-share": { purpose: "A share of an element's own box: how far a backdrop is drawn past it on an axis, growing with the box.", write: "a percentage of the box's size on that axis" },
94
97
  overlap: { purpose: "How far neighbours of an arrangement overlap, in place of a gap between them.", write: "px or rem" },
95
98
  "font-family": { purpose: "The text font and its fallbacks.", write: null },
@@ -185,7 +188,10 @@ const tokenRolesByKind = {
185
188
  "border-block-start-color": ["paint"],
186
189
  "border-block-end-color": ["paint"],
187
190
  "shape-shadow": ["shadow"],
188
- "group-shadow": ["shadow"]
191
+ "group-shadow": ["shadow"],
192
+ "scrollbar-thumb": ["paint"],
193
+ "scrollbar-track": ["paint"],
194
+ "scrollbar-width": ["scrollbar-width"]
189
195
  },
190
196
  spacing: {
191
197
  "content-gap": ["content-gap", "spacing"],