tiny-essentials 1.12.1 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/legacy/firebase/index.mjs +5 -5
- package/dist/v1/TinyBasicsEs.js +1 -1257
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyDomReadyManager.js +213 -0
- package/dist/v1/TinyDomReadyManager.min.js +1 -0
- package/dist/v1/TinyEssentials.js +512 -146
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyUploadClicker.js +331 -147
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/basics/index.cjs +0 -23
- package/dist/v1/basics/index.d.mts +1 -23
- package/dist/v1/basics/index.mjs +1 -2
- package/dist/v1/build/TinyDomReadyManager.cjs +7 -0
- package/dist/v1/build/TinyDomReadyManager.d.mts +3 -0
- package/dist/v1/build/TinyDomReadyManager.mjs +2 -0
- package/dist/v1/fileManager/asyncFuncs.cjs +272 -0
- package/dist/v1/fileManager/asyncFuncs.d.mts +93 -0
- package/dist/v1/fileManager/asyncFuncs.mjs +236 -0
- package/dist/v1/fileManager/index.cjs +35 -0
- package/dist/v1/fileManager/index.d.mts +30 -0
- package/dist/v1/fileManager/index.mjs +3 -0
- package/dist/v1/{basics/fileManager.cjs → fileManager/normalFuncs.cjs} +10 -105
- package/dist/v1/{basics/fileManager.d.mts → fileManager/normalFuncs.d.mts} +3 -56
- package/dist/v1/{basics/fileManager.mjs → fileManager/normalFuncs.mjs} +48 -131
- package/dist/v1/index.cjs +32 -23
- package/dist/v1/index.d.mts +30 -23
- package/dist/v1/index.mjs +4 -2
- package/dist/v1/libs/TinyDomReadyManager.cjs +174 -0
- package/dist/v1/libs/TinyDomReadyManager.d.mts +100 -0
- package/dist/v1/libs/TinyDomReadyManager.mjs +158 -0
- package/dist/v1/libs/TinyUploadClicker.cjs +1 -0
- package/docs/v1/README.md +4 -1
- package/docs/v1/{basics/fileManager.md → fileManager/main.md} +12 -0
- package/docs/v1/libs/TinyDomReadyManager.md +198 -0
- package/package.json +5 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/******/ (() => { // webpackBootstrap
|
|
2
2
|
/******/ var __webpack_modules__ = ({
|
|
3
3
|
|
|
4
|
-
/***/
|
|
4
|
+
/***/ 133:
|
|
5
5
|
/***/ (() => {
|
|
6
6
|
|
|
7
7
|
/* (ignored) */
|
|
@@ -1924,6 +1924,13 @@ var hexSliceLookupTable = (function () {
|
|
|
1924
1924
|
})()
|
|
1925
1925
|
|
|
1926
1926
|
|
|
1927
|
+
/***/ }),
|
|
1928
|
+
|
|
1929
|
+
/***/ 370:
|
|
1930
|
+
/***/ (() => {
|
|
1931
|
+
|
|
1932
|
+
/* (ignored) */
|
|
1933
|
+
|
|
1927
1934
|
/***/ }),
|
|
1928
1935
|
|
|
1929
1936
|
/***/ 526:
|
|
@@ -2879,6 +2886,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2879
2886
|
// EXPORTS
|
|
2880
2887
|
__webpack_require__.d(__webpack_exports__, {
|
|
2881
2888
|
ColorSafeStringify: () => (/* reexport */ libs_ColorSafeStringify),
|
|
2889
|
+
TinyDomReadyManager: () => (/* reexport */ libs_TinyDomReadyManager),
|
|
2882
2890
|
TinyDragDropDetector: () => (/* reexport */ libs_TinyDragDropDetector),
|
|
2883
2891
|
TinyDragger: () => (/* reexport */ libs_TinyDragger),
|
|
2884
2892
|
TinyLevelUp: () => (/* reexport */ userLevel),
|
|
@@ -2893,18 +2901,21 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
2893
2901
|
backupFile: () => (/* reexport */ backupFile),
|
|
2894
2902
|
checkObj: () => (/* reexport */ checkObj),
|
|
2895
2903
|
clearDirectory: () => (/* reexport */ clearDirectory),
|
|
2904
|
+
clearDirectoryAsync: () => (/* reexport */ clearDirectoryAsync),
|
|
2896
2905
|
cloneObjTypeOrder: () => (/* reexport */ cloneObjTypeOrder),
|
|
2897
2906
|
countObj: () => (/* reexport */ countObj),
|
|
2898
2907
|
dirExists: () => (/* reexport */ dirExists),
|
|
2899
2908
|
dirSize: () => (/* reexport */ dirSize),
|
|
2909
|
+
dirSizeAsync: () => (/* reexport */ dirSizeAsync),
|
|
2900
2910
|
documentIsFullScreen: () => (/* reexport */ documentIsFullScreen),
|
|
2901
2911
|
ensureCopyFile: () => (/* reexport */ ensureCopyFile),
|
|
2902
|
-
ensureDirectory: () => (/* reexport */
|
|
2912
|
+
ensureDirectory: () => (/* reexport */ normalFuncs_ensureDirectory),
|
|
2903
2913
|
exitFullScreen: () => (/* reexport */ exitFullScreen),
|
|
2904
2914
|
extendObjType: () => (/* reexport */ extendObjType),
|
|
2905
2915
|
fetchJson: () => (/* reexport */ fetchJson),
|
|
2906
|
-
fileExists: () => (/* reexport */
|
|
2916
|
+
fileExists: () => (/* reexport */ normalFuncs_fileExists),
|
|
2907
2917
|
fileSize: () => (/* reexport */ fileSize),
|
|
2918
|
+
fileSizeAsync: () => (/* reexport */ fileSizeAsync),
|
|
2908
2919
|
formatBytes: () => (/* reexport */ formatBytes),
|
|
2909
2920
|
formatCustomTimer: () => (/* reexport */ formatCustomTimer),
|
|
2910
2921
|
formatDayTimer: () => (/* reexport */ formatDayTimer),
|
|
@@ -2914,15 +2925,18 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
2914
2925
|
getHtmlElBordersWidth: () => (/* reexport */ getHtmlElBordersWidth),
|
|
2915
2926
|
getHtmlElMargin: () => (/* reexport */ getHtmlElMargin),
|
|
2916
2927
|
getHtmlElPadding: () => (/* reexport */ getHtmlElPadding),
|
|
2917
|
-
getLatestBackupPath: () => (/* reexport */
|
|
2928
|
+
getLatestBackupPath: () => (/* reexport */ normalFuncs_getLatestBackupPath),
|
|
2918
2929
|
getSimplePerc: () => (/* reexport */ getSimplePerc),
|
|
2919
2930
|
getTimeDuration: () => (/* reexport */ getTimeDuration),
|
|
2920
2931
|
isDirEmpty: () => (/* reexport */ isDirEmpty),
|
|
2932
|
+
isDirEmptyAsync: () => (/* reexport */ isDirEmptyAsync),
|
|
2921
2933
|
isFullScreenMode: () => (/* reexport */ isFullScreenMode),
|
|
2922
2934
|
isJsonObject: () => (/* reexport */ isJsonObject),
|
|
2923
2935
|
isScreenFilled: () => (/* reexport */ isScreenFilled),
|
|
2924
2936
|
listDirs: () => (/* reexport */ listDirs),
|
|
2937
|
+
listDirsAsync: () => (/* reexport */ listDirsAsync),
|
|
2925
2938
|
listFiles: () => (/* reexport */ listFiles),
|
|
2939
|
+
listFilesAsync: () => (/* reexport */ listFilesAsync),
|
|
2926
2940
|
objType: () => (/* reexport */ objType),
|
|
2927
2941
|
offFullScreenChange: () => (/* reexport */ offFullScreenChange),
|
|
2928
2942
|
onFullScreenChange: () => (/* reexport */ onFullScreenChange),
|
|
@@ -6612,10 +6626,10 @@ class TinyDragDropDetector {
|
|
|
6612
6626
|
/* harmony default export */ const libs_TinyDragDropDetector = (TinyDragDropDetector);
|
|
6613
6627
|
|
|
6614
6628
|
// EXTERNAL MODULE: fs (ignored)
|
|
6615
|
-
var fs_ignored_ = __webpack_require__(
|
|
6629
|
+
var fs_ignored_ = __webpack_require__(133);
|
|
6616
6630
|
// EXTERNAL MODULE: ./node_modules/path-browserify/index.js
|
|
6617
6631
|
var path_browserify = __webpack_require__(975);
|
|
6618
|
-
;// ./src/v1/
|
|
6632
|
+
;// ./src/v1/fileManager/normalFuncs.mjs
|
|
6619
6633
|
|
|
6620
6634
|
|
|
6621
6635
|
|
|
@@ -6631,8 +6645,8 @@ var path_browserify = __webpack_require__(975);
|
|
|
6631
6645
|
* @returns {any}
|
|
6632
6646
|
*/
|
|
6633
6647
|
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');
|
|
6648
|
+
if (!(0,fs_ignored_.existsSync)(filePath)) throw new Error(`File not found: ${filePath}`);
|
|
6649
|
+
const content = (0,fs_ignored_.readFileSync)(filePath, 'utf-8');
|
|
6636
6650
|
return JSON.parse(content);
|
|
6637
6651
|
}
|
|
6638
6652
|
|
|
@@ -6645,32 +6659,7 @@ function readJsonFile(filePath) {
|
|
|
6645
6659
|
*/
|
|
6646
6660
|
function writeJsonFile(filePath, data, spaces = 2) {
|
|
6647
6661
|
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');
|
|
6662
|
+
(0,fs_ignored_.writeFileSync)(filePath, json, 'utf-8');
|
|
6674
6663
|
}
|
|
6675
6664
|
|
|
6676
6665
|
/*========================*
|
|
@@ -6681,9 +6670,9 @@ function writeJsonFileAsync(filePath, data, spaces = 2) {
|
|
|
6681
6670
|
* Ensures that the directory exists, creating it recursively if needed.
|
|
6682
6671
|
* @param {string} dirPath
|
|
6683
6672
|
*/
|
|
6684
|
-
function
|
|
6685
|
-
if (!fs_ignored_.existsSync(dirPath)) {
|
|
6686
|
-
fs_ignored_.mkdirSync(dirPath, { recursive: true });
|
|
6673
|
+
function normalFuncs_ensureDirectory(dirPath) {
|
|
6674
|
+
if (!(0,fs_ignored_.existsSync)(dirPath)) {
|
|
6675
|
+
(0,fs_ignored_.mkdirSync)(dirPath, { recursive: true });
|
|
6687
6676
|
}
|
|
6688
6677
|
}
|
|
6689
6678
|
|
|
@@ -6692,15 +6681,15 @@ function ensureDirectory(dirPath) {
|
|
|
6692
6681
|
* @param {string} dirPath
|
|
6693
6682
|
*/
|
|
6694
6683
|
function clearDirectory(dirPath) {
|
|
6695
|
-
if (!fs_ignored_.existsSync(dirPath)) return;
|
|
6696
|
-
const files = fs_ignored_.readdirSync(dirPath);
|
|
6684
|
+
if (!(0,fs_ignored_.existsSync)(dirPath)) return;
|
|
6685
|
+
const files = (0,fs_ignored_.readdirSync)(dirPath);
|
|
6697
6686
|
for (const file of files) {
|
|
6698
|
-
const fullPath = path_browserify.join(dirPath, file);
|
|
6699
|
-
const
|
|
6700
|
-
if (
|
|
6701
|
-
fs_ignored_.rmSync(fullPath, { recursive: true, force: true });
|
|
6687
|
+
const fullPath = (0,path_browserify.join)(dirPath, file);
|
|
6688
|
+
const statData = (0,fs_ignored_.lstatSync)(fullPath);
|
|
6689
|
+
if (statData.isDirectory()) {
|
|
6690
|
+
(0,fs_ignored_.rmSync)(fullPath, { recursive: true, force: true });
|
|
6702
6691
|
} else {
|
|
6703
|
-
fs_ignored_.unlinkSync(fullPath);
|
|
6692
|
+
(0,fs_ignored_.unlinkSync)(fullPath);
|
|
6704
6693
|
}
|
|
6705
6694
|
}
|
|
6706
6695
|
}
|
|
@@ -6714,8 +6703,8 @@ function clearDirectory(dirPath) {
|
|
|
6714
6703
|
* @param {string} filePath
|
|
6715
6704
|
* @returns {boolean}
|
|
6716
6705
|
*/
|
|
6717
|
-
function
|
|
6718
|
-
return fs_ignored_.existsSync(filePath) && fs_ignored_.lstatSync(filePath).isFile();
|
|
6706
|
+
function normalFuncs_fileExists(filePath) {
|
|
6707
|
+
return (0,fs_ignored_.existsSync)(filePath) && (0,fs_ignored_.lstatSync)(filePath).isFile();
|
|
6719
6708
|
}
|
|
6720
6709
|
|
|
6721
6710
|
/**
|
|
@@ -6724,7 +6713,7 @@ function fileExists(filePath) {
|
|
|
6724
6713
|
* @returns {boolean}
|
|
6725
6714
|
*/
|
|
6726
6715
|
function dirExists(dirPath) {
|
|
6727
|
-
return fs_ignored_.existsSync(dirPath) && fs_ignored_.lstatSync(dirPath).isDirectory();
|
|
6716
|
+
return (0,fs_ignored_.existsSync)(dirPath) && (0,fs_ignored_.lstatSync)(dirPath).isDirectory();
|
|
6728
6717
|
}
|
|
6729
6718
|
|
|
6730
6719
|
/**
|
|
@@ -6733,7 +6722,7 @@ function dirExists(dirPath) {
|
|
|
6733
6722
|
* @returns {boolean}
|
|
6734
6723
|
*/
|
|
6735
6724
|
function isDirEmpty(dirPath) {
|
|
6736
|
-
return
|
|
6725
|
+
return (0,fs_ignored_.readdirSync)(dirPath).length === 0;
|
|
6737
6726
|
}
|
|
6738
6727
|
|
|
6739
6728
|
/*========================*
|
|
@@ -6747,8 +6736,8 @@ function isDirEmpty(dirPath) {
|
|
|
6747
6736
|
* @param {number} [mode]
|
|
6748
6737
|
*/
|
|
6749
6738
|
function ensureCopyFile(src, dest, mode) {
|
|
6750
|
-
|
|
6751
|
-
fs_ignored_.copyFileSync(src, dest, mode);
|
|
6739
|
+
normalFuncs_ensureDirectory((0,path_browserify.dirname)(dest));
|
|
6740
|
+
(0,fs_ignored_.copyFileSync)(src, dest, mode);
|
|
6752
6741
|
}
|
|
6753
6742
|
|
|
6754
6743
|
/**
|
|
@@ -6757,33 +6746,8 @@ function ensureCopyFile(src, dest, mode) {
|
|
|
6757
6746
|
* @returns {boolean}
|
|
6758
6747
|
*/
|
|
6759
6748
|
function tryDeleteFile(filePath) {
|
|
6760
|
-
if (
|
|
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);
|
|
6749
|
+
if (normalFuncs_fileExists(filePath)) {
|
|
6750
|
+
(0,fs_ignored_.unlinkSync)(filePath);
|
|
6787
6751
|
return true;
|
|
6788
6752
|
}
|
|
6789
6753
|
return false;
|
|
@@ -6797,25 +6761,12 @@ async function tryDeleteFileAsync(filePath) {
|
|
|
6797
6761
|
* Writes text to a file (Ensures that the directory exists, creating it recursively if needed).
|
|
6798
6762
|
* @param {string} filePath
|
|
6799
6763
|
* @param {string} content
|
|
6800
|
-
* @param {fs.WriteFileOptions} [ops='utf-8']
|
|
6764
|
+
* @param {import('fs').WriteFileOptions} [ops='utf-8']
|
|
6801
6765
|
*/
|
|
6802
6766
|
function writeTextFile(filePath, content, ops = 'utf-8') {
|
|
6803
|
-
const dir = path_browserify.dirname(filePath);
|
|
6804
|
-
|
|
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);
|
|
6767
|
+
const dir = (0,path_browserify.dirname)(filePath);
|
|
6768
|
+
normalFuncs_ensureDirectory(dir);
|
|
6769
|
+
(0,fs_ignored_.writeFileSync)(filePath, content, ops);
|
|
6819
6770
|
}
|
|
6820
6771
|
|
|
6821
6772
|
/*========================*
|
|
@@ -6833,11 +6784,11 @@ function listFiles(dirPath, recursive = false) {
|
|
|
6833
6784
|
const results = { files: [], dirs: [] };
|
|
6834
6785
|
if (!dirExists(dirPath)) return results;
|
|
6835
6786
|
|
|
6836
|
-
const entries = fs_ignored_.readdirSync(dirPath);
|
|
6787
|
+
const entries = (0,fs_ignored_.readdirSync)(dirPath);
|
|
6837
6788
|
for (const entry of entries) {
|
|
6838
|
-
const fullPath = path_browserify.join(dirPath, entry);
|
|
6839
|
-
const
|
|
6840
|
-
if (
|
|
6789
|
+
const fullPath = (0,path_browserify.join)(dirPath, entry);
|
|
6790
|
+
const statData = (0,fs_ignored_.lstatSync)(fullPath);
|
|
6791
|
+
if (statData.isDirectory()) {
|
|
6841
6792
|
results.dirs.push(fullPath);
|
|
6842
6793
|
if (recursive) {
|
|
6843
6794
|
const results2 = listFiles(fullPath, true);
|
|
@@ -6862,11 +6813,11 @@ function listDirs(dirPath, recursive = false) {
|
|
|
6862
6813
|
const results = [];
|
|
6863
6814
|
if (!dirExists(dirPath)) return results;
|
|
6864
6815
|
|
|
6865
|
-
const entries = fs_ignored_.readdirSync(dirPath);
|
|
6816
|
+
const entries = (0,fs_ignored_.readdirSync)(dirPath);
|
|
6866
6817
|
for (const entry of entries) {
|
|
6867
|
-
const fullPath = path_browserify.join(dirPath, entry);
|
|
6868
|
-
const
|
|
6869
|
-
if (
|
|
6818
|
+
const fullPath = (0,path_browserify.join)(dirPath, entry);
|
|
6819
|
+
const statData = (0,fs_ignored_.lstatSync)(fullPath);
|
|
6820
|
+
if (statData.isDirectory()) {
|
|
6870
6821
|
results.push(fullPath);
|
|
6871
6822
|
if (recursive) {
|
|
6872
6823
|
results.push(...listDirs(fullPath, true));
|
|
@@ -6886,8 +6837,8 @@ function listDirs(dirPath, recursive = false) {
|
|
|
6886
6837
|
* @returns {number}
|
|
6887
6838
|
*/
|
|
6888
6839
|
function fileSize(filePath) {
|
|
6889
|
-
if (!
|
|
6890
|
-
const stats = fs_ignored_.statSync(filePath);
|
|
6840
|
+
if (!normalFuncs_fileExists(filePath)) return 0;
|
|
6841
|
+
const stats = (0,fs_ignored_.statSync)(filePath);
|
|
6891
6842
|
return stats.size;
|
|
6892
6843
|
}
|
|
6893
6844
|
|
|
@@ -6915,7 +6866,7 @@ function dirSize(dirPath) {
|
|
|
6915
6866
|
* @param {string} [ext='bak']
|
|
6916
6867
|
*/
|
|
6917
6868
|
function backupFile(filePath, ext = 'bak') {
|
|
6918
|
-
if (!
|
|
6869
|
+
if (!normalFuncs_fileExists(filePath)) return;
|
|
6919
6870
|
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
6920
6871
|
const backupPath = `${filePath}.${ext}.${timestamp}`;
|
|
6921
6872
|
ensureCopyFile(filePath, backupPath);
|
|
@@ -6927,17 +6878,17 @@ function backupFile(filePath, ext = 'bak') {
|
|
|
6927
6878
|
* @param {string} [ext='bak']
|
|
6928
6879
|
* @returns {string} Full path to the most recent backup
|
|
6929
6880
|
*/
|
|
6930
|
-
function
|
|
6931
|
-
const dir = path_browserify.dirname(filePath);
|
|
6932
|
-
const baseName = path_browserify.basename(filePath);
|
|
6933
|
-
const backups = fs_ignored_.readdirSync(dir)
|
|
6881
|
+
function normalFuncs_getLatestBackupPath(filePath, ext = 'bak') {
|
|
6882
|
+
const dir = (0,path_browserify.dirname)(filePath);
|
|
6883
|
+
const baseName = (0,path_browserify.basename)(filePath);
|
|
6884
|
+
const backups = (0,fs_ignored_.readdirSync)(dir)
|
|
6934
6885
|
.filter((name) => name.startsWith(`${baseName}.${ext}.`))
|
|
6935
6886
|
.sort()
|
|
6936
6887
|
.reverse();
|
|
6937
6888
|
|
|
6938
6889
|
if (backups.length === 0) throw new Error(`No backups found for ${filePath}`);
|
|
6939
6890
|
|
|
6940
|
-
return path_browserify.join(dir, backups[0]);
|
|
6891
|
+
return (0,path_browserify.join)(dir, backups[0]);
|
|
6941
6892
|
}
|
|
6942
6893
|
|
|
6943
6894
|
/**
|
|
@@ -6946,34 +6897,10 @@ function getLatestBackupPath(filePath, ext = 'bak') {
|
|
|
6946
6897
|
* @param {string} [ext='bak']
|
|
6947
6898
|
*/
|
|
6948
6899
|
function restoreLatestBackup(filePath, ext = 'bak') {
|
|
6949
|
-
const latestBackup =
|
|
6900
|
+
const latestBackup = normalFuncs_getLatestBackupPath(filePath, ext);
|
|
6950
6901
|
ensureCopyFile(latestBackup, filePath);
|
|
6951
6902
|
}
|
|
6952
6903
|
|
|
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
6904
|
/*========================*
|
|
6978
6905
|
* Rename Utilities
|
|
6979
6906
|
*========================*/
|
|
@@ -6992,7 +6919,7 @@ function renameFileBatch(dirPath, renameFn, extensions = []) {
|
|
|
6992
6919
|
if (typeof dirPath !== 'string') throw new TypeError('dirPath must be a string');
|
|
6993
6920
|
if (typeof renameFn !== 'function') throw new TypeError('renameFn must be a function');
|
|
6994
6921
|
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())
|
|
6922
|
+
if (!(0,fs_ignored_.existsSync)(dirPath) || !(0,fs_ignored_.statSync)(dirPath).isDirectory())
|
|
6996
6923
|
throw new Error(`Directory not found or invalid: ${dirPath}`);
|
|
6997
6924
|
for (const ext of extensions) {
|
|
6998
6925
|
if (typeof ext !== 'string' || !ext.startsWith('.'))
|
|
@@ -7003,16 +6930,16 @@ function renameFileBatch(dirPath, renameFn, extensions = []) {
|
|
|
7003
6930
|
let index = 0;
|
|
7004
6931
|
|
|
7005
6932
|
for (const file of files) {
|
|
7006
|
-
const ext = path_browserify.extname(file);
|
|
6933
|
+
const ext = (0,path_browserify.extname)(file);
|
|
7007
6934
|
if (extensions.length && !extensions.includes(ext)) continue;
|
|
7008
6935
|
|
|
7009
|
-
const originalName = path_browserify.basename(file);
|
|
6936
|
+
const originalName = (0,path_browserify.basename)(file);
|
|
7010
6937
|
const newName = renameFn(originalName, index++);
|
|
7011
|
-
const newPath = path_browserify.join(dirPath, newName);
|
|
6938
|
+
const newPath = (0,path_browserify.join)(dirPath, newName);
|
|
7012
6939
|
|
|
7013
6940
|
if (originalName === newName) continue;
|
|
7014
6941
|
|
|
7015
|
-
fs_ignored_.renameSync(file, newPath);
|
|
6942
|
+
(0,fs_ignored_.renameSync)(file, newPath);
|
|
7016
6943
|
}
|
|
7017
6944
|
}
|
|
7018
6945
|
|
|
@@ -7027,8 +6954,8 @@ function renameFileRegex(dirPath, pattern, replacement, extensions = []) {
|
|
|
7027
6954
|
renameFileBatch(
|
|
7028
6955
|
dirPath,
|
|
7029
6956
|
(filename) => {
|
|
7030
|
-
const ext = path_browserify.extname(filename);
|
|
7031
|
-
const name = path_browserify.basename(filename, ext).replace(pattern, replacement);
|
|
6957
|
+
const ext = (0,path_browserify.extname)(filename);
|
|
6958
|
+
const name = (0,path_browserify.basename)(filename, ext).replace(pattern, replacement);
|
|
7032
6959
|
return `${name}${ext}`;
|
|
7033
6960
|
},
|
|
7034
6961
|
extensions,
|
|
@@ -7045,8 +6972,8 @@ function renameFileAddPrefixSuffix(dirPath, { prefix = '', suffix = '' }, extens
|
|
|
7045
6972
|
renameFileBatch(
|
|
7046
6973
|
dirPath,
|
|
7047
6974
|
(filename) => {
|
|
7048
|
-
const ext = path_browserify.extname(filename);
|
|
7049
|
-
const name = path_browserify.basename(filename, ext);
|
|
6975
|
+
const ext = (0,path_browserify.extname)(filename);
|
|
6976
|
+
const name = (0,path_browserify.basename)(filename, ext);
|
|
7050
6977
|
return `${prefix}${name}${suffix}${ext}`;
|
|
7051
6978
|
},
|
|
7052
6979
|
extensions,
|
|
@@ -7083,9 +7010,9 @@ function renameFileNormalizeCase(
|
|
|
7083
7010
|
else return text;
|
|
7084
7011
|
};
|
|
7085
7012
|
|
|
7086
|
-
const rawExt = path_browserify.extname(filename);
|
|
7013
|
+
const rawExt = (0,path_browserify.extname)(filename);
|
|
7087
7014
|
const ext = normalizeExt ? changeToMode(rawExt) : rawExt;
|
|
7088
|
-
const name = changeToMode(path_browserify.basename(filename, rawExt));
|
|
7015
|
+
const name = changeToMode((0,path_browserify.basename)(filename, rawExt));
|
|
7089
7016
|
return `${name}${ext}`;
|
|
7090
7017
|
},
|
|
7091
7018
|
extensions,
|
|
@@ -7108,6 +7035,266 @@ function renameFilePadNumbers(dirPath, totalDigits = 3, extensions = []) {
|
|
|
7108
7035
|
);
|
|
7109
7036
|
}
|
|
7110
7037
|
|
|
7038
|
+
// EXTERNAL MODULE: fs/promises (ignored)
|
|
7039
|
+
var promises_ignored_ = __webpack_require__(370);
|
|
7040
|
+
;// ./src/v1/fileManager/asyncFuncs.mjs
|
|
7041
|
+
|
|
7042
|
+
|
|
7043
|
+
|
|
7044
|
+
|
|
7045
|
+
|
|
7046
|
+
/*========================*
|
|
7047
|
+
* JSON Operations
|
|
7048
|
+
*========================*/
|
|
7049
|
+
|
|
7050
|
+
/**
|
|
7051
|
+
* Reads and parses a JSON file.
|
|
7052
|
+
* Throws an error if the file content is not valid JSON.
|
|
7053
|
+
* @param {string} filePath
|
|
7054
|
+
* @returns {Promise<any>}
|
|
7055
|
+
*/
|
|
7056
|
+
async function readJsonFileAsync(filePath) {
|
|
7057
|
+
if (!existsSync(filePath)) throw new Error(`File not found: ${filePath}`);
|
|
7058
|
+
const content = await readFile(filePath, 'utf-8');
|
|
7059
|
+
return JSON.parse(content);
|
|
7060
|
+
}
|
|
7061
|
+
|
|
7062
|
+
/**
|
|
7063
|
+
* Saves an object as JSON to a file.
|
|
7064
|
+
* Automatically creates the directory if it does not exist.
|
|
7065
|
+
* @param {string} filePath
|
|
7066
|
+
* @param {any} data
|
|
7067
|
+
* @param {number} [spaces=2]
|
|
7068
|
+
* @returns {Promise<void>}
|
|
7069
|
+
*/
|
|
7070
|
+
function writeJsonFileAsync(filePath, data, spaces = 2) {
|
|
7071
|
+
const json = JSON.stringify(data, null, spaces);
|
|
7072
|
+
return writeFile(filePath, json, 'utf-8');
|
|
7073
|
+
}
|
|
7074
|
+
|
|
7075
|
+
/*========================*
|
|
7076
|
+
* Directory Management
|
|
7077
|
+
*========================*/
|
|
7078
|
+
|
|
7079
|
+
/**
|
|
7080
|
+
* Clears all contents inside a directory but keeps the directory.
|
|
7081
|
+
* @param {string} dirPath
|
|
7082
|
+
*/
|
|
7083
|
+
async function clearDirectoryAsync(dirPath) {
|
|
7084
|
+
if (!(0,fs_ignored_.existsSync)(dirPath)) return;
|
|
7085
|
+
const files = await (0,promises_ignored_.readdir)(dirPath);
|
|
7086
|
+
|
|
7087
|
+
/** @type {Record<string, import('fs').Stats>} */
|
|
7088
|
+
const dataList = {};
|
|
7089
|
+
const promises = [];
|
|
7090
|
+
|
|
7091
|
+
for (const file of files) {
|
|
7092
|
+
const fullPath = (0,path_browserify.join)(dirPath, file);
|
|
7093
|
+
const lsResult = (0,promises_ignored_.lstat)(fullPath);
|
|
7094
|
+
|
|
7095
|
+
lsResult.then((statData) => {
|
|
7096
|
+
dataList[fullPath] = statData;
|
|
7097
|
+
return statData;
|
|
7098
|
+
});
|
|
7099
|
+
promises.push(lsResult);
|
|
7100
|
+
}
|
|
7101
|
+
|
|
7102
|
+
await Promise.all(promises);
|
|
7103
|
+
const promises2 = [];
|
|
7104
|
+
for (const fullPath in dataList) {
|
|
7105
|
+
const statData = dataList[fullPath];
|
|
7106
|
+
if (statData.isDirectory()) {
|
|
7107
|
+
promises2.push((0,promises_ignored_.rm)(fullPath, { recursive: true, force: true }));
|
|
7108
|
+
} else {
|
|
7109
|
+
promises2.push((0,promises_ignored_.unlink)(fullPath));
|
|
7110
|
+
}
|
|
7111
|
+
}
|
|
7112
|
+
|
|
7113
|
+
await Promise.all(promises2);
|
|
7114
|
+
}
|
|
7115
|
+
|
|
7116
|
+
/*========================*
|
|
7117
|
+
* File Checks
|
|
7118
|
+
*========================*/
|
|
7119
|
+
|
|
7120
|
+
/**
|
|
7121
|
+
* Checks whether a directory is empty.
|
|
7122
|
+
* @param {string} dirPath
|
|
7123
|
+
* @returns {Promise<boolean>}
|
|
7124
|
+
*/
|
|
7125
|
+
async function isDirEmptyAsync(dirPath) {
|
|
7126
|
+
const data = await (0,promises_ignored_.readdir)(dirPath);
|
|
7127
|
+
return data.length === 0;
|
|
7128
|
+
}
|
|
7129
|
+
|
|
7130
|
+
/*========================*
|
|
7131
|
+
* File Operations
|
|
7132
|
+
*========================*/
|
|
7133
|
+
|
|
7134
|
+
/**
|
|
7135
|
+
* Copies a file to a destination.
|
|
7136
|
+
* @param {string} src
|
|
7137
|
+
* @param {string} dest
|
|
7138
|
+
* @param {number} [mode]
|
|
7139
|
+
* @returns {Promise<void>}
|
|
7140
|
+
*/
|
|
7141
|
+
function ensureCopyFileAsync(src, dest, mode) {
|
|
7142
|
+
ensureDirectory(dirname(dest));
|
|
7143
|
+
return copyFile(src, dest, mode);
|
|
7144
|
+
}
|
|
7145
|
+
|
|
7146
|
+
/**
|
|
7147
|
+
* Deletes a file (If the file exists).
|
|
7148
|
+
* @param {string} filePath
|
|
7149
|
+
* @returns {Promise<boolean>}
|
|
7150
|
+
*/
|
|
7151
|
+
async function tryDeleteFileAsync(filePath) {
|
|
7152
|
+
if (fileExists(filePath)) {
|
|
7153
|
+
await unlink(filePath);
|
|
7154
|
+
return true;
|
|
7155
|
+
}
|
|
7156
|
+
return false;
|
|
7157
|
+
}
|
|
7158
|
+
|
|
7159
|
+
/*========================*
|
|
7160
|
+
* Text Operations
|
|
7161
|
+
*========================*/
|
|
7162
|
+
|
|
7163
|
+
/**
|
|
7164
|
+
* Writes text to a file (Ensures that the directory exists, creating it recursively if needed).
|
|
7165
|
+
* @param {string} filePath
|
|
7166
|
+
* @param {string} content
|
|
7167
|
+
* @param {import('fs').WriteFileOptions} [ops='utf-8']
|
|
7168
|
+
* @returns {Promise<void>}
|
|
7169
|
+
*/
|
|
7170
|
+
function writeTextFileAsync(filePath, content, ops = 'utf-8') {
|
|
7171
|
+
const dir = dirname(filePath);
|
|
7172
|
+
ensureDirectory(dir);
|
|
7173
|
+
return writeFile(filePath, content, ops);
|
|
7174
|
+
}
|
|
7175
|
+
|
|
7176
|
+
/*========================*
|
|
7177
|
+
* Directory Listings
|
|
7178
|
+
*========================*/
|
|
7179
|
+
|
|
7180
|
+
/**
|
|
7181
|
+
* Lists all files and dirs in a directory (optionally recursive).
|
|
7182
|
+
* @param {string} dirPath
|
|
7183
|
+
* @param {boolean} [recursive=false]
|
|
7184
|
+
* @returns {Promise<{ files: string[]; dirs: string[] }>}
|
|
7185
|
+
*/
|
|
7186
|
+
async function listFilesAsync(dirPath, recursive = false) {
|
|
7187
|
+
/** @type {{ files: string[]; dirs: string[] }} */
|
|
7188
|
+
const results = { files: [], dirs: [] };
|
|
7189
|
+
if (!dirExists(dirPath)) return results;
|
|
7190
|
+
|
|
7191
|
+
const entries = await (0,promises_ignored_.readdir)(dirPath);
|
|
7192
|
+
for (const entry of entries) {
|
|
7193
|
+
const fullPath = (0,path_browserify.join)(dirPath, entry);
|
|
7194
|
+
const statData = await (0,promises_ignored_.lstat)(fullPath);
|
|
7195
|
+
if (statData.isDirectory()) {
|
|
7196
|
+
results.dirs.push(fullPath);
|
|
7197
|
+
if (recursive) {
|
|
7198
|
+
const results2 = await listFilesAsync(fullPath, true);
|
|
7199
|
+
results.files.push(...results2.files);
|
|
7200
|
+
results.dirs.push(...results2.dirs);
|
|
7201
|
+
}
|
|
7202
|
+
} else {
|
|
7203
|
+
results.files.push(fullPath);
|
|
7204
|
+
}
|
|
7205
|
+
}
|
|
7206
|
+
return results;
|
|
7207
|
+
}
|
|
7208
|
+
|
|
7209
|
+
/**
|
|
7210
|
+
* Lists all directories in a directory (optionally recursive).
|
|
7211
|
+
* @param {string} dirPath
|
|
7212
|
+
* @param {boolean} [recursive=false]
|
|
7213
|
+
* @returns {Promise<string[]>}
|
|
7214
|
+
*/
|
|
7215
|
+
async function listDirsAsync(dirPath, recursive = false) {
|
|
7216
|
+
/** @type {string[]} */
|
|
7217
|
+
const results = [];
|
|
7218
|
+
if (!dirExists(dirPath)) return results;
|
|
7219
|
+
|
|
7220
|
+
const entries = await (0,promises_ignored_.readdir)(dirPath);
|
|
7221
|
+
for (const entry of entries) {
|
|
7222
|
+
const fullPath = (0,path_browserify.join)(dirPath, entry);
|
|
7223
|
+
const statData = await (0,promises_ignored_.lstat)(fullPath);
|
|
7224
|
+
if (statData.isDirectory()) {
|
|
7225
|
+
results.push(fullPath);
|
|
7226
|
+
if (recursive) {
|
|
7227
|
+
results.push(...(await listDirsAsync(fullPath, true)));
|
|
7228
|
+
}
|
|
7229
|
+
}
|
|
7230
|
+
}
|
|
7231
|
+
return results;
|
|
7232
|
+
}
|
|
7233
|
+
|
|
7234
|
+
/*========================*
|
|
7235
|
+
* File Info
|
|
7236
|
+
*========================*/
|
|
7237
|
+
|
|
7238
|
+
/**
|
|
7239
|
+
* Returns the size of a file in bytes.
|
|
7240
|
+
* @param {string} filePath
|
|
7241
|
+
* @returns {Promise<number>}
|
|
7242
|
+
*/
|
|
7243
|
+
async function fileSizeAsync(filePath) {
|
|
7244
|
+
if (!normalFuncs_fileExists(filePath)) return 0;
|
|
7245
|
+
const stats = await (0,promises_ignored_.stat)(filePath);
|
|
7246
|
+
return stats.size;
|
|
7247
|
+
}
|
|
7248
|
+
|
|
7249
|
+
/**
|
|
7250
|
+
* Returns the total size of a directory in bytes.
|
|
7251
|
+
* @param {string} dirPath
|
|
7252
|
+
* @returns {Promise<number>}
|
|
7253
|
+
*/
|
|
7254
|
+
async function dirSizeAsync(dirPath) {
|
|
7255
|
+
let total = 0;
|
|
7256
|
+
const { files } = await listFilesAsync(dirPath, true);
|
|
7257
|
+
const promises = [];
|
|
7258
|
+
for (const file of files) {
|
|
7259
|
+
const result = fileSizeAsync(file);
|
|
7260
|
+
result.then((item) => {
|
|
7261
|
+
total += item;
|
|
7262
|
+
return item;
|
|
7263
|
+
});
|
|
7264
|
+
promises.push(result);
|
|
7265
|
+
}
|
|
7266
|
+
await Promise.all(promises);
|
|
7267
|
+
return total;
|
|
7268
|
+
}
|
|
7269
|
+
|
|
7270
|
+
/*========================*
|
|
7271
|
+
* Backup Utilities
|
|
7272
|
+
*========================*/
|
|
7273
|
+
|
|
7274
|
+
/**
|
|
7275
|
+
* Restores the most recent backup of a file.
|
|
7276
|
+
* @param {string} filePath
|
|
7277
|
+
* @param {string} [ext='bak']
|
|
7278
|
+
* @returns {Promise<void>}
|
|
7279
|
+
*/
|
|
7280
|
+
function restoreLatestBackupAsync(filePath, ext = 'bak') {
|
|
7281
|
+
const latestBackup = getLatestBackupPath(filePath, ext);
|
|
7282
|
+
return ensureCopyFileAsync(latestBackup, filePath);
|
|
7283
|
+
}
|
|
7284
|
+
|
|
7285
|
+
/**
|
|
7286
|
+
* Creates a backup copy of a file with .bak timestamp suffix.
|
|
7287
|
+
* @param {string} filePath
|
|
7288
|
+
* @param {string} [ext='bak']
|
|
7289
|
+
* @returns {Promise<void>}
|
|
7290
|
+
*/
|
|
7291
|
+
async function backupFileAsync(filePath, ext = 'bak') {
|
|
7292
|
+
if (!fileExists(filePath)) return;
|
|
7293
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
7294
|
+
const backupPath = `${filePath}.${ext}.${timestamp}`;
|
|
7295
|
+
return ensureCopyFileAsync(filePath, backupPath);
|
|
7296
|
+
}
|
|
7297
|
+
|
|
7111
7298
|
;// ./src/v1/libs/TinyDragger.mjs
|
|
7112
7299
|
|
|
7113
7300
|
|
|
@@ -8014,6 +8201,180 @@ class TinyDragger {
|
|
|
8014
8201
|
|
|
8015
8202
|
/* harmony default export */ const libs_TinyDragger = (TinyDragger);
|
|
8016
8203
|
|
|
8204
|
+
;// ./src/v1/libs/TinyDomReadyManager.mjs
|
|
8205
|
+
/**
|
|
8206
|
+
* A basic function that performs a task when the system is ready.
|
|
8207
|
+
* Used for handlers in the readiness queue.
|
|
8208
|
+
*
|
|
8209
|
+
* @typedef {() => void} Fn
|
|
8210
|
+
*/
|
|
8211
|
+
|
|
8212
|
+
/**
|
|
8213
|
+
* A function that determines whether a specific handler should be executed.
|
|
8214
|
+
* Should return `true` to allow execution, or `false` to skip the handler.
|
|
8215
|
+
*
|
|
8216
|
+
* @typedef {() => boolean} FnFilter
|
|
8217
|
+
*/
|
|
8218
|
+
|
|
8219
|
+
/**
|
|
8220
|
+
* @typedef {Object} Handler
|
|
8221
|
+
* @property {Fn} fn - Function to execute when ready.
|
|
8222
|
+
* @property {boolean} once - Whether to execute only once.
|
|
8223
|
+
* @property {number} priority - Execution order (higher priority runs first).
|
|
8224
|
+
* @property {FnFilter|null} filter - Optional filter function to determine execution.
|
|
8225
|
+
* @property {boolean} domOnly - Whether to run as soon as DOM is ready (before full readiness).
|
|
8226
|
+
*/
|
|
8227
|
+
|
|
8228
|
+
class TinyDomReadyManager {
|
|
8229
|
+
/** @type {Handler[]} */
|
|
8230
|
+
#handlers = [];
|
|
8231
|
+
|
|
8232
|
+
/** @type {boolean} */
|
|
8233
|
+
#isDomReady = false;
|
|
8234
|
+
|
|
8235
|
+
/** @type {boolean} */
|
|
8236
|
+
#isFullyReady = false;
|
|
8237
|
+
|
|
8238
|
+
/** @type {Promise<any>[]} */
|
|
8239
|
+
#promises = [];
|
|
8240
|
+
|
|
8241
|
+
/**
|
|
8242
|
+
* Checks if the DOM is ready and if all Promises have been resolved.
|
|
8243
|
+
*/
|
|
8244
|
+
#checkAllReady() {
|
|
8245
|
+
if (this.#isDomReady) {
|
|
8246
|
+
Promise.all(this.#promises)
|
|
8247
|
+
.then(() => {
|
|
8248
|
+
this.#isFullyReady = true;
|
|
8249
|
+
this.#runHandlers(false); // run non-domOnly
|
|
8250
|
+
})
|
|
8251
|
+
.catch((err) => {
|
|
8252
|
+
console.error('[TinyDomReadyManager] Promise rejected:', err);
|
|
8253
|
+
});
|
|
8254
|
+
}
|
|
8255
|
+
}
|
|
8256
|
+
|
|
8257
|
+
/**
|
|
8258
|
+
* Executes handlers by filtering them by `domOnly` flag and sorting by priority.
|
|
8259
|
+
* @param {boolean} domOnlyOnly - Whether to run only `domOnly` handlers.
|
|
8260
|
+
*/
|
|
8261
|
+
#runHandlers(domOnlyOnly) {
|
|
8262
|
+
this.#handlers
|
|
8263
|
+
.filter((h) => h.domOnly === domOnlyOnly)
|
|
8264
|
+
.sort((a, b) => b.priority - a.priority)
|
|
8265
|
+
.forEach((handler) => this.#invokeHandler(handler));
|
|
8266
|
+
|
|
8267
|
+
this.#handlers = this.#handlers.filter((h) => !(h.once && (domOnlyOnly ? h.domOnly : true)));
|
|
8268
|
+
}
|
|
8269
|
+
|
|
8270
|
+
/**
|
|
8271
|
+
* Executes a handler if its filter passes.
|
|
8272
|
+
* @param {Handler} handler
|
|
8273
|
+
*/
|
|
8274
|
+
#invokeHandler(handler) {
|
|
8275
|
+
if (typeof handler.filter === 'function') {
|
|
8276
|
+
try {
|
|
8277
|
+
if (!handler.filter()) return;
|
|
8278
|
+
} catch (err) {
|
|
8279
|
+
console.warn('[TinyDomReadyManager] Filter error:', err);
|
|
8280
|
+
return;
|
|
8281
|
+
}
|
|
8282
|
+
}
|
|
8283
|
+
|
|
8284
|
+
try {
|
|
8285
|
+
handler.fn();
|
|
8286
|
+
} catch (err) {
|
|
8287
|
+
console.error('[TinyDomReadyManager] Handler error:', err);
|
|
8288
|
+
}
|
|
8289
|
+
}
|
|
8290
|
+
|
|
8291
|
+
/**
|
|
8292
|
+
* Marks the system as DOM-ready and runs DOM-only handlers.
|
|
8293
|
+
* @private
|
|
8294
|
+
*/
|
|
8295
|
+
_markDomReady() {
|
|
8296
|
+
this.#isDomReady = true;
|
|
8297
|
+
this.#runHandlers(true); // Run domOnly
|
|
8298
|
+
this.#checkAllReady(); // Then check for full readiness
|
|
8299
|
+
}
|
|
8300
|
+
|
|
8301
|
+
/**
|
|
8302
|
+
* Initializes the manager using `DOMContentLoaded`.
|
|
8303
|
+
*/
|
|
8304
|
+
init() {
|
|
8305
|
+
if (this.#isDomReady) throw new Error('[TinyDomReadyManager] init() has already been called.');
|
|
8306
|
+
|
|
8307
|
+
if (document.readyState === 'interactive' || document.readyState === 'complete') {
|
|
8308
|
+
this._markDomReady();
|
|
8309
|
+
} else {
|
|
8310
|
+
document.addEventListener('DOMContentLoaded', () => this._markDomReady());
|
|
8311
|
+
}
|
|
8312
|
+
}
|
|
8313
|
+
|
|
8314
|
+
/**
|
|
8315
|
+
* Adds a Promise to delay full readiness.
|
|
8316
|
+
* @param {Promise<any>} promise
|
|
8317
|
+
* @throws {TypeError}
|
|
8318
|
+
*/
|
|
8319
|
+
addPromise(promise) {
|
|
8320
|
+
if (!(promise instanceof Promise))
|
|
8321
|
+
throw new TypeError('[TinyDomReadyManager] promise must be a valid Promise.');
|
|
8322
|
+
|
|
8323
|
+
if (this.#isFullyReady) return;
|
|
8324
|
+
this.#promises.push(promise);
|
|
8325
|
+
if (this.#isDomReady) this.#checkAllReady();
|
|
8326
|
+
}
|
|
8327
|
+
|
|
8328
|
+
/**
|
|
8329
|
+
* Registers a handler to run either after DOM is ready or after full readiness.
|
|
8330
|
+
*
|
|
8331
|
+
* @param {Fn} fn - Function to execute.
|
|
8332
|
+
* @param {Object} [options]
|
|
8333
|
+
* @param {boolean} [options.once=true] - Execute only once.
|
|
8334
|
+
* @param {number} [options.priority=0] - Higher priority runs first.
|
|
8335
|
+
* @param {FnFilter|null} [options.filter=null] - Optional filter function.
|
|
8336
|
+
* @param {boolean} [options.domOnly=false] - If true, executes after DOM ready only.
|
|
8337
|
+
* @throws {TypeError} If fn is not a function.
|
|
8338
|
+
*/
|
|
8339
|
+
onReady(fn, { once = true, priority = 0, filter = null, domOnly = false } = {}) {
|
|
8340
|
+
if (typeof fn !== 'function')
|
|
8341
|
+
throw new TypeError('[TinyDomReadyManager] fn must be a function.');
|
|
8342
|
+
|
|
8343
|
+
const handler = { fn, once, priority, filter, domOnly };
|
|
8344
|
+
|
|
8345
|
+
if (domOnly && this.#isDomReady) {
|
|
8346
|
+
this.#invokeHandler(handler);
|
|
8347
|
+
if (!once) this.#handlers.push(handler);
|
|
8348
|
+
return;
|
|
8349
|
+
}
|
|
8350
|
+
|
|
8351
|
+
if (!domOnly && this.#isFullyReady) {
|
|
8352
|
+
this.#invokeHandler(handler);
|
|
8353
|
+
} else {
|
|
8354
|
+
this.#handlers.push(handler);
|
|
8355
|
+
}
|
|
8356
|
+
}
|
|
8357
|
+
|
|
8358
|
+
/**
|
|
8359
|
+
* Returns whether the system is fully ready (DOM + Promises).
|
|
8360
|
+
* @returns {boolean}
|
|
8361
|
+
*/
|
|
8362
|
+
isReady() {
|
|
8363
|
+
return this.#isFullyReady;
|
|
8364
|
+
}
|
|
8365
|
+
|
|
8366
|
+
/**
|
|
8367
|
+
* Returns whether the DOM is ready (DOMContentLoaded has fired).
|
|
8368
|
+
* Does not wait for promises.
|
|
8369
|
+
* @returns {boolean}
|
|
8370
|
+
*/
|
|
8371
|
+
isDomReady() {
|
|
8372
|
+
return this.#isDomReady;
|
|
8373
|
+
}
|
|
8374
|
+
}
|
|
8375
|
+
|
|
8376
|
+
/* harmony default export */ const libs_TinyDomReadyManager = (TinyDomReadyManager);
|
|
8377
|
+
|
|
8017
8378
|
;// ./src/v1/index.mjs
|
|
8018
8379
|
|
|
8019
8380
|
|
|
@@ -8030,6 +8391,11 @@ class TinyDragger {
|
|
|
8030
8391
|
|
|
8031
8392
|
|
|
8032
8393
|
|
|
8394
|
+
|
|
8395
|
+
|
|
8396
|
+
|
|
8397
|
+
|
|
8398
|
+
|
|
8033
8399
|
|
|
8034
8400
|
|
|
8035
8401
|
|