@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.
Files changed (108) hide show
  1. package/dist/Children/isFragment.cjs +7 -1
  2. package/dist/Children/isFragment.js +4 -4
  3. package/dist/Children/toArray.cjs +20 -1
  4. package/dist/Children/toArray.js +17 -8
  5. package/dist/Dom/addEventListener.cjs +13 -1
  6. package/dist/Dom/addEventListener.js +7 -5
  7. package/dist/Dom/canUseDom.cjs +6 -1
  8. package/dist/Dom/canUseDom.js +3 -3
  9. package/dist/Dom/class.cjs +29 -1
  10. package/dist/Dom/class.js +23 -13
  11. package/dist/Dom/contains.cjs +16 -1
  12. package/dist/Dom/contains.js +12 -12
  13. package/dist/Dom/css.cjs +96 -1
  14. package/dist/Dom/css.js +69 -48
  15. package/dist/Dom/dynamicCSS.cjs +110 -1
  16. package/dist/Dom/dynamicCSS.js +92 -59
  17. package/dist/Dom/findDOMNode.cjs +16 -1
  18. package/dist/Dom/findDOMNode.js +12 -8
  19. package/dist/Dom/focus.cjs +60 -1
  20. package/dist/Dom/focus.js +48 -28
  21. package/dist/Dom/isVisible.cjs +22 -1
  22. package/dist/Dom/isVisible.js +16 -16
  23. package/dist/Dom/scrollLocker.cjs +89 -1
  24. package/dist/Dom/scrollLocker.js +70 -45
  25. package/dist/Dom/shadow.cjs +13 -1
  26. package/dist/Dom/shadow.js +8 -8
  27. package/dist/Dom/styleChecker.cjs +25 -1
  28. package/dist/Dom/styleChecker.js +19 -14
  29. package/dist/Dom/support.cjs +28 -1
  30. package/dist/Dom/support.js +16 -12
  31. package/dist/KeyCode.cjs +523 -1
  32. package/dist/KeyCode.js +62 -55
  33. package/dist/Portal.cjs +48 -1
  34. package/dist/Portal.js +34 -19
  35. package/dist/PortalWrapper.cjs +169 -1
  36. package/dist/PortalWrapper.js +133 -79
  37. package/dist/classnames.cjs +45 -1
  38. package/dist/classnames.js +38 -25
  39. package/dist/composeProps.cjs +19 -1
  40. package/dist/composeProps.js +15 -9
  41. package/dist/createRef.cjs +24 -1
  42. package/dist/createRef.js +16 -13
  43. package/dist/debug/diff.cjs +50 -1
  44. package/dist/debug/diff.js +39 -30
  45. package/dist/deprecated.cjs +10 -1
  46. package/dist/deprecated.js +7 -5
  47. package/dist/getScrollBarSize.cjs +51 -1
  48. package/dist/getScrollBarSize.js +39 -25
  49. package/dist/guid.cjs +7 -1
  50. package/dist/guid.js +4 -4
  51. package/dist/hooks/useEvent.cjs +6 -1
  52. package/dist/hooks/useEvent.js +3 -3
  53. package/dist/hooks/useId.cjs +18 -1
  54. package/dist/hooks/useId.js +14 -8
  55. package/dist/hooks/useLayoutEffect.cjs +58 -1
  56. package/dist/hooks/useLayoutEffect.js +50 -20
  57. package/dist/hooks/useMemo.cjs +16 -1
  58. package/dist/hooks/useMemo.js +13 -7
  59. package/dist/hooks/useMergedState.cjs +30 -1
  60. package/dist/hooks/useMergedState.js +25 -16
  61. package/dist/hooks/useMobile.cjs +16 -1
  62. package/dist/hooks/useMobile.js +13 -11
  63. package/dist/hooks/useState.cjs +12 -1
  64. package/dist/hooks/useState.js +8 -7
  65. package/dist/index.cjs +11 -1
  66. package/dist/index.js +9 -9
  67. package/dist/isEqual.cjs +36 -1
  68. package/dist/isEqual.js +30 -26
  69. package/dist/isMobile.cjs +13 -1
  70. package/dist/isMobile.js +7 -7
  71. package/dist/isValid.cjs +6 -1
  72. package/dist/isValid.js +3 -3
  73. package/dist/omit.cjs +12 -1
  74. package/dist/omit.js +9 -6
  75. package/dist/pickAttrs.cjs +41 -3
  76. package/dist/pickAttrs.js +37 -22
  77. package/dist/props-util/index.cjs +69 -1
  78. package/dist/props-util/index.js +62 -32
  79. package/dist/raf.cjs +48 -1
  80. package/dist/raf.js +37 -26
  81. package/dist/setStyle.cjs +17 -1
  82. package/dist/setStyle.js +13 -9
  83. package/dist/switchScrollingEffect.cjs +38 -1
  84. package/dist/switchScrollingEffect.js +27 -20
  85. package/dist/test/domHook.cjs +52 -1
  86. package/dist/test/domHook.js +43 -28
  87. package/dist/type.cjs +51 -1
  88. package/dist/type.js +39 -37
  89. package/dist/utils/checkSlotProp.cjs +13 -1
  90. package/dist/utils/checkSlotProp.js +10 -3
  91. package/dist/utils/get.cjs +12 -1
  92. package/dist/utils/get.js +8 -8
  93. package/dist/utils/omit.cjs +10 -1
  94. package/dist/utils/omit.js +7 -6
  95. package/dist/utils/set.cjs +64 -1
  96. package/dist/utils/set.js +54 -32
  97. package/dist/utils/transition.cjs +96 -1
  98. package/dist/utils/transition.d.ts +2 -2
  99. package/dist/utils/transition.js +70 -65
  100. package/dist/utils/watchState.cjs +20 -1
  101. package/dist/utils/watchState.js +15 -10
  102. package/dist/vnode.cjs +56 -1
  103. package/dist/vnode.js +46 -30
  104. package/dist/vueuse/unref-element.cjs +8 -1
  105. package/dist/vueuse/unref-element.js +5 -5
  106. package/dist/warning.cjs +53 -1
  107. package/dist/warning.js +40 -35
  108. package/package.json +1 -1
@@ -1,77 +1,110 @@
1
- import N from "./canUseDom.js";
2
- import b from "./contains.js";
3
- const h = "data-vc-order", p = "data-vc-priority", E = "vc-util-key", s = /* @__PURE__ */ new Map();
4
- function m({ mark: e } = {}) {
5
- return e ? e.startsWith("data-") ? e : `data-${e}` : E;
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 d(e) {
8
- return e.attachTo ? e.attachTo : document.querySelector("head") || document.body;
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 P(e) {
11
- return e === "queue" ? "prependQueue" : e ? "prepend" : "append";
18
+ function getOrder(prepend) {
19
+ if (prepend === "queue")
20
+ return "prependQueue";
21
+ return prepend ? "prepend" : "append";
12
22
  }
13
- function g(e) {
23
+ function findStyles(container) {
14
24
  return Array.from(
15
- (s.get(e) || e).children
16
- ).filter((n) => n.tagName === "STYLE");
25
+ (containerCache.get(container) || container).children
26
+ ).filter((node) => node.tagName === "STYLE");
17
27
  }
18
- function C(e, n = {}) {
19
- if (!N())
28
+ function injectCSS(css, option = {}) {
29
+ if (!canUseDom())
20
30
  return null;
21
- const { csp: t, prepend: c, priority: r = 0 } = n, o = P(c), f = o === "prependQueue", i = document.createElement("style");
22
- i.setAttribute(h, o), f && r && i.setAttribute(p, `${r}`), t?.nonce && (i.nonce = t?.nonce), i.innerHTML = e;
23
- const u = d(n), { firstChild: S } = u;
24
- if (c) {
25
- if (f) {
26
- const a = g(u).filter((l) => {
27
- if (!["prepend", "prependQueue"].includes(l.getAttribute(h)))
28
- return !1;
29
- const A = Number(l.getAttribute(p) || 0);
30
- return r >= A;
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 (a.length)
33
- return u.insertBefore(
34
- i,
35
- a[a.length - 1].nextSibling
36
- ), i;
51
+ if (existStyle.length) {
52
+ container.insertBefore(
53
+ styleNode,
54
+ existStyle[existStyle.length - 1].nextSibling
55
+ );
56
+ return styleNode;
57
+ }
37
58
  }
38
- u.insertBefore(i, S);
39
- } else
40
- u.appendChild(i);
41
- return i;
59
+ container.insertBefore(styleNode, firstChild);
60
+ } else {
61
+ container.appendChild(styleNode);
62
+ }
63
+ return styleNode;
42
64
  }
43
- function y(e, n = {}) {
44
- const t = d(n);
45
- return g(t).find(
46
- (c) => c.getAttribute(m(n)) === e
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 x(e, n = {}) {
50
- const t = y(e, n);
51
- t && d(n).removeChild(t);
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 R(e, n) {
54
- const t = s.get(e);
55
- if (!t || !b(document, t)) {
56
- const c = C("", n), { parentNode: r } = c;
57
- s.set(e, r), e.removeChild(c);
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 M() {
61
- s.clear();
87
+ function clearContainerCache() {
88
+ containerCache.clear();
62
89
  }
63
- function D(e, n, t = {}) {
64
- const c = d(t);
65
- R(c, t);
66
- const r = y(n, t);
67
- if (r)
68
- return t.csp?.nonce && r.nonce !== t.csp?.nonce && (r.nonce = t.csp?.nonce), r.innerHTML !== e && (r.innerHTML = e), r;
69
- const o = C(e, t);
70
- return o.setAttribute(m(t), n), o;
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
- M as clearContainerCache,
74
- C as injectCSS,
75
- x as removeCSS,
76
- D as updateCSS
106
+ clearContainerCache,
107
+ injectCSS,
108
+ removeCSS,
109
+ updateCSS
77
110
  };
@@ -1 +1,16 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const u=require("vue");function t(n){return n instanceof HTMLElement||n instanceof SVGElement}function r(n){const e=u.unref(n);return t(e)?e:e&&"$el"in e?e.$el:null}exports.default=r;exports.isDOM=t;
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;
@@ -1,12 +1,16 @@
1
- import { unref as t } from "vue";
2
- function r(e) {
3
- return e instanceof HTMLElement || e instanceof SVGElement;
1
+ import { unref } from "vue";
2
+ function isDOM(node) {
3
+ return node instanceof HTMLElement || node instanceof SVGElement;
4
4
  }
5
- function i(e) {
6
- const n = t(e);
7
- return r(n) ? n : n && "$el" in n ? n.$el : null;
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
- i as default,
11
- r as isDOM
14
+ findDOMNode as default,
15
+ isDOM
12
16
  };
@@ -1 +1,60 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./isVisible.cjs");function c(t,s=!1){if(r.default(t)){const e=t.nodeName.toLowerCase(),n=["input","select","textarea","button"].includes(e)||t.isContentEditable||e==="a"&&!!t.getAttribute("href"),u=t.getAttribute("tabindex"),o=Number(u);let a=null;return u&&!Number.isNaN(o)?a=o:n&&a===null&&(a=0),n&&t.disabled&&(a=null),a!==null&&(a>=0||s&&a<0)}return!1}function i(t,s=!1){const e=[...t.querySelectorAll("*")].filter(n=>c(n,s));return c(t,s)&&e.unshift(t),e}let l=null;function f(){l=document.activeElement}function b(){l=null}function d(){if(l)try{l.focus()}catch{}}function N(t,s){if(s.keyCode===9){const e=i(t);(e[s.shiftKey?0:e.length-1]===document.activeElement||t===document.activeElement)&&(e[s.shiftKey?e.length-1:0].focus(),s.preventDefault())}}exports.backLastFocusNode=d;exports.clearLastFocusNode=b;exports.getFocusNodeList=i;exports.limitTabRange=N;exports.saveLastFocusNode=f;
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 o from "./isVisible.js";
2
- function c(t, n = !1) {
3
- if (o(t)) {
4
- const e = t.nodeName.toLowerCase(), l = ["input", "select", "textarea", "button"].includes(e) || t.isContentEditable || e === "a" && !!t.getAttribute("href"), i = t.getAttribute("tabindex"), u = Number(i);
5
- let a = null;
6
- return i && !Number.isNaN(u) ? a = u : l && a === null && (a = 0), l && t.disabled && (a = null), a !== null && (a >= 0 || n && a < 0);
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 !1;
17
+ return false;
9
18
  }
10
- function r(t, n = !1) {
11
- const e = [...t.querySelectorAll("*")].filter((l) => c(l, n));
12
- return c(t, n) && e.unshift(t), e;
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 s = null;
15
- function b() {
16
- s = document.activeElement;
27
+ let lastFocusElement = null;
28
+ function saveLastFocusNode() {
29
+ lastFocusElement = document.activeElement;
17
30
  }
18
- function m() {
19
- s = null;
31
+ function clearLastFocusNode() {
32
+ lastFocusElement = null;
20
33
  }
21
- function N() {
22
- if (s)
34
+ function backLastFocusNode() {
35
+ if (lastFocusElement) {
23
36
  try {
24
- s.focus();
25
- } catch {
37
+ lastFocusElement.focus();
38
+ } catch (_e) {
26
39
  }
40
+ }
27
41
  }
28
- function d(t, n) {
29
- if (n.keyCode === 9) {
30
- const e = r(t);
31
- (e[n.shiftKey ? 0 : e.length - 1] === document.activeElement || t === document.activeElement) && (e[n.shiftKey ? e.length - 1 : 0].focus(), n.preventDefault());
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
- N as backLastFocusNode,
36
- m as clearLastFocusNode,
37
- r as getFocusNodeList,
38
- d as limitTabRange,
39
- b as saveLastFocusNode
55
+ backLastFocusNode,
56
+ clearLastFocusNode,
57
+ getFocusNodeList,
58
+ limitTabRange,
59
+ saveLastFocusNode
40
60
  };
@@ -1 +1,22 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=t=>{if(!t)return!1;if(t instanceof Element){if(t.offsetParent)return!0;if(t.getBBox){const{width:i,height:e}=t.getBBox();if(i||e)return!0}if(t.getBoundingClientRect){const{width:i,height:e}=t.getBoundingClientRect();if(i||e)return!0}}return!1};exports.default=r;
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;
@@ -1,22 +1,22 @@
1
- const f = (t) => {
2
- if (!t)
3
- return !1;
4
- if (t instanceof Element) {
5
- if (t.offsetParent)
6
- return !0;
7
- if (t.getBBox) {
8
- const { width: i, height: r } = t.getBBox();
9
- if (i || r)
10
- return !0;
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 (t.getBoundingClientRect) {
13
- const { width: i, height: r } = t.getBoundingClientRect();
14
- if (i || r)
15
- return !0;
12
+ if (element.getBoundingClientRect) {
13
+ const { width, height } = element.getBoundingClientRect();
14
+ if (width || height)
15
+ return true;
16
16
  }
17
17
  }
18
- return !1;
18
+ return false;
19
19
  };
20
20
  export {
21
- f as default
21
+ isVisible as default
22
22
  };
@@ -1 +1,89 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const a=require("../getScrollBarSize.cjs"),l=require("../setStyle.cjs");let d=0,o=[];const r="ant-scrolling-effect",s=new RegExp(`${r}`,"g"),c=new Map;class f{lockTarget;options;constructor(n){this.lockTarget=d++,this.options=n}getContainer=()=>this.options?.container;reLock=n=>{const t=o.find(({target:i})=>i===this.lockTarget);t&&this.unLock(),this.options=n,t&&(t.options=n,this.lock())};lock=()=>{if(o.some(({target:e})=>e===this.lockTarget))return;if(o.some(({options:e})=>e?.container===this.options?.container)){o=[...o,{target:this.lockTarget,options:this.options}];return}let n=0;const t=this.options?.container||document.body;(t===document.body&&window.innerWidth-document.documentElement.clientWidth>0||t.scrollHeight>t.clientHeight)&&getComputedStyle(t).overflow!=="hidden"&&(n=a.default());const i=t.className;if(o.filter(({options:e})=>e?.container===this.options?.container).length===0&&c.set(t,l.default({width:n!==0?`calc(100% - ${n}px)`:void 0,overflow:"hidden",overflowX:"hidden",overflowY:"hidden"},{element:t})),!s.test(i)){const e=`${i} ${r}`;t.className=e.trim()}o=[...o,{target:this.lockTarget,options:this.options}]};unLock=()=>{const n=o.find(({target:e})=>e===this.lockTarget);if(o=o.filter(({target:e})=>e!==this.lockTarget),!n||o.some(({options:e})=>e?.container===n.options?.container))return;const t=this.options?.container||document.body,i=t.className;s.test(i)&&(l.default(c.get(t),{element:t}),c.delete(t),t.className=t.className.replace(s,"").trim())}}exports.default=f;
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;
@@ -1,64 +1,89 @@
1
- import a from "../getScrollBarSize.js";
2
- import r from "../setStyle.js";
3
- let d = 0, o = [];
4
- const l = "ant-scrolling-effect", s = new RegExp(
5
- `${l}`,
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
- ), c = /* @__PURE__ */ new Map();
8
- class g {
9
+ );
10
+ const cacheStyle = /* @__PURE__ */ new Map();
11
+ class ScrollLocker {
9
12
  lockTarget;
10
13
  options;
11
- constructor(n) {
12
- this.lockTarget = d++, this.options = n;
14
+ constructor(options) {
15
+ this.lockTarget = uuid++;
16
+ this.options = options;
13
17
  }
14
- getContainer = () => this.options?.container;
18
+ getContainer = () => {
19
+ return this.options?.container;
20
+ };
15
21
  // if options change...
16
- reLock = (n) => {
17
- const t = o.find(({ target: i }) => i === this.lockTarget);
18
- t && this.unLock(), this.options = n, t && (t.options = n, this.lock());
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 (o.some(({ target: e }) => e === this.lockTarget))
33
+ if (locks.some(({ target }) => target === this.lockTarget))
22
34
  return;
23
- if (o.some(
24
- ({ options: e }) => e?.container === this.options?.container
35
+ if (locks.some(
36
+ ({ options }) => options?.container === this.options?.container
25
37
  )) {
26
- o = [...o, { target: this.lockTarget, options: this.options }];
38
+ locks = [...locks, { target: this.lockTarget, options: this.options }];
27
39
  return;
28
40
  }
29
- let n = 0;
30
- const t = this.options?.container || document.body;
31
- (t === document.body && window.innerWidth - document.documentElement.clientWidth > 0 || t.scrollHeight > t.clientHeight) && getComputedStyle(t).overflow !== "hidden" && (n = a());
32
- const i = t.className;
33
- if (o.filter(
34
- ({ options: e }) => e?.container === this.options?.container
35
- ).length === 0 && c.set(
36
- t,
37
- r(
38
- {
39
- width: n !== 0 ? `calc(100% - ${n}px)` : void 0,
40
- overflow: "hidden",
41
- overflowX: "hidden",
42
- overflowY: "hidden"
43
- },
44
- { element: t }
45
- )
46
- ), !s.test(i)) {
47
- const e = `${i} ${l}`;
48
- t.className = e.trim();
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
- o = [...o, { target: this.lockTarget, options: this.options }];
68
+ locks = [...locks, { target: this.lockTarget, options: this.options }];
51
69
  };
52
70
  unLock = () => {
53
- const n = o.find(({ target: e }) => e === this.lockTarget);
54
- if (o = o.filter(({ target: e }) => e !== this.lockTarget), !n || o.some(
55
- ({ options: e }) => e?.container === n.options?.container
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
- const t = this.options?.container || document.body, i = t.className;
59
- s.test(i) && (r(c.get(t), { element: t }), c.delete(t), t.className = t.className.replace(s, "").trim());
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
- g as default
88
+ ScrollLocker as default
64
89
  };