@bifrostui/utils 1.1.11-beta.0 → 1.1.11-beta.4

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 (57) hide show
  1. package/README.md +3 -0
  2. package/dist/debounce.js +4 -4
  3. package/dist/domTarget.js +0 -2
  4. package/dist/getBoundingClientRect/index.js +0 -2
  5. package/dist/getBoundingClientRect/index.miniapp.js +0 -2
  6. package/dist/hex2rgba.js +1 -3
  7. package/dist/hooks/index.js +0 -2
  8. package/dist/hooks/useDidMountEffect.js +5 -5
  9. package/dist/hooks/useDomCss/index.js +0 -2
  10. package/dist/hooks/useDomCss/index.miniapp.js +0 -2
  11. package/dist/hooks/useDomReady/index.js +0 -2
  12. package/dist/hooks/useDomReady/index.miniapp.js +0 -2
  13. package/dist/hooks/useEventCallback.js +0 -2
  14. package/dist/hooks/useForkRef.js +0 -2
  15. package/dist/hooks/useMemoizedFn.js +0 -2
  16. package/dist/hooks/useSize.js +0 -2
  17. package/dist/hooks/useTouch.js +4 -5
  18. package/dist/hooks/useTouchEmulator.js +3 -5
  19. package/dist/hooks/useValue.js +0 -2
  20. package/dist/index.js +0 -2
  21. package/dist/isDev.js +1 -3
  22. package/dist/isMini.js +4 -6
  23. package/dist/isType.js +1 -3
  24. package/dist/setRef.js +0 -2
  25. package/dist/throttle.js +2 -3
  26. package/dist/toArray.js +0 -2
  27. package/dist/touchBlocker.js +6 -5
  28. package/dist/transitions.js +29 -19
  29. package/es/debounce.js +12 -11
  30. package/es/domTarget.js +8 -5
  31. package/es/getBoundingClientRect/index.js +5 -2
  32. package/es/getBoundingClientRect/index.miniapp.js +9 -14
  33. package/es/hex2rgba.js +12 -19
  34. package/es/hooks/index.js +11 -1
  35. package/es/hooks/useDidMountEffect.js +12 -9
  36. package/es/hooks/useDomCss/index.js +11 -8
  37. package/es/hooks/useDomCss/index.miniapp.js +12 -9
  38. package/es/hooks/useDomReady/index.js +7 -4
  39. package/es/hooks/useDomReady/index.miniapp.js +8 -5
  40. package/es/hooks/useEventCallback.js +9 -16
  41. package/es/hooks/useForkRef.js +10 -18
  42. package/es/hooks/useMemoizedFn.js +13 -14
  43. package/es/hooks/useSize.js +10 -19
  44. package/es/hooks/useTouch.js +47 -47
  45. package/es/hooks/useTouchEmulator.js +34 -90
  46. package/es/hooks/useValue.js +24 -32
  47. package/es/index.js +54 -12
  48. package/es/isDev.js +5 -2
  49. package/es/isMini.js +11 -6
  50. package/es/isType.js +6 -4
  51. package/es/setRef.js +6 -3
  52. package/es/throttle.js +16 -34
  53. package/es/toArray.js +10 -8
  54. package/es/touchBlocker.js +59 -62
  55. package/es/transitions.js +57 -45
  56. package/package.json +13 -7
  57. package/src/index.ts +27 -0
package/es/index.js CHANGED
@@ -1,12 +1,54 @@
1
- export { default as debounce } from "./debounce";
2
- export { default as convertHexToRGBA } from "./hex2rgba";
3
- export { useDidMountEffect, useEventCallback, useForkRef, useTouchEmulator, useValue, useDomReady, useSize, useDomCss, useTouch } from "./hooks";
4
- export { default as isDev } from "./isDev";
5
- export { isMini, isWeapp, isAlipay, isMiniapp } 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";
1
+ import { default as default2 } from "./debounce";
2
+ import { default as default3 } from "./hex2rgba";
3
+ import {
4
+ useDidMountEffect,
5
+ useEventCallback,
6
+ useForkRef,
7
+ useTouchEmulator,
8
+ useValue,
9
+ useDomReady,
10
+ useSize,
11
+ useDomCss,
12
+ useTouch
13
+ } from "./hooks";
14
+ import { default as default4 } from "./isDev";
15
+ import { isMini, isWeapp, isAlipay, isMiniapp } from "./isMini";
16
+ import { default as default5 } from "./setRef";
17
+ import { default as default6 } from "./throttle";
18
+ import { default as default7 } from "./toArray";
19
+ import { default as default8 } from "./touchBlocker";
20
+ import {
21
+ easing,
22
+ duration,
23
+ getTransitionProps,
24
+ createTransitions
25
+ } from "./transitions";
26
+ import { default as default9 } from "./getBoundingClientRect";
27
+ export * from "./isType";
28
+ export {
29
+ default8 as blockTouch,
30
+ default3 as convertHexToRGBA,
31
+ createTransitions,
32
+ default2 as debounce,
33
+ duration,
34
+ easing,
35
+ default9 as getBoundingClientRect,
36
+ getTransitionProps,
37
+ isAlipay,
38
+ default4 as isDev,
39
+ isMini,
40
+ isMiniapp,
41
+ isWeapp,
42
+ default5 as setRef,
43
+ default6 as throttle,
44
+ default7 as toArray,
45
+ useDidMountEffect,
46
+ useDomCss,
47
+ useDomReady,
48
+ useEventCallback,
49
+ useForkRef,
50
+ useSize,
51
+ useTouch,
52
+ useTouchEmulator,
53
+ useValue
54
+ };
package/es/isDev.js CHANGED
@@ -1,2 +1,5 @@
1
- var isDev = process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test';
2
- export default isDev;
1
+ const isDev = process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
2
+ var isDev_default = isDev;
3
+ export {
4
+ isDev_default as default
5
+ };
package/es/isMini.js CHANGED
@@ -1,7 +1,12 @@
1
- var isMini = typeof process.env.TARO_ENV === 'string';
2
- var isWeapp = process.env.TARO_ENV === 'weapp';
3
- var isAlipay = process.env.TARO_ENV === 'alipay';
4
- export { isMini, isWeapp, isAlipay };
5
- export var isMiniapp = function isMiniapp() {
1
+ const isMini = typeof process.env.TARO_ENV === "string";
2
+ const isWeapp = process.env.TARO_ENV === "weapp";
3
+ const isAlipay = process.env.TARO_ENV === "alipay";
4
+ const isMiniapp = () => {
6
5
  return isMini;
7
- };
6
+ };
7
+ export {
8
+ isAlipay,
9
+ isMini,
10
+ isMiniapp,
11
+ isWeapp
12
+ };
package/es/isType.js CHANGED
@@ -1,4 +1,6 @@
1
- // eslint-disable-next-line import/prefer-default-export
2
- export var isFunction = function isFunction(fn) {
3
- return fn && {}.toString.call(fn) === '[object Function]';
4
- };
1
+ const isFunction = (fn) => {
2
+ return fn && {}.toString.call(fn) === "[object Function]";
3
+ };
4
+ export {
5
+ isFunction
6
+ };
package/es/setRef.js CHANGED
@@ -1,7 +1,10 @@
1
- export default function setRef(ref, value) {
2
- if (typeof ref === 'function') {
1
+ function setRef(ref, value) {
2
+ if (typeof ref === "function") {
3
3
  ref(value);
4
4
  } else if (ref) {
5
5
  ref.current = value;
6
6
  }
7
- }
7
+ }
8
+ export {
9
+ setRef as default
10
+ };
package/es/throttle.js CHANGED
@@ -1,49 +1,31 @@
1
- export default function throttle(fn) {
2
- var interval = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 200;
3
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
4
- leading: true,
5
- trailing: false
6
- };
7
- // 1.记录上一次的开始时间
8
- var _options$leading = options.leading,
9
- leading = _options$leading === void 0 ? true : _options$leading,
10
- _options$trailing = options.trailing,
11
- trailing = _options$trailing === void 0 ? false : _options$trailing;
12
- var lastTime = 0;
13
- var timer = null;
14
-
15
- // 2.事件触发时, 真正执行的函数
16
- /* eslint no-underscore-dangle: 0 */
17
- var _throttle = function _throttle() {
18
- var _this = this;
19
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
20
- args[_key] = arguments[_key];
21
- }
22
- // 2.1.获取当前事件触发时的时间
23
- var nowTime = new Date().getTime();
24
- if (!lastTime && !leading) lastTime = nowTime;
25
-
26
- // 2.2.使用当前触发的时间和之前的时间间隔以及上一次开始的时间, 计算出还剩余多长事件需要去触发函数
27
- var remainTime = interval - (nowTime - lastTime);
1
+ function throttle(fn, interval = 200, options = { leading: true, trailing: false }) {
2
+ const { leading = true, trailing = false } = options;
3
+ let lastTime = 0;
4
+ let timer = null;
5
+ const _throttle = function(...args) {
6
+ const nowTime = (/* @__PURE__ */ new Date()).getTime();
7
+ if (!lastTime && !leading)
8
+ lastTime = nowTime;
9
+ const remainTime = interval - (nowTime - lastTime);
28
10
  if (remainTime <= 0) {
29
11
  if (timer) {
30
12
  clearTimeout(timer);
31
13
  timer = null;
32
14
  }
33
-
34
- // 2.3.真正触发函数
35
15
  fn.apply(this, args);
36
- // 2.4.保留上次触发的时间
37
16
  lastTime = nowTime;
38
17
  return;
39
18
  }
40
19
  if (trailing && !timer) {
41
- timer = setTimeout(function () {
20
+ timer = setTimeout(() => {
42
21
  timer = null;
43
- lastTime = !leading ? 0 : new Date().getTime();
44
- fn.apply(_this, args);
22
+ lastTime = !leading ? 0 : (/* @__PURE__ */ new Date()).getTime();
23
+ fn.apply(this, args);
45
24
  }, remainTime);
46
25
  }
47
26
  };
48
27
  return _throttle;
49
- }
28
+ }
29
+ export {
30
+ throttle as default
31
+ };
package/es/toArray.js CHANGED
@@ -1,10 +1,9 @@
1
- import React from 'react';
2
- import { isFragment } from 'react-is';
3
- export default function toArray(children) {
4
- var option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
5
- var ret = [];
6
- React.Children.forEach(children, function (child) {
7
- if ((child === undefined || child === null) && !option.keepEmpty) {
1
+ import React from "react";
2
+ import { isFragment } from "react-is";
3
+ function toArray(children, option = {}) {
4
+ let ret = [];
5
+ React.Children.forEach(children, (child) => {
6
+ if ((child === void 0 || child === null) && !option.keepEmpty) {
8
7
  return;
9
8
  }
10
9
  if (Array.isArray(child)) {
@@ -16,4 +15,7 @@ export default function toArray(children) {
16
15
  }
17
16
  });
18
17
  return ret;
19
- }
18
+ }
19
+ export {
20
+ toArray as default
21
+ };
@@ -1,90 +1,87 @@
1
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
- /**
8
- * author: 辉宇
9
- * 为一个DOM元素添加滑动穿透防护
10
- * 返回一个函数,调用可解除滑动穿透防护
11
- *
12
- * **这里滑动穿透防护的定义为不允许root外部的元素被touch类事件滑动(overflow)**
13
- *
14
- * @param root: HTMLElement
15
- * @returns {(function(): void)|*}
16
- */
17
- export default function blockTouch(root) {
18
- var lastTouch;
19
- var moveDirection;
20
- var moveAxis;
21
- var onTouchStart = function onTouchStart(e) {
22
- var _e$touches = _slicedToArray(e.touches, 1);
23
- lastTouch = _e$touches[0];
1
+ function blockTouch(root) {
2
+ let lastTouch;
3
+ let moveDirection;
4
+ let moveAxis;
5
+ const onTouchStart = (e) => {
6
+ [lastTouch] = e.touches;
24
7
  };
25
- var shouldPrevent = function shouldPrevent(targetElement, axis, delta) {
26
- var el = targetElement;
27
- var needPrevent = true;
8
+ const shouldPrevent = (targetElement, axis, delta) => {
9
+ let el = targetElement;
10
+ let needPrevent = true;
28
11
  while (el) {
29
- var _window$getComputedSt = window.getComputedStyle(el),
30
- overflowY = _window$getComputedSt.overflowY,
31
- overflowX = _window$getComputedSt.overflowX;
32
- if (axis === 'y' && (overflowY === 'scroll' || overflowY === 'auto')) {
33
- var dir = moveDirection || delta;
34
- if (moveDirection === undefined) moveDirection = dir;
12
+ const { overflowY, overflowX } = window.getComputedStyle(el);
13
+ if (axis === "y" && (overflowY === "scroll" || overflowY === "auto")) {
14
+ const dir = moveDirection || delta;
15
+ if (moveDirection === void 0)
16
+ moveDirection = dir;
35
17
  if (el.scrollTop !== 0 && dir < 0) {
36
18
  needPrevent = false;
37
19
  break;
38
20
  }
39
- // 当内部滚动元素高度有小数时,可能会出现小于号左右差1的情况导致算法失效
40
21
  if (el.scrollTop + el.offsetHeight + 1 < el.scrollHeight && dir > 0) {
41
22
  needPrevent = false;
42
23
  break;
43
24
  }
44
25
  }
45
- if (axis === 'x' && (overflowX === 'scroll' || overflowX === 'auto')) {
46
- var _dir = moveDirection || delta;
47
- if (moveDirection === undefined) moveDirection = _dir;
48
- if (el.scrollLeft !== 0 && _dir < 0) {
26
+ if (axis === "x" && (overflowX === "scroll" || overflowX === "auto")) {
27
+ const dir = moveDirection || delta;
28
+ if (moveDirection === void 0)
29
+ moveDirection = dir;
30
+ if (el.scrollLeft !== 0 && dir < 0) {
49
31
  needPrevent = false;
50
32
  break;
51
33
  }
52
- if (el.scrollLeft + el.offsetWidth < el.scrollWidth && _dir > 0) {
34
+ if (el.scrollLeft + el.offsetWidth < el.scrollWidth && dir > 0) {
53
35
  needPrevent = false;
54
36
  break;
55
37
  }
56
38
  }
57
- if (el === root) break;
39
+ if (el === root)
40
+ break;
58
41
  el = el.parentNode;
59
42
  }
60
43
  return needPrevent;
61
44
  };
62
- var onTouchMove = function onTouchMove(e) {
63
- var currentTouch = e.touches[0];
45
+ const onTouchMove = (e) => {
46
+ const currentTouch = e.touches[0];
64
47
  if (!moveAxis) {
65
- if (Math.abs(lastTouch.screenY - currentTouch.screenY) > Math.abs(lastTouch.screenX - currentTouch.screenX)) moveAxis = 'y';
66
- if (Math.abs(lastTouch.screenY - currentTouch.screenY) < Math.abs(lastTouch.screenX - currentTouch.screenX)) moveAxis = 'x';
48
+ if (Math.abs(lastTouch.screenY - currentTouch.screenY) > Math.abs(lastTouch.screenX - currentTouch.screenX))
49
+ moveAxis = "y";
50
+ if (Math.abs(lastTouch.screenY - currentTouch.screenY) < Math.abs(lastTouch.screenX - currentTouch.screenX))
51
+ moveAxis = "x";
67
52
  }
68
- if (shouldPrevent(e.target, moveAxis, moveAxis === 'x' ? lastTouch.screenX - currentTouch.screenX : lastTouch.screenY - currentTouch.screenY) && !e.cancelable === false) e.preventDefault();
69
- // setLastTouch(e.touches[0]);
53
+ if (shouldPrevent(
54
+ e.target,
55
+ moveAxis,
56
+ moveAxis === "x" ? lastTouch.screenX - currentTouch.screenX : lastTouch.screenY - currentTouch.screenY
57
+ ) && !e.cancelable === false)
58
+ e.preventDefault();
70
59
  };
71
- var onTouchEnd = function onTouchEnd() {
72
- lastTouch = undefined;
73
- moveDirection = undefined;
74
- moveAxis = undefined;
60
+ const onTouchEnd = () => {
61
+ lastTouch = void 0;
62
+ moveDirection = void 0;
63
+ moveAxis = void 0;
75
64
  };
76
- var onScroll = function onScroll(e) {
77
- if (shouldPrevent(e.target, Math.abs(e.deltaX) > Math.abs(e.deltaY) ? 'x' : 'y', Math.abs(e.deltaX) > Math.abs(e.deltaY) ? e.deltaX : e.deltaY) && !e.cancelable === false) e.preventDefault();
78
- moveDirection = undefined;
65
+ const onScroll = (e) => {
66
+ if (shouldPrevent(
67
+ e.target,
68
+ Math.abs(e.deltaX) > Math.abs(e.deltaY) ? "x" : "y",
69
+ Math.abs(e.deltaX) > Math.abs(e.deltaY) ? e.deltaX : e.deltaY
70
+ ) && !e.cancelable === false)
71
+ e.preventDefault();
72
+ moveDirection = void 0;
79
73
  };
80
- root.addEventListener('touchstart', onTouchStart);
81
- root.addEventListener('touchmove', onTouchMove);
82
- root.addEventListener('touchend', onTouchEnd);
83
- root.addEventListener('wheel', onScroll);
84
- return function () {
85
- root.removeEventListener('touchstart', onTouchStart);
86
- root.removeEventListener('touchmove', onTouchMove);
87
- root.removeEventListener('touchend', onTouchEnd);
88
- root.removeEventListener('wheel', onScroll);
74
+ root.addEventListener("touchstart", onTouchStart);
75
+ root.addEventListener("touchmove", onTouchMove);
76
+ root.addEventListener("touchend", onTouchEnd);
77
+ root.addEventListener("wheel", onScroll);
78
+ return () => {
79
+ root.removeEventListener("touchstart", onTouchStart);
80
+ root.removeEventListener("touchmove", onTouchMove);
81
+ root.removeEventListener("touchend", onTouchEnd);
82
+ root.removeEventListener("wheel", onScroll);
89
83
  };
90
- }
84
+ }
85
+ export {
86
+ blockTouch as default
87
+ };
package/es/transitions.js CHANGED
@@ -1,16 +1,29 @@
1
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
3
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
5
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
6
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
7
- export var easing = {
8
- easeInOut: 'cubic-bezier(0.4, 0, 0.2, 1)',
9
- easeOut: 'cubic-bezier(0.0, 0, 0.2, 1)',
10
- easeIn: 'cubic-bezier(0.4, 0, 1, 1)',
11
- sharp: 'cubic-bezier(0.4, 0, 0.6, 1)'
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
12
18
  };
13
- export var duration = {
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ const easing = {
21
+ easeInOut: "cubic-bezier(0.4, 0, 0.2, 1)",
22
+ easeOut: "cubic-bezier(0.0, 0, 0.2, 1)",
23
+ easeIn: "cubic-bezier(0.4, 0, 1, 1)",
24
+ sharp: "cubic-bezier(0.4, 0, 0.6, 1)"
25
+ };
26
+ const duration = {
14
27
  shortest: 150,
15
28
  shorter: 200,
16
29
  short: 250,
@@ -21,45 +34,44 @@ export var duration = {
21
34
  enteringScreen: 225,
22
35
  leavingScreen: 195
23
36
  };
24
- export function getTransitionProps(props, options) {
25
- var _style$transitionDura, _style$transitionTimi, _style$transitionDela;
26
- var timeout = props.timeout,
27
- easingProps = props.easing,
28
- _props$style = props.style,
29
- style = _props$style === void 0 ? {} : _props$style,
30
- delay = props.delay;
31
- var mode = options.mode;
32
- if (mode !== 'enter' && mode !== 'exit') mode = mode === 'entering' || mode === 'entered' ? 'enter' : 'exit';
37
+ function getTransitionProps(props, options) {
38
+ var _a, _b, _c;
39
+ const { timeout, easing: easingProps, style = {}, delay } = props;
40
+ let { mode } = options;
41
+ if (mode !== "enter" && mode !== "exit")
42
+ mode = mode === "entering" || mode === "entered" ? "enter" : "exit";
33
43
  return {
34
- duration: (_style$transitionDura = style.transitionDuration) !== null && _style$transitionDura !== void 0 ? _style$transitionDura : typeof timeout === 'number' ? timeout : timeout[mode] || 0,
35
- easing: (_style$transitionTimi = style.transitionTimingFunction) !== null && _style$transitionTimi !== void 0 ? _style$transitionTimi : _typeof(easingProps) === 'object' ? easingProps[mode] : easingProps,
36
- delay: (_style$transitionDela = style.transitionDelay) !== null && _style$transitionDela !== void 0 ? _style$transitionDela : typeof delay === 'number' ? delay : delay[mode] || 0
44
+ duration: (_a = style.transitionDuration) != null ? _a : typeof timeout === "number" ? timeout : timeout[mode] || 0,
45
+ easing: (_b = style.transitionTimingFunction) != null ? _b : typeof easingProps === "object" ? easingProps[mode] : easingProps,
46
+ delay: (_c = style.transitionDelay) != null ? _c : typeof delay === "number" ? delay : delay[mode] || 0
37
47
  };
38
48
  }
39
49
  function formatMs(milliseconds) {
40
- return "".concat(Math.round(milliseconds), "ms");
50
+ return `${Math.round(milliseconds)}ms`;
41
51
  }
42
- export function createTransitions() {
43
- var inputTransitions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
44
- var mergedEasing = _objectSpread(_objectSpread({}, easing), inputTransitions.easing);
45
- var mergedDuration = _objectSpread(_objectSpread({}, duration), inputTransitions.duration);
46
- var create = function create() {
47
- var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ['all'];
48
- var options = arguments.length > 1 ? arguments[1] : undefined;
49
- var _options$duration = options.duration,
50
- durationOption = _options$duration === void 0 ? mergedDuration.standard : _options$duration,
51
- _options$easing = options.easing,
52
- easingOption = _options$easing === void 0 ? mergedEasing.easeInOut : _options$easing,
53
- _options$delay = options.delay,
54
- delay = _options$delay === void 0 ? 0 : _options$delay;
55
- return (Array.isArray(props) ? props : [props]).map(function (animatedProp) {
56
- return "".concat(animatedProp, " ").concat(typeof durationOption === 'string' ? durationOption : formatMs(durationOption), " ").concat(easingOption, " ").concat(typeof delay === 'string' ? delay : formatMs(delay));
57
- }).join(',');
52
+ function createTransitions(inputTransitions = {}) {
53
+ const mergedEasing = __spreadValues(__spreadValues({}, easing), inputTransitions.easing);
54
+ const mergedDuration = __spreadValues(__spreadValues({}, duration), inputTransitions.duration);
55
+ const create = (props = ["all"], options) => {
56
+ const {
57
+ duration: durationOption = mergedDuration.standard,
58
+ easing: easingOption = mergedEasing.easeInOut,
59
+ delay = 0
60
+ } = options;
61
+ return (Array.isArray(props) ? props : [props]).map(
62
+ (animatedProp) => `${animatedProp} ${typeof durationOption === "string" ? durationOption : formatMs(durationOption)} ${easingOption} ${typeof delay === "string" ? delay : formatMs(delay)}`
63
+ ).join(",");
58
64
  };
59
- return _objectSpread(_objectSpread({
60
- create: create
61
- }, inputTransitions), {}, {
65
+ return __spreadProps(__spreadValues({
66
+ create
67
+ }, inputTransitions), {
62
68
  easing: mergedEasing,
63
69
  duration: mergedDuration
64
70
  });
65
- }
71
+ }
72
+ export {
73
+ createTransitions,
74
+ duration,
75
+ easing,
76
+ getTransitionProps
77
+ };
package/package.json CHANGED
@@ -1,32 +1,38 @@
1
1
  {
2
2
  "name": "@bifrostui/utils",
3
- "version": "1.1.11-beta.0",
3
+ "version": "1.1.11-beta.4",
4
4
  "description": "BUI React utilities for building components.",
5
- "main": "dist/index.js",
6
- "module": "es/index.js",
5
+ "main": "src/index.ts",
6
+ "module": "src/index.ts",
7
7
  "sideEffects": false,
8
8
  "files": [
9
9
  "es",
10
10
  "dist"
11
11
  ],
12
12
  "scripts": {
13
- "build": "father build",
13
+ "build": "node esbuild.config.js",
14
14
  "test": "echo \"Error: run tests from root\" && exit 1"
15
15
  },
16
16
  "devDependencies": {
17
- "father": "4.3.1"
17
+ "esbuild": "^0.19.7",
18
+ "esbuild-plugin-less": "1.3.10",
19
+ "fs-extra": "^11.2.0",
20
+ "glob": "11.0.0"
18
21
  },
19
22
  "dependencies": {
20
23
  "react-is": "^18.0.0"
21
24
  },
22
25
  "peerDependencies": {
23
- "@tarojs/taro": "^3.2.0",
26
+ "@tarojs/runtime": "^3.0.0",
27
+ "@tarojs/taro": "^3.0.0",
24
28
  "react": "^17.0.0 || ^18.0.0"
25
29
  },
26
30
  "license": "MIT",
27
31
  "publishConfig": {
32
+ "main": "dist/index.js",
33
+ "module": "es/index.js",
28
34
  "access": "public",
29
35
  "registry": "https://registry.npmjs.org/"
30
36
  },
31
- "gitHead": "5a4c0b97ca6184ddb27880b71f1594dac54d8a37"
37
+ "gitHead": "efd0ef8c98be4e4e566b2518777b884a4eb75aa6"
32
38
  }
package/src/index.ts ADDED
@@ -0,0 +1,27 @@
1
+ export { default as debounce } from './debounce';
2
+ export { default as convertHexToRGBA } from './hex2rgba';
3
+ export {
4
+ useDidMountEffect,
5
+ useEventCallback,
6
+ useForkRef,
7
+ useTouchEmulator,
8
+ useValue,
9
+ useDomReady,
10
+ useSize,
11
+ useDomCss,
12
+ useTouch,
13
+ } from './hooks';
14
+ export { default as isDev } from './isDev';
15
+ export { isMini, isWeapp, isAlipay, isMiniapp } from './isMini';
16
+ export { default as setRef } from './setRef';
17
+ export { default as throttle } from './throttle';
18
+ export { default as toArray } from './toArray';
19
+ export { default as blockTouch } from './touchBlocker';
20
+ export {
21
+ easing,
22
+ duration,
23
+ getTransitionProps,
24
+ createTransitions,
25
+ } from './transitions';
26
+ export { default as getBoundingClientRect } from './getBoundingClientRect';
27
+ export * from './isType';