@v-c/util 0.0.12 → 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 +5 -1
- package/dist/Children/isFragment.js +4 -6
- package/dist/Children/toArray.cjs +13 -1
- package/dist/Children/toArray.js +12 -10
- package/dist/Dom/addEventListener.cjs +8 -1
- package/dist/Dom/addEventListener.js +7 -10
- package/dist/Dom/canUseDom.cjs +5 -1
- package/dist/Dom/canUseDom.js +3 -5
- package/dist/Dom/class.cjs +15 -1
- package/dist/Dom/class.js +10 -16
- package/dist/Dom/contains.cjs +12 -1
- package/dist/Dom/contains.js +10 -15
- package/dist/Dom/css.cjs +81 -1
- package/dist/Dom/css.js +63 -64
- package/dist/Dom/dynamicCSS.cjs +83 -1
- package/dist/Dom/dynamicCSS.js +70 -67
- package/dist/Dom/findDOMNode.cjs +13 -1
- package/dist/Dom/findDOMNode.js +9 -10
- package/dist/Dom/focus.cjs +53 -1
- package/dist/Dom/focus.js +43 -34
- package/dist/Dom/isVisible.cjs +17 -1
- package/dist/Dom/isVisible.js +15 -21
- package/dist/Dom/scrollLocker.cjs +67 -1
- package/dist/Dom/scrollLocker.js +65 -63
- package/dist/Dom/shadow.cjs +11 -1
- package/dist/Dom/shadow.js +7 -10
- package/dist/Dom/styleChecker.cjs +21 -1
- package/dist/Dom/styleChecker.js +18 -17
- package/dist/Dom/support.cjs +20 -1
- package/dist/Dom/support.js +17 -22
- package/dist/EventInterface.cjs +0 -1
- package/dist/EventInterface.js +0 -1
- package/dist/KeyCode.cjs +166 -1
- package/dist/KeyCode.js +164 -515
- package/dist/Portal.cjs +42 -1
- package/dist/Portal.js +38 -31
- package/dist/PortalWrapper.cjs +135 -1
- package/dist/PortalWrapper.js +130 -113
- package/dist/classnames.cjs +37 -1
- package/dist/classnames.js +33 -30
- package/dist/composeProps.cjs +17 -1
- package/dist/composeProps.js +15 -12
- package/dist/createRef.cjs +22 -1
- package/dist/createRef.js +16 -18
- package/dist/debug/diff.cjs +44 -1
- package/dist/debug/diff.js +41 -39
- package/dist/deprecated.cjs +5 -1
- package/dist/deprecated.js +3 -7
- package/dist/getScrollBarSize.cjs +47 -1
- package/dist/getScrollBarSize.js +42 -34
- package/dist/guid.cjs +6 -1
- package/dist/guid.js +4 -6
- package/dist/hooks/useEvent.cjs +5 -1
- package/dist/hooks/useEvent.js +3 -5
- package/dist/hooks/useId.cjs +13 -1
- package/dist/hooks/useId.js +10 -10
- package/dist/hooks/useLayoutEffect.cjs +35 -1
- package/dist/hooks/useLayoutEffect.js +32 -26
- package/dist/hooks/useMemo.cjs +12 -1
- package/dist/hooks/useMemo.js +10 -9
- package/dist/hooks/useMergedState.cjs +25 -1
- package/dist/hooks/useMergedState.js +23 -20
- package/dist/hooks/useMobile.cjs +16 -1
- package/dist/hooks/useMobile.js +13 -13
- package/dist/hooks/useState.cjs +10 -1
- package/dist/hooks/useState.js +8 -10
- package/dist/index.cjs +9 -1
- package/dist/index.js +5 -11
- package/dist/isEqual.cjs +28 -1
- package/dist/isEqual.js +26 -31
- package/dist/isMobile.cjs +7 -1
- package/dist/isMobile.js +5 -12
- package/dist/isValid.cjs +6 -1
- package/dist/isValid.js +4 -5
- package/dist/omit.cjs +9 -1
- package/dist/omit.js +7 -8
- package/dist/pickAttrs.cjs +25 -3
- package/dist/pickAttrs.js +22 -24
- package/dist/props-util/index.cjs +52 -1
- package/dist/props-util/index.js +42 -34
- package/dist/raf.cjs +45 -1
- package/dist/raf.js +39 -33
- package/dist/setStyle.cjs +16 -1
- package/dist/setStyle.js +14 -12
- package/dist/switchScrollingEffect.cjs +32 -1
- package/dist/switchScrollingEffect.js +29 -29
- package/dist/test/domHook.cjs +38 -1
- package/dist/test/domHook.js +35 -35
- package/dist/type.cjs +70 -1
- package/dist/type.d.ts +1 -1
- package/dist/type.js +59 -49
- package/dist/utils/checkSlotProp.cjs +9 -1
- package/dist/utils/checkSlotProp.js +8 -5
- package/dist/utils/get.cjs +10 -1
- package/dist/utils/get.js +8 -11
- package/dist/utils/omit.cjs +8 -1
- package/dist/utils/omit.js +7 -8
- package/dist/utils/set.cjs +50 -1
- package/dist/utils/set.js +42 -37
- package/dist/utils/transition.cjs +92 -1
- package/dist/utils/transition.js +83 -86
- package/dist/utils/watchState.cjs +18 -1
- package/dist/utils/watchState.js +15 -13
- package/dist/vnode.cjs +48 -1
- package/dist/vnode.js +38 -34
- package/dist/vueuse/unref-element.cjs +6 -1
- package/dist/vueuse/unref-element.js +5 -7
- package/dist/warning.cjs +45 -1
- package/dist/warning.js +30 -41
- package/package.json +1 -1
|
@@ -1 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
let vue = require("vue");
|
|
2
|
+
function isFragment(node) {
|
|
3
|
+
return (0, vue.isVNode)(node) && node.type === vue.Fragment;
|
|
4
|
+
}
|
|
5
|
+
exports.isFragment = isFragment;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
function
|
|
3
|
-
|
|
1
|
+
import { Fragment, isVNode } from "vue";
|
|
2
|
+
function isFragment(node) {
|
|
3
|
+
return isVNode(node) && node.type === Fragment;
|
|
4
4
|
}
|
|
5
|
-
export {
|
|
6
|
-
m as isFragment
|
|
7
|
-
};
|
|
5
|
+
export { isFragment };
|
|
@@ -1 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
const require_isFragment = require("./isFragment.cjs");
|
|
2
|
+
function toArray(children, option = {}) {
|
|
3
|
+
let ret = [];
|
|
4
|
+
if (!Array.isArray(children)) children = [children];
|
|
5
|
+
for (const child of children) {
|
|
6
|
+
if ((child === void 0 || child === null) && !option.keepEmpty) continue;
|
|
7
|
+
if (Array.isArray(child)) ret = ret.concat(toArray(child, option));
|
|
8
|
+
else if (require_isFragment.isFragment(child) && child.children) ret = ret.concat(toArray(child.children, option));
|
|
9
|
+
else ret.push(child);
|
|
10
|
+
}
|
|
11
|
+
return ret;
|
|
12
|
+
}
|
|
13
|
+
exports.toArray = toArray;
|
package/dist/Children/toArray.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { isFragment
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { isFragment } from "./isFragment.js";
|
|
2
|
+
function toArray(children, option = {}) {
|
|
3
|
+
let ret = [];
|
|
4
|
+
if (!Array.isArray(children)) children = [children];
|
|
5
|
+
for (const child of children) {
|
|
6
|
+
if ((child === void 0 || child === null) && !option.keepEmpty) continue;
|
|
7
|
+
if (Array.isArray(child)) ret = ret.concat(toArray(child, option));
|
|
8
|
+
else if (isFragment(child) && child.children) ret = ret.concat(toArray(child.children, option));
|
|
9
|
+
else ret.push(child);
|
|
10
|
+
}
|
|
11
|
+
return ret;
|
|
8
12
|
}
|
|
9
|
-
export {
|
|
10
|
-
a as toArray
|
|
11
|
-
};
|
|
13
|
+
export { toArray };
|
|
@@ -1 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
function addEventListener(...args) {
|
|
2
|
+
const [target, eventType, cb, option] = args;
|
|
3
|
+
if (target?.addEventListener) target.addEventListener(eventType, cb, option);
|
|
4
|
+
return { remove() {
|
|
5
|
+
target?.removeEventListener?.(eventType, cb, option);
|
|
6
|
+
} };
|
|
7
|
+
}
|
|
8
|
+
exports.addEventListener = addEventListener;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
1
|
+
function addEventListener(...args) {
|
|
2
|
+
const [target, eventType, cb, option] = args;
|
|
3
|
+
if (target?.addEventListener) target.addEventListener(eventType, cb, option);
|
|
4
|
+
return { remove() {
|
|
5
|
+
target?.removeEventListener?.(eventType, cb, option);
|
|
6
|
+
} };
|
|
8
7
|
}
|
|
9
|
-
export {
|
|
10
|
-
o as addEventListener
|
|
11
|
-
};
|
|
8
|
+
export { addEventListener };
|
package/dist/Dom/canUseDom.cjs
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
function canUseDom() {
|
|
3
|
+
return !!(typeof window !== "undefined" && window.document && window.document.createElement);
|
|
4
|
+
}
|
|
5
|
+
exports.default = canUseDom;
|
package/dist/Dom/canUseDom.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
1
|
+
function canUseDom() {
|
|
2
|
+
return !!(typeof window !== "undefined" && window.document && window.document.createElement);
|
|
3
3
|
}
|
|
4
|
-
export {
|
|
5
|
-
e as default
|
|
6
|
-
};
|
|
4
|
+
export { canUseDom as default };
|
package/dist/Dom/class.cjs
CHANGED
|
@@ -1 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
function hasClass(node, className) {
|
|
2
|
+
if (node.classList) return node.classList.contains(className);
|
|
3
|
+
return ` ${node.className} `.includes(` ${className} `);
|
|
4
|
+
}
|
|
5
|
+
function addClass(node, className) {
|
|
6
|
+
if (node.classList) node.classList.add(className);
|
|
7
|
+
else if (!hasClass(node, className)) node.className = `${node.className} ${className}`;
|
|
8
|
+
}
|
|
9
|
+
function removeClass(node, className) {
|
|
10
|
+
if (node.classList) node.classList.remove(className);
|
|
11
|
+
else if (hasClass(node, className)) node.className = ` ${node.className} `.replace(` ${className} `, " ");
|
|
12
|
+
}
|
|
13
|
+
exports.addClass = addClass;
|
|
14
|
+
exports.hasClass = hasClass;
|
|
15
|
+
exports.removeClass = removeClass;
|
package/dist/Dom/class.js
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
1
|
+
function hasClass(node, className) {
|
|
2
|
+
if (node.classList) return node.classList.contains(className);
|
|
3
|
+
return ` ${node.className} `.includes(` ${className} `);
|
|
3
4
|
}
|
|
4
|
-
function
|
|
5
|
-
|
|
5
|
+
function addClass(node, className) {
|
|
6
|
+
if (node.classList) node.classList.add(className);
|
|
7
|
+
else if (!hasClass(node, className)) node.className = `${node.className} ${className}`;
|
|
6
8
|
}
|
|
7
|
-
function
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
else if (l(s, i)) {
|
|
11
|
-
const a = s.className;
|
|
12
|
-
s.className = ` ${a} `.replace(` ${i} `, " ");
|
|
13
|
-
}
|
|
9
|
+
function removeClass(node, className) {
|
|
10
|
+
if (node.classList) node.classList.remove(className);
|
|
11
|
+
else if (hasClass(node, className)) node.className = ` ${node.className} `.replace(` ${className} `, " ");
|
|
14
12
|
}
|
|
15
|
-
export {
|
|
16
|
-
t as addClass,
|
|
17
|
-
l as hasClass,
|
|
18
|
-
c as removeClass
|
|
19
|
-
};
|
|
13
|
+
export { addClass, hasClass, removeClass };
|
package/dist/Dom/contains.cjs
CHANGED
|
@@ -1 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
function contains(root, n) {
|
|
3
|
+
if (!root) return false;
|
|
4
|
+
if (root.contains) return root.contains(n);
|
|
5
|
+
let node = n;
|
|
6
|
+
while (node) {
|
|
7
|
+
if (node === root) return true;
|
|
8
|
+
node = node.parentNode;
|
|
9
|
+
}
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
exports.default = contains;
|
package/dist/Dom/contains.js
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
n = n.parentNode;
|
|
11
|
-
}
|
|
12
|
-
return !1;
|
|
1
|
+
function contains(root, n) {
|
|
2
|
+
if (!root) return false;
|
|
3
|
+
if (root.contains) return root.contains(n);
|
|
4
|
+
let node = n;
|
|
5
|
+
while (node) {
|
|
6
|
+
if (node === root) return true;
|
|
7
|
+
node = node.parentNode;
|
|
8
|
+
}
|
|
9
|
+
return false;
|
|
13
10
|
}
|
|
14
|
-
export {
|
|
15
|
-
a as default
|
|
16
|
-
};
|
|
11
|
+
export { contains as default };
|
package/dist/Dom/css.cjs
CHANGED
|
@@ -1 +1,81 @@
|
|
|
1
|
-
|
|
1
|
+
var PIXEL_PATTERN = /margin|padding|width|height|max|min|offset/;
|
|
2
|
+
var removePixel = {
|
|
3
|
+
left: true,
|
|
4
|
+
top: true
|
|
5
|
+
};
|
|
6
|
+
var floatMap = {
|
|
7
|
+
cssFloat: 1,
|
|
8
|
+
styleFloat: 1,
|
|
9
|
+
float: 1
|
|
10
|
+
};
|
|
11
|
+
function getComputedStyle(node) {
|
|
12
|
+
return node.nodeType === 1 ? node.ownerDocument.defaultView.getComputedStyle(node, null) : {};
|
|
13
|
+
}
|
|
14
|
+
function getStyleValue(node, type, value) {
|
|
15
|
+
type = type.toLowerCase();
|
|
16
|
+
if (value === "auto") {
|
|
17
|
+
if (type === "height") return node.offsetHeight;
|
|
18
|
+
if (type === "width") return node.offsetWidth;
|
|
19
|
+
}
|
|
20
|
+
if (!(type in removePixel)) removePixel[type] = PIXEL_PATTERN.test(type);
|
|
21
|
+
return removePixel[type] ? Number.parseFloat(value) || 0 : value;
|
|
22
|
+
}
|
|
23
|
+
function get(node, name) {
|
|
24
|
+
const length = arguments.length;
|
|
25
|
+
const style = getComputedStyle(node);
|
|
26
|
+
name = floatMap[name] ? "cssFloat" in node.style ? "cssFloat" : "styleFloat" : name;
|
|
27
|
+
return length === 1 ? style : getStyleValue(node, name, style[name] || node.style[name]);
|
|
28
|
+
}
|
|
29
|
+
function set(node, name, value) {
|
|
30
|
+
const length = arguments.length;
|
|
31
|
+
name = floatMap[name] ? "cssFloat" in node.style ? "cssFloat" : "styleFloat" : name;
|
|
32
|
+
if (length === 3) {
|
|
33
|
+
if (typeof value === "number" && PIXEL_PATTERN.test(name)) value = `${value}px`;
|
|
34
|
+
node.style[name] = value;
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
for (const x in name) if (x in name) set(node, x, name[x]);
|
|
38
|
+
return getComputedStyle(node);
|
|
39
|
+
}
|
|
40
|
+
function getOuterWidth(el) {
|
|
41
|
+
if (el === document.body) return document.documentElement.clientWidth;
|
|
42
|
+
return el.offsetWidth;
|
|
43
|
+
}
|
|
44
|
+
function getOuterHeight(el) {
|
|
45
|
+
if (el === document.body) return window.innerHeight || document.documentElement.clientHeight;
|
|
46
|
+
return el.offsetHeight;
|
|
47
|
+
}
|
|
48
|
+
function getDocSize() {
|
|
49
|
+
return {
|
|
50
|
+
width: Math.max(document.documentElement.scrollWidth, document.body.scrollWidth),
|
|
51
|
+
height: Math.max(document.documentElement.scrollHeight, document.body.scrollHeight)
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function getClientSize() {
|
|
55
|
+
return {
|
|
56
|
+
width: document.documentElement.clientWidth,
|
|
57
|
+
height: window.innerHeight || document.documentElement.clientHeight
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function getScroll() {
|
|
61
|
+
return {
|
|
62
|
+
scrollLeft: Math.max(document.documentElement.scrollLeft, document.body.scrollLeft),
|
|
63
|
+
scrollTop: Math.max(document.documentElement.scrollTop, document.body.scrollTop)
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function getOffset(node) {
|
|
67
|
+
const box = node.getBoundingClientRect();
|
|
68
|
+
const docElem = document.documentElement;
|
|
69
|
+
return {
|
|
70
|
+
left: box.left + (window.pageXOffset || docElem.scrollLeft) - (docElem.clientLeft || document.body.clientLeft || 0),
|
|
71
|
+
top: box.top + (window.pageYOffset || docElem.scrollTop) - (docElem.clientTop || document.body.clientTop || 0)
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
exports.get = get;
|
|
75
|
+
exports.getClientSize = getClientSize;
|
|
76
|
+
exports.getDocSize = getDocSize;
|
|
77
|
+
exports.getOffset = getOffset;
|
|
78
|
+
exports.getOuterHeight = getOuterHeight;
|
|
79
|
+
exports.getOuterWidth = getOuterWidth;
|
|
80
|
+
exports.getScroll = getScroll;
|
|
81
|
+
exports.set = set;
|
package/dist/Dom/css.js
CHANGED
|
@@ -1,75 +1,74 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
cssFloat: 1,
|
|
6
|
-
styleFloat: 1,
|
|
7
|
-
float: 1
|
|
1
|
+
var PIXEL_PATTERN = /margin|padding|width|height|max|min|offset/;
|
|
2
|
+
var removePixel = {
|
|
3
|
+
left: true,
|
|
4
|
+
top: true
|
|
8
5
|
};
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
var floatMap = {
|
|
7
|
+
cssFloat: 1,
|
|
8
|
+
styleFloat: 1,
|
|
9
|
+
float: 1
|
|
10
|
+
};
|
|
11
|
+
function getComputedStyle(node) {
|
|
12
|
+
return node.nodeType === 1 ? node.ownerDocument.defaultView.getComputedStyle(node, null) : {};
|
|
11
13
|
}
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
function getStyleValue(node, type, value) {
|
|
15
|
+
type = type.toLowerCase();
|
|
16
|
+
if (value === "auto") {
|
|
17
|
+
if (type === "height") return node.offsetHeight;
|
|
18
|
+
if (type === "width") return node.offsetWidth;
|
|
19
|
+
}
|
|
20
|
+
if (!(type in removePixel)) removePixel[type] = PIXEL_PATTERN.test(type);
|
|
21
|
+
return removePixel[type] ? Number.parseFloat(value) || 0 : value;
|
|
20
22
|
}
|
|
21
|
-
function
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
function get(node, name) {
|
|
24
|
+
const length = arguments.length;
|
|
25
|
+
const style = getComputedStyle(node);
|
|
26
|
+
name = floatMap[name] ? "cssFloat" in node.style ? "cssFloat" : "styleFloat" : name;
|
|
27
|
+
return length === 1 ? style : getStyleValue(node, name, style[name] || node.style[name]);
|
|
24
28
|
}
|
|
25
|
-
function
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
function set(node, name, value) {
|
|
30
|
+
const length = arguments.length;
|
|
31
|
+
name = floatMap[name] ? "cssFloat" in node.style ? "cssFloat" : "styleFloat" : name;
|
|
32
|
+
if (length === 3) {
|
|
33
|
+
if (typeof value === "number" && PIXEL_PATTERN.test(name)) value = `${value}px`;
|
|
34
|
+
node.style[name] = value;
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
for (const x in name) if (x in name) set(node, x, name[x]);
|
|
38
|
+
return getComputedStyle(node);
|
|
32
39
|
}
|
|
33
|
-
function
|
|
34
|
-
|
|
40
|
+
function getOuterWidth(el) {
|
|
41
|
+
if (el === document.body) return document.documentElement.clientWidth;
|
|
42
|
+
return el.offsetWidth;
|
|
35
43
|
}
|
|
36
|
-
function
|
|
37
|
-
|
|
44
|
+
function getOuterHeight(el) {
|
|
45
|
+
if (el === document.body) return window.innerHeight || document.documentElement.clientHeight;
|
|
46
|
+
return el.offsetHeight;
|
|
38
47
|
}
|
|
39
|
-
function
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
};
|
|
48
|
+
function getDocSize() {
|
|
49
|
+
return {
|
|
50
|
+
width: Math.max(document.documentElement.scrollWidth, document.body.scrollWidth),
|
|
51
|
+
height: Math.max(document.documentElement.scrollHeight, document.body.scrollHeight)
|
|
52
|
+
};
|
|
45
53
|
}
|
|
46
|
-
function
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
};
|
|
54
|
+
function getClientSize() {
|
|
55
|
+
return {
|
|
56
|
+
width: document.documentElement.clientWidth,
|
|
57
|
+
height: window.innerHeight || document.documentElement.clientHeight
|
|
58
|
+
};
|
|
52
59
|
}
|
|
53
|
-
function
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
60
|
+
function getScroll() {
|
|
61
|
+
return {
|
|
62
|
+
scrollLeft: Math.max(document.documentElement.scrollLeft, document.body.scrollLeft),
|
|
63
|
+
scrollTop: Math.max(document.documentElement.scrollTop, document.body.scrollTop)
|
|
64
|
+
};
|
|
58
65
|
}
|
|
59
|
-
function
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
66
|
+
function getOffset(node) {
|
|
67
|
+
const box = node.getBoundingClientRect();
|
|
68
|
+
const docElem = document.documentElement;
|
|
69
|
+
return {
|
|
70
|
+
left: box.left + (window.pageXOffset || docElem.scrollLeft) - (docElem.clientLeft || document.body.clientLeft || 0),
|
|
71
|
+
top: box.top + (window.pageYOffset || docElem.scrollTop) - (docElem.clientTop || document.body.clientTop || 0)
|
|
72
|
+
};
|
|
65
73
|
}
|
|
66
|
-
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
|
|
75
|
-
};
|
|
74
|
+
export { get, getClientSize, getDocSize, getOffset, getOuterHeight, getOuterWidth, getScroll, set };
|
package/dist/Dom/dynamicCSS.cjs
CHANGED
|
@@ -1 +1,83 @@
|
|
|
1
|
-
|
|
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();
|
|
7
|
+
function getMark({ mark } = {}) {
|
|
8
|
+
if (mark) return mark.startsWith("data-") ? mark : `data-${mark}`;
|
|
9
|
+
return MARK_KEY;
|
|
10
|
+
}
|
|
11
|
+
function getContainer(option) {
|
|
12
|
+
if (option.attachTo) return option.attachTo;
|
|
13
|
+
return document.querySelector("head") || document.body;
|
|
14
|
+
}
|
|
15
|
+
function getOrder(prepend) {
|
|
16
|
+
if (prepend === "queue") return "prependQueue";
|
|
17
|
+
return prepend ? "prepend" : "append";
|
|
18
|
+
}
|
|
19
|
+
function findStyles(container) {
|
|
20
|
+
return Array.from((containerCache.get(container) || container).children).filter((node) => node.tagName === "STYLE");
|
|
21
|
+
}
|
|
22
|
+
function injectCSS(css, option = {}) {
|
|
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;
|
|
48
|
+
}
|
|
49
|
+
function findExistNode(key, option = {}) {
|
|
50
|
+
return findStyles(getContainer(option)).find((node) => node.getAttribute(getMark(option)) === key);
|
|
51
|
+
}
|
|
52
|
+
function removeCSS(key, option = {}) {
|
|
53
|
+
const existNode = findExistNode(key, option);
|
|
54
|
+
if (existNode) getContainer(option).removeChild(existNode);
|
|
55
|
+
}
|
|
56
|
+
function syncRealContainer(container, option) {
|
|
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
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function clearContainerCache() {
|
|
66
|
+
containerCache.clear();
|
|
67
|
+
}
|
|
68
|
+
function updateCSS(css, key, option = {}) {
|
|
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;
|
|
79
|
+
}
|
|
80
|
+
exports.clearContainerCache = clearContainerCache;
|
|
81
|
+
exports.injectCSS = injectCSS;
|
|
82
|
+
exports.removeCSS = removeCSS;
|
|
83
|
+
exports.updateCSS = updateCSS;
|