lone-format 0.1.3 → 0.1.5
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 +1871 -326
- 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 le, useCssVars as ce, ref as R, computed as T, resolveComponent as pe, createElementBlock as A, openBlock as w, createElementVNode as P, createCommentVNode as N, withDirectives as re, toDisplayString as $, withKeys as X, vModelText as ne, createTextVNode as ie, Fragment as ye, renderList as be, createVNode as ue, normalizeClass as de, nextTick as ee, watch as ge } from "vue";
|
|
2
|
+
class Ee {
|
|
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, o) {
|
|
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][o ? "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(o) {
|
|
41
|
+
o.call(t && t.context ? t.context : t, t);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
class me {
|
|
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), o = 0; o < e; o++)
|
|
64
|
+
t[o] = arguments[o];
|
|
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 s {
|
|
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" + s.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 s.max_unop_len = Math.max(e.length, s.max_unop_len), s.unary_ops[e] = 1, s;
|
|
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, o) {
|
|
102
|
+
return s.max_binop_len = Math.max(e.length, s.max_binop_len), s.binary_ops[e] = t, o ? s.right_associative.add(e) : s.right_associative.delete(e), s;
|
|
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 s.additional_identifier_chars.add(e), s;
|
|
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 s.literals[e] = t, s;
|
|
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 s.unary_ops[e], e.length === s.max_unop_len && (s.max_unop_len = s.getMaxKeyLen(s.unary_ops)), s;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* @method removeAllUnaryOps
|
|
131
|
+
* @returns {Jsep}
|
|
132
|
+
*/
|
|
133
|
+
static removeAllUnaryOps() {
|
|
134
|
+
return s.unary_ops = {}, s.max_unop_len = 0, s;
|
|
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 s.additional_identifier_chars.delete(e), s;
|
|
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 s.binary_ops[e], e.length === s.max_binop_len && (s.max_binop_len = s.getMaxKeyLen(s.binary_ops)), s.right_associative.delete(e), s;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* @method removeAllBinaryOps
|
|
154
|
+
* @returns {Jsep}
|
|
155
|
+
*/
|
|
156
|
+
static removeAllBinaryOps() {
|
|
157
|
+
return s.binary_ops = {}, s.max_binop_len = 0, s;
|
|
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 s.literals[e], s;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* @method removeAllLiterals
|
|
169
|
+
* @returns {Jsep}
|
|
170
|
+
*/
|
|
171
|
+
static removeAllLiterals() {
|
|
172
|
+
return s.literals = {}, s;
|
|
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 s(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 s.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 && !s.binary_ops[String.fromCharCode(e)] || // any non-ASCII that is not an operator
|
|
234
|
+
s.additional_identifier_chars.has(String.fromCharCode(e));
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* @param {number} ch
|
|
238
|
+
* @returns {boolean}
|
|
239
|
+
*/
|
|
240
|
+
static isIdentifierPart(e) {
|
|
241
|
+
return s.isIdentifierStart(e) || s.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 (s.hooks[e]) {
|
|
260
|
+
const o = {
|
|
261
|
+
context: this,
|
|
262
|
+
node: t
|
|
263
|
+
};
|
|
264
|
+
return s.hooks.run(e, o), o.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 (s.hooks[e]) {
|
|
275
|
+
const t = {
|
|
276
|
+
context: this
|
|
277
|
+
};
|
|
278
|
+
return s.hooks[e].find(function(o) {
|
|
279
|
+
return o.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 === s.SPACE_CODE || e === s.TAB_CODE || e === s.LF_CODE || e === s.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: s.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 = [], o, n;
|
|
311
|
+
for (; this.index < this.expr.length; )
|
|
312
|
+
if (o = this.code, o === s.SEMCOL_CODE || o === s.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 (o === 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, s.max_binop_len), t = e.length;
|
|
341
|
+
for (; t > 0; ) {
|
|
342
|
+
if (s.binary_ops.hasOwnProperty(e) && (!s.isIdentifierStart(this.code) || this.index + e.length < this.expr.length && !s.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, o, n, a, l, f, d, h;
|
|
355
|
+
if (l = this.gobbleToken(), !l || (t = this.gobbleBinaryOp(), !t))
|
|
356
|
+
return l;
|
|
357
|
+
for (a = {
|
|
358
|
+
value: t,
|
|
359
|
+
prec: s.binaryPrecedence(t),
|
|
360
|
+
right_a: s.right_associative.has(t)
|
|
361
|
+
}, f = this.gobbleToken(), f || this.throwError("Expected expression after " + t), n = [l, a, f]; t = this.gobbleBinaryOp(); ) {
|
|
362
|
+
if (o = s.binaryPrecedence(t), o === 0) {
|
|
363
|
+
this.index -= t.length;
|
|
364
|
+
break;
|
|
365
|
+
}
|
|
366
|
+
a = {
|
|
367
|
+
value: t,
|
|
368
|
+
prec: o,
|
|
369
|
+
right_a: s.right_associative.has(t)
|
|
370
|
+
}, h = t;
|
|
371
|
+
const m = (p) => a.right_a && p.right_a ? o > p.prec : o <= p.prec;
|
|
372
|
+
for (; n.length > 2 && m(n[n.length - 2]); )
|
|
373
|
+
f = n.pop(), t = n.pop().value, l = n.pop(), e = {
|
|
374
|
+
type: s.BINARY_EXP,
|
|
375
|
+
operator: t,
|
|
376
|
+
left: l,
|
|
377
|
+
right: f
|
|
378
|
+
}, n.push(e);
|
|
379
|
+
e = this.gobbleToken(), e || this.throwError("Expected expression after " + h), n.push(a, e);
|
|
380
|
+
}
|
|
381
|
+
for (d = n.length - 1, e = n[d]; d > 1; )
|
|
382
|
+
e = {
|
|
383
|
+
type: s.BINARY_EXP,
|
|
384
|
+
operator: n[d - 1].value,
|
|
385
|
+
left: n[d - 2],
|
|
386
|
+
right: e
|
|
387
|
+
}, d -= 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, o, n;
|
|
397
|
+
if (this.gobbleSpaces(), n = this.searchHook("gobble-token"), n)
|
|
398
|
+
return this.runHook("after-token", n);
|
|
399
|
+
if (e = this.code, s.isDecimalDigit(e) || e === s.PERIOD_CODE)
|
|
400
|
+
return this.gobbleNumericLiteral();
|
|
401
|
+
if (e === s.SQUOTE_CODE || e === s.DQUOTE_CODE)
|
|
402
|
+
n = this.gobbleStringLiteral();
|
|
403
|
+
else if (e === s.OBRACK_CODE)
|
|
404
|
+
n = this.gobbleArray();
|
|
405
|
+
else {
|
|
406
|
+
for (t = this.expr.substr(this.index, s.max_unop_len), o = t.length; o > 0; ) {
|
|
407
|
+
if (s.unary_ops.hasOwnProperty(t) && (!s.isIdentifierStart(this.code) || this.index + t.length < this.expr.length && !s.isIdentifierPart(this.expr.charCodeAt(this.index + t.length)))) {
|
|
408
|
+
this.index += o;
|
|
409
|
+
const a = this.gobbleToken();
|
|
410
|
+
return a || this.throwError("missing unaryOp argument"), this.runHook("after-token", {
|
|
411
|
+
type: s.UNARY_EXP,
|
|
412
|
+
operator: t,
|
|
413
|
+
argument: a,
|
|
414
|
+
prefix: !0
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
t = t.substr(0, --o);
|
|
418
|
+
}
|
|
419
|
+
s.isIdentifierStart(e) ? (n = this.gobbleIdentifier(), s.literals.hasOwnProperty(n.name) ? n = {
|
|
420
|
+
type: s.LITERAL,
|
|
421
|
+
value: s.literals[n.name],
|
|
422
|
+
raw: n.name
|
|
423
|
+
} : n.name === s.this_str && (n = {
|
|
424
|
+
type: s.THIS_EXP
|
|
425
|
+
})) : e === s.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 === s.PERIOD_CODE || t === s.OBRACK_CODE || t === s.OPAREN_CODE || t === s.QUMARK_CODE; ) {
|
|
441
|
+
let o;
|
|
442
|
+
if (t === s.QUMARK_CODE) {
|
|
443
|
+
if (this.expr.charCodeAt(this.index + 1) !== s.PERIOD_CODE)
|
|
444
|
+
break;
|
|
445
|
+
o = !0, this.index += 2, this.gobbleSpaces(), t = this.code;
|
|
446
|
+
}
|
|
447
|
+
this.index++, t === s.OBRACK_CODE ? (e = {
|
|
448
|
+
type: s.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 !== s.CBRACK_CODE && this.throwError("Unclosed ["), this.index++) : t === s.OPAREN_CODE ? e = {
|
|
453
|
+
type: s.CALL_EXP,
|
|
454
|
+
arguments: this.gobbleArguments(s.CPAREN_CODE),
|
|
455
|
+
callee: e
|
|
456
|
+
} : (t === s.PERIOD_CODE || o) && (o && this.index--, this.gobbleSpaces(), e = {
|
|
457
|
+
type: s.MEMBER_EXP,
|
|
458
|
+
computed: !1,
|
|
459
|
+
object: e,
|
|
460
|
+
property: this.gobbleIdentifier()
|
|
461
|
+
}), o && (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, o;
|
|
472
|
+
for (; s.isDecimalDigit(this.code); )
|
|
473
|
+
e += this.expr.charAt(this.index++);
|
|
474
|
+
if (this.code === s.PERIOD_CODE)
|
|
475
|
+
for (e += this.expr.charAt(this.index++); s.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++)); s.isDecimalDigit(this.code); )
|
|
479
|
+
e += this.expr.charAt(this.index++);
|
|
480
|
+
s.isDecimalDigit(this.expr.charCodeAt(this.index - 1)) || this.throwError("Expected exponent (" + e + this.char + ")");
|
|
481
|
+
}
|
|
482
|
+
return o = this.code, s.isIdentifierStart(o) ? this.throwError("Variable names cannot start with a number (" + e + this.char + ")") : (o === s.PERIOD_CODE || e.length === 1 && e.charCodeAt(0) === s.PERIOD_CODE) && this.throwError("Unexpected period"), {
|
|
483
|
+
type: s.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, o = 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 === o) {
|
|
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: s.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 (s.isIdentifierStart(e) ? this.index++ : this.throwError("Unexpected " + this.char); this.index < this.expr.length && (e = this.code, s.isIdentifierPart(e)); )
|
|
545
|
+
this.index++;
|
|
546
|
+
return {
|
|
547
|
+
type: s.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 o = !1, n = 0;
|
|
563
|
+
for (; this.index < this.expr.length; ) {
|
|
564
|
+
this.gobbleSpaces();
|
|
565
|
+
let a = this.code;
|
|
566
|
+
if (a === e) {
|
|
567
|
+
o = !0, this.index++, e === s.CPAREN_CODE && n && n >= t.length && this.throwError("Unexpected token " + String.fromCharCode(e));
|
|
568
|
+
break;
|
|
569
|
+
} else if (a === s.COMMA_CODE) {
|
|
570
|
+
if (this.index++, n++, n !== t.length) {
|
|
571
|
+
if (e === s.CPAREN_CODE)
|
|
572
|
+
this.throwError("Unexpected token ,");
|
|
573
|
+
else if (e === s.CBRACK_CODE)
|
|
574
|
+
for (let l = t.length; l < n; l++)
|
|
575
|
+
t.push(null);
|
|
576
|
+
}
|
|
577
|
+
} else if (t.length !== n && n !== 0)
|
|
578
|
+
this.throwError("Expected comma");
|
|
579
|
+
else {
|
|
580
|
+
const l = this.gobbleExpression();
|
|
581
|
+
(!l || l.type === s.COMPOUND) && this.throwError("Expected comma"), t.push(l);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
return o || 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(s.CPAREN_CODE);
|
|
598
|
+
if (this.code === s.CPAREN_CODE)
|
|
599
|
+
return this.index++, e.length === 1 ? e[0] : e.length ? {
|
|
600
|
+
type: s.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: s.ARRAY_EXP,
|
|
614
|
+
elements: this.gobbleArguments(s.CBRACK_CODE)
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
const ve = new Ee();
|
|
619
|
+
Object.assign(s, {
|
|
620
|
+
hooks: ve,
|
|
621
|
+
plugins: new me(s),
|
|
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
|
+
s.max_unop_len = s.getMaxKeyLen(s.unary_ops);
|
|
716
|
+
s.max_binop_len = s.getMaxKeyLen(s.binary_ops);
|
|
717
|
+
const L = (r) => new s(r).parse(), _e = Object.getOwnPropertyNames(class {
|
|
718
|
+
});
|
|
719
|
+
Object.getOwnPropertyNames(s).filter((r) => !_e.includes(r) && L[r] === void 0).forEach((r) => {
|
|
720
|
+
L[r] = s[r];
|
|
721
|
+
});
|
|
722
|
+
L.Jsep = s;
|
|
723
|
+
const xe = "ConditionalExpression";
|
|
724
|
+
var ke = {
|
|
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 o = 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: xe,
|
|
736
|
+
test: o,
|
|
737
|
+
consequent: n,
|
|
738
|
+
alternate: a
|
|
739
|
+
}, o.operator && r.binary_ops[o.operator] <= 0.9) {
|
|
740
|
+
let l = o;
|
|
741
|
+
for (; l.right.operator && r.binary_ops[l.right.operator] <= 0.9; )
|
|
742
|
+
l = l.right;
|
|
743
|
+
t.node.test = l.right, l.right = t.node, t.node = o;
|
|
744
|
+
}
|
|
745
|
+
} else
|
|
746
|
+
this.throwError("Expected :");
|
|
747
|
+
}
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
};
|
|
751
|
+
L.plugins.register(ke);
|
|
752
|
+
const ae = 47, Oe = 92;
|
|
753
|
+
var Ce = {
|
|
754
|
+
name: "regex",
|
|
755
|
+
init(r) {
|
|
756
|
+
r.hooks.add("gobble-token", function(t) {
|
|
757
|
+
if (this.code === ae) {
|
|
758
|
+
const o = ++this.index;
|
|
759
|
+
let n = !1;
|
|
760
|
+
for (; this.index < this.expr.length; ) {
|
|
761
|
+
if (this.code === ae && !n) {
|
|
762
|
+
const a = this.expr.slice(o, this.index);
|
|
763
|
+
let l = "";
|
|
764
|
+
for (; ++this.index < this.expr.length; ) {
|
|
765
|
+
const d = this.code;
|
|
766
|
+
if (d >= 97 && d <= 122 || d >= 65 && d <= 90 || d >= 48 && d <= 57)
|
|
767
|
+
l += this.char;
|
|
768
|
+
else
|
|
769
|
+
break;
|
|
770
|
+
}
|
|
771
|
+
let f;
|
|
772
|
+
try {
|
|
773
|
+
f = new RegExp(a, l);
|
|
774
|
+
} catch (d) {
|
|
775
|
+
this.throwError(d.message);
|
|
776
|
+
}
|
|
777
|
+
return t.node = {
|
|
778
|
+
type: r.LITERAL,
|
|
779
|
+
value: f,
|
|
780
|
+
raw: this.expr.slice(o - 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 === Oe ? 2 : 1;
|
|
784
|
+
}
|
|
785
|
+
this.throwError("Unclosed Regex");
|
|
786
|
+
}
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
};
|
|
790
|
+
const oe = 43, Ae = 45, G = {
|
|
791
|
+
name: "assignment",
|
|
792
|
+
assignmentOperators: /* @__PURE__ */ new Set(["=", "*=", "**=", "/=", "%=", "+=", "-=", "<<=", ">>=", ">>>=", "&=", "^=", "|=", "||=", "&&=", "??="]),
|
|
793
|
+
updateOperators: [oe, Ae],
|
|
794
|
+
assignmentPrecedence: 0.9,
|
|
795
|
+
init(r) {
|
|
796
|
+
const e = [r.IDENTIFIER, r.MEMBER_EXP];
|
|
797
|
+
G.assignmentOperators.forEach((o) => r.addBinaryOp(o, G.assignmentPrecedence, !0)), r.hooks.add("gobble-token", function(n) {
|
|
798
|
+
const a = this.code;
|
|
799
|
+
G.updateOperators.some((l) => l === a && l === this.expr.charCodeAt(this.index + 1)) && (this.index += 2, n.node = {
|
|
800
|
+
type: "UpdateExpression",
|
|
801
|
+
operator: a === oe ? "++" : "--",
|
|
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
|
+
G.updateOperators.some((l) => l === a && l === 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 === oe ? "++" : "--",
|
|
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(o) {
|
|
819
|
+
G.assignmentOperators.has(o.operator) ? (o.type = "AssignmentExpression", t(o.left), t(o.right)) : o.operator || Object.values(o).forEach((n) => {
|
|
820
|
+
n && typeof n == "object" && t(n);
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
};
|
|
825
|
+
L.plugins.register(Ce, G);
|
|
826
|
+
L.addUnaryOp("typeof");
|
|
827
|
+
L.addLiteral("null", null);
|
|
828
|
+
L.addLiteral("undefined", void 0);
|
|
829
|
+
const we = /* @__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
|
+
"||": (o, n) => o || n(),
|
|
864
|
+
"&&": (o, n) => o && n(),
|
|
865
|
+
"|": (o, n) => o | n(),
|
|
866
|
+
"^": (o, n) => o ^ n(),
|
|
867
|
+
"&": (o, n) => o & n(),
|
|
868
|
+
// eslint-disable-next-line eqeqeq -- API
|
|
869
|
+
"==": (o, n) => o == n(),
|
|
870
|
+
// eslint-disable-next-line eqeqeq -- API
|
|
871
|
+
"!=": (o, n) => o != n(),
|
|
872
|
+
"===": (o, n) => o === n(),
|
|
873
|
+
"!==": (o, n) => o !== n(),
|
|
874
|
+
"<": (o, n) => o < n(),
|
|
875
|
+
">": (o, n) => o > n(),
|
|
876
|
+
"<=": (o, n) => o <= n(),
|
|
877
|
+
">=": (o, n) => o >= n(),
|
|
878
|
+
"<<": (o, n) => o << n(),
|
|
879
|
+
">>": (o, n) => o >> n(),
|
|
880
|
+
">>>": (o, n) => o >>> n(),
|
|
881
|
+
"+": (o, n) => o + n(),
|
|
882
|
+
"-": (o, n) => o - n(),
|
|
883
|
+
"*": (o, n) => o * n(),
|
|
884
|
+
"/": (o, n) => o / n(),
|
|
885
|
+
"%": (o, n) => o % 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 o = 0; o < r.body.length; o++) {
|
|
891
|
+
r.body[o].type === "Identifier" && ["var", "let", "const"].includes(r.body[o].name) && r.body[o + 1] && r.body[o + 1].type === "AssignmentExpression" && (o += 1);
|
|
892
|
+
const n = r.body[o];
|
|
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
|
+
), o = O.evalAst(r.object, e);
|
|
916
|
+
if (o == null)
|
|
917
|
+
throw TypeError(`Cannot read properties of ${o} (reading '${t}')`);
|
|
918
|
+
if (!Object.hasOwn(o, t) && we.has(t))
|
|
919
|
+
throw TypeError(`Cannot read properties of ${o} (reading '${t}')`);
|
|
920
|
+
const n = o[t];
|
|
921
|
+
return typeof n == "function" ? n.bind(o) : n;
|
|
922
|
+
},
|
|
923
|
+
evalUnaryExpression(r, e) {
|
|
924
|
+
return {
|
|
925
|
+
"-": (o) => -O.evalAst(o, e),
|
|
926
|
+
"!": (o) => !O.evalAst(o, e),
|
|
927
|
+
"~": (o) => ~O.evalAst(o, e),
|
|
928
|
+
// eslint-disable-next-line no-implicit-coercion -- API
|
|
929
|
+
"+": (o) => +O.evalAst(o, e),
|
|
930
|
+
typeof: (o) => typeof O.evalAst(o, 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, o = O.evalAst(r.right, e);
|
|
944
|
+
return e[t] = o, e[t];
|
|
945
|
+
}
|
|
946
|
+
};
|
|
947
|
+
class Se {
|
|
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 M(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 Pe 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, o, n) {
|
|
979
|
+
if (!(this instanceof x))
|
|
980
|
+
try {
|
|
981
|
+
return new x(r, e, t, o, n);
|
|
982
|
+
} catch (l) {
|
|
983
|
+
if (!l.avoidNew)
|
|
984
|
+
throw l;
|
|
985
|
+
return l.value;
|
|
986
|
+
}
|
|
987
|
+
typeof r == "string" && (n = o, o = 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 || o || 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 l = {
|
|
993
|
+
path: a ? r.path : e
|
|
994
|
+
};
|
|
995
|
+
a ? "json" in r && (l.json = r.json) : l.json = t;
|
|
996
|
+
const f = this.evaluate(l);
|
|
997
|
+
if (!f || typeof f != "object")
|
|
998
|
+
throw new Pe(f);
|
|
999
|
+
return f;
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
x.prototype.evaluate = function(r, e, t, o) {
|
|
1003
|
+
let n = this.parent, a = this.parentProperty, {
|
|
1004
|
+
flatten: l,
|
|
1005
|
+
wrap: f
|
|
1006
|
+
} = this;
|
|
1007
|
+
if (this.currResultType = this.resultType, this.currEval = this.eval, this.currSandbox = this.sandbox, t = t || this.callback, this.currOtherTypeCallback = o || 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), l = Object.hasOwn(r, "flatten") ? r.flatten : l, this.currResultType = Object.hasOwn(r, "resultType") ? r.resultType : this.currResultType, this.currSandbox = Object.hasOwn(r, "sandbox") ? r.sandbox : this.currSandbox, f = Object.hasOwn(r, "wrap") ? r.wrap : f, 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 d = x.toPathArray(r);
|
|
1019
|
+
d[0] === "$" && d.length > 1 && d.shift(), this._hasParentSelector = null;
|
|
1020
|
+
const h = this._trace(d, e, ["$"], n, a, t).filter(function(m) {
|
|
1021
|
+
return m && !m.isParentSelector;
|
|
1022
|
+
});
|
|
1023
|
+
return h.length ? !f && h.length === 1 && !h[0].hasArrExpr ? this._getPreferredOutput(h[0]) : h.reduce((m, p) => {
|
|
1024
|
+
const k = this._getPreferredOutput(p);
|
|
1025
|
+
return l && Array.isArray(k) ? m = m.concat(k) : m.push(k), m;
|
|
1026
|
+
}, []) : f ? [] : 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 o = this._getPreferredOutput(r);
|
|
1050
|
+
r.path = typeof r.path == "string" ? r.path : x.toPathString(r.path), e(o, t, r);
|
|
1051
|
+
}
|
|
1052
|
+
};
|
|
1053
|
+
x.prototype._trace = function(r, e, t, o, n, a, l, f) {
|
|
1054
|
+
let d;
|
|
1055
|
+
if (!r.length)
|
|
1056
|
+
return d = {
|
|
1057
|
+
path: t,
|
|
1058
|
+
value: e,
|
|
1059
|
+
parent: o,
|
|
1060
|
+
parentProperty: n,
|
|
1061
|
+
hasArrExpr: l
|
|
1062
|
+
}, this._handleCallback(d, a, "value"), d;
|
|
1063
|
+
const h = r[0], m = r.slice(1), p = [];
|
|
1064
|
+
function k(g) {
|
|
1065
|
+
Array.isArray(g) ? g.forEach((S) => {
|
|
1066
|
+
p.push(S);
|
|
1067
|
+
}) : p.push(g);
|
|
1068
|
+
}
|
|
1069
|
+
if ((typeof h != "string" || f) && e && Object.hasOwn(e, h))
|
|
1070
|
+
k(this._trace(m, e[h], M(t, h), e, h, a, l));
|
|
1071
|
+
else if (h === "*")
|
|
1072
|
+
this._walk(e, (g) => {
|
|
1073
|
+
k(this._trace(m, e[g], M(t, g), e, g, a, !0, !0));
|
|
1074
|
+
});
|
|
1075
|
+
else if (h === "..")
|
|
1076
|
+
k(this._trace(m, e, t, o, n, a, l)), this._walk(e, (g) => {
|
|
1077
|
+
typeof e[g] == "object" && k(this._trace(r.slice(), e[g], M(t, g), e, g, a, !0));
|
|
1078
|
+
});
|
|
1079
|
+
else {
|
|
1080
|
+
if (h === "^")
|
|
1081
|
+
return this._hasParentSelector = !0, {
|
|
1082
|
+
path: t.slice(0, -1),
|
|
1083
|
+
expr: m,
|
|
1084
|
+
isParentSelector: !0
|
|
1085
|
+
};
|
|
1086
|
+
if (h === "~")
|
|
1087
|
+
return d = {
|
|
1088
|
+
path: M(t, h),
|
|
1089
|
+
value: n,
|
|
1090
|
+
parent: o,
|
|
1091
|
+
parentProperty: null
|
|
1092
|
+
}, this._handleCallback(d, a, "property"), d;
|
|
1093
|
+
if (h === "$")
|
|
1094
|
+
k(this._trace(m, e, t, null, null, a, l));
|
|
1095
|
+
else if (/^(-?\d*):(-?\d*):?(\d*)$/u.test(h))
|
|
1096
|
+
k(this._slice(h, m, e, t, o, 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 g = h.replace(/^\?\((.*?)\)$/u, "$1"), S = /@.?([^?]*)[['](\??\(.*?\))(?!.\)\])[\]']/gu.exec(g);
|
|
1101
|
+
S ? this._walk(e, (C) => {
|
|
1102
|
+
const U = [S[2]], D = S[1] ? e[C][S[1]] : e[C];
|
|
1103
|
+
this._trace(U, D, t, o, n, a, !0).length > 0 && k(this._trace(m, e[C], M(t, C), e, C, a, !0));
|
|
1104
|
+
}) : this._walk(e, (C) => {
|
|
1105
|
+
this._eval(g, e[C], C, t, o, n) && k(this._trace(m, e[C], M(t, C), e, C, a, !0));
|
|
1106
|
+
});
|
|
1107
|
+
} else if (h[0] === "(") {
|
|
1108
|
+
if (this.currEval === !1)
|
|
1109
|
+
throw new Error("Eval [(expr)] prevented in JSONPath expression.");
|
|
1110
|
+
k(this._trace(se(this._eval(h, e, t.at(-1), t.slice(0, -1), o, n), m), e, t, o, n, a, l));
|
|
1111
|
+
} else if (h[0] === "@") {
|
|
1112
|
+
let g = !1;
|
|
1113
|
+
const S = h.slice(1, -2);
|
|
1114
|
+
switch (S) {
|
|
1115
|
+
case "scalar":
|
|
1116
|
+
(!e || !["object", "function"].includes(typeof e)) && (g = !0);
|
|
1117
|
+
break;
|
|
1118
|
+
case "boolean":
|
|
1119
|
+
case "string":
|
|
1120
|
+
case "undefined":
|
|
1121
|
+
case "function":
|
|
1122
|
+
typeof e === S && (g = !0);
|
|
1123
|
+
break;
|
|
1124
|
+
case "integer":
|
|
1125
|
+
Number.isFinite(e) && !(e % 1) && (g = !0);
|
|
1126
|
+
break;
|
|
1127
|
+
case "number":
|
|
1128
|
+
Number.isFinite(e) && (g = !0);
|
|
1129
|
+
break;
|
|
1130
|
+
case "nonFinite":
|
|
1131
|
+
typeof e == "number" && !Number.isFinite(e) && (g = !0);
|
|
1132
|
+
break;
|
|
1133
|
+
case "object":
|
|
1134
|
+
e && typeof e === S && (g = !0);
|
|
1135
|
+
break;
|
|
1136
|
+
case "array":
|
|
1137
|
+
Array.isArray(e) && (g = !0);
|
|
1138
|
+
break;
|
|
1139
|
+
case "other":
|
|
1140
|
+
g = this.currOtherTypeCallback(e, t, o, n);
|
|
1141
|
+
break;
|
|
1142
|
+
case "null":
|
|
1143
|
+
e === null && (g = !0);
|
|
1144
|
+
break;
|
|
1145
|
+
/* c8 ignore next 2 */
|
|
1146
|
+
default:
|
|
1147
|
+
throw new TypeError("Unknown value type " + S);
|
|
1148
|
+
}
|
|
1149
|
+
if (g)
|
|
1150
|
+
return d = {
|
|
1151
|
+
path: t,
|
|
1152
|
+
value: e,
|
|
1153
|
+
parent: o,
|
|
1154
|
+
parentProperty: n
|
|
1155
|
+
}, this._handleCallback(d, a, "value"), d;
|
|
1156
|
+
} else if (h[0] === "`" && e && Object.hasOwn(e, h.slice(1))) {
|
|
1157
|
+
const g = h.slice(1);
|
|
1158
|
+
k(this._trace(m, e[g], M(t, g), e, g, a, l, !0));
|
|
1159
|
+
} else if (h.includes(",")) {
|
|
1160
|
+
const g = h.split(",");
|
|
1161
|
+
for (const S of g)
|
|
1162
|
+
k(this._trace(se(S, m), e, t, o, n, a, !0));
|
|
1163
|
+
} else !f && e && Object.hasOwn(e, h) && k(this._trace(m, e[h], M(t, h), e, h, a, l, !0));
|
|
1164
|
+
}
|
|
1165
|
+
if (this._hasParentSelector)
|
|
1166
|
+
for (let g = 0; g < p.length; g++) {
|
|
1167
|
+
const S = p[g];
|
|
1168
|
+
if (S && S.isParentSelector) {
|
|
1169
|
+
const C = this._trace(S.expr, e, S.path, o, n, a, l);
|
|
1170
|
+
if (Array.isArray(C)) {
|
|
1171
|
+
p[g] = C[0];
|
|
1172
|
+
const U = C.length;
|
|
1173
|
+
for (let D = 1; D < U; D++)
|
|
1174
|
+
g++, p.splice(g, 0, C[D]);
|
|
1175
|
+
} else
|
|
1176
|
+
p[g] = C;
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
return p;
|
|
1180
|
+
};
|
|
1181
|
+
x.prototype._walk = function(r, e) {
|
|
1182
|
+
if (Array.isArray(r)) {
|
|
1183
|
+
const t = r.length;
|
|
1184
|
+
for (let o = 0; o < t; o++)
|
|
1185
|
+
e(o);
|
|
1186
|
+
} else r && typeof r == "object" && Object.keys(r).forEach((t) => {
|
|
1187
|
+
e(t);
|
|
1188
|
+
});
|
|
1189
|
+
};
|
|
1190
|
+
x.prototype._slice = function(r, e, t, o, n, a, l) {
|
|
1191
|
+
if (!Array.isArray(t))
|
|
1192
|
+
return;
|
|
1193
|
+
const f = t.length, d = r.split(":"), h = d[2] && Number.parseInt(d[2]) || 1;
|
|
1194
|
+
let m = d[0] && Number.parseInt(d[0]) || 0, p = d[1] && Number.parseInt(d[1]) || f;
|
|
1195
|
+
m = m < 0 ? Math.max(0, m + f) : Math.min(f, m), p = p < 0 ? Math.max(0, p + f) : Math.min(f, p);
|
|
1196
|
+
const k = [];
|
|
1197
|
+
for (let g = m; g < p; g += h)
|
|
1198
|
+
this._trace(se(g, e), t, o, n, a, l, !0).forEach((C) => {
|
|
1199
|
+
k.push(C);
|
|
1200
|
+
});
|
|
1201
|
+
return k;
|
|
1202
|
+
};
|
|
1203
|
+
x.prototype._eval = function(r, e, t, o, 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 l = r.includes("@path");
|
|
1206
|
+
l && (this.currSandbox._$_path = x.toPathString(o.concat([t])));
|
|
1207
|
+
const f = this.currEval + "Script:" + r;
|
|
1208
|
+
if (!x.cache[f]) {
|
|
1209
|
+
let d = r.replaceAll("@parentProperty", "_$_parentProperty").replaceAll("@parent", "_$_parent").replaceAll("@property", "_$_property").replaceAll("@root", "_$_root").replaceAll(/@([.\s)[])/gu, "_$_v$1");
|
|
1210
|
+
if (l && (d = d.replaceAll("@path", "_$_path")), this.currEval === "safe" || this.currEval === !0 || this.currEval === void 0)
|
|
1211
|
+
x.cache[f] = new this.safeVm.Script(d);
|
|
1212
|
+
else if (this.currEval === "native")
|
|
1213
|
+
x.cache[f] = new this.vm.Script(d);
|
|
1214
|
+
else if (typeof this.currEval == "function" && this.currEval.prototype && Object.hasOwn(this.currEval.prototype, "runInNewContext")) {
|
|
1215
|
+
const h = this.currEval;
|
|
1216
|
+
x.cache[f] = new h(d);
|
|
1217
|
+
} else if (typeof this.currEval == "function")
|
|
1218
|
+
x.cache[f] = {
|
|
1219
|
+
runInNewContext: (h) => this.currEval(d, h)
|
|
1220
|
+
};
|
|
1221
|
+
else
|
|
1222
|
+
throw new TypeError(`Unknown "eval" property "${this.currEval}"`);
|
|
1223
|
+
}
|
|
1224
|
+
try {
|
|
1225
|
+
return x.cache[f].runInNewContext(this.currSandbox);
|
|
1226
|
+
} catch (d) {
|
|
1227
|
+
if (this.ignoreEvalErrors)
|
|
1228
|
+
return !1;
|
|
1229
|
+
throw new Error("jsonPath: " + d.message + ": " + r);
|
|
1230
|
+
}
|
|
1231
|
+
};
|
|
1232
|
+
x.cache = {};
|
|
1233
|
+
x.toPathString = function(r) {
|
|
1234
|
+
const e = r, t = e.length;
|
|
1235
|
+
let o = "$";
|
|
1236
|
+
for (let n = 1; n < t; n++)
|
|
1237
|
+
/^(~|\^|@.*?\(\))$/u.test(e[n]) || (o += /^[0-9*]+$/u.test(e[n]) ? "[" + e[n] + "]" : "['" + e[n] + "']");
|
|
1238
|
+
return o;
|
|
1239
|
+
};
|
|
1240
|
+
x.toPointer = function(r) {
|
|
1241
|
+
const e = r, t = e.length;
|
|
1242
|
+
let o = "";
|
|
1243
|
+
for (let n = 1; n < t; n++)
|
|
1244
|
+
/^(~|\^|@.*?\(\))$/u.test(e[n]) || (o += "/" + e[n].toString().replaceAll("~", "~0").replaceAll("/", "~1"));
|
|
1245
|
+
return o;
|
|
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, l) {
|
|
1254
|
+
return "[#" + (t.push(l) - 1) + "]";
|
|
1255
|
+
}).replaceAll(/\[['"]([^'\]]*)['"]\]/gu, function(a, l) {
|
|
1256
|
+
return "['" + l.replaceAll(".", "%@%").replaceAll("~", "%%@@%%") + "']";
|
|
1257
|
+
}).replaceAll("~", ";~;").replaceAll(/['"]?\.['"]?(?![^[]*\])|\[['"]?/gu, ";").replaceAll("%@%", ".").replaceAll("%%@@%%", "~").replaceAll(/(?:;)?(\^+)(?:;)?/gu, function(a, l) {
|
|
1258
|
+
return ";" + l.split("").join(";") + ";";
|
|
1259
|
+
}).replaceAll(/;;;|;;/gu, ";..;").replaceAll(/;$|'?\]|'$/gu, "").split(";").map(function(a) {
|
|
1260
|
+
const l = a.match(/#(\d+)/u);
|
|
1261
|
+
return !l || !l[1] ? a : t[l[1]];
|
|
1262
|
+
});
|
|
1263
|
+
return e[r] = n, e[r].concat();
|
|
1264
|
+
};
|
|
1265
|
+
x.prototype.safeVm = {
|
|
1266
|
+
Script: Se
|
|
1267
|
+
};
|
|
1268
|
+
const Ne = function(r, e, t) {
|
|
1269
|
+
const o = r.length;
|
|
1270
|
+
for (let n = 0; n < o; n++) {
|
|
1271
|
+
const a = r[n];
|
|
1272
|
+
t(a) && e.push(r.splice(n--, 1)[0]);
|
|
1273
|
+
}
|
|
1274
|
+
};
|
|
1275
|
+
class Te {
|
|
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 o = Object.keys(e), n = [];
|
|
1290
|
+
Ne(o, n, (h) => typeof e[h] == "function");
|
|
1291
|
+
const a = o.map((h) => e[h]);
|
|
1292
|
+
t = n.reduce((h, m) => {
|
|
1293
|
+
let p = e[m].toString();
|
|
1294
|
+
return /function/u.test(p) || (p = "function " + p), "var " + m + "=" + p + ";" + h;
|
|
1295
|
+
}, "") + t, !/(['"])use strict\1/u.test(t) && !o.includes("arguments") && (t = "var arguments = undefined;" + t), t = t.replace(/;\s*$/u, "");
|
|
1296
|
+
const f = t.lastIndexOf(";"), d = f !== -1 ? t.slice(0, f + 1) + " return " + t.slice(f + 1) : " return " + t;
|
|
1297
|
+
return new Function(...o, d)(...a);
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
x.prototype.vm = {
|
|
1301
|
+
Script: Te
|
|
1302
|
+
};
|
|
1303
|
+
const Be = { 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"], Re = {
|
|
9
1310
|
key: 3,
|
|
10
1311
|
class: "json-node__collapsed"
|
|
11
|
-
},
|
|
1312
|
+
}, Le = {
|
|
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
|
+
}, Me = { class: "json-node__children-content" }, Ve = { class: "json-node__line json-node__closing-bracket" }, Fe = { class: "json-node__bracket" }, He = {
|
|
18
1319
|
key: 0,
|
|
19
1320
|
class: "json-node__comma"
|
|
20
|
-
},
|
|
1321
|
+
}, Ke = {
|
|
21
1322
|
key: 1,
|
|
22
1323
|
class: "json-node__primitive"
|
|
23
|
-
},
|
|
1324
|
+
}, Xe = {
|
|
24
1325
|
key: 2,
|
|
25
1326
|
class: "json-node__colon"
|
|
26
|
-
},
|
|
27
|
-
key:
|
|
1327
|
+
}, Ge = ["title"], Qe = {
|
|
1328
|
+
key: 0,
|
|
28
1329
|
class: "json-node__comma"
|
|
29
|
-
},
|
|
1330
|
+
}, Ye = /* @__PURE__ */ le({
|
|
30
1331
|
name: "JsonNode",
|
|
31
1332
|
__name: "JsonNode",
|
|
32
1333
|
props: {
|
|
@@ -35,445 +1336,689 @@ const se = { class: "json-node" }, oe = {
|
|
|
35
1336
|
level: {},
|
|
36
1337
|
path: { default: "" },
|
|
37
1338
|
expanded: {},
|
|
38
|
-
isLast: { type: Boolean, default: !1 }
|
|
1339
|
+
isLast: { type: Boolean, default: !1 },
|
|
1340
|
+
theme: {}
|
|
39
1341
|
},
|
|
40
1342
|
emits: ["update:value", "toggle-expand", "copy", "update:key"],
|
|
41
|
-
setup(
|
|
42
|
-
|
|
43
|
-
|
|
1343
|
+
setup(r, { emit: e }) {
|
|
1344
|
+
ce((u) => ({
|
|
1345
|
+
"9759b91a": u.level,
|
|
1346
|
+
"35265df4": u.theme.colors.syntaxKey,
|
|
1347
|
+
"86a60ffc": u.theme.colors.hoverBackground,
|
|
1348
|
+
d1dccc86: u.theme.colors.syntaxBracket,
|
|
1349
|
+
"8f163582": u.theme.colors.textSecondary,
|
|
1350
|
+
"2a47fc5c": u.theme.colors.syntaxString,
|
|
1351
|
+
"21cb7794": u.theme.colors.syntaxNumber,
|
|
1352
|
+
da874d86: u.theme.colors.syntaxBoolean,
|
|
1353
|
+
"6fa6f892": u.theme.colors.syntaxNull,
|
|
1354
|
+
"078e91b6": u.theme.colors.background,
|
|
1355
|
+
"73841b48": u.theme.colors.indentLine
|
|
44
1356
|
}));
|
|
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
|
-
|
|
1357
|
+
const t = r, o = e, n = R(!1), a = R(!1), l = R(""), f = R(""), d = (u) => {
|
|
1358
|
+
if (!/^-?\d+(\.\d+)?$/.test(u)) return !1;
|
|
1359
|
+
const v = Number(u);
|
|
1360
|
+
return !Number.isSafeInteger(v) || u.length > 15;
|
|
1361
|
+
}, h = T(() => t.value !== null && typeof t.value == "object"), m = T(() => Array.isArray(t.value)), p = T(() => t.path ? t.path : t.keyName ? t.keyName : "root"), k = T(() => t.expanded.has(p.value)), g = T(() => t.keyName), S = T(() => m.value ? "[" : "{"), C = T(() => m.value ? "]" : "}"), U = T(() => {
|
|
1362
|
+
if (!t.value) return "";
|
|
1363
|
+
const v = Object.keys(t.value).length;
|
|
1364
|
+
return m.value ? v > 0 ? ` ${v} items ` : " " : v > 0 ? ` ${v} keys ` : " ";
|
|
1365
|
+
}), D = T(() => {
|
|
1366
|
+
const u = typeof t.value;
|
|
1367
|
+
return t.value === null ? "json-node__value--null" : u === "boolean" ? "json-node__value--boolean" : u === "number" ? "json-node__value--number" : u === "string" ? d(t.value) ? "json-node__value--number" : "json-node__value--string" : "";
|
|
1368
|
+
}), Q = T(() => a.value ? f.value : t.value === null ? "null" : typeof t.value == "boolean" || typeof t.value == "number" ? String(t.value) : typeof t.value == "string" ? d(t.value) ? t.value : `"${t.value}"` : String(t.value)), te = T(() => "Click to edit, double-click to copy"), Z = (u) => t.level === 0 ? u : p.value ? `${p.value}.${u}` : u, F = (u) => {
|
|
1369
|
+
const v = Object.keys(t.value);
|
|
1370
|
+
return v.indexOf(u) === v.length - 1;
|
|
1371
|
+
}, Y = () => {
|
|
1372
|
+
o("toggle-expand", p.value);
|
|
1373
|
+
}, q = () => {
|
|
1374
|
+
t.level !== 0 && (n.value = !0, l.value = t.keyName, ee(() => {
|
|
1375
|
+
const u = document.querySelectorAll(".json-node__key-input"), v = u[u.length - 1];
|
|
1376
|
+
v && (v.focus(), v.select());
|
|
65
1377
|
}));
|
|
66
|
-
},
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
1378
|
+
}, J = () => {
|
|
1379
|
+
h.value || (a.value = !0, typeof t.value == "string" && d(t.value) || typeof t.value == "string" ? f.value = t.value : f.value = String(t.value), ee(() => {
|
|
1380
|
+
const u = document.querySelectorAll(".json-node__value-input"), v = u[u.length - 1];
|
|
1381
|
+
v && (v.focus(), v.select());
|
|
70
1382
|
}));
|
|
71
1383
|
}, V = () => {
|
|
72
|
-
if (
|
|
73
|
-
const
|
|
74
|
-
if (!
|
|
75
|
-
|
|
1384
|
+
if (t.level === 0 || !n.value) return;
|
|
1385
|
+
const u = l.value.trim();
|
|
1386
|
+
if (!u) {
|
|
1387
|
+
W();
|
|
76
1388
|
return;
|
|
77
1389
|
}
|
|
78
|
-
if (
|
|
79
|
-
|
|
1390
|
+
if (u === t.keyName) {
|
|
1391
|
+
n.value = !1;
|
|
80
1392
|
return;
|
|
81
1393
|
}
|
|
82
|
-
|
|
83
|
-
},
|
|
1394
|
+
n.value = !1, o("update:key", p.value, u);
|
|
1395
|
+
}, z = () => {
|
|
84
1396
|
try {
|
|
85
|
-
let
|
|
86
|
-
const
|
|
87
|
-
if (
|
|
88
|
-
|
|
89
|
-
else if (
|
|
90
|
-
|
|
91
|
-
else if (!isNaN(Number(
|
|
92
|
-
const
|
|
93
|
-
!Number.isSafeInteger(
|
|
1397
|
+
let u;
|
|
1398
|
+
const v = f.value.trim();
|
|
1399
|
+
if (v === "null")
|
|
1400
|
+
u = null;
|
|
1401
|
+
else if (v === "true" || v === "false")
|
|
1402
|
+
u = v === "true";
|
|
1403
|
+
else if (!isNaN(Number(v)) && v !== "") {
|
|
1404
|
+
const K = Number(v);
|
|
1405
|
+
!Number.isSafeInteger(K) || v.length > 15 ? u = v : u = K;
|
|
94
1406
|
} else
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
} catch (
|
|
98
|
-
console.error("Failed to parse value:",
|
|
1407
|
+
u = f.value;
|
|
1408
|
+
o("update:value", p.value, u), a.value = !1;
|
|
1409
|
+
} catch (u) {
|
|
1410
|
+
console.error("Failed to parse value:", u), a.value = !1;
|
|
99
1411
|
}
|
|
100
|
-
},
|
|
101
|
-
|
|
102
|
-
},
|
|
103
|
-
|
|
1412
|
+
}, W = () => {
|
|
1413
|
+
n.value = !1, l.value = t.keyName;
|
|
1414
|
+
}, H = () => {
|
|
1415
|
+
a.value = !1, typeof t.value == "string" && d(t.value) || typeof t.value == "string" ? f.value = t.value : f.value = String(t.value);
|
|
104
1416
|
};
|
|
105
|
-
return (
|
|
106
|
-
const
|
|
107
|
-
return
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
1417
|
+
return (u, v) => {
|
|
1418
|
+
const K = pe("JsonNode", !0);
|
|
1419
|
+
return w(), A("div", Be, [
|
|
1420
|
+
h.value ? (w(), A("div", De, [
|
|
1421
|
+
P("div", je, [
|
|
1422
|
+
u.keyName && !n.value ? (w(), A("span", {
|
|
111
1423
|
key: 0,
|
|
112
1424
|
class: "json-node__key",
|
|
113
|
-
onClick:
|
|
1425
|
+
onClick: q,
|
|
114
1426
|
title: "Click to edit key"
|
|
115
|
-
}, ' "' + $(
|
|
116
|
-
|
|
1427
|
+
}, ' "' + $(g.value) + '" ', 1)) : N("", !0),
|
|
1428
|
+
u.keyName && n.value ? re((w(), A("input", {
|
|
117
1429
|
key: 1,
|
|
118
|
-
"onUpdate:modelValue":
|
|
1430
|
+
"onUpdate:modelValue": v[0] || (v[0] = (i) => l.value = i),
|
|
119
1431
|
onKeyup: [
|
|
120
|
-
|
|
121
|
-
|
|
1432
|
+
X(V, ["enter"]),
|
|
1433
|
+
X(W, ["escape"])
|
|
122
1434
|
],
|
|
123
1435
|
onBlur: V,
|
|
124
1436
|
class: "json-node__key-input"
|
|
125
1437
|
}, null, 544)), [
|
|
126
|
-
[
|
|
127
|
-
]) :
|
|
128
|
-
|
|
129
|
-
|
|
1438
|
+
[ne, l.value]
|
|
1439
|
+
]) : N("", !0),
|
|
1440
|
+
u.keyName ? (w(), A("span", Ie, ": ")) : N("", !0),
|
|
1441
|
+
P("span", {
|
|
130
1442
|
class: "json-node__bracket json-node__bracket--clickable",
|
|
131
|
-
onClick:
|
|
132
|
-
title:
|
|
133
|
-
}, $(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
1443
|
+
onClick: Y,
|
|
1444
|
+
title: k.value ? "Click to collapse" : "Click to expand"
|
|
1445
|
+
}, $(S.value), 9, $e),
|
|
1446
|
+
k.value ? N("", !0) : (w(), A("span", Re, [
|
|
1447
|
+
ie($(U.value) + " ", 1),
|
|
1448
|
+
P("span", {
|
|
137
1449
|
class: "json-node__bracket json-node__bracket--clickable",
|
|
138
|
-
onClick:
|
|
139
|
-
}, $(
|
|
1450
|
+
onClick: Y
|
|
1451
|
+
}, $(C.value), 1)
|
|
140
1452
|
])),
|
|
141
|
-
!
|
|
1453
|
+
!k.value && !u.isLast ? (w(), A("span", Le, ",")) : N("", !0)
|
|
142
1454
|
]),
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
(
|
|
146
|
-
key:
|
|
1455
|
+
k.value ? (w(), A("div", Ue, [
|
|
1456
|
+
P("div", Me, [
|
|
1457
|
+
(w(!0), A(ye, null, be(u.value, (i, c) => (w(), A("div", {
|
|
1458
|
+
key: c,
|
|
147
1459
|
class: "json-node__child"
|
|
148
1460
|
}, [
|
|
149
|
-
|
|
1461
|
+
ue(K, {
|
|
150
1462
|
value: i,
|
|
151
|
-
"key-name":
|
|
152
|
-
level:
|
|
153
|
-
path:
|
|
154
|
-
expanded:
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
"
|
|
160
|
-
|
|
1463
|
+
"key-name": m.value ? "" : String(c),
|
|
1464
|
+
level: u.level + 1,
|
|
1465
|
+
path: Z(String(c)),
|
|
1466
|
+
expanded: u.expanded,
|
|
1467
|
+
theme: u.theme,
|
|
1468
|
+
"onUpdate:value": v[1] || (v[1] = (y, b) => u.$emit("update:value", y, b)),
|
|
1469
|
+
onToggleExpand: v[2] || (v[2] = (y) => u.$emit("toggle-expand", y)),
|
|
1470
|
+
onCopy: v[3] || (v[3] = (y) => u.$emit("copy", y)),
|
|
1471
|
+
"onUpdate:key": v[4] || (v[4] = (y, b) => u.$emit("update:key", y, b)),
|
|
1472
|
+
"is-last": F(String(c))
|
|
1473
|
+
}, null, 8, ["value", "key-name", "level", "path", "expanded", "theme", "is-last"])
|
|
161
1474
|
]))), 128))
|
|
162
1475
|
]),
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
1476
|
+
P("div", Ve, [
|
|
1477
|
+
P("span", Fe, $(C.value), 1),
|
|
1478
|
+
u.isLast ? N("", !0) : (w(), A("span", He, ","))
|
|
166
1479
|
])
|
|
167
|
-
])) :
|
|
168
|
-
])) : (
|
|
169
|
-
|
|
1480
|
+
])) : N("", !0)
|
|
1481
|
+
])) : (w(), A("div", Ke, [
|
|
1482
|
+
u.keyName && !n.value ? (w(), A("span", {
|
|
170
1483
|
key: 0,
|
|
171
1484
|
class: "json-node__key",
|
|
172
|
-
onClick:
|
|
1485
|
+
onClick: q,
|
|
173
1486
|
title: "Click to edit key"
|
|
174
|
-
}, ' "' + $(
|
|
175
|
-
|
|
1487
|
+
}, ' "' + $(g.value) + '" ', 1)) : N("", !0),
|
|
1488
|
+
u.keyName && n.value ? re((w(), A("input", {
|
|
176
1489
|
key: 1,
|
|
177
|
-
"onUpdate:modelValue":
|
|
1490
|
+
"onUpdate:modelValue": v[5] || (v[5] = (i) => l.value = i),
|
|
178
1491
|
onKeyup: [
|
|
179
|
-
|
|
180
|
-
|
|
1492
|
+
X(V, ["enter"]),
|
|
1493
|
+
X(W, ["escape"])
|
|
181
1494
|
],
|
|
182
1495
|
onBlur: V,
|
|
183
1496
|
class: "json-node__key-input"
|
|
184
1497
|
}, null, 544)), [
|
|
185
|
-
[
|
|
186
|
-
]) :
|
|
187
|
-
|
|
188
|
-
|
|
1498
|
+
[ne, l.value]
|
|
1499
|
+
]) : N("", !0),
|
|
1500
|
+
u.keyName ? (w(), A("span", Xe, ": ")) : N("", !0),
|
|
1501
|
+
a.value ? N("", !0) : (w(), A("span", {
|
|
189
1502
|
key: 3,
|
|
190
|
-
class:
|
|
191
|
-
onClick:
|
|
192
|
-
onDblclick:
|
|
193
|
-
title:
|
|
194
|
-
},
|
|
195
|
-
|
|
1503
|
+
class: de(["json-node__value", D.value]),
|
|
1504
|
+
onClick: J,
|
|
1505
|
+
onDblclick: v[6] || (v[6] = (i) => u.$emit("copy", u.value)),
|
|
1506
|
+
title: te.value
|
|
1507
|
+
}, [
|
|
1508
|
+
ie($(Q.value), 1),
|
|
1509
|
+
u.isLast ? N("", !0) : (w(), A("span", Qe, ","))
|
|
1510
|
+
], 42, Ge)),
|
|
1511
|
+
a.value ? re((w(), A("input", {
|
|
196
1512
|
key: 4,
|
|
197
|
-
"onUpdate:modelValue":
|
|
1513
|
+
"onUpdate:modelValue": v[7] || (v[7] = (i) => f.value = i),
|
|
198
1514
|
onKeyup: [
|
|
199
|
-
|
|
200
|
-
|
|
1515
|
+
X(z, ["enter"]),
|
|
1516
|
+
X(H, ["escape"])
|
|
201
1517
|
],
|
|
202
|
-
onBlur:
|
|
1518
|
+
onBlur: z,
|
|
203
1519
|
class: "json-node__value-input"
|
|
204
1520
|
}, null, 544)), [
|
|
205
|
-
[
|
|
206
|
-
]) :
|
|
207
|
-
e.isLast ? k("", !0) : (u(), a("span", ke, ","))
|
|
1521
|
+
[ne, f.value]
|
|
1522
|
+
]) : N("", !0)
|
|
208
1523
|
]))
|
|
209
1524
|
]);
|
|
210
1525
|
};
|
|
211
1526
|
}
|
|
212
|
-
}),
|
|
213
|
-
const
|
|
214
|
-
for (const [
|
|
215
|
-
o
|
|
216
|
-
return
|
|
217
|
-
},
|
|
1527
|
+
}), he = (r, e) => {
|
|
1528
|
+
const t = r.__vccOpts || r;
|
|
1529
|
+
for (const [o, n] of e)
|
|
1530
|
+
t[o] = n;
|
|
1531
|
+
return t;
|
|
1532
|
+
}, qe = /* @__PURE__ */ he(Ye, [["__scopeId", "data-v-65598de1"]]), fe = {
|
|
1533
|
+
name: "github-light",
|
|
1534
|
+
colors: {
|
|
1535
|
+
// 背景色
|
|
1536
|
+
background: "#ffffff",
|
|
1537
|
+
surfaceBackground: "#f6f8fa",
|
|
1538
|
+
// 边框色
|
|
1539
|
+
border: "#d0d7de",
|
|
1540
|
+
// 文本色
|
|
1541
|
+
text: "#24292f",
|
|
1542
|
+
textSecondary: "#656d76",
|
|
1543
|
+
// 按钮样式
|
|
1544
|
+
buttonBackground: "#f6f8fa",
|
|
1545
|
+
buttonBackgroundHover: "#f3f4f6",
|
|
1546
|
+
buttonBorder: "#d0d7de",
|
|
1547
|
+
buttonText: "#24292f",
|
|
1548
|
+
buttonPrimary: "#2da44e",
|
|
1549
|
+
buttonPrimaryHover: "#2c974b",
|
|
1550
|
+
// 状态指示
|
|
1551
|
+
success: "#1a7f37",
|
|
1552
|
+
successBackground: "#dafbe1",
|
|
1553
|
+
error: "#cf222e",
|
|
1554
|
+
errorBackground: "#ffebe9",
|
|
1555
|
+
// JSON 语法高亮
|
|
1556
|
+
syntaxString: "#0a3069",
|
|
1557
|
+
syntaxNumber: "#0969da",
|
|
1558
|
+
syntaxBoolean: "#8250df",
|
|
1559
|
+
syntaxNull: "#656d76",
|
|
1560
|
+
syntaxKey: "#0969da",
|
|
1561
|
+
syntaxBracket: "#24292f",
|
|
1562
|
+
// 滚动条
|
|
1563
|
+
scrollbarTrack: "#f6f8fa",
|
|
1564
|
+
scrollbarThumb: "#d0d7de",
|
|
1565
|
+
scrollbarThumbHover: "#afb8c1",
|
|
1566
|
+
// 悬停效果
|
|
1567
|
+
hoverBackground: "#f6f8fa",
|
|
1568
|
+
// 缩进线
|
|
1569
|
+
indentLine: "#d0d7de"
|
|
1570
|
+
}
|
|
1571
|
+
}, ze = {
|
|
1572
|
+
name: "github-dark",
|
|
1573
|
+
colors: {
|
|
1574
|
+
// 背景色
|
|
1575
|
+
background: "#0d1117",
|
|
1576
|
+
surfaceBackground: "#161b22",
|
|
1577
|
+
// 边框色
|
|
1578
|
+
border: "#30363d",
|
|
1579
|
+
// 文本色
|
|
1580
|
+
text: "#e6edf3",
|
|
1581
|
+
textSecondary: "#7d8590",
|
|
1582
|
+
// 按钮样式
|
|
1583
|
+
buttonBackground: "#21262d",
|
|
1584
|
+
buttonBackgroundHover: "#30363d",
|
|
1585
|
+
buttonBorder: "#30363d",
|
|
1586
|
+
buttonText: "#e6edf3",
|
|
1587
|
+
buttonPrimary: "#238636",
|
|
1588
|
+
buttonPrimaryHover: "#2ea043",
|
|
1589
|
+
// 状态指示
|
|
1590
|
+
success: "#3fb950",
|
|
1591
|
+
successBackground: "#0f2419",
|
|
1592
|
+
error: "#f85149",
|
|
1593
|
+
errorBackground: "#381921",
|
|
1594
|
+
// JSON 语法高亮
|
|
1595
|
+
syntaxString: "#a5d6ff",
|
|
1596
|
+
syntaxNumber: "#79c0ff",
|
|
1597
|
+
syntaxBoolean: "#d2a8ff",
|
|
1598
|
+
syntaxNull: "#7d8590",
|
|
1599
|
+
syntaxKey: "#79c0ff",
|
|
1600
|
+
syntaxBracket: "#e6edf3",
|
|
1601
|
+
// 滚动条
|
|
1602
|
+
scrollbarTrack: "#161b22",
|
|
1603
|
+
scrollbarThumb: "#30363d",
|
|
1604
|
+
scrollbarThumbHover: "#6e7681",
|
|
1605
|
+
// 悬停效果
|
|
1606
|
+
hoverBackground: "#161b22",
|
|
1607
|
+
// 缩进线
|
|
1608
|
+
indentLine: "#30363d"
|
|
1609
|
+
}
|
|
1610
|
+
}, We = {
|
|
1611
|
+
name: "min-light",
|
|
1612
|
+
colors: {
|
|
1613
|
+
// 背景色 - 纯白简洁
|
|
1614
|
+
background: "#ffffff",
|
|
1615
|
+
surfaceBackground: "#fafafa",
|
|
1616
|
+
// 边框色 - 极浅灰
|
|
1617
|
+
border: "#e5e5e5",
|
|
1618
|
+
// 文本色 - 深灰而非纯黑
|
|
1619
|
+
text: "#333333",
|
|
1620
|
+
textSecondary: "#888888",
|
|
1621
|
+
// 按钮样式 - 简约设计
|
|
1622
|
+
buttonBackground: "#f8f8f8",
|
|
1623
|
+
buttonBackgroundHover: "#eeeeee",
|
|
1624
|
+
buttonBorder: "#e0e0e0",
|
|
1625
|
+
buttonText: "#333333",
|
|
1626
|
+
buttonPrimary: "#007acc",
|
|
1627
|
+
buttonPrimaryHover: "#005a9e",
|
|
1628
|
+
// 状态指示 - 柔和色彩
|
|
1629
|
+
success: "#22c55e",
|
|
1630
|
+
successBackground: "#f0fdf4",
|
|
1631
|
+
error: "#ef4444",
|
|
1632
|
+
errorBackground: "#fef2f2",
|
|
1633
|
+
// JSON 语法高亮 - 简约配色
|
|
1634
|
+
syntaxString: "#22c55e",
|
|
1635
|
+
syntaxNumber: "#3b82f6",
|
|
1636
|
+
syntaxBoolean: "#8b5cf6",
|
|
1637
|
+
syntaxNull: "#6b7280",
|
|
1638
|
+
syntaxKey: "#1f2937",
|
|
1639
|
+
syntaxBracket: "#374151",
|
|
1640
|
+
// 滚动条 - 极简
|
|
1641
|
+
scrollbarTrack: "#f5f5f5",
|
|
1642
|
+
scrollbarThumb: "#d1d5db",
|
|
1643
|
+
scrollbarThumbHover: "#9ca3af",
|
|
1644
|
+
// 悬停效果
|
|
1645
|
+
hoverBackground: "#f9f9f9",
|
|
1646
|
+
// 缩进线
|
|
1647
|
+
indentLine: "#e5e7eb"
|
|
1648
|
+
}
|
|
1649
|
+
}, Ze = {
|
|
1650
|
+
name: "slack-ochin",
|
|
1651
|
+
colors: {
|
|
1652
|
+
// 背景色 - 温暖的米色调
|
|
1653
|
+
background: "#fefbf6",
|
|
1654
|
+
surfaceBackground: "#faf6f0",
|
|
1655
|
+
// 边框色 - 暖橙色调
|
|
1656
|
+
border: "#e8d5b7",
|
|
1657
|
+
// 文本色 - 深棕色
|
|
1658
|
+
text: "#4a3b2a",
|
|
1659
|
+
textSecondary: "#8b7355",
|
|
1660
|
+
// 按钮样式 - Slack 风格橙色
|
|
1661
|
+
buttonBackground: "#f4ede4",
|
|
1662
|
+
buttonBackgroundHover: "#efe5d8",
|
|
1663
|
+
buttonBorder: "#e8d5b7",
|
|
1664
|
+
buttonText: "#4a3b2a",
|
|
1665
|
+
buttonPrimary: "#ff6b35",
|
|
1666
|
+
buttonPrimaryHover: "#e55a2b",
|
|
1667
|
+
// 状态指示 - 暖色调
|
|
1668
|
+
success: "#ff9500",
|
|
1669
|
+
successBackground: "#fff8f0",
|
|
1670
|
+
error: "#d73502",
|
|
1671
|
+
errorBackground: "#ffeee8",
|
|
1672
|
+
// JSON 语法高亮 - 温暖配色
|
|
1673
|
+
syntaxString: "#d73502",
|
|
1674
|
+
syntaxNumber: "#ff6b35",
|
|
1675
|
+
syntaxBoolean: "#b7472a",
|
|
1676
|
+
syntaxNull: "#8b7355",
|
|
1677
|
+
syntaxKey: "#4a3b2a",
|
|
1678
|
+
syntaxBracket: "#6b5444",
|
|
1679
|
+
// 滚动条 - 暖色调
|
|
1680
|
+
scrollbarTrack: "#f4ede4",
|
|
1681
|
+
scrollbarThumb: "#e8d5b7",
|
|
1682
|
+
scrollbarThumbHover: "#d4c4a8",
|
|
1683
|
+
// 悬停效果
|
|
1684
|
+
hoverBackground: "#f8f2eb",
|
|
1685
|
+
// 缩进线
|
|
1686
|
+
indentLine: "#e8d5b7"
|
|
1687
|
+
}
|
|
1688
|
+
}, Je = {
|
|
1689
|
+
"github-light": fe,
|
|
1690
|
+
"github-dark": ze,
|
|
1691
|
+
"min-light": We,
|
|
1692
|
+
"slack-ochin": Ze
|
|
1693
|
+
};
|
|
1694
|
+
function et(r = "github-light") {
|
|
1695
|
+
return Je[r] || fe;
|
|
1696
|
+
}
|
|
1697
|
+
const tt = {
|
|
218
1698
|
key: 0,
|
|
219
1699
|
class: "json-format__toolbar"
|
|
220
|
-
},
|
|
1700
|
+
}, rt = { class: "json-format__actions" }, nt = ["disabled"], ot = ["disabled"], st = ["disabled"], it = ["disabled"], at = { class: "json-format__info" }, lt = {
|
|
221
1701
|
key: 0,
|
|
222
1702
|
class: "json-format__status json-format__status--success"
|
|
223
|
-
},
|
|
1703
|
+
}, ct = {
|
|
224
1704
|
key: 1,
|
|
225
1705
|
class: "json-format__status json-format__status--error"
|
|
226
|
-
},
|
|
1706
|
+
}, ut = { class: "json-format__content" }, dt = {
|
|
227
1707
|
key: 0,
|
|
228
1708
|
class: "json-format__error"
|
|
229
|
-
},
|
|
1709
|
+
}, ht = {
|
|
230
1710
|
key: 1,
|
|
1711
|
+
class: "json-format__error"
|
|
1712
|
+
}, ft = {
|
|
1713
|
+
key: 2,
|
|
231
1714
|
class: "json-format__viewer"
|
|
232
|
-
},
|
|
1715
|
+
}, pt = /* @__PURE__ */ le({
|
|
233
1716
|
name: "JsonFormat",
|
|
234
1717
|
__name: "index",
|
|
235
1718
|
props: {
|
|
236
1719
|
modelValue: { default: "" },
|
|
237
1720
|
readonly: { type: Boolean, default: !1 },
|
|
238
1721
|
maxDepth: { default: 10 },
|
|
239
|
-
showToolbar: { type: Boolean, default: !0 }
|
|
1722
|
+
showToolbar: { type: Boolean, default: !0 },
|
|
1723
|
+
theme: { default: "github-light" }
|
|
240
1724
|
},
|
|
241
1725
|
emits: ["update:modelValue", "copy-success", "copy-error", "expand-all", "collapse-all", "compress"],
|
|
242
|
-
setup(
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
1726
|
+
setup(r, { expose: e, emit: t }) {
|
|
1727
|
+
ce((i) => ({
|
|
1728
|
+
"8d5bfdae": p.value.colors.border,
|
|
1729
|
+
"14a51bab": p.value.colors.background,
|
|
1730
|
+
"0504ed6a": p.value.colors.text,
|
|
1731
|
+
a5b566c4: p.value.colors.surfaceBackground,
|
|
1732
|
+
a172158a: p.value.colors.buttonBorder,
|
|
1733
|
+
"5ffdb6bd": p.value.colors.buttonBackground,
|
|
1734
|
+
"796bbdfc": p.value.colors.buttonText,
|
|
1735
|
+
"225a5f02": p.value.colors.buttonBackgroundHover,
|
|
1736
|
+
"22d2aed3": p.value.colors.buttonPrimary,
|
|
1737
|
+
"27e37629": p.value.colors.buttonPrimaryHover,
|
|
1738
|
+
"1d58ec74": p.value.colors.successBackground,
|
|
1739
|
+
"04bd5ab4": p.value.colors.success,
|
|
1740
|
+
"0242d8f9": p.value.colors.errorBackground,
|
|
1741
|
+
ca699d2a: p.value.colors.error,
|
|
1742
|
+
"4d5522c2": p.value.colors.scrollbarTrack,
|
|
1743
|
+
"4d50e34d": p.value.colors.scrollbarThumb,
|
|
1744
|
+
"6854fdef": p.value.colors.scrollbarThumbHover
|
|
1745
|
+
}));
|
|
1746
|
+
const o = r, n = t, a = R(null), l = R(""), f = R(/* @__PURE__ */ new Set()), d = R(null), h = R(""), m = T(() => l.value === ""), p = T(() => et(o.theme)), k = T(() => h.value ? null : d.value !== null ? d.value : a.value), g = (i) => {
|
|
1747
|
+
if (!i.trim()) {
|
|
1748
|
+
a.value = null, l.value = "", d.value = null, h.value = "";
|
|
1749
|
+
return;
|
|
1750
|
+
}
|
|
1751
|
+
try {
|
|
1752
|
+
let c = i;
|
|
1753
|
+
c = c.replace(/:\s*(\d{16,})\s*([,}])/g, ': "$1"$2'), c = c.replace(/:\s*(\d+\.\d*?0+)\s*([,}])/g, ': "$1"$2'), a.value = JSON.parse(c), l.value = "", d.value = null, h.value = "", ee(() => {
|
|
1754
|
+
k.value !== null && F();
|
|
1755
|
+
});
|
|
1756
|
+
} catch (c) {
|
|
1757
|
+
l.value = c instanceof Error ? c.message : "Unknown parsing error", a.value = null, d.value = null, h.value = "";
|
|
1758
|
+
}
|
|
1759
|
+
}, S = (i) => {
|
|
1760
|
+
if (!i || !i.expression.trim()) {
|
|
1761
|
+
C();
|
|
1762
|
+
return;
|
|
1763
|
+
}
|
|
1764
|
+
if (!a.value) {
|
|
1765
|
+
h.value = "No valid JSON data to filter";
|
|
246
1766
|
return;
|
|
247
1767
|
}
|
|
248
1768
|
try {
|
|
249
|
-
let
|
|
250
|
-
|
|
251
|
-
|
|
1769
|
+
let c;
|
|
1770
|
+
if (i.type === "jsonpath")
|
|
1771
|
+
c = x({ path: i.expression, json: a.value }), c.length === 1 && i.expression.includes("$[") === !1 && !i.expression.endsWith("[*]") ? d.value = c[0] : d.value = c;
|
|
1772
|
+
else if (i.type === "js")
|
|
1773
|
+
c = new Function("data", `
|
|
1774
|
+
try {
|
|
1775
|
+
return ${i.expression};
|
|
1776
|
+
} catch (error) {
|
|
1777
|
+
throw new Error('JavaScript expression error: ' + error.message);
|
|
1778
|
+
}
|
|
1779
|
+
`)(a.value), d.value = c;
|
|
1780
|
+
else
|
|
1781
|
+
throw new Error(`Unsupported filter type: ${i.type}`);
|
|
1782
|
+
h.value = "", ee(() => {
|
|
1783
|
+
F();
|
|
252
1784
|
});
|
|
253
|
-
} catch (
|
|
254
|
-
|
|
1785
|
+
} catch (c) {
|
|
1786
|
+
h.value = c instanceof Error ? c.message : "Filter execution error", d.value = null;
|
|
255
1787
|
}
|
|
1788
|
+
}, C = () => {
|
|
1789
|
+
d.value = null, h.value = "";
|
|
256
1790
|
};
|
|
257
|
-
|
|
258
|
-
|
|
1791
|
+
ge(() => o.modelValue, (i) => {
|
|
1792
|
+
g(i);
|
|
259
1793
|
}, { 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
|
|
1794
|
+
const U = (i) => {
|
|
1795
|
+
if (!/^-?\d+(\.\d+)?$/.test(i)) return !1;
|
|
1796
|
+
const c = Number(i);
|
|
1797
|
+
return !Number.isSafeInteger(c) || i.length > 15;
|
|
1798
|
+
}, D = (i, c, y) => JSON.stringify(i, (b, E) => {
|
|
1799
|
+
if (typeof E == "string" && U(E))
|
|
1800
|
+
return `__BIG_NUMBER__${E}__BIG_NUMBER__`;
|
|
1801
|
+
if (typeof E == "string" && /^-?\d+(\.\d+)?$/.test(E)) {
|
|
1802
|
+
const _ = Number(E);
|
|
1803
|
+
if (Number.isSafeInteger(_) && _.toString() === E)
|
|
1804
|
+
return _;
|
|
1805
|
+
if (!Number.isNaN(_) && isFinite(_) && E.includes("."))
|
|
1806
|
+
return _.toString() === E ? _ : `__PRESERVE_STRING__${E}__PRESERVE_STRING__`;
|
|
1807
|
+
if (!Number.isNaN(_) && isFinite(_))
|
|
1808
|
+
return _;
|
|
275
1809
|
}
|
|
276
|
-
return
|
|
277
|
-
},
|
|
278
|
-
if (!
|
|
1810
|
+
return c && typeof c == "function" ? c(b, E) : E;
|
|
1811
|
+
}, y).replace(/"__BIG_NUMBER__(.+?)__BIG_NUMBER__"/g, "$1").replace(/"__PRESERVE_STRING__(.+?)__PRESERVE_STRING__"/g, "$1"), Q = (i, c) => {
|
|
1812
|
+
if (!o.readonly)
|
|
279
1813
|
try {
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
} catch (
|
|
283
|
-
console.error("Failed to update JSON:",
|
|
1814
|
+
const y = te(a.value, i, c), b = D(y, null, 2);
|
|
1815
|
+
n("update:modelValue", b);
|
|
1816
|
+
} catch (y) {
|
|
1817
|
+
console.error("Failed to update JSON:", y);
|
|
284
1818
|
}
|
|
285
|
-
},
|
|
286
|
-
if (!
|
|
287
|
-
const
|
|
288
|
-
let
|
|
289
|
-
for (let
|
|
290
|
-
const
|
|
291
|
-
|
|
1819
|
+
}, te = (i, c, y) => {
|
|
1820
|
+
if (!c || c === "root") return y;
|
|
1821
|
+
const b = c.split("."), E = H(i, b.slice(0, -1));
|
|
1822
|
+
let _ = E;
|
|
1823
|
+
for (let j = 0; j < b.length - 1; j++) {
|
|
1824
|
+
const I = b[j];
|
|
1825
|
+
I !== "root" && (Array.isArray(_) ? _ = _[parseInt(I)] : _ = _[I]);
|
|
292
1826
|
}
|
|
293
|
-
const
|
|
294
|
-
return
|
|
295
|
-
},
|
|
296
|
-
|
|
297
|
-
},
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
const
|
|
301
|
-
|
|
302
|
-
}) : Object.keys(
|
|
303
|
-
const
|
|
304
|
-
|
|
1827
|
+
const B = b[b.length - 1];
|
|
1828
|
+
return B === "root" ? y : (Array.isArray(_) ? _[parseInt(B)] = y : _[B] = y, E);
|
|
1829
|
+
}, Z = (i) => {
|
|
1830
|
+
f.value.has(i) ? f.value.delete(i) : f.value.add(i);
|
|
1831
|
+
}, F = () => {
|
|
1832
|
+
const i = /* @__PURE__ */ new Set(), c = (y, b = "") => {
|
|
1833
|
+
y !== null && typeof y == "object" && (i.add(b || "root"), Array.isArray(y) ? y.forEach((E, _) => {
|
|
1834
|
+
const B = b ? `${b}.${_}` : `${_}`;
|
|
1835
|
+
c(E, B);
|
|
1836
|
+
}) : Object.keys(y).forEach((E) => {
|
|
1837
|
+
const _ = b ? `${b}.${E}` : E;
|
|
1838
|
+
c(y[E], _);
|
|
305
1839
|
}));
|
|
306
1840
|
};
|
|
307
|
-
|
|
308
|
-
},
|
|
309
|
-
|
|
310
|
-
},
|
|
1841
|
+
c(k.value), f.value = i, n("expand-all");
|
|
1842
|
+
}, Y = () => {
|
|
1843
|
+
f.value = /* @__PURE__ */ new Set(["root"]), n("collapse-all");
|
|
1844
|
+
}, q = async () => {
|
|
311
1845
|
if (m.value)
|
|
312
1846
|
try {
|
|
313
|
-
const
|
|
314
|
-
await navigator.clipboard.writeText(
|
|
315
|
-
} catch (
|
|
316
|
-
console.error("Failed to copy JSON:",
|
|
1847
|
+
const i = k.value, c = D(i, null, 2);
|
|
1848
|
+
await navigator.clipboard.writeText(c), n("copy-success", c);
|
|
1849
|
+
} catch (i) {
|
|
1850
|
+
console.error("Failed to copy JSON:", i), n("copy-error", i instanceof Error ? i : new Error("Failed to copy JSON"));
|
|
317
1851
|
}
|
|
318
|
-
},
|
|
1852
|
+
}, J = () => {
|
|
319
1853
|
if (m.value)
|
|
320
1854
|
try {
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
} catch (
|
|
324
|
-
console.error("Failed to compress JSON:",
|
|
1855
|
+
const i = k.value, c = D(i);
|
|
1856
|
+
n("update:modelValue", c), n("compress", c);
|
|
1857
|
+
} catch (i) {
|
|
1858
|
+
console.error("Failed to compress JSON:", i);
|
|
325
1859
|
}
|
|
326
|
-
},
|
|
1860
|
+
}, V = async (i) => {
|
|
327
1861
|
try {
|
|
328
|
-
let
|
|
329
|
-
typeof
|
|
330
|
-
} catch (
|
|
331
|
-
console.error("Failed to copy value:",
|
|
1862
|
+
let c;
|
|
1863
|
+
typeof i == "string" && U(i) ? c = i : typeof i == "string" ? c = `"${i}"` : c = JSON.stringify(i), await navigator.clipboard.writeText(c);
|
|
1864
|
+
} catch (c) {
|
|
1865
|
+
console.error("Failed to copy value:", c);
|
|
332
1866
|
}
|
|
333
|
-
},
|
|
334
|
-
if (!
|
|
1867
|
+
}, z = (i, c) => {
|
|
1868
|
+
if (!o.readonly)
|
|
335
1869
|
try {
|
|
336
|
-
const
|
|
337
|
-
|
|
338
|
-
} catch (
|
|
339
|
-
console.error("Failed to rename key:",
|
|
1870
|
+
const y = W(a.value, i, c), b = D(y, null, 2);
|
|
1871
|
+
n("update:modelValue", b), K(i, c);
|
|
1872
|
+
} catch (y) {
|
|
1873
|
+
console.error("Failed to rename key:", y);
|
|
340
1874
|
}
|
|
341
|
-
},
|
|
342
|
-
if (!
|
|
343
|
-
const
|
|
344
|
-
if (
|
|
345
|
-
const
|
|
346
|
-
return
|
|
1875
|
+
}, W = (i, c, y) => {
|
|
1876
|
+
if (!c || c === "root") return i;
|
|
1877
|
+
const b = c.split("."), E = H(i, b.slice(0, -1));
|
|
1878
|
+
if (b.length === 1) {
|
|
1879
|
+
const j = b[0];
|
|
1880
|
+
return E && typeof E == "object" && !Array.isArray(E) ? u(E, j, y) : E;
|
|
347
1881
|
}
|
|
348
|
-
let
|
|
349
|
-
for (let
|
|
350
|
-
const
|
|
351
|
-
Array.isArray(
|
|
1882
|
+
let _ = E;
|
|
1883
|
+
for (let j = 0; j < b.length - 1; j++) {
|
|
1884
|
+
const I = b[j];
|
|
1885
|
+
Array.isArray(_) ? _ = _[parseInt(I)] : _ = _[I];
|
|
352
1886
|
}
|
|
353
|
-
const
|
|
354
|
-
if (!Array.isArray(
|
|
355
|
-
const
|
|
356
|
-
|
|
1887
|
+
const B = b[b.length - 1];
|
|
1888
|
+
if (!Array.isArray(_) && _ && typeof _ == "object") {
|
|
1889
|
+
const j = u(_, B, y), I = b.slice(0, -1);
|
|
1890
|
+
I.length > 0 && v(E, I, j);
|
|
357
1891
|
}
|
|
358
|
-
return
|
|
359
|
-
},
|
|
360
|
-
if (
|
|
361
|
-
if (Array.isArray(
|
|
362
|
-
const
|
|
363
|
-
return
|
|
364
|
-
} else if (
|
|
365
|
-
const
|
|
366
|
-
return
|
|
1892
|
+
return E;
|
|
1893
|
+
}, H = (i, c) => {
|
|
1894
|
+
if (c.length === 0) return i;
|
|
1895
|
+
if (Array.isArray(i)) {
|
|
1896
|
+
const y = [...i], b = c[0], E = parseInt(b);
|
|
1897
|
+
return c.length === 1 || (y[E] = H(i[E], c.slice(1))), y;
|
|
1898
|
+
} else if (i && typeof i == "object") {
|
|
1899
|
+
const y = { ...i }, b = c[0];
|
|
1900
|
+
return c.length === 1 || (y[b] = H(i[b], c.slice(1))), y;
|
|
367
1901
|
}
|
|
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(
|
|
1902
|
+
return i;
|
|
1903
|
+
}, u = (i, c, y) => {
|
|
1904
|
+
if (!i || typeof i != "object" || Array.isArray(i))
|
|
1905
|
+
return i;
|
|
1906
|
+
const b = Object.keys(i), E = {};
|
|
1907
|
+
for (const _ of b)
|
|
1908
|
+
_ === c ? E[y] = i[_] : E[_] = i[_];
|
|
1909
|
+
return E;
|
|
1910
|
+
}, v = (i, c, y) => {
|
|
1911
|
+
let b = i;
|
|
1912
|
+
for (let _ = 0; _ < c.length - 1; _++) {
|
|
1913
|
+
const B = c[_];
|
|
1914
|
+
Array.isArray(b) ? b = b[parseInt(B)] : b = b[B];
|
|
381
1915
|
}
|
|
382
|
-
const
|
|
383
|
-
Array.isArray(
|
|
384
|
-
},
|
|
385
|
-
const
|
|
386
|
-
|
|
387
|
-
if (
|
|
388
|
-
const
|
|
389
|
-
|
|
390
|
-
} else if (
|
|
391
|
-
const
|
|
392
|
-
|
|
393
|
-
const
|
|
394
|
-
|
|
1916
|
+
const E = c[c.length - 1];
|
|
1917
|
+
Array.isArray(b) ? b[parseInt(E)] = y : b[E] = y;
|
|
1918
|
+
}, K = (i, c) => {
|
|
1919
|
+
const y = /* @__PURE__ */ new Set();
|
|
1920
|
+
f.value.forEach((b) => {
|
|
1921
|
+
if (b === i) {
|
|
1922
|
+
const E = i.split(".");
|
|
1923
|
+
E[E.length - 1] = c, y.add(E.join("."));
|
|
1924
|
+
} else if (b.startsWith(i + ".")) {
|
|
1925
|
+
const E = i.split(".");
|
|
1926
|
+
E[E.length - 1] = c;
|
|
1927
|
+
const _ = E.join("."), B = b.substring(i.length);
|
|
1928
|
+
y.add(_ + B);
|
|
395
1929
|
} else
|
|
396
|
-
|
|
397
|
-
}),
|
|
1930
|
+
y.add(b);
|
|
1931
|
+
}), f.value = y;
|
|
398
1932
|
};
|
|
399
|
-
return
|
|
1933
|
+
return e({
|
|
400
1934
|
// 核心操作方法
|
|
401
|
-
copyJson:
|
|
402
|
-
compressSource:
|
|
403
|
-
expandAll:
|
|
404
|
-
collapseAll:
|
|
405
|
-
toggleExpand:
|
|
406
|
-
updateValue:
|
|
407
|
-
updateKey:
|
|
1935
|
+
copyJson: q,
|
|
1936
|
+
compressSource: J,
|
|
1937
|
+
expandAll: F,
|
|
1938
|
+
collapseAll: Y,
|
|
1939
|
+
toggleExpand: Z,
|
|
1940
|
+
updateValue: Q,
|
|
1941
|
+
updateKey: z,
|
|
1942
|
+
// Filter 相关方法
|
|
1943
|
+
filter: S,
|
|
1944
|
+
clearFilter: C,
|
|
408
1945
|
// 状态访问方法
|
|
409
1946
|
isValidJson: () => m.value,
|
|
410
|
-
getParsedJson: () =>
|
|
411
|
-
|
|
412
|
-
|
|
1947
|
+
getParsedJson: () => a.value,
|
|
1948
|
+
getFilteredJson: () => d.value,
|
|
1949
|
+
getExpandedNodes: () => f.value,
|
|
1950
|
+
getParseError: () => l.value,
|
|
1951
|
+
getFilterError: () => h.value,
|
|
413
1952
|
// 工具方法
|
|
414
|
-
parseJson: (
|
|
415
|
-
copyValue: (
|
|
416
|
-
}), (
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
1953
|
+
parseJson: (i) => g(i),
|
|
1954
|
+
copyValue: (i) => V(i)
|
|
1955
|
+
}), (i, c) => (w(), A("div", {
|
|
1956
|
+
class: de(["json-format", `json-format--${p.value.name}`])
|
|
1957
|
+
}, [
|
|
1958
|
+
i.showToolbar ? (w(), A("div", tt, [
|
|
1959
|
+
P("div", rt, [
|
|
1960
|
+
P("button", {
|
|
420
1961
|
class: "json-format__btn json-format__btn--primary",
|
|
421
|
-
onClick:
|
|
1962
|
+
onClick: q,
|
|
422
1963
|
disabled: !m.value,
|
|
423
1964
|
title: "Copy JSON"
|
|
424
|
-
}, " 📋 Copy ", 8,
|
|
425
|
-
|
|
1965
|
+
}, " 📋 Copy ", 8, nt),
|
|
1966
|
+
P("button", {
|
|
426
1967
|
class: "json-format__btn json-format__btn--secondary",
|
|
427
|
-
onClick:
|
|
1968
|
+
onClick: F,
|
|
428
1969
|
disabled: !m.value,
|
|
429
1970
|
title: "Expand All"
|
|
430
|
-
}, " ⬇️ Expand All ", 8,
|
|
431
|
-
|
|
1971
|
+
}, " ⬇️ Expand All ", 8, ot),
|
|
1972
|
+
P("button", {
|
|
432
1973
|
class: "json-format__btn json-format__btn--secondary",
|
|
433
|
-
onClick:
|
|
1974
|
+
onClick: Y,
|
|
434
1975
|
disabled: !m.value,
|
|
435
1976
|
title: "Collapse All"
|
|
436
|
-
}, " ➡️ Collapse All ", 8,
|
|
437
|
-
|
|
1977
|
+
}, " ➡️ Collapse All ", 8, st),
|
|
1978
|
+
P("button", {
|
|
438
1979
|
class: "json-format__btn json-format__btn--secondary",
|
|
439
|
-
onClick:
|
|
1980
|
+
onClick: J,
|
|
440
1981
|
disabled: !m.value,
|
|
441
1982
|
title: "Compress JSON"
|
|
442
|
-
}, " 📦 Compress ", 8,
|
|
1983
|
+
}, " 📦 Compress ", 8, it)
|
|
443
1984
|
]),
|
|
444
|
-
|
|
445
|
-
m.value ? (
|
|
1985
|
+
P("div", at, [
|
|
1986
|
+
m.value ? (w(), A("span", lt, " ✅ Valid JSON ")) : (w(), A("span", ct, " ❌ Invalid JSON "))
|
|
446
1987
|
])
|
|
447
|
-
])) :
|
|
448
|
-
|
|
449
|
-
m.value ? (
|
|
450
|
-
|
|
451
|
-
|
|
1988
|
+
])) : N("", !0),
|
|
1989
|
+
P("div", ut, [
|
|
1990
|
+
m.value ? h.value ? (w(), A("div", ht, [
|
|
1991
|
+
c[1] || (c[1] = P("h4", null, "Filter Error:", -1)),
|
|
1992
|
+
P("pre", null, $(h.value), 1)
|
|
1993
|
+
])) : (w(), A("div", ft, [
|
|
1994
|
+
ue(qe, {
|
|
1995
|
+
value: k.value,
|
|
452
1996
|
"key-name": "",
|
|
453
1997
|
level: 0,
|
|
454
|
-
expanded:
|
|
1998
|
+
expanded: f.value,
|
|
455
1999
|
"is-last": !0,
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
2000
|
+
theme: p.value,
|
|
2001
|
+
"onUpdate:value": Q,
|
|
2002
|
+
onToggleExpand: Z,
|
|
2003
|
+
onCopy: V,
|
|
2004
|
+
"onUpdate:key": z
|
|
2005
|
+
}, null, 8, ["value", "expanded", "theme"])
|
|
2006
|
+
])) : (w(), A("div", dt, [
|
|
2007
|
+
c[0] || (c[0] = P("h4", null, "JSON Parse Error:", -1)),
|
|
2008
|
+
P("pre", null, $(l.value), 1)
|
|
464
2009
|
]))
|
|
465
2010
|
])
|
|
466
|
-
]));
|
|
2011
|
+
], 2));
|
|
467
2012
|
}
|
|
468
|
-
}),
|
|
469
|
-
|
|
470
|
-
const
|
|
471
|
-
|
|
2013
|
+
}), yt = /* @__PURE__ */ he(pt, [["__scopeId", "data-v-38157665"]]), bt = [yt], gt = (r) => {
|
|
2014
|
+
bt.forEach((e) => {
|
|
2015
|
+
const t = e.name || e.__name || "UnknownComponent";
|
|
2016
|
+
r.component(t, e);
|
|
472
2017
|
});
|
|
473
|
-
},
|
|
474
|
-
install:
|
|
2018
|
+
}, vt = {
|
|
2019
|
+
install: gt
|
|
475
2020
|
};
|
|
476
2021
|
export {
|
|
477
|
-
|
|
478
|
-
|
|
2022
|
+
yt as JsonFormat,
|
|
2023
|
+
vt as default
|
|
479
2024
|
};
|