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