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.cjs ADDED
@@ -0,0 +1,1095 @@
1
+ /*!
2
+ * directix v1.0.0
3
+ * A comprehensive, easy-to-use, and high-performance Vue custom directives library supporting both Vue 2 and Vue 3
4
+ * (c) 2021-present saqqdy <https://github.com/saqqdy>
5
+ * Released under the MIT License.
6
+ */
7
+ "use strict";
8
+ var __defProp = Object.defineProperty;
9
+ var __defProps = Object.defineProperties;
10
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
11
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
12
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
13
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
14
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
15
+ var __spreadValues = (a, b) => {
16
+ for (var prop in b || (b = {}))
17
+ if (__hasOwnProp.call(b, prop))
18
+ __defNormalProp(a, prop, b[prop]);
19
+ if (__getOwnPropSymbols)
20
+ for (var prop of __getOwnPropSymbols(b)) {
21
+ if (__propIsEnum.call(b, prop))
22
+ __defNormalProp(a, prop, b[prop]);
23
+ }
24
+ return a;
25
+ };
26
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
27
+ var __objRest = (source, exclude) => {
28
+ var target = {};
29
+ for (var prop in source)
30
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
31
+ target[prop] = source[prop];
32
+ if (source != null && __getOwnPropSymbols)
33
+ for (var prop of __getOwnPropSymbols(source)) {
34
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
35
+ target[prop] = source[prop];
36
+ }
37
+ return target;
38
+ };
39
+ var __async = (__this, __arguments, generator) => {
40
+ return new Promise((resolve, reject) => {
41
+ var fulfilled = (value) => {
42
+ try {
43
+ step(generator.next(value));
44
+ } catch (e) {
45
+ reject(e);
46
+ }
47
+ };
48
+ var rejected = (value) => {
49
+ try {
50
+ step(generator.throw(value));
51
+ } catch (e) {
52
+ reject(e);
53
+ }
54
+ };
55
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
56
+ step((generator = generator.apply(__this, __arguments)).next());
57
+ });
58
+ };
59
+ /*!
60
+ * directix v1.0.0
61
+ * A comprehensive, easy-to-use, and high-performance Vue custom directives library supporting both Vue 2 and Vue 3
62
+ * (c) 2021-present saqqdy <https://github.com/saqqdy>
63
+ * Released under the MIT License.
64
+ */
65
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
66
+ let _vueVersion = null;
67
+ function getVueVersion() {
68
+ var _a, _b;
69
+ if (_vueVersion !== null) return _vueVersion;
70
+ try {
71
+ const vue = require("vue");
72
+ if ((_a = vue == null ? void 0 : vue.version) == null ? void 0 : _a.startsWith("2")) {
73
+ _vueVersion = 2;
74
+ } else if ((_b = vue == null ? void 0 : vue.version) == null ? void 0 : _b.startsWith("3")) {
75
+ _vueVersion = 3;
76
+ }
77
+ } catch (e) {
78
+ }
79
+ if (_vueVersion === null) {
80
+ if (typeof window !== "undefined") {
81
+ console.warn(
82
+ "[Directix] Unable to detect Vue version, defaulting to Vue 3. Please ensure Vue is installed correctly."
83
+ );
84
+ }
85
+ _vueVersion = 3;
86
+ }
87
+ return _vueVersion;
88
+ }
89
+ const isVue2 = () => getVueVersion() === 2;
90
+ const isVue3 = () => getVueVersion() === 3;
91
+ const isBrowser = () => {
92
+ return typeof window !== "undefined" && typeof document !== "undefined";
93
+ };
94
+ const isSSR = () => !isBrowser();
95
+ const supportsPassive = () => {
96
+ if (!isBrowser()) return false;
97
+ let supports = false;
98
+ try {
99
+ const options = {
100
+ get passive() {
101
+ supports = true;
102
+ return false;
103
+ }
104
+ };
105
+ window.addEventListener("test", null, options);
106
+ window.removeEventListener("test", null, options);
107
+ } catch (e) {
108
+ supports = false;
109
+ }
110
+ return supports;
111
+ };
112
+ const supportsIntersectionObserver = () => {
113
+ return isBrowser() && "IntersectionObserver" in window;
114
+ };
115
+ const supportsResizeObserver = () => {
116
+ return isBrowser() && "ResizeObserver" in window;
117
+ };
118
+ const supportsClipboard = () => {
119
+ return isBrowser() && "clipboard" in navigator;
120
+ };
121
+ const supportsMutationObserver = () => {
122
+ return isBrowser() && "MutationObserver" in window;
123
+ };
124
+ function createVue2Directive(hooks) {
125
+ const directive = {
126
+ bind(el, binding, vnode) {
127
+ const state = {
128
+ value: binding.value,
129
+ vnode,
130
+ cleanup: []
131
+ };
132
+ el.__directix_state__ = state;
133
+ },
134
+ inserted(el, binding, vnode) {
135
+ if (hooks.mounted) {
136
+ hooks.mounted(el, normalizeBinding(binding), vnode);
137
+ }
138
+ },
139
+ update(el, binding, vnode, oldVnode) {
140
+ const state = el.__directix_state__;
141
+ if (hooks.updated) {
142
+ hooks.updated(
143
+ el,
144
+ normalizeBinding(binding),
145
+ vnode,
146
+ normalizeBinding(__spreadProps(__spreadValues({}, binding), { value: binding.oldValue })),
147
+ oldVnode
148
+ );
149
+ }
150
+ if (state) {
151
+ state.value = binding.value;
152
+ state.vnode = vnode;
153
+ }
154
+ },
155
+ componentUpdated(_el, _binding, _vnode, _oldVnode) {
156
+ },
157
+ unbind(el, binding, vnode) {
158
+ if (hooks.unmounted) {
159
+ hooks.unmounted(el, normalizeBinding(binding), vnode);
160
+ }
161
+ const state = el.__directix_state__;
162
+ if (state == null ? void 0 : state.cleanup) {
163
+ state.cleanup.forEach((fn) => fn());
164
+ }
165
+ delete el.__directix_state__;
166
+ }
167
+ };
168
+ return directive;
169
+ }
170
+ function normalizeBinding(binding) {
171
+ var _a;
172
+ return {
173
+ value: binding.value,
174
+ oldValue: (_a = binding.oldValue) != null ? _a : null,
175
+ arg: binding.arg,
176
+ modifiers: binding.modifiers || {},
177
+ instance: binding.instance || null
178
+ };
179
+ }
180
+ function addCleanup$1(el, fn) {
181
+ const state = el.__directix_state__;
182
+ if (state) {
183
+ state.cleanup.push(fn);
184
+ }
185
+ }
186
+ function createVue3Directive(hooks) {
187
+ const directive = {
188
+ created(el, binding, vnode) {
189
+ const state = {
190
+ value: binding.value,
191
+ vnode,
192
+ cleanup: []
193
+ };
194
+ el.__directix_state__ = state;
195
+ },
196
+ beforeMount(_el, _binding, _vnode) {
197
+ },
198
+ mounted(el, binding, vnode) {
199
+ if (hooks.mounted) {
200
+ hooks.mounted(el, normalizeBindingVue3(binding), vnode);
201
+ }
202
+ },
203
+ beforeUpdate(_el, _binding, _vnode, _prevVnode) {
204
+ },
205
+ updated(el, binding, vnode, prevVnode) {
206
+ const state = el.__directix_state__;
207
+ if (hooks.updated) {
208
+ hooks.updated(
209
+ el,
210
+ normalizeBindingVue3(binding),
211
+ vnode,
212
+ normalizeBindingVue3(__spreadProps(__spreadValues({}, binding), { value: binding.oldValue })),
213
+ prevVnode
214
+ );
215
+ }
216
+ if (state) {
217
+ state.value = binding.value;
218
+ state.vnode = vnode;
219
+ }
220
+ },
221
+ beforeUnmount(_el, _binding, _vnode) {
222
+ },
223
+ unmounted(el, binding, vnode) {
224
+ if (hooks.unmounted) {
225
+ hooks.unmounted(el, normalizeBindingVue3(binding), vnode);
226
+ }
227
+ const state = el.__directix_state__;
228
+ if (state == null ? void 0 : state.cleanup) {
229
+ state.cleanup.forEach((fn) => fn());
230
+ }
231
+ delete el.__directix_state__;
232
+ }
233
+ };
234
+ return directive;
235
+ }
236
+ function normalizeBindingVue3(binding) {
237
+ var _a;
238
+ return {
239
+ value: binding.value,
240
+ oldValue: (_a = binding.oldValue) != null ? _a : null,
241
+ arg: binding.arg,
242
+ modifiers: binding.modifiers || {},
243
+ instance: binding.instance
244
+ };
245
+ }
246
+ function addCleanup(el, fn) {
247
+ const state = el.__directix_state__;
248
+ if (state) {
249
+ state.cleanup.push(fn);
250
+ }
251
+ }
252
+ function defineDirective(definition) {
253
+ var _b;
254
+ const _a = definition, { name, version, ssr, defaults } = _a, hooks = __objRest(_a, ["name", "version", "ssr", "defaults"]);
255
+ if (isSSR() && !ssr) {
256
+ if (typeof process !== "undefined" && ((_b = process.env) == null ? void 0 : _b.NODE_ENV) !== "test") {
257
+ console.warn(
258
+ `[Directix] Directive "${name}" is not compatible with SSR. It will be a no-op on the server side.`
259
+ );
260
+ }
261
+ return createNoOpDirective();
262
+ }
263
+ const wrappedHooks = {
264
+ mounted: hooks.mounted ? (el, binding, vnode) => {
265
+ const mergedBinding = applyDefaults(binding, defaults);
266
+ hooks.mounted(el, mergedBinding, vnode);
267
+ } : void 0,
268
+ updated: hooks.updated ? (el, binding, vnode, prevBinding, prevVnode) => {
269
+ const mergedBinding = applyDefaults(binding, defaults);
270
+ hooks.updated(el, mergedBinding, vnode, prevBinding, prevVnode);
271
+ } : void 0,
272
+ unmounted: hooks.unmounted
273
+ };
274
+ if (isVue2()) {
275
+ return createVue2Directive(wrappedHooks);
276
+ }
277
+ return createVue3Directive(wrappedHooks);
278
+ }
279
+ function applyDefaults(binding, defaults) {
280
+ if (!defaults) return binding;
281
+ const value = typeof binding.value === "object" && binding.value !== null ? __spreadValues(__spreadValues({}, defaults), binding.value) : binding.value;
282
+ return __spreadProps(__spreadValues({}, binding), { value });
283
+ }
284
+ function createNoOpDirective() {
285
+ return {
286
+ mounted: () => {
287
+ },
288
+ updated: () => {
289
+ },
290
+ unmounted: () => {
291
+ }
292
+ };
293
+ }
294
+ function defineDirectiveGroup(name, directives) {
295
+ return {
296
+ name,
297
+ directives,
298
+ install(app, _options) {
299
+ Object.entries(directives).forEach(([directiveName, directive]) => {
300
+ const fullName = `${name}-${directiveName}`;
301
+ app.directive(fullName, directive);
302
+ });
303
+ }
304
+ };
305
+ }
306
+ function isElement(value) {
307
+ return value instanceof Element;
308
+ }
309
+ function getElement(target) {
310
+ if (!target) return null;
311
+ if (typeof target === "string") {
312
+ if (!isBrowser()) return null;
313
+ return document.querySelector(target);
314
+ }
315
+ return isElement(target) ? target : null;
316
+ }
317
+ function on(target, event, handler, options = false) {
318
+ if (!isBrowser()) return;
319
+ const opts = normalizeOptions$5(options);
320
+ target.addEventListener(event, handler, opts);
321
+ }
322
+ function off(target, event, handler, options = false) {
323
+ if (!isBrowser()) return;
324
+ const opts = normalizeOptions$5(options);
325
+ target.removeEventListener(event, handler, opts);
326
+ }
327
+ function normalizeOptions$5(options) {
328
+ if (typeof options === "boolean") {
329
+ return options;
330
+ }
331
+ const { capture = false, passive = false, once = false } = options;
332
+ if (supportsPassive()) {
333
+ return { capture, passive, once };
334
+ }
335
+ return capture;
336
+ }
337
+ function isString(value) {
338
+ return typeof value === "string";
339
+ }
340
+ function isNumber(value) {
341
+ return typeof value === "number" && !Number.isNaN(value);
342
+ }
343
+ function isBoolean(value) {
344
+ return typeof value === "boolean";
345
+ }
346
+ function isFunction(value) {
347
+ return typeof value === "function";
348
+ }
349
+ function isObject(value) {
350
+ return typeof value === "object" && value !== null;
351
+ }
352
+ function isArray(value) {
353
+ return Array.isArray(value);
354
+ }
355
+ function isEmpty(value) {
356
+ if (value === null || value === void 0) return true;
357
+ if (isString(value) || isArray(value)) return value.length === 0;
358
+ if (isObject(value)) return Object.keys(value).length === 0;
359
+ return false;
360
+ }
361
+ function isPromise(value) {
362
+ return isObject(value) && isFunction(value.then);
363
+ }
364
+ function deepClone(obj) {
365
+ if (obj === null || typeof obj !== "object") {
366
+ return obj;
367
+ }
368
+ if (Array.isArray(obj)) {
369
+ return obj.map((item) => deepClone(item));
370
+ }
371
+ const cloned = {};
372
+ for (const key in obj) {
373
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
374
+ cloned[key] = deepClone(obj[key]);
375
+ }
376
+ }
377
+ return cloned;
378
+ }
379
+ function deepMerge(target, ...sources) {
380
+ if (!sources.length) return target;
381
+ const source = sources.shift();
382
+ if (isObject(target) && isObject(source)) {
383
+ for (const key in source) {
384
+ if (isObject(source[key])) {
385
+ if (!target[key]) {
386
+ Object.assign(target, { [key]: {} });
387
+ }
388
+ deepMerge(
389
+ target[key],
390
+ source[key]
391
+ );
392
+ } else {
393
+ Object.assign(target, { [key]: source[key] });
394
+ }
395
+ }
396
+ }
397
+ return deepMerge(target, ...sources);
398
+ }
399
+ function get(obj, path, defaultValue) {
400
+ const keys = path.split(".");
401
+ let result = obj;
402
+ for (const key of keys) {
403
+ if (result === null || result === void 0) {
404
+ return defaultValue;
405
+ }
406
+ result = result[key];
407
+ }
408
+ return result === void 0 ? defaultValue : result;
409
+ }
410
+ function set(obj, path, value) {
411
+ const keys = path.split(".");
412
+ const lastKey = keys.pop();
413
+ let current = obj;
414
+ for (const key of keys) {
415
+ if (current[key] === void 0) {
416
+ current[key] = {};
417
+ }
418
+ current = current[key];
419
+ }
420
+ current[lastKey] = value;
421
+ }
422
+ function debounce(func, wait = 300, options = {}) {
423
+ let timerId = null, lastArgs = null, lastThis = null;
424
+ const { leading = false, trailing = true } = options;
425
+ const invokeFunc = () => {
426
+ if (lastArgs) {
427
+ func.apply(lastThis, lastArgs);
428
+ lastArgs = null;
429
+ lastThis = null;
430
+ }
431
+ };
432
+ const debounced = function(...args) {
433
+ lastArgs = args;
434
+ lastThis = this;
435
+ if (timerId) {
436
+ clearTimeout(timerId);
437
+ }
438
+ if (leading && !timerId) {
439
+ invokeFunc();
440
+ }
441
+ timerId = setTimeout(() => {
442
+ if (trailing) {
443
+ invokeFunc();
444
+ }
445
+ timerId = null;
446
+ }, wait);
447
+ };
448
+ debounced.cancel = () => {
449
+ if (timerId) {
450
+ clearTimeout(timerId);
451
+ timerId = null;
452
+ }
453
+ lastArgs = null;
454
+ lastThis = null;
455
+ };
456
+ debounced.flush = () => {
457
+ if (timerId) {
458
+ clearTimeout(timerId);
459
+ invokeFunc();
460
+ timerId = null;
461
+ }
462
+ };
463
+ return debounced;
464
+ }
465
+ function throttle(func, wait = 300, options = {}) {
466
+ let timerId = null, lastArgs = null, lastThis = null, lastCallTime = 0;
467
+ const { leading = true, trailing = true } = options;
468
+ const invokeFunc = () => {
469
+ if (lastArgs) {
470
+ func.apply(lastThis, lastArgs);
471
+ lastArgs = null;
472
+ lastThis = null;
473
+ }
474
+ };
475
+ const throttled = function(...args) {
476
+ const now = Date.now();
477
+ if (!lastCallTime && !leading) {
478
+ lastCallTime = now;
479
+ }
480
+ const remaining = wait - (now - lastCallTime);
481
+ lastArgs = args;
482
+ lastThis = this;
483
+ if (remaining <= 0 || remaining > wait) {
484
+ if (timerId) {
485
+ clearTimeout(timerId);
486
+ timerId = null;
487
+ }
488
+ lastCallTime = now;
489
+ invokeFunc();
490
+ } else if (!timerId && trailing) {
491
+ timerId = setTimeout(() => {
492
+ lastCallTime = leading ? Date.now() : 0;
493
+ timerId = null;
494
+ invokeFunc();
495
+ }, remaining);
496
+ }
497
+ };
498
+ throttled.cancel = () => {
499
+ if (timerId) {
500
+ clearTimeout(timerId);
501
+ timerId = null;
502
+ }
503
+ lastCallTime = 0;
504
+ lastArgs = null;
505
+ lastThis = null;
506
+ };
507
+ return throttled;
508
+ }
509
+ function parseTime(arg) {
510
+ if (!arg) return null;
511
+ if (arg.endsWith("ms")) {
512
+ return Number.parseInt(arg, 10);
513
+ }
514
+ if (arg.endsWith("s")) {
515
+ return Number.parseFloat(arg) * 1e3;
516
+ }
517
+ const num = Number.parseInt(arg, 10);
518
+ return Number.isNaN(num) ? null : num;
519
+ }
520
+ function generateId(prefix = "") {
521
+ return `${prefix}${Date.now().toString(36)}${Math.random().toString(36).slice(2, 9)}`;
522
+ }
523
+ const vClickOutside = defineDirective({
524
+ name: "click-outside",
525
+ ssr: false,
526
+ defaults: {
527
+ capture: true,
528
+ events: ["click"],
529
+ disabled: false,
530
+ stop: false,
531
+ prevent: false
532
+ },
533
+ mounted(el, binding) {
534
+ const options = normalizeOptions$4(binding.value);
535
+ if (options.disabled) return;
536
+ const state = {
537
+ options,
538
+ handlers: /* @__PURE__ */ new Map()
539
+ };
540
+ el.__clickOutside = state;
541
+ const createHandler = (_eventType) => {
542
+ return (event) => {
543
+ if (!isValidClick(el, event, options)) {
544
+ return;
545
+ }
546
+ if (options.stop) {
547
+ event.stopPropagation();
548
+ }
549
+ if (options.prevent) {
550
+ event.preventDefault();
551
+ }
552
+ options.handler(event);
553
+ };
554
+ };
555
+ options.events.forEach((eventType) => {
556
+ const handler = createHandler();
557
+ state.handlers.set(eventType, handler);
558
+ const listenerOptions = {
559
+ capture: options.capture,
560
+ passive: !options.prevent
561
+ };
562
+ on(document, eventType, handler, listenerOptions);
563
+ });
564
+ },
565
+ updated(el, binding) {
566
+ const state = el.__clickOutside;
567
+ if (!state) return;
568
+ const oldOptions = state.options;
569
+ const newOptions = normalizeOptions$4(binding.value);
570
+ if (oldOptions.disabled !== newOptions.disabled) {
571
+ if (newOptions.disabled) {
572
+ state.handlers.forEach((handler, eventType) => {
573
+ off(document, eventType, handler, { capture: oldOptions.capture });
574
+ });
575
+ state.handlers.clear();
576
+ } else {
577
+ const createHandler = (_eventType) => {
578
+ return (event) => {
579
+ if (!isValidClick(el, event, newOptions)) return;
580
+ if (newOptions.stop) event.stopPropagation();
581
+ if (newOptions.prevent) event.preventDefault();
582
+ newOptions.handler(event);
583
+ };
584
+ };
585
+ newOptions.events.forEach((eventType) => {
586
+ const handler = createHandler();
587
+ state.handlers.set(eventType, handler);
588
+ on(document, eventType, handler, {
589
+ capture: newOptions.capture,
590
+ passive: !newOptions.prevent
591
+ });
592
+ });
593
+ }
594
+ }
595
+ state.options = newOptions;
596
+ },
597
+ unmounted(el) {
598
+ const state = el.__clickOutside;
599
+ if (!state) return;
600
+ state.handlers.forEach((handler, eventType) => {
601
+ off(document, eventType, handler, { capture: state.options.capture });
602
+ });
603
+ delete el.__clickOutside;
604
+ }
605
+ });
606
+ function normalizeOptions$4(binding) {
607
+ var _a, _b, _c, _d, _e;
608
+ if (typeof binding === "function") {
609
+ return {
610
+ handler: binding,
611
+ capture: true,
612
+ events: ["click"],
613
+ disabled: false,
614
+ stop: false,
615
+ prevent: false
616
+ };
617
+ }
618
+ if (!binding) {
619
+ throw new Error("[Directix] v-click-outside: handler is required");
620
+ }
621
+ return __spreadValues({
622
+ capture: (_a = binding.capture) != null ? _a : true,
623
+ events: (_b = binding.events) != null ? _b : ["click"],
624
+ disabled: (_c = binding.disabled) != null ? _c : false,
625
+ stop: (_d = binding.stop) != null ? _d : false,
626
+ prevent: (_e = binding.prevent) != null ? _e : false
627
+ }, binding);
628
+ }
629
+ function isValidClick(el, event, options) {
630
+ var _a;
631
+ const target = event.target;
632
+ if (el.contains(target)) {
633
+ return false;
634
+ }
635
+ if ((_a = options.exclude) == null ? void 0 : _a.length) {
636
+ for (const exclude of options.exclude) {
637
+ const excludeEl = typeof exclude === "function" ? exclude() : getElement(exclude);
638
+ if (excludeEl && (excludeEl === target || excludeEl.contains(target))) {
639
+ return false;
640
+ }
641
+ }
642
+ }
643
+ return true;
644
+ }
645
+ function copyToClipboard(text) {
646
+ return __async(this, null, function* () {
647
+ if (supportsClipboard()) {
648
+ try {
649
+ yield navigator.clipboard.writeText(text);
650
+ return true;
651
+ } catch (e) {
652
+ console.warn("[Directix] Clipboard API failed, falling back to execCommand");
653
+ }
654
+ }
655
+ return copyWithExecCommand(text);
656
+ });
657
+ }
658
+ function copyWithExecCommand(text) {
659
+ const textarea = document.createElement("textarea");
660
+ textarea.value = text;
661
+ textarea.style.cssText = `
662
+ position: fixed;
663
+ top: -9999px;
664
+ left: -9999px;
665
+ opacity: 0;
666
+ pointer-events: none;
667
+ `;
668
+ document.body.appendChild(textarea);
669
+ try {
670
+ textarea.select();
671
+ textarea.setSelectionRange(0, textarea.value.length);
672
+ return document.execCommand("copy");
673
+ } catch (e) {
674
+ return false;
675
+ } finally {
676
+ document.body.removeChild(textarea);
677
+ }
678
+ }
679
+ const vCopy = defineDirective({
680
+ name: "copy",
681
+ ssr: false,
682
+ mounted(el, binding) {
683
+ const options = normalizeOptions$3(binding.value);
684
+ if (options.disabled) return;
685
+ if (options.title) {
686
+ el.setAttribute("title", options.title);
687
+ }
688
+ const state = {
689
+ handler: null,
690
+ options
691
+ };
692
+ state.handler = () => __async(null, null, function* () {
693
+ var _a, _b, _c, _d;
694
+ const text = state.options.value;
695
+ if (!text) {
696
+ console.warn("[Directix] v-copy: No text to copy");
697
+ return;
698
+ }
699
+ try {
700
+ const success = yield copyToClipboard(text);
701
+ if (success) {
702
+ (_b = (_a = state.options).onSuccess) == null ? void 0 : _b.call(_a, text);
703
+ el.dispatchEvent(new CustomEvent("copy:success", { detail: { text } }));
704
+ } else {
705
+ throw new Error("Copy failed");
706
+ }
707
+ } catch (err) {
708
+ const error = err;
709
+ (_d = (_c = state.options).onError) == null ? void 0 : _d.call(_c, error);
710
+ el.dispatchEvent(new CustomEvent("copy:error", { detail: { error } }));
711
+ }
712
+ });
713
+ el.addEventListener("click", state.handler);
714
+ el.__copy = state;
715
+ },
716
+ updated(el, binding) {
717
+ const state = el.__copy;
718
+ if (!state) return;
719
+ state.options = normalizeOptions$3(binding.value);
720
+ if (state.options.title) {
721
+ el.setAttribute("title", state.options.title);
722
+ }
723
+ },
724
+ unmounted(el) {
725
+ const state = el.__copy;
726
+ if (!state) return;
727
+ el.removeEventListener("click", state.handler);
728
+ delete el.__copy;
729
+ }
730
+ });
731
+ function normalizeOptions$3(binding) {
732
+ if (typeof binding === "string") {
733
+ return { value: binding };
734
+ }
735
+ return binding;
736
+ }
737
+ const vDebounce = defineDirective({
738
+ name: "debounce",
739
+ ssr: false,
740
+ defaults: {
741
+ wait: 300,
742
+ leading: false,
743
+ trailing: true
744
+ },
745
+ mounted(el, binding) {
746
+ const options = normalizeOptions$2(binding.value, binding);
747
+ const eventType = getEventTypeFromModifiers$1(binding.modifiers) || getEventType$1(el);
748
+ const debouncedFn = debounce(options.handler, options.wait, {
749
+ leading: options.leading,
750
+ trailing: options.trailing
751
+ });
752
+ el.addEventListener(eventType, debouncedFn);
753
+ el.__debounce = {
754
+ debouncedFn,
755
+ eventType,
756
+ options
757
+ };
758
+ },
759
+ updated(el, binding) {
760
+ const state = el.__debounce;
761
+ if (!state) return;
762
+ const newOptions = normalizeOptions$2(binding.value, binding);
763
+ if (newOptions.wait !== state.options.wait || newOptions.leading !== state.options.leading || newOptions.trailing !== state.options.trailing) {
764
+ state.debouncedFn.cancel();
765
+ const debouncedFn = debounce(newOptions.handler, newOptions.wait, {
766
+ leading: newOptions.leading,
767
+ trailing: newOptions.trailing
768
+ });
769
+ el.removeEventListener(state.eventType, state.debouncedFn);
770
+ el.addEventListener(state.eventType, debouncedFn);
771
+ el.__debounce = {
772
+ debouncedFn,
773
+ eventType: state.eventType,
774
+ options: newOptions
775
+ };
776
+ } else if (newOptions.handler !== state.options.handler) {
777
+ state.options.handler = newOptions.handler;
778
+ }
779
+ },
780
+ unmounted(el) {
781
+ const state = el.__debounce;
782
+ if (!state) return;
783
+ state.debouncedFn.cancel();
784
+ el.removeEventListener(state.eventType, state.debouncedFn);
785
+ delete el.__debounce;
786
+ }
787
+ });
788
+ function normalizeOptions$2(binding, directiveBinding) {
789
+ const wait = parseTime(directiveBinding.arg) || 300;
790
+ if (typeof binding === "function") {
791
+ return { handler: binding, wait };
792
+ }
793
+ return __spreadProps(__spreadValues({}, binding), { wait: binding.wait || wait });
794
+ }
795
+ function getEventType$1(el) {
796
+ const tagName = el.tagName.toLowerCase();
797
+ if (tagName === "input" || tagName === "textarea") {
798
+ return "input";
799
+ }
800
+ return "click";
801
+ }
802
+ const EVENT_MODIFIERS$1 = [
803
+ "click",
804
+ "input",
805
+ "change",
806
+ "submit",
807
+ "scroll",
808
+ "resize",
809
+ "mouseenter",
810
+ "mouseleave",
811
+ "mousemove",
812
+ "mousedown",
813
+ "mouseup",
814
+ "keydown",
815
+ "keyup",
816
+ "focus",
817
+ "blur",
818
+ "touchstart",
819
+ "touchmove",
820
+ "touchend"
821
+ ];
822
+ function getEventTypeFromModifiers$1(modifiers) {
823
+ for (const modifier of EVENT_MODIFIERS$1) {
824
+ if (modifiers[modifier]) {
825
+ return modifier;
826
+ }
827
+ }
828
+ return null;
829
+ }
830
+ const vThrottle = defineDirective({
831
+ name: "throttle",
832
+ ssr: false,
833
+ defaults: {
834
+ wait: 300,
835
+ leading: true,
836
+ trailing: true
837
+ },
838
+ mounted(el, binding) {
839
+ const options = normalizeOptions$1(binding.value, binding);
840
+ const eventType = getEventTypeFromModifiers(binding.modifiers) || getEventType(el);
841
+ const throttledFn = throttle(options.handler, options.wait, {
842
+ leading: options.leading,
843
+ trailing: options.trailing
844
+ });
845
+ el.addEventListener(eventType, throttledFn);
846
+ el.__throttle = {
847
+ throttledFn,
848
+ eventType,
849
+ options
850
+ };
851
+ },
852
+ updated(el, binding) {
853
+ const state = el.__throttle;
854
+ if (!state) return;
855
+ const newOptions = normalizeOptions$1(binding.value, binding);
856
+ if (newOptions.wait !== state.options.wait || newOptions.leading !== state.options.leading || newOptions.trailing !== state.options.trailing) {
857
+ state.throttledFn.cancel();
858
+ const throttledFn = throttle(newOptions.handler, newOptions.wait, {
859
+ leading: newOptions.leading,
860
+ trailing: newOptions.trailing
861
+ });
862
+ el.removeEventListener(state.eventType, state.throttledFn);
863
+ el.addEventListener(state.eventType, throttledFn);
864
+ el.__throttle = {
865
+ throttledFn,
866
+ eventType: state.eventType,
867
+ options: newOptions
868
+ };
869
+ } else if (newOptions.handler !== state.options.handler) {
870
+ state.options.handler = newOptions.handler;
871
+ }
872
+ },
873
+ unmounted(el) {
874
+ const state = el.__throttle;
875
+ if (!state) return;
876
+ state.throttledFn.cancel();
877
+ el.removeEventListener(state.eventType, state.throttledFn);
878
+ delete el.__throttle;
879
+ }
880
+ });
881
+ function normalizeOptions$1(binding, directiveBinding) {
882
+ const wait = parseTime(directiveBinding.arg) || 300;
883
+ if (typeof binding === "function") {
884
+ return { handler: binding, wait };
885
+ }
886
+ return __spreadProps(__spreadValues({}, binding), { wait: binding.wait || wait });
887
+ }
888
+ function getEventType(el) {
889
+ const tagName = el.tagName.toLowerCase();
890
+ if (tagName === "input" || tagName === "textarea") {
891
+ return "input";
892
+ }
893
+ return "click";
894
+ }
895
+ const EVENT_MODIFIERS = [
896
+ "click",
897
+ "input",
898
+ "change",
899
+ "submit",
900
+ "scroll",
901
+ "resize",
902
+ "mouseenter",
903
+ "mouseleave",
904
+ "mousemove",
905
+ "mousedown",
906
+ "mouseup",
907
+ "keydown",
908
+ "keyup",
909
+ "focus",
910
+ "blur",
911
+ "touchstart",
912
+ "touchmove",
913
+ "touchend"
914
+ ];
915
+ function getEventTypeFromModifiers(modifiers) {
916
+ for (const modifier of EVENT_MODIFIERS) {
917
+ if (modifiers[modifier]) {
918
+ return modifier;
919
+ }
920
+ }
921
+ return null;
922
+ }
923
+ const FOCUSABLE_TAGS = /* @__PURE__ */ new Set(["input", "textarea", "select", "button"]);
924
+ function isEqual(a, b) {
925
+ if (a === b) return true;
926
+ if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
927
+ const objA = a;
928
+ const objB = b;
929
+ const keysA = Object.keys(objA);
930
+ const keysB = Object.keys(objB);
931
+ if (keysA.length !== keysB.length) return false;
932
+ return keysA.every((key) => objA[key] === objB[key]);
933
+ }
934
+ const vFocus = defineDirective({
935
+ name: "focus",
936
+ ssr: false,
937
+ defaults: {
938
+ focus: true,
939
+ refocus: false
940
+ },
941
+ mounted(el, binding) {
942
+ const options = normalizeOptions(binding.value);
943
+ if (!options.focus || !isFocusable(el)) {
944
+ if (options.focus) {
945
+ console.warn("[Directix] v-focus: Element is not focusable");
946
+ }
947
+ return;
948
+ }
949
+ const handleFocus = () => {
950
+ var _a;
951
+ return (_a = options.onFocus) == null ? void 0 : _a.call(options, el);
952
+ };
953
+ const handleBlur = () => {
954
+ var _a;
955
+ return (_a = options.onBlur) == null ? void 0 : _a.call(options, el);
956
+ };
957
+ el.addEventListener("focus", handleFocus);
958
+ el.addEventListener("blur", handleBlur);
959
+ el.__focus = {
960
+ options,
961
+ handleFocus,
962
+ handleBlur,
963
+ lastValue: binding.value
964
+ };
965
+ el.focus();
966
+ },
967
+ updated(el, binding) {
968
+ const state = el.__focus;
969
+ if (!state) return;
970
+ const newOptions = normalizeOptions(binding.value);
971
+ if (newOptions.onFocus !== state.options.onFocus) {
972
+ el.removeEventListener("focus", state.handleFocus);
973
+ state.handleFocus = () => {
974
+ var _a;
975
+ return (_a = newOptions.onFocus) == null ? void 0 : _a.call(newOptions, el);
976
+ };
977
+ el.addEventListener("focus", state.handleFocus);
978
+ }
979
+ if (newOptions.onBlur !== state.options.onBlur) {
980
+ el.removeEventListener("blur", state.handleBlur);
981
+ state.handleBlur = () => {
982
+ var _a;
983
+ return (_a = newOptions.onBlur) == null ? void 0 : _a.call(newOptions, el);
984
+ };
985
+ el.addEventListener("blur", state.handleBlur);
986
+ }
987
+ const valueChanged = !isEqual(binding.value, state.lastValue);
988
+ if (newOptions.refocus && newOptions.focus && valueChanged) {
989
+ el.focus();
990
+ }
991
+ state.options = newOptions;
992
+ state.lastValue = binding.value;
993
+ },
994
+ unmounted(el) {
995
+ const state = el.__focus;
996
+ if (!state) return;
997
+ el.removeEventListener("focus", state.handleFocus);
998
+ el.removeEventListener("blur", state.handleBlur);
999
+ delete el.__focus;
1000
+ }
1001
+ });
1002
+ function normalizeOptions(binding) {
1003
+ if (typeof binding === "boolean") {
1004
+ return { focus: binding, refocus: false };
1005
+ }
1006
+ return __spreadValues({
1007
+ focus: true,
1008
+ refocus: false
1009
+ }, binding);
1010
+ }
1011
+ function isFocusable(el) {
1012
+ if (!isBrowser()) return false;
1013
+ const tagName = el.tagName.toLowerCase();
1014
+ if (FOCUSABLE_TAGS.has(tagName)) {
1015
+ return !el.disabled;
1016
+ }
1017
+ if (el.isContentEditable) return true;
1018
+ const tabindex = el.getAttribute("tabindex");
1019
+ if (tabindex != null) return tabindex !== "-1";
1020
+ if (tagName === "a" || tagName === "area") {
1021
+ return el.hasAttribute("href");
1022
+ }
1023
+ return false;
1024
+ }
1025
+ const allDirectives = {
1026
+ "click-outside": vClickOutside,
1027
+ copy: vCopy,
1028
+ debounce: vDebounce,
1029
+ throttle: vThrottle,
1030
+ focus: vFocus
1031
+ };
1032
+ const install = (app, options = {}) => {
1033
+ const { directives, all = false } = options;
1034
+ if (all || !directives) {
1035
+ Object.entries(allDirectives).forEach(([name, directive]) => {
1036
+ app.directive(name, directive);
1037
+ });
1038
+ } else {
1039
+ directives.forEach((name) => {
1040
+ const directive = allDirectives[name];
1041
+ if (directive) {
1042
+ app.directive(name, directive);
1043
+ } else {
1044
+ console.warn(`[Directix] Unknown directive: ${name}`);
1045
+ }
1046
+ });
1047
+ }
1048
+ };
1049
+ const Directix = {
1050
+ install
1051
+ };
1052
+ exports.Directix = Directix;
1053
+ exports.addCleanupVue2 = addCleanup$1;
1054
+ exports.addCleanupVue3 = addCleanup;
1055
+ exports.clickOutside = vClickOutside;
1056
+ exports.copy = vCopy;
1057
+ exports.createVue2Directive = createVue2Directive;
1058
+ exports.createVue3Directive = createVue3Directive;
1059
+ exports.debounce = vDebounce;
1060
+ exports.debounceFn = debounce;
1061
+ exports.deepClone = deepClone;
1062
+ exports.deepMerge = deepMerge;
1063
+ exports.defineDirective = defineDirective;
1064
+ exports.defineDirectiveGroup = defineDirectiveGroup;
1065
+ exports.focus = vFocus;
1066
+ exports.generateId = generateId;
1067
+ exports.get = get;
1068
+ exports.getVueVersion = getVueVersion;
1069
+ exports.isArray = isArray;
1070
+ exports.isBoolean = isBoolean;
1071
+ exports.isBrowser = isBrowser;
1072
+ exports.isEmpty = isEmpty;
1073
+ exports.isFunction = isFunction;
1074
+ exports.isNumber = isNumber;
1075
+ exports.isObject = isObject;
1076
+ exports.isPromise = isPromise;
1077
+ exports.isSSR = isSSR;
1078
+ exports.isString = isString;
1079
+ exports.isVue2 = isVue2;
1080
+ exports.isVue3 = isVue3;
1081
+ exports.parseTime = parseTime;
1082
+ exports.set = set;
1083
+ exports.supportsClipboard = supportsClipboard;
1084
+ exports.supportsIntersectionObserver = supportsIntersectionObserver;
1085
+ exports.supportsMutationObserver = supportsMutationObserver;
1086
+ exports.supportsPassive = supportsPassive;
1087
+ exports.supportsResizeObserver = supportsResizeObserver;
1088
+ exports.throttle = vThrottle;
1089
+ exports.throttleFn = throttle;
1090
+ exports.vClickOutside = vClickOutside;
1091
+ exports.vCopy = vCopy;
1092
+ exports.vDebounce = vDebounce;
1093
+ exports.vFocus = vFocus;
1094
+ exports.vThrottle = vThrottle;
1095
+ //# sourceMappingURL=index.cjs.map