@reqvire-org/ads 0.5.7 → 0.5.9

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.
@@ -464,6 +464,7 @@ export function checkFindings(inputs, check, publics = null) {
464
464
  diagnostics.push(...targets.diagnostics);
465
465
  advisories.push(...targets.advisories);
466
466
  advisories.push(...counterFindings(inputs, analyzedOwners(check.outcomes)));
467
+ advisories.push(...disabledShownFindings(inputs, analyzedOwners(check.outcomes)));
467
468
  diagnostics.push(...documentFindings(inputs, analyzedOwners(check.outcomes)));
468
469
  diagnostics.push(...endAlignmentFindings(inputs, analyzedOwners(check.outcomes), check.foundation));
469
470
  diagnostics.push(...focusShownFindings(inputs, analyzedOwners(check.outcomes)));
@@ -605,6 +606,38 @@ function counterFindings(inputs, owners) {
605
606
  }
606
607
  return [...used].flatMap(([counter, origin]) => reset.has(counter) ? [] : [reviewFinding(inputs, { origin, review: { kind: "counter-unreset", counter } })]);
607
608
  }
609
+ const UNSEEN_DISABLED = /^(cursor|pointer-events|user-select|-webkit-user-select|touch-action|transition(-[a-z]+)?|animation(-[a-z]+)?)$/, INACTIVE_STATE = /:disabled|\[aria-disabled=["']?true["']?\]/, EXCLUDED_INACTIVE = /:not\((?::disabled|\[aria-disabled=["']?true["']?\])\)/g;
610
+ function disabledShownFindings(inputs, owners) {
611
+ const findings = [];
612
+ for (const facts of owners.values()) {
613
+ let origin;
614
+ const changes = new Set;
615
+ let shown = !1;
616
+ for (const style of facts.styles.values()) {
617
+ if (!INACTIVE_STATE.test(style.css))
618
+ continue;
619
+ const [first] = style.origins;
620
+ for (const match of style.css.matchAll(/([^{}]+)\{([^{}]*)\}/g)) {
621
+ if (!INACTIVE_STATE.test((match[1] ?? "").replace(EXCLUDED_INACTIVE, "")))
622
+ continue;
623
+ if (origin === void 0 && first?.kind === "point")
624
+ origin = { ...first, file: path.join(inputs.dsRoot, first.file) };
625
+ for (const declaration of (match[2] ?? "").split(";")) {
626
+ const property = declaration.split(":")[0]?.trim() ?? "";
627
+ if (property === "")
628
+ continue;
629
+ if (UNSEEN_DISABLED.test(property))
630
+ changes.add(property);
631
+ else
632
+ shown = !0;
633
+ }
634
+ }
635
+ }
636
+ if (origin !== void 0 && !shown)
637
+ findings.push(reviewFinding(inputs, { origin, review: { kind: "disabled-unshown", changes: [...changes].sort() } }));
638
+ }
639
+ return findings;
640
+ }
608
641
  function placedSpacing(owners, plain, publics) {
609
642
  if (publics === null)
610
643
  return new Map;
@@ -111,6 +111,7 @@ const identifier = /^[a-z][\w-]*$/, profile = /^[a-z][\w-]*(?:\([a-z][\w-]*:\s*[
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") },
114
+ "ads-flow": { edges: oneOf("trim") },
114
115
  "ads-snap": { type: oneOf(...SNAP_TYPES), align: oneOf(...SNAP_ALIGNS) },
115
116
  "ads-layer": {
116
117
  element: oneOf("dialog", "popover"),
@@ -514,6 +514,14 @@ export interface RecipeSpec {
514
514
  * the list's gap and the item's last block's space after.
515
515
  */
516
516
  readonly carry?: boolean;
517
+ /**
518
+ * A root in block flow (no `layout`): `edges: "trim"` makes its first child's space before and its last child's space
519
+ * after nothing, so a page that opens with a heading starts flush. A block flow inside its own padding or border
520
+ * does this by itself; a frameless one otherwise passes those spaces out, as CSS margins do.
521
+ */
522
+ readonly flow?: {
523
+ readonly edges: "trim";
524
+ };
517
525
  /** On a part: `"assistive"` hides it on screen while assistive technology still reads it (a table caption). */
518
526
  readonly presence?: "visible" | "assistive";
519
527
  /** A list's marker style at each nesting depth, outermost first; deeper lists keep the last. */
@@ -95,7 +95,7 @@ function buildProfileTree(spec) {
95
95
  required(profileDefinition(node));
96
96
  return root;
97
97
  }
98
- 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 = {
98
+ 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", "flow"]), NESTED_IN = {
99
99
  "ads-part": ["recipe", "when", "frame", "parts", "paintTransition", "pseudo", "at", "measured", "paints", "normalize", "accessibility", "enter", "sticky", "play", "outset", "focus", "geometryTransition", "counter", "between"],
100
100
  "ads-cell": ["at"],
101
101
  "ads-at": ["cells", "frame"],
@@ -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", "focus"] : []] : 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", "flow"] : []] : 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}`);
@@ -132,6 +132,8 @@ function body(node, spec) {
132
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
+ if (spec.flow !== void 0)
136
+ clause(node, "ads-flow", "", only(spec.flow, ["edges"]));
135
137
  if (spec.counter !== void 0)
136
138
  clause(node, "ads-counter", "", only(spec.counter, ["reset", "increment"]));
137
139
  if (spec.between !== void 0)
@@ -217,7 +219,8 @@ export const combineRecipes = (...inputs) => rejecting(() => {
217
219
  };
218
220
  return makeRecipe(inputs.reduce((result, input) => merge(result, input.spec, "recipe"), {}));
219
221
  }), foundation = (spec) => rejecting(() => {
220
- only(spec, ["tokens", "text", "surface", "focus", "reset", "themes", "brands", "palette", "followSystemTheme", "sections", "appIcon"]);
222
+ only(spec, ["tokens", "text", "surface", "focus", "reset", "themes", "brands", "palette", "followSystemTheme", "sections", "appIcon", "scrollbarGutter"]);
223
+ check(spec.scrollbarGutter === void 0 || spec.scrollbarGutter === "stable", `Foundation's scrollbarGutter is "stable", or omitted`);
221
224
  check(spec.tokens === "./tokens", "Foundation uses the owned role directory");
222
225
  check(typeof spec.text === "string" && typeof spec.surface === "string", "Foundation needs text and surface profiles");
223
226
  check(typeof spec.focus === "string", "Foundation needs a focus profile for the document's default focus indicator");
@@ -544,13 +544,18 @@ function lowerParts(parts, parent, layout, gap, context, parentGrows = !1, overl
544
544
  context.neighbours.push({ axis, gap: between, first, second });
545
545
  });
546
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
+ }
553
+ function flowSpace(part, context) {
554
+ const before = ownSpace(part, "before", context), after = ownSpace(part, "after", context);
555
+ return before === null && after === null ? {} : { "margin-block-start": before ?? "0", "margin-block-end": after ?? "0" };
556
+ }
547
557
  function writePartSpace(parts, parent, layout, gap, context, carry = !1) {
548
- const { out, profile, slots } = context, own = (part, side) => {
549
- const binding = side === "before" ? part.spaceBefore : part.spaceAfter;
550
- if (binding !== null)
551
- return profile.field(profile.of(slots["spacing-profile"], "spacing", "space"), "spacing", kebab(binding.field));
552
- return part.spacing === null ? null : profile.of(part.spacing, "spacing", part.name)[`space-${side}`] ?? null;
553
- }, spaced = parts.flatMap((part) => {
558
+ const { out } = context, own = (part, side) => ownSpace(part, side, context), spaced = parts.flatMap((part) => {
554
559
  const before = own(part, "before"), after = own(part, "after");
555
560
  if (part.spacing !== null && before === null && after === null)
556
561
  return context.reject({ kind: "profile-field-missing", profile: part.spacing, field: "spaceBefore" });
@@ -560,6 +565,8 @@ function writePartSpace(parts, parent, layout, gap, context, carry = !1) {
560
565
  return;
561
566
  if (layout !== "stack" && layout !== "native")
562
567
  return context.reject({ kind: "space-parent-unsupported", part: first.part.name, layout });
568
+ if (layout === "native")
569
+ return;
563
570
  const between = gap ?? "0px", margin = (space) => ({ "margin-block-start": `calc(${space} - ${between})` });
564
571
  for (const { part, before, after } of spaced) {
565
572
  if (before !== null)
@@ -578,6 +585,13 @@ function writePartSpace(parts, parent, layout, gap, context, carry = !1) {
578
585
  out.rule(`&:not(:last-child):has(> ${part.selector}:last-child)`, { "margin-block-end": `max(0px, calc(${after} - var(${FLOW_GAP}, 0px)))` });
579
586
  }
580
587
  }
588
+ const BLOCK_EDGE = /^(padding|border)-(block|top|bottom)(-start|-end)?(-width)?$/, framedBlock = (values) => Object.entries(values).some(([property, value]) => BLOCK_EDGE.test(property) && (property.startsWith("padding") || property.endsWith("-width")) && !/^0(px)?$/.test(String(value).trim()));
589
+ function trimFlowEdges(parts, parent, context) {
590
+ if (!parts.some((part) => ownSpace(part, "before", context) !== null || ownSpace(part, "after", context) !== null))
591
+ return;
592
+ context.out.rule(`${parent} > :first-child:first-child`, { "margin-block-start": "0" });
593
+ context.out.rule(`${parent} > :last-child:last-child`, { "margin-block-end": "0" });
594
+ }
581
595
  const FLOW_GAP = "--ads-flow-gap", keepsWords = (part) => part.textLayout.wrap !== "truncate" && part.textLayout.wrap !== "anywhere" && part.frame === null && part.box === null;
582
596
  function lowerPart(part, parent, parentLayout, context, parentGrows, overlapping = null, parentWraps = !1) {
583
597
  const { out, profile, slots, reject } = context, path = `${parent} > ${part.selector}`;
@@ -586,7 +600,8 @@ function lowerPart(part, parent, parentLayout, context, parentGrows, overlapping
586
600
  return null;
587
601
  }
588
602
  if (part.content.kind === "component") {
589
- writeConditioned(part, path, checked(extentValues(part.extent, parentLayout, part.name, parentGrows, parentWraps && keepsWords(part)), reject), context);
603
+ const placed = checked(extentValues(part.extent, parentLayout, part.name, parentGrows, parentWraps && keepsWords(part)), reject);
604
+ writeConditioned(part, path, { ...placed, ...parentLayout === "native" ? flowSpace(part, context) : {} }, context);
590
605
  return null;
591
606
  }
592
607
  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;
@@ -694,7 +709,10 @@ function lowerPart(part, parent, parentLayout, context, parentGrows, overlapping
694
709
  if (twice !== void 0)
695
710
  return reject({ kind: "extent-conflict", element: part.name, property: twice[0], providers: ["recipe.normalize.when", "normalize"] });
696
711
  add(normalizedDeclarations(part.normalize), "normalize");
697
- 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"));
712
+ const pathKey = path.split(" > ").slice(1).join(" ");
713
+ if (parentLayout === "native")
714
+ add(flowSpace(part, context), "space");
715
+ const ownMargin = Object.keys(values).some((property) => property.startsWith("margin")) || (context.rootNormalized.get(path) ?? []).some((property) => property.startsWith("margin"));
698
716
  if (context.input.margined?.includes(pathKey) === !0 && !ownMargin)
699
717
  out.rule(path, { margin: "0" });
700
718
  if (context.input.native?.includes(pathKey) === !0) {
@@ -727,6 +745,8 @@ function lowerPart(part, parent, parentLayout, context, parentGrows, overlapping
727
745
  if (part.presence === "assistive")
728
746
  out.rule(path, { ...ASSISTIVE_ONLY });
729
747
  }
748
+ if ((part.arrangement?.layout ?? "native") === "native" && framedBlock(values))
749
+ trimFlowEdges(part.parts, path, context);
730
750
  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");
731
751
  return target;
732
752
  }
@@ -1010,6 +1030,8 @@ export function lowerRegion(spec, foundation, input) {
1010
1030
  out.rule(selector, normalizedDeclarations(normalized));
1011
1031
  stateRules(out, "&", spec.when, profile, entering?.blurred ?? !1);
1012
1032
  const partLayout = spec.exposeRows.length > 0 ? "grid" : arrangement.layout;
1033
+ if (partLayout === "native" && (spec.flowEdges === "trim" || framedBlock(values)))
1034
+ trimFlowEdges(spec.parts, "&", context);
1013
1035
  lowerParts(spec.parts, "&", partLayout, values.gap ?? values["column-gap"], context, growsWithContent(values), rootGeometry.overlap, rootGeometry.gaps, values["flex-wrap"] === "wrap");
1014
1036
  if (spec.focusWithin !== null) {
1015
1037
  const focus = context.profile.of(context.slots["focus-profile"], "focus", "recipe.focus");