@office-open/docx 0.10.1 → 0.10.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/{context-C0vWotG5.mjs → context-DCpANdYI.mjs} +133 -56
- package/dist/context-DCpANdYI.mjs.map +1 -0
- package/dist/{core-properties-DFRUHpWM.d.mts → core-properties-DQWsBBjj.d.mts} +236 -169
- package/dist/core-properties-DQWsBBjj.d.mts.map +1 -0
- package/dist/{generate-Bh4akIEz.mjs → generate-BpWZmWkO.mjs} +62 -55
- package/dist/generate-BpWZmWkO.mjs.map +1 -0
- package/dist/generate.d.mts +1 -1
- package/dist/generate.mjs +1 -1
- package/dist/index.d.mts +2 -39
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +5 -5
- package/dist/{parse-COZdd0oD.mjs → parse-Dhuwrt2i.mjs} +14 -25
- package/dist/parse-Dhuwrt2i.mjs.map +1 -0
- package/dist/parse.d.mts +1 -1
- package/dist/parse.mjs +1 -1
- package/dist/{parts-DVpfsxSR.mjs → parts-BXGYKB-u.mjs} +733 -515
- package/dist/parts-BXGYKB-u.mjs.map +1 -0
- package/dist/patch/index.d.mts +1 -1
- package/dist/patch/index.d.mts.map +1 -1
- package/dist/patch/index.mjs +8 -19
- package/dist/patch/index.mjs.map +1 -1
- package/package.json +3 -3
- package/dist/context-C0vWotG5.mjs.map +0 -1
- package/dist/core-properties-DFRUHpWM.d.mts.map +0 -1
- package/dist/generate-Bh4akIEz.mjs.map +0 -1
- package/dist/parse-COZdd0oD.mjs.map +0 -1
- package/dist/parts-DVpfsxSR.mjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { I as DefaultStylesFactory,
|
|
1
|
+
import { I as DefaultStylesFactory, Mn as Media, P as extractStyleId, j as Styles, nt as Numbering, wt as FontWrapper } from "./parts-BXGYKB-u.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";
|
|
@@ -110,6 +110,73 @@ var EmbeddingCollection = class {
|
|
|
110
110
|
*
|
|
111
111
|
* @module
|
|
112
112
|
*/
|
|
113
|
+
/** User styles override factory defaults with the same styleId; keep the rest. */
|
|
114
|
+
function mergeById(factoryStyles, userStyles) {
|
|
115
|
+
const factory = factoryStyles ?? [];
|
|
116
|
+
if (!userStyles || userStyles.length === 0) return factory;
|
|
117
|
+
const userIds = new Set(userStyles.map((s) => s.id));
|
|
118
|
+
return [...factory.filter((s) => !userIds.has(s.id)), ...userStyles];
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Highest comment id in an explicit comments list, or -1 when there are none.
|
|
122
|
+
* Seeds the comment id allocator so auto-allocated ids never collide with ids
|
|
123
|
+
* the caller already assigned (e.g. round-tripped from an existing document).
|
|
124
|
+
*/
|
|
125
|
+
function maxCommentId(comments) {
|
|
126
|
+
let max = -1;
|
|
127
|
+
if (comments) {
|
|
128
|
+
for (const c of comments) if (c.id > max) max = c.id;
|
|
129
|
+
}
|
|
130
|
+
return max;
|
|
131
|
+
}
|
|
132
|
+
/** Narrows an object to a `{ id: number }` marker without an `as` cast. */
|
|
133
|
+
function isNumericIdMarker(value) {
|
|
134
|
+
return typeof value === "object" && value !== null && "id" in value && typeof value.id === "number";
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Highest w:id among explicit bookmark + move-range start markers (`range`) and
|
|
138
|
+
* explicit movedFrom/movedTo runs (`moveRun`) anywhere in the body tree
|
|
139
|
+
* (paragraphs, tables, textboxes, SDTs, headers/footers nested in sections).
|
|
140
|
+
* Seeds the markup id allocators so `{ bookmark }` / `{ moveFrom }` / `{ moveTo }`
|
|
141
|
+
* sugars never collide with ids the caller already assigned. Comment ids live in
|
|
142
|
+
* their own namespace (comments.nextId) and are intentionally excluded.
|
|
143
|
+
*/
|
|
144
|
+
function collectMaxMarkupIds(value, acc) {
|
|
145
|
+
if (value === null || value === void 0 || typeof value !== "object") return;
|
|
146
|
+
if (value instanceof Uint8Array || value instanceof Date) return;
|
|
147
|
+
if (Array.isArray(value)) {
|
|
148
|
+
for (const item of value) collectMaxMarkupIds(item, acc);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const obj = value;
|
|
152
|
+
const rangeMarker = obj.bookmarkStart ?? obj.moveFromRangeStart ?? obj.moveToRangeStart;
|
|
153
|
+
if (isNumericIdMarker(rangeMarker) && rangeMarker.id > acc.range) acc.range = rangeMarker.id;
|
|
154
|
+
const moveRun = obj.movedFrom ?? obj.movedTo;
|
|
155
|
+
if (isNumericIdMarker(moveRun) && moveRun.id > acc.moveRun) acc.moveRun = moveRun.id;
|
|
156
|
+
for (const key of Object.keys(obj)) collectMaxMarkupIds(obj[key], acc);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Whether any `{ comment }` sugar child appears anywhere in the body tree
|
|
160
|
+
* (paragraphs, tables, textboxes, SDTs, headers/footers nested in sections).
|
|
161
|
+
* The document→comments relationship must exist whenever comments.xml will be
|
|
162
|
+
* generated; since sugar entries are registered during stringify — after the
|
|
163
|
+
* constructor wires relationships — this pre-scan predicts them so the part and
|
|
164
|
+
* its relationship stay in sync (OPC consistency). Every `{ comment }` always
|
|
165
|
+
* stringifies, so the prediction matches the entries actually registered.
|
|
166
|
+
*/
|
|
167
|
+
function bodyContainsCommentSugar(value) {
|
|
168
|
+
if (value === null || value === void 0) return false;
|
|
169
|
+
if (typeof value !== "object") return false;
|
|
170
|
+
if (value instanceof Uint8Array || value instanceof Date) return false;
|
|
171
|
+
if (Array.isArray(value)) {
|
|
172
|
+
for (const item of value) if (bodyContainsCommentSugar(item)) return true;
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
const obj = value;
|
|
176
|
+
if (typeof obj.comment === "object" && obj.comment !== null) return true;
|
|
177
|
+
for (const key of Object.keys(obj)) if (bodyContainsCommentSugar(obj[key])) return true;
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
113
180
|
var DocxWriteContext = class {
|
|
114
181
|
_currentRelationshipId = 1;
|
|
115
182
|
_sectionProperties = [];
|
|
@@ -119,15 +186,42 @@ var DocxWriteContext = class {
|
|
|
119
186
|
addRelationship(_type, _target, _mode) {
|
|
120
187
|
return `rId${this._currentRelationshipId++}`;
|
|
121
188
|
}
|
|
122
|
-
addMedia(
|
|
123
|
-
return
|
|
189
|
+
addMedia(data, type) {
|
|
190
|
+
return `{${this.media.addMedia(data, type, (fileName) => ({
|
|
191
|
+
data,
|
|
192
|
+
fileName,
|
|
193
|
+
type,
|
|
194
|
+
transformation: {
|
|
195
|
+
pixels: {
|
|
196
|
+
x: 0,
|
|
197
|
+
y: 0
|
|
198
|
+
},
|
|
199
|
+
emus: {
|
|
200
|
+
x: 0,
|
|
201
|
+
y: 0
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
})).fileName}}`;
|
|
124
205
|
}
|
|
125
206
|
_headers = [];
|
|
126
207
|
_footers = [];
|
|
127
208
|
constructor(options) {
|
|
128
209
|
this._options = options;
|
|
129
210
|
this.numbering = new Numbering(options.numbering ? options.numbering : { config: [] });
|
|
130
|
-
this.comments = {
|
|
211
|
+
this.comments = {
|
|
212
|
+
relationships: new Relationships(),
|
|
213
|
+
entries: [],
|
|
214
|
+
nextId: maxCommentId(options.comments?.children) + 1
|
|
215
|
+
};
|
|
216
|
+
const markupSeed = {
|
|
217
|
+
range: -1,
|
|
218
|
+
moveRun: -1
|
|
219
|
+
};
|
|
220
|
+
collectMaxMarkupIds(options.sections, markupSeed);
|
|
221
|
+
this.markupIds = {
|
|
222
|
+
rangeNext: markupSeed.range + 1,
|
|
223
|
+
moveRunNext: markupSeed.moveRun + 1
|
|
224
|
+
};
|
|
131
225
|
this.fileRelationships = new Relationships();
|
|
132
226
|
this.footNotes = {
|
|
133
227
|
relationships: new Relationships(),
|
|
@@ -172,64 +266,47 @@ var DocxWriteContext = class {
|
|
|
172
266
|
this.altChunks = new AltChunkCollection();
|
|
173
267
|
this.subDocs = new SubDocCollection();
|
|
174
268
|
if (options.externalStyles !== void 0) {
|
|
175
|
-
const defaultStyles = new DefaultStylesFactory().newInstance(options.styles?.default);
|
|
176
269
|
const externalStyles = new ExternalStylesFactory().newInstance(options.externalStyles);
|
|
177
|
-
const
|
|
270
|
+
const defaultStyles = new DefaultStylesFactory().newInstance(options.styles?.default ?? {});
|
|
271
|
+
const externalIds = /* @__PURE__ */ new Set();
|
|
178
272
|
for (const s of externalStyles.importedStyles ?? []) {
|
|
179
273
|
const id = extractStyleId(s._raw);
|
|
180
|
-
if (id)
|
|
274
|
+
if (id) externalIds.add(id);
|
|
181
275
|
}
|
|
182
|
-
const
|
|
183
|
-
const id = extractStyleId(s._raw);
|
|
184
|
-
return !id || !externalStyleIds.has(id);
|
|
185
|
-
});
|
|
276
|
+
const notInExternal = (arr) => (arr ?? []).filter((s) => !externalIds.has(s.id));
|
|
186
277
|
this.styles = new Styles({
|
|
187
|
-
|
|
188
|
-
|
|
278
|
+
importedStyles: externalStyles.importedStyles,
|
|
279
|
+
initialAttributes: externalStyles.initialAttributes ?? defaultStyles.initialAttributes,
|
|
280
|
+
paragraphStyles: notInExternal(defaultStyles.paragraphStyles),
|
|
281
|
+
characterStyles: notInExternal(defaultStyles.characterStyles),
|
|
282
|
+
tableStyles: notInExternal(defaultStyles.tableStyles),
|
|
283
|
+
numberingStyles: notInExternal(defaultStyles.numberingStyles)
|
|
189
284
|
});
|
|
190
285
|
} else if (options.styles) {
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
const
|
|
196
|
-
if (ddIdx >= 0) merged[ddIdx] = { _raw: restStyles.docDefaultsXml };
|
|
197
|
-
}
|
|
198
|
-
if (restStyles.latentStylesXml) {
|
|
199
|
-
const latentIdx = merged.findIndex((s) => s._raw.startsWith("<w:latentStyles"));
|
|
200
|
-
if (latentIdx >= 0) merged[latentIdx] = { _raw: restStyles.latentStylesXml };
|
|
201
|
-
}
|
|
202
|
-
if (parsedStyles && parsedStyles.length > 0) {
|
|
203
|
-
merged.splice(2);
|
|
204
|
-
const overrideIds = collectDefaultOverrideIds(options.styles.default);
|
|
205
|
-
if (overrideIds.size > 0) {
|
|
206
|
-
const overrideById = /* @__PURE__ */ new Map();
|
|
207
|
-
for (const s of defaultStyles.importedStyles.slice(2)) {
|
|
208
|
-
const id = extractStyleId(s._raw);
|
|
209
|
-
if (id) overrideById.set(id, s);
|
|
210
|
-
}
|
|
211
|
-
for (const s of parsedStyles) {
|
|
212
|
-
const id = extractStyleId(s._raw);
|
|
213
|
-
if (id && overrideIds.has(id)) continue;
|
|
214
|
-
merged.push(s);
|
|
215
|
-
}
|
|
216
|
-
for (const id of overrideIds) {
|
|
217
|
-
const s = overrideById.get(id);
|
|
218
|
-
if (s) merged.push(s);
|
|
219
|
-
}
|
|
220
|
-
} else merged.push(...parsedStyles);
|
|
286
|
+
const s = options.styles;
|
|
287
|
+
if (s.roundTripped) {
|
|
288
|
+
const f = new DefaultStylesFactory().newInstance({});
|
|
289
|
+
const docDefaults = s.docDefaultsXml ?? f.importedStyles?.[0]?._raw ?? "";
|
|
290
|
+
const latentStyles = s.latentStylesXml ?? f.importedStyles?.[1]?._raw ?? "";
|
|
221
291
|
this.styles = new Styles({
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
292
|
+
importedStyles: [{ _raw: docDefaults }, { _raw: latentStyles }],
|
|
293
|
+
initialAttributes: s.initialAttributes ?? f.initialAttributes,
|
|
294
|
+
paragraphStyles: s.paragraphStyles,
|
|
295
|
+
characterStyles: s.characterStyles,
|
|
296
|
+
tableStyles: s.tableStyles,
|
|
297
|
+
numberingStyles: s.numberingStyles
|
|
225
298
|
});
|
|
226
|
-
} else
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
299
|
+
} else {
|
|
300
|
+
const f = new DefaultStylesFactory().newInstance(s.default);
|
|
301
|
+
this.styles = new Styles({
|
|
302
|
+
importedStyles: f.importedStyles,
|
|
303
|
+
initialAttributes: s.initialAttributes ?? f.initialAttributes,
|
|
304
|
+
paragraphStyles: mergeById(f.paragraphStyles, s.paragraphStyles),
|
|
305
|
+
characterStyles: mergeById(f.characterStyles, s.characterStyles),
|
|
306
|
+
tableStyles: mergeById(f.tableStyles, s.tableStyles),
|
|
307
|
+
numberingStyles: mergeById(f.numberingStyles, s.numberingStyles)
|
|
308
|
+
});
|
|
309
|
+
}
|
|
233
310
|
} else {
|
|
234
311
|
const stylesFactory = new DefaultStylesFactory();
|
|
235
312
|
this.styles = new Styles(stylesFactory.newInstance());
|
|
@@ -322,10 +399,10 @@ var DocxWriteContext = class {
|
|
|
322
399
|
this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes", "footnotes.xml");
|
|
323
400
|
this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes", "endnotes.xml");
|
|
324
401
|
this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings", "settings.xml");
|
|
325
|
-
if (this._options.comments?.children?.length) this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments", "comments.xml");
|
|
402
|
+
if (this._options.comments?.children?.length || bodyContainsCommentSugar(this._options.sections)) this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments", "comments.xml");
|
|
326
403
|
if (this._options.bibliography) this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/bibliography", "bibliography.xml");
|
|
327
404
|
const themePart = this._options.rawParts?.find((p) => p.path.startsWith("word/theme/"));
|
|
328
|
-
|
|
405
|
+
this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme", themePart ? themePart.path.replace(/^word\//, "") : "theme/theme1.xml");
|
|
329
406
|
for (const part of this._options.rawParts ?? []) if (part.path.startsWith("customXml/") && part.path.endsWith(".xml") && !part.path.includes("/_rels/") && !part.path.includes("itemProps")) this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml", `../${part.path}`);
|
|
330
407
|
}
|
|
331
408
|
};
|
|
@@ -383,4 +460,4 @@ var DocxReadContext = class {
|
|
|
383
460
|
//#endregion
|
|
384
461
|
export { AltChunkCollection as i, DocxWriteContext as n, SubDocCollection as r, DocxReadContext as t };
|
|
385
462
|
|
|
386
|
-
//# sourceMappingURL=context-
|
|
463
|
+
//# sourceMappingURL=context-DCpANdYI.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-DCpANdYI.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 { CommentOptions } from \"@parts/paragraph/run/comment-run\";\nimport type { SettingsOptions } from \"@parts/settings/settings\";\nimport { Styles, extractStyleId } from \"@parts/styles\";\nimport { ExternalStylesFactory } from \"@parts/styles/external-styles-factory\";\nimport { DefaultStylesFactory } 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 { MediaData } from \"@shared/media/data\";\nimport type { SectionOptions } from \"@shared/section\";\nimport type { SectionChild } from \"@shared/section\";\n\nimport type { DocxDocument } from \"./parse\";\n\n/** User styles override factory defaults with the same styleId; keep the rest. */\nfunction mergeById<T extends { id: string }>(\n factoryStyles: T[] | undefined,\n userStyles: T[] | undefined,\n): T[] {\n const factory = factoryStyles ?? [];\n if (!userStyles || userStyles.length === 0) return factory;\n const userIds = new Set(userStyles.map((s) => s.id));\n return [...factory.filter((s) => !userIds.has(s.id)), ...userStyles];\n}\n\n/**\n * Highest comment id in an explicit comments list, or -1 when there are none.\n * Seeds the comment id allocator so auto-allocated ids never collide with ids\n * the caller already assigned (e.g. round-tripped from an existing document).\n */\nfunction maxCommentId(comments: readonly CommentOptions[] | undefined): number {\n let max = -1;\n if (comments) {\n for (const c of comments) {\n if (c.id > max) max = c.id;\n }\n }\n return max;\n}\n\n/** Narrows an object to a `{ id: number }` marker without an `as` cast. */\nfunction isNumericIdMarker(value: unknown): value is { id: number } {\n return (\n typeof value === \"object\" && value !== null && \"id\" in value && typeof value.id === \"number\"\n );\n}\n\n/**\n * Highest w:id among explicit bookmark + move-range start markers (`range`) and\n * explicit movedFrom/movedTo runs (`moveRun`) anywhere in the body tree\n * (paragraphs, tables, textboxes, SDTs, headers/footers nested in sections).\n * Seeds the markup id allocators so `{ bookmark }` / `{ moveFrom }` / `{ moveTo }`\n * sugars never collide with ids the caller already assigned. Comment ids live in\n * their own namespace (comments.nextId) and are intentionally excluded.\n */\nfunction collectMaxMarkupIds(value: unknown, acc: { range: number; moveRun: number }): void {\n if (value === null || value === undefined || typeof value !== \"object\") return;\n if (value instanceof Uint8Array || value instanceof Date) return;\n if (Array.isArray(value)) {\n for (const item of value) collectMaxMarkupIds(item, acc);\n return;\n }\n const obj = value as Record<string, unknown>;\n const rangeMarker = obj.bookmarkStart ?? obj.moveFromRangeStart ?? obj.moveToRangeStart;\n if (isNumericIdMarker(rangeMarker) && rangeMarker.id > acc.range) acc.range = rangeMarker.id;\n const moveRun = obj.movedFrom ?? obj.movedTo;\n if (isNumericIdMarker(moveRun) && moveRun.id > acc.moveRun) acc.moveRun = moveRun.id;\n for (const key of Object.keys(obj)) collectMaxMarkupIds(obj[key], acc);\n}\n\n/**\n * Whether any `{ comment }` sugar child appears anywhere in the body tree\n * (paragraphs, tables, textboxes, SDTs, headers/footers nested in sections).\n * The document→comments relationship must exist whenever comments.xml will be\n * generated; since sugar entries are registered during stringify — after the\n * constructor wires relationships — this pre-scan predicts them so the part and\n * its relationship stay in sync (OPC consistency). Every `{ comment }` always\n * stringifies, so the prediction matches the entries actually registered.\n */\nfunction bodyContainsCommentSugar(value: unknown): boolean {\n if (value === null || value === undefined) return false;\n if (typeof value !== \"object\") return false;\n if (value instanceof Uint8Array || value instanceof Date) return false;\n if (Array.isArray(value)) {\n for (const item of value) {\n if (bodyContainsCommentSugar(item)) return true;\n }\n return false;\n }\n const obj = value as Record<string, unknown>;\n if (typeof obj.comment === \"object\" && obj.comment !== null) return true;\n for (const key of Object.keys(obj)) {\n if (bodyContainsCommentSugar(obj[key])) return true;\n }\n return false;\n}\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<MediaData>;\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: {\n relationships: Relationships;\n /** Comment entries registered by `{ comment }` sugar children during stringify. */\n entries: CommentOptions[];\n /** Next auto-allocated comment id (seeded above any explicit comment id). */\n nextId: number;\n };\n declare public markupIds: {\n /** Next id for bookmark + move-range markers (CT_MarkupRange) — shared, like Word. */\n rangeNext: number;\n /** Next id for movedFrom/movedTo runs (CT_TrackChange). */\n moveRunNext: number;\n };\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 const entry = this.media.addMedia(\n data,\n type,\n (fileName) =>\n ({\n data,\n fileName,\n type,\n transformation: { pixels: { x: 0, y: 0 }, emus: { x: 0, y: 0 } },\n }) as MediaData,\n );\n return `{${entry.fileName}}`;\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 = {\n relationships: new Relationships(),\n entries: [],\n nextId: maxCommentId(options.comments?.children) + 1,\n };\n const markupSeed = { range: -1, moveRun: -1 };\n collectMaxMarkupIds(options.sections, markupSeed);\n this.markupIds = {\n rangeNext: markupSeed.range + 1,\n moveRunNext: markupSeed.moveRun + 1,\n };\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<MediaData>();\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 externalStyles = new ExternalStylesFactory().newInstance(options.externalStyles);\n const defaultStyles = new DefaultStylesFactory().newInstance(options.styles?.default ?? {});\n // External (user-provided full styles.xml) wins; factory builtins fill\n // any gaps. Drop factory builtins whose styleId the external XML already\n // defines (no duplicate styleId). docDefaults/latentStyles come from the\n // external XML — the factory's are not mixed in.\n const externalIds = new Set<string>();\n for (const s of externalStyles.importedStyles ?? []) {\n const id = extractStyleId(s._raw);\n if (id) externalIds.add(id);\n }\n const notInExternal = <T extends { id: string }>(arr: T[] | undefined) =>\n (arr ?? []).filter((s) => !externalIds.has(s.id));\n this.styles = new Styles({\n importedStyles: externalStyles.importedStyles,\n initialAttributes: externalStyles.initialAttributes ?? defaultStyles.initialAttributes,\n paragraphStyles: notInExternal(defaultStyles.paragraphStyles),\n characterStyles: notInExternal(defaultStyles.characterStyles),\n tableStyles: notInExternal(defaultStyles.tableStyles),\n numberingStyles: notInExternal(defaultStyles.numberingStyles),\n });\n } else if (options.styles) {\n const s = options.styles;\n if (s.roundTripped) {\n // Round-trip origin (parseStyleDefinitions): parsed structured\n // builtin/custom styles win. The factory only supplies docDefaults +\n // latentStyles verbatim defaults; parsed docDefaultsXml/latentStylesXml\n // override when present. No factory builtin rebuild — parsed builtins\n // already carry the source document's customizations.\n const f = new DefaultStylesFactory().newInstance({});\n const docDefaults = s.docDefaultsXml ?? f.importedStyles?.[0]?._raw ?? \"\";\n const latentStyles = s.latentStylesXml ?? f.importedStyles?.[1]?._raw ?? \"\";\n this.styles = new Styles({\n importedStyles: [{ _raw: docDefaults }, { _raw: latentStyles }],\n initialAttributes: s.initialAttributes ?? f.initialAttributes,\n paragraphStyles: s.paragraphStyles,\n characterStyles: s.characterStyles,\n tableStyles: s.tableStyles,\n numberingStyles: s.numberingStyles,\n });\n } else {\n // Fresh generation: factory default builtins (structured) + user\n // overrides. User paragraphStyles/characterStyles/tableStyles/\n // numberingStyles override factory builtins with the same styleId.\n const f = new DefaultStylesFactory().newInstance(s.default);\n this.styles = new Styles({\n importedStyles: f.importedStyles,\n initialAttributes: s.initialAttributes ?? f.initialAttributes,\n paragraphStyles: mergeById(f.paragraphStyles, s.paragraphStyles),\n characterStyles: mergeById(f.characterStyles, s.characterStyles),\n tableStyles: mergeById(f.tableStyles, s.tableStyles),\n numberingStyles: mergeById(f.numberingStyles, s.numberingStyles),\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 (\n this._options.comments?.children?.length ||\n bodyContainsCommentSugar(this._options.sections)\n ) {\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 — always present: fresh-compile generates a default theme, round-trip\n // passes the source theme through rawParts. Word needs the document→theme\n // relationship to resolve theme colors/fonts.\n const themePart = this._options.rawParts?.find((p) => p.path.startsWith(\"word/theme/\"));\n this.document.relationships.addRelationship(\n this._currentRelationshipId++,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme\",\n themePart ? themePart.path.replace(/^word\\//, \"\") : \"theme/theme1.xml\",\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.getRaw(path);\n }\n}\n"],"mappings":";;;;;;;;;;;;AA4BA,IAAa,qBAAb,MAAgC;CAC9B;CAEA,cAAqB;EACnB,KAAK,sBAAM,IAAI,IAA0B;CAC3C;CAEA,YAAmB,KAAa,MAA0B;EACxD,KAAK,IAAI,IAAI,KAAK,IAAI;CACxB;CAEA,IAAW,QAAwB;EACjC,OAAO,CAAC,GAAG,KAAK,IAAI,OAAO,CAAC;CAC9B;AACF;;;;;;ACvBA,IAAa,mBAAb,MAA8B;CAC5B;CAEA,cAAqB;EACnB,KAAK,sBAAM,IAAI,IAAwB;CACzC;CAEA,UAAiB,KAAa,MAAwB;EACpD,KAAK,IAAI,IAAI,KAAK,IAAI;CACxB;CAEA,IAAW,QAAsB;EAC/B,OAAO,CAAC,GAAG,KAAK,IAAI,OAAO,CAAC;CAC9B;AACF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