@dan-uni/dan-any 1.3.0 → 1.3.3
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 +13384 -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 +4 -2
- package/dist/browser/src/utils/fileParser.d.ts +3 -0
- package/dist/node/index.js +1959 -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 +4 -2
- package/dist/node/src/utils/fileParser.d.ts +3 -0
- package/dist/umd/index.umd.min.js +1076 -320
- package/dist/umd/plugins/bili.umd.min.js +1077 -321
- package/dist/umd/plugins/index.umd.min.js +1077 -321
- package/dist/umd/src/index.d.ts +4 -2
- 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 +130 -43
- 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;
|
|
@@ -13581,9 +13581,6 @@
|
|
|
13581
13581
|
function IsJSON_isJSON(value) {
|
|
13582
13582
|
return 'string' == typeof value && isJSON_default()(value);
|
|
13583
13583
|
}
|
|
13584
|
-
function isObject(value) {
|
|
13585
|
-
return null != value && ('object' == typeof value || 'function' == typeof value) && !Array.isArray(value);
|
|
13586
|
-
}
|
|
13587
13584
|
var defaultContainer = new (function() {
|
|
13588
13585
|
function class_1() {
|
|
13589
13586
|
this.instances = [];
|
|
@@ -13649,6 +13646,7 @@
|
|
|
13649
13646
|
this.always = args.validationOptions.always;
|
|
13650
13647
|
this.each = args.validationOptions.each;
|
|
13651
13648
|
this.context = args.validationOptions.context;
|
|
13649
|
+
this.validateIf = args.validationOptions.validateIf;
|
|
13652
13650
|
}
|
|
13653
13651
|
}
|
|
13654
13652
|
return ValidationMetadata;
|
|
@@ -13923,6 +13921,48 @@
|
|
|
13923
13921
|
}
|
|
13924
13922
|
}, validationOptions);
|
|
13925
13923
|
}
|
|
13924
|
+
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';
|
|
13925
|
+
const nameChar = nameStartChar + '\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040';
|
|
13926
|
+
const nameRegexp = '[' + nameStartChar + '][' + nameChar + ']*';
|
|
13927
|
+
const regexName = new RegExp('^' + nameRegexp + '$');
|
|
13928
|
+
function getAllMatches(string, regex) {
|
|
13929
|
+
const matches = [];
|
|
13930
|
+
let match = regex.exec(string);
|
|
13931
|
+
while(match){
|
|
13932
|
+
const allmatches = [];
|
|
13933
|
+
allmatches.startIndex = regex.lastIndex - match[0].length;
|
|
13934
|
+
const len = match.length;
|
|
13935
|
+
for(let index = 0; index < len; index++)allmatches.push(match[index]);
|
|
13936
|
+
matches.push(allmatches);
|
|
13937
|
+
match = regex.exec(string);
|
|
13938
|
+
}
|
|
13939
|
+
return matches;
|
|
13940
|
+
}
|
|
13941
|
+
const isName = function(string) {
|
|
13942
|
+
const match = regexName.exec(string);
|
|
13943
|
+
return null != match;
|
|
13944
|
+
};
|
|
13945
|
+
function isExist(v) {
|
|
13946
|
+
return void 0 !== v;
|
|
13947
|
+
}
|
|
13948
|
+
const DANGEROUS_PROPERTY_NAMES = [
|
|
13949
|
+
'hasOwnProperty',
|
|
13950
|
+
'toString',
|
|
13951
|
+
'valueOf',
|
|
13952
|
+
'__defineGetter__',
|
|
13953
|
+
'__defineSetter__',
|
|
13954
|
+
'__lookupGetter__',
|
|
13955
|
+
'__lookupSetter__'
|
|
13956
|
+
];
|
|
13957
|
+
const criticalProperties = [
|
|
13958
|
+
"__proto__",
|
|
13959
|
+
"constructor",
|
|
13960
|
+
"prototype"
|
|
13961
|
+
];
|
|
13962
|
+
const defaultOnDangerousProperty = (name)=>{
|
|
13963
|
+
if (DANGEROUS_PROPERTY_NAMES.includes(name)) return "__" + name;
|
|
13964
|
+
return name;
|
|
13965
|
+
};
|
|
13926
13966
|
const OptionsBuilder_defaultOptions = {
|
|
13927
13967
|
preserveOrder: false,
|
|
13928
13968
|
attributeNamePrefix: '@_',
|
|
@@ -13960,8 +14000,18 @@
|
|
|
13960
14000
|
updateTag: function(tagName, jPath, attrs) {
|
|
13961
14001
|
return tagName;
|
|
13962
14002
|
},
|
|
13963
|
-
captureMetaData: false
|
|
13964
|
-
|
|
14003
|
+
captureMetaData: false,
|
|
14004
|
+
maxNestedTags: 100,
|
|
14005
|
+
strictReservedNames: true,
|
|
14006
|
+
jPath: true,
|
|
14007
|
+
onDangerousProperty: defaultOnDangerousProperty
|
|
14008
|
+
};
|
|
14009
|
+
function validatePropertyName(propertyName, optionName) {
|
|
14010
|
+
if ('string' != typeof propertyName) return;
|
|
14011
|
+
const normalized = propertyName.toLowerCase();
|
|
14012
|
+
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`);
|
|
14013
|
+
if (criticalProperties.some((dangerous)=>normalized === dangerous.toLowerCase())) throw new Error(`[SECURITY] Invalid ${optionName}: "${propertyName}" is a reserved JavaScript keyword that could cause prototype pollution`);
|
|
14014
|
+
}
|
|
13965
14015
|
function normalizeProcessEntities(value) {
|
|
13966
14016
|
if ('boolean' == typeof value) return {
|
|
13967
14017
|
enabled: value,
|
|
@@ -13969,15 +14019,17 @@
|
|
|
13969
14019
|
maxExpansionDepth: 10,
|
|
13970
14020
|
maxTotalExpansions: 1000,
|
|
13971
14021
|
maxExpandedLength: 100000,
|
|
14022
|
+
maxEntityCount: 100,
|
|
13972
14023
|
allowedTags: null,
|
|
13973
14024
|
tagFilter: null
|
|
13974
14025
|
};
|
|
13975
14026
|
if ('object' == typeof value && null !== value) return {
|
|
13976
14027
|
enabled: false !== value.enabled,
|
|
13977
|
-
maxEntitySize: value.maxEntitySize ?? 10000,
|
|
13978
|
-
maxExpansionDepth: value.maxExpansionDepth ?? 10,
|
|
13979
|
-
maxTotalExpansions: value.maxTotalExpansions ?? 1000,
|
|
13980
|
-
maxExpandedLength: value.maxExpandedLength ?? 100000,
|
|
14028
|
+
maxEntitySize: Math.max(1, value.maxEntitySize ?? 10000),
|
|
14029
|
+
maxExpansionDepth: Math.max(1, value.maxExpansionDepth ?? 10),
|
|
14030
|
+
maxTotalExpansions: Math.max(1, value.maxTotalExpansions ?? 1000),
|
|
14031
|
+
maxExpandedLength: Math.max(1, value.maxExpandedLength ?? 100000),
|
|
14032
|
+
maxEntityCount: Math.max(1, value.maxEntityCount ?? 100),
|
|
13981
14033
|
allowedTags: value.allowedTags ?? null,
|
|
13982
14034
|
tagFilter: value.tagFilter ?? null
|
|
13983
14035
|
};
|
|
@@ -13985,40 +14037,44 @@
|
|
|
13985
14037
|
}
|
|
13986
14038
|
const buildOptions = function(options) {
|
|
13987
14039
|
const built = Object.assign({}, OptionsBuilder_defaultOptions, options);
|
|
14040
|
+
const propertyNameOptions = [
|
|
14041
|
+
{
|
|
14042
|
+
value: built.attributeNamePrefix,
|
|
14043
|
+
name: 'attributeNamePrefix'
|
|
14044
|
+
},
|
|
14045
|
+
{
|
|
14046
|
+
value: built.attributesGroupName,
|
|
14047
|
+
name: 'attributesGroupName'
|
|
14048
|
+
},
|
|
14049
|
+
{
|
|
14050
|
+
value: built.textNodeName,
|
|
14051
|
+
name: 'textNodeName'
|
|
14052
|
+
},
|
|
14053
|
+
{
|
|
14054
|
+
value: built.cdataPropName,
|
|
14055
|
+
name: 'cdataPropName'
|
|
14056
|
+
},
|
|
14057
|
+
{
|
|
14058
|
+
value: built.commentPropName,
|
|
14059
|
+
name: 'commentPropName'
|
|
14060
|
+
}
|
|
14061
|
+
];
|
|
14062
|
+
for (const { value, name } of propertyNameOptions)if (value) validatePropertyName(value, name);
|
|
14063
|
+
if (null === built.onDangerousProperty) built.onDangerousProperty = defaultOnDangerousProperty;
|
|
13988
14064
|
built.processEntities = normalizeProcessEntities(built.processEntities);
|
|
14065
|
+
if (built.stopNodes && Array.isArray(built.stopNodes)) built.stopNodes = built.stopNodes.map((node)=>{
|
|
14066
|
+
if ('string' == typeof node && node.startsWith('*.')) return '..' + node.substring(2);
|
|
14067
|
+
return node;
|
|
14068
|
+
});
|
|
13989
14069
|
return built;
|
|
13990
14070
|
};
|
|
13991
|
-
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';
|
|
13992
|
-
const nameChar = nameStartChar + '\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040';
|
|
13993
|
-
const nameRegexp = '[' + nameStartChar + '][' + nameChar + ']*';
|
|
13994
|
-
const regexName = new RegExp('^' + nameRegexp + '$');
|
|
13995
|
-
function getAllMatches(string, regex) {
|
|
13996
|
-
const matches = [];
|
|
13997
|
-
let match = regex.exec(string);
|
|
13998
|
-
while(match){
|
|
13999
|
-
const allmatches = [];
|
|
14000
|
-
allmatches.startIndex = regex.lastIndex - match[0].length;
|
|
14001
|
-
const len = match.length;
|
|
14002
|
-
for(let index = 0; index < len; index++)allmatches.push(match[index]);
|
|
14003
|
-
matches.push(allmatches);
|
|
14004
|
-
match = regex.exec(string);
|
|
14005
|
-
}
|
|
14006
|
-
return matches;
|
|
14007
|
-
}
|
|
14008
|
-
const isName = function(string) {
|
|
14009
|
-
const match = regexName.exec(string);
|
|
14010
|
-
return null != match;
|
|
14011
|
-
};
|
|
14012
|
-
function isExist(v) {
|
|
14013
|
-
return void 0 !== v;
|
|
14014
|
-
}
|
|
14015
14071
|
let METADATA_SYMBOL;
|
|
14016
14072
|
METADATA_SYMBOL = "function" != typeof Symbol ? "@@xmlMetadata" : Symbol("XML Node Metadata");
|
|
14017
14073
|
class XmlNode {
|
|
14018
14074
|
constructor(tagname){
|
|
14019
14075
|
this.tagname = tagname;
|
|
14020
14076
|
this.child = [];
|
|
14021
|
-
this[":@"] =
|
|
14077
|
+
this[":@"] = Object.create(null);
|
|
14022
14078
|
}
|
|
14023
14079
|
add(key, val) {
|
|
14024
14080
|
if ("__proto__" === key) key = "#__proto__";
|
|
@@ -14049,7 +14105,8 @@
|
|
|
14049
14105
|
this.options = options;
|
|
14050
14106
|
}
|
|
14051
14107
|
readDocType(xmlData, i) {
|
|
14052
|
-
const entities =
|
|
14108
|
+
const entities = Object.create(null);
|
|
14109
|
+
let entityCount = 0;
|
|
14053
14110
|
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]) {
|
|
14054
14111
|
i += 9;
|
|
14055
14112
|
let angleBracketsCount = 1;
|
|
@@ -14070,11 +14127,13 @@
|
|
|
14070
14127
|
let entityName, val;
|
|
14071
14128
|
[entityName, val, i] = this.readEntityExp(xmlData, i + 1, this.suppressValidationErr);
|
|
14072
14129
|
if (-1 === val.indexOf("&")) {
|
|
14073
|
-
|
|
14130
|
+
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})`);
|
|
14131
|
+
const escaped = entityName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
14074
14132
|
entities[entityName] = {
|
|
14075
14133
|
regx: RegExp(`&${escaped};`, "g"),
|
|
14076
14134
|
val: val
|
|
14077
14135
|
};
|
|
14136
|
+
entityCount++;
|
|
14078
14137
|
}
|
|
14079
14138
|
} else if (hasBody && hasSeq(xmlData, "!ELEMENT", i)) {
|
|
14080
14139
|
i += 8;
|
|
@@ -14098,11 +14157,9 @@
|
|
|
14098
14157
|
}
|
|
14099
14158
|
readEntityExp(xmlData, i) {
|
|
14100
14159
|
i = skipWhitespace(xmlData, i);
|
|
14101
|
-
|
|
14102
|
-
while(i < xmlData.length && !/\s/.test(xmlData[i]) && '"' !== xmlData[i] && "'" !== xmlData[i])
|
|
14103
|
-
|
|
14104
|
-
i++;
|
|
14105
|
-
}
|
|
14160
|
+
const startIndex = i;
|
|
14161
|
+
while(i < xmlData.length && !/\s/.test(xmlData[i]) && '"' !== xmlData[i] && "'" !== xmlData[i])i++;
|
|
14162
|
+
let entityName = xmlData.substring(startIndex, i);
|
|
14106
14163
|
validateEntityName(entityName);
|
|
14107
14164
|
i = skipWhitespace(xmlData, i);
|
|
14108
14165
|
if (!this.suppressValidationErr) {
|
|
@@ -14111,7 +14168,7 @@
|
|
|
14111
14168
|
}
|
|
14112
14169
|
let entityValue = "";
|
|
14113
14170
|
[i, entityValue] = this.readIdentifierVal(xmlData, i, "entity");
|
|
14114
|
-
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})`);
|
|
14171
|
+
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})`);
|
|
14115
14172
|
i--;
|
|
14116
14173
|
return [
|
|
14117
14174
|
entityName,
|
|
@@ -14121,11 +14178,9 @@
|
|
|
14121
14178
|
}
|
|
14122
14179
|
readNotationExp(xmlData, i) {
|
|
14123
14180
|
i = skipWhitespace(xmlData, i);
|
|
14124
|
-
|
|
14125
|
-
while(i < xmlData.length && !/\s/.test(xmlData[i]))
|
|
14126
|
-
|
|
14127
|
-
i++;
|
|
14128
|
-
}
|
|
14181
|
+
const startIndex = i;
|
|
14182
|
+
while(i < xmlData.length && !/\s/.test(xmlData[i]))i++;
|
|
14183
|
+
let notationName = xmlData.substring(startIndex, i);
|
|
14129
14184
|
this.suppressValidationErr || validateEntityName(notationName);
|
|
14130
14185
|
i = skipWhitespace(xmlData, i);
|
|
14131
14186
|
const identifierType = xmlData.substring(i, i + 6).toUpperCase();
|
|
@@ -14154,10 +14209,9 @@
|
|
|
14154
14209
|
const startChar = xmlData[i];
|
|
14155
14210
|
if ('"' !== startChar && "'" !== startChar) throw new Error(`Expected quoted string, found "${startChar}"`);
|
|
14156
14211
|
i++;
|
|
14157
|
-
|
|
14158
|
-
|
|
14159
|
-
|
|
14160
|
-
}
|
|
14212
|
+
const startIndex = i;
|
|
14213
|
+
while(i < xmlData.length && xmlData[i] !== startChar)i++;
|
|
14214
|
+
identifierVal = xmlData.substring(startIndex, i);
|
|
14161
14215
|
if (xmlData[i] !== startChar) throw new Error(`Unterminated ${type} value`);
|
|
14162
14216
|
i++;
|
|
14163
14217
|
return [
|
|
@@ -14167,11 +14221,9 @@
|
|
|
14167
14221
|
}
|
|
14168
14222
|
readElementExp(xmlData, i) {
|
|
14169
14223
|
i = skipWhitespace(xmlData, i);
|
|
14170
|
-
|
|
14171
|
-
while(i < xmlData.length && !/\s/.test(xmlData[i]))
|
|
14172
|
-
|
|
14173
|
-
i++;
|
|
14174
|
-
}
|
|
14224
|
+
const startIndex = i;
|
|
14225
|
+
while(i < xmlData.length && !/\s/.test(xmlData[i]))i++;
|
|
14226
|
+
let elementName = xmlData.substring(startIndex, i);
|
|
14175
14227
|
if (!this.suppressValidationErr && !isName(elementName)) throw new Error(`Invalid element name: "${elementName}"`);
|
|
14176
14228
|
i = skipWhitespace(xmlData, i);
|
|
14177
14229
|
let contentModel = "";
|
|
@@ -14179,10 +14231,9 @@
|
|
|
14179
14231
|
else if ("A" === xmlData[i] && hasSeq(xmlData, "NY", i)) i += 2;
|
|
14180
14232
|
else if ("(" === xmlData[i]) {
|
|
14181
14233
|
i++;
|
|
14182
|
-
|
|
14183
|
-
|
|
14184
|
-
|
|
14185
|
-
}
|
|
14234
|
+
const startIndex = i;
|
|
14235
|
+
while(i < xmlData.length && ")" !== xmlData[i])i++;
|
|
14236
|
+
contentModel = xmlData.substring(startIndex, i);
|
|
14186
14237
|
if (")" !== xmlData[i]) throw new Error("Unterminated content model");
|
|
14187
14238
|
} else if (!this.suppressValidationErr) throw new Error(`Invalid Element Expression, found "${xmlData[i]}"`);
|
|
14188
14239
|
return {
|
|
@@ -14193,18 +14244,14 @@
|
|
|
14193
14244
|
}
|
|
14194
14245
|
readAttlistExp(xmlData, i) {
|
|
14195
14246
|
i = skipWhitespace(xmlData, i);
|
|
14196
|
-
let
|
|
14197
|
-
while(i < xmlData.length && !/\s/.test(xmlData[i]))
|
|
14198
|
-
|
|
14199
|
-
i++;
|
|
14200
|
-
}
|
|
14247
|
+
let startIndex = i;
|
|
14248
|
+
while(i < xmlData.length && !/\s/.test(xmlData[i]))i++;
|
|
14249
|
+
let elementName = xmlData.substring(startIndex, i);
|
|
14201
14250
|
validateEntityName(elementName);
|
|
14202
14251
|
i = skipWhitespace(xmlData, i);
|
|
14203
|
-
|
|
14204
|
-
while(i < xmlData.length && !/\s/.test(xmlData[i]))
|
|
14205
|
-
|
|
14206
|
-
i++;
|
|
14207
|
-
}
|
|
14252
|
+
startIndex = i;
|
|
14253
|
+
while(i < xmlData.length && !/\s/.test(xmlData[i]))i++;
|
|
14254
|
+
let attributeName = xmlData.substring(startIndex, i);
|
|
14208
14255
|
if (!validateEntityName(attributeName)) throw new Error(`Invalid attribute name: "${attributeName}"`);
|
|
14209
14256
|
i = skipWhitespace(xmlData, i);
|
|
14210
14257
|
let attributeType = "";
|
|
@@ -14216,11 +14263,9 @@
|
|
|
14216
14263
|
i++;
|
|
14217
14264
|
let allowedNotations = [];
|
|
14218
14265
|
while(i < xmlData.length && ")" !== xmlData[i]){
|
|
14219
|
-
|
|
14220
|
-
while(i < xmlData.length && "|" !== xmlData[i] && ")" !== xmlData[i])
|
|
14221
|
-
|
|
14222
|
-
i++;
|
|
14223
|
-
}
|
|
14266
|
+
const startIndex = i;
|
|
14267
|
+
while(i < xmlData.length && "|" !== xmlData[i] && ")" !== xmlData[i])i++;
|
|
14268
|
+
let notation = xmlData.substring(startIndex, i);
|
|
14224
14269
|
notation = notation.trim();
|
|
14225
14270
|
if (!validateEntityName(notation)) throw new Error(`Invalid notation name: "${notation}"`);
|
|
14226
14271
|
allowedNotations.push(notation);
|
|
@@ -14233,10 +14278,9 @@
|
|
|
14233
14278
|
i++;
|
|
14234
14279
|
attributeType += " (" + allowedNotations.join("|") + ")";
|
|
14235
14280
|
} else {
|
|
14236
|
-
|
|
14237
|
-
|
|
14238
|
-
|
|
14239
|
-
}
|
|
14281
|
+
const startIndex = i;
|
|
14282
|
+
while(i < xmlData.length && !/\s/.test(xmlData[i]))i++;
|
|
14283
|
+
attributeType += xmlData.substring(startIndex, i);
|
|
14240
14284
|
const validTypes = [
|
|
14241
14285
|
"CDATA",
|
|
14242
14286
|
"ID",
|
|
@@ -14285,7 +14329,8 @@
|
|
|
14285
14329
|
hex: true,
|
|
14286
14330
|
leadingZeros: true,
|
|
14287
14331
|
decimalPoint: "\.",
|
|
14288
|
-
eNotation: true
|
|
14332
|
+
eNotation: true,
|
|
14333
|
+
infinity: "original"
|
|
14289
14334
|
};
|
|
14290
14335
|
function toNumber(str, options = {}) {
|
|
14291
14336
|
options = Object.assign({}, consider, options);
|
|
@@ -14295,6 +14340,7 @@
|
|
|
14295
14340
|
{
|
|
14296
14341
|
if ("0" === str) return 0;
|
|
14297
14342
|
if (options.hex && hexRegex.test(trimmedStr)) return parse_int(trimmedStr, 16);
|
|
14343
|
+
if (!isFinite(trimmedStr)) return handleInfinity(str, Number(trimmedStr), options);
|
|
14298
14344
|
if (trimmedStr.includes('e') || trimmedStr.includes('E')) return resolveEnotation(str, trimmedStr, options);
|
|
14299
14345
|
const match = numRegex.exec(trimmedStr);
|
|
14300
14346
|
if (!match) return str;
|
|
@@ -14333,6 +14379,7 @@
|
|
|
14333
14379
|
const eAdjacentToLeadingZeros = sign ? str[leadingZeros.length + 1] === eChar : str[leadingZeros.length] === eChar;
|
|
14334
14380
|
if (leadingZeros.length > 1 && eAdjacentToLeadingZeros) return str;
|
|
14335
14381
|
if (1 === leadingZeros.length && (notation[3].startsWith(`.${eChar}`) || notation[3][0] === eChar)) return Number(trimmedStr);
|
|
14382
|
+
if (!(leadingZeros.length > 0)) return Number(trimmedStr);
|
|
14336
14383
|
if (!options.leadingZeros || !!eAdjacentToLeadingZeros) return str;
|
|
14337
14384
|
trimmedStr = (notation[1] || "") + notation[3];
|
|
14338
14385
|
return Number(trimmedStr);
|
|
@@ -14353,6 +14400,20 @@
|
|
|
14353
14400
|
if (window && window.parseInt) return window.parseInt(numStr, base);
|
|
14354
14401
|
throw new Error("parseInt, Number.parseInt, window.parseInt are not supported");
|
|
14355
14402
|
}
|
|
14403
|
+
function handleInfinity(str, num, options) {
|
|
14404
|
+
const isPositive = num === 1 / 0;
|
|
14405
|
+
switch(options.infinity.toLowerCase()){
|
|
14406
|
+
case "null":
|
|
14407
|
+
return null;
|
|
14408
|
+
case "infinity":
|
|
14409
|
+
return num;
|
|
14410
|
+
case "string":
|
|
14411
|
+
return isPositive ? "Infinity" : "-Infinity";
|
|
14412
|
+
case "original":
|
|
14413
|
+
default:
|
|
14414
|
+
return str;
|
|
14415
|
+
}
|
|
14416
|
+
}
|
|
14356
14417
|
function getIgnoreAttributesFn(ignoreAttributes) {
|
|
14357
14418
|
if ('function' == typeof ignoreAttributes) return ignoreAttributes;
|
|
14358
14419
|
if (Array.isArray(ignoreAttributes)) return (attrName)=>{
|
|
@@ -14363,6 +14424,329 @@
|
|
|
14363
14424
|
};
|
|
14364
14425
|
return ()=>false;
|
|
14365
14426
|
}
|
|
14427
|
+
const MUTATING_METHODS = new Set([
|
|
14428
|
+
'push',
|
|
14429
|
+
'pop',
|
|
14430
|
+
'reset',
|
|
14431
|
+
'updateCurrent',
|
|
14432
|
+
'restore'
|
|
14433
|
+
]);
|
|
14434
|
+
class Matcher {
|
|
14435
|
+
constructor(options = {}){
|
|
14436
|
+
this.separator = options.separator || '.';
|
|
14437
|
+
this.path = [];
|
|
14438
|
+
this.siblingStacks = [];
|
|
14439
|
+
}
|
|
14440
|
+
push(tagName, attrValues = null, namespace = null) {
|
|
14441
|
+
if (this.path.length > 0) {
|
|
14442
|
+
const prev = this.path[this.path.length - 1];
|
|
14443
|
+
prev.values = void 0;
|
|
14444
|
+
}
|
|
14445
|
+
const currentLevel = this.path.length;
|
|
14446
|
+
if (!this.siblingStacks[currentLevel]) this.siblingStacks[currentLevel] = new Map();
|
|
14447
|
+
const siblings = this.siblingStacks[currentLevel];
|
|
14448
|
+
const siblingKey = namespace ? `${namespace}:${tagName}` : tagName;
|
|
14449
|
+
const counter = siblings.get(siblingKey) || 0;
|
|
14450
|
+
let position = 0;
|
|
14451
|
+
for (const count of siblings.values())position += count;
|
|
14452
|
+
siblings.set(siblingKey, counter + 1);
|
|
14453
|
+
const node = {
|
|
14454
|
+
tag: tagName,
|
|
14455
|
+
position: position,
|
|
14456
|
+
counter: counter
|
|
14457
|
+
};
|
|
14458
|
+
if (null != namespace) node.namespace = namespace;
|
|
14459
|
+
if (null != attrValues) node.values = attrValues;
|
|
14460
|
+
this.path.push(node);
|
|
14461
|
+
}
|
|
14462
|
+
pop() {
|
|
14463
|
+
if (0 === this.path.length) return;
|
|
14464
|
+
const node = this.path.pop();
|
|
14465
|
+
if (this.siblingStacks.length > this.path.length + 1) this.siblingStacks.length = this.path.length + 1;
|
|
14466
|
+
return node;
|
|
14467
|
+
}
|
|
14468
|
+
updateCurrent(attrValues) {
|
|
14469
|
+
if (this.path.length > 0) {
|
|
14470
|
+
const current = this.path[this.path.length - 1];
|
|
14471
|
+
if (null != attrValues) current.values = attrValues;
|
|
14472
|
+
}
|
|
14473
|
+
}
|
|
14474
|
+
getCurrentTag() {
|
|
14475
|
+
return this.path.length > 0 ? this.path[this.path.length - 1].tag : void 0;
|
|
14476
|
+
}
|
|
14477
|
+
getCurrentNamespace() {
|
|
14478
|
+
return this.path.length > 0 ? this.path[this.path.length - 1].namespace : void 0;
|
|
14479
|
+
}
|
|
14480
|
+
getAttrValue(attrName) {
|
|
14481
|
+
if (0 === this.path.length) return;
|
|
14482
|
+
const current = this.path[this.path.length - 1];
|
|
14483
|
+
return current.values?.[attrName];
|
|
14484
|
+
}
|
|
14485
|
+
hasAttr(attrName) {
|
|
14486
|
+
if (0 === this.path.length) return false;
|
|
14487
|
+
const current = this.path[this.path.length - 1];
|
|
14488
|
+
return void 0 !== current.values && attrName in current.values;
|
|
14489
|
+
}
|
|
14490
|
+
getPosition() {
|
|
14491
|
+
if (0 === this.path.length) return -1;
|
|
14492
|
+
return this.path[this.path.length - 1].position ?? 0;
|
|
14493
|
+
}
|
|
14494
|
+
getCounter() {
|
|
14495
|
+
if (0 === this.path.length) return -1;
|
|
14496
|
+
return this.path[this.path.length - 1].counter ?? 0;
|
|
14497
|
+
}
|
|
14498
|
+
getIndex() {
|
|
14499
|
+
return this.getPosition();
|
|
14500
|
+
}
|
|
14501
|
+
getDepth() {
|
|
14502
|
+
return this.path.length;
|
|
14503
|
+
}
|
|
14504
|
+
toString(separator, includeNamespace = true) {
|
|
14505
|
+
const sep = separator || this.separator;
|
|
14506
|
+
return this.path.map((n)=>{
|
|
14507
|
+
if (includeNamespace && n.namespace) return `${n.namespace}:${n.tag}`;
|
|
14508
|
+
return n.tag;
|
|
14509
|
+
}).join(sep);
|
|
14510
|
+
}
|
|
14511
|
+
toArray() {
|
|
14512
|
+
return this.path.map((n)=>n.tag);
|
|
14513
|
+
}
|
|
14514
|
+
reset() {
|
|
14515
|
+
this.path = [];
|
|
14516
|
+
this.siblingStacks = [];
|
|
14517
|
+
}
|
|
14518
|
+
matches(expression) {
|
|
14519
|
+
const segments = expression.segments;
|
|
14520
|
+
if (0 === segments.length) return false;
|
|
14521
|
+
if (expression.hasDeepWildcard()) return this._matchWithDeepWildcard(segments);
|
|
14522
|
+
return this._matchSimple(segments);
|
|
14523
|
+
}
|
|
14524
|
+
_matchSimple(segments) {
|
|
14525
|
+
if (this.path.length !== segments.length) return false;
|
|
14526
|
+
for(let i = 0; i < segments.length; i++){
|
|
14527
|
+
const segment = segments[i];
|
|
14528
|
+
const node = this.path[i];
|
|
14529
|
+
const isCurrentNode = i === this.path.length - 1;
|
|
14530
|
+
if (!this._matchSegment(segment, node, isCurrentNode)) return false;
|
|
14531
|
+
}
|
|
14532
|
+
return true;
|
|
14533
|
+
}
|
|
14534
|
+
_matchWithDeepWildcard(segments) {
|
|
14535
|
+
let pathIdx = this.path.length - 1;
|
|
14536
|
+
let segIdx = segments.length - 1;
|
|
14537
|
+
while(segIdx >= 0 && pathIdx >= 0){
|
|
14538
|
+
const segment = segments[segIdx];
|
|
14539
|
+
if ('deep-wildcard' === segment.type) {
|
|
14540
|
+
segIdx--;
|
|
14541
|
+
if (segIdx < 0) return true;
|
|
14542
|
+
const nextSeg = segments[segIdx];
|
|
14543
|
+
let found = false;
|
|
14544
|
+
for(let i = pathIdx; i >= 0; i--){
|
|
14545
|
+
const isCurrentNode = i === this.path.length - 1;
|
|
14546
|
+
if (this._matchSegment(nextSeg, this.path[i], isCurrentNode)) {
|
|
14547
|
+
pathIdx = i - 1;
|
|
14548
|
+
segIdx--;
|
|
14549
|
+
found = true;
|
|
14550
|
+
break;
|
|
14551
|
+
}
|
|
14552
|
+
}
|
|
14553
|
+
if (!found) return false;
|
|
14554
|
+
} else {
|
|
14555
|
+
const isCurrentNode = pathIdx === this.path.length - 1;
|
|
14556
|
+
if (!this._matchSegment(segment, this.path[pathIdx], isCurrentNode)) return false;
|
|
14557
|
+
pathIdx--;
|
|
14558
|
+
segIdx--;
|
|
14559
|
+
}
|
|
14560
|
+
}
|
|
14561
|
+
return segIdx < 0;
|
|
14562
|
+
}
|
|
14563
|
+
_matchSegment(segment, node, isCurrentNode) {
|
|
14564
|
+
if ('*' !== segment.tag && segment.tag !== node.tag) return false;
|
|
14565
|
+
if (void 0 !== segment.namespace) {
|
|
14566
|
+
if ('*' !== segment.namespace && segment.namespace !== node.namespace) return false;
|
|
14567
|
+
}
|
|
14568
|
+
if (void 0 !== segment.attrName) {
|
|
14569
|
+
if (!isCurrentNode) return false;
|
|
14570
|
+
if (!node.values || !(segment.attrName in node.values)) return false;
|
|
14571
|
+
if (void 0 !== segment.attrValue) {
|
|
14572
|
+
const actualValue = node.values[segment.attrName];
|
|
14573
|
+
if (String(actualValue) !== String(segment.attrValue)) return false;
|
|
14574
|
+
}
|
|
14575
|
+
}
|
|
14576
|
+
if (void 0 !== segment.position) {
|
|
14577
|
+
if (!isCurrentNode) return false;
|
|
14578
|
+
const counter = node.counter ?? 0;
|
|
14579
|
+
if ('first' === segment.position && 0 !== counter) return false;
|
|
14580
|
+
if ('odd' === segment.position && counter % 2 !== 1) return false;
|
|
14581
|
+
if ('even' === segment.position && counter % 2 !== 0) return false;
|
|
14582
|
+
else if ('nth' === segment.position) {
|
|
14583
|
+
if (counter !== segment.positionValue) return false;
|
|
14584
|
+
}
|
|
14585
|
+
}
|
|
14586
|
+
return true;
|
|
14587
|
+
}
|
|
14588
|
+
snapshot() {
|
|
14589
|
+
return {
|
|
14590
|
+
path: this.path.map((node)=>({
|
|
14591
|
+
...node
|
|
14592
|
+
})),
|
|
14593
|
+
siblingStacks: this.siblingStacks.map((map)=>new Map(map))
|
|
14594
|
+
};
|
|
14595
|
+
}
|
|
14596
|
+
restore(snapshot) {
|
|
14597
|
+
this.path = snapshot.path.map((node)=>({
|
|
14598
|
+
...node
|
|
14599
|
+
}));
|
|
14600
|
+
this.siblingStacks = snapshot.siblingStacks.map((map)=>new Map(map));
|
|
14601
|
+
}
|
|
14602
|
+
readOnly() {
|
|
14603
|
+
const self1 = this;
|
|
14604
|
+
return new Proxy(self1, {
|
|
14605
|
+
get (target, prop, receiver) {
|
|
14606
|
+
if (MUTATING_METHODS.has(prop)) return ()=>{
|
|
14607
|
+
throw new TypeError(`Cannot call '${prop}' on a read-only Matcher. Obtain a writable instance to mutate state.`);
|
|
14608
|
+
};
|
|
14609
|
+
const value = Reflect.get(target, prop, receiver);
|
|
14610
|
+
if ('path' === prop || 'siblingStacks' === prop) return Object.freeze(Array.isArray(value) ? value.map((item)=>item instanceof Map ? Object.freeze(new Map(item)) : Object.freeze({
|
|
14611
|
+
...item
|
|
14612
|
+
})) : value);
|
|
14613
|
+
if ('function' == typeof value) return value.bind(target);
|
|
14614
|
+
return value;
|
|
14615
|
+
},
|
|
14616
|
+
set (_target, prop) {
|
|
14617
|
+
throw new TypeError(`Cannot set property '${String(prop)}' on a read-only Matcher.`);
|
|
14618
|
+
},
|
|
14619
|
+
deleteProperty (_target, prop) {
|
|
14620
|
+
throw new TypeError(`Cannot delete property '${String(prop)}' from a read-only Matcher.`);
|
|
14621
|
+
}
|
|
14622
|
+
});
|
|
14623
|
+
}
|
|
14624
|
+
}
|
|
14625
|
+
class Expression {
|
|
14626
|
+
constructor(pattern, options = {}){
|
|
14627
|
+
this.pattern = pattern;
|
|
14628
|
+
this.separator = options.separator || '.';
|
|
14629
|
+
this.segments = this._parse(pattern);
|
|
14630
|
+
this._hasDeepWildcard = this.segments.some((seg)=>'deep-wildcard' === seg.type);
|
|
14631
|
+
this._hasAttributeCondition = this.segments.some((seg)=>void 0 !== seg.attrName);
|
|
14632
|
+
this._hasPositionSelector = this.segments.some((seg)=>void 0 !== seg.position);
|
|
14633
|
+
}
|
|
14634
|
+
_parse(pattern) {
|
|
14635
|
+
const segments = [];
|
|
14636
|
+
let i = 0;
|
|
14637
|
+
let currentPart = '';
|
|
14638
|
+
while(i < pattern.length)if (pattern[i] === this.separator) if (i + 1 < pattern.length && pattern[i + 1] === this.separator) {
|
|
14639
|
+
if (currentPart.trim()) {
|
|
14640
|
+
segments.push(this._parseSegment(currentPart.trim()));
|
|
14641
|
+
currentPart = '';
|
|
14642
|
+
}
|
|
14643
|
+
segments.push({
|
|
14644
|
+
type: 'deep-wildcard'
|
|
14645
|
+
});
|
|
14646
|
+
i += 2;
|
|
14647
|
+
} else {
|
|
14648
|
+
if (currentPart.trim()) segments.push(this._parseSegment(currentPart.trim()));
|
|
14649
|
+
currentPart = '';
|
|
14650
|
+
i++;
|
|
14651
|
+
}
|
|
14652
|
+
else {
|
|
14653
|
+
currentPart += pattern[i];
|
|
14654
|
+
i++;
|
|
14655
|
+
}
|
|
14656
|
+
if (currentPart.trim()) segments.push(this._parseSegment(currentPart.trim()));
|
|
14657
|
+
return segments;
|
|
14658
|
+
}
|
|
14659
|
+
_parseSegment(part) {
|
|
14660
|
+
const segment = {
|
|
14661
|
+
type: 'tag'
|
|
14662
|
+
};
|
|
14663
|
+
let bracketContent = null;
|
|
14664
|
+
let withoutBrackets = part;
|
|
14665
|
+
const bracketMatch = part.match(/^([^\[]+)(\[[^\]]*\])(.*)$/);
|
|
14666
|
+
if (bracketMatch) {
|
|
14667
|
+
withoutBrackets = bracketMatch[1] + bracketMatch[3];
|
|
14668
|
+
if (bracketMatch[2]) {
|
|
14669
|
+
const content = bracketMatch[2].slice(1, -1);
|
|
14670
|
+
if (content) bracketContent = content;
|
|
14671
|
+
}
|
|
14672
|
+
}
|
|
14673
|
+
let namespace;
|
|
14674
|
+
let tagAndPosition = withoutBrackets;
|
|
14675
|
+
if (withoutBrackets.includes('::')) {
|
|
14676
|
+
const nsIndex = withoutBrackets.indexOf('::');
|
|
14677
|
+
namespace = withoutBrackets.substring(0, nsIndex).trim();
|
|
14678
|
+
tagAndPosition = withoutBrackets.substring(nsIndex + 2).trim();
|
|
14679
|
+
if (!namespace) throw new Error(`Invalid namespace in pattern: ${part}`);
|
|
14680
|
+
}
|
|
14681
|
+
let tag;
|
|
14682
|
+
let positionMatch = null;
|
|
14683
|
+
if (tagAndPosition.includes(':')) {
|
|
14684
|
+
const colonIndex = tagAndPosition.lastIndexOf(':');
|
|
14685
|
+
const tagPart = tagAndPosition.substring(0, colonIndex).trim();
|
|
14686
|
+
const posPart = tagAndPosition.substring(colonIndex + 1).trim();
|
|
14687
|
+
const isPositionKeyword = [
|
|
14688
|
+
'first',
|
|
14689
|
+
'last',
|
|
14690
|
+
'odd',
|
|
14691
|
+
'even'
|
|
14692
|
+
].includes(posPart) || /^nth\(\d+\)$/.test(posPart);
|
|
14693
|
+
if (isPositionKeyword) {
|
|
14694
|
+
tag = tagPart;
|
|
14695
|
+
positionMatch = posPart;
|
|
14696
|
+
} else tag = tagAndPosition;
|
|
14697
|
+
} else tag = tagAndPosition;
|
|
14698
|
+
if (!tag) throw new Error(`Invalid segment pattern: ${part}`);
|
|
14699
|
+
segment.tag = tag;
|
|
14700
|
+
if (namespace) segment.namespace = namespace;
|
|
14701
|
+
if (bracketContent) if (bracketContent.includes('=')) {
|
|
14702
|
+
const eqIndex = bracketContent.indexOf('=');
|
|
14703
|
+
segment.attrName = bracketContent.substring(0, eqIndex).trim();
|
|
14704
|
+
segment.attrValue = bracketContent.substring(eqIndex + 1).trim();
|
|
14705
|
+
} else segment.attrName = bracketContent.trim();
|
|
14706
|
+
if (positionMatch) {
|
|
14707
|
+
const nthMatch = positionMatch.match(/^nth\((\d+)\)$/);
|
|
14708
|
+
if (nthMatch) {
|
|
14709
|
+
segment.position = 'nth';
|
|
14710
|
+
segment.positionValue = parseInt(nthMatch[1], 10);
|
|
14711
|
+
} else segment.position = positionMatch;
|
|
14712
|
+
}
|
|
14713
|
+
return segment;
|
|
14714
|
+
}
|
|
14715
|
+
get length() {
|
|
14716
|
+
return this.segments.length;
|
|
14717
|
+
}
|
|
14718
|
+
hasDeepWildcard() {
|
|
14719
|
+
return this._hasDeepWildcard;
|
|
14720
|
+
}
|
|
14721
|
+
hasAttributeCondition() {
|
|
14722
|
+
return this._hasAttributeCondition;
|
|
14723
|
+
}
|
|
14724
|
+
hasPositionSelector() {
|
|
14725
|
+
return this._hasPositionSelector;
|
|
14726
|
+
}
|
|
14727
|
+
toString() {
|
|
14728
|
+
return this.pattern;
|
|
14729
|
+
}
|
|
14730
|
+
}
|
|
14731
|
+
function extractRawAttributes(prefixedAttrs, options) {
|
|
14732
|
+
if (!prefixedAttrs) return {};
|
|
14733
|
+
const attrs = options.attributesGroupName ? prefixedAttrs[options.attributesGroupName] : prefixedAttrs;
|
|
14734
|
+
if (!attrs) return {};
|
|
14735
|
+
const rawAttrs = {};
|
|
14736
|
+
for(const key in attrs)if (key.startsWith(options.attributeNamePrefix)) {
|
|
14737
|
+
const rawName = key.substring(options.attributeNamePrefix.length);
|
|
14738
|
+
rawAttrs[rawName] = attrs[key];
|
|
14739
|
+
} else rawAttrs[key] = attrs[key];
|
|
14740
|
+
return rawAttrs;
|
|
14741
|
+
}
|
|
14742
|
+
function extractNamespace(rawTagName) {
|
|
14743
|
+
if (!rawTagName || 'string' != typeof rawTagName) return;
|
|
14744
|
+
const colonIndex = rawTagName.indexOf(':');
|
|
14745
|
+
if (-1 !== colonIndex && colonIndex > 0) {
|
|
14746
|
+
const ns = rawTagName.substring(0, colonIndex);
|
|
14747
|
+
if ('xmlns' !== ns) return ns;
|
|
14748
|
+
}
|
|
14749
|
+
}
|
|
14366
14750
|
class OrderedObjParser {
|
|
14367
14751
|
constructor(options){
|
|
14368
14752
|
this.options = options;
|
|
@@ -14446,13 +14830,15 @@
|
|
|
14446
14830
|
this.ignoreAttributesFn = getIgnoreAttributesFn(this.options.ignoreAttributes);
|
|
14447
14831
|
this.entityExpansionCount = 0;
|
|
14448
14832
|
this.currentExpandedLength = 0;
|
|
14833
|
+
this.matcher = new Matcher();
|
|
14834
|
+
this.readonlyMatcher = this.matcher.readOnly();
|
|
14835
|
+
this.isCurrentNodeStopNode = false;
|
|
14449
14836
|
if (this.options.stopNodes && this.options.stopNodes.length > 0) {
|
|
14450
|
-
this.
|
|
14451
|
-
this.stopNodesWildcard = new Set();
|
|
14837
|
+
this.stopNodeExpressions = [];
|
|
14452
14838
|
for(let i = 0; i < this.options.stopNodes.length; i++){
|
|
14453
14839
|
const stopNodeExp = this.options.stopNodes[i];
|
|
14454
|
-
if ('string' == typeof stopNodeExp)
|
|
14455
|
-
else this.
|
|
14840
|
+
if ('string' == typeof stopNodeExp) this.stopNodeExpressions.push(new Expression(stopNodeExp));
|
|
14841
|
+
else if (stopNodeExp instanceof Expression) this.stopNodeExpressions.push(stopNodeExp);
|
|
14456
14842
|
}
|
|
14457
14843
|
}
|
|
14458
14844
|
}
|
|
@@ -14473,7 +14859,8 @@
|
|
|
14473
14859
|
if (this.options.trimValues && !dontTrim) val = val.trim();
|
|
14474
14860
|
if (val.length > 0) {
|
|
14475
14861
|
if (!escapeEntities) val = this.replaceEntitiesValue(val, tagName, jPath);
|
|
14476
|
-
const
|
|
14862
|
+
const jPathOrMatcher = this.options.jPath ? jPath.toString() : jPath;
|
|
14863
|
+
const newval = this.options.tagValueProcessor(tagName, val, jPathOrMatcher, hasAttributes, isLeafNode);
|
|
14477
14864
|
if (null == newval) return val;
|
|
14478
14865
|
{
|
|
14479
14866
|
if (typeof newval !== typeof val || newval !== val) return newval;
|
|
@@ -14500,18 +14887,32 @@
|
|
|
14500
14887
|
const matches = getAllMatches(attrStr, attrsRegx);
|
|
14501
14888
|
const len = matches.length;
|
|
14502
14889
|
const attrs = {};
|
|
14890
|
+
const rawAttrsForMatcher = {};
|
|
14891
|
+
for(let i = 0; i < len; i++){
|
|
14892
|
+
const attrName = this.resolveNameSpace(matches[i][1]);
|
|
14893
|
+
const oldVal = matches[i][4];
|
|
14894
|
+
if (attrName.length && void 0 !== oldVal) {
|
|
14895
|
+
let parsedVal = oldVal;
|
|
14896
|
+
if (this.options.trimValues) parsedVal = parsedVal.trim();
|
|
14897
|
+
parsedVal = this.replaceEntitiesValue(parsedVal, tagName, this.readonlyMatcher);
|
|
14898
|
+
rawAttrsForMatcher[attrName] = parsedVal;
|
|
14899
|
+
}
|
|
14900
|
+
}
|
|
14901
|
+
if (Object.keys(rawAttrsForMatcher).length > 0 && 'object' == typeof jPath && jPath.updateCurrent) jPath.updateCurrent(rawAttrsForMatcher);
|
|
14503
14902
|
for(let i = 0; i < len; i++){
|
|
14504
14903
|
const attrName = this.resolveNameSpace(matches[i][1]);
|
|
14505
|
-
|
|
14904
|
+
const jPathStr = this.options.jPath ? jPath.toString() : this.readonlyMatcher;
|
|
14905
|
+
if (this.ignoreAttributesFn(attrName, jPathStr)) continue;
|
|
14506
14906
|
let oldVal = matches[i][4];
|
|
14507
14907
|
let aName = this.options.attributeNamePrefix + attrName;
|
|
14508
14908
|
if (attrName.length) {
|
|
14509
14909
|
if (this.options.transformAttributeName) aName = this.options.transformAttributeName(aName);
|
|
14510
|
-
|
|
14910
|
+
aName = sanitizeName(aName, this.options);
|
|
14511
14911
|
if (void 0 !== oldVal) {
|
|
14512
14912
|
if (this.options.trimValues) oldVal = oldVal.trim();
|
|
14513
|
-
oldVal = this.replaceEntitiesValue(oldVal, tagName,
|
|
14514
|
-
const
|
|
14913
|
+
oldVal = this.replaceEntitiesValue(oldVal, tagName, this.readonlyMatcher);
|
|
14914
|
+
const jPathOrMatcher = this.options.jPath ? jPath.toString() : this.readonlyMatcher;
|
|
14915
|
+
const newVal = this.options.attributeValueProcessor(attrName, oldVal, jPathOrMatcher);
|
|
14515
14916
|
if (null == newVal) attrs[aName] = oldVal;
|
|
14516
14917
|
else if (typeof newVal !== typeof oldVal || newVal !== oldVal) attrs[aName] = newVal;
|
|
14517
14918
|
else attrs[aName] = parseValue(oldVal, this.options.parseAttributeValue, this.options.numberParseOptions);
|
|
@@ -14532,7 +14933,7 @@
|
|
|
14532
14933
|
const xmlObj = new XmlNode('!xml');
|
|
14533
14934
|
let currentNode = xmlObj;
|
|
14534
14935
|
let textData = "";
|
|
14535
|
-
|
|
14936
|
+
this.matcher.reset();
|
|
14536
14937
|
this.entityExpansionCount = 0;
|
|
14537
14938
|
this.currentExpandedLength = 0;
|
|
14538
14939
|
const docTypeReader = new DocTypeReader(this.options.processEntities);
|
|
@@ -14545,36 +14946,36 @@
|
|
|
14545
14946
|
const colonIndex = tagName.indexOf(":");
|
|
14546
14947
|
if (-1 !== colonIndex) tagName = tagName.substr(colonIndex + 1);
|
|
14547
14948
|
}
|
|
14548
|
-
|
|
14549
|
-
if (currentNode) textData = this.saveTextToParentTag(textData, currentNode,
|
|
14550
|
-
const lastTagName =
|
|
14949
|
+
tagName = transformTagName(this.options.transformTagName, tagName, "", this.options).tagName;
|
|
14950
|
+
if (currentNode) textData = this.saveTextToParentTag(textData, currentNode, this.readonlyMatcher);
|
|
14951
|
+
const lastTagName = this.matcher.getCurrentTag();
|
|
14551
14952
|
if (tagName && -1 !== this.options.unpairedTags.indexOf(tagName)) throw new Error(`Unpaired tag can not be used as closing tag: </${tagName}>`);
|
|
14552
|
-
let propIndex = 0;
|
|
14553
14953
|
if (lastTagName && -1 !== this.options.unpairedTags.indexOf(lastTagName)) {
|
|
14554
|
-
|
|
14954
|
+
this.matcher.pop();
|
|
14555
14955
|
this.tagsNodeStack.pop();
|
|
14556
|
-
}
|
|
14557
|
-
|
|
14956
|
+
}
|
|
14957
|
+
this.matcher.pop();
|
|
14958
|
+
this.isCurrentNodeStopNode = false;
|
|
14558
14959
|
currentNode = this.tagsNodeStack.pop();
|
|
14559
14960
|
textData = "";
|
|
14560
14961
|
i = closeIndex;
|
|
14561
14962
|
} else if ('?' === xmlData[i + 1]) {
|
|
14562
14963
|
let tagData = readTagExp(xmlData, i, false, "?>");
|
|
14563
14964
|
if (!tagData) throw new Error("Pi Tag is not closed.");
|
|
14564
|
-
textData = this.saveTextToParentTag(textData, currentNode,
|
|
14965
|
+
textData = this.saveTextToParentTag(textData, currentNode, this.readonlyMatcher);
|
|
14565
14966
|
if (this.options.ignoreDeclaration && "?xml" === tagData.tagName || this.options.ignorePiTags) ;
|
|
14566
14967
|
else {
|
|
14567
14968
|
const childNode = new XmlNode(tagData.tagName);
|
|
14568
14969
|
childNode.add(this.options.textNodeName, "");
|
|
14569
|
-
if (tagData.tagName !== tagData.tagExp && tagData.attrExpPresent) childNode[":@"] = this.buildAttributesMap(tagData.tagExp,
|
|
14570
|
-
this.addChild(currentNode, childNode,
|
|
14970
|
+
if (tagData.tagName !== tagData.tagExp && tagData.attrExpPresent) childNode[":@"] = this.buildAttributesMap(tagData.tagExp, this.matcher, tagData.tagName);
|
|
14971
|
+
this.addChild(currentNode, childNode, this.readonlyMatcher, i);
|
|
14571
14972
|
}
|
|
14572
14973
|
i = tagData.closeIndex + 1;
|
|
14573
14974
|
} else if ('!--' === xmlData.substr(i + 1, 3)) {
|
|
14574
14975
|
const endIndex = findClosingIndex(xmlData, "-->", i + 4, "Comment is not closed.");
|
|
14575
14976
|
if (this.options.commentPropName) {
|
|
14576
14977
|
const comment = xmlData.substring(i + 4, endIndex - 2);
|
|
14577
|
-
textData = this.saveTextToParentTag(textData, currentNode,
|
|
14978
|
+
textData = this.saveTextToParentTag(textData, currentNode, this.readonlyMatcher);
|
|
14578
14979
|
currentNode.add(this.options.commentPropName, [
|
|
14579
14980
|
{
|
|
14580
14981
|
[this.options.textNodeName]: comment
|
|
@@ -14589,8 +14990,8 @@
|
|
|
14589
14990
|
} else if ('![' === xmlData.substr(i + 1, 2)) {
|
|
14590
14991
|
const closeIndex = findClosingIndex(xmlData, "]]>", i, "CDATA is not closed.") - 2;
|
|
14591
14992
|
const tagExp = xmlData.substring(i + 9, closeIndex);
|
|
14592
|
-
textData = this.saveTextToParentTag(textData, currentNode,
|
|
14593
|
-
let val = this.parseTextData(tagExp, currentNode.tagname,
|
|
14993
|
+
textData = this.saveTextToParentTag(textData, currentNode, this.readonlyMatcher);
|
|
14994
|
+
let val = this.parseTextData(tagExp, currentNode.tagname, this.readonlyMatcher, true, false, true, true);
|
|
14594
14995
|
if (void 0 == val) val = "";
|
|
14595
14996
|
if (this.options.cdataPropName) currentNode.add(this.options.cdataPropName, [
|
|
14596
14997
|
{
|
|
@@ -14601,36 +15002,48 @@
|
|
|
14601
15002
|
i = closeIndex + 2;
|
|
14602
15003
|
} else {
|
|
14603
15004
|
let result = readTagExp(xmlData, i, this.options.removeNSPrefix);
|
|
15005
|
+
if (!result) {
|
|
15006
|
+
const context = xmlData.substring(Math.max(0, i - 50), Math.min(xmlData.length, i + 50));
|
|
15007
|
+
throw new Error(`readTagExp returned undefined at position ${i}. Context: "${context}"`);
|
|
15008
|
+
}
|
|
14604
15009
|
let tagName = result.tagName;
|
|
14605
15010
|
const rawTagName = result.rawTagName;
|
|
14606
15011
|
let tagExp = result.tagExp;
|
|
14607
15012
|
let attrExpPresent = result.attrExpPresent;
|
|
14608
15013
|
let closeIndex = result.closeIndex;
|
|
14609
|
-
|
|
14610
|
-
|
|
14611
|
-
if (tagExp === tagName) tagExp = newTagName;
|
|
14612
|
-
tagName = newTagName;
|
|
14613
|
-
}
|
|
15014
|
+
({ tagName, tagExp } = transformTagName(this.options.transformTagName, tagName, tagExp, this.options));
|
|
15015
|
+
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}`);
|
|
14614
15016
|
if (currentNode && textData) {
|
|
14615
|
-
if ('!xml' !== currentNode.tagname) textData = this.saveTextToParentTag(textData, currentNode,
|
|
15017
|
+
if ('!xml' !== currentNode.tagname) textData = this.saveTextToParentTag(textData, currentNode, this.readonlyMatcher, false);
|
|
14616
15018
|
}
|
|
14617
15019
|
const lastTag = currentNode;
|
|
14618
15020
|
if (lastTag && -1 !== this.options.unpairedTags.indexOf(lastTag.tagname)) {
|
|
14619
15021
|
currentNode = this.tagsNodeStack.pop();
|
|
14620
|
-
|
|
14621
|
-
}
|
|
14622
|
-
|
|
15022
|
+
this.matcher.pop();
|
|
15023
|
+
}
|
|
15024
|
+
let isSelfClosing = false;
|
|
15025
|
+
if (tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1) {
|
|
15026
|
+
isSelfClosing = true;
|
|
15027
|
+
if ("/" === tagName[tagName.length - 1]) {
|
|
15028
|
+
tagName = tagName.substr(0, tagName.length - 1);
|
|
15029
|
+
tagExp = tagName;
|
|
15030
|
+
} else tagExp = tagExp.substr(0, tagExp.length - 1);
|
|
15031
|
+
attrExpPresent = tagName !== tagExp;
|
|
15032
|
+
}
|
|
15033
|
+
let prefixedAttrs = null;
|
|
15034
|
+
let namespace;
|
|
15035
|
+
namespace = extractNamespace(rawTagName);
|
|
15036
|
+
if (tagName !== xmlObj.tagname) this.matcher.push(tagName, {}, namespace);
|
|
15037
|
+
if (tagName !== tagExp && attrExpPresent) {
|
|
15038
|
+
prefixedAttrs = this.buildAttributesMap(tagExp, this.matcher, tagName);
|
|
15039
|
+
if (prefixedAttrs) extractRawAttributes(prefixedAttrs, this.options);
|
|
15040
|
+
}
|
|
15041
|
+
if (tagName !== xmlObj.tagname) this.isCurrentNodeStopNode = this.isItStopNode(this.stopNodeExpressions, this.matcher);
|
|
14623
15042
|
const startIndex = i;
|
|
14624
|
-
if (this.
|
|
15043
|
+
if (this.isCurrentNodeStopNode) {
|
|
14625
15044
|
let tagContent = "";
|
|
14626
|
-
if (
|
|
14627
|
-
|
|
14628
|
-
tagName = tagName.substr(0, tagName.length - 1);
|
|
14629
|
-
jPath = jPath.substr(0, jPath.length - 1);
|
|
14630
|
-
tagExp = tagName;
|
|
14631
|
-
} else tagExp = tagExp.substr(0, tagExp.length - 1);
|
|
14632
|
-
i = result.closeIndex;
|
|
14633
|
-
} else if (-1 !== this.options.unpairedTags.indexOf(tagName)) i = result.closeIndex;
|
|
15045
|
+
if (isSelfClosing) i = result.closeIndex;
|
|
15046
|
+
else if (-1 !== this.options.unpairedTags.indexOf(tagName)) i = result.closeIndex;
|
|
14634
15047
|
else {
|
|
14635
15048
|
const result = this.readStopNodeData(xmlData, rawTagName, closeIndex + 1);
|
|
14636
15049
|
if (!result) throw new Error(`Unexpected end of ${rawTagName}`);
|
|
@@ -14638,32 +15051,33 @@
|
|
|
14638
15051
|
tagContent = result.tagContent;
|
|
14639
15052
|
}
|
|
14640
15053
|
const childNode = new XmlNode(tagName);
|
|
14641
|
-
if (
|
|
14642
|
-
if (tagContent) tagContent = this.parseTextData(tagContent, tagName, jPath, true, attrExpPresent, true, true);
|
|
14643
|
-
jPath = jPath.substr(0, jPath.lastIndexOf("."));
|
|
15054
|
+
if (prefixedAttrs) childNode[":@"] = prefixedAttrs;
|
|
14644
15055
|
childNode.add(this.options.textNodeName, tagContent);
|
|
14645
|
-
this.
|
|
15056
|
+
this.matcher.pop();
|
|
15057
|
+
this.isCurrentNodeStopNode = false;
|
|
15058
|
+
this.addChild(currentNode, childNode, this.readonlyMatcher, startIndex);
|
|
14646
15059
|
} else {
|
|
14647
|
-
if (
|
|
14648
|
-
|
|
14649
|
-
|
|
14650
|
-
|
|
14651
|
-
|
|
14652
|
-
|
|
14653
|
-
|
|
14654
|
-
|
|
14655
|
-
if (tagExp === tagName) tagExp = newTagName;
|
|
14656
|
-
tagName = newTagName;
|
|
14657
|
-
}
|
|
15060
|
+
if (isSelfClosing) {
|
|
15061
|
+
({ tagName, tagExp } = transformTagName(this.options.transformTagName, tagName, tagExp, this.options));
|
|
15062
|
+
const childNode = new XmlNode(tagName);
|
|
15063
|
+
if (prefixedAttrs) childNode[":@"] = prefixedAttrs;
|
|
15064
|
+
this.addChild(currentNode, childNode, this.readonlyMatcher, startIndex);
|
|
15065
|
+
this.matcher.pop();
|
|
15066
|
+
this.isCurrentNodeStopNode = false;
|
|
15067
|
+
} else if (-1 !== this.options.unpairedTags.indexOf(tagName)) {
|
|
14658
15068
|
const childNode = new XmlNode(tagName);
|
|
14659
|
-
if (
|
|
14660
|
-
this.addChild(currentNode, childNode,
|
|
14661
|
-
|
|
15069
|
+
if (prefixedAttrs) childNode[":@"] = prefixedAttrs;
|
|
15070
|
+
this.addChild(currentNode, childNode, this.readonlyMatcher, startIndex);
|
|
15071
|
+
this.matcher.pop();
|
|
15072
|
+
this.isCurrentNodeStopNode = false;
|
|
15073
|
+
i = result.closeIndex;
|
|
15074
|
+
continue;
|
|
14662
15075
|
} else {
|
|
14663
15076
|
const childNode = new XmlNode(tagName);
|
|
15077
|
+
if (this.tagsNodeStack.length > this.options.maxNestedTags) throw new Error("Maximum nested tags exceeded");
|
|
14664
15078
|
this.tagsNodeStack.push(currentNode);
|
|
14665
|
-
if (
|
|
14666
|
-
this.addChild(currentNode, childNode,
|
|
15079
|
+
if (prefixedAttrs) childNode[":@"] = prefixedAttrs;
|
|
15080
|
+
this.addChild(currentNode, childNode, this.readonlyMatcher, startIndex);
|
|
14667
15081
|
currentNode = childNode;
|
|
14668
15082
|
}
|
|
14669
15083
|
textData = "";
|
|
@@ -14674,26 +15088,29 @@
|
|
|
14674
15088
|
}
|
|
14675
15089
|
return xmlObj.child;
|
|
14676
15090
|
};
|
|
14677
|
-
function addChild(currentNode, childNode,
|
|
15091
|
+
function addChild(currentNode, childNode, matcher, startIndex) {
|
|
14678
15092
|
if (!this.options.captureMetaData) startIndex = void 0;
|
|
14679
|
-
const
|
|
15093
|
+
const jPathOrMatcher = this.options.jPath ? matcher.toString() : matcher;
|
|
15094
|
+
const result = this.options.updateTag(childNode.tagname, jPathOrMatcher, childNode[":@"]);
|
|
14680
15095
|
if (false === result) ;
|
|
14681
15096
|
else if ("string" == typeof result) {
|
|
14682
15097
|
childNode.tagname = result;
|
|
14683
15098
|
currentNode.addChild(childNode, startIndex);
|
|
14684
15099
|
} else currentNode.addChild(childNode, startIndex);
|
|
14685
15100
|
}
|
|
14686
|
-
|
|
14687
|
-
if (-1 === val.indexOf('&')) return val;
|
|
15101
|
+
function replaceEntitiesValue(val, tagName, jPath) {
|
|
14688
15102
|
const entityConfig = this.options.processEntities;
|
|
14689
|
-
if (!entityConfig.enabled) return val;
|
|
15103
|
+
if (!entityConfig || !entityConfig.enabled) return val;
|
|
14690
15104
|
if (entityConfig.allowedTags) {
|
|
14691
|
-
|
|
15105
|
+
const jPathOrMatcher = this.options.jPath ? jPath.toString() : jPath;
|
|
15106
|
+
const allowed = Array.isArray(entityConfig.allowedTags) ? entityConfig.allowedTags.includes(tagName) : entityConfig.allowedTags(tagName, jPathOrMatcher);
|
|
15107
|
+
if (!allowed) return val;
|
|
14692
15108
|
}
|
|
14693
15109
|
if (entityConfig.tagFilter) {
|
|
14694
|
-
|
|
15110
|
+
const jPathOrMatcher = this.options.jPath ? jPath.toString() : jPath;
|
|
15111
|
+
if (!entityConfig.tagFilter(tagName, jPathOrMatcher)) return val;
|
|
14695
15112
|
}
|
|
14696
|
-
for(
|
|
15113
|
+
for (const entityName of Object.keys(this.docTypeEntities)){
|
|
14697
15114
|
const entity = this.docTypeEntities[entityName];
|
|
14698
15115
|
const matches = val.match(entity.regx);
|
|
14699
15116
|
if (matches) {
|
|
@@ -14707,31 +15124,40 @@
|
|
|
14707
15124
|
}
|
|
14708
15125
|
}
|
|
14709
15126
|
}
|
|
14710
|
-
|
|
14711
|
-
for(let entityName in this.lastEntities){
|
|
15127
|
+
for (const entityName of Object.keys(this.lastEntities)){
|
|
14712
15128
|
const entity = this.lastEntities[entityName];
|
|
15129
|
+
const matches = val.match(entity.regex);
|
|
15130
|
+
if (matches) {
|
|
15131
|
+
this.entityExpansionCount += matches.length;
|
|
15132
|
+
if (entityConfig.maxTotalExpansions && this.entityExpansionCount > entityConfig.maxTotalExpansions) throw new Error(`Entity expansion limit exceeded: ${this.entityExpansionCount} > ${entityConfig.maxTotalExpansions}`);
|
|
15133
|
+
}
|
|
14713
15134
|
val = val.replace(entity.regex, entity.val);
|
|
14714
15135
|
}
|
|
14715
15136
|
if (-1 === val.indexOf('&')) return val;
|
|
14716
|
-
if (this.options.htmlEntities) for(
|
|
15137
|
+
if (this.options.htmlEntities) for (const entityName of Object.keys(this.htmlEntities)){
|
|
14717
15138
|
const entity = this.htmlEntities[entityName];
|
|
15139
|
+
const matches = val.match(entity.regex);
|
|
15140
|
+
if (matches) {
|
|
15141
|
+
this.entityExpansionCount += matches.length;
|
|
15142
|
+
if (entityConfig.maxTotalExpansions && this.entityExpansionCount > entityConfig.maxTotalExpansions) throw new Error(`Entity expansion limit exceeded: ${this.entityExpansionCount} > ${entityConfig.maxTotalExpansions}`);
|
|
15143
|
+
}
|
|
14718
15144
|
val = val.replace(entity.regex, entity.val);
|
|
14719
15145
|
}
|
|
14720
15146
|
val = val.replace(this.ampEntity.regex, this.ampEntity.val);
|
|
14721
15147
|
return val;
|
|
14722
|
-
}
|
|
14723
|
-
function saveTextToParentTag(textData,
|
|
15148
|
+
}
|
|
15149
|
+
function saveTextToParentTag(textData, parentNode, matcher, isLeafNode) {
|
|
14724
15150
|
if (textData) {
|
|
14725
|
-
if (void 0 === isLeafNode) isLeafNode = 0 ===
|
|
14726
|
-
textData = this.parseTextData(textData,
|
|
14727
|
-
if (void 0 !== textData && "" !== textData)
|
|
15151
|
+
if (void 0 === isLeafNode) isLeafNode = 0 === parentNode.child.length;
|
|
15152
|
+
textData = this.parseTextData(textData, parentNode.tagname, matcher, false, parentNode[":@"] ? 0 !== Object.keys(parentNode[":@"]).length : false, isLeafNode);
|
|
15153
|
+
if (void 0 !== textData && "" !== textData) parentNode.add(this.options.textNodeName, textData);
|
|
14728
15154
|
textData = "";
|
|
14729
15155
|
}
|
|
14730
15156
|
return textData;
|
|
14731
15157
|
}
|
|
14732
|
-
function isItStopNode(
|
|
14733
|
-
if (
|
|
14734
|
-
|
|
15158
|
+
function isItStopNode(stopNodeExpressions, matcher) {
|
|
15159
|
+
if (!stopNodeExpressions || 0 === stopNodeExpressions.length) return false;
|
|
15160
|
+
for(let i = 0; i < stopNodeExpressions.length; i++)if (matcher.matches(stopNodeExpressions[i])) return true;
|
|
14735
15161
|
return false;
|
|
14736
15162
|
}
|
|
14737
15163
|
function tagExpWithClosingIndex(xmlData, i, closingChar = ">") {
|
|
@@ -14835,39 +15261,72 @@
|
|
|
14835
15261
|
if (codePoint >= 0 && codePoint <= 0x10FFFF) return String.fromCodePoint(codePoint);
|
|
14836
15262
|
return prefix + str + ";";
|
|
14837
15263
|
}
|
|
14838
|
-
|
|
14839
|
-
|
|
14840
|
-
|
|
15264
|
+
function transformTagName(fn, tagName, tagExp, options) {
|
|
15265
|
+
if (fn) {
|
|
15266
|
+
const newTagName = fn(tagName);
|
|
15267
|
+
if (tagExp === tagName) tagExp = newTagName;
|
|
15268
|
+
tagName = newTagName;
|
|
15269
|
+
}
|
|
15270
|
+
tagName = sanitizeName(tagName, options);
|
|
15271
|
+
return {
|
|
15272
|
+
tagName,
|
|
15273
|
+
tagExp
|
|
15274
|
+
};
|
|
14841
15275
|
}
|
|
14842
|
-
function
|
|
15276
|
+
function sanitizeName(name, options) {
|
|
15277
|
+
if (criticalProperties.includes(name)) throw new Error(`[SECURITY] Invalid name: "${name}" is a reserved JavaScript keyword that could cause prototype pollution`);
|
|
15278
|
+
if (DANGEROUS_PROPERTY_NAMES.includes(name)) return options.onDangerousProperty(name);
|
|
15279
|
+
return name;
|
|
15280
|
+
}
|
|
15281
|
+
const node2json_METADATA_SYMBOL = XmlNode.getMetaDataSymbol();
|
|
15282
|
+
function stripAttributePrefix(attrs, prefix) {
|
|
15283
|
+
if (!attrs || 'object' != typeof attrs) return {};
|
|
15284
|
+
if (!prefix) return attrs;
|
|
15285
|
+
const rawAttrs = {};
|
|
15286
|
+
for(const key in attrs)if (key.startsWith(prefix)) {
|
|
15287
|
+
const rawName = key.substring(prefix.length);
|
|
15288
|
+
rawAttrs[rawName] = attrs[key];
|
|
15289
|
+
} else rawAttrs[key] = attrs[key];
|
|
15290
|
+
return rawAttrs;
|
|
15291
|
+
}
|
|
15292
|
+
function prettify(node, options, matcher, readonlyMatcher) {
|
|
15293
|
+
return node2json_compress(node, options, matcher, readonlyMatcher);
|
|
15294
|
+
}
|
|
15295
|
+
function node2json_compress(arr, options, matcher, readonlyMatcher) {
|
|
14843
15296
|
let text;
|
|
14844
15297
|
const compressedObj = {};
|
|
14845
15298
|
for(let i = 0; i < arr.length; i++){
|
|
14846
15299
|
const tagObj = arr[i];
|
|
14847
15300
|
const property = propName(tagObj);
|
|
14848
|
-
|
|
14849
|
-
|
|
15301
|
+
if (void 0 !== property && property !== options.textNodeName) {
|
|
15302
|
+
const rawAttrs = stripAttributePrefix(tagObj[":@"] || {}, options.attributeNamePrefix);
|
|
15303
|
+
matcher.push(property, rawAttrs);
|
|
15304
|
+
}
|
|
14850
15305
|
if (property === options.textNodeName) if (void 0 === text) text = tagObj[property];
|
|
14851
15306
|
else text += "" + tagObj[property];
|
|
14852
15307
|
else if (void 0 === property) continue;
|
|
14853
15308
|
else if (tagObj[property]) {
|
|
14854
|
-
let val = node2json_compress(tagObj[property], options,
|
|
15309
|
+
let val = node2json_compress(tagObj[property], options, matcher, readonlyMatcher);
|
|
14855
15310
|
const isLeaf = isLeafTag(val, options);
|
|
14856
|
-
if (
|
|
14857
|
-
if (tagObj[":@"]) assignAttributes(val, tagObj[":@"], newJpath, options);
|
|
15311
|
+
if (tagObj[":@"]) assignAttributes(val, tagObj[":@"], readonlyMatcher, options);
|
|
14858
15312
|
else if (1 !== Object.keys(val).length || void 0 === val[options.textNodeName] || options.alwaysCreateTextNode) {
|
|
14859
15313
|
if (0 === Object.keys(val).length) if (options.alwaysCreateTextNode) val[options.textNodeName] = "";
|
|
14860
15314
|
else val = "";
|
|
14861
15315
|
} else val = val[options.textNodeName];
|
|
14862
|
-
if (void 0 !==
|
|
15316
|
+
if (void 0 !== tagObj[node2json_METADATA_SYMBOL] && "object" == typeof val && null !== val) val[node2json_METADATA_SYMBOL] = tagObj[node2json_METADATA_SYMBOL];
|
|
15317
|
+
if (void 0 !== compressedObj[property] && Object.prototype.hasOwnProperty.call(compressedObj, property)) {
|
|
14863
15318
|
if (!Array.isArray(compressedObj[property])) compressedObj[property] = [
|
|
14864
15319
|
compressedObj[property]
|
|
14865
15320
|
];
|
|
14866
15321
|
compressedObj[property].push(val);
|
|
14867
|
-
} else
|
|
14868
|
-
|
|
14869
|
-
|
|
14870
|
-
|
|
15322
|
+
} else {
|
|
15323
|
+
const jPathOrMatcher = options.jPath ? readonlyMatcher.toString() : readonlyMatcher;
|
|
15324
|
+
if (options.isArray(property, jPathOrMatcher, isLeaf)) compressedObj[property] = [
|
|
15325
|
+
val
|
|
15326
|
+
];
|
|
15327
|
+
else compressedObj[property] = val;
|
|
15328
|
+
}
|
|
15329
|
+
if (void 0 !== property && property !== options.textNodeName) matcher.pop();
|
|
14871
15330
|
}
|
|
14872
15331
|
}
|
|
14873
15332
|
if ("string" == typeof text) {
|
|
@@ -14882,13 +15341,15 @@
|
|
|
14882
15341
|
if (":@" !== key) return key;
|
|
14883
15342
|
}
|
|
14884
15343
|
}
|
|
14885
|
-
function assignAttributes(obj, attrMap,
|
|
15344
|
+
function assignAttributes(obj, attrMap, readonlyMatcher, options) {
|
|
14886
15345
|
if (attrMap) {
|
|
14887
15346
|
const keys = Object.keys(attrMap);
|
|
14888
15347
|
const len = keys.length;
|
|
14889
15348
|
for(let i = 0; i < len; i++){
|
|
14890
15349
|
const atrrName = keys[i];
|
|
14891
|
-
|
|
15350
|
+
const rawAttrName = atrrName.startsWith(options.attributeNamePrefix) ? atrrName.substring(options.attributeNamePrefix.length) : atrrName;
|
|
15351
|
+
const jPathOrMatcher = options.jPath ? readonlyMatcher.toString() + "." + rawAttrName : readonlyMatcher;
|
|
15352
|
+
if (options.isArray(atrrName, jPathOrMatcher, true, true)) obj[atrrName] = [
|
|
14892
15353
|
attrMap[atrrName]
|
|
14893
15354
|
];
|
|
14894
15355
|
else obj[atrrName] = attrMap[atrrName];
|
|
@@ -15068,7 +15529,7 @@
|
|
|
15068
15529
|
if (void 0 === matches[i][3] && !options.allowBooleanAttributes) return getErrorObject('InvalidAttr', "boolean attribute '" + matches[i][2] + "' is not allowed.", getPositionFromMatch(matches[i]));
|
|
15069
15530
|
const attrName = matches[i][2];
|
|
15070
15531
|
if (!validateAttrName(attrName)) return getErrorObject('InvalidAttr', "Attribute '" + attrName + "' is an invalid name.", getPositionFromMatch(matches[i]));
|
|
15071
|
-
if (
|
|
15532
|
+
if (Object.prototype.hasOwnProperty.call(attrNames, attrName)) return getErrorObject('InvalidAttr', "Attribute '" + attrName + "' is repeated.", getPositionFromMatch(matches[i]));
|
|
15072
15533
|
attrNames[attrName] = 1;
|
|
15073
15534
|
}
|
|
15074
15535
|
return true;
|
|
@@ -15142,7 +15603,7 @@
|
|
|
15142
15603
|
orderedObjParser.addExternalEntities(this.externalEntities);
|
|
15143
15604
|
const orderedResult = orderedObjParser.parseXml(xmlData);
|
|
15144
15605
|
if (this.options.preserveOrder || void 0 === orderedResult) return orderedResult;
|
|
15145
|
-
return prettify(orderedResult, this.options);
|
|
15606
|
+
return prettify(orderedResult, this.options, orderedObjParser.matcher, orderedObjParser.readonlyMatcher);
|
|
15146
15607
|
}
|
|
15147
15608
|
addEntity(key, value) {
|
|
15148
15609
|
if (-1 !== value.indexOf("&")) throw new Error("Entity value can't have '&'");
|
|
@@ -15158,52 +15619,74 @@
|
|
|
15158
15619
|
function toXml(jArray, options) {
|
|
15159
15620
|
let indentation = "";
|
|
15160
15621
|
if (options.format && options.indentBy.length > 0) indentation = EOL;
|
|
15161
|
-
|
|
15622
|
+
const stopNodeExpressions = [];
|
|
15623
|
+
if (options.stopNodes && Array.isArray(options.stopNodes)) for(let i = 0; i < options.stopNodes.length; i++){
|
|
15624
|
+
const node = options.stopNodes[i];
|
|
15625
|
+
if ('string' == typeof node) stopNodeExpressions.push(new Expression(node));
|
|
15626
|
+
else if (node instanceof Expression) stopNodeExpressions.push(node);
|
|
15627
|
+
}
|
|
15628
|
+
const matcher = new Matcher();
|
|
15629
|
+
return arrToStr(jArray, options, indentation, matcher, stopNodeExpressions);
|
|
15162
15630
|
}
|
|
15163
|
-
function arrToStr(arr, options,
|
|
15631
|
+
function arrToStr(arr, options, indentation, matcher, stopNodeExpressions) {
|
|
15164
15632
|
let xmlStr = "";
|
|
15165
15633
|
let isPreviousElementTag = false;
|
|
15634
|
+
if (options.maxNestedTags && matcher.getDepth() > options.maxNestedTags) throw new Error("Maximum nested tags exceeded");
|
|
15635
|
+
if (!Array.isArray(arr)) {
|
|
15636
|
+
if (null != arr) {
|
|
15637
|
+
let text = arr.toString();
|
|
15638
|
+
text = orderedJs2Xml_replaceEntitiesValue(text, options);
|
|
15639
|
+
return text;
|
|
15640
|
+
}
|
|
15641
|
+
return "";
|
|
15642
|
+
}
|
|
15166
15643
|
for(let i = 0; i < arr.length; i++){
|
|
15167
15644
|
const tagObj = arr[i];
|
|
15168
15645
|
const tagName = orderedJs2Xml_propName(tagObj);
|
|
15169
15646
|
if (void 0 === tagName) continue;
|
|
15170
|
-
|
|
15171
|
-
|
|
15647
|
+
const attrValues = extractAttributeValues(tagObj[":@"], options);
|
|
15648
|
+
matcher.push(tagName, attrValues);
|
|
15649
|
+
const isStopNode = checkStopNode(matcher, stopNodeExpressions);
|
|
15172
15650
|
if (tagName === options.textNodeName) {
|
|
15173
15651
|
let tagText = tagObj[tagName];
|
|
15174
|
-
if (!isStopNode
|
|
15652
|
+
if (!isStopNode) {
|
|
15175
15653
|
tagText = options.tagValueProcessor(tagName, tagText);
|
|
15176
15654
|
tagText = orderedJs2Xml_replaceEntitiesValue(tagText, options);
|
|
15177
15655
|
}
|
|
15178
15656
|
if (isPreviousElementTag) xmlStr += indentation;
|
|
15179
15657
|
xmlStr += tagText;
|
|
15180
15658
|
isPreviousElementTag = false;
|
|
15659
|
+
matcher.pop();
|
|
15181
15660
|
continue;
|
|
15182
15661
|
}
|
|
15183
15662
|
if (tagName === options.cdataPropName) {
|
|
15184
15663
|
if (isPreviousElementTag) xmlStr += indentation;
|
|
15185
15664
|
xmlStr += `<![CDATA[${tagObj[tagName][0][options.textNodeName]}]]>`;
|
|
15186
15665
|
isPreviousElementTag = false;
|
|
15666
|
+
matcher.pop();
|
|
15187
15667
|
continue;
|
|
15188
15668
|
}
|
|
15189
15669
|
if (tagName === options.commentPropName) {
|
|
15190
15670
|
xmlStr += indentation + `<!--${tagObj[tagName][0][options.textNodeName]}-->`;
|
|
15191
15671
|
isPreviousElementTag = true;
|
|
15672
|
+
matcher.pop();
|
|
15192
15673
|
continue;
|
|
15193
15674
|
} else if ("?" === tagName[0]) {
|
|
15194
|
-
const attStr = attr_to_str(tagObj[":@"], options);
|
|
15675
|
+
const attStr = attr_to_str(tagObj[":@"], options, isStopNode);
|
|
15195
15676
|
const tempInd = "?xml" === tagName ? "" : indentation;
|
|
15196
15677
|
let piTextNodeName = tagObj[tagName][0][options.textNodeName];
|
|
15197
15678
|
piTextNodeName = 0 !== piTextNodeName.length ? " " + piTextNodeName : "";
|
|
15198
15679
|
xmlStr += tempInd + `<${tagName}${piTextNodeName}${attStr}?>`;
|
|
15199
15680
|
isPreviousElementTag = true;
|
|
15681
|
+
matcher.pop();
|
|
15200
15682
|
continue;
|
|
15201
15683
|
}
|
|
15202
15684
|
let newIdentation = indentation;
|
|
15203
15685
|
if ("" !== newIdentation) newIdentation += options.indentBy;
|
|
15204
|
-
const attStr = attr_to_str(tagObj[":@"], options);
|
|
15686
|
+
const attStr = attr_to_str(tagObj[":@"], options, isStopNode);
|
|
15205
15687
|
const tagStart = indentation + `<${tagName}${attStr}`;
|
|
15206
|
-
|
|
15688
|
+
let tagValue;
|
|
15689
|
+
tagValue = isStopNode ? getRawContent(tagObj[tagName], options) : arrToStr(tagObj[tagName], options, newIdentation, matcher, stopNodeExpressions);
|
|
15207
15690
|
if (-1 !== options.unpairedTags.indexOf(tagName)) if (options.suppressUnpairedNode) xmlStr += tagStart + ">";
|
|
15208
15691
|
else xmlStr += tagStart + "/>";
|
|
15209
15692
|
else if ((!tagValue || 0 === tagValue.length) && options.suppressEmptyNode) xmlStr += tagStart + "/>";
|
|
@@ -15215,33 +15698,81 @@
|
|
|
15215
15698
|
xmlStr += `</${tagName}>`;
|
|
15216
15699
|
}
|
|
15217
15700
|
isPreviousElementTag = true;
|
|
15701
|
+
matcher.pop();
|
|
15218
15702
|
}
|
|
15219
15703
|
return xmlStr;
|
|
15220
15704
|
}
|
|
15705
|
+
function extractAttributeValues(attrMap, options) {
|
|
15706
|
+
if (!attrMap || options.ignoreAttributes) return null;
|
|
15707
|
+
const attrValues = {};
|
|
15708
|
+
let hasAttrs = false;
|
|
15709
|
+
for(let attr in attrMap){
|
|
15710
|
+
if (!Object.prototype.hasOwnProperty.call(attrMap, attr)) continue;
|
|
15711
|
+
const cleanAttrName = attr.startsWith(options.attributeNamePrefix) ? attr.substr(options.attributeNamePrefix.length) : attr;
|
|
15712
|
+
attrValues[cleanAttrName] = attrMap[attr];
|
|
15713
|
+
hasAttrs = true;
|
|
15714
|
+
}
|
|
15715
|
+
return hasAttrs ? attrValues : null;
|
|
15716
|
+
}
|
|
15717
|
+
function getRawContent(arr, options) {
|
|
15718
|
+
if (!Array.isArray(arr)) {
|
|
15719
|
+
if (null != arr) return arr.toString();
|
|
15720
|
+
return "";
|
|
15721
|
+
}
|
|
15722
|
+
let content = "";
|
|
15723
|
+
for(let i = 0; i < arr.length; i++){
|
|
15724
|
+
const item = arr[i];
|
|
15725
|
+
const tagName = orderedJs2Xml_propName(item);
|
|
15726
|
+
if (tagName === options.textNodeName) content += item[tagName];
|
|
15727
|
+
else if (tagName === options.cdataPropName) content += item[tagName][0][options.textNodeName];
|
|
15728
|
+
else if (tagName === options.commentPropName) content += item[tagName][0][options.textNodeName];
|
|
15729
|
+
else if (tagName && "?" === tagName[0]) continue;
|
|
15730
|
+
else if (tagName) {
|
|
15731
|
+
const attStr = attr_to_str_raw(item[":@"], options);
|
|
15732
|
+
const nestedContent = getRawContent(item[tagName], options);
|
|
15733
|
+
if (nestedContent && 0 !== nestedContent.length) content += `<${tagName}${attStr}>${nestedContent}</${tagName}>`;
|
|
15734
|
+
else content += `<${tagName}${attStr}/>`;
|
|
15735
|
+
}
|
|
15736
|
+
}
|
|
15737
|
+
return content;
|
|
15738
|
+
}
|
|
15739
|
+
function attr_to_str_raw(attrMap, options) {
|
|
15740
|
+
let attrStr = "";
|
|
15741
|
+
if (attrMap && !options.ignoreAttributes) for(let attr in attrMap){
|
|
15742
|
+
if (!Object.prototype.hasOwnProperty.call(attrMap, attr)) continue;
|
|
15743
|
+
let attrVal = attrMap[attr];
|
|
15744
|
+
if (true === attrVal && options.suppressBooleanAttributes) attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}`;
|
|
15745
|
+
else attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}="${attrVal}"`;
|
|
15746
|
+
}
|
|
15747
|
+
return attrStr;
|
|
15748
|
+
}
|
|
15221
15749
|
function orderedJs2Xml_propName(obj) {
|
|
15222
15750
|
const keys = Object.keys(obj);
|
|
15223
15751
|
for(let i = 0; i < keys.length; i++){
|
|
15224
15752
|
const key = keys[i];
|
|
15225
|
-
if (
|
|
15753
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
15226
15754
|
if (":@" !== key) return key;
|
|
15227
15755
|
}
|
|
15228
15756
|
}
|
|
15229
15757
|
}
|
|
15230
|
-
function attr_to_str(attrMap, options) {
|
|
15758
|
+
function attr_to_str(attrMap, options, isStopNode) {
|
|
15231
15759
|
let attrStr = "";
|
|
15232
15760
|
if (attrMap && !options.ignoreAttributes) for(let attr in attrMap){
|
|
15233
|
-
if (!
|
|
15234
|
-
let attrVal
|
|
15235
|
-
attrVal =
|
|
15761
|
+
if (!Object.prototype.hasOwnProperty.call(attrMap, attr)) continue;
|
|
15762
|
+
let attrVal;
|
|
15763
|
+
if (isStopNode) attrVal = attrMap[attr];
|
|
15764
|
+
else {
|
|
15765
|
+
attrVal = options.attributeValueProcessor(attr, attrMap[attr]);
|
|
15766
|
+
attrVal = orderedJs2Xml_replaceEntitiesValue(attrVal, options);
|
|
15767
|
+
}
|
|
15236
15768
|
if (true === attrVal && options.suppressBooleanAttributes) attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}`;
|
|
15237
15769
|
else attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}="${attrVal}"`;
|
|
15238
15770
|
}
|
|
15239
15771
|
return attrStr;
|
|
15240
15772
|
}
|
|
15241
|
-
function
|
|
15242
|
-
|
|
15243
|
-
let
|
|
15244
|
-
for(let index in options.stopNodes)if (options.stopNodes[index] === jPath || options.stopNodes[index] === "*." + tagName) return true;
|
|
15773
|
+
function checkStopNode(matcher, stopNodeExpressions) {
|
|
15774
|
+
if (!stopNodeExpressions || 0 === stopNodeExpressions.length) return false;
|
|
15775
|
+
for(let i = 0; i < stopNodeExpressions.length; i++)if (matcher.matches(stopNodeExpressions[i])) return true;
|
|
15245
15776
|
return false;
|
|
15246
15777
|
}
|
|
15247
15778
|
function orderedJs2Xml_replaceEntitiesValue(textValue, options) {
|
|
@@ -15251,7 +15782,17 @@
|
|
|
15251
15782
|
}
|
|
15252
15783
|
return textValue;
|
|
15253
15784
|
}
|
|
15254
|
-
|
|
15785
|
+
function ignoreAttributes_getIgnoreAttributesFn(ignoreAttributes) {
|
|
15786
|
+
if ('function' == typeof ignoreAttributes) return ignoreAttributes;
|
|
15787
|
+
if (Array.isArray(ignoreAttributes)) return (attrName)=>{
|
|
15788
|
+
for (const pattern of ignoreAttributes){
|
|
15789
|
+
if ('string' == typeof pattern && attrName === pattern) return true;
|
|
15790
|
+
if (pattern instanceof RegExp && pattern.test(attrName)) return true;
|
|
15791
|
+
}
|
|
15792
|
+
};
|
|
15793
|
+
return ()=>false;
|
|
15794
|
+
}
|
|
15795
|
+
const fxb_defaultOptions = {
|
|
15255
15796
|
attributeNamePrefix: '@_',
|
|
15256
15797
|
attributesGroupName: false,
|
|
15257
15798
|
textNodeName: '#text',
|
|
@@ -15295,15 +15836,27 @@
|
|
|
15295
15836
|
],
|
|
15296
15837
|
processEntities: true,
|
|
15297
15838
|
stopNodes: [],
|
|
15298
|
-
oneListGroup: false
|
|
15839
|
+
oneListGroup: false,
|
|
15840
|
+
maxNestedTags: 100,
|
|
15841
|
+
jPath: true
|
|
15299
15842
|
};
|
|
15300
15843
|
function Builder(options) {
|
|
15301
|
-
this.options = Object.assign({},
|
|
15844
|
+
this.options = Object.assign({}, fxb_defaultOptions, options);
|
|
15845
|
+
if (this.options.stopNodes && Array.isArray(this.options.stopNodes)) this.options.stopNodes = this.options.stopNodes.map((node)=>{
|
|
15846
|
+
if ('string' == typeof node && node.startsWith('*.')) return '..' + node.substring(2);
|
|
15847
|
+
return node;
|
|
15848
|
+
});
|
|
15849
|
+
this.stopNodeExpressions = [];
|
|
15850
|
+
if (this.options.stopNodes && Array.isArray(this.options.stopNodes)) for(let i = 0; i < this.options.stopNodes.length; i++){
|
|
15851
|
+
const node = this.options.stopNodes[i];
|
|
15852
|
+
if ('string' == typeof node) this.stopNodeExpressions.push(new Expression(node));
|
|
15853
|
+
else if (node instanceof Expression) this.stopNodeExpressions.push(node);
|
|
15854
|
+
}
|
|
15302
15855
|
if (true === this.options.ignoreAttributes || this.options.attributesGroupName) this.isAttribute = function() {
|
|
15303
15856
|
return false;
|
|
15304
15857
|
};
|
|
15305
15858
|
else {
|
|
15306
|
-
this.ignoreAttributesFn =
|
|
15859
|
+
this.ignoreAttributesFn = ignoreAttributes_getIgnoreAttributesFn(this.options.ignoreAttributes);
|
|
15307
15860
|
this.attrPrefixLen = this.options.attributeNamePrefix.length;
|
|
15308
15861
|
this.isAttribute = isAttribute;
|
|
15309
15862
|
}
|
|
@@ -15322,29 +15875,43 @@
|
|
|
15322
15875
|
}
|
|
15323
15876
|
Builder.prototype.build = function(jObj) {
|
|
15324
15877
|
if (this.options.preserveOrder) return toXml(jObj, this.options);
|
|
15325
|
-
|
|
15326
|
-
|
|
15327
|
-
|
|
15328
|
-
|
|
15878
|
+
{
|
|
15879
|
+
if (Array.isArray(jObj) && this.options.arrayNodeName && this.options.arrayNodeName.length > 1) jObj = {
|
|
15880
|
+
[this.options.arrayNodeName]: jObj
|
|
15881
|
+
};
|
|
15882
|
+
const matcher = new Matcher();
|
|
15883
|
+
return this.j2x(jObj, 0, matcher).val;
|
|
15884
|
+
}
|
|
15329
15885
|
};
|
|
15330
|
-
Builder.prototype.j2x = function(jObj, level,
|
|
15886
|
+
Builder.prototype.j2x = function(jObj, level, matcher) {
|
|
15331
15887
|
let attrStr = '';
|
|
15332
15888
|
let val = '';
|
|
15333
|
-
|
|
15889
|
+
if (this.options.maxNestedTags && matcher.getDepth() >= this.options.maxNestedTags) throw new Error("Maximum nested tags exceeded");
|
|
15890
|
+
const jPath = this.options.jPath ? matcher.toString() : matcher;
|
|
15891
|
+
const isCurrentStopNode = this.checkStopNode(matcher);
|
|
15334
15892
|
for(let key in jObj)if (Object.prototype.hasOwnProperty.call(jObj, key)) if (void 0 === jObj[key]) {
|
|
15335
15893
|
if (this.isAttribute(key)) val += '';
|
|
15336
15894
|
} else if (null === jObj[key]) if (this.isAttribute(key)) val += '';
|
|
15337
15895
|
else if (key === this.options.cdataPropName) val += '';
|
|
15338
15896
|
else if ('?' === key[0]) val += this.indentate(level) + '<' + key + '?' + this.tagEndChar;
|
|
15339
15897
|
else val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;
|
|
15340
|
-
else if (jObj[key] instanceof Date) val += this.buildTextValNode(jObj[key], key, '', level);
|
|
15898
|
+
else if (jObj[key] instanceof Date) val += this.buildTextValNode(jObj[key], key, '', level, matcher);
|
|
15341
15899
|
else if ('object' != typeof jObj[key]) {
|
|
15342
15900
|
const attr = this.isAttribute(key);
|
|
15343
|
-
if (attr && !this.ignoreAttributesFn(attr, jPath)) attrStr += this.buildAttrPairStr(attr, '' + jObj[key]);
|
|
15901
|
+
if (attr && !this.ignoreAttributesFn(attr, jPath)) attrStr += this.buildAttrPairStr(attr, '' + jObj[key], isCurrentStopNode);
|
|
15344
15902
|
else if (!attr) if (key === this.options.textNodeName) {
|
|
15345
15903
|
let newval = this.options.tagValueProcessor(key, '' + jObj[key]);
|
|
15346
15904
|
val += this.replaceEntitiesValue(newval);
|
|
15347
|
-
} else
|
|
15905
|
+
} else {
|
|
15906
|
+
matcher.push(key);
|
|
15907
|
+
const isStopNode = this.checkStopNode(matcher);
|
|
15908
|
+
matcher.pop();
|
|
15909
|
+
if (isStopNode) {
|
|
15910
|
+
const textValue = '' + jObj[key];
|
|
15911
|
+
if ('' === textValue) val += this.indentate(level) + '<' + key + this.closeTag(key) + this.tagEndChar;
|
|
15912
|
+
else val += this.indentate(level) + '<' + key + '>' + textValue + '</' + key + this.tagEndChar;
|
|
15913
|
+
} else val += this.buildTextValNode(jObj[key], key, '', level, matcher);
|
|
15914
|
+
}
|
|
15348
15915
|
} else if (Array.isArray(jObj[key])) {
|
|
15349
15916
|
const arrLen = jObj[key].length;
|
|
15350
15917
|
let listTagVal = "";
|
|
@@ -15355,39 +15922,135 @@
|
|
|
15355
15922
|
else if (null === item) if ("?" === key[0]) val += this.indentate(level) + '<' + key + '?' + this.tagEndChar;
|
|
15356
15923
|
else val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;
|
|
15357
15924
|
else if ('object' == typeof item) if (this.options.oneListGroup) {
|
|
15358
|
-
|
|
15925
|
+
matcher.push(key);
|
|
15926
|
+
const result = this.j2x(item, level + 1, matcher);
|
|
15927
|
+
matcher.pop();
|
|
15359
15928
|
listTagVal += result.val;
|
|
15360
15929
|
if (this.options.attributesGroupName && item.hasOwnProperty(this.options.attributesGroupName)) listTagAttr += result.attrStr;
|
|
15361
|
-
} else listTagVal += this.processTextOrObjNode(item, key, level,
|
|
15930
|
+
} else listTagVal += this.processTextOrObjNode(item, key, level, matcher);
|
|
15362
15931
|
else if (this.options.oneListGroup) {
|
|
15363
15932
|
let textValue = this.options.tagValueProcessor(key, item);
|
|
15364
15933
|
textValue = this.replaceEntitiesValue(textValue);
|
|
15365
15934
|
listTagVal += textValue;
|
|
15366
|
-
} else
|
|
15935
|
+
} else {
|
|
15936
|
+
matcher.push(key);
|
|
15937
|
+
const isStopNode = this.checkStopNode(matcher);
|
|
15938
|
+
matcher.pop();
|
|
15939
|
+
if (isStopNode) {
|
|
15940
|
+
const textValue = '' + item;
|
|
15941
|
+
if ('' === textValue) listTagVal += this.indentate(level) + '<' + key + this.closeTag(key) + this.tagEndChar;
|
|
15942
|
+
else listTagVal += this.indentate(level) + '<' + key + '>' + textValue + '</' + key + this.tagEndChar;
|
|
15943
|
+
} else listTagVal += this.buildTextValNode(item, key, '', level, matcher);
|
|
15944
|
+
}
|
|
15367
15945
|
}
|
|
15368
15946
|
if (this.options.oneListGroup) listTagVal = this.buildObjectNode(listTagVal, key, listTagAttr, level);
|
|
15369
15947
|
val += listTagVal;
|
|
15370
15948
|
} else if (this.options.attributesGroupName && key === this.options.attributesGroupName) {
|
|
15371
15949
|
const Ks = Object.keys(jObj[key]);
|
|
15372
15950
|
const L = Ks.length;
|
|
15373
|
-
for(let j = 0; j < L; j++)attrStr += this.buildAttrPairStr(Ks[j], '' + jObj[key][Ks[j]]);
|
|
15374
|
-
} else val += this.processTextOrObjNode(jObj[key], key, level,
|
|
15951
|
+
for(let j = 0; j < L; j++)attrStr += this.buildAttrPairStr(Ks[j], '' + jObj[key][Ks[j]], isCurrentStopNode);
|
|
15952
|
+
} else val += this.processTextOrObjNode(jObj[key], key, level, matcher);
|
|
15375
15953
|
return {
|
|
15376
15954
|
attrStr: attrStr,
|
|
15377
15955
|
val: val
|
|
15378
15956
|
};
|
|
15379
15957
|
};
|
|
15380
|
-
Builder.prototype.buildAttrPairStr = function(attrName, val) {
|
|
15381
|
-
|
|
15382
|
-
|
|
15958
|
+
Builder.prototype.buildAttrPairStr = function(attrName, val, isStopNode) {
|
|
15959
|
+
if (!isStopNode) {
|
|
15960
|
+
val = this.options.attributeValueProcessor(attrName, '' + val);
|
|
15961
|
+
val = this.replaceEntitiesValue(val);
|
|
15962
|
+
}
|
|
15383
15963
|
if (this.options.suppressBooleanAttributes && "true" === val) return ' ' + attrName;
|
|
15384
15964
|
return ' ' + attrName + '="' + val + '"';
|
|
15385
15965
|
};
|
|
15386
|
-
function processTextOrObjNode(object, key, level,
|
|
15387
|
-
const
|
|
15388
|
-
|
|
15966
|
+
function processTextOrObjNode(object, key, level, matcher) {
|
|
15967
|
+
const attrValues = this.extractAttributes(object);
|
|
15968
|
+
matcher.push(key, attrValues);
|
|
15969
|
+
const isStopNode = this.checkStopNode(matcher);
|
|
15970
|
+
if (isStopNode) {
|
|
15971
|
+
const rawContent = this.buildRawContent(object);
|
|
15972
|
+
const attrStr = this.buildAttributesForStopNode(object);
|
|
15973
|
+
matcher.pop();
|
|
15974
|
+
return this.buildObjectNode(rawContent, key, attrStr, level);
|
|
15975
|
+
}
|
|
15976
|
+
const result = this.j2x(object, level + 1, matcher);
|
|
15977
|
+
matcher.pop();
|
|
15978
|
+
if (void 0 !== object[this.options.textNodeName] && 1 === Object.keys(object).length) return this.buildTextValNode(object[this.options.textNodeName], key, result.attrStr, level, matcher);
|
|
15389
15979
|
return this.buildObjectNode(result.val, key, result.attrStr, level);
|
|
15390
15980
|
}
|
|
15981
|
+
Builder.prototype.extractAttributes = function(obj) {
|
|
15982
|
+
if (!obj || 'object' != typeof obj) return null;
|
|
15983
|
+
const attrValues = {};
|
|
15984
|
+
let hasAttrs = false;
|
|
15985
|
+
if (this.options.attributesGroupName && obj[this.options.attributesGroupName]) {
|
|
15986
|
+
const attrGroup = obj[this.options.attributesGroupName];
|
|
15987
|
+
for(let attrKey in attrGroup){
|
|
15988
|
+
if (!Object.prototype.hasOwnProperty.call(attrGroup, attrKey)) continue;
|
|
15989
|
+
const cleanKey = attrKey.startsWith(this.options.attributeNamePrefix) ? attrKey.substring(this.options.attributeNamePrefix.length) : attrKey;
|
|
15990
|
+
attrValues[cleanKey] = attrGroup[attrKey];
|
|
15991
|
+
hasAttrs = true;
|
|
15992
|
+
}
|
|
15993
|
+
} else for(let key in obj){
|
|
15994
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
15995
|
+
const attr = this.isAttribute(key);
|
|
15996
|
+
if (attr) {
|
|
15997
|
+
attrValues[attr] = obj[key];
|
|
15998
|
+
hasAttrs = true;
|
|
15999
|
+
}
|
|
16000
|
+
}
|
|
16001
|
+
return hasAttrs ? attrValues : null;
|
|
16002
|
+
};
|
|
16003
|
+
Builder.prototype.buildRawContent = function(obj) {
|
|
16004
|
+
if ('string' == typeof obj) return obj;
|
|
16005
|
+
if ('object' != typeof obj || null === obj) return String(obj);
|
|
16006
|
+
if (void 0 !== obj[this.options.textNodeName]) return obj[this.options.textNodeName];
|
|
16007
|
+
let content = '';
|
|
16008
|
+
for(let key in obj){
|
|
16009
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
16010
|
+
if (this.isAttribute(key)) continue;
|
|
16011
|
+
if (this.options.attributesGroupName && key === this.options.attributesGroupName) continue;
|
|
16012
|
+
const value = obj[key];
|
|
16013
|
+
if (key === this.options.textNodeName) content += value;
|
|
16014
|
+
else if (Array.isArray(value)) {
|
|
16015
|
+
for (let item of value)if ('string' == typeof item || 'number' == typeof item) content += `<${key}>${item}</${key}>`;
|
|
16016
|
+
else if ('object' == typeof item && null !== item) {
|
|
16017
|
+
const nestedContent = this.buildRawContent(item);
|
|
16018
|
+
const nestedAttrs = this.buildAttributesForStopNode(item);
|
|
16019
|
+
if ('' === nestedContent) content += `<${key}${nestedAttrs}/>`;
|
|
16020
|
+
else content += `<${key}${nestedAttrs}>${nestedContent}</${key}>`;
|
|
16021
|
+
}
|
|
16022
|
+
} else if ('object' == typeof value && null !== value) {
|
|
16023
|
+
const nestedContent = this.buildRawContent(value);
|
|
16024
|
+
const nestedAttrs = this.buildAttributesForStopNode(value);
|
|
16025
|
+
if ('' === nestedContent) content += `<${key}${nestedAttrs}/>`;
|
|
16026
|
+
else content += `<${key}${nestedAttrs}>${nestedContent}</${key}>`;
|
|
16027
|
+
} else content += `<${key}>${value}</${key}>`;
|
|
16028
|
+
}
|
|
16029
|
+
return content;
|
|
16030
|
+
};
|
|
16031
|
+
Builder.prototype.buildAttributesForStopNode = function(obj) {
|
|
16032
|
+
if (!obj || 'object' != typeof obj) return '';
|
|
16033
|
+
let attrStr = '';
|
|
16034
|
+
if (this.options.attributesGroupName && obj[this.options.attributesGroupName]) {
|
|
16035
|
+
const attrGroup = obj[this.options.attributesGroupName];
|
|
16036
|
+
for(let attrKey in attrGroup){
|
|
16037
|
+
if (!Object.prototype.hasOwnProperty.call(attrGroup, attrKey)) continue;
|
|
16038
|
+
const cleanKey = attrKey.startsWith(this.options.attributeNamePrefix) ? attrKey.substring(this.options.attributeNamePrefix.length) : attrKey;
|
|
16039
|
+
const val = attrGroup[attrKey];
|
|
16040
|
+
if (true === val && this.options.suppressBooleanAttributes) attrStr += ' ' + cleanKey;
|
|
16041
|
+
else attrStr += ' ' + cleanKey + '="' + val + '"';
|
|
16042
|
+
}
|
|
16043
|
+
} else for(let key in obj){
|
|
16044
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
16045
|
+
const attr = this.isAttribute(key);
|
|
16046
|
+
if (attr) {
|
|
16047
|
+
const val = obj[key];
|
|
16048
|
+
if (true === val && this.options.suppressBooleanAttributes) attrStr += ' ' + attr;
|
|
16049
|
+
else attrStr += ' ' + attr + '="' + val + '"';
|
|
16050
|
+
}
|
|
16051
|
+
}
|
|
16052
|
+
return attrStr;
|
|
16053
|
+
};
|
|
15391
16054
|
Builder.prototype.buildObjectNode = function(val, key, attrStr, level) {
|
|
15392
16055
|
if ("" === val) if ("?" === key[0]) return this.indentate(level) + '<' + key + attrStr + '?' + this.tagEndChar;
|
|
15393
16056
|
else return this.indentate(level) + '<' + key + attrStr + this.closeTag(key) + this.tagEndChar;
|
|
@@ -15410,7 +16073,12 @@
|
|
|
15410
16073
|
} else closeTag = this.options.suppressEmptyNode ? "/" : `></${key}`;
|
|
15411
16074
|
return closeTag;
|
|
15412
16075
|
};
|
|
15413
|
-
Builder.prototype.
|
|
16076
|
+
Builder.prototype.checkStopNode = function(matcher) {
|
|
16077
|
+
if (!this.stopNodeExpressions || 0 === this.stopNodeExpressions.length) return false;
|
|
16078
|
+
for(let i = 0; i < this.stopNodeExpressions.length; i++)if (matcher.matches(this.stopNodeExpressions[i])) return true;
|
|
16079
|
+
return false;
|
|
16080
|
+
};
|
|
16081
|
+
Builder.prototype.buildTextValNode = function(val, key, attrStr, level, matcher) {
|
|
15414
16082
|
if (false !== this.options.cdataPropName && key === this.options.cdataPropName) return this.indentate(level) + `<![CDATA[${val}]]>` + this.newLine;
|
|
15415
16083
|
{
|
|
15416
16084
|
if (false !== this.options.commentPropName && key === this.options.commentPropName) return this.indentate(level) + `<!--${val}-->` + this.newLine;
|
|
@@ -15435,6 +16103,7 @@
|
|
|
15435
16103
|
if (name.startsWith(this.options.attributeNamePrefix) && name !== this.options.textNodeName) return name.substr(this.attrPrefixLen);
|
|
15436
16104
|
return false;
|
|
15437
16105
|
}
|
|
16106
|
+
const json2xml = Builder;
|
|
15438
16107
|
var json_bigint = __webpack_require__("../../node_modules/.pnpm/json-bigint@1.0.0/node_modules/json-bigint/index.js");
|
|
15439
16108
|
var json_bigint_default = /*#__PURE__*/ __webpack_require__.n(json_bigint);
|
|
15440
16109
|
var descriptors_ScalarType;
|
|
@@ -15827,12 +16496,12 @@
|
|
|
15827
16496
|
break;
|
|
15828
16497
|
}
|
|
15829
16498
|
}
|
|
15830
|
-
function
|
|
16499
|
+
function isObject(arg) {
|
|
15831
16500
|
return null !== arg && "object" == typeof arg && !Array.isArray(arg);
|
|
15832
16501
|
}
|
|
15833
16502
|
function isReflectList(arg, field) {
|
|
15834
16503
|
var _a, _b, _c, _d;
|
|
15835
|
-
if (
|
|
16504
|
+
if (isObject(arg) && unsafeLocal in arg && "add" in arg && "field" in arg && "function" == typeof arg.field) {
|
|
15836
16505
|
if (void 0 !== field) {
|
|
15837
16506
|
const a = field;
|
|
15838
16507
|
const b = arg.field();
|
|
@@ -15844,7 +16513,7 @@
|
|
|
15844
16513
|
}
|
|
15845
16514
|
function isReflectMap(arg, field) {
|
|
15846
16515
|
var _a, _b, _c, _d;
|
|
15847
|
-
if (
|
|
16516
|
+
if (isObject(arg) && unsafeLocal in arg && "has" in arg && "field" in arg && "function" == typeof arg.field) {
|
|
15848
16517
|
if (void 0 !== field) {
|
|
15849
16518
|
const a = field, b = arg.field();
|
|
15850
16519
|
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);
|
|
@@ -15854,7 +16523,7 @@
|
|
|
15854
16523
|
return false;
|
|
15855
16524
|
}
|
|
15856
16525
|
function isReflectMessage(arg, messageDesc) {
|
|
15857
|
-
return
|
|
16526
|
+
return isObject(arg) && unsafeLocal in arg && "desc" in arg && isObject(arg.desc) && "message" === arg.desc.kind && (void 0 === messageDesc || arg.desc.typeName == messageDesc.typeName);
|
|
15858
16527
|
}
|
|
15859
16528
|
const symbol = Symbol.for("@bufbuild/protobuf/text-encoding");
|
|
15860
16529
|
function getTextEncoding() {
|
|
@@ -16379,7 +17048,7 @@
|
|
|
16379
17048
|
return value;
|
|
16380
17049
|
}
|
|
16381
17050
|
function initMap(field, value) {
|
|
16382
|
-
if (
|
|
17051
|
+
if (isObject(value)) {
|
|
16383
17052
|
if (field.scalar == descriptors_ScalarType.BYTES) return convertObjectValues(value, toU8Arr);
|
|
16384
17053
|
if ("message" == field.mapKind) return convertObjectValues(value, (val)=>toMessage(field, val));
|
|
16385
17054
|
}
|
|
@@ -16394,7 +17063,7 @@
|
|
|
16394
17063
|
}
|
|
16395
17064
|
function toMessage(field, value) {
|
|
16396
17065
|
if ("message" == field.fieldKind && !field.oneof && isWrapperDesc(field.message)) return initScalar(field.message.fields[0], value);
|
|
16397
|
-
if (
|
|
17066
|
+
if (isObject(value)) {
|
|
16398
17067
|
if ("google.protobuf.Struct" == field.message.typeName && "google.protobuf.Value" !== field.parent.typeName) return value;
|
|
16399
17068
|
if (!is_message_isMessage(value, field.message)) return create(field.message, value);
|
|
16400
17069
|
}
|
|
@@ -16674,7 +17343,7 @@
|
|
|
16674
17343
|
$typeName: field.message.typeName,
|
|
16675
17344
|
value: longToReflect(field.message.fields[0], value)
|
|
16676
17345
|
};
|
|
16677
|
-
else if ("google.protobuf.Struct" == field.message.typeName && "google.protobuf.Value" != field.parent.typeName &&
|
|
17346
|
+
else if ("google.protobuf.Struct" == field.message.typeName && "google.protobuf.Value" != field.parent.typeName && isObject(value)) value = wktStructToReflect(value);
|
|
16678
17347
|
}
|
|
16679
17348
|
return new ReflectMessageImpl(field.message, value, check);
|
|
16680
17349
|
}
|
|
@@ -16768,7 +17437,7 @@
|
|
|
16768
17437
|
$typeName: "google.protobuf.Struct",
|
|
16769
17438
|
fields: {}
|
|
16770
17439
|
};
|
|
16771
|
-
if (
|
|
17440
|
+
if (isObject(json)) for (const [k, v] of Object.entries(json))struct.fields[k] = wktValueToReflect(v);
|
|
16772
17441
|
return struct;
|
|
16773
17442
|
}
|
|
16774
17443
|
function wktStructToLocal(val) {
|
|
@@ -20391,7 +21060,7 @@
|
|
|
20391
21060
|
function timestamp_timestampMs(timestamp) {
|
|
20392
21061
|
return 1000 * Number(timestamp.seconds) + Math.round(timestamp.nanos / 1000000);
|
|
20393
21062
|
}
|
|
20394
|
-
var package_namespaceObject = JSON.parse('{"UU":"@dan-uni/dan-any","rE":"1.3.
|
|
21063
|
+
var package_namespaceObject = JSON.parse('{"UU":"@dan-uni/dan-any","rE":"1.3.3","TB":"https://github.com/ani-uni/danuni/tree/master/packages/dan-any#readme"}');
|
|
20395
21064
|
const color_pad = (s)=>s.length < 2 ? `0${s}` : s;
|
|
20396
21065
|
const decimalToHex = (n)=>color_pad(n.toString(16));
|
|
20397
21066
|
const isDarkColor = ({ r, g, b })=>0.299 * r + 0.587 * g + 0.114 * b < 0x30;
|
|
@@ -21148,9 +21817,7 @@
|
|
|
21148
21817
|
ValidationExecutor.prototype.customValidations = function(object, value, metadatas, error) {
|
|
21149
21818
|
var _this = this;
|
|
21150
21819
|
metadatas.forEach(function(metadata) {
|
|
21151
|
-
|
|
21152
|
-
if (customConstraintMetadata.async && _this.ignoreAsyncValidations) return;
|
|
21153
|
-
if (_this.validatorOptions && _this.validatorOptions.stopAtFirstError && Object.keys(error.constraints || {}).length > 0) return;
|
|
21820
|
+
var getValidationArguments = function() {
|
|
21154
21821
|
var validationArguments = {
|
|
21155
21822
|
targetName: object.constructor ? object.constructor.name : void 0,
|
|
21156
21823
|
property: metadata.propertyName,
|
|
@@ -21158,6 +21825,16 @@
|
|
|
21158
21825
|
value: value,
|
|
21159
21826
|
constraints: metadata.constraints
|
|
21160
21827
|
};
|
|
21828
|
+
return validationArguments;
|
|
21829
|
+
};
|
|
21830
|
+
if (metadata.validateIf) {
|
|
21831
|
+
var shouldValidate = metadata.validateIf(object, value);
|
|
21832
|
+
if (!shouldValidate) return;
|
|
21833
|
+
}
|
|
21834
|
+
_this.metadataStorage.getTargetValidatorConstraints(metadata.constraintCls).forEach(function(customConstraintMetadata) {
|
|
21835
|
+
if (customConstraintMetadata.async && _this.ignoreAsyncValidations) return;
|
|
21836
|
+
if (_this.validatorOptions && _this.validatorOptions.stopAtFirstError && Object.keys(error.constraints || {}).length > 0) return;
|
|
21837
|
+
var validationArguments = getValidationArguments();
|
|
21161
21838
|
if (!metadata.each || !(Array.isArray(value) || value instanceof Set || value instanceof Map)) {
|
|
21162
21839
|
var validatedValue = customConstraintMetadata.instance.validate(value, validationArguments);
|
|
21163
21840
|
if (is_promise_util_isPromise(validatedValue)) {
|
|
@@ -22697,7 +23374,7 @@
|
|
|
22697
23374
|
do {
|
|
22698
23375
|
bits.unshift(!!(1 & number));
|
|
22699
23376
|
number >>= 1;
|
|
22700
|
-
}while (number)
|
|
23377
|
+
}while (number)
|
|
22701
23378
|
return bits.toReversed();
|
|
22702
23379
|
};
|
|
22703
23380
|
var dm_gen_DMAttr = /*#__PURE__*/ function(DMAttr) {
|
|
@@ -22771,7 +23448,7 @@
|
|
|
22771
23448
|
if (!this.SOID) this.SOID = def.SOID;
|
|
22772
23449
|
if (!this.progress) this.progress = def.progress;
|
|
22773
23450
|
if (!this.mode) this.mode = def.mode;
|
|
22774
|
-
if (!this.fontsize) this.fontsize = def.
|
|
23451
|
+
if (!this.fontsize) this.fontsize = def.fontsize;
|
|
22775
23452
|
if (!this.color) this.color = def.color;
|
|
22776
23453
|
if (!this.senderID) this.senderID = def.senderID;
|
|
22777
23454
|
if (!this.content) this.content = def.content;
|
|
@@ -23666,7 +24343,7 @@
|
|
|
23666
24343
|
const rawText = JSON.stringify(raw1);
|
|
23667
24344
|
let compress;
|
|
23668
24345
|
compress = 'brotli' === compressType ? (0, lib.brotliCompressSync)(rawText) : (0, lib.gzipSync)(rawText);
|
|
23669
|
-
return `;RawCompressType: ${compressType}\n;RawBaseType: ${baseType}\n;Raw: ${'base64' === baseType ? compress.toString('base64') : fromUint16Array(base16384_lib.
|
|
24346
|
+
return `;RawCompressType: ${compressType}\n;RawBaseType: ${baseType}\n;Raw: ${'base64' === baseType ? compress.toString('base64') : fromUint16Array(base16384_lib.lF(compress))}`;
|
|
23670
24347
|
}
|
|
23671
24348
|
function deRaw(ass) {
|
|
23672
24349
|
const arr = ass.split('\n');
|
|
@@ -23680,7 +24357,7 @@
|
|
|
23680
24357
|
if (!compressTypes.has(compressType)) compressType = 'gzip';
|
|
23681
24358
|
if (!baseTypes.has(baseType)) baseType = 'base64';
|
|
23682
24359
|
const text = lineRaw.replace(';Raw: ', '').trim();
|
|
23683
|
-
const buffer = 'base64' === baseType ? raw_Buffer.from(text, 'base64') : raw_Buffer.from(base16384_lib.
|
|
24360
|
+
const buffer = 'base64' === baseType ? raw_Buffer.from(text, 'base64') : raw_Buffer.from(base16384_lib.D4(raw_Buffer.from(text, 'utf8').toString('utf8')));
|
|
23684
24361
|
let decompress;
|
|
23685
24362
|
decompress = 'brotli' === compressType ? (0, lib.brotliDecompressSync)(buffer) : (0, lib.gunzipSync)(buffer);
|
|
23686
24363
|
try {
|
|
@@ -23803,6 +24480,31 @@
|
|
|
23803
24480
|
file_google_protobuf_timestamp
|
|
23804
24481
|
]);
|
|
23805
24482
|
const ListDanResponseSchema = /*@__PURE__*/ message_messageDesc(file_danuni_danmaku_v1_danmaku, 2);
|
|
24483
|
+
function fileParser(file, mod) {
|
|
24484
|
+
const isBinary = file instanceof ArrayBuffer || file instanceof Uint8Array;
|
|
24485
|
+
switch(mod){
|
|
24486
|
+
case 'bin':
|
|
24487
|
+
if (isBinary) return file;
|
|
24488
|
+
throw new TypeError('Expected binary data for mod "bin"');
|
|
24489
|
+
case 'string':
|
|
24490
|
+
if ('string' == typeof file) return file;
|
|
24491
|
+
if (isBinary) return new TextDecoder().decode(file);
|
|
24492
|
+
throw new TypeError('Expected binary data or string for mod "string"');
|
|
24493
|
+
case 'json':
|
|
24494
|
+
{
|
|
24495
|
+
if ('object' == typeof file && null !== file && !isBinary) return file;
|
|
24496
|
+
if ('string' != typeof file && !isBinary) throw new TypeError('Expected object, JSON string, or binary data for mod "json"');
|
|
24497
|
+
const str = 'string' == typeof file ? file : new TextDecoder().decode(file);
|
|
24498
|
+
try {
|
|
24499
|
+
return JSON.parse(str);
|
|
24500
|
+
} catch {
|
|
24501
|
+
throw new Error('Invalid JSON string');
|
|
24502
|
+
}
|
|
24503
|
+
}
|
|
24504
|
+
default:
|
|
24505
|
+
throw new Error(`Unsupported mod "${mod}"`);
|
|
24506
|
+
}
|
|
24507
|
+
}
|
|
23806
24508
|
const src_JSON = json_bigint_default()({
|
|
23807
24509
|
useNativeBigInt: true
|
|
23808
24510
|
});
|
|
@@ -24022,6 +24724,87 @@
|
|
|
24022
24724
|
return this.dans.map((d)=>d.minify());
|
|
24023
24725
|
}
|
|
24024
24726
|
static import(file, options, mod) {
|
|
24727
|
+
const handlers = {
|
|
24728
|
+
["danuni.json"]: (json)=>({
|
|
24729
|
+
pool: new UniPool(json, options),
|
|
24730
|
+
fmt: "danuni.json"
|
|
24731
|
+
}),
|
|
24732
|
+
["danuni.min.json"]: (json)=>({
|
|
24733
|
+
pool: this.fromMin(json, options),
|
|
24734
|
+
fmt: "danuni.min.json"
|
|
24735
|
+
}),
|
|
24736
|
+
["danuni.binpb"]: (file)=>({
|
|
24737
|
+
pool: this.fromPb(file),
|
|
24738
|
+
fmt: "danuni.binpb"
|
|
24739
|
+
}),
|
|
24740
|
+
["bili.xml"]: (file)=>({
|
|
24741
|
+
pool: this.fromBiliXML(file, options),
|
|
24742
|
+
fmt: "bili.xml"
|
|
24743
|
+
}),
|
|
24744
|
+
["bili.binpb"]: (file)=>({
|
|
24745
|
+
pool: this.fromBiliGrpc(file),
|
|
24746
|
+
fmt: "bili.binpb"
|
|
24747
|
+
}),
|
|
24748
|
+
["bili.cmd.binpb"]: (file)=>({
|
|
24749
|
+
pool: this.fromBiliCommandGrpc(file),
|
|
24750
|
+
fmt: "bili.cmd.binpb"
|
|
24751
|
+
}),
|
|
24752
|
+
["bili.up.json"]: (json)=>({
|
|
24753
|
+
pool: this.fromBiliUp(json, options),
|
|
24754
|
+
fmt: "bili.up.json"
|
|
24755
|
+
}),
|
|
24756
|
+
["dplayer.json"]: (json)=>({
|
|
24757
|
+
pool: this.fromDplayer(json, json.danuni?.data ?? '', void 0, options),
|
|
24758
|
+
fmt: "dplayer.json"
|
|
24759
|
+
}),
|
|
24760
|
+
["artplayer.json"]: (json)=>({
|
|
24761
|
+
pool: this.fromArtplayer(json, json.danuni?.data ?? '', void 0, options),
|
|
24762
|
+
fmt: "artplayer.json"
|
|
24763
|
+
}),
|
|
24764
|
+
["ddplay.json"]: (json)=>({
|
|
24765
|
+
pool: this.fromDDPlay(json, json.danuni?.data ?? '', options),
|
|
24766
|
+
fmt: "ddplay.json"
|
|
24767
|
+
}),
|
|
24768
|
+
["common.ass"]: (file)=>({
|
|
24769
|
+
pool: this.fromASS(file, options),
|
|
24770
|
+
fmt: "common.ass"
|
|
24771
|
+
})
|
|
24772
|
+
};
|
|
24773
|
+
if ('string' == typeof mod) {
|
|
24774
|
+
const fn = mod;
|
|
24775
|
+
try {
|
|
24776
|
+
if (fn.endsWith("danuni.json")) return handlers["danuni.json"](fileParser(file, 'json'));
|
|
24777
|
+
if (fn.endsWith("danuni.min.json")) return handlers["danuni.min.json"](fileParser(file, 'json'));
|
|
24778
|
+
if (fn.endsWith("danuni.binpb")) return handlers["danuni.binpb"](fileParser(file, 'bin'));
|
|
24779
|
+
else if (fn.endsWith("bili.xml")) return handlers["bili.xml"](fileParser(file, 'string'));
|
|
24780
|
+
else if (fn.endsWith("bili.binpb")) return handlers["bili.binpb"](fileParser(file, 'bin'));
|
|
24781
|
+
else if (fn.endsWith("bili.cmd.binpb")) return handlers["bili.cmd.binpb"](fileParser(file, 'bin'));
|
|
24782
|
+
else if (fn.endsWith("bili.up.json")) return handlers["bili.up.json"](fileParser(file, 'json'));
|
|
24783
|
+
else if (fn.endsWith("dplayer.json")) return handlers["dplayer.json"](fileParser(file, 'json'));
|
|
24784
|
+
else if (fn.endsWith("artplayer.json")) return handlers["artplayer.json"](fileParser(file, 'json'));
|
|
24785
|
+
else if (fn.endsWith("ddplay.json")) return handlers["ddplay.json"](fileParser(file, 'json'));
|
|
24786
|
+
else if (fn.endsWith("common.ass")) return handlers["common.ass"](fileParser(file, 'string'));
|
|
24787
|
+
} catch {}
|
|
24788
|
+
const ext = fn.split('.').pop()?.toLowerCase();
|
|
24789
|
+
if (ext) {
|
|
24790
|
+
if ('json' === ext) mod = [
|
|
24791
|
+
'json'
|
|
24792
|
+
];
|
|
24793
|
+
else if ([
|
|
24794
|
+
'xml',
|
|
24795
|
+
'ass'
|
|
24796
|
+
].includes(ext)) mod = [
|
|
24797
|
+
'str'
|
|
24798
|
+
];
|
|
24799
|
+
else if ([
|
|
24800
|
+
'binpb',
|
|
24801
|
+
'bin',
|
|
24802
|
+
'so'
|
|
24803
|
+
].includes(ext)) mod = [
|
|
24804
|
+
'bin'
|
|
24805
|
+
];
|
|
24806
|
+
}
|
|
24807
|
+
}
|
|
24025
24808
|
if (!mod) mod = [
|
|
24026
24809
|
'json',
|
|
24027
24810
|
'str',
|
|
@@ -24030,26 +24813,11 @@
|
|
|
24030
24813
|
const err = '无法识别该文件,请手动指定格式!';
|
|
24031
24814
|
const parseJSON = (json)=>{
|
|
24032
24815
|
try {
|
|
24033
|
-
if (Array.isArray(json) && json.every((d)=>d.SOID)) return
|
|
24034
|
-
|
|
24035
|
-
|
|
24036
|
-
|
|
24037
|
-
if (json.
|
|
24038
|
-
pool: this.fromArtplayer(json, json.danuni?.data ?? '', void 0, options),
|
|
24039
|
-
fmt: "artplayer.json"
|
|
24040
|
-
};
|
|
24041
|
-
if (json.count && json.comments && Array.isArray(json.comments) && json.comments.every((d)=>d.m)) return {
|
|
24042
|
-
pool: this.fromDDPlay(json, json.danuni?.data ?? '', options),
|
|
24043
|
-
fmt: "ddplay.json"
|
|
24044
|
-
};
|
|
24045
|
-
else if (0 == json.code && json.data && Array.isArray(json.data) && json.data.every((d)=>Array.isArray(d))) return {
|
|
24046
|
-
pool: this.fromDplayer(json, json.danuni?.data ?? '', void 0, options),
|
|
24047
|
-
fmt: "dplayer.json"
|
|
24048
|
-
};
|
|
24049
|
-
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 {
|
|
24050
|
-
pool: this.fromBiliUp(json, options),
|
|
24051
|
-
fmt: "bili.up.json"
|
|
24052
|
-
};
|
|
24816
|
+
if (Array.isArray(json) && json.every((d)=>d.SOID)) return handlers["danuni.min.json"](json);
|
|
24817
|
+
if (json.danmuku && json.danmuku.every((d)=>d.text)) return handlers["artplayer.json"](json);
|
|
24818
|
+
if (json.count && json.comments && Array.isArray(json.comments) && json.comments.every((d)=>d.m)) return handlers["ddplay.json"](json);
|
|
24819
|
+
else if (0 == json.code && json.data && Array.isArray(json.data) && json.data.every((d)=>Array.isArray(d))) return handlers["dplayer.json"](json);
|
|
24820
|
+
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);
|
|
24053
24821
|
} catch {}
|
|
24054
24822
|
};
|
|
24055
24823
|
const parseStr = (file)=>{
|
|
@@ -24065,40 +24833,25 @@
|
|
|
24065
24833
|
ignoreAttributes: false
|
|
24066
24834
|
});
|
|
24067
24835
|
const xml = xmlParser.parse(file);
|
|
24068
|
-
if (xml?.i?.d) return
|
|
24069
|
-
pool: this.fromBiliXML(file, options),
|
|
24070
|
-
fmt: "bili.xml"
|
|
24071
|
-
};
|
|
24836
|
+
if (xml?.i?.d) return handlers["bili.xml"](file);
|
|
24072
24837
|
} catch {}
|
|
24073
24838
|
try {
|
|
24074
|
-
return
|
|
24075
|
-
pool: this.fromASS(file, options),
|
|
24076
|
-
fmt: "common.ass"
|
|
24077
|
-
};
|
|
24839
|
+
return handlers["common.ass"](file);
|
|
24078
24840
|
} catch {}
|
|
24079
24841
|
}
|
|
24080
24842
|
};
|
|
24081
24843
|
let errmesg;
|
|
24082
|
-
if (
|
|
24844
|
+
if ('object' == typeof file || Array.isArray(file)) {
|
|
24083
24845
|
if (file instanceof ArrayBuffer || file instanceof Uint8Array) {
|
|
24084
24846
|
if (mod.includes('bin')) {
|
|
24085
24847
|
try {
|
|
24086
|
-
return
|
|
24087
|
-
pool: this.fromPb(file),
|
|
24088
|
-
fmt: "danuni.binpb"
|
|
24089
|
-
};
|
|
24848
|
+
return handlers["danuni.binpb"](file);
|
|
24090
24849
|
} catch {}
|
|
24091
24850
|
try {
|
|
24092
|
-
return
|
|
24093
|
-
pool: this.fromBiliGrpc(file),
|
|
24094
|
-
fmt: "bili.binpb"
|
|
24095
|
-
};
|
|
24851
|
+
return handlers["bili.binpb"](file);
|
|
24096
24852
|
} catch {}
|
|
24097
24853
|
try {
|
|
24098
|
-
return
|
|
24099
|
-
pool: this.fromBiliCommandGrpc(file),
|
|
24100
|
-
fmt: "bili.cmd.binpb"
|
|
24101
|
-
};
|
|
24854
|
+
return handlers["bili.cmd.binpb"](file);
|
|
24102
24855
|
} catch {}
|
|
24103
24856
|
}
|
|
24104
24857
|
try {
|
|
@@ -24143,6 +24896,9 @@
|
|
|
24143
24896
|
}
|
|
24144
24897
|
}
|
|
24145
24898
|
}
|
|
24899
|
+
static fromMin(json, options) {
|
|
24900
|
+
return new UniPool(json.map((d)=>UniDM.create(d, options)));
|
|
24901
|
+
}
|
|
24146
24902
|
static fromPb(bin, options) {
|
|
24147
24903
|
const data = fromBinary(ListDanResponseSchema, new Uint8Array(bin));
|
|
24148
24904
|
return new UniPool(data.danmakus.map((d)=>UniDM.create({
|
|
@@ -24204,7 +24960,7 @@
|
|
|
24204
24960
|
const ok = this.dans.every((d)=>d.senderID.endsWith(`@${platform.PlatformVideoSource.Bilibili}`));
|
|
24205
24961
|
if (!ok) throw new Error('存在其他来源的senderID,请关闭该功能再试!');
|
|
24206
24962
|
}
|
|
24207
|
-
const builder = new
|
|
24963
|
+
const builder = new json2xml({
|
|
24208
24964
|
ignoreAttributes: false
|
|
24209
24965
|
});
|
|
24210
24966
|
return builder.build({
|