lone-format 0.1.3 → 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 -6
- package/dist/lone-format.css +1 -1
- package/dist/lone-format.js +1673 -328
- package/dist/lone-format.umd.cjs +8 -1
- package/package.json +4 -2
- package/dist/components/JsonFormat/JsonNode.vue.d.ts +0 -65
- package/dist/components/JsonFormat/index.vue.d.ts +0 -57
- package/dist/components/JsonFormat/types.d.ts +0 -36
- package/dist/components/index.d.ts +0 -2
package/dist/lone-format.js
CHANGED
|
@@ -1,32 +1,1333 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
|
|
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
|
+
}
|
|
44
|
+
}
|
|
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 + '"');
|
|
320
|
+
}
|
|
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;
|
|
365
|
+
}
|
|
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
|
+
});
|
|
416
|
+
}
|
|
417
|
+
t = t.substr(0, --s);
|
|
418
|
+
}
|
|
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;
|
|
446
|
+
}
|
|
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);
|
|
582
|
+
}
|
|
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
|
+
}
|
|
617
|
+
}
|
|
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 :");
|
|
747
|
+
}
|
|
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;
|
|
770
|
+
}
|
|
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;
|
|
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
|
+
});
|
|
814
|
+
}
|
|
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);
|
|
821
|
+
});
|
|
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;
|
|
966
|
+
}
|
|
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
|
|
994
|
+
};
|
|
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;
|
|
1034
|
+
}
|
|
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
|
|
1085
|
+
};
|
|
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 */
|
|
1146
|
+
default:
|
|
1147
|
+
throw new TypeError("Unknown value type " + S);
|
|
1148
|
+
}
|
|
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
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
x.prototype.vm = {
|
|
1301
|
+
Script: Pe
|
|
1302
|
+
};
|
|
1303
|
+
const Ne = { class: "json-node" }, De = {
|
|
3
1304
|
key: 0,
|
|
4
1305
|
class: "json-node__container"
|
|
5
|
-
},
|
|
1306
|
+
}, je = { class: "json-node__line" }, Ie = {
|
|
6
1307
|
key: 2,
|
|
7
1308
|
class: "json-node__colon"
|
|
8
|
-
},
|
|
1309
|
+
}, $e = ["title"], Te = {
|
|
9
1310
|
key: 3,
|
|
10
1311
|
class: "json-node__collapsed"
|
|
11
|
-
},
|
|
1312
|
+
}, Re = {
|
|
12
1313
|
key: 4,
|
|
13
1314
|
class: "json-node__comma"
|
|
14
|
-
},
|
|
1315
|
+
}, Ue = {
|
|
15
1316
|
key: 0,
|
|
16
1317
|
class: "json-node__children"
|
|
17
|
-
},
|
|
1318
|
+
}, Be = { class: "json-node__children-content" }, Le = { class: "json-node__line json-node__closing-bracket" }, Me = { class: "json-node__bracket" }, Fe = {
|
|
18
1319
|
key: 0,
|
|
19
1320
|
class: "json-node__comma"
|
|
20
|
-
},
|
|
1321
|
+
}, Ve = {
|
|
21
1322
|
key: 1,
|
|
22
1323
|
class: "json-node__primitive"
|
|
23
|
-
},
|
|
1324
|
+
}, Ke = {
|
|
24
1325
|
key: 2,
|
|
25
1326
|
class: "json-node__colon"
|
|
26
|
-
},
|
|
27
|
-
key:
|
|
1327
|
+
}, Xe = ["title"], He = {
|
|
1328
|
+
key: 0,
|
|
28
1329
|
class: "json-node__comma"
|
|
29
|
-
},
|
|
1330
|
+
}, Qe = /* @__PURE__ */ ae({
|
|
30
1331
|
name: "JsonNode",
|
|
31
1332
|
__name: "JsonNode",
|
|
32
1333
|
props: {
|
|
@@ -38,198 +1339,203 @@ const se = { class: "json-node" }, oe = {
|
|
|
38
1339
|
isLast: { type: Boolean, default: !1 }
|
|
39
1340
|
},
|
|
40
1341
|
emits: ["update:value", "toggle-expand", "copy", "update:key"],
|
|
41
|
-
setup(
|
|
42
|
-
|
|
43
|
-
|
|
1342
|
+
setup(r, { emit: e }) {
|
|
1343
|
+
ue((f) => ({
|
|
1344
|
+
"1f6d5aa6": f.level
|
|
44
1345
|
}));
|
|
45
|
-
const
|
|
46
|
-
if (!/^-?\d+(\.\d+)?$/.test(
|
|
47
|
-
const
|
|
48
|
-
return !Number.isSafeInteger(
|
|
49
|
-
},
|
|
50
|
-
if (!
|
|
51
|
-
const
|
|
52
|
-
return
|
|
53
|
-
}),
|
|
54
|
-
const
|
|
55
|
-
return
|
|
56
|
-
}),
|
|
57
|
-
const
|
|
58
|
-
return
|
|
59
|
-
},
|
|
60
|
-
|
|
61
|
-
},
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
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());
|
|
65
1366
|
}));
|
|
66
|
-
},
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
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());
|
|
70
1371
|
}));
|
|
71
1372
|
}, V = () => {
|
|
72
|
-
if (
|
|
73
|
-
const
|
|
74
|
-
if (!
|
|
75
|
-
|
|
1373
|
+
if (t.level === 0 || !n.value) return;
|
|
1374
|
+
const f = c.value.trim();
|
|
1375
|
+
if (!f) {
|
|
1376
|
+
M();
|
|
76
1377
|
return;
|
|
77
1378
|
}
|
|
78
|
-
if (
|
|
79
|
-
|
|
1379
|
+
if (f === t.keyName) {
|
|
1380
|
+
n.value = !1;
|
|
80
1381
|
return;
|
|
81
1382
|
}
|
|
82
|
-
|
|
83
|
-
},
|
|
1383
|
+
n.value = !1, s("update:key", m.value, f);
|
|
1384
|
+
}, Z = () => {
|
|
84
1385
|
try {
|
|
85
|
-
let
|
|
86
|
-
const
|
|
87
|
-
if (
|
|
88
|
-
|
|
89
|
-
else if (
|
|
90
|
-
|
|
91
|
-
else if (!isNaN(Number(
|
|
92
|
-
const
|
|
93
|
-
!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;
|
|
94
1395
|
} else
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
} catch (
|
|
98
|
-
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;
|
|
99
1400
|
}
|
|
100
|
-
},
|
|
101
|
-
|
|
102
|
-
},
|
|
103
|
-
|
|
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);
|
|
104
1405
|
};
|
|
105
|
-
return (
|
|
106
|
-
const
|
|
107
|
-
return
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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", {
|
|
111
1412
|
key: 0,
|
|
112
1413
|
class: "json-node__key",
|
|
113
|
-
onClick:
|
|
1414
|
+
onClick: Y,
|
|
114
1415
|
title: "Click to edit key"
|
|
115
|
-
}, ' "' +
|
|
116
|
-
|
|
1416
|
+
}, ' "' + U(E.value) + '" ', 1)) : N("", !0),
|
|
1417
|
+
f.keyName && n.value ? te((k(), w("input", {
|
|
117
1418
|
key: 1,
|
|
118
|
-
"onUpdate:modelValue":
|
|
1419
|
+
"onUpdate:modelValue": v[0] || (v[0] = (l) => c.value = l),
|
|
119
1420
|
onKeyup: [
|
|
120
|
-
|
|
121
|
-
|
|
1421
|
+
X(V, ["enter"]),
|
|
1422
|
+
X(M, ["escape"])
|
|
122
1423
|
],
|
|
123
1424
|
onBlur: V,
|
|
124
1425
|
class: "json-node__key-input"
|
|
125
1426
|
}, null, 544)), [
|
|
126
|
-
[
|
|
127
|
-
]) :
|
|
128
|
-
|
|
129
|
-
|
|
1427
|
+
[re, c.value]
|
|
1428
|
+
]) : N("", !0),
|
|
1429
|
+
f.keyName ? (k(), w("span", Ie, ": ")) : N("", !0),
|
|
1430
|
+
P("span", {
|
|
130
1431
|
class: "json-node__bracket json-node__bracket--clickable",
|
|
131
|
-
onClick:
|
|
132
|
-
title:
|
|
133
|
-
},
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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", {
|
|
137
1438
|
class: "json-node__bracket json-node__bracket--clickable",
|
|
138
|
-
onClick:
|
|
139
|
-
},
|
|
1439
|
+
onClick: Q
|
|
1440
|
+
}, U(A.value), 1)
|
|
140
1441
|
])),
|
|
141
|
-
!
|
|
1442
|
+
!C.value && !f.isLast ? (k(), w("span", Re, ",")) : N("", !0)
|
|
142
1443
|
]),
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
(
|
|
146
|
-
key:
|
|
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,
|
|
147
1448
|
class: "json-node__child"
|
|
148
1449
|
}, [
|
|
149
|
-
|
|
150
|
-
value:
|
|
151
|
-
"key-name":
|
|
152
|
-
level:
|
|
153
|
-
path:
|
|
154
|
-
expanded:
|
|
155
|
-
"onUpdate:value":
|
|
156
|
-
onToggleExpand:
|
|
157
|
-
onCopy:
|
|
158
|
-
"onUpdate:key":
|
|
159
|
-
"is-last":
|
|
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))
|
|
160
1461
|
}, null, 8, ["value", "key-name", "level", "path", "expanded", "is-last"])
|
|
161
1462
|
]))), 128))
|
|
162
1463
|
]),
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
1464
|
+
P("div", Le, [
|
|
1465
|
+
P("span", Me, U(A.value), 1),
|
|
1466
|
+
f.isLast ? N("", !0) : (k(), w("span", Fe, ","))
|
|
166
1467
|
])
|
|
167
|
-
])) :
|
|
168
|
-
])) : (
|
|
169
|
-
|
|
1468
|
+
])) : N("", !0)
|
|
1469
|
+
])) : (k(), w("div", Ve, [
|
|
1470
|
+
f.keyName && !n.value ? (k(), w("span", {
|
|
170
1471
|
key: 0,
|
|
171
1472
|
class: "json-node__key",
|
|
172
|
-
onClick:
|
|
1473
|
+
onClick: Y,
|
|
173
1474
|
title: "Click to edit key"
|
|
174
|
-
}, ' "' +
|
|
175
|
-
|
|
1475
|
+
}, ' "' + U(E.value) + '" ', 1)) : N("", !0),
|
|
1476
|
+
f.keyName && n.value ? te((k(), w("input", {
|
|
176
1477
|
key: 1,
|
|
177
|
-
"onUpdate:modelValue":
|
|
1478
|
+
"onUpdate:modelValue": v[5] || (v[5] = (l) => c.value = l),
|
|
178
1479
|
onKeyup: [
|
|
179
|
-
|
|
180
|
-
|
|
1480
|
+
X(V, ["enter"]),
|
|
1481
|
+
X(M, ["escape"])
|
|
181
1482
|
],
|
|
182
1483
|
onBlur: V,
|
|
183
1484
|
class: "json-node__key-input"
|
|
184
1485
|
}, null, 544)), [
|
|
185
|
-
[
|
|
186
|
-
]) :
|
|
187
|
-
|
|
188
|
-
|
|
1486
|
+
[re, c.value]
|
|
1487
|
+
]) : N("", !0),
|
|
1488
|
+
f.keyName ? (k(), w("span", Ke, ": ")) : N("", !0),
|
|
1489
|
+
a.value ? N("", !0) : (k(), w("span", {
|
|
189
1490
|
key: 3,
|
|
190
|
-
class:
|
|
191
|
-
onClick:
|
|
192
|
-
onDblclick:
|
|
193
|
-
title:
|
|
194
|
-
},
|
|
195
|
-
|
|
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", {
|
|
196
1500
|
key: 4,
|
|
197
|
-
"onUpdate:modelValue":
|
|
1501
|
+
"onUpdate:modelValue": v[7] || (v[7] = (l) => d.value = l),
|
|
198
1502
|
onKeyup: [
|
|
199
|
-
|
|
200
|
-
|
|
1503
|
+
X(Z, ["enter"]),
|
|
1504
|
+
X(J, ["escape"])
|
|
201
1505
|
],
|
|
202
|
-
onBlur:
|
|
1506
|
+
onBlur: Z,
|
|
203
1507
|
class: "json-node__value-input"
|
|
204
1508
|
}, null, 544)), [
|
|
205
|
-
[
|
|
206
|
-
]) :
|
|
207
|
-
e.isLast ? k("", !0) : (u(), a("span", ke, ","))
|
|
1509
|
+
[re, d.value]
|
|
1510
|
+
]) : N("", !0)
|
|
208
1511
|
]))
|
|
209
1512
|
]);
|
|
210
1513
|
};
|
|
211
1514
|
}
|
|
212
|
-
}),
|
|
213
|
-
const
|
|
214
|
-
for (const [
|
|
215
|
-
|
|
216
|
-
return
|
|
217
|
-
},
|
|
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 = {
|
|
218
1521
|
key: 0,
|
|
219
1522
|
class: "json-format__toolbar"
|
|
220
|
-
},
|
|
1523
|
+
}, ze = { class: "json-format__actions" }, We = ["disabled"], Ze = ["disabled"], Je = ["disabled"], et = ["disabled"], tt = { class: "json-format__info" }, rt = {
|
|
221
1524
|
key: 0,
|
|
222
1525
|
class: "json-format__status json-format__status--success"
|
|
223
|
-
},
|
|
1526
|
+
}, nt = {
|
|
224
1527
|
key: 1,
|
|
225
1528
|
class: "json-format__status json-format__status--error"
|
|
226
|
-
},
|
|
1529
|
+
}, st = { class: "json-format__content" }, it = {
|
|
227
1530
|
key: 0,
|
|
228
1531
|
class: "json-format__error"
|
|
229
|
-
},
|
|
1532
|
+
}, ot = {
|
|
230
1533
|
key: 1,
|
|
1534
|
+
class: "json-format__error"
|
|
1535
|
+
}, at = {
|
|
1536
|
+
key: 2,
|
|
231
1537
|
class: "json-format__viewer"
|
|
232
|
-
},
|
|
1538
|
+
}, lt = /* @__PURE__ */ ae({
|
|
233
1539
|
name: "JsonFormat",
|
|
234
1540
|
__name: "index",
|
|
235
1541
|
props: {
|
|
@@ -239,241 +1545,280 @@ const se = { class: "json-node" }, oe = {
|
|
|
239
1545
|
showToolbar: { type: Boolean, default: !0 }
|
|
240
1546
|
},
|
|
241
1547
|
emits: ["update:modelValue", "copy-success", "copy-error", "expand-all", "collapse-all", "compress"],
|
|
242
|
-
setup(
|
|
243
|
-
const
|
|
244
|
-
if (!
|
|
245
|
-
|
|
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 = "";
|
|
1552
|
+
return;
|
|
1553
|
+
}
|
|
1554
|
+
try {
|
|
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();
|
|
1558
|
+
});
|
|
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;
|
|
1566
|
+
}
|
|
1567
|
+
if (!a.value) {
|
|
1568
|
+
h.value = "No valid JSON data to filter";
|
|
246
1569
|
return;
|
|
247
1570
|
}
|
|
248
1571
|
try {
|
|
249
|
-
let
|
|
250
|
-
|
|
251
|
-
|
|
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();
|
|
252
1587
|
});
|
|
253
|
-
} catch (
|
|
254
|
-
|
|
1588
|
+
} catch (l) {
|
|
1589
|
+
h.value = l instanceof Error ? l.message : "Filter execution error", u.value = null;
|
|
255
1590
|
}
|
|
1591
|
+
}, S = () => {
|
|
1592
|
+
u.value = null, h.value = "";
|
|
256
1593
|
};
|
|
257
|
-
|
|
258
|
-
|
|
1594
|
+
ye(() => s.modelValue, (o) => {
|
|
1595
|
+
C(o);
|
|
259
1596
|
}, { immediate: !0 });
|
|
260
|
-
const
|
|
261
|
-
if (!/^-?\d+(\.\d+)?$/.test(
|
|
262
|
-
const
|
|
263
|
-
return !Number.isSafeInteger(
|
|
264
|
-
},
|
|
265
|
-
if (typeof
|
|
266
|
-
return `__BIG_NUMBER__${
|
|
267
|
-
if (typeof
|
|
268
|
-
const
|
|
269
|
-
if (Number.isSafeInteger(
|
|
270
|
-
return
|
|
271
|
-
if (!Number.isNaN(
|
|
272
|
-
return
|
|
273
|
-
if (!Number.isNaN(
|
|
274
|
-
return
|
|
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 _;
|
|
275
1612
|
}
|
|
276
|
-
return
|
|
277
|
-
},
|
|
278
|
-
if (!
|
|
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)
|
|
279
1616
|
try {
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
} catch (
|
|
283
|
-
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);
|
|
284
1621
|
}
|
|
285
|
-
},
|
|
286
|
-
if (!
|
|
287
|
-
const
|
|
288
|
-
let
|
|
289
|
-
for (let
|
|
290
|
-
const
|
|
291
|
-
|
|
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]);
|
|
292
1629
|
}
|
|
293
|
-
const
|
|
294
|
-
return
|
|
295
|
-
},
|
|
296
|
-
|
|
297
|
-
},
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
const
|
|
301
|
-
|
|
302
|
-
}) : Object.keys(
|
|
303
|
-
const
|
|
304
|
-
|
|
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], _);
|
|
305
1642
|
}));
|
|
306
1643
|
};
|
|
307
|
-
|
|
308
|
-
},
|
|
309
|
-
|
|
310
|
-
},
|
|
311
|
-
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)
|
|
312
1649
|
try {
|
|
313
|
-
const
|
|
314
|
-
await navigator.clipboard.writeText(
|
|
315
|
-
} catch (
|
|
316
|
-
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"));
|
|
317
1654
|
}
|
|
318
|
-
},
|
|
319
|
-
if (
|
|
1655
|
+
}, Y = () => {
|
|
1656
|
+
if (b.value)
|
|
320
1657
|
try {
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
} catch (
|
|
324
|
-
console.error("Failed to compress JSON:",
|
|
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);
|
|
325
1662
|
}
|
|
326
|
-
},
|
|
1663
|
+
}, W = async (o) => {
|
|
327
1664
|
try {
|
|
328
|
-
let
|
|
329
|
-
typeof
|
|
330
|
-
} catch (
|
|
331
|
-
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);
|
|
332
1669
|
}
|
|
333
|
-
},
|
|
334
|
-
if (!
|
|
1670
|
+
}, V = (o, l) => {
|
|
1671
|
+
if (!s.readonly)
|
|
335
1672
|
try {
|
|
336
|
-
const
|
|
337
|
-
|
|
338
|
-
} catch (
|
|
339
|
-
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);
|
|
340
1677
|
}
|
|
341
|
-
},
|
|
342
|
-
if (!
|
|
343
|
-
const
|
|
344
|
-
if (
|
|
345
|
-
const
|
|
346
|
-
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;
|
|
347
1684
|
}
|
|
348
|
-
let
|
|
349
|
-
for (let
|
|
350
|
-
const
|
|
351
|
-
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];
|
|
352
1689
|
}
|
|
353
|
-
const
|
|
354
|
-
if (!Array.isArray(
|
|
355
|
-
const
|
|
356
|
-
|
|
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);
|
|
357
1694
|
}
|
|
358
|
-
return
|
|
359
|
-
},
|
|
360
|
-
if (
|
|
361
|
-
if (Array.isArray(
|
|
362
|
-
const
|
|
363
|
-
return
|
|
364
|
-
} else if (
|
|
365
|
-
const
|
|
366
|
-
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;
|
|
367
1704
|
}
|
|
368
|
-
return
|
|
369
|
-
},
|
|
370
|
-
if (!
|
|
371
|
-
return
|
|
372
|
-
const
|
|
373
|
-
for (const
|
|
374
|
-
|
|
375
|
-
return
|
|
376
|
-
},
|
|
377
|
-
let
|
|
378
|
-
for (let
|
|
379
|
-
const
|
|
380
|
-
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];
|
|
381
1718
|
}
|
|
382
|
-
const
|
|
383
|
-
Array.isArray(
|
|
384
|
-
},
|
|
385
|
-
const
|
|
386
|
-
|
|
387
|
-
if (
|
|
388
|
-
const
|
|
389
|
-
|
|
390
|
-
} else if (
|
|
391
|
-
const
|
|
392
|
-
|
|
393
|
-
const
|
|
394
|
-
|
|
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);
|
|
395
1732
|
} else
|
|
396
|
-
|
|
397
|
-
}),
|
|
1733
|
+
g.add(p);
|
|
1734
|
+
}), d.value = g;
|
|
398
1735
|
};
|
|
399
|
-
return
|
|
1736
|
+
return e({
|
|
400
1737
|
// 核心操作方法
|
|
401
|
-
copyJson:
|
|
402
|
-
compressSource:
|
|
403
|
-
expandAll:
|
|
404
|
-
collapseAll:
|
|
405
|
-
toggleExpand:
|
|
406
|
-
updateValue:
|
|
407
|
-
updateKey:
|
|
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,
|
|
408
1748
|
// 状态访问方法
|
|
409
|
-
isValidJson: () =>
|
|
410
|
-
getParsedJson: () =>
|
|
411
|
-
|
|
412
|
-
|
|
1749
|
+
isValidJson: () => b.value,
|
|
1750
|
+
getParsedJson: () => a.value,
|
|
1751
|
+
getFilteredJson: () => u.value,
|
|
1752
|
+
getExpandedNodes: () => d.value,
|
|
1753
|
+
getParseError: () => c.value,
|
|
1754
|
+
getFilterError: () => h.value,
|
|
413
1755
|
// 工具方法
|
|
414
|
-
parseJson: (
|
|
415
|
-
copyValue: (
|
|
416
|
-
}), (
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
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", {
|
|
420
1762
|
class: "json-format__btn json-format__btn--primary",
|
|
421
|
-
onClick:
|
|
422
|
-
disabled: !
|
|
1763
|
+
onClick: Q,
|
|
1764
|
+
disabled: !b.value,
|
|
423
1765
|
title: "Copy JSON"
|
|
424
|
-
}, " 📋 Copy ", 8,
|
|
425
|
-
|
|
1766
|
+
}, " 📋 Copy ", 8, We),
|
|
1767
|
+
P("button", {
|
|
426
1768
|
class: "json-format__btn json-format__btn--secondary",
|
|
427
|
-
onClick:
|
|
428
|
-
disabled: !
|
|
1769
|
+
onClick: K,
|
|
1770
|
+
disabled: !b.value,
|
|
429
1771
|
title: "Expand All"
|
|
430
|
-
}, " ⬇️ Expand All ", 8,
|
|
431
|
-
|
|
1772
|
+
}, " ⬇️ Expand All ", 8, Ze),
|
|
1773
|
+
P("button", {
|
|
432
1774
|
class: "json-format__btn json-format__btn--secondary",
|
|
433
|
-
onClick:
|
|
434
|
-
disabled: !
|
|
1775
|
+
onClick: z,
|
|
1776
|
+
disabled: !b.value,
|
|
435
1777
|
title: "Collapse All"
|
|
436
1778
|
}, " ➡️ Collapse All ", 8, Je),
|
|
437
|
-
|
|
1779
|
+
P("button", {
|
|
438
1780
|
class: "json-format__btn json-format__btn--secondary",
|
|
439
|
-
onClick:
|
|
440
|
-
disabled: !
|
|
1781
|
+
onClick: Y,
|
|
1782
|
+
disabled: !b.value,
|
|
441
1783
|
title: "Compress JSON"
|
|
442
|
-
}, " 📦 Compress ", 8,
|
|
1784
|
+
}, " 📦 Compress ", 8, et)
|
|
443
1785
|
]),
|
|
444
|
-
|
|
445
|
-
|
|
1786
|
+
P("div", tt, [
|
|
1787
|
+
b.value ? (k(), w("span", rt, " ✅ Valid JSON ")) : (k(), w("span", nt, " ❌ Invalid JSON "))
|
|
446
1788
|
])
|
|
447
|
-
])) :
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
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,
|
|
452
1797
|
"key-name": "",
|
|
453
1798
|
level: 0,
|
|
454
|
-
expanded:
|
|
1799
|
+
expanded: d.value,
|
|
455
1800
|
"is-last": !0,
|
|
456
|
-
"onUpdate:value":
|
|
457
|
-
onToggleExpand:
|
|
458
|
-
onCopy:
|
|
459
|
-
"onUpdate:key":
|
|
1801
|
+
"onUpdate:value": $,
|
|
1802
|
+
onToggleExpand: G,
|
|
1803
|
+
onCopy: W,
|
|
1804
|
+
"onUpdate:key": V
|
|
460
1805
|
}, null, 8, ["value", "expanded"])
|
|
461
|
-
])) : (
|
|
462
|
-
|
|
463
|
-
|
|
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)
|
|
464
1809
|
]))
|
|
465
1810
|
])
|
|
466
1811
|
]));
|
|
467
1812
|
}
|
|
468
|
-
}),
|
|
469
|
-
|
|
470
|
-
const
|
|
471
|
-
|
|
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);
|
|
472
1817
|
});
|
|
473
|
-
},
|
|
474
|
-
install:
|
|
1818
|
+
}, pt = {
|
|
1819
|
+
install: ht
|
|
475
1820
|
};
|
|
476
1821
|
export {
|
|
477
|
-
|
|
478
|
-
|
|
1822
|
+
ct as JsonFormat,
|
|
1823
|
+
pt as default
|
|
479
1824
|
};
|