@design-edito/tools 0.1.32 → 0.1.34

Sign up to get free protection for your applications and to get access to all the features.
Files changed (184) hide show
  1. package/agnostic/css/index.js +5 -5
  2. package/agnostic/html/hyper-json/cast/index.js +2 -2
  3. package/agnostic/html/hyper-json/index.js +3 -3
  4. package/agnostic/html/hyper-json/transformers/append/index.js +2 -2
  5. package/agnostic/html/hyper-json/transformers/classList/index.js +2 -2
  6. package/agnostic/html/hyper-json/transformers/index.js +2 -2
  7. package/agnostic/html/hyper-json/transformers/join/index.js +2 -2
  8. package/agnostic/html/hyper-json/transformers/length/index.js +2 -2
  9. package/agnostic/html/hyper-json/transformers/print/index.js +2 -2
  10. package/agnostic/html/hyper-json/transformers/push/index.js +2 -2
  11. package/agnostic/html/hyper-json/transformers/querySelector/index.js +2 -2
  12. package/agnostic/html/hyper-json/transformers/ref/index.js +2 -2
  13. package/agnostic/html/hyper-json/transformers/replace/index.js +2 -2
  14. package/agnostic/html/hyper-json/transformers/split/index.js +2 -2
  15. package/agnostic/html/hyper-json/transformers/toArray/index.js +2 -2
  16. package/agnostic/html/hyper-json/transformers/toBoolean/index.js +2 -2
  17. package/agnostic/html/hyper-json/transformers/toElement/index.js +2 -2
  18. package/agnostic/html/hyper-json/transformers/toNodeList/index.js +2 -2
  19. package/agnostic/html/hyper-json/transformers/toNull/index.js +2 -2
  20. package/agnostic/html/hyper-json/transformers/toNumber/index.js +2 -2
  21. package/agnostic/html/hyper-json/transformers/toRecord/index.js +2 -2
  22. package/agnostic/html/hyper-json/transformers/toRef/index.js +2 -2
  23. package/agnostic/html/hyper-json/transformers/toString/index.js +2 -2
  24. package/agnostic/html/hyper-json/transformers/toText/index.js +2 -2
  25. package/agnostic/html/hyper-json/transformers/toTransformer/index.js +2 -2
  26. package/agnostic/html/hyper-json/transformers/transformSelected/index.js +2 -2
  27. package/agnostic/html/hyper-json/transformers/trim/index.js +2 -2
  28. package/agnostic/html/hyper-json/tree/index.js +2 -2
  29. package/agnostic/html/hyper-json/utils/index.js +2 -2
  30. package/agnostic/html/index.js +13 -13
  31. package/agnostic/misc/index.js +11 -11
  32. package/agnostic/misc/lorem-ipsum/index.js +6 -6
  33. package/agnostic/numbers/index.js +3 -3
  34. package/agnostic/objects/index.d.ts +3 -1
  35. package/agnostic/objects/index.js +13 -9
  36. package/agnostic/objects/record-map/index.d.ts +3 -0
  37. package/agnostic/objects/record-map/index.js +6 -0
  38. package/agnostic/optim/index.js +3 -3
  39. package/agnostic/strings/index.js +4 -4
  40. package/agnostic/time/index.js +3 -3
  41. package/chunks/chunk-XNF5MLCQ.js +14 -0
  42. package/node/files/index.js +3 -3
  43. package/package.json +1 -2
  44. package/agnostic/html/hyper-json/crossenv/index.d.ts +0 -13
  45. package/agnostic/html/hyper-json/crossenv/index.js +0 -6
  46. package/agnostic/misc/crossenv/get-document/index.d.ts +0 -2
  47. package/agnostic/misc/crossenv/get-document/index.js +0 -7
  48. package/agnostic/misc/crossenv/get-window/browser.d.ts +0 -2
  49. package/agnostic/misc/crossenv/get-window/index.d.ts +0 -2
  50. package/agnostic/misc/crossenv/get-window/index.js +0 -6
  51. package/agnostic/misc/crossenv/types.d.ts +0 -3
  52. package/chunks/chunk-2DMWYLFG.js +0 -16
  53. package/chunks/chunk-2PI5AZIL.js +0 -211
  54. package/chunks/chunk-2UYTYTX4.js +0 -31
  55. package/chunks/chunk-3KQRMKQJ.js +0 -27
  56. package/chunks/chunk-3LVR6KZH.js +0 -22
  57. package/chunks/chunk-3PHPA25U.js +0 -18
  58. package/chunks/chunk-3PM7GZ6B.js +0 -33
  59. package/chunks/chunk-3SQJEEBK.js +0 -642
  60. package/chunks/chunk-3UQJFMBN.js +0 -27
  61. package/chunks/chunk-3UURICGY.js +0 -211
  62. package/chunks/chunk-3X6RXJBR.js +0 -37
  63. package/chunks/chunk-4F7ZVE7T.js +0 -332
  64. package/chunks/chunk-4GUDL44X.js +0 -13
  65. package/chunks/chunk-4QQBKBYH.js +0 -59
  66. package/chunks/chunk-4RDW62CU.js +0 -36
  67. package/chunks/chunk-5IR2PWO6.js +0 -211
  68. package/chunks/chunk-6CM2SWSX.js +0 -35
  69. package/chunks/chunk-6EYBQHJS.js +0 -33
  70. package/chunks/chunk-6NZCBAT4.js +0 -19
  71. package/chunks/chunk-6R54C426.js +0 -35
  72. package/chunks/chunk-6V23XMYE.js +0 -982
  73. package/chunks/chunk-73V5RDSG.js +0 -13
  74. package/chunks/chunk-7IGZP4TV.js +0 -30
  75. package/chunks/chunk-7QMAYGNV.js +0 -25
  76. package/chunks/chunk-7YW5HL6N.js +0 -168
  77. package/chunks/chunk-AFFLZUW5.js +0 -33
  78. package/chunks/chunk-AMS3FB24.js +0 -85
  79. package/chunks/chunk-APWPG7BU.js +0 -647
  80. package/chunks/chunk-AXMPRLPI.js +0 -35
  81. package/chunks/chunk-B2O7PFSF.js +0 -1108
  82. package/chunks/chunk-B6CSCX7J.js +0 -278
  83. package/chunks/chunk-B74HAAS6.js +0 -35
  84. package/chunks/chunk-BDHNULU7.js +0 -211
  85. package/chunks/chunk-BEJSITDG.js +0 -31
  86. package/chunks/chunk-BNB7LEMQ.js +0 -35
  87. package/chunks/chunk-CB52KVOZ.js +0 -22
  88. package/chunks/chunk-CECF6UZV.js +0 -29
  89. package/chunks/chunk-DBAJ66BR.js +0 -18
  90. package/chunks/chunk-DGQLPQS2.js +0 -33
  91. package/chunks/chunk-DLLTITVO.js +0 -33
  92. package/chunks/chunk-DMDOCC72.js +0 -18
  93. package/chunks/chunk-DRH7Q4FL.js +0 -127
  94. package/chunks/chunk-DRNK3RLE.js +0 -64
  95. package/chunks/chunk-EAY65ZP6.js +0 -22
  96. package/chunks/chunk-EVOTJ7SU.js +0 -35
  97. package/chunks/chunk-EW46EXFB.js +0 -8
  98. package/chunks/chunk-F5YMP5WU.js +0 -18
  99. package/chunks/chunk-F7EVMWVG.js +0 -27
  100. package/chunks/chunk-F7XWUG2V.js +0 -18
  101. package/chunks/chunk-FFOATPL4.js +0 -211
  102. package/chunks/chunk-FSCSFZOD.js +0 -647
  103. package/chunks/chunk-FWHUASVA.js +0 -22
  104. package/chunks/chunk-G2NZXHW6.js +0 -21
  105. package/chunks/chunk-GDYVCEWA.js +0 -38
  106. package/chunks/chunk-GNBIAWSY.js +0 -278
  107. package/chunks/chunk-GQSPY2CV.js +0 -19
  108. package/chunks/chunk-HDALT7XM.js +0 -620
  109. package/chunks/chunk-HEJV6JIO.js +0 -133
  110. package/chunks/chunk-HENMQK5Y.js +0 -647
  111. package/chunks/chunk-HFEOHBYG.js +0 -647
  112. package/chunks/chunk-HGECIEKD.js +0 -35
  113. package/chunks/chunk-HUKHWFVL.js +0 -19
  114. package/chunks/chunk-IGD53YL5.js +0 -870
  115. package/chunks/chunk-ILEM73XB.js +0 -981
  116. package/chunks/chunk-IPB3U2PD.js +0 -278
  117. package/chunks/chunk-JAST3E5G.js +0 -647
  118. package/chunks/chunk-JY3QZ2YO.js +0 -211
  119. package/chunks/chunk-K3OQEJI3.js +0 -33
  120. package/chunks/chunk-KN4RZPDY.js +0 -211
  121. package/chunks/chunk-KXBKJ3GS.js +0 -642
  122. package/chunks/chunk-L7SL3MND.js +0 -35
  123. package/chunks/chunk-LCFDDWJR.js +0 -278
  124. package/chunks/chunk-LFUY5AWK.js +0 -1108
  125. package/chunks/chunk-LGECI2WL.js +0 -306
  126. package/chunks/chunk-LGUEB5L5.js +0 -211
  127. package/chunks/chunk-LI6QDZCA.js +0 -211
  128. package/chunks/chunk-LYMZZ4BB.js +0 -22
  129. package/chunks/chunk-MDEDNPU5.js +0 -38
  130. package/chunks/chunk-MQHKEGP4.js +0 -33
  131. package/chunks/chunk-NF5ACCXZ.js +0 -211
  132. package/chunks/chunk-NFUY7SLX.js +0 -211
  133. package/chunks/chunk-NK557MKV.js +0 -35
  134. package/chunks/chunk-NTBSGBV2.js +0 -1108
  135. package/chunks/chunk-NWFX6TEY.js +0 -28
  136. package/chunks/chunk-NWMEWFTK.js +0 -33
  137. package/chunks/chunk-O5OTBN22.js +0 -35
  138. package/chunks/chunk-O7MDUYEF.js +0 -211
  139. package/chunks/chunk-OO5SJJDW.js +0 -35
  140. package/chunks/chunk-OVG5RGI3.js +0 -29
  141. package/chunks/chunk-OWRQ3QBI.js +0 -211
  142. package/chunks/chunk-PO3V3I57.js +0 -23
  143. package/chunks/chunk-PXB7U2DH.js +0 -31
  144. package/chunks/chunk-Q52UJOBC.js +0 -18
  145. package/chunks/chunk-QFEF4EET.js +0 -211
  146. package/chunks/chunk-QHSVCGLD.js +0 -280
  147. package/chunks/chunk-QO64L4KB.js +0 -97
  148. package/chunks/chunk-R6KCN6CK.js +0 -40
  149. package/chunks/chunk-RHYLRLKT.js +0 -211
  150. package/chunks/chunk-RJ5E22H5.js +0 -15
  151. package/chunks/chunk-RWUPHV54.js +0 -25
  152. package/chunks/chunk-S2757FI3.js +0 -36
  153. package/chunks/chunk-S42P73SC.js +0 -30
  154. package/chunks/chunk-S5XDYLJH.js +0 -18
  155. package/chunks/chunk-S7MJLTCR.js +0 -211
  156. package/chunks/chunk-SCM6NACT.js +0 -15
  157. package/chunks/chunk-SFV2NYY4.js +0 -211
  158. package/chunks/chunk-SH3Y2I5P.js +0 -18
  159. package/chunks/chunk-SMLKMOAX.js +0 -18
  160. package/chunks/chunk-SQZGZ3VT.js +0 -15
  161. package/chunks/chunk-T5CGXYST.js +0 -647
  162. package/chunks/chunk-TATRVKBS.js +0 -211
  163. package/chunks/chunk-TRB6DPKJ.js +0 -35
  164. package/chunks/chunk-UFKH5WD2.js +0 -21
  165. package/chunks/chunk-UODQZRY2.js +0 -620
  166. package/chunks/chunk-UOULDS6J.js +0 -33
  167. package/chunks/chunk-UPHVZROF.js +0 -35
  168. package/chunks/chunk-UUDXUSI5.js +0 -211
  169. package/chunks/chunk-UWAMSJ2X.js +0 -28
  170. package/chunks/chunk-UZUXLD2Q.js +0 -35
  171. package/chunks/chunk-VA6HXRX4.js +0 -211
  172. package/chunks/chunk-VRUJR6WR.js +0 -39
  173. package/chunks/chunk-W6YBEEZM.js +0 -211
  174. package/chunks/chunk-WABWQCFE.js +0 -127
  175. package/chunks/chunk-WECTUHS5.js +0 -127
  176. package/chunks/chunk-YE5HI3RK.js +0 -211
  177. package/chunks/chunk-YEBOL67V.js +0 -32
  178. package/chunks/chunk-YRGOY5YU.js +0 -1108
  179. package/chunks/chunk-YYE2MVZO.js +0 -211
  180. package/chunks/chunk-ZB73RE7P.js +0 -35
  181. package/chunks/chunk-ZONKYNKA.js +0 -28
  182. package/chunks/{chunk-GPWFYPER.js → chunk-5HWYTIYR.js} +3 -3
  183. package/chunks/{chunk-MCW3JX25.js → chunk-FWZSMFVA.js} +9 -9
  184. package/chunks/{chunk-MUGIN5OW.js → chunk-MZSIKE3H.js} +3 -3
@@ -1,620 +0,0 @@
1
- import {
2
- toRef
3
- } from "./chunk-4RDW62CU.js";
4
- import {
5
- toNumber
6
- } from "./chunk-F7XWUG2V.js";
7
- import {
8
- toRecord
9
- } from "./chunk-F5YMP5WU.js";
10
- import {
11
- toString
12
- } from "./chunk-DMDOCC72.js";
13
- import {
14
- toText
15
- } from "./chunk-3PHPA25U.js";
16
- import {
17
- toTransformer
18
- } from "./chunk-SMLKMOAX.js";
19
- import {
20
- trim
21
- } from "./chunk-7IGZP4TV.js";
22
- import {
23
- replace
24
- } from "./chunk-MDEDNPU5.js";
25
- import {
26
- ref
27
- } from "./chunk-3X6RXJBR.js";
28
- import {
29
- toArray
30
- } from "./chunk-Q52UJOBC.js";
31
- import {
32
- split
33
- } from "./chunk-6CM2SWSX.js";
34
- import {
35
- toBoolean
36
- } from "./chunk-SH3Y2I5P.js";
37
- import {
38
- toElement
39
- } from "./chunk-S5XDYLJH.js";
40
- import {
41
- toNodeList
42
- } from "./chunk-DBAJ66BR.js";
43
- import {
44
- toNull
45
- } from "./chunk-RJ5E22H5.js";
46
- import {
47
- append
48
- } from "./chunk-K3OQEJI3.js";
49
- import {
50
- join
51
- } from "./chunk-RWUPHV54.js";
52
- import {
53
- classList
54
- } from "./chunk-VRUJR6WR.js";
55
- import {
56
- length
57
- } from "./chunk-S42P73SC.js";
58
- import {
59
- print
60
- } from "./chunk-2DMWYLFG.js";
61
- import {
62
- querySelector
63
- } from "./chunk-BNB7LEMQ.js";
64
- import {
65
- push
66
- } from "./chunk-FWHUASVA.js";
67
- import {
68
- Cast
69
- } from "./chunk-QO64L4KB.js";
70
- import {
71
- Serialize
72
- } from "./chunk-DRNK3RLE.js";
73
- import {
74
- Crossenv
75
- } from "./chunk-3LVR6KZH.js";
76
- import {
77
- Types
78
- } from "./chunk-7QMAYGNV.js";
79
- import {
80
- Utils
81
- } from "./chunk-YEBOL67V.js";
82
- import {
83
- replaceInElement
84
- } from "./chunk-GBMHGF7P.js";
85
- import {
86
- isInEnum
87
- } from "./chunk-E6MSDKON.js";
88
- import {
89
- isRecord
90
- } from "./chunk-YDIBNEGA.js";
91
-
92
- // src/agnostic/html/hyper-json/transformers/transformSelected/index.ts
93
- var transformSelected = (callerTagName, ...args) => {
94
- return Utils.toNamedTransformer(callerTagName, (currentValue, callerTree) => {
95
- const { NodeList, Element, Text } = Crossenv.getWindow();
96
- if (!(currentValue instanceof Element) && !(currentValue instanceof NodeList)) return Utils.makeTransformerError({
97
- message: "Current value must be Element or NodeList",
98
- input: currentValue
99
- });
100
- const [selector, ...transformerDescriptors] = args;
101
- if (typeof selector !== "string" && !(selector instanceof Text)) return Utils.makeTransformerError({
102
- message: "Selector argument must be string or text",
103
- input: selector !== void 0 ? selector : "<undefined>"
104
- });
105
- if (transformerDescriptors.length === 0) return Utils.makeTransformerError("No transformer descriptor provided");
106
- let transformers = [];
107
- for (const descriptor of transformerDescriptors) {
108
- const errorResponse = Utils.makeTransformerError({
109
- message: "Transformer descriptors must be of shape { name: string, arguments: Value[] }",
110
- input: descriptor
111
- });
112
- if (!isRecord(descriptor)) return errorResponse;
113
- if (!("name" in descriptor) || typeof descriptor.name !== "string") return errorResponse;
114
- if (!("arguments" in descriptor) || !Array.isArray(descriptor.arguments)) return errorResponse;
115
- const { name, arguments: args2 } = descriptor;
116
- const generator = callerTree.getGenerator(name);
117
- if (generator === void 0) return Utils.makeTransformerError(`No transformer found under the name ${name}`);
118
- transformers.push(generator(name, ...args2));
119
- }
120
- const elementInput = Cast.toElement(currentValue);
121
- const strSelector = Cast.toString(selector);
122
- const selected = Array.from(elementInput.querySelectorAll(strSelector));
123
- const transformationErrors = [];
124
- const transformed = selected.map((input) => {
125
- const output = transformers.reduce((reduced, transformer, transformerPos) => {
126
- const result = transformer(reduced, callerTree);
127
- if (result.action === "REPLACE") return result.value;
128
- else if (result.action === "MERGE") {
129
- const merged = Tree.mergeValues(
130
- reduced,
131
- result.value,
132
- transformerPos,
133
- callerTree
134
- );
135
- return merged;
136
- }
137
- if (result.action === "ERROR") transformationErrors.push({
138
- message: result.value,
139
- transformerName: transformer.transformerName,
140
- transformerPos,
141
- transforming: reduced
142
- });
143
- return reduced;
144
- }, input);
145
- return { input, output };
146
- });
147
- if (transformationErrors.length !== 0) return Utils.makeTransformerError({
148
- message: "Some nested transformers returned an error",
149
- errors: transformationErrors
150
- });
151
- const nonElementTransformResult = transformed.find((item) => !(item.output instanceof Element));
152
- if (nonElementTransformResult !== void 0) return Utils.makeTransformerError({
153
- message: "Some transformations resulted in a non Element output",
154
- inputElement: nonElementTransformResult.input,
155
- outputValue: nonElementTransformResult.output
156
- });
157
- const transformMap = new Map(transformed.map((e) => [e.input, e.output]));
158
- const elementOutput = replaceInElement(elementInput, transformMap);
159
- return {
160
- action: "REPLACE",
161
- value: elementOutput
162
- };
163
- });
164
- };
165
-
166
- // src/agnostic/html/hyper-json/transformers/index.ts
167
- var Transformers;
168
- ((Transformers2) => {
169
- Transformers2.defaultGeneratorsMap = /* @__PURE__ */ new Map([
170
- ["append", append],
171
- ["classList", classList],
172
- ["join", join],
173
- ["length", length],
174
- ["print", print],
175
- ["push", push],
176
- ["querySelector", querySelector],
177
- ["ref", ref],
178
- ["replace", replace],
179
- ["split", split],
180
- ["toArray", toArray],
181
- ["toBoolean", toBoolean],
182
- ["toElement", toElement],
183
- ["toNodeList", toNodeList],
184
- ["toNull", toNull],
185
- ["toNumber", toNumber],
186
- ["toRecord", toRecord],
187
- ["toRef", toRef],
188
- ["toString", toString],
189
- ["toText", toText],
190
- ["toTransformer", toTransformer],
191
- ["transformSelected", transformSelected],
192
- ["trim", trim]
193
- ]);
194
- })(Transformers || (Transformers = {}));
195
-
196
- // src/agnostic/html/hyper-json/tree/index.ts
197
- var getWindow = Crossenv.getWindow;
198
- var isElement = (node) => node.nodeType === getWindow().Node.ELEMENT_NODE;
199
- var isText = (node) => node.nodeType === getWindow().Node.TEXT_NODE;
200
- var Tree;
201
- ((_Tree) => {
202
- function fillOptions(options) {
203
- const defaultOptions = {
204
- generatorsMap: Transformers.defaultGeneratorsMap,
205
- keyAttribute: "_name",
206
- actionAttribute: "_action"
207
- };
208
- return {
209
- ...defaultOptions,
210
- ...options
211
- };
212
- }
213
- _Tree.fillOptions = fillOptions;
214
- function mergeValues(currentValue, incomingValue, mergeKey, initiatorTree) {
215
- const { Element, Text, NodeList, document } = getWindow();
216
- if (typeof incomingValue === "function") {
217
- const evaluated = incomingValue(currentValue, initiatorTree);
218
- if (evaluated.action === null) return currentValue;
219
- if (evaluated.action === "REPLACE") return evaluated.value;
220
- if (evaluated.action === "ERROR") {
221
- const errorMessage = `Tranformer error:
222
- from: ${incomingValue.transformerName}
223
- at: ${initiatorTree.pathString.slice(1)}/${mergeKey}
224
- message:`;
225
- console.warn(errorMessage, evaluated.value);
226
- return currentValue;
227
- }
228
- return mergeValues(
229
- currentValue,
230
- evaluated.value,
231
- mergeKey,
232
- initiatorTree
233
- );
234
- }
235
- if (Array.isArray(currentValue)) {
236
- if (typeof mergeKey === "string") return currentValue;
237
- return [...currentValue, incomingValue];
238
- }
239
- if (currentValue === null || typeof currentValue === "boolean" || typeof currentValue === "number" || typeof currentValue === "string" || typeof currentValue === "function" || currentValue instanceof Text || currentValue instanceof Element) {
240
- if (incomingValue === null || typeof incomingValue === "boolean" || typeof incomingValue === "number" || typeof incomingValue === "string" || Array.isArray(incomingValue) || isRecord(incomingValue)) {
241
- return incomingValue;
242
- }
243
- const frag = document.createDocumentFragment();
244
- if (currentValue instanceof Element || currentValue instanceof Text) frag.append(currentValue.cloneNode(true));
245
- else frag.append(`${currentValue}`);
246
- if (incomingValue instanceof Element || incomingValue instanceof Text) {
247
- frag.append(incomingValue.cloneNode(true));
248
- return frag.childNodes;
249
- }
250
- frag.append(...Array.from(incomingValue).map((e) => e.cloneNode(true)));
251
- return frag.childNodes;
252
- }
253
- if (currentValue instanceof NodeList) {
254
- if (incomingValue instanceof Element || incomingValue instanceof Text) {
255
- const frag = document.createDocumentFragment();
256
- frag.append(...Array.from(currentValue).map((e) => e.cloneNode(true)), incomingValue);
257
- return frag.childNodes;
258
- }
259
- if (incomingValue instanceof NodeList) {
260
- const frag = document.createDocumentFragment();
261
- frag.append(
262
- ...Array.from(currentValue).map((e) => e.cloneNode(true)),
263
- ...Array.from(incomingValue).map((e) => e.cloneNode(true))
264
- );
265
- return frag.childNodes;
266
- }
267
- if (incomingValue === null || typeof incomingValue === "string" || typeof incomingValue === "number" || typeof incomingValue === "boolean") {
268
- const frag = document.createDocumentFragment();
269
- frag.append(...Array.from(currentValue).map((e) => e.cloneNode(true)), `${incomingValue}`);
270
- return frag.childNodes;
271
- }
272
- if (Array.isArray(incomingValue)) return [
273
- ...Array.from(currentValue),
274
- ...incomingValue
275
- ];
276
- return { ...incomingValue };
277
- }
278
- if (typeof mergeKey === "number") return currentValue;
279
- return {
280
- ...currentValue,
281
- [mergeKey]: incomingValue
282
- };
283
- }
284
- _Tree.mergeValues = mergeValues;
285
- function merge(nodes, options = {}) {
286
- const [first, ...rest] = nodes;
287
- const defaultOptions = fillOptions({});
288
- const actionAttribute = options?.actionAttribute ?? defaultOptions.actionAttribute;
289
- const keyAttribute = options?.keyAttribute ?? defaultOptions.keyAttribute;
290
- if (first === void 0) throw new Error("Expecting at least one node");
291
- const { Text, Element, document } = getWindow();
292
- const wrapper = document.createElement("div");
293
- wrapper.append(first);
294
- rest.forEach((node) => {
295
- const current = wrapper.childNodes[0];
296
- if (current === void 0) return wrapper.append(node);
297
- if (node instanceof Text) return replaceElement(node, current);
298
- const actionRaw = node.getAttribute(actionAttribute);
299
- const action = isInEnum(Types.ReductionAction, actionRaw) ? actionRaw : Types.ReductionAction.REPLACE;
300
- if (action === Types.ReductionAction.REPLACE) return replaceElement(node, current);
301
- if (current instanceof Text) {
302
- if (node instanceof Text) {
303
- const appended = action === Types.ReductionAction.APPEND ? document.createTextNode(`${current.textContent}${node.textContent}`) : document.createTextNode(`${node.textContent}${current.textContent}`);
304
- return replaceElement(appended, current);
305
- }
306
- return replaceElement(node, current);
307
- }
308
- if (node instanceof Text) return replaceElement(node, current);
309
- return action === Types.ReductionAction.APPEND ? appendInElement(node, current) : prependInElement(node, current);
310
- });
311
- const wrapperChildren = Array.from(wrapper.childNodes);
312
- const subpaths = /* @__PURE__ */ new Map();
313
- let positionnedChildrenCount = 0;
314
- wrapperChildren.forEach((child) => {
315
- if (child instanceof Text) {
316
- const childKey = positionnedChildrenCount;
317
- const found = subpaths.get(childKey) ?? [];
318
- found.push(child);
319
- subpaths.set(childKey, found);
320
- positionnedChildrenCount += 1;
321
- } else {
322
- const rawChildKey = child.getAttribute(keyAttribute);
323
- const childKey = rawChildKey ?? positionnedChildrenCount;
324
- const found = subpaths.get(childKey) ?? [];
325
- found.push(child);
326
- subpaths.set(childKey, found);
327
- if (rawChildKey === null) {
328
- positionnedChildrenCount += 1;
329
- }
330
- }
331
- });
332
- subpaths.forEach((nodes2) => {
333
- if (nodes2.length < 2) return;
334
- return merge(nodes2, {
335
- actionAttribute,
336
- keyAttribute
337
- });
338
- });
339
- const wrapperFirstChild = wrapper.childNodes[0];
340
- if (wrapperFirstChild === void 0) throw new Error("Empty output");
341
- return wrapperFirstChild;
342
- function replaceElement(replacer, element) {
343
- element.parentNode?.replaceChild(replacer, element);
344
- }
345
- function isTextOrElement(node) {
346
- return node instanceof Text || node instanceof Element;
347
- }
348
- function appendInElement(appender, element) {
349
- const appenderChildren = Array.from(appender.childNodes).filter(isTextOrElement);
350
- element.append(...appenderChildren);
351
- }
352
- function prependInElement(prepender, element) {
353
- const prependerChildren = Array.from(prepender.childNodes).filter(isTextOrElement);
354
- element.prepend(...prependerChildren);
355
- }
356
- }
357
- _Tree.merge = merge;
358
- function create(...args) {
359
- return new Tree2(...args);
360
- }
361
- _Tree.create = create;
362
- class Tree2 {
363
- node;
364
- name;
365
- parent;
366
- root;
367
- isRoot;
368
- path;
369
- pathString;
370
- tagName;
371
- attributes;
372
- subtrees = /* @__PURE__ */ new Map();
373
- children;
374
- type;
375
- generators;
376
- keyAttribute;
377
- actionAttribute;
378
- constructor(node, parentOrOptions, pathFromParent, options) {
379
- this.resolve = this.resolve.bind(this);
380
- this.getGenerator = this.getGenerator.bind(this);
381
- this.initValue = this.initValue.bind(this);
382
- this.getInnerValue = this.getInnerValue.bind(this);
383
- this.wrapInnerValue = this.wrapInnerValue.bind(this);
384
- this.setCache = this.setCache.bind(this);
385
- this.getPerfCounters = this.getPerfCounters.bind(this);
386
- this.printPerfCounters = this.printPerfCounters.bind(this);
387
- this.pushToEvalCallStack = this.pushToEvalCallStack.bind(this);
388
- this.flushEvalCallStack = this.flushEvalCallStack.bind(this);
389
- this.evaluate = this.evaluate.bind(this);
390
- const { Element, Text } = getWindow();
391
- const _node = node;
392
- const _parent = parentOrOptions instanceof Tree2 ? parentOrOptions : void 0;
393
- this.node = _node;
394
- this.parent = _parent ?? null;
395
- this.root = this.parent === null ? this : this.parent.root;
396
- this.isRoot = this.root === this;
397
- const _options = options ?? parentOrOptions instanceof Tree2 ? fillOptions({}) : fillOptions(parentOrOptions ?? {});
398
- this.keyAttribute = _options.keyAttribute;
399
- this.actionAttribute = _options.actionAttribute;
400
- this.generators = this.isRoot ? _options.generatorsMap : this.root.generators;
401
- this.name = this.node instanceof Element ? this.node.getAttribute(this.keyAttribute) : null;
402
- const _pathFromParent = pathFromParent !== void 0 ? pathFromParent : void 0;
403
- if (this.parent === null) this.path = [];
404
- else if (_pathFromParent === void 0) {
405
- this.path = [...this.parent.path, 0];
406
- } else {
407
- this.path = [...this.parent.path, _pathFromParent];
408
- }
409
- this.pathString = `/${this.path.join("/")}`;
410
- this.tagName = node instanceof Element ? node.tagName.toLowerCase() : null;
411
- this.attributes = isElement(node) ? Array.from(node.attributes) : null;
412
- const { childNodes } = node;
413
- let positionnedChildrenCount = 0;
414
- const mutableSubtrees = /* @__PURE__ */ new Map();
415
- Array.from(childNodes).filter((node2, _, nodes) => {
416
- if (isElement(node2)) return true;
417
- if (isText(node2)) {
418
- const hasContent = (node2.textContent ?? "").trim() !== "";
419
- if (hasContent) return true;
420
- if (nodes.some((n) => n instanceof Element)) return false;
421
- return true;
422
- }
423
- return false;
424
- }).forEach((childNode) => {
425
- if (childNode instanceof Text) {
426
- mutableSubtrees.set(
427
- positionnedChildrenCount,
428
- new Tree2(childNode, this, positionnedChildrenCount)
429
- );
430
- positionnedChildrenCount += 1;
431
- } else {
432
- const propertyName = childNode.getAttribute(this.keyAttribute);
433
- if (propertyName === null) {
434
- mutableSubtrees.set(
435
- positionnedChildrenCount,
436
- new Tree2(childNode, this, positionnedChildrenCount)
437
- );
438
- positionnedChildrenCount += 1;
439
- } else {
440
- mutableSubtrees.set(
441
- propertyName,
442
- new Tree2(childNode, this, propertyName)
443
- );
444
- }
445
- }
446
- });
447
- this.subtrees = mutableSubtrees;
448
- this.children = Array.from(this.subtrees.values());
449
- if (this.tagName === null) {
450
- this.type = "text";
451
- } else if (this.tagName === Types.TyperTagName.NULL) {
452
- this.type = "null";
453
- } else if (this.tagName === Types.TyperTagName.BOOLEAN) {
454
- this.type = "boolean";
455
- } else if (this.tagName === Types.TyperTagName.NUMBER) {
456
- this.type = "number";
457
- } else if (this.tagName === Types.TyperTagName.STRING) {
458
- this.type = "string";
459
- } else if (this.tagName === Types.TyperTagName.TEXT) {
460
- this.type = "text";
461
- } else if (this.tagName === Types.TyperTagName.NODELIST) {
462
- this.type = "nodelist";
463
- } else if (this.tagName === Types.TyperTagName.ARRAY) {
464
- this.type = "array";
465
- } else if (this.tagName === Types.TyperTagName.RECORD) {
466
- this.type = "record";
467
- } else if (this.generators.get(this.tagName) !== void 0) {
468
- this.type = "transformer";
469
- } else {
470
- this.type = "element";
471
- }
472
- }
473
- resolve = function(path) {
474
- let currentTree = this.root;
475
- for (const chunk of path) {
476
- const { subtrees } = currentTree;
477
- const foundSubtree = subtrees.get(chunk);
478
- if (foundSubtree === void 0) return void 0;
479
- currentTree = foundSubtree;
480
- }
481
- return currentTree;
482
- };
483
- getGenerator(name) {
484
- return this.generators.get(name);
485
- }
486
- initValue() {
487
- const { type } = this;
488
- let currentValue;
489
- if (type === "null") {
490
- currentValue = null;
491
- } else if (type === "boolean") {
492
- currentValue = false;
493
- } else if (type === "number") {
494
- currentValue = 0;
495
- } else if (type === "string") {
496
- currentValue = "";
497
- } else if (type === "text") {
498
- currentValue = this.node.textContent;
499
- } else if (type === "element") {
500
- currentValue = getWindow().document.createDocumentFragment().childNodes;
501
- } else if (type === "nodelist") {
502
- currentValue = getWindow().document.createDocumentFragment().childNodes;
503
- } else if (type === "array") {
504
- currentValue = [];
505
- } else if (type === "record") {
506
- currentValue = {};
507
- } else if (type === "transformer") {
508
- currentValue = [];
509
- } else {
510
- currentValue = null;
511
- }
512
- return currentValue;
513
- }
514
- getInnerValue(initialValue) {
515
- const { subtrees } = this;
516
- const innerValue = Array.from(subtrees.entries()).reduce((currentValue, [subpath, subtree]) => mergeValues(
517
- currentValue,
518
- subtree.evaluate(),
519
- subpath,
520
- this
521
- ), initialValue);
522
- return innerValue;
523
- }
524
- wrapInnerValue(innerValue) {
525
- const { type } = this;
526
- if (type === "transformer") {
527
- const transformerName = this.tagName;
528
- if (transformerName === null) return innerValue;
529
- const generator = this.getGenerator(transformerName);
530
- if (generator === void 0) return innerValue;
531
- const transformer = Array.isArray(innerValue) ? generator(transformerName, ...innerValue) : generator(transformerName, innerValue);
532
- return transformer;
533
- }
534
- if (type === "null") return Cast.toNull();
535
- if (type === "boolean") return Cast.toBoolean(innerValue);
536
- if (type === "number") return Cast.toNumber(innerValue);
537
- if (type === "string") return Cast.toString(innerValue);
538
- if (type === "array") return Cast.toArray(innerValue);
539
- if (type === "record") return Cast.toRecord(innerValue);
540
- if (type === "text") return Cast.toText(innerValue);
541
- if (type === "element") return Cast.toElement(innerValue);
542
- if (type === "nodelist") return Cast.toNodeList(innerValue);
543
- return Cast.toNull();
544
- }
545
- cache = void 0;
546
- setCache(value) {
547
- this.cache = Serialize.serialize(value);
548
- }
549
- perfCounters = {
550
- computed: 0,
551
- computeTime: 0,
552
- computeTimeAvg: 0,
553
- cached: 0,
554
- cacheTime: 0,
555
- cacheTimeAvg: 0,
556
- totalTime: 0
557
- };
558
- getPerfCounters() {
559
- const { subtrees } = this;
560
- const subCounters = [];
561
- subCounters.push([this.pathString, this.perfCounters]);
562
- subtrees.forEach((subtree) => subCounters.push(...subtree.getPerfCounters()));
563
- return subCounters;
564
- }
565
- printPerfCounters() {
566
- const perfCounters = this.getPerfCounters().sort((a, b) => b[1].totalTime - a[1].totalTime).map((e) => ({
567
- path: e[0],
568
- totalMs: e[1].totalTime,
569
- computeMs: e[1].computeTime,
570
- cacheMs: e[1].cacheTime,
571
- ops: `${e[1].computed}/${e[1].cached}`
572
- }));
573
- console.table(perfCounters);
574
- }
575
- callstack = [];
576
- pushToEvalCallStack(path) {
577
- this.callstack.push(path);
578
- this.parent?.pushToEvalCallStack(path);
579
- }
580
- flushEvalCallStack() {
581
- this.callstack.length = 0;
582
- }
583
- evaluate() {
584
- const start = Date.now();
585
- const circularPatternDetected = this.callstack.some((p) => p.startsWith(this.pathString));
586
- if (circularPatternDetected) throw new Error(`Circular reference pattern detected @ ${this.pathString}`);
587
- this.pushToEvalCallStack(this.pathString);
588
- const { perfCounters, cache } = this;
589
- if (cache !== void 0) {
590
- const deserialized = Serialize.deserialize(cache);
591
- const end2 = Date.now();
592
- const time2 = end2 - start;
593
- perfCounters.cached++;
594
- perfCounters.cacheTime += time2;
595
- perfCounters.cacheTimeAvg = perfCounters.cacheTime / perfCounters.cached;
596
- perfCounters.totalTime = perfCounters.computeTime + perfCounters.cacheTime;
597
- return deserialized;
598
- }
599
- const init = this.initValue();
600
- const inner = this.getInnerValue(init);
601
- const wrapped = this.wrapInnerValue(inner);
602
- this.setCache(wrapped);
603
- const end = Date.now();
604
- const time = end - start;
605
- perfCounters.computed++;
606
- perfCounters.computeTime += time;
607
- perfCounters.computeTimeAvg = perfCounters.computeTime / perfCounters.computed;
608
- perfCounters.totalTime = perfCounters.computeTime + perfCounters.cacheTime;
609
- this.flushEvalCallStack();
610
- return wrapped;
611
- }
612
- }
613
- _Tree.Tree = Tree2;
614
- })(Tree || (Tree = {}));
615
-
616
- export {
617
- Tree,
618
- transformSelected,
619
- Transformers
620
- };