@v-c/util 0.0.13 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Children/isFragment.cjs +2 -4
- package/dist/Children/isFragment.js +3 -5
- package/dist/Children/toArray.cjs +10 -17
- package/dist/Children/toArray.js +10 -17
- package/dist/Dom/addEventListener.cjs +5 -10
- package/dist/Dom/addEventListener.js +6 -11
- package/dist/Dom/canUseDom.cjs +2 -3
- package/dist/Dom/canUseDom.js +2 -4
- package/dist/Dom/class.cjs +6 -20
- package/dist/Dom/class.js +7 -23
- package/dist/Dom/contains.cjs +9 -13
- package/dist/Dom/contains.js +9 -14
- package/dist/Dom/css.cjs +51 -66
- package/dist/Dom/css.js +52 -74
- package/dist/Dom/dynamicCSS.cjs +59 -86
- package/dist/Dom/dynamicCSS.js +58 -88
- package/dist/Dom/findDOMNode.cjs +7 -10
- package/dist/Dom/findDOMNode.js +6 -11
- package/dist/Dom/focus.cjs +36 -43
- package/dist/Dom/focus.js +37 -48
- package/dist/Dom/isVisible.cjs +16 -21
- package/dist/Dom/isVisible.js +15 -21
- package/dist/Dom/scrollLocker.cjs +66 -88
- package/dist/Dom/scrollLocker.js +64 -87
- package/dist/Dom/shadow.cjs +3 -5
- package/dist/Dom/shadow.js +4 -7
- package/dist/Dom/styleChecker.cjs +14 -18
- package/dist/Dom/styleChecker.js +14 -18
- package/dist/Dom/support.cjs +14 -22
- package/dist/Dom/support.js +12 -21
- package/dist/EventInterface.cjs +0 -1
- package/dist/EventInterface.js +0 -1
- package/dist/KeyCode.cjs +165 -522
- package/dist/KeyCode.js +164 -522
- package/dist/Portal.cjs +40 -46
- package/dist/Portal.js +37 -45
- package/dist/PortalWrapper.cjs +130 -164
- package/dist/PortalWrapper.js +126 -163
- package/dist/classnames.cjs +30 -38
- package/dist/classnames.js +30 -40
- package/dist/composeProps.cjs +15 -17
- package/dist/composeProps.js +14 -17
- package/dist/createRef.cjs +14 -16
- package/dist/createRef.js +13 -18
- package/dist/debug/diff.cjs +39 -45
- package/dist/debug/diff.js +39 -46
- package/dist/deprecated.cjs +2 -7
- package/dist/deprecated.js +2 -8
- package/dist/getScrollBarSize.cjs +39 -43
- package/dist/getScrollBarSize.js +39 -45
- package/dist/guid.cjs +3 -4
- package/dist/guid.js +3 -5
- package/dist/hooks/useEvent.cjs +2 -3
- package/dist/hooks/useEvent.js +2 -4
- package/dist/hooks/useId.cjs +10 -15
- package/dist/hooks/useId.js +9 -15
- package/dist/hooks/useLayoutEffect.cjs +29 -52
- package/dist/hooks/useLayoutEffect.js +30 -54
- package/dist/hooks/useMemo.cjs +9 -13
- package/dist/hooks/useMemo.js +8 -13
- package/dist/hooks/useMergedState.cjs +22 -27
- package/dist/hooks/useMergedState.js +22 -28
- package/dist/hooks/useMobile.cjs +13 -13
- package/dist/hooks/useMobile.js +12 -14
- package/dist/hooks/useState.cjs +7 -9
- package/dist/hooks/useState.js +6 -9
- package/dist/index.cjs +9 -11
- package/dist/index.js +5 -11
- package/dist/isEqual.cjs +26 -34
- package/dist/isEqual.js +25 -34
- package/dist/isMobile.cjs +6 -12
- package/dist/isMobile.js +5 -12
- package/dist/isValid.cjs +4 -4
- package/dist/isValid.js +3 -4
- package/dist/omit.cjs +6 -9
- package/dist/omit.js +6 -10
- package/dist/pickAttrs.cjs +20 -36
- package/dist/pickAttrs.js +20 -37
- package/dist/props-util/index.cjs +35 -52
- package/dist/props-util/index.js +35 -57
- package/dist/raf.cjs +34 -37
- package/dist/raf.js +33 -38
- package/dist/setStyle.cjs +14 -15
- package/dist/setStyle.js +13 -15
- package/dist/switchScrollingEffect.cjs +29 -35
- package/dist/switchScrollingEffect.js +27 -34
- package/dist/test/domHook.cjs +32 -46
- package/dist/test/domHook.js +33 -48
- package/dist/type.cjs +36 -17
- package/dist/type.d.ts +1 -1
- package/dist/type.js +38 -30
- package/dist/utils/checkSlotProp.cjs +6 -10
- package/dist/utils/checkSlotProp.js +7 -11
- package/dist/utils/get.cjs +7 -9
- package/dist/utils/get.js +7 -10
- package/dist/utils/omit.cjs +5 -7
- package/dist/utils/omit.js +6 -8
- package/dist/utils/set.cjs +37 -51
- package/dist/utils/set.js +36 -53
- package/dist/utils/transition.cjs +76 -80
- package/dist/utils/transition.d.ts +2 -2
- package/dist/utils/transition.js +76 -84
- package/dist/utils/watchState.cjs +12 -14
- package/dist/utils/watchState.js +13 -16
- package/dist/vnode.cjs +31 -39
- package/dist/vnode.js +31 -43
- package/dist/vueuse/unref-element.cjs +3 -5
- package/dist/vueuse/unref-element.js +3 -5
- package/dist/warning.cjs +21 -29
- package/dist/warning.js +20 -36
- package/package.json +1 -1
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const vue = require("vue");
|
|
1
|
+
let vue = require("vue");
|
|
4
2
|
function isFragment(node) {
|
|
5
|
-
|
|
3
|
+
return (0, vue.isVNode)(node) && node.type === vue.Fragment;
|
|
6
4
|
}
|
|
7
5
|
exports.isFragment = isFragment;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Fragment, isVNode } from "vue";
|
|
2
2
|
function isFragment(node) {
|
|
3
|
-
|
|
3
|
+
return isVNode(node) && node.type === Fragment;
|
|
4
4
|
}
|
|
5
|
-
export {
|
|
6
|
-
isFragment
|
|
7
|
-
};
|
|
5
|
+
export { isFragment };
|
|
@@ -1,20 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const isFragment = require("./isFragment.cjs");
|
|
1
|
+
const require_isFragment = require("./isFragment.cjs");
|
|
4
2
|
function toArray(children, option = {}) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
ret = ret.concat(toArray(child.children, option));
|
|
15
|
-
else
|
|
16
|
-
ret.push(child);
|
|
17
|
-
}
|
|
18
|
-
return ret;
|
|
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;
|
|
19
12
|
}
|
|
20
13
|
exports.toArray = toArray;
|
package/dist/Children/toArray.js
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
import { isFragment } from "./isFragment.js";
|
|
2
2
|
function toArray(children, option = {}) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
ret = ret.concat(toArray(child.children, option));
|
|
13
|
-
else
|
|
14
|
-
ret.push(child);
|
|
15
|
-
}
|
|
16
|
-
return ret;
|
|
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;
|
|
17
12
|
}
|
|
18
|
-
export {
|
|
19
|
-
toArray
|
|
20
|
-
};
|
|
13
|
+
export { toArray };
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
1
|
function addEventListener(...args) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
target?.removeEventListener?.(eventType, cb, option);
|
|
10
|
-
}
|
|
11
|
-
};
|
|
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
|
+
} };
|
|
12
7
|
}
|
|
13
8
|
exports.addEventListener = addEventListener;
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
function addEventListener(...args) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
target?.removeEventListener?.(eventType, cb, option);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
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
|
+
} };
|
|
10
7
|
}
|
|
11
|
-
export {
|
|
12
|
-
addEventListener
|
|
13
|
-
};
|
|
8
|
+
export { addEventListener };
|
package/dist/Dom/canUseDom.cjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
"
|
|
2
|
-
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
2
|
function canUseDom() {
|
|
4
|
-
|
|
3
|
+
return !!(typeof window !== "undefined" && window.document && window.document.createElement);
|
|
5
4
|
}
|
|
6
5
|
exports.default = canUseDom;
|
package/dist/Dom/canUseDom.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
function canUseDom() {
|
|
2
|
-
|
|
2
|
+
return !!(typeof window !== "undefined" && window.document && window.document.createElement);
|
|
3
3
|
}
|
|
4
|
-
export {
|
|
5
|
-
canUseDom as default
|
|
6
|
-
};
|
|
4
|
+
export { canUseDom as default };
|
package/dist/Dom/class.cjs
CHANGED
|
@@ -1,28 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
1
|
function hasClass(node, className) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const originClass = node.className;
|
|
7
|
-
return ` ${originClass} `.includes(` ${className} `);
|
|
2
|
+
if (node.classList) return node.classList.contains(className);
|
|
3
|
+
return ` ${node.className} `.includes(` ${className} `);
|
|
8
4
|
}
|
|
9
5
|
function addClass(node, className) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} else {
|
|
13
|
-
if (!hasClass(node, className))
|
|
14
|
-
node.className = `${node.className} ${className}`;
|
|
15
|
-
}
|
|
6
|
+
if (node.classList) node.classList.add(className);
|
|
7
|
+
else if (!hasClass(node, className)) node.className = `${node.className} ${className}`;
|
|
16
8
|
}
|
|
17
9
|
function removeClass(node, className) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
} else {
|
|
21
|
-
if (hasClass(node, className)) {
|
|
22
|
-
const originClass = node.className;
|
|
23
|
-
node.className = ` ${originClass} `.replace(` ${className} `, " ");
|
|
24
|
-
}
|
|
25
|
-
}
|
|
10
|
+
if (node.classList) node.classList.remove(className);
|
|
11
|
+
else if (hasClass(node, className)) node.className = ` ${node.className} `.replace(` ${className} `, " ");
|
|
26
12
|
}
|
|
27
13
|
exports.addClass = addClass;
|
|
28
14
|
exports.hasClass = hasClass;
|
package/dist/Dom/class.js
CHANGED
|
@@ -1,29 +1,13 @@
|
|
|
1
1
|
function hasClass(node, className) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const originClass = node.className;
|
|
5
|
-
return ` ${originClass} `.includes(` ${className} `);
|
|
2
|
+
if (node.classList) return node.classList.contains(className);
|
|
3
|
+
return ` ${node.className} `.includes(` ${className} `);
|
|
6
4
|
}
|
|
7
5
|
function addClass(node, className) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} else {
|
|
11
|
-
if (!hasClass(node, className))
|
|
12
|
-
node.className = `${node.className} ${className}`;
|
|
13
|
-
}
|
|
6
|
+
if (node.classList) node.classList.add(className);
|
|
7
|
+
else if (!hasClass(node, className)) node.className = `${node.className} ${className}`;
|
|
14
8
|
}
|
|
15
9
|
function removeClass(node, className) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} else {
|
|
19
|
-
if (hasClass(node, className)) {
|
|
20
|
-
const originClass = node.className;
|
|
21
|
-
node.className = ` ${originClass} `.replace(` ${className} `, " ");
|
|
22
|
-
}
|
|
23
|
-
}
|
|
10
|
+
if (node.classList) node.classList.remove(className);
|
|
11
|
+
else if (hasClass(node, className)) node.className = ` ${node.className} `.replace(` ${className} `, " ");
|
|
24
12
|
}
|
|
25
|
-
export {
|
|
26
|
-
addClass,
|
|
27
|
-
hasClass,
|
|
28
|
-
removeClass
|
|
29
|
-
};
|
|
13
|
+
export { addClass, hasClass, removeClass };
|
package/dist/Dom/contains.cjs
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
"
|
|
2
|
-
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
2
|
function contains(root, n) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
node = node.parentNode;
|
|
13
|
-
}
|
|
14
|
-
return false;
|
|
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;
|
|
15
11
|
}
|
|
16
12
|
exports.default = contains;
|
package/dist/Dom/contains.js
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
function contains(root, n) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
node = node.parentNode;
|
|
11
|
-
}
|
|
12
|
-
return false;
|
|
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
|
-
contains as default
|
|
16
|
-
};
|
|
11
|
+
export { contains as default };
|
package/dist/Dom/css.cjs
CHANGED
|
@@ -1,90 +1,75 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
left: true,
|
|
6
|
-
top: true
|
|
1
|
+
var PIXEL_PATTERN = /margin|padding|width|height|max|min|offset/;
|
|
2
|
+
var removePixel = {
|
|
3
|
+
left: true,
|
|
4
|
+
top: true
|
|
7
5
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
var floatMap = {
|
|
7
|
+
cssFloat: 1,
|
|
8
|
+
styleFloat: 1,
|
|
9
|
+
float: 1
|
|
12
10
|
};
|
|
13
11
|
function getComputedStyle(node) {
|
|
14
|
-
|
|
12
|
+
return node.nodeType === 1 ? node.ownerDocument.defaultView.getComputedStyle(node, null) : {};
|
|
15
13
|
}
|
|
16
14
|
function getStyleValue(node, type, value) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (!(type in removePixel))
|
|
25
|
-
removePixel[type] = PIXEL_PATTERN.test(type);
|
|
26
|
-
return removePixel[type] ? Number.parseFloat(value) || 0 : 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;
|
|
27
22
|
}
|
|
28
23
|
function get(node, name) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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]);
|
|
33
28
|
}
|
|
34
29
|
function set(node, name, value) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (x in name)
|
|
45
|
-
set(node, x, name[x]);
|
|
46
|
-
}
|
|
47
|
-
return getComputedStyle(node);
|
|
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);
|
|
48
39
|
}
|
|
49
40
|
function getOuterWidth(el) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return el.offsetWidth;
|
|
41
|
+
if (el === document.body) return document.documentElement.clientWidth;
|
|
42
|
+
return el.offsetWidth;
|
|
53
43
|
}
|
|
54
44
|
function getOuterHeight(el) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return el.offsetHeight;
|
|
45
|
+
if (el === document.body) return window.innerHeight || document.documentElement.clientHeight;
|
|
46
|
+
return el.offsetHeight;
|
|
58
47
|
}
|
|
59
48
|
function getDocSize() {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
height
|
|
65
|
-
};
|
|
49
|
+
return {
|
|
50
|
+
width: Math.max(document.documentElement.scrollWidth, document.body.scrollWidth),
|
|
51
|
+
height: Math.max(document.documentElement.scrollHeight, document.body.scrollHeight)
|
|
52
|
+
};
|
|
66
53
|
}
|
|
67
54
|
function getClientSize() {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
height
|
|
73
|
-
};
|
|
55
|
+
return {
|
|
56
|
+
width: document.documentElement.clientWidth,
|
|
57
|
+
height: window.innerHeight || document.documentElement.clientHeight
|
|
58
|
+
};
|
|
74
59
|
}
|
|
75
60
|
function getScroll() {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
61
|
+
return {
|
|
62
|
+
scrollLeft: Math.max(document.documentElement.scrollLeft, document.body.scrollLeft),
|
|
63
|
+
scrollTop: Math.max(document.documentElement.scrollTop, document.body.scrollTop)
|
|
64
|
+
};
|
|
80
65
|
}
|
|
81
66
|
function getOffset(node) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
+
};
|
|
88
73
|
}
|
|
89
74
|
exports.get = get;
|
|
90
75
|
exports.getClientSize = getClientSize;
|
package/dist/Dom/css.js
CHANGED
|
@@ -1,96 +1,74 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var PIXEL_PATTERN = /margin|padding|width|height|max|min|offset/;
|
|
2
|
+
var removePixel = {
|
|
3
|
+
left: true,
|
|
4
|
+
top: true
|
|
5
5
|
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
var floatMap = {
|
|
7
|
+
cssFloat: 1,
|
|
8
|
+
styleFloat: 1,
|
|
9
|
+
float: 1
|
|
10
10
|
};
|
|
11
11
|
function getComputedStyle(node) {
|
|
12
|
-
|
|
12
|
+
return node.nodeType === 1 ? node.ownerDocument.defaultView.getComputedStyle(node, null) : {};
|
|
13
13
|
}
|
|
14
14
|
function getStyleValue(node, type, value) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (!(type in removePixel))
|
|
23
|
-
removePixel[type] = PIXEL_PATTERN.test(type);
|
|
24
|
-
return removePixel[type] ? Number.parseFloat(value) || 0 : 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;
|
|
25
22
|
}
|
|
26
23
|
function get(node, name) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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]);
|
|
31
28
|
}
|
|
32
29
|
function set(node, name, value) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (x in name)
|
|
43
|
-
set(node, x, name[x]);
|
|
44
|
-
}
|
|
45
|
-
return getComputedStyle(node);
|
|
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);
|
|
46
39
|
}
|
|
47
40
|
function getOuterWidth(el) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return el.offsetWidth;
|
|
41
|
+
if (el === document.body) return document.documentElement.clientWidth;
|
|
42
|
+
return el.offsetWidth;
|
|
51
43
|
}
|
|
52
44
|
function getOuterHeight(el) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return el.offsetHeight;
|
|
45
|
+
if (el === document.body) return window.innerHeight || document.documentElement.clientHeight;
|
|
46
|
+
return el.offsetHeight;
|
|
56
47
|
}
|
|
57
48
|
function getDocSize() {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
height
|
|
63
|
-
};
|
|
49
|
+
return {
|
|
50
|
+
width: Math.max(document.documentElement.scrollWidth, document.body.scrollWidth),
|
|
51
|
+
height: Math.max(document.documentElement.scrollHeight, document.body.scrollHeight)
|
|
52
|
+
};
|
|
64
53
|
}
|
|
65
54
|
function getClientSize() {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
height
|
|
71
|
-
};
|
|
55
|
+
return {
|
|
56
|
+
width: document.documentElement.clientWidth,
|
|
57
|
+
height: window.innerHeight || document.documentElement.clientHeight
|
|
58
|
+
};
|
|
72
59
|
}
|
|
73
60
|
function getScroll() {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
61
|
+
return {
|
|
62
|
+
scrollLeft: Math.max(document.documentElement.scrollLeft, document.body.scrollLeft),
|
|
63
|
+
scrollTop: Math.max(document.documentElement.scrollTop, document.body.scrollTop)
|
|
64
|
+
};
|
|
78
65
|
}
|
|
79
66
|
function getOffset(node) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
+
};
|
|
86
73
|
}
|
|
87
|
-
export {
|
|
88
|
-
get,
|
|
89
|
-
getClientSize,
|
|
90
|
-
getDocSize,
|
|
91
|
-
getOffset,
|
|
92
|
-
getOuterHeight,
|
|
93
|
-
getOuterWidth,
|
|
94
|
-
getScroll,
|
|
95
|
-
set
|
|
96
|
-
};
|
|
74
|
+
export { get, getClientSize, getDocSize, getOffset, getOuterHeight, getOuterWidth, getScroll, set };
|