tiny-essentials 1.13.2 → 1.15.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 (36) hide show
  1. package/dist/v1/TinyBasicsEs.js +656 -26
  2. package/dist/v1/TinyBasicsEs.min.js +1 -1
  3. package/dist/v1/TinyDragger.js +196 -26
  4. package/dist/v1/TinyEssentials.js +896 -26
  5. package/dist/v1/TinyEssentials.min.js +1 -1
  6. package/dist/v1/TinyNotifications.js +408 -0
  7. package/dist/v1/TinyNotifications.min.js +1 -0
  8. package/dist/v1/TinyUploadClicker.js +198 -26
  9. package/dist/v1/basics/collision.cjs +413 -0
  10. package/dist/v1/basics/collision.d.mts +187 -0
  11. package/dist/v1/basics/collision.mjs +350 -0
  12. package/dist/v1/basics/html.cjs +201 -26
  13. package/dist/v1/basics/html.d.mts +71 -7
  14. package/dist/v1/basics/html.mjs +186 -23
  15. package/dist/v1/basics/index.cjs +24 -0
  16. package/dist/v1/basics/index.d.mts +24 -1
  17. package/dist/v1/basics/index.mjs +4 -3
  18. package/dist/v1/basics/text.cjs +43 -0
  19. package/dist/v1/basics/text.d.mts +16 -0
  20. package/dist/v1/basics/text.mjs +37 -0
  21. package/dist/v1/build/TinyNotifications.cjs +7 -0
  22. package/dist/v1/build/TinyNotifications.d.mts +3 -0
  23. package/dist/v1/build/TinyNotifications.mjs +2 -0
  24. package/dist/v1/index.cjs +26 -0
  25. package/dist/v1/index.d.mts +25 -1
  26. package/dist/v1/index.mjs +5 -3
  27. package/dist/v1/libs/TinyNotifications.cjs +238 -0
  28. package/dist/v1/libs/TinyNotifications.d.mts +106 -0
  29. package/dist/v1/libs/TinyNotifications.mjs +211 -0
  30. package/docs/v1/README.md +5 -3
  31. package/docs/v1/basics/array.md +16 -43
  32. package/docs/v1/basics/collision.md +237 -0
  33. package/docs/v1/basics/html.md +117 -28
  34. package/docs/v1/basics/text.md +44 -14
  35. package/docs/v1/libs/TinyNotifications.md +189 -0
  36. package/package.json +5 -2
@@ -0,0 +1,413 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * A direction relative to a rectangle.
5
+ *
6
+ * Represents one of the four cardinal directions from the perspective of the element.
7
+ *
8
+ * @typedef {'top' | 'bottom' | 'left' | 'right'} Dirs
9
+ */
10
+
11
+ /**
12
+ * Represents all directional aspects of a collision.
13
+ *
14
+ * @typedef {Object} CollDirs
15
+ * @property {Dirs | 'center' | null} in - The dominant direction of entry. `'center'` if all sides are equally overlapped. `null` if no collision.
16
+ * @property {Dirs | null} x - The horizontal direction (`'left'` or `'right'`) the collision is biased toward, or `null`.
17
+ * @property {Dirs | null} y - The vertical direction (`'top'` or `'bottom'`) the collision is biased toward, or `null`.
18
+ */
19
+
20
+ /**
21
+ * Indicates if a collision is in the negative direction (rect2 is outside rect1).
22
+ *
23
+ * @typedef {Object} NegCollDirs
24
+ * @property {Dirs | null} x - Horizontal direction of negative overlap, if any.
25
+ * @property {Dirs | null} y - Vertical direction of negative overlap, if any.
26
+ */
27
+
28
+ /**
29
+ * Collision depth values from each side of rect2 inside rect1.
30
+ *
31
+ * Positive values indicate penetration; negative values indicate gaps.
32
+ *
33
+ * @typedef {Object} CollData
34
+ * @property {number} top - Depth from rect2's top into rect1.
35
+ * @property {number} bottom - Depth from rect2's bottom into rect1.
36
+ * @property {number} left - Depth from rect2's left into rect1.
37
+ * @property {number} right - Depth from rect2's right into rect1.
38
+ */
39
+
40
+ /**
41
+ * X and Y offset representing center difference between two rectangles.
42
+ *
43
+ * Useful to measure how far one element's center is from another.
44
+ *
45
+ * @typedef {Object} CollCenter
46
+ * @property {number} x - Horizontal distance in pixels from rect1's center to rect2's center.
47
+ * @property {number} y - Vertical distance in pixels from rect1's center to rect2's center.
48
+ */
49
+
50
+ /**
51
+ * Represents a rectangular area in absolute pixel values.
52
+ *
53
+ * Similar to `DOMRect`, this object describes the dimensions and position of a box
54
+ * in the 2D plane, typically representing an element's bounding box.
55
+ *
56
+ * @typedef {Object} ObjRect
57
+ * @property {number} height - The total height of the rectangle in pixels.
58
+ * @property {number} width - The total width of the rectangle in pixels.
59
+ * @property {number} top - The Y-coordinate of the top edge of the rectangle.
60
+ * @property {number} bottom - The Y-coordinate of the bottom edge of the rectangle.
61
+ * @property {number} left - The X-coordinate of the left edge of the rectangle.
62
+ * @property {number} right - The X-coordinate of the right edge of the rectangle.
63
+ */
64
+
65
+ // Normal collision checks (loose overlap detection)
66
+
67
+ /**
68
+ * Checks if rect1 is completely above rect2 (no vertical overlap).
69
+ *
70
+ * @param {ObjRect} rect1 - The bounding rectangle of the first element.
71
+ * @param {ObjRect} rect2 - The bounding rectangle of the second element.
72
+ * @returns {boolean} True if rect1 is entirely above rect2.
73
+ */
74
+ const areElsCollTop = (rect1, rect2) => rect1.bottom < rect2.top;
75
+
76
+ /**
77
+ * Checks if rect1 is completely below rect2 (no vertical overlap).
78
+ *
79
+ * @param {ObjRect} rect1
80
+ * @param {ObjRect} rect2
81
+ * @returns {boolean} True if rect1 is entirely below rect2.
82
+ */
83
+ const areElsCollBottom = (rect1, rect2) => rect1.top > rect2.bottom;
84
+
85
+ /**
86
+ * Checks if rect1 is completely to the left of rect2 (no horizontal overlap).
87
+ *
88
+ * @param {ObjRect} rect1
89
+ * @param {ObjRect} rect2
90
+ * @returns {boolean} True if rect1 is entirely to the left of rect2.
91
+ */
92
+ const areElsCollLeft = (rect1, rect2) => rect1.right < rect2.left;
93
+
94
+ /**
95
+ * Checks if rect1 is completely to the right of rect2 (no horizontal overlap).
96
+ *
97
+ * @param {ObjRect} rect1
98
+ * @param {ObjRect} rect2
99
+ * @returns {boolean} True if rect1 is entirely to the right of rect2.
100
+ */
101
+ const areElsCollRight = (rect1, rect2) => rect1.left > rect2.right;
102
+
103
+ // Perfect collision checks (touch included)
104
+
105
+ /**
106
+ * Checks if rect1 is perfectly above rect2 (no vertical touch or overlap).
107
+ *
108
+ * @param {ObjRect} rect1
109
+ * @param {ObjRect} rect2
110
+ * @returns {boolean} True if rect1 is fully above or touching rect2's top.
111
+ */
112
+ const areElsCollPerfTop = (rect1, rect2) => rect1.bottom <= rect2.top;
113
+
114
+ /**
115
+ * Checks if rect1 is perfectly below rect2 (no vertical touch or overlap).
116
+ *
117
+ * @param {ObjRect} rect1
118
+ * @param {ObjRect} rect2
119
+ * @returns {boolean} True if rect1 is fully below or touching rect2's bottom.
120
+ */
121
+ const areElsCollPerfBottom = (rect1, rect2) => rect1.top >= rect2.bottom;
122
+
123
+ /**
124
+ * Checks if rect1 is perfectly to the left of rect2 (no horizontal touch or overlap).
125
+ *
126
+ * @param {ObjRect} rect1
127
+ * @param {ObjRect} rect2
128
+ * @returns {boolean} True if rect1 is fully left or touching rect2's left.
129
+ */
130
+ const areElsCollPerfLeft = (rect1, rect2) => rect1.right <= rect2.left;
131
+
132
+ /**
133
+ * Checks if rect1 is perfectly to the right of rect2 (no horizontal touch or overlap).
134
+ *
135
+ * @param {ObjRect} rect1
136
+ * @param {ObjRect} rect2
137
+ * @returns {boolean} True if rect1 is fully right or touching rect2's right.
138
+ */
139
+ const areElsCollPerfRight = (rect1, rect2) => rect1.left >= rect2.right;
140
+
141
+ // Main collision check
142
+
143
+ /**
144
+ * Returns true if rect1 and rect2 are colliding (partially or fully overlapping).
145
+ *
146
+ * @param {ObjRect} rect1
147
+ * @param {ObjRect} rect2
148
+ * @returns {boolean} True if there's any collision between rect1 and rect2.
149
+ */
150
+ const areElsColliding = (rect1, rect2) =>
151
+ !(
152
+ areElsCollLeft(rect1, rect2) ||
153
+ areElsCollRight(rect1, rect2) ||
154
+ areElsCollTop(rect1, rect2) ||
155
+ areElsCollBottom(rect1, rect2)
156
+ );
157
+
158
+ /**
159
+ * Returns true if rect1 and rect2 are colliding or perfectly touching.
160
+ *
161
+ * @param {ObjRect} rect1
162
+ * @param {ObjRect} rect2
163
+ * @returns {boolean} True if there's any contact or overlap.
164
+ */
165
+ const areElsPerfColliding = (rect1, rect2) =>
166
+ !(
167
+ areElsCollPerfLeft(rect1, rect2) ||
168
+ areElsCollPerfRight(rect1, rect2) ||
169
+ areElsCollPerfTop(rect1, rect2) ||
170
+ areElsCollPerfBottom(rect1, rect2)
171
+ );
172
+
173
+ // Collision direction guess (loose and perfect)
174
+
175
+ /**
176
+ * Attempts to determine the direction rect1 entered rect2 based on loose overlap rules.
177
+ *
178
+ * @param {ObjRect} rect1
179
+ * @param {ObjRect} rect2
180
+ * @returns {string|null} 'top' | 'bottom' | 'left' | 'right' | null
181
+ */
182
+ const getElsColliding = (rect1, rect2) => {
183
+ if (areElsCollLeft(rect1, rect2)) return 'left';
184
+ else if (areElsCollRight(rect1, rect2)) return 'right';
185
+ else if (areElsCollTop(rect1, rect2)) return 'top';
186
+ else if (areElsCollBottom(rect1, rect2)) return 'bottom';
187
+ return null;
188
+ };
189
+
190
+ /**
191
+ * Attempts to determine the direction rect1 touched or entered rect2 using perfect mode.
192
+ *
193
+ * @param {ObjRect} rect1
194
+ * @param {ObjRect} rect2
195
+ * @returns {'top' | 'bottom' | 'left' | 'right' | null}
196
+ */
197
+ const getElsPerfColliding = (rect1, rect2) => {
198
+ if (areElsCollPerfLeft(rect1, rect2)) return 'left';
199
+ else if (areElsCollPerfRight(rect1, rect2)) return 'right';
200
+ else if (areElsCollPerfTop(rect1, rect2)) return 'top';
201
+ else if (areElsCollPerfBottom(rect1, rect2)) return 'bottom';
202
+ return null;
203
+ };
204
+
205
+ // Overlap Calculation
206
+
207
+ /**
208
+ * Calculates overlap values between rect1 and rect2 in all directions.
209
+ *
210
+ * @param {ObjRect} rect1
211
+ * @param {ObjRect} rect2
212
+ * @returns {{
213
+ * overlapLeft: number,
214
+ * overlapRight: number,
215
+ * overlapTop: number,
216
+ * overlapBottom: number
217
+ * }} Distance of overlap from each direction (can be negative).
218
+ */
219
+ const getElsCollOverlap = (rect1, rect2) => ({
220
+ overlapLeft: rect2.right - rect1.left,
221
+ overlapRight: rect1.right - rect2.left,
222
+ overlapTop: rect2.bottom - rect1.top,
223
+ overlapBottom: rect1.bottom - rect2.top,
224
+ });
225
+
226
+ /**
227
+ * Determines directional collision based on overlap depth.
228
+ *
229
+ * @param {Object} [settings={}]
230
+ * @param {number} [settings.overlapLeft]
231
+ * @param {number} [settings.overlapRight]
232
+ * @param {number} [settings.overlapTop]
233
+ * @param {number} [settings.overlapBottom]
234
+ * @returns {{ dirX: Dirs, dirY: Dirs }} Direction of strongest X/Y overlap.
235
+ */
236
+ const getElsCollOverlapPos = ({
237
+ overlapLeft = -1,
238
+ overlapRight = -1,
239
+ overlapTop = -1,
240
+ overlapBottom = -1,
241
+ } = {}) => ({
242
+ dirX: overlapLeft < overlapRight ? 'right' : 'left',
243
+ dirY: overlapTop < overlapBottom ? 'bottom' : 'top',
244
+ });
245
+
246
+ // Center utils
247
+
248
+ /**
249
+ * Calculates the center point (X and Y) of a given Rect.
250
+ *
251
+ * @param {ObjRect} rect - The bounding rectangle of the element.
252
+ * @returns {{ x: number, y: number }} An object with the `x` and `y` coordinates of the center.
253
+ */
254
+ const getRectCenter = (rect) => ({
255
+ x: rect.left + rect.width / 2,
256
+ y: rect.top + rect.height / 2,
257
+ });
258
+
259
+ /**
260
+ * Calculates the offset between the center of rect2 and the center of rect1.
261
+ *
262
+ * The values will be 0 when rect1 is perfectly centered over rect2.
263
+ *
264
+ * @param {ObjRect} rect1 - The bounding rectangle of the reference element.
265
+ * @param {ObjRect} rect2 - The bounding rectangle of the element being compared.
266
+ * @returns {{
267
+ * x: number,
268
+ * y: number
269
+ * }} An object with the X and Y offset in pixels from rect1's center to rect2's center.
270
+ */
271
+ function getElsRelativeCenterOffset(rect1, rect2) {
272
+ const center1X = rect1.left + rect1.width / 2;
273
+ const center1Y = rect1.top + rect1.height / 2;
274
+
275
+ const center2X = rect2.left + rect2.width / 2;
276
+ const center2Y = rect2.top + rect2.height / 2;
277
+
278
+ return {
279
+ x: center2X - center1X,
280
+ y: center2Y - center1Y,
281
+ };
282
+ }
283
+
284
+ // Direction & Depth detection
285
+
286
+ /**
287
+ * Detects the direction of the dominant collision between two elements
288
+ * and calculates how deep the overlap is in both x and y axes.
289
+ *
290
+ * @param {ObjRect} rect1 - The bounding rectangle of the first element.
291
+ * @param {ObjRect} rect2 - The bounding rectangle of the second element.
292
+ * @returns {{
293
+ * inDir: Dirs | null;
294
+ * dirX: Dirs | null;
295
+ * dirY: Dirs | null;
296
+ * depthX: number;
297
+ * depthY: number;
298
+ * }} An object containing the collision direction and how deep the overlap is.
299
+ */
300
+ function getElsCollDirDepth(rect1, rect2) {
301
+ if (!areElsPerfColliding(rect1, rect2))
302
+ return {
303
+ inDir: null,
304
+ dirX: null,
305
+ dirY: null,
306
+ depthX: 0,
307
+ depthY: 0,
308
+ };
309
+
310
+ const { overlapLeft, overlapRight, overlapTop, overlapBottom } = getElsCollOverlap(rect1, rect2);
311
+ const { dirX, dirY } = getElsCollOverlapPos({
312
+ overlapLeft,
313
+ overlapRight,
314
+ overlapTop,
315
+ overlapBottom,
316
+ });
317
+ const depthX = Math.min(overlapLeft, overlapRight);
318
+ const depthY = Math.min(overlapTop, overlapBottom);
319
+
320
+ /** @type {Dirs} */
321
+ let inDir;
322
+
323
+ if (depthX < depthY) inDir = dirX;
324
+ else inDir = dirY;
325
+ return { inDir, dirX, dirY, depthX, depthY };
326
+ }
327
+
328
+ // Full detail report
329
+
330
+ /**
331
+ * Detects the collision direction and depth between two DOMRects.
332
+ *
333
+ * @param {ObjRect} rect1 - The bounding rectangle of the first element.
334
+ * @param {ObjRect} rect2 - The bounding rectangle of the second element.
335
+ * @returns {{ depth: CollData; dirs: CollDirs; isNeg: NegCollDirs; }} Collision info or null if no collision is detected.
336
+ */
337
+ function getElsCollDetails(rect1, rect2) {
338
+ const isColliding = areElsPerfColliding(rect1, rect2);
339
+
340
+ /** @type {CollDirs} */
341
+ const dirs = { in: null, x: null, y: null };
342
+
343
+ /** @type {NegCollDirs} */
344
+ const isNeg = { y: null, x: null };
345
+
346
+ /** @type {Record<Dirs, number>} */
347
+ const depth = { top: 0, bottom: 0, left: 0, right: 0 };
348
+
349
+ // Depth
350
+ // Yes, it's actually reversed the values orders
351
+ const { overlapLeft, overlapRight, overlapTop, overlapBottom } = getElsCollOverlap(rect2, rect1);
352
+ depth.top = overlapTop;
353
+ depth.bottom = overlapBottom;
354
+ depth.left = overlapLeft;
355
+ depth.right = overlapRight;
356
+
357
+ // Dirs
358
+ /**
359
+ * Detect the direction with the smallest positive overlap (entry point)
360
+ * @type {[Dirs, number][]}
361
+ */
362
+ // @ts-ignore
363
+ const entries = Object.entries(depth)
364
+ .filter(([, val]) => val > 0)
365
+ .sort((a, b) => a[1] - b[1]);
366
+
367
+ // Yes, it's actually reversed the values orders here too
368
+ const { dirX, dirY } = getElsCollOverlapPos({
369
+ overlapLeft: overlapRight,
370
+ overlapRight: overlapLeft,
371
+ overlapTop: overlapBottom,
372
+ overlapBottom: overlapTop,
373
+ });
374
+ dirs.y = dirY;
375
+ dirs.x = dirX;
376
+
377
+ // isNeg
378
+ if (depth.bottom < 0) isNeg.y = 'bottom';
379
+ else if (depth.top < 0) isNeg.y = 'top';
380
+ if (depth.left < 0) isNeg.x = 'left';
381
+ else if (depth.right < 0) isNeg.x = 'right';
382
+
383
+ // Inside Dir
384
+ dirs.in = isColliding
385
+ ? depth.top === depth.bottom && depth.bottom === depth.left && depth.left === depth.right
386
+ ? 'center'
387
+ : entries.length
388
+ ? entries[0][0]
389
+ : 'top'
390
+ : null; // fallback in case of exact match
391
+
392
+ // Complete
393
+ return { dirs, depth, isNeg };
394
+ }
395
+
396
+ exports.areElsCollBottom = areElsCollBottom;
397
+ exports.areElsCollLeft = areElsCollLeft;
398
+ exports.areElsCollPerfBottom = areElsCollPerfBottom;
399
+ exports.areElsCollPerfLeft = areElsCollPerfLeft;
400
+ exports.areElsCollPerfRight = areElsCollPerfRight;
401
+ exports.areElsCollPerfTop = areElsCollPerfTop;
402
+ exports.areElsCollRight = areElsCollRight;
403
+ exports.areElsCollTop = areElsCollTop;
404
+ exports.areElsColliding = areElsColliding;
405
+ exports.areElsPerfColliding = areElsPerfColliding;
406
+ exports.getElsCollDetails = getElsCollDetails;
407
+ exports.getElsCollDirDepth = getElsCollDirDepth;
408
+ exports.getElsCollOverlap = getElsCollOverlap;
409
+ exports.getElsCollOverlapPos = getElsCollOverlapPos;
410
+ exports.getElsColliding = getElsColliding;
411
+ exports.getElsPerfColliding = getElsPerfColliding;
412
+ exports.getElsRelativeCenterOffset = getElsRelativeCenterOffset;
413
+ exports.getRectCenter = getRectCenter;
@@ -0,0 +1,187 @@
1
+ /**
2
+ * Calculates the offset between the center of rect2 and the center of rect1.
3
+ *
4
+ * The values will be 0 when rect1 is perfectly centered over rect2.
5
+ *
6
+ * @param {ObjRect} rect1 - The bounding rectangle of the reference element.
7
+ * @param {ObjRect} rect2 - The bounding rectangle of the element being compared.
8
+ * @returns {{
9
+ * x: number,
10
+ * y: number
11
+ * }} An object with the X and Y offset in pixels from rect1's center to rect2's center.
12
+ */
13
+ export function getElsRelativeCenterOffset(rect1: ObjRect, rect2: ObjRect): {
14
+ x: number;
15
+ y: number;
16
+ };
17
+ /**
18
+ * Detects the direction of the dominant collision between two elements
19
+ * and calculates how deep the overlap is in both x and y axes.
20
+ *
21
+ * @param {ObjRect} rect1 - The bounding rectangle of the first element.
22
+ * @param {ObjRect} rect2 - The bounding rectangle of the second element.
23
+ * @returns {{
24
+ * inDir: Dirs | null;
25
+ * dirX: Dirs | null;
26
+ * dirY: Dirs | null;
27
+ * depthX: number;
28
+ * depthY: number;
29
+ * }} An object containing the collision direction and how deep the overlap is.
30
+ */
31
+ export function getElsCollDirDepth(rect1: ObjRect, rect2: ObjRect): {
32
+ inDir: Dirs | null;
33
+ dirX: Dirs | null;
34
+ dirY: Dirs | null;
35
+ depthX: number;
36
+ depthY: number;
37
+ };
38
+ /**
39
+ * Detects the collision direction and depth between two DOMRects.
40
+ *
41
+ * @param {ObjRect} rect1 - The bounding rectangle of the first element.
42
+ * @param {ObjRect} rect2 - The bounding rectangle of the second element.
43
+ * @returns {{ depth: CollData; dirs: CollDirs; isNeg: NegCollDirs; }} Collision info or null if no collision is detected.
44
+ */
45
+ export function getElsCollDetails(rect1: ObjRect, rect2: ObjRect): {
46
+ depth: CollData;
47
+ dirs: CollDirs;
48
+ isNeg: NegCollDirs;
49
+ };
50
+ export function areElsCollTop(rect1: ObjRect, rect2: ObjRect): boolean;
51
+ export function areElsCollBottom(rect1: ObjRect, rect2: ObjRect): boolean;
52
+ export function areElsCollLeft(rect1: ObjRect, rect2: ObjRect): boolean;
53
+ export function areElsCollRight(rect1: ObjRect, rect2: ObjRect): boolean;
54
+ export function areElsCollPerfTop(rect1: ObjRect, rect2: ObjRect): boolean;
55
+ export function areElsCollPerfBottom(rect1: ObjRect, rect2: ObjRect): boolean;
56
+ export function areElsCollPerfLeft(rect1: ObjRect, rect2: ObjRect): boolean;
57
+ export function areElsCollPerfRight(rect1: ObjRect, rect2: ObjRect): boolean;
58
+ export function areElsColliding(rect1: ObjRect, rect2: ObjRect): boolean;
59
+ export function areElsPerfColliding(rect1: ObjRect, rect2: ObjRect): boolean;
60
+ export function getElsColliding(rect1: ObjRect, rect2: ObjRect): string | null;
61
+ export function getElsPerfColliding(rect1: ObjRect, rect2: ObjRect): "top" | "bottom" | "left" | "right" | null;
62
+ export function getElsCollOverlap(rect1: ObjRect, rect2: ObjRect): {
63
+ overlapLeft: number;
64
+ overlapRight: number;
65
+ overlapTop: number;
66
+ overlapBottom: number;
67
+ };
68
+ export function getElsCollOverlapPos({ overlapLeft, overlapRight, overlapTop, overlapBottom, }?: {
69
+ overlapLeft?: number | undefined;
70
+ overlapRight?: number | undefined;
71
+ overlapTop?: number | undefined;
72
+ overlapBottom?: number | undefined;
73
+ }): {
74
+ dirX: Dirs;
75
+ dirY: Dirs;
76
+ };
77
+ export function getRectCenter(rect: ObjRect): {
78
+ x: number;
79
+ y: number;
80
+ };
81
+ /**
82
+ * A direction relative to a rectangle.
83
+ *
84
+ * Represents one of the four cardinal directions from the perspective of the element.
85
+ */
86
+ export type Dirs = "top" | "bottom" | "left" | "right";
87
+ /**
88
+ * Represents all directional aspects of a collision.
89
+ */
90
+ export type CollDirs = {
91
+ /**
92
+ * - The dominant direction of entry. `'center'` if all sides are equally overlapped. `null` if no collision.
93
+ */
94
+ in: Dirs | "center" | null;
95
+ /**
96
+ * - The horizontal direction (`'left'` or `'right'`) the collision is biased toward, or `null`.
97
+ */
98
+ x: Dirs | null;
99
+ /**
100
+ * - The vertical direction (`'top'` or `'bottom'`) the collision is biased toward, or `null`.
101
+ */
102
+ y: Dirs | null;
103
+ };
104
+ /**
105
+ * Indicates if a collision is in the negative direction (rect2 is outside rect1).
106
+ */
107
+ export type NegCollDirs = {
108
+ /**
109
+ * - Horizontal direction of negative overlap, if any.
110
+ */
111
+ x: Dirs | null;
112
+ /**
113
+ * - Vertical direction of negative overlap, if any.
114
+ */
115
+ y: Dirs | null;
116
+ };
117
+ /**
118
+ * Collision depth values from each side of rect2 inside rect1.
119
+ *
120
+ * Positive values indicate penetration; negative values indicate gaps.
121
+ */
122
+ export type CollData = {
123
+ /**
124
+ * - Depth from rect2's top into rect1.
125
+ */
126
+ top: number;
127
+ /**
128
+ * - Depth from rect2's bottom into rect1.
129
+ */
130
+ bottom: number;
131
+ /**
132
+ * - Depth from rect2's left into rect1.
133
+ */
134
+ left: number;
135
+ /**
136
+ * - Depth from rect2's right into rect1.
137
+ */
138
+ right: number;
139
+ };
140
+ /**
141
+ * X and Y offset representing center difference between two rectangles.
142
+ *
143
+ * Useful to measure how far one element's center is from another.
144
+ */
145
+ export type CollCenter = {
146
+ /**
147
+ * - Horizontal distance in pixels from rect1's center to rect2's center.
148
+ */
149
+ x: number;
150
+ /**
151
+ * - Vertical distance in pixels from rect1's center to rect2's center.
152
+ */
153
+ y: number;
154
+ };
155
+ /**
156
+ * Represents a rectangular area in absolute pixel values.
157
+ *
158
+ * Similar to `DOMRect`, this object describes the dimensions and position of a box
159
+ * in the 2D plane, typically representing an element's bounding box.
160
+ */
161
+ export type ObjRect = {
162
+ /**
163
+ * - The total height of the rectangle in pixels.
164
+ */
165
+ height: number;
166
+ /**
167
+ * - The total width of the rectangle in pixels.
168
+ */
169
+ width: number;
170
+ /**
171
+ * - The Y-coordinate of the top edge of the rectangle.
172
+ */
173
+ top: number;
174
+ /**
175
+ * - The Y-coordinate of the bottom edge of the rectangle.
176
+ */
177
+ bottom: number;
178
+ /**
179
+ * - The X-coordinate of the left edge of the rectangle.
180
+ */
181
+ left: number;
182
+ /**
183
+ * - The X-coordinate of the right edge of the rectangle.
184
+ */
185
+ right: number;
186
+ };
187
+ //# sourceMappingURL=collision.d.mts.map