@design-edito/tools 0.1.20 → 0.1.22

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