@wow-two-beta/fe 0.0.49 → 0.0.50
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/feedback/FeedbackBus.d.ts +154 -29
- package/dist/feedback/FeedbackBus.js +264 -27
- package/dist/feedback/FeedbackBus.js.map +1 -1
- package/dist/feedback/index.d.ts +1 -1
- package/dist/feedback/index.js +3 -1
- package/dist/foundation/dom/enums/ElementTag.d.ts +2 -0
- package/dist/foundation/dom/enums/ElementTag.js +3 -1
- package/dist/foundation/dom/enums/ElementTag.js.map +1 -1
- package/dist/index.js +325 -312
- package/dist/index.js.map +1 -1
- package/dist/presentation/display/index.js +105 -102
- package/dist/presentation/display/index.js.map +1 -1
- package/dist/presentation/display/notificationCenterGroup/NotificationCenterButton.vue.d.ts +18 -0
- package/dist/presentation/display/notificationCenterGroup/NotificationCenterButton.vue.js +120 -0
- package/dist/presentation/display/notificationCenterGroup/NotificationCenterButton.vue.js.map +1 -0
- package/dist/presentation/display/notificationCenterGroup/NotificationCenterButton2.vue.js +5 -0
- package/dist/presentation/display/notificationCenterGroup/NotificationCenterButton2.vue.js.map +1 -0
- package/dist/presentation/display/notificationCenterGroup/NotificationCenterGroup.vue.d.ts +11 -6
- package/dist/presentation/display/notificationCenterGroup/NotificationCenterGroup.vue.js +255 -61
- package/dist/presentation/display/notificationCenterGroup/NotificationCenterGroup.vue.js.map +1 -1
- package/dist/presentation/display/notificationCenterGroup/{NotificationItem.vue.d.ts → NotificationCenterGroupItem.vue.d.ts} +13 -12
- package/dist/presentation/display/notificationCenterGroup/{NotificationItem.vue.js → NotificationCenterGroupItem.vue.js} +81 -58
- package/dist/presentation/display/notificationCenterGroup/NotificationCenterGroupItem.vue.js.map +1 -0
- package/dist/presentation/display/notificationCenterGroup/NotificationCenterGroupItem2.vue.js +5 -0
- package/dist/presentation/display/notificationCenterGroup/NotificationCenterGroupItem2.vue.js.map +1 -0
- package/dist/presentation/display/notificationCenterGroup/index.d.ts +6 -1
- package/dist/presentation/feedback/feedbackToastHost/FeedbackToastHost.vue.d.ts +1 -9
- package/dist/presentation/feedback/feedbackToastHost/FeedbackToastHost.vue.js +165 -20
- package/dist/presentation/feedback/feedbackToastHost/FeedbackToastHost.vue.js.map +1 -1
- package/dist/presentation/feedback/feedbackToastHost/RemindLaterButton.vue.d.ts +7 -0
- package/dist/presentation/feedback/feedbackToastHost/RemindLaterButton.vue.js +56 -0
- package/dist/presentation/feedback/feedbackToastHost/RemindLaterButton.vue.js.map +1 -0
- package/dist/presentation/feedback/feedbackToastHost/RemindLaterButton2.vue.js +5 -0
- package/dist/presentation/feedback/feedbackToastHost/RemindLaterButton2.vue.js.map +1 -0
- package/dist/presentation/feedback/index.js +9 -1
- package/dist/presentation/feedback/index.js.map +1 -1
- package/dist/presentation/feedback/toast/Toast.vue.d.ts +34 -8
- package/dist/presentation/feedback/toast/Toast.vue.js +290 -85
- package/dist/presentation/feedback/toast/Toast.vue.js.map +1 -1
- package/dist/presentation/feedback/toast/ToastContent.vue.d.ts +25 -0
- package/dist/presentation/feedback/toast/ToastContent.vue.js +78 -0
- package/dist/presentation/feedback/toast/ToastContent.vue.js.map +1 -0
- package/dist/presentation/feedback/toast/ToastContent2.vue.js +5 -0
- package/dist/presentation/feedback/toast/ToastContent2.vue.js.map +1 -0
- package/dist/presentation/feedback/toast/ToastRunningProgress.vue.d.ts +15 -0
- package/dist/presentation/feedback/toast/ToastRunningProgress.vue.js +88 -0
- package/dist/presentation/feedback/toast/ToastRunningProgress.vue.js.map +1 -0
- package/dist/presentation/feedback/toast/ToastRunningProgress2.vue.js +5 -0
- package/dist/presentation/feedback/toast/ToastRunningProgress2.vue.js.map +1 -0
- package/dist/presentation/feedback/toast/ToastSurface.d.ts +8 -0
- package/dist/presentation/feedback/toast/ToastSurface.js +10 -0
- package/dist/presentation/feedback/toast/ToastSurface.js.map +1 -0
- package/dist/presentation/feedback/toast/index.d.ts +1 -0
- package/dist/presentation/feedback/toastHost/ToastContent.d.ts +3 -0
- package/dist/presentation/feedback/toastHost/ToastEntry.d.ts +12 -0
- package/dist/presentation/feedback/toastHost/ToastFocusExtensions.d.ts +2 -0
- package/dist/presentation/feedback/toastHost/ToastFocusExtensions.js +11 -0
- package/dist/presentation/feedback/toastHost/ToastFocusExtensions.js.map +1 -0
- package/dist/presentation/feedback/toastHost/ToastGroup.d.ts +8 -0
- package/dist/presentation/feedback/toastHost/ToastGroupLatest.d.ts +10 -0
- package/dist/presentation/feedback/toastHost/ToastHost.vue.d.ts +55 -110
- package/dist/presentation/feedback/toastHost/ToastHost.vue.js +394 -399
- package/dist/presentation/feedback/toastHost/ToastHost.vue.js.map +1 -1
- package/dist/presentation/feedback/toastHost/ToastHost2.vue.js +4 -5
- package/dist/presentation/feedback/toastHost/ToastHostStore.d.ts +37 -0
- package/dist/presentation/feedback/toastHost/ToastHostStore.js +98 -0
- package/dist/presentation/feedback/toastHost/ToastHostStore.js.map +1 -0
- package/dist/presentation/feedback/toastHost/ToastHostStyles.d.ts +34 -0
- package/dist/presentation/feedback/toastHost/ToastHostStyles.js +44 -0
- package/dist/presentation/feedback/toastHost/ToastHostStyles.js.map +1 -0
- package/dist/presentation/feedback/toastHost/ToastNode.d.ts +3 -0
- package/dist/presentation/feedback/toastHost/ToastOptions.d.ts +72 -0
- package/dist/presentation/feedback/toastHost/ToastProgress.vue.d.ts +11 -0
- package/dist/presentation/feedback/toastHost/ToastProgress.vue.js +44 -0
- package/dist/presentation/feedback/toastHost/ToastProgress.vue.js.map +1 -0
- package/dist/presentation/feedback/toastHost/ToastProgress2.vue.js +5 -0
- package/dist/presentation/feedback/toastHost/ToastProgress2.vue.js.map +1 -0
- package/dist/presentation/feedback/toastHost/ToastPromiseOptions.d.ts +12 -0
- package/dist/presentation/feedback/toastHost/ToastRing.vue.d.ts +14 -0
- package/dist/presentation/feedback/toastHost/ToastRing.vue.js +65 -0
- package/dist/presentation/feedback/toastHost/ToastRing.vue.js.map +1 -0
- package/dist/presentation/feedback/toastHost/ToastRing2.vue.js +5 -0
- package/dist/presentation/feedback/toastHost/ToastRing2.vue.js.map +1 -0
- package/dist/presentation/feedback/toastHost/ToastSeconds.vue.d.ts +9 -0
- package/dist/presentation/feedback/toastHost/ToastSeconds.vue.js +56 -0
- package/dist/presentation/feedback/toastHost/ToastSeconds.vue.js.map +1 -0
- package/dist/presentation/feedback/toastHost/ToastSeconds2.vue.js +5 -0
- package/dist/presentation/feedback/toastHost/ToastSeconds2.vue.js.map +1 -0
- package/dist/presentation/feedback/toastHost/ToastSeverity.d.ts +3 -0
- package/dist/presentation/feedback/toastHost/UseResolvedToasts.d.ts +27 -0
- package/dist/presentation/feedback/toastHost/UseResolvedToasts.js +34 -0
- package/dist/presentation/feedback/toastHost/UseResolvedToasts.js.map +1 -0
- package/dist/presentation/feedback/toastHost/UseToastAnnouncer.d.ts +14 -0
- package/dist/presentation/feedback/toastHost/UseToastAnnouncer.js +106 -0
- package/dist/presentation/feedback/toastHost/UseToastAnnouncer.js.map +1 -0
- package/dist/presentation/feedback/toastHost/UseToastCapacity.d.ts +34 -0
- package/dist/presentation/feedback/toastHost/UseToastCapacity.js +128 -0
- package/dist/presentation/feedback/toastHost/UseToastCapacity.js.map +1 -0
- package/dist/presentation/feedback/toastHost/UseToastClock.d.ts +44 -0
- package/dist/presentation/feedback/toastHost/UseToastClock.js +134 -0
- package/dist/presentation/feedback/toastHost/UseToastClock.js.map +1 -0
- package/dist/presentation/feedback/toastHost/UseToastCountdown.d.ts +26 -0
- package/dist/presentation/feedback/toastHost/UseToastCountdown.js +23 -0
- package/dist/presentation/feedback/toastHost/UseToastCountdown.js.map +1 -0
- package/dist/presentation/feedback/toastHost/UseToastEntries.d.ts +4 -0
- package/dist/presentation/feedback/toastHost/UseToastEntries.js +17 -0
- package/dist/presentation/feedback/toastHost/UseToastEntries.js.map +1 -0
- package/dist/presentation/feedback/toastHost/UseToastExits.d.ts +11 -0
- package/dist/presentation/feedback/toastHost/UseToastExits.js +52 -0
- package/dist/presentation/feedback/toastHost/UseToastExits.js.map +1 -0
- package/dist/presentation/feedback/toastHost/UseToastGroupMotion.d.ts +43 -0
- package/dist/presentation/feedback/toastHost/UseToastGroupMotion.js +173 -0
- package/dist/presentation/feedback/toastHost/UseToastGroupMotion.js.map +1 -0
- package/dist/presentation/feedback/toastHost/UseToastHost.d.ts +10 -0
- package/dist/presentation/feedback/toastHost/UseToastHost.js +14 -0
- package/dist/presentation/feedback/toastHost/UseToastHost.js.map +1 -0
- package/dist/presentation/feedback/toastHost/UseToastHotkey.d.ts +20 -0
- package/dist/presentation/feedback/toastHost/UseToastHotkey.js +66 -0
- package/dist/presentation/feedback/toastHost/UseToastHotkey.js.map +1 -0
- package/dist/presentation/feedback/toastHost/UseToastPins.d.ts +26 -0
- package/dist/presentation/feedback/toastHost/UseToastPins.js +35 -0
- package/dist/presentation/feedback/toastHost/UseToastPins.js.map +1 -0
- package/dist/presentation/feedback/toastHost/UseToastStackMotion.d.ts +27 -0
- package/dist/presentation/feedback/toastHost/UseToastStackMotion.js +96 -0
- package/dist/presentation/feedback/toastHost/UseToastStackMotion.js.map +1 -0
- package/dist/presentation/feedback/toastHost/UseToastSwipe.d.ts +19 -0
- package/dist/presentation/feedback/toastHost/UseToastSwipe.js +173 -0
- package/dist/presentation/feedback/toastHost/UseToastSwipe.js.map +1 -0
- package/dist/presentation/feedback/toastHost/index.d.ts +8 -1
- package/dist/presentation/feedback/toastHost/index.js +7 -1
- package/dist/presentation/feedback/toastHost/index.js.map +1 -1
- package/dist/presentation/feedback/toastHost/styles.css +14 -2
- package/dist/presentation/layout/grid/Grid.variants.d.ts +7 -0
- package/dist/presentation/layout/grid/Grid.variants.js +4 -0
- package/dist/presentation/layout/grid/Grid.variants.js.map +1 -1
- package/dist/presentation/layout/grid/Grid.vue.d.ts +5 -0
- package/dist/presentation/layout/grid/Grid.vue.js +16 -4
- package/dist/presentation/layout/grid/Grid.vue.js.map +1 -1
- package/dist/presentation/layout/grid/index.d.ts +1 -1
- package/dist/presentation/layout/index.js +3 -1
- package/dist/presentation/layout/navbar/Navbar.vue.js.map +1 -1
- package/dist/presentation/overlays/popover/PopoverContent.vue.js +4 -4
- package/dist/presentation/overlays/popover/PopoverContent.vue.js.map +1 -1
- package/dist/presentation/overlays/tooltip/Tooltip.vue.js +8 -9
- package/dist/presentation/overlays/tooltip/Tooltip.vue.js.map +1 -1
- package/package.json +1 -1
- package/dist/presentation/display/notificationCenterGroup/NotificationItem.vue.js.map +0 -1
- package/dist/presentation/display/notificationCenterGroup/NotificationItem2.vue.js +0 -5
- package/dist/presentation/display/notificationCenterGroup/NotificationItem2.vue.js.map +0 -1
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import { VisibleToast } from './UseResolvedToasts';
|
|
3
|
+
import { ToastPinControls } from './UseToastPins';
|
|
4
|
+
/** Defines the reactive inputs a host's expiry clocks follow. */
|
|
5
|
+
export interface ToastClockSources {
|
|
6
|
+
readonly stack: Readonly<Ref<HTMLElement | null>>;
|
|
7
|
+
/** Every live toast, in delivery order. */
|
|
8
|
+
readonly cards: Readonly<Ref<ReadonlyArray<VisibleToast>>>;
|
|
9
|
+
readonly visible: Readonly<Ref<ReadonlyArray<VisibleToast>>>;
|
|
10
|
+
readonly activeIds: Readonly<Ref<ReadonlySet<string>>>;
|
|
11
|
+
readonly visibleIds: Readonly<Ref<ReadonlySet<string>>>;
|
|
12
|
+
/** Dismissed toasts still playing their exit; a pin survives until the exit ends. */
|
|
13
|
+
readonly exiting: Readonly<Ref<ReadonlyArray<VisibleToast>>>;
|
|
14
|
+
readonly expandedDetails: Readonly<Ref<ReadonlySet<string>>>;
|
|
15
|
+
readonly pins: ToastPinControls;
|
|
16
|
+
/** Whether the reader is browsing the expanded overflow list, which holds every ordinary clock. */
|
|
17
|
+
readonly browsing: () => boolean;
|
|
18
|
+
/** The card a finger is dragging, whose ordinary clock holds until the drag ends. */
|
|
19
|
+
readonly swiping: () => string | undefined;
|
|
20
|
+
readonly expire: (id: string) => void;
|
|
21
|
+
}
|
|
22
|
+
/** Defines the host setting the expiry clocks read. */
|
|
23
|
+
export interface ToastClockSettings {
|
|
24
|
+
/** Whether hovering or focusing the stack holds the clocks. */
|
|
25
|
+
readonly canPauseOnHover: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Manages one expiry clock per timed toast. Hover, descendant focus, open details, the overflow list, a swipe in
|
|
29
|
+
* progress and a toast's `pauseExpiry` bank the remaining time; a toast outside the collapsed window waits with
|
|
30
|
+
* its time banked. A deadline runs through all of them. Pinning discards the clock; unpinning starts a fresh one.
|
|
31
|
+
*/
|
|
32
|
+
export declare function useToastClock(sources: ToastClockSources, settings: ToastClockSettings): {
|
|
33
|
+
paused: import('vue').ComputedRef<boolean>;
|
|
34
|
+
pausedIds: import('vue').ComputedRef<Set<string>>;
|
|
35
|
+
hasCountdown: (t: VisibleToast) => boolean;
|
|
36
|
+
countdownKey: (t: VisibleToast) => string;
|
|
37
|
+
timerElapsed: (t: VisibleToast) => number;
|
|
38
|
+
onPointerEnter(event: PointerEvent): void;
|
|
39
|
+
onPointerLeave(): void;
|
|
40
|
+
onFocusin(): void;
|
|
41
|
+
onFocusout(event: FocusEvent): void;
|
|
42
|
+
/** Forgets hover and focus once the stack is gone; neither ends with an event then. */
|
|
43
|
+
release(): void;
|
|
44
|
+
};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { ref, computed, watch, onScopeDispose } from "vue";
|
|
2
|
+
import { hasDeadline } from "./ToastHostStore.js";
|
|
3
|
+
const MaxTimerDelay = 2147483647;
|
|
4
|
+
function useToastClock(sources, settings) {
|
|
5
|
+
const { stack, cards, visible, activeIds, visibleIds, exiting, expandedDetails, pins, browsing, swiping, expire } = sources;
|
|
6
|
+
const hovered = ref(false);
|
|
7
|
+
const focused = ref(false);
|
|
8
|
+
const paused = computed(() => settings.canPauseOnHover && (hovered.value || focused.value));
|
|
9
|
+
const clocks = /* @__PURE__ */ new Map();
|
|
10
|
+
const pausedIds = computed(
|
|
11
|
+
() => new Set(
|
|
12
|
+
visible.value.filter(
|
|
13
|
+
(card) => !hasDeadline(card) && (browsing() || paused.value || card.id === swiping() || card.details && expandedDetails.value.has(card.id) || card.pauseExpiry?.())
|
|
14
|
+
).map((card) => card.id)
|
|
15
|
+
)
|
|
16
|
+
);
|
|
17
|
+
function hasCountdown(t) {
|
|
18
|
+
return Number.isFinite(t.resolvedDuration) && !pins.isPinned(t);
|
|
19
|
+
}
|
|
20
|
+
function countdownKey(t) {
|
|
21
|
+
return `${t.id}:${t.nonce}:${t.resolvedDuration}`;
|
|
22
|
+
}
|
|
23
|
+
function timerElapsed(t) {
|
|
24
|
+
if (hasDeadline(t)) return Math.min(t.resolvedDuration, Math.max(0, Date.now() - t.createdAtMs));
|
|
25
|
+
const clock = clocks.get(t.id);
|
|
26
|
+
if (clock?.nonce !== t.nonce || clock.duration !== t.resolvedDuration) return 0;
|
|
27
|
+
const running = clock.handle === void 0 ? 0 : Date.now() - clock.startedAt;
|
|
28
|
+
return Math.min(clock.duration, clock.duration - clock.remaining + running);
|
|
29
|
+
}
|
|
30
|
+
function pauseClock(clock, now) {
|
|
31
|
+
if (clock.handle === void 0) return;
|
|
32
|
+
window.clearTimeout(clock.handle);
|
|
33
|
+
clock.handle = void 0;
|
|
34
|
+
clock.remaining = Math.max(0, clock.remaining - (now - clock.startedAt));
|
|
35
|
+
}
|
|
36
|
+
function holdsFocus() {
|
|
37
|
+
const active = document.activeElement;
|
|
38
|
+
return !!active && !!stack.value?.contains(active) && !active.closest("[data-toast-exiting]");
|
|
39
|
+
}
|
|
40
|
+
watch(
|
|
41
|
+
[visible, exiting],
|
|
42
|
+
() => {
|
|
43
|
+
if (focused.value && !holdsFocus()) focused.value = false;
|
|
44
|
+
},
|
|
45
|
+
{ flush: "post" }
|
|
46
|
+
);
|
|
47
|
+
function runClock(clock, id, now) {
|
|
48
|
+
const delay = Math.min(clock.remaining, MaxTimerDelay);
|
|
49
|
+
clock.startedAt = now;
|
|
50
|
+
clock.handle = window.setTimeout(() => {
|
|
51
|
+
if (delay >= clock.remaining) {
|
|
52
|
+
expire(id);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const at = Date.now();
|
|
56
|
+
clock.remaining = Math.max(0, clock.remaining - Math.max(delay, at - clock.startedAt));
|
|
57
|
+
runClock(clock, id, at);
|
|
58
|
+
}, delay);
|
|
59
|
+
}
|
|
60
|
+
watch(
|
|
61
|
+
[cards, visibleIds, pausedIds, pins.pinned, pins.effective, exiting],
|
|
62
|
+
([live, showing, held]) => {
|
|
63
|
+
for (const [id, clock] of clocks) {
|
|
64
|
+
if (activeIds.value.has(id)) continue;
|
|
65
|
+
window.clearTimeout(clock.handle);
|
|
66
|
+
clocks.delete(id);
|
|
67
|
+
}
|
|
68
|
+
pins.retain([...live, ...exiting.value]);
|
|
69
|
+
const now = Date.now();
|
|
70
|
+
for (const t of live) {
|
|
71
|
+
let clock = clocks.get(t.id);
|
|
72
|
+
if (!hasCountdown(t)) {
|
|
73
|
+
window.clearTimeout(clock?.handle);
|
|
74
|
+
clocks.delete(t.id);
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const deadline = hasDeadline(t);
|
|
78
|
+
if (!deadline && !showing.has(t.id)) {
|
|
79
|
+
if (clock) pauseClock(clock, now);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (!clock || clock.nonce !== t.nonce || clock.duration !== t.resolvedDuration) {
|
|
83
|
+
window.clearTimeout(clock?.handle);
|
|
84
|
+
clock = {
|
|
85
|
+
nonce: t.nonce,
|
|
86
|
+
duration: t.resolvedDuration,
|
|
87
|
+
remaining: deadline ? Math.max(0, t.expiresAtMs - now) : t.resolvedDuration,
|
|
88
|
+
startedAt: now
|
|
89
|
+
};
|
|
90
|
+
clocks.set(t.id, clock);
|
|
91
|
+
}
|
|
92
|
+
if (held.has(t.id)) {
|
|
93
|
+
pauseClock(clock, now);
|
|
94
|
+
} else if (clock.handle === void 0) {
|
|
95
|
+
runClock(clock, t.id, now);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
{ immediate: true, flush: "post" }
|
|
100
|
+
);
|
|
101
|
+
onScopeDispose(() => {
|
|
102
|
+
for (const clock of clocks.values()) window.clearTimeout(clock.handle);
|
|
103
|
+
clocks.clear();
|
|
104
|
+
});
|
|
105
|
+
return {
|
|
106
|
+
paused,
|
|
107
|
+
pausedIds,
|
|
108
|
+
hasCountdown,
|
|
109
|
+
countdownKey,
|
|
110
|
+
timerElapsed,
|
|
111
|
+
onPointerEnter(event) {
|
|
112
|
+
if (event.pointerType !== "touch") hovered.value = true;
|
|
113
|
+
},
|
|
114
|
+
onPointerLeave() {
|
|
115
|
+
hovered.value = false;
|
|
116
|
+
},
|
|
117
|
+
onFocusin() {
|
|
118
|
+
focused.value = true;
|
|
119
|
+
},
|
|
120
|
+
onFocusout(event) {
|
|
121
|
+
const host = event.currentTarget;
|
|
122
|
+
if (!(event.relatedTarget instanceof Node) || !host.contains(event.relatedTarget)) focused.value = false;
|
|
123
|
+
},
|
|
124
|
+
/** Forgets hover and focus once the stack is gone; neither ends with an event then. */
|
|
125
|
+
release() {
|
|
126
|
+
hovered.value = false;
|
|
127
|
+
focused.value = false;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
export {
|
|
132
|
+
useToastClock
|
|
133
|
+
};
|
|
134
|
+
//# sourceMappingURL=UseToastClock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UseToastClock.js","sources":["../../../../src/presentation/feedback/toastHost/UseToastClock.ts"],"sourcesContent":["import { computed, onScopeDispose, ref, watch, type Ref } from 'vue';\n\nimport { hasDeadline } from './ToastHostStore';\nimport type { VisibleToast } from './UseResolvedToasts';\nimport type { ToastPinControls } from './UseToastPins';\n\n/** @internal The longest delay `setTimeout` keeps (2^31 − 1 ms); a longer one fires at once. */\nconst MaxTimerDelay = 2_147_483_647;\n\n/** @internal One toast's expiry clock — its banked time and the timer running the rest. */\ninterface ToastClock {\n nonce: number;\n duration: number;\n remaining: number;\n startedAt: number;\n handle?: number;\n}\n\n/** Defines the reactive inputs a host's expiry clocks follow. */\nexport interface ToastClockSources {\n readonly stack: Readonly<Ref<HTMLElement | null>>;\n /** Every live toast, in delivery order. */\n readonly cards: Readonly<Ref<ReadonlyArray<VisibleToast>>>;\n readonly visible: Readonly<Ref<ReadonlyArray<VisibleToast>>>;\n readonly activeIds: Readonly<Ref<ReadonlySet<string>>>;\n readonly visibleIds: Readonly<Ref<ReadonlySet<string>>>;\n /** Dismissed toasts still playing their exit; a pin survives until the exit ends. */\n readonly exiting: Readonly<Ref<ReadonlyArray<VisibleToast>>>;\n readonly expandedDetails: Readonly<Ref<ReadonlySet<string>>>;\n readonly pins: ToastPinControls;\n /** Whether the reader is browsing the expanded overflow list, which holds every ordinary clock. */\n readonly browsing: () => boolean;\n /** The card a finger is dragging, whose ordinary clock holds until the drag ends. */\n readonly swiping: () => string | undefined;\n readonly expire: (id: string) => void;\n}\n\n/** Defines the host setting the expiry clocks read. */\nexport interface ToastClockSettings {\n /** Whether hovering or focusing the stack holds the clocks. */\n readonly canPauseOnHover: boolean;\n}\n\n/**\n * Manages one expiry clock per timed toast. Hover, descendant focus, open details, the overflow list, a swipe in\n * progress and a toast's `pauseExpiry` bank the remaining time; a toast outside the collapsed window waits with\n * its time banked. A deadline runs through all of them. Pinning discards the clock; unpinning starts a fresh one.\n */\nexport function useToastClock(sources: ToastClockSources, settings: ToastClockSettings) {\n const { stack, cards, visible, activeIds, visibleIds, exiting, expandedDetails, pins, browsing, swiping, expire } =\n sources;\n const hovered = ref(false);\n const focused = ref(false);\n const paused = computed(() => settings.canPauseOnHover && (hovered.value || focused.value));\n const clocks = new Map<string, ToastClock>();\n\n const pausedIds = computed(\n () =>\n new Set(\n visible.value\n .filter(\n (card) =>\n !hasDeadline(card) &&\n (browsing() ||\n paused.value ||\n card.id === swiping() ||\n (card.details && expandedDetails.value.has(card.id)) ||\n card.pauseExpiry?.()),\n )\n .map((card) => card.id),\n ),\n );\n\n function hasCountdown(t: VisibleToast): boolean {\n return Number.isFinite(t.resolvedDuration) && !pins.isPinned(t);\n }\n\n function countdownKey(t: VisibleToast): string {\n return `${t.id}:${t.nonce}:${t.resolvedDuration}`;\n }\n\n /** The time a toast's display starts from — banked time, plus the run since the clock last resumed. */\n function timerElapsed(t: VisibleToast): number {\n if (hasDeadline(t)) return Math.min(t.resolvedDuration, Math.max(0, Date.now() - t.createdAtMs));\n const clock = clocks.get(t.id);\n if (clock?.nonce !== t.nonce || clock.duration !== t.resolvedDuration) return 0;\n const running = clock.handle === undefined ? 0 : Date.now() - clock.startedAt;\n return Math.min(clock.duration, clock.duration - clock.remaining + running);\n }\n\n function pauseClock(clock: ToastClock, now: number): void {\n if (clock.handle === undefined) return;\n window.clearTimeout(clock.handle);\n clock.handle = undefined;\n clock.remaining = Math.max(0, clock.remaining - (now - clock.startedAt));\n }\n\n /** Reports whether focus still sits on a card that stays — not outside the stack, not on an exiting card. */\n function holdsFocus(): boolean {\n const active = document.activeElement;\n return !!active && !!stack.value?.contains(active) && !active.closest('[data-toast-exiting]');\n }\n\n // A focused card that leaves the stack fires no `focusout`, so each change of the rendered cards rechecks where\n // focus went. Registered before the clocks, so they run on the settled focus in the same flush.\n watch(\n [visible, exiting],\n () => {\n if (focused.value && !holdsFocus()) focused.value = false;\n },\n { flush: 'post' },\n );\n\n /** Runs a clock's remaining time; a delay past the timer limit fires early and re-arms with the rest. */\n function runClock(clock: ToastClock, id: string, now: number): void {\n const delay = Math.min(clock.remaining, MaxTimerDelay);\n clock.startedAt = now;\n clock.handle = window.setTimeout(() => {\n if (delay >= clock.remaining) {\n expire(id);\n return;\n }\n const at = Date.now();\n clock.remaining = Math.max(0, clock.remaining - Math.max(delay, at - clock.startedAt));\n runClock(clock, id, at);\n }, delay);\n }\n\n // Effective pins follow the host's pin default; the end of an exit releases that toast's pin.\n watch(\n [cards, visibleIds, pausedIds, pins.pinned, pins.effective, exiting],\n ([live, showing, held]) => {\n for (const [id, clock] of clocks) {\n if (activeIds.value.has(id)) continue;\n window.clearTimeout(clock.handle);\n clocks.delete(id);\n }\n pins.retain([...live, ...exiting.value]);\n const now = Date.now();\n for (const t of live) {\n let clock = clocks.get(t.id);\n if (!hasCountdown(t)) {\n window.clearTimeout(clock?.handle);\n clocks.delete(t.id);\n continue;\n }\n const deadline = hasDeadline(t);\n if (!deadline && !showing.has(t.id)) {\n if (clock) pauseClock(clock, now);\n continue;\n }\n if (!clock || clock.nonce !== t.nonce || clock.duration !== t.resolvedDuration) {\n window.clearTimeout(clock?.handle);\n clock = {\n nonce: t.nonce,\n duration: t.resolvedDuration,\n remaining: deadline ? Math.max(0, t.expiresAtMs - now) : t.resolvedDuration,\n startedAt: now,\n };\n clocks.set(t.id, clock);\n }\n if (held.has(t.id)) {\n pauseClock(clock, now);\n } else if (clock.handle === undefined) {\n runClock(clock, t.id, now);\n }\n }\n },\n { immediate: true, flush: 'post' },\n );\n\n onScopeDispose(() => {\n for (const clock of clocks.values()) window.clearTimeout(clock.handle);\n clocks.clear();\n });\n\n return {\n paused,\n pausedIds,\n hasCountdown,\n countdownKey,\n timerElapsed,\n onPointerEnter(event: PointerEvent): void {\n if (event.pointerType !== 'touch') hovered.value = true;\n },\n onPointerLeave(): void {\n hovered.value = false;\n },\n onFocusin(): void {\n focused.value = true;\n },\n onFocusout(event: FocusEvent): void {\n const host = event.currentTarget as HTMLElement;\n if (!(event.relatedTarget instanceof Node) || !host.contains(event.relatedTarget)) focused.value = false;\n },\n /** Forgets hover and focus once the stack is gone; neither ends with an event then. */\n release(): void {\n hovered.value = false;\n focused.value = false;\n },\n };\n}\n"],"names":[],"mappings":";;AAOA,MAAM,gBAAgB;AAyCf,SAAS,cAAc,SAA4B,UAA8B;AACtF,QAAM,EAAE,OAAO,OAAO,SAAS,WAAW,YAAY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,CAAC,KAAK,SAAS,MAAM,aAAa,EAAG,SAAQ,QAAQ;AAAA,IACrG;AAAA;AAAA,IAEA,UAAgB;AACd,cAAQ,QAAQ;AAChB,cAAQ,QAAQ;AAAA,IAClB;AAAA,EAAA;AAEJ;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Severity } from '../../../foundation/styles';
|
|
2
|
+
/** Defines props shared by every countdown display — it mirrors the host's expiry clock, never drives it. */
|
|
3
|
+
export interface ToastCountdownProps {
|
|
4
|
+
/** The toast's full lifetime in ms. */
|
|
5
|
+
readonly duration: number;
|
|
6
|
+
/** The time already spent when the display mounts, in ms. */
|
|
7
|
+
readonly elapsed?: number;
|
|
8
|
+
/** The hold state — true freezes the display while the host's clock is held. */
|
|
9
|
+
readonly isPaused?: boolean;
|
|
10
|
+
/** The severity whose tone the countdown takes. */
|
|
11
|
+
readonly severity?: Severity;
|
|
12
|
+
}
|
|
13
|
+
/** Defines the clock reading a countdown runs from. */
|
|
14
|
+
export interface ToastCountdownClock {
|
|
15
|
+
/** The toast's full lifetime in ms. */
|
|
16
|
+
readonly duration: number;
|
|
17
|
+
/** The time already spent when the display mounts, in ms. */
|
|
18
|
+
readonly elapsed: number;
|
|
19
|
+
/** Whether the display is held. */
|
|
20
|
+
readonly isPaused: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Manages one Web Animations API countdown on a template ref, paused and resumed in step with the host's expiry
|
|
24
|
+
* clock; environments without `animate` leave the element static at full.
|
|
25
|
+
*/
|
|
26
|
+
export declare function useToastCountdown(element: () => Element | null, keyframes: ReadonlyArray<Keyframe>, countdown: ToastCountdownClock): void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { onMounted, watch, onScopeDispose } from "vue";
|
|
2
|
+
function useToastCountdown(element, keyframes, countdown) {
|
|
3
|
+
let animation;
|
|
4
|
+
onMounted(() => {
|
|
5
|
+
const target = element();
|
|
6
|
+
if (!target || typeof target.animate !== "function") return;
|
|
7
|
+
animation = target.animate([...keyframes], { duration: countdown.duration, easing: "linear", fill: "forwards" });
|
|
8
|
+
if (countdown.elapsed > 0) animation.currentTime = countdown.elapsed;
|
|
9
|
+
if (countdown.isPaused) animation.pause();
|
|
10
|
+
});
|
|
11
|
+
watch(
|
|
12
|
+
() => countdown.isPaused,
|
|
13
|
+
(isPaused) => {
|
|
14
|
+
if (isPaused) animation?.pause();
|
|
15
|
+
else animation?.play();
|
|
16
|
+
}
|
|
17
|
+
);
|
|
18
|
+
onScopeDispose(() => animation?.cancel());
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
useToastCountdown
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=UseToastCountdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UseToastCountdown.js","sources":["../../../../src/presentation/feedback/toastHost/UseToastCountdown.ts"],"sourcesContent":["import { onMounted, onScopeDispose, watch } from 'vue';\n\nimport type { Severity } from '../../../foundation/styles';\n\n/** Defines props shared by every countdown display — it mirrors the host's expiry clock, never drives it. */\nexport interface ToastCountdownProps {\n /** The toast's full lifetime in ms. */\n readonly duration: number;\n\n /** The time already spent when the display mounts, in ms. */\n readonly elapsed?: number;\n\n /** The hold state — true freezes the display while the host's clock is held. */\n readonly isPaused?: boolean;\n\n /** The severity whose tone the countdown takes. */\n readonly severity?: Severity;\n}\n\n/** Defines the clock reading a countdown runs from. */\nexport interface ToastCountdownClock {\n /** The toast's full lifetime in ms. */\n readonly duration: number;\n\n /** The time already spent when the display mounts, in ms. */\n readonly elapsed: number;\n\n /** Whether the display is held. */\n readonly isPaused: boolean;\n}\n\n/**\n * Manages one Web Animations API countdown on a template ref, paused and resumed in step with the host's expiry\n * clock; environments without `animate` leave the element static at full.\n */\nexport function useToastCountdown(\n element: () => Element | null,\n keyframes: ReadonlyArray<Keyframe>,\n countdown: ToastCountdownClock,\n): void {\n let animation: Animation | undefined;\n onMounted(() => {\n const target = element();\n if (!target || typeof target.animate !== 'function') return;\n animation = target.animate([...keyframes], { duration: countdown.duration, easing: 'linear', fill: 'forwards' });\n if (countdown.elapsed > 0) animation.currentTime = countdown.elapsed;\n if (countdown.isPaused) animation.pause();\n });\n watch(\n () => countdown.isPaused,\n (isPaused) => {\n if (isPaused) animation?.pause();\n else animation?.play();\n },\n );\n onScopeDispose(() => animation?.cancel());\n}\n"],"names":[],"mappings":";AAmCO,SAAS,kBACd,SACA,WACA,WACM;AACN,MAAI;AACJ,YAAU,MAAM;AACd,UAAM,SAAS,QAAA;AACf,QAAI,CAAC,UAAU,OAAO,OAAO,YAAY,WAAY;AACrD,gBAAY,OAAO,QAAQ,CAAC,GAAG,SAAS,GAAG,EAAE,UAAU,UAAU,UAAU,QAAQ,UAAU,MAAM,YAAY;AAC/G,QAAI,UAAU,UAAU,EAAG,WAAU,cAAc,UAAU;AAC7D,QAAI,UAAU,SAAU,WAAU,MAAA;AAAA,EACpC,CAAC;AACD;AAAA,IACE,MAAM,UAAU;AAAA,IAChB,CAAC,aAAa;AACZ,UAAI,qBAAqB,MAAA;AAAA,sBACT,KAAA;AAAA,IAClB;AAAA,EAAA;AAEF,iBAAe,MAAM,WAAW,QAAQ;AAC1C;"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ShallowRef } from 'vue';
|
|
2
|
+
import { ToastEntry } from './ToastEntry';
|
|
3
|
+
/** Manages a mirror of the store's live toasts while the calling component is mounted; a server render sees none. */
|
|
4
|
+
export declare function useToastEntries(): Readonly<ShallowRef<ReadonlyArray<ToastEntry>>>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { shallowRef, onMounted, onScopeDispose } from "vue";
|
|
2
|
+
import { toastHost } from "./ToastHostStore.js";
|
|
3
|
+
function useToastEntries() {
|
|
4
|
+
const entries = shallowRef([]);
|
|
5
|
+
let unsubscribe;
|
|
6
|
+
onMounted(() => {
|
|
7
|
+
unsubscribe = toastHost.subscribe((next) => {
|
|
8
|
+
entries.value = next;
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
onScopeDispose(() => unsubscribe?.());
|
|
12
|
+
return entries;
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
useToastEntries
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=UseToastEntries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UseToastEntries.js","sources":["../../../../src/presentation/feedback/toastHost/UseToastEntries.ts"],"sourcesContent":["import { onMounted, onScopeDispose, shallowRef, type ShallowRef } from 'vue';\n\nimport type { ToastEntry } from './ToastEntry';\nimport { toastHost } from './ToastHostStore';\n\n/** Manages a mirror of the store's live toasts while the calling component is mounted; a server render sees none. */\nexport function useToastEntries(): Readonly<ShallowRef<ReadonlyArray<ToastEntry>>> {\n const entries = shallowRef<ReadonlyArray<ToastEntry>>([]);\n let unsubscribe: (() => void) | undefined;\n onMounted(() => {\n unsubscribe = toastHost.subscribe((next) => {\n entries.value = next;\n });\n });\n onScopeDispose(() => unsubscribe?.());\n return entries;\n}\n"],"names":[],"mappings":";;AAMO,SAAS,kBAAmE;AACjF,QAAM,UAAU,WAAsC,EAAE;AACxD,MAAI;AACJ,YAAU,MAAM;AACd,kBAAc,UAAU,UAAU,CAAC,SAAS;AAC1C,cAAQ,QAAQ;AAAA,IAClB,CAAC;AAAA,EACH,CAAC;AACD,iBAAe,MAAM,eAAe;AACpC,SAAO;AACT;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import { VisibleToast } from './UseResolvedToasts';
|
|
3
|
+
/**
|
|
4
|
+
* Manages the exit list, retaining each dismissed card in its slot until its exit ends. `removeExiting` runs
|
|
5
|
+
* when the exit's `Presence` unmounts the card; a card that returns to the visible list leaves the list at once.
|
|
6
|
+
* Keyboard focus inside a departing card moves to the nearest card that stays, or to the overflow control.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useToastExits(stack: Readonly<Ref<HTMLElement | null>>, visible: Readonly<Ref<ReadonlyArray<VisibleToast>>>, visibleIds: Readonly<Ref<ReadonlySet<string>>>, activeIds: Readonly<Ref<ReadonlySet<string>>>): {
|
|
9
|
+
exiting: import('vue').ShallowRef<readonly VisibleToast[], readonly VisibleToast[]>;
|
|
10
|
+
removeExiting: (id: string) => void;
|
|
11
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { shallowRef, watch, nextTick } from "vue";
|
|
2
|
+
import { isFocusVisible } from "./ToastFocusExtensions.js";
|
|
3
|
+
function neighbourOf(host, leaving) {
|
|
4
|
+
const present = (node) => node instanceof HTMLElement && node.dataset.toastId !== void 0 && !node.hasAttribute("data-toast-exiting");
|
|
5
|
+
for (let node = leaving.nextElementSibling; node; node = node.nextElementSibling) if (present(node)) return node;
|
|
6
|
+
for (let node = leaving.previousElementSibling; node; node = node.previousElementSibling) {
|
|
7
|
+
if (present(node)) return node;
|
|
8
|
+
}
|
|
9
|
+
return host.querySelector("[data-toast-overflow]");
|
|
10
|
+
}
|
|
11
|
+
function useToastExits(stack, visible, visibleIds, activeIds) {
|
|
12
|
+
const exiting = shallowRef([]);
|
|
13
|
+
let previous = [];
|
|
14
|
+
function handOffFocus(gone) {
|
|
15
|
+
const host = stack.value;
|
|
16
|
+
if (!host || gone.length === 0) return;
|
|
17
|
+
const focused = document.activeElement;
|
|
18
|
+
if (!host.contains(focused) || !isFocusVisible(focused)) return;
|
|
19
|
+
const leaving = [...host.children].find(
|
|
20
|
+
(node) => node instanceof HTMLElement && node.contains(focused) && gone.some((card) => card.id === node.dataset.toastId)
|
|
21
|
+
);
|
|
22
|
+
if (!leaving) return;
|
|
23
|
+
void nextTick(() => {
|
|
24
|
+
const current = document.activeElement;
|
|
25
|
+
if (stack.value !== host || current !== focused && current !== document.body && current !== null) return;
|
|
26
|
+
neighbourOf(host, leaving)?.focus({ preventScroll: true });
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
watch(
|
|
30
|
+
visibleIds,
|
|
31
|
+
(ids) => {
|
|
32
|
+
const gone = previous.filter((p) => !ids.has(p.id) && !activeIds.value.has(p.id));
|
|
33
|
+
previous = visible.value;
|
|
34
|
+
handOffFocus(gone);
|
|
35
|
+
const current = exiting.value;
|
|
36
|
+
const known = new Set(current.map((e) => e.id));
|
|
37
|
+
const merged = [...current, ...gone.filter((g) => !known.has(g.id))].filter((e) => !ids.has(e.id));
|
|
38
|
+
if (merged.length !== current.length || !merged.every((e, i) => e.id === current[i]?.id)) {
|
|
39
|
+
exiting.value = merged;
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
{ immediate: true }
|
|
43
|
+
);
|
|
44
|
+
function removeExiting(id) {
|
|
45
|
+
exiting.value = exiting.value.filter((e) => e.id !== id);
|
|
46
|
+
}
|
|
47
|
+
return { exiting, removeExiting };
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
useToastExits
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=UseToastExits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UseToastExits.js","sources":["../../../../src/presentation/feedback/toastHost/UseToastExits.ts"],"sourcesContent":["import { nextTick, shallowRef, watch, type Ref } from 'vue';\n\nimport { isFocusVisible } from './ToastFocusExtensions';\nimport type { VisibleToast } from './UseResolvedToasts';\n\n/** @internal The present card nearest a departing one — the next toward the far end, else the previous. */\nfunction neighbourOf(host: HTMLElement, leaving: Element): HTMLElement | null {\n const present = (node: Element | null): node is HTMLElement =>\n node instanceof HTMLElement && node.dataset.toastId !== undefined && !node.hasAttribute('data-toast-exiting');\n for (let node = leaving.nextElementSibling; node; node = node.nextElementSibling) if (present(node)) return node;\n for (let node = leaving.previousElementSibling; node; node = node.previousElementSibling) {\n if (present(node)) return node;\n }\n return host.querySelector<HTMLElement>('[data-toast-overflow]');\n}\n\n/**\n * Manages the exit list, retaining each dismissed card in its slot until its exit ends. `removeExiting` runs\n * when the exit's `Presence` unmounts the card; a card that returns to the visible list leaves the list at once.\n * Keyboard focus inside a departing card moves to the nearest card that stays, or to the overflow control.\n */\nexport function useToastExits(\n stack: Readonly<Ref<HTMLElement | null>>,\n visible: Readonly<Ref<ReadonlyArray<VisibleToast>>>,\n visibleIds: Readonly<Ref<ReadonlySet<string>>>,\n activeIds: Readonly<Ref<ReadonlySet<string>>>,\n) {\n const exiting = shallowRef<ReadonlyArray<VisibleToast>>([]);\n let previous: ReadonlyArray<VisibleToast> = [];\n\n function handOffFocus(gone: ReadonlyArray<VisibleToast>): void {\n const host = stack.value;\n if (!host || gone.length === 0) return;\n const focused = document.activeElement;\n if (!host.contains(focused) || !isFocusVisible(focused)) return;\n const leaving = [...host.children].find(\n (node) =>\n node instanceof HTMLElement && node.contains(focused) && gone.some((card) => card.id === node.dataset.toastId),\n );\n if (!leaving) return;\n void nextTick(() => {\n const current = document.activeElement;\n if (stack.value !== host || (current !== focused && current !== document.body && current !== null)) return;\n neighbourOf(host, leaving)?.focus({ preventScroll: true });\n });\n }\n\n // Runs before Vue patches the list, so a departing card never leaves its slot for a frame.\n watch(\n visibleIds,\n (ids) => {\n const gone = previous.filter((p) => !ids.has(p.id) && !activeIds.value.has(p.id));\n previous = visible.value;\n handOffFocus(gone);\n const current = exiting.value;\n const known = new Set(current.map((e) => e.id));\n const merged = [...current, ...gone.filter((g) => !known.has(g.id))].filter((e) => !ids.has(e.id));\n if (merged.length !== current.length || !merged.every((e, i) => e.id === current[i]?.id)) {\n exiting.value = merged;\n }\n },\n { immediate: true },\n );\n\n function removeExiting(id: string): void {\n exiting.value = exiting.value.filter((e) => e.id !== id);\n }\n\n return { exiting, removeExiting };\n}\n"],"names":[],"mappings":";;AAMA,SAAS,YAAY,MAAmB,SAAsC;AAC5E,QAAM,UAAU,CAAC,SACf,gBAAgB,eAAe,KAAK,QAAQ,YAAY,UAAa,CAAC,KAAK,aAAa,oBAAoB;AAC9G,WAAS,OAAO,QAAQ,oBAAoB,MAAM,OAAO,KAAK,mBAAoB,KAAI,QA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,MAAM,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC;AACjG,UAAI,OAAO,WAAW,QAAQ,UAAU,CAAC,OAAO,MAAM,CAAC,GAAG,MAAM,EAAE,OAAO,QAAQ,CAAC,GAAG,EAAE,GAAG;AACxF,gBAAQ,QAAQ;AAAA,MAClB;AAAA,IACF;AAAA,IACA,EAAE,WAAW,KAAA;AAAA,EAAK;AAGpB,WAAS,cAAc,IAAkB;AACvC,YAAQ,QAAQ,QAAQ,MAAM,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE;AAAA,EACzD;AAEA,SAAO,EAAE,SAAS,cAAA;AACpB;"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import { OverlayPosition } from '../../../foundation/styles';
|
|
3
|
+
import { ToastGroupMotion } from './ToastHost.vue';
|
|
4
|
+
import { ToastOptions } from './ToastOptions';
|
|
5
|
+
import { VisibleToast } from './UseResolvedToasts';
|
|
6
|
+
/** Defines how a card changed in place. */
|
|
7
|
+
export declare const ToastChange: {
|
|
8
|
+
/** Refers to a change of the card's height. */
|
|
9
|
+
readonly Resize: "resize";
|
|
10
|
+
/** Refers to a group's first merge. */
|
|
11
|
+
readonly Merge: "merge";
|
|
12
|
+
/** Refers to a further arrival in a group. */
|
|
13
|
+
readonly Arrival: "arrival";
|
|
14
|
+
/** Refers to a change of the card's copy or severity. */
|
|
15
|
+
readonly Content: "content";
|
|
16
|
+
};
|
|
17
|
+
export type ToastChange = (typeof ToastChange)[keyof typeof ToastChange];
|
|
18
|
+
/** Defines the elements, lists and host state a card's in-place motion reads. */
|
|
19
|
+
export interface ToastGroupMotionSources {
|
|
20
|
+
readonly stack: Readonly<Ref<HTMLElement | null>>;
|
|
21
|
+
readonly visible: Readonly<Ref<ReadonlyArray<VisibleToast>>>;
|
|
22
|
+
readonly position: () => OverlayPosition;
|
|
23
|
+
readonly groupMotion: () => ToastGroupMotion;
|
|
24
|
+
readonly reducedMotion: Readonly<Ref<boolean>>;
|
|
25
|
+
/** Whether the stack scrolls, so a preview starts at its visible edge. */
|
|
26
|
+
readonly scrolls: () => boolean;
|
|
27
|
+
readonly isExpanded: (id: string) => boolean;
|
|
28
|
+
readonly copyOf: (toast: ToastOptions) => Pick<ToastOptions, 'title' | 'description'>;
|
|
29
|
+
}
|
|
30
|
+
/** Defines the host settings a card's in-place motion reads. */
|
|
31
|
+
export interface ToastGroupMotionSettings {
|
|
32
|
+
/** The time cards take to slide together, in ms; 0 is an instant reflow. */
|
|
33
|
+
readonly moveDuration: number;
|
|
34
|
+
/** The space between cards, in px. */
|
|
35
|
+
readonly gap: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Manages the animation of a card that changes in place: a group's merge preview flying over the stack, the
|
|
39
|
+
* count glowing as a member arrives, a height change, and a highlight when the copy or severity changes.
|
|
40
|
+
*/
|
|
41
|
+
export declare function useToastGroupMotion(sources: ToastGroupMotionSources, settings: ToastGroupMotionSettings): {
|
|
42
|
+
captureToastChange: (id: string, change: ToastChange) => void;
|
|
43
|
+
};
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { watch, onScopeDispose, nextTick } from "vue";
|
|
2
|
+
import { animate } from "../../../foundation/animation/Animate.js";
|
|
3
|
+
import { isFocusVisible } from "./ToastFocusExtensions.js";
|
|
4
|
+
import { isRunning } from "./ToastHostStore.js";
|
|
5
|
+
const ToastChange = {
|
|
6
|
+
/** Refers to a change of the card's height. */
|
|
7
|
+
Resize: "resize",
|
|
8
|
+
/** Refers to a group's first merge. */
|
|
9
|
+
Merge: "merge",
|
|
10
|
+
/** Refers to a further arrival in a group. */
|
|
11
|
+
Arrival: "arrival",
|
|
12
|
+
/** Refers to a change of the card's copy or severity. */
|
|
13
|
+
Content: "content"
|
|
14
|
+
};
|
|
15
|
+
function useToastGroupMotion(sources, settings) {
|
|
16
|
+
const { stack, visible, position, reducedMotion, scrolls, isExpanded, copyOf } = sources;
|
|
17
|
+
const updateMotions = /* @__PURE__ */ new Map();
|
|
18
|
+
function stop() {
|
|
19
|
+
for (const animations of updateMotions.values()) {
|
|
20
|
+
for (const animation of animations) animation.cancel();
|
|
21
|
+
}
|
|
22
|
+
updateMotions.clear();
|
|
23
|
+
}
|
|
24
|
+
function animateGroupCard(host, card, arrival, initialExtraHeight, expanded) {
|
|
25
|
+
const bottom = position().startsWith("bottom");
|
|
26
|
+
const room = Number.parseFloat(getComputedStyle(host).maxHeight) || window.innerHeight;
|
|
27
|
+
const scrolling = scrolls();
|
|
28
|
+
const startEdge = scrolling ? host.scrollTop : host.offsetHeight + initialExtraHeight - room;
|
|
29
|
+
const endEdge = scrolling ? host.scrollTop + host.clientHeight : room;
|
|
30
|
+
const details = expanded ? card.querySelector("[data-toast-details]") : null;
|
|
31
|
+
const landing = details ? Math.round(details.getBoundingClientRect().top - card.getBoundingClientRect().top) : 0;
|
|
32
|
+
const target = card.offsetTop + landing;
|
|
33
|
+
if (scrolling && (target < startEdge || target >= endEdge)) return [];
|
|
34
|
+
let tail = bottom ? card.offsetTop : card.offsetTop + card.offsetHeight;
|
|
35
|
+
for (const item of host.children) {
|
|
36
|
+
if (!(item instanceof HTMLElement) || !item.dataset.toastId || item.hasAttribute("data-toast-exiting")) continue;
|
|
37
|
+
tail = bottom ? Math.min(tail, item.offsetTop) : Math.max(tail, item.offsetTop + item.offsetHeight);
|
|
38
|
+
}
|
|
39
|
+
const origin = bottom ? Math.max(startEdge, tail - settings.gap - arrival.offsetHeight) : Math.min(endEdge - arrival.offsetHeight, tail + settings.gap + initialExtraHeight);
|
|
40
|
+
const distance = origin - target;
|
|
41
|
+
if ((bottom ? -distance : distance) < 16) return [];
|
|
42
|
+
const duration = settings.moveDuration * 2;
|
|
43
|
+
return [
|
|
44
|
+
animate(card, [{ zIndex: 2 }, { zIndex: 2 }], { duration }),
|
|
45
|
+
animate(
|
|
46
|
+
arrival,
|
|
47
|
+
[
|
|
48
|
+
{ translate: `0 ${landing + distance}px`, scale: 1, opacity: 0.9, visibility: "visible" },
|
|
49
|
+
{ translate: `0 ${landing + distance * 0.65}px`, scale: 1, opacity: 1, offset: 0.32, visibility: "visible" },
|
|
50
|
+
{ translate: landing ? `0 ${landing}px` : "none", scale: 0.94, opacity: 0, visibility: "visible" }
|
|
51
|
+
],
|
|
52
|
+
{ duration, easing: "ease-out" }
|
|
53
|
+
)
|
|
54
|
+
];
|
|
55
|
+
}
|
|
56
|
+
function animateHighlight(node, peak, rest, delay = 0) {
|
|
57
|
+
const duration = settings.moveDuration;
|
|
58
|
+
if (reducedMotion.value) return animate(node, [peak, peak], { duration: duration * 3 });
|
|
59
|
+
return animate(
|
|
60
|
+
node,
|
|
61
|
+
[
|
|
62
|
+
{ ...rest, easing: "ease-out" },
|
|
63
|
+
{ ...peak, offset: 0.065 },
|
|
64
|
+
{ ...peak, offset: 0.25, easing: "ease-in-out" },
|
|
65
|
+
rest
|
|
66
|
+
],
|
|
67
|
+
{ duration: duration * 6, delay, easing: "linear" }
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
function captureToastChange(id, change) {
|
|
71
|
+
const host = stack.value;
|
|
72
|
+
const node = Array.from(host?.children ?? []).find(
|
|
73
|
+
(child) => child instanceof HTMLElement && child.dataset.toastId === id
|
|
74
|
+
);
|
|
75
|
+
const surface = node?.firstElementChild;
|
|
76
|
+
if (!host || !node || !(surface instanceof HTMLElement)) return;
|
|
77
|
+
const firstHeight = surface.offsetHeight;
|
|
78
|
+
const containedFocus = node.contains(document.activeElement);
|
|
79
|
+
const keyboardFocus = containedFocus && isFocusVisible(document.activeElement);
|
|
80
|
+
void nextTick(() => {
|
|
81
|
+
if (stack.value !== host || !node.isConnected || node.hasAttribute("data-toast-exiting")) return;
|
|
82
|
+
if (containedFocus && document.activeElement === document.body) {
|
|
83
|
+
const disclosure = node.querySelector("button[aria-controls]");
|
|
84
|
+
(disclosure ?? (keyboardFocus ? node : null))?.focus({ preventScroll: true });
|
|
85
|
+
}
|
|
86
|
+
if (settings.moveDuration <= 0 || typeof surface.animate !== "function") return;
|
|
87
|
+
for (const animation of updateMotions.get(node) ?? []) animation.cancel();
|
|
88
|
+
const duration = settings.moveDuration;
|
|
89
|
+
const motionAllowed = !reducedMotion.value;
|
|
90
|
+
const lastHeight = surface.offsetHeight;
|
|
91
|
+
const animations = [];
|
|
92
|
+
const incoming = change === ToastChange.Merge || change === ToastChange.Arrival;
|
|
93
|
+
const arrival = incoming && motionAllowed ? node.querySelector("[data-toast-group-arrival]") : null;
|
|
94
|
+
const flight = arrival ? animateGroupCard(host, node, arrival, Math.max(0, firstHeight - lastHeight), isExpanded(id)) : [];
|
|
95
|
+
animations.push(...flight);
|
|
96
|
+
if (motionAllowed && Math.abs(firstHeight - lastHeight) >= 1) {
|
|
97
|
+
animations.push(
|
|
98
|
+
animate(
|
|
99
|
+
surface,
|
|
100
|
+
[
|
|
101
|
+
{ height: `${firstHeight}px`, overflow: "clip" },
|
|
102
|
+
{ height: `${lastHeight}px`, overflow: "clip" }
|
|
103
|
+
],
|
|
104
|
+
{ duration }
|
|
105
|
+
)
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
if (motionAllowed && change === ToastChange.Merge) {
|
|
109
|
+
animations.push(
|
|
110
|
+
animate(
|
|
111
|
+
node.querySelector("[data-toast-summary]"),
|
|
112
|
+
[
|
|
113
|
+
{ translate: "0 3px", opacity: 0.55 },
|
|
114
|
+
{ translate: "none", opacity: 1 }
|
|
115
|
+
],
|
|
116
|
+
{ duration }
|
|
117
|
+
)
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
if (incoming) {
|
|
121
|
+
animations.push(
|
|
122
|
+
animateHighlight(
|
|
123
|
+
node.querySelector("[data-toast-group-count-highlight]"),
|
|
124
|
+
{
|
|
125
|
+
color: "var(--toast-count-peak, var(--color-popover-foreground))",
|
|
126
|
+
textShadow: motionAllowed ? "var(--toast-count-glow, 0 0 0.4em color-mix(in oklab, var(--color-primary) 75%, transparent))" : "none"
|
|
127
|
+
},
|
|
128
|
+
{ color: "var(--toast-count-rest, var(--color-muted-foreground))", textShadow: "none" },
|
|
129
|
+
flight.length > 0 ? duration * 1.5 : 0
|
|
130
|
+
)
|
|
131
|
+
);
|
|
132
|
+
} else if (change === ToastChange.Content) {
|
|
133
|
+
animations.push(
|
|
134
|
+
animateHighlight(node.querySelector("[data-toast-update-highlight]"), { opacity: 1 }, { opacity: 0 })
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
updateMotions.set(node, animations);
|
|
138
|
+
void Promise.all(animations.map((animation) => animation.finished)).then(() => {
|
|
139
|
+
if (updateMotions.get(node) === animations) updateMotions.delete(node);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
watch(visible, (next, previous) => {
|
|
144
|
+
if (previous.length === 0) return;
|
|
145
|
+
const earlier = new Map(previous.map((card) => [card.id, card]));
|
|
146
|
+
for (const card of next) {
|
|
147
|
+
const prior = earlier.get(card.id);
|
|
148
|
+
if (!prior || prior.nonce === card.nonce) continue;
|
|
149
|
+
const before = prior.group?.count;
|
|
150
|
+
const after = card.group?.count;
|
|
151
|
+
if (before !== void 0 && after !== void 0 && before !== after) {
|
|
152
|
+
captureToastChange(
|
|
153
|
+
card.id,
|
|
154
|
+
after < before ? ToastChange.Resize : before === 1 ? ToastChange.Merge : ToastChange.Arrival
|
|
155
|
+
);
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
const oldCopy = copyOf(prior);
|
|
159
|
+
const newCopy = copyOf(card);
|
|
160
|
+
if (oldCopy.title !== newCopy.title || oldCopy.description !== newCopy.description || prior.severity !== card.severity || isRunning(prior) && !isRunning(card)) {
|
|
161
|
+
captureToastChange(card.id, ToastChange.Content);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
watch([reducedMotion, position, () => settings.moveDuration, sources.groupMotion], stop);
|
|
166
|
+
onScopeDispose(stop);
|
|
167
|
+
return { captureToastChange };
|
|
168
|
+
}
|
|
169
|
+
export {
|
|
170
|
+
ToastChange,
|
|
171
|
+
useToastGroupMotion
|
|
172
|
+
};
|
|
173
|
+
//# sourceMappingURL=UseToastGroupMotion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UseToastGroupMotion.js","sources":["../../../../src/presentation/feedback/toastHost/UseToastGroupMotion.ts"],"sourcesContent":["import { nextTick, onScopeDispose, watch, type Ref } from 'vue';\n\nimport { animate, type AnimationHandle } from '../../../foundation/animation';\nimport type { OverlayPosition } from '../../../foundation/styles';\nimport { isFocusVisible } from './ToastFocusExtensions';\nimport type { ToastGroupMotion } from './ToastHost.vue';\nimport { isRunning } from './ToastHostStore';\nimport type { ToastOptions } from './ToastOptions';\nimport type { VisibleToast } from './UseResolvedToasts';\n\n/** Defines how a card changed in place. */\nexport const ToastChange = {\n /** Refers to a change of the card's height. */\n Resize: 'resize',\n /** Refers to a group's first merge. */\n Merge: 'merge',\n /** Refers to a further arrival in a group. */\n Arrival: 'arrival',\n /** Refers to a change of the card's copy or severity. */\n Content: 'content',\n} as const;\n\nexport type ToastChange = (typeof ToastChange)[keyof typeof ToastChange];\n\n/** Defines the elements, lists and host state a card's in-place motion reads. */\nexport interface ToastGroupMotionSources {\n readonly stack: Readonly<Ref<HTMLElement | null>>;\n readonly visible: Readonly<Ref<ReadonlyArray<VisibleToast>>>;\n readonly position: () => OverlayPosition;\n readonly groupMotion: () => ToastGroupMotion;\n readonly reducedMotion: Readonly<Ref<boolean>>;\n /** Whether the stack scrolls, so a preview starts at its visible edge. */\n readonly scrolls: () => boolean;\n readonly isExpanded: (id: string) => boolean;\n readonly copyOf: (toast: ToastOptions) => Pick<ToastOptions, 'title' | 'description'>;\n}\n\n/** Defines the host settings a card's in-place motion reads. */\nexport interface ToastGroupMotionSettings {\n /** The time cards take to slide together, in ms; 0 is an instant reflow. */\n readonly moveDuration: number;\n\n /** The space between cards, in px. */\n readonly gap: number;\n}\n\n/**\n * Manages the animation of a card that changes in place: a group's merge preview flying over the stack, the\n * count glowing as a member arrives, a height change, and a highlight when the copy or severity changes.\n */\nexport function useToastGroupMotion(sources: ToastGroupMotionSources, settings: ToastGroupMotionSettings) {\n const { stack, visible, position, reducedMotion, scrolls, isExpanded, copyOf } = sources;\n const updateMotions = new Map<HTMLElement, Array<AnimationHandle>>();\n\n function stop(): void {\n for (const animations of updateMotions.values()) {\n for (const animation of animations) animation.cancel();\n }\n updateMotions.clear();\n }\n\n function animateGroupCard(\n host: HTMLElement,\n card: HTMLElement,\n arrival: HTMLElement,\n initialExtraHeight: number,\n expanded: boolean,\n ): Array<AnimationHandle> {\n const bottom = position().startsWith('bottom');\n const room = Number.parseFloat(getComputedStyle(host).maxHeight) || window.innerHeight;\n const scrolling = scrolls();\n const startEdge = scrolling ? host.scrollTop : host.offsetHeight + initialExtraHeight - room;\n const endEdge = scrolling ? host.scrollTop + host.clientHeight : room;\n const details = expanded ? card.querySelector('[data-toast-details]') : null;\n const landing = details ? Math.round(details.getBoundingClientRect().top - card.getBoundingClientRect().top) : 0;\n const target = card.offsetTop + landing;\n if (scrolling && (target < startEdge || target >= endEdge)) return [];\n\n let tail = bottom ? card.offsetTop : card.offsetTop + card.offsetHeight;\n for (const item of host.children) {\n if (!(item instanceof HTMLElement) || !item.dataset.toastId || item.hasAttribute('data-toast-exiting')) continue;\n tail = bottom ? Math.min(tail, item.offsetTop) : Math.max(tail, item.offsetTop + item.offsetHeight);\n }\n // A shrinking group still occupies its old height when the preview starts moving.\n const origin = bottom\n ? Math.max(startEdge, tail - settings.gap - arrival.offsetHeight)\n : Math.min(endEdge - arrival.offsetHeight, tail + settings.gap + initialExtraHeight);\n const distance = origin - target;\n if ((bottom ? -distance : distance) < 16) return [];\n\n const duration = settings.moveDuration * 2;\n return [\n animate(card, [{ zIndex: 2 }, { zIndex: 2 }], { duration }),\n animate(\n arrival,\n [\n { translate: `0 ${landing + distance}px`, scale: 1, opacity: 0.9, visibility: 'visible' },\n { translate: `0 ${landing + distance * 0.65}px`, scale: 1, opacity: 1, offset: 0.32, visibility: 'visible' },\n { translate: landing ? `0 ${landing}px` : 'none', scale: 0.94, opacity: 0, visibility: 'visible' },\n ],\n { duration, easing: 'ease-out' },\n ),\n ];\n }\n\n function animateHighlight(node: Element | null, peak: Keyframe, rest: Keyframe, delay = 0): AnimationHandle {\n const duration = settings.moveDuration;\n if (reducedMotion.value) return animate(node, [peak, peak], { duration: duration * 3 });\n return animate(\n node,\n [\n { ...rest, easing: 'ease-out' },\n { ...peak, offset: 0.065 },\n { ...peak, offset: 0.25, easing: 'ease-in-out' },\n rest,\n ],\n { duration: duration * 6, delay, easing: 'linear' },\n );\n }\n\n /** Measures a card before Vue patches it, then animates from that measure once the patch lands. */\n function captureToastChange(id: string, change: ToastChange): void {\n const host = stack.value;\n const node = Array.from(host?.children ?? []).find(\n (child): child is HTMLElement => child instanceof HTMLElement && child.dataset.toastId === id,\n );\n const surface = node?.firstElementChild;\n if (!host || !node || !(surface instanceof HTMLElement)) return;\n const firstHeight = surface.offsetHeight;\n const containedFocus = node.contains(document.activeElement);\n const keyboardFocus = containedFocus && isFocusVisible(document.activeElement);\n\n void nextTick(() => {\n if (stack.value !== host || !node.isConnected || node.hasAttribute('data-toast-exiting')) return;\n // A patch that removes the focused control hands focus to the card's disclosure, or to a keyboard user's card.\n if (containedFocus && document.activeElement === document.body) {\n const disclosure = node.querySelector<HTMLElement>('button[aria-controls]');\n (disclosure ?? (keyboardFocus ? node : null))?.focus({ preventScroll: true });\n }\n if (settings.moveDuration <= 0 || typeof surface.animate !== 'function') return;\n for (const animation of updateMotions.get(node) ?? []) animation.cancel();\n\n const duration = settings.moveDuration;\n const motionAllowed = !reducedMotion.value;\n const lastHeight = surface.offsetHeight;\n const animations: Array<AnimationHandle> = [];\n const incoming = change === ToastChange.Merge || change === ToastChange.Arrival;\n const arrival = incoming && motionAllowed ? node.querySelector<HTMLElement>('[data-toast-group-arrival]') : null;\n const flight = arrival\n ? animateGroupCard(host, node, arrival, Math.max(0, firstHeight - lastHeight), isExpanded(id))\n : [];\n animations.push(...flight);\n if (motionAllowed && Math.abs(firstHeight - lastHeight) >= 1) {\n animations.push(\n animate(\n surface,\n [\n { height: `${firstHeight}px`, overflow: 'clip' },\n { height: `${lastHeight}px`, overflow: 'clip' },\n ],\n { duration },\n ),\n );\n }\n if (motionAllowed && change === ToastChange.Merge) {\n animations.push(\n animate(\n node.querySelector('[data-toast-summary]'),\n [\n { translate: '0 3px', opacity: 0.55 },\n { translate: 'none', opacity: 1 },\n ],\n { duration },\n ),\n );\n }\n if (incoming) {\n animations.push(\n animateHighlight(\n node.querySelector('[data-toast-group-count-highlight]'),\n {\n color: 'var(--toast-count-peak, var(--color-popover-foreground))',\n textShadow: motionAllowed\n ? 'var(--toast-count-glow, 0 0 0.4em color-mix(in oklab, var(--color-primary) 75%, transparent))'\n : 'none',\n },\n { color: 'var(--toast-count-rest, var(--color-muted-foreground))', textShadow: 'none' },\n flight.length > 0 ? duration * 1.5 : 0,\n ),\n );\n } else if (change === ToastChange.Content) {\n animations.push(\n animateHighlight(node.querySelector('[data-toast-update-highlight]'), { opacity: 1 }, { opacity: 0 }),\n );\n }\n updateMotions.set(node, animations);\n void Promise.all(animations.map((animation) => animation.finished)).then(() => {\n if (updateMotions.get(node) === animations) updateMotions.delete(node);\n });\n });\n }\n\n // A group's count change merges or resizes it; a changed copy, severity or finished operation highlights it.\n watch(visible, (next, previous) => {\n if (previous.length === 0) return;\n const earlier = new Map(previous.map((card) => [card.id, card]));\n for (const card of next) {\n const prior = earlier.get(card.id);\n if (!prior || prior.nonce === card.nonce) continue;\n const before = prior.group?.count;\n const after = card.group?.count;\n if (before !== undefined && after !== undefined && before !== after) {\n captureToastChange(\n card.id,\n after < before ? ToastChange.Resize : before === 1 ? ToastChange.Merge : ToastChange.Arrival,\n );\n continue;\n }\n const oldCopy = copyOf(prior);\n const newCopy = copyOf(card);\n if (\n oldCopy.title !== newCopy.title ||\n oldCopy.description !== newCopy.description ||\n prior.severity !== card.severity ||\n (isRunning(prior) && !isRunning(card))\n ) {\n captureToastChange(card.id, ToastChange.Content);\n }\n }\n });\n\n watch([reducedMotion, position, () => settings.moveDuration, sources.groupMotion], stop);\n onScopeDispose(stop);\n\n return { captureToastChange };\n}\n"],"names":[],"mappings":";;;;AAWO,MAAM,cAAc;AAAA;AAAA,EAEzB,QAAQ;AAAA;AAAA,EAER,OAAO;AAAA;AAAA,EAEP,SAAS;AAAA;AAAA,EAET,SAAS;AACX;AA8BO,SAAS,oBAAoB,SAAkC,UAAoC;AACxG,QAAM,EAAE,OAAO,SAAS,UAAU,eAAe,SAAS,YAAY,WAAW;AACjF,QAAM,oCAAoB,IAAA;AAE1B,WAAS,OAAa;AACpB,eAAW,cAAc,cAAc,UAAU;AAC/C,iBAAW,aAAa,WAAY,WAAU,OAAA;AAAA,IAChD;AACA,kBAAc,MAAA;AAAA,EAChB;AAEA,WAAS,iBACP,MACA,MACA,SACA,oBACA,UACwB;AACxB,UAAM,SAAS,WAAW,WAAW,QAAQ;AAC7C,UAAM,OAAO,OAAO,WAAW,iBAAiB,IAAI,EAAE,SAAS,KAAK,OAAO;AAC3E,UAAM,YAAY,QAAA;AAClB,UAAM,YAAY,YAAY,KAAK,YAAY,KAAK,eAAe,qBAAqB;AACxF,UAAM,UAAU,YAAY,KAAK,YAAY,KAAK,eAAe;AACjE,UAAM,UAAU,WAAW,KAAK,cAAc,sBAAsB,IAAI;AACxE,UAAM,UAAU,UAAU,KAAK,MAAM,QAAQ,wBAAwB,MAAM,KAAK,wBAAwB,GAAG,IAAI;AAC/G,UAAM,SAAS,KAAK,YAAY;AAChC,QAAI,cAAc,SAAS,aAAa,UAAU,iBAAiB,CAAA;AAEnE,QAAI,OAAO,SAAS,KAAK,YAAY,KAAK,YAAY,KAAK;AAC3D,eAAW,QAAQ,KAAK,UAAU;AAChC,UAAI,EAAE,gBAAgB,gBAAg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ACH,CAAC;AAAA,EACH;AAGA,QAAM,SAAS,CAAC,MAAM,aAAa;AACjC,QAAI,SAAS,WAAW,EAAG;AAC3B,UAAM,UAAU,IAAI,IAAI,SAAS,IAAI,CAAC,SAAS,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC;AAC/D,eAAW,QAAQ,MAAM;AACvB,YAAM,QAAQ,QAAQ,IAAI,KAAK,EAAE;AACjC,UAAI,CAAC,SAAS,MAAM,UAAU,KAAK,MAAO;AAC1C,YAAM,SAAS,MAAM,OAAO;AAC5B,YAAM,QAAQ,KAAK,OAAO;AAC1B,UAAI,WAAW,UAAa,UAAU,UAAa,WAAW,OAAO;AACnE;AAAA,UACE,KAAK;AAAA,UACL,QAAQ,SAAS,YAAY,SAAS,WAAW,IAAI,YAAY,QAAQ,YAAY;AAAA,QAAA;AAEvF;AAAA,MACF;AACA,YAAM,UAAU,OAAO,KAAK;AAC5B,YAAM,UAAU,OAAO,IAAI;AAC3B,UACE,QAAQ,UAAU,QAAQ,SAC1B,QAAQ,gBAAgB,QAAQ,eAChC,MAAM,aAAa,KAAK,YACvB,UAAU,KAAK,KAAK,CAAC,UAAU,IAAI,GACpC;AACA,2BAAmB,KAAK,IAAI,YAAY,OAAO;AAAA,MACjD;AAAA,IACF;AAAA,EACF,CAAC;AAED,QAAM,CAAC,eAAe,UAAU,MAAM,SAAS,cAAc,QAAQ,WAAW,GAAG,IAAI;AACvF,iBAAe,IAAI;AAEnB,SAAO,EAAE,mBAAA;AACX;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ToastOptions } from './ToastOptions';
|
|
2
|
+
import { ToastPromiseOptions } from './ToastPromiseOptions';
|
|
3
|
+
/** Manages the imperative toast API, bound to the app-wide store. */
|
|
4
|
+
export declare function useToastHost(): {
|
|
5
|
+
toast: (opts: ToastOptions) => string;
|
|
6
|
+
update: (id: string, patch: Partial<ToastOptions>) => void;
|
|
7
|
+
promise: <T>(promise: Promise<T>, opts: ToastPromiseOptions<T>) => Promise<T>;
|
|
8
|
+
dismiss: (id: string) => void;
|
|
9
|
+
dismissAll: () => void;
|
|
10
|
+
};
|