@lanfermann/ui 0.5.0 → 0.7.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 (186) hide show
  1. package/dist/components/accordion/accordion.d.ts +11 -3
  2. package/dist/components/accordion/accordion.js +15 -10
  3. package/dist/components/action-bar/action-bar.d.ts +60 -0
  4. package/dist/components/action-bar/action-bar.js +117 -0
  5. package/dist/components/alert/alert.d.ts +1 -1
  6. package/dist/components/alert/alert.js +3 -17
  7. package/dist/components/alert-dialog/alert-dialog.d.ts +1 -1
  8. package/dist/components/app-shell/app-shell.d.ts +33 -0
  9. package/dist/components/app-shell/app-shell.js +93 -0
  10. package/dist/components/attachment/attachment.d.ts +51 -0
  11. package/dist/components/attachment/attachment.js +255 -0
  12. package/dist/components/attachment/kinds.d.ts +7 -0
  13. package/dist/components/attachment/kinds.js +142 -0
  14. package/dist/components/avatar/avatar.d.ts +14 -4
  15. package/dist/components/avatar/avatar.js +57 -13
  16. package/dist/components/avatar-group/avatar-group.d.ts +33 -0
  17. package/dist/components/avatar-group/avatar-group.js +110 -0
  18. package/dist/components/avatar-group/people.d.ts +12 -0
  19. package/dist/components/avatar-group/people.js +24 -0
  20. package/dist/components/badge/badge.d.ts +9 -3
  21. package/dist/components/badge/badge.js +21 -6
  22. package/dist/components/banner/banner.d.ts +39 -0
  23. package/dist/components/banner/banner.js +149 -0
  24. package/dist/components/button-group/button-group-variants.d.ts +4 -3
  25. package/dist/components/button-group/button-group-variants.js +13 -12
  26. package/dist/components/button-group/button-group.d.ts +3 -3
  27. package/dist/components/button-group/button-group.js +3 -3
  28. package/dist/components/card/card.d.ts +20 -4
  29. package/dist/components/card/card.js +32 -6
  30. package/dist/components/checkbox-card/checkbox-card.d.ts +21 -0
  31. package/dist/components/checkbox-card/checkbox-card.js +50 -0
  32. package/dist/components/chip/chip-group.d.ts +15 -0
  33. package/dist/components/chip/chip-group.js +44 -0
  34. package/dist/components/chip/chip-variants.d.ts +6 -0
  35. package/dist/components/chip/chip-variants.js +28 -0
  36. package/dist/components/chip/chip.d.ts +39 -0
  37. package/dist/components/chip/chip.js +71 -0
  38. package/dist/components/code-block/code-copy.d.ts +3 -11
  39. package/dist/components/code-block/code-copy.js +15 -62
  40. package/dist/components/code-block/code-keys.js +10 -22
  41. package/dist/components/collapsible/collapsible.js +7 -3
  42. package/dist/components/combobox/combobox.d.ts +53 -3
  43. package/dist/components/combobox/combobox.js +204 -20
  44. package/dist/components/command/command.d.ts +131 -0
  45. package/dist/components/command/command.js +335 -0
  46. package/dist/components/consent/consent-card.js +365 -0
  47. package/dist/components/consent/consent-embed.d.ts +21 -0
  48. package/dist/components/consent/consent-embed.js +111 -0
  49. package/dist/components/consent/consent-labels.d.ts +70 -0
  50. package/dist/components/consent/consent-labels.js +61 -0
  51. package/dist/components/consent/consent-record.d.ts +95 -0
  52. package/dist/components/consent/consent-record.js +112 -0
  53. package/dist/components/consent/consent-store.d.ts +26 -0
  54. package/dist/components/consent/consent-store.js +240 -0
  55. package/dist/components/consent/consent.d.ts +86 -0
  56. package/dist/components/consent/consent.js +306 -0
  57. package/dist/components/container/container.d.ts +1 -1
  58. package/dist/components/context-menu/context-menu.d.ts +23 -0
  59. package/dist/components/context-menu/context-menu.js +50 -0
  60. package/dist/components/conversation/conversation.d.ts +45 -0
  61. package/dist/components/conversation/conversation.js +295 -0
  62. package/dist/components/conversation/stick.js +23 -0
  63. package/dist/components/copy-button/copy-button.d.ts +50 -0
  64. package/dist/components/copy-button/copy-button.js +65 -0
  65. package/dist/components/copy-page/copy-page.d.ts +4 -4
  66. package/dist/components/copy-page/copy-page.js +16 -36
  67. package/dist/components/copy-pill/copy-pill.js +1 -1
  68. package/dist/components/description-list/description-list.d.ts +32 -0
  69. package/dist/components/description-list/description-list.js +51 -0
  70. package/dist/components/empty/empty.d.ts +38 -0
  71. package/dist/components/empty/empty.js +57 -0
  72. package/dist/components/field/field.js +1 -1
  73. package/dist/components/file-upload/file-upload.d.ts +96 -0
  74. package/dist/components/file-upload/file-upload.js +347 -0
  75. package/dist/components/file-upload/files.d.ts +39 -0
  76. package/dist/components/file-upload/files.js +74 -0
  77. package/dist/components/grow/grow.d.ts +15 -3
  78. package/dist/components/grow/grow.js +24 -9
  79. package/dist/components/heading/heading.d.ts +1 -1
  80. package/dist/components/icon/icon.d.ts +1 -1
  81. package/dist/components/input/input.js +1 -1
  82. package/dist/components/menu/menu.d.ts +20 -8
  83. package/dist/components/menu/menu.js +51 -29
  84. package/dist/components/message/message.d.ts +81 -0
  85. package/dist/components/message/message.js +208 -0
  86. package/dist/components/navigation-menu/navigation-menu.d.ts +7 -1
  87. package/dist/components/navigation-menu/navigation-menu.js +11 -4
  88. package/dist/components/otp-field/otp-field.d.ts +37 -0
  89. package/dist/components/otp-field/otp-field.js +161 -0
  90. package/dist/components/pagination/pagination.d.ts +50 -0
  91. package/dist/components/pagination/pagination.js +188 -0
  92. package/dist/components/prompt-input/keys.js +15 -0
  93. package/dist/components/prompt-input/prompt-input.d.ts +89 -0
  94. package/dist/components/prompt-input/prompt-input.js +331 -0
  95. package/dist/components/radio-card/radio-card.d.ts +23 -0
  96. package/dist/components/radio-card/radio-card.js +49 -0
  97. package/dist/components/rolling-number/rolling-number.d.ts +30 -0
  98. package/dist/components/rolling-number/rolling-number.js +149 -0
  99. package/dist/components/seam/seam.d.ts +1 -1
  100. package/dist/components/secret-field/secret-field.d.ts +53 -0
  101. package/dist/components/secret-field/secret-field.js +121 -0
  102. package/dist/components/section/section.d.ts +1 -1
  103. package/dist/components/segmented-control/segmented-control.js +29 -16
  104. package/dist/components/select/select.d.ts +5 -4
  105. package/dist/components/select/select.js +16 -11
  106. package/dist/components/shortcut/shortcut.d.ts +46 -0
  107. package/dist/components/shortcut/shortcut.js +87 -0
  108. package/dist/components/sidebar/sidebar-context.js +16 -0
  109. package/dist/components/sidebar/sidebar.d.ts +161 -0
  110. package/dist/components/sidebar/sidebar.js +588 -0
  111. package/dist/components/site-header/site-header.js +1 -1
  112. package/dist/components/skeleton/loaded.d.ts +21 -0
  113. package/dist/components/skeleton/loaded.js +57 -0
  114. package/dist/components/skeleton/skeleton.d.ts +43 -0
  115. package/dist/components/skeleton/skeleton.js +48 -0
  116. package/dist/components/sources/source-list.d.ts +17 -0
  117. package/dist/components/sources/source-list.js +26 -0
  118. package/dist/components/sources/sources.d.ts +45 -0
  119. package/dist/components/sources/sources.js +167 -0
  120. package/dist/components/stat/stat.d.ts +59 -0
  121. package/dist/components/stat/stat.js +112 -0
  122. package/dist/components/steps/steps.d.ts +57 -0
  123. package/dist/components/steps/steps.js +134 -0
  124. package/dist/components/table/table.d.ts +18 -9
  125. package/dist/components/table/table.js +21 -13
  126. package/dist/components/text/text.d.ts +1 -1
  127. package/dist/components/theme-switch/theme-switch.js +1 -1
  128. package/dist/components/time-field/time-field.js +7 -6
  129. package/dist/components/timeline/timeline.d.ts +45 -0
  130. package/dist/components/timeline/timeline.js +86 -0
  131. package/dist/components/toast/toast.js +10 -26
  132. package/dist/components/toggle/toggle.d.ts +27 -0
  133. package/dist/components/toggle/toggle.js +61 -0
  134. package/dist/components/toggle-group/toggle-group.d.ts +27 -0
  135. package/dist/components/toggle-group/toggle-group.js +38 -0
  136. package/dist/components/toolbar/toolbar-context.js +12 -0
  137. package/dist/components/toolbar/toolbar.d.ts +52 -0
  138. package/dist/components/toolbar/toolbar.js +105 -0
  139. package/dist/components/trace/trace.d.ts +2 -1
  140. package/dist/components/trace/trace.js +15 -27
  141. package/dist/index.d.ts +46 -3
  142. package/dist/index.js +44 -3
  143. package/dist/internal/arriving-pieces.js +56 -0
  144. package/dist/internal/arriving.js +171 -0
  145. package/dist/internal/avatar-cut.d.ts +15 -0
  146. package/dist/internal/avatar-cut.js +83 -0
  147. package/dist/internal/choice-card.d.ts +15 -0
  148. package/dist/internal/choice-card.js +81 -0
  149. package/dist/internal/clipboard.js +37 -0
  150. package/dist/internal/copy.js +58 -0
  151. package/dist/internal/disclosure.js +15 -3
  152. package/dist/internal/field.js +24 -4
  153. package/dist/internal/glyphs.js +26 -1
  154. package/dist/internal/key-tip.js +18 -0
  155. package/dist/internal/list-mark.js +39 -0
  156. package/dist/internal/live-list.js +41 -0
  157. package/dist/internal/number-places.js +157 -0
  158. package/dist/internal/picker-sheet.js +1 -1
  159. package/dist/internal/presence-dot.js +24 -0
  160. package/dist/internal/presence.js +104 -0
  161. package/dist/internal/rail-mark.d.ts +3 -0
  162. package/dist/internal/rail-mark.js +33 -0
  163. package/dist/internal/rule.js +2 -1
  164. package/dist/internal/status-icon.js +22 -0
  165. package/dist/internal/tile.js +23 -0
  166. package/dist/internal/travelling-mark.js +204 -0
  167. package/dist/lib/cn.js +10 -0
  168. package/dist/lib/shortcut.d.ts +11 -0
  169. package/dist/lib/shortcut.js +165 -0
  170. package/package.json +1 -1
  171. package/src/styles/accordion.css +176 -0
  172. package/src/styles/action-bar.css +28 -0
  173. package/src/styles/assistant.css +83 -0
  174. package/src/styles/avatar.css +24 -0
  175. package/src/styles/consent.css +65 -0
  176. package/src/styles/copy.css +12 -11
  177. package/src/styles/depth.css +120 -4
  178. package/src/styles/marks.css +20 -2
  179. package/src/styles/motion.css +3 -0
  180. package/src/styles/rail.css +49 -0
  181. package/src/styles/rolling-number.css +94 -0
  182. package/src/styles/segmented.css +14 -7
  183. package/src/styles/steps.css +98 -0
  184. package/src/styles/timeline.css +48 -0
  185. package/src/styles/travel.css +36 -0
  186. package/src/styles.css +10 -0
@@ -0,0 +1,204 @@
1
+ "use client";
2
+ import { atRest, springForce, stepSpring } from "../motion/spring-step.js";
3
+ import { springs } from "../motion/springs.js";
4
+ import { useLayoutEffect } from "react";
5
+ // src/internal/travelling-mark.ts
6
+ const sides = [
7
+ "x",
8
+ "y",
9
+ "w",
10
+ "h"
11
+ ];
12
+ const force = springForce(springs.glide);
13
+ /** A tenth of a pixel from its place, and all but still: nobody sees the difference. */
14
+ const ARRIVED = .1;
15
+ /**
16
+ * How long a fold may claim it has further to go without going there. Something sticks out of
17
+ * it then (it is never as tall as what it holds), and the mark stops waiting for it.
18
+ */
19
+ const STALLED_MS = 250;
20
+ /** Where an element stands inside a box that is one of its positioned ancestors. */
21
+ function placeWithin(element, box) {
22
+ let x = 0;
23
+ let y = 0;
24
+ let node = element;
25
+ while (node && node !== box) {
26
+ x += node.offsetLeft;
27
+ y += node.offsetTop;
28
+ node = node.offsetParent;
29
+ }
30
+ return {
31
+ x,
32
+ y,
33
+ w: element.offsetWidth,
34
+ h: element.offsetHeight
35
+ };
36
+ }
37
+ /**
38
+ * Keeps one mark on the current entry of a list and lets it travel when another entry becomes
39
+ * current: the tint of a `Sidebar`, the tint under a page number. "The mark travels" (DESIGN.md).
40
+ *
41
+ * `listRef` is the positioned box that holds the entries and the mark. The mark's place is the
42
+ * entry's measured offsets (layout pixels, so it is right under `zoom`), written onto it as
43
+ * `--mark-x`, `--mark-y`, `--mark-w` and `--mark-h`; the `travels` utility (travel.css) turns
44
+ * them into a box moved by `translate`. Nothing renders: the list is watched for the entry that
45
+ * says it is current.
46
+ *
47
+ * The travel is a spring stepped by hand (`glide`), not a CSS transition, because the place it
48
+ * travels to may itself be moving: the subpages of the entry it left fold away, and every entry
49
+ * below slides up while the mark is on its way. A transition would have to be given a new goal
50
+ * on every frame, and such a transition never arrives. The spring reads its goal anew each
51
+ * frame and keeps its speed. For the parts named in `folds` it also knows how far they still
52
+ * have to go, so its goal is where the entry will come to rest: it does not overshoot an entry
53
+ * that comes towards it.
54
+ *
55
+ * At rest the mark is part of its entry: when the layout moves under it (a group folds, the
56
+ * list narrows), it is set to the entry's new place at once, frame by frame.
57
+ *
58
+ * What the stylesheet reads:
59
+ *
60
+ * `data-shown` on the mark an entry is current and laid out; without it the mark fades
61
+ * `data-placed` on the list the mark has taken over. Until then (on the server, before the
62
+ * first measure) the current entry wears the same look itself,
63
+ * so nothing appears late.
64
+ */
65
+ function useTravellingMark(listRef, markRef, { current = "[aria-current=\"page\"]", attribute = "aria-current", still, folds, enabled = true } = {}) {
66
+ useLayoutEffect(() => {
67
+ const box = listRef.current;
68
+ const piece = markRef.current;
69
+ if (!enabled || !box || !piece) return;
70
+ const reduced = window.matchMedia("(prefers-reduced-motion: reduce)");
71
+ /** Where the mark is right now, and how fast each of its sides moves. */
72
+ let at = null;
73
+ let frame = 0;
74
+ let then = 0;
75
+ /** What the folds last said they had to go, and when that last changed. */
76
+ let lastRest = NaN;
77
+ let movedAt = 0;
78
+ /** The entry the mark belongs on, if it has a place: laid out, and not inside a moving part. */
79
+ const entryNow = () => {
80
+ const entry = box.querySelector(current);
81
+ if (!entry || entry.offsetParent === null) return null;
82
+ if (still && entry.closest(`[${still}]`)) return null;
83
+ return entry;
84
+ };
85
+ const goal = () => {
86
+ const entry = entryNow();
87
+ return entry && placeWithin(entry, box);
88
+ };
89
+ /**
90
+ * How far the entry still has to slide down (or, negative, up) until the parts that fold
91
+ * above it have arrived: what each of them will be tall, less what it is tall now.
92
+ */
93
+ const stillToCome = () => {
94
+ const entry = folds ? entryNow() : null;
95
+ if (!entry || !folds) return 0;
96
+ let rest = 0;
97
+ for (const part of box.querySelectorAll(folds)) {
98
+ if (!(part.compareDocumentPosition(entry) & Node.DOCUMENT_POSITION_FOLLOWING) || part.contains(entry)) continue;
99
+ rest += (part.hasAttribute("data-open") ? part.scrollHeight : 0) - part.offsetHeight;
100
+ }
101
+ return rest;
102
+ };
103
+ const draw = (place) => {
104
+ for (const side of sides) piece.style.setProperty(`--mark-${side}`, `${place[side]}px`);
105
+ };
106
+ const stop = () => {
107
+ cancelAnimationFrame(frame);
108
+ frame = 0;
109
+ };
110
+ /** Stands on the entry at once: the first place, a layout that moved, reduced motion. */
111
+ const seat = () => {
112
+ stop();
113
+ const place = goal();
114
+ if (!place) {
115
+ at = null;
116
+ delete piece.dataset.shown;
117
+ return;
118
+ }
119
+ at = {
120
+ x: still0(place.x),
121
+ y: still0(place.y),
122
+ w: still0(place.w),
123
+ h: still0(place.h)
124
+ };
125
+ draw(place);
126
+ piece.dataset.shown = "";
127
+ };
128
+ const tick = (now) => {
129
+ frame = 0;
130
+ const place = goal();
131
+ if (!place || !at) return seat();
132
+ let rest = stillToCome();
133
+ if (rest !== lastRest) {
134
+ lastRest = rest;
135
+ movedAt = now;
136
+ }
137
+ if (now - movedAt > STALLED_MS) rest = 0;
138
+ place.y += rest;
139
+ const seconds = (now - then) / 1e3;
140
+ then = now;
141
+ let arrived = Math.abs(rest) < ARRIVED;
142
+ for (const side of sides) {
143
+ at[side] = stepSpring(at[side], place[side], force, seconds);
144
+ arrived &&= atRest(at[side], place[side], ARRIVED);
145
+ }
146
+ if (arrived) return seat();
147
+ const w = Math.min(at.w.value, Math.max(0, box.offsetWidth - at.x.value));
148
+ draw({
149
+ x: at.x.value,
150
+ y: at.y.value,
151
+ w,
152
+ h: at.h.value
153
+ });
154
+ frame = requestAnimationFrame(tick);
155
+ };
156
+ /** Another entry is current: the mark sets off for it from where it stands. */
157
+ const travel = () => {
158
+ if (!at || !goal() || reduced.matches) return seat();
159
+ if (frame) return;
160
+ then = movedAt = performance.now();
161
+ lastRest = NaN;
162
+ frame = requestAnimationFrame(tick);
163
+ };
164
+ seat();
165
+ box.dataset.placed = "";
166
+ const changed = new MutationObserver((records) => {
167
+ if (still && records.some((record) => record.attributeName === still)) seat();
168
+ else travel();
169
+ });
170
+ changed.observe(box, {
171
+ subtree: true,
172
+ childList: true,
173
+ attributes: true,
174
+ attributeFilter: still ? [attribute, still] : [attribute]
175
+ });
176
+ const resized = new ResizeObserver(() => {
177
+ if (!frame) seat();
178
+ });
179
+ resized.observe(box);
180
+ return () => {
181
+ stop();
182
+ changed.disconnect();
183
+ resized.disconnect();
184
+ delete box.dataset.placed;
185
+ delete piece.dataset.shown;
186
+ };
187
+ }, [
188
+ listRef,
189
+ markRef,
190
+ current,
191
+ attribute,
192
+ still,
193
+ folds,
194
+ enabled
195
+ ]);
196
+ }
197
+ /** A side that stands where it is. */
198
+ function still0(value) {
199
+ return {
200
+ value,
201
+ velocity: 0
202
+ };
203
+ }
204
+ export { useTravellingMark };
package/dist/lib/cn.js CHANGED
@@ -19,6 +19,10 @@ const depthNames = [
19
19
  "field-focus",
20
20
  "field-invalid",
21
21
  "card",
22
+ "bevel",
23
+ "bevel-chosen",
24
+ "gloss",
25
+ "dock",
22
26
  "floating",
23
27
  "overlay",
24
28
  "bar",
@@ -42,6 +46,9 @@ const shadowNames = [
42
46
  "field-focus",
43
47
  "field-invalid",
44
48
  "card",
49
+ "bevel",
50
+ "bevel-pressed",
51
+ "dock",
45
52
  "floating",
46
53
  "overlay",
47
54
  "bar"
@@ -54,6 +61,9 @@ const insetShadowNames = [
54
61
  "trough",
55
62
  "field",
56
63
  "card",
64
+ "bevel",
65
+ "bevel-chosen",
66
+ "gloss",
57
67
  "sheet",
58
68
  "bar"
59
69
  ];
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Keyboard shortcuts as data: how one is written, how it is drawn on a keyboard, and whether a
3
+ * key press is it. Plain functions without a hook, so the server can draw a shortcut too.
4
+ *
5
+ * A shortcut is written as its keys joined by a plus: `mod+k`, `mod+shift+p`, `esc`, `/`. `mod`
6
+ * is the key an operating system uses for its commands: ⌘ on Apple devices, Strg elsewhere.
7
+ * The other names are `ctrl`, `alt`, `shift`, `enter`, `esc`, `tab`, `space`, `backspace`,
8
+ * `delete`, `up`, `down`, `left`, `right` and `plus`; anything else is the character itself.
9
+ */
10
+ /** The two kinds of keyboard a shortcut is drawn for. */
11
+ export type Platform = "apple" | "other";
@@ -0,0 +1,165 @@
1
+ // src/lib/shortcut.ts
2
+ const modifiers = /* @__PURE__ */ new Set([
3
+ "mod",
4
+ "ctrl",
5
+ "alt",
6
+ "shift"
7
+ ]);
8
+ /** What stands on the cap, and its name, where the two kinds of keyboard agree. */
9
+ const shared = {
10
+ shift: {
11
+ label: "⇧",
12
+ name: "Umschalttaste"
13
+ },
14
+ enter: {
15
+ label: "↵",
16
+ name: "Eingabetaste"
17
+ },
18
+ esc: {
19
+ label: "Esc",
20
+ name: "Escape"
21
+ },
22
+ tab: {
23
+ label: "⇥",
24
+ name: "Tabulatortaste"
25
+ },
26
+ space: {
27
+ label: "Leertaste",
28
+ name: "Leertaste"
29
+ },
30
+ backspace: {
31
+ label: "⌫",
32
+ name: "Rücktaste"
33
+ },
34
+ up: {
35
+ label: "↑",
36
+ name: "Pfeil nach oben"
37
+ },
38
+ down: {
39
+ label: "↓",
40
+ name: "Pfeil nach unten"
41
+ },
42
+ left: {
43
+ label: "←",
44
+ name: "Pfeil nach links"
45
+ },
46
+ right: {
47
+ label: "→",
48
+ name: "Pfeil nach rechts"
49
+ },
50
+ plus: {
51
+ label: "+",
52
+ name: "Plus"
53
+ }
54
+ };
55
+ /** Where they differ: an Apple keyboard prints symbols, the others print German words. */
56
+ const perPlatform = {
57
+ apple: {
58
+ mod: {
59
+ label: "⌘",
60
+ name: "Befehlstaste"
61
+ },
62
+ ctrl: {
63
+ label: "⌃",
64
+ name: "Control"
65
+ },
66
+ alt: {
67
+ label: "⌥",
68
+ name: "Wahltaste"
69
+ },
70
+ delete: {
71
+ label: "⌦",
72
+ name: "Entfernen"
73
+ }
74
+ },
75
+ other: {
76
+ mod: {
77
+ label: "Strg",
78
+ name: "Steuerung"
79
+ },
80
+ ctrl: {
81
+ label: "Strg",
82
+ name: "Steuerung"
83
+ },
84
+ alt: {
85
+ label: "Alt",
86
+ name: "Alt"
87
+ },
88
+ delete: {
89
+ label: "Entf",
90
+ name: "Entfernen"
91
+ }
92
+ }
93
+ };
94
+ /** The value of `KeyboardEvent.key` for each named key. */
95
+ const eventKeys = {
96
+ enter: "Enter",
97
+ esc: "Escape",
98
+ tab: "Tab",
99
+ space: " ",
100
+ backspace: "Backspace",
101
+ delete: "Delete",
102
+ up: "ArrowUp",
103
+ down: "ArrowDown",
104
+ left: "ArrowLeft",
105
+ right: "ArrowRight",
106
+ plus: "+"
107
+ };
108
+ function tokens(keys) {
109
+ return keys.split("+").map((token) => token.trim().toLowerCase()).filter(Boolean);
110
+ }
111
+ /** The keys of a shortcut in the order they are written, as they stand on that keyboard. */
112
+ function shortcutKeys(keys, platform) {
113
+ return tokens(keys).map((token) => {
114
+ const named = perPlatform[platform][token] ?? shared[token];
115
+ if (named) return named;
116
+ const label = token.length === 1 ? token.toUpperCase() : token;
117
+ return {
118
+ label,
119
+ name: label
120
+ };
121
+ });
122
+ }
123
+ /** Whether a shortcut holds a key that turns a letter into a command: `mod`, `ctrl` or `alt`. */
124
+ function hasCommandKey(keys) {
125
+ return tokens(keys).some((token) => token === "mod" || token === "ctrl" || token === "alt");
126
+ }
127
+ /** Whether a shortcut is drawn differently on the two kinds of keyboard. */
128
+ function dependsOnPlatform(keys) {
129
+ return tokens(keys).some((token) => token in perPlatform.apple);
130
+ }
131
+ /**
132
+ * Whether a key press is the shortcut, on that kind of keyboard.
133
+ *
134
+ * A letter is compared by what the key types, not by where it sits, so the shortcut follows the
135
+ * layout: `mod+z` is the key marked Z on a German keyboard too. Two exceptions. With `alt` held
136
+ * a key types another character (⌥K gives ˚), so there the place of the key decides. And a sign
137
+ * such as `?` needs Shift on some layouts and not on others, so for a sign Shift is not compared.
138
+ */
139
+ function matchesShortcut(press, keys, platform) {
140
+ const parts = tokens(keys);
141
+ const key = parts.find((part) => !modifiers.has(part));
142
+ if (!key) return false;
143
+ const wants = (modifier) => parts.includes(modifier);
144
+ const meta = platform === "apple" && wants("mod");
145
+ const ctrl = wants("ctrl") || platform === "other" && wants("mod");
146
+ if (press.metaKey !== meta || press.ctrlKey !== ctrl || press.altKey !== wants("alt")) return false;
147
+ const named = eventKeys[key];
148
+ const letter = /^[a-z0-9]$/.test(key);
149
+ if ((named !== void 0 || letter) && press.shiftKey !== wants("shift")) return false;
150
+ if (named !== void 0) return press.key === named;
151
+ if (letter && wants("alt")) return press.code === (/[0-9]/.test(key) ? `Digit${key}` : `Key${key.toUpperCase()}`);
152
+ return press.key.toLowerCase() === key;
153
+ }
154
+ /** Whether the keyboard in front of the reader is an Apple one. Only the browser can say. */
155
+ function detectPlatform() {
156
+ if (typeof navigator === "undefined") return "other";
157
+ const hinted = navigator.userAgentData?.platform;
158
+ return /mac|iphone|ipad|ipod/i.test(hinted || navigator.platform || navigator.userAgent) ? "apple" : "other";
159
+ }
160
+ /** Whether a key press lands in something that is typed into: a field, or editable text. */
161
+ function isTypingTarget(target) {
162
+ if (!(target instanceof HTMLElement)) return false;
163
+ return target.isContentEditable || /^(input|textarea|select)$/i.test(target.tagName);
164
+ }
165
+ export { dependsOnPlatform, detectPlatform, hasCommandKey, isTypingTarget, matchesShortcut, shortcutKeys };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lanfermann/ui",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "Lanfermann design system components for Next.js + Tailwind CSS v4, built on Base UI.",
5
5
  "license": "MIT",
6
6
  "author": "Justin Lanfermann",
@@ -0,0 +1,176 @@
1
+ /*
2
+ * Accordion: rows divided by hairlines, and the shape a row takes while it is pointed at.
3
+ * Chosen by Justin on 2026-11-20 (DESIGN.md, Accordion).
4
+ *
5
+ * One edge per boundary. Where a wash marks a row, the lines on its two sides step aside (fade),
6
+ * so the wash is the row's only edge and never stands a pixel short of a line that runs on past
7
+ * its corners. A wash stands `--accordion-inset` inside its row.
8
+ *
9
+ * An open row rests unmarked. Pointed at, its question's wash is a lid: its lower corners go
10
+ * square and the wash runs on at half strength behind the answer, so the pointer shows what the
11
+ * row holds. The corners turn as the row opens (`settle`) and closes (`leave`).
12
+ *
13
+ * The lines and washes are pseudo-elements, so they can fade and take corners of their own:
14
+ * root ::before the hairline that opens the block
15
+ * item ::after the hairline under the row
16
+ * item ::before the tail of an open row's wash, behind its answer
17
+ * trigger ::before the wash under the pointer
18
+ * (The trigger's `::after` is its touch target.)
19
+ *
20
+ * Pointed at means `:hover` on a device that can hover, and `:active` everywhere, so a finger
21
+ * gets the wash while it is down, as a cell does on iOS. `data-quiet` (the `quiet` prop) takes no
22
+ * wash: the lines stay and only the chevron answers.
23
+ */
24
+
25
+ [data-slot="accordion"] {
26
+ --accordion-inset: 2px;
27
+ position: relative;
28
+ padding-top: 1px;
29
+ }
30
+
31
+ /* ---- Lines ---- */
32
+
33
+ [data-slot="accordion-item"] {
34
+ position: relative;
35
+ isolation: isolate;
36
+ padding-bottom: 1px;
37
+ }
38
+
39
+ [data-slot="accordion"]::before,
40
+ [data-slot="accordion-item"]::after {
41
+ content: "";
42
+ position: absolute;
43
+ inset-inline: 0;
44
+ height: 1px;
45
+ background-color: var(--lf-hairline);
46
+ pointer-events: none;
47
+ transition: opacity var(--transition-duration-spring-snap) var(--ease-spring-snap);
48
+ }
49
+
50
+ [data-slot="accordion"]::before {
51
+ top: 0;
52
+ }
53
+
54
+ [data-slot="accordion-item"]::after {
55
+ bottom: 0;
56
+ }
57
+
58
+ /* ---- Washes ---- */
59
+
60
+ [data-slot="accordion-trigger"] {
61
+ isolation: isolate;
62
+ }
63
+
64
+ [data-slot="accordion-trigger"]::before {
65
+ content: "";
66
+ position: absolute;
67
+ inset: var(--accordion-inset) 0;
68
+ z-index: -1;
69
+ border-radius: var(--radius-base);
70
+ background-color: var(--lf-hover);
71
+ opacity: 0;
72
+ pointer-events: none;
73
+ transition:
74
+ opacity var(--transition-duration-spring-snap) var(--ease-spring-snap),
75
+ border-radius var(--transition-duration-spring-leave) var(--ease-spring-leave);
76
+ }
77
+
78
+ /* Open, the wash is a lid: the tail's corners on top, square below where the answer goes on. */
79
+ [data-slot="accordion-trigger"][data-panel-open]::before {
80
+ border-radius: calc(var(--radius-base) * 1.5) calc(var(--radius-base) * 1.5) 0 0;
81
+ transition:
82
+ opacity var(--transition-duration-spring-snap) var(--ease-spring-snap),
83
+ border-radius var(--transition-duration-spring-settle) var(--ease-spring-settle);
84
+ }
85
+
86
+ /* The tail: the whole open row, inside its lines by the inset, under the lid. */
87
+ [data-slot="accordion-item"]::before {
88
+ content: "";
89
+ position: absolute;
90
+ inset: var(--accordion-inset) 0 calc(var(--accordion-inset) + 1px);
91
+ z-index: -1;
92
+ border-radius: calc(var(--radius-base) * 1.5);
93
+ background-color: var(--lf-hover);
94
+ opacity: 0;
95
+ pointer-events: none;
96
+ transition: opacity var(--transition-duration-spring-snap) var(--ease-spring-snap);
97
+ }
98
+
99
+ /* ---- Pointed at ---- */
100
+
101
+ @media (hover: hover) {
102
+ [data-slot="accordion"]:not([data-quiet]) {
103
+ & [data-slot="accordion-trigger"]:hover::before {
104
+ opacity: 1;
105
+ }
106
+
107
+ &
108
+ [data-slot="accordion-item"][data-open]:has(
109
+ > [data-slot="accordion-header"] > [data-slot="accordion-trigger"]:hover
110
+ )::before {
111
+ opacity: 0.5;
112
+ }
113
+
114
+ &
115
+ [data-slot="accordion-item"]:is(
116
+ :has(> [data-slot="accordion-header"] > [data-slot="accordion-trigger"]:hover),
117
+ :has(
118
+ + [data-slot="accordion-item"]
119
+ > [data-slot="accordion-header"]
120
+ > [data-slot="accordion-trigger"]:hover
121
+ )
122
+ )::after {
123
+ opacity: 0;
124
+ }
125
+
126
+ &:has(
127
+ > [data-slot="accordion-item"]:first-child
128
+ > [data-slot="accordion-header"]
129
+ > [data-slot="accordion-trigger"]:hover
130
+ )::before {
131
+ opacity: 0;
132
+ }
133
+ }
134
+ }
135
+
136
+ [data-slot="accordion"]:not([data-quiet]) {
137
+ & [data-slot="accordion-trigger"]:active::before {
138
+ opacity: 1;
139
+ }
140
+
141
+ &
142
+ [data-slot="accordion-item"][data-open]:has(
143
+ > [data-slot="accordion-header"] > [data-slot="accordion-trigger"]:active
144
+ )::before {
145
+ opacity: 0.5;
146
+ }
147
+
148
+ &
149
+ [data-slot="accordion-item"]:is(
150
+ :has(> [data-slot="accordion-header"] > [data-slot="accordion-trigger"]:active),
151
+ :has(
152
+ + [data-slot="accordion-item"]
153
+ > [data-slot="accordion-header"]
154
+ > [data-slot="accordion-trigger"]:active
155
+ )
156
+ )::after {
157
+ opacity: 0;
158
+ }
159
+
160
+ &:has(
161
+ > [data-slot="accordion-item"]:first-child
162
+ > [data-slot="accordion-header"]
163
+ > [data-slot="accordion-trigger"]:active
164
+ )::before {
165
+ opacity: 0;
166
+ }
167
+ }
168
+
169
+ /* Forced colours drop the washes; the lines are drawn in the text colour and always stay. */
170
+ @media (forced-colors: active) {
171
+ [data-slot="accordion"]::before,
172
+ [data-slot="accordion-item"]::after {
173
+ background-color: CanvasText;
174
+ opacity: 1 !important;
175
+ }
176
+ }
@@ -0,0 +1,28 @@
1
+ /*
2
+ * How an `ActionBar` comes and goes. It is always in the page, unseen while nothing is
3
+ * selected, so both ways are plain transitions that can be turned around half-way: selecting
4
+ * and deselecting quickly never leaves it stuck.
5
+ *
6
+ * It rises into place on `sheet`, by twice what a popup travels, and it leaves by fading, as
7
+ * every exit does: it is set back down only once it is no longer seen. Under reduced motion it
8
+ * does not travel at all (`--motion-enter-offset` is 0).
9
+ */
10
+ @utility action-bar-motion {
11
+ opacity: 0;
12
+ translate: 0 calc(var(--motion-enter-offset) * 2);
13
+ visibility: hidden;
14
+ transition:
15
+ opacity var(--transition-duration-spring-leave) var(--ease-spring-leave),
16
+ translate 0s var(--transition-duration-spring-leave),
17
+ visibility 0s var(--transition-duration-spring-leave);
18
+
19
+ &[data-open] {
20
+ opacity: 1;
21
+ translate: 0 0;
22
+ visibility: visible;
23
+ transition:
24
+ opacity var(--transition-duration-spring-sheet) var(--ease-spring-sheet),
25
+ translate var(--transition-duration-spring-sheet) var(--ease-spring-sheet),
26
+ visibility 0s;
27
+ }
28
+ }