@office-open/docx 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { n as __reExport, t as __exportAll } from "./_chunks/chunk-DmsbSTSH.mjs";
2
- import { AppProperties, BaseXmlComponent, BuilderElement, BuilderElement as BuilderElement$1, EMPTY_OBJECT, EmptyElement, Formatter, HpsMeasureElement, IgnoreIfEmptyXmlComponent, ImportedRootElementAttributes, ImportedXmlComponent, InitializableXmlComponent, NextAttributeComponent, NumberValueElement, OnOffElement, RawPassthrough, Relationships, StringContainer, StringEnumValueElement, StringValueElement, TargetModeType, XmlAttributeComponent, XmlAttributeComponent as XmlAttributeComponent$1, XmlComponent, chartAttr, convertInchesToTwip, convertMillimetersToTwip, convertPixelsToEmu, convertToXmlComponent, getImageType, hashedId, hpsMeasureObj, isRaw, numberValObj, onOffObj, parseCoreProperties, parseRels, readAllXmlParts, readXmlFromZip, stringEnumValObj, stringValObj, uint8ToBase64, uniqueId, uniqueNumericIdCreator, uniqueNumericIdCreator as uniqueNumericIdCreator$1, uniqueUuid, unzipToMap, wrapEl } from "@office-open/core";
2
+ import { AppProperties, BaseXmlComponent, BuilderElement, BuilderElement as BuilderElement$1, EMPTY_OBJECT, EmptyElement, Formatter, HpsMeasureElement, IgnoreIfEmptyXmlComponent, ImportedRootElementAttributes, ImportedXmlComponent, InitializableXmlComponent, NextAttributeComponent, NumberValueElement, OnOffElement, PrettifyType, RawPassthrough, Relationships, StringContainer, StringEnumValueElement, StringValueElement, TargetModeType, XmlAttributeComponent, XmlAttributeComponent as XmlAttributeComponent$1, XmlComponent, addSmartArtRelationships, chartAttr, convertInchesToTwip, convertMillimetersToTwip, convertOutput, convertPixelsToEmu, convertPrettifyType, convertToXmlComponent, getImageType, getReferencedMedia, hasPlaceholders, hashedId, hpsMeasureObj, isRaw, numberValObj, onOffObj, parseCoreProperties, parseRels, readAllXmlParts, readXmlFromZip, replaceChartPlaceholders, replaceImagePlaceholders, replaceSmartArtPlaceholders, stringEnumValObj, stringValObj, uint8ToBase64, uniqueId, uniqueNumericIdCreator, uniqueNumericIdCreator as uniqueNumericIdCreator$1, uniqueUuid, unzipToMap, wrapEl } from "@office-open/core";
3
3
  import { textToUint8Array, toUint8Array } from "undio";
4
4
  import { PresetGeometry, buildFill, createBlipFill, createCustomGeometry, createEffectDag, createEffectList, createOutline, createScene3D, createShape3D, extractBlipFillMedia } from "@office-open/core/drawingml";
5
5
  import { ChartCollection, ChartTitle, createChartType } from "@office-open/core/chart";
@@ -2042,8 +2042,9 @@ var RunProperties = class extends IgnoreIfEmptyXmlComponent {
2042
2042
  const szCs = options.sizeComplexScript === void 0 || options.sizeComplexScript === true ? options.size : options.sizeComplexScript;
2043
2043
  if (szCs) this.push(new HpsMeasureElement("w:szCs", szCs));
2044
2044
  if (options.highlight) this.push(new Highlight(options.highlight));
2045
- const highlightCs = options.highlightComplexScript === void 0 || options.highlightComplexScript === true ? options.highlight : options.highlightComplexScript;
2046
- if (highlightCs) this.push(new HighlightComplexScript(highlightCs));
2045
+ if (options.highlightComplexScript === true) {
2046
+ if (options.highlight) this.push(new HighlightComplexScript(options.highlight));
2047
+ } else if (options.highlightComplexScript !== void 0 && options.highlightComplexScript !== false) this.push(new HighlightComplexScript(options.highlightComplexScript));
2047
2048
  if (options.underline) this.push(createUnderline(options.underline.type, options.underline.color));
2048
2049
  if (options.effect) this.push(new StringValueElement("w:effect", options.effect));
2049
2050
  if (options.border) this.push(createBorderElement("w:bdr", options.border));
@@ -2125,8 +2126,9 @@ function buildRunProperties(options) {
2125
2126
  const szCs = options.sizeComplexScript === void 0 || options.sizeComplexScript === true ? options.size : options.sizeComplexScript;
2126
2127
  if (szCs) children.push(hpsMeasureObj("w:szCs", szCs));
2127
2128
  if (options.highlight) children.push(new Highlight(options.highlight).prepForXml(EMPTY_CTX));
2128
- const highlightCs = options.highlightComplexScript === void 0 || options.highlightComplexScript === true ? options.highlight : options.highlightComplexScript;
2129
- if (highlightCs) children.push(new HighlightComplexScript(highlightCs).prepForXml(EMPTY_CTX));
2129
+ if (options.highlightComplexScript === true) {
2130
+ if (options.highlight) children.push(new HighlightComplexScript(options.highlight).prepForXml(EMPTY_CTX));
2131
+ } else if (options.highlightComplexScript !== void 0 && options.highlightComplexScript !== false) children.push(new HighlightComplexScript(options.highlightComplexScript).prepForXml(EMPTY_CTX));
2130
2132
  if (options.underline) children.push(createUnderline(options.underline.type, options.underline.color).prepForXml(EMPTY_CTX));
2131
2133
  if (options.effect) children.push(stringValObj("w:effect", options.effect));
2132
2134
  if (options.border) children.push(createBorderElement("w:bdr", options.border).prepForXml(EMPTY_CTX));
@@ -21157,1281 +21159,6 @@ var file_exports = /* @__PURE__ */ __exportAll({
21157
21159
  });
21158
21160
  __reExport(file_exports, smartart_exports);
21159
21161
  //#endregion
21160
- //#region \0polyfill-node.global.js
21161
- var _polyfill_node_global_default = typeof _polyfill_node_global_default !== "undefined" ? _polyfill_node_global_default : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};
21162
- //#endregion
21163
- //#region \0polyfill-node.buffer.js
21164
- var lookup = [];
21165
- var revLookup = [];
21166
- var Arr = typeof Uint8Array !== "undefined" ? Uint8Array : Array;
21167
- var inited = false;
21168
- function init() {
21169
- inited = true;
21170
- var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
21171
- for (var i = 0, len = code.length; i < len; ++i) {
21172
- lookup[i] = code[i];
21173
- revLookup[code.charCodeAt(i)] = i;
21174
- }
21175
- revLookup["-".charCodeAt(0)] = 62;
21176
- revLookup["_".charCodeAt(0)] = 63;
21177
- }
21178
- function toByteArray(b64) {
21179
- if (!inited) init();
21180
- var i, j, l, tmp, placeHolders, arr;
21181
- var len = b64.length;
21182
- if (len % 4 > 0) throw new Error("Invalid string. Length must be a multiple of 4");
21183
- placeHolders = b64[len - 2] === "=" ? 2 : b64[len - 1] === "=" ? 1 : 0;
21184
- arr = new Arr(len * 3 / 4 - placeHolders);
21185
- l = placeHolders > 0 ? len - 4 : len;
21186
- var L = 0;
21187
- for (i = 0, j = 0; i < l; i += 4, j += 3) {
21188
- tmp = revLookup[b64.charCodeAt(i)] << 18 | revLookup[b64.charCodeAt(i + 1)] << 12 | revLookup[b64.charCodeAt(i + 2)] << 6 | revLookup[b64.charCodeAt(i + 3)];
21189
- arr[L++] = tmp >> 16 & 255;
21190
- arr[L++] = tmp >> 8 & 255;
21191
- arr[L++] = tmp & 255;
21192
- }
21193
- if (placeHolders === 2) {
21194
- tmp = revLookup[b64.charCodeAt(i)] << 2 | revLookup[b64.charCodeAt(i + 1)] >> 4;
21195
- arr[L++] = tmp & 255;
21196
- } else if (placeHolders === 1) {
21197
- tmp = revLookup[b64.charCodeAt(i)] << 10 | revLookup[b64.charCodeAt(i + 1)] << 4 | revLookup[b64.charCodeAt(i + 2)] >> 2;
21198
- arr[L++] = tmp >> 8 & 255;
21199
- arr[L++] = tmp & 255;
21200
- }
21201
- return arr;
21202
- }
21203
- function tripletToBase64(num) {
21204
- return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63];
21205
- }
21206
- function encodeChunk(uint8, start, end) {
21207
- var tmp;
21208
- var output = [];
21209
- for (var i = start; i < end; i += 3) {
21210
- tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + uint8[i + 2];
21211
- output.push(tripletToBase64(tmp));
21212
- }
21213
- return output.join("");
21214
- }
21215
- function fromByteArray(uint8) {
21216
- if (!inited) init();
21217
- var tmp;
21218
- var len = uint8.length;
21219
- var extraBytes = len % 3;
21220
- var output = "";
21221
- var parts = [];
21222
- var maxChunkLength = 16383;
21223
- for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) parts.push(encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength));
21224
- if (extraBytes === 1) {
21225
- tmp = uint8[len - 1];
21226
- output += lookup[tmp >> 2];
21227
- output += lookup[tmp << 4 & 63];
21228
- output += "==";
21229
- } else if (extraBytes === 2) {
21230
- tmp = (uint8[len - 2] << 8) + uint8[len - 1];
21231
- output += lookup[tmp >> 10];
21232
- output += lookup[tmp >> 4 & 63];
21233
- output += lookup[tmp << 2 & 63];
21234
- output += "=";
21235
- }
21236
- parts.push(output);
21237
- return parts.join("");
21238
- }
21239
- function read(buffer, offset, isLE, mLen, nBytes) {
21240
- var e, m;
21241
- var eLen = nBytes * 8 - mLen - 1;
21242
- var eMax = (1 << eLen) - 1;
21243
- var eBias = eMax >> 1;
21244
- var nBits = -7;
21245
- var i = isLE ? nBytes - 1 : 0;
21246
- var d = isLE ? -1 : 1;
21247
- var s = buffer[offset + i];
21248
- i += d;
21249
- e = s & (1 << -nBits) - 1;
21250
- s >>= -nBits;
21251
- nBits += eLen;
21252
- for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8);
21253
- m = e & (1 << -nBits) - 1;
21254
- e >>= -nBits;
21255
- nBits += mLen;
21256
- for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8);
21257
- if (e === 0) e = 1 - eBias;
21258
- else if (e === eMax) return m ? NaN : (s ? -1 : 1) * Infinity;
21259
- else {
21260
- m = m + Math.pow(2, mLen);
21261
- e = e - eBias;
21262
- }
21263
- return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
21264
- }
21265
- function write(buffer, value, offset, isLE, mLen, nBytes) {
21266
- var e, m, c;
21267
- var eLen = nBytes * 8 - mLen - 1;
21268
- var eMax = (1 << eLen) - 1;
21269
- var eBias = eMax >> 1;
21270
- var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
21271
- var i = isLE ? 0 : nBytes - 1;
21272
- var d = isLE ? 1 : -1;
21273
- var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
21274
- value = Math.abs(value);
21275
- if (isNaN(value) || value === Infinity) {
21276
- m = isNaN(value) ? 1 : 0;
21277
- e = eMax;
21278
- } else {
21279
- e = Math.floor(Math.log(value) / Math.LN2);
21280
- if (value * (c = Math.pow(2, -e)) < 1) {
21281
- e--;
21282
- c *= 2;
21283
- }
21284
- if (e + eBias >= 1) value += rt / c;
21285
- else value += rt * Math.pow(2, 1 - eBias);
21286
- if (value * c >= 2) {
21287
- e++;
21288
- c /= 2;
21289
- }
21290
- if (e + eBias >= eMax) {
21291
- m = 0;
21292
- e = eMax;
21293
- } else if (e + eBias >= 1) {
21294
- m = (value * c - 1) * Math.pow(2, mLen);
21295
- e = e + eBias;
21296
- } else {
21297
- m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
21298
- e = 0;
21299
- }
21300
- }
21301
- for (; mLen >= 8; buffer[offset + i] = m & 255, i += d, m /= 256, mLen -= 8);
21302
- e = e << mLen | m;
21303
- eLen += mLen;
21304
- for (; eLen > 0; buffer[offset + i] = e & 255, i += d, e /= 256, eLen -= 8);
21305
- buffer[offset + i - d] |= s * 128;
21306
- }
21307
- var toString = {}.toString;
21308
- var isArray = Array.isArray || function(arr) {
21309
- return toString.call(arr) == "[object Array]";
21310
- };
21311
- /**
21312
- * If `Buffer.TYPED_ARRAY_SUPPORT`:
21313
- * === true Use Uint8Array implementation (fastest)
21314
- * === false Use Object implementation (most compatible, even IE6)
21315
- *
21316
- * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
21317
- * Opera 11.6+, iOS 4.2+.
21318
- *
21319
- * Due to various browser bugs, sometimes the Object implementation will be used even
21320
- * when the browser supports typed arrays.
21321
- *
21322
- * Note:
21323
- *
21324
- * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
21325
- * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
21326
- *
21327
- * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
21328
- *
21329
- * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
21330
- * incorrect length in some situations.
21331
-
21332
- * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
21333
- * get the Object implementation, which is slower but behaves correctly.
21334
- */
21335
- Buffer.TYPED_ARRAY_SUPPORT = _polyfill_node_global_default.TYPED_ARRAY_SUPPORT !== void 0 ? _polyfill_node_global_default.TYPED_ARRAY_SUPPORT : true;
21336
- kMaxLength();
21337
- function kMaxLength() {
21338
- return Buffer.TYPED_ARRAY_SUPPORT ? 2147483647 : 1073741823;
21339
- }
21340
- function createBuffer(that, length) {
21341
- if (kMaxLength() < length) throw new RangeError("Invalid typed array length");
21342
- if (Buffer.TYPED_ARRAY_SUPPORT) {
21343
- that = new Uint8Array(length);
21344
- that.__proto__ = Buffer.prototype;
21345
- } else {
21346
- if (that === null) that = new Buffer(length);
21347
- that.length = length;
21348
- }
21349
- return that;
21350
- }
21351
- /**
21352
- * The Buffer constructor returns instances of `Uint8Array` that have their
21353
- * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
21354
- * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
21355
- * and the `Uint8Array` methods. Square bracket notation works as expected -- it
21356
- * returns a single octet.
21357
- *
21358
- * The `Uint8Array` prototype remains unmodified.
21359
- */
21360
- function Buffer(arg, encodingOrOffset, length) {
21361
- if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) return new Buffer(arg, encodingOrOffset, length);
21362
- if (typeof arg === "number") {
21363
- if (typeof encodingOrOffset === "string") throw new Error("If encoding is specified then the first argument must be a string");
21364
- return allocUnsafe(this, arg);
21365
- }
21366
- return from(this, arg, encodingOrOffset, length);
21367
- }
21368
- Buffer.poolSize = 8192;
21369
- Buffer._augment = function(arr) {
21370
- arr.__proto__ = Buffer.prototype;
21371
- return arr;
21372
- };
21373
- function from(that, value, encodingOrOffset, length) {
21374
- if (typeof value === "number") throw new TypeError("\"value\" argument must not be a number");
21375
- if (typeof ArrayBuffer !== "undefined" && value instanceof ArrayBuffer) return fromArrayBuffer(that, value, encodingOrOffset, length);
21376
- if (typeof value === "string") return fromString(that, value, encodingOrOffset);
21377
- return fromObject(that, value);
21378
- }
21379
- /**
21380
- * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
21381
- * if value is a number.
21382
- * Buffer.from(str[, encoding])
21383
- * Buffer.from(array)
21384
- * Buffer.from(buffer)
21385
- * Buffer.from(arrayBuffer[, byteOffset[, length]])
21386
- **/
21387
- Buffer.from = function(value, encodingOrOffset, length) {
21388
- return from(null, value, encodingOrOffset, length);
21389
- };
21390
- if (Buffer.TYPED_ARRAY_SUPPORT) {
21391
- Buffer.prototype.__proto__ = Uint8Array.prototype;
21392
- Buffer.__proto__ = Uint8Array;
21393
- if (typeof Symbol !== "undefined" && Symbol.species && Buffer[Symbol.species] === Buffer);
21394
- }
21395
- function assertSize(size) {
21396
- if (typeof size !== "number") throw new TypeError("\"size\" argument must be a number");
21397
- else if (size < 0) throw new RangeError("\"size\" argument must not be negative");
21398
- }
21399
- function alloc(that, size, fill, encoding) {
21400
- assertSize(size);
21401
- if (size <= 0) return createBuffer(that, size);
21402
- if (fill !== void 0) return typeof encoding === "string" ? createBuffer(that, size).fill(fill, encoding) : createBuffer(that, size).fill(fill);
21403
- return createBuffer(that, size);
21404
- }
21405
- /**
21406
- * Creates a new filled Buffer instance.
21407
- * alloc(size[, fill[, encoding]])
21408
- **/
21409
- Buffer.alloc = function(size, fill, encoding) {
21410
- return alloc(null, size, fill, encoding);
21411
- };
21412
- function allocUnsafe(that, size) {
21413
- assertSize(size);
21414
- that = createBuffer(that, size < 0 ? 0 : checked(size) | 0);
21415
- if (!Buffer.TYPED_ARRAY_SUPPORT) for (var i = 0; i < size; ++i) that[i] = 0;
21416
- return that;
21417
- }
21418
- /**
21419
- * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
21420
- * */
21421
- Buffer.allocUnsafe = function(size) {
21422
- return allocUnsafe(null, size);
21423
- };
21424
- /**
21425
- * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
21426
- */
21427
- Buffer.allocUnsafeSlow = function(size) {
21428
- return allocUnsafe(null, size);
21429
- };
21430
- function fromString(that, string, encoding) {
21431
- if (typeof encoding !== "string" || encoding === "") encoding = "utf8";
21432
- if (!Buffer.isEncoding(encoding)) throw new TypeError("\"encoding\" must be a valid string encoding");
21433
- var length = byteLength(string, encoding) | 0;
21434
- that = createBuffer(that, length);
21435
- var actual = that.write(string, encoding);
21436
- if (actual !== length) that = that.slice(0, actual);
21437
- return that;
21438
- }
21439
- function fromArrayLike(that, array) {
21440
- var length = array.length < 0 ? 0 : checked(array.length) | 0;
21441
- that = createBuffer(that, length);
21442
- for (var i = 0; i < length; i += 1) that[i] = array[i] & 255;
21443
- return that;
21444
- }
21445
- function fromArrayBuffer(that, array, byteOffset, length) {
21446
- array.byteLength;
21447
- if (byteOffset < 0 || array.byteLength < byteOffset) throw new RangeError("'offset' is out of bounds");
21448
- if (array.byteLength < byteOffset + (length || 0)) throw new RangeError("'length' is out of bounds");
21449
- if (byteOffset === void 0 && length === void 0) array = new Uint8Array(array);
21450
- else if (length === void 0) array = new Uint8Array(array, byteOffset);
21451
- else array = new Uint8Array(array, byteOffset, length);
21452
- if (Buffer.TYPED_ARRAY_SUPPORT) {
21453
- that = array;
21454
- that.__proto__ = Buffer.prototype;
21455
- } else that = fromArrayLike(that, array);
21456
- return that;
21457
- }
21458
- function fromObject(that, obj) {
21459
- if (internalIsBuffer(obj)) {
21460
- var len = checked(obj.length) | 0;
21461
- that = createBuffer(that, len);
21462
- if (that.length === 0) return that;
21463
- obj.copy(that, 0, 0, len);
21464
- return that;
21465
- }
21466
- if (obj) {
21467
- if (typeof ArrayBuffer !== "undefined" && obj.buffer instanceof ArrayBuffer || "length" in obj) {
21468
- if (typeof obj.length !== "number" || isnan(obj.length)) return createBuffer(that, 0);
21469
- return fromArrayLike(that, obj);
21470
- }
21471
- if (obj.type === "Buffer" && isArray(obj.data)) return fromArrayLike(that, obj.data);
21472
- }
21473
- throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.");
21474
- }
21475
- function checked(length) {
21476
- if (length >= kMaxLength()) throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x" + kMaxLength().toString(16) + " bytes");
21477
- return length | 0;
21478
- }
21479
- Buffer.isBuffer = isBuffer;
21480
- function internalIsBuffer(b) {
21481
- return !!(b != null && b._isBuffer);
21482
- }
21483
- Buffer.compare = function compare(a, b) {
21484
- if (!internalIsBuffer(a) || !internalIsBuffer(b)) throw new TypeError("Arguments must be Buffers");
21485
- if (a === b) return 0;
21486
- var x = a.length;
21487
- var y = b.length;
21488
- for (var i = 0, len = Math.min(x, y); i < len; ++i) if (a[i] !== b[i]) {
21489
- x = a[i];
21490
- y = b[i];
21491
- break;
21492
- }
21493
- if (x < y) return -1;
21494
- if (y < x) return 1;
21495
- return 0;
21496
- };
21497
- Buffer.isEncoding = function isEncoding(encoding) {
21498
- switch (String(encoding).toLowerCase()) {
21499
- case "hex":
21500
- case "utf8":
21501
- case "utf-8":
21502
- case "ascii":
21503
- case "latin1":
21504
- case "binary":
21505
- case "base64":
21506
- case "ucs2":
21507
- case "ucs-2":
21508
- case "utf16le":
21509
- case "utf-16le": return true;
21510
- default: return false;
21511
- }
21512
- };
21513
- Buffer.concat = function concat(list, length) {
21514
- if (!isArray(list)) throw new TypeError("\"list\" argument must be an Array of Buffers");
21515
- if (list.length === 0) return Buffer.alloc(0);
21516
- var i;
21517
- if (length === void 0) {
21518
- length = 0;
21519
- for (i = 0; i < list.length; ++i) length += list[i].length;
21520
- }
21521
- var buffer = Buffer.allocUnsafe(length);
21522
- var pos = 0;
21523
- for (i = 0; i < list.length; ++i) {
21524
- var buf = list[i];
21525
- if (!internalIsBuffer(buf)) throw new TypeError("\"list\" argument must be an Array of Buffers");
21526
- buf.copy(buffer, pos);
21527
- pos += buf.length;
21528
- }
21529
- return buffer;
21530
- };
21531
- function byteLength(string, encoding) {
21532
- if (internalIsBuffer(string)) return string.length;
21533
- if (typeof ArrayBuffer !== "undefined" && typeof ArrayBuffer.isView === "function" && (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) return string.byteLength;
21534
- if (typeof string !== "string") string = "" + string;
21535
- var len = string.length;
21536
- if (len === 0) return 0;
21537
- var loweredCase = false;
21538
- for (;;) switch (encoding) {
21539
- case "ascii":
21540
- case "latin1":
21541
- case "binary": return len;
21542
- case "utf8":
21543
- case "utf-8":
21544
- case void 0: return utf8ToBytes(string).length;
21545
- case "ucs2":
21546
- case "ucs-2":
21547
- case "utf16le":
21548
- case "utf-16le": return len * 2;
21549
- case "hex": return len >>> 1;
21550
- case "base64": return base64ToBytes(string).length;
21551
- default:
21552
- if (loweredCase) return utf8ToBytes(string).length;
21553
- encoding = ("" + encoding).toLowerCase();
21554
- loweredCase = true;
21555
- }
21556
- }
21557
- Buffer.byteLength = byteLength;
21558
- function slowToString(encoding, start, end) {
21559
- var loweredCase = false;
21560
- if (start === void 0 || start < 0) start = 0;
21561
- if (start > this.length) return "";
21562
- if (end === void 0 || end > this.length) end = this.length;
21563
- if (end <= 0) return "";
21564
- end >>>= 0;
21565
- start >>>= 0;
21566
- if (end <= start) return "";
21567
- if (!encoding) encoding = "utf8";
21568
- while (true) switch (encoding) {
21569
- case "hex": return hexSlice(this, start, end);
21570
- case "utf8":
21571
- case "utf-8": return utf8Slice(this, start, end);
21572
- case "ascii": return asciiSlice(this, start, end);
21573
- case "latin1":
21574
- case "binary": return latin1Slice(this, start, end);
21575
- case "base64": return base64Slice(this, start, end);
21576
- case "ucs2":
21577
- case "ucs-2":
21578
- case "utf16le":
21579
- case "utf-16le": return utf16leSlice(this, start, end);
21580
- default:
21581
- if (loweredCase) throw new TypeError("Unknown encoding: " + encoding);
21582
- encoding = (encoding + "").toLowerCase();
21583
- loweredCase = true;
21584
- }
21585
- }
21586
- Buffer.prototype._isBuffer = true;
21587
- function swap(b, n, m) {
21588
- var i = b[n];
21589
- b[n] = b[m];
21590
- b[m] = i;
21591
- }
21592
- Buffer.prototype.swap16 = function swap16() {
21593
- var len = this.length;
21594
- if (len % 2 !== 0) throw new RangeError("Buffer size must be a multiple of 16-bits");
21595
- for (var i = 0; i < len; i += 2) swap(this, i, i + 1);
21596
- return this;
21597
- };
21598
- Buffer.prototype.swap32 = function swap32() {
21599
- var len = this.length;
21600
- if (len % 4 !== 0) throw new RangeError("Buffer size must be a multiple of 32-bits");
21601
- for (var i = 0; i < len; i += 4) {
21602
- swap(this, i, i + 3);
21603
- swap(this, i + 1, i + 2);
21604
- }
21605
- return this;
21606
- };
21607
- Buffer.prototype.swap64 = function swap64() {
21608
- var len = this.length;
21609
- if (len % 8 !== 0) throw new RangeError("Buffer size must be a multiple of 64-bits");
21610
- for (var i = 0; i < len; i += 8) {
21611
- swap(this, i, i + 7);
21612
- swap(this, i + 1, i + 6);
21613
- swap(this, i + 2, i + 5);
21614
- swap(this, i + 3, i + 4);
21615
- }
21616
- return this;
21617
- };
21618
- Buffer.prototype.toString = function toString() {
21619
- var length = this.length | 0;
21620
- if (length === 0) return "";
21621
- if (arguments.length === 0) return utf8Slice(this, 0, length);
21622
- return slowToString.apply(this, arguments);
21623
- };
21624
- Buffer.prototype.equals = function equals(b) {
21625
- if (!internalIsBuffer(b)) throw new TypeError("Argument must be a Buffer");
21626
- if (this === b) return true;
21627
- return Buffer.compare(this, b) === 0;
21628
- };
21629
- Buffer.prototype.inspect = function inspect() {
21630
- var str = "";
21631
- var max = 50;
21632
- if (this.length > 0) {
21633
- str = this.toString("hex", 0, max).match(/.{2}/g).join(" ");
21634
- if (this.length > max) str += " ... ";
21635
- }
21636
- return "<Buffer " + str + ">";
21637
- };
21638
- Buffer.prototype.compare = function compare(target, start, end, thisStart, thisEnd) {
21639
- if (!internalIsBuffer(target)) throw new TypeError("Argument must be a Buffer");
21640
- if (start === void 0) start = 0;
21641
- if (end === void 0) end = target ? target.length : 0;
21642
- if (thisStart === void 0) thisStart = 0;
21643
- if (thisEnd === void 0) thisEnd = this.length;
21644
- if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) throw new RangeError("out of range index");
21645
- if (thisStart >= thisEnd && start >= end) return 0;
21646
- if (thisStart >= thisEnd) return -1;
21647
- if (start >= end) return 1;
21648
- start >>>= 0;
21649
- end >>>= 0;
21650
- thisStart >>>= 0;
21651
- thisEnd >>>= 0;
21652
- if (this === target) return 0;
21653
- var x = thisEnd - thisStart;
21654
- var y = end - start;
21655
- var len = Math.min(x, y);
21656
- var thisCopy = this.slice(thisStart, thisEnd);
21657
- var targetCopy = target.slice(start, end);
21658
- for (var i = 0; i < len; ++i) if (thisCopy[i] !== targetCopy[i]) {
21659
- x = thisCopy[i];
21660
- y = targetCopy[i];
21661
- break;
21662
- }
21663
- if (x < y) return -1;
21664
- if (y < x) return 1;
21665
- return 0;
21666
- };
21667
- function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
21668
- if (buffer.length === 0) return -1;
21669
- if (typeof byteOffset === "string") {
21670
- encoding = byteOffset;
21671
- byteOffset = 0;
21672
- } else if (byteOffset > 2147483647) byteOffset = 2147483647;
21673
- else if (byteOffset < -2147483648) byteOffset = -2147483648;
21674
- byteOffset = +byteOffset;
21675
- if (isNaN(byteOffset)) byteOffset = dir ? 0 : buffer.length - 1;
21676
- if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
21677
- if (byteOffset >= buffer.length) if (dir) return -1;
21678
- else byteOffset = buffer.length - 1;
21679
- else if (byteOffset < 0) if (dir) byteOffset = 0;
21680
- else return -1;
21681
- if (typeof val === "string") val = Buffer.from(val, encoding);
21682
- if (internalIsBuffer(val)) {
21683
- if (val.length === 0) return -1;
21684
- return arrayIndexOf(buffer, val, byteOffset, encoding, dir);
21685
- } else if (typeof val === "number") {
21686
- val = val & 255;
21687
- if (Buffer.TYPED_ARRAY_SUPPORT && typeof Uint8Array.prototype.indexOf === "function") if (dir) return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset);
21688
- else return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset);
21689
- return arrayIndexOf(buffer, [val], byteOffset, encoding, dir);
21690
- }
21691
- throw new TypeError("val must be string, number or Buffer");
21692
- }
21693
- function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
21694
- var indexSize = 1;
21695
- var arrLength = arr.length;
21696
- var valLength = val.length;
21697
- if (encoding !== void 0) {
21698
- encoding = String(encoding).toLowerCase();
21699
- if (encoding === "ucs2" || encoding === "ucs-2" || encoding === "utf16le" || encoding === "utf-16le") {
21700
- if (arr.length < 2 || val.length < 2) return -1;
21701
- indexSize = 2;
21702
- arrLength /= 2;
21703
- valLength /= 2;
21704
- byteOffset /= 2;
21705
- }
21706
- }
21707
- function read(buf, i) {
21708
- if (indexSize === 1) return buf[i];
21709
- else return buf.readUInt16BE(i * indexSize);
21710
- }
21711
- var i;
21712
- if (dir) {
21713
- var foundIndex = -1;
21714
- for (i = byteOffset; i < arrLength; i++) if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
21715
- if (foundIndex === -1) foundIndex = i;
21716
- if (i - foundIndex + 1 === valLength) return foundIndex * indexSize;
21717
- } else {
21718
- if (foundIndex !== -1) i -= i - foundIndex;
21719
- foundIndex = -1;
21720
- }
21721
- } else {
21722
- if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
21723
- for (i = byteOffset; i >= 0; i--) {
21724
- var found = true;
21725
- for (var j = 0; j < valLength; j++) if (read(arr, i + j) !== read(val, j)) {
21726
- found = false;
21727
- break;
21728
- }
21729
- if (found) return i;
21730
- }
21731
- }
21732
- return -1;
21733
- }
21734
- Buffer.prototype.includes = function includes(val, byteOffset, encoding) {
21735
- return this.indexOf(val, byteOffset, encoding) !== -1;
21736
- };
21737
- Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
21738
- return bidirectionalIndexOf(this, val, byteOffset, encoding, true);
21739
- };
21740
- Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {
21741
- return bidirectionalIndexOf(this, val, byteOffset, encoding, false);
21742
- };
21743
- function hexWrite(buf, string, offset, length) {
21744
- offset = Number(offset) || 0;
21745
- var remaining = buf.length - offset;
21746
- if (!length) length = remaining;
21747
- else {
21748
- length = Number(length);
21749
- if (length > remaining) length = remaining;
21750
- }
21751
- var strLen = string.length;
21752
- if (strLen % 2 !== 0) throw new TypeError("Invalid hex string");
21753
- if (length > strLen / 2) length = strLen / 2;
21754
- for (var i = 0; i < length; ++i) {
21755
- var parsed = parseInt(string.substr(i * 2, 2), 16);
21756
- if (isNaN(parsed)) return i;
21757
- buf[offset + i] = parsed;
21758
- }
21759
- return i;
21760
- }
21761
- function utf8Write(buf, string, offset, length) {
21762
- return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length);
21763
- }
21764
- function asciiWrite(buf, string, offset, length) {
21765
- return blitBuffer(asciiToBytes(string), buf, offset, length);
21766
- }
21767
- function latin1Write(buf, string, offset, length) {
21768
- return asciiWrite(buf, string, offset, length);
21769
- }
21770
- function base64Write(buf, string, offset, length) {
21771
- return blitBuffer(base64ToBytes(string), buf, offset, length);
21772
- }
21773
- function ucs2Write(buf, string, offset, length) {
21774
- return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length);
21775
- }
21776
- Buffer.prototype.write = function write(string, offset, length, encoding) {
21777
- if (offset === void 0) {
21778
- encoding = "utf8";
21779
- length = this.length;
21780
- offset = 0;
21781
- } else if (length === void 0 && typeof offset === "string") {
21782
- encoding = offset;
21783
- length = this.length;
21784
- offset = 0;
21785
- } else if (isFinite(offset)) {
21786
- offset = offset | 0;
21787
- if (isFinite(length)) {
21788
- length = length | 0;
21789
- if (encoding === void 0) encoding = "utf8";
21790
- } else {
21791
- encoding = length;
21792
- length = void 0;
21793
- }
21794
- } else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");
21795
- var remaining = this.length - offset;
21796
- if (length === void 0 || length > remaining) length = remaining;
21797
- if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) throw new RangeError("Attempt to write outside buffer bounds");
21798
- if (!encoding) encoding = "utf8";
21799
- var loweredCase = false;
21800
- for (;;) switch (encoding) {
21801
- case "hex": return hexWrite(this, string, offset, length);
21802
- case "utf8":
21803
- case "utf-8": return utf8Write(this, string, offset, length);
21804
- case "ascii": return asciiWrite(this, string, offset, length);
21805
- case "latin1":
21806
- case "binary": return latin1Write(this, string, offset, length);
21807
- case "base64": return base64Write(this, string, offset, length);
21808
- case "ucs2":
21809
- case "ucs-2":
21810
- case "utf16le":
21811
- case "utf-16le": return ucs2Write(this, string, offset, length);
21812
- default:
21813
- if (loweredCase) throw new TypeError("Unknown encoding: " + encoding);
21814
- encoding = ("" + encoding).toLowerCase();
21815
- loweredCase = true;
21816
- }
21817
- };
21818
- Buffer.prototype.toJSON = function toJSON() {
21819
- return {
21820
- type: "Buffer",
21821
- data: Array.prototype.slice.call(this._arr || this, 0)
21822
- };
21823
- };
21824
- function base64Slice(buf, start, end) {
21825
- if (start === 0 && end === buf.length) return fromByteArray(buf);
21826
- else return fromByteArray(buf.slice(start, end));
21827
- }
21828
- function utf8Slice(buf, start, end) {
21829
- end = Math.min(buf.length, end);
21830
- var res = [];
21831
- var i = start;
21832
- while (i < end) {
21833
- var firstByte = buf[i];
21834
- var codePoint = null;
21835
- var bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1;
21836
- if (i + bytesPerSequence <= end) {
21837
- var secondByte, thirdByte, fourthByte, tempCodePoint;
21838
- switch (bytesPerSequence) {
21839
- case 1:
21840
- if (firstByte < 128) codePoint = firstByte;
21841
- break;
21842
- case 2:
21843
- secondByte = buf[i + 1];
21844
- if ((secondByte & 192) === 128) {
21845
- tempCodePoint = (firstByte & 31) << 6 | secondByte & 63;
21846
- if (tempCodePoint > 127) codePoint = tempCodePoint;
21847
- }
21848
- break;
21849
- case 3:
21850
- secondByte = buf[i + 1];
21851
- thirdByte = buf[i + 2];
21852
- if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) {
21853
- tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63;
21854
- if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) codePoint = tempCodePoint;
21855
- }
21856
- break;
21857
- case 4:
21858
- secondByte = buf[i + 1];
21859
- thirdByte = buf[i + 2];
21860
- fourthByte = buf[i + 3];
21861
- if ((secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) {
21862
- tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63;
21863
- if (tempCodePoint > 65535 && tempCodePoint < 1114112) codePoint = tempCodePoint;
21864
- }
21865
- }
21866
- }
21867
- if (codePoint === null) {
21868
- codePoint = 65533;
21869
- bytesPerSequence = 1;
21870
- } else if (codePoint > 65535) {
21871
- codePoint -= 65536;
21872
- res.push(codePoint >>> 10 & 1023 | 55296);
21873
- codePoint = 56320 | codePoint & 1023;
21874
- }
21875
- res.push(codePoint);
21876
- i += bytesPerSequence;
21877
- }
21878
- return decodeCodePointsArray(res);
21879
- }
21880
- var MAX_ARGUMENTS_LENGTH = 4096;
21881
- function decodeCodePointsArray(codePoints) {
21882
- var len = codePoints.length;
21883
- if (len <= MAX_ARGUMENTS_LENGTH) return String.fromCharCode.apply(String, codePoints);
21884
- var res = "";
21885
- var i = 0;
21886
- while (i < len) res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH));
21887
- return res;
21888
- }
21889
- function asciiSlice(buf, start, end) {
21890
- var ret = "";
21891
- end = Math.min(buf.length, end);
21892
- for (var i = start; i < end; ++i) ret += String.fromCharCode(buf[i] & 127);
21893
- return ret;
21894
- }
21895
- function latin1Slice(buf, start, end) {
21896
- var ret = "";
21897
- end = Math.min(buf.length, end);
21898
- for (var i = start; i < end; ++i) ret += String.fromCharCode(buf[i]);
21899
- return ret;
21900
- }
21901
- function hexSlice(buf, start, end) {
21902
- var len = buf.length;
21903
- if (!start || start < 0) start = 0;
21904
- if (!end || end < 0 || end > len) end = len;
21905
- var out = "";
21906
- for (var i = start; i < end; ++i) out += toHex(buf[i]);
21907
- return out;
21908
- }
21909
- function utf16leSlice(buf, start, end) {
21910
- var bytes = buf.slice(start, end);
21911
- var res = "";
21912
- for (var i = 0; i < bytes.length; i += 2) res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
21913
- return res;
21914
- }
21915
- Buffer.prototype.slice = function slice(start, end) {
21916
- var len = this.length;
21917
- start = ~~start;
21918
- end = end === void 0 ? len : ~~end;
21919
- if (start < 0) {
21920
- start += len;
21921
- if (start < 0) start = 0;
21922
- } else if (start > len) start = len;
21923
- if (end < 0) {
21924
- end += len;
21925
- if (end < 0) end = 0;
21926
- } else if (end > len) end = len;
21927
- if (end < start) end = start;
21928
- var newBuf;
21929
- if (Buffer.TYPED_ARRAY_SUPPORT) {
21930
- newBuf = this.subarray(start, end);
21931
- newBuf.__proto__ = Buffer.prototype;
21932
- } else {
21933
- var sliceLen = end - start;
21934
- newBuf = new Buffer(sliceLen, void 0);
21935
- for (var i = 0; i < sliceLen; ++i) newBuf[i] = this[i + start];
21936
- }
21937
- return newBuf;
21938
- };
21939
- function checkOffset(offset, ext, length) {
21940
- if (offset % 1 !== 0 || offset < 0) throw new RangeError("offset is not uint");
21941
- if (offset + ext > length) throw new RangeError("Trying to access beyond buffer length");
21942
- }
21943
- Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength, noAssert) {
21944
- offset = offset | 0;
21945
- byteLength = byteLength | 0;
21946
- if (!noAssert) checkOffset(offset, byteLength, this.length);
21947
- var val = this[offset];
21948
- var mul = 1;
21949
- var i = 0;
21950
- while (++i < byteLength && (mul *= 256)) val += this[offset + i] * mul;
21951
- return val;
21952
- };
21953
- Buffer.prototype.readUIntBE = function readUIntBE(offset, byteLength, noAssert) {
21954
- offset = offset | 0;
21955
- byteLength = byteLength | 0;
21956
- if (!noAssert) checkOffset(offset, byteLength, this.length);
21957
- var val = this[offset + --byteLength];
21958
- var mul = 1;
21959
- while (byteLength > 0 && (mul *= 256)) val += this[offset + --byteLength] * mul;
21960
- return val;
21961
- };
21962
- Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) {
21963
- if (!noAssert) checkOffset(offset, 1, this.length);
21964
- return this[offset];
21965
- };
21966
- Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) {
21967
- if (!noAssert) checkOffset(offset, 2, this.length);
21968
- return this[offset] | this[offset + 1] << 8;
21969
- };
21970
- Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) {
21971
- if (!noAssert) checkOffset(offset, 2, this.length);
21972
- return this[offset] << 8 | this[offset + 1];
21973
- };
21974
- Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) {
21975
- if (!noAssert) checkOffset(offset, 4, this.length);
21976
- return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 16777216;
21977
- };
21978
- Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {
21979
- if (!noAssert) checkOffset(offset, 4, this.length);
21980
- return this[offset] * 16777216 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]);
21981
- };
21982
- Buffer.prototype.readIntLE = function readIntLE(offset, byteLength, noAssert) {
21983
- offset = offset | 0;
21984
- byteLength = byteLength | 0;
21985
- if (!noAssert) checkOffset(offset, byteLength, this.length);
21986
- var val = this[offset];
21987
- var mul = 1;
21988
- var i = 0;
21989
- while (++i < byteLength && (mul *= 256)) val += this[offset + i] * mul;
21990
- mul *= 128;
21991
- if (val >= mul) val -= Math.pow(2, 8 * byteLength);
21992
- return val;
21993
- };
21994
- Buffer.prototype.readIntBE = function readIntBE(offset, byteLength, noAssert) {
21995
- offset = offset | 0;
21996
- byteLength = byteLength | 0;
21997
- if (!noAssert) checkOffset(offset, byteLength, this.length);
21998
- var i = byteLength;
21999
- var mul = 1;
22000
- var val = this[offset + --i];
22001
- while (i > 0 && (mul *= 256)) val += this[offset + --i] * mul;
22002
- mul *= 128;
22003
- if (val >= mul) val -= Math.pow(2, 8 * byteLength);
22004
- return val;
22005
- };
22006
- Buffer.prototype.readInt8 = function readInt8(offset, noAssert) {
22007
- if (!noAssert) checkOffset(offset, 1, this.length);
22008
- if (!(this[offset] & 128)) return this[offset];
22009
- return (255 - this[offset] + 1) * -1;
22010
- };
22011
- Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) {
22012
- if (!noAssert) checkOffset(offset, 2, this.length);
22013
- var val = this[offset] | this[offset + 1] << 8;
22014
- return val & 32768 ? val | 4294901760 : val;
22015
- };
22016
- Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) {
22017
- if (!noAssert) checkOffset(offset, 2, this.length);
22018
- var val = this[offset + 1] | this[offset] << 8;
22019
- return val & 32768 ? val | 4294901760 : val;
22020
- };
22021
- Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) {
22022
- if (!noAssert) checkOffset(offset, 4, this.length);
22023
- return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24;
22024
- };
22025
- Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) {
22026
- if (!noAssert) checkOffset(offset, 4, this.length);
22027
- return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3];
22028
- };
22029
- Buffer.prototype.readFloatLE = function readFloatLE(offset, noAssert) {
22030
- if (!noAssert) checkOffset(offset, 4, this.length);
22031
- return read(this, offset, true, 23, 4);
22032
- };
22033
- Buffer.prototype.readFloatBE = function readFloatBE(offset, noAssert) {
22034
- if (!noAssert) checkOffset(offset, 4, this.length);
22035
- return read(this, offset, false, 23, 4);
22036
- };
22037
- Buffer.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) {
22038
- if (!noAssert) checkOffset(offset, 8, this.length);
22039
- return read(this, offset, true, 52, 8);
22040
- };
22041
- Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {
22042
- if (!noAssert) checkOffset(offset, 8, this.length);
22043
- return read(this, offset, false, 52, 8);
22044
- };
22045
- function checkInt(buf, value, offset, ext, max, min) {
22046
- if (!internalIsBuffer(buf)) throw new TypeError("\"buffer\" argument must be a Buffer instance");
22047
- if (value > max || value < min) throw new RangeError("\"value\" argument is out of bounds");
22048
- if (offset + ext > buf.length) throw new RangeError("Index out of range");
22049
- }
22050
- Buffer.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength, noAssert) {
22051
- value = +value;
22052
- offset = offset | 0;
22053
- byteLength = byteLength | 0;
22054
- if (!noAssert) {
22055
- var maxBytes = Math.pow(2, 8 * byteLength) - 1;
22056
- checkInt(this, value, offset, byteLength, maxBytes, 0);
22057
- }
22058
- var mul = 1;
22059
- var i = 0;
22060
- this[offset] = value & 255;
22061
- while (++i < byteLength && (mul *= 256)) this[offset + i] = value / mul & 255;
22062
- return offset + byteLength;
22063
- };
22064
- Buffer.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength, noAssert) {
22065
- value = +value;
22066
- offset = offset | 0;
22067
- byteLength = byteLength | 0;
22068
- if (!noAssert) {
22069
- var maxBytes = Math.pow(2, 8 * byteLength) - 1;
22070
- checkInt(this, value, offset, byteLength, maxBytes, 0);
22071
- }
22072
- var i = byteLength - 1;
22073
- var mul = 1;
22074
- this[offset + i] = value & 255;
22075
- while (--i >= 0 && (mul *= 256)) this[offset + i] = value / mul & 255;
22076
- return offset + byteLength;
22077
- };
22078
- Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) {
22079
- value = +value;
22080
- offset = offset | 0;
22081
- if (!noAssert) checkInt(this, value, offset, 1, 255, 0);
22082
- if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
22083
- this[offset] = value & 255;
22084
- return offset + 1;
22085
- };
22086
- function objectWriteUInt16(buf, value, offset, littleEndian) {
22087
- if (value < 0) value = 65535 + value + 1;
22088
- 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;
22089
- }
22090
- Buffer.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) {
22091
- value = +value;
22092
- offset = offset | 0;
22093
- if (!noAssert) checkInt(this, value, offset, 2, 65535, 0);
22094
- if (Buffer.TYPED_ARRAY_SUPPORT) {
22095
- this[offset] = value & 255;
22096
- this[offset + 1] = value >>> 8;
22097
- } else objectWriteUInt16(this, value, offset, true);
22098
- return offset + 2;
22099
- };
22100
- Buffer.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) {
22101
- value = +value;
22102
- offset = offset | 0;
22103
- if (!noAssert) checkInt(this, value, offset, 2, 65535, 0);
22104
- if (Buffer.TYPED_ARRAY_SUPPORT) {
22105
- this[offset] = value >>> 8;
22106
- this[offset + 1] = value & 255;
22107
- } else objectWriteUInt16(this, value, offset, false);
22108
- return offset + 2;
22109
- };
22110
- function objectWriteUInt32(buf, value, offset, littleEndian) {
22111
- if (value < 0) value = 4294967295 + value + 1;
22112
- for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) buf[offset + i] = value >>> (littleEndian ? i : 3 - i) * 8 & 255;
22113
- }
22114
- Buffer.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) {
22115
- value = +value;
22116
- offset = offset | 0;
22117
- if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0);
22118
- if (Buffer.TYPED_ARRAY_SUPPORT) {
22119
- this[offset + 3] = value >>> 24;
22120
- this[offset + 2] = value >>> 16;
22121
- this[offset + 1] = value >>> 8;
22122
- this[offset] = value & 255;
22123
- } else objectWriteUInt32(this, value, offset, true);
22124
- return offset + 4;
22125
- };
22126
- Buffer.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) {
22127
- value = +value;
22128
- offset = offset | 0;
22129
- if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0);
22130
- if (Buffer.TYPED_ARRAY_SUPPORT) {
22131
- this[offset] = value >>> 24;
22132
- this[offset + 1] = value >>> 16;
22133
- this[offset + 2] = value >>> 8;
22134
- this[offset + 3] = value & 255;
22135
- } else objectWriteUInt32(this, value, offset, false);
22136
- return offset + 4;
22137
- };
22138
- Buffer.prototype.writeIntLE = function writeIntLE(value, offset, byteLength, noAssert) {
22139
- value = +value;
22140
- offset = offset | 0;
22141
- if (!noAssert) {
22142
- var limit = Math.pow(2, 8 * byteLength - 1);
22143
- checkInt(this, value, offset, byteLength, limit - 1, -limit);
22144
- }
22145
- var i = 0;
22146
- var mul = 1;
22147
- var sub = 0;
22148
- this[offset] = value & 255;
22149
- while (++i < byteLength && (mul *= 256)) {
22150
- if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) sub = 1;
22151
- this[offset + i] = (value / mul >> 0) - sub & 255;
22152
- }
22153
- return offset + byteLength;
22154
- };
22155
- Buffer.prototype.writeIntBE = function writeIntBE(value, offset, byteLength, noAssert) {
22156
- value = +value;
22157
- offset = offset | 0;
22158
- if (!noAssert) {
22159
- var limit = Math.pow(2, 8 * byteLength - 1);
22160
- checkInt(this, value, offset, byteLength, limit - 1, -limit);
22161
- }
22162
- var i = byteLength - 1;
22163
- var mul = 1;
22164
- var sub = 0;
22165
- this[offset + i] = value & 255;
22166
- while (--i >= 0 && (mul *= 256)) {
22167
- if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) sub = 1;
22168
- this[offset + i] = (value / mul >> 0) - sub & 255;
22169
- }
22170
- return offset + byteLength;
22171
- };
22172
- Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) {
22173
- value = +value;
22174
- offset = offset | 0;
22175
- if (!noAssert) checkInt(this, value, offset, 1, 127, -128);
22176
- if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
22177
- if (value < 0) value = 255 + value + 1;
22178
- this[offset] = value & 255;
22179
- return offset + 1;
22180
- };
22181
- Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) {
22182
- value = +value;
22183
- offset = offset | 0;
22184
- if (!noAssert) checkInt(this, value, offset, 2, 32767, -32768);
22185
- if (Buffer.TYPED_ARRAY_SUPPORT) {
22186
- this[offset] = value & 255;
22187
- this[offset + 1] = value >>> 8;
22188
- } else objectWriteUInt16(this, value, offset, true);
22189
- return offset + 2;
22190
- };
22191
- Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) {
22192
- value = +value;
22193
- offset = offset | 0;
22194
- if (!noAssert) checkInt(this, value, offset, 2, 32767, -32768);
22195
- if (Buffer.TYPED_ARRAY_SUPPORT) {
22196
- this[offset] = value >>> 8;
22197
- this[offset + 1] = value & 255;
22198
- } else objectWriteUInt16(this, value, offset, false);
22199
- return offset + 2;
22200
- };
22201
- Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) {
22202
- value = +value;
22203
- offset = offset | 0;
22204
- if (!noAssert) checkInt(this, value, offset, 4, 2147483647, -2147483648);
22205
- if (Buffer.TYPED_ARRAY_SUPPORT) {
22206
- this[offset] = value & 255;
22207
- this[offset + 1] = value >>> 8;
22208
- this[offset + 2] = value >>> 16;
22209
- this[offset + 3] = value >>> 24;
22210
- } else objectWriteUInt32(this, value, offset, true);
22211
- return offset + 4;
22212
- };
22213
- Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) {
22214
- value = +value;
22215
- offset = offset | 0;
22216
- if (!noAssert) checkInt(this, value, offset, 4, 2147483647, -2147483648);
22217
- if (value < 0) value = 4294967295 + value + 1;
22218
- if (Buffer.TYPED_ARRAY_SUPPORT) {
22219
- this[offset] = value >>> 24;
22220
- this[offset + 1] = value >>> 16;
22221
- this[offset + 2] = value >>> 8;
22222
- this[offset + 3] = value & 255;
22223
- } else objectWriteUInt32(this, value, offset, false);
22224
- return offset + 4;
22225
- };
22226
- function checkIEEE754(buf, value, offset, ext, max, min) {
22227
- if (offset + ext > buf.length) throw new RangeError("Index out of range");
22228
- if (offset < 0) throw new RangeError("Index out of range");
22229
- }
22230
- function writeFloat(buf, value, offset, littleEndian, noAssert) {
22231
- if (!noAssert) checkIEEE754(buf, value, offset, 4);
22232
- write(buf, value, offset, littleEndian, 23, 4);
22233
- return offset + 4;
22234
- }
22235
- Buffer.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) {
22236
- return writeFloat(this, value, offset, true, noAssert);
22237
- };
22238
- Buffer.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) {
22239
- return writeFloat(this, value, offset, false, noAssert);
22240
- };
22241
- function writeDouble(buf, value, offset, littleEndian, noAssert) {
22242
- if (!noAssert) checkIEEE754(buf, value, offset, 8);
22243
- write(buf, value, offset, littleEndian, 52, 8);
22244
- return offset + 8;
22245
- }
22246
- Buffer.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) {
22247
- return writeDouble(this, value, offset, true, noAssert);
22248
- };
22249
- Buffer.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) {
22250
- return writeDouble(this, value, offset, false, noAssert);
22251
- };
22252
- Buffer.prototype.copy = function copy(target, targetStart, start, end) {
22253
- if (!start) start = 0;
22254
- if (!end && end !== 0) end = this.length;
22255
- if (targetStart >= target.length) targetStart = target.length;
22256
- if (!targetStart) targetStart = 0;
22257
- if (end > 0 && end < start) end = start;
22258
- if (end === start) return 0;
22259
- if (target.length === 0 || this.length === 0) return 0;
22260
- if (targetStart < 0) throw new RangeError("targetStart out of bounds");
22261
- if (start < 0 || start >= this.length) throw new RangeError("sourceStart out of bounds");
22262
- if (end < 0) throw new RangeError("sourceEnd out of bounds");
22263
- if (end > this.length) end = this.length;
22264
- if (target.length - targetStart < end - start) end = target.length - targetStart + start;
22265
- var len = end - start;
22266
- var i;
22267
- if (this === target && start < targetStart && targetStart < end) for (i = len - 1; i >= 0; --i) target[i + targetStart] = this[i + start];
22268
- else if (len < 1e3 || !Buffer.TYPED_ARRAY_SUPPORT) for (i = 0; i < len; ++i) target[i + targetStart] = this[i + start];
22269
- else Uint8Array.prototype.set.call(target, this.subarray(start, start + len), targetStart);
22270
- return len;
22271
- };
22272
- Buffer.prototype.fill = function fill(val, start, end, encoding) {
22273
- if (typeof val === "string") {
22274
- if (typeof start === "string") {
22275
- encoding = start;
22276
- start = 0;
22277
- end = this.length;
22278
- } else if (typeof end === "string") {
22279
- encoding = end;
22280
- end = this.length;
22281
- }
22282
- if (val.length === 1) {
22283
- var code = val.charCodeAt(0);
22284
- if (code < 256) val = code;
22285
- }
22286
- if (encoding !== void 0 && typeof encoding !== "string") throw new TypeError("encoding must be a string");
22287
- if (typeof encoding === "string" && !Buffer.isEncoding(encoding)) throw new TypeError("Unknown encoding: " + encoding);
22288
- } else if (typeof val === "number") val = val & 255;
22289
- if (start < 0 || this.length < start || this.length < end) throw new RangeError("Out of range index");
22290
- if (end <= start) return this;
22291
- start = start >>> 0;
22292
- end = end === void 0 ? this.length : end >>> 0;
22293
- if (!val) val = 0;
22294
- var i;
22295
- if (typeof val === "number") for (i = start; i < end; ++i) this[i] = val;
22296
- else {
22297
- var bytes = internalIsBuffer(val) ? val : utf8ToBytes(new Buffer(val, encoding).toString());
22298
- var len = bytes.length;
22299
- for (i = 0; i < end - start; ++i) this[i + start] = bytes[i % len];
22300
- }
22301
- return this;
22302
- };
22303
- var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g;
22304
- function base64clean(str) {
22305
- str = stringtrim(str).replace(INVALID_BASE64_RE, "");
22306
- if (str.length < 2) return "";
22307
- while (str.length % 4 !== 0) str = str + "=";
22308
- return str;
22309
- }
22310
- function stringtrim(str) {
22311
- if (str.trim) return str.trim();
22312
- return str.replace(/^\s+|\s+$/g, "");
22313
- }
22314
- function toHex(n) {
22315
- if (n < 16) return "0" + n.toString(16);
22316
- return n.toString(16);
22317
- }
22318
- function utf8ToBytes(string, units) {
22319
- units = units || Infinity;
22320
- var codePoint;
22321
- var length = string.length;
22322
- var leadSurrogate = null;
22323
- var bytes = [];
22324
- for (var i = 0; i < length; ++i) {
22325
- codePoint = string.charCodeAt(i);
22326
- if (codePoint > 55295 && codePoint < 57344) {
22327
- if (!leadSurrogate) {
22328
- if (codePoint > 56319) {
22329
- if ((units -= 3) > -1) bytes.push(239, 191, 189);
22330
- continue;
22331
- } else if (i + 1 === length) {
22332
- if ((units -= 3) > -1) bytes.push(239, 191, 189);
22333
- continue;
22334
- }
22335
- leadSurrogate = codePoint;
22336
- continue;
22337
- }
22338
- if (codePoint < 56320) {
22339
- if ((units -= 3) > -1) bytes.push(239, 191, 189);
22340
- leadSurrogate = codePoint;
22341
- continue;
22342
- }
22343
- codePoint = (leadSurrogate - 55296 << 10 | codePoint - 56320) + 65536;
22344
- } else if (leadSurrogate) {
22345
- if ((units -= 3) > -1) bytes.push(239, 191, 189);
22346
- }
22347
- leadSurrogate = null;
22348
- if (codePoint < 128) {
22349
- if ((units -= 1) < 0) break;
22350
- bytes.push(codePoint);
22351
- } else if (codePoint < 2048) {
22352
- if ((units -= 2) < 0) break;
22353
- bytes.push(codePoint >> 6 | 192, codePoint & 63 | 128);
22354
- } else if (codePoint < 65536) {
22355
- if ((units -= 3) < 0) break;
22356
- bytes.push(codePoint >> 12 | 224, codePoint >> 6 & 63 | 128, codePoint & 63 | 128);
22357
- } else if (codePoint < 1114112) {
22358
- if ((units -= 4) < 0) break;
22359
- bytes.push(codePoint >> 18 | 240, codePoint >> 12 & 63 | 128, codePoint >> 6 & 63 | 128, codePoint & 63 | 128);
22360
- } else throw new Error("Invalid code point");
22361
- }
22362
- return bytes;
22363
- }
22364
- function asciiToBytes(str) {
22365
- var byteArray = [];
22366
- for (var i = 0; i < str.length; ++i) byteArray.push(str.charCodeAt(i) & 255);
22367
- return byteArray;
22368
- }
22369
- function utf16leToBytes(str, units) {
22370
- var c, hi, lo;
22371
- var byteArray = [];
22372
- for (var i = 0; i < str.length; ++i) {
22373
- if ((units -= 2) < 0) break;
22374
- c = str.charCodeAt(i);
22375
- hi = c >> 8;
22376
- lo = c % 256;
22377
- byteArray.push(lo);
22378
- byteArray.push(hi);
22379
- }
22380
- return byteArray;
22381
- }
22382
- function base64ToBytes(str) {
22383
- return toByteArray(base64clean(str));
22384
- }
22385
- function blitBuffer(src, dst, offset, length) {
22386
- for (var i = 0; i < length; ++i) {
22387
- if (i + offset >= dst.length || i >= src.length) break;
22388
- dst[i + offset] = src[i];
22389
- }
22390
- return i;
22391
- }
22392
- function isnan(val) {
22393
- return val !== val;
22394
- }
22395
- function isBuffer(obj) {
22396
- return obj != null && (!!obj._isBuffer || isFastBuffer(obj) || isSlowBuffer(obj));
22397
- }
22398
- function isFastBuffer(obj) {
22399
- return !!obj.constructor && typeof obj.constructor.isBuffer === "function" && obj.constructor.isBuffer(obj);
22400
- }
22401
- function isSlowBuffer(obj) {
22402
- return typeof obj.readFloatLE === "function" && typeof obj.slice === "function" && isFastBuffer(obj.slice(0, 0));
22403
- }
22404
- //#endregion
22405
- //#region src/util/output-type.ts
22406
- /**
22407
- * Output type definitions for document generation.
22408
- *
22409
- * This module defines the various output formats supported when generating
22410
- * .docx files. These types correspond to fflate's output formats.
22411
- *
22412
- * @module
22413
- */
22414
- /**
22415
- * Converts a Uint8Array to the specified output type.
22416
- *
22417
- * This is used by both the Packer and patchDocument to convert fflate's
22418
- * raw Uint8Array output into the user's requested format.
22419
- */
22420
- const convertOutput = (data, type) => {
22421
- switch (type) {
22422
- case "nodebuffer": return Buffer.from(data);
22423
- case "blob": return new Blob([data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength)], { type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" });
22424
- case "arraybuffer": return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
22425
- case "uint8array": return data;
22426
- case "base64": return btoa(strFromU8(data, true));
22427
- case "string":
22428
- case "text":
22429
- case "binarystring": return strFromU8(data, true);
22430
- case "array": return [...data];
22431
- default: return data;
22432
- }
22433
- };
22434
- //#endregion
22435
21162
  //#region src/file/fonts/obfuscate-ttf-to-odttf.ts
22436
21163
  /**
22437
21164
  * Font obfuscation module for embedding fonts in WordprocessingML documents.
@@ -22484,125 +21211,12 @@ const obfuscate = (buf, fontKey) => {
22484
21211
  return out;
22485
21212
  };
22486
21213
  //#endregion
22487
- //#region src/export/packer/chart-replacer.ts
22488
- /**
22489
- * Replaces chart placeholder tokens with relationship IDs in XML content.
22490
- *
22491
- * Charts use placeholders like `{chart:chart_123}` in the document XML.
22492
- * This class replaces them with the actual relationship IDs.
22493
- */
22494
- var ChartReplacer = class {
22495
- /**
22496
- * Replaces chart placeholder tokens with relationship IDs.
22497
- *
22498
- * @param xmlData - The XML string containing chart placeholders
22499
- * @param charts - The chart collection
22500
- * @param offset - Starting offset for relationship IDs
22501
- * @returns XML string with placeholders replaced by relationship IDs
22502
- */
22503
- replace(xmlData, charts, offset) {
22504
- let currentXmlData = xmlData;
22505
- charts.Array.forEach((chartData, i) => {
22506
- currentXmlData = currentXmlData.replace(new RegExp(`\\{chart:${chartData.key}\\}`, "g"), (offset + i).toString());
22507
- });
22508
- return currentXmlData;
22509
- }
22510
- };
22511
- //#endregion
22512
- //#region src/export/packer/image-replacer.ts
22513
- var ImageReplacer = class {
22514
- replace(xmlData, mediaData, offset) {
22515
- let currentXmlData = xmlData;
22516
- mediaData.forEach((image, i) => {
22517
- currentXmlData = currentXmlData.replace(new RegExp(`{${image.fileName}}`, "g"), `rId${offset + i}`);
22518
- });
22519
- return currentXmlData;
22520
- }
22521
- getMediaData(xmlData, media) {
22522
- return media.Array.filter((image) => xmlData.search(`{${image.fileName}}`) > 0);
22523
- }
22524
- };
22525
- //#endregion
22526
- //#region src/export/packer/numbering-replacer.ts
22527
- /**
22528
- * Replaces numbering instance placeholders with actual numbering IDs in XML content.
22529
- *
22530
- * Numbering instances (for bullets and numbered lists) use placeholder tokens during
22531
- * compilation. This class replaces those placeholders with the final numbering IDs
22532
- * that reference the numbering definitions in numbering.xml.
22533
- *
22534
- * @example
22535
- * ```typescript
22536
- * const replacer = new NumberingReplacer();
22537
- * const updatedXml = replacer.replace(xmlString, concreteNumberings);
22538
- * ```
22539
- */
22540
- var NumberingReplacer = class {
22541
- /**
22542
- * Replaces numbering placeholder tokens with actual numbering IDs.
22543
- *
22544
- * Placeholder format: {reference-instance} where reference identifies the
22545
- * numbering definition and instance is the specific usage.
22546
- *
22547
- * @param xmlData - The XML string containing numbering placeholders
22548
- * @param concreteNumberings - Array of concrete numbering instances to replace
22549
- * @returns XML string with placeholders replaced by numbering IDs
22550
- */
22551
- replace(xmlData, concreteNumberings) {
22552
- let currentXmlData = xmlData;
22553
- for (const concreteNumbering of concreteNumberings) currentXmlData = currentXmlData.replace(new RegExp(`{${concreteNumbering.reference}-${concreteNumbering.instance}}`, "g"), concreteNumbering.numId.toString());
22554
- return currentXmlData;
22555
- }
22556
- };
22557
- //#endregion
22558
- //#region src/export/packer/smartart-replacer.ts
22559
- /**
22560
- * Replaces SmartArt placeholder tokens with relationship IDs in XML content.
22561
- *
22562
- * SmartArt uses multiple placeholders:
22563
- * - `{smartart:N}` — data model relationship (internal)
22564
- * - `{smartart-lo:N}` — layout relationship (internal)
22565
- * - `{smartart-qs:N}` — quick style relationship (internal)
22566
- * - `{smartart-cs:N}` — color style relationship (internal)
22567
- */
22568
- var SmartArtReplacer = class {
22569
- /**
22570
- * Replaces SmartArt placeholder tokens with relationship IDs.
22571
- */
22572
- replace(xmlData, smartArts, dataOffset) {
22573
- let currentXmlData = xmlData;
22574
- smartArts.Array.forEach((smartArtData, i) => {
22575
- const key = smartArtData.key;
22576
- currentXmlData = currentXmlData.replace(new RegExp(`\\{smartart:${key}\\}`, "g"), (dataOffset + i).toString());
22577
- const loOffset = dataOffset + smartArts.Array.length;
22578
- const qsOffset = loOffset + smartArts.Array.length;
22579
- const csOffset = qsOffset + smartArts.Array.length;
22580
- currentXmlData = currentXmlData.replace(new RegExp(`\\{smartart-lo:${key}\\}`, "g"), (loOffset + i).toString());
22581
- currentXmlData = currentXmlData.replace(new RegExp(`\\{smartart-qs:${key}\\}`, "g"), (qsOffset + i).toString());
22582
- currentXmlData = currentXmlData.replace(new RegExp(`\\{smartart-cs:${key}\\}`, "g"), (csOffset + i).toString());
22583
- });
22584
- return currentXmlData;
22585
- }
22586
- /**
22587
- * Adds SmartArt relationships to the document relationships.
22588
- *
22589
- * All relationships are internal (pointing to package-local files).
22590
- */
22591
- addRelationships(smartArts, addRelationship, baseOffset, chartCount) {
22592
- const dataOffset = baseOffset + chartCount;
22593
- const smartArtCount = smartArts.Array.length;
22594
- const loOffset = dataOffset + smartArtCount;
22595
- const qsOffset = loOffset + smartArtCount;
22596
- const csOffset = qsOffset + smartArtCount;
22597
- smartArts.Array.forEach((_smartArtData, i) => {
22598
- addRelationship(dataOffset + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/diagramData", `diagrams/data${i + 1}.xml`);
22599
- addRelationship(loOffset + i, "http://schemas.microsoft.com/office/2007/relationships/diagramLayout", `diagrams/layout${i + 1}.xml`);
22600
- addRelationship(qsOffset + i, "http://schemas.microsoft.com/office/2007/relationships/diagramStyle", `diagrams/quickStyle${i + 1}.xml`);
22601
- addRelationship(csOffset + i, "http://schemas.microsoft.com/office/2007/relationships/diagramColors", `diagrams/colors${i + 1}.xml`);
22602
- addRelationship(csOffset + smartArtCount + i, "http://schemas.microsoft.com/office/2007/relationships/diagramDrawing", `diagrams/drawing${i + 1}.xml`);
22603
- });
22604
- }
22605
- };
21214
+ //#region src/export/packer/numbering-placeholders.ts
21215
+ function replaceNumberingPlaceholders(xml, concreteNumberings) {
21216
+ let result = xml;
21217
+ for (const { reference, instance, numId } of concreteNumberings) result = result.replace(new RegExp(`{${reference}-${instance}}`, "g"), numId.toString());
21218
+ return result;
21219
+ }
22606
21220
  //#endregion
22607
21221
  //#region src/export/packer/next-compiler.ts
22608
21222
  /**
@@ -22620,21 +21234,8 @@ var SmartArtReplacer = class {
22620
21234
  */
22621
21235
  var Compiler = class {
22622
21236
  formatter;
22623
- imageReplacer;
22624
- numberingReplacer;
22625
- chartReplacer;
22626
- smartArtReplacer;
22627
- /**
22628
- * Creates a new Compiler instance.
22629
- *
22630
- * Initializes the formatter and replacer utilities used during compilation.
22631
- */
22632
21237
  constructor() {
22633
21238
  this.formatter = new Formatter();
22634
- this.imageReplacer = new ImageReplacer();
22635
- this.numberingReplacer = new NumberingReplacer();
22636
- this.chartReplacer = new ChartReplacer();
22637
- this.smartArtReplacer = new SmartArtReplacer();
22638
21239
  }
22639
21240
  /**
22640
21241
  * Compiles a File object into a flat file map suitable for fflate zipSync.
@@ -22660,12 +21261,12 @@ var Compiler = class {
22660
21261
  const footerFormattedViews = /* @__PURE__ */ new Map();
22661
21262
  const xmlifiedFileMapping = this.xmlifyFile(file, headerFormattedViews, footerFormattedViews, prettifyXml);
22662
21263
  const map = new Map(Object.entries(xmlifiedFileMapping));
22663
- for (const [, obj] of map) if (Array.isArray(obj)) for (const subFile of obj) files[subFile.path] = typeof subFile.data === "string" ? textToUint8Array(subFile.data) : subFile.data;
21264
+ for (const [, obj] of map) if (Array.isArray(obj)) for (const subFile of obj) files[subFile.path] = [typeof subFile.data === "string" ? textToUint8Array(subFile.data) : subFile.data, { level: 0 }];
22664
21265
  else {
22665
21266
  const fileObj = obj;
22666
- files[fileObj.path] = typeof fileObj.data === "string" ? textToUint8Array(fileObj.data) : fileObj.data;
21267
+ files[fileObj.path] = [typeof fileObj.data === "string" ? textToUint8Array(fileObj.data) : fileObj.data, { level: 0 }];
22667
21268
  }
22668
- for (const subFile of overrides) files[subFile.path] = typeof subFile.data === "string" ? textToUint8Array(subFile.data) : subFile.data;
21269
+ for (const subFile of overrides) files[subFile.path] = [typeof subFile.data === "string" ? textToUint8Array(subFile.data) : subFile.data, { level: 0 }];
22669
21270
  for (const mediaData of file.Media.Array) {
22670
21271
  files[`word/media/${mediaData.fileName}`] = [toUint8Array(mediaData.data), { level: 0 }];
22671
21272
  if (mediaData.type === "svg") files[`word/media/${mediaData.fallback.fileName}`] = [toUint8Array(mediaData.fallback.data), { level: 0 }];
@@ -22719,9 +21320,9 @@ var Compiler = class {
22719
21320
  },
22720
21321
  indent: prettify
22721
21322
  });
22722
- const documentMediaDatas = this.imageReplacer.getMediaData(documentXmlData, file.Media);
22723
- const commentMediaDatas = this.imageReplacer.getMediaData(commentXmlData, file.Media);
22724
- const footnoteMediaDatas = this.imageReplacer.getMediaData(footnoteXmlData, file.Media);
21323
+ const documentMediaDatas = hasPlaceholders(documentXmlData) ? getReferencedMedia(documentXmlData, file.Media.Array) : [];
21324
+ const commentMediaDatas = hasPlaceholders(commentXmlData) ? getReferencedMedia(commentXmlData, file.Media.Array) : [];
21325
+ const footnoteMediaDatas = hasPlaceholders(footnoteXmlData) ? getReferencedMedia(footnoteXmlData, file.Media.Array) : [];
22725
21326
  return {
22726
21327
  AppProperties: {
22727
21328
  data: xml(this.formatter.format(file.AppProperties, {
@@ -22729,20 +21330,14 @@ var Compiler = class {
22729
21330
  file,
22730
21331
  stack: [],
22731
21332
  viewWrapper: file.Document
22732
- }), {
22733
- declaration: {
22734
- encoding: "UTF-8",
22735
- standalone: "yes"
22736
- },
22737
- indent: prettify
22738
- }),
21333
+ }), { declaration: {
21334
+ encoding: "UTF-8",
21335
+ standalone: "yes"
21336
+ } }),
22739
21337
  path: "docProps/app.xml"
22740
21338
  },
22741
21339
  Comments: {
22742
- data: (() => {
22743
- const xmlData = this.imageReplacer.replace(commentXmlData, commentMediaDatas, commentRelationshipCount);
22744
- return this.numberingReplacer.replace(xmlData, file.Numbering.ConcreteNumbering);
22745
- })(),
21340
+ data: replaceNumberingPlaceholders(commentMediaDatas.length > 0 ? replaceImagePlaceholders(commentXmlData, commentMediaDatas, commentRelationshipCount, "plain") : commentXmlData, file.Numbering.ConcreteNumbering),
22746
21341
  path: "word/comments.xml"
22747
21342
  },
22748
21343
  CommentsRelationships: {
@@ -22806,11 +21401,13 @@ var Compiler = class {
22806
21401
  },
22807
21402
  Document: {
22808
21403
  data: (() => {
22809
- let xmlData = this.imageReplacer.replace(documentXmlData, documentMediaDatas, documentRelationshipCount);
22810
- xmlData = this.chartReplacer.replace(xmlData, file.Charts, documentRelationshipCount);
22811
- const smartArtDataOffset = documentRelationshipCount + documentMediaDatas.length + file.Charts.Array.length;
22812
- xmlData = this.smartArtReplacer.replace(xmlData, file.SmartArts, smartArtDataOffset);
22813
- return this.numberingReplacer.replace(xmlData, file.Numbering.ConcreteNumbering);
21404
+ let xmlData = documentMediaDatas.length > 0 ? replaceImagePlaceholders(documentXmlData, documentMediaDatas, documentRelationshipCount, "plain") : documentXmlData;
21405
+ if (hasPlaceholders(xmlData)) {
21406
+ xmlData = replaceChartPlaceholders(xmlData, file.Charts.Array.map((c) => c.key), documentRelationshipCount, "plain");
21407
+ const smartArtDataOffset = documentRelationshipCount + documentMediaDatas.length + file.Charts.Array.length;
21408
+ xmlData = replaceSmartArtPlaceholders(xmlData, file.SmartArts.Array.map((s) => s.key), smartArtDataOffset, "plain");
21409
+ }
21410
+ return replaceNumberingPlaceholders(xmlData, file.Numbering.ConcreteNumbering);
22814
21411
  })(),
22815
21412
  path: "word/document.xml"
22816
21413
  },
@@ -22878,10 +21475,7 @@ var Compiler = class {
22878
21475
  path: "word/_rels/fontTable.xml.rels"
22879
21476
  },
22880
21477
  FootNotes: {
22881
- data: (() => {
22882
- const xmlData = this.imageReplacer.replace(footnoteXmlData, footnoteMediaDatas, footnoteRelationshipCount);
22883
- return this.numberingReplacer.replace(xmlData, file.Numbering.ConcreteNumbering);
22884
- })(),
21478
+ data: replaceNumberingPlaceholders(footnoteMediaDatas.length > 0 ? replaceImagePlaceholders(footnoteXmlData, footnoteMediaDatas, footnoteRelationshipCount, "plain") : footnoteXmlData, file.Numbering.ConcreteNumbering),
22885
21479
  path: "word/footnotes.xml"
22886
21480
  },
22887
21481
  FootNotesRelationships: {
@@ -22912,7 +21506,7 @@ var Compiler = class {
22912
21506
  indent: prettify
22913
21507
  });
22914
21508
  footerFormattedViews.set(index, xmlData);
22915
- this.imageReplacer.getMediaData(xmlData, file.Media).forEach((mediaData, i) => {
21509
+ getReferencedMedia(xmlData, file.Media.Array).forEach((mediaData, i) => {
22916
21510
  footerWrapper.Relationships.addRelationship(i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaData.fileName}`);
22917
21511
  });
22918
21512
  return {
@@ -22930,10 +21524,9 @@ var Compiler = class {
22930
21524
  }),
22931
21525
  Footers: file.Footers.map((_footerWrapper, index) => {
22932
21526
  const tempXmlData = footerFormattedViews.get(index);
22933
- const mediaDatas = this.imageReplacer.getMediaData(tempXmlData, file.Media);
22934
- const xmlData = this.imageReplacer.replace(tempXmlData, mediaDatas, 0);
21527
+ const mediaDatas = hasPlaceholders(tempXmlData) ? getReferencedMedia(tempXmlData, file.Media.Array) : [];
22935
21528
  return {
22936
- data: this.numberingReplacer.replace(xmlData, file.Numbering.ConcreteNumbering),
21529
+ data: replaceNumberingPlaceholders(mediaDatas.length > 0 ? replaceImagePlaceholders(tempXmlData, mediaDatas, 0, "plain") : tempXmlData, file.Numbering.ConcreteNumbering),
22937
21530
  path: `word/footer${index + 1}.xml`
22938
21531
  };
22939
21532
  }),
@@ -22948,7 +21541,7 @@ var Compiler = class {
22948
21541
  indent: prettify
22949
21542
  });
22950
21543
  headerFormattedViews.set(index, xmlData);
22951
- this.imageReplacer.getMediaData(xmlData, file.Media).forEach((mediaData, i) => {
21544
+ getReferencedMedia(xmlData, file.Media.Array).forEach((mediaData, i) => {
22952
21545
  headerWrapper.Relationships.addRelationship(i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaData.fileName}`);
22953
21546
  });
22954
21547
  return {
@@ -22966,10 +21559,9 @@ var Compiler = class {
22966
21559
  }),
22967
21560
  Headers: file.Headers.map((_headerWrapper, index) => {
22968
21561
  const tempXmlData = headerFormattedViews.get(index);
22969
- const mediaDatas = this.imageReplacer.getMediaData(tempXmlData, file.Media);
22970
- const xmlData = this.imageReplacer.replace(tempXmlData, mediaDatas, 0);
21562
+ const mediaDatas = hasPlaceholders(tempXmlData) ? getReferencedMedia(tempXmlData, file.Media.Array) : [];
22971
21563
  return {
22972
- data: this.numberingReplacer.replace(xmlData, file.Numbering.ConcreteNumbering),
21564
+ data: replaceNumberingPlaceholders(mediaDatas.length > 0 ? replaceImagePlaceholders(tempXmlData, mediaDatas, 0, "plain") : tempXmlData, file.Numbering.ConcreteNumbering),
22973
21565
  path: `word/header${index + 1}.xml`
22974
21566
  };
22975
21567
  }),
@@ -23012,9 +21604,12 @@ var Compiler = class {
23012
21604
  file.Charts.Array.forEach((_chartData, i) => {
23013
21605
  file.Document.Relationships.addRelationship(chartOffset + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart", `charts/chart${i + 1}.xml`);
23014
21606
  });
23015
- this.smartArtReplacer.addRelationships(file.SmartArts, (id, type, target, targetMode) => {
23016
- file.Document.Relationships.addRelationship(id, type, target, targetMode);
23017
- }, documentRelationshipCount, documentMediaDatas.length + file.Charts.Array.length);
21607
+ addSmartArtRelationships(file.SmartArts.Array.map((s) => s.key), (id, type, target) => {
21608
+ file.Document.Relationships.addRelationship(id, type, target);
21609
+ }, documentRelationshipCount + documentMediaDatas.length + file.Charts.Array.length, 0, {
21610
+ pathPrefix: "",
21611
+ styleRelType: "http://schemas.microsoft.com/office/2007/relationships/diagramStyle"
21612
+ });
23018
21613
  file.Document.Relationships.addRelationship(file.Document.Relationships.RelationshipCount + 1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable", "fontTable.xml");
23019
21614
  return xml(this.formatter.format(file.Document.Relationships, {
23020
21615
  fileData: file,
@@ -23044,21 +21639,18 @@ var Compiler = class {
23044
21639
  path: "word/settings.xml"
23045
21640
  },
23046
21641
  Styles: {
23047
- data: (() => {
23048
- const xmlStyles = xml(this.formatter.format(file.Styles, {
23049
- fileData: file,
23050
- file,
23051
- stack: [],
23052
- viewWrapper: file.Document
23053
- }), {
23054
- declaration: {
23055
- encoding: "UTF-8",
23056
- standalone: "yes"
23057
- },
23058
- indent: prettify
23059
- });
23060
- return this.numberingReplacer.replace(xmlStyles, file.Numbering.ConcreteNumbering);
23061
- })(),
21642
+ data: replaceNumberingPlaceholders(xml(this.formatter.format(file.Styles, {
21643
+ fileData: file,
21644
+ file,
21645
+ stack: [],
21646
+ viewWrapper: file.Document
21647
+ }), {
21648
+ declaration: {
21649
+ encoding: "UTF-8",
21650
+ standalone: "yes"
21651
+ },
21652
+ indent: prettify
21653
+ }), file.Numbering.ConcreteNumbering),
23062
21654
  path: "word/styles.xml"
23063
21655
  },
23064
21656
  ...file.Bibliography ? { Bibliography: {
@@ -23147,26 +21739,6 @@ var Compiler = class {
23147
21739
  //#endregion
23148
21740
  //#region src/export/packer/packer.ts
23149
21741
  /**
23150
- * Packer module for exporting documents to various output formats.
23151
- *
23152
- * @module
23153
- */
23154
- /**
23155
- * Prettify options for formatting XML output.
23156
- *
23157
- * Controls the indentation style used when formatting the generated XML.
23158
- * Prettified output is more human-readable but results in larger file sizes.
23159
- *
23160
- * @publicApi
23161
- */
23162
- const PrettifyType = {
23163
- NONE: "",
23164
- WITH_2_BLANKS: " ",
23165
- WITH_4_BLANKS: " ",
23166
- WITH_TAB: " "
23167
- };
23168
- const convertPrettifyType = (prettify) => prettify === true ? PrettifyType.WITH_2_BLANKS : prettify === false ? void 0 : prettify;
23169
- /**
23170
21742
  * Exports documents to various output formats.
23171
21743
  *
23172
21744
  * The Packer class provides static methods to convert a File object into different
@@ -23888,7 +22460,6 @@ const PatchType = {
23888
22460
  DOCUMENT: "file",
23889
22461
  PARAGRAPH: "paragraph"
23890
22462
  };
23891
- const imageReplacer = new ImageReplacer();
23892
22463
  const UTF16LE = new Uint8Array([255, 254]);
23893
22464
  const UTF16BE = new Uint8Array([254, 255]);
23894
22465
  const compareByteArrays = (a, b) => {
@@ -24013,7 +22584,7 @@ const patchDocument = async ({ outputType, data, patches, keepOriginalStyles, pl
24013
22584
  if (!recursive || !didFindOccurrence) break;
24014
22585
  }
24015
22586
  }
24016
- const mediaDatas = imageReplacer.getMediaData(JSON.stringify(json), context.file.Media);
22587
+ const mediaDatas = getReferencedMedia(JSON.stringify(json), context.file.Media.Array);
24017
22588
  if (mediaDatas.length > 0) {
24018
22589
  hasMedia = true;
24019
22590
  imageRelationshipAdditions.push({
@@ -24029,7 +22600,7 @@ const patchDocument = async ({ outputType, data, patches, keepOriginalStyles, pl
24029
22600
  const relationshipsJson = map.get(relationshipKey) ?? createRelationshipFile();
24030
22601
  map.set(relationshipKey, relationshipsJson);
24031
22602
  const index = getNextRelationshipIndex(relationshipsJson);
24032
- const newJson = imageReplacer.replace(JSON.stringify(map.get(key)), mediaDatas, index);
22603
+ const newJson = replaceImagePlaceholders(JSON.stringify(map.get(key)), mediaDatas, index, "plain");
24033
22604
  map.set(key, JSON.parse(newJson));
24034
22605
  for (let i = 0; i < mediaDatas.length; i++) {
24035
22606
  const { fileName } = mediaDatas[i];
@@ -24885,7 +23456,8 @@ function parseParagraph(p, ctx) {
24885
23456
  $type: "math",
24886
23457
  element: child
24887
23458
  });
24888
- else if (child.name === "w:pPr") {} else children.push({
23459
+ else if (child.name === "w:pPr") {} else if (child.name === "w:tab") children.push({ $type: "tab" });
23460
+ else children.push({
24889
23461
  $raw: true,
24890
23462
  element: child
24891
23463
  });
@@ -25509,7 +24081,7 @@ function convertParagraphChild(child) {
25509
24081
  case "pageBreak": return new PageBreak();
25510
24082
  case "lineBreak": return new ColumnBreak();
25511
24083
  case "columnBreak": return new ColumnBreak();
25512
- case "tab": return new Tab();
24084
+ case "tab": return new Run({ children: [new Tab()] });
25513
24085
  case "bookmark": return new RawPassthrough(child.element);
25514
24086
  case "sdtRun": return convertSdtRun(child);
25515
24087
  case "math": return new RawPassthrough(child.element);
@@ -25518,11 +24090,16 @@ function convertParagraphChild(child) {
25518
24090
  }
25519
24091
  }
25520
24092
  function convertParagraph(json) {
25521
- const { children, text, ...rest } = json;
24093
+ const { children, text, tabs, ...rest } = json;
25522
24094
  const runs = children ? toParagraphChildren(children) : text ? [new Run({ text })] : void 0;
25523
24095
  return new Paragraph({
25524
24096
  ...rest,
25525
- children: runs
24097
+ children: runs,
24098
+ ...tabs ? { tabStops: tabs.map((t) => ({
24099
+ position: t.pos,
24100
+ ...t.align ? { type: t.align } : {},
24101
+ ...t.leader ? { leader: t.leader } : {}
24102
+ })) } : {}
25526
24103
  });
25527
24104
  }
25528
24105
  function convertRun(json) {