@xto/core 1.2.0 → 1.2.1

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.
@@ -0,0 +1,248 @@
1
+ import { Ref, ComputedRef } from 'vue';
2
+ import { UseToggleReturn, UseVisibleReturn, UseDisabledReturn, UseLoadingReturn, UseFocusReturn } from '../types';
3
+ /**
4
+ * 布尔值切换 Hook
5
+ *
6
+ * @param defaultValue 默认值,默认为 false
7
+ * @returns 切换工具对象
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const { value, toggle, setTrue, setFalse } = useToggle()
12
+ *
13
+ * console.log(value.value) // false
14
+ * toggle() // 切换为 true
15
+ * setFalse() // 设置为 false
16
+ * setTrue() // 设置为 true
17
+ * ```
18
+ */
19
+ export declare function useToggle(defaultValue?: boolean): UseToggleReturn;
20
+ /**
21
+ * 双向绑定 Hook
22
+ * 用于实现 v-model 双向绑定
23
+ *
24
+ * @param props 组件 props
25
+ * @param emit emit 函数
26
+ * @param key 绑定的 prop 名称,默认为 'modelValue'
27
+ * @param defaultValue 默认值
28
+ * @returns 响应式计算属性
29
+ *
30
+ * @example
31
+ * ```vue
32
+ * <script setup>
33
+ * const props = defineProps<{ modelValue?: string }>()
34
+ * const emit = defineEmits<{ 'update:modelValue': [value: string] }>()
35
+ *
36
+ * const value = useModel(props, emit)
37
+ * </script>
38
+ *
39
+ * <template>
40
+ * <input v-model="value" />
41
+ * </template>
42
+ * ```
43
+ */
44
+ export declare function useModel<T>(props: Record<string, any>, emit: (event: string, value: any) => void, key?: string, defaultValue?: T): ComputedRef<T>;
45
+ /**
46
+ * 可见性控制 Hook
47
+ * 用于控制元素的显示/隐藏
48
+ *
49
+ * @param defaultVisible 默认可见状态,默认为 false
50
+ * @returns 可见性控制对象
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * const { visible, show, hide, toggle } = useVisible()
55
+ *
56
+ * show() // 显示
57
+ * hide() // 隐藏
58
+ * toggle() // 切换
59
+ * ```
60
+ */
61
+ export declare function useVisible(defaultVisible?: boolean): UseVisibleReturn;
62
+ /**
63
+ * 禁用状态控制 Hook
64
+ * 用于控制元素的禁用/启用状态
65
+ *
66
+ * @param defaultDisabled 默认禁用状态,默认为 false
67
+ * @returns 禁用控制对象
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * const { disabled, enable, disable } = useDisabled()
72
+ *
73
+ * disable() // 禁用
74
+ * enable() // 启用
75
+ * ```
76
+ */
77
+ export declare function useDisabled(defaultDisabled?: boolean): UseDisabledReturn;
78
+ /**
79
+ * 加载状态控制 Hook
80
+ * 用于控制加载状态
81
+ *
82
+ * @param defaultLoading 默认加载状态,默认为 false
83
+ * @returns 加载控制对象
84
+ *
85
+ * @example
86
+ * ```ts
87
+ * const { loading, setLoading, start, end } = useLoading()
88
+ *
89
+ * start() // 开始加载
90
+ * end() // 结束加载
91
+ * setLoading(true) // 设置加载状态
92
+ * ```
93
+ */
94
+ export declare function useLoading(defaultLoading?: boolean): UseLoadingReturn;
95
+ /**
96
+ * 点击外部检测 Hook
97
+ * 当点击目标元素外部时触发回调
98
+ *
99
+ * @param target 目标元素 Ref
100
+ * @param callback 点击外部时的回调函数
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * const dropdownRef = ref<HTMLElement>()
105
+ *
106
+ * useClickOutside(dropdownRef, () => {
107
+ * // 点击外部,关闭下拉菜单
108
+ * closeDropdown()
109
+ * })
110
+ * ```
111
+ */
112
+ export declare function useClickOutside(target: Ref<HTMLElement | undefined>, callback: () => void): void;
113
+ /**
114
+ * ESC 键检测 Hook
115
+ * 当按下 ESC 键时触发回调
116
+ *
117
+ * @param callback 按下 ESC 时的回调函数
118
+ *
119
+ * @example
120
+ * ```ts
121
+ * useEscape(() => {
122
+ * // 按下 ESC,关闭模态框
123
+ * closeModal()
124
+ * })
125
+ * ```
126
+ */
127
+ export declare function useEscape(callback: () => void): void;
128
+ /**
129
+ * 元素尺寸变化监听 Hook
130
+ * 当目标元素尺寸变化时触发回调
131
+ *
132
+ * @param target 目标元素 Ref
133
+ * @param callback 尺寸变化时的回调函数
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * const containerRef = ref<HTMLElement>()
138
+ *
139
+ * useResize(containerRef, (width, height) => {
140
+ * console.log('尺寸变化:', width, height)
141
+ * })
142
+ * ```
143
+ */
144
+ export declare function useResize(target: Ref<HTMLElement | undefined>, callback: (width: number, height: number) => void): void;
145
+ /**
146
+ * DOM 变化监听 Hook
147
+ * 当目标 DOM 发生变化时触发回调
148
+ *
149
+ * @param target 目标元素 Ref
150
+ * @param options MutationObserver 配置选项
151
+ * @param callback DOM 变化时的回调函数
152
+ *
153
+ * @example
154
+ * ```ts
155
+ * const containerRef = ref<HTMLElement>()
156
+ *
157
+ * useDOMObserver(
158
+ * containerRef,
159
+ * { childList: true },
160
+ * (mutations) => {
161
+ * console.log('DOM 变化:', mutations)
162
+ * }
163
+ * )
164
+ * ```
165
+ */
166
+ export declare function useDOMObserver(target: Ref<HTMLElement | undefined>, options: MutationObserverInit | undefined, callback: (mutations: MutationRecord[]) => void): void;
167
+ /**
168
+ * 滚动监听 Hook
169
+ * 当目标元素滚动时触发回调
170
+ *
171
+ * @param target 目标元素 Ref
172
+ * @param callback 滚动时的回调函数
173
+ *
174
+ * @example
175
+ * ```ts
176
+ * const containerRef = ref<HTMLElement>()
177
+ *
178
+ * useScroll(containerRef, (scrollTop, scrollLeft) => {
179
+ * console.log('滚动位置:', scrollTop, scrollLeft)
180
+ * })
181
+ * ```
182
+ */
183
+ export declare function useScroll(target: Ref<HTMLElement | undefined | Window>, callback: (scrollTop: number, scrollLeft: number) => void): void;
184
+ /**
185
+ * 焦点控制 Hook
186
+ * 监听元素的焦点状态
187
+ *
188
+ * @param target 目标元素 Ref
189
+ * @param callback 焦点变化时的回调函数(可选)
190
+ * @returns 焦点状态对象
191
+ *
192
+ * @example
193
+ * ```ts
194
+ * const inputRef = ref<HTMLElement>()
195
+ * const { focused } = useFocus(inputRef)
196
+ *
197
+ * watch(focused, (isFocused) => {
198
+ * console.log('焦点状态:', isFocused)
199
+ * })
200
+ * ```
201
+ */
202
+ export declare function useFocus(target: Ref<HTMLElement | undefined>, callback?: (focused: boolean) => void): UseFocusReturn;
203
+ /**
204
+ * 交叉观察器 Hook
205
+ * 监听元素是否进入视口
206
+ *
207
+ * @param target 目标元素 Ref
208
+ * @param callback 交叉状态变化时的回调函数
209
+ * @param options IntersectionObserver 配置选项
210
+ *
211
+ * @example
212
+ * ```ts
213
+ * const elementRef = ref<HTMLElement>()
214
+ *
215
+ * useIntersectionObserver(
216
+ * elementRef,
217
+ * (isIntersecting) => {
218
+ * if (isIntersecting) {
219
+ * console.log('元素进入视口')
220
+ * }
221
+ * },
222
+ * { threshold: 0.5 }
223
+ * )
224
+ * ```
225
+ */
226
+ export declare function useIntersectionObserver(target: Ref<HTMLElement | undefined>, callback: (isIntersecting: boolean) => void, options?: IntersectionObserverInit): void;
227
+ /**
228
+ * 延迟动作 Hook
229
+ * 延迟执行某个动作,可取消
230
+ *
231
+ * @param delay 延迟时间(毫秒)
232
+ * @returns 延迟控制对象
233
+ *
234
+ * @example
235
+ * ```ts
236
+ * const { execute, cancel } = useDelayedAction(300)
237
+ *
238
+ * execute(() => {
239
+ * console.log('延迟执行')
240
+ * })
241
+ *
242
+ * cancel() // 取消执行
243
+ * ```
244
+ */
245
+ export declare function useDelayedAction(delay?: number): {
246
+ execute: (callback: () => void) => void;
247
+ cancel: () => void;
248
+ };
package/es/index.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @xto/core
3
+ * XTO UI 核心模块
4
+ * 提供类型定义、工具函数、组合式函数、主题配置和国际化
5
+ */
6
+ export * from './types';
7
+ export * from './theme';
8
+ export * from './utils';
9
+ export * from './hooks';
10
+ export * from './locale';
11
+ export declare const version = "1.0.0";