@fragiola/primitives 0.0.0-stage → 0.0.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/LICENSE +21 -0
- package/README.md +50 -2
- package/dist/async-list-Bv6ff5Oj.js +81 -0
- package/dist/async-list-Bv6ff5Oj.js.map +1 -0
- package/dist/async-list.d.ts +2 -0
- package/dist/async-list.js +1 -0
- package/dist/calendar-keys-DGYpjLwv.d.ts +12 -0
- package/dist/calendar-system-B5U5HcPQ.d.ts +415 -0
- package/dist/calendar-systems-Daa6Q_ca.js +659 -0
- package/dist/calendar-systems-Daa6Q_ca.js.map +1 -0
- package/dist/calendar-systems.d.ts +3 -0
- package/dist/calendar-systems.js +1 -0
- package/dist/carousel-LRbWqbAx.js +375 -0
- package/dist/carousel-LRbWqbAx.js.map +1 -0
- package/dist/carousel.d.ts +2 -0
- package/dist/carousel.js +1 -0
- package/dist/cascade-B155Xvvv.js +64 -0
- package/dist/cascade-B155Xvvv.js.map +1 -0
- package/dist/cascade.d.ts +2 -0
- package/dist/cascade.js +1 -0
- package/dist/clipboard-Cy2cbGEW.js +33 -0
- package/dist/clipboard-Cy2cbGEW.js.map +1 -0
- package/dist/clipboard.d.ts +2 -0
- package/dist/clipboard.js +1 -0
- package/dist/collection-Dbk-PB5S.js +609 -0
- package/dist/collection-Dbk-PB5S.js.map +1 -0
- package/dist/collection.d.ts +2 -0
- package/dist/collection.js +3 -0
- package/dist/color-sURV5Irg.js +699 -0
- package/dist/color-sURV5Irg.js.map +1 -0
- package/dist/color.d.ts +2 -0
- package/dist/color.js +1 -0
- package/dist/command-DueCXi65.js +104 -0
- package/dist/command-DueCXi65.js.map +1 -0
- package/dist/command.d.ts +2 -0
- package/dist/command.js +1 -0
- package/dist/date-CrbFSJKQ.js +215 -0
- package/dist/date-CrbFSJKQ.js.map +1 -0
- package/dist/date.d.ts +4 -0
- package/dist/date.js +1 -0
- package/dist/direction-CTnVLpmd.d.ts +8 -0
- package/dist/direction-DJDPvnxJ.js +13 -0
- package/dist/direction-DJDPvnxJ.js.map +1 -0
- package/dist/direction.d.ts +2 -0
- package/dist/direction.js +1 -0
- package/dist/drag-session-CSr06B5v.js +41 -0
- package/dist/drag-session-CSr06B5v.js.map +1 -0
- package/dist/file-DSLtfzbi.js +263 -0
- package/dist/file-DSLtfzbi.js.map +1 -0
- package/dist/file.d.ts +2 -0
- package/dist/file.js +1 -0
- package/dist/focus-BI-VvM0f.js +75 -0
- package/dist/focus-BI-VvM0f.js.map +1 -0
- package/dist/focus.d.ts +2 -0
- package/dist/focus.js +3 -0
- package/dist/form-DovwKtqz.js +501 -0
- package/dist/form-DovwKtqz.js.map +1 -0
- package/dist/form.d.ts +2 -0
- package/dist/form.js +1 -0
- package/dist/hover-BakyPYnC.js +62 -0
- package/dist/hover-BakyPYnC.js.map +1 -0
- package/dist/hover.d.ts +2 -0
- package/dist/hover.js +1 -0
- package/dist/id-B0Y8iZrc.js +13 -0
- package/dist/id-B0Y8iZrc.js.map +1 -0
- package/dist/id.d.ts +2 -0
- package/dist/id.js +1 -0
- package/dist/image-D4X_yRYw.js +44 -0
- package/dist/image-D4X_yRYw.js.map +1 -0
- package/dist/image.d.ts +2 -0
- package/dist/image.js +1 -0
- package/dist/index-B0rwIZw9.d.ts +51 -0
- package/dist/index-B4wF1isn.d.ts +128 -0
- package/dist/index-BHiBRE01.d.ts +20 -0
- package/dist/index-BNlMm-0u.d.ts +17 -0
- package/dist/index-BapNrjY9.d.ts +48 -0
- package/dist/index-Bd-tVb7C.d.ts +6 -0
- package/dist/index-BjE8nDiX.d.ts +125 -0
- package/dist/index-BpbT-FsX.d.ts +117 -0
- package/dist/index-CBgGcTeX.d.ts +37 -0
- package/dist/index-CGThV_Md.d.ts +100 -0
- package/dist/index-CMig3TXL.d.ts +28 -0
- package/dist/index-CWFRduRd.d.ts +212 -0
- package/dist/index-CkrHWyU_.d.ts +33 -0
- package/dist/index-Cwu6f7y1.d.ts +18 -0
- package/dist/index-D10LDdR6.d.ts +139 -0
- package/dist/index-D146vm21.d.ts +104 -0
- package/dist/index-DGKhEvNr.d.ts +107 -0
- package/dist/index-DbAu4s16.d.ts +48 -0
- package/dist/index-DdaCj6IO.d.ts +54 -0
- package/dist/index-DeHcNdjC.d.ts +68 -0
- package/dist/index-DeR4ncrW.d.ts +93 -0
- package/dist/index-HIksgK0e.d.ts +70 -0
- package/dist/index-IZB0mlZl.d.ts +71 -0
- package/dist/index-IfDZj87U.d.ts +28 -0
- package/dist/index-SrTuVBms.d.ts +75 -0
- package/dist/index-T9UcYvkf.d.ts +339 -0
- package/dist/index-fRTojAoR.d.ts +31 -0
- package/dist/index-fuLUke9n.d.ts +6 -0
- package/dist/index-l63esAck.d.ts +104 -0
- package/dist/index-raSUg9U7.d.ts +38 -0
- package/dist/index-twgzPKvZ.d.ts +278 -0
- package/dist/index-wBpjRykh.d.ts +125 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +42 -0
- package/dist/inert-DlGToy3q.js +80 -0
- package/dist/inert-DlGToy3q.js.map +1 -0
- package/dist/inert.d.ts +2 -0
- package/dist/inert.js +1 -0
- package/dist/layer-stack-BEtzaFC1.js +118 -0
- package/dist/layer-stack-BEtzaFC1.js.map +1 -0
- package/dist/layers-C-N4rrZX.js +24 -0
- package/dist/layers-C-N4rrZX.js.map +1 -0
- package/dist/layers.d.ts +2 -0
- package/dist/layers.js +3 -0
- package/dist/list-navigation-CbWv4DK5.js +40 -0
- package/dist/list-navigation-CbWv4DK5.js.map +1 -0
- package/dist/month-year-BG5imFUq.js +108 -0
- package/dist/month-year-BG5imFUq.js.map +1 -0
- package/dist/month-year.d.ts +3 -0
- package/dist/month-year.js +1 -0
- package/dist/number-BFUio97d.js +316 -0
- package/dist/number-BFUio97d.js.map +1 -0
- package/dist/number.d.ts +2 -0
- package/dist/number.js +1 -0
- package/dist/overlay-BwPyiM3T.js +78 -0
- package/dist/overlay-BwPyiM3T.js.map +1 -0
- package/dist/overlay.d.ts +2 -0
- package/dist/overlay.js +1 -0
- package/dist/pagination-BkVzaIGP.js +51 -0
- package/dist/pagination-BkVzaIGP.js.map +1 -0
- package/dist/pagination.d.ts +2 -0
- package/dist/pagination.js +1 -0
- package/dist/plain-date-idQH1P6X.d.ts +29 -0
- package/dist/plain-date-time-B8PGahhe.d.ts +99 -0
- package/dist/pointer-CuDtD9XA.js +189 -0
- package/dist/pointer-CuDtD9XA.js.map +1 -0
- package/dist/pointer.d.ts +2 -0
- package/dist/pointer.js +3 -0
- package/dist/positioning-DDUQ75mB.js +148 -0
- package/dist/positioning-DDUQ75mB.js.map +1 -0
- package/dist/positioning.d.ts +2 -0
- package/dist/positioning.js +1 -0
- package/dist/presence-BhKDOmII.js +86 -0
- package/dist/presence-BhKDOmII.js.map +1 -0
- package/dist/presence.d.ts +2 -0
- package/dist/presence.js +1 -0
- package/dist/range-o0_GBhyY.js +158 -0
- package/dist/range-o0_GBhyY.js.map +1 -0
- package/dist/range.d.ts +2 -0
- package/dist/range.js +1 -0
- package/dist/scroll-area-BYNhv36t.js +447 -0
- package/dist/scroll-area-BYNhv36t.js.map +1 -0
- package/dist/scroll-area.d.ts +2 -0
- package/dist/scroll-area.js +1 -0
- package/dist/scroll-lock-JzRNOA1O.js +42 -0
- package/dist/scroll-lock-JzRNOA1O.js.map +1 -0
- package/dist/scroll-lock.d.ts +2 -0
- package/dist/scroll-lock.js +1 -0
- package/dist/segments-eRu5G_Bd.js +587 -0
- package/dist/segments-eRu5G_Bd.js.map +1 -0
- package/dist/segments.d.ts +3 -0
- package/dist/segments.js +1 -0
- package/dist/selection-Cor67w_V.js +287 -0
- package/dist/selection-Cor67w_V.js.map +1 -0
- package/dist/selection.d.ts +2 -0
- package/dist/selection.js +1 -0
- package/dist/swipe.d.ts +2 -0
- package/dist/swipe.js +1 -0
- package/dist/tabbable-BPiLssIv.js +35 -0
- package/dist/tabbable-BPiLssIv.js.map +1 -0
- package/dist/time-Ct6oq9kt.js +208 -0
- package/dist/time-Ct6oq9kt.js.map +1 -0
- package/dist/time-zone-DegkzwST.js +305 -0
- package/dist/time-zone-DegkzwST.js.map +1 -0
- package/dist/time-zone.d.ts +2 -0
- package/dist/time-zone.js +1 -0
- package/dist/time.d.ts +2 -0
- package/dist/time.js +1 -0
- package/dist/toast-BjRpJalM.js +400 -0
- package/dist/toast-BjRpJalM.js.map +1 -0
- package/dist/toast.d.ts +2 -0
- package/dist/toast.js +1 -0
- package/dist/unit-grid-DJy8lb5D.d.ts +21 -0
- package/dist/virtual-BlX1RuHD.js +306 -0
- package/dist/virtual-BlX1RuHD.js.map +1 -0
- package/dist/virtual.d.ts +2 -0
- package/dist/virtual.js +1 -0
- package/dist/watch-swipe-BIucfr9O.js +301 -0
- package/dist/watch-swipe-BIucfr9O.js.map +1 -0
- package/package.json +234 -3
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
// src/toast/measure-toast-height.ts
|
|
2
|
+
/**
|
|
3
|
+
* A toast's natural height in px (spec/toast.md, "Stacking"): its border box with its inline
|
|
4
|
+
* `height` set to `auto` for the read, since a collapsed stack may give it the frontmost one's.
|
|
5
|
+
*/
|
|
6
|
+
function measureToastHeight(element) {
|
|
7
|
+
const previous = element.style.height;
|
|
8
|
+
element.style.height = "auto";
|
|
9
|
+
const height = element.offsetHeight;
|
|
10
|
+
element.style.height = previous;
|
|
11
|
+
return height;
|
|
12
|
+
}
|
|
13
|
+
// src/toast/toast-manager.ts
|
|
14
|
+
function toOptions(value) {
|
|
15
|
+
return typeof value === "string" ? { title: value } : value;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates a toast queue (spec/toast.md, "The toast queue"). Its timers run on the page's clock
|
|
19
|
+
* (`setTimeout`, `Date.now`); a toast's timer runs only while it shows (not queued past the
|
|
20
|
+
* limit, not closing, not `loading`) and nothing pauses the queue, and keeps what it had left
|
|
21
|
+
* across pauses.
|
|
22
|
+
*/
|
|
23
|
+
function createToastManager(options = {}) {
|
|
24
|
+
let limit = options.limit ?? 3;
|
|
25
|
+
let timeout = options.timeout ?? 5e3;
|
|
26
|
+
let entries = [];
|
|
27
|
+
let snapshot = [];
|
|
28
|
+
let count = 0;
|
|
29
|
+
const pauses = /* @__PURE__ */ new Set();
|
|
30
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
31
|
+
const duration = (entry) => {
|
|
32
|
+
const value = entry.options.timeout ?? timeout;
|
|
33
|
+
return entry.options.type === "loading" || value <= 0 ? null : value;
|
|
34
|
+
};
|
|
35
|
+
const limitedIds = () => {
|
|
36
|
+
const limited = /* @__PURE__ */ new Set();
|
|
37
|
+
let shown = 0;
|
|
38
|
+
for (const entry of entries) {
|
|
39
|
+
if (entry.closing) continue;
|
|
40
|
+
if (shown >= limit) limited.add(entry.id);
|
|
41
|
+
shown += 1;
|
|
42
|
+
}
|
|
43
|
+
return limited;
|
|
44
|
+
};
|
|
45
|
+
const stop = (entry) => {
|
|
46
|
+
if (entry.handle !== void 0) {
|
|
47
|
+
clearTimeout(entry.handle);
|
|
48
|
+
entry.handle = void 0;
|
|
49
|
+
}
|
|
50
|
+
if (entry.startedAt !== null && entry.remaining !== null) entry.remaining = Math.max(0, entry.remaining - (Date.now() - entry.startedAt));
|
|
51
|
+
entry.startedAt = null;
|
|
52
|
+
};
|
|
53
|
+
const syncTimers = (limited) => {
|
|
54
|
+
for (const entry of entries) if (!(!entry.closing && entry.remaining !== null && pauses.size === 0 && !limited.has(entry.id))) stop(entry);
|
|
55
|
+
else if (entry.handle === void 0) {
|
|
56
|
+
const left = entry.remaining;
|
|
57
|
+
entry.startedAt = Date.now();
|
|
58
|
+
entry.handle = setTimeout(() => {
|
|
59
|
+
entry.handle = void 0;
|
|
60
|
+
entry.startedAt = null;
|
|
61
|
+
entry.remaining = 0;
|
|
62
|
+
close(entry.id);
|
|
63
|
+
}, left);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const commit = () => {
|
|
67
|
+
const limited = limitedIds();
|
|
68
|
+
syncTimers(limited);
|
|
69
|
+
let shown = 0;
|
|
70
|
+
let offsetY = 0;
|
|
71
|
+
snapshot = entries.map((entry, position) => {
|
|
72
|
+
const toast = {
|
|
73
|
+
...entry.options,
|
|
74
|
+
id: entry.id,
|
|
75
|
+
priority: entry.options.priority ?? "low",
|
|
76
|
+
closing: entry.closing,
|
|
77
|
+
limited: limited.has(entry.id),
|
|
78
|
+
index: entry.closing ? position : shown,
|
|
79
|
+
height: entry.height,
|
|
80
|
+
offsetY,
|
|
81
|
+
updateKey: entry.updateKey
|
|
82
|
+
};
|
|
83
|
+
offsetY += entry.height;
|
|
84
|
+
if (!entry.closing) shown += 1;
|
|
85
|
+
return toast;
|
|
86
|
+
});
|
|
87
|
+
for (const listener of [...listeners]) listener();
|
|
88
|
+
};
|
|
89
|
+
const find = (id) => entries.find((entry) => entry.id === id);
|
|
90
|
+
const restart = (entry) => {
|
|
91
|
+
stop(entry);
|
|
92
|
+
entry.remaining = duration(entry);
|
|
93
|
+
};
|
|
94
|
+
function close(id) {
|
|
95
|
+
const closing = entries.filter((entry) => !entry.closing && (id === void 0 || entry.id === id));
|
|
96
|
+
if (closing.length === 0) return;
|
|
97
|
+
for (const entry of closing) {
|
|
98
|
+
stop(entry);
|
|
99
|
+
entry.closing = true;
|
|
100
|
+
entry.height = 0;
|
|
101
|
+
}
|
|
102
|
+
commit();
|
|
103
|
+
for (const entry of closing) entry.options.onClose?.();
|
|
104
|
+
}
|
|
105
|
+
function add(toast) {
|
|
106
|
+
const { id: requested, ...rest } = toast;
|
|
107
|
+
const existing = requested === void 0 ? void 0 : find(requested);
|
|
108
|
+
if (existing !== void 0 && !existing.closing) {
|
|
109
|
+
existing.options = {
|
|
110
|
+
...existing.options,
|
|
111
|
+
...rest
|
|
112
|
+
};
|
|
113
|
+
existing.updateKey += 1;
|
|
114
|
+
restart(existing);
|
|
115
|
+
commit();
|
|
116
|
+
return existing.id;
|
|
117
|
+
}
|
|
118
|
+
if (existing !== void 0) {
|
|
119
|
+
stop(existing);
|
|
120
|
+
entries = entries.filter((entry) => entry !== existing);
|
|
121
|
+
}
|
|
122
|
+
count += 1;
|
|
123
|
+
const entry = {
|
|
124
|
+
options: rest,
|
|
125
|
+
id: requested ?? `toast-${count}`,
|
|
126
|
+
closing: false,
|
|
127
|
+
height: 0,
|
|
128
|
+
updateKey: 0,
|
|
129
|
+
remaining: null,
|
|
130
|
+
startedAt: null,
|
|
131
|
+
handle: void 0
|
|
132
|
+
};
|
|
133
|
+
entry.remaining = duration(entry);
|
|
134
|
+
entries = [entry, ...entries];
|
|
135
|
+
commit();
|
|
136
|
+
return entry.id;
|
|
137
|
+
}
|
|
138
|
+
function update(id, updates) {
|
|
139
|
+
const entry = find(id);
|
|
140
|
+
const current = snapshot.find((toast) => toast.id === id);
|
|
141
|
+
if (entry === void 0 || entry.closing || current === void 0) return;
|
|
142
|
+
const next = typeof updates === "function" ? updates(current) : updates;
|
|
143
|
+
if (entry.closing) return;
|
|
144
|
+
const wasLoading = entry.options.type === "loading";
|
|
145
|
+
entry.options = {
|
|
146
|
+
...entry.options,
|
|
147
|
+
...next
|
|
148
|
+
};
|
|
149
|
+
entry.updateKey += 1;
|
|
150
|
+
if (wasLoading || Object.hasOwn(next, "timeout") || Object.hasOwn(next, "type")) restart(entry);
|
|
151
|
+
commit();
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
toasts: () => snapshot,
|
|
155
|
+
subscribe(listener) {
|
|
156
|
+
listeners.add(listener);
|
|
157
|
+
return () => {
|
|
158
|
+
listeners.delete(listener);
|
|
159
|
+
};
|
|
160
|
+
},
|
|
161
|
+
add,
|
|
162
|
+
update,
|
|
163
|
+
close,
|
|
164
|
+
promise(promise, settled) {
|
|
165
|
+
const id = add({
|
|
166
|
+
...toOptions(settled.loading),
|
|
167
|
+
type: "loading"
|
|
168
|
+
});
|
|
169
|
+
return promise.then((value) => {
|
|
170
|
+
const success = typeof settled.success === "function" ? settled.success(value) : settled.success;
|
|
171
|
+
update(id, {
|
|
172
|
+
type: "success",
|
|
173
|
+
...toOptions(success)
|
|
174
|
+
});
|
|
175
|
+
return value;
|
|
176
|
+
}, (error) => {
|
|
177
|
+
const failure = typeof settled.error === "function" ? settled.error(error) : settled.error;
|
|
178
|
+
update(id, {
|
|
179
|
+
type: "error",
|
|
180
|
+
...toOptions(failure)
|
|
181
|
+
});
|
|
182
|
+
throw error;
|
|
183
|
+
});
|
|
184
|
+
},
|
|
185
|
+
remove(id) {
|
|
186
|
+
const entry = find(id);
|
|
187
|
+
if (entry === void 0 || !entry.closing) return;
|
|
188
|
+
entries = entries.filter((other) => other !== entry);
|
|
189
|
+
commit();
|
|
190
|
+
entry.options.onRemove?.();
|
|
191
|
+
},
|
|
192
|
+
setHeight(id, height) {
|
|
193
|
+
const entry = find(id);
|
|
194
|
+
if (entry === void 0 || entry.closing || entry.height === height) return;
|
|
195
|
+
entry.height = height;
|
|
196
|
+
commit();
|
|
197
|
+
},
|
|
198
|
+
pause(source) {
|
|
199
|
+
if (pauses.has(source)) return;
|
|
200
|
+
pauses.add(source);
|
|
201
|
+
syncTimers(limitedIds());
|
|
202
|
+
},
|
|
203
|
+
resume(source) {
|
|
204
|
+
if (!pauses.delete(source)) return;
|
|
205
|
+
syncTimers(limitedIds());
|
|
206
|
+
},
|
|
207
|
+
configure(next) {
|
|
208
|
+
const changed = next.limit !== void 0 && next.limit !== limit || next.timeout !== void 0 && next.timeout !== timeout;
|
|
209
|
+
limit = next.limit ?? limit;
|
|
210
|
+
timeout = next.timeout ?? timeout;
|
|
211
|
+
if (changed) commit();
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
// src/toast/watch-toast-viewport.ts
|
|
216
|
+
const ROOT = "[data-primitives-part=\"toast-root\"]";
|
|
217
|
+
/** Styles that keep an element in the accessibility tree and off the screen. */
|
|
218
|
+
const VISUALLY_HIDDEN = "position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap";
|
|
219
|
+
function isFocusVisible(element) {
|
|
220
|
+
try {
|
|
221
|
+
return element.matches(":focus-visible");
|
|
222
|
+
} catch {
|
|
223
|
+
return true;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Watches a toast Viewport (spec/toast.md, "Viewport", "Announcements", "Pausing"): the F6
|
|
228
|
+
* landmark (F6 focuses the viewport, F6 or Shift+Tab from it go back where focus was), the
|
|
229
|
+
* pauses (the pointer over it, the keyboard in it, a hidden page), and the announcements: two
|
|
230
|
+
* live regions inside it, polite and assertive, that hold the title and description of every
|
|
231
|
+
* shown toast by its priority, inserted in the order they show. It holds no component state:
|
|
232
|
+
* the queue (`manager`) holds the toasts, the component the expanded state it reports.
|
|
233
|
+
*/
|
|
234
|
+
function watchToastViewport(viewport, manager, options) {
|
|
235
|
+
const doc = viewport.ownerDocument;
|
|
236
|
+
let previous = null;
|
|
237
|
+
let hovering = false;
|
|
238
|
+
let focused = false;
|
|
239
|
+
let expanded = false;
|
|
240
|
+
let leaving = false;
|
|
241
|
+
const report = () => {
|
|
242
|
+
const next = hovering || focused;
|
|
243
|
+
if (next !== expanded) {
|
|
244
|
+
expanded = next;
|
|
245
|
+
options.onExpandedChange(next);
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
const region = (live) => {
|
|
249
|
+
const element = doc.createElement("div");
|
|
250
|
+
element.setAttribute("data-primitives-part", "toast-announcer");
|
|
251
|
+
element.setAttribute("data-priority", live === "polite" ? "low" : "high");
|
|
252
|
+
element.setAttribute("aria-live", live);
|
|
253
|
+
element.setAttribute("aria-atomic", "false");
|
|
254
|
+
element.setAttribute("aria-relevant", "additions text");
|
|
255
|
+
element.setAttribute("style", VISUALLY_HIDDEN);
|
|
256
|
+
return element;
|
|
257
|
+
};
|
|
258
|
+
const polite = region("polite");
|
|
259
|
+
const assertive = region("assertive");
|
|
260
|
+
viewport.prepend(polite, assertive);
|
|
261
|
+
const announced = /* @__PURE__ */ new Map();
|
|
262
|
+
const announce = (toasts) => {
|
|
263
|
+
const shown = new Map(toasts.filter((toast) => !toast.closing && !toast.limited).map((toast) => [toast.id, toast]));
|
|
264
|
+
for (const [id, element] of announced) {
|
|
265
|
+
const toast = shown.get(id);
|
|
266
|
+
const target = toast?.priority === "high" ? assertive : polite;
|
|
267
|
+
if (toast === void 0 || element.parentElement !== target) {
|
|
268
|
+
element.remove();
|
|
269
|
+
announced.delete(id);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
for (const toast of [...shown.values()].reverse()) {
|
|
273
|
+
const text = [toast.title, toast.description].filter((part) => part !== void 0 && part !== "").join(" ");
|
|
274
|
+
let element = announced.get(toast.id);
|
|
275
|
+
if (element === void 0) {
|
|
276
|
+
element = doc.createElement("div");
|
|
277
|
+
element.setAttribute("data-primitives-part", "toast-announcement");
|
|
278
|
+
element.textContent = text;
|
|
279
|
+
(toast.priority === "high" ? assertive : polite).append(element);
|
|
280
|
+
announced.set(toast.id, element);
|
|
281
|
+
} else if (element.textContent !== text) element.textContent = text;
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
const restoreFocus = () => {
|
|
285
|
+
const target = previous;
|
|
286
|
+
previous = null;
|
|
287
|
+
if (target?.isConnected && target !== doc.body) {
|
|
288
|
+
target.focus({ preventScroll: true });
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
const active = doc.activeElement;
|
|
292
|
+
if (active instanceof HTMLElement && viewport.contains(active)) active.blur();
|
|
293
|
+
};
|
|
294
|
+
const hasToasts = () => manager.toasts().some((toast) => !toast.closing);
|
|
295
|
+
const settleLeave = () => {
|
|
296
|
+
if (!leaving || manager.toasts().some((toast) => toast.closing)) return;
|
|
297
|
+
leaving = false;
|
|
298
|
+
hovering = false;
|
|
299
|
+
manager.resume("hover");
|
|
300
|
+
report();
|
|
301
|
+
};
|
|
302
|
+
const unsubscribe = manager.subscribe(() => {
|
|
303
|
+
const toasts = manager.toasts();
|
|
304
|
+
announce(toasts);
|
|
305
|
+
if (toasts.length === 0) {
|
|
306
|
+
leaving = false;
|
|
307
|
+
hovering = false;
|
|
308
|
+
focused = false;
|
|
309
|
+
manager.resume("hover");
|
|
310
|
+
manager.resume("focus");
|
|
311
|
+
report();
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
settleLeave();
|
|
315
|
+
});
|
|
316
|
+
const onPointerEnter = (event) => {
|
|
317
|
+
if (event.pointerType === "touch") return;
|
|
318
|
+
leaving = false;
|
|
319
|
+
hovering = true;
|
|
320
|
+
manager.pause("hover");
|
|
321
|
+
report();
|
|
322
|
+
};
|
|
323
|
+
const onPointerLeave = (event) => {
|
|
324
|
+
if (event.pointerType === "touch" || !hovering) return;
|
|
325
|
+
leaving = true;
|
|
326
|
+
settleLeave();
|
|
327
|
+
};
|
|
328
|
+
const onFocusIn = (event) => {
|
|
329
|
+
const target = event.target;
|
|
330
|
+
if (focused || !(target instanceof Element) || !(target === viewport || isFocusVisible(target))) return;
|
|
331
|
+
focused = true;
|
|
332
|
+
manager.pause("focus");
|
|
333
|
+
report();
|
|
334
|
+
};
|
|
335
|
+
const onFocusOut = (event) => {
|
|
336
|
+
const next = event.relatedTarget;
|
|
337
|
+
if (!focused || next instanceof Node && viewport.contains(next)) return;
|
|
338
|
+
focused = false;
|
|
339
|
+
manager.resume("focus");
|
|
340
|
+
report();
|
|
341
|
+
};
|
|
342
|
+
const onViewportKeyDown = (event) => {
|
|
343
|
+
if (event.defaultPrevented || previous === null) return;
|
|
344
|
+
if (event.key === "F6" || event.key === "Tab" && event.shiftKey && event.target === viewport) {
|
|
345
|
+
event.preventDefault();
|
|
346
|
+
event.stopPropagation();
|
|
347
|
+
restoreFocus();
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
const onDocumentKeyDown = (event) => {
|
|
351
|
+
if (event.key !== "F6" || event.defaultPrevented || !hasToasts()) return;
|
|
352
|
+
const active = doc.activeElement;
|
|
353
|
+
if (active instanceof Node && viewport.contains(active)) return;
|
|
354
|
+
event.preventDefault();
|
|
355
|
+
previous = active instanceof HTMLElement ? active : null;
|
|
356
|
+
viewport.focus({ preventScroll: true });
|
|
357
|
+
};
|
|
358
|
+
const onVisibility = () => {
|
|
359
|
+
if (doc.visibilityState === "hidden") manager.pause("hidden");
|
|
360
|
+
else manager.resume("hidden");
|
|
361
|
+
};
|
|
362
|
+
viewport.addEventListener("pointerenter", onPointerEnter);
|
|
363
|
+
viewport.addEventListener("pointerleave", onPointerLeave);
|
|
364
|
+
viewport.addEventListener("focusin", onFocusIn);
|
|
365
|
+
viewport.addEventListener("focusout", onFocusOut);
|
|
366
|
+
viewport.addEventListener("keydown", onViewportKeyDown);
|
|
367
|
+
doc.addEventListener("keydown", onDocumentKeyDown);
|
|
368
|
+
doc.addEventListener("visibilitychange", onVisibility);
|
|
369
|
+
onVisibility();
|
|
370
|
+
announce(manager.toasts());
|
|
371
|
+
return {
|
|
372
|
+
focusAfterClose(root) {
|
|
373
|
+
const active = doc.activeElement;
|
|
374
|
+
if (!(active instanceof Element) || !root.contains(active) || !isFocusVisible(active)) return;
|
|
375
|
+
const roots = [...viewport.querySelectorAll(ROOT)].filter((element) => element === root || !element.hasAttribute("data-ending-style") && !element.hasAttribute("data-limited") && !element.inert);
|
|
376
|
+
const index = roots.indexOf(root);
|
|
377
|
+
const next = roots[index + 1] ?? roots[index - 1];
|
|
378
|
+
if (next !== void 0 && next !== root) next.focus();
|
|
379
|
+
else restoreFocus();
|
|
380
|
+
},
|
|
381
|
+
stop() {
|
|
382
|
+
unsubscribe();
|
|
383
|
+
viewport.removeEventListener("pointerenter", onPointerEnter);
|
|
384
|
+
viewport.removeEventListener("pointerleave", onPointerLeave);
|
|
385
|
+
viewport.removeEventListener("focusin", onFocusIn);
|
|
386
|
+
viewport.removeEventListener("focusout", onFocusOut);
|
|
387
|
+
viewport.removeEventListener("keydown", onViewportKeyDown);
|
|
388
|
+
doc.removeEventListener("keydown", onDocumentKeyDown);
|
|
389
|
+
doc.removeEventListener("visibilitychange", onVisibility);
|
|
390
|
+
polite.remove();
|
|
391
|
+
assertive.remove();
|
|
392
|
+
manager.resume("hover");
|
|
393
|
+
manager.resume("focus");
|
|
394
|
+
manager.resume("hidden");
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
export { createToastManager as n, measureToastHeight as r, watchToastViewport as t };
|
|
399
|
+
|
|
400
|
+
//# sourceMappingURL=toast-BjRpJalM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toast-BjRpJalM.js","names":[],"sources":["../src/toast/measure-toast-height.ts","../src/toast/toast-manager.ts","../src/toast/watch-toast-viewport.ts"],"sourcesContent":["/**\n * A toast's natural height in px (spec/toast.md, \"Stacking\"): its border box with its inline\n * `height` set to `auto` for the read, since a collapsed stack may give it the frontmost one's.\n */\nexport function measureToastHeight(element: HTMLElement): number {\n const previous = element.style.height;\n element.style.height = \"auto\";\n const height = element.offsetHeight;\n element.style.height = previous;\n return height;\n}\n","/** How urgently a toast is announced: `low` politely, `high` assertively (spec/toast.md). */\nexport type ToastPriority = \"low\" | \"high\";\n\n/** What a toast says and how long it stays (spec/toast.md, \"The toast queue\"). */\nexport interface ToastOptions<Data = unknown> {\n /** Adding a toast with the id of an open one updates it in place and restarts its timer. */\n id?: string;\n title?: string;\n description?: string;\n /** Free-form (`success`, `error`, ...); `loading` never closes by itself. */\n type?: string;\n /** ms before it closes by itself (default: the manager's); `0`: never. */\n timeout?: number;\n /** `low` (default): announced politely; `high`: assertively. */\n priority?: ToastPriority;\n /** The app's own data, for its rendering. */\n data?: Data;\n /** Called once when it closes (by its timer, a Close, a swipe, Escape or `close`). */\n onClose?: () => void;\n /** Called once it left the list, after its exit animation. */\n onRemove?: () => void;\n}\n\n/** A change to an open toast (`update`): any option but its id. */\nexport type ToastUpdate<Data = unknown> = Omit<ToastOptions<Data>, \"id\">;\n\n/** A toast in the queue: its options, and what the queue derives for its rendering. */\nexport interface ToastObject<Data = unknown> extends ToastUpdate<Data> {\n readonly id: string;\n readonly priority: ToastPriority;\n /** Closed: its exit runs until the component calls `remove(id)`. */\n readonly closing: boolean;\n /** Past the `limit`: queued behind the newer ones, its timer waiting (spec/toast.md). */\n readonly limited: boolean;\n /** Its place in the stack, `0` the frontmost (newest); a closing toast keeps its list index. */\n readonly index: number;\n /** Its measured height in px (`setHeight`), `0` until measured and once closing. */\n readonly height: number;\n /** The sum of the heights of the toasts in front of it, in px. */\n readonly offsetY: number;\n /** Counts its updates (an upsert, `update`), so a component knows to measure it again. */\n readonly updateKey: number;\n}\n\n/** A promise toast's three states: each a title, options, or a function of the result. */\nexport interface ToastPromiseOptions<Value, Data = unknown> {\n loading: string | ToastOptions<Data>;\n success:\n | string\n | ToastUpdate<Data>\n | ((value: Value) => string | ToastUpdate<Data>);\n error:\n | string\n | ToastUpdate<Data>\n | ((error: unknown) => string | ToastUpdate<Data>);\n}\n\nexport interface ToastManagerOptions {\n /** How many toasts show at once; the older ones wait (default `3`). */\n limit?: number;\n /** The default ms before a toast closes by itself (default `5000`; `0`: never). */\n timeout?: number;\n}\n\n/**\n * The toast queue (spec/toast.md, \"The toast queue\"): the app's notifications, which a plain\n * module can import and fill, with no component. Toast's Provider renders from it and reports\n * back what only the page knows (heights, the end of an exit, the hover and focus that pause it).\n */\nexport interface ToastManager<Data = unknown> {\n /** The toasts, newest first: the same array until something changes. */\n toasts(): readonly ToastObject<Data>[];\n /** Calls `listener` after every change; returns the unsubscribe. */\n subscribe(listener: () => void): () => void;\n /** Adds a toast (or updates the open one with its id); returns its id. */\n add(options: ToastOptions<Data>): string;\n /** Changes an open toast; ignored for a closing or unknown one. */\n update(\n id: string,\n updates:\n | ToastUpdate<Data>\n | ((toast: ToastObject<Data>) => ToastUpdate<Data>),\n ): void;\n /** Closes a toast, or every toast without an id. */\n close(id?: string): void;\n /**\n * A `loading` toast that becomes `success` or `error` when `promise` settles; returns the\n * promise's own result (rejected with its error).\n */\n promise<Value>(\n promise: Promise<Value>,\n options: ToastPromiseOptions<Value, Data>,\n ): Promise<Value>;\n /** Takes a closed toast out of the list once its exit ended (the component calls it). */\n remove(id: string): void;\n /** Records a toast's measured height (the stacking offsets). */\n setHeight(id: string, height: number): void;\n /** Pauses every timer for `source` (`hover`, `focus`, `hidden`, ...) until resumed. */\n pause(source: string): void;\n /** Ends `source`'s pause; the timers run again once no source pauses them. */\n resume(source: string): void;\n /** Changes the limit or the default timeout (a Provider's props). */\n configure(options: ToastManagerOptions): void;\n}\n\ninterface Entry<Data> {\n options: ToastUpdate<Data>;\n id: string;\n closing: boolean;\n height: number;\n updateKey: number;\n /** ms its timer has left, `null` for none (loading, `timeout: 0`). */\n remaining: number | null;\n /** When its timer last started running, while it runs. */\n startedAt: number | null;\n handle: ReturnType<typeof setTimeout> | undefined;\n}\n\nfunction toOptions<Data>(value: string | ToastUpdate<Data>): ToastUpdate<Data> {\n return typeof value === \"string\" ? { title: value } : value;\n}\n\n/**\n * Creates a toast queue (spec/toast.md, \"The toast queue\"). Its timers run on the page's clock\n * (`setTimeout`, `Date.now`); a toast's timer runs only while it shows (not queued past the\n * limit, not closing, not `loading`) and nothing pauses the queue, and keeps what it had left\n * across pauses.\n */\nexport function createToastManager<Data = unknown>(\n options: ToastManagerOptions = {},\n): ToastManager<Data> {\n let limit = options.limit ?? 3;\n let timeout = options.timeout ?? 5000;\n let entries: Entry<Data>[] = [];\n let snapshot: readonly ToastObject<Data>[] = [];\n let count = 0;\n const pauses = new Set<string>();\n const listeners = new Set<() => void>();\n\n const duration = (entry: Entry<Data>): number | null => {\n const value = entry.options.timeout ?? timeout;\n return entry.options.type === \"loading\" || value <= 0 ? null : value;\n };\n\n const limitedIds = (): Set<string> => {\n const limited = new Set<string>();\n let shown = 0;\n for (const entry of entries) {\n if (entry.closing) {\n continue;\n }\n if (shown >= limit) {\n limited.add(entry.id);\n }\n shown += 1;\n }\n return limited;\n };\n\n const stop = (entry: Entry<Data>) => {\n if (entry.handle !== undefined) {\n clearTimeout(entry.handle);\n entry.handle = undefined;\n }\n if (entry.startedAt !== null && entry.remaining !== null) {\n entry.remaining = Math.max(\n 0,\n entry.remaining - (Date.now() - entry.startedAt),\n );\n }\n entry.startedAt = null;\n };\n\n // starts or stops every timer for the current state\n const syncTimers = (limited: Set<string>) => {\n for (const entry of entries) {\n const runs =\n !entry.closing &&\n entry.remaining !== null &&\n pauses.size === 0 &&\n !limited.has(entry.id);\n if (!runs) {\n stop(entry);\n } else if (entry.handle === undefined) {\n const left = entry.remaining as number;\n entry.startedAt = Date.now();\n entry.handle = setTimeout(() => {\n entry.handle = undefined;\n entry.startedAt = null;\n entry.remaining = 0;\n close(entry.id);\n }, left);\n }\n }\n };\n\n const commit = () => {\n const limited = limitedIds();\n syncTimers(limited);\n let shown = 0;\n let offsetY = 0;\n snapshot = entries.map((entry, position) => {\n const toast: ToastObject<Data> = {\n ...entry.options,\n id: entry.id,\n priority: entry.options.priority ?? \"low\",\n closing: entry.closing,\n limited: limited.has(entry.id),\n index: entry.closing ? position : shown,\n height: entry.height,\n offsetY,\n updateKey: entry.updateKey,\n };\n offsetY += entry.height;\n if (!entry.closing) {\n shown += 1;\n }\n return toast;\n });\n for (const listener of [...listeners]) {\n listener();\n }\n };\n\n const find = (id: string) => entries.find((entry) => entry.id === id);\n\n const restart = (entry: Entry<Data>) => {\n stop(entry);\n entry.remaining = duration(entry);\n };\n\n function close(id?: string) {\n const closing = entries.filter(\n (entry) => !entry.closing && (id === undefined || entry.id === id),\n );\n if (closing.length === 0) {\n return;\n }\n for (const entry of closing) {\n stop(entry);\n entry.closing = true;\n entry.height = 0;\n }\n commit();\n for (const entry of closing) {\n entry.options.onClose?.();\n }\n }\n\n function add(toast: ToastOptions<Data>): string {\n const { id: requested, ...rest } = toast;\n const existing = requested === undefined ? undefined : find(requested);\n if (existing !== undefined && !existing.closing) {\n existing.options = { ...existing.options, ...rest };\n existing.updateKey += 1;\n restart(existing);\n commit();\n return existing.id;\n }\n if (existing !== undefined) {\n // a closing toast with that id leaves at once, without its onRemove\n stop(existing);\n entries = entries.filter((entry) => entry !== existing);\n }\n count += 1;\n const entry: Entry<Data> = {\n options: rest,\n id: requested ?? `toast-${count}`,\n closing: false,\n height: 0,\n updateKey: 0,\n remaining: null,\n startedAt: null,\n handle: undefined,\n };\n entry.remaining = duration(entry);\n entries = [entry, ...entries];\n commit();\n return entry.id;\n }\n\n function update(\n id: string,\n updates:\n | ToastUpdate<Data>\n | ((toast: ToastObject<Data>) => ToastUpdate<Data>),\n ) {\n const entry = find(id);\n const current = snapshot.find((toast) => toast.id === id);\n if (entry === undefined || entry.closing || current === undefined) {\n return;\n }\n const next = typeof updates === \"function\" ? updates(current) : updates;\n // the updater may have closed it\n if (entry.closing) {\n return;\n }\n const wasLoading = entry.options.type === \"loading\";\n entry.options = { ...entry.options, ...next };\n entry.updateKey += 1;\n if (\n wasLoading ||\n Object.hasOwn(next, \"timeout\") ||\n Object.hasOwn(next, \"type\")\n ) {\n restart(entry);\n }\n commit();\n }\n\n return {\n toasts: () => snapshot,\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n add,\n update,\n close,\n promise(promise, settled) {\n const id = add({ ...toOptions(settled.loading), type: \"loading\" });\n return promise.then(\n (value) => {\n const success =\n typeof settled.success === \"function\"\n ? settled.success(value)\n : settled.success;\n update(id, { type: \"success\", ...toOptions(success) });\n return value;\n },\n (error: unknown) => {\n const failure =\n typeof settled.error === \"function\"\n ? settled.error(error)\n : settled.error;\n update(id, { type: \"error\", ...toOptions(failure) });\n throw error;\n },\n );\n },\n remove(id) {\n const entry = find(id);\n if (entry === undefined || !entry.closing) {\n return;\n }\n entries = entries.filter((other) => other !== entry);\n commit();\n entry.options.onRemove?.();\n },\n setHeight(id, height) {\n const entry = find(id);\n if (\n entry === undefined ||\n entry.closing ||\n entry.height === height\n ) {\n return;\n }\n entry.height = height;\n commit();\n },\n pause(source) {\n if (pauses.has(source)) {\n return;\n }\n pauses.add(source);\n syncTimers(limitedIds());\n },\n resume(source) {\n if (!pauses.delete(source)) {\n return;\n }\n syncTimers(limitedIds());\n },\n configure(next) {\n const changed =\n (next.limit !== undefined && next.limit !== limit) ||\n (next.timeout !== undefined && next.timeout !== timeout);\n limit = next.limit ?? limit;\n timeout = next.timeout ?? timeout;\n if (changed) {\n commit();\n }\n },\n };\n}\n","import type { ToastManager, ToastObject } from \"./toast-manager.ts\";\n\n/** What a Viewport's watch reports and needs (spec/toast.md, \"Viewport\"). */\nexport interface ToastViewportWatch {\n /** Moves focus off a toast that is closing (`root`): to the next toast, else the previous, else back. */\n focusAfterClose(root: HTMLElement): void;\n /** Removes every listener and the live regions. */\n stop(): void;\n}\n\nexport interface ToastViewportWatchOptions {\n /** The stack expands while the pointer is over it or the keyboard is in it. */\n onExpandedChange: (expanded: boolean) => void;\n}\n\nconst ROOT = '[data-primitives-part=\"toast-root\"]';\n\n/** Styles that keep an element in the accessibility tree and off the screen. */\nconst VISUALLY_HIDDEN =\n \"position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap\";\n\nfunction isFocusVisible(element: Element): boolean {\n try {\n return element.matches(\":focus-visible\");\n } catch {\n return true;\n }\n}\n\n/**\n * Watches a toast Viewport (spec/toast.md, \"Viewport\", \"Announcements\", \"Pausing\"): the F6\n * landmark (F6 focuses the viewport, F6 or Shift+Tab from it go back where focus was), the\n * pauses (the pointer over it, the keyboard in it, a hidden page), and the announcements: two\n * live regions inside it, polite and assertive, that hold the title and description of every\n * shown toast by its priority, inserted in the order they show. It holds no component state:\n * the queue (`manager`) holds the toasts, the component the expanded state it reports.\n */\nexport function watchToastViewport<Data>(\n viewport: HTMLElement,\n manager: ToastManager<Data>,\n options: ToastViewportWatchOptions,\n): ToastViewportWatch {\n const doc = viewport.ownerDocument;\n let previous: HTMLElement | null = null;\n let hovering = false;\n let focused = false;\n let expanded = false;\n let leaving = false;\n\n const report = () => {\n const next = hovering || focused;\n if (next !== expanded) {\n expanded = next;\n options.onExpandedChange(next);\n }\n };\n\n // the live regions: in the page before any toast, so a screen reader follows them\n const region = (live: \"polite\" | \"assertive\") => {\n const element = doc.createElement(\"div\");\n element.setAttribute(\"data-primitives-part\", \"toast-announcer\");\n element.setAttribute(\n \"data-priority\",\n live === \"polite\" ? \"low\" : \"high\",\n );\n element.setAttribute(\"aria-live\", live);\n element.setAttribute(\"aria-atomic\", \"false\");\n element.setAttribute(\"aria-relevant\", \"additions text\");\n element.setAttribute(\"style\", VISUALLY_HIDDEN);\n return element;\n };\n const polite = region(\"polite\");\n const assertive = region(\"assertive\");\n viewport.prepend(polite, assertive);\n const announced = new Map<string, HTMLElement>();\n\n const announce = (toasts: readonly ToastObject<Data>[]) => {\n const shown = new Map(\n toasts\n .filter((toast) => !toast.closing && !toast.limited)\n .map((toast) => [toast.id, toast]),\n );\n for (const [id, element] of announced) {\n const toast = shown.get(id);\n const target = toast?.priority === \"high\" ? assertive : polite;\n if (toast === undefined || element.parentElement !== target) {\n element.remove();\n announced.delete(id);\n }\n }\n // the oldest first: a newer toast is inserted after the ones already announced\n for (const toast of [...shown.values()].reverse()) {\n const text = [toast.title, toast.description]\n .filter((part) => part !== undefined && part !== \"\")\n .join(\" \");\n let element = announced.get(toast.id);\n if (element === undefined) {\n element = doc.createElement(\"div\");\n element.setAttribute(\n \"data-primitives-part\",\n \"toast-announcement\",\n );\n element.textContent = text;\n (toast.priority === \"high\" ? assertive : polite).append(\n element,\n );\n announced.set(toast.id, element);\n } else if (element.textContent !== text) {\n element.textContent = text;\n }\n }\n };\n\n const restoreFocus = () => {\n const target = previous;\n previous = null;\n if (target?.isConnected && target !== doc.body) {\n target.focus({ preventScroll: true });\n return;\n }\n const active = doc.activeElement;\n if (active instanceof HTMLElement && viewport.contains(active)) {\n active.blur();\n }\n };\n\n const hasToasts = () => manager.toasts().some((toast) => !toast.closing);\n\n const settleLeave = () => {\n // the stack stays expanded under the pointer while a toast's exit runs\n if (!leaving || manager.toasts().some((toast) => toast.closing)) {\n return;\n }\n leaving = false;\n hovering = false;\n manager.resume(\"hover\");\n report();\n };\n\n const unsubscribe = manager.subscribe(() => {\n const toasts = manager.toasts();\n announce(toasts);\n if (toasts.length === 0) {\n leaving = false;\n hovering = false;\n focused = false;\n manager.resume(\"hover\");\n manager.resume(\"focus\");\n report();\n return;\n }\n settleLeave();\n });\n\n const onPointerEnter = (event: PointerEvent) => {\n if (event.pointerType === \"touch\") {\n return;\n }\n leaving = false;\n hovering = true;\n manager.pause(\"hover\");\n report();\n };\n const onPointerLeave = (event: PointerEvent) => {\n if (event.pointerType === \"touch\" || !hovering) {\n return;\n }\n leaving = true;\n settleLeave();\n };\n const onFocusIn = (event: FocusEvent) => {\n const target = event.target;\n if (\n focused ||\n !(target instanceof Element) ||\n !(target === viewport || isFocusVisible(target))\n ) {\n return;\n }\n focused = true;\n manager.pause(\"focus\");\n report();\n };\n const onFocusOut = (event: FocusEvent) => {\n const next = event.relatedTarget;\n if (!focused || (next instanceof Node && viewport.contains(next))) {\n return;\n }\n focused = false;\n manager.resume(\"focus\");\n report();\n };\n const onViewportKeyDown = (event: KeyboardEvent) => {\n if (event.defaultPrevented || previous === null) {\n return;\n }\n if (\n event.key === \"F6\" ||\n (event.key === \"Tab\" && event.shiftKey && event.target === viewport)\n ) {\n event.preventDefault();\n event.stopPropagation();\n restoreFocus();\n }\n };\n const onDocumentKeyDown = (event: KeyboardEvent) => {\n if (event.key !== \"F6\" || event.defaultPrevented || !hasToasts()) {\n return;\n }\n const active = doc.activeElement;\n if (active instanceof Node && viewport.contains(active)) {\n return;\n }\n event.preventDefault();\n previous = active instanceof HTMLElement ? active : null;\n viewport.focus({ preventScroll: true });\n };\n const onVisibility = () => {\n if (doc.visibilityState === \"hidden\") {\n manager.pause(\"hidden\");\n } else {\n manager.resume(\"hidden\");\n }\n };\n\n viewport.addEventListener(\"pointerenter\", onPointerEnter);\n viewport.addEventListener(\"pointerleave\", onPointerLeave);\n viewport.addEventListener(\"focusin\", onFocusIn);\n viewport.addEventListener(\"focusout\", onFocusOut);\n viewport.addEventListener(\"keydown\", onViewportKeyDown);\n doc.addEventListener(\"keydown\", onDocumentKeyDown);\n doc.addEventListener(\"visibilitychange\", onVisibility);\n onVisibility();\n announce(manager.toasts());\n\n return {\n focusAfterClose(root) {\n const active = doc.activeElement;\n if (\n !(active instanceof Element) ||\n !root.contains(active) ||\n !isFocusVisible(active)\n ) {\n return;\n }\n const roots = [\n ...viewport.querySelectorAll<HTMLElement>(ROOT),\n ].filter(\n (element) =>\n element === root ||\n (!element.hasAttribute(\"data-ending-style\") &&\n !element.hasAttribute(\"data-limited\") &&\n !element.inert),\n );\n const index = roots.indexOf(root);\n const next = roots[index + 1] ?? roots[index - 1];\n if (next !== undefined && next !== root) {\n next.focus();\n } else {\n restoreFocus();\n }\n },\n stop() {\n unsubscribe();\n viewport.removeEventListener(\"pointerenter\", onPointerEnter);\n viewport.removeEventListener(\"pointerleave\", onPointerLeave);\n viewport.removeEventListener(\"focusin\", onFocusIn);\n viewport.removeEventListener(\"focusout\", onFocusOut);\n viewport.removeEventListener(\"keydown\", onViewportKeyDown);\n doc.removeEventListener(\"keydown\", onDocumentKeyDown);\n doc.removeEventListener(\"visibilitychange\", onVisibility);\n polite.remove();\n assertive.remove();\n manager.resume(\"hover\");\n manager.resume(\"focus\");\n manager.resume(\"hidden\");\n },\n };\n}\n"],"mappings":";;;;;AAIA,SAAgB,mBAAmB,SAA8B;CAC7D,MAAM,WAAW,QAAQ,MAAM;CAC/B,QAAQ,MAAM,SAAS;CACvB,MAAM,SAAS,QAAQ;CACvB,QAAQ,MAAM,SAAS;CACvB,OAAO;AACX;;AC4GA,SAAS,UAAgB,OAAsD;CAC3E,OAAO,OAAO,UAAU,WAAW,EAAE,OAAO,MAAM,IAAI;AAC1D;;;;;;;AAQA,SAAgB,mBACZ,UAA+B,CAAC,GACd;CAClB,IAAI,QAAQ,QAAQ,SAAS;CAC7B,IAAI,UAAU,QAAQ,WAAW;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QAAQ,CACV,GAAG,SAAS,iBAA8B,IAAI,CAClD,CAAC,CAAC,QACG,YACG,YAAY,QACX,CAAC,QAAQ,aAAa,mBAAmB,KACtC,CAAC,QAAQ,aAAa,cAAc,KACpC,CAAC,QAAQ,KACrB;GACA,MAAM,QAAQ,MAAM,QAAQ,IAAI;GAChC,MAAM,OAAO,MAAM,QAAQ,MAAM,MAAM,QAAQ;GAC/C,IAAI,SAAS,KAAA,KAAa,SAAS,MAC/B,KAAK,MAAM;QAEX,aAAa;EAErB;EACA,OAAO;GACH,YAAY;GACZ,SAAS,oBAAoB,gBAAgB,cAAc;GAC3D,SAAS,oBAAoB,gBAAgB,cAAc;GAC3D,SAAS,oBAAoB,WAAW,SAAS;GACjD,SAAS,oBAAoB,YAAY,UAAU;GACnD,SAAS,oBAAoB,WAAW,iBAAiB;GACzD,IAAI,oBAAoB,WAAW,iBAAiB;GACpD,IAAI,oBAAoB,oBAAoB,YAAY;GACxD,OAAO,OAAO;GACd,UAAU,OAAO;GACjB,QAAQ,OAAO,OAAO;GACtB,QAAQ,OAAO,OAAO;GACtB,QAAQ,OAAO,QAAQ;EAC3B;CACJ;AACJ"}
|
package/dist/toast.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as ToastManagerOptions, c as ToastPriority, d as createToastManager, f as measureToastHeight, i as ToastManager, l as ToastPromiseOptions, n as ToastViewportWatchOptions, o as ToastObject, r as watchToastViewport, s as ToastOptions, t as ToastViewportWatch, u as ToastUpdate } from "./index-BpbT-FsX.js";
|
|
2
|
+
export { type ToastManager, type ToastManagerOptions, type ToastObject, type ToastOptions, type ToastPriority, type ToastPromiseOptions, type ToastUpdate, type ToastViewportWatch, type ToastViewportWatchOptions, createToastManager, measureToastHeight, watchToastViewport };
|
package/dist/toast.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { n as createToastManager, r as measureToastHeight, t as watchToastViewport } from "./toast-BjRpJalM.js";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The grid of a month or year calendar (spec/month-calendar.md): a page of 12 items (the months
|
|
3
|
+
* of a year, or 12 years starting at a multiple of 12), in rows of `columns`. Items are numbers:
|
|
4
|
+
* a month's `monthIndex`, or the year.
|
|
5
|
+
*/
|
|
6
|
+
declare const UNIT_PAGE_SIZE = 12;
|
|
7
|
+
/** The first item of the page holding `index` (January of its year; 2016 for 2026). */
|
|
8
|
+
declare function unitPageStart(index: number): number;
|
|
9
|
+
/** The page starting at `start`, in rows of `columns` items. */
|
|
10
|
+
declare function unitRows(start: number, columns: number): number[][];
|
|
11
|
+
interface UnitKeyOptions {
|
|
12
|
+
rtl: boolean;
|
|
13
|
+
/** Items per row. */
|
|
14
|
+
columns: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The item a key moves the focused item to in a month or year grid (spec/month-calendar.md,
|
|
18
|
+
* "Keyboard": the Calendar's keys mapped to the grid), or `null` when the key does not move it.
|
|
19
|
+
*/
|
|
20
|
+
declare function unitKeyTarget(key: string, focused: number, { rtl, columns }: UnitKeyOptions): number | null;
|
|
21
|
+
export { unitRows as a, unitPageStart as i, UnitKeyOptions as n, unitKeyTarget as r, UNIT_PAGE_SIZE as t };
|