@reqvire-org/ads 0.5.8 → 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)
@@ -550,6 +550,10 @@ function ownSpace(part, side, context) {
550
550
  return profile.field(profile.of(slots["spacing-profile"], "spacing", "space"), "spacing", kebab(binding.field));
551
551
  return part.spacing === null ? null : profile.of(part.spacing, "spacing", part.name)[`space-${side}`] ?? null;
552
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
+ }
553
557
  function writePartSpace(parts, parent, layout, gap, context, carry = !1) {
554
558
  const { out } = context, own = (part, side) => ownSpace(part, side, context), spaced = parts.flatMap((part) => {
555
559
  const before = own(part, "before"), after = own(part, "after");
@@ -581,6 +585,13 @@ function writePartSpace(parts, parent, layout, gap, context, carry = !1) {
581
585
  out.rule(`&:not(:last-child):has(> ${part.selector}:last-child)`, { "margin-block-end": `max(0px, calc(${after} - var(${FLOW_GAP}, 0px)))` });
582
586
  }
583
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
+ }
584
595
  const FLOW_GAP = "--ads-flow-gap", keepsWords = (part) => part.textLayout.wrap !== "truncate" && part.textLayout.wrap !== "anywhere" && part.frame === null && part.box === null;
585
596
  function lowerPart(part, parent, parentLayout, context, parentGrows, overlapping = null, parentWraps = !1) {
586
597
  const { out, profile, slots, reject } = context, path = `${parent} > ${part.selector}`;
@@ -589,7 +600,8 @@ function lowerPart(part, parent, parentLayout, context, parentGrows, overlapping
589
600
  return null;
590
601
  }
591
602
  if (part.content.kind === "component") {
592
- 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);
593
605
  return null;
594
606
  }
595
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;
@@ -698,11 +710,8 @@ function lowerPart(part, parent, parentLayout, context, parentGrows, overlapping
698
710
  return reject({ kind: "extent-conflict", element: part.name, property: twice[0], providers: ["recipe.normalize.when", "normalize"] });
699
711
  add(normalizedDeclarations(part.normalize), "normalize");
700
712
  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
- }
713
+ if (parentLayout === "native")
714
+ add(flowSpace(part, context), "space");
706
715
  const ownMargin = Object.keys(values).some((property) => property.startsWith("margin")) || (context.rootNormalized.get(path) ?? []).some((property) => property.startsWith("margin"));
707
716
  if (context.input.margined?.includes(pathKey) === !0 && !ownMargin)
708
717
  out.rule(path, { margin: "0" });
@@ -736,6 +745,8 @@ function lowerPart(part, parent, parentLayout, context, parentGrows, overlapping
736
745
  if (part.presence === "assistive")
737
746
  out.rule(path, { ...ASSISTIVE_ONLY });
738
747
  }
748
+ if ((part.arrangement?.layout ?? "native") === "native" && framedBlock(values))
749
+ trimFlowEdges(part.parts, path, context);
739
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");
740
751
  return target;
741
752
  }
@@ -1019,6 +1030,8 @@ export function lowerRegion(spec, foundation, input) {
1019
1030
  out.rule(selector, normalizedDeclarations(normalized));
1020
1031
  stateRules(out, "&", spec.when, profile, entering?.blurred ?? !1);
1021
1032
  const partLayout = spec.exposeRows.length > 0 ? "grid" : arrangement.layout;
1033
+ if (partLayout === "native" && (spec.flowEdges === "trim" || framedBlock(values)))
1034
+ trimFlowEdges(spec.parts, "&", context);
1022
1035
  lowerParts(spec.parts, "&", partLayout, values.gap ?? values["column-gap"], context, growsWithContent(values), rootGeometry.overlap, rootGeometry.gaps, values["flex-wrap"] === "wrap");
1023
1036
  if (spec.focusWithin !== null) {
1024
1037
  const focus = context.profile.of(context.slots["focus-profile"], "focus", "recipe.focus");