tiny-essentials 1.14.0 → 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.
- package/dist/v1/TinyBasicsEs.js +496 -6
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyDragger.js +81 -6
- package/dist/v1/TinyEssentials.js +496 -6
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyUploadClicker.js +82 -6
- package/dist/v1/basics/collision.cjs +413 -0
- package/dist/v1/basics/collision.d.mts +187 -0
- package/dist/v1/basics/collision.mjs +350 -0
- package/dist/v1/basics/html.cjs +84 -6
- package/dist/v1/basics/html.d.mts +25 -0
- package/dist/v1/basics/html.mjs +74 -4
- package/dist/v1/basics/index.cjs +21 -0
- package/dist/v1/basics/index.d.mts +21 -1
- package/dist/v1/basics/index.mjs +3 -2
- package/dist/v1/index.cjs +21 -0
- package/dist/v1/index.d.mts +21 -1
- package/dist/v1/index.mjs +3 -2
- package/docs/v1/README.md +1 -0
- package/docs/v1/basics/collision.md +237 -0
- package/docs/v1/basics/html.md +27 -1
- package/package.json +5 -2
|
@@ -2896,6 +2896,16 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
2896
2896
|
TinyRateLimiter: () => (/* reexport */ libs_TinyRateLimiter),
|
|
2897
2897
|
TinyToastNotify: () => (/* reexport */ libs_TinyToastNotify),
|
|
2898
2898
|
addAiMarkerShortcut: () => (/* reexport */ addAiMarkerShortcut),
|
|
2899
|
+
areElsCollBottom: () => (/* reexport */ collision_areElsCollBottom),
|
|
2900
|
+
areElsCollLeft: () => (/* reexport */ collision_areElsCollLeft),
|
|
2901
|
+
areElsCollPerfBottom: () => (/* reexport */ areElsCollPerfBottom),
|
|
2902
|
+
areElsCollPerfLeft: () => (/* reexport */ areElsCollPerfLeft),
|
|
2903
|
+
areElsCollPerfRight: () => (/* reexport */ areElsCollPerfRight),
|
|
2904
|
+
areElsCollPerfTop: () => (/* reexport */ areElsCollPerfTop),
|
|
2905
|
+
areElsCollRight: () => (/* reexport */ collision_areElsCollRight),
|
|
2906
|
+
areElsCollTop: () => (/* reexport */ collision_areElsCollTop),
|
|
2907
|
+
areElsColliding: () => (/* reexport */ collision_areElsColliding),
|
|
2908
|
+
areElsPerfColliding: () => (/* reexport */ areElsPerfColliding),
|
|
2899
2909
|
areHtmlElsColliding: () => (/* reexport */ areHtmlElsColliding),
|
|
2900
2910
|
arraySortPositions: () => (/* reexport */ arraySortPositions),
|
|
2901
2911
|
asyncReplace: () => (/* reexport */ asyncReplace),
|
|
@@ -2923,19 +2933,29 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
2923
2933
|
formatTimer: () => (/* reexport */ formatTimer),
|
|
2924
2934
|
genFibonacciSeq: () => (/* reexport */ genFibonacciSeq),
|
|
2925
2935
|
getAge: () => (/* reexport */ getAge),
|
|
2936
|
+
getElsCollDetails: () => (/* reexport */ getElsCollDetails),
|
|
2937
|
+
getElsCollDirDepth: () => (/* reexport */ getElsCollDirDepth),
|
|
2938
|
+
getElsCollOverlap: () => (/* reexport */ getElsCollOverlap),
|
|
2939
|
+
getElsCollOverlapPos: () => (/* reexport */ getElsCollOverlapPos),
|
|
2940
|
+
getElsColliding: () => (/* reexport */ getElsColliding),
|
|
2941
|
+
getElsPerfColliding: () => (/* reexport */ getElsPerfColliding),
|
|
2942
|
+
getElsRelativeCenterOffset: () => (/* reexport */ getElsRelativeCenterOffset),
|
|
2926
2943
|
getHtmlElBorders: () => (/* reexport */ getHtmlElBorders),
|
|
2927
2944
|
getHtmlElBordersWidth: () => (/* reexport */ getHtmlElBordersWidth),
|
|
2928
2945
|
getHtmlElMargin: () => (/* reexport */ getHtmlElMargin),
|
|
2929
2946
|
getHtmlElPadding: () => (/* reexport */ getHtmlElPadding),
|
|
2930
2947
|
getLatestBackupPath: () => (/* reexport */ normalFuncs_getLatestBackupPath),
|
|
2948
|
+
getRectCenter: () => (/* reexport */ getRectCenter),
|
|
2931
2949
|
getSimplePerc: () => (/* reexport */ getSimplePerc),
|
|
2932
2950
|
getTimeDuration: () => (/* reexport */ getTimeDuration),
|
|
2933
2951
|
installWindowHiddenScript: () => (/* reexport */ installWindowHiddenScript),
|
|
2934
2952
|
isDirEmpty: () => (/* reexport */ isDirEmpty),
|
|
2935
2953
|
isDirEmptyAsync: () => (/* reexport */ isDirEmptyAsync),
|
|
2936
2954
|
isFullScreenMode: () => (/* reexport */ isFullScreenMode),
|
|
2955
|
+
isInViewport: () => (/* reexport */ isInViewport),
|
|
2937
2956
|
isJsonObject: () => (/* reexport */ isJsonObject),
|
|
2938
2957
|
isScreenFilled: () => (/* reexport */ isScreenFilled),
|
|
2958
|
+
isScrolledIntoView: () => (/* reexport */ isScrolledIntoView),
|
|
2939
2959
|
listDirs: () => (/* reexport */ listDirs),
|
|
2940
2960
|
listDirsAsync: () => (/* reexport */ listDirsAsync),
|
|
2941
2961
|
listFiles: () => (/* reexport */ listFiles),
|
|
@@ -6189,9 +6209,404 @@ class TinyToastNotify {
|
|
|
6189
6209
|
|
|
6190
6210
|
/* harmony default export */ const libs_TinyToastNotify = (TinyToastNotify);
|
|
6191
6211
|
|
|
6212
|
+
;// ./src/v1/basics/collision.mjs
|
|
6213
|
+
/**
|
|
6214
|
+
* A direction relative to a rectangle.
|
|
6215
|
+
*
|
|
6216
|
+
* Represents one of the four cardinal directions from the perspective of the element.
|
|
6217
|
+
*
|
|
6218
|
+
* @typedef {'top' | 'bottom' | 'left' | 'right'} Dirs
|
|
6219
|
+
*/
|
|
6220
|
+
|
|
6221
|
+
/**
|
|
6222
|
+
* Represents all directional aspects of a collision.
|
|
6223
|
+
*
|
|
6224
|
+
* @typedef {Object} CollDirs
|
|
6225
|
+
* @property {Dirs | 'center' | null} in - The dominant direction of entry. `'center'` if all sides are equally overlapped. `null` if no collision.
|
|
6226
|
+
* @property {Dirs | null} x - The horizontal direction (`'left'` or `'right'`) the collision is biased toward, or `null`.
|
|
6227
|
+
* @property {Dirs | null} y - The vertical direction (`'top'` or `'bottom'`) the collision is biased toward, or `null`.
|
|
6228
|
+
*/
|
|
6229
|
+
|
|
6230
|
+
/**
|
|
6231
|
+
* Indicates if a collision is in the negative direction (rect2 is outside rect1).
|
|
6232
|
+
*
|
|
6233
|
+
* @typedef {Object} NegCollDirs
|
|
6234
|
+
* @property {Dirs | null} x - Horizontal direction of negative overlap, if any.
|
|
6235
|
+
* @property {Dirs | null} y - Vertical direction of negative overlap, if any.
|
|
6236
|
+
*/
|
|
6237
|
+
|
|
6238
|
+
/**
|
|
6239
|
+
* Collision depth values from each side of rect2 inside rect1.
|
|
6240
|
+
*
|
|
6241
|
+
* Positive values indicate penetration; negative values indicate gaps.
|
|
6242
|
+
*
|
|
6243
|
+
* @typedef {Object} CollData
|
|
6244
|
+
* @property {number} top - Depth from rect2's top into rect1.
|
|
6245
|
+
* @property {number} bottom - Depth from rect2's bottom into rect1.
|
|
6246
|
+
* @property {number} left - Depth from rect2's left into rect1.
|
|
6247
|
+
* @property {number} right - Depth from rect2's right into rect1.
|
|
6248
|
+
*/
|
|
6249
|
+
|
|
6250
|
+
/**
|
|
6251
|
+
* X and Y offset representing center difference between two rectangles.
|
|
6252
|
+
*
|
|
6253
|
+
* Useful to measure how far one element's center is from another.
|
|
6254
|
+
*
|
|
6255
|
+
* @typedef {Object} CollCenter
|
|
6256
|
+
* @property {number} x - Horizontal distance in pixels from rect1's center to rect2's center.
|
|
6257
|
+
* @property {number} y - Vertical distance in pixels from rect1's center to rect2's center.
|
|
6258
|
+
*/
|
|
6259
|
+
|
|
6260
|
+
/**
|
|
6261
|
+
* Represents a rectangular area in absolute pixel values.
|
|
6262
|
+
*
|
|
6263
|
+
* Similar to `DOMRect`, this object describes the dimensions and position of a box
|
|
6264
|
+
* in the 2D plane, typically representing an element's bounding box.
|
|
6265
|
+
*
|
|
6266
|
+
* @typedef {Object} ObjRect
|
|
6267
|
+
* @property {number} height - The total height of the rectangle in pixels.
|
|
6268
|
+
* @property {number} width - The total width of the rectangle in pixels.
|
|
6269
|
+
* @property {number} top - The Y-coordinate of the top edge of the rectangle.
|
|
6270
|
+
* @property {number} bottom - The Y-coordinate of the bottom edge of the rectangle.
|
|
6271
|
+
* @property {number} left - The X-coordinate of the left edge of the rectangle.
|
|
6272
|
+
* @property {number} right - The X-coordinate of the right edge of the rectangle.
|
|
6273
|
+
*/
|
|
6274
|
+
|
|
6275
|
+
// Normal collision checks (loose overlap detection)
|
|
6276
|
+
|
|
6277
|
+
/**
|
|
6278
|
+
* Checks if rect1 is completely above rect2 (no vertical overlap).
|
|
6279
|
+
*
|
|
6280
|
+
* @param {ObjRect} rect1 - The bounding rectangle of the first element.
|
|
6281
|
+
* @param {ObjRect} rect2 - The bounding rectangle of the second element.
|
|
6282
|
+
* @returns {boolean} True if rect1 is entirely above rect2.
|
|
6283
|
+
*/
|
|
6284
|
+
const collision_areElsCollTop = (rect1, rect2) => rect1.bottom < rect2.top;
|
|
6285
|
+
|
|
6286
|
+
/**
|
|
6287
|
+
* Checks if rect1 is completely below rect2 (no vertical overlap).
|
|
6288
|
+
*
|
|
6289
|
+
* @param {ObjRect} rect1
|
|
6290
|
+
* @param {ObjRect} rect2
|
|
6291
|
+
* @returns {boolean} True if rect1 is entirely below rect2.
|
|
6292
|
+
*/
|
|
6293
|
+
const collision_areElsCollBottom = (rect1, rect2) => rect1.top > rect2.bottom;
|
|
6294
|
+
|
|
6295
|
+
/**
|
|
6296
|
+
* Checks if rect1 is completely to the left of rect2 (no horizontal overlap).
|
|
6297
|
+
*
|
|
6298
|
+
* @param {ObjRect} rect1
|
|
6299
|
+
* @param {ObjRect} rect2
|
|
6300
|
+
* @returns {boolean} True if rect1 is entirely to the left of rect2.
|
|
6301
|
+
*/
|
|
6302
|
+
const collision_areElsCollLeft = (rect1, rect2) => rect1.right < rect2.left;
|
|
6303
|
+
|
|
6304
|
+
/**
|
|
6305
|
+
* Checks if rect1 is completely to the right of rect2 (no horizontal overlap).
|
|
6306
|
+
*
|
|
6307
|
+
* @param {ObjRect} rect1
|
|
6308
|
+
* @param {ObjRect} rect2
|
|
6309
|
+
* @returns {boolean} True if rect1 is entirely to the right of rect2.
|
|
6310
|
+
*/
|
|
6311
|
+
const collision_areElsCollRight = (rect1, rect2) => rect1.left > rect2.right;
|
|
6312
|
+
|
|
6313
|
+
// Perfect collision checks (touch included)
|
|
6314
|
+
|
|
6315
|
+
/**
|
|
6316
|
+
* Checks if rect1 is perfectly above rect2 (no vertical touch or overlap).
|
|
6317
|
+
*
|
|
6318
|
+
* @param {ObjRect} rect1
|
|
6319
|
+
* @param {ObjRect} rect2
|
|
6320
|
+
* @returns {boolean} True if rect1 is fully above or touching rect2's top.
|
|
6321
|
+
*/
|
|
6322
|
+
const areElsCollPerfTop = (rect1, rect2) => rect1.bottom <= rect2.top;
|
|
6323
|
+
|
|
6324
|
+
/**
|
|
6325
|
+
* Checks if rect1 is perfectly below rect2 (no vertical touch or overlap).
|
|
6326
|
+
*
|
|
6327
|
+
* @param {ObjRect} rect1
|
|
6328
|
+
* @param {ObjRect} rect2
|
|
6329
|
+
* @returns {boolean} True if rect1 is fully below or touching rect2's bottom.
|
|
6330
|
+
*/
|
|
6331
|
+
const areElsCollPerfBottom = (rect1, rect2) => rect1.top >= rect2.bottom;
|
|
6332
|
+
|
|
6333
|
+
/**
|
|
6334
|
+
* Checks if rect1 is perfectly to the left of rect2 (no horizontal touch or overlap).
|
|
6335
|
+
*
|
|
6336
|
+
* @param {ObjRect} rect1
|
|
6337
|
+
* @param {ObjRect} rect2
|
|
6338
|
+
* @returns {boolean} True if rect1 is fully left or touching rect2's left.
|
|
6339
|
+
*/
|
|
6340
|
+
const areElsCollPerfLeft = (rect1, rect2) => rect1.right <= rect2.left;
|
|
6341
|
+
|
|
6342
|
+
/**
|
|
6343
|
+
* Checks if rect1 is perfectly to the right of rect2 (no horizontal touch or overlap).
|
|
6344
|
+
*
|
|
6345
|
+
* @param {ObjRect} rect1
|
|
6346
|
+
* @param {ObjRect} rect2
|
|
6347
|
+
* @returns {boolean} True if rect1 is fully right or touching rect2's right.
|
|
6348
|
+
*/
|
|
6349
|
+
const areElsCollPerfRight = (rect1, rect2) => rect1.left >= rect2.right;
|
|
6350
|
+
|
|
6351
|
+
// Main collision check
|
|
6352
|
+
|
|
6353
|
+
/**
|
|
6354
|
+
* Returns true if rect1 and rect2 are colliding (partially or fully overlapping).
|
|
6355
|
+
*
|
|
6356
|
+
* @param {ObjRect} rect1
|
|
6357
|
+
* @param {ObjRect} rect2
|
|
6358
|
+
* @returns {boolean} True if there's any collision between rect1 and rect2.
|
|
6359
|
+
*/
|
|
6360
|
+
const collision_areElsColliding = (rect1, rect2) =>
|
|
6361
|
+
!(
|
|
6362
|
+
collision_areElsCollLeft(rect1, rect2) ||
|
|
6363
|
+
collision_areElsCollRight(rect1, rect2) ||
|
|
6364
|
+
collision_areElsCollTop(rect1, rect2) ||
|
|
6365
|
+
collision_areElsCollBottom(rect1, rect2)
|
|
6366
|
+
);
|
|
6367
|
+
|
|
6368
|
+
/**
|
|
6369
|
+
* Returns true if rect1 and rect2 are colliding or perfectly touching.
|
|
6370
|
+
*
|
|
6371
|
+
* @param {ObjRect} rect1
|
|
6372
|
+
* @param {ObjRect} rect2
|
|
6373
|
+
* @returns {boolean} True if there's any contact or overlap.
|
|
6374
|
+
*/
|
|
6375
|
+
const areElsPerfColliding = (rect1, rect2) =>
|
|
6376
|
+
!(
|
|
6377
|
+
areElsCollPerfLeft(rect1, rect2) ||
|
|
6378
|
+
areElsCollPerfRight(rect1, rect2) ||
|
|
6379
|
+
areElsCollPerfTop(rect1, rect2) ||
|
|
6380
|
+
areElsCollPerfBottom(rect1, rect2)
|
|
6381
|
+
);
|
|
6382
|
+
|
|
6383
|
+
// Collision direction guess (loose and perfect)
|
|
6384
|
+
|
|
6385
|
+
/**
|
|
6386
|
+
* Attempts to determine the direction rect1 entered rect2 based on loose overlap rules.
|
|
6387
|
+
*
|
|
6388
|
+
* @param {ObjRect} rect1
|
|
6389
|
+
* @param {ObjRect} rect2
|
|
6390
|
+
* @returns {string|null} 'top' | 'bottom' | 'left' | 'right' | null
|
|
6391
|
+
*/
|
|
6392
|
+
const getElsColliding = (rect1, rect2) => {
|
|
6393
|
+
if (collision_areElsCollLeft(rect1, rect2)) return 'left';
|
|
6394
|
+
else if (collision_areElsCollRight(rect1, rect2)) return 'right';
|
|
6395
|
+
else if (collision_areElsCollTop(rect1, rect2)) return 'top';
|
|
6396
|
+
else if (collision_areElsCollBottom(rect1, rect2)) return 'bottom';
|
|
6397
|
+
return null;
|
|
6398
|
+
};
|
|
6399
|
+
|
|
6400
|
+
/**
|
|
6401
|
+
* Attempts to determine the direction rect1 touched or entered rect2 using perfect mode.
|
|
6402
|
+
*
|
|
6403
|
+
* @param {ObjRect} rect1
|
|
6404
|
+
* @param {ObjRect} rect2
|
|
6405
|
+
* @returns {'top' | 'bottom' | 'left' | 'right' | null}
|
|
6406
|
+
*/
|
|
6407
|
+
const getElsPerfColliding = (rect1, rect2) => {
|
|
6408
|
+
if (areElsCollPerfLeft(rect1, rect2)) return 'left';
|
|
6409
|
+
else if (areElsCollPerfRight(rect1, rect2)) return 'right';
|
|
6410
|
+
else if (areElsCollPerfTop(rect1, rect2)) return 'top';
|
|
6411
|
+
else if (areElsCollPerfBottom(rect1, rect2)) return 'bottom';
|
|
6412
|
+
return null;
|
|
6413
|
+
};
|
|
6414
|
+
|
|
6415
|
+
// Overlap Calculation
|
|
6416
|
+
|
|
6417
|
+
/**
|
|
6418
|
+
* Calculates overlap values between rect1 and rect2 in all directions.
|
|
6419
|
+
*
|
|
6420
|
+
* @param {ObjRect} rect1
|
|
6421
|
+
* @param {ObjRect} rect2
|
|
6422
|
+
* @returns {{
|
|
6423
|
+
* overlapLeft: number,
|
|
6424
|
+
* overlapRight: number,
|
|
6425
|
+
* overlapTop: number,
|
|
6426
|
+
* overlapBottom: number
|
|
6427
|
+
* }} Distance of overlap from each direction (can be negative).
|
|
6428
|
+
*/
|
|
6429
|
+
const getElsCollOverlap = (rect1, rect2) => ({
|
|
6430
|
+
overlapLeft: rect2.right - rect1.left,
|
|
6431
|
+
overlapRight: rect1.right - rect2.left,
|
|
6432
|
+
overlapTop: rect2.bottom - rect1.top,
|
|
6433
|
+
overlapBottom: rect1.bottom - rect2.top,
|
|
6434
|
+
});
|
|
6435
|
+
|
|
6436
|
+
/**
|
|
6437
|
+
* Determines directional collision based on overlap depth.
|
|
6438
|
+
*
|
|
6439
|
+
* @param {Object} [settings={}]
|
|
6440
|
+
* @param {number} [settings.overlapLeft]
|
|
6441
|
+
* @param {number} [settings.overlapRight]
|
|
6442
|
+
* @param {number} [settings.overlapTop]
|
|
6443
|
+
* @param {number} [settings.overlapBottom]
|
|
6444
|
+
* @returns {{ dirX: Dirs, dirY: Dirs }} Direction of strongest X/Y overlap.
|
|
6445
|
+
*/
|
|
6446
|
+
const getElsCollOverlapPos = ({
|
|
6447
|
+
overlapLeft = -1,
|
|
6448
|
+
overlapRight = -1,
|
|
6449
|
+
overlapTop = -1,
|
|
6450
|
+
overlapBottom = -1,
|
|
6451
|
+
} = {}) => ({
|
|
6452
|
+
dirX: overlapLeft < overlapRight ? 'right' : 'left',
|
|
6453
|
+
dirY: overlapTop < overlapBottom ? 'bottom' : 'top',
|
|
6454
|
+
});
|
|
6455
|
+
|
|
6456
|
+
// Center utils
|
|
6457
|
+
|
|
6458
|
+
/**
|
|
6459
|
+
* Calculates the center point (X and Y) of a given Rect.
|
|
6460
|
+
*
|
|
6461
|
+
* @param {ObjRect} rect - The bounding rectangle of the element.
|
|
6462
|
+
* @returns {{ x: number, y: number }} An object with the `x` and `y` coordinates of the center.
|
|
6463
|
+
*/
|
|
6464
|
+
const getRectCenter = (rect) => ({
|
|
6465
|
+
x: rect.left + rect.width / 2,
|
|
6466
|
+
y: rect.top + rect.height / 2,
|
|
6467
|
+
});
|
|
6468
|
+
|
|
6469
|
+
/**
|
|
6470
|
+
* Calculates the offset between the center of rect2 and the center of rect1.
|
|
6471
|
+
*
|
|
6472
|
+
* The values will be 0 when rect1 is perfectly centered over rect2.
|
|
6473
|
+
*
|
|
6474
|
+
* @param {ObjRect} rect1 - The bounding rectangle of the reference element.
|
|
6475
|
+
* @param {ObjRect} rect2 - The bounding rectangle of the element being compared.
|
|
6476
|
+
* @returns {{
|
|
6477
|
+
* x: number,
|
|
6478
|
+
* y: number
|
|
6479
|
+
* }} An object with the X and Y offset in pixels from rect1's center to rect2's center.
|
|
6480
|
+
*/
|
|
6481
|
+
function getElsRelativeCenterOffset(rect1, rect2) {
|
|
6482
|
+
const center1X = rect1.left + rect1.width / 2;
|
|
6483
|
+
const center1Y = rect1.top + rect1.height / 2;
|
|
6484
|
+
|
|
6485
|
+
const center2X = rect2.left + rect2.width / 2;
|
|
6486
|
+
const center2Y = rect2.top + rect2.height / 2;
|
|
6487
|
+
|
|
6488
|
+
return {
|
|
6489
|
+
x: center2X - center1X,
|
|
6490
|
+
y: center2Y - center1Y,
|
|
6491
|
+
};
|
|
6492
|
+
}
|
|
6493
|
+
|
|
6494
|
+
// Direction & Depth detection
|
|
6495
|
+
|
|
6496
|
+
/**
|
|
6497
|
+
* Detects the direction of the dominant collision between two elements
|
|
6498
|
+
* and calculates how deep the overlap is in both x and y axes.
|
|
6499
|
+
*
|
|
6500
|
+
* @param {ObjRect} rect1 - The bounding rectangle of the first element.
|
|
6501
|
+
* @param {ObjRect} rect2 - The bounding rectangle of the second element.
|
|
6502
|
+
* @returns {{
|
|
6503
|
+
* inDir: Dirs | null;
|
|
6504
|
+
* dirX: Dirs | null;
|
|
6505
|
+
* dirY: Dirs | null;
|
|
6506
|
+
* depthX: number;
|
|
6507
|
+
* depthY: number;
|
|
6508
|
+
* }} An object containing the collision direction and how deep the overlap is.
|
|
6509
|
+
*/
|
|
6510
|
+
function getElsCollDirDepth(rect1, rect2) {
|
|
6511
|
+
if (!areElsPerfColliding(rect1, rect2))
|
|
6512
|
+
return {
|
|
6513
|
+
inDir: null,
|
|
6514
|
+
dirX: null,
|
|
6515
|
+
dirY: null,
|
|
6516
|
+
depthX: 0,
|
|
6517
|
+
depthY: 0,
|
|
6518
|
+
};
|
|
6519
|
+
|
|
6520
|
+
const { overlapLeft, overlapRight, overlapTop, overlapBottom } = getElsCollOverlap(rect1, rect2);
|
|
6521
|
+
const { dirX, dirY } = getElsCollOverlapPos({
|
|
6522
|
+
overlapLeft,
|
|
6523
|
+
overlapRight,
|
|
6524
|
+
overlapTop,
|
|
6525
|
+
overlapBottom,
|
|
6526
|
+
});
|
|
6527
|
+
const depthX = Math.min(overlapLeft, overlapRight);
|
|
6528
|
+
const depthY = Math.min(overlapTop, overlapBottom);
|
|
6529
|
+
|
|
6530
|
+
/** @type {Dirs} */
|
|
6531
|
+
let inDir;
|
|
6532
|
+
|
|
6533
|
+
if (depthX < depthY) inDir = dirX;
|
|
6534
|
+
else inDir = dirY;
|
|
6535
|
+
return { inDir, dirX, dirY, depthX, depthY };
|
|
6536
|
+
}
|
|
6537
|
+
|
|
6538
|
+
// Full detail report
|
|
6539
|
+
|
|
6540
|
+
/**
|
|
6541
|
+
* Detects the collision direction and depth between two DOMRects.
|
|
6542
|
+
*
|
|
6543
|
+
* @param {ObjRect} rect1 - The bounding rectangle of the first element.
|
|
6544
|
+
* @param {ObjRect} rect2 - The bounding rectangle of the second element.
|
|
6545
|
+
* @returns {{ depth: CollData; dirs: CollDirs; isNeg: NegCollDirs; }} Collision info or null if no collision is detected.
|
|
6546
|
+
*/
|
|
6547
|
+
function getElsCollDetails(rect1, rect2) {
|
|
6548
|
+
const isColliding = areElsPerfColliding(rect1, rect2);
|
|
6549
|
+
|
|
6550
|
+
/** @type {CollDirs} */
|
|
6551
|
+
const dirs = { in: null, x: null, y: null };
|
|
6552
|
+
|
|
6553
|
+
/** @type {NegCollDirs} */
|
|
6554
|
+
const isNeg = { y: null, x: null };
|
|
6555
|
+
|
|
6556
|
+
/** @type {Record<Dirs, number>} */
|
|
6557
|
+
const depth = { top: 0, bottom: 0, left: 0, right: 0 };
|
|
6558
|
+
|
|
6559
|
+
// Depth
|
|
6560
|
+
// Yes, it's actually reversed the values orders
|
|
6561
|
+
const { overlapLeft, overlapRight, overlapTop, overlapBottom } = getElsCollOverlap(rect2, rect1);
|
|
6562
|
+
depth.top = overlapTop;
|
|
6563
|
+
depth.bottom = overlapBottom;
|
|
6564
|
+
depth.left = overlapLeft;
|
|
6565
|
+
depth.right = overlapRight;
|
|
6566
|
+
|
|
6567
|
+
// Dirs
|
|
6568
|
+
/**
|
|
6569
|
+
* Detect the direction with the smallest positive overlap (entry point)
|
|
6570
|
+
* @type {[Dirs, number][]}
|
|
6571
|
+
*/
|
|
6572
|
+
// @ts-ignore
|
|
6573
|
+
const entries = Object.entries(depth)
|
|
6574
|
+
.filter(([, val]) => val > 0)
|
|
6575
|
+
.sort((a, b) => a[1] - b[1]);
|
|
6576
|
+
|
|
6577
|
+
// Yes, it's actually reversed the values orders here too
|
|
6578
|
+
const { dirX, dirY } = getElsCollOverlapPos({
|
|
6579
|
+
overlapLeft: overlapRight,
|
|
6580
|
+
overlapRight: overlapLeft,
|
|
6581
|
+
overlapTop: overlapBottom,
|
|
6582
|
+
overlapBottom: overlapTop,
|
|
6583
|
+
});
|
|
6584
|
+
dirs.y = dirY;
|
|
6585
|
+
dirs.x = dirX;
|
|
6586
|
+
|
|
6587
|
+
// isNeg
|
|
6588
|
+
if (depth.bottom < 0) isNeg.y = 'bottom';
|
|
6589
|
+
else if (depth.top < 0) isNeg.y = 'top';
|
|
6590
|
+
if (depth.left < 0) isNeg.x = 'left';
|
|
6591
|
+
else if (depth.right < 0) isNeg.x = 'right';
|
|
6592
|
+
|
|
6593
|
+
// Inside Dir
|
|
6594
|
+
dirs.in = isColliding
|
|
6595
|
+
? depth.top === depth.bottom && depth.bottom === depth.left && depth.left === depth.right
|
|
6596
|
+
? 'center'
|
|
6597
|
+
: entries.length
|
|
6598
|
+
? entries[0][0]
|
|
6599
|
+
: 'top'
|
|
6600
|
+
: null; // fallback in case of exact match
|
|
6601
|
+
|
|
6602
|
+
// Complete
|
|
6603
|
+
return { dirs, depth, isNeg };
|
|
6604
|
+
}
|
|
6605
|
+
|
|
6192
6606
|
;// ./src/v1/basics/html.mjs
|
|
6193
6607
|
|
|
6194
6608
|
|
|
6609
|
+
|
|
6195
6610
|
/**
|
|
6196
6611
|
* Checks if two DOM elements are colliding on the screen.
|
|
6197
6612
|
*
|
|
@@ -6202,13 +6617,55 @@ class TinyToastNotify {
|
|
|
6202
6617
|
function areHtmlElsColliding(elem1, elem2) {
|
|
6203
6618
|
const rect1 = elem1.getBoundingClientRect();
|
|
6204
6619
|
const rect2 = elem2.getBoundingClientRect();
|
|
6620
|
+
return collision_areElsColliding(rect1, rect2);
|
|
6621
|
+
}
|
|
6205
6622
|
|
|
6206
|
-
|
|
6207
|
-
|
|
6208
|
-
|
|
6209
|
-
|
|
6210
|
-
|
|
6211
|
-
|
|
6623
|
+
/**
|
|
6624
|
+
* Checks if two DOM elements are colliding on the screen, and locks the collision
|
|
6625
|
+
* until the element exits through the same side it entered.
|
|
6626
|
+
*
|
|
6627
|
+
* @param {Element} elem1 - First DOM element (e.g. draggable or moving element).
|
|
6628
|
+
* @param {Element} elem2 - Second DOM element (e.g. a container or boundary element).
|
|
6629
|
+
* @param {'top'|'bottom'|'left'|'right'} lockDirection - Direction that must be respected to unlock the collision.
|
|
6630
|
+
* @param {WeakMap<Element, string>} stateMap - A shared WeakMap to track persistent entry direction per element.
|
|
6631
|
+
* @returns {boolean} True if collision is still active.
|
|
6632
|
+
*/
|
|
6633
|
+
function areHtmlElsCollidingWithLock(elem1, elem2, lockDirection, stateMap) {
|
|
6634
|
+
const rect1 = elem1.getBoundingClientRect();
|
|
6635
|
+
const rect2 = elem2.getBoundingClientRect();
|
|
6636
|
+
const isColliding = areElsColliding(rect1, rect2);
|
|
6637
|
+
|
|
6638
|
+
if (isColliding) {
|
|
6639
|
+
// Save entry direction
|
|
6640
|
+
if (!stateMap.has(elem1)) {
|
|
6641
|
+
stateMap.set(elem1, lockDirection);
|
|
6642
|
+
}
|
|
6643
|
+
return true;
|
|
6644
|
+
}
|
|
6645
|
+
|
|
6646
|
+
// Handle unlock logic
|
|
6647
|
+
if (stateMap.has(elem1)) {
|
|
6648
|
+
const lastDirection = stateMap.get(elem1);
|
|
6649
|
+
|
|
6650
|
+
switch (lastDirection) {
|
|
6651
|
+
case 'top':
|
|
6652
|
+
if (areElsCollTop(rect1, rect2)) stateMap.delete(elem1); // exited from top
|
|
6653
|
+
break;
|
|
6654
|
+
case 'bottom':
|
|
6655
|
+
if (areElsCollBottom(rect1, rect2)) stateMap.delete(elem1); // exited from bottom
|
|
6656
|
+
break;
|
|
6657
|
+
case 'left':
|
|
6658
|
+
if (areElsCollLeft(rect1, rect2)) stateMap.delete(elem1); // exited from left
|
|
6659
|
+
break;
|
|
6660
|
+
case 'right':
|
|
6661
|
+
if (areElsCollRight(rect1, rect2)) stateMap.delete(elem1); // exited from right
|
|
6662
|
+
break;
|
|
6663
|
+
}
|
|
6664
|
+
|
|
6665
|
+
return stateMap.has(elem1); // still colliding (locked)
|
|
6666
|
+
}
|
|
6667
|
+
|
|
6668
|
+
return false;
|
|
6212
6669
|
}
|
|
6213
6670
|
|
|
6214
6671
|
/**
|
|
@@ -6637,6 +7094,38 @@ function installWindowHiddenScript({
|
|
|
6637
7094
|
return uninstall;
|
|
6638
7095
|
}
|
|
6639
7096
|
|
|
7097
|
+
/**
|
|
7098
|
+
* Checks if the given element is at least partially visible in the viewport.
|
|
7099
|
+
*
|
|
7100
|
+
* @param {HTMLElement} element - The DOM element to check.
|
|
7101
|
+
* @returns {boolean} True if the element is partially in the viewport, false otherwise.
|
|
7102
|
+
*/
|
|
7103
|
+
function isInViewport(element) {
|
|
7104
|
+
const elementTop = element.offsetTop;
|
|
7105
|
+
const elementBottom = elementTop + element.offsetHeight;
|
|
7106
|
+
|
|
7107
|
+
const viewportTop = window.scrollY;
|
|
7108
|
+
const viewportBottom = viewportTop + window.innerHeight;
|
|
7109
|
+
|
|
7110
|
+
return elementBottom > viewportTop && elementTop < viewportBottom;
|
|
7111
|
+
}
|
|
7112
|
+
|
|
7113
|
+
/**
|
|
7114
|
+
* Checks if the given element is fully visible in the viewport (top and bottom).
|
|
7115
|
+
*
|
|
7116
|
+
* @param {HTMLElement} element - The DOM element to check.
|
|
7117
|
+
* @returns {boolean} True if the element is fully visible in the viewport, false otherwise.
|
|
7118
|
+
*/
|
|
7119
|
+
function isScrolledIntoView(element) {
|
|
7120
|
+
const viewportTop = window.scrollY;
|
|
7121
|
+
const viewportBottom = viewportTop + window.innerHeight;
|
|
7122
|
+
|
|
7123
|
+
const elemTop = element.offsetTop;
|
|
7124
|
+
const elemBottom = elemTop + element.offsetHeight;
|
|
7125
|
+
|
|
7126
|
+
return elemBottom <= viewportBottom && elemTop >= viewportTop;
|
|
7127
|
+
}
|
|
7128
|
+
|
|
6640
7129
|
;// ./src/v1/libs/TinyDragDropDetector.mjs
|
|
6641
7130
|
/**
|
|
6642
7131
|
* @typedef {Object} DragAndDropOptions
|
|
@@ -8919,6 +9408,7 @@ class TinyNotifications {
|
|
|
8919
9408
|
|
|
8920
9409
|
|
|
8921
9410
|
|
|
9411
|
+
|
|
8922
9412
|
|
|
8923
9413
|
|
|
8924
9414
|
})();
|