directix 1.0.0-beta.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -4,132 +4,132 @@ import { Plugin as Plugin_2 } from 'vue';
4
4
  import { VNode } from 'vue';
5
5
 
6
6
  /**
7
- * 添加清理函数到元素
7
+ * Add cleanup function to element
8
8
  */
9
9
  export declare function addCleanupVue2(el: Element, fn: () => void): void;
10
10
 
11
11
  /**
12
- * 添加清理函数到元素
12
+ * Add cleanup function to element
13
13
  */
14
14
  export declare function addCleanupVue3(el: Element, fn: () => void): void;
15
15
 
16
16
  /**
17
- * 指令绑定值类型
17
+ * Directive binding value type
18
18
  */
19
19
  export declare type ClickOutsideBinding = ClickOutsideHandler | ClickOutsideOptions;
20
20
 
21
21
  /**
22
- * 点击外部处理函数
22
+ * Click outside handler
23
23
  */
24
24
  export declare type ClickOutsideHandler = (event: MouseEvent | TouchEvent) => void;
25
25
 
26
26
  /**
27
- * 点击外部指令选项
27
+ * Click outside directive options
28
28
  */
29
29
  export declare interface ClickOutsideOptions {
30
30
  /**
31
- * 点击外部时的回调函数
31
+ * Callback when clicking outside
32
32
  * @required
33
33
  */
34
34
  handler: ClickOutsideHandler;
35
35
  /**
36
- * 排除的元素选择器或元素引用
36
+ * Excluded element selectors or element references
37
37
  */
38
38
  exclude?: (string | HTMLElement | (() => HTMLElement | null))[];
39
39
  /**
40
- * 是否使用捕获模式
40
+ * Whether to use capture mode
41
41
  * @default true
42
42
  */
43
43
  capture?: boolean;
44
44
  /**
45
- * 监听的事件类型
45
+ * Event types to listen for
46
46
  * @default ['click']
47
47
  */
48
48
  events?: ('click' | 'mousedown' | 'mouseup' | 'touchstart' | 'touchend')[];
49
49
  /**
50
- * 是否禁用
50
+ * Whether to disable
51
51
  * @default false
52
52
  */
53
53
  disabled?: boolean;
54
54
  /**
55
- * 停止传播
55
+ * Stop propagation
56
56
  * @default false
57
57
  */
58
58
  stop?: boolean;
59
59
  /**
60
- * 阻止默认行为
60
+ * Prevent default behavior
61
61
  * @default false
62
62
  */
63
63
  prevent?: boolean;
64
64
  }
65
65
 
66
66
  /**
67
- * 指令绑定值类型
67
+ * Directive binding value type
68
68
  */
69
69
  export declare type CopyBinding = string | CopyOptions;
70
70
 
71
71
  /**
72
- * 复制失败回调
72
+ * Copy error callback
73
73
  */
74
74
  export declare type CopyErrorCallback = (error: Error) => void;
75
75
 
76
76
  /**
77
- * 复制指令选项
77
+ * Copy directive options
78
78
  */
79
79
  export declare interface CopyOptions {
80
80
  /**
81
- * 要复制的文本
81
+ * Text to copy
82
82
  * @required
83
83
  */
84
84
  value: string;
85
85
  /**
86
- * 复制成功回调
86
+ * Callback on copy success
87
87
  */
88
88
  onSuccess?: CopySuccessCallback;
89
89
  /**
90
- * 复制失败回调
90
+ * Callback on copy error
91
91
  */
92
92
  onError?: CopyErrorCallback;
93
93
  /**
94
- * 复制按钮的提示文本
94
+ * Tooltip text for the copy button
95
95
  */
96
96
  title?: string;
97
97
  /**
98
- * 是否禁用
98
+ * Whether to disable
99
99
  * @default false
100
100
  */
101
101
  disabled?: boolean;
102
102
  }
103
103
 
104
104
  /**
105
- * 复制成功回调
105
+ * Copy success callback
106
106
  */
107
107
  export declare type CopySuccessCallback = (text: string) => void;
108
108
 
109
109
  /**
110
- * Vue 2 指令适配器
110
+ * Vue 2 directive adapter
111
111
  * @returns Vue 2 directive object with bind/inserted/update/unbind hooks
112
112
  */
113
113
  export declare function createVue2Directive<T, B extends Element>(hooks: DirectiveHooks<T, B>): Record<string, any>;
114
114
 
115
115
  /**
116
- * Vue 3 指令适配器
116
+ * Vue 3 directive adapter
117
117
  * @returns Vue 3 directive object with created/mounted/updated/unmounted hooks
118
118
  */
119
119
  export declare function createVue3Directive<T, B extends Element>(hooks: DirectiveHooks<T, B>): Record<string, any>;
120
120
 
121
121
  /**
122
- * 跨版本指令类型(兼容 Vue 2/3
122
+ * Cross-version directive type (compatible with Vue 2/3)
123
123
  */
124
124
  export declare type CrossVersionDirective = Directive | Vue2DirectiveHooks | Vue3DirectiveHooks;
125
125
 
126
126
  /**
127
- * 指令绑定值类型
127
+ * Directive binding value type
128
128
  */
129
129
  export declare type DebounceBinding<T extends (...args: any[]) => any = any> = T | DebounceOptions<T>;
130
130
 
131
131
  /**
132
- * 防抖函数类型
132
+ * Debounced function type
133
133
  */
134
134
  export declare interface DebouncedFunction<T extends (...args: any[]) => any> {
135
135
  (...args: Parameters<T>): void;
@@ -138,7 +138,7 @@ export declare interface DebouncedFunction<T extends (...args: any[]) => any> {
138
138
  }
139
139
 
140
140
  /**
141
- * 防抖函数
141
+ * Debounce function
142
142
  */
143
143
  export declare function debounceFn<T extends (...args: any[]) => any>(func: T, wait?: number, options?: {
144
144
  leading?: boolean;
@@ -149,49 +149,49 @@ export declare function debounceFn<T extends (...args: any[]) => any>(func: T, w
149
149
  };
150
150
 
151
151
  /**
152
- * 防抖指令选项
152
+ * Debounce directive options
153
153
  */
154
154
  export declare interface DebounceOptions<T extends (...args: any[]) => any = any> {
155
155
  /**
156
- * 要防抖的函数
156
+ * Function to debounce
157
157
  */
158
158
  handler: T;
159
159
  /**
160
- * 延迟时间(毫秒)
160
+ * Delay time in milliseconds
161
161
  * @default 300
162
162
  */
163
163
  wait?: number;
164
164
  /**
165
- * 是否在延迟开始前立即调用
165
+ * Whether to invoke immediately before delay starts
166
166
  * @default false
167
167
  */
168
168
  leading?: boolean;
169
169
  /**
170
- * 是否在延迟结束后调用
170
+ * Whether to invoke after delay ends
171
171
  * @default true
172
172
  */
173
173
  trailing?: boolean;
174
174
  }
175
175
 
176
176
  /**
177
- * 深拷贝
177
+ * Deep clone an object
178
178
  */
179
179
  export declare function deepClone<T>(obj: T): T;
180
180
 
181
181
  /**
182
- * 深合并
182
+ * Deep merge objects
183
183
  */
184
184
  export declare function deepMerge<T extends Record<string, any>>(target: T, ...sources: Partial<T>[]): T;
185
185
 
186
186
  /**
187
- * 定义一个跨版本兼容的指令
188
- * @param definition 指令定义
189
- * @returns Vue 指令对象
187
+ * Define a cross-version compatible directive
188
+ * @param definition The directive definition
189
+ * @returns Vue directive object
190
190
  */
191
191
  export declare function defineDirective<T = any, B extends Element = Element>(definition: DirectiveDefinition<T, B>): Directive;
192
192
 
193
193
  /**
194
- * 定义指令组
194
+ * Define a directive group
195
195
  */
196
196
  export declare function defineDirectiveGroup(name: string, directives: Record<string, any>): {
197
197
  name: string;
@@ -200,229 +200,229 @@ export declare function defineDirectiveGroup(name: string, directives: Record<st
200
200
  };
201
201
 
202
202
  /**
203
- * 统一的指令绑定对象
203
+ * Unified directive binding object
204
204
  */
205
205
  export declare interface DirectiveBinding<T = any> {
206
- /** 指令绑定的值 */
206
+ /** The value passed to the directive */
207
207
  value: T;
208
- /** 上一次绑定的值 */
208
+ /** The previous value */
209
209
  oldValue: T | null;
210
- /** 指令参数 (v-xxx:arg) */
210
+ /** The directive argument (v-xxx:arg) */
211
211
  arg?: string;
212
- /** 修饰符对象 (v-xxx.modifier) */
212
+ /** The modifiers object (v-xxx.modifier) */
213
213
  modifiers: Record<string, boolean>;
214
- /** 组件实例 */
214
+ /** The component instance */
215
215
  instance: ComponentPublicInstance | null;
216
216
  }
217
217
 
218
218
  /**
219
- * 指令定义接口
219
+ * Directive definition interface
220
220
  */
221
221
  export declare interface DirectiveDefinition<T = any, B extends Element = Element> extends DirectiveHooks<T, B> {
222
- /** 指令名称 */
222
+ /** The directive name */
223
223
  name: string;
224
- /** 指令版本 */
224
+ /** The Vue version compatibility */
225
225
  version?: '2' | '3' | 'both';
226
- /** 是否服务端渲染兼容 */
226
+ /** Whether SSR compatible */
227
227
  ssr?: boolean;
228
- /** 默认值 */
228
+ /** Default values */
229
229
  defaults?: Partial<T>;
230
230
  }
231
231
 
232
232
  /**
233
- * 统一的指令钩子函数
233
+ * Unified directive hooks
234
234
  */
235
235
  export declare interface DirectiveHooks<T = any, B extends Element = Element> {
236
236
  /**
237
- * 指令绑定到元素时调用
238
- * @param el 绑定的 DOM 元素
239
- * @param binding 绑定对象
240
- * @param vnode Vue 虚拟节点
237
+ * Called when the directive is bound to an element
238
+ * @param el The bound DOM element
239
+ * @param binding The binding object
240
+ * @param vnode The Vue virtual node
241
241
  */
242
242
  mounted?: (el: B, binding: DirectiveBinding<T>, vnode: VNode) => void;
243
243
  /**
244
- * 元素更新时调用
245
- * @param el 绑定的 DOM 元素
246
- * @param binding 新的绑定对象
247
- * @param vnode 新的虚拟节点
248
- * @param prevBinding 旧的绑定对象
249
- * @param prevVnode 旧的虚拟节点
244
+ * Called when the element is updated
245
+ * @param el The bound DOM element
246
+ * @param binding The new binding object
247
+ * @param vnode The new virtual node
248
+ * @param prevBinding The previous binding object
249
+ * @param prevVnode The previous virtual node
250
250
  */
251
251
  updated?: (el: B, binding: DirectiveBinding<T>, vnode: VNode, prevBinding: DirectiveBinding<T>, prevVnode: VNode) => void;
252
252
  /**
253
- * 指令卸载时调用
254
- * @param el 绑定的 DOM 元素
255
- * @param binding 绑定对象
256
- * @param vnode 虚拟节点
253
+ * Called when the directive is unbound
254
+ * @param el The bound DOM element
255
+ * @param binding The binding object
256
+ * @param vnode The virtual node
257
257
  */
258
258
  unmounted?: (el: B, binding: DirectiveBinding<T>, vnode: VNode) => void;
259
259
  }
260
260
 
261
261
  /**
262
- * 指令安装选项
262
+ * Directive installation options
263
263
  */
264
264
  export declare interface DirectiveInstallOptions {
265
- /** 注册的指令名称列表,不传则注册全部 */
265
+ /** List of directive names to register, registers all if not provided */
266
266
  directives?: string[];
267
- /** 是否注册全部指令 */
267
+ /** Whether to register all directives */
268
268
  all?: boolean;
269
- /** 全局配置 */
269
+ /** Global configuration */
270
270
  config?: Record<string, any>;
271
271
  }
272
272
 
273
273
  /**
274
- * Directix 插件
274
+ * Directix plugin
275
275
  */
276
276
  export declare const Directix: Plugin_2;
277
277
 
278
278
  /**
279
- * 指令绑定值类型
279
+ * Directive binding value type
280
280
  */
281
281
  export declare type FocusBinding = boolean | FocusOptions_2;
282
282
 
283
283
  /**
284
- * 焦点指令选项
284
+ * Focus directive options
285
285
  */
286
286
  declare interface FocusOptions_2 {
287
287
  /**
288
- * 是否自动聚焦
288
+ * Whether to auto focus
289
289
  * @default true
290
290
  */
291
291
  focus?: boolean;
292
292
  /**
293
- * 是否在每次更新时重新聚焦
293
+ * Whether to refocus when binding value changes
294
294
  * @default false
295
295
  */
296
296
  refocus?: boolean;
297
297
  /**
298
- * 聚焦时的回调
298
+ * Callback when focused
299
299
  */
300
300
  onFocus?: (el: HTMLElement) => void;
301
301
  /**
302
- * 失焦时的回调
302
+ * Callback when blurred
303
303
  */
304
304
  onBlur?: (el: HTMLElement) => void;
305
305
  }
306
306
  export { FocusOptions_2 as FocusOptions }
307
307
 
308
308
  /**
309
- * 生成唯一 ID
309
+ * Generate unique ID
310
310
  */
311
311
  export declare function generateId(prefix?: string): string;
312
312
 
313
313
  /**
314
- * 获取嵌套属性值
314
+ * Get nested property value by path
315
315
  */
316
316
  export declare function get<T = any>(obj: Record<string, any>, path: string, defaultValue?: T): T;
317
317
 
318
318
  /**
319
- * 获取当前 Vue 版本
319
+ * Get current Vue version
320
320
  */
321
321
  export declare function getVueVersion(): 2 | 3;
322
322
 
323
323
  /**
324
- * 检查是否为数组
324
+ * Check if value is an array
325
325
  */
326
326
  export declare function isArray(value: unknown): value is any[];
327
327
 
328
328
  /**
329
- * 检查是否为布尔值
329
+ * Check if value is a boolean
330
330
  */
331
331
  export declare function isBoolean(value: unknown): value is boolean;
332
332
 
333
333
  /**
334
- * 是否浏览器环境
334
+ * Check if browser environment
335
335
  */
336
336
  export declare const isBrowser: () => boolean;
337
337
 
338
338
  /**
339
- * 检查是否为空
339
+ * Check if value is empty
340
340
  */
341
341
  export declare function isEmpty(value: unknown): boolean;
342
342
 
343
343
  /**
344
- * 检查是否为函数
344
+ * Check if value is a function
345
345
  */
346
346
  export declare function isFunction(value: unknown): value is (...args: any[]) => any;
347
347
 
348
348
  /**
349
- * 检查是否为数字
349
+ * Check if value is a number
350
350
  */
351
351
  export declare function isNumber(value: unknown): value is number;
352
352
 
353
353
  /**
354
- * 检查是否为对象
354
+ * Check if value is an object
355
355
  */
356
356
  export declare function isObject(value: unknown): value is Record<string, any>;
357
357
 
358
358
  /**
359
- * 检查是否为 Promise
359
+ * Check if value is a Promise
360
360
  */
361
361
  export declare function isPromise<T = any>(value: unknown): value is Promise<T>;
362
362
 
363
363
  /**
364
- * 是否服务端渲染
364
+ * Check if server-side rendering
365
365
  */
366
366
  export declare const isSSR: () => boolean;
367
367
 
368
368
  /**
369
- * 检查是否为字符串
369
+ * Check if value is a string
370
370
  */
371
371
  export declare function isString(value: unknown): value is string;
372
372
 
373
373
  /**
374
- * 是否 Vue 2
374
+ * Check if Vue 2
375
375
  */
376
376
  export declare const isVue2: () => boolean;
377
377
 
378
378
  /**
379
- * 是否 Vue 3
379
+ * Check if Vue 3
380
380
  */
381
381
  export declare const isVue3: () => boolean;
382
382
 
383
383
  /**
384
- * 解析时间参数
385
- * 支持格式: "300" | "300ms" | "1s"
384
+ * Parse time argument
385
+ * Supports formats: "300" | "300ms" | "1s"
386
386
  */
387
387
  export declare function parseTime(arg?: string): number | null;
388
388
 
389
389
  /**
390
- * 设置嵌套属性值
390
+ * Set nested property value by path
391
391
  */
392
392
  export declare function set(obj: Record<string, any>, path: string, value: any): void;
393
393
 
394
394
  /**
395
- * 是否支持 Clipboard API
395
+ * Check if Clipboard API is supported
396
396
  */
397
397
  export declare const supportsClipboard: () => boolean;
398
398
 
399
399
  /**
400
- * 是否支持 IntersectionObserver
400
+ * Check if IntersectionObserver is supported
401
401
  */
402
402
  export declare const supportsIntersectionObserver: () => boolean;
403
403
 
404
404
  /**
405
- * 是否支持 MutationObserver
405
+ * Check if MutationObserver is supported
406
406
  */
407
407
  export declare const supportsMutationObserver: () => boolean;
408
408
 
409
409
  /**
410
- * 是否支持 Passive 事件监听
410
+ * Check if passive event listening is supported
411
411
  */
412
412
  export declare const supportsPassive: () => boolean;
413
413
 
414
414
  /**
415
- * 是否支持 ResizeObserver
415
+ * Check if ResizeObserver is supported
416
416
  */
417
417
  export declare const supportsResizeObserver: () => boolean;
418
418
 
419
419
  /**
420
- * 指令绑定值类型
420
+ * Directive binding value type
421
421
  */
422
422
  export declare type ThrottleBinding<T extends (...args: any[]) => any = any> = T | ThrottleOptions<T>;
423
423
 
424
424
  /**
425
- * 节流函数类型
425
+ * Throttled function type
426
426
  */
427
427
  export declare interface ThrottledFunction<T extends (...args: any[]) => any> {
428
428
  (...args: Parameters<T>): void;
@@ -430,7 +430,7 @@ export declare interface ThrottledFunction<T extends (...args: any[]) => any> {
430
430
  }
431
431
 
432
432
  /**
433
- * 节流函数
433
+ * Throttle function
434
434
  */
435
435
  export declare function throttleFn<T extends (...args: any[]) => any>(func: T, wait?: number, options?: {
436
436
  leading?: boolean;
@@ -440,38 +440,38 @@ export declare function throttleFn<T extends (...args: any[]) => any>(func: T, w
440
440
  };
441
441
 
442
442
  /**
443
- * 节流指令选项
443
+ * Throttle directive options
444
444
  */
445
445
  export declare interface ThrottleOptions<T extends (...args: any[]) => any = any> {
446
446
  /**
447
- * 要节流的函数
447
+ * Function to throttle
448
448
  */
449
449
  handler: T;
450
450
  /**
451
- * 延迟时间(毫秒)
451
+ * Delay time in milliseconds
452
452
  * @default 300
453
453
  */
454
454
  wait?: number;
455
455
  /**
456
- * 是否在延迟开始前立即调用
456
+ * Whether to invoke immediately before delay starts
457
457
  * @default true
458
458
  */
459
459
  leading?: boolean;
460
460
  /**
461
- * 是否在延迟结束后调用
461
+ * Whether to invoke after delay ends
462
462
  * @default true
463
463
  */
464
464
  trailing?: boolean;
465
465
  }
466
466
 
467
467
  /**
468
- * v-click-outside 指令
468
+ * v-click-outside directive
469
469
  *
470
470
  * @example
471
471
  * ```vue
472
472
  * <template>
473
473
  * <div v-click-outside="handleClickOutside">
474
- * 下拉菜单
474
+ * Dropdown menu
475
475
  * </div>
476
476
  * </template>
477
477
  * ```
@@ -481,12 +481,12 @@ export { vClickOutside as clickOutside }
481
481
  export { vClickOutside }
482
482
 
483
483
  /**
484
- * v-copy 指令
484
+ * v-copy directive
485
485
  *
486
486
  * @example
487
487
  * ```vue
488
488
  * <template>
489
- * <button v-copy="textToCopy">复制文本</button>
489
+ * <button v-copy="textToCopy">Copy Text</button>
490
490
  * </template>
491
491
  * ```
492
492
  */
@@ -495,7 +495,7 @@ export { vCopy as copy }
495
495
  export { vCopy }
496
496
 
497
497
  /**
498
- * v-debounce 指令
498
+ * v-debounce directive
499
499
  *
500
500
  * @example
501
501
  * ```vue
@@ -503,8 +503,8 @@ export { vCopy }
503
503
  * <input v-debounce="handleInput" />
504
504
  * <input v-debounce:500ms="handleInput" />
505
505
  * <input v-debounce="{ handler: handleInput, wait: 500 }" />
506
- * <div v-debounce.scroll="handleScroll">滚动防抖</div>
507
- * <div v-debounce:100.scroll="handleScroll">100ms 滚动防抖</div>
506
+ * <div v-debounce.scroll="handleScroll">Scroll Debounce</div>
507
+ * <div v-debounce:100.scroll="handleScroll">100ms Scroll Debounce</div>
508
508
  * </template>
509
509
  * ```
510
510
  */
@@ -513,7 +513,7 @@ export { vDebounce as debounce }
513
513
  export { vDebounce }
514
514
 
515
515
  /**
516
- * v-focus 指令
516
+ * v-focus directive
517
517
  *
518
518
  * @example
519
519
  * ```vue
@@ -528,15 +528,15 @@ export { vFocus as focus }
528
528
  export { vFocus }
529
529
 
530
530
  /**
531
- * v-throttle 指令
531
+ * v-throttle directive
532
532
  *
533
533
  * @example
534
534
  * ```vue
535
535
  * <template>
536
- * <button v-throttle="handleClick">节流按钮</button>
537
- * <button v-throttle:1s="handleClick">1秒节流</button>
538
- * <div v-throttle.scroll="handleScroll">滚动节流</div>
539
- * <div v-throttle:100.scroll="handleScroll">100ms 滚动节流</div>
536
+ * <button v-throttle="handleClick">Throttled Button</button>
537
+ * <button v-throttle:1s="handleClick">1s Throttled</button>
538
+ * <div v-throttle.scroll="handleScroll">Scroll Throttle</div>
539
+ * <div v-throttle:100.scroll="handleScroll">100ms Scroll Throttle</div>
540
540
  * </template>
541
541
  * ```
542
542
  */
@@ -545,7 +545,7 @@ export { vThrottle as throttle }
545
545
  export { vThrottle }
546
546
 
547
547
  /**
548
- * Vue 2 指令钩子
548
+ * Vue 2 directive hooks
549
549
  */
550
550
  export declare interface Vue2DirectiveHooks {
551
551
  bind?: (el: any, binding: any, vnode: any, oldVnode: any) => void;
@@ -556,7 +556,7 @@ export declare interface Vue2DirectiveHooks {
556
556
  }
557
557
 
558
558
  /**
559
- * Vue 3 指令钩子
559
+ * Vue 3 directive hooks
560
560
  */
561
561
  export declare interface Vue3DirectiveHooks {
562
562
  created?: (el: any, binding: any, vnode: any, prevVnode: any) => void;