@lanfermann/ui 0.5.0 → 0.6.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 (165) hide show
  1. package/dist/components/action-bar/action-bar.d.ts +59 -0
  2. package/dist/components/action-bar/action-bar.js +116 -0
  3. package/dist/components/alert/alert.d.ts +1 -1
  4. package/dist/components/alert/alert.js +3 -17
  5. package/dist/components/alert-dialog/alert-dialog.d.ts +1 -1
  6. package/dist/components/app-shell/app-shell.d.ts +33 -0
  7. package/dist/components/app-shell/app-shell.js +93 -0
  8. package/dist/components/attachment/attachment.d.ts +46 -0
  9. package/dist/components/attachment/attachment.js +222 -0
  10. package/dist/components/attachment/kinds.d.ts +7 -0
  11. package/dist/components/attachment/kinds.js +100 -0
  12. package/dist/components/avatar/avatar.d.ts +14 -4
  13. package/dist/components/avatar/avatar.js +57 -13
  14. package/dist/components/avatar-group/avatar-group.d.ts +33 -0
  15. package/dist/components/avatar-group/avatar-group.js +110 -0
  16. package/dist/components/avatar-group/people.d.ts +12 -0
  17. package/dist/components/avatar-group/people.js +24 -0
  18. package/dist/components/badge/badge.d.ts +9 -3
  19. package/dist/components/badge/badge.js +21 -6
  20. package/dist/components/banner/banner.d.ts +39 -0
  21. package/dist/components/banner/banner.js +149 -0
  22. package/dist/components/card/card.d.ts +11 -3
  23. package/dist/components/card/card.js +18 -4
  24. package/dist/components/checkbox-card/checkbox-card.d.ts +21 -0
  25. package/dist/components/checkbox-card/checkbox-card.js +49 -0
  26. package/dist/components/chip/chip-group.d.ts +15 -0
  27. package/dist/components/chip/chip-group.js +44 -0
  28. package/dist/components/chip/chip-variants.d.ts +6 -0
  29. package/dist/components/chip/chip-variants.js +28 -0
  30. package/dist/components/chip/chip.d.ts +39 -0
  31. package/dist/components/chip/chip.js +71 -0
  32. package/dist/components/code-block/code-copy.d.ts +3 -11
  33. package/dist/components/code-block/code-copy.js +15 -62
  34. package/dist/components/code-block/code-keys.js +10 -22
  35. package/dist/components/combobox/combobox.d.ts +50 -2
  36. package/dist/components/combobox/combobox.js +178 -9
  37. package/dist/components/command/command.d.ts +131 -0
  38. package/dist/components/command/command.js +335 -0
  39. package/dist/components/consent/consent-card.js +365 -0
  40. package/dist/components/consent/consent-embed.d.ts +21 -0
  41. package/dist/components/consent/consent-embed.js +111 -0
  42. package/dist/components/consent/consent-labels.d.ts +70 -0
  43. package/dist/components/consent/consent-labels.js +61 -0
  44. package/dist/components/consent/consent-record.d.ts +95 -0
  45. package/dist/components/consent/consent-record.js +112 -0
  46. package/dist/components/consent/consent-store.d.ts +26 -0
  47. package/dist/components/consent/consent-store.js +240 -0
  48. package/dist/components/consent/consent.d.ts +86 -0
  49. package/dist/components/consent/consent.js +306 -0
  50. package/dist/components/container/container.d.ts +1 -1
  51. package/dist/components/context-menu/context-menu.d.ts +23 -0
  52. package/dist/components/context-menu/context-menu.js +50 -0
  53. package/dist/components/conversation/conversation.d.ts +45 -0
  54. package/dist/components/conversation/conversation.js +295 -0
  55. package/dist/components/conversation/stick.js +23 -0
  56. package/dist/components/copy-button/copy-button.d.ts +50 -0
  57. package/dist/components/copy-button/copy-button.js +65 -0
  58. package/dist/components/copy-page/copy-page.js +7 -17
  59. package/dist/components/copy-pill/copy-pill.js +1 -1
  60. package/dist/components/description-list/description-list.d.ts +32 -0
  61. package/dist/components/description-list/description-list.js +51 -0
  62. package/dist/components/empty/empty.d.ts +38 -0
  63. package/dist/components/empty/empty.js +57 -0
  64. package/dist/components/field/field.js +1 -1
  65. package/dist/components/file-upload/file-upload.d.ts +96 -0
  66. package/dist/components/file-upload/file-upload.js +347 -0
  67. package/dist/components/file-upload/files.d.ts +39 -0
  68. package/dist/components/file-upload/files.js +74 -0
  69. package/dist/components/grow/grow.d.ts +15 -3
  70. package/dist/components/grow/grow.js +24 -9
  71. package/dist/components/heading/heading.d.ts +1 -1
  72. package/dist/components/icon/icon.d.ts +1 -1
  73. package/dist/components/input/input.js +1 -1
  74. package/dist/components/message/message.d.ts +73 -0
  75. package/dist/components/message/message.js +196 -0
  76. package/dist/components/otp-field/otp-field.d.ts +37 -0
  77. package/dist/components/otp-field/otp-field.js +126 -0
  78. package/dist/components/pagination/pagination.d.ts +50 -0
  79. package/dist/components/pagination/pagination.js +188 -0
  80. package/dist/components/prompt-input/keys.js +15 -0
  81. package/dist/components/prompt-input/prompt-input.d.ts +89 -0
  82. package/dist/components/prompt-input/prompt-input.js +331 -0
  83. package/dist/components/radio-card/radio-card.d.ts +23 -0
  84. package/dist/components/radio-card/radio-card.js +48 -0
  85. package/dist/components/rolling-number/rolling-number.d.ts +30 -0
  86. package/dist/components/rolling-number/rolling-number.js +149 -0
  87. package/dist/components/seam/seam.d.ts +1 -1
  88. package/dist/components/secret-field/secret-field.d.ts +53 -0
  89. package/dist/components/secret-field/secret-field.js +121 -0
  90. package/dist/components/section/section.d.ts +1 -1
  91. package/dist/components/select/select.d.ts +1 -1
  92. package/dist/components/select/select.js +1 -1
  93. package/dist/components/shortcut/shortcut.d.ts +46 -0
  94. package/dist/components/shortcut/shortcut.js +87 -0
  95. package/dist/components/sidebar/sidebar-context.js +16 -0
  96. package/dist/components/sidebar/sidebar.d.ts +161 -0
  97. package/dist/components/sidebar/sidebar.js +588 -0
  98. package/dist/components/site-header/site-header.js +1 -1
  99. package/dist/components/skeleton/loaded.d.ts +21 -0
  100. package/dist/components/skeleton/loaded.js +57 -0
  101. package/dist/components/skeleton/skeleton.d.ts +43 -0
  102. package/dist/components/skeleton/skeleton.js +48 -0
  103. package/dist/components/sources/source-list.d.ts +17 -0
  104. package/dist/components/sources/source-list.js +26 -0
  105. package/dist/components/sources/sources.d.ts +45 -0
  106. package/dist/components/sources/sources.js +167 -0
  107. package/dist/components/stat/stat.d.ts +57 -0
  108. package/dist/components/stat/stat.js +110 -0
  109. package/dist/components/steps/steps.d.ts +57 -0
  110. package/dist/components/steps/steps.js +131 -0
  111. package/dist/components/table/table.d.ts +18 -9
  112. package/dist/components/table/table.js +21 -13
  113. package/dist/components/text/text.d.ts +1 -1
  114. package/dist/components/theme-switch/theme-switch.js +1 -1
  115. package/dist/components/time-field/time-field.js +1 -1
  116. package/dist/components/timeline/timeline.d.ts +45 -0
  117. package/dist/components/timeline/timeline.js +86 -0
  118. package/dist/components/toast/toast.js +10 -26
  119. package/dist/components/toggle/toggle.d.ts +24 -0
  120. package/dist/components/toggle/toggle.js +53 -0
  121. package/dist/components/toggle-group/toggle-group.d.ts +27 -0
  122. package/dist/components/toggle-group/toggle-group.js +38 -0
  123. package/dist/components/toolbar/toolbar-context.js +12 -0
  124. package/dist/components/toolbar/toolbar.d.ts +45 -0
  125. package/dist/components/toolbar/toolbar.js +92 -0
  126. package/dist/components/trace/trace.d.ts +2 -1
  127. package/dist/components/trace/trace.js +14 -26
  128. package/dist/index.d.ts +46 -3
  129. package/dist/index.js +44 -3
  130. package/dist/internal/arriving-pieces.js +56 -0
  131. package/dist/internal/arriving.js +171 -0
  132. package/dist/internal/avatar-cut.d.ts +15 -0
  133. package/dist/internal/avatar-cut.js +83 -0
  134. package/dist/internal/choice-card.d.ts +15 -0
  135. package/dist/internal/choice-card.js +65 -0
  136. package/dist/internal/clipboard.js +37 -0
  137. package/dist/internal/copy.js +58 -0
  138. package/dist/internal/field.js +24 -4
  139. package/dist/internal/glyphs.js +26 -1
  140. package/dist/internal/live-list.js +41 -0
  141. package/dist/internal/number-places.js +156 -0
  142. package/dist/internal/picker-sheet.js +1 -1
  143. package/dist/internal/presence-dot.js +24 -0
  144. package/dist/internal/presence.js +104 -0
  145. package/dist/internal/rail-mark.d.ts +3 -0
  146. package/dist/internal/rail-mark.js +33 -0
  147. package/dist/internal/status-icon.js +22 -0
  148. package/dist/internal/travelling-mark.js +204 -0
  149. package/dist/lib/cn.js +4 -0
  150. package/dist/lib/shortcut.d.ts +11 -0
  151. package/dist/lib/shortcut.js +165 -0
  152. package/package.json +1 -1
  153. package/src/styles/action-bar.css +28 -0
  154. package/src/styles/assistant.css +83 -0
  155. package/src/styles/avatar.css +24 -0
  156. package/src/styles/consent.css +65 -0
  157. package/src/styles/copy.css +12 -11
  158. package/src/styles/depth.css +46 -2
  159. package/src/styles/marks.css +20 -2
  160. package/src/styles/rail.css +49 -0
  161. package/src/styles/rolling-number.css +94 -0
  162. package/src/styles/steps.css +98 -0
  163. package/src/styles/timeline.css +48 -0
  164. package/src/styles/travel.css +36 -0
  165. package/src/styles.css +9 -0
@@ -0,0 +1,171 @@
1
+ "use client";
2
+ import { advancePieces, staggerDelays } from "./arriving-pieces.js";
3
+ import { useReducedMotion } from "./reduced-motion.js";
4
+ import { jsx } from "react/jsx-runtime";
5
+ import { Fragment as Fragment$1, cloneElement, isValidElement, useEffect, useLayoutEffect, useRef, useState } from "react";
6
+ // src/internal/arriving.tsx
7
+ /**
8
+ * Pieces of one look fade in this far apart at most, and all within this span (ms). Fading in
9
+ * by words was chosen over a line at a time, once it is full (Justin, 2026-11-19).
10
+ */
11
+ const WORD_STEP = 40;
12
+ const SPAN = 240;
13
+ /** Elements whose text arrives whole: code, pictures, formulas, form controls. */
14
+ const whole = /* @__PURE__ */ new Set([
15
+ "pre",
16
+ "svg",
17
+ "math",
18
+ "script",
19
+ "style",
20
+ "textarea",
21
+ "select"
22
+ ]);
23
+ /**
24
+ * The look of a piece. `data-arriving` is never rendered: the engine sets it on a new piece
25
+ * before it is painted and takes it away when its fade begins.
26
+ */
27
+ const pieceLook = "transition-opacity spring-settle data-arriving:opacity-0";
28
+ /** The caller's tree with each string handed to `visit`; everything else as it was. */
29
+ function walk(node, path, visit) {
30
+ if (typeof node === "string") return visit(node, path);
31
+ if (typeof node === "number" || typeof node === "bigint") return visit(String(node), path);
32
+ if (Array.isArray(node)) return node.map((child, index) => walk(child, `${path}.${index}`, visit));
33
+ if (!isValidElement(node)) return node;
34
+ const element = node;
35
+ const { type } = element;
36
+ const children = element.props.children;
37
+ if (children === void 0 || children === null || typeof children === "boolean") return node;
38
+ if (typeof children === "function") return node;
39
+ if (typeof type === "string") {
40
+ if (whole.has(type)) return node;
41
+ } else if (type !== Fragment$1 && typeof children === "string") {
42
+ if (!type.carriesText) return node;
43
+ }
44
+ if (Array.isArray(children)) {
45
+ const walked = children.map((child, index) => walk(child, `${path}.${index}`, visit));
46
+ return cloneElement(element, void 0, ...walked);
47
+ }
48
+ return cloneElement(element, void 0, walk(children, `${path}.0`, visit));
49
+ }
50
+ /** Every string of a tree by its place in it, in reading order. */
51
+ function textsOf(children) {
52
+ const texts = /* @__PURE__ */ new Map();
53
+ walk(children, "t", (text, path) => {
54
+ texts.set(path, text);
55
+ return null;
56
+ });
57
+ return texts;
58
+ }
59
+ /** The first look: everything there is shown at once. */
60
+ function firstLook(children, streaming) {
61
+ const texts = /* @__PURE__ */ new Map();
62
+ for (const [path, text] of textsOf(children)) texts.set(path, text.length > 0 ? {
63
+ ends: [text.length],
64
+ born: [0]
65
+ } : {
66
+ ends: [],
67
+ born: []
68
+ });
69
+ return {
70
+ source: children,
71
+ streaming,
72
+ generation: 0,
73
+ texts
74
+ };
75
+ }
76
+ /** The next look: what is new since the last one becomes pieces of this one. */
77
+ function nextLook(before, children, streaming) {
78
+ const generation = before.generation + 1;
79
+ const strings = textsOf(children);
80
+ const last = [...strings.keys()].at(-1);
81
+ const texts = /* @__PURE__ */ new Map();
82
+ for (const [path, text] of strings) {
83
+ const old = before.texts.get(path) ?? {
84
+ ends: [],
85
+ born: []
86
+ };
87
+ const { ends, fresh } = advancePieces(old.ends, text, { complete: !streaming || path !== last });
88
+ const born = [...old.born.slice(0, fresh), ...ends.slice(fresh).map(() => generation)];
89
+ texts.set(path, {
90
+ ends,
91
+ born
92
+ });
93
+ }
94
+ return {
95
+ source: children,
96
+ streaming,
97
+ generation,
98
+ texts
99
+ };
100
+ }
101
+ /** The caller's tree with its strings cut into the pieces of a look. */
102
+ function draw(children, look) {
103
+ return walk(children, "t", (text, path) => {
104
+ const shown = look.texts.get(path);
105
+ if (!shown) return text;
106
+ let start = 0;
107
+ return /* @__PURE__ */ jsx(Fragment$1, { children: shown.ends.map((end, index) => {
108
+ const piece = /* @__PURE__ */ jsx("span", {
109
+ "data-slot": "message-piece",
110
+ "data-born": shown.born[index],
111
+ className: pieceLook,
112
+ children: text.slice(start, end)
113
+ }, index);
114
+ start = end;
115
+ return piece;
116
+ }) }, path);
117
+ });
118
+ }
119
+ /**
120
+ * Text that is still being written, faded in piece by piece. It takes the tree the caller has
121
+ * rendered (paragraphs, lists, links, from Markdown or not) and cuts each string in it into
122
+ * pieces of a few words; a piece that is new since the last render fades in on `settle`, a few
123
+ * pieces 40ms apart and a burst pressed into 240ms. Nothing travels: the words are being read.
124
+ *
125
+ * What a component draws from its props, or as HTML, arrives whole; so does code. Hand over
126
+ * the rendered elements, not a component that renders the Markdown itself: from the outside
127
+ * its text cannot be seen.
128
+ *
129
+ * What the text holds when it mounts is there at once. Once `streaming` is over and the last
130
+ * piece has faded in, the pieces go and the caller's tree is rendered as it is. Under reduced
131
+ * motion there are no pieces at all.
132
+ */
133
+ function useArrivingText(children, { streaming, box }) {
134
+ const reduced = useReducedMotion();
135
+ const [plain, setPlain] = useState(!streaming);
136
+ const [look, setLook] = useState(() => firstLook(children, streaming));
137
+ if (streaming && plain) {
138
+ setPlain(false);
139
+ setLook(firstLook(children, streaming));
140
+ } else if (!plain && (look.source !== children || look.streaming !== streaming)) setLook(nextLook(look, children, streaming));
141
+ const active = !plain && !reduced;
142
+ /** The last look whose new pieces were set off. */
143
+ const handled = useRef(0);
144
+ useLayoutEffect(() => {
145
+ const root = box.current;
146
+ if (look.generation < handled.current) handled.current = look.generation;
147
+ if (!active || !root || handled.current >= look.generation) return;
148
+ const since = handled.current;
149
+ handled.current = look.generation;
150
+ const fresh = [...root.querySelectorAll("[data-born]")].filter((piece) => Number(piece.dataset.born) > since);
151
+ if (fresh.length === 0) return;
152
+ for (const piece of fresh) piece.setAttribute("data-arriving", "");
153
+ root.offsetHeight;
154
+ const delays = staggerDelays(fresh.length, WORD_STEP, SPAN);
155
+ fresh.forEach((piece, index) => {
156
+ piece.style.transitionDelay = `${delays[index] ?? 0}ms`;
157
+ piece.removeAttribute("data-arriving");
158
+ });
159
+ }, [
160
+ active,
161
+ look,
162
+ box
163
+ ]);
164
+ useEffect(() => {
165
+ if (streaming || plain) return;
166
+ const timer = window.setTimeout(() => setPlain(true), 840);
167
+ return () => window.clearTimeout(timer);
168
+ }, [streaming, plain]);
169
+ return active ? draw(children, look) : children;
170
+ }
171
+ export { useArrivingText };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The cut-out that parts two avatars: the gap between them is not a ring in the colour of the
3
+ * ground, it is cut out of the avatar underneath, so it is right on every ground, on a washed
4
+ * table row and over a picture. Avatars are round, and the outline of a circle grown by the gap
5
+ * is a circle the gap larger: the cut follows the avatar in front at a constant distance, and
6
+ * what is seen of the one underneath is a clean crescent.
7
+ *
8
+ * A presence dot stands on the edge of its avatar, half outside it, and is cut out of the avatar
9
+ * the same way, in a circle the gap larger than the dot; the avatar underneath has a hole for
10
+ * the dot of the one in front as well, so the dot never touches it.
11
+ *
12
+ * Each cut is one SVG for the avatar's own box, used as its mask: it moves and scales with the
13
+ * avatar and is drawn in whole pixels. Server-safe; the numbers are pixels at a 16px root.
14
+ */
15
+ export type AvatarSize = "sm" | "md" | "lg" | "xl";
@@ -0,0 +1,83 @@
1
+ // src/internal/avatar-cut.ts
2
+ /** The avatar of each size: its diameter and the diameter of its presence dot. */
3
+ const avatarGeometry = {
4
+ sm: {
5
+ size: 24,
6
+ dot: 6
7
+ },
8
+ md: {
9
+ size: 28,
10
+ dot: 8
11
+ },
12
+ lg: {
13
+ size: 36,
14
+ dot: 10
15
+ },
16
+ xl: {
17
+ size: 48,
18
+ dot: 12
19
+ }
20
+ };
21
+ /**
22
+ * How far one avatar lies over the next, in pixels: a quarter of it, so a face stays a face
23
+ * (Justin, 2026-11-19, over a third).
24
+ */
25
+ const avatarOverlap = {
26
+ sm: 6,
27
+ md: 7,
28
+ lg: 9,
29
+ xl: 12
30
+ };
31
+ /** Where a presence dot stands in an avatar's box: on its edge, in the bottom end corner. */
32
+ function dotCentre(size, dot) {
33
+ return size - dot / 2;
34
+ }
35
+ /** The circles cut out of an avatar, in its own pixels. */
36
+ function cutShapes({ size, gap, step, dot, frontDot, rtl }) {
37
+ const circles = [];
38
+ if (step !== void 0) {
39
+ circles.push({
40
+ cx: size / 2 - step,
41
+ cy: size / 2,
42
+ r: size / 2 + gap
43
+ });
44
+ if (frontDot !== void 0) {
45
+ const at = dotCentre(size, frontDot);
46
+ circles.push({
47
+ cx: at - step,
48
+ cy: at,
49
+ r: frontDot / 2 + gap
50
+ });
51
+ }
52
+ }
53
+ if (dot !== void 0) {
54
+ const at = dotCentre(size, dot);
55
+ circles.push({
56
+ cx: at,
57
+ cy: at,
58
+ r: dot / 2 + gap
59
+ });
60
+ }
61
+ return rtl ? circles.map((circle) => ({
62
+ ...circle,
63
+ cx: size - circle.cx
64
+ })) : circles;
65
+ }
66
+ const masks = /* @__PURE__ */ new Map();
67
+ /**
68
+ * The mask of one avatar as a CSS `url()`, or `undefined` when nothing is cut out of it. Black
69
+ * circles in an SVG `<mask>` rather than holes in one path, so two cuts that overlap stay cut.
70
+ */
71
+ function cutMask(options) {
72
+ const key = JSON.stringify(options);
73
+ const cached = masks.get(key);
74
+ if (cached) return cached;
75
+ const circles = cutShapes(options);
76
+ if (circles.length === 0) return void 0;
77
+ const { size } = options;
78
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="0 0 ${size} ${size}"><mask id="m"><rect width="${size}" height="${size}" fill="#fff"/><g fill="#000">${circles.map((circle) => `<circle cx="${circle.cx}" cy="${circle.cy}" r="${circle.r}"/>`).join("")}</g></mask><rect width="${size}" height="${size}" mask="url(#m)"/></svg>`;
79
+ const mask = `url("data:image/svg+xml,${encodeURIComponent(svg)}")`;
80
+ masks.set(key, mask);
81
+ return mask;
82
+ }
83
+ export { avatarGeometry, avatarOverlap, cutMask, cutShapes, dotCentre };
@@ -0,0 +1,15 @@
1
+ import { IconSvgElement } from "../components/icon/icon.js";
2
+ import { ReactNode } from "react";
3
+ /** What a card that is a choice says about itself. */
4
+ export type ChoiceCardText = {
5
+ /** The choice, in a word or two: "Team", "Rechnungen schreiben". It names the control. */
6
+ title: ReactNode;
7
+ /** One sentence on what choosing it means. It describes the control. */
8
+ description?: ReactNode;
9
+ /** A second fact at the end of the first line, in tabular digits: a price, a number. */
10
+ detail?: ReactNode;
11
+ /** A 16px symbol before the title. Give every card of a group one or none. */
12
+ icon?: IconSvgElement;
13
+ /** More that belongs to the choice, under its sentence: a short list, a `Badge`. */
14
+ children?: ReactNode;
15
+ };
@@ -0,0 +1,65 @@
1
+ import { Icon } from "../components/icon/icon.js";
2
+ import { cn } from "../lib/cn.js";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
+ // src/internal/choice-card.tsx
5
+ /**
6
+ * The card around a radio or a checkbox: a softly raised sheet that is the control's label, so
7
+ * the whole of it is the target. The sheet keeps its size and answers with its shadow: a
8
+ * little higher under the pointer, down on the page under a press, while its mark dips as a
9
+ * plain `Radio` or `Checkbox` does. (The whole card going down to the press scale moved a wide
10
+ * sheet by ten pixels and was too heavy: Justin, 2026-11-19.) It takes the accent outline when
11
+ * the keyboard is on its control, and lies flat when the control is disabled. State is read
12
+ * from the control inside, which carries `data-slot="choice-control"`.
13
+ */
14
+ const choiceCard = [
15
+ "group/card relative flex cursor-pointer items-start gap-3 rounded-xl bg-surface p-4 text-left depth-card select-none",
16
+ "transition-[box-shadow] spring-leave not-active:has-[[data-slot=choice-control][data-checked]]:spring-settle active:spring-snap",
17
+ "not-has-[[data-slot=choice-control][data-disabled]]:hover:shadow-card-hover not-has-[[data-slot=choice-control][data-disabled]]:active:shadow-card-pressed",
18
+ "has-[[data-slot=choice-control]:focus-visible]:outline-2 has-[[data-slot=choice-control]:focus-visible]:outline-offset-2 has-[[data-slot=choice-control]:focus-visible]:outline-accent",
19
+ "has-[[data-slot=choice-control][data-disabled]]:cursor-default has-[[data-slot=choice-control][data-disabled]]:bg-disabled has-[[data-slot=choice-control][data-disabled]]:depth-flat"
20
+ ].join(" ");
21
+ /** The chosen card wears the accent as its edge; it eases in on the card's own transition. */
22
+ const choiceCardEdge = "has-[[data-slot=choice-control][data-checked]]:depth-card-chosen";
23
+ /**
24
+ * The control inside the card: a box of the check size on the title's first line. The card
25
+ * around it takes the presses and shows the focus, so the control gives both up; it dips
26
+ * while the card is pressed, by as much as a plain `Radio` does under its own press.
27
+ */
28
+ const choiceControl = [
29
+ "group/control pointer-events-none mt-0.5 flex size-(--check-size) shrink-0 items-center justify-center outline-hidden",
30
+ "transition-[scale] spring-seat group-active/card:scale-[0.92] group-active/card:spring-snap",
31
+ "data-disabled:scale-100"
32
+ ].join(" ");
33
+ /** The words of the card, beside its control. */
34
+ function ChoiceCardBody({ slot, titleId, descriptionId, title, description, detail, icon, children }) {
35
+ return /* @__PURE__ */ jsxs("span", {
36
+ className: "flex min-w-0 flex-1 flex-col gap-0.5",
37
+ children: [
38
+ /* @__PURE__ */ jsxs("span", {
39
+ className: "flex items-baseline gap-3",
40
+ children: [/* @__PURE__ */ jsxs("span", {
41
+ id: titleId,
42
+ "data-slot": `${slot}-title`,
43
+ className: cn("flex min-w-0 items-center gap-2 text-control font-medium text-fg", "group-has-[[data-disabled]]/card:text-on-disabled"),
44
+ children: [icon && /* @__PURE__ */ jsx(Icon, {
45
+ icon,
46
+ size: 16,
47
+ className: "shrink-0 text-fg-muted"
48
+ }), title]
49
+ }), detail !== void 0 && /* @__PURE__ */ jsx("span", {
50
+ "data-slot": `${slot}-detail`,
51
+ className: "ml-auto shrink-0 text-control whitespace-nowrap text-fg-body tabular-nums group-has-[[data-disabled]]/card:text-on-disabled",
52
+ children: detail
53
+ })]
54
+ }),
55
+ description !== void 0 && /* @__PURE__ */ jsx("span", {
56
+ id: descriptionId,
57
+ "data-slot": `${slot}-description`,
58
+ className: "text-sm text-pretty text-fg-muted group-has-[[data-disabled]]/card:text-on-disabled",
59
+ children: description
60
+ }),
61
+ children
62
+ ]
63
+ });
64
+ }
65
+ export { ChoiceCardBody, choiceCard, choiceCardEdge, choiceControl };
@@ -0,0 +1,37 @@
1
+ // src/internal/clipboard.ts
2
+ /**
3
+ * Puts text on the clipboard, or rejects when the browser refuses.
4
+ *
5
+ * The text may still be on its way (a page being fetched). A browser only lets a press write to
6
+ * the clipboard, and a write that waits for the text first has left the press by the time it
7
+ * comes. Where the browser takes a promise for the clipboard (Safari, Chrome), the promise is
8
+ * handed over inside the press and the text follows; elsewhere the write waits for it.
9
+ */
10
+ async function writeClipboard(text) {
11
+ if (typeof text === "string") {
12
+ await navigator.clipboard.writeText(text);
13
+ return;
14
+ }
15
+ try {
16
+ if (typeof ClipboardItem !== "undefined" && typeof navigator.clipboard.write === "function") {
17
+ const blob = text.then((body) => new Blob([body], { type: "text/plain" }));
18
+ await navigator.clipboard.write([new ClipboardItem({ "text/plain": blob })]);
19
+ return;
20
+ }
21
+ } catch {}
22
+ await navigator.clipboard.writeText(await text);
23
+ }
24
+ /**
25
+ * Selects what an element shows, so ⌘C still copies it after the clipboard was refused: the
26
+ * text of a field, or everything inside any other element.
27
+ */
28
+ function selectContents(element) {
29
+ if (!element) return;
30
+ if (element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement) {
31
+ element.focus();
32
+ element.select();
33
+ return;
34
+ }
35
+ window.getSelection()?.selectAllChildren(element);
36
+ }
37
+ export { selectContents, writeClipboard };
@@ -0,0 +1,58 @@
1
+ "use client";
2
+ import { Icon } from "../components/icon/icon.js";
3
+ import { selectContents, writeClipboard } from "./clipboard.js";
4
+ import { TickGlyph } from "./glyphs.js";
5
+ import { jsx, jsxs } from "react/jsx-runtime";
6
+ import { useEffect, useRef, useState } from "react";
7
+ import { Copy01Icon } from "@hugeicons/core-free-icons";
8
+ // src/internal/copy.tsx
9
+ /** How long a copy stays confirmed before the symbol comes back, in ms. */
10
+ const COPY_SHOWN_MS = 1600;
11
+ /**
12
+ * The copy every control performs: write the text, hold the confirmation for a moment, and when
13
+ * the browser refuses, select what was to be copied instead. Draw the state with `CopyMarks`.
14
+ */
15
+ function useCopy({ text, selectTarget, onCopied, onRefused }) {
16
+ const [state, setState] = useState("idle");
17
+ const timer = useRef(void 0);
18
+ useEffect(() => () => clearTimeout(timer.current), []);
19
+ async function copy() {
20
+ clearTimeout(timer.current);
21
+ try {
22
+ await writeClipboard(typeof text === "function" ? text() : text);
23
+ setState("copied");
24
+ onCopied?.();
25
+ } catch {
26
+ onRefused?.();
27
+ selectContents(selectTarget?.current);
28
+ setState("failed");
29
+ }
30
+ timer.current = setTimeout(() => setState("idle"), COPY_SHOWN_MS);
31
+ }
32
+ return {
33
+ state,
34
+ copy
35
+ };
36
+ }
37
+ /**
38
+ * The two marks of a key that confirms: its symbol, and the tick that is drawn in its place
39
+ * (copy.css). The tick keeps the weight of the symbol's stroke at every size.
40
+ */
41
+ function CopyMarks({ copied, icon = Copy01Icon, size = 14 }) {
42
+ return /* @__PURE__ */ jsxs("span", {
43
+ "data-slot": "copy-marks",
44
+ "data-copied": copied ? "" : void 0,
45
+ className: "grid place-items-center *:col-start-1 *:row-start-1",
46
+ children: [/* @__PURE__ */ jsx(Icon, {
47
+ "data-slot": "copy-symbol",
48
+ icon,
49
+ size
50
+ }), /* @__PURE__ */ jsx(TickGlyph, {
51
+ "data-slot": "copy-tick",
52
+ width: size,
53
+ height: size,
54
+ strokeWidth: 21 / size
55
+ })]
56
+ });
57
+ }
58
+ export { COPY_SHOWN_MS, CopyMarks, useCopy };
@@ -7,13 +7,33 @@ const fieldText = ["pointer-coarse:text-base", "placeholder:text-fg-muted placeh
7
7
  * The wrapper that wears the field. The halo follows the control only: a button inside the shell
8
8
  * shows its own focus outline, and the field stays quiet. Invalid beats focus, as on `Input`.
9
9
  */
10
- const fieldShell = [
11
- "group/field relative flex w-full min-w-0 cursor-text items-center pointer-coarse:text-base",
12
- fieldFace,
10
+ const fieldShellStates = [
13
11
  "has-[[data-field-control]:focus]:depth-field-focus",
14
12
  "has-[[data-field-control][data-invalid]]:depth-field-invalid has-[[data-field-control][data-invalid]:focus]:depth-field-invalid",
15
13
  "has-[[data-field-control][data-disabled]]:cursor-default has-[[data-field-control][data-disabled]]:bg-disabled has-[[data-field-control][data-disabled]]:depth-flat has-[[data-field-control][data-disabled]]:text-on-disabled"
16
14
  ].join(" ");
15
+ const fieldShell = [
16
+ "group/field relative flex w-full min-w-0 cursor-text items-center pointer-coarse:text-base",
17
+ fieldFace,
18
+ fieldShellStates
19
+ ].join(" ");
20
+ /**
21
+ * The shell of a field that grows by a line (a multi-select whose chips wrap), for the box of a
22
+ * `Grow`: the face and the states, no height and no layout. What the field holds is laid out on
23
+ * the `Grow`'s inner box, which is the one that is measured. The halo keeps its own transition
24
+ * beside the height's (`--grow-also`).
25
+ */
26
+ const fieldShellGrowing = [
27
+ "group/field relative block w-full min-w-0 cursor-text bg-surface text-control text-fg depth-field pointer-coarse:text-base",
28
+ "[--grow-also:box-shadow_var(--transition-duration-spring-snap)_var(--ease-spring-snap),background-color_var(--transition-duration-spring-snap)_var(--ease-spring-snap)]",
29
+ fieldShellStates
30
+ ].join(" ");
31
+ /** Corner and the field's variables by size, without the fixed height of `fieldShellSize`. */
32
+ const fieldShellGrowingSize = {
33
+ sm: "rounded-sm [--field-height:var(--control-sm)] [--field-pad:var(--field-pad-sm)] [--field-radius:var(--radius-sm)]",
34
+ md: "rounded-md [--field-height:var(--control-md)] [--field-pad:var(--field-pad-md)] [--field-radius:var(--radius-md)]",
35
+ lg: "rounded-lg [--field-height:var(--control-lg)] [--field-pad:var(--field-pad-lg)] [--field-radius:var(--radius-lg)]"
36
+ };
17
37
  /**
18
38
  * Height, corner and inline padding by size, handed to the parts inside as variables:
19
39
  * `--field-pad` (where text starts), `--field-height` and `--field-radius` (for a button that
@@ -46,4 +66,4 @@ function focusFieldControl(event) {
46
66
  event.preventDefault();
47
67
  control.focus();
48
68
  }
49
- export { bareControl, fieldFace, fieldShell, fieldShellSize, fieldText, focusFieldControl };
69
+ export { bareControl, fieldFace, fieldShell, fieldShellGrowing, fieldShellGrowingSize, fieldShellSize, fieldText, focusFieldControl };
@@ -74,6 +74,31 @@ function MinusGlyph(props) {
74
74
  children: /* @__PURE__ */ jsx("path", { d: "M2.5 6h7" })
75
75
  });
76
76
  }
77
+ /** Three square dots on the middle line: something was left out here (pages, in a `Pagination`). */
78
+ function GapGlyph(props) {
79
+ return /* @__PURE__ */ jsx(Glyph, {
80
+ ...props,
81
+ children: /* @__PURE__ */ jsx("path", { d: "M1.5 6h1.75M5.125 6h1.75M8.75 6h1.75" })
82
+ });
83
+ }
84
+ /**
85
+ * Stop, on the key that halts an answer being written: a filled square with the corner of a
86
+ * small key, so it reads as a solid mark where the send arrow stood.
87
+ */
88
+ function StopGlyph(props) {
89
+ return /* @__PURE__ */ jsx(Glyph, {
90
+ ...props,
91
+ children: /* @__PURE__ */ jsx("rect", {
92
+ x: "2.5",
93
+ y: "2.5",
94
+ width: "7",
95
+ height: "7",
96
+ rx: "1.25",
97
+ fill: "currentColor",
98
+ stroke: "none"
99
+ })
100
+ });
101
+ }
77
102
  /** The direction mark of a sortable column: up is ascending; turned, descending. */
78
103
  function ArrowUpGlyph(props) {
79
104
  return /* @__PURE__ */ jsx(Glyph, {
@@ -81,4 +106,4 @@ function ArrowUpGlyph(props) {
81
106
  children: /* @__PURE__ */ jsx("path", { d: "M6 10V2.75M2.5 6 6 2.5 9.5 6" })
82
107
  });
83
108
  }
84
- export { ArrowUpGlyph, ChevronDownGlyph, ChevronLeftGlyph, ChevronRightGlyph, CloseGlyph, DashGlyph, MinusGlyph, PlusGlyph, TickGlyph };
109
+ export { ArrowUpGlyph, ChevronDownGlyph, ChevronLeftGlyph, ChevronRightGlyph, CloseGlyph, DashGlyph, GapGlyph, MinusGlyph, PlusGlyph, StopGlyph, TickGlyph };
@@ -0,0 +1,41 @@
1
+ "use client";
2
+ import { mergeRefs } from "../lib/merge-refs.js";
3
+ import { jsx } from "react/jsx-runtime";
4
+ import { useEffect, useRef, useState } from "react";
5
+ // src/internal/live-list.tsx
6
+ /**
7
+ * A list that says when it has stood on screen for a frame (`data-live`), so only what joins it
8
+ * afterwards animates its entrance. The one piece of script a server-safe list (a `Timeline`)
9
+ * needs: the list stays markup the server writes, and this part marks it.
10
+ *
11
+ * Hidden (`display: none`, a closed tab) it is not live again until a frame after it shows, so
12
+ * a list that is revealed stands still like one that loads.
13
+ */
14
+ function LiveList({ ref, ...props }) {
15
+ const list = useRef(null);
16
+ const [live, setLive] = useState(false);
17
+ useEffect(() => {
18
+ const element = list.current;
19
+ if (!element) return;
20
+ let frame = 0;
21
+ const observer = new ResizeObserver(() => {
22
+ cancelAnimationFrame(frame);
23
+ if (!element.checkVisibility()) {
24
+ setLive(false);
25
+ return;
26
+ }
27
+ frame = requestAnimationFrame(() => setLive(true));
28
+ });
29
+ observer.observe(element);
30
+ return () => {
31
+ observer.disconnect();
32
+ cancelAnimationFrame(frame);
33
+ };
34
+ }, []);
35
+ return /* @__PURE__ */ jsx("ol", {
36
+ ref: mergeRefs(list, ref),
37
+ "data-live": live ? "" : void 0,
38
+ ...props
39
+ });
40
+ }
41
+ export { LiveList };