directix 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +149 -28
- package/dist/index.cjs +2141 -45
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1084 -67
- package/dist/index.iife.js +2141 -172
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +2 -2
- package/dist/index.mjs +2142 -46
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -10
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* directix v1.
|
|
2
|
+
* directix v1.1.0
|
|
3
3
|
* A comprehensive, easy-to-use, and high-performance Vue custom directives library supporting both Vue 2 and Vue 3
|
|
4
4
|
* (c) 2021-present saqqdy <https://github.com/saqqdy>
|
|
5
5
|
* Released under the MIT License.
|
|
@@ -10,6 +10,7 @@ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
|
10
10
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
11
11
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
12
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
13
|
+
var __pow = Math.pow;
|
|
13
14
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
14
15
|
var __spreadValues = (a, b) => {
|
|
15
16
|
for (var prop in b || (b = {}))
|
|
@@ -56,36 +57,117 @@ var __async = (__this, __arguments, generator) => {
|
|
|
56
57
|
});
|
|
57
58
|
};
|
|
58
59
|
/*!
|
|
59
|
-
* directix v1.
|
|
60
|
+
* directix v1.1.0
|
|
60
61
|
* A comprehensive, easy-to-use, and high-performance Vue custom directives library supporting both Vue 2 and Vue 3
|
|
61
62
|
* (c) 2021-present saqqdy <https://github.com/saqqdy>
|
|
62
63
|
* Released under the MIT License.
|
|
63
64
|
*/
|
|
64
|
-
let _vueVersion = null;
|
|
65
|
+
let _vueVersion = null, _isVue2 = null, _isVue27 = null, _isVue3 = null;
|
|
66
|
+
function parseVersion(version) {
|
|
67
|
+
if (version.startsWith("2.7")) return 2.7;
|
|
68
|
+
if (version.startsWith("2")) return 2;
|
|
69
|
+
if (version.startsWith("3")) return 3;
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
65
72
|
function getVueVersion() {
|
|
66
73
|
var _a, _b;
|
|
67
74
|
if (_vueVersion !== null) return _vueVersion;
|
|
75
|
+
if (typeof process !== "undefined") {
|
|
76
|
+
const envVersion = process.env.DIRECTIX_VUE_VERSION;
|
|
77
|
+
if (envVersion === "2.7") {
|
|
78
|
+
_vueVersion = 2.7;
|
|
79
|
+
return _vueVersion;
|
|
80
|
+
}
|
|
81
|
+
if (envVersion === "2") {
|
|
82
|
+
_vueVersion = 2;
|
|
83
|
+
return _vueVersion;
|
|
84
|
+
}
|
|
85
|
+
if (envVersion === "3") {
|
|
86
|
+
_vueVersion = 3;
|
|
87
|
+
return _vueVersion;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
68
90
|
try {
|
|
69
91
|
const vue = require("vue");
|
|
70
|
-
|
|
92
|
+
const version = parseVersion(vue == null ? void 0 : vue.version);
|
|
93
|
+
if (version !== null) {
|
|
94
|
+
_vueVersion = version;
|
|
95
|
+
return _vueVersion;
|
|
96
|
+
}
|
|
97
|
+
} catch (e) {
|
|
98
|
+
}
|
|
99
|
+
if (typeof window !== "undefined") {
|
|
100
|
+
const win = window;
|
|
101
|
+
const vue = win.Vue;
|
|
102
|
+
if (vue == null ? void 0 : vue.version) {
|
|
103
|
+
const version = parseVersion(vue.version);
|
|
104
|
+
if (version !== null) {
|
|
105
|
+
_vueVersion = version;
|
|
106
|
+
return _vueVersion;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (typeof (vue == null ? void 0 : vue.observable) === "function") {
|
|
71
110
|
_vueVersion = 2;
|
|
72
|
-
|
|
111
|
+
return _vueVersion;
|
|
112
|
+
}
|
|
113
|
+
if (typeof (vue == null ? void 0 : vue.createApp) === "function" && typeof (vue == null ? void 0 : vue.observable) !== "function") {
|
|
73
114
|
_vueVersion = 3;
|
|
115
|
+
return _vueVersion;
|
|
116
|
+
}
|
|
117
|
+
const devtools = win.__VUE_DEVTOOLS_GLOBAL_HOOK__;
|
|
118
|
+
if ((_a = devtools == null ? void 0 : devtools.Vue) == null ? void 0 : _a.version) {
|
|
119
|
+
const version = parseVersion(devtools.Vue.version);
|
|
120
|
+
if (version !== null) {
|
|
121
|
+
_vueVersion = version;
|
|
122
|
+
return _vueVersion;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if ((_b = devtools == null ? void 0 : devtools.apps) == null ? void 0 : _b.length) {
|
|
126
|
+
_vueVersion = 3;
|
|
127
|
+
return _vueVersion;
|
|
74
128
|
}
|
|
75
|
-
} catch (e) {
|
|
76
129
|
}
|
|
77
130
|
if (_vueVersion === null) {
|
|
78
131
|
if (typeof window !== "undefined") {
|
|
79
132
|
console.warn(
|
|
80
|
-
"[Directix] Unable to detect Vue version, defaulting to Vue 3.
|
|
133
|
+
"[Directix] Unable to detect Vue version, defaulting to Vue 3. Set DIRECTIX_VUE_VERSION=2 or call setVueVersion(2) if using Vue 2."
|
|
81
134
|
);
|
|
82
135
|
}
|
|
83
136
|
_vueVersion = 3;
|
|
84
137
|
}
|
|
85
138
|
return _vueVersion;
|
|
86
139
|
}
|
|
87
|
-
|
|
88
|
-
|
|
140
|
+
function setVueVersion(version) {
|
|
141
|
+
_vueVersion = version;
|
|
142
|
+
_isVue2 = version === 2 || version === 2.7;
|
|
143
|
+
_isVue27 = version === 2.7;
|
|
144
|
+
_isVue3 = version === 3;
|
|
145
|
+
}
|
|
146
|
+
function resetVueVersion() {
|
|
147
|
+
_vueVersion = null;
|
|
148
|
+
_isVue2 = null;
|
|
149
|
+
_isVue27 = null;
|
|
150
|
+
_isVue3 = null;
|
|
151
|
+
}
|
|
152
|
+
function isVue2() {
|
|
153
|
+
if (_isVue2 === null) {
|
|
154
|
+
const version = getVueVersion();
|
|
155
|
+
_isVue2 = version === 2 || version === 2.7;
|
|
156
|
+
}
|
|
157
|
+
return _isVue2;
|
|
158
|
+
}
|
|
159
|
+
function isVue27() {
|
|
160
|
+
if (_isVue27 === null) {
|
|
161
|
+
_isVue27 = getVueVersion() === 2.7;
|
|
162
|
+
}
|
|
163
|
+
return _isVue27;
|
|
164
|
+
}
|
|
165
|
+
function isVue3() {
|
|
166
|
+
if (_isVue3 === null) {
|
|
167
|
+
_isVue3 = getVueVersion() === 3;
|
|
168
|
+
}
|
|
169
|
+
return _isVue3;
|
|
170
|
+
}
|
|
89
171
|
const isBrowser = () => {
|
|
90
172
|
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
91
173
|
};
|
|
@@ -260,19 +342,45 @@ function defineDirective(definition) {
|
|
|
260
342
|
}
|
|
261
343
|
const wrappedHooks = {
|
|
262
344
|
mounted: hooks.mounted ? (el, binding, vnode) => {
|
|
263
|
-
|
|
264
|
-
hooks.mounted(el, mergedBinding, vnode);
|
|
345
|
+
hooks.mounted(el, applyDefaults(binding, defaults), vnode);
|
|
265
346
|
} : void 0,
|
|
266
347
|
updated: hooks.updated ? (el, binding, vnode, prevBinding, prevVnode) => {
|
|
267
|
-
|
|
268
|
-
hooks.updated(el, mergedBinding, vnode, prevBinding, prevVnode);
|
|
348
|
+
hooks.updated(el, applyDefaults(binding, defaults), vnode, prevBinding, prevVnode);
|
|
269
349
|
} : void 0,
|
|
270
350
|
unmounted: hooks.unmounted
|
|
271
351
|
};
|
|
272
|
-
|
|
273
|
-
|
|
352
|
+
return createLazyDirective(wrappedHooks);
|
|
353
|
+
}
|
|
354
|
+
function createLazyDirective(hooks) {
|
|
355
|
+
let cachedDirective = null;
|
|
356
|
+
function getDirective() {
|
|
357
|
+
if (!cachedDirective) {
|
|
358
|
+
cachedDirective = getVueVersion() === 2 ? createVue2Directive(hooks) : createVue3Directive(hooks);
|
|
359
|
+
}
|
|
360
|
+
return cachedDirective;
|
|
361
|
+
}
|
|
362
|
+
function createHook(hookName) {
|
|
363
|
+
return function(el, binding, vnode, prevVnode) {
|
|
364
|
+
var _a, _b;
|
|
365
|
+
(_b = (_a = getDirective())[hookName]) == null ? void 0 : _b.call(_a, el, binding, vnode, prevVnode);
|
|
366
|
+
};
|
|
274
367
|
}
|
|
275
|
-
return
|
|
368
|
+
return {
|
|
369
|
+
// Vue 2 hooks
|
|
370
|
+
bind: createHook("bind"),
|
|
371
|
+
inserted: createHook("inserted"),
|
|
372
|
+
update: createHook("update"),
|
|
373
|
+
componentUpdated: createHook("componentUpdated"),
|
|
374
|
+
unbind: createHook("unbind"),
|
|
375
|
+
// Vue 3 hooks
|
|
376
|
+
created: createHook("created"),
|
|
377
|
+
beforeMount: createHook("beforeMount"),
|
|
378
|
+
mounted: createHook("mounted"),
|
|
379
|
+
beforeUpdate: createHook("beforeUpdate"),
|
|
380
|
+
updated: createHook("updated"),
|
|
381
|
+
beforeUnmount: createHook("beforeUnmount"),
|
|
382
|
+
unmounted: createHook("unmounted")
|
|
383
|
+
};
|
|
276
384
|
}
|
|
277
385
|
function applyDefaults(binding, defaults) {
|
|
278
386
|
if (!defaults) return binding;
|
|
@@ -312,17 +420,29 @@ function getElement(target) {
|
|
|
312
420
|
}
|
|
313
421
|
return isElement(target) ? target : null;
|
|
314
422
|
}
|
|
423
|
+
function getScrollParent(el) {
|
|
424
|
+
if (!isBrowser()) return window;
|
|
425
|
+
let parent = el.parentElement;
|
|
426
|
+
while (parent) {
|
|
427
|
+
const { overflow, overflowX, overflowY } = getComputedStyle(parent);
|
|
428
|
+
if (/(auto|scroll)/.test(overflow + overflowX + overflowY)) {
|
|
429
|
+
return parent;
|
|
430
|
+
}
|
|
431
|
+
parent = parent.parentElement;
|
|
432
|
+
}
|
|
433
|
+
return window;
|
|
434
|
+
}
|
|
315
435
|
function on(target, event, handler, options = false) {
|
|
316
436
|
if (!isBrowser()) return;
|
|
317
|
-
const opts = normalizeOptions$
|
|
437
|
+
const opts = normalizeOptions$k(options);
|
|
318
438
|
target.addEventListener(event, handler, opts);
|
|
319
439
|
}
|
|
320
440
|
function off(target, event, handler, options = false) {
|
|
321
441
|
if (!isBrowser()) return;
|
|
322
|
-
const opts = normalizeOptions$
|
|
442
|
+
const opts = normalizeOptions$k(options);
|
|
323
443
|
target.removeEventListener(event, handler, opts);
|
|
324
444
|
}
|
|
325
|
-
function normalizeOptions$
|
|
445
|
+
function normalizeOptions$k(options) {
|
|
326
446
|
if (typeof options === "boolean") {
|
|
327
447
|
return options;
|
|
328
448
|
}
|
|
@@ -332,6 +452,22 @@ function normalizeOptions$5(options) {
|
|
|
332
452
|
}
|
|
333
453
|
return capture;
|
|
334
454
|
}
|
|
455
|
+
function getEventPosition(e) {
|
|
456
|
+
let clientX = 0, clientY = 0;
|
|
457
|
+
if ("touches" in e && e.touches.length > 0) {
|
|
458
|
+
clientX = e.touches[0].clientX;
|
|
459
|
+
clientY = e.touches[0].clientY;
|
|
460
|
+
} else if ("clientX" in e) {
|
|
461
|
+
clientX = e.clientX;
|
|
462
|
+
clientY = e.clientY;
|
|
463
|
+
}
|
|
464
|
+
return {
|
|
465
|
+
x: clientX,
|
|
466
|
+
y: clientY,
|
|
467
|
+
clientX,
|
|
468
|
+
clientY
|
|
469
|
+
};
|
|
470
|
+
}
|
|
335
471
|
function isString(value) {
|
|
336
472
|
return typeof value === "string";
|
|
337
473
|
}
|
|
@@ -529,7 +665,7 @@ const vClickOutside = defineDirective({
|
|
|
529
665
|
prevent: false
|
|
530
666
|
},
|
|
531
667
|
mounted(el, binding) {
|
|
532
|
-
const options = normalizeOptions$
|
|
668
|
+
const options = normalizeOptions$j(binding.value);
|
|
533
669
|
if (options.disabled) return;
|
|
534
670
|
const state = {
|
|
535
671
|
options,
|
|
@@ -564,7 +700,7 @@ const vClickOutside = defineDirective({
|
|
|
564
700
|
const state = el.__clickOutside;
|
|
565
701
|
if (!state) return;
|
|
566
702
|
const oldOptions = state.options;
|
|
567
|
-
const newOptions = normalizeOptions$
|
|
703
|
+
const newOptions = normalizeOptions$j(binding.value);
|
|
568
704
|
if (oldOptions.disabled !== newOptions.disabled) {
|
|
569
705
|
if (newOptions.disabled) {
|
|
570
706
|
state.handlers.forEach((handler, eventType) => {
|
|
@@ -601,7 +737,7 @@ const vClickOutside = defineDirective({
|
|
|
601
737
|
delete el.__clickOutside;
|
|
602
738
|
}
|
|
603
739
|
});
|
|
604
|
-
function normalizeOptions$
|
|
740
|
+
function normalizeOptions$j(binding) {
|
|
605
741
|
var _a, _b, _c, _d, _e;
|
|
606
742
|
if (typeof binding === "function") {
|
|
607
743
|
return {
|
|
@@ -678,7 +814,7 @@ const vCopy = defineDirective({
|
|
|
678
814
|
name: "copy",
|
|
679
815
|
ssr: false,
|
|
680
816
|
mounted(el, binding) {
|
|
681
|
-
const options = normalizeOptions$
|
|
817
|
+
const options = normalizeOptions$i(binding.value);
|
|
682
818
|
if (options.disabled) return;
|
|
683
819
|
if (options.title) {
|
|
684
820
|
el.setAttribute("title", options.title);
|
|
@@ -714,7 +850,7 @@ const vCopy = defineDirective({
|
|
|
714
850
|
updated(el, binding) {
|
|
715
851
|
const state = el.__copy;
|
|
716
852
|
if (!state) return;
|
|
717
|
-
state.options = normalizeOptions$
|
|
853
|
+
state.options = normalizeOptions$i(binding.value);
|
|
718
854
|
if (state.options.title) {
|
|
719
855
|
el.setAttribute("title", state.options.title);
|
|
720
856
|
}
|
|
@@ -726,7 +862,7 @@ const vCopy = defineDirective({
|
|
|
726
862
|
delete el.__copy;
|
|
727
863
|
}
|
|
728
864
|
});
|
|
729
|
-
function normalizeOptions$
|
|
865
|
+
function normalizeOptions$i(binding) {
|
|
730
866
|
if (typeof binding === "string") {
|
|
731
867
|
return { value: binding };
|
|
732
868
|
}
|
|
@@ -734,14 +870,15 @@ function normalizeOptions$3(binding) {
|
|
|
734
870
|
}
|
|
735
871
|
const vDebounce = defineDirective({
|
|
736
872
|
name: "debounce",
|
|
737
|
-
ssr:
|
|
873
|
+
ssr: true,
|
|
874
|
+
// SSR safe - event binding is skipped on server
|
|
738
875
|
defaults: {
|
|
739
876
|
wait: 300,
|
|
740
877
|
leading: false,
|
|
741
878
|
trailing: true
|
|
742
879
|
},
|
|
743
880
|
mounted(el, binding) {
|
|
744
|
-
const options = normalizeOptions$
|
|
881
|
+
const options = normalizeOptions$h(binding.value, binding);
|
|
745
882
|
const eventType = getEventTypeFromModifiers$1(binding.modifiers) || getEventType$1(el);
|
|
746
883
|
const debouncedFn = debounce(options.handler, options.wait, {
|
|
747
884
|
leading: options.leading,
|
|
@@ -757,7 +894,7 @@ const vDebounce = defineDirective({
|
|
|
757
894
|
updated(el, binding) {
|
|
758
895
|
const state = el.__debounce;
|
|
759
896
|
if (!state) return;
|
|
760
|
-
const newOptions = normalizeOptions$
|
|
897
|
+
const newOptions = normalizeOptions$h(binding.value, binding);
|
|
761
898
|
if (newOptions.wait !== state.options.wait || newOptions.leading !== state.options.leading || newOptions.trailing !== state.options.trailing) {
|
|
762
899
|
state.debouncedFn.cancel();
|
|
763
900
|
const debouncedFn = debounce(newOptions.handler, newOptions.wait, {
|
|
@@ -783,7 +920,7 @@ const vDebounce = defineDirective({
|
|
|
783
920
|
delete el.__debounce;
|
|
784
921
|
}
|
|
785
922
|
});
|
|
786
|
-
function normalizeOptions$
|
|
923
|
+
function normalizeOptions$h(binding, directiveBinding) {
|
|
787
924
|
const wait = parseTime(directiveBinding.arg) || 300;
|
|
788
925
|
if (typeof binding === "function") {
|
|
789
926
|
return { handler: binding, wait };
|
|
@@ -827,14 +964,15 @@ function getEventTypeFromModifiers$1(modifiers) {
|
|
|
827
964
|
}
|
|
828
965
|
const vThrottle = defineDirective({
|
|
829
966
|
name: "throttle",
|
|
830
|
-
ssr:
|
|
967
|
+
ssr: true,
|
|
968
|
+
// SSR safe - event binding is skipped on server
|
|
831
969
|
defaults: {
|
|
832
970
|
wait: 300,
|
|
833
971
|
leading: true,
|
|
834
972
|
trailing: true
|
|
835
973
|
},
|
|
836
974
|
mounted(el, binding) {
|
|
837
|
-
const options = normalizeOptions$
|
|
975
|
+
const options = normalizeOptions$g(binding.value, binding);
|
|
838
976
|
const eventType = getEventTypeFromModifiers(binding.modifiers) || getEventType(el);
|
|
839
977
|
const throttledFn = throttle(options.handler, options.wait, {
|
|
840
978
|
leading: options.leading,
|
|
@@ -850,7 +988,7 @@ const vThrottle = defineDirective({
|
|
|
850
988
|
updated(el, binding) {
|
|
851
989
|
const state = el.__throttle;
|
|
852
990
|
if (!state) return;
|
|
853
|
-
const newOptions = normalizeOptions$
|
|
991
|
+
const newOptions = normalizeOptions$g(binding.value, binding);
|
|
854
992
|
if (newOptions.wait !== state.options.wait || newOptions.leading !== state.options.leading || newOptions.trailing !== state.options.trailing) {
|
|
855
993
|
state.throttledFn.cancel();
|
|
856
994
|
const throttledFn = throttle(newOptions.handler, newOptions.wait, {
|
|
@@ -876,7 +1014,7 @@ const vThrottle = defineDirective({
|
|
|
876
1014
|
delete el.__throttle;
|
|
877
1015
|
}
|
|
878
1016
|
});
|
|
879
|
-
function normalizeOptions$
|
|
1017
|
+
function normalizeOptions$g(binding, directiveBinding) {
|
|
880
1018
|
const wait = parseTime(directiveBinding.arg) || 300;
|
|
881
1019
|
if (typeof binding === "function") {
|
|
882
1020
|
return { handler: binding, wait };
|
|
@@ -931,13 +1069,15 @@ function isEqual(a, b) {
|
|
|
931
1069
|
}
|
|
932
1070
|
const vFocus = defineDirective({
|
|
933
1071
|
name: "focus",
|
|
934
|
-
ssr:
|
|
1072
|
+
ssr: true,
|
|
1073
|
+
// SSR safe - will skip focus on server
|
|
935
1074
|
defaults: {
|
|
936
1075
|
focus: true,
|
|
937
1076
|
refocus: false
|
|
938
1077
|
},
|
|
939
1078
|
mounted(el, binding) {
|
|
940
|
-
|
|
1079
|
+
if (!isBrowser()) return;
|
|
1080
|
+
const options = normalizeOptions$f(binding.value);
|
|
941
1081
|
if (!options.focus || !isFocusable(el)) {
|
|
942
1082
|
if (options.focus) {
|
|
943
1083
|
console.warn("[Directix] v-focus: Element is not focusable");
|
|
@@ -965,7 +1105,7 @@ const vFocus = defineDirective({
|
|
|
965
1105
|
updated(el, binding) {
|
|
966
1106
|
const state = el.__focus;
|
|
967
1107
|
if (!state) return;
|
|
968
|
-
const newOptions = normalizeOptions(binding.value);
|
|
1108
|
+
const newOptions = normalizeOptions$f(binding.value);
|
|
969
1109
|
if (newOptions.onFocus !== state.options.onFocus) {
|
|
970
1110
|
el.removeEventListener("focus", state.handleFocus);
|
|
971
1111
|
state.handleFocus = () => {
|
|
@@ -997,7 +1137,7 @@ const vFocus = defineDirective({
|
|
|
997
1137
|
delete el.__focus;
|
|
998
1138
|
}
|
|
999
1139
|
});
|
|
1000
|
-
function normalizeOptions(binding) {
|
|
1140
|
+
function normalizeOptions$f(binding) {
|
|
1001
1141
|
if (typeof binding === "boolean") {
|
|
1002
1142
|
return { focus: binding, refocus: false };
|
|
1003
1143
|
}
|
|
@@ -1020,14 +1160,1935 @@ function isFocusable(el) {
|
|
|
1020
1160
|
}
|
|
1021
1161
|
return false;
|
|
1022
1162
|
}
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1163
|
+
let globalObserver = null;
|
|
1164
|
+
function getGlobalObserver(preload) {
|
|
1165
|
+
if (globalObserver) return globalObserver;
|
|
1166
|
+
globalObserver = new IntersectionObserver(
|
|
1167
|
+
(entries) => {
|
|
1168
|
+
entries.forEach((entry) => {
|
|
1169
|
+
if (entry.isIntersecting) {
|
|
1170
|
+
load(entry.target);
|
|
1171
|
+
globalObserver == null ? void 0 : globalObserver.unobserve(entry.target);
|
|
1172
|
+
}
|
|
1173
|
+
});
|
|
1174
|
+
},
|
|
1175
|
+
{
|
|
1176
|
+
rootMargin: `${preload}px`
|
|
1177
|
+
}
|
|
1178
|
+
);
|
|
1179
|
+
return globalObserver;
|
|
1180
|
+
}
|
|
1181
|
+
function setSrc(el, src) {
|
|
1182
|
+
if (el.tagName === "IMG") {
|
|
1183
|
+
el.src = src;
|
|
1184
|
+
} else {
|
|
1185
|
+
el.style.backgroundImage = `url("${src}")`;
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
function setLazyState(el, state) {
|
|
1189
|
+
el.dataset.lazyState = state;
|
|
1190
|
+
}
|
|
1191
|
+
function getLazyState(el) {
|
|
1192
|
+
return el.dataset.lazyState || "pending";
|
|
1193
|
+
}
|
|
1194
|
+
function load(el) {
|
|
1195
|
+
const state = el.__lazy;
|
|
1196
|
+
if (!state || !state.options.src) return;
|
|
1197
|
+
if (state.options.filter && !state.options.filter(state.options.src)) {
|
|
1198
|
+
return;
|
|
1199
|
+
}
|
|
1200
|
+
setLazyState(el, "loading");
|
|
1201
|
+
state.attempt++;
|
|
1202
|
+
el.classList.add("v-lazy--loading");
|
|
1203
|
+
const img = new Image();
|
|
1204
|
+
img.onload = () => {
|
|
1205
|
+
var _a, _b;
|
|
1206
|
+
setSrc(el, state.options.src);
|
|
1207
|
+
setLazyState(el, "loaded");
|
|
1208
|
+
el.classList.remove("v-lazy--loading");
|
|
1209
|
+
el.classList.add("v-lazy--loaded");
|
|
1210
|
+
(_b = (_a = state.options).onLoad) == null ? void 0 : _b.call(_a, el);
|
|
1211
|
+
};
|
|
1212
|
+
img.onerror = () => {
|
|
1213
|
+
var _a, _b;
|
|
1214
|
+
el.classList.remove("v-lazy--loading");
|
|
1215
|
+
if (state.attempt < (state.options.attempt || 1)) {
|
|
1216
|
+
setTimeout(() => load(el), 1e3 * state.attempt);
|
|
1217
|
+
return;
|
|
1218
|
+
}
|
|
1219
|
+
if (state.options.error) {
|
|
1220
|
+
setSrc(el, state.options.error);
|
|
1221
|
+
}
|
|
1222
|
+
setLazyState(el, "error");
|
|
1223
|
+
el.classList.add("v-lazy--error");
|
|
1224
|
+
(_b = (_a = state.options).onError) == null ? void 0 : _b.call(_a, el, new Error("Failed to load image"));
|
|
1225
|
+
};
|
|
1226
|
+
img.src = state.options.src;
|
|
1227
|
+
}
|
|
1228
|
+
function observe(el) {
|
|
1229
|
+
const state = el.__lazy;
|
|
1230
|
+
if (!state) return;
|
|
1231
|
+
if (!supportsIntersectionObserver()) {
|
|
1232
|
+
load(el);
|
|
1233
|
+
return;
|
|
1234
|
+
}
|
|
1235
|
+
if (state.options.observer) {
|
|
1236
|
+
state.observer = state.options.observer;
|
|
1237
|
+
state.observer.observe(el);
|
|
1238
|
+
} else {
|
|
1239
|
+
const observer = getGlobalObserver(state.options.preload || 0);
|
|
1240
|
+
state.observer = observer;
|
|
1241
|
+
observer.observe(el);
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
function unobserve(el) {
|
|
1245
|
+
const state = el.__lazy;
|
|
1246
|
+
if (!state) return;
|
|
1247
|
+
if (state.observer) {
|
|
1248
|
+
state.observer.unobserve(el);
|
|
1249
|
+
} else if (globalObserver) {
|
|
1250
|
+
globalObserver.unobserve(el);
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
function normalizeOptions$e(binding) {
|
|
1254
|
+
if (typeof binding === "string") {
|
|
1255
|
+
return { src: binding };
|
|
1256
|
+
}
|
|
1257
|
+
return binding || {};
|
|
1258
|
+
}
|
|
1259
|
+
const vLazy = defineDirective({
|
|
1260
|
+
name: "lazy",
|
|
1261
|
+
ssr: false,
|
|
1262
|
+
defaults: {
|
|
1263
|
+
preload: 0,
|
|
1264
|
+
attempt: 1,
|
|
1265
|
+
disabled: false
|
|
1266
|
+
},
|
|
1267
|
+
mounted(el, binding) {
|
|
1268
|
+
const options = normalizeOptions$e(binding.value);
|
|
1269
|
+
if (options.disabled) return;
|
|
1270
|
+
if (!options.src) {
|
|
1271
|
+
console.warn("[Directix] v-lazy: No source provided");
|
|
1272
|
+
return;
|
|
1273
|
+
}
|
|
1274
|
+
setLazyState(el, "pending");
|
|
1275
|
+
if (options.placeholder) {
|
|
1276
|
+
setSrc(el, options.placeholder);
|
|
1277
|
+
}
|
|
1278
|
+
el.classList.add("v-lazy");
|
|
1279
|
+
const state = {
|
|
1280
|
+
options,
|
|
1281
|
+
attempt: 0
|
|
1282
|
+
};
|
|
1283
|
+
el.__lazy = state;
|
|
1284
|
+
observe(el);
|
|
1285
|
+
},
|
|
1286
|
+
updated(el, binding) {
|
|
1287
|
+
const state = el.__lazy;
|
|
1288
|
+
if (!state) return;
|
|
1289
|
+
const newOptions = normalizeOptions$e(binding.value);
|
|
1290
|
+
if (newOptions.disabled) {
|
|
1291
|
+
unobserve(el);
|
|
1292
|
+
return;
|
|
1293
|
+
}
|
|
1294
|
+
if (newOptions.src !== state.options.src) {
|
|
1295
|
+
state.options = newOptions;
|
|
1296
|
+
state.attempt = 0;
|
|
1297
|
+
if (getLazyState(el) !== "pending") {
|
|
1298
|
+
setLazyState(el, "pending");
|
|
1299
|
+
el.classList.remove("v-lazy--loaded", "v-lazy--error");
|
|
1300
|
+
if (newOptions.placeholder) {
|
|
1301
|
+
setSrc(el, newOptions.placeholder);
|
|
1302
|
+
}
|
|
1303
|
+
observe(el);
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
},
|
|
1307
|
+
unmounted(el) {
|
|
1308
|
+
unobserve(el);
|
|
1309
|
+
delete el.__lazy;
|
|
1310
|
+
}
|
|
1311
|
+
});
|
|
1312
|
+
const STATE_KEY$3 = "__intersect";
|
|
1313
|
+
function normalizeOptions$d(binding) {
|
|
1314
|
+
const options = typeof binding === "function" ? { handler: binding } : __spreadValues({}, binding);
|
|
1315
|
+
if (options.root !== null && typeof options.root === "object" && "value" in options.root) {
|
|
1316
|
+
options.root = options.root.value;
|
|
1317
|
+
}
|
|
1318
|
+
return options;
|
|
1319
|
+
}
|
|
1320
|
+
function createObserverCallback(el, state, options) {
|
|
1321
|
+
return (entries) => {
|
|
1322
|
+
var _a, _b, _c, _d;
|
|
1323
|
+
for (const entry of entries) {
|
|
1324
|
+
if (options.once && state.hasTriggeredOnce) continue;
|
|
1325
|
+
const { isIntersecting } = entry;
|
|
1326
|
+
(_a = options.handler) == null ? void 0 : _a.call(options, entry, state.observer);
|
|
1327
|
+
(_b = options.onChange) == null ? void 0 : _b.call(options, isIntersecting, entry);
|
|
1328
|
+
if (isIntersecting) {
|
|
1329
|
+
(_c = options.onEnter) == null ? void 0 : _c.call(options, entry, state.observer);
|
|
1330
|
+
if (options.once) state.hasTriggeredOnce = true;
|
|
1331
|
+
} else {
|
|
1332
|
+
(_d = options.onLeave) == null ? void 0 : _d.call(options, entry, state.observer);
|
|
1333
|
+
}
|
|
1334
|
+
el.dispatchEvent(new CustomEvent("intersect", { detail: { isIntersecting, entry } }));
|
|
1335
|
+
}
|
|
1336
|
+
};
|
|
1337
|
+
}
|
|
1338
|
+
function createObserver(el, state, options) {
|
|
1339
|
+
return new IntersectionObserver(createObserverCallback(el, state, options), {
|
|
1340
|
+
root: options.root,
|
|
1341
|
+
rootMargin: options.rootMargin,
|
|
1342
|
+
threshold: options.threshold
|
|
1343
|
+
});
|
|
1344
|
+
}
|
|
1345
|
+
const vIntersect = defineDirective({
|
|
1346
|
+
name: "intersect",
|
|
1347
|
+
ssr: false,
|
|
1348
|
+
defaults: {
|
|
1349
|
+
disabled: false,
|
|
1350
|
+
once: false,
|
|
1351
|
+
rootMargin: "0px",
|
|
1352
|
+
threshold: 0
|
|
1353
|
+
},
|
|
1354
|
+
mounted(el, binding) {
|
|
1355
|
+
const options = normalizeOptions$d(binding.value);
|
|
1356
|
+
if (options.disabled || !isBrowser() || !supportsIntersectionObserver()) {
|
|
1357
|
+
if (!supportsIntersectionObserver()) {
|
|
1358
|
+
console.warn("[Directix] v-intersect: IntersectionObserver not supported");
|
|
1359
|
+
}
|
|
1360
|
+
return;
|
|
1361
|
+
}
|
|
1362
|
+
const state = {
|
|
1363
|
+
options,
|
|
1364
|
+
observer: null,
|
|
1365
|
+
hasTriggeredOnce: false
|
|
1366
|
+
};
|
|
1367
|
+
state.observer = createObserver(el, state, options);
|
|
1368
|
+
el[STATE_KEY$3] = state;
|
|
1369
|
+
state.observer.observe(el);
|
|
1370
|
+
},
|
|
1371
|
+
updated(el, binding) {
|
|
1372
|
+
var _a, _b, _c;
|
|
1373
|
+
const state = el[STATE_KEY$3];
|
|
1374
|
+
if (!state) return;
|
|
1375
|
+
const newOptions = normalizeOptions$d(binding.value);
|
|
1376
|
+
const observerOptionsChanged = newOptions.root !== state.options.root || newOptions.rootMargin !== state.options.rootMargin || newOptions.threshold !== state.options.threshold;
|
|
1377
|
+
if (newOptions.disabled !== state.options.disabled) {
|
|
1378
|
+
if (newOptions.disabled) {
|
|
1379
|
+
(_a = state.observer) == null ? void 0 : _a.disconnect();
|
|
1380
|
+
} else {
|
|
1381
|
+
(_b = state.observer) == null ? void 0 : _b.observe(el);
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
if (observerOptionsChanged) {
|
|
1385
|
+
(_c = state.observer) == null ? void 0 : _c.disconnect();
|
|
1386
|
+
state.observer = createObserver(el, state, newOptions);
|
|
1387
|
+
state.observer.observe(el);
|
|
1388
|
+
}
|
|
1389
|
+
state.options = newOptions;
|
|
1390
|
+
},
|
|
1391
|
+
unmounted(el) {
|
|
1392
|
+
var _a;
|
|
1393
|
+
const state = el[STATE_KEY$3];
|
|
1394
|
+
if (!state) return;
|
|
1395
|
+
(_a = state.observer) == null ? void 0 : _a.disconnect();
|
|
1396
|
+
delete el[STATE_KEY$3];
|
|
1397
|
+
}
|
|
1398
|
+
});
|
|
1399
|
+
function normalizeOptions$c(binding) {
|
|
1400
|
+
if (typeof binding === "boolean") {
|
|
1401
|
+
return { initial: binding };
|
|
1402
|
+
}
|
|
1403
|
+
return __spreadValues({
|
|
1404
|
+
initial: true,
|
|
1405
|
+
disabled: false,
|
|
1406
|
+
useHidden: false
|
|
1407
|
+
}, binding);
|
|
1408
|
+
}
|
|
1409
|
+
const vVisible = defineDirective({
|
|
1410
|
+
name: "visible",
|
|
1411
|
+
ssr: true,
|
|
1412
|
+
// SSR safe - will set initial visibility on server
|
|
1413
|
+
defaults: {
|
|
1414
|
+
initial: true,
|
|
1415
|
+
disabled: false,
|
|
1416
|
+
useHidden: false
|
|
1417
|
+
},
|
|
1418
|
+
mounted(el, binding) {
|
|
1419
|
+
var _a, _b;
|
|
1420
|
+
if (!isBrowser()) return;
|
|
1421
|
+
const options = normalizeOptions$c(binding.value);
|
|
1422
|
+
const originalDisplay = el.style.display;
|
|
1423
|
+
const originalVisibility = el.style.visibility;
|
|
1424
|
+
const state = {
|
|
1425
|
+
options,
|
|
1426
|
+
isVisible: (_a = options.initial) != null ? _a : true,
|
|
1427
|
+
originalDisplay,
|
|
1428
|
+
originalVisibility,
|
|
1429
|
+
transitionEndHandler: (e) => {
|
|
1430
|
+
if (e.propertyName === "opacity" || e.propertyName === "visibility") {
|
|
1431
|
+
el.dispatchEvent(new CustomEvent("visible:transition-end", {
|
|
1432
|
+
detail: { isVisible: state.isVisible }
|
|
1433
|
+
}));
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
};
|
|
1437
|
+
el.__visible = state;
|
|
1438
|
+
on(el, "transitionend", state.transitionEndHandler);
|
|
1439
|
+
applyVisibility(el, state, (_b = options.initial) != null ? _b : true);
|
|
1440
|
+
},
|
|
1441
|
+
updated(el, binding) {
|
|
1442
|
+
var _a;
|
|
1443
|
+
const state = el.__visible;
|
|
1444
|
+
if (!state) return;
|
|
1445
|
+
const newOptions = normalizeOptions$c(binding.value);
|
|
1446
|
+
let newVisibility;
|
|
1447
|
+
if (typeof binding.value === "boolean") {
|
|
1448
|
+
newVisibility = binding.value;
|
|
1449
|
+
} else {
|
|
1450
|
+
newVisibility = (_a = newOptions.initial) != null ? _a : true;
|
|
1451
|
+
}
|
|
1452
|
+
if (state.isVisible !== newVisibility) {
|
|
1453
|
+
applyVisibility(el, state, newVisibility);
|
|
1454
|
+
}
|
|
1455
|
+
state.options = newOptions;
|
|
1456
|
+
},
|
|
1457
|
+
unmounted(el) {
|
|
1458
|
+
const state = el.__visible;
|
|
1459
|
+
if (!state) return;
|
|
1460
|
+
off(el, "transitionend", state.transitionEndHandler);
|
|
1461
|
+
el.style.display = state.originalDisplay;
|
|
1462
|
+
el.style.visibility = state.originalVisibility;
|
|
1463
|
+
delete el.__visible;
|
|
1464
|
+
}
|
|
1465
|
+
});
|
|
1466
|
+
function applyVisibility(el, state, isVisible) {
|
|
1467
|
+
const previousVisibility = state.isVisible;
|
|
1468
|
+
state.isVisible = isVisible;
|
|
1469
|
+
if (isVisible) {
|
|
1470
|
+
el.classList.remove("v-hidden");
|
|
1471
|
+
el.classList.add("v-visible");
|
|
1472
|
+
} else {
|
|
1473
|
+
el.classList.remove("v-visible");
|
|
1474
|
+
el.classList.add("v-hidden");
|
|
1475
|
+
}
|
|
1476
|
+
if (state.options.useHidden) {
|
|
1477
|
+
if (isVisible) {
|
|
1478
|
+
el.style.visibility = state.originalVisibility || "visible";
|
|
1479
|
+
} else {
|
|
1480
|
+
const computedStyle = getComputedStyle(el);
|
|
1481
|
+
const hasTransition = computedStyle.transitionDuration !== "0s";
|
|
1482
|
+
if (hasTransition) {
|
|
1483
|
+
const handleTransitionEnd = (e) => {
|
|
1484
|
+
if (e.target === el && (e.propertyName === "opacity" || e.propertyName === "transform")) {
|
|
1485
|
+
if (!state.isVisible) {
|
|
1486
|
+
el.style.visibility = "hidden";
|
|
1487
|
+
}
|
|
1488
|
+
el.removeEventListener("transitionend", handleTransitionEnd);
|
|
1489
|
+
}
|
|
1490
|
+
};
|
|
1491
|
+
el.addEventListener("transitionend", handleTransitionEnd);
|
|
1492
|
+
} else {
|
|
1493
|
+
el.style.visibility = "hidden";
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
} else {
|
|
1497
|
+
el.style.display = isVisible ? state.originalDisplay : "none";
|
|
1498
|
+
}
|
|
1499
|
+
el.dispatchEvent(new CustomEvent("visible:change", {
|
|
1500
|
+
detail: { isVisible, previousVisibility }
|
|
1501
|
+
}));
|
|
1502
|
+
if (state.options.handler && previousVisibility !== isVisible) {
|
|
1503
|
+
state.options.handler(isVisible);
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
function normalizeOptions$b(binding) {
|
|
1507
|
+
if (typeof binding === "boolean") {
|
|
1508
|
+
return { value: binding };
|
|
1509
|
+
}
|
|
1510
|
+
return __spreadValues({
|
|
1511
|
+
value: true,
|
|
1512
|
+
loadingClass: "v-loading",
|
|
1513
|
+
spinnerClass: "v-loading__spinner",
|
|
1514
|
+
textClass: "v-loading__text",
|
|
1515
|
+
background: "rgba(255, 255, 255, 0.9)",
|
|
1516
|
+
lock: false,
|
|
1517
|
+
disabled: false
|
|
1518
|
+
}, binding);
|
|
1519
|
+
}
|
|
1520
|
+
const DEFAULT_SPINNER = `
|
|
1521
|
+
<svg class="v-loading__circular" viewBox="25 25 50 50">
|
|
1522
|
+
<circle class="v-loading__path" cx="50" cy="50" r="20" fill="none" stroke-width="2" stroke-miterlimit="10"/>
|
|
1523
|
+
</svg>
|
|
1524
|
+
`;
|
|
1525
|
+
function createLoadingOverlay(options) {
|
|
1526
|
+
const overlay = document.createElement("div");
|
|
1527
|
+
overlay.className = options.loadingClass || "v-loading";
|
|
1528
|
+
overlay.style.cssText = `
|
|
1529
|
+
position: absolute;
|
|
1530
|
+
top: 0;
|
|
1531
|
+
left: 0;
|
|
1532
|
+
right: 0;
|
|
1533
|
+
bottom: 0;
|
|
1534
|
+
z-index: 1000;
|
|
1535
|
+
background: ${options.background || "rgba(255, 255, 255, 0.9)"};
|
|
1536
|
+
display: flex;
|
|
1537
|
+
flex-direction: column;
|
|
1538
|
+
align-items: center;
|
|
1539
|
+
justify-content: center;
|
|
1540
|
+
`;
|
|
1541
|
+
const spinnerHtml = options.spinner || DEFAULT_SPINNER;
|
|
1542
|
+
const spinnerContainer = document.createElement("div");
|
|
1543
|
+
spinnerContainer.className = options.spinnerClass || "v-loading__spinner";
|
|
1544
|
+
spinnerContainer.innerHTML = spinnerHtml;
|
|
1545
|
+
overlay.appendChild(spinnerContainer);
|
|
1546
|
+
if (options.text) {
|
|
1547
|
+
const textEl = document.createElement("div");
|
|
1548
|
+
textEl.className = options.textClass || "v-loading__text";
|
|
1549
|
+
textEl.textContent = options.text;
|
|
1550
|
+
overlay.appendChild(textEl);
|
|
1551
|
+
}
|
|
1552
|
+
return overlay;
|
|
1553
|
+
}
|
|
1554
|
+
const vLoading = defineDirective({
|
|
1555
|
+
name: "loading",
|
|
1556
|
+
ssr: true,
|
|
1557
|
+
// SSR safe - will skip DOM manipulation on server
|
|
1558
|
+
defaults: {
|
|
1559
|
+
value: true,
|
|
1560
|
+
loadingClass: "v-loading",
|
|
1561
|
+
spinnerClass: "v-loading__spinner",
|
|
1562
|
+
textClass: "v-loading__text",
|
|
1563
|
+
background: "rgba(255, 255, 255, 0.9)",
|
|
1564
|
+
lock: false,
|
|
1565
|
+
disabled: false
|
|
1566
|
+
},
|
|
1567
|
+
mounted(el, binding) {
|
|
1568
|
+
if (!isBrowser()) return;
|
|
1569
|
+
const options = normalizeOptions$b(binding.value);
|
|
1570
|
+
if (options.disabled) return;
|
|
1571
|
+
const computedStyle = getComputedStyle(el);
|
|
1572
|
+
const originalPosition = el.style.position;
|
|
1573
|
+
const originalOverflow = el.style.overflow;
|
|
1574
|
+
const state = {
|
|
1575
|
+
options,
|
|
1576
|
+
loadingOverlay: null,
|
|
1577
|
+
originalPosition,
|
|
1578
|
+
originalOverflow
|
|
1579
|
+
};
|
|
1580
|
+
el.__loading = state;
|
|
1581
|
+
if (computedStyle.position === "static") {
|
|
1582
|
+
el.style.position = "relative";
|
|
1583
|
+
}
|
|
1584
|
+
if (options.value) {
|
|
1585
|
+
showLoading(el, state);
|
|
1586
|
+
}
|
|
1587
|
+
},
|
|
1588
|
+
updated(el, binding) {
|
|
1589
|
+
const state = el.__loading;
|
|
1590
|
+
if (!state) return;
|
|
1591
|
+
const newOptions = normalizeOptions$b(binding.value);
|
|
1592
|
+
if (newOptions.disabled) {
|
|
1593
|
+
hideLoading(el, state);
|
|
1594
|
+
return;
|
|
1595
|
+
}
|
|
1596
|
+
if (newOptions.value && !state.options.value) {
|
|
1597
|
+
showLoading(el, state);
|
|
1598
|
+
} else if (!newOptions.value && state.options.value) {
|
|
1599
|
+
hideLoading(el, state);
|
|
1600
|
+
}
|
|
1601
|
+
if (state.loadingOverlay && newOptions.text !== state.options.text) {
|
|
1602
|
+
const textEl = state.loadingOverlay.querySelector(`.${state.options.textClass}`);
|
|
1603
|
+
if (textEl) {
|
|
1604
|
+
textEl.textContent = newOptions.text || "";
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
state.options = newOptions;
|
|
1608
|
+
},
|
|
1609
|
+
unmounted(el) {
|
|
1610
|
+
const state = el.__loading;
|
|
1611
|
+
if (!state) return;
|
|
1612
|
+
hideLoading(el, state);
|
|
1613
|
+
el.style.position = state.originalPosition;
|
|
1614
|
+
el.style.overflow = state.originalOverflow;
|
|
1615
|
+
delete el.__loading;
|
|
1616
|
+
}
|
|
1617
|
+
});
|
|
1618
|
+
function showLoading(el, state) {
|
|
1619
|
+
if (state.loadingOverlay) return;
|
|
1620
|
+
state.loadingOverlay = createLoadingOverlay(state.options);
|
|
1621
|
+
el.appendChild(state.loadingOverlay);
|
|
1622
|
+
if (state.options.lock) {
|
|
1623
|
+
el.style.overflow = "hidden";
|
|
1624
|
+
}
|
|
1625
|
+
el.classList.add("v-loading--active");
|
|
1626
|
+
}
|
|
1627
|
+
function hideLoading(el, state) {
|
|
1628
|
+
if (!state.loadingOverlay) return;
|
|
1629
|
+
state.loadingOverlay.remove();
|
|
1630
|
+
state.loadingOverlay = null;
|
|
1631
|
+
if (state.options.lock) {
|
|
1632
|
+
el.style.overflow = state.originalOverflow;
|
|
1633
|
+
}
|
|
1634
|
+
el.classList.remove("v-loading--active");
|
|
1635
|
+
}
|
|
1636
|
+
function getScrollInfo(container, lastScrollLeft, lastScrollTop) {
|
|
1637
|
+
let scrollLeft = 0, scrollTop = 0, scrollLeftMax = 0, scrollTopMax = 0;
|
|
1638
|
+
if (container === window) {
|
|
1639
|
+
scrollLeft = window.scrollX || document.documentElement.scrollLeft;
|
|
1640
|
+
scrollTop = window.scrollY || document.documentElement.scrollTop;
|
|
1641
|
+
scrollLeftMax = document.documentElement.scrollWidth - window.innerWidth;
|
|
1642
|
+
scrollTopMax = document.documentElement.scrollHeight - window.innerHeight;
|
|
1643
|
+
} else {
|
|
1644
|
+
const el = container;
|
|
1645
|
+
scrollLeft = el.scrollLeft;
|
|
1646
|
+
scrollTop = el.scrollTop;
|
|
1647
|
+
scrollLeftMax = el.scrollWidth - el.clientWidth;
|
|
1648
|
+
scrollTopMax = el.scrollHeight - el.clientHeight;
|
|
1649
|
+
}
|
|
1650
|
+
const progressX = scrollLeftMax > 0 ? scrollLeft / scrollLeftMax : 0;
|
|
1651
|
+
const progressY = scrollTopMax > 0 ? scrollTop / scrollTopMax : 0;
|
|
1652
|
+
const directionX = scrollLeft !== lastScrollLeft ? scrollLeft > lastScrollLeft ? 1 : -1 : 0;
|
|
1653
|
+
const directionY = scrollTop !== lastScrollTop ? scrollTop > lastScrollTop ? 1 : -1 : 0;
|
|
1654
|
+
return {
|
|
1655
|
+
scrollLeft,
|
|
1656
|
+
scrollTop,
|
|
1657
|
+
scrollLeftMax,
|
|
1658
|
+
scrollTopMax,
|
|
1659
|
+
progressX,
|
|
1660
|
+
progressY,
|
|
1661
|
+
directionX,
|
|
1662
|
+
directionY,
|
|
1663
|
+
container
|
|
1664
|
+
};
|
|
1665
|
+
}
|
|
1666
|
+
function normalizeOptions$a(binding) {
|
|
1667
|
+
if (typeof binding === "function") {
|
|
1668
|
+
return { handler: binding, passive: true };
|
|
1669
|
+
}
|
|
1670
|
+
if (!binding) {
|
|
1671
|
+
throw new Error("[Directix] v-scroll: handler is required");
|
|
1672
|
+
}
|
|
1673
|
+
return __spreadValues({
|
|
1674
|
+
passive: true,
|
|
1675
|
+
throttle: 0,
|
|
1676
|
+
disabled: false
|
|
1677
|
+
}, binding);
|
|
1678
|
+
}
|
|
1679
|
+
const vScroll = defineDirective({
|
|
1680
|
+
name: "scroll",
|
|
1681
|
+
ssr: false,
|
|
1682
|
+
defaults: {
|
|
1683
|
+
passive: true,
|
|
1684
|
+
throttle: 0,
|
|
1685
|
+
disabled: false
|
|
1686
|
+
},
|
|
1687
|
+
mounted(el, binding) {
|
|
1688
|
+
const options = normalizeOptions$a(binding.value);
|
|
1689
|
+
if (options.disabled || !isBrowser()) return;
|
|
1690
|
+
let container;
|
|
1691
|
+
if (options.container) {
|
|
1692
|
+
if (options.container === window) {
|
|
1693
|
+
container = window;
|
|
1694
|
+
} else if (typeof options.container === "string") {
|
|
1695
|
+
const found = document.querySelector(options.container);
|
|
1696
|
+
container = found || getScrollParent(el);
|
|
1697
|
+
} else {
|
|
1698
|
+
container = options.container;
|
|
1699
|
+
}
|
|
1700
|
+
} else {
|
|
1701
|
+
const { overflow, overflowX, overflowY } = getComputedStyle(el);
|
|
1702
|
+
const isSelfScrollable = /(auto|scroll)/.test(overflow + overflowX + overflowY);
|
|
1703
|
+
container = isSelfScrollable ? el : getScrollParent(el);
|
|
1704
|
+
}
|
|
1705
|
+
const state = {
|
|
1706
|
+
options,
|
|
1707
|
+
container,
|
|
1708
|
+
lastScrollLeft: 0,
|
|
1709
|
+
lastScrollTop: 0,
|
|
1710
|
+
throttleTimer: null,
|
|
1711
|
+
pendingEvent: null,
|
|
1712
|
+
scrollHandler: (e) => {
|
|
1713
|
+
if (options.throttle && options.throttle > 0) {
|
|
1714
|
+
state.pendingEvent = e;
|
|
1715
|
+
if (!state.throttleTimer) {
|
|
1716
|
+
state.throttleTimer = setTimeout(() => {
|
|
1717
|
+
if (state.pendingEvent) {
|
|
1718
|
+
const info = getScrollInfo(container, state.lastScrollLeft, state.lastScrollTop);
|
|
1719
|
+
state.lastScrollLeft = info.scrollLeft;
|
|
1720
|
+
state.lastScrollTop = info.scrollTop;
|
|
1721
|
+
options.handler(state.pendingEvent, info);
|
|
1722
|
+
}
|
|
1723
|
+
state.throttleTimer = null;
|
|
1724
|
+
state.pendingEvent = null;
|
|
1725
|
+
}, options.throttle);
|
|
1726
|
+
}
|
|
1727
|
+
} else {
|
|
1728
|
+
const info = getScrollInfo(container, state.lastScrollLeft, state.lastScrollTop);
|
|
1729
|
+
state.lastScrollLeft = info.scrollLeft;
|
|
1730
|
+
state.lastScrollTop = info.scrollTop;
|
|
1731
|
+
options.handler(e, info);
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
};
|
|
1735
|
+
const initialInfo = getScrollInfo(container, 0, 0);
|
|
1736
|
+
state.lastScrollLeft = initialInfo.scrollLeft;
|
|
1737
|
+
state.lastScrollTop = initialInfo.scrollTop;
|
|
1738
|
+
el.__scroll = state;
|
|
1739
|
+
on(container, "scroll", state.scrollHandler, { passive: options.passive });
|
|
1740
|
+
},
|
|
1741
|
+
updated(el, binding) {
|
|
1742
|
+
const state = el.__scroll;
|
|
1743
|
+
if (!state) return;
|
|
1744
|
+
state.options = normalizeOptions$a(binding.value);
|
|
1745
|
+
},
|
|
1746
|
+
unmounted(el) {
|
|
1747
|
+
const state = el.__scroll;
|
|
1748
|
+
if (!state) return;
|
|
1749
|
+
if (state.throttleTimer) {
|
|
1750
|
+
clearTimeout(state.throttleTimer);
|
|
1751
|
+
}
|
|
1752
|
+
off(state.container, "scroll", state.scrollHandler);
|
|
1753
|
+
delete el.__scroll;
|
|
1754
|
+
}
|
|
1755
|
+
});
|
|
1756
|
+
function normalizeOptions$9(binding) {
|
|
1757
|
+
if (typeof binding === "function") {
|
|
1758
|
+
return { handler: binding, distance: 0, throttle: 200, useIntersection: true };
|
|
1759
|
+
}
|
|
1760
|
+
if (!binding) {
|
|
1761
|
+
throw new Error("[Directix] v-infinite-scroll: handler is required");
|
|
1762
|
+
}
|
|
1763
|
+
return __spreadValues({
|
|
1764
|
+
distance: 0,
|
|
1765
|
+
disabled: false,
|
|
1766
|
+
loading: false,
|
|
1767
|
+
useIntersection: true,
|
|
1768
|
+
throttle: 200
|
|
1769
|
+
}, binding);
|
|
1770
|
+
}
|
|
1771
|
+
const vInfiniteScroll = defineDirective({
|
|
1772
|
+
name: "infinite-scroll",
|
|
1773
|
+
ssr: false,
|
|
1774
|
+
defaults: {
|
|
1775
|
+
distance: 0,
|
|
1776
|
+
disabled: false,
|
|
1777
|
+
loading: false,
|
|
1778
|
+
useIntersection: true,
|
|
1779
|
+
throttle: 200
|
|
1780
|
+
},
|
|
1781
|
+
mounted(el, binding) {
|
|
1782
|
+
const options = normalizeOptions$9(binding.value);
|
|
1783
|
+
if (options.disabled || !isBrowser()) return;
|
|
1784
|
+
let container;
|
|
1785
|
+
if (options.container) {
|
|
1786
|
+
if (typeof options.container === "string") {
|
|
1787
|
+
const found = document.querySelector(options.container);
|
|
1788
|
+
container = found || getScrollParent(el);
|
|
1789
|
+
} else {
|
|
1790
|
+
container = options.container;
|
|
1791
|
+
}
|
|
1792
|
+
} else {
|
|
1793
|
+
container = getScrollParent(el);
|
|
1794
|
+
}
|
|
1795
|
+
const state = {
|
|
1796
|
+
options,
|
|
1797
|
+
container,
|
|
1798
|
+
sentinel: null,
|
|
1799
|
+
observer: null,
|
|
1800
|
+
throttleTimer: null,
|
|
1801
|
+
isLoading: false,
|
|
1802
|
+
scrollHandler: (_e) => __async(null, null, function* () {
|
|
1803
|
+
if (state.isLoading || state.options.disabled || state.options.loading) {
|
|
1804
|
+
return;
|
|
1805
|
+
}
|
|
1806
|
+
if (state.throttleTimer) {
|
|
1807
|
+
return;
|
|
1808
|
+
}
|
|
1809
|
+
state.throttleTimer = setTimeout(() => {
|
|
1810
|
+
state.throttleTimer = null;
|
|
1811
|
+
}, options.throttle);
|
|
1812
|
+
const shouldLoad = checkShouldLoad(container, el, options.distance || 0);
|
|
1813
|
+
if (shouldLoad) {
|
|
1814
|
+
yield triggerLoad(state, el);
|
|
1815
|
+
}
|
|
1816
|
+
})
|
|
1817
|
+
};
|
|
1818
|
+
el.__infiniteScroll = state;
|
|
1819
|
+
if (options.useIntersection && supportsIntersectionObserver()) {
|
|
1820
|
+
setupIntersectionObserver(el, state);
|
|
1821
|
+
} else {
|
|
1822
|
+
on(container, "scroll", state.scrollHandler, { passive: true });
|
|
1823
|
+
}
|
|
1824
|
+
},
|
|
1825
|
+
updated(el, binding) {
|
|
1826
|
+
const state = el.__infiniteScroll;
|
|
1827
|
+
if (!state) return;
|
|
1828
|
+
state.options = normalizeOptions$9(binding.value);
|
|
1829
|
+
},
|
|
1830
|
+
unmounted(el) {
|
|
1831
|
+
const state = el.__infiniteScroll;
|
|
1832
|
+
if (!state) return;
|
|
1833
|
+
if (state.throttleTimer) {
|
|
1834
|
+
clearTimeout(state.throttleTimer);
|
|
1835
|
+
}
|
|
1836
|
+
if (state.observer) {
|
|
1837
|
+
state.observer.disconnect();
|
|
1838
|
+
}
|
|
1839
|
+
if (state.sentinel && state.sentinel.parentNode) {
|
|
1840
|
+
state.sentinel.parentNode.removeChild(state.sentinel);
|
|
1841
|
+
}
|
|
1842
|
+
off(state.container, "scroll", state.scrollHandler);
|
|
1843
|
+
delete el.__infiniteScroll;
|
|
1844
|
+
}
|
|
1845
|
+
});
|
|
1846
|
+
function checkShouldLoad(container, _el, distance) {
|
|
1847
|
+
if (container === window) {
|
|
1848
|
+
const scrollTop2 = window.scrollY || document.documentElement.scrollTop;
|
|
1849
|
+
const scrollHeight2 = document.documentElement.scrollHeight;
|
|
1850
|
+
const clientHeight2 = window.innerHeight;
|
|
1851
|
+
return scrollTop2 + clientHeight2 >= scrollHeight2 - distance;
|
|
1852
|
+
}
|
|
1853
|
+
const el = container;
|
|
1854
|
+
const scrollTop = el.scrollTop;
|
|
1855
|
+
const scrollHeight = el.scrollHeight;
|
|
1856
|
+
const clientHeight = el.clientHeight;
|
|
1857
|
+
return scrollTop + clientHeight >= scrollHeight - distance;
|
|
1858
|
+
}
|
|
1859
|
+
function triggerLoad(state, el) {
|
|
1860
|
+
return __async(this, null, function* () {
|
|
1861
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1862
|
+
state.isLoading = true;
|
|
1863
|
+
(_b = (_a = state.options).onLoadStart) == null ? void 0 : _b.call(_a);
|
|
1864
|
+
el.classList.add("v-infinite-scroll--loading");
|
|
1865
|
+
try {
|
|
1866
|
+
yield state.options.handler();
|
|
1867
|
+
} catch (err) {
|
|
1868
|
+
(_d = (_c = state.options).onError) == null ? void 0 : _d.call(_c, err);
|
|
1869
|
+
} finally {
|
|
1870
|
+
state.isLoading = false;
|
|
1871
|
+
(_f = (_e = state.options).onLoadEnd) == null ? void 0 : _f.call(_e);
|
|
1872
|
+
el.classList.remove("v-infinite-scroll--loading");
|
|
1873
|
+
}
|
|
1874
|
+
});
|
|
1875
|
+
}
|
|
1876
|
+
function setupIntersectionObserver(el, state) {
|
|
1877
|
+
const sentinel = document.createElement("div");
|
|
1878
|
+
sentinel.className = "v-infinite-scroll__sentinel";
|
|
1879
|
+
sentinel.style.cssText = `
|
|
1880
|
+
height: 1px;
|
|
1881
|
+
width: 100%;
|
|
1882
|
+
clear: both;
|
|
1883
|
+
`;
|
|
1884
|
+
el.appendChild(sentinel);
|
|
1885
|
+
state.sentinel = sentinel;
|
|
1886
|
+
state.observer = new IntersectionObserver(
|
|
1887
|
+
(entries) => __async(null, null, function* () {
|
|
1888
|
+
for (const entry of entries) {
|
|
1889
|
+
if (entry.isIntersecting) {
|
|
1890
|
+
if (!state.isLoading && !state.options.disabled && !state.options.loading) {
|
|
1891
|
+
yield triggerLoad(state, el);
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
}),
|
|
1896
|
+
{
|
|
1897
|
+
root: state.container === window ? null : state.container,
|
|
1898
|
+
rootMargin: `${state.options.distance || 0}px`,
|
|
1899
|
+
threshold: 0
|
|
1900
|
+
}
|
|
1901
|
+
);
|
|
1902
|
+
state.observer.observe(sentinel);
|
|
1903
|
+
}
|
|
1904
|
+
const STATE_KEY$2 = "__sticky";
|
|
1905
|
+
function normalizeOptions$8(binding) {
|
|
1906
|
+
if (binding === false) return { disabled: true, top: 0, zIndex: 100 };
|
|
1907
|
+
if (typeof binding === "number") return { top: binding, zIndex: 100 };
|
|
1908
|
+
return __spreadValues({
|
|
1909
|
+
top: 0,
|
|
1910
|
+
zIndex: 100,
|
|
1911
|
+
stickyClass: "v-sticky--fixed",
|
|
1912
|
+
disabled: false
|
|
1913
|
+
}, binding && typeof binding === "object" ? binding : {});
|
|
1914
|
+
}
|
|
1915
|
+
function parseOffset(value) {
|
|
1916
|
+
if (value === void 0) return "0";
|
|
1917
|
+
return typeof value === "number" ? `${value}px` : value;
|
|
1918
|
+
}
|
|
1919
|
+
function getScrollContainer(el, customContainer) {
|
|
1920
|
+
if (customContainer) {
|
|
1921
|
+
if (typeof customContainer === "string") {
|
|
1922
|
+
return document.querySelector(customContainer) || getScrollParent(el);
|
|
1923
|
+
}
|
|
1924
|
+
return customContainer;
|
|
1925
|
+
}
|
|
1926
|
+
const parent = el.parentElement;
|
|
1927
|
+
if (parent) {
|
|
1928
|
+
const { overflow, overflowX, overflowY } = getComputedStyle(parent);
|
|
1929
|
+
if (/(auto|scroll)/.test(overflow + overflowX + overflowY)) {
|
|
1930
|
+
return parent;
|
|
1931
|
+
}
|
|
1932
|
+
}
|
|
1933
|
+
return getScrollParent(el);
|
|
1934
|
+
}
|
|
1935
|
+
function checkSticky(el, state) {
|
|
1936
|
+
if (state.options.disabled) {
|
|
1937
|
+
unsetSticky(el, state);
|
|
1938
|
+
return;
|
|
1939
|
+
}
|
|
1940
|
+
const topOffset = Number.parseFloat(parseOffset(state.options.top));
|
|
1941
|
+
const containerRect = state.container === window ? { top: 0 } : state.container.getBoundingClientRect();
|
|
1942
|
+
const referenceEl = state.placeholder || el;
|
|
1943
|
+
const rect = referenceEl.getBoundingClientRect();
|
|
1944
|
+
const elementTopRelativeToContainer = rect.top - containerRect.top;
|
|
1945
|
+
const shouldSticky = elementTopRelativeToContainer <= topOffset;
|
|
1946
|
+
if (shouldSticky && !state.isSticky) {
|
|
1947
|
+
setSticky(el, state, topOffset, containerRect.top);
|
|
1948
|
+
} else if (!shouldSticky && state.isSticky) {
|
|
1949
|
+
unsetSticky(el, state);
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
function setSticky(el, state, topOffset, containerTop) {
|
|
1953
|
+
var _a, _b, _c;
|
|
1954
|
+
state.isSticky = true;
|
|
1955
|
+
const placeholder = document.createElement("div");
|
|
1956
|
+
placeholder.style.cssText = `width:${el.offsetWidth}px;height:${el.offsetHeight}px`;
|
|
1957
|
+
(_a = el.parentNode) == null ? void 0 : _a.insertBefore(placeholder, el);
|
|
1958
|
+
state.placeholder = placeholder;
|
|
1959
|
+
const fixedTop = state.container === window ? topOffset : containerTop + topOffset;
|
|
1960
|
+
el.style.position = "fixed";
|
|
1961
|
+
el.style.top = `${fixedTop}px`;
|
|
1962
|
+
el.style.zIndex = String(state.options.zIndex || 100);
|
|
1963
|
+
el.style.width = `${el.offsetWidth}px`;
|
|
1964
|
+
if (state.options.bottom !== void 0) {
|
|
1965
|
+
el.style.bottom = parseOffset(state.options.bottom);
|
|
1966
|
+
}
|
|
1967
|
+
state.options.stickyClass && el.classList.add(state.options.stickyClass);
|
|
1968
|
+
el.dispatchEvent(new CustomEvent("sticky:change", { detail: { isSticky: true } }));
|
|
1969
|
+
(_c = (_b = state.options).onChange) == null ? void 0 : _c.call(_b, true);
|
|
1970
|
+
}
|
|
1971
|
+
function unsetSticky(el, state) {
|
|
1972
|
+
var _a, _b, _c, _d;
|
|
1973
|
+
if (!state.isSticky) return;
|
|
1974
|
+
state.isSticky = false;
|
|
1975
|
+
(_b = (_a = state.placeholder) == null ? void 0 : _a.parentNode) == null ? void 0 : _b.removeChild(state.placeholder);
|
|
1976
|
+
state.placeholder = null;
|
|
1977
|
+
Object.assign(el.style, state.originalStyles);
|
|
1978
|
+
state.options.stickyClass && el.classList.remove(state.options.stickyClass);
|
|
1979
|
+
el.dispatchEvent(new CustomEvent("sticky:change", { detail: { isSticky: false } }));
|
|
1980
|
+
(_d = (_c = state.options).onChange) == null ? void 0 : _d.call(_c, false);
|
|
1981
|
+
}
|
|
1982
|
+
const vSticky = defineDirective({
|
|
1983
|
+
name: "sticky",
|
|
1984
|
+
ssr: false,
|
|
1985
|
+
defaults: { top: 0, zIndex: 100, stickyClass: "v-sticky--fixed", disabled: false },
|
|
1986
|
+
mounted(el, binding) {
|
|
1987
|
+
const options = normalizeOptions$8(binding.value);
|
|
1988
|
+
if (options.disabled || !isBrowser()) return;
|
|
1989
|
+
const container = getScrollContainer(el, options.container);
|
|
1990
|
+
const state = {
|
|
1991
|
+
options,
|
|
1992
|
+
placeholder: null,
|
|
1993
|
+
originalStyles: {
|
|
1994
|
+
position: el.style.position,
|
|
1995
|
+
top: el.style.top,
|
|
1996
|
+
bottom: el.style.bottom,
|
|
1997
|
+
zIndex: el.style.zIndex,
|
|
1998
|
+
width: el.style.width
|
|
1999
|
+
},
|
|
2000
|
+
isSticky: false,
|
|
2001
|
+
container,
|
|
2002
|
+
scrollHandler: () => checkSticky(el, state),
|
|
2003
|
+
resizeHandler: () => checkSticky(el, state)
|
|
2004
|
+
};
|
|
2005
|
+
el.classList.add("v-sticky");
|
|
2006
|
+
el[STATE_KEY$2] = state;
|
|
2007
|
+
on(container, "scroll", state.scrollHandler, { passive: true });
|
|
2008
|
+
on(window, "resize", state.resizeHandler, { passive: true });
|
|
2009
|
+
checkSticky(el, state);
|
|
2010
|
+
},
|
|
2011
|
+
updated(el, binding) {
|
|
2012
|
+
const state = el[STATE_KEY$2];
|
|
2013
|
+
if (!state) return;
|
|
2014
|
+
state.options = normalizeOptions$8(binding.value);
|
|
2015
|
+
checkSticky(el, state);
|
|
2016
|
+
},
|
|
2017
|
+
unmounted(el) {
|
|
2018
|
+
var _a, _b;
|
|
2019
|
+
const state = el[STATE_KEY$2];
|
|
2020
|
+
if (!state) return;
|
|
2021
|
+
(_b = (_a = state.placeholder) == null ? void 0 : _a.parentNode) == null ? void 0 : _b.removeChild(state.placeholder);
|
|
2022
|
+
Object.assign(el.style, state.originalStyles);
|
|
2023
|
+
el.classList.remove("v-sticky", state.options.stickyClass || "v-sticky--fixed");
|
|
2024
|
+
off(state.container, "scroll", state.scrollHandler);
|
|
2025
|
+
off(window, "resize", state.resizeHandler);
|
|
2026
|
+
delete el[STATE_KEY$2];
|
|
2027
|
+
}
|
|
2028
|
+
});
|
|
2029
|
+
function normalizeOptions$7(binding) {
|
|
2030
|
+
if (typeof binding === "function") {
|
|
2031
|
+
return { handler: binding, duration: 500, distance: 10 };
|
|
2032
|
+
}
|
|
2033
|
+
if (!binding) {
|
|
2034
|
+
throw new Error("[Directix] v-long-press: handler is required");
|
|
2035
|
+
}
|
|
2036
|
+
return __spreadValues({
|
|
2037
|
+
duration: 500,
|
|
2038
|
+
distance: 10,
|
|
2039
|
+
disabled: false,
|
|
2040
|
+
prevent: true,
|
|
2041
|
+
stop: false,
|
|
2042
|
+
tickInterval: 100
|
|
2043
|
+
}, binding);
|
|
2044
|
+
}
|
|
2045
|
+
function getDistance(p1, p2) {
|
|
2046
|
+
return Math.sqrt(__pow(p2.x - p1.x, 2) + __pow(p2.y - p1.y, 2));
|
|
2047
|
+
}
|
|
2048
|
+
const vLongPress = defineDirective({
|
|
2049
|
+
name: "long-press",
|
|
2050
|
+
ssr: false,
|
|
2051
|
+
defaults: {
|
|
2052
|
+
duration: 500,
|
|
2053
|
+
distance: 10,
|
|
2054
|
+
disabled: false,
|
|
2055
|
+
prevent: true,
|
|
2056
|
+
stop: false,
|
|
2057
|
+
tickInterval: 100
|
|
2058
|
+
},
|
|
2059
|
+
mounted(el, binding) {
|
|
2060
|
+
const options = normalizeOptions$7(binding.value);
|
|
2061
|
+
if (options.disabled || !isBrowser()) return;
|
|
2062
|
+
const state = {
|
|
2063
|
+
options,
|
|
2064
|
+
timerId: null,
|
|
2065
|
+
tickTimerId: null,
|
|
2066
|
+
startTime: 0,
|
|
2067
|
+
startPos: { x: 0, y: 0 },
|
|
2068
|
+
startHandler: () => {
|
|
2069
|
+
},
|
|
2070
|
+
endHandler: () => {
|
|
2071
|
+
},
|
|
2072
|
+
moveHandler: () => {
|
|
2073
|
+
}
|
|
2074
|
+
};
|
|
2075
|
+
state.startHandler = (e) => {
|
|
2076
|
+
var _a;
|
|
2077
|
+
const event = e;
|
|
2078
|
+
if (options.prevent) {
|
|
2079
|
+
event.preventDefault();
|
|
2080
|
+
}
|
|
2081
|
+
if (options.stop) {
|
|
2082
|
+
event.stopPropagation();
|
|
2083
|
+
}
|
|
2084
|
+
if (state.timerId) {
|
|
2085
|
+
clearTimeout(state.timerId);
|
|
2086
|
+
state.timerId = null;
|
|
2087
|
+
}
|
|
2088
|
+
if (state.tickTimerId) {
|
|
2089
|
+
clearInterval(state.tickTimerId);
|
|
2090
|
+
state.tickTimerId = null;
|
|
2091
|
+
}
|
|
2092
|
+
const pos = getEventPosition(event);
|
|
2093
|
+
state.startPos = { x: pos.x, y: pos.y };
|
|
2094
|
+
state.startTime = Date.now();
|
|
2095
|
+
(_a = options.onStart) == null ? void 0 : _a.call(options, event);
|
|
2096
|
+
if (options.onTick) {
|
|
2097
|
+
let remaining = options.duration;
|
|
2098
|
+
state.tickTimerId = setInterval(() => {
|
|
2099
|
+
var _a2;
|
|
2100
|
+
remaining -= options.tickInterval;
|
|
2101
|
+
(_a2 = options.onTick) == null ? void 0 : _a2.call(options, Math.max(0, remaining));
|
|
2102
|
+
}, options.tickInterval);
|
|
2103
|
+
}
|
|
2104
|
+
state.timerId = setTimeout(() => {
|
|
2105
|
+
if (state.tickTimerId) {
|
|
2106
|
+
clearInterval(state.tickTimerId);
|
|
2107
|
+
state.tickTimerId = null;
|
|
2108
|
+
}
|
|
2109
|
+
options.handler(event);
|
|
2110
|
+
}, options.duration);
|
|
2111
|
+
};
|
|
2112
|
+
state.endHandler = (e) => {
|
|
2113
|
+
var _a;
|
|
2114
|
+
const event = e;
|
|
2115
|
+
if (state.timerId) {
|
|
2116
|
+
clearTimeout(state.timerId);
|
|
2117
|
+
state.timerId = null;
|
|
2118
|
+
}
|
|
2119
|
+
if (state.tickTimerId) {
|
|
2120
|
+
clearInterval(state.tickTimerId);
|
|
2121
|
+
state.tickTimerId = null;
|
|
2122
|
+
}
|
|
2123
|
+
if (state.startTime > 0) {
|
|
2124
|
+
(_a = options.onCancel) == null ? void 0 : _a.call(options, event);
|
|
2125
|
+
}
|
|
2126
|
+
state.startTime = 0;
|
|
2127
|
+
};
|
|
2128
|
+
state.moveHandler = (e) => {
|
|
2129
|
+
var _a;
|
|
2130
|
+
if (!state.timerId) return;
|
|
2131
|
+
const event = e;
|
|
2132
|
+
const pos = getEventPosition(event);
|
|
2133
|
+
const distance = getDistance(state.startPos, { x: pos.x, y: pos.y });
|
|
2134
|
+
if (distance > (options.distance || 10)) {
|
|
2135
|
+
if (state.timerId) {
|
|
2136
|
+
clearTimeout(state.timerId);
|
|
2137
|
+
state.timerId = null;
|
|
2138
|
+
}
|
|
2139
|
+
if (state.tickTimerId) {
|
|
2140
|
+
clearInterval(state.tickTimerId);
|
|
2141
|
+
state.tickTimerId = null;
|
|
2142
|
+
}
|
|
2143
|
+
(_a = options.onCancel) == null ? void 0 : _a.call(options, event);
|
|
2144
|
+
state.startTime = 0;
|
|
2145
|
+
}
|
|
2146
|
+
};
|
|
2147
|
+
el.__longPress = state;
|
|
2148
|
+
on(el, "mousedown", state.startHandler);
|
|
2149
|
+
on(el, "mouseup", state.endHandler);
|
|
2150
|
+
on(el, "mouseleave", state.endHandler);
|
|
2151
|
+
on(el, "mousemove", state.moveHandler);
|
|
2152
|
+
on(el, "touchstart", state.startHandler, { passive: !options.prevent });
|
|
2153
|
+
on(el, "touchend", state.endHandler);
|
|
2154
|
+
on(el, "touchcancel", state.endHandler);
|
|
2155
|
+
on(el, "touchmove", state.moveHandler, { passive: true });
|
|
2156
|
+
},
|
|
2157
|
+
updated(el, binding) {
|
|
2158
|
+
const state = el.__longPress;
|
|
2159
|
+
if (!state) {
|
|
2160
|
+
const options = normalizeOptions$7(binding.value);
|
|
2161
|
+
if (!options.disabled) {
|
|
2162
|
+
el.__longPress = null;
|
|
2163
|
+
}
|
|
2164
|
+
return;
|
|
2165
|
+
}
|
|
2166
|
+
state.options = normalizeOptions$7(binding.value);
|
|
2167
|
+
},
|
|
2168
|
+
unmounted(el) {
|
|
2169
|
+
const state = el.__longPress;
|
|
2170
|
+
if (!state) return;
|
|
2171
|
+
if (state.timerId) {
|
|
2172
|
+
clearTimeout(state.timerId);
|
|
2173
|
+
}
|
|
2174
|
+
if (state.tickTimerId) {
|
|
2175
|
+
clearInterval(state.tickTimerId);
|
|
2176
|
+
}
|
|
2177
|
+
off(el, "mousedown", state.startHandler);
|
|
2178
|
+
off(el, "mouseup", state.endHandler);
|
|
2179
|
+
off(el, "mouseleave", state.endHandler);
|
|
2180
|
+
off(el, "mousemove", state.moveHandler);
|
|
2181
|
+
off(el, "touchstart", state.startHandler);
|
|
2182
|
+
off(el, "touchend", state.endHandler);
|
|
2183
|
+
off(el, "touchcancel", state.endHandler);
|
|
2184
|
+
off(el, "touchmove", state.moveHandler);
|
|
2185
|
+
delete el.__longPress;
|
|
2186
|
+
}
|
|
2187
|
+
});
|
|
2188
|
+
function normalizeOptions$6(binding) {
|
|
2189
|
+
if (typeof binding === "function") {
|
|
2190
|
+
return { handler: binding, class: "v-hover" };
|
|
2191
|
+
}
|
|
2192
|
+
return __spreadValues({
|
|
2193
|
+
class: "v-hover",
|
|
2194
|
+
disabled: false,
|
|
2195
|
+
enterDelay: 0,
|
|
2196
|
+
leaveDelay: 0
|
|
2197
|
+
}, binding);
|
|
2198
|
+
}
|
|
2199
|
+
const vHover = defineDirective({
|
|
2200
|
+
name: "hover",
|
|
2201
|
+
ssr: false,
|
|
2202
|
+
defaults: {
|
|
2203
|
+
class: "v-hover",
|
|
2204
|
+
disabled: false,
|
|
2205
|
+
enterDelay: 0,
|
|
2206
|
+
leaveDelay: 0
|
|
2207
|
+
},
|
|
2208
|
+
mounted(el, binding) {
|
|
2209
|
+
const options = normalizeOptions$6(binding.value);
|
|
2210
|
+
if (options.disabled || !isBrowser()) return;
|
|
2211
|
+
const state = {
|
|
2212
|
+
options,
|
|
2213
|
+
isHovering: false,
|
|
2214
|
+
enterTimerId: null,
|
|
2215
|
+
leaveTimerId: null,
|
|
2216
|
+
enterHandler: () => {
|
|
2217
|
+
},
|
|
2218
|
+
leaveHandler: () => {
|
|
2219
|
+
}
|
|
2220
|
+
};
|
|
2221
|
+
state.enterHandler = (e) => {
|
|
2222
|
+
const event = e;
|
|
2223
|
+
if (state.leaveTimerId) {
|
|
2224
|
+
clearTimeout(state.leaveTimerId);
|
|
2225
|
+
state.leaveTimerId = null;
|
|
2226
|
+
}
|
|
2227
|
+
if (state.isHovering) return;
|
|
2228
|
+
if (options.enterDelay && options.enterDelay > 0) {
|
|
2229
|
+
state.enterTimerId = setTimeout(() => {
|
|
2230
|
+
state.isHovering = true;
|
|
2231
|
+
applyHoverState(el, state, event);
|
|
2232
|
+
}, options.enterDelay);
|
|
2233
|
+
} else {
|
|
2234
|
+
state.isHovering = true;
|
|
2235
|
+
applyHoverState(el, state, event);
|
|
2236
|
+
}
|
|
2237
|
+
};
|
|
2238
|
+
state.leaveHandler = (e) => {
|
|
2239
|
+
const event = e;
|
|
2240
|
+
if (state.enterTimerId) {
|
|
2241
|
+
clearTimeout(state.enterTimerId);
|
|
2242
|
+
state.enterTimerId = null;
|
|
2243
|
+
}
|
|
2244
|
+
if (!state.isHovering) return;
|
|
2245
|
+
if (options.leaveDelay && options.leaveDelay > 0) {
|
|
2246
|
+
state.leaveTimerId = setTimeout(() => {
|
|
2247
|
+
state.isHovering = false;
|
|
2248
|
+
applyLeaveState(el, state, event);
|
|
2249
|
+
}, options.leaveDelay);
|
|
2250
|
+
} else {
|
|
2251
|
+
state.isHovering = false;
|
|
2252
|
+
applyLeaveState(el, state, event);
|
|
2253
|
+
}
|
|
2254
|
+
};
|
|
2255
|
+
el.__hover = state;
|
|
2256
|
+
on(el, "mouseenter", state.enterHandler);
|
|
2257
|
+
on(el, "mouseleave", state.leaveHandler);
|
|
2258
|
+
},
|
|
2259
|
+
updated(el, binding) {
|
|
2260
|
+
const state = el.__hover;
|
|
2261
|
+
if (!state) return;
|
|
2262
|
+
const newOptions = normalizeOptions$6(binding.value);
|
|
2263
|
+
if (newOptions.disabled && !state.options.disabled) {
|
|
2264
|
+
el.classList.remove(state.options.class || "v-hover");
|
|
2265
|
+
} else if (!newOptions.disabled && state.options.disabled) ;
|
|
2266
|
+
state.options = newOptions;
|
|
2267
|
+
},
|
|
2268
|
+
unmounted(el) {
|
|
2269
|
+
const state = el.__hover;
|
|
2270
|
+
if (!state) return;
|
|
2271
|
+
if (state.enterTimerId) {
|
|
2272
|
+
clearTimeout(state.enterTimerId);
|
|
2273
|
+
}
|
|
2274
|
+
if (state.leaveTimerId) {
|
|
2275
|
+
clearTimeout(state.leaveTimerId);
|
|
2276
|
+
}
|
|
2277
|
+
off(el, "mouseenter", state.enterHandler);
|
|
2278
|
+
off(el, "mouseleave", state.leaveHandler);
|
|
2279
|
+
el.classList.remove(state.options.class || "v-hover");
|
|
2280
|
+
delete el.__hover;
|
|
2281
|
+
}
|
|
2282
|
+
});
|
|
2283
|
+
function applyHoverState(el, state, e) {
|
|
2284
|
+
var _a, _b;
|
|
2285
|
+
const { options } = state;
|
|
2286
|
+
if (options.class) {
|
|
2287
|
+
el.classList.add(options.class);
|
|
2288
|
+
}
|
|
2289
|
+
el.dispatchEvent(new CustomEvent("hover:enter", { detail: { event: e } }));
|
|
2290
|
+
(_a = options.onEnter) == null ? void 0 : _a.call(options, e);
|
|
2291
|
+
(_b = options.handler) == null ? void 0 : _b.call(options, true, e);
|
|
2292
|
+
}
|
|
2293
|
+
function applyLeaveState(el, state, e) {
|
|
2294
|
+
var _a, _b;
|
|
2295
|
+
const { options } = state;
|
|
2296
|
+
if (options.class) {
|
|
2297
|
+
el.classList.remove(options.class);
|
|
2298
|
+
}
|
|
2299
|
+
el.dispatchEvent(new CustomEvent("hover:leave", { detail: { event: e } }));
|
|
2300
|
+
(_a = options.onLeave) == null ? void 0 : _a.call(options, e);
|
|
2301
|
+
(_b = options.handler) == null ? void 0 : _b.call(options, false, e);
|
|
2302
|
+
}
|
|
2303
|
+
function normalizeOptions$5(binding) {
|
|
2304
|
+
if (binding === false) {
|
|
2305
|
+
return { disabled: true, color: "currentColor", duration: 600 };
|
|
2306
|
+
}
|
|
2307
|
+
if (typeof binding === "string") {
|
|
2308
|
+
return { color: binding, duration: 600 };
|
|
2309
|
+
}
|
|
2310
|
+
const base = {
|
|
2311
|
+
color: "currentColor",
|
|
2312
|
+
duration: 600,
|
|
2313
|
+
disabled: false,
|
|
2314
|
+
initialScale: 0,
|
|
2315
|
+
finalScale: 2
|
|
2316
|
+
};
|
|
2317
|
+
return binding && typeof binding === "object" ? __spreadValues(__spreadValues({}, base), binding) : base;
|
|
2318
|
+
}
|
|
2319
|
+
function createRipple(event, el, options) {
|
|
2320
|
+
const rect = el.getBoundingClientRect();
|
|
2321
|
+
const x = event.clientX - rect.left;
|
|
2322
|
+
const y = event.clientY - rect.top;
|
|
2323
|
+
const size = Math.max(rect.width, rect.height) * 2;
|
|
2324
|
+
const ripple = document.createElement("span");
|
|
2325
|
+
ripple.className = "v-ripple__wave";
|
|
2326
|
+
ripple.style.cssText = `
|
|
2327
|
+
position: absolute;
|
|
2328
|
+
border-radius: 50%;
|
|
2329
|
+
pointer-events: none;
|
|
2330
|
+
background-color: ${options.color};
|
|
2331
|
+
width: ${size}px;
|
|
2332
|
+
height: ${size}px;
|
|
2333
|
+
left: ${x - size / 2}px;
|
|
2334
|
+
top: ${y - size / 2}px;
|
|
2335
|
+
transform: scale(${options.initialScale});
|
|
2336
|
+
opacity: 0.3;
|
|
2337
|
+
z-index: 0;
|
|
2338
|
+
`;
|
|
2339
|
+
return ripple;
|
|
2340
|
+
}
|
|
2341
|
+
function animateRipple(ripple, options) {
|
|
2342
|
+
const duration = options.duration || 600;
|
|
2343
|
+
const initialScale = options.initialScale || 0;
|
|
2344
|
+
const finalScale = options.finalScale || 2;
|
|
2345
|
+
if (typeof ripple.animate === "function") {
|
|
2346
|
+
ripple.animate(
|
|
2347
|
+
[
|
|
2348
|
+
{ transform: `scale(${initialScale})`, opacity: 0.3 },
|
|
2349
|
+
{ transform: `scale(${finalScale})`, opacity: 0 }
|
|
2350
|
+
],
|
|
2351
|
+
{
|
|
2352
|
+
duration,
|
|
2353
|
+
easing: "ease-out",
|
|
2354
|
+
fill: "forwards"
|
|
2355
|
+
}
|
|
2356
|
+
).onfinish = () => {
|
|
2357
|
+
ripple.remove();
|
|
2358
|
+
};
|
|
2359
|
+
} else {
|
|
2360
|
+
ripple.style.transition = `transform ${duration}ms ease-out, opacity ${duration}ms ease-out`;
|
|
2361
|
+
String(ripple.offsetHeight);
|
|
2362
|
+
ripple.style.transform = `scale(${finalScale})`;
|
|
2363
|
+
ripple.style.opacity = "0";
|
|
2364
|
+
setTimeout(() => {
|
|
2365
|
+
ripple.remove();
|
|
2366
|
+
}, duration);
|
|
2367
|
+
}
|
|
2368
|
+
}
|
|
2369
|
+
const vRipple = defineDirective({
|
|
2370
|
+
name: "ripple",
|
|
2371
|
+
ssr: false,
|
|
2372
|
+
defaults: {
|
|
2373
|
+
color: "currentColor",
|
|
2374
|
+
duration: 600,
|
|
2375
|
+
disabled: false,
|
|
2376
|
+
initialScale: 0,
|
|
2377
|
+
finalScale: 2
|
|
2378
|
+
},
|
|
2379
|
+
mounted(el, binding) {
|
|
2380
|
+
const options = normalizeOptions$5(binding.value);
|
|
2381
|
+
if (options.disabled || !isBrowser()) return;
|
|
2382
|
+
const computedStyle = getComputedStyle(el);
|
|
2383
|
+
if (computedStyle.position === "static") {
|
|
2384
|
+
el.style.position = "relative";
|
|
2385
|
+
}
|
|
2386
|
+
if (computedStyle.overflow === "visible") {
|
|
2387
|
+
el.style.overflow = "hidden";
|
|
2388
|
+
}
|
|
2389
|
+
el.classList.add("v-ripple");
|
|
2390
|
+
const state = {
|
|
2391
|
+
options,
|
|
2392
|
+
clickHandler: (e) => {
|
|
2393
|
+
if (state.options.disabled) return;
|
|
2394
|
+
const mouseEvent = e;
|
|
2395
|
+
const ripple = createRipple(mouseEvent, el, state.options);
|
|
2396
|
+
if (ripple) {
|
|
2397
|
+
el.appendChild(ripple);
|
|
2398
|
+
animateRipple(ripple, state.options);
|
|
2399
|
+
}
|
|
2400
|
+
}
|
|
2401
|
+
};
|
|
2402
|
+
el.__ripple = state;
|
|
2403
|
+
on(el, "click", state.clickHandler);
|
|
2404
|
+
},
|
|
2405
|
+
updated(el, binding) {
|
|
2406
|
+
const state = el.__ripple;
|
|
2407
|
+
if (!state) return;
|
|
2408
|
+
state.options = normalizeOptions$5(binding.value);
|
|
2409
|
+
},
|
|
2410
|
+
unmounted(el) {
|
|
2411
|
+
const state = el.__ripple;
|
|
2412
|
+
if (!state) return;
|
|
2413
|
+
off(el, "click", state.clickHandler);
|
|
2414
|
+
el.classList.remove("v-ripple");
|
|
2415
|
+
delete el.__ripple;
|
|
2416
|
+
}
|
|
2417
|
+
});
|
|
2418
|
+
const STATE_KEY$1 = "__mask";
|
|
2419
|
+
const TOKEN_PATTERNS = {
|
|
2420
|
+
"#": /\d/,
|
|
2421
|
+
A: /[A-Za-z]/,
|
|
2422
|
+
N: /[A-Za-z0-9]/,
|
|
2423
|
+
X: /./
|
|
2424
|
+
};
|
|
2425
|
+
function parseMask(mask, placeholder) {
|
|
2426
|
+
return [...mask].map((char) => {
|
|
2427
|
+
const pattern = TOKEN_PATTERNS[char];
|
|
2428
|
+
return pattern ? { pattern, placeholder, isLiteral: false } : { pattern: new RegExp(`\\${char}`), placeholder: char, isLiteral: true };
|
|
2429
|
+
});
|
|
2430
|
+
}
|
|
2431
|
+
function normalizeOptions$4(binding) {
|
|
2432
|
+
if (typeof binding === "string") return { mask: binding, placeholder: "_", showPlaceholder: true };
|
|
2433
|
+
if (!(binding == null ? void 0 : binding.mask)) throw new Error("[Directix] v-mask: mask is required");
|
|
2434
|
+
return __spreadValues({ placeholder: "_", showPlaceholder: true, showMaskOnBlur: false, clearIncomplete: false, disabled: false }, binding);
|
|
2435
|
+
}
|
|
2436
|
+
function isInput(el) {
|
|
2437
|
+
return el.tagName === "INPUT" || el.tagName === "TEXTAREA";
|
|
2438
|
+
}
|
|
2439
|
+
function formatValue(value, tokens, placeholder, showPlaceholder) {
|
|
2440
|
+
let result = "", valueIndex = 0;
|
|
2441
|
+
for (const token of tokens) {
|
|
2442
|
+
if (valueIndex >= value.length) {
|
|
2443
|
+
result += token.isLiteral ? token.placeholder : showPlaceholder ? placeholder : "";
|
|
2444
|
+
continue;
|
|
2445
|
+
}
|
|
2446
|
+
const inputChar = value[valueIndex];
|
|
2447
|
+
if (token.isLiteral) {
|
|
2448
|
+
if (inputChar === token.placeholder) valueIndex++;
|
|
2449
|
+
result += token.placeholder;
|
|
2450
|
+
} else if (token.pattern.test(inputChar)) {
|
|
2451
|
+
result += inputChar;
|
|
2452
|
+
valueIndex++;
|
|
2453
|
+
} else if (inputChar === placeholder) {
|
|
2454
|
+
result += showPlaceholder ? placeholder : "";
|
|
2455
|
+
valueIndex++;
|
|
2456
|
+
} else {
|
|
2457
|
+
valueIndex++;
|
|
2458
|
+
}
|
|
2459
|
+
}
|
|
2460
|
+
return result;
|
|
2461
|
+
}
|
|
2462
|
+
function getRawValue(value, tokens, placeholder) {
|
|
2463
|
+
let raw = "";
|
|
2464
|
+
for (let i = 0; i < value.length && i < tokens.length; i++) {
|
|
2465
|
+
if (!tokens[i].isLiteral && value[i] !== placeholder) {
|
|
2466
|
+
raw += value[i];
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
return raw;
|
|
2470
|
+
}
|
|
2471
|
+
function isComplete(value, tokens, placeholder) {
|
|
2472
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
2473
|
+
if (!tokens[i].isLiteral && (i >= value.length || value[i] === placeholder)) {
|
|
2474
|
+
return false;
|
|
2475
|
+
}
|
|
2476
|
+
}
|
|
2477
|
+
return true;
|
|
2478
|
+
}
|
|
2479
|
+
function getCursorPos(tokens, rawCursorPos) {
|
|
2480
|
+
let pos = rawCursorPos;
|
|
2481
|
+
while (pos < tokens.length && tokens[pos].isLiteral) {
|
|
2482
|
+
pos++;
|
|
2483
|
+
}
|
|
2484
|
+
return Math.min(pos, tokens.length);
|
|
2485
|
+
}
|
|
2486
|
+
const vMask = defineDirective({
|
|
2487
|
+
name: "mask",
|
|
2488
|
+
ssr: false,
|
|
2489
|
+
defaults: { placeholder: "_", showPlaceholder: true, showMaskOnBlur: false, clearIncomplete: false, disabled: false },
|
|
2490
|
+
mounted(el, binding) {
|
|
2491
|
+
var _a;
|
|
2492
|
+
if (!isInput(el)) {
|
|
2493
|
+
console.warn("[Directix] v-mask: directive must be used on input or textarea elements");
|
|
2494
|
+
return;
|
|
2495
|
+
}
|
|
2496
|
+
const options = normalizeOptions$4(binding.value);
|
|
2497
|
+
if (options.disabled || !isBrowser()) return;
|
|
2498
|
+
const placeholder = options.placeholder || "_";
|
|
2499
|
+
const tokens = parseMask(options.mask, placeholder);
|
|
2500
|
+
const inputHandler = (e) => {
|
|
2501
|
+
var _a2, _b, _c;
|
|
2502
|
+
const target = e.target;
|
|
2503
|
+
const rawValue = target.value;
|
|
2504
|
+
const cursorPos = target.selectionStart || 0;
|
|
2505
|
+
const formatted = formatValue(rawValue, tokens, placeholder, (_a2 = options.showPlaceholder) != null ? _a2 : true);
|
|
2506
|
+
if (formatted !== rawValue) {
|
|
2507
|
+
target.value = formatted;
|
|
2508
|
+
target.setSelectionRange(getCursorPos(tokens, cursorPos), getCursorPos(tokens, cursorPos));
|
|
2509
|
+
target.dispatchEvent(new Event("input", { bubbles: true }));
|
|
2510
|
+
return;
|
|
2511
|
+
}
|
|
2512
|
+
(_b = options.onChange) == null ? void 0 : _b.call(options, formatted, getRawValue(formatted, tokens, placeholder));
|
|
2513
|
+
if (isComplete(formatted, tokens, placeholder)) {
|
|
2514
|
+
(_c = options.onComplete) == null ? void 0 : _c.call(options, formatted);
|
|
2515
|
+
}
|
|
2516
|
+
};
|
|
2517
|
+
const focusHandler = () => {
|
|
2518
|
+
if (!el.value && options.showPlaceholder) {
|
|
2519
|
+
el.value = formatValue("", tokens, placeholder, true);
|
|
2520
|
+
}
|
|
2521
|
+
};
|
|
2522
|
+
const blurHandler = () => {
|
|
2523
|
+
if (!options.showMaskOnBlur && !isComplete(el.value, tokens, placeholder) && options.clearIncomplete) {
|
|
2524
|
+
el.value = "";
|
|
2525
|
+
}
|
|
2526
|
+
};
|
|
2527
|
+
on(el, "input", inputHandler);
|
|
2528
|
+
on(el, "focus", focusHandler);
|
|
2529
|
+
on(el, "blur", blurHandler);
|
|
2530
|
+
el[STATE_KEY$1] = { options, tokens, placeholder, inputHandler, focusHandler, blurHandler };
|
|
2531
|
+
if (el.value) {
|
|
2532
|
+
el.value = formatValue(el.value, tokens, placeholder, (_a = options.showPlaceholder) != null ? _a : true);
|
|
2533
|
+
}
|
|
2534
|
+
},
|
|
2535
|
+
updated(el, binding) {
|
|
2536
|
+
const state = el[STATE_KEY$1];
|
|
2537
|
+
if (!state) return;
|
|
2538
|
+
state.options = normalizeOptions$4(binding.value);
|
|
2539
|
+
state.tokens = parseMask(state.options.mask, state.placeholder);
|
|
2540
|
+
},
|
|
2541
|
+
unmounted(el) {
|
|
2542
|
+
const state = el[STATE_KEY$1];
|
|
2543
|
+
if (!state) return;
|
|
2544
|
+
off(el, "input", state.inputHandler);
|
|
2545
|
+
off(el, "focus", state.focusHandler);
|
|
2546
|
+
off(el, "blur", state.blurHandler);
|
|
2547
|
+
delete el[STATE_KEY$1];
|
|
2548
|
+
}
|
|
2549
|
+
});
|
|
2550
|
+
const STATE_KEY = "__permission";
|
|
2551
|
+
const WILDCARD = "*";
|
|
2552
|
+
let globalConfig = null;
|
|
2553
|
+
function configurePermission(config) {
|
|
2554
|
+
globalConfig = config;
|
|
2555
|
+
}
|
|
2556
|
+
function getPermissionConfig() {
|
|
2557
|
+
return globalConfig;
|
|
2558
|
+
}
|
|
2559
|
+
function normalizeOptions$3(binding) {
|
|
2560
|
+
if (!binding) {
|
|
2561
|
+
throw new Error("[Directix] v-permission: permission value is required");
|
|
2562
|
+
}
|
|
2563
|
+
if (typeof binding === "string") {
|
|
2564
|
+
return { value: binding };
|
|
2565
|
+
}
|
|
2566
|
+
if (Array.isArray(binding)) {
|
|
2567
|
+
return { value: binding };
|
|
2568
|
+
}
|
|
2569
|
+
return binding;
|
|
2570
|
+
}
|
|
2571
|
+
function hasPermission(required, permissions) {
|
|
2572
|
+
return permissions.includes(WILDCARD) || permissions.includes(required);
|
|
2573
|
+
}
|
|
2574
|
+
function verifyPermission(options) {
|
|
2575
|
+
var _a;
|
|
2576
|
+
if (options.check) {
|
|
2577
|
+
return options.check(options.value, options.mode || "some");
|
|
2578
|
+
}
|
|
2579
|
+
if (!globalConfig) {
|
|
2580
|
+
console.warn("[Directix] v-permission: No permission config provided");
|
|
2581
|
+
return true;
|
|
2582
|
+
}
|
|
2583
|
+
const permissions = globalConfig.getPermissions();
|
|
2584
|
+
const roles = ((_a = globalConfig.getRoles) == null ? void 0 : _a.call(globalConfig)) || [];
|
|
2585
|
+
const roleMap = globalConfig.roleMap || {};
|
|
2586
|
+
const required = Array.isArray(options.value) ? options.value : [options.value];
|
|
2587
|
+
const mode = options.mode || "some";
|
|
2588
|
+
function checkSingle(value) {
|
|
2589
|
+
if (value in roleMap) {
|
|
2590
|
+
return roles.includes(value);
|
|
2591
|
+
}
|
|
2592
|
+
if (hasPermission(value, permissions)) {
|
|
2593
|
+
return true;
|
|
2594
|
+
}
|
|
2595
|
+
for (const role of roles) {
|
|
2596
|
+
const rolePermissions = roleMap[role] || [];
|
|
2597
|
+
if (hasPermission(value, rolePermissions)) {
|
|
2598
|
+
return true;
|
|
2599
|
+
}
|
|
2600
|
+
}
|
|
2601
|
+
return false;
|
|
2602
|
+
}
|
|
2603
|
+
return mode === "every" ? required.every(checkSingle) : required.some(checkSingle);
|
|
2604
|
+
}
|
|
2605
|
+
function handleDenied(el, action, state) {
|
|
2606
|
+
var _a, _b;
|
|
2607
|
+
switch (action) {
|
|
2608
|
+
case "remove":
|
|
2609
|
+
state.parentNode = el.parentNode;
|
|
2610
|
+
state.placeholder = document.createComment("v-permission");
|
|
2611
|
+
(_a = el.parentNode) == null ? void 0 : _a.insertBefore(state.placeholder, el);
|
|
2612
|
+
(_b = el.parentNode) == null ? void 0 : _b.removeChild(el);
|
|
2613
|
+
break;
|
|
2614
|
+
case "disable":
|
|
2615
|
+
state.originalDisabled = el.getAttribute("disabled") || false;
|
|
2616
|
+
el.setAttribute("disabled", "true");
|
|
2617
|
+
el.classList.add("v-permission--disabled");
|
|
2618
|
+
break;
|
|
2619
|
+
case "hide":
|
|
2620
|
+
state.originalDisplay = el.style.display;
|
|
2621
|
+
el.style.display = "none";
|
|
2622
|
+
el.classList.add("v-permission--hidden");
|
|
2623
|
+
break;
|
|
2624
|
+
}
|
|
2625
|
+
}
|
|
2626
|
+
function handleGranted(el, action, state) {
|
|
2627
|
+
switch (action) {
|
|
2628
|
+
case "remove":
|
|
2629
|
+
if (state.placeholder && state.parentNode) {
|
|
2630
|
+
state.parentNode.insertBefore(el, state.placeholder);
|
|
2631
|
+
state.parentNode.removeChild(state.placeholder);
|
|
2632
|
+
state.placeholder = null;
|
|
2633
|
+
}
|
|
2634
|
+
break;
|
|
2635
|
+
case "disable":
|
|
2636
|
+
if (state.originalDisabled === false) {
|
|
2637
|
+
el.removeAttribute("disabled");
|
|
2638
|
+
} else if (state.originalDisabled) {
|
|
2639
|
+
el.setAttribute("disabled", state.originalDisabled);
|
|
2640
|
+
}
|
|
2641
|
+
el.classList.remove("v-permission--disabled");
|
|
2642
|
+
break;
|
|
2643
|
+
case "hide":
|
|
2644
|
+
el.style.display = state.originalDisplay || "";
|
|
2645
|
+
el.classList.remove("v-permission--hidden");
|
|
2646
|
+
break;
|
|
2647
|
+
}
|
|
2648
|
+
}
|
|
2649
|
+
function getState(el) {
|
|
2650
|
+
if (!el[STATE_KEY]) {
|
|
2651
|
+
el[STATE_KEY] = {
|
|
2652
|
+
options: { value: "" },
|
|
2653
|
+
originalDisplay: "",
|
|
2654
|
+
originalDisabled: false,
|
|
2655
|
+
parentNode: null,
|
|
2656
|
+
placeholder: null
|
|
2657
|
+
};
|
|
2658
|
+
}
|
|
2659
|
+
return el[STATE_KEY];
|
|
2660
|
+
}
|
|
2661
|
+
function checkPermission(el, binding) {
|
|
2662
|
+
var _a, _b;
|
|
2663
|
+
const state = getState(el);
|
|
2664
|
+
state.options = normalizeOptions$3(binding.value);
|
|
2665
|
+
const granted = verifyPermission(state.options);
|
|
2666
|
+
(_b = (_a = state.options).onChange) == null ? void 0 : _b.call(_a, granted);
|
|
2667
|
+
const action = state.options.action || "remove";
|
|
2668
|
+
if (granted) {
|
|
2669
|
+
handleGranted(el, action, state);
|
|
2670
|
+
} else {
|
|
2671
|
+
handleDenied(el, action, state);
|
|
2672
|
+
}
|
|
2673
|
+
}
|
|
2674
|
+
function cleanup(el) {
|
|
2675
|
+
const state = el[STATE_KEY];
|
|
2676
|
+
if ((state == null ? void 0 : state.placeholder) && state.parentNode) {
|
|
2677
|
+
state.parentNode.removeChild(state.placeholder);
|
|
2678
|
+
}
|
|
2679
|
+
delete el[STATE_KEY];
|
|
2680
|
+
}
|
|
2681
|
+
const vPermission = defineDirective({
|
|
2682
|
+
name: "permission",
|
|
2683
|
+
ssr: true,
|
|
2684
|
+
mounted(el, binding) {
|
|
2685
|
+
checkPermission(el, binding);
|
|
2686
|
+
},
|
|
2687
|
+
updated(el, binding) {
|
|
2688
|
+
checkPermission(el, binding);
|
|
2689
|
+
},
|
|
2690
|
+
unmounted(el) {
|
|
2691
|
+
cleanup(el);
|
|
2692
|
+
}
|
|
2693
|
+
});
|
|
2694
|
+
const DEFAULT_ALLOWED_TAGS = ["b", "i", "u", "strong", "em", "br", "p", "span", "div"];
|
|
2695
|
+
const DEFAULT_ALLOWED_ATTRIBUTES = ["title", "alt", "href", "src"];
|
|
2696
|
+
const DANGEROUS_TAGS = ["script", "iframe", "object", "embed", "form", "input", "style", "link", "meta", "base"];
|
|
2697
|
+
const DANGEROUS_ATTRIBUTES = ["onclick", "onerror", "onload", "onmouseover", "onfocus", "onblur", "onchange", "onsubmit"];
|
|
2698
|
+
function normalizeOptions$2(binding) {
|
|
2699
|
+
if (binding === false) {
|
|
2700
|
+
return { disabled: true };
|
|
2701
|
+
}
|
|
2702
|
+
if (binding === true) {
|
|
2703
|
+
return {
|
|
2704
|
+
allowedTags: DEFAULT_ALLOWED_TAGS,
|
|
2705
|
+
allowedAttributes: DEFAULT_ALLOWED_ATTRIBUTES
|
|
2706
|
+
};
|
|
2707
|
+
}
|
|
2708
|
+
return __spreadValues({
|
|
2709
|
+
allowedTags: DEFAULT_ALLOWED_TAGS,
|
|
2710
|
+
allowedAttributes: DEFAULT_ALLOWED_ATTRIBUTES,
|
|
2711
|
+
allowDataUrls: false,
|
|
2712
|
+
allowStyles: false,
|
|
2713
|
+
allowClass: false,
|
|
2714
|
+
allowId: false,
|
|
2715
|
+
disabled: false,
|
|
2716
|
+
sanitizeOnUpdate: true
|
|
2717
|
+
}, binding);
|
|
2718
|
+
}
|
|
2719
|
+
function sanitizeHtml(html, options) {
|
|
2720
|
+
var _a;
|
|
2721
|
+
if (options.handler) {
|
|
2722
|
+
return options.handler(html);
|
|
2723
|
+
}
|
|
2724
|
+
const temp = document.createElement("div");
|
|
2725
|
+
temp.innerHTML = html;
|
|
2726
|
+
for (const tag of DANGEROUS_TAGS) {
|
|
2727
|
+
const elements = temp.getElementsByTagName(tag);
|
|
2728
|
+
while (elements.length > 0) {
|
|
2729
|
+
(_a = elements[0].parentNode) == null ? void 0 : _a.removeChild(elements[0]);
|
|
2730
|
+
}
|
|
2731
|
+
}
|
|
2732
|
+
const processElement = (el) => {
|
|
2733
|
+
var _a2;
|
|
2734
|
+
const tagName = el.tagName.toLowerCase();
|
|
2735
|
+
if (options.allowedTags && !options.allowedTags.includes(tagName)) {
|
|
2736
|
+
const text = document.createTextNode(el.textContent || "");
|
|
2737
|
+
(_a2 = el.parentNode) == null ? void 0 : _a2.replaceChild(text, el);
|
|
2738
|
+
return;
|
|
2739
|
+
}
|
|
2740
|
+
for (const attr of DANGEROUS_ATTRIBUTES) {
|
|
2741
|
+
el.removeAttribute(attr);
|
|
2742
|
+
}
|
|
2743
|
+
const href = el.getAttribute("href");
|
|
2744
|
+
if (href && href.toLowerCase().startsWith("javascript:")) {
|
|
2745
|
+
el.removeAttribute("href");
|
|
2746
|
+
}
|
|
2747
|
+
if (!options.allowDataUrls) {
|
|
2748
|
+
const src = el.getAttribute("src");
|
|
2749
|
+
if (src && src.toLowerCase().startsWith("data:")) {
|
|
2750
|
+
el.removeAttribute("src");
|
|
2751
|
+
}
|
|
2752
|
+
}
|
|
2753
|
+
if (options.allowedAttributes) {
|
|
2754
|
+
const attrs = Array.from(el.attributes);
|
|
2755
|
+
for (const attr of attrs) {
|
|
2756
|
+
const isAllowed = options.allowedAttributes.includes(attr.name.toLowerCase());
|
|
2757
|
+
const isClass = attr.name === "class" && options.allowClass;
|
|
2758
|
+
const isId = attr.name === "id" && options.allowId;
|
|
2759
|
+
const isStyle = attr.name === "style" && options.allowStyles;
|
|
2760
|
+
if (!isAllowed && !isClass && !isId && !isStyle) {
|
|
2761
|
+
el.removeAttribute(attr.name);
|
|
2762
|
+
}
|
|
2763
|
+
}
|
|
2764
|
+
}
|
|
2765
|
+
for (const child of Array.from(el.children)) {
|
|
2766
|
+
processElement(child);
|
|
2767
|
+
}
|
|
2768
|
+
};
|
|
2769
|
+
for (const child of Array.from(temp.children)) {
|
|
2770
|
+
processElement(child);
|
|
2771
|
+
}
|
|
2772
|
+
return temp.innerHTML;
|
|
2773
|
+
}
|
|
2774
|
+
const vSanitize = defineDirective({
|
|
2775
|
+
name: "sanitize",
|
|
2776
|
+
ssr: true,
|
|
2777
|
+
defaults: {
|
|
2778
|
+
allowedTags: DEFAULT_ALLOWED_TAGS,
|
|
2779
|
+
allowedAttributes: DEFAULT_ALLOWED_ATTRIBUTES,
|
|
2780
|
+
allowDataUrls: false,
|
|
2781
|
+
allowStyles: false,
|
|
2782
|
+
allowClass: false,
|
|
2783
|
+
allowId: false,
|
|
2784
|
+
disabled: false,
|
|
2785
|
+
sanitizeOnUpdate: true
|
|
2786
|
+
},
|
|
2787
|
+
mounted(el, binding) {
|
|
2788
|
+
if (!isBrowser()) return;
|
|
2789
|
+
const options = normalizeOptions$2(binding.value);
|
|
2790
|
+
if (options.disabled) return;
|
|
2791
|
+
el.__sanitize = { options };
|
|
2792
|
+
const content = el.innerHTML;
|
|
2793
|
+
if (content) {
|
|
2794
|
+
el.innerHTML = sanitizeHtml(content, options);
|
|
2795
|
+
}
|
|
2796
|
+
},
|
|
2797
|
+
updated(el, binding) {
|
|
2798
|
+
const state = el.__sanitize;
|
|
2799
|
+
if (!state) return;
|
|
2800
|
+
state.options = normalizeOptions$2(binding.value);
|
|
2801
|
+
if (state.options.disabled || !state.options.sanitizeOnUpdate) return;
|
|
2802
|
+
const content = el.innerHTML;
|
|
2803
|
+
if (content) {
|
|
2804
|
+
el.innerHTML = sanitizeHtml(content, state.options);
|
|
2805
|
+
}
|
|
2806
|
+
},
|
|
2807
|
+
unmounted(el) {
|
|
2808
|
+
delete el.__sanitize;
|
|
2809
|
+
}
|
|
2810
|
+
});
|
|
2811
|
+
function getResizeInfo(entry) {
|
|
2812
|
+
return {
|
|
2813
|
+
width: entry.contentRect.width,
|
|
2814
|
+
height: entry.contentRect.height,
|
|
2815
|
+
contentRect: entry.contentRect,
|
|
2816
|
+
borderBoxSize: entry.borderBoxSize,
|
|
2817
|
+
contentBoxSize: entry.contentBoxSize,
|
|
2818
|
+
devicePixelContentBoxSize: entry.devicePixelContentBoxSize
|
|
2819
|
+
};
|
|
2820
|
+
}
|
|
2821
|
+
function normalizeOptions$1(binding) {
|
|
2822
|
+
if (typeof binding === "function") {
|
|
2823
|
+
return { handler: binding };
|
|
2824
|
+
}
|
|
2825
|
+
if (!binding) {
|
|
2826
|
+
throw new Error("[Directix] v-resize: handler is required");
|
|
2827
|
+
}
|
|
2828
|
+
return __spreadValues({
|
|
2829
|
+
disabled: false,
|
|
2830
|
+
box: "content-box",
|
|
2831
|
+
debounce: 0
|
|
2832
|
+
}, binding);
|
|
2833
|
+
}
|
|
2834
|
+
function createFallbackResize(el, callback) {
|
|
2835
|
+
const iframe = document.createElement("iframe");
|
|
2836
|
+
iframe.style.cssText = `
|
|
2837
|
+
position: absolute;
|
|
2838
|
+
top: 0;
|
|
2839
|
+
left: 0;
|
|
2840
|
+
width: 100%;
|
|
2841
|
+
height: 100%;
|
|
2842
|
+
border: none;
|
|
2843
|
+
pointer-events: none;
|
|
2844
|
+
opacity: 0;
|
|
2845
|
+
`;
|
|
2846
|
+
el.appendChild(iframe);
|
|
2847
|
+
const iWindow = iframe.contentWindow;
|
|
2848
|
+
if (iWindow) {
|
|
2849
|
+
iWindow.addEventListener("resize", callback);
|
|
2850
|
+
}
|
|
2851
|
+
return {
|
|
2852
|
+
iframe,
|
|
2853
|
+
cleanup: () => {
|
|
2854
|
+
if (iWindow) {
|
|
2855
|
+
iWindow.removeEventListener("resize", callback);
|
|
2856
|
+
}
|
|
2857
|
+
iframe.remove();
|
|
2858
|
+
}
|
|
2859
|
+
};
|
|
2860
|
+
}
|
|
2861
|
+
const vResize = defineDirective({
|
|
2862
|
+
name: "resize",
|
|
2863
|
+
ssr: false,
|
|
2864
|
+
defaults: {
|
|
2865
|
+
disabled: false,
|
|
2866
|
+
box: "content-box",
|
|
2867
|
+
debounce: 0
|
|
2868
|
+
},
|
|
2869
|
+
mounted(el, binding) {
|
|
2870
|
+
const options = normalizeOptions$1(binding.value);
|
|
2871
|
+
if (options.disabled || !isBrowser()) return;
|
|
2872
|
+
const computedStyle = getComputedStyle(el);
|
|
2873
|
+
if (computedStyle.position === "static") {
|
|
2874
|
+
el.style.position = "relative";
|
|
2875
|
+
}
|
|
2876
|
+
const state = {
|
|
2877
|
+
options,
|
|
2878
|
+
observer: null,
|
|
2879
|
+
debounceTimer: null,
|
|
2880
|
+
pendingEntry: null,
|
|
2881
|
+
fallbackIframe: null,
|
|
2882
|
+
handler: (entry) => {
|
|
2883
|
+
if (options.debounce && options.debounce > 0) {
|
|
2884
|
+
state.pendingEntry = entry;
|
|
2885
|
+
if (!state.debounceTimer) {
|
|
2886
|
+
state.debounceTimer = setTimeout(() => {
|
|
2887
|
+
if (state.pendingEntry) {
|
|
2888
|
+
options.handler(state.pendingEntry);
|
|
2889
|
+
}
|
|
2890
|
+
state.debounceTimer = null;
|
|
2891
|
+
state.pendingEntry = null;
|
|
2892
|
+
}, options.debounce);
|
|
2893
|
+
}
|
|
2894
|
+
} else {
|
|
2895
|
+
options.handler(entry);
|
|
2896
|
+
}
|
|
2897
|
+
}
|
|
2898
|
+
};
|
|
2899
|
+
el.__resize = state;
|
|
2900
|
+
if (supportsResizeObserver()) {
|
|
2901
|
+
state.observer = new ResizeObserver((entries) => {
|
|
2902
|
+
for (const entry of entries) {
|
|
2903
|
+
state.handler(entry);
|
|
2904
|
+
}
|
|
2905
|
+
});
|
|
2906
|
+
state.observer.observe(el, { box: options.box });
|
|
2907
|
+
} else {
|
|
2908
|
+
console.warn("[Directix] v-resize: ResizeObserver not supported, using fallback");
|
|
2909
|
+
const { iframe, cleanup: cleanup2 } = createFallbackResize(el, () => {
|
|
2910
|
+
const rect = el.getBoundingClientRect();
|
|
2911
|
+
const entry = {
|
|
2912
|
+
target: el,
|
|
2913
|
+
contentRect: rect,
|
|
2914
|
+
borderBoxSize: [],
|
|
2915
|
+
contentBoxSize: [],
|
|
2916
|
+
devicePixelContentBoxSize: []
|
|
2917
|
+
};
|
|
2918
|
+
state.handler(entry);
|
|
2919
|
+
if (options.onFallback) {
|
|
2920
|
+
options.onFallback(getResizeInfo(entry));
|
|
2921
|
+
}
|
|
2922
|
+
});
|
|
2923
|
+
state.fallbackIframe = iframe;
|
|
2924
|
+
el.__resizeCleanup = cleanup2;
|
|
2925
|
+
}
|
|
2926
|
+
},
|
|
2927
|
+
updated(el, binding) {
|
|
2928
|
+
const state = el.__resize;
|
|
2929
|
+
if (!state) return;
|
|
2930
|
+
state.options = normalizeOptions$1(binding.value);
|
|
2931
|
+
},
|
|
2932
|
+
unmounted(el) {
|
|
2933
|
+
const state = el.__resize;
|
|
2934
|
+
if (!state) return;
|
|
2935
|
+
if (state.debounceTimer) {
|
|
2936
|
+
clearTimeout(state.debounceTimer);
|
|
2937
|
+
}
|
|
2938
|
+
if (state.observer) {
|
|
2939
|
+
state.observer.disconnect();
|
|
2940
|
+
}
|
|
2941
|
+
const cleanup2 = el.__resizeCleanup;
|
|
2942
|
+
if (cleanup2) {
|
|
2943
|
+
cleanup2();
|
|
2944
|
+
}
|
|
2945
|
+
delete el.__resize;
|
|
2946
|
+
delete el.__resizeCleanup;
|
|
2947
|
+
}
|
|
2948
|
+
});
|
|
2949
|
+
function normalizeOptions(binding) {
|
|
2950
|
+
if (typeof binding === "function") {
|
|
2951
|
+
return { handler: binding, childList: true };
|
|
2952
|
+
}
|
|
2953
|
+
if (!binding || !binding.handler) {
|
|
2954
|
+
throw new Error("[Directix] v-mutation: handler is required");
|
|
2955
|
+
}
|
|
2956
|
+
return __spreadValues({
|
|
2957
|
+
attributes: false,
|
|
2958
|
+
childList: true,
|
|
2959
|
+
subtree: false,
|
|
2960
|
+
characterData: false,
|
|
2961
|
+
attributeOldValue: false,
|
|
2962
|
+
characterDataOldValue: false,
|
|
2963
|
+
disabled: false
|
|
2964
|
+
}, binding);
|
|
2965
|
+
}
|
|
2966
|
+
const vMutation = defineDirective({
|
|
2967
|
+
name: "mutation",
|
|
2968
|
+
ssr: false,
|
|
2969
|
+
defaults: {
|
|
2970
|
+
attributes: false,
|
|
2971
|
+
childList: true,
|
|
2972
|
+
subtree: false,
|
|
2973
|
+
characterData: false,
|
|
2974
|
+
attributeOldValue: false,
|
|
2975
|
+
characterDataOldValue: false,
|
|
2976
|
+
disabled: false
|
|
2977
|
+
},
|
|
2978
|
+
mounted(el, binding) {
|
|
2979
|
+
const options = normalizeOptions(binding.value);
|
|
2980
|
+
if (options.disabled || !isBrowser()) return;
|
|
2981
|
+
if (!supportsMutationObserver()) {
|
|
2982
|
+
console.warn("[Directix] v-mutation: MutationObserver not supported");
|
|
2983
|
+
return;
|
|
2984
|
+
}
|
|
2985
|
+
const state = {
|
|
2986
|
+
options,
|
|
2987
|
+
observer: null
|
|
2988
|
+
};
|
|
2989
|
+
state.observer = new MutationObserver((mutations, observer) => {
|
|
2990
|
+
options.handler(mutations, observer);
|
|
2991
|
+
});
|
|
2992
|
+
state.observer.observe(el, {
|
|
2993
|
+
attributes: options.attributes,
|
|
2994
|
+
attributeFilter: options.attributeFilter,
|
|
2995
|
+
childList: options.childList,
|
|
2996
|
+
subtree: options.subtree,
|
|
2997
|
+
characterData: options.characterData,
|
|
2998
|
+
attributeOldValue: options.attributeOldValue,
|
|
2999
|
+
characterDataOldValue: options.characterDataOldValue
|
|
3000
|
+
});
|
|
3001
|
+
el.__mutation = state;
|
|
3002
|
+
},
|
|
3003
|
+
updated(el, binding) {
|
|
3004
|
+
const state = el.__mutation;
|
|
3005
|
+
if (!state) return;
|
|
3006
|
+
const newOptions = normalizeOptions(binding.value);
|
|
3007
|
+
if (newOptions.disabled && !state.options.disabled) {
|
|
3008
|
+
if (state.observer) {
|
|
3009
|
+
state.observer.disconnect();
|
|
3010
|
+
}
|
|
3011
|
+
} else if (!newOptions.disabled && state.options.disabled) {
|
|
3012
|
+
if (state.observer) {
|
|
3013
|
+
state.observer.observe(el, {
|
|
3014
|
+
attributes: newOptions.attributes,
|
|
3015
|
+
attributeFilter: newOptions.attributeFilter,
|
|
3016
|
+
childList: newOptions.childList,
|
|
3017
|
+
subtree: newOptions.subtree,
|
|
3018
|
+
characterData: newOptions.characterData,
|
|
3019
|
+
attributeOldValue: newOptions.attributeOldValue,
|
|
3020
|
+
characterDataOldValue: newOptions.characterDataOldValue
|
|
3021
|
+
});
|
|
3022
|
+
}
|
|
3023
|
+
} else if (!newOptions.disabled) {
|
|
3024
|
+
if (newOptions.attributes !== state.options.attributes || newOptions.childList !== state.options.childList || newOptions.subtree !== state.options.subtree || newOptions.characterData !== state.options.characterData) {
|
|
3025
|
+
if (state.observer) {
|
|
3026
|
+
state.observer.disconnect();
|
|
3027
|
+
state.observer.observe(el, {
|
|
3028
|
+
attributes: newOptions.attributes,
|
|
3029
|
+
attributeFilter: newOptions.attributeFilter,
|
|
3030
|
+
childList: newOptions.childList,
|
|
3031
|
+
subtree: newOptions.subtree,
|
|
3032
|
+
characterData: newOptions.characterData,
|
|
3033
|
+
attributeOldValue: newOptions.attributeOldValue,
|
|
3034
|
+
characterDataOldValue: newOptions.characterDataOldValue
|
|
3035
|
+
});
|
|
3036
|
+
}
|
|
3037
|
+
}
|
|
3038
|
+
}
|
|
3039
|
+
state.options = newOptions;
|
|
3040
|
+
},
|
|
3041
|
+
unmounted(el) {
|
|
3042
|
+
const state = el.__mutation;
|
|
3043
|
+
if (!state) return;
|
|
3044
|
+
if (state.observer) {
|
|
3045
|
+
state.observer.disconnect();
|
|
3046
|
+
}
|
|
3047
|
+
delete el.__mutation;
|
|
3048
|
+
}
|
|
3049
|
+
});
|
|
3050
|
+
const allDirectives = {
|
|
3051
|
+
"click-outside": vClickOutside,
|
|
3052
|
+
copy: vCopy,
|
|
3053
|
+
debounce: vDebounce,
|
|
3054
|
+
throttle: vThrottle,
|
|
3055
|
+
focus: vFocus,
|
|
3056
|
+
lazy: vLazy,
|
|
3057
|
+
intersect: vIntersect,
|
|
3058
|
+
visible: vVisible,
|
|
3059
|
+
loading: vLoading,
|
|
3060
|
+
scroll: vScroll,
|
|
3061
|
+
"infinite-scroll": vInfiniteScroll,
|
|
3062
|
+
sticky: vSticky,
|
|
3063
|
+
"long-press": vLongPress,
|
|
3064
|
+
hover: vHover,
|
|
3065
|
+
ripple: vRipple,
|
|
3066
|
+
mask: vMask,
|
|
3067
|
+
permission: vPermission,
|
|
3068
|
+
sanitize: vSanitize,
|
|
3069
|
+
resize: vResize,
|
|
3070
|
+
mutation: vMutation
|
|
3071
|
+
};
|
|
3072
|
+
const install = (app, options = {}) => {
|
|
3073
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
3074
|
+
let vueVersion = null;
|
|
3075
|
+
if (typeof app === "function" && ((_a = app.version) == null ? void 0 : _a.startsWith("2"))) {
|
|
3076
|
+
vueVersion = 2;
|
|
3077
|
+
} else if ((app == null ? void 0 : app.config) && ((_b = app == null ? void 0 : app.version) == null ? void 0 : _b.startsWith("3"))) {
|
|
3078
|
+
vueVersion = 3;
|
|
3079
|
+
} else if (typeof (app == null ? void 0 : app.directive) === "function" && typeof (app == null ? void 0 : app.mixin) === "function" && ((_c = app.version) == null ? void 0 : _c.startsWith("2"))) {
|
|
3080
|
+
vueVersion = 2;
|
|
3081
|
+
} else if (typeof window !== "undefined") {
|
|
3082
|
+
const win = window;
|
|
3083
|
+
if ((_e = (_d = win.Vue) == null ? void 0 : _d.version) == null ? void 0 : _e.startsWith("2")) {
|
|
3084
|
+
vueVersion = 2;
|
|
3085
|
+
} else if ((_g = (_f = win.Vue) == null ? void 0 : _f.version) == null ? void 0 : _g.startsWith("3")) {
|
|
3086
|
+
vueVersion = 3;
|
|
3087
|
+
}
|
|
3088
|
+
}
|
|
3089
|
+
if (vueVersion) {
|
|
3090
|
+
setVueVersion(vueVersion);
|
|
3091
|
+
}
|
|
1031
3092
|
const { directives, all = false } = options;
|
|
1032
3093
|
if (all || !directives) {
|
|
1033
3094
|
Object.entries(allDirectives).forEach(([name, directive]) => {
|
|
@@ -1052,6 +3113,7 @@ export {
|
|
|
1052
3113
|
addCleanup$1 as addCleanupVue2,
|
|
1053
3114
|
addCleanup as addCleanupVue3,
|
|
1054
3115
|
vClickOutside as clickOutside,
|
|
3116
|
+
configurePermission,
|
|
1055
3117
|
vCopy as copy,
|
|
1056
3118
|
createVue2Directive,
|
|
1057
3119
|
createVue3Directive,
|
|
@@ -1064,7 +3126,11 @@ export {
|
|
|
1064
3126
|
vFocus as focus,
|
|
1065
3127
|
generateId,
|
|
1066
3128
|
get,
|
|
3129
|
+
getPermissionConfig,
|
|
1067
3130
|
getVueVersion,
|
|
3131
|
+
vHover as hover,
|
|
3132
|
+
vInfiniteScroll as infiniteScroll,
|
|
3133
|
+
vIntersect as intersect,
|
|
1068
3134
|
isArray,
|
|
1069
3135
|
isBoolean,
|
|
1070
3136
|
isBrowser,
|
|
@@ -1076,9 +3142,23 @@ export {
|
|
|
1076
3142
|
isSSR,
|
|
1077
3143
|
isString,
|
|
1078
3144
|
isVue2,
|
|
3145
|
+
isVue27,
|
|
1079
3146
|
isVue3,
|
|
3147
|
+
vLazy as lazy,
|
|
3148
|
+
vLoading as loading,
|
|
3149
|
+
vLongPress as longPress,
|
|
3150
|
+
vMask as mask,
|
|
3151
|
+
vMutation as mutation,
|
|
1080
3152
|
parseTime,
|
|
3153
|
+
vPermission as permission,
|
|
3154
|
+
resetVueVersion,
|
|
3155
|
+
vResize as resize,
|
|
3156
|
+
vRipple as ripple,
|
|
3157
|
+
vSanitize as sanitize,
|
|
3158
|
+
vScroll as scroll,
|
|
1081
3159
|
set,
|
|
3160
|
+
setVueVersion,
|
|
3161
|
+
vSticky as sticky,
|
|
1082
3162
|
supportsClipboard,
|
|
1083
3163
|
supportsIntersectionObserver,
|
|
1084
3164
|
supportsMutationObserver,
|
|
@@ -1090,6 +3170,22 @@ export {
|
|
|
1090
3170
|
vCopy,
|
|
1091
3171
|
vDebounce,
|
|
1092
3172
|
vFocus,
|
|
1093
|
-
|
|
3173
|
+
vHover,
|
|
3174
|
+
vInfiniteScroll,
|
|
3175
|
+
vIntersect,
|
|
3176
|
+
vLazy,
|
|
3177
|
+
vLoading,
|
|
3178
|
+
vLongPress,
|
|
3179
|
+
vMask,
|
|
3180
|
+
vMutation,
|
|
3181
|
+
vPermission,
|
|
3182
|
+
vResize,
|
|
3183
|
+
vRipple,
|
|
3184
|
+
vSanitize,
|
|
3185
|
+
vScroll,
|
|
3186
|
+
vSticky,
|
|
3187
|
+
vThrottle,
|
|
3188
|
+
vVisible,
|
|
3189
|
+
vVisible as visible
|
|
1094
3190
|
};
|
|
1095
3191
|
//# sourceMappingURL=index.mjs.map
|