@bifrostui/utils 1.4.6 → 1.4.7-beta.0

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 (46) hide show
  1. package/dist/directionLocationUtil.d.ts +27 -12
  2. package/dist/directionLocationUtil.js +101 -55
  3. package/dist/domUtils/index.d.ts +12 -0
  4. package/dist/domUtils/index.js +46 -0
  5. package/dist/domUtils/index.miniapp.d.ts +2 -0
  6. package/dist/domUtils/index.miniapp.js +86 -0
  7. package/dist/getBoundingClientRect/index.miniapp.d.ts +1 -2
  8. package/dist/getBoundingClientRect/index.miniapp.js +34 -5
  9. package/dist/getRootContainer/index.d.ts +2 -0
  10. package/dist/{getRootElement → getRootContainer}/index.js +8 -8
  11. package/dist/getRootContainer/index.miniapp.d.ts +3 -0
  12. package/dist/{getRootElement → getRootContainer}/index.miniapp.js +4 -4
  13. package/dist/hooks/index.d.ts +2 -2
  14. package/dist/hooks/index.js +8 -0
  15. package/dist/hooks/useTouchEmulator.d.ts +7 -1
  16. package/dist/hooks/useTouchEmulator.js +36 -10
  17. package/dist/index.d.ts +4 -3
  18. package/dist/index.js +18 -3
  19. package/dist/isMini.d.ts +2 -1
  20. package/dist/isMini.js +3 -0
  21. package/es/directionLocationUtil.d.ts +27 -12
  22. package/es/directionLocationUtil.js +91 -55
  23. package/es/domUtils/index.d.ts +12 -0
  24. package/es/domUtils/index.js +22 -0
  25. package/es/domUtils/index.miniapp.d.ts +2 -0
  26. package/es/domUtils/index.miniapp.js +54 -0
  27. package/es/getBoundingClientRect/index.miniapp.d.ts +1 -2
  28. package/es/getBoundingClientRect/index.miniapp.js +34 -5
  29. package/es/getRootContainer/index.d.ts +2 -0
  30. package/es/getRootContainer/index.js +9 -0
  31. package/es/getRootContainer/index.miniapp.d.ts +3 -0
  32. package/es/{getRootElement → getRootContainer}/index.miniapp.js +4 -4
  33. package/es/hooks/index.d.ts +2 -2
  34. package/es/hooks/index.js +10 -1
  35. package/es/hooks/useTouchEmulator.d.ts +7 -1
  36. package/es/hooks/useTouchEmulator.js +29 -10
  37. package/es/index.d.ts +4 -3
  38. package/es/index.js +15 -2
  39. package/es/isMini.d.ts +2 -1
  40. package/es/isMini.js +2 -0
  41. package/package.json +1 -1
  42. package/dist/getRootElement/index.d.ts +0 -2
  43. package/dist/getRootElement/index.miniapp.d.ts +0 -3
  44. package/es/getRootElement/index.d.ts +0 -2
  45. package/es/getRootElement/index.js +0 -9
  46. package/es/getRootElement/index.miniapp.d.ts +0 -3
@@ -1,13 +1,13 @@
1
1
  import Taro from "@tarojs/taro";
2
- const getRootElement = (rootEle) => {
2
+ const getRootContainer = (rootCon, defaultCon) => {
3
3
  const currentPages = Taro.getCurrentPages() || [];
4
4
  const currentPage = currentPages[currentPages.length - 1];
5
5
  const pageElement = currentPage == null ? void 0 : currentPage.$taroPath;
6
6
  const defaultRootElement = document.getElementById(pageElement);
7
- const rootElement = typeof rootEle === "function" ? rootEle() : rootEle;
8
- return rootElement || defaultRootElement;
7
+ const rootElement = typeof rootCon === "function" ? rootCon() : rootCon;
8
+ return rootElement || defaultCon || defaultRootElement;
9
9
  };
10
- var index_miniapp_default = getRootElement;
10
+ var index_miniapp_default = getRootContainer;
11
11
  export {
12
12
  index_miniapp_default as default
13
13
  };
@@ -1,11 +1,11 @@
1
1
  import useDidMountEffect from './useDidMountEffect';
2
2
  import useEventCallback from './useEventCallback';
3
3
  import useForkRef from './useForkRef';
4
- import useTouchEmulator from './useTouchEmulator';
4
+ import useTouchEmulator, { touchEmulator, emulateTouchStart, emulateTouchMove, emulateTouchEnd } from './useTouchEmulator';
5
5
  import useValue from './useValue';
6
6
  import useDomReady from './useDomReady';
7
7
  import useSize from './useSize';
8
8
  import useDomCss from './useDomCss';
9
9
  import useTouch from './useTouch';
10
10
  import useUniqueId from './useUniqueId';
11
- export { useValue, useForkRef, useEventCallback, useDidMountEffect, useTouchEmulator, useDomReady, useSize, useDomCss, useTouch, useUniqueId, };
11
+ export { useValue, useForkRef, useEventCallback, useDidMountEffect, useTouchEmulator, touchEmulator, emulateTouchStart, emulateTouchMove, emulateTouchEnd, useDomReady, useSize, useDomCss, useTouch, useUniqueId, };
package/es/hooks/index.js CHANGED
@@ -1,7 +1,12 @@
1
1
  import useDidMountEffect from "./useDidMountEffect";
2
2
  import useEventCallback from "./useEventCallback";
3
3
  import useForkRef from "./useForkRef";
4
- import useTouchEmulator from "./useTouchEmulator";
4
+ import useTouchEmulator, {
5
+ touchEmulator,
6
+ emulateTouchStart,
7
+ emulateTouchMove,
8
+ emulateTouchEnd
9
+ } from "./useTouchEmulator";
5
10
  import useValue from "./useValue";
6
11
  import useDomReady from "./useDomReady";
7
12
  import useSize from "./useSize";
@@ -9,6 +14,10 @@ import useDomCss from "./useDomCss";
9
14
  import useTouch from "./useTouch";
10
15
  import useUniqueId from "./useUniqueId";
11
16
  export {
17
+ emulateTouchEnd,
18
+ emulateTouchMove,
19
+ emulateTouchStart,
20
+ touchEmulator,
12
21
  useDidMountEffect,
13
22
  useDomCss,
14
23
  useDomReady,
@@ -1 +1,7 @@
1
- export default function useTouchEmulator(dom?: HTMLElement | Window): void;
1
+ declare const emulateTouchStart: (ev: any) => void;
2
+ declare const emulateTouchMove: (ev: any) => void;
3
+ declare const emulateTouchEnd: (ev: any) => void;
4
+ declare function useTouchEmulator(dom?: HTMLElement | Window): void;
5
+ declare const touchEmulator: (dom?: HTMLElement | Window) => () => void;
6
+ export default useTouchEmulator;
7
+ export { touchEmulator, emulateTouchStart, emulateTouchMove, emulateTouchEnd };
@@ -66,25 +66,44 @@ function getActiveTouches(mouseEv) {
66
66
  }
67
67
  return createTouchList(mouseEv);
68
68
  }
69
+ const emulateTouchStart = onMouse("touchstart");
70
+ const emulateTouchMove = onMouse("touchmove");
71
+ const emulateTouchEnd = onMouse("touchend");
69
72
  function useTouchEmulator(dom = window) {
70
- const touchStart = onMouse("touchstart");
71
- const touchMove = onMouse("touchmove");
72
- const touchEnd = onMouse("touchend");
73
73
  useEffect(() => {
74
74
  if (dom) {
75
- dom.addEventListener("mousedown", touchStart, true);
76
- dom.addEventListener("mousemove", touchMove, true);
77
- dom.addEventListener("mouseup", touchEnd, true);
75
+ dom.addEventListener("mousedown", emulateTouchStart, true);
76
+ dom.addEventListener("mousemove", emulateTouchMove, true);
77
+ dom.addEventListener("mouseup", emulateTouchEnd, true);
78
78
  }
79
79
  return () => {
80
80
  if (dom) {
81
- dom.removeEventListener("mousedown", touchStart, true);
82
- dom.removeEventListener("mousemove", touchMove, true);
83
- dom.removeEventListener("mouseup", touchEnd, true);
81
+ dom.removeEventListener("mousedown", emulateTouchStart, true);
82
+ dom.removeEventListener("mousemove", emulateTouchMove, true);
83
+ dom.removeEventListener("mouseup", emulateTouchEnd, true);
84
84
  }
85
85
  };
86
86
  }, [dom]);
87
87
  }
88
+ const touchEmulator = (dom = window) => {
89
+ if (dom) {
90
+ dom.addEventListener("mousedown", emulateTouchStart, true);
91
+ dom.addEventListener("mousemove", emulateTouchMove, true);
92
+ dom.addEventListener("mouseup", emulateTouchEnd, true);
93
+ }
94
+ return function() {
95
+ if (dom) {
96
+ dom.removeEventListener("mousedown", emulateTouchStart, true);
97
+ dom.removeEventListener("mousemove", emulateTouchMove, true);
98
+ dom.removeEventListener("mouseup", emulateTouchEnd, true);
99
+ }
100
+ };
101
+ };
102
+ var useTouchEmulator_default = useTouchEmulator;
88
103
  export {
89
- useTouchEmulator as default
104
+ useTouchEmulator_default as default,
105
+ emulateTouchEnd,
106
+ emulateTouchMove,
107
+ emulateTouchStart,
108
+ touchEmulator
90
109
  };
package/es/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { default as debounce } from './debounce';
2
- export { getStylesAndLocation, triggerEventTransform, parsePlacement, } from './directionLocationUtil';
2
+ export { getStylesAndLocation, getNewDirectionLocation, triggerEventTransform, parsePlacement, } from './directionLocationUtil';
3
3
  export { default as convertHexToRGBA } from './hex2rgba';
4
- export { useDidMountEffect, useEventCallback, useForkRef, useTouchEmulator, useValue, useDomReady, useSize, useDomCss, useTouch, useUniqueId, } from './hooks';
4
+ export { useDidMountEffect, useEventCallback, useForkRef, useTouchEmulator, touchEmulator, emulateTouchStart, emulateTouchMove, emulateTouchEnd, useValue, useDomReady, useSize, useDomCss, useTouch, useUniqueId, } from './hooks';
5
5
  export { default as isDev } from './isDev';
6
6
  export { isMini, isWeapp, isAlipay, isMiniapp } from './isMini';
7
7
  export { default as setRef } from './setRef';
@@ -9,7 +9,8 @@ export { default as throttle } from './throttle';
9
9
  export { default as toArray } from './toArray';
10
10
  export { default as blockTouch } from './touchBlocker';
11
11
  export { easing, duration, getTransitionProps, createTransitions, } from './transitions';
12
- export { default as getRootElement } from './getRootElement';
12
+ export { default as getRootContainer } from './getRootContainer';
13
13
  export { default as getBoundingClientRect } from './getBoundingClientRect';
14
+ export { getScrollRect, getClientRect } from './domUtils';
14
15
  export * from './isType';
15
16
  export * from './render';
package/es/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { default as default2 } from "./debounce";
2
2
  import {
3
3
  getStylesAndLocation,
4
+ getNewDirectionLocation,
4
5
  triggerEventTransform,
5
6
  parsePlacement
6
7
  } from "./directionLocationUtil";
@@ -10,6 +11,10 @@ import {
10
11
  useEventCallback,
11
12
  useForkRef,
12
13
  useTouchEmulator,
14
+ touchEmulator,
15
+ emulateTouchStart,
16
+ emulateTouchMove,
17
+ emulateTouchEnd,
13
18
  useValue,
14
19
  useDomReady,
15
20
  useSize,
@@ -29,8 +34,9 @@ import {
29
34
  getTransitionProps,
30
35
  createTransitions
31
36
  } from "./transitions";
32
- import { default as default9 } from "./getRootElement";
37
+ import { default as default9 } from "./getRootContainer";
33
38
  import { default as default10 } from "./getBoundingClientRect";
39
+ import { getScrollRect, getClientRect } from "./domUtils";
34
40
  export * from "./isType";
35
41
  export * from "./render";
36
42
  export {
@@ -40,8 +46,14 @@ export {
40
46
  default2 as debounce,
41
47
  duration,
42
48
  easing,
49
+ emulateTouchEnd,
50
+ emulateTouchMove,
51
+ emulateTouchStart,
43
52
  default10 as getBoundingClientRect,
44
- default9 as getRootElement,
53
+ getClientRect,
54
+ getNewDirectionLocation,
55
+ default9 as getRootContainer,
56
+ getScrollRect,
45
57
  getStylesAndLocation,
46
58
  getTransitionProps,
47
59
  isAlipay,
@@ -53,6 +65,7 @@ export {
53
65
  default5 as setRef,
54
66
  default6 as throttle,
55
67
  default7 as toArray,
68
+ touchEmulator,
56
69
  triggerEventTransform,
57
70
  useDidMountEffect,
58
71
  useDomCss,
package/es/isMini.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  declare const isMini: boolean;
2
2
  declare const isWeapp: boolean;
3
3
  declare const isAlipay: boolean;
4
- export { isMini, isWeapp, isAlipay };
4
+ declare const isTt: boolean;
5
+ export { isMini, isWeapp, isAlipay, isTt };
5
6
  export declare const isMiniapp: () => boolean;
package/es/isMini.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const isMini = typeof process.env.TARO_ENV === "string";
2
2
  const isWeapp = process.env.TARO_ENV === "weapp";
3
3
  const isAlipay = process.env.TARO_ENV === "alipay";
4
+ const isTt = process.env.TARO_ENV === "tt";
4
5
  const isMiniapp = () => {
5
6
  return isMini;
6
7
  };
@@ -8,5 +9,6 @@ export {
8
9
  isAlipay,
9
10
  isMini,
10
11
  isMiniapp,
12
+ isTt,
11
13
  isWeapp
12
14
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bifrostui/utils",
3
- "version": "1.4.6",
3
+ "version": "1.4.7-beta.0",
4
4
  "description": "BUI React utilities for building components.",
5
5
  "main": "dist/index.js",
6
6
  "module": "es/index.js",
@@ -1,2 +0,0 @@
1
- declare const getRootElement: (rootEle?: HTMLElement | (() => HTMLElement)) => HTMLElement;
2
- export default getRootElement;
@@ -1,3 +0,0 @@
1
- import type { TaroElement } from '@tarojs/runtime';
2
- declare const getRootElement: (rootEle?: TaroElement | (() => TaroElement)) => HTMLElement | TaroElement;
3
- export default getRootElement;
@@ -1,2 +0,0 @@
1
- declare const getRootElement: (rootEle?: HTMLElement | (() => HTMLElement)) => HTMLElement;
2
- export default getRootElement;
@@ -1,9 +0,0 @@
1
- const getRootElement = (rootEle) => {
2
- const rootElement = typeof rootEle === "function" ? rootEle() : rootEle;
3
- const defaultRootElement = document.body;
4
- return rootElement || defaultRootElement;
5
- };
6
- var getRootElement_default = getRootElement;
7
- export {
8
- getRootElement_default as default
9
- };
@@ -1,3 +0,0 @@
1
- import type { TaroElement } from '@tarojs/runtime';
2
- declare const getRootElement: (rootEle?: TaroElement | (() => TaroElement)) => HTMLElement | TaroElement;
3
- export default getRootElement;