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