@bifrostui/utils 1.4.2-beta.1 → 1.4.3-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.
@@ -41,3 +41,12 @@ export declare const triggerEventTransform: ({ trigger, click, show, hide }: {
41
41
  show: any;
42
42
  hide: any;
43
43
  }) => {};
44
+ /**
45
+ * for example: placement = 'topLeft', return { direction: 'top', location: 'left' }
46
+ * @param placement
47
+ * @returns
48
+ */
49
+ export declare const parsePlacement: (placement: any) => {
50
+ direction: any;
51
+ location: any;
52
+ };
@@ -20,6 +20,7 @@ __export(directionLocationUtil_exports, {
20
20
  getDirectionLocationStyle: () => getDirectionLocationStyle,
21
21
  getNewDirectionLocation: () => getNewDirectionLocation,
22
22
  getStylesAndLocation: () => getStylesAndLocation,
23
+ parsePlacement: () => parsePlacement,
23
24
  triggerEventTransform: () => triggerEventTransform
24
25
  });
25
26
  module.exports = __toCommonJS(directionLocationUtil_exports);
@@ -98,8 +99,7 @@ const getDirectionLocationStyle = ({
98
99
  } = rootOffset;
99
100
  const { width, height } = tipOffset;
100
101
  if (arrowDirection === "top") {
101
- styles.top = cTop - offsetSpacing;
102
- styles.transform = `translateY(-100%)`;
102
+ styles.top = cTop - offsetSpacing - height;
103
103
  switch (arrowLocation) {
104
104
  case "left":
105
105
  styles.left = cLeft;
@@ -108,8 +108,7 @@ const getDirectionLocationStyle = ({
108
108
  styles.left = cLeft + (cWidth - width) / 2;
109
109
  break;
110
110
  case "right":
111
- styles.left = cRight;
112
- styles.transform = `translate(-100%, -100%)`;
111
+ styles.left = cRight - width;
113
112
  break;
114
113
  default:
115
114
  break;
@@ -124,15 +123,13 @@ const getDirectionLocationStyle = ({
124
123
  styles.left = cLeft + (cWidth - width) / 2;
125
124
  break;
126
125
  case "right":
127
- styles.left = cRight;
128
- styles.transform = `translateX(-100%)`;
126
+ styles.left = cRight - width;
129
127
  break;
130
128
  default:
131
129
  break;
132
130
  }
133
131
  } else if (arrowDirection === "left") {
134
- styles.left = cLeft - offsetSpacing;
135
- styles.transform = `translateX(-100%)`;
132
+ styles.left = cLeft - offsetSpacing - width;
136
133
  switch (arrowLocation) {
137
134
  case "top":
138
135
  styles.top = cTop;
@@ -141,8 +138,7 @@ const getDirectionLocationStyle = ({
141
138
  styles.top = cTop + (cHeight - height) / 2;
142
139
  break;
143
140
  case "bottom":
144
- styles.top = cBottom;
145
- styles.transform = `translate(-100%, -100%)`;
141
+ styles.top = cBottom - height;
146
142
  break;
147
143
  default:
148
144
  break;
@@ -157,8 +153,7 @@ const getDirectionLocationStyle = ({
157
153
  styles.top = cTop + (cHeight - height) / 2;
158
154
  break;
159
155
  case "bottom":
160
- styles.top = cBottom;
161
- styles.transform = `translateY(-100%)`;
156
+ styles.top = cBottom - height;
162
157
  break;
163
158
  default:
164
159
  break;
@@ -170,7 +165,6 @@ const getDirectionLocationStyle = ({
170
165
  if (styles.left) {
171
166
  styles.left = `${styles.left + scrollLeft}px`;
172
167
  }
173
- styles.width = `${width}px`;
174
168
  return styles;
175
169
  };
176
170
  const getStylesAndLocation = ({
@@ -245,10 +239,24 @@ const triggerEventTransform = ({ trigger, click, show, hide }) => {
245
239
  });
246
240
  return option;
247
241
  };
242
+ const parsePlacement = (placement) => {
243
+ const positionArr = placement.split(/([A-Z])/);
244
+ const direction = positionArr[0];
245
+ let location;
246
+ if (positionArr.length > 1) {
247
+ positionArr.splice(0, 1);
248
+ location = positionArr.join("").toLowerCase();
249
+ }
250
+ return {
251
+ direction,
252
+ location
253
+ };
254
+ };
248
255
  // Annotate the CommonJS export names for ESM import in node:
249
256
  0 && (module.exports = {
250
257
  getDirectionLocationStyle,
251
258
  getNewDirectionLocation,
252
259
  getStylesAndLocation,
260
+ parsePlacement,
253
261
  triggerEventTransform
254
262
  });
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { default as debounce } from './debounce';
2
- export { getStylesAndLocation, triggerEventTransform, } from './directionLocationUtil';
2
+ export { getStylesAndLocation, triggerEventTransform, parsePlacement, } from './directionLocationUtil';
3
3
  export { default as convertHexToRGBA } from './hex2rgba';
4
4
  export { useDidMountEffect, useEventCallback, useForkRef, useTouchEmulator, useValue, useDomReady, useSize, useDomCss, useTouch, useUniqueId, } from './hooks';
5
5
  export { default as isDev } from './isDev';
package/dist/index.js CHANGED
@@ -43,6 +43,7 @@ __export(src_exports, {
43
43
  isMini: () => import_isMini.isMini,
44
44
  isMiniapp: () => import_isMini.isMiniapp,
45
45
  isWeapp: () => import_isMini.isWeapp,
46
+ parsePlacement: () => import_directionLocationUtil.parsePlacement,
46
47
  setRef: () => import_setRef.default,
47
48
  throttle: () => import_throttle.default,
48
49
  toArray: () => import_toArray.default,
@@ -91,6 +92,7 @@ __reExport(src_exports, require("./render"), module.exports);
91
92
  isMini,
92
93
  isMiniapp,
93
94
  isWeapp,
95
+ parsePlacement,
94
96
  setRef,
95
97
  throttle,
96
98
  toArray,
@@ -41,3 +41,12 @@ export declare const triggerEventTransform: ({ trigger, click, show, hide }: {
41
41
  show: any;
42
42
  hide: any;
43
43
  }) => {};
44
+ /**
45
+ * for example: placement = 'topLeft', return { direction: 'top', location: 'left' }
46
+ * @param placement
47
+ * @returns
48
+ */
49
+ export declare const parsePlacement: (placement: any) => {
50
+ direction: any;
51
+ location: any;
52
+ };
@@ -73,8 +73,7 @@ const getDirectionLocationStyle = ({
73
73
  } = rootOffset;
74
74
  const { width, height } = tipOffset;
75
75
  if (arrowDirection === "top") {
76
- styles.top = cTop - offsetSpacing;
77
- styles.transform = `translateY(-100%)`;
76
+ styles.top = cTop - offsetSpacing - height;
78
77
  switch (arrowLocation) {
79
78
  case "left":
80
79
  styles.left = cLeft;
@@ -83,8 +82,7 @@ const getDirectionLocationStyle = ({
83
82
  styles.left = cLeft + (cWidth - width) / 2;
84
83
  break;
85
84
  case "right":
86
- styles.left = cRight;
87
- styles.transform = `translate(-100%, -100%)`;
85
+ styles.left = cRight - width;
88
86
  break;
89
87
  default:
90
88
  break;
@@ -99,15 +97,13 @@ const getDirectionLocationStyle = ({
99
97
  styles.left = cLeft + (cWidth - width) / 2;
100
98
  break;
101
99
  case "right":
102
- styles.left = cRight;
103
- styles.transform = `translateX(-100%)`;
100
+ styles.left = cRight - width;
104
101
  break;
105
102
  default:
106
103
  break;
107
104
  }
108
105
  } else if (arrowDirection === "left") {
109
- styles.left = cLeft - offsetSpacing;
110
- styles.transform = `translateX(-100%)`;
106
+ styles.left = cLeft - offsetSpacing - width;
111
107
  switch (arrowLocation) {
112
108
  case "top":
113
109
  styles.top = cTop;
@@ -116,8 +112,7 @@ const getDirectionLocationStyle = ({
116
112
  styles.top = cTop + (cHeight - height) / 2;
117
113
  break;
118
114
  case "bottom":
119
- styles.top = cBottom;
120
- styles.transform = `translate(-100%, -100%)`;
115
+ styles.top = cBottom - height;
121
116
  break;
122
117
  default:
123
118
  break;
@@ -132,8 +127,7 @@ const getDirectionLocationStyle = ({
132
127
  styles.top = cTop + (cHeight - height) / 2;
133
128
  break;
134
129
  case "bottom":
135
- styles.top = cBottom;
136
- styles.transform = `translateY(-100%)`;
130
+ styles.top = cBottom - height;
137
131
  break;
138
132
  default:
139
133
  break;
@@ -145,7 +139,6 @@ const getDirectionLocationStyle = ({
145
139
  if (styles.left) {
146
140
  styles.left = `${styles.left + scrollLeft}px`;
147
141
  }
148
- styles.width = `${width}px`;
149
142
  return styles;
150
143
  };
151
144
  const getStylesAndLocation = ({
@@ -220,9 +213,23 @@ const triggerEventTransform = ({ trigger, click, show, hide }) => {
220
213
  });
221
214
  return option;
222
215
  };
216
+ const parsePlacement = (placement) => {
217
+ const positionArr = placement.split(/([A-Z])/);
218
+ const direction = positionArr[0];
219
+ let location;
220
+ if (positionArr.length > 1) {
221
+ positionArr.splice(0, 1);
222
+ location = positionArr.join("").toLowerCase();
223
+ }
224
+ return {
225
+ direction,
226
+ location
227
+ };
228
+ };
223
229
  export {
224
230
  getDirectionLocationStyle,
225
231
  getNewDirectionLocation,
226
232
  getStylesAndLocation,
233
+ parsePlacement,
227
234
  triggerEventTransform
228
235
  };
package/es/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { default as debounce } from './debounce';
2
- export { getStylesAndLocation, triggerEventTransform, } from './directionLocationUtil';
2
+ export { getStylesAndLocation, triggerEventTransform, parsePlacement, } from './directionLocationUtil';
3
3
  export { default as convertHexToRGBA } from './hex2rgba';
4
4
  export { useDidMountEffect, useEventCallback, useForkRef, useTouchEmulator, useValue, useDomReady, useSize, useDomCss, useTouch, useUniqueId, } from './hooks';
5
5
  export { default as isDev } from './isDev';
package/es/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { default as default2 } from "./debounce";
2
2
  import {
3
3
  getStylesAndLocation,
4
- triggerEventTransform
4
+ triggerEventTransform,
5
+ parsePlacement
5
6
  } from "./directionLocationUtil";
6
7
  import { default as default3 } from "./hex2rgba";
7
8
  import {
@@ -48,6 +49,7 @@ export {
48
49
  isMini,
49
50
  isMiniapp,
50
51
  isWeapp,
52
+ parsePlacement,
51
53
  default5 as setRef,
52
54
  default6 as throttle,
53
55
  default7 as toArray,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bifrostui/utils",
3
- "version": "1.4.2-beta.1",
3
+ "version": "1.4.3-beta.0",
4
4
  "description": "BUI React utilities for building components.",
5
5
  "main": "dist/index.js",
6
6
  "module": "es/index.js",