@design-edito/tools 0.1.21 → 0.1.22
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/agnostic/arrays/find-duplicates/index.d.ts +1 -0
- package/agnostic/arrays/find-duplicates/index.js +6 -0
- package/agnostic/arrays/index.d.ts +8 -7
- package/agnostic/arrays/make/index.d.ts +3 -0
- package/agnostic/arrays/make/index.js +6 -0
- package/agnostic/arrays/random-pick/index.d.ts +2 -0
- package/agnostic/arrays/random-pick/index.js +8 -0
- package/agnostic/css/index.js +10 -10
- package/agnostic/errors/index.js +2 -2
- package/agnostic/html/hyper-json/cast/index.d.ts +18 -0
- package/agnostic/html/hyper-json/cast/index.js +11 -0
- package/agnostic/html/hyper-json/crossenv/index.d.ts +13 -0
- package/agnostic/html/hyper-json/crossenv/index.js +6 -0
- package/agnostic/html/hyper-json/index.d.ts +14 -43
- package/agnostic/html/hyper-json/index.js +32 -2
- package/agnostic/html/hyper-json/serialize/index.d.ts +5 -0
- package/agnostic/html/hyper-json/serialize/index.js +7 -0
- package/agnostic/html/hyper-json/transformers/append/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/append/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/classList/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/classList/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/index.d.ts +4 -0
- package/agnostic/html/hyper-json/transformers/index.js +39 -0
- package/agnostic/html/hyper-json/transformers/join/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/join/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/length/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/length/index.js +8 -0
- package/agnostic/html/hyper-json/transformers/print/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/print/index.js +7 -0
- package/agnostic/html/hyper-json/transformers/push/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/push/index.js +7 -0
- package/agnostic/html/hyper-json/transformers/querySelector/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/querySelector/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/ref/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/ref/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/replace/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/replace/index.js +13 -0
- package/agnostic/html/hyper-json/transformers/split/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/split/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/toArray/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/toArray/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/toBoolean/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/toBoolean/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/toElement/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/toElement/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/toNodeList/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/toNodeList/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/toNull/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/toNull/index.js +7 -0
- package/agnostic/html/hyper-json/transformers/toNumber/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/toNumber/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/toRecord/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/toRecord/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/toRef/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/toRef/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/toString/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/toString/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/toText/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/toText/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/toTransformer/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/toTransformer/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/transformSelected/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/transformSelected/index.js +39 -0
- package/agnostic/html/hyper-json/transformers/trim/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/trim/index.js +12 -0
- package/agnostic/html/hyper-json/tree/index.d.ts +56 -0
- package/agnostic/html/hyper-json/tree/index.js +39 -0
- package/agnostic/html/hyper-json/types/index.d.ts +86 -0
- package/agnostic/html/hyper-json/types/index.js +6 -0
- package/agnostic/html/hyper-json/utils/index.d.ts +10 -0
- package/agnostic/html/hyper-json/utils/index.js +6 -0
- package/agnostic/html/index.js +51 -19
- package/agnostic/html/replace-in-element/index.d.ts +1 -0
- package/agnostic/html/replace-in-element/index.js +6 -0
- package/agnostic/html/sanitize/index.js +7 -5
- package/agnostic/html/selector-to-element/index.js +7 -5
- package/agnostic/html/string-to-nodes/index.js +8 -6
- package/agnostic/index.d.ts +0 -2
- package/agnostic/misc/{web-crawler → crawler}/index.d.ts +1 -1
- package/agnostic/misc/crawler/index.js +7 -0
- package/agnostic/misc/crossenv/get-document/index.d.ts +2 -0
- package/agnostic/misc/crossenv/get-document/index.js +7 -0
- package/agnostic/misc/crossenv/get-window/browser.d.ts +2 -0
- package/agnostic/misc/crossenv/get-window/index.d.ts +2 -0
- package/agnostic/misc/crossenv/get-window/index.js +6 -0
- package/agnostic/misc/crossenv/index.d.ts +4 -1
- package/agnostic/misc/crossenv/index.js +3 -1
- package/agnostic/misc/crossenv/types.d.ts +3 -0
- package/agnostic/misc/index.d.ts +3 -1
- package/agnostic/misc/index.js +24 -14
- package/agnostic/misc/lorem-ipsum/index.js +5 -2
- package/agnostic/numbers/index.js +3 -3
- package/agnostic/objects/index.js +10 -10
- package/agnostic/optim/index.js +3 -3
- package/agnostic/random/index.js +6 -0
- package/agnostic/strings/index.js +9 -9
- package/agnostic/time/duration/index.d.ts +26 -0
- package/agnostic/time/duration/index.js +6 -0
- package/agnostic/time/index.d.ts +8 -7
- package/agnostic/time/index.js +17 -28
- package/agnostic/time/timeout/index.d.ts +1 -0
- package/agnostic/time/timeout/index.js +6 -0
- package/agnostic/time/transitions/index.js +7 -0
- package/agnostic/time/wait/index.js +6 -0
- package/chunks/chunk-2DMWYLFG.js +16 -0
- package/chunks/chunk-2KT7AKRW.js +17 -0
- package/chunks/{chunk-UCV2AZZV.js → chunk-2PI5AZIL.js} +14 -25
- package/chunks/chunk-3KQRMKQJ.js +27 -0
- package/chunks/chunk-3LVR6KZH.js +22 -0
- package/chunks/chunk-3PHPA25U.js +18 -0
- package/chunks/chunk-3PM7GZ6B.js +33 -0
- package/chunks/chunk-3SQJEEBK.js +642 -0
- package/chunks/chunk-3UURICGY.js +211 -0
- package/chunks/chunk-3X6RXJBR.js +37 -0
- package/chunks/{chunk-DQNJQBC6.js → chunk-4CIS3R7T.js} +1 -1
- package/chunks/chunk-4F7ZVE7T.js +332 -0
- package/chunks/chunk-4GUDL44X.js +13 -0
- package/chunks/chunk-4RDW62CU.js +36 -0
- package/chunks/chunk-5IR2PWO6.js +211 -0
- package/chunks/chunk-6CM2SWSX.js +35 -0
- package/chunks/chunk-6EYBQHJS.js +33 -0
- package/chunks/chunk-6NYUQXJT.js +109 -0
- package/chunks/chunk-6NZCBAT4.js +19 -0
- package/chunks/chunk-6V23XMYE.js +982 -0
- package/chunks/chunk-73V5RDSG.js +13 -0
- package/chunks/chunk-7IGZP4TV.js +30 -0
- package/chunks/chunk-7QMAYGNV.js +25 -0
- package/chunks/chunk-7YW5HL6N.js +168 -0
- package/chunks/chunk-AFFLZUW5.js +33 -0
- package/chunks/chunk-AMS3FB24.js +85 -0
- package/chunks/chunk-AXMPRLPI.js +35 -0
- package/chunks/chunk-B6CSCX7J.js +278 -0
- package/chunks/chunk-BDHNULU7.js +211 -0
- package/chunks/chunk-BNB7LEMQ.js +35 -0
- package/chunks/chunk-CECF6UZV.js +29 -0
- package/chunks/chunk-DBAJ66BR.js +18 -0
- package/chunks/chunk-DGQLPQS2.js +33 -0
- package/chunks/chunk-DLLTITVO.js +33 -0
- package/chunks/chunk-DMDOCC72.js +18 -0
- package/chunks/{chunk-IFT6HLDW.js → chunk-DRH7Q4FL.js} +3 -6
- package/chunks/chunk-DRNK3RLE.js +64 -0
- package/chunks/chunk-EAY65ZP6.js +22 -0
- package/chunks/{chunk-4GDNHUCZ.js → chunk-ENMBK6H7.js} +2 -2
- package/chunks/chunk-F5YMP5WU.js +18 -0
- package/chunks/chunk-F7EVMWVG.js +27 -0
- package/chunks/chunk-F7XWUG2V.js +18 -0
- package/chunks/chunk-FCU6IHKD.js +15 -0
- package/chunks/chunk-FFOATPL4.js +211 -0
- package/chunks/chunk-FWHUASVA.js +22 -0
- package/chunks/chunk-GBMHGF7P.js +20 -0
- package/chunks/{chunk-GJOU3UAL.js → chunk-GDYVCEWA.js} +8 -6
- package/chunks/chunk-GNBIAWSY.js +278 -0
- package/chunks/chunk-GQSPY2CV.js +19 -0
- package/chunks/chunk-HDALT7XM.js +620 -0
- package/chunks/chunk-HUKHWFVL.js +19 -0
- package/chunks/chunk-IGD53YL5.js +870 -0
- package/chunks/chunk-ILEM73XB.js +981 -0
- package/chunks/{chunk-DMGR57KA.js → chunk-IPB3U2PD.js} +20 -18
- package/chunks/chunk-JY3QZ2YO.js +211 -0
- package/chunks/chunk-K3OQEJI3.js +33 -0
- package/chunks/chunk-KXBKJ3GS.js +642 -0
- package/chunks/chunk-LCFDDWJR.js +278 -0
- package/chunks/chunk-LGECI2WL.js +306 -0
- package/chunks/chunk-LGUEB5L5.js +211 -0
- package/chunks/chunk-LI6QDZCA.js +211 -0
- package/chunks/{chunk-ZMHKLIP2.js → chunk-LYMZZ4BB.js} +1 -1
- package/chunks/chunk-MDEDNPU5.js +38 -0
- package/chunks/chunk-MQHKEGP4.js +33 -0
- package/chunks/chunk-NF5ACCXZ.js +211 -0
- package/chunks/chunk-NK557MKV.js +35 -0
- package/chunks/chunk-NWMEWFTK.js +33 -0
- package/chunks/chunk-O5OTBN22.js +35 -0
- package/chunks/chunk-O7MDUYEF.js +211 -0
- package/chunks/{chunk-LI5KVXAJ.js → chunk-OO5SJJDW.js} +2 -5
- package/chunks/chunk-Q52UJOBC.js +18 -0
- package/chunks/chunk-QFEF4EET.js +211 -0
- package/chunks/chunk-QHSVCGLD.js +280 -0
- package/chunks/chunk-QO64L4KB.js +97 -0
- package/chunks/{chunk-WLL3FNVL.js → chunk-R6KCN6CK.js} +1 -1
- package/chunks/chunk-RJ5E22H5.js +15 -0
- package/chunks/chunk-RLAZR3NL.js +8 -0
- package/chunks/chunk-RWUPHV54.js +25 -0
- package/chunks/chunk-S2757FI3.js +36 -0
- package/chunks/chunk-S42P73SC.js +30 -0
- package/chunks/chunk-S5XDYLJH.js +18 -0
- package/chunks/chunk-SCM6NACT.js +15 -0
- package/chunks/chunk-SH3Y2I5P.js +18 -0
- package/chunks/chunk-SMLKMOAX.js +18 -0
- package/chunks/chunk-TATRVKBS.js +211 -0
- package/chunks/chunk-UODQZRY2.js +620 -0
- package/chunks/chunk-UOULDS6J.js +33 -0
- package/chunks/chunk-UUDXUSI5.js +211 -0
- package/chunks/{chunk-GL23YDEH.js → chunk-UWAMSJ2X.js} +3 -6
- package/chunks/chunk-UZUXLD2Q.js +35 -0
- package/chunks/chunk-VA6HXRX4.js +211 -0
- package/chunks/chunk-VRUJR6WR.js +39 -0
- package/chunks/chunk-W6YBEEZM.js +211 -0
- package/chunks/chunk-WECTUHS5.js +127 -0
- package/chunks/chunk-YE5HI3RK.js +211 -0
- package/chunks/chunk-YEBOL67V.js +32 -0
- package/chunks/chunk-YS6WMSWC.js +15 -0
- package/{agnostic/misc/web-crawler/index.js → chunks/chunk-YUP434IY.js} +8 -7
- package/chunks/chunk-YYE2MVZO.js +211 -0
- package/chunks/chunk-Z7ZDDBV5.js +18 -0
- package/chunks/chunk-ZB73RE7P.js +35 -0
- package/chunks/chunk-ZONKYNKA.js +28 -0
- package/node/files/index.js +3 -3
- package/package.json +4 -1
- package/agnostic/async/index.d.ts +0 -8
- package/agnostic/async/index.js +0 -20
- package/agnostic/async/timeout-call/index.d.ts +0 -1
- package/agnostic/async/timeout-call/index.js +0 -6
- package/agnostic/async/transitions/index.js +0 -7
- package/agnostic/async/wait/index.js +0 -6
- package/agnostic/misc/random/index.js +0 -6
- package/chunks/chunk-4VC5PT5T.js +0 -13
- /package/agnostic/{misc/random → random}/index.d.ts +0 -0
- /package/agnostic/{async → time}/transitions/index.d.ts +0 -0
- /package/agnostic/{async → time}/wait/index.d.ts +0 -0
|
@@ -0,0 +1,981 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Serialize
|
|
3
|
+
} from "./chunk-DRNK3RLE.js";
|
|
4
|
+
import {
|
|
5
|
+
Crossenv
|
|
6
|
+
} from "./chunk-3LVR6KZH.js";
|
|
7
|
+
import {
|
|
8
|
+
Utils
|
|
9
|
+
} from "./chunk-F7EVMWVG.js";
|
|
10
|
+
import {
|
|
11
|
+
Types
|
|
12
|
+
} from "./chunk-7QMAYGNV.js";
|
|
13
|
+
import {
|
|
14
|
+
insertNode
|
|
15
|
+
} from "./chunk-XA4HVHJ4.js";
|
|
16
|
+
import {
|
|
17
|
+
replaceInElement
|
|
18
|
+
} from "./chunk-GBMHGF7P.js";
|
|
19
|
+
import {
|
|
20
|
+
isRecord
|
|
21
|
+
} from "./chunk-YDIBNEGA.js";
|
|
22
|
+
import {
|
|
23
|
+
replaceAll
|
|
24
|
+
} from "./chunk-MF56TTC5.js";
|
|
25
|
+
import {
|
|
26
|
+
isFalsy
|
|
27
|
+
} from "./chunk-QXAJXTXV.js";
|
|
28
|
+
|
|
29
|
+
// src/agnostic/html/hyper-json/cast/index.ts
|
|
30
|
+
var getWindow = Crossenv.getWindow;
|
|
31
|
+
var Cast;
|
|
32
|
+
((Cast2) => {
|
|
33
|
+
Cast2.toNull = () => null;
|
|
34
|
+
Cast2.toBoolean = (input) => !isFalsy(input);
|
|
35
|
+
Cast2.toNumber = (input) => {
|
|
36
|
+
const { Text } = getWindow();
|
|
37
|
+
if (typeof input === "number") return input;
|
|
38
|
+
if (typeof input === "string") return parseFloat(`${input}`);
|
|
39
|
+
if (input instanceof Text) return parseFloat(`${input.textContent}`);
|
|
40
|
+
return 0;
|
|
41
|
+
};
|
|
42
|
+
Cast2.toString = (input) => {
|
|
43
|
+
if (typeof input === "string") return input;
|
|
44
|
+
if (typeof input === "number" || typeof input === "boolean" || input === null) return `${input}`;
|
|
45
|
+
const { Element, Text, NodeList } = getWindow();
|
|
46
|
+
if (input instanceof Element) return input.outerHTML;
|
|
47
|
+
if (input instanceof Text) return input.textContent ?? "";
|
|
48
|
+
if (input instanceof NodeList) return Array.from(input).map((e) => {
|
|
49
|
+
if (e instanceof Element) return e.outerHTML;
|
|
50
|
+
return e.textContent;
|
|
51
|
+
}).join("");
|
|
52
|
+
return input.toString();
|
|
53
|
+
};
|
|
54
|
+
Cast2.toText = (input) => {
|
|
55
|
+
const { Text, document: document2 } = getWindow();
|
|
56
|
+
if (input instanceof Text) return input.cloneNode(true);
|
|
57
|
+
return document2.createTextNode((0, Cast2.toString)(input));
|
|
58
|
+
};
|
|
59
|
+
Cast2.toElement = (input) => {
|
|
60
|
+
const { Element, Text, NodeList, document: document2 } = getWindow();
|
|
61
|
+
if (input instanceof Element) return input.cloneNode(true);
|
|
62
|
+
const elt = document2.createElement("div");
|
|
63
|
+
if (input instanceof Text) {
|
|
64
|
+
elt.append(input.cloneNode(true));
|
|
65
|
+
return elt;
|
|
66
|
+
}
|
|
67
|
+
if (input instanceof NodeList) {
|
|
68
|
+
elt.append(...Array.from(input).map((e) => e.cloneNode(true)));
|
|
69
|
+
return elt;
|
|
70
|
+
}
|
|
71
|
+
if (Array.isArray(input)) return elt;
|
|
72
|
+
if (isRecord(input)) return elt;
|
|
73
|
+
elt.append(`${input}`);
|
|
74
|
+
return elt;
|
|
75
|
+
};
|
|
76
|
+
Cast2.toNodeList = (input) => {
|
|
77
|
+
const { Element, Text, NodeList, document: document2 } = getWindow();
|
|
78
|
+
const elt = document2.createElement("div");
|
|
79
|
+
if (input instanceof NodeList) {
|
|
80
|
+
elt.append(...Array.from(input).map((i) => i.cloneNode(true)));
|
|
81
|
+
return elt.childNodes;
|
|
82
|
+
}
|
|
83
|
+
if (input instanceof Element || input instanceof Text) {
|
|
84
|
+
elt.append(input.cloneNode(true));
|
|
85
|
+
return elt.childNodes;
|
|
86
|
+
}
|
|
87
|
+
if (Array.isArray(input)) return elt.childNodes;
|
|
88
|
+
if (isRecord(input)) return elt.childNodes;
|
|
89
|
+
elt.innerHTML = `${input}`;
|
|
90
|
+
return elt.childNodes;
|
|
91
|
+
};
|
|
92
|
+
Cast2.toArray = (input) => {
|
|
93
|
+
const { NodeList } = getWindow();
|
|
94
|
+
if (Array.isArray(input)) return [...input];
|
|
95
|
+
if (input instanceof NodeList) return Array.from(input);
|
|
96
|
+
return [input];
|
|
97
|
+
};
|
|
98
|
+
Cast2.toRecord = (input) => {
|
|
99
|
+
if (isRecord(input)) return { ...input };
|
|
100
|
+
return {};
|
|
101
|
+
};
|
|
102
|
+
Cast2.toTransformer = (input) => {
|
|
103
|
+
return Transformers.toNamed("utils/Cast.toTransformer", () => ({
|
|
104
|
+
action: "REPLACE",
|
|
105
|
+
value: input
|
|
106
|
+
}));
|
|
107
|
+
};
|
|
108
|
+
})(Cast || (Cast = {}));
|
|
109
|
+
|
|
110
|
+
// src/agnostic/html/hyper-json/transformers/classList/index.ts
|
|
111
|
+
var classList = (callerTagName, ...args) => {
|
|
112
|
+
return Transformers.toNamed(callerTagName, (currentValue) => {
|
|
113
|
+
const { Element } = Crossenv.getWindow();
|
|
114
|
+
if (!(currentValue instanceof Element)) return Utils.makeTransformerError("Current value must be an Element");
|
|
115
|
+
const [actionArg, classNameArg] = args;
|
|
116
|
+
if (actionArg === void 0 || classNameArg === void 0) return Utils.makeTransformerError(`Expecting 2 arguments: (action: 'add' | 'remove' | 'toggle', classList: string)`);
|
|
117
|
+
const action = Cast.toString(actionArg);
|
|
118
|
+
const className = Cast.toString(actionArg).trim();
|
|
119
|
+
if (action === "add" /* ADD */) {
|
|
120
|
+
const outputValue = currentValue.cloneNode(true);
|
|
121
|
+
outputValue.classList.add(className);
|
|
122
|
+
return { action: "REPLACE", value: outputValue };
|
|
123
|
+
} else if (action === "remove" /* REMOVE */) {
|
|
124
|
+
const outputValue = currentValue.cloneNode(true);
|
|
125
|
+
outputValue.classList.remove(className);
|
|
126
|
+
return { action: "REPLACE", value: outputValue };
|
|
127
|
+
} else if (action === "toggle" /* TOGGLE */) {
|
|
128
|
+
const outputValue = currentValue.cloneNode(true);
|
|
129
|
+
outputValue.classList.toggle(className);
|
|
130
|
+
return { action: "REPLACE", value: outputValue };
|
|
131
|
+
}
|
|
132
|
+
return Utils.makeTransformerError(`Unknown action: ${action}`);
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// src/agnostic/html/hyper-json/transformers/join/index.ts
|
|
137
|
+
var join = (callerTagName, ...args) => {
|
|
138
|
+
return Transformers.toNamed(callerTagName, (currentValue) => {
|
|
139
|
+
const joiner = Cast.toString(args.at(0) ?? ",");
|
|
140
|
+
if (!Array.isArray(currentValue)) return Utils.makeTransformerError({
|
|
141
|
+
message: `Current value must be an array`,
|
|
142
|
+
input: currentValue
|
|
143
|
+
});
|
|
144
|
+
return {
|
|
145
|
+
action: "REPLACE",
|
|
146
|
+
value: currentValue.join(joiner)
|
|
147
|
+
};
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// src/agnostic/html/hyper-json/transformers/length/index.ts
|
|
152
|
+
var length = (callerTagName) => {
|
|
153
|
+
return Transformers.toNamed(callerTagName, (currentValue) => {
|
|
154
|
+
const { Element, NodeList, Text } = Crossenv.getWindow();
|
|
155
|
+
if (typeof currentValue === "string" || Array.isArray(currentValue) || currentValue instanceof NodeList) return {
|
|
156
|
+
action: "REPLACE",
|
|
157
|
+
value: currentValue.length
|
|
158
|
+
};
|
|
159
|
+
if (currentValue instanceof Element) return {
|
|
160
|
+
action: "REPLACE",
|
|
161
|
+
value: Array.from(currentValue.childNodes).length
|
|
162
|
+
};
|
|
163
|
+
if (currentValue instanceof Text) return {
|
|
164
|
+
action: "REPLACE",
|
|
165
|
+
value: currentValue.data.length
|
|
166
|
+
};
|
|
167
|
+
return Utils.makeTransformerError(`Current value must be of type string, Array, NodeList, Element or Text`);
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// src/agnostic/html/hyper-json/transformers/print/index.ts
|
|
172
|
+
var print = (callerTagName, ...args) => {
|
|
173
|
+
return Transformers.toNamed(callerTagName, (currentValue) => {
|
|
174
|
+
if (args.length === 0) console.log(currentValue);
|
|
175
|
+
else console.log(...args);
|
|
176
|
+
return { action: null };
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
// src/agnostic/html/hyper-json/transformers/push/index.ts
|
|
181
|
+
var push = (callerTagName, ...args) => {
|
|
182
|
+
return Transformers.toNamed(callerTagName, (currentValue) => {
|
|
183
|
+
if (!Array.isArray(currentValue)) return Utils.makeTransformerError({
|
|
184
|
+
message: "Current value must be an array",
|
|
185
|
+
input: currentValue
|
|
186
|
+
});
|
|
187
|
+
const outputValue = [...currentValue, ...args];
|
|
188
|
+
return {
|
|
189
|
+
action: "REPLACE",
|
|
190
|
+
value: outputValue
|
|
191
|
+
};
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
// src/agnostic/html/hyper-json/transformers/querySelector/index.ts
|
|
196
|
+
var querySelector = (callerTagName, ...args) => {
|
|
197
|
+
return Transformers.toNamed(callerTagName, (currentValue) => {
|
|
198
|
+
const { document: document2, Element, NodeList } = Crossenv.getWindow();
|
|
199
|
+
const [selectorRaw] = args;
|
|
200
|
+
if (selectorRaw === void 0) return Utils.makeTransformerError("Selector argument expected.");
|
|
201
|
+
const selector = Cast.toString(selectorRaw);
|
|
202
|
+
let toQuery;
|
|
203
|
+
if (currentValue instanceof Element) {
|
|
204
|
+
toQuery = currentValue.cloneNode(true);
|
|
205
|
+
} else if (currentValue instanceof NodeList) {
|
|
206
|
+
toQuery = document2.createElement("div");
|
|
207
|
+
toQuery.append(...Array.from(currentValue).map((e) => e.cloneNode(true)));
|
|
208
|
+
} else return Utils.makeTransformerError("Current value must be an Element or a NodeList");
|
|
209
|
+
const found = toQuery.querySelectorAll(selector);
|
|
210
|
+
return {
|
|
211
|
+
action: "REPLACE",
|
|
212
|
+
value: found
|
|
213
|
+
};
|
|
214
|
+
});
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
// src/agnostic/html/hyper-json/transformers/ref/index.ts
|
|
218
|
+
var ref = (callerTagName, ...args) => {
|
|
219
|
+
return Transformers.toNamed(callerTagName, (_, callerTree) => {
|
|
220
|
+
const [refPathStrRaw] = args;
|
|
221
|
+
const { Text } = Crossenv.getWindow();
|
|
222
|
+
if (typeof refPathStrRaw !== "string" && !(refPathStrRaw instanceof Text)) return Utils.makeTransformerError({
|
|
223
|
+
message: "PathString must be of type string or Text",
|
|
224
|
+
input: refPathStrRaw !== void 0 ? refPathStrRaw : "<undefined>"
|
|
225
|
+
});
|
|
226
|
+
const refPathStr = Cast.toString(refPathStrRaw);
|
|
227
|
+
const refPath = Utils.pathStringToPath(Cast.toString(refPathStrRaw));
|
|
228
|
+
const foundTree = callerTree.resolve(refPath);
|
|
229
|
+
if (foundTree === void 0) return Utils.makeTransformerError({
|
|
230
|
+
message: "Referenced value has not been found",
|
|
231
|
+
input: refPathStr
|
|
232
|
+
});
|
|
233
|
+
const evaluated = foundTree.evaluate();
|
|
234
|
+
return {
|
|
235
|
+
action: "MERGE",
|
|
236
|
+
value: evaluated
|
|
237
|
+
};
|
|
238
|
+
});
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
// src/agnostic/html/hyper-json/transformers/replace/index.ts
|
|
242
|
+
var replace = (callerTagName, ...args) => {
|
|
243
|
+
return Transformers.toNamed(callerTagName, (currentValue) => {
|
|
244
|
+
const { Text, NodeList, Element } = Crossenv.getWindow();
|
|
245
|
+
if (typeof currentValue !== "string" && !(currentValue instanceof Text) && !(currentValue instanceof Element) && !(currentValue instanceof NodeList)) return Utils.makeTransformerError("Current value must be string, Text, Element or NodeList");
|
|
246
|
+
if (args.some((arg) => typeof arg !== "string" && !(arg instanceof Text) && !(arg instanceof Element) && !(arg instanceof NodeList))) return Utils.makeTransformerError("Arguments must be of type string, Text, Element or NodeList");
|
|
247
|
+
const [first, second] = args;
|
|
248
|
+
if (first === void 0 || second === void 0) return Utils.makeTransformerError(`Expecting at least 2 arguments. Found only ${args.length}`);
|
|
249
|
+
const replacer = args.at(-1);
|
|
250
|
+
const strReplacer = Cast.toString(replacer);
|
|
251
|
+
const toReplace = args.slice(0, -1);
|
|
252
|
+
const strToReplace = toReplace.map(Cast.toString);
|
|
253
|
+
const strInput = Cast.toString(currentValue);
|
|
254
|
+
const strOutput = strToReplace.reduce((str, torpl) => replaceAll(str, torpl, strReplacer), strInput);
|
|
255
|
+
if (typeof currentValue === "string") return { action: "REPLACE", value: strOutput };
|
|
256
|
+
if (currentValue instanceof Text) return { action: "REPLACE", value: Cast.toText(strOutput) };
|
|
257
|
+
if (currentValue instanceof Element) return { action: "REPLACE", value: Cast.toElement(strOutput) };
|
|
258
|
+
if (currentValue instanceof NodeList) return { action: "REPLACE", value: Cast.toNodeList(strOutput) };
|
|
259
|
+
return { action: null };
|
|
260
|
+
});
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
// src/agnostic/html/hyper-json/transformers/split/index.ts
|
|
264
|
+
var split = (callerTagName, ...args) => {
|
|
265
|
+
return Transformers.toNamed(callerTagName, (currentValue) => {
|
|
266
|
+
const { Text } = Crossenv.getWindow();
|
|
267
|
+
const [splitter] = args;
|
|
268
|
+
if (typeof currentValue !== "string" && !(currentValue instanceof Text)) return Utils.makeTransformerError({
|
|
269
|
+
message: "Current value must be string or Text",
|
|
270
|
+
input: currentValue
|
|
271
|
+
});
|
|
272
|
+
if (typeof splitter !== "string") return Utils.makeTransformerError({
|
|
273
|
+
message: "Splitter argument must be string",
|
|
274
|
+
input: splitter !== void 0 ? splitter : "<undefined>"
|
|
275
|
+
});
|
|
276
|
+
const strCurrentValue = Cast.toString(currentValue);
|
|
277
|
+
const splitted = strCurrentValue.split(splitter).map((e) => typeof currentValue === "string" ? Cast.toString(e) : Cast.toText(e));
|
|
278
|
+
return {
|
|
279
|
+
action: "REPLACE",
|
|
280
|
+
value: splitted
|
|
281
|
+
};
|
|
282
|
+
});
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
// src/agnostic/html/hyper-json/transformers/toArray/index.ts
|
|
286
|
+
var toArray = (callerTagName) => {
|
|
287
|
+
return Transformers.toNamed(callerTagName, (currentValue) => ({
|
|
288
|
+
action: "REPLACE",
|
|
289
|
+
value: Cast.toArray(currentValue)
|
|
290
|
+
}));
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
// src/agnostic/html/hyper-json/transformers/toBoolean/index.ts
|
|
294
|
+
var toBoolean = (callerTagName) => {
|
|
295
|
+
return Transformers.toNamed(callerTagName, (currentValue) => ({
|
|
296
|
+
action: "REPLACE",
|
|
297
|
+
value: Cast.toBoolean(currentValue)
|
|
298
|
+
}));
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
// src/agnostic/html/hyper-json/transformers/toElement/index.ts
|
|
302
|
+
var toElement = (callerTagName) => {
|
|
303
|
+
return Transformers.toNamed(callerTagName, (currentValue) => ({
|
|
304
|
+
action: "REPLACE",
|
|
305
|
+
value: Cast.toElement(currentValue)
|
|
306
|
+
}));
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
// src/agnostic/html/hyper-json/transformers/toNodeList/index.ts
|
|
310
|
+
var toNodeList = (callerTagName) => {
|
|
311
|
+
return Transformers.toNamed(callerTagName, (currentValue) => ({
|
|
312
|
+
action: "REPLACE",
|
|
313
|
+
value: Cast.toNodeList(currentValue)
|
|
314
|
+
}));
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
// src/agnostic/html/hyper-json/transformers/toNull/index.ts
|
|
318
|
+
var toNull = (callerTagName) => {
|
|
319
|
+
return Transformers.toNamed(callerTagName, (currentValue) => ({
|
|
320
|
+
action: "REPLACE",
|
|
321
|
+
value: null
|
|
322
|
+
}));
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
// src/agnostic/html/hyper-json/transformers/toNumber/index.ts
|
|
326
|
+
var toNumber = (callerTagName) => {
|
|
327
|
+
return Transformers.toNamed(callerTagName, (currentValue) => ({
|
|
328
|
+
action: "REPLACE",
|
|
329
|
+
value: Cast.toNumber(currentValue)
|
|
330
|
+
}));
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
// src/agnostic/html/hyper-json/transformers/toRecord/index.ts
|
|
334
|
+
var toRecord = (callerTagName) => {
|
|
335
|
+
return Transformers.toNamed(callerTagName, (currentValue) => ({
|
|
336
|
+
action: "REPLACE",
|
|
337
|
+
value: Cast.toRecord(currentValue)
|
|
338
|
+
}));
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
// src/agnostic/html/hyper-json/transformers/toRef/index.ts
|
|
342
|
+
var toRef = (callerTagName) => {
|
|
343
|
+
return Transformers.toNamed(callerTagName, (currentValue, callerTree) => {
|
|
344
|
+
const { Text } = Crossenv.getWindow();
|
|
345
|
+
if (typeof currentValue !== "string" && !(currentValue instanceof Text)) return Utils.makeTransformerError({
|
|
346
|
+
message: "Current value must be string or Text",
|
|
347
|
+
input: currentValue
|
|
348
|
+
});
|
|
349
|
+
const refPathStr = Cast.toString(currentValue);
|
|
350
|
+
const refPath = Utils.pathStringToPath(refPathStr);
|
|
351
|
+
const foundTree = callerTree.resolve(refPath);
|
|
352
|
+
if (foundTree === void 0) return Utils.makeTransformerError({
|
|
353
|
+
message: "Referenced value has not been found",
|
|
354
|
+
input: refPathStr
|
|
355
|
+
});
|
|
356
|
+
const evaluated = foundTree.evaluate();
|
|
357
|
+
return {
|
|
358
|
+
action: "REPLACE",
|
|
359
|
+
value: evaluated
|
|
360
|
+
};
|
|
361
|
+
});
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
// src/agnostic/html/hyper-json/transformers/toString/index.ts
|
|
365
|
+
var toString = (callerTagName) => {
|
|
366
|
+
return Transformers.toNamed(callerTagName, (currentValue) => ({
|
|
367
|
+
action: "REPLACE",
|
|
368
|
+
value: Cast.toString(currentValue)
|
|
369
|
+
}));
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
// src/agnostic/html/hyper-json/transformers/toText/index.ts
|
|
373
|
+
var toText = (callerTagName) => {
|
|
374
|
+
return Transformers.toNamed(callerTagName, (currentValue) => ({
|
|
375
|
+
action: "REPLACE",
|
|
376
|
+
value: Cast.toText(currentValue)
|
|
377
|
+
}));
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
// src/agnostic/html/hyper-json/transformers/toTransformer/index.ts
|
|
381
|
+
var toTransformer = (callerTagName) => {
|
|
382
|
+
return Transformers.toNamed(callerTagName, (currentValue) => ({
|
|
383
|
+
action: "REPLACE",
|
|
384
|
+
value: Cast.toTransformer(currentValue)
|
|
385
|
+
}));
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
// src/agnostic/html/hyper-json/tree/index.ts
|
|
389
|
+
var getWindow2 = Crossenv.getWindow;
|
|
390
|
+
var isElement = (node) => node.nodeType === getWindow2().Node.ELEMENT_NODE;
|
|
391
|
+
var isText = (node) => node.nodeType === getWindow2().Node.TEXT_NODE;
|
|
392
|
+
var Tree = class _Tree {
|
|
393
|
+
node;
|
|
394
|
+
name;
|
|
395
|
+
parent;
|
|
396
|
+
root;
|
|
397
|
+
isRoot;
|
|
398
|
+
path;
|
|
399
|
+
pathString;
|
|
400
|
+
tagName;
|
|
401
|
+
attributes;
|
|
402
|
+
subtrees = /* @__PURE__ */ new Map();
|
|
403
|
+
children;
|
|
404
|
+
type;
|
|
405
|
+
generators;
|
|
406
|
+
keyAttribute;
|
|
407
|
+
actionAttribute;
|
|
408
|
+
constructor(node, parentOrOptions, pathFromParent, options) {
|
|
409
|
+
this.resolve = this.resolve.bind(this);
|
|
410
|
+
this.getGenerator = this.getGenerator.bind(this);
|
|
411
|
+
this.initValue = this.initValue.bind(this);
|
|
412
|
+
this.getInnerValue = this.getInnerValue.bind(this);
|
|
413
|
+
this.wrapInnerValue = this.wrapInnerValue.bind(this);
|
|
414
|
+
this.setCache = this.setCache.bind(this);
|
|
415
|
+
this.getPerfCounters = this.getPerfCounters.bind(this);
|
|
416
|
+
this.printPerfCounters = this.printPerfCounters.bind(this);
|
|
417
|
+
this.pushToEvalCallStack = this.pushToEvalCallStack.bind(this);
|
|
418
|
+
this.flushEvalCallStack = this.flushEvalCallStack.bind(this);
|
|
419
|
+
this.evaluate = this.evaluate.bind(this);
|
|
420
|
+
const { Element, Text } = getWindow2();
|
|
421
|
+
const _node = node;
|
|
422
|
+
const _parent = parentOrOptions instanceof _Tree ? parentOrOptions : void 0;
|
|
423
|
+
this.node = _node;
|
|
424
|
+
this.parent = _parent ?? null;
|
|
425
|
+
this.root = this.parent === null ? this : this.parent.root;
|
|
426
|
+
this.isRoot = this.root === this;
|
|
427
|
+
const _options = options ?? parentOrOptions instanceof _Tree ? _Tree.fillOptions({}) : _Tree.fillOptions(parentOrOptions ?? {});
|
|
428
|
+
this.keyAttribute = _options.keyAttribute;
|
|
429
|
+
this.actionAttribute = _options.actionAttribute;
|
|
430
|
+
this.generators = this.isRoot ? _options.generatorsMap : this.root.generators;
|
|
431
|
+
this.name = this.node instanceof Element ? this.node.getAttribute(this.keyAttribute) : null;
|
|
432
|
+
const _pathFromParent = pathFromParent !== void 0 ? pathFromParent : void 0;
|
|
433
|
+
if (this.parent === null) this.path = [];
|
|
434
|
+
else if (_pathFromParent === void 0) {
|
|
435
|
+
this.path = [...this.parent.path, 0];
|
|
436
|
+
} else {
|
|
437
|
+
this.path = [...this.parent.path, _pathFromParent];
|
|
438
|
+
}
|
|
439
|
+
this.pathString = `/${this.path.join("/")}`;
|
|
440
|
+
this.tagName = node instanceof Element ? node.tagName.toLowerCase() : null;
|
|
441
|
+
this.attributes = isElement(node) ? Array.from(node.attributes) : null;
|
|
442
|
+
const { childNodes } = node;
|
|
443
|
+
let positionnedChildrenCount = 0;
|
|
444
|
+
const mutableSubtrees = /* @__PURE__ */ new Map();
|
|
445
|
+
Array.from(childNodes).filter((node2, _, nodes) => {
|
|
446
|
+
if (isElement(node2)) return true;
|
|
447
|
+
if (isText(node2)) {
|
|
448
|
+
const hasContent = (node2.textContent ?? "").trim() !== "";
|
|
449
|
+
if (hasContent) return true;
|
|
450
|
+
if (nodes.some((n) => n instanceof Element)) return false;
|
|
451
|
+
return true;
|
|
452
|
+
}
|
|
453
|
+
return false;
|
|
454
|
+
}).forEach((childNode) => {
|
|
455
|
+
if (childNode instanceof Text) {
|
|
456
|
+
mutableSubtrees.set(
|
|
457
|
+
positionnedChildrenCount,
|
|
458
|
+
new _Tree(childNode, this, positionnedChildrenCount)
|
|
459
|
+
);
|
|
460
|
+
positionnedChildrenCount += 1;
|
|
461
|
+
} else {
|
|
462
|
+
const propertyName = childNode.getAttribute(this.keyAttribute);
|
|
463
|
+
if (propertyName === null) {
|
|
464
|
+
mutableSubtrees.set(
|
|
465
|
+
positionnedChildrenCount,
|
|
466
|
+
new _Tree(childNode, this, positionnedChildrenCount)
|
|
467
|
+
);
|
|
468
|
+
positionnedChildrenCount += 1;
|
|
469
|
+
} else {
|
|
470
|
+
mutableSubtrees.set(
|
|
471
|
+
propertyName,
|
|
472
|
+
new _Tree(childNode, this, propertyName)
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
this.subtrees = mutableSubtrees;
|
|
478
|
+
this.children = Array.from(this.subtrees.values());
|
|
479
|
+
if (this.tagName === null) {
|
|
480
|
+
this.type = "text";
|
|
481
|
+
} else if (this.tagName === Types.TyperTagName.NULL) {
|
|
482
|
+
this.type = "null";
|
|
483
|
+
} else if (this.tagName === Types.TyperTagName.BOOLEAN) {
|
|
484
|
+
this.type = "boolean";
|
|
485
|
+
} else if (this.tagName === Types.TyperTagName.NUMBER) {
|
|
486
|
+
this.type = "number";
|
|
487
|
+
} else if (this.tagName === Types.TyperTagName.STRING) {
|
|
488
|
+
this.type = "string";
|
|
489
|
+
} else if (this.tagName === Types.TyperTagName.TEXT) {
|
|
490
|
+
this.type = "text";
|
|
491
|
+
} else if (this.tagName === Types.TyperTagName.NODELIST) {
|
|
492
|
+
this.type = "nodelist";
|
|
493
|
+
} else if (this.tagName === Types.TyperTagName.ARRAY) {
|
|
494
|
+
this.type = "array";
|
|
495
|
+
} else if (this.tagName === Types.TyperTagName.RECORD) {
|
|
496
|
+
this.type = "record";
|
|
497
|
+
} else if (this.generators.get(this.tagName) !== void 0) {
|
|
498
|
+
this.type = "transformer";
|
|
499
|
+
} else {
|
|
500
|
+
this.type = "element";
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
static defaultOptions = {
|
|
504
|
+
generatorsMap: Transformers.defaultGeneratorsMap,
|
|
505
|
+
keyAttribute: "_name",
|
|
506
|
+
actionAttribute: "_action"
|
|
507
|
+
};
|
|
508
|
+
static fillOptions(options) {
|
|
509
|
+
return {
|
|
510
|
+
..._Tree.defaultOptions,
|
|
511
|
+
...options
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
static mergeValues(currentValue, incomingValue, mergeKey, initiatorTree) {
|
|
515
|
+
const {
|
|
516
|
+
Element,
|
|
517
|
+
Text,
|
|
518
|
+
NodeList,
|
|
519
|
+
document: document2
|
|
520
|
+
} = getWindow2();
|
|
521
|
+
if (typeof incomingValue === "function") {
|
|
522
|
+
const evaluated = incomingValue(currentValue, initiatorTree);
|
|
523
|
+
if (evaluated.action === null) return currentValue;
|
|
524
|
+
if (evaluated.action === "REPLACE") return evaluated.value;
|
|
525
|
+
if (evaluated.action === "ERROR") {
|
|
526
|
+
const errorMessage = `Tranformer error:
|
|
527
|
+
from: ${incomingValue.transformerName}
|
|
528
|
+
at: ${initiatorTree.pathString.slice(1)}/${mergeKey}
|
|
529
|
+
message:`;
|
|
530
|
+
console.warn(errorMessage, evaluated.value);
|
|
531
|
+
return currentValue;
|
|
532
|
+
}
|
|
533
|
+
return _Tree.mergeValues(
|
|
534
|
+
currentValue,
|
|
535
|
+
evaluated.value,
|
|
536
|
+
mergeKey,
|
|
537
|
+
initiatorTree
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
if (Array.isArray(currentValue)) {
|
|
541
|
+
if (typeof mergeKey === "string") return currentValue;
|
|
542
|
+
return [...currentValue, incomingValue];
|
|
543
|
+
}
|
|
544
|
+
if (currentValue === null || typeof currentValue === "boolean" || typeof currentValue === "number" || typeof currentValue === "string" || typeof currentValue === "function" || currentValue instanceof Text || currentValue instanceof Element) {
|
|
545
|
+
if (incomingValue === null || typeof incomingValue === "boolean" || typeof incomingValue === "number" || typeof incomingValue === "string" || Array.isArray(incomingValue) || isRecord(incomingValue)) {
|
|
546
|
+
return incomingValue;
|
|
547
|
+
}
|
|
548
|
+
const frag = document2.createDocumentFragment();
|
|
549
|
+
if (currentValue instanceof Element || currentValue instanceof Text) frag.append(currentValue.cloneNode(true));
|
|
550
|
+
else frag.append(`${currentValue}`);
|
|
551
|
+
if (incomingValue instanceof Element || incomingValue instanceof Text) {
|
|
552
|
+
frag.append(incomingValue.cloneNode(true));
|
|
553
|
+
return frag.childNodes;
|
|
554
|
+
}
|
|
555
|
+
frag.append(...Array.from(incomingValue).map((e) => e.cloneNode(true)));
|
|
556
|
+
return frag.childNodes;
|
|
557
|
+
}
|
|
558
|
+
if (currentValue instanceof NodeList) {
|
|
559
|
+
if (incomingValue instanceof Element || incomingValue instanceof Text) {
|
|
560
|
+
const frag = document2.createDocumentFragment();
|
|
561
|
+
frag.append(...Array.from(currentValue).map((e) => e.cloneNode(true)), incomingValue);
|
|
562
|
+
return frag.childNodes;
|
|
563
|
+
}
|
|
564
|
+
if (incomingValue instanceof NodeList) {
|
|
565
|
+
const frag = document2.createDocumentFragment();
|
|
566
|
+
frag.append(
|
|
567
|
+
...Array.from(currentValue).map((e) => e.cloneNode(true)),
|
|
568
|
+
...Array.from(incomingValue).map((e) => e.cloneNode(true))
|
|
569
|
+
);
|
|
570
|
+
return frag.childNodes;
|
|
571
|
+
}
|
|
572
|
+
if (incomingValue === null || typeof incomingValue === "string" || typeof incomingValue === "number" || typeof incomingValue === "boolean") {
|
|
573
|
+
const frag = document2.createDocumentFragment();
|
|
574
|
+
frag.append(...Array.from(currentValue).map((e) => e.cloneNode(true)), `${incomingValue}`);
|
|
575
|
+
return frag.childNodes;
|
|
576
|
+
}
|
|
577
|
+
if (Array.isArray(incomingValue)) return [
|
|
578
|
+
...Array.from(currentValue),
|
|
579
|
+
...incomingValue
|
|
580
|
+
];
|
|
581
|
+
return { ...incomingValue };
|
|
582
|
+
}
|
|
583
|
+
if (typeof mergeKey === "number") return currentValue;
|
|
584
|
+
return {
|
|
585
|
+
...currentValue,
|
|
586
|
+
[mergeKey]: incomingValue
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
static mergeRootElements(...rootElements) {
|
|
590
|
+
const output = document.createElement("data");
|
|
591
|
+
rootElements.forEach((rootElement) => {
|
|
592
|
+
const nodes = [...Array.from(rootElement.cloneNode(true).childNodes)];
|
|
593
|
+
output.append(...nodes);
|
|
594
|
+
});
|
|
595
|
+
return output;
|
|
596
|
+
}
|
|
597
|
+
static reduceRootElement(rootElement, options) {
|
|
598
|
+
const { Element, Text, document: document2 } = getWindow2();
|
|
599
|
+
const _options = _Tree.fillOptions(options ?? {});
|
|
600
|
+
const { keyAttribute, actionAttribute } = _options;
|
|
601
|
+
const outputRootElement = rootElement.cloneNode();
|
|
602
|
+
let positionnedChildrenCount = 0;
|
|
603
|
+
const childrenMap = /* @__PURE__ */ new Map();
|
|
604
|
+
const children = Array.from(rootElement.childNodes).filter((e) => {
|
|
605
|
+
if (e instanceof Element) return true;
|
|
606
|
+
if (e instanceof Text) return true;
|
|
607
|
+
return false;
|
|
608
|
+
});
|
|
609
|
+
children.forEach((child) => {
|
|
610
|
+
if (child instanceof Text) {
|
|
611
|
+
childrenMap.set(positionnedChildrenCount, child);
|
|
612
|
+
outputRootElement.appendChild(child);
|
|
613
|
+
positionnedChildrenCount += 1;
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
const foundKey = child.getAttribute(keyAttribute);
|
|
617
|
+
const actionType = child.getAttribute(actionAttribute);
|
|
618
|
+
const targetKey = foundKey ?? positionnedChildrenCount;
|
|
619
|
+
if (foundKey === null) {
|
|
620
|
+
positionnedChildrenCount += 1;
|
|
621
|
+
}
|
|
622
|
+
const existingElement = childrenMap.get(targetKey);
|
|
623
|
+
if (existingElement === void 0) {
|
|
624
|
+
childrenMap.set(targetKey, child);
|
|
625
|
+
outputRootElement.appendChild(child);
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
if (actionType === Types.ReductionAction.APPEND || actionType === Types.ReductionAction.PREPEND) {
|
|
629
|
+
if (existingElement instanceof Text) {
|
|
630
|
+
if (child instanceof Text) {
|
|
631
|
+
const newTextNode = actionType === Types.ReductionAction.APPEND ? document2.createTextNode(`${existingElement.textContent}${child.textContent}`) : document2.createTextNode(`${child.textContent}${existingElement.textContent}`);
|
|
632
|
+
childrenMap.set(targetKey, newTextNode);
|
|
633
|
+
insertNode(newTextNode, "after", existingElement);
|
|
634
|
+
existingElement.remove();
|
|
635
|
+
return;
|
|
636
|
+
} else {
|
|
637
|
+
childrenMap.set(targetKey, child);
|
|
638
|
+
insertNode(child, "after", existingElement);
|
|
639
|
+
existingElement.remove();
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
} else {
|
|
643
|
+
if (child instanceof Text) {
|
|
644
|
+
childrenMap.set(targetKey, child);
|
|
645
|
+
insertNode(child, "after", existingElement);
|
|
646
|
+
existingElement.remove();
|
|
647
|
+
} else {
|
|
648
|
+
if (actionType === Types.ReductionAction.APPEND) existingElement.append(...Array.from(child.childNodes));
|
|
649
|
+
else existingElement.prepend(...Array.from(child.childNodes));
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
insertNode(child, "after", existingElement);
|
|
654
|
+
existingElement.remove();
|
|
655
|
+
childrenMap.set(targetKey, child);
|
|
656
|
+
});
|
|
657
|
+
const outputChildren = Array.from(outputRootElement.childNodes);
|
|
658
|
+
outputChildren.forEach((outputChild) => {
|
|
659
|
+
if (outputChild instanceof Element) {
|
|
660
|
+
const reduced = _Tree.reduceRootElement(outputChild);
|
|
661
|
+
insertNode(reduced, "after", outputChild);
|
|
662
|
+
outputChild.remove();
|
|
663
|
+
}
|
|
664
|
+
});
|
|
665
|
+
return outputRootElement;
|
|
666
|
+
}
|
|
667
|
+
resolve = function(path) {
|
|
668
|
+
let currentTree = this.root;
|
|
669
|
+
for (const chunk of path) {
|
|
670
|
+
const { subtrees } = currentTree;
|
|
671
|
+
const foundSubtree = subtrees.get(chunk);
|
|
672
|
+
if (foundSubtree === void 0) return void 0;
|
|
673
|
+
currentTree = foundSubtree;
|
|
674
|
+
}
|
|
675
|
+
return currentTree;
|
|
676
|
+
};
|
|
677
|
+
getGenerator(name) {
|
|
678
|
+
return this.generators.get(name);
|
|
679
|
+
}
|
|
680
|
+
initValue() {
|
|
681
|
+
const { type } = this;
|
|
682
|
+
let currentValue;
|
|
683
|
+
if (type === "null") {
|
|
684
|
+
currentValue = null;
|
|
685
|
+
} else if (type === "boolean") {
|
|
686
|
+
currentValue = false;
|
|
687
|
+
} else if (type === "number") {
|
|
688
|
+
currentValue = 0;
|
|
689
|
+
} else if (type === "string") {
|
|
690
|
+
currentValue = "";
|
|
691
|
+
} else if (type === "text") {
|
|
692
|
+
currentValue = this.node.textContent;
|
|
693
|
+
} else if (type === "element") {
|
|
694
|
+
currentValue = getWindow2().document.createDocumentFragment().childNodes;
|
|
695
|
+
} else if (type === "nodelist") {
|
|
696
|
+
currentValue = getWindow2().document.createDocumentFragment().childNodes;
|
|
697
|
+
} else if (type === "array") {
|
|
698
|
+
currentValue = [];
|
|
699
|
+
} else if (type === "record") {
|
|
700
|
+
currentValue = {};
|
|
701
|
+
} else if (type === "transformer") {
|
|
702
|
+
currentValue = [];
|
|
703
|
+
} else {
|
|
704
|
+
currentValue = null;
|
|
705
|
+
}
|
|
706
|
+
return currentValue;
|
|
707
|
+
}
|
|
708
|
+
getInnerValue(initialValue) {
|
|
709
|
+
const { subtrees } = this;
|
|
710
|
+
const innerValue = Array.from(subtrees.entries()).reduce((currentValue, [subpath, subtree]) => _Tree.mergeValues(
|
|
711
|
+
currentValue,
|
|
712
|
+
subtree.evaluate(),
|
|
713
|
+
subpath,
|
|
714
|
+
this
|
|
715
|
+
), initialValue);
|
|
716
|
+
return innerValue;
|
|
717
|
+
}
|
|
718
|
+
wrapInnerValue(innerValue) {
|
|
719
|
+
const { type } = this;
|
|
720
|
+
if (type === "transformer") {
|
|
721
|
+
const transformerName = this.tagName;
|
|
722
|
+
if (transformerName === null) return innerValue;
|
|
723
|
+
const generator = this.getGenerator(transformerName);
|
|
724
|
+
if (generator === void 0) return innerValue;
|
|
725
|
+
const transformer = Array.isArray(innerValue) ? generator(transformerName, ...innerValue) : generator(transformerName, innerValue);
|
|
726
|
+
return transformer;
|
|
727
|
+
}
|
|
728
|
+
if (type === "null") return Cast.toNull();
|
|
729
|
+
if (type === "boolean") return Cast.toBoolean(innerValue);
|
|
730
|
+
if (type === "number") return Cast.toNumber(innerValue);
|
|
731
|
+
if (type === "string") return Cast.toString(innerValue);
|
|
732
|
+
if (type === "array") return Cast.toArray(innerValue);
|
|
733
|
+
if (type === "record") return Cast.toRecord(innerValue);
|
|
734
|
+
if (type === "text") return Cast.toText(innerValue);
|
|
735
|
+
if (type === "element") return Cast.toElement(innerValue);
|
|
736
|
+
if (type === "nodelist") return Cast.toNodeList(innerValue);
|
|
737
|
+
return Cast.toNull();
|
|
738
|
+
}
|
|
739
|
+
cache = void 0;
|
|
740
|
+
setCache(value) {
|
|
741
|
+
this.cache = Serialize.serialize(value);
|
|
742
|
+
}
|
|
743
|
+
perfCounters = {
|
|
744
|
+
computed: 0,
|
|
745
|
+
computeTime: 0,
|
|
746
|
+
computeTimeAvg: 0,
|
|
747
|
+
cached: 0,
|
|
748
|
+
cacheTime: 0,
|
|
749
|
+
cacheTimeAvg: 0,
|
|
750
|
+
totalTime: 0
|
|
751
|
+
};
|
|
752
|
+
getPerfCounters() {
|
|
753
|
+
const { subtrees } = this;
|
|
754
|
+
const subCounters = [];
|
|
755
|
+
subCounters.push([this.pathString, this.perfCounters]);
|
|
756
|
+
subtrees.forEach((subtree) => subCounters.push(...subtree.getPerfCounters()));
|
|
757
|
+
return subCounters;
|
|
758
|
+
}
|
|
759
|
+
printPerfCounters() {
|
|
760
|
+
const perfCounters = this.getPerfCounters().sort((a, b) => b[1].totalTime - a[1].totalTime).map((e) => ({
|
|
761
|
+
path: e[0],
|
|
762
|
+
totalMs: e[1].totalTime,
|
|
763
|
+
computeMs: e[1].computeTime,
|
|
764
|
+
cacheMs: e[1].cacheTime,
|
|
765
|
+
ops: `${e[1].computed}/${e[1].cached}`
|
|
766
|
+
}));
|
|
767
|
+
console.table(perfCounters);
|
|
768
|
+
}
|
|
769
|
+
callstack = [];
|
|
770
|
+
pushToEvalCallStack(path) {
|
|
771
|
+
this.callstack.push(path);
|
|
772
|
+
this.parent?.pushToEvalCallStack(path);
|
|
773
|
+
}
|
|
774
|
+
flushEvalCallStack() {
|
|
775
|
+
this.callstack.length = 0;
|
|
776
|
+
}
|
|
777
|
+
evaluate() {
|
|
778
|
+
const start = Date.now();
|
|
779
|
+
const circularPatternDetected = this.callstack.some((p) => p.startsWith(this.pathString));
|
|
780
|
+
if (circularPatternDetected) throw new Error(`Circular reference pattern detected @ ${this.pathString}`);
|
|
781
|
+
this.pushToEvalCallStack(this.pathString);
|
|
782
|
+
const { perfCounters, cache } = this;
|
|
783
|
+
if (cache !== void 0) {
|
|
784
|
+
const deserialized = Serialize.deserialize(cache);
|
|
785
|
+
const end2 = Date.now();
|
|
786
|
+
const time2 = end2 - start;
|
|
787
|
+
perfCounters.cached++;
|
|
788
|
+
perfCounters.cacheTime += time2;
|
|
789
|
+
perfCounters.cacheTimeAvg = perfCounters.cacheTime / perfCounters.cached;
|
|
790
|
+
perfCounters.totalTime = perfCounters.computeTime + perfCounters.cacheTime;
|
|
791
|
+
return deserialized;
|
|
792
|
+
}
|
|
793
|
+
const init = this.initValue();
|
|
794
|
+
const inner = this.getInnerValue(init);
|
|
795
|
+
const wrapped = this.wrapInnerValue(inner);
|
|
796
|
+
this.setCache(wrapped);
|
|
797
|
+
const end = Date.now();
|
|
798
|
+
const time = end - start;
|
|
799
|
+
perfCounters.computed++;
|
|
800
|
+
perfCounters.computeTime += time;
|
|
801
|
+
perfCounters.computeTimeAvg = perfCounters.computeTime / perfCounters.computed;
|
|
802
|
+
perfCounters.totalTime = perfCounters.computeTime + perfCounters.cacheTime;
|
|
803
|
+
this.flushEvalCallStack();
|
|
804
|
+
return wrapped;
|
|
805
|
+
}
|
|
806
|
+
};
|
|
807
|
+
|
|
808
|
+
// src/agnostic/html/hyper-json/transformers/transformSelected/index.ts
|
|
809
|
+
var transformSelected = (callerTagName, ...args) => {
|
|
810
|
+
return Transformers.toNamed(callerTagName, (currentValue, callerTree) => {
|
|
811
|
+
const { NodeList, Element, Text } = Crossenv.getWindow();
|
|
812
|
+
if (!(currentValue instanceof Element) && !(currentValue instanceof NodeList)) return Utils.makeTransformerError({
|
|
813
|
+
message: "Current value must be Element or NodeList",
|
|
814
|
+
input: currentValue
|
|
815
|
+
});
|
|
816
|
+
const [selector, ...transformerDescriptors] = args;
|
|
817
|
+
if (typeof selector !== "string" && !(selector instanceof Text)) return Utils.makeTransformerError({
|
|
818
|
+
message: "Selector argument must be string or text",
|
|
819
|
+
input: selector !== void 0 ? selector : "<undefined>"
|
|
820
|
+
});
|
|
821
|
+
if (transformerDescriptors.length === 0) return Utils.makeTransformerError("No transformer descriptor provided");
|
|
822
|
+
let transformers = [];
|
|
823
|
+
for (const descriptor of transformerDescriptors) {
|
|
824
|
+
const errorResponse = Utils.makeTransformerError({
|
|
825
|
+
message: "Transformer descriptors must be of shape { name: string, arguments: Value[] }",
|
|
826
|
+
input: descriptor
|
|
827
|
+
});
|
|
828
|
+
if (!isRecord(descriptor)) return errorResponse;
|
|
829
|
+
if (!("name" in descriptor) || typeof descriptor.name !== "string") return errorResponse;
|
|
830
|
+
if (!("arguments" in descriptor) || !Array.isArray(descriptor.arguments)) return errorResponse;
|
|
831
|
+
const { name, arguments: args2 } = descriptor;
|
|
832
|
+
const generator = callerTree.getGenerator(name);
|
|
833
|
+
if (generator === void 0) return Utils.makeTransformerError(`No transformer found under the name ${name}`);
|
|
834
|
+
transformers.push(generator(name, ...args2));
|
|
835
|
+
}
|
|
836
|
+
const elementInput = Cast.toElement(currentValue);
|
|
837
|
+
const strSelector = Cast.toString(selector);
|
|
838
|
+
const selected = Array.from(elementInput.querySelectorAll(strSelector));
|
|
839
|
+
const transformationErrors = [];
|
|
840
|
+
const transformed = selected.map((input) => {
|
|
841
|
+
const output = transformers.reduce((reduced, transformer, transformerPos) => {
|
|
842
|
+
const result = transformer(reduced, callerTree);
|
|
843
|
+
if (result.action === "REPLACE") return result.value;
|
|
844
|
+
else if (result.action === "MERGE") {
|
|
845
|
+
const merged = Tree.mergeValues(
|
|
846
|
+
reduced,
|
|
847
|
+
result.value,
|
|
848
|
+
transformerPos,
|
|
849
|
+
callerTree
|
|
850
|
+
);
|
|
851
|
+
return merged;
|
|
852
|
+
}
|
|
853
|
+
if (result.action === "ERROR") transformationErrors.push({
|
|
854
|
+
message: result.value,
|
|
855
|
+
transformerName: transformer.transformerName,
|
|
856
|
+
transformerPos,
|
|
857
|
+
transforming: reduced
|
|
858
|
+
});
|
|
859
|
+
return reduced;
|
|
860
|
+
}, input);
|
|
861
|
+
return { input, output };
|
|
862
|
+
});
|
|
863
|
+
if (transformationErrors.length !== 0) return Utils.makeTransformerError({
|
|
864
|
+
message: "Some nested transformers returned an error",
|
|
865
|
+
errors: transformationErrors
|
|
866
|
+
});
|
|
867
|
+
const nonElementTransformResult = transformed.find((item) => !(item.output instanceof Element));
|
|
868
|
+
if (nonElementTransformResult !== void 0) return Utils.makeTransformerError({
|
|
869
|
+
message: "Some transformations resulted in a non Element output",
|
|
870
|
+
inputElement: nonElementTransformResult.input,
|
|
871
|
+
outputValue: nonElementTransformResult.output
|
|
872
|
+
});
|
|
873
|
+
const transformMap = new Map(transformed.map((e) => [e.input, e.output]));
|
|
874
|
+
const elementOutput = replaceInElement(elementInput, transformMap);
|
|
875
|
+
return {
|
|
876
|
+
action: "REPLACE",
|
|
877
|
+
value: elementOutput
|
|
878
|
+
};
|
|
879
|
+
});
|
|
880
|
+
};
|
|
881
|
+
|
|
882
|
+
// src/agnostic/html/hyper-json/transformers/trim/index.ts
|
|
883
|
+
var trim = (callerTagName) => {
|
|
884
|
+
return Transformers.toNamed(callerTagName, (currentValue) => {
|
|
885
|
+
const { Text } = Crossenv.getWindow();
|
|
886
|
+
if (typeof currentValue !== "string" && !(currentValue instanceof Text)) return Utils.makeTransformerError({
|
|
887
|
+
message: "Current value must be of type string or Text",
|
|
888
|
+
input: currentValue
|
|
889
|
+
});
|
|
890
|
+
const inputStr = Cast.toString(currentValue);
|
|
891
|
+
const trimmed = inputStr.trim();
|
|
892
|
+
return {
|
|
893
|
+
action: "REPLACE",
|
|
894
|
+
value: currentValue instanceof Text ? Cast.toText(trimmed) : trimmed
|
|
895
|
+
};
|
|
896
|
+
});
|
|
897
|
+
};
|
|
898
|
+
|
|
899
|
+
// src/agnostic/html/hyper-json/transformers/index.ts
|
|
900
|
+
var Transformers;
|
|
901
|
+
((Transformers2) => {
|
|
902
|
+
Transformers2.defaultGeneratorsMap = /* @__PURE__ */ new Map([
|
|
903
|
+
["append", append],
|
|
904
|
+
["classList", classList],
|
|
905
|
+
["join", join],
|
|
906
|
+
["length", length],
|
|
907
|
+
["print", print],
|
|
908
|
+
["push", push],
|
|
909
|
+
["querySelector", querySelector],
|
|
910
|
+
["ref", ref],
|
|
911
|
+
["replace", replace],
|
|
912
|
+
["split", split],
|
|
913
|
+
["toArray", toArray],
|
|
914
|
+
["toBoolean", toBoolean],
|
|
915
|
+
["toElement", toElement],
|
|
916
|
+
["toNodeList", toNodeList],
|
|
917
|
+
["toNull", toNull],
|
|
918
|
+
["toNumber", toNumber],
|
|
919
|
+
["toRecord", toRecord],
|
|
920
|
+
["toRef", toRef],
|
|
921
|
+
["toString", toString],
|
|
922
|
+
["toText", toText],
|
|
923
|
+
["toTransformer", toTransformer],
|
|
924
|
+
["transformSelected", transformSelected],
|
|
925
|
+
["trim", trim]
|
|
926
|
+
]);
|
|
927
|
+
Transformers2.toNamed = (name, anonymous) => {
|
|
928
|
+
const named = anonymous;
|
|
929
|
+
named.transformerName = name;
|
|
930
|
+
return named;
|
|
931
|
+
};
|
|
932
|
+
})(Transformers || (Transformers = {}));
|
|
933
|
+
|
|
934
|
+
// src/agnostic/html/hyper-json/transformers/append/index.ts
|
|
935
|
+
var append = (callerTagName, ...args) => {
|
|
936
|
+
return Transformers.toNamed(callerTagName, (currentValue) => {
|
|
937
|
+
const { document: document2, Element, Text, NodeList } = Crossenv.getWindow();
|
|
938
|
+
const [...toAppend] = args;
|
|
939
|
+
const frag = document2.createDocumentFragment();
|
|
940
|
+
frag.append(...Array.from(Cast.toNodeList(currentValue)).map((e) => e.cloneNode(true)));
|
|
941
|
+
toAppend.forEach((item) => {
|
|
942
|
+
if (item instanceof Element) frag.append(item.cloneNode(true));
|
|
943
|
+
else if (item instanceof Text) frag.append(item.cloneNode(true));
|
|
944
|
+
else if (item instanceof NodeList) frag.append(...Array.from(item).map((e) => e.cloneNode(true)));
|
|
945
|
+
else frag.append(Cast.toString(item));
|
|
946
|
+
});
|
|
947
|
+
return {
|
|
948
|
+
action: "REPLACE",
|
|
949
|
+
value: frag.childNodes
|
|
950
|
+
};
|
|
951
|
+
});
|
|
952
|
+
};
|
|
953
|
+
|
|
954
|
+
export {
|
|
955
|
+
append,
|
|
956
|
+
classList,
|
|
957
|
+
join,
|
|
958
|
+
length,
|
|
959
|
+
print,
|
|
960
|
+
push,
|
|
961
|
+
querySelector,
|
|
962
|
+
ref,
|
|
963
|
+
replace,
|
|
964
|
+
split,
|
|
965
|
+
toArray,
|
|
966
|
+
toBoolean,
|
|
967
|
+
toElement,
|
|
968
|
+
toNodeList,
|
|
969
|
+
toNull,
|
|
970
|
+
toNumber,
|
|
971
|
+
toRecord,
|
|
972
|
+
toRef,
|
|
973
|
+
toString,
|
|
974
|
+
toText,
|
|
975
|
+
toTransformer,
|
|
976
|
+
Tree,
|
|
977
|
+
transformSelected,
|
|
978
|
+
trim,
|
|
979
|
+
Transformers,
|
|
980
|
+
Cast
|
|
981
|
+
};
|