@dan-uni/dan-any 1.3.0 → 1.3.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/README.md +1 -0
- package/dist/browser/index.min.js +13419 -1
- package/dist/browser/plugins/bili.min.js +77 -1
- package/dist/browser/plugins/index.min.js +2 -2
- package/dist/browser/plugins/stats.min.js +10 -1
- package/dist/browser/rslib-runtime.min.js +5 -5
- package/dist/browser/src/index.d.ts +22 -9
- package/dist/browser/src/utils/fileParser.d.ts +3 -0
- package/dist/node/index.js +1994 -1
- package/dist/node/plugins/bili.js +77 -1
- package/dist/node/plugins/index.js +2 -2
- package/dist/node/plugins/stats.js +10 -1
- package/dist/node/rslib-runtime.js +5 -5
- package/dist/node/src/index.d.ts +22 -9
- package/dist/node/src/utils/fileParser.d.ts +3 -0
- package/dist/umd/index.umd.min.js +1119 -328
- package/dist/umd/plugins/bili.umd.min.js +1120 -329
- package/dist/umd/plugins/index.umd.min.js +1120 -329
- package/dist/umd/src/index.d.ts +22 -9
- package/dist/umd/src/utils/fileParser.d.ts +3 -0
- package/package.json +5 -7
- package/src/index.test.ts +22 -0
- package/src/index.ts +223 -58
- package/src/utils/dm-gen.ts +1 -1
- package/src/utils/fileParser.ts +37 -0
- package/dist/browser/17.min.js +0 -13305
- package/dist/browser/705.min.js +0 -77
- package/dist/browser/898.min.js +0 -10
- package/dist/node/17.js +0 -1880
- package/dist/node/705.js +0 -77
- package/dist/node/898.js +0 -10
- /package/dist/browser/{17.min.js.LICENSE.txt → index.min.js.LICENSE.txt} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*!
|
|
1
|
+
/*! LICENSE: index.umd.min.js.LICENSE.txt */
|
|
2
2
|
(function(root, factory) {
|
|
3
3
|
if ('object' == typeof exports && 'object' == typeof module) module.exports = factory();
|
|
4
4
|
else if ('function' == typeof define && define.amd) define([], factory);
|
|
@@ -1511,7 +1511,7 @@
|
|
|
1511
1511
|
},
|
|
1512
1512
|
"../../node_modules/.pnpm/base16384@1.0.0/node_modules/base16384/lib/index.js" (__unused_rspack_module, exports1) {
|
|
1513
1513
|
"use strict";
|
|
1514
|
-
exports1.
|
|
1514
|
+
exports1.D4 = exports1.lF = void 0;
|
|
1515
1515
|
function align(input, output, sWidth, tWidth, sOffset, tOffset) {
|
|
1516
1516
|
let offset = 0;
|
|
1517
1517
|
let rest = 0;
|
|
@@ -1541,7 +1541,7 @@
|
|
|
1541
1541
|
output[output.length - 1] = input.length % 7 + 0x3d00;
|
|
1542
1542
|
return output;
|
|
1543
1543
|
}
|
|
1544
|
-
exports1.
|
|
1544
|
+
exports1.lF = encode;
|
|
1545
1545
|
function toUint16Array(source) {
|
|
1546
1546
|
const input = new Uint16Array(source.length);
|
|
1547
1547
|
for(let i = 0; i < source.length; i++)input[i] = source.charCodeAt(i);
|
|
@@ -1555,7 +1555,7 @@
|
|
|
1555
1555
|
align(input, output, 14, 8, 0x4e00, 0);
|
|
1556
1556
|
return output;
|
|
1557
1557
|
}
|
|
1558
|
-
exports1.
|
|
1558
|
+
exports1.D4 = decode;
|
|
1559
1559
|
},
|
|
1560
1560
|
"../../node_modules/.pnpm/base64-js@1.5.1/node_modules/base64-js/index.js" (__unused_rspack_module, exports1) {
|
|
1561
1561
|
"use strict";
|
|
@@ -2167,7 +2167,7 @@
|
|
|
2167
2167
|
];
|
|
2168
2168
|
remL = 1;
|
|
2169
2169
|
}
|
|
2170
|
-
}while ((xi++ < xL || null != rem[0]) && s--)
|
|
2170
|
+
}while ((xi++ < xL || null != rem[0]) && s--)
|
|
2171
2171
|
more = null != rem[0];
|
|
2172
2172
|
if (!qc[0]) qc.splice(0, 1);
|
|
2173
2173
|
}
|
|
@@ -3522,7 +3522,7 @@
|
|
|
3522
3522
|
});
|
|
3523
3523
|
assert(this._handle, 'zlib binding closed');
|
|
3524
3524
|
do var res = this._handle.writeSync(flushFlag, chunk, inOff, availInBefore, this._buffer, this._offset, availOutBefore);
|
|
3525
|
-
while (!this._hadError && callback(res[0], res[1]))
|
|
3525
|
+
while (!this._hadError && callback(res[0], res[1]))
|
|
3526
3526
|
if (this._hadError) throw error;
|
|
3527
3527
|
if (nread >= kMaxLength) {
|
|
3528
3528
|
_close(this);
|
|
@@ -6888,7 +6888,7 @@
|
|
|
6888
6888
|
do {
|
|
6889
6889
|
s1 = s1 + buf[pos++] | 0;
|
|
6890
6890
|
s2 = s2 + s1 | 0;
|
|
6891
|
-
}while (--n)
|
|
6891
|
+
}while (--n)
|
|
6892
6892
|
s1 %= 65521;
|
|
6893
6893
|
s2 %= 65521;
|
|
6894
6894
|
}
|
|
@@ -7069,7 +7069,7 @@
|
|
|
7069
7069
|
scan += 2;
|
|
7070
7070
|
match++;
|
|
7071
7071
|
do ;
|
|
7072
|
-
while (_win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && scan < strend)
|
|
7072
|
+
while (_win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && scan < strend)
|
|
7073
7073
|
len = MAX_MATCH - (strend - scan);
|
|
7074
7074
|
scan = strend - MAX_MATCH;
|
|
7075
7075
|
if (len > best_len) {
|
|
@@ -7079,7 +7079,7 @@
|
|
|
7079
7079
|
scan_end1 = _win[scan + best_len - 1];
|
|
7080
7080
|
scan_end = _win[scan + best_len];
|
|
7081
7081
|
}
|
|
7082
|
-
}while ((cur_match = prev[cur_match & wmask]) > limit && 0 !== --chain_length)
|
|
7082
|
+
}while ((cur_match = prev[cur_match & wmask]) > limit && 0 !== --chain_length)
|
|
7083
7083
|
if (best_len <= s.lookahead) return best_len;
|
|
7084
7084
|
return s.lookahead;
|
|
7085
7085
|
}
|
|
@@ -7098,13 +7098,13 @@
|
|
|
7098
7098
|
do {
|
|
7099
7099
|
m = s.head[--p];
|
|
7100
7100
|
s.head[p] = m >= _w_size ? m - _w_size : 0;
|
|
7101
|
-
}while (--n)
|
|
7101
|
+
}while (--n)
|
|
7102
7102
|
n = _w_size;
|
|
7103
7103
|
p = n;
|
|
7104
7104
|
do {
|
|
7105
7105
|
m = s.prev[--p];
|
|
7106
7106
|
s.prev[p] = m >= _w_size ? m - _w_size : 0;
|
|
7107
|
-
}while (--n)
|
|
7107
|
+
}while (--n)
|
|
7108
7108
|
more += _w_size;
|
|
7109
7109
|
}
|
|
7110
7110
|
if (0 === s.strm.avail_in) break;
|
|
@@ -7123,7 +7123,7 @@
|
|
|
7123
7123
|
if (s.lookahead + s.insert < MIN_MATCH) break;
|
|
7124
7124
|
}
|
|
7125
7125
|
}
|
|
7126
|
-
}while (s.lookahead < MIN_LOOKAHEAD && 0 !== s.strm.avail_in)
|
|
7126
|
+
}while (s.lookahead < MIN_LOOKAHEAD && 0 !== s.strm.avail_in)
|
|
7127
7127
|
}
|
|
7128
7128
|
function deflate_stored(s, flush) {
|
|
7129
7129
|
var max_block_size = 0xffff;
|
|
@@ -7186,7 +7186,7 @@
|
|
|
7186
7186
|
s.ins_h = (s.ins_h << s.hash_shift ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
|
|
7187
7187
|
hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
|
|
7188
7188
|
s.head[s.ins_h] = s.strstart;
|
|
7189
|
-
}while (0 !== --s.match_length)
|
|
7189
|
+
}while (0 !== --s.match_length)
|
|
7190
7190
|
s.strstart++;
|
|
7191
7191
|
} else {
|
|
7192
7192
|
s.strstart += s.match_length;
|
|
@@ -7249,7 +7249,7 @@
|
|
|
7249
7249
|
hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
|
|
7250
7250
|
s.head[s.ins_h] = s.strstart;
|
|
7251
7251
|
}
|
|
7252
|
-
while (0 !== --s.prev_length)
|
|
7252
|
+
while (0 !== --s.prev_length)
|
|
7253
7253
|
s.match_available = 0;
|
|
7254
7254
|
s.match_length = MIN_MATCH - 1;
|
|
7255
7255
|
s.strstart++;
|
|
@@ -7303,7 +7303,7 @@
|
|
|
7303
7303
|
if (prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan]) {
|
|
7304
7304
|
strend = s.strstart + MAX_MATCH;
|
|
7305
7305
|
do ;
|
|
7306
|
-
while (prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && scan < strend)
|
|
7306
|
+
while (prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && scan < strend)
|
|
7307
7307
|
s.match_length = MAX_MATCH - (strend - scan);
|
|
7308
7308
|
if (s.match_length > s.lookahead) s.match_length = s.lookahead;
|
|
7309
7309
|
}
|
|
@@ -7619,7 +7619,7 @@
|
|
|
7619
7619
|
}
|
|
7620
7620
|
val = s.gzindex < s.gzhead.name.length ? 0xff & s.gzhead.name.charCodeAt(s.gzindex++) : 0;
|
|
7621
7621
|
put_byte(s, val);
|
|
7622
|
-
}while (0 !== val)
|
|
7622
|
+
}while (0 !== val)
|
|
7623
7623
|
if (s.gzhead.hcrc && s.pending > beg) strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
|
|
7624
7624
|
if (0 === val) {
|
|
7625
7625
|
s.gzindex = 0;
|
|
@@ -7640,7 +7640,7 @@
|
|
|
7640
7640
|
}
|
|
7641
7641
|
val = s.gzindex < s.gzhead.comment.length ? 0xff & s.gzhead.comment.charCodeAt(s.gzindex++) : 0;
|
|
7642
7642
|
put_byte(s, val);
|
|
7643
|
-
}while (0 !== val)
|
|
7643
|
+
}while (0 !== val)
|
|
7644
7644
|
if (s.gzhead.hcrc && s.pending > beg) strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
|
|
7645
7645
|
if (0 === val) s.status = HCRC_STATE;
|
|
7646
7646
|
} else s.status = HCRC_STATE;
|
|
@@ -7757,7 +7757,7 @@
|
|
|
7757
7757
|
s.prev[str & s.w_mask] = s.head[s.ins_h];
|
|
7758
7758
|
s.head[s.ins_h] = str;
|
|
7759
7759
|
str++;
|
|
7760
|
-
}while (--n)
|
|
7760
|
+
}while (--n)
|
|
7761
7761
|
s.strstart = str;
|
|
7762
7762
|
s.lookahead = MIN_MATCH - 1;
|
|
7763
7763
|
fill_window(s);
|
|
@@ -7906,7 +7906,7 @@
|
|
|
7906
7906
|
if (op < len) {
|
|
7907
7907
|
len -= op;
|
|
7908
7908
|
do output[_out++] = s_window[from++];
|
|
7909
|
-
while (--op)
|
|
7909
|
+
while (--op)
|
|
7910
7910
|
from = _out - dist;
|
|
7911
7911
|
from_source = output;
|
|
7912
7912
|
}
|
|
@@ -7916,13 +7916,13 @@
|
|
|
7916
7916
|
if (op < len) {
|
|
7917
7917
|
len -= op;
|
|
7918
7918
|
do output[_out++] = s_window[from++];
|
|
7919
|
-
while (--op)
|
|
7919
|
+
while (--op)
|
|
7920
7920
|
from = 0;
|
|
7921
7921
|
if (wnext < len) {
|
|
7922
7922
|
op = wnext;
|
|
7923
7923
|
len -= op;
|
|
7924
7924
|
do output[_out++] = s_window[from++];
|
|
7925
|
-
while (--op)
|
|
7925
|
+
while (--op)
|
|
7926
7926
|
from = _out - dist;
|
|
7927
7927
|
from_source = output;
|
|
7928
7928
|
}
|
|
@@ -7932,7 +7932,7 @@
|
|
|
7932
7932
|
if (op < len) {
|
|
7933
7933
|
len -= op;
|
|
7934
7934
|
do output[_out++] = s_window[from++];
|
|
7935
|
-
while (--op)
|
|
7935
|
+
while (--op)
|
|
7936
7936
|
from = _out - dist;
|
|
7937
7937
|
from_source = output;
|
|
7938
7938
|
}
|
|
@@ -7954,7 +7954,7 @@
|
|
|
7954
7954
|
output[_out++] = output[from++];
|
|
7955
7955
|
output[_out++] = output[from++];
|
|
7956
7956
|
len -= 3;
|
|
7957
|
-
}while (len > 2)
|
|
7957
|
+
}while (len > 2)
|
|
7958
7958
|
if (len) {
|
|
7959
7959
|
output[_out++] = output[from++];
|
|
7960
7960
|
if (len > 1) output[_out++] = output[from++];
|
|
@@ -7983,7 +7983,7 @@
|
|
|
7983
7983
|
}
|
|
7984
7984
|
break;
|
|
7985
7985
|
}
|
|
7986
|
-
}while (_in < last && _out < end)
|
|
7986
|
+
}while (_in < last && _out < end)
|
|
7987
7987
|
len = bits >> 3;
|
|
7988
7988
|
_in -= len;
|
|
7989
7989
|
bits -= len << 3;
|
|
@@ -8424,7 +8424,7 @@
|
|
|
8424
8424
|
do {
|
|
8425
8425
|
len = input[next + copy++];
|
|
8426
8426
|
if (state.head && len && state.length < 65536) state.head.name += String.fromCharCode(len);
|
|
8427
|
-
}while (len && copy < have)
|
|
8427
|
+
}while (len && copy < have)
|
|
8428
8428
|
if (0x0200 & state.flags) state.check = crc32(state.check, input, copy, next);
|
|
8429
8429
|
have -= copy;
|
|
8430
8430
|
next += copy;
|
|
@@ -8439,7 +8439,7 @@
|
|
|
8439
8439
|
do {
|
|
8440
8440
|
len = input[next + copy++];
|
|
8441
8441
|
if (state.head && len && state.length < 65536) state.head.comment += String.fromCharCode(len);
|
|
8442
|
-
}while (len && copy < have)
|
|
8442
|
+
}while (len && copy < have)
|
|
8443
8443
|
if (0x0200 & state.flags) state.check = crc32(state.check, input, copy, next);
|
|
8444
8444
|
have -= copy;
|
|
8445
8445
|
next += copy;
|
|
@@ -8903,7 +8903,7 @@
|
|
|
8903
8903
|
left -= copy;
|
|
8904
8904
|
state.length -= copy;
|
|
8905
8905
|
do output[put++] = from_source[from++];
|
|
8906
|
-
while (--copy)
|
|
8906
|
+
while (--copy)
|
|
8907
8907
|
if (0 === state.length) state.mode = LEN;
|
|
8908
8908
|
break;
|
|
8909
8909
|
case LIT:
|
|
@@ -9265,7 +9265,7 @@
|
|
|
9265
9265
|
do {
|
|
9266
9266
|
fill -= incr;
|
|
9267
9267
|
table[next + (huff >> drop) + fill] = here_bits << 24 | here_op << 16 | here_val;
|
|
9268
|
-
}while (0 !== fill)
|
|
9268
|
+
}while (0 !== fill)
|
|
9269
9269
|
incr = 1 << len - 1;
|
|
9270
9270
|
while(huff & incr)incr >>= 1;
|
|
9271
9271
|
if (0 !== incr) {
|
|
@@ -9503,7 +9503,7 @@
|
|
|
9503
9503
|
res |= 1 & code;
|
|
9504
9504
|
code >>>= 1;
|
|
9505
9505
|
res <<= 1;
|
|
9506
|
-
}while (--len > 0)
|
|
9506
|
+
}while (--len > 0)
|
|
9507
9507
|
return res >>> 1;
|
|
9508
9508
|
}
|
|
9509
9509
|
function bi_flush(s) {
|
|
@@ -9558,7 +9558,7 @@
|
|
|
9558
9558
|
s.bl_count[bits + 1] += 2;
|
|
9559
9559
|
s.bl_count[max_length]--;
|
|
9560
9560
|
overflow -= 2;
|
|
9561
|
-
}while (overflow > 0)
|
|
9561
|
+
}while (overflow > 0)
|
|
9562
9562
|
for(bits = max_length; 0 !== bits; bits--){
|
|
9563
9563
|
n = s.bl_count[bits];
|
|
9564
9564
|
while(0 !== n){
|
|
@@ -9706,7 +9706,7 @@
|
|
|
9706
9706
|
send_bits(s, dist, extra);
|
|
9707
9707
|
}
|
|
9708
9708
|
}
|
|
9709
|
-
}while (lx < s.last_lit)
|
|
9709
|
+
}while (lx < s.last_lit)
|
|
9710
9710
|
send_code(s, END_BLOCK, ltree);
|
|
9711
9711
|
}
|
|
9712
9712
|
function build_tree(s, desc) {
|
|
@@ -9745,7 +9745,7 @@
|
|
|
9745
9745
|
tree[2 * n + 1] = tree[2 * m + 1] = node;
|
|
9746
9746
|
s.heap[1] = node++;
|
|
9747
9747
|
pqdownheap(s, tree, 1);
|
|
9748
|
-
}while (s.heap_len >= 2)
|
|
9748
|
+
}while (s.heap_len >= 2)
|
|
9749
9749
|
s.heap[--s.heap_max] = s.heap[1];
|
|
9750
9750
|
gen_bitlen(s, desc);
|
|
9751
9751
|
gen_codes(tree, max_code, s.bl_count);
|
|
@@ -9805,7 +9805,7 @@
|
|
|
9805
9805
|
nextlen = tree[(n + 1) * 2 + 1];
|
|
9806
9806
|
if (!(++count < max_count) || curlen !== nextlen) {
|
|
9807
9807
|
if (count < min_count) do send_code(s, curlen, s.bl_tree);
|
|
9808
|
-
while (0 !== --count)
|
|
9808
|
+
while (0 !== --count)
|
|
9809
9809
|
else if (0 !== curlen) {
|
|
9810
9810
|
if (curlen !== prevlen) {
|
|
9811
9811
|
send_code(s, curlen, s.bl_tree);
|
|
@@ -10169,7 +10169,7 @@
|
|
|
10169
10169
|
return 'Unknown encoding: ' + arg;
|
|
10170
10170
|
}, TypeError);
|
|
10171
10171
|
createErrorType('ERR_STREAM_UNSHIFT_AFTER_END_EVENT', 'stream.unshift() after end event');
|
|
10172
|
-
module1.exports.
|
|
10172
|
+
module1.exports.F = codes;
|
|
10173
10173
|
},
|
|
10174
10174
|
"../../node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/lib/_stream_duplex.js" (module1, __unused_rspack_exports, __webpack_require__) {
|
|
10175
10175
|
"use strict";
|
|
@@ -10278,7 +10278,7 @@
|
|
|
10278
10278
|
var BufferList = __webpack_require__("../../node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/lib/internal/streams/buffer_list.js");
|
|
10279
10279
|
var destroyImpl = __webpack_require__("../../node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/lib/internal/streams/destroy.js");
|
|
10280
10280
|
var _require = __webpack_require__("../../node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/lib/internal/streams/state.js"), getHighWaterMark = _require.getHighWaterMark;
|
|
10281
|
-
var _require$codes = __webpack_require__("../../node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/errors-browser.js").
|
|
10281
|
+
var _require$codes = __webpack_require__("../../node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/errors-browser.js").F, ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE, ERR_STREAM_PUSH_AFTER_EOF = _require$codes.ERR_STREAM_PUSH_AFTER_EOF, ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED, ERR_STREAM_UNSHIFT_AFTER_END_EVENT = _require$codes.ERR_STREAM_UNSHIFT_AFTER_END_EVENT;
|
|
10282
10282
|
var StringDecoder;
|
|
10283
10283
|
var createReadableStreamAsyncIterator;
|
|
10284
10284
|
var from;
|
|
@@ -10330,7 +10330,7 @@
|
|
|
10330
10330
|
this.decoder = null;
|
|
10331
10331
|
this.encoding = null;
|
|
10332
10332
|
if (options.encoding) {
|
|
10333
|
-
if (!StringDecoder) StringDecoder = __webpack_require__("../../node_modules/.pnpm/string_decoder@1.3.0/node_modules/string_decoder/lib/string_decoder.js").
|
|
10333
|
+
if (!StringDecoder) StringDecoder = __webpack_require__("../../node_modules/.pnpm/string_decoder@1.3.0/node_modules/string_decoder/lib/string_decoder.js").I;
|
|
10334
10334
|
this.decoder = new StringDecoder(options.encoding);
|
|
10335
10335
|
this.encoding = options.encoding;
|
|
10336
10336
|
}
|
|
@@ -10436,7 +10436,7 @@
|
|
|
10436
10436
|
return false === this._readableState.flowing;
|
|
10437
10437
|
};
|
|
10438
10438
|
Readable.prototype.setEncoding = function(enc) {
|
|
10439
|
-
if (!StringDecoder) StringDecoder = __webpack_require__("../../node_modules/.pnpm/string_decoder@1.3.0/node_modules/string_decoder/lib/string_decoder.js").
|
|
10439
|
+
if (!StringDecoder) StringDecoder = __webpack_require__("../../node_modules/.pnpm/string_decoder@1.3.0/node_modules/string_decoder/lib/string_decoder.js").I;
|
|
10440
10440
|
var decoder = new StringDecoder(enc);
|
|
10441
10441
|
this._readableState.decoder = decoder;
|
|
10442
10442
|
this._readableState.encoding = this._readableState.decoder.encoding;
|
|
@@ -10917,7 +10917,7 @@
|
|
|
10917
10917
|
"../../node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/lib/_stream_transform.js" (module1, __unused_rspack_exports, __webpack_require__) {
|
|
10918
10918
|
"use strict";
|
|
10919
10919
|
module1.exports = Transform;
|
|
10920
|
-
var _require$codes = __webpack_require__("../../node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/errors-browser.js").
|
|
10920
|
+
var _require$codes = __webpack_require__("../../node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/errors-browser.js").F, ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED, ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK, ERR_TRANSFORM_ALREADY_TRANSFORMING = _require$codes.ERR_TRANSFORM_ALREADY_TRANSFORMING, ERR_TRANSFORM_WITH_LENGTH_0 = _require$codes.ERR_TRANSFORM_WITH_LENGTH_0;
|
|
10921
10921
|
var Duplex = __webpack_require__("../../node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/lib/_stream_duplex.js");
|
|
10922
10922
|
__webpack_require__("../../node_modules/.pnpm/inherits@2.0.4/node_modules/inherits/inherits_browser.js")(Transform, Duplex);
|
|
10923
10923
|
function afterTransform(er, data) {
|
|
@@ -11025,7 +11025,7 @@
|
|
|
11025
11025
|
}
|
|
11026
11026
|
var destroyImpl = __webpack_require__("../../node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/lib/internal/streams/destroy.js");
|
|
11027
11027
|
var _require = __webpack_require__("../../node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/lib/internal/streams/state.js"), getHighWaterMark = _require.getHighWaterMark;
|
|
11028
|
-
var _require$codes = __webpack_require__("../../node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/errors-browser.js").
|
|
11028
|
+
var _require$codes = __webpack_require__("../../node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/errors-browser.js").F, ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE, ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED, ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK, ERR_STREAM_CANNOT_PIPE = _require$codes.ERR_STREAM_CANNOT_PIPE, ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED, ERR_STREAM_NULL_VALUES = _require$codes.ERR_STREAM_NULL_VALUES, ERR_STREAM_WRITE_AFTER_END = _require$codes.ERR_STREAM_WRITE_AFTER_END, ERR_UNKNOWN_ENCODING = _require$codes.ERR_UNKNOWN_ENCODING;
|
|
11029
11029
|
var errorOrDestroy = destroyImpl.errorOrDestroy;
|
|
11030
11030
|
__webpack_require__("../../node_modules/.pnpm/inherits@2.0.4/node_modules/inherits/inherits_browser.js")(Writable, Stream);
|
|
11031
11031
|
function nop() {}
|
|
@@ -11900,7 +11900,7 @@
|
|
|
11900
11900
|
},
|
|
11901
11901
|
"../../node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/lib/internal/streams/end-of-stream.js" (module1, __unused_rspack_exports, __webpack_require__) {
|
|
11902
11902
|
"use strict";
|
|
11903
|
-
var ERR_STREAM_PREMATURE_CLOSE = __webpack_require__("../../node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/errors-browser.js").
|
|
11903
|
+
var ERR_STREAM_PREMATURE_CLOSE = __webpack_require__("../../node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/errors-browser.js").F.ERR_STREAM_PREMATURE_CLOSE;
|
|
11904
11904
|
function once(callback) {
|
|
11905
11905
|
var called = false;
|
|
11906
11906
|
return function() {
|
|
@@ -11996,7 +11996,7 @@
|
|
|
11996
11996
|
callback.apply(void 0, arguments);
|
|
11997
11997
|
};
|
|
11998
11998
|
}
|
|
11999
|
-
var _require$codes = __webpack_require__("../../node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/errors-browser.js").
|
|
11999
|
+
var _require$codes = __webpack_require__("../../node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/errors-browser.js").F, ERR_MISSING_ARGS = _require$codes.ERR_MISSING_ARGS, ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED;
|
|
12000
12000
|
function noop(err) {
|
|
12001
12001
|
if (err) throw err;
|
|
12002
12002
|
}
|
|
@@ -12062,7 +12062,7 @@
|
|
|
12062
12062
|
},
|
|
12063
12063
|
"../../node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/lib/internal/streams/state.js" (module1, __unused_rspack_exports, __webpack_require__) {
|
|
12064
12064
|
"use strict";
|
|
12065
|
-
var ERR_INVALID_OPT_VALUE = __webpack_require__("../../node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/errors-browser.js").
|
|
12065
|
+
var ERR_INVALID_OPT_VALUE = __webpack_require__("../../node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/errors-browser.js").F.ERR_INVALID_OPT_VALUE;
|
|
12066
12066
|
function highWaterMarkFrom(options, isDuplex, duplexKey) {
|
|
12067
12067
|
return null != options.highWaterMark ? options.highWaterMark : isDuplex ? options[duplexKey] : null;
|
|
12068
12068
|
}
|
|
@@ -12276,7 +12276,7 @@
|
|
|
12276
12276
|
if ('string' != typeof nenc && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) throw new Error('Unknown encoding: ' + enc);
|
|
12277
12277
|
return nenc || enc;
|
|
12278
12278
|
}
|
|
12279
|
-
exports1.
|
|
12279
|
+
exports1.I = StringDecoder;
|
|
12280
12280
|
function StringDecoder(encoding) {
|
|
12281
12281
|
this.encoding = normalizeEncoding(encoding);
|
|
12282
12282
|
var nb;
|
|
@@ -14291,9 +14291,6 @@ and limitations under the License.
|
|
|
14291
14291
|
function IsJSON_isJSON(value) {
|
|
14292
14292
|
return 'string' == typeof value && isJSON_default()(value);
|
|
14293
14293
|
}
|
|
14294
|
-
function isObject(value) {
|
|
14295
|
-
return null != value && ('object' == typeof value || 'function' == typeof value) && !Array.isArray(value);
|
|
14296
|
-
}
|
|
14297
14294
|
var defaultContainer = new (function() {
|
|
14298
14295
|
function class_1() {
|
|
14299
14296
|
this.instances = [];
|
|
@@ -14359,6 +14356,7 @@ and limitations under the License.
|
|
|
14359
14356
|
this.always = args.validationOptions.always;
|
|
14360
14357
|
this.each = args.validationOptions.each;
|
|
14361
14358
|
this.context = args.validationOptions.context;
|
|
14359
|
+
this.validateIf = args.validationOptions.validateIf;
|
|
14362
14360
|
}
|
|
14363
14361
|
}
|
|
14364
14362
|
return ValidationMetadata;
|
|
@@ -14633,6 +14631,48 @@ and limitations under the License.
|
|
|
14633
14631
|
}
|
|
14634
14632
|
}, validationOptions);
|
|
14635
14633
|
}
|
|
14634
|
+
const nameStartChar = ':A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD';
|
|
14635
|
+
const nameChar = nameStartChar + '\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040';
|
|
14636
|
+
const nameRegexp = '[' + nameStartChar + '][' + nameChar + ']*';
|
|
14637
|
+
const regexName = new RegExp('^' + nameRegexp + '$');
|
|
14638
|
+
function getAllMatches(string, regex) {
|
|
14639
|
+
const matches = [];
|
|
14640
|
+
let match = regex.exec(string);
|
|
14641
|
+
while(match){
|
|
14642
|
+
const allmatches = [];
|
|
14643
|
+
allmatches.startIndex = regex.lastIndex - match[0].length;
|
|
14644
|
+
const len = match.length;
|
|
14645
|
+
for(let index = 0; index < len; index++)allmatches.push(match[index]);
|
|
14646
|
+
matches.push(allmatches);
|
|
14647
|
+
match = regex.exec(string);
|
|
14648
|
+
}
|
|
14649
|
+
return matches;
|
|
14650
|
+
}
|
|
14651
|
+
const isName = function(string) {
|
|
14652
|
+
const match = regexName.exec(string);
|
|
14653
|
+
return null != match;
|
|
14654
|
+
};
|
|
14655
|
+
function isExist(v) {
|
|
14656
|
+
return void 0 !== v;
|
|
14657
|
+
}
|
|
14658
|
+
const DANGEROUS_PROPERTY_NAMES = [
|
|
14659
|
+
'hasOwnProperty',
|
|
14660
|
+
'toString',
|
|
14661
|
+
'valueOf',
|
|
14662
|
+
'__defineGetter__',
|
|
14663
|
+
'__defineSetter__',
|
|
14664
|
+
'__lookupGetter__',
|
|
14665
|
+
'__lookupSetter__'
|
|
14666
|
+
];
|
|
14667
|
+
const criticalProperties = [
|
|
14668
|
+
"__proto__",
|
|
14669
|
+
"constructor",
|
|
14670
|
+
"prototype"
|
|
14671
|
+
];
|
|
14672
|
+
const defaultOnDangerousProperty = (name)=>{
|
|
14673
|
+
if (DANGEROUS_PROPERTY_NAMES.includes(name)) return "__" + name;
|
|
14674
|
+
return name;
|
|
14675
|
+
};
|
|
14636
14676
|
const OptionsBuilder_defaultOptions = {
|
|
14637
14677
|
preserveOrder: false,
|
|
14638
14678
|
attributeNamePrefix: '@_',
|
|
@@ -14670,8 +14710,18 @@ and limitations under the License.
|
|
|
14670
14710
|
updateTag: function(tagName, jPath, attrs) {
|
|
14671
14711
|
return tagName;
|
|
14672
14712
|
},
|
|
14673
|
-
captureMetaData: false
|
|
14713
|
+
captureMetaData: false,
|
|
14714
|
+
maxNestedTags: 100,
|
|
14715
|
+
strictReservedNames: true,
|
|
14716
|
+
jPath: true,
|
|
14717
|
+
onDangerousProperty: defaultOnDangerousProperty
|
|
14674
14718
|
};
|
|
14719
|
+
function validatePropertyName(propertyName, optionName) {
|
|
14720
|
+
if ('string' != typeof propertyName) return;
|
|
14721
|
+
const normalized = propertyName.toLowerCase();
|
|
14722
|
+
if (DANGEROUS_PROPERTY_NAMES.some((dangerous)=>normalized === dangerous.toLowerCase())) throw new Error(`[SECURITY] Invalid ${optionName}: "${propertyName}" is a reserved JavaScript keyword that could cause prototype pollution`);
|
|
14723
|
+
if (criticalProperties.some((dangerous)=>normalized === dangerous.toLowerCase())) throw new Error(`[SECURITY] Invalid ${optionName}: "${propertyName}" is a reserved JavaScript keyword that could cause prototype pollution`);
|
|
14724
|
+
}
|
|
14675
14725
|
function normalizeProcessEntities(value) {
|
|
14676
14726
|
if ('boolean' == typeof value) return {
|
|
14677
14727
|
enabled: value,
|
|
@@ -14679,15 +14729,17 @@ and limitations under the License.
|
|
|
14679
14729
|
maxExpansionDepth: 10,
|
|
14680
14730
|
maxTotalExpansions: 1000,
|
|
14681
14731
|
maxExpandedLength: 100000,
|
|
14732
|
+
maxEntityCount: 100,
|
|
14682
14733
|
allowedTags: null,
|
|
14683
14734
|
tagFilter: null
|
|
14684
14735
|
};
|
|
14685
14736
|
if ('object' == typeof value && null !== value) return {
|
|
14686
14737
|
enabled: false !== value.enabled,
|
|
14687
|
-
maxEntitySize: value.maxEntitySize ?? 10000,
|
|
14688
|
-
maxExpansionDepth: value.maxExpansionDepth ?? 10,
|
|
14689
|
-
maxTotalExpansions: value.maxTotalExpansions ?? 1000,
|
|
14690
|
-
maxExpandedLength: value.maxExpandedLength ?? 100000,
|
|
14738
|
+
maxEntitySize: Math.max(1, value.maxEntitySize ?? 10000),
|
|
14739
|
+
maxExpansionDepth: Math.max(1, value.maxExpansionDepth ?? 10),
|
|
14740
|
+
maxTotalExpansions: Math.max(1, value.maxTotalExpansions ?? 1000),
|
|
14741
|
+
maxExpandedLength: Math.max(1, value.maxExpandedLength ?? 100000),
|
|
14742
|
+
maxEntityCount: Math.max(1, value.maxEntityCount ?? 100),
|
|
14691
14743
|
allowedTags: value.allowedTags ?? null,
|
|
14692
14744
|
tagFilter: value.tagFilter ?? null
|
|
14693
14745
|
};
|
|
@@ -14695,40 +14747,44 @@ and limitations under the License.
|
|
|
14695
14747
|
}
|
|
14696
14748
|
const buildOptions = function(options) {
|
|
14697
14749
|
const built = Object.assign({}, OptionsBuilder_defaultOptions, options);
|
|
14750
|
+
const propertyNameOptions = [
|
|
14751
|
+
{
|
|
14752
|
+
value: built.attributeNamePrefix,
|
|
14753
|
+
name: 'attributeNamePrefix'
|
|
14754
|
+
},
|
|
14755
|
+
{
|
|
14756
|
+
value: built.attributesGroupName,
|
|
14757
|
+
name: 'attributesGroupName'
|
|
14758
|
+
},
|
|
14759
|
+
{
|
|
14760
|
+
value: built.textNodeName,
|
|
14761
|
+
name: 'textNodeName'
|
|
14762
|
+
},
|
|
14763
|
+
{
|
|
14764
|
+
value: built.cdataPropName,
|
|
14765
|
+
name: 'cdataPropName'
|
|
14766
|
+
},
|
|
14767
|
+
{
|
|
14768
|
+
value: built.commentPropName,
|
|
14769
|
+
name: 'commentPropName'
|
|
14770
|
+
}
|
|
14771
|
+
];
|
|
14772
|
+
for (const { value, name } of propertyNameOptions)if (value) validatePropertyName(value, name);
|
|
14773
|
+
if (null === built.onDangerousProperty) built.onDangerousProperty = defaultOnDangerousProperty;
|
|
14698
14774
|
built.processEntities = normalizeProcessEntities(built.processEntities);
|
|
14775
|
+
if (built.stopNodes && Array.isArray(built.stopNodes)) built.stopNodes = built.stopNodes.map((node)=>{
|
|
14776
|
+
if ('string' == typeof node && node.startsWith('*.')) return '..' + node.substring(2);
|
|
14777
|
+
return node;
|
|
14778
|
+
});
|
|
14699
14779
|
return built;
|
|
14700
14780
|
};
|
|
14701
|
-
const nameStartChar = ':A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD';
|
|
14702
|
-
const nameChar = nameStartChar + '\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040';
|
|
14703
|
-
const nameRegexp = '[' + nameStartChar + '][' + nameChar + ']*';
|
|
14704
|
-
const regexName = new RegExp('^' + nameRegexp + '$');
|
|
14705
|
-
function getAllMatches(string, regex) {
|
|
14706
|
-
const matches = [];
|
|
14707
|
-
let match = regex.exec(string);
|
|
14708
|
-
while(match){
|
|
14709
|
-
const allmatches = [];
|
|
14710
|
-
allmatches.startIndex = regex.lastIndex - match[0].length;
|
|
14711
|
-
const len = match.length;
|
|
14712
|
-
for(let index = 0; index < len; index++)allmatches.push(match[index]);
|
|
14713
|
-
matches.push(allmatches);
|
|
14714
|
-
match = regex.exec(string);
|
|
14715
|
-
}
|
|
14716
|
-
return matches;
|
|
14717
|
-
}
|
|
14718
|
-
const isName = function(string) {
|
|
14719
|
-
const match = regexName.exec(string);
|
|
14720
|
-
return null != match;
|
|
14721
|
-
};
|
|
14722
|
-
function isExist(v) {
|
|
14723
|
-
return void 0 !== v;
|
|
14724
|
-
}
|
|
14725
14781
|
let METADATA_SYMBOL;
|
|
14726
14782
|
METADATA_SYMBOL = "function" != typeof Symbol ? "@@xmlMetadata" : Symbol("XML Node Metadata");
|
|
14727
14783
|
class XmlNode {
|
|
14728
14784
|
constructor(tagname){
|
|
14729
14785
|
this.tagname = tagname;
|
|
14730
14786
|
this.child = [];
|
|
14731
|
-
this[":@"] =
|
|
14787
|
+
this[":@"] = Object.create(null);
|
|
14732
14788
|
}
|
|
14733
14789
|
add(key, val) {
|
|
14734
14790
|
if ("__proto__" === key) key = "#__proto__";
|
|
@@ -14759,7 +14815,8 @@ and limitations under the License.
|
|
|
14759
14815
|
this.options = options;
|
|
14760
14816
|
}
|
|
14761
14817
|
readDocType(xmlData, i) {
|
|
14762
|
-
const entities =
|
|
14818
|
+
const entities = Object.create(null);
|
|
14819
|
+
let entityCount = 0;
|
|
14763
14820
|
if ('O' === xmlData[i + 3] && 'C' === xmlData[i + 4] && 'T' === xmlData[i + 5] && 'Y' === xmlData[i + 6] && 'P' === xmlData[i + 7] && 'E' === xmlData[i + 8]) {
|
|
14764
14821
|
i += 9;
|
|
14765
14822
|
let angleBracketsCount = 1;
|
|
@@ -14780,11 +14837,13 @@ and limitations under the License.
|
|
|
14780
14837
|
let entityName, val;
|
|
14781
14838
|
[entityName, val, i] = this.readEntityExp(xmlData, i + 1, this.suppressValidationErr);
|
|
14782
14839
|
if (-1 === val.indexOf("&")) {
|
|
14783
|
-
|
|
14840
|
+
if (false !== this.options.enabled && null != this.options.maxEntityCount && entityCount >= this.options.maxEntityCount) throw new Error(`Entity count (${entityCount + 1}) exceeds maximum allowed (${this.options.maxEntityCount})`);
|
|
14841
|
+
const escaped = entityName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
14784
14842
|
entities[entityName] = {
|
|
14785
14843
|
regx: RegExp(`&${escaped};`, "g"),
|
|
14786
14844
|
val: val
|
|
14787
14845
|
};
|
|
14846
|
+
entityCount++;
|
|
14788
14847
|
}
|
|
14789
14848
|
} else if (hasBody && hasSeq(xmlData, "!ELEMENT", i)) {
|
|
14790
14849
|
i += 8;
|
|
@@ -14808,11 +14867,9 @@ and limitations under the License.
|
|
|
14808
14867
|
}
|
|
14809
14868
|
readEntityExp(xmlData, i) {
|
|
14810
14869
|
i = skipWhitespace(xmlData, i);
|
|
14811
|
-
|
|
14812
|
-
while(i < xmlData.length && !/\s/.test(xmlData[i]) && '"' !== xmlData[i] && "'" !== xmlData[i])
|
|
14813
|
-
|
|
14814
|
-
i++;
|
|
14815
|
-
}
|
|
14870
|
+
const startIndex = i;
|
|
14871
|
+
while(i < xmlData.length && !/\s/.test(xmlData[i]) && '"' !== xmlData[i] && "'" !== xmlData[i])i++;
|
|
14872
|
+
let entityName = xmlData.substring(startIndex, i);
|
|
14816
14873
|
validateEntityName(entityName);
|
|
14817
14874
|
i = skipWhitespace(xmlData, i);
|
|
14818
14875
|
if (!this.suppressValidationErr) {
|
|
@@ -14821,7 +14878,7 @@ and limitations under the License.
|
|
|
14821
14878
|
}
|
|
14822
14879
|
let entityValue = "";
|
|
14823
14880
|
[i, entityValue] = this.readIdentifierVal(xmlData, i, "entity");
|
|
14824
|
-
if (false !== this.options.enabled && this.options.maxEntitySize && entityValue.length > this.options.maxEntitySize) throw new Error(`Entity "${entityName}" size (${entityValue.length}) exceeds maximum allowed size (${this.options.maxEntitySize})`);
|
|
14881
|
+
if (false !== this.options.enabled && null != this.options.maxEntitySize && entityValue.length > this.options.maxEntitySize) throw new Error(`Entity "${entityName}" size (${entityValue.length}) exceeds maximum allowed size (${this.options.maxEntitySize})`);
|
|
14825
14882
|
i--;
|
|
14826
14883
|
return [
|
|
14827
14884
|
entityName,
|
|
@@ -14831,11 +14888,9 @@ and limitations under the License.
|
|
|
14831
14888
|
}
|
|
14832
14889
|
readNotationExp(xmlData, i) {
|
|
14833
14890
|
i = skipWhitespace(xmlData, i);
|
|
14834
|
-
|
|
14835
|
-
while(i < xmlData.length && !/\s/.test(xmlData[i]))
|
|
14836
|
-
|
|
14837
|
-
i++;
|
|
14838
|
-
}
|
|
14891
|
+
const startIndex = i;
|
|
14892
|
+
while(i < xmlData.length && !/\s/.test(xmlData[i]))i++;
|
|
14893
|
+
let notationName = xmlData.substring(startIndex, i);
|
|
14839
14894
|
this.suppressValidationErr || validateEntityName(notationName);
|
|
14840
14895
|
i = skipWhitespace(xmlData, i);
|
|
14841
14896
|
const identifierType = xmlData.substring(i, i + 6).toUpperCase();
|
|
@@ -14864,10 +14919,9 @@ and limitations under the License.
|
|
|
14864
14919
|
const startChar = xmlData[i];
|
|
14865
14920
|
if ('"' !== startChar && "'" !== startChar) throw new Error(`Expected quoted string, found "${startChar}"`);
|
|
14866
14921
|
i++;
|
|
14867
|
-
|
|
14868
|
-
|
|
14869
|
-
|
|
14870
|
-
}
|
|
14922
|
+
const startIndex = i;
|
|
14923
|
+
while(i < xmlData.length && xmlData[i] !== startChar)i++;
|
|
14924
|
+
identifierVal = xmlData.substring(startIndex, i);
|
|
14871
14925
|
if (xmlData[i] !== startChar) throw new Error(`Unterminated ${type} value`);
|
|
14872
14926
|
i++;
|
|
14873
14927
|
return [
|
|
@@ -14877,11 +14931,9 @@ and limitations under the License.
|
|
|
14877
14931
|
}
|
|
14878
14932
|
readElementExp(xmlData, i) {
|
|
14879
14933
|
i = skipWhitespace(xmlData, i);
|
|
14880
|
-
|
|
14881
|
-
while(i < xmlData.length && !/\s/.test(xmlData[i]))
|
|
14882
|
-
|
|
14883
|
-
i++;
|
|
14884
|
-
}
|
|
14934
|
+
const startIndex = i;
|
|
14935
|
+
while(i < xmlData.length && !/\s/.test(xmlData[i]))i++;
|
|
14936
|
+
let elementName = xmlData.substring(startIndex, i);
|
|
14885
14937
|
if (!this.suppressValidationErr && !isName(elementName)) throw new Error(`Invalid element name: "${elementName}"`);
|
|
14886
14938
|
i = skipWhitespace(xmlData, i);
|
|
14887
14939
|
let contentModel = "";
|
|
@@ -14889,10 +14941,9 @@ and limitations under the License.
|
|
|
14889
14941
|
else if ("A" === xmlData[i] && hasSeq(xmlData, "NY", i)) i += 2;
|
|
14890
14942
|
else if ("(" === xmlData[i]) {
|
|
14891
14943
|
i++;
|
|
14892
|
-
|
|
14893
|
-
|
|
14894
|
-
|
|
14895
|
-
}
|
|
14944
|
+
const startIndex = i;
|
|
14945
|
+
while(i < xmlData.length && ")" !== xmlData[i])i++;
|
|
14946
|
+
contentModel = xmlData.substring(startIndex, i);
|
|
14896
14947
|
if (")" !== xmlData[i]) throw new Error("Unterminated content model");
|
|
14897
14948
|
} else if (!this.suppressValidationErr) throw new Error(`Invalid Element Expression, found "${xmlData[i]}"`);
|
|
14898
14949
|
return {
|
|
@@ -14903,18 +14954,14 @@ and limitations under the License.
|
|
|
14903
14954
|
}
|
|
14904
14955
|
readAttlistExp(xmlData, i) {
|
|
14905
14956
|
i = skipWhitespace(xmlData, i);
|
|
14906
|
-
let
|
|
14907
|
-
while(i < xmlData.length && !/\s/.test(xmlData[i]))
|
|
14908
|
-
|
|
14909
|
-
i++;
|
|
14910
|
-
}
|
|
14957
|
+
let startIndex = i;
|
|
14958
|
+
while(i < xmlData.length && !/\s/.test(xmlData[i]))i++;
|
|
14959
|
+
let elementName = xmlData.substring(startIndex, i);
|
|
14911
14960
|
validateEntityName(elementName);
|
|
14912
14961
|
i = skipWhitespace(xmlData, i);
|
|
14913
|
-
|
|
14914
|
-
while(i < xmlData.length && !/\s/.test(xmlData[i]))
|
|
14915
|
-
|
|
14916
|
-
i++;
|
|
14917
|
-
}
|
|
14962
|
+
startIndex = i;
|
|
14963
|
+
while(i < xmlData.length && !/\s/.test(xmlData[i]))i++;
|
|
14964
|
+
let attributeName = xmlData.substring(startIndex, i);
|
|
14918
14965
|
if (!validateEntityName(attributeName)) throw new Error(`Invalid attribute name: "${attributeName}"`);
|
|
14919
14966
|
i = skipWhitespace(xmlData, i);
|
|
14920
14967
|
let attributeType = "";
|
|
@@ -14926,11 +14973,9 @@ and limitations under the License.
|
|
|
14926
14973
|
i++;
|
|
14927
14974
|
let allowedNotations = [];
|
|
14928
14975
|
while(i < xmlData.length && ")" !== xmlData[i]){
|
|
14929
|
-
|
|
14930
|
-
while(i < xmlData.length && "|" !== xmlData[i] && ")" !== xmlData[i])
|
|
14931
|
-
|
|
14932
|
-
i++;
|
|
14933
|
-
}
|
|
14976
|
+
const startIndex = i;
|
|
14977
|
+
while(i < xmlData.length && "|" !== xmlData[i] && ")" !== xmlData[i])i++;
|
|
14978
|
+
let notation = xmlData.substring(startIndex, i);
|
|
14934
14979
|
notation = notation.trim();
|
|
14935
14980
|
if (!validateEntityName(notation)) throw new Error(`Invalid notation name: "${notation}"`);
|
|
14936
14981
|
allowedNotations.push(notation);
|
|
@@ -14943,10 +14988,9 @@ and limitations under the License.
|
|
|
14943
14988
|
i++;
|
|
14944
14989
|
attributeType += " (" + allowedNotations.join("|") + ")";
|
|
14945
14990
|
} else {
|
|
14946
|
-
|
|
14947
|
-
|
|
14948
|
-
|
|
14949
|
-
}
|
|
14991
|
+
const startIndex = i;
|
|
14992
|
+
while(i < xmlData.length && !/\s/.test(xmlData[i]))i++;
|
|
14993
|
+
attributeType += xmlData.substring(startIndex, i);
|
|
14950
14994
|
const validTypes = [
|
|
14951
14995
|
"CDATA",
|
|
14952
14996
|
"ID",
|
|
@@ -14995,7 +15039,8 @@ and limitations under the License.
|
|
|
14995
15039
|
hex: true,
|
|
14996
15040
|
leadingZeros: true,
|
|
14997
15041
|
decimalPoint: "\.",
|
|
14998
|
-
eNotation: true
|
|
15042
|
+
eNotation: true,
|
|
15043
|
+
infinity: "original"
|
|
14999
15044
|
};
|
|
15000
15045
|
function toNumber(str, options = {}) {
|
|
15001
15046
|
options = Object.assign({}, consider, options);
|
|
@@ -15005,6 +15050,7 @@ and limitations under the License.
|
|
|
15005
15050
|
{
|
|
15006
15051
|
if ("0" === str) return 0;
|
|
15007
15052
|
if (options.hex && hexRegex.test(trimmedStr)) return parse_int(trimmedStr, 16);
|
|
15053
|
+
if (!isFinite(trimmedStr)) return handleInfinity(str, Number(trimmedStr), options);
|
|
15008
15054
|
if (trimmedStr.includes('e') || trimmedStr.includes('E')) return resolveEnotation(str, trimmedStr, options);
|
|
15009
15055
|
const match = numRegex.exec(trimmedStr);
|
|
15010
15056
|
if (!match) return str;
|
|
@@ -15043,6 +15089,7 @@ and limitations under the License.
|
|
|
15043
15089
|
const eAdjacentToLeadingZeros = sign ? str[leadingZeros.length + 1] === eChar : str[leadingZeros.length] === eChar;
|
|
15044
15090
|
if (leadingZeros.length > 1 && eAdjacentToLeadingZeros) return str;
|
|
15045
15091
|
if (1 === leadingZeros.length && (notation[3].startsWith(`.${eChar}`) || notation[3][0] === eChar)) return Number(trimmedStr);
|
|
15092
|
+
if (!(leadingZeros.length > 0)) return Number(trimmedStr);
|
|
15046
15093
|
if (!options.leadingZeros || !!eAdjacentToLeadingZeros) return str;
|
|
15047
15094
|
trimmedStr = (notation[1] || "") + notation[3];
|
|
15048
15095
|
return Number(trimmedStr);
|
|
@@ -15063,6 +15110,20 @@ and limitations under the License.
|
|
|
15063
15110
|
if (window && window.parseInt) return window.parseInt(numStr, base);
|
|
15064
15111
|
throw new Error("parseInt, Number.parseInt, window.parseInt are not supported");
|
|
15065
15112
|
}
|
|
15113
|
+
function handleInfinity(str, num, options) {
|
|
15114
|
+
const isPositive = num === 1 / 0;
|
|
15115
|
+
switch(options.infinity.toLowerCase()){
|
|
15116
|
+
case "null":
|
|
15117
|
+
return null;
|
|
15118
|
+
case "infinity":
|
|
15119
|
+
return num;
|
|
15120
|
+
case "string":
|
|
15121
|
+
return isPositive ? "Infinity" : "-Infinity";
|
|
15122
|
+
case "original":
|
|
15123
|
+
default:
|
|
15124
|
+
return str;
|
|
15125
|
+
}
|
|
15126
|
+
}
|
|
15066
15127
|
function getIgnoreAttributesFn(ignoreAttributes) {
|
|
15067
15128
|
if ('function' == typeof ignoreAttributes) return ignoreAttributes;
|
|
15068
15129
|
if (Array.isArray(ignoreAttributes)) return (attrName)=>{
|
|
@@ -15073,6 +15134,329 @@ and limitations under the License.
|
|
|
15073
15134
|
};
|
|
15074
15135
|
return ()=>false;
|
|
15075
15136
|
}
|
|
15137
|
+
const MUTATING_METHODS = new Set([
|
|
15138
|
+
'push',
|
|
15139
|
+
'pop',
|
|
15140
|
+
'reset',
|
|
15141
|
+
'updateCurrent',
|
|
15142
|
+
'restore'
|
|
15143
|
+
]);
|
|
15144
|
+
class Matcher {
|
|
15145
|
+
constructor(options = {}){
|
|
15146
|
+
this.separator = options.separator || '.';
|
|
15147
|
+
this.path = [];
|
|
15148
|
+
this.siblingStacks = [];
|
|
15149
|
+
}
|
|
15150
|
+
push(tagName, attrValues = null, namespace = null) {
|
|
15151
|
+
if (this.path.length > 0) {
|
|
15152
|
+
const prev = this.path[this.path.length - 1];
|
|
15153
|
+
prev.values = void 0;
|
|
15154
|
+
}
|
|
15155
|
+
const currentLevel = this.path.length;
|
|
15156
|
+
if (!this.siblingStacks[currentLevel]) this.siblingStacks[currentLevel] = new Map();
|
|
15157
|
+
const siblings = this.siblingStacks[currentLevel];
|
|
15158
|
+
const siblingKey = namespace ? `${namespace}:${tagName}` : tagName;
|
|
15159
|
+
const counter = siblings.get(siblingKey) || 0;
|
|
15160
|
+
let position = 0;
|
|
15161
|
+
for (const count of siblings.values())position += count;
|
|
15162
|
+
siblings.set(siblingKey, counter + 1);
|
|
15163
|
+
const node = {
|
|
15164
|
+
tag: tagName,
|
|
15165
|
+
position: position,
|
|
15166
|
+
counter: counter
|
|
15167
|
+
};
|
|
15168
|
+
if (null != namespace) node.namespace = namespace;
|
|
15169
|
+
if (null != attrValues) node.values = attrValues;
|
|
15170
|
+
this.path.push(node);
|
|
15171
|
+
}
|
|
15172
|
+
pop() {
|
|
15173
|
+
if (0 === this.path.length) return;
|
|
15174
|
+
const node = this.path.pop();
|
|
15175
|
+
if (this.siblingStacks.length > this.path.length + 1) this.siblingStacks.length = this.path.length + 1;
|
|
15176
|
+
return node;
|
|
15177
|
+
}
|
|
15178
|
+
updateCurrent(attrValues) {
|
|
15179
|
+
if (this.path.length > 0) {
|
|
15180
|
+
const current = this.path[this.path.length - 1];
|
|
15181
|
+
if (null != attrValues) current.values = attrValues;
|
|
15182
|
+
}
|
|
15183
|
+
}
|
|
15184
|
+
getCurrentTag() {
|
|
15185
|
+
return this.path.length > 0 ? this.path[this.path.length - 1].tag : void 0;
|
|
15186
|
+
}
|
|
15187
|
+
getCurrentNamespace() {
|
|
15188
|
+
return this.path.length > 0 ? this.path[this.path.length - 1].namespace : void 0;
|
|
15189
|
+
}
|
|
15190
|
+
getAttrValue(attrName) {
|
|
15191
|
+
if (0 === this.path.length) return;
|
|
15192
|
+
const current = this.path[this.path.length - 1];
|
|
15193
|
+
return current.values?.[attrName];
|
|
15194
|
+
}
|
|
15195
|
+
hasAttr(attrName) {
|
|
15196
|
+
if (0 === this.path.length) return false;
|
|
15197
|
+
const current = this.path[this.path.length - 1];
|
|
15198
|
+
return void 0 !== current.values && attrName in current.values;
|
|
15199
|
+
}
|
|
15200
|
+
getPosition() {
|
|
15201
|
+
if (0 === this.path.length) return -1;
|
|
15202
|
+
return this.path[this.path.length - 1].position ?? 0;
|
|
15203
|
+
}
|
|
15204
|
+
getCounter() {
|
|
15205
|
+
if (0 === this.path.length) return -1;
|
|
15206
|
+
return this.path[this.path.length - 1].counter ?? 0;
|
|
15207
|
+
}
|
|
15208
|
+
getIndex() {
|
|
15209
|
+
return this.getPosition();
|
|
15210
|
+
}
|
|
15211
|
+
getDepth() {
|
|
15212
|
+
return this.path.length;
|
|
15213
|
+
}
|
|
15214
|
+
toString(separator, includeNamespace = true) {
|
|
15215
|
+
const sep = separator || this.separator;
|
|
15216
|
+
return this.path.map((n)=>{
|
|
15217
|
+
if (includeNamespace && n.namespace) return `${n.namespace}:${n.tag}`;
|
|
15218
|
+
return n.tag;
|
|
15219
|
+
}).join(sep);
|
|
15220
|
+
}
|
|
15221
|
+
toArray() {
|
|
15222
|
+
return this.path.map((n)=>n.tag);
|
|
15223
|
+
}
|
|
15224
|
+
reset() {
|
|
15225
|
+
this.path = [];
|
|
15226
|
+
this.siblingStacks = [];
|
|
15227
|
+
}
|
|
15228
|
+
matches(expression) {
|
|
15229
|
+
const segments = expression.segments;
|
|
15230
|
+
if (0 === segments.length) return false;
|
|
15231
|
+
if (expression.hasDeepWildcard()) return this._matchWithDeepWildcard(segments);
|
|
15232
|
+
return this._matchSimple(segments);
|
|
15233
|
+
}
|
|
15234
|
+
_matchSimple(segments) {
|
|
15235
|
+
if (this.path.length !== segments.length) return false;
|
|
15236
|
+
for(let i = 0; i < segments.length; i++){
|
|
15237
|
+
const segment = segments[i];
|
|
15238
|
+
const node = this.path[i];
|
|
15239
|
+
const isCurrentNode = i === this.path.length - 1;
|
|
15240
|
+
if (!this._matchSegment(segment, node, isCurrentNode)) return false;
|
|
15241
|
+
}
|
|
15242
|
+
return true;
|
|
15243
|
+
}
|
|
15244
|
+
_matchWithDeepWildcard(segments) {
|
|
15245
|
+
let pathIdx = this.path.length - 1;
|
|
15246
|
+
let segIdx = segments.length - 1;
|
|
15247
|
+
while(segIdx >= 0 && pathIdx >= 0){
|
|
15248
|
+
const segment = segments[segIdx];
|
|
15249
|
+
if ('deep-wildcard' === segment.type) {
|
|
15250
|
+
segIdx--;
|
|
15251
|
+
if (segIdx < 0) return true;
|
|
15252
|
+
const nextSeg = segments[segIdx];
|
|
15253
|
+
let found = false;
|
|
15254
|
+
for(let i = pathIdx; i >= 0; i--){
|
|
15255
|
+
const isCurrentNode = i === this.path.length - 1;
|
|
15256
|
+
if (this._matchSegment(nextSeg, this.path[i], isCurrentNode)) {
|
|
15257
|
+
pathIdx = i - 1;
|
|
15258
|
+
segIdx--;
|
|
15259
|
+
found = true;
|
|
15260
|
+
break;
|
|
15261
|
+
}
|
|
15262
|
+
}
|
|
15263
|
+
if (!found) return false;
|
|
15264
|
+
} else {
|
|
15265
|
+
const isCurrentNode = pathIdx === this.path.length - 1;
|
|
15266
|
+
if (!this._matchSegment(segment, this.path[pathIdx], isCurrentNode)) return false;
|
|
15267
|
+
pathIdx--;
|
|
15268
|
+
segIdx--;
|
|
15269
|
+
}
|
|
15270
|
+
}
|
|
15271
|
+
return segIdx < 0;
|
|
15272
|
+
}
|
|
15273
|
+
_matchSegment(segment, node, isCurrentNode) {
|
|
15274
|
+
if ('*' !== segment.tag && segment.tag !== node.tag) return false;
|
|
15275
|
+
if (void 0 !== segment.namespace) {
|
|
15276
|
+
if ('*' !== segment.namespace && segment.namespace !== node.namespace) return false;
|
|
15277
|
+
}
|
|
15278
|
+
if (void 0 !== segment.attrName) {
|
|
15279
|
+
if (!isCurrentNode) return false;
|
|
15280
|
+
if (!node.values || !(segment.attrName in node.values)) return false;
|
|
15281
|
+
if (void 0 !== segment.attrValue) {
|
|
15282
|
+
const actualValue = node.values[segment.attrName];
|
|
15283
|
+
if (String(actualValue) !== String(segment.attrValue)) return false;
|
|
15284
|
+
}
|
|
15285
|
+
}
|
|
15286
|
+
if (void 0 !== segment.position) {
|
|
15287
|
+
if (!isCurrentNode) return false;
|
|
15288
|
+
const counter = node.counter ?? 0;
|
|
15289
|
+
if ('first' === segment.position && 0 !== counter) return false;
|
|
15290
|
+
if ('odd' === segment.position && counter % 2 !== 1) return false;
|
|
15291
|
+
if ('even' === segment.position && counter % 2 !== 0) return false;
|
|
15292
|
+
else if ('nth' === segment.position) {
|
|
15293
|
+
if (counter !== segment.positionValue) return false;
|
|
15294
|
+
}
|
|
15295
|
+
}
|
|
15296
|
+
return true;
|
|
15297
|
+
}
|
|
15298
|
+
snapshot() {
|
|
15299
|
+
return {
|
|
15300
|
+
path: this.path.map((node)=>({
|
|
15301
|
+
...node
|
|
15302
|
+
})),
|
|
15303
|
+
siblingStacks: this.siblingStacks.map((map)=>new Map(map))
|
|
15304
|
+
};
|
|
15305
|
+
}
|
|
15306
|
+
restore(snapshot) {
|
|
15307
|
+
this.path = snapshot.path.map((node)=>({
|
|
15308
|
+
...node
|
|
15309
|
+
}));
|
|
15310
|
+
this.siblingStacks = snapshot.siblingStacks.map((map)=>new Map(map));
|
|
15311
|
+
}
|
|
15312
|
+
readOnly() {
|
|
15313
|
+
const self1 = this;
|
|
15314
|
+
return new Proxy(self1, {
|
|
15315
|
+
get (target, prop, receiver) {
|
|
15316
|
+
if (MUTATING_METHODS.has(prop)) return ()=>{
|
|
15317
|
+
throw new TypeError(`Cannot call '${prop}' on a read-only Matcher. Obtain a writable instance to mutate state.`);
|
|
15318
|
+
};
|
|
15319
|
+
const value = Reflect.get(target, prop, receiver);
|
|
15320
|
+
if ('path' === prop || 'siblingStacks' === prop) return Object.freeze(Array.isArray(value) ? value.map((item)=>item instanceof Map ? Object.freeze(new Map(item)) : Object.freeze({
|
|
15321
|
+
...item
|
|
15322
|
+
})) : value);
|
|
15323
|
+
if ('function' == typeof value) return value.bind(target);
|
|
15324
|
+
return value;
|
|
15325
|
+
},
|
|
15326
|
+
set (_target, prop) {
|
|
15327
|
+
throw new TypeError(`Cannot set property '${String(prop)}' on a read-only Matcher.`);
|
|
15328
|
+
},
|
|
15329
|
+
deleteProperty (_target, prop) {
|
|
15330
|
+
throw new TypeError(`Cannot delete property '${String(prop)}' from a read-only Matcher.`);
|
|
15331
|
+
}
|
|
15332
|
+
});
|
|
15333
|
+
}
|
|
15334
|
+
}
|
|
15335
|
+
class Expression {
|
|
15336
|
+
constructor(pattern, options = {}){
|
|
15337
|
+
this.pattern = pattern;
|
|
15338
|
+
this.separator = options.separator || '.';
|
|
15339
|
+
this.segments = this._parse(pattern);
|
|
15340
|
+
this._hasDeepWildcard = this.segments.some((seg)=>'deep-wildcard' === seg.type);
|
|
15341
|
+
this._hasAttributeCondition = this.segments.some((seg)=>void 0 !== seg.attrName);
|
|
15342
|
+
this._hasPositionSelector = this.segments.some((seg)=>void 0 !== seg.position);
|
|
15343
|
+
}
|
|
15344
|
+
_parse(pattern) {
|
|
15345
|
+
const segments = [];
|
|
15346
|
+
let i = 0;
|
|
15347
|
+
let currentPart = '';
|
|
15348
|
+
while(i < pattern.length)if (pattern[i] === this.separator) if (i + 1 < pattern.length && pattern[i + 1] === this.separator) {
|
|
15349
|
+
if (currentPart.trim()) {
|
|
15350
|
+
segments.push(this._parseSegment(currentPart.trim()));
|
|
15351
|
+
currentPart = '';
|
|
15352
|
+
}
|
|
15353
|
+
segments.push({
|
|
15354
|
+
type: 'deep-wildcard'
|
|
15355
|
+
});
|
|
15356
|
+
i += 2;
|
|
15357
|
+
} else {
|
|
15358
|
+
if (currentPart.trim()) segments.push(this._parseSegment(currentPart.trim()));
|
|
15359
|
+
currentPart = '';
|
|
15360
|
+
i++;
|
|
15361
|
+
}
|
|
15362
|
+
else {
|
|
15363
|
+
currentPart += pattern[i];
|
|
15364
|
+
i++;
|
|
15365
|
+
}
|
|
15366
|
+
if (currentPart.trim()) segments.push(this._parseSegment(currentPart.trim()));
|
|
15367
|
+
return segments;
|
|
15368
|
+
}
|
|
15369
|
+
_parseSegment(part) {
|
|
15370
|
+
const segment = {
|
|
15371
|
+
type: 'tag'
|
|
15372
|
+
};
|
|
15373
|
+
let bracketContent = null;
|
|
15374
|
+
let withoutBrackets = part;
|
|
15375
|
+
const bracketMatch = part.match(/^([^\[]+)(\[[^\]]*\])(.*)$/);
|
|
15376
|
+
if (bracketMatch) {
|
|
15377
|
+
withoutBrackets = bracketMatch[1] + bracketMatch[3];
|
|
15378
|
+
if (bracketMatch[2]) {
|
|
15379
|
+
const content = bracketMatch[2].slice(1, -1);
|
|
15380
|
+
if (content) bracketContent = content;
|
|
15381
|
+
}
|
|
15382
|
+
}
|
|
15383
|
+
let namespace;
|
|
15384
|
+
let tagAndPosition = withoutBrackets;
|
|
15385
|
+
if (withoutBrackets.includes('::')) {
|
|
15386
|
+
const nsIndex = withoutBrackets.indexOf('::');
|
|
15387
|
+
namespace = withoutBrackets.substring(0, nsIndex).trim();
|
|
15388
|
+
tagAndPosition = withoutBrackets.substring(nsIndex + 2).trim();
|
|
15389
|
+
if (!namespace) throw new Error(`Invalid namespace in pattern: ${part}`);
|
|
15390
|
+
}
|
|
15391
|
+
let tag;
|
|
15392
|
+
let positionMatch = null;
|
|
15393
|
+
if (tagAndPosition.includes(':')) {
|
|
15394
|
+
const colonIndex = tagAndPosition.lastIndexOf(':');
|
|
15395
|
+
const tagPart = tagAndPosition.substring(0, colonIndex).trim();
|
|
15396
|
+
const posPart = tagAndPosition.substring(colonIndex + 1).trim();
|
|
15397
|
+
const isPositionKeyword = [
|
|
15398
|
+
'first',
|
|
15399
|
+
'last',
|
|
15400
|
+
'odd',
|
|
15401
|
+
'even'
|
|
15402
|
+
].includes(posPart) || /^nth\(\d+\)$/.test(posPart);
|
|
15403
|
+
if (isPositionKeyword) {
|
|
15404
|
+
tag = tagPart;
|
|
15405
|
+
positionMatch = posPart;
|
|
15406
|
+
} else tag = tagAndPosition;
|
|
15407
|
+
} else tag = tagAndPosition;
|
|
15408
|
+
if (!tag) throw new Error(`Invalid segment pattern: ${part}`);
|
|
15409
|
+
segment.tag = tag;
|
|
15410
|
+
if (namespace) segment.namespace = namespace;
|
|
15411
|
+
if (bracketContent) if (bracketContent.includes('=')) {
|
|
15412
|
+
const eqIndex = bracketContent.indexOf('=');
|
|
15413
|
+
segment.attrName = bracketContent.substring(0, eqIndex).trim();
|
|
15414
|
+
segment.attrValue = bracketContent.substring(eqIndex + 1).trim();
|
|
15415
|
+
} else segment.attrName = bracketContent.trim();
|
|
15416
|
+
if (positionMatch) {
|
|
15417
|
+
const nthMatch = positionMatch.match(/^nth\((\d+)\)$/);
|
|
15418
|
+
if (nthMatch) {
|
|
15419
|
+
segment.position = 'nth';
|
|
15420
|
+
segment.positionValue = parseInt(nthMatch[1], 10);
|
|
15421
|
+
} else segment.position = positionMatch;
|
|
15422
|
+
}
|
|
15423
|
+
return segment;
|
|
15424
|
+
}
|
|
15425
|
+
get length() {
|
|
15426
|
+
return this.segments.length;
|
|
15427
|
+
}
|
|
15428
|
+
hasDeepWildcard() {
|
|
15429
|
+
return this._hasDeepWildcard;
|
|
15430
|
+
}
|
|
15431
|
+
hasAttributeCondition() {
|
|
15432
|
+
return this._hasAttributeCondition;
|
|
15433
|
+
}
|
|
15434
|
+
hasPositionSelector() {
|
|
15435
|
+
return this._hasPositionSelector;
|
|
15436
|
+
}
|
|
15437
|
+
toString() {
|
|
15438
|
+
return this.pattern;
|
|
15439
|
+
}
|
|
15440
|
+
}
|
|
15441
|
+
function extractRawAttributes(prefixedAttrs, options) {
|
|
15442
|
+
if (!prefixedAttrs) return {};
|
|
15443
|
+
const attrs = options.attributesGroupName ? prefixedAttrs[options.attributesGroupName] : prefixedAttrs;
|
|
15444
|
+
if (!attrs) return {};
|
|
15445
|
+
const rawAttrs = {};
|
|
15446
|
+
for(const key in attrs)if (key.startsWith(options.attributeNamePrefix)) {
|
|
15447
|
+
const rawName = key.substring(options.attributeNamePrefix.length);
|
|
15448
|
+
rawAttrs[rawName] = attrs[key];
|
|
15449
|
+
} else rawAttrs[key] = attrs[key];
|
|
15450
|
+
return rawAttrs;
|
|
15451
|
+
}
|
|
15452
|
+
function extractNamespace(rawTagName) {
|
|
15453
|
+
if (!rawTagName || 'string' != typeof rawTagName) return;
|
|
15454
|
+
const colonIndex = rawTagName.indexOf(':');
|
|
15455
|
+
if (-1 !== colonIndex && colonIndex > 0) {
|
|
15456
|
+
const ns = rawTagName.substring(0, colonIndex);
|
|
15457
|
+
if ('xmlns' !== ns) return ns;
|
|
15458
|
+
}
|
|
15459
|
+
}
|
|
15076
15460
|
class OrderedObjParser {
|
|
15077
15461
|
constructor(options){
|
|
15078
15462
|
this.options = options;
|
|
@@ -15156,13 +15540,15 @@ and limitations under the License.
|
|
|
15156
15540
|
this.ignoreAttributesFn = getIgnoreAttributesFn(this.options.ignoreAttributes);
|
|
15157
15541
|
this.entityExpansionCount = 0;
|
|
15158
15542
|
this.currentExpandedLength = 0;
|
|
15543
|
+
this.matcher = new Matcher();
|
|
15544
|
+
this.readonlyMatcher = this.matcher.readOnly();
|
|
15545
|
+
this.isCurrentNodeStopNode = false;
|
|
15159
15546
|
if (this.options.stopNodes && this.options.stopNodes.length > 0) {
|
|
15160
|
-
this.
|
|
15161
|
-
this.stopNodesWildcard = new Set();
|
|
15547
|
+
this.stopNodeExpressions = [];
|
|
15162
15548
|
for(let i = 0; i < this.options.stopNodes.length; i++){
|
|
15163
15549
|
const stopNodeExp = this.options.stopNodes[i];
|
|
15164
|
-
if ('string' == typeof stopNodeExp)
|
|
15165
|
-
else this.
|
|
15550
|
+
if ('string' == typeof stopNodeExp) this.stopNodeExpressions.push(new Expression(stopNodeExp));
|
|
15551
|
+
else if (stopNodeExp instanceof Expression) this.stopNodeExpressions.push(stopNodeExp);
|
|
15166
15552
|
}
|
|
15167
15553
|
}
|
|
15168
15554
|
}
|
|
@@ -15183,7 +15569,8 @@ and limitations under the License.
|
|
|
15183
15569
|
if (this.options.trimValues && !dontTrim) val = val.trim();
|
|
15184
15570
|
if (val.length > 0) {
|
|
15185
15571
|
if (!escapeEntities) val = this.replaceEntitiesValue(val, tagName, jPath);
|
|
15186
|
-
const
|
|
15572
|
+
const jPathOrMatcher = this.options.jPath ? jPath.toString() : jPath;
|
|
15573
|
+
const newval = this.options.tagValueProcessor(tagName, val, jPathOrMatcher, hasAttributes, isLeafNode);
|
|
15187
15574
|
if (null == newval) return val;
|
|
15188
15575
|
{
|
|
15189
15576
|
if (typeof newval !== typeof val || newval !== val) return newval;
|
|
@@ -15210,18 +15597,32 @@ and limitations under the License.
|
|
|
15210
15597
|
const matches = getAllMatches(attrStr, attrsRegx);
|
|
15211
15598
|
const len = matches.length;
|
|
15212
15599
|
const attrs = {};
|
|
15600
|
+
const rawAttrsForMatcher = {};
|
|
15601
|
+
for(let i = 0; i < len; i++){
|
|
15602
|
+
const attrName = this.resolveNameSpace(matches[i][1]);
|
|
15603
|
+
const oldVal = matches[i][4];
|
|
15604
|
+
if (attrName.length && void 0 !== oldVal) {
|
|
15605
|
+
let parsedVal = oldVal;
|
|
15606
|
+
if (this.options.trimValues) parsedVal = parsedVal.trim();
|
|
15607
|
+
parsedVal = this.replaceEntitiesValue(parsedVal, tagName, this.readonlyMatcher);
|
|
15608
|
+
rawAttrsForMatcher[attrName] = parsedVal;
|
|
15609
|
+
}
|
|
15610
|
+
}
|
|
15611
|
+
if (Object.keys(rawAttrsForMatcher).length > 0 && 'object' == typeof jPath && jPath.updateCurrent) jPath.updateCurrent(rawAttrsForMatcher);
|
|
15213
15612
|
for(let i = 0; i < len; i++){
|
|
15214
15613
|
const attrName = this.resolveNameSpace(matches[i][1]);
|
|
15215
|
-
|
|
15614
|
+
const jPathStr = this.options.jPath ? jPath.toString() : this.readonlyMatcher;
|
|
15615
|
+
if (this.ignoreAttributesFn(attrName, jPathStr)) continue;
|
|
15216
15616
|
let oldVal = matches[i][4];
|
|
15217
15617
|
let aName = this.options.attributeNamePrefix + attrName;
|
|
15218
15618
|
if (attrName.length) {
|
|
15219
15619
|
if (this.options.transformAttributeName) aName = this.options.transformAttributeName(aName);
|
|
15220
|
-
|
|
15620
|
+
aName = sanitizeName(aName, this.options);
|
|
15221
15621
|
if (void 0 !== oldVal) {
|
|
15222
15622
|
if (this.options.trimValues) oldVal = oldVal.trim();
|
|
15223
|
-
oldVal = this.replaceEntitiesValue(oldVal, tagName,
|
|
15224
|
-
const
|
|
15623
|
+
oldVal = this.replaceEntitiesValue(oldVal, tagName, this.readonlyMatcher);
|
|
15624
|
+
const jPathOrMatcher = this.options.jPath ? jPath.toString() : this.readonlyMatcher;
|
|
15625
|
+
const newVal = this.options.attributeValueProcessor(attrName, oldVal, jPathOrMatcher);
|
|
15225
15626
|
if (null == newVal) attrs[aName] = oldVal;
|
|
15226
15627
|
else if (typeof newVal !== typeof oldVal || newVal !== oldVal) attrs[aName] = newVal;
|
|
15227
15628
|
else attrs[aName] = parseValue(oldVal, this.options.parseAttributeValue, this.options.numberParseOptions);
|
|
@@ -15242,7 +15643,7 @@ and limitations under the License.
|
|
|
15242
15643
|
const xmlObj = new XmlNode('!xml');
|
|
15243
15644
|
let currentNode = xmlObj;
|
|
15244
15645
|
let textData = "";
|
|
15245
|
-
|
|
15646
|
+
this.matcher.reset();
|
|
15246
15647
|
this.entityExpansionCount = 0;
|
|
15247
15648
|
this.currentExpandedLength = 0;
|
|
15248
15649
|
const docTypeReader = new DocTypeReader(this.options.processEntities);
|
|
@@ -15255,36 +15656,36 @@ and limitations under the License.
|
|
|
15255
15656
|
const colonIndex = tagName.indexOf(":");
|
|
15256
15657
|
if (-1 !== colonIndex) tagName = tagName.substr(colonIndex + 1);
|
|
15257
15658
|
}
|
|
15258
|
-
|
|
15259
|
-
if (currentNode) textData = this.saveTextToParentTag(textData, currentNode,
|
|
15260
|
-
const lastTagName =
|
|
15659
|
+
tagName = transformTagName(this.options.transformTagName, tagName, "", this.options).tagName;
|
|
15660
|
+
if (currentNode) textData = this.saveTextToParentTag(textData, currentNode, this.readonlyMatcher);
|
|
15661
|
+
const lastTagName = this.matcher.getCurrentTag();
|
|
15261
15662
|
if (tagName && -1 !== this.options.unpairedTags.indexOf(tagName)) throw new Error(`Unpaired tag can not be used as closing tag: </${tagName}>`);
|
|
15262
|
-
let propIndex = 0;
|
|
15263
15663
|
if (lastTagName && -1 !== this.options.unpairedTags.indexOf(lastTagName)) {
|
|
15264
|
-
|
|
15664
|
+
this.matcher.pop();
|
|
15265
15665
|
this.tagsNodeStack.pop();
|
|
15266
|
-
}
|
|
15267
|
-
|
|
15666
|
+
}
|
|
15667
|
+
this.matcher.pop();
|
|
15668
|
+
this.isCurrentNodeStopNode = false;
|
|
15268
15669
|
currentNode = this.tagsNodeStack.pop();
|
|
15269
15670
|
textData = "";
|
|
15270
15671
|
i = closeIndex;
|
|
15271
15672
|
} else if ('?' === xmlData[i + 1]) {
|
|
15272
15673
|
let tagData = readTagExp(xmlData, i, false, "?>");
|
|
15273
15674
|
if (!tagData) throw new Error("Pi Tag is not closed.");
|
|
15274
|
-
textData = this.saveTextToParentTag(textData, currentNode,
|
|
15675
|
+
textData = this.saveTextToParentTag(textData, currentNode, this.readonlyMatcher);
|
|
15275
15676
|
if (this.options.ignoreDeclaration && "?xml" === tagData.tagName || this.options.ignorePiTags) ;
|
|
15276
15677
|
else {
|
|
15277
15678
|
const childNode = new XmlNode(tagData.tagName);
|
|
15278
15679
|
childNode.add(this.options.textNodeName, "");
|
|
15279
|
-
if (tagData.tagName !== tagData.tagExp && tagData.attrExpPresent) childNode[":@"] = this.buildAttributesMap(tagData.tagExp,
|
|
15280
|
-
this.addChild(currentNode, childNode,
|
|
15680
|
+
if (tagData.tagName !== tagData.tagExp && tagData.attrExpPresent) childNode[":@"] = this.buildAttributesMap(tagData.tagExp, this.matcher, tagData.tagName);
|
|
15681
|
+
this.addChild(currentNode, childNode, this.readonlyMatcher, i);
|
|
15281
15682
|
}
|
|
15282
15683
|
i = tagData.closeIndex + 1;
|
|
15283
15684
|
} else if ('!--' === xmlData.substr(i + 1, 3)) {
|
|
15284
15685
|
const endIndex = findClosingIndex(xmlData, "-->", i + 4, "Comment is not closed.");
|
|
15285
15686
|
if (this.options.commentPropName) {
|
|
15286
15687
|
const comment = xmlData.substring(i + 4, endIndex - 2);
|
|
15287
|
-
textData = this.saveTextToParentTag(textData, currentNode,
|
|
15688
|
+
textData = this.saveTextToParentTag(textData, currentNode, this.readonlyMatcher);
|
|
15288
15689
|
currentNode.add(this.options.commentPropName, [
|
|
15289
15690
|
{
|
|
15290
15691
|
[this.options.textNodeName]: comment
|
|
@@ -15299,8 +15700,8 @@ and limitations under the License.
|
|
|
15299
15700
|
} else if ('![' === xmlData.substr(i + 1, 2)) {
|
|
15300
15701
|
const closeIndex = findClosingIndex(xmlData, "]]>", i, "CDATA is not closed.") - 2;
|
|
15301
15702
|
const tagExp = xmlData.substring(i + 9, closeIndex);
|
|
15302
|
-
textData = this.saveTextToParentTag(textData, currentNode,
|
|
15303
|
-
let val = this.parseTextData(tagExp, currentNode.tagname,
|
|
15703
|
+
textData = this.saveTextToParentTag(textData, currentNode, this.readonlyMatcher);
|
|
15704
|
+
let val = this.parseTextData(tagExp, currentNode.tagname, this.readonlyMatcher, true, false, true, true);
|
|
15304
15705
|
if (void 0 == val) val = "";
|
|
15305
15706
|
if (this.options.cdataPropName) currentNode.add(this.options.cdataPropName, [
|
|
15306
15707
|
{
|
|
@@ -15311,36 +15712,48 @@ and limitations under the License.
|
|
|
15311
15712
|
i = closeIndex + 2;
|
|
15312
15713
|
} else {
|
|
15313
15714
|
let result = readTagExp(xmlData, i, this.options.removeNSPrefix);
|
|
15715
|
+
if (!result) {
|
|
15716
|
+
const context = xmlData.substring(Math.max(0, i - 50), Math.min(xmlData.length, i + 50));
|
|
15717
|
+
throw new Error(`readTagExp returned undefined at position ${i}. Context: "${context}"`);
|
|
15718
|
+
}
|
|
15314
15719
|
let tagName = result.tagName;
|
|
15315
15720
|
const rawTagName = result.rawTagName;
|
|
15316
15721
|
let tagExp = result.tagExp;
|
|
15317
15722
|
let attrExpPresent = result.attrExpPresent;
|
|
15318
15723
|
let closeIndex = result.closeIndex;
|
|
15319
|
-
|
|
15320
|
-
|
|
15321
|
-
if (tagExp === tagName) tagExp = newTagName;
|
|
15322
|
-
tagName = newTagName;
|
|
15323
|
-
}
|
|
15724
|
+
({ tagName, tagExp } = transformTagName(this.options.transformTagName, tagName, tagExp, this.options));
|
|
15725
|
+
if (this.options.strictReservedNames && (tagName === this.options.commentPropName || tagName === this.options.cdataPropName || tagName === this.options.textNodeName || tagName === this.options.attributesGroupName)) throw new Error(`Invalid tag name: ${tagName}`);
|
|
15324
15726
|
if (currentNode && textData) {
|
|
15325
|
-
if ('!xml' !== currentNode.tagname) textData = this.saveTextToParentTag(textData, currentNode,
|
|
15727
|
+
if ('!xml' !== currentNode.tagname) textData = this.saveTextToParentTag(textData, currentNode, this.readonlyMatcher, false);
|
|
15326
15728
|
}
|
|
15327
15729
|
const lastTag = currentNode;
|
|
15328
15730
|
if (lastTag && -1 !== this.options.unpairedTags.indexOf(lastTag.tagname)) {
|
|
15329
15731
|
currentNode = this.tagsNodeStack.pop();
|
|
15330
|
-
|
|
15331
|
-
}
|
|
15332
|
-
|
|
15732
|
+
this.matcher.pop();
|
|
15733
|
+
}
|
|
15734
|
+
let isSelfClosing = false;
|
|
15735
|
+
if (tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1) {
|
|
15736
|
+
isSelfClosing = true;
|
|
15737
|
+
if ("/" === tagName[tagName.length - 1]) {
|
|
15738
|
+
tagName = tagName.substr(0, tagName.length - 1);
|
|
15739
|
+
tagExp = tagName;
|
|
15740
|
+
} else tagExp = tagExp.substr(0, tagExp.length - 1);
|
|
15741
|
+
attrExpPresent = tagName !== tagExp;
|
|
15742
|
+
}
|
|
15743
|
+
let prefixedAttrs = null;
|
|
15744
|
+
let namespace;
|
|
15745
|
+
namespace = extractNamespace(rawTagName);
|
|
15746
|
+
if (tagName !== xmlObj.tagname) this.matcher.push(tagName, {}, namespace);
|
|
15747
|
+
if (tagName !== tagExp && attrExpPresent) {
|
|
15748
|
+
prefixedAttrs = this.buildAttributesMap(tagExp, this.matcher, tagName);
|
|
15749
|
+
if (prefixedAttrs) extractRawAttributes(prefixedAttrs, this.options);
|
|
15750
|
+
}
|
|
15751
|
+
if (tagName !== xmlObj.tagname) this.isCurrentNodeStopNode = this.isItStopNode(this.stopNodeExpressions, this.matcher);
|
|
15333
15752
|
const startIndex = i;
|
|
15334
|
-
if (this.
|
|
15753
|
+
if (this.isCurrentNodeStopNode) {
|
|
15335
15754
|
let tagContent = "";
|
|
15336
|
-
if (
|
|
15337
|
-
|
|
15338
|
-
tagName = tagName.substr(0, tagName.length - 1);
|
|
15339
|
-
jPath = jPath.substr(0, jPath.length - 1);
|
|
15340
|
-
tagExp = tagName;
|
|
15341
|
-
} else tagExp = tagExp.substr(0, tagExp.length - 1);
|
|
15342
|
-
i = result.closeIndex;
|
|
15343
|
-
} else if (-1 !== this.options.unpairedTags.indexOf(tagName)) i = result.closeIndex;
|
|
15755
|
+
if (isSelfClosing) i = result.closeIndex;
|
|
15756
|
+
else if (-1 !== this.options.unpairedTags.indexOf(tagName)) i = result.closeIndex;
|
|
15344
15757
|
else {
|
|
15345
15758
|
const result = this.readStopNodeData(xmlData, rawTagName, closeIndex + 1);
|
|
15346
15759
|
if (!result) throw new Error(`Unexpected end of ${rawTagName}`);
|
|
@@ -15348,32 +15761,33 @@ and limitations under the License.
|
|
|
15348
15761
|
tagContent = result.tagContent;
|
|
15349
15762
|
}
|
|
15350
15763
|
const childNode = new XmlNode(tagName);
|
|
15351
|
-
if (
|
|
15352
|
-
if (tagContent) tagContent = this.parseTextData(tagContent, tagName, jPath, true, attrExpPresent, true, true);
|
|
15353
|
-
jPath = jPath.substr(0, jPath.lastIndexOf("."));
|
|
15764
|
+
if (prefixedAttrs) childNode[":@"] = prefixedAttrs;
|
|
15354
15765
|
childNode.add(this.options.textNodeName, tagContent);
|
|
15355
|
-
this.
|
|
15766
|
+
this.matcher.pop();
|
|
15767
|
+
this.isCurrentNodeStopNode = false;
|
|
15768
|
+
this.addChild(currentNode, childNode, this.readonlyMatcher, startIndex);
|
|
15356
15769
|
} else {
|
|
15357
|
-
if (
|
|
15358
|
-
|
|
15359
|
-
|
|
15360
|
-
|
|
15361
|
-
|
|
15362
|
-
|
|
15363
|
-
|
|
15364
|
-
|
|
15365
|
-
if (tagExp === tagName) tagExp = newTagName;
|
|
15366
|
-
tagName = newTagName;
|
|
15367
|
-
}
|
|
15770
|
+
if (isSelfClosing) {
|
|
15771
|
+
({ tagName, tagExp } = transformTagName(this.options.transformTagName, tagName, tagExp, this.options));
|
|
15772
|
+
const childNode = new XmlNode(tagName);
|
|
15773
|
+
if (prefixedAttrs) childNode[":@"] = prefixedAttrs;
|
|
15774
|
+
this.addChild(currentNode, childNode, this.readonlyMatcher, startIndex);
|
|
15775
|
+
this.matcher.pop();
|
|
15776
|
+
this.isCurrentNodeStopNode = false;
|
|
15777
|
+
} else if (-1 !== this.options.unpairedTags.indexOf(tagName)) {
|
|
15368
15778
|
const childNode = new XmlNode(tagName);
|
|
15369
|
-
if (
|
|
15370
|
-
this.addChild(currentNode, childNode,
|
|
15371
|
-
|
|
15779
|
+
if (prefixedAttrs) childNode[":@"] = prefixedAttrs;
|
|
15780
|
+
this.addChild(currentNode, childNode, this.readonlyMatcher, startIndex);
|
|
15781
|
+
this.matcher.pop();
|
|
15782
|
+
this.isCurrentNodeStopNode = false;
|
|
15783
|
+
i = result.closeIndex;
|
|
15784
|
+
continue;
|
|
15372
15785
|
} else {
|
|
15373
15786
|
const childNode = new XmlNode(tagName);
|
|
15787
|
+
if (this.tagsNodeStack.length > this.options.maxNestedTags) throw new Error("Maximum nested tags exceeded");
|
|
15374
15788
|
this.tagsNodeStack.push(currentNode);
|
|
15375
|
-
if (
|
|
15376
|
-
this.addChild(currentNode, childNode,
|
|
15789
|
+
if (prefixedAttrs) childNode[":@"] = prefixedAttrs;
|
|
15790
|
+
this.addChild(currentNode, childNode, this.readonlyMatcher, startIndex);
|
|
15377
15791
|
currentNode = childNode;
|
|
15378
15792
|
}
|
|
15379
15793
|
textData = "";
|
|
@@ -15384,26 +15798,29 @@ and limitations under the License.
|
|
|
15384
15798
|
}
|
|
15385
15799
|
return xmlObj.child;
|
|
15386
15800
|
};
|
|
15387
|
-
function addChild(currentNode, childNode,
|
|
15801
|
+
function addChild(currentNode, childNode, matcher, startIndex) {
|
|
15388
15802
|
if (!this.options.captureMetaData) startIndex = void 0;
|
|
15389
|
-
const
|
|
15803
|
+
const jPathOrMatcher = this.options.jPath ? matcher.toString() : matcher;
|
|
15804
|
+
const result = this.options.updateTag(childNode.tagname, jPathOrMatcher, childNode[":@"]);
|
|
15390
15805
|
if (false === result) ;
|
|
15391
15806
|
else if ("string" == typeof result) {
|
|
15392
15807
|
childNode.tagname = result;
|
|
15393
15808
|
currentNode.addChild(childNode, startIndex);
|
|
15394
15809
|
} else currentNode.addChild(childNode, startIndex);
|
|
15395
15810
|
}
|
|
15396
|
-
|
|
15397
|
-
if (-1 === val.indexOf('&')) return val;
|
|
15811
|
+
function replaceEntitiesValue(val, tagName, jPath) {
|
|
15398
15812
|
const entityConfig = this.options.processEntities;
|
|
15399
|
-
if (!entityConfig.enabled) return val;
|
|
15813
|
+
if (!entityConfig || !entityConfig.enabled) return val;
|
|
15400
15814
|
if (entityConfig.allowedTags) {
|
|
15401
|
-
|
|
15815
|
+
const jPathOrMatcher = this.options.jPath ? jPath.toString() : jPath;
|
|
15816
|
+
const allowed = Array.isArray(entityConfig.allowedTags) ? entityConfig.allowedTags.includes(tagName) : entityConfig.allowedTags(tagName, jPathOrMatcher);
|
|
15817
|
+
if (!allowed) return val;
|
|
15402
15818
|
}
|
|
15403
15819
|
if (entityConfig.tagFilter) {
|
|
15404
|
-
|
|
15820
|
+
const jPathOrMatcher = this.options.jPath ? jPath.toString() : jPath;
|
|
15821
|
+
if (!entityConfig.tagFilter(tagName, jPathOrMatcher)) return val;
|
|
15405
15822
|
}
|
|
15406
|
-
for(
|
|
15823
|
+
for (const entityName of Object.keys(this.docTypeEntities)){
|
|
15407
15824
|
const entity = this.docTypeEntities[entityName];
|
|
15408
15825
|
const matches = val.match(entity.regx);
|
|
15409
15826
|
if (matches) {
|
|
@@ -15417,31 +15834,40 @@ and limitations under the License.
|
|
|
15417
15834
|
}
|
|
15418
15835
|
}
|
|
15419
15836
|
}
|
|
15420
|
-
|
|
15421
|
-
for(let entityName in this.lastEntities){
|
|
15837
|
+
for (const entityName of Object.keys(this.lastEntities)){
|
|
15422
15838
|
const entity = this.lastEntities[entityName];
|
|
15839
|
+
const matches = val.match(entity.regex);
|
|
15840
|
+
if (matches) {
|
|
15841
|
+
this.entityExpansionCount += matches.length;
|
|
15842
|
+
if (entityConfig.maxTotalExpansions && this.entityExpansionCount > entityConfig.maxTotalExpansions) throw new Error(`Entity expansion limit exceeded: ${this.entityExpansionCount} > ${entityConfig.maxTotalExpansions}`);
|
|
15843
|
+
}
|
|
15423
15844
|
val = val.replace(entity.regex, entity.val);
|
|
15424
15845
|
}
|
|
15425
15846
|
if (-1 === val.indexOf('&')) return val;
|
|
15426
|
-
if (this.options.htmlEntities) for(
|
|
15847
|
+
if (this.options.htmlEntities) for (const entityName of Object.keys(this.htmlEntities)){
|
|
15427
15848
|
const entity = this.htmlEntities[entityName];
|
|
15849
|
+
const matches = val.match(entity.regex);
|
|
15850
|
+
if (matches) {
|
|
15851
|
+
this.entityExpansionCount += matches.length;
|
|
15852
|
+
if (entityConfig.maxTotalExpansions && this.entityExpansionCount > entityConfig.maxTotalExpansions) throw new Error(`Entity expansion limit exceeded: ${this.entityExpansionCount} > ${entityConfig.maxTotalExpansions}`);
|
|
15853
|
+
}
|
|
15428
15854
|
val = val.replace(entity.regex, entity.val);
|
|
15429
15855
|
}
|
|
15430
15856
|
val = val.replace(this.ampEntity.regex, this.ampEntity.val);
|
|
15431
15857
|
return val;
|
|
15432
|
-
}
|
|
15433
|
-
function saveTextToParentTag(textData,
|
|
15858
|
+
}
|
|
15859
|
+
function saveTextToParentTag(textData, parentNode, matcher, isLeafNode) {
|
|
15434
15860
|
if (textData) {
|
|
15435
|
-
if (void 0 === isLeafNode) isLeafNode = 0 ===
|
|
15436
|
-
textData = this.parseTextData(textData,
|
|
15437
|
-
if (void 0 !== textData && "" !== textData)
|
|
15861
|
+
if (void 0 === isLeafNode) isLeafNode = 0 === parentNode.child.length;
|
|
15862
|
+
textData = this.parseTextData(textData, parentNode.tagname, matcher, false, parentNode[":@"] ? 0 !== Object.keys(parentNode[":@"]).length : false, isLeafNode);
|
|
15863
|
+
if (void 0 !== textData && "" !== textData) parentNode.add(this.options.textNodeName, textData);
|
|
15438
15864
|
textData = "";
|
|
15439
15865
|
}
|
|
15440
15866
|
return textData;
|
|
15441
15867
|
}
|
|
15442
|
-
function isItStopNode(
|
|
15443
|
-
if (
|
|
15444
|
-
|
|
15868
|
+
function isItStopNode(stopNodeExpressions, matcher) {
|
|
15869
|
+
if (!stopNodeExpressions || 0 === stopNodeExpressions.length) return false;
|
|
15870
|
+
for(let i = 0; i < stopNodeExpressions.length; i++)if (matcher.matches(stopNodeExpressions[i])) return true;
|
|
15445
15871
|
return false;
|
|
15446
15872
|
}
|
|
15447
15873
|
function tagExpWithClosingIndex(xmlData, i, closingChar = ">") {
|
|
@@ -15545,39 +15971,72 @@ and limitations under the License.
|
|
|
15545
15971
|
if (codePoint >= 0 && codePoint <= 0x10FFFF) return String.fromCodePoint(codePoint);
|
|
15546
15972
|
return prefix + str + ";";
|
|
15547
15973
|
}
|
|
15548
|
-
|
|
15549
|
-
|
|
15550
|
-
|
|
15974
|
+
function transformTagName(fn, tagName, tagExp, options) {
|
|
15975
|
+
if (fn) {
|
|
15976
|
+
const newTagName = fn(tagName);
|
|
15977
|
+
if (tagExp === tagName) tagExp = newTagName;
|
|
15978
|
+
tagName = newTagName;
|
|
15979
|
+
}
|
|
15980
|
+
tagName = sanitizeName(tagName, options);
|
|
15981
|
+
return {
|
|
15982
|
+
tagName,
|
|
15983
|
+
tagExp
|
|
15984
|
+
};
|
|
15985
|
+
}
|
|
15986
|
+
function sanitizeName(name, options) {
|
|
15987
|
+
if (criticalProperties.includes(name)) throw new Error(`[SECURITY] Invalid name: "${name}" is a reserved JavaScript keyword that could cause prototype pollution`);
|
|
15988
|
+
if (DANGEROUS_PROPERTY_NAMES.includes(name)) return options.onDangerousProperty(name);
|
|
15989
|
+
return name;
|
|
15551
15990
|
}
|
|
15552
|
-
|
|
15991
|
+
const node2json_METADATA_SYMBOL = XmlNode.getMetaDataSymbol();
|
|
15992
|
+
function stripAttributePrefix(attrs, prefix) {
|
|
15993
|
+
if (!attrs || 'object' != typeof attrs) return {};
|
|
15994
|
+
if (!prefix) return attrs;
|
|
15995
|
+
const rawAttrs = {};
|
|
15996
|
+
for(const key in attrs)if (key.startsWith(prefix)) {
|
|
15997
|
+
const rawName = key.substring(prefix.length);
|
|
15998
|
+
rawAttrs[rawName] = attrs[key];
|
|
15999
|
+
} else rawAttrs[key] = attrs[key];
|
|
16000
|
+
return rawAttrs;
|
|
16001
|
+
}
|
|
16002
|
+
function prettify(node, options, matcher, readonlyMatcher) {
|
|
16003
|
+
return node2json_compress(node, options, matcher, readonlyMatcher);
|
|
16004
|
+
}
|
|
16005
|
+
function node2json_compress(arr, options, matcher, readonlyMatcher) {
|
|
15553
16006
|
let text;
|
|
15554
16007
|
const compressedObj = {};
|
|
15555
16008
|
for(let i = 0; i < arr.length; i++){
|
|
15556
16009
|
const tagObj = arr[i];
|
|
15557
16010
|
const property = propName(tagObj);
|
|
15558
|
-
|
|
15559
|
-
|
|
16011
|
+
if (void 0 !== property && property !== options.textNodeName) {
|
|
16012
|
+
const rawAttrs = stripAttributePrefix(tagObj[":@"] || {}, options.attributeNamePrefix);
|
|
16013
|
+
matcher.push(property, rawAttrs);
|
|
16014
|
+
}
|
|
15560
16015
|
if (property === options.textNodeName) if (void 0 === text) text = tagObj[property];
|
|
15561
16016
|
else text += "" + tagObj[property];
|
|
15562
16017
|
else if (void 0 === property) continue;
|
|
15563
16018
|
else if (tagObj[property]) {
|
|
15564
|
-
let val = node2json_compress(tagObj[property], options,
|
|
16019
|
+
let val = node2json_compress(tagObj[property], options, matcher, readonlyMatcher);
|
|
15565
16020
|
const isLeaf = isLeafTag(val, options);
|
|
15566
|
-
if (
|
|
15567
|
-
if (tagObj[":@"]) assignAttributes(val, tagObj[":@"], newJpath, options);
|
|
16021
|
+
if (tagObj[":@"]) assignAttributes(val, tagObj[":@"], readonlyMatcher, options);
|
|
15568
16022
|
else if (1 !== Object.keys(val).length || void 0 === val[options.textNodeName] || options.alwaysCreateTextNode) {
|
|
15569
16023
|
if (0 === Object.keys(val).length) if (options.alwaysCreateTextNode) val[options.textNodeName] = "";
|
|
15570
16024
|
else val = "";
|
|
15571
16025
|
} else val = val[options.textNodeName];
|
|
15572
|
-
if (void 0 !==
|
|
16026
|
+
if (void 0 !== tagObj[node2json_METADATA_SYMBOL] && "object" == typeof val && null !== val) val[node2json_METADATA_SYMBOL] = tagObj[node2json_METADATA_SYMBOL];
|
|
16027
|
+
if (void 0 !== compressedObj[property] && Object.prototype.hasOwnProperty.call(compressedObj, property)) {
|
|
15573
16028
|
if (!Array.isArray(compressedObj[property])) compressedObj[property] = [
|
|
15574
16029
|
compressedObj[property]
|
|
15575
16030
|
];
|
|
15576
16031
|
compressedObj[property].push(val);
|
|
15577
|
-
} else
|
|
15578
|
-
|
|
15579
|
-
|
|
15580
|
-
|
|
16032
|
+
} else {
|
|
16033
|
+
const jPathOrMatcher = options.jPath ? readonlyMatcher.toString() : readonlyMatcher;
|
|
16034
|
+
if (options.isArray(property, jPathOrMatcher, isLeaf)) compressedObj[property] = [
|
|
16035
|
+
val
|
|
16036
|
+
];
|
|
16037
|
+
else compressedObj[property] = val;
|
|
16038
|
+
}
|
|
16039
|
+
if (void 0 !== property && property !== options.textNodeName) matcher.pop();
|
|
15581
16040
|
}
|
|
15582
16041
|
}
|
|
15583
16042
|
if ("string" == typeof text) {
|
|
@@ -15592,13 +16051,15 @@ and limitations under the License.
|
|
|
15592
16051
|
if (":@" !== key) return key;
|
|
15593
16052
|
}
|
|
15594
16053
|
}
|
|
15595
|
-
function assignAttributes(obj, attrMap,
|
|
16054
|
+
function assignAttributes(obj, attrMap, readonlyMatcher, options) {
|
|
15596
16055
|
if (attrMap) {
|
|
15597
16056
|
const keys = Object.keys(attrMap);
|
|
15598
16057
|
const len = keys.length;
|
|
15599
16058
|
for(let i = 0; i < len; i++){
|
|
15600
16059
|
const atrrName = keys[i];
|
|
15601
|
-
|
|
16060
|
+
const rawAttrName = atrrName.startsWith(options.attributeNamePrefix) ? atrrName.substring(options.attributeNamePrefix.length) : atrrName;
|
|
16061
|
+
const jPathOrMatcher = options.jPath ? readonlyMatcher.toString() + "." + rawAttrName : readonlyMatcher;
|
|
16062
|
+
if (options.isArray(atrrName, jPathOrMatcher, true, true)) obj[atrrName] = [
|
|
15602
16063
|
attrMap[atrrName]
|
|
15603
16064
|
];
|
|
15604
16065
|
else obj[atrrName] = attrMap[atrrName];
|
|
@@ -15778,7 +16239,7 @@ and limitations under the License.
|
|
|
15778
16239
|
if (void 0 === matches[i][3] && !options.allowBooleanAttributes) return getErrorObject('InvalidAttr', "boolean attribute '" + matches[i][2] + "' is not allowed.", getPositionFromMatch(matches[i]));
|
|
15779
16240
|
const attrName = matches[i][2];
|
|
15780
16241
|
if (!validateAttrName(attrName)) return getErrorObject('InvalidAttr', "Attribute '" + attrName + "' is an invalid name.", getPositionFromMatch(matches[i]));
|
|
15781
|
-
if (
|
|
16242
|
+
if (Object.prototype.hasOwnProperty.call(attrNames, attrName)) return getErrorObject('InvalidAttr', "Attribute '" + attrName + "' is repeated.", getPositionFromMatch(matches[i]));
|
|
15782
16243
|
attrNames[attrName] = 1;
|
|
15783
16244
|
}
|
|
15784
16245
|
return true;
|
|
@@ -15852,7 +16313,7 @@ and limitations under the License.
|
|
|
15852
16313
|
orderedObjParser.addExternalEntities(this.externalEntities);
|
|
15853
16314
|
const orderedResult = orderedObjParser.parseXml(xmlData);
|
|
15854
16315
|
if (this.options.preserveOrder || void 0 === orderedResult) return orderedResult;
|
|
15855
|
-
return prettify(orderedResult, this.options);
|
|
16316
|
+
return prettify(orderedResult, this.options, orderedObjParser.matcher, orderedObjParser.readonlyMatcher);
|
|
15856
16317
|
}
|
|
15857
16318
|
addEntity(key, value) {
|
|
15858
16319
|
if (-1 !== value.indexOf("&")) throw new Error("Entity value can't have '&'");
|
|
@@ -15868,52 +16329,74 @@ and limitations under the License.
|
|
|
15868
16329
|
function toXml(jArray, options) {
|
|
15869
16330
|
let indentation = "";
|
|
15870
16331
|
if (options.format && options.indentBy.length > 0) indentation = EOL;
|
|
15871
|
-
|
|
16332
|
+
const stopNodeExpressions = [];
|
|
16333
|
+
if (options.stopNodes && Array.isArray(options.stopNodes)) for(let i = 0; i < options.stopNodes.length; i++){
|
|
16334
|
+
const node = options.stopNodes[i];
|
|
16335
|
+
if ('string' == typeof node) stopNodeExpressions.push(new Expression(node));
|
|
16336
|
+
else if (node instanceof Expression) stopNodeExpressions.push(node);
|
|
16337
|
+
}
|
|
16338
|
+
const matcher = new Matcher();
|
|
16339
|
+
return arrToStr(jArray, options, indentation, matcher, stopNodeExpressions);
|
|
15872
16340
|
}
|
|
15873
|
-
function arrToStr(arr, options,
|
|
16341
|
+
function arrToStr(arr, options, indentation, matcher, stopNodeExpressions) {
|
|
15874
16342
|
let xmlStr = "";
|
|
15875
16343
|
let isPreviousElementTag = false;
|
|
16344
|
+
if (options.maxNestedTags && matcher.getDepth() > options.maxNestedTags) throw new Error("Maximum nested tags exceeded");
|
|
16345
|
+
if (!Array.isArray(arr)) {
|
|
16346
|
+
if (null != arr) {
|
|
16347
|
+
let text = arr.toString();
|
|
16348
|
+
text = orderedJs2Xml_replaceEntitiesValue(text, options);
|
|
16349
|
+
return text;
|
|
16350
|
+
}
|
|
16351
|
+
return "";
|
|
16352
|
+
}
|
|
15876
16353
|
for(let i = 0; i < arr.length; i++){
|
|
15877
16354
|
const tagObj = arr[i];
|
|
15878
16355
|
const tagName = orderedJs2Xml_propName(tagObj);
|
|
15879
16356
|
if (void 0 === tagName) continue;
|
|
15880
|
-
|
|
15881
|
-
|
|
16357
|
+
const attrValues = extractAttributeValues(tagObj[":@"], options);
|
|
16358
|
+
matcher.push(tagName, attrValues);
|
|
16359
|
+
const isStopNode = checkStopNode(matcher, stopNodeExpressions);
|
|
15882
16360
|
if (tagName === options.textNodeName) {
|
|
15883
16361
|
let tagText = tagObj[tagName];
|
|
15884
|
-
if (!isStopNode
|
|
16362
|
+
if (!isStopNode) {
|
|
15885
16363
|
tagText = options.tagValueProcessor(tagName, tagText);
|
|
15886
16364
|
tagText = orderedJs2Xml_replaceEntitiesValue(tagText, options);
|
|
15887
16365
|
}
|
|
15888
16366
|
if (isPreviousElementTag) xmlStr += indentation;
|
|
15889
16367
|
xmlStr += tagText;
|
|
15890
16368
|
isPreviousElementTag = false;
|
|
16369
|
+
matcher.pop();
|
|
15891
16370
|
continue;
|
|
15892
16371
|
}
|
|
15893
16372
|
if (tagName === options.cdataPropName) {
|
|
15894
16373
|
if (isPreviousElementTag) xmlStr += indentation;
|
|
15895
16374
|
xmlStr += `<![CDATA[${tagObj[tagName][0][options.textNodeName]}]]>`;
|
|
15896
16375
|
isPreviousElementTag = false;
|
|
16376
|
+
matcher.pop();
|
|
15897
16377
|
continue;
|
|
15898
16378
|
}
|
|
15899
16379
|
if (tagName === options.commentPropName) {
|
|
15900
16380
|
xmlStr += indentation + `<!--${tagObj[tagName][0][options.textNodeName]}-->`;
|
|
15901
16381
|
isPreviousElementTag = true;
|
|
16382
|
+
matcher.pop();
|
|
15902
16383
|
continue;
|
|
15903
16384
|
} else if ("?" === tagName[0]) {
|
|
15904
|
-
const attStr = attr_to_str(tagObj[":@"], options);
|
|
16385
|
+
const attStr = attr_to_str(tagObj[":@"], options, isStopNode);
|
|
15905
16386
|
const tempInd = "?xml" === tagName ? "" : indentation;
|
|
15906
16387
|
let piTextNodeName = tagObj[tagName][0][options.textNodeName];
|
|
15907
16388
|
piTextNodeName = 0 !== piTextNodeName.length ? " " + piTextNodeName : "";
|
|
15908
16389
|
xmlStr += tempInd + `<${tagName}${piTextNodeName}${attStr}?>`;
|
|
15909
16390
|
isPreviousElementTag = true;
|
|
16391
|
+
matcher.pop();
|
|
15910
16392
|
continue;
|
|
15911
16393
|
}
|
|
15912
16394
|
let newIdentation = indentation;
|
|
15913
16395
|
if ("" !== newIdentation) newIdentation += options.indentBy;
|
|
15914
|
-
const attStr = attr_to_str(tagObj[":@"], options);
|
|
16396
|
+
const attStr = attr_to_str(tagObj[":@"], options, isStopNode);
|
|
15915
16397
|
const tagStart = indentation + `<${tagName}${attStr}`;
|
|
15916
|
-
|
|
16398
|
+
let tagValue;
|
|
16399
|
+
tagValue = isStopNode ? getRawContent(tagObj[tagName], options) : arrToStr(tagObj[tagName], options, newIdentation, matcher, stopNodeExpressions);
|
|
15917
16400
|
if (-1 !== options.unpairedTags.indexOf(tagName)) if (options.suppressUnpairedNode) xmlStr += tagStart + ">";
|
|
15918
16401
|
else xmlStr += tagStart + "/>";
|
|
15919
16402
|
else if ((!tagValue || 0 === tagValue.length) && options.suppressEmptyNode) xmlStr += tagStart + "/>";
|
|
@@ -15925,33 +16408,81 @@ and limitations under the License.
|
|
|
15925
16408
|
xmlStr += `</${tagName}>`;
|
|
15926
16409
|
}
|
|
15927
16410
|
isPreviousElementTag = true;
|
|
16411
|
+
matcher.pop();
|
|
15928
16412
|
}
|
|
15929
16413
|
return xmlStr;
|
|
15930
16414
|
}
|
|
16415
|
+
function extractAttributeValues(attrMap, options) {
|
|
16416
|
+
if (!attrMap || options.ignoreAttributes) return null;
|
|
16417
|
+
const attrValues = {};
|
|
16418
|
+
let hasAttrs = false;
|
|
16419
|
+
for(let attr in attrMap){
|
|
16420
|
+
if (!Object.prototype.hasOwnProperty.call(attrMap, attr)) continue;
|
|
16421
|
+
const cleanAttrName = attr.startsWith(options.attributeNamePrefix) ? attr.substr(options.attributeNamePrefix.length) : attr;
|
|
16422
|
+
attrValues[cleanAttrName] = attrMap[attr];
|
|
16423
|
+
hasAttrs = true;
|
|
16424
|
+
}
|
|
16425
|
+
return hasAttrs ? attrValues : null;
|
|
16426
|
+
}
|
|
16427
|
+
function getRawContent(arr, options) {
|
|
16428
|
+
if (!Array.isArray(arr)) {
|
|
16429
|
+
if (null != arr) return arr.toString();
|
|
16430
|
+
return "";
|
|
16431
|
+
}
|
|
16432
|
+
let content = "";
|
|
16433
|
+
for(let i = 0; i < arr.length; i++){
|
|
16434
|
+
const item = arr[i];
|
|
16435
|
+
const tagName = orderedJs2Xml_propName(item);
|
|
16436
|
+
if (tagName === options.textNodeName) content += item[tagName];
|
|
16437
|
+
else if (tagName === options.cdataPropName) content += item[tagName][0][options.textNodeName];
|
|
16438
|
+
else if (tagName === options.commentPropName) content += item[tagName][0][options.textNodeName];
|
|
16439
|
+
else if (tagName && "?" === tagName[0]) continue;
|
|
16440
|
+
else if (tagName) {
|
|
16441
|
+
const attStr = attr_to_str_raw(item[":@"], options);
|
|
16442
|
+
const nestedContent = getRawContent(item[tagName], options);
|
|
16443
|
+
if (nestedContent && 0 !== nestedContent.length) content += `<${tagName}${attStr}>${nestedContent}</${tagName}>`;
|
|
16444
|
+
else content += `<${tagName}${attStr}/>`;
|
|
16445
|
+
}
|
|
16446
|
+
}
|
|
16447
|
+
return content;
|
|
16448
|
+
}
|
|
16449
|
+
function attr_to_str_raw(attrMap, options) {
|
|
16450
|
+
let attrStr = "";
|
|
16451
|
+
if (attrMap && !options.ignoreAttributes) for(let attr in attrMap){
|
|
16452
|
+
if (!Object.prototype.hasOwnProperty.call(attrMap, attr)) continue;
|
|
16453
|
+
let attrVal = attrMap[attr];
|
|
16454
|
+
if (true === attrVal && options.suppressBooleanAttributes) attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}`;
|
|
16455
|
+
else attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}="${attrVal}"`;
|
|
16456
|
+
}
|
|
16457
|
+
return attrStr;
|
|
16458
|
+
}
|
|
15931
16459
|
function orderedJs2Xml_propName(obj) {
|
|
15932
16460
|
const keys = Object.keys(obj);
|
|
15933
16461
|
for(let i = 0; i < keys.length; i++){
|
|
15934
16462
|
const key = keys[i];
|
|
15935
|
-
if (
|
|
16463
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
15936
16464
|
if (":@" !== key) return key;
|
|
15937
16465
|
}
|
|
15938
16466
|
}
|
|
15939
16467
|
}
|
|
15940
|
-
function attr_to_str(attrMap, options) {
|
|
16468
|
+
function attr_to_str(attrMap, options, isStopNode) {
|
|
15941
16469
|
let attrStr = "";
|
|
15942
16470
|
if (attrMap && !options.ignoreAttributes) for(let attr in attrMap){
|
|
15943
|
-
if (!
|
|
15944
|
-
let attrVal
|
|
15945
|
-
attrVal =
|
|
16471
|
+
if (!Object.prototype.hasOwnProperty.call(attrMap, attr)) continue;
|
|
16472
|
+
let attrVal;
|
|
16473
|
+
if (isStopNode) attrVal = attrMap[attr];
|
|
16474
|
+
else {
|
|
16475
|
+
attrVal = options.attributeValueProcessor(attr, attrMap[attr]);
|
|
16476
|
+
attrVal = orderedJs2Xml_replaceEntitiesValue(attrVal, options);
|
|
16477
|
+
}
|
|
15946
16478
|
if (true === attrVal && options.suppressBooleanAttributes) attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}`;
|
|
15947
16479
|
else attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}="${attrVal}"`;
|
|
15948
16480
|
}
|
|
15949
16481
|
return attrStr;
|
|
15950
16482
|
}
|
|
15951
|
-
function
|
|
15952
|
-
|
|
15953
|
-
let
|
|
15954
|
-
for(let index in options.stopNodes)if (options.stopNodes[index] === jPath || options.stopNodes[index] === "*." + tagName) return true;
|
|
16483
|
+
function checkStopNode(matcher, stopNodeExpressions) {
|
|
16484
|
+
if (!stopNodeExpressions || 0 === stopNodeExpressions.length) return false;
|
|
16485
|
+
for(let i = 0; i < stopNodeExpressions.length; i++)if (matcher.matches(stopNodeExpressions[i])) return true;
|
|
15955
16486
|
return false;
|
|
15956
16487
|
}
|
|
15957
16488
|
function orderedJs2Xml_replaceEntitiesValue(textValue, options) {
|
|
@@ -15961,7 +16492,17 @@ and limitations under the License.
|
|
|
15961
16492
|
}
|
|
15962
16493
|
return textValue;
|
|
15963
16494
|
}
|
|
15964
|
-
|
|
16495
|
+
function ignoreAttributes_getIgnoreAttributesFn(ignoreAttributes) {
|
|
16496
|
+
if ('function' == typeof ignoreAttributes) return ignoreAttributes;
|
|
16497
|
+
if (Array.isArray(ignoreAttributes)) return (attrName)=>{
|
|
16498
|
+
for (const pattern of ignoreAttributes){
|
|
16499
|
+
if ('string' == typeof pattern && attrName === pattern) return true;
|
|
16500
|
+
if (pattern instanceof RegExp && pattern.test(attrName)) return true;
|
|
16501
|
+
}
|
|
16502
|
+
};
|
|
16503
|
+
return ()=>false;
|
|
16504
|
+
}
|
|
16505
|
+
const fxb_defaultOptions = {
|
|
15965
16506
|
attributeNamePrefix: '@_',
|
|
15966
16507
|
attributesGroupName: false,
|
|
15967
16508
|
textNodeName: '#text',
|
|
@@ -16005,15 +16546,27 @@ and limitations under the License.
|
|
|
16005
16546
|
],
|
|
16006
16547
|
processEntities: true,
|
|
16007
16548
|
stopNodes: [],
|
|
16008
|
-
oneListGroup: false
|
|
16549
|
+
oneListGroup: false,
|
|
16550
|
+
maxNestedTags: 100,
|
|
16551
|
+
jPath: true
|
|
16009
16552
|
};
|
|
16010
16553
|
function Builder(options) {
|
|
16011
|
-
this.options = Object.assign({},
|
|
16554
|
+
this.options = Object.assign({}, fxb_defaultOptions, options);
|
|
16555
|
+
if (this.options.stopNodes && Array.isArray(this.options.stopNodes)) this.options.stopNodes = this.options.stopNodes.map((node)=>{
|
|
16556
|
+
if ('string' == typeof node && node.startsWith('*.')) return '..' + node.substring(2);
|
|
16557
|
+
return node;
|
|
16558
|
+
});
|
|
16559
|
+
this.stopNodeExpressions = [];
|
|
16560
|
+
if (this.options.stopNodes && Array.isArray(this.options.stopNodes)) for(let i = 0; i < this.options.stopNodes.length; i++){
|
|
16561
|
+
const node = this.options.stopNodes[i];
|
|
16562
|
+
if ('string' == typeof node) this.stopNodeExpressions.push(new Expression(node));
|
|
16563
|
+
else if (node instanceof Expression) this.stopNodeExpressions.push(node);
|
|
16564
|
+
}
|
|
16012
16565
|
if (true === this.options.ignoreAttributes || this.options.attributesGroupName) this.isAttribute = function() {
|
|
16013
16566
|
return false;
|
|
16014
16567
|
};
|
|
16015
16568
|
else {
|
|
16016
|
-
this.ignoreAttributesFn =
|
|
16569
|
+
this.ignoreAttributesFn = ignoreAttributes_getIgnoreAttributesFn(this.options.ignoreAttributes);
|
|
16017
16570
|
this.attrPrefixLen = this.options.attributeNamePrefix.length;
|
|
16018
16571
|
this.isAttribute = isAttribute;
|
|
16019
16572
|
}
|
|
@@ -16032,29 +16585,43 @@ and limitations under the License.
|
|
|
16032
16585
|
}
|
|
16033
16586
|
Builder.prototype.build = function(jObj) {
|
|
16034
16587
|
if (this.options.preserveOrder) return toXml(jObj, this.options);
|
|
16035
|
-
|
|
16036
|
-
|
|
16037
|
-
|
|
16038
|
-
|
|
16588
|
+
{
|
|
16589
|
+
if (Array.isArray(jObj) && this.options.arrayNodeName && this.options.arrayNodeName.length > 1) jObj = {
|
|
16590
|
+
[this.options.arrayNodeName]: jObj
|
|
16591
|
+
};
|
|
16592
|
+
const matcher = new Matcher();
|
|
16593
|
+
return this.j2x(jObj, 0, matcher).val;
|
|
16594
|
+
}
|
|
16039
16595
|
};
|
|
16040
|
-
Builder.prototype.j2x = function(jObj, level,
|
|
16596
|
+
Builder.prototype.j2x = function(jObj, level, matcher) {
|
|
16041
16597
|
let attrStr = '';
|
|
16042
16598
|
let val = '';
|
|
16043
|
-
|
|
16599
|
+
if (this.options.maxNestedTags && matcher.getDepth() >= this.options.maxNestedTags) throw new Error("Maximum nested tags exceeded");
|
|
16600
|
+
const jPath = this.options.jPath ? matcher.toString() : matcher;
|
|
16601
|
+
const isCurrentStopNode = this.checkStopNode(matcher);
|
|
16044
16602
|
for(let key in jObj)if (Object.prototype.hasOwnProperty.call(jObj, key)) if (void 0 === jObj[key]) {
|
|
16045
16603
|
if (this.isAttribute(key)) val += '';
|
|
16046
16604
|
} else if (null === jObj[key]) if (this.isAttribute(key)) val += '';
|
|
16047
16605
|
else if (key === this.options.cdataPropName) val += '';
|
|
16048
16606
|
else if ('?' === key[0]) val += this.indentate(level) + '<' + key + '?' + this.tagEndChar;
|
|
16049
16607
|
else val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;
|
|
16050
|
-
else if (jObj[key] instanceof Date) val += this.buildTextValNode(jObj[key], key, '', level);
|
|
16608
|
+
else if (jObj[key] instanceof Date) val += this.buildTextValNode(jObj[key], key, '', level, matcher);
|
|
16051
16609
|
else if ('object' != typeof jObj[key]) {
|
|
16052
16610
|
const attr = this.isAttribute(key);
|
|
16053
|
-
if (attr && !this.ignoreAttributesFn(attr, jPath)) attrStr += this.buildAttrPairStr(attr, '' + jObj[key]);
|
|
16611
|
+
if (attr && !this.ignoreAttributesFn(attr, jPath)) attrStr += this.buildAttrPairStr(attr, '' + jObj[key], isCurrentStopNode);
|
|
16054
16612
|
else if (!attr) if (key === this.options.textNodeName) {
|
|
16055
16613
|
let newval = this.options.tagValueProcessor(key, '' + jObj[key]);
|
|
16056
16614
|
val += this.replaceEntitiesValue(newval);
|
|
16057
|
-
} else
|
|
16615
|
+
} else {
|
|
16616
|
+
matcher.push(key);
|
|
16617
|
+
const isStopNode = this.checkStopNode(matcher);
|
|
16618
|
+
matcher.pop();
|
|
16619
|
+
if (isStopNode) {
|
|
16620
|
+
const textValue = '' + jObj[key];
|
|
16621
|
+
if ('' === textValue) val += this.indentate(level) + '<' + key + this.closeTag(key) + this.tagEndChar;
|
|
16622
|
+
else val += this.indentate(level) + '<' + key + '>' + textValue + '</' + key + this.tagEndChar;
|
|
16623
|
+
} else val += this.buildTextValNode(jObj[key], key, '', level, matcher);
|
|
16624
|
+
}
|
|
16058
16625
|
} else if (Array.isArray(jObj[key])) {
|
|
16059
16626
|
const arrLen = jObj[key].length;
|
|
16060
16627
|
let listTagVal = "";
|
|
@@ -16065,39 +16632,135 @@ and limitations under the License.
|
|
|
16065
16632
|
else if (null === item) if ("?" === key[0]) val += this.indentate(level) + '<' + key + '?' + this.tagEndChar;
|
|
16066
16633
|
else val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;
|
|
16067
16634
|
else if ('object' == typeof item) if (this.options.oneListGroup) {
|
|
16068
|
-
|
|
16635
|
+
matcher.push(key);
|
|
16636
|
+
const result = this.j2x(item, level + 1, matcher);
|
|
16637
|
+
matcher.pop();
|
|
16069
16638
|
listTagVal += result.val;
|
|
16070
16639
|
if (this.options.attributesGroupName && item.hasOwnProperty(this.options.attributesGroupName)) listTagAttr += result.attrStr;
|
|
16071
|
-
} else listTagVal += this.processTextOrObjNode(item, key, level,
|
|
16640
|
+
} else listTagVal += this.processTextOrObjNode(item, key, level, matcher);
|
|
16072
16641
|
else if (this.options.oneListGroup) {
|
|
16073
16642
|
let textValue = this.options.tagValueProcessor(key, item);
|
|
16074
16643
|
textValue = this.replaceEntitiesValue(textValue);
|
|
16075
16644
|
listTagVal += textValue;
|
|
16076
|
-
} else
|
|
16645
|
+
} else {
|
|
16646
|
+
matcher.push(key);
|
|
16647
|
+
const isStopNode = this.checkStopNode(matcher);
|
|
16648
|
+
matcher.pop();
|
|
16649
|
+
if (isStopNode) {
|
|
16650
|
+
const textValue = '' + item;
|
|
16651
|
+
if ('' === textValue) listTagVal += this.indentate(level) + '<' + key + this.closeTag(key) + this.tagEndChar;
|
|
16652
|
+
else listTagVal += this.indentate(level) + '<' + key + '>' + textValue + '</' + key + this.tagEndChar;
|
|
16653
|
+
} else listTagVal += this.buildTextValNode(item, key, '', level, matcher);
|
|
16654
|
+
}
|
|
16077
16655
|
}
|
|
16078
16656
|
if (this.options.oneListGroup) listTagVal = this.buildObjectNode(listTagVal, key, listTagAttr, level);
|
|
16079
16657
|
val += listTagVal;
|
|
16080
16658
|
} else if (this.options.attributesGroupName && key === this.options.attributesGroupName) {
|
|
16081
16659
|
const Ks = Object.keys(jObj[key]);
|
|
16082
16660
|
const L = Ks.length;
|
|
16083
|
-
for(let j = 0; j < L; j++)attrStr += this.buildAttrPairStr(Ks[j], '' + jObj[key][Ks[j]]);
|
|
16084
|
-
} else val += this.processTextOrObjNode(jObj[key], key, level,
|
|
16661
|
+
for(let j = 0; j < L; j++)attrStr += this.buildAttrPairStr(Ks[j], '' + jObj[key][Ks[j]], isCurrentStopNode);
|
|
16662
|
+
} else val += this.processTextOrObjNode(jObj[key], key, level, matcher);
|
|
16085
16663
|
return {
|
|
16086
16664
|
attrStr: attrStr,
|
|
16087
16665
|
val: val
|
|
16088
16666
|
};
|
|
16089
16667
|
};
|
|
16090
|
-
Builder.prototype.buildAttrPairStr = function(attrName, val) {
|
|
16091
|
-
|
|
16092
|
-
|
|
16668
|
+
Builder.prototype.buildAttrPairStr = function(attrName, val, isStopNode) {
|
|
16669
|
+
if (!isStopNode) {
|
|
16670
|
+
val = this.options.attributeValueProcessor(attrName, '' + val);
|
|
16671
|
+
val = this.replaceEntitiesValue(val);
|
|
16672
|
+
}
|
|
16093
16673
|
if (this.options.suppressBooleanAttributes && "true" === val) return ' ' + attrName;
|
|
16094
16674
|
return ' ' + attrName + '="' + val + '"';
|
|
16095
16675
|
};
|
|
16096
|
-
function processTextOrObjNode(object, key, level,
|
|
16097
|
-
const
|
|
16098
|
-
|
|
16676
|
+
function processTextOrObjNode(object, key, level, matcher) {
|
|
16677
|
+
const attrValues = this.extractAttributes(object);
|
|
16678
|
+
matcher.push(key, attrValues);
|
|
16679
|
+
const isStopNode = this.checkStopNode(matcher);
|
|
16680
|
+
if (isStopNode) {
|
|
16681
|
+
const rawContent = this.buildRawContent(object);
|
|
16682
|
+
const attrStr = this.buildAttributesForStopNode(object);
|
|
16683
|
+
matcher.pop();
|
|
16684
|
+
return this.buildObjectNode(rawContent, key, attrStr, level);
|
|
16685
|
+
}
|
|
16686
|
+
const result = this.j2x(object, level + 1, matcher);
|
|
16687
|
+
matcher.pop();
|
|
16688
|
+
if (void 0 !== object[this.options.textNodeName] && 1 === Object.keys(object).length) return this.buildTextValNode(object[this.options.textNodeName], key, result.attrStr, level, matcher);
|
|
16099
16689
|
return this.buildObjectNode(result.val, key, result.attrStr, level);
|
|
16100
16690
|
}
|
|
16691
|
+
Builder.prototype.extractAttributes = function(obj) {
|
|
16692
|
+
if (!obj || 'object' != typeof obj) return null;
|
|
16693
|
+
const attrValues = {};
|
|
16694
|
+
let hasAttrs = false;
|
|
16695
|
+
if (this.options.attributesGroupName && obj[this.options.attributesGroupName]) {
|
|
16696
|
+
const attrGroup = obj[this.options.attributesGroupName];
|
|
16697
|
+
for(let attrKey in attrGroup){
|
|
16698
|
+
if (!Object.prototype.hasOwnProperty.call(attrGroup, attrKey)) continue;
|
|
16699
|
+
const cleanKey = attrKey.startsWith(this.options.attributeNamePrefix) ? attrKey.substring(this.options.attributeNamePrefix.length) : attrKey;
|
|
16700
|
+
attrValues[cleanKey] = attrGroup[attrKey];
|
|
16701
|
+
hasAttrs = true;
|
|
16702
|
+
}
|
|
16703
|
+
} else for(let key in obj){
|
|
16704
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
16705
|
+
const attr = this.isAttribute(key);
|
|
16706
|
+
if (attr) {
|
|
16707
|
+
attrValues[attr] = obj[key];
|
|
16708
|
+
hasAttrs = true;
|
|
16709
|
+
}
|
|
16710
|
+
}
|
|
16711
|
+
return hasAttrs ? attrValues : null;
|
|
16712
|
+
};
|
|
16713
|
+
Builder.prototype.buildRawContent = function(obj) {
|
|
16714
|
+
if ('string' == typeof obj) return obj;
|
|
16715
|
+
if ('object' != typeof obj || null === obj) return String(obj);
|
|
16716
|
+
if (void 0 !== obj[this.options.textNodeName]) return obj[this.options.textNodeName];
|
|
16717
|
+
let content = '';
|
|
16718
|
+
for(let key in obj){
|
|
16719
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
16720
|
+
if (this.isAttribute(key)) continue;
|
|
16721
|
+
if (this.options.attributesGroupName && key === this.options.attributesGroupName) continue;
|
|
16722
|
+
const value = obj[key];
|
|
16723
|
+
if (key === this.options.textNodeName) content += value;
|
|
16724
|
+
else if (Array.isArray(value)) {
|
|
16725
|
+
for (let item of value)if ('string' == typeof item || 'number' == typeof item) content += `<${key}>${item}</${key}>`;
|
|
16726
|
+
else if ('object' == typeof item && null !== item) {
|
|
16727
|
+
const nestedContent = this.buildRawContent(item);
|
|
16728
|
+
const nestedAttrs = this.buildAttributesForStopNode(item);
|
|
16729
|
+
if ('' === nestedContent) content += `<${key}${nestedAttrs}/>`;
|
|
16730
|
+
else content += `<${key}${nestedAttrs}>${nestedContent}</${key}>`;
|
|
16731
|
+
}
|
|
16732
|
+
} else if ('object' == typeof value && null !== value) {
|
|
16733
|
+
const nestedContent = this.buildRawContent(value);
|
|
16734
|
+
const nestedAttrs = this.buildAttributesForStopNode(value);
|
|
16735
|
+
if ('' === nestedContent) content += `<${key}${nestedAttrs}/>`;
|
|
16736
|
+
else content += `<${key}${nestedAttrs}>${nestedContent}</${key}>`;
|
|
16737
|
+
} else content += `<${key}>${value}</${key}>`;
|
|
16738
|
+
}
|
|
16739
|
+
return content;
|
|
16740
|
+
};
|
|
16741
|
+
Builder.prototype.buildAttributesForStopNode = function(obj) {
|
|
16742
|
+
if (!obj || 'object' != typeof obj) return '';
|
|
16743
|
+
let attrStr = '';
|
|
16744
|
+
if (this.options.attributesGroupName && obj[this.options.attributesGroupName]) {
|
|
16745
|
+
const attrGroup = obj[this.options.attributesGroupName];
|
|
16746
|
+
for(let attrKey in attrGroup){
|
|
16747
|
+
if (!Object.prototype.hasOwnProperty.call(attrGroup, attrKey)) continue;
|
|
16748
|
+
const cleanKey = attrKey.startsWith(this.options.attributeNamePrefix) ? attrKey.substring(this.options.attributeNamePrefix.length) : attrKey;
|
|
16749
|
+
const val = attrGroup[attrKey];
|
|
16750
|
+
if (true === val && this.options.suppressBooleanAttributes) attrStr += ' ' + cleanKey;
|
|
16751
|
+
else attrStr += ' ' + cleanKey + '="' + val + '"';
|
|
16752
|
+
}
|
|
16753
|
+
} else for(let key in obj){
|
|
16754
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
16755
|
+
const attr = this.isAttribute(key);
|
|
16756
|
+
if (attr) {
|
|
16757
|
+
const val = obj[key];
|
|
16758
|
+
if (true === val && this.options.suppressBooleanAttributes) attrStr += ' ' + attr;
|
|
16759
|
+
else attrStr += ' ' + attr + '="' + val + '"';
|
|
16760
|
+
}
|
|
16761
|
+
}
|
|
16762
|
+
return attrStr;
|
|
16763
|
+
};
|
|
16101
16764
|
Builder.prototype.buildObjectNode = function(val, key, attrStr, level) {
|
|
16102
16765
|
if ("" === val) if ("?" === key[0]) return this.indentate(level) + '<' + key + attrStr + '?' + this.tagEndChar;
|
|
16103
16766
|
else return this.indentate(level) + '<' + key + attrStr + this.closeTag(key) + this.tagEndChar;
|
|
@@ -16120,7 +16783,12 @@ and limitations under the License.
|
|
|
16120
16783
|
} else closeTag = this.options.suppressEmptyNode ? "/" : `></${key}`;
|
|
16121
16784
|
return closeTag;
|
|
16122
16785
|
};
|
|
16123
|
-
Builder.prototype.
|
|
16786
|
+
Builder.prototype.checkStopNode = function(matcher) {
|
|
16787
|
+
if (!this.stopNodeExpressions || 0 === this.stopNodeExpressions.length) return false;
|
|
16788
|
+
for(let i = 0; i < this.stopNodeExpressions.length; i++)if (matcher.matches(this.stopNodeExpressions[i])) return true;
|
|
16789
|
+
return false;
|
|
16790
|
+
};
|
|
16791
|
+
Builder.prototype.buildTextValNode = function(val, key, attrStr, level, matcher) {
|
|
16124
16792
|
if (false !== this.options.cdataPropName && key === this.options.cdataPropName) return this.indentate(level) + `<![CDATA[${val}]]>` + this.newLine;
|
|
16125
16793
|
{
|
|
16126
16794
|
if (false !== this.options.commentPropName && key === this.options.commentPropName) return this.indentate(level) + `<!--${val}-->` + this.newLine;
|
|
@@ -16145,6 +16813,7 @@ and limitations under the License.
|
|
|
16145
16813
|
if (name.startsWith(this.options.attributeNamePrefix) && name !== this.options.textNodeName) return name.substr(this.attrPrefixLen);
|
|
16146
16814
|
return false;
|
|
16147
16815
|
}
|
|
16816
|
+
const json2xml = Builder;
|
|
16148
16817
|
var json_bigint = __webpack_require__("../../node_modules/.pnpm/json-bigint@1.0.0/node_modules/json-bigint/index.js");
|
|
16149
16818
|
var json_bigint_default = /*#__PURE__*/ __webpack_require__.n(json_bigint);
|
|
16150
16819
|
var descriptors_ScalarType;
|
|
@@ -16537,12 +17206,12 @@ and limitations under the License.
|
|
|
16537
17206
|
break;
|
|
16538
17207
|
}
|
|
16539
17208
|
}
|
|
16540
|
-
function
|
|
17209
|
+
function isObject(arg) {
|
|
16541
17210
|
return null !== arg && "object" == typeof arg && !Array.isArray(arg);
|
|
16542
17211
|
}
|
|
16543
17212
|
function isReflectList(arg, field) {
|
|
16544
17213
|
var _a, _b, _c, _d;
|
|
16545
|
-
if (
|
|
17214
|
+
if (isObject(arg) && unsafeLocal in arg && "add" in arg && "field" in arg && "function" == typeof arg.field) {
|
|
16546
17215
|
if (void 0 !== field) {
|
|
16547
17216
|
const a = field;
|
|
16548
17217
|
const b = arg.field();
|
|
@@ -16554,7 +17223,7 @@ and limitations under the License.
|
|
|
16554
17223
|
}
|
|
16555
17224
|
function isReflectMap(arg, field) {
|
|
16556
17225
|
var _a, _b, _c, _d;
|
|
16557
|
-
if (
|
|
17226
|
+
if (isObject(arg) && unsafeLocal in arg && "has" in arg && "field" in arg && "function" == typeof arg.field) {
|
|
16558
17227
|
if (void 0 !== field) {
|
|
16559
17228
|
const a = field, b = arg.field();
|
|
16560
17229
|
return a.mapKey === b.mapKey && a.mapKind == b.mapKind && a.scalar === b.scalar && (null == (_a = a.message) ? void 0 : _a.typeName) === (null == (_b = b.message) ? void 0 : _b.typeName) && (null == (_c = a.enum) ? void 0 : _c.typeName) === (null == (_d = b.enum) ? void 0 : _d.typeName);
|
|
@@ -16564,7 +17233,7 @@ and limitations under the License.
|
|
|
16564
17233
|
return false;
|
|
16565
17234
|
}
|
|
16566
17235
|
function isReflectMessage(arg, messageDesc) {
|
|
16567
|
-
return
|
|
17236
|
+
return isObject(arg) && unsafeLocal in arg && "desc" in arg && isObject(arg.desc) && "message" === arg.desc.kind && (void 0 === messageDesc || arg.desc.typeName == messageDesc.typeName);
|
|
16568
17237
|
}
|
|
16569
17238
|
const symbol = Symbol.for("@bufbuild/protobuf/text-encoding");
|
|
16570
17239
|
function getTextEncoding() {
|
|
@@ -17089,7 +17758,7 @@ and limitations under the License.
|
|
|
17089
17758
|
return value;
|
|
17090
17759
|
}
|
|
17091
17760
|
function initMap(field, value) {
|
|
17092
|
-
if (
|
|
17761
|
+
if (isObject(value)) {
|
|
17093
17762
|
if (field.scalar == descriptors_ScalarType.BYTES) return convertObjectValues(value, toU8Arr);
|
|
17094
17763
|
if ("message" == field.mapKind) return convertObjectValues(value, (val)=>toMessage(field, val));
|
|
17095
17764
|
}
|
|
@@ -17104,7 +17773,7 @@ and limitations under the License.
|
|
|
17104
17773
|
}
|
|
17105
17774
|
function toMessage(field, value) {
|
|
17106
17775
|
if ("message" == field.fieldKind && !field.oneof && isWrapperDesc(field.message)) return initScalar(field.message.fields[0], value);
|
|
17107
|
-
if (
|
|
17776
|
+
if (isObject(value)) {
|
|
17108
17777
|
if ("google.protobuf.Struct" == field.message.typeName && "google.protobuf.Value" !== field.parent.typeName) return value;
|
|
17109
17778
|
if (!is_message_isMessage(value, field.message)) return create(field.message, value);
|
|
17110
17779
|
}
|
|
@@ -17384,7 +18053,7 @@ and limitations under the License.
|
|
|
17384
18053
|
$typeName: field.message.typeName,
|
|
17385
18054
|
value: longToReflect(field.message.fields[0], value)
|
|
17386
18055
|
};
|
|
17387
|
-
else if ("google.protobuf.Struct" == field.message.typeName && "google.protobuf.Value" != field.parent.typeName &&
|
|
18056
|
+
else if ("google.protobuf.Struct" == field.message.typeName && "google.protobuf.Value" != field.parent.typeName && isObject(value)) value = wktStructToReflect(value);
|
|
17388
18057
|
}
|
|
17389
18058
|
return new ReflectMessageImpl(field.message, value, check);
|
|
17390
18059
|
}
|
|
@@ -17478,7 +18147,7 @@ and limitations under the License.
|
|
|
17478
18147
|
$typeName: "google.protobuf.Struct",
|
|
17479
18148
|
fields: {}
|
|
17480
18149
|
};
|
|
17481
|
-
if (
|
|
18150
|
+
if (isObject(json)) for (const [k, v] of Object.entries(json))struct.fields[k] = wktValueToReflect(v);
|
|
17482
18151
|
return struct;
|
|
17483
18152
|
}
|
|
17484
18153
|
function wktStructToLocal(val) {
|
|
@@ -21101,7 +21770,7 @@ and limitations under the License.
|
|
|
21101
21770
|
function timestamp_timestampMs(timestamp) {
|
|
21102
21771
|
return 1000 * Number(timestamp.seconds) + Math.round(timestamp.nanos / 1000000);
|
|
21103
21772
|
}
|
|
21104
|
-
var package_namespaceObject = JSON.parse('{"UU":"@dan-uni/dan-any","rE":"1.3.
|
|
21773
|
+
var package_namespaceObject = JSON.parse('{"UU":"@dan-uni/dan-any","rE":"1.3.4","TB":"https://github.com/ani-uni/danuni/tree/master/packages/dan-any#readme"}');
|
|
21105
21774
|
const color_pad = (s)=>s.length < 2 ? `0${s}` : s;
|
|
21106
21775
|
const decimalToHex = (n)=>color_pad(n.toString(16));
|
|
21107
21776
|
const isDarkColor = ({ r, g, b })=>0.299 * r + 0.587 * g + 0.114 * b < 0x30;
|
|
@@ -21858,9 +22527,7 @@ and limitations under the License.
|
|
|
21858
22527
|
ValidationExecutor.prototype.customValidations = function(object, value, metadatas, error) {
|
|
21859
22528
|
var _this = this;
|
|
21860
22529
|
metadatas.forEach(function(metadata) {
|
|
21861
|
-
|
|
21862
|
-
if (customConstraintMetadata.async && _this.ignoreAsyncValidations) return;
|
|
21863
|
-
if (_this.validatorOptions && _this.validatorOptions.stopAtFirstError && Object.keys(error.constraints || {}).length > 0) return;
|
|
22530
|
+
var getValidationArguments = function() {
|
|
21864
22531
|
var validationArguments = {
|
|
21865
22532
|
targetName: object.constructor ? object.constructor.name : void 0,
|
|
21866
22533
|
property: metadata.propertyName,
|
|
@@ -21868,6 +22535,16 @@ and limitations under the License.
|
|
|
21868
22535
|
value: value,
|
|
21869
22536
|
constraints: metadata.constraints
|
|
21870
22537
|
};
|
|
22538
|
+
return validationArguments;
|
|
22539
|
+
};
|
|
22540
|
+
if (metadata.validateIf) {
|
|
22541
|
+
var shouldValidate = metadata.validateIf(object, value);
|
|
22542
|
+
if (!shouldValidate) return;
|
|
22543
|
+
}
|
|
22544
|
+
_this.metadataStorage.getTargetValidatorConstraints(metadata.constraintCls).forEach(function(customConstraintMetadata) {
|
|
22545
|
+
if (customConstraintMetadata.async && _this.ignoreAsyncValidations) return;
|
|
22546
|
+
if (_this.validatorOptions && _this.validatorOptions.stopAtFirstError && Object.keys(error.constraints || {}).length > 0) return;
|
|
22547
|
+
var validationArguments = getValidationArguments();
|
|
21871
22548
|
if (!metadata.each || !(Array.isArray(value) || value instanceof Set || value instanceof Map)) {
|
|
21872
22549
|
var validatedValue = customConstraintMetadata.instance.validate(value, validationArguments);
|
|
21873
22550
|
if (is_promise_util_isPromise(validatedValue)) {
|
|
@@ -23407,7 +24084,7 @@ and limitations under the License.
|
|
|
23407
24084
|
do {
|
|
23408
24085
|
bits.unshift(!!(1 & number));
|
|
23409
24086
|
number >>= 1;
|
|
23410
|
-
}while (number)
|
|
24087
|
+
}while (number)
|
|
23411
24088
|
return bits.toReversed();
|
|
23412
24089
|
};
|
|
23413
24090
|
var dm_gen_DMAttr = /*#__PURE__*/ function(DMAttr) {
|
|
@@ -23501,7 +24178,7 @@ and limitations under the License.
|
|
|
23501
24178
|
if (!this.SOID) this.SOID = def.SOID;
|
|
23502
24179
|
if (!this.progress) this.progress = def.progress;
|
|
23503
24180
|
if (!this.mode) this.mode = def.mode;
|
|
23504
|
-
if (!this.fontsize) this.fontsize = def.
|
|
24181
|
+
if (!this.fontsize) this.fontsize = def.fontsize;
|
|
23505
24182
|
if (!this.color) this.color = def.color;
|
|
23506
24183
|
if (!this.senderID) this.senderID = def.senderID;
|
|
23507
24184
|
if (!this.content) this.content = def.content;
|
|
@@ -24396,7 +25073,7 @@ and limitations under the License.
|
|
|
24396
25073
|
const rawText = JSON.stringify(raw1);
|
|
24397
25074
|
let compress;
|
|
24398
25075
|
compress = 'brotli' === compressType ? (0, lib.brotliCompressSync)(rawText) : (0, lib.gzipSync)(rawText);
|
|
24399
|
-
return `;RawCompressType: ${compressType}\n;RawBaseType: ${baseType}\n;Raw: ${'base64' === baseType ? compress.toString('base64') : fromUint16Array(base16384_lib.
|
|
25076
|
+
return `;RawCompressType: ${compressType}\n;RawBaseType: ${baseType}\n;Raw: ${'base64' === baseType ? compress.toString('base64') : fromUint16Array(base16384_lib.lF(compress))}`;
|
|
24400
25077
|
}
|
|
24401
25078
|
function deRaw(ass) {
|
|
24402
25079
|
const arr = ass.split('\n');
|
|
@@ -24410,7 +25087,7 @@ and limitations under the License.
|
|
|
24410
25087
|
if (!compressTypes.has(compressType)) compressType = 'gzip';
|
|
24411
25088
|
if (!baseTypes.has(baseType)) baseType = 'base64';
|
|
24412
25089
|
const text = lineRaw.replace(';Raw: ', '').trim();
|
|
24413
|
-
const buffer = 'base64' === baseType ? raw_Buffer.from(text, 'base64') : raw_Buffer.from(base16384_lib.
|
|
25090
|
+
const buffer = 'base64' === baseType ? raw_Buffer.from(text, 'base64') : raw_Buffer.from(base16384_lib.D4(raw_Buffer.from(text, 'utf8').toString('utf8')));
|
|
24414
25091
|
let decompress;
|
|
24415
25092
|
decompress = 'brotli' === compressType ? (0, lib.brotliDecompressSync)(buffer) : (0, lib.gunzipSync)(buffer);
|
|
24416
25093
|
try {
|
|
@@ -24533,6 +25210,31 @@ and limitations under the License.
|
|
|
24533
25210
|
file_google_protobuf_timestamp
|
|
24534
25211
|
]);
|
|
24535
25212
|
const ListDanResponseSchema = /*@__PURE__*/ message_messageDesc(file_danuni_danmaku_v1_danmaku, 2);
|
|
25213
|
+
function fileParser(file, mod) {
|
|
25214
|
+
const isBinary = file instanceof ArrayBuffer || file instanceof Uint8Array;
|
|
25215
|
+
switch(mod){
|
|
25216
|
+
case 'bin':
|
|
25217
|
+
if (isBinary) return file;
|
|
25218
|
+
throw new TypeError('Expected binary data for mod "bin"');
|
|
25219
|
+
case 'string':
|
|
25220
|
+
if ('string' == typeof file) return file;
|
|
25221
|
+
if (isBinary) return new TextDecoder().decode(file);
|
|
25222
|
+
throw new TypeError('Expected binary data or string for mod "string"');
|
|
25223
|
+
case 'json':
|
|
25224
|
+
{
|
|
25225
|
+
if ('object' == typeof file && null !== file && !isBinary) return file;
|
|
25226
|
+
if ('string' != typeof file && !isBinary) throw new TypeError('Expected object, JSON string, or binary data for mod "json"');
|
|
25227
|
+
const str = 'string' == typeof file ? file : new TextDecoder().decode(file);
|
|
25228
|
+
try {
|
|
25229
|
+
return JSON.parse(str);
|
|
25230
|
+
} catch {
|
|
25231
|
+
throw new Error('Invalid JSON string');
|
|
25232
|
+
}
|
|
25233
|
+
}
|
|
25234
|
+
default:
|
|
25235
|
+
throw new Error(`Unsupported mod "${mod}"`);
|
|
25236
|
+
}
|
|
25237
|
+
}
|
|
24536
25238
|
const src_JSON = json_bigint_default()({
|
|
24537
25239
|
useNativeBigInt: true
|
|
24538
25240
|
});
|
|
@@ -24766,6 +25468,87 @@ and limitations under the License.
|
|
|
24766
25468
|
return this.dans.map((d)=>d.minify());
|
|
24767
25469
|
}
|
|
24768
25470
|
static import(file, options, mod) {
|
|
25471
|
+
const handlers = {
|
|
25472
|
+
["danuni.json"]: (json)=>({
|
|
25473
|
+
pool: new UniPool(json, options),
|
|
25474
|
+
fmt: "danuni.json"
|
|
25475
|
+
}),
|
|
25476
|
+
["danuni.min.json"]: (json)=>({
|
|
25477
|
+
pool: this.fromMin(json, options),
|
|
25478
|
+
fmt: "danuni.min.json"
|
|
25479
|
+
}),
|
|
25480
|
+
["danuni.binpb"]: (file)=>({
|
|
25481
|
+
pool: this.fromPb(file),
|
|
25482
|
+
fmt: "danuni.binpb"
|
|
25483
|
+
}),
|
|
25484
|
+
["bili.xml"]: (file)=>({
|
|
25485
|
+
pool: this.fromBiliXML(file, options),
|
|
25486
|
+
fmt: "bili.xml"
|
|
25487
|
+
}),
|
|
25488
|
+
["bili.binpb"]: (file)=>({
|
|
25489
|
+
pool: this.fromBiliGrpc(file),
|
|
25490
|
+
fmt: "bili.binpb"
|
|
25491
|
+
}),
|
|
25492
|
+
["bili.cmd.binpb"]: (file)=>({
|
|
25493
|
+
pool: this.fromBiliCommandGrpc(file),
|
|
25494
|
+
fmt: "bili.cmd.binpb"
|
|
25495
|
+
}),
|
|
25496
|
+
["bili.up.json"]: (json)=>({
|
|
25497
|
+
pool: this.fromBiliUp(json, options),
|
|
25498
|
+
fmt: "bili.up.json"
|
|
25499
|
+
}),
|
|
25500
|
+
["dplayer.json"]: (json)=>({
|
|
25501
|
+
pool: this.fromDplayer(json, json.danuni?.data ?? '', void 0, options),
|
|
25502
|
+
fmt: "dplayer.json"
|
|
25503
|
+
}),
|
|
25504
|
+
["artplayer.json"]: (json)=>({
|
|
25505
|
+
pool: this.fromArtplayer(json, json.danuni?.data ?? '', void 0, options),
|
|
25506
|
+
fmt: "artplayer.json"
|
|
25507
|
+
}),
|
|
25508
|
+
["ddplay.json"]: (json)=>({
|
|
25509
|
+
pool: this.fromDDPlay(json, json.danuni?.data ?? '', options),
|
|
25510
|
+
fmt: "ddplay.json"
|
|
25511
|
+
}),
|
|
25512
|
+
["common.ass"]: (file)=>({
|
|
25513
|
+
pool: this.fromASS(file, options),
|
|
25514
|
+
fmt: "common.ass"
|
|
25515
|
+
})
|
|
25516
|
+
};
|
|
25517
|
+
if ('string' == typeof mod) {
|
|
25518
|
+
const fn = mod;
|
|
25519
|
+
try {
|
|
25520
|
+
if (fn.endsWith("danuni.json")) return handlers["danuni.json"](fileParser(file, 'json'));
|
|
25521
|
+
if (fn.endsWith("danuni.min.json")) return handlers["danuni.min.json"](fileParser(file, 'json'));
|
|
25522
|
+
if (fn.endsWith("danuni.binpb")) return handlers["danuni.binpb"](fileParser(file, 'bin'));
|
|
25523
|
+
else if (fn.endsWith("bili.xml")) return handlers["bili.xml"](fileParser(file, 'string'));
|
|
25524
|
+
else if (fn.endsWith("bili.binpb")) return handlers["bili.binpb"](fileParser(file, 'bin'));
|
|
25525
|
+
else if (fn.endsWith("bili.cmd.binpb")) return handlers["bili.cmd.binpb"](fileParser(file, 'bin'));
|
|
25526
|
+
else if (fn.endsWith("bili.up.json")) return handlers["bili.up.json"](fileParser(file, 'json'));
|
|
25527
|
+
else if (fn.endsWith("dplayer.json")) return handlers["dplayer.json"](fileParser(file, 'json'));
|
|
25528
|
+
else if (fn.endsWith("artplayer.json")) return handlers["artplayer.json"](fileParser(file, 'json'));
|
|
25529
|
+
else if (fn.endsWith("ddplay.json")) return handlers["ddplay.json"](fileParser(file, 'json'));
|
|
25530
|
+
else if (fn.endsWith("common.ass")) return handlers["common.ass"](fileParser(file, 'string'));
|
|
25531
|
+
} catch {}
|
|
25532
|
+
const ext = fn.split('.').pop()?.toLowerCase();
|
|
25533
|
+
if (ext) {
|
|
25534
|
+
if ('json' === ext) mod = [
|
|
25535
|
+
'json'
|
|
25536
|
+
];
|
|
25537
|
+
else if ([
|
|
25538
|
+
'xml',
|
|
25539
|
+
'ass'
|
|
25540
|
+
].includes(ext)) mod = [
|
|
25541
|
+
'str'
|
|
25542
|
+
];
|
|
25543
|
+
else if ([
|
|
25544
|
+
'binpb',
|
|
25545
|
+
'bin',
|
|
25546
|
+
'so'
|
|
25547
|
+
].includes(ext)) mod = [
|
|
25548
|
+
'bin'
|
|
25549
|
+
];
|
|
25550
|
+
}
|
|
25551
|
+
}
|
|
24769
25552
|
if (!mod) mod = [
|
|
24770
25553
|
'json',
|
|
24771
25554
|
'str',
|
|
@@ -24774,26 +25557,11 @@ and limitations under the License.
|
|
|
24774
25557
|
const err = '无法识别该文件,请手动指定格式!';
|
|
24775
25558
|
const parseJSON = (json)=>{
|
|
24776
25559
|
try {
|
|
24777
|
-
if (Array.isArray(json) && json.every((d)=>d.SOID)) return
|
|
24778
|
-
|
|
24779
|
-
|
|
24780
|
-
|
|
24781
|
-
if (json.
|
|
24782
|
-
pool: this.fromArtplayer(json, json.danuni?.data ?? '', void 0, options),
|
|
24783
|
-
fmt: "artplayer.json"
|
|
24784
|
-
};
|
|
24785
|
-
if (json.count && json.comments && Array.isArray(json.comments) && json.comments.every((d)=>d.m)) return {
|
|
24786
|
-
pool: this.fromDDPlay(json, json.danuni?.data ?? '', options),
|
|
24787
|
-
fmt: "ddplay.json"
|
|
24788
|
-
};
|
|
24789
|
-
else if (0 == json.code && json.data && Array.isArray(json.data) && json.data.every((d)=>Array.isArray(d))) return {
|
|
24790
|
-
pool: this.fromDplayer(json, json.danuni?.data ?? '', void 0, options),
|
|
24791
|
-
fmt: "dplayer.json"
|
|
24792
|
-
};
|
|
24793
|
-
else if (0 == json.code && '0' == json.message && json.data && json.data.page && json.data.result && Array.isArray(json.data.result) && json.data.result.every((d)=>d.id && d.oid)) return {
|
|
24794
|
-
pool: this.fromBiliUp(json, options),
|
|
24795
|
-
fmt: "bili.up.json"
|
|
24796
|
-
};
|
|
25560
|
+
if (Array.isArray(json) && json.every((d)=>d.SOID)) return handlers["danuni.min.json"](json);
|
|
25561
|
+
if (json.danmuku && json.danmuku.every((d)=>d.text)) return handlers["artplayer.json"](json);
|
|
25562
|
+
if (json.count && json.comments && Array.isArray(json.comments) && json.comments.every((d)=>d.m)) return handlers["ddplay.json"](json);
|
|
25563
|
+
else if (0 == json.code && json.data && Array.isArray(json.data) && json.data.every((d)=>Array.isArray(d))) return handlers["dplayer.json"](json);
|
|
25564
|
+
else if (0 == json.code && '0' == json.message && json.data && json.data.page && json.data.result && Array.isArray(json.data.result) && json.data.result.every((d)=>d.id && d.oid)) return handlers["bili.up.json"](json);
|
|
24797
25565
|
} catch {}
|
|
24798
25566
|
};
|
|
24799
25567
|
const parseStr = (file)=>{
|
|
@@ -24809,40 +25577,25 @@ and limitations under the License.
|
|
|
24809
25577
|
ignoreAttributes: false
|
|
24810
25578
|
});
|
|
24811
25579
|
const xml = xmlParser.parse(file);
|
|
24812
|
-
if (xml?.i?.d) return
|
|
24813
|
-
pool: this.fromBiliXML(file, options),
|
|
24814
|
-
fmt: "bili.xml"
|
|
24815
|
-
};
|
|
25580
|
+
if (xml?.i?.d) return handlers["bili.xml"](file);
|
|
24816
25581
|
} catch {}
|
|
24817
25582
|
try {
|
|
24818
|
-
return
|
|
24819
|
-
pool: this.fromASS(file, options),
|
|
24820
|
-
fmt: "common.ass"
|
|
24821
|
-
};
|
|
25583
|
+
return handlers["common.ass"](file);
|
|
24822
25584
|
} catch {}
|
|
24823
25585
|
}
|
|
24824
25586
|
};
|
|
24825
25587
|
let errmesg;
|
|
24826
|
-
if (
|
|
25588
|
+
if ('object' == typeof file || Array.isArray(file)) {
|
|
24827
25589
|
if (file instanceof ArrayBuffer || file instanceof Uint8Array) {
|
|
24828
25590
|
if (mod.includes('bin')) {
|
|
24829
25591
|
try {
|
|
24830
|
-
return
|
|
24831
|
-
pool: this.fromPb(file),
|
|
24832
|
-
fmt: "danuni.binpb"
|
|
24833
|
-
};
|
|
25592
|
+
return handlers["danuni.binpb"](file);
|
|
24834
25593
|
} catch {}
|
|
24835
25594
|
try {
|
|
24836
|
-
return
|
|
24837
|
-
pool: this.fromBiliGrpc(file),
|
|
24838
|
-
fmt: "bili.binpb"
|
|
24839
|
-
};
|
|
25595
|
+
return handlers["bili.binpb"](file);
|
|
24840
25596
|
} catch {}
|
|
24841
25597
|
try {
|
|
24842
|
-
return
|
|
24843
|
-
pool: this.fromBiliCommandGrpc(file),
|
|
24844
|
-
fmt: "bili.cmd.binpb"
|
|
24845
|
-
};
|
|
25598
|
+
return handlers["bili.cmd.binpb"](file);
|
|
24846
25599
|
} catch {}
|
|
24847
25600
|
}
|
|
24848
25601
|
try {
|
|
@@ -24863,21 +25616,56 @@ and limitations under the License.
|
|
|
24863
25616
|
}
|
|
24864
25617
|
throw new Error(errmesg ?? err);
|
|
24865
25618
|
}
|
|
24866
|
-
convert2(format, continue_on_error = false) {
|
|
25619
|
+
convert2(format, file_wrapper = false, continue_on_error = false) {
|
|
24867
25620
|
switch(format){
|
|
24868
|
-
case
|
|
25621
|
+
case "danuni.json":
|
|
25622
|
+
if (file_wrapper) return new File([
|
|
25623
|
+
src_JSON.stringify(this.dans)
|
|
25624
|
+
], "danuni.json", {
|
|
25625
|
+
type: 'application/json'
|
|
25626
|
+
});
|
|
24869
25627
|
return this.dans;
|
|
24870
|
-
case
|
|
25628
|
+
case "danuni.min.json":
|
|
25629
|
+
if (file_wrapper) return new File([
|
|
25630
|
+
src_JSON.stringify(this.minify())
|
|
25631
|
+
], "danuni.min.json", {
|
|
25632
|
+
type: 'application/json'
|
|
25633
|
+
});
|
|
24871
25634
|
return this.minify();
|
|
24872
|
-
case
|
|
25635
|
+
case "danuni.binpb":
|
|
25636
|
+
if (file_wrapper) return new File([
|
|
25637
|
+
this.toPb()
|
|
25638
|
+
], "danuni.binpb", {
|
|
25639
|
+
type: 'application/protobuf'
|
|
25640
|
+
});
|
|
24873
25641
|
return this.toPb();
|
|
24874
|
-
case
|
|
25642
|
+
case "bili.xml":
|
|
25643
|
+
if (file_wrapper) return new File([
|
|
25644
|
+
this.toBiliXML()
|
|
25645
|
+
], "bili.xml", {
|
|
25646
|
+
type: 'application/xml'
|
|
25647
|
+
});
|
|
24875
25648
|
return this.toBiliXML();
|
|
24876
|
-
case
|
|
25649
|
+
case "dplayer.json":
|
|
25650
|
+
if (file_wrapper) return new File([
|
|
25651
|
+
src_JSON.stringify(this.toDplayer())
|
|
25652
|
+
], "dplayer.json", {
|
|
25653
|
+
type: 'application/json'
|
|
25654
|
+
});
|
|
24877
25655
|
return this.toDplayer();
|
|
24878
|
-
case
|
|
25656
|
+
case "artplayer.json":
|
|
25657
|
+
if (file_wrapper) return new File([
|
|
25658
|
+
src_JSON.stringify(this.toArtplayer())
|
|
25659
|
+
], "artplayer.json", {
|
|
25660
|
+
type: 'application/json'
|
|
25661
|
+
});
|
|
24879
25662
|
return this.toArtplayer();
|
|
24880
|
-
case
|
|
25663
|
+
case "ddplay.json":
|
|
25664
|
+
if (file_wrapper) return new File([
|
|
25665
|
+
src_JSON.stringify(this.toDDplay())
|
|
25666
|
+
], "ddplay.json", {
|
|
25667
|
+
type: 'application/json'
|
|
25668
|
+
});
|
|
24881
25669
|
return this.toDDplay();
|
|
24882
25670
|
default:
|
|
24883
25671
|
{
|
|
@@ -24887,6 +25675,9 @@ and limitations under the License.
|
|
|
24887
25675
|
}
|
|
24888
25676
|
}
|
|
24889
25677
|
}
|
|
25678
|
+
static fromMin(json, options) {
|
|
25679
|
+
return new UniPool(json.map((d)=>UniDM.create(d, options)));
|
|
25680
|
+
}
|
|
24890
25681
|
static fromPb(bin, options) {
|
|
24891
25682
|
const data = fromBinary(ListDanResponseSchema, new Uint8Array(bin));
|
|
24892
25683
|
return new UniPool(data.danmakus.map((d)=>UniDM.create({
|
|
@@ -24948,7 +25739,7 @@ and limitations under the License.
|
|
|
24948
25739
|
const ok = this.dans.every((d)=>d.senderID.endsWith(`@${platform.PlatformVideoSource.Bilibili}`));
|
|
24949
25740
|
if (!ok) throw new Error('存在其他来源的senderID,请关闭该功能再试!');
|
|
24950
25741
|
}
|
|
24951
|
-
const builder = new
|
|
25742
|
+
const builder = new json2xml({
|
|
24952
25743
|
ignoreAttributes: false
|
|
24953
25744
|
});
|
|
24954
25745
|
return builder.build({
|