@bifrostui/utils 1.4.7 → 1.5.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
@@ -22,26 +22,41 @@ export declare const getDirectionLocationStyle: ({ childrenOffset, arrowDirectio
22
22
  tipOffset: any;
23
23
  arrowLocation: any;
24
24
  offsetSpacing: any;
25
- }) => {
26
- styles: any;
25
+ }) => Promise<{
26
+ styles: {
27
+ top: number;
28
+ left: number;
29
+ transform: string;
30
+ visibility: string;
31
+ };
27
32
  childrenStyle: any;
28
- };
33
+ }>;
29
34
  /**
30
35
  * 获取气泡位置和箭头位置
31
36
  */
32
- export declare const getStylesAndLocation: ({ scrollRoot, childrenRef, arrowDirection, arrowLocation, offsetSpacing, selector, }: {
37
+ export declare const getStylesAndLocation: ({ scrollRoot, childrenRef, tipRef, arrowDirection, arrowLocation, offsetSpacing, }: {
33
38
  scrollRoot?: Element;
34
- childrenRef: any;
35
- arrowDirection: any;
36
- arrowLocation: any;
37
- offsetSpacing: any;
38
- selector: any;
39
- }) => {
40
- styles: any;
39
+ childrenRef?: React.RefObject<any>;
40
+ tipRef?: React.RefObject<any>;
41
+ arrowDirection: string;
42
+ arrowLocation: string;
43
+ offsetSpacing?: number;
44
+ }) => Promise<{
45
+ styles: {};
46
+ childrenStyle: {};
47
+ newArrowDirection: string;
48
+ newArrowLocation: string;
49
+ } | {
50
+ styles: {
51
+ top: number;
52
+ left: number;
53
+ transform: string;
54
+ visibility: string;
55
+ };
41
56
  childrenStyle: any;
42
57
  newArrowDirection: any;
43
58
  newArrowLocation: any;
44
- };
59
+ }>;
45
60
  export declare const triggerEventTransform: ({ trigger, click, show, hide }: {
46
61
  trigger: any;
47
62
  click: any;
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,7 +16,35 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
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
+ ));
17
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var __async = (__this, __arguments, generator) => {
29
+ return new Promise((resolve, reject) => {
30
+ var fulfilled = (value) => {
31
+ try {
32
+ step(generator.next(value));
33
+ } catch (e) {
34
+ reject(e);
35
+ }
36
+ };
37
+ var rejected = (value) => {
38
+ try {
39
+ step(generator.throw(value));
40
+ } catch (e) {
41
+ reject(e);
42
+ }
43
+ };
44
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
45
+ step((generator = generator.apply(__this, __arguments)).next());
46
+ });
47
+ };
18
48
  var directionLocationUtil_exports = {};
19
49
  __export(directionLocationUtil_exports, {
20
50
  getDirectionLocationStyle: () => getDirectionLocationStyle,
@@ -24,15 +54,14 @@ __export(directionLocationUtil_exports, {
24
54
  triggerEventTransform: () => triggerEventTransform
25
55
  });
26
56
  module.exports = __toCommonJS(directionLocationUtil_exports);
57
+ var import_domUtils = require("./domUtils");
58
+ var import_getBoundingClientRect = __toESM(require("./getBoundingClientRect"));
27
59
  const directionCssMap = {
28
60
  left: "right",
29
61
  right: "left",
30
62
  top: "bottom",
31
63
  bottom: "top"
32
64
  };
33
- const isBodyScroll = (scrollRoot) => {
34
- return scrollRoot === document.body;
35
- };
36
65
  const getNewDirectionLocation = ({
37
66
  scrollRoot,
38
67
  scrollRootOffset,
@@ -55,14 +84,15 @@ const getNewDirectionLocation = ({
55
84
  top: sTop,
56
85
  bottom: sBottom,
57
86
  left: sLeft,
58
- right: sRight
87
+ right: sRight,
88
+ width: pageWidth,
89
+ height: pageHeight
59
90
  } = scrollRootOffset;
60
- const pageWidth = document.documentElement.clientWidth || document.body.clientWidth;
61
- const pageHeight = document.documentElement.clientHeight || document.body.clientHeight;
62
- const maxTop = isBodyScroll(scrollRoot) ? 0 : sTop;
63
- const maxBottom = isBodyScroll(scrollRoot) ? pageHeight : sBottom;
64
- const maxLeft = isBodyScroll(scrollRoot) ? 0 : sLeft;
65
- const maxRight = isBodyScroll(scrollRoot) ? pageWidth : sRight;
91
+ const isBodyRoot = !scrollRoot;
92
+ const maxTop = isBodyRoot ? 0 : sTop;
93
+ const maxBottom = isBodyRoot ? pageHeight : sBottom;
94
+ const maxLeft = isBodyRoot ? 0 : sLeft;
95
+ const maxRight = isBodyRoot ? pageWidth : sRight;
66
96
  let newArrowDirection = arrowDirection;
67
97
  let newArrowLocation = arrowLocation;
68
98
  const isDirectionTop = arrowDirection === "top";
@@ -97,16 +127,14 @@ const getNewDirectionLocation = ({
97
127
  newArrowLocation
98
128
  };
99
129
  };
100
- const getDirectionLocationStyle = ({
130
+ const getDirectionLocationStyle = (_0) => __async(void 0, [_0], function* ({
101
131
  childrenOffset,
102
132
  arrowDirection,
103
133
  tipOffset,
104
134
  arrowLocation,
105
135
  offsetSpacing
106
- }) => {
107
- const scrollTop = window.scrollY >= 0 && window.scrollY || document.documentElement.scrollTop;
108
- const scrollLeft = window.scrollX >= 0 && window.scrollX || document.documentElement.scrollLeft;
109
- const styles = {};
136
+ }) {
137
+ const { top: scrollTop, left: scrollLeft } = yield (0, import_domUtils.getScrollRect)();
110
138
  const {
111
139
  width: cWidth,
112
140
  height: cHeight,
@@ -120,107 +148,125 @@ const getDirectionLocationStyle = ({
120
148
  childrenStyle = { width: `${cWidth}px`, height: `${cHeight}px` };
121
149
  }
122
150
  const { width, height } = tipOffset;
151
+ let styleTop;
152
+ let styleLeft;
123
153
  if (arrowDirection === "top") {
124
- styles.top = cTop - offsetSpacing - height;
154
+ styleTop = cTop - offsetSpacing - height;
125
155
  switch (arrowLocation) {
126
156
  case "left":
127
- styles.left = cLeft;
157
+ styleLeft = cLeft;
128
158
  break;
129
159
  case "center":
130
- styles.left = cLeft + (cWidth - width) / 2;
160
+ styleLeft = cLeft + (cWidth - width) / 2;
131
161
  break;
132
162
  case "right":
133
- styles.left = cRight - width;
163
+ styleLeft = cRight - width;
134
164
  break;
135
165
  case "none":
136
- styles.left = cLeft;
166
+ styleLeft = cLeft;
137
167
  break;
138
168
  default:
139
169
  break;
140
170
  }
141
171
  } else if (arrowDirection === "bottom") {
142
- styles.top = cBottom + offsetSpacing;
172
+ styleTop = cBottom + offsetSpacing;
143
173
  switch (arrowLocation) {
144
174
  case "left":
145
- styles.left = cLeft;
175
+ styleLeft = cLeft;
146
176
  break;
147
177
  case "center":
148
- styles.left = cLeft + (cWidth - width) / 2;
178
+ styleLeft = cLeft + (cWidth - width) / 2;
149
179
  break;
150
180
  case "right":
151
- styles.left = cRight - width;
181
+ styleLeft = cRight - width;
152
182
  break;
153
183
  case "none":
154
- styles.left = cLeft;
184
+ styleLeft = cLeft;
155
185
  break;
156
186
  default:
157
187
  break;
158
188
  }
159
189
  } else if (arrowDirection === "left") {
160
- styles.left = cLeft - offsetSpacing - width;
190
+ styleLeft = cLeft - offsetSpacing - width;
161
191
  switch (arrowLocation) {
162
192
  case "top":
163
- styles.top = cTop;
193
+ styleTop = cTop;
164
194
  break;
165
195
  case "center":
166
- styles.top = cTop + (cHeight - height) / 2;
196
+ styleTop = cTop + (cHeight - height) / 2;
167
197
  break;
168
198
  case "bottom":
169
- styles.top = cBottom - height;
199
+ styleTop = cBottom - height;
170
200
  break;
171
201
  case "none":
172
- styles.top = cTop;
202
+ styleTop = cTop;
173
203
  break;
174
204
  default:
175
205
  break;
176
206
  }
177
207
  } else if (arrowDirection === "right") {
178
- styles.left = cRight + offsetSpacing;
208
+ styleLeft = cRight + offsetSpacing;
179
209
  switch (arrowLocation) {
180
210
  case "top":
181
- styles.top = cTop;
211
+ styleTop = cTop;
182
212
  break;
183
213
  case "center":
184
- styles.top = cTop + (cHeight - height) / 2;
214
+ styleTop = cTop + (cHeight - height) / 2;
185
215
  break;
186
216
  case "bottom":
187
- styles.top = cBottom - height;
217
+ styleTop = cBottom - height;
188
218
  break;
189
219
  case "none":
190
- styles.top = cTop;
220
+ styleTop = cTop;
191
221
  break;
192
222
  default:
193
223
  break;
194
224
  }
195
225
  }
196
- if (styles.top) {
197
- styles.top = `${styles.top + scrollTop}px`;
226
+ if (styleTop) {
227
+ styleTop = `${styleTop + scrollTop}px`;
198
228
  }
199
- if (styles.left) {
200
- styles.left = `${styles.left + scrollLeft}px`;
229
+ if (styleLeft) {
230
+ styleLeft = `${styleLeft + scrollLeft}px`;
201
231
  }
232
+ const styles = {
233
+ top: 0,
234
+ left: 0,
235
+ transform: `translate3d(${styleLeft}, ${styleTop}, 0)`,
236
+ visibility: ""
237
+ };
202
238
  return { styles, childrenStyle };
203
- };
204
- const getStylesAndLocation = ({
205
- scrollRoot = document.body,
239
+ });
240
+ const getStylesAndLocation = (_0) => __async(void 0, [_0], function* ({
241
+ scrollRoot,
206
242
  childrenRef,
207
- arrowDirection,
208
- arrowLocation,
209
- offsetSpacing,
210
- selector
211
- }) => {
243
+ tipRef,
244
+ arrowDirection = "top",
245
+ arrowLocation = "center",
246
+ offsetSpacing = 0
247
+ }) {
212
248
  if (!(childrenRef == null ? void 0 : childrenRef.current)) {
213
249
  console.error(
214
250
  "\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"
215
251
  );
216
252
  return null;
217
253
  }
218
- const childrenOffset = childrenRef.current.getBoundingClientRect();
219
- const $rtDom = document.querySelector(selector);
220
- if (!$rtDom)
221
- return null;
222
- const tipOffset = $rtDom.getBoundingClientRect();
223
- const scrollRootOffset = scrollRoot.getBoundingClientRect();
254
+ const childrenOffset = yield (0, import_getBoundingClientRect.default)(childrenRef.current);
255
+ const tipOffset = yield (0, import_getBoundingClientRect.default)(tipRef.current);
256
+ if (!tipOffset || !childrenOffset) {
257
+ return {
258
+ styles: {},
259
+ childrenStyle: {},
260
+ newArrowDirection: arrowDirection,
261
+ newArrowLocation: arrowLocation
262
+ };
263
+ }
264
+ let scrollRootOffset;
265
+ if (scrollRoot) {
266
+ scrollRootOffset = yield (0, import_getBoundingClientRect.default)(scrollRoot);
267
+ } else {
268
+ scrollRootOffset = yield (0, import_domUtils.getClientRect)();
269
+ }
224
270
  const { newArrowDirection, newArrowLocation } = getNewDirectionLocation({
225
271
  scrollRoot,
226
272
  scrollRootOffset,
@@ -230,7 +276,7 @@ const getStylesAndLocation = ({
230
276
  arrowLocation,
231
277
  offsetSpacing
232
278
  });
233
- const { styles, childrenStyle } = getDirectionLocationStyle({
279
+ const { styles, childrenStyle } = yield getDirectionLocationStyle({
234
280
  childrenOffset,
235
281
  arrowDirection: newArrowDirection,
236
282
  tipOffset,
@@ -244,7 +290,7 @@ const getStylesAndLocation = ({
244
290
  newArrowDirection,
245
291
  newArrowLocation
246
292
  };
247
- };
293
+ });
248
294
  const onMouseEnter = "onMouseEnter";
249
295
  const onMouseLeave = "onMouseLeave";
250
296
  const onClick = "onClick";
@@ -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,46 @@
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
+ var domUtils_exports = {};
19
+ __export(domUtils_exports, {
20
+ getClientRect: () => getClientRect,
21
+ getScrollRect: () => getScrollRect
22
+ });
23
+ module.exports = __toCommonJS(domUtils_exports);
24
+ const getClientRect = () => {
25
+ const width = window.innerWidth || document.documentElement.clientWidth;
26
+ const height = window.innerHeight || document.documentElement.clientHeight;
27
+ return Promise.resolve({
28
+ width,
29
+ height,
30
+ left: 0,
31
+ top: 0,
32
+ right: width,
33
+ bottom: height
34
+ });
35
+ };
36
+ const getScrollRect = () => {
37
+ return Promise.resolve({
38
+ top: window.scrollY >= 0 && window.scrollY || document.documentElement.scrollTop,
39
+ left: window.scrollX >= 0 && window.scrollX || document.documentElement.scrollLeft
40
+ });
41
+ };
42
+ // Annotate the CommonJS export names for ESM import in node:
43
+ 0 && (module.exports = {
44
+ getClientRect,
45
+ getScrollRect
46
+ });
@@ -0,0 +1,2 @@
1
+ export declare const getClientRect: () => Promise<unknown>;
2
+ export declare const getScrollRect: () => Promise<unknown>;
@@ -0,0 +1,86 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var __export = (target, all) => {
25
+ for (var name in all)
26
+ __defProp(target, name, { get: all[name], enumerable: true });
27
+ };
28
+ var __copyProps = (to, from, except, desc) => {
29
+ if (from && typeof from === "object" || typeof from === "function") {
30
+ for (let key of __getOwnPropNames(from))
31
+ if (!__hasOwnProp.call(to, key) && key !== except)
32
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
33
+ }
34
+ return to;
35
+ };
36
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
37
+ // If the importer is in node compatibility mode or this is not an ESM
38
+ // file that has been converted to a CommonJS file using a Babel-
39
+ // compatible transform (i.e. "__esModule" has not been set), then set
40
+ // "default" to the CommonJS "module.exports" for node compatibility.
41
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
42
+ mod
43
+ ));
44
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
45
+ var index_miniapp_exports = {};
46
+ __export(index_miniapp_exports, {
47
+ getClientRect: () => getClientRect,
48
+ getScrollRect: () => getScrollRect
49
+ });
50
+ module.exports = __toCommonJS(index_miniapp_exports);
51
+ var import_taro = __toESM(require("@tarojs/taro"));
52
+ const getClientRect = () => {
53
+ return new Promise((resolve, reject) => {
54
+ try {
55
+ const res = import_taro.default.getSystemInfoSync();
56
+ const width = res.windowWidth;
57
+ const height = res.windowHeight;
58
+ const clientInfo = __spreadProps(__spreadValues({}, res), {
59
+ width,
60
+ height,
61
+ left: 0,
62
+ top: 0,
63
+ right: width,
64
+ bottom: height
65
+ });
66
+ resolve(clientInfo);
67
+ } catch (error) {
68
+ reject(error);
69
+ }
70
+ });
71
+ };
72
+ const getScrollRect = () => {
73
+ return new Promise((resolve) => {
74
+ import_taro.default.createSelectorQuery().selectViewport().scrollOffset().exec((res) => {
75
+ resolve({
76
+ top: res[0].scrollTop,
77
+ left: res[0].scrollLeft
78
+ });
79
+ });
80
+ });
81
+ };
82
+ // Annotate the CommonJS export names for ESM import in node:
83
+ 0 && (module.exports = {
84
+ getClientRect,
85
+ getScrollRect
86
+ });
@@ -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>;
@@ -25,17 +25,46 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
25
25
  mod
26
26
  ));
27
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var __async = (__this, __arguments, generator) => {
29
+ return new Promise((resolve, reject) => {
30
+ var fulfilled = (value) => {
31
+ try {
32
+ step(generator.next(value));
33
+ } catch (e) {
34
+ reject(e);
35
+ }
36
+ };
37
+ var rejected = (value) => {
38
+ try {
39
+ step(generator.throw(value));
40
+ } catch (e) {
41
+ reject(e);
42
+ }
43
+ };
44
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
45
+ step((generator = generator.apply(__this, __arguments)).next());
46
+ });
47
+ };
28
48
  var index_miniapp_exports = {};
29
49
  __export(index_miniapp_exports, {
30
50
  default: () => getBoundingClientRect
31
51
  });
32
52
  module.exports = __toCommonJS(index_miniapp_exports);
33
53
  var import_taro = __toESM(require("@tarojs/taro"));
54
+ var import_isMini = require("../isMini");
34
55
  function getBoundingClientRect(ele) {
35
- return new Promise((resolve) => {
36
- const query = import_taro.default.createSelectorQuery();
37
- query.select(`#${ele.uid}`).boundingClientRect().exec(([res]) => {
38
- resolve(res);
39
- });
56
+ return __async(this, null, function* () {
57
+ let result;
58
+ if (import_isMini.isWeapp || import_isMini.isTt) {
59
+ result = yield ele.getBoundingClientRect();
60
+ } else {
61
+ const query = import_taro.default.createSelectorQuery();
62
+ result = yield new Promise((resolve) => {
63
+ query.select(`#${ele.uid}`).boundingClientRect().exec(([res]) => {
64
+ resolve(res);
65
+ });
66
+ });
67
+ }
68
+ return result;
40
69
  });
41
70
  }
@@ -0,0 +1,2 @@
1
+ declare const getRootContainer: (rootCon?: HTMLElement | (() => HTMLElement) | Window, defaultCon?: any) => any;
2
+ export default getRootContainer;
@@ -15,14 +15,14 @@ var __copyProps = (to, from, except, desc) => {
15
15
  return to;
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var getRootElement_exports = {};
19
- __export(getRootElement_exports, {
20
- default: () => getRootElement_default
18
+ var getRootContainer_exports = {};
19
+ __export(getRootContainer_exports, {
20
+ default: () => getRootContainer_default
21
21
  });
22
- module.exports = __toCommonJS(getRootElement_exports);
23
- const getRootElement = (rootEle) => {
24
- const rootElement = typeof rootEle === "function" ? rootEle() : rootEle;
22
+ module.exports = __toCommonJS(getRootContainer_exports);
23
+ const getRootContainer = (rootCon, defaultCon) => {
24
+ const rootElement = typeof rootCon === "function" ? rootCon() : rootCon;
25
25
  const defaultRootElement = document.body;
26
- return rootElement || defaultRootElement;
26
+ return rootElement || defaultCon || defaultRootElement;
27
27
  };
28
- var getRootElement_default = getRootElement;
28
+ var getRootContainer_default = getRootContainer;
@@ -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;
@@ -31,12 +31,12 @@ __export(index_miniapp_exports, {
31
31
  });
32
32
  module.exports = __toCommonJS(index_miniapp_exports);
33
33
  var import_taro = __toESM(require("@tarojs/taro"));
34
- const getRootElement = (rootEle) => {
34
+ const getRootContainer = (rootCon, defaultCon) => {
35
35
  const currentPages = import_taro.default.getCurrentPages() || [];
36
36
  const currentPage = currentPages[currentPages.length - 1];
37
37
  const pageElement = currentPage == null ? void 0 : currentPage.$taroPath;
38
38
  const defaultRootElement = document.getElementById(pageElement);
39
- const rootElement = typeof rootEle === "function" ? rootEle() : rootEle;
40
- return rootElement || defaultRootElement;
39
+ const rootElement = typeof rootCon === "function" ? rootCon() : rootCon;
40
+ return rootElement || defaultCon || defaultRootElement;
41
41
  };
42
- var index_miniapp_default = getRootElement;
42
+ var index_miniapp_default = getRootContainer;
@@ -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, };
@@ -27,6 +27,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
28
  var hooks_exports = {};
29
29
  __export(hooks_exports, {
30
+ emulateTouchEnd: () => import_useTouchEmulator.emulateTouchEnd,
31
+ emulateTouchMove: () => import_useTouchEmulator.emulateTouchMove,
32
+ emulateTouchStart: () => import_useTouchEmulator.emulateTouchStart,
33
+ touchEmulator: () => import_useTouchEmulator.touchEmulator,
30
34
  useDidMountEffect: () => import_useDidMountEffect.default,
31
35
  useDomCss: () => import_useDomCss.default,
32
36
  useDomReady: () => import_useDomReady.default,
@@ -51,6 +55,10 @@ var import_useTouch = __toESM(require("./useTouch"));
51
55
  var import_useUniqueId = __toESM(require("./useUniqueId"));
52
56
  // Annotate the CommonJS export names for ESM import in node:
53
57
  0 && (module.exports = {
58
+ emulateTouchEnd,
59
+ emulateTouchMove,
60
+ emulateTouchStart,
61
+ touchEmulator,
54
62
  useDidMountEffect,
55
63
  useDomCss,
56
64
  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 };