@agile-plus/headless 0.0.0-stage → 0.1.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 +59 -2
- package/dist/index.cjs +2610 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +30 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +2631 -0
- package/dist/index.js.map +1 -0
- package/dist/types-2ROaIfZ9.d.cts +57 -0
- package/dist/types-2ROaIfZ9.d.ts +57 -0
- package/dist/types-C9nl8qeg.d.cts +100 -0
- package/dist/types-C9nl8qeg.d.ts +100 -0
- package/dist/types-DM4s_xZa.d.cts +128 -0
- package/dist/types-DM4s_xZa.d.ts +128 -0
- package/dist/useCheckbox/index.cjs +255 -0
- package/dist/useCheckbox/index.cjs.map +1 -0
- package/dist/useCheckbox/index.d.cts +145 -0
- package/dist/useCheckbox/index.d.ts +145 -0
- package/dist/useCheckbox/index.js +232 -0
- package/dist/useCheckbox/index.js.map +1 -0
- package/dist/useCheckboxGroup/index.cjs +100 -0
- package/dist/useCheckboxGroup/index.cjs.map +1 -0
- package/dist/useCheckboxGroup/index.d.cts +102 -0
- package/dist/useCheckboxGroup/index.d.ts +102 -0
- package/dist/useCheckboxGroup/index.js +73 -0
- package/dist/useCheckboxGroup/index.js.map +1 -0
- package/dist/useCollapsible/index.cjs +151 -0
- package/dist/useCollapsible/index.cjs.map +1 -0
- package/dist/useCollapsible/index.d.cts +106 -0
- package/dist/useCollapsible/index.d.ts +106 -0
- package/dist/useCollapsible/index.js +129 -0
- package/dist/useCollapsible/index.js.map +1 -0
- package/dist/useDialog/index.cjs +294 -0
- package/dist/useDialog/index.cjs.map +1 -0
- package/dist/useDialog/index.d.cts +105 -0
- package/dist/useDialog/index.d.ts +105 -0
- package/dist/useDialog/index.js +267 -0
- package/dist/useDialog/index.js.map +1 -0
- package/dist/useForm/index.cjs +123 -0
- package/dist/useForm/index.cjs.map +1 -0
- package/dist/useForm/index.d.cts +22 -0
- package/dist/useForm/index.d.ts +22 -0
- package/dist/useForm/index.js +96 -0
- package/dist/useForm/index.js.map +1 -0
- package/dist/useFormControl/index.cjs +162 -0
- package/dist/useFormControl/index.cjs.map +1 -0
- package/dist/useFormControl/index.d.cts +116 -0
- package/dist/useFormControl/index.d.ts +116 -0
- package/dist/useFormControl/index.js +143 -0
- package/dist/useFormControl/index.js.map +1 -0
- package/dist/useFormField/index.cjs +45 -0
- package/dist/useFormField/index.cjs.map +1 -0
- package/dist/useFormField/index.d.cts +22 -0
- package/dist/useFormField/index.d.ts +22 -0
- package/dist/useFormField/index.js +18 -0
- package/dist/useFormField/index.js.map +1 -0
- package/dist/useFormMessage/index.cjs +77 -0
- package/dist/useFormMessage/index.cjs.map +1 -0
- package/dist/useFormMessage/index.d.cts +80 -0
- package/dist/useFormMessage/index.d.ts +80 -0
- package/dist/useFormMessage/index.js +54 -0
- package/dist/useFormMessage/index.js.map +1 -0
- package/dist/usePresence/index.cjs +117 -0
- package/dist/usePresence/index.cjs.map +1 -0
- package/dist/usePresence/index.d.cts +52 -0
- package/dist/usePresence/index.d.ts +52 -0
- package/dist/usePresence/index.js +90 -0
- package/dist/usePresence/index.js.map +1 -0
- package/dist/useRadioGroup/index.cjs +197 -0
- package/dist/useRadioGroup/index.cjs.map +1 -0
- package/dist/useRadioGroup/index.d.cts +162 -0
- package/dist/useRadioGroup/index.d.ts +162 -0
- package/dist/useRadioGroup/index.js +170 -0
- package/dist/useRadioGroup/index.js.map +1 -0
- package/dist/useScrollArea/index.cjs +309 -0
- package/dist/useScrollArea/index.cjs.map +1 -0
- package/dist/useScrollArea/index.d.cts +127 -0
- package/dist/useScrollArea/index.d.ts +127 -0
- package/dist/useScrollArea/index.js +287 -0
- package/dist/useScrollArea/index.js.map +1 -0
- package/dist/useSlider/index.cjs +417 -0
- package/dist/useSlider/index.cjs.map +1 -0
- package/dist/useSlider/index.d.cts +215 -0
- package/dist/useSlider/index.d.ts +215 -0
- package/dist/useSlider/index.js +401 -0
- package/dist/useSlider/index.js.map +1 -0
- package/dist/useSwitch/index.cjs +264 -0
- package/dist/useSwitch/index.cjs.map +1 -0
- package/dist/useSwitch/index.d.cts +110 -0
- package/dist/useSwitch/index.d.ts +110 -0
- package/dist/useSwitch/index.js +237 -0
- package/dist/useSwitch/index.js.map +1 -0
- package/dist/useTabs/index.cjs +153 -0
- package/dist/useTabs/index.cjs.map +1 -0
- package/dist/useTabs/index.d.cts +84 -0
- package/dist/useTabs/index.d.ts +84 -0
- package/dist/useTabs/index.js +126 -0
- package/dist/useTabs/index.js.map +1 -0
- package/dist/useToast/index.cjs +375 -0
- package/dist/useToast/index.cjs.map +1 -0
- package/dist/useToast/index.d.cts +148 -0
- package/dist/useToast/index.d.ts +148 -0
- package/dist/useToast/index.js +358 -0
- package/dist/useToast/index.js.map +1 -0
- package/dist/useToastProvider/index.cjs +118 -0
- package/dist/useToastProvider/index.cjs.map +1 -0
- package/dist/useToastProvider/index.d.cts +25 -0
- package/dist/useToastProvider/index.d.ts +25 -0
- package/dist/useToastProvider/index.js +96 -0
- package/dist/useToastProvider/index.js.map +1 -0
- package/dist/useToastViewport/index.cjs +227 -0
- package/dist/useToastViewport/index.cjs.map +1 -0
- package/dist/useToastViewport/index.d.cts +130 -0
- package/dist/useToastViewport/index.d.ts +130 -0
- package/dist/useToastViewport/index.js +207 -0
- package/dist/useToastViewport/index.js.map +1 -0
- package/dist/useToggle/index.cjs +86 -0
- package/dist/useToggle/index.cjs.map +1 -0
- package/dist/useToggle/index.d.cts +66 -0
- package/dist/useToggle/index.d.ts +66 -0
- package/dist/useToggle/index.js +59 -0
- package/dist/useToggle/index.js.map +1 -0
- package/dist/useToggleGroup/index.cjs +227 -0
- package/dist/useToggleGroup/index.cjs.map +1 -0
- package/dist/useToggleGroup/index.d.cts +159 -0
- package/dist/useToggleGroup/index.d.ts +159 -0
- package/dist/useToggleGroup/index.js +207 -0
- package/dist/useToggleGroup/index.js.map +1 -0
- package/package.json +163 -3
- package/src/index.ts +37 -0
- package/src/useCheckbox/index.ts +3 -0
- package/src/useCheckbox/types.ts +150 -0
- package/src/useCheckbox/useCheckbox.ts +141 -0
- package/src/useCheckboxGroup/index.ts +3 -0
- package/src/useCheckboxGroup/types.ts +104 -0
- package/src/useCheckboxGroup/useCheckboxGroup.ts +79 -0
- package/src/useCollapsible/index.ts +3 -0
- package/src/useCollapsible/types.ts +103 -0
- package/src/useCollapsible/useCollapsible.ts +160 -0
- package/src/useDialog/index.ts +3 -0
- package/src/useDialog/types.ts +109 -0
- package/src/useDialog/useDialog.ts +181 -0
- package/src/useForm/index.ts +9 -0
- package/src/useForm/types.ts +149 -0
- package/src/useForm/useForm.ts +156 -0
- package/src/useFormControl/index.ts +3 -0
- package/src/useFormControl/types.ts +101 -0
- package/src/useFormControl/useFormControl.ts +181 -0
- package/src/useFormField/index.ts +3 -0
- package/src/useFormField/types.ts +65 -0
- package/src/useFormField/useFormField.ts +46 -0
- package/src/useFormMessage/index.ts +3 -0
- package/src/useFormMessage/types.ts +64 -0
- package/src/useFormMessage/useFormMessage.ts +116 -0
- package/src/usePresence/index.ts +3 -0
- package/src/usePresence/types.ts +38 -0
- package/src/usePresence/usePresence.ts +168 -0
- package/src/useRadioGroup/index.ts +8 -0
- package/src/useRadioGroup/types.ts +173 -0
- package/src/useRadioGroup/useRadioGroup.ts +204 -0
- package/src/useScrollArea/index.ts +3 -0
- package/src/useScrollArea/types.ts +141 -0
- package/src/useScrollArea/useScrollArea.ts +360 -0
- package/src/useSlider/index.ts +3 -0
- package/src/useSlider/types.ts +231 -0
- package/src/useSlider/useSlider.ts +486 -0
- package/src/useSwitch/index.ts +3 -0
- package/src/useSwitch/types.ts +109 -0
- package/src/useSwitch/useSwitch.ts +144 -0
- package/src/useTabs/index.ts +3 -0
- package/src/useTabs/types.ts +83 -0
- package/src/useTabs/useTabs.ts +196 -0
- package/src/useToast/index.ts +3 -0
- package/src/useToast/types.ts +167 -0
- package/src/useToast/useToast.ts +378 -0
- package/src/useToastProvider/index.ts +3 -0
- package/src/useToastProvider/types.ts +121 -0
- package/src/useToastProvider/useToastProvider.ts +115 -0
- package/src/useToastViewport/index.ts +3 -0
- package/src/useToastViewport/types.ts +131 -0
- package/src/useToastViewport/useToastViewport.ts +319 -0
- package/src/useToggle/index.ts +3 -0
- package/src/useToggle/types.ts +59 -0
- package/src/useToggle/useToggle.ts +57 -0
- package/src/useToggleGroup/index.ts +3 -0
- package/src/useToggleGroup/types.ts +171 -0
- package/src/useToggleGroup/useToggleGroup.ts +260 -0
- package/src/utils/env.ts +26 -0
- package/src/utils/useBubbleInput.ts +168 -0
- package/src/utils/useCollection.ts +92 -0
- package/src/utils/useControllable.ts +96 -0
- package/src/utils/useFocusTrap.ts +160 -0
- package/src/utils/useFormResetListener.ts +80 -0
- package/src/utils/usePointerDrag.ts +101 -0
- package/src/utils/useResizeObserver.ts +60 -0
- package/src/utils/useScrollLock.ts +95 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { ToastPoint, ToastType, ToastSwipePhase, ToastSwipeDirection } from '@agile-plus/primitives/toast';
|
|
2
|
+
import { a as UseToastProviderReturn } from '../types-C9nl8qeg.cjs';
|
|
3
|
+
import { MaybeRefOrGetter, ComputedRef, Ref } from 'vue';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 滑动手势回调的事件负载。
|
|
7
|
+
*
|
|
8
|
+
* Radix 用 CustomEvent 携带 detail,是因为它的默认行为(写 data-swipe 与 CSS 变量)
|
|
9
|
+
* 靠 composeEventHandlers 与自定义事件一起实现。本库把默认行为放进响应式状态,
|
|
10
|
+
* 对外只暴露语义化的负载,消费者不需要构造或取消 CustomEvent。
|
|
11
|
+
*/
|
|
12
|
+
interface ToastSwipeDetail {
|
|
13
|
+
/** 触发手势的原生指针事件 */
|
|
14
|
+
originalEvent: PointerEvent;
|
|
15
|
+
/** 钳制后的位移:只保留手势轴,且不朝反方向越界 */
|
|
16
|
+
delta: ToastPoint;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* useToast 的配置项。
|
|
20
|
+
*/
|
|
21
|
+
interface UseToastOptions {
|
|
22
|
+
/** Provider 上下文,由 UI 层注入后传入 */
|
|
23
|
+
provider: UseToastProviderReturn;
|
|
24
|
+
/**
|
|
25
|
+
* 受控打开状态,传入后进入受控模式。
|
|
26
|
+
*
|
|
27
|
+
* `undefined` 表示未受控,这是受控判定的依据,因此类型必须允许 undefined;
|
|
28
|
+
* 布尔 prop 在封装层会被 cast 成 false,导致误判为受控并立刻关闭通知。
|
|
29
|
+
*/
|
|
30
|
+
open?: MaybeRefOrGetter<boolean | undefined>;
|
|
31
|
+
/** 非受控模式下的初始打开状态,默认 true(通知一挂载就该出现) */
|
|
32
|
+
defaultOpen?: boolean;
|
|
33
|
+
/** 打开状态变化回调 */
|
|
34
|
+
onOpenChange?: (open: boolean) => void;
|
|
35
|
+
/**
|
|
36
|
+
* 本条通知的时长,覆盖 Provider 的默认值。
|
|
37
|
+
*
|
|
38
|
+
* 0、NaN、Infinity 表示不自动关闭。
|
|
39
|
+
*/
|
|
40
|
+
duration?: MaybeRefOrGetter<number | undefined>;
|
|
41
|
+
/**
|
|
42
|
+
* 通知敏感度,决定 announcer 的 aria-live,默认 `foreground`。
|
|
43
|
+
*
|
|
44
|
+
* `foreground` 用 assertive 立刻打断,`background` 用 polite 等待当前朗读结束。
|
|
45
|
+
*/
|
|
46
|
+
type?: MaybeRefOrGetter<ToastType | undefined>;
|
|
47
|
+
/** 强制保留在 DOM 中,用于外部接管动画,默认 false */
|
|
48
|
+
forceMount?: MaybeRefOrGetter<boolean | undefined>;
|
|
49
|
+
/**
|
|
50
|
+
* Escape 处理器;调用 `preventDefault()` 可阻止关闭。
|
|
51
|
+
*
|
|
52
|
+
* @param event 原生键盘事件。
|
|
53
|
+
*/
|
|
54
|
+
onEscapeKeyDown?: (event: KeyboardEvent) => void;
|
|
55
|
+
/** 自动计时被暂停时回调 */
|
|
56
|
+
onPause?: () => void;
|
|
57
|
+
/** 自动计时恢复时回调 */
|
|
58
|
+
onResume?: () => void;
|
|
59
|
+
/** 滑动开始(越过启动阈值)时回调 */
|
|
60
|
+
onSwipeStart?: (detail: ToastSwipeDetail) => void;
|
|
61
|
+
/** 滑动过程中回调 */
|
|
62
|
+
onSwipeMove?: (detail: ToastSwipeDetail) => void;
|
|
63
|
+
/** 滑动未达阈值而回弹时回调 */
|
|
64
|
+
onSwipeCancel?: (detail: ToastSwipeDetail) => void;
|
|
65
|
+
/** 滑动达到阈值、即将关闭时回调 */
|
|
66
|
+
onSwipeEnd?: (detail: ToastSwipeDetail) => void;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* useToast 的返回值。
|
|
70
|
+
*
|
|
71
|
+
* 契约:get*Props 只返回可 v-bind 的属性,事件处理器单独暴露。
|
|
72
|
+
*/
|
|
73
|
+
interface UseToastReturn {
|
|
74
|
+
/** 当前是否打开;关闭动画期间仍为 false,而 isPresent 保持 true */
|
|
75
|
+
isOpen: ComputedRef<boolean>;
|
|
76
|
+
/** 是否应当渲染在 DOM 中 */
|
|
77
|
+
isPresent: ComputedRef<boolean>;
|
|
78
|
+
/** 通知根元素 */
|
|
79
|
+
element: Ref<HTMLElement | null>;
|
|
80
|
+
/**
|
|
81
|
+
* 绑定根元素,传给模板 `:ref`。
|
|
82
|
+
*
|
|
83
|
+
* @param node 元素实例,卸载时为 null。
|
|
84
|
+
*/
|
|
85
|
+
bindElement(node: unknown): void;
|
|
86
|
+
/** 关闭通知,Action/Close 按钮走这里 */
|
|
87
|
+
close(): void;
|
|
88
|
+
/** 滑动手势阶段,无手势时为 null(此时不输出 data-swipe 属性) */
|
|
89
|
+
swipePhase: ComputedRef<ToastSwipePhase | null>;
|
|
90
|
+
/** 手势方向,始终跟随 Provider */
|
|
91
|
+
swipeDirection: ComputedRef<ToastSwipeDirection>;
|
|
92
|
+
/** 获取通知根元素属性:tabindex、data-* 与位移 CSS 变量、内联防误选手势样式 */
|
|
93
|
+
getRootProps(): Record<string, unknown>;
|
|
94
|
+
/** 是否渲染 announcer;朗读内容存活期结束后为 false */
|
|
95
|
+
isAnnounceVisible: ComputedRef<boolean>;
|
|
96
|
+
/** 需要播报的文本片段,未到渲染时机时为 null */
|
|
97
|
+
announceText: ComputedRef<string[] | null>;
|
|
98
|
+
/** announcer 的前缀标签 */
|
|
99
|
+
announceLabel: ComputedRef<string>;
|
|
100
|
+
/** announcer 的 Teleport 目标 */
|
|
101
|
+
announceTarget: ComputedRef<Element | DocumentFragment | 'body'>;
|
|
102
|
+
/** 获取 announcer 属性:role="status"、aria-live 与视觉隐藏样式 */
|
|
103
|
+
getAnnounceProps(): Record<string, unknown>;
|
|
104
|
+
/**
|
|
105
|
+
* 根元素键盘处理器,绑定到 @keydown。
|
|
106
|
+
*
|
|
107
|
+
* @param event 原生键盘事件。
|
|
108
|
+
*/
|
|
109
|
+
onRootKeydown(event: KeyboardEvent): void;
|
|
110
|
+
/**
|
|
111
|
+
* 根元素指针按下处理器,绑定到 @pointerdown。
|
|
112
|
+
*
|
|
113
|
+
* @param event 原生指针事件。
|
|
114
|
+
*/
|
|
115
|
+
onRootPointerdown(event: PointerEvent): void;
|
|
116
|
+
/**
|
|
117
|
+
* 根元素指针移动处理器,绑定到 @pointermove。
|
|
118
|
+
*
|
|
119
|
+
* @param event 原生指针事件。
|
|
120
|
+
*/
|
|
121
|
+
onRootPointermove(event: PointerEvent): void;
|
|
122
|
+
/**
|
|
123
|
+
* 根元素指针抬起处理器,绑定到 @pointerup。
|
|
124
|
+
*
|
|
125
|
+
* @param event 原生指针事件。
|
|
126
|
+
*/
|
|
127
|
+
onRootPointerup(event: PointerEvent): void;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* useToast 的单条通知逻辑。
|
|
132
|
+
*
|
|
133
|
+
* 三块状态各自独立,共同点只有「都挂在这条通知上」,分开写比塞进一个状态机更好读:
|
|
134
|
+
*
|
|
135
|
+
* 1. **计时**。时长可被 Provider 或本条覆盖,`Infinity`/0/NaN 表示常驻。暂停时扣减
|
|
136
|
+
* 已消耗时间、恢复时按剩余时间重开,所以计时快照与 setTimeout 句柄必须成对维护。
|
|
137
|
+
* 2. **手势**。位移钳制、启动阈值、方向判定与关闭阈值全部委托 primitives,这里只做
|
|
138
|
+
* 「事件 → 状态」的桥接;指针捕获挂在命中元素上,手指移出通知也能继续拖。
|
|
139
|
+
* 3. **announcer**。通知本体是 portal 进视口的,读屏需要一个独立的 `role="status"`
|
|
140
|
+
* 区域;文本要等下一帧才写入(否则 NVDA 读不到),并在存活期结束后移除,让同一条
|
|
141
|
+
* 通知再次出现时还能重新播报。
|
|
142
|
+
*
|
|
143
|
+
* @param options 通知配置,必须带上 Provider 上下文。
|
|
144
|
+
* @returns 渲染与交互所需的响应式状态、属性与处理器。
|
|
145
|
+
*/
|
|
146
|
+
declare function useToast(options: UseToastOptions): UseToastReturn;
|
|
147
|
+
|
|
148
|
+
export { type ToastSwipeDetail, type UseToastOptions, type UseToastReturn, useToast };
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { ToastPoint, ToastType, ToastSwipePhase, ToastSwipeDirection } from '@agile-plus/primitives/toast';
|
|
2
|
+
import { a as UseToastProviderReturn } from '../types-C9nl8qeg.js';
|
|
3
|
+
import { MaybeRefOrGetter, ComputedRef, Ref } from 'vue';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 滑动手势回调的事件负载。
|
|
7
|
+
*
|
|
8
|
+
* Radix 用 CustomEvent 携带 detail,是因为它的默认行为(写 data-swipe 与 CSS 变量)
|
|
9
|
+
* 靠 composeEventHandlers 与自定义事件一起实现。本库把默认行为放进响应式状态,
|
|
10
|
+
* 对外只暴露语义化的负载,消费者不需要构造或取消 CustomEvent。
|
|
11
|
+
*/
|
|
12
|
+
interface ToastSwipeDetail {
|
|
13
|
+
/** 触发手势的原生指针事件 */
|
|
14
|
+
originalEvent: PointerEvent;
|
|
15
|
+
/** 钳制后的位移:只保留手势轴,且不朝反方向越界 */
|
|
16
|
+
delta: ToastPoint;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* useToast 的配置项。
|
|
20
|
+
*/
|
|
21
|
+
interface UseToastOptions {
|
|
22
|
+
/** Provider 上下文,由 UI 层注入后传入 */
|
|
23
|
+
provider: UseToastProviderReturn;
|
|
24
|
+
/**
|
|
25
|
+
* 受控打开状态,传入后进入受控模式。
|
|
26
|
+
*
|
|
27
|
+
* `undefined` 表示未受控,这是受控判定的依据,因此类型必须允许 undefined;
|
|
28
|
+
* 布尔 prop 在封装层会被 cast 成 false,导致误判为受控并立刻关闭通知。
|
|
29
|
+
*/
|
|
30
|
+
open?: MaybeRefOrGetter<boolean | undefined>;
|
|
31
|
+
/** 非受控模式下的初始打开状态,默认 true(通知一挂载就该出现) */
|
|
32
|
+
defaultOpen?: boolean;
|
|
33
|
+
/** 打开状态变化回调 */
|
|
34
|
+
onOpenChange?: (open: boolean) => void;
|
|
35
|
+
/**
|
|
36
|
+
* 本条通知的时长,覆盖 Provider 的默认值。
|
|
37
|
+
*
|
|
38
|
+
* 0、NaN、Infinity 表示不自动关闭。
|
|
39
|
+
*/
|
|
40
|
+
duration?: MaybeRefOrGetter<number | undefined>;
|
|
41
|
+
/**
|
|
42
|
+
* 通知敏感度,决定 announcer 的 aria-live,默认 `foreground`。
|
|
43
|
+
*
|
|
44
|
+
* `foreground` 用 assertive 立刻打断,`background` 用 polite 等待当前朗读结束。
|
|
45
|
+
*/
|
|
46
|
+
type?: MaybeRefOrGetter<ToastType | undefined>;
|
|
47
|
+
/** 强制保留在 DOM 中,用于外部接管动画,默认 false */
|
|
48
|
+
forceMount?: MaybeRefOrGetter<boolean | undefined>;
|
|
49
|
+
/**
|
|
50
|
+
* Escape 处理器;调用 `preventDefault()` 可阻止关闭。
|
|
51
|
+
*
|
|
52
|
+
* @param event 原生键盘事件。
|
|
53
|
+
*/
|
|
54
|
+
onEscapeKeyDown?: (event: KeyboardEvent) => void;
|
|
55
|
+
/** 自动计时被暂停时回调 */
|
|
56
|
+
onPause?: () => void;
|
|
57
|
+
/** 自动计时恢复时回调 */
|
|
58
|
+
onResume?: () => void;
|
|
59
|
+
/** 滑动开始(越过启动阈值)时回调 */
|
|
60
|
+
onSwipeStart?: (detail: ToastSwipeDetail) => void;
|
|
61
|
+
/** 滑动过程中回调 */
|
|
62
|
+
onSwipeMove?: (detail: ToastSwipeDetail) => void;
|
|
63
|
+
/** 滑动未达阈值而回弹时回调 */
|
|
64
|
+
onSwipeCancel?: (detail: ToastSwipeDetail) => void;
|
|
65
|
+
/** 滑动达到阈值、即将关闭时回调 */
|
|
66
|
+
onSwipeEnd?: (detail: ToastSwipeDetail) => void;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* useToast 的返回值。
|
|
70
|
+
*
|
|
71
|
+
* 契约:get*Props 只返回可 v-bind 的属性,事件处理器单独暴露。
|
|
72
|
+
*/
|
|
73
|
+
interface UseToastReturn {
|
|
74
|
+
/** 当前是否打开;关闭动画期间仍为 false,而 isPresent 保持 true */
|
|
75
|
+
isOpen: ComputedRef<boolean>;
|
|
76
|
+
/** 是否应当渲染在 DOM 中 */
|
|
77
|
+
isPresent: ComputedRef<boolean>;
|
|
78
|
+
/** 通知根元素 */
|
|
79
|
+
element: Ref<HTMLElement | null>;
|
|
80
|
+
/**
|
|
81
|
+
* 绑定根元素,传给模板 `:ref`。
|
|
82
|
+
*
|
|
83
|
+
* @param node 元素实例,卸载时为 null。
|
|
84
|
+
*/
|
|
85
|
+
bindElement(node: unknown): void;
|
|
86
|
+
/** 关闭通知,Action/Close 按钮走这里 */
|
|
87
|
+
close(): void;
|
|
88
|
+
/** 滑动手势阶段,无手势时为 null(此时不输出 data-swipe 属性) */
|
|
89
|
+
swipePhase: ComputedRef<ToastSwipePhase | null>;
|
|
90
|
+
/** 手势方向,始终跟随 Provider */
|
|
91
|
+
swipeDirection: ComputedRef<ToastSwipeDirection>;
|
|
92
|
+
/** 获取通知根元素属性:tabindex、data-* 与位移 CSS 变量、内联防误选手势样式 */
|
|
93
|
+
getRootProps(): Record<string, unknown>;
|
|
94
|
+
/** 是否渲染 announcer;朗读内容存活期结束后为 false */
|
|
95
|
+
isAnnounceVisible: ComputedRef<boolean>;
|
|
96
|
+
/** 需要播报的文本片段,未到渲染时机时为 null */
|
|
97
|
+
announceText: ComputedRef<string[] | null>;
|
|
98
|
+
/** announcer 的前缀标签 */
|
|
99
|
+
announceLabel: ComputedRef<string>;
|
|
100
|
+
/** announcer 的 Teleport 目标 */
|
|
101
|
+
announceTarget: ComputedRef<Element | DocumentFragment | 'body'>;
|
|
102
|
+
/** 获取 announcer 属性:role="status"、aria-live 与视觉隐藏样式 */
|
|
103
|
+
getAnnounceProps(): Record<string, unknown>;
|
|
104
|
+
/**
|
|
105
|
+
* 根元素键盘处理器,绑定到 @keydown。
|
|
106
|
+
*
|
|
107
|
+
* @param event 原生键盘事件。
|
|
108
|
+
*/
|
|
109
|
+
onRootKeydown(event: KeyboardEvent): void;
|
|
110
|
+
/**
|
|
111
|
+
* 根元素指针按下处理器,绑定到 @pointerdown。
|
|
112
|
+
*
|
|
113
|
+
* @param event 原生指针事件。
|
|
114
|
+
*/
|
|
115
|
+
onRootPointerdown(event: PointerEvent): void;
|
|
116
|
+
/**
|
|
117
|
+
* 根元素指针移动处理器,绑定到 @pointermove。
|
|
118
|
+
*
|
|
119
|
+
* @param event 原生指针事件。
|
|
120
|
+
*/
|
|
121
|
+
onRootPointermove(event: PointerEvent): void;
|
|
122
|
+
/**
|
|
123
|
+
* 根元素指针抬起处理器,绑定到 @pointerup。
|
|
124
|
+
*
|
|
125
|
+
* @param event 原生指针事件。
|
|
126
|
+
*/
|
|
127
|
+
onRootPointerup(event: PointerEvent): void;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* useToast 的单条通知逻辑。
|
|
132
|
+
*
|
|
133
|
+
* 三块状态各自独立,共同点只有「都挂在这条通知上」,分开写比塞进一个状态机更好读:
|
|
134
|
+
*
|
|
135
|
+
* 1. **计时**。时长可被 Provider 或本条覆盖,`Infinity`/0/NaN 表示常驻。暂停时扣减
|
|
136
|
+
* 已消耗时间、恢复时按剩余时间重开,所以计时快照与 setTimeout 句柄必须成对维护。
|
|
137
|
+
* 2. **手势**。位移钳制、启动阈值、方向判定与关闭阈值全部委托 primitives,这里只做
|
|
138
|
+
* 「事件 → 状态」的桥接;指针捕获挂在命中元素上,手指移出通知也能继续拖。
|
|
139
|
+
* 3. **announcer**。通知本体是 portal 进视口的,读屏需要一个独立的 `role="status"`
|
|
140
|
+
* 区域;文本要等下一帧才写入(否则 NVDA 读不到),并在存活期结束后移除,让同一条
|
|
141
|
+
* 通知再次出现时还能重新播报。
|
|
142
|
+
*
|
|
143
|
+
* @param options 通知配置,必须带上 Provider 上下文。
|
|
144
|
+
* @returns 渲染与交互所需的响应式状态、属性与处理器。
|
|
145
|
+
*/
|
|
146
|
+
declare function useToast(options: UseToastOptions): UseToastReturn;
|
|
147
|
+
|
|
148
|
+
export { type ToastSwipeDetail, type UseToastOptions, type UseToastReturn, useToast };
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
// src/useToast/useToast.ts
|
|
2
|
+
import { computed as computed3, onMounted, onScopeDispose as onScopeDispose2, ref as ref2, toValue as toValue3, useId, watch as watch2 } from "vue";
|
|
3
|
+
import {
|
|
4
|
+
TOAST_ANNOUNCE_LIFETIME,
|
|
5
|
+
VISUALLY_HIDDEN_STYLE,
|
|
6
|
+
createToastTimerSnapshot,
|
|
7
|
+
getSwipeEndPhase,
|
|
8
|
+
getToastAnnounceTextContent,
|
|
9
|
+
isToastTimerDisabled,
|
|
10
|
+
pauseToastTimer,
|
|
11
|
+
resolveSwipeMove,
|
|
12
|
+
resumeToastTimer
|
|
13
|
+
} from "@agile-plus/primitives/toast";
|
|
14
|
+
|
|
15
|
+
// src/usePresence/usePresence.ts
|
|
16
|
+
import { computed, onScopeDispose, ref, toValue, watch } from "vue";
|
|
17
|
+
import { isPresencePresent, sendPresenceEvent } from "@agile-plus/primitives/presence";
|
|
18
|
+
function usePresence(options) {
|
|
19
|
+
const state = ref(toValue(options.present) ? "mounted" : "unmounted");
|
|
20
|
+
const element = ref(null);
|
|
21
|
+
const isPresent = computed(() => isPresencePresent(state.value));
|
|
22
|
+
let previousAnimationName = "none";
|
|
23
|
+
let fillModeTimer = 0;
|
|
24
|
+
function readStyles() {
|
|
25
|
+
if (!element.value) return null;
|
|
26
|
+
return element.value.ownerDocument.defaultView?.getComputedStyle(element.value) ?? null;
|
|
27
|
+
}
|
|
28
|
+
function readAnimationName() {
|
|
29
|
+
return readStyles()?.animationName || "none";
|
|
30
|
+
}
|
|
31
|
+
function send(event) {
|
|
32
|
+
const next = sendPresenceEvent(state.value, event);
|
|
33
|
+
if (next === state.value) return;
|
|
34
|
+
state.value = next;
|
|
35
|
+
previousAnimationName = next === "mounted" ? readAnimationName() : "none";
|
|
36
|
+
}
|
|
37
|
+
function handleAnimationStart(event) {
|
|
38
|
+
if (event.target !== element.value) return;
|
|
39
|
+
previousAnimationName = readAnimationName();
|
|
40
|
+
}
|
|
41
|
+
function handleAnimationFinished(event) {
|
|
42
|
+
const node = element.value;
|
|
43
|
+
if (!node || event.target !== node) return;
|
|
44
|
+
const currentAnimationName = readAnimationName();
|
|
45
|
+
if (!currentAnimationName.includes(event.animationName)) return;
|
|
46
|
+
send("ANIMATION_END");
|
|
47
|
+
if (toValue(options.present)) return;
|
|
48
|
+
const previousFillMode = node.style.animationFillMode;
|
|
49
|
+
node.style.animationFillMode = "forwards";
|
|
50
|
+
fillModeTimer = window.setTimeout(() => {
|
|
51
|
+
if (node.style.animationFillMode === "forwards") {
|
|
52
|
+
node.style.animationFillMode = previousFillMode;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function setElement(node) {
|
|
57
|
+
element.value = node instanceof HTMLElement ? node : null;
|
|
58
|
+
}
|
|
59
|
+
watch(element, (node, previousNode) => {
|
|
60
|
+
window.clearTimeout(fillModeTimer);
|
|
61
|
+
previousNode?.removeEventListener("animationstart", handleAnimationStart);
|
|
62
|
+
previousNode?.removeEventListener("animationcancel", handleAnimationFinished);
|
|
63
|
+
previousNode?.removeEventListener("animationend", handleAnimationFinished);
|
|
64
|
+
if (!node) {
|
|
65
|
+
send("ANIMATION_END");
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (state.value === "mounted") previousAnimationName = readAnimationName();
|
|
69
|
+
node.addEventListener("animationstart", handleAnimationStart);
|
|
70
|
+
node.addEventListener("animationcancel", handleAnimationFinished);
|
|
71
|
+
node.addEventListener("animationend", handleAnimationFinished);
|
|
72
|
+
});
|
|
73
|
+
watch(
|
|
74
|
+
() => toValue(options.present),
|
|
75
|
+
(present, wasPresent) => {
|
|
76
|
+
if (present) {
|
|
77
|
+
send("MOUNT");
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const currentAnimationName = readAnimationName();
|
|
81
|
+
const hasExitAnimation = currentAnimationName !== "none" && readStyles()?.display !== "none";
|
|
82
|
+
const isAnimating = previousAnimationName !== currentAnimationName;
|
|
83
|
+
if (!wasPresent || !hasExitAnimation || !isAnimating) {
|
|
84
|
+
send("UNMOUNT");
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
send("ANIMATION_OUT");
|
|
88
|
+
},
|
|
89
|
+
{ flush: "post", immediate: true }
|
|
90
|
+
);
|
|
91
|
+
onScopeDispose(() => {
|
|
92
|
+
window.clearTimeout(fillModeTimer);
|
|
93
|
+
const node = element.value;
|
|
94
|
+
if (!node) return;
|
|
95
|
+
node.removeEventListener("animationstart", handleAnimationStart);
|
|
96
|
+
node.removeEventListener("animationcancel", handleAnimationFinished);
|
|
97
|
+
node.removeEventListener("animationend", handleAnimationFinished);
|
|
98
|
+
});
|
|
99
|
+
return { isPresent, element, setElement };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// src/utils/env.ts
|
|
103
|
+
var isBrowser = typeof window !== "undefined" && typeof document !== "undefined";
|
|
104
|
+
|
|
105
|
+
// src/utils/useControllable.ts
|
|
106
|
+
import { computed as computed2, shallowRef, toValue as toValue2 } from "vue";
|
|
107
|
+
function useControllable(options) {
|
|
108
|
+
const controlled = computed2(() => toValue2(options.value));
|
|
109
|
+
const isControlled = computed2(() => controlled.value !== void 0);
|
|
110
|
+
const internal = shallowRef(options.defaultValue);
|
|
111
|
+
const value = computed2(() => {
|
|
112
|
+
const current = controlled.value;
|
|
113
|
+
return current === void 0 ? internal.value : current;
|
|
114
|
+
});
|
|
115
|
+
function set(next) {
|
|
116
|
+
if (!isControlled.value) internal.value = next;
|
|
117
|
+
options.onChange?.(next);
|
|
118
|
+
}
|
|
119
|
+
function replace(next) {
|
|
120
|
+
if (isControlled.value) return;
|
|
121
|
+
internal.value = next;
|
|
122
|
+
}
|
|
123
|
+
return { value, isControlled, set, replace };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// src/useToast/useToast.ts
|
|
127
|
+
var SWIPE_VARS = {
|
|
128
|
+
moveX: "--y-toast-swipe-move-x",
|
|
129
|
+
moveY: "--y-toast-swipe-move-y",
|
|
130
|
+
endX: "--y-toast-swipe-end-x",
|
|
131
|
+
endY: "--y-toast-swipe-end-y"
|
|
132
|
+
};
|
|
133
|
+
function useToast(options) {
|
|
134
|
+
const { provider } = options;
|
|
135
|
+
const id = useId();
|
|
136
|
+
const state = useControllable({
|
|
137
|
+
value: () => toValue3(options.open),
|
|
138
|
+
defaultValue: options.defaultOpen ?? true,
|
|
139
|
+
onChange: (value) => options.onOpenChange?.(value)
|
|
140
|
+
});
|
|
141
|
+
const isOpen = state.value;
|
|
142
|
+
const duration = computed3(() => toValue3(options.duration) ?? provider.duration.value);
|
|
143
|
+
const presence = usePresence({
|
|
144
|
+
present: () => Boolean(toValue3(options.forceMount)) || isOpen.value
|
|
145
|
+
});
|
|
146
|
+
const swipePhase = ref2(null);
|
|
147
|
+
const swipeMove = ref2(null);
|
|
148
|
+
const swipeEnd = ref2(null);
|
|
149
|
+
let pointerStart = null;
|
|
150
|
+
let gestureDelta = null;
|
|
151
|
+
let timerId = 0;
|
|
152
|
+
let snapshot = createToastTimerSnapshot(duration.value, isBrowser ? Date.now() : 0);
|
|
153
|
+
function setOpen(value) {
|
|
154
|
+
state.set(value);
|
|
155
|
+
}
|
|
156
|
+
function close() {
|
|
157
|
+
setOpen(false);
|
|
158
|
+
}
|
|
159
|
+
function handleClose() {
|
|
160
|
+
const isFocusInside = presence.element.value?.contains(document.activeElement);
|
|
161
|
+
if (isFocusInside) provider.viewport.value?.focus();
|
|
162
|
+
close();
|
|
163
|
+
}
|
|
164
|
+
function startTimer(delay) {
|
|
165
|
+
if (isToastTimerDisabled(delay)) return;
|
|
166
|
+
window.clearTimeout(timerId);
|
|
167
|
+
snapshot = createToastTimerSnapshot(delay, Date.now());
|
|
168
|
+
timerId = window.setTimeout(handleClose, delay);
|
|
169
|
+
}
|
|
170
|
+
function pauseTimer() {
|
|
171
|
+
snapshot = pauseToastTimer(snapshot, Date.now());
|
|
172
|
+
window.clearTimeout(timerId);
|
|
173
|
+
options.onPause?.();
|
|
174
|
+
}
|
|
175
|
+
function resumeTimer() {
|
|
176
|
+
snapshot = resumeToastTimer(snapshot, Date.now());
|
|
177
|
+
startTimer(snapshot.remaining);
|
|
178
|
+
options.onResume?.();
|
|
179
|
+
}
|
|
180
|
+
const unsubscribeClosing = provider.subscribeClosing((paused) => {
|
|
181
|
+
if (!isOpen.value) return;
|
|
182
|
+
if (paused) pauseTimer();
|
|
183
|
+
else resumeTimer();
|
|
184
|
+
});
|
|
185
|
+
watch2(
|
|
186
|
+
[isOpen, duration],
|
|
187
|
+
([open, nextDuration]) => {
|
|
188
|
+
snapshot = createToastTimerSnapshot(nextDuration, Date.now());
|
|
189
|
+
if (!isBrowser) return;
|
|
190
|
+
if (open && !provider.isClosePaused.value) startTimer(nextDuration);
|
|
191
|
+
else window.clearTimeout(timerId);
|
|
192
|
+
},
|
|
193
|
+
{ immediate: true }
|
|
194
|
+
);
|
|
195
|
+
let unregister = null;
|
|
196
|
+
watch2(
|
|
197
|
+
presence.isPresent,
|
|
198
|
+
(present) => {
|
|
199
|
+
if (present) unregister = provider.registerToast({ id, element: presence.element, close });
|
|
200
|
+
else {
|
|
201
|
+
unregister?.();
|
|
202
|
+
unregister = null;
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
{ immediate: true }
|
|
206
|
+
);
|
|
207
|
+
const announcePhase = ref2("pending");
|
|
208
|
+
let nextFrameId = 0;
|
|
209
|
+
let lifetimeId = 0;
|
|
210
|
+
onMounted(() => {
|
|
211
|
+
if (!isBrowser) return;
|
|
212
|
+
nextFrameId = window.requestAnimationFrame(() => {
|
|
213
|
+
nextFrameId = window.requestAnimationFrame(() => {
|
|
214
|
+
announcePhase.value = "ready";
|
|
215
|
+
lifetimeId = window.setTimeout(() => {
|
|
216
|
+
announcePhase.value = "expired";
|
|
217
|
+
}, TOAST_ANNOUNCE_LIFETIME);
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
const announceText = computed3(() => {
|
|
222
|
+
if (announcePhase.value !== "ready" || !presence.element.value) return null;
|
|
223
|
+
return getToastAnnounceTextContent(presence.element.value);
|
|
224
|
+
});
|
|
225
|
+
const ariaLive = computed3(
|
|
226
|
+
() => (toValue3(options.type) ?? "foreground") === "foreground" ? "assertive" : "polite"
|
|
227
|
+
);
|
|
228
|
+
function emitSwipe(phase, detail) {
|
|
229
|
+
swipePhase.value = phase;
|
|
230
|
+
if (phase === "start") {
|
|
231
|
+
options.onSwipeStart?.(detail);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
if (phase === "move") options.onSwipeMove?.(detail);
|
|
235
|
+
if (phase === "cancel") options.onSwipeCancel?.(detail);
|
|
236
|
+
if (phase === "end") options.onSwipeEnd?.(detail);
|
|
237
|
+
}
|
|
238
|
+
function onRootKeydown(event) {
|
|
239
|
+
if (event.key !== "Escape") return;
|
|
240
|
+
options.onEscapeKeyDown?.(event);
|
|
241
|
+
if (!event.defaultPrevented) close();
|
|
242
|
+
}
|
|
243
|
+
function onRootPointerdown(event) {
|
|
244
|
+
if (event.button !== 0) return;
|
|
245
|
+
pointerStart = { x: event.clientX, y: event.clientY };
|
|
246
|
+
}
|
|
247
|
+
function onRootPointermove(event) {
|
|
248
|
+
if (!pointerStart) return;
|
|
249
|
+
const result = resolveSwipeMove({
|
|
250
|
+
delta: { x: event.clientX - pointerStart.x, y: event.clientY - pointerStart.y },
|
|
251
|
+
direction: provider.swipeDirection.value,
|
|
252
|
+
pointerType: event.pointerType,
|
|
253
|
+
started: gestureDelta !== null
|
|
254
|
+
});
|
|
255
|
+
if (result.phase === "idle") return;
|
|
256
|
+
if (result.phase === "reset") {
|
|
257
|
+
pointerStart = null;
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
const detail = { originalEvent: event, delta: result.clamped };
|
|
261
|
+
gestureDelta = result.clamped;
|
|
262
|
+
if (result.phase === "start") {
|
|
263
|
+
emitSwipe("start", detail);
|
|
264
|
+
if (event.target instanceof HTMLElement) event.target.setPointerCapture(event.pointerId);
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
swipeMove.value = result.clamped;
|
|
268
|
+
emitSwipe("move", detail);
|
|
269
|
+
}
|
|
270
|
+
function onRootPointerup(event) {
|
|
271
|
+
const delta = gestureDelta;
|
|
272
|
+
const target = event.target instanceof HTMLElement ? event.target : null;
|
|
273
|
+
if (target?.hasPointerCapture(event.pointerId)) target.releasePointerCapture(event.pointerId);
|
|
274
|
+
gestureDelta = null;
|
|
275
|
+
pointerStart = null;
|
|
276
|
+
if (!delta) return;
|
|
277
|
+
const detail = { originalEvent: event, delta };
|
|
278
|
+
const phase = getSwipeEndPhase(
|
|
279
|
+
delta,
|
|
280
|
+
provider.swipeDirection.value,
|
|
281
|
+
provider.swipeThreshold.value
|
|
282
|
+
);
|
|
283
|
+
if (phase === "end") {
|
|
284
|
+
swipeMove.value = null;
|
|
285
|
+
swipeEnd.value = delta;
|
|
286
|
+
emitSwipe("end", detail);
|
|
287
|
+
close();
|
|
288
|
+
} else {
|
|
289
|
+
swipeMove.value = null;
|
|
290
|
+
swipeEnd.value = null;
|
|
291
|
+
emitSwipe("cancel", detail);
|
|
292
|
+
}
|
|
293
|
+
if (event.currentTarget instanceof HTMLElement) {
|
|
294
|
+
event.currentTarget.addEventListener("click", (clickEvent) => clickEvent.preventDefault(), {
|
|
295
|
+
once: true
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
function getRootProps() {
|
|
300
|
+
return {
|
|
301
|
+
tabindex: 0,
|
|
302
|
+
"data-state": isOpen.value ? "open" : "closed",
|
|
303
|
+
"data-swipe-direction": provider.swipeDirection.value,
|
|
304
|
+
...swipePhase.value ? { "data-swipe": swipePhase.value } : {},
|
|
305
|
+
style: {
|
|
306
|
+
// 内联而不是写在样式里:滑动手势必须生效,而不依赖消费者有没有引入样式表。
|
|
307
|
+
userSelect: "none",
|
|
308
|
+
touchAction: "none",
|
|
309
|
+
...swipeMove.value ? { [SWIPE_VARS.moveX]: `${swipeMove.value.x}px` } : null,
|
|
310
|
+
...swipeMove.value ? { [SWIPE_VARS.moveY]: `${swipeMove.value.y}px` } : null,
|
|
311
|
+
...swipeEnd.value ? { [SWIPE_VARS.endX]: `${swipeEnd.value.x}px` } : null,
|
|
312
|
+
...swipeEnd.value ? { [SWIPE_VARS.endY]: `${swipeEnd.value.y}px` } : null
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
function getAnnounceProps() {
|
|
317
|
+
return {
|
|
318
|
+
// 永远用 status 而不是 alert:alert 在部分读屏里会造成逐字卡顿。
|
|
319
|
+
role: "status",
|
|
320
|
+
"aria-live": ariaLive.value,
|
|
321
|
+
style: VISUALLY_HIDDEN_STYLE
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
function bindElement(node) {
|
|
325
|
+
presence.setElement(node);
|
|
326
|
+
}
|
|
327
|
+
onScopeDispose2(() => {
|
|
328
|
+
unsubscribeClosing();
|
|
329
|
+
unregister?.();
|
|
330
|
+
if (!isBrowser) return;
|
|
331
|
+
window.clearTimeout(timerId);
|
|
332
|
+
window.clearTimeout(lifetimeId);
|
|
333
|
+
if (nextFrameId) window.cancelAnimationFrame(nextFrameId);
|
|
334
|
+
});
|
|
335
|
+
return {
|
|
336
|
+
isOpen,
|
|
337
|
+
isPresent: presence.isPresent,
|
|
338
|
+
element: presence.element,
|
|
339
|
+
bindElement,
|
|
340
|
+
close,
|
|
341
|
+
swipePhase: computed3(() => swipePhase.value),
|
|
342
|
+
swipeDirection: provider.swipeDirection,
|
|
343
|
+
getRootProps,
|
|
344
|
+
isAnnounceVisible: computed3(() => announcePhase.value !== "expired"),
|
|
345
|
+
announceText,
|
|
346
|
+
announceLabel: provider.label,
|
|
347
|
+
announceTarget: computed3(() => provider.announceContainer.value ?? "body"),
|
|
348
|
+
getAnnounceProps,
|
|
349
|
+
onRootKeydown,
|
|
350
|
+
onRootPointerdown,
|
|
351
|
+
onRootPointermove,
|
|
352
|
+
onRootPointerup
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
export {
|
|
356
|
+
useToast
|
|
357
|
+
};
|
|
358
|
+
//# sourceMappingURL=index.js.map
|