@v-c/util 0.0.12 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/dist/Children/isFragment.cjs +7 -1
  2. package/dist/Children/isFragment.js +4 -4
  3. package/dist/Children/toArray.cjs +20 -1
  4. package/dist/Children/toArray.js +17 -8
  5. package/dist/Dom/addEventListener.cjs +13 -1
  6. package/dist/Dom/addEventListener.js +7 -5
  7. package/dist/Dom/canUseDom.cjs +6 -1
  8. package/dist/Dom/canUseDom.js +3 -3
  9. package/dist/Dom/class.cjs +29 -1
  10. package/dist/Dom/class.js +23 -13
  11. package/dist/Dom/contains.cjs +16 -1
  12. package/dist/Dom/contains.js +12 -12
  13. package/dist/Dom/css.cjs +96 -1
  14. package/dist/Dom/css.js +69 -48
  15. package/dist/Dom/dynamicCSS.cjs +110 -1
  16. package/dist/Dom/dynamicCSS.js +92 -59
  17. package/dist/Dom/findDOMNode.cjs +16 -1
  18. package/dist/Dom/findDOMNode.js +12 -8
  19. package/dist/Dom/focus.cjs +60 -1
  20. package/dist/Dom/focus.js +48 -28
  21. package/dist/Dom/isVisible.cjs +22 -1
  22. package/dist/Dom/isVisible.js +16 -16
  23. package/dist/Dom/scrollLocker.cjs +89 -1
  24. package/dist/Dom/scrollLocker.js +70 -45
  25. package/dist/Dom/shadow.cjs +13 -1
  26. package/dist/Dom/shadow.js +8 -8
  27. package/dist/Dom/styleChecker.cjs +25 -1
  28. package/dist/Dom/styleChecker.js +19 -14
  29. package/dist/Dom/support.cjs +28 -1
  30. package/dist/Dom/support.js +16 -12
  31. package/dist/KeyCode.cjs +523 -1
  32. package/dist/KeyCode.js +62 -55
  33. package/dist/Portal.cjs +48 -1
  34. package/dist/Portal.js +34 -19
  35. package/dist/PortalWrapper.cjs +169 -1
  36. package/dist/PortalWrapper.js +133 -79
  37. package/dist/classnames.cjs +45 -1
  38. package/dist/classnames.js +38 -25
  39. package/dist/composeProps.cjs +19 -1
  40. package/dist/composeProps.js +15 -9
  41. package/dist/createRef.cjs +24 -1
  42. package/dist/createRef.js +16 -13
  43. package/dist/debug/diff.cjs +50 -1
  44. package/dist/debug/diff.js +39 -30
  45. package/dist/deprecated.cjs +10 -1
  46. package/dist/deprecated.js +7 -5
  47. package/dist/getScrollBarSize.cjs +51 -1
  48. package/dist/getScrollBarSize.js +39 -25
  49. package/dist/guid.cjs +7 -1
  50. package/dist/guid.js +4 -4
  51. package/dist/hooks/useEvent.cjs +6 -1
  52. package/dist/hooks/useEvent.js +3 -3
  53. package/dist/hooks/useId.cjs +18 -1
  54. package/dist/hooks/useId.js +14 -8
  55. package/dist/hooks/useLayoutEffect.cjs +58 -1
  56. package/dist/hooks/useLayoutEffect.js +50 -20
  57. package/dist/hooks/useMemo.cjs +16 -1
  58. package/dist/hooks/useMemo.js +13 -7
  59. package/dist/hooks/useMergedState.cjs +30 -1
  60. package/dist/hooks/useMergedState.js +25 -16
  61. package/dist/hooks/useMobile.cjs +16 -1
  62. package/dist/hooks/useMobile.js +13 -11
  63. package/dist/hooks/useState.cjs +12 -1
  64. package/dist/hooks/useState.js +8 -7
  65. package/dist/index.cjs +11 -1
  66. package/dist/index.js +9 -9
  67. package/dist/isEqual.cjs +36 -1
  68. package/dist/isEqual.js +30 -26
  69. package/dist/isMobile.cjs +13 -1
  70. package/dist/isMobile.js +7 -7
  71. package/dist/isValid.cjs +6 -1
  72. package/dist/isValid.js +3 -3
  73. package/dist/omit.cjs +12 -1
  74. package/dist/omit.js +9 -6
  75. package/dist/pickAttrs.cjs +41 -3
  76. package/dist/pickAttrs.js +37 -22
  77. package/dist/props-util/index.cjs +69 -1
  78. package/dist/props-util/index.js +62 -32
  79. package/dist/raf.cjs +48 -1
  80. package/dist/raf.js +37 -26
  81. package/dist/setStyle.cjs +17 -1
  82. package/dist/setStyle.js +13 -9
  83. package/dist/switchScrollingEffect.cjs +38 -1
  84. package/dist/switchScrollingEffect.js +27 -20
  85. package/dist/test/domHook.cjs +52 -1
  86. package/dist/test/domHook.js +43 -28
  87. package/dist/type.cjs +51 -1
  88. package/dist/type.js +39 -37
  89. package/dist/utils/checkSlotProp.cjs +13 -1
  90. package/dist/utils/checkSlotProp.js +10 -3
  91. package/dist/utils/get.cjs +12 -1
  92. package/dist/utils/get.js +8 -8
  93. package/dist/utils/omit.cjs +10 -1
  94. package/dist/utils/omit.js +7 -6
  95. package/dist/utils/set.cjs +64 -1
  96. package/dist/utils/set.js +54 -32
  97. package/dist/utils/transition.cjs +96 -1
  98. package/dist/utils/transition.d.ts +2 -2
  99. package/dist/utils/transition.js +70 -65
  100. package/dist/utils/watchState.cjs +20 -1
  101. package/dist/utils/watchState.js +15 -10
  102. package/dist/vnode.cjs +56 -1
  103. package/dist/vnode.js +46 -30
  104. package/dist/vueuse/unref-element.cjs +8 -1
  105. package/dist/vueuse/unref-element.js +5 -5
  106. package/dist/warning.cjs +53 -1
  107. package/dist/warning.js +40 -35
  108. package/package.json +1 -1
package/dist/pickAttrs.js CHANGED
@@ -1,4 +1,4 @@
1
- const s = `accept acceptCharset accessKey action allowFullScreen allowTransparency
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`, i = `onCopy onCut onPaste onCompositionEnd onCompositionStart onCompositionUpdate onKeyDown
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`, l = `${s} ${i}`.split(/\s+/), c = "aria-", d = "data-";
19
- function r(a, n) {
20
- return a.indexOf(n) === 0;
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 u(a, n = !1) {
23
- let e;
24
- n === !1 ? e = {
25
- aria: !0,
26
- data: !0,
27
- attr: !0
28
- } : n === !0 ? e = {
29
- aria: !0
30
- } : e = {
31
- ...n
32
- };
33
- const t = {};
34
- return Object.keys(a).forEach((o) => {
35
- // Aria
36
- (e.aria && (o === "role" || r(o, c)) || e.data && r(o, d) || e.attr && l.includes(o)) && (t[o] = a[o]);
37
- }), t;
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
- u as default
55
+ pickAttrs as default
41
56
  };
@@ -1 +1,69 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("vue"),i=require("../isValid.cjs");function u(e){return e&&(e.type===o.Comment||e.type===o.Fragment&&e.children.length===0||e.type===o.Text&&e.children.trim()==="")}function a(e=[]){const t=[];return e.forEach(r=>{Array.isArray(r)?t.push(...r):r?.type===o.Fragment?t.push(...a(r.children)):t.push(r)}),t.filter(r=>!u(r))}const p=Symbol("skipFlatten");function f(e,t=!0){const r=Array.isArray(e)?e:[e],s=[];return r.forEach(n=>{Array.isArray(n)?s.push(...f(n,t)):i.default(n)?s.push(n):n&&typeof n=="object"&&n.type===o.Fragment?n.key===p?s.push(n):s.push(...f(n.children,t)):n&&o.isVNode(n)&&(t&&!u(n)?s.push(n):t||s.push(n))}),t?a(s):s}function y(e,...t){const r={};return t.forEach(s=>{r[s]=o.toRef(e,s)}),r}function m(e){const t={};return Object.keys(e).forEach(r=>{const s=e[r];s!==void 0&&(t[r]=s)}),t}exports.filterEmpty=a;exports.flattenChildren=f;exports.isEmptyElement=u;exports.removeUndefined=m;exports.skipFlattenKey=p;exports.toPropsRefs=y;
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;
@@ -1,39 +1,69 @@
1
- import { Comment as a, Fragment as o, Text as y, isVNode as m, toRef as i } from "vue";
2
- import A from "../isValid.js";
3
- function u(e) {
4
- return e && (e.type === a || e.type === o && e.children.length === 0 || e.type === y && e.children.trim() === "");
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 p(e = []) {
7
- const r = [];
8
- return e.forEach((t) => {
9
- Array.isArray(t) ? r.push(...t) : t?.type === o ? r.push(...p(t.children)) : r.push(t);
10
- }), r.filter((t) => !u(t));
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 v = Symbol("skipFlatten");
13
- function f(e, r = !0) {
14
- const t = Array.isArray(e) ? e : [e], s = [];
15
- return t.forEach((n) => {
16
- Array.isArray(n) ? s.push(...f(n, r)) : A(n) ? s.push(n) : n && typeof n == "object" && n.type === o ? n.key === v ? s.push(n) : s.push(...f(n.children, r)) : n && m(n) && (r && !u(n) ? s.push(n) : r || s.push(n));
17
- }), r ? p(s) : s;
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 g(e, ...r) {
20
- const t = {};
21
- return r.forEach((s) => {
22
- t[s] = i(e, s);
23
- }), t;
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 k(e) {
26
- const r = {};
27
- return Object.keys(e).forEach((t) => {
28
- const s = e[t];
29
- s !== void 0 && (r[t] = s);
30
- }), r;
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
- p as filterEmpty,
34
- f as flattenChildren,
35
- u as isEmptyElement,
36
- k as removeUndefined,
37
- v as skipFlattenKey,
38
- g as toPropsRefs
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";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});let c=e=>+setTimeout(e,16),l=e=>clearTimeout(e);typeof window<"u"&&"requestAnimationFrame"in window&&(c=e=>window.requestAnimationFrame(e),l=e=>window.cancelAnimationFrame(e));let u=0;const i=new Map;function f(e){i.delete(e)}function t(e,n=1){u+=1;const o=u;function r(a){if(a===0)f(o),e();else{const d=c(()=>{r(a-1)});i.set(o,d)}}return r(n),o}t.cancel=e=>{const n=i.get(e);return f(e),l(n)};process.env.NODE_ENV!=="production"&&(t.ids=()=>i);function s(e){let n=null;return()=>{n!==null&&t.cancel(n),n=t(e)}}exports.default=t;exports.rafDebounce=s;
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 l = (e) => +setTimeout(e, 16), u = (e) => clearTimeout(e);
2
- typeof window < "u" && "requestAnimationFrame" in window && (l = (e) => window.requestAnimationFrame(e), u = (e) => window.cancelAnimationFrame(e));
3
- let c = 0;
4
- const a = /* @__PURE__ */ new Map();
5
- function f(e) {
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
- function t(e, n = 1) {
9
- c += 1;
10
- const i = c;
11
- function o(r) {
12
- if (r === 0)
13
- f(i), e();
14
- else {
15
- const d = l(() => {
16
- o(r - 1);
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
- a.set(i, d);
23
+ rafIds.set(id, realId);
19
24
  }
20
25
  }
21
- return o(n), i;
26
+ callRef(times);
27
+ return id;
22
28
  }
23
- t.cancel = (e) => {
24
- const n = a.get(e);
25
- return f(e), u(n);
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" && (t.ids = () => a);
28
- function s(e) {
29
- let n = null;
34
+ if (process.env.NODE_ENV !== "production")
35
+ wrapperRaf.ids = () => rafIds;
36
+ function rafDebounce(fn) {
37
+ let id = null;
30
38
  return () => {
31
- n !== null && t.cancel(n), n = t(e);
39
+ if (id !== null) {
40
+ wrapperRaf.cancel(id);
41
+ }
42
+ id = wrapperRaf(fn);
32
43
  };
33
44
  }
34
45
  export {
35
- t as default,
36
- s as rafDebounce
46
+ wrapperRaf as default,
47
+ rafDebounce
37
48
  };
package/dist/setStyle.cjs CHANGED
@@ -1 +1,17 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function s(t,r={}){if(!t)return{};const{element:o=document.body}=r,l={},n=Object.keys(t);return n.forEach(e=>{l[e]=o.style[e]}),n.forEach(e=>{o.style[e]=t[e]}),l}exports.default=s;
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 r(e, s = {}) {
2
- if (!e)
1
+ function setStyle(style, options = {}) {
2
+ if (!style)
3
3
  return {};
4
- const { element: o = document.body } = s, n = {}, c = Object.keys(e);
5
- return c.forEach((t) => {
6
- n[t] = o.style[t];
7
- }), c.forEach((t) => {
8
- o.style[t] = e[t];
9
- }), n;
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
- r as default
16
+ setStyle as default
13
17
  };
@@ -1 +1,38 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("./getScrollBarSize.cjs"),i=require("./setStyle.cjs");function a(){return document.body.scrollHeight>(window.innerHeight||document.documentElement.clientHeight)&&window.innerWidth>document.body.offsetWidth}let o={};const d=n=>{if(!a()&&!n)return;const c="ant-scrolling-effect",t=new RegExp(`${c}`,"g"),e=document.body.className;if(n){if(!t.test(e))return;i.default(o),o={},document.body.className=e.replace(t,"").trim();return}const l=r.default();if(l&&(o=i.default({position:"relative",width:`calc(100% - ${l}px)`}),!t.test(e))){const s=`${e} ${c}`;document.body.className=s.trim()}};exports.default=d;
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 r from "./getScrollBarSize.js";
2
- import s from "./setStyle.js";
3
- function a() {
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 o = {};
7
- const f = (n) => {
8
- if (!a() && !n)
6
+ let cacheStyle = {};
7
+ const switchScrollingEffect = (close) => {
8
+ if (!isBodyOverflowing() && !close)
9
9
  return;
10
- const c = "ant-scrolling-effect", t = new RegExp(
11
- `${c}`,
10
+ const scrollingEffectClassName = "ant-scrolling-effect";
11
+ const scrollingEffectClassNameReg = new RegExp(
12
+ `${scrollingEffectClassName}`,
12
13
  "g"
13
- ), e = document.body.className;
14
- if (n) {
15
- if (!t.test(e))
14
+ );
15
+ const bodyClassName = document.body.className;
16
+ if (close) {
17
+ if (!scrollingEffectClassNameReg.test(bodyClassName))
16
18
  return;
17
- s(o), o = {}, document.body.className = e.replace(t, "").trim();
19
+ setStyle(cacheStyle);
20
+ cacheStyle = {};
21
+ document.body.className = bodyClassName.replace(scrollingEffectClassNameReg, "").trim();
18
22
  return;
19
23
  }
20
- const i = r();
21
- if (i && (o = s({
22
- position: "relative",
23
- width: `calc(100% - ${i}px)`
24
- }), !t.test(e))) {
25
- const l = `${e} ${c}`;
26
- document.body.className = l.trim();
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
- f as default
37
+ switchScrollingEffect as default
31
38
  };
@@ -1 +1,52 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s={__NOT_EXIST:!0};function p(o,n){const c=Object.keys(n),y={};return c.forEach(e=>{const t=Object.getOwnPropertyDescriptor(o.prototype,e);y[e]=t||s;const r=n[e];typeof r=="function"?o.prototype[e]=function(...f){return r.call(this,t,...f)}:Object.defineProperty(o.prototype,e,{...r,set(i){return r.set?r.set.call(this,t,i):t.set(i)},get(){return r.get?r.get.call(this,t):t.get()},configurable:!0})}),{mockRestore(){c.forEach(e=>{const t=y[e];t===s?delete o.prototype[e]:typeof t=="function"?o.prototype[e]=t:Object.defineProperty(o.prototype,e,t)})}}}function u(o,n,c){return p(o,{[n]:c})}exports.spyElementPrototype=u;exports.spyElementPrototypes=p;
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;
@@ -1,37 +1,52 @@
1
- const y = { __NOT_EXIST: !0 };
2
- function p(r, n) {
3
- const c = Object.keys(n), s = {};
4
- return c.forEach((o) => {
5
- const t = Object.getOwnPropertyDescriptor(r.prototype, o);
6
- s[o] = t || y;
7
- const e = n[o];
8
- typeof e == "function" ? r.prototype[o] = function(...f) {
9
- return e.call(this, t, ...f);
10
- } : Object.defineProperty(r.prototype, o, {
11
- ...e,
12
- set(i) {
13
- return e.set ? e.set.call(this, t, i) : t.set(i);
14
- },
15
- get() {
16
- return e.get ? e.get.call(this, t) : t.get();
17
- },
18
- configurable: !0
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
- c.forEach((o) => {
23
- const t = s[o];
24
- t === y ? delete r.prototype[o] : typeof t == "function" ? r.prototype[o] = t : Object.defineProperty(r.prototype, o, t);
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 u(r, n, c) {
30
- return p(r, {
31
- [n]: c
44
+ function spyElementPrototype(Element, propName, property) {
45
+ return spyElementPrototypes(Element, {
46
+ [propName]: property
32
47
  });
33
48
  }
34
49
  export {
35
- u as spyElementPrototype,
36
- p as spyElementPrototypes
50
+ spyElementPrototype,
51
+ spyElementPrototypes
37
52
  };