@bifrostui/utils 0.0.5

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 (107) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +13 -0
  3. package/dist/debounce.d.ts +1 -0
  4. package/dist/debounce.js +37 -0
  5. package/dist/domTarget.d.ts +7 -0
  6. package/dist/domTarget.js +42 -0
  7. package/dist/getBoundingClientRect/index.d.ts +1 -0
  8. package/dist/getBoundingClientRect/index.js +27 -0
  9. package/dist/getBoundingClientRect/index.miniapp.d.ts +2 -0
  10. package/dist/getBoundingClientRect/index.miniapp.js +43 -0
  11. package/dist/hex2rgba.d.ts +2 -0
  12. package/dist/hex2rgba.js +39 -0
  13. package/dist/hooks/index.d.ts +9 -0
  14. package/dist/hooks/index.js +60 -0
  15. package/dist/hooks/useDidMountEffect.d.ts +5 -0
  16. package/dist/hooks/useDidMountEffect.js +35 -0
  17. package/dist/hooks/useDomCss/index.d.ts +3 -0
  18. package/dist/hooks/useDomCss/index.js +48 -0
  19. package/dist/hooks/useDomCss/index.miniapp.d.ts +3 -0
  20. package/dist/hooks/useDomCss/index.miniapp.js +51 -0
  21. package/dist/hooks/useDomReady/index.d.ts +2 -0
  22. package/dist/hooks/useDomReady/index.js +41 -0
  23. package/dist/hooks/useDomReady/index.miniapp.d.ts +2 -0
  24. package/dist/hooks/useDomReady/index.miniapp.js +43 -0
  25. package/dist/hooks/useEventCallback.d.ts +6 -0
  26. package/dist/hooks/useEventCallback.js +42 -0
  27. package/dist/hooks/useForkRef.d.ts +2 -0
  28. package/dist/hooks/useForkRef.js +48 -0
  29. package/dist/hooks/useMemoizedFn.d.ts +3 -0
  30. package/dist/hooks/useMemoizedFn.js +55 -0
  31. package/dist/hooks/useSize.d.ts +7 -0
  32. package/dist/hooks/useSize.js +51 -0
  33. package/dist/hooks/useTouchEmulator.d.ts +1 -0
  34. package/dist/hooks/useTouchEmulator.js +111 -0
  35. package/dist/hooks/useValue.d.ts +12 -0
  36. package/dist/hooks/useValue.js +49 -0
  37. package/dist/index.d.ts +12 -0
  38. package/dist/index.js +96 -0
  39. package/dist/isDev.d.ts +2 -0
  40. package/dist/isDev.js +26 -0
  41. package/dist/isMini.d.ts +4 -0
  42. package/dist/isMini.js +35 -0
  43. package/dist/isType.d.ts +1 -0
  44. package/dist/isType.js +31 -0
  45. package/dist/setRef.d.ts +2 -0
  46. package/dist/setRef.js +31 -0
  47. package/dist/throttle.d.ts +6 -0
  48. package/dist/throttle.js +52 -0
  49. package/dist/toArray.d.ts +6 -0
  50. package/dist/toArray.js +52 -0
  51. package/dist/touchBlocker.d.ts +11 -0
  52. package/dist/touchBlocker.js +108 -0
  53. package/dist/transitions.d.ts +72 -0
  54. package/dist/transitions.js +91 -0
  55. package/es/debounce.d.ts +1 -0
  56. package/es/debounce.js +15 -0
  57. package/es/domTarget.d.ts +7 -0
  58. package/es/domTarget.js +14 -0
  59. package/es/getBoundingClientRect/index.d.ts +1 -0
  60. package/es/getBoundingClientRect/index.js +3 -0
  61. package/es/getBoundingClientRect/index.miniapp.d.ts +2 -0
  62. package/es/getBoundingClientRect/index.miniapp.js +17 -0
  63. package/es/hex2rgba.d.ts +2 -0
  64. package/es/hex2rgba.js +25 -0
  65. package/es/hooks/index.d.ts +9 -0
  66. package/es/hooks/index.js +9 -0
  67. package/es/hooks/useDidMountEffect.d.ts +5 -0
  68. package/es/hooks/useDidMountEffect.js +11 -0
  69. package/es/hooks/useDomCss/index.d.ts +3 -0
  70. package/es/hooks/useDomCss/index.js +14 -0
  71. package/es/hooks/useDomCss/index.miniapp.d.ts +3 -0
  72. package/es/hooks/useDomCss/index.miniapp.js +17 -0
  73. package/es/hooks/useDomReady/index.d.ts +2 -0
  74. package/es/hooks/useDomReady/index.js +7 -0
  75. package/es/hooks/useDomReady/index.miniapp.d.ts +2 -0
  76. package/es/hooks/useDomReady/index.miniapp.js +9 -0
  77. package/es/hooks/useEventCallback.d.ts +6 -0
  78. package/es/hooks/useEventCallback.js +18 -0
  79. package/es/hooks/useForkRef.d.ts +2 -0
  80. package/es/hooks/useForkRef.js +25 -0
  81. package/es/hooks/useMemoizedFn.d.ts +3 -0
  82. package/es/hooks/useMemoizedFn.js +25 -0
  83. package/es/hooks/useSize.d.ts +7 -0
  84. package/es/hooks/useSize.js +29 -0
  85. package/es/hooks/useTouchEmulator.d.ts +1 -0
  86. package/es/hooks/useTouchEmulator.js +146 -0
  87. package/es/hooks/useValue.d.ts +12 -0
  88. package/es/hooks/useValue.js +36 -0
  89. package/es/index.d.ts +12 -0
  90. package/es/index.js +12 -0
  91. package/es/isDev.d.ts +2 -0
  92. package/es/isDev.js +2 -0
  93. package/es/isMini.d.ts +4 -0
  94. package/es/isMini.js +4 -0
  95. package/es/isType.d.ts +1 -0
  96. package/es/isType.js +4 -0
  97. package/es/setRef.d.ts +2 -0
  98. package/es/setRef.js +7 -0
  99. package/es/throttle.d.ts +6 -0
  100. package/es/throttle.js +49 -0
  101. package/es/toArray.d.ts +6 -0
  102. package/es/toArray.js +19 -0
  103. package/es/touchBlocker.d.ts +11 -0
  104. package/es/touchBlocker.js +90 -0
  105. package/es/transitions.d.ts +72 -0
  106. package/es/transitions.js +65 -0
  107. package/package.json +32 -0
@@ -0,0 +1,48 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/hooks/useForkRef.ts
30
+ var useForkRef_exports = {};
31
+ __export(useForkRef_exports, {
32
+ default: () => useForkRef
33
+ });
34
+ module.exports = __toCommonJS(useForkRef_exports);
35
+ var React = __toESM(require("react"));
36
+ var import_setRef = __toESM(require("../setRef"));
37
+ function useForkRef(...refs) {
38
+ return React.useMemo(() => {
39
+ if (refs.every((ref) => ref == null)) {
40
+ return null;
41
+ }
42
+ return (instance) => {
43
+ refs.forEach((ref) => {
44
+ (0, import_setRef.default)(ref, instance);
45
+ });
46
+ };
47
+ }, refs);
48
+ }
@@ -0,0 +1,3 @@
1
+ type noop = (this: any, ...args: any[]) => any;
2
+ export default function useMemoizedFn<T extends noop>(fn: T): T;
3
+ export {};
@@ -0,0 +1,55 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/hooks/useMemoizedFn.ts
30
+ var useMemoizedFn_exports = {};
31
+ __export(useMemoizedFn_exports, {
32
+ default: () => useMemoizedFn
33
+ });
34
+ module.exports = __toCommonJS(useMemoizedFn_exports);
35
+ var import_react = require("react");
36
+ var import_isDev = __toESM(require("../isDev"));
37
+ var import_isType = require("../isType");
38
+ function useMemoizedFn(fn) {
39
+ if (import_isDev.default) {
40
+ if (!(0, import_isType.isFunction)(fn)) {
41
+ console.error(
42
+ `useMemoizedFn expected parameter is a function, got ${typeof fn}`
43
+ );
44
+ }
45
+ }
46
+ const fnRef = (0, import_react.useRef)(fn);
47
+ fnRef.current = (0, import_react.useMemo)(() => fn, [fn]);
48
+ const memoizedFn = (0, import_react.useRef)();
49
+ if (!memoizedFn.current) {
50
+ memoizedFn.current = function(...args) {
51
+ return fnRef.current.apply(this, args);
52
+ };
53
+ }
54
+ return memoizedFn.current;
55
+ }
@@ -0,0 +1,7 @@
1
+ import type { BasicTarget } from '../domTarget';
2
+ type Size = {
3
+ width: number;
4
+ height: number;
5
+ };
6
+ declare function useSize(target: BasicTarget): Size;
7
+ export default useSize;
@@ -0,0 +1,51 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/hooks/useSize.ts
30
+ var useSize_exports = {};
31
+ __export(useSize_exports, {
32
+ default: () => useSize_default
33
+ });
34
+ module.exports = __toCommonJS(useSize_exports);
35
+ var import_react = __toESM(require("react"));
36
+ var import_useDomReady = __toESM(require("./useDomReady"));
37
+ var import_getBoundingClientRect = __toESM(require("../getBoundingClientRect"));
38
+ var import_domTarget = require("../domTarget");
39
+ function useSize(target) {
40
+ const [state, setState] = import_react.default.useState({});
41
+ (0, import_useDomReady.default)(() => {
42
+ const el = (0, import_domTarget.getTargetElement)(target);
43
+ if (el) {
44
+ (0, import_getBoundingClientRect.default)(el).then((res) => {
45
+ setState({ width: res.width, height: res.height });
46
+ });
47
+ }
48
+ });
49
+ return state;
50
+ }
51
+ var useSize_default = useSize;
@@ -0,0 +1 @@
1
+ export default function useTouchEmulator(dom?: HTMLElement | Window): void;
@@ -0,0 +1,111 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/hooks/useTouchEmulator.ts
20
+ var useTouchEmulator_exports = {};
21
+ __export(useTouchEmulator_exports, {
22
+ default: () => useTouchEmulator
23
+ });
24
+ module.exports = __toCommonJS(useTouchEmulator_exports);
25
+ var import_react = require("react");
26
+ var eventTarget;
27
+ var Touch = function Touch2(target, identifier, pos, deltaX, deltaY) {
28
+ deltaX = deltaX || 0;
29
+ deltaY = deltaY || 0;
30
+ this.identifier = identifier;
31
+ this.target = target;
32
+ this.clientX = pos.clientX + deltaX;
33
+ this.clientY = pos.clientY + deltaY;
34
+ this.screenX = pos.screenX + deltaX;
35
+ this.screenY = pos.screenY + deltaY;
36
+ this.pageX = pos.pageX + deltaX;
37
+ this.pageY = pos.pageY + deltaY;
38
+ };
39
+ function TouchList() {
40
+ const touchList = [];
41
+ touchList.item = (index) => {
42
+ return this[index] || null;
43
+ };
44
+ touchList.identifiedTouch = (id) => {
45
+ return this[id + 1] || null;
46
+ };
47
+ return touchList;
48
+ }
49
+ var initiated = false;
50
+ function onMouse(touchType) {
51
+ return function(ev) {
52
+ if (ev.type === "mousedown") {
53
+ initiated = true;
54
+ }
55
+ if (ev.type === "mouseup") {
56
+ initiated = false;
57
+ }
58
+ if (ev.type === "mousemove" && !initiated) {
59
+ return;
60
+ }
61
+ if (ev.type === "mousedown" || !eventTarget || eventTarget && !eventTarget.dispatchEvent) {
62
+ eventTarget = ev.target;
63
+ }
64
+ triggerTouch(touchType, ev);
65
+ if (ev.type === "mouseup") {
66
+ eventTarget = null;
67
+ }
68
+ };
69
+ }
70
+ function triggerTouch(eventName, mouseEv) {
71
+ const touchEvent = document.createEvent("Event");
72
+ touchEvent.initEvent(eventName, true, false);
73
+ touchEvent.altKey = mouseEv.altKey;
74
+ touchEvent.ctrlKey = mouseEv.ctrlKey;
75
+ touchEvent.metaKey = mouseEv.metaKey;
76
+ touchEvent.shiftKey = mouseEv.shiftKey;
77
+ touchEvent.touches = getActiveTouches(mouseEv);
78
+ touchEvent.targetTouches = getActiveTouches(mouseEv);
79
+ touchEvent.changedTouches = createTouchList(mouseEv);
80
+ eventTarget.dispatchEvent(touchEvent);
81
+ }
82
+ function createTouchList(mouseEv) {
83
+ const touchList = TouchList();
84
+ touchList.push(new Touch(eventTarget, 1, mouseEv, 0, 0));
85
+ return touchList;
86
+ }
87
+ function getActiveTouches(mouseEv) {
88
+ if (mouseEv.type === "mouseup") {
89
+ return TouchList();
90
+ }
91
+ return createTouchList(mouseEv);
92
+ }
93
+ function useTouchEmulator(dom = window) {
94
+ const touchStart = onMouse("touchstart");
95
+ const touchMove = onMouse("touchmove");
96
+ const touchEnd = onMouse("touchend");
97
+ (0, import_react.useEffect)(() => {
98
+ if (dom) {
99
+ dom.addEventListener("mousedown", touchStart, true);
100
+ dom.addEventListener("mousemove", touchMove, true);
101
+ dom.addEventListener("mouseup", touchEnd, true);
102
+ }
103
+ return () => {
104
+ if (dom) {
105
+ dom.removeEventListener("mousedown", touchStart, true);
106
+ dom.removeEventListener("mousemove", touchMove, true);
107
+ dom.removeEventListener("mouseup", touchEnd, true);
108
+ }
109
+ };
110
+ }, [dom]);
111
+ }
@@ -0,0 +1,12 @@
1
+ import { ChangeEvent } from 'react';
2
+ type Options<T> = {
3
+ value?: T;
4
+ defaultValue: T;
5
+ onChange?: (e: ChangeEvent<HTMLElement>, data: Record<string, any>) => void;
6
+ config?: {
7
+ name?: string;
8
+ state?: string;
9
+ };
10
+ };
11
+ export default function useValue<T>(options: Options<T>): readonly [T, (e: any, val: any) => void];
12
+ export {};
@@ -0,0 +1,49 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/hooks/useValue.ts
20
+ var useValue_exports = {};
21
+ __export(useValue_exports, {
22
+ default: () => useValue
23
+ });
24
+ module.exports = __toCommonJS(useValue_exports);
25
+ var import_react = require("react");
26
+ function useValue(options) {
27
+ const { value, defaultValue, onChange, config = {} } = options;
28
+ const { state, name } = config;
29
+ const [internalValue, setInternalValue] = (0, import_react.useState)(defaultValue);
30
+ const initialDefaultValue = (0, import_react.useRef)(defaultValue);
31
+ const isControlled = value !== void 0;
32
+ (0, import_react.useEffect)(() => {
33
+ if (!isControlled && JSON.stringify(defaultValue) !== JSON.stringify(initialDefaultValue.current) && state && name) {
34
+ console.error(
35
+ [
36
+ `BUI: A component is changing the default ${state} state of an uncontrolled ${name} after being initialized. To suppress this warning opt to use a controlled ${name}.`
37
+ ].join("\n")
38
+ );
39
+ }
40
+ }, [defaultValue]);
41
+ const triggerChange = (0, import_react.useCallback)(
42
+ (e, val) => {
43
+ setInternalValue(val);
44
+ onChange == null ? void 0 : onChange(e, { value: val });
45
+ },
46
+ [onChange]
47
+ );
48
+ return [isControlled ? value : internalValue, triggerChange];
49
+ }
@@ -0,0 +1,12 @@
1
+ export { default as debounce } from './debounce';
2
+ export { default as convertHexToRGBA } from './hex2rgba';
3
+ export { useDidMountEffect, useEventCallback, useForkRef, useTouchEmulator, useValue, useDomReady, useSize, useDomCss, } from './hooks';
4
+ export { default as isDev } from './isDev';
5
+ export { isMini, isWeapp, isAlipay } from './isMini';
6
+ export { default as setRef } from './setRef';
7
+ export { default as throttle } from './throttle';
8
+ export { default as toArray } from './toArray';
9
+ export { default as blockTouch } from './touchBlocker';
10
+ export { easing, duration, getTransitionProps, createTransitions, } from './transitions';
11
+ export { default as getBoundingClientRect } from './getBoundingClientRect';
12
+ export * from './isType';
package/dist/index.js ADDED
@@ -0,0 +1,96 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ blockTouch: () => import_touchBlocker.default,
34
+ convertHexToRGBA: () => import_hex2rgba.default,
35
+ createTransitions: () => import_transitions.createTransitions,
36
+ debounce: () => import_debounce.default,
37
+ duration: () => import_transitions.duration,
38
+ easing: () => import_transitions.easing,
39
+ getBoundingClientRect: () => import_getBoundingClientRect.default,
40
+ getTransitionProps: () => import_transitions.getTransitionProps,
41
+ isAlipay: () => import_isMini.isAlipay,
42
+ isDev: () => import_isDev.default,
43
+ isMini: () => import_isMini.isMini,
44
+ isWeapp: () => import_isMini.isWeapp,
45
+ setRef: () => import_setRef.default,
46
+ throttle: () => import_throttle.default,
47
+ toArray: () => import_toArray.default,
48
+ useDidMountEffect: () => import_hooks.useDidMountEffect,
49
+ useDomCss: () => import_hooks.useDomCss,
50
+ useDomReady: () => import_hooks.useDomReady,
51
+ useEventCallback: () => import_hooks.useEventCallback,
52
+ useForkRef: () => import_hooks.useForkRef,
53
+ useSize: () => import_hooks.useSize,
54
+ useTouchEmulator: () => import_hooks.useTouchEmulator,
55
+ useValue: () => import_hooks.useValue
56
+ });
57
+ module.exports = __toCommonJS(src_exports);
58
+ var import_debounce = __toESM(require("./debounce"));
59
+ var import_hex2rgba = __toESM(require("./hex2rgba"));
60
+ var import_hooks = require("./hooks");
61
+ var import_isDev = __toESM(require("./isDev"));
62
+ var import_isMini = require("./isMini");
63
+ var import_setRef = __toESM(require("./setRef"));
64
+ var import_throttle = __toESM(require("./throttle"));
65
+ var import_toArray = __toESM(require("./toArray"));
66
+ var import_touchBlocker = __toESM(require("./touchBlocker"));
67
+ var import_transitions = require("./transitions");
68
+ var import_getBoundingClientRect = __toESM(require("./getBoundingClientRect"));
69
+ __reExport(src_exports, require("./isType"), module.exports);
70
+ // Annotate the CommonJS export names for ESM import in node:
71
+ 0 && (module.exports = {
72
+ blockTouch,
73
+ convertHexToRGBA,
74
+ createTransitions,
75
+ debounce,
76
+ duration,
77
+ easing,
78
+ getBoundingClientRect,
79
+ getTransitionProps,
80
+ isAlipay,
81
+ isDev,
82
+ isMini,
83
+ isWeapp,
84
+ setRef,
85
+ throttle,
86
+ toArray,
87
+ useDidMountEffect,
88
+ useDomCss,
89
+ useDomReady,
90
+ useEventCallback,
91
+ useForkRef,
92
+ useSize,
93
+ useTouchEmulator,
94
+ useValue,
95
+ ...require("./isType")
96
+ });
@@ -0,0 +1,2 @@
1
+ declare const isDev: boolean;
2
+ export default isDev;
package/dist/isDev.js ADDED
@@ -0,0 +1,26 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/isDev.ts
20
+ var isDev_exports = {};
21
+ __export(isDev_exports, {
22
+ default: () => isDev_default
23
+ });
24
+ module.exports = __toCommonJS(isDev_exports);
25
+ var isDev = process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
26
+ var isDev_default = isDev;
@@ -0,0 +1,4 @@
1
+ declare const isMini: boolean;
2
+ declare const isWeapp: boolean;
3
+ declare const isAlipay: boolean;
4
+ export { isMini, isWeapp, isAlipay };
package/dist/isMini.js ADDED
@@ -0,0 +1,35 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/isMini.ts
20
+ var isMini_exports = {};
21
+ __export(isMini_exports, {
22
+ isAlipay: () => isAlipay,
23
+ isMini: () => isMini,
24
+ isWeapp: () => isWeapp
25
+ });
26
+ module.exports = __toCommonJS(isMini_exports);
27
+ var isMini = typeof process.env.TARO_ENV === "string";
28
+ var isWeapp = process.env.TARO_ENV === "weapp";
29
+ var isAlipay = process.env.TARO_ENV === "alipay";
30
+ // Annotate the CommonJS export names for ESM import in node:
31
+ 0 && (module.exports = {
32
+ isAlipay,
33
+ isMini,
34
+ isWeapp
35
+ });
@@ -0,0 +1 @@
1
+ export declare const isFunction: (fn: any) => boolean;
package/dist/isType.js ADDED
@@ -0,0 +1,31 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/isType.ts
20
+ var isType_exports = {};
21
+ __export(isType_exports, {
22
+ isFunction: () => isFunction
23
+ });
24
+ module.exports = __toCommonJS(isType_exports);
25
+ var isFunction = (fn) => {
26
+ return fn && {}.toString.call(fn) === "[object Function]";
27
+ };
28
+ // Annotate the CommonJS export names for ESM import in node:
29
+ 0 && (module.exports = {
30
+ isFunction
31
+ });
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export default function setRef<T>(ref: React.MutableRefObject<T | null> | ((instance: T | null) => void) | null | undefined, value: T | null): void;
package/dist/setRef.js ADDED
@@ -0,0 +1,31 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/setRef.ts
20
+ var setRef_exports = {};
21
+ __export(setRef_exports, {
22
+ default: () => setRef
23
+ });
24
+ module.exports = __toCommonJS(setRef_exports);
25
+ function setRef(ref, value) {
26
+ if (typeof ref === "function") {
27
+ ref(value);
28
+ } else if (ref) {
29
+ ref.current = value;
30
+ }
31
+ }
@@ -0,0 +1,6 @@
1
+ interface OptionsThrottle {
2
+ leading?: boolean;
3
+ trailing?: boolean;
4
+ }
5
+ export default function throttle(fn: any, interval?: number, options?: OptionsThrottle): (...args: any[]) => void;
6
+ export {};
@@ -0,0 +1,52 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/throttle.ts
20
+ var throttle_exports = {};
21
+ __export(throttle_exports, {
22
+ default: () => throttle
23
+ });
24
+ module.exports = __toCommonJS(throttle_exports);
25
+ function throttle(fn, interval = 200, options = { leading: true, trailing: false }) {
26
+ const { leading = true, trailing = false } = options;
27
+ let lastTime = 0;
28
+ let timer = null;
29
+ const _throttle = function(...args) {
30
+ const nowTime = (/* @__PURE__ */ new Date()).getTime();
31
+ if (!lastTime && !leading)
32
+ lastTime = nowTime;
33
+ const remainTime = interval - (nowTime - lastTime);
34
+ if (remainTime <= 0) {
35
+ if (timer) {
36
+ clearTimeout(timer);
37
+ timer = null;
38
+ }
39
+ fn.apply(this, args);
40
+ lastTime = nowTime;
41
+ return;
42
+ }
43
+ if (trailing && !timer) {
44
+ timer = setTimeout(() => {
45
+ timer = null;
46
+ lastTime = !leading ? 0 : (/* @__PURE__ */ new Date()).getTime();
47
+ fn.apply(this, args);
48
+ }, remainTime);
49
+ }
50
+ };
51
+ return _throttle;
52
+ }
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ interface Option {
3
+ keepEmpty?: boolean;
4
+ }
5
+ export default function toArray(children: React.ReactNode, option?: Option): React.ReactElement[];
6
+ export {};