@design-edito/tools 0.1.43 → 0.1.45

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