@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.
- 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
package/dist/pickAttrs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const attributes = `accept acceptCharset accessKey action allowFullScreen allowTransparency
|
|
2
2
|
alt async autoComplete autoFocus autoPlay capture cellPadding cellSpacing challenge
|
|
3
3
|
charSet checked classID className colSpan cols content contentEditable contextMenu
|
|
4
4
|
controls coords crossOrigin data dateTime default defer dir disabled download draggable
|
|
@@ -9,33 +9,48 @@ const s = `accept acceptCharset accessKey action allowFullScreen allowTransparen
|
|
|
9
9
|
optimum pattern placeholder poster preload radioGroup readOnly rel required
|
|
10
10
|
reversed role rowSpan rows sandbox scope scoped scrolling seamless selected
|
|
11
11
|
shape size sizes span spellCheck src srcDoc srcLang srcSet start step style
|
|
12
|
-
summary tabIndex target title type useMap value width wmode wrap
|
|
12
|
+
summary tabIndex target title type useMap value width wmode wrap`;
|
|
13
|
+
const eventsName = `onCopy onCut onPaste onCompositionEnd onCompositionStart onCompositionUpdate onKeyDown
|
|
13
14
|
onKeyPress onKeyUp onFocus onBlur onChange onInput onSubmit onClick onContextMenu onDoubleClick
|
|
14
15
|
onDrag onDragEnd onDragEnter onDragExit onDragLeave onDragOver onDragStart onDrop onMouseDown
|
|
15
16
|
onMouseEnter onMouseLeave onMouseMove onMouseOut onMouseOver onMouseUp onSelect onTouchCancel
|
|
16
17
|
onTouchEnd onTouchMove onTouchStart onScroll onWheel onAbort onCanPlay onCanPlayThrough
|
|
17
18
|
onDurationChange onEmptied onEncrypted onEnded onError onLoadedData onLoadedMetadata
|
|
18
|
-
onLoadStart onPause onPlay onPlaying onProgress onRateChange onSeeked onSeeking onStalled onSuspend onTimeUpdate onVolumeChange onWaiting onLoad onError
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
onLoadStart onPause onPlay onPlaying onProgress onRateChange onSeeked onSeeking onStalled onSuspend onTimeUpdate onVolumeChange onWaiting onLoad onError`;
|
|
20
|
+
const propList = `${attributes} ${eventsName}`.split(/\s+/);
|
|
21
|
+
const ariaPrefix = "aria-";
|
|
22
|
+
const dataPrefix = "data-";
|
|
23
|
+
function match(key, prefix) {
|
|
24
|
+
return key.indexOf(prefix) === 0;
|
|
21
25
|
}
|
|
22
|
-
function
|
|
23
|
-
let
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
26
|
+
function pickAttrs(props, ariaOnly = false) {
|
|
27
|
+
let mergedConfig;
|
|
28
|
+
if (ariaOnly === false) {
|
|
29
|
+
mergedConfig = {
|
|
30
|
+
aria: true,
|
|
31
|
+
data: true,
|
|
32
|
+
attr: true
|
|
33
|
+
};
|
|
34
|
+
} else if (ariaOnly === true) {
|
|
35
|
+
mergedConfig = {
|
|
36
|
+
aria: true
|
|
37
|
+
};
|
|
38
|
+
} else {
|
|
39
|
+
mergedConfig = {
|
|
40
|
+
...ariaOnly
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const attrs = {};
|
|
44
|
+
Object.keys(props).forEach((key) => {
|
|
45
|
+
if (
|
|
46
|
+
// Aria
|
|
47
|
+
mergedConfig.aria && (key === "role" || match(key, ariaPrefix)) || mergedConfig.data && match(key, dataPrefix) || mergedConfig.attr && propList.includes(key)
|
|
48
|
+
) {
|
|
49
|
+
attrs[key] = props[key];
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
return attrs;
|
|
38
53
|
}
|
|
39
54
|
export {
|
|
40
|
-
|
|
55
|
+
pickAttrs as default
|
|
41
56
|
};
|
|
@@ -1 +1,69 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const vue = require("vue");
|
|
4
|
+
const isValid = require("../isValid.cjs");
|
|
5
|
+
function isEmptyElement(c) {
|
|
6
|
+
return c && (c.type === vue.Comment || c.type === vue.Fragment && c.children.length === 0 || c.type === vue.Text && c.children.trim() === "");
|
|
7
|
+
}
|
|
8
|
+
function filterEmpty(children = []) {
|
|
9
|
+
const res = [];
|
|
10
|
+
children.forEach((child) => {
|
|
11
|
+
if (Array.isArray(child))
|
|
12
|
+
res.push(...child);
|
|
13
|
+
else if (child?.type === vue.Fragment)
|
|
14
|
+
res.push(...filterEmpty(child.children));
|
|
15
|
+
else res.push(child);
|
|
16
|
+
});
|
|
17
|
+
return res.filter((c) => !isEmptyElement(c));
|
|
18
|
+
}
|
|
19
|
+
const skipFlattenKey = Symbol("skipFlatten");
|
|
20
|
+
function flattenChildren(children, isFilterEmpty = true) {
|
|
21
|
+
const temp = Array.isArray(children) ? children : [children];
|
|
22
|
+
const res = [];
|
|
23
|
+
temp.forEach((child) => {
|
|
24
|
+
if (Array.isArray(child)) {
|
|
25
|
+
res.push(...flattenChildren(child, isFilterEmpty));
|
|
26
|
+
} else if (isValid.default(child)) {
|
|
27
|
+
res.push(child);
|
|
28
|
+
} else if (child && typeof child === "object" && child.type === vue.Fragment) {
|
|
29
|
+
if (child.key === skipFlattenKey) {
|
|
30
|
+
res.push(child);
|
|
31
|
+
} else {
|
|
32
|
+
res.push(...flattenChildren(child.children, isFilterEmpty));
|
|
33
|
+
}
|
|
34
|
+
} else if (child && vue.isVNode(child)) {
|
|
35
|
+
if (isFilterEmpty && !isEmptyElement(child)) {
|
|
36
|
+
res.push(child);
|
|
37
|
+
} else if (!isFilterEmpty) {
|
|
38
|
+
res.push(child);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
if (isFilterEmpty) {
|
|
43
|
+
return filterEmpty(res);
|
|
44
|
+
}
|
|
45
|
+
return res;
|
|
46
|
+
}
|
|
47
|
+
function toPropsRefs(obj, ...args) {
|
|
48
|
+
const _res = {};
|
|
49
|
+
args.forEach((key) => {
|
|
50
|
+
_res[key] = vue.toRef(obj, key);
|
|
51
|
+
});
|
|
52
|
+
return _res;
|
|
53
|
+
}
|
|
54
|
+
function removeUndefined(obj) {
|
|
55
|
+
const res = {};
|
|
56
|
+
Object.keys(obj).forEach((key) => {
|
|
57
|
+
const value = obj[key];
|
|
58
|
+
if (value !== void 0) {
|
|
59
|
+
res[key] = value;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return res;
|
|
63
|
+
}
|
|
64
|
+
exports.filterEmpty = filterEmpty;
|
|
65
|
+
exports.flattenChildren = flattenChildren;
|
|
66
|
+
exports.isEmptyElement = isEmptyElement;
|
|
67
|
+
exports.removeUndefined = removeUndefined;
|
|
68
|
+
exports.skipFlattenKey = skipFlattenKey;
|
|
69
|
+
exports.toPropsRefs = toPropsRefs;
|
package/dist/props-util/index.js
CHANGED
|
@@ -1,39 +1,69 @@
|
|
|
1
|
-
import { Comment
|
|
2
|
-
import
|
|
3
|
-
function
|
|
4
|
-
return
|
|
1
|
+
import { Comment, Fragment, Text, isVNode, toRef } from "vue";
|
|
2
|
+
import isValid from "../isValid.js";
|
|
3
|
+
function isEmptyElement(c) {
|
|
4
|
+
return c && (c.type === Comment || c.type === Fragment && c.children.length === 0 || c.type === Text && c.children.trim() === "");
|
|
5
5
|
}
|
|
6
|
-
function
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
Array.isArray(
|
|
10
|
-
|
|
6
|
+
function filterEmpty(children = []) {
|
|
7
|
+
const res = [];
|
|
8
|
+
children.forEach((child) => {
|
|
9
|
+
if (Array.isArray(child))
|
|
10
|
+
res.push(...child);
|
|
11
|
+
else if (child?.type === Fragment)
|
|
12
|
+
res.push(...filterEmpty(child.children));
|
|
13
|
+
else res.push(child);
|
|
14
|
+
});
|
|
15
|
+
return res.filter((c) => !isEmptyElement(c));
|
|
11
16
|
}
|
|
12
|
-
const
|
|
13
|
-
function
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
const skipFlattenKey = Symbol("skipFlatten");
|
|
18
|
+
function flattenChildren(children, isFilterEmpty = true) {
|
|
19
|
+
const temp = Array.isArray(children) ? children : [children];
|
|
20
|
+
const res = [];
|
|
21
|
+
temp.forEach((child) => {
|
|
22
|
+
if (Array.isArray(child)) {
|
|
23
|
+
res.push(...flattenChildren(child, isFilterEmpty));
|
|
24
|
+
} else if (isValid(child)) {
|
|
25
|
+
res.push(child);
|
|
26
|
+
} else if (child && typeof child === "object" && child.type === Fragment) {
|
|
27
|
+
if (child.key === skipFlattenKey) {
|
|
28
|
+
res.push(child);
|
|
29
|
+
} else {
|
|
30
|
+
res.push(...flattenChildren(child.children, isFilterEmpty));
|
|
31
|
+
}
|
|
32
|
+
} else if (child && isVNode(child)) {
|
|
33
|
+
if (isFilterEmpty && !isEmptyElement(child)) {
|
|
34
|
+
res.push(child);
|
|
35
|
+
} else if (!isFilterEmpty) {
|
|
36
|
+
res.push(child);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
if (isFilterEmpty) {
|
|
41
|
+
return filterEmpty(res);
|
|
42
|
+
}
|
|
43
|
+
return res;
|
|
18
44
|
}
|
|
19
|
-
function
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
})
|
|
45
|
+
function toPropsRefs(obj, ...args) {
|
|
46
|
+
const _res = {};
|
|
47
|
+
args.forEach((key) => {
|
|
48
|
+
_res[key] = toRef(obj, key);
|
|
49
|
+
});
|
|
50
|
+
return _res;
|
|
24
51
|
}
|
|
25
|
-
function
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
52
|
+
function removeUndefined(obj) {
|
|
53
|
+
const res = {};
|
|
54
|
+
Object.keys(obj).forEach((key) => {
|
|
55
|
+
const value = obj[key];
|
|
56
|
+
if (value !== void 0) {
|
|
57
|
+
res[key] = value;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
return res;
|
|
31
61
|
}
|
|
32
62
|
export {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
63
|
+
filterEmpty,
|
|
64
|
+
flattenChildren,
|
|
65
|
+
isEmptyElement,
|
|
66
|
+
removeUndefined,
|
|
67
|
+
skipFlattenKey,
|
|
68
|
+
toPropsRefs
|
|
39
69
|
};
|
package/dist/raf.cjs
CHANGED
|
@@ -1 +1,48 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
let raf = (callback) => +setTimeout(callback, 16);
|
|
4
|
+
let caf = (num) => clearTimeout(num);
|
|
5
|
+
if (typeof window !== "undefined" && "requestAnimationFrame" in window) {
|
|
6
|
+
raf = (callback) => window.requestAnimationFrame(callback);
|
|
7
|
+
caf = (handle) => window.cancelAnimationFrame(handle);
|
|
8
|
+
}
|
|
9
|
+
let rafUUID = 0;
|
|
10
|
+
const rafIds = /* @__PURE__ */ new Map();
|
|
11
|
+
function cleanup(id) {
|
|
12
|
+
rafIds.delete(id);
|
|
13
|
+
}
|
|
14
|
+
function wrapperRaf(callback, times = 1) {
|
|
15
|
+
rafUUID += 1;
|
|
16
|
+
const id = rafUUID;
|
|
17
|
+
function callRef(leftTimes) {
|
|
18
|
+
if (leftTimes === 0) {
|
|
19
|
+
cleanup(id);
|
|
20
|
+
callback();
|
|
21
|
+
} else {
|
|
22
|
+
const realId = raf(() => {
|
|
23
|
+
callRef(leftTimes - 1);
|
|
24
|
+
});
|
|
25
|
+
rafIds.set(id, realId);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
callRef(times);
|
|
29
|
+
return id;
|
|
30
|
+
}
|
|
31
|
+
wrapperRaf.cancel = (id) => {
|
|
32
|
+
const realId = rafIds.get(id);
|
|
33
|
+
cleanup(id);
|
|
34
|
+
return caf(realId);
|
|
35
|
+
};
|
|
36
|
+
if (process.env.NODE_ENV !== "production")
|
|
37
|
+
wrapperRaf.ids = () => rafIds;
|
|
38
|
+
function rafDebounce(fn) {
|
|
39
|
+
let id = null;
|
|
40
|
+
return () => {
|
|
41
|
+
if (id !== null) {
|
|
42
|
+
wrapperRaf.cancel(id);
|
|
43
|
+
}
|
|
44
|
+
id = wrapperRaf(fn);
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
exports.default = wrapperRaf;
|
|
48
|
+
exports.rafDebounce = rafDebounce;
|
package/dist/raf.js
CHANGED
|
@@ -1,37 +1,48 @@
|
|
|
1
|
-
let
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
a.delete(e);
|
|
1
|
+
let raf = (callback) => +setTimeout(callback, 16);
|
|
2
|
+
let caf = (num) => clearTimeout(num);
|
|
3
|
+
if (typeof window !== "undefined" && "requestAnimationFrame" in window) {
|
|
4
|
+
raf = (callback) => window.requestAnimationFrame(callback);
|
|
5
|
+
caf = (handle) => window.cancelAnimationFrame(handle);
|
|
7
6
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
let rafUUID = 0;
|
|
8
|
+
const rafIds = /* @__PURE__ */ new Map();
|
|
9
|
+
function cleanup(id) {
|
|
10
|
+
rafIds.delete(id);
|
|
11
|
+
}
|
|
12
|
+
function wrapperRaf(callback, times = 1) {
|
|
13
|
+
rafUUID += 1;
|
|
14
|
+
const id = rafUUID;
|
|
15
|
+
function callRef(leftTimes) {
|
|
16
|
+
if (leftTimes === 0) {
|
|
17
|
+
cleanup(id);
|
|
18
|
+
callback();
|
|
19
|
+
} else {
|
|
20
|
+
const realId = raf(() => {
|
|
21
|
+
callRef(leftTimes - 1);
|
|
17
22
|
});
|
|
18
|
-
|
|
23
|
+
rafIds.set(id, realId);
|
|
19
24
|
}
|
|
20
25
|
}
|
|
21
|
-
|
|
26
|
+
callRef(times);
|
|
27
|
+
return id;
|
|
22
28
|
}
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
29
|
+
wrapperRaf.cancel = (id) => {
|
|
30
|
+
const realId = rafIds.get(id);
|
|
31
|
+
cleanup(id);
|
|
32
|
+
return caf(realId);
|
|
26
33
|
};
|
|
27
|
-
process.env.NODE_ENV !== "production"
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
if (process.env.NODE_ENV !== "production")
|
|
35
|
+
wrapperRaf.ids = () => rafIds;
|
|
36
|
+
function rafDebounce(fn) {
|
|
37
|
+
let id = null;
|
|
30
38
|
return () => {
|
|
31
|
-
|
|
39
|
+
if (id !== null) {
|
|
40
|
+
wrapperRaf.cancel(id);
|
|
41
|
+
}
|
|
42
|
+
id = wrapperRaf(fn);
|
|
32
43
|
};
|
|
33
44
|
}
|
|
34
45
|
export {
|
|
35
|
-
|
|
36
|
-
|
|
46
|
+
wrapperRaf as default,
|
|
47
|
+
rafDebounce
|
|
37
48
|
};
|
package/dist/setStyle.cjs
CHANGED
|
@@ -1 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
function setStyle(style, options = {}) {
|
|
4
|
+
if (!style)
|
|
5
|
+
return {};
|
|
6
|
+
const { element = document.body } = options;
|
|
7
|
+
const oldStyle = {};
|
|
8
|
+
const styleKeys = Object.keys(style);
|
|
9
|
+
styleKeys.forEach((key) => {
|
|
10
|
+
oldStyle[key] = element.style[key];
|
|
11
|
+
});
|
|
12
|
+
styleKeys.forEach((key) => {
|
|
13
|
+
element.style[key] = style[key];
|
|
14
|
+
});
|
|
15
|
+
return oldStyle;
|
|
16
|
+
}
|
|
17
|
+
exports.default = setStyle;
|
package/dist/setStyle.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
function
|
|
2
|
-
if (!
|
|
1
|
+
function setStyle(style, options = {}) {
|
|
2
|
+
if (!style)
|
|
3
3
|
return {};
|
|
4
|
-
const { element
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
})
|
|
4
|
+
const { element = document.body } = options;
|
|
5
|
+
const oldStyle = {};
|
|
6
|
+
const styleKeys = Object.keys(style);
|
|
7
|
+
styleKeys.forEach((key) => {
|
|
8
|
+
oldStyle[key] = element.style[key];
|
|
9
|
+
});
|
|
10
|
+
styleKeys.forEach((key) => {
|
|
11
|
+
element.style[key] = style[key];
|
|
12
|
+
});
|
|
13
|
+
return oldStyle;
|
|
10
14
|
}
|
|
11
15
|
export {
|
|
12
|
-
|
|
16
|
+
setStyle as default
|
|
13
17
|
};
|
|
@@ -1 +1,38 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const getScrollBarSize = require("./getScrollBarSize.cjs");
|
|
4
|
+
const setStyle = require("./setStyle.cjs");
|
|
5
|
+
function isBodyOverflowing() {
|
|
6
|
+
return document.body.scrollHeight > (window.innerHeight || document.documentElement.clientHeight) && window.innerWidth > document.body.offsetWidth;
|
|
7
|
+
}
|
|
8
|
+
let cacheStyle = {};
|
|
9
|
+
const switchScrollingEffect = (close) => {
|
|
10
|
+
if (!isBodyOverflowing() && !close)
|
|
11
|
+
return;
|
|
12
|
+
const scrollingEffectClassName = "ant-scrolling-effect";
|
|
13
|
+
const scrollingEffectClassNameReg = new RegExp(
|
|
14
|
+
`${scrollingEffectClassName}`,
|
|
15
|
+
"g"
|
|
16
|
+
);
|
|
17
|
+
const bodyClassName = document.body.className;
|
|
18
|
+
if (close) {
|
|
19
|
+
if (!scrollingEffectClassNameReg.test(bodyClassName))
|
|
20
|
+
return;
|
|
21
|
+
setStyle.default(cacheStyle);
|
|
22
|
+
cacheStyle = {};
|
|
23
|
+
document.body.className = bodyClassName.replace(scrollingEffectClassNameReg, "").trim();
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const scrollBarSize = getScrollBarSize.default();
|
|
27
|
+
if (scrollBarSize) {
|
|
28
|
+
cacheStyle = setStyle.default({
|
|
29
|
+
position: "relative",
|
|
30
|
+
width: `calc(100% - ${scrollBarSize}px)`
|
|
31
|
+
});
|
|
32
|
+
if (!scrollingEffectClassNameReg.test(bodyClassName)) {
|
|
33
|
+
const addClassName = `${bodyClassName} ${scrollingEffectClassName}`;
|
|
34
|
+
document.body.className = addClassName.trim();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
exports.default = switchScrollingEffect;
|
|
@@ -1,31 +1,38 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
function
|
|
1
|
+
import getScrollBarSize from "./getScrollBarSize.js";
|
|
2
|
+
import setStyle from "./setStyle.js";
|
|
3
|
+
function isBodyOverflowing() {
|
|
4
4
|
return document.body.scrollHeight > (window.innerHeight || document.documentElement.clientHeight) && window.innerWidth > document.body.offsetWidth;
|
|
5
5
|
}
|
|
6
|
-
let
|
|
7
|
-
const
|
|
8
|
-
if (!
|
|
6
|
+
let cacheStyle = {};
|
|
7
|
+
const switchScrollingEffect = (close) => {
|
|
8
|
+
if (!isBodyOverflowing() && !close)
|
|
9
9
|
return;
|
|
10
|
-
const
|
|
11
|
-
|
|
10
|
+
const scrollingEffectClassName = "ant-scrolling-effect";
|
|
11
|
+
const scrollingEffectClassNameReg = new RegExp(
|
|
12
|
+
`${scrollingEffectClassName}`,
|
|
12
13
|
"g"
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
);
|
|
15
|
+
const bodyClassName = document.body.className;
|
|
16
|
+
if (close) {
|
|
17
|
+
if (!scrollingEffectClassNameReg.test(bodyClassName))
|
|
16
18
|
return;
|
|
17
|
-
|
|
19
|
+
setStyle(cacheStyle);
|
|
20
|
+
cacheStyle = {};
|
|
21
|
+
document.body.className = bodyClassName.replace(scrollingEffectClassNameReg, "").trim();
|
|
18
22
|
return;
|
|
19
23
|
}
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
const scrollBarSize = getScrollBarSize();
|
|
25
|
+
if (scrollBarSize) {
|
|
26
|
+
cacheStyle = setStyle({
|
|
27
|
+
position: "relative",
|
|
28
|
+
width: `calc(100% - ${scrollBarSize}px)`
|
|
29
|
+
});
|
|
30
|
+
if (!scrollingEffectClassNameReg.test(bodyClassName)) {
|
|
31
|
+
const addClassName = `${bodyClassName} ${scrollingEffectClassName}`;
|
|
32
|
+
document.body.className = addClassName.trim();
|
|
33
|
+
}
|
|
27
34
|
}
|
|
28
35
|
};
|
|
29
36
|
export {
|
|
30
|
-
|
|
37
|
+
switchScrollingEffect as default
|
|
31
38
|
};
|
package/dist/test/domHook.cjs
CHANGED
|
@@ -1 +1,52 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const NO_EXIST = { __NOT_EXIST: true };
|
|
4
|
+
function spyElementPrototypes(elementClass, properties) {
|
|
5
|
+
const propNames = Object.keys(properties);
|
|
6
|
+
const originDescriptors = {};
|
|
7
|
+
propNames.forEach((propName) => {
|
|
8
|
+
const originDescriptor = Object.getOwnPropertyDescriptor(elementClass.prototype, propName);
|
|
9
|
+
originDescriptors[propName] = originDescriptor || NO_EXIST;
|
|
10
|
+
const spyProp = properties[propName];
|
|
11
|
+
if (typeof spyProp === "function") {
|
|
12
|
+
elementClass.prototype[propName] = function spyFunc(...args) {
|
|
13
|
+
return spyProp.call(this, originDescriptor, ...args);
|
|
14
|
+
};
|
|
15
|
+
} else {
|
|
16
|
+
Object.defineProperty(elementClass.prototype, propName, {
|
|
17
|
+
...spyProp,
|
|
18
|
+
set(value) {
|
|
19
|
+
if (spyProp.set)
|
|
20
|
+
return spyProp.set.call(this, originDescriptor, value);
|
|
21
|
+
return originDescriptor.set(value);
|
|
22
|
+
},
|
|
23
|
+
get() {
|
|
24
|
+
if (spyProp.get)
|
|
25
|
+
return spyProp.get.call(this, originDescriptor);
|
|
26
|
+
return originDescriptor.get();
|
|
27
|
+
},
|
|
28
|
+
configurable: true
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
return {
|
|
33
|
+
mockRestore() {
|
|
34
|
+
propNames.forEach((propName) => {
|
|
35
|
+
const originDescriptor = originDescriptors[propName];
|
|
36
|
+
if (originDescriptor === NO_EXIST)
|
|
37
|
+
delete elementClass.prototype[propName];
|
|
38
|
+
else if (typeof originDescriptor === "function")
|
|
39
|
+
elementClass.prototype[propName] = originDescriptor;
|
|
40
|
+
else
|
|
41
|
+
Object.defineProperty(elementClass.prototype, propName, originDescriptor);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function spyElementPrototype(Element, propName, property) {
|
|
47
|
+
return spyElementPrototypes(Element, {
|
|
48
|
+
[propName]: property
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
exports.spyElementPrototype = spyElementPrototype;
|
|
52
|
+
exports.spyElementPrototypes = spyElementPrototypes;
|
package/dist/test/domHook.js
CHANGED
|
@@ -1,37 +1,52 @@
|
|
|
1
|
-
const
|
|
2
|
-
function
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
const NO_EXIST = { __NOT_EXIST: true };
|
|
2
|
+
function spyElementPrototypes(elementClass, properties) {
|
|
3
|
+
const propNames = Object.keys(properties);
|
|
4
|
+
const originDescriptors = {};
|
|
5
|
+
propNames.forEach((propName) => {
|
|
6
|
+
const originDescriptor = Object.getOwnPropertyDescriptor(elementClass.prototype, propName);
|
|
7
|
+
originDescriptors[propName] = originDescriptor || NO_EXIST;
|
|
8
|
+
const spyProp = properties[propName];
|
|
9
|
+
if (typeof spyProp === "function") {
|
|
10
|
+
elementClass.prototype[propName] = function spyFunc(...args) {
|
|
11
|
+
return spyProp.call(this, originDescriptor, ...args);
|
|
12
|
+
};
|
|
13
|
+
} else {
|
|
14
|
+
Object.defineProperty(elementClass.prototype, propName, {
|
|
15
|
+
...spyProp,
|
|
16
|
+
set(value) {
|
|
17
|
+
if (spyProp.set)
|
|
18
|
+
return spyProp.set.call(this, originDescriptor, value);
|
|
19
|
+
return originDescriptor.set(value);
|
|
20
|
+
},
|
|
21
|
+
get() {
|
|
22
|
+
if (spyProp.get)
|
|
23
|
+
return spyProp.get.call(this, originDescriptor);
|
|
24
|
+
return originDescriptor.get();
|
|
25
|
+
},
|
|
26
|
+
configurable: true
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
21
31
|
mockRestore() {
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
32
|
+
propNames.forEach((propName) => {
|
|
33
|
+
const originDescriptor = originDescriptors[propName];
|
|
34
|
+
if (originDescriptor === NO_EXIST)
|
|
35
|
+
delete elementClass.prototype[propName];
|
|
36
|
+
else if (typeof originDescriptor === "function")
|
|
37
|
+
elementClass.prototype[propName] = originDescriptor;
|
|
38
|
+
else
|
|
39
|
+
Object.defineProperty(elementClass.prototype, propName, originDescriptor);
|
|
25
40
|
});
|
|
26
41
|
}
|
|
27
42
|
};
|
|
28
43
|
}
|
|
29
|
-
function
|
|
30
|
-
return
|
|
31
|
-
[
|
|
44
|
+
function spyElementPrototype(Element, propName, property) {
|
|
45
|
+
return spyElementPrototypes(Element, {
|
|
46
|
+
[propName]: property
|
|
32
47
|
});
|
|
33
48
|
}
|
|
34
49
|
export {
|
|
35
|
-
|
|
36
|
-
|
|
50
|
+
spyElementPrototype,
|
|
51
|
+
spyElementPrototypes
|
|
37
52
|
};
|