@design-edito/tools 0.0.33 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- package/agnostic/arrays/index.d.ts +11 -0
- package/{utils/agnostic → agnostic/arrays}/is-array-of/index.d.ts +2 -2
- package/agnostic/arrays/is-array-of/index.js +23 -0
- package/agnostic/async/index.d.ts +8 -0
- package/agnostic/async/index.js +20 -0
- package/agnostic/async/timeout-call/index.d.ts +1 -0
- package/agnostic/async/timeout-call/index.js +6 -0
- package/agnostic/async/transitions/index.d.ts +41 -0
- package/agnostic/async/transitions/index.js +7 -0
- package/agnostic/async/wait/index.d.ts +1 -0
- package/agnostic/async/wait/index.js +6 -0
- package/agnostic/booleans/index.d.ts +8 -0
- package/agnostic/booleans/index.js +17 -0
- package/{utils/agnostic → agnostic/booleans}/is-falsy/index.d.ts +1 -2
- package/agnostic/booleans/is-falsy/index.js +11 -0
- package/agnostic/css/bem/index.d.ts +7 -0
- package/agnostic/css/bem/index.js +9 -0
- package/{utils/agnostic → agnostic/css}/generate-nice-color/index.d.ts +0 -1
- package/agnostic/css/generate-nice-color/index.js +8 -0
- package/agnostic/css/index.d.ts +14 -0
- package/agnostic/css/index.js +177 -0
- package/agnostic/css/is-valid-css-class-name/index.d.ts +2 -0
- package/agnostic/css/is-valid-css-class-name/index.js +8 -0
- package/agnostic/css/styles-set/index.d.ts +37 -0
- package/agnostic/errors/index.d.ts +30 -0
- package/agnostic/errors/index.js +6 -0
- package/agnostic/html/get-node-ancestors/index.d.ts +1 -0
- package/agnostic/html/get-node-ancestors/index.js +6 -0
- package/agnostic/html/get-position-inside-parent/index.d.ts +1 -0
- package/agnostic/html/get-position-inside-parent/index.js +6 -0
- package/agnostic/html/index.d.ts +17 -0
- package/agnostic/html/index.js +39 -0
- package/agnostic/html/insert-node/index.d.ts +2 -0
- package/agnostic/html/insert-node/index.js +6 -0
- package/agnostic/html/placeholders/index.d.ts +9 -0
- package/agnostic/html/placeholders/index.js +6 -0
- package/agnostic/html/sanitize/index.d.ts +24 -0
- package/agnostic/html/sanitize/index.js +9 -0
- package/agnostic/html/selector-to-element/index.d.ts +1 -0
- package/agnostic/html/selector-to-element/index.js +9 -0
- package/agnostic/html/string-to-nodes/index.d.ts +7 -0
- package/agnostic/html/string-to-nodes/index.js +10 -0
- package/agnostic/index.d.ts +26 -0
- package/agnostic/misc/assert/index.d.ts +5 -0
- package/agnostic/misc/assert/index.js +6 -0
- package/agnostic/misc/cast/index.d.ts +9 -0
- package/agnostic/misc/cast/index.js +8 -0
- package/agnostic/misc/crossenv/index.d.ts +13 -0
- package/agnostic/misc/crossenv/index.js +6 -0
- package/agnostic/misc/get-current-downlink/index.d.ts +1 -0
- package/agnostic/misc/get-current-downlink/index.js +6 -0
- package/agnostic/misc/index.d.ts +22 -0
- package/agnostic/misc/index.js +45 -0
- package/{utils/agnostic → agnostic/misc}/is-constructor-function/index.d.ts +1 -1
- package/agnostic/misc/is-constructor-function/index.js +6 -0
- package/{utils/agnostic → agnostic/misc}/is-nullish/index.d.ts +0 -1
- package/agnostic/misc/is-nullish/index.js +10 -0
- package/agnostic/misc/logs/index.d.ts +55 -0
- package/agnostic/misc/logs/index.js +6 -0
- package/agnostic/misc/random/index.d.ts +10 -0
- package/agnostic/misc/random/index.js +6 -0
- package/agnostic/numbers/absolute-modulo/index.d.ts +1 -0
- package/agnostic/numbers/absolute-modulo/index.js +6 -0
- package/agnostic/numbers/clamp/index.d.ts +1 -0
- package/agnostic/numbers/clamp/index.js +6 -0
- package/agnostic/numbers/index.d.ts +13 -0
- package/agnostic/numbers/index.js +30 -0
- package/agnostic/numbers/interpolate/index.d.ts +1 -0
- package/agnostic/numbers/interpolate/index.js +6 -0
- package/agnostic/numbers/responsive-harmonics/index.js +9 -0
- package/agnostic/numbers/round/index.d.ts +1 -0
- package/agnostic/numbers/round/index.js +6 -0
- package/agnostic/objects/enums/index.d.ts +4 -0
- package/agnostic/objects/enums/index.js +7 -0
- package/{utils/agnostic → agnostic/objects/enums}/is-in-enum/index.d.ts +1 -1
- package/agnostic/objects/enums/is-in-enum/index.js +6 -0
- package/agnostic/objects/flatten-getters/index.d.ts +1 -0
- package/agnostic/objects/flatten-getters/index.js +9 -0
- package/agnostic/objects/index.d.ts +12 -0
- package/agnostic/objects/index.js +32 -0
- package/agnostic/objects/is-object/index.d.ts +1 -0
- package/agnostic/objects/is-object/index.js +6 -0
- package/agnostic/objects/is-record/index.d.ts +1 -0
- package/agnostic/objects/is-record/index.js +6 -0
- package/agnostic/objects/record-format/index.js +16 -0
- package/agnostic/objects/validation/index.d.ts +3 -0
- package/agnostic/objects/validation/index.js +6 -0
- package/agnostic/optim/index.d.ts +7 -0
- package/agnostic/optim/index.js +18 -0
- package/{utils/agnostic → agnostic/optim}/memoize/index.d.ts +1 -1
- package/agnostic/optim/memoize/index.js +6 -0
- package/agnostic/optim/throttle-debounce/index.js +8 -0
- package/{utils/agnostic → agnostic/optim}/throttle-debounce/types.d.ts +0 -1
- package/agnostic/regexps/index.d.ts +23 -0
- package/agnostic/regexps/index.js +89 -0
- package/agnostic/strings/char-codes/index.d.ts +17 -0
- package/agnostic/strings/char-codes/index.js +6 -0
- package/agnostic/strings/index.d.ts +14 -0
- package/agnostic/strings/index.js +32 -0
- package/agnostic/strings/matches/index.d.ts +3 -0
- package/agnostic/strings/matches/index.js +10 -0
- package/agnostic/strings/normalize-indent/index.d.ts +1 -0
- package/agnostic/strings/normalize-indent/index.js +6 -0
- package/{utils/agnostic → agnostic/strings}/replace-all/index.d.ts +1 -1
- package/agnostic/strings/replace-all/index.js +6 -0
- package/agnostic/strings/to-alphanum/index.d.ts +1 -0
- package/agnostic/strings/to-alphanum/index.js +6 -0
- package/chunks/chunk-32IRF4OP.js +9 -0
- package/chunks/chunk-34U4HX4V.js +73 -0
- package/chunks/chunk-4GDNHUCZ.js +162 -0
- package/chunks/chunk-4QQBKBYH.js +59 -0
- package/chunks/chunk-4VC5PT5T.js +13 -0
- package/chunks/chunk-5LNUCDQ6.js +132 -0
- package/chunks/chunk-7AWTHZLY.js +12 -0
- package/chunks/chunk-7DBNMU6N.js +14 -0
- package/chunks/chunk-COVPTTAD.js +10 -0
- package/chunks/chunk-DNIOWD7K.js +8 -0
- package/chunks/chunk-DQNJQBC6.js +10 -0
- package/chunks/chunk-E6MSDKON.js +13 -0
- package/chunks/chunk-EDVNAV3G.js +72 -0
- package/chunks/chunk-EW46EXFB.js +8 -0
- package/chunks/chunk-FPEW3A27.js +14 -0
- package/chunks/chunk-GJOU3UAL.js +36 -0
- package/chunks/chunk-HC6ZOHCS.js +14 -0
- package/chunks/chunk-HGCG2J77.js +122 -0
- package/chunks/chunk-IFD7GSGK.js +130 -0
- package/chunks/chunk-JQXNEJAP.js +18 -0
- package/chunks/chunk-JWBDZPQG.js +18 -0
- package/chunks/chunk-K37RALUX.js +8 -0
- package/chunks/chunk-KIONYWA7.js +168 -0
- package/chunks/chunk-KQT5CTGF.js +21 -0
- package/chunks/chunk-LEXQ6E6L.js +31 -0
- package/chunks/chunk-LQFKUNVQ.js +19 -0
- package/chunks/chunk-MF56TTC5.js +15 -0
- package/chunks/chunk-MT74WIQR.js +41 -0
- package/chunks/chunk-NRITRUZW.js +10 -0
- package/chunks/chunk-NRJQKVQV.js +31 -0
- package/chunks/chunk-OSAXBA7G.js +10 -0
- package/chunks/chunk-PO3V3I57.js +23 -0
- package/chunks/chunk-QXAJXTXV.js +19 -0
- package/chunks/chunk-RCO57B6F.js +9 -0
- package/chunks/chunk-SQZGZ3VT.js +15 -0
- package/chunks/chunk-UYTXXUU7.js +54 -0
- package/chunks/chunk-VTPRO4NJ.js +10 -0
- package/chunks/chunk-VYW4IADX.js +35 -0
- package/chunks/chunk-VZDUZTW6.js +113 -0
- package/chunks/chunk-W5A2TON3.js +10 -0
- package/chunks/chunk-W7YBGJ4H.js +28 -0
- package/chunks/chunk-WLL3FNVL.js +40 -0
- package/chunks/chunk-WOAYU6LB.js +13 -0
- package/chunks/chunk-XA4HVHJ4.js +18 -0
- package/chunks/chunk-XN3PZIVL.js +38 -0
- package/chunks/chunk-YDIBNEGA.js +9 -0
- package/components/index.d.ts +4 -0
- package/index.d.ts +3 -0
- package/node/files/index.d.ts +9 -0
- package/node/files/index.js +21 -0
- package/node/files/is-in-directory/index.d.ts +1 -0
- package/node/files/is-in-directory/index.js +6 -0
- package/node/files/read-write/index.d.ts +9 -0
- package/node/files/read-write/index.js +6 -0
- package/node/files/subpaths/index.d.ts +34 -0
- package/node/files/subpaths/index.js +7 -0
- package/node/index.d.ts +6 -0
- package/node/process/index.d.ts +8 -0
- package/node/process/index.js +20 -0
- package/{utils/node/process-exit → node/process/on-exit}/index.d.ts +1 -1
- package/node/process/on-exit/index.js +14 -0
- package/package.json +12 -12
- package/shared/errors/index.d.ts +14 -0
- package/shared/index.d.ts +0 -0
- package/chunks/chunk-BEZTX3QU.js +0 -1
- package/chunks/chunk-BW5CY5YB.js +0 -1
- package/chunks/chunk-DIPJ73JH.js +0 -1
- package/chunks/chunk-EFFU6KXJ.js +0 -1
- package/chunks/chunk-KNE7WIIW.js +0 -1
- package/chunks/chunk-LCLAV6Q2.js +0 -1
- package/chunks/chunk-PCAKH6ZJ.js +0 -1
- package/chunks/chunk-QQRJPDR7.js +0 -1
- package/chunks/chunk-WZBNXYN3.js +0 -1
- package/chunks/chunk-XCKXCF4A.js +0 -1
- package/chunks/chunk-ZVJO36JU.js +0 -1
- package/components/Comp/index.js +0 -1
- package/index.js +0 -96
- package/utils/agnostic/absolute-modulo/index.d.ts +0 -1
- package/utils/agnostic/absolute-modulo/index.js +0 -1
- package/utils/agnostic/array/index.d.ts +0 -7
- package/utils/agnostic/array/index.js +0 -1
- package/utils/agnostic/assert/index.d.ts +0 -3
- package/utils/agnostic/assert/index.js +0 -1
- package/utils/agnostic/await-timeout/index.d.ts +0 -2
- package/utils/agnostic/await-timeout/index.js +0 -1
- package/utils/agnostic/bem/index.d.ts +0 -5
- package/utils/agnostic/bem/index.js +0 -1
- package/utils/agnostic/cast/index.d.ts +0 -7
- package/utils/agnostic/cast/index.js +0 -1
- package/utils/agnostic/charcode-string/index.d.ts +0 -2
- package/utils/agnostic/charcode-string/index.js +0 -1
- package/utils/agnostic/clamp/index.d.ts +0 -1
- package/utils/agnostic/clamp/index.js +0 -1
- package/utils/agnostic/clientside-html-sanitizer/index.d.ts +0 -22
- package/utils/agnostic/clientside-html-sanitizer/index.js +0 -1
- package/utils/agnostic/crossenv/index.d.ts +0 -11
- package/utils/agnostic/crossenv/index.js +0 -1
- package/utils/agnostic/flatten-getters/index.d.ts +0 -1
- package/utils/agnostic/flatten-getters/index.js +0 -1
- package/utils/agnostic/generate-html-placeholders/index.d.ts +0 -7
- package/utils/agnostic/generate-html-placeholders/index.js +0 -5
- package/utils/agnostic/generate-nice-color/index.js +0 -1
- package/utils/agnostic/insert-node/index.d.ts +0 -2
- package/utils/agnostic/insert-node/index.js +0 -1
- package/utils/agnostic/interpolate/index.d.ts +0 -3
- package/utils/agnostic/interpolate/index.js +0 -1
- package/utils/agnostic/is-array-of/index.js +0 -1
- package/utils/agnostic/is-constructor-function/index.js +0 -1
- package/utils/agnostic/is-falsy/index.js +0 -1
- package/utils/agnostic/is-in-enum/index.js +0 -1
- package/utils/agnostic/is-nullish/index.js +0 -1
- package/utils/agnostic/is-object/index.d.ts +0 -1
- package/utils/agnostic/is-object/index.js +0 -1
- package/utils/agnostic/is-record/index.d.ts +0 -1
- package/utils/agnostic/is-record/index.js +0 -1
- package/utils/agnostic/is-valid-css-class-name/index.d.ts +0 -2
- package/utils/agnostic/is-valid-css-class-name/index.js +0 -1
- package/utils/agnostic/memoize/index.js +0 -1
- package/utils/agnostic/object-validate-from-partial/index.d.ts +0 -1
- package/utils/agnostic/object-validate-from-partial/index.js +0 -1
- package/utils/agnostic/random/index.d.ts +0 -9
- package/utils/agnostic/random/index.js +0 -1
- package/utils/agnostic/record-format/index.js +0 -1
- package/utils/agnostic/regexp/index.d.ts +0 -21
- package/utils/agnostic/regexp/index.js +0 -1
- package/utils/agnostic/replace-all/index.js +0 -1
- package/utils/agnostic/responsive-harmonics/index.js +0 -1
- package/utils/agnostic/round-numbers/index.d.ts +0 -1
- package/utils/agnostic/round-numbers/index.js +0 -1
- package/utils/agnostic/selector-to-element/index.d.ts +0 -1
- package/utils/agnostic/selector-to-element/index.js +0 -1
- package/utils/agnostic/silent-log/index.d.ts +0 -53
- package/utils/agnostic/silent-log/index.js +0 -9
- package/utils/agnostic/str-to-nodes/index.d.ts +0 -7
- package/utils/agnostic/str-to-nodes/index.js +0 -1
- package/utils/agnostic/string-matches/index.d.ts +0 -4
- package/utils/agnostic/string-matches/index.js +0 -1
- package/utils/agnostic/string-normalize-indent/index.d.ts +0 -1
- package/utils/agnostic/string-normalize-indent/index.js +0 -3
- package/utils/agnostic/throttle-debounce/index.js +0 -1
- package/utils/agnostic/to-alphanum/index.d.ts +0 -1
- package/utils/agnostic/to-alphanum/index.js +0 -1
- package/utils/agnostic/transition/index.d.ts +0 -39
- package/utils/agnostic/transition/index.js +0 -1
- package/utils/agnostic/wait/index.d.ts +0 -1
- package/utils/agnostic/wait/index.js +0 -1
- package/utils/browser/dynamic-css/index.d.ts +0 -4
- package/utils/browser/dynamic-css/index.js +0 -2
- package/utils/browser/get-current-downlink/index.d.ts +0 -1
- package/utils/browser/get-current-downlink/index.js +0 -1
- package/utils/browser/get-node-ancestors/index.d.ts +0 -1
- package/utils/browser/get-node-ancestors/index.js +0 -1
- package/utils/node/is-in-directory/index.d.ts +0 -1
- package/utils/node/is-in-directory/index.js +0 -1
- package/utils/node/list-subpaths/index.d.ts +0 -33
- package/utils/node/list-subpaths/index.js +0 -1
- package/utils/node/process-exit/index.js +0 -1
- package/utils/node/read-write-file/index.d.ts +0 -12
- package/utils/node/read-write-file/index.js +0 -1
- /package/{utils/agnostic → agnostic/css}/bem/BEM.d.ts +0 -0
- /package/{utils/agnostic → agnostic/css}/bem/getNamesArr.d.ts +0 -0
- /package/{utils/agnostic → agnostic/numbers}/responsive-harmonics/index.d.ts +0 -0
- /package/{utils/agnostic → agnostic/objects}/record-format/index.d.ts +0 -0
- /package/{utils/agnostic → agnostic/optim}/throttle-debounce/index.d.ts +0 -0
@@ -0,0 +1,168 @@
|
|
1
|
+
import {
|
2
|
+
isValidClassName
|
3
|
+
} from "./chunk-W5A2TON3.js";
|
4
|
+
import {
|
5
|
+
isFalsy
|
6
|
+
} from "./chunk-QXAJXTXV.js";
|
7
|
+
|
8
|
+
// src/agnostic/css/bem/getNamesArr.ts
|
9
|
+
function getNamesArr(arg) {
|
10
|
+
const returned = [];
|
11
|
+
if (typeof arg === "string") {
|
12
|
+
arg.trim().split(/\s+/gm).forEach((name) => {
|
13
|
+
if (isValidClassName(name)) returned.push(name);
|
14
|
+
});
|
15
|
+
} else if (Array.isArray(arg)) {
|
16
|
+
arg.forEach((elt) => returned.push(...getNamesArr(elt)));
|
17
|
+
} else if (typeof arg === "object" && arg !== null) {
|
18
|
+
Object.entries(arg).forEach(([key, val]) => {
|
19
|
+
if (!isFalsy(val)) returned.push(...getNamesArr(key));
|
20
|
+
});
|
21
|
+
}
|
22
|
+
return returned;
|
23
|
+
}
|
24
|
+
var getNamesArr_default = getNamesArr;
|
25
|
+
|
26
|
+
// src/agnostic/css/bem/BEM.ts
|
27
|
+
var BEM = class _BEM {
|
28
|
+
constructor() {
|
29
|
+
this.findBlockByName = this.findBlockByName.bind(this);
|
30
|
+
this.addBlock = this.addBlock.bind(this);
|
31
|
+
this.addElement = this.addElement.bind(this);
|
32
|
+
this.addModifier = this.addModifier.bind(this);
|
33
|
+
this.copy = this.copy.bind(this);
|
34
|
+
this.block = this.block.bind(this);
|
35
|
+
this.element = this.element.bind(this);
|
36
|
+
this.modifier = this.modifier.bind(this);
|
37
|
+
this.blk = this.blk.bind(this);
|
38
|
+
this.elt = this.elt.bind(this);
|
39
|
+
this.mod = this.mod.bind(this);
|
40
|
+
this.cp = this.cp.bind(this);
|
41
|
+
this.addSingleBlock = this.addSingleBlock.bind(this);
|
42
|
+
this.addSingleElement = this.addSingleElement.bind(this);
|
43
|
+
this.addSingleModifier = this.addSingleModifier.bind(this);
|
44
|
+
this.setCurrentBlockByName = this.setCurrentBlockByName.bind(this);
|
45
|
+
this.createBlockByName = this.createBlockByName.bind(this);
|
46
|
+
this.getCurrentBlock = this.getCurrentBlock.bind(this);
|
47
|
+
}
|
48
|
+
addBlock(blockNameArg) {
|
49
|
+
const blocksNames = getNamesArr_default(blockNameArg);
|
50
|
+
blocksNames.forEach(this.addSingleBlock);
|
51
|
+
return this;
|
52
|
+
}
|
53
|
+
addElement(elementNameArg) {
|
54
|
+
const elementsNames = getNamesArr_default(elementNameArg);
|
55
|
+
elementsNames.forEach(this.addSingleElement);
|
56
|
+
return this;
|
57
|
+
}
|
58
|
+
addModifier(modifierNameArg) {
|
59
|
+
const currentBlock = this.getCurrentBlock();
|
60
|
+
if (currentBlock === void 0) return this;
|
61
|
+
const modifiersNames = getNamesArr_default(modifierNameArg);
|
62
|
+
modifiersNames.forEach(this.addSingleModifier);
|
63
|
+
return this;
|
64
|
+
}
|
65
|
+
copy() {
|
66
|
+
const copy = new _BEM();
|
67
|
+
this.blocks.forEach((block) => {
|
68
|
+
copy.addBlock(block.name);
|
69
|
+
block.modifiers.forEach(copy.addModifier);
|
70
|
+
});
|
71
|
+
return copy;
|
72
|
+
}
|
73
|
+
block(blockNameArg) {
|
74
|
+
return this.copy().addBlock(blockNameArg);
|
75
|
+
}
|
76
|
+
element(elementNameArg) {
|
77
|
+
return this.copy().addElement(elementNameArg);
|
78
|
+
}
|
79
|
+
modifier(modifierNameArg) {
|
80
|
+
return this.copy().addModifier(modifierNameArg);
|
81
|
+
}
|
82
|
+
blk(blockNameArg) {
|
83
|
+
return this.block(blockNameArg);
|
84
|
+
}
|
85
|
+
elt(elementNameArg) {
|
86
|
+
return this.element(elementNameArg);
|
87
|
+
}
|
88
|
+
mod(modifierNameArg) {
|
89
|
+
return this.modifier(modifierNameArg);
|
90
|
+
}
|
91
|
+
cp() {
|
92
|
+
return this.copy();
|
93
|
+
}
|
94
|
+
get value() {
|
95
|
+
return this.blocks.map((block) => {
|
96
|
+
return [block.name, ...block.modifiers.map((modifier) => {
|
97
|
+
return `${block.name}_${modifier}`;
|
98
|
+
})].join(" ");
|
99
|
+
}).join(" ");
|
100
|
+
}
|
101
|
+
get val() {
|
102
|
+
return this.value;
|
103
|
+
}
|
104
|
+
blocks = [];
|
105
|
+
findBlockByName(name) {
|
106
|
+
return this.blocks.find((block) => block.name === name);
|
107
|
+
}
|
108
|
+
addSingleBlock(blockName) {
|
109
|
+
if (this.findBlockByName(blockName) !== void 0) {
|
110
|
+
this.setCurrentBlockByName(blockName);
|
111
|
+
} else {
|
112
|
+
const block = this.createBlockByName(blockName);
|
113
|
+
this.blocks.push(block);
|
114
|
+
}
|
115
|
+
return this;
|
116
|
+
}
|
117
|
+
addSingleElement(elementName) {
|
118
|
+
const currentBlock = this.getCurrentBlock();
|
119
|
+
if (currentBlock === void 0) this.addBlock(elementName);
|
120
|
+
else {
|
121
|
+
currentBlock.name = currentBlock.name + "__" + elementName;
|
122
|
+
}
|
123
|
+
return this;
|
124
|
+
}
|
125
|
+
addSingleModifier(modifierName) {
|
126
|
+
const currentBlock = this.getCurrentBlock();
|
127
|
+
if (currentBlock !== void 0) {
|
128
|
+
currentBlock.modifiers.push(modifierName);
|
129
|
+
}
|
130
|
+
return this;
|
131
|
+
}
|
132
|
+
setCurrentBlockByName(blockName) {
|
133
|
+
const block = this.findBlockByName(blockName);
|
134
|
+
if (block !== void 0) {
|
135
|
+
const blockPos = this.blocks.indexOf(block);
|
136
|
+
this.blocks = [
|
137
|
+
...this.blocks.slice(0, blockPos),
|
138
|
+
...this.blocks.slice(blockPos + 1),
|
139
|
+
block
|
140
|
+
];
|
141
|
+
}
|
142
|
+
return this;
|
143
|
+
}
|
144
|
+
createBlockByName(blockName) {
|
145
|
+
return { name: blockName, modifiers: [] };
|
146
|
+
}
|
147
|
+
getCurrentBlock() {
|
148
|
+
return this.blocks.slice(-1)[0];
|
149
|
+
}
|
150
|
+
};
|
151
|
+
var BEM_default = BEM;
|
152
|
+
|
153
|
+
// src/agnostic/css/bem/index.ts
|
154
|
+
var Bem;
|
155
|
+
((Bem2) => {
|
156
|
+
Bem2.BEM = BEM_default;
|
157
|
+
function bem(blockNameArg) {
|
158
|
+
const bem2 = new BEM_default();
|
159
|
+
if (blockNameArg instanceof BEM_default) return blockNameArg.copy();
|
160
|
+
return bem2.addBlock(blockNameArg);
|
161
|
+
}
|
162
|
+
Bem2.bem = bem;
|
163
|
+
Bem2.getNamesArr = getNamesArr_default;
|
164
|
+
})(Bem || (Bem = {}));
|
165
|
+
|
166
|
+
export {
|
167
|
+
Bem
|
168
|
+
};
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import {
|
2
|
+
Crossenv
|
3
|
+
} from "./chunk-GJOU3UAL.js";
|
4
|
+
import {
|
5
|
+
Errors
|
6
|
+
} from "./chunk-MT74WIQR.js";
|
7
|
+
|
8
|
+
// src/shared/errors/index.ts
|
9
|
+
var register = new Errors.Register({
|
10
|
+
["no-window-document-on-runtime" /* NO_DOCUMENT */]: {
|
11
|
+
message: `Runtime '${Crossenv.detectRuntime()}' does not provide a Document object, cannot complete.`
|
12
|
+
},
|
13
|
+
["no-window-document-on-runtime-please-provide" /* NO_DOCUMENT_PLEASE_PROVIDE */]: {
|
14
|
+
message: `Please provide a Document object since none are found on runtime '${Crossenv.detectRuntime()}'`,
|
15
|
+
makeDetails: (tips) => tips
|
16
|
+
}
|
17
|
+
});
|
18
|
+
|
19
|
+
export {
|
20
|
+
register
|
21
|
+
};
|
@@ -0,0 +1,31 @@
|
|
1
|
+
// src/node/process/on-exit/index.ts
|
2
|
+
var forceExitEvents = ["SIGINT", "SIGTERM", "uncaughtException"];
|
3
|
+
function beforeForcedExit(callback) {
|
4
|
+
forceExitEvents.forEach((ev) => process.on(ev, callback));
|
5
|
+
}
|
6
|
+
function beforeExit(callback) {
|
7
|
+
process.on("beforeExit", callback);
|
8
|
+
}
|
9
|
+
function onExit(callback) {
|
10
|
+
process.on("exit", callback);
|
11
|
+
}
|
12
|
+
function onAllExits(callback) {
|
13
|
+
let alreadyCalled = false;
|
14
|
+
const actualCallback = () => {
|
15
|
+
if (!alreadyCalled) {
|
16
|
+
alreadyCalled = true;
|
17
|
+
callback();
|
18
|
+
}
|
19
|
+
};
|
20
|
+
beforeForcedExit(actualCallback);
|
21
|
+
beforeExit(actualCallback);
|
22
|
+
onExit(actualCallback);
|
23
|
+
}
|
24
|
+
|
25
|
+
export {
|
26
|
+
forceExitEvents,
|
27
|
+
beforeForcedExit,
|
28
|
+
beforeExit,
|
29
|
+
onExit,
|
30
|
+
onAllExits
|
31
|
+
};
|
@@ -0,0 +1,19 @@
|
|
1
|
+
// src/agnostic/strings/matches/index.ts
|
2
|
+
function matches(input, matcher) {
|
3
|
+
if (typeof matcher === "string") return input === matcher;
|
4
|
+
return input.match(matcher) !== null;
|
5
|
+
}
|
6
|
+
function matchesSome(input, matchers) {
|
7
|
+
if (!Array.isArray(matchers)) return matches(input, matchers);
|
8
|
+
return matchers.some((matcher) => matches(input, matcher));
|
9
|
+
}
|
10
|
+
function matchesEvery(input, matchers) {
|
11
|
+
if (!Array.isArray(matchers)) return matches(input, matchers);
|
12
|
+
return matchers.every((matcher) => matches(input, matcher));
|
13
|
+
}
|
14
|
+
|
15
|
+
export {
|
16
|
+
matches,
|
17
|
+
matchesSome,
|
18
|
+
matchesEvery
|
19
|
+
};
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// src/agnostic/strings/replace-all/index.ts
|
2
|
+
function replaceAll(input, pattern, replacer, maxOps = 1e3) {
|
3
|
+
let output = input;
|
4
|
+
let opsCnt = 0;
|
5
|
+
while (output.match(pattern) && opsCnt < maxOps) {
|
6
|
+
opsCnt++;
|
7
|
+
if (typeof replacer === "function") output = output.replace(pattern, replacer);
|
8
|
+
else output = output.replace(pattern, replacer);
|
9
|
+
}
|
10
|
+
return output;
|
11
|
+
}
|
12
|
+
|
13
|
+
export {
|
14
|
+
replaceAll
|
15
|
+
};
|
@@ -0,0 +1,41 @@
|
|
1
|
+
// src/agnostic/errors/index.ts
|
2
|
+
var Errors;
|
3
|
+
((Errors2) => {
|
4
|
+
class CustomError extends Error {
|
5
|
+
code;
|
6
|
+
details;
|
7
|
+
constructor(data) {
|
8
|
+
const { code, message, details } = data;
|
9
|
+
super(message);
|
10
|
+
this.code = code;
|
11
|
+
this.details = details;
|
12
|
+
}
|
13
|
+
}
|
14
|
+
Errors2.CustomError = CustomError;
|
15
|
+
class Register {
|
16
|
+
_source;
|
17
|
+
constructor(source) {
|
18
|
+
this._source = source;
|
19
|
+
}
|
20
|
+
getFactory(code) {
|
21
|
+
return this._source[code];
|
22
|
+
}
|
23
|
+
getData(code, ...params) {
|
24
|
+
const core = this.getFactory(code);
|
25
|
+
const { message, makeDetails } = core;
|
26
|
+
return {
|
27
|
+
code,
|
28
|
+
message,
|
29
|
+
details: makeDetails?.(...params)
|
30
|
+
};
|
31
|
+
}
|
32
|
+
getError(code, ...params) {
|
33
|
+
return new CustomError(this.getData(code, ...params));
|
34
|
+
}
|
35
|
+
}
|
36
|
+
Errors2.Register = Register;
|
37
|
+
})(Errors || (Errors = {}));
|
38
|
+
|
39
|
+
export {
|
40
|
+
Errors
|
41
|
+
};
|
@@ -0,0 +1,10 @@
|
|
1
|
+
// src/node/files/is-in-directory/index.ts
|
2
|
+
import path from "node:path";
|
3
|
+
function isInDirectory(childPath, parentPath) {
|
4
|
+
const rel = path.relative(parentPath, childPath);
|
5
|
+
return rel !== "" && !rel.startsWith("..");
|
6
|
+
}
|
7
|
+
|
8
|
+
export {
|
9
|
+
isInDirectory
|
10
|
+
};
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import {
|
2
|
+
Sanitize
|
3
|
+
} from "./chunk-IFD7GSGK.js";
|
4
|
+
import {
|
5
|
+
register
|
6
|
+
} from "./chunk-KQT5CTGF.js";
|
7
|
+
import {
|
8
|
+
Crossenv
|
9
|
+
} from "./chunk-GJOU3UAL.js";
|
10
|
+
|
11
|
+
// src/agnostic/html/string-to-nodes/index.ts
|
12
|
+
function stringToNodes(dirtyStr, options) {
|
13
|
+
const actualDocument = options?.documentObj ?? Crossenv.getDocument();
|
14
|
+
if (actualDocument === null) throw register.getError("no-window-document-on-runtime-please-provide" /* NO_DOCUMENT_PLEASE_PROVIDE */, "See documentObj in the options object");
|
15
|
+
const sanitizeOptions = {
|
16
|
+
...options?.sanitize,
|
17
|
+
documentObj: options?.sanitize?.documentObj ?? options?.documentObj
|
18
|
+
};
|
19
|
+
const str = options?.sanitize !== void 0 ? Sanitize.sanitize(dirtyStr, sanitizeOptions) : dirtyStr;
|
20
|
+
const wrapperDiv = actualDocument.createElement("div");
|
21
|
+
wrapperDiv.innerHTML = str;
|
22
|
+
const nodes = Array.from(wrapperDiv.childNodes).filter((node) => {
|
23
|
+
const allowedNodeTypes = [Node.ELEMENT_NODE, Node.TEXT_NODE];
|
24
|
+
return allowedNodeTypes.includes(node.nodeType);
|
25
|
+
});
|
26
|
+
return nodes;
|
27
|
+
}
|
28
|
+
|
29
|
+
export {
|
30
|
+
stringToNodes
|
31
|
+
};
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import {
|
2
|
+
Cast
|
3
|
+
} from "./chunk-4QQBKBYH.js";
|
4
|
+
|
5
|
+
// src/agnostic/objects/flatten-getters/index.ts
|
6
|
+
function flattenGetters(obj) {
|
7
|
+
try {
|
8
|
+
const { entries, getOwnPropertyDescriptors } = Object;
|
9
|
+
const properties = Cast.toRecord(obj);
|
10
|
+
const getters = entries(getOwnPropertyDescriptors(obj)).filter(([_, desc]) => typeof desc.get === "function").map(([key]) => key);
|
11
|
+
const returned = { ...properties };
|
12
|
+
getters.forEach((getter) => {
|
13
|
+
returned[getter] = obj[getter];
|
14
|
+
});
|
15
|
+
return returned;
|
16
|
+
} catch (err) {
|
17
|
+
return {};
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
export {
|
22
|
+
flattenGetters
|
23
|
+
};
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import {
|
2
|
+
nullishValues
|
3
|
+
} from "./chunk-HC6ZOHCS.js";
|
4
|
+
|
5
|
+
// src/agnostic/booleans/is-falsy/index.ts
|
6
|
+
var falsyValues = [...nullishValues, false, "", 0, -0, NaN];
|
7
|
+
if (typeof BigInt === "function") falsyValues.push(BigInt(0));
|
8
|
+
function isFalsy(val) {
|
9
|
+
return falsyValues.includes(val);
|
10
|
+
}
|
11
|
+
function isNotFalsy(val) {
|
12
|
+
return !isFalsy(val);
|
13
|
+
}
|
14
|
+
|
15
|
+
export {
|
16
|
+
falsyValues,
|
17
|
+
isFalsy,
|
18
|
+
isNotFalsy
|
19
|
+
};
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// src/agnostic/html/get-node-ancestors/index.ts
|
2
|
+
function getNodeAncestors(node) {
|
3
|
+
const returned = [];
|
4
|
+
let currentElement = node.parentElement;
|
5
|
+
while (currentElement !== null) {
|
6
|
+
returned.push(currentElement);
|
7
|
+
const newCurrentElement = currentElement.parentElement;
|
8
|
+
currentElement = newCurrentElement;
|
9
|
+
}
|
10
|
+
return returned;
|
11
|
+
}
|
12
|
+
|
13
|
+
export {
|
14
|
+
getNodeAncestors
|
15
|
+
};
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import {
|
2
|
+
round
|
3
|
+
} from "./chunk-32IRF4OP.js";
|
4
|
+
|
5
|
+
// src/agnostic/numbers/responsive-harmonics/index.ts
|
6
|
+
function getHarmonic(min, max, level, steps) {
|
7
|
+
if (min === 0) {
|
8
|
+
console.warn("Cannot generate harmonics if min value is zero");
|
9
|
+
return NaN;
|
10
|
+
}
|
11
|
+
if (steps < 1) {
|
12
|
+
console.warn("Cannot generate harmonics if steps is lower than one");
|
13
|
+
return NaN;
|
14
|
+
}
|
15
|
+
const maxOverMin = max / min;
|
16
|
+
const oneOverSteps = 1 / parseInt(`${steps}`);
|
17
|
+
const factor = Math.pow(maxOverMin, oneOverSteps);
|
18
|
+
return min * Math.pow(factor, level);
|
19
|
+
}
|
20
|
+
function getAffineFunction(x1, y1, x2, y2) {
|
21
|
+
const slope = (y2 - y1) / (x2 - x1);
|
22
|
+
const yIntercept = y1 - x1 * slope;
|
23
|
+
return { slope, yIntercept };
|
24
|
+
}
|
25
|
+
function getCssValueFromAffine(affine) {
|
26
|
+
const { slope, yIntercept } = affine;
|
27
|
+
const roundedSlope = round(100 * slope, 3);
|
28
|
+
const roundedIntercept = round(yIntercept, 2);
|
29
|
+
return `calc(${roundedSlope}vw + ${roundedIntercept}px)`;
|
30
|
+
}
|
31
|
+
function createScale(descriptor) {
|
32
|
+
const {
|
33
|
+
screenBounds: [loBound, hiBound],
|
34
|
+
lowLevel: [loLevelMin, loLevelMax],
|
35
|
+
highLevel: [hiLevelMin, hiLevelMax],
|
36
|
+
steps,
|
37
|
+
clamp
|
38
|
+
} = descriptor;
|
39
|
+
return function scale(level) {
|
40
|
+
if (steps < 2) return;
|
41
|
+
const loBoundVal = getHarmonic(loLevelMin, hiLevelMin, level - 1, steps - 1);
|
42
|
+
const hiBoundVal = getHarmonic(loLevelMax, hiLevelMax, level - 1, steps - 1);
|
43
|
+
if (loBoundVal === void 0) return;
|
44
|
+
if (hiBoundVal === void 0) return;
|
45
|
+
const affine = getAffineFunction(loBound, loBoundVal, hiBound, hiBoundVal);
|
46
|
+
const cssFormula = getCssValueFromAffine(affine);
|
47
|
+
return clamp === true ? `clamp(${round(loBoundVal, 2)}px, ${cssFormula}, ${round(hiBoundVal, 2)}px)` : cssFormula;
|
48
|
+
};
|
49
|
+
}
|
50
|
+
|
51
|
+
export {
|
52
|
+
getHarmonic,
|
53
|
+
createScale
|
54
|
+
};
|
@@ -0,0 +1,10 @@
|
|
1
|
+
// src/agnostic/html/get-position-inside-parent/index.ts
|
2
|
+
function getPositionInsideParent(node) {
|
3
|
+
if (!node.parentNode) return null;
|
4
|
+
const childNodes = Array.from(node.parentNode.childNodes);
|
5
|
+
return childNodes.indexOf(node);
|
6
|
+
}
|
7
|
+
|
8
|
+
export {
|
9
|
+
getPositionInsideParent
|
10
|
+
};
|
@@ -0,0 +1,35 @@
|
|
1
|
+
// src/agnostic/html/placeholders/index.ts
|
2
|
+
var Placeholders;
|
3
|
+
((Placeholders2) => {
|
4
|
+
Placeholders2.EightKiloByteOfLoremIpsumSentences = "Etiam consequat interdum elit eu interdum. Nunc eu nulla vel arcu mattis venenatis sit amet gravida sem. Mauris pretium aliquam augue vitae tempor. Interdum et malesuada fames ac ante ipsum primis in faucibus. Nam mollis in ipsum nec efficitur. Nullam imperdiet et urna vitae suscipit. In hac habitasse platea dictumst. Nullam lacinia commodo enim non iaculis. Nam elementum tellus ac lectus aliquam porta. Mauris ut lorem nec magna porttitor efficitur sed sed odio. Ut in dapibus nulla, non eleifend elit. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Maecenas posuere leo neque, a luctus quam feugiat in. Phasellus lobortis egestas cursus. In sit amet massa et sem scelerisque facilisis quis fringilla felis. Praesent purus velit, vehicula id orci ac, placerat congue quam. Cras vulputate nisi eu justo accumsan malesuada. Vestibulum ex urna, volutpat non quam in, vulputate pellentesque est. Pellentesque interdum orci in quam finibus faucibus. In eget lectus augue. Vestibulum lobortis vulputate odio. Nam vitae felis in lorem dignissim venenatis. Curabitur bibendum, est quis tempor efficitur, magna orci facilisis erat, id rhoncus massa ante non tellus. Etiam id gravida elit. Mauris ut semper risus. Nulla sed interdum lorem. Nullam eu consectetur purus. Praesent ut enim diam. Nulla hendrerit dapibus eros, sit amet rhoncus eros consequat aliquam. Duis viverra erat vel commodo facilisis. Quisque hendrerit posuere sapien, id cursus ligula rhoncus vitae. Ut et turpis augue. Aliquam augue lorem, fringilla at magna eu, egestas sagittis ex. Vestibulum elementum diam facilisis elit ultrices, eget viverra massa venenatis. Nullam finibus ligula est. Interdum et malesuada fames ac ante ipsum primis in faucibus. Nam condimentum, justo pulvinar posuere tincidunt, mi libero convallis sapien, id consectetur nunc tellus eget nisi. Fusce tincidunt sit amet enim vitae feugiat. Etiam in nulla vitae orci consequat vulputate. Vestibulum sodales urna sit amet velit elementum, vel fringilla eros iaculis. Vestibulum gravida tempus nulla, at vulputate nunc aliquam vitae. Phasellus ac augue et augue finibus congue ut nec nunc. Ut in dictum lectus, eget efficitur dui. Suspendisse bibendum congue arcu, sit amet maximus felis dictum sit amet. Morbi scelerisque feugiat risus, id pellentesque elit cursus nec. Vivamus at erat id magna sagittis cursus vitae eu magna. Integer pretium nec lorem at consectetur. Integer id justo vitae nunc gravida posuere eu vel magna. Donec ex nunc, condimentum id laoreet et, scelerisque nec enim. Sed venenatis, augue vel posuere ullamcorper, lorem velit auctor erat, a auctor mi odio id velit. Donec justo erat, tempor ut diam sed, scelerisque aliquam dolor. Donec erat dui, dictum a tortor sit amet, pellentesque blandit risus. Donec tincidunt ligula ex, vel tincidunt leo posuere sit amet. Curabitur lacinia blandit pellentesque. Donec fringilla aliquam purus ac porta. Fusce faucibus convallis leo, ut aliquet libero maximus nec. Morbi ac magna lorem. Quisque suscipit quis nisi interdum condimentum. Pellentesque imperdiet lorem diam, eu molestie ipsum scelerisque vel. Vivamus hendrerit, ipsum id sollicitudin pharetra, justo justo laoreet lorem, ac scelerisque turpis justo vitae augue. Nullam lacinia magna nec neque auctor scelerisque. Nunc sit amet lacus condimentum, interdum nisl eu, pharetra lorem. Morbi consectetur eros ac nisi facilisis, facilisis placerat magna aliquet. Donec bibendum leo ac est aliquam dictum. Quisque commodo magna risus, ut rhoncus ex feugiat nec. Sed vel tellus porta, feugiat sem quis, facilisis enim. Quisque accumsan imperdiet felis id laoreet. Etiam condimentum at ligula nec vehicula. Phasellus eget placerat quam. Cras efficitur mauris id ex tempus porttitor. Quisque pulvinar tellus id tempus ultricies. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In non erat justo. Nulla blandit placerat hendrerit. Sed blandit mattis magna eget sodales. Morbi eget accumsan sapien. Sed ornare interdum tortor iaculis volutpat. Maecenas vel tortor quis urna placerat mollis. Mauris ultrices, magna sit amet molestie sagittis, libero mi tincidunt diam, eu scelerisque nulla est vel dolor. Aenean congue congue eros bibendum elementum. Phasellus lobortis faucibus eros, et cursus lectus ultricies et. Vivamus augue metus, iaculis eget egestas in, tincidunt et lectus. Mauris varius arcu at cursus auctor. Curabitur eget nunc tellus. In eget tempor odio, vitae dictum massa. Proin in cursus est. Curabitur lobortis, velit eu accumsan sollicitudin, orci orci aliquam velit, ac iaculis massa justo sit amet massa. Duis a mauris iaculis, aliquam ipsum vel, vulputate mauris. Sed ex augue, cursus a dapibus sed, iaculis lacinia quam. Vivamus sit amet justo tellus. Nunc ac neque mattis, euismod velit id, feugiat massa. Etiam vitae auctor orci. Pellentesque sollicitudin est nibh, vitae scelerisque lacus sagittis eu. Morbi convallis metus eu enim gravida, non finibus enim accumsan. In quis pharetra justo, et tempor nibh. Duis non interdum diam. Vestibulum nec felis rhoncus, pharetra ipsum eu, rutrum magna. Integer dignissim odio eu mi finibus sollicitudin. Sed ut magna a nulla porttitor lobortis in id nibh. Pellentesque in lobortis ligula, vel malesuada neque. Aenean commodo arcu nunc, et posuere eros vulputate et. Mauris vestibulum euismod molestie. Vestibulum luctus sapien sollicitudin, cursus ante vel, varius massa. Mauris non magna pharetra, luctus felis sed, dapibus massa. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Donec posuere sapien diam, vitae porttitor nisi dictum sed. Maecenas sit amet eleifend odio. In luctus, neque eget eleifend ultricies, neque ante vestibulum leo, non ullamcorper enim orci vestibulum erat. Phasellus bibendum urna at aliquet elementum. Nulla facilisi. Sed porttitor lacus id hendrerit iaculis. Vivamus facilisis ex eget odio malesuada bibendum. Vestibulum fermentum at sem nec dignissim. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nunc faucibus augue id odio ornare, et maximus quam placerat. Nullam rutrum enim justo, id hendrerit felis faucibus sed. Aenean id nulla arcu. Nulla vitae eleifend ante. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Quisque ipsum risus, cursus at ligula convallis, interdum fringilla quam. Curabitur libero sapien, mollis in consectetur sit amet, accumsan vel justo. Nulla a eros sit amet nibh pharetra ultricies. Proin et dapibus mauris. Maecenas at lacinia felis. Vestibulum consectetur vestibulum ante. Interdum et malesuada fames ac ante ipsum primis in faucibus. In imperdiet ipsum ac facilisis interdum. Nullam vestibulum dictum vestibulum. Cras pharetra vehicula neque.".split(".").map((e) => e.trim());
|
5
|
+
Placeholders2.generateSentence = () => {
|
6
|
+
const pos = Math.floor(Math.random() * Placeholders2.EightKiloByteOfLoremIpsumSentences.length);
|
7
|
+
return Placeholders2.EightKiloByteOfLoremIpsumSentences[pos];
|
8
|
+
};
|
9
|
+
Placeholders2.generateSentences = (amount = 1) => {
|
10
|
+
return new Array(amount).fill(null).map(Placeholders2.generateSentence);
|
11
|
+
};
|
12
|
+
Placeholders2.generateTitle = () => `<h1 class="title">${(0, Placeholders2.generateSentence)()}</h1>`;
|
13
|
+
Placeholders2.generateIntertitle = () => `<h2 class="intertitle">${(0, Placeholders2.generateSentence)()}</h2>`;
|
14
|
+
Placeholders2.generateParagraph = () => {
|
15
|
+
const length = Math.floor(Math.random() * 5) + 3;
|
16
|
+
const sentencesArr = new Array(length).fill(null).map(Placeholders2.generateSentence);
|
17
|
+
return `<p class="paragraph">${sentencesArr.join(". ")}</p>`;
|
18
|
+
};
|
19
|
+
Placeholders2.generateContentPage = (len = 1) => {
|
20
|
+
const length = (Math.floor(Math.random() * 3) + 3) * Math.round(len);
|
21
|
+
const pageBody = new Array(length).fill(null).map(() => {
|
22
|
+
if (Math.random() < 0.2) return (0, Placeholders2.generateIntertitle)();
|
23
|
+
return (0, Placeholders2.generateParagraph)();
|
24
|
+
}).join("");
|
25
|
+
return `<div class="content-page">
|
26
|
+
${(0, Placeholders2.generateTitle)()}
|
27
|
+
${pageBody}
|
28
|
+
${(0, Placeholders2.generateParagraph)()}
|
29
|
+
</div>`;
|
30
|
+
};
|
31
|
+
})(Placeholders || (Placeholders = {}));
|
32
|
+
|
33
|
+
export {
|
34
|
+
Placeholders
|
35
|
+
};
|
@@ -0,0 +1,113 @@
|
|
1
|
+
// src/agnostic/optim/throttle-debounce/index.ts
|
2
|
+
function throttle(toThrottleFunc, delayMs) {
|
3
|
+
let currentDelayMs = delayMs;
|
4
|
+
let lastArgs = [];
|
5
|
+
let lastExecutedOn = 0;
|
6
|
+
let lastReturnValue = void 0;
|
7
|
+
let nextExecutionTimeout = null;
|
8
|
+
function scheduleNextCall() {
|
9
|
+
if (nextExecutionTimeout !== null) {
|
10
|
+
clearTimeout(nextExecutionTimeout);
|
11
|
+
nextExecutionTimeout = null;
|
12
|
+
}
|
13
|
+
const now = Date.now();
|
14
|
+
const nextExecutionTimestamp = lastExecutedOn + currentDelayMs;
|
15
|
+
const msTillNextExecution = nextExecutionTimestamp - now;
|
16
|
+
nextExecutionTimeout = setTimeout(() => {
|
17
|
+
nextExecutionTimeout = null;
|
18
|
+
const returnValue = toThrottleFunc(...lastArgs);
|
19
|
+
lastReturnValue = returnValue;
|
20
|
+
lastExecutedOn = now;
|
21
|
+
}, msTillNextExecution) ?? null;
|
22
|
+
}
|
23
|
+
function throttled(...args) {
|
24
|
+
const now = Date.now();
|
25
|
+
lastArgs = args;
|
26
|
+
if (now - lastExecutedOn >= delayMs) {
|
27
|
+
const returnValue = toThrottleFunc(...lastArgs);
|
28
|
+
lastReturnValue = returnValue;
|
29
|
+
lastExecutedOn = now;
|
30
|
+
return {
|
31
|
+
returnValue: lastReturnValue,
|
32
|
+
lastExecutedOn,
|
33
|
+
delayMs: currentDelayMs,
|
34
|
+
isCached: false
|
35
|
+
};
|
36
|
+
}
|
37
|
+
if (nextExecutionTimeout === null) scheduleNextCall();
|
38
|
+
return {
|
39
|
+
returnValue: lastReturnValue,
|
40
|
+
lastExecutedOn,
|
41
|
+
delayMs: currentDelayMs,
|
42
|
+
isCached: true
|
43
|
+
};
|
44
|
+
}
|
45
|
+
function setDelay(delayMs2) {
|
46
|
+
currentDelayMs = delayMs2;
|
47
|
+
if (nextExecutionTimeout !== null) scheduleNextCall();
|
48
|
+
}
|
49
|
+
return {
|
50
|
+
throttled,
|
51
|
+
setDelay
|
52
|
+
};
|
53
|
+
}
|
54
|
+
function debounce(toDebounceFunc, delayMs) {
|
55
|
+
let currentDelayMs = delayMs;
|
56
|
+
let lastArgs = [];
|
57
|
+
let lastCalledOn = 0;
|
58
|
+
let lastExecutedOn = 0;
|
59
|
+
let lastReturnValue = void 0;
|
60
|
+
let nextExecutionTimeout = null;
|
61
|
+
function scheduleNextCall() {
|
62
|
+
if (typeof nextExecutionTimeout === "number") {
|
63
|
+
clearTimeout(nextExecutionTimeout);
|
64
|
+
nextExecutionTimeout = null;
|
65
|
+
}
|
66
|
+
const now = Date.now();
|
67
|
+
const nextExecutionTimestamp = lastCalledOn + currentDelayMs;
|
68
|
+
const msTillNextExecution = nextExecutionTimestamp - now;
|
69
|
+
nextExecutionTimeout = setTimeout(() => {
|
70
|
+
nextExecutionTimeout = null;
|
71
|
+
const returnValue = toDebounceFunc(...lastArgs);
|
72
|
+
lastReturnValue = returnValue;
|
73
|
+
lastExecutedOn = now;
|
74
|
+
}, msTillNextExecution) ?? null;
|
75
|
+
}
|
76
|
+
function debounced(...args) {
|
77
|
+
const now = Date.now();
|
78
|
+
lastArgs = args;
|
79
|
+
if (now - lastCalledOn >= currentDelayMs) {
|
80
|
+
lastCalledOn = now;
|
81
|
+
const returnValue = toDebounceFunc(...lastArgs);
|
82
|
+
lastReturnValue = returnValue;
|
83
|
+
lastExecutedOn = now;
|
84
|
+
return {
|
85
|
+
returnValue: lastReturnValue,
|
86
|
+
lastExecutedOn,
|
87
|
+
delayMs: currentDelayMs,
|
88
|
+
isCached: false
|
89
|
+
};
|
90
|
+
}
|
91
|
+
lastCalledOn = now;
|
92
|
+
scheduleNextCall();
|
93
|
+
return {
|
94
|
+
returnValue: lastReturnValue,
|
95
|
+
lastExecutedOn,
|
96
|
+
delayMs: currentDelayMs,
|
97
|
+
isCached: true
|
98
|
+
};
|
99
|
+
}
|
100
|
+
function setDelay(delayMs2) {
|
101
|
+
currentDelayMs = delayMs2;
|
102
|
+
if (nextExecutionTimeout !== null) scheduleNextCall();
|
103
|
+
}
|
104
|
+
return {
|
105
|
+
debounced,
|
106
|
+
setDelay
|
107
|
+
};
|
108
|
+
}
|
109
|
+
|
110
|
+
export {
|
111
|
+
throttle,
|
112
|
+
debounce
|
113
|
+
};
|