tiny-essentials 1.11.0 → 1.12.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 (72) hide show
  1. package/README.md +12 -3
  2. package/dist/node_modules/firebase-functions/lib/common/trace.cjs +82 -0
  3. package/dist/node_modules/firebase-functions/lib/logger/common.cjs +57 -0
  4. package/dist/node_modules/firebase-functions/lib/logger/index.cjs +158 -0
  5. package/dist/v1/TinyBasicsEs.js +1653 -1
  6. package/dist/v1/TinyBasicsEs.min.js +1 -1
  7. package/dist/v1/TinyDragDropDetector.js +307 -0
  8. package/dist/v1/TinyDragDropDetector.min.js +1 -0
  9. package/dist/v1/TinyDragger.js +3563 -0
  10. package/dist/v1/TinyDragger.min.js +2 -0
  11. package/dist/v1/TinyDragger.min.js.LICENSE.txt +8 -0
  12. package/dist/v1/TinyEssentials.js +2783 -2
  13. package/dist/v1/TinyEssentials.min.js +1 -1
  14. package/dist/v1/TinyNotifyCenter.js +32 -0
  15. package/dist/v1/TinyNotifyCenter.min.js +1 -1
  16. package/dist/v1/TinyToastNotify.js +24 -0
  17. package/dist/v1/TinyToastNotify.min.js +1 -1
  18. package/dist/v1/TinyUploadClicker.js +5235 -0
  19. package/dist/v1/TinyUploadClicker.min.js +2 -0
  20. package/dist/v1/TinyUploadClicker.min.js.LICENSE.txt +8 -0
  21. package/dist/v1/basics/fileManager.cjs +524 -0
  22. package/dist/v1/basics/fileManager.d.mts +209 -0
  23. package/dist/v1/basics/fileManager.mjs +443 -0
  24. package/dist/v1/basics/fullScreen.cjs +134 -0
  25. package/dist/v1/basics/fullScreen.d.mts +8 -0
  26. package/dist/v1/basics/fullScreen.mjs +121 -0
  27. package/dist/v1/basics/html.cjs +262 -0
  28. package/dist/v1/basics/html.d.mts +63 -0
  29. package/dist/v1/basics/html.mjs +208 -0
  30. package/dist/v1/basics/index.cjs +40 -0
  31. package/dist/v1/basics/index.d.mts +38 -1
  32. package/dist/v1/basics/index.mjs +4 -1
  33. package/dist/v1/build/TinyDragDropDetector.cjs +7 -0
  34. package/dist/v1/build/TinyDragDropDetector.d.mts +3 -0
  35. package/dist/v1/build/TinyDragDropDetector.mjs +2 -0
  36. package/dist/v1/build/TinyDragger.cjs +7 -0
  37. package/dist/v1/build/TinyDragger.d.mts +3 -0
  38. package/dist/v1/build/TinyDragger.mjs +2 -0
  39. package/dist/v1/build/TinyUploadClicker.cjs +7 -0
  40. package/dist/v1/build/TinyUploadClicker.d.mts +3 -0
  41. package/dist/v1/build/TinyUploadClicker.mjs +2 -0
  42. package/dist/v1/css/TinyDraggerExample.css +21 -0
  43. package/dist/v1/css/TinyDraggerExample.min.css +1 -0
  44. package/dist/v1/index.cjs +44 -0
  45. package/dist/v1/index.d.mts +40 -1
  46. package/dist/v1/index.mjs +6 -1
  47. package/dist/v1/libs/TinyDragDropDetector.cjs +268 -0
  48. package/dist/v1/libs/TinyDragDropDetector.d.mts +123 -0
  49. package/dist/v1/libs/TinyDragDropDetector.mjs +228 -0
  50. package/dist/v1/libs/TinyDragger.cjs +801 -0
  51. package/dist/v1/libs/TinyDragger.d.mts +300 -0
  52. package/dist/v1/libs/TinyDragger.mjs +689 -0
  53. package/dist/v1/libs/TinyNotifyCenter.cjs +32 -0
  54. package/dist/v1/libs/TinyNotifyCenter.d.mts +9 -0
  55. package/dist/v1/libs/TinyNotifyCenter.mjs +28 -0
  56. package/dist/v1/libs/TinyToastNotify.cjs +24 -0
  57. package/dist/v1/libs/TinyToastNotify.d.mts +8 -0
  58. package/dist/v1/libs/TinyToastNotify.mjs +20 -0
  59. package/dist/v1/libs/TinyUploadClicker.cjs +223 -0
  60. package/dist/v1/libs/TinyUploadClicker.d.mts +80 -0
  61. package/dist/v1/libs/TinyUploadClicker.mjs +182 -0
  62. package/docs/v1/README.md +8 -2
  63. package/docs/v1/basics/fileManager.md +222 -0
  64. package/docs/v1/basics/fullScreen.md +183 -0
  65. package/docs/v1/basics/html.md +243 -0
  66. package/docs/v1/libs/TinyDragDropDetector.md +143 -0
  67. package/docs/v1/libs/TinyDragger.md +415 -0
  68. package/docs/v1/libs/TinyLevelUp.md +1 -1
  69. package/docs/v1/libs/TinyNotifyCenter.md +20 -0
  70. package/docs/v1/libs/TinyToastNotify.md +19 -0
  71. package/docs/v1/libs/TinyUploadClicker.md +108 -0
  72. package/package.json +12 -2
@@ -1,6 +1,13 @@
1
1
  /******/ (() => { // webpackBootstrap
2
2
  /******/ var __webpack_modules__ = ({
3
3
 
4
+ /***/ 41:
5
+ /***/ (() => {
6
+
7
+ /* (ignored) */
8
+
9
+ /***/ }),
10
+
4
11
  /***/ 251:
5
12
  /***/ ((__unused_webpack_module, exports) => {
6
13
 
@@ -2075,6 +2082,735 @@ function fromByteArray (uint8) {
2075
2082
  }
2076
2083
 
2077
2084
 
2085
+ /***/ }),
2086
+
2087
+ /***/ 606:
2088
+ /***/ ((module) => {
2089
+
2090
+ // shim for using process in browser
2091
+ var process = module.exports = {};
2092
+
2093
+ // cached from whatever global is present so that test runners that stub it
2094
+ // don't break things. But we need to wrap it in a try catch in case it is
2095
+ // wrapped in strict mode code which doesn't define any globals. It's inside a
2096
+ // function because try/catches deoptimize in certain engines.
2097
+
2098
+ var cachedSetTimeout;
2099
+ var cachedClearTimeout;
2100
+
2101
+ function defaultSetTimout() {
2102
+ throw new Error('setTimeout has not been defined');
2103
+ }
2104
+ function defaultClearTimeout () {
2105
+ throw new Error('clearTimeout has not been defined');
2106
+ }
2107
+ (function () {
2108
+ try {
2109
+ if (typeof setTimeout === 'function') {
2110
+ cachedSetTimeout = setTimeout;
2111
+ } else {
2112
+ cachedSetTimeout = defaultSetTimout;
2113
+ }
2114
+ } catch (e) {
2115
+ cachedSetTimeout = defaultSetTimout;
2116
+ }
2117
+ try {
2118
+ if (typeof clearTimeout === 'function') {
2119
+ cachedClearTimeout = clearTimeout;
2120
+ } else {
2121
+ cachedClearTimeout = defaultClearTimeout;
2122
+ }
2123
+ } catch (e) {
2124
+ cachedClearTimeout = defaultClearTimeout;
2125
+ }
2126
+ } ())
2127
+ function runTimeout(fun) {
2128
+ if (cachedSetTimeout === setTimeout) {
2129
+ //normal enviroments in sane situations
2130
+ return setTimeout(fun, 0);
2131
+ }
2132
+ // if setTimeout wasn't available but was latter defined
2133
+ if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
2134
+ cachedSetTimeout = setTimeout;
2135
+ return setTimeout(fun, 0);
2136
+ }
2137
+ try {
2138
+ // when when somebody has screwed with setTimeout but no I.E. maddness
2139
+ return cachedSetTimeout(fun, 0);
2140
+ } catch(e){
2141
+ try {
2142
+ // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
2143
+ return cachedSetTimeout.call(null, fun, 0);
2144
+ } catch(e){
2145
+ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
2146
+ return cachedSetTimeout.call(this, fun, 0);
2147
+ }
2148
+ }
2149
+
2150
+
2151
+ }
2152
+ function runClearTimeout(marker) {
2153
+ if (cachedClearTimeout === clearTimeout) {
2154
+ //normal enviroments in sane situations
2155
+ return clearTimeout(marker);
2156
+ }
2157
+ // if clearTimeout wasn't available but was latter defined
2158
+ if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
2159
+ cachedClearTimeout = clearTimeout;
2160
+ return clearTimeout(marker);
2161
+ }
2162
+ try {
2163
+ // when when somebody has screwed with setTimeout but no I.E. maddness
2164
+ return cachedClearTimeout(marker);
2165
+ } catch (e){
2166
+ try {
2167
+ // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
2168
+ return cachedClearTimeout.call(null, marker);
2169
+ } catch (e){
2170
+ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
2171
+ // Some versions of I.E. have different rules for clearTimeout vs setTimeout
2172
+ return cachedClearTimeout.call(this, marker);
2173
+ }
2174
+ }
2175
+
2176
+
2177
+
2178
+ }
2179
+ var queue = [];
2180
+ var draining = false;
2181
+ var currentQueue;
2182
+ var queueIndex = -1;
2183
+
2184
+ function cleanUpNextTick() {
2185
+ if (!draining || !currentQueue) {
2186
+ return;
2187
+ }
2188
+ draining = false;
2189
+ if (currentQueue.length) {
2190
+ queue = currentQueue.concat(queue);
2191
+ } else {
2192
+ queueIndex = -1;
2193
+ }
2194
+ if (queue.length) {
2195
+ drainQueue();
2196
+ }
2197
+ }
2198
+
2199
+ function drainQueue() {
2200
+ if (draining) {
2201
+ return;
2202
+ }
2203
+ var timeout = runTimeout(cleanUpNextTick);
2204
+ draining = true;
2205
+
2206
+ var len = queue.length;
2207
+ while(len) {
2208
+ currentQueue = queue;
2209
+ queue = [];
2210
+ while (++queueIndex < len) {
2211
+ if (currentQueue) {
2212
+ currentQueue[queueIndex].run();
2213
+ }
2214
+ }
2215
+ queueIndex = -1;
2216
+ len = queue.length;
2217
+ }
2218
+ currentQueue = null;
2219
+ draining = false;
2220
+ runClearTimeout(timeout);
2221
+ }
2222
+
2223
+ process.nextTick = function (fun) {
2224
+ var args = new Array(arguments.length - 1);
2225
+ if (arguments.length > 1) {
2226
+ for (var i = 1; i < arguments.length; i++) {
2227
+ args[i - 1] = arguments[i];
2228
+ }
2229
+ }
2230
+ queue.push(new Item(fun, args));
2231
+ if (queue.length === 1 && !draining) {
2232
+ runTimeout(drainQueue);
2233
+ }
2234
+ };
2235
+
2236
+ // v8 likes predictible objects
2237
+ function Item(fun, array) {
2238
+ this.fun = fun;
2239
+ this.array = array;
2240
+ }
2241
+ Item.prototype.run = function () {
2242
+ this.fun.apply(null, this.array);
2243
+ };
2244
+ process.title = 'browser';
2245
+ process.browser = true;
2246
+ process.env = {};
2247
+ process.argv = [];
2248
+ process.version = ''; // empty string to avoid regexp issues
2249
+ process.versions = {};
2250
+
2251
+ function noop() {}
2252
+
2253
+ process.on = noop;
2254
+ process.addListener = noop;
2255
+ process.once = noop;
2256
+ process.off = noop;
2257
+ process.removeListener = noop;
2258
+ process.removeAllListeners = noop;
2259
+ process.emit = noop;
2260
+ process.prependListener = noop;
2261
+ process.prependOnceListener = noop;
2262
+
2263
+ process.listeners = function (name) { return [] }
2264
+
2265
+ process.binding = function (name) {
2266
+ throw new Error('process.binding is not supported');
2267
+ };
2268
+
2269
+ process.cwd = function () { return '/' };
2270
+ process.chdir = function (dir) {
2271
+ throw new Error('process.chdir is not supported');
2272
+ };
2273
+ process.umask = function() { return 0; };
2274
+
2275
+
2276
+ /***/ }),
2277
+
2278
+ /***/ 975:
2279
+ /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2280
+
2281
+ "use strict";
2282
+ /* provided dependency */ var process = __webpack_require__(606);
2283
+ // 'path' module extracted from Node.js v8.11.1 (only the posix part)
2284
+ // transplited with Babel
2285
+
2286
+ // Copyright Joyent, Inc. and other Node contributors.
2287
+ //
2288
+ // Permission is hereby granted, free of charge, to any person obtaining a
2289
+ // copy of this software and associated documentation files (the
2290
+ // "Software"), to deal in the Software without restriction, including
2291
+ // without limitation the rights to use, copy, modify, merge, publish,
2292
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
2293
+ // persons to whom the Software is furnished to do so, subject to the
2294
+ // following conditions:
2295
+ //
2296
+ // The above copyright notice and this permission notice shall be included
2297
+ // in all copies or substantial portions of the Software.
2298
+ //
2299
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
2300
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2301
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
2302
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
2303
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
2304
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2305
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
2306
+
2307
+
2308
+
2309
+ function assertPath(path) {
2310
+ if (typeof path !== 'string') {
2311
+ throw new TypeError('Path must be a string. Received ' + JSON.stringify(path));
2312
+ }
2313
+ }
2314
+
2315
+ // Resolves . and .. elements in a path with directory names
2316
+ function normalizeStringPosix(path, allowAboveRoot) {
2317
+ var res = '';
2318
+ var lastSegmentLength = 0;
2319
+ var lastSlash = -1;
2320
+ var dots = 0;
2321
+ var code;
2322
+ for (var i = 0; i <= path.length; ++i) {
2323
+ if (i < path.length)
2324
+ code = path.charCodeAt(i);
2325
+ else if (code === 47 /*/*/)
2326
+ break;
2327
+ else
2328
+ code = 47 /*/*/;
2329
+ if (code === 47 /*/*/) {
2330
+ if (lastSlash === i - 1 || dots === 1) {
2331
+ // NOOP
2332
+ } else if (lastSlash !== i - 1 && dots === 2) {
2333
+ if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 /*.*/ || res.charCodeAt(res.length - 2) !== 46 /*.*/) {
2334
+ if (res.length > 2) {
2335
+ var lastSlashIndex = res.lastIndexOf('/');
2336
+ if (lastSlashIndex !== res.length - 1) {
2337
+ if (lastSlashIndex === -1) {
2338
+ res = '';
2339
+ lastSegmentLength = 0;
2340
+ } else {
2341
+ res = res.slice(0, lastSlashIndex);
2342
+ lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
2343
+ }
2344
+ lastSlash = i;
2345
+ dots = 0;
2346
+ continue;
2347
+ }
2348
+ } else if (res.length === 2 || res.length === 1) {
2349
+ res = '';
2350
+ lastSegmentLength = 0;
2351
+ lastSlash = i;
2352
+ dots = 0;
2353
+ continue;
2354
+ }
2355
+ }
2356
+ if (allowAboveRoot) {
2357
+ if (res.length > 0)
2358
+ res += '/..';
2359
+ else
2360
+ res = '..';
2361
+ lastSegmentLength = 2;
2362
+ }
2363
+ } else {
2364
+ if (res.length > 0)
2365
+ res += '/' + path.slice(lastSlash + 1, i);
2366
+ else
2367
+ res = path.slice(lastSlash + 1, i);
2368
+ lastSegmentLength = i - lastSlash - 1;
2369
+ }
2370
+ lastSlash = i;
2371
+ dots = 0;
2372
+ } else if (code === 46 /*.*/ && dots !== -1) {
2373
+ ++dots;
2374
+ } else {
2375
+ dots = -1;
2376
+ }
2377
+ }
2378
+ return res;
2379
+ }
2380
+
2381
+ function _format(sep, pathObject) {
2382
+ var dir = pathObject.dir || pathObject.root;
2383
+ var base = pathObject.base || (pathObject.name || '') + (pathObject.ext || '');
2384
+ if (!dir) {
2385
+ return base;
2386
+ }
2387
+ if (dir === pathObject.root) {
2388
+ return dir + base;
2389
+ }
2390
+ return dir + sep + base;
2391
+ }
2392
+
2393
+ var posix = {
2394
+ // path.resolve([from ...], to)
2395
+ resolve: function resolve() {
2396
+ var resolvedPath = '';
2397
+ var resolvedAbsolute = false;
2398
+ var cwd;
2399
+
2400
+ for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
2401
+ var path;
2402
+ if (i >= 0)
2403
+ path = arguments[i];
2404
+ else {
2405
+ if (cwd === undefined)
2406
+ cwd = process.cwd();
2407
+ path = cwd;
2408
+ }
2409
+
2410
+ assertPath(path);
2411
+
2412
+ // Skip empty entries
2413
+ if (path.length === 0) {
2414
+ continue;
2415
+ }
2416
+
2417
+ resolvedPath = path + '/' + resolvedPath;
2418
+ resolvedAbsolute = path.charCodeAt(0) === 47 /*/*/;
2419
+ }
2420
+
2421
+ // At this point the path should be resolved to a full absolute path, but
2422
+ // handle relative paths to be safe (might happen when process.cwd() fails)
2423
+
2424
+ // Normalize the path
2425
+ resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);
2426
+
2427
+ if (resolvedAbsolute) {
2428
+ if (resolvedPath.length > 0)
2429
+ return '/' + resolvedPath;
2430
+ else
2431
+ return '/';
2432
+ } else if (resolvedPath.length > 0) {
2433
+ return resolvedPath;
2434
+ } else {
2435
+ return '.';
2436
+ }
2437
+ },
2438
+
2439
+ normalize: function normalize(path) {
2440
+ assertPath(path);
2441
+
2442
+ if (path.length === 0) return '.';
2443
+
2444
+ var isAbsolute = path.charCodeAt(0) === 47 /*/*/;
2445
+ var trailingSeparator = path.charCodeAt(path.length - 1) === 47 /*/*/;
2446
+
2447
+ // Normalize the path
2448
+ path = normalizeStringPosix(path, !isAbsolute);
2449
+
2450
+ if (path.length === 0 && !isAbsolute) path = '.';
2451
+ if (path.length > 0 && trailingSeparator) path += '/';
2452
+
2453
+ if (isAbsolute) return '/' + path;
2454
+ return path;
2455
+ },
2456
+
2457
+ isAbsolute: function isAbsolute(path) {
2458
+ assertPath(path);
2459
+ return path.length > 0 && path.charCodeAt(0) === 47 /*/*/;
2460
+ },
2461
+
2462
+ join: function join() {
2463
+ if (arguments.length === 0)
2464
+ return '.';
2465
+ var joined;
2466
+ for (var i = 0; i < arguments.length; ++i) {
2467
+ var arg = arguments[i];
2468
+ assertPath(arg);
2469
+ if (arg.length > 0) {
2470
+ if (joined === undefined)
2471
+ joined = arg;
2472
+ else
2473
+ joined += '/' + arg;
2474
+ }
2475
+ }
2476
+ if (joined === undefined)
2477
+ return '.';
2478
+ return posix.normalize(joined);
2479
+ },
2480
+
2481
+ relative: function relative(from, to) {
2482
+ assertPath(from);
2483
+ assertPath(to);
2484
+
2485
+ if (from === to) return '';
2486
+
2487
+ from = posix.resolve(from);
2488
+ to = posix.resolve(to);
2489
+
2490
+ if (from === to) return '';
2491
+
2492
+ // Trim any leading backslashes
2493
+ var fromStart = 1;
2494
+ for (; fromStart < from.length; ++fromStart) {
2495
+ if (from.charCodeAt(fromStart) !== 47 /*/*/)
2496
+ break;
2497
+ }
2498
+ var fromEnd = from.length;
2499
+ var fromLen = fromEnd - fromStart;
2500
+
2501
+ // Trim any leading backslashes
2502
+ var toStart = 1;
2503
+ for (; toStart < to.length; ++toStart) {
2504
+ if (to.charCodeAt(toStart) !== 47 /*/*/)
2505
+ break;
2506
+ }
2507
+ var toEnd = to.length;
2508
+ var toLen = toEnd - toStart;
2509
+
2510
+ // Compare paths to find the longest common path from root
2511
+ var length = fromLen < toLen ? fromLen : toLen;
2512
+ var lastCommonSep = -1;
2513
+ var i = 0;
2514
+ for (; i <= length; ++i) {
2515
+ if (i === length) {
2516
+ if (toLen > length) {
2517
+ if (to.charCodeAt(toStart + i) === 47 /*/*/) {
2518
+ // We get here if `from` is the exact base path for `to`.
2519
+ // For example: from='/foo/bar'; to='/foo/bar/baz'
2520
+ return to.slice(toStart + i + 1);
2521
+ } else if (i === 0) {
2522
+ // We get here if `from` is the root
2523
+ // For example: from='/'; to='/foo'
2524
+ return to.slice(toStart + i);
2525
+ }
2526
+ } else if (fromLen > length) {
2527
+ if (from.charCodeAt(fromStart + i) === 47 /*/*/) {
2528
+ // We get here if `to` is the exact base path for `from`.
2529
+ // For example: from='/foo/bar/baz'; to='/foo/bar'
2530
+ lastCommonSep = i;
2531
+ } else if (i === 0) {
2532
+ // We get here if `to` is the root.
2533
+ // For example: from='/foo'; to='/'
2534
+ lastCommonSep = 0;
2535
+ }
2536
+ }
2537
+ break;
2538
+ }
2539
+ var fromCode = from.charCodeAt(fromStart + i);
2540
+ var toCode = to.charCodeAt(toStart + i);
2541
+ if (fromCode !== toCode)
2542
+ break;
2543
+ else if (fromCode === 47 /*/*/)
2544
+ lastCommonSep = i;
2545
+ }
2546
+
2547
+ var out = '';
2548
+ // Generate the relative path based on the path difference between `to`
2549
+ // and `from`
2550
+ for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
2551
+ if (i === fromEnd || from.charCodeAt(i) === 47 /*/*/) {
2552
+ if (out.length === 0)
2553
+ out += '..';
2554
+ else
2555
+ out += '/..';
2556
+ }
2557
+ }
2558
+
2559
+ // Lastly, append the rest of the destination (`to`) path that comes after
2560
+ // the common path parts
2561
+ if (out.length > 0)
2562
+ return out + to.slice(toStart + lastCommonSep);
2563
+ else {
2564
+ toStart += lastCommonSep;
2565
+ if (to.charCodeAt(toStart) === 47 /*/*/)
2566
+ ++toStart;
2567
+ return to.slice(toStart);
2568
+ }
2569
+ },
2570
+
2571
+ _makeLong: function _makeLong(path) {
2572
+ return path;
2573
+ },
2574
+
2575
+ dirname: function dirname(path) {
2576
+ assertPath(path);
2577
+ if (path.length === 0) return '.';
2578
+ var code = path.charCodeAt(0);
2579
+ var hasRoot = code === 47 /*/*/;
2580
+ var end = -1;
2581
+ var matchedSlash = true;
2582
+ for (var i = path.length - 1; i >= 1; --i) {
2583
+ code = path.charCodeAt(i);
2584
+ if (code === 47 /*/*/) {
2585
+ if (!matchedSlash) {
2586
+ end = i;
2587
+ break;
2588
+ }
2589
+ } else {
2590
+ // We saw the first non-path separator
2591
+ matchedSlash = false;
2592
+ }
2593
+ }
2594
+
2595
+ if (end === -1) return hasRoot ? '/' : '.';
2596
+ if (hasRoot && end === 1) return '//';
2597
+ return path.slice(0, end);
2598
+ },
2599
+
2600
+ basename: function basename(path, ext) {
2601
+ if (ext !== undefined && typeof ext !== 'string') throw new TypeError('"ext" argument must be a string');
2602
+ assertPath(path);
2603
+
2604
+ var start = 0;
2605
+ var end = -1;
2606
+ var matchedSlash = true;
2607
+ var i;
2608
+
2609
+ if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
2610
+ if (ext.length === path.length && ext === path) return '';
2611
+ var extIdx = ext.length - 1;
2612
+ var firstNonSlashEnd = -1;
2613
+ for (i = path.length - 1; i >= 0; --i) {
2614
+ var code = path.charCodeAt(i);
2615
+ if (code === 47 /*/*/) {
2616
+ // If we reached a path separator that was not part of a set of path
2617
+ // separators at the end of the string, stop now
2618
+ if (!matchedSlash) {
2619
+ start = i + 1;
2620
+ break;
2621
+ }
2622
+ } else {
2623
+ if (firstNonSlashEnd === -1) {
2624
+ // We saw the first non-path separator, remember this index in case
2625
+ // we need it if the extension ends up not matching
2626
+ matchedSlash = false;
2627
+ firstNonSlashEnd = i + 1;
2628
+ }
2629
+ if (extIdx >= 0) {
2630
+ // Try to match the explicit extension
2631
+ if (code === ext.charCodeAt(extIdx)) {
2632
+ if (--extIdx === -1) {
2633
+ // We matched the extension, so mark this as the end of our path
2634
+ // component
2635
+ end = i;
2636
+ }
2637
+ } else {
2638
+ // Extension does not match, so our result is the entire path
2639
+ // component
2640
+ extIdx = -1;
2641
+ end = firstNonSlashEnd;
2642
+ }
2643
+ }
2644
+ }
2645
+ }
2646
+
2647
+ if (start === end) end = firstNonSlashEnd;else if (end === -1) end = path.length;
2648
+ return path.slice(start, end);
2649
+ } else {
2650
+ for (i = path.length - 1; i >= 0; --i) {
2651
+ if (path.charCodeAt(i) === 47 /*/*/) {
2652
+ // If we reached a path separator that was not part of a set of path
2653
+ // separators at the end of the string, stop now
2654
+ if (!matchedSlash) {
2655
+ start = i + 1;
2656
+ break;
2657
+ }
2658
+ } else if (end === -1) {
2659
+ // We saw the first non-path separator, mark this as the end of our
2660
+ // path component
2661
+ matchedSlash = false;
2662
+ end = i + 1;
2663
+ }
2664
+ }
2665
+
2666
+ if (end === -1) return '';
2667
+ return path.slice(start, end);
2668
+ }
2669
+ },
2670
+
2671
+ extname: function extname(path) {
2672
+ assertPath(path);
2673
+ var startDot = -1;
2674
+ var startPart = 0;
2675
+ var end = -1;
2676
+ var matchedSlash = true;
2677
+ // Track the state of characters (if any) we see before our first dot and
2678
+ // after any path separator we find
2679
+ var preDotState = 0;
2680
+ for (var i = path.length - 1; i >= 0; --i) {
2681
+ var code = path.charCodeAt(i);
2682
+ if (code === 47 /*/*/) {
2683
+ // If we reached a path separator that was not part of a set of path
2684
+ // separators at the end of the string, stop now
2685
+ if (!matchedSlash) {
2686
+ startPart = i + 1;
2687
+ break;
2688
+ }
2689
+ continue;
2690
+ }
2691
+ if (end === -1) {
2692
+ // We saw the first non-path separator, mark this as the end of our
2693
+ // extension
2694
+ matchedSlash = false;
2695
+ end = i + 1;
2696
+ }
2697
+ if (code === 46 /*.*/) {
2698
+ // If this is our first dot, mark it as the start of our extension
2699
+ if (startDot === -1)
2700
+ startDot = i;
2701
+ else if (preDotState !== 1)
2702
+ preDotState = 1;
2703
+ } else if (startDot !== -1) {
2704
+ // We saw a non-dot and non-path separator before our dot, so we should
2705
+ // have a good chance at having a non-empty extension
2706
+ preDotState = -1;
2707
+ }
2708
+ }
2709
+
2710
+ if (startDot === -1 || end === -1 ||
2711
+ // We saw a non-dot character immediately before the dot
2712
+ preDotState === 0 ||
2713
+ // The (right-most) trimmed path component is exactly '..'
2714
+ preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
2715
+ return '';
2716
+ }
2717
+ return path.slice(startDot, end);
2718
+ },
2719
+
2720
+ format: function format(pathObject) {
2721
+ if (pathObject === null || typeof pathObject !== 'object') {
2722
+ throw new TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
2723
+ }
2724
+ return _format('/', pathObject);
2725
+ },
2726
+
2727
+ parse: function parse(path) {
2728
+ assertPath(path);
2729
+
2730
+ var ret = { root: '', dir: '', base: '', ext: '', name: '' };
2731
+ if (path.length === 0) return ret;
2732
+ var code = path.charCodeAt(0);
2733
+ var isAbsolute = code === 47 /*/*/;
2734
+ var start;
2735
+ if (isAbsolute) {
2736
+ ret.root = '/';
2737
+ start = 1;
2738
+ } else {
2739
+ start = 0;
2740
+ }
2741
+ var startDot = -1;
2742
+ var startPart = 0;
2743
+ var end = -1;
2744
+ var matchedSlash = true;
2745
+ var i = path.length - 1;
2746
+
2747
+ // Track the state of characters (if any) we see before our first dot and
2748
+ // after any path separator we find
2749
+ var preDotState = 0;
2750
+
2751
+ // Get non-dir info
2752
+ for (; i >= start; --i) {
2753
+ code = path.charCodeAt(i);
2754
+ if (code === 47 /*/*/) {
2755
+ // If we reached a path separator that was not part of a set of path
2756
+ // separators at the end of the string, stop now
2757
+ if (!matchedSlash) {
2758
+ startPart = i + 1;
2759
+ break;
2760
+ }
2761
+ continue;
2762
+ }
2763
+ if (end === -1) {
2764
+ // We saw the first non-path separator, mark this as the end of our
2765
+ // extension
2766
+ matchedSlash = false;
2767
+ end = i + 1;
2768
+ }
2769
+ if (code === 46 /*.*/) {
2770
+ // If this is our first dot, mark it as the start of our extension
2771
+ if (startDot === -1) startDot = i;else if (preDotState !== 1) preDotState = 1;
2772
+ } else if (startDot !== -1) {
2773
+ // We saw a non-dot and non-path separator before our dot, so we should
2774
+ // have a good chance at having a non-empty extension
2775
+ preDotState = -1;
2776
+ }
2777
+ }
2778
+
2779
+ if (startDot === -1 || end === -1 ||
2780
+ // We saw a non-dot character immediately before the dot
2781
+ preDotState === 0 ||
2782
+ // The (right-most) trimmed path component is exactly '..'
2783
+ preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
2784
+ if (end !== -1) {
2785
+ if (startPart === 0 && isAbsolute) ret.base = ret.name = path.slice(1, end);else ret.base = ret.name = path.slice(startPart, end);
2786
+ }
2787
+ } else {
2788
+ if (startPart === 0 && isAbsolute) {
2789
+ ret.name = path.slice(1, startDot);
2790
+ ret.base = path.slice(1, end);
2791
+ } else {
2792
+ ret.name = path.slice(startPart, startDot);
2793
+ ret.base = path.slice(startPart, end);
2794
+ }
2795
+ ret.ext = path.slice(startDot, end);
2796
+ }
2797
+
2798
+ if (startPart > 0) ret.dir = path.slice(0, startPart - 1);else if (isAbsolute) ret.dir = '/';
2799
+
2800
+ return ret;
2801
+ },
2802
+
2803
+ sep: '/',
2804
+ delimiter: ':',
2805
+ win32: null,
2806
+ posix: null
2807
+ };
2808
+
2809
+ posix.posix = posix;
2810
+
2811
+ module.exports = posix;
2812
+
2813
+
2078
2814
  /***/ })
2079
2815
 
2080
2816
  /******/ });
@@ -2143,32 +2879,71 @@ __webpack_require__.r(__webpack_exports__);
2143
2879
  // EXPORTS
2144
2880
  __webpack_require__.d(__webpack_exports__, {
2145
2881
  ColorSafeStringify: () => (/* reexport */ libs_ColorSafeStringify),
2882
+ TinyDragDropDetector: () => (/* reexport */ libs_TinyDragDropDetector),
2883
+ TinyDragger: () => (/* reexport */ libs_TinyDragger),
2146
2884
  TinyLevelUp: () => (/* reexport */ userLevel),
2147
2885
  TinyNotifyCenter: () => (/* reexport */ libs_TinyNotifyCenter),
2148
2886
  TinyPromiseQueue: () => (/* reexport */ libs_TinyPromiseQueue),
2149
2887
  TinyRateLimiter: () => (/* reexport */ libs_TinyRateLimiter),
2150
2888
  TinyToastNotify: () => (/* reexport */ libs_TinyToastNotify),
2151
2889
  addAiMarkerShortcut: () => (/* reexport */ addAiMarkerShortcut),
2890
+ areHtmlElsColliding: () => (/* reexport */ areHtmlElsColliding),
2152
2891
  arraySortPositions: () => (/* reexport */ arraySortPositions),
2153
2892
  asyncReplace: () => (/* reexport */ asyncReplace),
2893
+ backupFile: () => (/* reexport */ backupFile),
2154
2894
  checkObj: () => (/* reexport */ checkObj),
2895
+ clearDirectory: () => (/* reexport */ clearDirectory),
2155
2896
  cloneObjTypeOrder: () => (/* reexport */ cloneObjTypeOrder),
2156
2897
  countObj: () => (/* reexport */ countObj),
2898
+ dirExists: () => (/* reexport */ dirExists),
2899
+ dirSize: () => (/* reexport */ dirSize),
2900
+ documentIsFullScreen: () => (/* reexport */ documentIsFullScreen),
2901
+ ensureCopyFile: () => (/* reexport */ ensureCopyFile),
2902
+ ensureDirectory: () => (/* reexport */ ensureDirectory),
2903
+ exitFullScreen: () => (/* reexport */ exitFullScreen),
2157
2904
  extendObjType: () => (/* reexport */ extendObjType),
2905
+ fetchJson: () => (/* reexport */ fetchJson),
2906
+ fileExists: () => (/* reexport */ fileExists),
2907
+ fileSize: () => (/* reexport */ fileSize),
2158
2908
  formatBytes: () => (/* reexport */ formatBytes),
2159
2909
  formatCustomTimer: () => (/* reexport */ formatCustomTimer),
2160
2910
  formatDayTimer: () => (/* reexport */ formatDayTimer),
2161
2911
  formatTimer: () => (/* reexport */ formatTimer),
2162
2912
  getAge: () => (/* reexport */ getAge),
2913
+ getHtmlElBorders: () => (/* reexport */ getHtmlElBorders),
2914
+ getHtmlElBordersWidth: () => (/* reexport */ getHtmlElBordersWidth),
2915
+ getHtmlElMargin: () => (/* reexport */ getHtmlElMargin),
2916
+ getHtmlElPadding: () => (/* reexport */ getHtmlElPadding),
2917
+ getLatestBackupPath: () => (/* reexport */ getLatestBackupPath),
2163
2918
  getSimplePerc: () => (/* reexport */ getSimplePerc),
2164
2919
  getTimeDuration: () => (/* reexport */ getTimeDuration),
2920
+ isDirEmpty: () => (/* reexport */ isDirEmpty),
2921
+ isFullScreenMode: () => (/* reexport */ isFullScreenMode),
2165
2922
  isJsonObject: () => (/* reexport */ isJsonObject),
2923
+ isScreenFilled: () => (/* reexport */ isScreenFilled),
2924
+ listDirs: () => (/* reexport */ listDirs),
2925
+ listFiles: () => (/* reexport */ listFiles),
2166
2926
  objType: () => (/* reexport */ objType),
2927
+ offFullScreenChange: () => (/* reexport */ offFullScreenChange),
2928
+ onFullScreenChange: () => (/* reexport */ onFullScreenChange),
2929
+ readJsonBlob: () => (/* reexport */ readJsonBlob),
2930
+ readJsonFile: () => (/* reexport */ readJsonFile),
2931
+ renameFileAddPrefixSuffix: () => (/* reexport */ renameFileAddPrefixSuffix),
2932
+ renameFileBatch: () => (/* reexport */ renameFileBatch),
2933
+ renameFileNormalizeCase: () => (/* reexport */ renameFileNormalizeCase),
2934
+ renameFilePadNumbers: () => (/* reexport */ renameFilePadNumbers),
2935
+ renameFileRegex: () => (/* reexport */ renameFileRegex),
2167
2936
  reorderObjTypeOrder: () => (/* reexport */ reorderObjTypeOrder),
2937
+ requestFullScreen: () => (/* reexport */ requestFullScreen),
2938
+ restoreLatestBackup: () => (/* reexport */ restoreLatestBackup),
2168
2939
  ruleOfThree: () => (/* reexport */ ruleOfThree),
2940
+ saveJsonFile: () => (/* reexport */ saveJsonFile),
2169
2941
  shuffleArray: () => (/* reexport */ shuffleArray),
2170
2942
  toTitleCase: () => (/* reexport */ toTitleCase),
2171
- toTitleCaseLowerFirst: () => (/* reexport */ toTitleCaseLowerFirst)
2943
+ toTitleCaseLowerFirst: () => (/* reexport */ toTitleCaseLowerFirst),
2944
+ tryDeleteFile: () => (/* reexport */ tryDeleteFile),
2945
+ writeJsonFile: () => (/* reexport */ writeJsonFile),
2946
+ writeTextFile: () => (/* reexport */ writeTextFile)
2172
2947
  });
2173
2948
 
2174
2949
  ;// ./src/legacy/libs/replaceAsync.mjs
@@ -3090,6 +3865,132 @@ extendObjType([
3090
3865
  ],
3091
3866
  ]);
3092
3867
 
3868
+ ;// ./src/v1/basics/fullScreen.mjs
3869
+ /**
3870
+ * Checks if the document is currently in fullscreen mode.
3871
+ *
3872
+ * @returns {boolean}
3873
+ */
3874
+ const documentIsFullScreen = () =>
3875
+ !!(
3876
+ document.fullscreenElement ||
3877
+ // @ts-ignore
3878
+ document.webkitFullscreenElement ||
3879
+ // @ts-ignore
3880
+ document.mozFullScreenElement ||
3881
+ // @ts-ignore
3882
+ document.msFullscreenElement ||
3883
+ // @ts-ignore
3884
+ document.webkitIsFullScreen ||
3885
+ // @ts-ignore
3886
+ document.mozFullScreen
3887
+ );
3888
+
3889
+ /**
3890
+ * Checks if the window occupies the entire screen dimensions.
3891
+ *
3892
+ * @returns {boolean}
3893
+ */
3894
+ const isScreenFilled = () =>
3895
+ window.innerHeight === screen.height && window.innerWidth === screen.width;
3896
+
3897
+ /**
3898
+ * Checks if fullscreen mode is active either via document API or by matching screen dimensions.
3899
+ *
3900
+ * @returns {boolean}
3901
+ */
3902
+ const isFullScreenMode = () => documentIsFullScreen() || isScreenFilled();
3903
+
3904
+ /**
3905
+ * Requests fullscreen mode for the document.
3906
+ *
3907
+ * @param {FullscreenOptions} [ops]
3908
+ * @returns {Promise<void>}
3909
+ */
3910
+ const requestFullScreen = (ops) =>
3911
+ new Promise(async (resolve, reject) => {
3912
+ const docElm = document.documentElement;
3913
+ try {
3914
+ if (docElm.requestFullscreen) {
3915
+ await docElm.requestFullscreen(ops);
3916
+ // @ts-ignore
3917
+ } else if (docElm.mozRequestFullScreen) {
3918
+ // @ts-ignore
3919
+ docElm.mozRequestFullScreen(ops);
3920
+ // @ts-ignore
3921
+ } else if (docElm.webkitRequestFullScreen) {
3922
+ // @ts-ignore
3923
+ docElm.webkitRequestFullScreen(ops);
3924
+ // @ts-ignore
3925
+ } else if (docElm.msRequestFullscreen) {
3926
+ // @ts-ignore
3927
+ docElm.msRequestFullscreen(ops);
3928
+ }
3929
+ resolve();
3930
+ } catch (err) {
3931
+ reject(err);
3932
+ }
3933
+ });
3934
+
3935
+ /**
3936
+ * Exits fullscreen mode.
3937
+ *
3938
+ * @returns {Promise<void>}
3939
+ */
3940
+ const exitFullScreen = () =>
3941
+ new Promise((resolve, reject) => {
3942
+ if (document.exitFullscreen) {
3943
+ document.exitFullscreen().then(resolve).catch(reject);
3944
+ } else {
3945
+ try {
3946
+ // @ts-ignore
3947
+ if (document.mozCancelFullScreen) document.mozCancelFullScreen();
3948
+ // @ts-ignore
3949
+ else if (document.webkitCancelFullScreen) document.webkitCancelFullScreen();
3950
+ // @ts-ignore
3951
+ else if (document.msExitFullscreen) document.msExitFullscreen();
3952
+ else throw new Error('Fullscreen API is not supported');
3953
+ resolve();
3954
+ } catch (err) {
3955
+ reject(err);
3956
+ }
3957
+ }
3958
+ });
3959
+
3960
+ /** @type {readonly string[]} */
3961
+ const fullScreenEvents = [
3962
+ 'fullscreenchange',
3963
+ 'webkitfullscreenchange',
3964
+ 'mozfullscreenchange',
3965
+ 'MSFullscreenChange',
3966
+ ];
3967
+
3968
+ /**
3969
+ * Attaches a listener to fullscreen change events.
3970
+ *
3971
+ * @param {EventListenerOrEventListenerObject} listener
3972
+ * @param {boolean|AddEventListenerOptions} [ops]
3973
+ * @returns {void}
3974
+ */
3975
+ const onFullScreenChange = (listener, ops) => {
3976
+ fullScreenEvents.forEach((event) => {
3977
+ document.addEventListener(event, listener, ops);
3978
+ });
3979
+ };
3980
+
3981
+ /**
3982
+ * Removes a listener from fullscreen change events.
3983
+ *
3984
+ * @param {EventListenerOrEventListenerObject} listener
3985
+ * @param {boolean|AddEventListenerOptions} [ops]
3986
+ * @returns {void}
3987
+ */
3988
+ const offFullScreenChange = (listener, ops) => {
3989
+ fullScreenEvents.forEach((event) => {
3990
+ document.removeEventListener(event, listener, ops);
3991
+ });
3992
+ };
3993
+
3093
3994
  ;// ./src/v1/basics/simpleMath.mjs
3094
3995
  /**
3095
3996
  * Executes a Rule of Three calculation.
@@ -4751,6 +5652,38 @@ class TinyNotifyCenter {
4751
5652
  get count() {
4752
5653
  return this.#count;
4753
5654
  }
5655
+
5656
+ /**
5657
+ * Destroys the notification center instance, removing all event listeners,
5658
+ * clearing notifications, and optionally removing DOM elements.
5659
+ *
5660
+ * Call this when the notification center is no longer needed to prevent memory leaks.
5661
+ *
5662
+ * @returns {void}
5663
+ */
5664
+ destroy() {
5665
+ // Remove event listeners
5666
+ this.#button?.removeEventListener('click', this.toggle);
5667
+ this.#center?.querySelector('.close')?.removeEventListener('click', this.close);
5668
+ this.#center?.querySelector('.clear-all')?.removeEventListener('click', this.clear);
5669
+ this.#overlay?.removeEventListener('click', this.close);
5670
+
5671
+ // Clear all notifications
5672
+ this.clear();
5673
+
5674
+ this.#center?.remove();
5675
+ this.#overlay?.remove();
5676
+ this.#button?.remove();
5677
+
5678
+ // Clean internal references
5679
+ // this.#center = null;
5680
+ // this.#list = null;
5681
+ // this.#badge = null;
5682
+ // this.#button = null;
5683
+ // this.#overlay = null;
5684
+ this.#count = 0;
5685
+ this.#modes = new WeakMap();
5686
+ }
4754
5687
  }
4755
5688
 
4756
5689
  /* harmony default export */ const libs_TinyNotifyCenter = (TinyNotifyCenter);
@@ -4802,6 +5735,8 @@ class TinyToastNotify {
4802
5735
  #baseDuration;
4803
5736
  #extraPerChar;
4804
5737
  #fadeOutDuration;
5738
+
5739
+ /** @type {HTMLElement|null} */
4805
5740
  #container;
4806
5741
 
4807
5742
  /**
@@ -5129,11 +6064,1857 @@ class TinyToastNotify {
5129
6064
 
5130
6065
  setTimeout(() => close(), totalTime);
5131
6066
  }
6067
+
6068
+ /**
6069
+ * Destroys the notification container and removes all active notifications.
6070
+ * This should be called when the notification system is no longer needed,
6071
+ * such as when unloading a page or switching views in a single-page app.
6072
+ *
6073
+ * @returns {void}
6074
+ */
6075
+ destroy() {
6076
+ if (!(this.#container instanceof HTMLElement)) return;
6077
+
6078
+ // Remove all child notifications
6079
+ this.#container.querySelectorAll('.notify').forEach((el) => el.remove());
6080
+
6081
+ // Remove the container itself from the DOM
6082
+ if (this.#container.parentNode) {
6083
+ this.#container.parentNode.removeChild(this.#container);
6084
+ }
6085
+
6086
+ // Optional: Clean internal references (safe practice)
6087
+ this.#container = null;
6088
+ }
5132
6089
  }
5133
6090
 
5134
6091
  /* harmony default export */ const libs_TinyToastNotify = (TinyToastNotify);
5135
6092
 
5136
- ;// ./src/v1/index.mjs
6093
+ ;// ./src/v1/basics/html.mjs
6094
+
6095
+
6096
+ /**
6097
+ * Checks if two DOM elements are colliding on the screen.
6098
+ *
6099
+ * @param {Element} elem1 - First DOM element.
6100
+ * @param {Element} elem2 - Second DOM element.
6101
+ * @returns {boolean} - Returns true if the elements are colliding.
6102
+ */
6103
+ function areHtmlElsColliding(elem1, elem2) {
6104
+ const rect1 = elem1.getBoundingClientRect();
6105
+ const rect2 = elem2.getBoundingClientRect();
6106
+
6107
+ return !(
6108
+ rect1.right < rect2.left ||
6109
+ rect1.left > rect2.right ||
6110
+ rect1.bottom < rect2.top ||
6111
+ rect1.top > rect2.bottom
6112
+ );
6113
+ }
6114
+
6115
+ /**
6116
+ * Reads and parses a JSON data using FileReader.
6117
+ * Throws an error if the content is not valid JSON.
6118
+ * @param {File} file
6119
+ * @returns {Promise<any>}
6120
+ */
6121
+ function readJsonBlob(file) {
6122
+ return new Promise((resolve, reject) => {
6123
+ const reader = new FileReader();
6124
+
6125
+ reader.onload = () => {
6126
+ try {
6127
+ // @ts-ignore
6128
+ const result = JSON.parse(reader.result);
6129
+ resolve(result);
6130
+ } catch (error) {
6131
+ // @ts-ignore
6132
+ reject(new Error(`Invalid JSON in file: ${file.name}\n${error.message}`));
6133
+ }
6134
+ };
6135
+
6136
+ reader.onerror = () => {
6137
+ reject(new Error(`Error reading file: ${file.name}`));
6138
+ };
6139
+
6140
+ reader.readAsText(file);
6141
+ });
6142
+ }
6143
+
6144
+ /**
6145
+ * Saves a JSON object as a downloadable file.
6146
+ * @param {string} filename
6147
+ * @param {any} data
6148
+ * @param {number} [spaces=2]
6149
+ */
6150
+ function saveJsonFile(filename, data, spaces = 2) {
6151
+ const json = JSON.stringify(data, null, spaces);
6152
+ const blob = new Blob([json], { type: 'application/json' });
6153
+ const url = URL.createObjectURL(blob);
6154
+
6155
+ const link = document.createElement('a');
6156
+ link.href = url;
6157
+ link.download = filename;
6158
+
6159
+ document.body.appendChild(link);
6160
+ link.click();
6161
+ document.body.removeChild(link);
6162
+
6163
+ URL.revokeObjectURL(url);
6164
+ }
6165
+
6166
+ /**
6167
+ * Loads and parses a JSON from a remote URL using Fetch API.
6168
+ *
6169
+ * @param {string} url - The full URL to fetch JSON from.
6170
+ * @param {Object} [options] - Optional settings.
6171
+ * @param {string} [options.method="GET"] - HTTP method to use (GET, POST, etc.).
6172
+ * @param {any} [options.body] - Request body (only for methods like POST, PUT).
6173
+ * @param {number} [options.timeout=0] - Timeout in milliseconds (ignored if signal is provided).
6174
+ * @param {number} [options.retries=0] - Number of retry attempts (ignored if signal is provided).
6175
+ * @param {Headers|Record<string, *>} [options.headers={}] - Additional headers.
6176
+ * @param {AbortSignal|null} [options.signal] - External AbortSignal; disables timeout and retries.
6177
+ * @returns {Promise<*>} Parsed JSON object.
6178
+ * @throws {Error} Throws if fetch fails, times out, or returns invalid JSON.
6179
+ */
6180
+ async function fetchJson(
6181
+ url,
6182
+ { method = 'GET', body, timeout = 0, retries = 0, headers = {}, signal = null } = {},
6183
+ ) {
6184
+ if (
6185
+ typeof url !== 'string' ||
6186
+ (!url.startsWith('../') &&
6187
+ !url.startsWith('./') &&
6188
+ !url.startsWith('/') &&
6189
+ !url.startsWith('https://') &&
6190
+ !url.startsWith('http://'))
6191
+ )
6192
+ throw new Error('Invalid URL: must be a valid http or https address.');
6193
+
6194
+ if (typeof method !== 'string' || !method.trim())
6195
+ throw new Error('Invalid method: must be a non-empty string.');
6196
+
6197
+ if (!signal) {
6198
+ if (
6199
+ typeof timeout !== 'number' ||
6200
+ !Number.isFinite(timeout) ||
6201
+ Number.isNaN(timeout) ||
6202
+ timeout < 0
6203
+ )
6204
+ throw new Error('Invalid timeout: must be a positive number.');
6205
+
6206
+ if (
6207
+ typeof retries !== 'number' ||
6208
+ !Number.isFinite(retries) ||
6209
+ Number.isNaN(retries) ||
6210
+ retries < 0
6211
+ )
6212
+ throw new Error('Invalid retries: must be a positive number.');
6213
+ }
6214
+
6215
+ const attempts = signal ? 1 : retries + 1;
6216
+ /** @type {Error|null} */
6217
+ let lastError = null;
6218
+
6219
+ for (let attempt = 0; attempt < attempts; attempt++) {
6220
+ const controller = signal ? null : new AbortController();
6221
+ const localSignal = signal || (controller?.signal ?? null);
6222
+ const timer =
6223
+ !signal && timeout && controller ? setTimeout(() => controller.abort(), timeout) : null;
6224
+
6225
+ try {
6226
+ const response = await fetch(url, {
6227
+ method: method.toUpperCase(),
6228
+ headers: {
6229
+ Accept: 'application/json',
6230
+ ...headers,
6231
+ },
6232
+ body: body !== undefined ? (isJsonObject(body) ? JSON.stringify(body) : body) : undefined,
6233
+ signal: localSignal,
6234
+ });
6235
+
6236
+ if (timer) clearTimeout(timer);
6237
+
6238
+ if (!response.ok) throw new Error(`HTTP error: ${response.status} ${response.statusText}`);
6239
+
6240
+ const contentType = response.headers.get('content-type') || '';
6241
+ if (!contentType.includes('application/json'))
6242
+ throw new Error(`Unexpected content-type: ${contentType}`);
6243
+
6244
+ const data = await response.json();
6245
+
6246
+ if (!isJsonObject(data)) throw new Error('Received invalid data instead of valid JSON.');
6247
+
6248
+ return data;
6249
+ } catch (err) {
6250
+ lastError = /** @type {Error} */ (err);
6251
+ if (signal) break; // if an external signal came, it does not retry
6252
+ if (attempt < retries)
6253
+ await new Promise((resolve) => setTimeout(resolve, 300 * (attempt + 1)));
6254
+ }
6255
+ }
6256
+
6257
+ throw new Error(
6258
+ `Failed to fetch JSON from "${url}"${lastError ? `: ${lastError.message}` : '.'}`,
6259
+ );
6260
+ }
6261
+
6262
+ /**
6263
+ * @typedef {Object} HtmlElBoxSides
6264
+ * @property {number} x - Total horizontal size (left + right)
6265
+ * @property {number} y - Total vertical size (top + bottom)
6266
+ * @property {number} left
6267
+ * @property {number} right
6268
+ * @property {number} top
6269
+ * @property {number} bottom
6270
+ */
6271
+
6272
+ /**
6273
+ * Returns the total border width and individual sides from `border{Side}Width` CSS properties.
6274
+ *
6275
+ * @param {Element} el - The target DOM element.
6276
+ * @returns {HtmlElBoxSides} - Total horizontal (x) and vertical (y) border widths, and each side individually.
6277
+ */
6278
+ const getHtmlElBordersWidth = (el) => {
6279
+ const styles = getComputedStyle(el);
6280
+ const left = parseFloat(styles.borderLeftWidth) || 0;
6281
+ const right = parseFloat(styles.borderRightWidth) || 0;
6282
+ const top = parseFloat(styles.borderTopWidth) || 0;
6283
+ const bottom = parseFloat(styles.borderBottomWidth) || 0;
6284
+ const x = left + right;
6285
+ const y = top + bottom;
6286
+
6287
+ return { x, y, left, right, top, bottom };
6288
+ };
6289
+
6290
+ /**
6291
+ * Returns the total border size and individual sides from `border{Side}` CSS properties.
6292
+ *
6293
+ * @param {Element} el - The target DOM element.
6294
+ * @returns {HtmlElBoxSides} - Total horizontal (x) and vertical (y) border sizes, and each side individually.
6295
+ */
6296
+ const getHtmlElBorders = (el) => {
6297
+ const styles = getComputedStyle(el);
6298
+ const left = parseFloat(styles.borderLeft) || 0;
6299
+ const right = parseFloat(styles.borderRight) || 0;
6300
+ const top = parseFloat(styles.borderTop) || 0;
6301
+ const bottom = parseFloat(styles.borderBottom) || 0;
6302
+ const x = left + right;
6303
+ const y = top + bottom;
6304
+
6305
+ return { x, y, left, right, top, bottom };
6306
+ };
6307
+
6308
+ /**
6309
+ * Returns the total margin and individual sides from `margin{Side}` CSS properties.
6310
+ *
6311
+ * @param {Element} el - The target DOM element.
6312
+ * @returns {HtmlElBoxSides} - Total horizontal (x) and vertical (y) margins, and each side individually.
6313
+ */
6314
+ const getHtmlElMargin = (el) => {
6315
+ const styles = getComputedStyle(el);
6316
+ const left = parseFloat(styles.marginLeft) || 0;
6317
+ const right = parseFloat(styles.marginRight) || 0;
6318
+ const top = parseFloat(styles.marginTop) || 0;
6319
+ const bottom = parseFloat(styles.marginBottom) || 0;
6320
+
6321
+ const x = left + right;
6322
+ const y = top + bottom;
6323
+
6324
+ return { x, y, left, right, top, bottom };
6325
+ };
6326
+
6327
+ /**
6328
+ * Returns the total padding and individual sides from `padding{Side}` CSS properties.
6329
+ *
6330
+ * @param {Element} el - The target DOM element.
6331
+ * @returns {HtmlElBoxSides} - Total horizontal (x) and vertical (y) paddings, and each side individually.
6332
+ */
6333
+ const getHtmlElPadding = (el) => {
6334
+ const styles = getComputedStyle(el);
6335
+ const left = parseFloat(styles.paddingLeft) || 0;
6336
+ const right = parseFloat(styles.paddingRight) || 0;
6337
+ const top = parseFloat(styles.paddingTop) || 0;
6338
+ const bottom = parseFloat(styles.paddingBottom) || 0;
6339
+
6340
+ const x = left + right;
6341
+ const y = top + bottom;
6342
+
6343
+ return { x, y, left, right, top, bottom };
6344
+ };
6345
+
6346
+ ;// ./src/v1/libs/TinyDragDropDetector.mjs
6347
+ /**
6348
+ * @typedef {Object} DragAndDropOptions
6349
+ * @property {HTMLElement} [target=document.body] - The DOM element where drag listeners will be attached. Defaults to `document.body` if `fullscreen` is true or no target is provided.
6350
+ * @property {boolean} [fullscreen=true] - If true, listeners are attached to the entire page (`document.body`). If false, the `target` must be specified.
6351
+ * @property {string} [hoverClass="dnd-hover"] - CSS class applied to the target element while files are being dragged over it.
6352
+ * @property {(files: FileList, event: DragEvent) => void} [onDrop] - Callback function executed when files are dropped onto the target.
6353
+ * @property {(event: DragEvent) => void} [onEnter] - Optional callback triggered when dragging enters the target area.
6354
+ * @property {(event: DragEvent) => void} [onLeave] - Optional callback triggered when dragging leaves the target area.
6355
+ */
6356
+
6357
+ /**
6358
+ * TinyDragDropDetector
6359
+ *
6360
+ * A lightweight utility to detect drag-and-drop file operations on a specific DOM element or the entire page.
6361
+ * It handles the drag lifecycle (enter, over, leave, drop) and provides hooks for developers to handle file uploads or UI changes.
6362
+ *
6363
+ * @class
6364
+ */
6365
+ class TinyDragDropDetector {
6366
+ /** @type {HTMLElement} */
6367
+ #target;
6368
+
6369
+ /** @type {boolean} */
6370
+ #fullscreen;
6371
+
6372
+ /** @type {string} */
6373
+ #hoverClass;
6374
+
6375
+ /** @type {(files: FileList, event: DragEvent) => void} */
6376
+ #onDropCallback;
6377
+
6378
+ /** @type {(event: DragEvent) => void} */
6379
+ #onEnterCallback;
6380
+
6381
+ /** @type {(event: DragEvent) => void} */
6382
+ #onLeaveCallback;
6383
+
6384
+ /** @type {boolean} */
6385
+ #isDragging;
6386
+
6387
+ /** @type {boolean} */
6388
+ #bound;
6389
+
6390
+ /**
6391
+ * Creates a new instance of TinyDragDropDetector to handle drag-and-drop file detection.
6392
+ *
6393
+ * @param {DragAndDropOptions} [options={}] - Configuration options for the detector.
6394
+ * @throws {TypeError} If `target` is not an HTMLElement.
6395
+ * @throws {TypeError} If `fullscreen` is not a boolean.
6396
+ * @throws {TypeError} If `hoverClass` is not a string.
6397
+ * @throws {TypeError} If `onDrop` is defined but not a function.
6398
+ * @throws {TypeError} If `onEnter` is defined but not a function.
6399
+ * @throws {TypeError} If `onLeave` is defined but not a function.
6400
+ */
6401
+ constructor(options = {}) {
6402
+ const {
6403
+ target,
6404
+ fullscreen = true,
6405
+ hoverClass = 'dnd-hover',
6406
+ onDrop,
6407
+ onEnter,
6408
+ onLeave,
6409
+ } = options;
6410
+
6411
+ // Validate fullscreen
6412
+ if (typeof fullscreen !== 'boolean')
6413
+ throw new TypeError('The "fullscreen" option must be a boolean.');
6414
+
6415
+ // Validate target
6416
+ const resolvedTarget = fullscreen ? document.body : target || document.body;
6417
+ if (!(resolvedTarget instanceof HTMLElement))
6418
+ throw new TypeError('The "target" option must be an instance of HTMLElement.');
6419
+
6420
+ // Validate hoverClass
6421
+ if (typeof hoverClass !== 'string')
6422
+ throw new TypeError('The "hoverClass" option must be a string.');
6423
+
6424
+ // Validate onDrop
6425
+ if (typeof onDrop !== 'function')
6426
+ throw new TypeError('The "onDrop" option must be a function.');
6427
+
6428
+ // Validate onEnter
6429
+ if (typeof onEnter !== 'function')
6430
+ throw new TypeError('The "onEnter" option must be a function.');
6431
+
6432
+ // Validate onLeave
6433
+ if (typeof onLeave !== 'function')
6434
+ throw new TypeError('The "onLeave" option must be a function.');
6435
+
6436
+ // Store properties
6437
+ this.#target = resolvedTarget;
6438
+ this.#fullscreen = fullscreen;
6439
+ this.#hoverClass = hoverClass;
6440
+
6441
+ this.#onDropCallback = onDrop || (() => {});
6442
+ this.#onEnterCallback = onEnter;
6443
+ this.#onLeaveCallback = onLeave;
6444
+
6445
+ this.#isDragging = false;
6446
+ this.#bound = false;
6447
+
6448
+ // Bind event handlers
6449
+ this._handleDragEnter = this._handleDragEnter.bind(this);
6450
+ this._handleDragOver = this._handleDragOver.bind(this);
6451
+ this._handleDragLeave = this._handleDragLeave.bind(this);
6452
+ this._handleDrop = this._handleDrop.bind(this);
6453
+
6454
+ this.#bindEvents();
6455
+ }
6456
+
6457
+ /**
6458
+ * Returns the current target DOM element where the listeners are attached.
6459
+ * @returns {HTMLElement}
6460
+ */
6461
+ getTarget() {
6462
+ return this.#target;
6463
+ }
6464
+
6465
+ /**
6466
+ * Returns the CSS class applied during drag hover.
6467
+ * @returns {string}
6468
+ */
6469
+ getHoverClass() {
6470
+ return this.#hoverClass;
6471
+ }
6472
+
6473
+ /**
6474
+ * Indicates whether the detector is operating in fullscreen mode.
6475
+ * @returns {boolean}
6476
+ */
6477
+ isFullScreen() {
6478
+ return this.#fullscreen;
6479
+ }
6480
+
6481
+ /**
6482
+ * Returns whether a drag operation is currently active over the target.
6483
+ * @returns {boolean}
6484
+ */
6485
+ isDragging() {
6486
+ return this.#isDragging;
6487
+ }
6488
+
6489
+ /**
6490
+ * Returns whether the event listeners are currently bound to the target.
6491
+ * @returns {boolean}
6492
+ */
6493
+ bound() {
6494
+ return this.#bound;
6495
+ }
6496
+
6497
+ /**
6498
+ * Binds the drag-and-drop event listeners to the target element.
6499
+ * Automatically called on instantiation.
6500
+ * @returns {void}
6501
+ */
6502
+ #bindEvents() {
6503
+ if (this.#bound) return;
6504
+ const target = this.getTarget();
6505
+ target.addEventListener('dragenter', this._handleDragEnter);
6506
+ target.addEventListener('dragover', this._handleDragOver);
6507
+ target.addEventListener('dragleave', this._handleDragLeave);
6508
+ target.addEventListener('drop', this._handleDrop);
6509
+ this.#bound = true;
6510
+ }
6511
+
6512
+ /**
6513
+ * Removes all previously attached drag-and-drop event listeners from the target.
6514
+ * @returns {void}
6515
+ */
6516
+ #unbindEvents() {
6517
+ if (!this.#bound) return;
6518
+ const target = this.getTarget();
6519
+ target.removeEventListener('dragenter', this._handleDragEnter);
6520
+ target.removeEventListener('dragover', this._handleDragOver);
6521
+ target.removeEventListener('dragleave', this._handleDragLeave);
6522
+ target.removeEventListener('drop', this._handleDrop);
6523
+ this.#bound = false;
6524
+ }
6525
+
6526
+ /**
6527
+ * Handles the `dragenter` event.
6528
+ * Adds the hover CSS class and triggers the `onEnter` callback if provided.
6529
+ * @private
6530
+ * @param {DragEvent} event - The dragenter event.
6531
+ * @returns {void}
6532
+ */
6533
+ _handleDragEnter(event) {
6534
+ event.preventDefault();
6535
+ if (!this.#isDragging) {
6536
+ const target = this.getTarget();
6537
+ this.#isDragging = true;
6538
+ target.classList.add(this.#hoverClass);
6539
+ this.#onEnterCallback(event);
6540
+ }
6541
+ }
6542
+
6543
+ /**
6544
+ * Handles the `dragover` event.
6545
+ * Prevents default to allow drop and sets the drop effect.
6546
+ * @private
6547
+ * @param {DragEvent} event - The dragover event.
6548
+ * @returns {void}
6549
+ */
6550
+ _handleDragOver(event) {
6551
+ event.preventDefault(); // Required to allow drop
6552
+ if (!event.dataTransfer) {
6553
+ console.warn('[TinyDragDropDetector] [handleDragOver] DragOver event missing dataTransfer.');
6554
+ return;
6555
+ }
6556
+ event.dataTransfer.dropEffect = 'copy';
6557
+ }
6558
+
6559
+ /**
6560
+ * Handles the `dragleave` event.
6561
+ * Removes the hover class and triggers the `onLeave` callback if provided.
6562
+ * @private
6563
+ * @param {DragEvent} event - The dragleave event.
6564
+ * @returns {void}
6565
+ */
6566
+ _handleDragLeave(event) {
6567
+ event.preventDefault();
6568
+ const target = this.getTarget();
6569
+ // Check if you've completely left the area
6570
+ // @ts-ignore
6571
+ if (event.relatedTarget === null || !target.contains(event.relatedTarget)) {
6572
+ this.#isDragging = false;
6573
+ target.classList.remove(this.#hoverClass);
6574
+ this.#onLeaveCallback(event);
6575
+ }
6576
+ }
6577
+
6578
+ /**
6579
+ * Handles the `drop` event.
6580
+ * Removes the hover class, resets dragging state, and triggers the `onDrop` callback.
6581
+ * @private
6582
+ * @param {DragEvent} event - The drop event.
6583
+ * @returns {void}
6584
+ */
6585
+ _handleDrop(event) {
6586
+ event.preventDefault();
6587
+ if (!event.dataTransfer) {
6588
+ console.warn('[TinyDragDropDetector] [handleDrop] DragOver event missing dataTransfer.');
6589
+ return;
6590
+ }
6591
+ const target = this.getTarget();
6592
+ this.#isDragging = false;
6593
+ target.classList.remove(this.#hoverClass);
6594
+ const files = event.dataTransfer.files;
6595
+ if (files.length > 0) {
6596
+ this.#onDropCallback(files, event);
6597
+ }
6598
+ }
6599
+
6600
+ /**
6601
+ * Destroys the detector instance, unbinding all event listeners and cleaning up.
6602
+ * Should be called when the detector is no longer needed to avoid memory leaks.
6603
+ * @returns {void}
6604
+ */
6605
+ destroy() {
6606
+ this.#unbindEvents();
6607
+ const target = this.getTarget();
6608
+ target.classList.remove(this.#hoverClass);
6609
+ }
6610
+ }
6611
+
6612
+ /* harmony default export */ const libs_TinyDragDropDetector = (TinyDragDropDetector);
6613
+
6614
+ // EXTERNAL MODULE: fs (ignored)
6615
+ var fs_ignored_ = __webpack_require__(41);
6616
+ // EXTERNAL MODULE: ./node_modules/path-browserify/index.js
6617
+ var path_browserify = __webpack_require__(975);
6618
+ ;// ./src/v1/basics/fileManager.mjs
6619
+
6620
+
6621
+
6622
+
6623
+ /*========================*
6624
+ * JSON Operations
6625
+ *========================*/
6626
+
6627
+ /**
6628
+ * Reads and parses a JSON file.
6629
+ * Throws an error if the file content is not valid JSON.
6630
+ * @param {string} filePath
6631
+ * @returns {any}
6632
+ */
6633
+ function readJsonFile(filePath) {
6634
+ if (!fs_ignored_.existsSync(filePath)) throw new Error(`File not found: ${filePath}`);
6635
+ const content = fs_ignored_.readFileSync(filePath, 'utf-8');
6636
+ return JSON.parse(content);
6637
+ }
6638
+
6639
+ /**
6640
+ * Saves an object as JSON to a file.
6641
+ * Automatically creates the directory if it does not exist.
6642
+ * @param {string} filePath
6643
+ * @param {any} data
6644
+ * @param {number} [spaces=2]
6645
+ */
6646
+ function writeJsonFile(filePath, data, spaces = 2) {
6647
+ const json = JSON.stringify(data, null, spaces);
6648
+ fs_ignored_.writeFileSync(filePath, json, 'utf-8');
6649
+ }
6650
+
6651
+ /**
6652
+ * Reads and parses a JSON file.
6653
+ * Throws an error if the file content is not valid JSON.
6654
+ * @param {string} filePath
6655
+ * @returns {Promise<any>}
6656
+ */
6657
+ async function readJsonFileAsync(filePath) {
6658
+ if (!fs.existsSync(filePath)) throw new Error(`File not found: ${filePath}`);
6659
+ const content = await fs.promises.readFile(filePath, 'utf-8');
6660
+ return JSON.parse(content);
6661
+ }
6662
+
6663
+ /**
6664
+ * Saves an object as JSON to a file.
6665
+ * Automatically creates the directory if it does not exist.
6666
+ * @param {string} filePath
6667
+ * @param {any} data
6668
+ * @param {number} [spaces=2]
6669
+ * @returns {Promise<void>}
6670
+ */
6671
+ function writeJsonFileAsync(filePath, data, spaces = 2) {
6672
+ const json = JSON.stringify(data, null, spaces);
6673
+ return fs.promises.writeFile(filePath, json, 'utf-8');
6674
+ }
6675
+
6676
+ /*========================*
6677
+ * Directory Management
6678
+ *========================*/
6679
+
6680
+ /**
6681
+ * Ensures that the directory exists, creating it recursively if needed.
6682
+ * @param {string} dirPath
6683
+ */
6684
+ function ensureDirectory(dirPath) {
6685
+ if (!fs_ignored_.existsSync(dirPath)) {
6686
+ fs_ignored_.mkdirSync(dirPath, { recursive: true });
6687
+ }
6688
+ }
6689
+
6690
+ /**
6691
+ * Clears all contents inside a directory but keeps the directory.
6692
+ * @param {string} dirPath
6693
+ */
6694
+ function clearDirectory(dirPath) {
6695
+ if (!fs_ignored_.existsSync(dirPath)) return;
6696
+ const files = fs_ignored_.readdirSync(dirPath);
6697
+ for (const file of files) {
6698
+ const fullPath = path_browserify.join(dirPath, file);
6699
+ const stat = fs_ignored_.lstatSync(fullPath);
6700
+ if (stat.isDirectory()) {
6701
+ fs_ignored_.rmSync(fullPath, { recursive: true, force: true });
6702
+ } else {
6703
+ fs_ignored_.unlinkSync(fullPath);
6704
+ }
6705
+ }
6706
+ }
6707
+
6708
+ /*========================*
6709
+ * File Checks
6710
+ *========================*/
6711
+
6712
+ /**
6713
+ * Checks whether a file exists.
6714
+ * @param {string} filePath
6715
+ * @returns {boolean}
6716
+ */
6717
+ function fileExists(filePath) {
6718
+ return fs_ignored_.existsSync(filePath) && fs_ignored_.lstatSync(filePath).isFile();
6719
+ }
6720
+
6721
+ /**
6722
+ * Checks whether a directory exists.
6723
+ * @param {string} dirPath
6724
+ * @returns {boolean}
6725
+ */
6726
+ function dirExists(dirPath) {
6727
+ return fs_ignored_.existsSync(dirPath) && fs_ignored_.lstatSync(dirPath).isDirectory();
6728
+ }
6729
+
6730
+ /**
6731
+ * Checks whether a directory is empty.
6732
+ * @param {string} dirPath
6733
+ * @returns {boolean}
6734
+ */
6735
+ function isDirEmpty(dirPath) {
6736
+ return fs_ignored_.existsSync(dirPath) && fs_ignored_.readdirSync(dirPath).length === 0;
6737
+ }
6738
+
6739
+ /*========================*
6740
+ * File Operations
6741
+ *========================*/
6742
+
6743
+ /**
6744
+ * Copies a file to a destination.
6745
+ * @param {string} src
6746
+ * @param {string} dest
6747
+ * @param {number} [mode]
6748
+ */
6749
+ function ensureCopyFile(src, dest, mode) {
6750
+ ensureDirectory(path_browserify.dirname(dest));
6751
+ fs_ignored_.copyFileSync(src, dest, mode);
6752
+ }
6753
+
6754
+ /**
6755
+ * Deletes a file (If the file exists).
6756
+ * @param {string} filePath
6757
+ * @returns {boolean}
6758
+ */
6759
+ function tryDeleteFile(filePath) {
6760
+ if (fileExists(filePath)) {
6761
+ fs_ignored_.unlinkSync(filePath);
6762
+ return true;
6763
+ }
6764
+ return false;
6765
+ }
6766
+
6767
+ /**
6768
+ * Copies a file to a destination.
6769
+ * @param {string} src
6770
+ * @param {string} dest
6771
+ * @param {number} [mode]
6772
+ * @returns {Promise<void>}
6773
+ */
6774
+ function ensureCopyFileAsync(src, dest, mode) {
6775
+ ensureDirectory(path.dirname(dest));
6776
+ return fs.promises.copyFile(src, dest, mode);
6777
+ }
6778
+
6779
+ /**
6780
+ * Deletes a file (If the file exists).
6781
+ * @param {string} filePath
6782
+ * @returns {Promise<boolean>}
6783
+ */
6784
+ async function tryDeleteFileAsync(filePath) {
6785
+ if (fileExists(filePath)) {
6786
+ await fs.promises.unlink(filePath);
6787
+ return true;
6788
+ }
6789
+ return false;
6790
+ }
6791
+
6792
+ /*========================*
6793
+ * Text Operations
6794
+ *========================*/
6795
+
6796
+ /**
6797
+ * Writes text to a file (Ensures that the directory exists, creating it recursively if needed).
6798
+ * @param {string} filePath
6799
+ * @param {string} content
6800
+ * @param {fs.WriteFileOptions} [ops='utf-8']
6801
+ */
6802
+ function writeTextFile(filePath, content, ops = 'utf-8') {
6803
+ const dir = path_browserify.dirname(filePath);
6804
+ ensureDirectory(dir);
6805
+ fs_ignored_.writeFileSync(filePath, content, ops);
6806
+ }
6807
+
6808
+ /**
6809
+ * Writes text to a file (Ensures that the directory exists, creating it recursively if needed).
6810
+ * @param {string} filePath
6811
+ * @param {string} content
6812
+ * @param {fs.WriteFileOptions} [ops='utf-8']
6813
+ * @returns {Promise<void>}
6814
+ */
6815
+ function writeTextFileAsync(filePath, content, ops = 'utf-8') {
6816
+ const dir = path.dirname(filePath);
6817
+ ensureDirectory(dir);
6818
+ return fs.promises.writeFile(filePath, content, ops);
6819
+ }
6820
+
6821
+ /*========================*
6822
+ * Directory Listings
6823
+ *========================*/
6824
+
6825
+ /**
6826
+ * Lists all files and dirs in a directory (optionally recursive).
6827
+ * @param {string} dirPath
6828
+ * @param {boolean} [recursive=false]
6829
+ * @returns {{ files: string[]; dirs: string[] }}
6830
+ */
6831
+ function listFiles(dirPath, recursive = false) {
6832
+ /** @type {{ files: string[]; dirs: string[] }} */
6833
+ const results = { files: [], dirs: [] };
6834
+ if (!dirExists(dirPath)) return results;
6835
+
6836
+ const entries = fs_ignored_.readdirSync(dirPath);
6837
+ for (const entry of entries) {
6838
+ const fullPath = path_browserify.join(dirPath, entry);
6839
+ const stat = fs_ignored_.lstatSync(fullPath);
6840
+ if (stat.isDirectory()) {
6841
+ results.dirs.push(fullPath);
6842
+ if (recursive) {
6843
+ const results2 = listFiles(fullPath, true);
6844
+ results.files.push(...results2.files);
6845
+ results.dirs.push(...results2.dirs);
6846
+ }
6847
+ } else {
6848
+ results.files.push(fullPath);
6849
+ }
6850
+ }
6851
+ return results;
6852
+ }
6853
+
6854
+ /**
6855
+ * Lists all directories in a directory (optionally recursive).
6856
+ * @param {string} dirPath
6857
+ * @param {boolean} [recursive=false]
6858
+ * @returns {string[]}
6859
+ */
6860
+ function listDirs(dirPath, recursive = false) {
6861
+ /** @type {string[]} */
6862
+ const results = [];
6863
+ if (!dirExists(dirPath)) return results;
6864
+
6865
+ const entries = fs_ignored_.readdirSync(dirPath);
6866
+ for (const entry of entries) {
6867
+ const fullPath = path_browserify.join(dirPath, entry);
6868
+ const stat = fs_ignored_.lstatSync(fullPath);
6869
+ if (stat.isDirectory()) {
6870
+ results.push(fullPath);
6871
+ if (recursive) {
6872
+ results.push(...listDirs(fullPath, true));
6873
+ }
6874
+ }
6875
+ }
6876
+ return results;
6877
+ }
6878
+
6879
+ /*========================*
6880
+ * File Info
6881
+ *========================*/
6882
+
6883
+ /**
6884
+ * Returns the size of a file in bytes.
6885
+ * @param {string} filePath
6886
+ * @returns {number}
6887
+ */
6888
+ function fileSize(filePath) {
6889
+ if (!fileExists(filePath)) return 0;
6890
+ const stats = fs_ignored_.statSync(filePath);
6891
+ return stats.size;
6892
+ }
6893
+
6894
+ /**
6895
+ * Returns the total size of a directory in bytes.
6896
+ * @param {string} dirPath
6897
+ * @returns {number}
6898
+ */
6899
+ function dirSize(dirPath) {
6900
+ let total = 0;
6901
+ const files = listFiles(dirPath, true).files;
6902
+ for (const file of files) {
6903
+ total += fileSize(file);
6904
+ }
6905
+ return total;
6906
+ }
6907
+
6908
+ /*========================*
6909
+ * Backup Utilities
6910
+ *========================*/
6911
+
6912
+ /**
6913
+ * Creates a backup copy of a file with .bak timestamp suffix.
6914
+ * @param {string} filePath
6915
+ * @param {string} [ext='bak']
6916
+ */
6917
+ function backupFile(filePath, ext = 'bak') {
6918
+ if (!fileExists(filePath)) return;
6919
+ const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
6920
+ const backupPath = `${filePath}.${ext}.${timestamp}`;
6921
+ ensureCopyFile(filePath, backupPath);
6922
+ }
6923
+
6924
+ /**
6925
+ * Returns the most recent backup file path for a given file.
6926
+ * @param {string} filePath
6927
+ * @param {string} [ext='bak']
6928
+ * @returns {string} Full path to the most recent backup
6929
+ */
6930
+ function getLatestBackupPath(filePath, ext = 'bak') {
6931
+ const dir = path_browserify.dirname(filePath);
6932
+ const baseName = path_browserify.basename(filePath);
6933
+ const backups = fs_ignored_.readdirSync(dir)
6934
+ .filter((name) => name.startsWith(`${baseName}.${ext}.`))
6935
+ .sort()
6936
+ .reverse();
6937
+
6938
+ if (backups.length === 0) throw new Error(`No backups found for ${filePath}`);
6939
+
6940
+ return path_browserify.join(dir, backups[0]);
6941
+ }
6942
+
6943
+ /**
6944
+ * Restores the most recent backup of a file.
6945
+ * @param {string} filePath
6946
+ * @param {string} [ext='bak']
6947
+ */
6948
+ function restoreLatestBackup(filePath, ext = 'bak') {
6949
+ const latestBackup = getLatestBackupPath(filePath, ext);
6950
+ ensureCopyFile(latestBackup, filePath);
6951
+ }
6952
+
6953
+ /**
6954
+ * Restores the most recent backup of a file.
6955
+ * @param {string} filePath
6956
+ * @param {string} [ext='bak']
6957
+ * @returns {Promise<void>}
6958
+ */
6959
+ function restoreLatestBackupAsync(filePath, ext = 'bak') {
6960
+ const latestBackup = getLatestBackupPath(filePath, ext);
6961
+ return ensureCopyFileAsync(latestBackup, filePath);
6962
+ }
6963
+
6964
+ /**
6965
+ * Creates a backup copy of a file with .bak timestamp suffix.
6966
+ * @param {string} filePath
6967
+ * @param {string} [ext='bak']
6968
+ * @returns {Promise<void>}
6969
+ */
6970
+ async function backupFileAsync(filePath, ext = 'bak') {
6971
+ if (!fileExists(filePath)) return;
6972
+ const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
6973
+ const backupPath = `${filePath}.${ext}.${timestamp}`;
6974
+ return ensureCopyFileAsync(filePath, backupPath);
6975
+ }
6976
+
6977
+ /*========================*
6978
+ * Rename Utilities
6979
+ *========================*/
6980
+
6981
+ /**
6982
+ * Renames multiple files in a directory using a rename function.
6983
+ * @param {string} dirPath - The target directory.
6984
+ * @param {(original: string, index: number) => string} renameFn - Function that returns new filename.
6985
+ * @param {string[]} [extensions] - Optional: Only rename files with these extensions.
6986
+ *
6987
+ * @throws {TypeError} If any argument has an invalid type.
6988
+ * @throws {Error} If the directory does not exist or contains invalid files.
6989
+ */
6990
+ function renameFileBatch(dirPath, renameFn, extensions = []) {
6991
+ // Validate types
6992
+ if (typeof dirPath !== 'string') throw new TypeError('dirPath must be a string');
6993
+ if (typeof renameFn !== 'function') throw new TypeError('renameFn must be a function');
6994
+ if (!Array.isArray(extensions)) throw new TypeError('extensions must be an array of strings');
6995
+ if (!fs_ignored_.existsSync(dirPath) || !fs_ignored_.statSync(dirPath).isDirectory())
6996
+ throw new Error(`Directory not found or invalid: ${dirPath}`);
6997
+ for (const ext of extensions) {
6998
+ if (typeof ext !== 'string' || !ext.startsWith('.'))
6999
+ throw new TypeError(`Invalid extension: ${ext}`);
7000
+ }
7001
+
7002
+ const files = listFiles(dirPath).files;
7003
+ let index = 0;
7004
+
7005
+ for (const file of files) {
7006
+ const ext = path_browserify.extname(file);
7007
+ if (extensions.length && !extensions.includes(ext)) continue;
7008
+
7009
+ const originalName = path_browserify.basename(file);
7010
+ const newName = renameFn(originalName, index++);
7011
+ const newPath = path_browserify.join(dirPath, newName);
7012
+
7013
+ if (originalName === newName) continue;
7014
+
7015
+ fs_ignored_.renameSync(file, newPath);
7016
+ }
7017
+ }
7018
+
7019
+ /**
7020
+ * Renames files using regex replacement.
7021
+ * @param {string} dirPath
7022
+ * @param {RegExp} pattern - Regex to match in the filename.
7023
+ * @param {string} replacement - Replacement string.
7024
+ * @param {string[]} [extensions]
7025
+ */
7026
+ function renameFileRegex(dirPath, pattern, replacement, extensions = []) {
7027
+ renameFileBatch(
7028
+ dirPath,
7029
+ (filename) => {
7030
+ const ext = path_browserify.extname(filename);
7031
+ const name = path_browserify.basename(filename, ext).replace(pattern, replacement);
7032
+ return `${name}${ext}`;
7033
+ },
7034
+ extensions,
7035
+ );
7036
+ }
7037
+
7038
+ /**
7039
+ * Adds a prefix or suffix to filenames.
7040
+ * @param {string} dirPath
7041
+ * @param {{ prefix?: string, suffix?: string }} options
7042
+ * @param {string[]} [extensions]
7043
+ */
7044
+ function renameFileAddPrefixSuffix(dirPath, { prefix = '', suffix = '' }, extensions = []) {
7045
+ renameFileBatch(
7046
+ dirPath,
7047
+ (filename) => {
7048
+ const ext = path_browserify.extname(filename);
7049
+ const name = path_browserify.basename(filename, ext);
7050
+ return `${prefix}${name}${suffix}${ext}`;
7051
+ },
7052
+ extensions,
7053
+ );
7054
+ }
7055
+
7056
+ /**
7057
+ * Normalizes all filenames to lowercase (or uppercase).
7058
+ * @param {string} dirPath
7059
+ * @param {'lower' | 'upper' | 'title'} mode
7060
+ * @param {string[]} [extensions]
7061
+ * @param {boolean} [normalizeExt=false] - Whether to apply case change to file extensions too.
7062
+ * @throws {Error} If mode is invalid.
7063
+ */
7064
+ function renameFileNormalizeCase(
7065
+ dirPath,
7066
+ mode = 'lower',
7067
+ extensions = [],
7068
+ normalizeExt = false,
7069
+ ) {
7070
+ if (typeof mode !== 'string' || !['lower', 'upper', 'title'].includes(mode))
7071
+ throw new Error(`Invalid mode "${mode}". Must be 'lower', 'upper' or 'title'.`);
7072
+ renameFileBatch(
7073
+ dirPath,
7074
+ (filename) => {
7075
+ /**
7076
+ * @param {string} text
7077
+ * @returns {string}
7078
+ */
7079
+ const changeToMode = (text) => {
7080
+ if (mode === 'lower') return text.toLowerCase();
7081
+ else if (mode === 'upper') return text.toUpperCase();
7082
+ else if (mode === 'title') return toTitleCase(text);
7083
+ else return text;
7084
+ };
7085
+
7086
+ const rawExt = path_browserify.extname(filename);
7087
+ const ext = normalizeExt ? changeToMode(rawExt) : rawExt;
7088
+ const name = changeToMode(path_browserify.basename(filename, rawExt));
7089
+ return `${name}${ext}`;
7090
+ },
7091
+ extensions,
7092
+ );
7093
+ }
7094
+
7095
+ /**
7096
+ * Pads numbers in filenames (e.g., "img1.jpg" -> "img001.jpg").
7097
+ * @param {string} dirPath
7098
+ * @param {number} totalDigits
7099
+ * @param {string[]} [extensions]
7100
+ */
7101
+ function renameFilePadNumbers(dirPath, totalDigits = 3, extensions = []) {
7102
+ renameFileBatch(
7103
+ dirPath,
7104
+ (filename) => {
7105
+ return filename.replace(/\d+/, (match) => match.padStart(totalDigits, '0'));
7106
+ },
7107
+ extensions,
7108
+ );
7109
+ }
7110
+
7111
+ ;// ./src/v1/libs/TinyDragger.mjs
7112
+
7113
+
7114
+
7115
+ /**
7116
+ * @typedef {Object} VibrationPatterns
7117
+ * @property {number[]|false} start - Pattern to vibrate on start
7118
+ * @property {number[]|false} end - Pattern to vibrate on end
7119
+ * @property {number[]|false} collide - Pattern to vibrate on collision
7120
+ * @property {number[]|false} move - Pattern to vibrate while moving
7121
+ */
7122
+
7123
+ /**
7124
+ * TinyDragger enables drag-and-drop functionality for a DOM element.
7125
+ * It supports jail boundaries, optional collision detection, vibration feedback,
7126
+ * automatic reverting, proxy dragging, and event dispatching.
7127
+ */
7128
+ class TinyDragger {
7129
+ #enabled = true;
7130
+ #destroyed = false;
7131
+
7132
+ #offsetY = 0;
7133
+ #offsetX = 0;
7134
+
7135
+ #lockInsideJail = false;
7136
+ #revertOnDrop = false;
7137
+ #dragging = false;
7138
+ #collisionByMouse = false;
7139
+ #dropInJailOnly = false;
7140
+
7141
+ /** @type {HTMLElement|null} */
7142
+ #lastCollision = null;
7143
+
7144
+ /** @type {HTMLElement[]} */
7145
+ #collidables = [];
7146
+
7147
+ /** @type {HTMLElement|null} */
7148
+ #dragProxy = null;
7149
+
7150
+ /** @type {VibrationPatterns} */
7151
+ #vibration = { start: false, end: false, collide: false, move: false };
7152
+
7153
+ /** @type {HTMLElement|null} */
7154
+ #jail = null;
7155
+
7156
+ #target;
7157
+
7158
+ #dragHiddenClass = 'drag-hidden';
7159
+ #classDragging = 'dragging';
7160
+ #classBodyDragging = 'drag-active';
7161
+ #classJailDragging = 'jail-drag-active';
7162
+ #classJailDragDisabled = 'jail-drag-disabled';
7163
+ #classDragCollision = 'dragging-collision';
7164
+
7165
+ /** @typedef {(event: TouchEvent) => void} TouchDragEvent */
7166
+
7167
+ /**
7168
+ * @param {HTMLElement} targetElement - The element to make draggable.
7169
+ * @param {Object} [options={}] - Configuration options.
7170
+ * @param {HTMLElement} [options.jail] - Optional container to restrict dragging within.
7171
+ * @param {boolean} [options.collisionByMouse=false] - Use mouse position for collision instead of element rect.
7172
+ * @param {string} [options.classDragging='dragging'] - CSS class applied to the clone during dragging.
7173
+ * @param {string} [options.classBodyDragging='drag-active'] - CSS class applied to <body> during dragging.
7174
+ * @param {string} [options.classJailDragging='jail-drag-active'] - CSS class applied to jail element during drag.
7175
+ * @param {string} [options.classJailDragDisabled='jail-drag-disabled'] - CSS class applied to jail element disabled.
7176
+ * @param {string} [options.classDragCollision='dragging-collision'] - CSS class applied to collision element.
7177
+ * @param {boolean} [options.lockInsideJail=false] - Restrict movement within the jail container.
7178
+ * @param {boolean} [options.dropInJailOnly=false] - Restrict drop within the jail container.
7179
+ * @param {VibrationPatterns|false} [options.vibration=false] - Vibration feedback configuration.
7180
+ * @param {boolean} [options.revertOnDrop=false] - Whether to return to original position on drop.
7181
+ * @param {string} [options.classHidden='drag-hidden'] - CSS class to hide original element during dragging.
7182
+ * @throws {Error} If any option has an invalid type.
7183
+ */
7184
+ constructor(targetElement, options = {}) {
7185
+ if (!(targetElement instanceof HTMLElement))
7186
+ throw new Error('TinyDragger requires a valid target HTMLElement to initialize.');
7187
+
7188
+ this.#target = targetElement;
7189
+
7190
+ // === Validations ===
7191
+ if (options.jail !== undefined && !(options.jail instanceof HTMLElement))
7192
+ throw new Error('The "jail" option must be an HTMLElement if provided.');
7193
+
7194
+ if (
7195
+ options.vibration !== undefined &&
7196
+ options.vibration !== false &&
7197
+ !isJsonObject(options.vibration)
7198
+ )
7199
+ throw new Error('The "vibration" option must be an object or false.');
7200
+
7201
+ /**
7202
+ * @param {any} val
7203
+ * @param {string} name
7204
+ */
7205
+ const validateBoolean = (val, name) => {
7206
+ if (val !== undefined && typeof val !== 'boolean') {
7207
+ throw new Error(`The "${name}" option must be a boolean.`);
7208
+ }
7209
+ };
7210
+
7211
+ /**
7212
+ * @param {any} val
7213
+ * @param {string} name
7214
+ */
7215
+ const validateString = (val, name) => {
7216
+ if (val !== undefined && typeof val !== 'string') {
7217
+ throw new Error(`The "${name}" option must be a string.`);
7218
+ }
7219
+ };
7220
+
7221
+ validateBoolean(options.collisionByMouse, 'collisionByMouse');
7222
+ validateBoolean(options.lockInsideJail, 'lockInsideJail');
7223
+ validateBoolean(options.dropInJailOnly, 'dropInJailOnly');
7224
+ validateBoolean(options.revertOnDrop, 'revertOnDrop');
7225
+
7226
+ validateString(options.classDragging, 'classDragging');
7227
+ validateString(options.classBodyDragging, 'classBodyDragging');
7228
+ validateString(options.classJailDragging, 'classJailDragging');
7229
+ validateString(options.classJailDragDisabled, 'classJailDragDisabled');
7230
+ validateString(options.classDragCollision, 'classDragCollision');
7231
+ validateString(options.classHidden, 'classHidden');
7232
+
7233
+ if (options.jail instanceof HTMLElement) this.#jail = options.jail;
7234
+
7235
+ /** @type {VibrationPatterns} */
7236
+ const vibrationTemplate = { start: false, end: false, collide: false, move: false };
7237
+ this.#vibration = Object.assign(
7238
+ vibrationTemplate,
7239
+ isJsonObject(options.vibration) ? options.vibration : {},
7240
+ );
7241
+
7242
+ if (typeof options.classDragging === 'string') this.#classDragging = options.classDragging;
7243
+ if (typeof options.classBodyDragging === 'string')
7244
+ this.#classBodyDragging = options.classBodyDragging;
7245
+ if (typeof options.classJailDragging === 'string')
7246
+ this.#classJailDragging = options.classJailDragging;
7247
+ if (typeof options.classJailDragDisabled === 'string')
7248
+ this.#classJailDragDisabled = options.classJailDragDisabled;
7249
+ if (typeof options.classHidden === 'string') this.#dragHiddenClass = options.classHidden;
7250
+ if (typeof options.classDragCollision === 'string')
7251
+ this.#classDragCollision = options.classDragCollision;
7252
+
7253
+ if (typeof options.collisionByMouse === 'boolean')
7254
+ this.#collisionByMouse = options.collisionByMouse;
7255
+ if (typeof options.revertOnDrop === 'boolean') this.#revertOnDrop = options.revertOnDrop;
7256
+ if (typeof options.lockInsideJail === 'boolean') this.#lockInsideJail = options.lockInsideJail;
7257
+ if (typeof options.dropInJailOnly === 'boolean') this.#dropInJailOnly = options.dropInJailOnly;
7258
+
7259
+ /** @private */
7260
+ this._onMouseDown = this.#startDrag.bind(this);
7261
+ /** @private */
7262
+ this._onMouseMove = this.#drag.bind(this);
7263
+ /** @private */
7264
+ this._onMouseUp = this.#endDrag.bind(this);
7265
+
7266
+ /**
7267
+ * @type {TouchDragEvent}
7268
+ * @private
7269
+ */
7270
+ this._onTouchStart = (e) => this.#startDrag(e.touches[0]);
7271
+
7272
+ /**
7273
+ * @type {TouchDragEvent}
7274
+ * @private
7275
+ */
7276
+ this._onTouchMove = (e) => this.#drag(e.touches[0]);
7277
+
7278
+ /**
7279
+ * @type {TouchDragEvent}
7280
+ * @private
7281
+ */
7282
+ this._onTouchEnd = (e) => this.#endDrag(e.changedTouches[0]);
7283
+
7284
+ this.#target.addEventListener('mousedown', this._onMouseDown);
7285
+ this.#target.addEventListener('touchstart', this._onTouchStart, { passive: false });
7286
+ }
7287
+
7288
+ /**
7289
+ * Enables the drag functionality.
7290
+ */
7291
+ enable() {
7292
+ this.#checkDestroy();
7293
+ if (this.#jail) this.#jail.classList.add(this.#classJailDragDisabled);
7294
+ this.#enabled = true;
7295
+ }
7296
+
7297
+ /**
7298
+ * Disables the drag functionality.
7299
+ */
7300
+ disable() {
7301
+ if (this.#jail) this.#jail.classList.remove(this.#classJailDragDisabled);
7302
+ this.#enabled = false;
7303
+ }
7304
+
7305
+ /**
7306
+ * Adds an element to be considered for collision detection.
7307
+ * @param {HTMLElement} element - The element to track collisions with.
7308
+ * @throws {Error} If the element is not a valid HTMLElement.
7309
+ */
7310
+ addCollidable(element) {
7311
+ this.#checkDestroy();
7312
+ if (!(element instanceof HTMLElement))
7313
+ throw new Error('addCollidable expects an HTMLElement as argument.');
7314
+ if (!this.#collidables.includes(element)) this.#collidables.push(element);
7315
+ }
7316
+
7317
+ /**
7318
+ * Removes a collidable element from the tracking list.
7319
+ * @param {HTMLElement} element - The element to remove.
7320
+ * @throws {Error} If the element is not a valid HTMLElement.
7321
+ */
7322
+ removeCollidable(element) {
7323
+ this.#checkDestroy();
7324
+ if (!(element instanceof HTMLElement))
7325
+ throw new Error('removeCollidable expects an HTMLElement as argument.');
7326
+ this.#collidables = this.#collidables.filter((el) => el !== element);
7327
+ }
7328
+
7329
+ /**
7330
+ * Sets vibration patterns for drag events.
7331
+ * @param {Object} [param0={}] - Vibration pattern configuration.
7332
+ * @param {number[]|false} [param0.startPattern=false] - Vibration on drag start.
7333
+ * @param {number[]|false} [param0.endPattern=false] - Vibration on drag end.
7334
+ * @param {number[]|false} [param0.collidePattern=false] - Vibration on collision.
7335
+ * @param {number[]|false} [param0.movePattern=false] - Vibration during movement.
7336
+ * @throws {Error} If any pattern is not false or an array of numbers.
7337
+ */
7338
+ setVibrationPattern({
7339
+ startPattern = false,
7340
+ endPattern = false,
7341
+ collidePattern = false,
7342
+ movePattern = false,
7343
+ } = {}) {
7344
+ this.#checkDestroy();
7345
+
7346
+ /** @param {any} value */
7347
+ const isValidPattern = (value) =>
7348
+ value === false || (Array.isArray(value) && value.every((n) => typeof n === 'number'));
7349
+
7350
+ if (!isValidPattern(startPattern))
7351
+ throw new Error('Invalid "startPattern": must be false or an array of numbers.');
7352
+ if (!isValidPattern(endPattern))
7353
+ throw new Error('Invalid "endPattern": must be false or an array of numbers.');
7354
+ if (!isValidPattern(collidePattern))
7355
+ throw new Error('Invalid "collidePattern": must be false or an array of numbers.');
7356
+ if (!isValidPattern(movePattern))
7357
+ throw new Error('Invalid "movePattern": must be false or an array of numbers.');
7358
+
7359
+ this.#vibration = {
7360
+ start: startPattern,
7361
+ end: endPattern,
7362
+ collide: collidePattern,
7363
+ move: movePattern,
7364
+ };
7365
+ }
7366
+
7367
+ /**
7368
+ * Disables all vibration feedback.
7369
+ */
7370
+ disableVibration() {
7371
+ this.#checkDestroy();
7372
+ this.#vibration = { start: false, end: false, collide: false, move: false };
7373
+ }
7374
+
7375
+ /**
7376
+ * Calculates the cursor offset relative to the top-left of the target element.
7377
+ * @param {MouseEvent|Touch} event - The mouse or touch event.
7378
+ * @returns {{x: number, y: number}} The offset in pixels.
7379
+ * @throws {Error} If event is not a MouseEvent or Touch with clientX/clientY.
7380
+ */
7381
+ getOffset(event) {
7382
+ this.#checkDestroy();
7383
+ if (
7384
+ (!(event instanceof MouseEvent) && !(event instanceof Touch)) ||
7385
+ typeof event.clientX !== 'number' ||
7386
+ typeof event.clientY !== 'number'
7387
+ )
7388
+ throw new Error('getOffset expects an event with valid clientX and clientY coordinates.');
7389
+
7390
+ const targetRect = this.#target.getBoundingClientRect();
7391
+ const { left: borderLeft, top: borderTop } = getHtmlElBordersWidth(this.#target);
7392
+ return {
7393
+ x: event.clientX - targetRect.left + borderLeft,
7394
+ y: event.clientY - targetRect.top + borderTop,
7395
+ };
7396
+ }
7397
+
7398
+ /**
7399
+ * Handles the start of a drag event.
7400
+ * @param {MouseEvent|Touch} event - The initiating event.
7401
+ */
7402
+ #startDrag(event) {
7403
+ if (event instanceof MouseEvent) event.preventDefault();
7404
+ if (this.#destroyed || !this.#enabled || !this.#target.parentElement) return;
7405
+
7406
+ const dragProxy = this.#target.cloneNode(true);
7407
+ if (!(dragProxy instanceof HTMLElement)) return;
7408
+ this.#dragProxy = dragProxy;
7409
+
7410
+ this.#dragging = true;
7411
+
7412
+ const rect = this.#target.getBoundingClientRect();
7413
+
7414
+ Object.assign(this.#dragProxy.style, {
7415
+ position: 'absolute',
7416
+ pointerEvents: 'none',
7417
+ left: `${this.#target.offsetLeft}px`,
7418
+ top: `${this.#target.offsetTop}px`,
7419
+ width: `${rect.width}px`,
7420
+ height: `${rect.height}px`,
7421
+ zIndex: 9999,
7422
+ });
7423
+
7424
+ this.#target.classList.add(this.#dragHiddenClass);
7425
+ this.#target.parentElement.appendChild(this.#dragProxy);
7426
+
7427
+ const { x: offsetX, y: offsetY } = this.getOffset(event);
7428
+ this.#offsetX = offsetX;
7429
+ this.#offsetY = offsetY;
7430
+
7431
+ this.#dragProxy.classList.add(this.#classDragging);
7432
+ document.body.classList.add(this.#classBodyDragging);
7433
+ if (this.#jail) this.#jail.classList.add(this.#classJailDragging);
7434
+
7435
+ document.addEventListener('mousemove', this._onMouseMove);
7436
+ document.addEventListener('mouseup', this._onMouseUp);
7437
+
7438
+ document.addEventListener('touchmove', this._onTouchMove, { passive: false });
7439
+ document.addEventListener('touchend', this._onTouchEnd);
7440
+
7441
+ if (navigator.vibrate && Array.isArray(this.#vibration.start)) {
7442
+ navigator.vibrate(this.#vibration.start);
7443
+ }
7444
+
7445
+ this.checkDragCollision(event);
7446
+ this.#dispatchEvent('drag');
7447
+ }
7448
+
7449
+ /**
7450
+ * Handles dragging collision.
7451
+ * @param {MouseEvent|Touch} event - The drag event.
7452
+ */
7453
+ checkDragCollision(event) {
7454
+ const { collidedElement: collided } = this.execCollision(event);
7455
+ if (collided && collided !== this.#lastCollision) {
7456
+ if (navigator.vibrate && Array.isArray(this.#vibration.collide)) {
7457
+ navigator.vibrate(this.#vibration.collide);
7458
+ }
7459
+ this.#lastCollision = collided;
7460
+ if (this.#lastCollision) this.#lastCollision.classList.add(this.#classDragCollision);
7461
+ } else if (!collided) {
7462
+ if (this.#lastCollision) this.#lastCollision.classList.remove(this.#classDragCollision);
7463
+ this.#lastCollision = null;
7464
+ }
7465
+ }
7466
+
7467
+ /**
7468
+ * Handles dragging movement.
7469
+ * @param {MouseEvent|Touch} event - The drag event.
7470
+ */
7471
+ #drag(event) {
7472
+ if (event instanceof MouseEvent) event.preventDefault();
7473
+ if (this.#destroyed || !this.#dragging || !this.#enabled || !this.#dragProxy) return;
7474
+
7475
+ const parent = this.#dragProxy.offsetParent || document.body;
7476
+ const parentRect = parent.getBoundingClientRect();
7477
+
7478
+ let x = event.clientX - parentRect.left - this.#offsetX;
7479
+ let y = event.clientY - parentRect.top - this.#offsetY;
7480
+
7481
+ if (this.#lockInsideJail && this.#jail) {
7482
+ const jailRect = this.#jail.getBoundingClientRect();
7483
+ const targetRect = this.#dragProxy.getBoundingClientRect();
7484
+
7485
+ const jailLeft = jailRect.left - parentRect.left;
7486
+ const jailTop = jailRect.top - parentRect.top;
7487
+
7488
+ const { x: borderX, y: borderY } = getHtmlElBordersWidth(this.#jail);
7489
+ const maxX = jailLeft + jailRect.width - targetRect.width - borderY;
7490
+ const maxY = jailTop + jailRect.height - targetRect.height - borderX;
7491
+
7492
+ x = Math.max(jailLeft, Math.min(x, maxX));
7493
+ y = Math.max(jailTop, Math.min(y, maxY));
7494
+ }
7495
+
7496
+ this.#dragProxy.style.position = 'absolute';
7497
+ this.#dragProxy.style.left = `${x}px`;
7498
+ this.#dragProxy.style.top = `${y}px`;
7499
+
7500
+ if (navigator.vibrate && Array.isArray(this.#vibration.move)) {
7501
+ navigator.vibrate(this.#vibration.move);
7502
+ }
7503
+
7504
+ this.checkDragCollision(event);
7505
+ this.#dispatchEvent('dragging');
7506
+ }
7507
+
7508
+ /**
7509
+ * Handles the collision of a drag.
7510
+ * @param {MouseEvent|Touch} event - The release event.
7511
+ * @returns {{ inJail: boolean; collidedElement: HTMLElement|null }}
7512
+ */
7513
+ execCollision(event) {
7514
+ if (this.#destroyed || !this.#dragProxy) return { inJail: false, collidedElement: null };
7515
+
7516
+ let collidedElement;
7517
+ let inJail = true;
7518
+ const jailRect = this.#jail?.getBoundingClientRect();
7519
+ if (this.#collisionByMouse) {
7520
+ const x = event.clientX;
7521
+ const y = event.clientY;
7522
+ if (this.#dropInJailOnly && this.#jail && jailRect) {
7523
+ inJail =
7524
+ x >= jailRect.left && x <= jailRect.right && y >= jailRect.top && y <= jailRect.bottom;
7525
+ }
7526
+
7527
+ collidedElement = inJail ? this.getCollidedElement(x, y) : null;
7528
+ } else {
7529
+ const targetRect = this.#dragProxy.getBoundingClientRect();
7530
+ if (this.#dropInJailOnly && this.#jail && jailRect) {
7531
+ inJail =
7532
+ targetRect.left >= jailRect.left &&
7533
+ targetRect.right <= jailRect.right &&
7534
+ targetRect.top >= jailRect.top &&
7535
+ targetRect.bottom <= jailRect.bottom;
7536
+ }
7537
+
7538
+ collidedElement = inJail ? this.getCollidedElementByRect(targetRect) : null;
7539
+ }
7540
+
7541
+ return { inJail, collidedElement };
7542
+ }
7543
+
7544
+ /**
7545
+ * Handles the end of a drag.
7546
+ * @param {MouseEvent|Touch} event - The release event.
7547
+ */
7548
+ #endDrag(event) {
7549
+ if (event instanceof MouseEvent) event.preventDefault();
7550
+ if (this.#destroyed || !this.#dragging) return;
7551
+
7552
+ this.#dragging = false;
7553
+ if (!this.#dragProxy) return;
7554
+
7555
+ this.#target.classList.remove(this.#classDragging);
7556
+ document.body.classList.remove(this.#classBodyDragging);
7557
+ if (this.#jail) this.#jail.classList.remove(this.#classJailDragging);
7558
+
7559
+ document.removeEventListener('mousemove', this._onMouseMove);
7560
+ document.removeEventListener('mouseup', this._onMouseUp);
7561
+
7562
+ document.removeEventListener('touchmove', this._onTouchMove);
7563
+ document.removeEventListener('touchend', this._onTouchEnd);
7564
+ const { collidedElement } = this.execCollision(event);
7565
+
7566
+ if (navigator.vibrate && Array.isArray(this.#vibration.end)) {
7567
+ navigator.vibrate(this.#vibration.end);
7568
+ }
7569
+
7570
+ const newX = this.#dragProxy.style.left;
7571
+ const newY = this.#dragProxy.style.top;
7572
+ if (this.#dragProxy) {
7573
+ this.#dragProxy.remove();
7574
+ this.#dragProxy = null;
7575
+ }
7576
+
7577
+ if (this.#lastCollision) this.#lastCollision.classList.remove(this.#classDragCollision);
7578
+ this.#lastCollision = null;
7579
+
7580
+ this.#target.classList.remove(this.#dragHiddenClass);
7581
+ if (!this.#revertOnDrop) {
7582
+ this.#target.style.left = newX;
7583
+ this.#target.style.top = newY;
7584
+ }
7585
+
7586
+ const dropEvent = new CustomEvent('drop', {
7587
+ detail: {
7588
+ target: collidedElement,
7589
+ },
7590
+ });
7591
+
7592
+ this.#target.dispatchEvent(dropEvent);
7593
+ }
7594
+
7595
+ /**
7596
+ * Detects collision based on rectangle intersection.
7597
+ * @param {DOMRect} rect - Bounding rectangle of the dragged proxy.
7598
+ * @returns {HTMLElement|null} The collided element or null.
7599
+ * @throws {Error} If rect is not a DOMRect with valid numeric properties.
7600
+ */
7601
+ getCollidedElementByRect(rect) {
7602
+ this.#checkDestroy();
7603
+ if (
7604
+ !(rect instanceof DOMRect) ||
7605
+ typeof rect.left !== 'number' ||
7606
+ typeof rect.right !== 'number' ||
7607
+ typeof rect.top !== 'number' ||
7608
+ typeof rect.bottom !== 'number'
7609
+ )
7610
+ throw new Error('getCollidedElementByRect expects a valid DOMRect object.');
7611
+
7612
+ return (
7613
+ this.#collidables.find((el) => {
7614
+ const elRect = el.getBoundingClientRect();
7615
+ return !(
7616
+ rect.right < elRect.left ||
7617
+ rect.left > elRect.right ||
7618
+ rect.bottom < elRect.top ||
7619
+ rect.top > elRect.bottom
7620
+ );
7621
+ }) || null
7622
+ );
7623
+ }
7624
+
7625
+ /**
7626
+ * Detects collision with a point using element bounding rectangles.
7627
+ * @param {number} x - Horizontal screen coordinate.
7628
+ * @param {number} y - Vertical screen coordinate.
7629
+ * @returns {HTMLElement|null} The collided element or null.
7630
+ */
7631
+ getCollidedElement(x, y) {
7632
+ this.#checkDestroy();
7633
+ if (typeof x !== 'number' || typeof y !== 'number')
7634
+ throw new Error('getCollidedElement expects numeric x and y coordinates.');
7635
+
7636
+ return (
7637
+ this.#collidables.find((el) => {
7638
+ const rect = el.getBoundingClientRect();
7639
+ return x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom;
7640
+ }) || null
7641
+ );
7642
+ }
7643
+
7644
+ /**
7645
+ * Dispatches a custom event from the target element.
7646
+ * @param {string} type - The event name.
7647
+ */
7648
+ #dispatchEvent(type) {
7649
+ const event = new CustomEvent(type);
7650
+ this.#target.dispatchEvent(event);
7651
+ }
7652
+
7653
+ /**
7654
+ * Gets whether dragging is currently active.
7655
+ * @returns {boolean}
7656
+ */
7657
+ getDragging() {
7658
+ return this.#dragging;
7659
+ }
7660
+
7661
+ /**
7662
+ * Gets whether movement is restricted inside the jail container.
7663
+ * @returns {boolean}
7664
+ */
7665
+ getLockInsideJail() {
7666
+ return this.#lockInsideJail;
7667
+ }
7668
+
7669
+ /**
7670
+ * Sets whether movement is restricted inside the jail container.
7671
+ * @param {boolean} value
7672
+ */
7673
+ setLockInsideJail(value) {
7674
+ if (typeof value !== 'boolean') throw new Error('lockInsideJail must be a boolean.');
7675
+ this.#lockInsideJail = value;
7676
+ }
7677
+
7678
+ /**
7679
+ * Gets whether the element should revert to original position on drop.
7680
+ * @returns {boolean}
7681
+ */
7682
+ getRevertOnDrop() {
7683
+ return this.#revertOnDrop;
7684
+ }
7685
+
7686
+ /**
7687
+ * Sets whether the element should revert to original position on drop.
7688
+ * @param {boolean} value
7689
+ */
7690
+ setRevertOnDrop(value) {
7691
+ if (typeof value !== 'boolean') throw new Error('revertOnDrop must be a boolean.');
7692
+ this.#revertOnDrop = value;
7693
+ }
7694
+
7695
+ /**
7696
+ * Gets whether collision detection uses mouse position.
7697
+ * @returns {boolean}
7698
+ */
7699
+ getCollisionByMouse() {
7700
+ return this.#collisionByMouse;
7701
+ }
7702
+
7703
+ /**
7704
+ * Sets whether collision detection uses mouse position.
7705
+ * @param {boolean} value
7706
+ */
7707
+ setCollisionByMouse(value) {
7708
+ if (typeof value !== 'boolean') throw new Error('collisionByMouse must be a boolean.');
7709
+ this.#collisionByMouse = value;
7710
+ }
7711
+
7712
+ /**
7713
+ * Gets whether dropping is restricted inside the jail container.
7714
+ * @returns {boolean}
7715
+ */
7716
+ getDropInJailOnly() {
7717
+ return this.#dropInJailOnly;
7718
+ }
7719
+
7720
+ /**
7721
+ * Sets whether dropping is restricted inside the jail container.
7722
+ * @param {boolean} value
7723
+ */
7724
+ setDropInJailOnly(value) {
7725
+ if (typeof value !== 'boolean') throw new Error('dropInJailOnly must be a boolean.');
7726
+ this.#dropInJailOnly = value;
7727
+ }
7728
+
7729
+ /**
7730
+ * Returns the original target element being dragged.
7731
+ * @returns {HTMLElement}
7732
+ */
7733
+ getTarget() {
7734
+ return this.#target;
7735
+ }
7736
+
7737
+ /**
7738
+ * Returns the current jail container (if any).
7739
+ * @returns {HTMLElement|null}
7740
+ */
7741
+ getJail() {
7742
+ return this.#jail;
7743
+ }
7744
+
7745
+ /**
7746
+ * Returns the current proxy element being dragged (if any).
7747
+ * @returns {HTMLElement|null}
7748
+ */
7749
+ getDragProxy() {
7750
+ return this.#dragProxy;
7751
+ }
7752
+
7753
+ /**
7754
+ * Returns the last collided element (if any).
7755
+ * @returns {HTMLElement|null}
7756
+ */
7757
+ getLastCollision() {
7758
+ return this.#lastCollision;
7759
+ }
7760
+
7761
+ /**
7762
+ * Returns all registered collidable elements.
7763
+ * @returns {HTMLElement[]}
7764
+ */
7765
+ getCollidables() {
7766
+ return [...this.#collidables];
7767
+ }
7768
+
7769
+ /**
7770
+ * Returns the CSS class used to hide the target during drag.
7771
+ * @returns {string}
7772
+ */
7773
+ getDragHiddenClass() {
7774
+ return this.#dragHiddenClass;
7775
+ }
7776
+
7777
+ /**
7778
+ * Returns the CSS class applied to the clone during dragging.
7779
+ * @returns {string}
7780
+ */
7781
+ getClassDragging() {
7782
+ return this.#classDragging;
7783
+ }
7784
+
7785
+ /**
7786
+ * Returns the CSS class applied to <body> during dragging.
7787
+ * @returns {string}
7788
+ */
7789
+ getClassBodyDragging() {
7790
+ return this.#classBodyDragging;
7791
+ }
7792
+
7793
+ /**
7794
+ * Returns the CSS class applied to the jail during dragging.
7795
+ * @returns {string}
7796
+ */
7797
+ getClassJailDragging() {
7798
+ return this.#classJailDragging;
7799
+ }
7800
+
7801
+ /**
7802
+ * Returns the CSS class applied to the jail when dragging is disabled.
7803
+ * @returns {string}
7804
+ */
7805
+ getClassJailDragDisabled() {
7806
+ return this.#classJailDragDisabled;
7807
+ }
7808
+
7809
+ /**
7810
+ * Returns the CSS class applied to a collided element.
7811
+ * @returns {string}
7812
+ */
7813
+ getClassDragCollision() {
7814
+ return this.#classDragCollision;
7815
+ }
7816
+
7817
+ /**
7818
+ * Returns the full vibration configuration.
7819
+ * @returns {VibrationPatterns}
7820
+ */
7821
+ getVibrations() {
7822
+ return { ...this.#vibration };
7823
+ }
7824
+
7825
+ /**
7826
+ * Returns the vibration pattern for drag start.
7827
+ * @returns {number[]|boolean}
7828
+ */
7829
+ getStartVibration() {
7830
+ return this.#vibration.start;
7831
+ }
7832
+
7833
+ /**
7834
+ * Returns the vibration pattern for drag end.
7835
+ * @returns {number[]|boolean}
7836
+ */
7837
+ getEndVibration() {
7838
+ return this.#vibration.end;
7839
+ }
7840
+
7841
+ /**
7842
+ * Returns the vibration pattern for collisions.
7843
+ * @returns {number[]|boolean}
7844
+ */
7845
+ getCollideVibration() {
7846
+ return this.#vibration.collide;
7847
+ }
7848
+
7849
+ /**
7850
+ * Returns the vibration pattern during movement.
7851
+ * @returns {number[]|boolean}
7852
+ */
7853
+ getMoveVibration() {
7854
+ return this.#vibration.move;
7855
+ }
7856
+
7857
+ /**
7858
+ * Returns whether the dragger is currently enabled.
7859
+ * @returns {boolean}
7860
+ */
7861
+ isEnabled() {
7862
+ return this.#enabled;
7863
+ }
7864
+
7865
+ /**
7866
+ * Internal method to verify if the instance has been destroyed.
7867
+ * Throws an error if any operation is attempted after destruction.
7868
+ */
7869
+ #checkDestroy() {
7870
+ if (this.#destroyed)
7871
+ throw new Error('This TinyDragger instance has been destroyed and can no longer be used.');
7872
+ }
7873
+
7874
+ /**
7875
+ * Completely disables drag-and-drop and cleans up all event listeners.
7876
+ * Does NOT remove the original HTML element.
7877
+ */
7878
+ destroy() {
7879
+ if (this.#destroyed) return;
7880
+ this.disable();
7881
+
7882
+ this.#target.removeEventListener('mousedown', this._onMouseDown);
7883
+ this.#target.removeEventListener('touchstart', this._onTouchStart);
7884
+
7885
+ document.removeEventListener('mousemove', this._onMouseMove);
7886
+ document.removeEventListener('mouseup', this._onMouseUp);
7887
+
7888
+ document.removeEventListener('touchmove', this._onTouchMove);
7889
+ document.removeEventListener('touchend', this._onTouchEnd);
7890
+
7891
+ if (this.#lastCollision) this.#lastCollision.classList.remove(this.#classDragCollision);
7892
+ if (this.#dragProxy) {
7893
+ this.#dragProxy.remove();
7894
+ this.#dragProxy = null;
7895
+ }
7896
+
7897
+ this.#collidables = [];
7898
+ this.#dragging = false;
7899
+ this.#lastCollision = null;
7900
+
7901
+ this.#target.classList.remove(this.#dragHiddenClass, this.#classDragging);
7902
+ document.body.classList.remove(this.#classBodyDragging);
7903
+ if (this.#jail)
7904
+ this.#jail.classList.remove(this.#classJailDragging, this.#classJailDragDisabled);
7905
+
7906
+ this.#destroyed = true;
7907
+ }
7908
+ }
7909
+
7910
+ /* harmony default export */ const libs_TinyDragger = (TinyDragger);
7911
+
7912
+ ;// ./src/v1/index.mjs
7913
+
7914
+
7915
+
7916
+
7917
+
5137
7918
 
5138
7919
 
5139
7920