@design-edito/tools 0.1.21 → 0.1.22

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