loseta 0.16.0 → 0.18.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/README.md +33 -8
- package/dist/commands/add.d.ts +8 -0
- package/dist/commands/add.js +60 -15
- package/dist/commands/add.js.map +1 -1
- package/dist/commands/init.js +2 -1
- package/dist/commands/init.js.map +1 -1
- package/dist/config.d.ts +7 -0
- package/dist/config.js +13 -0
- package/dist/config.js.map +1 -1
- package/dist/imports.d.ts +4 -0
- package/dist/imports.js +30 -2
- package/dist/imports.js.map +1 -1
- package/dist/install.d.ts +23 -3
- package/dist/install.js +84 -5
- package/dist/install.js.map +1 -1
- package/dist/style-switch.js +2 -1
- package/dist/style-switch.js.map +1 -1
- package/dist/types.d.ts +11 -0
- package/dist/ui.js +4 -1
- package/dist/ui.js.map +1 -1
- package/package.json +4 -3
- package/registry/behaviors/code-block.js +106 -0
- package/registry/behaviors/combobox.js +237 -0
- package/registry/behaviors/command.js +105 -0
- package/registry/behaviors/core.js +302 -0
- package/registry/behaviors/dialog.js +97 -0
- package/registry/behaviors/listbox.js +135 -0
- package/registry/behaviors/menu.js +586 -0
- package/registry/behaviors/popover.js +127 -0
- package/registry/behaviors/select.js +196 -0
- package/registry/behaviors/tabs.js +95 -0
- package/registry/behaviors/toast.js +137 -0
- package/registry/components/badge.css +4 -7
- package/registry/components/breadcrumb.css +9 -1
- package/registry/components/calendar.css +39 -0
- package/registry/components/card.css +5 -0
- package/registry/components/code-block.css +19 -0
- package/registry/components/input-otp.css +103 -10
- package/registry/components/kbd.css +8 -0
- package/registry/components/native-select.css +6 -0
- package/registry/components/select.css +3 -0
- package/registry/components/tooltip.css +295 -144
- package/registry/examples/alert-dialog.html +21 -21
- package/registry/examples/badge.html +37 -0
- package/registry/examples/breadcrumb.html +86 -6
- package/registry/examples/button-group.html +3 -3
- package/registry/examples/calendar.html +687 -51
- package/registry/examples/card.html +190 -4
- package/registry/examples/code-block.html +10 -4
- package/registry/examples/combobox.html +2 -0
- package/registry/examples/command.html +17 -17
- package/registry/examples/context-menu.html +18 -18
- package/registry/examples/dialog.html +15 -15
- package/registry/examples/drawer.html +22 -22
- package/registry/examples/input-otp.html +116 -11
- package/registry/examples/kbd.html +90 -2
- package/registry/examples/native-select.html +83 -2
- package/registry/examples/select.html +206 -6
- package/registry/examples/sheet.html +23 -23
- package/registry/examples/sidebar.html +11 -11
- package/registry/examples/toast.html +11 -0
- package/registry/examples/tooltip.html +75 -70
- package/registry/primitives/dialog-shell.css +5 -0
- package/registry/primitives/menu.css +15 -3
- package/registry/registry.json +231 -9
- package/registry/schema.json +17 -0
- package/registry/styles/luma/badge.css +28 -0
- package/registry/styles/luma/breadcrumb.css +2 -1
- package/registry/styles/luma/calendar.css +62 -0
- package/registry/styles/luma/card.css +9 -27
- package/registry/styles/luma/input-otp.css +79 -36
- package/registry/styles/luma/native-select.css +9 -2
- package/registry/styles/luma/primitives/listbox.css +8 -0
- package/registry/styles/luma/select.css +7 -2
- package/registry/styles/luma/tooltip.css +29 -16
- package/registry/styles/lyra/badge.css +28 -0
- package/registry/styles/lyra/breadcrumb.css +2 -1
- package/registry/styles/lyra/calendar.css +62 -0
- package/registry/styles/lyra/card.css +9 -27
- package/registry/styles/lyra/input-otp.css +79 -36
- package/registry/styles/lyra/native-select.css +6 -1
- package/registry/styles/lyra/primitives/listbox.css +8 -0
- package/registry/styles/lyra/select.css +6 -1
- package/registry/styles/lyra/tooltip.css +29 -16
- package/registry/styles/maia/badge.css +29 -0
- package/registry/styles/maia/breadcrumb.css +2 -1
- package/registry/styles/maia/calendar.css +62 -0
- package/registry/styles/maia/card.css +9 -27
- package/registry/styles/maia/input-otp.css +79 -36
- package/registry/styles/maia/native-select.css +9 -2
- package/registry/styles/maia/primitives/listbox.css +8 -0
- package/registry/styles/maia/select.css +7 -2
- package/registry/styles/maia/tooltip.css +29 -16
- package/registry/styles/mira/badge.css +32 -0
- package/registry/styles/mira/breadcrumb.css +2 -1
- package/registry/styles/mira/calendar.css +62 -0
- package/registry/styles/mira/card.css +9 -27
- package/registry/styles/mira/input-otp.css +79 -36
- package/registry/styles/mira/native-select.css +7 -2
- package/registry/styles/mira/primitives/listbox.css +8 -0
- package/registry/styles/mira/select.css +7 -2
- package/registry/styles/mira/tooltip.css +29 -16
- package/registry/styles/nova/badge.css +28 -0
- package/registry/styles/nova/breadcrumb.css +2 -1
- package/registry/styles/nova/calendar.css +62 -0
- package/registry/styles/nova/card.css +9 -27
- package/registry/styles/nova/input-otp.css +79 -36
- package/registry/styles/nova/native-select.css +9 -2
- package/registry/styles/nova/primitives/listbox.css +8 -0
- package/registry/styles/nova/select.css +7 -2
- package/registry/styles/nova/tooltip.css +29 -16
- package/registry/styles/rhea/badge.css +28 -0
- package/registry/styles/rhea/breadcrumb.css +2 -1
- package/registry/styles/rhea/calendar.css +62 -0
- package/registry/styles/rhea/card.css +9 -27
- package/registry/styles/rhea/input-otp.css +79 -36
- package/registry/styles/rhea/native-select.css +9 -2
- package/registry/styles/rhea/primitives/listbox.css +8 -0
- package/registry/styles/rhea/select.css +7 -2
- package/registry/styles/rhea/tooltip.css +29 -16
- package/registry/styles/sera/badge.css +29 -1
- package/registry/styles/sera/breadcrumb.css +2 -1
- package/registry/styles/sera/calendar.css +66 -0
- package/registry/styles/sera/card.css +9 -27
- package/registry/styles/sera/input-otp.css +80 -37
- package/registry/styles/sera/native-select.css +9 -2
- package/registry/styles/sera/primitives/listbox.css +8 -0
- package/registry/styles/sera/select.css +7 -2
- package/registry/styles/sera/tooltip.css +29 -16
- package/registry/styles/vega/badge.css +28 -0
- package/registry/styles/vega/breadcrumb.css +2 -1
- package/registry/styles/vega/calendar.css +62 -0
- package/registry/styles/vega/card.css +9 -27
- package/registry/styles/vega/input-otp.css +79 -36
- package/registry/styles/vega/native-select.css +9 -2
- package/registry/styles/vega/primitives/listbox.css +8 -0
- package/registry/styles/vega/select.css +7 -2
- package/registry/styles/vega/tooltip.css +29 -16
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
emit,
|
|
5
|
+
init,
|
|
6
|
+
on,
|
|
7
|
+
onDocument,
|
|
8
|
+
panelFor,
|
|
9
|
+
typeaheadTarget
|
|
10
|
+
} from "./core.js";
|
|
11
|
+
import {
|
|
12
|
+
firstOption,
|
|
13
|
+
highlight,
|
|
14
|
+
lastOption,
|
|
15
|
+
listboxIn,
|
|
16
|
+
moveHighlight,
|
|
17
|
+
resetFilter,
|
|
18
|
+
selectOption,
|
|
19
|
+
selectedOptions,
|
|
20
|
+
visibleOptions
|
|
21
|
+
} from "./listbox.js";
|
|
22
|
+
|
|
23
|
+
/** @param {HTMLElement} control */
|
|
24
|
+
function rootOf(control) {
|
|
25
|
+
return control.closest(".select") ?? control.parentElement ?? control;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** @param {HTMLElement} control */
|
|
29
|
+
function parts(control) {
|
|
30
|
+
const panel = panelFor(control);
|
|
31
|
+
const listbox = panel ? listboxIn(panel) : null;
|
|
32
|
+
return { panel, listbox };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** @param {HTMLElement} control */
|
|
36
|
+
function isExpanded(control) {
|
|
37
|
+
return control.getAttribute("aria-expanded") === "true";
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** @param {HTMLElement} control @param {boolean} open */
|
|
41
|
+
function setExpanded(control, open) {
|
|
42
|
+
const { panel } = parts(control);
|
|
43
|
+
control.setAttribute("aria-expanded", String(open));
|
|
44
|
+
if (panel) panel.setAttribute("aria-hidden", String(!open));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** @param {HTMLElement} control */
|
|
48
|
+
function openSelect(control) {
|
|
49
|
+
const { panel, listbox } = parts(control);
|
|
50
|
+
if (!panel || !listbox) return;
|
|
51
|
+
|
|
52
|
+
resetFilter(listbox);
|
|
53
|
+
setExpanded(control, true);
|
|
54
|
+
|
|
55
|
+
const selected = selectedOptions(listbox)[0] ?? firstOption(listbox);
|
|
56
|
+
highlight(listbox, selected, control);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** @param {HTMLElement} control @param {boolean} focusTrigger */
|
|
60
|
+
function closeSelect(control, focusTrigger) {
|
|
61
|
+
const { listbox } = parts(control);
|
|
62
|
+
setExpanded(control, false);
|
|
63
|
+
if (listbox) highlight(listbox, null, control);
|
|
64
|
+
if (focusTrigger) control.focus();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** @param {HTMLElement} control @param {Element} option */
|
|
68
|
+
function choose(control, option) {
|
|
69
|
+
const { listbox } = parts(control);
|
|
70
|
+
if (!listbox) return;
|
|
71
|
+
|
|
72
|
+
const values = selectOption(listbox, option, false);
|
|
73
|
+
const value = values[0] ?? "";
|
|
74
|
+
const root = rootOf(control);
|
|
75
|
+
const valueSlot = root.querySelector("[data-slot='value']");
|
|
76
|
+
if (valueSlot instanceof HTMLElement) {
|
|
77
|
+
valueSlot.textContent = value;
|
|
78
|
+
valueSlot.removeAttribute("data-placeholder");
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const hidden = root.querySelector("input[data-slot='input']");
|
|
82
|
+
if (hidden instanceof HTMLInputElement) hidden.value = value;
|
|
83
|
+
|
|
84
|
+
emit(root, "change", { value });
|
|
85
|
+
closeSelect(control, true);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
on("click", ".select [role='combobox']", (event, target) => {
|
|
89
|
+
if (!(target instanceof HTMLElement)) return;
|
|
90
|
+
if (isExpanded(target)) {
|
|
91
|
+
closeSelect(target, true);
|
|
92
|
+
} else {
|
|
93
|
+
openSelect(target);
|
|
94
|
+
}
|
|
95
|
+
event.preventDefault();
|
|
96
|
+
return true;
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
on("click", ".select [role='option']", (event, target) => {
|
|
100
|
+
if (!(target instanceof HTMLElement) || target.getAttribute("aria-disabled") === "true") {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const control = target.closest(".select")?.querySelector("[role='combobox']");
|
|
104
|
+
if (control instanceof HTMLElement) choose(control, target);
|
|
105
|
+
event.preventDefault();
|
|
106
|
+
return true;
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
on("keydown", ".select [role='combobox']", (event, target) => {
|
|
110
|
+
if (!(event instanceof KeyboardEvent) || !(target instanceof HTMLElement)) return;
|
|
111
|
+
const { listbox } = parts(target);
|
|
112
|
+
if (!listbox) return;
|
|
113
|
+
const expanded = isExpanded(target);
|
|
114
|
+
|
|
115
|
+
if (event.key === "Escape") {
|
|
116
|
+
if (!expanded) return;
|
|
117
|
+
closeSelect(target, true);
|
|
118
|
+
event.preventDefault();
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (!expanded) {
|
|
123
|
+
const opens =
|
|
124
|
+
event.key === "ArrowDown" ||
|
|
125
|
+
event.key === "ArrowUp" ||
|
|
126
|
+
event.key === "Enter" ||
|
|
127
|
+
event.key === " ";
|
|
128
|
+
if (opens) {
|
|
129
|
+
openSelect(target);
|
|
130
|
+
if (event.key === "ArrowUp") {
|
|
131
|
+
highlight(listbox, lastOption(listbox), target);
|
|
132
|
+
}
|
|
133
|
+
event.preventDefault();
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey) {
|
|
138
|
+
openSelect(target);
|
|
139
|
+
const match = typeaheadTarget(listbox, event.key, visibleOptions(listbox), null);
|
|
140
|
+
if (match) highlight(listbox, match, target);
|
|
141
|
+
event.preventDefault();
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
148
|
+
const next = moveHighlight(listbox, event.key === "ArrowDown" ? 1 : -1);
|
|
149
|
+
if (next) highlight(listbox, next, target);
|
|
150
|
+
event.preventDefault();
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (event.key === "Home" || event.key === "End") {
|
|
155
|
+
highlight(listbox, event.key === "Home" ? firstOption(listbox) : lastOption(listbox), target);
|
|
156
|
+
event.preventDefault();
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
161
|
+
const option = listbox.querySelector("[data-highlighted]");
|
|
162
|
+
if (option instanceof HTMLElement) choose(target, option);
|
|
163
|
+
event.preventDefault();
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (event.key === "Tab") {
|
|
168
|
+
closeSelect(target, false);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey) {
|
|
173
|
+
const current = listbox.querySelector("[data-highlighted]");
|
|
174
|
+
const match = typeaheadTarget(
|
|
175
|
+
listbox,
|
|
176
|
+
event.key,
|
|
177
|
+
visibleOptions(listbox),
|
|
178
|
+
current instanceof Element ? current : null
|
|
179
|
+
);
|
|
180
|
+
if (match) highlight(listbox, match, target);
|
|
181
|
+
event.preventDefault();
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
}, 25);
|
|
185
|
+
|
|
186
|
+
onDocument("pointerdown", (event) => {
|
|
187
|
+
if (!(event.target instanceof Node)) return;
|
|
188
|
+
for (const control of document.querySelectorAll(".select [role='combobox']")) {
|
|
189
|
+
if (!(control instanceof HTMLElement) || !isExpanded(control)) continue;
|
|
190
|
+
const root = rootOf(control);
|
|
191
|
+
if (root.contains(event.target)) continue;
|
|
192
|
+
closeSelect(control, false);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
init();
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
emit,
|
|
5
|
+
firstEnabled,
|
|
6
|
+
init,
|
|
7
|
+
isDisabled,
|
|
8
|
+
lastEnabled,
|
|
9
|
+
nextEnabled,
|
|
10
|
+
on,
|
|
11
|
+
panelFor
|
|
12
|
+
} from "./core.js";
|
|
13
|
+
|
|
14
|
+
const TAB_SELECTOR = "[role='tab']";
|
|
15
|
+
|
|
16
|
+
/** @param {Element} tab */
|
|
17
|
+
function tablistOf(tab) {
|
|
18
|
+
const tablist = tab.closest("[role='tablist']");
|
|
19
|
+
return tablist instanceof HTMLElement ? tablist : null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** @param {Element} tablist */
|
|
23
|
+
function tabsOf(tablist) {
|
|
24
|
+
return [...tablist.querySelectorAll(TAB_SELECTOR)].filter(
|
|
25
|
+
(tab) => tab.closest("[role='tablist']") === tablist
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** @param {Element} tab */
|
|
30
|
+
function rootOf(tab) {
|
|
31
|
+
return tab.closest(".tabs") ?? tablistOf(tab) ?? tab;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @param {Element} tab
|
|
36
|
+
* @param {boolean} focus
|
|
37
|
+
*/
|
|
38
|
+
function selectTab(tab, focus) {
|
|
39
|
+
const tablist = tablistOf(tab);
|
|
40
|
+
if (!tablist) return;
|
|
41
|
+
|
|
42
|
+
const tabs = tabsOf(tablist);
|
|
43
|
+
for (const candidate of tabs) {
|
|
44
|
+
const selected = candidate === tab;
|
|
45
|
+
candidate.setAttribute("aria-selected", String(selected));
|
|
46
|
+
candidate.setAttribute("tabindex", selected ? "0" : "-1");
|
|
47
|
+
|
|
48
|
+
const panel = panelFor(candidate);
|
|
49
|
+
if (panel instanceof HTMLElement) {
|
|
50
|
+
panel.hidden = !selected;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
emit(rootOf(tab), "change", { value: tab.id });
|
|
55
|
+
if (focus && tab instanceof HTMLElement) tab.focus();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
on("click", ".tabs [role='tab']", (event, target) => {
|
|
59
|
+
if (!(target instanceof HTMLElement) || isDisabled(target)) return;
|
|
60
|
+
selectTab(target, false);
|
|
61
|
+
event.preventDefault();
|
|
62
|
+
return true;
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
on("keydown", ".tabs [role='tab']", (event, target) => {
|
|
66
|
+
if (!(event instanceof KeyboardEvent)) return;
|
|
67
|
+
if (!(target instanceof HTMLElement)) return;
|
|
68
|
+
const tablist = tablistOf(target);
|
|
69
|
+
if (!tablist) return;
|
|
70
|
+
|
|
71
|
+
const tabs = tabsOf(tablist);
|
|
72
|
+
const vertical = tablist.getAttribute("aria-orientation") === "vertical";
|
|
73
|
+
const nextKey = vertical ? "ArrowDown" : "ArrowRight";
|
|
74
|
+
const previousKey = vertical ? "ArrowUp" : "ArrowLeft";
|
|
75
|
+
|
|
76
|
+
if (event.key === nextKey || event.key === previousKey) {
|
|
77
|
+
const next = nextEnabled(
|
|
78
|
+
tabs,
|
|
79
|
+
target,
|
|
80
|
+
event.key === nextKey ? 1 : -1
|
|
81
|
+
);
|
|
82
|
+
if (next instanceof HTMLElement) selectTab(next, true);
|
|
83
|
+
event.preventDefault();
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (event.key === "Home" || event.key === "End") {
|
|
88
|
+
const next = event.key === "Home" ? firstEnabled(tabs) : lastEnabled(tabs);
|
|
89
|
+
if (next instanceof HTMLElement) selectTab(next, true);
|
|
90
|
+
event.preventDefault();
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
init();
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { emit, init, on } from "./core.js";
|
|
4
|
+
|
|
5
|
+
const DEFAULT_DURATION = 5000;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {object} ToastState
|
|
9
|
+
* @property {number} duration
|
|
10
|
+
* @property {number} remaining
|
|
11
|
+
* @property {number} startedAt
|
|
12
|
+
* @property {number} timer
|
|
13
|
+
* @property {boolean} paused
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** @type {WeakMap<HTMLElement, ToastState>} */
|
|
17
|
+
const states = new WeakMap();
|
|
18
|
+
|
|
19
|
+
/** @param {Element} toast */
|
|
20
|
+
function durationOf(toast) {
|
|
21
|
+
const raw = toast.getAttribute("data-duration");
|
|
22
|
+
if (raw === null) return DEFAULT_DURATION;
|
|
23
|
+
const value = Number(raw);
|
|
24
|
+
return Number.isFinite(value) ? Math.max(0, value) : DEFAULT_DURATION;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** @param {HTMLElement} toast */
|
|
28
|
+
function startTimer(toast) {
|
|
29
|
+
const state = states.get(toast);
|
|
30
|
+
if (!state || state.duration === 0) return;
|
|
31
|
+
state.startedAt = Date.now();
|
|
32
|
+
state.paused = false;
|
|
33
|
+
state.timer = window.setTimeout(() => dismiss(toast, "timeout"), state.remaining);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** @param {HTMLElement} toast */
|
|
37
|
+
function arm(toast) {
|
|
38
|
+
if (states.has(toast) || toast.hasAttribute("hidden")) return;
|
|
39
|
+
const duration = durationOf(toast);
|
|
40
|
+
states.set(toast, {
|
|
41
|
+
duration,
|
|
42
|
+
remaining: duration,
|
|
43
|
+
startedAt: 0,
|
|
44
|
+
timer: 0,
|
|
45
|
+
paused: false
|
|
46
|
+
});
|
|
47
|
+
startTimer(toast);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** @param {HTMLElement} toast */
|
|
51
|
+
function pause(toast) {
|
|
52
|
+
const state = states.get(toast);
|
|
53
|
+
if (!state || state.paused || state.duration === 0) return;
|
|
54
|
+
window.clearTimeout(state.timer);
|
|
55
|
+
state.remaining = Math.max(0, state.remaining - (Date.now() - state.startedAt));
|
|
56
|
+
state.paused = true;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** @param {HTMLElement} toast */
|
|
60
|
+
function resume(toast) {
|
|
61
|
+
const state = states.get(toast);
|
|
62
|
+
if (!state || !state.paused || state.duration === 0) return;
|
|
63
|
+
startTimer(toast);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** @param {HTMLElement} toast @param {"timeout" | "close"} reason */
|
|
67
|
+
function dismiss(toast, reason) {
|
|
68
|
+
const state = states.get(toast);
|
|
69
|
+
if (state) {
|
|
70
|
+
window.clearTimeout(state.timer);
|
|
71
|
+
states.delete(toast);
|
|
72
|
+
}
|
|
73
|
+
toast.hidden = true;
|
|
74
|
+
emit(toast, "dismiss", { reason });
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** @param {ParentNode} root */
|
|
78
|
+
function armAll(root) {
|
|
79
|
+
for (const toast of root.querySelectorAll(".toast")) {
|
|
80
|
+
if (toast instanceof HTMLElement) arm(toast);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
on("click", ".toast [data-slot='close']", (event, target) => {
|
|
85
|
+
if (!(target instanceof HTMLElement)) return;
|
|
86
|
+
const toast = target.closest(".toast");
|
|
87
|
+
if (!(toast instanceof HTMLElement)) return;
|
|
88
|
+
dismiss(toast, "close");
|
|
89
|
+
event.preventDefault();
|
|
90
|
+
return true;
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
on("pointerover", ".toast", (_event, target) => {
|
|
94
|
+
if (!(target instanceof HTMLElement)) return;
|
|
95
|
+
pause(target);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
on("pointerout", ".toast", (event, target) => {
|
|
99
|
+
if (!(target instanceof HTMLElement)) return;
|
|
100
|
+
const next = event instanceof PointerEvent ? event.relatedTarget : null;
|
|
101
|
+
if (next instanceof Node && target.contains(next)) return;
|
|
102
|
+
resume(target);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
on("focusin", ".toast", (_event, target) => {
|
|
106
|
+
if (!(target instanceof HTMLElement)) return;
|
|
107
|
+
pause(target);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
on("focusout", ".toast", (event, target) => {
|
|
111
|
+
if (!(target instanceof HTMLElement) || !(event instanceof FocusEvent)) return;
|
|
112
|
+
const next = event.relatedTarget;
|
|
113
|
+
if (next instanceof Node && target.contains(next)) return;
|
|
114
|
+
resume(target);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
init();
|
|
118
|
+
|
|
119
|
+
if (typeof document !== "undefined") {
|
|
120
|
+
const armExisting = () => armAll(document);
|
|
121
|
+
if (document.readyState === "loading") {
|
|
122
|
+
document.addEventListener("DOMContentLoaded", armExisting, { once: true });
|
|
123
|
+
} else {
|
|
124
|
+
armExisting();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const observer = new MutationObserver((records) => {
|
|
128
|
+
for (const record of records) {
|
|
129
|
+
for (const node of record.addedNodes) {
|
|
130
|
+
if (!(node instanceof Element)) continue;
|
|
131
|
+
if (node.matches(".toast")) arm(/** @type {HTMLElement} */ (node));
|
|
132
|
+
armAll(node);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
observer.observe(document.documentElement, { childList: true, subtree: true });
|
|
137
|
+
}
|
|
@@ -8,14 +8,11 @@
|
|
|
8
8
|
justify-content: center;
|
|
9
9
|
overflow: hidden;
|
|
10
10
|
white-space: nowrap;
|
|
11
|
+
outline-style: none;
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
&[aria-invalid='true'] {
|
|
18
|
-
border-color: var(--destructive);
|
|
13
|
+
@media (forced-colors: active) {
|
|
14
|
+
outline: 2px solid transparent;
|
|
15
|
+
outline-offset: 2px;
|
|
19
16
|
}
|
|
20
17
|
|
|
21
18
|
> svg {
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
:is(a, button)
|
|
30
|
+
> ol > li > :is(a, button),
|
|
31
|
+
> ol > li > :is(.dropdown-menu, .popover) > button {
|
|
31
32
|
outline-style: none;
|
|
32
33
|
|
|
33
34
|
@media (forced-colors: active) {
|
|
@@ -36,6 +37,13 @@
|
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
|
|
40
|
+
> ol > li > button,
|
|
41
|
+
> ol > li > :is(.dropdown-menu, .popover) > button {
|
|
42
|
+
display: inline-flex;
|
|
43
|
+
align-items: center;
|
|
44
|
+
gap: 0.25rem;
|
|
45
|
+
}
|
|
46
|
+
|
|
39
47
|
[aria-current='page'] {
|
|
40
48
|
cursor: default;
|
|
41
49
|
}
|
|
@@ -22,6 +22,45 @@
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
> header > [data-slot='caption'] {
|
|
26
|
+
display: inline-flex;
|
|
27
|
+
align-items: center;
|
|
28
|
+
justify-content: center;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
> header [data-slot='dropdown'] {
|
|
32
|
+
position: relative;
|
|
33
|
+
display: inline-flex;
|
|
34
|
+
align-items: center;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
> header [data-slot='dropdown'] > select {
|
|
38
|
+
appearance: none;
|
|
39
|
+
border: 0;
|
|
40
|
+
background-color: transparent;
|
|
41
|
+
color: inherit;
|
|
42
|
+
font: inherit;
|
|
43
|
+
cursor: pointer;
|
|
44
|
+
outline-style: none;
|
|
45
|
+
|
|
46
|
+
@media (forced-colors: active) {
|
|
47
|
+
outline: 2px solid transparent;
|
|
48
|
+
outline-offset: 2px;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
> header [data-slot='dropdown'] > svg {
|
|
53
|
+
position: absolute;
|
|
54
|
+
inset-block-start: 50%;
|
|
55
|
+
inset-inline-end: 0.375rem;
|
|
56
|
+
translate: 0 -50%;
|
|
57
|
+
pointer-events: none;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
&:dir(rtl) > header > button > svg {
|
|
61
|
+
rotate: 180deg;
|
|
62
|
+
}
|
|
63
|
+
|
|
25
64
|
table {
|
|
26
65
|
width: 100%;
|
|
27
66
|
table-layout: fixed;
|
|
@@ -8,6 +8,25 @@
|
|
|
8
8
|
flex-direction: column;
|
|
9
9
|
overflow: hidden;
|
|
10
10
|
|
|
11
|
+
[data-slot='copy-icon'],
|
|
12
|
+
[data-slot='check-icon'] {
|
|
13
|
+
display: inline-flex;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
[data-slot='check-icon'] {
|
|
17
|
+
display: none;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
[data-slot='copy'][data-copied] {
|
|
21
|
+
[data-slot='copy-icon'] {
|
|
22
|
+
display: none;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
[data-slot='check-icon'] {
|
|
26
|
+
display: inline-flex;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
11
30
|
> header {
|
|
12
31
|
display: flex;
|
|
13
32
|
min-width: 0;
|
|
@@ -1,26 +1,119 @@
|
|
|
1
1
|
/* Input OTP */
|
|
2
2
|
@layer loseta.components {
|
|
3
|
+
/* The root is a label: clicking any cell focuses the input. The cells define
|
|
4
|
+
the row width; the content-sized input sits in an overlay entry and its
|
|
5
|
+
trailing indicator tracks the next cell. */
|
|
3
6
|
.input-otp {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
--otp-cell-size: 2.5rem;
|
|
8
|
+
--otp-gap: 0.5rem;
|
|
9
|
+
/* Joined mode zeroes the effective gap without overriding the style. */
|
|
10
|
+
--_otp-gap: var(--otp-gap);
|
|
11
|
+
|
|
12
|
+
position: relative;
|
|
13
|
+
display: grid;
|
|
14
|
+
grid-auto-columns: var(--otp-cell-size);
|
|
15
|
+
grid-auto-flow: column;
|
|
16
|
+
gap: var(--_otp-gap);
|
|
17
|
+
max-width: max-content;
|
|
18
|
+
/* Clip the input's caret gutter, but let the active-slot ring paint out. */
|
|
19
|
+
clip-path: inset(-6px);
|
|
20
|
+
cursor: text;
|
|
21
|
+
/* Codes read left to right even inside an RTL field. */
|
|
22
|
+
direction: ltr;
|
|
9
23
|
font-variant-numeric: tabular-nums;
|
|
10
24
|
|
|
11
25
|
@media (forced-colors: active) {
|
|
12
|
-
|
|
13
|
-
|
|
26
|
+
&:has(> [data-slot='entry'] > input:focus-visible)
|
|
27
|
+
> [data-slot='entry']::after {
|
|
28
|
+
outline: 2px solid transparent;
|
|
29
|
+
outline-offset: 2px;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
&:has(> [data-slot='entry'] > input:valid:focus-visible)
|
|
33
|
+
> [data-slot='cell'] {
|
|
34
|
+
outline: 2px solid transparent;
|
|
35
|
+
outline-offset: 2px;
|
|
36
|
+
}
|
|
14
37
|
}
|
|
15
38
|
|
|
16
|
-
|
|
17
|
-
|
|
39
|
+
> [data-slot='cell'] {
|
|
40
|
+
display: block;
|
|
41
|
+
inline-size: var(--otp-cell-size);
|
|
42
|
+
block-size: var(--otp-cell-size);
|
|
43
|
+
pointer-events: none;
|
|
18
44
|
}
|
|
19
45
|
|
|
20
|
-
|
|
46
|
+
> [data-slot='entry'] {
|
|
47
|
+
position: absolute;
|
|
48
|
+
inset-block: 0;
|
|
49
|
+
inset-inline-start: 0;
|
|
50
|
+
z-index: 1;
|
|
51
|
+
display: flex;
|
|
52
|
+
align-items: center;
|
|
53
|
+
gap: var(--_otp-gap);
|
|
21
54
|
pointer-events: none;
|
|
55
|
+
|
|
56
|
+
/* Sits over the next cell. The negative margin cancels the input's
|
|
57
|
+
start padding and the flex gap. */
|
|
58
|
+
&::after {
|
|
59
|
+
content: "";
|
|
60
|
+
flex: none;
|
|
61
|
+
inline-size: var(--otp-cell-size);
|
|
62
|
+
block-size: var(--otp-cell-size);
|
|
63
|
+
margin-inline-start: calc(
|
|
64
|
+
-1 * ((var(--otp-cell-size) - 1ch) / 2 + var(--_otp-gap))
|
|
65
|
+
);
|
|
66
|
+
visibility: hidden;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
> input {
|
|
70
|
+
field-sizing: content;
|
|
71
|
+
width: auto;
|
|
72
|
+
height: 100%;
|
|
73
|
+
min-width: 0;
|
|
74
|
+
margin: 0;
|
|
75
|
+
padding: 0;
|
|
76
|
+
padding-inline-start: calc((var(--otp-cell-size) - 1ch) / 2);
|
|
77
|
+
border: 0;
|
|
78
|
+
outline: 0;
|
|
79
|
+
appearance: none;
|
|
80
|
+
background-color: transparent;
|
|
81
|
+
color: inherit;
|
|
82
|
+
font: inherit;
|
|
83
|
+
font-variant-numeric: tabular-nums;
|
|
84
|
+
letter-spacing: calc(var(--otp-cell-size) + var(--_otp-gap) - 1ch);
|
|
85
|
+
line-height: var(--otp-cell-size);
|
|
86
|
+
text-align: start;
|
|
87
|
+
pointer-events: auto;
|
|
88
|
+
|
|
89
|
+
&::placeholder {
|
|
90
|
+
color: var(--muted-foreground);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
&:has(> [data-slot='entry'] > input:focus-visible)
|
|
96
|
+
> [data-slot='entry']::after {
|
|
97
|
+
visibility: visible;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/* A complete code has no next cell; the style files ring the cells. */
|
|
101
|
+
&:has(> [data-slot='entry'] > input:valid:focus-visible)
|
|
102
|
+
> [data-slot='entry']::after {
|
|
103
|
+
visibility: hidden;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
&[data-spacing='joined'] {
|
|
107
|
+
--_otp-gap: 0rem;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
&:has(> [data-slot='entry'] > input:disabled) {
|
|
22
111
|
cursor: not-allowed;
|
|
23
112
|
opacity: 50%;
|
|
113
|
+
|
|
114
|
+
> [data-slot='entry'] > input {
|
|
115
|
+
cursor: not-allowed;
|
|
116
|
+
}
|
|
24
117
|
}
|
|
25
118
|
}
|
|
26
119
|
}
|
|
@@ -3,9 +3,17 @@
|
|
|
3
3
|
.kbd {
|
|
4
4
|
pointer-events: none;
|
|
5
5
|
display: inline-flex;
|
|
6
|
+
flex-shrink: 0;
|
|
6
7
|
align-items: center;
|
|
7
8
|
justify-content: center;
|
|
9
|
+
white-space: nowrap;
|
|
8
10
|
-webkit-user-select: none;
|
|
9
11
|
user-select: none;
|
|
10
12
|
}
|
|
13
|
+
|
|
14
|
+
.kbd-group {
|
|
15
|
+
display: inline-flex;
|
|
16
|
+
align-items: center;
|
|
17
|
+
gap: 0.25rem;
|
|
18
|
+
}
|
|
11
19
|
}
|