@office-open/docx 0.10.0 → 0.10.1

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.
@@ -1,4 +1,4 @@
1
- import { F as collectDefaultOverrideIds, M as extractStyleId, P as DefaultStylesFactory, X as Numbering, ht as FontWrapper, k as Styles, wn as Media } from "./parts-BWmkYaBr.mjs";
1
+ import { I as DefaultStylesFactory, P as extractStyleId, Pn as Media, R as collectDefaultOverrideIds, Tt as FontWrapper, j as Styles, rt as Numbering } from "./parts-DVpfsxSR.mjs";
2
2
  import { Relationships } from "@office-open/core";
3
3
  import { js2xml, xml2js } from "@office-open/xml";
4
4
  import { ChartCollection } from "@office-open/core/chart";
@@ -78,6 +78,29 @@ var ExternalStylesFactory = class {
78
78
  }
79
79
  };
80
80
  //#endregion
81
+ //#region src/shared/embeddings/embeddings.ts
82
+ /**
83
+ * Collects OLE embeddings allocated during document generation. Each embedding
84
+ * is stored under a sequential `oleObjectN.bin` name in word/embeddings/,
85
+ * mirroring MS Office's numbering so output is deterministic and diffable.
86
+ */
87
+ var EmbeddingCollection = class {
88
+ map = /* @__PURE__ */ new Map();
89
+ counter = 0;
90
+ /** Allocate the next sequential embedding file name (oleObject1.bin, …). */
91
+ nextEmbeddingName() {
92
+ return `oleObject${++this.counter}.bin`;
93
+ }
94
+ /** Register an embedding under a unique key. */
95
+ addEmbedding(key, data) {
96
+ this.map.set(key, data);
97
+ }
98
+ /** All registered embeddings in insertion order. */
99
+ get array() {
100
+ return [...this.map.values()];
101
+ }
102
+ };
103
+ //#endregion
81
104
  //#region src/context.ts
82
105
  /**
83
106
  * DOCX compilation context.
@@ -145,6 +168,7 @@ var DocxWriteContext = class {
145
168
  this.media = new Media();
146
169
  this.charts = new ChartCollection();
147
170
  this.smartArts = new SmartArtCollection();
171
+ this.embeddings = new EmbeddingCollection();
148
172
  this.altChunks = new AltChunkCollection();
149
173
  this.subDocs = new SubDocCollection();
150
174
  if (options.externalStyles !== void 0) {
@@ -165,7 +189,7 @@ var DocxWriteContext = class {
165
189
  });
166
190
  } else if (options.styles) {
167
191
  const defaultStyles = new DefaultStylesFactory().newInstance(options.styles.default);
168
- const { importedStyles: parsedStyles, paragraphStyles, characterStyles, ...restStyles } = options.styles;
192
+ const { importedStyles: parsedStyles, paragraphStyles, characterStyles, tableStyles, ...restStyles } = options.styles;
169
193
  const merged = defaultStyles.importedStyles ? [...defaultStyles.importedStyles] : [];
170
194
  if (restStyles.docDefaultsXml) {
171
195
  const ddIdx = merged.findIndex((s) => s._raw.startsWith("<w:docDefaults"));
@@ -203,6 +227,7 @@ var DocxWriteContext = class {
203
227
  ...defaultStyles,
204
228
  paragraphStyles,
205
229
  characterStyles,
230
+ tableStyles,
206
231
  ...restStyles
207
232
  });
208
233
  } else {
@@ -358,4 +383,4 @@ var DocxReadContext = class {
358
383
  //#endregion
359
384
  export { AltChunkCollection as i, DocxWriteContext as n, SubDocCollection as r, DocxReadContext as t };
360
385
 
361
- //# sourceMappingURL=context-D9RMvxSu.mjs.map
386
+ //# sourceMappingURL=context-C0vWotG5.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-C0vWotG5.mjs","names":[],"sources":["../src/parts/alt-chunk/alt-chunk-collection.ts","../src/parts/sub-doc/sub-doc-collection.ts","../src/parts/styles/external-styles-factory.ts","../src/shared/embeddings/embeddings.ts","../src/context.ts"],"sourcesContent":["/**\n * AltChunk collection module for managing alternative format content parts.\n *\n * @module\n */\n\n/**\n * Stores alternative format chunk data for later serialization by the compiler.\n */\nexport interface AltChunkData {\n /** Unique key for this alt chunk (e.g., relId) */\n key: string;\n /** Raw content data */\n data: Uint8Array;\n /** Part sub-path within word/ (e.g., \"afchunks/afchunk1.html\") */\n path: string;\n /** File extension (e.g., \"html\", \"rtf\", \"txt\") */\n extension: string;\n /** MIME content type (e.g., \"text/html\", \"application/rtf\") */\n contentType: string;\n}\n\n/**\n * Manages alternative format chunk parts in a document.\n *\n * Stores external content (HTML, RTF, plain text) that will be\n * serialized into separate parts in the DOCX package.\n */\nexport class AltChunkCollection {\n private map: Map<string, AltChunkData>;\n\n public constructor() {\n this.map = new Map<string, AltChunkData>();\n }\n\n public addAltChunk(key: string, data: AltChunkData): void {\n this.map.set(key, data);\n }\n\n public get array(): AltChunkData[] {\n return [...this.map.values()];\n }\n}\n","/**\n * Sub-document collection module for managing sub-document parts.\n *\n * @module\n */\n\n/**\n * Stores sub-document data for later serialization by the compiler.\n */\nexport interface SubDocData {\n /** Raw document data (.docx bytes) */\n data: Uint8Array;\n /** Part sub-path within word/ (e.g., \"subdocs/subdoc1.docx\") */\n path: string;\n}\n\n/**\n * Manages sub-document parts in a document.\n */\nexport class SubDocCollection {\n private map: Map<string, SubDocData>;\n\n public constructor() {\n this.map = new Map<string, SubDocData>();\n }\n\n public addSubDoc(key: string, data: SubDocData): void {\n this.map.set(key, data);\n }\n\n public get array(): SubDocData[] {\n return [...this.map.values()];\n }\n}\n","/**\n * External styles factory module for WordprocessingML documents.\n *\n * Parses styles from external XML and returns raw XML strings.\n * No XmlComponent dependency.\n *\n * Reference: http://officeopenxml.com/WPstyles.php\n *\n * @module\n */\nimport { js2xml, xml2js } from \"@office-open/xml\";\nimport type { Element as XMLElement } from \"@office-open/xml\";\n\nimport type { StylesOptions } from \"./styles\";\n\n/**\n * Factory for creating styles from external XML sources.\n *\n * Parses styles from XML (typically from a styles.xml file)\n * and returns raw XML strings for each style element.\n */\nexport class ExternalStylesFactory {\n /**\n * Creates new Styles based on the given XML data.\n *\n * Parses the styles XML and converts each child to a raw XML string.\n */\n public newInstance(xmlData: string): StylesOptions {\n const xmlObj = xml2js(xmlData, { compact: false }) as XMLElement;\n\n let stylesXmlElement: XMLElement | undefined;\n for (const xmlElm of xmlObj.elements || []) {\n if (xmlElm.name === \"w:styles\") {\n stylesXmlElement = xmlElm;\n }\n }\n\n if (stylesXmlElement === undefined) {\n return { importedStyles: [], initialAttributes: {} };\n }\n\n const stylesElements = stylesXmlElement.elements || [];\n\n return {\n importedStyles: stylesElements.map((childElm) => ({\n _raw: js2xml({ elements: [childElm] }),\n })),\n initialAttributes: (stylesXmlElement.attributes as Record<string, string>) ?? {},\n };\n }\n}\n","/**\n * Embeddings module for WordprocessingML documents.\n *\n * Manages OLE object embeddings (word/embeddings/oleObjectN.bin) referenced by\n * w:object elements. Mirrors the Media collection pattern but targets binary\n * OLE container parts instead of images.\n *\n * @module\n */\n\n/** OLE embedding data stored under word/embeddings/. */\nexport interface EmbeddingData {\n /** File name within word/embeddings/ (e.g. \"oleObject1.bin\"). */\n fileName: string;\n /** Raw OLE container bytes. */\n data: Uint8Array;\n /** OLE program id (e.g. \"Excel.Sheet.12\") — informational only. */\n progId?: string;\n}\n\n/**\n * Collects OLE embeddings allocated during document generation. Each embedding\n * is stored under a sequential `oleObjectN.bin` name in word/embeddings/,\n * mirroring MS Office's numbering so output is deterministic and diffable.\n */\nexport class EmbeddingCollection {\n private map = new Map<string, EmbeddingData>();\n private counter = 0;\n\n /** Allocate the next sequential embedding file name (oleObject1.bin, …). */\n public nextEmbeddingName(): string {\n return `oleObject${++this.counter}.bin`;\n }\n\n /** Register an embedding under a unique key. */\n public addEmbedding(key: string, data: EmbeddingData): void {\n this.map.set(key, data);\n }\n\n /** All registered embeddings in insertion order. */\n public get array(): EmbeddingData[] {\n return [...this.map.values()];\n }\n}\n","/**\n * DOCX compilation context.\n *\n * DocxWriteContext holds all mutable state needed during document compilation.\n * generateDocument() creates a DocxWriteContext internally.\n *\n * @module\n */\n\nimport { Relationships } from \"@office-open/core\";\nimport { ChartCollection } from \"@office-open/core/chart\";\nimport type { ReadContext, WriteContext } from \"@office-open/core/descriptor\";\nimport { SmartArtCollection } from \"@office-open/core/smartart\";\nimport type { Element } from \"@office-open/xml\";\nimport { AltChunkCollection } from \"@parts/alt-chunk/alt-chunk-collection\";\nimport type { DocumentOptions } from \"@parts/core-properties\";\nimport type { SectionPropertiesOptions } from \"@parts/document/body/section-properties/section-properties\";\nimport type { EndnoteSeparator } from \"@parts/endnotes/descriptor\";\nimport { FontWrapper } from \"@parts/fonts/font-wrapper\";\nimport type { FootnoteSeparator } from \"@parts/footnotes/descriptor\";\nimport type { GlossaryDocumentOptions } from \"@parts/glossary-document\";\nimport type { HeaderFooterEntry } from \"@parts/header-footer\";\nimport { Numbering } from \"@parts/numbering\";\nimport type { ParagraphOptions } from \"@parts/paragraph/paragraph\";\nimport type { SettingsOptions } from \"@parts/settings/settings\";\nimport { Styles, extractStyleId } from \"@parts/styles\";\nimport { ExternalStylesFactory } from \"@parts/styles/external-styles-factory\";\nimport { DefaultStylesFactory, collectDefaultOverrideIds } from \"@parts/styles/factory\";\nimport { SubDocCollection } from \"@parts/sub-doc/sub-doc-collection\";\nimport type { WebSettingsOptions } from \"@parts/web-settings\";\nimport { EmbeddingCollection } from \"@shared/embeddings/embeddings\";\nimport { Media } from \"@shared/media\";\nimport type { SectionOptions } from \"@shared/section\";\nimport type { SectionChild } from \"@shared/section\";\n\nimport type { DocxDocument } from \"./parse\";\n\n/** Interface for document view wrappers — provides relationships access. */\nexport interface ViewWrapper {\n relationships: Relationships;\n}\n\n// ── BodyContext ──\n\n/**\n * Context for body-level stringification.\n *\n * Pure JSON pipeline context — extends WriteContext for descriptor compatibility.\n * No dependency on XmlComponent Context (compile/ uses zero toXml calls).\n */\nexport interface BodyContext extends WriteContext {\n /** The root write context with all mutable document state. */\n fileData: DocxWriteContext;\n /** Alias for fileData — some descriptor internals access context.file. */\n file: DocxWriteContext;\n /** Current view wrapper for relationship access. */\n viewWrapper: { relationships: Relationships };\n /** Stringify a body-level child element — injected to break circular imports. */\n stringifyChild: (child: SectionChild, ctx: BodyContext) => string;\n}\n\n// ── DocxWriteContext ──\n\nexport class DocxWriteContext implements WriteContext {\n private _currentRelationshipId = 1;\n\n // --- Accessed by XmlComponent via context.file.* during toXml() ---\n declare public document: { relationships: Relationships };\n declare public numbering: Numbering;\n declare public media: Media;\n declare public charts: ChartCollection;\n declare public smartArts: SmartArtCollection;\n declare public embeddings: EmbeddingCollection;\n declare public altChunks: AltChunkCollection;\n declare public subDocs: SubDocCollection;\n declare public comments: { relationships: Relationships };\n declare public footNotes: {\n relationships: Relationships;\n notes: Map<number, (ParagraphOptions | string)[]>;\n separator?: FootnoteSeparator;\n continuationSeparator?: FootnoteSeparator;\n };\n declare public endnotes: {\n relationships: Relationships;\n notes: Map<number, (ParagraphOptions | string)[]>;\n separator?: EndnoteSeparator;\n continuationSeparator?: EndnoteSeparator;\n };\n\n // --- Additional state used by the compiler ---\n declare public fileRelationships: Relationships;\n declare public _settingsOptions: SettingsOptions;\n declare public styles: Styles;\n declare public fontTable: FontWrapper;\n declare public glossaryOptions: GlossaryDocumentOptions | undefined;\n declare public webSettings: WebSettingsOptions | undefined;\n\n // --- Section properties (one per section, raw options for descriptor pipeline) ---\n private _sectionProperties: SectionPropertiesOptions[] = [];\n public get sectionProperties(): readonly SectionPropertiesOptions[] {\n return this._sectionProperties;\n }\n\n // --- WriteContext interface (core descriptor pipeline) ---\n\n public addRelationship(_type: string, _target: string, _mode?: string): string {\n const id = this._currentRelationshipId++;\n return `rId${id}`;\n }\n\n public addMedia(_data: Uint8Array, _type: string): string {\n // DOCX media registration goes through Media.addImage() in compiler.\n return \"\";\n }\n\n // --- Internal tracking ---\n private _headers: HeaderFooterEntry[] = [];\n private _footers: HeaderFooterEntry[] = [];\n\n // --- Original input preserved for descriptor usage ---\n declare public _options: DocumentOptions;\n\n constructor(options: DocumentOptions) {\n this._options = options;\n\n this.numbering = new Numbering(options.numbering ? options.numbering : { config: [] });\n\n this.comments = { relationships: new Relationships() };\n this.fileRelationships = new Relationships();\n this.footNotes = { relationships: new Relationships(), notes: new Map() };\n this.endnotes = { relationships: new Relationships(), notes: new Map() };\n this.document = { relationships: new Relationships() };\n this._settingsOptions = {\n compatibility: options.compatibility,\n compatibilityModeVersion: options.compatabilityModeVersion,\n defaultTabStop: options.defaultTabStop,\n evenAndOddHeaders: options.evenAndOddHeaderAndFooters ? true : false,\n characterSpacingControl: options.characterSpacingControl,\n hyphenation: {\n autoHyphenation: options.hyphenation?.autoHyphenation,\n consecutiveHyphenLimit: options.hyphenation?.consecutiveHyphenLimit,\n doNotHyphenateCaps: options.hyphenation?.doNotHyphenateCaps,\n hyphenationZone: options.hyphenation?.hyphenationZone,\n },\n trackRevisions: options.features?.trackRevisions,\n updateFields: options.features?.updateFields,\n documentProtection: options.features?.documentProtection,\n view: options.view,\n zoom: options.zoom,\n writeProtection: options.writeProtection,\n displayBackgroundShape:\n options.displayBackgroundShape ?? (options.background?.image ? true : undefined),\n embedTrueTypeFonts: options.embedTrueTypeFonts,\n embedSystemFonts: options.embedSystemFonts,\n saveSubsetFonts: options.saveSubsetFonts,\n docVars: options.docVars,\n colorSchemeMapping: options.colorSchemeMapping,\n mailMerge: options.mailMerge,\n ...options.settings,\n };\n\n this.media = new Media();\n this.charts = new ChartCollection();\n this.smartArts = new SmartArtCollection();\n this.embeddings = new EmbeddingCollection();\n this.altChunks = new AltChunkCollection();\n this.subDocs = new SubDocCollection();\n\n if (options.externalStyles !== undefined) {\n const defaultFactory = new DefaultStylesFactory();\n const defaultStyles = defaultFactory.newInstance(options.styles?.default);\n const externalFactory = new ExternalStylesFactory();\n const externalStyles = externalFactory.newInstance(options.externalStyles);\n // Skip docDefaults AND latentStyles from default factory —\n // external styles already provide them; XSD requires docDefaults → latentStyles → style sequence.\n // Also drop builtins whose styleId the external XML already defines so\n // user definitions override defaults (no duplicate styleId in the output).\n const externalStyleIds = new Set<string>();\n for (const s of externalStyles.importedStyles ?? []) {\n const id = extractStyleId(s._raw);\n if (id) externalStyleIds.add(id);\n }\n const defaultStyleElements = defaultStyles.importedStyles!.slice(2).filter((s) => {\n const id = extractStyleId(s._raw);\n return !id || !externalStyleIds.has(id);\n });\n this.styles = new Styles({\n ...externalStyles,\n importedStyles: [...externalStyles.importedStyles!, ...defaultStyleElements],\n });\n } else if (options.styles) {\n const stylesFactory = new DefaultStylesFactory();\n const defaultStyles = stylesFactory.newInstance(options.styles.default);\n // importedStyles[0]=docDefaults, [1]=latentStyles, [2+]=builtin styles.\n // paragraphStyles/characterStyles stay available for numbering registration\n // below but are NOT emitted when round-tripping (the raw importedStyles\n // already carry every source style — emitting both would duplicate them).\n const {\n importedStyles: parsedStyles,\n paragraphStyles,\n characterStyles,\n tableStyles,\n ...restStyles\n } = options.styles;\n const merged = defaultStyles.importedStyles ? [...defaultStyles.importedStyles] : [];\n if (restStyles.docDefaultsXml) {\n const ddIdx = merged.findIndex((s) => s._raw.startsWith(\"<w:docDefaults\"));\n if (ddIdx >= 0) merged[ddIdx] = { _raw: restStyles.docDefaultsXml };\n }\n if (restStyles.latentStylesXml) {\n const latentIdx = merged.findIndex((s) => s._raw.startsWith(\"<w:latentStyles\"));\n if (latentIdx >= 0) merged[latentIdx] = { _raw: restStyles.latentStylesXml };\n }\n if (parsedStyles && parsedStyles.length > 0) {\n // Round-trip: emit verbatim source styles (suppress factory builtins\n // and structured re-emission). User overrides via default.<field>\n // (e.g. default.heading1) take precedence over the verbatim source —\n // drop those ids from the source and emit the factory's structured\n // version instead, so \"modify a default style\" works post-parse.\n merged.splice(2);\n const overrideIds = collectDefaultOverrideIds(options.styles.default);\n if (overrideIds.size > 0) {\n const overrideById = new Map<string, { _raw: string }>();\n for (const s of defaultStyles.importedStyles!.slice(2)) {\n const id = extractStyleId(s._raw);\n if (id) overrideById.set(id, s);\n }\n for (const s of parsedStyles) {\n const id = extractStyleId(s._raw);\n if (id && overrideIds.has(id)) continue;\n merged.push(s);\n }\n for (const id of overrideIds) {\n const s = overrideById.get(id);\n if (s) merged.push(s);\n }\n } else {\n merged.push(...parsedStyles);\n }\n this.styles = new Styles({ ...defaultStyles, importedStyles: merged, ...restStyles });\n } else {\n // Generation: factory builtins + structured custom styles.\n this.styles = new Styles({\n ...defaultStyles,\n paragraphStyles,\n characterStyles,\n tableStyles,\n ...restStyles,\n });\n }\n } else {\n const stylesFactory = new DefaultStylesFactory();\n this.styles = new Styles(stylesFactory.newInstance());\n }\n\n // Register numbering references from custom paragraph/character styles.\n // Style definitions may contain numbering properties whose concrete instances\n // are never created through the body paragraph processing path.\n if (options.styles?.paragraphStyles) {\n for (const style of options.styles.paragraphStyles) {\n const num = style.paragraph?.numbering;\n if (num) {\n this.numbering.createConcreteNumberingInstance(num.reference, num.instance ?? 0);\n }\n }\n }\n\n this.addDefaultRelationships();\n\n for (const section of options.sections) {\n this.addSection(section);\n }\n\n if (options.footnotes) {\n for (const key in options.footnotes) {\n // Skip the round-tripped separator markers (they carry no .children).\n if (key === \"separator\" || key === \"continuationSeparator\") continue;\n this.footNotes.notes.set(parseFloat(key), options.footnotes[key].children);\n }\n this.footNotes.separator = options.footnotes.separator;\n this.footNotes.continuationSeparator = options.footnotes.continuationSeparator;\n }\n\n if (options.endnotes) {\n for (const key in options.endnotes) {\n if (key === \"separator\" || key === \"continuationSeparator\") continue;\n this.endnotes.notes.set(parseFloat(key), options.endnotes[key].children);\n }\n this.endnotes.separator = options.endnotes.separator;\n this.endnotes.continuationSeparator = options.endnotes.continuationSeparator;\n }\n\n this.fontTable = new FontWrapper(options.fonts ?? []);\n this.glossaryOptions = options.glossary;\n this.webSettings = options.webSettings ?? undefined;\n\n if (options.glossary) {\n this.document.relationships.addRelationship(\n this._currentRelationshipId++,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/glossaryDocument\",\n \"glossary/document.xml\",\n );\n }\n\n if (this.webSettings) {\n this.document.relationships.addRelationship(\n this._currentRelationshipId++,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings\",\n \"webSettings.xml\",\n );\n }\n }\n\n get headers(): HeaderFooterEntry[] {\n return this._headers;\n }\n\n get footers(): HeaderFooterEntry[] {\n return this._footers;\n }\n\n // --- Private helpers ---\n\n private addSection({ headers = {}, footers = {}, properties }: SectionOptions): void {\n const sectPrOptions: SectionPropertiesOptions = {\n ...properties,\n footerWrapperGroup: {\n default: footers.default ? this.createFooter(footers.default) : undefined,\n even: footers.even ? this.createFooter(footers.even) : undefined,\n first: footers.first ? this.createFooter(footers.first) : undefined,\n },\n headerWrapperGroup: {\n default: headers.default ? this.createHeader(headers.default) : undefined,\n even: headers.even ? this.createHeader(headers.even) : undefined,\n first: headers.first ? this.createHeader(headers.first) : undefined,\n },\n };\n this._sectionProperties.push(sectPrOptions);\n }\n\n private createHeader(header: SectionChild[]): HeaderFooterEntry {\n const referenceId = this._currentRelationshipId++;\n const entry: HeaderFooterEntry = {\n children: header,\n relationships: new Relationships(),\n referenceId,\n };\n this.addHeaderToDocument(entry);\n return entry;\n }\n\n private createFooter(footer: SectionChild[]): HeaderFooterEntry {\n const referenceId = this._currentRelationshipId++;\n const entry: HeaderFooterEntry = {\n children: footer,\n relationships: new Relationships(),\n referenceId,\n };\n this.addFooterToDocument(entry);\n return entry;\n }\n\n private addHeaderToDocument(header: HeaderFooterEntry): void {\n this._headers.push(header);\n this.document.relationships.addRelationship(\n header.referenceId,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/header\",\n `header${this._headers.length}.xml`,\n );\n }\n\n private addFooterToDocument(footer: HeaderFooterEntry): void {\n this._footers.push(footer);\n this.document.relationships.addRelationship(\n footer.referenceId,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer\",\n `footer${this._footers.length}.xml`,\n );\n }\n\n private addDefaultRelationships(): void {\n this.fileRelationships.addRelationship(\n 1,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument\",\n \"word/document.xml\",\n );\n this.fileRelationships.addRelationship(\n 2,\n \"http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties\",\n \"docProps/core.xml\",\n );\n this.fileRelationships.addRelationship(\n 3,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties\",\n \"docProps/app.xml\",\n );\n this.fileRelationships.addRelationship(\n 4,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties\",\n \"docProps/custom.xml\",\n );\n\n this.document.relationships.addRelationship(\n this._currentRelationshipId++,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles\",\n \"styles.xml\",\n );\n this.document.relationships.addRelationship(\n this._currentRelationshipId++,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering\",\n \"numbering.xml\",\n );\n this.document.relationships.addRelationship(\n this._currentRelationshipId++,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes\",\n \"footnotes.xml\",\n );\n this.document.relationships.addRelationship(\n this._currentRelationshipId++,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes\",\n \"endnotes.xml\",\n );\n this.document.relationships.addRelationship(\n this._currentRelationshipId++,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings\",\n \"settings.xml\",\n );\n // Comments is an optional part — only wire the document→comments relationship\n // when the document actually carries comments. Emitting it unconditionally\n // produces an orphan comments.xml that Word rejects as an OPC violation\n // (empty part with no [Content_Types] Override when content types are\n // passed through from the source on round-trip).\n if (this._options.comments?.children?.length) {\n this.document.relationships.addRelationship(\n this._currentRelationshipId++,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments\",\n \"comments.xml\",\n );\n }\n if (this._options.bibliography) {\n this.document.relationships.addRelationship(\n this._currentRelationshipId++,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/bibliography\",\n \"bibliography.xml\",\n );\n }\n\n // Theme — a raw-passthrough part. Only declare the document→theme\n // relationship when the source carried one, so Word can resolve theme\n // colors/fonts. Without it theme1.xml is an orphan part Word may reject.\n const themePart = this._options.rawParts?.find((p) => p.path.startsWith(\"word/theme/\"));\n if (themePart) {\n this.document.relationships.addRelationship(\n this._currentRelationshipId++,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme\",\n themePart.path.replace(/^word\\//, \"\"),\n );\n }\n\n // customXml storage — raw-passthrough parts. Declare the document→customXml\n // relationship for each item (itemProps are linked via the item's own .rels,\n // not directly by the document) so Word can bind cover-page metadata, etc.\n for (const part of this._options.rawParts ?? []) {\n if (\n part.path.startsWith(\"customXml/\") &&\n part.path.endsWith(\".xml\") &&\n !part.path.includes(\"/_rels/\") &&\n !part.path.includes(\"itemProps\")\n ) {\n this.document.relationships.addRelationship(\n this._currentRelationshipId++,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml\",\n `../${part.path}`,\n );\n }\n }\n }\n}\n\n// ── DocxReadContext ──\n\n/**\n * DOCX-specific read context.\n *\n * Holds references to the parsed DocxDocument and cached style/numbering data\n * used throughout the DOCX parsing pipeline. Implements ReadContext for\n * descriptor pipeline compatibility.\n */\nexport class DocxReadContext implements ReadContext {\n /**\n * Path of the part currently being parsed. Each part carries its own .rels\n * with independent rId numbering, so drawings inside a part must resolve\n * image relationships against that part's rels. Defaults to the document body.\n */\n public currentPart = \"word/document.xml\";\n\n constructor(\n public docx: DocxDocument,\n public styleCache: Map<string, Element>,\n public numberingCache: Map<string, Element>,\n ) {}\n\n resolveRelationship(rId: string): string | undefined {\n const partMedia = this.docx.partRefs.partMedia.get(this.currentPart);\n if (partMedia) {\n const media = partMedia.get(rId);\n if (media) return media;\n }\n return (\n this.docx.partRefs.headers.get(rId) ??\n this.docx.partRefs.footers.get(rId) ??\n this.docx.partRefs.media.get(rId) ??\n this.docx.partRefs.charts.get(rId) ??\n this.docx.partRefs.diagramData.get(rId) ??\n this.docx.partRefs.afChunks.get(rId) ??\n this.docx.partRefs.subDocs.get(rId) ??\n this.docx.partRefs.hyperlinks.get(rId)\n );\n }\n\n /**\n * Run `fn` with `currentPart` temporarily set to `partPath`, restoring the\n * previous value afterwards. Use when parsing a sub-document part (header,\n * footer, footnotes, …) so its drawings resolve images from its own rels.\n */\n withPart<T>(partPath: string, fn: () => T): T {\n const prev = this.currentPart;\n this.currentPart = partPath;\n try {\n return fn();\n } finally {\n this.currentPart = prev;\n }\n }\n\n getPart(path: string): Element | undefined {\n return this.docx.doc.get(path);\n }\n\n getRaw(path: string): Uint8Array | undefined {\n return this.docx.doc.getR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