@v-c/util 0.0.11 → 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.
- package/dist/Children/isFragment.cjs +7 -1
- package/dist/Children/isFragment.js +4 -4
- package/dist/Children/toArray.cjs +20 -1
- package/dist/Children/toArray.js +17 -8
- package/dist/Dom/addEventListener.cjs +13 -1
- package/dist/Dom/addEventListener.js +7 -5
- package/dist/Dom/canUseDom.cjs +6 -1
- package/dist/Dom/canUseDom.js +3 -3
- package/dist/Dom/class.cjs +29 -1
- package/dist/Dom/class.js +23 -13
- package/dist/Dom/contains.cjs +16 -1
- package/dist/Dom/contains.js +12 -12
- package/dist/Dom/css.cjs +96 -1
- package/dist/Dom/css.js +69 -48
- package/dist/Dom/dynamicCSS.cjs +110 -1
- package/dist/Dom/dynamicCSS.js +92 -59
- package/dist/Dom/findDOMNode.cjs +16 -1
- package/dist/Dom/findDOMNode.js +12 -8
- package/dist/Dom/focus.cjs +60 -1
- package/dist/Dom/focus.js +48 -28
- package/dist/Dom/isVisible.cjs +22 -1
- package/dist/Dom/isVisible.js +16 -16
- package/dist/Dom/scrollLocker.cjs +89 -1
- package/dist/Dom/scrollLocker.js +70 -45
- package/dist/Dom/shadow.cjs +13 -1
- package/dist/Dom/shadow.js +8 -8
- package/dist/Dom/styleChecker.cjs +25 -1
- package/dist/Dom/styleChecker.js +19 -14
- package/dist/Dom/support.cjs +28 -1
- package/dist/Dom/support.js +16 -12
- package/dist/KeyCode.cjs +523 -1
- package/dist/KeyCode.js +62 -55
- package/dist/Portal.cjs +48 -1
- package/dist/Portal.js +34 -19
- package/dist/PortalWrapper.cjs +169 -1
- package/dist/PortalWrapper.js +133 -79
- package/dist/classnames.cjs +45 -1
- package/dist/classnames.js +38 -25
- package/dist/composeProps.cjs +19 -1
- package/dist/composeProps.js +15 -9
- package/dist/createRef.cjs +24 -1
- package/dist/createRef.js +16 -13
- package/dist/debug/diff.cjs +50 -1
- package/dist/debug/diff.js +39 -30
- package/dist/deprecated.cjs +10 -1
- package/dist/deprecated.js +7 -5
- package/dist/getScrollBarSize.cjs +51 -1
- package/dist/getScrollBarSize.js +39 -25
- package/dist/guid.cjs +7 -1
- package/dist/guid.js +4 -4
- package/dist/hooks/useEvent.cjs +6 -1
- package/dist/hooks/useEvent.js +3 -3
- package/dist/hooks/useId.cjs +18 -1
- package/dist/hooks/useId.js +14 -8
- package/dist/hooks/useLayoutEffect.cjs +58 -1
- package/dist/hooks/useLayoutEffect.js +50 -20
- package/dist/hooks/useMemo.cjs +16 -1
- package/dist/hooks/useMemo.js +13 -7
- package/dist/hooks/useMergedState.cjs +30 -1
- package/dist/hooks/useMergedState.js +25 -16
- package/dist/hooks/useMobile.cjs +16 -1
- package/dist/hooks/useMobile.js +13 -11
- package/dist/hooks/useState.cjs +12 -1
- package/dist/hooks/useState.js +8 -7
- package/dist/index.cjs +11 -1
- package/dist/index.js +9 -9
- package/dist/isEqual.cjs +36 -1
- package/dist/isEqual.js +30 -26
- package/dist/isMobile.cjs +13 -1
- package/dist/isMobile.js +7 -7
- package/dist/isValid.cjs +6 -1
- package/dist/isValid.js +3 -3
- package/dist/omit.cjs +12 -1
- package/dist/omit.js +9 -6
- package/dist/pickAttrs.cjs +41 -3
- package/dist/pickAttrs.js +37 -22
- package/dist/props-util/index.cjs +69 -1
- package/dist/props-util/index.js +62 -32
- package/dist/raf.cjs +48 -1
- package/dist/raf.js +37 -26
- package/dist/setStyle.cjs +17 -1
- package/dist/setStyle.js +13 -9
- package/dist/switchScrollingEffect.cjs +38 -1
- package/dist/switchScrollingEffect.js +27 -20
- package/dist/test/domHook.cjs +52 -1
- package/dist/test/domHook.js +43 -28
- package/dist/type.cjs +51 -1
- package/dist/type.js +39 -37
- package/dist/utils/checkSlotProp.cjs +13 -1
- package/dist/utils/checkSlotProp.js +10 -3
- package/dist/utils/get.cjs +12 -1
- package/dist/utils/get.js +8 -8
- package/dist/utils/omit.cjs +10 -1
- package/dist/utils/omit.js +7 -6
- package/dist/utils/set.cjs +64 -1
- package/dist/utils/set.js +54 -32
- package/dist/utils/transition.cjs +96 -1
- package/dist/utils/transition.d.ts +2 -2
- package/dist/utils/transition.js +70 -65
- package/dist/utils/watchState.cjs +20 -1
- package/dist/utils/watchState.js +15 -10
- package/dist/vnode.cjs +56 -1
- package/dist/vnode.js +46 -30
- package/dist/vueuse/unref-element.cjs +8 -1
- package/dist/vueuse/unref-element.js +5 -5
- package/dist/warning.cjs +53 -1
- package/dist/warning.js +40 -35
- package/package.json +1 -1
|
@@ -1 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
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
|
|
2
|
-
function
|
|
3
|
-
return
|
|
1
|
+
import { isVNode, Fragment } from "vue";
|
|
2
|
+
function isFragment(node) {
|
|
3
|
+
return isVNode(node) && node.type === Fragment;
|
|
4
4
|
}
|
|
5
5
|
export {
|
|
6
|
-
|
|
6
|
+
isFragment
|
|
7
7
|
};
|
|
@@ -1 +1,20 @@
|
|
|
1
|
-
"use strict";
|
|
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;
|
package/dist/Children/toArray.js
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
import { isFragment
|
|
2
|
-
function
|
|
3
|
-
let
|
|
4
|
-
Array.isArray(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
19
|
+
toArray
|
|
11
20
|
};
|
|
@@ -1 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
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
|
|
2
|
-
const [
|
|
3
|
-
|
|
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
|
-
|
|
7
|
+
target?.removeEventListener?.(eventType, cb, option);
|
|
6
8
|
}
|
|
7
9
|
};
|
|
8
10
|
}
|
|
9
11
|
export {
|
|
10
|
-
|
|
12
|
+
addEventListener
|
|
11
13
|
};
|
package/dist/Dom/canUseDom.cjs
CHANGED
|
@@ -1 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
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;
|
package/dist/Dom/canUseDom.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
function
|
|
2
|
-
return !!(typeof window
|
|
1
|
+
function canUseDom() {
|
|
2
|
+
return !!(typeof window !== "undefined" && window.document && window.document.createElement);
|
|
3
3
|
}
|
|
4
4
|
export {
|
|
5
|
-
|
|
5
|
+
canUseDom as default
|
|
6
6
|
};
|
package/dist/Dom/class.cjs
CHANGED
|
@@ -1 +1,29 @@
|
|
|
1
|
-
"use strict";
|
|
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
|
|
2
|
-
|
|
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
|
|
5
|
-
|
|
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
|
|
8
|
-
if (
|
|
9
|
-
|
|
10
|
-
else
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
26
|
+
addClass,
|
|
27
|
+
hasClass,
|
|
28
|
+
removeClass
|
|
19
29
|
};
|
package/dist/Dom/contains.cjs
CHANGED
|
@@ -1 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
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;
|
package/dist/Dom/contains.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
function
|
|
2
|
-
if (!
|
|
3
|
-
return
|
|
4
|
-
if (
|
|
5
|
-
return
|
|
6
|
-
let
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
return
|
|
10
|
-
|
|
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
|
|
12
|
+
return false;
|
|
13
13
|
}
|
|
14
14
|
export {
|
|
15
|
-
|
|
15
|
+
contains as default
|
|
16
16
|
};
|
package/dist/Dom/css.cjs
CHANGED
|
@@ -1 +1,96 @@
|
|
|
1
|
-
"use strict";
|
|
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
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
|
10
|
-
return
|
|
11
|
+
function getComputedStyle(node) {
|
|
12
|
+
return node.nodeType === 1 ? node.ownerDocument.defaultView.getComputedStyle(node, null) : {};
|
|
11
13
|
}
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
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
|
|
22
|
-
const
|
|
23
|
-
|
|
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
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
|
34
|
-
|
|
47
|
+
function getOuterWidth(el) {
|
|
48
|
+
if (el === document.body)
|
|
49
|
+
return document.documentElement.clientWidth;
|
|
50
|
+
return el.offsetWidth;
|
|
35
51
|
}
|
|
36
|
-
function
|
|
37
|
-
|
|
52
|
+
function getOuterHeight(el) {
|
|
53
|
+
if (el === document.body)
|
|
54
|
+
return window.innerHeight || document.documentElement.clientHeight;
|
|
55
|
+
return el.offsetHeight;
|
|
38
56
|
}
|
|
39
|
-
function
|
|
40
|
-
const
|
|
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
|
|
43
|
-
height
|
|
61
|
+
width,
|
|
62
|
+
height
|
|
44
63
|
};
|
|
45
64
|
}
|
|
46
|
-
function
|
|
47
|
-
const
|
|
65
|
+
function getClientSize() {
|
|
66
|
+
const width = document.documentElement.clientWidth;
|
|
67
|
+
const height = window.innerHeight || document.documentElement.clientHeight;
|
|
48
68
|
return {
|
|
49
|
-
width
|
|
50
|
-
height
|
|
69
|
+
width,
|
|
70
|
+
height
|
|
51
71
|
};
|
|
52
72
|
}
|
|
53
|
-
function
|
|
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
|
|
60
|
-
const
|
|
79
|
+
function getOffset(node) {
|
|
80
|
+
const box = node.getBoundingClientRect();
|
|
81
|
+
const docElem = document.documentElement;
|
|
61
82
|
return {
|
|
62
|
-
left:
|
|
63
|
-
top:
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
88
|
+
get,
|
|
89
|
+
getClientSize,
|
|
90
|
+
getDocSize,
|
|
91
|
+
getOffset,
|
|
92
|
+
getOuterHeight,
|
|
93
|
+
getOuterWidth,
|
|
94
|
+
getScroll,
|
|
95
|
+
set
|
|
75
96
|
};
|
package/dist/Dom/dynamicCSS.cjs
CHANGED
|
@@ -1 +1,110 @@
|
|
|
1
|
-
"use strict";
|
|
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;
|