@design-edito/tools 0.1.21 → 0.1.23
Sign up to get free protection for your applications and to get access to all the features.
- package/agnostic/arrays/find-duplicates/index.d.ts +1 -0
- package/agnostic/arrays/find-duplicates/index.js +6 -0
- package/agnostic/arrays/index.d.ts +8 -7
- package/agnostic/arrays/make/index.d.ts +3 -0
- package/agnostic/arrays/make/index.js +6 -0
- package/agnostic/arrays/random-pick/index.d.ts +2 -0
- package/agnostic/arrays/random-pick/index.js +8 -0
- package/agnostic/css/index.js +13 -13
- package/agnostic/html/hyper-json/cast/index.d.ts +18 -0
- package/agnostic/html/hyper-json/cast/index.js +11 -0
- package/agnostic/html/hyper-json/crossenv/index.d.ts +13 -0
- package/agnostic/html/hyper-json/crossenv/index.js +6 -0
- package/agnostic/html/hyper-json/index.d.ts +14 -43
- package/agnostic/html/hyper-json/index.js +32 -2
- package/agnostic/html/hyper-json/serialize/index.d.ts +5 -0
- package/agnostic/html/hyper-json/serialize/index.js +7 -0
- package/agnostic/html/hyper-json/transformers/append/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/append/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/classList/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/classList/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/index.d.ts +4 -0
- package/agnostic/html/hyper-json/transformers/index.js +39 -0
- package/agnostic/html/hyper-json/transformers/join/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/join/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/length/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/length/index.js +8 -0
- package/agnostic/html/hyper-json/transformers/print/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/print/index.js +7 -0
- package/agnostic/html/hyper-json/transformers/push/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/push/index.js +7 -0
- package/agnostic/html/hyper-json/transformers/querySelector/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/querySelector/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/ref/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/ref/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/replace/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/replace/index.js +13 -0
- package/agnostic/html/hyper-json/transformers/split/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/split/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/toArray/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/toArray/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/toBoolean/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/toBoolean/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/toElement/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/toElement/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/toNodeList/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/toNodeList/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/toNull/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/toNull/index.js +7 -0
- package/agnostic/html/hyper-json/transformers/toNumber/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/toNumber/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/toRecord/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/toRecord/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/toRef/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/toRef/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/toString/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/toString/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/toText/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/toText/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/toTransformer/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/toTransformer/index.js +12 -0
- package/agnostic/html/hyper-json/transformers/transformSelected/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/transformSelected/index.js +39 -0
- package/agnostic/html/hyper-json/transformers/trim/index.d.ts +2 -0
- package/agnostic/html/hyper-json/transformers/trim/index.js +12 -0
- package/agnostic/html/hyper-json/tree/index.d.ts +58 -0
- package/agnostic/html/hyper-json/tree/index.js +39 -0
- package/agnostic/html/hyper-json/types/index.d.ts +86 -0
- package/agnostic/html/hyper-json/types/index.js +6 -0
- package/agnostic/html/hyper-json/utils/index.d.ts +10 -0
- package/agnostic/html/hyper-json/utils/index.js +6 -0
- package/agnostic/html/index.js +48 -16
- package/agnostic/html/replace-in-element/index.d.ts +1 -0
- package/agnostic/html/replace-in-element/index.js +6 -0
- package/agnostic/html/sanitize/index.js +5 -3
- package/agnostic/html/selector-to-element/index.js +5 -3
- package/agnostic/html/string-to-nodes/index.js +6 -4
- package/agnostic/index.d.ts +0 -2
- package/agnostic/misc/{web-crawler → crawler}/index.d.ts +1 -1
- package/agnostic/misc/crawler/index.js +7 -0
- package/agnostic/misc/crossenv/get-document/index.d.ts +2 -0
- package/agnostic/misc/crossenv/get-document/index.js +7 -0
- package/agnostic/misc/crossenv/get-window/browser.d.ts +2 -0
- package/agnostic/misc/crossenv/get-window/index.d.ts +2 -0
- package/agnostic/misc/crossenv/get-window/index.js +6 -0
- package/agnostic/misc/crossenv/index.d.ts +4 -1
- package/agnostic/misc/crossenv/index.js +3 -1
- package/agnostic/misc/crossenv/types.d.ts +3 -0
- package/agnostic/misc/index.d.ts +3 -1
- package/agnostic/misc/index.js +24 -14
- package/agnostic/misc/lorem-ipsum/index.js +5 -2
- package/agnostic/numbers/index.js +6 -6
- package/agnostic/objects/index.js +9 -9
- package/agnostic/optim/index.js +3 -3
- package/agnostic/random/index.js +6 -0
- package/agnostic/strings/index.js +3 -3
- package/agnostic/time/duration/index.d.ts +26 -0
- package/agnostic/time/duration/index.js +6 -0
- package/agnostic/time/index.d.ts +8 -7
- package/agnostic/time/index.js +17 -28
- package/agnostic/time/timeout/index.d.ts +1 -0
- package/agnostic/time/timeout/index.js +6 -0
- package/agnostic/time/transitions/index.js +7 -0
- package/agnostic/time/wait/index.js +6 -0
- package/chunks/chunk-2DMWYLFG.js +16 -0
- package/chunks/chunk-2KT7AKRW.js +17 -0
- package/chunks/{chunk-UCV2AZZV.js → chunk-2PI5AZIL.js} +14 -25
- package/chunks/chunk-3KQRMKQJ.js +27 -0
- package/chunks/chunk-3LVR6KZH.js +22 -0
- package/chunks/chunk-3PHPA25U.js +18 -0
- package/chunks/chunk-3PM7GZ6B.js +33 -0
- package/chunks/chunk-3SQJEEBK.js +642 -0
- package/chunks/chunk-3UURICGY.js +211 -0
- package/chunks/chunk-3X6RXJBR.js +37 -0
- package/chunks/{chunk-DQNJQBC6.js → chunk-4CIS3R7T.js} +1 -1
- package/chunks/chunk-4F7ZVE7T.js +332 -0
- package/chunks/chunk-4GUDL44X.js +13 -0
- package/chunks/chunk-4RDW62CU.js +36 -0
- package/chunks/chunk-5IR2PWO6.js +211 -0
- package/chunks/chunk-6CM2SWSX.js +35 -0
- package/chunks/chunk-6EYBQHJS.js +33 -0
- package/chunks/chunk-6NYUQXJT.js +109 -0
- package/chunks/chunk-6NZCBAT4.js +19 -0
- package/chunks/chunk-6V23XMYE.js +982 -0
- package/chunks/chunk-73V5RDSG.js +13 -0
- package/chunks/chunk-7IGZP4TV.js +30 -0
- package/chunks/chunk-7QMAYGNV.js +25 -0
- package/chunks/chunk-7YW5HL6N.js +168 -0
- package/chunks/chunk-AFFLZUW5.js +33 -0
- package/chunks/chunk-AMS3FB24.js +85 -0
- package/chunks/chunk-AXMPRLPI.js +35 -0
- package/chunks/chunk-B6CSCX7J.js +278 -0
- package/chunks/chunk-BDHNULU7.js +211 -0
- package/chunks/chunk-BNB7LEMQ.js +35 -0
- package/chunks/chunk-CECF6UZV.js +29 -0
- package/chunks/chunk-DBAJ66BR.js +18 -0
- package/chunks/chunk-DGQLPQS2.js +33 -0
- package/chunks/chunk-DLLTITVO.js +33 -0
- package/chunks/chunk-DMDOCC72.js +18 -0
- package/chunks/{chunk-IFT6HLDW.js → chunk-DRH7Q4FL.js} +3 -6
- package/chunks/chunk-DRNK3RLE.js +64 -0
- package/chunks/chunk-EAY65ZP6.js +22 -0
- package/chunks/{chunk-4GDNHUCZ.js → chunk-ENMBK6H7.js} +2 -2
- package/chunks/chunk-F5YMP5WU.js +18 -0
- package/chunks/chunk-F7EVMWVG.js +27 -0
- package/chunks/chunk-F7XWUG2V.js +18 -0
- package/chunks/chunk-FCU6IHKD.js +15 -0
- package/chunks/chunk-FFOATPL4.js +211 -0
- package/chunks/chunk-FWHUASVA.js +22 -0
- package/chunks/chunk-GBMHGF7P.js +20 -0
- package/chunks/{chunk-GJOU3UAL.js → chunk-GDYVCEWA.js} +8 -6
- package/chunks/chunk-GNBIAWSY.js +278 -0
- package/chunks/chunk-GQSPY2CV.js +19 -0
- package/chunks/chunk-HDALT7XM.js +620 -0
- package/chunks/chunk-HENMQK5Y.js +647 -0
- package/chunks/chunk-HFEOHBYG.js +647 -0
- package/chunks/chunk-HGECIEKD.js +35 -0
- package/chunks/chunk-HUKHWFVL.js +19 -0
- package/chunks/chunk-IGD53YL5.js +870 -0
- package/chunks/chunk-ILEM73XB.js +981 -0
- package/chunks/{chunk-DMGR57KA.js → chunk-IPB3U2PD.js} +20 -18
- package/chunks/chunk-JY3QZ2YO.js +211 -0
- package/chunks/chunk-K3OQEJI3.js +33 -0
- package/chunks/chunk-KXBKJ3GS.js +642 -0
- package/chunks/chunk-L7SL3MND.js +35 -0
- package/chunks/chunk-LCFDDWJR.js +278 -0
- package/chunks/chunk-LGECI2WL.js +306 -0
- package/chunks/chunk-LGUEB5L5.js +211 -0
- package/chunks/chunk-LI6QDZCA.js +211 -0
- package/chunks/{chunk-ZMHKLIP2.js → chunk-LYMZZ4BB.js} +1 -1
- package/chunks/chunk-MDEDNPU5.js +38 -0
- package/chunks/chunk-MQHKEGP4.js +33 -0
- package/chunks/chunk-NF5ACCXZ.js +211 -0
- package/chunks/chunk-NK557MKV.js +35 -0
- package/chunks/chunk-NWMEWFTK.js +33 -0
- package/chunks/chunk-O5OTBN22.js +35 -0
- package/chunks/chunk-O7MDUYEF.js +211 -0
- package/chunks/{chunk-LI5KVXAJ.js → chunk-OO5SJJDW.js} +2 -5
- package/chunks/chunk-OWRQ3QBI.js +211 -0
- package/chunks/chunk-Q52UJOBC.js +18 -0
- package/chunks/chunk-QFEF4EET.js +211 -0
- package/chunks/chunk-QHSVCGLD.js +280 -0
- package/chunks/chunk-QO64L4KB.js +97 -0
- package/chunks/{chunk-WLL3FNVL.js → chunk-R6KCN6CK.js} +1 -1
- package/chunks/chunk-RHYLRLKT.js +211 -0
- package/chunks/chunk-RJ5E22H5.js +15 -0
- package/chunks/chunk-RLAZR3NL.js +8 -0
- package/chunks/chunk-RWUPHV54.js +25 -0
- package/chunks/chunk-S2757FI3.js +36 -0
- package/chunks/chunk-S42P73SC.js +30 -0
- package/chunks/chunk-S5XDYLJH.js +18 -0
- package/chunks/chunk-SCM6NACT.js +15 -0
- package/chunks/chunk-SH3Y2I5P.js +18 -0
- package/chunks/chunk-SMLKMOAX.js +18 -0
- package/chunks/chunk-TATRVKBS.js +211 -0
- package/chunks/chunk-UODQZRY2.js +620 -0
- package/chunks/chunk-UOULDS6J.js +33 -0
- package/chunks/chunk-UUDXUSI5.js +211 -0
- package/chunks/{chunk-GL23YDEH.js → chunk-UWAMSJ2X.js} +3 -6
- package/chunks/chunk-UZUXLD2Q.js +35 -0
- package/chunks/chunk-VA6HXRX4.js +211 -0
- package/chunks/chunk-VRUJR6WR.js +39 -0
- package/chunks/chunk-W6YBEEZM.js +211 -0
- package/chunks/chunk-WECTUHS5.js +127 -0
- package/chunks/chunk-YE5HI3RK.js +211 -0
- package/chunks/chunk-YEBOL67V.js +32 -0
- package/chunks/chunk-YS6WMSWC.js +15 -0
- package/{agnostic/misc/web-crawler/index.js → chunks/chunk-YUP434IY.js} +8 -7
- package/chunks/chunk-YYE2MVZO.js +211 -0
- package/chunks/chunk-Z7ZDDBV5.js +18 -0
- package/chunks/chunk-ZB73RE7P.js +35 -0
- package/chunks/chunk-ZONKYNKA.js +28 -0
- package/package.json +4 -1
- package/agnostic/async/index.d.ts +0 -8
- package/agnostic/async/index.js +0 -20
- package/agnostic/async/timeout-call/index.d.ts +0 -1
- package/agnostic/async/timeout-call/index.js +0 -6
- package/agnostic/async/transitions/index.js +0 -7
- package/agnostic/async/wait/index.js +0 -6
- package/agnostic/misc/random/index.js +0 -6
- package/chunks/chunk-4VC5PT5T.js +0 -13
- /package/agnostic/{misc/random → random}/index.d.ts +0 -0
- /package/agnostic/{async → time}/transitions/index.d.ts +0 -0
- /package/agnostic/{async → time}/wait/index.d.ts +0 -0
@@ -0,0 +1,620 @@
|
|
1
|
+
import {
|
2
|
+
toNull
|
3
|
+
} from "./chunk-RJ5E22H5.js";
|
4
|
+
import {
|
5
|
+
toRecord
|
6
|
+
} from "./chunk-F5YMP5WU.js";
|
7
|
+
import {
|
8
|
+
toString
|
9
|
+
} from "./chunk-DMDOCC72.js";
|
10
|
+
import {
|
11
|
+
toRef
|
12
|
+
} from "./chunk-4RDW62CU.js";
|
13
|
+
import {
|
14
|
+
toTransformer
|
15
|
+
} from "./chunk-SMLKMOAX.js";
|
16
|
+
import {
|
17
|
+
toText
|
18
|
+
} from "./chunk-3PHPA25U.js";
|
19
|
+
import {
|
20
|
+
replace
|
21
|
+
} from "./chunk-MDEDNPU5.js";
|
22
|
+
import {
|
23
|
+
querySelector
|
24
|
+
} from "./chunk-BNB7LEMQ.js";
|
25
|
+
import {
|
26
|
+
split
|
27
|
+
} from "./chunk-6CM2SWSX.js";
|
28
|
+
import {
|
29
|
+
toArray
|
30
|
+
} from "./chunk-Q52UJOBC.js";
|
31
|
+
import {
|
32
|
+
toBoolean
|
33
|
+
} from "./chunk-SH3Y2I5P.js";
|
34
|
+
import {
|
35
|
+
toElement
|
36
|
+
} from "./chunk-S5XDYLJH.js";
|
37
|
+
import {
|
38
|
+
toNumber
|
39
|
+
} from "./chunk-F7XWUG2V.js";
|
40
|
+
import {
|
41
|
+
toNodeList
|
42
|
+
} from "./chunk-DBAJ66BR.js";
|
43
|
+
import {
|
44
|
+
append
|
45
|
+
} from "./chunk-K3OQEJI3.js";
|
46
|
+
import {
|
47
|
+
classList
|
48
|
+
} from "./chunk-VRUJR6WR.js";
|
49
|
+
import {
|
50
|
+
join
|
51
|
+
} from "./chunk-RWUPHV54.js";
|
52
|
+
import {
|
53
|
+
print
|
54
|
+
} from "./chunk-2DMWYLFG.js";
|
55
|
+
import {
|
56
|
+
length
|
57
|
+
} from "./chunk-S42P73SC.js";
|
58
|
+
import {
|
59
|
+
push
|
60
|
+
} from "./chunk-FWHUASVA.js";
|
61
|
+
import {
|
62
|
+
ref
|
63
|
+
} from "./chunk-3X6RXJBR.js";
|
64
|
+
import {
|
65
|
+
Cast
|
66
|
+
} from "./chunk-QO64L4KB.js";
|
67
|
+
import {
|
68
|
+
Serialize
|
69
|
+
} from "./chunk-DRNK3RLE.js";
|
70
|
+
import {
|
71
|
+
Crossenv
|
72
|
+
} from "./chunk-3LVR6KZH.js";
|
73
|
+
import {
|
74
|
+
Types
|
75
|
+
} from "./chunk-7QMAYGNV.js";
|
76
|
+
import {
|
77
|
+
Utils
|
78
|
+
} from "./chunk-YEBOL67V.js";
|
79
|
+
import {
|
80
|
+
insertNode
|
81
|
+
} from "./chunk-XA4HVHJ4.js";
|
82
|
+
import {
|
83
|
+
replaceInElement
|
84
|
+
} from "./chunk-GBMHGF7P.js";
|
85
|
+
import {
|
86
|
+
isRecord
|
87
|
+
} from "./chunk-YDIBNEGA.js";
|
88
|
+
|
89
|
+
// src/agnostic/html/hyper-json/transformers/transformSelected/index.ts
|
90
|
+
var transformSelected = (callerTagName, ...args) => {
|
91
|
+
return Utils.toNamedTransformer(callerTagName, (currentValue, callerTree) => {
|
92
|
+
const { NodeList, Element, Text } = Crossenv.getWindow();
|
93
|
+
if (!(currentValue instanceof Element) && !(currentValue instanceof NodeList)) return Utils.makeTransformerError({
|
94
|
+
message: "Current value must be Element or NodeList",
|
95
|
+
input: currentValue
|
96
|
+
});
|
97
|
+
const [selector, ...transformerDescriptors] = args;
|
98
|
+
if (typeof selector !== "string" && !(selector instanceof Text)) return Utils.makeTransformerError({
|
99
|
+
message: "Selector argument must be string or text",
|
100
|
+
input: selector !== void 0 ? selector : "<undefined>"
|
101
|
+
});
|
102
|
+
if (transformerDescriptors.length === 0) return Utils.makeTransformerError("No transformer descriptor provided");
|
103
|
+
let transformers = [];
|
104
|
+
for (const descriptor of transformerDescriptors) {
|
105
|
+
const errorResponse = Utils.makeTransformerError({
|
106
|
+
message: "Transformer descriptors must be of shape { name: string, arguments: Value[] }",
|
107
|
+
input: descriptor
|
108
|
+
});
|
109
|
+
if (!isRecord(descriptor)) return errorResponse;
|
110
|
+
if (!("name" in descriptor) || typeof descriptor.name !== "string") return errorResponse;
|
111
|
+
if (!("arguments" in descriptor) || !Array.isArray(descriptor.arguments)) return errorResponse;
|
112
|
+
const { name, arguments: args2 } = descriptor;
|
113
|
+
const generator = callerTree.getGenerator(name);
|
114
|
+
if (generator === void 0) return Utils.makeTransformerError(`No transformer found under the name ${name}`);
|
115
|
+
transformers.push(generator(name, ...args2));
|
116
|
+
}
|
117
|
+
const elementInput = Cast.toElement(currentValue);
|
118
|
+
const strSelector = Cast.toString(selector);
|
119
|
+
const selected = Array.from(elementInput.querySelectorAll(strSelector));
|
120
|
+
const transformationErrors = [];
|
121
|
+
const transformed = selected.map((input) => {
|
122
|
+
const output = transformers.reduce((reduced, transformer, transformerPos) => {
|
123
|
+
const result = transformer(reduced, callerTree);
|
124
|
+
if (result.action === "REPLACE") return result.value;
|
125
|
+
else if (result.action === "MERGE") {
|
126
|
+
const merged = Tree.mergeValues(
|
127
|
+
reduced,
|
128
|
+
result.value,
|
129
|
+
transformerPos,
|
130
|
+
callerTree
|
131
|
+
);
|
132
|
+
return merged;
|
133
|
+
}
|
134
|
+
if (result.action === "ERROR") transformationErrors.push({
|
135
|
+
message: result.value,
|
136
|
+
transformerName: transformer.transformerName,
|
137
|
+
transformerPos,
|
138
|
+
transforming: reduced
|
139
|
+
});
|
140
|
+
return reduced;
|
141
|
+
}, input);
|
142
|
+
return { input, output };
|
143
|
+
});
|
144
|
+
if (transformationErrors.length !== 0) return Utils.makeTransformerError({
|
145
|
+
message: "Some nested transformers returned an error",
|
146
|
+
errors: transformationErrors
|
147
|
+
});
|
148
|
+
const nonElementTransformResult = transformed.find((item) => !(item.output instanceof Element));
|
149
|
+
if (nonElementTransformResult !== void 0) return Utils.makeTransformerError({
|
150
|
+
message: "Some transformations resulted in a non Element output",
|
151
|
+
inputElement: nonElementTransformResult.input,
|
152
|
+
outputValue: nonElementTransformResult.output
|
153
|
+
});
|
154
|
+
const transformMap = new Map(transformed.map((e) => [e.input, e.output]));
|
155
|
+
const elementOutput = replaceInElement(elementInput, transformMap);
|
156
|
+
return {
|
157
|
+
action: "REPLACE",
|
158
|
+
value: elementOutput
|
159
|
+
};
|
160
|
+
});
|
161
|
+
};
|
162
|
+
|
163
|
+
// src/agnostic/html/hyper-json/transformers/index.ts
|
164
|
+
var Transformers;
|
165
|
+
((Transformers2) => {
|
166
|
+
Transformers2.defaultGeneratorsMap = /* @__PURE__ */ new Map([
|
167
|
+
["append", append],
|
168
|
+
["classList", classList],
|
169
|
+
["join", join],
|
170
|
+
["length", length],
|
171
|
+
["print", print],
|
172
|
+
["push", push],
|
173
|
+
["querySelector", querySelector],
|
174
|
+
["ref", ref],
|
175
|
+
["replace", replace],
|
176
|
+
["split", split],
|
177
|
+
["toArray", toArray],
|
178
|
+
["toBoolean", toBoolean],
|
179
|
+
["toElement", toElement],
|
180
|
+
["toNodeList", toNodeList],
|
181
|
+
["toNull", toNull],
|
182
|
+
["toNumber", toNumber],
|
183
|
+
["toRecord", toRecord],
|
184
|
+
["toRef", toRef],
|
185
|
+
["toString", toString],
|
186
|
+
["toText", toText],
|
187
|
+
["toTransformer", toTransformer],
|
188
|
+
["transformSelected", transformSelected]
|
189
|
+
// ['trim', trim]
|
190
|
+
]);
|
191
|
+
})(Transformers || (Transformers = {}));
|
192
|
+
|
193
|
+
// src/agnostic/html/hyper-json/tree/index.ts
|
194
|
+
var getWindow = Crossenv.getWindow;
|
195
|
+
var isElement = (node) => node.nodeType === getWindow().Node.ELEMENT_NODE;
|
196
|
+
var isText = (node) => node.nodeType === getWindow().Node.TEXT_NODE;
|
197
|
+
var Tree;
|
198
|
+
((_Tree) => {
|
199
|
+
_Tree.defaultOptions = {
|
200
|
+
generatorsMap: Transformers.defaultGeneratorsMap,
|
201
|
+
keyAttribute: "_name",
|
202
|
+
actionAttribute: "_action"
|
203
|
+
};
|
204
|
+
function fillOptions(options) {
|
205
|
+
return {
|
206
|
+
..._Tree.defaultOptions,
|
207
|
+
...options
|
208
|
+
};
|
209
|
+
}
|
210
|
+
_Tree.fillOptions = fillOptions;
|
211
|
+
function mergeValues(currentValue, incomingValue, mergeKey, initiatorTree) {
|
212
|
+
const { Element, Text, NodeList, document: document2 } = getWindow();
|
213
|
+
if (typeof incomingValue === "function") {
|
214
|
+
const evaluated = incomingValue(currentValue, initiatorTree);
|
215
|
+
if (evaluated.action === null) return currentValue;
|
216
|
+
if (evaluated.action === "REPLACE") return evaluated.value;
|
217
|
+
if (evaluated.action === "ERROR") {
|
218
|
+
const errorMessage = `Tranformer error:
|
219
|
+
from: ${incomingValue.transformerName}
|
220
|
+
at: ${initiatorTree.pathString.slice(1)}/${mergeKey}
|
221
|
+
message:`;
|
222
|
+
console.warn(errorMessage, evaluated.value);
|
223
|
+
return currentValue;
|
224
|
+
}
|
225
|
+
return mergeValues(
|
226
|
+
currentValue,
|
227
|
+
evaluated.value,
|
228
|
+
mergeKey,
|
229
|
+
initiatorTree
|
230
|
+
);
|
231
|
+
}
|
232
|
+
if (Array.isArray(currentValue)) {
|
233
|
+
if (typeof mergeKey === "string") return currentValue;
|
234
|
+
return [...currentValue, incomingValue];
|
235
|
+
}
|
236
|
+
if (currentValue === null || typeof currentValue === "boolean" || typeof currentValue === "number" || typeof currentValue === "string" || typeof currentValue === "function" || currentValue instanceof Text || currentValue instanceof Element) {
|
237
|
+
if (incomingValue === null || typeof incomingValue === "boolean" || typeof incomingValue === "number" || typeof incomingValue === "string" || Array.isArray(incomingValue) || isRecord(incomingValue)) {
|
238
|
+
return incomingValue;
|
239
|
+
}
|
240
|
+
const frag = document2.createDocumentFragment();
|
241
|
+
if (currentValue instanceof Element || currentValue instanceof Text) frag.append(currentValue.cloneNode(true));
|
242
|
+
else frag.append(`${currentValue}`);
|
243
|
+
if (incomingValue instanceof Element || incomingValue instanceof Text) {
|
244
|
+
frag.append(incomingValue.cloneNode(true));
|
245
|
+
return frag.childNodes;
|
246
|
+
}
|
247
|
+
frag.append(...Array.from(incomingValue).map((e) => e.cloneNode(true)));
|
248
|
+
return frag.childNodes;
|
249
|
+
}
|
250
|
+
if (currentValue instanceof NodeList) {
|
251
|
+
if (incomingValue instanceof Element || incomingValue instanceof Text) {
|
252
|
+
const frag = document2.createDocumentFragment();
|
253
|
+
frag.append(...Array.from(currentValue).map((e) => e.cloneNode(true)), incomingValue);
|
254
|
+
return frag.childNodes;
|
255
|
+
}
|
256
|
+
if (incomingValue instanceof NodeList) {
|
257
|
+
const frag = document2.createDocumentFragment();
|
258
|
+
frag.append(
|
259
|
+
...Array.from(currentValue).map((e) => e.cloneNode(true)),
|
260
|
+
...Array.from(incomingValue).map((e) => e.cloneNode(true))
|
261
|
+
);
|
262
|
+
return frag.childNodes;
|
263
|
+
}
|
264
|
+
if (incomingValue === null || typeof incomingValue === "string" || typeof incomingValue === "number" || typeof incomingValue === "boolean") {
|
265
|
+
const frag = document2.createDocumentFragment();
|
266
|
+
frag.append(...Array.from(currentValue).map((e) => e.cloneNode(true)), `${incomingValue}`);
|
267
|
+
return frag.childNodes;
|
268
|
+
}
|
269
|
+
if (Array.isArray(incomingValue)) return [
|
270
|
+
...Array.from(currentValue),
|
271
|
+
...incomingValue
|
272
|
+
];
|
273
|
+
return { ...incomingValue };
|
274
|
+
}
|
275
|
+
if (typeof mergeKey === "number") return currentValue;
|
276
|
+
return {
|
277
|
+
...currentValue,
|
278
|
+
[mergeKey]: incomingValue
|
279
|
+
};
|
280
|
+
}
|
281
|
+
_Tree.mergeValues = mergeValues;
|
282
|
+
function mergeRootElements(...rootElements) {
|
283
|
+
const output = document.createElement("data");
|
284
|
+
rootElements.forEach((rootElement) => {
|
285
|
+
const nodes = [...Array.from(rootElement.cloneNode(true).childNodes)];
|
286
|
+
output.append(...nodes);
|
287
|
+
});
|
288
|
+
return output;
|
289
|
+
}
|
290
|
+
_Tree.mergeRootElements = mergeRootElements;
|
291
|
+
function reduceRootElement(rootElement, options) {
|
292
|
+
const { Element, Text, document: document2 } = getWindow();
|
293
|
+
const _options = fillOptions(options ?? {});
|
294
|
+
const { keyAttribute, actionAttribute } = _options;
|
295
|
+
const outputRootElement = rootElement.cloneNode();
|
296
|
+
let positionnedChildrenCount = 0;
|
297
|
+
const childrenMap = /* @__PURE__ */ new Map();
|
298
|
+
const children = Array.from(rootElement.childNodes).filter((e) => {
|
299
|
+
if (e instanceof Element) return true;
|
300
|
+
if (e instanceof Text) return true;
|
301
|
+
return false;
|
302
|
+
});
|
303
|
+
children.forEach((child) => {
|
304
|
+
if (child instanceof Text) {
|
305
|
+
childrenMap.set(positionnedChildrenCount, child);
|
306
|
+
outputRootElement.appendChild(child);
|
307
|
+
positionnedChildrenCount += 1;
|
308
|
+
return;
|
309
|
+
}
|
310
|
+
const foundKey = child.getAttribute(keyAttribute);
|
311
|
+
const actionType = child.getAttribute(actionAttribute);
|
312
|
+
const targetKey = foundKey ?? positionnedChildrenCount;
|
313
|
+
if (foundKey === null) {
|
314
|
+
positionnedChildrenCount += 1;
|
315
|
+
}
|
316
|
+
const existingElement = childrenMap.get(targetKey);
|
317
|
+
if (existingElement === void 0) {
|
318
|
+
childrenMap.set(targetKey, child);
|
319
|
+
outputRootElement.appendChild(child);
|
320
|
+
return;
|
321
|
+
}
|
322
|
+
if (actionType === Types.ReductionAction.APPEND || actionType === Types.ReductionAction.PREPEND) {
|
323
|
+
if (existingElement instanceof Text) {
|
324
|
+
if (child instanceof Text) {
|
325
|
+
const newTextNode = actionType === Types.ReductionAction.APPEND ? document2.createTextNode(`${existingElement.textContent}${child.textContent}`) : document2.createTextNode(`${child.textContent}${existingElement.textContent}`);
|
326
|
+
childrenMap.set(targetKey, newTextNode);
|
327
|
+
insertNode(newTextNode, "after", existingElement);
|
328
|
+
existingElement.remove();
|
329
|
+
return;
|
330
|
+
} else {
|
331
|
+
childrenMap.set(targetKey, child);
|
332
|
+
insertNode(child, "after", existingElement);
|
333
|
+
existingElement.remove();
|
334
|
+
return;
|
335
|
+
}
|
336
|
+
} else {
|
337
|
+
if (child instanceof Text) {
|
338
|
+
childrenMap.set(targetKey, child);
|
339
|
+
insertNode(child, "after", existingElement);
|
340
|
+
existingElement.remove();
|
341
|
+
} else {
|
342
|
+
if (actionType === Types.ReductionAction.APPEND) existingElement.append(...Array.from(child.childNodes));
|
343
|
+
else existingElement.prepend(...Array.from(child.childNodes));
|
344
|
+
}
|
345
|
+
}
|
346
|
+
}
|
347
|
+
insertNode(child, "after", existingElement);
|
348
|
+
existingElement.remove();
|
349
|
+
childrenMap.set(targetKey, child);
|
350
|
+
});
|
351
|
+
const outputChildren = Array.from(outputRootElement.childNodes);
|
352
|
+
outputChildren.forEach((outputChild) => {
|
353
|
+
if (outputChild instanceof Element) {
|
354
|
+
const reduced = reduceRootElement(outputChild);
|
355
|
+
insertNode(reduced, "after", outputChild);
|
356
|
+
outputChild.remove();
|
357
|
+
}
|
358
|
+
});
|
359
|
+
return outputRootElement;
|
360
|
+
}
|
361
|
+
_Tree.reduceRootElement = reduceRootElement;
|
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
|
+
};
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import {
|
2
|
+
Cast,
|
3
|
+
Transformers,
|
4
|
+
Tree
|
5
|
+
} from "./chunk-ILEM73XB.js";
|
6
|
+
import {
|
7
|
+
Serialize
|
8
|
+
} from "./chunk-DRNK3RLE.js";
|
9
|
+
import {
|
10
|
+
Crossenv
|
11
|
+
} from "./chunk-3LVR6KZH.js";
|
12
|
+
import {
|
13
|
+
Utils
|
14
|
+
} from "./chunk-F7EVMWVG.js";
|
15
|
+
import {
|
16
|
+
Types
|
17
|
+
} from "./chunk-7QMAYGNV.js";
|
18
|
+
|
19
|
+
// src/agnostic/html/hyper-json/index.ts
|
20
|
+
var HyperJson;
|
21
|
+
((HyperJson2) => {
|
22
|
+
HyperJson2.Cast = Cast;
|
23
|
+
HyperJson2.Crossenv = Crossenv;
|
24
|
+
HyperJson2.Serialize = Serialize;
|
25
|
+
HyperJson2.Transformers = Transformers;
|
26
|
+
HyperJson2.Tree = Tree;
|
27
|
+
HyperJson2.Types = Types;
|
28
|
+
HyperJson2.Utils = Utils;
|
29
|
+
})(HyperJson || (HyperJson = {}));
|
30
|
+
|
31
|
+
export {
|
32
|
+
HyperJson
|
33
|
+
};
|