@nanisoft/prism-ui 0.7.0 → 0.8.0

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.
Files changed (43) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/catalog.d.ts.map +1 -1
  3. package/dist/catalog.js +30 -0
  4. package/dist/components/index.d.ts +6 -0
  5. package/dist/components/index.d.ts.map +1 -1
  6. package/dist/components/index.js +3 -0
  7. package/dist/components/ui/breadcrumb.d.ts +6 -2
  8. package/dist/components/ui/breadcrumb.d.ts.map +1 -1
  9. package/dist/components/ui/breadcrumb.js +5 -3
  10. package/dist/components/ui/dialog.d.ts +12 -1
  11. package/dist/components/ui/dialog.d.ts.map +1 -1
  12. package/dist/components/ui/dialog.js +2 -2
  13. package/dist/components/ui/live-region.d.ts +78 -0
  14. package/dist/components/ui/live-region.d.ts.map +1 -0
  15. package/dist/components/ui/live-region.js +48 -0
  16. package/dist/components/ui/mark.d.ts +44 -0
  17. package/dist/components/ui/mark.d.ts.map +1 -0
  18. package/dist/components/ui/mark.js +79 -0
  19. package/dist/components/ui/pagination.d.ts +24 -6
  20. package/dist/components/ui/pagination.d.ts.map +1 -1
  21. package/dist/components/ui/pagination.js +23 -9
  22. package/dist/components/ui/product-switcher.d.ts +7 -0
  23. package/dist/components/ui/product-switcher.d.ts.map +1 -1
  24. package/dist/components/ui/product-switcher.js +2 -2
  25. package/dist/components/ui/slider.d.ts +1 -1
  26. package/dist/components/ui/slider.d.ts.map +1 -1
  27. package/dist/components/ui/tree.d.ts +115 -0
  28. package/dist/components/ui/tree.d.ts.map +1 -0
  29. package/dist/components/ui/tree.js +137 -0
  30. package/dist/styles.css +31 -0
  31. package/gates/README.md +98 -0
  32. package/gates/cli.mjs +133 -0
  33. package/gates/hidden-state.mjs +243 -0
  34. package/gates/index.mjs +81 -0
  35. package/gates/laws.mjs +170 -0
  36. package/gates/links.mjs +187 -0
  37. package/gates/pack-boundary.mjs +421 -0
  38. package/gates/pin.mjs +130 -0
  39. package/gates/retired-line.mjs +314 -0
  40. package/gates/run.mjs +320 -0
  41. package/gates/runtime-token-read.mjs +129 -0
  42. package/gates/stylesheet-ownership.mjs +207 -0
  43. package/package.json +14 -2
@@ -1 +1 @@
1
- {"version":3,"file":"slider.d.ts","sourceRoot":"","sources":["../../../src/components/ui/slider.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAI3C;;;;;GAKG;AACH,MAAM,WAAW,WAAY,SAAQ,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,UAAU,GAAG,cAAc,CAAC;IAC3F,wDAAwD;IACxD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,kEAAkE;IAClE,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,iDAAiD;IACjD,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,mDAAmD;IACnD,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,2DAA2D;IAC3D,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,mDAAmD;IACnD,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,gEAAgE;IAChE,WAAW,CAAC,EAAE,YAAY,GAAG,UAAU,CAAA;IACvC,mDAAmD;IACnD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,sDAAsD;IACtD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,kEAAkE;IAClE,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,mCAAmC;IACnC,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CACxC;AAED;;;;;;;;GAQG;AACH,iBAAS,MAAM,CAAC,EACd,SAAS,EACT,YAAY,EAAE,SAAS,EACvB,GAAG,KAAK,EACT,EAAE,WAAW,+BAiCb;AAED,OAAO,EAAE,MAAM,EAAE,CAAA"}
1
+ {"version":3,"file":"slider.d.ts","sourceRoot":"","sources":["../../../src/components/ui/slider.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAI3C;;;;;GAKG;AACH,MAAM,WAAW,WAAY,SAAQ,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC;IAC1E,wDAAwD;IACxD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,kEAAkE;IAClE,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,iDAAiD;IACjD,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,mDAAmD;IACnD,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,2DAA2D;IAC3D,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,mDAAmD;IACnD,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,gEAAgE;IAChE,WAAW,CAAC,EAAE,YAAY,GAAG,UAAU,CAAA;IACvC,mDAAmD;IACnD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,sDAAsD;IACtD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,kEAAkE;IAClE,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,mCAAmC;IACnC,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CACxC;AAED;;;;;;;;GAQG;AACH,iBAAS,MAAM,CAAC,EACd,SAAS,EACT,YAAY,EAAE,SAAS,EACvB,GAAG,KAAK,EACT,EAAE,WAAW,+BAiCb;AAED,OAAO,EAAE,MAAM,EAAE,CAAA"}
@@ -0,0 +1,115 @@
1
+ import { type ReactNode } from 'react';
2
+ /**
3
+ * A node a reader can arrive at: a title and the address it is read at.
4
+ *
5
+ * `href` is required. A node in a tree that goes nowhere is an entry a reader can
6
+ * focus and not follow, and this Component renders every node with a destination
7
+ * as a native anchor so a reader can see where it goes before taking it.
8
+ */
9
+ export type TreeNodePage = {
10
+ type: 'page';
11
+ /** The words the reader meets. */
12
+ title: string;
13
+ /** The address the node is read at. */
14
+ href: string;
15
+ };
16
+ /**
17
+ * A label over a list of nodes, at any depth.
18
+ *
19
+ * `href` is the group's own index and it is optional on purpose. A group with no
20
+ * index is a place in the tree and not a route, so this Component renders it as a
21
+ * label: no anchor, no `href`, nothing focusable. Inventing a route for it would
22
+ * publish an address that resolves to nothing.
23
+ *
24
+ * `items` is required, because a group that renders a label and holds nothing is
25
+ * an empty entry rather than a group. Pass a node with no children rather than a
26
+ * group with none.
27
+ */
28
+ export type TreeNodeGroup = {
29
+ type: 'group';
30
+ /** The words on the label. A status inside them stays inside them. */
31
+ title: string;
32
+ /** The group's own index, where it has one. Omit it for a label over a list. */
33
+ href?: string;
34
+ /** The nodes under this group, in the order a reader should meet them. */
35
+ items: readonly TreeNode[];
36
+ };
37
+ /**
38
+ * A rule between nodes, carrying a name that is usually empty.
39
+ *
40
+ * It is a label and never a link. The alternative spelling, a page node with an
41
+ * empty `href`, is a control that cannot be operated, so a rule is its own type.
42
+ */
43
+ export type TreeNodeDivider = {
44
+ type: 'divider';
45
+ /** The words on the rule, which may be the empty string. */
46
+ title: string;
47
+ };
48
+ /**
49
+ * One node in a tree, of any of the three kinds.
50
+ *
51
+ * The union is closed, and it is a union rather than one shape with optional
52
+ * fields because a reader meets three different things in a tree: a destination, a
53
+ * label over a list, and a rule. A single shape would make all three look alike,
54
+ * and "a place that is a heading, not a link" is the distinction the whole
55
+ * arrangement turns on.
56
+ */
57
+ export type TreeNode = TreeNodePage | TreeNodeGroup | TreeNodeDivider;
58
+ /** The props the Tree accepts. */
59
+ export interface TreeProps {
60
+ /** The nodes, in the order a reader should meet them. */
61
+ nodes: readonly TreeNode[];
62
+ /**
63
+ * The address the reader is currently at, which is what marks the current node.
64
+ *
65
+ * The marking is the attribute and not a class, so it survives a theme change and
66
+ * does not depend on a colour a reader may not distinguish.
67
+ */
68
+ currentHref?: string;
69
+ /**
70
+ * The accessible name of the tree, read before its nodes.
71
+ *
72
+ * Required rather than defaulted, because a tree with no name is announced as
73
+ * "tree" and a page with two of them is a page where a reader cannot tell which
74
+ * is which. The name is the caller's word.
75
+ */
76
+ label: string;
77
+ /** Layout only. */
78
+ className?: string;
79
+ /**
80
+ * The words a reader is told when the tree is empty, and optionally what to do
81
+ * about it.
82
+ *
83
+ * A tree that renders nothing is a control with nothing in it, so the empty case
84
+ * is authored rather than left to a caller to notice.
85
+ */
86
+ empty?: {
87
+ message: string;
88
+ action?: ReactNode;
89
+ };
90
+ }
91
+ /**
92
+ * A tree of nodes, given as data.
93
+ *
94
+ * This is the third of the three primitives the expansion found missing, and the
95
+ * one with a different kind of work behind it: the implementation already existed
96
+ * as two private renderers inside the documentation Page, with its depth rule, its
97
+ * `aria-current` marking and its rule that a group with no index renders a label.
98
+ * What was missing was that it was unreachable, and that its data type was bound
99
+ * to documentation navigation rather than being a tree's own vocabulary. So this is
100
+ * a promotion rather than a second implementation, and the reasoning in the
101
+ * documentation Page is carried across rather than rewritten.
102
+ *
103
+ * **A flat list renders a flat tree.** An outline is a tree of depth one, so a
104
+ * caller passes leaves and gets leaves. A Component that required nesting to
105
+ * express a flat structure would make the common case the awkward one.
106
+ *
107
+ * **The Page keeps its own renderers and does not change.** Its two rules, that a
108
+ * section carries no status or count and that a group with no index is a label,
109
+ * are specific to a documentation rail and are reasoned at length in the design
110
+ * rules. A documentation rail is one shape a tree takes, not the shape. Whether the
111
+ * Page composes this Component later is a decision this ticket does not make.
112
+ */
113
+ declare function Tree({ nodes, currentHref, label, className, empty }: TreeProps): import("react").JSX.Element;
114
+ export { Tree };
115
+ //# sourceMappingURL=tree.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tree.d.ts","sourceRoot":"","sources":["../../../src/components/ui/tree.tsx"],"names":[],"mappings":"AAEA,OAAO,EAA8B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAIlE;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,kCAAkC;IAClC,KAAK,EAAE,MAAM,CAAA;IACb,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,OAAO,CAAA;IACb,sEAAsE;IACtE,KAAK,EAAE,MAAM,CAAA;IACb,gFAAgF;IAChF,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,0EAA0E;IAC1E,KAAK,EAAE,SAAS,QAAQ,EAAE,CAAA;CAC3B,CAAA;AAED;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,SAAS,CAAA;IACf,4DAA4D;IAC5D,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,QAAQ,GAAG,YAAY,GAAG,aAAa,GAAG,eAAe,CAAA;AAErE,kCAAkC;AAClC,MAAM,WAAW,SAAS;IACxB,yDAAyD;IACzD,KAAK,EAAE,SAAS,QAAQ,EAAE,CAAA;IAC1B;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;;;OAMG;IACH,KAAK,EAAE,MAAM,CAAA;IACb,mBAAmB;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;;;OAMG;IACH,KAAK,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,SAAS,CAAA;KAAE,CAAA;CAChD;AAqKD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,iBAAS,IAAI,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,SAAS,+BAkEvE;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -0,0 +1,137 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useRef } from 'react';
4
+ import { cn } from '../../lib/utils';
5
+ /** Whether a group's subtree contains the current address, at any depth. */
6
+ function containsHref(nodes, currentHref) {
7
+ if (currentHref === undefined)
8
+ return false;
9
+ for (const node of nodes) {
10
+ if (node.type === 'page' && node.href === currentHref)
11
+ return true;
12
+ if (node.type === 'group') {
13
+ if (node.href === currentHref)
14
+ return true;
15
+ if (containsHref(node.items, currentHref))
16
+ return true;
17
+ }
18
+ }
19
+ return false;
20
+ }
21
+ /** Whether an address is the current one or lies under it, for a heading's emphasis. */
22
+ function under(href, currentHref) {
23
+ if (currentHref === undefined)
24
+ return false;
25
+ return currentHref === href || currentHref.startsWith(`${href}/`);
26
+ }
27
+ function TreeLevel({ nodes, currentHref, depth, }) {
28
+ return (_jsx("ul", { "data-slot": "tree-list", "data-depth": depth,
29
+ // `group` on the list, not `treeitem`: the items are the things a reader
30
+ // navigates between, and a `ul` of them is a group. `role="none"` on each
31
+ // item below removes the listitem role so that only the anchors and labels
32
+ // are the navigable things, which is what lets a caller's own keyboard model
33
+ // move between them without a roving tabindex fighting the document's.
34
+ role: "group", className: cn('border-border flex flex-col gap-1 border-l',
35
+ // One level of indent per nested group and none at the top, so the depth
36
+ // reads from the rule rather than from the words.
37
+ depth > 0 && 'ps-3'), children: nodes.map((node, index) => (_jsx(TreeItem, { node: node, currentHref: currentHref, depth: depth }, `${node.type}:${index}`))) }));
38
+ }
39
+ function TreeItem({ node, currentHref, depth, }) {
40
+ if (node.type === 'divider') {
41
+ // A rule between nodes. It is a label, so it is not focusable and a reader
42
+ // does not meet it as a destination, and the empty title renders no words
43
+ // above the hairline rather than a word a reader has to interpret.
44
+ return (_jsx("li", { "data-slot": "tree-divider", role: "none", className: "border-border mt-2 border-t pt-2 first:mt-0 first:border-t-0 first:pt-0", children: node.title ? (_jsx("span", { className: "text-muted-foreground text-xs font-medium tracking-wide uppercase", children: node.title })) : null }));
45
+ }
46
+ if (node.type === 'group') {
47
+ return (_jsx("li", { "data-slot": "tree-group", role: "none", children: _jsxs("div", { className: "flex flex-col gap-1", children: [node.href === undefined ? (
48
+ /*
49
+ * A group with no index is a tree item that is not a destination, so it
50
+ * carries `role="treeitem"` and its level and nothing else. It is not a
51
+ * bare span: `aria-level` on an element with no role is prohibited
52
+ * rather than ignored, which the accessibility gate caught the first
53
+ * time this was rendered, and a reader needs the level to place a label
54
+ * that has no anchor to place it by.
55
+ */
56
+ _jsx("span", { "data-slot": "tree-label", role: "treeitem", "aria-level": depth + 1, "aria-expanded": node.items.length > 0 ? true : undefined, className: cn('rounded-sm text-sm font-semibold tracking-tight', containsHref(node.items, currentHref) ? 'text-foreground' : 'text-muted-foreground'), children: node.title })) : (_jsx("a", { "data-slot": "tree-heading", href: node.href, role: "treeitem", "aria-level": depth + 1, "aria-expanded": node.items.length > 0 ? true : undefined, "aria-current": currentHref === node.href ? 'page' : undefined, className: cn('hover:text-foreground rounded-sm text-sm font-semibold tracking-tight transition-colors duration-fast ease-out', under(node.href, currentHref) ? 'text-foreground' : 'text-muted-foreground'), children: node.title })), node.items.length > 0 ? (_jsx(TreeLevel, { nodes: node.items, currentHref: currentHref, depth: depth + 1 })) : null] }) }));
57
+ }
58
+ return (_jsx("li", { "data-slot": "tree-item", role: "none", children: _jsx("a", { "data-slot": "tree-link", href: node.href,
59
+ // A destination in a tree is a `treeitem`, not a link with a level hung
60
+ // off it: the level belongs to the item, and a reader placing it in the
61
+ // tree is reading the item rather than the anchor inside it.
62
+ role: "treeitem", "aria-level": depth + 1, "aria-current": currentHref === node.href ? 'page' : undefined, className: cn('-ms-px block border-l-2 py-1 ps-3 text-sm transition-colors duration-fast ease-out', currentHref === node.href
63
+ ? 'text-foreground border-primary font-medium'
64
+ : 'text-muted-foreground hover:text-foreground border-transparent'), children: node.title }) }));
65
+ }
66
+ /**
67
+ * A tree of nodes, given as data.
68
+ *
69
+ * This is the third of the three primitives the expansion found missing, and the
70
+ * one with a different kind of work behind it: the implementation already existed
71
+ * as two private renderers inside the documentation Page, with its depth rule, its
72
+ * `aria-current` marking and its rule that a group with no index renders a label.
73
+ * What was missing was that it was unreachable, and that its data type was bound
74
+ * to documentation navigation rather than being a tree's own vocabulary. So this is
75
+ * a promotion rather than a second implementation, and the reasoning in the
76
+ * documentation Page is carried across rather than rewritten.
77
+ *
78
+ * **A flat list renders a flat tree.** An outline is a tree of depth one, so a
79
+ * caller passes leaves and gets leaves. A Component that required nesting to
80
+ * express a flat structure would make the common case the awkward one.
81
+ *
82
+ * **The Page keeps its own renderers and does not change.** Its two rules, that a
83
+ * section carries no status or count and that a group with no index is a label,
84
+ * are specific to a documentation rail and are reasoned at length in the design
85
+ * rules. A documentation rail is one shape a tree takes, not the shape. Whether the
86
+ * Page composes this Component later is a decision this ticket does not make.
87
+ */
88
+ function Tree({ nodes, currentHref, label, className, empty }) {
89
+ const root = useRef(null);
90
+ /**
91
+ * The keyboard model, and the reason it lives here rather than in a caller's.
92
+ *
93
+ * A tree is one Tab stop, and the arrow keys move inside it. That is the ARIA
94
+ * pattern, and a consumer who composes the markup themselves gets the Tab order
95
+ * of the document instead, which is every node in the tree and none of the
96
+ * arrows. A roving tabindex is the mechanism: one node is tabbable at a time and
97
+ * the arrows move which one.
98
+ *
99
+ * The flat order is collected from the DOM rather than computed from the node
100
+ * data, because the DOM is what a reader actually moves through and computing a
101
+ * second order from the data is a second list to fall behind the first. Only
102
+ * focusable nodes take part, so a label that is not a destination is skipped
103
+ * rather than focused and doing nothing.
104
+ */
105
+ const onKeyDown = (event) => {
106
+ const keys = ['ArrowDown', 'ArrowUp', 'Home', 'End'];
107
+ if (!keys.includes(event.key))
108
+ return;
109
+ const root_ = root.current;
110
+ if (root_ === null)
111
+ return;
112
+ const items = [
113
+ ...root_.querySelectorAll('[data-slot="tree-link"], [data-slot="tree-heading"]'),
114
+ ];
115
+ if (items.length === 0)
116
+ return;
117
+ const at = items.indexOf(document.activeElement);
118
+ if (at === -1)
119
+ return;
120
+ event.preventDefault();
121
+ const next = event.key === 'ArrowDown'
122
+ ? Math.min(at + 1, items.length - 1)
123
+ : event.key === 'ArrowUp'
124
+ ? Math.max(at - 1, 0)
125
+ : event.key === 'Home'
126
+ ? 0
127
+ : items.length - 1;
128
+ items[next]?.focus();
129
+ };
130
+ if (nodes.length === 0) {
131
+ // A tree that renders nothing is a control with nothing in it, so the empty
132
+ // case is authored rather than left for a caller to notice.
133
+ return (_jsxs("div", { "data-slot": "tree-empty", className: cn('text-muted-foreground text-sm', className), children: [empty?.message ?? null, empty?.action] }));
134
+ }
135
+ return (_jsx("div", { "data-slot": "tree", ref: root, role: "tree", "aria-label": label, onKeyDown: onKeyDown, className: cn('flex flex-col', className), children: _jsx(TreeLevel, { nodes: nodes, currentHref: currentHref, depth: 0 }) }));
136
+ }
137
+ export { Tree };
package/dist/styles.css CHANGED
@@ -635,6 +635,9 @@
635
635
  --tw-translate-y: var(--spacing-0\.5);
636
636
  translate: var(--tw-translate-x) var(--tw-translate-y);
637
637
  }
638
+ .transform {
639
+ transform: var(--tw-rotate-x,) var(--tw-rotate-y,) var(--tw-rotate-z,) var(--tw-skew-x,) var(--tw-skew-y,);
640
+ }
638
641
  .cursor-default {
639
642
  cursor: default;
640
643
  }
@@ -1002,6 +1005,9 @@
1002
1005
  .p-6 {
1003
1006
  padding: var(--spacing-6);
1004
1007
  }
1008
+ .px-0\.5 {
1009
+ padding-inline: var(--spacing-0\.5);
1010
+ }
1005
1011
  .px-1 {
1006
1012
  padding-inline: var(--spacing-1);
1007
1013
  }
@@ -2624,6 +2630,26 @@
2624
2630
  inherits: false;
2625
2631
  initial-value: 0;
2626
2632
  }
2633
+ @property --tw-rotate-x {
2634
+ syntax: "*";
2635
+ inherits: false;
2636
+ }
2637
+ @property --tw-rotate-y {
2638
+ syntax: "*";
2639
+ inherits: false;
2640
+ }
2641
+ @property --tw-rotate-z {
2642
+ syntax: "*";
2643
+ inherits: false;
2644
+ }
2645
+ @property --tw-skew-x {
2646
+ syntax: "*";
2647
+ inherits: false;
2648
+ }
2649
+ @property --tw-skew-y {
2650
+ syntax: "*";
2651
+ inherits: false;
2652
+ }
2627
2653
  @property --tw-border-style {
2628
2654
  syntax: "*";
2629
2655
  inherits: false;
@@ -2891,6 +2917,11 @@
2891
2917
  --tw-translate-x: 0;
2892
2918
  --tw-translate-y: 0;
2893
2919
  --tw-translate-z: 0;
2920
+ --tw-rotate-x: initial;
2921
+ --tw-rotate-y: initial;
2922
+ --tw-rotate-z: initial;
2923
+ --tw-skew-x: initial;
2924
+ --tw-skew-y: initial;
2894
2925
  --tw-border-style: solid;
2895
2926
  --tw-gradient-position: initial;
2896
2927
  --tw-gradient-from: #0000;
@@ -0,0 +1,98 @@
1
+ # `@nanisoft/prism-ui/gates`
2
+
3
+ The cross-repository laws, as programs, in the package a consumer already pins
4
+ exactly.
5
+
6
+ For four years the five NaniSoft repositories coordinated through a prose
7
+ contract mirrored in four files. It drifted into three implementations of one rule
8
+ and one of the three rules was false, and it could not be enforced because prose
9
+ cannot fail. This subpath is the replacement: every law is the failure message of
10
+ a gate, and the gate is here, so a change to a law lands once and reaches every
11
+ consumer in one release.
12
+
13
+ ## What a consumer holds, and what the package holds
14
+
15
+ A consumer's repository holds **data**:
16
+
17
+ | the consumer declares | because |
18
+ | --- | --- |
19
+ | its stylesheets | which sheets are its own is a fact about its own pages |
20
+ | its pack map | the regions it allows, and why each one exists |
21
+ | its region resolver | naming a region means knowing its own DOM |
22
+ | its coverage floors | how many rules or routes count as having read something |
23
+ | its destinations known to be broken | one site's content defect, with a reason |
24
+ | its custom properties the build supplies | one site's build, one site's font |
25
+
26
+ The package holds **every law**: what the judgements are, what each failure says,
27
+ and why each one exists. A consumer that restates any of it has two rules that will
28
+ disagree, and the disagreement is invisible until a reader sees the difference.
29
+
30
+ ## Running it
31
+
32
+ ```bash
33
+ pnpm exec prism-gates # every gate prism-gates.json names
34
+ pnpm exec prism-gates --gate=links # one gate
35
+ pnpm exec prism-gates --json # machine-readable, for a test
36
+ ```
37
+
38
+ In a consumer's `package.json`:
39
+
40
+ ```json
41
+ {
42
+ "scripts": {
43
+ "check:gates": "prism-gates"
44
+ }
45
+ }
46
+ ```
47
+
48
+ And in `prism-gates.json`, at the repository root:
49
+
50
+ ```json
51
+ {
52
+ "gateKit": 1,
53
+ "gates": ["pin", "retired-line", "stylesheet-ownership", "links", "hidden-state"],
54
+ "stylesheet-ownership": { "sheets": ["app/globals.css"], "minDeclarations": 20 },
55
+ "links": { "outDir": "out", "minRoutes": 30, "minAnchors": 200 },
56
+ "hidden-state": { "sheets": ["app/globals.css"], "minRules": 25 }
57
+ }
58
+ ```
59
+
60
+ `gateKit` is the generation of the contract the consumer is holding itself to. A
61
+ consumer that does not state one gets the package's current generation, and a law
62
+ rewritten in a later release is then a version the consumer has not moved to rather
63
+ than a silent change of wording underneath it.
64
+
65
+ ## The laws
66
+
67
+ | id | the law |
68
+ | --- | --- |
69
+ | `pin` | the design system is an exact version, and the token package is the component package's dependency rather than the consumer's |
70
+ | `retired-line` | no trace of the retired component library survives |
71
+ | `stylesheet-ownership` | a site stylesheet does not own a surface the design system owns |
72
+ | `token-read` | a custom property that nothing declares is not a wrong colour, it is no declaration at all |
73
+ | `links` | every internal destination resolves and every fragment names an element that exists |
74
+ | `pack-boundary` | a pack boundary lands on a mark, and a declared region set is the whole of what may carry a second pack |
75
+ | `hidden-state` | a CSS-authored hidden state is escapable, and its exit is not a clock |
76
+
77
+ The full text of each, and the failure each one prevents, is in `laws.mjs` and is
78
+ printed by the gate that holds it. It is not restated here on purpose: this file is
79
+ the one place a reader looks when a build is red, and a second copy of a law in a
80
+ second file is a second rule.
81
+
82
+ ## What a gate here cannot do
83
+
84
+ Stated here rather than left for a reader to discover:
85
+
86
+ - **It reads text, not a cascade.** The ownership gate sees a selector and a
87
+ declaration. It does not resolve which rule wins.
88
+ - **It reads the emitted export, not a browser.** The links and pack-boundary gates
89
+ read `out/`. Run the build first; a gate that read nothing fails rather than
90
+ reporting a clean page.
91
+ - **It does not see a runtime.** A `data-pack` attribute set after paint, or a
92
+ token read in client code, is outside every gate in this kit.
93
+ - **A stylesheet half is not a rendered half.** A consumer that ships a hidden
94
+ state also needs a test that renders with scripting switched off.
95
+
96
+ These limits are printed on every run as well, because a gate that appeared to
97
+ resolve cascades and did not would be worse than no gate: it would retire the
98
+ question.
package/gates/cli.mjs ADDED
@@ -0,0 +1,133 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * The consumer's gate chain. One program, one configuration file, one exit code.
4
+ *
5
+ * A consumer's repository holds data: its roots, its sheet, its pack map, its
6
+ * coverage floors, its destinations it knows are broken. It does not hold the
7
+ * wording of a rule, because a wording held in four places is four rules that will
8
+ * disagree, and the version they disagree at is the version nobody chose.
9
+ *
10
+ * pnpm prism-gates # every gate the configuration names
11
+ * pnpm prism-gates --gate=links # one gate
12
+ * pnpm prism-gates --gate=links --json # machine-readable, for a test
13
+ *
14
+ * `--json` exists because the assertion that matters about a gate is not that it
15
+ * passed: it is that it went red on a defect it can see. A test cannot watch a
16
+ * human-readable exit code and be sure it saw the failure it planted, so the
17
+ * machine form carries the findings and the coverage the run achieved.
18
+ *
19
+ * **The exit code is the contract.** 0 means every named gate ran and found
20
+ * nothing. 1 means a gate found something. 2 means a gate could not read what it
21
+ * was pointed at, which is a different answer from "clean" and is never reported
22
+ * as 0. A gate that read nothing and exited 0 is the failure this program exists
23
+ * to make impossible, and it is why the coverage floors live in the gates rather
24
+ * than in the consumer's expectations.
25
+ */
26
+ import process from 'node:process'
27
+ import path from 'node:path'
28
+
29
+ import { GATE_IDS, GATE_KIT_VERSION, gate, laws } from './index.mjs'
30
+ import { CoverageError, readJson } from './run.mjs'
31
+
32
+ const CONFIG_NAME = 'prism-gates.json'
33
+
34
+ const flag = (name) => process.argv.find((argument) => argument.startsWith(`--${name}=`))?.slice(name.length + 3)
35
+ const has = (name) => process.argv.includes(`--${name}`)
36
+
37
+ async function main() {
38
+ const root = path.resolve(process.cwd())
39
+ const configPath = flag('config') ?? CONFIG_NAME
40
+ const json = has('json')
41
+ const only = flag('gate')
42
+
43
+ let config
44
+ try {
45
+ config = readJson(root, configPath)
46
+ } catch (cause) {
47
+ return fail(`error prism-gates: ${cause.message}`)
48
+ }
49
+ if (!config) {
50
+ return fail(
51
+ `error prism-gates: ${path.join(root, configPath)} does not resolve.\n` +
52
+ ' A gate chain with no configuration is a chain that runs nothing, and nothing looks like a pass.\n' +
53
+ ' The configuration holds this repository\'s own data only: its roots, its sheet, its pack map, its\n' +
54
+ ' coverage floors. The laws are not in it, because they are in the package.',
55
+ )
56
+ }
57
+
58
+ const named = only ? [only] : (config.gates ?? [])
59
+ if (named.length === 0) {
60
+ return fail(
61
+ `error prism-gates: ${configPath} names no gates, so this run enforced nothing.\n` +
62
+ ` A chain that runs nothing exits the same as a chain that found nothing, which is the answer this\n` +
63
+ ` program exists to stop giving. The kit ships: ${GATE_IDS.join(', ')}.`,
64
+ )
65
+ }
66
+
67
+ const results = []
68
+ let findings = 0
69
+ let unreadable = 0
70
+
71
+ for (const id of named) {
72
+ const settings = config[id] ?? {}
73
+ try {
74
+ const { run } = await gate(id)
75
+ const result = await run({ root, config: settings })
76
+ findings += result.findings.length
77
+ results.push({ gate: id, law: result.law.id, ok: result.findings.length === 0, findings: result.findings, notes: result.notes, also: (result.also ?? []).map((l) => l.id) })
78
+ } catch (cause) {
79
+ unreadable += 1
80
+ const message =
81
+ cause instanceof CoverageError
82
+ ? `error prism-gates: ${id}: ${cause.message}`
83
+ : `error prism-gates: ${id} could not run: ${cause.stack ?? cause.message}`
84
+ if (json) {
85
+ results.push({ gate: id, ok: false, unreadable: true, findings: [], notes: [message] })
86
+ } else {
87
+ console.error(message)
88
+ }
89
+ }
90
+ }
91
+
92
+ if (json) {
93
+ console.log(
94
+ JSON.stringify(
95
+ { gateKit: GATE_KIT_VERSION, laws: laws().map((l) => l.id), results },
96
+ null,
97
+ 2,
98
+ ),
99
+ )
100
+ return findings > 0 || unreadable > 0 ? 1 : 0
101
+ }
102
+
103
+ for (const result of results) {
104
+ if (result.unreadable) continue
105
+ for (const line of result.notes) console.log(line)
106
+ for (const line of result.findings) console.error(line)
107
+ if (result.findings.length > 0) {
108
+ const law = laws().find((l) => l.id === result.law)
109
+ console.error(`\n${law.title}`)
110
+ console.error(law.message)
111
+ console.error(` It is here because: ${law.why}`)
112
+ }
113
+ }
114
+
115
+ console.log(
116
+ `\nprism-gates: gate kit ${GATE_KIT_VERSION}, ${named.length} gate(s) run, ${findings} finding(s), ` +
117
+ `${unreadable} unreadable`,
118
+ )
119
+ console.log(`prism-gates: the laws this run enforced: ${laws().map((l) => l.id).join(', ')}`)
120
+ console.log(
121
+ 'prism-gates: the wording of every law above is in the package you pinned, not in this repository. A change\n' +
122
+ ' to it reaches this repository in one release and cannot be declined here.',
123
+ )
124
+
125
+ return findings > 0 || unreadable > 0 ? 1 : 0
126
+ }
127
+
128
+ function fail(message) {
129
+ console.error(message)
130
+ return 2
131
+ }
132
+
133
+ process.exitCode = await main()