@office-open/core 0.6.9 → 0.6.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,9 +1,9 @@
1
- import { _ as EMPTY_OBJECT, a as BuilderElement, b as BaseXmlComponent, c as buildAttrObject, d as numberValObj, f as onOffObj, g as wrapEl, h as stringValObj, i as convertToXmlComponent, l as chartAttr, m as stringEnumValObj, n as ImportedRootElementAttributes, o as EmptyElement, p as stringContainerObj, r as ImportedXmlComponent, s as attrObj, t as InitializableXmlComponent, u as hpsMeasureObj, v as IgnoreIfEmptyXmlComponent, y as XmlComponent } from "./xml-components-BWnF8xox.mjs";
2
- import { ThemeColor, ThemeFont, dateTimeValue, decimalNumber, eighthPointMeasureValue, hexBinary, hexColorValue, hpsMeasureValue, longHexNumber, measurementOrPercentValue, percentageValue, pointMeasureValue, positiveUniversalMeasureValue, shortHexNumber, signedHpsMeasureValue, signedTwipsMeasureValue, twipsMeasureValue, uCharHexNumber, universalMeasureValue, unsignedDecimalNumber } from "./values.mjs";
3
- import { $ as xsdCompoundLine, A as LineJoin, At as hashedId, B as createNoFill, Bt as convertPixelsToEmu, C as createOuterShadowEffect, Ct as createSchemeColor, D as createFillOverlayEffect, Dt as createPresetColor, E as BlendMode, Et as PresetColor, F as LineEndType, Ft as convertEmuToPixels, G as PathShadeType, H as extractBlipFillMedia, I as LineEndWidth, It as convertEmuToPoints, J as createGradientStop, K as TileFlipMode, L as createLineEnd, Lt as convertInchesToEmu, M as PresetDash, Mt as uniqueNumericIdCreator, N as createOutline, Nt as uniqueUuid, O as CompoundLine, Ot as createHslColor, P as LineEndLength, Pt as convertEmuToInches, Q as xsdBlendMode, R as createCustomDash, Rt as convertInchesToTwip, S as RectAlignment, St as SchemeColor, T as createGlowEffect, Tt as createRgbColor, U as PresetPattern, V as buildFill, Vt as convertPointsToEmu, W as createPatternFill, X as createTileInfo, Y as TileAlignment, Z as invertMap, _ as createEffectList, _t as createBlipEffects, a as createBlip, at as xsdPattern, b as PresetShadowVal, bt as SystemColor, c as PresetGeometry, ct as xsdRectAlignment, d as createShape3D, dt as xsdTextAnchor, et as xsdEffectContainer, f as BevelPresetType, ft as xsdTextCaps, g as createEffectDag, gt as createSourceRectangle, h as createScene3D, ht as Stretch, i as createBlipFill, it as xsdPathFillMode, j as PenAlignment, jt as uniqueId, k as LineCap, kt as createColorTransforms, l as createAdjustmentValues, lt as xsdStrikeStyle, m as createBottomBevel, mt as xsdVerticalMergeRev, n as createGroupTransform2D, nt as xsdLineEndSize, o as createExtentionList, ot as xsdPenAlignment, p as createBevel, pt as xsdUnderlineStyle, q as createGradientFill, r as createTransform2D, rt as xsdMaterialType, s as createCustomGeometry, st as xsdPresetShadow, t as createTransformation, tt as xsdLineCap, u as PresetMaterialType, ut as xsdTextAlign, v as createSoftEdgeEffect, vt as createColorElement, w as createInnerShadowEffect, wt as createScRgbColor, x as createPresetShadowEffect, xt as createSystemColor, y as createReflectionEffect, yt as createSolidFill, z as createGroupFill, zt as convertMillimetersToTwip } from "./drawingml-B_cFnIfw.mjs";
4
- import { a as DataModel, c as getColorXml, d as COLOR_CATEGORIES, f as LAYOUT_CATEGORIES, i as TransPoint, l as getLayoutXml, n as SmartArtCollection, o as Connection, p as STYLE_CATEGORIES, r as Point, s as DEFAULT_DRAWING_XML, t as createDataModel, u as getStyleXml } from "./smartart-3Aw0Aho1.mjs";
5
- import { a as ScatterChart, c as BarChart, d as createStrRef, f as CatAx, i as createChartType, l as AreaChart, n as ChartSpace, o as PieChart, p as ValAx, r as ChartTitle, s as LineChart, t as ChartCollection, u as createNumRef } from "./chart-BjBXDvRe.mjs";
6
- import { a as createTraverser, c as TokenNotFoundError, d as getFirstLevelElements, f as patchSpaceAttribute, h as PPTX_NS, i as createReplacer, l as createSplitInject, m as DOCX_NS, n as getNextRelationshipIndex, o as createRunRenderer, p as toJson, r as appendContentType, s as createTokenReplacer, t as appendRelationship, u as createTextElementContents } from "./patch-DCGadPUU.mjs";
1
+ import { _ as EMPTY_OBJECT, a as BuilderElement, b as BaseXmlComponent, c as buildAttrObject, d as numberValObj, f as onOffObj, g as wrapEl, h as stringValObj, i as convertToXmlComponent, l as chartAttr, m as stringEnumValObj, n as ImportedRootElementAttributes, o as EmptyElement, p as stringContainerObj, r as ImportedXmlComponent, s as attrObj, t as InitializableXmlComponent, u as hpsMeasureObj, v as IgnoreIfEmptyXmlComponent, y as XmlComponent } from "./xml-components-xJkfJ6ff.mjs";
2
+ import { _ as twipsMeasureValue, a as eighthPointMeasureValue, b as unsignedDecimalNumber, c as hpsMeasureValue, d as percentageValue, f as pointMeasureValue, g as signedTwipsMeasureValue, h as signedHpsMeasureValue, i as decimalNumber, l as longHexNumber, m as shortHexNumber, n as ThemeFont, o as hexBinary, p as positiveUniversalMeasureValue, r as dateTimeValue, s as hexColorValue, t as ThemeColor, u as measurementOrPercentValue, v as uCharHexNumber, y as universalMeasureValue } from "./values-zMCu5EoQ.mjs";
3
+ import { $ as xsdCompoundLine, A as LineJoin, At as hashedId, B as createNoFill, Bt as convertPixelsToEmu, C as createOuterShadowEffect, Ct as createSchemeColor, D as createFillOverlayEffect, Dt as createPresetColor, E as BlendMode, Et as PresetColor, F as LineEndType, Ft as convertEmuToPixels, G as PathShadeType, H as extractBlipFillMedia, I as LineEndWidth, It as convertEmuToPoints, J as createGradientStop, K as TileFlipMode, L as createLineEnd, Lt as convertInchesToEmu, M as PresetDash, Mt as uniqueNumericIdCreator, N as createOutline, Nt as uniqueUuid, O as CompoundLine, Ot as createHslColor, P as LineEndLength, Pt as convertEmuToInches, Q as xsdBlendMode, R as createCustomDash, Rt as convertInchesToTwip, S as RectAlignment, St as SchemeColor, T as createGlowEffect, Tt as createRgbColor, U as PresetPattern, V as buildFill, Vt as convertPointsToEmu, W as createPatternFill, X as createTileInfo, Y as TileAlignment, Z as invertMap, _ as createEffectList, _t as createBlipEffects, a as createBlip, at as xsdPattern, b as PresetShadowVal, bt as SystemColor, c as PresetGeometry, ct as xsdRectAlignment, d as createShape3D, dt as xsdTextAnchor, et as xsdEffectContainer, f as BevelPresetType, ft as xsdTextCaps, g as createEffectDag, gt as createSourceRectangle, h as createScene3D, ht as Stretch, i as createBlipFill, it as xsdPathFillMode, j as PenAlignment, jt as uniqueId, k as LineCap, kt as createColorTransforms, l as createAdjustmentValues, lt as xsdStrikeStyle, m as createBottomBevel, mt as xsdVerticalMergeRev, n as createGroupTransform2D, nt as xsdLineEndSize, o as createExtentionList, ot as xsdPenAlignment, p as createBevel, pt as xsdUnderlineStyle, q as createGradientFill, r as createTransform2D, rt as xsdMaterialType, s as createCustomGeometry, st as xsdPresetShadow, t as createTransformation, tt as xsdLineCap, u as PresetMaterialType, ut as xsdTextAlign, v as createSoftEdgeEffect, vt as createColorElement, w as createInnerShadowEffect, wt as createScRgbColor, x as createPresetShadowEffect, xt as createSystemColor, y as createReflectionEffect, yt as createSolidFill, z as createGroupFill, zt as convertMillimetersToTwip } from "./drawingml-DQlhouyh.mjs";
4
+ import { a as DataModel, c as getColorXml, d as COLOR_CATEGORIES, f as LAYOUT_CATEGORIES, i as TransPoint, l as getLayoutXml, n as SmartArtCollection, o as Connection, p as STYLE_CATEGORIES, r as Point, s as DEFAULT_DRAWING_XML, t as createDataModel, u as getStyleXml } from "./smartart-Cx1qa6k_.mjs";
5
+ import { a as ScatterChart, c as BarChart, d as createStrRef, f as CatAx, i as createChartType, l as AreaChart, n as ChartSpace, o as PieChart, p as ValAx, r as ChartTitle, s as LineChart, t as ChartCollection, u as createNumRef } from "./chart-dfAcyzCL.mjs";
6
+ import { a as createTraverser, c as TokenNotFoundError, d as getFirstLevelElements, f as patchSpaceAttribute, h as PPTX_NS, i as createReplacer, l as createSplitInject, m as DOCX_NS, n as getNextRelationshipIndex, o as createRunRenderer, p as toJson, r as appendContentType, s as createTokenReplacer, t as appendRelationship, u as createTextElementContents } from "./patch-ilNZTQmG.mjs";
7
7
  import { escapeXml, js2xml, textOf, xml2js } from "@office-open/xml";
8
8
  import { AsyncZipDeflate, Zip, ZipPassThrough, strFromU8, strFromU8 as strFromU8$1, strToU8, unzipSync, unzipSync as unzipSync$1, zip, zipSync } from "fflate";
9
9
  //#region src/output-type.ts
@@ -23,7 +23,7 @@ const convertOutput = (data, type, mimeType = OoxmlMimeType.DOCX) => {
23
23
  case "blob": return new Blob([data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength)], { type: mimeType });
24
24
  case "arraybuffer": return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
25
25
  case "uint8array": return data;
26
- case "base64": return btoa(strFromU8$1(data, true));
26
+ case "base64": return typeof Buffer !== "undefined" ? Buffer.from(data).toString("base64") : btoa(strFromU8$1(data, true));
27
27
  case "string":
28
28
  case "text":
29
29
  case "binarystring": return strFromU8$1(data, true);
@@ -32,15 +32,194 @@ const convertOutput = (data, type, mimeType = OoxmlMimeType.DOCX) => {
32
32
  }
33
33
  };
34
34
  //#endregion
35
+ //#region src/zip-native.ts
36
+ const CRC_TABLE = new Int32Array(256);
37
+ for (let i = 0; i < 256; i++) {
38
+ let c = i;
39
+ for (let k = 0; k < 8; k++) c = c & 1 ? c >>> 1 ^ -306674912 : c >>> 1;
40
+ CRC_TABLE[i] = c;
41
+ }
42
+ function computeCrc32(data) {
43
+ let crc = -1;
44
+ for (let i = 0; i < data.length; i++) crc = CRC_TABLE[(crc ^ data[i]) & 255] ^ crc >>> 8;
45
+ return ~crc;
46
+ }
47
+ let _nativeDeflate;
48
+ let _nativeDeflateAsync;
49
+ let _nativeCrc32;
50
+ try {
51
+ const zlib = await import("node:zlib");
52
+ _nativeDeflate = (data, level) => zlib.deflateRawSync(data, { level });
53
+ _nativeDeflateAsync = (data, level) => new Promise((resolve, reject) => zlib.deflateRaw(data, { level }, (err, result) => {
54
+ if (err) reject(err);
55
+ else resolve(result);
56
+ }));
57
+ _nativeCrc32 = zlib.crc32 ? (data) => zlib.crc32(data) : computeCrc32;
58
+ } catch {}
59
+ const hasNativeDeflate = () => _nativeDeflate !== void 0;
60
+ function wU16(b, o, v) {
61
+ b[o] = v & 255;
62
+ b[o + 1] = v >> 8 & 255;
63
+ }
64
+ function wU32(b, o, v) {
65
+ b[o] = v & 255;
66
+ b[o + 1] = v >> 8 & 255;
67
+ b[o + 2] = v >> 16 & 255;
68
+ b[o + 3] = v >> 24 & 255;
69
+ }
70
+ function resolveEntryData(raw, defaultLevel) {
71
+ if (Array.isArray(raw)) return {
72
+ data: raw[0],
73
+ level: raw[1].level ?? defaultLevel
74
+ };
75
+ return {
76
+ data: raw,
77
+ level: defaultLevel
78
+ };
79
+ }
80
+ function compressOne(data, level, method, deflate) {
81
+ if (level === 0) return {
82
+ compressed: data,
83
+ method: 0
84
+ };
85
+ const compressed = deflate(data, level);
86
+ if (compressed.length >= data.length) return {
87
+ compressed: data,
88
+ method: 0
89
+ };
90
+ return {
91
+ compressed,
92
+ method: 8
93
+ };
94
+ }
95
+ async function compressOneAsync(data, level, deflate) {
96
+ if (level === 0) return {
97
+ compressed: data,
98
+ method: 0
99
+ };
100
+ const compressed = await deflate(data, level);
101
+ if (compressed.length >= data.length) return {
102
+ compressed: data,
103
+ method: 0
104
+ };
105
+ return {
106
+ compressed,
107
+ method: 8
108
+ };
109
+ }
110
+ function writeZipBuffer(entries) {
111
+ let totalSize = 0;
112
+ for (let i = 0; i < entries.length; i++) totalSize += 30 + entries[i].filename.length + entries[i].data.length;
113
+ const cdOffset = totalSize;
114
+ let cdSize = 0;
115
+ for (let i = 0; i < entries.length; i++) cdSize += 46 + entries[i].filename.length;
116
+ totalSize += cdSize + 22;
117
+ const buf = new Uint8Array(totalSize);
118
+ let offset = 0;
119
+ for (let i = 0; i < entries.length; i++) {
120
+ const e = entries[i];
121
+ e.localOffset = offset;
122
+ wU32(buf, offset, 67324752);
123
+ wU16(buf, offset + 4, 20);
124
+ wU16(buf, offset + 6, 0);
125
+ wU16(buf, offset + 8, e.method);
126
+ wU16(buf, offset + 10, 0);
127
+ wU16(buf, offset + 12, 0);
128
+ wU32(buf, offset + 14, e.crc);
129
+ wU32(buf, offset + 18, e.data.length);
130
+ wU32(buf, offset + 22, e.uncompressedSize);
131
+ wU16(buf, offset + 26, e.filename.length);
132
+ wU16(buf, offset + 28, 0);
133
+ offset += 30;
134
+ buf.set(e.filename, offset);
135
+ offset += e.filename.length;
136
+ buf.set(e.data, offset);
137
+ offset += e.data.length;
138
+ }
139
+ for (let i = 0; i < entries.length; i++) {
140
+ const e = entries[i];
141
+ wU32(buf, offset, 33639248);
142
+ wU16(buf, offset + 4, 20);
143
+ wU16(buf, offset + 6, 20);
144
+ wU16(buf, offset + 8, 0);
145
+ wU16(buf, offset + 10, e.method);
146
+ wU16(buf, offset + 12, 0);
147
+ wU16(buf, offset + 14, 0);
148
+ wU32(buf, offset + 16, e.crc);
149
+ wU32(buf, offset + 20, e.data.length);
150
+ wU32(buf, offset + 24, e.uncompressedSize);
151
+ wU16(buf, offset + 28, e.filename.length);
152
+ wU16(buf, offset + 30, 0);
153
+ wU16(buf, offset + 32, 0);
154
+ wU16(buf, offset + 34, 0);
155
+ wU16(buf, offset + 36, 0);
156
+ wU32(buf, offset + 38, 0);
157
+ wU32(buf, offset + 42, e.localOffset);
158
+ offset += 46;
159
+ buf.set(e.filename, offset);
160
+ offset += e.filename.length;
161
+ }
162
+ wU32(buf, offset, 101010256);
163
+ wU16(buf, offset + 4, 0);
164
+ wU16(buf, offset + 6, 0);
165
+ wU16(buf, offset + 8, entries.length);
166
+ wU16(buf, offset + 10, entries.length);
167
+ wU32(buf, offset + 12, cdSize);
168
+ wU32(buf, offset + 16, cdOffset);
169
+ wU16(buf, offset + 20, 0);
170
+ return buf;
171
+ }
172
+ const textEncoder = new TextEncoder();
173
+ function nativeZip(files, level = 6) {
174
+ if (!_nativeDeflate) throw new Error("Native deflate not available");
175
+ const crc = _nativeCrc32 ?? computeCrc32;
176
+ const keys = Object.keys(files);
177
+ const entries = Array.from({ length: keys.length });
178
+ for (let i = 0; i < keys.length; i++) {
179
+ const { data, level: entryLevel } = resolveEntryData(files[keys[i]], level);
180
+ const c = crc(data);
181
+ const { compressed, method } = compressOne(data, entryLevel, 8, _nativeDeflate);
182
+ entries[i] = {
183
+ filename: textEncoder.encode(keys[i]),
184
+ data: compressed,
185
+ uncompressedSize: data.length,
186
+ crc: c,
187
+ method,
188
+ localOffset: 0
189
+ };
190
+ }
191
+ return writeZipBuffer(entries);
192
+ }
193
+ async function nativeZipAsync(files, level = 6) {
194
+ if (!_nativeDeflateAsync) throw new Error("Native async deflate not available");
195
+ const crc = _nativeCrc32 ?? computeCrc32;
196
+ const keys = Object.keys(files);
197
+ const entries = Array.from({ length: keys.length });
198
+ for (let i = 0; i < keys.length; i++) {
199
+ const { data, level: entryLevel } = resolveEntryData(files[keys[i]], level);
200
+ const c = crc(data);
201
+ const { compressed, method } = await compressOneAsync(data, entryLevel, _nativeDeflateAsync);
202
+ entries[i] = {
203
+ filename: textEncoder.encode(keys[i]),
204
+ data: compressed,
205
+ uncompressedSize: data.length,
206
+ crc: c,
207
+ method,
208
+ localOffset: 0
209
+ };
210
+ }
211
+ return writeZipBuffer(entries);
212
+ }
213
+ //#endregion
35
214
  //#region src/packer.ts
36
215
  /**
37
216
  * Shared packer utilities for OOXML document generation.
38
217
  *
39
218
  * @module
40
219
  */
41
- /** Default DEFLATE compression level matching Microsoft Office behavior. */
42
- const ZIP_DEFLATE_LEVEL = 6;
43
- /** STORE level for already-compressed media formats (JPEG, PNG, GIF, etc.). */
220
+ /** Default DEFLATE level for XML entries (SuperFast, matching MS Office). */
221
+ const ZIP_DEFLATE_LEVEL = 1;
222
+ /** Default level for media entries (STORE no compression). */
44
223
  const ZIP_STORED_LEVEL = 0;
45
224
  /**
46
225
  * Asynchronously compress files and convert to the requested output format.
@@ -49,8 +228,8 @@ const ZIP_STORED_LEVEL = 0;
49
228
  * XML entries use DEFLATE by default; media entries should explicitly set
50
229
  * `{ level: ZIP_STORED_LEVEL }` to avoid redundant compression.
51
230
  */
52
- const zipAndConvert = async (files, type, mimeType, level = 6) => {
53
- return convertOutput(await new Promise((resolve, reject) => {
231
+ const zipAndConvert = async (files, type, mimeType, level = 1) => {
232
+ return convertOutput(hasNativeDeflate() ? await nativeZipAsync(files, level) : await new Promise((resolve, reject) => {
54
233
  zip(files, {
55
234
  level,
56
235
  consume: true
@@ -66,8 +245,8 @@ const zipAndConvert = async (files, type, mimeType, level = 6) => {
66
245
  * Uses synchronous DEFLATE compression for maximum throughput.
67
246
  * Blocks the event loop — prefer {@link zipAndConvert} in server contexts.
68
247
  */
69
- const zipSyncAndConvert = (files, type, mimeType, level = 6) => {
70
- return convertOutput(zipSync(files, { level }), type, mimeType);
248
+ const zipSyncAndConvert = (files, type, mimeType, level = 1) => {
249
+ return convertOutput(hasNativeDeflate() ? nativeZip(files, level) : zipSync(files, { level }), type, mimeType);
71
250
  };
72
251
  /**
73
252
  * Create a `ReadableStream<Uint8Array>` from compressed file entries.
@@ -76,7 +255,7 @@ const zipSyncAndConvert = (files, type, mimeType, level = 6) => {
76
255
  * `STORED` entries (media) pass through synchronously.
77
256
  * Works in both Node.js and browsers (Web Streams API).
78
257
  */
79
- const createZipStream = (files) => {
258
+ const createZipStream = (files, defaultLevel = 1) => {
80
259
  return new ReadableStream({ start(controller) {
81
260
  try {
82
261
  const zip = new Zip((err, chunk, _final) => {
@@ -89,7 +268,7 @@ const createZipStream = (files) => {
89
268
  });
90
269
  for (const [name, data] of Object.entries(files)) {
91
270
  const raw = Array.isArray(data) ? data[0] : data;
92
- const level = Array.isArray(data) ? data[1].level ?? 6 : 6;
271
+ const level = Array.isArray(data) ? data[1].level ?? defaultLevel : defaultLevel;
93
272
  const entry = level === 0 ? new ZipPassThrough(name) : new AsyncZipDeflate(name, { level });
94
273
  zip.add(entry);
95
274
  entry.push(raw, true);
@@ -109,35 +288,35 @@ const createZipStream = (files) => {
109
288
  */
110
289
  const createPacker = (options) => {
111
290
  const { compile, mimeType } = options;
112
- const compileFiles = (file, overrides = []) => compile(file, overrides);
113
- const pack = async (file, type, overrides) => {
114
- return zipAndConvert(compileFiles(file, overrides), type, mimeType);
291
+ const pack = async (file, type, opts) => {
292
+ return zipAndConvert(compile(file, opts?.overrides ?? [], opts?.compression?.media ?? 0), type, mimeType, opts?.compression?.xml ?? 1);
115
293
  };
116
- const toBytes = (file, overrides) => pack(file, "uint8array", overrides);
117
- const toString = (file, overrides) => pack(file, "string", overrides);
118
- const toBuffer = (file, overrides) => pack(file, "nodebuffer", overrides);
119
- const toBase64String = (file, overrides) => pack(file, "base64", overrides);
120
- const toBlob = (file, overrides) => pack(file, "blob", overrides);
121
- const toArrayBuffer = (file, overrides) => pack(file, "arraybuffer", overrides);
122
- const packSync = (file, type, overrides) => {
123
- return zipSyncAndConvert(compileFiles(file, overrides), type, mimeType);
294
+ const toBytes = (file, opts) => pack(file, "uint8array", opts);
295
+ const toString = (file, opts) => pack(file, "string", opts);
296
+ const toBuffer = (file, opts) => pack(file, "nodebuffer", opts);
297
+ const toBase64String = (file, opts) => pack(file, "base64", opts);
298
+ const toBlob = (file, opts) => pack(file, "blob", opts);
299
+ const toArrayBuffer = (file, opts) => pack(file, "arraybuffer", opts);
300
+ const packSync = (file, type, opts) => {
301
+ return zipSyncAndConvert(compile(file, opts?.overrides ?? [], opts?.compression?.media ?? 0), type, mimeType, opts?.compression?.xml ?? 1);
124
302
  };
125
- const toBytesSync = (file, overrides) => packSync(file, "uint8array", overrides);
126
- const toStringSync = (file, overrides) => packSync(file, "string", overrides);
127
- const toBufferSync = (file, overrides) => packSync(file, "nodebuffer", overrides);
128
- const toBase64StringSync = (file, overrides) => packSync(file, "base64", overrides);
129
- const toBlobSync = (file, overrides) => packSync(file, "blob", overrides);
130
- const toArrayBufferSync = (file, overrides) => packSync(file, "arraybuffer", overrides);
131
- const toStream = (file, overrides) => {
303
+ const toBytesSync = (file, opts) => packSync(file, "uint8array", opts);
304
+ const toStringSync = (file, opts) => packSync(file, "string", opts);
305
+ const toBufferSync = (file, opts) => packSync(file, "nodebuffer", opts);
306
+ const toBase64StringSync = (file, opts) => packSync(file, "base64", opts);
307
+ const toBlobSync = (file, opts) => packSync(file, "blob", opts);
308
+ const toArrayBufferSync = (file, opts) => packSync(file, "arraybuffer", opts);
309
+ const toStream = (file, opts) => {
310
+ const mediaLevel = opts?.compression?.media ?? 0;
132
311
  let files;
133
312
  try {
134
- files = compileFiles(file, overrides);
313
+ files = compile(file, opts?.overrides ?? [], mediaLevel);
135
314
  } catch (err) {
136
315
  return new ReadableStream({ start(controller) {
137
316
  controller.error(err instanceof Error ? err : new Error(String(err)));
138
317
  } });
139
318
  }
140
- return createZipStream(files);
319
+ return createZipStream(files, opts?.compression?.xml ?? 1);
141
320
  };
142
321
  return {
143
322
  compile,
@@ -452,7 +631,7 @@ var ParsedArchive = class {
452
631
  return zipSync(files);
453
632
  }
454
633
  };
455
- /** Set of already-compressed media file extensions (lowercase, with dot prefix). */
634
+ /** Media file extensions that should use STORE (no compression). */
456
635
  const MEDIA_EXTENSIONS = new Set([
457
636
  ".png",
458
637
  ".jpg",
@@ -580,8 +759,6 @@ function addSmartArtRelationships(keys, addRel, baseOffset, globalStartIndex, op
580
759
  }
581
760
  //#endregion
582
761
  //#region src/compiler-utils.ts
583
- /** Default STORE level for already-compressed media formats. */
584
- const ZIP_STORED_LEVEL$1 = 0;
585
762
  /** Reusable TextEncoder instance (stateless, safe to share). */
586
763
  const encoder = new TextEncoder();
587
764
  /**
@@ -589,11 +766,11 @@ const encoder = new TextEncoder();
589
766
  *
590
767
  * Centralises the mapping→Zippable conversion shared by all three compilers.
591
768
  */
592
- function compileMapping(mapping, overrides, media) {
769
+ function compileMapping(mapping, overrides, media, mediaLevel = 0) {
593
770
  const files = {};
594
771
  for (const entry of Object.values(mapping)) files[entry.path] = encoder.encode(entry.data);
595
772
  if (overrides) for (const o of overrides) files[o.path] = typeof o.data === "string" ? encoder.encode(o.data) : o.data;
596
- if (media) for (const m of media) files[m.path] = [m.data, { level: ZIP_STORED_LEVEL$1 }];
773
+ if (media) for (const m of media) files[m.path] = [m.data, { level: mediaLevel }];
597
774
  return files;
598
775
  }
599
776
  //#endregion
@@ -1,2 +1,2 @@
1
- import { a as createTraverser, c as TokenNotFoundError, d as getFirstLevelElements, f as patchSpaceAttribute, h as PPTX_NS, i as createReplacer, l as createSplitInject, m as DOCX_NS, n as getNextRelationshipIndex, o as createRunRenderer, p as toJson, r as appendContentType, s as createTokenReplacer, t as appendRelationship, u as createTextElementContents } from "../patch-DCGadPUU.mjs";
1
+ import { a as createTraverser, c as TokenNotFoundError, d as getFirstLevelElements, f as patchSpaceAttribute, h as PPTX_NS, i as createReplacer, l as createSplitInject, m as DOCX_NS, n as getNextRelationshipIndex, o as createRunRenderer, p as toJson, r as appendContentType, s as createTokenReplacer, t as appendRelationship, u as createTextElementContents } from "../patch-ilNZTQmG.mjs";
2
2
  export { DOCX_NS, PPTX_NS, TokenNotFoundError, appendContentType, appendRelationship, createReplacer, createRunRenderer, createSplitInject, createTextElementContents, createTokenReplacer, createTraverser, getFirstLevelElements, getNextRelationshipIndex, patchSpaceAttribute, toJson };
@@ -218,11 +218,18 @@ function createTraverser(ns) {
218
218
  const renderedParagraphs = [];
219
219
  const queue = [];
220
220
  const rootChildren = node.elements;
221
- if (rootChildren) for (let i = 0; i < rootChildren.length; i++) queue.push({
222
- element: rootChildren[i],
223
- index: i,
224
- parent: void 0
225
- });
221
+ if (rootChildren) {
222
+ const root = {
223
+ element: node,
224
+ index: 0,
225
+ parent: void 0
226
+ };
227
+ for (let i = 0; i < rootChildren.length; i++) queue.push({
228
+ element: rootChildren[i],
229
+ index: i,
230
+ parent: root
231
+ });
232
+ }
226
233
  let qi = 0;
227
234
  while (qi < queue.length) {
228
235
  const current = queue[qi++];
@@ -1,2 +1,2 @@
1
- import { a as Point, c as Connection, d as getLayoutXml, f as getStyleXml, h as STYLE_CATEGORIES, i as SmartArtData, l as DEFAULT_DRAWING_XML, m as LAYOUT_CATEGORIES, n as createDataModel, o as TransPoint, p as COLOR_CATEGORIES, r as SmartArtCollection, s as DataModel, t as TreeNode, u as getColorXml } from "../index-BD7Tgfi4.mjs";
1
+ import { a as Point, c as Connection, d as getLayoutXml, f as getStyleXml, h as STYLE_CATEGORIES, i as SmartArtData, l as DEFAULT_DRAWING_XML, m as LAYOUT_CATEGORIES, n as createDataModel, o as TransPoint, p as COLOR_CATEGORIES, r as SmartArtCollection, s as DataModel, t as TreeNode, u as getColorXml } from "../index-f_Izh2dj.mjs";
2
2
  export { COLOR_CATEGORIES, Connection, DEFAULT_DRAWING_XML, DataModel, LAYOUT_CATEGORIES, Point, STYLE_CATEGORIES, SmartArtCollection, SmartArtData, TransPoint, TreeNode, createDataModel, getColorXml, getLayoutXml, getStyleXml };
@@ -1,2 +1,2 @@
1
- import { a as DataModel, c as getColorXml, d as COLOR_CATEGORIES, f as LAYOUT_CATEGORIES, i as TransPoint, l as getLayoutXml, n as SmartArtCollection, o as Connection, p as STYLE_CATEGORIES, r as Point, s as DEFAULT_DRAWING_XML, t as createDataModel, u as getStyleXml } from "../smartart-3Aw0Aho1.mjs";
1
+ import { a as DataModel, c as getColorXml, d as COLOR_CATEGORIES, f as LAYOUT_CATEGORIES, i as TransPoint, l as getLayoutXml, n as SmartArtCollection, o as Connection, p as STYLE_CATEGORIES, r as Point, s as DEFAULT_DRAWING_XML, t as createDataModel, u as getStyleXml } from "../smartart-Cx1qa6k_.mjs";
2
2
  export { COLOR_CATEGORIES, Connection, DEFAULT_DRAWING_XML, DataModel, LAYOUT_CATEGORIES, Point, STYLE_CATEGORIES, SmartArtCollection, TransPoint, createDataModel, getColorXml, getLayoutXml, getStyleXml };
@@ -1,4 +1,4 @@
1
- import { l as chartAttr, y as XmlComponent } from "./xml-components-BWnF8xox.mjs";
1
+ import { l as chartAttr, y as XmlComponent } from "./xml-components-xJkfJ6ff.mjs";
2
2
  //#region src/smartart/categories.ts
3
3
  /** Layout ID → OOXML category type */
4
4
  const LAYOUT_CATEGORIES = {