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