@design-edito/tools 0.1.49 → 0.1.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/agnostic/arrays/index.d.ts +2 -0
  2. package/agnostic/arrays/index.js +7 -6
  3. package/agnostic/arrays/random-pick/index.js +4 -4
  4. package/agnostic/arrays/shuffle/index.d.ts +1 -0
  5. package/agnostic/arrays/shuffle/index.js +6 -0
  6. package/agnostic/css/bem/index.js +2 -2
  7. package/agnostic/css/index.js +12 -12
  8. package/agnostic/css/styles-set/index.js +4 -4
  9. package/agnostic/errors/register/index.d.ts +1 -0
  10. package/agnostic/html/hyper-json/cast/index.js +3 -3
  11. package/agnostic/html/hyper-json/index.js +4 -4
  12. package/agnostic/html/hyper-json/smart-tags/coalesced/add/index.js +3 -3
  13. package/agnostic/html/hyper-json/smart-tags/coalesced/addclass/index.js +3 -3
  14. package/agnostic/html/hyper-json/smart-tags/coalesced/and/index.js +3 -3
  15. package/agnostic/html/hyper-json/smart-tags/coalesced/append/index.js +3 -3
  16. package/agnostic/html/hyper-json/smart-tags/coalesced/at/index.js +3 -3
  17. package/agnostic/html/hyper-json/smart-tags/coalesced/call/index.js +3 -3
  18. package/agnostic/html/hyper-json/smart-tags/coalesced/clone/index.js +3 -3
  19. package/agnostic/html/hyper-json/smart-tags/coalesced/deleteproperties/index.js +3 -3
  20. package/agnostic/html/hyper-json/smart-tags/coalesced/equals/index.js +3 -3
  21. package/agnostic/html/hyper-json/smart-tags/coalesced/getattribute/index.js +3 -3
  22. package/agnostic/html/hyper-json/smart-tags/coalesced/getproperties/index.js +3 -3
  23. package/agnostic/html/hyper-json/smart-tags/coalesced/getproperty/index.js +3 -3
  24. package/agnostic/html/hyper-json/smart-tags/coalesced/if/index.js +3 -3
  25. package/agnostic/html/hyper-json/smart-tags/coalesced/initialize/index.js +3 -3
  26. package/agnostic/html/hyper-json/smart-tags/coalesced/join/index.js +3 -3
  27. package/agnostic/html/hyper-json/smart-tags/coalesced/length/index.js +3 -3
  28. package/agnostic/html/hyper-json/smart-tags/coalesced/map/index.js +3 -3
  29. package/agnostic/html/hyper-json/smart-tags/coalesced/negate/index.js +3 -3
  30. package/agnostic/html/hyper-json/smart-tags/coalesced/notrailing/index.js +3 -3
  31. package/agnostic/html/hyper-json/smart-tags/coalesced/or/index.js +3 -3
  32. package/agnostic/html/hyper-json/smart-tags/coalesced/pickrandom/index.js +3 -3
  33. package/agnostic/html/hyper-json/smart-tags/coalesced/populate/index.js +3 -3
  34. package/agnostic/html/hyper-json/smart-tags/coalesced/print/index.js +3 -3
  35. package/agnostic/html/hyper-json/smart-tags/coalesced/push/index.js +3 -3
  36. package/agnostic/html/hyper-json/smart-tags/coalesced/pusheach/index.js +3 -3
  37. package/agnostic/html/hyper-json/smart-tags/coalesced/recordtoarray/index.js +3 -3
  38. package/agnostic/html/hyper-json/smart-tags/coalesced/removeattribute/index.js +3 -3
  39. package/agnostic/html/hyper-json/smart-tags/coalesced/removeclass/index.js +3 -3
  40. package/agnostic/html/hyper-json/smart-tags/coalesced/renameproperty/index.js +3 -3
  41. package/agnostic/html/hyper-json/smart-tags/coalesced/replace/index.js +3 -3
  42. package/agnostic/html/hyper-json/smart-tags/coalesced/select/index.js +3 -3
  43. package/agnostic/html/hyper-json/smart-tags/coalesced/set/index.js +3 -3
  44. package/agnostic/html/hyper-json/smart-tags/coalesced/setattribute/index.js +3 -3
  45. package/agnostic/html/hyper-json/smart-tags/coalesced/setproperty/index.js +3 -3
  46. package/agnostic/html/hyper-json/smart-tags/coalesced/sorton/index.js +3 -3
  47. package/agnostic/html/hyper-json/smart-tags/coalesced/split/index.js +3 -3
  48. package/agnostic/html/hyper-json/smart-tags/coalesced/spread/index.js +3 -3
  49. package/agnostic/html/hyper-json/smart-tags/coalesced/toarray/index.js +3 -3
  50. package/agnostic/html/hyper-json/smart-tags/coalesced/toboolean/index.js +3 -3
  51. package/agnostic/html/hyper-json/smart-tags/coalesced/toelement/index.js +3 -3
  52. package/agnostic/html/hyper-json/smart-tags/coalesced/toggleclass/index.js +3 -3
  53. package/agnostic/html/hyper-json/smart-tags/coalesced/tonodelist/index.js +3 -3
  54. package/agnostic/html/hyper-json/smart-tags/coalesced/tonull/index.js +3 -3
  55. package/agnostic/html/hyper-json/smart-tags/coalesced/tonumber/index.js +3 -3
  56. package/agnostic/html/hyper-json/smart-tags/coalesced/torecord/index.js +3 -3
  57. package/agnostic/html/hyper-json/smart-tags/coalesced/toref/index.js +3 -3
  58. package/agnostic/html/hyper-json/smart-tags/coalesced/tostring/index.js +3 -3
  59. package/agnostic/html/hyper-json/smart-tags/coalesced/totext/index.js +3 -3
  60. package/agnostic/html/hyper-json/smart-tags/coalesced/transformselected/index.js +3 -3
  61. package/agnostic/html/hyper-json/smart-tags/coalesced/trim/index.js +3 -3
  62. package/agnostic/html/hyper-json/smart-tags/isolated/boolean/index.js +3 -3
  63. package/agnostic/html/hyper-json/smart-tags/isolated/element/index.js +3 -3
  64. package/agnostic/html/hyper-json/smart-tags/isolated/get/index.js +3 -3
  65. package/agnostic/html/hyper-json/smart-tags/isolated/global/index.js +3 -3
  66. package/agnostic/html/hyper-json/smart-tags/isolated/guess/index.js +3 -3
  67. package/agnostic/html/hyper-json/smart-tags/isolated/nodelist/index.js +3 -3
  68. package/agnostic/html/hyper-json/smart-tags/isolated/number/index.js +3 -3
  69. package/agnostic/html/hyper-json/smart-tags/isolated/record/index.js +3 -3
  70. package/agnostic/html/hyper-json/smart-tags/isolated/ref/index.js +3 -3
  71. package/agnostic/html/hyper-json/smart-tags/isolated/string/index.js +3 -3
  72. package/agnostic/html/hyper-json/smart-tags/isolated/text/index.js +3 -3
  73. package/agnostic/html/hyper-json/tree/index.js +3 -3
  74. package/agnostic/html/hyper-json/utils/index.js +3 -3
  75. package/agnostic/html/index.js +20 -20
  76. package/agnostic/html/sanitize/index.js +4 -4
  77. package/agnostic/html/selector-to-element/index.js +4 -4
  78. package/agnostic/html/string-to-nodes/index.js +5 -5
  79. package/agnostic/misc/crossenv/index.js +2 -2
  80. package/agnostic/misc/data-size/index.d.ts +41 -0
  81. package/agnostic/misc/data-size/index.js +6 -0
  82. package/agnostic/misc/index.d.ts +5 -2
  83. package/agnostic/misc/index.js +32 -24
  84. package/agnostic/misc/logs/index.js +2 -2
  85. package/agnostic/misc/lorem-ipsum/index.js +11 -10
  86. package/agnostic/numbers/index.js +3 -3
  87. package/agnostic/objects/index.js +11 -11
  88. package/agnostic/strings/index.js +8 -8
  89. package/agnostic/time/index.js +4 -4
  90. package/chunks/chunk-2U2J4P3O.js +31 -0
  91. package/chunks/chunk-3C3MXKEW.js +31 -0
  92. package/chunks/chunk-42ZKFWKF.js +2369 -0
  93. package/chunks/chunk-4EFX53Y4.js +31 -0
  94. package/chunks/chunk-5CYZ66VE.js +31 -0
  95. package/chunks/chunk-5E7N4BDI.js +186 -0
  96. package/chunks/chunk-5UM7HYXS.js +191 -0
  97. package/chunks/chunk-5VHXL242.js +37 -0
  98. package/chunks/chunk-64SYLWJ7.js +37 -0
  99. package/chunks/chunk-66X6D4HF.js +191 -0
  100. package/chunks/chunk-6A7GLDXD.js +191 -0
  101. package/chunks/chunk-6KWNKTNI.js +173 -0
  102. package/chunks/chunk-75DDEILC.js +191 -0
  103. package/chunks/chunk-7GIJUKYP.js +173 -0
  104. package/chunks/chunk-7VTVA56L.js +37 -0
  105. package/chunks/chunk-7W5LABV2.js +37 -0
  106. package/chunks/chunk-D2V6SYYA.js +191 -0
  107. package/chunks/chunk-D6VWX3D6.js +186 -0
  108. package/chunks/chunk-DLSXW4NB.js +2369 -0
  109. package/chunks/chunk-H7WUTMKQ.js +31 -0
  110. package/chunks/chunk-JRXEHYIE.js +37 -0
  111. package/chunks/chunk-JUIKU4XP.js +191 -0
  112. package/chunks/chunk-LXPG32TV.js +31 -0
  113. package/chunks/chunk-M6WWIEQJ.js +37 -0
  114. package/chunks/chunk-M7YNPJYY.js +173 -0
  115. package/chunks/chunk-MBWRDYGE.js +191 -0
  116. package/chunks/chunk-O2WG3EMN.js +2369 -0
  117. package/chunks/chunk-PLIJVLAB.js +173 -0
  118. package/chunks/chunk-QI67BXO6.js +2370 -0
  119. package/chunks/chunk-RI37ZSKY.js +2369 -0
  120. package/chunks/chunk-RRSHCFEP.js +191 -0
  121. package/chunks/chunk-TYJOCMG7.js +37 -0
  122. package/chunks/chunk-U32YPAPW.js +2369 -0
  123. package/chunks/chunk-UODICVLG.js +173 -0
  124. package/chunks/chunk-VH4FK3TX.js +31 -0
  125. package/chunks/chunk-VJJIYJMY.js +13 -0
  126. package/chunks/chunk-VV35APGM.js +2369 -0
  127. package/chunks/chunk-WP7L5ZFP.js +173 -0
  128. package/chunks/chunk-WYY3N6PO.js +2369 -0
  129. package/chunks/chunk-XGOWRHVM.js +37 -0
  130. package/chunks/chunk-XK2PI5WI.js +31 -0
  131. package/chunks/chunk-XL7AQDAE.js +31 -0
  132. package/chunks/chunk-XRUSQWPJ.js +173 -0
  133. package/chunks/chunk-YYYRFMNZ.js +191 -0
  134. package/node/files/index.js +3 -3
  135. package/package.json +4 -8
  136. package/shared/errors/index.d.ts +1 -0
@@ -0,0 +1,2369 @@
1
+ import {
2
+ nullFunc
3
+ } from "./chunk-QAVYONH6.js";
4
+ import {
5
+ Serialize
6
+ } from "./chunk-SXRWMH3U.js";
7
+ import {
8
+ Types
9
+ } from "./chunk-XEQ2PBT2.js";
10
+ import {
11
+ any
12
+ } from "./chunk-FHLCPVND.js";
13
+ import {
14
+ array
15
+ } from "./chunk-QAQZEKIF.js";
16
+ import {
17
+ SmartTags
18
+ } from "./chunk-UT2J62LH.js";
19
+ import {
20
+ Transformer
21
+ } from "./chunk-BKO7GLC2.js";
22
+ import {
23
+ Method
24
+ } from "./chunk-RW7VAKJW.js";
25
+ import {
26
+ insertNode
27
+ } from "./chunk-XA4HVHJ4.js";
28
+ import {
29
+ Outcome
30
+ } from "./chunk-JMU5PDBD.js";
31
+ import {
32
+ recordMap
33
+ } from "./chunk-XNF5MLCQ.js";
34
+ import {
35
+ isInEnum
36
+ } from "./chunk-E6MSDKON.js";
37
+ import {
38
+ isRecord
39
+ } from "./chunk-YDIBNEGA.js";
40
+ import {
41
+ replaceAll
42
+ } from "./chunk-ZTDVUXPR.js";
43
+ import {
44
+ trimEnd,
45
+ trimStart
46
+ } from "./chunk-6XL25OZX.js";
47
+ import {
48
+ Window
49
+ } from "./chunk-RLJOYG64.js";
50
+
51
+ // src/agnostic/html/hyper-json/cast/index.ts
52
+ var Cast;
53
+ ((Cast2) => {
54
+ Cast2.toNull = () => null;
55
+ Cast2.toBoolean = (input) => {
56
+ const { Text: Text2 } = Window.get();
57
+ if (input === null) return false;
58
+ if (typeof input === "boolean") return input;
59
+ if (typeof input === "number") return input !== 0;
60
+ if (typeof input === "string" || input instanceof Text2) {
61
+ const strInput = (0, Cast2.toString)(input);
62
+ if (strInput.trim() === "") return false;
63
+ if (strInput.trim().toLowerCase() === "false") return false;
64
+ return true;
65
+ }
66
+ return true;
67
+ };
68
+ Cast2.toNumber = (input) => {
69
+ const { Text: Text2 } = Window.get();
70
+ if (typeof input === "boolean") return input ? 1 : 0;
71
+ if (typeof input === "number") return input;
72
+ if (typeof input === "string") return parseFloat(`${input}`);
73
+ if (input instanceof Text2) return parseFloat(`${input.textContent}`);
74
+ return 0;
75
+ };
76
+ Cast2.toString = (input) => {
77
+ if (typeof input === "string") return input;
78
+ if (typeof input === "number" || typeof input === "boolean" || input === null) return `${input}`;
79
+ const { Element: Element2, Text: Text2, NodeList } = Window.get();
80
+ if (input instanceof Element2) return input.outerHTML;
81
+ if (input instanceof Text2) return input.textContent ?? "";
82
+ if (input instanceof NodeList) return Array.from(input).map((e) => {
83
+ if (e instanceof Element2) return e.outerHTML;
84
+ return e.textContent;
85
+ }).join("");
86
+ if (Array.isArray(input)) return input.map(Cast2.toString).join("");
87
+ if (input instanceof Method) return `[Method:${input.transformer.name}]`;
88
+ return `{${Object.entries(input).map(([key, val]) => `${key}:"${(0, Cast2.toString)(val)}"`).join(",")}}`;
89
+ };
90
+ Cast2.toText = (input) => {
91
+ const { Text: Text2, document: document2 } = Window.get();
92
+ if (input instanceof Text2) return input.cloneNode(true);
93
+ return document2.createTextNode((0, Cast2.toString)(input));
94
+ };
95
+ Cast2.toElement = (input) => {
96
+ const { Element: Element2, Text: Text2, NodeList, document: document2 } = Window.get();
97
+ if (input instanceof Element2) return input.cloneNode(true);
98
+ const returned = document2.createElement("div");
99
+ if (input instanceof Text2) {
100
+ returned.append(input.cloneNode(true));
101
+ return returned;
102
+ }
103
+ if (input instanceof NodeList) {
104
+ returned.append(...Array.from(input).map((e) => e.cloneNode(true)));
105
+ return returned;
106
+ }
107
+ if (Array.isArray(input)) return returned;
108
+ if (isRecord(input)) return returned;
109
+ returned.innerHTML = `${input}`;
110
+ return returned;
111
+ };
112
+ Cast2.toNodeList = (input) => {
113
+ const { Element: Element2, Text: Text2, NodeList, document: document2 } = Window.get();
114
+ const parentDiv = document2.createElement("div");
115
+ if (input instanceof NodeList) {
116
+ parentDiv.append(...Array.from(input).map((i) => i.cloneNode(true)));
117
+ return parentDiv.childNodes;
118
+ }
119
+ if (input instanceof Element2 || input instanceof Text2) {
120
+ parentDiv.append(input.cloneNode(true));
121
+ return parentDiv.childNodes;
122
+ }
123
+ if (Array.isArray(input)) {
124
+ input.forEach((item) => {
125
+ if (typeof item === "number" || typeof item === "boolean" || item === null) parentDiv.append(`${item}`);
126
+ else if (typeof item === "string" || item instanceof Text2 || item instanceof Element2) parentDiv.append(item);
127
+ else if (item instanceof NodeList) parentDiv.append(...Array.from(item));
128
+ else if (Array.isArray(item)) parentDiv.append(...Array.from((0, Cast2.toNodeList)(item)));
129
+ else parentDiv.append((0, Cast2.toString)(item));
130
+ });
131
+ return parentDiv.childNodes;
132
+ }
133
+ if (isRecord(input)) {
134
+ parentDiv.append((0, Cast2.toString)(input));
135
+ return parentDiv.childNodes;
136
+ }
137
+ parentDiv.innerHTML = `${input}`;
138
+ return parentDiv.childNodes;
139
+ };
140
+ Cast2.toArray = (input) => {
141
+ const { NodeList } = Window.get();
142
+ if (Array.isArray(input)) return [...input];
143
+ if (input instanceof NodeList) return Array.from(input);
144
+ return [input];
145
+ };
146
+ Cast2.toRecord = (input) => {
147
+ const isRecord2 = Utils.Tree.TypeChecks.typeCheck(input, "record");
148
+ if (isRecord2.success) return { ...isRecord2.payload };
149
+ return {};
150
+ };
151
+ })(Cast || (Cast = {}));
152
+
153
+ // src/agnostic/html/hyper-json/smart-tags/isolated/element/index.ts
154
+ var element = SmartTags.makeSmartTag({
155
+ name: "element",
156
+ defaultMode: "isolation",
157
+ isolationInitType: "array",
158
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "string", "text"),
159
+ argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "null", "boolean", "number", "string", "text", "element", "nodelist"),
160
+ func: (main, args) => {
161
+ const tagName = Cast.toString(main).trim().toLowerCase();
162
+ const { document: document2, NodeList } = Window.get();
163
+ const elt = document2.createElement(tagName);
164
+ for (const argVal of args) {
165
+ if (argVal instanceof NodeList) elt.append(...Array.from(argVal));
166
+ else if (argVal instanceof Element) elt.append(argVal);
167
+ else elt.append(Cast.toText(argVal));
168
+ }
169
+ return Outcome.makeSuccess(elt);
170
+ }
171
+ });
172
+
173
+ // src/agnostic/html/hyper-json/smart-tags/isolated/get/index.ts
174
+ var get = SmartTags.makeSmartTag({
175
+ name: "get",
176
+ defaultMode: "isolation",
177
+ isolationInitType: "array",
178
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "string", "text"),
179
+ argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
180
+ func: (main, _args, { sourceTree }) => {
181
+ const { makeSuccess, makeFailure } = Outcome;
182
+ const { makeTransformationError } = Utils.SmartTags;
183
+ const strName = Cast.toString(main);
184
+ const found = sourceTree.getVariable(strName);
185
+ if (found === void 0) return makeFailure(makeTransformationError(`No variable stored under the name '${strName}'`));
186
+ return makeSuccess(found);
187
+ }
188
+ });
189
+
190
+ // src/agnostic/html/hyper-json/smart-tags/isolated/global/index.ts
191
+ var global = SmartTags.makeSmartTag({
192
+ name: "global",
193
+ defaultMode: "isolation",
194
+ isolationInitType: "array",
195
+ mainValueCheck: (m) => Outcome.makeSuccess(m),
196
+ argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
197
+ func: (_m, _a, { sourceTree }) => {
198
+ const globalObject = sourceTree.options.globalObject ?? {};
199
+ return Outcome.makeSuccess({ ...globalObject });
200
+ }
201
+ });
202
+
203
+ // src/agnostic/html/hyper-json/smart-tags/isolated/guess/index.ts
204
+ var guess = SmartTags.makeSmartTag({
205
+ name: "guess",
206
+ defaultMode: "isolation",
207
+ isolationInitType: "string",
208
+ mainValueCheck: (m) => Outcome.makeSuccess(m),
209
+ argsValueCheck: (a) => Outcome.makeSuccess(a),
210
+ func: (main, args) => {
211
+ const { typeCheck } = Utils.Tree.TypeChecks;
212
+ const { makeSuccess } = Outcome;
213
+ let coalesced = main;
214
+ for (const arg of args) coalesced = Utils.coalesceValues(coalesced, 0, arg);
215
+ const { Text: Text2, Element: Element2, document: document2 } = Window.get();
216
+ if (typeof coalesced !== "string" && !(coalesced instanceof Text2)) return makeSuccess(coalesced);
217
+ const strCoalesced = Cast.toString(coalesced);
218
+ if (strCoalesced.trim().toLowerCase() === "true") return makeSuccess(true);
219
+ if (strCoalesced.trim().toLowerCase() === "false") return makeSuccess(false);
220
+ if (strCoalesced.trim().toLowerCase().match(/^\s*-?\s*(\d+(\.\d*)?|\.\d+)\s*$/)) return makeSuccess(parseFloat(strCoalesced));
221
+ if (strCoalesced.trim().toLowerCase() === "null") return makeSuccess(null);
222
+ try {
223
+ const parsed = JSON.parse(strCoalesced);
224
+ const arrayChecked = typeCheck(parsed, "array");
225
+ const recordChecked = typeCheck(parsed, "record");
226
+ if (arrayChecked.success) return makeSuccess(arrayChecked.payload);
227
+ if (recordChecked.success) return makeSuccess(recordChecked.payload);
228
+ } catch (err) {
229
+ }
230
+ const div = document2.createElement("div");
231
+ div.innerHTML = strCoalesced;
232
+ const divChildren = div.childNodes;
233
+ if (divChildren.length === 0) return makeSuccess(coalesced);
234
+ const validDivChildren = Cast.toNodeList(Array.from(divChildren).filter((e) => {
235
+ if (e instanceof Element2) return true;
236
+ if (e instanceof Text2) return true;
237
+ return false;
238
+ }));
239
+ if (validDivChildren.length > 1) return makeSuccess(validDivChildren);
240
+ const validDivFirstchild = validDivChildren.item(0);
241
+ if (validDivChildren.length === 1 && validDivFirstchild instanceof Element2) return makeSuccess(validDivFirstchild);
242
+ return makeSuccess(coalesced);
243
+ }
244
+ });
245
+
246
+ // src/agnostic/html/hyper-json/smart-tags/isolated/nodelist/index.ts
247
+ var nodelist = SmartTags.makeSmartTag({
248
+ name: "nodelist",
249
+ defaultMode: "isolation",
250
+ isolationInitType: "nodelist",
251
+ mainValueCheck: (m) => Outcome.makeSuccess(m),
252
+ argsValueCheck: (a) => Outcome.makeSuccess(a),
253
+ func: (main, args) => {
254
+ const { document: document2 } = Window.get();
255
+ const returnedParent = document2.createDocumentFragment();
256
+ returnedParent.append(
257
+ ...Array.from(Cast.toNodeList(main)),
258
+ ...Array.from(Cast.toNodeList(args))
259
+ );
260
+ const returned = returnedParent.childNodes;
261
+ return Outcome.makeSuccess(returned);
262
+ }
263
+ });
264
+
265
+ // src/agnostic/html/hyper-json/smart-tags/isolated/number/index.ts
266
+ var number = SmartTags.makeSmartTag({
267
+ name: "number",
268
+ defaultMode: "isolation",
269
+ isolationInitType: "number",
270
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "null", "boolean", "number", "string", "text"),
271
+ argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "null", "boolean", "number", "string", "text"),
272
+ func: (main, args) => {
273
+ const all = [main, ...args];
274
+ const reduced = all.reduce((reduced2, curr) => {
275
+ return reduced2 + Cast.toNumber(curr);
276
+ }, 0);
277
+ return Outcome.makeSuccess(reduced);
278
+ }
279
+ });
280
+
281
+ // src/agnostic/html/hyper-json/smart-tags/isolated/record/index.ts
282
+ var record = SmartTags.makeSmartTag({
283
+ name: "record",
284
+ defaultMode: "isolation",
285
+ isolationInitType: "record",
286
+ mainValueCheck: (i) => Utils.Tree.TypeChecks.typeCheck(i, "record"),
287
+ argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "record"),
288
+ func: (main, args) => Outcome.makeSuccess(args.reduce((reduced, current) => ({
289
+ ...reduced,
290
+ ...current
291
+ }), main))
292
+ });
293
+
294
+ // src/agnostic/html/hyper-json/smart-tags/isolated/ref/index.ts
295
+ var func = (main, _args, { sourceTree }) => {
296
+ const { makeFailure, makeSuccess } = Outcome;
297
+ const { makeTransformationError } = Utils.SmartTags;
298
+ const strMain = Cast.toString(main);
299
+ const resolveFrom = strMain.startsWith("/") ? sourceTree.root : sourceTree;
300
+ const splitted = strMain.split("/").filter((e) => e.trim() !== "").map((e) => {
301
+ const looksLikeNumber = e.match(/^\d+$/igm);
302
+ if (looksLikeNumber === null) return e;
303
+ const parsed = parseInt(e);
304
+ if (Number.isNaN(parsed)) return e;
305
+ return parsed;
306
+ });
307
+ const resolved = resolveFrom.resolve(splitted);
308
+ if (resolved === void 0) return makeFailure(makeTransformationError(`No value was found at path: ${strMain}`));
309
+ if (resolved === sourceTree) return makeFailure(makeTransformationError("A ref node cannot reference itself."));
310
+ if (resolved.parents.includes(sourceTree)) return makeFailure(makeTransformationError("A ref node cannot reference one of its parents."));
311
+ if (sourceTree.parents.includes(resolved)) return makeFailure(makeTransformationError("A ref node cannot reference one of its children."));
312
+ const evaluated = resolved.evaluate();
313
+ const { getType } = Utils.Tree.TypeChecks;
314
+ if (getType(evaluated) === "transformer") {
315
+ const transformer = evaluated;
316
+ return makeSuccess(transformer.toMethod());
317
+ }
318
+ return makeSuccess(evaluated);
319
+ };
320
+ var ref = SmartTags.makeSmartTag({
321
+ name: "ref",
322
+ defaultMode: "isolation",
323
+ isolationInitType: "array",
324
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "string", "text"),
325
+ argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
326
+ func
327
+ });
328
+
329
+ // src/agnostic/html/hyper-json/smart-tags/isolated/string/index.ts
330
+ var string = SmartTags.makeSmartTag({
331
+ name: "string",
332
+ defaultMode: "isolation",
333
+ isolationInitType: "string",
334
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "null", "boolean", "number", "string", "text", "element", "nodelist"),
335
+ argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "null", "boolean", "number", "string", "text", "element", "nodelist"),
336
+ func: (main, args) => {
337
+ const all = [main, ...args];
338
+ const reduced = all.reduce((reduced2, curr) => {
339
+ return `${reduced2}${Cast.toString(curr)}`;
340
+ }, "");
341
+ return Outcome.makeSuccess(reduced);
342
+ }
343
+ });
344
+
345
+ // src/agnostic/html/hyper-json/smart-tags/isolated/text/index.ts
346
+ var text = SmartTags.makeSmartTag({
347
+ name: "text",
348
+ defaultMode: "isolation",
349
+ isolationInitType: "text",
350
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "null", "boolean", "number", "string", "text", "element", "nodelist"),
351
+ argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "null", "boolean", "number", "string", "text", "element", "nodelist"),
352
+ func: (main, args) => {
353
+ const all = [main, ...args];
354
+ const reduced = all.reduce((reduced2, curr) => {
355
+ return Cast.toText(`${reduced2}${Cast.toText(curr)}`);
356
+ }, Cast.toText(""));
357
+ return Outcome.makeSuccess(reduced);
358
+ }
359
+ });
360
+
361
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/add/index.ts
362
+ var add = SmartTags.makeSmartTag({
363
+ name: "add",
364
+ defaultMode: "coalescion",
365
+ isolationInitType: "array",
366
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "number", "string", "text"),
367
+ argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "number", "string", "text"),
368
+ func: (main, args) => {
369
+ const numMain = Cast.toNumber(main);
370
+ const numArgs = args.map(Cast.toNumber);
371
+ return Outcome.makeSuccess(numArgs.reduce((reduced, arg) => reduced + arg, numMain));
372
+ }
373
+ });
374
+
375
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/addclass/index.ts
376
+ var addclass = SmartTags.makeSmartTag({
377
+ name: "addclass",
378
+ defaultMode: "coalescion",
379
+ isolationInitType: "array",
380
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "element"),
381
+ argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "string", "text"),
382
+ func: (main, args) => {
383
+ main.classList.add(...args.map((arg) => Cast.toString(arg)));
384
+ return Outcome.makeSuccess(main);
385
+ }
386
+ });
387
+
388
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/and/index.ts
389
+ var and = SmartTags.makeSmartTag({
390
+ name: "and",
391
+ defaultMode: "coalescion",
392
+ isolationInitType: "array",
393
+ mainValueCheck: (m) => Outcome.makeSuccess(m),
394
+ argsValueCheck: (a) => Outcome.makeSuccess(a),
395
+ func: (main, args) => {
396
+ const all = [main, ...args];
397
+ const returned = all.every(Cast.toBoolean);
398
+ return Outcome.makeSuccess(returned);
399
+ }
400
+ });
401
+
402
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/append/index.ts
403
+ var append = SmartTags.makeSmartTag({
404
+ name: "append",
405
+ defaultMode: "coalescion",
406
+ isolationInitType: "array",
407
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "string", "text", "nodelist", "element", "array"),
408
+ argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "string", "text", "nodelist", "element", "array"),
409
+ func: (main, args) => {
410
+ const { makeSuccess } = Outcome;
411
+ const { Text: Text2, Element: Element2, NodeList, document: document2 } = Window.get();
412
+ if (Array.isArray(main)) return makeSuccess([...main, ...args]);
413
+ if (main instanceof Element2) {
414
+ main.append(...Array.from(Cast.toNodeList(args)));
415
+ return makeSuccess(main);
416
+ }
417
+ if (main instanceof NodeList) {
418
+ const frag = document2.createDocumentFragment();
419
+ frag.append(
420
+ ...Array.from(main),
421
+ ...Array.from(Cast.toNodeList(args))
422
+ );
423
+ return makeSuccess(frag.childNodes);
424
+ }
425
+ if (main instanceof Text2) {
426
+ const reducedString = args.reduce((reduced, arg) => {
427
+ return `${reduced}${Cast.toString(arg)}`;
428
+ }, Cast.toString(main));
429
+ return makeSuccess(Cast.toText(reducedString));
430
+ }
431
+ return makeSuccess(args.reduce((reduced, arg) => {
432
+ return `${reduced}${Cast.toString(arg)}`;
433
+ }, main));
434
+ }
435
+ });
436
+
437
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/at/index.ts
438
+ var at = SmartTags.makeSmartTag({
439
+ name: "at",
440
+ defaultMode: "coalescion",
441
+ isolationInitType: "array",
442
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "string", "text", "array", "nodelist"),
443
+ argsValueCheck: (a) => {
444
+ const { makeFailure, makeSuccess } = Outcome;
445
+ const { makeArgsValueError } = Utils.SmartTags;
446
+ const { getType, typeCheckMany } = Utils.Tree.TypeChecks;
447
+ if (a.length === 0) return makeFailure(makeArgsValueError("number | string | text", "undefined", 0));
448
+ if (a.length > 1) return makeFailure(makeArgsValueError("undefined", getType(a[1]) ?? "undefined", 1));
449
+ const checked = typeCheckMany(a, "number", "string", "text");
450
+ if (checked.success) return makeSuccess(a);
451
+ return checked;
452
+ },
453
+ func: (main, args) => {
454
+ const { makeFailure, makeSuccess } = Outcome;
455
+ const { makeTransformationError } = Utils.SmartTags;
456
+ const pos = args[0];
457
+ const numPos = Cast.toNumber(pos);
458
+ let found;
459
+ const { NodeList } = Window.get();
460
+ if (typeof main === "string" || Array.isArray(main) || main instanceof NodeList) {
461
+ found = main[numPos];
462
+ } else {
463
+ const strMain = Cast.toString(main);
464
+ found = strMain[numPos];
465
+ }
466
+ if (found === void 0) return makeFailure(makeTransformationError({
467
+ message: "Property does not exist"
468
+ // [WIP] maybe more details here ?
469
+ }));
470
+ return makeSuccess(found);
471
+ }
472
+ });
473
+
474
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/call/index.ts
475
+ var call = SmartTags.makeSmartTag({
476
+ name: "call",
477
+ defaultMode: "coalescion",
478
+ isolationInitType: "array",
479
+ mainValueCheck: (m) => {
480
+ const { makeFailure } = Outcome;
481
+ const { typeCheck, typeCheckMany, getType } = Utils.Tree.TypeChecks;
482
+ const { makeMainValueError } = Utils.SmartTags;
483
+ const isMethodCheck = typeCheck(m, "method");
484
+ if (isMethodCheck.success) return isMethodCheck;
485
+ if (!Array.isArray(m)) return makeFailure({
486
+ expected: "method[]",
487
+ found: getType(m) ?? "undefined"
488
+ });
489
+ const isMethodsArrayCheck = typeCheckMany(m, "method");
490
+ if (isMethodsArrayCheck.success) return isMethodsArrayCheck;
491
+ return makeFailure(makeMainValueError("method | method[]", getType(m) ?? "undefined"));
492
+ },
493
+ argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "array"),
494
+ func: (main, args) => {
495
+ const { makeFailure, makeSuccess } = Outcome;
496
+ const { makeTransformationError } = Utils.SmartTags;
497
+ return makeFailure(makeTransformationError({
498
+ message: "This smart tag should not be used."
499
+ }));
500
+ }
501
+ });
502
+
503
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/clone/index.ts
504
+ var clone = SmartTags.makeSmartTag({
505
+ name: "clone",
506
+ defaultMode: "coalescion",
507
+ isolationInitType: "array",
508
+ mainValueCheck: (m) => Outcome.makeSuccess(m),
509
+ argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
510
+ func: (main) => Outcome.makeSuccess(Utils.clone(main))
511
+ });
512
+
513
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/deleteproperties/index.ts
514
+ var deleteproperties = SmartTags.makeSmartTag({
515
+ name: "deleteproperties",
516
+ defaultMode: "coalescion",
517
+ isolationInitType: "array",
518
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "record"),
519
+ argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "string", "text"),
520
+ func: (main, args) => {
521
+ const { makeFailure, makeSuccess } = Outcome;
522
+ const { makeTransformationError } = Utils.SmartTags;
523
+ let returned = Utils.clone(main);
524
+ for (const arg of args) {
525
+ const strArg = Cast.toString(arg);
526
+ try {
527
+ returned = deepDeleteProperty(returned, strArg);
528
+ } catch (err) {
529
+ return makeFailure(makeTransformationError(`Cannot access ${strArg} from input record`));
530
+ }
531
+ }
532
+ return makeSuccess(returned);
533
+ }
534
+ });
535
+ function deepDeleteProperty(record2, pathString) {
536
+ const cloned = Utils.clone(record2);
537
+ const pathChunks = pathString.split(".");
538
+ let currentRecord = cloned;
539
+ pathChunks.forEach((chunk, pos) => {
540
+ const isLast = pos === pathChunks.length - 1;
541
+ if (isLast) delete currentRecord[chunk];
542
+ else {
543
+ const found = currentRecord[chunk];
544
+ if (isRecord(found)) currentRecord = found;
545
+ else throw "not a record";
546
+ }
547
+ });
548
+ return cloned;
549
+ }
550
+
551
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/equals/index.ts
552
+ var equals = SmartTags.makeSmartTag({
553
+ name: "equals",
554
+ defaultMode: "coalescion",
555
+ isolationInitType: "array",
556
+ mainValueCheck: (m) => Outcome.makeSuccess(m),
557
+ argsValueCheck: (a) => {
558
+ const [first, ...others] = a;
559
+ if (first === void 0) return Outcome.makeFailure(Utils.SmartTags.makeArgsValueError(
560
+ "value",
561
+ "undefined",
562
+ 0
563
+ ));
564
+ const returned = [first, ...others];
565
+ return Outcome.makeSuccess(returned);
566
+ },
567
+ func: (main, args) => {
568
+ const { Text: Text2 } = Window.get();
569
+ const normalizedMain = main instanceof Text2 ? Cast.toString(main) : main;
570
+ const normalizedArgs = args.map((a) => a instanceof Text2 ? Cast.toString(a) : a);
571
+ return Outcome.makeSuccess(normalizedArgs.every((arg) => arg === normalizedMain));
572
+ }
573
+ });
574
+
575
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/getattribute/index.ts
576
+ var getattribute = SmartTags.makeSmartTag({
577
+ name: "getattribute",
578
+ defaultMode: "coalescion",
579
+ isolationInitType: "array",
580
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "element"),
581
+ argsValueCheck: (a) => {
582
+ const { makeFailure, makeSuccess } = Outcome;
583
+ const { typeCheckMany, getType } = Utils.Tree.TypeChecks;
584
+ const { makeArgsValueError } = Utils.SmartTags;
585
+ if (a.length === 0) return makeFailure(makeArgsValueError("string | Text", "undefined", 0));
586
+ if (a.length > 1) return makeFailure(makeArgsValueError("undefined", getType(a[2]) ?? "undefined", 1));
587
+ const checked = typeCheckMany(a, "string", "text");
588
+ if (checked.success) return makeSuccess(checked.payload);
589
+ return checked;
590
+ },
591
+ func: (main, args) => {
592
+ const name = Cast.toString(args[0]);
593
+ const found = main.getAttribute(name);
594
+ return Outcome.makeSuccess(found);
595
+ }
596
+ });
597
+
598
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/getproperties/index.ts
599
+ var getproperties = SmartTags.makeSmartTag({
600
+ name: "getproperties",
601
+ defaultMode: "coalescion",
602
+ isolationInitType: "array",
603
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "record"),
604
+ argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "string", "text"),
605
+ func: (main, args) => {
606
+ const reduced = args.reduce((reduced2, curr) => {
607
+ const key = Cast.toString(curr);
608
+ const val = main[key];
609
+ if (val === void 0) return { ...reduced2 };
610
+ return { ...reduced2, [key]: val };
611
+ }, {});
612
+ return Outcome.makeSuccess(reduced);
613
+ }
614
+ });
615
+
616
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/getproperty/index.ts
617
+ var getproperty = SmartTags.makeSmartTag({
618
+ name: "getproperty",
619
+ defaultMode: "coalescion",
620
+ isolationInitType: "array",
621
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "record"),
622
+ argsValueCheck: (a) => {
623
+ const { makeFailure, makeSuccess } = Outcome;
624
+ const { makeArgsValueError } = Utils.SmartTags;
625
+ const { getType, typeCheckMany } = Utils.Tree.TypeChecks;
626
+ if (a.length === 0) return makeFailure(makeArgsValueError("string | Text", "undefined", 0));
627
+ if (a.length !== 1) return makeFailure(makeArgsValueError("undefined", getType(a.at(1)) ?? "undefined", 1));
628
+ const checked = typeCheckMany(a, "string", "text");
629
+ if (!checked.success) return checked;
630
+ return makeSuccess(checked.payload);
631
+ },
632
+ func: (main, args) => {
633
+ const { getType } = Utils.Tree.TypeChecks;
634
+ const { makeTransformationError } = Utils.SmartTags;
635
+ const { makeFailure, makeSuccess } = Outcome;
636
+ const [propName] = args;
637
+ const strPropName = Cast.toString(propName);
638
+ try {
639
+ const found = deepGetProperty(main, strPropName);
640
+ const foundType = getType(found);
641
+ if (foundType !== "transformer") return makeSuccess(found);
642
+ return makeFailure(makeTransformationError(`Forbidden access to key: '${strPropName}'`));
643
+ } catch (err) {
644
+ return makeFailure(makeTransformationError(`Impossible to access ${strPropName}`));
645
+ }
646
+ }
647
+ });
648
+ function deepGetProperty(record2, pathString) {
649
+ const pathChunks = pathString.split(".").map((e) => e.trim()).filter((e) => e !== "");
650
+ let currentRecord = record2;
651
+ let returned = currentRecord;
652
+ pathChunks.forEach((chunk, pos) => {
653
+ const isLast = pos === pathChunks.length - 1;
654
+ if (isLast) {
655
+ const val = currentRecord[chunk];
656
+ if (val === void 0) throw "PROP_UNDEFINED";
657
+ returned = val;
658
+ } else {
659
+ const found = currentRecord[chunk];
660
+ if (isRecord(found)) currentRecord = found;
661
+ else throw "NOT_A_RECORD";
662
+ }
663
+ });
664
+ return returned;
665
+ }
666
+
667
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/if/index.ts
668
+ var ifFunc = SmartTags.makeSmartTag({
669
+ name: "if",
670
+ defaultMode: "coalescion",
671
+ isolationInitType: "array",
672
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "boolean"),
673
+ argsValueCheck: (a) => {
674
+ const { makeFailure, makeSuccess } = Outcome;
675
+ const { makeArgsValueError } = Utils.SmartTags;
676
+ if (a.length > 2) return makeFailure(makeArgsValueError("value", "undefined", a.length));
677
+ if (a.length < 2) return makeFailure(makeArgsValueError("undefined", "value", 2));
678
+ return makeSuccess(a);
679
+ },
680
+ func: (main, args) => {
681
+ const [then, otherwise] = args;
682
+ return Outcome.makeSuccess(main ? then : otherwise);
683
+ }
684
+ });
685
+
686
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/initialize/index.ts
687
+ var initialize = SmartTags.makeSmartTag({
688
+ name: "initialize",
689
+ defaultMode: "coalescion",
690
+ isolationInitType: "array",
691
+ mainValueCheck: (m) => Outcome.makeSuccess(m),
692
+ argsValueCheck: (a) => {
693
+ const { makeFailure, makeSuccess } = Outcome;
694
+ const { getType, typeCheck } = Utils.Tree.TypeChecks;
695
+ const { makeArgsValueError } = Utils.SmartTags;
696
+ const first = a[0];
697
+ if (first === void 0) return makeFailure(makeArgsValueError("string | text", "undefined", 0));
698
+ if (a.length > 1) return makeFailure(makeArgsValueError("undefined", getType(a[1]) ?? "undefined", 1));
699
+ const firstChecked = typeCheck(first, "string", "text");
700
+ if (!firstChecked.success) return makeFailure(makeArgsValueError(firstChecked.error.expected, firstChecked.error.found, 0));
701
+ return makeSuccess(a);
702
+ },
703
+ func: (_main, args) => {
704
+ const { makeFailure, makeSuccess } = Outcome;
705
+ const { makeTransformationError } = Utils.SmartTags;
706
+ const { getInitialValueFromTypeName } = Utils.Tree;
707
+ const { isValueTypeName } = Utils.Tree.TypeChecks;
708
+ const firstArg = args[0];
709
+ const strFirstArg = Cast.toString(firstArg).trim().toLowerCase();
710
+ const isValueType = isValueTypeName(strFirstArg);
711
+ if (!isValueType || strFirstArg === "transformer" || strFirstArg === "method") return makeFailure(makeTransformationError(`${strFirstArg} is not a valid type`));
712
+ const initialized = getInitialValueFromTypeName(strFirstArg);
713
+ return makeSuccess(initialized);
714
+ }
715
+ });
716
+
717
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/join/index.ts
718
+ var join = SmartTags.makeSmartTag({
719
+ name: "join",
720
+ defaultMode: "coalescion",
721
+ isolationInitType: "array",
722
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "array", "nodelist"),
723
+ argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "string", "text"),
724
+ func: (main, args) => {
725
+ const { makeSuccess } = Outcome;
726
+ const joiner = Cast.toString(args);
727
+ if (Array.isArray(main)) return makeSuccess(main.map(Cast.toString).join(joiner));
728
+ return makeSuccess(Array.from(main).map(Cast.toString).join(joiner));
729
+ }
730
+ });
731
+
732
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/length/index.ts
733
+ var length = SmartTags.makeSmartTag({
734
+ name: "length",
735
+ defaultMode: "coalescion",
736
+ isolationInitType: "array",
737
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "string", "nodelist"),
738
+ argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
739
+ func: (main) => {
740
+ const { makeSuccess } = Outcome;
741
+ const { Text: Text2, NodeList, Element: Element2 } = Window.get();
742
+ if (typeof main === "string" || main instanceof NodeList || main instanceof Text2 || Array.isArray(main)) return makeSuccess(main.length);
743
+ if (main instanceof Element2) return makeSuccess(main.childNodes.length);
744
+ return makeSuccess(Object.keys(main).length);
745
+ }
746
+ });
747
+
748
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/map/index.ts
749
+ var map = SmartTags.makeSmartTag({
750
+ name: "map",
751
+ defaultMode: "coalescion",
752
+ isolationInitType: "array",
753
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "array"),
754
+ argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "method"),
755
+ func: (main, args) => {
756
+ const { makeTransformationError } = Utils.SmartTags;
757
+ let mapped = [];
758
+ for (const val of main) {
759
+ let reduced = val;
760
+ for (const arg of args) {
761
+ const { transformer } = arg;
762
+ const applied = transformer.apply(reduced);
763
+ if (!applied.success) return Outcome.makeFailure(makeTransformationError({
764
+ message: "Subtransformation failure.",
765
+ onTransformed: reduced,
766
+ transformerAt: args.indexOf(arg),
767
+ transformerName: transformer.name,
768
+ transformerInput: reduced,
769
+ transformerOutput: applied
770
+ }));
771
+ reduced = applied.payload;
772
+ }
773
+ mapped.push(reduced);
774
+ }
775
+ return Outcome.makeSuccess(mapped);
776
+ }
777
+ });
778
+
779
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/negate/index.ts
780
+ var negate = SmartTags.makeSmartTag({
781
+ name: "negate",
782
+ defaultMode: "coalescion",
783
+ isolationInitType: "array",
784
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "boolean"),
785
+ argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
786
+ func: (main) => Outcome.makeSuccess(!main)
787
+ });
788
+
789
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/notrailing/index.ts
790
+ var notrailing = SmartTags.makeSmartTag({
791
+ name: "notrailing",
792
+ defaultMode: "coalescion",
793
+ isolationInitType: "array",
794
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "string", "text"),
795
+ argsValueCheck: (a) => {
796
+ const { makeSuccess, makeFailure } = Outcome;
797
+ const { makeArgsValueError } = Utils.SmartTags;
798
+ const { getType, typeCheck } = Utils.Tree.TypeChecks;
799
+ if (a.length === 0) return makeSuccess([]);
800
+ if (a.length > 1) return makeFailure(makeArgsValueError("undefined", getType(a[1]) ?? "undefined", 1));
801
+ const [first] = a;
802
+ const firstChecked = typeCheck(first, "string", "text");
803
+ if (!firstChecked.success) return makeFailure(makeArgsValueError(
804
+ firstChecked.error.expected,
805
+ firstChecked.error.found,
806
+ 0
807
+ ));
808
+ return makeSuccess([firstChecked.payload]);
809
+ },
810
+ func: (main, args) => {
811
+ const strMain = Cast.toString(main);
812
+ const firstArg = args[0];
813
+ const strFirstArg = Cast.toString(firstArg ?? "/");
814
+ let strOutput = strMain;
815
+ while (strOutput.endsWith(strFirstArg)) strOutput = strOutput.slice(0, -1);
816
+ if (typeof main === "string") return Outcome.makeSuccess(strOutput);
817
+ return Outcome.makeSuccess(Cast.toText(strOutput));
818
+ }
819
+ });
820
+
821
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/or/index.ts
822
+ var or = SmartTags.makeSmartTag({
823
+ name: "or",
824
+ defaultMode: "coalescion",
825
+ isolationInitType: "array",
826
+ mainValueCheck: (m) => Outcome.makeSuccess(m),
827
+ argsValueCheck: (a) => Outcome.makeSuccess(a),
828
+ func: (main, args) => {
829
+ const all = [main, ...args];
830
+ const returned = all.some(Cast.toBoolean);
831
+ return Outcome.makeSuccess(returned);
832
+ }
833
+ });
834
+
835
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/pickrandom/index.ts
836
+ var pickrandom = SmartTags.makeSmartTag({
837
+ name: "pickrandom",
838
+ defaultMode: "coalescion",
839
+ isolationInitType: "array",
840
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "array"),
841
+ argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
842
+ func: (main) => {
843
+ const { makeSuccess, makeFailure } = Outcome;
844
+ const { makeTransformationError } = Utils.SmartTags;
845
+ const pos = Math.floor(Math.random() * main.length);
846
+ const found = main[pos];
847
+ if (found === void 0) return makeFailure(makeTransformationError("Cannot pick inside empty array"));
848
+ return makeSuccess(found);
849
+ }
850
+ });
851
+
852
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/print/index.ts
853
+ var print = SmartTags.makeSmartTag({
854
+ name: "print",
855
+ defaultMode: "coalescion",
856
+ isolationInitType: "array",
857
+ mainValueCheck: (m) => {
858
+ const { getType } = Utils.Tree.TypeChecks;
859
+ const { makeSuccess, makeFailure } = Outcome;
860
+ const { makeMainValueError } = Utils.SmartTags;
861
+ return getType(m) === "transformer" ? makeFailure(makeMainValueError("Exclude<value, transformer>", "transformer")) : makeSuccess(m);
862
+ },
863
+ argsValueCheck: (a) => Outcome.makeSuccess(a),
864
+ func: (main, args, details) => {
865
+ console.group("print");
866
+ console.log("Main:", main);
867
+ console.log("Args:", ...args);
868
+ console.log("Tree:", details.sourceTree);
869
+ console.groupEnd();
870
+ return Outcome.makeSuccess(main);
871
+ }
872
+ });
873
+
874
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/populate/index.ts
875
+ var populate = SmartTags.makeSmartTag({
876
+ name: "populate",
877
+ defaultMode: "coalescion",
878
+ isolationInitType: "array",
879
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "record"),
880
+ argsValueCheck: (a) => {
881
+ const [first, ...others] = a;
882
+ const { makeFailure, makeSuccess } = Outcome;
883
+ const { makeArgsValueError } = Utils.SmartTags;
884
+ const { typeCheck, typeCheckMany, getType } = Utils.Tree.TypeChecks;
885
+ const firstChecked = typeCheck(first, "string", "text", "nodelist", "element");
886
+ if (!firstChecked.success) return makeFailure(makeArgsValueError(
887
+ firstChecked.error.expected,
888
+ firstChecked.error.found,
889
+ 0
890
+ ));
891
+ const othersChecked = typeCheckMany(others, "array");
892
+ if (!othersChecked.success) return makeFailure(makeArgsValueError(
893
+ othersChecked.error.expected,
894
+ othersChecked.error.found,
895
+ othersChecked.error.position + 1
896
+ ));
897
+ for (const [argPos, arg] of Object.entries(othersChecked.payload)) {
898
+ const argPosNum = parseInt(argPos);
899
+ const [first2, second] = arg;
900
+ const firstChecked2 = typeCheck(first2, "string", "text");
901
+ const secondChecked = typeCheck(second, "string", "text");
902
+ if (!firstChecked2.success || !secondChecked.success) return makeFailure(makeArgsValueError(
903
+ "[string | Text, string | Text]",
904
+ `[${getType(first2)}, ${getType(second)}]`,
905
+ argPosNum + 1
906
+ ));
907
+ }
908
+ return makeSuccess(a);
909
+ },
910
+ func: (main, args) => {
911
+ const { makeSuccess, makeFailure } = Outcome;
912
+ const { makeTransformationError } = Utils.SmartTags;
913
+ const record2 = main;
914
+ const [template, ...actions] = args;
915
+ let returnedStr = Cast.toString(template);
916
+ for (const [propName, toReplace] of actions) {
917
+ try {
918
+ const value = deepGetProperty(record2, Cast.toString(propName));
919
+ const replaced = replaceAll(returnedStr, Cast.toString(toReplace), Cast.toString(value));
920
+ returnedStr = replaced;
921
+ } catch (err) {
922
+ return makeFailure(makeTransformationError({
923
+ message: "Something went wrong",
924
+ subTransformerError: err
925
+ }));
926
+ }
927
+ }
928
+ const { Text: Text2, NodeList } = Window.get();
929
+ if (typeof template === "string") return makeSuccess(returnedStr);
930
+ if (template instanceof Text2) return makeSuccess(Cast.toText(returnedStr));
931
+ if (template instanceof NodeList) return makeSuccess(Cast.toNodeList(returnedStr));
932
+ return makeSuccess(Cast.toElement(returnedStr));
933
+ }
934
+ });
935
+
936
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/push/index.ts
937
+ var push = SmartTags.makeSmartTag({
938
+ name: "push",
939
+ defaultMode: "coalescion",
940
+ isolationInitType: "array",
941
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "array"),
942
+ argsValueCheck: (a) => Outcome.makeSuccess(a),
943
+ func: (main, args) => Outcome.makeSuccess([...main, ...args])
944
+ });
945
+
946
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/pusheach/index.ts
947
+ var pusheach = SmartTags.makeSmartTag({
948
+ name: "pusheach",
949
+ defaultMode: "coalescion",
950
+ isolationInitType: "array",
951
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "array"),
952
+ argsValueCheck: (a) => {
953
+ const { makeSuccess, makeFailure } = Outcome;
954
+ const { typeCheck } = Utils.Tree.TypeChecks;
955
+ const { makeArgsValueError } = Utils.SmartTags;
956
+ for (const [argPos, arg] of Object.entries(a)) {
957
+ const numPos = parseInt(argPos);
958
+ const checked = typeCheck(arg, "array");
959
+ if (!checked.success) return makeFailure(makeArgsValueError(
960
+ checked.error.expected,
961
+ checked.error.found,
962
+ numPos
963
+ ));
964
+ }
965
+ return makeSuccess(a);
966
+ },
967
+ func: (main, args) => {
968
+ const returned = [...main];
969
+ for (const arg of args) {
970
+ returned.push(...arg);
971
+ }
972
+ return Outcome.makeSuccess(returned);
973
+ }
974
+ });
975
+
976
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/recordtoarray/index.ts
977
+ var recordtoarray = SmartTags.makeSmartTag({
978
+ name: "recordtoarray",
979
+ defaultMode: "coalescion",
980
+ isolationInitType: "array",
981
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "record"),
982
+ argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
983
+ func: (main) => Outcome.makeSuccess(Object.values(main))
984
+ });
985
+
986
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/removeattribute/index.ts
987
+ var removeattribute = SmartTags.makeSmartTag({
988
+ name: "removeattribute",
989
+ defaultMode: "coalescion",
990
+ isolationInitType: "array",
991
+ mainValueCheck: (m) => {
992
+ const { typeCheck, typeCheckMany } = Utils.Tree.TypeChecks;
993
+ if (Array.isArray(m)) return typeCheckMany(m, "element");
994
+ return typeCheck(m, "element");
995
+ },
996
+ argsValueCheck: (a) => {
997
+ const { makeFailure, makeSuccess } = Outcome;
998
+ const { typeCheckMany, getType } = Utils.Tree.TypeChecks;
999
+ const { makeArgsValueError } = Utils.SmartTags;
1000
+ if (a.length === 0) return makeFailure(makeArgsValueError("string | Text", "undefined", 0));
1001
+ if (a.length > 1) return makeFailure(makeArgsValueError("undefined", getType(a[2]) ?? "undefined", 1));
1002
+ const checked = typeCheckMany(a, "string", "text");
1003
+ if (checked.success) return makeSuccess(checked.payload);
1004
+ return checked;
1005
+ },
1006
+ func: (main, args) => {
1007
+ const { makeSuccess } = Outcome;
1008
+ const mainArr = Array.isArray(main) ? main : [main];
1009
+ const mainArrCloned = mainArr.map((e) => Utils.clone(e));
1010
+ const name = Cast.toString(args[0]);
1011
+ mainArrCloned.forEach((e) => e.removeAttribute(name));
1012
+ if (Array.isArray(main)) return makeSuccess(mainArrCloned);
1013
+ return makeSuccess(mainArrCloned[0]);
1014
+ }
1015
+ });
1016
+
1017
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/removeclass/index.ts
1018
+ var removeclass = SmartTags.makeSmartTag({
1019
+ name: "removeclass",
1020
+ defaultMode: "coalescion",
1021
+ isolationInitType: "array",
1022
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "element"),
1023
+ argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "string", "text"),
1024
+ func: (main, args) => {
1025
+ main.classList.remove(...args.map((arg) => Cast.toString(arg)));
1026
+ return Outcome.makeSuccess(main);
1027
+ }
1028
+ });
1029
+
1030
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/renameproperty/index.ts
1031
+ var renameproperty = SmartTags.makeSmartTag({
1032
+ name: "renameproperty",
1033
+ defaultMode: "coalescion",
1034
+ isolationInitType: "array",
1035
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "record"),
1036
+ argsValueCheck: (a) => {
1037
+ const { makeFailure, makeSuccess } = Outcome;
1038
+ const { typeCheck, typeCheckMany } = Utils.Tree.TypeChecks;
1039
+ const checked = typeCheckMany(a, "string", "text");
1040
+ if (!checked.success) return checked;
1041
+ const [first, second] = a;
1042
+ const firstChecked = typeCheck(first, "string", "text");
1043
+ if (!firstChecked.success) return makeFailure(Utils.SmartTags.makeArgsValueError(
1044
+ firstChecked.error.expected,
1045
+ firstChecked.error.found,
1046
+ 0
1047
+ ));
1048
+ const secondChecked = typeCheck(second, "string", "text");
1049
+ if (!secondChecked.success) return makeFailure(Utils.SmartTags.makeArgsValueError(
1050
+ secondChecked.error.expected,
1051
+ secondChecked.error.found,
1052
+ 0
1053
+ ));
1054
+ return makeSuccess([firstChecked.payload, secondChecked.payload]);
1055
+ },
1056
+ func: (main, args) => {
1057
+ const [oldKey, newKey] = args.map(Cast.toString);
1058
+ const returned = {};
1059
+ Object.entries(main).forEach(([key, value]) => {
1060
+ const targetKey = key === oldKey ? newKey : key;
1061
+ returned[targetKey] = value;
1062
+ });
1063
+ return Outcome.makeSuccess(returned);
1064
+ }
1065
+ });
1066
+
1067
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/replace/index.ts
1068
+ var replace = SmartTags.makeSmartTag({
1069
+ name: "replace",
1070
+ defaultMode: "coalescion",
1071
+ isolationInitType: "array",
1072
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "string", "text", "nodelist", "element"),
1073
+ argsValueCheck: (a) => {
1074
+ const { makeFailure, makeSuccess } = Outcome;
1075
+ const { getType, typeCheckMany } = Utils.Tree.TypeChecks;
1076
+ const { makeArgsValueError } = Utils.SmartTags;
1077
+ const expectedStr = "string | Text | NodeListOf<Element | Text> | Element";
1078
+ if (a.length === 0) return makeFailure(makeArgsValueError(expectedStr, "undefined", 0));
1079
+ if (a.length === 1) return makeFailure(makeArgsValueError(expectedStr, "undefined", 1));
1080
+ if (a.length > 2) return makeFailure(makeArgsValueError("undefined", getType(a.at(2)) ?? "undefined", 3));
1081
+ const checked = typeCheckMany(a, "string", "text", "nodelist", "element");
1082
+ if (!checked.success) return checked;
1083
+ return makeSuccess(checked.payload);
1084
+ },
1085
+ func: (main, args) => {
1086
+ const [toReplace, replacer] = args;
1087
+ const strMain = Cast.toString(main);
1088
+ const strToReplace = Cast.toString(toReplace);
1089
+ const strReplacer = Cast.toString(replacer);
1090
+ const strReplaced = replaceAll(strMain, strToReplace, strReplacer);
1091
+ let returned;
1092
+ if (typeof main === "string") {
1093
+ returned = strReplaced;
1094
+ } else if (main instanceof Text) {
1095
+ returned = Cast.toText(strReplaced);
1096
+ } else if (main instanceof Element) {
1097
+ returned = Cast.toElement(strReplaced);
1098
+ } else {
1099
+ returned = Cast.toNodeList(strReplaced);
1100
+ }
1101
+ return Outcome.makeSuccess(returned);
1102
+ }
1103
+ });
1104
+
1105
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/select/index.ts
1106
+ var select = SmartTags.makeSmartTag({
1107
+ name: "select",
1108
+ defaultMode: "coalescion",
1109
+ isolationInitType: "array",
1110
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "nodelist", "element"),
1111
+ argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "string", "text"),
1112
+ func: (main, args) => {
1113
+ const selectedFragment = document.createDocumentFragment();
1114
+ if (main instanceof Window.get().Element) {
1115
+ for (const arg of args) {
1116
+ const selector = Cast.toString(arg);
1117
+ const found = main.querySelectorAll(selector);
1118
+ selectedFragment.append(...Array.from(found));
1119
+ }
1120
+ } else {
1121
+ const divWrapper = Window.get().document.createElement("div");
1122
+ divWrapper.append(...Array.from(main));
1123
+ for (const arg of args) {
1124
+ const selector = Cast.toString(arg);
1125
+ const found = divWrapper.querySelectorAll(selector);
1126
+ selectedFragment.append(...Array.from(found));
1127
+ }
1128
+ }
1129
+ const selected = selectedFragment.childNodes;
1130
+ return Outcome.makeSuccess(selected);
1131
+ }
1132
+ });
1133
+
1134
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/set/index.ts
1135
+ var set = SmartTags.makeSmartTag({
1136
+ name: "set",
1137
+ defaultMode: "coalescion",
1138
+ isolationInitType: "array",
1139
+ mainValueCheck: (m) => Outcome.makeSuccess(m),
1140
+ argsValueCheck: (a) => {
1141
+ const { makeFailure, makeSuccess } = Outcome;
1142
+ const { makeArgsValueError } = Utils.SmartTags;
1143
+ const { getType, typeCheck } = Utils.Tree.TypeChecks;
1144
+ const first = a[0];
1145
+ if (first === void 0) return makeFailure(makeArgsValueError("string | text", "undefined", 0));
1146
+ if (a.length > 2) return makeFailure(makeArgsValueError("undefined", getType(a[2]) ?? "undefined", 2));
1147
+ const firstChecked = typeCheck(first, "string", "text");
1148
+ if (!firstChecked.success) return firstChecked;
1149
+ else return makeSuccess(a);
1150
+ },
1151
+ func: (main, args, { sourceTree }) => {
1152
+ const [first, second] = args;
1153
+ const strFirst = Cast.toString(first);
1154
+ sourceTree.setVariable(strFirst, second === void 0 ? main : second);
1155
+ return Outcome.makeSuccess(main);
1156
+ }
1157
+ });
1158
+
1159
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/setattribute/index.ts
1160
+ var setattribute = SmartTags.makeSmartTag({
1161
+ name: "setattribute",
1162
+ defaultMode: "coalescion",
1163
+ isolationInitType: "array",
1164
+ mainValueCheck: (m) => {
1165
+ const { typeCheck, typeCheckMany } = Utils.Tree.TypeChecks;
1166
+ if (Array.isArray(m)) return typeCheckMany(m, "element");
1167
+ return typeCheck(m, "element");
1168
+ },
1169
+ argsValueCheck: (a) => {
1170
+ const { makeFailure, makeSuccess } = Outcome;
1171
+ const { typeCheckMany, getType } = Utils.Tree.TypeChecks;
1172
+ const { makeArgsValueError } = Utils.SmartTags;
1173
+ if (a.length === 0) return makeFailure(makeArgsValueError("string | Text", "undefined", 0));
1174
+ if (a.length > 2) return makeFailure(makeArgsValueError("undefined", getType(a[2]) ?? "undefined", 2));
1175
+ const checked = typeCheckMany(a, "string", "text");
1176
+ if (checked.success) return makeSuccess(checked.payload);
1177
+ return checked;
1178
+ },
1179
+ func: (main, args) => {
1180
+ const mainArr = Array.isArray(main) ? main : [main];
1181
+ const mainArrCloned = mainArr.map((e) => Utils.clone(e));
1182
+ const argsStr = args.map((e) => Cast.toString(e));
1183
+ const [name, value = ""] = argsStr;
1184
+ mainArrCloned.forEach((e) => e.setAttribute(name, value));
1185
+ if (Array.isArray(main)) return Outcome.makeSuccess(mainArrCloned);
1186
+ return Outcome.makeSuccess(mainArrCloned[0]);
1187
+ }
1188
+ });
1189
+
1190
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/setproperty/index.ts
1191
+ var setproperty = SmartTags.makeSmartTag({
1192
+ name: "setproperty",
1193
+ defaultMode: "coalescion",
1194
+ isolationInitType: "array",
1195
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "record"),
1196
+ argsValueCheck: (a) => {
1197
+ const { makeFailure, makeSuccess } = Outcome;
1198
+ const { makeArgsValueError } = Utils.SmartTags;
1199
+ const { getType, typeCheck } = Utils.Tree.TypeChecks;
1200
+ if (a.length === 0) return makeFailure(makeArgsValueError("string | Text", "undefined", 0));
1201
+ if (a.length === 1) return makeFailure(makeArgsValueError("value", "undefined", 1));
1202
+ if (a.length !== 2) return makeFailure(makeArgsValueError("undefined", getType(a.at(2)) ?? "undefined", 2));
1203
+ const [first, second] = a;
1204
+ const firstChecked = typeCheck(first, "string", "text");
1205
+ if (!firstChecked.success) return makeFailure(makeArgsValueError(firstChecked.error.expected, firstChecked.error.found, 0));
1206
+ return makeSuccess([firstChecked.payload, second]);
1207
+ },
1208
+ func: (main, args) => {
1209
+ const [key, val] = args;
1210
+ const { makeSuccess, makeFailure } = Outcome;
1211
+ const { makeTransformationError } = Utils.SmartTags;
1212
+ try {
1213
+ const withPropertySet = deepSetProperty(
1214
+ Utils.clone(main),
1215
+ Cast.toString(key),
1216
+ val
1217
+ );
1218
+ return makeSuccess(withPropertySet);
1219
+ } catch (err) {
1220
+ return makeFailure(makeTransformationError(`Impossible to access property :${key}`));
1221
+ }
1222
+ }
1223
+ });
1224
+ function deepSetProperty(record2, pathString, value) {
1225
+ const pathChunks = pathString.split(".");
1226
+ const clone2 = Utils.clone(record2);
1227
+ let currentRecord = clone2;
1228
+ pathChunks.forEach((chunk, pos) => {
1229
+ const isLast = pos === pathChunks.length - 1;
1230
+ if (isLast) {
1231
+ currentRecord[chunk] = value;
1232
+ } else {
1233
+ const found = currentRecord[chunk];
1234
+ if (isRecord(found)) currentRecord = found;
1235
+ else throw "NOT_A_RECORD";
1236
+ }
1237
+ });
1238
+ return clone2;
1239
+ }
1240
+
1241
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/sorton/index.ts
1242
+ var sorton = SmartTags.makeSmartTag({
1243
+ name: "sorton",
1244
+ defaultMode: "coalescion",
1245
+ isolationInitType: "array",
1246
+ mainValueCheck: (m) => {
1247
+ const { makeMainValueError } = Utils.SmartTags;
1248
+ const { getType } = Utils.Tree.TypeChecks;
1249
+ const { makeFailure, makeSuccess } = Outcome;
1250
+ if (!Array.isArray(m)) return makeFailure(makeMainValueError("array<record>", getType(m) ?? "undefined"));
1251
+ for (const [itemPos, itemVal] of Object.entries(m)) {
1252
+ if (isRecord(itemVal)) continue;
1253
+ return makeFailure(makeMainValueError("record", getType(itemVal), `At position ${parseInt(itemPos)} in main value`));
1254
+ }
1255
+ return makeSuccess(m);
1256
+ },
1257
+ argsValueCheck: (a) => {
1258
+ const { makeFailure, makeSuccess } = Outcome;
1259
+ const { makeArgsValueError } = Utils.SmartTags;
1260
+ const { getType, typeCheckMany } = Utils.Tree.TypeChecks;
1261
+ if (a.length === 0) return makeFailure(makeArgsValueError("[string | text]", "[]", 0));
1262
+ if (a.length > 1) return makeFailure(makeArgsValueError("undefined", getType(a[1]) ?? "undefined", 2));
1263
+ const checked = typeCheckMany(a, "string", "text");
1264
+ if (checked.success) return makeSuccess(checked.payload);
1265
+ return checked;
1266
+ },
1267
+ func: (main, args) => {
1268
+ const { makeFailure, makeSuccess } = Outcome;
1269
+ const strPropName = Cast.toString(args[0]);
1270
+ const { getType } = Utils.Tree.TypeChecks;
1271
+ const { makeTransformationError } = Utils.SmartTags;
1272
+ const map2 = main.map((record2) => {
1273
+ const prop = record2[strPropName];
1274
+ const type = getType(prop);
1275
+ return { record: record2, prop, type };
1276
+ });
1277
+ const firstItem = map2[0];
1278
+ if (firstItem === void 0) return makeSuccess([]);
1279
+ const firstItemType = firstItem.type;
1280
+ if (firstItemType === void 0) return makeFailure(makeTransformationError({
1281
+ message: "Invalid property type",
1282
+ onItem: 0,
1283
+ found: firstItemType
1284
+ }));
1285
+ for (const [daytumPos, daytumVal] of Object.entries(map2)) {
1286
+ if (daytumVal.type !== firstItemType) return makeFailure(makeTransformationError({
1287
+ message: "Invalid property type",
1288
+ onItem: parseInt(daytumPos),
1289
+ expected: firstItemType,
1290
+ found: daytumVal.type
1291
+ }));
1292
+ }
1293
+ const sorted = main.sort((a, b) => {
1294
+ const { Text: Text2, NodeList } = Window.get();
1295
+ const aProp = a[strPropName];
1296
+ const bProp = b[strPropName];
1297
+ if (aProp === null) return 0;
1298
+ if (typeof aProp === "boolean") {
1299
+ if (aProp === bProp) return 0;
1300
+ if (aProp) return 1;
1301
+ return -1;
1302
+ }
1303
+ if (typeof aProp === "string") return aProp.localeCompare(Cast.toString(bProp));
1304
+ if (aProp instanceof Text2) return Cast.toString(aProp).localeCompare(Cast.toString(bProp));
1305
+ if (typeof aProp === "number") return aProp - Cast.toNumber(bProp);
1306
+ if (Array.isArray(aProp)) return aProp.length - Cast.toArray(bProp).length;
1307
+ if (aProp instanceof NodeList) return aProp.length - Cast.toNodeList(bProp).length;
1308
+ return 0;
1309
+ });
1310
+ return makeSuccess(sorted);
1311
+ }
1312
+ });
1313
+
1314
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/split/index.ts
1315
+ var split = SmartTags.makeSmartTag({
1316
+ name: "split",
1317
+ defaultMode: "coalescion",
1318
+ isolationInitType: "array",
1319
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "string", "text"),
1320
+ argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "string", "text"),
1321
+ func: (main, args) => {
1322
+ let strReturnedArr = [Cast.toString(main)];
1323
+ for (const arg of args) {
1324
+ strReturnedArr = strReturnedArr.map((e) => e.split(Cast.toString(arg))).flat();
1325
+ }
1326
+ if (typeof main === "string") return Outcome.makeSuccess(strReturnedArr);
1327
+ return Outcome.makeSuccess(strReturnedArr.map(Cast.toText));
1328
+ }
1329
+ });
1330
+
1331
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/spread/index.ts
1332
+ var spread = SmartTags.makeSmartTag({
1333
+ name: "spread",
1334
+ defaultMode: "coalescion",
1335
+ isolationInitType: "array",
1336
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "record"),
1337
+ argsValueCheck: (a) => {
1338
+ const { makeFailure, makeSuccess } = Outcome;
1339
+ const { makeArgsValueError } = Utils.SmartTags;
1340
+ const { getType, typeCheck } = Utils.Tree.TypeChecks;
1341
+ if (a.length === 0) return makeFailure(makeArgsValueError("record", "undefined", 0));
1342
+ if (a.length > 1) return makeFailure(makeArgsValueError("undefined", getType(a.at(1)) ?? "undefined", 1));
1343
+ const [first] = a;
1344
+ const firstChecked = typeCheck(first, "record");
1345
+ if (!firstChecked.success) return makeFailure(makeArgsValueError(firstChecked.error.expected, firstChecked.error.found, 0));
1346
+ return makeSuccess([firstChecked.payload]);
1347
+ },
1348
+ func: (main, args) => Outcome.makeSuccess({ ...main, ...args[0] })
1349
+ });
1350
+
1351
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/toarray/index.ts
1352
+ var toarray = SmartTags.makeSmartTag({
1353
+ name: "toarray",
1354
+ defaultMode: "coalescion",
1355
+ isolationInitType: "array",
1356
+ mainValueCheck: (m) => Outcome.makeSuccess(m),
1357
+ argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
1358
+ func: (main) => Outcome.makeSuccess(Cast.toArray(main))
1359
+ });
1360
+
1361
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/toboolean/index.ts
1362
+ var toboolean = SmartTags.makeSmartTag({
1363
+ name: "toboolean",
1364
+ defaultMode: "coalescion",
1365
+ isolationInitType: "array",
1366
+ mainValueCheck: (m) => Outcome.makeSuccess(m),
1367
+ argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
1368
+ func: (m) => Outcome.makeSuccess(Cast.toBoolean(m))
1369
+ });
1370
+
1371
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/toelement/index.ts
1372
+ var toelement = SmartTags.makeSmartTag({
1373
+ name: "toelement",
1374
+ defaultMode: "coalescion",
1375
+ isolationInitType: "array",
1376
+ mainValueCheck: (m) => Outcome.makeSuccess(m),
1377
+ argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
1378
+ func: (m) => Outcome.makeSuccess(Cast.toElement(m))
1379
+ });
1380
+
1381
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/toggleclass/index.ts
1382
+ var toggleclass = SmartTags.makeSmartTag({
1383
+ name: "toggleclass",
1384
+ defaultMode: "coalescion",
1385
+ isolationInitType: "array",
1386
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "element"),
1387
+ argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "string", "text"),
1388
+ func: (main, args) => {
1389
+ for (const arg of args) main.classList.toggle(Cast.toString(arg));
1390
+ return Outcome.makeSuccess(main);
1391
+ }
1392
+ });
1393
+
1394
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/tonodelist/index.ts
1395
+ var tonodelist = SmartTags.makeSmartTag({
1396
+ name: "tonodelist",
1397
+ defaultMode: "coalescion",
1398
+ isolationInitType: "array",
1399
+ mainValueCheck: (m) => Outcome.makeSuccess(m),
1400
+ argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
1401
+ func: (m) => Outcome.makeSuccess(Cast.toNodeList(m))
1402
+ });
1403
+
1404
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/tonull/index.ts
1405
+ var tonull = SmartTags.makeSmartTag({
1406
+ name: "tonull",
1407
+ defaultMode: "coalescion",
1408
+ isolationInitType: "array",
1409
+ mainValueCheck: (m) => Outcome.makeSuccess(m),
1410
+ argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
1411
+ func: () => Outcome.makeSuccess(null)
1412
+ });
1413
+
1414
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/tonumber/index.ts
1415
+ var tonumber = SmartTags.makeSmartTag({
1416
+ name: "tonumber",
1417
+ defaultMode: "coalescion",
1418
+ isolationInitType: "array",
1419
+ mainValueCheck: (m) => Outcome.makeSuccess(m),
1420
+ argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
1421
+ func: (m) => Outcome.makeSuccess(Cast.toNumber(m))
1422
+ });
1423
+
1424
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/torecord/index.ts
1425
+ var torecord = SmartTags.makeSmartTag({
1426
+ name: "torecord",
1427
+ defaultMode: "coalescion",
1428
+ isolationInitType: "array",
1429
+ mainValueCheck: (m) => Outcome.makeSuccess(m),
1430
+ argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
1431
+ func: (main) => Outcome.makeSuccess(Cast.toRecord(main))
1432
+ });
1433
+
1434
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/toref/index.ts
1435
+ var toref = SmartTags.makeSmartTag({
1436
+ name: "toref",
1437
+ defaultMode: "coalescion",
1438
+ isolationInitType: "array",
1439
+ mainValueCheck: (m) => Outcome.makeSuccess(m),
1440
+ argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
1441
+ func: (main, args, details) => func(Cast.toString(main), args, details)
1442
+ });
1443
+
1444
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/tostring/index.ts
1445
+ var tostring = SmartTags.makeSmartTag({
1446
+ name: "tostring",
1447
+ defaultMode: "coalescion",
1448
+ isolationInitType: "array",
1449
+ mainValueCheck: (m) => Outcome.makeSuccess(m),
1450
+ argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
1451
+ func: (m) => Outcome.makeSuccess(Cast.toString(m))
1452
+ });
1453
+
1454
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/totext/index.ts
1455
+ var totext = SmartTags.makeSmartTag({
1456
+ name: "totext",
1457
+ defaultMode: "coalescion",
1458
+ isolationInitType: "array",
1459
+ mainValueCheck: (m) => Outcome.makeSuccess(m),
1460
+ argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
1461
+ func: (m) => Outcome.makeSuccess(Cast.toText(m))
1462
+ });
1463
+
1464
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/transformselected/index.ts
1465
+ var transformselected = SmartTags.makeSmartTag({
1466
+ name: "transformselected",
1467
+ defaultMode: "coalescion",
1468
+ isolationInitType: "array",
1469
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "element", "nodelist"),
1470
+ argsValueCheck: (a) => {
1471
+ const { makeFailure, makeSuccess } = Outcome;
1472
+ const { typeCheck, typeCheckMany } = Utils.Tree.TypeChecks;
1473
+ const [first, ...others] = a;
1474
+ const firstChecked = typeCheck(first, "string", "text");
1475
+ if (!firstChecked.success) return makeFailure({ ...firstChecked.error, position: 0 });
1476
+ const othersChecked = typeCheckMany(others, "method");
1477
+ if (!othersChecked.success) return makeFailure({
1478
+ ...othersChecked.error,
1479
+ position: othersChecked.error.position + 1
1480
+ });
1481
+ const returned = [firstChecked.payload, ...othersChecked.payload];
1482
+ return makeSuccess(returned);
1483
+ },
1484
+ func: (main, args) => {
1485
+ const { makeFailure, makeSuccess } = Outcome;
1486
+ const { makeTransformationError } = Utils.SmartTags;
1487
+ const { typeCheck } = Utils.Tree.TypeChecks;
1488
+ const mainClone = Cast.toElement(main);
1489
+ const [selector, ...methods] = args;
1490
+ const selectedElements = Array.from(mainClone.querySelectorAll(Cast.toString(selector)));
1491
+ const transformationMap = new Map(selectedElements.map((s) => [s, Utils.clone(s)]));
1492
+ for (const method of methods) {
1493
+ for (const [selected, value] of Array.from(transformationMap)) {
1494
+ const transformer = method.transformer;
1495
+ const applied = transformer.apply(value);
1496
+ if (!applied.success) return makeFailure(makeTransformationError({
1497
+ // [WIP] maybe a custom makeSubTransformationError ?
1498
+ message: "Subtransformation failure.",
1499
+ onSelected: selected,
1500
+ onTransformed: value,
1501
+ transformerAt: methods.indexOf(method),
1502
+ transformerName: transformer.name,
1503
+ transformerOutput: applied
1504
+ }));
1505
+ transformationMap.set(selected, applied.payload);
1506
+ }
1507
+ }
1508
+ for (const [selected, transformed] of Array.from(transformationMap)) {
1509
+ const transformedChecked = typeCheck(transformed, "element", "nodelist", "text", "string", "number", "boolean", "null");
1510
+ if (!transformedChecked.success) return makeFailure(makeTransformationError({
1511
+ // [WIP] maybe a custom makeBadTransformationOutputError ?
1512
+ message: "Bad transformation output",
1513
+ onSelected: selected,
1514
+ onTransformed: transformed,
1515
+ details: { ...transformedChecked.error }
1516
+ }));
1517
+ const { Element: Element2, NodeList, Text: Text2 } = Window.get();
1518
+ const replacer = transformedChecked.payload;
1519
+ if (replacer instanceof Element2 || replacer instanceof Text2) {
1520
+ insertNode(replacer, "after", selected);
1521
+ selected.remove();
1522
+ } else if (replacer instanceof NodeList) {
1523
+ replacer.forEach((item) => insertNode(item, "before", selected));
1524
+ selected.remove();
1525
+ } else {
1526
+ insertNode(Cast.toText(replacer), "after", selected);
1527
+ selected.remove();
1528
+ }
1529
+ transformedChecked.payload;
1530
+ }
1531
+ if (main instanceof Element) return makeSuccess(mainClone);
1532
+ const safeChildren = Array.from(mainClone.childNodes).filter((e) => e instanceof Element || e instanceof Text);
1533
+ return main instanceof Element ? makeSuccess(mainClone) : makeSuccess(Cast.toNodeList(safeChildren));
1534
+ }
1535
+ });
1536
+
1537
+ // src/agnostic/html/hyper-json/smart-tags/coalesced/trim/index.ts
1538
+ var trim = SmartTags.makeSmartTag({
1539
+ name: "trim",
1540
+ defaultMode: "coalescion",
1541
+ isolationInitType: "array",
1542
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "string", "text"),
1543
+ argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
1544
+ func: (main) => {
1545
+ return typeof main === "string" ? Outcome.makeSuccess(main.trim()) : Outcome.makeSuccess(Cast.toText(`${main}`.trim()));
1546
+ }
1547
+ });
1548
+
1549
+ // src/agnostic/html/hyper-json/tree/index.ts
1550
+ var Tree;
1551
+ ((_Tree) => {
1552
+ class Tree2 {
1553
+ node;
1554
+ options;
1555
+ parent;
1556
+ parents;
1557
+ pathFromParent;
1558
+ root;
1559
+ isRoot;
1560
+ path;
1561
+ pathString;
1562
+ attributes;
1563
+ isMethod;
1564
+ tagName;
1565
+ smartTagName;
1566
+ smartTagsRegister;
1567
+ smartTagData;
1568
+ mode;
1569
+ isPreserved;
1570
+ isLiteral;
1571
+ isolationInitType;
1572
+ subtrees = /* @__PURE__ */ new Map();
1573
+ static actionAttribute = "_action";
1574
+ static keyAttribute = "_key";
1575
+ static methodAttribute = "_method";
1576
+ static initAttribute = "_init";
1577
+ static modeAttribute = "_mode";
1578
+ static preserveAttribute = "_preserve";
1579
+ static literalAttribute = "_literal";
1580
+ static defaultOptions = {
1581
+ globalObject: {},
1582
+ logger: null,
1583
+ loggerThread: "hyperjson"
1584
+ };
1585
+ static from(nodes, options) {
1586
+ const merged = Utils.Tree.mergeNodes(nodes);
1587
+ return new Tree2(merged, null, null, options);
1588
+ }
1589
+ constructor(node, parent, pathFromParent, options) {
1590
+ const { Element: Element2, Text: Text2, document: document2 } = Window.get();
1591
+ this.resolve = this.resolve.bind(this);
1592
+ this.setVariable = this.setVariable.bind(this);
1593
+ this.getVariable = this.getVariable.bind(this);
1594
+ this.performSafetyChecks = this.performSafetyChecks.bind(this);
1595
+ this.computeValue = this.computeValue.bind(this);
1596
+ this.enforceEvaluation = this.enforceEvaluation.bind(this);
1597
+ this.getCachedValue = this.getCachedValue.bind(this);
1598
+ this.setCachedValue = this.setCachedValue.bind(this);
1599
+ this.evaluate = this.evaluate.bind(this);
1600
+ this.node = node;
1601
+ this.options = options ?? Tree2.defaultOptions;
1602
+ if (parent !== null && pathFromParent !== null) {
1603
+ this.isRoot = false;
1604
+ this.parent = parent;
1605
+ this.parents = [parent, ...parent.parents];
1606
+ this.pathFromParent = pathFromParent;
1607
+ this.root = this.parent.root;
1608
+ } else {
1609
+ this.isRoot = true;
1610
+ this.parent = null;
1611
+ this.parents = [];
1612
+ this.pathFromParent = null;
1613
+ this.root = this;
1614
+ }
1615
+ this.path = this.isRoot ? [] : [...this.parent.path, this.pathFromParent];
1616
+ this.pathString = `/${this.path.join("/")}`;
1617
+ this.attributes = node instanceof Element2 ? Array.from(node.attributes) : null;
1618
+ if (node instanceof Element2) {
1619
+ const rawTagName = node.tagName.trim().toLowerCase();
1620
+ const hasTrailingUnderscore = rawTagName.endsWith("_");
1621
+ const hasMethodAttribute = this.attributes?.find((attr) => attr.name === Tree2.methodAttribute) !== void 0;
1622
+ const isMethod = hasTrailingUnderscore || hasMethodAttribute;
1623
+ this.isMethod = isMethod;
1624
+ this.tagName = rawTagName;
1625
+ this.smartTagName = hasTrailingUnderscore ? rawTagName.replace(/_+$/g, "") : rawTagName;
1626
+ } else {
1627
+ this.isMethod = false;
1628
+ this.tagName = null;
1629
+ this.smartTagName = null;
1630
+ }
1631
+ this.smartTagsRegister = new Map([
1632
+ any,
1633
+ array,
1634
+ boolean,
1635
+ element,
1636
+ get,
1637
+ global,
1638
+ guess,
1639
+ nodelist,
1640
+ nullFunc,
1641
+ number,
1642
+ record,
1643
+ ref,
1644
+ string,
1645
+ text,
1646
+ add,
1647
+ addclass,
1648
+ and,
1649
+ append,
1650
+ at,
1651
+ call,
1652
+ clone,
1653
+ deleteproperties,
1654
+ equals,
1655
+ getattribute,
1656
+ getproperties,
1657
+ getproperty,
1658
+ ifFunc,
1659
+ initialize,
1660
+ join,
1661
+ length,
1662
+ map,
1663
+ negate,
1664
+ notrailing,
1665
+ or,
1666
+ pickrandom,
1667
+ print,
1668
+ populate,
1669
+ push,
1670
+ pusheach,
1671
+ recordtoarray,
1672
+ removeattribute,
1673
+ removeclass,
1674
+ renameproperty,
1675
+ replace,
1676
+ select,
1677
+ set,
1678
+ setattribute,
1679
+ spread,
1680
+ setproperty,
1681
+ sorton,
1682
+ split,
1683
+ toarray,
1684
+ toboolean,
1685
+ toelement,
1686
+ toggleclass,
1687
+ tonodelist,
1688
+ tonull,
1689
+ tonumber,
1690
+ toref,
1691
+ torecord,
1692
+ tostring,
1693
+ totext,
1694
+ transformselected,
1695
+ trim
1696
+ ]);
1697
+ if (this.smartTagName === null) {
1698
+ this.smartTagData = null;
1699
+ } else {
1700
+ this.smartTagData = this.smartTagsRegister.get(this.smartTagName) ?? null;
1701
+ }
1702
+ const hasModeAttribute = this.attributes?.find((attr) => {
1703
+ return attr.name === Tree2.modeAttribute && Utils.Tree.TypeChecks.isTreeMode(attr.value);
1704
+ });
1705
+ this.mode = hasModeAttribute?.value ?? this.smartTagData?.defaultMode ?? "isolation";
1706
+ const hasLiteralAttribute = this.attributes?.find((attr) => attr.name === Tree2.literalAttribute) !== void 0;
1707
+ this.isLiteral = hasLiteralAttribute;
1708
+ const hasPreservedAttribute = this.attributes?.find((attr) => attr.name === Tree2.preserveAttribute) !== void 0;
1709
+ this.isPreserved = hasPreservedAttribute;
1710
+ const hasInitAttribute = this.attributes?.find((attr) => {
1711
+ if (attr.name !== Tree2.initAttribute) return false;
1712
+ const val = attr.value.trim().toLowerCase();
1713
+ if (!Utils.Tree.TypeChecks.isValueTypeName(val)) return false;
1714
+ if (val === "transformer") return false;
1715
+ if (val === "method") return false;
1716
+ return true;
1717
+ });
1718
+ if (this.mode === "coalescion") {
1719
+ this.isolationInitType = "array";
1720
+ } else {
1721
+ const initAttributeValue = hasInitAttribute?.value;
1722
+ if (initAttributeValue !== void 0) {
1723
+ this.isolationInitType = initAttributeValue;
1724
+ } else if (this.smartTagData !== null) {
1725
+ this.isolationInitType = this.smartTagData?.isolationInitType ?? "array";
1726
+ } else {
1727
+ this.isolationInitType = "nodelist";
1728
+ }
1729
+ }
1730
+ const { childNodes } = node;
1731
+ let positionnedChildrenCount = 0;
1732
+ const mutableSubtrees = /* @__PURE__ */ new Map();
1733
+ Array.from(childNodes).filter((child, _, childNodes2) => {
1734
+ if (child instanceof Element2) return true;
1735
+ if (child instanceof Text2) return true;
1736
+ return false;
1737
+ }).reduce((reduced, child) => {
1738
+ if (reduced.length === 0) return [child];
1739
+ if (child instanceof Element2) return [...reduced, child];
1740
+ const lastReducedItem = reduced[reduced.length - 1];
1741
+ if (lastReducedItem instanceof Element2) return [...reduced, child];
1742
+ const lastReducedTrimmed = trimEnd(lastReducedItem.textContent ?? "");
1743
+ const childTrimmed = trimStart(child.textContent ?? "");
1744
+ const merged = document2.createTextNode(`${lastReducedTrimmed}${childTrimmed}`);
1745
+ const returned = [...reduced];
1746
+ returned.pop();
1747
+ returned.push(merged);
1748
+ return returned;
1749
+ }, []).filter((child) => {
1750
+ if (child instanceof Element2) return true;
1751
+ const textContent = child.textContent ?? "";
1752
+ return textContent.trim() !== "";
1753
+ }).forEach((childNode) => {
1754
+ if (childNode instanceof Text2) {
1755
+ const rawTextContent = childNode.textContent ?? "";
1756
+ const textContent = rawTextContent.replace(/^\s*\n+\s*/, "").replace(/\s*\n+\s*$/, "");
1757
+ const returnedChildNode = document2.createTextNode(textContent);
1758
+ mutableSubtrees.set(
1759
+ positionnedChildrenCount,
1760
+ new Tree2(returnedChildNode, this, positionnedChildrenCount, this.options)
1761
+ );
1762
+ positionnedChildrenCount += 1;
1763
+ } else {
1764
+ const propertyName = childNode.getAttribute(Tree2.keyAttribute);
1765
+ if (propertyName === null) {
1766
+ mutableSubtrees.set(
1767
+ positionnedChildrenCount,
1768
+ new Tree2(childNode, this, positionnedChildrenCount, this.options)
1769
+ );
1770
+ positionnedChildrenCount += 1;
1771
+ } else {
1772
+ mutableSubtrees.set(
1773
+ propertyName,
1774
+ new Tree2(childNode, this, propertyName, this.options)
1775
+ );
1776
+ }
1777
+ }
1778
+ });
1779
+ this.subtrees = mutableSubtrees;
1780
+ }
1781
+ resolve = function(path) {
1782
+ let currentTree = this;
1783
+ for (const chunk of path) {
1784
+ if (chunk === ".") continue;
1785
+ if (chunk === "..") {
1786
+ currentTree = currentTree.parent ?? this;
1787
+ continue;
1788
+ }
1789
+ const { subtrees } = currentTree;
1790
+ const foundSubtree = subtrees.get(chunk);
1791
+ if (foundSubtree === void 0) return void 0;
1792
+ currentTree = foundSubtree;
1793
+ }
1794
+ return currentTree;
1795
+ };
1796
+ // [WIP] variablesStore is actually only used on root Tree
1797
+ variablesStore = /* @__PURE__ */ new Map();
1798
+ setVariable(name, value) {
1799
+ const { root, isRoot, variablesStore } = this;
1800
+ if (!isRoot) return root.setVariable(name, value);
1801
+ variablesStore.set(name, Serialize.serialize(value));
1802
+ }
1803
+ getVariable(name) {
1804
+ const { root } = this;
1805
+ const found = root.variablesStore.get(name);
1806
+ if (found === void 0) return void 0;
1807
+ const deserialized = Serialize.deserialize(found);
1808
+ if (deserialized instanceof Transformer) throw "A transformer should not be stored as a variable, this happening denotes an implementation error.";
1809
+ return deserialized;
1810
+ }
1811
+ performSafetyChecks() {
1812
+ const { node, smartTagData, isMethod, mode, isRoot } = this;
1813
+ const { Text: Text2 } = Window.get();
1814
+ if (node instanceof Text2 || smartTagData === null) {
1815
+ if (isMethod) throw new Error(`A Text or HTMLElement node cannot be used as a method @ ${this.pathString}`);
1816
+ if (mode === "coalescion") throw new Error(`A Text or HTMLElement node cannot be used in coalescion mode @ ${this.pathString}`);
1817
+ }
1818
+ if (isRoot && mode === "coalescion") throw new Error(`The root node cannot be used in coalescion mode @ ${this.pathString}`);
1819
+ }
1820
+ computeValue() {
1821
+ const {
1822
+ isolationInitType,
1823
+ subtrees,
1824
+ node,
1825
+ smartTagData,
1826
+ isMethod,
1827
+ mode,
1828
+ performSafetyChecks
1829
+ } = this;
1830
+ performSafetyChecks();
1831
+ const { Text: Text2 } = Window.get();
1832
+ if (node instanceof Text2) return node.cloneNode(true);
1833
+ const initialInnerValue = Utils.Tree.getInitialValueFromTypeName(isolationInitType);
1834
+ const innerValue = Array.from(subtrees).reduce((reduced, [subpath, subtree]) => {
1835
+ const subvalue = subtree.evaluate();
1836
+ const coalesced = Utils.coalesceValues(reduced, subpath, subvalue);
1837
+ return coalesced;
1838
+ }, initialInnerValue);
1839
+ if (smartTagData === null) {
1840
+ const nodelist2 = Cast.toNodeList(innerValue);
1841
+ const clone2 = node.cloneNode();
1842
+ clone2.append(...Array.from(nodelist2));
1843
+ return clone2;
1844
+ }
1845
+ const { transformer, method } = smartTagData.generator(innerValue, mode, this);
1846
+ if (isMethod) return method;
1847
+ if (mode === "isolation") {
1848
+ const applied = transformer.apply(null);
1849
+ if (applied.success) return applied.payload;
1850
+ throw {
1851
+ error: "Transformation error",
1852
+ details: applied.error,
1853
+ transformer: transformer.name,
1854
+ path: this.pathString
1855
+ };
1856
+ }
1857
+ return transformer;
1858
+ }
1859
+ enforceEvaluation() {
1860
+ const { isPreserved, node, computeValue, isLiteral, attributes } = this;
1861
+ const { Element: Element2 } = Window.get();
1862
+ if (isPreserved) return Utils.clone(node);
1863
+ const evaluated = computeValue();
1864
+ if (!isLiteral) return evaluated;
1865
+ const asLiteral = Utils.toHyperJson(evaluated);
1866
+ if (asLiteral instanceof Element2) attributes?.forEach(({ name, value }) => asLiteral.setAttribute(name, value));
1867
+ return asLiteral;
1868
+ }
1869
+ cachedValue = void 0;
1870
+ getCachedValue() {
1871
+ const { cachedValue } = this;
1872
+ if (cachedValue === void 0) return void 0;
1873
+ const deserialized = Serialize.deserialize(cachedValue);
1874
+ return deserialized;
1875
+ }
1876
+ setCachedValue(evaluated) {
1877
+ this.cachedValue = Serialize.serialize(evaluated);
1878
+ }
1879
+ evaluate() {
1880
+ const start = Date.now();
1881
+ const {
1882
+ getCachedValue,
1883
+ setCachedValue,
1884
+ enforceEvaluation
1885
+ } = this;
1886
+ const cached = getCachedValue();
1887
+ if (cached !== void 0) return cached;
1888
+ const evaluated = enforceEvaluation();
1889
+ setCachedValue(evaluated);
1890
+ const end = Date.now();
1891
+ const time = end - start;
1892
+ if (time > 20) console.warn(`${this.pathString} took ${time}ms to evaluate, maybe there's something wrong here`);
1893
+ return evaluated;
1894
+ }
1895
+ }
1896
+ _Tree.Tree = Tree2;
1897
+ })(Tree || (Tree = {}));
1898
+
1899
+ // src/agnostic/html/hyper-json/utils/index.ts
1900
+ var Utils;
1901
+ ((Utils2) => {
1902
+ function clone2(value) {
1903
+ const { Element: Element2, Text: Text2, NodeList, document: document2 } = Window.get();
1904
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value === null) return value;
1905
+ if (value instanceof Text2) return value.cloneNode(true);
1906
+ if (value instanceof NodeList) {
1907
+ const frag = document2.createDocumentFragment();
1908
+ const nodes = Array.from(value).map((e) => e.cloneNode(true));
1909
+ frag.append(...nodes);
1910
+ return frag.childNodes;
1911
+ }
1912
+ if (value instanceof Element2) return value.cloneNode(true);
1913
+ if (value instanceof Transformer) return Transformer.clone(value);
1914
+ if (value instanceof Method) return Method.clone(value);
1915
+ if (Array.isArray(value)) return [...value.map(clone2)];
1916
+ if (isRecord(value)) return recordMap(value, (prop) => clone2(prop));
1917
+ throw new Error(`Cannot clone value: ${value}`);
1918
+ }
1919
+ Utils2.clone = clone2;
1920
+ function coalesceValues(currentValue, subpath, subvalue) {
1921
+ const { Element: Element2, Text: Text2, NodeList, document: document2 } = Window.get();
1922
+ let actualSubvalue = subvalue;
1923
+ if (actualSubvalue instanceof Transformer) {
1924
+ const transformer = actualSubvalue;
1925
+ const transformationResult = transformer.apply(currentValue);
1926
+ if (!transformationResult.success) {
1927
+ console.warn({ ...transformationResult.error });
1928
+ return currentValue;
1929
+ }
1930
+ const evaluated = transformationResult.payload;
1931
+ if (transformer.mode === "isolation") {
1932
+ actualSubvalue = evaluated;
1933
+ } else {
1934
+ return evaluated;
1935
+ }
1936
+ }
1937
+ if (Array.isArray(currentValue)) return [...currentValue, actualSubvalue];
1938
+ if (currentValue === null) return actualSubvalue;
1939
+ if (typeof currentValue === "boolean") return actualSubvalue;
1940
+ if (typeof currentValue === "number") return actualSubvalue;
1941
+ if (currentValue instanceof Transformer) return actualSubvalue;
1942
+ if (currentValue instanceof Method) return actualSubvalue;
1943
+ if (typeof currentValue === "string") {
1944
+ if (actualSubvalue === null || typeof actualSubvalue === "boolean" || typeof actualSubvalue === "number" || typeof actualSubvalue === "string") return `${currentValue}${actualSubvalue}`;
1945
+ if (actualSubvalue instanceof Text2) return `${currentValue}${actualSubvalue.textContent}`;
1946
+ if (actualSubvalue instanceof Element2) {
1947
+ const frag = document2.createDocumentFragment();
1948
+ frag.append(currentValue, Utils2.clone(actualSubvalue));
1949
+ return frag.childNodes;
1950
+ }
1951
+ if (actualSubvalue instanceof NodeList) {
1952
+ const frag = document2.createDocumentFragment();
1953
+ frag.append(currentValue, ...Array.from(Utils2.clone(actualSubvalue)));
1954
+ return frag.childNodes;
1955
+ }
1956
+ return actualSubvalue;
1957
+ }
1958
+ if (currentValue instanceof Text2) {
1959
+ if (actualSubvalue === null || typeof actualSubvalue === "boolean" || typeof actualSubvalue === "number" || typeof actualSubvalue === "string") return document2.createTextNode(`${currentValue.textContent}${actualSubvalue}`);
1960
+ if (actualSubvalue instanceof Text2) return document2.createTextNode(`${currentValue.textContent}${actualSubvalue.textContent}`);
1961
+ if (actualSubvalue instanceof Element2) {
1962
+ const frag = document2.createDocumentFragment();
1963
+ frag.append(clone2(currentValue), clone2(actualSubvalue));
1964
+ return frag.childNodes;
1965
+ }
1966
+ if (actualSubvalue instanceof NodeList) {
1967
+ const frag = document2.createDocumentFragment();
1968
+ frag.append(clone2(currentValue), ...Array.from(clone2(actualSubvalue)));
1969
+ return frag.childNodes;
1970
+ }
1971
+ return actualSubvalue;
1972
+ }
1973
+ if (currentValue instanceof Element2) {
1974
+ if (actualSubvalue === null || typeof actualSubvalue === "boolean" || typeof actualSubvalue === "number" || typeof actualSubvalue === "string") {
1975
+ const frag = document2.createDocumentFragment();
1976
+ frag.append(clone2(currentValue), `${actualSubvalue}`);
1977
+ return frag.childNodes;
1978
+ }
1979
+ if (actualSubvalue instanceof Text2 || actualSubvalue instanceof Element2) {
1980
+ const frag = document2.createDocumentFragment();
1981
+ frag.append(clone2(currentValue), clone2(actualSubvalue));
1982
+ return frag.childNodes;
1983
+ }
1984
+ if (actualSubvalue instanceof NodeList) {
1985
+ const frag = document2.createDocumentFragment();
1986
+ frag.append(clone2(currentValue), ...Array.from(clone2(actualSubvalue)));
1987
+ return frag.childNodes;
1988
+ }
1989
+ return actualSubvalue;
1990
+ }
1991
+ if (currentValue instanceof NodeList) {
1992
+ if (actualSubvalue === null || typeof actualSubvalue === "boolean" || typeof actualSubvalue === "number" || typeof actualSubvalue === "string") {
1993
+ const frag = document2.createDocumentFragment();
1994
+ frag.append(...Array.from(clone2(currentValue)), `${actualSubvalue}`);
1995
+ return frag.childNodes;
1996
+ }
1997
+ if (actualSubvalue instanceof Text2 || actualSubvalue instanceof Element2) {
1998
+ const frag = document2.createDocumentFragment();
1999
+ frag.append(...Array.from(clone2(currentValue)), clone2(actualSubvalue));
2000
+ return frag.childNodes;
2001
+ }
2002
+ if (actualSubvalue instanceof NodeList) {
2003
+ const frag = document2.createDocumentFragment();
2004
+ frag.append(...Array.from(clone2(currentValue)), ...Array.from(clone2(actualSubvalue)));
2005
+ return frag.childNodes;
2006
+ }
2007
+ return actualSubvalue;
2008
+ }
2009
+ if (typeof subpath === "number") return { ...currentValue };
2010
+ return {
2011
+ ...currentValue,
2012
+ [subpath]: actualSubvalue
2013
+ };
2014
+ }
2015
+ Utils2.coalesceValues = coalesceValues;
2016
+ Utils2.toHyperJson = (value) => {
2017
+ const { document: document2, Element: Element2, Text: Text2, NodeList } = Window.get();
2018
+ if (value instanceof Text2) {
2019
+ const elt2 = document2.createElement("text");
2020
+ elt2.innerHTML = value.textContent ?? "";
2021
+ return elt2;
2022
+ }
2023
+ if (value instanceof Element2) return value.cloneNode(true);
2024
+ if (value instanceof NodeList) {
2025
+ const elt2 = document2.createElement("nodelist");
2026
+ elt2.append(...Array.from(value).map((e) => e.cloneNode(true)));
2027
+ return elt2;
2028
+ }
2029
+ if (value === null) return document2.createElement("null");
2030
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
2031
+ const elt2 = document2.createElement(typeof value);
2032
+ elt2.innerHTML = `${value}`;
2033
+ return elt2;
2034
+ }
2035
+ if (Array.isArray(value)) {
2036
+ const elt2 = document2.createElement("array");
2037
+ elt2.append(...value.map((e) => (0, Utils2.toHyperJson)(e)));
2038
+ return elt2;
2039
+ }
2040
+ if (value instanceof Transformer) return clone2(value.sourceTree.node);
2041
+ if (value instanceof Method) return clone2(value.transformer.sourceTree.node);
2042
+ const elt = document2.createElement("record");
2043
+ Object.entries(value).forEach(([key, val]) => {
2044
+ const hjVal = (0, Utils2.toHyperJson)(val);
2045
+ if (hjVal instanceof Text2) return;
2046
+ hjVal.setAttribute(Tree.Tree.keyAttribute, key);
2047
+ elt.append(hjVal);
2048
+ });
2049
+ return elt;
2050
+ };
2051
+ let Transformations;
2052
+ ((Transformations2) => {
2053
+ let TypeChecks;
2054
+ ((TypeChecks2) => {
2055
+ function getType(value) {
2056
+ if (singleTypeCheck(value, "null")) return "null";
2057
+ if (singleTypeCheck(value, "boolean")) return "boolean";
2058
+ if (singleTypeCheck(value, "number")) return "number";
2059
+ if (singleTypeCheck(value, "string")) return "string";
2060
+ if (singleTypeCheck(value, "element")) return "element";
2061
+ if (singleTypeCheck(value, "text")) return "text";
2062
+ if (singleTypeCheck(value, "nodelist")) return "nodelist";
2063
+ if (singleTypeCheck(value, "method")) return "method";
2064
+ if (singleTypeCheck(value, "array")) return "array";
2065
+ if (singleTypeCheck(value, "record")) return "record";
2066
+ return void 0;
2067
+ }
2068
+ TypeChecks2.getType = getType;
2069
+ TypeChecks2.everyTypeName = [
2070
+ "null",
2071
+ "boolean",
2072
+ "number",
2073
+ "string",
2074
+ "text",
2075
+ "nodelist",
2076
+ "element",
2077
+ "method",
2078
+ "array",
2079
+ "record"
2080
+ ];
2081
+ function singleTypeCheck(value, type) {
2082
+ const { Element: Element2, Text: Text2, NodeList } = Window.get();
2083
+ if (type === "null" && value === null) return true;
2084
+ if (type === "boolean" && typeof value === "boolean") return true;
2085
+ if (type === "number" && typeof value === "number") return true;
2086
+ if (type === "string" && typeof value === "string") return true;
2087
+ if (type === "element" && value instanceof Element2) return true;
2088
+ if (type === "text" && value instanceof Text2) return true;
2089
+ if (type === "nodelist" && value instanceof NodeList) {
2090
+ const children = Array.from(value);
2091
+ return children.every((child) => child instanceof Element2 || child instanceof Text2);
2092
+ }
2093
+ if (type === "method" && value instanceof Method) return true;
2094
+ if (type === "array" && Array.isArray(value)) {
2095
+ const childrenOk = value.every((child) => typeCheck(child, ...TypeChecks2.everyTypeName).success);
2096
+ return childrenOk;
2097
+ }
2098
+ if (type === "record" && isRecord(value)) {
2099
+ const childrenOk = Object.values(value).every((child) => typeCheck(child, ...TypeChecks2.everyTypeName).success);
2100
+ return childrenOk;
2101
+ }
2102
+ return false;
2103
+ }
2104
+ TypeChecks2.singleTypeCheck = singleTypeCheck;
2105
+ function typeCheck(value, ...types) {
2106
+ const matchesOneType = types.some((type) => singleTypeCheck(value, type));
2107
+ if (matchesOneType) return Outcome.makeSuccess(value);
2108
+ return Outcome.makeFailure({
2109
+ expected: types.join(" | "),
2110
+ found: getType(value) ?? "undefined"
2111
+ });
2112
+ }
2113
+ TypeChecks2.typeCheck = typeCheck;
2114
+ function typeCheckMany(values, ...types) {
2115
+ for (const [pos, val] of Object.entries(values)) {
2116
+ const checked = typeCheck(val, ...types);
2117
+ if (checked.success) continue;
2118
+ return Outcome.makeFailure({ position: parseInt(pos), ...checked.error });
2119
+ }
2120
+ return Outcome.makeSuccess(values);
2121
+ }
2122
+ TypeChecks2.typeCheckMany = typeCheckMany;
2123
+ })(TypeChecks = Transformations2.TypeChecks || (Transformations2.TypeChecks = {}));
2124
+ })(Transformations = Utils2.Transformations || (Utils2.Transformations = {}));
2125
+ let Tree2;
2126
+ ((Tree3) => {
2127
+ function mergeNodes(nodes) {
2128
+ const clones = nodes.map((node) => node.cloneNode(true));
2129
+ const allChildren = [];
2130
+ clones.forEach((node) => {
2131
+ const actionAttribute = node.getAttribute(Tree.Tree.actionAttribute)?.trim().toLowerCase();
2132
+ const actionAttrIsValid = isInEnum(Types.Tree.Merge.Action, actionAttribute ?? "");
2133
+ const nodeAction = actionAttrIsValid ? actionAttribute : Types.Tree.Merge.Action.APPEND;
2134
+ const { Element: Element2, Text: Text2 } = Window.get();
2135
+ const children = Array.from(node.childNodes).filter((child) => child instanceof Text2 || child instanceof Element2).map((child) => {
2136
+ if (child instanceof Text2) return { node: child, key: void 0 };
2137
+ const childKey = child.getAttribute(Tree.Tree.keyAttribute) ?? void 0;
2138
+ return { node: child, key: childKey };
2139
+ });
2140
+ if (nodeAction === Types.Tree.Merge.Action.REPLACE) {
2141
+ allChildren.splice(0, allChildren.length);
2142
+ } else if (nodeAction === Types.Tree.Merge.Action.PREPEND) {
2143
+ allChildren.unshift(...children);
2144
+ } else {
2145
+ allChildren.push(...children);
2146
+ }
2147
+ });
2148
+ const mergedChildren = [];
2149
+ allChildren.forEach((childData) => {
2150
+ if (childData.key === void 0) mergedChildren.push(childData);
2151
+ else {
2152
+ const childKey = childData.key;
2153
+ const alreadyMerged = mergedChildren.find((dat) => dat.key === childKey);
2154
+ if (alreadyMerged) return;
2155
+ const toMerge = allChildren.filter((dat) => dat.key === childKey);
2156
+ if (toMerge.length === 0) return;
2157
+ const merged = mergeNodes(toMerge.map((dat) => dat.node));
2158
+ mergedChildren.push({ node: merged, key: childKey });
2159
+ }
2160
+ });
2161
+ const allAttributes = clones.reduce((attributes, node) => [
2162
+ ...Array.from(attributes),
2163
+ ...Array.from(node.attributes)
2164
+ ], []);
2165
+ const outWrapper = clones[0]?.cloneNode() ?? document.createElement("div");
2166
+ allAttributes.forEach((attr) => outWrapper.setAttribute(attr.name, attr.value));
2167
+ outWrapper.append(...mergedChildren.map((e) => e.node));
2168
+ return outWrapper;
2169
+ }
2170
+ Tree3.mergeNodes = mergeNodes;
2171
+ function getInitialValueFromTypeName(name) {
2172
+ const { document: document2 } = Window.get();
2173
+ if (name === "null") return null;
2174
+ if (name === "boolean") return false;
2175
+ if (name === "number") return 0;
2176
+ if (name === "string") return "";
2177
+ if (name === "text") return document2.createTextNode("");
2178
+ if (name === "nodelist") return document2.createDocumentFragment().childNodes;
2179
+ if (name === "element") return document2.createElement("div");
2180
+ if (name === "array") return [];
2181
+ if (name === "record") return {};
2182
+ throw new Error(`Unknown value type name: ${name}`);
2183
+ }
2184
+ Tree3.getInitialValueFromTypeName = getInitialValueFromTypeName;
2185
+ let TypeChecks;
2186
+ ((TypeChecks2) => {
2187
+ function getType(value) {
2188
+ if (singleTypeCheck(value, "null")) return "null";
2189
+ if (singleTypeCheck(value, "boolean")) return "boolean";
2190
+ if (singleTypeCheck(value, "number")) return "number";
2191
+ if (singleTypeCheck(value, "string")) return "string";
2192
+ if (singleTypeCheck(value, "element")) return "element";
2193
+ if (singleTypeCheck(value, "text")) return "text";
2194
+ if (singleTypeCheck(value, "nodelist")) return "nodelist";
2195
+ if (singleTypeCheck(value, "transformer")) return "transformer";
2196
+ if (singleTypeCheck(value, "method")) return "method";
2197
+ if (singleTypeCheck(value, "array")) return "array";
2198
+ if (singleTypeCheck(value, "record")) return "record";
2199
+ return void 0;
2200
+ }
2201
+ TypeChecks2.getType = getType;
2202
+ TypeChecks2.everyTypeName = [
2203
+ "null",
2204
+ "boolean",
2205
+ "number",
2206
+ "string",
2207
+ "text",
2208
+ "nodelist",
2209
+ "element",
2210
+ "transformer",
2211
+ "method",
2212
+ "array",
2213
+ "record"
2214
+ ];
2215
+ function singleTypeCheck(value, type) {
2216
+ const { Element: Element2, Text: Text2, NodeList } = Window.get();
2217
+ if (type === "null" && value === null) return true;
2218
+ if (type === "boolean" && typeof value === "boolean") return true;
2219
+ if (type === "number" && typeof value === "number") return true;
2220
+ if (type === "string" && typeof value === "string") return true;
2221
+ if (type === "element" && value instanceof Element2) return true;
2222
+ if (type === "text" && value instanceof Text2) return true;
2223
+ if (type === "nodelist" && value instanceof NodeList) {
2224
+ const children = Array.from(value);
2225
+ return children.every((child) => child instanceof Element2 || child instanceof Text2);
2226
+ }
2227
+ if (type === "transformer" && value instanceof Transformer) return true;
2228
+ if (type === "method" && value instanceof Method) return true;
2229
+ if (type === "array" && Array.isArray(value)) {
2230
+ const childrenOk = value.every((child) => typeCheck(child, ...TypeChecks2.everyTypeName).success);
2231
+ return childrenOk;
2232
+ }
2233
+ if (type === "record" && isRecord(value)) {
2234
+ const childrenOk = Object.values(value).every((child) => typeCheck(child, ...TypeChecks2.everyTypeName).success);
2235
+ return childrenOk;
2236
+ }
2237
+ return false;
2238
+ }
2239
+ TypeChecks2.singleTypeCheck = singleTypeCheck;
2240
+ function typeCheck(value, ...types) {
2241
+ const matchesOneType = types.some((type) => singleTypeCheck(value, type));
2242
+ if (matchesOneType) return Outcome.makeSuccess(value);
2243
+ return Outcome.makeFailure({
2244
+ expected: types.join(" | "),
2245
+ found: getType(value) ?? "undefined"
2246
+ });
2247
+ }
2248
+ TypeChecks2.typeCheck = typeCheck;
2249
+ function typeCheckMany(values, ...types) {
2250
+ for (const [pos, val] of Object.entries(values)) {
2251
+ const checked = typeCheck(val, ...types);
2252
+ if (checked.success) continue;
2253
+ return Outcome.makeFailure({ position: parseInt(pos), ...checked.error });
2254
+ }
2255
+ return Outcome.makeSuccess(values);
2256
+ }
2257
+ TypeChecks2.typeCheckMany = typeCheckMany;
2258
+ TypeChecks2.isTreeMode = (name) => name === "isolation" || name === "coalescion";
2259
+ TypeChecks2.isValueTypeName = (name) => {
2260
+ const list = [
2261
+ "null",
2262
+ "boolean",
2263
+ "number",
2264
+ "string",
2265
+ "text",
2266
+ "nodelist",
2267
+ "element",
2268
+ "transformer",
2269
+ "method",
2270
+ "array",
2271
+ "record"
2272
+ ];
2273
+ return list.includes(name);
2274
+ };
2275
+ })(TypeChecks = Tree3.TypeChecks || (Tree3.TypeChecks = {}));
2276
+ })(Tree2 = Utils2.Tree || (Utils2.Tree = {}));
2277
+ let SmartTags2;
2278
+ ((SmartTags3) => {
2279
+ SmartTags3.expectEmptyArgs = (args) => {
2280
+ if (args.length === 0) return Outcome.makeSuccess([]);
2281
+ return Outcome.makeFailure({
2282
+ expected: "length: 0",
2283
+ found: `length: ${args.length}`
2284
+ });
2285
+ };
2286
+ SmartTags3.makeMainValueError = (expected, found, details) => ({ expected, found, details });
2287
+ SmartTags3.makeArgsValueError = (expected, found, position, details) => ({ expected, found, position, details });
2288
+ SmartTags3.makeTransformationError = (details) => ({ details });
2289
+ })(SmartTags2 = Utils2.SmartTags || (Utils2.SmartTags = {}));
2290
+ })(Utils || (Utils = {}));
2291
+
2292
+ // src/agnostic/html/hyper-json/smart-tags/isolated/boolean/index.ts
2293
+ var boolean = SmartTags.makeSmartTag({
2294
+ name: "boolean",
2295
+ defaultMode: "isolation",
2296
+ isolationInitType: "boolean",
2297
+ mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "null", "boolean", "number", "string", "text"),
2298
+ argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "null", "boolean", "number", "string", "text"),
2299
+ func: (main, args) => Outcome.makeSuccess([main, ...args].every((item) => Cast.toBoolean(item)))
2300
+ });
2301
+
2302
+ export {
2303
+ boolean,
2304
+ element,
2305
+ get,
2306
+ global,
2307
+ guess,
2308
+ nodelist,
2309
+ number,
2310
+ record,
2311
+ func,
2312
+ ref,
2313
+ string,
2314
+ text,
2315
+ add,
2316
+ addclass,
2317
+ and,
2318
+ append,
2319
+ at,
2320
+ call,
2321
+ clone,
2322
+ deleteproperties,
2323
+ equals,
2324
+ getattribute,
2325
+ getproperties,
2326
+ getproperty,
2327
+ deepGetProperty,
2328
+ ifFunc,
2329
+ initialize,
2330
+ join,
2331
+ length,
2332
+ map,
2333
+ negate,
2334
+ notrailing,
2335
+ or,
2336
+ pickrandom,
2337
+ print,
2338
+ populate,
2339
+ push,
2340
+ pusheach,
2341
+ recordtoarray,
2342
+ removeattribute,
2343
+ removeclass,
2344
+ renameproperty,
2345
+ replace,
2346
+ select,
2347
+ set,
2348
+ setattribute,
2349
+ setproperty,
2350
+ sorton,
2351
+ split,
2352
+ spread,
2353
+ toarray,
2354
+ toboolean,
2355
+ toelement,
2356
+ toggleclass,
2357
+ tonodelist,
2358
+ tonull,
2359
+ tonumber,
2360
+ torecord,
2361
+ toref,
2362
+ tostring,
2363
+ totext,
2364
+ transformselected,
2365
+ trim,
2366
+ Tree,
2367
+ Utils,
2368
+ Cast
2369
+ };