@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.
- package/dist/components/action-bar/action-bar.d.ts +59 -0
- package/dist/components/action-bar/action-bar.js +116 -0
- package/dist/components/alert/alert.d.ts +1 -1
- package/dist/components/alert/alert.js +3 -17
- package/dist/components/alert-dialog/alert-dialog.d.ts +1 -1
- package/dist/components/app-shell/app-shell.d.ts +33 -0
- package/dist/components/app-shell/app-shell.js +93 -0
- package/dist/components/attachment/attachment.d.ts +46 -0
- package/dist/components/attachment/attachment.js +222 -0
- package/dist/components/attachment/kinds.d.ts +7 -0
- package/dist/components/attachment/kinds.js +100 -0
- package/dist/components/avatar/avatar.d.ts +14 -4
- package/dist/components/avatar/avatar.js +57 -13
- package/dist/components/avatar-group/avatar-group.d.ts +33 -0
- package/dist/components/avatar-group/avatar-group.js +110 -0
- package/dist/components/avatar-group/people.d.ts +12 -0
- package/dist/components/avatar-group/people.js +24 -0
- package/dist/components/badge/badge.d.ts +9 -3
- package/dist/components/badge/badge.js +21 -6
- package/dist/components/banner/banner.d.ts +39 -0
- package/dist/components/banner/banner.js +149 -0
- package/dist/components/card/card.d.ts +11 -3
- package/dist/components/card/card.js +18 -4
- package/dist/components/checkbox-card/checkbox-card.d.ts +21 -0
- package/dist/components/checkbox-card/checkbox-card.js +49 -0
- package/dist/components/chip/chip-group.d.ts +15 -0
- package/dist/components/chip/chip-group.js +44 -0
- package/dist/components/chip/chip-variants.d.ts +6 -0
- package/dist/components/chip/chip-variants.js +28 -0
- package/dist/components/chip/chip.d.ts +39 -0
- package/dist/components/chip/chip.js +71 -0
- package/dist/components/code-block/code-copy.d.ts +3 -11
- package/dist/components/code-block/code-copy.js +15 -62
- package/dist/components/code-block/code-keys.js +10 -22
- package/dist/components/combobox/combobox.d.ts +50 -2
- package/dist/components/combobox/combobox.js +178 -9
- package/dist/components/command/command.d.ts +131 -0
- package/dist/components/command/command.js +335 -0
- package/dist/components/consent/consent-card.js +365 -0
- package/dist/components/consent/consent-embed.d.ts +21 -0
- package/dist/components/consent/consent-embed.js +111 -0
- package/dist/components/consent/consent-labels.d.ts +70 -0
- package/dist/components/consent/consent-labels.js +61 -0
- package/dist/components/consent/consent-record.d.ts +95 -0
- package/dist/components/consent/consent-record.js +112 -0
- package/dist/components/consent/consent-store.d.ts +26 -0
- package/dist/components/consent/consent-store.js +240 -0
- package/dist/components/consent/consent.d.ts +86 -0
- package/dist/components/consent/consent.js +306 -0
- package/dist/components/container/container.d.ts +1 -1
- package/dist/components/context-menu/context-menu.d.ts +23 -0
- package/dist/components/context-menu/context-menu.js +50 -0
- package/dist/components/conversation/conversation.d.ts +45 -0
- package/dist/components/conversation/conversation.js +295 -0
- package/dist/components/conversation/stick.js +23 -0
- package/dist/components/copy-button/copy-button.d.ts +50 -0
- package/dist/components/copy-button/copy-button.js +65 -0
- package/dist/components/copy-page/copy-page.js +7 -17
- package/dist/components/copy-pill/copy-pill.js +1 -1
- package/dist/components/description-list/description-list.d.ts +32 -0
- package/dist/components/description-list/description-list.js +51 -0
- package/dist/components/empty/empty.d.ts +38 -0
- package/dist/components/empty/empty.js +57 -0
- package/dist/components/field/field.js +1 -1
- package/dist/components/file-upload/file-upload.d.ts +96 -0
- package/dist/components/file-upload/file-upload.js +347 -0
- package/dist/components/file-upload/files.d.ts +39 -0
- package/dist/components/file-upload/files.js +74 -0
- package/dist/components/grow/grow.d.ts +15 -3
- package/dist/components/grow/grow.js +24 -9
- package/dist/components/heading/heading.d.ts +1 -1
- package/dist/components/icon/icon.d.ts +1 -1
- package/dist/components/input/input.js +1 -1
- package/dist/components/message/message.d.ts +73 -0
- package/dist/components/message/message.js +196 -0
- package/dist/components/otp-field/otp-field.d.ts +37 -0
- package/dist/components/otp-field/otp-field.js +126 -0
- package/dist/components/pagination/pagination.d.ts +50 -0
- package/dist/components/pagination/pagination.js +188 -0
- package/dist/components/prompt-input/keys.js +15 -0
- package/dist/components/prompt-input/prompt-input.d.ts +89 -0
- package/dist/components/prompt-input/prompt-input.js +331 -0
- package/dist/components/radio-card/radio-card.d.ts +23 -0
- package/dist/components/radio-card/radio-card.js +48 -0
- package/dist/components/rolling-number/rolling-number.d.ts +30 -0
- package/dist/components/rolling-number/rolling-number.js +149 -0
- package/dist/components/seam/seam.d.ts +1 -1
- package/dist/components/secret-field/secret-field.d.ts +53 -0
- package/dist/components/secret-field/secret-field.js +121 -0
- package/dist/components/section/section.d.ts +1 -1
- package/dist/components/select/select.d.ts +1 -1
- package/dist/components/select/select.js +1 -1
- package/dist/components/shortcut/shortcut.d.ts +46 -0
- package/dist/components/shortcut/shortcut.js +87 -0
- package/dist/components/sidebar/sidebar-context.js +16 -0
- package/dist/components/sidebar/sidebar.d.ts +161 -0
- package/dist/components/sidebar/sidebar.js +588 -0
- package/dist/components/site-header/site-header.js +1 -1
- package/dist/components/skeleton/loaded.d.ts +21 -0
- package/dist/components/skeleton/loaded.js +57 -0
- package/dist/components/skeleton/skeleton.d.ts +43 -0
- package/dist/components/skeleton/skeleton.js +48 -0
- package/dist/components/sources/source-list.d.ts +17 -0
- package/dist/components/sources/source-list.js +26 -0
- package/dist/components/sources/sources.d.ts +45 -0
- package/dist/components/sources/sources.js +167 -0
- package/dist/components/stat/stat.d.ts +57 -0
- package/dist/components/stat/stat.js +110 -0
- package/dist/components/steps/steps.d.ts +57 -0
- package/dist/components/steps/steps.js +131 -0
- package/dist/components/table/table.d.ts +18 -9
- package/dist/components/table/table.js +21 -13
- package/dist/components/text/text.d.ts +1 -1
- package/dist/components/theme-switch/theme-switch.js +1 -1
- package/dist/components/time-field/time-field.js +1 -1
- package/dist/components/timeline/timeline.d.ts +45 -0
- package/dist/components/timeline/timeline.js +86 -0
- package/dist/components/toast/toast.js +10 -26
- package/dist/components/toggle/toggle.d.ts +24 -0
- package/dist/components/toggle/toggle.js +53 -0
- package/dist/components/toggle-group/toggle-group.d.ts +27 -0
- package/dist/components/toggle-group/toggle-group.js +38 -0
- package/dist/components/toolbar/toolbar-context.js +12 -0
- package/dist/components/toolbar/toolbar.d.ts +45 -0
- package/dist/components/toolbar/toolbar.js +92 -0
- package/dist/components/trace/trace.d.ts +2 -1
- package/dist/components/trace/trace.js +14 -26
- package/dist/index.d.ts +46 -3
- package/dist/index.js +44 -3
- package/dist/internal/arriving-pieces.js +56 -0
- package/dist/internal/arriving.js +171 -0
- package/dist/internal/avatar-cut.d.ts +15 -0
- package/dist/internal/avatar-cut.js +83 -0
- package/dist/internal/choice-card.d.ts +15 -0
- package/dist/internal/choice-card.js +65 -0
- package/dist/internal/clipboard.js +37 -0
- package/dist/internal/copy.js +58 -0
- package/dist/internal/field.js +24 -4
- package/dist/internal/glyphs.js +26 -1
- package/dist/internal/live-list.js +41 -0
- package/dist/internal/number-places.js +156 -0
- package/dist/internal/picker-sheet.js +1 -1
- package/dist/internal/presence-dot.js +24 -0
- package/dist/internal/presence.js +104 -0
- package/dist/internal/rail-mark.d.ts +3 -0
- package/dist/internal/rail-mark.js +33 -0
- package/dist/internal/status-icon.js +22 -0
- package/dist/internal/travelling-mark.js +204 -0
- package/dist/lib/cn.js +4 -0
- package/dist/lib/shortcut.d.ts +11 -0
- package/dist/lib/shortcut.js +165 -0
- package/package.json +1 -1
- package/src/styles/action-bar.css +28 -0
- package/src/styles/assistant.css +83 -0
- package/src/styles/avatar.css +24 -0
- package/src/styles/consent.css +65 -0
- package/src/styles/copy.css +12 -11
- package/src/styles/depth.css +46 -2
- package/src/styles/marks.css +20 -2
- package/src/styles/rail.css +49 -0
- package/src/styles/rolling-number.css +94 -0
- package/src/styles/steps.css +98 -0
- package/src/styles/timeline.css +48 -0
- package/src/styles/travel.css +36 -0
- package/src/styles.css +9 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// src/internal/number-places.ts
|
|
2
|
+
const BODY = /* @__PURE__ */ new Set([
|
|
3
|
+
"integer",
|
|
4
|
+
"group",
|
|
5
|
+
"decimal",
|
|
6
|
+
"fraction"
|
|
7
|
+
]);
|
|
8
|
+
/**
|
|
9
|
+
* The number format for a `RollingNumber`: German by default, and a minus only where there is
|
|
10
|
+
* something below zero (`signDisplay: "negative"`), so a value rounding to zero is never "-0".
|
|
11
|
+
*/
|
|
12
|
+
function numberFormat(locale = "de-DE", options) {
|
|
13
|
+
return new Intl.NumberFormat(locale, {
|
|
14
|
+
signDisplay: "negative",
|
|
15
|
+
...options
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function toPlaces(format, value) {
|
|
19
|
+
const parts = format.formatToParts(value);
|
|
20
|
+
const text = parts.map((part) => part.value).join("");
|
|
21
|
+
const first = parts.findIndex((part) => BODY.has(part.type));
|
|
22
|
+
if (first === -1) return {
|
|
23
|
+
text,
|
|
24
|
+
places: [{
|
|
25
|
+
key: "pre",
|
|
26
|
+
kind: "symbol",
|
|
27
|
+
text
|
|
28
|
+
}],
|
|
29
|
+
unit: text
|
|
30
|
+
};
|
|
31
|
+
let last = first;
|
|
32
|
+
for (let index = first; index < parts.length; index++) if (BODY.has(parts[index].type)) last = index;
|
|
33
|
+
const places = [];
|
|
34
|
+
let unit = "";
|
|
35
|
+
let run = "";
|
|
36
|
+
let runs = 0;
|
|
37
|
+
const flush = () => {
|
|
38
|
+
if (run) places.push({
|
|
39
|
+
key: runs++ === 0 ? "pre" : "pre2",
|
|
40
|
+
kind: "symbol",
|
|
41
|
+
text: run
|
|
42
|
+
});
|
|
43
|
+
unit += run;
|
|
44
|
+
run = "";
|
|
45
|
+
};
|
|
46
|
+
for (const part of parts.slice(0, first)) if (part.type === "minusSign") {
|
|
47
|
+
flush();
|
|
48
|
+
places.push({
|
|
49
|
+
key: "minus",
|
|
50
|
+
kind: "symbol",
|
|
51
|
+
text: part.value
|
|
52
|
+
});
|
|
53
|
+
} else run += part.value;
|
|
54
|
+
flush();
|
|
55
|
+
const zero = zeroOf(format);
|
|
56
|
+
const digitOf = (character) => (character.codePointAt(0) ?? zero) - zero;
|
|
57
|
+
const body = parts.slice(first, last + 1);
|
|
58
|
+
let integers = body.filter((part) => part.type === "integer").reduce((count, part) => count + part.value.length, 0);
|
|
59
|
+
let fractions = 0;
|
|
60
|
+
for (const part of body) if (part.type === "integer") for (const character of part.value) {
|
|
61
|
+
integers -= 1;
|
|
62
|
+
places.push({
|
|
63
|
+
key: `i${integers}`,
|
|
64
|
+
kind: "digit",
|
|
65
|
+
digit: digitOf(character)
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
else if (part.type === "group") places.push({
|
|
69
|
+
key: `g${integers}`,
|
|
70
|
+
kind: "symbol",
|
|
71
|
+
text: part.value
|
|
72
|
+
});
|
|
73
|
+
else if (part.type === "decimal") places.push({
|
|
74
|
+
key: "decimal",
|
|
75
|
+
kind: "symbol",
|
|
76
|
+
text: part.value
|
|
77
|
+
});
|
|
78
|
+
else if (part.type === "fraction") for (const character of part.value) {
|
|
79
|
+
fractions += 1;
|
|
80
|
+
places.push({
|
|
81
|
+
key: `f${fractions}`,
|
|
82
|
+
kind: "digit",
|
|
83
|
+
digit: digitOf(character)
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
const after = parts.slice(last + 1).map((part) => part.value).join("");
|
|
87
|
+
if (after) places.push({
|
|
88
|
+
key: "post",
|
|
89
|
+
kind: "symbol",
|
|
90
|
+
text: after
|
|
91
|
+
});
|
|
92
|
+
unit += `|${after}`;
|
|
93
|
+
return {
|
|
94
|
+
text,
|
|
95
|
+
places,
|
|
96
|
+
unit
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/** The code point of the format's zero: digits of every numbering system run on from it. */
|
|
100
|
+
function zeroOf(format) {
|
|
101
|
+
return (format.formatToParts(0).find((part) => part.type === "integer")?.value)?.codePointAt(0) ?? 48;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Where each digit place's column stands after a change: a position that only ever grows when
|
|
105
|
+
* the number grows and shrinks when it shrinks, so every column rolls the way the number moves
|
|
106
|
+
* (an odometer: 19 → 20 rolls the ones forward through 0). The digit shown is the position
|
|
107
|
+
* modulo ten. A place that is new starts at its digit; it fades in and does not roll.
|
|
108
|
+
*
|
|
109
|
+
* Worked out from the last target, never from what is on screen, so a change that arrives
|
|
110
|
+
* while the columns still move simply sets a new target.
|
|
111
|
+
*/
|
|
112
|
+
function nextRolls(rolls, places, direction) {
|
|
113
|
+
const next = {};
|
|
114
|
+
for (const place of places) {
|
|
115
|
+
if (place.kind !== "digit") continue;
|
|
116
|
+
const before = rolls[place.key];
|
|
117
|
+
if (before === void 0) {
|
|
118
|
+
next[place.key] = place.digit;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const shown = (before % 10 + 10) % 10;
|
|
122
|
+
const step = direction < 0 ? -((shown - place.digit + 10) % 10) : (place.digit - shown + 10) % 10;
|
|
123
|
+
next[place.key] = before + step;
|
|
124
|
+
}
|
|
125
|
+
return next;
|
|
126
|
+
}
|
|
127
|
+
/** Left to right: what comes before, the integer places from the highest, the fraction. */
|
|
128
|
+
function rank(key) {
|
|
129
|
+
if (key === "pre") return 0;
|
|
130
|
+
if (key === "minus") return 1;
|
|
131
|
+
if (key === "pre2") return 2;
|
|
132
|
+
if (key === "decimal") return 5e4;
|
|
133
|
+
if (key === "post") return 9e4;
|
|
134
|
+
const n = Number(key.slice(1));
|
|
135
|
+
if (key[0] === "i") return 10 + (1e4 - n) * 2;
|
|
136
|
+
if (key[0] === "g") return 10 + (1e4 - n) * 2 + 1;
|
|
137
|
+
return 5e4 + n;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* The places to draw: the value's own, and those of the previous drawing that the value no
|
|
141
|
+
* longer has, kept where they stood and marked as leaving. A leaving place that the value has
|
|
142
|
+
* again comes back as it is (it reverses instead of entering anew).
|
|
143
|
+
*/
|
|
144
|
+
function mergePlaces(shown, places) {
|
|
145
|
+
const keys = new Set(places.map((place) => place.key));
|
|
146
|
+
const merged = places.map((place) => ({
|
|
147
|
+
...place,
|
|
148
|
+
leaving: false
|
|
149
|
+
}));
|
|
150
|
+
for (const place of shown) if (!keys.has(place.key)) merged.push({
|
|
151
|
+
...place,
|
|
152
|
+
leaving: true
|
|
153
|
+
});
|
|
154
|
+
return merged.sort((a, b) => rank(a.key) - rank(b.key));
|
|
155
|
+
}
|
|
156
|
+
export { mergePlaces, nextRolls, numberFormat, toPlaces };
|
|
@@ -7,8 +7,8 @@ import { PopoverClose, PopoverContent, PopoverTrigger } from "../components/popo
|
|
|
7
7
|
import { TimeField } from "../components/time-field/time-field.js";
|
|
8
8
|
import { FieldDisabledContext } from "./field-context.js";
|
|
9
9
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
-
import { Calendar03Icon } from "@hugeicons/core-free-icons";
|
|
11
10
|
import { useContext, useRef } from "react";
|
|
11
|
+
import { Calendar03Icon } from "@hugeicons/core-free-icons";
|
|
12
12
|
// src/internal/picker-sheet.tsx
|
|
13
13
|
/**
|
|
14
14
|
* The button at the end of a date field that opens its calendar. A field that cannot be changed
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { cn } from "../lib/cn.js";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
// src/internal/presence-dot.tsx
|
|
4
|
+
const look = {
|
|
5
|
+
online: "bg-success-solid forced-colors:bg-[CanvasText]",
|
|
6
|
+
away: "bg-warning-solid forced-colors:bg-[CanvasText]",
|
|
7
|
+
offline: "inset-ring-[1.5px] inset-ring-fg-muted forced-colors:outline forced-colors:outline-1 forced-colors:-outline-offset-1 forced-colors:outline-[CanvasText]"
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* The dot on the edge of an avatar, at the bottom end, that says whether the person is there. It stands
|
|
11
|
+
* beside the avatar, not in it (the avatar is masked, and a dot inside would be cut out with
|
|
12
|
+
* it), and the avatar has a hole cut for it the gap larger (`avatar-cut.ts`). Its words are
|
|
13
|
+
* said elsewhere: the dot alone never carries the status. Server-safe.
|
|
14
|
+
*/
|
|
15
|
+
function PresenceDot({ presence, diameter, slot, className }) {
|
|
16
|
+
return /* @__PURE__ */ jsx("span", {
|
|
17
|
+
"aria-hidden": true,
|
|
18
|
+
"data-slot": slot,
|
|
19
|
+
"data-presence": presence,
|
|
20
|
+
style: { "--dot": `${diameter / 16}rem` },
|
|
21
|
+
className: cn("pointer-events-none absolute end-0 bottom-0 size-(--dot) rounded-full transition-[background-color,box-shadow] spring-settle", look[presence], className)
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export { PresenceDot };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
// src/internal/presence.tsx
|
|
4
|
+
/**
|
|
5
|
+
* Whether a list has stood for a frame. Page load does not animate: what is there when a list
|
|
6
|
+
* first shows stands still, and only what joins afterwards comes in. Put the result on the list
|
|
7
|
+
* as `data-live` and gate the entrance with `in-data-live:starting:*`.
|
|
8
|
+
*/
|
|
9
|
+
function useLive() {
|
|
10
|
+
const [live, setLive] = useState(false);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const frame = requestAnimationFrame(() => setLive(true));
|
|
13
|
+
return () => cancelAnimationFrame(frame);
|
|
14
|
+
}, []);
|
|
15
|
+
return live;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The items of a row, and with them those that were just taken out of it: what its owner removes
|
|
19
|
+
* is kept where it stood until it has left, so it can fade and its place can close. The owner's
|
|
20
|
+
* list is already without it; only the picture lags.
|
|
21
|
+
*
|
|
22
|
+
* Draw every place with `placeProps`, inside the box of `boxRef`: a place says when its
|
|
23
|
+
* transition has ended, and the hook finds the places that never started one.
|
|
24
|
+
*
|
|
25
|
+
* Hand it the same array for as long as nothing changed: memoise a list made from `children`
|
|
26
|
+
* on `children`. The hook keeps the list as it was last drawn, so what leaves goes as it last
|
|
27
|
+
* looked (a file removed mid-upload, not as it stood when the list last gained or lost one),
|
|
28
|
+
* and a new array every render would never let it settle.
|
|
29
|
+
*/
|
|
30
|
+
function usePresence(items, keyOf, boxRef) {
|
|
31
|
+
const [before, setBefore] = useState(items);
|
|
32
|
+
const [leavers, setLeavers] = useState([]);
|
|
33
|
+
const keys = items.map(keyOf);
|
|
34
|
+
if (before !== items) {
|
|
35
|
+
if (before.map(keyOf).join("\n") !== keys.join("\n")) {
|
|
36
|
+
const stays = new Set(keys);
|
|
37
|
+
const gone = before.map((item, index) => ({
|
|
38
|
+
item,
|
|
39
|
+
key: keyOf(item),
|
|
40
|
+
index
|
|
41
|
+
})).filter(({ key }) => !stays.has(key));
|
|
42
|
+
setLeavers((old) => [...old.filter(({ key }) => !stays.has(key)), ...gone]);
|
|
43
|
+
}
|
|
44
|
+
setBefore(items);
|
|
45
|
+
}
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (leavers.length === 0) return;
|
|
48
|
+
const frame = requestAnimationFrame(() => {
|
|
49
|
+
const moving = /* @__PURE__ */ new Set();
|
|
50
|
+
boxRef.current?.querySelectorAll("[data-leaving][data-key]").forEach((place) => {
|
|
51
|
+
if (place.getAnimations().length > 0) moving.add(place.dataset.key);
|
|
52
|
+
});
|
|
53
|
+
setLeavers((old) => {
|
|
54
|
+
const next = old.filter(({ key }) => moving.has(key));
|
|
55
|
+
return next.length === old.length ? old : next;
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
return () => cancelAnimationFrame(frame);
|
|
59
|
+
}, [leavers, boxRef]);
|
|
60
|
+
const left = (key) => setLeavers((old) => old.filter((leaver) => leaver.key !== key));
|
|
61
|
+
const places = items.map((item, index) => ({
|
|
62
|
+
item,
|
|
63
|
+
key: keys[index] ?? "",
|
|
64
|
+
leaving: false
|
|
65
|
+
}));
|
|
66
|
+
for (const { item, key, index } of leavers) places.splice(Math.min(index, places.length), 0, {
|
|
67
|
+
item,
|
|
68
|
+
key,
|
|
69
|
+
leaving: true
|
|
70
|
+
});
|
|
71
|
+
return {
|
|
72
|
+
places,
|
|
73
|
+
left
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* What every place carries: its key, whether it is leaving, and the two events that say it has
|
|
78
|
+
* left. What has left the owner's list can no longer be pressed or focused (`inert`).
|
|
79
|
+
*/
|
|
80
|
+
function placeProps(place, left) {
|
|
81
|
+
const ended = (event) => {
|
|
82
|
+
if (place.leaving && event.target === event.currentTarget) left(place.key);
|
|
83
|
+
};
|
|
84
|
+
return {
|
|
85
|
+
"data-key": place.key,
|
|
86
|
+
"data-leaving": place.leaving ? "" : void 0,
|
|
87
|
+
inert: place.leaving,
|
|
88
|
+
onTransitionEnd: ended,
|
|
89
|
+
onTransitionCancel: ended
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* A place in a row: a grid of one column that opens from nothing and closes to nothing. What
|
|
94
|
+
* stands in it keeps its size all the while; only its place changes, which moves its
|
|
95
|
+
* neighbours. The row's gap is the variable `--chip-gap`, because a place that closes has to
|
|
96
|
+
* take its gap with it. What stands inside has faded before the place closes (the delay), so it
|
|
97
|
+
* is never seen under a neighbour.
|
|
98
|
+
*/
|
|
99
|
+
const placeInRow = [
|
|
100
|
+
"inline-grid grid-cols-[1fr] transition-[grid-template-columns,margin] spring-settle",
|
|
101
|
+
"in-data-live:starting:-mr-(--chip-gap) in-data-live:starting:grid-cols-[0fr]",
|
|
102
|
+
"data-leaving:-mr-(--chip-gap) data-leaving:grid-cols-[0fr] data-leaving:delay-75"
|
|
103
|
+
].join(" ");
|
|
104
|
+
export { placeInRow, placeProps, useLive, usePresence };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Icon } from "../components/icon/icon.js";
|
|
2
|
+
import { Spinner } from "../components/spinner/spinner.js";
|
|
3
|
+
import { cn } from "../lib/cn.js";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
import { Alert02Icon } from "@hugeicons/core-free-icons";
|
|
6
|
+
// src/internal/rail-mark.tsx
|
|
7
|
+
/**
|
|
8
|
+
* The mark in front of an entry on a rail (`rail.css`): an open ring waits, the spinner's arc
|
|
9
|
+
* works (it is the ring before it has closed), the disc is done, and a failure carries the danger
|
|
10
|
+
* symbol. Shared by `Trace` and `Timeline`, so both lists are drawn by the same hand.
|
|
11
|
+
*
|
|
12
|
+
* A 16px box, hidden from assistive tech: the entry says its state in words. Server-safe.
|
|
13
|
+
*/
|
|
14
|
+
function RailMark({ slot, status, icon, enter, className }) {
|
|
15
|
+
return /* @__PURE__ */ jsx("span", {
|
|
16
|
+
"aria-hidden": true,
|
|
17
|
+
"data-slot": slot,
|
|
18
|
+
className: cn("flex size-4 shrink-0 items-center justify-center", className),
|
|
19
|
+
children: status === "running" ? /* @__PURE__ */ jsx(Spinner, {
|
|
20
|
+
size: 14,
|
|
21
|
+
className: "text-fg"
|
|
22
|
+
}) : status === "error" ? /* @__PURE__ */ jsx(Icon, {
|
|
23
|
+
icon: Alert02Icon,
|
|
24
|
+
size: 14,
|
|
25
|
+
className: "text-danger"
|
|
26
|
+
}) : icon && status === "done" ? /* @__PURE__ */ jsx(Icon, {
|
|
27
|
+
icon,
|
|
28
|
+
size: 14,
|
|
29
|
+
className: cn("text-fg-muted transition-opacity spring-settle", enter?.icon)
|
|
30
|
+
}) : /* @__PURE__ */ jsx("span", { className: cn("mark", status === "done" && cn("mark-on", enter?.disc)) })
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
export { RailMark };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Alert02Icon, AlertCircleIcon, CheckmarkCircle02Icon, InformationCircleIcon } from "@hugeicons/core-free-icons";
|
|
2
|
+
// src/internal/status-icon.ts
|
|
3
|
+
/**
|
|
4
|
+
* The symbol of each status, the same in an `Alert`, a toast and a `Banner`: a status never
|
|
5
|
+
* relies on colour, it always has a symbol and words. Server-safe.
|
|
6
|
+
*/
|
|
7
|
+
const statusIcons = {
|
|
8
|
+
neutral: InformationCircleIcon,
|
|
9
|
+
info: InformationCircleIcon,
|
|
10
|
+
success: CheckmarkCircle02Icon,
|
|
11
|
+
warning: Alert02Icon,
|
|
12
|
+
danger: AlertCircleIcon
|
|
13
|
+
};
|
|
14
|
+
/** The colour of each status symbol. Indigo is never spent on an icon: info stays in the text colour. */
|
|
15
|
+
const statusIconTone = {
|
|
16
|
+
neutral: "text-fg-muted",
|
|
17
|
+
info: "text-fg",
|
|
18
|
+
success: "text-success",
|
|
19
|
+
warning: "text-warning",
|
|
20
|
+
danger: "text-danger"
|
|
21
|
+
};
|
|
22
|
+
export { statusIconTone, statusIcons };
|
|
@@ -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,7 @@ const depthNames = [
|
|
|
19
19
|
"field-focus",
|
|
20
20
|
"field-invalid",
|
|
21
21
|
"card",
|
|
22
|
+
"card-chosen",
|
|
22
23
|
"floating",
|
|
23
24
|
"overlay",
|
|
24
25
|
"bar",
|
|
@@ -42,6 +43,8 @@ const shadowNames = [
|
|
|
42
43
|
"field-focus",
|
|
43
44
|
"field-invalid",
|
|
44
45
|
"card",
|
|
46
|
+
"card-hover",
|
|
47
|
+
"card-pressed",
|
|
45
48
|
"floating",
|
|
46
49
|
"overlay",
|
|
47
50
|
"bar"
|
|
@@ -54,6 +57,7 @@ const insetShadowNames = [
|
|
|
54
57
|
"trough",
|
|
55
58
|
"field",
|
|
56
59
|
"card",
|
|
60
|
+
"card-chosen",
|
|
57
61
|
"sheet",
|
|
58
62
|
"bar"
|
|
59
63
|
];
|
|
@@ -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";
|