@aiszlab/relax 1.0.26 → 1.0.28

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.
@@ -0,0 +1 @@
1
+ export declare const useScrollLocker: (isLock?: boolean) => void;
@@ -0,0 +1,84 @@
1
+ import { __classPrivateFieldSet, __classPrivateFieldGet } from '../node_modules/tslib/tslib.es6.js';
2
+ import { useId, useLayoutEffect } from 'react';
3
+ import { isOverflow } from '../utils/is-overflow.js';
4
+ import { isStyleElement } from '../utils/is-style-element.js';
5
+
6
+ var _ScrollLocker_scrollLocker, _ScrollLocker_barSize;
7
+ const isComputable = (value) => /^(.*)px$/.test(value);
8
+ class ScrollLocker {
9
+ constructor() {
10
+ var _a;
11
+ // singleton mode
12
+ _ScrollLocker_scrollLocker.set(this, null
13
+ // bar size
14
+ );
15
+ // bar size
16
+ _ScrollLocker_barSize.set(this, null);
17
+ return (__classPrivateFieldSet(this, _ScrollLocker_scrollLocker, (_a = __classPrivateFieldGet(this, _ScrollLocker_scrollLocker, "f")) !== null && _a !== void 0 ? _a : this, "f"));
18
+ }
19
+ get barSize() {
20
+ var _a;
21
+ if (__classPrivateFieldGet(this, _ScrollLocker_barSize, "f"))
22
+ return __classPrivateFieldGet(this, _ScrollLocker_barSize, "f");
23
+ const { width, height } = getComputedStyle(document.body, '::-webkit-scrollbar');
24
+ return (__classPrivateFieldSet(this, _ScrollLocker_barSize, (_a = __classPrivateFieldGet(this, _ScrollLocker_barSize, "f")) !== null && _a !== void 0 ? _a : {
25
+ width: isComputable(width) ? width : '0',
26
+ height: isComputable(height) ? height : '0'
27
+ }, "f"));
28
+ }
29
+ get isOverflow() {
30
+ return isOverflow();
31
+ }
32
+ get locker() {
33
+ return `html body {
34
+ overflow-y: hidden;
35
+ ${this.isOverflow ? `width: calc(100% - ${this.barSize.width});` : ''}
36
+ }`;
37
+ }
38
+ get container() {
39
+ return document.head || document.body;
40
+ }
41
+ getLocked(id) {
42
+ return Array.from(this.container.children).filter((element) => isStyleElement(element)).find((element) => element.id === id);
43
+ }
44
+ lock(id) {
45
+ if (!this.container)
46
+ return;
47
+ const locked = this.getLocked(id);
48
+ if (locked) {
49
+ if (locked.innerHTML !== this.locker) {
50
+ locked.innerHTML = this.locker;
51
+ }
52
+ return locked;
53
+ }
54
+ const locker = document.createElement('style');
55
+ locker.id = id;
56
+ locker.innerHTML = this.locker;
57
+ this.container.appendChild(locker);
58
+ return locker;
59
+ }
60
+ unlock(id) {
61
+ const locked = this.getLocked(id);
62
+ if (!locked)
63
+ return;
64
+ this.container.removeChild(locked);
65
+ }
66
+ }
67
+ _ScrollLocker_scrollLocker = new WeakMap(), _ScrollLocker_barSize = new WeakMap();
68
+ const useScrollLocker = (isLock) => {
69
+ const id = useId();
70
+ useLayoutEffect(() => {
71
+ const scrollLocker = new ScrollLocker();
72
+ if (!!isLock) {
73
+ scrollLocker.lock(id);
74
+ }
75
+ else {
76
+ scrollLocker.unlock(id);
77
+ }
78
+ return () => {
79
+ scrollLocker.unlock(id);
80
+ };
81
+ }, [!!isLock, id]);
82
+ };
83
+
84
+ export { useScrollLocker };
package/dist/index.d.ts CHANGED
@@ -10,6 +10,7 @@ export { useMounted } from './hooks/use-mounted';
10
10
  export { useTimeout } from './hooks/use-timeout';
11
11
  export { useControlledState } from './hooks/use-controlled-state';
12
12
  export { useOnceState } from './hooks/use-once-state';
13
+ export { useScrollLocker } from './hooks/use-scroll-locker';
13
14
  /**
14
15
  * @description
15
16
  * utils
@@ -19,3 +20,9 @@ export { isUndefined } from './utils/is-undefined';
19
20
  export { isStateGetter } from './utils/is-state-getter';
20
21
  export { isNull } from './utils/is-null';
21
22
  export { isVoid } from './utils/is-void';
23
+ export { isArray } from './utils/is-array';
24
+ export { isEmpty } from './utils/is-empty';
25
+ export { isDomUsable } from './utils/is-dom-usable';
26
+ export { isMobile } from './utils/is-mobile';
27
+ export { isOverflow } from './utils/is-overflow';
28
+ export { isStyleElement } from './utils/is-style-element';
package/dist/index.js CHANGED
@@ -6,8 +6,15 @@ export { useMounted } from './hooks/use-mounted.js';
6
6
  export { useTimeout } from './hooks/use-timeout.js';
7
7
  export { useControlledState } from './hooks/use-controlled-state.js';
8
8
  export { useOnceState } from './hooks/use-once-state.js';
9
+ export { useScrollLocker } from './hooks/use-scroll-locker.js';
9
10
  export { isRefable } from './utils/is-refable.js';
10
11
  export { isUndefined } from './utils/is-undefined.js';
11
12
  export { isStateGetter } from './utils/is-state-getter.js';
12
13
  export { isNull } from './utils/is-null.js';
13
14
  export { isVoid } from './utils/is-void.js';
15
+ export { isArray } from './utils/is-array.js';
16
+ export { isEmpty } from './utils/is-empty.js';
17
+ export { isDomUsable } from './utils/is-dom-usable.js';
18
+ export { isMobile } from './utils/is-mobile.js';
19
+ export { isOverflow } from './utils/is-overflow.js';
20
+ export { isStyleElement } from './utils/is-style-element.js';
@@ -0,0 +1,17 @@
1
+ function __classPrivateFieldGet(receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ }
6
+ function __classPrivateFieldSet(receiver, state, value, kind, f) {
7
+ if (kind === "m") throw new TypeError("Private method is not writable");
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
+ return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
11
+ }
12
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
13
+ var e = new Error(message);
14
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
15
+ };
16
+
17
+ export { __classPrivateFieldGet, __classPrivateFieldSet };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @description
3
+ * is array
4
+ */
5
+ const isArray = (value) => {
6
+ return Array.isArray(value);
7
+ };
8
+
9
+ export { isArray };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @description
3
+ * if there is dom
4
+ */
5
+ export declare const isDomUsable: () => boolean;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @description
3
+ * if there is dom
4
+ */
5
+ const isDomUsable = () => {
6
+ return !!(typeof window !== 'undefined' && window.document && window.document.createElement);
7
+ };
8
+
9
+ export { isDomUsable };
@@ -0,0 +1,29 @@
1
+ import 'react';
2
+ import 'rxjs';
3
+ import '../hooks/use-scroll-locker.js';
4
+ import 'react-is';
5
+ import { isVoid } from './is-void.js';
6
+ import { isArray } from './is-array.js';
7
+
8
+ /**
9
+ * @author murukal
10
+ *
11
+ * @description
12
+ * is empty
13
+ */
14
+ const isEmpty = (value) => {
15
+ // null or undefined
16
+ if (isVoid(value))
17
+ return true;
18
+ // object
19
+ if (typeof value === 'object') {
20
+ return Object.keys(value).length === 0;
21
+ }
22
+ // array
23
+ if (isArray(value)) {
24
+ return value.length === 0;
25
+ }
26
+ return !!value;
27
+ };
28
+
29
+ export { isEmpty };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @description
3
+ * is mobile
4
+ */
5
+ export declare const isMobile: () => boolean;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @description
3
+ * is mobile
4
+ */
5
+ const isMobile = () => {
6
+ if (typeof navigator === 'undefined' || typeof window === 'undefined') {
7
+ return false;
8
+ }
9
+ const agent = navigator.userAgent ||
10
+ navigator.vendor ||
11
+ window.opera;
12
+ return (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(agent) ||
13
+ /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test(agent === null || agent === void 0 ? void 0 : agent.substring(0, 4)));
14
+ };
15
+
16
+ export { isMobile };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @description
3
+ * if is overflow
4
+ */
5
+ export declare function isOverflow(): boolean;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @description
3
+ * if is overflow
4
+ */
5
+ function isOverflow() {
6
+ return (document.body.scrollHeight > (window.innerHeight || document.documentElement.clientHeight) &&
7
+ window.innerWidth > document.body.offsetWidth);
8
+ }
9
+
10
+ export { isOverflow };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @description
3
+ * style element
4
+ */
5
+ export declare const isStyleElement: (element: Element) => element is HTMLStyleElement;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @description
3
+ * style element
4
+ */
5
+ const isStyleElement = (element) => {
6
+ return element.tagName === 'STYLE';
7
+ };
8
+
9
+ export { isStyleElement };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiszlab/relax",
3
- "version": "1.0.26",
3
+ "version": "1.0.28",
4
4
  "description": "react utils collection",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",