@rpgjs/tiledmap 5.0.0-alpha.1-local.1 → 5.0.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/index.js +11 -5
- package/dist/client/index2.js +1 -1
- package/dist/client/index3.js +4649 -12
- package/dist/client/index4.js +15 -0
- package/dist/index.d.ts +1 -0
- package/dist/server/index.js +1 -1
- package/dist/server/index2.js +1 -1
- package/dist/server/index3.js +5232 -0
- package/dist/server.d.ts +1 -1
- package/package.json +10 -8
- package/src/client.ts +1 -1
- package/src/index.ts +27 -18
- package/src/server.ts +1 -4
- package/src/tiled.ce +3 -2
package/dist/client/index3.js
CHANGED
|
@@ -1,15 +1,4652 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { TiledMap } from "@canvasengine/presets";
|
|
4
|
-
function component($$props) {
|
|
5
|
-
useProps($$props);
|
|
6
|
-
const defineProps = useDefineProps($$props);
|
|
7
|
-
var _a = defineProps(), data = _a.data;
|
|
8
|
-
_a.children;
|
|
9
|
-
var map = signal(data());
|
|
10
|
-
let $this = h(Container, null, h(TiledMap, { map, basePath: "map", createLayersPerTilesZ: true, objectLayer: () => h(EventLayerComponent) }));
|
|
11
|
-
return $this;
|
|
1
|
+
function joinPath(...segments) {
|
|
2
|
+
return segments.filter((segment) => segment && segment.length > 0).join("/").replace(/\/+/g, "/");
|
|
12
3
|
}
|
|
4
|
+
function getAugmentedNamespace(n) {
|
|
5
|
+
if (Object.prototype.hasOwnProperty.call(n, "__esModule")) return n;
|
|
6
|
+
var f = n.default;
|
|
7
|
+
if (typeof f == "function") {
|
|
8
|
+
var a = function a2() {
|
|
9
|
+
if (this instanceof a2) {
|
|
10
|
+
return Reflect.construct(f, arguments, this.constructor);
|
|
11
|
+
}
|
|
12
|
+
return f.apply(this, arguments);
|
|
13
|
+
};
|
|
14
|
+
a.prototype = f.prototype;
|
|
15
|
+
} else a = {};
|
|
16
|
+
Object.defineProperty(a, "__esModule", { value: true });
|
|
17
|
+
Object.keys(n).forEach(function(k) {
|
|
18
|
+
var d = Object.getOwnPropertyDescriptor(n, k);
|
|
19
|
+
Object.defineProperty(a, k, d.get ? d : {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function() {
|
|
22
|
+
return n[k];
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
return a;
|
|
27
|
+
}
|
|
28
|
+
var sax = {};
|
|
29
|
+
const __viteBrowserExternal = {};
|
|
30
|
+
const __viteBrowserExternal$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
31
|
+
__proto__: null,
|
|
32
|
+
default: __viteBrowserExternal
|
|
33
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
34
|
+
const require$$0 = /* @__PURE__ */ getAugmentedNamespace(__viteBrowserExternal$1);
|
|
35
|
+
var string_decoder = {};
|
|
36
|
+
var safeBuffer = { exports: {} };
|
|
37
|
+
var buffer = {};
|
|
38
|
+
var base64Js = {};
|
|
39
|
+
var hasRequiredBase64Js;
|
|
40
|
+
function requireBase64Js() {
|
|
41
|
+
if (hasRequiredBase64Js) return base64Js;
|
|
42
|
+
hasRequiredBase64Js = 1;
|
|
43
|
+
base64Js.byteLength = byteLength;
|
|
44
|
+
base64Js.toByteArray = toByteArray;
|
|
45
|
+
base64Js.fromByteArray = fromByteArray;
|
|
46
|
+
var lookup = [];
|
|
47
|
+
var revLookup = [];
|
|
48
|
+
var Arr = typeof Uint8Array !== "undefined" ? Uint8Array : Array;
|
|
49
|
+
var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
50
|
+
for (var i = 0, len = code.length; i < len; ++i) {
|
|
51
|
+
lookup[i] = code[i];
|
|
52
|
+
revLookup[code.charCodeAt(i)] = i;
|
|
53
|
+
}
|
|
54
|
+
revLookup["-".charCodeAt(0)] = 62;
|
|
55
|
+
revLookup["_".charCodeAt(0)] = 63;
|
|
56
|
+
function getLens(b64) {
|
|
57
|
+
var len2 = b64.length;
|
|
58
|
+
if (len2 % 4 > 0) {
|
|
59
|
+
throw new Error("Invalid string. Length must be a multiple of 4");
|
|
60
|
+
}
|
|
61
|
+
var validLen = b64.indexOf("=");
|
|
62
|
+
if (validLen === -1) validLen = len2;
|
|
63
|
+
var placeHoldersLen = validLen === len2 ? 0 : 4 - validLen % 4;
|
|
64
|
+
return [validLen, placeHoldersLen];
|
|
65
|
+
}
|
|
66
|
+
function byteLength(b64) {
|
|
67
|
+
var lens = getLens(b64);
|
|
68
|
+
var validLen = lens[0];
|
|
69
|
+
var placeHoldersLen = lens[1];
|
|
70
|
+
return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
|
|
71
|
+
}
|
|
72
|
+
function _byteLength(b64, validLen, placeHoldersLen) {
|
|
73
|
+
return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
|
|
74
|
+
}
|
|
75
|
+
function toByteArray(b64) {
|
|
76
|
+
var tmp;
|
|
77
|
+
var lens = getLens(b64);
|
|
78
|
+
var validLen = lens[0];
|
|
79
|
+
var placeHoldersLen = lens[1];
|
|
80
|
+
var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
|
|
81
|
+
var curByte = 0;
|
|
82
|
+
var len2 = placeHoldersLen > 0 ? validLen - 4 : validLen;
|
|
83
|
+
var i2;
|
|
84
|
+
for (i2 = 0; i2 < len2; i2 += 4) {
|
|
85
|
+
tmp = revLookup[b64.charCodeAt(i2)] << 18 | revLookup[b64.charCodeAt(i2 + 1)] << 12 | revLookup[b64.charCodeAt(i2 + 2)] << 6 | revLookup[b64.charCodeAt(i2 + 3)];
|
|
86
|
+
arr[curByte++] = tmp >> 16 & 255;
|
|
87
|
+
arr[curByte++] = tmp >> 8 & 255;
|
|
88
|
+
arr[curByte++] = tmp & 255;
|
|
89
|
+
}
|
|
90
|
+
if (placeHoldersLen === 2) {
|
|
91
|
+
tmp = revLookup[b64.charCodeAt(i2)] << 2 | revLookup[b64.charCodeAt(i2 + 1)] >> 4;
|
|
92
|
+
arr[curByte++] = tmp & 255;
|
|
93
|
+
}
|
|
94
|
+
if (placeHoldersLen === 1) {
|
|
95
|
+
tmp = revLookup[b64.charCodeAt(i2)] << 10 | revLookup[b64.charCodeAt(i2 + 1)] << 4 | revLookup[b64.charCodeAt(i2 + 2)] >> 2;
|
|
96
|
+
arr[curByte++] = tmp >> 8 & 255;
|
|
97
|
+
arr[curByte++] = tmp & 255;
|
|
98
|
+
}
|
|
99
|
+
return arr;
|
|
100
|
+
}
|
|
101
|
+
function tripletToBase64(num) {
|
|
102
|
+
return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63];
|
|
103
|
+
}
|
|
104
|
+
function encodeChunk(uint8, start, end) {
|
|
105
|
+
var tmp;
|
|
106
|
+
var output = [];
|
|
107
|
+
for (var i2 = start; i2 < end; i2 += 3) {
|
|
108
|
+
tmp = (uint8[i2] << 16 & 16711680) + (uint8[i2 + 1] << 8 & 65280) + (uint8[i2 + 2] & 255);
|
|
109
|
+
output.push(tripletToBase64(tmp));
|
|
110
|
+
}
|
|
111
|
+
return output.join("");
|
|
112
|
+
}
|
|
113
|
+
function fromByteArray(uint8) {
|
|
114
|
+
var tmp;
|
|
115
|
+
var len2 = uint8.length;
|
|
116
|
+
var extraBytes = len2 % 3;
|
|
117
|
+
var parts = [];
|
|
118
|
+
var maxChunkLength = 16383;
|
|
119
|
+
for (var i2 = 0, len22 = len2 - extraBytes; i2 < len22; i2 += maxChunkLength) {
|
|
120
|
+
parts.push(encodeChunk(uint8, i2, i2 + maxChunkLength > len22 ? len22 : i2 + maxChunkLength));
|
|
121
|
+
}
|
|
122
|
+
if (extraBytes === 1) {
|
|
123
|
+
tmp = uint8[len2 - 1];
|
|
124
|
+
parts.push(
|
|
125
|
+
lookup[tmp >> 2] + lookup[tmp << 4 & 63] + "=="
|
|
126
|
+
);
|
|
127
|
+
} else if (extraBytes === 2) {
|
|
128
|
+
tmp = (uint8[len2 - 2] << 8) + uint8[len2 - 1];
|
|
129
|
+
parts.push(
|
|
130
|
+
lookup[tmp >> 10] + lookup[tmp >> 4 & 63] + lookup[tmp << 2 & 63] + "="
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
return parts.join("");
|
|
134
|
+
}
|
|
135
|
+
return base64Js;
|
|
136
|
+
}
|
|
137
|
+
var ieee754 = {};
|
|
138
|
+
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
139
|
+
var hasRequiredIeee754;
|
|
140
|
+
function requireIeee754() {
|
|
141
|
+
if (hasRequiredIeee754) return ieee754;
|
|
142
|
+
hasRequiredIeee754 = 1;
|
|
143
|
+
ieee754.read = function(buffer2, offset, isLE, mLen, nBytes) {
|
|
144
|
+
var e, m;
|
|
145
|
+
var eLen = nBytes * 8 - mLen - 1;
|
|
146
|
+
var eMax = (1 << eLen) - 1;
|
|
147
|
+
var eBias = eMax >> 1;
|
|
148
|
+
var nBits = -7;
|
|
149
|
+
var i = isLE ? nBytes - 1 : 0;
|
|
150
|
+
var d = isLE ? -1 : 1;
|
|
151
|
+
var s = buffer2[offset + i];
|
|
152
|
+
i += d;
|
|
153
|
+
e = s & (1 << -nBits) - 1;
|
|
154
|
+
s >>= -nBits;
|
|
155
|
+
nBits += eLen;
|
|
156
|
+
for (; nBits > 0; e = e * 256 + buffer2[offset + i], i += d, nBits -= 8) {
|
|
157
|
+
}
|
|
158
|
+
m = e & (1 << -nBits) - 1;
|
|
159
|
+
e >>= -nBits;
|
|
160
|
+
nBits += mLen;
|
|
161
|
+
for (; nBits > 0; m = m * 256 + buffer2[offset + i], i += d, nBits -= 8) {
|
|
162
|
+
}
|
|
163
|
+
if (e === 0) {
|
|
164
|
+
e = 1 - eBias;
|
|
165
|
+
} else if (e === eMax) {
|
|
166
|
+
return m ? NaN : (s ? -1 : 1) * Infinity;
|
|
167
|
+
} else {
|
|
168
|
+
m = m + Math.pow(2, mLen);
|
|
169
|
+
e = e - eBias;
|
|
170
|
+
}
|
|
171
|
+
return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
|
|
172
|
+
};
|
|
173
|
+
ieee754.write = function(buffer2, value, offset, isLE, mLen, nBytes) {
|
|
174
|
+
var e, m, c;
|
|
175
|
+
var eLen = nBytes * 8 - mLen - 1;
|
|
176
|
+
var eMax = (1 << eLen) - 1;
|
|
177
|
+
var eBias = eMax >> 1;
|
|
178
|
+
var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
|
|
179
|
+
var i = isLE ? 0 : nBytes - 1;
|
|
180
|
+
var d = isLE ? 1 : -1;
|
|
181
|
+
var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
|
|
182
|
+
value = Math.abs(value);
|
|
183
|
+
if (isNaN(value) || value === Infinity) {
|
|
184
|
+
m = isNaN(value) ? 1 : 0;
|
|
185
|
+
e = eMax;
|
|
186
|
+
} else {
|
|
187
|
+
e = Math.floor(Math.log(value) / Math.LN2);
|
|
188
|
+
if (value * (c = Math.pow(2, -e)) < 1) {
|
|
189
|
+
e--;
|
|
190
|
+
c *= 2;
|
|
191
|
+
}
|
|
192
|
+
if (e + eBias >= 1) {
|
|
193
|
+
value += rt / c;
|
|
194
|
+
} else {
|
|
195
|
+
value += rt * Math.pow(2, 1 - eBias);
|
|
196
|
+
}
|
|
197
|
+
if (value * c >= 2) {
|
|
198
|
+
e++;
|
|
199
|
+
c /= 2;
|
|
200
|
+
}
|
|
201
|
+
if (e + eBias >= eMax) {
|
|
202
|
+
m = 0;
|
|
203
|
+
e = eMax;
|
|
204
|
+
} else if (e + eBias >= 1) {
|
|
205
|
+
m = (value * c - 1) * Math.pow(2, mLen);
|
|
206
|
+
e = e + eBias;
|
|
207
|
+
} else {
|
|
208
|
+
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
|
209
|
+
e = 0;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
for (; mLen >= 8; buffer2[offset + i] = m & 255, i += d, m /= 256, mLen -= 8) {
|
|
213
|
+
}
|
|
214
|
+
e = e << mLen | m;
|
|
215
|
+
eLen += mLen;
|
|
216
|
+
for (; eLen > 0; buffer2[offset + i] = e & 255, i += d, e /= 256, eLen -= 8) {
|
|
217
|
+
}
|
|
218
|
+
buffer2[offset + i - d] |= s * 128;
|
|
219
|
+
};
|
|
220
|
+
return ieee754;
|
|
221
|
+
}
|
|
222
|
+
/*!
|
|
223
|
+
* The buffer module from node.js, for the browser.
|
|
224
|
+
*
|
|
225
|
+
* @author Feross Aboukhadijeh <https://feross.org>
|
|
226
|
+
* @license MIT
|
|
227
|
+
*/
|
|
228
|
+
var hasRequiredBuffer;
|
|
229
|
+
function requireBuffer() {
|
|
230
|
+
if (hasRequiredBuffer) return buffer;
|
|
231
|
+
hasRequiredBuffer = 1;
|
|
232
|
+
(function(exports) {
|
|
233
|
+
const base64 = requireBase64Js();
|
|
234
|
+
const ieee7542 = requireIeee754();
|
|
235
|
+
const customInspectSymbol = typeof Symbol === "function" && typeof Symbol["for"] === "function" ? Symbol["for"]("nodejs.util.inspect.custom") : null;
|
|
236
|
+
exports.Buffer = Buffer2;
|
|
237
|
+
exports.SlowBuffer = SlowBuffer;
|
|
238
|
+
exports.INSPECT_MAX_BYTES = 50;
|
|
239
|
+
const K_MAX_LENGTH = 2147483647;
|
|
240
|
+
exports.kMaxLength = K_MAX_LENGTH;
|
|
241
|
+
Buffer2.TYPED_ARRAY_SUPPORT = typedArraySupport();
|
|
242
|
+
if (!Buffer2.TYPED_ARRAY_SUPPORT && typeof console !== "undefined" && typeof console.error === "function") {
|
|
243
|
+
console.error(
|
|
244
|
+
"This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
function typedArraySupport() {
|
|
248
|
+
try {
|
|
249
|
+
const arr = new Uint8Array(1);
|
|
250
|
+
const proto = { foo: function() {
|
|
251
|
+
return 42;
|
|
252
|
+
} };
|
|
253
|
+
Object.setPrototypeOf(proto, Uint8Array.prototype);
|
|
254
|
+
Object.setPrototypeOf(arr, proto);
|
|
255
|
+
return arr.foo() === 42;
|
|
256
|
+
} catch (e) {
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
Object.defineProperty(Buffer2.prototype, "parent", {
|
|
261
|
+
enumerable: true,
|
|
262
|
+
get: function() {
|
|
263
|
+
if (!Buffer2.isBuffer(this)) return void 0;
|
|
264
|
+
return this.buffer;
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
Object.defineProperty(Buffer2.prototype, "offset", {
|
|
268
|
+
enumerable: true,
|
|
269
|
+
get: function() {
|
|
270
|
+
if (!Buffer2.isBuffer(this)) return void 0;
|
|
271
|
+
return this.byteOffset;
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
function createBuffer(length) {
|
|
275
|
+
if (length > K_MAX_LENGTH) {
|
|
276
|
+
throw new RangeError('The value "' + length + '" is invalid for option "size"');
|
|
277
|
+
}
|
|
278
|
+
const buf = new Uint8Array(length);
|
|
279
|
+
Object.setPrototypeOf(buf, Buffer2.prototype);
|
|
280
|
+
return buf;
|
|
281
|
+
}
|
|
282
|
+
function Buffer2(arg, encodingOrOffset, length) {
|
|
283
|
+
if (typeof arg === "number") {
|
|
284
|
+
if (typeof encodingOrOffset === "string") {
|
|
285
|
+
throw new TypeError(
|
|
286
|
+
'The "string" argument must be of type string. Received type number'
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
return allocUnsafe(arg);
|
|
290
|
+
}
|
|
291
|
+
return from(arg, encodingOrOffset, length);
|
|
292
|
+
}
|
|
293
|
+
Buffer2.poolSize = 8192;
|
|
294
|
+
function from(value, encodingOrOffset, length) {
|
|
295
|
+
if (typeof value === "string") {
|
|
296
|
+
return fromString(value, encodingOrOffset);
|
|
297
|
+
}
|
|
298
|
+
if (ArrayBuffer.isView(value)) {
|
|
299
|
+
return fromArrayView(value);
|
|
300
|
+
}
|
|
301
|
+
if (value == null) {
|
|
302
|
+
throw new TypeError(
|
|
303
|
+
"The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
if (isInstance(value, ArrayBuffer) || value && isInstance(value.buffer, ArrayBuffer)) {
|
|
307
|
+
return fromArrayBuffer(value, encodingOrOffset, length);
|
|
308
|
+
}
|
|
309
|
+
if (typeof SharedArrayBuffer !== "undefined" && (isInstance(value, SharedArrayBuffer) || value && isInstance(value.buffer, SharedArrayBuffer))) {
|
|
310
|
+
return fromArrayBuffer(value, encodingOrOffset, length);
|
|
311
|
+
}
|
|
312
|
+
if (typeof value === "number") {
|
|
313
|
+
throw new TypeError(
|
|
314
|
+
'The "value" argument must not be of type number. Received type number'
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
const valueOf = value.valueOf && value.valueOf();
|
|
318
|
+
if (valueOf != null && valueOf !== value) {
|
|
319
|
+
return Buffer2.from(valueOf, encodingOrOffset, length);
|
|
320
|
+
}
|
|
321
|
+
const b = fromObject(value);
|
|
322
|
+
if (b) return b;
|
|
323
|
+
if (typeof Symbol !== "undefined" && Symbol.toPrimitive != null && typeof value[Symbol.toPrimitive] === "function") {
|
|
324
|
+
return Buffer2.from(value[Symbol.toPrimitive]("string"), encodingOrOffset, length);
|
|
325
|
+
}
|
|
326
|
+
throw new TypeError(
|
|
327
|
+
"The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
Buffer2.from = function(value, encodingOrOffset, length) {
|
|
331
|
+
return from(value, encodingOrOffset, length);
|
|
332
|
+
};
|
|
333
|
+
Object.setPrototypeOf(Buffer2.prototype, Uint8Array.prototype);
|
|
334
|
+
Object.setPrototypeOf(Buffer2, Uint8Array);
|
|
335
|
+
function assertSize(size) {
|
|
336
|
+
if (typeof size !== "number") {
|
|
337
|
+
throw new TypeError('"size" argument must be of type number');
|
|
338
|
+
} else if (size < 0) {
|
|
339
|
+
throw new RangeError('The value "' + size + '" is invalid for option "size"');
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
function alloc(size, fill, encoding) {
|
|
343
|
+
assertSize(size);
|
|
344
|
+
if (size <= 0) {
|
|
345
|
+
return createBuffer(size);
|
|
346
|
+
}
|
|
347
|
+
if (fill !== void 0) {
|
|
348
|
+
return typeof encoding === "string" ? createBuffer(size).fill(fill, encoding) : createBuffer(size).fill(fill);
|
|
349
|
+
}
|
|
350
|
+
return createBuffer(size);
|
|
351
|
+
}
|
|
352
|
+
Buffer2.alloc = function(size, fill, encoding) {
|
|
353
|
+
return alloc(size, fill, encoding);
|
|
354
|
+
};
|
|
355
|
+
function allocUnsafe(size) {
|
|
356
|
+
assertSize(size);
|
|
357
|
+
return createBuffer(size < 0 ? 0 : checked(size) | 0);
|
|
358
|
+
}
|
|
359
|
+
Buffer2.allocUnsafe = function(size) {
|
|
360
|
+
return allocUnsafe(size);
|
|
361
|
+
};
|
|
362
|
+
Buffer2.allocUnsafeSlow = function(size) {
|
|
363
|
+
return allocUnsafe(size);
|
|
364
|
+
};
|
|
365
|
+
function fromString(string, encoding) {
|
|
366
|
+
if (typeof encoding !== "string" || encoding === "") {
|
|
367
|
+
encoding = "utf8";
|
|
368
|
+
}
|
|
369
|
+
if (!Buffer2.isEncoding(encoding)) {
|
|
370
|
+
throw new TypeError("Unknown encoding: " + encoding);
|
|
371
|
+
}
|
|
372
|
+
const length = byteLength(string, encoding) | 0;
|
|
373
|
+
let buf = createBuffer(length);
|
|
374
|
+
const actual = buf.write(string, encoding);
|
|
375
|
+
if (actual !== length) {
|
|
376
|
+
buf = buf.slice(0, actual);
|
|
377
|
+
}
|
|
378
|
+
return buf;
|
|
379
|
+
}
|
|
380
|
+
function fromArrayLike(array) {
|
|
381
|
+
const length = array.length < 0 ? 0 : checked(array.length) | 0;
|
|
382
|
+
const buf = createBuffer(length);
|
|
383
|
+
for (let i = 0; i < length; i += 1) {
|
|
384
|
+
buf[i] = array[i] & 255;
|
|
385
|
+
}
|
|
386
|
+
return buf;
|
|
387
|
+
}
|
|
388
|
+
function fromArrayView(arrayView) {
|
|
389
|
+
if (isInstance(arrayView, Uint8Array)) {
|
|
390
|
+
const copy = new Uint8Array(arrayView);
|
|
391
|
+
return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength);
|
|
392
|
+
}
|
|
393
|
+
return fromArrayLike(arrayView);
|
|
394
|
+
}
|
|
395
|
+
function fromArrayBuffer(array, byteOffset, length) {
|
|
396
|
+
if (byteOffset < 0 || array.byteLength < byteOffset) {
|
|
397
|
+
throw new RangeError('"offset" is outside of buffer bounds');
|
|
398
|
+
}
|
|
399
|
+
if (array.byteLength < byteOffset + (length || 0)) {
|
|
400
|
+
throw new RangeError('"length" is outside of buffer bounds');
|
|
401
|
+
}
|
|
402
|
+
let buf;
|
|
403
|
+
if (byteOffset === void 0 && length === void 0) {
|
|
404
|
+
buf = new Uint8Array(array);
|
|
405
|
+
} else if (length === void 0) {
|
|
406
|
+
buf = new Uint8Array(array, byteOffset);
|
|
407
|
+
} else {
|
|
408
|
+
buf = new Uint8Array(array, byteOffset, length);
|
|
409
|
+
}
|
|
410
|
+
Object.setPrototypeOf(buf, Buffer2.prototype);
|
|
411
|
+
return buf;
|
|
412
|
+
}
|
|
413
|
+
function fromObject(obj) {
|
|
414
|
+
if (Buffer2.isBuffer(obj)) {
|
|
415
|
+
const len = checked(obj.length) | 0;
|
|
416
|
+
const buf = createBuffer(len);
|
|
417
|
+
if (buf.length === 0) {
|
|
418
|
+
return buf;
|
|
419
|
+
}
|
|
420
|
+
obj.copy(buf, 0, 0, len);
|
|
421
|
+
return buf;
|
|
422
|
+
}
|
|
423
|
+
if (obj.length !== void 0) {
|
|
424
|
+
if (typeof obj.length !== "number" || numberIsNaN(obj.length)) {
|
|
425
|
+
return createBuffer(0);
|
|
426
|
+
}
|
|
427
|
+
return fromArrayLike(obj);
|
|
428
|
+
}
|
|
429
|
+
if (obj.type === "Buffer" && Array.isArray(obj.data)) {
|
|
430
|
+
return fromArrayLike(obj.data);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
function checked(length) {
|
|
434
|
+
if (length >= K_MAX_LENGTH) {
|
|
435
|
+
throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x" + K_MAX_LENGTH.toString(16) + " bytes");
|
|
436
|
+
}
|
|
437
|
+
return length | 0;
|
|
438
|
+
}
|
|
439
|
+
function SlowBuffer(length) {
|
|
440
|
+
if (+length != length) {
|
|
441
|
+
length = 0;
|
|
442
|
+
}
|
|
443
|
+
return Buffer2.alloc(+length);
|
|
444
|
+
}
|
|
445
|
+
Buffer2.isBuffer = function isBuffer(b) {
|
|
446
|
+
return b != null && b._isBuffer === true && b !== Buffer2.prototype;
|
|
447
|
+
};
|
|
448
|
+
Buffer2.compare = function compare(a, b) {
|
|
449
|
+
if (isInstance(a, Uint8Array)) a = Buffer2.from(a, a.offset, a.byteLength);
|
|
450
|
+
if (isInstance(b, Uint8Array)) b = Buffer2.from(b, b.offset, b.byteLength);
|
|
451
|
+
if (!Buffer2.isBuffer(a) || !Buffer2.isBuffer(b)) {
|
|
452
|
+
throw new TypeError(
|
|
453
|
+
'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
|
|
454
|
+
);
|
|
455
|
+
}
|
|
456
|
+
if (a === b) return 0;
|
|
457
|
+
let x = a.length;
|
|
458
|
+
let y = b.length;
|
|
459
|
+
for (let i = 0, len = Math.min(x, y); i < len; ++i) {
|
|
460
|
+
if (a[i] !== b[i]) {
|
|
461
|
+
x = a[i];
|
|
462
|
+
y = b[i];
|
|
463
|
+
break;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
if (x < y) return -1;
|
|
467
|
+
if (y < x) return 1;
|
|
468
|
+
return 0;
|
|
469
|
+
};
|
|
470
|
+
Buffer2.isEncoding = function isEncoding(encoding) {
|
|
471
|
+
switch (String(encoding).toLowerCase()) {
|
|
472
|
+
case "hex":
|
|
473
|
+
case "utf8":
|
|
474
|
+
case "utf-8":
|
|
475
|
+
case "ascii":
|
|
476
|
+
case "latin1":
|
|
477
|
+
case "binary":
|
|
478
|
+
case "base64":
|
|
479
|
+
case "ucs2":
|
|
480
|
+
case "ucs-2":
|
|
481
|
+
case "utf16le":
|
|
482
|
+
case "utf-16le":
|
|
483
|
+
return true;
|
|
484
|
+
default:
|
|
485
|
+
return false;
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
Buffer2.concat = function concat(list, length) {
|
|
489
|
+
if (!Array.isArray(list)) {
|
|
490
|
+
throw new TypeError('"list" argument must be an Array of Buffers');
|
|
491
|
+
}
|
|
492
|
+
if (list.length === 0) {
|
|
493
|
+
return Buffer2.alloc(0);
|
|
494
|
+
}
|
|
495
|
+
let i;
|
|
496
|
+
if (length === void 0) {
|
|
497
|
+
length = 0;
|
|
498
|
+
for (i = 0; i < list.length; ++i) {
|
|
499
|
+
length += list[i].length;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
const buffer2 = Buffer2.allocUnsafe(length);
|
|
503
|
+
let pos = 0;
|
|
504
|
+
for (i = 0; i < list.length; ++i) {
|
|
505
|
+
let buf = list[i];
|
|
506
|
+
if (isInstance(buf, Uint8Array)) {
|
|
507
|
+
if (pos + buf.length > buffer2.length) {
|
|
508
|
+
if (!Buffer2.isBuffer(buf)) buf = Buffer2.from(buf);
|
|
509
|
+
buf.copy(buffer2, pos);
|
|
510
|
+
} else {
|
|
511
|
+
Uint8Array.prototype.set.call(
|
|
512
|
+
buffer2,
|
|
513
|
+
buf,
|
|
514
|
+
pos
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
} else if (!Buffer2.isBuffer(buf)) {
|
|
518
|
+
throw new TypeError('"list" argument must be an Array of Buffers');
|
|
519
|
+
} else {
|
|
520
|
+
buf.copy(buffer2, pos);
|
|
521
|
+
}
|
|
522
|
+
pos += buf.length;
|
|
523
|
+
}
|
|
524
|
+
return buffer2;
|
|
525
|
+
};
|
|
526
|
+
function byteLength(string, encoding) {
|
|
527
|
+
if (Buffer2.isBuffer(string)) {
|
|
528
|
+
return string.length;
|
|
529
|
+
}
|
|
530
|
+
if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
|
|
531
|
+
return string.byteLength;
|
|
532
|
+
}
|
|
533
|
+
if (typeof string !== "string") {
|
|
534
|
+
throw new TypeError(
|
|
535
|
+
'The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type ' + typeof string
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
const len = string.length;
|
|
539
|
+
const mustMatch = arguments.length > 2 && arguments[2] === true;
|
|
540
|
+
if (!mustMatch && len === 0) return 0;
|
|
541
|
+
let loweredCase = false;
|
|
542
|
+
for (; ; ) {
|
|
543
|
+
switch (encoding) {
|
|
544
|
+
case "ascii":
|
|
545
|
+
case "latin1":
|
|
546
|
+
case "binary":
|
|
547
|
+
return len;
|
|
548
|
+
case "utf8":
|
|
549
|
+
case "utf-8":
|
|
550
|
+
return utf8ToBytes(string).length;
|
|
551
|
+
case "ucs2":
|
|
552
|
+
case "ucs-2":
|
|
553
|
+
case "utf16le":
|
|
554
|
+
case "utf-16le":
|
|
555
|
+
return len * 2;
|
|
556
|
+
case "hex":
|
|
557
|
+
return len >>> 1;
|
|
558
|
+
case "base64":
|
|
559
|
+
return base64ToBytes(string).length;
|
|
560
|
+
default:
|
|
561
|
+
if (loweredCase) {
|
|
562
|
+
return mustMatch ? -1 : utf8ToBytes(string).length;
|
|
563
|
+
}
|
|
564
|
+
encoding = ("" + encoding).toLowerCase();
|
|
565
|
+
loweredCase = true;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
Buffer2.byteLength = byteLength;
|
|
570
|
+
function slowToString(encoding, start, end) {
|
|
571
|
+
let loweredCase = false;
|
|
572
|
+
if (start === void 0 || start < 0) {
|
|
573
|
+
start = 0;
|
|
574
|
+
}
|
|
575
|
+
if (start > this.length) {
|
|
576
|
+
return "";
|
|
577
|
+
}
|
|
578
|
+
if (end === void 0 || end > this.length) {
|
|
579
|
+
end = this.length;
|
|
580
|
+
}
|
|
581
|
+
if (end <= 0) {
|
|
582
|
+
return "";
|
|
583
|
+
}
|
|
584
|
+
end >>>= 0;
|
|
585
|
+
start >>>= 0;
|
|
586
|
+
if (end <= start) {
|
|
587
|
+
return "";
|
|
588
|
+
}
|
|
589
|
+
if (!encoding) encoding = "utf8";
|
|
590
|
+
while (true) {
|
|
591
|
+
switch (encoding) {
|
|
592
|
+
case "hex":
|
|
593
|
+
return hexSlice(this, start, end);
|
|
594
|
+
case "utf8":
|
|
595
|
+
case "utf-8":
|
|
596
|
+
return utf8Slice(this, start, end);
|
|
597
|
+
case "ascii":
|
|
598
|
+
return asciiSlice(this, start, end);
|
|
599
|
+
case "latin1":
|
|
600
|
+
case "binary":
|
|
601
|
+
return latin1Slice(this, start, end);
|
|
602
|
+
case "base64":
|
|
603
|
+
return base64Slice(this, start, end);
|
|
604
|
+
case "ucs2":
|
|
605
|
+
case "ucs-2":
|
|
606
|
+
case "utf16le":
|
|
607
|
+
case "utf-16le":
|
|
608
|
+
return utf16leSlice(this, start, end);
|
|
609
|
+
default:
|
|
610
|
+
if (loweredCase) throw new TypeError("Unknown encoding: " + encoding);
|
|
611
|
+
encoding = (encoding + "").toLowerCase();
|
|
612
|
+
loweredCase = true;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
Buffer2.prototype._isBuffer = true;
|
|
617
|
+
function swap(b, n, m) {
|
|
618
|
+
const i = b[n];
|
|
619
|
+
b[n] = b[m];
|
|
620
|
+
b[m] = i;
|
|
621
|
+
}
|
|
622
|
+
Buffer2.prototype.swap16 = function swap16() {
|
|
623
|
+
const len = this.length;
|
|
624
|
+
if (len % 2 !== 0) {
|
|
625
|
+
throw new RangeError("Buffer size must be a multiple of 16-bits");
|
|
626
|
+
}
|
|
627
|
+
for (let i = 0; i < len; i += 2) {
|
|
628
|
+
swap(this, i, i + 1);
|
|
629
|
+
}
|
|
630
|
+
return this;
|
|
631
|
+
};
|
|
632
|
+
Buffer2.prototype.swap32 = function swap32() {
|
|
633
|
+
const len = this.length;
|
|
634
|
+
if (len % 4 !== 0) {
|
|
635
|
+
throw new RangeError("Buffer size must be a multiple of 32-bits");
|
|
636
|
+
}
|
|
637
|
+
for (let i = 0; i < len; i += 4) {
|
|
638
|
+
swap(this, i, i + 3);
|
|
639
|
+
swap(this, i + 1, i + 2);
|
|
640
|
+
}
|
|
641
|
+
return this;
|
|
642
|
+
};
|
|
643
|
+
Buffer2.prototype.swap64 = function swap64() {
|
|
644
|
+
const len = this.length;
|
|
645
|
+
if (len % 8 !== 0) {
|
|
646
|
+
throw new RangeError("Buffer size must be a multiple of 64-bits");
|
|
647
|
+
}
|
|
648
|
+
for (let i = 0; i < len; i += 8) {
|
|
649
|
+
swap(this, i, i + 7);
|
|
650
|
+
swap(this, i + 1, i + 6);
|
|
651
|
+
swap(this, i + 2, i + 5);
|
|
652
|
+
swap(this, i + 3, i + 4);
|
|
653
|
+
}
|
|
654
|
+
return this;
|
|
655
|
+
};
|
|
656
|
+
Buffer2.prototype.toString = function toString() {
|
|
657
|
+
const length = this.length;
|
|
658
|
+
if (length === 0) return "";
|
|
659
|
+
if (arguments.length === 0) return utf8Slice(this, 0, length);
|
|
660
|
+
return slowToString.apply(this, arguments);
|
|
661
|
+
};
|
|
662
|
+
Buffer2.prototype.toLocaleString = Buffer2.prototype.toString;
|
|
663
|
+
Buffer2.prototype.equals = function equals(b) {
|
|
664
|
+
if (!Buffer2.isBuffer(b)) throw new TypeError("Argument must be a Buffer");
|
|
665
|
+
if (this === b) return true;
|
|
666
|
+
return Buffer2.compare(this, b) === 0;
|
|
667
|
+
};
|
|
668
|
+
Buffer2.prototype.inspect = function inspect() {
|
|
669
|
+
let str = "";
|
|
670
|
+
const max = exports.INSPECT_MAX_BYTES;
|
|
671
|
+
str = this.toString("hex", 0, max).replace(/(.{2})/g, "$1 ").trim();
|
|
672
|
+
if (this.length > max) str += " ... ";
|
|
673
|
+
return "<Buffer " + str + ">";
|
|
674
|
+
};
|
|
675
|
+
if (customInspectSymbol) {
|
|
676
|
+
Buffer2.prototype[customInspectSymbol] = Buffer2.prototype.inspect;
|
|
677
|
+
}
|
|
678
|
+
Buffer2.prototype.compare = function compare(target, start, end, thisStart, thisEnd) {
|
|
679
|
+
if (isInstance(target, Uint8Array)) {
|
|
680
|
+
target = Buffer2.from(target, target.offset, target.byteLength);
|
|
681
|
+
}
|
|
682
|
+
if (!Buffer2.isBuffer(target)) {
|
|
683
|
+
throw new TypeError(
|
|
684
|
+
'The "target" argument must be one of type Buffer or Uint8Array. Received type ' + typeof target
|
|
685
|
+
);
|
|
686
|
+
}
|
|
687
|
+
if (start === void 0) {
|
|
688
|
+
start = 0;
|
|
689
|
+
}
|
|
690
|
+
if (end === void 0) {
|
|
691
|
+
end = target ? target.length : 0;
|
|
692
|
+
}
|
|
693
|
+
if (thisStart === void 0) {
|
|
694
|
+
thisStart = 0;
|
|
695
|
+
}
|
|
696
|
+
if (thisEnd === void 0) {
|
|
697
|
+
thisEnd = this.length;
|
|
698
|
+
}
|
|
699
|
+
if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
|
|
700
|
+
throw new RangeError("out of range index");
|
|
701
|
+
}
|
|
702
|
+
if (thisStart >= thisEnd && start >= end) {
|
|
703
|
+
return 0;
|
|
704
|
+
}
|
|
705
|
+
if (thisStart >= thisEnd) {
|
|
706
|
+
return -1;
|
|
707
|
+
}
|
|
708
|
+
if (start >= end) {
|
|
709
|
+
return 1;
|
|
710
|
+
}
|
|
711
|
+
start >>>= 0;
|
|
712
|
+
end >>>= 0;
|
|
713
|
+
thisStart >>>= 0;
|
|
714
|
+
thisEnd >>>= 0;
|
|
715
|
+
if (this === target) return 0;
|
|
716
|
+
let x = thisEnd - thisStart;
|
|
717
|
+
let y = end - start;
|
|
718
|
+
const len = Math.min(x, y);
|
|
719
|
+
const thisCopy = this.slice(thisStart, thisEnd);
|
|
720
|
+
const targetCopy = target.slice(start, end);
|
|
721
|
+
for (let i = 0; i < len; ++i) {
|
|
722
|
+
if (thisCopy[i] !== targetCopy[i]) {
|
|
723
|
+
x = thisCopy[i];
|
|
724
|
+
y = targetCopy[i];
|
|
725
|
+
break;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
if (x < y) return -1;
|
|
729
|
+
if (y < x) return 1;
|
|
730
|
+
return 0;
|
|
731
|
+
};
|
|
732
|
+
function bidirectionalIndexOf(buffer2, val, byteOffset, encoding, dir) {
|
|
733
|
+
if (buffer2.length === 0) return -1;
|
|
734
|
+
if (typeof byteOffset === "string") {
|
|
735
|
+
encoding = byteOffset;
|
|
736
|
+
byteOffset = 0;
|
|
737
|
+
} else if (byteOffset > 2147483647) {
|
|
738
|
+
byteOffset = 2147483647;
|
|
739
|
+
} else if (byteOffset < -2147483648) {
|
|
740
|
+
byteOffset = -2147483648;
|
|
741
|
+
}
|
|
742
|
+
byteOffset = +byteOffset;
|
|
743
|
+
if (numberIsNaN(byteOffset)) {
|
|
744
|
+
byteOffset = dir ? 0 : buffer2.length - 1;
|
|
745
|
+
}
|
|
746
|
+
if (byteOffset < 0) byteOffset = buffer2.length + byteOffset;
|
|
747
|
+
if (byteOffset >= buffer2.length) {
|
|
748
|
+
if (dir) return -1;
|
|
749
|
+
else byteOffset = buffer2.length - 1;
|
|
750
|
+
} else if (byteOffset < 0) {
|
|
751
|
+
if (dir) byteOffset = 0;
|
|
752
|
+
else return -1;
|
|
753
|
+
}
|
|
754
|
+
if (typeof val === "string") {
|
|
755
|
+
val = Buffer2.from(val, encoding);
|
|
756
|
+
}
|
|
757
|
+
if (Buffer2.isBuffer(val)) {
|
|
758
|
+
if (val.length === 0) {
|
|
759
|
+
return -1;
|
|
760
|
+
}
|
|
761
|
+
return arrayIndexOf(buffer2, val, byteOffset, encoding, dir);
|
|
762
|
+
} else if (typeof val === "number") {
|
|
763
|
+
val = val & 255;
|
|
764
|
+
if (typeof Uint8Array.prototype.indexOf === "function") {
|
|
765
|
+
if (dir) {
|
|
766
|
+
return Uint8Array.prototype.indexOf.call(buffer2, val, byteOffset);
|
|
767
|
+
} else {
|
|
768
|
+
return Uint8Array.prototype.lastIndexOf.call(buffer2, val, byteOffset);
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
return arrayIndexOf(buffer2, [val], byteOffset, encoding, dir);
|
|
772
|
+
}
|
|
773
|
+
throw new TypeError("val must be string, number or Buffer");
|
|
774
|
+
}
|
|
775
|
+
function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
|
|
776
|
+
let indexSize = 1;
|
|
777
|
+
let arrLength = arr.length;
|
|
778
|
+
let valLength = val.length;
|
|
779
|
+
if (encoding !== void 0) {
|
|
780
|
+
encoding = String(encoding).toLowerCase();
|
|
781
|
+
if (encoding === "ucs2" || encoding === "ucs-2" || encoding === "utf16le" || encoding === "utf-16le") {
|
|
782
|
+
if (arr.length < 2 || val.length < 2) {
|
|
783
|
+
return -1;
|
|
784
|
+
}
|
|
785
|
+
indexSize = 2;
|
|
786
|
+
arrLength /= 2;
|
|
787
|
+
valLength /= 2;
|
|
788
|
+
byteOffset /= 2;
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
function read(buf, i2) {
|
|
792
|
+
if (indexSize === 1) {
|
|
793
|
+
return buf[i2];
|
|
794
|
+
} else {
|
|
795
|
+
return buf.readUInt16BE(i2 * indexSize);
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
let i;
|
|
799
|
+
if (dir) {
|
|
800
|
+
let foundIndex = -1;
|
|
801
|
+
for (i = byteOffset; i < arrLength; i++) {
|
|
802
|
+
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
|
803
|
+
if (foundIndex === -1) foundIndex = i;
|
|
804
|
+
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize;
|
|
805
|
+
} else {
|
|
806
|
+
if (foundIndex !== -1) i -= i - foundIndex;
|
|
807
|
+
foundIndex = -1;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
} else {
|
|
811
|
+
if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
|
|
812
|
+
for (i = byteOffset; i >= 0; i--) {
|
|
813
|
+
let found = true;
|
|
814
|
+
for (let j = 0; j < valLength; j++) {
|
|
815
|
+
if (read(arr, i + j) !== read(val, j)) {
|
|
816
|
+
found = false;
|
|
817
|
+
break;
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
if (found) return i;
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
return -1;
|
|
824
|
+
}
|
|
825
|
+
Buffer2.prototype.includes = function includes(val, byteOffset, encoding) {
|
|
826
|
+
return this.indexOf(val, byteOffset, encoding) !== -1;
|
|
827
|
+
};
|
|
828
|
+
Buffer2.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
|
|
829
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, true);
|
|
830
|
+
};
|
|
831
|
+
Buffer2.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {
|
|
832
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, false);
|
|
833
|
+
};
|
|
834
|
+
function hexWrite(buf, string, offset, length) {
|
|
835
|
+
offset = Number(offset) || 0;
|
|
836
|
+
const remaining = buf.length - offset;
|
|
837
|
+
if (!length) {
|
|
838
|
+
length = remaining;
|
|
839
|
+
} else {
|
|
840
|
+
length = Number(length);
|
|
841
|
+
if (length > remaining) {
|
|
842
|
+
length = remaining;
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
const strLen = string.length;
|
|
846
|
+
if (length > strLen / 2) {
|
|
847
|
+
length = strLen / 2;
|
|
848
|
+
}
|
|
849
|
+
let i;
|
|
850
|
+
for (i = 0; i < length; ++i) {
|
|
851
|
+
const parsed = parseInt(string.substr(i * 2, 2), 16);
|
|
852
|
+
if (numberIsNaN(parsed)) return i;
|
|
853
|
+
buf[offset + i] = parsed;
|
|
854
|
+
}
|
|
855
|
+
return i;
|
|
856
|
+
}
|
|
857
|
+
function utf8Write(buf, string, offset, length) {
|
|
858
|
+
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length);
|
|
859
|
+
}
|
|
860
|
+
function asciiWrite(buf, string, offset, length) {
|
|
861
|
+
return blitBuffer(asciiToBytes(string), buf, offset, length);
|
|
862
|
+
}
|
|
863
|
+
function base64Write(buf, string, offset, length) {
|
|
864
|
+
return blitBuffer(base64ToBytes(string), buf, offset, length);
|
|
865
|
+
}
|
|
866
|
+
function ucs2Write(buf, string, offset, length) {
|
|
867
|
+
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length);
|
|
868
|
+
}
|
|
869
|
+
Buffer2.prototype.write = function write(string, offset, length, encoding) {
|
|
870
|
+
if (offset === void 0) {
|
|
871
|
+
encoding = "utf8";
|
|
872
|
+
length = this.length;
|
|
873
|
+
offset = 0;
|
|
874
|
+
} else if (length === void 0 && typeof offset === "string") {
|
|
875
|
+
encoding = offset;
|
|
876
|
+
length = this.length;
|
|
877
|
+
offset = 0;
|
|
878
|
+
} else if (isFinite(offset)) {
|
|
879
|
+
offset = offset >>> 0;
|
|
880
|
+
if (isFinite(length)) {
|
|
881
|
+
length = length >>> 0;
|
|
882
|
+
if (encoding === void 0) encoding = "utf8";
|
|
883
|
+
} else {
|
|
884
|
+
encoding = length;
|
|
885
|
+
length = void 0;
|
|
886
|
+
}
|
|
887
|
+
} else {
|
|
888
|
+
throw new Error(
|
|
889
|
+
"Buffer.write(string, encoding, offset[, length]) is no longer supported"
|
|
890
|
+
);
|
|
891
|
+
}
|
|
892
|
+
const remaining = this.length - offset;
|
|
893
|
+
if (length === void 0 || length > remaining) length = remaining;
|
|
894
|
+
if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) {
|
|
895
|
+
throw new RangeError("Attempt to write outside buffer bounds");
|
|
896
|
+
}
|
|
897
|
+
if (!encoding) encoding = "utf8";
|
|
898
|
+
let loweredCase = false;
|
|
899
|
+
for (; ; ) {
|
|
900
|
+
switch (encoding) {
|
|
901
|
+
case "hex":
|
|
902
|
+
return hexWrite(this, string, offset, length);
|
|
903
|
+
case "utf8":
|
|
904
|
+
case "utf-8":
|
|
905
|
+
return utf8Write(this, string, offset, length);
|
|
906
|
+
case "ascii":
|
|
907
|
+
case "latin1":
|
|
908
|
+
case "binary":
|
|
909
|
+
return asciiWrite(this, string, offset, length);
|
|
910
|
+
case "base64":
|
|
911
|
+
return base64Write(this, string, offset, length);
|
|
912
|
+
case "ucs2":
|
|
913
|
+
case "ucs-2":
|
|
914
|
+
case "utf16le":
|
|
915
|
+
case "utf-16le":
|
|
916
|
+
return ucs2Write(this, string, offset, length);
|
|
917
|
+
default:
|
|
918
|
+
if (loweredCase) throw new TypeError("Unknown encoding: " + encoding);
|
|
919
|
+
encoding = ("" + encoding).toLowerCase();
|
|
920
|
+
loweredCase = true;
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
};
|
|
924
|
+
Buffer2.prototype.toJSON = function toJSON() {
|
|
925
|
+
return {
|
|
926
|
+
type: "Buffer",
|
|
927
|
+
data: Array.prototype.slice.call(this._arr || this, 0)
|
|
928
|
+
};
|
|
929
|
+
};
|
|
930
|
+
function base64Slice(buf, start, end) {
|
|
931
|
+
if (start === 0 && end === buf.length) {
|
|
932
|
+
return base64.fromByteArray(buf);
|
|
933
|
+
} else {
|
|
934
|
+
return base64.fromByteArray(buf.slice(start, end));
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
function utf8Slice(buf, start, end) {
|
|
938
|
+
end = Math.min(buf.length, end);
|
|
939
|
+
const res = [];
|
|
940
|
+
let i = start;
|
|
941
|
+
while (i < end) {
|
|
942
|
+
const firstByte = buf[i];
|
|
943
|
+
let codePoint = null;
|
|
944
|
+
let bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1;
|
|
945
|
+
if (i + bytesPerSequence <= end) {
|
|
946
|
+
let secondByte, thirdByte, fourthByte, tempCodePoint;
|
|
947
|
+
switch (bytesPerSequence) {
|
|
948
|
+
case 1:
|
|
949
|
+
if (firstByte < 128) {
|
|
950
|
+
codePoint = firstByte;
|
|
951
|
+
}
|
|
952
|
+
break;
|
|
953
|
+
case 2:
|
|
954
|
+
secondByte = buf[i + 1];
|
|
955
|
+
if ((secondByte & 192) === 128) {
|
|
956
|
+
tempCodePoint = (firstByte & 31) << 6 | secondByte & 63;
|
|
957
|
+
if (tempCodePoint > 127) {
|
|
958
|
+
codePoint = tempCodePoint;
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
break;
|
|
962
|
+
case 3:
|
|
963
|
+
secondByte = buf[i + 1];
|
|
964
|
+
thirdByte = buf[i + 2];
|
|
965
|
+
if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) {
|
|
966
|
+
tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63;
|
|
967
|
+
if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) {
|
|
968
|
+
codePoint = tempCodePoint;
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
break;
|
|
972
|
+
case 4:
|
|
973
|
+
secondByte = buf[i + 1];
|
|
974
|
+
thirdByte = buf[i + 2];
|
|
975
|
+
fourthByte = buf[i + 3];
|
|
976
|
+
if ((secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) {
|
|
977
|
+
tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63;
|
|
978
|
+
if (tempCodePoint > 65535 && tempCodePoint < 1114112) {
|
|
979
|
+
codePoint = tempCodePoint;
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
if (codePoint === null) {
|
|
985
|
+
codePoint = 65533;
|
|
986
|
+
bytesPerSequence = 1;
|
|
987
|
+
} else if (codePoint > 65535) {
|
|
988
|
+
codePoint -= 65536;
|
|
989
|
+
res.push(codePoint >>> 10 & 1023 | 55296);
|
|
990
|
+
codePoint = 56320 | codePoint & 1023;
|
|
991
|
+
}
|
|
992
|
+
res.push(codePoint);
|
|
993
|
+
i += bytesPerSequence;
|
|
994
|
+
}
|
|
995
|
+
return decodeCodePointsArray(res);
|
|
996
|
+
}
|
|
997
|
+
const MAX_ARGUMENTS_LENGTH = 4096;
|
|
998
|
+
function decodeCodePointsArray(codePoints) {
|
|
999
|
+
const len = codePoints.length;
|
|
1000
|
+
if (len <= MAX_ARGUMENTS_LENGTH) {
|
|
1001
|
+
return String.fromCharCode.apply(String, codePoints);
|
|
1002
|
+
}
|
|
1003
|
+
let res = "";
|
|
1004
|
+
let i = 0;
|
|
1005
|
+
while (i < len) {
|
|
1006
|
+
res += String.fromCharCode.apply(
|
|
1007
|
+
String,
|
|
1008
|
+
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
|
|
1009
|
+
);
|
|
1010
|
+
}
|
|
1011
|
+
return res;
|
|
1012
|
+
}
|
|
1013
|
+
function asciiSlice(buf, start, end) {
|
|
1014
|
+
let ret = "";
|
|
1015
|
+
end = Math.min(buf.length, end);
|
|
1016
|
+
for (let i = start; i < end; ++i) {
|
|
1017
|
+
ret += String.fromCharCode(buf[i] & 127);
|
|
1018
|
+
}
|
|
1019
|
+
return ret;
|
|
1020
|
+
}
|
|
1021
|
+
function latin1Slice(buf, start, end) {
|
|
1022
|
+
let ret = "";
|
|
1023
|
+
end = Math.min(buf.length, end);
|
|
1024
|
+
for (let i = start; i < end; ++i) {
|
|
1025
|
+
ret += String.fromCharCode(buf[i]);
|
|
1026
|
+
}
|
|
1027
|
+
return ret;
|
|
1028
|
+
}
|
|
1029
|
+
function hexSlice(buf, start, end) {
|
|
1030
|
+
const len = buf.length;
|
|
1031
|
+
if (!start || start < 0) start = 0;
|
|
1032
|
+
if (!end || end < 0 || end > len) end = len;
|
|
1033
|
+
let out = "";
|
|
1034
|
+
for (let i = start; i < end; ++i) {
|
|
1035
|
+
out += hexSliceLookupTable[buf[i]];
|
|
1036
|
+
}
|
|
1037
|
+
return out;
|
|
1038
|
+
}
|
|
1039
|
+
function utf16leSlice(buf, start, end) {
|
|
1040
|
+
const bytes = buf.slice(start, end);
|
|
1041
|
+
let res = "";
|
|
1042
|
+
for (let i = 0; i < bytes.length - 1; i += 2) {
|
|
1043
|
+
res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
|
|
1044
|
+
}
|
|
1045
|
+
return res;
|
|
1046
|
+
}
|
|
1047
|
+
Buffer2.prototype.slice = function slice(start, end) {
|
|
1048
|
+
const len = this.length;
|
|
1049
|
+
start = ~~start;
|
|
1050
|
+
end = end === void 0 ? len : ~~end;
|
|
1051
|
+
if (start < 0) {
|
|
1052
|
+
start += len;
|
|
1053
|
+
if (start < 0) start = 0;
|
|
1054
|
+
} else if (start > len) {
|
|
1055
|
+
start = len;
|
|
1056
|
+
}
|
|
1057
|
+
if (end < 0) {
|
|
1058
|
+
end += len;
|
|
1059
|
+
if (end < 0) end = 0;
|
|
1060
|
+
} else if (end > len) {
|
|
1061
|
+
end = len;
|
|
1062
|
+
}
|
|
1063
|
+
if (end < start) end = start;
|
|
1064
|
+
const newBuf = this.subarray(start, end);
|
|
1065
|
+
Object.setPrototypeOf(newBuf, Buffer2.prototype);
|
|
1066
|
+
return newBuf;
|
|
1067
|
+
};
|
|
1068
|
+
function checkOffset(offset, ext, length) {
|
|
1069
|
+
if (offset % 1 !== 0 || offset < 0) throw new RangeError("offset is not uint");
|
|
1070
|
+
if (offset + ext > length) throw new RangeError("Trying to access beyond buffer length");
|
|
1071
|
+
}
|
|
1072
|
+
Buffer2.prototype.readUintLE = Buffer2.prototype.readUIntLE = function readUIntLE(offset, byteLength2, noAssert) {
|
|
1073
|
+
offset = offset >>> 0;
|
|
1074
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1075
|
+
if (!noAssert) checkOffset(offset, byteLength2, this.length);
|
|
1076
|
+
let val = this[offset];
|
|
1077
|
+
let mul = 1;
|
|
1078
|
+
let i = 0;
|
|
1079
|
+
while (++i < byteLength2 && (mul *= 256)) {
|
|
1080
|
+
val += this[offset + i] * mul;
|
|
1081
|
+
}
|
|
1082
|
+
return val;
|
|
1083
|
+
};
|
|
1084
|
+
Buffer2.prototype.readUintBE = Buffer2.prototype.readUIntBE = function readUIntBE(offset, byteLength2, noAssert) {
|
|
1085
|
+
offset = offset >>> 0;
|
|
1086
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1087
|
+
if (!noAssert) {
|
|
1088
|
+
checkOffset(offset, byteLength2, this.length);
|
|
1089
|
+
}
|
|
1090
|
+
let val = this[offset + --byteLength2];
|
|
1091
|
+
let mul = 1;
|
|
1092
|
+
while (byteLength2 > 0 && (mul *= 256)) {
|
|
1093
|
+
val += this[offset + --byteLength2] * mul;
|
|
1094
|
+
}
|
|
1095
|
+
return val;
|
|
1096
|
+
};
|
|
1097
|
+
Buffer2.prototype.readUint8 = Buffer2.prototype.readUInt8 = function readUInt8(offset, noAssert) {
|
|
1098
|
+
offset = offset >>> 0;
|
|
1099
|
+
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
1100
|
+
return this[offset];
|
|
1101
|
+
};
|
|
1102
|
+
Buffer2.prototype.readUint16LE = Buffer2.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) {
|
|
1103
|
+
offset = offset >>> 0;
|
|
1104
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1105
|
+
return this[offset] | this[offset + 1] << 8;
|
|
1106
|
+
};
|
|
1107
|
+
Buffer2.prototype.readUint16BE = Buffer2.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) {
|
|
1108
|
+
offset = offset >>> 0;
|
|
1109
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1110
|
+
return this[offset] << 8 | this[offset + 1];
|
|
1111
|
+
};
|
|
1112
|
+
Buffer2.prototype.readUint32LE = Buffer2.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) {
|
|
1113
|
+
offset = offset >>> 0;
|
|
1114
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1115
|
+
return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 16777216;
|
|
1116
|
+
};
|
|
1117
|
+
Buffer2.prototype.readUint32BE = Buffer2.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {
|
|
1118
|
+
offset = offset >>> 0;
|
|
1119
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1120
|
+
return this[offset] * 16777216 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]);
|
|
1121
|
+
};
|
|
1122
|
+
Buffer2.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE(offset) {
|
|
1123
|
+
offset = offset >>> 0;
|
|
1124
|
+
validateNumber(offset, "offset");
|
|
1125
|
+
const first = this[offset];
|
|
1126
|
+
const last = this[offset + 7];
|
|
1127
|
+
if (first === void 0 || last === void 0) {
|
|
1128
|
+
boundsError(offset, this.length - 8);
|
|
1129
|
+
}
|
|
1130
|
+
const lo = first + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 24;
|
|
1131
|
+
const hi = this[++offset] + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + last * 2 ** 24;
|
|
1132
|
+
return BigInt(lo) + (BigInt(hi) << BigInt(32));
|
|
1133
|
+
});
|
|
1134
|
+
Buffer2.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE(offset) {
|
|
1135
|
+
offset = offset >>> 0;
|
|
1136
|
+
validateNumber(offset, "offset");
|
|
1137
|
+
const first = this[offset];
|
|
1138
|
+
const last = this[offset + 7];
|
|
1139
|
+
if (first === void 0 || last === void 0) {
|
|
1140
|
+
boundsError(offset, this.length - 8);
|
|
1141
|
+
}
|
|
1142
|
+
const hi = first * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + this[++offset];
|
|
1143
|
+
const lo = this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last;
|
|
1144
|
+
return (BigInt(hi) << BigInt(32)) + BigInt(lo);
|
|
1145
|
+
});
|
|
1146
|
+
Buffer2.prototype.readIntLE = function readIntLE(offset, byteLength2, noAssert) {
|
|
1147
|
+
offset = offset >>> 0;
|
|
1148
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1149
|
+
if (!noAssert) checkOffset(offset, byteLength2, this.length);
|
|
1150
|
+
let val = this[offset];
|
|
1151
|
+
let mul = 1;
|
|
1152
|
+
let i = 0;
|
|
1153
|
+
while (++i < byteLength2 && (mul *= 256)) {
|
|
1154
|
+
val += this[offset + i] * mul;
|
|
1155
|
+
}
|
|
1156
|
+
mul *= 128;
|
|
1157
|
+
if (val >= mul) val -= Math.pow(2, 8 * byteLength2);
|
|
1158
|
+
return val;
|
|
1159
|
+
};
|
|
1160
|
+
Buffer2.prototype.readIntBE = function readIntBE(offset, byteLength2, noAssert) {
|
|
1161
|
+
offset = offset >>> 0;
|
|
1162
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1163
|
+
if (!noAssert) checkOffset(offset, byteLength2, this.length);
|
|
1164
|
+
let i = byteLength2;
|
|
1165
|
+
let mul = 1;
|
|
1166
|
+
let val = this[offset + --i];
|
|
1167
|
+
while (i > 0 && (mul *= 256)) {
|
|
1168
|
+
val += this[offset + --i] * mul;
|
|
1169
|
+
}
|
|
1170
|
+
mul *= 128;
|
|
1171
|
+
if (val >= mul) val -= Math.pow(2, 8 * byteLength2);
|
|
1172
|
+
return val;
|
|
1173
|
+
};
|
|
1174
|
+
Buffer2.prototype.readInt8 = function readInt8(offset, noAssert) {
|
|
1175
|
+
offset = offset >>> 0;
|
|
1176
|
+
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
1177
|
+
if (!(this[offset] & 128)) return this[offset];
|
|
1178
|
+
return (255 - this[offset] + 1) * -1;
|
|
1179
|
+
};
|
|
1180
|
+
Buffer2.prototype.readInt16LE = function readInt16LE(offset, noAssert) {
|
|
1181
|
+
offset = offset >>> 0;
|
|
1182
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1183
|
+
const val = this[offset] | this[offset + 1] << 8;
|
|
1184
|
+
return val & 32768 ? val | 4294901760 : val;
|
|
1185
|
+
};
|
|
1186
|
+
Buffer2.prototype.readInt16BE = function readInt16BE(offset, noAssert) {
|
|
1187
|
+
offset = offset >>> 0;
|
|
1188
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1189
|
+
const val = this[offset + 1] | this[offset] << 8;
|
|
1190
|
+
return val & 32768 ? val | 4294901760 : val;
|
|
1191
|
+
};
|
|
1192
|
+
Buffer2.prototype.readInt32LE = function readInt32LE(offset, noAssert) {
|
|
1193
|
+
offset = offset >>> 0;
|
|
1194
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1195
|
+
return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24;
|
|
1196
|
+
};
|
|
1197
|
+
Buffer2.prototype.readInt32BE = function readInt32BE(offset, noAssert) {
|
|
1198
|
+
offset = offset >>> 0;
|
|
1199
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1200
|
+
return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3];
|
|
1201
|
+
};
|
|
1202
|
+
Buffer2.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE(offset) {
|
|
1203
|
+
offset = offset >>> 0;
|
|
1204
|
+
validateNumber(offset, "offset");
|
|
1205
|
+
const first = this[offset];
|
|
1206
|
+
const last = this[offset + 7];
|
|
1207
|
+
if (first === void 0 || last === void 0) {
|
|
1208
|
+
boundsError(offset, this.length - 8);
|
|
1209
|
+
}
|
|
1210
|
+
const val = this[offset + 4] + this[offset + 5] * 2 ** 8 + this[offset + 6] * 2 ** 16 + (last << 24);
|
|
1211
|
+
return (BigInt(val) << BigInt(32)) + BigInt(first + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 24);
|
|
1212
|
+
});
|
|
1213
|
+
Buffer2.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE(offset) {
|
|
1214
|
+
offset = offset >>> 0;
|
|
1215
|
+
validateNumber(offset, "offset");
|
|
1216
|
+
const first = this[offset];
|
|
1217
|
+
const last = this[offset + 7];
|
|
1218
|
+
if (first === void 0 || last === void 0) {
|
|
1219
|
+
boundsError(offset, this.length - 8);
|
|
1220
|
+
}
|
|
1221
|
+
const val = (first << 24) + // Overflow
|
|
1222
|
+
this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + this[++offset];
|
|
1223
|
+
return (BigInt(val) << BigInt(32)) + BigInt(this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last);
|
|
1224
|
+
});
|
|
1225
|
+
Buffer2.prototype.readFloatLE = function readFloatLE(offset, noAssert) {
|
|
1226
|
+
offset = offset >>> 0;
|
|
1227
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1228
|
+
return ieee7542.read(this, offset, true, 23, 4);
|
|
1229
|
+
};
|
|
1230
|
+
Buffer2.prototype.readFloatBE = function readFloatBE(offset, noAssert) {
|
|
1231
|
+
offset = offset >>> 0;
|
|
1232
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1233
|
+
return ieee7542.read(this, offset, false, 23, 4);
|
|
1234
|
+
};
|
|
1235
|
+
Buffer2.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) {
|
|
1236
|
+
offset = offset >>> 0;
|
|
1237
|
+
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
1238
|
+
return ieee7542.read(this, offset, true, 52, 8);
|
|
1239
|
+
};
|
|
1240
|
+
Buffer2.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {
|
|
1241
|
+
offset = offset >>> 0;
|
|
1242
|
+
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
1243
|
+
return ieee7542.read(this, offset, false, 52, 8);
|
|
1244
|
+
};
|
|
1245
|
+
function checkInt(buf, value, offset, ext, max, min) {
|
|
1246
|
+
if (!Buffer2.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance');
|
|
1247
|
+
if (value > max || value < min) throw new RangeError('"value" argument is out of bounds');
|
|
1248
|
+
if (offset + ext > buf.length) throw new RangeError("Index out of range");
|
|
1249
|
+
}
|
|
1250
|
+
Buffer2.prototype.writeUintLE = Buffer2.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength2, noAssert) {
|
|
1251
|
+
value = +value;
|
|
1252
|
+
offset = offset >>> 0;
|
|
1253
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1254
|
+
if (!noAssert) {
|
|
1255
|
+
const maxBytes = Math.pow(2, 8 * byteLength2) - 1;
|
|
1256
|
+
checkInt(this, value, offset, byteLength2, maxBytes, 0);
|
|
1257
|
+
}
|
|
1258
|
+
let mul = 1;
|
|
1259
|
+
let i = 0;
|
|
1260
|
+
this[offset] = value & 255;
|
|
1261
|
+
while (++i < byteLength2 && (mul *= 256)) {
|
|
1262
|
+
this[offset + i] = value / mul & 255;
|
|
1263
|
+
}
|
|
1264
|
+
return offset + byteLength2;
|
|
1265
|
+
};
|
|
1266
|
+
Buffer2.prototype.writeUintBE = Buffer2.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength2, noAssert) {
|
|
1267
|
+
value = +value;
|
|
1268
|
+
offset = offset >>> 0;
|
|
1269
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1270
|
+
if (!noAssert) {
|
|
1271
|
+
const maxBytes = Math.pow(2, 8 * byteLength2) - 1;
|
|
1272
|
+
checkInt(this, value, offset, byteLength2, maxBytes, 0);
|
|
1273
|
+
}
|
|
1274
|
+
let i = byteLength2 - 1;
|
|
1275
|
+
let mul = 1;
|
|
1276
|
+
this[offset + i] = value & 255;
|
|
1277
|
+
while (--i >= 0 && (mul *= 256)) {
|
|
1278
|
+
this[offset + i] = value / mul & 255;
|
|
1279
|
+
}
|
|
1280
|
+
return offset + byteLength2;
|
|
1281
|
+
};
|
|
1282
|
+
Buffer2.prototype.writeUint8 = Buffer2.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) {
|
|
1283
|
+
value = +value;
|
|
1284
|
+
offset = offset >>> 0;
|
|
1285
|
+
if (!noAssert) checkInt(this, value, offset, 1, 255, 0);
|
|
1286
|
+
this[offset] = value & 255;
|
|
1287
|
+
return offset + 1;
|
|
1288
|
+
};
|
|
1289
|
+
Buffer2.prototype.writeUint16LE = Buffer2.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) {
|
|
1290
|
+
value = +value;
|
|
1291
|
+
offset = offset >>> 0;
|
|
1292
|
+
if (!noAssert) checkInt(this, value, offset, 2, 65535, 0);
|
|
1293
|
+
this[offset] = value & 255;
|
|
1294
|
+
this[offset + 1] = value >>> 8;
|
|
1295
|
+
return offset + 2;
|
|
1296
|
+
};
|
|
1297
|
+
Buffer2.prototype.writeUint16BE = Buffer2.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) {
|
|
1298
|
+
value = +value;
|
|
1299
|
+
offset = offset >>> 0;
|
|
1300
|
+
if (!noAssert) checkInt(this, value, offset, 2, 65535, 0);
|
|
1301
|
+
this[offset] = value >>> 8;
|
|
1302
|
+
this[offset + 1] = value & 255;
|
|
1303
|
+
return offset + 2;
|
|
1304
|
+
};
|
|
1305
|
+
Buffer2.prototype.writeUint32LE = Buffer2.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) {
|
|
1306
|
+
value = +value;
|
|
1307
|
+
offset = offset >>> 0;
|
|
1308
|
+
if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0);
|
|
1309
|
+
this[offset + 3] = value >>> 24;
|
|
1310
|
+
this[offset + 2] = value >>> 16;
|
|
1311
|
+
this[offset + 1] = value >>> 8;
|
|
1312
|
+
this[offset] = value & 255;
|
|
1313
|
+
return offset + 4;
|
|
1314
|
+
};
|
|
1315
|
+
Buffer2.prototype.writeUint32BE = Buffer2.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) {
|
|
1316
|
+
value = +value;
|
|
1317
|
+
offset = offset >>> 0;
|
|
1318
|
+
if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0);
|
|
1319
|
+
this[offset] = value >>> 24;
|
|
1320
|
+
this[offset + 1] = value >>> 16;
|
|
1321
|
+
this[offset + 2] = value >>> 8;
|
|
1322
|
+
this[offset + 3] = value & 255;
|
|
1323
|
+
return offset + 4;
|
|
1324
|
+
};
|
|
1325
|
+
function wrtBigUInt64LE(buf, value, offset, min, max) {
|
|
1326
|
+
checkIntBI(value, min, max, buf, offset, 7);
|
|
1327
|
+
let lo = Number(value & BigInt(4294967295));
|
|
1328
|
+
buf[offset++] = lo;
|
|
1329
|
+
lo = lo >> 8;
|
|
1330
|
+
buf[offset++] = lo;
|
|
1331
|
+
lo = lo >> 8;
|
|
1332
|
+
buf[offset++] = lo;
|
|
1333
|
+
lo = lo >> 8;
|
|
1334
|
+
buf[offset++] = lo;
|
|
1335
|
+
let hi = Number(value >> BigInt(32) & BigInt(4294967295));
|
|
1336
|
+
buf[offset++] = hi;
|
|
1337
|
+
hi = hi >> 8;
|
|
1338
|
+
buf[offset++] = hi;
|
|
1339
|
+
hi = hi >> 8;
|
|
1340
|
+
buf[offset++] = hi;
|
|
1341
|
+
hi = hi >> 8;
|
|
1342
|
+
buf[offset++] = hi;
|
|
1343
|
+
return offset;
|
|
1344
|
+
}
|
|
1345
|
+
function wrtBigUInt64BE(buf, value, offset, min, max) {
|
|
1346
|
+
checkIntBI(value, min, max, buf, offset, 7);
|
|
1347
|
+
let lo = Number(value & BigInt(4294967295));
|
|
1348
|
+
buf[offset + 7] = lo;
|
|
1349
|
+
lo = lo >> 8;
|
|
1350
|
+
buf[offset + 6] = lo;
|
|
1351
|
+
lo = lo >> 8;
|
|
1352
|
+
buf[offset + 5] = lo;
|
|
1353
|
+
lo = lo >> 8;
|
|
1354
|
+
buf[offset + 4] = lo;
|
|
1355
|
+
let hi = Number(value >> BigInt(32) & BigInt(4294967295));
|
|
1356
|
+
buf[offset + 3] = hi;
|
|
1357
|
+
hi = hi >> 8;
|
|
1358
|
+
buf[offset + 2] = hi;
|
|
1359
|
+
hi = hi >> 8;
|
|
1360
|
+
buf[offset + 1] = hi;
|
|
1361
|
+
hi = hi >> 8;
|
|
1362
|
+
buf[offset] = hi;
|
|
1363
|
+
return offset + 8;
|
|
1364
|
+
}
|
|
1365
|
+
Buffer2.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE(value, offset = 0) {
|
|
1366
|
+
return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt("0xffffffffffffffff"));
|
|
1367
|
+
});
|
|
1368
|
+
Buffer2.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE(value, offset = 0) {
|
|
1369
|
+
return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt("0xffffffffffffffff"));
|
|
1370
|
+
});
|
|
1371
|
+
Buffer2.prototype.writeIntLE = function writeIntLE(value, offset, byteLength2, noAssert) {
|
|
1372
|
+
value = +value;
|
|
1373
|
+
offset = offset >>> 0;
|
|
1374
|
+
if (!noAssert) {
|
|
1375
|
+
const limit = Math.pow(2, 8 * byteLength2 - 1);
|
|
1376
|
+
checkInt(this, value, offset, byteLength2, limit - 1, -limit);
|
|
1377
|
+
}
|
|
1378
|
+
let i = 0;
|
|
1379
|
+
let mul = 1;
|
|
1380
|
+
let sub = 0;
|
|
1381
|
+
this[offset] = value & 255;
|
|
1382
|
+
while (++i < byteLength2 && (mul *= 256)) {
|
|
1383
|
+
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
|
|
1384
|
+
sub = 1;
|
|
1385
|
+
}
|
|
1386
|
+
this[offset + i] = (value / mul >> 0) - sub & 255;
|
|
1387
|
+
}
|
|
1388
|
+
return offset + byteLength2;
|
|
1389
|
+
};
|
|
1390
|
+
Buffer2.prototype.writeIntBE = function writeIntBE(value, offset, byteLength2, noAssert) {
|
|
1391
|
+
value = +value;
|
|
1392
|
+
offset = offset >>> 0;
|
|
1393
|
+
if (!noAssert) {
|
|
1394
|
+
const limit = Math.pow(2, 8 * byteLength2 - 1);
|
|
1395
|
+
checkInt(this, value, offset, byteLength2, limit - 1, -limit);
|
|
1396
|
+
}
|
|
1397
|
+
let i = byteLength2 - 1;
|
|
1398
|
+
let mul = 1;
|
|
1399
|
+
let sub = 0;
|
|
1400
|
+
this[offset + i] = value & 255;
|
|
1401
|
+
while (--i >= 0 && (mul *= 256)) {
|
|
1402
|
+
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
|
|
1403
|
+
sub = 1;
|
|
1404
|
+
}
|
|
1405
|
+
this[offset + i] = (value / mul >> 0) - sub & 255;
|
|
1406
|
+
}
|
|
1407
|
+
return offset + byteLength2;
|
|
1408
|
+
};
|
|
1409
|
+
Buffer2.prototype.writeInt8 = function writeInt8(value, offset, noAssert) {
|
|
1410
|
+
value = +value;
|
|
1411
|
+
offset = offset >>> 0;
|
|
1412
|
+
if (!noAssert) checkInt(this, value, offset, 1, 127, -128);
|
|
1413
|
+
if (value < 0) value = 255 + value + 1;
|
|
1414
|
+
this[offset] = value & 255;
|
|
1415
|
+
return offset + 1;
|
|
1416
|
+
};
|
|
1417
|
+
Buffer2.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) {
|
|
1418
|
+
value = +value;
|
|
1419
|
+
offset = offset >>> 0;
|
|
1420
|
+
if (!noAssert) checkInt(this, value, offset, 2, 32767, -32768);
|
|
1421
|
+
this[offset] = value & 255;
|
|
1422
|
+
this[offset + 1] = value >>> 8;
|
|
1423
|
+
return offset + 2;
|
|
1424
|
+
};
|
|
1425
|
+
Buffer2.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) {
|
|
1426
|
+
value = +value;
|
|
1427
|
+
offset = offset >>> 0;
|
|
1428
|
+
if (!noAssert) checkInt(this, value, offset, 2, 32767, -32768);
|
|
1429
|
+
this[offset] = value >>> 8;
|
|
1430
|
+
this[offset + 1] = value & 255;
|
|
1431
|
+
return offset + 2;
|
|
1432
|
+
};
|
|
1433
|
+
Buffer2.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) {
|
|
1434
|
+
value = +value;
|
|
1435
|
+
offset = offset >>> 0;
|
|
1436
|
+
if (!noAssert) checkInt(this, value, offset, 4, 2147483647, -2147483648);
|
|
1437
|
+
this[offset] = value & 255;
|
|
1438
|
+
this[offset + 1] = value >>> 8;
|
|
1439
|
+
this[offset + 2] = value >>> 16;
|
|
1440
|
+
this[offset + 3] = value >>> 24;
|
|
1441
|
+
return offset + 4;
|
|
1442
|
+
};
|
|
1443
|
+
Buffer2.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) {
|
|
1444
|
+
value = +value;
|
|
1445
|
+
offset = offset >>> 0;
|
|
1446
|
+
if (!noAssert) checkInt(this, value, offset, 4, 2147483647, -2147483648);
|
|
1447
|
+
if (value < 0) value = 4294967295 + value + 1;
|
|
1448
|
+
this[offset] = value >>> 24;
|
|
1449
|
+
this[offset + 1] = value >>> 16;
|
|
1450
|
+
this[offset + 2] = value >>> 8;
|
|
1451
|
+
this[offset + 3] = value & 255;
|
|
1452
|
+
return offset + 4;
|
|
1453
|
+
};
|
|
1454
|
+
Buffer2.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE(value, offset = 0) {
|
|
1455
|
+
return wrtBigUInt64LE(this, value, offset, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
|
|
1456
|
+
});
|
|
1457
|
+
Buffer2.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE(value, offset = 0) {
|
|
1458
|
+
return wrtBigUInt64BE(this, value, offset, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
|
|
1459
|
+
});
|
|
1460
|
+
function checkIEEE754(buf, value, offset, ext, max, min) {
|
|
1461
|
+
if (offset + ext > buf.length) throw new RangeError("Index out of range");
|
|
1462
|
+
if (offset < 0) throw new RangeError("Index out of range");
|
|
1463
|
+
}
|
|
1464
|
+
function writeFloat(buf, value, offset, littleEndian, noAssert) {
|
|
1465
|
+
value = +value;
|
|
1466
|
+
offset = offset >>> 0;
|
|
1467
|
+
if (!noAssert) {
|
|
1468
|
+
checkIEEE754(buf, value, offset, 4);
|
|
1469
|
+
}
|
|
1470
|
+
ieee7542.write(buf, value, offset, littleEndian, 23, 4);
|
|
1471
|
+
return offset + 4;
|
|
1472
|
+
}
|
|
1473
|
+
Buffer2.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) {
|
|
1474
|
+
return writeFloat(this, value, offset, true, noAssert);
|
|
1475
|
+
};
|
|
1476
|
+
Buffer2.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) {
|
|
1477
|
+
return writeFloat(this, value, offset, false, noAssert);
|
|
1478
|
+
};
|
|
1479
|
+
function writeDouble(buf, value, offset, littleEndian, noAssert) {
|
|
1480
|
+
value = +value;
|
|
1481
|
+
offset = offset >>> 0;
|
|
1482
|
+
if (!noAssert) {
|
|
1483
|
+
checkIEEE754(buf, value, offset, 8);
|
|
1484
|
+
}
|
|
1485
|
+
ieee7542.write(buf, value, offset, littleEndian, 52, 8);
|
|
1486
|
+
return offset + 8;
|
|
1487
|
+
}
|
|
1488
|
+
Buffer2.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) {
|
|
1489
|
+
return writeDouble(this, value, offset, true, noAssert);
|
|
1490
|
+
};
|
|
1491
|
+
Buffer2.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) {
|
|
1492
|
+
return writeDouble(this, value, offset, false, noAssert);
|
|
1493
|
+
};
|
|
1494
|
+
Buffer2.prototype.copy = function copy(target, targetStart, start, end) {
|
|
1495
|
+
if (!Buffer2.isBuffer(target)) throw new TypeError("argument should be a Buffer");
|
|
1496
|
+
if (!start) start = 0;
|
|
1497
|
+
if (!end && end !== 0) end = this.length;
|
|
1498
|
+
if (targetStart >= target.length) targetStart = target.length;
|
|
1499
|
+
if (!targetStart) targetStart = 0;
|
|
1500
|
+
if (end > 0 && end < start) end = start;
|
|
1501
|
+
if (end === start) return 0;
|
|
1502
|
+
if (target.length === 0 || this.length === 0) return 0;
|
|
1503
|
+
if (targetStart < 0) {
|
|
1504
|
+
throw new RangeError("targetStart out of bounds");
|
|
1505
|
+
}
|
|
1506
|
+
if (start < 0 || start >= this.length) throw new RangeError("Index out of range");
|
|
1507
|
+
if (end < 0) throw new RangeError("sourceEnd out of bounds");
|
|
1508
|
+
if (end > this.length) end = this.length;
|
|
1509
|
+
if (target.length - targetStart < end - start) {
|
|
1510
|
+
end = target.length - targetStart + start;
|
|
1511
|
+
}
|
|
1512
|
+
const len = end - start;
|
|
1513
|
+
if (this === target && typeof Uint8Array.prototype.copyWithin === "function") {
|
|
1514
|
+
this.copyWithin(targetStart, start, end);
|
|
1515
|
+
} else {
|
|
1516
|
+
Uint8Array.prototype.set.call(
|
|
1517
|
+
target,
|
|
1518
|
+
this.subarray(start, end),
|
|
1519
|
+
targetStart
|
|
1520
|
+
);
|
|
1521
|
+
}
|
|
1522
|
+
return len;
|
|
1523
|
+
};
|
|
1524
|
+
Buffer2.prototype.fill = function fill(val, start, end, encoding) {
|
|
1525
|
+
if (typeof val === "string") {
|
|
1526
|
+
if (typeof start === "string") {
|
|
1527
|
+
encoding = start;
|
|
1528
|
+
start = 0;
|
|
1529
|
+
end = this.length;
|
|
1530
|
+
} else if (typeof end === "string") {
|
|
1531
|
+
encoding = end;
|
|
1532
|
+
end = this.length;
|
|
1533
|
+
}
|
|
1534
|
+
if (encoding !== void 0 && typeof encoding !== "string") {
|
|
1535
|
+
throw new TypeError("encoding must be a string");
|
|
1536
|
+
}
|
|
1537
|
+
if (typeof encoding === "string" && !Buffer2.isEncoding(encoding)) {
|
|
1538
|
+
throw new TypeError("Unknown encoding: " + encoding);
|
|
1539
|
+
}
|
|
1540
|
+
if (val.length === 1) {
|
|
1541
|
+
const code = val.charCodeAt(0);
|
|
1542
|
+
if (encoding === "utf8" && code < 128 || encoding === "latin1") {
|
|
1543
|
+
val = code;
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
} else if (typeof val === "number") {
|
|
1547
|
+
val = val & 255;
|
|
1548
|
+
} else if (typeof val === "boolean") {
|
|
1549
|
+
val = Number(val);
|
|
1550
|
+
}
|
|
1551
|
+
if (start < 0 || this.length < start || this.length < end) {
|
|
1552
|
+
throw new RangeError("Out of range index");
|
|
1553
|
+
}
|
|
1554
|
+
if (end <= start) {
|
|
1555
|
+
return this;
|
|
1556
|
+
}
|
|
1557
|
+
start = start >>> 0;
|
|
1558
|
+
end = end === void 0 ? this.length : end >>> 0;
|
|
1559
|
+
if (!val) val = 0;
|
|
1560
|
+
let i;
|
|
1561
|
+
if (typeof val === "number") {
|
|
1562
|
+
for (i = start; i < end; ++i) {
|
|
1563
|
+
this[i] = val;
|
|
1564
|
+
}
|
|
1565
|
+
} else {
|
|
1566
|
+
const bytes = Buffer2.isBuffer(val) ? val : Buffer2.from(val, encoding);
|
|
1567
|
+
const len = bytes.length;
|
|
1568
|
+
if (len === 0) {
|
|
1569
|
+
throw new TypeError('The value "' + val + '" is invalid for argument "value"');
|
|
1570
|
+
}
|
|
1571
|
+
for (i = 0; i < end - start; ++i) {
|
|
1572
|
+
this[i + start] = bytes[i % len];
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
return this;
|
|
1576
|
+
};
|
|
1577
|
+
const errors = {};
|
|
1578
|
+
function E(sym, getMessage, Base) {
|
|
1579
|
+
errors[sym] = class NodeError extends Base {
|
|
1580
|
+
constructor() {
|
|
1581
|
+
super();
|
|
1582
|
+
Object.defineProperty(this, "message", {
|
|
1583
|
+
value: getMessage.apply(this, arguments),
|
|
1584
|
+
writable: true,
|
|
1585
|
+
configurable: true
|
|
1586
|
+
});
|
|
1587
|
+
this.name = `${this.name} [${sym}]`;
|
|
1588
|
+
this.stack;
|
|
1589
|
+
delete this.name;
|
|
1590
|
+
}
|
|
1591
|
+
get code() {
|
|
1592
|
+
return sym;
|
|
1593
|
+
}
|
|
1594
|
+
set code(value) {
|
|
1595
|
+
Object.defineProperty(this, "code", {
|
|
1596
|
+
configurable: true,
|
|
1597
|
+
enumerable: true,
|
|
1598
|
+
value,
|
|
1599
|
+
writable: true
|
|
1600
|
+
});
|
|
1601
|
+
}
|
|
1602
|
+
toString() {
|
|
1603
|
+
return `${this.name} [${sym}]: ${this.message}`;
|
|
1604
|
+
}
|
|
1605
|
+
};
|
|
1606
|
+
}
|
|
1607
|
+
E(
|
|
1608
|
+
"ERR_BUFFER_OUT_OF_BOUNDS",
|
|
1609
|
+
function(name) {
|
|
1610
|
+
if (name) {
|
|
1611
|
+
return `${name} is outside of buffer bounds`;
|
|
1612
|
+
}
|
|
1613
|
+
return "Attempt to access memory outside buffer bounds";
|
|
1614
|
+
},
|
|
1615
|
+
RangeError
|
|
1616
|
+
);
|
|
1617
|
+
E(
|
|
1618
|
+
"ERR_INVALID_ARG_TYPE",
|
|
1619
|
+
function(name, actual) {
|
|
1620
|
+
return `The "${name}" argument must be of type number. Received type ${typeof actual}`;
|
|
1621
|
+
},
|
|
1622
|
+
TypeError
|
|
1623
|
+
);
|
|
1624
|
+
E(
|
|
1625
|
+
"ERR_OUT_OF_RANGE",
|
|
1626
|
+
function(str, range, input) {
|
|
1627
|
+
let msg = `The value of "${str}" is out of range.`;
|
|
1628
|
+
let received = input;
|
|
1629
|
+
if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {
|
|
1630
|
+
received = addNumericalSeparator(String(input));
|
|
1631
|
+
} else if (typeof input === "bigint") {
|
|
1632
|
+
received = String(input);
|
|
1633
|
+
if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {
|
|
1634
|
+
received = addNumericalSeparator(received);
|
|
1635
|
+
}
|
|
1636
|
+
received += "n";
|
|
1637
|
+
}
|
|
1638
|
+
msg += ` It must be ${range}. Received ${received}`;
|
|
1639
|
+
return msg;
|
|
1640
|
+
},
|
|
1641
|
+
RangeError
|
|
1642
|
+
);
|
|
1643
|
+
function addNumericalSeparator(val) {
|
|
1644
|
+
let res = "";
|
|
1645
|
+
let i = val.length;
|
|
1646
|
+
const start = val[0] === "-" ? 1 : 0;
|
|
1647
|
+
for (; i >= start + 4; i -= 3) {
|
|
1648
|
+
res = `_${val.slice(i - 3, i)}${res}`;
|
|
1649
|
+
}
|
|
1650
|
+
return `${val.slice(0, i)}${res}`;
|
|
1651
|
+
}
|
|
1652
|
+
function checkBounds(buf, offset, byteLength2) {
|
|
1653
|
+
validateNumber(offset, "offset");
|
|
1654
|
+
if (buf[offset] === void 0 || buf[offset + byteLength2] === void 0) {
|
|
1655
|
+
boundsError(offset, buf.length - (byteLength2 + 1));
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
function checkIntBI(value, min, max, buf, offset, byteLength2) {
|
|
1659
|
+
if (value > max || value < min) {
|
|
1660
|
+
const n = typeof min === "bigint" ? "n" : "";
|
|
1661
|
+
let range;
|
|
1662
|
+
{
|
|
1663
|
+
if (min === 0 || min === BigInt(0)) {
|
|
1664
|
+
range = `>= 0${n} and < 2${n} ** ${(byteLength2 + 1) * 8}${n}`;
|
|
1665
|
+
} else {
|
|
1666
|
+
range = `>= -(2${n} ** ${(byteLength2 + 1) * 8 - 1}${n}) and < 2 ** ${(byteLength2 + 1) * 8 - 1}${n}`;
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
throw new errors.ERR_OUT_OF_RANGE("value", range, value);
|
|
1670
|
+
}
|
|
1671
|
+
checkBounds(buf, offset, byteLength2);
|
|
1672
|
+
}
|
|
1673
|
+
function validateNumber(value, name) {
|
|
1674
|
+
if (typeof value !== "number") {
|
|
1675
|
+
throw new errors.ERR_INVALID_ARG_TYPE(name, "number", value);
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
function boundsError(value, length, type) {
|
|
1679
|
+
if (Math.floor(value) !== value) {
|
|
1680
|
+
validateNumber(value, type);
|
|
1681
|
+
throw new errors.ERR_OUT_OF_RANGE("offset", "an integer", value);
|
|
1682
|
+
}
|
|
1683
|
+
if (length < 0) {
|
|
1684
|
+
throw new errors.ERR_BUFFER_OUT_OF_BOUNDS();
|
|
1685
|
+
}
|
|
1686
|
+
throw new errors.ERR_OUT_OF_RANGE(
|
|
1687
|
+
"offset",
|
|
1688
|
+
`>= ${0} and <= ${length}`,
|
|
1689
|
+
value
|
|
1690
|
+
);
|
|
1691
|
+
}
|
|
1692
|
+
const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
|
|
1693
|
+
function base64clean(str) {
|
|
1694
|
+
str = str.split("=")[0];
|
|
1695
|
+
str = str.trim().replace(INVALID_BASE64_RE, "");
|
|
1696
|
+
if (str.length < 2) return "";
|
|
1697
|
+
while (str.length % 4 !== 0) {
|
|
1698
|
+
str = str + "=";
|
|
1699
|
+
}
|
|
1700
|
+
return str;
|
|
1701
|
+
}
|
|
1702
|
+
function utf8ToBytes(string, units) {
|
|
1703
|
+
units = units || Infinity;
|
|
1704
|
+
let codePoint;
|
|
1705
|
+
const length = string.length;
|
|
1706
|
+
let leadSurrogate = null;
|
|
1707
|
+
const bytes = [];
|
|
1708
|
+
for (let i = 0; i < length; ++i) {
|
|
1709
|
+
codePoint = string.charCodeAt(i);
|
|
1710
|
+
if (codePoint > 55295 && codePoint < 57344) {
|
|
1711
|
+
if (!leadSurrogate) {
|
|
1712
|
+
if (codePoint > 56319) {
|
|
1713
|
+
if ((units -= 3) > -1) bytes.push(239, 191, 189);
|
|
1714
|
+
continue;
|
|
1715
|
+
} else if (i + 1 === length) {
|
|
1716
|
+
if ((units -= 3) > -1) bytes.push(239, 191, 189);
|
|
1717
|
+
continue;
|
|
1718
|
+
}
|
|
1719
|
+
leadSurrogate = codePoint;
|
|
1720
|
+
continue;
|
|
1721
|
+
}
|
|
1722
|
+
if (codePoint < 56320) {
|
|
1723
|
+
if ((units -= 3) > -1) bytes.push(239, 191, 189);
|
|
1724
|
+
leadSurrogate = codePoint;
|
|
1725
|
+
continue;
|
|
1726
|
+
}
|
|
1727
|
+
codePoint = (leadSurrogate - 55296 << 10 | codePoint - 56320) + 65536;
|
|
1728
|
+
} else if (leadSurrogate) {
|
|
1729
|
+
if ((units -= 3) > -1) bytes.push(239, 191, 189);
|
|
1730
|
+
}
|
|
1731
|
+
leadSurrogate = null;
|
|
1732
|
+
if (codePoint < 128) {
|
|
1733
|
+
if ((units -= 1) < 0) break;
|
|
1734
|
+
bytes.push(codePoint);
|
|
1735
|
+
} else if (codePoint < 2048) {
|
|
1736
|
+
if ((units -= 2) < 0) break;
|
|
1737
|
+
bytes.push(
|
|
1738
|
+
codePoint >> 6 | 192,
|
|
1739
|
+
codePoint & 63 | 128
|
|
1740
|
+
);
|
|
1741
|
+
} else if (codePoint < 65536) {
|
|
1742
|
+
if ((units -= 3) < 0) break;
|
|
1743
|
+
bytes.push(
|
|
1744
|
+
codePoint >> 12 | 224,
|
|
1745
|
+
codePoint >> 6 & 63 | 128,
|
|
1746
|
+
codePoint & 63 | 128
|
|
1747
|
+
);
|
|
1748
|
+
} else if (codePoint < 1114112) {
|
|
1749
|
+
if ((units -= 4) < 0) break;
|
|
1750
|
+
bytes.push(
|
|
1751
|
+
codePoint >> 18 | 240,
|
|
1752
|
+
codePoint >> 12 & 63 | 128,
|
|
1753
|
+
codePoint >> 6 & 63 | 128,
|
|
1754
|
+
codePoint & 63 | 128
|
|
1755
|
+
);
|
|
1756
|
+
} else {
|
|
1757
|
+
throw new Error("Invalid code point");
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
return bytes;
|
|
1761
|
+
}
|
|
1762
|
+
function asciiToBytes(str) {
|
|
1763
|
+
const byteArray = [];
|
|
1764
|
+
for (let i = 0; i < str.length; ++i) {
|
|
1765
|
+
byteArray.push(str.charCodeAt(i) & 255);
|
|
1766
|
+
}
|
|
1767
|
+
return byteArray;
|
|
1768
|
+
}
|
|
1769
|
+
function utf16leToBytes(str, units) {
|
|
1770
|
+
let c, hi, lo;
|
|
1771
|
+
const byteArray = [];
|
|
1772
|
+
for (let i = 0; i < str.length; ++i) {
|
|
1773
|
+
if ((units -= 2) < 0) break;
|
|
1774
|
+
c = str.charCodeAt(i);
|
|
1775
|
+
hi = c >> 8;
|
|
1776
|
+
lo = c % 256;
|
|
1777
|
+
byteArray.push(lo);
|
|
1778
|
+
byteArray.push(hi);
|
|
1779
|
+
}
|
|
1780
|
+
return byteArray;
|
|
1781
|
+
}
|
|
1782
|
+
function base64ToBytes(str) {
|
|
1783
|
+
return base64.toByteArray(base64clean(str));
|
|
1784
|
+
}
|
|
1785
|
+
function blitBuffer(src, dst, offset, length) {
|
|
1786
|
+
let i;
|
|
1787
|
+
for (i = 0; i < length; ++i) {
|
|
1788
|
+
if (i + offset >= dst.length || i >= src.length) break;
|
|
1789
|
+
dst[i + offset] = src[i];
|
|
1790
|
+
}
|
|
1791
|
+
return i;
|
|
1792
|
+
}
|
|
1793
|
+
function isInstance(obj, type) {
|
|
1794
|
+
return obj instanceof type || obj != null && obj.constructor != null && obj.constructor.name != null && obj.constructor.name === type.name;
|
|
1795
|
+
}
|
|
1796
|
+
function numberIsNaN(obj) {
|
|
1797
|
+
return obj !== obj;
|
|
1798
|
+
}
|
|
1799
|
+
const hexSliceLookupTable = function() {
|
|
1800
|
+
const alphabet = "0123456789abcdef";
|
|
1801
|
+
const table = new Array(256);
|
|
1802
|
+
for (let i = 0; i < 16; ++i) {
|
|
1803
|
+
const i16 = i * 16;
|
|
1804
|
+
for (let j = 0; j < 16; ++j) {
|
|
1805
|
+
table[i16 + j] = alphabet[i] + alphabet[j];
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
return table;
|
|
1809
|
+
}();
|
|
1810
|
+
function defineBigIntMethod(fn) {
|
|
1811
|
+
return typeof BigInt === "undefined" ? BufferBigIntNotDefined : fn;
|
|
1812
|
+
}
|
|
1813
|
+
function BufferBigIntNotDefined() {
|
|
1814
|
+
throw new Error("BigInt not supported");
|
|
1815
|
+
}
|
|
1816
|
+
})(buffer);
|
|
1817
|
+
return buffer;
|
|
1818
|
+
}
|
|
1819
|
+
/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
1820
|
+
var hasRequiredSafeBuffer;
|
|
1821
|
+
function requireSafeBuffer() {
|
|
1822
|
+
if (hasRequiredSafeBuffer) return safeBuffer.exports;
|
|
1823
|
+
hasRequiredSafeBuffer = 1;
|
|
1824
|
+
(function(module, exports) {
|
|
1825
|
+
var buffer2 = requireBuffer();
|
|
1826
|
+
var Buffer2 = buffer2.Buffer;
|
|
1827
|
+
function copyProps(src, dst) {
|
|
1828
|
+
for (var key in src) {
|
|
1829
|
+
dst[key] = src[key];
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
if (Buffer2.from && Buffer2.alloc && Buffer2.allocUnsafe && Buffer2.allocUnsafeSlow) {
|
|
1833
|
+
module.exports = buffer2;
|
|
1834
|
+
} else {
|
|
1835
|
+
copyProps(buffer2, exports);
|
|
1836
|
+
exports.Buffer = SafeBuffer;
|
|
1837
|
+
}
|
|
1838
|
+
function SafeBuffer(arg, encodingOrOffset, length) {
|
|
1839
|
+
return Buffer2(arg, encodingOrOffset, length);
|
|
1840
|
+
}
|
|
1841
|
+
SafeBuffer.prototype = Object.create(Buffer2.prototype);
|
|
1842
|
+
copyProps(Buffer2, SafeBuffer);
|
|
1843
|
+
SafeBuffer.from = function(arg, encodingOrOffset, length) {
|
|
1844
|
+
if (typeof arg === "number") {
|
|
1845
|
+
throw new TypeError("Argument must not be a number");
|
|
1846
|
+
}
|
|
1847
|
+
return Buffer2(arg, encodingOrOffset, length);
|
|
1848
|
+
};
|
|
1849
|
+
SafeBuffer.alloc = function(size, fill, encoding) {
|
|
1850
|
+
if (typeof size !== "number") {
|
|
1851
|
+
throw new TypeError("Argument must be a number");
|
|
1852
|
+
}
|
|
1853
|
+
var buf = Buffer2(size);
|
|
1854
|
+
if (fill !== void 0) {
|
|
1855
|
+
if (typeof encoding === "string") {
|
|
1856
|
+
buf.fill(fill, encoding);
|
|
1857
|
+
} else {
|
|
1858
|
+
buf.fill(fill);
|
|
1859
|
+
}
|
|
1860
|
+
} else {
|
|
1861
|
+
buf.fill(0);
|
|
1862
|
+
}
|
|
1863
|
+
return buf;
|
|
1864
|
+
};
|
|
1865
|
+
SafeBuffer.allocUnsafe = function(size) {
|
|
1866
|
+
if (typeof size !== "number") {
|
|
1867
|
+
throw new TypeError("Argument must be a number");
|
|
1868
|
+
}
|
|
1869
|
+
return Buffer2(size);
|
|
1870
|
+
};
|
|
1871
|
+
SafeBuffer.allocUnsafeSlow = function(size) {
|
|
1872
|
+
if (typeof size !== "number") {
|
|
1873
|
+
throw new TypeError("Argument must be a number");
|
|
1874
|
+
}
|
|
1875
|
+
return buffer2.SlowBuffer(size);
|
|
1876
|
+
};
|
|
1877
|
+
})(safeBuffer, safeBuffer.exports);
|
|
1878
|
+
return safeBuffer.exports;
|
|
1879
|
+
}
|
|
1880
|
+
var hasRequiredString_decoder;
|
|
1881
|
+
function requireString_decoder() {
|
|
1882
|
+
if (hasRequiredString_decoder) return string_decoder;
|
|
1883
|
+
hasRequiredString_decoder = 1;
|
|
1884
|
+
var Buffer2 = requireSafeBuffer().Buffer;
|
|
1885
|
+
var isEncoding = Buffer2.isEncoding || function(encoding) {
|
|
1886
|
+
encoding = "" + encoding;
|
|
1887
|
+
switch (encoding && encoding.toLowerCase()) {
|
|
1888
|
+
case "hex":
|
|
1889
|
+
case "utf8":
|
|
1890
|
+
case "utf-8":
|
|
1891
|
+
case "ascii":
|
|
1892
|
+
case "binary":
|
|
1893
|
+
case "base64":
|
|
1894
|
+
case "ucs2":
|
|
1895
|
+
case "ucs-2":
|
|
1896
|
+
case "utf16le":
|
|
1897
|
+
case "utf-16le":
|
|
1898
|
+
case "raw":
|
|
1899
|
+
return true;
|
|
1900
|
+
default:
|
|
1901
|
+
return false;
|
|
1902
|
+
}
|
|
1903
|
+
};
|
|
1904
|
+
function _normalizeEncoding(enc) {
|
|
1905
|
+
if (!enc) return "utf8";
|
|
1906
|
+
var retried;
|
|
1907
|
+
while (true) {
|
|
1908
|
+
switch (enc) {
|
|
1909
|
+
case "utf8":
|
|
1910
|
+
case "utf-8":
|
|
1911
|
+
return "utf8";
|
|
1912
|
+
case "ucs2":
|
|
1913
|
+
case "ucs-2":
|
|
1914
|
+
case "utf16le":
|
|
1915
|
+
case "utf-16le":
|
|
1916
|
+
return "utf16le";
|
|
1917
|
+
case "latin1":
|
|
1918
|
+
case "binary":
|
|
1919
|
+
return "latin1";
|
|
1920
|
+
case "base64":
|
|
1921
|
+
case "ascii":
|
|
1922
|
+
case "hex":
|
|
1923
|
+
return enc;
|
|
1924
|
+
default:
|
|
1925
|
+
if (retried) return;
|
|
1926
|
+
enc = ("" + enc).toLowerCase();
|
|
1927
|
+
retried = true;
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
function normalizeEncoding(enc) {
|
|
1932
|
+
var nenc = _normalizeEncoding(enc);
|
|
1933
|
+
if (typeof nenc !== "string" && (Buffer2.isEncoding === isEncoding || !isEncoding(enc))) throw new Error("Unknown encoding: " + enc);
|
|
1934
|
+
return nenc || enc;
|
|
1935
|
+
}
|
|
1936
|
+
string_decoder.StringDecoder = StringDecoder;
|
|
1937
|
+
function StringDecoder(encoding) {
|
|
1938
|
+
this.encoding = normalizeEncoding(encoding);
|
|
1939
|
+
var nb;
|
|
1940
|
+
switch (this.encoding) {
|
|
1941
|
+
case "utf16le":
|
|
1942
|
+
this.text = utf16Text;
|
|
1943
|
+
this.end = utf16End;
|
|
1944
|
+
nb = 4;
|
|
1945
|
+
break;
|
|
1946
|
+
case "utf8":
|
|
1947
|
+
this.fillLast = utf8FillLast;
|
|
1948
|
+
nb = 4;
|
|
1949
|
+
break;
|
|
1950
|
+
case "base64":
|
|
1951
|
+
this.text = base64Text;
|
|
1952
|
+
this.end = base64End;
|
|
1953
|
+
nb = 3;
|
|
1954
|
+
break;
|
|
1955
|
+
default:
|
|
1956
|
+
this.write = simpleWrite;
|
|
1957
|
+
this.end = simpleEnd;
|
|
1958
|
+
return;
|
|
1959
|
+
}
|
|
1960
|
+
this.lastNeed = 0;
|
|
1961
|
+
this.lastTotal = 0;
|
|
1962
|
+
this.lastChar = Buffer2.allocUnsafe(nb);
|
|
1963
|
+
}
|
|
1964
|
+
StringDecoder.prototype.write = function(buf) {
|
|
1965
|
+
if (buf.length === 0) return "";
|
|
1966
|
+
var r;
|
|
1967
|
+
var i;
|
|
1968
|
+
if (this.lastNeed) {
|
|
1969
|
+
r = this.fillLast(buf);
|
|
1970
|
+
if (r === void 0) return "";
|
|
1971
|
+
i = this.lastNeed;
|
|
1972
|
+
this.lastNeed = 0;
|
|
1973
|
+
} else {
|
|
1974
|
+
i = 0;
|
|
1975
|
+
}
|
|
1976
|
+
if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i);
|
|
1977
|
+
return r || "";
|
|
1978
|
+
};
|
|
1979
|
+
StringDecoder.prototype.end = utf8End;
|
|
1980
|
+
StringDecoder.prototype.text = utf8Text;
|
|
1981
|
+
StringDecoder.prototype.fillLast = function(buf) {
|
|
1982
|
+
if (this.lastNeed <= buf.length) {
|
|
1983
|
+
buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed);
|
|
1984
|
+
return this.lastChar.toString(this.encoding, 0, this.lastTotal);
|
|
1985
|
+
}
|
|
1986
|
+
buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
|
|
1987
|
+
this.lastNeed -= buf.length;
|
|
1988
|
+
};
|
|
1989
|
+
function utf8CheckByte(byte) {
|
|
1990
|
+
if (byte <= 127) return 0;
|
|
1991
|
+
else if (byte >> 5 === 6) return 2;
|
|
1992
|
+
else if (byte >> 4 === 14) return 3;
|
|
1993
|
+
else if (byte >> 3 === 30) return 4;
|
|
1994
|
+
return byte >> 6 === 2 ? -1 : -2;
|
|
1995
|
+
}
|
|
1996
|
+
function utf8CheckIncomplete(self, buf, i) {
|
|
1997
|
+
var j = buf.length - 1;
|
|
1998
|
+
if (j < i) return 0;
|
|
1999
|
+
var nb = utf8CheckByte(buf[j]);
|
|
2000
|
+
if (nb >= 0) {
|
|
2001
|
+
if (nb > 0) self.lastNeed = nb - 1;
|
|
2002
|
+
return nb;
|
|
2003
|
+
}
|
|
2004
|
+
if (--j < i || nb === -2) return 0;
|
|
2005
|
+
nb = utf8CheckByte(buf[j]);
|
|
2006
|
+
if (nb >= 0) {
|
|
2007
|
+
if (nb > 0) self.lastNeed = nb - 2;
|
|
2008
|
+
return nb;
|
|
2009
|
+
}
|
|
2010
|
+
if (--j < i || nb === -2) return 0;
|
|
2011
|
+
nb = utf8CheckByte(buf[j]);
|
|
2012
|
+
if (nb >= 0) {
|
|
2013
|
+
if (nb > 0) {
|
|
2014
|
+
if (nb === 2) nb = 0;
|
|
2015
|
+
else self.lastNeed = nb - 3;
|
|
2016
|
+
}
|
|
2017
|
+
return nb;
|
|
2018
|
+
}
|
|
2019
|
+
return 0;
|
|
2020
|
+
}
|
|
2021
|
+
function utf8CheckExtraBytes(self, buf, p) {
|
|
2022
|
+
if ((buf[0] & 192) !== 128) {
|
|
2023
|
+
self.lastNeed = 0;
|
|
2024
|
+
return "�";
|
|
2025
|
+
}
|
|
2026
|
+
if (self.lastNeed > 1 && buf.length > 1) {
|
|
2027
|
+
if ((buf[1] & 192) !== 128) {
|
|
2028
|
+
self.lastNeed = 1;
|
|
2029
|
+
return "�";
|
|
2030
|
+
}
|
|
2031
|
+
if (self.lastNeed > 2 && buf.length > 2) {
|
|
2032
|
+
if ((buf[2] & 192) !== 128) {
|
|
2033
|
+
self.lastNeed = 2;
|
|
2034
|
+
return "�";
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
function utf8FillLast(buf) {
|
|
2040
|
+
var p = this.lastTotal - this.lastNeed;
|
|
2041
|
+
var r = utf8CheckExtraBytes(this, buf);
|
|
2042
|
+
if (r !== void 0) return r;
|
|
2043
|
+
if (this.lastNeed <= buf.length) {
|
|
2044
|
+
buf.copy(this.lastChar, p, 0, this.lastNeed);
|
|
2045
|
+
return this.lastChar.toString(this.encoding, 0, this.lastTotal);
|
|
2046
|
+
}
|
|
2047
|
+
buf.copy(this.lastChar, p, 0, buf.length);
|
|
2048
|
+
this.lastNeed -= buf.length;
|
|
2049
|
+
}
|
|
2050
|
+
function utf8Text(buf, i) {
|
|
2051
|
+
var total = utf8CheckIncomplete(this, buf, i);
|
|
2052
|
+
if (!this.lastNeed) return buf.toString("utf8", i);
|
|
2053
|
+
this.lastTotal = total;
|
|
2054
|
+
var end = buf.length - (total - this.lastNeed);
|
|
2055
|
+
buf.copy(this.lastChar, 0, end);
|
|
2056
|
+
return buf.toString("utf8", i, end);
|
|
2057
|
+
}
|
|
2058
|
+
function utf8End(buf) {
|
|
2059
|
+
var r = buf && buf.length ? this.write(buf) : "";
|
|
2060
|
+
if (this.lastNeed) return r + "�";
|
|
2061
|
+
return r;
|
|
2062
|
+
}
|
|
2063
|
+
function utf16Text(buf, i) {
|
|
2064
|
+
if ((buf.length - i) % 2 === 0) {
|
|
2065
|
+
var r = buf.toString("utf16le", i);
|
|
2066
|
+
if (r) {
|
|
2067
|
+
var c = r.charCodeAt(r.length - 1);
|
|
2068
|
+
if (c >= 55296 && c <= 56319) {
|
|
2069
|
+
this.lastNeed = 2;
|
|
2070
|
+
this.lastTotal = 4;
|
|
2071
|
+
this.lastChar[0] = buf[buf.length - 2];
|
|
2072
|
+
this.lastChar[1] = buf[buf.length - 1];
|
|
2073
|
+
return r.slice(0, -1);
|
|
2074
|
+
}
|
|
2075
|
+
}
|
|
2076
|
+
return r;
|
|
2077
|
+
}
|
|
2078
|
+
this.lastNeed = 1;
|
|
2079
|
+
this.lastTotal = 2;
|
|
2080
|
+
this.lastChar[0] = buf[buf.length - 1];
|
|
2081
|
+
return buf.toString("utf16le", i, buf.length - 1);
|
|
2082
|
+
}
|
|
2083
|
+
function utf16End(buf) {
|
|
2084
|
+
var r = buf && buf.length ? this.write(buf) : "";
|
|
2085
|
+
if (this.lastNeed) {
|
|
2086
|
+
var end = this.lastTotal - this.lastNeed;
|
|
2087
|
+
return r + this.lastChar.toString("utf16le", 0, end);
|
|
2088
|
+
}
|
|
2089
|
+
return r;
|
|
2090
|
+
}
|
|
2091
|
+
function base64Text(buf, i) {
|
|
2092
|
+
var n = (buf.length - i) % 3;
|
|
2093
|
+
if (n === 0) return buf.toString("base64", i);
|
|
2094
|
+
this.lastNeed = 3 - n;
|
|
2095
|
+
this.lastTotal = 3;
|
|
2096
|
+
if (n === 1) {
|
|
2097
|
+
this.lastChar[0] = buf[buf.length - 1];
|
|
2098
|
+
} else {
|
|
2099
|
+
this.lastChar[0] = buf[buf.length - 2];
|
|
2100
|
+
this.lastChar[1] = buf[buf.length - 1];
|
|
2101
|
+
}
|
|
2102
|
+
return buf.toString("base64", i, buf.length - n);
|
|
2103
|
+
}
|
|
2104
|
+
function base64End(buf) {
|
|
2105
|
+
var r = buf && buf.length ? this.write(buf) : "";
|
|
2106
|
+
if (this.lastNeed) return r + this.lastChar.toString("base64", 0, 3 - this.lastNeed);
|
|
2107
|
+
return r;
|
|
2108
|
+
}
|
|
2109
|
+
function simpleWrite(buf) {
|
|
2110
|
+
return buf.toString(this.encoding);
|
|
2111
|
+
}
|
|
2112
|
+
function simpleEnd(buf) {
|
|
2113
|
+
return buf && buf.length ? this.write(buf) : "";
|
|
2114
|
+
}
|
|
2115
|
+
return string_decoder;
|
|
2116
|
+
}
|
|
2117
|
+
var hasRequiredSax;
|
|
2118
|
+
function requireSax() {
|
|
2119
|
+
if (hasRequiredSax) return sax;
|
|
2120
|
+
hasRequiredSax = 1;
|
|
2121
|
+
(function(exports) {
|
|
2122
|
+
(function(sax2) {
|
|
2123
|
+
sax2.parser = function(strict, opt) {
|
|
2124
|
+
return new SAXParser(strict, opt);
|
|
2125
|
+
};
|
|
2126
|
+
sax2.SAXParser = SAXParser;
|
|
2127
|
+
sax2.SAXStream = SAXStream;
|
|
2128
|
+
sax2.createStream = createStream;
|
|
2129
|
+
sax2.MAX_BUFFER_LENGTH = 64 * 1024;
|
|
2130
|
+
var buffers = [
|
|
2131
|
+
"comment",
|
|
2132
|
+
"sgmlDecl",
|
|
2133
|
+
"textNode",
|
|
2134
|
+
"tagName",
|
|
2135
|
+
"doctype",
|
|
2136
|
+
"procInstName",
|
|
2137
|
+
"procInstBody",
|
|
2138
|
+
"entity",
|
|
2139
|
+
"attribName",
|
|
2140
|
+
"attribValue",
|
|
2141
|
+
"cdata",
|
|
2142
|
+
"script"
|
|
2143
|
+
];
|
|
2144
|
+
sax2.EVENTS = [
|
|
2145
|
+
"text",
|
|
2146
|
+
"processinginstruction",
|
|
2147
|
+
"sgmldeclaration",
|
|
2148
|
+
"doctype",
|
|
2149
|
+
"comment",
|
|
2150
|
+
"opentagstart",
|
|
2151
|
+
"attribute",
|
|
2152
|
+
"opentag",
|
|
2153
|
+
"closetag",
|
|
2154
|
+
"opencdata",
|
|
2155
|
+
"cdata",
|
|
2156
|
+
"closecdata",
|
|
2157
|
+
"error",
|
|
2158
|
+
"end",
|
|
2159
|
+
"ready",
|
|
2160
|
+
"script",
|
|
2161
|
+
"opennamespace",
|
|
2162
|
+
"closenamespace"
|
|
2163
|
+
];
|
|
2164
|
+
function SAXParser(strict, opt) {
|
|
2165
|
+
if (!(this instanceof SAXParser)) {
|
|
2166
|
+
return new SAXParser(strict, opt);
|
|
2167
|
+
}
|
|
2168
|
+
var parser = this;
|
|
2169
|
+
clearBuffers(parser);
|
|
2170
|
+
parser.q = parser.c = "";
|
|
2171
|
+
parser.bufferCheckPosition = sax2.MAX_BUFFER_LENGTH;
|
|
2172
|
+
parser.opt = opt || {};
|
|
2173
|
+
parser.opt.lowercase = parser.opt.lowercase || parser.opt.lowercasetags;
|
|
2174
|
+
parser.looseCase = parser.opt.lowercase ? "toLowerCase" : "toUpperCase";
|
|
2175
|
+
parser.tags = [];
|
|
2176
|
+
parser.closed = parser.closedRoot = parser.sawRoot = false;
|
|
2177
|
+
parser.tag = parser.error = null;
|
|
2178
|
+
parser.strict = !!strict;
|
|
2179
|
+
parser.noscript = !!(strict || parser.opt.noscript);
|
|
2180
|
+
parser.state = S.BEGIN;
|
|
2181
|
+
parser.strictEntities = parser.opt.strictEntities;
|
|
2182
|
+
parser.ENTITIES = parser.strictEntities ? Object.create(sax2.XML_ENTITIES) : Object.create(sax2.ENTITIES);
|
|
2183
|
+
parser.attribList = [];
|
|
2184
|
+
if (parser.opt.xmlns) {
|
|
2185
|
+
parser.ns = Object.create(rootNS);
|
|
2186
|
+
}
|
|
2187
|
+
if (parser.opt.unquotedAttributeValues === void 0) {
|
|
2188
|
+
parser.opt.unquotedAttributeValues = !strict;
|
|
2189
|
+
}
|
|
2190
|
+
parser.trackPosition = parser.opt.position !== false;
|
|
2191
|
+
if (parser.trackPosition) {
|
|
2192
|
+
parser.position = parser.line = parser.column = 0;
|
|
2193
|
+
}
|
|
2194
|
+
emit(parser, "onready");
|
|
2195
|
+
}
|
|
2196
|
+
if (!Object.create) {
|
|
2197
|
+
Object.create = function(o) {
|
|
2198
|
+
function F() {
|
|
2199
|
+
}
|
|
2200
|
+
F.prototype = o;
|
|
2201
|
+
var newf = new F();
|
|
2202
|
+
return newf;
|
|
2203
|
+
};
|
|
2204
|
+
}
|
|
2205
|
+
if (!Object.keys) {
|
|
2206
|
+
Object.keys = function(o) {
|
|
2207
|
+
var a = [];
|
|
2208
|
+
for (var i in o) if (o.hasOwnProperty(i)) a.push(i);
|
|
2209
|
+
return a;
|
|
2210
|
+
};
|
|
2211
|
+
}
|
|
2212
|
+
function checkBufferLength(parser) {
|
|
2213
|
+
var maxAllowed = Math.max(sax2.MAX_BUFFER_LENGTH, 10);
|
|
2214
|
+
var maxActual = 0;
|
|
2215
|
+
for (var i = 0, l = buffers.length; i < l; i++) {
|
|
2216
|
+
var len = parser[buffers[i]].length;
|
|
2217
|
+
if (len > maxAllowed) {
|
|
2218
|
+
switch (buffers[i]) {
|
|
2219
|
+
case "textNode":
|
|
2220
|
+
closeText(parser);
|
|
2221
|
+
break;
|
|
2222
|
+
case "cdata":
|
|
2223
|
+
emitNode(parser, "oncdata", parser.cdata);
|
|
2224
|
+
parser.cdata = "";
|
|
2225
|
+
break;
|
|
2226
|
+
case "script":
|
|
2227
|
+
emitNode(parser, "onscript", parser.script);
|
|
2228
|
+
parser.script = "";
|
|
2229
|
+
break;
|
|
2230
|
+
default:
|
|
2231
|
+
error(parser, "Max buffer length exceeded: " + buffers[i]);
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
maxActual = Math.max(maxActual, len);
|
|
2235
|
+
}
|
|
2236
|
+
var m = sax2.MAX_BUFFER_LENGTH - maxActual;
|
|
2237
|
+
parser.bufferCheckPosition = m + parser.position;
|
|
2238
|
+
}
|
|
2239
|
+
function clearBuffers(parser) {
|
|
2240
|
+
for (var i = 0, l = buffers.length; i < l; i++) {
|
|
2241
|
+
parser[buffers[i]] = "";
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
function flushBuffers(parser) {
|
|
2245
|
+
closeText(parser);
|
|
2246
|
+
if (parser.cdata !== "") {
|
|
2247
|
+
emitNode(parser, "oncdata", parser.cdata);
|
|
2248
|
+
parser.cdata = "";
|
|
2249
|
+
}
|
|
2250
|
+
if (parser.script !== "") {
|
|
2251
|
+
emitNode(parser, "onscript", parser.script);
|
|
2252
|
+
parser.script = "";
|
|
2253
|
+
}
|
|
2254
|
+
}
|
|
2255
|
+
SAXParser.prototype = {
|
|
2256
|
+
end: function() {
|
|
2257
|
+
end(this);
|
|
2258
|
+
},
|
|
2259
|
+
write,
|
|
2260
|
+
resume: function() {
|
|
2261
|
+
this.error = null;
|
|
2262
|
+
return this;
|
|
2263
|
+
},
|
|
2264
|
+
close: function() {
|
|
2265
|
+
return this.write(null);
|
|
2266
|
+
},
|
|
2267
|
+
flush: function() {
|
|
2268
|
+
flushBuffers(this);
|
|
2269
|
+
}
|
|
2270
|
+
};
|
|
2271
|
+
var Stream;
|
|
2272
|
+
try {
|
|
2273
|
+
Stream = require$$0.Stream;
|
|
2274
|
+
} catch (ex) {
|
|
2275
|
+
Stream = function() {
|
|
2276
|
+
};
|
|
2277
|
+
}
|
|
2278
|
+
if (!Stream) Stream = function() {
|
|
2279
|
+
};
|
|
2280
|
+
var streamWraps = sax2.EVENTS.filter(function(ev) {
|
|
2281
|
+
return ev !== "error" && ev !== "end";
|
|
2282
|
+
});
|
|
2283
|
+
function createStream(strict, opt) {
|
|
2284
|
+
return new SAXStream(strict, opt);
|
|
2285
|
+
}
|
|
2286
|
+
function SAXStream(strict, opt) {
|
|
2287
|
+
if (!(this instanceof SAXStream)) {
|
|
2288
|
+
return new SAXStream(strict, opt);
|
|
2289
|
+
}
|
|
2290
|
+
Stream.apply(this);
|
|
2291
|
+
this._parser = new SAXParser(strict, opt);
|
|
2292
|
+
this.writable = true;
|
|
2293
|
+
this.readable = true;
|
|
2294
|
+
var me = this;
|
|
2295
|
+
this._parser.onend = function() {
|
|
2296
|
+
me.emit("end");
|
|
2297
|
+
};
|
|
2298
|
+
this._parser.onerror = function(er) {
|
|
2299
|
+
me.emit("error", er);
|
|
2300
|
+
me._parser.error = null;
|
|
2301
|
+
};
|
|
2302
|
+
this._decoder = null;
|
|
2303
|
+
streamWraps.forEach(function(ev) {
|
|
2304
|
+
Object.defineProperty(me, "on" + ev, {
|
|
2305
|
+
get: function() {
|
|
2306
|
+
return me._parser["on" + ev];
|
|
2307
|
+
},
|
|
2308
|
+
set: function(h) {
|
|
2309
|
+
if (!h) {
|
|
2310
|
+
me.removeAllListeners(ev);
|
|
2311
|
+
me._parser["on" + ev] = h;
|
|
2312
|
+
return h;
|
|
2313
|
+
}
|
|
2314
|
+
me.on(ev, h);
|
|
2315
|
+
},
|
|
2316
|
+
enumerable: true,
|
|
2317
|
+
configurable: false
|
|
2318
|
+
});
|
|
2319
|
+
});
|
|
2320
|
+
}
|
|
2321
|
+
SAXStream.prototype = Object.create(Stream.prototype, {
|
|
2322
|
+
constructor: {
|
|
2323
|
+
value: SAXStream
|
|
2324
|
+
}
|
|
2325
|
+
});
|
|
2326
|
+
SAXStream.prototype.write = function(data) {
|
|
2327
|
+
if (typeof Buffer === "function" && typeof Buffer.isBuffer === "function" && Buffer.isBuffer(data)) {
|
|
2328
|
+
if (!this._decoder) {
|
|
2329
|
+
var SD = requireString_decoder().StringDecoder;
|
|
2330
|
+
this._decoder = new SD("utf8");
|
|
2331
|
+
}
|
|
2332
|
+
data = this._decoder.write(data);
|
|
2333
|
+
}
|
|
2334
|
+
this._parser.write(data.toString());
|
|
2335
|
+
this.emit("data", data);
|
|
2336
|
+
return true;
|
|
2337
|
+
};
|
|
2338
|
+
SAXStream.prototype.end = function(chunk) {
|
|
2339
|
+
if (chunk && chunk.length) {
|
|
2340
|
+
this.write(chunk);
|
|
2341
|
+
}
|
|
2342
|
+
this._parser.end();
|
|
2343
|
+
return true;
|
|
2344
|
+
};
|
|
2345
|
+
SAXStream.prototype.on = function(ev, handler) {
|
|
2346
|
+
var me = this;
|
|
2347
|
+
if (!me._parser["on" + ev] && streamWraps.indexOf(ev) !== -1) {
|
|
2348
|
+
me._parser["on" + ev] = function() {
|
|
2349
|
+
var args = arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments);
|
|
2350
|
+
args.splice(0, 0, ev);
|
|
2351
|
+
me.emit.apply(me, args);
|
|
2352
|
+
};
|
|
2353
|
+
}
|
|
2354
|
+
return Stream.prototype.on.call(me, ev, handler);
|
|
2355
|
+
};
|
|
2356
|
+
var CDATA = "[CDATA[";
|
|
2357
|
+
var DOCTYPE = "DOCTYPE";
|
|
2358
|
+
var XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace";
|
|
2359
|
+
var XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/";
|
|
2360
|
+
var rootNS = { xml: XML_NAMESPACE, xmlns: XMLNS_NAMESPACE };
|
|
2361
|
+
var nameStart = /[:_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]/;
|
|
2362
|
+
var nameBody = /[:_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\u00B7\u0300-\u036F\u203F-\u2040.\d-]/;
|
|
2363
|
+
var entityStart = /[#:_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]/;
|
|
2364
|
+
var entityBody = /[#:_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\u00B7\u0300-\u036F\u203F-\u2040.\d-]/;
|
|
2365
|
+
function isWhitespace(c) {
|
|
2366
|
+
return c === " " || c === "\n" || c === "\r" || c === " ";
|
|
2367
|
+
}
|
|
2368
|
+
function isQuote(c) {
|
|
2369
|
+
return c === '"' || c === "'";
|
|
2370
|
+
}
|
|
2371
|
+
function isAttribEnd(c) {
|
|
2372
|
+
return c === ">" || isWhitespace(c);
|
|
2373
|
+
}
|
|
2374
|
+
function isMatch(regex, c) {
|
|
2375
|
+
return regex.test(c);
|
|
2376
|
+
}
|
|
2377
|
+
function notMatch(regex, c) {
|
|
2378
|
+
return !isMatch(regex, c);
|
|
2379
|
+
}
|
|
2380
|
+
var S = 0;
|
|
2381
|
+
sax2.STATE = {
|
|
2382
|
+
BEGIN: S++,
|
|
2383
|
+
// leading byte order mark or whitespace
|
|
2384
|
+
BEGIN_WHITESPACE: S++,
|
|
2385
|
+
// leading whitespace
|
|
2386
|
+
TEXT: S++,
|
|
2387
|
+
// general stuff
|
|
2388
|
+
TEXT_ENTITY: S++,
|
|
2389
|
+
// & and such.
|
|
2390
|
+
OPEN_WAKA: S++,
|
|
2391
|
+
// <
|
|
2392
|
+
SGML_DECL: S++,
|
|
2393
|
+
// <!BLARG
|
|
2394
|
+
SGML_DECL_QUOTED: S++,
|
|
2395
|
+
// <!BLARG foo "bar
|
|
2396
|
+
DOCTYPE: S++,
|
|
2397
|
+
// <!DOCTYPE
|
|
2398
|
+
DOCTYPE_QUOTED: S++,
|
|
2399
|
+
// <!DOCTYPE "//blah
|
|
2400
|
+
DOCTYPE_DTD: S++,
|
|
2401
|
+
// <!DOCTYPE "//blah" [ ...
|
|
2402
|
+
DOCTYPE_DTD_QUOTED: S++,
|
|
2403
|
+
// <!DOCTYPE "//blah" [ "foo
|
|
2404
|
+
COMMENT_STARTING: S++,
|
|
2405
|
+
// <!-
|
|
2406
|
+
COMMENT: S++,
|
|
2407
|
+
// <!--
|
|
2408
|
+
COMMENT_ENDING: S++,
|
|
2409
|
+
// <!-- blah -
|
|
2410
|
+
COMMENT_ENDED: S++,
|
|
2411
|
+
// <!-- blah --
|
|
2412
|
+
CDATA: S++,
|
|
2413
|
+
// <![CDATA[ something
|
|
2414
|
+
CDATA_ENDING: S++,
|
|
2415
|
+
// ]
|
|
2416
|
+
CDATA_ENDING_2: S++,
|
|
2417
|
+
// ]]
|
|
2418
|
+
PROC_INST: S++,
|
|
2419
|
+
// <?hi
|
|
2420
|
+
PROC_INST_BODY: S++,
|
|
2421
|
+
// <?hi there
|
|
2422
|
+
PROC_INST_ENDING: S++,
|
|
2423
|
+
// <?hi "there" ?
|
|
2424
|
+
OPEN_TAG: S++,
|
|
2425
|
+
// <strong
|
|
2426
|
+
OPEN_TAG_SLASH: S++,
|
|
2427
|
+
// <strong /
|
|
2428
|
+
ATTRIB: S++,
|
|
2429
|
+
// <a
|
|
2430
|
+
ATTRIB_NAME: S++,
|
|
2431
|
+
// <a foo
|
|
2432
|
+
ATTRIB_NAME_SAW_WHITE: S++,
|
|
2433
|
+
// <a foo _
|
|
2434
|
+
ATTRIB_VALUE: S++,
|
|
2435
|
+
// <a foo=
|
|
2436
|
+
ATTRIB_VALUE_QUOTED: S++,
|
|
2437
|
+
// <a foo="bar
|
|
2438
|
+
ATTRIB_VALUE_CLOSED: S++,
|
|
2439
|
+
// <a foo="bar"
|
|
2440
|
+
ATTRIB_VALUE_UNQUOTED: S++,
|
|
2441
|
+
// <a foo=bar
|
|
2442
|
+
ATTRIB_VALUE_ENTITY_Q: S++,
|
|
2443
|
+
// <foo bar="""
|
|
2444
|
+
ATTRIB_VALUE_ENTITY_U: S++,
|
|
2445
|
+
// <foo bar="
|
|
2446
|
+
CLOSE_TAG: S++,
|
|
2447
|
+
// </a
|
|
2448
|
+
CLOSE_TAG_SAW_WHITE: S++,
|
|
2449
|
+
// </a >
|
|
2450
|
+
SCRIPT: S++,
|
|
2451
|
+
// <script> ...
|
|
2452
|
+
SCRIPT_ENDING: S++
|
|
2453
|
+
// <script> ... <
|
|
2454
|
+
};
|
|
2455
|
+
sax2.XML_ENTITIES = {
|
|
2456
|
+
"amp": "&",
|
|
2457
|
+
"gt": ">",
|
|
2458
|
+
"lt": "<",
|
|
2459
|
+
"quot": '"',
|
|
2460
|
+
"apos": "'"
|
|
2461
|
+
};
|
|
2462
|
+
sax2.ENTITIES = {
|
|
2463
|
+
"amp": "&",
|
|
2464
|
+
"gt": ">",
|
|
2465
|
+
"lt": "<",
|
|
2466
|
+
"quot": '"',
|
|
2467
|
+
"apos": "'",
|
|
2468
|
+
"AElig": 198,
|
|
2469
|
+
"Aacute": 193,
|
|
2470
|
+
"Acirc": 194,
|
|
2471
|
+
"Agrave": 192,
|
|
2472
|
+
"Aring": 197,
|
|
2473
|
+
"Atilde": 195,
|
|
2474
|
+
"Auml": 196,
|
|
2475
|
+
"Ccedil": 199,
|
|
2476
|
+
"ETH": 208,
|
|
2477
|
+
"Eacute": 201,
|
|
2478
|
+
"Ecirc": 202,
|
|
2479
|
+
"Egrave": 200,
|
|
2480
|
+
"Euml": 203,
|
|
2481
|
+
"Iacute": 205,
|
|
2482
|
+
"Icirc": 206,
|
|
2483
|
+
"Igrave": 204,
|
|
2484
|
+
"Iuml": 207,
|
|
2485
|
+
"Ntilde": 209,
|
|
2486
|
+
"Oacute": 211,
|
|
2487
|
+
"Ocirc": 212,
|
|
2488
|
+
"Ograve": 210,
|
|
2489
|
+
"Oslash": 216,
|
|
2490
|
+
"Otilde": 213,
|
|
2491
|
+
"Ouml": 214,
|
|
2492
|
+
"THORN": 222,
|
|
2493
|
+
"Uacute": 218,
|
|
2494
|
+
"Ucirc": 219,
|
|
2495
|
+
"Ugrave": 217,
|
|
2496
|
+
"Uuml": 220,
|
|
2497
|
+
"Yacute": 221,
|
|
2498
|
+
"aacute": 225,
|
|
2499
|
+
"acirc": 226,
|
|
2500
|
+
"aelig": 230,
|
|
2501
|
+
"agrave": 224,
|
|
2502
|
+
"aring": 229,
|
|
2503
|
+
"atilde": 227,
|
|
2504
|
+
"auml": 228,
|
|
2505
|
+
"ccedil": 231,
|
|
2506
|
+
"eacute": 233,
|
|
2507
|
+
"ecirc": 234,
|
|
2508
|
+
"egrave": 232,
|
|
2509
|
+
"eth": 240,
|
|
2510
|
+
"euml": 235,
|
|
2511
|
+
"iacute": 237,
|
|
2512
|
+
"icirc": 238,
|
|
2513
|
+
"igrave": 236,
|
|
2514
|
+
"iuml": 239,
|
|
2515
|
+
"ntilde": 241,
|
|
2516
|
+
"oacute": 243,
|
|
2517
|
+
"ocirc": 244,
|
|
2518
|
+
"ograve": 242,
|
|
2519
|
+
"oslash": 248,
|
|
2520
|
+
"otilde": 245,
|
|
2521
|
+
"ouml": 246,
|
|
2522
|
+
"szlig": 223,
|
|
2523
|
+
"thorn": 254,
|
|
2524
|
+
"uacute": 250,
|
|
2525
|
+
"ucirc": 251,
|
|
2526
|
+
"ugrave": 249,
|
|
2527
|
+
"uuml": 252,
|
|
2528
|
+
"yacute": 253,
|
|
2529
|
+
"yuml": 255,
|
|
2530
|
+
"copy": 169,
|
|
2531
|
+
"reg": 174,
|
|
2532
|
+
"nbsp": 160,
|
|
2533
|
+
"iexcl": 161,
|
|
2534
|
+
"cent": 162,
|
|
2535
|
+
"pound": 163,
|
|
2536
|
+
"curren": 164,
|
|
2537
|
+
"yen": 165,
|
|
2538
|
+
"brvbar": 166,
|
|
2539
|
+
"sect": 167,
|
|
2540
|
+
"uml": 168,
|
|
2541
|
+
"ordf": 170,
|
|
2542
|
+
"laquo": 171,
|
|
2543
|
+
"not": 172,
|
|
2544
|
+
"shy": 173,
|
|
2545
|
+
"macr": 175,
|
|
2546
|
+
"deg": 176,
|
|
2547
|
+
"plusmn": 177,
|
|
2548
|
+
"sup1": 185,
|
|
2549
|
+
"sup2": 178,
|
|
2550
|
+
"sup3": 179,
|
|
2551
|
+
"acute": 180,
|
|
2552
|
+
"micro": 181,
|
|
2553
|
+
"para": 182,
|
|
2554
|
+
"middot": 183,
|
|
2555
|
+
"cedil": 184,
|
|
2556
|
+
"ordm": 186,
|
|
2557
|
+
"raquo": 187,
|
|
2558
|
+
"frac14": 188,
|
|
2559
|
+
"frac12": 189,
|
|
2560
|
+
"frac34": 190,
|
|
2561
|
+
"iquest": 191,
|
|
2562
|
+
"times": 215,
|
|
2563
|
+
"divide": 247,
|
|
2564
|
+
"OElig": 338,
|
|
2565
|
+
"oelig": 339,
|
|
2566
|
+
"Scaron": 352,
|
|
2567
|
+
"scaron": 353,
|
|
2568
|
+
"Yuml": 376,
|
|
2569
|
+
"fnof": 402,
|
|
2570
|
+
"circ": 710,
|
|
2571
|
+
"tilde": 732,
|
|
2572
|
+
"Alpha": 913,
|
|
2573
|
+
"Beta": 914,
|
|
2574
|
+
"Gamma": 915,
|
|
2575
|
+
"Delta": 916,
|
|
2576
|
+
"Epsilon": 917,
|
|
2577
|
+
"Zeta": 918,
|
|
2578
|
+
"Eta": 919,
|
|
2579
|
+
"Theta": 920,
|
|
2580
|
+
"Iota": 921,
|
|
2581
|
+
"Kappa": 922,
|
|
2582
|
+
"Lambda": 923,
|
|
2583
|
+
"Mu": 924,
|
|
2584
|
+
"Nu": 925,
|
|
2585
|
+
"Xi": 926,
|
|
2586
|
+
"Omicron": 927,
|
|
2587
|
+
"Pi": 928,
|
|
2588
|
+
"Rho": 929,
|
|
2589
|
+
"Sigma": 931,
|
|
2590
|
+
"Tau": 932,
|
|
2591
|
+
"Upsilon": 933,
|
|
2592
|
+
"Phi": 934,
|
|
2593
|
+
"Chi": 935,
|
|
2594
|
+
"Psi": 936,
|
|
2595
|
+
"Omega": 937,
|
|
2596
|
+
"alpha": 945,
|
|
2597
|
+
"beta": 946,
|
|
2598
|
+
"gamma": 947,
|
|
2599
|
+
"delta": 948,
|
|
2600
|
+
"epsilon": 949,
|
|
2601
|
+
"zeta": 950,
|
|
2602
|
+
"eta": 951,
|
|
2603
|
+
"theta": 952,
|
|
2604
|
+
"iota": 953,
|
|
2605
|
+
"kappa": 954,
|
|
2606
|
+
"lambda": 955,
|
|
2607
|
+
"mu": 956,
|
|
2608
|
+
"nu": 957,
|
|
2609
|
+
"xi": 958,
|
|
2610
|
+
"omicron": 959,
|
|
2611
|
+
"pi": 960,
|
|
2612
|
+
"rho": 961,
|
|
2613
|
+
"sigmaf": 962,
|
|
2614
|
+
"sigma": 963,
|
|
2615
|
+
"tau": 964,
|
|
2616
|
+
"upsilon": 965,
|
|
2617
|
+
"phi": 966,
|
|
2618
|
+
"chi": 967,
|
|
2619
|
+
"psi": 968,
|
|
2620
|
+
"omega": 969,
|
|
2621
|
+
"thetasym": 977,
|
|
2622
|
+
"upsih": 978,
|
|
2623
|
+
"piv": 982,
|
|
2624
|
+
"ensp": 8194,
|
|
2625
|
+
"emsp": 8195,
|
|
2626
|
+
"thinsp": 8201,
|
|
2627
|
+
"zwnj": 8204,
|
|
2628
|
+
"zwj": 8205,
|
|
2629
|
+
"lrm": 8206,
|
|
2630
|
+
"rlm": 8207,
|
|
2631
|
+
"ndash": 8211,
|
|
2632
|
+
"mdash": 8212,
|
|
2633
|
+
"lsquo": 8216,
|
|
2634
|
+
"rsquo": 8217,
|
|
2635
|
+
"sbquo": 8218,
|
|
2636
|
+
"ldquo": 8220,
|
|
2637
|
+
"rdquo": 8221,
|
|
2638
|
+
"bdquo": 8222,
|
|
2639
|
+
"dagger": 8224,
|
|
2640
|
+
"Dagger": 8225,
|
|
2641
|
+
"bull": 8226,
|
|
2642
|
+
"hellip": 8230,
|
|
2643
|
+
"permil": 8240,
|
|
2644
|
+
"prime": 8242,
|
|
2645
|
+
"Prime": 8243,
|
|
2646
|
+
"lsaquo": 8249,
|
|
2647
|
+
"rsaquo": 8250,
|
|
2648
|
+
"oline": 8254,
|
|
2649
|
+
"frasl": 8260,
|
|
2650
|
+
"euro": 8364,
|
|
2651
|
+
"image": 8465,
|
|
2652
|
+
"weierp": 8472,
|
|
2653
|
+
"real": 8476,
|
|
2654
|
+
"trade": 8482,
|
|
2655
|
+
"alefsym": 8501,
|
|
2656
|
+
"larr": 8592,
|
|
2657
|
+
"uarr": 8593,
|
|
2658
|
+
"rarr": 8594,
|
|
2659
|
+
"darr": 8595,
|
|
2660
|
+
"harr": 8596,
|
|
2661
|
+
"crarr": 8629,
|
|
2662
|
+
"lArr": 8656,
|
|
2663
|
+
"uArr": 8657,
|
|
2664
|
+
"rArr": 8658,
|
|
2665
|
+
"dArr": 8659,
|
|
2666
|
+
"hArr": 8660,
|
|
2667
|
+
"forall": 8704,
|
|
2668
|
+
"part": 8706,
|
|
2669
|
+
"exist": 8707,
|
|
2670
|
+
"empty": 8709,
|
|
2671
|
+
"nabla": 8711,
|
|
2672
|
+
"isin": 8712,
|
|
2673
|
+
"notin": 8713,
|
|
2674
|
+
"ni": 8715,
|
|
2675
|
+
"prod": 8719,
|
|
2676
|
+
"sum": 8721,
|
|
2677
|
+
"minus": 8722,
|
|
2678
|
+
"lowast": 8727,
|
|
2679
|
+
"radic": 8730,
|
|
2680
|
+
"prop": 8733,
|
|
2681
|
+
"infin": 8734,
|
|
2682
|
+
"ang": 8736,
|
|
2683
|
+
"and": 8743,
|
|
2684
|
+
"or": 8744,
|
|
2685
|
+
"cap": 8745,
|
|
2686
|
+
"cup": 8746,
|
|
2687
|
+
"int": 8747,
|
|
2688
|
+
"there4": 8756,
|
|
2689
|
+
"sim": 8764,
|
|
2690
|
+
"cong": 8773,
|
|
2691
|
+
"asymp": 8776,
|
|
2692
|
+
"ne": 8800,
|
|
2693
|
+
"equiv": 8801,
|
|
2694
|
+
"le": 8804,
|
|
2695
|
+
"ge": 8805,
|
|
2696
|
+
"sub": 8834,
|
|
2697
|
+
"sup": 8835,
|
|
2698
|
+
"nsub": 8836,
|
|
2699
|
+
"sube": 8838,
|
|
2700
|
+
"supe": 8839,
|
|
2701
|
+
"oplus": 8853,
|
|
2702
|
+
"otimes": 8855,
|
|
2703
|
+
"perp": 8869,
|
|
2704
|
+
"sdot": 8901,
|
|
2705
|
+
"lceil": 8968,
|
|
2706
|
+
"rceil": 8969,
|
|
2707
|
+
"lfloor": 8970,
|
|
2708
|
+
"rfloor": 8971,
|
|
2709
|
+
"lang": 9001,
|
|
2710
|
+
"rang": 9002,
|
|
2711
|
+
"loz": 9674,
|
|
2712
|
+
"spades": 9824,
|
|
2713
|
+
"clubs": 9827,
|
|
2714
|
+
"hearts": 9829,
|
|
2715
|
+
"diams": 9830
|
|
2716
|
+
};
|
|
2717
|
+
Object.keys(sax2.ENTITIES).forEach(function(key) {
|
|
2718
|
+
var e = sax2.ENTITIES[key];
|
|
2719
|
+
var s2 = typeof e === "number" ? String.fromCharCode(e) : e;
|
|
2720
|
+
sax2.ENTITIES[key] = s2;
|
|
2721
|
+
});
|
|
2722
|
+
for (var s in sax2.STATE) {
|
|
2723
|
+
sax2.STATE[sax2.STATE[s]] = s;
|
|
2724
|
+
}
|
|
2725
|
+
S = sax2.STATE;
|
|
2726
|
+
function emit(parser, event, data) {
|
|
2727
|
+
parser[event] && parser[event](data);
|
|
2728
|
+
}
|
|
2729
|
+
function emitNode(parser, nodeType, data) {
|
|
2730
|
+
if (parser.textNode) closeText(parser);
|
|
2731
|
+
emit(parser, nodeType, data);
|
|
2732
|
+
}
|
|
2733
|
+
function closeText(parser) {
|
|
2734
|
+
parser.textNode = textopts(parser.opt, parser.textNode);
|
|
2735
|
+
if (parser.textNode) emit(parser, "ontext", parser.textNode);
|
|
2736
|
+
parser.textNode = "";
|
|
2737
|
+
}
|
|
2738
|
+
function textopts(opt, text) {
|
|
2739
|
+
if (opt.trim) text = text.trim();
|
|
2740
|
+
if (opt.normalize) text = text.replace(/\s+/g, " ");
|
|
2741
|
+
return text;
|
|
2742
|
+
}
|
|
2743
|
+
function error(parser, er) {
|
|
2744
|
+
closeText(parser);
|
|
2745
|
+
if (parser.trackPosition) {
|
|
2746
|
+
er += "\nLine: " + parser.line + "\nColumn: " + parser.column + "\nChar: " + parser.c;
|
|
2747
|
+
}
|
|
2748
|
+
er = new Error(er);
|
|
2749
|
+
parser.error = er;
|
|
2750
|
+
emit(parser, "onerror", er);
|
|
2751
|
+
return parser;
|
|
2752
|
+
}
|
|
2753
|
+
function end(parser) {
|
|
2754
|
+
if (parser.sawRoot && !parser.closedRoot) strictFail(parser, "Unclosed root tag");
|
|
2755
|
+
if (parser.state !== S.BEGIN && parser.state !== S.BEGIN_WHITESPACE && parser.state !== S.TEXT) {
|
|
2756
|
+
error(parser, "Unexpected end");
|
|
2757
|
+
}
|
|
2758
|
+
closeText(parser);
|
|
2759
|
+
parser.c = "";
|
|
2760
|
+
parser.closed = true;
|
|
2761
|
+
emit(parser, "onend");
|
|
2762
|
+
SAXParser.call(parser, parser.strict, parser.opt);
|
|
2763
|
+
return parser;
|
|
2764
|
+
}
|
|
2765
|
+
function strictFail(parser, message) {
|
|
2766
|
+
if (typeof parser !== "object" || !(parser instanceof SAXParser)) {
|
|
2767
|
+
throw new Error("bad call to strictFail");
|
|
2768
|
+
}
|
|
2769
|
+
if (parser.strict) {
|
|
2770
|
+
error(parser, message);
|
|
2771
|
+
}
|
|
2772
|
+
}
|
|
2773
|
+
function newTag(parser) {
|
|
2774
|
+
if (!parser.strict) parser.tagName = parser.tagName[parser.looseCase]();
|
|
2775
|
+
var parent = parser.tags[parser.tags.length - 1] || parser;
|
|
2776
|
+
var tag = parser.tag = { name: parser.tagName, attributes: {} };
|
|
2777
|
+
if (parser.opt.xmlns) {
|
|
2778
|
+
tag.ns = parent.ns;
|
|
2779
|
+
}
|
|
2780
|
+
parser.attribList.length = 0;
|
|
2781
|
+
emitNode(parser, "onopentagstart", tag);
|
|
2782
|
+
}
|
|
2783
|
+
function qname(name, attribute) {
|
|
2784
|
+
var i = name.indexOf(":");
|
|
2785
|
+
var qualName = i < 0 ? ["", name] : name.split(":");
|
|
2786
|
+
var prefix = qualName[0];
|
|
2787
|
+
var local = qualName[1];
|
|
2788
|
+
if (attribute && name === "xmlns") {
|
|
2789
|
+
prefix = "xmlns";
|
|
2790
|
+
local = "";
|
|
2791
|
+
}
|
|
2792
|
+
return { prefix, local };
|
|
2793
|
+
}
|
|
2794
|
+
function attrib(parser) {
|
|
2795
|
+
if (!parser.strict) {
|
|
2796
|
+
parser.attribName = parser.attribName[parser.looseCase]();
|
|
2797
|
+
}
|
|
2798
|
+
if (parser.attribList.indexOf(parser.attribName) !== -1 || parser.tag.attributes.hasOwnProperty(parser.attribName)) {
|
|
2799
|
+
parser.attribName = parser.attribValue = "";
|
|
2800
|
+
return;
|
|
2801
|
+
}
|
|
2802
|
+
if (parser.opt.xmlns) {
|
|
2803
|
+
var qn = qname(parser.attribName, true);
|
|
2804
|
+
var prefix = qn.prefix;
|
|
2805
|
+
var local = qn.local;
|
|
2806
|
+
if (prefix === "xmlns") {
|
|
2807
|
+
if (local === "xml" && parser.attribValue !== XML_NAMESPACE) {
|
|
2808
|
+
strictFail(
|
|
2809
|
+
parser,
|
|
2810
|
+
"xml: prefix must be bound to " + XML_NAMESPACE + "\nActual: " + parser.attribValue
|
|
2811
|
+
);
|
|
2812
|
+
} else if (local === "xmlns" && parser.attribValue !== XMLNS_NAMESPACE) {
|
|
2813
|
+
strictFail(
|
|
2814
|
+
parser,
|
|
2815
|
+
"xmlns: prefix must be bound to " + XMLNS_NAMESPACE + "\nActual: " + parser.attribValue
|
|
2816
|
+
);
|
|
2817
|
+
} else {
|
|
2818
|
+
var tag = parser.tag;
|
|
2819
|
+
var parent = parser.tags[parser.tags.length - 1] || parser;
|
|
2820
|
+
if (tag.ns === parent.ns) {
|
|
2821
|
+
tag.ns = Object.create(parent.ns);
|
|
2822
|
+
}
|
|
2823
|
+
tag.ns[local] = parser.attribValue;
|
|
2824
|
+
}
|
|
2825
|
+
}
|
|
2826
|
+
parser.attribList.push([parser.attribName, parser.attribValue]);
|
|
2827
|
+
} else {
|
|
2828
|
+
parser.tag.attributes[parser.attribName] = parser.attribValue;
|
|
2829
|
+
emitNode(parser, "onattribute", {
|
|
2830
|
+
name: parser.attribName,
|
|
2831
|
+
value: parser.attribValue
|
|
2832
|
+
});
|
|
2833
|
+
}
|
|
2834
|
+
parser.attribName = parser.attribValue = "";
|
|
2835
|
+
}
|
|
2836
|
+
function openTag(parser, selfClosing) {
|
|
2837
|
+
if (parser.opt.xmlns) {
|
|
2838
|
+
var tag = parser.tag;
|
|
2839
|
+
var qn = qname(parser.tagName);
|
|
2840
|
+
tag.prefix = qn.prefix;
|
|
2841
|
+
tag.local = qn.local;
|
|
2842
|
+
tag.uri = tag.ns[qn.prefix] || "";
|
|
2843
|
+
if (tag.prefix && !tag.uri) {
|
|
2844
|
+
strictFail(parser, "Unbound namespace prefix: " + JSON.stringify(parser.tagName));
|
|
2845
|
+
tag.uri = qn.prefix;
|
|
2846
|
+
}
|
|
2847
|
+
var parent = parser.tags[parser.tags.length - 1] || parser;
|
|
2848
|
+
if (tag.ns && parent.ns !== tag.ns) {
|
|
2849
|
+
Object.keys(tag.ns).forEach(function(p) {
|
|
2850
|
+
emitNode(parser, "onopennamespace", {
|
|
2851
|
+
prefix: p,
|
|
2852
|
+
uri: tag.ns[p]
|
|
2853
|
+
});
|
|
2854
|
+
});
|
|
2855
|
+
}
|
|
2856
|
+
for (var i = 0, l = parser.attribList.length; i < l; i++) {
|
|
2857
|
+
var nv = parser.attribList[i];
|
|
2858
|
+
var name = nv[0];
|
|
2859
|
+
var value = nv[1];
|
|
2860
|
+
var qualName = qname(name, true);
|
|
2861
|
+
var prefix = qualName.prefix;
|
|
2862
|
+
var local = qualName.local;
|
|
2863
|
+
var uri = prefix === "" ? "" : tag.ns[prefix] || "";
|
|
2864
|
+
var a = {
|
|
2865
|
+
name,
|
|
2866
|
+
value,
|
|
2867
|
+
prefix,
|
|
2868
|
+
local,
|
|
2869
|
+
uri
|
|
2870
|
+
};
|
|
2871
|
+
if (prefix && prefix !== "xmlns" && !uri) {
|
|
2872
|
+
strictFail(parser, "Unbound namespace prefix: " + JSON.stringify(prefix));
|
|
2873
|
+
a.uri = prefix;
|
|
2874
|
+
}
|
|
2875
|
+
parser.tag.attributes[name] = a;
|
|
2876
|
+
emitNode(parser, "onattribute", a);
|
|
2877
|
+
}
|
|
2878
|
+
parser.attribList.length = 0;
|
|
2879
|
+
}
|
|
2880
|
+
parser.tag.isSelfClosing = !!selfClosing;
|
|
2881
|
+
parser.sawRoot = true;
|
|
2882
|
+
parser.tags.push(parser.tag);
|
|
2883
|
+
emitNode(parser, "onopentag", parser.tag);
|
|
2884
|
+
if (!selfClosing) {
|
|
2885
|
+
if (!parser.noscript && parser.tagName.toLowerCase() === "script") {
|
|
2886
|
+
parser.state = S.SCRIPT;
|
|
2887
|
+
} else {
|
|
2888
|
+
parser.state = S.TEXT;
|
|
2889
|
+
}
|
|
2890
|
+
parser.tag = null;
|
|
2891
|
+
parser.tagName = "";
|
|
2892
|
+
}
|
|
2893
|
+
parser.attribName = parser.attribValue = "";
|
|
2894
|
+
parser.attribList.length = 0;
|
|
2895
|
+
}
|
|
2896
|
+
function closeTag(parser) {
|
|
2897
|
+
if (!parser.tagName) {
|
|
2898
|
+
strictFail(parser, "Weird empty close tag.");
|
|
2899
|
+
parser.textNode += "</>";
|
|
2900
|
+
parser.state = S.TEXT;
|
|
2901
|
+
return;
|
|
2902
|
+
}
|
|
2903
|
+
if (parser.script) {
|
|
2904
|
+
if (parser.tagName !== "script") {
|
|
2905
|
+
parser.script += "</" + parser.tagName + ">";
|
|
2906
|
+
parser.tagName = "";
|
|
2907
|
+
parser.state = S.SCRIPT;
|
|
2908
|
+
return;
|
|
2909
|
+
}
|
|
2910
|
+
emitNode(parser, "onscript", parser.script);
|
|
2911
|
+
parser.script = "";
|
|
2912
|
+
}
|
|
2913
|
+
var t = parser.tags.length;
|
|
2914
|
+
var tagName = parser.tagName;
|
|
2915
|
+
if (!parser.strict) {
|
|
2916
|
+
tagName = tagName[parser.looseCase]();
|
|
2917
|
+
}
|
|
2918
|
+
var closeTo = tagName;
|
|
2919
|
+
while (t--) {
|
|
2920
|
+
var close = parser.tags[t];
|
|
2921
|
+
if (close.name !== closeTo) {
|
|
2922
|
+
strictFail(parser, "Unexpected close tag");
|
|
2923
|
+
} else {
|
|
2924
|
+
break;
|
|
2925
|
+
}
|
|
2926
|
+
}
|
|
2927
|
+
if (t < 0) {
|
|
2928
|
+
strictFail(parser, "Unmatched closing tag: " + parser.tagName);
|
|
2929
|
+
parser.textNode += "</" + parser.tagName + ">";
|
|
2930
|
+
parser.state = S.TEXT;
|
|
2931
|
+
return;
|
|
2932
|
+
}
|
|
2933
|
+
parser.tagName = tagName;
|
|
2934
|
+
var s2 = parser.tags.length;
|
|
2935
|
+
while (s2-- > t) {
|
|
2936
|
+
var tag = parser.tag = parser.tags.pop();
|
|
2937
|
+
parser.tagName = parser.tag.name;
|
|
2938
|
+
emitNode(parser, "onclosetag", parser.tagName);
|
|
2939
|
+
var x = {};
|
|
2940
|
+
for (var i in tag.ns) {
|
|
2941
|
+
x[i] = tag.ns[i];
|
|
2942
|
+
}
|
|
2943
|
+
var parent = parser.tags[parser.tags.length - 1] || parser;
|
|
2944
|
+
if (parser.opt.xmlns && tag.ns !== parent.ns) {
|
|
2945
|
+
Object.keys(tag.ns).forEach(function(p) {
|
|
2946
|
+
var n = tag.ns[p];
|
|
2947
|
+
emitNode(parser, "onclosenamespace", { prefix: p, uri: n });
|
|
2948
|
+
});
|
|
2949
|
+
}
|
|
2950
|
+
}
|
|
2951
|
+
if (t === 0) parser.closedRoot = true;
|
|
2952
|
+
parser.tagName = parser.attribValue = parser.attribName = "";
|
|
2953
|
+
parser.attribList.length = 0;
|
|
2954
|
+
parser.state = S.TEXT;
|
|
2955
|
+
}
|
|
2956
|
+
function parseEntity(parser) {
|
|
2957
|
+
var entity = parser.entity;
|
|
2958
|
+
var entityLC = entity.toLowerCase();
|
|
2959
|
+
var num;
|
|
2960
|
+
var numStr = "";
|
|
2961
|
+
if (parser.ENTITIES[entity]) {
|
|
2962
|
+
return parser.ENTITIES[entity];
|
|
2963
|
+
}
|
|
2964
|
+
if (parser.ENTITIES[entityLC]) {
|
|
2965
|
+
return parser.ENTITIES[entityLC];
|
|
2966
|
+
}
|
|
2967
|
+
entity = entityLC;
|
|
2968
|
+
if (entity.charAt(0) === "#") {
|
|
2969
|
+
if (entity.charAt(1) === "x") {
|
|
2970
|
+
entity = entity.slice(2);
|
|
2971
|
+
num = parseInt(entity, 16);
|
|
2972
|
+
numStr = num.toString(16);
|
|
2973
|
+
} else {
|
|
2974
|
+
entity = entity.slice(1);
|
|
2975
|
+
num = parseInt(entity, 10);
|
|
2976
|
+
numStr = num.toString(10);
|
|
2977
|
+
}
|
|
2978
|
+
}
|
|
2979
|
+
entity = entity.replace(/^0+/, "");
|
|
2980
|
+
if (isNaN(num) || numStr.toLowerCase() !== entity) {
|
|
2981
|
+
strictFail(parser, "Invalid character entity");
|
|
2982
|
+
return "&" + parser.entity + ";";
|
|
2983
|
+
}
|
|
2984
|
+
return String.fromCodePoint(num);
|
|
2985
|
+
}
|
|
2986
|
+
function beginWhiteSpace(parser, c) {
|
|
2987
|
+
if (c === "<") {
|
|
2988
|
+
parser.state = S.OPEN_WAKA;
|
|
2989
|
+
parser.startTagPosition = parser.position;
|
|
2990
|
+
} else if (!isWhitespace(c)) {
|
|
2991
|
+
strictFail(parser, "Non-whitespace before first tag.");
|
|
2992
|
+
parser.textNode = c;
|
|
2993
|
+
parser.state = S.TEXT;
|
|
2994
|
+
}
|
|
2995
|
+
}
|
|
2996
|
+
function charAt(chunk, i) {
|
|
2997
|
+
var result = "";
|
|
2998
|
+
if (i < chunk.length) {
|
|
2999
|
+
result = chunk.charAt(i);
|
|
3000
|
+
}
|
|
3001
|
+
return result;
|
|
3002
|
+
}
|
|
3003
|
+
function write(chunk) {
|
|
3004
|
+
var parser = this;
|
|
3005
|
+
if (this.error) {
|
|
3006
|
+
throw this.error;
|
|
3007
|
+
}
|
|
3008
|
+
if (parser.closed) {
|
|
3009
|
+
return error(
|
|
3010
|
+
parser,
|
|
3011
|
+
"Cannot write after close. Assign an onready handler."
|
|
3012
|
+
);
|
|
3013
|
+
}
|
|
3014
|
+
if (chunk === null) {
|
|
3015
|
+
return end(parser);
|
|
3016
|
+
}
|
|
3017
|
+
if (typeof chunk === "object") {
|
|
3018
|
+
chunk = chunk.toString();
|
|
3019
|
+
}
|
|
3020
|
+
var i = 0;
|
|
3021
|
+
var c = "";
|
|
3022
|
+
while (true) {
|
|
3023
|
+
c = charAt(chunk, i++);
|
|
3024
|
+
parser.c = c;
|
|
3025
|
+
if (!c) {
|
|
3026
|
+
break;
|
|
3027
|
+
}
|
|
3028
|
+
if (parser.trackPosition) {
|
|
3029
|
+
parser.position++;
|
|
3030
|
+
if (c === "\n") {
|
|
3031
|
+
parser.line++;
|
|
3032
|
+
parser.column = 0;
|
|
3033
|
+
} else {
|
|
3034
|
+
parser.column++;
|
|
3035
|
+
}
|
|
3036
|
+
}
|
|
3037
|
+
switch (parser.state) {
|
|
3038
|
+
case S.BEGIN:
|
|
3039
|
+
parser.state = S.BEGIN_WHITESPACE;
|
|
3040
|
+
if (c === "\uFEFF") {
|
|
3041
|
+
continue;
|
|
3042
|
+
}
|
|
3043
|
+
beginWhiteSpace(parser, c);
|
|
3044
|
+
continue;
|
|
3045
|
+
case S.BEGIN_WHITESPACE:
|
|
3046
|
+
beginWhiteSpace(parser, c);
|
|
3047
|
+
continue;
|
|
3048
|
+
case S.TEXT:
|
|
3049
|
+
if (parser.sawRoot && !parser.closedRoot) {
|
|
3050
|
+
var starti = i - 1;
|
|
3051
|
+
while (c && c !== "<" && c !== "&") {
|
|
3052
|
+
c = charAt(chunk, i++);
|
|
3053
|
+
if (c && parser.trackPosition) {
|
|
3054
|
+
parser.position++;
|
|
3055
|
+
if (c === "\n") {
|
|
3056
|
+
parser.line++;
|
|
3057
|
+
parser.column = 0;
|
|
3058
|
+
} else {
|
|
3059
|
+
parser.column++;
|
|
3060
|
+
}
|
|
3061
|
+
}
|
|
3062
|
+
}
|
|
3063
|
+
parser.textNode += chunk.substring(starti, i - 1);
|
|
3064
|
+
}
|
|
3065
|
+
if (c === "<" && !(parser.sawRoot && parser.closedRoot && !parser.strict)) {
|
|
3066
|
+
parser.state = S.OPEN_WAKA;
|
|
3067
|
+
parser.startTagPosition = parser.position;
|
|
3068
|
+
} else {
|
|
3069
|
+
if (!isWhitespace(c) && (!parser.sawRoot || parser.closedRoot)) {
|
|
3070
|
+
strictFail(parser, "Text data outside of root node.");
|
|
3071
|
+
}
|
|
3072
|
+
if (c === "&") {
|
|
3073
|
+
parser.state = S.TEXT_ENTITY;
|
|
3074
|
+
} else {
|
|
3075
|
+
parser.textNode += c;
|
|
3076
|
+
}
|
|
3077
|
+
}
|
|
3078
|
+
continue;
|
|
3079
|
+
case S.SCRIPT:
|
|
3080
|
+
if (c === "<") {
|
|
3081
|
+
parser.state = S.SCRIPT_ENDING;
|
|
3082
|
+
} else {
|
|
3083
|
+
parser.script += c;
|
|
3084
|
+
}
|
|
3085
|
+
continue;
|
|
3086
|
+
case S.SCRIPT_ENDING:
|
|
3087
|
+
if (c === "/") {
|
|
3088
|
+
parser.state = S.CLOSE_TAG;
|
|
3089
|
+
} else {
|
|
3090
|
+
parser.script += "<" + c;
|
|
3091
|
+
parser.state = S.SCRIPT;
|
|
3092
|
+
}
|
|
3093
|
+
continue;
|
|
3094
|
+
case S.OPEN_WAKA:
|
|
3095
|
+
if (c === "!") {
|
|
3096
|
+
parser.state = S.SGML_DECL;
|
|
3097
|
+
parser.sgmlDecl = "";
|
|
3098
|
+
} else if (isWhitespace(c)) ;
|
|
3099
|
+
else if (isMatch(nameStart, c)) {
|
|
3100
|
+
parser.state = S.OPEN_TAG;
|
|
3101
|
+
parser.tagName = c;
|
|
3102
|
+
} else if (c === "/") {
|
|
3103
|
+
parser.state = S.CLOSE_TAG;
|
|
3104
|
+
parser.tagName = "";
|
|
3105
|
+
} else if (c === "?") {
|
|
3106
|
+
parser.state = S.PROC_INST;
|
|
3107
|
+
parser.procInstName = parser.procInstBody = "";
|
|
3108
|
+
} else {
|
|
3109
|
+
strictFail(parser, "Unencoded <");
|
|
3110
|
+
if (parser.startTagPosition + 1 < parser.position) {
|
|
3111
|
+
var pad = parser.position - parser.startTagPosition;
|
|
3112
|
+
c = new Array(pad).join(" ") + c;
|
|
3113
|
+
}
|
|
3114
|
+
parser.textNode += "<" + c;
|
|
3115
|
+
parser.state = S.TEXT;
|
|
3116
|
+
}
|
|
3117
|
+
continue;
|
|
3118
|
+
case S.SGML_DECL:
|
|
3119
|
+
if (parser.sgmlDecl + c === "--") {
|
|
3120
|
+
parser.state = S.COMMENT;
|
|
3121
|
+
parser.comment = "";
|
|
3122
|
+
parser.sgmlDecl = "";
|
|
3123
|
+
continue;
|
|
3124
|
+
}
|
|
3125
|
+
if (parser.doctype && parser.doctype !== true && parser.sgmlDecl) {
|
|
3126
|
+
parser.state = S.DOCTYPE_DTD;
|
|
3127
|
+
parser.doctype += "<!" + parser.sgmlDecl + c;
|
|
3128
|
+
parser.sgmlDecl = "";
|
|
3129
|
+
} else if ((parser.sgmlDecl + c).toUpperCase() === CDATA) {
|
|
3130
|
+
emitNode(parser, "onopencdata");
|
|
3131
|
+
parser.state = S.CDATA;
|
|
3132
|
+
parser.sgmlDecl = "";
|
|
3133
|
+
parser.cdata = "";
|
|
3134
|
+
} else if ((parser.sgmlDecl + c).toUpperCase() === DOCTYPE) {
|
|
3135
|
+
parser.state = S.DOCTYPE;
|
|
3136
|
+
if (parser.doctype || parser.sawRoot) {
|
|
3137
|
+
strictFail(
|
|
3138
|
+
parser,
|
|
3139
|
+
"Inappropriately located doctype declaration"
|
|
3140
|
+
);
|
|
3141
|
+
}
|
|
3142
|
+
parser.doctype = "";
|
|
3143
|
+
parser.sgmlDecl = "";
|
|
3144
|
+
} else if (c === ">") {
|
|
3145
|
+
emitNode(parser, "onsgmldeclaration", parser.sgmlDecl);
|
|
3146
|
+
parser.sgmlDecl = "";
|
|
3147
|
+
parser.state = S.TEXT;
|
|
3148
|
+
} else if (isQuote(c)) {
|
|
3149
|
+
parser.state = S.SGML_DECL_QUOTED;
|
|
3150
|
+
parser.sgmlDecl += c;
|
|
3151
|
+
} else {
|
|
3152
|
+
parser.sgmlDecl += c;
|
|
3153
|
+
}
|
|
3154
|
+
continue;
|
|
3155
|
+
case S.SGML_DECL_QUOTED:
|
|
3156
|
+
if (c === parser.q) {
|
|
3157
|
+
parser.state = S.SGML_DECL;
|
|
3158
|
+
parser.q = "";
|
|
3159
|
+
}
|
|
3160
|
+
parser.sgmlDecl += c;
|
|
3161
|
+
continue;
|
|
3162
|
+
case S.DOCTYPE:
|
|
3163
|
+
if (c === ">") {
|
|
3164
|
+
parser.state = S.TEXT;
|
|
3165
|
+
emitNode(parser, "ondoctype", parser.doctype);
|
|
3166
|
+
parser.doctype = true;
|
|
3167
|
+
} else {
|
|
3168
|
+
parser.doctype += c;
|
|
3169
|
+
if (c === "[") {
|
|
3170
|
+
parser.state = S.DOCTYPE_DTD;
|
|
3171
|
+
} else if (isQuote(c)) {
|
|
3172
|
+
parser.state = S.DOCTYPE_QUOTED;
|
|
3173
|
+
parser.q = c;
|
|
3174
|
+
}
|
|
3175
|
+
}
|
|
3176
|
+
continue;
|
|
3177
|
+
case S.DOCTYPE_QUOTED:
|
|
3178
|
+
parser.doctype += c;
|
|
3179
|
+
if (c === parser.q) {
|
|
3180
|
+
parser.q = "";
|
|
3181
|
+
parser.state = S.DOCTYPE;
|
|
3182
|
+
}
|
|
3183
|
+
continue;
|
|
3184
|
+
case S.DOCTYPE_DTD:
|
|
3185
|
+
if (c === "]") {
|
|
3186
|
+
parser.doctype += c;
|
|
3187
|
+
parser.state = S.DOCTYPE;
|
|
3188
|
+
} else if (c === "<") {
|
|
3189
|
+
parser.state = S.OPEN_WAKA;
|
|
3190
|
+
parser.startTagPosition = parser.position;
|
|
3191
|
+
} else if (isQuote(c)) {
|
|
3192
|
+
parser.doctype += c;
|
|
3193
|
+
parser.state = S.DOCTYPE_DTD_QUOTED;
|
|
3194
|
+
parser.q = c;
|
|
3195
|
+
} else {
|
|
3196
|
+
parser.doctype += c;
|
|
3197
|
+
}
|
|
3198
|
+
continue;
|
|
3199
|
+
case S.DOCTYPE_DTD_QUOTED:
|
|
3200
|
+
parser.doctype += c;
|
|
3201
|
+
if (c === parser.q) {
|
|
3202
|
+
parser.state = S.DOCTYPE_DTD;
|
|
3203
|
+
parser.q = "";
|
|
3204
|
+
}
|
|
3205
|
+
continue;
|
|
3206
|
+
case S.COMMENT:
|
|
3207
|
+
if (c === "-") {
|
|
3208
|
+
parser.state = S.COMMENT_ENDING;
|
|
3209
|
+
} else {
|
|
3210
|
+
parser.comment += c;
|
|
3211
|
+
}
|
|
3212
|
+
continue;
|
|
3213
|
+
case S.COMMENT_ENDING:
|
|
3214
|
+
if (c === "-") {
|
|
3215
|
+
parser.state = S.COMMENT_ENDED;
|
|
3216
|
+
parser.comment = textopts(parser.opt, parser.comment);
|
|
3217
|
+
if (parser.comment) {
|
|
3218
|
+
emitNode(parser, "oncomment", parser.comment);
|
|
3219
|
+
}
|
|
3220
|
+
parser.comment = "";
|
|
3221
|
+
} else {
|
|
3222
|
+
parser.comment += "-" + c;
|
|
3223
|
+
parser.state = S.COMMENT;
|
|
3224
|
+
}
|
|
3225
|
+
continue;
|
|
3226
|
+
case S.COMMENT_ENDED:
|
|
3227
|
+
if (c !== ">") {
|
|
3228
|
+
strictFail(parser, "Malformed comment");
|
|
3229
|
+
parser.comment += "--" + c;
|
|
3230
|
+
parser.state = S.COMMENT;
|
|
3231
|
+
} else if (parser.doctype && parser.doctype !== true) {
|
|
3232
|
+
parser.state = S.DOCTYPE_DTD;
|
|
3233
|
+
} else {
|
|
3234
|
+
parser.state = S.TEXT;
|
|
3235
|
+
}
|
|
3236
|
+
continue;
|
|
3237
|
+
case S.CDATA:
|
|
3238
|
+
if (c === "]") {
|
|
3239
|
+
parser.state = S.CDATA_ENDING;
|
|
3240
|
+
} else {
|
|
3241
|
+
parser.cdata += c;
|
|
3242
|
+
}
|
|
3243
|
+
continue;
|
|
3244
|
+
case S.CDATA_ENDING:
|
|
3245
|
+
if (c === "]") {
|
|
3246
|
+
parser.state = S.CDATA_ENDING_2;
|
|
3247
|
+
} else {
|
|
3248
|
+
parser.cdata += "]" + c;
|
|
3249
|
+
parser.state = S.CDATA;
|
|
3250
|
+
}
|
|
3251
|
+
continue;
|
|
3252
|
+
case S.CDATA_ENDING_2:
|
|
3253
|
+
if (c === ">") {
|
|
3254
|
+
if (parser.cdata) {
|
|
3255
|
+
emitNode(parser, "oncdata", parser.cdata);
|
|
3256
|
+
}
|
|
3257
|
+
emitNode(parser, "onclosecdata");
|
|
3258
|
+
parser.cdata = "";
|
|
3259
|
+
parser.state = S.TEXT;
|
|
3260
|
+
} else if (c === "]") {
|
|
3261
|
+
parser.cdata += "]";
|
|
3262
|
+
} else {
|
|
3263
|
+
parser.cdata += "]]" + c;
|
|
3264
|
+
parser.state = S.CDATA;
|
|
3265
|
+
}
|
|
3266
|
+
continue;
|
|
3267
|
+
case S.PROC_INST:
|
|
3268
|
+
if (c === "?") {
|
|
3269
|
+
parser.state = S.PROC_INST_ENDING;
|
|
3270
|
+
} else if (isWhitespace(c)) {
|
|
3271
|
+
parser.state = S.PROC_INST_BODY;
|
|
3272
|
+
} else {
|
|
3273
|
+
parser.procInstName += c;
|
|
3274
|
+
}
|
|
3275
|
+
continue;
|
|
3276
|
+
case S.PROC_INST_BODY:
|
|
3277
|
+
if (!parser.procInstBody && isWhitespace(c)) {
|
|
3278
|
+
continue;
|
|
3279
|
+
} else if (c === "?") {
|
|
3280
|
+
parser.state = S.PROC_INST_ENDING;
|
|
3281
|
+
} else {
|
|
3282
|
+
parser.procInstBody += c;
|
|
3283
|
+
}
|
|
3284
|
+
continue;
|
|
3285
|
+
case S.PROC_INST_ENDING:
|
|
3286
|
+
if (c === ">") {
|
|
3287
|
+
emitNode(parser, "onprocessinginstruction", {
|
|
3288
|
+
name: parser.procInstName,
|
|
3289
|
+
body: parser.procInstBody
|
|
3290
|
+
});
|
|
3291
|
+
parser.procInstName = parser.procInstBody = "";
|
|
3292
|
+
parser.state = S.TEXT;
|
|
3293
|
+
} else {
|
|
3294
|
+
parser.procInstBody += "?" + c;
|
|
3295
|
+
parser.state = S.PROC_INST_BODY;
|
|
3296
|
+
}
|
|
3297
|
+
continue;
|
|
3298
|
+
case S.OPEN_TAG:
|
|
3299
|
+
if (isMatch(nameBody, c)) {
|
|
3300
|
+
parser.tagName += c;
|
|
3301
|
+
} else {
|
|
3302
|
+
newTag(parser);
|
|
3303
|
+
if (c === ">") {
|
|
3304
|
+
openTag(parser);
|
|
3305
|
+
} else if (c === "/") {
|
|
3306
|
+
parser.state = S.OPEN_TAG_SLASH;
|
|
3307
|
+
} else {
|
|
3308
|
+
if (!isWhitespace(c)) {
|
|
3309
|
+
strictFail(parser, "Invalid character in tag name");
|
|
3310
|
+
}
|
|
3311
|
+
parser.state = S.ATTRIB;
|
|
3312
|
+
}
|
|
3313
|
+
}
|
|
3314
|
+
continue;
|
|
3315
|
+
case S.OPEN_TAG_SLASH:
|
|
3316
|
+
if (c === ">") {
|
|
3317
|
+
openTag(parser, true);
|
|
3318
|
+
closeTag(parser);
|
|
3319
|
+
} else {
|
|
3320
|
+
strictFail(parser, "Forward-slash in opening tag not followed by >");
|
|
3321
|
+
parser.state = S.ATTRIB;
|
|
3322
|
+
}
|
|
3323
|
+
continue;
|
|
3324
|
+
case S.ATTRIB:
|
|
3325
|
+
if (isWhitespace(c)) {
|
|
3326
|
+
continue;
|
|
3327
|
+
} else if (c === ">") {
|
|
3328
|
+
openTag(parser);
|
|
3329
|
+
} else if (c === "/") {
|
|
3330
|
+
parser.state = S.OPEN_TAG_SLASH;
|
|
3331
|
+
} else if (isMatch(nameStart, c)) {
|
|
3332
|
+
parser.attribName = c;
|
|
3333
|
+
parser.attribValue = "";
|
|
3334
|
+
parser.state = S.ATTRIB_NAME;
|
|
3335
|
+
} else {
|
|
3336
|
+
strictFail(parser, "Invalid attribute name");
|
|
3337
|
+
}
|
|
3338
|
+
continue;
|
|
3339
|
+
case S.ATTRIB_NAME:
|
|
3340
|
+
if (c === "=") {
|
|
3341
|
+
parser.state = S.ATTRIB_VALUE;
|
|
3342
|
+
} else if (c === ">") {
|
|
3343
|
+
strictFail(parser, "Attribute without value");
|
|
3344
|
+
parser.attribValue = parser.attribName;
|
|
3345
|
+
attrib(parser);
|
|
3346
|
+
openTag(parser);
|
|
3347
|
+
} else if (isWhitespace(c)) {
|
|
3348
|
+
parser.state = S.ATTRIB_NAME_SAW_WHITE;
|
|
3349
|
+
} else if (isMatch(nameBody, c)) {
|
|
3350
|
+
parser.attribName += c;
|
|
3351
|
+
} else {
|
|
3352
|
+
strictFail(parser, "Invalid attribute name");
|
|
3353
|
+
}
|
|
3354
|
+
continue;
|
|
3355
|
+
case S.ATTRIB_NAME_SAW_WHITE:
|
|
3356
|
+
if (c === "=") {
|
|
3357
|
+
parser.state = S.ATTRIB_VALUE;
|
|
3358
|
+
} else if (isWhitespace(c)) {
|
|
3359
|
+
continue;
|
|
3360
|
+
} else {
|
|
3361
|
+
strictFail(parser, "Attribute without value");
|
|
3362
|
+
parser.tag.attributes[parser.attribName] = "";
|
|
3363
|
+
parser.attribValue = "";
|
|
3364
|
+
emitNode(parser, "onattribute", {
|
|
3365
|
+
name: parser.attribName,
|
|
3366
|
+
value: ""
|
|
3367
|
+
});
|
|
3368
|
+
parser.attribName = "";
|
|
3369
|
+
if (c === ">") {
|
|
3370
|
+
openTag(parser);
|
|
3371
|
+
} else if (isMatch(nameStart, c)) {
|
|
3372
|
+
parser.attribName = c;
|
|
3373
|
+
parser.state = S.ATTRIB_NAME;
|
|
3374
|
+
} else {
|
|
3375
|
+
strictFail(parser, "Invalid attribute name");
|
|
3376
|
+
parser.state = S.ATTRIB;
|
|
3377
|
+
}
|
|
3378
|
+
}
|
|
3379
|
+
continue;
|
|
3380
|
+
case S.ATTRIB_VALUE:
|
|
3381
|
+
if (isWhitespace(c)) {
|
|
3382
|
+
continue;
|
|
3383
|
+
} else if (isQuote(c)) {
|
|
3384
|
+
parser.q = c;
|
|
3385
|
+
parser.state = S.ATTRIB_VALUE_QUOTED;
|
|
3386
|
+
} else {
|
|
3387
|
+
if (!parser.opt.unquotedAttributeValues) {
|
|
3388
|
+
error(parser, "Unquoted attribute value");
|
|
3389
|
+
}
|
|
3390
|
+
parser.state = S.ATTRIB_VALUE_UNQUOTED;
|
|
3391
|
+
parser.attribValue = c;
|
|
3392
|
+
}
|
|
3393
|
+
continue;
|
|
3394
|
+
case S.ATTRIB_VALUE_QUOTED:
|
|
3395
|
+
if (c !== parser.q) {
|
|
3396
|
+
if (c === "&") {
|
|
3397
|
+
parser.state = S.ATTRIB_VALUE_ENTITY_Q;
|
|
3398
|
+
} else {
|
|
3399
|
+
parser.attribValue += c;
|
|
3400
|
+
}
|
|
3401
|
+
continue;
|
|
3402
|
+
}
|
|
3403
|
+
attrib(parser);
|
|
3404
|
+
parser.q = "";
|
|
3405
|
+
parser.state = S.ATTRIB_VALUE_CLOSED;
|
|
3406
|
+
continue;
|
|
3407
|
+
case S.ATTRIB_VALUE_CLOSED:
|
|
3408
|
+
if (isWhitespace(c)) {
|
|
3409
|
+
parser.state = S.ATTRIB;
|
|
3410
|
+
} else if (c === ">") {
|
|
3411
|
+
openTag(parser);
|
|
3412
|
+
} else if (c === "/") {
|
|
3413
|
+
parser.state = S.OPEN_TAG_SLASH;
|
|
3414
|
+
} else if (isMatch(nameStart, c)) {
|
|
3415
|
+
strictFail(parser, "No whitespace between attributes");
|
|
3416
|
+
parser.attribName = c;
|
|
3417
|
+
parser.attribValue = "";
|
|
3418
|
+
parser.state = S.ATTRIB_NAME;
|
|
3419
|
+
} else {
|
|
3420
|
+
strictFail(parser, "Invalid attribute name");
|
|
3421
|
+
}
|
|
3422
|
+
continue;
|
|
3423
|
+
case S.ATTRIB_VALUE_UNQUOTED:
|
|
3424
|
+
if (!isAttribEnd(c)) {
|
|
3425
|
+
if (c === "&") {
|
|
3426
|
+
parser.state = S.ATTRIB_VALUE_ENTITY_U;
|
|
3427
|
+
} else {
|
|
3428
|
+
parser.attribValue += c;
|
|
3429
|
+
}
|
|
3430
|
+
continue;
|
|
3431
|
+
}
|
|
3432
|
+
attrib(parser);
|
|
3433
|
+
if (c === ">") {
|
|
3434
|
+
openTag(parser);
|
|
3435
|
+
} else {
|
|
3436
|
+
parser.state = S.ATTRIB;
|
|
3437
|
+
}
|
|
3438
|
+
continue;
|
|
3439
|
+
case S.CLOSE_TAG:
|
|
3440
|
+
if (!parser.tagName) {
|
|
3441
|
+
if (isWhitespace(c)) {
|
|
3442
|
+
continue;
|
|
3443
|
+
} else if (notMatch(nameStart, c)) {
|
|
3444
|
+
if (parser.script) {
|
|
3445
|
+
parser.script += "</" + c;
|
|
3446
|
+
parser.state = S.SCRIPT;
|
|
3447
|
+
} else {
|
|
3448
|
+
strictFail(parser, "Invalid tagname in closing tag.");
|
|
3449
|
+
}
|
|
3450
|
+
} else {
|
|
3451
|
+
parser.tagName = c;
|
|
3452
|
+
}
|
|
3453
|
+
} else if (c === ">") {
|
|
3454
|
+
closeTag(parser);
|
|
3455
|
+
} else if (isMatch(nameBody, c)) {
|
|
3456
|
+
parser.tagName += c;
|
|
3457
|
+
} else if (parser.script) {
|
|
3458
|
+
parser.script += "</" + parser.tagName;
|
|
3459
|
+
parser.tagName = "";
|
|
3460
|
+
parser.state = S.SCRIPT;
|
|
3461
|
+
} else {
|
|
3462
|
+
if (!isWhitespace(c)) {
|
|
3463
|
+
strictFail(parser, "Invalid tagname in closing tag");
|
|
3464
|
+
}
|
|
3465
|
+
parser.state = S.CLOSE_TAG_SAW_WHITE;
|
|
3466
|
+
}
|
|
3467
|
+
continue;
|
|
3468
|
+
case S.CLOSE_TAG_SAW_WHITE:
|
|
3469
|
+
if (isWhitespace(c)) {
|
|
3470
|
+
continue;
|
|
3471
|
+
}
|
|
3472
|
+
if (c === ">") {
|
|
3473
|
+
closeTag(parser);
|
|
3474
|
+
} else {
|
|
3475
|
+
strictFail(parser, "Invalid characters in closing tag");
|
|
3476
|
+
}
|
|
3477
|
+
continue;
|
|
3478
|
+
case S.TEXT_ENTITY:
|
|
3479
|
+
case S.ATTRIB_VALUE_ENTITY_Q:
|
|
3480
|
+
case S.ATTRIB_VALUE_ENTITY_U:
|
|
3481
|
+
var returnState;
|
|
3482
|
+
var buffer2;
|
|
3483
|
+
switch (parser.state) {
|
|
3484
|
+
case S.TEXT_ENTITY:
|
|
3485
|
+
returnState = S.TEXT;
|
|
3486
|
+
buffer2 = "textNode";
|
|
3487
|
+
break;
|
|
3488
|
+
case S.ATTRIB_VALUE_ENTITY_Q:
|
|
3489
|
+
returnState = S.ATTRIB_VALUE_QUOTED;
|
|
3490
|
+
buffer2 = "attribValue";
|
|
3491
|
+
break;
|
|
3492
|
+
case S.ATTRIB_VALUE_ENTITY_U:
|
|
3493
|
+
returnState = S.ATTRIB_VALUE_UNQUOTED;
|
|
3494
|
+
buffer2 = "attribValue";
|
|
3495
|
+
break;
|
|
3496
|
+
}
|
|
3497
|
+
if (c === ";") {
|
|
3498
|
+
var parsedEntity = parseEntity(parser);
|
|
3499
|
+
if (parser.opt.unparsedEntities && !Object.values(sax2.XML_ENTITIES).includes(parsedEntity)) {
|
|
3500
|
+
parser.entity = "";
|
|
3501
|
+
parser.state = returnState;
|
|
3502
|
+
parser.write(parsedEntity);
|
|
3503
|
+
} else {
|
|
3504
|
+
parser[buffer2] += parsedEntity;
|
|
3505
|
+
parser.entity = "";
|
|
3506
|
+
parser.state = returnState;
|
|
3507
|
+
}
|
|
3508
|
+
} else if (isMatch(parser.entity.length ? entityBody : entityStart, c)) {
|
|
3509
|
+
parser.entity += c;
|
|
3510
|
+
} else {
|
|
3511
|
+
strictFail(parser, "Invalid character in entity name");
|
|
3512
|
+
parser[buffer2] += "&" + parser.entity + c;
|
|
3513
|
+
parser.entity = "";
|
|
3514
|
+
parser.state = returnState;
|
|
3515
|
+
}
|
|
3516
|
+
continue;
|
|
3517
|
+
default: {
|
|
3518
|
+
throw new Error(parser, "Unknown state: " + parser.state);
|
|
3519
|
+
}
|
|
3520
|
+
}
|
|
3521
|
+
}
|
|
3522
|
+
if (parser.position >= parser.bufferCheckPosition) {
|
|
3523
|
+
checkBufferLength(parser);
|
|
3524
|
+
}
|
|
3525
|
+
return parser;
|
|
3526
|
+
}
|
|
3527
|
+
/*! http://mths.be/fromcodepoint v0.1.0 by @mathias */
|
|
3528
|
+
if (!String.fromCodePoint) {
|
|
3529
|
+
(function() {
|
|
3530
|
+
var stringFromCharCode = String.fromCharCode;
|
|
3531
|
+
var floor = Math.floor;
|
|
3532
|
+
var fromCodePoint = function() {
|
|
3533
|
+
var MAX_SIZE = 16384;
|
|
3534
|
+
var codeUnits = [];
|
|
3535
|
+
var highSurrogate;
|
|
3536
|
+
var lowSurrogate;
|
|
3537
|
+
var index = -1;
|
|
3538
|
+
var length = arguments.length;
|
|
3539
|
+
if (!length) {
|
|
3540
|
+
return "";
|
|
3541
|
+
}
|
|
3542
|
+
var result = "";
|
|
3543
|
+
while (++index < length) {
|
|
3544
|
+
var codePoint = Number(arguments[index]);
|
|
3545
|
+
if (!isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
|
|
3546
|
+
codePoint < 0 || // not a valid Unicode code point
|
|
3547
|
+
codePoint > 1114111 || // not a valid Unicode code point
|
|
3548
|
+
floor(codePoint) !== codePoint) {
|
|
3549
|
+
throw RangeError("Invalid code point: " + codePoint);
|
|
3550
|
+
}
|
|
3551
|
+
if (codePoint <= 65535) {
|
|
3552
|
+
codeUnits.push(codePoint);
|
|
3553
|
+
} else {
|
|
3554
|
+
codePoint -= 65536;
|
|
3555
|
+
highSurrogate = (codePoint >> 10) + 55296;
|
|
3556
|
+
lowSurrogate = codePoint % 1024 + 56320;
|
|
3557
|
+
codeUnits.push(highSurrogate, lowSurrogate);
|
|
3558
|
+
}
|
|
3559
|
+
if (index + 1 === length || codeUnits.length > MAX_SIZE) {
|
|
3560
|
+
result += stringFromCharCode.apply(null, codeUnits);
|
|
3561
|
+
codeUnits.length = 0;
|
|
3562
|
+
}
|
|
3563
|
+
}
|
|
3564
|
+
return result;
|
|
3565
|
+
};
|
|
3566
|
+
if (Object.defineProperty) {
|
|
3567
|
+
Object.defineProperty(String, "fromCodePoint", {
|
|
3568
|
+
value: fromCodePoint,
|
|
3569
|
+
configurable: true,
|
|
3570
|
+
writable: true
|
|
3571
|
+
});
|
|
3572
|
+
} else {
|
|
3573
|
+
String.fromCodePoint = fromCodePoint;
|
|
3574
|
+
}
|
|
3575
|
+
})();
|
|
3576
|
+
}
|
|
3577
|
+
})(exports);
|
|
3578
|
+
})(sax);
|
|
3579
|
+
return sax;
|
|
3580
|
+
}
|
|
3581
|
+
var arrayHelper;
|
|
3582
|
+
var hasRequiredArrayHelper;
|
|
3583
|
+
function requireArrayHelper() {
|
|
3584
|
+
if (hasRequiredArrayHelper) return arrayHelper;
|
|
3585
|
+
hasRequiredArrayHelper = 1;
|
|
3586
|
+
arrayHelper = {
|
|
3587
|
+
isArray: function(value) {
|
|
3588
|
+
if (Array.isArray) {
|
|
3589
|
+
return Array.isArray(value);
|
|
3590
|
+
}
|
|
3591
|
+
return Object.prototype.toString.call(value) === "[object Array]";
|
|
3592
|
+
}
|
|
3593
|
+
};
|
|
3594
|
+
return arrayHelper;
|
|
3595
|
+
}
|
|
3596
|
+
var optionsHelper;
|
|
3597
|
+
var hasRequiredOptionsHelper;
|
|
3598
|
+
function requireOptionsHelper() {
|
|
3599
|
+
if (hasRequiredOptionsHelper) return optionsHelper;
|
|
3600
|
+
hasRequiredOptionsHelper = 1;
|
|
3601
|
+
var isArray = requireArrayHelper().isArray;
|
|
3602
|
+
optionsHelper = {
|
|
3603
|
+
copyOptions: function(options) {
|
|
3604
|
+
var key, copy = {};
|
|
3605
|
+
for (key in options) {
|
|
3606
|
+
if (options.hasOwnProperty(key)) {
|
|
3607
|
+
copy[key] = options[key];
|
|
3608
|
+
}
|
|
3609
|
+
}
|
|
3610
|
+
return copy;
|
|
3611
|
+
},
|
|
3612
|
+
ensureFlagExists: function(item, options) {
|
|
3613
|
+
if (!(item in options) || typeof options[item] !== "boolean") {
|
|
3614
|
+
options[item] = false;
|
|
3615
|
+
}
|
|
3616
|
+
},
|
|
3617
|
+
ensureSpacesExists: function(options) {
|
|
3618
|
+
if (!("spaces" in options) || typeof options.spaces !== "number" && typeof options.spaces !== "string") {
|
|
3619
|
+
options.spaces = 0;
|
|
3620
|
+
}
|
|
3621
|
+
},
|
|
3622
|
+
ensureAlwaysArrayExists: function(options) {
|
|
3623
|
+
if (!("alwaysArray" in options) || typeof options.alwaysArray !== "boolean" && !isArray(options.alwaysArray)) {
|
|
3624
|
+
options.alwaysArray = false;
|
|
3625
|
+
}
|
|
3626
|
+
},
|
|
3627
|
+
ensureKeyExists: function(key, options) {
|
|
3628
|
+
if (!(key + "Key" in options) || typeof options[key + "Key"] !== "string") {
|
|
3629
|
+
options[key + "Key"] = options.compact ? "_" + key : key;
|
|
3630
|
+
}
|
|
3631
|
+
},
|
|
3632
|
+
checkFnExists: function(key, options) {
|
|
3633
|
+
return key + "Fn" in options;
|
|
3634
|
+
}
|
|
3635
|
+
};
|
|
3636
|
+
return optionsHelper;
|
|
3637
|
+
}
|
|
3638
|
+
var xml2js;
|
|
3639
|
+
var hasRequiredXml2js;
|
|
3640
|
+
function requireXml2js() {
|
|
3641
|
+
if (hasRequiredXml2js) return xml2js;
|
|
3642
|
+
hasRequiredXml2js = 1;
|
|
3643
|
+
var sax2 = requireSax();
|
|
3644
|
+
var helper = requireOptionsHelper();
|
|
3645
|
+
var isArray = requireArrayHelper().isArray;
|
|
3646
|
+
var options;
|
|
3647
|
+
var currentElement;
|
|
3648
|
+
function validateOptions(userOptions) {
|
|
3649
|
+
options = helper.copyOptions(userOptions);
|
|
3650
|
+
helper.ensureFlagExists("ignoreDeclaration", options);
|
|
3651
|
+
helper.ensureFlagExists("ignoreInstruction", options);
|
|
3652
|
+
helper.ensureFlagExists("ignoreAttributes", options);
|
|
3653
|
+
helper.ensureFlagExists("ignoreText", options);
|
|
3654
|
+
helper.ensureFlagExists("ignoreComment", options);
|
|
3655
|
+
helper.ensureFlagExists("ignoreCdata", options);
|
|
3656
|
+
helper.ensureFlagExists("ignoreDoctype", options);
|
|
3657
|
+
helper.ensureFlagExists("compact", options);
|
|
3658
|
+
helper.ensureFlagExists("alwaysChildren", options);
|
|
3659
|
+
helper.ensureFlagExists("addParent", options);
|
|
3660
|
+
helper.ensureFlagExists("trim", options);
|
|
3661
|
+
helper.ensureFlagExists("nativeType", options);
|
|
3662
|
+
helper.ensureFlagExists("nativeTypeAttributes", options);
|
|
3663
|
+
helper.ensureFlagExists("sanitize", options);
|
|
3664
|
+
helper.ensureFlagExists("instructionHasAttributes", options);
|
|
3665
|
+
helper.ensureFlagExists("captureSpacesBetweenElements", options);
|
|
3666
|
+
helper.ensureAlwaysArrayExists(options);
|
|
3667
|
+
helper.ensureKeyExists("declaration", options);
|
|
3668
|
+
helper.ensureKeyExists("instruction", options);
|
|
3669
|
+
helper.ensureKeyExists("attributes", options);
|
|
3670
|
+
helper.ensureKeyExists("text", options);
|
|
3671
|
+
helper.ensureKeyExists("comment", options);
|
|
3672
|
+
helper.ensureKeyExists("cdata", options);
|
|
3673
|
+
helper.ensureKeyExists("doctype", options);
|
|
3674
|
+
helper.ensureKeyExists("type", options);
|
|
3675
|
+
helper.ensureKeyExists("name", options);
|
|
3676
|
+
helper.ensureKeyExists("elements", options);
|
|
3677
|
+
helper.ensureKeyExists("parent", options);
|
|
3678
|
+
helper.checkFnExists("doctype", options);
|
|
3679
|
+
helper.checkFnExists("instruction", options);
|
|
3680
|
+
helper.checkFnExists("cdata", options);
|
|
3681
|
+
helper.checkFnExists("comment", options);
|
|
3682
|
+
helper.checkFnExists("text", options);
|
|
3683
|
+
helper.checkFnExists("instructionName", options);
|
|
3684
|
+
helper.checkFnExists("elementName", options);
|
|
3685
|
+
helper.checkFnExists("attributeName", options);
|
|
3686
|
+
helper.checkFnExists("attributeValue", options);
|
|
3687
|
+
helper.checkFnExists("attributes", options);
|
|
3688
|
+
return options;
|
|
3689
|
+
}
|
|
3690
|
+
function nativeType(value) {
|
|
3691
|
+
var nValue = Number(value);
|
|
3692
|
+
if (!isNaN(nValue)) {
|
|
3693
|
+
return nValue;
|
|
3694
|
+
}
|
|
3695
|
+
var bValue = value.toLowerCase();
|
|
3696
|
+
if (bValue === "true") {
|
|
3697
|
+
return true;
|
|
3698
|
+
} else if (bValue === "false") {
|
|
3699
|
+
return false;
|
|
3700
|
+
}
|
|
3701
|
+
return value;
|
|
3702
|
+
}
|
|
3703
|
+
function addField(type, value) {
|
|
3704
|
+
var key;
|
|
3705
|
+
if (options.compact) {
|
|
3706
|
+
if (!currentElement[options[type + "Key"]] && (isArray(options.alwaysArray) ? options.alwaysArray.indexOf(options[type + "Key"]) !== -1 : options.alwaysArray)) {
|
|
3707
|
+
currentElement[options[type + "Key"]] = [];
|
|
3708
|
+
}
|
|
3709
|
+
if (currentElement[options[type + "Key"]] && !isArray(currentElement[options[type + "Key"]])) {
|
|
3710
|
+
currentElement[options[type + "Key"]] = [currentElement[options[type + "Key"]]];
|
|
3711
|
+
}
|
|
3712
|
+
if (type + "Fn" in options && typeof value === "string") {
|
|
3713
|
+
value = options[type + "Fn"](value, currentElement);
|
|
3714
|
+
}
|
|
3715
|
+
if (type === "instruction" && ("instructionFn" in options || "instructionNameFn" in options)) {
|
|
3716
|
+
for (key in value) {
|
|
3717
|
+
if (value.hasOwnProperty(key)) {
|
|
3718
|
+
if ("instructionFn" in options) {
|
|
3719
|
+
value[key] = options.instructionFn(value[key], key, currentElement);
|
|
3720
|
+
} else {
|
|
3721
|
+
var temp = value[key];
|
|
3722
|
+
delete value[key];
|
|
3723
|
+
value[options.instructionNameFn(key, temp, currentElement)] = temp;
|
|
3724
|
+
}
|
|
3725
|
+
}
|
|
3726
|
+
}
|
|
3727
|
+
}
|
|
3728
|
+
if (isArray(currentElement[options[type + "Key"]])) {
|
|
3729
|
+
currentElement[options[type + "Key"]].push(value);
|
|
3730
|
+
} else {
|
|
3731
|
+
currentElement[options[type + "Key"]] = value;
|
|
3732
|
+
}
|
|
3733
|
+
} else {
|
|
3734
|
+
if (!currentElement[options.elementsKey]) {
|
|
3735
|
+
currentElement[options.elementsKey] = [];
|
|
3736
|
+
}
|
|
3737
|
+
var element = {};
|
|
3738
|
+
element[options.typeKey] = type;
|
|
3739
|
+
if (type === "instruction") {
|
|
3740
|
+
for (key in value) {
|
|
3741
|
+
if (value.hasOwnProperty(key)) {
|
|
3742
|
+
break;
|
|
3743
|
+
}
|
|
3744
|
+
}
|
|
3745
|
+
element[options.nameKey] = "instructionNameFn" in options ? options.instructionNameFn(key, value, currentElement) : key;
|
|
3746
|
+
if (options.instructionHasAttributes) {
|
|
3747
|
+
element[options.attributesKey] = value[key][options.attributesKey];
|
|
3748
|
+
if ("instructionFn" in options) {
|
|
3749
|
+
element[options.attributesKey] = options.instructionFn(element[options.attributesKey], key, currentElement);
|
|
3750
|
+
}
|
|
3751
|
+
} else {
|
|
3752
|
+
if ("instructionFn" in options) {
|
|
3753
|
+
value[key] = options.instructionFn(value[key], key, currentElement);
|
|
3754
|
+
}
|
|
3755
|
+
element[options.instructionKey] = value[key];
|
|
3756
|
+
}
|
|
3757
|
+
} else {
|
|
3758
|
+
if (type + "Fn" in options) {
|
|
3759
|
+
value = options[type + "Fn"](value, currentElement);
|
|
3760
|
+
}
|
|
3761
|
+
element[options[type + "Key"]] = value;
|
|
3762
|
+
}
|
|
3763
|
+
if (options.addParent) {
|
|
3764
|
+
element[options.parentKey] = currentElement;
|
|
3765
|
+
}
|
|
3766
|
+
currentElement[options.elementsKey].push(element);
|
|
3767
|
+
}
|
|
3768
|
+
}
|
|
3769
|
+
function manipulateAttributes(attributes) {
|
|
3770
|
+
if ("attributesFn" in options && attributes) {
|
|
3771
|
+
attributes = options.attributesFn(attributes, currentElement);
|
|
3772
|
+
}
|
|
3773
|
+
if ((options.trim || "attributeValueFn" in options || "attributeNameFn" in options || options.nativeTypeAttributes) && attributes) {
|
|
3774
|
+
var key;
|
|
3775
|
+
for (key in attributes) {
|
|
3776
|
+
if (attributes.hasOwnProperty(key)) {
|
|
3777
|
+
if (options.trim) attributes[key] = attributes[key].trim();
|
|
3778
|
+
if (options.nativeTypeAttributes) {
|
|
3779
|
+
attributes[key] = nativeType(attributes[key]);
|
|
3780
|
+
}
|
|
3781
|
+
if ("attributeValueFn" in options) attributes[key] = options.attributeValueFn(attributes[key], key, currentElement);
|
|
3782
|
+
if ("attributeNameFn" in options) {
|
|
3783
|
+
var temp = attributes[key];
|
|
3784
|
+
delete attributes[key];
|
|
3785
|
+
attributes[options.attributeNameFn(key, attributes[key], currentElement)] = temp;
|
|
3786
|
+
}
|
|
3787
|
+
}
|
|
3788
|
+
}
|
|
3789
|
+
}
|
|
3790
|
+
return attributes;
|
|
3791
|
+
}
|
|
3792
|
+
function onInstruction(instruction) {
|
|
3793
|
+
var attributes = {};
|
|
3794
|
+
if (instruction.body && (instruction.name.toLowerCase() === "xml" || options.instructionHasAttributes)) {
|
|
3795
|
+
var attrsRegExp = /([\w:-]+)\s*=\s*(?:"([^"]*)"|'([^']*)'|(\w+))\s*/g;
|
|
3796
|
+
var match;
|
|
3797
|
+
while ((match = attrsRegExp.exec(instruction.body)) !== null) {
|
|
3798
|
+
attributes[match[1]] = match[2] || match[3] || match[4];
|
|
3799
|
+
}
|
|
3800
|
+
attributes = manipulateAttributes(attributes);
|
|
3801
|
+
}
|
|
3802
|
+
if (instruction.name.toLowerCase() === "xml") {
|
|
3803
|
+
if (options.ignoreDeclaration) {
|
|
3804
|
+
return;
|
|
3805
|
+
}
|
|
3806
|
+
currentElement[options.declarationKey] = {};
|
|
3807
|
+
if (Object.keys(attributes).length) {
|
|
3808
|
+
currentElement[options.declarationKey][options.attributesKey] = attributes;
|
|
3809
|
+
}
|
|
3810
|
+
if (options.addParent) {
|
|
3811
|
+
currentElement[options.declarationKey][options.parentKey] = currentElement;
|
|
3812
|
+
}
|
|
3813
|
+
} else {
|
|
3814
|
+
if (options.ignoreInstruction) {
|
|
3815
|
+
return;
|
|
3816
|
+
}
|
|
3817
|
+
if (options.trim) {
|
|
3818
|
+
instruction.body = instruction.body.trim();
|
|
3819
|
+
}
|
|
3820
|
+
var value = {};
|
|
3821
|
+
if (options.instructionHasAttributes && Object.keys(attributes).length) {
|
|
3822
|
+
value[instruction.name] = {};
|
|
3823
|
+
value[instruction.name][options.attributesKey] = attributes;
|
|
3824
|
+
} else {
|
|
3825
|
+
value[instruction.name] = instruction.body;
|
|
3826
|
+
}
|
|
3827
|
+
addField("instruction", value);
|
|
3828
|
+
}
|
|
3829
|
+
}
|
|
3830
|
+
function onStartElement(name, attributes) {
|
|
3831
|
+
var element;
|
|
3832
|
+
if (typeof name === "object") {
|
|
3833
|
+
attributes = name.attributes;
|
|
3834
|
+
name = name.name;
|
|
3835
|
+
}
|
|
3836
|
+
attributes = manipulateAttributes(attributes);
|
|
3837
|
+
if ("elementNameFn" in options) {
|
|
3838
|
+
name = options.elementNameFn(name, currentElement);
|
|
3839
|
+
}
|
|
3840
|
+
if (options.compact) {
|
|
3841
|
+
element = {};
|
|
3842
|
+
if (!options.ignoreAttributes && attributes && Object.keys(attributes).length) {
|
|
3843
|
+
element[options.attributesKey] = {};
|
|
3844
|
+
var key;
|
|
3845
|
+
for (key in attributes) {
|
|
3846
|
+
if (attributes.hasOwnProperty(key)) {
|
|
3847
|
+
element[options.attributesKey][key] = attributes[key];
|
|
3848
|
+
}
|
|
3849
|
+
}
|
|
3850
|
+
}
|
|
3851
|
+
if (!(name in currentElement) && (isArray(options.alwaysArray) ? options.alwaysArray.indexOf(name) !== -1 : options.alwaysArray)) {
|
|
3852
|
+
currentElement[name] = [];
|
|
3853
|
+
}
|
|
3854
|
+
if (currentElement[name] && !isArray(currentElement[name])) {
|
|
3855
|
+
currentElement[name] = [currentElement[name]];
|
|
3856
|
+
}
|
|
3857
|
+
if (isArray(currentElement[name])) {
|
|
3858
|
+
currentElement[name].push(element);
|
|
3859
|
+
} else {
|
|
3860
|
+
currentElement[name] = element;
|
|
3861
|
+
}
|
|
3862
|
+
} else {
|
|
3863
|
+
if (!currentElement[options.elementsKey]) {
|
|
3864
|
+
currentElement[options.elementsKey] = [];
|
|
3865
|
+
}
|
|
3866
|
+
element = {};
|
|
3867
|
+
element[options.typeKey] = "element";
|
|
3868
|
+
element[options.nameKey] = name;
|
|
3869
|
+
if (!options.ignoreAttributes && attributes && Object.keys(attributes).length) {
|
|
3870
|
+
element[options.attributesKey] = attributes;
|
|
3871
|
+
}
|
|
3872
|
+
if (options.alwaysChildren) {
|
|
3873
|
+
element[options.elementsKey] = [];
|
|
3874
|
+
}
|
|
3875
|
+
currentElement[options.elementsKey].push(element);
|
|
3876
|
+
}
|
|
3877
|
+
element[options.parentKey] = currentElement;
|
|
3878
|
+
currentElement = element;
|
|
3879
|
+
}
|
|
3880
|
+
function onText(text) {
|
|
3881
|
+
if (options.ignoreText) {
|
|
3882
|
+
return;
|
|
3883
|
+
}
|
|
3884
|
+
if (!text.trim() && !options.captureSpacesBetweenElements) {
|
|
3885
|
+
return;
|
|
3886
|
+
}
|
|
3887
|
+
if (options.trim) {
|
|
3888
|
+
text = text.trim();
|
|
3889
|
+
}
|
|
3890
|
+
if (options.nativeType) {
|
|
3891
|
+
text = nativeType(text);
|
|
3892
|
+
}
|
|
3893
|
+
if (options.sanitize) {
|
|
3894
|
+
text = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
3895
|
+
}
|
|
3896
|
+
addField("text", text);
|
|
3897
|
+
}
|
|
3898
|
+
function onComment(comment) {
|
|
3899
|
+
if (options.ignoreComment) {
|
|
3900
|
+
return;
|
|
3901
|
+
}
|
|
3902
|
+
if (options.trim) {
|
|
3903
|
+
comment = comment.trim();
|
|
3904
|
+
}
|
|
3905
|
+
addField("comment", comment);
|
|
3906
|
+
}
|
|
3907
|
+
function onEndElement(name) {
|
|
3908
|
+
var parentElement = currentElement[options.parentKey];
|
|
3909
|
+
if (!options.addParent) {
|
|
3910
|
+
delete currentElement[options.parentKey];
|
|
3911
|
+
}
|
|
3912
|
+
currentElement = parentElement;
|
|
3913
|
+
}
|
|
3914
|
+
function onCdata(cdata) {
|
|
3915
|
+
if (options.ignoreCdata) {
|
|
3916
|
+
return;
|
|
3917
|
+
}
|
|
3918
|
+
if (options.trim) {
|
|
3919
|
+
cdata = cdata.trim();
|
|
3920
|
+
}
|
|
3921
|
+
addField("cdata", cdata);
|
|
3922
|
+
}
|
|
3923
|
+
function onDoctype(doctype) {
|
|
3924
|
+
if (options.ignoreDoctype) {
|
|
3925
|
+
return;
|
|
3926
|
+
}
|
|
3927
|
+
doctype = doctype.replace(/^ /, "");
|
|
3928
|
+
if (options.trim) {
|
|
3929
|
+
doctype = doctype.trim();
|
|
3930
|
+
}
|
|
3931
|
+
addField("doctype", doctype);
|
|
3932
|
+
}
|
|
3933
|
+
function onError(error) {
|
|
3934
|
+
error.note = error;
|
|
3935
|
+
}
|
|
3936
|
+
xml2js = function(xml, userOptions) {
|
|
3937
|
+
var parser = sax2.parser(true, {});
|
|
3938
|
+
var result = {};
|
|
3939
|
+
currentElement = result;
|
|
3940
|
+
options = validateOptions(userOptions);
|
|
3941
|
+
{
|
|
3942
|
+
parser.opt = { strictEntities: true };
|
|
3943
|
+
parser.onopentag = onStartElement;
|
|
3944
|
+
parser.ontext = onText;
|
|
3945
|
+
parser.oncomment = onComment;
|
|
3946
|
+
parser.onclosetag = onEndElement;
|
|
3947
|
+
parser.onerror = onError;
|
|
3948
|
+
parser.oncdata = onCdata;
|
|
3949
|
+
parser.ondoctype = onDoctype;
|
|
3950
|
+
parser.onprocessinginstruction = onInstruction;
|
|
3951
|
+
}
|
|
3952
|
+
{
|
|
3953
|
+
parser.write(xml).close();
|
|
3954
|
+
}
|
|
3955
|
+
if (result[options.elementsKey]) {
|
|
3956
|
+
var temp = result[options.elementsKey];
|
|
3957
|
+
delete result[options.elementsKey];
|
|
3958
|
+
result[options.elementsKey] = temp;
|
|
3959
|
+
delete result.text;
|
|
3960
|
+
}
|
|
3961
|
+
return result;
|
|
3962
|
+
};
|
|
3963
|
+
return xml2js;
|
|
3964
|
+
}
|
|
3965
|
+
var xml2json;
|
|
3966
|
+
var hasRequiredXml2json;
|
|
3967
|
+
function requireXml2json() {
|
|
3968
|
+
if (hasRequiredXml2json) return xml2json;
|
|
3969
|
+
hasRequiredXml2json = 1;
|
|
3970
|
+
var helper = requireOptionsHelper();
|
|
3971
|
+
var xml2js2 = requireXml2js();
|
|
3972
|
+
function validateOptions(userOptions) {
|
|
3973
|
+
var options = helper.copyOptions(userOptions);
|
|
3974
|
+
helper.ensureSpacesExists(options);
|
|
3975
|
+
return options;
|
|
3976
|
+
}
|
|
3977
|
+
xml2json = function(xml, userOptions) {
|
|
3978
|
+
var options, js, json, parentKey;
|
|
3979
|
+
options = validateOptions(userOptions);
|
|
3980
|
+
js = xml2js2(xml, options);
|
|
3981
|
+
parentKey = "compact" in options && options.compact ? "_parent" : "parent";
|
|
3982
|
+
if ("addParent" in options && options.addParent) {
|
|
3983
|
+
json = JSON.stringify(js, function(k, v) {
|
|
3984
|
+
return k === parentKey ? "_" : v;
|
|
3985
|
+
}, options.spaces);
|
|
3986
|
+
} else {
|
|
3987
|
+
json = JSON.stringify(js, null, options.spaces);
|
|
3988
|
+
}
|
|
3989
|
+
return json.replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
3990
|
+
};
|
|
3991
|
+
return xml2json;
|
|
3992
|
+
}
|
|
3993
|
+
var js2xml;
|
|
3994
|
+
var hasRequiredJs2xml;
|
|
3995
|
+
function requireJs2xml() {
|
|
3996
|
+
if (hasRequiredJs2xml) return js2xml;
|
|
3997
|
+
hasRequiredJs2xml = 1;
|
|
3998
|
+
var helper = requireOptionsHelper();
|
|
3999
|
+
var isArray = requireArrayHelper().isArray;
|
|
4000
|
+
var currentElement, currentElementName;
|
|
4001
|
+
function validateOptions(userOptions) {
|
|
4002
|
+
var options = helper.copyOptions(userOptions);
|
|
4003
|
+
helper.ensureFlagExists("ignoreDeclaration", options);
|
|
4004
|
+
helper.ensureFlagExists("ignoreInstruction", options);
|
|
4005
|
+
helper.ensureFlagExists("ignoreAttributes", options);
|
|
4006
|
+
helper.ensureFlagExists("ignoreText", options);
|
|
4007
|
+
helper.ensureFlagExists("ignoreComment", options);
|
|
4008
|
+
helper.ensureFlagExists("ignoreCdata", options);
|
|
4009
|
+
helper.ensureFlagExists("ignoreDoctype", options);
|
|
4010
|
+
helper.ensureFlagExists("compact", options);
|
|
4011
|
+
helper.ensureFlagExists("indentText", options);
|
|
4012
|
+
helper.ensureFlagExists("indentCdata", options);
|
|
4013
|
+
helper.ensureFlagExists("indentAttributes", options);
|
|
4014
|
+
helper.ensureFlagExists("indentInstruction", options);
|
|
4015
|
+
helper.ensureFlagExists("fullTagEmptyElement", options);
|
|
4016
|
+
helper.ensureFlagExists("noQuotesForNativeAttributes", options);
|
|
4017
|
+
helper.ensureSpacesExists(options);
|
|
4018
|
+
if (typeof options.spaces === "number") {
|
|
4019
|
+
options.spaces = Array(options.spaces + 1).join(" ");
|
|
4020
|
+
}
|
|
4021
|
+
helper.ensureKeyExists("declaration", options);
|
|
4022
|
+
helper.ensureKeyExists("instruction", options);
|
|
4023
|
+
helper.ensureKeyExists("attributes", options);
|
|
4024
|
+
helper.ensureKeyExists("text", options);
|
|
4025
|
+
helper.ensureKeyExists("comment", options);
|
|
4026
|
+
helper.ensureKeyExists("cdata", options);
|
|
4027
|
+
helper.ensureKeyExists("doctype", options);
|
|
4028
|
+
helper.ensureKeyExists("type", options);
|
|
4029
|
+
helper.ensureKeyExists("name", options);
|
|
4030
|
+
helper.ensureKeyExists("elements", options);
|
|
4031
|
+
helper.checkFnExists("doctype", options);
|
|
4032
|
+
helper.checkFnExists("instruction", options);
|
|
4033
|
+
helper.checkFnExists("cdata", options);
|
|
4034
|
+
helper.checkFnExists("comment", options);
|
|
4035
|
+
helper.checkFnExists("text", options);
|
|
4036
|
+
helper.checkFnExists("instructionName", options);
|
|
4037
|
+
helper.checkFnExists("elementName", options);
|
|
4038
|
+
helper.checkFnExists("attributeName", options);
|
|
4039
|
+
helper.checkFnExists("attributeValue", options);
|
|
4040
|
+
helper.checkFnExists("attributes", options);
|
|
4041
|
+
helper.checkFnExists("fullTagEmptyElement", options);
|
|
4042
|
+
return options;
|
|
4043
|
+
}
|
|
4044
|
+
function writeIndentation(options, depth, firstLine) {
|
|
4045
|
+
return (!firstLine && options.spaces ? "\n" : "") + Array(depth + 1).join(options.spaces);
|
|
4046
|
+
}
|
|
4047
|
+
function writeAttributes(attributes, options, depth) {
|
|
4048
|
+
if (options.ignoreAttributes) {
|
|
4049
|
+
return "";
|
|
4050
|
+
}
|
|
4051
|
+
if ("attributesFn" in options) {
|
|
4052
|
+
attributes = options.attributesFn(attributes, currentElementName, currentElement);
|
|
4053
|
+
}
|
|
4054
|
+
var key, attr, attrName, quote, result = [];
|
|
4055
|
+
for (key in attributes) {
|
|
4056
|
+
if (attributes.hasOwnProperty(key) && attributes[key] !== null && attributes[key] !== void 0) {
|
|
4057
|
+
quote = options.noQuotesForNativeAttributes && typeof attributes[key] !== "string" ? "" : '"';
|
|
4058
|
+
attr = "" + attributes[key];
|
|
4059
|
+
attr = attr.replace(/"/g, """);
|
|
4060
|
+
attrName = "attributeNameFn" in options ? options.attributeNameFn(key, attr, currentElementName, currentElement) : key;
|
|
4061
|
+
result.push(options.spaces && options.indentAttributes ? writeIndentation(options, depth + 1, false) : " ");
|
|
4062
|
+
result.push(attrName + "=" + quote + ("attributeValueFn" in options ? options.attributeValueFn(attr, key, currentElementName, currentElement) : attr) + quote);
|
|
4063
|
+
}
|
|
4064
|
+
}
|
|
4065
|
+
if (attributes && Object.keys(attributes).length && options.spaces && options.indentAttributes) {
|
|
4066
|
+
result.push(writeIndentation(options, depth, false));
|
|
4067
|
+
}
|
|
4068
|
+
return result.join("");
|
|
4069
|
+
}
|
|
4070
|
+
function writeDeclaration(declaration, options, depth) {
|
|
4071
|
+
currentElement = declaration;
|
|
4072
|
+
currentElementName = "xml";
|
|
4073
|
+
return options.ignoreDeclaration ? "" : "<?xml" + writeAttributes(declaration[options.attributesKey], options, depth) + "?>";
|
|
4074
|
+
}
|
|
4075
|
+
function writeInstruction(instruction, options, depth) {
|
|
4076
|
+
if (options.ignoreInstruction) {
|
|
4077
|
+
return "";
|
|
4078
|
+
}
|
|
4079
|
+
var key;
|
|
4080
|
+
for (key in instruction) {
|
|
4081
|
+
if (instruction.hasOwnProperty(key)) {
|
|
4082
|
+
break;
|
|
4083
|
+
}
|
|
4084
|
+
}
|
|
4085
|
+
var instructionName = "instructionNameFn" in options ? options.instructionNameFn(key, instruction[key], currentElementName, currentElement) : key;
|
|
4086
|
+
if (typeof instruction[key] === "object") {
|
|
4087
|
+
currentElement = instruction;
|
|
4088
|
+
currentElementName = instructionName;
|
|
4089
|
+
return "<?" + instructionName + writeAttributes(instruction[key][options.attributesKey], options, depth) + "?>";
|
|
4090
|
+
} else {
|
|
4091
|
+
var instructionValue = instruction[key] ? instruction[key] : "";
|
|
4092
|
+
if ("instructionFn" in options) instructionValue = options.instructionFn(instructionValue, key, currentElementName, currentElement);
|
|
4093
|
+
return "<?" + instructionName + (instructionValue ? " " + instructionValue : "") + "?>";
|
|
4094
|
+
}
|
|
4095
|
+
}
|
|
4096
|
+
function writeComment(comment, options) {
|
|
4097
|
+
return options.ignoreComment ? "" : "<!--" + ("commentFn" in options ? options.commentFn(comment, currentElementName, currentElement) : comment) + "-->";
|
|
4098
|
+
}
|
|
4099
|
+
function writeCdata(cdata, options) {
|
|
4100
|
+
return options.ignoreCdata ? "" : "<![CDATA[" + ("cdataFn" in options ? options.cdataFn(cdata, currentElementName, currentElement) : cdata.replace("]]>", "]]]]><![CDATA[>")) + "]]>";
|
|
4101
|
+
}
|
|
4102
|
+
function writeDoctype(doctype, options) {
|
|
4103
|
+
return options.ignoreDoctype ? "" : "<!DOCTYPE " + ("doctypeFn" in options ? options.doctypeFn(doctype, currentElementName, currentElement) : doctype) + ">";
|
|
4104
|
+
}
|
|
4105
|
+
function writeText(text, options) {
|
|
4106
|
+
if (options.ignoreText) return "";
|
|
4107
|
+
text = "" + text;
|
|
4108
|
+
text = text.replace(/&/g, "&");
|
|
4109
|
+
text = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
4110
|
+
return "textFn" in options ? options.textFn(text, currentElementName, currentElement) : text;
|
|
4111
|
+
}
|
|
4112
|
+
function hasContent(element, options) {
|
|
4113
|
+
var i;
|
|
4114
|
+
if (element.elements && element.elements.length) {
|
|
4115
|
+
for (i = 0; i < element.elements.length; ++i) {
|
|
4116
|
+
switch (element.elements[i][options.typeKey]) {
|
|
4117
|
+
case "text":
|
|
4118
|
+
if (options.indentText) {
|
|
4119
|
+
return true;
|
|
4120
|
+
}
|
|
4121
|
+
break;
|
|
4122
|
+
// skip to next key
|
|
4123
|
+
case "cdata":
|
|
4124
|
+
if (options.indentCdata) {
|
|
4125
|
+
return true;
|
|
4126
|
+
}
|
|
4127
|
+
break;
|
|
4128
|
+
// skip to next key
|
|
4129
|
+
case "instruction":
|
|
4130
|
+
if (options.indentInstruction) {
|
|
4131
|
+
return true;
|
|
4132
|
+
}
|
|
4133
|
+
break;
|
|
4134
|
+
// skip to next key
|
|
4135
|
+
case "doctype":
|
|
4136
|
+
case "comment":
|
|
4137
|
+
case "element":
|
|
4138
|
+
return true;
|
|
4139
|
+
default:
|
|
4140
|
+
return true;
|
|
4141
|
+
}
|
|
4142
|
+
}
|
|
4143
|
+
}
|
|
4144
|
+
return false;
|
|
4145
|
+
}
|
|
4146
|
+
function writeElement(element, options, depth) {
|
|
4147
|
+
currentElement = element;
|
|
4148
|
+
currentElementName = element.name;
|
|
4149
|
+
var xml = [], elementName = "elementNameFn" in options ? options.elementNameFn(element.name, element) : element.name;
|
|
4150
|
+
xml.push("<" + elementName);
|
|
4151
|
+
if (element[options.attributesKey]) {
|
|
4152
|
+
xml.push(writeAttributes(element[options.attributesKey], options, depth));
|
|
4153
|
+
}
|
|
4154
|
+
var withClosingTag = element[options.elementsKey] && element[options.elementsKey].length || element[options.attributesKey] && element[options.attributesKey]["xml:space"] === "preserve";
|
|
4155
|
+
if (!withClosingTag) {
|
|
4156
|
+
if ("fullTagEmptyElementFn" in options) {
|
|
4157
|
+
withClosingTag = options.fullTagEmptyElementFn(element.name, element);
|
|
4158
|
+
} else {
|
|
4159
|
+
withClosingTag = options.fullTagEmptyElement;
|
|
4160
|
+
}
|
|
4161
|
+
}
|
|
4162
|
+
if (withClosingTag) {
|
|
4163
|
+
xml.push(">");
|
|
4164
|
+
if (element[options.elementsKey] && element[options.elementsKey].length) {
|
|
4165
|
+
xml.push(writeElements(element[options.elementsKey], options, depth + 1));
|
|
4166
|
+
currentElement = element;
|
|
4167
|
+
currentElementName = element.name;
|
|
4168
|
+
}
|
|
4169
|
+
xml.push(options.spaces && hasContent(element, options) ? "\n" + Array(depth + 1).join(options.spaces) : "");
|
|
4170
|
+
xml.push("</" + elementName + ">");
|
|
4171
|
+
} else {
|
|
4172
|
+
xml.push("/>");
|
|
4173
|
+
}
|
|
4174
|
+
return xml.join("");
|
|
4175
|
+
}
|
|
4176
|
+
function writeElements(elements, options, depth, firstLine) {
|
|
4177
|
+
return elements.reduce(function(xml, element) {
|
|
4178
|
+
var indent = writeIndentation(options, depth, firstLine && !xml);
|
|
4179
|
+
switch (element.type) {
|
|
4180
|
+
case "element":
|
|
4181
|
+
return xml + indent + writeElement(element, options, depth);
|
|
4182
|
+
case "comment":
|
|
4183
|
+
return xml + indent + writeComment(element[options.commentKey], options);
|
|
4184
|
+
case "doctype":
|
|
4185
|
+
return xml + indent + writeDoctype(element[options.doctypeKey], options);
|
|
4186
|
+
case "cdata":
|
|
4187
|
+
return xml + (options.indentCdata ? indent : "") + writeCdata(element[options.cdataKey], options);
|
|
4188
|
+
case "text":
|
|
4189
|
+
return xml + (options.indentText ? indent : "") + writeText(element[options.textKey], options);
|
|
4190
|
+
case "instruction":
|
|
4191
|
+
var instruction = {};
|
|
4192
|
+
instruction[element[options.nameKey]] = element[options.attributesKey] ? element : element[options.instructionKey];
|
|
4193
|
+
return xml + (options.indentInstruction ? indent : "") + writeInstruction(instruction, options, depth);
|
|
4194
|
+
}
|
|
4195
|
+
}, "");
|
|
4196
|
+
}
|
|
4197
|
+
function hasContentCompact(element, options, anyContent) {
|
|
4198
|
+
var key;
|
|
4199
|
+
for (key in element) {
|
|
4200
|
+
if (element.hasOwnProperty(key)) {
|
|
4201
|
+
switch (key) {
|
|
4202
|
+
case options.parentKey:
|
|
4203
|
+
case options.attributesKey:
|
|
4204
|
+
break;
|
|
4205
|
+
// skip to next key
|
|
4206
|
+
case options.textKey:
|
|
4207
|
+
if (options.indentText || anyContent) {
|
|
4208
|
+
return true;
|
|
4209
|
+
}
|
|
4210
|
+
break;
|
|
4211
|
+
// skip to next key
|
|
4212
|
+
case options.cdataKey:
|
|
4213
|
+
if (options.indentCdata || anyContent) {
|
|
4214
|
+
return true;
|
|
4215
|
+
}
|
|
4216
|
+
break;
|
|
4217
|
+
// skip to next key
|
|
4218
|
+
case options.instructionKey:
|
|
4219
|
+
if (options.indentInstruction || anyContent) {
|
|
4220
|
+
return true;
|
|
4221
|
+
}
|
|
4222
|
+
break;
|
|
4223
|
+
// skip to next key
|
|
4224
|
+
case options.doctypeKey:
|
|
4225
|
+
case options.commentKey:
|
|
4226
|
+
return true;
|
|
4227
|
+
default:
|
|
4228
|
+
return true;
|
|
4229
|
+
}
|
|
4230
|
+
}
|
|
4231
|
+
}
|
|
4232
|
+
return false;
|
|
4233
|
+
}
|
|
4234
|
+
function writeElementCompact(element, name, options, depth, indent) {
|
|
4235
|
+
currentElement = element;
|
|
4236
|
+
currentElementName = name;
|
|
4237
|
+
var elementName = "elementNameFn" in options ? options.elementNameFn(name, element) : name;
|
|
4238
|
+
if (typeof element === "undefined" || element === null || element === "") {
|
|
4239
|
+
return "fullTagEmptyElementFn" in options && options.fullTagEmptyElementFn(name, element) || options.fullTagEmptyElement ? "<" + elementName + "></" + elementName + ">" : "<" + elementName + "/>";
|
|
4240
|
+
}
|
|
4241
|
+
var xml = [];
|
|
4242
|
+
if (name) {
|
|
4243
|
+
xml.push("<" + elementName);
|
|
4244
|
+
if (typeof element !== "object") {
|
|
4245
|
+
xml.push(">" + writeText(element, options) + "</" + elementName + ">");
|
|
4246
|
+
return xml.join("");
|
|
4247
|
+
}
|
|
4248
|
+
if (element[options.attributesKey]) {
|
|
4249
|
+
xml.push(writeAttributes(element[options.attributesKey], options, depth));
|
|
4250
|
+
}
|
|
4251
|
+
var withClosingTag = hasContentCompact(element, options, true) || element[options.attributesKey] && element[options.attributesKey]["xml:space"] === "preserve";
|
|
4252
|
+
if (!withClosingTag) {
|
|
4253
|
+
if ("fullTagEmptyElementFn" in options) {
|
|
4254
|
+
withClosingTag = options.fullTagEmptyElementFn(name, element);
|
|
4255
|
+
} else {
|
|
4256
|
+
withClosingTag = options.fullTagEmptyElement;
|
|
4257
|
+
}
|
|
4258
|
+
}
|
|
4259
|
+
if (withClosingTag) {
|
|
4260
|
+
xml.push(">");
|
|
4261
|
+
} else {
|
|
4262
|
+
xml.push("/>");
|
|
4263
|
+
return xml.join("");
|
|
4264
|
+
}
|
|
4265
|
+
}
|
|
4266
|
+
xml.push(writeElementsCompact(element, options, depth + 1, false));
|
|
4267
|
+
currentElement = element;
|
|
4268
|
+
currentElementName = name;
|
|
4269
|
+
if (name) {
|
|
4270
|
+
xml.push((indent ? writeIndentation(options, depth, false) : "") + "</" + elementName + ">");
|
|
4271
|
+
}
|
|
4272
|
+
return xml.join("");
|
|
4273
|
+
}
|
|
4274
|
+
function writeElementsCompact(element, options, depth, firstLine) {
|
|
4275
|
+
var i, key, nodes, xml = [];
|
|
4276
|
+
for (key in element) {
|
|
4277
|
+
if (element.hasOwnProperty(key)) {
|
|
4278
|
+
nodes = isArray(element[key]) ? element[key] : [element[key]];
|
|
4279
|
+
for (i = 0; i < nodes.length; ++i) {
|
|
4280
|
+
switch (key) {
|
|
4281
|
+
case options.declarationKey:
|
|
4282
|
+
xml.push(writeDeclaration(nodes[i], options, depth));
|
|
4283
|
+
break;
|
|
4284
|
+
case options.instructionKey:
|
|
4285
|
+
xml.push((options.indentInstruction ? writeIndentation(options, depth, firstLine) : "") + writeInstruction(nodes[i], options, depth));
|
|
4286
|
+
break;
|
|
4287
|
+
case options.attributesKey:
|
|
4288
|
+
case options.parentKey:
|
|
4289
|
+
break;
|
|
4290
|
+
// skip
|
|
4291
|
+
case options.textKey:
|
|
4292
|
+
xml.push((options.indentText ? writeIndentation(options, depth, firstLine) : "") + writeText(nodes[i], options));
|
|
4293
|
+
break;
|
|
4294
|
+
case options.cdataKey:
|
|
4295
|
+
xml.push((options.indentCdata ? writeIndentation(options, depth, firstLine) : "") + writeCdata(nodes[i], options));
|
|
4296
|
+
break;
|
|
4297
|
+
case options.doctypeKey:
|
|
4298
|
+
xml.push(writeIndentation(options, depth, firstLine) + writeDoctype(nodes[i], options));
|
|
4299
|
+
break;
|
|
4300
|
+
case options.commentKey:
|
|
4301
|
+
xml.push(writeIndentation(options, depth, firstLine) + writeComment(nodes[i], options));
|
|
4302
|
+
break;
|
|
4303
|
+
default:
|
|
4304
|
+
xml.push(writeIndentation(options, depth, firstLine) + writeElementCompact(nodes[i], key, options, depth, hasContentCompact(nodes[i], options)));
|
|
4305
|
+
}
|
|
4306
|
+
firstLine = firstLine && !xml.length;
|
|
4307
|
+
}
|
|
4308
|
+
}
|
|
4309
|
+
}
|
|
4310
|
+
return xml.join("");
|
|
4311
|
+
}
|
|
4312
|
+
js2xml = function(js, options) {
|
|
4313
|
+
options = validateOptions(options);
|
|
4314
|
+
var xml = [];
|
|
4315
|
+
currentElement = js;
|
|
4316
|
+
currentElementName = "_root_";
|
|
4317
|
+
if (options.compact) {
|
|
4318
|
+
xml.push(writeElementsCompact(js, options, 0, true));
|
|
4319
|
+
} else {
|
|
4320
|
+
if (js[options.declarationKey]) {
|
|
4321
|
+
xml.push(writeDeclaration(js[options.declarationKey], options, 0));
|
|
4322
|
+
}
|
|
4323
|
+
if (js[options.elementsKey] && js[options.elementsKey].length) {
|
|
4324
|
+
xml.push(writeElements(js[options.elementsKey], options, 0, !xml.length));
|
|
4325
|
+
}
|
|
4326
|
+
}
|
|
4327
|
+
return xml.join("");
|
|
4328
|
+
};
|
|
4329
|
+
return js2xml;
|
|
4330
|
+
}
|
|
4331
|
+
var json2xml;
|
|
4332
|
+
var hasRequiredJson2xml;
|
|
4333
|
+
function requireJson2xml() {
|
|
4334
|
+
if (hasRequiredJson2xml) return json2xml;
|
|
4335
|
+
hasRequiredJson2xml = 1;
|
|
4336
|
+
var js2xml2 = requireJs2xml();
|
|
4337
|
+
json2xml = function(json, options) {
|
|
4338
|
+
if (json instanceof Buffer) {
|
|
4339
|
+
json = json.toString();
|
|
4340
|
+
}
|
|
4341
|
+
var js = null;
|
|
4342
|
+
if (typeof json === "string") {
|
|
4343
|
+
try {
|
|
4344
|
+
js = JSON.parse(json);
|
|
4345
|
+
} catch (e) {
|
|
4346
|
+
throw new Error("The JSON structure is invalid");
|
|
4347
|
+
}
|
|
4348
|
+
} else {
|
|
4349
|
+
js = json;
|
|
4350
|
+
}
|
|
4351
|
+
return js2xml2(js, options);
|
|
4352
|
+
};
|
|
4353
|
+
return json2xml;
|
|
4354
|
+
}
|
|
4355
|
+
var lib;
|
|
4356
|
+
var hasRequiredLib;
|
|
4357
|
+
function requireLib() {
|
|
4358
|
+
if (hasRequiredLib) return lib;
|
|
4359
|
+
hasRequiredLib = 1;
|
|
4360
|
+
var xml2js2 = requireXml2js();
|
|
4361
|
+
var xml2json2 = requireXml2json();
|
|
4362
|
+
var js2xml2 = requireJs2xml();
|
|
4363
|
+
var json2xml2 = requireJson2xml();
|
|
4364
|
+
lib = {
|
|
4365
|
+
xml2js: xml2js2,
|
|
4366
|
+
xml2json: xml2json2,
|
|
4367
|
+
js2xml: js2xml2,
|
|
4368
|
+
json2xml: json2xml2
|
|
4369
|
+
};
|
|
4370
|
+
return lib;
|
|
4371
|
+
}
|
|
4372
|
+
var libExports = requireLib();
|
|
4373
|
+
var bufferExports = requireBuffer();
|
|
4374
|
+
const _TiledParser = class _TiledParser {
|
|
4375
|
+
constructor(xml, filePath = "", basePath = "") {
|
|
4376
|
+
this.xml = xml;
|
|
4377
|
+
this.filePath = filePath;
|
|
4378
|
+
this.basePath = basePath;
|
|
4379
|
+
this.layers = /* @__PURE__ */ new Map();
|
|
4380
|
+
this.transform = (obj) => {
|
|
4381
|
+
var _a, _b;
|
|
4382
|
+
if (!obj) return;
|
|
4383
|
+
const attr = obj.attributes || obj._attributes;
|
|
4384
|
+
if (!attr) return obj;
|
|
4385
|
+
let newObj = {
|
|
4386
|
+
...obj,
|
|
4387
|
+
...attr,
|
|
4388
|
+
..._TiledParser.propToNumber(attr, [
|
|
4389
|
+
"version",
|
|
4390
|
+
"width",
|
|
4391
|
+
"height",
|
|
4392
|
+
"tilewidth",
|
|
4393
|
+
"tileheight",
|
|
4394
|
+
"nextlayerid",
|
|
4395
|
+
"nextobjectid",
|
|
4396
|
+
"hexsidelength",
|
|
4397
|
+
"opacity",
|
|
4398
|
+
"x",
|
|
4399
|
+
"y",
|
|
4400
|
+
"offsetx",
|
|
4401
|
+
"offsety",
|
|
4402
|
+
"startx",
|
|
4403
|
+
"starty",
|
|
4404
|
+
"id",
|
|
4405
|
+
"firstgid",
|
|
4406
|
+
"imageheight",
|
|
4407
|
+
"imagewidth",
|
|
4408
|
+
"margin",
|
|
4409
|
+
"columns",
|
|
4410
|
+
"rows",
|
|
4411
|
+
"tilecount",
|
|
4412
|
+
"rotation",
|
|
4413
|
+
"gid",
|
|
4414
|
+
"tileid",
|
|
4415
|
+
"duration",
|
|
4416
|
+
"parallaxx",
|
|
4417
|
+
"parallaxy",
|
|
4418
|
+
"repeatx",
|
|
4419
|
+
"repeaty",
|
|
4420
|
+
"pixelsize"
|
|
4421
|
+
]),
|
|
4422
|
+
..._TiledParser.propToBool(attr, [
|
|
4423
|
+
"visible",
|
|
4424
|
+
"infinite",
|
|
4425
|
+
"locked",
|
|
4426
|
+
"bold",
|
|
4427
|
+
"italic",
|
|
4428
|
+
"kerning",
|
|
4429
|
+
"strikeout",
|
|
4430
|
+
"underline",
|
|
4431
|
+
"wrap"
|
|
4432
|
+
])
|
|
4433
|
+
};
|
|
4434
|
+
if (newObj.properties) {
|
|
4435
|
+
const properties = _TiledParser.toArray(newObj.properties.property);
|
|
4436
|
+
const propObj = {};
|
|
4437
|
+
for (let prop of properties) {
|
|
4438
|
+
const attr2 = prop._attributes;
|
|
4439
|
+
if (!attr2) continue;
|
|
4440
|
+
let val;
|
|
4441
|
+
switch (attr2.type) {
|
|
4442
|
+
case "file":
|
|
4443
|
+
val = this.getImagePath(attr2.value);
|
|
4444
|
+
break;
|
|
4445
|
+
case "object":
|
|
4446
|
+
case "float":
|
|
4447
|
+
case "int":
|
|
4448
|
+
val = +attr2.value;
|
|
4449
|
+
break;
|
|
4450
|
+
case "bool":
|
|
4451
|
+
val = attr2.value == "true" ? true : false;
|
|
4452
|
+
break;
|
|
4453
|
+
case "class":
|
|
4454
|
+
val = {
|
|
4455
|
+
...((_a = this.transform(prop)) == null ? void 0 : _a.properties) ?? {},
|
|
4456
|
+
_classname: attr2.propertytype
|
|
4457
|
+
};
|
|
4458
|
+
break;
|
|
4459
|
+
default:
|
|
4460
|
+
val = attr2.value;
|
|
4461
|
+
}
|
|
4462
|
+
propObj[attr2.name] = val;
|
|
4463
|
+
}
|
|
4464
|
+
newObj.properties = propObj;
|
|
4465
|
+
}
|
|
4466
|
+
if (newObj.polygon) {
|
|
4467
|
+
newObj.polygon = this.transform(newObj.polygon);
|
|
4468
|
+
}
|
|
4469
|
+
if (newObj.polyline) {
|
|
4470
|
+
newObj.polyline = this.transform(newObj.polyline);
|
|
4471
|
+
}
|
|
4472
|
+
if (newObj.points) {
|
|
4473
|
+
newObj = newObj.points.split(" ").map((point) => {
|
|
4474
|
+
const pos = point.split(",");
|
|
4475
|
+
return { x: +pos[0], y: +pos[1] };
|
|
4476
|
+
});
|
|
4477
|
+
}
|
|
4478
|
+
if (newObj.point) {
|
|
4479
|
+
newObj.point = true;
|
|
4480
|
+
}
|
|
4481
|
+
if (newObj.ellipse) {
|
|
4482
|
+
newObj.ellipse = true;
|
|
4483
|
+
}
|
|
4484
|
+
if (newObj.text) {
|
|
4485
|
+
newObj.text = {
|
|
4486
|
+
text: newObj.text._text,
|
|
4487
|
+
...this.transform(newObj.text)
|
|
4488
|
+
};
|
|
4489
|
+
delete newObj.text._text;
|
|
4490
|
+
}
|
|
4491
|
+
if (newObj.image) {
|
|
4492
|
+
newObj.image = this.transform(newObj.image);
|
|
4493
|
+
}
|
|
4494
|
+
if (newObj.source) {
|
|
4495
|
+
if (!this.isTilesetSource(newObj)) {
|
|
4496
|
+
newObj.source = this.getImagePath(newObj.source);
|
|
4497
|
+
}
|
|
4498
|
+
}
|
|
4499
|
+
const objectgroup = newObj.object || ((_b = newObj.objectgroup) == null ? void 0 : _b.object);
|
|
4500
|
+
if (objectgroup) {
|
|
4501
|
+
newObj.objects = _TiledParser.toArray(objectgroup).map((object) => {
|
|
4502
|
+
return this.transform(object);
|
|
4503
|
+
});
|
|
4504
|
+
}
|
|
4505
|
+
delete newObj._attributes;
|
|
4506
|
+
delete newObj.attributes;
|
|
4507
|
+
delete newObj.object;
|
|
4508
|
+
delete newObj.objectgroup;
|
|
4509
|
+
return newObj;
|
|
4510
|
+
};
|
|
4511
|
+
}
|
|
4512
|
+
static toArray(prop) {
|
|
4513
|
+
if (!prop) return [];
|
|
4514
|
+
if (!Array.isArray(prop)) return [prop];
|
|
4515
|
+
return prop;
|
|
4516
|
+
}
|
|
4517
|
+
getImagePath(image) {
|
|
4518
|
+
if (this.filePath.startsWith("http")) return new URL(image, this.filePath).href;
|
|
4519
|
+
return joinPath(this.basePath, image);
|
|
4520
|
+
}
|
|
4521
|
+
/**
|
|
4522
|
+
* Check if the object is a tileset source reference
|
|
4523
|
+
* Tileset sources should not have their paths transformed with getImagePath
|
|
4524
|
+
*/
|
|
4525
|
+
isTilesetSource(obj) {
|
|
4526
|
+
return obj.firstgid !== void 0 || obj.tilewidth !== void 0 || obj.tileheight !== void 0 || obj.tilecount !== void 0 || obj.columns !== void 0;
|
|
4527
|
+
}
|
|
4528
|
+
static unpackTileBytes(buffer2, size) {
|
|
4529
|
+
const expectedCount = size * 4;
|
|
4530
|
+
if (buffer2.length !== expectedCount) {
|
|
4531
|
+
throw new Error("Expected " + expectedCount + " bytes of tile data; received " + buffer2.length);
|
|
4532
|
+
}
|
|
4533
|
+
let tileIndex = 0;
|
|
4534
|
+
const array = [];
|
|
4535
|
+
for (let i = 0; i < expectedCount; i += 4) {
|
|
4536
|
+
array[tileIndex] = buffer2.readUInt32LE(i);
|
|
4537
|
+
tileIndex++;
|
|
4538
|
+
}
|
|
4539
|
+
return array;
|
|
4540
|
+
}
|
|
4541
|
+
static decode(obj, size) {
|
|
4542
|
+
const { encoding, data } = obj;
|
|
4543
|
+
if (encoding == "base64") {
|
|
4544
|
+
return _TiledParser.unpackTileBytes(bufferExports.Buffer.from(data.trim(), "base64"), size);
|
|
4545
|
+
} else if (encoding == "csv") {
|
|
4546
|
+
return data.trim().split(",").map((x) => +x);
|
|
4547
|
+
}
|
|
4548
|
+
return data;
|
|
4549
|
+
}
|
|
4550
|
+
parseMap() {
|
|
4551
|
+
const json = libExports.xml2js(this.xml, { compact: true });
|
|
4552
|
+
const jsonNoCompact = libExports.xml2js(this.xml);
|
|
4553
|
+
const tileset = json.map.tileset;
|
|
4554
|
+
json.map.group;
|
|
4555
|
+
const recursiveObjectGroup = (obj) => {
|
|
4556
|
+
const { objectgroup, group: group2, layer, imagelayer } = obj;
|
|
4557
|
+
const setLayer = (type) => {
|
|
4558
|
+
if (!type) return;
|
|
4559
|
+
_TiledParser.toArray(type).forEach((val) => {
|
|
4560
|
+
if (this.layers.has(+val._attributes.id)) {
|
|
4561
|
+
throw new Error(`Tiled Parser Error: Layer with id ${val._attributes.id} already exists`);
|
|
4562
|
+
}
|
|
4563
|
+
this.layers.set(+val._attributes.id, val);
|
|
4564
|
+
});
|
|
4565
|
+
};
|
|
4566
|
+
setLayer(objectgroup);
|
|
4567
|
+
setLayer(layer);
|
|
4568
|
+
setLayer(group2);
|
|
4569
|
+
setLayer(imagelayer);
|
|
4570
|
+
if (group2) {
|
|
4571
|
+
recursiveObjectGroup(group2);
|
|
4572
|
+
}
|
|
4573
|
+
};
|
|
4574
|
+
recursiveObjectGroup(json.map);
|
|
4575
|
+
const recursiveLayer = (elements, array = []) => {
|
|
4576
|
+
var _a;
|
|
4577
|
+
if (!elements) return array;
|
|
4578
|
+
for (let element of elements) {
|
|
4579
|
+
const { name } = element;
|
|
4580
|
+
if (!["layer", "group", "imagelayer", "objectgroup"].includes(name)) continue;
|
|
4581
|
+
const data = (_a = element.elements) == null ? void 0 : _a.find((el) => el.name == "data");
|
|
4582
|
+
element.layer = this.layers.get(+element.attributes.id);
|
|
4583
|
+
const obj = {
|
|
4584
|
+
...this.transform(data) ?? {},
|
|
4585
|
+
...this.transform(element),
|
|
4586
|
+
...this.transform(element.layer),
|
|
4587
|
+
layers: recursiveLayer(element.elements),
|
|
4588
|
+
data: data ? data.elements[0].text : void 0,
|
|
4589
|
+
type: name == "layer" ? "tilelayer" : name
|
|
4590
|
+
};
|
|
4591
|
+
delete obj.elements;
|
|
4592
|
+
delete obj.layer;
|
|
4593
|
+
if (obj.data) obj.data = _TiledParser.decode(obj, obj.width * obj.height);
|
|
4594
|
+
array.push(obj);
|
|
4595
|
+
}
|
|
4596
|
+
return array;
|
|
4597
|
+
};
|
|
4598
|
+
const layers = recursiveLayer(jsonNoCompact.elements[0].elements);
|
|
4599
|
+
const tilesets = _TiledParser.toArray(tileset).map((tileset2) => {
|
|
4600
|
+
const obj = this.transform(tileset2);
|
|
4601
|
+
return obj;
|
|
4602
|
+
});
|
|
4603
|
+
const ret = {
|
|
4604
|
+
...this.transform(json.map),
|
|
4605
|
+
layers,
|
|
4606
|
+
tilesets
|
|
4607
|
+
};
|
|
4608
|
+
delete ret.layer;
|
|
4609
|
+
delete ret.tileset;
|
|
4610
|
+
delete ret.group;
|
|
4611
|
+
delete ret.imagelayer;
|
|
4612
|
+
return ret;
|
|
4613
|
+
}
|
|
4614
|
+
parseTileset() {
|
|
4615
|
+
const json = libExports.xml2js(this.xml, { compact: true });
|
|
4616
|
+
const { tileset } = json;
|
|
4617
|
+
const ret = {
|
|
4618
|
+
...this.transform(tileset),
|
|
4619
|
+
image: this.transform(tileset.image),
|
|
4620
|
+
tiles: _TiledParser.toArray(tileset.tile).map((tile) => {
|
|
4621
|
+
const ret2 = this.transform(tile);
|
|
4622
|
+
if (tile.animation) {
|
|
4623
|
+
ret2.animations = _TiledParser.toArray(tile.animation.frame).map(this.transform);
|
|
4624
|
+
}
|
|
4625
|
+
delete ret2.animation;
|
|
4626
|
+
return ret2;
|
|
4627
|
+
})
|
|
4628
|
+
};
|
|
4629
|
+
delete ret.tile;
|
|
4630
|
+
return ret;
|
|
4631
|
+
}
|
|
4632
|
+
};
|
|
4633
|
+
_TiledParser.propToNumber = (obj, props) => {
|
|
4634
|
+
for (let key of props) {
|
|
4635
|
+
if (obj[key] !== void 0) {
|
|
4636
|
+
obj[key] = +obj[key];
|
|
4637
|
+
}
|
|
4638
|
+
}
|
|
4639
|
+
return obj;
|
|
4640
|
+
};
|
|
4641
|
+
_TiledParser.propToBool = (obj, props) => {
|
|
4642
|
+
for (let key of props) {
|
|
4643
|
+
if (obj[key] !== void 0) {
|
|
4644
|
+
obj[key] = obj[key] == "true" || obj[key] == "1";
|
|
4645
|
+
}
|
|
4646
|
+
}
|
|
4647
|
+
return obj;
|
|
4648
|
+
};
|
|
4649
|
+
let TiledParser = _TiledParser;
|
|
13
4650
|
export {
|
|
14
|
-
|
|
4651
|
+
TiledParser
|
|
15
4652
|
};
|