polpo 0.1.11 → 0.1.13
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.
- package/dist/components.cjs +3654 -1
- package/dist/components.cjs.map +1 -1
- package/dist/components.css +2172 -1
- package/dist/components.css.map +1 -1
- package/dist/components.js +3575 -1
- package/dist/components.js.map +1 -1
- package/dist/helpers.cjs +310 -1
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.js +275 -1
- package/dist/helpers.js.map +1 -1
- package/dist/hooks.cjs +1064 -1
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.js +997 -1
- package/dist/hooks.js.map +1 -1
- package/dist/layouts.cjs +145 -1
- package/dist/layouts.cjs.map +1 -1
- package/dist/layouts.css +4 -1
- package/dist/layouts.css.map +1 -1
- package/dist/layouts.js +118 -1
- package/dist/layouts.js.map +1 -1
- package/dist/types.cjs +18 -1
- package/dist/types.cjs.map +1 -1
- package/package.json +4 -3
package/dist/helpers.cjs
CHANGED
|
@@ -1,3 +1,312 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/helpers/index.ts
|
|
22
|
+
var helpers_exports = {};
|
|
23
|
+
__export(helpers_exports, {
|
|
24
|
+
PositionContainer: () => PositionContainer,
|
|
25
|
+
fixModalPosition: () => fixModalPosition,
|
|
26
|
+
formatBytes: () => formatBytes,
|
|
27
|
+
formatDate: () => formatDate,
|
|
28
|
+
getModalPosition: () => getModalPosition,
|
|
29
|
+
getModalPositionRelativeToContainer: () => getModalPositionRelativeToContainer,
|
|
30
|
+
getModalPositionRelativeToScreen: () => getModalPositionRelativeToScreen,
|
|
31
|
+
getOppositePosition: () => getOppositePosition,
|
|
32
|
+
timeBetween: () => timeBetween,
|
|
33
|
+
toCapitalize: () => toCapitalize
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(helpers_exports);
|
|
36
|
+
|
|
37
|
+
// src/helpers/format-bytes.ts
|
|
38
|
+
var formatBytes = (bytes, decimals = 2) => {
|
|
39
|
+
if (bytes === 0) return "0 Bytes";
|
|
40
|
+
const k = 1e3;
|
|
41
|
+
const dm = decimals < 0 ? 0 : decimals;
|
|
42
|
+
const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
|
43
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
44
|
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i];
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// src/helpers/format-dates.ts
|
|
48
|
+
var MONTHS_SHORT = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
49
|
+
var formatDate = (date) => {
|
|
50
|
+
const parsedDate = new Date(date);
|
|
51
|
+
if (Number.isNaN(parsedDate.getTime())) {
|
|
52
|
+
return date;
|
|
53
|
+
}
|
|
54
|
+
return `${MONTHS_SHORT[parsedDate.getMonth()]} ${parsedDate.getFullYear()}`;
|
|
55
|
+
};
|
|
56
|
+
var timeBetween = (date_start, date_end) => {
|
|
57
|
+
const start = new Date(date_start);
|
|
58
|
+
if (Number.isNaN(start.getTime())) {
|
|
59
|
+
return "";
|
|
60
|
+
}
|
|
61
|
+
const end = Date.parse(date_end) ? new Date(date_end) : /* @__PURE__ */ new Date();
|
|
62
|
+
const diffMs = Math.abs(end.getTime() - start.getTime());
|
|
63
|
+
const minutes = Math.floor(diffMs / (1e3 * 60));
|
|
64
|
+
const hours = Math.floor(diffMs / (1e3 * 60 * 60));
|
|
65
|
+
const days = Math.floor(diffMs / (1e3 * 60 * 60 * 24));
|
|
66
|
+
const months = Math.floor(days / 30);
|
|
67
|
+
const years = Math.floor(days / 365);
|
|
68
|
+
if (years > 0) {
|
|
69
|
+
return `${years} year${years > 1 ? "s" : ""}`;
|
|
70
|
+
}
|
|
71
|
+
if (months > 0) {
|
|
72
|
+
return `${months} month${months > 1 ? "s" : ""}`;
|
|
73
|
+
}
|
|
74
|
+
if (days > 0) {
|
|
75
|
+
return `${days} day${days > 1 ? "s" : ""}`;
|
|
76
|
+
}
|
|
77
|
+
if (hours > 0) {
|
|
78
|
+
return `${hours} hour${hours > 1 ? "s" : ""}`;
|
|
79
|
+
}
|
|
80
|
+
return `${minutes} minute${minutes !== 1 ? "s" : ""}`;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// src/helpers/get-modal-position.ts
|
|
84
|
+
var PositionContainer = /* @__PURE__ */ ((PositionContainer2) => {
|
|
85
|
+
PositionContainer2["CENTER"] = "center";
|
|
86
|
+
PositionContainer2["TOP"] = "top";
|
|
87
|
+
PositionContainer2["TOP_LEFT"] = "top left";
|
|
88
|
+
PositionContainer2["TOP_RIGHT"] = "top right";
|
|
89
|
+
PositionContainer2["TOP_CENTER"] = "top center";
|
|
90
|
+
PositionContainer2["LEFT"] = "left";
|
|
91
|
+
PositionContainer2["LEFT_TOP"] = "left top";
|
|
92
|
+
PositionContainer2["LEFT_BOTTOM"] = "left bottom";
|
|
93
|
+
PositionContainer2["LEFT_CENTER"] = "left center";
|
|
94
|
+
PositionContainer2["RIGHT"] = "right";
|
|
95
|
+
PositionContainer2["RIGHT_TOP"] = "right top";
|
|
96
|
+
PositionContainer2["RIGHT_BOTTOM"] = "right bottom";
|
|
97
|
+
PositionContainer2["RIGHT_CENTER"] = "right center";
|
|
98
|
+
PositionContainer2["BOTTOM"] = "bottom";
|
|
99
|
+
PositionContainer2["BOTTOM_LEFT"] = "bottom left";
|
|
100
|
+
PositionContainer2["BOTTOM_RIGHT"] = "bottom right";
|
|
101
|
+
PositionContainer2["BOTTOM_CENTER"] = "bottom center";
|
|
102
|
+
return PositionContainer2;
|
|
103
|
+
})(PositionContainer || {});
|
|
104
|
+
var getModalPosition = ({ c, m, offset, position }) => {
|
|
105
|
+
let top = c.y + c.h + offset;
|
|
106
|
+
let left = c.x - (m.w - c.w) * (50 / 100);
|
|
107
|
+
switch (position) {
|
|
108
|
+
case "top" /* TOP */:
|
|
109
|
+
case "top center" /* TOP_CENTER */:
|
|
110
|
+
top = c.y - m.h - offset;
|
|
111
|
+
left = c.x - (m.w - c.w) / 2;
|
|
112
|
+
break;
|
|
113
|
+
case "top left" /* TOP_LEFT */:
|
|
114
|
+
top = c.y - m.h - offset;
|
|
115
|
+
left = c.x - m.w + c.w;
|
|
116
|
+
break;
|
|
117
|
+
case "top right" /* TOP_RIGHT */:
|
|
118
|
+
top = c.y - m.h - offset;
|
|
119
|
+
left = c.x;
|
|
120
|
+
break;
|
|
121
|
+
case "bottom" /* BOTTOM */:
|
|
122
|
+
case "bottom center" /* BOTTOM_CENTER */:
|
|
123
|
+
top = c.y + c.h + offset;
|
|
124
|
+
left = c.x - (m.w - c.w) / 2;
|
|
125
|
+
break;
|
|
126
|
+
case "bottom left" /* BOTTOM_LEFT */:
|
|
127
|
+
top = c.y + c.h + offset;
|
|
128
|
+
left = c.x - m.w + c.w;
|
|
129
|
+
break;
|
|
130
|
+
case "bottom right" /* BOTTOM_RIGHT */:
|
|
131
|
+
top = c.y + c.h + offset;
|
|
132
|
+
left = c.x;
|
|
133
|
+
break;
|
|
134
|
+
case "left" /* LEFT */:
|
|
135
|
+
case "left center" /* LEFT_CENTER */:
|
|
136
|
+
top = c.y - (m.h - c.h) / 2;
|
|
137
|
+
left = c.x - m.w - offset;
|
|
138
|
+
break;
|
|
139
|
+
case "left top" /* LEFT_TOP */:
|
|
140
|
+
top = c.y - m.h + c.h;
|
|
141
|
+
left = c.x - m.w - offset;
|
|
142
|
+
break;
|
|
143
|
+
case "left bottom" /* LEFT_BOTTOM */:
|
|
144
|
+
top = c.y;
|
|
145
|
+
left = c.x - m.w - offset;
|
|
146
|
+
break;
|
|
147
|
+
case "right" /* RIGHT */:
|
|
148
|
+
case "right center" /* RIGHT_CENTER */:
|
|
149
|
+
top = c.y - (m.h - c.h) / 2;
|
|
150
|
+
left = c.x + c.w + offset;
|
|
151
|
+
break;
|
|
152
|
+
case "right top" /* RIGHT_TOP */:
|
|
153
|
+
top = c.y - m.h + c.h;
|
|
154
|
+
left = c.x + c.w + offset;
|
|
155
|
+
break;
|
|
156
|
+
case "right bottom" /* RIGHT_BOTTOM */:
|
|
157
|
+
top = c.y;
|
|
158
|
+
left = c.x + c.w + offset;
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
left: Math.round(left),
|
|
163
|
+
top: Math.round(top)
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
var getOppositePosition = ({ top, left }, position, windowOffset, m) => {
|
|
167
|
+
const positions = position.split(" ");
|
|
168
|
+
const newPosition = [];
|
|
169
|
+
const rightOffset = left + m.w + windowOffset - window.innerWidth;
|
|
170
|
+
const bottomOffset = top + m.h + windowOffset - window.innerHeight;
|
|
171
|
+
for (const p of positions) {
|
|
172
|
+
if (p === "top" /* TOP */ && top < windowOffset) {
|
|
173
|
+
newPosition.push("bottom" /* BOTTOM */);
|
|
174
|
+
} else if (p === "left" /* LEFT */ && left < windowOffset) {
|
|
175
|
+
newPosition.push("right" /* RIGHT */);
|
|
176
|
+
} else if (p === "bottom" /* BOTTOM */ && bottomOffset > 0) {
|
|
177
|
+
newPosition.push("top" /* TOP */);
|
|
178
|
+
} else if (p === "right" /* RIGHT */ && rightOffset > 0) {
|
|
179
|
+
newPosition.push("left" /* LEFT */);
|
|
180
|
+
} else {
|
|
181
|
+
newPosition.push(p);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return newPosition.join(" ");
|
|
185
|
+
};
|
|
186
|
+
var fixModalPosition = ({ top, left }, m, windowOffset) => {
|
|
187
|
+
const rightOffset = left + m.w + windowOffset - window.innerWidth;
|
|
188
|
+
const bottomOffset = top + m.h + windowOffset - window.innerHeight;
|
|
189
|
+
left = rightOffset > 0 ? left - rightOffset : left;
|
|
190
|
+
top = bottomOffset > 0 ? top - bottomOffset : top;
|
|
191
|
+
left = left < windowOffset ? windowOffset : left;
|
|
192
|
+
top = top < windowOffset ? windowOffset : top;
|
|
193
|
+
return { top, left };
|
|
194
|
+
};
|
|
195
|
+
var getModalPositionRelativeToContainer = ({
|
|
196
|
+
c,
|
|
197
|
+
m,
|
|
198
|
+
offset,
|
|
199
|
+
windowOffset,
|
|
200
|
+
position
|
|
201
|
+
}) => {
|
|
202
|
+
const params = { c, m, offset, position };
|
|
203
|
+
let modalContainerStyle = getModalPosition(params);
|
|
204
|
+
const oppositePosition = getOppositePosition(modalContainerStyle, position, windowOffset, m);
|
|
205
|
+
if (oppositePosition !== position) {
|
|
206
|
+
modalContainerStyle = getModalPosition({
|
|
207
|
+
...params,
|
|
208
|
+
position: oppositePosition
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
const fixedPosition = fixModalPosition(modalContainerStyle, m, windowOffset);
|
|
212
|
+
return {
|
|
213
|
+
left: `${fixedPosition.left}px`,
|
|
214
|
+
top: `${fixedPosition.top}px`
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
// src/helpers/get-modal-position-relative-to-screen.ts
|
|
219
|
+
var getModalPositionRelativeToScreen = ({
|
|
220
|
+
position,
|
|
221
|
+
windowOffset
|
|
222
|
+
}) => {
|
|
223
|
+
switch (position) {
|
|
224
|
+
case "center" /* CENTER */:
|
|
225
|
+
return {
|
|
226
|
+
top: "50%",
|
|
227
|
+
left: "50%",
|
|
228
|
+
transform: "translate(-50%, -50%)"
|
|
229
|
+
};
|
|
230
|
+
case "top" /* TOP */:
|
|
231
|
+
case "top center" /* TOP_CENTER */:
|
|
232
|
+
return {
|
|
233
|
+
top: `${windowOffset}px`,
|
|
234
|
+
left: "50%",
|
|
235
|
+
transform: "translateX(-50%)"
|
|
236
|
+
};
|
|
237
|
+
case "top left" /* TOP_LEFT */:
|
|
238
|
+
case "left top" /* LEFT_TOP */:
|
|
239
|
+
return {
|
|
240
|
+
top: `${windowOffset}px`,
|
|
241
|
+
left: `${windowOffset}px`
|
|
242
|
+
};
|
|
243
|
+
case "top right" /* TOP_RIGHT */:
|
|
244
|
+
case "right top" /* RIGHT_TOP */:
|
|
245
|
+
return {
|
|
246
|
+
top: `${windowOffset}px`,
|
|
247
|
+
right: `${windowOffset}px`
|
|
248
|
+
};
|
|
249
|
+
case "bottom" /* BOTTOM */:
|
|
250
|
+
case "bottom center" /* BOTTOM_CENTER */:
|
|
251
|
+
return {
|
|
252
|
+
bottom: `${windowOffset}px`,
|
|
253
|
+
left: "50%",
|
|
254
|
+
transform: "translateX(-50%)"
|
|
255
|
+
};
|
|
256
|
+
case "left bottom" /* LEFT_BOTTOM */:
|
|
257
|
+
case "bottom left" /* BOTTOM_LEFT */:
|
|
258
|
+
return {
|
|
259
|
+
bottom: `${windowOffset}px`,
|
|
260
|
+
left: `${windowOffset}px`
|
|
261
|
+
};
|
|
262
|
+
case "right bottom" /* RIGHT_BOTTOM */:
|
|
263
|
+
case "bottom right" /* BOTTOM_RIGHT */:
|
|
264
|
+
return {
|
|
265
|
+
bottom: `${windowOffset}px`,
|
|
266
|
+
right: `${windowOffset}px`
|
|
267
|
+
};
|
|
268
|
+
case "left" /* LEFT */:
|
|
269
|
+
case "left center" /* LEFT_CENTER */:
|
|
270
|
+
return {
|
|
271
|
+
top: "50%",
|
|
272
|
+
left: `${windowOffset}px`,
|
|
273
|
+
transform: "translateY(-50%)"
|
|
274
|
+
};
|
|
275
|
+
case "right" /* RIGHT */:
|
|
276
|
+
case "right center" /* RIGHT_CENTER */:
|
|
277
|
+
return {
|
|
278
|
+
top: "50%",
|
|
279
|
+
right: `${windowOffset}px`,
|
|
280
|
+
transform: "translateY(-50%)"
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
return {
|
|
284
|
+
top: "50%",
|
|
285
|
+
left: "50%",
|
|
286
|
+
transform: "translate(-50%, -50%)"
|
|
287
|
+
};
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
// src/helpers/text/to-capitalize.ts
|
|
291
|
+
var toCapitalize = (text, options = {}) => {
|
|
292
|
+
const { separator = " ", variant = "each-word", join = separator } = options;
|
|
293
|
+
if (variant === "first-word") {
|
|
294
|
+
return text[0].toUpperCase() + text.slice(1);
|
|
295
|
+
}
|
|
296
|
+
const words = text.split(separator);
|
|
297
|
+
return words.map((word) => word[0].toUpperCase() + word.slice(1)).join(join);
|
|
298
|
+
};
|
|
299
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
300
|
+
0 && (module.exports = {
|
|
301
|
+
PositionContainer,
|
|
302
|
+
fixModalPosition,
|
|
303
|
+
formatBytes,
|
|
304
|
+
formatDate,
|
|
305
|
+
getModalPosition,
|
|
306
|
+
getModalPositionRelativeToContainer,
|
|
307
|
+
getModalPositionRelativeToScreen,
|
|
308
|
+
getOppositePosition,
|
|
309
|
+
timeBetween,
|
|
310
|
+
toCapitalize
|
|
311
|
+
});
|
|
3
312
|
//# sourceMappingURL=helpers.cjs.map
|
package/dist/helpers.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/helpers/index.ts","../src/helpers/format-bytes.ts","../src/helpers/format-dates.ts","../src/helpers/get-modal-position.ts","../src/helpers/get-modal-position-relative-to-screen.ts","../src/helpers/text/to-capitalize.ts"],"sourcesContent":["export * from './format-bytes';\nexport * from './format-dates';\nexport * from './get-modal-position';\nexport * from './get-modal-position-relative-to-screen';\nexport * from './text';\n","export const formatBytes = (bytes: number, decimals = 2) => {\n if (bytes === 0) return '0 Bytes';\n\n const k = 1000;\n const dm = decimals < 0 ? 0 : decimals;\n const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];\n\n const i = Math.floor(Math.log(bytes) / Math.log(k));\n\n return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];\n};\n","const MONTHS_SHORT = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];\n\nexport const formatDate = (date: string) => {\n const parsedDate = new Date(date);\n\n if (Number.isNaN(parsedDate.getTime())) {\n return date;\n }\n\n return `${MONTHS_SHORT[parsedDate.getMonth()]} ${parsedDate.getFullYear()}`;\n};\n\nexport const timeBetween = (date_start: string, date_end: string) => {\n const start = new Date(date_start);\n\n if (Number.isNaN(start.getTime())) {\n return '';\n }\n\n const end = Date.parse(date_end) ? new Date(date_end) : new Date();\n\n const diffMs = Math.abs(end.getTime() - start.getTime());\n\n const minutes = Math.floor(diffMs / (1000 * 60));\n const hours = Math.floor(diffMs / (1000 * 60 * 60));\n const days = Math.floor(diffMs / (1000 * 60 * 60 * 24));\n const months = Math.floor(days / 30);\n const years = Math.floor(days / 365);\n\n if (years > 0) {\n return `${years} year${years > 1 ? 's' : ''}`;\n }\n\n if (months > 0) {\n return `${months} month${months > 1 ? 's' : ''}`;\n }\n\n if (days > 0) {\n return `${days} day${days > 1 ? 's' : ''}`;\n }\n\n if (hours > 0) {\n return `${hours} hour${hours > 1 ? 's' : ''}`;\n }\n\n return `${minutes} minute${minutes !== 1 ? 's' : ''}`;\n};\n","export enum PositionContainer {\n CENTER = 'center',\n TOP = 'top',\n TOP_LEFT = 'top left',\n TOP_RIGHT = 'top right',\n TOP_CENTER = 'top center',\n LEFT = 'left',\n LEFT_TOP = 'left top',\n LEFT_BOTTOM = 'left bottom',\n LEFT_CENTER = 'left center',\n RIGHT = 'right',\n RIGHT_TOP = 'right top',\n RIGHT_BOTTOM = 'right bottom',\n RIGHT_CENTER = 'right center',\n BOTTOM = 'bottom',\n BOTTOM_LEFT = 'bottom left',\n BOTTOM_RIGHT = 'bottom right',\n BOTTOM_CENTER = 'bottom center',\n}\n\nexport type PositionObject = {\n x: number;\n y: number;\n top: number;\n left: number;\n w: number;\n h: number;\n};\n\nexport type ModalPosition = {\n left: number;\n top: number;\n};\n\nexport type GetModalPositionParams = {\n c: PositionObject;\n m: PositionObject;\n offset: number;\n position: PositionContainer;\n};\n\n/*\n * @description Calculates the position of the modal relative to the container\n *\n * @param c - The container's position object\n * @param m - The modal's position object\n * @param offset - The offset between the container and the modal\n * @param position - The position of the modal\n *\n * -----------------------------------------------------------------------------\n * @returns The position of the modal relative to the container\n */\nexport const getModalPosition = ({ c, m, offset, position }: GetModalPositionParams): ModalPosition => {\n // Default bottom\n let top = c.y + c.h + offset;\n let left = c.x - (m.w - c.w) * (50 / 100);\n\n switch (position) {\n case PositionContainer.TOP:\n case PositionContainer.TOP_CENTER:\n top = c.y - m.h - offset;\n left = c.x - (m.w - c.w) / 2;\n\n break;\n case PositionContainer.TOP_LEFT:\n top = c.y - m.h - offset;\n left = c.x - m.w + c.w;\n\n break;\n\n case PositionContainer.TOP_RIGHT:\n top = c.y - m.h - offset;\n left = c.x;\n\n break;\n\n case PositionContainer.BOTTOM:\n case PositionContainer.BOTTOM_CENTER:\n top = c.y + c.h + offset;\n left = c.x - (m.w - c.w) / 2;\n\n break;\n\n case PositionContainer.BOTTOM_LEFT:\n top = c.y + c.h + offset;\n left = c.x - m.w + c.w;\n\n break;\n\n case PositionContainer.BOTTOM_RIGHT:\n top = c.y + c.h + offset;\n left = c.x;\n\n break;\n\n case PositionContainer.LEFT:\n case PositionContainer.LEFT_CENTER:\n top = c.y - (m.h - c.h) / 2;\n left = c.x - m.w - offset;\n\n break;\n\n case PositionContainer.LEFT_TOP:\n top = c.y - m.h + c.h;\n left = c.x - m.w - offset;\n\n break;\n\n case PositionContainer.LEFT_BOTTOM:\n top = c.y;\n left = c.x - m.w - offset;\n\n break;\n\n case PositionContainer.RIGHT:\n case PositionContainer.RIGHT_CENTER:\n top = c.y - (m.h - c.h) / 2;\n left = c.x + c.w + offset;\n\n break;\n\n case PositionContainer.RIGHT_TOP:\n top = c.y - m.h + c.h;\n left = c.x + c.w + offset;\n\n break;\n\n case PositionContainer.RIGHT_BOTTOM:\n top = c.y;\n left = c.x + c.w + offset;\n\n break;\n }\n\n return {\n left: Math.round(left),\n top: Math.round(top),\n };\n};\n\nexport const getOppositePosition = (\n { top, left }: ModalPosition,\n position: PositionContainer,\n windowOffset: number,\n m: PositionObject,\n) => {\n const positions = position.split(' ');\n const newPosition = [];\n const rightOffset = left + m.w + windowOffset - window.innerWidth;\n const bottomOffset = top + m.h + windowOffset - window.innerHeight;\n\n for (const p of positions) {\n if (p === PositionContainer.TOP && top < windowOffset) {\n newPosition.push(PositionContainer.BOTTOM);\n } else if (p === PositionContainer.LEFT && left < windowOffset) {\n newPosition.push(PositionContainer.RIGHT);\n } else if (p === PositionContainer.BOTTOM && bottomOffset > 0) {\n newPosition.push(PositionContainer.TOP);\n } else if (p === PositionContainer.RIGHT && rightOffset > 0) {\n newPosition.push(PositionContainer.LEFT);\n } else {\n newPosition.push(p);\n }\n }\n\n return newPosition.join(' ') as PositionContainer;\n};\n\nexport const fixModalPosition = ({ top, left }: ModalPosition, m: PositionObject, windowOffset: number) => {\n const rightOffset = left + m.w + windowOffset - window.innerWidth;\n const bottomOffset = top + m.h + windowOffset - window.innerHeight;\n\n left = rightOffset > 0 ? left - rightOffset : left;\n top = bottomOffset > 0 ? top - bottomOffset : top;\n\n left = left < windowOffset ? windowOffset : left;\n top = top < windowOffset ? windowOffset : top;\n\n return { top, left };\n};\n\ntype getModalPositionRelativeToContainerParams = GetModalPositionParams & {\n windowOffset: number;\n};\n\nexport const getModalPositionRelativeToContainer = ({\n c,\n m,\n offset,\n windowOffset,\n position,\n}: getModalPositionRelativeToContainerParams): Record<string, string> => {\n const params = { c, m, offset, position };\n let modalContainerStyle = getModalPosition(params);\n\n const oppositePosition = getOppositePosition(modalContainerStyle, position, windowOffset, m);\n\n if (oppositePosition !== position) {\n modalContainerStyle = getModalPosition({\n ...params,\n position: oppositePosition,\n });\n }\n\n const fixedPosition = fixModalPosition(modalContainerStyle, m, windowOffset);\n\n return {\n left: `${fixedPosition.left}px`,\n top: `${fixedPosition.top}px`,\n };\n};\n","import { PositionContainer } from './get-modal-position';\n\nexport type GetModalPositionRelativeToScreenParams = {\n position: PositionContainer;\n windowOffset: number;\n};\n\nexport const getModalPositionRelativeToScreen = ({\n position,\n windowOffset,\n}: GetModalPositionRelativeToScreenParams): Record<string, string> => {\n switch (position) {\n case PositionContainer.CENTER:\n return {\n top: '50%',\n left: '50%',\n transform: 'translate(-50%, -50%)',\n };\n\n case PositionContainer.TOP:\n case PositionContainer.TOP_CENTER:\n return {\n top: `${windowOffset}px`,\n left: '50%',\n transform: 'translateX(-50%)',\n };\n\n case PositionContainer.TOP_LEFT:\n case PositionContainer.LEFT_TOP:\n return {\n top: `${windowOffset}px`,\n left: `${windowOffset}px`,\n };\n\n case PositionContainer.TOP_RIGHT:\n case PositionContainer.RIGHT_TOP:\n return {\n top: `${windowOffset}px`,\n right: `${windowOffset}px`,\n };\n\n case PositionContainer.BOTTOM:\n case PositionContainer.BOTTOM_CENTER:\n return {\n bottom: `${windowOffset}px`,\n left: '50%',\n transform: 'translateX(-50%)',\n };\n\n case PositionContainer.LEFT_BOTTOM:\n case PositionContainer.BOTTOM_LEFT:\n return {\n bottom: `${windowOffset}px`,\n left: `${windowOffset}px`,\n };\n\n case PositionContainer.RIGHT_BOTTOM:\n case PositionContainer.BOTTOM_RIGHT:\n return {\n bottom: `${windowOffset}px`,\n right: `${windowOffset}px`,\n };\n\n case PositionContainer.LEFT:\n case PositionContainer.LEFT_CENTER:\n return {\n top: '50%',\n left: `${windowOffset}px`,\n transform: 'translateY(-50%)',\n };\n\n case PositionContainer.RIGHT:\n case PositionContainer.RIGHT_CENTER:\n return {\n top: '50%',\n right: `${windowOffset}px`,\n transform: 'translateY(-50%)',\n };\n }\n\n return {\n top: '50%',\n left: '50%',\n transform: 'translate(-50%, -50%)',\n };\n};\n","export type ToCapitalizeOptions = Partial<{\n separator: string;\n join: string;\n variant: 'first-word' | 'each-word';\n}>;\n\nexport const toCapitalize = (text: string, options: ToCapitalizeOptions = {}) => {\n const { separator = ' ', variant = 'each-word', join = separator } = options;\n\n if (variant === 'first-word') {\n return text[0].toUpperCase() + text.slice(1);\n }\n\n const words = text.split(separator);\n\n return words.map(word => word[0].toUpperCase() + word.slice(1)).join(join);\n};\n"],"mappings":";yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,EAAA,qBAAAC,EAAA,gBAAAC,EAAA,eAAAC,EAAA,qBAAAC,EAAA,wCAAAC,EAAA,qCAAAC,EAAA,wBAAAC,EAAA,gBAAAC,EAAA,iBAAAC,IAAA,eAAAC,EAAAZ,GCAO,IAAMa,EAAc,CAACC,EAAeC,EAAW,IAAM,CAC1D,GAAID,IAAU,EAAG,MAAO,UAExB,IAAME,EAAI,IACJC,EAAKF,EAAW,EAAI,EAAIA,EACxBG,EAAQ,CAAC,QAAS,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,IAAI,EAEhEC,EAAI,KAAK,MAAM,KAAK,IAAIL,CAAK,EAAI,KAAK,IAAIE,CAAC,CAAC,EAElD,OAAO,YAAYF,EAAQ,KAAK,IAAIE,EAAGG,CAA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E,MAAO,CACL,OAAQ,GAAGA,CAAY,KACvB,KAAM,GAAGA,CAAY,IACvB,EAEF,mBACA,mBACE,MAAO,CACL,OAAQ,GAAGA,CAAY,KACvB,MAAO,GAAGA,CAAY,IACxB,EAEF,WACA,kBACE,MAAO,CACL,IAAK,MACL,KAAM,GAAGA,CAAY,KACrB,UAAW,kBACb,EAEF,YACA,mBACE,MAAO,CACL,IAAK,MACL,MAAO,GAAGA,CAAY,KACtB,UAAW,kBACb,CACJ,CAEA,MAAO,CACL,IAAK,MACL,KAAM,MACN,UAAW,uBACb,CACF,EC/EO,IAAMC,EAAe,CAACC,EAAcC,EAA+B,CAAC,IAAM,CAC/E,GAAM,CAAE,UAAAC,EAAY,IAAK,QAAAC,EAAU,YAAa,KAAAC,EAAOF,CAAU,EAAID,EAErE,OAAIE,IAAY,aACPH,EAAK,CAAC,EAAE,YAAY,EAAIA,EAAK,MAAM,CAAC,EAG/BA,EAAK,MAAME,CAAS,EAErB,IAAIG,GAAQA,EAAK,CAAC,EAAE,YAAY,EAAIA,EAAK,MAAM,CAAC,CAAC,EAAE,KAAKD,CAAI,CAC3E","names":["helpers_exports","__export","PositionContainer","fixModalPosition","formatBytes","formatDate","getModalPosition","getModalPositionRelativeToContainer","getModalPositionRelativeToScreen","getOppositePosition","timeBetween","toCapitalize","__toCommonJS","formatBytes","bytes","decimals","k","dm","sizes","i","MONTHS_SHORT","formatDate","date","parsedDate","timeBetween","date_start","date_end","start","end","diffMs","minutes","hours","days","months","years","PositionContainer","getModalPosition","c","m","offset","position","top","left","getOppositePosition","windowOffset","positions","newPosition","rightOffset","bottomOffset","fixModalPosition","getModalPositionRelativeToContainer","params","modalContainerStyle","oppositePosition","fixedPosition","getModalPositionRelativeToScreen","position","windowOffset","toCapitalize","text","options","separator","variant","join","word"]}
|
|
1
|
+
{"version":3,"sources":["../src/helpers/index.ts","../src/helpers/format-bytes.ts","../src/helpers/format-dates.ts","../src/helpers/get-modal-position.ts","../src/helpers/get-modal-position-relative-to-screen.ts","../src/helpers/text/to-capitalize.ts"],"sourcesContent":["export * from './format-bytes';\nexport * from './format-dates';\nexport * from './get-modal-position';\nexport * from './get-modal-position-relative-to-screen';\nexport * from './text';\n","export const formatBytes = (bytes: number, decimals = 2) => {\n if (bytes === 0) return '0 Bytes';\n\n const k = 1000;\n const dm = decimals < 0 ? 0 : decimals;\n const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];\n\n const i = Math.floor(Math.log(bytes) / Math.log(k));\n\n return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];\n};\n","const MONTHS_SHORT = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];\n\nexport const formatDate = (date: string) => {\n const parsedDate = new Date(date);\n\n if (Number.isNaN(parsedDate.getTime())) {\n return date;\n }\n\n return `${MONTHS_SHORT[parsedDate.getMonth()]} ${parsedDate.getFullYear()}`;\n};\n\nexport const timeBetween = (date_start: string, date_end: string) => {\n const start = new Date(date_start);\n\n if (Number.isNaN(start.getTime())) {\n return '';\n }\n\n const end = Date.parse(date_end) ? new Date(date_end) : new Date();\n\n const diffMs = Math.abs(end.getTime() - start.getTime());\n\n const minutes = Math.floor(diffMs / (1000 * 60));\n const hours = Math.floor(diffMs / (1000 * 60 * 60));\n const days = Math.floor(diffMs / (1000 * 60 * 60 * 24));\n const months = Math.floor(days / 30);\n const years = Math.floor(days / 365);\n\n if (years > 0) {\n return `${years} year${years > 1 ? 's' : ''}`;\n }\n\n if (months > 0) {\n return `${months} month${months > 1 ? 's' : ''}`;\n }\n\n if (days > 0) {\n return `${days} day${days > 1 ? 's' : ''}`;\n }\n\n if (hours > 0) {\n return `${hours} hour${hours > 1 ? 's' : ''}`;\n }\n\n return `${minutes} minute${minutes !== 1 ? 's' : ''}`;\n};\n","export enum PositionContainer {\n CENTER = 'center',\n TOP = 'top',\n TOP_LEFT = 'top left',\n TOP_RIGHT = 'top right',\n TOP_CENTER = 'top center',\n LEFT = 'left',\n LEFT_TOP = 'left top',\n LEFT_BOTTOM = 'left bottom',\n LEFT_CENTER = 'left center',\n RIGHT = 'right',\n RIGHT_TOP = 'right top',\n RIGHT_BOTTOM = 'right bottom',\n RIGHT_CENTER = 'right center',\n BOTTOM = 'bottom',\n BOTTOM_LEFT = 'bottom left',\n BOTTOM_RIGHT = 'bottom right',\n BOTTOM_CENTER = 'bottom center',\n}\n\nexport type PositionObject = {\n x: number;\n y: number;\n top: number;\n left: number;\n w: number;\n h: number;\n};\n\nexport type ModalPosition = {\n left: number;\n top: number;\n};\n\nexport type GetModalPositionParams = {\n c: PositionObject;\n m: PositionObject;\n offset: number;\n position: PositionContainer;\n};\n\n/*\n * @description Calculates the position of the modal relative to the container\n *\n * @param c - The container's position object\n * @param m - The modal's position object\n * @param offset - The offset between the container and the modal\n * @param position - The position of the modal\n *\n * -----------------------------------------------------------------------------\n * @returns The position of the modal relative to the container\n */\nexport const getModalPosition = ({ c, m, offset, position }: GetModalPositionParams): ModalPosition => {\n // Default bottom\n let top = c.y + c.h + offset;\n let left = c.x - (m.w - c.w) * (50 / 100);\n\n switch (position) {\n case PositionContainer.TOP:\n case PositionContainer.TOP_CENTER:\n top = c.y - m.h - offset;\n left = c.x - (m.w - c.w) / 2;\n\n break;\n case PositionContainer.TOP_LEFT:\n top = c.y - m.h - offset;\n left = c.x - m.w + c.w;\n\n break;\n\n case PositionContainer.TOP_RIGHT:\n top = c.y - m.h - offset;\n left = c.x;\n\n break;\n\n case PositionContainer.BOTTOM:\n case PositionContainer.BOTTOM_CENTER:\n top = c.y + c.h + offset;\n left = c.x - (m.w - c.w) / 2;\n\n break;\n\n case PositionContainer.BOTTOM_LEFT:\n top = c.y + c.h + offset;\n left = c.x - m.w + c.w;\n\n break;\n\n case PositionContainer.BOTTOM_RIGHT:\n top = c.y + c.h + offset;\n left = c.x;\n\n break;\n\n case PositionContainer.LEFT:\n case PositionContainer.LEFT_CENTER:\n top = c.y - (m.h - c.h) / 2;\n left = c.x - m.w - offset;\n\n break;\n\n case PositionContainer.LEFT_TOP:\n top = c.y - m.h + c.h;\n left = c.x - m.w - offset;\n\n break;\n\n case PositionContainer.LEFT_BOTTOM:\n top = c.y;\n left = c.x - m.w - offset;\n\n break;\n\n case PositionContainer.RIGHT:\n case PositionContainer.RIGHT_CENTER:\n top = c.y - (m.h - c.h) / 2;\n left = c.x + c.w + offset;\n\n break;\n\n case PositionContainer.RIGHT_TOP:\n top = c.y - m.h + c.h;\n left = c.x + c.w + offset;\n\n break;\n\n case PositionContainer.RIGHT_BOTTOM:\n top = c.y;\n left = c.x + c.w + offset;\n\n break;\n }\n\n return {\n left: Math.round(left),\n top: Math.round(top),\n };\n};\n\nexport const getOppositePosition = (\n { top, left }: ModalPosition,\n position: PositionContainer,\n windowOffset: number,\n m: PositionObject,\n) => {\n const positions = position.split(' ');\n const newPosition = [];\n const rightOffset = left + m.w + windowOffset - window.innerWidth;\n const bottomOffset = top + m.h + windowOffset - window.innerHeight;\n\n for (const p of positions) {\n if (p === PositionContainer.TOP && top < windowOffset) {\n newPosition.push(PositionContainer.BOTTOM);\n } else if (p === PositionContainer.LEFT && left < windowOffset) {\n newPosition.push(PositionContainer.RIGHT);\n } else if (p === PositionContainer.BOTTOM && bottomOffset > 0) {\n newPosition.push(PositionContainer.TOP);\n } else if (p === PositionContainer.RIGHT && rightOffset > 0) {\n newPosition.push(PositionContainer.LEFT);\n } else {\n newPosition.push(p);\n }\n }\n\n return newPosition.join(' ') as PositionContainer;\n};\n\nexport const fixModalPosition = ({ top, left }: ModalPosition, m: PositionObject, windowOffset: number) => {\n const rightOffset = left + m.w + windowOffset - window.innerWidth;\n const bottomOffset = top + m.h + windowOffset - window.innerHeight;\n\n left = rightOffset > 0 ? left - rightOffset : left;\n top = bottomOffset > 0 ? top - bottomOffset : top;\n\n left = left < windowOffset ? windowOffset : left;\n top = top < windowOffset ? windowOffset : top;\n\n return { top, left };\n};\n\ntype getModalPositionRelativeToContainerParams = GetModalPositionParams & {\n windowOffset: number;\n};\n\nexport const getModalPositionRelativeToContainer = ({\n c,\n m,\n offset,\n windowOffset,\n position,\n}: getModalPositionRelativeToContainerParams): Record<string, string> => {\n const params = { c, m, offset, position };\n let modalContainerStyle = getModalPosition(params);\n\n const oppositePosition = getOppositePosition(modalContainerStyle, position, windowOffset, m);\n\n if (oppositePosition !== position) {\n modalContainerStyle = getModalPosition({\n ...params,\n position: oppositePosition,\n });\n }\n\n const fixedPosition = fixModalPosition(modalContainerStyle, m, windowOffset);\n\n return {\n left: `${fixedPosition.left}px`,\n top: `${fixedPosition.top}px`,\n };\n};\n","import { PositionContainer } from './get-modal-position';\n\nexport type GetModalPositionRelativeToScreenParams = {\n position: PositionContainer;\n windowOffset: number;\n};\n\nexport const getModalPositionRelativeToScreen = ({\n position,\n windowOffset,\n}: GetModalPositionRelativeToScreenParams): Record<string, string> => {\n switch (position) {\n case PositionContainer.CENTER:\n return {\n top: '50%',\n left: '50%',\n transform: 'translate(-50%, -50%)',\n };\n\n case PositionContainer.TOP:\n case PositionContainer.TOP_CENTER:\n return {\n top: `${windowOffset}px`,\n left: '50%',\n transform: 'translateX(-50%)',\n };\n\n case PositionContainer.TOP_LEFT:\n case PositionContainer.LEFT_TOP:\n return {\n top: `${windowOffset}px`,\n left: `${windowOffset}px`,\n };\n\n case PositionContainer.TOP_RIGHT:\n case PositionContainer.RIGHT_TOP:\n return {\n top: `${windowOffset}px`,\n right: `${windowOffset}px`,\n };\n\n case PositionContainer.BOTTOM:\n case PositionContainer.BOTTOM_CENTER:\n return {\n bottom: `${windowOffset}px`,\n left: '50%',\n transform: 'translateX(-50%)',\n };\n\n case PositionContainer.LEFT_BOTTOM:\n case PositionContainer.BOTTOM_LEFT:\n return {\n bottom: `${windowOffset}px`,\n left: `${windowOffset}px`,\n };\n\n case PositionContainer.RIGHT_BOTTOM:\n case PositionContainer.BOTTOM_RIGHT:\n return {\n bottom: `${windowOffset}px`,\n right: `${windowOffset}px`,\n };\n\n case PositionContainer.LEFT:\n case PositionContainer.LEFT_CENTER:\n return {\n top: '50%',\n left: `${windowOffset}px`,\n transform: 'translateY(-50%)',\n };\n\n case PositionContainer.RIGHT:\n case PositionContainer.RIGHT_CENTER:\n return {\n top: '50%',\n right: `${windowOffset}px`,\n transform: 'translateY(-50%)',\n };\n }\n\n return {\n top: '50%',\n left: '50%',\n transform: 'translate(-50%, -50%)',\n };\n};\n","export type ToCapitalizeOptions = Partial<{\n separator: string;\n join: string;\n variant: 'first-word' | 'each-word';\n}>;\n\nexport const toCapitalize = (text: string, options: ToCapitalizeOptions = {}) => {\n const { separator = ' ', variant = 'each-word', join = separator } = options;\n\n if (variant === 'first-word') {\n return text[0].toUpperCase() + text.slice(1);\n }\n\n const words = text.split(separator);\n\n return words.map(word => word[0].toUpperCase() + word.slice(1)).join(join);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,cAAc,CAAC,OAAe,WAAW,MAAM;AAC1D,MAAI,UAAU,EAAG,QAAO;AAExB,QAAM,IAAI;AACV,QAAM,KAAK,WAAW,IAAI,IAAI;AAC9B,QAAM,QAAQ,CAAC,SAAS,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,IAAI;AAEtE,QAAM,IAAI,KAAK,MAAM,KAAK,IAAI,KAAK,IAAI,KAAK,IAAI,CAAC,CAAC;AAElD,SAAO,YAAY,QAAQ,KAAK,IAAI,GAAG,CAAC,GAAG,QAAQ,EAAE,CAAC,IAAI,MAAM,MAAM,CAAC;AACzE;;;ACVA,IAAM,eAAe,CAAC,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,KAAK;AAEjG,IAAM,aAAa,CAAC,SAAiB;AAC1C,QAAM,aAAa,IAAI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