@office-open/docx 0.9.5 → 0.9.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -10
- package/dist/context-BrtlmvVE.mjs +323 -0
- package/dist/context-BrtlmvVE.mjs.map +1 -0
- package/dist/{core-properties-BMagGcpC.d.mts → core-properties-CBMhgSrn.d.mts} +700 -558
- package/dist/core-properties-CBMhgSrn.d.mts.map +1 -0
- package/dist/{generate-BVfOLdwW.mjs → generate-BMTVflV1.mjs} +50 -34
- package/dist/generate-BMTVflV1.mjs.map +1 -0
- package/dist/generate.d.mts +1 -1
- package/dist/generate.mjs +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +5 -5
- package/dist/parse-K59nx6MF.mjs +1927 -0
- package/dist/parse-K59nx6MF.mjs.map +1 -0
- package/dist/parse.d.mts +1 -1
- package/dist/parse.mjs +1 -1
- package/dist/parts-BQBGNSGm.mjs +12090 -0
- package/dist/parts-BQBGNSGm.mjs.map +1 -0
- package/dist/patch/index.d.mts +1 -1
- package/dist/patch/index.mjs +1 -1
- package/package.json +3 -3
- package/dist/context-CSBntKXD.mjs +0 -5116
- package/dist/context-CSBntKXD.mjs.map +0 -1
- package/dist/core-properties-BMagGcpC.d.mts.map +0 -1
- package/dist/document-DYH7tGnw.mjs +0 -6227
- package/dist/document-DYH7tGnw.mjs.map +0 -1
- package/dist/generate-BVfOLdwW.mjs.map +0 -1
- package/dist/parse-Db2NGghB.mjs +0 -514
- package/dist/parse-Db2NGghB.mjs.map +0 -1
|
@@ -0,0 +1,1927 @@
|
|
|
1
|
+
import { A as buildStyleCache, Bt as setBodyParseChild, C as parseToc, D as settingsDesc, Gt as stringifyElement, J as parseNumberingDefinitions, Q as tableDesc, Rt as parseCustomXmlPr, S as footnotesDesc, Z as setTableParseChild, _ as bibliographyDesc, a as appPropertiesDesc, at as parseParagraphProperties, ct as replaceRelsWithPlaceholders, f as commentsDesc, g as glossaryDesc, i as webSettingsDesc, it as parseParagraph, j as parseStyleDefinitions, k as buildNumberingCache, o as customPropertiesDesc, pt as parseSectionPropertiesEl, s as corePropertiesDesc, u as contentTypesDesc, ut as parseSdtBlock, v as fontTableDesc, x as endnotesDesc } from "./parts-BQBGNSGm.mjs";
|
|
2
|
+
import { t as DocxReadContext } from "./context-BrtlmvVE.mjs";
|
|
3
|
+
import { parseArchive, toUint8Array } from "@office-open/core";
|
|
4
|
+
import { attr, findChild, textOf } from "@office-open/xml";
|
|
5
|
+
//#region \0polyfill-node.global.js
|
|
6
|
+
var _polyfill_node_global_default = typeof _polyfill_node_global_default !== "undefined" ? _polyfill_node_global_default : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region \0polyfill-node.buffer.js
|
|
9
|
+
var lookup = [];
|
|
10
|
+
var revLookup = [];
|
|
11
|
+
var Arr = typeof Uint8Array !== "undefined" ? Uint8Array : Array;
|
|
12
|
+
var inited = false;
|
|
13
|
+
function init() {
|
|
14
|
+
inited = true;
|
|
15
|
+
var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
16
|
+
for (var i = 0, len = code.length; i < len; ++i) {
|
|
17
|
+
lookup[i] = code[i];
|
|
18
|
+
revLookup[code.charCodeAt(i)] = i;
|
|
19
|
+
}
|
|
20
|
+
revLookup["-".charCodeAt(0)] = 62;
|
|
21
|
+
revLookup["_".charCodeAt(0)] = 63;
|
|
22
|
+
}
|
|
23
|
+
function toByteArray(b64) {
|
|
24
|
+
if (!inited) init();
|
|
25
|
+
var i, j, l, tmp, placeHolders, arr;
|
|
26
|
+
var len = b64.length;
|
|
27
|
+
if (len % 4 > 0) throw new Error("Invalid string. Length must be a multiple of 4");
|
|
28
|
+
placeHolders = b64[len - 2] === "=" ? 2 : b64[len - 1] === "=" ? 1 : 0;
|
|
29
|
+
arr = new Arr(len * 3 / 4 - placeHolders);
|
|
30
|
+
l = placeHolders > 0 ? len - 4 : len;
|
|
31
|
+
var L = 0;
|
|
32
|
+
for (i = 0, j = 0; i < l; i += 4, j += 3) {
|
|
33
|
+
tmp = revLookup[b64.charCodeAt(i)] << 18 | revLookup[b64.charCodeAt(i + 1)] << 12 | revLookup[b64.charCodeAt(i + 2)] << 6 | revLookup[b64.charCodeAt(i + 3)];
|
|
34
|
+
arr[L++] = tmp >> 16 & 255;
|
|
35
|
+
arr[L++] = tmp >> 8 & 255;
|
|
36
|
+
arr[L++] = tmp & 255;
|
|
37
|
+
}
|
|
38
|
+
if (placeHolders === 2) {
|
|
39
|
+
tmp = revLookup[b64.charCodeAt(i)] << 2 | revLookup[b64.charCodeAt(i + 1)] >> 4;
|
|
40
|
+
arr[L++] = tmp & 255;
|
|
41
|
+
} else if (placeHolders === 1) {
|
|
42
|
+
tmp = revLookup[b64.charCodeAt(i)] << 10 | revLookup[b64.charCodeAt(i + 1)] << 4 | revLookup[b64.charCodeAt(i + 2)] >> 2;
|
|
43
|
+
arr[L++] = tmp >> 8 & 255;
|
|
44
|
+
arr[L++] = tmp & 255;
|
|
45
|
+
}
|
|
46
|
+
return arr;
|
|
47
|
+
}
|
|
48
|
+
function tripletToBase64(num) {
|
|
49
|
+
return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63];
|
|
50
|
+
}
|
|
51
|
+
function encodeChunk(uint8, start, end) {
|
|
52
|
+
var tmp;
|
|
53
|
+
var output = [];
|
|
54
|
+
for (var i = start; i < end; i += 3) {
|
|
55
|
+
tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + uint8[i + 2];
|
|
56
|
+
output.push(tripletToBase64(tmp));
|
|
57
|
+
}
|
|
58
|
+
return output.join("");
|
|
59
|
+
}
|
|
60
|
+
function fromByteArray(uint8) {
|
|
61
|
+
if (!inited) init();
|
|
62
|
+
var tmp;
|
|
63
|
+
var len = uint8.length;
|
|
64
|
+
var extraBytes = len % 3;
|
|
65
|
+
var output = "";
|
|
66
|
+
var parts = [];
|
|
67
|
+
var maxChunkLength = 16383;
|
|
68
|
+
for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) parts.push(encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength));
|
|
69
|
+
if (extraBytes === 1) {
|
|
70
|
+
tmp = uint8[len - 1];
|
|
71
|
+
output += lookup[tmp >> 2];
|
|
72
|
+
output += lookup[tmp << 4 & 63];
|
|
73
|
+
output += "==";
|
|
74
|
+
} else if (extraBytes === 2) {
|
|
75
|
+
tmp = (uint8[len - 2] << 8) + uint8[len - 1];
|
|
76
|
+
output += lookup[tmp >> 10];
|
|
77
|
+
output += lookup[tmp >> 4 & 63];
|
|
78
|
+
output += lookup[tmp << 2 & 63];
|
|
79
|
+
output += "=";
|
|
80
|
+
}
|
|
81
|
+
parts.push(output);
|
|
82
|
+
return parts.join("");
|
|
83
|
+
}
|
|
84
|
+
function read(buffer, offset, isLE, mLen, nBytes) {
|
|
85
|
+
var e, m;
|
|
86
|
+
var eLen = nBytes * 8 - mLen - 1;
|
|
87
|
+
var eMax = (1 << eLen) - 1;
|
|
88
|
+
var eBias = eMax >> 1;
|
|
89
|
+
var nBits = -7;
|
|
90
|
+
var i = isLE ? nBytes - 1 : 0;
|
|
91
|
+
var d = isLE ? -1 : 1;
|
|
92
|
+
var s = buffer[offset + i];
|
|
93
|
+
i += d;
|
|
94
|
+
e = s & (1 << -nBits) - 1;
|
|
95
|
+
s >>= -nBits;
|
|
96
|
+
nBits += eLen;
|
|
97
|
+
for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8);
|
|
98
|
+
m = e & (1 << -nBits) - 1;
|
|
99
|
+
e >>= -nBits;
|
|
100
|
+
nBits += mLen;
|
|
101
|
+
for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8);
|
|
102
|
+
if (e === 0) e = 1 - eBias;
|
|
103
|
+
else if (e === eMax) return m ? NaN : (s ? -1 : 1) * Infinity;
|
|
104
|
+
else {
|
|
105
|
+
m = m + Math.pow(2, mLen);
|
|
106
|
+
e = e - eBias;
|
|
107
|
+
}
|
|
108
|
+
return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
|
|
109
|
+
}
|
|
110
|
+
function write(buffer, value, offset, isLE, mLen, nBytes) {
|
|
111
|
+
var e, m, c;
|
|
112
|
+
var eLen = nBytes * 8 - mLen - 1;
|
|
113
|
+
var eMax = (1 << eLen) - 1;
|
|
114
|
+
var eBias = eMax >> 1;
|
|
115
|
+
var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
|
|
116
|
+
var i = isLE ? 0 : nBytes - 1;
|
|
117
|
+
var d = isLE ? 1 : -1;
|
|
118
|
+
var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
|
|
119
|
+
value = Math.abs(value);
|
|
120
|
+
if (isNaN(value) || value === Infinity) {
|
|
121
|
+
m = isNaN(value) ? 1 : 0;
|
|
122
|
+
e = eMax;
|
|
123
|
+
} else {
|
|
124
|
+
e = Math.floor(Math.log(value) / Math.LN2);
|
|
125
|
+
if (value * (c = Math.pow(2, -e)) < 1) {
|
|
126
|
+
e--;
|
|
127
|
+
c *= 2;
|
|
128
|
+
}
|
|
129
|
+
if (e + eBias >= 1) value += rt / c;
|
|
130
|
+
else value += rt * Math.pow(2, 1 - eBias);
|
|
131
|
+
if (value * c >= 2) {
|
|
132
|
+
e++;
|
|
133
|
+
c /= 2;
|
|
134
|
+
}
|
|
135
|
+
if (e + eBias >= eMax) {
|
|
136
|
+
m = 0;
|
|
137
|
+
e = eMax;
|
|
138
|
+
} else if (e + eBias >= 1) {
|
|
139
|
+
m = (value * c - 1) * Math.pow(2, mLen);
|
|
140
|
+
e = e + eBias;
|
|
141
|
+
} else {
|
|
142
|
+
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
|
143
|
+
e = 0;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
for (; mLen >= 8; buffer[offset + i] = m & 255, i += d, m /= 256, mLen -= 8);
|
|
147
|
+
e = e << mLen | m;
|
|
148
|
+
eLen += mLen;
|
|
149
|
+
for (; eLen > 0; buffer[offset + i] = e & 255, i += d, e /= 256, eLen -= 8);
|
|
150
|
+
buffer[offset + i - d] |= s * 128;
|
|
151
|
+
}
|
|
152
|
+
var toString = {}.toString;
|
|
153
|
+
var isArray = Array.isArray || function(arr) {
|
|
154
|
+
return toString.call(arr) == "[object Array]";
|
|
155
|
+
};
|
|
156
|
+
/*!
|
|
157
|
+
* The buffer module from node.js, for the browser.
|
|
158
|
+
*
|
|
159
|
+
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
|
|
160
|
+
* @license MIT
|
|
161
|
+
*/
|
|
162
|
+
/**
|
|
163
|
+
* If `Buffer.TYPED_ARRAY_SUPPORT`:
|
|
164
|
+
* === true Use Uint8Array implementation (fastest)
|
|
165
|
+
* === false Use Object implementation (most compatible, even IE6)
|
|
166
|
+
*
|
|
167
|
+
* Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
|
|
168
|
+
* Opera 11.6+, iOS 4.2+.
|
|
169
|
+
*
|
|
170
|
+
* Due to various browser bugs, sometimes the Object implementation will be used even
|
|
171
|
+
* when the browser supports typed arrays.
|
|
172
|
+
*
|
|
173
|
+
* Note:
|
|
174
|
+
*
|
|
175
|
+
* - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
|
|
176
|
+
* See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
|
|
177
|
+
*
|
|
178
|
+
* - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
|
|
179
|
+
*
|
|
180
|
+
* - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
|
|
181
|
+
* incorrect length in some situations.
|
|
182
|
+
|
|
183
|
+
* We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
|
|
184
|
+
* get the Object implementation, which is slower but behaves correctly.
|
|
185
|
+
*/
|
|
186
|
+
Buffer.TYPED_ARRAY_SUPPORT = _polyfill_node_global_default.TYPED_ARRAY_SUPPORT !== void 0 ? _polyfill_node_global_default.TYPED_ARRAY_SUPPORT : true;
|
|
187
|
+
kMaxLength();
|
|
188
|
+
function kMaxLength() {
|
|
189
|
+
return Buffer.TYPED_ARRAY_SUPPORT ? 2147483647 : 1073741823;
|
|
190
|
+
}
|
|
191
|
+
function createBuffer(that, length) {
|
|
192
|
+
if (kMaxLength() < length) throw new RangeError("Invalid typed array length");
|
|
193
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
194
|
+
that = new Uint8Array(length);
|
|
195
|
+
that.__proto__ = Buffer.prototype;
|
|
196
|
+
} else {
|
|
197
|
+
if (that === null) that = new Buffer(length);
|
|
198
|
+
that.length = length;
|
|
199
|
+
}
|
|
200
|
+
return that;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* The Buffer constructor returns instances of `Uint8Array` that have their
|
|
204
|
+
* prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
|
|
205
|
+
* `Uint8Array`, so the returned instances will have all the node `Buffer` methods
|
|
206
|
+
* and the `Uint8Array` methods. Square bracket notation works as expected -- it
|
|
207
|
+
* returns a single octet.
|
|
208
|
+
*
|
|
209
|
+
* The `Uint8Array` prototype remains unmodified.
|
|
210
|
+
*/
|
|
211
|
+
function Buffer(arg, encodingOrOffset, length) {
|
|
212
|
+
if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) return new Buffer(arg, encodingOrOffset, length);
|
|
213
|
+
if (typeof arg === "number") {
|
|
214
|
+
if (typeof encodingOrOffset === "string") throw new Error("If encoding is specified then the first argument must be a string");
|
|
215
|
+
return allocUnsafe(this, arg);
|
|
216
|
+
}
|
|
217
|
+
return from(this, arg, encodingOrOffset, length);
|
|
218
|
+
}
|
|
219
|
+
Buffer.poolSize = 8192;
|
|
220
|
+
Buffer._augment = function(arr) {
|
|
221
|
+
arr.__proto__ = Buffer.prototype;
|
|
222
|
+
return arr;
|
|
223
|
+
};
|
|
224
|
+
function from(that, value, encodingOrOffset, length) {
|
|
225
|
+
if (typeof value === "number") throw new TypeError("\"value\" argument must not be a number");
|
|
226
|
+
if (typeof ArrayBuffer !== "undefined" && value instanceof ArrayBuffer) return fromArrayBuffer(that, value, encodingOrOffset, length);
|
|
227
|
+
if (typeof value === "string") return fromString(that, value, encodingOrOffset);
|
|
228
|
+
return fromObject(that, value);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
|
|
232
|
+
* if value is a number.
|
|
233
|
+
* Buffer.from(str[, encoding])
|
|
234
|
+
* Buffer.from(array)
|
|
235
|
+
* Buffer.from(buffer)
|
|
236
|
+
* Buffer.from(arrayBuffer[, byteOffset[, length]])
|
|
237
|
+
**/
|
|
238
|
+
Buffer.from = function(value, encodingOrOffset, length) {
|
|
239
|
+
return from(null, value, encodingOrOffset, length);
|
|
240
|
+
};
|
|
241
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
242
|
+
Buffer.prototype.__proto__ = Uint8Array.prototype;
|
|
243
|
+
Buffer.__proto__ = Uint8Array;
|
|
244
|
+
if (typeof Symbol !== "undefined" && Symbol.species && Buffer[Symbol.species] === Buffer);
|
|
245
|
+
}
|
|
246
|
+
function assertSize(size) {
|
|
247
|
+
if (typeof size !== "number") throw new TypeError("\"size\" argument must be a number");
|
|
248
|
+
else if (size < 0) throw new RangeError("\"size\" argument must not be negative");
|
|
249
|
+
}
|
|
250
|
+
function alloc(that, size, fill, encoding) {
|
|
251
|
+
assertSize(size);
|
|
252
|
+
if (size <= 0) return createBuffer(that, size);
|
|
253
|
+
if (fill !== void 0) return typeof encoding === "string" ? createBuffer(that, size).fill(fill, encoding) : createBuffer(that, size).fill(fill);
|
|
254
|
+
return createBuffer(that, size);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Creates a new filled Buffer instance.
|
|
258
|
+
* alloc(size[, fill[, encoding]])
|
|
259
|
+
**/
|
|
260
|
+
Buffer.alloc = function(size, fill, encoding) {
|
|
261
|
+
return alloc(null, size, fill, encoding);
|
|
262
|
+
};
|
|
263
|
+
function allocUnsafe(that, size) {
|
|
264
|
+
assertSize(size);
|
|
265
|
+
that = createBuffer(that, size < 0 ? 0 : checked(size) | 0);
|
|
266
|
+
if (!Buffer.TYPED_ARRAY_SUPPORT) for (var i = 0; i < size; ++i) that[i] = 0;
|
|
267
|
+
return that;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
|
|
271
|
+
* */
|
|
272
|
+
Buffer.allocUnsafe = function(size) {
|
|
273
|
+
return allocUnsafe(null, size);
|
|
274
|
+
};
|
|
275
|
+
/**
|
|
276
|
+
* Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
|
277
|
+
*/
|
|
278
|
+
Buffer.allocUnsafeSlow = function(size) {
|
|
279
|
+
return allocUnsafe(null, size);
|
|
280
|
+
};
|
|
281
|
+
function fromString(that, string, encoding) {
|
|
282
|
+
if (typeof encoding !== "string" || encoding === "") encoding = "utf8";
|
|
283
|
+
if (!Buffer.isEncoding(encoding)) throw new TypeError("\"encoding\" must be a valid string encoding");
|
|
284
|
+
var length = byteLength(string, encoding) | 0;
|
|
285
|
+
that = createBuffer(that, length);
|
|
286
|
+
var actual = that.write(string, encoding);
|
|
287
|
+
if (actual !== length) that = that.slice(0, actual);
|
|
288
|
+
return that;
|
|
289
|
+
}
|
|
290
|
+
function fromArrayLike(that, array) {
|
|
291
|
+
var length = array.length < 0 ? 0 : checked(array.length) | 0;
|
|
292
|
+
that = createBuffer(that, length);
|
|
293
|
+
for (var i = 0; i < length; i += 1) that[i] = array[i] & 255;
|
|
294
|
+
return that;
|
|
295
|
+
}
|
|
296
|
+
function fromArrayBuffer(that, array, byteOffset, length) {
|
|
297
|
+
array.byteLength;
|
|
298
|
+
if (byteOffset < 0 || array.byteLength < byteOffset) throw new RangeError("'offset' is out of bounds");
|
|
299
|
+
if (array.byteLength < byteOffset + (length || 0)) throw new RangeError("'length' is out of bounds");
|
|
300
|
+
if (byteOffset === void 0 && length === void 0) array = new Uint8Array(array);
|
|
301
|
+
else if (length === void 0) array = new Uint8Array(array, byteOffset);
|
|
302
|
+
else array = new Uint8Array(array, byteOffset, length);
|
|
303
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
304
|
+
that = array;
|
|
305
|
+
that.__proto__ = Buffer.prototype;
|
|
306
|
+
} else that = fromArrayLike(that, array);
|
|
307
|
+
return that;
|
|
308
|
+
}
|
|
309
|
+
function fromObject(that, obj) {
|
|
310
|
+
if (internalIsBuffer(obj)) {
|
|
311
|
+
var len = checked(obj.length) | 0;
|
|
312
|
+
that = createBuffer(that, len);
|
|
313
|
+
if (that.length === 0) return that;
|
|
314
|
+
obj.copy(that, 0, 0, len);
|
|
315
|
+
return that;
|
|
316
|
+
}
|
|
317
|
+
if (obj) {
|
|
318
|
+
if (typeof ArrayBuffer !== "undefined" && obj.buffer instanceof ArrayBuffer || "length" in obj) {
|
|
319
|
+
if (typeof obj.length !== "number" || isnan(obj.length)) return createBuffer(that, 0);
|
|
320
|
+
return fromArrayLike(that, obj);
|
|
321
|
+
}
|
|
322
|
+
if (obj.type === "Buffer" && isArray(obj.data)) return fromArrayLike(that, obj.data);
|
|
323
|
+
}
|
|
324
|
+
throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.");
|
|
325
|
+
}
|
|
326
|
+
function checked(length) {
|
|
327
|
+
if (length >= kMaxLength()) throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x" + kMaxLength().toString(16) + " bytes");
|
|
328
|
+
return length | 0;
|
|
329
|
+
}
|
|
330
|
+
Buffer.isBuffer = isBuffer;
|
|
331
|
+
function internalIsBuffer(b) {
|
|
332
|
+
return !!(b != null && b._isBuffer);
|
|
333
|
+
}
|
|
334
|
+
Buffer.compare = function compare(a, b) {
|
|
335
|
+
if (!internalIsBuffer(a) || !internalIsBuffer(b)) throw new TypeError("Arguments must be Buffers");
|
|
336
|
+
if (a === b) return 0;
|
|
337
|
+
var x = a.length;
|
|
338
|
+
var y = b.length;
|
|
339
|
+
for (var i = 0, len = Math.min(x, y); i < len; ++i) if (a[i] !== b[i]) {
|
|
340
|
+
x = a[i];
|
|
341
|
+
y = b[i];
|
|
342
|
+
break;
|
|
343
|
+
}
|
|
344
|
+
if (x < y) return -1;
|
|
345
|
+
if (y < x) return 1;
|
|
346
|
+
return 0;
|
|
347
|
+
};
|
|
348
|
+
Buffer.isEncoding = function isEncoding(encoding) {
|
|
349
|
+
switch (String(encoding).toLowerCase()) {
|
|
350
|
+
case "hex":
|
|
351
|
+
case "utf8":
|
|
352
|
+
case "utf-8":
|
|
353
|
+
case "ascii":
|
|
354
|
+
case "latin1":
|
|
355
|
+
case "binary":
|
|
356
|
+
case "base64":
|
|
357
|
+
case "ucs2":
|
|
358
|
+
case "ucs-2":
|
|
359
|
+
case "utf16le":
|
|
360
|
+
case "utf-16le": return true;
|
|
361
|
+
default: return false;
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
Buffer.concat = function concat(list, length) {
|
|
365
|
+
if (!isArray(list)) throw new TypeError("\"list\" argument must be an Array of Buffers");
|
|
366
|
+
if (list.length === 0) return Buffer.alloc(0);
|
|
367
|
+
var i;
|
|
368
|
+
if (length === void 0) {
|
|
369
|
+
length = 0;
|
|
370
|
+
for (i = 0; i < list.length; ++i) length += list[i].length;
|
|
371
|
+
}
|
|
372
|
+
var buffer = Buffer.allocUnsafe(length);
|
|
373
|
+
var pos = 0;
|
|
374
|
+
for (i = 0; i < list.length; ++i) {
|
|
375
|
+
var buf = list[i];
|
|
376
|
+
if (!internalIsBuffer(buf)) throw new TypeError("\"list\" argument must be an Array of Buffers");
|
|
377
|
+
buf.copy(buffer, pos);
|
|
378
|
+
pos += buf.length;
|
|
379
|
+
}
|
|
380
|
+
return buffer;
|
|
381
|
+
};
|
|
382
|
+
function byteLength(string, encoding) {
|
|
383
|
+
if (internalIsBuffer(string)) return string.length;
|
|
384
|
+
if (typeof ArrayBuffer !== "undefined" && typeof ArrayBuffer.isView === "function" && (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) return string.byteLength;
|
|
385
|
+
if (typeof string !== "string") string = "" + string;
|
|
386
|
+
var len = string.length;
|
|
387
|
+
if (len === 0) return 0;
|
|
388
|
+
var loweredCase = false;
|
|
389
|
+
for (;;) switch (encoding) {
|
|
390
|
+
case "ascii":
|
|
391
|
+
case "latin1":
|
|
392
|
+
case "binary": return len;
|
|
393
|
+
case "utf8":
|
|
394
|
+
case "utf-8":
|
|
395
|
+
case void 0: return utf8ToBytes(string).length;
|
|
396
|
+
case "ucs2":
|
|
397
|
+
case "ucs-2":
|
|
398
|
+
case "utf16le":
|
|
399
|
+
case "utf-16le": return len * 2;
|
|
400
|
+
case "hex": return len >>> 1;
|
|
401
|
+
case "base64": return base64ToBytes(string).length;
|
|
402
|
+
default:
|
|
403
|
+
if (loweredCase) return utf8ToBytes(string).length;
|
|
404
|
+
encoding = ("" + encoding).toLowerCase();
|
|
405
|
+
loweredCase = true;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
Buffer.byteLength = byteLength;
|
|
409
|
+
function slowToString(encoding, start, end) {
|
|
410
|
+
var loweredCase = false;
|
|
411
|
+
if (start === void 0 || start < 0) start = 0;
|
|
412
|
+
if (start > this.length) return "";
|
|
413
|
+
if (end === void 0 || end > this.length) end = this.length;
|
|
414
|
+
if (end <= 0) return "";
|
|
415
|
+
end >>>= 0;
|
|
416
|
+
start >>>= 0;
|
|
417
|
+
if (end <= start) return "";
|
|
418
|
+
if (!encoding) encoding = "utf8";
|
|
419
|
+
while (true) switch (encoding) {
|
|
420
|
+
case "hex": return hexSlice(this, start, end);
|
|
421
|
+
case "utf8":
|
|
422
|
+
case "utf-8": return utf8Slice(this, start, end);
|
|
423
|
+
case "ascii": return asciiSlice(this, start, end);
|
|
424
|
+
case "latin1":
|
|
425
|
+
case "binary": return latin1Slice(this, start, end);
|
|
426
|
+
case "base64": return base64Slice(this, start, end);
|
|
427
|
+
case "ucs2":
|
|
428
|
+
case "ucs-2":
|
|
429
|
+
case "utf16le":
|
|
430
|
+
case "utf-16le": return utf16leSlice(this, start, end);
|
|
431
|
+
default:
|
|
432
|
+
if (loweredCase) throw new TypeError("Unknown encoding: " + encoding);
|
|
433
|
+
encoding = (encoding + "").toLowerCase();
|
|
434
|
+
loweredCase = true;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
Buffer.prototype._isBuffer = true;
|
|
438
|
+
function swap(b, n, m) {
|
|
439
|
+
var i = b[n];
|
|
440
|
+
b[n] = b[m];
|
|
441
|
+
b[m] = i;
|
|
442
|
+
}
|
|
443
|
+
Buffer.prototype.swap16 = function swap16() {
|
|
444
|
+
var len = this.length;
|
|
445
|
+
if (len % 2 !== 0) throw new RangeError("Buffer size must be a multiple of 16-bits");
|
|
446
|
+
for (var i = 0; i < len; i += 2) swap(this, i, i + 1);
|
|
447
|
+
return this;
|
|
448
|
+
};
|
|
449
|
+
Buffer.prototype.swap32 = function swap32() {
|
|
450
|
+
var len = this.length;
|
|
451
|
+
if (len % 4 !== 0) throw new RangeError("Buffer size must be a multiple of 32-bits");
|
|
452
|
+
for (var i = 0; i < len; i += 4) {
|
|
453
|
+
swap(this, i, i + 3);
|
|
454
|
+
swap(this, i + 1, i + 2);
|
|
455
|
+
}
|
|
456
|
+
return this;
|
|
457
|
+
};
|
|
458
|
+
Buffer.prototype.swap64 = function swap64() {
|
|
459
|
+
var len = this.length;
|
|
460
|
+
if (len % 8 !== 0) throw new RangeError("Buffer size must be a multiple of 64-bits");
|
|
461
|
+
for (var i = 0; i < len; i += 8) {
|
|
462
|
+
swap(this, i, i + 7);
|
|
463
|
+
swap(this, i + 1, i + 6);
|
|
464
|
+
swap(this, i + 2, i + 5);
|
|
465
|
+
swap(this, i + 3, i + 4);
|
|
466
|
+
}
|
|
467
|
+
return this;
|
|
468
|
+
};
|
|
469
|
+
Buffer.prototype.toString = function toString() {
|
|
470
|
+
var length = this.length | 0;
|
|
471
|
+
if (length === 0) return "";
|
|
472
|
+
if (arguments.length === 0) return utf8Slice(this, 0, length);
|
|
473
|
+
return slowToString.apply(this, arguments);
|
|
474
|
+
};
|
|
475
|
+
Buffer.prototype.equals = function equals(b) {
|
|
476
|
+
if (!internalIsBuffer(b)) throw new TypeError("Argument must be a Buffer");
|
|
477
|
+
if (this === b) return true;
|
|
478
|
+
return Buffer.compare(this, b) === 0;
|
|
479
|
+
};
|
|
480
|
+
Buffer.prototype.inspect = function inspect() {
|
|
481
|
+
var str = "";
|
|
482
|
+
var max = 50;
|
|
483
|
+
if (this.length > 0) {
|
|
484
|
+
str = this.toString("hex", 0, max).match(/.{2}/g).join(" ");
|
|
485
|
+
if (this.length > max) str += " ... ";
|
|
486
|
+
}
|
|
487
|
+
return "<Buffer " + str + ">";
|
|
488
|
+
};
|
|
489
|
+
Buffer.prototype.compare = function compare(target, start, end, thisStart, thisEnd) {
|
|
490
|
+
if (!internalIsBuffer(target)) throw new TypeError("Argument must be a Buffer");
|
|
491
|
+
if (start === void 0) start = 0;
|
|
492
|
+
if (end === void 0) end = target ? target.length : 0;
|
|
493
|
+
if (thisStart === void 0) thisStart = 0;
|
|
494
|
+
if (thisEnd === void 0) thisEnd = this.length;
|
|
495
|
+
if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) throw new RangeError("out of range index");
|
|
496
|
+
if (thisStart >= thisEnd && start >= end) return 0;
|
|
497
|
+
if (thisStart >= thisEnd) return -1;
|
|
498
|
+
if (start >= end) return 1;
|
|
499
|
+
start >>>= 0;
|
|
500
|
+
end >>>= 0;
|
|
501
|
+
thisStart >>>= 0;
|
|
502
|
+
thisEnd >>>= 0;
|
|
503
|
+
if (this === target) return 0;
|
|
504
|
+
var x = thisEnd - thisStart;
|
|
505
|
+
var y = end - start;
|
|
506
|
+
var len = Math.min(x, y);
|
|
507
|
+
var thisCopy = this.slice(thisStart, thisEnd);
|
|
508
|
+
var targetCopy = target.slice(start, end);
|
|
509
|
+
for (var i = 0; i < len; ++i) if (thisCopy[i] !== targetCopy[i]) {
|
|
510
|
+
x = thisCopy[i];
|
|
511
|
+
y = targetCopy[i];
|
|
512
|
+
break;
|
|
513
|
+
}
|
|
514
|
+
if (x < y) return -1;
|
|
515
|
+
if (y < x) return 1;
|
|
516
|
+
return 0;
|
|
517
|
+
};
|
|
518
|
+
function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
|
|
519
|
+
if (buffer.length === 0) return -1;
|
|
520
|
+
if (typeof byteOffset === "string") {
|
|
521
|
+
encoding = byteOffset;
|
|
522
|
+
byteOffset = 0;
|
|
523
|
+
} else if (byteOffset > 2147483647) byteOffset = 2147483647;
|
|
524
|
+
else if (byteOffset < -2147483648) byteOffset = -2147483648;
|
|
525
|
+
byteOffset = +byteOffset;
|
|
526
|
+
if (isNaN(byteOffset)) byteOffset = dir ? 0 : buffer.length - 1;
|
|
527
|
+
if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
|
|
528
|
+
if (byteOffset >= buffer.length) if (dir) return -1;
|
|
529
|
+
else byteOffset = buffer.length - 1;
|
|
530
|
+
else if (byteOffset < 0) if (dir) byteOffset = 0;
|
|
531
|
+
else return -1;
|
|
532
|
+
if (typeof val === "string") val = Buffer.from(val, encoding);
|
|
533
|
+
if (internalIsBuffer(val)) {
|
|
534
|
+
if (val.length === 0) return -1;
|
|
535
|
+
return arrayIndexOf(buffer, val, byteOffset, encoding, dir);
|
|
536
|
+
} else if (typeof val === "number") {
|
|
537
|
+
val = val & 255;
|
|
538
|
+
if (Buffer.TYPED_ARRAY_SUPPORT && typeof Uint8Array.prototype.indexOf === "function") if (dir) return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset);
|
|
539
|
+
else return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset);
|
|
540
|
+
return arrayIndexOf(buffer, [val], byteOffset, encoding, dir);
|
|
541
|
+
}
|
|
542
|
+
throw new TypeError("val must be string, number or Buffer");
|
|
543
|
+
}
|
|
544
|
+
function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
|
|
545
|
+
var indexSize = 1;
|
|
546
|
+
var arrLength = arr.length;
|
|
547
|
+
var valLength = val.length;
|
|
548
|
+
if (encoding !== void 0) {
|
|
549
|
+
encoding = String(encoding).toLowerCase();
|
|
550
|
+
if (encoding === "ucs2" || encoding === "ucs-2" || encoding === "utf16le" || encoding === "utf-16le") {
|
|
551
|
+
if (arr.length < 2 || val.length < 2) return -1;
|
|
552
|
+
indexSize = 2;
|
|
553
|
+
arrLength /= 2;
|
|
554
|
+
valLength /= 2;
|
|
555
|
+
byteOffset /= 2;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
function read(buf, i) {
|
|
559
|
+
if (indexSize === 1) return buf[i];
|
|
560
|
+
else return buf.readUInt16BE(i * indexSize);
|
|
561
|
+
}
|
|
562
|
+
var i;
|
|
563
|
+
if (dir) {
|
|
564
|
+
var foundIndex = -1;
|
|
565
|
+
for (i = byteOffset; i < arrLength; i++) if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
|
566
|
+
if (foundIndex === -1) foundIndex = i;
|
|
567
|
+
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize;
|
|
568
|
+
} else {
|
|
569
|
+
if (foundIndex !== -1) i -= i - foundIndex;
|
|
570
|
+
foundIndex = -1;
|
|
571
|
+
}
|
|
572
|
+
} else {
|
|
573
|
+
if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
|
|
574
|
+
for (i = byteOffset; i >= 0; i--) {
|
|
575
|
+
var found = true;
|
|
576
|
+
for (var j = 0; j < valLength; j++) if (read(arr, i + j) !== read(val, j)) {
|
|
577
|
+
found = false;
|
|
578
|
+
break;
|
|
579
|
+
}
|
|
580
|
+
if (found) return i;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
return -1;
|
|
584
|
+
}
|
|
585
|
+
Buffer.prototype.includes = function includes(val, byteOffset, encoding) {
|
|
586
|
+
return this.indexOf(val, byteOffset, encoding) !== -1;
|
|
587
|
+
};
|
|
588
|
+
Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
|
|
589
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, true);
|
|
590
|
+
};
|
|
591
|
+
Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {
|
|
592
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, false);
|
|
593
|
+
};
|
|
594
|
+
function hexWrite(buf, string, offset, length) {
|
|
595
|
+
offset = Number(offset) || 0;
|
|
596
|
+
var remaining = buf.length - offset;
|
|
597
|
+
if (!length) length = remaining;
|
|
598
|
+
else {
|
|
599
|
+
length = Number(length);
|
|
600
|
+
if (length > remaining) length = remaining;
|
|
601
|
+
}
|
|
602
|
+
var strLen = string.length;
|
|
603
|
+
if (strLen % 2 !== 0) throw new TypeError("Invalid hex string");
|
|
604
|
+
if (length > strLen / 2) length = strLen / 2;
|
|
605
|
+
for (var i = 0; i < length; ++i) {
|
|
606
|
+
var parsed = parseInt(string.substr(i * 2, 2), 16);
|
|
607
|
+
if (isNaN(parsed)) return i;
|
|
608
|
+
buf[offset + i] = parsed;
|
|
609
|
+
}
|
|
610
|
+
return i;
|
|
611
|
+
}
|
|
612
|
+
function utf8Write(buf, string, offset, length) {
|
|
613
|
+
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length);
|
|
614
|
+
}
|
|
615
|
+
function asciiWrite(buf, string, offset, length) {
|
|
616
|
+
return blitBuffer(asciiToBytes(string), buf, offset, length);
|
|
617
|
+
}
|
|
618
|
+
function latin1Write(buf, string, offset, length) {
|
|
619
|
+
return asciiWrite(buf, string, offset, length);
|
|
620
|
+
}
|
|
621
|
+
function base64Write(buf, string, offset, length) {
|
|
622
|
+
return blitBuffer(base64ToBytes(string), buf, offset, length);
|
|
623
|
+
}
|
|
624
|
+
function ucs2Write(buf, string, offset, length) {
|
|
625
|
+
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length);
|
|
626
|
+
}
|
|
627
|
+
Buffer.prototype.write = function write(string, offset, length, encoding) {
|
|
628
|
+
if (offset === void 0) {
|
|
629
|
+
encoding = "utf8";
|
|
630
|
+
length = this.length;
|
|
631
|
+
offset = 0;
|
|
632
|
+
} else if (length === void 0 && typeof offset === "string") {
|
|
633
|
+
encoding = offset;
|
|
634
|
+
length = this.length;
|
|
635
|
+
offset = 0;
|
|
636
|
+
} else if (isFinite(offset)) {
|
|
637
|
+
offset = offset | 0;
|
|
638
|
+
if (isFinite(length)) {
|
|
639
|
+
length = length | 0;
|
|
640
|
+
if (encoding === void 0) encoding = "utf8";
|
|
641
|
+
} else {
|
|
642
|
+
encoding = length;
|
|
643
|
+
length = void 0;
|
|
644
|
+
}
|
|
645
|
+
} else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");
|
|
646
|
+
var remaining = this.length - offset;
|
|
647
|
+
if (length === void 0 || length > remaining) length = remaining;
|
|
648
|
+
if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) throw new RangeError("Attempt to write outside buffer bounds");
|
|
649
|
+
if (!encoding) encoding = "utf8";
|
|
650
|
+
var loweredCase = false;
|
|
651
|
+
for (;;) switch (encoding) {
|
|
652
|
+
case "hex": return hexWrite(this, string, offset, length);
|
|
653
|
+
case "utf8":
|
|
654
|
+
case "utf-8": return utf8Write(this, string, offset, length);
|
|
655
|
+
case "ascii": return asciiWrite(this, string, offset, length);
|
|
656
|
+
case "latin1":
|
|
657
|
+
case "binary": return latin1Write(this, string, offset, length);
|
|
658
|
+
case "base64": return base64Write(this, string, offset, length);
|
|
659
|
+
case "ucs2":
|
|
660
|
+
case "ucs-2":
|
|
661
|
+
case "utf16le":
|
|
662
|
+
case "utf-16le": return ucs2Write(this, string, offset, length);
|
|
663
|
+
default:
|
|
664
|
+
if (loweredCase) throw new TypeError("Unknown encoding: " + encoding);
|
|
665
|
+
encoding = ("" + encoding).toLowerCase();
|
|
666
|
+
loweredCase = true;
|
|
667
|
+
}
|
|
668
|
+
};
|
|
669
|
+
Buffer.prototype.toJSON = function toJSON() {
|
|
670
|
+
return {
|
|
671
|
+
type: "Buffer",
|
|
672
|
+
data: Array.prototype.slice.call(this._arr || this, 0)
|
|
673
|
+
};
|
|
674
|
+
};
|
|
675
|
+
function base64Slice(buf, start, end) {
|
|
676
|
+
if (start === 0 && end === buf.length) return fromByteArray(buf);
|
|
677
|
+
else return fromByteArray(buf.slice(start, end));
|
|
678
|
+
}
|
|
679
|
+
function utf8Slice(buf, start, end) {
|
|
680
|
+
end = Math.min(buf.length, end);
|
|
681
|
+
var res = [];
|
|
682
|
+
var i = start;
|
|
683
|
+
while (i < end) {
|
|
684
|
+
var firstByte = buf[i];
|
|
685
|
+
var codePoint = null;
|
|
686
|
+
var bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1;
|
|
687
|
+
if (i + bytesPerSequence <= end) {
|
|
688
|
+
var secondByte, thirdByte, fourthByte, tempCodePoint;
|
|
689
|
+
switch (bytesPerSequence) {
|
|
690
|
+
case 1:
|
|
691
|
+
if (firstByte < 128) codePoint = firstByte;
|
|
692
|
+
break;
|
|
693
|
+
case 2:
|
|
694
|
+
secondByte = buf[i + 1];
|
|
695
|
+
if ((secondByte & 192) === 128) {
|
|
696
|
+
tempCodePoint = (firstByte & 31) << 6 | secondByte & 63;
|
|
697
|
+
if (tempCodePoint > 127) codePoint = tempCodePoint;
|
|
698
|
+
}
|
|
699
|
+
break;
|
|
700
|
+
case 3:
|
|
701
|
+
secondByte = buf[i + 1];
|
|
702
|
+
thirdByte = buf[i + 2];
|
|
703
|
+
if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) {
|
|
704
|
+
tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63;
|
|
705
|
+
if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) codePoint = tempCodePoint;
|
|
706
|
+
}
|
|
707
|
+
break;
|
|
708
|
+
case 4:
|
|
709
|
+
secondByte = buf[i + 1];
|
|
710
|
+
thirdByte = buf[i + 2];
|
|
711
|
+
fourthByte = buf[i + 3];
|
|
712
|
+
if ((secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) {
|
|
713
|
+
tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63;
|
|
714
|
+
if (tempCodePoint > 65535 && tempCodePoint < 1114112) codePoint = tempCodePoint;
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
if (codePoint === null) {
|
|
719
|
+
codePoint = 65533;
|
|
720
|
+
bytesPerSequence = 1;
|
|
721
|
+
} else if (codePoint > 65535) {
|
|
722
|
+
codePoint -= 65536;
|
|
723
|
+
res.push(codePoint >>> 10 & 1023 | 55296);
|
|
724
|
+
codePoint = 56320 | codePoint & 1023;
|
|
725
|
+
}
|
|
726
|
+
res.push(codePoint);
|
|
727
|
+
i += bytesPerSequence;
|
|
728
|
+
}
|
|
729
|
+
return decodeCodePointsArray(res);
|
|
730
|
+
}
|
|
731
|
+
var MAX_ARGUMENTS_LENGTH = 4096;
|
|
732
|
+
function decodeCodePointsArray(codePoints) {
|
|
733
|
+
var len = codePoints.length;
|
|
734
|
+
if (len <= MAX_ARGUMENTS_LENGTH) return String.fromCharCode.apply(String, codePoints);
|
|
735
|
+
var res = "";
|
|
736
|
+
var i = 0;
|
|
737
|
+
while (i < len) res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH));
|
|
738
|
+
return res;
|
|
739
|
+
}
|
|
740
|
+
function asciiSlice(buf, start, end) {
|
|
741
|
+
var ret = "";
|
|
742
|
+
end = Math.min(buf.length, end);
|
|
743
|
+
for (var i = start; i < end; ++i) ret += String.fromCharCode(buf[i] & 127);
|
|
744
|
+
return ret;
|
|
745
|
+
}
|
|
746
|
+
function latin1Slice(buf, start, end) {
|
|
747
|
+
var ret = "";
|
|
748
|
+
end = Math.min(buf.length, end);
|
|
749
|
+
for (var i = start; i < end; ++i) ret += String.fromCharCode(buf[i]);
|
|
750
|
+
return ret;
|
|
751
|
+
}
|
|
752
|
+
function hexSlice(buf, start, end) {
|
|
753
|
+
var len = buf.length;
|
|
754
|
+
if (!start || start < 0) start = 0;
|
|
755
|
+
if (!end || end < 0 || end > len) end = len;
|
|
756
|
+
var out = "";
|
|
757
|
+
for (var i = start; i < end; ++i) out += toHex(buf[i]);
|
|
758
|
+
return out;
|
|
759
|
+
}
|
|
760
|
+
function utf16leSlice(buf, start, end) {
|
|
761
|
+
var bytes = buf.slice(start, end);
|
|
762
|
+
var res = "";
|
|
763
|
+
for (var i = 0; i < bytes.length; i += 2) res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
|
|
764
|
+
return res;
|
|
765
|
+
}
|
|
766
|
+
Buffer.prototype.slice = function slice(start, end) {
|
|
767
|
+
var len = this.length;
|
|
768
|
+
start = ~~start;
|
|
769
|
+
end = end === void 0 ? len : ~~end;
|
|
770
|
+
if (start < 0) {
|
|
771
|
+
start += len;
|
|
772
|
+
if (start < 0) start = 0;
|
|
773
|
+
} else if (start > len) start = len;
|
|
774
|
+
if (end < 0) {
|
|
775
|
+
end += len;
|
|
776
|
+
if (end < 0) end = 0;
|
|
777
|
+
} else if (end > len) end = len;
|
|
778
|
+
if (end < start) end = start;
|
|
779
|
+
var newBuf;
|
|
780
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
781
|
+
newBuf = this.subarray(start, end);
|
|
782
|
+
newBuf.__proto__ = Buffer.prototype;
|
|
783
|
+
} else {
|
|
784
|
+
var sliceLen = end - start;
|
|
785
|
+
newBuf = new Buffer(sliceLen, void 0);
|
|
786
|
+
for (var i = 0; i < sliceLen; ++i) newBuf[i] = this[i + start];
|
|
787
|
+
}
|
|
788
|
+
return newBuf;
|
|
789
|
+
};
|
|
790
|
+
function checkOffset(offset, ext, length) {
|
|
791
|
+
if (offset % 1 !== 0 || offset < 0) throw new RangeError("offset is not uint");
|
|
792
|
+
if (offset + ext > length) throw new RangeError("Trying to access beyond buffer length");
|
|
793
|
+
}
|
|
794
|
+
Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength, noAssert) {
|
|
795
|
+
offset = offset | 0;
|
|
796
|
+
byteLength = byteLength | 0;
|
|
797
|
+
if (!noAssert) checkOffset(offset, byteLength, this.length);
|
|
798
|
+
var val = this[offset];
|
|
799
|
+
var mul = 1;
|
|
800
|
+
var i = 0;
|
|
801
|
+
while (++i < byteLength && (mul *= 256)) val += this[offset + i] * mul;
|
|
802
|
+
return val;
|
|
803
|
+
};
|
|
804
|
+
Buffer.prototype.readUIntBE = function readUIntBE(offset, byteLength, noAssert) {
|
|
805
|
+
offset = offset | 0;
|
|
806
|
+
byteLength = byteLength | 0;
|
|
807
|
+
if (!noAssert) checkOffset(offset, byteLength, this.length);
|
|
808
|
+
var val = this[offset + --byteLength];
|
|
809
|
+
var mul = 1;
|
|
810
|
+
while (byteLength > 0 && (mul *= 256)) val += this[offset + --byteLength] * mul;
|
|
811
|
+
return val;
|
|
812
|
+
};
|
|
813
|
+
Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) {
|
|
814
|
+
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
815
|
+
return this[offset];
|
|
816
|
+
};
|
|
817
|
+
Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) {
|
|
818
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
819
|
+
return this[offset] | this[offset + 1] << 8;
|
|
820
|
+
};
|
|
821
|
+
Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) {
|
|
822
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
823
|
+
return this[offset] << 8 | this[offset + 1];
|
|
824
|
+
};
|
|
825
|
+
Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) {
|
|
826
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
827
|
+
return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 16777216;
|
|
828
|
+
};
|
|
829
|
+
Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {
|
|
830
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
831
|
+
return this[offset] * 16777216 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]);
|
|
832
|
+
};
|
|
833
|
+
Buffer.prototype.readIntLE = function readIntLE(offset, byteLength, noAssert) {
|
|
834
|
+
offset = offset | 0;
|
|
835
|
+
byteLength = byteLength | 0;
|
|
836
|
+
if (!noAssert) checkOffset(offset, byteLength, this.length);
|
|
837
|
+
var val = this[offset];
|
|
838
|
+
var mul = 1;
|
|
839
|
+
var i = 0;
|
|
840
|
+
while (++i < byteLength && (mul *= 256)) val += this[offset + i] * mul;
|
|
841
|
+
mul *= 128;
|
|
842
|
+
if (val >= mul) val -= Math.pow(2, 8 * byteLength);
|
|
843
|
+
return val;
|
|
844
|
+
};
|
|
845
|
+
Buffer.prototype.readIntBE = function readIntBE(offset, byteLength, noAssert) {
|
|
846
|
+
offset = offset | 0;
|
|
847
|
+
byteLength = byteLength | 0;
|
|
848
|
+
if (!noAssert) checkOffset(offset, byteLength, this.length);
|
|
849
|
+
var i = byteLength;
|
|
850
|
+
var mul = 1;
|
|
851
|
+
var val = this[offset + --i];
|
|
852
|
+
while (i > 0 && (mul *= 256)) val += this[offset + --i] * mul;
|
|
853
|
+
mul *= 128;
|
|
854
|
+
if (val >= mul) val -= Math.pow(2, 8 * byteLength);
|
|
855
|
+
return val;
|
|
856
|
+
};
|
|
857
|
+
Buffer.prototype.readInt8 = function readInt8(offset, noAssert) {
|
|
858
|
+
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
859
|
+
if (!(this[offset] & 128)) return this[offset];
|
|
860
|
+
return (255 - this[offset] + 1) * -1;
|
|
861
|
+
};
|
|
862
|
+
Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) {
|
|
863
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
864
|
+
var val = this[offset] | this[offset + 1] << 8;
|
|
865
|
+
return val & 32768 ? val | 4294901760 : val;
|
|
866
|
+
};
|
|
867
|
+
Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) {
|
|
868
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
869
|
+
var val = this[offset + 1] | this[offset] << 8;
|
|
870
|
+
return val & 32768 ? val | 4294901760 : val;
|
|
871
|
+
};
|
|
872
|
+
Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) {
|
|
873
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
874
|
+
return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24;
|
|
875
|
+
};
|
|
876
|
+
Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) {
|
|
877
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
878
|
+
return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3];
|
|
879
|
+
};
|
|
880
|
+
Buffer.prototype.readFloatLE = function readFloatLE(offset, noAssert) {
|
|
881
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
882
|
+
return read(this, offset, true, 23, 4);
|
|
883
|
+
};
|
|
884
|
+
Buffer.prototype.readFloatBE = function readFloatBE(offset, noAssert) {
|
|
885
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
886
|
+
return read(this, offset, false, 23, 4);
|
|
887
|
+
};
|
|
888
|
+
Buffer.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) {
|
|
889
|
+
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
890
|
+
return read(this, offset, true, 52, 8);
|
|
891
|
+
};
|
|
892
|
+
Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {
|
|
893
|
+
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
894
|
+
return read(this, offset, false, 52, 8);
|
|
895
|
+
};
|
|
896
|
+
function checkInt(buf, value, offset, ext, max, min) {
|
|
897
|
+
if (!internalIsBuffer(buf)) throw new TypeError("\"buffer\" argument must be a Buffer instance");
|
|
898
|
+
if (value > max || value < min) throw new RangeError("\"value\" argument is out of bounds");
|
|
899
|
+
if (offset + ext > buf.length) throw new RangeError("Index out of range");
|
|
900
|
+
}
|
|
901
|
+
Buffer.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength, noAssert) {
|
|
902
|
+
value = +value;
|
|
903
|
+
offset = offset | 0;
|
|
904
|
+
byteLength = byteLength | 0;
|
|
905
|
+
if (!noAssert) {
|
|
906
|
+
var maxBytes = Math.pow(2, 8 * byteLength) - 1;
|
|
907
|
+
checkInt(this, value, offset, byteLength, maxBytes, 0);
|
|
908
|
+
}
|
|
909
|
+
var mul = 1;
|
|
910
|
+
var i = 0;
|
|
911
|
+
this[offset] = value & 255;
|
|
912
|
+
while (++i < byteLength && (mul *= 256)) this[offset + i] = value / mul & 255;
|
|
913
|
+
return offset + byteLength;
|
|
914
|
+
};
|
|
915
|
+
Buffer.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength, noAssert) {
|
|
916
|
+
value = +value;
|
|
917
|
+
offset = offset | 0;
|
|
918
|
+
byteLength = byteLength | 0;
|
|
919
|
+
if (!noAssert) {
|
|
920
|
+
var maxBytes = Math.pow(2, 8 * byteLength) - 1;
|
|
921
|
+
checkInt(this, value, offset, byteLength, maxBytes, 0);
|
|
922
|
+
}
|
|
923
|
+
var i = byteLength - 1;
|
|
924
|
+
var mul = 1;
|
|
925
|
+
this[offset + i] = value & 255;
|
|
926
|
+
while (--i >= 0 && (mul *= 256)) this[offset + i] = value / mul & 255;
|
|
927
|
+
return offset + byteLength;
|
|
928
|
+
};
|
|
929
|
+
Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) {
|
|
930
|
+
value = +value;
|
|
931
|
+
offset = offset | 0;
|
|
932
|
+
if (!noAssert) checkInt(this, value, offset, 1, 255, 0);
|
|
933
|
+
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
|
|
934
|
+
this[offset] = value & 255;
|
|
935
|
+
return offset + 1;
|
|
936
|
+
};
|
|
937
|
+
function objectWriteUInt16(buf, value, offset, littleEndian) {
|
|
938
|
+
if (value < 0) value = 65535 + value + 1;
|
|
939
|
+
for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) buf[offset + i] = (value & 255 << 8 * (littleEndian ? i : 1 - i)) >>> (littleEndian ? i : 1 - i) * 8;
|
|
940
|
+
}
|
|
941
|
+
Buffer.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) {
|
|
942
|
+
value = +value;
|
|
943
|
+
offset = offset | 0;
|
|
944
|
+
if (!noAssert) checkInt(this, value, offset, 2, 65535, 0);
|
|
945
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
946
|
+
this[offset] = value & 255;
|
|
947
|
+
this[offset + 1] = value >>> 8;
|
|
948
|
+
} else objectWriteUInt16(this, value, offset, true);
|
|
949
|
+
return offset + 2;
|
|
950
|
+
};
|
|
951
|
+
Buffer.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) {
|
|
952
|
+
value = +value;
|
|
953
|
+
offset = offset | 0;
|
|
954
|
+
if (!noAssert) checkInt(this, value, offset, 2, 65535, 0);
|
|
955
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
956
|
+
this[offset] = value >>> 8;
|
|
957
|
+
this[offset + 1] = value & 255;
|
|
958
|
+
} else objectWriteUInt16(this, value, offset, false);
|
|
959
|
+
return offset + 2;
|
|
960
|
+
};
|
|
961
|
+
function objectWriteUInt32(buf, value, offset, littleEndian) {
|
|
962
|
+
if (value < 0) value = 4294967295 + value + 1;
|
|
963
|
+
for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) buf[offset + i] = value >>> (littleEndian ? i : 3 - i) * 8 & 255;
|
|
964
|
+
}
|
|
965
|
+
Buffer.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) {
|
|
966
|
+
value = +value;
|
|
967
|
+
offset = offset | 0;
|
|
968
|
+
if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0);
|
|
969
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
970
|
+
this[offset + 3] = value >>> 24;
|
|
971
|
+
this[offset + 2] = value >>> 16;
|
|
972
|
+
this[offset + 1] = value >>> 8;
|
|
973
|
+
this[offset] = value & 255;
|
|
974
|
+
} else objectWriteUInt32(this, value, offset, true);
|
|
975
|
+
return offset + 4;
|
|
976
|
+
};
|
|
977
|
+
Buffer.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) {
|
|
978
|
+
value = +value;
|
|
979
|
+
offset = offset | 0;
|
|
980
|
+
if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0);
|
|
981
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
982
|
+
this[offset] = value >>> 24;
|
|
983
|
+
this[offset + 1] = value >>> 16;
|
|
984
|
+
this[offset + 2] = value >>> 8;
|
|
985
|
+
this[offset + 3] = value & 255;
|
|
986
|
+
} else objectWriteUInt32(this, value, offset, false);
|
|
987
|
+
return offset + 4;
|
|
988
|
+
};
|
|
989
|
+
Buffer.prototype.writeIntLE = function writeIntLE(value, offset, byteLength, noAssert) {
|
|
990
|
+
value = +value;
|
|
991
|
+
offset = offset | 0;
|
|
992
|
+
if (!noAssert) {
|
|
993
|
+
var limit = Math.pow(2, 8 * byteLength - 1);
|
|
994
|
+
checkInt(this, value, offset, byteLength, limit - 1, -limit);
|
|
995
|
+
}
|
|
996
|
+
var i = 0;
|
|
997
|
+
var mul = 1;
|
|
998
|
+
var sub = 0;
|
|
999
|
+
this[offset] = value & 255;
|
|
1000
|
+
while (++i < byteLength && (mul *= 256)) {
|
|
1001
|
+
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) sub = 1;
|
|
1002
|
+
this[offset + i] = (value / mul >> 0) - sub & 255;
|
|
1003
|
+
}
|
|
1004
|
+
return offset + byteLength;
|
|
1005
|
+
};
|
|
1006
|
+
Buffer.prototype.writeIntBE = function writeIntBE(value, offset, byteLength, noAssert) {
|
|
1007
|
+
value = +value;
|
|
1008
|
+
offset = offset | 0;
|
|
1009
|
+
if (!noAssert) {
|
|
1010
|
+
var limit = Math.pow(2, 8 * byteLength - 1);
|
|
1011
|
+
checkInt(this, value, offset, byteLength, limit - 1, -limit);
|
|
1012
|
+
}
|
|
1013
|
+
var i = byteLength - 1;
|
|
1014
|
+
var mul = 1;
|
|
1015
|
+
var sub = 0;
|
|
1016
|
+
this[offset + i] = value & 255;
|
|
1017
|
+
while (--i >= 0 && (mul *= 256)) {
|
|
1018
|
+
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) sub = 1;
|
|
1019
|
+
this[offset + i] = (value / mul >> 0) - sub & 255;
|
|
1020
|
+
}
|
|
1021
|
+
return offset + byteLength;
|
|
1022
|
+
};
|
|
1023
|
+
Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) {
|
|
1024
|
+
value = +value;
|
|
1025
|
+
offset = offset | 0;
|
|
1026
|
+
if (!noAssert) checkInt(this, value, offset, 1, 127, -128);
|
|
1027
|
+
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
|
|
1028
|
+
if (value < 0) value = 255 + value + 1;
|
|
1029
|
+
this[offset] = value & 255;
|
|
1030
|
+
return offset + 1;
|
|
1031
|
+
};
|
|
1032
|
+
Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) {
|
|
1033
|
+
value = +value;
|
|
1034
|
+
offset = offset | 0;
|
|
1035
|
+
if (!noAssert) checkInt(this, value, offset, 2, 32767, -32768);
|
|
1036
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1037
|
+
this[offset] = value & 255;
|
|
1038
|
+
this[offset + 1] = value >>> 8;
|
|
1039
|
+
} else objectWriteUInt16(this, value, offset, true);
|
|
1040
|
+
return offset + 2;
|
|
1041
|
+
};
|
|
1042
|
+
Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) {
|
|
1043
|
+
value = +value;
|
|
1044
|
+
offset = offset | 0;
|
|
1045
|
+
if (!noAssert) checkInt(this, value, offset, 2, 32767, -32768);
|
|
1046
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1047
|
+
this[offset] = value >>> 8;
|
|
1048
|
+
this[offset + 1] = value & 255;
|
|
1049
|
+
} else objectWriteUInt16(this, value, offset, false);
|
|
1050
|
+
return offset + 2;
|
|
1051
|
+
};
|
|
1052
|
+
Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) {
|
|
1053
|
+
value = +value;
|
|
1054
|
+
offset = offset | 0;
|
|
1055
|
+
if (!noAssert) checkInt(this, value, offset, 4, 2147483647, -2147483648);
|
|
1056
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1057
|
+
this[offset] = value & 255;
|
|
1058
|
+
this[offset + 1] = value >>> 8;
|
|
1059
|
+
this[offset + 2] = value >>> 16;
|
|
1060
|
+
this[offset + 3] = value >>> 24;
|
|
1061
|
+
} else objectWriteUInt32(this, value, offset, true);
|
|
1062
|
+
return offset + 4;
|
|
1063
|
+
};
|
|
1064
|
+
Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) {
|
|
1065
|
+
value = +value;
|
|
1066
|
+
offset = offset | 0;
|
|
1067
|
+
if (!noAssert) checkInt(this, value, offset, 4, 2147483647, -2147483648);
|
|
1068
|
+
if (value < 0) value = 4294967295 + value + 1;
|
|
1069
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1070
|
+
this[offset] = value >>> 24;
|
|
1071
|
+
this[offset + 1] = value >>> 16;
|
|
1072
|
+
this[offset + 2] = value >>> 8;
|
|
1073
|
+
this[offset + 3] = value & 255;
|
|
1074
|
+
} else objectWriteUInt32(this, value, offset, false);
|
|
1075
|
+
return offset + 4;
|
|
1076
|
+
};
|
|
1077
|
+
function checkIEEE754(buf, value, offset, ext, max, min) {
|
|
1078
|
+
if (offset + ext > buf.length) throw new RangeError("Index out of range");
|
|
1079
|
+
if (offset < 0) throw new RangeError("Index out of range");
|
|
1080
|
+
}
|
|
1081
|
+
function writeFloat(buf, value, offset, littleEndian, noAssert) {
|
|
1082
|
+
if (!noAssert) checkIEEE754(buf, value, offset, 4);
|
|
1083
|
+
write(buf, value, offset, littleEndian, 23, 4);
|
|
1084
|
+
return offset + 4;
|
|
1085
|
+
}
|
|
1086
|
+
Buffer.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) {
|
|
1087
|
+
return writeFloat(this, value, offset, true, noAssert);
|
|
1088
|
+
};
|
|
1089
|
+
Buffer.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) {
|
|
1090
|
+
return writeFloat(this, value, offset, false, noAssert);
|
|
1091
|
+
};
|
|
1092
|
+
function writeDouble(buf, value, offset, littleEndian, noAssert) {
|
|
1093
|
+
if (!noAssert) checkIEEE754(buf, value, offset, 8);
|
|
1094
|
+
write(buf, value, offset, littleEndian, 52, 8);
|
|
1095
|
+
return offset + 8;
|
|
1096
|
+
}
|
|
1097
|
+
Buffer.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) {
|
|
1098
|
+
return writeDouble(this, value, offset, true, noAssert);
|
|
1099
|
+
};
|
|
1100
|
+
Buffer.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) {
|
|
1101
|
+
return writeDouble(this, value, offset, false, noAssert);
|
|
1102
|
+
};
|
|
1103
|
+
Buffer.prototype.copy = function copy(target, targetStart, start, end) {
|
|
1104
|
+
if (!start) start = 0;
|
|
1105
|
+
if (!end && end !== 0) end = this.length;
|
|
1106
|
+
if (targetStart >= target.length) targetStart = target.length;
|
|
1107
|
+
if (!targetStart) targetStart = 0;
|
|
1108
|
+
if (end > 0 && end < start) end = start;
|
|
1109
|
+
if (end === start) return 0;
|
|
1110
|
+
if (target.length === 0 || this.length === 0) return 0;
|
|
1111
|
+
if (targetStart < 0) throw new RangeError("targetStart out of bounds");
|
|
1112
|
+
if (start < 0 || start >= this.length) throw new RangeError("sourceStart out of bounds");
|
|
1113
|
+
if (end < 0) throw new RangeError("sourceEnd out of bounds");
|
|
1114
|
+
if (end > this.length) end = this.length;
|
|
1115
|
+
if (target.length - targetStart < end - start) end = target.length - targetStart + start;
|
|
1116
|
+
var len = end - start;
|
|
1117
|
+
var i;
|
|
1118
|
+
if (this === target && start < targetStart && targetStart < end) for (i = len - 1; i >= 0; --i) target[i + targetStart] = this[i + start];
|
|
1119
|
+
else if (len < 1e3 || !Buffer.TYPED_ARRAY_SUPPORT) for (i = 0; i < len; ++i) target[i + targetStart] = this[i + start];
|
|
1120
|
+
else Uint8Array.prototype.set.call(target, this.subarray(start, start + len), targetStart);
|
|
1121
|
+
return len;
|
|
1122
|
+
};
|
|
1123
|
+
Buffer.prototype.fill = function fill(val, start, end, encoding) {
|
|
1124
|
+
if (typeof val === "string") {
|
|
1125
|
+
if (typeof start === "string") {
|
|
1126
|
+
encoding = start;
|
|
1127
|
+
start = 0;
|
|
1128
|
+
end = this.length;
|
|
1129
|
+
} else if (typeof end === "string") {
|
|
1130
|
+
encoding = end;
|
|
1131
|
+
end = this.length;
|
|
1132
|
+
}
|
|
1133
|
+
if (val.length === 1) {
|
|
1134
|
+
var code = val.charCodeAt(0);
|
|
1135
|
+
if (code < 256) val = code;
|
|
1136
|
+
}
|
|
1137
|
+
if (encoding !== void 0 && typeof encoding !== "string") throw new TypeError("encoding must be a string");
|
|
1138
|
+
if (typeof encoding === "string" && !Buffer.isEncoding(encoding)) throw new TypeError("Unknown encoding: " + encoding);
|
|
1139
|
+
} else if (typeof val === "number") val = val & 255;
|
|
1140
|
+
if (start < 0 || this.length < start || this.length < end) throw new RangeError("Out of range index");
|
|
1141
|
+
if (end <= start) return this;
|
|
1142
|
+
start = start >>> 0;
|
|
1143
|
+
end = end === void 0 ? this.length : end >>> 0;
|
|
1144
|
+
if (!val) val = 0;
|
|
1145
|
+
var i;
|
|
1146
|
+
if (typeof val === "number") for (i = start; i < end; ++i) this[i] = val;
|
|
1147
|
+
else {
|
|
1148
|
+
var bytes = internalIsBuffer(val) ? val : utf8ToBytes(new Buffer(val, encoding).toString());
|
|
1149
|
+
var len = bytes.length;
|
|
1150
|
+
for (i = 0; i < end - start; ++i) this[i + start] = bytes[i % len];
|
|
1151
|
+
}
|
|
1152
|
+
return this;
|
|
1153
|
+
};
|
|
1154
|
+
var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g;
|
|
1155
|
+
function base64clean(str) {
|
|
1156
|
+
str = stringtrim(str).replace(INVALID_BASE64_RE, "");
|
|
1157
|
+
if (str.length < 2) return "";
|
|
1158
|
+
while (str.length % 4 !== 0) str = str + "=";
|
|
1159
|
+
return str;
|
|
1160
|
+
}
|
|
1161
|
+
function stringtrim(str) {
|
|
1162
|
+
if (str.trim) return str.trim();
|
|
1163
|
+
return str.replace(/^\s+|\s+$/g, "");
|
|
1164
|
+
}
|
|
1165
|
+
function toHex(n) {
|
|
1166
|
+
if (n < 16) return "0" + n.toString(16);
|
|
1167
|
+
return n.toString(16);
|
|
1168
|
+
}
|
|
1169
|
+
function utf8ToBytes(string, units) {
|
|
1170
|
+
units = units || Infinity;
|
|
1171
|
+
var codePoint;
|
|
1172
|
+
var length = string.length;
|
|
1173
|
+
var leadSurrogate = null;
|
|
1174
|
+
var bytes = [];
|
|
1175
|
+
for (var i = 0; i < length; ++i) {
|
|
1176
|
+
codePoint = string.charCodeAt(i);
|
|
1177
|
+
if (codePoint > 55295 && codePoint < 57344) {
|
|
1178
|
+
if (!leadSurrogate) {
|
|
1179
|
+
if (codePoint > 56319) {
|
|
1180
|
+
if ((units -= 3) > -1) bytes.push(239, 191, 189);
|
|
1181
|
+
continue;
|
|
1182
|
+
} else if (i + 1 === length) {
|
|
1183
|
+
if ((units -= 3) > -1) bytes.push(239, 191, 189);
|
|
1184
|
+
continue;
|
|
1185
|
+
}
|
|
1186
|
+
leadSurrogate = codePoint;
|
|
1187
|
+
continue;
|
|
1188
|
+
}
|
|
1189
|
+
if (codePoint < 56320) {
|
|
1190
|
+
if ((units -= 3) > -1) bytes.push(239, 191, 189);
|
|
1191
|
+
leadSurrogate = codePoint;
|
|
1192
|
+
continue;
|
|
1193
|
+
}
|
|
1194
|
+
codePoint = (leadSurrogate - 55296 << 10 | codePoint - 56320) + 65536;
|
|
1195
|
+
} else if (leadSurrogate) {
|
|
1196
|
+
if ((units -= 3) > -1) bytes.push(239, 191, 189);
|
|
1197
|
+
}
|
|
1198
|
+
leadSurrogate = null;
|
|
1199
|
+
if (codePoint < 128) {
|
|
1200
|
+
if ((units -= 1) < 0) break;
|
|
1201
|
+
bytes.push(codePoint);
|
|
1202
|
+
} else if (codePoint < 2048) {
|
|
1203
|
+
if ((units -= 2) < 0) break;
|
|
1204
|
+
bytes.push(codePoint >> 6 | 192, codePoint & 63 | 128);
|
|
1205
|
+
} else if (codePoint < 65536) {
|
|
1206
|
+
if ((units -= 3) < 0) break;
|
|
1207
|
+
bytes.push(codePoint >> 12 | 224, codePoint >> 6 & 63 | 128, codePoint & 63 | 128);
|
|
1208
|
+
} else if (codePoint < 1114112) {
|
|
1209
|
+
if ((units -= 4) < 0) break;
|
|
1210
|
+
bytes.push(codePoint >> 18 | 240, codePoint >> 12 & 63 | 128, codePoint >> 6 & 63 | 128, codePoint & 63 | 128);
|
|
1211
|
+
} else throw new Error("Invalid code point");
|
|
1212
|
+
}
|
|
1213
|
+
return bytes;
|
|
1214
|
+
}
|
|
1215
|
+
function asciiToBytes(str) {
|
|
1216
|
+
var byteArray = [];
|
|
1217
|
+
for (var i = 0; i < str.length; ++i) byteArray.push(str.charCodeAt(i) & 255);
|
|
1218
|
+
return byteArray;
|
|
1219
|
+
}
|
|
1220
|
+
function utf16leToBytes(str, units) {
|
|
1221
|
+
var c, hi, lo;
|
|
1222
|
+
var byteArray = [];
|
|
1223
|
+
for (var i = 0; i < str.length; ++i) {
|
|
1224
|
+
if ((units -= 2) < 0) break;
|
|
1225
|
+
c = str.charCodeAt(i);
|
|
1226
|
+
hi = c >> 8;
|
|
1227
|
+
lo = c % 256;
|
|
1228
|
+
byteArray.push(lo);
|
|
1229
|
+
byteArray.push(hi);
|
|
1230
|
+
}
|
|
1231
|
+
return byteArray;
|
|
1232
|
+
}
|
|
1233
|
+
function base64ToBytes(str) {
|
|
1234
|
+
return toByteArray(base64clean(str));
|
|
1235
|
+
}
|
|
1236
|
+
function blitBuffer(src, dst, offset, length) {
|
|
1237
|
+
for (var i = 0; i < length; ++i) {
|
|
1238
|
+
if (i + offset >= dst.length || i >= src.length) break;
|
|
1239
|
+
dst[i + offset] = src[i];
|
|
1240
|
+
}
|
|
1241
|
+
return i;
|
|
1242
|
+
}
|
|
1243
|
+
function isnan(val) {
|
|
1244
|
+
return val !== val;
|
|
1245
|
+
}
|
|
1246
|
+
function isBuffer(obj) {
|
|
1247
|
+
return obj != null && (!!obj._isBuffer || isFastBuffer(obj) || isSlowBuffer(obj));
|
|
1248
|
+
}
|
|
1249
|
+
function isFastBuffer(obj) {
|
|
1250
|
+
return !!obj.constructor && typeof obj.constructor.isBuffer === "function" && obj.constructor.isBuffer(obj);
|
|
1251
|
+
}
|
|
1252
|
+
function isSlowBuffer(obj) {
|
|
1253
|
+
return typeof obj.readFloatLE === "function" && typeof obj.slice === "function" && isFastBuffer(obj.slice(0, 0));
|
|
1254
|
+
}
|
|
1255
|
+
//#endregion
|
|
1256
|
+
//#region src/parts/alt-chunk/alt-chunk-parse.ts
|
|
1257
|
+
/**
|
|
1258
|
+
* AltChunk parser for DOCX documents.
|
|
1259
|
+
*
|
|
1260
|
+
* Parses w:altChunk elements and extracts embedded content from the ZIP.
|
|
1261
|
+
*
|
|
1262
|
+
* @module
|
|
1263
|
+
*/
|
|
1264
|
+
/**
|
|
1265
|
+
* Parse a w:altChunk element into AltChunkOptions.
|
|
1266
|
+
* Reads the referenced data from the ZIP package.
|
|
1267
|
+
*/
|
|
1268
|
+
function parseAltChunk(el, ctx) {
|
|
1269
|
+
const rId = attr(el, "r:id");
|
|
1270
|
+
if (!rId) throw new Error("w:altChunk missing r:id attribute");
|
|
1271
|
+
const path = ctx.docx.partRefs.afChunks.get(rId);
|
|
1272
|
+
if (!path) throw new Error(`AltChunk relationship ${rId} not found`);
|
|
1273
|
+
const data = ctx.docx.doc.getRaw(path);
|
|
1274
|
+
if (!data) throw new Error(`AltChunk data not found at ${path}`);
|
|
1275
|
+
const ext = path.split(".").pop() ?? "txt";
|
|
1276
|
+
let contentType;
|
|
1277
|
+
let extension;
|
|
1278
|
+
switch (ext) {
|
|
1279
|
+
case "html":
|
|
1280
|
+
contentType = "text/html";
|
|
1281
|
+
extension = "html";
|
|
1282
|
+
break;
|
|
1283
|
+
case "rtf":
|
|
1284
|
+
contentType = "application/rtf";
|
|
1285
|
+
extension = "rtf";
|
|
1286
|
+
break;
|
|
1287
|
+
default:
|
|
1288
|
+
contentType = "text/plain";
|
|
1289
|
+
extension = "txt";
|
|
1290
|
+
break;
|
|
1291
|
+
}
|
|
1292
|
+
return {
|
|
1293
|
+
data,
|
|
1294
|
+
contentType,
|
|
1295
|
+
extension
|
|
1296
|
+
};
|
|
1297
|
+
}
|
|
1298
|
+
//#endregion
|
|
1299
|
+
//#region src/parts/custom-xml/custom-xml-parse.ts
|
|
1300
|
+
/**
|
|
1301
|
+
* Parser for custom XML block elements (w:customXml).
|
|
1302
|
+
*
|
|
1303
|
+
* @module
|
|
1304
|
+
*/
|
|
1305
|
+
/**
|
|
1306
|
+
* Parse w:customXml element into CustomXmlBlockOptions.
|
|
1307
|
+
*
|
|
1308
|
+
* Uses a callback for child parsing to avoid circular dependencies
|
|
1309
|
+
* (same pattern as parseTable).
|
|
1310
|
+
*/
|
|
1311
|
+
function parseCustomXmlBlock(el, ctx, parseChild) {
|
|
1312
|
+
const opts = {};
|
|
1313
|
+
const element = attr(el, "w:element");
|
|
1314
|
+
if (element) opts.element = element;
|
|
1315
|
+
const uri = attr(el, "w:uri");
|
|
1316
|
+
if (uri) opts.uri = uri;
|
|
1317
|
+
const xmlPr = findChild(el, "w:customXmlPr");
|
|
1318
|
+
if (xmlPr) opts.customXmlPr = parseCustomXmlPr(xmlPr);
|
|
1319
|
+
const children = [];
|
|
1320
|
+
for (const child of el.elements ?? []) {
|
|
1321
|
+
if (child.name === "w:customXmlPr") continue;
|
|
1322
|
+
const parsed = parseChild(child, ctx);
|
|
1323
|
+
children.push(parsed);
|
|
1324
|
+
}
|
|
1325
|
+
if (children.length > 0) opts.children = children;
|
|
1326
|
+
return opts;
|
|
1327
|
+
}
|
|
1328
|
+
//#endregion
|
|
1329
|
+
//#region src/parts/sub-doc/sub-doc-parse.ts
|
|
1330
|
+
/**
|
|
1331
|
+
* SubDoc parser for DOCX documents.
|
|
1332
|
+
*
|
|
1333
|
+
* Parses w:subDoc elements and extracts embedded document data.
|
|
1334
|
+
*
|
|
1335
|
+
* @module
|
|
1336
|
+
*/
|
|
1337
|
+
/**
|
|
1338
|
+
* Parse a w:subDoc element into SubDocOptions.
|
|
1339
|
+
* Reads the referenced document data from the ZIP package.
|
|
1340
|
+
*/
|
|
1341
|
+
function parseSubDoc(el, ctx) {
|
|
1342
|
+
const rId = attr(el, "r:id");
|
|
1343
|
+
if (!rId) throw new Error("w:subDoc missing r:id attribute");
|
|
1344
|
+
const path = ctx.docx.partRefs.subDocs.get(rId);
|
|
1345
|
+
if (!path) throw new Error(`SubDoc relationship ${rId} not found`);
|
|
1346
|
+
const data = ctx.docx.doc.getRaw(path);
|
|
1347
|
+
if (!data) throw new Error(`SubDoc data not found at ${path}`);
|
|
1348
|
+
return { data };
|
|
1349
|
+
}
|
|
1350
|
+
//#endregion
|
|
1351
|
+
//#region src/parts/textbox/textbox-parse.ts
|
|
1352
|
+
/**
|
|
1353
|
+
* Textbox parser for DOCX documents.
|
|
1354
|
+
*
|
|
1355
|
+
* Parses w:pict → v:shape → v:textbox → w:txbxContent elements.
|
|
1356
|
+
*
|
|
1357
|
+
* @module
|
|
1358
|
+
*/
|
|
1359
|
+
/**
|
|
1360
|
+
* Parse VML shape style string into VmlShapeStyle-like object.
|
|
1361
|
+
*/
|
|
1362
|
+
function parseVmlStyle(styleStr) {
|
|
1363
|
+
const style = {};
|
|
1364
|
+
for (const part of styleStr.split(";")) {
|
|
1365
|
+
const [key, val] = part.split(":").map((s) => s.trim());
|
|
1366
|
+
if (key && val) style[key] = val;
|
|
1367
|
+
}
|
|
1368
|
+
return style;
|
|
1369
|
+
}
|
|
1370
|
+
/**
|
|
1371
|
+
* Parse a w:pict element that contains a textbox.
|
|
1372
|
+
* Returns an object suitable for the { textbox: ... } SectionChild variant.
|
|
1373
|
+
*/
|
|
1374
|
+
function parseTextbox(el, ctx, parseChildren) {
|
|
1375
|
+
const shape = findDeep$1(el, "v:shape")[0];
|
|
1376
|
+
if (!shape) return {};
|
|
1377
|
+
const opts = {};
|
|
1378
|
+
const styleAttr = attr(shape, "style");
|
|
1379
|
+
if (styleAttr) opts.style = parseVmlStyle(styleAttr);
|
|
1380
|
+
const textbox = findDeep$1(shape, "v:textbox")[0];
|
|
1381
|
+
if (textbox) {
|
|
1382
|
+
const txbxContent = findChild(textbox, "w:txbxContent");
|
|
1383
|
+
if (txbxContent) {
|
|
1384
|
+
const childList = parseChildren(txbxContent.elements ?? [], ctx);
|
|
1385
|
+
if (childList.length > 0) opts.children = childList;
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
return opts;
|
|
1389
|
+
}
|
|
1390
|
+
function findDeep$1(parent, name) {
|
|
1391
|
+
const result = [];
|
|
1392
|
+
for (const child of parent.elements ?? []) {
|
|
1393
|
+
if (child.name === name) result.push(child);
|
|
1394
|
+
result.push(...findDeep$1(child, name));
|
|
1395
|
+
}
|
|
1396
|
+
return result;
|
|
1397
|
+
}
|
|
1398
|
+
//#endregion
|
|
1399
|
+
//#region src/parse/body.ts
|
|
1400
|
+
/**
|
|
1401
|
+
* Body parser for DOCX documents.
|
|
1402
|
+
*
|
|
1403
|
+
* Parses w:body → SectionOptions[] by splitting at w:sectPr boundaries.
|
|
1404
|
+
*
|
|
1405
|
+
* @module
|
|
1406
|
+
*/
|
|
1407
|
+
/**
|
|
1408
|
+
* Parse w:sectPr element into SectionPropertiesOptions.
|
|
1409
|
+
* Delegates to the section properties descriptor's parse method.
|
|
1410
|
+
*/
|
|
1411
|
+
function parseSectionProperties(el, ctx) {
|
|
1412
|
+
const opts = parseSectionPropertiesEl(el);
|
|
1413
|
+
const headerRefs = {};
|
|
1414
|
+
const footerRefs = {};
|
|
1415
|
+
for (const child of el.elements ?? []) {
|
|
1416
|
+
if (child.name === "w:headerReference") {
|
|
1417
|
+
const rId = attr(child, "r:id");
|
|
1418
|
+
const type = attr(child, "w:type");
|
|
1419
|
+
if (rId && type) {
|
|
1420
|
+
const headerChildren = parseHeaderFooterRef(rId, ctx);
|
|
1421
|
+
if (headerChildren) headerRefs[type] = headerChildren;
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
if (child.name === "w:footerReference") {
|
|
1425
|
+
const rId = attr(child, "r:id");
|
|
1426
|
+
const type = attr(child, "w:type");
|
|
1427
|
+
if (rId && type) {
|
|
1428
|
+
const footerChildren = parseHeaderFooterRef(rId, ctx);
|
|
1429
|
+
if (footerChildren) footerRefs[type] = footerChildren;
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
if (Object.keys(headerRefs).length > 0) opts.parsedHeaders = headerRefs;
|
|
1434
|
+
if (Object.keys(footerRefs).length > 0) opts.parsedFooters = footerRefs;
|
|
1435
|
+
return opts;
|
|
1436
|
+
}
|
|
1437
|
+
/**
|
|
1438
|
+
* Parse a header/footer reference by following the relationship to its XML part.
|
|
1439
|
+
*/
|
|
1440
|
+
function parseHeaderFooterRef(rId, ctx) {
|
|
1441
|
+
const path = ctx.docx.partRefs.headers.get(rId) ?? ctx.docx.partRefs.footers.get(rId);
|
|
1442
|
+
if (!path) return void 0;
|
|
1443
|
+
const partEl = ctx.docx.doc.get(path);
|
|
1444
|
+
if (!partEl) return void 0;
|
|
1445
|
+
const children = [];
|
|
1446
|
+
ctx.withPart(path, () => {
|
|
1447
|
+
for (const child of partEl.elements ?? []) {
|
|
1448
|
+
const sectionChild = parseSectionChild(child, ctx);
|
|
1449
|
+
if (sectionChild !== void 0) children.push(sectionChild);
|
|
1450
|
+
}
|
|
1451
|
+
});
|
|
1452
|
+
return children.length > 0 ? children : void 0;
|
|
1453
|
+
}
|
|
1454
|
+
/**
|
|
1455
|
+
* Parse a single body child element into a SectionChild.
|
|
1456
|
+
*/
|
|
1457
|
+
function parseSectionChild(el, ctx) {
|
|
1458
|
+
switch (el.name) {
|
|
1459
|
+
case "w:p": {
|
|
1460
|
+
const pict = findChild(el, "w:pict");
|
|
1461
|
+
if (pict) {
|
|
1462
|
+
if (findDeepElement(pict, "v:textbox")) return { textbox: parseTextbox(pict, ctx, parseSectionChildrenElements) };
|
|
1463
|
+
}
|
|
1464
|
+
return { paragraph: parseParagraph(el, ctx) };
|
|
1465
|
+
}
|
|
1466
|
+
case "w:tbl": return { table: tableDesc.parse(el, ctx) };
|
|
1467
|
+
case "w:sdt": {
|
|
1468
|
+
const tocResult = parseToc(el, ctx);
|
|
1469
|
+
if (tocResult) return { toc: tocResult };
|
|
1470
|
+
const sdtResult = parseSdtBlock(el, ctx, parseSectionChildrenElements);
|
|
1471
|
+
return { sdt: {
|
|
1472
|
+
properties: sdtResult.properties,
|
|
1473
|
+
children: sdtResult.children
|
|
1474
|
+
} };
|
|
1475
|
+
}
|
|
1476
|
+
case "w:altChunk": return { altChunk: parseAltChunk(el, ctx) };
|
|
1477
|
+
case "w:subDoc": return { subDoc: parseSubDoc(el, ctx) };
|
|
1478
|
+
case "w:customXml": return { customXml: parseCustomXmlBlock(el, ctx, parseSectionChild) };
|
|
1479
|
+
case "w:bookmarkStart": {
|
|
1480
|
+
const idRaw = attr(el, "w:id");
|
|
1481
|
+
const name = attr(el, "w:name");
|
|
1482
|
+
if (idRaw !== void 0 && name) return { bookmarkStart: {
|
|
1483
|
+
id: Number(idRaw),
|
|
1484
|
+
name
|
|
1485
|
+
} };
|
|
1486
|
+
return { rawXml: stringifyElement(el) };
|
|
1487
|
+
}
|
|
1488
|
+
case "w:bookmarkEnd": {
|
|
1489
|
+
const idRaw = attr(el, "w:id");
|
|
1490
|
+
if (idRaw !== void 0) return { bookmarkEnd: Number(idRaw) };
|
|
1491
|
+
return { rawXml: stringifyElement(el) };
|
|
1492
|
+
}
|
|
1493
|
+
default: return { rawXml: stringifyElement(el) };
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
/**
|
|
1497
|
+
* Find a deep descendant element by name.
|
|
1498
|
+
*/
|
|
1499
|
+
function findDeepElement(parent, name) {
|
|
1500
|
+
for (const child of parent.elements ?? []) {
|
|
1501
|
+
if (child.name === name) return child;
|
|
1502
|
+
const found = findDeepElement(child, name);
|
|
1503
|
+
if (found) return found;
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
/**
|
|
1507
|
+
* Parse w:body element into SectionOptions[].
|
|
1508
|
+
*
|
|
1509
|
+
* Splits body content at w:sectPr boundaries to create sections.
|
|
1510
|
+
* The last w:sectPr (child of w:body directly) defines the last section.
|
|
1511
|
+
* Previous w:sectPr elements appear inside w:pPr elements.
|
|
1512
|
+
*/
|
|
1513
|
+
function parseBody(body, ctx) {
|
|
1514
|
+
setBodyParseChild(parseSectionChild);
|
|
1515
|
+
const bodyChildren = [];
|
|
1516
|
+
const boundaries = [];
|
|
1517
|
+
for (const child of body.elements ?? []) if (child.name === "w:sectPr") boundaries.push({
|
|
1518
|
+
index: bodyChildren.length,
|
|
1519
|
+
sectPr: child
|
|
1520
|
+
});
|
|
1521
|
+
else {
|
|
1522
|
+
bodyChildren.push(child);
|
|
1523
|
+
if (child.name === "w:p") {
|
|
1524
|
+
const pPr = findChild(child, "w:pPr");
|
|
1525
|
+
if (pPr) {
|
|
1526
|
+
const sectPr = findChild(pPr, "w:sectPr");
|
|
1527
|
+
if (sectPr) boundaries.push({
|
|
1528
|
+
index: bodyChildren.length,
|
|
1529
|
+
sectPr
|
|
1530
|
+
});
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
if (boundaries.length === 0) return [{ children: parseBodyChildren(bodyChildren, ctx) }];
|
|
1535
|
+
const sections = [];
|
|
1536
|
+
let start = 0;
|
|
1537
|
+
for (let i = 0; i < boundaries.length; i++) {
|
|
1538
|
+
const boundary = boundaries[i];
|
|
1539
|
+
const endIdx = i < boundaries.length - 1 ? Math.max(start, boundary.index - 1) : boundary.index;
|
|
1540
|
+
const sectionElements = bodyChildren.slice(start, endIdx);
|
|
1541
|
+
const parsedProps = parseSectionProperties(boundary.sectPr, ctx);
|
|
1542
|
+
const rawProps = parsedProps;
|
|
1543
|
+
const parsedHeaders = rawProps.parsedHeaders;
|
|
1544
|
+
const parsedFooters = rawProps.parsedFooters;
|
|
1545
|
+
const cleanProps = { ...parsedProps };
|
|
1546
|
+
delete cleanProps.parsedHeaders;
|
|
1547
|
+
delete cleanProps.parsedFooters;
|
|
1548
|
+
const section = {
|
|
1549
|
+
children: parseBodyChildren(sectionElements, ctx),
|
|
1550
|
+
properties: cleanProps,
|
|
1551
|
+
...parsedHeaders ? { headers: parsedHeaders } : {},
|
|
1552
|
+
...parsedFooters ? { footers: parsedFooters } : {}
|
|
1553
|
+
};
|
|
1554
|
+
sections.push(section);
|
|
1555
|
+
start = boundary.index;
|
|
1556
|
+
}
|
|
1557
|
+
return sections;
|
|
1558
|
+
}
|
|
1559
|
+
/**
|
|
1560
|
+
* Net field-nesting change across all descendant fldChar markers
|
|
1561
|
+
* (begin: +1, end: -1). Balances cross-paragraph field boundaries without a
|
|
1562
|
+
* stack — the running depth hits 0 exactly when the outermost field closes.
|
|
1563
|
+
*/
|
|
1564
|
+
function countFieldDelta(el) {
|
|
1565
|
+
let delta = 0;
|
|
1566
|
+
const walk = (node) => {
|
|
1567
|
+
if (node.name === "w:fldChar") {
|
|
1568
|
+
const type = attr(node, "w:fldCharType");
|
|
1569
|
+
if (type === "begin") delta += 1;
|
|
1570
|
+
else if (type === "end") delta -= 1;
|
|
1571
|
+
}
|
|
1572
|
+
for (const c of node.elements ?? []) if (c.type === "element") walk(c);
|
|
1573
|
+
};
|
|
1574
|
+
walk(el);
|
|
1575
|
+
return delta;
|
|
1576
|
+
}
|
|
1577
|
+
/**
|
|
1578
|
+
* True when a w:p opens a bare TOC complex field: it carries a fldChar begin
|
|
1579
|
+
* whose instrText starts with "TOC". Such fields span multiple paragraphs and
|
|
1580
|
+
* defeat the per-paragraph field accumulator, so they are aggregated as rawXml.
|
|
1581
|
+
*/
|
|
1582
|
+
function isTocFieldBegin(el) {
|
|
1583
|
+
if (el.name !== "w:p") return false;
|
|
1584
|
+
let hasBegin = false;
|
|
1585
|
+
let instr = "";
|
|
1586
|
+
const walk = (node) => {
|
|
1587
|
+
if (node.name === "w:fldChar" && attr(node, "w:fldCharType") === "begin") hasBegin = true;
|
|
1588
|
+
if (node.name === "w:instrText") instr += textOf(node);
|
|
1589
|
+
for (const c of node.elements ?? []) if (c.type === "element") walk(c);
|
|
1590
|
+
};
|
|
1591
|
+
walk(el);
|
|
1592
|
+
return hasBegin && instr.trim().toUpperCase().startsWith("TOC");
|
|
1593
|
+
}
|
|
1594
|
+
/**
|
|
1595
|
+
* Parse a run of body-level elements into SectionChild[], aggregating any
|
|
1596
|
+
* cross-paragraph TOC complex field into a single rawXml child so its nested
|
|
1597
|
+
* HYPERLINK/PAGEREF fields and bookmark markers round-trip intact.
|
|
1598
|
+
*/
|
|
1599
|
+
function parseBodyChildren(elements, ctx) {
|
|
1600
|
+
const children = [];
|
|
1601
|
+
let tocBuffer = null;
|
|
1602
|
+
let tocDepth = 0;
|
|
1603
|
+
for (const el of elements) {
|
|
1604
|
+
if (tocBuffer !== null) {
|
|
1605
|
+
tocBuffer.push(stringifyElement(el));
|
|
1606
|
+
tocDepth += countFieldDelta(el);
|
|
1607
|
+
if (tocDepth <= 0) {
|
|
1608
|
+
children.push({ rawXml: tocBuffer.join("") });
|
|
1609
|
+
tocBuffer = null;
|
|
1610
|
+
tocDepth = 0;
|
|
1611
|
+
}
|
|
1612
|
+
continue;
|
|
1613
|
+
}
|
|
1614
|
+
if (isTocFieldBegin(el)) {
|
|
1615
|
+
tocBuffer = [stringifyElement(el)];
|
|
1616
|
+
tocDepth = countFieldDelta(el);
|
|
1617
|
+
if (tocDepth <= 0) {
|
|
1618
|
+
children.push({ rawXml: tocBuffer.join("") });
|
|
1619
|
+
tocBuffer = null;
|
|
1620
|
+
tocDepth = 0;
|
|
1621
|
+
}
|
|
1622
|
+
continue;
|
|
1623
|
+
}
|
|
1624
|
+
children.push(parseSectionChild(el, ctx));
|
|
1625
|
+
}
|
|
1626
|
+
if (tocBuffer !== null) children.push({ rawXml: tocBuffer.join("") });
|
|
1627
|
+
return children;
|
|
1628
|
+
}
|
|
1629
|
+
/**
|
|
1630
|
+
* Parse a list of elements into SectionChild[].
|
|
1631
|
+
* Used by SDT and textbox parsers for their content.
|
|
1632
|
+
*/
|
|
1633
|
+
function parseSectionChildrenElements(elements, ctx) {
|
|
1634
|
+
return parseBodyChildren(elements, ctx);
|
|
1635
|
+
}
|
|
1636
|
+
//#endregion
|
|
1637
|
+
//#region src/parse.ts
|
|
1638
|
+
function resolveRelsPath(target) {
|
|
1639
|
+
if (target.startsWith("/")) return target.slice(1);
|
|
1640
|
+
if (target.startsWith("../")) return target.replace("../", "");
|
|
1641
|
+
return `word/${target}`;
|
|
1642
|
+
}
|
|
1643
|
+
/**
|
|
1644
|
+
* Resolve each embedded font's .odttf bytes through fontTable.xml.rels.
|
|
1645
|
+
* Reads the binary verbatim and flags it raw so the compiler copies it as-is
|
|
1646
|
+
* instead of re-obfuscating (the fontKey already matches the bytes).
|
|
1647
|
+
*/
|
|
1648
|
+
function resolveEmbeddedFontData(fonts, doc) {
|
|
1649
|
+
const relsEl = doc.get("word/_rels/fontTable.xml.rels");
|
|
1650
|
+
if (!relsEl) return;
|
|
1651
|
+
const ridToPath = /* @__PURE__ */ new Map();
|
|
1652
|
+
for (const child of relsEl.elements ?? []) {
|
|
1653
|
+
if (child.name !== "Relationship") continue;
|
|
1654
|
+
if (!(attr(child, "Type") ?? "").includes("/font")) continue;
|
|
1655
|
+
const id = attr(child, "Id") ?? "";
|
|
1656
|
+
const target = attr(child, "Target") ?? "";
|
|
1657
|
+
if (id && target) ridToPath.set(id, resolveRelsPath(target));
|
|
1658
|
+
}
|
|
1659
|
+
for (const font of fonts) {
|
|
1660
|
+
if (!font.embedRid) continue;
|
|
1661
|
+
const odttfPath = ridToPath.get(font.embedRid);
|
|
1662
|
+
if (!odttfPath) continue;
|
|
1663
|
+
const bytes = doc.getRaw(odttfPath);
|
|
1664
|
+
if (bytes) {
|
|
1665
|
+
font.data = Buffer.from(bytes);
|
|
1666
|
+
font.rawOdttf = true;
|
|
1667
|
+
font.odttfPath = odttfPath;
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
function parseDocPartRefs(doc) {
|
|
1672
|
+
const refs = {
|
|
1673
|
+
headers: /* @__PURE__ */ new Map(),
|
|
1674
|
+
footers: /* @__PURE__ */ new Map(),
|
|
1675
|
+
hyperlinks: /* @__PURE__ */ new Map(),
|
|
1676
|
+
charts: /* @__PURE__ */ new Map(),
|
|
1677
|
+
diagramData: /* @__PURE__ */ new Map(),
|
|
1678
|
+
media: /* @__PURE__ */ new Map(),
|
|
1679
|
+
partMedia: /* @__PURE__ */ new Map(),
|
|
1680
|
+
afChunks: /* @__PURE__ */ new Map(),
|
|
1681
|
+
subDocs: /* @__PURE__ */ new Map()
|
|
1682
|
+
};
|
|
1683
|
+
const relsEl = doc.get("word/_rels/document.xml.rels");
|
|
1684
|
+
if (!relsEl) return refs;
|
|
1685
|
+
for (const child of relsEl.elements ?? []) {
|
|
1686
|
+
if (child.name !== "Relationship") continue;
|
|
1687
|
+
const type = attr(child, "Type") ?? "";
|
|
1688
|
+
const target = attr(child, "Target") ?? "";
|
|
1689
|
+
const id = attr(child, "Id") ?? "";
|
|
1690
|
+
if (!target) continue;
|
|
1691
|
+
const path = resolveRelsPath(target);
|
|
1692
|
+
if (type.includes("/header")) refs.headers.set(id, path);
|
|
1693
|
+
else if (type.includes("/footer")) refs.footers.set(id, path);
|
|
1694
|
+
else if (type.includes("/footnotes")) refs.footnotes = path;
|
|
1695
|
+
else if (type.includes("/endnotes")) refs.endnotes = path;
|
|
1696
|
+
else if (type.includes("/comments")) refs.comments = path;
|
|
1697
|
+
else if (type.includes("/chart")) refs.charts.set(id, path);
|
|
1698
|
+
else if (type.includes("/diagramData")) refs.diagramData.set(id, path);
|
|
1699
|
+
else if (type.includes("/image") || type.includes("/media")) refs.media.set(id, path);
|
|
1700
|
+
else if (type.includes("/aFChunk")) refs.afChunks.set(id, path);
|
|
1701
|
+
else if (type.includes("/subDocument")) refs.subDocs.set(id, path);
|
|
1702
|
+
else if (type.includes("/bibliography")) refs.bibliography = path;
|
|
1703
|
+
else if (type.includes("/glossaryDocument")) refs.glossary = path;
|
|
1704
|
+
else if (type.includes("/hyperlink")) refs.hyperlinks.set(id, target);
|
|
1705
|
+
}
|
|
1706
|
+
for (const relsPath of doc.keys("word/_rels/")) {
|
|
1707
|
+
if (!relsPath.endsWith(".rels")) continue;
|
|
1708
|
+
const relsEl = doc.get(relsPath);
|
|
1709
|
+
if (!relsEl) continue;
|
|
1710
|
+
const partPath = "word/" + relsPath.slice(11, -5);
|
|
1711
|
+
for (const rel of relsEl.elements ?? []) {
|
|
1712
|
+
if (rel.name !== "Relationship") continue;
|
|
1713
|
+
const type = attr(rel, "Type") ?? "";
|
|
1714
|
+
if (!type.includes("/image") && !type.includes("/media")) continue;
|
|
1715
|
+
const id = attr(rel, "Id") ?? "";
|
|
1716
|
+
const target = attr(rel, "Target") ?? "";
|
|
1717
|
+
if (!id || !target) continue;
|
|
1718
|
+
let partMap = refs.partMedia.get(partPath);
|
|
1719
|
+
if (!partMap) {
|
|
1720
|
+
partMap = /* @__PURE__ */ new Map();
|
|
1721
|
+
refs.partMedia.set(partPath, partMap);
|
|
1722
|
+
}
|
|
1723
|
+
partMap.set(id, resolveRelsPath(target));
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
return refs;
|
|
1727
|
+
}
|
|
1728
|
+
function parseRootRels(doc) {
|
|
1729
|
+
const relsEl = doc.get("_rels/.rels");
|
|
1730
|
+
if (!relsEl) return {};
|
|
1731
|
+
let coreProps;
|
|
1732
|
+
let appProps;
|
|
1733
|
+
let customProps;
|
|
1734
|
+
for (const child of relsEl.elements ?? []) {
|
|
1735
|
+
if (child.name !== "Relationship") continue;
|
|
1736
|
+
const type = attr(child, "Type") ?? "";
|
|
1737
|
+
const target = attr(child, "Target") ?? "";
|
|
1738
|
+
if (!target) continue;
|
|
1739
|
+
const path = target.startsWith("/") ? target.slice(1) : target;
|
|
1740
|
+
if (type.includes("/core-properties")) coreProps = path;
|
|
1741
|
+
else if (type.includes("/extended-properties")) appProps = path;
|
|
1742
|
+
else if (type.includes("/custom-properties")) customProps = path;
|
|
1743
|
+
}
|
|
1744
|
+
return {
|
|
1745
|
+
coreProps,
|
|
1746
|
+
appProps,
|
|
1747
|
+
customProps
|
|
1748
|
+
};
|
|
1749
|
+
}
|
|
1750
|
+
/**
|
|
1751
|
+
* Parse a .docx file and convert it into DocumentOptions.
|
|
1752
|
+
*
|
|
1753
|
+
* This is the main public API for parsing DOCX files.
|
|
1754
|
+
* The returned options can be passed directly to `new Document(parsed)`
|
|
1755
|
+
* to recreate the document.
|
|
1756
|
+
*
|
|
1757
|
+
* @param data - Raw bytes of a .docx file
|
|
1758
|
+
* @returns Document options including sections and metadata
|
|
1759
|
+
*/
|
|
1760
|
+
function parseDocument(data) {
|
|
1761
|
+
const docx = parseDocx(data);
|
|
1762
|
+
const ctx = new DocxReadContext(docx, buildStyleCache(docx.styles), buildNumberingCache(docx.numbering));
|
|
1763
|
+
setTableParseChild(parseSectionChild);
|
|
1764
|
+
setBodyParseChild(parseSectionChild);
|
|
1765
|
+
const opts = { sections: parseBody(docx.body, ctx) };
|
|
1766
|
+
if (docx.background) if ((docx.background.elements ?? []).some((e) => e.type === "element")) {
|
|
1767
|
+
const { rawXml, rawMedia } = replaceRelsWithPlaceholders(stringifyElement(docx.background), ctx, "background");
|
|
1768
|
+
opts.background = rawMedia.length > 0 ? {
|
|
1769
|
+
rawXml,
|
|
1770
|
+
rawMedia
|
|
1771
|
+
} : { rawXml };
|
|
1772
|
+
} else {
|
|
1773
|
+
const bg = {};
|
|
1774
|
+
const color = attr(docx.background, "w:color");
|
|
1775
|
+
if (color) bg.color = color;
|
|
1776
|
+
const themeColor = attr(docx.background, "w:themeColor");
|
|
1777
|
+
if (themeColor) bg.themeColor = themeColor;
|
|
1778
|
+
const themeShade = attr(docx.background, "w:themeShade");
|
|
1779
|
+
if (themeShade) bg.themeShade = themeShade;
|
|
1780
|
+
const themeTint = attr(docx.background, "w:themeTint");
|
|
1781
|
+
if (themeTint) bg.themeTint = themeTint;
|
|
1782
|
+
if (Object.keys(bg).length > 0) opts.background = bg;
|
|
1783
|
+
}
|
|
1784
|
+
if (docx.coreProps) {
|
|
1785
|
+
const corePropsEl = docx.doc.get(docx.coreProps);
|
|
1786
|
+
if (corePropsEl) {
|
|
1787
|
+
const cp = corePropertiesDesc.parse(corePropsEl, ctx);
|
|
1788
|
+
if (cp.title) opts.title = cp.title;
|
|
1789
|
+
if (cp.subject) opts.subject = cp.subject;
|
|
1790
|
+
if (cp.creator) opts.creator = cp.creator;
|
|
1791
|
+
if (cp.keywords) opts.keywords = cp.keywords;
|
|
1792
|
+
if (cp.description) opts.description = cp.description;
|
|
1793
|
+
if (cp.lastModifiedBy) opts.lastModifiedBy = cp.lastModifiedBy;
|
|
1794
|
+
if (cp.revision) opts.revision = cp.revision;
|
|
1795
|
+
if (cp.lastPrinted) opts.lastPrinted = cp.lastPrinted;
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1798
|
+
if (docx.appProps) {
|
|
1799
|
+
const appPropsEl = docx.doc.get(docx.appProps);
|
|
1800
|
+
if (appPropsEl) {
|
|
1801
|
+
const ap = appPropertiesDesc.parse(appPropsEl, ctx);
|
|
1802
|
+
if (Object.keys(ap).length > 0) opts.appProperties = ap;
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
if (docx.settings) {
|
|
1806
|
+
const settingsOpts = settingsDesc.parse(docx.settings, ctx);
|
|
1807
|
+
Object.assign(opts, settingsOpts);
|
|
1808
|
+
if (settingsOpts.rawXml !== void 0) opts.settings = {
|
|
1809
|
+
rawXml: settingsOpts.rawXml,
|
|
1810
|
+
rootAttributes: settingsOpts.rootAttributes
|
|
1811
|
+
};
|
|
1812
|
+
}
|
|
1813
|
+
if (docx.webSettings) {
|
|
1814
|
+
const wsOpts = webSettingsDesc.parse(docx.webSettings, ctx);
|
|
1815
|
+
if (Object.keys(wsOpts).length > 0) opts.webSettings = wsOpts;
|
|
1816
|
+
}
|
|
1817
|
+
if (docx.customProps) {
|
|
1818
|
+
const customPropsEl = docx.doc.get(docx.customProps);
|
|
1819
|
+
if (customPropsEl) {
|
|
1820
|
+
const cpResult = customPropertiesDesc.parse(customPropsEl, ctx);
|
|
1821
|
+
if (cpResult.properties && cpResult.properties.length > 0) opts.customProperties = cpResult.properties;
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
if (docx.partRefs.comments) {
|
|
1825
|
+
const commentsEl = docx.doc.get(docx.partRefs.comments);
|
|
1826
|
+
if (commentsEl) {
|
|
1827
|
+
const children = ctx.withPart(docx.partRefs.comments, () => commentsDesc.parse(commentsEl, ctx)).children;
|
|
1828
|
+
if (children && children.length > 0) opts.comments = { children };
|
|
1829
|
+
}
|
|
1830
|
+
}
|
|
1831
|
+
if (docx.partRefs.footnotes) {
|
|
1832
|
+
const footnotesEl = docx.doc.get(docx.partRefs.footnotes);
|
|
1833
|
+
if (footnotesEl) {
|
|
1834
|
+
const fnResult = ctx.withPart(docx.partRefs.footnotes, () => footnotesDesc.parse(footnotesEl, ctx));
|
|
1835
|
+
const footnotesMap = {};
|
|
1836
|
+
for (const [id, paragraphs] of fnResult.notes) footnotesMap[String(id)] = { children: paragraphs };
|
|
1837
|
+
if (Object.keys(footnotesMap).length > 0) opts.footnotes = footnotesMap;
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
if (docx.partRefs.endnotes) {
|
|
1841
|
+
const endnotesEl = docx.doc.get(docx.partRefs.endnotes);
|
|
1842
|
+
if (endnotesEl) {
|
|
1843
|
+
const enResult = ctx.withPart(docx.partRefs.endnotes, () => endnotesDesc.parse(endnotesEl, ctx));
|
|
1844
|
+
const endnotesMap = {};
|
|
1845
|
+
for (const [id, paragraphs] of enResult.notes) endnotesMap[String(id)] = { children: paragraphs };
|
|
1846
|
+
if (Object.keys(endnotesMap).length > 0) opts.endnotes = endnotesMap;
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
if (docx.styles) {
|
|
1850
|
+
const styleOpts = parseStyleDefinitions(docx.styles, parseParagraphProperties, ctx);
|
|
1851
|
+
if (styleOpts) opts.styles = styleOpts;
|
|
1852
|
+
}
|
|
1853
|
+
if (docx.numbering) {
|
|
1854
|
+
const numOpts = parseNumberingDefinitions(docx.numbering, parseParagraphProperties, ctx);
|
|
1855
|
+
if (numOpts) opts.numbering = numOpts;
|
|
1856
|
+
}
|
|
1857
|
+
if (docx.fontTable) {
|
|
1858
|
+
const ftResult = fontTableDesc.parse(docx.fontTable, ctx);
|
|
1859
|
+
if (ftResult.fonts && ftResult.fonts.length > 0) {
|
|
1860
|
+
resolveEmbeddedFontData(ftResult.fonts, docx.doc);
|
|
1861
|
+
opts.fonts = ftResult.fonts;
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
if (docx.partRefs.bibliography) {
|
|
1865
|
+
const bibEl = docx.doc.get(docx.partRefs.bibliography);
|
|
1866
|
+
if (bibEl) {
|
|
1867
|
+
const bibResult = bibliographyDesc.parse(bibEl, ctx);
|
|
1868
|
+
if (bibResult.sources && bibResult.sources.length > 0) opts.bibliography = bibResult;
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
if (docx.partRefs.glossary) {
|
|
1872
|
+
const glossaryEl = docx.doc.get(docx.partRefs.glossary);
|
|
1873
|
+
if (glossaryEl) {
|
|
1874
|
+
const glossaryResult = ctx.withPart(docx.partRefs.glossary, () => glossaryDesc.parse(glossaryEl, ctx));
|
|
1875
|
+
if (glossaryResult.parts && glossaryResult.parts.length > 0) opts.glossary = glossaryResult;
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
if (docx.contentTypes) {
|
|
1879
|
+
const ctResult = contentTypesDesc.parse(docx.contentTypes, ctx);
|
|
1880
|
+
if (ctResult) opts.contentTypes = ctResult;
|
|
1881
|
+
}
|
|
1882
|
+
const rawParts = [];
|
|
1883
|
+
for (const prefix of ["word/theme/", "customXml/"]) for (const p of docx.doc.keys(prefix)) {
|
|
1884
|
+
if (p.endsWith("/")) continue;
|
|
1885
|
+
const data = docx.doc.getRaw(p);
|
|
1886
|
+
if (data) rawParts.push({
|
|
1887
|
+
path: p,
|
|
1888
|
+
data
|
|
1889
|
+
});
|
|
1890
|
+
}
|
|
1891
|
+
if (rawParts.length > 0) opts.rawParts = rawParts;
|
|
1892
|
+
return opts;
|
|
1893
|
+
}
|
|
1894
|
+
function parseDocx(data) {
|
|
1895
|
+
const doc = parseArchive(toUint8Array(data));
|
|
1896
|
+
const documentEl = doc.get("word/document.xml");
|
|
1897
|
+
if (!documentEl) throw new Error("word/document.xml not found");
|
|
1898
|
+
const body = documentEl.elements?.find((e) => e.name === "w:body");
|
|
1899
|
+
if (!body) throw new Error("w:body not found in word/document.xml");
|
|
1900
|
+
const background = documentEl.elements?.find((e) => e.name === "w:background");
|
|
1901
|
+
const styles = doc.get("word/styles.xml");
|
|
1902
|
+
const numbering = doc.get("word/numbering.xml");
|
|
1903
|
+
const settings = doc.get("word/settings.xml");
|
|
1904
|
+
const fontTable = doc.get("word/fontTable.xml");
|
|
1905
|
+
const webSettings = doc.get("word/webSettings.xml");
|
|
1906
|
+
const partRefs = parseDocPartRefs(doc);
|
|
1907
|
+
const { coreProps, appProps, customProps } = parseRootRels(doc);
|
|
1908
|
+
return {
|
|
1909
|
+
doc,
|
|
1910
|
+
body,
|
|
1911
|
+
background,
|
|
1912
|
+
styles,
|
|
1913
|
+
numbering,
|
|
1914
|
+
settings,
|
|
1915
|
+
fontTable,
|
|
1916
|
+
webSettings,
|
|
1917
|
+
partRefs,
|
|
1918
|
+
coreProps,
|
|
1919
|
+
appProps,
|
|
1920
|
+
customProps,
|
|
1921
|
+
contentTypes: doc.get("[Content_Types].xml")
|
|
1922
|
+
};
|
|
1923
|
+
}
|
|
1924
|
+
//#endregion
|
|
1925
|
+
export { parseDocument as n, parseDocx as r, parseArchive as t };
|
|
1926
|
+
|
|
1927
|
+
//# sourceMappingURL=parse-K59nx6MF.mjs.map
|