@bifrostui/utils 2.0.0-alpha.0 → 2.0.0-alpha.2

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 (68) hide show
  1. package/dist/directionLocationUtil.d.ts +27 -12
  2. package/dist/directionLocationUtil.js +101 -55
  3. package/dist/domUtils/addClass.d.ts +1 -0
  4. package/dist/domUtils/addClass.js +46 -0
  5. package/dist/domUtils/index.d.ts +3 -0
  6. package/dist/domUtils/index.js +35 -0
  7. package/dist/domUtils/index.miniapp.d.ts +3 -0
  8. package/dist/domUtils/index.miniapp.js +35 -0
  9. package/dist/domUtils/rect.d.ts +12 -0
  10. package/dist/domUtils/rect.js +46 -0
  11. package/dist/domUtils/rect.miniapp.d.ts +2 -0
  12. package/dist/domUtils/rect.miniapp.js +86 -0
  13. package/dist/domUtils/removeClass.d.ts +1 -0
  14. package/dist/domUtils/removeClass.js +47 -0
  15. package/dist/getBoundingClientRect/index.d.ts +1 -1
  16. package/dist/getBoundingClientRect/index.js +13 -0
  17. package/dist/getBoundingClientRect/index.miniapp.d.ts +1 -2
  18. package/dist/getBoundingClientRect/index.miniapp.js +34 -5
  19. package/dist/getRootContainer/index.d.ts +2 -0
  20. package/dist/{getRootElement → getRootContainer}/index.js +8 -8
  21. package/dist/getRootContainer/index.miniapp.d.ts +3 -0
  22. package/dist/{getRootElement → getRootContainer}/index.miniapp.js +4 -4
  23. package/dist/hooks/index.d.ts +2 -2
  24. package/dist/hooks/index.js +8 -0
  25. package/dist/hooks/useTouchEmulator.d.ts +7 -1
  26. package/dist/hooks/useTouchEmulator.js +36 -10
  27. package/dist/index.d.ts +4 -3
  28. package/dist/index.js +15 -3
  29. package/dist/isMini.d.ts +2 -1
  30. package/dist/isMini.js +3 -0
  31. package/dist/render.d.ts +2 -2
  32. package/es/directionLocationUtil.d.ts +27 -12
  33. package/es/directionLocationUtil.js +91 -55
  34. package/es/domUtils/addClass.d.ts +1 -0
  35. package/es/domUtils/addClass.js +23 -0
  36. package/es/domUtils/index.d.ts +3 -0
  37. package/es/domUtils/index.js +9 -0
  38. package/es/domUtils/index.miniapp.d.ts +3 -0
  39. package/es/domUtils/index.miniapp.js +9 -0
  40. package/es/domUtils/rect.d.ts +12 -0
  41. package/es/domUtils/rect.js +22 -0
  42. package/es/domUtils/rect.miniapp.d.ts +2 -0
  43. package/es/domUtils/rect.miniapp.js +54 -0
  44. package/es/domUtils/removeClass.d.ts +1 -0
  45. package/es/domUtils/removeClass.js +24 -0
  46. package/es/getBoundingClientRect/index.d.ts +1 -1
  47. package/es/getBoundingClientRect/index.js +13 -0
  48. package/es/getBoundingClientRect/index.miniapp.d.ts +1 -2
  49. package/es/getBoundingClientRect/index.miniapp.js +34 -5
  50. package/es/getRootContainer/index.d.ts +2 -0
  51. package/es/getRootContainer/index.js +9 -0
  52. package/es/getRootContainer/index.miniapp.d.ts +3 -0
  53. package/es/{getRootElement → getRootContainer}/index.miniapp.js +4 -4
  54. package/es/hooks/index.d.ts +2 -2
  55. package/es/hooks/index.js +10 -1
  56. package/es/hooks/useTouchEmulator.d.ts +7 -1
  57. package/es/hooks/useTouchEmulator.js +29 -10
  58. package/es/index.d.ts +4 -3
  59. package/es/index.js +13 -2
  60. package/es/isMini.d.ts +2 -1
  61. package/es/isMini.js +2 -0
  62. package/es/render.d.ts +2 -2
  63. package/package.json +2 -2
  64. package/dist/getRootElement/index.d.ts +0 -2
  65. package/dist/getRootElement/index.miniapp.d.ts +0 -3
  66. package/es/getRootElement/index.d.ts +0 -2
  67. package/es/getRootElement/index.js +0 -9
  68. package/es/getRootElement/index.miniapp.d.ts +0 -3
@@ -1,12 +1,31 @@
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+ import { getScrollRect, getClientRect } from "./domUtils";
22
+ import getBoundingClientRect from "./getBoundingClientRect";
1
23
  const directionCssMap = {
2
24
  left: "right",
3
25
  right: "left",
4
26
  top: "bottom",
5
27
  bottom: "top"
6
28
  };
7
- const isBodyScroll = (scrollRoot) => {
8
- return scrollRoot === document.body;
9
- };
10
29
  const getNewDirectionLocation = ({
11
30
  scrollRoot,
12
31
  scrollRootOffset,
@@ -29,14 +48,15 @@ const getNewDirectionLocation = ({
29
48
  top: sTop,
30
49
  bottom: sBottom,
31
50
  left: sLeft,
32
- right: sRight
51
+ right: sRight,
52
+ width: pageWidth,
53
+ height: pageHeight
33
54
  } = scrollRootOffset;
34
- const pageWidth = document.documentElement.clientWidth || document.body.clientWidth;
35
- const pageHeight = document.documentElement.clientHeight || document.body.clientHeight;
36
- const maxTop = isBodyScroll(scrollRoot) ? 0 : sTop;
37
- const maxBottom = isBodyScroll(scrollRoot) ? pageHeight : sBottom;
38
- const maxLeft = isBodyScroll(scrollRoot) ? 0 : sLeft;
39
- const maxRight = isBodyScroll(scrollRoot) ? pageWidth : sRight;
55
+ const isBodyRoot = !scrollRoot;
56
+ const maxTop = isBodyRoot ? 0 : sTop;
57
+ const maxBottom = isBodyRoot ? pageHeight : sBottom;
58
+ const maxLeft = isBodyRoot ? 0 : sLeft;
59
+ const maxRight = isBodyRoot ? pageWidth : sRight;
40
60
  let newArrowDirection = arrowDirection;
41
61
  let newArrowLocation = arrowLocation;
42
62
  const isDirectionTop = arrowDirection === "top";
@@ -71,16 +91,14 @@ const getNewDirectionLocation = ({
71
91
  newArrowLocation
72
92
  };
73
93
  };
74
- const getDirectionLocationStyle = ({
94
+ const getDirectionLocationStyle = (_0) => __async(void 0, [_0], function* ({
75
95
  childrenOffset,
76
96
  arrowDirection,
77
97
  tipOffset,
78
98
  arrowLocation,
79
99
  offsetSpacing
80
- }) => {
81
- const scrollTop = window.scrollY >= 0 && window.scrollY || document.documentElement.scrollTop;
82
- const scrollLeft = window.scrollX >= 0 && window.scrollX || document.documentElement.scrollLeft;
83
- const styles = {};
100
+ }) {
101
+ const { top: scrollTop, left: scrollLeft } = yield getScrollRect();
84
102
  const {
85
103
  width: cWidth,
86
104
  height: cHeight,
@@ -94,107 +112,125 @@ const getDirectionLocationStyle = ({
94
112
  childrenStyle = { width: `${cWidth}px`, height: `${cHeight}px` };
95
113
  }
96
114
  const { width, height } = tipOffset;
115
+ let styleTop;
116
+ let styleLeft;
97
117
  if (arrowDirection === "top") {
98
- styles.top = cTop - offsetSpacing - height;
118
+ styleTop = cTop - offsetSpacing - height;
99
119
  switch (arrowLocation) {
100
120
  case "left":
101
- styles.left = cLeft;
121
+ styleLeft = cLeft;
102
122
  break;
103
123
  case "center":
104
- styles.left = cLeft + (cWidth - width) / 2;
124
+ styleLeft = cLeft + (cWidth - width) / 2;
105
125
  break;
106
126
  case "right":
107
- styles.left = cRight - width;
127
+ styleLeft = cRight - width;
108
128
  break;
109
129
  case "none":
110
- styles.left = cLeft;
130
+ styleLeft = cLeft;
111
131
  break;
112
132
  default:
113
133
  break;
114
134
  }
115
135
  } else if (arrowDirection === "bottom") {
116
- styles.top = cBottom + offsetSpacing;
136
+ styleTop = cBottom + offsetSpacing;
117
137
  switch (arrowLocation) {
118
138
  case "left":
119
- styles.left = cLeft;
139
+ styleLeft = cLeft;
120
140
  break;
121
141
  case "center":
122
- styles.left = cLeft + (cWidth - width) / 2;
142
+ styleLeft = cLeft + (cWidth - width) / 2;
123
143
  break;
124
144
  case "right":
125
- styles.left = cRight - width;
145
+ styleLeft = cRight - width;
126
146
  break;
127
147
  case "none":
128
- styles.left = cLeft;
148
+ styleLeft = cLeft;
129
149
  break;
130
150
  default:
131
151
  break;
132
152
  }
133
153
  } else if (arrowDirection === "left") {
134
- styles.left = cLeft - offsetSpacing - width;
154
+ styleLeft = cLeft - offsetSpacing - width;
135
155
  switch (arrowLocation) {
136
156
  case "top":
137
- styles.top = cTop;
157
+ styleTop = cTop;
138
158
  break;
139
159
  case "center":
140
- styles.top = cTop + (cHeight - height) / 2;
160
+ styleTop = cTop + (cHeight - height) / 2;
141
161
  break;
142
162
  case "bottom":
143
- styles.top = cBottom - height;
163
+ styleTop = cBottom - height;
144
164
  break;
145
165
  case "none":
146
- styles.top = cTop;
166
+ styleTop = cTop;
147
167
  break;
148
168
  default:
149
169
  break;
150
170
  }
151
171
  } else if (arrowDirection === "right") {
152
- styles.left = cRight + offsetSpacing;
172
+ styleLeft = cRight + offsetSpacing;
153
173
  switch (arrowLocation) {
154
174
  case "top":
155
- styles.top = cTop;
175
+ styleTop = cTop;
156
176
  break;
157
177
  case "center":
158
- styles.top = cTop + (cHeight - height) / 2;
178
+ styleTop = cTop + (cHeight - height) / 2;
159
179
  break;
160
180
  case "bottom":
161
- styles.top = cBottom - height;
181
+ styleTop = cBottom - height;
162
182
  break;
163
183
  case "none":
164
- styles.top = cTop;
184
+ styleTop = cTop;
165
185
  break;
166
186
  default:
167
187
  break;
168
188
  }
169
189
  }
170
- if (styles.top) {
171
- styles.top = `${styles.top + scrollTop}px`;
190
+ if (styleTop) {
191
+ styleTop = `${styleTop + scrollTop}px`;
172
192
  }
173
- if (styles.left) {
174
- styles.left = `${styles.left + scrollLeft}px`;
193
+ if (styleLeft) {
194
+ styleLeft = `${styleLeft + scrollLeft}px`;
175
195
  }
196
+ const styles = {
197
+ top: 0,
198
+ left: 0,
199
+ transform: `translate3d(${styleLeft}, ${styleTop}, 0)`,
200
+ visibility: ""
201
+ };
176
202
  return { styles, childrenStyle };
177
- };
178
- const getStylesAndLocation = ({
179
- scrollRoot = document.body,
203
+ });
204
+ const getStylesAndLocation = (_0) => __async(void 0, [_0], function* ({
205
+ scrollRoot,
180
206
  childrenRef,
181
- arrowDirection,
182
- arrowLocation,
183
- offsetSpacing,
184
- selector
185
- }) => {
207
+ tipRef,
208
+ arrowDirection = "top",
209
+ arrowLocation = "center",
210
+ offsetSpacing = 0
211
+ }) {
186
212
  if (!(childrenRef == null ? void 0 : childrenRef.current)) {
187
213
  console.error(
188
214
  "\u7EC4\u4EF6\u5305\u88F9\u7684children\u53EF\u80FD\u662F\u4E00\u4E2A\u7EC4\u4EF6\uFF0C\u60A8\u7684\u5F53\u524D\u5199\u6CD5\u53EF\u80FD\u5BFC\u81F4ref\u6CA1\u6709\u7ED1\u5B9A\u5230children\u4E0A\uFF0C\u8BF7\u5C1D\u8BD5\u5BF9children\u5BF9\u5E94\u7684\u7EC4\u4EF6\u4F7F\u7528/* @__PURE__ */ React.forwardRef\u6765\u89E3\u51B3"
189
215
  );
190
216
  return null;
191
217
  }
192
- const childrenOffset = childrenRef.current.getBoundingClientRect();
193
- const $rtDom = document.querySelector(selector);
194
- if (!$rtDom)
195
- return null;
196
- const tipOffset = $rtDom.getBoundingClientRect();
197
- const scrollRootOffset = scrollRoot.getBoundingClientRect();
218
+ const childrenOffset = yield getBoundingClientRect(childrenRef.current);
219
+ const tipOffset = yield getBoundingClientRect(tipRef.current);
220
+ if (!tipOffset || !childrenOffset) {
221
+ return {
222
+ styles: {},
223
+ childrenStyle: {},
224
+ newArrowDirection: arrowDirection,
225
+ newArrowLocation: arrowLocation
226
+ };
227
+ }
228
+ let scrollRootOffset;
229
+ if (scrollRoot) {
230
+ scrollRootOffset = yield getBoundingClientRect(scrollRoot);
231
+ } else {
232
+ scrollRootOffset = yield getClientRect();
233
+ }
198
234
  const { newArrowDirection, newArrowLocation } = getNewDirectionLocation({
199
235
  scrollRoot,
200
236
  scrollRootOffset,
@@ -204,7 +240,7 @@ const getStylesAndLocation = ({
204
240
  arrowLocation,
205
241
  offsetSpacing
206
242
  });
207
- const { styles, childrenStyle } = getDirectionLocationStyle({
243
+ const { styles, childrenStyle } = yield getDirectionLocationStyle({
208
244
  childrenOffset,
209
245
  arrowDirection: newArrowDirection,
210
246
  tipOffset,
@@ -218,7 +254,7 @@ const getStylesAndLocation = ({
218
254
  newArrowDirection,
219
255
  newArrowLocation
220
256
  };
221
- };
257
+ });
222
258
  const onMouseEnter = "onMouseEnter";
223
259
  const onMouseLeave = "onMouseLeave";
224
260
  const onClick = "onClick";
@@ -0,0 +1 @@
1
+ export declare const addClass: (element: Element | SVGElement, className: string) => void;
@@ -0,0 +1,23 @@
1
+ const hasClass = (element, className) => {
2
+ if (element.classList)
3
+ return !!className && element.classList.contains(className);
4
+ return ` ${element.className.baseVal || element.className} `.indexOf(
5
+ ` ${className} `
6
+ ) !== -1;
7
+ };
8
+ const addClass = (element, className) => {
9
+ if (element.classList) {
10
+ element.classList.add(className);
11
+ } else if (!hasClass(element, className))
12
+ if (typeof element.className === "string") {
13
+ element.className = `${element.className} ${className}`;
14
+ } else {
15
+ element.setAttribute(
16
+ "class",
17
+ `${element.className && element.className.baseVal || ""} ${className}`
18
+ );
19
+ }
20
+ };
21
+ export {
22
+ addClass
23
+ };
@@ -0,0 +1,3 @@
1
+ export { getClientRect, getScrollRect } from './rect';
2
+ export { addClass } from './addClass';
3
+ export { removeClass } from './removeClass';
@@ -0,0 +1,9 @@
1
+ import { getClientRect, getScrollRect } from "./rect";
2
+ import { addClass } from "./addClass";
3
+ import { removeClass } from "./removeClass";
4
+ export {
5
+ addClass,
6
+ getClientRect,
7
+ getScrollRect,
8
+ removeClass
9
+ };
@@ -0,0 +1,3 @@
1
+ export { getClientRect, getScrollRect } from './rect';
2
+ export { addClass } from './addClass';
3
+ export { removeClass } from './removeClass';
@@ -0,0 +1,9 @@
1
+ import { getClientRect, getScrollRect } from "./rect";
2
+ import { addClass } from "./addClass";
3
+ import { removeClass } from "./removeClass";
4
+ export {
5
+ addClass,
6
+ getClientRect,
7
+ getScrollRect,
8
+ removeClass
9
+ };
@@ -0,0 +1,12 @@
1
+ export declare const getClientRect: () => Promise<{
2
+ width: number;
3
+ height: number;
4
+ left: number;
5
+ top: number;
6
+ right: number;
7
+ bottom: number;
8
+ }>;
9
+ export declare const getScrollRect: () => Promise<{
10
+ top: number;
11
+ left: number;
12
+ }>;
@@ -0,0 +1,22 @@
1
+ const getClientRect = () => {
2
+ const width = window.innerWidth || document.documentElement.clientWidth;
3
+ const height = window.innerHeight || document.documentElement.clientHeight;
4
+ return Promise.resolve({
5
+ width,
6
+ height,
7
+ left: 0,
8
+ top: 0,
9
+ right: width,
10
+ bottom: height
11
+ });
12
+ };
13
+ const getScrollRect = () => {
14
+ return Promise.resolve({
15
+ top: window.scrollY >= 0 && window.scrollY || document.documentElement.scrollTop,
16
+ left: window.scrollX >= 0 && window.scrollX || document.documentElement.scrollLeft
17
+ });
18
+ };
19
+ export {
20
+ getClientRect,
21
+ getScrollRect
22
+ };
@@ -0,0 +1,2 @@
1
+ export declare const getClientRect: () => Promise<unknown>;
2
+ export declare const getScrollRect: () => Promise<unknown>;
@@ -0,0 +1,54 @@
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;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ import Taro from "@tarojs/taro";
21
+ const getClientRect = () => {
22
+ return new Promise((resolve, reject) => {
23
+ try {
24
+ const res = Taro.getSystemInfoSync();
25
+ const width = res.windowWidth;
26
+ const height = res.windowHeight;
27
+ const clientInfo = __spreadProps(__spreadValues({}, res), {
28
+ width,
29
+ height,
30
+ left: 0,
31
+ top: 0,
32
+ right: width,
33
+ bottom: height
34
+ });
35
+ resolve(clientInfo);
36
+ } catch (error) {
37
+ reject(error);
38
+ }
39
+ });
40
+ };
41
+ const getScrollRect = () => {
42
+ return new Promise((resolve) => {
43
+ Taro.createSelectorQuery().selectViewport().scrollOffset().exec((res) => {
44
+ resolve({
45
+ top: res[0].scrollTop,
46
+ left: res[0].scrollLeft
47
+ });
48
+ });
49
+ });
50
+ };
51
+ export {
52
+ getClientRect,
53
+ getScrollRect
54
+ };
@@ -0,0 +1 @@
1
+ export declare const removeClass: (element: Element | SVGElement, className: string) => void;
@@ -0,0 +1,24 @@
1
+ const replaceClassName = (origClass, classToRemove) => {
2
+ return origClass.replace(new RegExp(`(^|\\s)${classToRemove}(?:\\s|$)`, "g"), "$1").replace(/\s+/g, " ").replace(/^\s*|\s*$/g, "");
3
+ };
4
+ const removeClass = (element, className) => {
5
+ if (element.classList) {
6
+ element.classList.remove(className);
7
+ } else if (typeof element.className === "string") {
8
+ element.className = replaceClassName(
9
+ element.className,
10
+ className
11
+ );
12
+ } else {
13
+ element.setAttribute(
14
+ "class",
15
+ replaceClassName(
16
+ element.className && element.className.baseVal || "",
17
+ className
18
+ )
19
+ );
20
+ }
21
+ };
22
+ export {
23
+ removeClass
24
+ };
@@ -1 +1 @@
1
- export default function getBoundingClientRect(ele: Element): Promise<DOMRect>;
1
+ export default function getBoundingClientRect(ele: Element | null): Promise<DOMRect>;
@@ -1,4 +1,17 @@
1
1
  function getBoundingClientRect(ele) {
2
+ if (!ele) {
3
+ return Promise.resolve({
4
+ width: 0,
5
+ height: 0,
6
+ top: 0,
7
+ right: 0,
8
+ bottom: 0,
9
+ left: 0,
10
+ x: 0,
11
+ y: 0,
12
+ toJSON: () => ({})
13
+ });
14
+ }
2
15
  return Promise.resolve(ele.getBoundingClientRect());
3
16
  }
4
17
  export {
@@ -1,2 +1 @@
1
- import type { TaroElement } from '@tarojs/runtime';
2
- export default function getBoundingClientRect(ele: TaroElement): Promise<DOMRect>;
1
+ export default function getBoundingClientRect(ele: any): Promise<DOMRect>;
@@ -1,10 +1,39 @@
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
1
21
  import Taro from "@tarojs/taro";
22
+ import { isTt, isWeapp } from "../isMini";
2
23
  function getBoundingClientRect(ele) {
3
- return new Promise((resolve) => {
4
- const query = Taro.createSelectorQuery();
5
- query.select(`#${ele.uid}`).boundingClientRect().exec(([res]) => {
6
- resolve(res);
7
- });
24
+ return __async(this, null, function* () {
25
+ let result;
26
+ if (isWeapp || isTt) {
27
+ result = yield ele.getBoundingClientRect();
28
+ } else {
29
+ const query = Taro.createSelectorQuery();
30
+ result = yield new Promise((resolve) => {
31
+ query.select(`#${ele.uid}`).boundingClientRect().exec(([res]) => {
32
+ resolve(res);
33
+ });
34
+ });
35
+ }
36
+ return result;
8
37
  });
9
38
  }
10
39
  export {
@@ -0,0 +1,2 @@
1
+ declare const getRootContainer: (rootCon?: HTMLElement | (() => HTMLElement) | Window, defaultCon?: any) => any;
2
+ export default getRootContainer;
@@ -0,0 +1,9 @@
1
+ const getRootContainer = (rootCon, defaultCon) => {
2
+ const rootElement = typeof rootCon === "function" ? rootCon() : rootCon;
3
+ const defaultRootElement = document.body;
4
+ return rootElement || defaultCon || defaultRootElement;
5
+ };
6
+ var getRootContainer_default = getRootContainer;
7
+ export {
8
+ getRootContainer_default as default
9
+ };
@@ -0,0 +1,3 @@
1
+ import type { TaroElement } from '@tarojs/runtime';
2
+ declare const getRootContainer: (rootCon?: TaroElement | (() => TaroElement), defaultCon?: any) => any;
3
+ export default getRootContainer;
@@ -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
  };