@design-edito/tools 0.1.38 → 0.1.40

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