@v-c/util 0.0.12 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Children/isFragment.cjs +7 -1
- package/dist/Children/isFragment.js +4 -4
- package/dist/Children/toArray.cjs +20 -1
- package/dist/Children/toArray.js +17 -8
- package/dist/Dom/addEventListener.cjs +13 -1
- package/dist/Dom/addEventListener.js +7 -5
- package/dist/Dom/canUseDom.cjs +6 -1
- package/dist/Dom/canUseDom.js +3 -3
- package/dist/Dom/class.cjs +29 -1
- package/dist/Dom/class.js +23 -13
- package/dist/Dom/contains.cjs +16 -1
- package/dist/Dom/contains.js +12 -12
- package/dist/Dom/css.cjs +96 -1
- package/dist/Dom/css.js +69 -48
- package/dist/Dom/dynamicCSS.cjs +110 -1
- package/dist/Dom/dynamicCSS.js +92 -59
- package/dist/Dom/findDOMNode.cjs +16 -1
- package/dist/Dom/findDOMNode.js +12 -8
- package/dist/Dom/focus.cjs +60 -1
- package/dist/Dom/focus.js +48 -28
- package/dist/Dom/isVisible.cjs +22 -1
- package/dist/Dom/isVisible.js +16 -16
- package/dist/Dom/scrollLocker.cjs +89 -1
- package/dist/Dom/scrollLocker.js +70 -45
- package/dist/Dom/shadow.cjs +13 -1
- package/dist/Dom/shadow.js +8 -8
- package/dist/Dom/styleChecker.cjs +25 -1
- package/dist/Dom/styleChecker.js +19 -14
- package/dist/Dom/support.cjs +28 -1
- package/dist/Dom/support.js +16 -12
- package/dist/KeyCode.cjs +523 -1
- package/dist/KeyCode.js +62 -55
- package/dist/Portal.cjs +48 -1
- package/dist/Portal.js +34 -19
- package/dist/PortalWrapper.cjs +169 -1
- package/dist/PortalWrapper.js +133 -79
- package/dist/classnames.cjs +45 -1
- package/dist/classnames.js +38 -25
- package/dist/composeProps.cjs +19 -1
- package/dist/composeProps.js +15 -9
- package/dist/createRef.cjs +24 -1
- package/dist/createRef.js +16 -13
- package/dist/debug/diff.cjs +50 -1
- package/dist/debug/diff.js +39 -30
- package/dist/deprecated.cjs +10 -1
- package/dist/deprecated.js +7 -5
- package/dist/getScrollBarSize.cjs +51 -1
- package/dist/getScrollBarSize.js +39 -25
- package/dist/guid.cjs +7 -1
- package/dist/guid.js +4 -4
- package/dist/hooks/useEvent.cjs +6 -1
- package/dist/hooks/useEvent.js +3 -3
- package/dist/hooks/useId.cjs +18 -1
- package/dist/hooks/useId.js +14 -8
- package/dist/hooks/useLayoutEffect.cjs +58 -1
- package/dist/hooks/useLayoutEffect.js +50 -20
- package/dist/hooks/useMemo.cjs +16 -1
- package/dist/hooks/useMemo.js +13 -7
- package/dist/hooks/useMergedState.cjs +30 -1
- package/dist/hooks/useMergedState.js +25 -16
- package/dist/hooks/useMobile.cjs +16 -1
- package/dist/hooks/useMobile.js +13 -11
- package/dist/hooks/useState.cjs +12 -1
- package/dist/hooks/useState.js +8 -7
- package/dist/index.cjs +11 -1
- package/dist/index.js +9 -9
- package/dist/isEqual.cjs +36 -1
- package/dist/isEqual.js +30 -26
- package/dist/isMobile.cjs +13 -1
- package/dist/isMobile.js +7 -7
- package/dist/isValid.cjs +6 -1
- package/dist/isValid.js +3 -3
- package/dist/omit.cjs +12 -1
- package/dist/omit.js +9 -6
- package/dist/pickAttrs.cjs +41 -3
- package/dist/pickAttrs.js +37 -22
- package/dist/props-util/index.cjs +69 -1
- package/dist/props-util/index.js +62 -32
- package/dist/raf.cjs +48 -1
- package/dist/raf.js +37 -26
- package/dist/setStyle.cjs +17 -1
- package/dist/setStyle.js +13 -9
- package/dist/switchScrollingEffect.cjs +38 -1
- package/dist/switchScrollingEffect.js +27 -20
- package/dist/test/domHook.cjs +52 -1
- package/dist/test/domHook.js +43 -28
- package/dist/type.cjs +51 -1
- package/dist/type.js +39 -37
- package/dist/utils/checkSlotProp.cjs +13 -1
- package/dist/utils/checkSlotProp.js +10 -3
- package/dist/utils/get.cjs +12 -1
- package/dist/utils/get.js +8 -8
- package/dist/utils/omit.cjs +10 -1
- package/dist/utils/omit.js +7 -6
- package/dist/utils/set.cjs +64 -1
- package/dist/utils/set.js +54 -32
- package/dist/utils/transition.cjs +96 -1
- package/dist/utils/transition.d.ts +2 -2
- package/dist/utils/transition.js +70 -65
- package/dist/utils/watchState.cjs +20 -1
- package/dist/utils/watchState.js +15 -10
- package/dist/vnode.cjs +56 -1
- package/dist/vnode.js +46 -30
- package/dist/vueuse/unref-element.cjs +8 -1
- package/dist/vueuse/unref-element.js +5 -5
- package/dist/warning.cjs +53 -1
- package/dist/warning.js +40 -35
- package/package.json +1 -1
package/dist/Dom/dynamicCSS.js
CHANGED
|
@@ -1,77 +1,110 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import canUseDom from "./canUseDom.js";
|
|
2
|
+
import contains from "./contains.js";
|
|
3
|
+
const APPEND_ORDER = "data-vc-order";
|
|
4
|
+
const APPEND_PRIORITY = "data-vc-priority";
|
|
5
|
+
const MARK_KEY = `vc-util-key`;
|
|
6
|
+
const containerCache = /* @__PURE__ */ new Map();
|
|
7
|
+
function getMark({ mark } = {}) {
|
|
8
|
+
if (mark)
|
|
9
|
+
return mark.startsWith("data-") ? mark : `data-${mark}`;
|
|
10
|
+
return MARK_KEY;
|
|
6
11
|
}
|
|
7
|
-
function
|
|
8
|
-
|
|
12
|
+
function getContainer(option) {
|
|
13
|
+
if (option.attachTo)
|
|
14
|
+
return option.attachTo;
|
|
15
|
+
const head = document.querySelector("head");
|
|
16
|
+
return head || document.body;
|
|
9
17
|
}
|
|
10
|
-
function
|
|
11
|
-
|
|
18
|
+
function getOrder(prepend) {
|
|
19
|
+
if (prepend === "queue")
|
|
20
|
+
return "prependQueue";
|
|
21
|
+
return prepend ? "prepend" : "append";
|
|
12
22
|
}
|
|
13
|
-
function
|
|
23
|
+
function findStyles(container) {
|
|
14
24
|
return Array.from(
|
|
15
|
-
(
|
|
16
|
-
).filter((
|
|
25
|
+
(containerCache.get(container) || container).children
|
|
26
|
+
).filter((node) => node.tagName === "STYLE");
|
|
17
27
|
}
|
|
18
|
-
function
|
|
19
|
-
if (!
|
|
28
|
+
function injectCSS(css, option = {}) {
|
|
29
|
+
if (!canUseDom())
|
|
20
30
|
return null;
|
|
21
|
-
const { csp
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
const { csp, prepend, priority = 0 } = option;
|
|
32
|
+
const mergedOrder = getOrder(prepend);
|
|
33
|
+
const isPrependQueue = mergedOrder === "prependQueue";
|
|
34
|
+
const styleNode = document.createElement("style");
|
|
35
|
+
styleNode.setAttribute(APPEND_ORDER, mergedOrder);
|
|
36
|
+
if (isPrependQueue && priority)
|
|
37
|
+
styleNode.setAttribute(APPEND_PRIORITY, `${priority}`);
|
|
38
|
+
if (csp?.nonce)
|
|
39
|
+
styleNode.nonce = csp?.nonce;
|
|
40
|
+
styleNode.innerHTML = css;
|
|
41
|
+
const container = getContainer(option);
|
|
42
|
+
const { firstChild } = container;
|
|
43
|
+
if (prepend) {
|
|
44
|
+
if (isPrependQueue) {
|
|
45
|
+
const existStyle = findStyles(container).filter((node) => {
|
|
46
|
+
if (!["prepend", "prependQueue"].includes(node.getAttribute(APPEND_ORDER)))
|
|
47
|
+
return false;
|
|
48
|
+
const nodePriority = Number(node.getAttribute(APPEND_PRIORITY) || 0);
|
|
49
|
+
return priority >= nodePriority;
|
|
31
50
|
});
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
)
|
|
51
|
+
if (existStyle.length) {
|
|
52
|
+
container.insertBefore(
|
|
53
|
+
styleNode,
|
|
54
|
+
existStyle[existStyle.length - 1].nextSibling
|
|
55
|
+
);
|
|
56
|
+
return styleNode;
|
|
57
|
+
}
|
|
37
58
|
}
|
|
38
|
-
|
|
39
|
-
} else
|
|
40
|
-
|
|
41
|
-
|
|
59
|
+
container.insertBefore(styleNode, firstChild);
|
|
60
|
+
} else {
|
|
61
|
+
container.appendChild(styleNode);
|
|
62
|
+
}
|
|
63
|
+
return styleNode;
|
|
42
64
|
}
|
|
43
|
-
function
|
|
44
|
-
const
|
|
45
|
-
return
|
|
46
|
-
(
|
|
65
|
+
function findExistNode(key, option = {}) {
|
|
66
|
+
const container = getContainer(option);
|
|
67
|
+
return findStyles(container).find(
|
|
68
|
+
(node) => node.getAttribute(getMark(option)) === key
|
|
47
69
|
);
|
|
48
70
|
}
|
|
49
|
-
function
|
|
50
|
-
const
|
|
51
|
-
|
|
71
|
+
function removeCSS(key, option = {}) {
|
|
72
|
+
const existNode = findExistNode(key, option);
|
|
73
|
+
if (existNode) {
|
|
74
|
+
const container = getContainer(option);
|
|
75
|
+
container.removeChild(existNode);
|
|
76
|
+
}
|
|
52
77
|
}
|
|
53
|
-
function
|
|
54
|
-
const
|
|
55
|
-
if (!
|
|
56
|
-
const
|
|
57
|
-
|
|
78
|
+
function syncRealContainer(container, option) {
|
|
79
|
+
const cachedRealContainer = containerCache.get(container);
|
|
80
|
+
if (!cachedRealContainer || !contains(document, cachedRealContainer)) {
|
|
81
|
+
const placeholderStyle = injectCSS("", option);
|
|
82
|
+
const { parentNode } = placeholderStyle;
|
|
83
|
+
containerCache.set(container, parentNode);
|
|
84
|
+
container.removeChild(placeholderStyle);
|
|
58
85
|
}
|
|
59
86
|
}
|
|
60
|
-
function
|
|
61
|
-
|
|
87
|
+
function clearContainerCache() {
|
|
88
|
+
containerCache.clear();
|
|
62
89
|
}
|
|
63
|
-
function
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
90
|
+
function updateCSS(css, key, option = {}) {
|
|
91
|
+
const container = getContainer(option);
|
|
92
|
+
syncRealContainer(container, option);
|
|
93
|
+
const existNode = findExistNode(key, option);
|
|
94
|
+
if (existNode) {
|
|
95
|
+
if (option.csp?.nonce && existNode.nonce !== option.csp?.nonce)
|
|
96
|
+
existNode.nonce = option.csp?.nonce;
|
|
97
|
+
if (existNode.innerHTML !== css)
|
|
98
|
+
existNode.innerHTML = css;
|
|
99
|
+
return existNode;
|
|
100
|
+
}
|
|
101
|
+
const newNode = injectCSS(css, option);
|
|
102
|
+
newNode.setAttribute(getMark(option), key);
|
|
103
|
+
return newNode;
|
|
71
104
|
}
|
|
72
105
|
export {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
106
|
+
clearContainerCache,
|
|
107
|
+
injectCSS,
|
|
108
|
+
removeCSS,
|
|
109
|
+
updateCSS
|
|
77
110
|
};
|
package/dist/Dom/findDOMNode.cjs
CHANGED
|
@@ -1 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const vue = require("vue");
|
|
4
|
+
function isDOM(node) {
|
|
5
|
+
return node instanceof HTMLElement || node instanceof SVGElement;
|
|
6
|
+
}
|
|
7
|
+
function findDOMNode(_node) {
|
|
8
|
+
const node = vue.unref(_node);
|
|
9
|
+
if (isDOM(node))
|
|
10
|
+
return node;
|
|
11
|
+
else if (node && "$el" in node)
|
|
12
|
+
return node.$el;
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
exports.default = findDOMNode;
|
|
16
|
+
exports.isDOM = isDOM;
|
package/dist/Dom/findDOMNode.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import { unref
|
|
2
|
-
function
|
|
3
|
-
return
|
|
1
|
+
import { unref } from "vue";
|
|
2
|
+
function isDOM(node) {
|
|
3
|
+
return node instanceof HTMLElement || node instanceof SVGElement;
|
|
4
4
|
}
|
|
5
|
-
function
|
|
6
|
-
const
|
|
7
|
-
|
|
5
|
+
function findDOMNode(_node) {
|
|
6
|
+
const node = unref(_node);
|
|
7
|
+
if (isDOM(node))
|
|
8
|
+
return node;
|
|
9
|
+
else if (node && "$el" in node)
|
|
10
|
+
return node.$el;
|
|
11
|
+
return null;
|
|
8
12
|
}
|
|
9
13
|
export {
|
|
10
|
-
|
|
11
|
-
|
|
14
|
+
findDOMNode as default,
|
|
15
|
+
isDOM
|
|
12
16
|
};
|
package/dist/Dom/focus.cjs
CHANGED
|
@@ -1 +1,60 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const isVisible = require("./isVisible.cjs");
|
|
4
|
+
function focusable(node, includePositive = false) {
|
|
5
|
+
if (isVisible.default(node)) {
|
|
6
|
+
const nodeName = node.nodeName.toLowerCase();
|
|
7
|
+
const isFocusableElement = ["input", "select", "textarea", "button"].includes(nodeName) || node.isContentEditable || nodeName === "a" && !!node.getAttribute("href");
|
|
8
|
+
const tabIndexAttr = node.getAttribute("tabindex");
|
|
9
|
+
const tabIndexNum = Number(tabIndexAttr);
|
|
10
|
+
let tabIndex = null;
|
|
11
|
+
if (tabIndexAttr && !Number.isNaN(tabIndexNum))
|
|
12
|
+
tabIndex = tabIndexNum;
|
|
13
|
+
else if (isFocusableElement && tabIndex === null)
|
|
14
|
+
tabIndex = 0;
|
|
15
|
+
if (isFocusableElement && node.disabled)
|
|
16
|
+
tabIndex = null;
|
|
17
|
+
return tabIndex !== null && (tabIndex >= 0 || includePositive && tabIndex < 0);
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
function getFocusNodeList(node, includePositive = false) {
|
|
22
|
+
const res = [...node.querySelectorAll("*")].filter((child) => {
|
|
23
|
+
return focusable(child, includePositive);
|
|
24
|
+
});
|
|
25
|
+
if (focusable(node, includePositive))
|
|
26
|
+
res.unshift(node);
|
|
27
|
+
return res;
|
|
28
|
+
}
|
|
29
|
+
let lastFocusElement = null;
|
|
30
|
+
function saveLastFocusNode() {
|
|
31
|
+
lastFocusElement = document.activeElement;
|
|
32
|
+
}
|
|
33
|
+
function clearLastFocusNode() {
|
|
34
|
+
lastFocusElement = null;
|
|
35
|
+
}
|
|
36
|
+
function backLastFocusNode() {
|
|
37
|
+
if (lastFocusElement) {
|
|
38
|
+
try {
|
|
39
|
+
lastFocusElement.focus();
|
|
40
|
+
} catch (_e) {
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function limitTabRange(node, e) {
|
|
45
|
+
if (e.keyCode === 9) {
|
|
46
|
+
const tabNodeList = getFocusNodeList(node);
|
|
47
|
+
const lastTabNode = tabNodeList[e.shiftKey ? 0 : tabNodeList.length - 1];
|
|
48
|
+
const leavingTab = lastTabNode === document.activeElement || node === document.activeElement;
|
|
49
|
+
if (leavingTab) {
|
|
50
|
+
const target = tabNodeList[e.shiftKey ? tabNodeList.length - 1 : 0];
|
|
51
|
+
target.focus();
|
|
52
|
+
e.preventDefault();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.backLastFocusNode = backLastFocusNode;
|
|
57
|
+
exports.clearLastFocusNode = clearLastFocusNode;
|
|
58
|
+
exports.getFocusNodeList = getFocusNodeList;
|
|
59
|
+
exports.limitTabRange = limitTabRange;
|
|
60
|
+
exports.saveLastFocusNode = saveLastFocusNode;
|
package/dist/Dom/focus.js
CHANGED
|
@@ -1,40 +1,60 @@
|
|
|
1
|
-
import
|
|
2
|
-
function
|
|
3
|
-
if (
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import isVisible from "./isVisible.js";
|
|
2
|
+
function focusable(node, includePositive = false) {
|
|
3
|
+
if (isVisible(node)) {
|
|
4
|
+
const nodeName = node.nodeName.toLowerCase();
|
|
5
|
+
const isFocusableElement = ["input", "select", "textarea", "button"].includes(nodeName) || node.isContentEditable || nodeName === "a" && !!node.getAttribute("href");
|
|
6
|
+
const tabIndexAttr = node.getAttribute("tabindex");
|
|
7
|
+
const tabIndexNum = Number(tabIndexAttr);
|
|
8
|
+
let tabIndex = null;
|
|
9
|
+
if (tabIndexAttr && !Number.isNaN(tabIndexNum))
|
|
10
|
+
tabIndex = tabIndexNum;
|
|
11
|
+
else if (isFocusableElement && tabIndex === null)
|
|
12
|
+
tabIndex = 0;
|
|
13
|
+
if (isFocusableElement && node.disabled)
|
|
14
|
+
tabIndex = null;
|
|
15
|
+
return tabIndex !== null && (tabIndex >= 0 || includePositive && tabIndex < 0);
|
|
7
16
|
}
|
|
8
|
-
return
|
|
17
|
+
return false;
|
|
9
18
|
}
|
|
10
|
-
function
|
|
11
|
-
const
|
|
12
|
-
|
|
19
|
+
function getFocusNodeList(node, includePositive = false) {
|
|
20
|
+
const res = [...node.querySelectorAll("*")].filter((child) => {
|
|
21
|
+
return focusable(child, includePositive);
|
|
22
|
+
});
|
|
23
|
+
if (focusable(node, includePositive))
|
|
24
|
+
res.unshift(node);
|
|
25
|
+
return res;
|
|
13
26
|
}
|
|
14
|
-
let
|
|
15
|
-
function
|
|
16
|
-
|
|
27
|
+
let lastFocusElement = null;
|
|
28
|
+
function saveLastFocusNode() {
|
|
29
|
+
lastFocusElement = document.activeElement;
|
|
17
30
|
}
|
|
18
|
-
function
|
|
19
|
-
|
|
31
|
+
function clearLastFocusNode() {
|
|
32
|
+
lastFocusElement = null;
|
|
20
33
|
}
|
|
21
|
-
function
|
|
22
|
-
if (
|
|
34
|
+
function backLastFocusNode() {
|
|
35
|
+
if (lastFocusElement) {
|
|
23
36
|
try {
|
|
24
|
-
|
|
25
|
-
} catch {
|
|
37
|
+
lastFocusElement.focus();
|
|
38
|
+
} catch (_e) {
|
|
26
39
|
}
|
|
40
|
+
}
|
|
27
41
|
}
|
|
28
|
-
function
|
|
29
|
-
if (
|
|
30
|
-
const
|
|
31
|
-
|
|
42
|
+
function limitTabRange(node, e) {
|
|
43
|
+
if (e.keyCode === 9) {
|
|
44
|
+
const tabNodeList = getFocusNodeList(node);
|
|
45
|
+
const lastTabNode = tabNodeList[e.shiftKey ? 0 : tabNodeList.length - 1];
|
|
46
|
+
const leavingTab = lastTabNode === document.activeElement || node === document.activeElement;
|
|
47
|
+
if (leavingTab) {
|
|
48
|
+
const target = tabNodeList[e.shiftKey ? tabNodeList.length - 1 : 0];
|
|
49
|
+
target.focus();
|
|
50
|
+
e.preventDefault();
|
|
51
|
+
}
|
|
32
52
|
}
|
|
33
53
|
}
|
|
34
54
|
export {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
55
|
+
backLastFocusNode,
|
|
56
|
+
clearLastFocusNode,
|
|
57
|
+
getFocusNodeList,
|
|
58
|
+
limitTabRange,
|
|
59
|
+
saveLastFocusNode
|
|
40
60
|
};
|
package/dist/Dom/isVisible.cjs
CHANGED
|
@@ -1 +1,22 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const isVisible = (element) => {
|
|
4
|
+
if (!element)
|
|
5
|
+
return false;
|
|
6
|
+
if (element instanceof Element) {
|
|
7
|
+
if (element.offsetParent)
|
|
8
|
+
return true;
|
|
9
|
+
if (element.getBBox) {
|
|
10
|
+
const { width, height } = element.getBBox();
|
|
11
|
+
if (width || height)
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
if (element.getBoundingClientRect) {
|
|
15
|
+
const { width, height } = element.getBoundingClientRect();
|
|
16
|
+
if (width || height)
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
};
|
|
22
|
+
exports.default = isVisible;
|
package/dist/Dom/isVisible.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
const
|
|
2
|
-
if (!
|
|
3
|
-
return
|
|
4
|
-
if (
|
|
5
|
-
if (
|
|
6
|
-
return
|
|
7
|
-
if (
|
|
8
|
-
const { width
|
|
9
|
-
if (
|
|
10
|
-
return
|
|
1
|
+
const isVisible = (element) => {
|
|
2
|
+
if (!element)
|
|
3
|
+
return false;
|
|
4
|
+
if (element instanceof Element) {
|
|
5
|
+
if (element.offsetParent)
|
|
6
|
+
return true;
|
|
7
|
+
if (element.getBBox) {
|
|
8
|
+
const { width, height } = element.getBBox();
|
|
9
|
+
if (width || height)
|
|
10
|
+
return true;
|
|
11
11
|
}
|
|
12
|
-
if (
|
|
13
|
-
const { width
|
|
14
|
-
if (
|
|
15
|
-
return
|
|
12
|
+
if (element.getBoundingClientRect) {
|
|
13
|
+
const { width, height } = element.getBoundingClientRect();
|
|
14
|
+
if (width || height)
|
|
15
|
+
return true;
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
return
|
|
18
|
+
return false;
|
|
19
19
|
};
|
|
20
20
|
export {
|
|
21
|
-
|
|
21
|
+
isVisible as default
|
|
22
22
|
};
|
|
@@ -1 +1,89 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const getScrollBarSize = require("../getScrollBarSize.cjs");
|
|
4
|
+
const setStyle = require("../setStyle.cjs");
|
|
5
|
+
let uuid = 0;
|
|
6
|
+
let locks = [];
|
|
7
|
+
const scrollingEffectClassName = "ant-scrolling-effect";
|
|
8
|
+
const scrollingEffectClassNameReg = new RegExp(
|
|
9
|
+
`${scrollingEffectClassName}`,
|
|
10
|
+
"g"
|
|
11
|
+
);
|
|
12
|
+
const cacheStyle = /* @__PURE__ */ new Map();
|
|
13
|
+
class ScrollLocker {
|
|
14
|
+
lockTarget;
|
|
15
|
+
options;
|
|
16
|
+
constructor(options) {
|
|
17
|
+
this.lockTarget = uuid++;
|
|
18
|
+
this.options = options;
|
|
19
|
+
}
|
|
20
|
+
getContainer = () => {
|
|
21
|
+
return this.options?.container;
|
|
22
|
+
};
|
|
23
|
+
// if options change...
|
|
24
|
+
reLock = (options) => {
|
|
25
|
+
const findLock = locks.find(({ target }) => target === this.lockTarget);
|
|
26
|
+
if (findLock)
|
|
27
|
+
this.unLock();
|
|
28
|
+
this.options = options;
|
|
29
|
+
if (findLock) {
|
|
30
|
+
findLock.options = options;
|
|
31
|
+
this.lock();
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
lock = () => {
|
|
35
|
+
if (locks.some(({ target }) => target === this.lockTarget))
|
|
36
|
+
return;
|
|
37
|
+
if (locks.some(
|
|
38
|
+
({ options }) => options?.container === this.options?.container
|
|
39
|
+
)) {
|
|
40
|
+
locks = [...locks, { target: this.lockTarget, options: this.options }];
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
let scrollBarSize = 0;
|
|
44
|
+
const container = this.options?.container || document.body;
|
|
45
|
+
if (container === document.body && window.innerWidth - document.documentElement.clientWidth > 0 || container.scrollHeight > container.clientHeight) {
|
|
46
|
+
if (getComputedStyle(container).overflow !== "hidden")
|
|
47
|
+
scrollBarSize = getScrollBarSize.default();
|
|
48
|
+
}
|
|
49
|
+
const containerClassName = container.className;
|
|
50
|
+
if (locks.filter(
|
|
51
|
+
({ options }) => options?.container === this.options?.container
|
|
52
|
+
).length === 0) {
|
|
53
|
+
cacheStyle.set(
|
|
54
|
+
container,
|
|
55
|
+
setStyle.default(
|
|
56
|
+
{
|
|
57
|
+
width: scrollBarSize !== 0 ? `calc(100% - ${scrollBarSize}px)` : void 0,
|
|
58
|
+
overflow: "hidden",
|
|
59
|
+
overflowX: "hidden",
|
|
60
|
+
overflowY: "hidden"
|
|
61
|
+
},
|
|
62
|
+
{ element: container }
|
|
63
|
+
)
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
if (!scrollingEffectClassNameReg.test(containerClassName)) {
|
|
67
|
+
const addClassName = `${containerClassName} ${scrollingEffectClassName}`;
|
|
68
|
+
container.className = addClassName.trim();
|
|
69
|
+
}
|
|
70
|
+
locks = [...locks, { target: this.lockTarget, options: this.options }];
|
|
71
|
+
};
|
|
72
|
+
unLock = () => {
|
|
73
|
+
const findLock = locks.find(({ target }) => target === this.lockTarget);
|
|
74
|
+
locks = locks.filter(({ target }) => target !== this.lockTarget);
|
|
75
|
+
if (!findLock || locks.some(
|
|
76
|
+
({ options }) => options?.container === findLock.options?.container
|
|
77
|
+
)) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const container = this.options?.container || document.body;
|
|
81
|
+
const containerClassName = container.className;
|
|
82
|
+
if (!scrollingEffectClassNameReg.test(containerClassName))
|
|
83
|
+
return;
|
|
84
|
+
setStyle.default(cacheStyle.get(container), { element: container });
|
|
85
|
+
cacheStyle.delete(container);
|
|
86
|
+
container.className = container.className.replace(scrollingEffectClassNameReg, "").trim();
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
exports.default = ScrollLocker;
|
package/dist/Dom/scrollLocker.js
CHANGED
|
@@ -1,64 +1,89 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
let
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import getScrollBarSize from "../getScrollBarSize.js";
|
|
2
|
+
import setStyle from "../setStyle.js";
|
|
3
|
+
let uuid = 0;
|
|
4
|
+
let locks = [];
|
|
5
|
+
const scrollingEffectClassName = "ant-scrolling-effect";
|
|
6
|
+
const scrollingEffectClassNameReg = new RegExp(
|
|
7
|
+
`${scrollingEffectClassName}`,
|
|
6
8
|
"g"
|
|
7
|
-
)
|
|
8
|
-
|
|
9
|
+
);
|
|
10
|
+
const cacheStyle = /* @__PURE__ */ new Map();
|
|
11
|
+
class ScrollLocker {
|
|
9
12
|
lockTarget;
|
|
10
13
|
options;
|
|
11
|
-
constructor(
|
|
12
|
-
this.lockTarget =
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.lockTarget = uuid++;
|
|
16
|
+
this.options = options;
|
|
13
17
|
}
|
|
14
|
-
getContainer = () =>
|
|
18
|
+
getContainer = () => {
|
|
19
|
+
return this.options?.container;
|
|
20
|
+
};
|
|
15
21
|
// if options change...
|
|
16
|
-
reLock = (
|
|
17
|
-
const
|
|
18
|
-
|
|
22
|
+
reLock = (options) => {
|
|
23
|
+
const findLock = locks.find(({ target }) => target === this.lockTarget);
|
|
24
|
+
if (findLock)
|
|
25
|
+
this.unLock();
|
|
26
|
+
this.options = options;
|
|
27
|
+
if (findLock) {
|
|
28
|
+
findLock.options = options;
|
|
29
|
+
this.lock();
|
|
30
|
+
}
|
|
19
31
|
};
|
|
20
32
|
lock = () => {
|
|
21
|
-
if (
|
|
33
|
+
if (locks.some(({ target }) => target === this.lockTarget))
|
|
22
34
|
return;
|
|
23
|
-
if (
|
|
24
|
-
({ options
|
|
35
|
+
if (locks.some(
|
|
36
|
+
({ options }) => options?.container === this.options?.container
|
|
25
37
|
)) {
|
|
26
|
-
|
|
38
|
+
locks = [...locks, { target: this.lockTarget, options: this.options }];
|
|
27
39
|
return;
|
|
28
40
|
}
|
|
29
|
-
let
|
|
30
|
-
const
|
|
31
|
-
(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
let scrollBarSize = 0;
|
|
42
|
+
const container = this.options?.container || document.body;
|
|
43
|
+
if (container === document.body && window.innerWidth - document.documentElement.clientWidth > 0 || container.scrollHeight > container.clientHeight) {
|
|
44
|
+
if (getComputedStyle(container).overflow !== "hidden")
|
|
45
|
+
scrollBarSize = getScrollBarSize();
|
|
46
|
+
}
|
|
47
|
+
const containerClassName = container.className;
|
|
48
|
+
if (locks.filter(
|
|
49
|
+
({ options }) => options?.container === this.options?.container
|
|
50
|
+
).length === 0) {
|
|
51
|
+
cacheStyle.set(
|
|
52
|
+
container,
|
|
53
|
+
setStyle(
|
|
54
|
+
{
|
|
55
|
+
width: scrollBarSize !== 0 ? `calc(100% - ${scrollBarSize}px)` : void 0,
|
|
56
|
+
overflow: "hidden",
|
|
57
|
+
overflowX: "hidden",
|
|
58
|
+
overflowY: "hidden"
|
|
59
|
+
},
|
|
60
|
+
{ element: container }
|
|
61
|
+
)
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
if (!scrollingEffectClassNameReg.test(containerClassName)) {
|
|
65
|
+
const addClassName = `${containerClassName} ${scrollingEffectClassName}`;
|
|
66
|
+
container.className = addClassName.trim();
|
|
49
67
|
}
|
|
50
|
-
|
|
68
|
+
locks = [...locks, { target: this.lockTarget, options: this.options }];
|
|
51
69
|
};
|
|
52
70
|
unLock = () => {
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
71
|
+
const findLock = locks.find(({ target }) => target === this.lockTarget);
|
|
72
|
+
locks = locks.filter(({ target }) => target !== this.lockTarget);
|
|
73
|
+
if (!findLock || locks.some(
|
|
74
|
+
({ options }) => options?.container === findLock.options?.container
|
|
75
|
+
)) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const container = this.options?.container || document.body;
|
|
79
|
+
const containerClassName = container.className;
|
|
80
|
+
if (!scrollingEffectClassNameReg.test(containerClassName))
|
|
57
81
|
return;
|
|
58
|
-
|
|
59
|
-
|
|
82
|
+
setStyle(cacheStyle.get(container), { element: container });
|
|
83
|
+
cacheStyle.delete(container);
|
|
84
|
+
container.className = container.className.replace(scrollingEffectClassNameReg, "").trim();
|
|
60
85
|
};
|
|
61
86
|
}
|
|
62
87
|
export {
|
|
63
|
-
|
|
88
|
+
ScrollLocker as default
|
|
64
89
|
};
|