@v-c/util 0.0.13 → 0.0.14
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 +2 -4
- package/dist/Children/isFragment.js +3 -5
- package/dist/Children/toArray.cjs +10 -17
- package/dist/Children/toArray.js +10 -17
- package/dist/Dom/addEventListener.cjs +5 -10
- package/dist/Dom/addEventListener.js +6 -11
- package/dist/Dom/canUseDom.cjs +2 -3
- package/dist/Dom/canUseDom.js +2 -4
- package/dist/Dom/class.cjs +6 -20
- package/dist/Dom/class.js +7 -23
- package/dist/Dom/contains.cjs +9 -13
- package/dist/Dom/contains.js +9 -14
- package/dist/Dom/css.cjs +51 -66
- package/dist/Dom/css.js +52 -74
- package/dist/Dom/dynamicCSS.cjs +59 -86
- package/dist/Dom/dynamicCSS.js +58 -88
- package/dist/Dom/findDOMNode.cjs +7 -10
- package/dist/Dom/findDOMNode.js +6 -11
- package/dist/Dom/focus.cjs +36 -43
- package/dist/Dom/focus.js +37 -48
- package/dist/Dom/isVisible.cjs +16 -21
- package/dist/Dom/isVisible.js +15 -21
- package/dist/Dom/scrollLocker.cjs +66 -88
- package/dist/Dom/scrollLocker.js +64 -87
- package/dist/Dom/shadow.cjs +3 -5
- package/dist/Dom/shadow.js +4 -7
- package/dist/Dom/styleChecker.cjs +14 -18
- package/dist/Dom/styleChecker.js +14 -18
- package/dist/Dom/support.cjs +14 -22
- package/dist/Dom/support.js +12 -21
- package/dist/EventInterface.cjs +0 -1
- package/dist/EventInterface.js +0 -1
- package/dist/KeyCode.cjs +165 -522
- package/dist/KeyCode.js +164 -522
- package/dist/Portal.cjs +40 -46
- package/dist/Portal.js +37 -45
- package/dist/PortalWrapper.cjs +130 -164
- package/dist/PortalWrapper.js +126 -163
- package/dist/classnames.cjs +30 -38
- package/dist/classnames.js +30 -40
- package/dist/composeProps.cjs +15 -17
- package/dist/composeProps.js +14 -17
- package/dist/createRef.cjs +14 -16
- package/dist/createRef.js +13 -18
- package/dist/debug/diff.cjs +39 -45
- package/dist/debug/diff.js +39 -46
- package/dist/deprecated.cjs +2 -7
- package/dist/deprecated.js +2 -8
- package/dist/getScrollBarSize.cjs +39 -43
- package/dist/getScrollBarSize.js +39 -45
- package/dist/guid.cjs +3 -4
- package/dist/guid.js +3 -5
- package/dist/hooks/useEvent.cjs +2 -3
- package/dist/hooks/useEvent.js +2 -4
- package/dist/hooks/useId.cjs +10 -15
- package/dist/hooks/useId.js +9 -15
- package/dist/hooks/useLayoutEffect.cjs +29 -52
- package/dist/hooks/useLayoutEffect.js +30 -54
- package/dist/hooks/useMemo.cjs +9 -13
- package/dist/hooks/useMemo.js +8 -13
- package/dist/hooks/useMergedState.cjs +22 -27
- package/dist/hooks/useMergedState.js +22 -28
- package/dist/hooks/useMobile.cjs +13 -13
- package/dist/hooks/useMobile.js +12 -14
- package/dist/hooks/useState.cjs +7 -9
- package/dist/hooks/useState.js +6 -9
- package/dist/index.cjs +9 -11
- package/dist/index.js +5 -11
- package/dist/isEqual.cjs +26 -34
- package/dist/isEqual.js +25 -34
- package/dist/isMobile.cjs +6 -12
- package/dist/isMobile.js +5 -12
- package/dist/isValid.cjs +4 -4
- package/dist/isValid.js +3 -4
- package/dist/omit.cjs +6 -9
- package/dist/omit.js +6 -10
- package/dist/pickAttrs.cjs +20 -36
- package/dist/pickAttrs.js +20 -37
- package/dist/props-util/index.cjs +35 -52
- package/dist/props-util/index.js +35 -57
- package/dist/raf.cjs +34 -37
- package/dist/raf.js +33 -38
- package/dist/setStyle.cjs +14 -15
- package/dist/setStyle.js +13 -15
- package/dist/switchScrollingEffect.cjs +29 -35
- package/dist/switchScrollingEffect.js +27 -34
- package/dist/test/domHook.cjs +32 -46
- package/dist/test/domHook.js +33 -48
- package/dist/type.cjs +36 -17
- package/dist/type.d.ts +1 -1
- package/dist/type.js +38 -30
- package/dist/utils/checkSlotProp.cjs +6 -10
- package/dist/utils/checkSlotProp.js +7 -11
- package/dist/utils/get.cjs +7 -9
- package/dist/utils/get.js +7 -10
- package/dist/utils/omit.cjs +5 -7
- package/dist/utils/omit.js +6 -8
- package/dist/utils/set.cjs +37 -51
- package/dist/utils/set.js +36 -53
- package/dist/utils/transition.cjs +76 -80
- package/dist/utils/transition.d.ts +2 -2
- package/dist/utils/transition.js +76 -84
- package/dist/utils/watchState.cjs +12 -14
- package/dist/utils/watchState.js +13 -16
- package/dist/vnode.cjs +31 -39
- package/dist/vnode.js +31 -43
- package/dist/vueuse/unref-element.cjs +3 -5
- package/dist/vueuse/unref-element.js +3 -5
- package/dist/warning.cjs +21 -29
- package/dist/warning.js +20 -36
- package/package.json +1 -1
package/dist/Dom/dynamicCSS.cjs
CHANGED
|
@@ -1,108 +1,81 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const MARK_KEY = `vc-util-key`;
|
|
8
|
-
const containerCache = /* @__PURE__ */ new Map();
|
|
1
|
+
const require_canUseDom = require("./canUseDom.cjs");
|
|
2
|
+
const require_contains = require("./contains.cjs");
|
|
3
|
+
var APPEND_ORDER = "data-vc-order";
|
|
4
|
+
var APPEND_PRIORITY = "data-vc-priority";
|
|
5
|
+
var MARK_KEY = `vc-util-key`;
|
|
6
|
+
var containerCache = /* @__PURE__ */ new Map();
|
|
9
7
|
function getMark({ mark } = {}) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return MARK_KEY;
|
|
8
|
+
if (mark) return mark.startsWith("data-") ? mark : `data-${mark}`;
|
|
9
|
+
return MARK_KEY;
|
|
13
10
|
}
|
|
14
11
|
function getContainer(option) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const head = document.querySelector("head");
|
|
18
|
-
return head || document.body;
|
|
12
|
+
if (option.attachTo) return option.attachTo;
|
|
13
|
+
return document.querySelector("head") || document.body;
|
|
19
14
|
}
|
|
20
15
|
function getOrder(prepend) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return prepend ? "prepend" : "append";
|
|
16
|
+
if (prepend === "queue") return "prependQueue";
|
|
17
|
+
return prepend ? "prepend" : "append";
|
|
24
18
|
}
|
|
25
19
|
function findStyles(container) {
|
|
26
|
-
|
|
27
|
-
(containerCache.get(container) || container).children
|
|
28
|
-
).filter((node) => node.tagName === "STYLE");
|
|
20
|
+
return Array.from((containerCache.get(container) || container).children).filter((node) => node.tagName === "STYLE");
|
|
29
21
|
}
|
|
30
22
|
function injectCSS(css, option = {}) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
existStyle[existStyle.length - 1].nextSibling
|
|
57
|
-
);
|
|
58
|
-
return styleNode;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
container.insertBefore(styleNode, firstChild);
|
|
62
|
-
} else {
|
|
63
|
-
container.appendChild(styleNode);
|
|
64
|
-
}
|
|
65
|
-
return styleNode;
|
|
23
|
+
if (!require_canUseDom.default()) return null;
|
|
24
|
+
const { csp, prepend, priority = 0 } = option;
|
|
25
|
+
const mergedOrder = getOrder(prepend);
|
|
26
|
+
const isPrependQueue = mergedOrder === "prependQueue";
|
|
27
|
+
const styleNode = document.createElement("style");
|
|
28
|
+
styleNode.setAttribute(APPEND_ORDER, mergedOrder);
|
|
29
|
+
if (isPrependQueue && priority) styleNode.setAttribute(APPEND_PRIORITY, `${priority}`);
|
|
30
|
+
if (csp?.nonce) styleNode.nonce = csp?.nonce;
|
|
31
|
+
styleNode.innerHTML = css;
|
|
32
|
+
const container = getContainer(option);
|
|
33
|
+
const { firstChild } = container;
|
|
34
|
+
if (prepend) {
|
|
35
|
+
if (isPrependQueue) {
|
|
36
|
+
const existStyle = findStyles(container).filter((node) => {
|
|
37
|
+
if (!["prepend", "prependQueue"].includes(node.getAttribute(APPEND_ORDER))) return false;
|
|
38
|
+
return priority >= Number(node.getAttribute(APPEND_PRIORITY) || 0);
|
|
39
|
+
});
|
|
40
|
+
if (existStyle.length) {
|
|
41
|
+
container.insertBefore(styleNode, existStyle[existStyle.length - 1].nextSibling);
|
|
42
|
+
return styleNode;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
container.insertBefore(styleNode, firstChild);
|
|
46
|
+
} else container.appendChild(styleNode);
|
|
47
|
+
return styleNode;
|
|
66
48
|
}
|
|
67
49
|
function findExistNode(key, option = {}) {
|
|
68
|
-
|
|
69
|
-
return findStyles(container).find(
|
|
70
|
-
(node) => node.getAttribute(getMark(option)) === key
|
|
71
|
-
);
|
|
50
|
+
return findStyles(getContainer(option)).find((node) => node.getAttribute(getMark(option)) === key);
|
|
72
51
|
}
|
|
73
52
|
function removeCSS(key, option = {}) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const container = getContainer(option);
|
|
77
|
-
container.removeChild(existNode);
|
|
78
|
-
}
|
|
53
|
+
const existNode = findExistNode(key, option);
|
|
54
|
+
if (existNode) getContainer(option).removeChild(existNode);
|
|
79
55
|
}
|
|
80
56
|
function syncRealContainer(container, option) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
57
|
+
const cachedRealContainer = containerCache.get(container);
|
|
58
|
+
if (!cachedRealContainer || !require_contains.default(document, cachedRealContainer)) {
|
|
59
|
+
const placeholderStyle = injectCSS("", option);
|
|
60
|
+
const { parentNode } = placeholderStyle;
|
|
61
|
+
containerCache.set(container, parentNode);
|
|
62
|
+
container.removeChild(placeholderStyle);
|
|
63
|
+
}
|
|
88
64
|
}
|
|
89
65
|
function clearContainerCache() {
|
|
90
|
-
|
|
66
|
+
containerCache.clear();
|
|
91
67
|
}
|
|
92
68
|
function updateCSS(css, key, option = {}) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const newNode = injectCSS(css, option);
|
|
104
|
-
newNode.setAttribute(getMark(option), key);
|
|
105
|
-
return newNode;
|
|
69
|
+
syncRealContainer(getContainer(option), option);
|
|
70
|
+
const existNode = findExistNode(key, option);
|
|
71
|
+
if (existNode) {
|
|
72
|
+
if (option.csp?.nonce && existNode.nonce !== option.csp?.nonce) existNode.nonce = option.csp?.nonce;
|
|
73
|
+
if (existNode.innerHTML !== css) existNode.innerHTML = css;
|
|
74
|
+
return existNode;
|
|
75
|
+
}
|
|
76
|
+
const newNode = injectCSS(css, option);
|
|
77
|
+
newNode.setAttribute(getMark(option), key);
|
|
78
|
+
return newNode;
|
|
106
79
|
}
|
|
107
80
|
exports.clearContainerCache = clearContainerCache;
|
|
108
81
|
exports.injectCSS = injectCSS;
|
package/dist/Dom/dynamicCSS.js
CHANGED
|
@@ -1,110 +1,80 @@
|
|
|
1
1
|
import canUseDom from "./canUseDom.js";
|
|
2
2
|
import contains from "./contains.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
var APPEND_ORDER = "data-vc-order";
|
|
4
|
+
var APPEND_PRIORITY = "data-vc-priority";
|
|
5
|
+
var MARK_KEY = `vc-util-key`;
|
|
6
|
+
var containerCache = /* @__PURE__ */ new Map();
|
|
7
7
|
function getMark({ mark } = {}) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return MARK_KEY;
|
|
8
|
+
if (mark) return mark.startsWith("data-") ? mark : `data-${mark}`;
|
|
9
|
+
return MARK_KEY;
|
|
11
10
|
}
|
|
12
11
|
function getContainer(option) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const head = document.querySelector("head");
|
|
16
|
-
return head || document.body;
|
|
12
|
+
if (option.attachTo) return option.attachTo;
|
|
13
|
+
return document.querySelector("head") || document.body;
|
|
17
14
|
}
|
|
18
15
|
function getOrder(prepend) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return prepend ? "prepend" : "append";
|
|
16
|
+
if (prepend === "queue") return "prependQueue";
|
|
17
|
+
return prepend ? "prepend" : "append";
|
|
22
18
|
}
|
|
23
19
|
function findStyles(container) {
|
|
24
|
-
|
|
25
|
-
(containerCache.get(container) || container).children
|
|
26
|
-
).filter((node) => node.tagName === "STYLE");
|
|
20
|
+
return Array.from((containerCache.get(container) || container).children).filter((node) => node.tagName === "STYLE");
|
|
27
21
|
}
|
|
28
22
|
function injectCSS(css, option = {}) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
existStyle[existStyle.length - 1].nextSibling
|
|
55
|
-
);
|
|
56
|
-
return styleNode;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
container.insertBefore(styleNode, firstChild);
|
|
60
|
-
} else {
|
|
61
|
-
container.appendChild(styleNode);
|
|
62
|
-
}
|
|
63
|
-
return styleNode;
|
|
23
|
+
if (!canUseDom()) return null;
|
|
24
|
+
const { csp, prepend, priority = 0 } = option;
|
|
25
|
+
const mergedOrder = getOrder(prepend);
|
|
26
|
+
const isPrependQueue = mergedOrder === "prependQueue";
|
|
27
|
+
const styleNode = document.createElement("style");
|
|
28
|
+
styleNode.setAttribute(APPEND_ORDER, mergedOrder);
|
|
29
|
+
if (isPrependQueue && priority) styleNode.setAttribute(APPEND_PRIORITY, `${priority}`);
|
|
30
|
+
if (csp?.nonce) styleNode.nonce = csp?.nonce;
|
|
31
|
+
styleNode.innerHTML = css;
|
|
32
|
+
const container = getContainer(option);
|
|
33
|
+
const { firstChild } = container;
|
|
34
|
+
if (prepend) {
|
|
35
|
+
if (isPrependQueue) {
|
|
36
|
+
const existStyle = findStyles(container).filter((node) => {
|
|
37
|
+
if (!["prepend", "prependQueue"].includes(node.getAttribute(APPEND_ORDER))) return false;
|
|
38
|
+
return priority >= Number(node.getAttribute(APPEND_PRIORITY) || 0);
|
|
39
|
+
});
|
|
40
|
+
if (existStyle.length) {
|
|
41
|
+
container.insertBefore(styleNode, existStyle[existStyle.length - 1].nextSibling);
|
|
42
|
+
return styleNode;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
container.insertBefore(styleNode, firstChild);
|
|
46
|
+
} else container.appendChild(styleNode);
|
|
47
|
+
return styleNode;
|
|
64
48
|
}
|
|
65
49
|
function findExistNode(key, option = {}) {
|
|
66
|
-
|
|
67
|
-
return findStyles(container).find(
|
|
68
|
-
(node) => node.getAttribute(getMark(option)) === key
|
|
69
|
-
);
|
|
50
|
+
return findStyles(getContainer(option)).find((node) => node.getAttribute(getMark(option)) === key);
|
|
70
51
|
}
|
|
71
52
|
function removeCSS(key, option = {}) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const container = getContainer(option);
|
|
75
|
-
container.removeChild(existNode);
|
|
76
|
-
}
|
|
53
|
+
const existNode = findExistNode(key, option);
|
|
54
|
+
if (existNode) getContainer(option).removeChild(existNode);
|
|
77
55
|
}
|
|
78
56
|
function syncRealContainer(container, option) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
57
|
+
const cachedRealContainer = containerCache.get(container);
|
|
58
|
+
if (!cachedRealContainer || !contains(document, cachedRealContainer)) {
|
|
59
|
+
const placeholderStyle = injectCSS("", option);
|
|
60
|
+
const { parentNode } = placeholderStyle;
|
|
61
|
+
containerCache.set(container, parentNode);
|
|
62
|
+
container.removeChild(placeholderStyle);
|
|
63
|
+
}
|
|
86
64
|
}
|
|
87
65
|
function clearContainerCache() {
|
|
88
|
-
|
|
66
|
+
containerCache.clear();
|
|
89
67
|
}
|
|
90
68
|
function updateCSS(css, key, option = {}) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const newNode = injectCSS(css, option);
|
|
102
|
-
newNode.setAttribute(getMark(option), key);
|
|
103
|
-
return newNode;
|
|
69
|
+
syncRealContainer(getContainer(option), option);
|
|
70
|
+
const existNode = findExistNode(key, option);
|
|
71
|
+
if (existNode) {
|
|
72
|
+
if (option.csp?.nonce && existNode.nonce !== option.csp?.nonce) existNode.nonce = option.csp?.nonce;
|
|
73
|
+
if (existNode.innerHTML !== css) existNode.innerHTML = css;
|
|
74
|
+
return existNode;
|
|
75
|
+
}
|
|
76
|
+
const newNode = injectCSS(css, option);
|
|
77
|
+
newNode.setAttribute(getMark(option), key);
|
|
78
|
+
return newNode;
|
|
104
79
|
}
|
|
105
|
-
export {
|
|
106
|
-
clearContainerCache,
|
|
107
|
-
injectCSS,
|
|
108
|
-
removeCSS,
|
|
109
|
-
updateCSS
|
|
110
|
-
};
|
|
80
|
+
export { clearContainerCache, injectCSS, removeCSS, updateCSS };
|
package/dist/Dom/findDOMNode.cjs
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
const vue = require("vue");
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
let vue = require("vue");
|
|
4
3
|
function isDOM(node) {
|
|
5
|
-
|
|
4
|
+
return node instanceof HTMLElement || node instanceof SVGElement;
|
|
6
5
|
}
|
|
7
6
|
function findDOMNode(_node) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return node.$el;
|
|
13
|
-
return null;
|
|
7
|
+
const node = (0, vue.unref)(_node);
|
|
8
|
+
if (isDOM(node)) return node;
|
|
9
|
+
else if (node && "$el" in node) return node.$el;
|
|
10
|
+
return null;
|
|
14
11
|
}
|
|
15
12
|
exports.default = findDOMNode;
|
|
16
13
|
exports.isDOM = isDOM;
|
package/dist/Dom/findDOMNode.js
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import { unref } from "vue";
|
|
2
2
|
function isDOM(node) {
|
|
3
|
-
|
|
3
|
+
return node instanceof HTMLElement || node instanceof SVGElement;
|
|
4
4
|
}
|
|
5
5
|
function findDOMNode(_node) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return node.$el;
|
|
11
|
-
return null;
|
|
6
|
+
const node = unref(_node);
|
|
7
|
+
if (isDOM(node)) return node;
|
|
8
|
+
else if (node && "$el" in node) return node.$el;
|
|
9
|
+
return null;
|
|
12
10
|
}
|
|
13
|
-
export {
|
|
14
|
-
findDOMNode as default,
|
|
15
|
-
isDOM
|
|
16
|
-
};
|
|
11
|
+
export { findDOMNode as default, isDOM };
|
package/dist/Dom/focus.cjs
CHANGED
|
@@ -1,57 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const isVisible = require("./isVisible.cjs");
|
|
1
|
+
const require_isVisible = require("./isVisible.cjs");
|
|
4
2
|
function focusable(node, includePositive = false) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
3
|
+
if (require_isVisible.default(node)) {
|
|
4
|
+
const nodeName = node.nodeName.toLowerCase();
|
|
5
|
+
const isFocusableElement = [
|
|
6
|
+
"input",
|
|
7
|
+
"select",
|
|
8
|
+
"textarea",
|
|
9
|
+
"button"
|
|
10
|
+
].includes(nodeName) || node.isContentEditable || nodeName === "a" && !!node.getAttribute("href");
|
|
11
|
+
const tabIndexAttr = node.getAttribute("tabindex");
|
|
12
|
+
const tabIndexNum = Number(tabIndexAttr);
|
|
13
|
+
let tabIndex = null;
|
|
14
|
+
if (tabIndexAttr && !Number.isNaN(tabIndexNum)) tabIndex = tabIndexNum;
|
|
15
|
+
else if (isFocusableElement && tabIndex === null) tabIndex = 0;
|
|
16
|
+
if (isFocusableElement && node.disabled) tabIndex = null;
|
|
17
|
+
return tabIndex !== null && (tabIndex >= 0 || includePositive && tabIndex < 0);
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
20
|
}
|
|
21
21
|
function getFocusNodeList(node, includePositive = false) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return res;
|
|
22
|
+
const res = [...node.querySelectorAll("*")].filter((child) => {
|
|
23
|
+
return focusable(child, includePositive);
|
|
24
|
+
});
|
|
25
|
+
if (focusable(node, includePositive)) res.unshift(node);
|
|
26
|
+
return res;
|
|
28
27
|
}
|
|
29
|
-
|
|
28
|
+
var lastFocusElement = null;
|
|
30
29
|
function saveLastFocusNode() {
|
|
31
|
-
|
|
30
|
+
lastFocusElement = document.activeElement;
|
|
32
31
|
}
|
|
33
32
|
function clearLastFocusNode() {
|
|
34
|
-
|
|
33
|
+
lastFocusElement = null;
|
|
35
34
|
}
|
|
36
35
|
function backLastFocusNode() {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
} catch (_e) {
|
|
41
|
-
}
|
|
42
|
-
}
|
|
36
|
+
if (lastFocusElement) try {
|
|
37
|
+
lastFocusElement.focus();
|
|
38
|
+
} catch (_e) {}
|
|
43
39
|
}
|
|
44
40
|
function limitTabRange(node, e) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
e.preventDefault();
|
|
53
|
-
}
|
|
54
|
-
}
|
|
41
|
+
if (e.keyCode === 9) {
|
|
42
|
+
const tabNodeList = getFocusNodeList(node);
|
|
43
|
+
if (tabNodeList[e.shiftKey ? 0 : tabNodeList.length - 1] === document.activeElement || node === document.activeElement) {
|
|
44
|
+
tabNodeList[e.shiftKey ? tabNodeList.length - 1 : 0].focus();
|
|
45
|
+
e.preventDefault();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
55
48
|
}
|
|
56
49
|
exports.backLastFocusNode = backLastFocusNode;
|
|
57
50
|
exports.clearLastFocusNode = clearLastFocusNode;
|
package/dist/Dom/focus.js
CHANGED
|
@@ -1,60 +1,49 @@
|
|
|
1
|
-
import
|
|
1
|
+
import isVisible_default from "./isVisible.js";
|
|
2
2
|
function focusable(node, includePositive = false) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
3
|
+
if (isVisible_default(node)) {
|
|
4
|
+
const nodeName = node.nodeName.toLowerCase();
|
|
5
|
+
const isFocusableElement = [
|
|
6
|
+
"input",
|
|
7
|
+
"select",
|
|
8
|
+
"textarea",
|
|
9
|
+
"button"
|
|
10
|
+
].includes(nodeName) || node.isContentEditable || nodeName === "a" && !!node.getAttribute("href");
|
|
11
|
+
const tabIndexAttr = node.getAttribute("tabindex");
|
|
12
|
+
const tabIndexNum = Number(tabIndexAttr);
|
|
13
|
+
let tabIndex = null;
|
|
14
|
+
if (tabIndexAttr && !Number.isNaN(tabIndexNum)) tabIndex = tabIndexNum;
|
|
15
|
+
else if (isFocusableElement && tabIndex === null) tabIndex = 0;
|
|
16
|
+
if (isFocusableElement && node.disabled) tabIndex = null;
|
|
17
|
+
return tabIndex !== null && (tabIndex >= 0 || includePositive && tabIndex < 0);
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
18
20
|
}
|
|
19
21
|
function getFocusNodeList(node, includePositive = false) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return res;
|
|
22
|
+
const res = [...node.querySelectorAll("*")].filter((child) => {
|
|
23
|
+
return focusable(child, includePositive);
|
|
24
|
+
});
|
|
25
|
+
if (focusable(node, includePositive)) res.unshift(node);
|
|
26
|
+
return res;
|
|
26
27
|
}
|
|
27
|
-
|
|
28
|
+
var lastFocusElement = null;
|
|
28
29
|
function saveLastFocusNode() {
|
|
29
|
-
|
|
30
|
+
lastFocusElement = document.activeElement;
|
|
30
31
|
}
|
|
31
32
|
function clearLastFocusNode() {
|
|
32
|
-
|
|
33
|
+
lastFocusElement = null;
|
|
33
34
|
}
|
|
34
35
|
function backLastFocusNode() {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
} catch (_e) {
|
|
39
|
-
}
|
|
40
|
-
}
|
|
36
|
+
if (lastFocusElement) try {
|
|
37
|
+
lastFocusElement.focus();
|
|
38
|
+
} catch (_e) {}
|
|
41
39
|
}
|
|
42
40
|
function limitTabRange(node, e) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
e.preventDefault();
|
|
51
|
-
}
|
|
52
|
-
}
|
|
41
|
+
if (e.keyCode === 9) {
|
|
42
|
+
const tabNodeList = getFocusNodeList(node);
|
|
43
|
+
if (tabNodeList[e.shiftKey ? 0 : tabNodeList.length - 1] === document.activeElement || node === document.activeElement) {
|
|
44
|
+
tabNodeList[e.shiftKey ? tabNodeList.length - 1 : 0].focus();
|
|
45
|
+
e.preventDefault();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
53
48
|
}
|
|
54
|
-
export {
|
|
55
|
-
backLastFocusNode,
|
|
56
|
-
clearLastFocusNode,
|
|
57
|
-
getFocusNodeList,
|
|
58
|
-
limitTabRange,
|
|
59
|
-
saveLastFocusNode
|
|
60
|
-
};
|
|
49
|
+
export { backLastFocusNode, clearLastFocusNode, getFocusNodeList, limitTabRange, saveLastFocusNode };
|
package/dist/Dom/isVisible.cjs
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (width || height)
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return false;
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
var isVisible_default = (element) => {
|
|
3
|
+
if (!element) return false;
|
|
4
|
+
if (element instanceof Element) {
|
|
5
|
+
if (element.offsetParent) return true;
|
|
6
|
+
if (element.getBBox) {
|
|
7
|
+
const { width, height } = element.getBBox();
|
|
8
|
+
if (width || height) return true;
|
|
9
|
+
}
|
|
10
|
+
if (element.getBoundingClientRect) {
|
|
11
|
+
const { width, height } = element.getBoundingClientRect();
|
|
12
|
+
if (width || height) return true;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
21
16
|
};
|
|
22
|
-
exports.default =
|
|
17
|
+
exports.default = isVisible_default;
|