directix 1.2.0 → 1.3.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 +195 -1
- package/dist/index.cjs +1628 -104
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +593 -2
- package/dist/index.iife.js +1628 -104
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +2 -2
- package/dist/index.mjs +1629 -105
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* directix v1.
|
|
2
|
+
* directix v1.3.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.
|
|
@@ -57,7 +57,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
57
57
|
});
|
|
58
58
|
};
|
|
59
59
|
/*!
|
|
60
|
-
* directix v1.
|
|
60
|
+
* directix v1.3.0
|
|
61
61
|
* A comprehensive, easy-to-use, and high-performance Vue custom directives library supporting both Vue 2 and Vue 3
|
|
62
62
|
* (c) 2021-present saqqdy <https://github.com/saqqdy>
|
|
63
63
|
* Released under the MIT License.
|
|
@@ -74,7 +74,7 @@ function createVue2Directive(hooks) {
|
|
|
74
74
|
},
|
|
75
75
|
inserted(el, binding, vnode) {
|
|
76
76
|
if (hooks.mounted) {
|
|
77
|
-
hooks.mounted(el, normalizeBinding(binding), vnode);
|
|
77
|
+
hooks.mounted(el, normalizeBinding$1(binding), vnode);
|
|
78
78
|
}
|
|
79
79
|
},
|
|
80
80
|
update(el, binding, vnode, oldVnode) {
|
|
@@ -82,9 +82,9 @@ function createVue2Directive(hooks) {
|
|
|
82
82
|
if (hooks.updated) {
|
|
83
83
|
hooks.updated(
|
|
84
84
|
el,
|
|
85
|
-
normalizeBinding(binding),
|
|
85
|
+
normalizeBinding$1(binding),
|
|
86
86
|
vnode,
|
|
87
|
-
normalizeBinding(__spreadProps(__spreadValues({}, binding), { value: binding.oldValue })),
|
|
87
|
+
normalizeBinding$1(__spreadProps(__spreadValues({}, binding), { value: binding.oldValue })),
|
|
88
88
|
oldVnode
|
|
89
89
|
);
|
|
90
90
|
}
|
|
@@ -97,7 +97,7 @@ function createVue2Directive(hooks) {
|
|
|
97
97
|
},
|
|
98
98
|
unbind(el, binding, vnode) {
|
|
99
99
|
if (hooks.unmounted) {
|
|
100
|
-
hooks.unmounted(el, normalizeBinding(binding), vnode);
|
|
100
|
+
hooks.unmounted(el, normalizeBinding$1(binding), vnode);
|
|
101
101
|
}
|
|
102
102
|
const state = el.__directix_state__;
|
|
103
103
|
if (state == null ? void 0 : state.cleanup) {
|
|
@@ -108,7 +108,7 @@ function createVue2Directive(hooks) {
|
|
|
108
108
|
};
|
|
109
109
|
return directive;
|
|
110
110
|
}
|
|
111
|
-
function normalizeBinding(binding) {
|
|
111
|
+
function normalizeBinding$1(binding) {
|
|
112
112
|
var _a;
|
|
113
113
|
return {
|
|
114
114
|
value: binding.value,
|
|
@@ -481,7 +481,7 @@ function capitalizeWord(word) {
|
|
|
481
481
|
if (!word) return word;
|
|
482
482
|
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
483
483
|
}
|
|
484
|
-
function normalizeOptions$
|
|
484
|
+
function normalizeOptions$B(binding) {
|
|
485
485
|
var _a, _b, _c;
|
|
486
486
|
if (binding === void 0 || binding === true) {
|
|
487
487
|
return { every: true, onInput: true };
|
|
@@ -499,7 +499,7 @@ const vCapitalcase = defineDirective({
|
|
|
499
499
|
name: "capitalcase",
|
|
500
500
|
ssr: true,
|
|
501
501
|
mounted(el, binding) {
|
|
502
|
-
const options = normalizeOptions$
|
|
502
|
+
const options = normalizeOptions$B(binding.value);
|
|
503
503
|
if (isInputElement(el)) {
|
|
504
504
|
const cleanup2 = setupTextTransformInput(el, options, (text) => capitalizeText(text, options));
|
|
505
505
|
el.__capitalcaseCleanup = cleanup2;
|
|
@@ -508,7 +508,7 @@ const vCapitalcase = defineDirective({
|
|
|
508
508
|
}
|
|
509
509
|
},
|
|
510
510
|
updated(el, binding) {
|
|
511
|
-
const options = normalizeOptions$
|
|
511
|
+
const options = normalizeOptions$B(binding.value);
|
|
512
512
|
if (isInputElement(el)) {
|
|
513
513
|
if (options.onInput) {
|
|
514
514
|
el.value = capitalizeText(el.value, options);
|
|
@@ -523,6 +523,134 @@ const vCapitalcase = defineDirective({
|
|
|
523
523
|
delete el.__capitalcaseCleanup;
|
|
524
524
|
}
|
|
525
525
|
});
|
|
526
|
+
const vClickDelay = defineDirective({
|
|
527
|
+
name: "click-delay",
|
|
528
|
+
ssr: true,
|
|
529
|
+
defaults: {
|
|
530
|
+
delay: 300,
|
|
531
|
+
disabled: false,
|
|
532
|
+
pendingClass: "v-click-delay--pending",
|
|
533
|
+
feedback: true
|
|
534
|
+
},
|
|
535
|
+
mounted(el, binding) {
|
|
536
|
+
const options = normalizeOptions$A(binding.value, binding);
|
|
537
|
+
if (options.disabled) return;
|
|
538
|
+
const state = {
|
|
539
|
+
options,
|
|
540
|
+
handler: createClickHandler(el, options),
|
|
541
|
+
isPending: false,
|
|
542
|
+
timeoutId: null
|
|
543
|
+
};
|
|
544
|
+
el.__clickDelay = state;
|
|
545
|
+
el.addEventListener("click", state.handler);
|
|
546
|
+
el.addEventListener("touchend", state.handler);
|
|
547
|
+
},
|
|
548
|
+
updated(el, binding) {
|
|
549
|
+
const state = el.__clickDelay;
|
|
550
|
+
if (!state) {
|
|
551
|
+
const options = normalizeOptions$A(binding.value, binding);
|
|
552
|
+
if (!options.disabled) {
|
|
553
|
+
const newState = {
|
|
554
|
+
options,
|
|
555
|
+
handler: createClickHandler(el, options),
|
|
556
|
+
isPending: false,
|
|
557
|
+
timeoutId: null
|
|
558
|
+
};
|
|
559
|
+
el.__clickDelay = newState;
|
|
560
|
+
el.addEventListener("click", newState.handler);
|
|
561
|
+
el.addEventListener("touchend", newState.handler);
|
|
562
|
+
}
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
const newOptions = normalizeOptions$A(binding.value, binding);
|
|
566
|
+
if (newOptions.disabled && !state.options.disabled) {
|
|
567
|
+
el.removeEventListener("click", state.handler);
|
|
568
|
+
el.removeEventListener("touchend", state.handler);
|
|
569
|
+
if (state.timeoutId) {
|
|
570
|
+
clearTimeout(state.timeoutId);
|
|
571
|
+
}
|
|
572
|
+
removePendingClass(el, state.options);
|
|
573
|
+
delete el.__clickDelay;
|
|
574
|
+
} else if (!newOptions.disabled && state.options.disabled) {
|
|
575
|
+
state.handler = createClickHandler(el, newOptions);
|
|
576
|
+
state.isPending = false;
|
|
577
|
+
state.timeoutId = null;
|
|
578
|
+
el.addEventListener("click", state.handler);
|
|
579
|
+
el.addEventListener("touchend", state.handler);
|
|
580
|
+
}
|
|
581
|
+
state.options = newOptions;
|
|
582
|
+
},
|
|
583
|
+
unmounted(el) {
|
|
584
|
+
const state = el.__clickDelay;
|
|
585
|
+
if (!state) return;
|
|
586
|
+
el.removeEventListener("click", state.handler);
|
|
587
|
+
el.removeEventListener("touchend", state.handler);
|
|
588
|
+
if (state.timeoutId) {
|
|
589
|
+
clearTimeout(state.timeoutId);
|
|
590
|
+
}
|
|
591
|
+
removePendingClass(el, state.options);
|
|
592
|
+
delete el.__clickDelay;
|
|
593
|
+
}
|
|
594
|
+
});
|
|
595
|
+
function createClickHandler(el, options) {
|
|
596
|
+
return (event) => {
|
|
597
|
+
const state = el.__clickDelay;
|
|
598
|
+
if (!state || state.isPending) {
|
|
599
|
+
event.preventDefault();
|
|
600
|
+
event.stopPropagation();
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
state.isPending = true;
|
|
604
|
+
if (options.feedback && options.pendingClass) {
|
|
605
|
+
el.classList.add(options.pendingClass);
|
|
606
|
+
}
|
|
607
|
+
options.handler(event);
|
|
608
|
+
state.timeoutId = setTimeout(() => {
|
|
609
|
+
state.isPending = false;
|
|
610
|
+
state.timeoutId = null;
|
|
611
|
+
removePendingClass(el, options);
|
|
612
|
+
}, options.delay);
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
function removePendingClass(el, options) {
|
|
616
|
+
if (options.feedback && options.pendingClass) {
|
|
617
|
+
el.classList.remove(options.pendingClass);
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
function parseTime$1(arg) {
|
|
621
|
+
if (!arg) return null;
|
|
622
|
+
if (arg.endsWith("ms")) {
|
|
623
|
+
return parseInt(arg, 10);
|
|
624
|
+
}
|
|
625
|
+
if (arg.endsWith("s")) {
|
|
626
|
+
return parseFloat(arg) * 1e3;
|
|
627
|
+
}
|
|
628
|
+
const num = parseInt(arg, 10);
|
|
629
|
+
return Number.isNaN(num) ? null : num;
|
|
630
|
+
}
|
|
631
|
+
function normalizeOptions$A(binding, directiveBinding) {
|
|
632
|
+
var _a, _b, _c, _d;
|
|
633
|
+
const delay = parseTime$1(directiveBinding.arg) || 300;
|
|
634
|
+
if (typeof binding === "function") {
|
|
635
|
+
return {
|
|
636
|
+
handler: binding,
|
|
637
|
+
delay,
|
|
638
|
+
disabled: false,
|
|
639
|
+
pendingClass: "v-click-delay--pending",
|
|
640
|
+
feedback: true
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
if (!binding) {
|
|
644
|
+
throw new Error("[Directix] v-click-delay: handler is required");
|
|
645
|
+
}
|
|
646
|
+
return {
|
|
647
|
+
handler: binding.handler,
|
|
648
|
+
delay: (_a = binding.delay) != null ? _a : delay,
|
|
649
|
+
disabled: (_b = binding.disabled) != null ? _b : false,
|
|
650
|
+
pendingClass: (_c = binding.pendingClass) != null ? _c : "v-click-delay--pending",
|
|
651
|
+
feedback: (_d = binding.feedback) != null ? _d : true
|
|
652
|
+
};
|
|
653
|
+
}
|
|
526
654
|
function isElement(value) {
|
|
527
655
|
return value instanceof Element;
|
|
528
656
|
}
|
|
@@ -548,15 +676,15 @@ function getScrollParent(el) {
|
|
|
548
676
|
}
|
|
549
677
|
function on(target, event, handler, options = false) {
|
|
550
678
|
if (!isBrowser()) return;
|
|
551
|
-
const opts = normalizeOptions$
|
|
679
|
+
const opts = normalizeOptions$z(options);
|
|
552
680
|
target.addEventListener(event, handler, opts);
|
|
553
681
|
}
|
|
554
682
|
function off(target, event, handler, options = false) {
|
|
555
683
|
if (!isBrowser()) return;
|
|
556
|
-
const opts = normalizeOptions$
|
|
684
|
+
const opts = normalizeOptions$z(options);
|
|
557
685
|
target.removeEventListener(event, handler, opts);
|
|
558
686
|
}
|
|
559
|
-
function normalizeOptions$
|
|
687
|
+
function normalizeOptions$z(options) {
|
|
560
688
|
if (typeof options === "boolean") {
|
|
561
689
|
return options;
|
|
562
690
|
}
|
|
@@ -779,7 +907,7 @@ const vClickOutside = defineDirective({
|
|
|
779
907
|
prevent: false
|
|
780
908
|
},
|
|
781
909
|
mounted(el, binding) {
|
|
782
|
-
const options = normalizeOptions$
|
|
910
|
+
const options = normalizeOptions$y(binding.value);
|
|
783
911
|
if (options.disabled) return;
|
|
784
912
|
const state = {
|
|
785
913
|
options,
|
|
@@ -814,7 +942,7 @@ const vClickOutside = defineDirective({
|
|
|
814
942
|
const state = el.__clickOutside;
|
|
815
943
|
if (!state) return;
|
|
816
944
|
const oldOptions = state.options;
|
|
817
|
-
const newOptions = normalizeOptions$
|
|
945
|
+
const newOptions = normalizeOptions$y(binding.value);
|
|
818
946
|
if (oldOptions.disabled !== newOptions.disabled) {
|
|
819
947
|
if (newOptions.disabled) {
|
|
820
948
|
state.handlers.forEach((handler, eventType) => {
|
|
@@ -851,7 +979,7 @@ const vClickOutside = defineDirective({
|
|
|
851
979
|
delete el.__clickOutside;
|
|
852
980
|
}
|
|
853
981
|
});
|
|
854
|
-
function normalizeOptions$
|
|
982
|
+
function normalizeOptions$y(binding) {
|
|
855
983
|
var _a, _b, _c, _d, _e;
|
|
856
984
|
if (typeof binding === "function") {
|
|
857
985
|
return {
|
|
@@ -928,7 +1056,7 @@ const vCopy = defineDirective({
|
|
|
928
1056
|
name: "copy",
|
|
929
1057
|
ssr: false,
|
|
930
1058
|
mounted(el, binding) {
|
|
931
|
-
const options = normalizeOptions$
|
|
1059
|
+
const options = normalizeOptions$x(binding.value);
|
|
932
1060
|
if (options.disabled) return;
|
|
933
1061
|
if (options.title) {
|
|
934
1062
|
el.setAttribute("title", options.title);
|
|
@@ -964,7 +1092,7 @@ const vCopy = defineDirective({
|
|
|
964
1092
|
updated(el, binding) {
|
|
965
1093
|
const state = el.__copy;
|
|
966
1094
|
if (!state) return;
|
|
967
|
-
state.options = normalizeOptions$
|
|
1095
|
+
state.options = normalizeOptions$x(binding.value);
|
|
968
1096
|
if (state.options.title) {
|
|
969
1097
|
el.setAttribute("title", state.options.title);
|
|
970
1098
|
}
|
|
@@ -976,12 +1104,142 @@ const vCopy = defineDirective({
|
|
|
976
1104
|
delete el.__copy;
|
|
977
1105
|
}
|
|
978
1106
|
});
|
|
979
|
-
function normalizeOptions$
|
|
1107
|
+
function normalizeOptions$x(binding) {
|
|
980
1108
|
if (typeof binding === "string") {
|
|
981
1109
|
return { value: binding };
|
|
982
1110
|
}
|
|
983
1111
|
return binding;
|
|
984
1112
|
}
|
|
1113
|
+
function parseTargetTime(target) {
|
|
1114
|
+
if (target instanceof Date) {
|
|
1115
|
+
return target.getTime();
|
|
1116
|
+
}
|
|
1117
|
+
if (typeof target === "number") {
|
|
1118
|
+
return target;
|
|
1119
|
+
}
|
|
1120
|
+
return new Date(target).getTime();
|
|
1121
|
+
}
|
|
1122
|
+
function calculateTime(remaining) {
|
|
1123
|
+
const total = Math.max(0, remaining);
|
|
1124
|
+
return {
|
|
1125
|
+
days: Math.floor(total / (1e3 * 60 * 60 * 24)),
|
|
1126
|
+
hours: Math.floor(total % (1e3 * 60 * 60 * 24) / (1e3 * 60 * 60)),
|
|
1127
|
+
minutes: Math.floor(total % (1e3 * 60 * 60) / (1e3 * 60)),
|
|
1128
|
+
seconds: Math.floor(total % (1e3 * 60) / 1e3),
|
|
1129
|
+
milliseconds: total % 1e3,
|
|
1130
|
+
total
|
|
1131
|
+
};
|
|
1132
|
+
}
|
|
1133
|
+
function formatTime(time, format) {
|
|
1134
|
+
if (typeof format === "function") {
|
|
1135
|
+
return format(time);
|
|
1136
|
+
}
|
|
1137
|
+
const pad = (n, len = 2) => String(n).padStart(len, "0");
|
|
1138
|
+
const result = format.replace(/dd/gi, pad(time.days)).replace(/hh/gi, pad(time.hours)).replace(/mm/gi, pad(time.minutes)).replace(/ss/gi, pad(time.seconds)).replace(/S{3}/gi, pad(time.milliseconds, 3)).replace(/SS/gi, pad(Math.floor(time.milliseconds / 10))).replace(/S/gi, String(Math.floor(time.milliseconds / 100)));
|
|
1139
|
+
return result;
|
|
1140
|
+
}
|
|
1141
|
+
function normalizeOptions$w(binding) {
|
|
1142
|
+
var _a, _b, _c, _d;
|
|
1143
|
+
if (typeof binding === "object" && binding !== null && "target" in binding) {
|
|
1144
|
+
return {
|
|
1145
|
+
target: binding.target,
|
|
1146
|
+
format: (_a = binding.format) != null ? _a : "hh:mm:ss",
|
|
1147
|
+
onComplete: binding.onComplete,
|
|
1148
|
+
onTick: binding.onTick,
|
|
1149
|
+
interval: (_b = binding.interval) != null ? _b : 1e3,
|
|
1150
|
+
showMilliseconds: (_c = binding.showMilliseconds) != null ? _c : false,
|
|
1151
|
+
autoStart: (_d = binding.autoStart) != null ? _d : true,
|
|
1152
|
+
labels: binding.labels
|
|
1153
|
+
};
|
|
1154
|
+
}
|
|
1155
|
+
return {
|
|
1156
|
+
target: binding,
|
|
1157
|
+
format: "hh:mm:ss",
|
|
1158
|
+
interval: 1e3,
|
|
1159
|
+
showMilliseconds: false,
|
|
1160
|
+
autoStart: true
|
|
1161
|
+
};
|
|
1162
|
+
}
|
|
1163
|
+
const vCountdown = defineDirective({
|
|
1164
|
+
name: "countdown",
|
|
1165
|
+
ssr: true,
|
|
1166
|
+
mounted(el, binding) {
|
|
1167
|
+
const options = normalizeOptions$w(binding.value);
|
|
1168
|
+
const targetTime = parseTargetTime(options.target);
|
|
1169
|
+
const state = {
|
|
1170
|
+
options,
|
|
1171
|
+
targetTime,
|
|
1172
|
+
intervalId: null,
|
|
1173
|
+
paused: false,
|
|
1174
|
+
remaining: 0
|
|
1175
|
+
};
|
|
1176
|
+
el.__countdown = state;
|
|
1177
|
+
if (options.autoStart !== false) {
|
|
1178
|
+
startCountdown(el, state);
|
|
1179
|
+
} else {
|
|
1180
|
+
updateDisplay(el, state);
|
|
1181
|
+
}
|
|
1182
|
+
},
|
|
1183
|
+
updated(el, binding) {
|
|
1184
|
+
const state = el.__countdown;
|
|
1185
|
+
const newOptions = normalizeOptions$w(binding.value);
|
|
1186
|
+
const newTargetTime = parseTargetTime(newOptions.target);
|
|
1187
|
+
if (newTargetTime !== state.targetTime) {
|
|
1188
|
+
state.targetTime = newTargetTime;
|
|
1189
|
+
state.options = newOptions;
|
|
1190
|
+
if (state.intervalId) {
|
|
1191
|
+
clearInterval(state.intervalId);
|
|
1192
|
+
state.intervalId = null;
|
|
1193
|
+
}
|
|
1194
|
+
if (!state.paused) {
|
|
1195
|
+
startCountdown(el, state);
|
|
1196
|
+
}
|
|
1197
|
+
} else {
|
|
1198
|
+
state.options = newOptions;
|
|
1199
|
+
}
|
|
1200
|
+
},
|
|
1201
|
+
unmounted(el) {
|
|
1202
|
+
const state = el.__countdown;
|
|
1203
|
+
if (state == null ? void 0 : state.intervalId) {
|
|
1204
|
+
clearInterval(state.intervalId);
|
|
1205
|
+
}
|
|
1206
|
+
delete el.__countdown;
|
|
1207
|
+
}
|
|
1208
|
+
});
|
|
1209
|
+
function startCountdown(el, state) {
|
|
1210
|
+
const tick = () => {
|
|
1211
|
+
const now = Date.now();
|
|
1212
|
+
state.remaining = state.targetTime - now;
|
|
1213
|
+
if (state.remaining <= 0) {
|
|
1214
|
+
state.remaining = 0;
|
|
1215
|
+
updateDisplay(el, state);
|
|
1216
|
+
stopCountdown(state);
|
|
1217
|
+
if (state.options.onComplete) {
|
|
1218
|
+
state.options.onComplete();
|
|
1219
|
+
}
|
|
1220
|
+
el.dispatchEvent(new CustomEvent("countdown:complete"));
|
|
1221
|
+
return;
|
|
1222
|
+
}
|
|
1223
|
+
updateDisplay(el, state);
|
|
1224
|
+
if (state.options.onTick) {
|
|
1225
|
+
const time = calculateTime(state.remaining);
|
|
1226
|
+
state.options.onTick(time);
|
|
1227
|
+
}
|
|
1228
|
+
};
|
|
1229
|
+
tick();
|
|
1230
|
+
state.intervalId = setInterval(tick, state.options.interval || 1e3);
|
|
1231
|
+
}
|
|
1232
|
+
function stopCountdown(state) {
|
|
1233
|
+
if (state.intervalId) {
|
|
1234
|
+
clearInterval(state.intervalId);
|
|
1235
|
+
state.intervalId = null;
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
function updateDisplay(el, state) {
|
|
1239
|
+
const time = calculateTime(state.remaining);
|
|
1240
|
+
const display = formatTime(time, state.options.format || "hh:mm:ss");
|
|
1241
|
+
el.textContent = display;
|
|
1242
|
+
}
|
|
985
1243
|
const EVENT_MODIFIERS = [
|
|
986
1244
|
"click",
|
|
987
1245
|
"input",
|
|
@@ -1017,7 +1275,7 @@ function getDefaultEventType(el) {
|
|
|
1017
1275
|
}
|
|
1018
1276
|
return "click";
|
|
1019
1277
|
}
|
|
1020
|
-
function normalizeOptions$
|
|
1278
|
+
function normalizeOptions$v(binding, directiveBinding) {
|
|
1021
1279
|
const wait = parseTime(directiveBinding.arg) || 300;
|
|
1022
1280
|
if (typeof binding === "function") {
|
|
1023
1281
|
return { handler: binding, wait };
|
|
@@ -1034,7 +1292,7 @@ const vDebounce = defineDirective({
|
|
|
1034
1292
|
trailing: true
|
|
1035
1293
|
},
|
|
1036
1294
|
mounted(el, binding) {
|
|
1037
|
-
const options = normalizeOptions$
|
|
1295
|
+
const options = normalizeOptions$v(binding.value, binding);
|
|
1038
1296
|
const eventType = getEventTypeFromModifiers(binding.modifiers) || getDefaultEventType(el);
|
|
1039
1297
|
const debouncedFn = debounce(options.handler, options.wait, {
|
|
1040
1298
|
leading: options.leading,
|
|
@@ -1050,7 +1308,7 @@ const vDebounce = defineDirective({
|
|
|
1050
1308
|
updated(el, binding) {
|
|
1051
1309
|
const state = el.__debounce;
|
|
1052
1310
|
if (!state) return;
|
|
1053
|
-
const newOptions = normalizeOptions$
|
|
1311
|
+
const newOptions = normalizeOptions$v(binding.value, binding);
|
|
1054
1312
|
if (newOptions.wait !== state.options.wait || newOptions.leading !== state.options.leading || newOptions.trailing !== state.options.trailing) {
|
|
1055
1313
|
state.debouncedFn.cancel();
|
|
1056
1314
|
const debouncedFn = debounce(newOptions.handler, newOptions.wait, {
|
|
@@ -1104,7 +1362,7 @@ function parseTranslate(transform) {
|
|
|
1104
1362
|
}
|
|
1105
1363
|
return { x: 0, y: 0 };
|
|
1106
1364
|
}
|
|
1107
|
-
function normalizeOptions$
|
|
1365
|
+
function normalizeOptions$u(binding) {
|
|
1108
1366
|
var _a, _b, _c;
|
|
1109
1367
|
if (binding === void 0 || binding === true) {
|
|
1110
1368
|
return { axis: "both", constrain: false, disabled: false };
|
|
@@ -1128,7 +1386,7 @@ const vDraggable = defineDirective({
|
|
|
1128
1386
|
name: "draggable",
|
|
1129
1387
|
ssr: false,
|
|
1130
1388
|
mounted(el, binding) {
|
|
1131
|
-
const options = normalizeOptions$
|
|
1389
|
+
const options = normalizeOptions$u(binding.value);
|
|
1132
1390
|
if (options.disabled) return;
|
|
1133
1391
|
if (getComputedStyle(el).position === "static") {
|
|
1134
1392
|
el.style.position = "absolute";
|
|
@@ -1234,7 +1492,7 @@ const vDraggable = defineDirective({
|
|
|
1234
1492
|
updated(el, binding) {
|
|
1235
1493
|
const state = el.__draggable;
|
|
1236
1494
|
if (!state) return;
|
|
1237
|
-
state.options = normalizeOptions$
|
|
1495
|
+
state.options = normalizeOptions$u(binding.value);
|
|
1238
1496
|
if (state.options.handle) {
|
|
1239
1497
|
state.handleEl = el.querySelector(state.options.handle);
|
|
1240
1498
|
}
|
|
@@ -1253,6 +1511,150 @@ const vDraggable = defineDirective({
|
|
|
1253
1511
|
delete el.__draggable;
|
|
1254
1512
|
}
|
|
1255
1513
|
});
|
|
1514
|
+
const vEllipsis = defineDirective({
|
|
1515
|
+
name: "ellipsis",
|
|
1516
|
+
ssr: true,
|
|
1517
|
+
defaults: {
|
|
1518
|
+
lines: 1,
|
|
1519
|
+
ellipsis: "...",
|
|
1520
|
+
expandable: false,
|
|
1521
|
+
titleBehavior: "auto"
|
|
1522
|
+
},
|
|
1523
|
+
mounted(el, binding) {
|
|
1524
|
+
const options = normalizeOptions$t(binding.value);
|
|
1525
|
+
applyEllipsis(el, options);
|
|
1526
|
+
const state = {
|
|
1527
|
+
options,
|
|
1528
|
+
originalText: el.textContent || "",
|
|
1529
|
+
clickHandler: null,
|
|
1530
|
+
expanded: false
|
|
1531
|
+
};
|
|
1532
|
+
if (options.expandable) {
|
|
1533
|
+
const handler = () => {
|
|
1534
|
+
if (state.expanded) {
|
|
1535
|
+
applyEllipsis(el, options);
|
|
1536
|
+
state.expanded = false;
|
|
1537
|
+
} else {
|
|
1538
|
+
el.textContent = state.originalText;
|
|
1539
|
+
el.style.webkitLineClamp = "";
|
|
1540
|
+
el.style.display = "";
|
|
1541
|
+
el.style.overflow = "";
|
|
1542
|
+
el.style.cursor = "";
|
|
1543
|
+
state.expanded = true;
|
|
1544
|
+
}
|
|
1545
|
+
};
|
|
1546
|
+
el.addEventListener("click", handler);
|
|
1547
|
+
el.style.cursor = "pointer";
|
|
1548
|
+
state.clickHandler = handler;
|
|
1549
|
+
}
|
|
1550
|
+
if (options.titleBehavior === "always") {
|
|
1551
|
+
el.title = state.originalText;
|
|
1552
|
+
} else if (options.titleBehavior === "auto") {
|
|
1553
|
+
if (isTextTruncated(el)) {
|
|
1554
|
+
el.title = state.originalText;
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
el.__ellipsis = state;
|
|
1558
|
+
},
|
|
1559
|
+
updated(el, binding) {
|
|
1560
|
+
const state = el.__ellipsis;
|
|
1561
|
+
if (!state) {
|
|
1562
|
+
const options = normalizeOptions$t(binding.value);
|
|
1563
|
+
applyEllipsis(el, options);
|
|
1564
|
+
return;
|
|
1565
|
+
}
|
|
1566
|
+
const newOptions = normalizeOptions$t(binding.value);
|
|
1567
|
+
const textChanged = el.textContent !== state.originalText;
|
|
1568
|
+
if (textChanged) {
|
|
1569
|
+
state.originalText = el.textContent || "";
|
|
1570
|
+
state.expanded = false;
|
|
1571
|
+
}
|
|
1572
|
+
if (state.options.expandable !== newOptions.expandable) {
|
|
1573
|
+
if (state.clickHandler) {
|
|
1574
|
+
el.removeEventListener("click", state.clickHandler);
|
|
1575
|
+
state.clickHandler = null;
|
|
1576
|
+
}
|
|
1577
|
+
if (newOptions.expandable) {
|
|
1578
|
+
const handler = () => {
|
|
1579
|
+
if (state.expanded) {
|
|
1580
|
+
applyEllipsis(el, newOptions);
|
|
1581
|
+
state.expanded = false;
|
|
1582
|
+
} else {
|
|
1583
|
+
el.textContent = state.originalText;
|
|
1584
|
+
el.style.webkitLineClamp = "";
|
|
1585
|
+
el.style.display = "";
|
|
1586
|
+
el.style.overflow = "";
|
|
1587
|
+
state.expanded = true;
|
|
1588
|
+
}
|
|
1589
|
+
};
|
|
1590
|
+
el.addEventListener("click", handler);
|
|
1591
|
+
el.style.cursor = "pointer";
|
|
1592
|
+
state.clickHandler = handler;
|
|
1593
|
+
} else {
|
|
1594
|
+
el.style.cursor = "";
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
state.options = newOptions;
|
|
1598
|
+
if (!state.expanded) {
|
|
1599
|
+
applyEllipsis(el, newOptions);
|
|
1600
|
+
}
|
|
1601
|
+
if (newOptions.titleBehavior === "always") {
|
|
1602
|
+
el.title = state.originalText;
|
|
1603
|
+
} else if (newOptions.titleBehavior === "auto") {
|
|
1604
|
+
el.title = isTextTruncated(el) ? state.originalText : "";
|
|
1605
|
+
} else {
|
|
1606
|
+
el.removeAttribute("title");
|
|
1607
|
+
}
|
|
1608
|
+
},
|
|
1609
|
+
unmounted(el) {
|
|
1610
|
+
const state = el.__ellipsis;
|
|
1611
|
+
if (!state) return;
|
|
1612
|
+
if (state.clickHandler) {
|
|
1613
|
+
el.removeEventListener("click", state.clickHandler);
|
|
1614
|
+
}
|
|
1615
|
+
el.style.removeProperty("-webkit-line-clamp");
|
|
1616
|
+
el.style.removeProperty("-webkit-box-orient");
|
|
1617
|
+
el.style.removeProperty("display");
|
|
1618
|
+
el.style.removeProperty("overflow");
|
|
1619
|
+
el.style.removeProperty("text-overflow");
|
|
1620
|
+
el.style.removeProperty("white-space");
|
|
1621
|
+
el.style.removeProperty("cursor");
|
|
1622
|
+
delete el.__ellipsis;
|
|
1623
|
+
}
|
|
1624
|
+
});
|
|
1625
|
+
function applyEllipsis(el, options) {
|
|
1626
|
+
const lines = options.lines || 1;
|
|
1627
|
+
if (lines === 1) {
|
|
1628
|
+
el.style.overflow = "hidden";
|
|
1629
|
+
el.style.textOverflow = "ellipsis";
|
|
1630
|
+
el.style.whiteSpace = "nowrap";
|
|
1631
|
+
} else {
|
|
1632
|
+
el.style.display = "-webkit-box";
|
|
1633
|
+
el.style.overflow = "hidden";
|
|
1634
|
+
el.style.webkitBoxOrient = "vertical";
|
|
1635
|
+
el.style.webkitLineClamp = String(lines);
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
function isTextTruncated(el) {
|
|
1639
|
+
return el.scrollWidth > el.clientWidth || el.scrollHeight > el.clientHeight;
|
|
1640
|
+
}
|
|
1641
|
+
function normalizeOptions$t(binding) {
|
|
1642
|
+
var _a, _b, _c, _d;
|
|
1643
|
+
if (typeof binding === "number") {
|
|
1644
|
+
return {
|
|
1645
|
+
lines: binding,
|
|
1646
|
+
ellipsis: "...",
|
|
1647
|
+
expandable: false,
|
|
1648
|
+
titleBehavior: "auto"
|
|
1649
|
+
};
|
|
1650
|
+
}
|
|
1651
|
+
return {
|
|
1652
|
+
lines: (_a = binding == null ? void 0 : binding.lines) != null ? _a : 1,
|
|
1653
|
+
ellipsis: (_b = binding == null ? void 0 : binding.ellipsis) != null ? _b : "...",
|
|
1654
|
+
expandable: (_c = binding == null ? void 0 : binding.expandable) != null ? _c : false,
|
|
1655
|
+
titleBehavior: (_d = binding == null ? void 0 : binding.titleBehavior) != null ? _d : "auto"
|
|
1656
|
+
};
|
|
1657
|
+
}
|
|
1256
1658
|
const FOCUSABLE_TAGS = /* @__PURE__ */ new Set(["input", "textarea", "select", "button"]);
|
|
1257
1659
|
function isEqual(a, b) {
|
|
1258
1660
|
if (a === b) return true;
|
|
@@ -1274,7 +1676,7 @@ const vFocus = defineDirective({
|
|
|
1274
1676
|
},
|
|
1275
1677
|
mounted(el, binding) {
|
|
1276
1678
|
if (!isBrowser()) return;
|
|
1277
|
-
const options = normalizeOptions$
|
|
1679
|
+
const options = normalizeOptions$s(binding.value);
|
|
1278
1680
|
if (!options.focus || !isFocusable(el)) {
|
|
1279
1681
|
if (options.focus) {
|
|
1280
1682
|
console.warn("[Directix] v-focus: Element is not focusable");
|
|
@@ -1302,7 +1704,7 @@ const vFocus = defineDirective({
|
|
|
1302
1704
|
updated(el, binding) {
|
|
1303
1705
|
const state = el.__focus;
|
|
1304
1706
|
if (!state) return;
|
|
1305
|
-
const newOptions = normalizeOptions$
|
|
1707
|
+
const newOptions = normalizeOptions$s(binding.value);
|
|
1306
1708
|
if (newOptions.onFocus !== state.options.onFocus) {
|
|
1307
1709
|
el.removeEventListener("focus", state.handleFocus);
|
|
1308
1710
|
state.handleFocus = () => {
|
|
@@ -1334,7 +1736,7 @@ const vFocus = defineDirective({
|
|
|
1334
1736
|
delete el.__focus;
|
|
1335
1737
|
}
|
|
1336
1738
|
});
|
|
1337
|
-
function normalizeOptions$
|
|
1739
|
+
function normalizeOptions$s(binding) {
|
|
1338
1740
|
if (typeof binding === "boolean") {
|
|
1339
1741
|
return { focus: binding, refocus: false };
|
|
1340
1742
|
}
|
|
@@ -1357,7 +1759,181 @@ function isFocusable(el) {
|
|
|
1357
1759
|
}
|
|
1358
1760
|
return false;
|
|
1359
1761
|
}
|
|
1360
|
-
|
|
1762
|
+
const KEY_ALIASES = {
|
|
1763
|
+
esc: "escape",
|
|
1764
|
+
space: " ",
|
|
1765
|
+
up: "arrowup",
|
|
1766
|
+
down: "arrowdown",
|
|
1767
|
+
left: "arrowleft",
|
|
1768
|
+
right: "arrowright",
|
|
1769
|
+
enter: "enter",
|
|
1770
|
+
tab: "tab",
|
|
1771
|
+
delete: "delete",
|
|
1772
|
+
backspace: "backspace",
|
|
1773
|
+
insert: "insert",
|
|
1774
|
+
home: "home",
|
|
1775
|
+
end: "end",
|
|
1776
|
+
pagedown: "pagedown",
|
|
1777
|
+
pageup: "pageup",
|
|
1778
|
+
f1: "f1",
|
|
1779
|
+
f2: "f2",
|
|
1780
|
+
f3: "f3",
|
|
1781
|
+
f4: "f4",
|
|
1782
|
+
f5: "f5",
|
|
1783
|
+
f6: "f6",
|
|
1784
|
+
f7: "f7",
|
|
1785
|
+
f8: "f8",
|
|
1786
|
+
f9: "f9",
|
|
1787
|
+
f10: "f10",
|
|
1788
|
+
f11: "f11",
|
|
1789
|
+
f12: "f12"
|
|
1790
|
+
};
|
|
1791
|
+
const MODIFIER_KEYS = /* @__PURE__ */ new Set(["ctrl", "alt", "shift", "meta"]);
|
|
1792
|
+
function normalizeKey(key) {
|
|
1793
|
+
const lowerKey = key.toLowerCase();
|
|
1794
|
+
return KEY_ALIASES[lowerKey] || lowerKey;
|
|
1795
|
+
}
|
|
1796
|
+
function parseHotkeyString(hotkey) {
|
|
1797
|
+
const parts = hotkey.toLowerCase().split(/[+.]/);
|
|
1798
|
+
const modifiers = [];
|
|
1799
|
+
let key = "";
|
|
1800
|
+
for (const part of parts) {
|
|
1801
|
+
if (MODIFIER_KEYS.has(part)) {
|
|
1802
|
+
modifiers.push(part);
|
|
1803
|
+
} else {
|
|
1804
|
+
key = normalizeKey(part);
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
return { key, modifiers };
|
|
1808
|
+
}
|
|
1809
|
+
function matchesHotkey(event, entry) {
|
|
1810
|
+
if (normalizeKey(event.key) !== entry.key) return false;
|
|
1811
|
+
const eventModifiers = /* @__PURE__ */ new Set();
|
|
1812
|
+
if (event.ctrlKey) eventModifiers.add("ctrl");
|
|
1813
|
+
if (event.altKey) eventModifiers.add("alt");
|
|
1814
|
+
if (event.shiftKey) eventModifiers.add("shift");
|
|
1815
|
+
if (event.metaKey) eventModifiers.add("meta");
|
|
1816
|
+
if (eventModifiers.size !== entry.modifiers.size) return false;
|
|
1817
|
+
for (const mod of entry.modifiers) {
|
|
1818
|
+
if (!eventModifiers.has(mod)) return false;
|
|
1819
|
+
}
|
|
1820
|
+
return true;
|
|
1821
|
+
}
|
|
1822
|
+
function createEntry(key, modifiers, handler, options = {}) {
|
|
1823
|
+
var _a, _b, _c;
|
|
1824
|
+
return {
|
|
1825
|
+
key: normalizeKey(key),
|
|
1826
|
+
modifiers: new Set(modifiers),
|
|
1827
|
+
handler,
|
|
1828
|
+
prevent: (_a = options.prevent) != null ? _a : true,
|
|
1829
|
+
stop: (_b = options.stop) != null ? _b : true,
|
|
1830
|
+
disabled: (_c = options.disabled) != null ? _c : false
|
|
1831
|
+
};
|
|
1832
|
+
}
|
|
1833
|
+
function normalizeBinding(binding, arg, modifiers) {
|
|
1834
|
+
if (arg) {
|
|
1835
|
+
const argLower = arg.toLowerCase();
|
|
1836
|
+
const argIsModifier = MODIFIER_KEYS.has(argLower);
|
|
1837
|
+
let key;
|
|
1838
|
+
const parsedModifiers = [];
|
|
1839
|
+
if (argIsModifier) {
|
|
1840
|
+
parsedModifiers.push(argLower);
|
|
1841
|
+
for (const mod of Object.keys(modifiers)) {
|
|
1842
|
+
const modLower = mod.toLowerCase();
|
|
1843
|
+
if (MODIFIER_KEYS.has(modLower)) {
|
|
1844
|
+
parsedModifiers.push(modLower);
|
|
1845
|
+
} else {
|
|
1846
|
+
key = normalizeKey(mod);
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
} else {
|
|
1850
|
+
const parsed = parseHotkeyString(arg);
|
|
1851
|
+
key = parsed.key;
|
|
1852
|
+
parsedModifiers.push(...parsed.modifiers);
|
|
1853
|
+
for (const mod of Object.keys(modifiers)) {
|
|
1854
|
+
const modLower = mod.toLowerCase();
|
|
1855
|
+
if (MODIFIER_KEYS.has(modLower)) {
|
|
1856
|
+
parsedModifiers.push(modLower);
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
const handler = typeof binding === "function" ? binding : binding.handler;
|
|
1861
|
+
return [createEntry(key, parsedModifiers, handler)];
|
|
1862
|
+
}
|
|
1863
|
+
if (typeof binding === "function") {
|
|
1864
|
+
console.warn('[Directix] v-hotkey: hotkey definition required (use v-hotkey:ctrl.s="handler")');
|
|
1865
|
+
return [];
|
|
1866
|
+
}
|
|
1867
|
+
if (Array.isArray(binding)) {
|
|
1868
|
+
return binding.map(
|
|
1869
|
+
(item) => createEntry(item.key, item.modifiers || [], item.handler, {
|
|
1870
|
+
prevent: item.prevent,
|
|
1871
|
+
stop: item.stop,
|
|
1872
|
+
disabled: item.disabled
|
|
1873
|
+
})
|
|
1874
|
+
);
|
|
1875
|
+
}
|
|
1876
|
+
if (typeof binding === "object" && binding !== null) {
|
|
1877
|
+
if ("handler" in binding && typeof binding.handler === "function") {
|
|
1878
|
+
const def = binding;
|
|
1879
|
+
return [createEntry(def.key, def.modifiers || [], def.handler, def)];
|
|
1880
|
+
}
|
|
1881
|
+
const entries = [];
|
|
1882
|
+
for (const [hotkeyStr, value] of Object.entries(binding)) {
|
|
1883
|
+
const { key, modifiers: parsedModifiers } = parseHotkeyString(hotkeyStr);
|
|
1884
|
+
const handler = typeof value === "function" ? value : value.handler;
|
|
1885
|
+
const options = typeof value === "object" ? value : {};
|
|
1886
|
+
entries.push(createEntry(key, parsedModifiers, handler, options));
|
|
1887
|
+
}
|
|
1888
|
+
return entries;
|
|
1889
|
+
}
|
|
1890
|
+
return [];
|
|
1891
|
+
}
|
|
1892
|
+
function createKeydownHandler(state) {
|
|
1893
|
+
return (event) => {
|
|
1894
|
+
for (const entry of state.entries) {
|
|
1895
|
+
if (entry.disabled) continue;
|
|
1896
|
+
if (!matchesHotkey(event, entry)) continue;
|
|
1897
|
+
if (entry.prevent) event.preventDefault();
|
|
1898
|
+
if (entry.stop) event.stopPropagation();
|
|
1899
|
+
entry.handler(event);
|
|
1900
|
+
return;
|
|
1901
|
+
}
|
|
1902
|
+
};
|
|
1903
|
+
}
|
|
1904
|
+
function setupState$1(el, entries) {
|
|
1905
|
+
if (entries.length === 0) return null;
|
|
1906
|
+
const state = { entries, handler: null };
|
|
1907
|
+
state.handler = createKeydownHandler(state);
|
|
1908
|
+
el.tabIndex = el.tabIndex || -1;
|
|
1909
|
+
el.addEventListener("keydown", state.handler);
|
|
1910
|
+
el.__hotkey = state;
|
|
1911
|
+
return state;
|
|
1912
|
+
}
|
|
1913
|
+
const vHotkey = defineDirective({
|
|
1914
|
+
name: "hotkey",
|
|
1915
|
+
ssr: true,
|
|
1916
|
+
mounted(el, binding) {
|
|
1917
|
+
const entries = normalizeBinding(binding.value, binding.arg, binding.modifiers);
|
|
1918
|
+
setupState$1(el, entries);
|
|
1919
|
+
},
|
|
1920
|
+
updated(el, binding) {
|
|
1921
|
+
const state = el.__hotkey;
|
|
1922
|
+
const newEntries = normalizeBinding(binding.value, binding.arg, binding.modifiers);
|
|
1923
|
+
if (state) {
|
|
1924
|
+
state.entries = newEntries;
|
|
1925
|
+
} else {
|
|
1926
|
+
setupState$1(el, newEntries);
|
|
1927
|
+
}
|
|
1928
|
+
},
|
|
1929
|
+
unmounted(el) {
|
|
1930
|
+
const state = el.__hotkey;
|
|
1931
|
+
if (!state) return;
|
|
1932
|
+
el.removeEventListener("keydown", state.handler);
|
|
1933
|
+
delete el.__hotkey;
|
|
1934
|
+
}
|
|
1935
|
+
});
|
|
1936
|
+
function normalizeOptions$r(binding) {
|
|
1361
1937
|
if (typeof binding === "function") {
|
|
1362
1938
|
return { handler: binding, class: "v-hover" };
|
|
1363
1939
|
}
|
|
@@ -1378,7 +1954,7 @@ const vHover = defineDirective({
|
|
|
1378
1954
|
leaveDelay: 0
|
|
1379
1955
|
},
|
|
1380
1956
|
mounted(el, binding) {
|
|
1381
|
-
const options = normalizeOptions$
|
|
1957
|
+
const options = normalizeOptions$r(binding.value);
|
|
1382
1958
|
if (options.disabled || !isBrowser()) return;
|
|
1383
1959
|
const state = {
|
|
1384
1960
|
options,
|
|
@@ -1431,7 +2007,7 @@ const vHover = defineDirective({
|
|
|
1431
2007
|
updated(el, binding) {
|
|
1432
2008
|
const state = el.__hover;
|
|
1433
2009
|
if (!state) return;
|
|
1434
|
-
const newOptions = normalizeOptions$
|
|
2010
|
+
const newOptions = normalizeOptions$r(binding.value);
|
|
1435
2011
|
if (newOptions.disabled && !state.options.disabled) {
|
|
1436
2012
|
el.classList.remove(state.options.class || "v-hover");
|
|
1437
2013
|
} else if (!newOptions.disabled && state.options.disabled) ;
|
|
@@ -1744,7 +2320,7 @@ function createGestureHandlers(state, transformManager, closePreview) {
|
|
|
1744
2320
|
};
|
|
1745
2321
|
return { handleTouchStart, handleTouchMove, handleTouchEnd, handleMouseDown, handleMouseMove, handleMouseUp, handleWheel };
|
|
1746
2322
|
}
|
|
1747
|
-
function normalizeOptions$
|
|
2323
|
+
function normalizeOptions$q(binding, el) {
|
|
1748
2324
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1749
2325
|
const elSrc = el.tagName === "IMG" ? el.src : void 0;
|
|
1750
2326
|
const elPreviewSrc = el.getAttribute("data-preview") || void 0;
|
|
@@ -1789,7 +2365,7 @@ const vImagePreview = defineDirective({
|
|
|
1789
2365
|
name: "image-preview",
|
|
1790
2366
|
ssr: false,
|
|
1791
2367
|
mounted(el, binding) {
|
|
1792
|
-
const options = normalizeOptions$
|
|
2368
|
+
const options = normalizeOptions$q(binding.value, el);
|
|
1793
2369
|
const state = {
|
|
1794
2370
|
options,
|
|
1795
2371
|
overlay: null,
|
|
@@ -1903,7 +2479,7 @@ const vImagePreview = defineDirective({
|
|
|
1903
2479
|
updated(el, binding) {
|
|
1904
2480
|
const state = el.__imagePreview;
|
|
1905
2481
|
if (!state) return;
|
|
1906
|
-
state.options = normalizeOptions$
|
|
2482
|
+
state.options = normalizeOptions$q(binding.value, el);
|
|
1907
2483
|
el.style.cursor = state.options.disabled ? "" : "zoom-in";
|
|
1908
2484
|
},
|
|
1909
2485
|
unmounted(el) {
|
|
@@ -1925,7 +2501,7 @@ const vImagePreview = defineDirective({
|
|
|
1925
2501
|
delete el.__imagePreview;
|
|
1926
2502
|
}
|
|
1927
2503
|
});
|
|
1928
|
-
function normalizeOptions$
|
|
2504
|
+
function normalizeOptions$p(binding) {
|
|
1929
2505
|
if (typeof binding === "function") {
|
|
1930
2506
|
return { handler: binding, distance: 0, throttle: 200, useIntersection: true };
|
|
1931
2507
|
}
|
|
@@ -1951,7 +2527,7 @@ const vInfiniteScroll = defineDirective({
|
|
|
1951
2527
|
throttle: 200
|
|
1952
2528
|
},
|
|
1953
2529
|
mounted(el, binding) {
|
|
1954
|
-
const options = normalizeOptions$
|
|
2530
|
+
const options = normalizeOptions$p(binding.value);
|
|
1955
2531
|
if (options.disabled || !isBrowser()) return;
|
|
1956
2532
|
let container;
|
|
1957
2533
|
if (options.container) {
|
|
@@ -1997,7 +2573,7 @@ const vInfiniteScroll = defineDirective({
|
|
|
1997
2573
|
updated(el, binding) {
|
|
1998
2574
|
const state = el.__infiniteScroll;
|
|
1999
2575
|
if (!state) return;
|
|
2000
|
-
state.options = normalizeOptions$
|
|
2576
|
+
state.options = normalizeOptions$p(binding.value);
|
|
2001
2577
|
},
|
|
2002
2578
|
unmounted(el) {
|
|
2003
2579
|
const state = el.__infiniteScroll;
|
|
@@ -2074,7 +2650,7 @@ function setupIntersectionObserver(el, state) {
|
|
|
2074
2650
|
state.observer.observe(sentinel);
|
|
2075
2651
|
}
|
|
2076
2652
|
const STATE_KEY$3 = "__intersect";
|
|
2077
|
-
function normalizeOptions$
|
|
2653
|
+
function normalizeOptions$o(binding) {
|
|
2078
2654
|
const options = typeof binding === "function" ? { handler: binding } : __spreadValues({}, binding);
|
|
2079
2655
|
if (options.root !== null && typeof options.root === "object" && "value" in options.root) {
|
|
2080
2656
|
options.root = options.root.value;
|
|
@@ -2116,7 +2692,7 @@ const vIntersect = defineDirective({
|
|
|
2116
2692
|
threshold: 0
|
|
2117
2693
|
},
|
|
2118
2694
|
mounted(el, binding) {
|
|
2119
|
-
const options = normalizeOptions$
|
|
2695
|
+
const options = normalizeOptions$o(binding.value);
|
|
2120
2696
|
if (options.disabled || !isBrowser() || !supportsIntersectionObserver()) {
|
|
2121
2697
|
if (!supportsIntersectionObserver()) {
|
|
2122
2698
|
console.warn("[Directix] v-intersect: IntersectionObserver not supported");
|
|
@@ -2136,7 +2712,7 @@ const vIntersect = defineDirective({
|
|
|
2136
2712
|
var _a, _b, _c;
|
|
2137
2713
|
const state = el[STATE_KEY$3];
|
|
2138
2714
|
if (!state) return;
|
|
2139
|
-
const newOptions = normalizeOptions$
|
|
2715
|
+
const newOptions = normalizeOptions$o(binding.value);
|
|
2140
2716
|
const observerOptionsChanged = newOptions.root !== state.options.root || newOptions.rootMargin !== state.options.rootMargin || newOptions.threshold !== state.options.threshold;
|
|
2141
2717
|
if (newOptions.disabled !== state.options.disabled) {
|
|
2142
2718
|
if (newOptions.disabled) {
|
|
@@ -2250,7 +2826,7 @@ function unobserve(el) {
|
|
|
2250
2826
|
globalObserver.unobserve(el);
|
|
2251
2827
|
}
|
|
2252
2828
|
}
|
|
2253
|
-
function normalizeOptions$
|
|
2829
|
+
function normalizeOptions$n(binding) {
|
|
2254
2830
|
if (typeof binding === "string") {
|
|
2255
2831
|
return { src: binding };
|
|
2256
2832
|
}
|
|
@@ -2265,7 +2841,7 @@ const vLazy = defineDirective({
|
|
|
2265
2841
|
disabled: false
|
|
2266
2842
|
},
|
|
2267
2843
|
mounted(el, binding) {
|
|
2268
|
-
const options = normalizeOptions$
|
|
2844
|
+
const options = normalizeOptions$n(binding.value);
|
|
2269
2845
|
if (options.disabled) return;
|
|
2270
2846
|
if (!options.src) {
|
|
2271
2847
|
console.warn("[Directix] v-lazy: No source provided");
|
|
@@ -2286,7 +2862,7 @@ const vLazy = defineDirective({
|
|
|
2286
2862
|
updated(el, binding) {
|
|
2287
2863
|
const state = el.__lazy;
|
|
2288
2864
|
if (!state) return;
|
|
2289
|
-
const newOptions = normalizeOptions$
|
|
2865
|
+
const newOptions = normalizeOptions$n(binding.value);
|
|
2290
2866
|
if (newOptions.disabled) {
|
|
2291
2867
|
unobserve(el);
|
|
2292
2868
|
return;
|
|
@@ -2309,7 +2885,7 @@ const vLazy = defineDirective({
|
|
|
2309
2885
|
delete el.__lazy;
|
|
2310
2886
|
}
|
|
2311
2887
|
});
|
|
2312
|
-
function normalizeOptions$
|
|
2888
|
+
function normalizeOptions$m(binding) {
|
|
2313
2889
|
if (typeof binding === "boolean") {
|
|
2314
2890
|
return { value: binding };
|
|
2315
2891
|
}
|
|
@@ -2372,7 +2948,7 @@ const vLoading = defineDirective({
|
|
|
2372
2948
|
},
|
|
2373
2949
|
mounted(el, binding) {
|
|
2374
2950
|
if (!isBrowser()) return;
|
|
2375
|
-
const options = normalizeOptions$
|
|
2951
|
+
const options = normalizeOptions$m(binding.value);
|
|
2376
2952
|
if (options.disabled) return;
|
|
2377
2953
|
const computedStyle = getComputedStyle(el);
|
|
2378
2954
|
const originalPosition = el.style.position;
|
|
@@ -2394,7 +2970,7 @@ const vLoading = defineDirective({
|
|
|
2394
2970
|
updated(el, binding) {
|
|
2395
2971
|
const state = el.__loading;
|
|
2396
2972
|
if (!state) return;
|
|
2397
|
-
const newOptions = normalizeOptions$
|
|
2973
|
+
const newOptions = normalizeOptions$m(binding.value);
|
|
2398
2974
|
if (newOptions.disabled) {
|
|
2399
2975
|
hideLoading(el, state);
|
|
2400
2976
|
return;
|
|
@@ -2439,7 +3015,7 @@ function hideLoading(el, state) {
|
|
|
2439
3015
|
}
|
|
2440
3016
|
el.classList.remove("v-loading--active");
|
|
2441
3017
|
}
|
|
2442
|
-
function normalizeOptions$
|
|
3018
|
+
function normalizeOptions$l(binding) {
|
|
2443
3019
|
if (typeof binding === "function") {
|
|
2444
3020
|
return { handler: binding, duration: 500, distance: 10 };
|
|
2445
3021
|
}
|
|
@@ -2470,7 +3046,7 @@ const vLongPress = defineDirective({
|
|
|
2470
3046
|
tickInterval: 100
|
|
2471
3047
|
},
|
|
2472
3048
|
mounted(el, binding) {
|
|
2473
|
-
const options = normalizeOptions$
|
|
3049
|
+
const options = normalizeOptions$l(binding.value);
|
|
2474
3050
|
if (options.disabled || !isBrowser()) return;
|
|
2475
3051
|
const state = {
|
|
2476
3052
|
options,
|
|
@@ -2570,13 +3146,13 @@ const vLongPress = defineDirective({
|
|
|
2570
3146
|
updated(el, binding) {
|
|
2571
3147
|
const state = el.__longPress;
|
|
2572
3148
|
if (!state) {
|
|
2573
|
-
const options = normalizeOptions$
|
|
3149
|
+
const options = normalizeOptions$l(binding.value);
|
|
2574
3150
|
if (!options.disabled) {
|
|
2575
3151
|
el.__longPress = null;
|
|
2576
3152
|
}
|
|
2577
3153
|
return;
|
|
2578
3154
|
}
|
|
2579
|
-
state.options = normalizeOptions$
|
|
3155
|
+
state.options = normalizeOptions$l(binding.value);
|
|
2580
3156
|
},
|
|
2581
3157
|
unmounted(el) {
|
|
2582
3158
|
const state = el.__longPress;
|
|
@@ -2605,7 +3181,7 @@ function transformText$1(text, options) {
|
|
|
2605
3181
|
}
|
|
2606
3182
|
return text.toLowerCase();
|
|
2607
3183
|
}
|
|
2608
|
-
function normalizeOptions$
|
|
3184
|
+
function normalizeOptions$k(binding) {
|
|
2609
3185
|
var _a, _b;
|
|
2610
3186
|
if (binding === void 0 || binding === true) {
|
|
2611
3187
|
return { first: false, onInput: true };
|
|
@@ -2622,7 +3198,7 @@ const vLowercase = defineDirective({
|
|
|
2622
3198
|
name: "lowercase",
|
|
2623
3199
|
ssr: true,
|
|
2624
3200
|
mounted(el, binding) {
|
|
2625
|
-
const options = normalizeOptions$
|
|
3201
|
+
const options = normalizeOptions$k(binding.value);
|
|
2626
3202
|
if (isInputElement(el)) {
|
|
2627
3203
|
const cleanup2 = setupTextTransformInput(el, options, (text) => transformText$1(text, options));
|
|
2628
3204
|
el.__lowercaseCleanup = cleanup2;
|
|
@@ -2631,7 +3207,7 @@ const vLowercase = defineDirective({
|
|
|
2631
3207
|
}
|
|
2632
3208
|
},
|
|
2633
3209
|
updated(el, binding) {
|
|
2634
|
-
const options = normalizeOptions$
|
|
3210
|
+
const options = normalizeOptions$k(binding.value);
|
|
2635
3211
|
if (isInputElement(el)) {
|
|
2636
3212
|
if (options.onInput) {
|
|
2637
3213
|
el.value = transformText$1(el.value, options);
|
|
@@ -2659,7 +3235,7 @@ function parseMask(mask, placeholder) {
|
|
|
2659
3235
|
return pattern ? { pattern, placeholder, isLiteral: false } : { pattern: new RegExp(`\\${char}`), placeholder: char, isLiteral: true };
|
|
2660
3236
|
});
|
|
2661
3237
|
}
|
|
2662
|
-
function normalizeOptions$
|
|
3238
|
+
function normalizeOptions$j(binding) {
|
|
2663
3239
|
if (typeof binding === "string") return { mask: binding, placeholder: "_", showPlaceholder: true };
|
|
2664
3240
|
if (!(binding == null ? void 0 : binding.mask)) throw new Error("[Directix] v-mask: mask is required");
|
|
2665
3241
|
return __spreadValues({ placeholder: "_", showPlaceholder: true, showMaskOnBlur: false, clearIncomplete: false, disabled: false }, binding);
|
|
@@ -2724,7 +3300,7 @@ const vMask = defineDirective({
|
|
|
2724
3300
|
console.warn("[Directix] v-mask: directive must be used on input or textarea elements");
|
|
2725
3301
|
return;
|
|
2726
3302
|
}
|
|
2727
|
-
const options = normalizeOptions$
|
|
3303
|
+
const options = normalizeOptions$j(binding.value);
|
|
2728
3304
|
if (options.disabled || !isBrowser()) return;
|
|
2729
3305
|
const placeholder = options.placeholder || "_";
|
|
2730
3306
|
const tokens = parseMask(options.mask, placeholder);
|
|
@@ -2766,7 +3342,7 @@ const vMask = defineDirective({
|
|
|
2766
3342
|
updated(el, binding) {
|
|
2767
3343
|
const state = el[STATE_KEY$2];
|
|
2768
3344
|
if (!state) return;
|
|
2769
|
-
state.options = normalizeOptions$
|
|
3345
|
+
state.options = normalizeOptions$j(binding.value);
|
|
2770
3346
|
state.tokens = parseMask(state.options.mask, state.placeholder);
|
|
2771
3347
|
},
|
|
2772
3348
|
unmounted(el) {
|
|
@@ -2955,7 +3531,7 @@ const vMoney = defineDirective({
|
|
|
2955
3531
|
delete el.__money;
|
|
2956
3532
|
}
|
|
2957
3533
|
});
|
|
2958
|
-
function normalizeOptions$
|
|
3534
|
+
function normalizeOptions$i(binding) {
|
|
2959
3535
|
if (typeof binding === "function") {
|
|
2960
3536
|
return { handler: binding, childList: true };
|
|
2961
3537
|
}
|
|
@@ -2985,7 +3561,7 @@ const vMutation = defineDirective({
|
|
|
2985
3561
|
disabled: false
|
|
2986
3562
|
},
|
|
2987
3563
|
mounted(el, binding) {
|
|
2988
|
-
const options = normalizeOptions$
|
|
3564
|
+
const options = normalizeOptions$i(binding.value);
|
|
2989
3565
|
if (options.disabled || !isBrowser()) return;
|
|
2990
3566
|
if (!supportsMutationObserver()) {
|
|
2991
3567
|
console.warn("[Directix] v-mutation: MutationObserver not supported");
|
|
@@ -3012,7 +3588,7 @@ const vMutation = defineDirective({
|
|
|
3012
3588
|
updated(el, binding) {
|
|
3013
3589
|
const state = el.__mutation;
|
|
3014
3590
|
if (!state) return;
|
|
3015
|
-
const newOptions = normalizeOptions$
|
|
3591
|
+
const newOptions = normalizeOptions$i(binding.value);
|
|
3016
3592
|
if (newOptions.disabled && !state.options.disabled) {
|
|
3017
3593
|
if (state.observer) {
|
|
3018
3594
|
state.observer.disconnect();
|
|
@@ -3128,7 +3704,7 @@ function configurePermission(config) {
|
|
|
3128
3704
|
function getPermissionConfig() {
|
|
3129
3705
|
return globalConfig;
|
|
3130
3706
|
}
|
|
3131
|
-
function normalizeOptions$
|
|
3707
|
+
function normalizeOptions$h(binding) {
|
|
3132
3708
|
if (!binding) {
|
|
3133
3709
|
throw new Error("[Directix] v-permission: permission value is required");
|
|
3134
3710
|
}
|
|
@@ -3233,7 +3809,7 @@ function getState(el) {
|
|
|
3233
3809
|
function checkPermission(el, binding) {
|
|
3234
3810
|
var _a, _b;
|
|
3235
3811
|
const state = getState(el);
|
|
3236
|
-
state.options = normalizeOptions$
|
|
3812
|
+
state.options = normalizeOptions$h(binding.value);
|
|
3237
3813
|
const granted = verifyPermission(state.options);
|
|
3238
3814
|
(_b = (_a = state.options).onChange) == null ? void 0 : _b.call(_a, granted);
|
|
3239
3815
|
const action = state.options.action || "remove";
|
|
@@ -3263,17 +3839,383 @@ const vPermission = defineDirective({
|
|
|
3263
3839
|
cleanup(el);
|
|
3264
3840
|
}
|
|
3265
3841
|
});
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3842
|
+
const vPrint = defineDirective({
|
|
3843
|
+
name: "print",
|
|
3844
|
+
ssr: true,
|
|
3845
|
+
mounted(el, binding) {
|
|
3846
|
+
const options = normalizeOptions$g(binding.value);
|
|
3847
|
+
const state = {
|
|
3848
|
+
options,
|
|
3849
|
+
clickHandler: null
|
|
3850
|
+
};
|
|
3851
|
+
el.__print = state;
|
|
3852
|
+
if (options.immediate) {
|
|
3853
|
+
setTimeout(() => printElement(el, options), 100);
|
|
3854
|
+
return;
|
|
3855
|
+
}
|
|
3856
|
+
const clickHandler = () => {
|
|
3857
|
+
printElement(el, state.options);
|
|
3858
|
+
};
|
|
3859
|
+
el.addEventListener("click", clickHandler);
|
|
3860
|
+
state.clickHandler = clickHandler;
|
|
3861
|
+
el.style.cursor = "pointer";
|
|
3862
|
+
},
|
|
3863
|
+
updated(el, binding) {
|
|
3864
|
+
const state = el.__print;
|
|
3865
|
+
if (!state) return;
|
|
3866
|
+
const newOptions = normalizeOptions$g(binding.value);
|
|
3867
|
+
state.options = newOptions;
|
|
3868
|
+
},
|
|
3869
|
+
unmounted(el) {
|
|
3870
|
+
const state = el.__print;
|
|
3871
|
+
if (!state) return;
|
|
3872
|
+
if (state.clickHandler) {
|
|
3873
|
+
el.removeEventListener("click", state.clickHandler);
|
|
3874
|
+
}
|
|
3875
|
+
el.style.cursor = "";
|
|
3876
|
+
delete el.__print;
|
|
3877
|
+
}
|
|
3878
|
+
});
|
|
3879
|
+
function normalizeOptions$g(binding) {
|
|
3880
|
+
if (binding === true) {
|
|
3881
|
+
return { immediate: true };
|
|
3882
|
+
}
|
|
3883
|
+
if (binding === false) {
|
|
3884
|
+
return {};
|
|
3885
|
+
}
|
|
3886
|
+
return binding || {};
|
|
3887
|
+
}
|
|
3888
|
+
function printElement(triggerEl, options) {
|
|
3889
|
+
return __async(this, null, function* () {
|
|
3890
|
+
if (options.onBeforePrint) {
|
|
3891
|
+
const result = options.onBeforePrint();
|
|
3892
|
+
if (result === false) return;
|
|
3893
|
+
}
|
|
3894
|
+
const targetEl = options.target ? document.querySelector(options.target) : triggerEl;
|
|
3895
|
+
if (!targetEl) {
|
|
3896
|
+
console.warn("[Directix] v-print: Target element not found");
|
|
3897
|
+
return;
|
|
3898
|
+
}
|
|
3899
|
+
if (options.newWindow) {
|
|
3900
|
+
yield printInNewWindow(targetEl, options);
|
|
3901
|
+
} else {
|
|
3902
|
+
yield printInIframe(targetEl, options);
|
|
3903
|
+
}
|
|
3904
|
+
if (options.onAfterPrint) {
|
|
3905
|
+
options.onAfterPrint();
|
|
3906
|
+
}
|
|
3907
|
+
});
|
|
3908
|
+
}
|
|
3909
|
+
function printInIframe(el, options) {
|
|
3910
|
+
return __async(this, null, function* () {
|
|
3911
|
+
var _a, _b, _c;
|
|
3912
|
+
const iframe = document.createElement("iframe");
|
|
3913
|
+
iframe.style.cssText = "position: absolute; top: -10000px; left: -10000px; width: 0; height: 0; border: none;";
|
|
3914
|
+
document.body.appendChild(iframe);
|
|
3915
|
+
const iframeDoc = iframe.contentDocument || ((_a = iframe.contentWindow) == null ? void 0 : _a.document);
|
|
3916
|
+
if (!iframeDoc) {
|
|
3917
|
+
console.warn("[Directix] v-print: Could not access iframe document");
|
|
3918
|
+
document.body.removeChild(iframe);
|
|
3919
|
+
return;
|
|
3920
|
+
}
|
|
3921
|
+
const content = buildPrintContent(el, options);
|
|
3922
|
+
iframeDoc.open();
|
|
3923
|
+
iframeDoc.write(content);
|
|
3924
|
+
iframeDoc.close();
|
|
3925
|
+
yield waitForImages(iframeDoc);
|
|
3926
|
+
try {
|
|
3927
|
+
(_b = iframe.contentWindow) == null ? void 0 : _b.focus();
|
|
3928
|
+
(_c = iframe.contentWindow) == null ? void 0 : _c.print();
|
|
3929
|
+
} catch (err) {
|
|
3930
|
+
console.error("[Directix] v-print: Print failed", err);
|
|
3931
|
+
}
|
|
3932
|
+
setTimeout(() => {
|
|
3933
|
+
document.body.removeChild(iframe);
|
|
3934
|
+
}, 1e3);
|
|
3935
|
+
});
|
|
3936
|
+
}
|
|
3937
|
+
function printInNewWindow(el, options) {
|
|
3938
|
+
return __async(this, null, function* () {
|
|
3939
|
+
const printWindow = window.open("", "_blank");
|
|
3940
|
+
if (!printWindow) {
|
|
3941
|
+
console.warn("[Directix] v-print: Could not open print window");
|
|
3942
|
+
return;
|
|
3943
|
+
}
|
|
3944
|
+
const content = buildPrintContent(el, options);
|
|
3945
|
+
printWindow.document.open();
|
|
3946
|
+
printWindow.document.write(content);
|
|
3947
|
+
printWindow.document.close();
|
|
3948
|
+
yield waitForImages(printWindow.document);
|
|
3949
|
+
printWindow.focus();
|
|
3950
|
+
printWindow.print();
|
|
3951
|
+
setTimeout(() => {
|
|
3952
|
+
printWindow.close();
|
|
3953
|
+
}, 1e3);
|
|
3954
|
+
});
|
|
3955
|
+
}
|
|
3956
|
+
function buildPrintContent(el, options) {
|
|
3957
|
+
let styles = "";
|
|
3958
|
+
document.querySelectorAll('style, link[rel="stylesheet"]').forEach((styleEl) => {
|
|
3959
|
+
if (styleEl.tagName === "STYLE") {
|
|
3960
|
+
styles += `<style>${styleEl.textContent}</style>`;
|
|
3961
|
+
} else if (styleEl.tagName === "LINK") {
|
|
3962
|
+
const href = styleEl.href;
|
|
3963
|
+
styles += `<link rel="stylesheet" href="${href}">`;
|
|
3964
|
+
}
|
|
3965
|
+
});
|
|
3966
|
+
if (options.cssUrls) {
|
|
3967
|
+
options.cssUrls.forEach((url) => {
|
|
3968
|
+
styles += `<link rel="stylesheet" href="${url}">`;
|
|
3969
|
+
});
|
|
3970
|
+
}
|
|
3971
|
+
if (options.styles) {
|
|
3972
|
+
const customStyles = Array.isArray(options.styles) ? options.styles.join("\n") : options.styles;
|
|
3973
|
+
styles += `<style>${customStyles}</style>`;
|
|
3974
|
+
}
|
|
3975
|
+
styles += `
|
|
3976
|
+
<style>
|
|
3977
|
+
@media print {
|
|
3978
|
+
body { margin: 0; padding: 20px; }
|
|
3979
|
+
${options.printClass ? `.${options.printClass} { page-break-inside: avoid; }` : ""}
|
|
3980
|
+
}
|
|
3981
|
+
</style>
|
|
3982
|
+
`;
|
|
3983
|
+
const title = options.title || document.title || "Print";
|
|
3984
|
+
const content = el.outerHTML;
|
|
3985
|
+
return `<!DOCTYPE html>
|
|
3986
|
+
<html>
|
|
3987
|
+
<head>
|
|
3988
|
+
<meta charset="utf-8">
|
|
3989
|
+
<title>${title}</title>
|
|
3990
|
+
${styles}
|
|
3991
|
+
</head>
|
|
3992
|
+
<body>
|
|
3993
|
+
${content}
|
|
3994
|
+
</body>
|
|
3995
|
+
</html>`;
|
|
3996
|
+
}
|
|
3997
|
+
function waitForImages(doc) {
|
|
3998
|
+
const images = doc.querySelectorAll("img");
|
|
3999
|
+
const promises = [];
|
|
4000
|
+
images.forEach((img) => {
|
|
4001
|
+
if (!img.complete) {
|
|
4002
|
+
promises.push(
|
|
4003
|
+
new Promise((resolve) => {
|
|
4004
|
+
img.onload = () => resolve();
|
|
4005
|
+
img.onerror = () => resolve();
|
|
4006
|
+
})
|
|
4007
|
+
);
|
|
4008
|
+
}
|
|
4009
|
+
});
|
|
4010
|
+
return Promise.all(promises);
|
|
4011
|
+
}
|
|
4012
|
+
const DEFAULT_DISTANCE = 60;
|
|
4013
|
+
const DEFAULT_MAX_DISTANCE = 100;
|
|
4014
|
+
const DEFAULT_SUCCESS_DURATION = 500;
|
|
4015
|
+
const DEFAULT_ERROR_DURATION = 1e3;
|
|
4016
|
+
const DEFAULT_INDICATORS = {
|
|
4017
|
+
idle: "↓",
|
|
4018
|
+
pulling: "↓ Pull",
|
|
4019
|
+
ready: "↓ Release",
|
|
4020
|
+
loading: "⟳ Loading...",
|
|
4021
|
+
success: "✓ Done",
|
|
4022
|
+
error: "✗ Failed"
|
|
4023
|
+
};
|
|
4024
|
+
function normalizeOptions$f(binding) {
|
|
4025
|
+
var _a, _b, _c, _d, _e;
|
|
4026
|
+
if (typeof binding === "function") return { handler: binding };
|
|
4027
|
+
return {
|
|
4028
|
+
handler: binding.handler,
|
|
4029
|
+
distance: (_a = binding.distance) != null ? _a : DEFAULT_DISTANCE,
|
|
4030
|
+
maxDistance: (_b = binding.maxDistance) != null ? _b : DEFAULT_MAX_DISTANCE,
|
|
4031
|
+
disabled: (_c = binding.disabled) != null ? _c : false,
|
|
4032
|
+
indicator: binding.indicator,
|
|
4033
|
+
successDuration: (_d = binding.successDuration) != null ? _d : DEFAULT_SUCCESS_DURATION,
|
|
4034
|
+
errorDuration: (_e = binding.errorDuration) != null ? _e : DEFAULT_ERROR_DURATION,
|
|
4035
|
+
onStateChange: binding.onStateChange
|
|
4036
|
+
};
|
|
4037
|
+
}
|
|
4038
|
+
function createIndicator() {
|
|
4039
|
+
const el = document.createElement("div");
|
|
4040
|
+
el.className = "v-pull-refresh__indicator";
|
|
4041
|
+
el.style.cssText = `
|
|
4042
|
+
position: absolute;
|
|
4043
|
+
top: 0;
|
|
4044
|
+
left: 0;
|
|
4045
|
+
right: 0;
|
|
4046
|
+
height: 60px;
|
|
4047
|
+
display: flex;
|
|
4048
|
+
align-items: center;
|
|
4049
|
+
justify-content: center;
|
|
4050
|
+
background: #f5f5f5;
|
|
4051
|
+
font-size: 14px;
|
|
4052
|
+
color: #666;
|
|
4053
|
+
z-index: 10;
|
|
4054
|
+
pointer-events: none;
|
|
4055
|
+
opacity: 0;
|
|
4056
|
+
transition: opacity 0.2s ease;
|
|
4057
|
+
`;
|
|
4058
|
+
return el;
|
|
4059
|
+
}
|
|
4060
|
+
function updateIndicator(el, state, options) {
|
|
4061
|
+
var _a;
|
|
4062
|
+
const customIndicator = (_a = options.indicator) == null ? void 0 : _a[state];
|
|
4063
|
+
el.textContent = customIndicator || DEFAULT_INDICATORS[state];
|
|
4064
|
+
}
|
|
4065
|
+
function setState(internal, newState) {
|
|
4066
|
+
var _a, _b;
|
|
4067
|
+
if (internal.state === newState) return;
|
|
4068
|
+
internal.state = newState;
|
|
4069
|
+
updateIndicator(internal.indicatorEl, newState, internal.options);
|
|
4070
|
+
(_b = (_a = internal.options).onStateChange) == null ? void 0 : _b.call(_a, newState);
|
|
4071
|
+
}
|
|
4072
|
+
function applyTransform(internal, distance, showIndicator) {
|
|
4073
|
+
internal.contentEl.style.transform = `translateY(${distance}px)`;
|
|
4074
|
+
internal.indicatorEl.style.opacity = "1";
|
|
4075
|
+
internal.indicatorEl.style.transform = `translateY(${distance}px)`;
|
|
4076
|
+
}
|
|
4077
|
+
function resetPosition(internal) {
|
|
4078
|
+
internal.contentEl.style.transform = "";
|
|
4079
|
+
internal.indicatorEl.style.opacity = "0";
|
|
4080
|
+
setState(internal, "idle");
|
|
4081
|
+
}
|
|
4082
|
+
function triggerRefresh(internal) {
|
|
4083
|
+
return __async(this, null, function* () {
|
|
4084
|
+
setState(internal, "loading");
|
|
4085
|
+
const distance = internal.options.distance;
|
|
4086
|
+
applyTransform(internal, distance);
|
|
4087
|
+
try {
|
|
4088
|
+
yield internal.options.handler();
|
|
4089
|
+
setState(internal, "success");
|
|
4090
|
+
yield sleep(internal.options.successDuration);
|
|
4091
|
+
} catch (e) {
|
|
4092
|
+
setState(internal, "error");
|
|
4093
|
+
yield sleep(internal.options.errorDuration);
|
|
4094
|
+
} finally {
|
|
4095
|
+
resetPosition(internal);
|
|
4096
|
+
}
|
|
4097
|
+
});
|
|
4098
|
+
}
|
|
4099
|
+
function sleep(ms) {
|
|
4100
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
4101
|
+
}
|
|
4102
|
+
function createHandlers(internal) {
|
|
4103
|
+
const { contentEl, options } = internal;
|
|
4104
|
+
return {
|
|
4105
|
+
touchStart: (e) => {
|
|
4106
|
+
if (options.disabled || internal.state === "loading") return;
|
|
4107
|
+
if (contentEl.scrollTop > 0) return;
|
|
4108
|
+
internal.pulling = true;
|
|
4109
|
+
internal.startY = e.touches[0].clientY;
|
|
4110
|
+
internal.currentY = internal.startY;
|
|
4111
|
+
setState(internal, "idle");
|
|
4112
|
+
},
|
|
4113
|
+
touchMove: (e) => {
|
|
4114
|
+
if (!internal.pulling || options.disabled || internal.state === "loading") return;
|
|
4115
|
+
internal.currentY = e.touches[0].clientY;
|
|
4116
|
+
const diff = internal.currentY - internal.startY;
|
|
4117
|
+
if (diff <= 0) {
|
|
4118
|
+
if (contentEl.style.transform) {
|
|
4119
|
+
contentEl.style.transition = "";
|
|
4120
|
+
resetPosition(internal);
|
|
4121
|
+
}
|
|
4122
|
+
return;
|
|
4123
|
+
}
|
|
4124
|
+
e.preventDefault();
|
|
4125
|
+
const distance = Math.min(diff * 0.5, options.maxDistance);
|
|
4126
|
+
const progress = distance / options.distance;
|
|
4127
|
+
contentEl.style.transition = "none";
|
|
4128
|
+
applyTransform(internal, distance);
|
|
4129
|
+
setState(internal, progress >= 1 ? "ready" : "pulling");
|
|
4130
|
+
},
|
|
4131
|
+
touchEnd: () => {
|
|
4132
|
+
if (!internal.pulling || options.disabled) return;
|
|
4133
|
+
internal.pulling = false;
|
|
4134
|
+
const diff = internal.currentY - internal.startY;
|
|
4135
|
+
const distance = Math.min(diff * 0.5, options.maxDistance);
|
|
4136
|
+
contentEl.style.transition = "";
|
|
4137
|
+
if (internal.state === "ready" && distance >= options.distance) {
|
|
4138
|
+
triggerRefresh(internal);
|
|
4139
|
+
} else {
|
|
4140
|
+
resetPosition(internal);
|
|
4141
|
+
}
|
|
4142
|
+
}
|
|
4143
|
+
};
|
|
4144
|
+
}
|
|
4145
|
+
function bindEvents$1(el, handlers) {
|
|
4146
|
+
el.addEventListener("touchstart", handlers.touchStart, { passive: false });
|
|
4147
|
+
el.addEventListener("touchmove", handlers.touchMove, { passive: false });
|
|
4148
|
+
el.addEventListener("touchend", handlers.touchEnd, { passive: true });
|
|
4149
|
+
}
|
|
4150
|
+
function unbindEvents$1(el, handlers) {
|
|
4151
|
+
el.removeEventListener("touchstart", handlers.touchStart);
|
|
4152
|
+
el.removeEventListener("touchmove", handlers.touchMove);
|
|
4153
|
+
el.removeEventListener("touchend", handlers.touchEnd);
|
|
4154
|
+
}
|
|
4155
|
+
const vPullRefresh = defineDirective({
|
|
4156
|
+
name: "pull-refresh",
|
|
4157
|
+
ssr: false,
|
|
4158
|
+
mounted(el, binding) {
|
|
4159
|
+
const options = normalizeOptions$f(binding.value);
|
|
4160
|
+
el.style.position = "relative";
|
|
4161
|
+
el.style.overflow = "hidden";
|
|
4162
|
+
el.classList.add("v-pull-refresh");
|
|
4163
|
+
const contentEl = document.createElement("div");
|
|
4164
|
+
contentEl.className = "v-pull-refresh__content";
|
|
4165
|
+
contentEl.style.cssText = "position: relative; height: 100%; overflow-y: auto;";
|
|
4166
|
+
while (el.firstChild) {
|
|
4167
|
+
contentEl.appendChild(el.firstChild);
|
|
4168
|
+
}
|
|
4169
|
+
el.appendChild(contentEl);
|
|
4170
|
+
const indicatorEl = createIndicator();
|
|
4171
|
+
el.insertBefore(indicatorEl, contentEl);
|
|
4172
|
+
const internal = {
|
|
4173
|
+
options,
|
|
4174
|
+
state: "idle",
|
|
4175
|
+
startY: 0,
|
|
4176
|
+
currentY: 0,
|
|
4177
|
+
pulling: false,
|
|
4178
|
+
indicatorEl,
|
|
4179
|
+
contentEl,
|
|
4180
|
+
handlers: null
|
|
4181
|
+
};
|
|
4182
|
+
internal.handlers = createHandlers(internal);
|
|
4183
|
+
el.__pullRefresh = internal;
|
|
4184
|
+
if (!options.disabled) {
|
|
4185
|
+
bindEvents$1(el, internal.handlers);
|
|
4186
|
+
}
|
|
4187
|
+
updateIndicator(indicatorEl, "idle", options);
|
|
4188
|
+
},
|
|
4189
|
+
updated(el, binding) {
|
|
4190
|
+
const internal = el.__pullRefresh;
|
|
4191
|
+
if (!internal) return;
|
|
4192
|
+
const wasDisabled = internal.options.disabled;
|
|
4193
|
+
internal.options = normalizeOptions$f(binding.value);
|
|
4194
|
+
updateIndicator(internal.indicatorEl, internal.state, internal.options);
|
|
4195
|
+
if (internal.options.disabled && !wasDisabled) {
|
|
4196
|
+
unbindEvents$1(el, internal.handlers);
|
|
4197
|
+
} else if (!internal.options.disabled && wasDisabled) {
|
|
4198
|
+
bindEvents$1(el, internal.handlers);
|
|
4199
|
+
}
|
|
4200
|
+
},
|
|
4201
|
+
unmounted(el) {
|
|
4202
|
+
const internal = el.__pullRefresh;
|
|
4203
|
+
if (!internal) return;
|
|
4204
|
+
unbindEvents$1(el, internal.handlers);
|
|
4205
|
+
delete el.__pullRefresh;
|
|
4206
|
+
}
|
|
4207
|
+
});
|
|
4208
|
+
function getResizeInfo(entry) {
|
|
4209
|
+
return {
|
|
4210
|
+
width: entry.contentRect.width,
|
|
4211
|
+
height: entry.contentRect.height,
|
|
4212
|
+
contentRect: entry.contentRect,
|
|
4213
|
+
borderBoxSize: entry.borderBoxSize,
|
|
3272
4214
|
contentBoxSize: entry.contentBoxSize,
|
|
3273
4215
|
devicePixelContentBoxSize: entry.devicePixelContentBoxSize
|
|
3274
4216
|
};
|
|
3275
4217
|
}
|
|
3276
|
-
function normalizeOptions$
|
|
4218
|
+
function normalizeOptions$e(binding) {
|
|
3277
4219
|
if (typeof binding === "function") {
|
|
3278
4220
|
return { handler: binding };
|
|
3279
4221
|
}
|
|
@@ -3322,7 +4264,7 @@ const vResize = defineDirective({
|
|
|
3322
4264
|
debounce: 0
|
|
3323
4265
|
},
|
|
3324
4266
|
mounted(el, binding) {
|
|
3325
|
-
const options = normalizeOptions$
|
|
4267
|
+
const options = normalizeOptions$e(binding.value);
|
|
3326
4268
|
if (options.disabled || !isBrowser()) return;
|
|
3327
4269
|
const computedStyle = getComputedStyle(el);
|
|
3328
4270
|
if (computedStyle.position === "static") {
|
|
@@ -3382,7 +4324,7 @@ const vResize = defineDirective({
|
|
|
3382
4324
|
updated(el, binding) {
|
|
3383
4325
|
const state = el.__resize;
|
|
3384
4326
|
if (!state) return;
|
|
3385
|
-
state.options = normalizeOptions$
|
|
4327
|
+
state.options = normalizeOptions$e(binding.value);
|
|
3386
4328
|
},
|
|
3387
4329
|
unmounted(el) {
|
|
3388
4330
|
const state = el.__resize;
|
|
@@ -3401,7 +4343,7 @@ const vResize = defineDirective({
|
|
|
3401
4343
|
delete el.__resizeCleanup;
|
|
3402
4344
|
}
|
|
3403
4345
|
});
|
|
3404
|
-
function normalizeOptions$
|
|
4346
|
+
function normalizeOptions$d(binding) {
|
|
3405
4347
|
if (binding === false) {
|
|
3406
4348
|
return { disabled: true, color: "currentColor", duration: 600 };
|
|
3407
4349
|
}
|
|
@@ -3478,7 +4420,7 @@ const vRipple = defineDirective({
|
|
|
3478
4420
|
finalScale: 2
|
|
3479
4421
|
},
|
|
3480
4422
|
mounted(el, binding) {
|
|
3481
|
-
const options = normalizeOptions$
|
|
4423
|
+
const options = normalizeOptions$d(binding.value);
|
|
3482
4424
|
if (options.disabled || !isBrowser()) return;
|
|
3483
4425
|
const computedStyle = getComputedStyle(el);
|
|
3484
4426
|
if (computedStyle.position === "static") {
|
|
@@ -3506,7 +4448,7 @@ const vRipple = defineDirective({
|
|
|
3506
4448
|
updated(el, binding) {
|
|
3507
4449
|
const state = el.__ripple;
|
|
3508
4450
|
if (!state) return;
|
|
3509
|
-
state.options = normalizeOptions$
|
|
4451
|
+
state.options = normalizeOptions$d(binding.value);
|
|
3510
4452
|
},
|
|
3511
4453
|
unmounted(el) {
|
|
3512
4454
|
const state = el.__ripple;
|
|
@@ -3520,7 +4462,7 @@ const DEFAULT_ALLOWED_TAGS = ["b", "i", "u", "strong", "em", "br", "p", "span",
|
|
|
3520
4462
|
const DEFAULT_ALLOWED_ATTRIBUTES = ["title", "alt", "href", "src"];
|
|
3521
4463
|
const DANGEROUS_TAGS = ["script", "iframe", "object", "embed", "form", "input", "style", "link", "meta", "base"];
|
|
3522
4464
|
const DANGEROUS_ATTRIBUTES = ["onclick", "onerror", "onload", "onmouseover", "onfocus", "onblur", "onchange", "onsubmit"];
|
|
3523
|
-
function normalizeOptions$
|
|
4465
|
+
function normalizeOptions$c(binding) {
|
|
3524
4466
|
if (binding === false) {
|
|
3525
4467
|
return { disabled: true };
|
|
3526
4468
|
}
|
|
@@ -3611,7 +4553,7 @@ const vSanitize = defineDirective({
|
|
|
3611
4553
|
},
|
|
3612
4554
|
mounted(el, binding) {
|
|
3613
4555
|
if (!isBrowser()) return;
|
|
3614
|
-
const options = normalizeOptions$
|
|
4556
|
+
const options = normalizeOptions$c(binding.value);
|
|
3615
4557
|
if (options.disabled) return;
|
|
3616
4558
|
el.__sanitize = { options };
|
|
3617
4559
|
const content = el.innerHTML;
|
|
@@ -3622,7 +4564,7 @@ const vSanitize = defineDirective({
|
|
|
3622
4564
|
updated(el, binding) {
|
|
3623
4565
|
const state = el.__sanitize;
|
|
3624
4566
|
if (!state) return;
|
|
3625
|
-
state.options = normalizeOptions$
|
|
4567
|
+
state.options = normalizeOptions$c(binding.value);
|
|
3626
4568
|
if (state.options.disabled || !state.options.sanitizeOnUpdate) return;
|
|
3627
4569
|
const content = el.innerHTML;
|
|
3628
4570
|
if (content) {
|
|
@@ -3663,7 +4605,7 @@ function getScrollInfo(container, lastScrollLeft, lastScrollTop) {
|
|
|
3663
4605
|
container
|
|
3664
4606
|
};
|
|
3665
4607
|
}
|
|
3666
|
-
function normalizeOptions$
|
|
4608
|
+
function normalizeOptions$b(binding) {
|
|
3667
4609
|
if (typeof binding === "function") {
|
|
3668
4610
|
return { handler: binding, passive: true };
|
|
3669
4611
|
}
|
|
@@ -3685,7 +4627,7 @@ const vScroll = defineDirective({
|
|
|
3685
4627
|
disabled: false
|
|
3686
4628
|
},
|
|
3687
4629
|
mounted(el, binding) {
|
|
3688
|
-
const options = normalizeOptions$
|
|
4630
|
+
const options = normalizeOptions$b(binding.value);
|
|
3689
4631
|
if (options.disabled || !isBrowser()) return;
|
|
3690
4632
|
let container;
|
|
3691
4633
|
if (options.container) {
|
|
@@ -3741,7 +4683,7 @@ const vScroll = defineDirective({
|
|
|
3741
4683
|
updated(el, binding) {
|
|
3742
4684
|
const state = el.__scroll;
|
|
3743
4685
|
if (!state) return;
|
|
3744
|
-
state.options = normalizeOptions$
|
|
4686
|
+
state.options = normalizeOptions$b(binding.value);
|
|
3745
4687
|
},
|
|
3746
4688
|
unmounted(el) {
|
|
3747
4689
|
const state = el.__scroll;
|
|
@@ -3754,7 +4696,7 @@ const vScroll = defineDirective({
|
|
|
3754
4696
|
}
|
|
3755
4697
|
});
|
|
3756
4698
|
const STATE_KEY = "__sticky";
|
|
3757
|
-
function normalizeOptions$
|
|
4699
|
+
function normalizeOptions$a(binding) {
|
|
3758
4700
|
if (binding === false) return { disabled: true, top: 0, zIndex: 100 };
|
|
3759
4701
|
if (typeof binding === "number") return { top: binding, zIndex: 100 };
|
|
3760
4702
|
return __spreadValues({
|
|
@@ -3836,7 +4778,7 @@ const vSticky = defineDirective({
|
|
|
3836
4778
|
ssr: false,
|
|
3837
4779
|
defaults: { top: 0, zIndex: 100, stickyClass: "v-sticky--fixed", disabled: false },
|
|
3838
4780
|
mounted(el, binding) {
|
|
3839
|
-
const options = normalizeOptions$
|
|
4781
|
+
const options = normalizeOptions$a(binding.value);
|
|
3840
4782
|
if (options.disabled || !isBrowser()) return;
|
|
3841
4783
|
const container = getScrollContainer(el, options.container);
|
|
3842
4784
|
const state = {
|
|
@@ -3863,7 +4805,7 @@ const vSticky = defineDirective({
|
|
|
3863
4805
|
updated(el, binding) {
|
|
3864
4806
|
const state = el[STATE_KEY];
|
|
3865
4807
|
if (!state) return;
|
|
3866
|
-
state.options = normalizeOptions$
|
|
4808
|
+
state.options = normalizeOptions$a(binding.value);
|
|
3867
4809
|
checkSticky(el, state);
|
|
3868
4810
|
},
|
|
3869
4811
|
unmounted(el) {
|
|
@@ -3878,7 +4820,193 @@ const vSticky = defineDirective({
|
|
|
3878
4820
|
delete el[STATE_KEY];
|
|
3879
4821
|
}
|
|
3880
4822
|
});
|
|
3881
|
-
|
|
4823
|
+
const DEFAULT_THRESHOLD = 30;
|
|
4824
|
+
const DEFAULT_MAX_TIME = 500;
|
|
4825
|
+
const DEFAULT_DIRECTIONS = ["left", "right", "up", "down"];
|
|
4826
|
+
function getSwipeDirection(deltaX, deltaY, allowedDirections) {
|
|
4827
|
+
const absX = Math.abs(deltaX);
|
|
4828
|
+
const absY = Math.abs(deltaY);
|
|
4829
|
+
if (absX > absY) {
|
|
4830
|
+
const direction = deltaX > 0 ? "right" : "left";
|
|
4831
|
+
return allowedDirections.includes(direction) ? direction : null;
|
|
4832
|
+
} else {
|
|
4833
|
+
const direction = deltaY > 0 ? "down" : "up";
|
|
4834
|
+
return allowedDirections.includes(direction) ? direction : null;
|
|
4835
|
+
}
|
|
4836
|
+
}
|
|
4837
|
+
function normalizeOptions$9(binding) {
|
|
4838
|
+
var _a, _b, _c, _d, _e, _f;
|
|
4839
|
+
if (typeof binding === "function") return { handler: binding };
|
|
4840
|
+
return {
|
|
4841
|
+
handler: binding.handler,
|
|
4842
|
+
threshold: (_a = binding.threshold) != null ? _a : DEFAULT_THRESHOLD,
|
|
4843
|
+
maxTime: (_b = binding.maxTime) != null ? _b : DEFAULT_MAX_TIME,
|
|
4844
|
+
directions: (_c = binding.directions) != null ? _c : [...DEFAULT_DIRECTIONS],
|
|
4845
|
+
preventScrollOnSwipe: (_d = binding.preventScrollOnSwipe) != null ? _d : true,
|
|
4846
|
+
disabled: (_e = binding.disabled) != null ? _e : false,
|
|
4847
|
+
mouse: (_f = binding.mouse) != null ? _f : true,
|
|
4848
|
+
onLeft: binding.onLeft,
|
|
4849
|
+
onRight: binding.onRight,
|
|
4850
|
+
onUp: binding.onUp,
|
|
4851
|
+
onDown: binding.onDown
|
|
4852
|
+
};
|
|
4853
|
+
}
|
|
4854
|
+
function triggerSwipe(state, deltaX, deltaY, deltaTime, event, el) {
|
|
4855
|
+
var _a, _b, _c, _d, _e;
|
|
4856
|
+
const { options } = state;
|
|
4857
|
+
if (deltaTime > ((_a = options.maxTime) != null ? _a : DEFAULT_MAX_TIME)) return;
|
|
4858
|
+
const distance = Math.max(Math.abs(deltaX), Math.abs(deltaY));
|
|
4859
|
+
if (distance < ((_b = options.threshold) != null ? _b : DEFAULT_THRESHOLD)) return;
|
|
4860
|
+
const direction = getSwipeDirection(deltaX, deltaY, (_c = options.directions) != null ? _c : DEFAULT_DIRECTIONS);
|
|
4861
|
+
if (!direction) return;
|
|
4862
|
+
if (options.preventScrollOnSwipe && event.cancelable) {
|
|
4863
|
+
event.preventDefault();
|
|
4864
|
+
}
|
|
4865
|
+
(_d = options.handler) == null ? void 0 : _d.call(options, direction, event);
|
|
4866
|
+
const callbacks = {
|
|
4867
|
+
left: options.onLeft,
|
|
4868
|
+
right: options.onRight,
|
|
4869
|
+
up: options.onUp,
|
|
4870
|
+
down: options.onDown
|
|
4871
|
+
};
|
|
4872
|
+
(_e = callbacks[direction]) == null ? void 0 : _e.call(callbacks);
|
|
4873
|
+
el.dispatchEvent(new CustomEvent("swipe", { detail: { direction, deltaX, deltaY, deltaTime } }));
|
|
4874
|
+
}
|
|
4875
|
+
function createSwipeHandler(el, state) {
|
|
4876
|
+
return (clientX, clientY, event) => {
|
|
4877
|
+
const deltaX = clientX - state.startX;
|
|
4878
|
+
const deltaY = clientY - state.startY;
|
|
4879
|
+
const deltaTime = Date.now() - state.startTime;
|
|
4880
|
+
triggerSwipe(state, deltaX, deltaY, deltaTime, event, el);
|
|
4881
|
+
};
|
|
4882
|
+
}
|
|
4883
|
+
function setupState(el, options) {
|
|
4884
|
+
if (options.disabled) return null;
|
|
4885
|
+
el.style.touchAction = "none";
|
|
4886
|
+
el.style.userSelect = "none";
|
|
4887
|
+
const state = {
|
|
4888
|
+
options,
|
|
4889
|
+
startX: 0,
|
|
4890
|
+
startY: 0,
|
|
4891
|
+
startTime: 0,
|
|
4892
|
+
isActive: false,
|
|
4893
|
+
handlers: null
|
|
4894
|
+
};
|
|
4895
|
+
const handleSwipe = createSwipeHandler(el, state);
|
|
4896
|
+
state.handlers = {
|
|
4897
|
+
touchStart: (e) => {
|
|
4898
|
+
if (state.options.disabled) return;
|
|
4899
|
+
state.startX = e.touches[0].clientX;
|
|
4900
|
+
state.startY = e.touches[0].clientY;
|
|
4901
|
+
state.startTime = Date.now();
|
|
4902
|
+
state.isActive = true;
|
|
4903
|
+
},
|
|
4904
|
+
touchMove: (e) => {
|
|
4905
|
+
if (!state.isActive || state.options.disabled) return;
|
|
4906
|
+
if (state.options.preventScrollOnSwipe) {
|
|
4907
|
+
e.preventDefault();
|
|
4908
|
+
}
|
|
4909
|
+
},
|
|
4910
|
+
touchEnd: (e) => {
|
|
4911
|
+
if (!state.isActive || state.options.disabled) return;
|
|
4912
|
+
state.isActive = false;
|
|
4913
|
+
const touch = e.changedTouches[0];
|
|
4914
|
+
handleSwipe(touch.clientX, touch.clientY, e);
|
|
4915
|
+
},
|
|
4916
|
+
mouseDown: (e) => {
|
|
4917
|
+
if (state.options.disabled) return;
|
|
4918
|
+
state.startX = e.clientX;
|
|
4919
|
+
state.startY = e.clientY;
|
|
4920
|
+
state.startTime = Date.now();
|
|
4921
|
+
state.isActive = true;
|
|
4922
|
+
},
|
|
4923
|
+
mouseUp: (e) => {
|
|
4924
|
+
if (!state.isActive || state.options.disabled) return;
|
|
4925
|
+
state.isActive = false;
|
|
4926
|
+
handleSwipe(e.clientX, e.clientY, e);
|
|
4927
|
+
}
|
|
4928
|
+
};
|
|
4929
|
+
return state;
|
|
4930
|
+
}
|
|
4931
|
+
function bindEvents(el, state) {
|
|
4932
|
+
var _a;
|
|
4933
|
+
const { handlers } = state;
|
|
4934
|
+
const enableMouse = (_a = state.options.mouse) != null ? _a : true;
|
|
4935
|
+
el.addEventListener("touchstart", handlers.touchStart, { passive: true });
|
|
4936
|
+
el.addEventListener("touchmove", handlers.touchMove, { passive: false });
|
|
4937
|
+
el.addEventListener("touchend", handlers.touchEnd);
|
|
4938
|
+
el.addEventListener("touchcancel", handlers.touchEnd);
|
|
4939
|
+
if (enableMouse) {
|
|
4940
|
+
el.addEventListener("mousedown", handlers.mouseDown);
|
|
4941
|
+
el.addEventListener("mouseup", handlers.mouseUp);
|
|
4942
|
+
el.addEventListener("mouseleave", handlers.mouseUp);
|
|
4943
|
+
}
|
|
4944
|
+
}
|
|
4945
|
+
function unbindEvents(el, state) {
|
|
4946
|
+
var _a;
|
|
4947
|
+
const { handlers } = state;
|
|
4948
|
+
const enableMouse = (_a = state.options.mouse) != null ? _a : true;
|
|
4949
|
+
el.removeEventListener("touchstart", handlers.touchStart);
|
|
4950
|
+
el.removeEventListener("touchmove", handlers.touchMove);
|
|
4951
|
+
el.removeEventListener("touchend", handlers.touchEnd);
|
|
4952
|
+
el.removeEventListener("touchcancel", handlers.touchEnd);
|
|
4953
|
+
if (enableMouse) {
|
|
4954
|
+
el.removeEventListener("mousedown", handlers.mouseDown);
|
|
4955
|
+
el.removeEventListener("mouseup", handlers.mouseUp);
|
|
4956
|
+
el.removeEventListener("mouseleave", handlers.mouseUp);
|
|
4957
|
+
}
|
|
4958
|
+
}
|
|
4959
|
+
const vSwipe = defineDirective({
|
|
4960
|
+
name: "swipe",
|
|
4961
|
+
ssr: false,
|
|
4962
|
+
mounted(el, binding) {
|
|
4963
|
+
const options = normalizeOptions$9(binding.value);
|
|
4964
|
+
const state = setupState(el, options);
|
|
4965
|
+
if (!state) return;
|
|
4966
|
+
el.__swipe = state;
|
|
4967
|
+
bindEvents(el, state);
|
|
4968
|
+
},
|
|
4969
|
+
updated(el, binding) {
|
|
4970
|
+
var _a, _b;
|
|
4971
|
+
const state = el.__swipe;
|
|
4972
|
+
const newOptions = normalizeOptions$9(binding.value);
|
|
4973
|
+
if (!state) {
|
|
4974
|
+
const newState = setupState(el, newOptions);
|
|
4975
|
+
if (newState) {
|
|
4976
|
+
el.__swipe = newState;
|
|
4977
|
+
bindEvents(el, newState);
|
|
4978
|
+
}
|
|
4979
|
+
return;
|
|
4980
|
+
}
|
|
4981
|
+
const wasDisabled = state.options.disabled;
|
|
4982
|
+
const wasMouseEnabled = (_a = state.options.mouse) != null ? _a : true;
|
|
4983
|
+
const nowMouseEnabled = (_b = newOptions.mouse) != null ? _b : true;
|
|
4984
|
+
state.options = newOptions;
|
|
4985
|
+
if (newOptions.disabled && !wasDisabled) {
|
|
4986
|
+
unbindEvents(el, state);
|
|
4987
|
+
} else if (!newOptions.disabled && wasDisabled) {
|
|
4988
|
+
bindEvents(el, state);
|
|
4989
|
+
} else if (wasMouseEnabled !== nowMouseEnabled) {
|
|
4990
|
+
if (wasMouseEnabled) {
|
|
4991
|
+
el.removeEventListener("mousedown", state.handlers.mouseDown);
|
|
4992
|
+
el.removeEventListener("mouseup", state.handlers.mouseUp);
|
|
4993
|
+
el.removeEventListener("mouseleave", state.handlers.mouseUp);
|
|
4994
|
+
}
|
|
4995
|
+
if (nowMouseEnabled) {
|
|
4996
|
+
el.addEventListener("mousedown", state.handlers.mouseDown);
|
|
4997
|
+
el.addEventListener("mouseup", state.handlers.mouseUp);
|
|
4998
|
+
el.addEventListener("mouseleave", state.handlers.mouseUp);
|
|
4999
|
+
}
|
|
5000
|
+
}
|
|
5001
|
+
},
|
|
5002
|
+
unmounted(el) {
|
|
5003
|
+
const state = el.__swipe;
|
|
5004
|
+
if (!state) return;
|
|
5005
|
+
unbindEvents(el, state);
|
|
5006
|
+
delete el.__swipe;
|
|
5007
|
+
}
|
|
5008
|
+
});
|
|
5009
|
+
function normalizeOptions$8(binding, directiveBinding) {
|
|
3882
5010
|
const wait = parseTime(directiveBinding.arg) || 300;
|
|
3883
5011
|
if (typeof binding === "function") {
|
|
3884
5012
|
return { handler: binding, wait };
|
|
@@ -3895,7 +5023,7 @@ const vThrottle = defineDirective({
|
|
|
3895
5023
|
trailing: true
|
|
3896
5024
|
},
|
|
3897
5025
|
mounted(el, binding) {
|
|
3898
|
-
const options = normalizeOptions$
|
|
5026
|
+
const options = normalizeOptions$8(binding.value, binding);
|
|
3899
5027
|
const eventType = getEventTypeFromModifiers(binding.modifiers) || getDefaultEventType(el);
|
|
3900
5028
|
const throttledFn = throttle(options.handler, options.wait, {
|
|
3901
5029
|
leading: options.leading,
|
|
@@ -3911,7 +5039,7 @@ const vThrottle = defineDirective({
|
|
|
3911
5039
|
updated(el, binding) {
|
|
3912
5040
|
const state = el.__throttle;
|
|
3913
5041
|
if (!state) return;
|
|
3914
|
-
const newOptions = normalizeOptions$
|
|
5042
|
+
const newOptions = normalizeOptions$8(binding.value, binding);
|
|
3915
5043
|
if (newOptions.wait !== state.options.wait || newOptions.leading !== state.options.leading || newOptions.trailing !== state.options.trailing) {
|
|
3916
5044
|
state.throttledFn.cancel();
|
|
3917
5045
|
const throttledFn = throttle(newOptions.handler, newOptions.wait, {
|
|
@@ -4132,7 +5260,7 @@ function removeTriggerHandlers(el, state) {
|
|
|
4132
5260
|
document.removeEventListener("click", docHide);
|
|
4133
5261
|
}
|
|
4134
5262
|
}
|
|
4135
|
-
function normalizeOptions$
|
|
5263
|
+
function normalizeOptions$7(binding) {
|
|
4136
5264
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
4137
5265
|
if (typeof binding === "string") {
|
|
4138
5266
|
return { content: binding, placement: "top", trigger: "hover" };
|
|
@@ -4170,7 +5298,7 @@ const vTooltip = defineDirective({
|
|
|
4170
5298
|
name: "tooltip",
|
|
4171
5299
|
ssr: false,
|
|
4172
5300
|
mounted(el, binding) {
|
|
4173
|
-
const options = normalizeOptions$
|
|
5301
|
+
const options = normalizeOptions$7(binding.value);
|
|
4174
5302
|
if (options.disabled || !options.content) return;
|
|
4175
5303
|
const state = createState(options);
|
|
4176
5304
|
el.__tooltip = state;
|
|
@@ -4179,7 +5307,7 @@ const vTooltip = defineDirective({
|
|
|
4179
5307
|
},
|
|
4180
5308
|
updated(el, binding) {
|
|
4181
5309
|
const state = el.__tooltip;
|
|
4182
|
-
const newOptions = normalizeOptions$
|
|
5310
|
+
const newOptions = normalizeOptions$7(binding.value);
|
|
4183
5311
|
if (!state) {
|
|
4184
5312
|
if (!newOptions.disabled && newOptions.content) {
|
|
4185
5313
|
const newState = createState(newOptions);
|
|
@@ -4225,7 +5353,7 @@ const vTouch = defineDirective({
|
|
|
4225
5353
|
name: "touch",
|
|
4226
5354
|
ssr: false,
|
|
4227
5355
|
mounted(el, binding) {
|
|
4228
|
-
const options = normalizeOptions$
|
|
5356
|
+
const options = normalizeOptions$6(binding.value);
|
|
4229
5357
|
const state = {
|
|
4230
5358
|
options,
|
|
4231
5359
|
startX: 0,
|
|
@@ -4386,7 +5514,7 @@ const vTouch = defineDirective({
|
|
|
4386
5514
|
},
|
|
4387
5515
|
updated(el, binding) {
|
|
4388
5516
|
const state = el.__touch;
|
|
4389
|
-
if (state) state.options = normalizeOptions$
|
|
5517
|
+
if (state) state.options = normalizeOptions$6(binding.value);
|
|
4390
5518
|
},
|
|
4391
5519
|
unmounted(el) {
|
|
4392
5520
|
const state = el.__touch;
|
|
@@ -4403,7 +5531,7 @@ const vTouch = defineDirective({
|
|
|
4403
5531
|
delete el.__touch;
|
|
4404
5532
|
}
|
|
4405
5533
|
});
|
|
4406
|
-
function normalizeOptions$
|
|
5534
|
+
function normalizeOptions$6(binding) {
|
|
4407
5535
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
4408
5536
|
return {
|
|
4409
5537
|
swipeThreshold: (_a = binding == null ? void 0 : binding.swipeThreshold) != null ? _a : 30,
|
|
@@ -4452,7 +5580,7 @@ const vTrim = defineDirective({
|
|
|
4452
5580
|
name: "trim",
|
|
4453
5581
|
ssr: true,
|
|
4454
5582
|
mounted(el, binding) {
|
|
4455
|
-
const options = normalizeOptions$
|
|
5583
|
+
const options = normalizeOptions$5(binding.value);
|
|
4456
5584
|
if (el.tagName === "INPUT" || el.tagName === "TEXTAREA") {
|
|
4457
5585
|
setupInputElement(el, options);
|
|
4458
5586
|
} else {
|
|
@@ -4461,7 +5589,7 @@ const vTrim = defineDirective({
|
|
|
4461
5589
|
}
|
|
4462
5590
|
},
|
|
4463
5591
|
updated(el, binding) {
|
|
4464
|
-
const options = normalizeOptions$
|
|
5592
|
+
const options = normalizeOptions$5(binding.value);
|
|
4465
5593
|
const state = el.__trim;
|
|
4466
5594
|
if (el.tagName === "INPUT" || el.tagName === "TEXTAREA") {
|
|
4467
5595
|
if (state) {
|
|
@@ -4519,7 +5647,7 @@ function setupInputElement(el, options) {
|
|
|
4519
5647
|
performTrim();
|
|
4520
5648
|
}
|
|
4521
5649
|
}
|
|
4522
|
-
function normalizeOptions$
|
|
5650
|
+
function normalizeOptions$5(binding) {
|
|
4523
5651
|
var _a, _b, _c;
|
|
4524
5652
|
if (binding === void 0 || binding === true) {
|
|
4525
5653
|
return { position: "both", onInput: true, onBlur: true };
|
|
@@ -4559,7 +5687,7 @@ const vTruncate = defineDirective({
|
|
|
4559
5687
|
name: "truncate",
|
|
4560
5688
|
ssr: true,
|
|
4561
5689
|
mounted(el, binding) {
|
|
4562
|
-
const options = normalizeOptions$
|
|
5690
|
+
const options = normalizeOptions$4(binding.value);
|
|
4563
5691
|
const text = el.textContent || "";
|
|
4564
5692
|
const state = {
|
|
4565
5693
|
originalText: text,
|
|
@@ -4570,7 +5698,7 @@ const vTruncate = defineDirective({
|
|
|
4570
5698
|
},
|
|
4571
5699
|
updated(el, binding) {
|
|
4572
5700
|
const state = el.__truncate;
|
|
4573
|
-
const newOptions = normalizeOptions$
|
|
5701
|
+
const newOptions = normalizeOptions$4(binding.value);
|
|
4574
5702
|
if (state) {
|
|
4575
5703
|
const originalText = state.originalText;
|
|
4576
5704
|
if (JSON.stringify(newOptions) !== JSON.stringify(state.options)) {
|
|
@@ -4607,7 +5735,7 @@ function applyTruncation(el, text, options) {
|
|
|
4607
5735
|
}
|
|
4608
5736
|
}
|
|
4609
5737
|
}
|
|
4610
|
-
function normalizeOptions$
|
|
5738
|
+
function normalizeOptions$4(binding) {
|
|
4611
5739
|
var _a, _b, _c, _d, _e;
|
|
4612
5740
|
if (typeof binding === "number") {
|
|
4613
5741
|
return {
|
|
@@ -4633,7 +5761,7 @@ function transformText(text, options) {
|
|
|
4633
5761
|
}
|
|
4634
5762
|
return text.toUpperCase();
|
|
4635
5763
|
}
|
|
4636
|
-
function normalizeOptions$
|
|
5764
|
+
function normalizeOptions$3(binding) {
|
|
4637
5765
|
var _a, _b;
|
|
4638
5766
|
if (binding === void 0 || binding === true) {
|
|
4639
5767
|
return { first: false, onInput: true };
|
|
@@ -4650,7 +5778,7 @@ const vUppercase = defineDirective({
|
|
|
4650
5778
|
name: "uppercase",
|
|
4651
5779
|
ssr: true,
|
|
4652
5780
|
mounted(el, binding) {
|
|
4653
|
-
const options = normalizeOptions$
|
|
5781
|
+
const options = normalizeOptions$3(binding.value);
|
|
4654
5782
|
if (isInputElement(el)) {
|
|
4655
5783
|
const cleanup2 = setupTextTransformInput(el, options, (text) => transformText(text, options));
|
|
4656
5784
|
el.__uppercaseCleanup = cleanup2;
|
|
@@ -4659,7 +5787,7 @@ const vUppercase = defineDirective({
|
|
|
4659
5787
|
}
|
|
4660
5788
|
},
|
|
4661
5789
|
updated(el, binding) {
|
|
4662
|
-
const options = normalizeOptions$
|
|
5790
|
+
const options = normalizeOptions$3(binding.value);
|
|
4663
5791
|
if (isInputElement(el)) {
|
|
4664
5792
|
if (options.onInput) {
|
|
4665
5793
|
el.value = transformText(el.value, options);
|
|
@@ -4674,7 +5802,212 @@ const vUppercase = defineDirective({
|
|
|
4674
5802
|
delete el.__uppercaseCleanup;
|
|
4675
5803
|
}
|
|
4676
5804
|
});
|
|
4677
|
-
function
|
|
5805
|
+
function getItemSize(options, index) {
|
|
5806
|
+
if (typeof options.itemSize === "function") {
|
|
5807
|
+
return options.itemSize(index);
|
|
5808
|
+
}
|
|
5809
|
+
return options.itemSize || 50;
|
|
5810
|
+
}
|
|
5811
|
+
function calculateTotalHeight(options) {
|
|
5812
|
+
if (typeof options.itemSize === "function") {
|
|
5813
|
+
let total = 0;
|
|
5814
|
+
for (let i = 0; i < options.items.length; i++) {
|
|
5815
|
+
total += options.itemSize(i);
|
|
5816
|
+
}
|
|
5817
|
+
return total;
|
|
5818
|
+
}
|
|
5819
|
+
return (options.itemSize || 50) * options.items.length;
|
|
5820
|
+
}
|
|
5821
|
+
function calculateVisibleRange(scrollTop, containerHeight, options) {
|
|
5822
|
+
const items = options.items;
|
|
5823
|
+
const itemSize = options.itemSize || 50;
|
|
5824
|
+
const overscan = options.overscan || 3;
|
|
5825
|
+
let startIndex = 0, endIndex = 0, offsetY = 0;
|
|
5826
|
+
if (typeof itemSize === "function") {
|
|
5827
|
+
let currentOffset = 0;
|
|
5828
|
+
for (let i = 0; i < items.length; i++) {
|
|
5829
|
+
const size = itemSize(i);
|
|
5830
|
+
if (currentOffset + size > scrollTop) {
|
|
5831
|
+
startIndex = i;
|
|
5832
|
+
offsetY = currentOffset;
|
|
5833
|
+
break;
|
|
5834
|
+
}
|
|
5835
|
+
currentOffset += size;
|
|
5836
|
+
}
|
|
5837
|
+
endIndex = startIndex;
|
|
5838
|
+
currentOffset = offsetY;
|
|
5839
|
+
while (endIndex < items.length && currentOffset < scrollTop + containerHeight) {
|
|
5840
|
+
currentOffset += itemSize(endIndex);
|
|
5841
|
+
endIndex++;
|
|
5842
|
+
}
|
|
5843
|
+
startIndex = Math.max(0, startIndex - overscan);
|
|
5844
|
+
endIndex = Math.min(items.length, endIndex + overscan);
|
|
5845
|
+
currentOffset = 0;
|
|
5846
|
+
for (let i = 0; i < startIndex; i++) {
|
|
5847
|
+
currentOffset += itemSize(i);
|
|
5848
|
+
}
|
|
5849
|
+
offsetY = currentOffset;
|
|
5850
|
+
return { startIndex, endIndex, offsetY };
|
|
5851
|
+
}
|
|
5852
|
+
startIndex = Math.max(0, Math.floor(scrollTop / itemSize) - overscan);
|
|
5853
|
+
endIndex = Math.min(items.length, Math.ceil((scrollTop + containerHeight) / itemSize) + overscan);
|
|
5854
|
+
offsetY = startIndex * itemSize;
|
|
5855
|
+
return { startIndex, endIndex, offsetY };
|
|
5856
|
+
}
|
|
5857
|
+
function normalizeOptions$2(binding) {
|
|
5858
|
+
var _a, _b, _c, _d;
|
|
5859
|
+
if (Array.isArray(binding)) {
|
|
5860
|
+
return {
|
|
5861
|
+
items: binding,
|
|
5862
|
+
itemSize: 50,
|
|
5863
|
+
height: 400,
|
|
5864
|
+
overscan: 3,
|
|
5865
|
+
keyField: "id"
|
|
5866
|
+
};
|
|
5867
|
+
}
|
|
5868
|
+
return {
|
|
5869
|
+
items: binding.items,
|
|
5870
|
+
itemSize: (_a = binding.itemSize) != null ? _a : 50,
|
|
5871
|
+
height: (_b = binding.height) != null ? _b : 400,
|
|
5872
|
+
overscan: (_c = binding.overscan) != null ? _c : 3,
|
|
5873
|
+
render: binding.render,
|
|
5874
|
+
keyField: (_d = binding.keyField) != null ? _d : "id",
|
|
5875
|
+
onScroll: binding.onScroll,
|
|
5876
|
+
onVisibleChange: binding.onVisibleChange
|
|
5877
|
+
};
|
|
5878
|
+
}
|
|
5879
|
+
function createItemElement(item, index, options) {
|
|
5880
|
+
const el = document.createElement("div");
|
|
5881
|
+
el.className = "v-virtual-list__item";
|
|
5882
|
+
el.dataset.index = String(index);
|
|
5883
|
+
const keyField = options.keyField || "id";
|
|
5884
|
+
if (typeof item === "object" && item !== null && keyField in item) {
|
|
5885
|
+
el.dataset.key = String(item[keyField]);
|
|
5886
|
+
}
|
|
5887
|
+
const height = getItemSize(options, index);
|
|
5888
|
+
el.style.height = `${height}px`;
|
|
5889
|
+
el.style.boxSizing = "border-box";
|
|
5890
|
+
if (options.render) {
|
|
5891
|
+
el.innerHTML = options.render(item, index);
|
|
5892
|
+
} else {
|
|
5893
|
+
el.textContent = typeof item === "object" ? JSON.stringify(item) : String(item);
|
|
5894
|
+
}
|
|
5895
|
+
return el;
|
|
5896
|
+
}
|
|
5897
|
+
const vVirtualList = defineDirective({
|
|
5898
|
+
name: "virtual-list",
|
|
5899
|
+
ssr: false,
|
|
5900
|
+
mounted(el, binding) {
|
|
5901
|
+
const options = normalizeOptions$2(binding.value);
|
|
5902
|
+
el.classList.add("v-virtual-list");
|
|
5903
|
+
el.style.height = typeof options.height === "number" ? `${options.height}px` : options.height;
|
|
5904
|
+
el.style.overflow = "auto";
|
|
5905
|
+
el.style.position = "relative";
|
|
5906
|
+
const contentEl = document.createElement("div");
|
|
5907
|
+
contentEl.className = "v-virtual-list__content";
|
|
5908
|
+
contentEl.style.position = "relative";
|
|
5909
|
+
contentEl.style.height = `${calculateTotalHeight(options)}px`;
|
|
5910
|
+
el.appendChild(contentEl);
|
|
5911
|
+
const visibleEl = document.createElement("div");
|
|
5912
|
+
visibleEl.className = "v-virtual-list__visible";
|
|
5913
|
+
visibleEl.style.position = "absolute";
|
|
5914
|
+
visibleEl.style.top = "0";
|
|
5915
|
+
visibleEl.style.left = "0";
|
|
5916
|
+
visibleEl.style.right = "0";
|
|
5917
|
+
contentEl.appendChild(visibleEl);
|
|
5918
|
+
const state = {
|
|
5919
|
+
options,
|
|
5920
|
+
containerEl: el,
|
|
5921
|
+
contentEl,
|
|
5922
|
+
scrollHandler: null,
|
|
5923
|
+
resizeObserver: null,
|
|
5924
|
+
startIndex: 0,
|
|
5925
|
+
endIndex: 0,
|
|
5926
|
+
visibleItems: []
|
|
5927
|
+
};
|
|
5928
|
+
el.__virtualList = state;
|
|
5929
|
+
const scrollHandler = (_event) => {
|
|
5930
|
+
const scrollTop = el.scrollTop;
|
|
5931
|
+
const containerHeight = el.clientHeight;
|
|
5932
|
+
const { startIndex: startIndex2, endIndex: endIndex2, offsetY: offsetY2 } = calculateVisibleRange(
|
|
5933
|
+
scrollTop,
|
|
5934
|
+
containerHeight,
|
|
5935
|
+
state.options
|
|
5936
|
+
);
|
|
5937
|
+
if (startIndex2 !== state.startIndex || endIndex2 !== state.endIndex) {
|
|
5938
|
+
state.startIndex = startIndex2;
|
|
5939
|
+
state.endIndex = endIndex2;
|
|
5940
|
+
renderVisibleItems(visibleEl, state, offsetY2);
|
|
5941
|
+
if (state.options.onVisibleChange) {
|
|
5942
|
+
state.options.onVisibleChange(startIndex2, endIndex2);
|
|
5943
|
+
}
|
|
5944
|
+
}
|
|
5945
|
+
if (state.options.onScroll) {
|
|
5946
|
+
state.options.onScroll(scrollTop);
|
|
5947
|
+
}
|
|
5948
|
+
};
|
|
5949
|
+
state.scrollHandler = scrollHandler;
|
|
5950
|
+
el.addEventListener("scroll", scrollHandler, { passive: true });
|
|
5951
|
+
const { startIndex, endIndex, offsetY } = calculateVisibleRange(0, el.clientHeight, options);
|
|
5952
|
+
state.startIndex = startIndex;
|
|
5953
|
+
state.endIndex = endIndex;
|
|
5954
|
+
renderVisibleItems(visibleEl, state, offsetY);
|
|
5955
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
5956
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
5957
|
+
scrollHandler(new Event("scroll"));
|
|
5958
|
+
});
|
|
5959
|
+
resizeObserver.observe(el);
|
|
5960
|
+
state.resizeObserver = resizeObserver;
|
|
5961
|
+
}
|
|
5962
|
+
},
|
|
5963
|
+
updated(el, binding) {
|
|
5964
|
+
var _a;
|
|
5965
|
+
const state = el.__virtualList;
|
|
5966
|
+
if (!state) return;
|
|
5967
|
+
const newOptions = normalizeOptions$2(binding.value);
|
|
5968
|
+
state.options = newOptions;
|
|
5969
|
+
if (state.contentEl) {
|
|
5970
|
+
state.contentEl.style.height = `${calculateTotalHeight(newOptions)}px`;
|
|
5971
|
+
}
|
|
5972
|
+
const scrollTop = el.scrollTop;
|
|
5973
|
+
const containerHeight = el.clientHeight;
|
|
5974
|
+
const { startIndex, endIndex, offsetY } = calculateVisibleRange(
|
|
5975
|
+
scrollTop,
|
|
5976
|
+
containerHeight,
|
|
5977
|
+
newOptions
|
|
5978
|
+
);
|
|
5979
|
+
state.startIndex = startIndex;
|
|
5980
|
+
state.endIndex = endIndex;
|
|
5981
|
+
const visibleEl = (_a = state.contentEl) == null ? void 0 : _a.querySelector(".v-virtual-list__visible");
|
|
5982
|
+
if (visibleEl) {
|
|
5983
|
+
renderVisibleItems(visibleEl, state, offsetY);
|
|
5984
|
+
}
|
|
5985
|
+
},
|
|
5986
|
+
unmounted(el) {
|
|
5987
|
+
const state = el.__virtualList;
|
|
5988
|
+
if (!state) return;
|
|
5989
|
+
if (state.scrollHandler) {
|
|
5990
|
+
el.removeEventListener("scroll", state.scrollHandler);
|
|
5991
|
+
}
|
|
5992
|
+
if (state.resizeObserver) {
|
|
5993
|
+
state.resizeObserver.disconnect();
|
|
5994
|
+
}
|
|
5995
|
+
delete el.__virtualList;
|
|
5996
|
+
}
|
|
5997
|
+
});
|
|
5998
|
+
function renderVisibleItems(visibleEl, state, offsetY) {
|
|
5999
|
+
const { options, startIndex, endIndex } = state;
|
|
6000
|
+
visibleEl.style.transform = `translateY(${offsetY}px)`;
|
|
6001
|
+
visibleEl.innerHTML = "";
|
|
6002
|
+
for (let i = startIndex; i < endIndex; i++) {
|
|
6003
|
+
const item = options.items[i];
|
|
6004
|
+
if (item !== void 0) {
|
|
6005
|
+
const itemEl = createItemElement(item, i, options);
|
|
6006
|
+
visibleEl.appendChild(itemEl);
|
|
6007
|
+
}
|
|
6008
|
+
}
|
|
6009
|
+
}
|
|
6010
|
+
function normalizeOptions$1(binding) {
|
|
4678
6011
|
if (typeof binding === "boolean") {
|
|
4679
6012
|
return { initial: binding };
|
|
4680
6013
|
}
|
|
@@ -4696,7 +6029,7 @@ const vVisible = defineDirective({
|
|
|
4696
6029
|
mounted(el, binding) {
|
|
4697
6030
|
var _a, _b;
|
|
4698
6031
|
if (!isBrowser()) return;
|
|
4699
|
-
const options = normalizeOptions(binding.value);
|
|
6032
|
+
const options = normalizeOptions$1(binding.value);
|
|
4700
6033
|
const originalDisplay = el.style.display;
|
|
4701
6034
|
const originalVisibility = el.style.visibility;
|
|
4702
6035
|
const state = {
|
|
@@ -4720,7 +6053,7 @@ const vVisible = defineDirective({
|
|
|
4720
6053
|
var _a;
|
|
4721
6054
|
const state = el.__visible;
|
|
4722
6055
|
if (!state) return;
|
|
4723
|
-
const newOptions = normalizeOptions(binding.value);
|
|
6056
|
+
const newOptions = normalizeOptions$1(binding.value);
|
|
4724
6057
|
let newVisibility;
|
|
4725
6058
|
if (typeof binding.value === "boolean") {
|
|
4726
6059
|
newVisibility = binding.value;
|
|
@@ -4781,12 +6114,178 @@ function applyVisibility(el, state, isVisible) {
|
|
|
4781
6114
|
state.options.handler(isVisible);
|
|
4782
6115
|
}
|
|
4783
6116
|
}
|
|
6117
|
+
function createWatermarkCanvas(options) {
|
|
6118
|
+
var _a;
|
|
6119
|
+
const canvas = document.createElement("canvas");
|
|
6120
|
+
const ctx = canvas.getContext("2d");
|
|
6121
|
+
if (!ctx) {
|
|
6122
|
+
throw new Error("[Directix] v-watermark: Could not get canvas context");
|
|
6123
|
+
}
|
|
6124
|
+
const width = options.width || 300;
|
|
6125
|
+
const height = options.height || 200;
|
|
6126
|
+
const fontSize = options.fontSize || 16;
|
|
6127
|
+
const fontFamily = options.fontFamily || "sans-serif";
|
|
6128
|
+
const fontWeight = options.fontWeight || "normal";
|
|
6129
|
+
const color = options.color || "rgba(128, 128, 128, 0.15)";
|
|
6130
|
+
const rotate = (_a = options.rotate) != null ? _a : -22;
|
|
6131
|
+
canvas.width = width;
|
|
6132
|
+
canvas.height = height;
|
|
6133
|
+
ctx.font = `${fontWeight} ${fontSize}px ${fontFamily}`;
|
|
6134
|
+
ctx.fillStyle = color;
|
|
6135
|
+
ctx.textAlign = "center";
|
|
6136
|
+
ctx.textBaseline = "middle";
|
|
6137
|
+
ctx.translate(width / 2, height / 2);
|
|
6138
|
+
ctx.rotate(rotate * Math.PI / 180);
|
|
6139
|
+
const content = Array.isArray(options.content) ? options.content : [options.content];
|
|
6140
|
+
const lineHeight = fontSize * 1.5;
|
|
6141
|
+
const startY = -((content.length - 1) * lineHeight) / 2;
|
|
6142
|
+
content.forEach((text, index) => {
|
|
6143
|
+
ctx.fillText(text, 0, startY + index * lineHeight);
|
|
6144
|
+
});
|
|
6145
|
+
return canvas;
|
|
6146
|
+
}
|
|
6147
|
+
function createWatermarkElement(canvas, options) {
|
|
6148
|
+
var _a;
|
|
6149
|
+
const gap = Array.isArray(options.gap) ? options.gap : [options.gap || 100, options.gap || 100];
|
|
6150
|
+
const zIndex = (_a = options.zIndex) != null ? _a : 9999;
|
|
6151
|
+
const el = document.createElement("div");
|
|
6152
|
+
el.className = "v-watermark";
|
|
6153
|
+
el.style.cssText = `
|
|
6154
|
+
position: absolute;
|
|
6155
|
+
top: 0;
|
|
6156
|
+
left: 0;
|
|
6157
|
+
width: 100%;
|
|
6158
|
+
height: 100%;
|
|
6159
|
+
pointer-events: none;
|
|
6160
|
+
z-index: ${zIndex};
|
|
6161
|
+
background-image: url("${canvas.toDataURL()}");
|
|
6162
|
+
background-repeat: repeat;
|
|
6163
|
+
background-position: ${gap[0] / 2}px ${gap[1] / 2}px;
|
|
6164
|
+
background-size: ${canvas.width + gap[0]}px ${canvas.height + gap[1]}px;
|
|
6165
|
+
`;
|
|
6166
|
+
return el;
|
|
6167
|
+
}
|
|
6168
|
+
function normalizeOptions(binding) {
|
|
6169
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
6170
|
+
if (typeof binding === "string") {
|
|
6171
|
+
return { content: binding };
|
|
6172
|
+
}
|
|
6173
|
+
return {
|
|
6174
|
+
content: binding.content,
|
|
6175
|
+
width: (_a = binding.width) != null ? _a : 300,
|
|
6176
|
+
height: (_b = binding.height) != null ? _b : 200,
|
|
6177
|
+
rotate: (_c = binding.rotate) != null ? _c : -22,
|
|
6178
|
+
fontSize: (_d = binding.fontSize) != null ? _d : 16,
|
|
6179
|
+
fontFamily: (_e = binding.fontFamily) != null ? _e : "sans-serif",
|
|
6180
|
+
fontWeight: (_f = binding.fontWeight) != null ? _f : "normal",
|
|
6181
|
+
color: (_g = binding.color) != null ? _g : "rgba(128, 128, 128, 0.15)",
|
|
6182
|
+
gap: (_h = binding.gap) != null ? _h : [100, 100],
|
|
6183
|
+
zIndex: (_i = binding.zIndex) != null ? _i : 9999,
|
|
6184
|
+
disabled: (_j = binding.disabled) != null ? _j : false,
|
|
6185
|
+
protect: (_k = binding.protect) != null ? _k : true
|
|
6186
|
+
};
|
|
6187
|
+
}
|
|
6188
|
+
const vWatermark = defineDirective({
|
|
6189
|
+
name: "watermark",
|
|
6190
|
+
ssr: true,
|
|
6191
|
+
mounted(el, binding) {
|
|
6192
|
+
const options = normalizeOptions(binding.value);
|
|
6193
|
+
const computedStyle = getComputedStyle(el);
|
|
6194
|
+
if (computedStyle.position === "static") {
|
|
6195
|
+
el.style.position = "relative";
|
|
6196
|
+
}
|
|
6197
|
+
const state = {
|
|
6198
|
+
options,
|
|
6199
|
+
watermarkEl: null,
|
|
6200
|
+
observer: null,
|
|
6201
|
+
canvas: null
|
|
6202
|
+
};
|
|
6203
|
+
el.__watermark = state;
|
|
6204
|
+
if (!options.disabled) {
|
|
6205
|
+
applyWatermark(el, state);
|
|
6206
|
+
}
|
|
6207
|
+
},
|
|
6208
|
+
updated(el, binding) {
|
|
6209
|
+
const state = el.__watermark;
|
|
6210
|
+
if (!state) return;
|
|
6211
|
+
const newOptions = normalizeOptions(binding.value);
|
|
6212
|
+
if (newOptions.disabled && !state.options.disabled) {
|
|
6213
|
+
removeWatermark(state);
|
|
6214
|
+
} else if (!newOptions.disabled && state.options.disabled) {
|
|
6215
|
+
state.options = newOptions;
|
|
6216
|
+
applyWatermark(el, state);
|
|
6217
|
+
} else if (!newOptions.disabled) {
|
|
6218
|
+
state.options = newOptions;
|
|
6219
|
+
removeWatermark(state);
|
|
6220
|
+
applyWatermark(el, state);
|
|
6221
|
+
}
|
|
6222
|
+
state.options = newOptions;
|
|
6223
|
+
},
|
|
6224
|
+
unmounted(el) {
|
|
6225
|
+
const state = el.__watermark;
|
|
6226
|
+
if (!state) return;
|
|
6227
|
+
removeWatermark(state);
|
|
6228
|
+
delete el.__watermark;
|
|
6229
|
+
}
|
|
6230
|
+
});
|
|
6231
|
+
function applyWatermark(el, state) {
|
|
6232
|
+
const options = state.options;
|
|
6233
|
+
state.canvas = createWatermarkCanvas(options);
|
|
6234
|
+
state.watermarkEl = createWatermarkElement(state.canvas, options);
|
|
6235
|
+
el.appendChild(state.watermarkEl);
|
|
6236
|
+
if (options.protect) {
|
|
6237
|
+
setupProtection(el, state);
|
|
6238
|
+
}
|
|
6239
|
+
}
|
|
6240
|
+
function removeWatermark(state) {
|
|
6241
|
+
if (state.observer) {
|
|
6242
|
+
state.observer.disconnect();
|
|
6243
|
+
state.observer = null;
|
|
6244
|
+
}
|
|
6245
|
+
if (state.watermarkEl && state.watermarkEl.parentNode) {
|
|
6246
|
+
state.watermarkEl.parentNode.removeChild(state.watermarkEl);
|
|
6247
|
+
}
|
|
6248
|
+
state.watermarkEl = null;
|
|
6249
|
+
state.canvas = null;
|
|
6250
|
+
}
|
|
6251
|
+
function setupProtection(el, state) {
|
|
6252
|
+
if (typeof MutationObserver === "undefined") return;
|
|
6253
|
+
state.observer = new MutationObserver((mutations) => {
|
|
6254
|
+
if (!state.watermarkEl || !el.contains(state.watermarkEl)) {
|
|
6255
|
+
if (!state.options.disabled) {
|
|
6256
|
+
state.canvas = createWatermarkCanvas(state.options);
|
|
6257
|
+
state.watermarkEl = createWatermarkElement(state.canvas, state.options);
|
|
6258
|
+
el.appendChild(state.watermarkEl);
|
|
6259
|
+
}
|
|
6260
|
+
}
|
|
6261
|
+
for (const mutation of mutations) {
|
|
6262
|
+
if (mutation.type === "attributes" && mutation.target === state.watermarkEl) {
|
|
6263
|
+
const gap = Array.isArray(state.options.gap) ? state.options.gap : [state.options.gap || 100, state.options.gap || 100];
|
|
6264
|
+
state.watermarkEl.style.display = "block";
|
|
6265
|
+
state.watermarkEl.style.visibility = "visible";
|
|
6266
|
+
state.watermarkEl.style.opacity = "1";
|
|
6267
|
+
if (state.canvas) {
|
|
6268
|
+
state.watermarkEl.style.backgroundImage = `url("${state.canvas.toDataURL()}")`;
|
|
6269
|
+
}
|
|
6270
|
+
state.watermarkEl.style.backgroundSize = `${state.canvas.width + gap[0]}px ${state.canvas.height + gap[1]}px`;
|
|
6271
|
+
}
|
|
6272
|
+
}
|
|
6273
|
+
});
|
|
6274
|
+
state.observer.observe(el, {
|
|
6275
|
+
childList: true,
|
|
6276
|
+
subtree: true,
|
|
6277
|
+
attributes: true,
|
|
6278
|
+
attributeFilter: ["style", "class", "hidden"]
|
|
6279
|
+
});
|
|
6280
|
+
}
|
|
4784
6281
|
const allDirectives = {
|
|
4785
6282
|
"click-outside": vClickOutside,
|
|
6283
|
+
"click-delay": vClickDelay,
|
|
4786
6284
|
copy: vCopy,
|
|
4787
6285
|
debounce: vDebounce,
|
|
4788
6286
|
throttle: vThrottle,
|
|
4789
6287
|
focus: vFocus,
|
|
6288
|
+
hotkey: vHotkey,
|
|
4790
6289
|
lazy: vLazy,
|
|
4791
6290
|
intersect: vIntersect,
|
|
4792
6291
|
visible: vVisible,
|
|
@@ -4803,6 +6302,7 @@ const allDirectives = {
|
|
|
4803
6302
|
resize: vResize,
|
|
4804
6303
|
mutation: vMutation,
|
|
4805
6304
|
truncate: vTruncate,
|
|
6305
|
+
ellipsis: vEllipsis,
|
|
4806
6306
|
uppercase: vUppercase,
|
|
4807
6307
|
lowercase: vLowercase,
|
|
4808
6308
|
capitalcase: vCapitalcase,
|
|
@@ -4812,7 +6312,13 @@ const allDirectives = {
|
|
|
4812
6312
|
tooltip: vTooltip,
|
|
4813
6313
|
draggable: vDraggable,
|
|
4814
6314
|
touch: vTouch,
|
|
4815
|
-
|
|
6315
|
+
swipe: vSwipe,
|
|
6316
|
+
"image-preview": vImagePreview,
|
|
6317
|
+
countdown: vCountdown,
|
|
6318
|
+
watermark: vWatermark,
|
|
6319
|
+
print: vPrint,
|
|
6320
|
+
"virtual-list": vVirtualList,
|
|
6321
|
+
"pull-refresh": vPullRefresh
|
|
4816
6322
|
};
|
|
4817
6323
|
const install = (app, options = {}) => {
|
|
4818
6324
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
@@ -4858,9 +6364,11 @@ export {
|
|
|
4858
6364
|
addCleanup$1 as addCleanupVue2,
|
|
4859
6365
|
addCleanup as addCleanupVue3,
|
|
4860
6366
|
vCapitalcase as capitalcase,
|
|
6367
|
+
vClickDelay as clickDelay,
|
|
4861
6368
|
vClickOutside as clickOutside,
|
|
4862
6369
|
configurePermission,
|
|
4863
6370
|
vCopy as copy,
|
|
6371
|
+
vCountdown as countdown,
|
|
4864
6372
|
createVue2Directive,
|
|
4865
6373
|
createVue3Directive,
|
|
4866
6374
|
vDebounce as debounce,
|
|
@@ -4870,11 +6378,13 @@ export {
|
|
|
4870
6378
|
defineDirective,
|
|
4871
6379
|
defineDirectiveGroup,
|
|
4872
6380
|
vDraggable as draggable,
|
|
6381
|
+
vEllipsis as ellipsis,
|
|
4873
6382
|
vFocus as focus,
|
|
4874
6383
|
generateId,
|
|
4875
6384
|
get,
|
|
4876
6385
|
getPermissionConfig,
|
|
4877
6386
|
getVueVersion,
|
|
6387
|
+
vHotkey as hotkey,
|
|
4878
6388
|
vHover as hover,
|
|
4879
6389
|
vImagePreview as imagePreview,
|
|
4880
6390
|
vInfiniteScroll as infiniteScroll,
|
|
@@ -4902,6 +6412,8 @@ export {
|
|
|
4902
6412
|
vNumber as number,
|
|
4903
6413
|
parseTime,
|
|
4904
6414
|
vPermission as permission,
|
|
6415
|
+
vPrint as print,
|
|
6416
|
+
vPullRefresh as pullRefresh,
|
|
4905
6417
|
resetVueVersion,
|
|
4906
6418
|
vResize as resize,
|
|
4907
6419
|
vRipple as ripple,
|
|
@@ -4915,6 +6427,7 @@ export {
|
|
|
4915
6427
|
supportsMutationObserver,
|
|
4916
6428
|
supportsPassive,
|
|
4917
6429
|
supportsResizeObserver,
|
|
6430
|
+
vSwipe as swipe,
|
|
4918
6431
|
vThrottle as throttle,
|
|
4919
6432
|
throttle as throttleFn,
|
|
4920
6433
|
vTooltip as tooltip,
|
|
@@ -4923,11 +6436,15 @@ export {
|
|
|
4923
6436
|
vTruncate as truncate,
|
|
4924
6437
|
vUppercase as uppercase,
|
|
4925
6438
|
vCapitalcase,
|
|
6439
|
+
vClickDelay,
|
|
4926
6440
|
vClickOutside,
|
|
4927
6441
|
vCopy,
|
|
6442
|
+
vCountdown,
|
|
4928
6443
|
vDebounce,
|
|
4929
6444
|
vDraggable,
|
|
6445
|
+
vEllipsis,
|
|
4930
6446
|
vFocus,
|
|
6447
|
+
vHotkey,
|
|
4931
6448
|
vHover,
|
|
4932
6449
|
vImagePreview,
|
|
4933
6450
|
vInfiniteScroll,
|
|
@@ -4941,18 +6458,25 @@ export {
|
|
|
4941
6458
|
vMutation,
|
|
4942
6459
|
vNumber,
|
|
4943
6460
|
vPermission,
|
|
6461
|
+
vPrint,
|
|
6462
|
+
vPullRefresh,
|
|
4944
6463
|
vResize,
|
|
4945
6464
|
vRipple,
|
|
4946
6465
|
vSanitize,
|
|
4947
6466
|
vScroll,
|
|
4948
6467
|
vSticky,
|
|
6468
|
+
vSwipe,
|
|
4949
6469
|
vThrottle,
|
|
4950
6470
|
vTooltip,
|
|
4951
6471
|
vTouch,
|
|
4952
6472
|
vTrim,
|
|
4953
6473
|
vTruncate,
|
|
4954
6474
|
vUppercase,
|
|
6475
|
+
vVirtualList,
|
|
4955
6476
|
vVisible,
|
|
4956
|
-
|
|
6477
|
+
vWatermark,
|
|
6478
|
+
vVirtualList as virtualList,
|
|
6479
|
+
vVisible as visible,
|
|
6480
|
+
vWatermark as watermark
|
|
4957
6481
|
};
|
|
4958
6482
|
//# sourceMappingURL=index.mjs.map
|