@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 +1,7 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("vue");function r(e){return t.isVNode(e)&&e.type===t.Fragment}exports.isFragment=r;
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const vue = require("vue");
4
+ function isFragment(node) {
5
+ return vue.isVNode(node) && node.type === vue.Fragment;
6
+ }
7
+ exports.isFragment = isFragment;
@@ -1,7 +1,7 @@
1
- import { isVNode as t, Fragment as e } from "vue";
2
- function m(r) {
3
- return t(r) && r.type === e;
1
+ import { isVNode, Fragment } from "vue";
2
+ function isFragment(node) {
3
+ return isVNode(node) && node.type === Fragment;
4
4
  }
5
5
  export {
6
- m as isFragment
6
+ isFragment
7
7
  };
@@ -1 +1,20 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./isFragment.cjs");function a(t,i={}){let e=[];Array.isArray(t)||(t=[t]);for(const r of t)r==null&&!i.keepEmpty||(Array.isArray(r)?e=e.concat(a(r,i)):n.isFragment(r)&&r.children?e=e.concat(a(r.children,i)):e.push(r));return e}exports.toArray=a;
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const isFragment = require("./isFragment.cjs");
4
+ function toArray(children, option = {}) {
5
+ let ret = [];
6
+ if (!Array.isArray(children))
7
+ children = [children];
8
+ for (const child of children) {
9
+ if ((child === void 0 || child === null) && !option.keepEmpty)
10
+ continue;
11
+ if (Array.isArray(child))
12
+ ret = ret.concat(toArray(child, option));
13
+ else if (isFragment.isFragment(child) && child.children)
14
+ ret = ret.concat(toArray(child.children, option));
15
+ else
16
+ ret.push(child);
17
+ }
18
+ return ret;
19
+ }
20
+ exports.toArray = toArray;
@@ -1,11 +1,20 @@
1
- import { isFragment as f } from "./isFragment.js";
2
- function a(t, i = {}) {
3
- let e = [];
4
- Array.isArray(t) || (t = [t]);
5
- for (const r of t)
6
- r == null && !i.keepEmpty || (Array.isArray(r) ? e = e.concat(a(r, i)) : f(r) && r.children ? e = e.concat(a(r.children, i)) : e.push(r));
7
- return e;
1
+ import { isFragment } from "./isFragment.js";
2
+ function toArray(children, option = {}) {
3
+ let ret = [];
4
+ if (!Array.isArray(children))
5
+ children = [children];
6
+ for (const child of children) {
7
+ if ((child === void 0 || child === null) && !option.keepEmpty)
8
+ continue;
9
+ if (Array.isArray(child))
10
+ ret = ret.concat(toArray(child, option));
11
+ else if (isFragment(child) && child.children)
12
+ ret = ret.concat(toArray(child.children, option));
13
+ else
14
+ ret.push(child);
15
+ }
16
+ return ret;
8
17
  }
9
18
  export {
10
- a as toArray
19
+ toArray
11
20
  };
@@ -1 +1,13 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function d(...i){const[e,t,n,r]=i;return e?.addEventListener&&e.addEventListener(t,n,r),{remove(){e?.removeEventListener?.(t,n,r)}}}exports.addEventListener=d;
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function addEventListener(...args) {
4
+ const [target, eventType, cb, option] = args;
5
+ if (target?.addEventListener)
6
+ target.addEventListener(eventType, cb, option);
7
+ return {
8
+ remove() {
9
+ target?.removeEventListener?.(eventType, cb, option);
10
+ }
11
+ };
12
+ }
13
+ exports.addEventListener = addEventListener;
@@ -1,11 +1,13 @@
1
- function o(...i) {
2
- const [e, t, n, r] = i;
3
- return e?.addEventListener && e.addEventListener(t, n, r), {
1
+ function addEventListener(...args) {
2
+ const [target, eventType, cb, option] = args;
3
+ if (target?.addEventListener)
4
+ target.addEventListener(eventType, cb, option);
5
+ return {
4
6
  remove() {
5
- e?.removeEventListener?.(t, n, r);
7
+ target?.removeEventListener?.(eventType, cb, option);
6
8
  }
7
9
  };
8
10
  }
9
11
  export {
10
- o as addEventListener
12
+ addEventListener
11
13
  };
@@ -1 +1,6 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function e(){return!!(typeof window<"u"&&window.document&&window.document.createElement)}exports.default=e;
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ function canUseDom() {
4
+ return !!(typeof window !== "undefined" && window.document && window.document.createElement);
5
+ }
6
+ exports.default = canUseDom;
@@ -1,6 +1,6 @@
1
- function e() {
2
- return !!(typeof window < "u" && window.document && window.document.createElement);
1
+ function canUseDom() {
2
+ return !!(typeof window !== "undefined" && window.document && window.document.createElement);
3
3
  }
4
4
  export {
5
- e as default
5
+ canUseDom as default
6
6
  };
@@ -1 +1,29 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function a(s,i){return s.classList?s.classList.contains(i):` ${s.className} `.includes(` ${i} `)}function t(s,i){s.classList?s.classList.add(i):a(s,i)||(s.className=`${s.className} ${i}`)}function c(s,i){if(s.classList)s.classList.remove(i);else if(a(s,i)){const l=s.className;s.className=` ${l} `.replace(` ${i} `," ")}}exports.addClass=t;exports.hasClass=a;exports.removeClass=c;
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function hasClass(node, className) {
4
+ if (node.classList)
5
+ return node.classList.contains(className);
6
+ const originClass = node.className;
7
+ return ` ${originClass} `.includes(` ${className} `);
8
+ }
9
+ function addClass(node, className) {
10
+ if (node.classList) {
11
+ node.classList.add(className);
12
+ } else {
13
+ if (!hasClass(node, className))
14
+ node.className = `${node.className} ${className}`;
15
+ }
16
+ }
17
+ function removeClass(node, className) {
18
+ if (node.classList) {
19
+ node.classList.remove(className);
20
+ } else {
21
+ if (hasClass(node, className)) {
22
+ const originClass = node.className;
23
+ node.className = ` ${originClass} `.replace(` ${className} `, " ");
24
+ }
25
+ }
26
+ }
27
+ exports.addClass = addClass;
28
+ exports.hasClass = hasClass;
29
+ exports.removeClass = removeClass;
package/dist/Dom/class.js CHANGED
@@ -1,19 +1,29 @@
1
- function l(s, i) {
2
- return s.classList ? s.classList.contains(i) : ` ${s.className} `.includes(` ${i} `);
1
+ function hasClass(node, className) {
2
+ if (node.classList)
3
+ return node.classList.contains(className);
4
+ const originClass = node.className;
5
+ return ` ${originClass} `.includes(` ${className} `);
3
6
  }
4
- function t(s, i) {
5
- s.classList ? s.classList.add(i) : l(s, i) || (s.className = `${s.className} ${i}`);
7
+ function addClass(node, className) {
8
+ if (node.classList) {
9
+ node.classList.add(className);
10
+ } else {
11
+ if (!hasClass(node, className))
12
+ node.className = `${node.className} ${className}`;
13
+ }
6
14
  }
7
- function c(s, i) {
8
- if (s.classList)
9
- s.classList.remove(i);
10
- else if (l(s, i)) {
11
- const a = s.className;
12
- s.className = ` ${a} `.replace(` ${i} `, " ");
15
+ function removeClass(node, className) {
16
+ if (node.classList) {
17
+ node.classList.remove(className);
18
+ } else {
19
+ if (hasClass(node, className)) {
20
+ const originClass = node.className;
21
+ node.className = ` ${originClass} `.replace(` ${className} `, " ");
22
+ }
13
23
  }
14
24
  }
15
25
  export {
16
- t as addClass,
17
- l as hasClass,
18
- c as removeClass
26
+ addClass,
27
+ hasClass,
28
+ removeClass
19
29
  };
@@ -1 +1,16 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function u(e,n){if(!e)return!1;if(e.contains)return e.contains(n);let t=n;for(;t;){if(t===e)return!0;t=t.parentNode}return!1}exports.default=u;
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ function contains(root, n) {
4
+ if (!root)
5
+ return false;
6
+ if (root.contains)
7
+ return root.contains(n);
8
+ let node = n;
9
+ while (node) {
10
+ if (node === root)
11
+ return true;
12
+ node = node.parentNode;
13
+ }
14
+ return false;
15
+ }
16
+ exports.default = contains;
@@ -1,16 +1,16 @@
1
- function a(e, t) {
2
- if (!e)
3
- return !1;
4
- if (e.contains)
5
- return e.contains(t);
6
- let n = t;
7
- for (; n; ) {
8
- if (n === e)
9
- return !0;
10
- n = n.parentNode;
1
+ function contains(root, n) {
2
+ if (!root)
3
+ return false;
4
+ if (root.contains)
5
+ return root.contains(n);
6
+ let node = n;
7
+ while (node) {
8
+ if (node === root)
9
+ return true;
10
+ node = node.parentNode;
11
11
  }
12
- return !1;
12
+ return false;
13
13
  }
14
14
  export {
15
- a as default
15
+ contains as default
16
16
  };
package/dist/Dom/css.cjs CHANGED
@@ -1 +1,96 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=/margin|padding|width|height|max|min|offset/,i={left:!0,top:!0},r={cssFloat:1,styleFloat:1,float:1};function u(e){return e.nodeType===1?e.ownerDocument.defaultView.getComputedStyle(e,null):{}}function f(e,t,o){if(t=t.toLowerCase(),o==="auto"){if(t==="height")return e.offsetHeight;if(t==="width")return e.offsetWidth}return t in i||(i[t]=l.test(t)),i[t]?Number.parseFloat(o)||0:o}function d(e,t){const o=arguments.length,n=u(e);return t=r[t]?"cssFloat"in e.style?"cssFloat":"styleFloat":t,o===1?n:f(e,t,n[t]||e.style[t])}function s(e,t,o){const n=arguments.length;if(t=r[t]?"cssFloat"in e.style?"cssFloat":"styleFloat":t,n===3)return typeof o=="number"&&l.test(t)&&(o=`${o}px`),e.style[t]=o,o;for(const c in t)c in t&&s(e,c,t[c]);return u(e)}function g(e){return e===document.body?document.documentElement.clientWidth:e.offsetWidth}function m(e){return e===document.body?window.innerHeight||document.documentElement.clientHeight:e.offsetHeight}function h(){const e=Math.max(document.documentElement.scrollWidth,document.body.scrollWidth),t=Math.max(document.documentElement.scrollHeight,document.body.scrollHeight);return{width:e,height:t}}function a(){const e=document.documentElement.clientWidth,t=window.innerHeight||document.documentElement.clientHeight;return{width:e,height:t}}function y(){return{scrollLeft:Math.max(document.documentElement.scrollLeft,document.body.scrollLeft),scrollTop:Math.max(document.documentElement.scrollTop,document.body.scrollTop)}}function w(e){const t=e.getBoundingClientRect(),o=document.documentElement;return{left:t.left+(window.pageXOffset||o.scrollLeft)-(o.clientLeft||document.body.clientLeft||0),top:t.top+(window.pageYOffset||o.scrollTop)-(o.clientTop||document.body.clientTop||0)}}exports.get=d;exports.getClientSize=a;exports.getDocSize=h;exports.getOffset=w;exports.getOuterHeight=m;exports.getOuterWidth=g;exports.getScroll=y;exports.set=s;
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const PIXEL_PATTERN = /margin|padding|width|height|max|min|offset/;
4
+ const removePixel = {
5
+ left: true,
6
+ top: true
7
+ };
8
+ const floatMap = {
9
+ cssFloat: 1,
10
+ styleFloat: 1,
11
+ float: 1
12
+ };
13
+ function getComputedStyle(node) {
14
+ return node.nodeType === 1 ? node.ownerDocument.defaultView.getComputedStyle(node, null) : {};
15
+ }
16
+ function getStyleValue(node, type, value) {
17
+ type = type.toLowerCase();
18
+ if (value === "auto") {
19
+ if (type === "height")
20
+ return node.offsetHeight;
21
+ if (type === "width")
22
+ return node.offsetWidth;
23
+ }
24
+ if (!(type in removePixel))
25
+ removePixel[type] = PIXEL_PATTERN.test(type);
26
+ return removePixel[type] ? Number.parseFloat(value) || 0 : value;
27
+ }
28
+ function get(node, name) {
29
+ const length = arguments.length;
30
+ const style = getComputedStyle(node);
31
+ name = floatMap[name] ? "cssFloat" in node.style ? "cssFloat" : "styleFloat" : name;
32
+ return length === 1 ? style : getStyleValue(node, name, style[name] || node.style[name]);
33
+ }
34
+ function set(node, name, value) {
35
+ const length = arguments.length;
36
+ name = floatMap[name] ? "cssFloat" in node.style ? "cssFloat" : "styleFloat" : name;
37
+ if (length === 3) {
38
+ if (typeof value === "number" && PIXEL_PATTERN.test(name))
39
+ value = `${value}px`;
40
+ node.style[name] = value;
41
+ return value;
42
+ }
43
+ for (const x in name) {
44
+ if (x in name)
45
+ set(node, x, name[x]);
46
+ }
47
+ return getComputedStyle(node);
48
+ }
49
+ function getOuterWidth(el) {
50
+ if (el === document.body)
51
+ return document.documentElement.clientWidth;
52
+ return el.offsetWidth;
53
+ }
54
+ function getOuterHeight(el) {
55
+ if (el === document.body)
56
+ return window.innerHeight || document.documentElement.clientHeight;
57
+ return el.offsetHeight;
58
+ }
59
+ function getDocSize() {
60
+ const width = Math.max(document.documentElement.scrollWidth, document.body.scrollWidth);
61
+ const height = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
62
+ return {
63
+ width,
64
+ height
65
+ };
66
+ }
67
+ function getClientSize() {
68
+ const width = document.documentElement.clientWidth;
69
+ const height = window.innerHeight || document.documentElement.clientHeight;
70
+ return {
71
+ width,
72
+ height
73
+ };
74
+ }
75
+ function getScroll() {
76
+ return {
77
+ scrollLeft: Math.max(document.documentElement.scrollLeft, document.body.scrollLeft),
78
+ scrollTop: Math.max(document.documentElement.scrollTop, document.body.scrollTop)
79
+ };
80
+ }
81
+ function getOffset(node) {
82
+ const box = node.getBoundingClientRect();
83
+ const docElem = document.documentElement;
84
+ return {
85
+ left: box.left + (window.pageXOffset || docElem.scrollLeft) - (docElem.clientLeft || document.body.clientLeft || 0),
86
+ top: box.top + (window.pageYOffset || docElem.scrollTop) - (docElem.clientTop || document.body.clientTop || 0)
87
+ };
88
+ }
89
+ exports.get = get;
90
+ exports.getClientSize = getClientSize;
91
+ exports.getDocSize = getDocSize;
92
+ exports.getOffset = getOffset;
93
+ exports.getOuterHeight = getOuterHeight;
94
+ exports.getOuterWidth = getOuterWidth;
95
+ exports.getScroll = getScroll;
96
+ exports.set = set;
package/dist/Dom/css.js CHANGED
@@ -1,75 +1,96 @@
1
- const l = /margin|padding|width|height|max|min|offset/, i = {
2
- left: !0,
3
- top: !0
4
- }, u = {
1
+ const PIXEL_PATTERN = /margin|padding|width|height|max|min|offset/;
2
+ const removePixel = {
3
+ left: true,
4
+ top: true
5
+ };
6
+ const floatMap = {
5
7
  cssFloat: 1,
6
8
  styleFloat: 1,
7
9
  float: 1
8
10
  };
9
- function r(e) {
10
- return e.nodeType === 1 ? e.ownerDocument.defaultView.getComputedStyle(e, null) : {};
11
+ function getComputedStyle(node) {
12
+ return node.nodeType === 1 ? node.ownerDocument.defaultView.getComputedStyle(node, null) : {};
11
13
  }
12
- function s(e, t, o) {
13
- if (t = t.toLowerCase(), o === "auto") {
14
- if (t === "height")
15
- return e.offsetHeight;
16
- if (t === "width")
17
- return e.offsetWidth;
14
+ function getStyleValue(node, type, value) {
15
+ type = type.toLowerCase();
16
+ if (value === "auto") {
17
+ if (type === "height")
18
+ return node.offsetHeight;
19
+ if (type === "width")
20
+ return node.offsetWidth;
18
21
  }
19
- return t in i || (i[t] = l.test(t)), i[t] ? Number.parseFloat(o) || 0 : o;
22
+ if (!(type in removePixel))
23
+ removePixel[type] = PIXEL_PATTERN.test(type);
24
+ return removePixel[type] ? Number.parseFloat(value) || 0 : value;
20
25
  }
21
- function d(e, t) {
22
- const o = arguments.length, n = r(e);
23
- return t = u[t] ? "cssFloat" in e.style ? "cssFloat" : "styleFloat" : t, o === 1 ? n : s(e, t, n[t] || e.style[t]);
26
+ function get(node, name) {
27
+ const length = arguments.length;
28
+ const style = getComputedStyle(node);
29
+ name = floatMap[name] ? "cssFloat" in node.style ? "cssFloat" : "styleFloat" : name;
30
+ return length === 1 ? style : getStyleValue(node, name, style[name] || node.style[name]);
24
31
  }
25
- function f(e, t, o) {
26
- const n = arguments.length;
27
- if (t = u[t] ? "cssFloat" in e.style ? "cssFloat" : "styleFloat" : t, n === 3)
28
- return typeof o == "number" && l.test(t) && (o = `${o}px`), e.style[t] = o, o;
29
- for (const c in t)
30
- c in t && f(e, c, t[c]);
31
- return r(e);
32
+ function set(node, name, value) {
33
+ const length = arguments.length;
34
+ name = floatMap[name] ? "cssFloat" in node.style ? "cssFloat" : "styleFloat" : name;
35
+ if (length === 3) {
36
+ if (typeof value === "number" && PIXEL_PATTERN.test(name))
37
+ value = `${value}px`;
38
+ node.style[name] = value;
39
+ return value;
40
+ }
41
+ for (const x in name) {
42
+ if (x in name)
43
+ set(node, x, name[x]);
44
+ }
45
+ return getComputedStyle(node);
32
46
  }
33
- function m(e) {
34
- return e === document.body ? document.documentElement.clientWidth : e.offsetWidth;
47
+ function getOuterWidth(el) {
48
+ if (el === document.body)
49
+ return document.documentElement.clientWidth;
50
+ return el.offsetWidth;
35
51
  }
36
- function h(e) {
37
- return e === document.body ? window.innerHeight || document.documentElement.clientHeight : e.offsetHeight;
52
+ function getOuterHeight(el) {
53
+ if (el === document.body)
54
+ return window.innerHeight || document.documentElement.clientHeight;
55
+ return el.offsetHeight;
38
56
  }
39
- function g() {
40
- const e = Math.max(document.documentElement.scrollWidth, document.body.scrollWidth), t = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
57
+ function getDocSize() {
58
+ const width = Math.max(document.documentElement.scrollWidth, document.body.scrollWidth);
59
+ const height = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
41
60
  return {
42
- width: e,
43
- height: t
61
+ width,
62
+ height
44
63
  };
45
64
  }
46
- function w() {
47
- const e = document.documentElement.clientWidth, t = window.innerHeight || document.documentElement.clientHeight;
65
+ function getClientSize() {
66
+ const width = document.documentElement.clientWidth;
67
+ const height = window.innerHeight || document.documentElement.clientHeight;
48
68
  return {
49
- width: e,
50
- height: t
69
+ width,
70
+ height
51
71
  };
52
72
  }
53
- function a() {
73
+ function getScroll() {
54
74
  return {
55
75
  scrollLeft: Math.max(document.documentElement.scrollLeft, document.body.scrollLeft),
56
76
  scrollTop: Math.max(document.documentElement.scrollTop, document.body.scrollTop)
57
77
  };
58
78
  }
59
- function y(e) {
60
- const t = e.getBoundingClientRect(), o = document.documentElement;
79
+ function getOffset(node) {
80
+ const box = node.getBoundingClientRect();
81
+ const docElem = document.documentElement;
61
82
  return {
62
- left: t.left + (window.pageXOffset || o.scrollLeft) - (o.clientLeft || document.body.clientLeft || 0),
63
- top: t.top + (window.pageYOffset || o.scrollTop) - (o.clientTop || document.body.clientTop || 0)
83
+ left: box.left + (window.pageXOffset || docElem.scrollLeft) - (docElem.clientLeft || document.body.clientLeft || 0),
84
+ top: box.top + (window.pageYOffset || docElem.scrollTop) - (docElem.clientTop || document.body.clientTop || 0)
64
85
  };
65
86
  }
66
87
  export {
67
- d as get,
68
- w as getClientSize,
69
- g as getDocSize,
70
- y as getOffset,
71
- h as getOuterHeight,
72
- m as getOuterWidth,
73
- a as getScroll,
74
- f as set
88
+ get,
89
+ getClientSize,
90
+ getDocSize,
91
+ getOffset,
92
+ getOuterHeight,
93
+ getOuterWidth,
94
+ getScroll,
95
+ set
75
96
  };
@@ -1 +1,110 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A=require("./canUseDom.cjs"),N=require("./contains.cjs"),h="data-vc-order",C="data-vc-priority",v="vc-util-key",a=new Map;function p({mark:e}={}){return e?e.startsWith("data-")?e:`data-${e}`:v}function s(e){return e.attachTo?e.attachTo:document.querySelector("head")||document.body}function P(e){return e==="queue"?"prependQueue":e?"prepend":"append"}function g(e){return Array.from((a.get(e)||e).children).filter(n=>n.tagName==="STYLE")}function f(e,n={}){if(!A.default())return null;const{csp:t,prepend:c,priority:r=0}=n,o=P(c),l=o==="prependQueue",i=document.createElement("style");i.setAttribute(h,o),l&&r&&i.setAttribute(C,`${r}`),t?.nonce&&(i.nonce=t?.nonce),i.innerHTML=e;const u=s(n),{firstChild:m}=u;if(c){if(l){const d=g(u).filter(S=>{if(!["prepend","prependQueue"].includes(S.getAttribute(h)))return!1;const b=Number(S.getAttribute(C)||0);return r>=b});if(d.length)return u.insertBefore(i,d[d.length-1].nextSibling),i}u.insertBefore(i,m)}else u.appendChild(i);return i}function y(e,n={}){const t=s(n);return g(t).find(c=>c.getAttribute(p(n))===e)}function T(e,n={}){const t=y(e,n);t&&s(n).removeChild(t)}function E(e,n){const t=a.get(e);if(!t||!N.default(document,t)){const c=f("",n),{parentNode:r}=c;a.set(e,r),e.removeChild(c)}}function M(){a.clear()}function R(e,n,t={}){const c=s(t);E(c,t);const r=y(n,t);if(r)return t.csp?.nonce&&r.nonce!==t.csp?.nonce&&(r.nonce=t.csp?.nonce),r.innerHTML!==e&&(r.innerHTML=e),r;const o=f(e,t);return o.setAttribute(p(t),n),o}exports.clearContainerCache=M;exports.injectCSS=f;exports.removeCSS=T;exports.updateCSS=R;
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();
9
+ function getMark({ mark } = {}) {
10
+ if (mark)
11
+ return mark.startsWith("data-") ? mark : `data-${mark}`;
12
+ return MARK_KEY;
13
+ }
14
+ function getContainer(option) {
15
+ if (option.attachTo)
16
+ return option.attachTo;
17
+ const head = document.querySelector("head");
18
+ return head || document.body;
19
+ }
20
+ function getOrder(prepend) {
21
+ if (prepend === "queue")
22
+ return "prependQueue";
23
+ return prepend ? "prepend" : "append";
24
+ }
25
+ function findStyles(container) {
26
+ return Array.from(
27
+ (containerCache.get(container) || container).children
28
+ ).filter((node) => node.tagName === "STYLE");
29
+ }
30
+ 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;
66
+ }
67
+ function findExistNode(key, option = {}) {
68
+ const container = getContainer(option);
69
+ return findStyles(container).find(
70
+ (node) => node.getAttribute(getMark(option)) === key
71
+ );
72
+ }
73
+ function removeCSS(key, option = {}) {
74
+ const existNode = findExistNode(key, option);
75
+ if (existNode) {
76
+ const container = getContainer(option);
77
+ container.removeChild(existNode);
78
+ }
79
+ }
80
+ 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
+ }
88
+ }
89
+ function clearContainerCache() {
90
+ containerCache.clear();
91
+ }
92
+ 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;
106
+ }
107
+ exports.clearContainerCache = clearContainerCache;
108
+ exports.injectCSS = injectCSS;
109
+ exports.removeCSS = removeCSS;
110
+ exports.updateCSS = updateCSS;