lone-format 0.1.2 → 0.1.4
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.
- package/dist/index.d.ts +1 -3
- package/dist/lone-format.css +1 -1
- package/dist/lone-format.js +1668 -1159
- package/dist/lone-format.umd.cjs +8 -8
- package/package.json +4 -2
- package/dist/src/components/JsonFormat/JsonNode.vue.d.ts +0 -65
- package/dist/src/components/JsonFormat/index.vue.d.ts +0 -56
- package/dist/src/components/JsonFormat/types.d.ts +0 -36
- package/dist/src/components/index.d.ts +0 -2
- package/dist/src/index.d.ts +0 -6
package/dist/lone-format.js
CHANGED
|
@@ -1,895 +1,1333 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { defineComponent as ae, useCssVars as ue, ref as B, computed as j, resolveComponent as he, createElementBlock as w, openBlock as k, createElementVNode as P, createCommentVNode as N, withDirectives as te, toDisplayString as U, withKeys as X, vModelText as re, createTextVNode as ie, Fragment as de, renderList as fe, createVNode as le, normalizeClass as pe, nextTick as ee, watch as ye } from "vue";
|
|
2
|
+
class ge {
|
|
3
|
+
/**
|
|
4
|
+
* @callback HookCallback
|
|
5
|
+
* @this {*|Jsep} this
|
|
6
|
+
* @param {Jsep} env
|
|
7
|
+
* @returns: void
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Adds the given callback to the list of callbacks for the given hook.
|
|
11
|
+
*
|
|
12
|
+
* The callback will be invoked when the hook it is registered for is run.
|
|
13
|
+
*
|
|
14
|
+
* One callback function can be registered to multiple hooks and the same hook multiple times.
|
|
15
|
+
*
|
|
16
|
+
* @param {string|object} name The name of the hook, or an object of callbacks keyed by name
|
|
17
|
+
* @param {HookCallback|boolean} callback The callback function which is given environment variables.
|
|
18
|
+
* @param {?boolean} [first=false] Will add the hook to the top of the list (defaults to the bottom)
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
add(e, t, s) {
|
|
22
|
+
if (typeof arguments[0] != "string")
|
|
23
|
+
for (let n in arguments[0])
|
|
24
|
+
this.add(n, arguments[0][n], arguments[1]);
|
|
25
|
+
else
|
|
26
|
+
(Array.isArray(e) ? e : [e]).forEach(function(n) {
|
|
27
|
+
this[n] = this[n] || [], t && this[n][s ? "unshift" : "push"](t);
|
|
28
|
+
}, this);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Runs a hook invoking all registered callbacks with the given environment variables.
|
|
32
|
+
*
|
|
33
|
+
* Callbacks will be invoked synchronously and in the order in which they were registered.
|
|
34
|
+
*
|
|
35
|
+
* @param {string} name The name of the hook.
|
|
36
|
+
* @param {Object<string, any>} env The environment variables of the hook passed to all callbacks registered.
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
run(e, t) {
|
|
40
|
+
this[e] = this[e] || [], this[e].forEach(function(s) {
|
|
41
|
+
s.call(t && t.context ? t.context : t, t);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
4
44
|
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
return Q;
|
|
281
|
-
};
|
|
282
|
-
}();
|
|
283
|
-
function Oe(e, t, n, u) {
|
|
284
|
-
var i, s, f, r, o;
|
|
285
|
-
if (n == null ? n = p : x(n, 0, 8), !e.c) return e.toString();
|
|
286
|
-
if (i = e.c[0], f = e.e, t == null)
|
|
287
|
-
o = D(e.c), o = u == 1 || u == 2 && (f <= h || f >= U) ? b(o, f) : V(o, f, "0");
|
|
288
|
-
else if (e = ue(new v(e), t, n), s = e.e, o = D(e.c), r = o.length, u == 1 || u == 2 && (t <= s || s <= h)) {
|
|
289
|
-
for (; r < t; o += "0", r++) ;
|
|
290
|
-
o = b(o, s);
|
|
291
|
-
} else if (t -= f + (u === 2 && s > f), o = V(o, s, "0"), s + 1 > r) {
|
|
292
|
-
if (--t > 0) for (o += "."; t--; o += "0") ;
|
|
293
|
-
} else if (t += s - r, t > 0)
|
|
294
|
-
for (s + 1 == r && (o += "."); t--; o += "0") ;
|
|
295
|
-
return e.s < 0 && i ? "-" + o : o;
|
|
296
|
-
}
|
|
297
|
-
function $e(e, t) {
|
|
298
|
-
for (var n, u, i = 1, s = new v(e[0]); i < e.length; i++)
|
|
299
|
-
u = new v(e[i]), (!u.s || (n = W(s, u)) === t || n === 0 && s.s === t) && (s = u);
|
|
300
|
-
return s;
|
|
301
|
-
}
|
|
302
|
-
function xe(e, t, n) {
|
|
303
|
-
for (var u = 1, i = t.length; !t[--i]; t.pop()) ;
|
|
304
|
-
for (i = t[0]; i >= 10; i /= 10, u++) ;
|
|
305
|
-
return (n = u + n * w - 1) > H ? e.c = e.e = null : n < M ? e.c = [e.e = 0] : (e.e = n, e.c = t), e;
|
|
306
|
-
}
|
|
307
|
-
g = /* @__PURE__ */ function() {
|
|
308
|
-
var e = /^(-?)0([xbo])(?=\w[\w.]*$)/i, t = /^([^.]+)\.$/, n = /^\.([^.]+)$/, u = /^-?(Infinity|NaN)$/, i = /^\s*\+(?=[\w.])|^\s+|\s+$/g;
|
|
309
|
-
return function(s, f, r, o) {
|
|
310
|
-
var a, l = r ? f : f.replace(i, "");
|
|
311
|
-
if (u.test(l))
|
|
312
|
-
s.s = isNaN(l) ? null : l < 0 ? -1 : 1;
|
|
313
|
-
else {
|
|
314
|
-
if (!r && (l = l.replace(e, function(d, E, B) {
|
|
315
|
-
return a = (B = B.toLowerCase()) == "x" ? 16 : B == "b" ? 2 : 8, !o || o == a ? E : d;
|
|
316
|
-
}), o && (a = o, l = l.replace(t, "$1").replace(n, "0.$1")), f != l))
|
|
317
|
-
return new v(l, a);
|
|
318
|
-
if (v.DEBUG)
|
|
319
|
-
throw Error(C + "Not a" + (o ? " base " + o : "") + " number: " + f);
|
|
320
|
-
s.s = null;
|
|
321
|
-
}
|
|
322
|
-
s.c = s.e = null;
|
|
323
|
-
};
|
|
324
|
-
}();
|
|
325
|
-
function ue(e, t, n, u) {
|
|
326
|
-
var i, s, f, r, o, a, l, d = e.c, E = A;
|
|
327
|
-
if (d) {
|
|
328
|
-
e: {
|
|
329
|
-
for (i = 1, r = d[0]; r >= 10; r /= 10, i++) ;
|
|
330
|
-
if (s = t - i, s < 0)
|
|
331
|
-
s += w, f = t, o = d[a = 0], l = j(o / E[i - f - 1] % 10);
|
|
332
|
-
else if (a = O((s + 1) / w), a >= d.length)
|
|
333
|
-
if (u) {
|
|
334
|
-
for (; d.length <= a; d.push(0)) ;
|
|
335
|
-
o = l = 0, i = 1, s %= w, f = s - w + 1;
|
|
336
|
-
} else
|
|
337
|
-
break e;
|
|
338
|
-
else {
|
|
339
|
-
for (o = r = d[a], i = 1; r >= 10; r /= 10, i++) ;
|
|
340
|
-
s %= w, f = s - w + i, l = f < 0 ? 0 : j(o / E[i - f - 1] % 10);
|
|
341
|
-
}
|
|
342
|
-
if (u = u || t < 0 || // Are there any non-zero digits after the rounding digit?
|
|
343
|
-
// The expression n % pows10[d - j - 1] returns all digits of n to the right
|
|
344
|
-
// of the digit at j, e.g. if n is 908714 and j is 2, the expression gives 714.
|
|
345
|
-
d[a + 1] != null || (f < 0 ? o : o % E[i - f - 1]), u = n < 4 ? (l || u) && (n == 0 || n == (e.s < 0 ? 3 : 2)) : l > 5 || l == 5 && (n == 4 || u || n == 6 && // Check whether the digit to the left of the rounding digit is odd.
|
|
346
|
-
(s > 0 ? f > 0 ? o / E[i - f] : 0 : d[a - 1]) % 10 & 1 || n == (e.s < 0 ? 8 : 7)), t < 1 || !d[0])
|
|
347
|
-
return d.length = 0, u ? (t -= e.e + 1, d[0] = E[(w - t % w) % w], e.e = -t || 0) : d[0] = e.e = 0, e;
|
|
348
|
-
if (s == 0 ? (d.length = a, r = 1, a--) : (d.length = a + 1, r = E[w - s], d[a] = f > 0 ? j(o / E[i - f] % E[f]) * r : 0), u)
|
|
349
|
-
for (; ; )
|
|
350
|
-
if (a == 0) {
|
|
351
|
-
for (s = 1, f = d[0]; f >= 10; f /= 10, s++) ;
|
|
352
|
-
for (f = d[0] += r, r = 1; f >= 10; f /= 10, r++) ;
|
|
353
|
-
s != r && (e.e++, d[0] == T && (d[0] = 1));
|
|
354
|
-
break;
|
|
355
|
-
} else {
|
|
356
|
-
if (d[a] += r, d[a] != T) break;
|
|
357
|
-
d[a--] = 0, r = 1;
|
|
358
|
-
}
|
|
359
|
-
for (s = d.length; d[--s] === 0; d.pop()) ;
|
|
360
|
-
}
|
|
361
|
-
e.e > H ? e.c = e.e = null : e.e < M && (e.c = [e.e = 0]);
|
|
362
|
-
}
|
|
363
|
-
return e;
|
|
364
|
-
}
|
|
365
|
-
function de(e) {
|
|
366
|
-
var t, n = e.e;
|
|
367
|
-
return n === null ? e.toString() : (t = D(e.c), t = n <= h || n >= U ? b(t, n) : V(t, n, "0"), e.s < 0 ? "-" + t : t);
|
|
368
|
-
}
|
|
369
|
-
return c.absoluteValue = c.abs = function() {
|
|
370
|
-
var e = new v(this);
|
|
371
|
-
return e.s < 0 && (e.s = 1), e;
|
|
372
|
-
}, c.comparedTo = function(e, t) {
|
|
373
|
-
return W(this, new v(e, t));
|
|
374
|
-
}, c.decimalPlaces = c.dp = function(e, t) {
|
|
375
|
-
var n, u, i, s = this;
|
|
376
|
-
if (e != null)
|
|
377
|
-
return x(e, 0, $), t == null ? t = p : x(t, 0, 8), ue(new v(s), e + s.e + 1, t);
|
|
378
|
-
if (!(n = s.c)) return null;
|
|
379
|
-
if (u = ((i = n.length - 1) - X(this.e / w)) * w, i = n[i]) for (; i % 10 == 0; i /= 10, u--) ;
|
|
380
|
-
return u < 0 && (u = 0), u;
|
|
381
|
-
}, c.dividedBy = c.div = function(e, t) {
|
|
382
|
-
return k(this, new v(e, t), m, p);
|
|
383
|
-
}, c.dividedToIntegerBy = c.idiv = function(e, t) {
|
|
384
|
-
return k(this, new v(e, t), 0, 1);
|
|
385
|
-
}, c.exponentiatedBy = c.pow = function(e, t) {
|
|
386
|
-
var n, u, i, s, f, r, o, a, l, d = this;
|
|
387
|
-
if (e = new v(e), e.c && !e.isInteger())
|
|
388
|
-
throw Error(C + "Exponent not an integer: " + de(e));
|
|
389
|
-
if (t != null && (t = new v(t)), r = e.e > 14, !d.c || !d.c[0] || d.c[0] == 1 && !d.e && d.c.length == 1 || !e.c || !e.c[0])
|
|
390
|
-
return l = new v(Math.pow(+de(d), r ? e.s * (2 - I(e)) : +de(e))), t ? l.mod(t) : l;
|
|
391
|
-
if (o = e.s < 0, t) {
|
|
392
|
-
if (t.c ? !t.c[0] : !t.s) return new v(NaN);
|
|
393
|
-
u = !o && d.isInteger() && t.isInteger(), u && (d = d.mod(t));
|
|
394
|
-
} else {
|
|
395
|
-
if (e.e > 9 && (d.e > 0 || d.e < -1 || (d.e == 0 ? d.c[0] > 1 || r && d.c[1] >= 24e7 : d.c[0] < 8e13 || r && d.c[0] <= 9999975e7)))
|
|
396
|
-
return s = d.s < 0 && I(e) ? -0 : 0, d.e > -1 && (s = 1 / s), new v(o ? 1 / s : s);
|
|
397
|
-
ge && (s = O(ge / w + 2));
|
|
398
|
-
}
|
|
399
|
-
for (r ? (n = new v(0.5), o && (e.s = 1), a = I(e)) : (i = Math.abs(+de(e)), a = i % 2), l = new v(_); ; ) {
|
|
400
|
-
if (a) {
|
|
401
|
-
if (l = l.times(d), !l.c) break;
|
|
402
|
-
s ? l.c.length > s && (l.c.length = s) : u && (l = l.mod(t));
|
|
403
|
-
}
|
|
404
|
-
if (i) {
|
|
405
|
-
if (i = j(i / 2), i === 0) break;
|
|
406
|
-
a = i % 2;
|
|
407
|
-
} else if (e = e.times(n), ue(e, e.e + 1, 1), e.e > 14)
|
|
408
|
-
a = I(e);
|
|
409
|
-
else {
|
|
410
|
-
if (i = +de(e), i === 0) break;
|
|
411
|
-
a = i % 2;
|
|
412
|
-
}
|
|
413
|
-
d = d.times(d), s ? d.c && d.c.length > s && (d.c.length = s) : u && (d = d.mod(t));
|
|
414
|
-
}
|
|
415
|
-
return u ? l : (o && (l = _.div(l)), t ? l.mod(t) : s ? ue(l, ge, p, f) : l);
|
|
416
|
-
}, c.integerValue = function(e) {
|
|
417
|
-
var t = new v(this);
|
|
418
|
-
return e == null ? e = p : x(e, 0, 8), ue(t, t.e + 1, e);
|
|
419
|
-
}, c.isEqualTo = c.eq = function(e, t) {
|
|
420
|
-
return W(this, new v(e, t)) === 0;
|
|
421
|
-
}, c.isFinite = function() {
|
|
422
|
-
return !!this.c;
|
|
423
|
-
}, c.isGreaterThan = c.gt = function(e, t) {
|
|
424
|
-
return W(this, new v(e, t)) > 0;
|
|
425
|
-
}, c.isGreaterThanOrEqualTo = c.gte = function(e, t) {
|
|
426
|
-
return (t = W(this, new v(e, t))) === 1 || t === 0;
|
|
427
|
-
}, c.isInteger = function() {
|
|
428
|
-
return !!this.c && X(this.e / w) > this.c.length - 2;
|
|
429
|
-
}, c.isLessThan = c.lt = function(e, t) {
|
|
430
|
-
return W(this, new v(e, t)) < 0;
|
|
431
|
-
}, c.isLessThanOrEqualTo = c.lte = function(e, t) {
|
|
432
|
-
return (t = W(this, new v(e, t))) === -1 || t === 0;
|
|
433
|
-
}, c.isNaN = function() {
|
|
434
|
-
return !this.s;
|
|
435
|
-
}, c.isNegative = function() {
|
|
436
|
-
return this.s < 0;
|
|
437
|
-
}, c.isPositive = function() {
|
|
438
|
-
return this.s > 0;
|
|
439
|
-
}, c.isZero = function() {
|
|
440
|
-
return !!this.c && this.c[0] == 0;
|
|
441
|
-
}, c.minus = function(e, t) {
|
|
442
|
-
var n, u, i, s, f = this, r = f.s;
|
|
443
|
-
if (e = new v(e, t), t = e.s, !r || !t) return new v(NaN);
|
|
444
|
-
if (r != t)
|
|
445
|
-
return e.s = -t, f.plus(e);
|
|
446
|
-
var o = f.e / w, a = e.e / w, l = f.c, d = e.c;
|
|
447
|
-
if (!o || !a) {
|
|
448
|
-
if (!l || !d) return l ? (e.s = -t, e) : new v(d ? f : NaN);
|
|
449
|
-
if (!l[0] || !d[0])
|
|
450
|
-
return d[0] ? (e.s = -t, e) : new v(l[0] ? f : (
|
|
451
|
-
// IEEE 754 (2008) 6.3: n - n = -0 when rounding to -Infinity
|
|
452
|
-
p == 3 ? -0 : 0
|
|
453
|
-
));
|
|
454
|
-
}
|
|
455
|
-
if (o = X(o), a = X(a), l = l.slice(), r = o - a) {
|
|
456
|
-
for ((s = r < 0) ? (r = -r, i = l) : (a = o, i = d), i.reverse(), t = r; t--; i.push(0)) ;
|
|
457
|
-
i.reverse();
|
|
458
|
-
} else
|
|
459
|
-
for (u = (s = (r = l.length) < (t = d.length)) ? r : t, r = t = 0; t < u; t++)
|
|
460
|
-
if (l[t] != d[t]) {
|
|
461
|
-
s = l[t] < d[t];
|
|
462
|
-
break;
|
|
463
|
-
}
|
|
464
|
-
if (s && (i = l, l = d, d = i, e.s = -e.s), t = (u = d.length) - (n = l.length), t > 0) for (; t--; l[n++] = 0) ;
|
|
465
|
-
for (t = T - 1; u > r; ) {
|
|
466
|
-
if (l[--u] < d[u]) {
|
|
467
|
-
for (n = u; n && !l[--n]; l[n] = t) ;
|
|
468
|
-
--l[n], l[u] += T;
|
|
469
|
-
}
|
|
470
|
-
l[u] -= d[u];
|
|
471
|
-
}
|
|
472
|
-
for (; l[0] == 0; l.splice(0, 1), --a) ;
|
|
473
|
-
return l[0] ? xe(e, l, a) : (e.s = p == 3 ? -1 : 1, e.c = [e.e = 0], e);
|
|
474
|
-
}, c.modulo = c.mod = function(e, t) {
|
|
475
|
-
var n, u, i = this;
|
|
476
|
-
return e = new v(e, t), !i.c || !e.s || e.c && !e.c[0] ? new v(NaN) : !e.c || i.c && !i.c[0] ? new v(i) : (pe == 9 ? (u = e.s, e.s = 1, n = k(i, e, 0, 3), e.s = u, n.s *= u) : n = k(i, e, 0, pe), e = i.minus(n.times(e)), !e.c[0] && pe == 1 && (e.s = i.s), e);
|
|
477
|
-
}, c.multipliedBy = c.times = function(e, t) {
|
|
478
|
-
var n, u, i, s, f, r, o, a, l, d, E, B, R, Q, te, F = this, q = F.c, re = (e = new v(e, t)).c;
|
|
479
|
-
if (!q || !re || !q[0] || !re[0])
|
|
480
|
-
return !F.s || !e.s || q && !q[0] && !re || re && !re[0] && !q ? e.c = e.e = e.s = null : (e.s *= F.s, !q || !re ? e.c = e.e = null : (e.c = [0], e.e = 0)), e;
|
|
481
|
-
for (u = X(F.e / w) + X(e.e / w), e.s *= F.s, o = q.length, d = re.length, o < d && (R = q, q = re, re = R, i = o, o = d, d = i), i = o + d, R = []; i--; R.push(0)) ;
|
|
482
|
-
for (Q = T, te = P, i = d; --i >= 0; ) {
|
|
483
|
-
for (n = 0, E = re[i] % te, B = re[i] / te | 0, f = o, s = i + f; s > i; )
|
|
484
|
-
a = q[--f] % te, l = q[f] / te | 0, r = B * a + l * E, a = E * a + r % te * te + R[s] + n, n = (a / Q | 0) + (r / te | 0) + B * l, R[s--] = a % Q;
|
|
485
|
-
R[s] = n;
|
|
486
|
-
}
|
|
487
|
-
return n ? ++u : R.splice(0, 1), xe(e, R, u);
|
|
488
|
-
}, c.negated = function() {
|
|
489
|
-
var e = new v(this);
|
|
490
|
-
return e.s = -e.s || null, e;
|
|
491
|
-
}, c.plus = function(e, t) {
|
|
492
|
-
var n, u = this, i = u.s;
|
|
493
|
-
if (e = new v(e, t), t = e.s, !i || !t) return new v(NaN);
|
|
494
|
-
if (i != t)
|
|
495
|
-
return e.s = -t, u.minus(e);
|
|
496
|
-
var s = u.e / w, f = e.e / w, r = u.c, o = e.c;
|
|
497
|
-
if (!s || !f) {
|
|
498
|
-
if (!r || !o) return new v(i / 0);
|
|
499
|
-
if (!r[0] || !o[0]) return o[0] ? e : new v(r[0] ? u : i * 0);
|
|
500
|
-
}
|
|
501
|
-
if (s = X(s), f = X(f), r = r.slice(), i = s - f) {
|
|
502
|
-
for (i > 0 ? (f = s, n = o) : (i = -i, n = r), n.reverse(); i--; n.push(0)) ;
|
|
503
|
-
n.reverse();
|
|
504
|
-
}
|
|
505
|
-
for (i = r.length, t = o.length, i - t < 0 && (n = o, o = r, r = n, t = i), i = 0; t; )
|
|
506
|
-
i = (r[--t] = r[t] + o[t] + i) / T | 0, r[t] = T === r[t] ? 0 : r[t] % T;
|
|
507
|
-
return i && (r = [i].concat(r), ++f), xe(e, r, f);
|
|
508
|
-
}, c.precision = c.sd = function(e, t) {
|
|
509
|
-
var n, u, i, s = this;
|
|
510
|
-
if (e != null && e !== !!e)
|
|
511
|
-
return x(e, 1, $), t == null ? t = p : x(t, 0, 8), ue(new v(s), e, t);
|
|
512
|
-
if (!(n = s.c)) return null;
|
|
513
|
-
if (i = n.length - 1, u = i * w + 1, i = n[i]) {
|
|
514
|
-
for (; i % 10 == 0; i /= 10, u--) ;
|
|
515
|
-
for (i = n[0]; i >= 10; i /= 10, u++) ;
|
|
516
|
-
}
|
|
517
|
-
return e && s.e + 1 > u && (u = s.e + 1), u;
|
|
518
|
-
}, c.shiftedBy = function(e) {
|
|
519
|
-
return x(e, -J, J), this.times("1e" + e);
|
|
520
|
-
}, c.squareRoot = c.sqrt = function() {
|
|
521
|
-
var e, t, n, u, i, s = this, f = s.c, r = s.s, o = s.e, a = m + 4, l = new v("0.5");
|
|
522
|
-
if (r !== 1 || !f || !f[0])
|
|
523
|
-
return new v(!r || r < 0 && (!f || f[0]) ? NaN : f ? s : 1 / 0);
|
|
524
|
-
if (r = Math.sqrt(+de(s)), r == 0 || r == 1 / 0 ? (t = D(f), (t.length + o) % 2 == 0 && (t += "0"), r = Math.sqrt(+t), o = X((o + 1) / 2) - (o < 0 || o % 2), r == 1 / 0 ? t = "5e" + o : (t = r.toExponential(), t = t.slice(0, t.indexOf("e") + 1) + o), n = new v(t)) : n = new v(r + ""), n.c[0]) {
|
|
525
|
-
for (o = n.e, r = o + a, r < 3 && (r = 0); ; )
|
|
526
|
-
if (i = n, n = l.times(i.plus(k(s, i, a, 1))), D(i.c).slice(0, r) === (t = D(n.c)).slice(0, r))
|
|
527
|
-
if (n.e < o && --r, t = t.slice(r - 3, r + 1), t == "9999" || !u && t == "4999") {
|
|
528
|
-
if (!u && (ue(i, i.e + m + 2, 0), i.times(i).eq(s))) {
|
|
529
|
-
n = i;
|
|
530
|
-
break;
|
|
531
|
-
}
|
|
532
|
-
a += 4, r += 4, u = 1;
|
|
533
|
-
} else {
|
|
534
|
-
(!+t || !+t.slice(1) && t.charAt(0) == "5") && (ue(n, n.e + m + 2, 1), e = !n.times(n).eq(s));
|
|
535
|
-
break;
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
return ue(n, n.e + m + 1, p, e);
|
|
539
|
-
}, c.toExponential = function(e, t) {
|
|
540
|
-
return e != null && (x(e, 0, $), e++), Oe(this, e, t, 1);
|
|
541
|
-
}, c.toFixed = function(e, t) {
|
|
542
|
-
return e != null && (x(e, 0, $), e = e + this.e + 1), Oe(this, e, t);
|
|
543
|
-
}, c.toFormat = function(e, t, n) {
|
|
544
|
-
var u, i = this;
|
|
545
|
-
if (n == null)
|
|
546
|
-
e != null && t && typeof t == "object" ? (n = t, t = null) : e && typeof e == "object" ? (n = e, e = t = null) : n = ke;
|
|
547
|
-
else if (typeof n != "object")
|
|
548
|
-
throw Error(C + "Argument not an object: " + n);
|
|
549
|
-
if (u = i.toFixed(e, t), i.c) {
|
|
550
|
-
var s, f = u.split("."), r = +n.groupSize, o = +n.secondaryGroupSize, a = n.groupSeparator || "", l = f[0], d = f[1], E = i.s < 0, B = E ? l.slice(1) : l, R = B.length;
|
|
551
|
-
if (o && (s = r, r = o, o = s, R -= s), r > 0 && R > 0) {
|
|
552
|
-
for (s = R % r || r, l = B.substr(0, s); s < R; s += r) l += a + B.substr(s, r);
|
|
553
|
-
o > 0 && (l += a + B.slice(s)), E && (l = "-" + l);
|
|
554
|
-
}
|
|
555
|
-
u = d ? l + (n.decimalSeparator || "") + ((o = +n.fractionGroupSize) ? d.replace(
|
|
556
|
-
new RegExp("\\d{" + o + "}\\B", "g"),
|
|
557
|
-
"$&" + (n.fractionGroupSeparator || "")
|
|
558
|
-
) : d) : l;
|
|
559
|
-
}
|
|
560
|
-
return (n.prefix || "") + u + (n.suffix || "");
|
|
561
|
-
}, c.toFraction = function(e) {
|
|
562
|
-
var t, n, u, i, s, f, r, o, a, l, d, E, B = this, R = B.c;
|
|
563
|
-
if (e != null && (r = new v(e), !r.isInteger() && (r.c || r.s !== 1) || r.lt(_)))
|
|
564
|
-
throw Error(C + "Argument " + (r.isInteger() ? "out of range: " : "not an integer: ") + de(r));
|
|
565
|
-
if (!R) return new v(B);
|
|
566
|
-
for (t = new v(_), a = n = new v(_), u = o = new v(_), E = D(R), s = t.e = E.length - B.e - 1, t.c[0] = A[(f = s % w) < 0 ? w + f : f], e = !e || r.comparedTo(t) > 0 ? s > 0 ? t : a : r, f = H, H = 1 / 0, r = new v(E), o.c[0] = 0; l = k(r, t, 0, 1), i = n.plus(l.times(u)), i.comparedTo(e) != 1; )
|
|
567
|
-
n = u, u = i, a = o.plus(l.times(i = a)), o = i, t = r.minus(l.times(i = t)), r = i;
|
|
568
|
-
return i = k(e.minus(n), u, 0, 1), o = o.plus(i.times(a)), n = n.plus(i.times(u)), o.s = a.s = B.s, s = s * 2, d = k(a, u, s, p).minus(B).abs().comparedTo(
|
|
569
|
-
k(o, n, s, p).minus(B).abs()
|
|
570
|
-
) < 1 ? [a, u] : [o, n], H = f, d;
|
|
571
|
-
}, c.toNumber = function() {
|
|
572
|
-
return +de(this);
|
|
573
|
-
}, c.toPrecision = function(e, t) {
|
|
574
|
-
return e != null && x(e, 1, $), Oe(this, e, t, 2);
|
|
575
|
-
}, c.toString = function(e) {
|
|
576
|
-
var t, n = this, u = n.s, i = n.e;
|
|
577
|
-
return i === null ? u ? (t = "Infinity", u < 0 && (t = "-" + t)) : t = "NaN" : (e == null ? t = i <= h || i >= U ? b(D(n.c), i) : V(D(n.c), i, "0") : e === 10 && Ee ? (n = ue(new v(n), m + i + 1, p), t = V(D(n.c), n.e, "0")) : (x(e, 2, ve.length, "Base"), t = L(V(D(n.c), i, "0"), 10, e, u, !0)), u < 0 && n.c[0] && (t = "-" + t)), t;
|
|
578
|
-
}, c.valueOf = c.toJSON = function() {
|
|
579
|
-
return de(this);
|
|
580
|
-
}, c._isBigNumber = !0, S != null && v.set(S), v;
|
|
45
|
+
class Ee {
|
|
46
|
+
constructor(e) {
|
|
47
|
+
this.jsep = e, this.registered = {};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* @callback PluginSetup
|
|
51
|
+
* @this {Jsep} jsep
|
|
52
|
+
* @returns: void
|
|
53
|
+
*/
|
|
54
|
+
/**
|
|
55
|
+
* Adds the given plugin(s) to the registry
|
|
56
|
+
*
|
|
57
|
+
* @param {object} plugins
|
|
58
|
+
* @param {string} plugins.name The name of the plugin
|
|
59
|
+
* @param {PluginSetup} plugins.init The init function
|
|
60
|
+
* @public
|
|
61
|
+
*/
|
|
62
|
+
register() {
|
|
63
|
+
for (var e = arguments.length, t = new Array(e), s = 0; s < e; s++)
|
|
64
|
+
t[s] = arguments[s];
|
|
65
|
+
t.forEach((n) => {
|
|
66
|
+
if (typeof n != "object" || !n.name || !n.init)
|
|
67
|
+
throw new Error("Invalid JSEP plugin format");
|
|
68
|
+
this.registered[n.name] || (n.init(this.jsep), this.registered[n.name] = n);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
class i {
|
|
73
|
+
/**
|
|
74
|
+
* @returns {string}
|
|
75
|
+
*/
|
|
76
|
+
static get version() {
|
|
77
|
+
return "1.4.0";
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* @returns {string}
|
|
81
|
+
*/
|
|
82
|
+
static toString() {
|
|
83
|
+
return "JavaScript Expression Parser (JSEP) v" + i.version;
|
|
84
|
+
}
|
|
85
|
+
// ==================== CONFIG ================================
|
|
86
|
+
/**
|
|
87
|
+
* @method addUnaryOp
|
|
88
|
+
* @param {string} op_name The name of the unary op to add
|
|
89
|
+
* @returns {Jsep}
|
|
90
|
+
*/
|
|
91
|
+
static addUnaryOp(e) {
|
|
92
|
+
return i.max_unop_len = Math.max(e.length, i.max_unop_len), i.unary_ops[e] = 1, i;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* @method jsep.addBinaryOp
|
|
96
|
+
* @param {string} op_name The name of the binary op to add
|
|
97
|
+
* @param {number} precedence The precedence of the binary op (can be a float). Higher number = higher precedence
|
|
98
|
+
* @param {boolean} [isRightAssociative=false] whether operator is right-associative
|
|
99
|
+
* @returns {Jsep}
|
|
100
|
+
*/
|
|
101
|
+
static addBinaryOp(e, t, s) {
|
|
102
|
+
return i.max_binop_len = Math.max(e.length, i.max_binop_len), i.binary_ops[e] = t, s ? i.right_associative.add(e) : i.right_associative.delete(e), i;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* @method addIdentifierChar
|
|
106
|
+
* @param {string} char The additional character to treat as a valid part of an identifier
|
|
107
|
+
* @returns {Jsep}
|
|
108
|
+
*/
|
|
109
|
+
static addIdentifierChar(e) {
|
|
110
|
+
return i.additional_identifier_chars.add(e), i;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* @method addLiteral
|
|
114
|
+
* @param {string} literal_name The name of the literal to add
|
|
115
|
+
* @param {*} literal_value The value of the literal
|
|
116
|
+
* @returns {Jsep}
|
|
117
|
+
*/
|
|
118
|
+
static addLiteral(e, t) {
|
|
119
|
+
return i.literals[e] = t, i;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* @method removeUnaryOp
|
|
123
|
+
* @param {string} op_name The name of the unary op to remove
|
|
124
|
+
* @returns {Jsep}
|
|
125
|
+
*/
|
|
126
|
+
static removeUnaryOp(e) {
|
|
127
|
+
return delete i.unary_ops[e], e.length === i.max_unop_len && (i.max_unop_len = i.getMaxKeyLen(i.unary_ops)), i;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* @method removeAllUnaryOps
|
|
131
|
+
* @returns {Jsep}
|
|
132
|
+
*/
|
|
133
|
+
static removeAllUnaryOps() {
|
|
134
|
+
return i.unary_ops = {}, i.max_unop_len = 0, i;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* @method removeIdentifierChar
|
|
138
|
+
* @param {string} char The additional character to stop treating as a valid part of an identifier
|
|
139
|
+
* @returns {Jsep}
|
|
140
|
+
*/
|
|
141
|
+
static removeIdentifierChar(e) {
|
|
142
|
+
return i.additional_identifier_chars.delete(e), i;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* @method removeBinaryOp
|
|
146
|
+
* @param {string} op_name The name of the binary op to remove
|
|
147
|
+
* @returns {Jsep}
|
|
148
|
+
*/
|
|
149
|
+
static removeBinaryOp(e) {
|
|
150
|
+
return delete i.binary_ops[e], e.length === i.max_binop_len && (i.max_binop_len = i.getMaxKeyLen(i.binary_ops)), i.right_associative.delete(e), i;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* @method removeAllBinaryOps
|
|
154
|
+
* @returns {Jsep}
|
|
155
|
+
*/
|
|
156
|
+
static removeAllBinaryOps() {
|
|
157
|
+
return i.binary_ops = {}, i.max_binop_len = 0, i;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* @method removeLiteral
|
|
161
|
+
* @param {string} literal_name The name of the literal to remove
|
|
162
|
+
* @returns {Jsep}
|
|
163
|
+
*/
|
|
164
|
+
static removeLiteral(e) {
|
|
165
|
+
return delete i.literals[e], i;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* @method removeAllLiterals
|
|
169
|
+
* @returns {Jsep}
|
|
170
|
+
*/
|
|
171
|
+
static removeAllLiterals() {
|
|
172
|
+
return i.literals = {}, i;
|
|
173
|
+
}
|
|
174
|
+
// ==================== END CONFIG ============================
|
|
175
|
+
/**
|
|
176
|
+
* @returns {string}
|
|
177
|
+
*/
|
|
178
|
+
get char() {
|
|
179
|
+
return this.expr.charAt(this.index);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* @returns {number}
|
|
183
|
+
*/
|
|
184
|
+
get code() {
|
|
185
|
+
return this.expr.charCodeAt(this.index);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* @param {string} expr a string with the passed in express
|
|
189
|
+
* @returns Jsep
|
|
190
|
+
*/
|
|
191
|
+
constructor(e) {
|
|
192
|
+
this.expr = e, this.index = 0;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* static top-level parser
|
|
196
|
+
* @returns {jsep.Expression}
|
|
197
|
+
*/
|
|
198
|
+
static parse(e) {
|
|
199
|
+
return new i(e).parse();
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Get the longest key length of any object
|
|
203
|
+
* @param {object} obj
|
|
204
|
+
* @returns {number}
|
|
205
|
+
*/
|
|
206
|
+
static getMaxKeyLen(e) {
|
|
207
|
+
return Math.max(0, ...Object.keys(e).map((t) => t.length));
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* `ch` is a character code in the next three functions
|
|
211
|
+
* @param {number} ch
|
|
212
|
+
* @returns {boolean}
|
|
213
|
+
*/
|
|
214
|
+
static isDecimalDigit(e) {
|
|
215
|
+
return e >= 48 && e <= 57;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Returns the precedence of a binary operator or `0` if it isn't a binary operator. Can be float.
|
|
219
|
+
* @param {string} op_val
|
|
220
|
+
* @returns {number}
|
|
221
|
+
*/
|
|
222
|
+
static binaryPrecedence(e) {
|
|
223
|
+
return i.binary_ops[e] || 0;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Looks for start of identifier
|
|
227
|
+
* @param {number} ch
|
|
228
|
+
* @returns {boolean}
|
|
229
|
+
*/
|
|
230
|
+
static isIdentifierStart(e) {
|
|
231
|
+
return e >= 65 && e <= 90 || // A...Z
|
|
232
|
+
e >= 97 && e <= 122 || // a...z
|
|
233
|
+
e >= 128 && !i.binary_ops[String.fromCharCode(e)] || // any non-ASCII that is not an operator
|
|
234
|
+
i.additional_identifier_chars.has(String.fromCharCode(e));
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* @param {number} ch
|
|
238
|
+
* @returns {boolean}
|
|
239
|
+
*/
|
|
240
|
+
static isIdentifierPart(e) {
|
|
241
|
+
return i.isIdentifierStart(e) || i.isDecimalDigit(e);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* throw error at index of the expression
|
|
245
|
+
* @param {string} message
|
|
246
|
+
* @throws
|
|
247
|
+
*/
|
|
248
|
+
throwError(e) {
|
|
249
|
+
const t = new Error(e + " at character " + this.index);
|
|
250
|
+
throw t.index = this.index, t.description = e, t;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Run a given hook
|
|
254
|
+
* @param {string} name
|
|
255
|
+
* @param {jsep.Expression|false} [node]
|
|
256
|
+
* @returns {?jsep.Expression}
|
|
257
|
+
*/
|
|
258
|
+
runHook(e, t) {
|
|
259
|
+
if (i.hooks[e]) {
|
|
260
|
+
const s = {
|
|
261
|
+
context: this,
|
|
262
|
+
node: t
|
|
263
|
+
};
|
|
264
|
+
return i.hooks.run(e, s), s.node;
|
|
265
|
+
}
|
|
266
|
+
return t;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Runs a given hook until one returns a node
|
|
270
|
+
* @param {string} name
|
|
271
|
+
* @returns {?jsep.Expression}
|
|
272
|
+
*/
|
|
273
|
+
searchHook(e) {
|
|
274
|
+
if (i.hooks[e]) {
|
|
275
|
+
const t = {
|
|
276
|
+
context: this
|
|
277
|
+
};
|
|
278
|
+
return i.hooks[e].find(function(s) {
|
|
279
|
+
return s.call(t.context, t), t.node;
|
|
280
|
+
}), t.node;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Push `index` up to the next non-space character
|
|
285
|
+
*/
|
|
286
|
+
gobbleSpaces() {
|
|
287
|
+
let e = this.code;
|
|
288
|
+
for (; e === i.SPACE_CODE || e === i.TAB_CODE || e === i.LF_CODE || e === i.CR_CODE; )
|
|
289
|
+
e = this.expr.charCodeAt(++this.index);
|
|
290
|
+
this.runHook("gobble-spaces");
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Top-level method to parse all expressions and returns compound or single node
|
|
294
|
+
* @returns {jsep.Expression}
|
|
295
|
+
*/
|
|
296
|
+
parse() {
|
|
297
|
+
this.runHook("before-all");
|
|
298
|
+
const e = this.gobbleExpressions(), t = e.length === 1 ? e[0] : {
|
|
299
|
+
type: i.COMPOUND,
|
|
300
|
+
body: e
|
|
301
|
+
};
|
|
302
|
+
return this.runHook("after-all", t);
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* top-level parser (but can be reused within as well)
|
|
306
|
+
* @param {number} [untilICode]
|
|
307
|
+
* @returns {jsep.Expression[]}
|
|
308
|
+
*/
|
|
309
|
+
gobbleExpressions(e) {
|
|
310
|
+
let t = [], s, n;
|
|
311
|
+
for (; this.index < this.expr.length; )
|
|
312
|
+
if (s = this.code, s === i.SEMCOL_CODE || s === i.COMMA_CODE)
|
|
313
|
+
this.index++;
|
|
314
|
+
else if (n = this.gobbleExpression())
|
|
315
|
+
t.push(n);
|
|
316
|
+
else if (this.index < this.expr.length) {
|
|
317
|
+
if (s === e)
|
|
318
|
+
break;
|
|
319
|
+
this.throwError('Unexpected "' + this.char + '"');
|
|
581
320
|
}
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
321
|
+
return t;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* The main parsing function.
|
|
325
|
+
* @returns {?jsep.Expression}
|
|
326
|
+
*/
|
|
327
|
+
gobbleExpression() {
|
|
328
|
+
const e = this.searchHook("gobble-expression") || this.gobbleBinaryExpression();
|
|
329
|
+
return this.gobbleSpaces(), this.runHook("after-expression", e);
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Search for the operation portion of the string (e.g. `+`, `===`)
|
|
333
|
+
* Start by taking the longest possible binary operations (3 characters: `===`, `!==`, `>>>`)
|
|
334
|
+
* and move down from 3 to 2 to 1 character until a matching binary operation is found
|
|
335
|
+
* then, return that binary operation
|
|
336
|
+
* @returns {string|boolean}
|
|
337
|
+
*/
|
|
338
|
+
gobbleBinaryOp() {
|
|
339
|
+
this.gobbleSpaces();
|
|
340
|
+
let e = this.expr.substr(this.index, i.max_binop_len), t = e.length;
|
|
341
|
+
for (; t > 0; ) {
|
|
342
|
+
if (i.binary_ops.hasOwnProperty(e) && (!i.isIdentifierStart(this.code) || this.index + e.length < this.expr.length && !i.isIdentifierPart(this.expr.charCodeAt(this.index + e.length))))
|
|
343
|
+
return this.index += t, e;
|
|
344
|
+
e = e.substr(0, --t);
|
|
345
|
+
}
|
|
346
|
+
return !1;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* This function is responsible for gobbling an individual expression,
|
|
350
|
+
* e.g. `1`, `1+2`, `a+(b*2)-Math.sqrt(2)`
|
|
351
|
+
* @returns {?jsep.BinaryExpression}
|
|
352
|
+
*/
|
|
353
|
+
gobbleBinaryExpression() {
|
|
354
|
+
let e, t, s, n, a, c, d, u, h;
|
|
355
|
+
if (c = this.gobbleToken(), !c || (t = this.gobbleBinaryOp(), !t))
|
|
356
|
+
return c;
|
|
357
|
+
for (a = {
|
|
358
|
+
value: t,
|
|
359
|
+
prec: i.binaryPrecedence(t),
|
|
360
|
+
right_a: i.right_associative.has(t)
|
|
361
|
+
}, d = this.gobbleToken(), d || this.throwError("Expected expression after " + t), n = [c, a, d]; t = this.gobbleBinaryOp(); ) {
|
|
362
|
+
if (s = i.binaryPrecedence(t), s === 0) {
|
|
363
|
+
this.index -= t.length;
|
|
364
|
+
break;
|
|
585
365
|
}
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
366
|
+
a = {
|
|
367
|
+
value: t,
|
|
368
|
+
prec: s,
|
|
369
|
+
right_a: i.right_associative.has(t)
|
|
370
|
+
}, h = t;
|
|
371
|
+
const b = (m) => a.right_a && m.right_a ? s > m.prec : s <= m.prec;
|
|
372
|
+
for (; n.length > 2 && b(n[n.length - 2]); )
|
|
373
|
+
d = n.pop(), t = n.pop().value, c = n.pop(), e = {
|
|
374
|
+
type: i.BINARY_EXP,
|
|
375
|
+
operator: t,
|
|
376
|
+
left: c,
|
|
377
|
+
right: d
|
|
378
|
+
}, n.push(e);
|
|
379
|
+
e = this.gobbleToken(), e || this.throwError("Expected expression after " + h), n.push(a, e);
|
|
380
|
+
}
|
|
381
|
+
for (u = n.length - 1, e = n[u]; u > 1; )
|
|
382
|
+
e = {
|
|
383
|
+
type: i.BINARY_EXP,
|
|
384
|
+
operator: n[u - 1].value,
|
|
385
|
+
left: n[u - 2],
|
|
386
|
+
right: e
|
|
387
|
+
}, u -= 2;
|
|
388
|
+
return e;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* An individual part of a binary expression:
|
|
392
|
+
* e.g. `foo.bar(baz)`, `1`, `"abc"`, `(a % 2)` (because it's in parenthesis)
|
|
393
|
+
* @returns {boolean|jsep.Expression}
|
|
394
|
+
*/
|
|
395
|
+
gobbleToken() {
|
|
396
|
+
let e, t, s, n;
|
|
397
|
+
if (this.gobbleSpaces(), n = this.searchHook("gobble-token"), n)
|
|
398
|
+
return this.runHook("after-token", n);
|
|
399
|
+
if (e = this.code, i.isDecimalDigit(e) || e === i.PERIOD_CODE)
|
|
400
|
+
return this.gobbleNumericLiteral();
|
|
401
|
+
if (e === i.SQUOTE_CODE || e === i.DQUOTE_CODE)
|
|
402
|
+
n = this.gobbleStringLiteral();
|
|
403
|
+
else if (e === i.OBRACK_CODE)
|
|
404
|
+
n = this.gobbleArray();
|
|
405
|
+
else {
|
|
406
|
+
for (t = this.expr.substr(this.index, i.max_unop_len), s = t.length; s > 0; ) {
|
|
407
|
+
if (i.unary_ops.hasOwnProperty(t) && (!i.isIdentifierStart(this.code) || this.index + t.length < this.expr.length && !i.isIdentifierPart(this.expr.charCodeAt(this.index + t.length)))) {
|
|
408
|
+
this.index += s;
|
|
409
|
+
const a = this.gobbleToken();
|
|
410
|
+
return a || this.throwError("missing unaryOp argument"), this.runHook("after-token", {
|
|
411
|
+
type: i.UNARY_EXP,
|
|
412
|
+
operator: t,
|
|
413
|
+
argument: a,
|
|
414
|
+
prefix: !0
|
|
415
|
+
});
|
|
590
416
|
}
|
|
591
|
-
|
|
592
|
-
return _.slice(0, c + 1 || 1);
|
|
593
|
-
}
|
|
594
|
-
function W(S, k) {
|
|
595
|
-
var L, g, c = S.c, _ = k.c, m = S.s, p = k.s, h = S.e, U = k.e;
|
|
596
|
-
if (!m || !p) return null;
|
|
597
|
-
if (L = c && !c[0], g = _ && !_[0], L || g) return L ? g ? 0 : -p : m;
|
|
598
|
-
if (m != p) return m;
|
|
599
|
-
if (L = m < 0, g = h == U, !c || !_) return g ? 0 : !c ^ L ? 1 : -1;
|
|
600
|
-
if (!g) return h > U ^ L ? 1 : -1;
|
|
601
|
-
for (p = (h = c.length) < (U = _.length) ? h : U, m = 0; m < p; m++) if (c[m] != _[m]) return c[m] > _[m] ^ L ? 1 : -1;
|
|
602
|
-
return h == U ? 0 : h > U ^ L ? 1 : -1;
|
|
603
|
-
}
|
|
604
|
-
function x(S, k, L, g) {
|
|
605
|
-
if (S < k || S > L || S !== j(S))
|
|
606
|
-
throw Error(C + (g || "Argument") + (typeof S == "number" ? S < k || S > L ? " out of range: " : " not an integer: " : " not a primitive number: ") + String(S));
|
|
607
|
-
}
|
|
608
|
-
function I(S) {
|
|
609
|
-
var k = S.c.length - 1;
|
|
610
|
-
return X(S.e / w) == k && S.c[k] % 2 != 0;
|
|
417
|
+
t = t.substr(0, --s);
|
|
611
418
|
}
|
|
612
|
-
|
|
613
|
-
|
|
419
|
+
i.isIdentifierStart(e) ? (n = this.gobbleIdentifier(), i.literals.hasOwnProperty(n.name) ? n = {
|
|
420
|
+
type: i.LITERAL,
|
|
421
|
+
value: i.literals[n.name],
|
|
422
|
+
raw: n.name
|
|
423
|
+
} : n.name === i.this_str && (n = {
|
|
424
|
+
type: i.THIS_EXP
|
|
425
|
+
})) : e === i.OPAREN_CODE && (n = this.gobbleGroup());
|
|
426
|
+
}
|
|
427
|
+
return n ? (n = this.gobbleTokenProperty(n), this.runHook("after-token", n)) : this.runHook("after-token", !1);
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Gobble properties of of identifiers/strings/arrays/groups.
|
|
431
|
+
* e.g. `foo`, `bar.baz`, `foo['bar'].baz`
|
|
432
|
+
* It also gobbles function calls:
|
|
433
|
+
* e.g. `Math.acos(obj.angle)`
|
|
434
|
+
* @param {jsep.Expression} node
|
|
435
|
+
* @returns {jsep.Expression}
|
|
436
|
+
*/
|
|
437
|
+
gobbleTokenProperty(e) {
|
|
438
|
+
this.gobbleSpaces();
|
|
439
|
+
let t = this.code;
|
|
440
|
+
for (; t === i.PERIOD_CODE || t === i.OBRACK_CODE || t === i.OPAREN_CODE || t === i.QUMARK_CODE; ) {
|
|
441
|
+
let s;
|
|
442
|
+
if (t === i.QUMARK_CODE) {
|
|
443
|
+
if (this.expr.charCodeAt(this.index + 1) !== i.PERIOD_CODE)
|
|
444
|
+
break;
|
|
445
|
+
s = !0, this.index += 2, this.gobbleSpaces(), t = this.code;
|
|
614
446
|
}
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
447
|
+
this.index++, t === i.OBRACK_CODE ? (e = {
|
|
448
|
+
type: i.MEMBER_EXP,
|
|
449
|
+
computed: !0,
|
|
450
|
+
object: e,
|
|
451
|
+
property: this.gobbleExpression()
|
|
452
|
+
}, e.property || this.throwError('Unexpected "' + this.char + '"'), this.gobbleSpaces(), t = this.code, t !== i.CBRACK_CODE && this.throwError("Unclosed ["), this.index++) : t === i.OPAREN_CODE ? e = {
|
|
453
|
+
type: i.CALL_EXP,
|
|
454
|
+
arguments: this.gobbleArguments(i.CPAREN_CODE),
|
|
455
|
+
callee: e
|
|
456
|
+
} : (t === i.PERIOD_CODE || s) && (s && this.index--, this.gobbleSpaces(), e = {
|
|
457
|
+
type: i.MEMBER_EXP,
|
|
458
|
+
computed: !1,
|
|
459
|
+
object: e,
|
|
460
|
+
property: this.gobbleIdentifier()
|
|
461
|
+
}), s && (e.optional = !0), this.gobbleSpaces(), t = this.code;
|
|
462
|
+
}
|
|
463
|
+
return e;
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Parse simple numeric literals: `12`, `3.4`, `.5`. Do this by using a string to
|
|
467
|
+
* keep track of everything in the numeric literal and then calling `parseFloat` on that string
|
|
468
|
+
* @returns {jsep.Literal}
|
|
469
|
+
*/
|
|
470
|
+
gobbleNumericLiteral() {
|
|
471
|
+
let e = "", t, s;
|
|
472
|
+
for (; i.isDecimalDigit(this.code); )
|
|
473
|
+
e += this.expr.charAt(this.index++);
|
|
474
|
+
if (this.code === i.PERIOD_CODE)
|
|
475
|
+
for (e += this.expr.charAt(this.index++); i.isDecimalDigit(this.code); )
|
|
476
|
+
e += this.expr.charAt(this.index++);
|
|
477
|
+
if (t = this.char, t === "e" || t === "E") {
|
|
478
|
+
for (e += this.expr.charAt(this.index++), t = this.char, (t === "+" || t === "-") && (e += this.expr.charAt(this.index++)); i.isDecimalDigit(this.code); )
|
|
479
|
+
e += this.expr.charAt(this.index++);
|
|
480
|
+
i.isDecimalDigit(this.expr.charCodeAt(this.index - 1)) || this.throwError("Expected exponent (" + e + this.char + ")");
|
|
481
|
+
}
|
|
482
|
+
return s = this.code, i.isIdentifierStart(s) ? this.throwError("Variable names cannot start with a number (" + e + this.char + ")") : (s === i.PERIOD_CODE || e.length === 1 && e.charCodeAt(0) === i.PERIOD_CODE) && this.throwError("Unexpected period"), {
|
|
483
|
+
type: i.LITERAL,
|
|
484
|
+
value: parseFloat(e),
|
|
485
|
+
raw: e
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Parses a string literal, staring with single or double quotes with basic support for escape codes
|
|
490
|
+
* e.g. `"hello world"`, `'this is\nJSEP'`
|
|
491
|
+
* @returns {jsep.Literal}
|
|
492
|
+
*/
|
|
493
|
+
gobbleStringLiteral() {
|
|
494
|
+
let e = "";
|
|
495
|
+
const t = this.index, s = this.expr.charAt(this.index++);
|
|
496
|
+
let n = !1;
|
|
497
|
+
for (; this.index < this.expr.length; ) {
|
|
498
|
+
let a = this.expr.charAt(this.index++);
|
|
499
|
+
if (a === s) {
|
|
500
|
+
n = !0;
|
|
501
|
+
break;
|
|
502
|
+
} else if (a === "\\")
|
|
503
|
+
switch (a = this.expr.charAt(this.index++), a) {
|
|
504
|
+
case "n":
|
|
505
|
+
e += `
|
|
506
|
+
`;
|
|
507
|
+
break;
|
|
508
|
+
case "r":
|
|
509
|
+
e += "\r";
|
|
510
|
+
break;
|
|
511
|
+
case "t":
|
|
512
|
+
e += " ";
|
|
513
|
+
break;
|
|
514
|
+
case "b":
|
|
515
|
+
e += "\b";
|
|
516
|
+
break;
|
|
517
|
+
case "f":
|
|
518
|
+
e += "\f";
|
|
519
|
+
break;
|
|
520
|
+
case "v":
|
|
521
|
+
e += "\v";
|
|
522
|
+
break;
|
|
523
|
+
default:
|
|
524
|
+
e += a;
|
|
525
|
+
}
|
|
526
|
+
else
|
|
527
|
+
e += a;
|
|
528
|
+
}
|
|
529
|
+
return n || this.throwError('Unclosed quote after "' + e + '"'), {
|
|
530
|
+
type: i.LITERAL,
|
|
531
|
+
value: e,
|
|
532
|
+
raw: this.expr.substring(t, this.index)
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Gobbles only identifiers
|
|
537
|
+
* e.g.: `foo`, `_value`, `$x1`
|
|
538
|
+
* Also, this function checks if that identifier is a literal:
|
|
539
|
+
* (e.g. `true`, `false`, `null`) or `this`
|
|
540
|
+
* @returns {jsep.Identifier}
|
|
541
|
+
*/
|
|
542
|
+
gobbleIdentifier() {
|
|
543
|
+
let e = this.code, t = this.index;
|
|
544
|
+
for (i.isIdentifierStart(e) ? this.index++ : this.throwError("Unexpected " + this.char); this.index < this.expr.length && (e = this.code, i.isIdentifierPart(e)); )
|
|
545
|
+
this.index++;
|
|
546
|
+
return {
|
|
547
|
+
type: i.IDENTIFIER,
|
|
548
|
+
name: this.expr.slice(t, this.index)
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Gobbles a list of arguments within the context of a function call
|
|
553
|
+
* or array literal. This function also assumes that the opening character
|
|
554
|
+
* `(` or `[` has already been gobbled, and gobbles expressions and commas
|
|
555
|
+
* until the terminator character `)` or `]` is encountered.
|
|
556
|
+
* e.g. `foo(bar, baz)`, `my_func()`, or `[bar, baz]`
|
|
557
|
+
* @param {number} termination
|
|
558
|
+
* @returns {jsep.Expression[]}
|
|
559
|
+
*/
|
|
560
|
+
gobbleArguments(e) {
|
|
561
|
+
const t = [];
|
|
562
|
+
let s = !1, n = 0;
|
|
563
|
+
for (; this.index < this.expr.length; ) {
|
|
564
|
+
this.gobbleSpaces();
|
|
565
|
+
let a = this.code;
|
|
566
|
+
if (a === e) {
|
|
567
|
+
s = !0, this.index++, e === i.CPAREN_CODE && n && n >= t.length && this.throwError("Unexpected token " + String.fromCharCode(e));
|
|
568
|
+
break;
|
|
569
|
+
} else if (a === i.COMMA_CODE) {
|
|
570
|
+
if (this.index++, n++, n !== t.length) {
|
|
571
|
+
if (e === i.CPAREN_CODE)
|
|
572
|
+
this.throwError("Unexpected token ,");
|
|
573
|
+
else if (e === i.CBRACK_CODE)
|
|
574
|
+
for (let c = t.length; c < n; c++)
|
|
575
|
+
t.push(null);
|
|
576
|
+
}
|
|
577
|
+
} else if (t.length !== n && n !== 0)
|
|
578
|
+
this.throwError("Expected comma");
|
|
579
|
+
else {
|
|
580
|
+
const c = this.gobbleExpression();
|
|
581
|
+
(!c || c.type === i.COMPOUND) && this.throwError("Expected comma"), t.push(c);
|
|
625
582
|
}
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
}
|
|
583
|
+
}
|
|
584
|
+
return s || this.throwError("Expected " + String.fromCharCode(e)), t;
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Responsible for parsing a group of things within parentheses `()`
|
|
588
|
+
* that have no identifier in front (so not a function call)
|
|
589
|
+
* This function assumes that it needs to gobble the opening parenthesis
|
|
590
|
+
* and then tries to gobble everything within that parenthesis, assuming
|
|
591
|
+
* that the next thing it should see is the close parenthesis. If not,
|
|
592
|
+
* then the expression probably doesn't have a `)`
|
|
593
|
+
* @returns {boolean|jsep.Expression}
|
|
594
|
+
*/
|
|
595
|
+
gobbleGroup() {
|
|
596
|
+
this.index++;
|
|
597
|
+
let e = this.gobbleExpressions(i.CPAREN_CODE);
|
|
598
|
+
if (this.code === i.CPAREN_CODE)
|
|
599
|
+
return this.index++, e.length === 1 ? e[0] : e.length ? {
|
|
600
|
+
type: i.SEQUENCE_EXP,
|
|
601
|
+
expressions: e
|
|
602
|
+
} : !1;
|
|
603
|
+
this.throwError("Unclosed (");
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* Responsible for parsing Array literals `[1, 2, 3]`
|
|
607
|
+
* This function assumes that it needs to gobble the opening bracket
|
|
608
|
+
* and then tries to gobble the expressions as arguments.
|
|
609
|
+
* @returns {jsep.ArrayExpression}
|
|
610
|
+
*/
|
|
611
|
+
gobbleArray() {
|
|
612
|
+
return this.index++, {
|
|
613
|
+
type: i.ARRAY_EXP,
|
|
614
|
+
elements: this.gobbleArguments(i.CBRACK_CODE)
|
|
615
|
+
};
|
|
616
|
+
}
|
|
629
617
|
}
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
618
|
+
const be = new ge();
|
|
619
|
+
Object.assign(i, {
|
|
620
|
+
hooks: be,
|
|
621
|
+
plugins: new Ee(i),
|
|
622
|
+
// Node Types
|
|
623
|
+
// ----------
|
|
624
|
+
// This is the full set of types that any JSEP node can be.
|
|
625
|
+
// Store them here to save space when minified
|
|
626
|
+
COMPOUND: "Compound",
|
|
627
|
+
SEQUENCE_EXP: "SequenceExpression",
|
|
628
|
+
IDENTIFIER: "Identifier",
|
|
629
|
+
MEMBER_EXP: "MemberExpression",
|
|
630
|
+
LITERAL: "Literal",
|
|
631
|
+
THIS_EXP: "ThisExpression",
|
|
632
|
+
CALL_EXP: "CallExpression",
|
|
633
|
+
UNARY_EXP: "UnaryExpression",
|
|
634
|
+
BINARY_EXP: "BinaryExpression",
|
|
635
|
+
ARRAY_EXP: "ArrayExpression",
|
|
636
|
+
TAB_CODE: 9,
|
|
637
|
+
LF_CODE: 10,
|
|
638
|
+
CR_CODE: 13,
|
|
639
|
+
SPACE_CODE: 32,
|
|
640
|
+
PERIOD_CODE: 46,
|
|
641
|
+
// '.'
|
|
642
|
+
COMMA_CODE: 44,
|
|
643
|
+
// ','
|
|
644
|
+
SQUOTE_CODE: 39,
|
|
645
|
+
// single quote
|
|
646
|
+
DQUOTE_CODE: 34,
|
|
647
|
+
// double quotes
|
|
648
|
+
OPAREN_CODE: 40,
|
|
649
|
+
// (
|
|
650
|
+
CPAREN_CODE: 41,
|
|
651
|
+
// )
|
|
652
|
+
OBRACK_CODE: 91,
|
|
653
|
+
// [
|
|
654
|
+
CBRACK_CODE: 93,
|
|
655
|
+
// ]
|
|
656
|
+
QUMARK_CODE: 63,
|
|
657
|
+
// ?
|
|
658
|
+
SEMCOL_CODE: 59,
|
|
659
|
+
// ;
|
|
660
|
+
COLON_CODE: 58,
|
|
661
|
+
// :
|
|
662
|
+
// Operations
|
|
663
|
+
// ----------
|
|
664
|
+
// Use a quickly-accessible map to store all of the unary operators
|
|
665
|
+
// Values are set to `1` (it really doesn't matter)
|
|
666
|
+
unary_ops: {
|
|
667
|
+
"-": 1,
|
|
668
|
+
"!": 1,
|
|
669
|
+
"~": 1,
|
|
670
|
+
"+": 1
|
|
671
|
+
},
|
|
672
|
+
// Also use a map for the binary operations but set their values to their
|
|
673
|
+
// binary precedence for quick reference (higher number = higher precedence)
|
|
674
|
+
// see [Order of operations](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence)
|
|
675
|
+
binary_ops: {
|
|
676
|
+
"||": 1,
|
|
677
|
+
"??": 1,
|
|
678
|
+
"&&": 2,
|
|
679
|
+
"|": 3,
|
|
680
|
+
"^": 4,
|
|
681
|
+
"&": 5,
|
|
682
|
+
"==": 6,
|
|
683
|
+
"!=": 6,
|
|
684
|
+
"===": 6,
|
|
685
|
+
"!==": 6,
|
|
686
|
+
"<": 7,
|
|
687
|
+
">": 7,
|
|
688
|
+
"<=": 7,
|
|
689
|
+
">=": 7,
|
|
690
|
+
"<<": 8,
|
|
691
|
+
">>": 8,
|
|
692
|
+
">>>": 8,
|
|
693
|
+
"+": 9,
|
|
694
|
+
"-": 9,
|
|
695
|
+
"*": 10,
|
|
696
|
+
"/": 10,
|
|
697
|
+
"%": 10,
|
|
698
|
+
"**": 11
|
|
699
|
+
},
|
|
700
|
+
// sets specific binary_ops as right-associative
|
|
701
|
+
right_associative: /* @__PURE__ */ new Set(["**"]),
|
|
702
|
+
// Additional valid identifier chars, apart from a-z, A-Z and 0-9 (except on the starting char)
|
|
703
|
+
additional_identifier_chars: /* @__PURE__ */ new Set(["$", "_"]),
|
|
704
|
+
// Literals
|
|
705
|
+
// ----------
|
|
706
|
+
// Store the values to return for the various literals we may encounter
|
|
707
|
+
literals: {
|
|
708
|
+
true: !0,
|
|
709
|
+
false: !1,
|
|
710
|
+
null: null
|
|
711
|
+
},
|
|
712
|
+
// Except for `this`, which is special. This could be changed to something like `'self'` as well
|
|
713
|
+
this_str: "this"
|
|
714
|
+
});
|
|
715
|
+
i.max_unop_len = i.getMaxKeyLen(i.unary_ops);
|
|
716
|
+
i.max_binop_len = i.getMaxKeyLen(i.binary_ops);
|
|
717
|
+
const L = (r) => new i(r).parse(), ve = Object.getOwnPropertyNames(class {
|
|
718
|
+
});
|
|
719
|
+
Object.getOwnPropertyNames(i).filter((r) => !ve.includes(r) && L[r] === void 0).forEach((r) => {
|
|
720
|
+
L[r] = i[r];
|
|
721
|
+
});
|
|
722
|
+
L.Jsep = i;
|
|
723
|
+
const _e = "ConditionalExpression";
|
|
724
|
+
var me = {
|
|
725
|
+
name: "ternary",
|
|
726
|
+
init(r) {
|
|
727
|
+
r.hooks.add("after-expression", function(t) {
|
|
728
|
+
if (t.node && this.code === r.QUMARK_CODE) {
|
|
729
|
+
this.index++;
|
|
730
|
+
const s = t.node, n = this.gobbleExpression();
|
|
731
|
+
if (n || this.throwError("Expected expression"), this.gobbleSpaces(), this.code === r.COLON_CODE) {
|
|
732
|
+
this.index++;
|
|
733
|
+
const a = this.gobbleExpression();
|
|
734
|
+
if (a || this.throwError("Expected expression"), t.node = {
|
|
735
|
+
type: _e,
|
|
736
|
+
test: s,
|
|
737
|
+
consequent: n,
|
|
738
|
+
alternate: a
|
|
739
|
+
}, s.operator && r.binary_ops[s.operator] <= 0.9) {
|
|
740
|
+
let c = s;
|
|
741
|
+
for (; c.right.operator && r.binary_ops[c.right.operator] <= 0.9; )
|
|
742
|
+
c = c.right;
|
|
743
|
+
t.node.test = c.right, c.right = t.node, t.node = s;
|
|
744
|
+
}
|
|
745
|
+
} else
|
|
746
|
+
this.throwError("Expected :");
|
|
650
747
|
}
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
` + D + "]" : "[" + W.join(",") + "]", O = D, z;
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
};
|
|
751
|
+
L.plugins.register(me);
|
|
752
|
+
const oe = 47, xe = 92;
|
|
753
|
+
var Oe = {
|
|
754
|
+
name: "regex",
|
|
755
|
+
init(r) {
|
|
756
|
+
r.hooks.add("gobble-token", function(t) {
|
|
757
|
+
if (this.code === oe) {
|
|
758
|
+
const s = ++this.index;
|
|
759
|
+
let n = !1;
|
|
760
|
+
for (; this.index < this.expr.length; ) {
|
|
761
|
+
if (this.code === oe && !n) {
|
|
762
|
+
const a = this.expr.slice(s, this.index);
|
|
763
|
+
let c = "";
|
|
764
|
+
for (; ++this.index < this.expr.length; ) {
|
|
765
|
+
const u = this.code;
|
|
766
|
+
if (u >= 97 && u <= 122 || u >= 65 && u <= 90 || u >= 48 && u <= 57)
|
|
767
|
+
c += this.char;
|
|
768
|
+
else
|
|
769
|
+
break;
|
|
674
770
|
}
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
771
|
+
let d;
|
|
772
|
+
try {
|
|
773
|
+
d = new RegExp(a, c);
|
|
774
|
+
} catch (u) {
|
|
775
|
+
this.throwError(u.message);
|
|
776
|
+
}
|
|
777
|
+
return t.node = {
|
|
778
|
+
type: r.LITERAL,
|
|
779
|
+
value: d,
|
|
780
|
+
raw: this.expr.slice(s - 1, this.index)
|
|
781
|
+
}, t.node = this.gobbleTokenProperty(t.node), t.node;
|
|
782
|
+
}
|
|
783
|
+
this.code === r.OBRACK_CODE ? n = !0 : n && this.code === r.CBRACK_CODE && (n = !1), this.index += this.code === xe ? 2 : 1;
|
|
687
784
|
}
|
|
785
|
+
this.throwError("Unclosed Regex");
|
|
786
|
+
}
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
};
|
|
790
|
+
const ne = 43, Ce = 45, H = {
|
|
791
|
+
name: "assignment",
|
|
792
|
+
assignmentOperators: /* @__PURE__ */ new Set(["=", "*=", "**=", "/=", "%=", "+=", "-=", "<<=", ">>=", ">>>=", "&=", "^=", "|=", "||=", "&&=", "??="]),
|
|
793
|
+
updateOperators: [ne, Ce],
|
|
794
|
+
assignmentPrecedence: 0.9,
|
|
795
|
+
init(r) {
|
|
796
|
+
const e = [r.IDENTIFIER, r.MEMBER_EXP];
|
|
797
|
+
H.assignmentOperators.forEach((s) => r.addBinaryOp(s, H.assignmentPrecedence, !0)), r.hooks.add("gobble-token", function(n) {
|
|
798
|
+
const a = this.code;
|
|
799
|
+
H.updateOperators.some((c) => c === a && c === this.expr.charCodeAt(this.index + 1)) && (this.index += 2, n.node = {
|
|
800
|
+
type: "UpdateExpression",
|
|
801
|
+
operator: a === ne ? "++" : "--",
|
|
802
|
+
argument: this.gobbleTokenProperty(this.gobbleIdentifier()),
|
|
803
|
+
prefix: !0
|
|
804
|
+
}, (!n.node.argument || !e.includes(n.node.argument.type)) && this.throwError(`Unexpected ${n.node.operator}`));
|
|
805
|
+
}), r.hooks.add("after-token", function(n) {
|
|
806
|
+
if (n.node) {
|
|
807
|
+
const a = this.code;
|
|
808
|
+
H.updateOperators.some((c) => c === a && c === this.expr.charCodeAt(this.index + 1)) && (e.includes(n.node.type) || this.throwError(`Unexpected ${n.node.operator}`), this.index += 2, n.node = {
|
|
809
|
+
type: "UpdateExpression",
|
|
810
|
+
operator: a === ne ? "++" : "--",
|
|
811
|
+
argument: n.node,
|
|
812
|
+
prefix: !1
|
|
813
|
+
});
|
|
688
814
|
}
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
if (y = A, A && typeof A != "function" && (typeof A != "object" || typeof A.length != "number"))
|
|
696
|
-
throw new Error("JSON.stringify");
|
|
697
|
-
return w("", { "": J });
|
|
815
|
+
}), r.hooks.add("after-expression", function(n) {
|
|
816
|
+
n.node && t(n.node);
|
|
817
|
+
});
|
|
818
|
+
function t(s) {
|
|
819
|
+
H.assignmentOperators.has(s.operator) ? (s.type = "AssignmentExpression", t(s.left), t(s.right)) : s.operator || Object.values(s).forEach((n) => {
|
|
820
|
+
n && typeof n == "object" && t(n);
|
|
698
821
|
});
|
|
699
|
-
}
|
|
700
|
-
}
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
};
|
|
825
|
+
L.plugins.register(Oe, H);
|
|
826
|
+
L.addUnaryOp("typeof");
|
|
827
|
+
L.addLiteral("null", null);
|
|
828
|
+
L.addLiteral("undefined", void 0);
|
|
829
|
+
const Ae = /* @__PURE__ */ new Set(["constructor", "__proto__", "__defineGetter__", "__defineSetter__"]), O = {
|
|
830
|
+
/**
|
|
831
|
+
* @param {jsep.Expression} ast
|
|
832
|
+
* @param {Record<string, any>} subs
|
|
833
|
+
*/
|
|
834
|
+
evalAst(r, e) {
|
|
835
|
+
switch (r.type) {
|
|
836
|
+
case "BinaryExpression":
|
|
837
|
+
case "LogicalExpression":
|
|
838
|
+
return O.evalBinaryExpression(r, e);
|
|
839
|
+
case "Compound":
|
|
840
|
+
return O.evalCompound(r, e);
|
|
841
|
+
case "ConditionalExpression":
|
|
842
|
+
return O.evalConditionalExpression(r, e);
|
|
843
|
+
case "Identifier":
|
|
844
|
+
return O.evalIdentifier(r, e);
|
|
845
|
+
case "Literal":
|
|
846
|
+
return O.evalLiteral(r, e);
|
|
847
|
+
case "MemberExpression":
|
|
848
|
+
return O.evalMemberExpression(r, e);
|
|
849
|
+
case "UnaryExpression":
|
|
850
|
+
return O.evalUnaryExpression(r, e);
|
|
851
|
+
case "ArrayExpression":
|
|
852
|
+
return O.evalArrayExpression(r, e);
|
|
853
|
+
case "CallExpression":
|
|
854
|
+
return O.evalCallExpression(r, e);
|
|
855
|
+
case "AssignmentExpression":
|
|
856
|
+
return O.evalAssignmentExpression(r, e);
|
|
857
|
+
default:
|
|
858
|
+
throw SyntaxError("Unexpected expression", r);
|
|
859
|
+
}
|
|
860
|
+
},
|
|
861
|
+
evalBinaryExpression(r, e) {
|
|
862
|
+
return {
|
|
863
|
+
"||": (s, n) => s || n(),
|
|
864
|
+
"&&": (s, n) => s && n(),
|
|
865
|
+
"|": (s, n) => s | n(),
|
|
866
|
+
"^": (s, n) => s ^ n(),
|
|
867
|
+
"&": (s, n) => s & n(),
|
|
868
|
+
// eslint-disable-next-line eqeqeq -- API
|
|
869
|
+
"==": (s, n) => s == n(),
|
|
870
|
+
// eslint-disable-next-line eqeqeq -- API
|
|
871
|
+
"!=": (s, n) => s != n(),
|
|
872
|
+
"===": (s, n) => s === n(),
|
|
873
|
+
"!==": (s, n) => s !== n(),
|
|
874
|
+
"<": (s, n) => s < n(),
|
|
875
|
+
">": (s, n) => s > n(),
|
|
876
|
+
"<=": (s, n) => s <= n(),
|
|
877
|
+
">=": (s, n) => s >= n(),
|
|
878
|
+
"<<": (s, n) => s << n(),
|
|
879
|
+
">>": (s, n) => s >> n(),
|
|
880
|
+
">>>": (s, n) => s >>> n(),
|
|
881
|
+
"+": (s, n) => s + n(),
|
|
882
|
+
"-": (s, n) => s - n(),
|
|
883
|
+
"*": (s, n) => s * n(),
|
|
884
|
+
"/": (s, n) => s / n(),
|
|
885
|
+
"%": (s, n) => s % n()
|
|
886
|
+
}[r.operator](O.evalAst(r.left, e), () => O.evalAst(r.right, e));
|
|
887
|
+
},
|
|
888
|
+
evalCompound(r, e) {
|
|
889
|
+
let t;
|
|
890
|
+
for (let s = 0; s < r.body.length; s++) {
|
|
891
|
+
r.body[s].type === "Identifier" && ["var", "let", "const"].includes(r.body[s].name) && r.body[s + 1] && r.body[s + 1].type === "AssignmentExpression" && (s += 1);
|
|
892
|
+
const n = r.body[s];
|
|
893
|
+
t = O.evalAst(n, e);
|
|
894
|
+
}
|
|
895
|
+
return t;
|
|
896
|
+
},
|
|
897
|
+
evalConditionalExpression(r, e) {
|
|
898
|
+
return O.evalAst(r.test, e) ? O.evalAst(r.consequent, e) : O.evalAst(r.alternate, e);
|
|
899
|
+
},
|
|
900
|
+
evalIdentifier(r, e) {
|
|
901
|
+
if (Object.hasOwn(e, r.name))
|
|
902
|
+
return e[r.name];
|
|
903
|
+
throw ReferenceError(`${r.name} is not defined`);
|
|
904
|
+
},
|
|
905
|
+
evalLiteral(r) {
|
|
906
|
+
return r.value;
|
|
907
|
+
},
|
|
908
|
+
evalMemberExpression(r, e) {
|
|
909
|
+
const t = String(
|
|
910
|
+
// NOTE: `String(value)` throws error when
|
|
911
|
+
// value has overwritten the toString method to return non-string
|
|
912
|
+
// i.e. `value = {toString: () => []}`
|
|
913
|
+
r.computed ? O.evalAst(r.property) : r.property.name
|
|
914
|
+
// `object.property` property is Identifier
|
|
915
|
+
), s = O.evalAst(r.object, e);
|
|
916
|
+
if (s == null)
|
|
917
|
+
throw TypeError(`Cannot read properties of ${s} (reading '${t}')`);
|
|
918
|
+
if (!Object.hasOwn(s, t) && Ae.has(t))
|
|
919
|
+
throw TypeError(`Cannot read properties of ${s} (reading '${t}')`);
|
|
920
|
+
const n = s[t];
|
|
921
|
+
return typeof n == "function" ? n.bind(s) : n;
|
|
922
|
+
},
|
|
923
|
+
evalUnaryExpression(r, e) {
|
|
924
|
+
return {
|
|
925
|
+
"-": (s) => -O.evalAst(s, e),
|
|
926
|
+
"!": (s) => !O.evalAst(s, e),
|
|
927
|
+
"~": (s) => ~O.evalAst(s, e),
|
|
928
|
+
// eslint-disable-next-line no-implicit-coercion -- API
|
|
929
|
+
"+": (s) => +O.evalAst(s, e),
|
|
930
|
+
typeof: (s) => typeof O.evalAst(s, e)
|
|
931
|
+
}[r.operator](r.argument);
|
|
932
|
+
},
|
|
933
|
+
evalArrayExpression(r, e) {
|
|
934
|
+
return r.elements.map((t) => O.evalAst(t, e));
|
|
935
|
+
},
|
|
936
|
+
evalCallExpression(r, e) {
|
|
937
|
+
const t = r.arguments.map((n) => O.evalAst(n, e));
|
|
938
|
+
return O.evalAst(r.callee, e)(...t);
|
|
939
|
+
},
|
|
940
|
+
evalAssignmentExpression(r, e) {
|
|
941
|
+
if (r.left.type !== "Identifier")
|
|
942
|
+
throw SyntaxError("Invalid left-hand side in assignment");
|
|
943
|
+
const t = r.left.name, s = O.evalAst(r.right, e);
|
|
944
|
+
return e[t] = s, e[t];
|
|
945
|
+
}
|
|
946
|
+
};
|
|
947
|
+
class we {
|
|
948
|
+
/**
|
|
949
|
+
* @param {string} expr Expression to evaluate
|
|
950
|
+
*/
|
|
951
|
+
constructor(e) {
|
|
952
|
+
this.code = e, this.ast = L(this.code);
|
|
953
|
+
}
|
|
954
|
+
/**
|
|
955
|
+
* @param {object} context Object whose items will be added
|
|
956
|
+
* to evaluation
|
|
957
|
+
* @returns {EvaluatedResult} Result of evaluated code
|
|
958
|
+
*/
|
|
959
|
+
runInNewContext(e) {
|
|
960
|
+
const t = Object.assign(/* @__PURE__ */ Object.create(null), e);
|
|
961
|
+
return O.evalAst(this.ast, t);
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
function F(r, e) {
|
|
965
|
+
return r = r.slice(), r.push(e), r;
|
|
701
966
|
}
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
967
|
+
function se(r, e) {
|
|
968
|
+
return e = e.slice(), e.unshift(r), e;
|
|
969
|
+
}
|
|
970
|
+
class ke extends Error {
|
|
971
|
+
/**
|
|
972
|
+
* @param {AnyResult} value The evaluated scalar value
|
|
973
|
+
*/
|
|
974
|
+
constructor(e) {
|
|
975
|
+
super('JSONPath should not be called with "new" (it prevents return of (unwrapped) scalar values)'), this.avoidNew = !0, this.value = e, this.name = "NewError";
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
function x(r, e, t, s, n) {
|
|
979
|
+
if (!(this instanceof x))
|
|
980
|
+
try {
|
|
981
|
+
return new x(r, e, t, s, n);
|
|
982
|
+
} catch (c) {
|
|
983
|
+
if (!c.avoidNew)
|
|
984
|
+
throw c;
|
|
985
|
+
return c.value;
|
|
986
|
+
}
|
|
987
|
+
typeof r == "string" && (n = s, s = t, t = e, e = r, r = null);
|
|
988
|
+
const a = r && typeof r == "object";
|
|
989
|
+
if (r = r || {}, this.json = r.json || t, this.path = r.path || e, this.resultType = r.resultType || "value", this.flatten = r.flatten || !1, this.wrap = Object.hasOwn(r, "wrap") ? r.wrap : !0, this.sandbox = r.sandbox || {}, this.eval = r.eval === void 0 ? "safe" : r.eval, this.ignoreEvalErrors = typeof r.ignoreEvalErrors > "u" ? !1 : r.ignoreEvalErrors, this.parent = r.parent || null, this.parentProperty = r.parentProperty || null, this.callback = r.callback || s || null, this.otherTypeCallback = r.otherTypeCallback || n || function() {
|
|
990
|
+
throw new TypeError("You must supply an otherTypeCallback callback option with the @other() operator.");
|
|
991
|
+
}, r.autostart !== !1) {
|
|
992
|
+
const c = {
|
|
993
|
+
path: a ? r.path : e
|
|
720
994
|
};
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
995
|
+
a ? "json" in r && (c.json = r.json) : c.json = t;
|
|
996
|
+
const d = this.evaluate(c);
|
|
997
|
+
if (!d || typeof d != "object")
|
|
998
|
+
throw new ke(d);
|
|
999
|
+
return d;
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
x.prototype.evaluate = function(r, e, t, s) {
|
|
1003
|
+
let n = this.parent, a = this.parentProperty, {
|
|
1004
|
+
flatten: c,
|
|
1005
|
+
wrap: d
|
|
1006
|
+
} = this;
|
|
1007
|
+
if (this.currResultType = this.resultType, this.currEval = this.eval, this.currSandbox = this.sandbox, t = t || this.callback, this.currOtherTypeCallback = s || this.otherTypeCallback, e = e || this.json, r = r || this.path, r && typeof r == "object" && !Array.isArray(r)) {
|
|
1008
|
+
if (!r.path && r.path !== "")
|
|
1009
|
+
throw new TypeError('You must supply a "path" property when providing an object argument to JSONPath.evaluate().');
|
|
1010
|
+
if (!Object.hasOwn(r, "json"))
|
|
1011
|
+
throw new TypeError('You must supply a "json" property when providing an object argument to JSONPath.evaluate().');
|
|
1012
|
+
({
|
|
1013
|
+
json: e
|
|
1014
|
+
} = r), c = Object.hasOwn(r, "flatten") ? r.flatten : c, this.currResultType = Object.hasOwn(r, "resultType") ? r.resultType : this.currResultType, this.currSandbox = Object.hasOwn(r, "sandbox") ? r.sandbox : this.currSandbox, d = Object.hasOwn(r, "wrap") ? r.wrap : d, this.currEval = Object.hasOwn(r, "eval") ? r.eval : this.currEval, t = Object.hasOwn(r, "callback") ? r.callback : t, this.currOtherTypeCallback = Object.hasOwn(r, "otherTypeCallback") ? r.otherTypeCallback : this.currOtherTypeCallback, n = Object.hasOwn(r, "parent") ? r.parent : n, a = Object.hasOwn(r, "parentProperty") ? r.parentProperty : a, r = r.path;
|
|
1015
|
+
}
|
|
1016
|
+
if (n = n || null, a = a || null, Array.isArray(r) && (r = x.toPathString(r)), !r && r !== "" || !e)
|
|
1017
|
+
return;
|
|
1018
|
+
const u = x.toPathArray(r);
|
|
1019
|
+
u[0] === "$" && u.length > 1 && u.shift(), this._hasParentSelector = null;
|
|
1020
|
+
const h = this._trace(u, e, ["$"], n, a, t).filter(function(b) {
|
|
1021
|
+
return b && !b.isParentSelector;
|
|
1022
|
+
});
|
|
1023
|
+
return h.length ? !d && h.length === 1 && !h[0].hasArrExpr ? this._getPreferredOutput(h[0]) : h.reduce((b, m) => {
|
|
1024
|
+
const C = this._getPreferredOutput(m);
|
|
1025
|
+
return c && Array.isArray(C) ? b = b.concat(C) : b.push(C), b;
|
|
1026
|
+
}, []) : d ? [] : void 0;
|
|
1027
|
+
};
|
|
1028
|
+
x.prototype._getPreferredOutput = function(r) {
|
|
1029
|
+
const e = this.currResultType;
|
|
1030
|
+
switch (e) {
|
|
1031
|
+
case "all": {
|
|
1032
|
+
const t = Array.isArray(r.path) ? r.path : x.toPathArray(r.path);
|
|
1033
|
+
return r.pointer = x.toPointer(t), r.path = typeof r.path == "string" ? r.path : x.toPathString(r.path), r;
|
|
736
1034
|
}
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
1035
|
+
case "value":
|
|
1036
|
+
case "parent":
|
|
1037
|
+
case "parentProperty":
|
|
1038
|
+
return r[e];
|
|
1039
|
+
case "path":
|
|
1040
|
+
return x.toPathString(r[e]);
|
|
1041
|
+
case "pointer":
|
|
1042
|
+
return x.toPointer(r.path);
|
|
1043
|
+
default:
|
|
1044
|
+
throw new TypeError("Unknown result type");
|
|
1045
|
+
}
|
|
1046
|
+
};
|
|
1047
|
+
x.prototype._handleCallback = function(r, e, t) {
|
|
1048
|
+
if (e) {
|
|
1049
|
+
const s = this._getPreferredOutput(r);
|
|
1050
|
+
r.path = typeof r.path == "string" ? r.path : x.toPathString(r.path), e(s, t, r);
|
|
1051
|
+
}
|
|
1052
|
+
};
|
|
1053
|
+
x.prototype._trace = function(r, e, t, s, n, a, c, d) {
|
|
1054
|
+
let u;
|
|
1055
|
+
if (!r.length)
|
|
1056
|
+
return u = {
|
|
1057
|
+
path: t,
|
|
1058
|
+
value: e,
|
|
1059
|
+
parent: s,
|
|
1060
|
+
parentProperty: n,
|
|
1061
|
+
hasArrExpr: c
|
|
1062
|
+
}, this._handleCallback(u, a, "value"), u;
|
|
1063
|
+
const h = r[0], b = r.slice(1), m = [];
|
|
1064
|
+
function C(E) {
|
|
1065
|
+
Array.isArray(E) ? E.forEach((S) => {
|
|
1066
|
+
m.push(S);
|
|
1067
|
+
}) : m.push(E);
|
|
1068
|
+
}
|
|
1069
|
+
if ((typeof h != "string" || d) && e && Object.hasOwn(e, h))
|
|
1070
|
+
C(this._trace(b, e[h], F(t, h), e, h, a, c));
|
|
1071
|
+
else if (h === "*")
|
|
1072
|
+
this._walk(e, (E) => {
|
|
1073
|
+
C(this._trace(b, e[E], F(t, E), e, E, a, !0, !0));
|
|
1074
|
+
});
|
|
1075
|
+
else if (h === "..")
|
|
1076
|
+
C(this._trace(b, e, t, s, n, a, c)), this._walk(e, (E) => {
|
|
1077
|
+
typeof e[E] == "object" && C(this._trace(r.slice(), e[E], F(t, E), e, E, a, !0));
|
|
1078
|
+
});
|
|
1079
|
+
else {
|
|
1080
|
+
if (h === "^")
|
|
1081
|
+
return this._hasParentSelector = !0, {
|
|
1082
|
+
path: t.slice(0, -1),
|
|
1083
|
+
expr: b,
|
|
1084
|
+
isParentSelector: !0
|
|
753
1085
|
};
|
|
754
|
-
|
|
755
|
-
return
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
if (
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
case "
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
}, x = function() {
|
|
815
|
-
var I, b = /* @__PURE__ */ Object.create(null);
|
|
816
|
-
if (y === "{") {
|
|
817
|
-
if (A("{"), z(), y === "}")
|
|
818
|
-
return A("}"), b;
|
|
819
|
-
for (; y; ) {
|
|
820
|
-
if (I = $(), z(), A(":"), j.strict === !0 && Object.hasOwnProperty.call(b, I) && J('Duplicate key "' + I + '"'), ee.test(I) === !0 ? j.protoAction === "error" ? J("Object contains forbidden prototype property") : j.protoAction === "ignore" ? D() : b[I] = D() : N.test(I) === !0 ? j.constructorAction === "error" ? J("Object contains forbidden constructor property") : j.constructorAction === "ignore" ? D() : b[I] = D() : b[I] = D(), z(), y === "}")
|
|
821
|
-
return A("}"), b;
|
|
822
|
-
A(","), z();
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
J("Bad object");
|
|
826
|
-
};
|
|
827
|
-
return D = function() {
|
|
828
|
-
switch (z(), y) {
|
|
829
|
-
case "{":
|
|
830
|
-
return x();
|
|
831
|
-
case "[":
|
|
832
|
-
return W();
|
|
833
|
-
case '"':
|
|
834
|
-
return $();
|
|
835
|
-
case "-":
|
|
836
|
-
return P();
|
|
1086
|
+
if (h === "~")
|
|
1087
|
+
return u = {
|
|
1088
|
+
path: F(t, h),
|
|
1089
|
+
value: n,
|
|
1090
|
+
parent: s,
|
|
1091
|
+
parentProperty: null
|
|
1092
|
+
}, this._handleCallback(u, a, "property"), u;
|
|
1093
|
+
if (h === "$")
|
|
1094
|
+
C(this._trace(b, e, t, null, null, a, c));
|
|
1095
|
+
else if (/^(-?\d*):(-?\d*):?(\d*)$/u.test(h))
|
|
1096
|
+
C(this._slice(h, b, e, t, s, n, a));
|
|
1097
|
+
else if (h.indexOf("?(") === 0) {
|
|
1098
|
+
if (this.currEval === !1)
|
|
1099
|
+
throw new Error("Eval [?(expr)] prevented in JSONPath expression.");
|
|
1100
|
+
const E = h.replace(/^\?\((.*?)\)$/u, "$1"), S = /@.?([^?]*)[['](\??\(.*?\))(?!.\)\])[\]']/gu.exec(E);
|
|
1101
|
+
S ? this._walk(e, (A) => {
|
|
1102
|
+
const T = [S[2]], $ = S[1] ? e[A][S[1]] : e[A];
|
|
1103
|
+
this._trace(T, $, t, s, n, a, !0).length > 0 && C(this._trace(b, e[A], F(t, A), e, A, a, !0));
|
|
1104
|
+
}) : this._walk(e, (A) => {
|
|
1105
|
+
this._eval(E, e[A], A, t, s, n) && C(this._trace(b, e[A], F(t, A), e, A, a, !0));
|
|
1106
|
+
});
|
|
1107
|
+
} else if (h[0] === "(") {
|
|
1108
|
+
if (this.currEval === !1)
|
|
1109
|
+
throw new Error("Eval [(expr)] prevented in JSONPath expression.");
|
|
1110
|
+
C(this._trace(se(this._eval(h, e, t.at(-1), t.slice(0, -1), s, n), b), e, t, s, n, a, c));
|
|
1111
|
+
} else if (h[0] === "@") {
|
|
1112
|
+
let E = !1;
|
|
1113
|
+
const S = h.slice(1, -2);
|
|
1114
|
+
switch (S) {
|
|
1115
|
+
case "scalar":
|
|
1116
|
+
(!e || !["object", "function"].includes(typeof e)) && (E = !0);
|
|
1117
|
+
break;
|
|
1118
|
+
case "boolean":
|
|
1119
|
+
case "string":
|
|
1120
|
+
case "undefined":
|
|
1121
|
+
case "function":
|
|
1122
|
+
typeof e === S && (E = !0);
|
|
1123
|
+
break;
|
|
1124
|
+
case "integer":
|
|
1125
|
+
Number.isFinite(e) && !(e % 1) && (E = !0);
|
|
1126
|
+
break;
|
|
1127
|
+
case "number":
|
|
1128
|
+
Number.isFinite(e) && (E = !0);
|
|
1129
|
+
break;
|
|
1130
|
+
case "nonFinite":
|
|
1131
|
+
typeof e == "number" && !Number.isFinite(e) && (E = !0);
|
|
1132
|
+
break;
|
|
1133
|
+
case "object":
|
|
1134
|
+
e && typeof e === S && (E = !0);
|
|
1135
|
+
break;
|
|
1136
|
+
case "array":
|
|
1137
|
+
Array.isArray(e) && (E = !0);
|
|
1138
|
+
break;
|
|
1139
|
+
case "other":
|
|
1140
|
+
E = this.currOtherTypeCallback(e, t, s, n);
|
|
1141
|
+
break;
|
|
1142
|
+
case "null":
|
|
1143
|
+
e === null && (E = !0);
|
|
1144
|
+
break;
|
|
1145
|
+
/* c8 ignore next 2 */
|
|
837
1146
|
default:
|
|
838
|
-
|
|
1147
|
+
throw new TypeError("Unknown value type " + S);
|
|
839
1148
|
}
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
1149
|
+
if (E)
|
|
1150
|
+
return u = {
|
|
1151
|
+
path: t,
|
|
1152
|
+
value: e,
|
|
1153
|
+
parent: s,
|
|
1154
|
+
parentProperty: n
|
|
1155
|
+
}, this._handleCallback(u, a, "value"), u;
|
|
1156
|
+
} else if (h[0] === "`" && e && Object.hasOwn(e, h.slice(1))) {
|
|
1157
|
+
const E = h.slice(1);
|
|
1158
|
+
C(this._trace(b, e[E], F(t, E), e, E, a, c, !0));
|
|
1159
|
+
} else if (h.includes(",")) {
|
|
1160
|
+
const E = h.split(",");
|
|
1161
|
+
for (const S of E)
|
|
1162
|
+
C(this._trace(se(S, b), e, t, s, n, a, !0));
|
|
1163
|
+
} else !d && e && Object.hasOwn(e, h) && C(this._trace(b, e[h], F(t, h), e, h, a, c, !0));
|
|
1164
|
+
}
|
|
1165
|
+
if (this._hasParentSelector)
|
|
1166
|
+
for (let E = 0; E < m.length; E++) {
|
|
1167
|
+
const S = m[E];
|
|
1168
|
+
if (S && S.isParentSelector) {
|
|
1169
|
+
const A = this._trace(S.expr, e, S.path, s, n, a, c);
|
|
1170
|
+
if (Array.isArray(A)) {
|
|
1171
|
+
m[E] = A[0];
|
|
1172
|
+
const T = A.length;
|
|
1173
|
+
for (let $ = 1; $ < T; $++)
|
|
1174
|
+
E++, m.splice(E, 0, A[$]);
|
|
1175
|
+
} else
|
|
1176
|
+
m[E] = A;
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
return m;
|
|
1180
|
+
};
|
|
1181
|
+
x.prototype._walk = function(r, e) {
|
|
1182
|
+
if (Array.isArray(r)) {
|
|
1183
|
+
const t = r.length;
|
|
1184
|
+
for (let s = 0; s < t; s++)
|
|
1185
|
+
e(s);
|
|
1186
|
+
} else r && typeof r == "object" && Object.keys(r).forEach((t) => {
|
|
1187
|
+
e(t);
|
|
1188
|
+
});
|
|
1189
|
+
};
|
|
1190
|
+
x.prototype._slice = function(r, e, t, s, n, a, c) {
|
|
1191
|
+
if (!Array.isArray(t))
|
|
1192
|
+
return;
|
|
1193
|
+
const d = t.length, u = r.split(":"), h = u[2] && Number.parseInt(u[2]) || 1;
|
|
1194
|
+
let b = u[0] && Number.parseInt(u[0]) || 0, m = u[1] && Number.parseInt(u[1]) || d;
|
|
1195
|
+
b = b < 0 ? Math.max(0, b + d) : Math.min(d, b), m = m < 0 ? Math.max(0, m + d) : Math.min(d, m);
|
|
1196
|
+
const C = [];
|
|
1197
|
+
for (let E = b; E < m; E += h)
|
|
1198
|
+
this._trace(se(E, e), t, s, n, a, c, !0).forEach((A) => {
|
|
1199
|
+
C.push(A);
|
|
1200
|
+
});
|
|
1201
|
+
return C;
|
|
1202
|
+
};
|
|
1203
|
+
x.prototype._eval = function(r, e, t, s, n, a) {
|
|
1204
|
+
this.currSandbox._$_parentProperty = a, this.currSandbox._$_parent = n, this.currSandbox._$_property = t, this.currSandbox._$_root = this.json, this.currSandbox._$_v = e;
|
|
1205
|
+
const c = r.includes("@path");
|
|
1206
|
+
c && (this.currSandbox._$_path = x.toPathString(s.concat([t])));
|
|
1207
|
+
const d = this.currEval + "Script:" + r;
|
|
1208
|
+
if (!x.cache[d]) {
|
|
1209
|
+
let u = r.replaceAll("@parentProperty", "_$_parentProperty").replaceAll("@parent", "_$_parent").replaceAll("@property", "_$_property").replaceAll("@root", "_$_root").replaceAll(/@([.\s)[])/gu, "_$_v$1");
|
|
1210
|
+
if (c && (u = u.replaceAll("@path", "_$_path")), this.currEval === "safe" || this.currEval === !0 || this.currEval === void 0)
|
|
1211
|
+
x.cache[d] = new this.safeVm.Script(u);
|
|
1212
|
+
else if (this.currEval === "native")
|
|
1213
|
+
x.cache[d] = new this.vm.Script(u);
|
|
1214
|
+
else if (typeof this.currEval == "function" && this.currEval.prototype && Object.hasOwn(this.currEval.prototype, "runInNewContext")) {
|
|
1215
|
+
const h = this.currEval;
|
|
1216
|
+
x.cache[d] = new h(u);
|
|
1217
|
+
} else if (typeof this.currEval == "function")
|
|
1218
|
+
x.cache[d] = {
|
|
1219
|
+
runInNewContext: (h) => this.currEval(u, h)
|
|
1220
|
+
};
|
|
1221
|
+
else
|
|
1222
|
+
throw new TypeError(`Unknown "eval" property "${this.currEval}"`);
|
|
1223
|
+
}
|
|
1224
|
+
try {
|
|
1225
|
+
return x.cache[d].runInNewContext(this.currSandbox);
|
|
1226
|
+
} catch (u) {
|
|
1227
|
+
if (this.ignoreEvalErrors)
|
|
1228
|
+
return !1;
|
|
1229
|
+
throw new Error("jsonPath: " + u.message + ": " + r);
|
|
1230
|
+
}
|
|
1231
|
+
};
|
|
1232
|
+
x.cache = {};
|
|
1233
|
+
x.toPathString = function(r) {
|
|
1234
|
+
const e = r, t = e.length;
|
|
1235
|
+
let s = "$";
|
|
1236
|
+
for (let n = 1; n < t; n++)
|
|
1237
|
+
/^(~|\^|@.*?\(\))$/u.test(e[n]) || (s += /^[0-9*]+$/u.test(e[n]) ? "[" + e[n] + "]" : "['" + e[n] + "']");
|
|
1238
|
+
return s;
|
|
1239
|
+
};
|
|
1240
|
+
x.toPointer = function(r) {
|
|
1241
|
+
const e = r, t = e.length;
|
|
1242
|
+
let s = "";
|
|
1243
|
+
for (let n = 1; n < t; n++)
|
|
1244
|
+
/^(~|\^|@.*?\(\))$/u.test(e[n]) || (s += "/" + e[n].toString().replaceAll("~", "~0").replaceAll("/", "~1"));
|
|
1245
|
+
return s;
|
|
1246
|
+
};
|
|
1247
|
+
x.toPathArray = function(r) {
|
|
1248
|
+
const {
|
|
1249
|
+
cache: e
|
|
1250
|
+
} = x;
|
|
1251
|
+
if (e[r])
|
|
1252
|
+
return e[r].concat();
|
|
1253
|
+
const t = [], n = r.replaceAll(/@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\(\)/gu, ";$&;").replaceAll(/[['](\??\(.*?\))[\]'](?!.\])/gu, function(a, c) {
|
|
1254
|
+
return "[#" + (t.push(c) - 1) + "]";
|
|
1255
|
+
}).replaceAll(/\[['"]([^'\]]*)['"]\]/gu, function(a, c) {
|
|
1256
|
+
return "['" + c.replaceAll(".", "%@%").replaceAll("~", "%%@@%%") + "']";
|
|
1257
|
+
}).replaceAll("~", ";~;").replaceAll(/['"]?\.['"]?(?![^[]*\])|\[['"]?/gu, ";").replaceAll("%@%", ".").replaceAll("%%@@%%", "~").replaceAll(/(?:;)?(\^+)(?:;)?/gu, function(a, c) {
|
|
1258
|
+
return ";" + c.split("").join(";") + ";";
|
|
1259
|
+
}).replaceAll(/;;;|;;/gu, ";..;").replaceAll(/;$|'?\]|'$/gu, "").split(";").map(function(a) {
|
|
1260
|
+
const c = a.match(/#(\d+)/u);
|
|
1261
|
+
return !c || !c[1] ? a : t[c[1]];
|
|
1262
|
+
});
|
|
1263
|
+
return e[r] = n, e[r].concat();
|
|
1264
|
+
};
|
|
1265
|
+
x.prototype.safeVm = {
|
|
1266
|
+
Script: we
|
|
1267
|
+
};
|
|
1268
|
+
const Se = function(r, e, t) {
|
|
1269
|
+
const s = r.length;
|
|
1270
|
+
for (let n = 0; n < s; n++) {
|
|
1271
|
+
const a = r[n];
|
|
1272
|
+
t(a) && e.push(r.splice(n--, 1)[0]);
|
|
1273
|
+
}
|
|
1274
|
+
};
|
|
1275
|
+
class Pe {
|
|
1276
|
+
/**
|
|
1277
|
+
* @param {string} expr Expression to evaluate
|
|
1278
|
+
*/
|
|
1279
|
+
constructor(e) {
|
|
1280
|
+
this.code = e;
|
|
1281
|
+
}
|
|
1282
|
+
/**
|
|
1283
|
+
* @param {object} context Object whose items will be added
|
|
1284
|
+
* to evaluation
|
|
1285
|
+
* @returns {EvaluatedResult} Result of evaluated code
|
|
1286
|
+
*/
|
|
1287
|
+
runInNewContext(e) {
|
|
1288
|
+
let t = this.code;
|
|
1289
|
+
const s = Object.keys(e), n = [];
|
|
1290
|
+
Se(s, n, (h) => typeof e[h] == "function");
|
|
1291
|
+
const a = s.map((h) => e[h]);
|
|
1292
|
+
t = n.reduce((h, b) => {
|
|
1293
|
+
let m = e[b].toString();
|
|
1294
|
+
return /function/u.test(m) || (m = "function " + m), "var " + b + "=" + m + ";" + h;
|
|
1295
|
+
}, "") + t, !/(['"])use strict\1/u.test(t) && !s.includes("arguments") && (t = "var arguments = undefined;" + t), t = t.replace(/;\s*$/u, "");
|
|
1296
|
+
const d = t.lastIndexOf(";"), u = d !== -1 ? t.slice(0, d + 1) + " return " + t.slice(d + 1) : " return " + t;
|
|
1297
|
+
return new Function(...s, u)(...a);
|
|
1298
|
+
}
|
|
863
1299
|
}
|
|
864
|
-
|
|
865
|
-
|
|
1300
|
+
x.prototype.vm = {
|
|
1301
|
+
Script: Pe
|
|
1302
|
+
};
|
|
1303
|
+
const Ne = { class: "json-node" }, De = {
|
|
866
1304
|
key: 0,
|
|
867
1305
|
class: "json-node__container"
|
|
868
|
-
},
|
|
1306
|
+
}, je = { class: "json-node__line" }, Ie = {
|
|
869
1307
|
key: 2,
|
|
870
1308
|
class: "json-node__colon"
|
|
871
|
-
},
|
|
1309
|
+
}, $e = ["title"], Te = {
|
|
872
1310
|
key: 3,
|
|
873
1311
|
class: "json-node__collapsed"
|
|
874
|
-
},
|
|
1312
|
+
}, Re = {
|
|
875
1313
|
key: 4,
|
|
876
1314
|
class: "json-node__comma"
|
|
877
|
-
},
|
|
1315
|
+
}, Ue = {
|
|
878
1316
|
key: 0,
|
|
879
1317
|
class: "json-node__children"
|
|
880
|
-
},
|
|
1318
|
+
}, Be = { class: "json-node__children-content" }, Le = { class: "json-node__line json-node__closing-bracket" }, Me = { class: "json-node__bracket" }, Fe = {
|
|
881
1319
|
key: 0,
|
|
882
1320
|
class: "json-node__comma"
|
|
883
|
-
},
|
|
1321
|
+
}, Ve = {
|
|
884
1322
|
key: 1,
|
|
885
1323
|
class: "json-node__primitive"
|
|
886
|
-
},
|
|
1324
|
+
}, Ke = {
|
|
887
1325
|
key: 2,
|
|
888
1326
|
class: "json-node__colon"
|
|
889
|
-
},
|
|
890
|
-
key:
|
|
1327
|
+
}, Xe = ["title"], He = {
|
|
1328
|
+
key: 0,
|
|
891
1329
|
class: "json-node__comma"
|
|
892
|
-
},
|
|
1330
|
+
}, Qe = /* @__PURE__ */ ae({
|
|
893
1331
|
name: "JsonNode",
|
|
894
1332
|
__name: "JsonNode",
|
|
895
1333
|
props: {
|
|
@@ -901,196 +1339,203 @@ const nt = /* @__PURE__ */ Ye(tt), rt = { class: "json-node" }, it = {
|
|
|
901
1339
|
isLast: { type: Boolean, default: !1 }
|
|
902
1340
|
},
|
|
903
1341
|
emits: ["update:value", "toggle-expand", "copy", "update:key"],
|
|
904
|
-
setup(
|
|
905
|
-
|
|
906
|
-
"
|
|
1342
|
+
setup(r, { emit: e }) {
|
|
1343
|
+
ue((f) => ({
|
|
1344
|
+
"1f6d5aa6": f.level
|
|
907
1345
|
}));
|
|
908
|
-
const
|
|
909
|
-
if (!/^-?\d+(\.\d+)?$/.test(
|
|
910
|
-
const
|
|
911
|
-
return !Number.isSafeInteger(
|
|
912
|
-
},
|
|
913
|
-
if (!
|
|
914
|
-
const
|
|
915
|
-
return
|
|
916
|
-
}),
|
|
917
|
-
const
|
|
918
|
-
return
|
|
919
|
-
}),
|
|
920
|
-
const
|
|
921
|
-
return
|
|
922
|
-
},
|
|
923
|
-
|
|
924
|
-
},
|
|
925
|
-
|
|
926
|
-
const
|
|
927
|
-
|
|
1346
|
+
const t = r, s = e, n = B(!1), a = B(!1), c = B(""), d = B(""), u = (f) => {
|
|
1347
|
+
if (!/^-?\d+(\.\d+)?$/.test(f)) return !1;
|
|
1348
|
+
const v = Number(f);
|
|
1349
|
+
return !Number.isSafeInteger(v) || f.length > 15;
|
|
1350
|
+
}, h = j(() => t.value !== null && typeof t.value == "object"), b = j(() => Array.isArray(t.value)), m = j(() => t.path ? t.path : t.keyName ? t.keyName : "root"), C = j(() => t.expanded.has(m.value)), E = j(() => t.keyName), S = j(() => b.value ? "[" : "{"), A = j(() => b.value ? "]" : "}"), T = j(() => {
|
|
1351
|
+
if (!t.value) return "";
|
|
1352
|
+
const v = Object.keys(t.value).length;
|
|
1353
|
+
return b.value ? v > 0 ? ` ${v} items ` : " " : v > 0 ? ` ${v} keys ` : " ";
|
|
1354
|
+
}), $ = j(() => {
|
|
1355
|
+
const f = typeof t.value;
|
|
1356
|
+
return t.value === null ? "json-node__value--null" : f === "boolean" ? "json-node__value--boolean" : f === "number" ? "json-node__value--number" : f === "string" ? u(t.value) ? "json-node__value--number" : "json-node__value--string" : "";
|
|
1357
|
+
}), q = j(() => a.value ? d.value : t.value === null ? "null" : typeof t.value == "boolean" || typeof t.value == "number" ? String(t.value) : typeof t.value == "string" ? u(t.value) ? t.value : `"${t.value}"` : String(t.value)), G = j(() => "Click to edit, double-click to copy"), K = (f) => t.level === 0 ? f : m.value ? `${m.value}.${f}` : f, z = (f) => {
|
|
1358
|
+
const v = Object.keys(t.value);
|
|
1359
|
+
return v.indexOf(f) === v.length - 1;
|
|
1360
|
+
}, Q = () => {
|
|
1361
|
+
s("toggle-expand", m.value);
|
|
1362
|
+
}, Y = () => {
|
|
1363
|
+
t.level !== 0 && (n.value = !0, c.value = t.keyName, ee(() => {
|
|
1364
|
+
const f = document.querySelectorAll(".json-node__key-input"), v = f[f.length - 1];
|
|
1365
|
+
v && (v.focus(), v.select());
|
|
928
1366
|
}));
|
|
929
|
-
},
|
|
930
|
-
|
|
931
|
-
const
|
|
932
|
-
|
|
1367
|
+
}, W = () => {
|
|
1368
|
+
h.value || (a.value = !0, typeof t.value == "string" && u(t.value) || typeof t.value == "string" ? d.value = t.value : d.value = String(t.value), ee(() => {
|
|
1369
|
+
const f = document.querySelectorAll(".json-node__value-input"), v = f[f.length - 1];
|
|
1370
|
+
v && (v.focus(), v.select());
|
|
933
1371
|
}));
|
|
934
|
-
},
|
|
935
|
-
if (
|
|
936
|
-
const
|
|
937
|
-
if (!
|
|
938
|
-
|
|
1372
|
+
}, V = () => {
|
|
1373
|
+
if (t.level === 0 || !n.value) return;
|
|
1374
|
+
const f = c.value.trim();
|
|
1375
|
+
if (!f) {
|
|
1376
|
+
M();
|
|
939
1377
|
return;
|
|
940
1378
|
}
|
|
941
|
-
if (
|
|
942
|
-
|
|
1379
|
+
if (f === t.keyName) {
|
|
1380
|
+
n.value = !1;
|
|
943
1381
|
return;
|
|
944
1382
|
}
|
|
945
|
-
|
|
946
|
-
},
|
|
1383
|
+
n.value = !1, s("update:key", m.value, f);
|
|
1384
|
+
}, Z = () => {
|
|
947
1385
|
try {
|
|
948
|
-
let
|
|
949
|
-
const
|
|
950
|
-
if (
|
|
951
|
-
|
|
952
|
-
else if (
|
|
953
|
-
|
|
954
|
-
else if (!isNaN(Number(
|
|
955
|
-
const
|
|
956
|
-
!Number.isSafeInteger(
|
|
1386
|
+
let f;
|
|
1387
|
+
const v = d.value.trim();
|
|
1388
|
+
if (v === "null")
|
|
1389
|
+
f = null;
|
|
1390
|
+
else if (v === "true" || v === "false")
|
|
1391
|
+
f = v === "true";
|
|
1392
|
+
else if (!isNaN(Number(v)) && v !== "") {
|
|
1393
|
+
const o = Number(v);
|
|
1394
|
+
!Number.isSafeInteger(o) || v.length > 15 ? f = v : f = o;
|
|
957
1395
|
} else
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
} catch (
|
|
961
|
-
console.error("Failed to parse value:",
|
|
1396
|
+
f = d.value;
|
|
1397
|
+
s("update:value", m.value, f), a.value = !1;
|
|
1398
|
+
} catch (f) {
|
|
1399
|
+
console.error("Failed to parse value:", f), a.value = !1;
|
|
962
1400
|
}
|
|
963
|
-
},
|
|
964
|
-
|
|
965
|
-
},
|
|
966
|
-
|
|
1401
|
+
}, M = () => {
|
|
1402
|
+
n.value = !1, c.value = t.keyName;
|
|
1403
|
+
}, J = () => {
|
|
1404
|
+
a.value = !1, typeof t.value == "string" && u(t.value) || typeof t.value == "string" ? d.value = t.value : d.value = String(t.value);
|
|
967
1405
|
};
|
|
968
|
-
return (
|
|
969
|
-
const
|
|
970
|
-
return
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
1406
|
+
return (f, v) => {
|
|
1407
|
+
const o = he("JsonNode", !0);
|
|
1408
|
+
return k(), w("div", Ne, [
|
|
1409
|
+
h.value ? (k(), w("div", De, [
|
|
1410
|
+
P("div", je, [
|
|
1411
|
+
f.keyName && !n.value ? (k(), w("span", {
|
|
974
1412
|
key: 0,
|
|
975
1413
|
class: "json-node__key",
|
|
976
|
-
onClick:
|
|
1414
|
+
onClick: Y,
|
|
977
1415
|
title: "Click to edit key"
|
|
978
|
-
}, ' "' +
|
|
979
|
-
|
|
1416
|
+
}, ' "' + U(E.value) + '" ', 1)) : N("", !0),
|
|
1417
|
+
f.keyName && n.value ? te((k(), w("input", {
|
|
980
1418
|
key: 1,
|
|
981
|
-
"onUpdate:modelValue":
|
|
1419
|
+
"onUpdate:modelValue": v[0] || (v[0] = (l) => c.value = l),
|
|
982
1420
|
onKeyup: [
|
|
983
|
-
|
|
984
|
-
|
|
1421
|
+
X(V, ["enter"]),
|
|
1422
|
+
X(M, ["escape"])
|
|
985
1423
|
],
|
|
986
|
-
onBlur:
|
|
1424
|
+
onBlur: V,
|
|
987
1425
|
class: "json-node__key-input"
|
|
988
1426
|
}, null, 544)), [
|
|
989
|
-
[
|
|
990
|
-
]) :
|
|
991
|
-
|
|
992
|
-
|
|
1427
|
+
[re, c.value]
|
|
1428
|
+
]) : N("", !0),
|
|
1429
|
+
f.keyName ? (k(), w("span", Ie, ": ")) : N("", !0),
|
|
1430
|
+
P("span", {
|
|
993
1431
|
class: "json-node__bracket json-node__bracket--clickable",
|
|
994
|
-
onClick:
|
|
995
|
-
title:
|
|
996
|
-
},
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1432
|
+
onClick: Q,
|
|
1433
|
+
title: C.value ? "Click to collapse" : "Click to expand"
|
|
1434
|
+
}, U(S.value), 9, $e),
|
|
1435
|
+
C.value ? N("", !0) : (k(), w("span", Te, [
|
|
1436
|
+
ie(U(T.value) + " ", 1),
|
|
1437
|
+
P("span", {
|
|
1000
1438
|
class: "json-node__bracket json-node__bracket--clickable",
|
|
1001
|
-
onClick:
|
|
1002
|
-
},
|
|
1439
|
+
onClick: Q
|
|
1440
|
+
}, U(A.value), 1)
|
|
1003
1441
|
])),
|
|
1004
|
-
!
|
|
1442
|
+
!C.value && !f.isLast ? (k(), w("span", Re, ",")) : N("", !0)
|
|
1005
1443
|
]),
|
|
1006
|
-
|
|
1007
|
-
(
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1444
|
+
C.value ? (k(), w("div", Ue, [
|
|
1445
|
+
P("div", Be, [
|
|
1446
|
+
(k(!0), w(de, null, fe(f.value, (l, g) => (k(), w("div", {
|
|
1447
|
+
key: g,
|
|
1448
|
+
class: "json-node__child"
|
|
1449
|
+
}, [
|
|
1450
|
+
le(o, {
|
|
1451
|
+
value: l,
|
|
1452
|
+
"key-name": b.value ? "" : String(g),
|
|
1453
|
+
level: f.level + 1,
|
|
1454
|
+
path: K(String(g)),
|
|
1455
|
+
expanded: f.expanded,
|
|
1456
|
+
"onUpdate:value": v[1] || (v[1] = (p, y) => f.$emit("update:value", p, y)),
|
|
1457
|
+
onToggleExpand: v[2] || (v[2] = (p) => f.$emit("toggle-expand", p)),
|
|
1458
|
+
onCopy: v[3] || (v[3] = (p) => f.$emit("copy", p)),
|
|
1459
|
+
"onUpdate:key": v[4] || (v[4] = (p, y) => f.$emit("update:key", p, y)),
|
|
1460
|
+
"is-last": z(String(g))
|
|
1461
|
+
}, null, 8, ["value", "key-name", "level", "path", "expanded", "is-last"])
|
|
1462
|
+
]))), 128))
|
|
1463
|
+
]),
|
|
1464
|
+
P("div", Le, [
|
|
1465
|
+
P("span", Me, U(A.value), 1),
|
|
1466
|
+
f.isLast ? N("", !0) : (k(), w("span", Fe, ","))
|
|
1027
1467
|
])
|
|
1028
|
-
])) :
|
|
1029
|
-
])) : (
|
|
1030
|
-
|
|
1468
|
+
])) : N("", !0)
|
|
1469
|
+
])) : (k(), w("div", Ve, [
|
|
1470
|
+
f.keyName && !n.value ? (k(), w("span", {
|
|
1031
1471
|
key: 0,
|
|
1032
1472
|
class: "json-node__key",
|
|
1033
|
-
onClick:
|
|
1473
|
+
onClick: Y,
|
|
1034
1474
|
title: "Click to edit key"
|
|
1035
|
-
}, ' "' +
|
|
1036
|
-
|
|
1475
|
+
}, ' "' + U(E.value) + '" ', 1)) : N("", !0),
|
|
1476
|
+
f.keyName && n.value ? te((k(), w("input", {
|
|
1037
1477
|
key: 1,
|
|
1038
|
-
"onUpdate:modelValue":
|
|
1478
|
+
"onUpdate:modelValue": v[5] || (v[5] = (l) => c.value = l),
|
|
1039
1479
|
onKeyup: [
|
|
1040
|
-
|
|
1041
|
-
|
|
1480
|
+
X(V, ["enter"]),
|
|
1481
|
+
X(M, ["escape"])
|
|
1042
1482
|
],
|
|
1043
|
-
onBlur:
|
|
1483
|
+
onBlur: V,
|
|
1044
1484
|
class: "json-node__key-input"
|
|
1045
1485
|
}, null, 544)), [
|
|
1046
|
-
[
|
|
1047
|
-
]) :
|
|
1048
|
-
|
|
1049
|
-
|
|
1486
|
+
[re, c.value]
|
|
1487
|
+
]) : N("", !0),
|
|
1488
|
+
f.keyName ? (k(), w("span", Ke, ": ")) : N("", !0),
|
|
1489
|
+
a.value ? N("", !0) : (k(), w("span", {
|
|
1050
1490
|
key: 3,
|
|
1051
|
-
class:
|
|
1052
|
-
onClick:
|
|
1053
|
-
onDblclick:
|
|
1054
|
-
title:
|
|
1055
|
-
},
|
|
1056
|
-
|
|
1491
|
+
class: pe(["json-node__value", $.value]),
|
|
1492
|
+
onClick: W,
|
|
1493
|
+
onDblclick: v[6] || (v[6] = (l) => f.$emit("copy", f.value)),
|
|
1494
|
+
title: G.value
|
|
1495
|
+
}, [
|
|
1496
|
+
ie(U(q.value), 1),
|
|
1497
|
+
f.isLast ? N("", !0) : (k(), w("span", He, ","))
|
|
1498
|
+
], 42, Xe)),
|
|
1499
|
+
a.value ? te((k(), w("input", {
|
|
1057
1500
|
key: 4,
|
|
1058
|
-
"onUpdate:modelValue":
|
|
1501
|
+
"onUpdate:modelValue": v[7] || (v[7] = (l) => d.value = l),
|
|
1059
1502
|
onKeyup: [
|
|
1060
|
-
|
|
1061
|
-
|
|
1503
|
+
X(Z, ["enter"]),
|
|
1504
|
+
X(J, ["escape"])
|
|
1062
1505
|
],
|
|
1063
|
-
onBlur:
|
|
1506
|
+
onBlur: Z,
|
|
1064
1507
|
class: "json-node__value-input"
|
|
1065
1508
|
}, null, 544)), [
|
|
1066
|
-
[
|
|
1067
|
-
]) :
|
|
1068
|
-
p.isLast ? se("", !0) : (K(), Y("span", yt, ","))
|
|
1509
|
+
[re, d.value]
|
|
1510
|
+
]) : N("", !0)
|
|
1069
1511
|
]))
|
|
1070
1512
|
]);
|
|
1071
1513
|
};
|
|
1072
1514
|
}
|
|
1073
|
-
}),
|
|
1074
|
-
const
|
|
1075
|
-
for (const [
|
|
1076
|
-
|
|
1077
|
-
return
|
|
1078
|
-
},
|
|
1515
|
+
}), ce = (r, e) => {
|
|
1516
|
+
const t = r.__vccOpts || r;
|
|
1517
|
+
for (const [s, n] of e)
|
|
1518
|
+
t[s] = n;
|
|
1519
|
+
return t;
|
|
1520
|
+
}, Ye = /* @__PURE__ */ ce(Qe, [["__scopeId", "data-v-fdfd4b42"]]), qe = { class: "json-format" }, Ge = {
|
|
1079
1521
|
key: 0,
|
|
1080
1522
|
class: "json-format__toolbar"
|
|
1081
|
-
},
|
|
1523
|
+
}, ze = { class: "json-format__actions" }, We = ["disabled"], Ze = ["disabled"], Je = ["disabled"], et = ["disabled"], tt = { class: "json-format__info" }, rt = {
|
|
1082
1524
|
key: 0,
|
|
1083
1525
|
class: "json-format__status json-format__status--success"
|
|
1084
|
-
},
|
|
1526
|
+
}, nt = {
|
|
1085
1527
|
key: 1,
|
|
1086
1528
|
class: "json-format__status json-format__status--error"
|
|
1087
|
-
},
|
|
1529
|
+
}, st = { class: "json-format__content" }, it = {
|
|
1088
1530
|
key: 0,
|
|
1089
1531
|
class: "json-format__error"
|
|
1090
|
-
},
|
|
1532
|
+
}, ot = {
|
|
1091
1533
|
key: 1,
|
|
1534
|
+
class: "json-format__error"
|
|
1535
|
+
}, at = {
|
|
1536
|
+
key: 2,
|
|
1092
1537
|
class: "json-format__viewer"
|
|
1093
|
-
},
|
|
1538
|
+
}, lt = /* @__PURE__ */ ae({
|
|
1094
1539
|
name: "JsonFormat",
|
|
1095
1540
|
__name: "index",
|
|
1096
1541
|
props: {
|
|
@@ -1099,217 +1544,281 @@ const nt = /* @__PURE__ */ Ye(tt), rt = { class: "json-node" }, it = {
|
|
|
1099
1544
|
maxDepth: { default: 10 },
|
|
1100
1545
|
showToolbar: { type: Boolean, default: !0 }
|
|
1101
1546
|
},
|
|
1102
|
-
emits: ["update:modelValue", "copy-success", "copy-error", "expand-all", "collapse-all"],
|
|
1103
|
-
setup(
|
|
1104
|
-
const
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
useNativeBigInt: !1
|
|
1108
|
-
}), O = G, j = N, C = ye(null), y = ye(""), T = ye(/* @__PURE__ */ new Set()), w = fe(() => y.value === ""), J = (g) => {
|
|
1109
|
-
if (!g.trim()) {
|
|
1110
|
-
C.value = null, y.value = "";
|
|
1547
|
+
emits: ["update:modelValue", "copy-success", "copy-error", "expand-all", "collapse-all", "compress"],
|
|
1548
|
+
setup(r, { expose: e, emit: t }) {
|
|
1549
|
+
const s = r, n = t, a = B(null), c = B(""), d = B(/* @__PURE__ */ new Set()), u = B(null), h = B(""), b = j(() => c.value === ""), m = j(() => h.value ? null : u.value !== null ? u.value : a.value), C = (o) => {
|
|
1550
|
+
if (!o.trim()) {
|
|
1551
|
+
a.value = null, c.value = "", u.value = null, h.value = "";
|
|
1111
1552
|
return;
|
|
1112
1553
|
}
|
|
1113
1554
|
try {
|
|
1114
|
-
|
|
1115
|
-
|
|
1555
|
+
let l = o;
|
|
1556
|
+
l = l.replace(/:\s*(\d{16,})\s*([,}])/g, ': "$1"$2'), l = l.replace(/:\s*(\d+\.\d*?0+)\s*([,}])/g, ': "$1"$2'), a.value = JSON.parse(l), c.value = "", u.value = null, h.value = "", ee(() => {
|
|
1557
|
+
m.value !== null && K();
|
|
1116
1558
|
});
|
|
1117
|
-
} catch (
|
|
1118
|
-
|
|
1559
|
+
} catch (l) {
|
|
1560
|
+
c.value = l instanceof Error ? l.message : "Unknown parsing error", a.value = null, u.value = null, h.value = "";
|
|
1561
|
+
}
|
|
1562
|
+
}, E = (o) => {
|
|
1563
|
+
if (!o || !o.expression.trim()) {
|
|
1564
|
+
S();
|
|
1565
|
+
return;
|
|
1119
1566
|
}
|
|
1567
|
+
if (!a.value) {
|
|
1568
|
+
h.value = "No valid JSON data to filter";
|
|
1569
|
+
return;
|
|
1570
|
+
}
|
|
1571
|
+
try {
|
|
1572
|
+
let l;
|
|
1573
|
+
if (o.type === "jsonpath")
|
|
1574
|
+
l = x({ path: o.expression, json: a.value }), l.length === 1 && o.expression.includes("$[") === !1 && !o.expression.endsWith("[*]") ? u.value = l[0] : u.value = l;
|
|
1575
|
+
else if (o.type === "js")
|
|
1576
|
+
l = new Function("data", `
|
|
1577
|
+
try {
|
|
1578
|
+
return ${o.expression};
|
|
1579
|
+
} catch (error) {
|
|
1580
|
+
throw new Error('JavaScript expression error: ' + error.message);
|
|
1581
|
+
}
|
|
1582
|
+
`)(a.value), u.value = l;
|
|
1583
|
+
else
|
|
1584
|
+
throw new Error(`Unsupported filter type: ${o.type}`);
|
|
1585
|
+
h.value = "", ee(() => {
|
|
1586
|
+
K();
|
|
1587
|
+
});
|
|
1588
|
+
} catch (l) {
|
|
1589
|
+
h.value = l instanceof Error ? l.message : "Filter execution error", u.value = null;
|
|
1590
|
+
}
|
|
1591
|
+
}, S = () => {
|
|
1592
|
+
u.value = null, h.value = "";
|
|
1120
1593
|
};
|
|
1121
|
-
|
|
1122
|
-
|
|
1594
|
+
ye(() => s.modelValue, (o) => {
|
|
1595
|
+
C(o);
|
|
1123
1596
|
}, { immediate: !0 });
|
|
1124
|
-
const A = (
|
|
1125
|
-
if (!
|
|
1597
|
+
const A = (o) => {
|
|
1598
|
+
if (!/^-?\d+(\.\d+)?$/.test(o)) return !1;
|
|
1599
|
+
const l = Number(o);
|
|
1600
|
+
return !Number.isSafeInteger(l) || o.length > 15;
|
|
1601
|
+
}, T = (o, l, g) => JSON.stringify(o, (p, y) => {
|
|
1602
|
+
if (typeof y == "string" && A(y))
|
|
1603
|
+
return `__BIG_NUMBER__${y}__BIG_NUMBER__`;
|
|
1604
|
+
if (typeof y == "string" && /^-?\d+(\.\d+)?$/.test(y)) {
|
|
1605
|
+
const _ = Number(y);
|
|
1606
|
+
if (Number.isSafeInteger(_) && _.toString() === y)
|
|
1607
|
+
return _;
|
|
1608
|
+
if (!Number.isNaN(_) && isFinite(_) && y.includes("."))
|
|
1609
|
+
return _.toString() === y ? _ : y;
|
|
1610
|
+
if (!Number.isNaN(_) && isFinite(_))
|
|
1611
|
+
return _;
|
|
1612
|
+
}
|
|
1613
|
+
return l && typeof l == "function" ? l(p, y) : y;
|
|
1614
|
+
}, g).replace(/"__BIG_NUMBER__(.+?)__BIG_NUMBER__"/g, "$1"), $ = (o, l) => {
|
|
1615
|
+
if (!s.readonly)
|
|
1126
1616
|
try {
|
|
1127
|
-
const
|
|
1128
|
-
|
|
1129
|
-
} catch (
|
|
1130
|
-
console.error("Failed to update JSON:",
|
|
1617
|
+
const g = q(a.value, o, l), p = T(g, null, 2);
|
|
1618
|
+
n("update:modelValue", p);
|
|
1619
|
+
} catch (g) {
|
|
1620
|
+
console.error("Failed to update JSON:", g);
|
|
1131
1621
|
}
|
|
1132
|
-
},
|
|
1133
|
-
if (!
|
|
1134
|
-
const
|
|
1135
|
-
let
|
|
1136
|
-
for (let
|
|
1137
|
-
const
|
|
1138
|
-
|
|
1622
|
+
}, q = (o, l, g) => {
|
|
1623
|
+
if (!l || l === "root") return g;
|
|
1624
|
+
const p = l.split("."), y = M(o, p.slice(0, -1));
|
|
1625
|
+
let _ = y;
|
|
1626
|
+
for (let I = 0; I < p.length - 1; I++) {
|
|
1627
|
+
const R = p[I];
|
|
1628
|
+
R !== "root" && (Array.isArray(_) ? _ = _[parseInt(R)] : _ = _[R]);
|
|
1139
1629
|
}
|
|
1140
|
-
const
|
|
1141
|
-
return
|
|
1142
|
-
},
|
|
1143
|
-
|
|
1144
|
-
},
|
|
1145
|
-
const
|
|
1146
|
-
|
|
1147
|
-
const
|
|
1148
|
-
|
|
1149
|
-
}) : Object.keys(
|
|
1150
|
-
const
|
|
1151
|
-
|
|
1630
|
+
const D = p[p.length - 1];
|
|
1631
|
+
return D === "root" ? g : (Array.isArray(_) ? _[parseInt(D)] = g : _[D] = g, y);
|
|
1632
|
+
}, G = (o) => {
|
|
1633
|
+
d.value.has(o) ? d.value.delete(o) : d.value.add(o);
|
|
1634
|
+
}, K = () => {
|
|
1635
|
+
const o = /* @__PURE__ */ new Set(), l = (g, p = "") => {
|
|
1636
|
+
g !== null && typeof g == "object" && (o.add(p || "root"), Array.isArray(g) ? g.forEach((y, _) => {
|
|
1637
|
+
const D = p ? `${p}.${_}` : `${_}`;
|
|
1638
|
+
l(y, D);
|
|
1639
|
+
}) : Object.keys(g).forEach((y) => {
|
|
1640
|
+
const _ = p ? `${p}.${y}` : y;
|
|
1641
|
+
l(g[y], _);
|
|
1152
1642
|
}));
|
|
1153
1643
|
};
|
|
1154
|
-
|
|
1155
|
-
},
|
|
1156
|
-
|
|
1157
|
-
},
|
|
1158
|
-
if (
|
|
1644
|
+
l(m.value), d.value = o, n("expand-all");
|
|
1645
|
+
}, z = () => {
|
|
1646
|
+
d.value = /* @__PURE__ */ new Set(["root"]), n("collapse-all");
|
|
1647
|
+
}, Q = async () => {
|
|
1648
|
+
if (b.value)
|
|
1159
1649
|
try {
|
|
1160
|
-
const
|
|
1161
|
-
await navigator.clipboard.writeText(
|
|
1162
|
-
} catch (
|
|
1163
|
-
console.error("Failed to copy JSON:",
|
|
1650
|
+
const o = m.value, g = JSON.stringify(o, null, 2).replace(/"(\d{16,})"/g, "$1");
|
|
1651
|
+
await navigator.clipboard.writeText(g), n("copy-success", g);
|
|
1652
|
+
} catch (o) {
|
|
1653
|
+
console.error("Failed to copy JSON:", o), n("copy-error", o instanceof Error ? o : new Error("Failed to copy JSON"));
|
|
1164
1654
|
}
|
|
1165
|
-
},
|
|
1166
|
-
if (
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1655
|
+
}, Y = () => {
|
|
1656
|
+
if (b.value)
|
|
1657
|
+
try {
|
|
1658
|
+
const o = m.value, l = T(o);
|
|
1659
|
+
n("update:modelValue", l), n("compress", l);
|
|
1660
|
+
} catch (o) {
|
|
1661
|
+
console.error("Failed to compress JSON:", o);
|
|
1662
|
+
}
|
|
1663
|
+
}, W = async (o) => {
|
|
1170
1664
|
try {
|
|
1171
|
-
let
|
|
1172
|
-
typeof
|
|
1173
|
-
} catch (
|
|
1174
|
-
console.error("Failed to copy value:",
|
|
1665
|
+
let l;
|
|
1666
|
+
typeof o == "string" && A(o) ? l = o : typeof o == "string" ? l = `"${o}"` : l = JSON.stringify(o), await navigator.clipboard.writeText(l);
|
|
1667
|
+
} catch (l) {
|
|
1668
|
+
console.error("Failed to copy value:", l);
|
|
1175
1669
|
}
|
|
1176
|
-
},
|
|
1177
|
-
if (!
|
|
1670
|
+
}, V = (o, l) => {
|
|
1671
|
+
if (!s.readonly)
|
|
1178
1672
|
try {
|
|
1179
|
-
const
|
|
1180
|
-
|
|
1181
|
-
} catch (
|
|
1182
|
-
console.error("Failed to rename key:",
|
|
1673
|
+
const g = Z(a.value, o, l), p = T(g, null, 2);
|
|
1674
|
+
n("update:modelValue", p), v(o, l);
|
|
1675
|
+
} catch (g) {
|
|
1676
|
+
console.error("Failed to rename key:", g);
|
|
1183
1677
|
}
|
|
1184
|
-
},
|
|
1185
|
-
if (!
|
|
1186
|
-
const
|
|
1187
|
-
if (
|
|
1188
|
-
const
|
|
1189
|
-
return
|
|
1678
|
+
}, Z = (o, l, g) => {
|
|
1679
|
+
if (!l || l === "root") return o;
|
|
1680
|
+
const p = l.split("."), y = M(o, p.slice(0, -1));
|
|
1681
|
+
if (p.length === 1) {
|
|
1682
|
+
const I = p[0];
|
|
1683
|
+
return y && typeof y == "object" && !Array.isArray(y) ? J(y, I, g) : y;
|
|
1190
1684
|
}
|
|
1191
|
-
let
|
|
1192
|
-
for (let
|
|
1193
|
-
const
|
|
1194
|
-
Array.isArray(
|
|
1685
|
+
let _ = y;
|
|
1686
|
+
for (let I = 0; I < p.length - 1; I++) {
|
|
1687
|
+
const R = p[I];
|
|
1688
|
+
Array.isArray(_) ? _ = _[parseInt(R)] : _ = _[R];
|
|
1195
1689
|
}
|
|
1196
|
-
const
|
|
1197
|
-
if (!Array.isArray(
|
|
1198
|
-
const
|
|
1199
|
-
|
|
1690
|
+
const D = p[p.length - 1];
|
|
1691
|
+
if (!Array.isArray(_) && _ && typeof _ == "object") {
|
|
1692
|
+
const I = J(_, D, g), R = p.slice(0, -1);
|
|
1693
|
+
R.length > 0 && f(y, R, I);
|
|
1200
1694
|
}
|
|
1201
|
-
return
|
|
1202
|
-
},
|
|
1203
|
-
if (
|
|
1204
|
-
if (Array.isArray(
|
|
1205
|
-
const
|
|
1206
|
-
return
|
|
1207
|
-
} else if (
|
|
1208
|
-
const
|
|
1209
|
-
return
|
|
1695
|
+
return y;
|
|
1696
|
+
}, M = (o, l) => {
|
|
1697
|
+
if (l.length === 0) return o;
|
|
1698
|
+
if (Array.isArray(o)) {
|
|
1699
|
+
const g = [...o], p = l[0], y = parseInt(p);
|
|
1700
|
+
return l.length === 1 || (g[y] = M(o[y], l.slice(1))), g;
|
|
1701
|
+
} else if (o && typeof o == "object") {
|
|
1702
|
+
const g = { ...o }, p = l[0];
|
|
1703
|
+
return l.length === 1 || (g[p] = M(o[p], l.slice(1))), g;
|
|
1210
1704
|
}
|
|
1211
|
-
return
|
|
1212
|
-
},
|
|
1213
|
-
if (!
|
|
1214
|
-
return
|
|
1215
|
-
const
|
|
1216
|
-
for (const
|
|
1217
|
-
|
|
1218
|
-
return
|
|
1219
|
-
},
|
|
1220
|
-
let
|
|
1221
|
-
for (let
|
|
1222
|
-
const
|
|
1223
|
-
Array.isArray(
|
|
1705
|
+
return o;
|
|
1706
|
+
}, J = (o, l, g) => {
|
|
1707
|
+
if (!o || typeof o != "object" || Array.isArray(o))
|
|
1708
|
+
return o;
|
|
1709
|
+
const p = Object.keys(o), y = {};
|
|
1710
|
+
for (const _ of p)
|
|
1711
|
+
_ === l ? y[g] = o[_] : y[_] = o[_];
|
|
1712
|
+
return y;
|
|
1713
|
+
}, f = (o, l, g) => {
|
|
1714
|
+
let p = o;
|
|
1715
|
+
for (let _ = 0; _ < l.length - 1; _++) {
|
|
1716
|
+
const D = l[_];
|
|
1717
|
+
Array.isArray(p) ? p = p[parseInt(D)] : p = p[D];
|
|
1224
1718
|
}
|
|
1225
|
-
const
|
|
1226
|
-
Array.isArray(
|
|
1227
|
-
},
|
|
1228
|
-
const
|
|
1229
|
-
|
|
1230
|
-
if (
|
|
1231
|
-
const
|
|
1232
|
-
|
|
1233
|
-
} else if (
|
|
1234
|
-
const
|
|
1235
|
-
|
|
1236
|
-
const
|
|
1237
|
-
|
|
1719
|
+
const y = l[l.length - 1];
|
|
1720
|
+
Array.isArray(p) ? p[parseInt(y)] = g : p[y] = g;
|
|
1721
|
+
}, v = (o, l) => {
|
|
1722
|
+
const g = /* @__PURE__ */ new Set();
|
|
1723
|
+
d.value.forEach((p) => {
|
|
1724
|
+
if (p === o) {
|
|
1725
|
+
const y = o.split(".");
|
|
1726
|
+
y[y.length - 1] = l, g.add(y.join("."));
|
|
1727
|
+
} else if (p.startsWith(o + ".")) {
|
|
1728
|
+
const y = o.split(".");
|
|
1729
|
+
y[y.length - 1] = l;
|
|
1730
|
+
const _ = y.join("."), D = p.substring(o.length);
|
|
1731
|
+
g.add(_ + D);
|
|
1238
1732
|
} else
|
|
1239
|
-
|
|
1240
|
-
}),
|
|
1733
|
+
g.add(p);
|
|
1734
|
+
}), d.value = g;
|
|
1241
1735
|
};
|
|
1242
|
-
return
|
|
1736
|
+
return e({
|
|
1243
1737
|
// 核心操作方法
|
|
1244
|
-
copyJson:
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1738
|
+
copyJson: Q,
|
|
1739
|
+
compressSource: Y,
|
|
1740
|
+
expandAll: K,
|
|
1741
|
+
collapseAll: z,
|
|
1742
|
+
toggleExpand: G,
|
|
1743
|
+
updateValue: $,
|
|
1744
|
+
updateKey: V,
|
|
1745
|
+
// Filter 相关方法
|
|
1746
|
+
filter: E,
|
|
1747
|
+
clearFilter: S,
|
|
1250
1748
|
// 状态访问方法
|
|
1251
|
-
isValidJson: () =>
|
|
1252
|
-
getParsedJson: () =>
|
|
1253
|
-
|
|
1254
|
-
|
|
1749
|
+
isValidJson: () => b.value,
|
|
1750
|
+
getParsedJson: () => a.value,
|
|
1751
|
+
getFilteredJson: () => u.value,
|
|
1752
|
+
getExpandedNodes: () => d.value,
|
|
1753
|
+
getParseError: () => c.value,
|
|
1754
|
+
getFilterError: () => h.value,
|
|
1255
1755
|
// 工具方法
|
|
1256
|
-
parseJson: (
|
|
1257
|
-
copyValue: (
|
|
1258
|
-
}), (
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1756
|
+
parseJson: (o) => C(o),
|
|
1757
|
+
copyValue: (o) => W(o)
|
|
1758
|
+
}), (o, l) => (k(), w("div", qe, [
|
|
1759
|
+
o.showToolbar ? (k(), w("div", Ge, [
|
|
1760
|
+
P("div", ze, [
|
|
1761
|
+
P("button", {
|
|
1262
1762
|
class: "json-format__btn json-format__btn--primary",
|
|
1263
|
-
onClick:
|
|
1264
|
-
disabled: !
|
|
1763
|
+
onClick: Q,
|
|
1764
|
+
disabled: !b.value,
|
|
1265
1765
|
title: "Copy JSON"
|
|
1266
|
-
}, " 📋 Copy ", 8,
|
|
1267
|
-
|
|
1766
|
+
}, " 📋 Copy ", 8, We),
|
|
1767
|
+
P("button", {
|
|
1268
1768
|
class: "json-format__btn json-format__btn--secondary",
|
|
1269
|
-
onClick:
|
|
1270
|
-
disabled: !
|
|
1769
|
+
onClick: K,
|
|
1770
|
+
disabled: !b.value,
|
|
1271
1771
|
title: "Expand All"
|
|
1272
|
-
}, " ⬇️ Expand All ", 8,
|
|
1273
|
-
|
|
1772
|
+
}, " ⬇️ Expand All ", 8, Ze),
|
|
1773
|
+
P("button", {
|
|
1274
1774
|
class: "json-format__btn json-format__btn--secondary",
|
|
1275
|
-
onClick:
|
|
1276
|
-
disabled: !
|
|
1775
|
+
onClick: z,
|
|
1776
|
+
disabled: !b.value,
|
|
1277
1777
|
title: "Collapse All"
|
|
1278
|
-
}, " ➡️ Collapse All ", 8,
|
|
1778
|
+
}, " ➡️ Collapse All ", 8, Je),
|
|
1779
|
+
P("button", {
|
|
1780
|
+
class: "json-format__btn json-format__btn--secondary",
|
|
1781
|
+
onClick: Y,
|
|
1782
|
+
disabled: !b.value,
|
|
1783
|
+
title: "Compress JSON"
|
|
1784
|
+
}, " 📦 Compress ", 8, et)
|
|
1279
1785
|
]),
|
|
1280
|
-
|
|
1281
|
-
|
|
1786
|
+
P("div", tt, [
|
|
1787
|
+
b.value ? (k(), w("span", rt, " ✅ Valid JSON ")) : (k(), w("span", nt, " ❌ Invalid JSON "))
|
|
1282
1788
|
])
|
|
1283
|
-
])) :
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1789
|
+
])) : N("", !0),
|
|
1790
|
+
P("div", st, [
|
|
1791
|
+
b.value ? h.value ? (k(), w("div", ot, [
|
|
1792
|
+
l[1] || (l[1] = P("h4", null, "Filter Error:", -1)),
|
|
1793
|
+
P("pre", null, U(h.value), 1)
|
|
1794
|
+
])) : (k(), w("div", at, [
|
|
1795
|
+
le(Ye, {
|
|
1796
|
+
value: m.value,
|
|
1288
1797
|
"key-name": "",
|
|
1289
1798
|
level: 0,
|
|
1290
|
-
expanded:
|
|
1799
|
+
expanded: d.value,
|
|
1291
1800
|
"is-last": !0,
|
|
1292
|
-
"onUpdate:value":
|
|
1293
|
-
onToggleExpand:
|
|
1294
|
-
onCopy:
|
|
1295
|
-
"onUpdate:key":
|
|
1801
|
+
"onUpdate:value": $,
|
|
1802
|
+
onToggleExpand: G,
|
|
1803
|
+
onCopy: W,
|
|
1804
|
+
"onUpdate:key": V
|
|
1296
1805
|
}, null, 8, ["value", "expanded"])
|
|
1297
|
-
])) : (
|
|
1298
|
-
|
|
1299
|
-
|
|
1806
|
+
])) : (k(), w("div", it, [
|
|
1807
|
+
l[0] || (l[0] = P("h4", null, "JSON Parse Error:", -1)),
|
|
1808
|
+
P("pre", null, U(c.value), 1)
|
|
1300
1809
|
]))
|
|
1301
1810
|
])
|
|
1302
1811
|
]));
|
|
1303
1812
|
}
|
|
1304
|
-
}),
|
|
1305
|
-
|
|
1306
|
-
const
|
|
1307
|
-
|
|
1813
|
+
}), ct = /* @__PURE__ */ ce(lt, [["__scopeId", "data-v-c212b38f"]]), ut = [ct], ht = (r) => {
|
|
1814
|
+
ut.forEach((e) => {
|
|
1815
|
+
const t = e.name || e.__name || "UnknownComponent";
|
|
1816
|
+
r.component(t, e);
|
|
1308
1817
|
});
|
|
1309
|
-
},
|
|
1310
|
-
install:
|
|
1818
|
+
}, pt = {
|
|
1819
|
+
install: ht
|
|
1311
1820
|
};
|
|
1312
1821
|
export {
|
|
1313
|
-
|
|
1314
|
-
|
|
1822
|
+
ct as JsonFormat,
|
|
1823
|
+
pt as default
|
|
1315
1824
|
};
|