@office-open/docx 0.6.3 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { i as __toCommonJS, n as __exportAll, r as __reExport, t as __esmMin } from "./chunk-090QGkrx.mjs";
2
- import { AppProperties, BaseXmlComponent, BuilderElement, BuilderElement as BuilderElement$1, EMPTY_OBJECT, EmptyElement, Formatter, IgnoreIfEmptyXmlComponent, ImportedRootElementAttributes, ImportedXmlComponent, InitializableXmlComponent, NextAttributeComponent, OoxmlMimeType, PrettifyType, RawPassthrough, Relationships, TargetModeType, XmlAttributeComponent, XmlAttributeComponent as XmlAttributeComponent$1, XmlComponent, ZIP_STORED_LEVEL, addSmartArtRelationships, attrObj, chartAttr, convertEmuToPixels, convertInchesToTwip, convertMillimetersToTwip, convertPixelsToEmu, convertToXmlComponent, createDefault, createOverride, createPacker, getReferencedMedia, hasPlaceholders, hashedId, hpsMeasureObj, hpsMeasureObj as hpsMeasureObj$1, numberValObj, numberValObj as numberValObj$1, onOffObj, onOffObj as onOffObj$1, parseArchive, parseCorePropsElement, replaceChartPlaceholders, replaceImagePlaceholders, replaceSmartArtPlaceholders, strFromU8, stringContainerObj, stringEnumValObj, stringEnumValObj as stringEnumValObj$1, stringValObj, stringValObj as stringValObj$1, uniqueId, uniqueNumericIdCreator, uniqueNumericIdCreator as uniqueNumericIdCreator$1, uniqueUuid, unzipSync, wrapEl, zipAndConvert } from "@office-open/core";
2
+ import { AppProperties, BaseXmlComponent, BuilderElement, BuilderElement as BuilderElement$1, EMPTY_OBJECT, EmptyElement, Formatter, IgnoreIfEmptyXmlComponent, ImportedRootElementAttributes, ImportedXmlComponent, InitializableXmlComponent, NextAttributeComponent, OoxmlMimeType, PrettifyType, RawPassthrough, Relationships, TargetModeType, XmlAttributeComponent, XmlAttributeComponent as XmlAttributeComponent$1, XmlComponent, ZIP_STORED_LEVEL, addSmartArtRelationships, attrObj, chartAttr, convertEmuToPixels, convertInchesToTwip, convertMillimetersToTwip, convertPixelsToEmu, convertToXmlComponent, createDefault, createOverride, createPacker, getReferencedMedia, hasPlaceholders, hashedId, hpsMeasureObj, hpsMeasureObj as hpsMeasureObj$1, numberValObj, numberValObj as numberValObj$1, onOffObj, onOffObj as onOffObj$1, parseArchive, parseCorePropsElement, replaceChartPlaceholders, replaceImagePlaceholders, replaceSmartArtPlaceholders, strFromU8, stringContainerObj, stringEnumValObj, stringEnumValObj as stringEnumValObj$1, stringValObj, stringValObj as stringValObj$1, uniqueId, uniqueNumericIdCreator, uniqueNumericIdCreator as uniqueNumericIdCreator$1, uniqueUuid, unzipSync, wrapEl, xsdVerticalMergeRev, zipAndConvert } from "@office-open/core";
3
3
  import { textToUint8Array, toUint8Array } from "undio";
4
4
  import { PresetGeometry, buildFill, createBlipFill, createCustomGeometry, createEffectDag, createEffectList, createOutline, createScene3D, createShape3D, createTransform2D, extractBlipFillMedia } from "@office-open/core/drawingml";
5
5
  import { ChartCollection, ChartSpace } from "@office-open/core/chart";
@@ -1755,7 +1755,7 @@ var init_shape_properties = __esmMin((() => {
1755
1755
  }
1756
1756
  prepForXml(context) {
1757
1757
  const media = this.fillOptions ? extractBlipFillMedia(this.fillOptions) : void 0;
1758
- if (media) context.file.Media.addImage(media.fileName, {
1758
+ if (media) context.file.media.addImage(media.fileName, {
1759
1759
  data: media.data,
1760
1760
  fileName: media.fileName,
1761
1761
  type: media.type,
@@ -2080,12 +2080,12 @@ var init_non_visual_properties = __esmMin((() => {
2080
2080
  if (this.hyperlink) {
2081
2081
  if (this.hyperlink.click && !hasStackClick) {
2082
2082
  const linkId = uniqueId();
2083
- context.viewWrapper.Relationships.addRelationship(linkId, HYPERLINK_RELATIONSHIP_TYPE$1, this.hyperlink.click, TargetModeType.EXTERNAL);
2083
+ context.viewWrapper.relationships.addRelationship(linkId, HYPERLINK_RELATIONSHIP_TYPE$1, this.hyperlink.click, TargetModeType.EXTERNAL);
2084
2084
  this.root.push(buildHyperlinkClickObj(linkId, false));
2085
2085
  }
2086
2086
  if (this.hyperlink.hover) {
2087
2087
  const linkId = uniqueId();
2088
- context.viewWrapper.Relationships.addRelationship(linkId, HYPERLINK_RELATIONSHIP_TYPE$1, this.hyperlink.hover, TargetModeType.EXTERNAL);
2088
+ context.viewWrapper.relationships.addRelationship(linkId, HYPERLINK_RELATIONSHIP_TYPE$1, this.hyperlink.hover, TargetModeType.EXTERNAL);
2089
2089
  this.root.push(buildHyperlinkHoverObj(linkId, false));
2090
2090
  }
2091
2091
  }
@@ -2723,12 +2723,12 @@ var init_doc_properties = __esmMin((() => {
2723
2723
  if (this.hyperlink) {
2724
2724
  if (this.hyperlink.click && !hasStackClick) {
2725
2725
  const linkId = uniqueId();
2726
- context.viewWrapper.Relationships.addRelationship(linkId, HYPERLINK_RELATIONSHIP_TYPE, this.hyperlink.click, TargetModeType.EXTERNAL);
2726
+ context.viewWrapper.relationships.addRelationship(linkId, HYPERLINK_RELATIONSHIP_TYPE, this.hyperlink.click, TargetModeType.EXTERNAL);
2727
2727
  this.root.push(buildHyperlinkClickObj(linkId, true));
2728
2728
  }
2729
2729
  if (this.hyperlink.hover) {
2730
2730
  const linkId = uniqueId();
2731
- context.viewWrapper.Relationships.addRelationship(linkId, HYPERLINK_RELATIONSHIP_TYPE, this.hyperlink.hover, TargetModeType.EXTERNAL);
2731
+ context.viewWrapper.relationships.addRelationship(linkId, HYPERLINK_RELATIONSHIP_TYPE, this.hyperlink.hover, TargetModeType.EXTERNAL);
2732
2732
  this.root.push(buildHyperlinkHoverObj(linkId, true));
2733
2733
  }
2734
2734
  }
@@ -3010,7 +3010,7 @@ var init_media$1 = __esmMin((() => {
3010
3010
  *
3011
3011
  * @returns Read-only array of all media data in the collection
3012
3012
  */
3013
- get Array() {
3013
+ get array() {
3014
3014
  return [...this.map.values()];
3015
3015
  }
3016
3016
  };
@@ -3073,8 +3073,8 @@ var init_image_run = __esmMin((() => {
3073
3073
  this.extraChildren.push(drawing);
3074
3074
  }
3075
3075
  prepForXml(context) {
3076
- context.file.Media.addImage(this.imageData.fileName, this.imageData);
3077
- if (this.imageData.type === "svg") context.file.Media.addImage(this.imageData.fallback.fileName, this.imageData.fallback);
3076
+ context.file.media.addImage(this.imageData.fileName, this.imageData);
3077
+ if (this.imageData.type === "svg") context.file.media.addImage(this.imageData.fallback.fileName, this.imageData.fallback);
3078
3078
  return super.prepForXml(context);
3079
3079
  }
3080
3080
  };
@@ -3117,7 +3117,7 @@ var init_chart_run = __esmMin((() => {
3117
3117
  title: this.chartOptions.title,
3118
3118
  type: this.chartOptions.type
3119
3119
  });
3120
- context.file.Charts.addChart(this.chartKey, {
3120
+ context.file.charts.addChart(this.chartKey, {
3121
3121
  chartSpace,
3122
3122
  key: this.chartKey
3123
3123
  });
@@ -3174,7 +3174,7 @@ var init_smartart_run = __esmMin((() => {
3174
3174
  style: styleId,
3175
3175
  color: colorId
3176
3176
  };
3177
- context.file.SmartArts.addSmartArt(this.smartArtKey, smartArtData);
3177
+ context.file.smartArts.addSmartArt(this.smartArtKey, smartArtData);
3178
3178
  return super.prepForXml(context);
3179
3179
  }
3180
3180
  hashSmartArtData(options) {
@@ -3242,8 +3242,8 @@ var init_wpg_group_run = __esmMin((() => {
3242
3242
  }
3243
3243
  prepForXml(context) {
3244
3244
  this.mediaDatas.forEach((child) => {
3245
- context.file.Media.addImage(child.fileName, child);
3246
- if (child.type === "svg") context.file.Media.addImage(child.fallback.fileName, child.fallback);
3245
+ context.file.media.addImage(child.fileName, child);
3246
+ if (child.type === "svg") context.file.media.addImage(child.fallback.fileName, child.fallback);
3247
3247
  });
3248
3248
  return super.prepForXml(context);
3249
3249
  }
@@ -3503,12 +3503,9 @@ var init_font_wrapper = __esmMin((() => {
3503
3503
  this.relationships = new Relationships();
3504
3504
  for (let i = 0; i < options.length; i++) this.relationships.addRelationship(i + 1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/font", `fonts/${options[i].name}.odttf`);
3505
3505
  }
3506
- get View() {
3506
+ get view() {
3507
3507
  return this.fontTable;
3508
3508
  }
3509
- get Relationships() {
3510
- return this.relationships;
3511
- }
3512
3509
  };
3513
3510
  }));
3514
3511
  //#endregion
@@ -4486,7 +4483,7 @@ var init_math_fraction_properties = __esmMin((() => {
4486
4483
  if (options.fractionType) children.push(new BuilderElement({
4487
4484
  attributes: { val: {
4488
4485
  key: "m:val",
4489
- value: FractionType[options.fractionType]
4486
+ value: options.fractionType
4490
4487
  } },
4491
4488
  name: "m:type"
4492
4489
  }));
@@ -6287,7 +6284,7 @@ var init_properties = __esmMin((() => {
6287
6284
  * @returns The prepared XML object, or undefined if the component should be ignored
6288
6285
  */
6289
6286
  prepForXml(context) {
6290
- if (!(context.viewWrapper instanceof FontWrapper)) for (const reference of this.numberingReferences) context.file.Numbering.createConcreteNumberingInstance(reference.reference, reference.instance);
6287
+ if (!(context.viewWrapper instanceof FontWrapper)) for (const reference of this.numberingReferences) context.file.numbering.createConcreteNumberingInstance(reference.reference, reference.instance);
6291
6288
  return super.prepForXml(context);
6292
6289
  }
6293
6290
  };
@@ -6346,7 +6343,7 @@ var init_paragraph$1 = __esmMin((() => {
6346
6343
  prepForXml(context) {
6347
6344
  const children = [];
6348
6345
  const { xml: pPrObj, numberingReferences } = this._props;
6349
- if (!(context.viewWrapper instanceof FontWrapper)) for (const reference of numberingReferences) context.file.Numbering.createConcreteNumberingInstance(reference.reference, reference.instance);
6346
+ if (!(context.viewWrapper instanceof FontWrapper)) for (const reference of numberingReferences) context.file.numbering.createConcreteNumberingInstance(reference.reference, reference.instance);
6350
6347
  let finalPPrObj = pPrObj;
6351
6348
  if (this.sectionProperties) {
6352
6349
  const sectPrObj = this.sectionProperties.prepForXml(context);
@@ -6365,7 +6362,7 @@ var init_paragraph$1 = __esmMin((() => {
6365
6362
  if (this.options.children) for (const rawChild of this.options.children) {
6366
6363
  if (rawChild instanceof ExternalHyperlink) {
6367
6364
  const concreteHyperlink = new ConcreteHyperlink(rawChild.options.children, uniqueId(), { tooltip: rawChild.options.tooltip });
6368
- context.viewWrapper.Relationships.addRelationship(concreteHyperlink.linkId, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", rawChild.options.link, TargetModeType.EXTERNAL);
6365
+ context.viewWrapper.relationships.addRelationship(concreteHyperlink.linkId, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", rawChild.options.link, TargetModeType.EXTERNAL);
6369
6366
  const obj = concreteHyperlink.prepForXml(context);
6370
6367
  if (obj) children.push(obj);
6371
6368
  continue;
@@ -6400,7 +6397,7 @@ var init_paragraph$1 = __esmMin((() => {
6400
6397
  children: textRuns
6401
6398
  });
6402
6399
  const concrete = new ConcreteHyperlink(ext.options.children, uniqueId(), { tooltip: ext.options.tooltip });
6403
- context.viewWrapper.Relationships.addRelationship(concrete.linkId, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", ext.options.link, TargetModeType.EXTERNAL);
6400
+ context.viewWrapper.relationships.addRelationship(concrete.linkId, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", ext.options.link, TargetModeType.EXTERNAL);
6404
6401
  const obj = concrete.prepForXml(context);
6405
6402
  if (obj) children.push(obj);
6406
6403
  } else if ("anchor" in hyperlink) {
@@ -6528,9 +6525,6 @@ var init_comment_run = __esmMin((() => {
6528
6525
  for (const child of children) this.root.push(new Comment(child));
6529
6526
  this.relationships = new Relationships();
6530
6527
  }
6531
- get Relationships() {
6532
- return this.relationships;
6533
- }
6534
6528
  };
6535
6529
  }));
6536
6530
  //#endregion
@@ -6694,7 +6688,7 @@ var init_ruby = __esmMin((() => {
6694
6688
  name
6695
6689
  });
6696
6690
  createRuby = (options) => {
6697
- const align = options.alignment ?? "CENTER";
6691
+ const align = options.alignment ?? "center";
6698
6692
  const hps = options.fontSize ?? 20;
6699
6693
  const hpsRaise = options.raise ?? 20;
6700
6694
  const hpsBaseText = options.baseFontSize ?? 40;
@@ -6705,7 +6699,7 @@ var init_ruby = __esmMin((() => {
6705
6699
  new BuilderElement({
6706
6700
  attributes: { val: {
6707
6701
  key: "w:val",
6708
- value: RubyAlign[align]
6702
+ value: align
6709
6703
  } },
6710
6704
  name: "w:rubyAlign"
6711
6705
  }),
@@ -6867,15 +6861,15 @@ var init_alt_chunk = __esmMin((() => {
6867
6861
  const partPath = `afchunks/afchunk${relId}.${extension}`;
6868
6862
  const rawData = typeof this.options.data === "string" ? new TextEncoder().encode(this.options.data) : this.options.data;
6869
6863
  const data = this.options.contentType === "text/html" && typeof this.options.data === "string" ? new TextEncoder().encode(wrapHtmlDocument(this.options.data)) : rawData;
6870
- context.viewWrapper.Relationships.addRelationship(relId, ALTCHUNK_RELATIONSHIP_TYPE, partPath);
6871
- context.file.AltChunks.addAltChunk(relId, {
6864
+ context.viewWrapper.relationships.addRelationship(relId, ALTCHUNK_RELATIONSHIP_TYPE, partPath);
6865
+ context.file.altChunks.addAltChunk(relId, {
6872
6866
  key: relId,
6873
6867
  data,
6874
6868
  path: partPath,
6875
6869
  extension,
6876
6870
  contentType: this.options.contentType
6877
6871
  });
6878
- context.file.ContentTypes.addAltChunk(`/word/${partPath}`, this.options.contentType, extension);
6872
+ context.file.contentTypes.addAltChunk(`/word/${partPath}`, this.options.contentType, extension);
6879
6873
  return super.prepForXml(context);
6880
6874
  }
6881
6875
  };
@@ -7260,12 +7254,12 @@ var init_sub_doc = __esmMin((() => {
7260
7254
  const partPath = `subdocs/subdoc${relId}.docx`;
7261
7255
  this.root.splice(0, 0, { _attr: { "r:id": `rId${relId}` } });
7262
7256
  const data = typeof this.options.data === "string" ? new TextEncoder().encode(this.options.data) : this.options.data;
7263
- context.viewWrapper.Relationships.addRelationship(relId, SUBDOC_RELATIONSHIP_TYPE, partPath);
7264
- context.file.SubDocs.addSubDoc(relId, {
7257
+ context.viewWrapper.relationships.addRelationship(relId, SUBDOC_RELATIONSHIP_TYPE, partPath);
7258
+ context.file.subDocs.addSubDoc(relId, {
7265
7259
  data,
7266
7260
  path: partPath
7267
7261
  });
7268
- context.file.ContentTypes.addSubDoc(`/word/${partPath}`);
7262
+ context.file.contentTypes.addSubDoc(`/word/${partPath}`);
7269
7263
  return super.prepForXml(context);
7270
7264
  }
7271
7265
  };
@@ -7469,8 +7463,8 @@ function buildCellMergeObj(options) {
7469
7463
  "w:date": options.date,
7470
7464
  "w:id": options.id
7471
7465
  };
7472
- if (options.verticalMerge !== void 0) attrs["w:vMerge"] = options.verticalMerge;
7473
- if (options.verticalMergeOriginal !== void 0) attrs["w:vMergeOrig"] = options.verticalMergeOriginal;
7466
+ if (options.verticalMerge !== void 0) attrs["w:vMerge"] = xsdVerticalMergeRev.to(options.verticalMerge);
7467
+ if (options.verticalMergeOriginal !== void 0) attrs["w:vMergeOrig"] = xsdVerticalMergeRev.to(options.verticalMergeOriginal);
7474
7468
  return { "w:cellMerge": { _attr: attrs } };
7475
7469
  }
7476
7470
  var VerticalMergeRevisionType, CellMerge;
@@ -7480,11 +7474,11 @@ var init_cell_merge = __esmMin((() => {
7480
7474
  /**
7481
7475
  * Cell that is merged with upper one.
7482
7476
  */
7483
- CONTINUE: "cont",
7477
+ CONTINUE: "continue",
7484
7478
  /**
7485
7479
  * Cell that is starting the vertical merge.
7486
7480
  */
7487
- RESTART: "rest"
7481
+ RESTART: "restart"
7488
7482
  };
7489
7483
  CellMerge = class extends XmlComponent {
7490
7484
  constructor(options) {
@@ -7494,8 +7488,8 @@ var init_cell_merge = __esmMin((() => {
7494
7488
  "w:date": options.date,
7495
7489
  "w:id": options.id
7496
7490
  };
7497
- if (options.verticalMerge !== void 0) attrs["w:vMerge"] = options.verticalMerge;
7498
- if (options.verticalMergeOriginal !== void 0) attrs["w:vMergeOrig"] = options.verticalMergeOriginal;
7491
+ if (options.verticalMerge !== void 0) attrs["w:vMerge"] = xsdVerticalMergeRev.to(options.verticalMerge);
7492
+ if (options.verticalMergeOriginal !== void 0) attrs["w:vMergeOrig"] = xsdVerticalMergeRev.to(options.verticalMergeOriginal);
7499
7493
  this.root.push({ _attr: attrs });
7500
7494
  }
7501
7495
  };
@@ -8287,7 +8281,7 @@ var init_table_row$1 = __esmMin((() => {
8287
8281
  this.options = options;
8288
8282
  this.coercedChildren = options.children.map((child) => child instanceof TableCell || child instanceof StructuredDocumentTagCell || child instanceof StructuredDocumentTagRow ? child : new TableCell(child));
8289
8283
  }
8290
- get CellCount() {
8284
+ get cellCount() {
8291
8285
  return this.coercedChildren.length;
8292
8286
  }
8293
8287
  get cells() {
@@ -8548,8 +8542,8 @@ var init_sdt_row = __esmMin((() => {
8548
8542
  this.root.push(content);
8549
8543
  }
8550
8544
  }
8551
- get CellCount() {
8552
- return Math.max(...this.rows.map((r) => r.CellCount), 0);
8545
+ get cellCount() {
8546
+ return Math.max(...this.rows.map((r) => r.cellCount), 0);
8553
8547
  }
8554
8548
  get cells() {
8555
8549
  return this.rows.flatMap((r) => r.cells);
@@ -8613,7 +8607,7 @@ var init_table = __esmMin((() => {
8613
8607
  super("w:tbl");
8614
8608
  this.options = options;
8615
8609
  this.rows = options.rows.map((row) => row instanceof TableRow || row instanceof StructuredDocumentTagRow ? row : new TableRow(row));
8616
- this.columnWidths = options.columnWidths ?? Array(Math.max(...this.rows.map((row) => row.CellCount))).fill(100);
8610
+ this.columnWidths = options.columnWidths ?? Array(Math.max(...this.rows.map((row) => row.cellCount))).fill(100);
8617
8611
  this.rows.forEach((row, rowIndex) => {
8618
8612
  if (rowIndex === this.rows.length - 1) return;
8619
8613
  if (!(row instanceof TableRow)) return;
@@ -8851,7 +8845,7 @@ var AltChunkCollection = class {
8851
8845
  addAltChunk(key, data) {
8852
8846
  this.map.set(key, data);
8853
8847
  }
8854
- get Array() {
8848
+ get array() {
8855
8849
  return [...this.map.values()];
8856
8850
  }
8857
8851
  };
@@ -8954,9 +8948,6 @@ var Bibliography = class extends XmlComponent {
8954
8948
  for (const source of options.sources) this.root.push(new Source(source));
8955
8949
  this.relationships = new Relationships();
8956
8950
  }
8957
- get Relationships() {
8958
- return this.relationships;
8959
- }
8960
8951
  };
8961
8952
  //#endregion
8962
8953
  //#region src/file/content-types/content-types.ts
@@ -10329,15 +10320,15 @@ var SectionProperties = class extends XmlComponent {
10329
10320
  }
10330
10321
  addHeaderFooterGroup(type, group) {
10331
10322
  if (group.default) this.root.push(createHeaderFooterReference(type, {
10332
- id: group.default.View.ReferenceId,
10323
+ id: group.default.view.referenceId,
10333
10324
  type: HeaderFooterReferenceType.DEFAULT
10334
10325
  }));
10335
10326
  if (group.first) this.root.push(createHeaderFooterReference(type, {
10336
- id: group.first.View.ReferenceId,
10327
+ id: group.first.view.referenceId,
10337
10328
  type: HeaderFooterReferenceType.FIRST
10338
10329
  }));
10339
10330
  if (group.even) this.root.push(createHeaderFooterReference(type, {
10340
- id: group.even.View.ReferenceId,
10331
+ id: group.even.view.referenceId,
10341
10332
  type: HeaderFooterReferenceType.EVEN
10342
10333
  }));
10343
10334
  }
@@ -10552,7 +10543,7 @@ var DocumentBackground = class extends XmlComponent {
10552
10543
  }
10553
10544
  prepForXml(context) {
10554
10545
  if (this.imageData) {
10555
- context.file.Media.addImage(this.imageData.fileName, {
10546
+ context.file.media.addImage(this.imageData.fileName, {
10556
10547
  type: this.imageData.type,
10557
10548
  data: this.imageData.data,
10558
10549
  fileName: this.imageData.fileName,
@@ -10702,14 +10693,6 @@ var Document = class extends XmlComponent {
10702
10693
  this.body.push(item);
10703
10694
  return this;
10704
10695
  }
10705
- /**
10706
- * Gets the document body element.
10707
- *
10708
- * @returns The Body instance containing all document content
10709
- */
10710
- get Body() {
10711
- return this.body;
10712
- }
10713
10696
  };
10714
10697
  //#endregion
10715
10698
  //#region src/file/document-wrapper.ts
@@ -10746,12 +10729,9 @@ var DocumentWrapper = class {
10746
10729
  this.document = new Document(options);
10747
10730
  this.relationships = new Relationships();
10748
10731
  }
10749
- get View() {
10732
+ get view() {
10750
10733
  return this.document;
10751
10734
  }
10752
- get Relationships() {
10753
- return this.relationships;
10754
- }
10755
10735
  };
10756
10736
  //#endregion
10757
10737
  //#region src/file/footnotes/footnote/run/continuation-seperator.ts
@@ -10931,12 +10911,9 @@ var EndnotesWrapper = class {
10931
10911
  this.endnotes = new Endnotes();
10932
10912
  this.relationships = new Relationships();
10933
10913
  }
10934
- get View() {
10914
+ get view() {
10935
10915
  return this.endnotes;
10936
10916
  }
10937
- get Relationships() {
10938
- return this.relationships;
10939
- }
10940
10917
  };
10941
10918
  //#endregion
10942
10919
  //#region src/file/header-footer-base.ts
@@ -11010,7 +10987,7 @@ var HeaderFooterBase = class extends InitializableXmlComponent {
11010
10987
  this.refId = referenceNumber;
11011
10988
  if (!initContent) this.root.push(buildDocumentAttributes(namespaces));
11012
10989
  }
11013
- get ReferenceId() {
10990
+ get referenceId() {
11014
10991
  return this.refId;
11015
10992
  }
11016
10993
  add(item) {
@@ -11086,6 +11063,7 @@ init_relationships();
11086
11063
  var FooterWrapper = class {
11087
11064
  footer;
11088
11065
  relationships;
11066
+ media;
11089
11067
  constructor(media, referenceId, initContent) {
11090
11068
  this.media = media;
11091
11069
  this.footer = new Footer$1(referenceId, initContent);
@@ -11097,15 +11075,9 @@ var FooterWrapper = class {
11097
11075
  addChildElement(childElement) {
11098
11076
  this.footer.addChildElement(childElement);
11099
11077
  }
11100
- get View() {
11078
+ get view() {
11101
11079
  return this.footer;
11102
11080
  }
11103
- get Relationships() {
11104
- return this.relationships;
11105
- }
11106
- get Media() {
11107
- return this.media;
11108
- }
11109
11081
  };
11110
11082
  //#endregion
11111
11083
  //#region src/file/footnotes/footnote/run/footnote-ref.ts
@@ -11330,22 +11302,19 @@ init_relationships();
11330
11302
  * @example
11331
11303
  * ```typescript
11332
11304
  * const wrapper = new FootnotesWrapper();
11333
- * const footnotes = wrapper.View;
11334
- * const relationships = wrapper.Relationships;
11305
+ * const footnotes = wrapper.view;
11306
+ * const relationships = wrapper.relationships;
11335
11307
  * ```
11336
11308
  */
11337
11309
  var FootnotesWrapper = class {
11338
- footnotess;
11310
+ footnotes;
11339
11311
  relationships;
11340
11312
  constructor() {
11341
- this.footnotess = new FootNotes();
11313
+ this.footnotes = new FootNotes();
11342
11314
  this.relationships = new Relationships();
11343
11315
  }
11344
- get View() {
11345
- return this.footnotess;
11346
- }
11347
- get Relationships() {
11348
- return this.relationships;
11316
+ get view() {
11317
+ return this.footnotes;
11349
11318
  }
11350
11319
  };
11351
11320
  //#endregion
@@ -11462,6 +11431,7 @@ init_relationships();
11462
11431
  var HeaderWrapper = class {
11463
11432
  header;
11464
11433
  relationships;
11434
+ media;
11465
11435
  constructor(media, referenceId, initContent) {
11466
11436
  this.media = media;
11467
11437
  this.header = new Header$1(referenceId, initContent);
@@ -11474,15 +11444,9 @@ var HeaderWrapper = class {
11474
11444
  addChildElement(childElement) {
11475
11445
  this.header.addChildElement(childElement);
11476
11446
  }
11477
- get View() {
11447
+ get view() {
11478
11448
  return this.header;
11479
11449
  }
11480
- get Relationships() {
11481
- return this.relationships;
11482
- }
11483
- get Media() {
11484
- return this.media;
11485
- }
11486
11450
  };
11487
11451
  //#endregion
11488
11452
  //#region src/file/numbering/level.ts
@@ -12303,7 +12267,7 @@ var Numbering = class extends XmlComponent {
12303
12267
  *
12304
12268
  * @returns An array of all concrete numbering instances
12305
12269
  */
12306
- get ConcreteNumbering() {
12270
+ get concreteNumbering() {
12307
12271
  return [...this.concreteNumberingMap.values()];
12308
12272
  }
12309
12273
  /**
@@ -12311,7 +12275,7 @@ var Numbering = class extends XmlComponent {
12311
12275
  *
12312
12276
  * @returns An array of all numbering reference configurations
12313
12277
  */
12314
- get ReferenceConfig() {
12278
+ get referenceConfig() {
12315
12279
  return [...this.referenceConfigMap.values()];
12316
12280
  }
12317
12281
  };
@@ -13587,7 +13551,7 @@ var SubDocCollection = class {
13587
13551
  addSubDoc(key, data) {
13588
13552
  this.map.set(key, data);
13589
13553
  }
13590
- get Array() {
13554
+ get array() {
13591
13555
  return [...this.map.values()];
13592
13556
  }
13593
13557
  };
@@ -13681,10 +13645,10 @@ init_relationships();
13681
13645
  * ```
13682
13646
  */
13683
13647
  var File = class {
13684
- currentRelationshipId = 1;
13685
- documentWrapper;
13686
- headers = [];
13687
- footers = [];
13648
+ _currentRelationshipId = 1;
13649
+ document;
13650
+ _headers = [];
13651
+ _footers = [];
13688
13652
  coreProperties;
13689
13653
  numbering;
13690
13654
  media;
@@ -13693,8 +13657,8 @@ var File = class {
13693
13657
  altChunks;
13694
13658
  subDocs;
13695
13659
  fileRelationships;
13696
- footnotesWrapper;
13697
- endnotesWrapper;
13660
+ footNotes;
13661
+ endnotes;
13698
13662
  settings;
13699
13663
  contentTypes;
13700
13664
  customProperties;
@@ -13702,7 +13666,7 @@ var File = class {
13702
13666
  styles;
13703
13667
  comments;
13704
13668
  bibliography;
13705
- fontWrapper;
13669
+ fontTable;
13706
13670
  constructor(options) {
13707
13671
  this.coreProperties = new CoreProperties({
13708
13672
  ...options,
@@ -13716,10 +13680,10 @@ var File = class {
13716
13680
  this.fileRelationships = new Relationships();
13717
13681
  this.customProperties = new CustomProperties(options.customProperties ?? []);
13718
13682
  this.appProperties = new AppProperties();
13719
- this.footnotesWrapper = new FootnotesWrapper();
13720
- this.endnotesWrapper = new EndnotesWrapper();
13683
+ this.footNotes = new FootnotesWrapper();
13684
+ this.endnotes = new EndnotesWrapper();
13721
13685
  this.contentTypes = new ContentTypes();
13722
- this.documentWrapper = new DocumentWrapper({ background: options.background });
13686
+ this.document = new DocumentWrapper({ background: options.background });
13723
13687
  this.settings = new Settings({
13724
13688
  compatibility: options.compatibility,
13725
13689
  compatibilityModeVersion: options.compatabilityModeVersion,
@@ -13772,16 +13736,16 @@ var File = class {
13772
13736
  for (const section of options.sections) this.addSection(section);
13773
13737
  if (options.footnotes) for (const key in options.footnotes) {
13774
13738
  const children = options.footnotes[key].children.map((p) => p instanceof Paragraph ? p : new Paragraph(p));
13775
- this.footnotesWrapper.View.createFootNote(parseFloat(key), children);
13739
+ this.footNotes.view.createFootNote(parseFloat(key), children);
13776
13740
  }
13777
13741
  if (options.endnotes) for (const key in options.endnotes) {
13778
13742
  const children = options.endnotes[key].children.map((p) => p instanceof Paragraph ? p : new Paragraph(p));
13779
- this.endnotesWrapper.View.createEndnote(parseFloat(key), children);
13743
+ this.endnotes.view.createEndnote(parseFloat(key), children);
13780
13744
  }
13781
- this.fontWrapper = new FontWrapper(options.fonts ?? []);
13745
+ this.fontTable = new FontWrapper(options.fonts ?? []);
13782
13746
  }
13783
13747
  addSection({ headers = {}, footers = {}, children, properties }) {
13784
- this.documentWrapper.View.Body.addSection({
13748
+ this.document.view.body.addSection({
13785
13749
  ...properties,
13786
13750
  footerWrapperGroup: {
13787
13751
  default: footers.default ? this.createFooter(footers.default) : void 0,
@@ -13794,113 +13758,56 @@ var File = class {
13794
13758
  first: headers.first ? this.createHeader(headers.first) : void 0
13795
13759
  }
13796
13760
  });
13797
- for (const rawChild of children) this.documentWrapper.View.add(coerceSectionChild(rawChild));
13761
+ for (const rawChild of children) this.document.view.add(coerceSectionChild(rawChild));
13798
13762
  }
13799
13763
  createHeader(header) {
13800
- const wrapper = new HeaderWrapper(this.media, this.currentRelationshipId++);
13764
+ const wrapper = new HeaderWrapper(this.media, this._currentRelationshipId++);
13801
13765
  const children = header instanceof Header ? header.options.children : header;
13802
13766
  for (const rawChild of children) wrapper.add(coerceSectionChild(rawChild));
13803
13767
  this.addHeaderToDocument(wrapper);
13804
13768
  return wrapper;
13805
13769
  }
13806
13770
  createFooter(footer) {
13807
- const wrapper = new FooterWrapper(this.media, this.currentRelationshipId++);
13771
+ const wrapper = new FooterWrapper(this.media, this._currentRelationshipId++);
13808
13772
  const children = footer instanceof Footer ? footer.options.children : footer;
13809
13773
  for (const rawChild of children) wrapper.add(coerceSectionChild(rawChild));
13810
13774
  this.addFooterToDocument(wrapper);
13811
13775
  return wrapper;
13812
13776
  }
13813
13777
  addHeaderToDocument(header, type = HeaderFooterReferenceType.DEFAULT) {
13814
- this.headers.push({
13778
+ this._headers.push({
13815
13779
  header,
13816
13780
  type
13817
13781
  });
13818
- this.documentWrapper.Relationships.addRelationship(header.View.ReferenceId, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header", `header${this.headers.length}.xml`);
13819
- this.contentTypes.addHeader(this.headers.length);
13782
+ this.document.relationships.addRelationship(header.view.referenceId, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header", `header${this._headers.length}.xml`);
13783
+ this.contentTypes.addHeader(this._headers.length);
13820
13784
  }
13821
13785
  addFooterToDocument(footer, type = HeaderFooterReferenceType.DEFAULT) {
13822
- this.footers.push({
13786
+ this._footers.push({
13823
13787
  footer,
13824
13788
  type
13825
13789
  });
13826
- this.documentWrapper.Relationships.addRelationship(footer.View.ReferenceId, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer", `footer${this.footers.length}.xml`);
13827
- this.contentTypes.addFooter(this.footers.length);
13790
+ this.document.relationships.addRelationship(footer.view.referenceId, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer", `footer${this._footers.length}.xml`);
13791
+ this.contentTypes.addFooter(this._footers.length);
13828
13792
  }
13829
13793
  addDefaultRelationships() {
13830
13794
  this.fileRelationships.addRelationship(1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument", "word/document.xml");
13831
13795
  this.fileRelationships.addRelationship(2, "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties", "docProps/core.xml");
13832
13796
  this.fileRelationships.addRelationship(3, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties", "docProps/app.xml");
13833
13797
  this.fileRelationships.addRelationship(4, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties", "docProps/custom.xml");
13834
- this.documentWrapper.Relationships.addRelationship(this.currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles", "styles.xml");
13835
- this.documentWrapper.Relationships.addRelationship(this.currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering", "numbering.xml");
13836
- this.documentWrapper.Relationships.addRelationship(this.currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes", "footnotes.xml");
13837
- this.documentWrapper.Relationships.addRelationship(this.currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes", "endnotes.xml");
13838
- this.documentWrapper.Relationships.addRelationship(this.currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings", "settings.xml");
13839
- this.documentWrapper.Relationships.addRelationship(this.currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments", "comments.xml");
13840
- if (this.bibliography) this.documentWrapper.Relationships.addRelationship(this.currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/bibliography", "bibliography.xml");
13841
- }
13842
- get Document() {
13843
- return this.documentWrapper;
13844
- }
13845
- get Styles() {
13846
- return this.styles;
13847
- }
13848
- get CoreProperties() {
13849
- return this.coreProperties;
13850
- }
13851
- get Numbering() {
13852
- return this.numbering;
13853
- }
13854
- get Media() {
13855
- return this.media;
13856
- }
13857
- get Charts() {
13858
- return this.charts;
13859
- }
13860
- get SmartArts() {
13861
- return this.smartArts;
13862
- }
13863
- get AltChunks() {
13864
- return this.altChunks;
13865
- }
13866
- get SubDocs() {
13867
- return this.subDocs;
13868
- }
13869
- get FileRelationships() {
13870
- return this.fileRelationships;
13871
- }
13872
- get Headers() {
13873
- return this.headers.map((item) => item.header);
13874
- }
13875
- get Footers() {
13876
- return this.footers.map((item) => item.footer);
13798
+ this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles", "styles.xml");
13799
+ this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering", "numbering.xml");
13800
+ this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes", "footnotes.xml");
13801
+ this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes", "endnotes.xml");
13802
+ this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings", "settings.xml");
13803
+ this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments", "comments.xml");
13804
+ if (this.bibliography) this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/bibliography", "bibliography.xml");
13877
13805
  }
13878
- get ContentTypes() {
13879
- return this.contentTypes;
13806
+ get headers() {
13807
+ return this._headers.map((item) => item.header);
13880
13808
  }
13881
- get CustomProperties() {
13882
- return this.customProperties;
13883
- }
13884
- get AppProperties() {
13885
- return this.appProperties;
13886
- }
13887
- get FootNotes() {
13888
- return this.footnotesWrapper;
13889
- }
13890
- get Endnotes() {
13891
- return this.endnotesWrapper;
13892
- }
13893
- get Settings() {
13894
- return this.settings;
13895
- }
13896
- get Comments() {
13897
- return this.comments;
13898
- }
13899
- get Bibliography() {
13900
- return this.bibliography;
13901
- }
13902
- get FontTable() {
13903
- return this.fontWrapper;
13809
+ get footers() {
13810
+ return this._footers.map((item) => item.footer);
13904
13811
  }
13905
13812
  };
13906
13813
  //#endregion
@@ -14684,23 +14591,23 @@ var Compiler = class {
14684
14591
  files[fileObj.path] = typeof fileObj.data === "string" ? textToUint8Array(fileObj.data) : fileObj.data;
14685
14592
  }
14686
14593
  for (const subFile of overrides) files[subFile.path] = typeof subFile.data === "string" ? textToUint8Array(subFile.data) : subFile.data;
14687
- for (const mediaData of file.Media.Array) {
14594
+ for (const mediaData of file.media.array) {
14688
14595
  files[`word/media/${mediaData.fileName}`] = [toUint8Array(mediaData.data), { level: ZIP_STORED_LEVEL }];
14689
14596
  if (mediaData.type === "svg") files[`word/media/${mediaData.fallback.fileName}`] = [toUint8Array(mediaData.fallback.data), { level: ZIP_STORED_LEVEL }];
14690
14597
  }
14691
- for (const { data: buffer, name, fontKey } of file.FontTable.fontOptionsWithKey) {
14598
+ for (const { data: buffer, name, fontKey } of file.fontTable.fontOptionsWithKey) {
14692
14599
  const [nameWithoutExtension] = name.split(".");
14693
14600
  files[`word/fonts/${nameWithoutExtension}.odttf`] = obfuscate(buffer, fontKey);
14694
14601
  }
14695
14602
  return files;
14696
14603
  }
14697
14604
  xmlifyFile(file, headerFormattedViews, footerFormattedViews, prettify) {
14698
- const documentRelationshipCount = file.Document.Relationships.RelationshipCount + 1;
14699
- const documentXmlData = xml(this.formatter.format(file.Document.View, {
14605
+ const documentRelationshipCount = file.document.relationships.relationshipCount + 1;
14606
+ const documentXmlData = xml(this.formatter.format(file.document.view, {
14700
14607
  fileData: file,
14701
14608
  file,
14702
14609
  stack: [],
14703
- viewWrapper: file.Document
14610
+ viewWrapper: file.document
14704
14611
  }), {
14705
14612
  declaration: {
14706
14613
  encoding: "UTF-8",
@@ -14708,14 +14615,14 @@ var Compiler = class {
14708
14615
  },
14709
14616
  indent: prettify
14710
14617
  });
14711
- const commentRelationshipCount = file.Comments.Relationships.RelationshipCount + 1;
14712
- const commentXmlData = xml(this.formatter.format(file.Comments, {
14618
+ const commentRelationshipCount = file.comments.relationships.relationshipCount + 1;
14619
+ const commentXmlData = xml(this.formatter.format(file.comments, {
14713
14620
  fileData: file,
14714
14621
  file,
14715
14622
  stack: [],
14716
14623
  viewWrapper: {
14717
- Relationships: file.Comments.Relationships,
14718
- View: file.Comments
14624
+ relationships: file.comments.relationships,
14625
+ view: file.comments
14719
14626
  }
14720
14627
  }), {
14721
14628
  declaration: {
@@ -14724,12 +14631,12 @@ var Compiler = class {
14724
14631
  },
14725
14632
  indent: prettify
14726
14633
  });
14727
- const footnoteRelationshipCount = file.FootNotes.Relationships.RelationshipCount + 1;
14728
- const footnoteXmlData = xml(this.formatter.format(file.FootNotes.View, {
14634
+ const footnoteRelationshipCount = file.footNotes.relationships.relationshipCount + 1;
14635
+ const footnoteXmlData = xml(this.formatter.format(file.footNotes.view, {
14729
14636
  fileData: file,
14730
14637
  file,
14731
14638
  stack: [],
14732
- viewWrapper: file.FootNotes
14639
+ viewWrapper: file.footNotes
14733
14640
  }), {
14734
14641
  declaration: {
14735
14642
  encoding: "UTF-8",
@@ -14737,16 +14644,16 @@ var Compiler = class {
14737
14644
  },
14738
14645
  indent: prettify
14739
14646
  });
14740
- const documentMediaDatas = hasPlaceholders(documentXmlData) ? getReferencedMedia(documentXmlData, file.Media.Array) : [];
14741
- const commentMediaDatas = hasPlaceholders(commentXmlData) ? getReferencedMedia(commentXmlData, file.Media.Array) : [];
14742
- const footnoteMediaDatas = hasPlaceholders(footnoteXmlData) ? getReferencedMedia(footnoteXmlData, file.Media.Array) : [];
14647
+ const documentMediaDatas = hasPlaceholders(documentXmlData) ? getReferencedMedia(documentXmlData, file.media.array) : [];
14648
+ const commentMediaDatas = hasPlaceholders(commentXmlData) ? getReferencedMedia(commentXmlData, file.media.array) : [];
14649
+ const footnoteMediaDatas = hasPlaceholders(footnoteXmlData) ? getReferencedMedia(footnoteXmlData, file.media.array) : [];
14743
14650
  return {
14744
14651
  AppProperties: {
14745
- data: xml(this.formatter.format(file.AppProperties, {
14652
+ data: xml(this.formatter.format(file.appProperties, {
14746
14653
  fileData: file,
14747
14654
  file,
14748
14655
  stack: [],
14749
- viewWrapper: file.Document
14656
+ viewWrapper: file.document
14750
14657
  }), { declaration: {
14751
14658
  encoding: "UTF-8",
14752
14659
  standalone: "yes"
@@ -14754,21 +14661,21 @@ var Compiler = class {
14754
14661
  path: "docProps/app.xml"
14755
14662
  },
14756
14663
  Comments: {
14757
- data: replaceNumberingPlaceholders(commentMediaDatas.length > 0 ? replaceImagePlaceholders(commentXmlData, commentMediaDatas, commentRelationshipCount, "rId") : commentXmlData, file.Numbering.ConcreteNumbering),
14664
+ data: replaceNumberingPlaceholders(commentMediaDatas.length > 0 ? replaceImagePlaceholders(commentXmlData, commentMediaDatas, commentRelationshipCount, "rId") : commentXmlData, file.numbering.concreteNumbering),
14758
14665
  path: "word/comments.xml"
14759
14666
  },
14760
14667
  CommentsRelationships: {
14761
14668
  data: (() => {
14762
14669
  commentMediaDatas.forEach((mediaData, i) => {
14763
- file.Comments.Relationships.addRelationship(commentRelationshipCount + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaData.fileName}`);
14670
+ file.comments.relationships.addRelationship(commentRelationshipCount + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaData.fileName}`);
14764
14671
  });
14765
- return xml(this.formatter.format(file.Comments.Relationships, {
14672
+ return xml(this.formatter.format(file.comments.relationships, {
14766
14673
  fileData: file,
14767
14674
  file,
14768
14675
  stack: [],
14769
14676
  viewWrapper: {
14770
- Relationships: file.Comments.Relationships,
14771
- View: file.Comments
14677
+ relationships: file.comments.relationships,
14678
+ view: file.comments
14772
14679
  }
14773
14680
  }), {
14774
14681
  declaration: { encoding: "UTF-8" },
@@ -14779,21 +14686,21 @@ var Compiler = class {
14779
14686
  },
14780
14687
  ContentTypes: {
14781
14688
  data: (() => {
14782
- file.Charts.Array.forEach((_, i) => {
14783
- file.ContentTypes.addChart(i + 1);
14689
+ file.charts.array.forEach((_, i) => {
14690
+ file.contentTypes.addChart(i + 1);
14784
14691
  });
14785
- file.SmartArts.Array.forEach((_, i) => {
14786
- file.ContentTypes.addDiagramData(i + 1);
14787
- file.ContentTypes.addDiagramLayout(i + 1);
14788
- file.ContentTypes.addDiagramStyle(i + 1);
14789
- file.ContentTypes.addDiagramColors(i + 1);
14790
- file.ContentTypes.addDiagramDrawing(i + 1);
14692
+ file.smartArts.array.forEach((_, i) => {
14693
+ file.contentTypes.addDiagramData(i + 1);
14694
+ file.contentTypes.addDiagramLayout(i + 1);
14695
+ file.contentTypes.addDiagramStyle(i + 1);
14696
+ file.contentTypes.addDiagramColors(i + 1);
14697
+ file.contentTypes.addDiagramDrawing(i + 1);
14791
14698
  });
14792
- return xml(this.formatter.format(file.ContentTypes, {
14699
+ return xml(this.formatter.format(file.contentTypes, {
14793
14700
  fileData: file,
14794
14701
  file,
14795
14702
  stack: [],
14796
- viewWrapper: file.Document
14703
+ viewWrapper: file.document
14797
14704
  }), {
14798
14705
  declaration: { encoding: "UTF-8" },
14799
14706
  indent: prettify
@@ -14802,11 +14709,11 @@ var Compiler = class {
14802
14709
  path: "[Content_Types].xml"
14803
14710
  },
14804
14711
  CustomProperties: {
14805
- data: xml(this.formatter.format(file.CustomProperties, {
14712
+ data: xml(this.formatter.format(file.customProperties, {
14806
14713
  fileData: file,
14807
14714
  file,
14808
14715
  stack: [],
14809
- viewWrapper: file.Document
14716
+ viewWrapper: file.document
14810
14717
  }), {
14811
14718
  declaration: {
14812
14719
  encoding: "UTF-8",
@@ -14820,20 +14727,20 @@ var Compiler = class {
14820
14727
  data: (() => {
14821
14728
  let xmlData = documentMediaDatas.length > 0 ? replaceImagePlaceholders(documentXmlData, documentMediaDatas, documentRelationshipCount, "rId") : documentXmlData;
14822
14729
  if (hasPlaceholders(xmlData)) {
14823
- xmlData = replaceChartPlaceholders(xmlData, file.Charts.Array.map((c) => c.key), documentRelationshipCount + documentMediaDatas.length, "rId");
14824
- const smartArtDataOffset = documentRelationshipCount + documentMediaDatas.length + file.Charts.Array.length;
14825
- xmlData = replaceSmartArtPlaceholders(xmlData, file.SmartArts.Array.map((s) => s.key), smartArtDataOffset, "rId");
14730
+ xmlData = replaceChartPlaceholders(xmlData, file.charts.array.map((c) => c.key), documentRelationshipCount + documentMediaDatas.length, "rId");
14731
+ const smartArtDataOffset = documentRelationshipCount + documentMediaDatas.length + file.charts.array.length;
14732
+ xmlData = replaceSmartArtPlaceholders(xmlData, file.smartArts.array.map((s) => s.key), smartArtDataOffset, "rId");
14826
14733
  }
14827
- return replaceNumberingPlaceholders(xmlData, file.Numbering.ConcreteNumbering);
14734
+ return replaceNumberingPlaceholders(xmlData, file.numbering.concreteNumbering);
14828
14735
  })(),
14829
14736
  path: "word/document.xml"
14830
14737
  },
14831
14738
  Endnotes: {
14832
- data: xml(this.formatter.format(file.Endnotes.View, {
14739
+ data: xml(this.formatter.format(file.endnotes.view, {
14833
14740
  fileData: file,
14834
14741
  file,
14835
14742
  stack: [],
14836
- viewWrapper: file.Endnotes
14743
+ viewWrapper: file.endnotes
14837
14744
  }), {
14838
14745
  declaration: { encoding: "UTF-8" },
14839
14746
  indent: prettify
@@ -14841,11 +14748,11 @@ var Compiler = class {
14841
14748
  path: "word/endnotes.xml"
14842
14749
  },
14843
14750
  EndnotesRelationships: {
14844
- data: xml(this.formatter.format(file.Endnotes.Relationships, {
14751
+ data: xml(this.formatter.format(file.endnotes.relationships, {
14845
14752
  fileData: file,
14846
14753
  file,
14847
14754
  stack: [],
14848
- viewWrapper: file.Endnotes
14755
+ viewWrapper: file.endnotes
14849
14756
  }), {
14850
14757
  declaration: { encoding: "UTF-8" },
14851
14758
  indent: prettify
@@ -14853,11 +14760,11 @@ var Compiler = class {
14853
14760
  path: "word/_rels/endnotes.xml.rels"
14854
14761
  },
14855
14762
  FileRelationships: {
14856
- data: xml(this.formatter.format(file.FileRelationships, {
14763
+ data: xml(this.formatter.format(file.fileRelationships, {
14857
14764
  fileData: file,
14858
14765
  file,
14859
14766
  stack: [],
14860
- viewWrapper: file.Document
14767
+ viewWrapper: file.document
14861
14768
  }), {
14862
14769
  declaration: { encoding: "UTF-8" },
14863
14770
  indent: prettify
@@ -14865,11 +14772,11 @@ var Compiler = class {
14865
14772
  path: "_rels/.rels"
14866
14773
  },
14867
14774
  FontTable: {
14868
- data: xml(this.formatter.format(file.FontTable.View, {
14775
+ data: xml(this.formatter.format(file.fontTable.view, {
14869
14776
  fileData: file,
14870
14777
  file,
14871
14778
  stack: [],
14872
- viewWrapper: file.Document
14779
+ viewWrapper: file.document
14873
14780
  }), {
14874
14781
  declaration: {
14875
14782
  encoding: "UTF-8",
@@ -14880,11 +14787,11 @@ var Compiler = class {
14880
14787
  path: "word/fontTable.xml"
14881
14788
  },
14882
14789
  FontTableRelationships: {
14883
- data: xml(this.formatter.format(file.FontTable.Relationships, {
14790
+ data: xml(this.formatter.format(file.fontTable.relationships, {
14884
14791
  fileData: file,
14885
14792
  file,
14886
14793
  stack: [],
14887
- viewWrapper: file.Document
14794
+ viewWrapper: file.document
14888
14795
  }), {
14889
14796
  declaration: { encoding: "UTF-8" },
14890
14797
  indent: prettify
@@ -14892,19 +14799,19 @@ var Compiler = class {
14892
14799
  path: "word/_rels/fontTable.xml.rels"
14893
14800
  },
14894
14801
  FootNotes: {
14895
- data: replaceNumberingPlaceholders(footnoteMediaDatas.length > 0 ? replaceImagePlaceholders(footnoteXmlData, footnoteMediaDatas, footnoteRelationshipCount, "rId") : footnoteXmlData, file.Numbering.ConcreteNumbering),
14802
+ data: replaceNumberingPlaceholders(footnoteMediaDatas.length > 0 ? replaceImagePlaceholders(footnoteXmlData, footnoteMediaDatas, footnoteRelationshipCount, "rId") : footnoteXmlData, file.numbering.concreteNumbering),
14896
14803
  path: "word/footnotes.xml"
14897
14804
  },
14898
14805
  FootNotesRelationships: {
14899
14806
  data: (() => {
14900
14807
  footnoteMediaDatas.forEach((mediaData, i) => {
14901
- file.FootNotes.Relationships.addRelationship(footnoteRelationshipCount + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaData.fileName}`);
14808
+ file.footNotes.relationships.addRelationship(footnoteRelationshipCount + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaData.fileName}`);
14902
14809
  });
14903
- return xml(this.formatter.format(file.FootNotes.Relationships, {
14810
+ return xml(this.formatter.format(file.footNotes.relationships, {
14904
14811
  fileData: file,
14905
14812
  file,
14906
14813
  stack: [],
14907
- viewWrapper: file.FootNotes
14814
+ viewWrapper: file.footNotes
14908
14815
  }), {
14909
14816
  declaration: { encoding: "UTF-8" },
14910
14817
  indent: prettify
@@ -14912,8 +14819,8 @@ var Compiler = class {
14912
14819
  })(),
14913
14820
  path: "word/_rels/footnotes.xml.rels"
14914
14821
  },
14915
- FooterRelationships: file.Footers.map((footerWrapper, index) => {
14916
- const xmlData = xml(this.formatter.format(footerWrapper.View, {
14822
+ FooterRelationships: file.footers.map((footerWrapper, index) => {
14823
+ const xmlData = xml(this.formatter.format(footerWrapper.view, {
14917
14824
  fileData: file,
14918
14825
  file,
14919
14826
  stack: [],
@@ -14923,11 +14830,11 @@ var Compiler = class {
14923
14830
  indent: prettify
14924
14831
  });
14925
14832
  footerFormattedViews.set(index, xmlData);
14926
- getReferencedMedia(xmlData, file.Media.Array).forEach((mediaData, i) => {
14927
- footerWrapper.Relationships.addRelationship(i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaData.fileName}`);
14833
+ getReferencedMedia(xmlData, file.media.array).forEach((mediaData, i) => {
14834
+ footerWrapper.relationships.addRelationship(i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaData.fileName}`);
14928
14835
  });
14929
14836
  return {
14930
- data: xml(this.formatter.format(footerWrapper.Relationships, {
14837
+ data: xml(this.formatter.format(footerWrapper.relationships, {
14931
14838
  fileData: file,
14932
14839
  file,
14933
14840
  stack: [],
@@ -14939,16 +14846,16 @@ var Compiler = class {
14939
14846
  path: `word/_rels/footer${index + 1}.xml.rels`
14940
14847
  };
14941
14848
  }),
14942
- Footers: file.Footers.map((_footerWrapper, index) => {
14849
+ Footers: file.footers.map((_footerWrapper, index) => {
14943
14850
  const tempXmlData = footerFormattedViews.get(index);
14944
- const mediaDatas = hasPlaceholders(tempXmlData) ? getReferencedMedia(tempXmlData, file.Media.Array) : [];
14851
+ const mediaDatas = hasPlaceholders(tempXmlData) ? getReferencedMedia(tempXmlData, file.media.array) : [];
14945
14852
  return {
14946
- data: replaceNumberingPlaceholders(mediaDatas.length > 0 ? replaceImagePlaceholders(tempXmlData, mediaDatas, 0, "rId") : tempXmlData, file.Numbering.ConcreteNumbering),
14853
+ data: replaceNumberingPlaceholders(mediaDatas.length > 0 ? replaceImagePlaceholders(tempXmlData, mediaDatas, 0, "rId") : tempXmlData, file.numbering.concreteNumbering),
14947
14854
  path: `word/footer${index + 1}.xml`
14948
14855
  };
14949
14856
  }),
14950
- HeaderRelationships: file.Headers.map((headerWrapper, index) => {
14951
- const xmlData = xml(this.formatter.format(headerWrapper.View, {
14857
+ HeaderRelationships: file.headers.map((headerWrapper, index) => {
14858
+ const xmlData = xml(this.formatter.format(headerWrapper.view, {
14952
14859
  fileData: file,
14953
14860
  file,
14954
14861
  stack: [],
@@ -14958,11 +14865,11 @@ var Compiler = class {
14958
14865
  indent: prettify
14959
14866
  });
14960
14867
  headerFormattedViews.set(index, xmlData);
14961
- getReferencedMedia(xmlData, file.Media.Array).forEach((mediaData, i) => {
14962
- headerWrapper.Relationships.addRelationship(i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaData.fileName}`);
14868
+ getReferencedMedia(xmlData, file.media.array).forEach((mediaData, i) => {
14869
+ headerWrapper.relationships.addRelationship(i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaData.fileName}`);
14963
14870
  });
14964
14871
  return {
14965
- data: xml(this.formatter.format(headerWrapper.Relationships, {
14872
+ data: xml(this.formatter.format(headerWrapper.relationships, {
14966
14873
  fileData: file,
14967
14874
  file,
14968
14875
  stack: [],
@@ -14974,20 +14881,20 @@ var Compiler = class {
14974
14881
  path: `word/_rels/header${index + 1}.xml.rels`
14975
14882
  };
14976
14883
  }),
14977
- Headers: file.Headers.map((_headerWrapper, index) => {
14884
+ Headers: file.headers.map((_headerWrapper, index) => {
14978
14885
  const tempXmlData = headerFormattedViews.get(index);
14979
- const mediaDatas = hasPlaceholders(tempXmlData) ? getReferencedMedia(tempXmlData, file.Media.Array) : [];
14886
+ const mediaDatas = hasPlaceholders(tempXmlData) ? getReferencedMedia(tempXmlData, file.media.array) : [];
14980
14887
  return {
14981
- data: replaceNumberingPlaceholders(mediaDatas.length > 0 ? replaceImagePlaceholders(tempXmlData, mediaDatas, 0, "rId") : tempXmlData, file.Numbering.ConcreteNumbering),
14888
+ data: replaceNumberingPlaceholders(mediaDatas.length > 0 ? replaceImagePlaceholders(tempXmlData, mediaDatas, 0, "rId") : tempXmlData, file.numbering.concreteNumbering),
14982
14889
  path: `word/header${index + 1}.xml`
14983
14890
  };
14984
14891
  }),
14985
14892
  Numbering: {
14986
- data: xml(this.formatter.format(file.Numbering, {
14893
+ data: xml(this.formatter.format(file.numbering, {
14987
14894
  fileData: file,
14988
14895
  file,
14989
14896
  stack: [],
14990
- viewWrapper: file.Document
14897
+ viewWrapper: file.document
14991
14898
  }), {
14992
14899
  declaration: {
14993
14900
  encoding: "UTF-8",
@@ -14998,11 +14905,11 @@ var Compiler = class {
14998
14905
  path: "word/numbering.xml"
14999
14906
  },
15000
14907
  Properties: {
15001
- data: xml(this.formatter.format(file.CoreProperties, {
14908
+ data: xml(this.formatter.format(file.coreProperties, {
15002
14909
  fileData: file,
15003
14910
  file,
15004
14911
  stack: [],
15005
- viewWrapper: file.Document
14912
+ viewWrapper: file.document
15006
14913
  }), {
15007
14914
  declaration: {
15008
14915
  encoding: "UTF-8",
@@ -15015,24 +14922,24 @@ var Compiler = class {
15015
14922
  Relationships: {
15016
14923
  data: (() => {
15017
14924
  documentMediaDatas.forEach((mediaData, i) => {
15018
- file.Document.Relationships.addRelationship(documentRelationshipCount + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaData.fileName}`);
14925
+ file.document.relationships.addRelationship(documentRelationshipCount + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaData.fileName}`);
15019
14926
  });
15020
14927
  const chartOffset = documentRelationshipCount + documentMediaDatas.length;
15021
- file.Charts.Array.forEach((_chartData, i) => {
15022
- file.Document.Relationships.addRelationship(chartOffset + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart", `charts/chart${i + 1}.xml`);
14928
+ file.charts.array.forEach((_chartData, i) => {
14929
+ file.document.relationships.addRelationship(chartOffset + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart", `charts/chart${i + 1}.xml`);
15023
14930
  });
15024
- addSmartArtRelationships(file.SmartArts.Array.map((s) => s.key), (id, type, target) => {
15025
- file.Document.Relationships.addRelationship(id, type, target);
15026
- }, documentRelationshipCount + documentMediaDatas.length + file.Charts.Array.length, 0, {
14931
+ addSmartArtRelationships(file.smartArts.array.map((s) => s.key), (id, type, target) => {
14932
+ file.document.relationships.addRelationship(id, type, target);
14933
+ }, documentRelationshipCount + documentMediaDatas.length + file.charts.array.length, 0, {
15027
14934
  pathPrefix: "",
15028
14935
  styleRelType: "http://schemas.microsoft.com/office/2007/relationships/diagramStyle"
15029
14936
  });
15030
- file.Document.Relationships.addRelationship(file.Document.Relationships.RelationshipCount + 1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable", "fontTable.xml");
15031
- return xml(this.formatter.format(file.Document.Relationships, {
14937
+ file.document.relationships.addRelationship(file.document.relationships.relationshipCount + 1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable", "fontTable.xml");
14938
+ return xml(this.formatter.format(file.document.relationships, {
15032
14939
  fileData: file,
15033
14940
  file,
15034
14941
  stack: [],
15035
- viewWrapper: file.Document
14942
+ viewWrapper: file.document
15036
14943
  }), {
15037
14944
  declaration: { encoding: "UTF-8" },
15038
14945
  indent: prettify
@@ -15041,11 +14948,11 @@ var Compiler = class {
15041
14948
  path: "word/_rels/document.xml.rels"
15042
14949
  },
15043
14950
  Settings: {
15044
- data: xml(this.formatter.format(file.Settings, {
14951
+ data: xml(this.formatter.format(file.settings, {
15045
14952
  fileData: file,
15046
14953
  file,
15047
14954
  stack: [],
15048
- viewWrapper: file.Document
14955
+ viewWrapper: file.document
15049
14956
  }), {
15050
14957
  declaration: {
15051
14958
  encoding: "UTF-8",
@@ -15056,28 +14963,28 @@ var Compiler = class {
15056
14963
  path: "word/settings.xml"
15057
14964
  },
15058
14965
  Styles: {
15059
- data: replaceNumberingPlaceholders(xml(this.formatter.format(file.Styles, {
14966
+ data: replaceNumberingPlaceholders(xml(this.formatter.format(file.styles, {
15060
14967
  fileData: file,
15061
14968
  file,
15062
14969
  stack: [],
15063
- viewWrapper: file.Document
14970
+ viewWrapper: file.document
15064
14971
  }), {
15065
14972
  declaration: {
15066
14973
  encoding: "UTF-8",
15067
14974
  standalone: "yes"
15068
14975
  },
15069
14976
  indent: prettify
15070
- }), file.Numbering.ConcreteNumbering),
14977
+ }), file.numbering.concreteNumbering),
15071
14978
  path: "word/styles.xml"
15072
14979
  },
15073
- ...file.Bibliography ? { Bibliography: {
15074
- data: xml(this.formatter.format(file.Bibliography, {
14980
+ ...file.bibliography ? { Bibliography: {
14981
+ data: xml(this.formatter.format(file.bibliography, {
15075
14982
  fileData: file,
15076
14983
  file,
15077
14984
  stack: [],
15078
14985
  viewWrapper: {
15079
- Relationships: file.Bibliography.Relationships,
15080
- View: file.Bibliography
14986
+ relationships: file.bibliography.relationships,
14987
+ view: file.bibliography
15081
14988
  }
15082
14989
  }), {
15083
14990
  declaration: {
@@ -15088,12 +14995,12 @@ var Compiler = class {
15088
14995
  }),
15089
14996
  path: "word/bibliography.xml"
15090
14997
  } } : {},
15091
- ...file.Charts.Array.length > 0 ? { Charts: file.Charts.Array.flatMap((chartData, i) => [{
14998
+ ...file.charts.array.length > 0 ? { Charts: file.charts.array.flatMap((chartData, i) => [{
15092
14999
  data: xml(this.formatter.format(chartData.chartSpace, {
15093
15000
  fileData: file,
15094
15001
  file,
15095
15002
  stack: [],
15096
- viewWrapper: file.Document
15003
+ viewWrapper: file.document
15097
15004
  }), {
15098
15005
  declaration: {
15099
15006
  encoding: "UTF-8",
@@ -15109,13 +15016,13 @@ var Compiler = class {
15109
15016
  } }),
15110
15017
  path: `word/charts/_rels/chart${i + 1}.xml.rels`
15111
15018
  }]) } : {},
15112
- ...file.SmartArts.Array.length > 0 ? {
15113
- DiagramData: file.SmartArts.Array.map((smartArtData, i) => ({
15019
+ ...file.smartArts.array.length > 0 ? {
15020
+ DiagramData: file.smartArts.array.map((smartArtData, i) => ({
15114
15021
  data: xml(this.formatter.format(smartArtData.dataModel, {
15115
15022
  fileData: file,
15116
15023
  file,
15117
15024
  stack: [],
15118
- viewWrapper: file.Document
15025
+ viewWrapper: file.document
15119
15026
  }), {
15120
15027
  declaration: {
15121
15028
  encoding: "UTF-8",
@@ -15125,28 +15032,28 @@ var Compiler = class {
15125
15032
  }),
15126
15033
  path: `word/diagrams/data${i + 1}.xml`
15127
15034
  })),
15128
- DiagramLayout: file.SmartArts.Array.map((smartArtData, i) => ({
15035
+ DiagramLayout: file.smartArts.array.map((smartArtData, i) => ({
15129
15036
  data: getLayoutXml(smartArtData.layout),
15130
15037
  path: `word/diagrams/layout${i + 1}.xml`
15131
15038
  })),
15132
- DiagramStyle: file.SmartArts.Array.map((smartArtData, i) => ({
15039
+ DiagramStyle: file.smartArts.array.map((smartArtData, i) => ({
15133
15040
  data: getStyleXml(smartArtData.style),
15134
15041
  path: `word/diagrams/quickStyle${i + 1}.xml`
15135
15042
  })),
15136
- DiagramColors: file.SmartArts.Array.map((smartArtData, i) => ({
15043
+ DiagramColors: file.smartArts.array.map((smartArtData, i) => ({
15137
15044
  data: getColorXml(smartArtData.color),
15138
15045
  path: `word/diagrams/colors${i + 1}.xml`
15139
15046
  })),
15140
- DiagramDrawing: file.SmartArts.Array.map((_, i) => ({
15047
+ DiagramDrawing: file.smartArts.array.map((_, i) => ({
15141
15048
  data: DEFAULT_DRAWING_XML,
15142
15049
  path: `word/diagrams/drawing${i + 1}.xml`
15143
15050
  }))
15144
15051
  } : {},
15145
- ...file.AltChunks.Array.length > 0 ? { AltChunks: file.AltChunks.Array.map((altChunkData) => ({
15052
+ ...file.altChunks.array.length > 0 ? { AltChunks: file.altChunks.array.map((altChunkData) => ({
15146
15053
  data: altChunkData.data,
15147
15054
  path: `word/${altChunkData.path}`
15148
15055
  })) } : {},
15149
- ...file.SubDocs.Array.length > 0 ? { SubDocs: file.SubDocs.Array.map((subDocData) => ({
15056
+ ...file.subDocs.array.length > 0 ? { SubDocs: file.subDocs.array.map((subDocData) => ({
15150
15057
  data: subDocData.data,
15151
15058
  path: `word/${subDocData.path}`
15152
15059
  })) } : {}
@@ -15891,7 +15798,7 @@ const patchDocument = async ({ outputType, data, patches, keepOriginalStyles, pl
15891
15798
  if (!recursive || !didFindOccurrence) break;
15892
15799
  }
15893
15800
  }
15894
- const mediaDatas = getReferencedMedia(JSON.stringify(json), context.file.Media.Array);
15801
+ const mediaDatas = getReferencedMedia(JSON.stringify(json), context.file.media.array);
15895
15802
  if (mediaDatas.length > 0) {
15896
15803
  hasMedia = true;
15897
15804
  imageRelationshipAdditions.push({
@@ -15933,7 +15840,7 @@ const patchDocument = async ({ outputType, data, patches, keepOriginalStyles, pl
15933
15840
  const files = {};
15934
15841
  for (const [key, value] of map) files[key] = textToUint8Array(toXml(value));
15935
15842
  for (const [key, value] of binaryContentMap) files[key] = value;
15936
- for (const { data: mediaData, fileName } of file.Media.Array) files[`word/media/${fileName}`] = mediaData instanceof Uint8Array ? mediaData : new Uint8Array(mediaData);
15843
+ for (const { data: mediaData, fileName } of file.media.array) files[`word/media/${fileName}`] = mediaData instanceof Uint8Array ? mediaData : new Uint8Array(mediaData);
15937
15844
  return await zipAndConvert(files, outputType, OoxmlMimeType.DOCX);
15938
15845
  };
15939
15846
  const toXml = (jsonObj) => {
@@ -16003,939 +15910,1045 @@ const findPatchKeys = (text) => {
16003
15910
  return text.match(/(?<=\{\{).+?(?=\}\})/gs) ?? [];
16004
15911
  };
16005
15912
  //#endregion
16006
- //#region src/file/paragraph/run/run-parse.ts
15913
+ //#region src/file/drawing/drawing-parse.ts
16007
15914
  /**
16008
- * Run properties parser for DOCX documents.
15915
+ * Drawing parser for DOCX documents.
16009
15916
  *
16010
- * Parses w:rPr Element trees into RunPropertiesOptions objects.
15917
+ * Parses w:drawing elements and extracts image, chart, or SmartArt data.
16011
15918
  *
16012
15919
  * @module
16013
15920
  */
16014
15921
  /**
16015
- * Parse a w:rPr element into RunPropertiesOptions.
15922
+ * Parse a w:drawing element and dispatch to the correct parser
15923
+ * based on the graphicData URI.
16016
15924
  */
16017
- function parseRunProperties(el) {
16018
- const opts = {};
16019
- const rStyle = findChild(el, "w:rStyle");
16020
- if (rStyle) opts.style = attr(rStyle, "w:val");
16021
- const font = findChild(el, "w:rFonts");
16022
- if (font) {
16023
- const ascii = attr(font, "w:ascii");
16024
- const eastAsia = attr(font, "w:eastAsia");
16025
- const hAnsi = attr(font, "w:hAnsi");
16026
- const cs = attr(font, "w:cs");
16027
- const hint = attr(font, "w:hint");
16028
- if (ascii && !eastAsia && !hAnsi && !cs) opts.font = hint ? {
16029
- name: ascii,
16030
- hint
16031
- } : ascii;
16032
- else {
16033
- const fontObj = {};
16034
- if (ascii) fontObj.ascii = ascii;
16035
- if (eastAsia) fontObj.eastAsia = eastAsia;
16036
- if (hAnsi) fontObj.hAnsi = hAnsi;
16037
- if (cs) fontObj.cs = cs;
16038
- if (hint) fontObj.hint = hint;
16039
- opts.font = fontObj;
16040
- }
16041
- }
16042
- const bold = findChild(el, "w:b");
16043
- if (bold) opts.bold = attrBool(bold, "w:val") ?? true;
16044
- const boldCs = findChild(el, "w:bCs");
16045
- if (boldCs) opts.boldComplexScript = attrBool(boldCs, "w:val") ?? true;
16046
- const italics = findChild(el, "w:i");
16047
- if (italics) opts.italics = attrBool(italics, "w:val") ?? true;
16048
- const italicsCs = findChild(el, "w:iCs");
16049
- if (italicsCs) opts.italicsComplexScript = attrBool(italicsCs, "w:val") ?? true;
16050
- const underline = findChild(el, "w:u");
16051
- if (underline) {
16052
- const ul = {};
16053
- const uType = attr(underline, "w:val");
16054
- if (uType) ul.type = uType;
16055
- const uColor = colorAttr(underline, "w:color");
16056
- if (uColor) ul.color = uColor;
16057
- opts.underline = ul;
16058
- }
16059
- for (const [name, optKey] of [
16060
- ["w:strike", "strike"],
16061
- ["w:dstrike", "doubleStrike"],
16062
- ["w:outline", "outline"],
16063
- ["w:shadow", "shadow"],
16064
- ["w:emboss", "emboss"],
16065
- ["w:imprint", "imprint"],
16066
- ["w:vanish", "vanish"],
16067
- ["w:webHidden", "webHidden"],
16068
- ["w:noProof", "noProof"],
16069
- ["w:snapToGrid", "snapToGrid"],
16070
- ["w:smallCaps", "smallCaps"],
16071
- ["w:caps", "allCaps"],
16072
- ["w:rtl", "rightToLeft"],
16073
- ["w:cs", "complexScript"],
16074
- ["w:specVanish", "specVanish"],
16075
- ["w:math", "math"]
16076
- ]) {
16077
- const child = findChild(el, name);
16078
- if (child) opts[optKey] = attrBool(child, "w:val") ?? true;
16079
- }
16080
- const color = findChild(el, "w:color");
16081
- if (color) {
16082
- const c = colorAttr(color, "w:val");
16083
- if (c) opts.color = c;
16084
- }
16085
- const sz = findChild(el, "w:sz");
16086
- if (sz) {
16087
- const halfPts = attrNum(sz, "w:val");
16088
- if (halfPts !== void 0) opts.size = halfPts;
16089
- }
16090
- const szCs = findChild(el, "w:szCs");
16091
- if (szCs) {
16092
- const halfPts = attrNum(szCs, "w:val");
16093
- if (halfPts !== void 0) opts.sizeComplexScript = halfPts;
16094
- }
16095
- const highlight = findChild(el, "w:highlight");
16096
- if (highlight) {
16097
- const val = attr(highlight, "w:val");
16098
- if (val) opts.highlight = val;
16099
- }
16100
- const highlightCs = findChild(el, "w:highlightCs");
16101
- if (highlightCs) {
16102
- const val = attr(highlightCs, "w:val");
16103
- if (val) opts.highlightComplexScript = val;
16104
- }
16105
- const vertAlign = findChild(el, "w:vertAlign");
16106
- if (vertAlign) {
16107
- const val = attr(vertAlign, "w:val");
16108
- if (val === "subscript") opts.subScript = true;
16109
- else if (val === "superscript") opts.superScript = true;
16110
- }
16111
- const effect = findChild(el, "w:effect");
16112
- if (effect) {
16113
- const val = attr(effect, "w:val");
16114
- if (val) opts.effect = val;
16115
- }
16116
- const emphasisMark = findChild(el, "w:em");
16117
- if (emphasisMark) {
16118
- const val = attr(emphasisMark, "w:val");
16119
- if (val) opts.emphasisMark = { type: val };
16120
- }
16121
- const spacing = findChild(el, "w:spacing");
16122
- if (spacing) {
16123
- const val = attrNum(spacing, "w:val");
16124
- if (val !== void 0) opts.characterSpacing = val;
16125
- }
16126
- const scale = findChild(el, "w:w");
16127
- if (scale) {
16128
- const val = attrNum(scale, "w:val");
16129
- if (val !== void 0) opts.scale = val;
16130
- }
16131
- const kern = findChild(el, "w:kern");
16132
- if (kern) {
16133
- const val = attrNum(kern, "w:val");
16134
- if (val !== void 0) opts.kern = val;
16135
- }
16136
- const position = findChild(el, "w:position");
16137
- if (position) {
16138
- const val = attr(position, "w:val");
16139
- if (val !== void 0) opts.position = val;
16140
- }
16141
- const fitText = findChild(el, "w:fitText");
16142
- if (fitText) {
16143
- const val = attrNum(fitText, "w:val");
16144
- if (val !== void 0) opts.fitText = val;
16145
- }
16146
- const lang = findChild(el, "w:lang");
16147
- if (lang) {
16148
- const langObj = {};
16149
- const val = attr(lang, "w:val");
16150
- if (val) langObj.val = val;
16151
- const eastAsia = attr(lang, "w:eastAsia");
16152
- if (eastAsia) langObj.eastAsia = eastAsia;
16153
- const bidi = attr(lang, "w:bidi");
16154
- if (bidi) langObj.bidi = bidi;
16155
- if (Object.keys(langObj).length > 0) opts.language = langObj;
16156
- }
16157
- const bdr = findChild(el, "w:bdr");
16158
- if (bdr) opts.border = parseBorder(bdr);
16159
- const shd = findChild(el, "w:shd");
16160
- if (shd) opts.shading = parseShading(shd);
16161
- return opts;
15925
+ function parseDrawingRun(el, ctx) {
15926
+ const graphicData = findDeep(el, "a:graphicData")[0];
15927
+ if (!graphicData) return void 0;
15928
+ const uri = attr(graphicData, "uri") ?? "";
15929
+ if (uri.includes("/chart")) return parseChartDrawing(el, ctx);
15930
+ if (uri.includes("/diagram")) return parseSmartArtDrawing(el, ctx);
15931
+ return parseImageRun(el, ctx);
16162
15932
  }
16163
15933
  /**
16164
- * Parse a w:bdr element into BorderOptions.
15934
+ * Determine image type from file extension or MIME type.
16165
15935
  */
16166
- function parseBorder(el) {
16167
- const opts = {};
16168
- const style = attr(el, "w:val");
16169
- if (style) opts.style = style;
16170
- const color = colorAttr(el, "w:color");
16171
- if (color) opts.color = color;
16172
- const size = attrNum(el, "w:sz");
16173
- if (size !== void 0) opts.size = size;
16174
- const space = attrNum(el, "w:space");
16175
- if (space !== void 0) opts.space = space;
16176
- const shadow = attrBool(el, "w:shadow");
16177
- if (shadow !== void 0) opts.shadow = shadow;
16178
- const frame = attrBool(el, "w:frame");
16179
- if (frame !== void 0) opts.frame = frame;
16180
- return opts;
15936
+ function imageTypeFromPath(path) {
15937
+ switch (path.split(".").pop()?.toLowerCase() ?? "") {
15938
+ case "jpg":
15939
+ case "jpeg": return "jpg";
15940
+ case "png": return "png";
15941
+ case "gif": return "gif";
15942
+ case "bmp": return "bmp";
15943
+ case "tif":
15944
+ case "tiff": return "tif";
15945
+ case "ico": return "ico";
15946
+ case "emf": return "emf";
15947
+ case "wmf": return "wmf";
15948
+ default: return "png";
15949
+ }
16181
15950
  }
16182
15951
  /**
16183
- * Parse a w:shd element into ShadingAttributesProperties.
15952
+ * Parse a w:drawing element and return image data wrapped in { image: ... }.
16184
15953
  */
16185
- function parseShading(el) {
16186
- const opts = {};
16187
- const fill = colorAttr(el, "w:fill");
16188
- if (fill) opts.fill = fill;
16189
- const color = colorAttr(el, "w:color");
16190
- if (color) opts.color = color;
16191
- const type = attr(el, "w:val");
16192
- if (type) opts.type = type;
16193
- return opts;
16194
- }
16195
- /** Matches w:br[@w:type="page"] → PageBreak */
16196
- const PARSED_PAGE_BREAK = Symbol("PageBreak");
16197
- /** Matches w:br (line break) */
16198
- const PARSED_LINE_BREAK = Symbol("LineBreak");
16199
- /** Matches w:tab */
16200
- const PARSED_TAB = Symbol("Tab");
16201
- /** Matches w:cr */
16202
- const PARSED_CR = Symbol("CarriageReturn");
16203
- /** Matches w:noBreakHyphen */
16204
- const PARSED_NO_BREAK_HYPHEN = Symbol("NoBreakHyphen");
16205
- /** Matches w:softHyphen */
16206
- const PARSED_SOFT_HYPHEN = Symbol("SoftHyphen");
16207
- /**
16208
- * Parse a w:r element into run data.
16209
- * Returns { properties, children } where children are parsed run content items.
16210
- */
16211
- function parseRun(el, _ctx) {
16212
- const rPr = findChild(el, "w:rPr");
16213
- const properties = rPr ? parseRunProperties(rPr) : void 0;
16214
- const children = [];
16215
- for (const child of el.elements ?? []) switch (child.name) {
16216
- case "w:rPr": break;
16217
- case "w:t": {
16218
- const preserveSpace = attrBool(child, "xml:space");
16219
- let text = textOf(child);
16220
- if (preserveSpace && text) {}
16221
- children.push(text);
16222
- break;
15954
+ function parseImageRun(el, ctx) {
15955
+ const inline = findDeep(el, "wp:inline")[0];
15956
+ const anchor = inline ? void 0 : findDeep(el, "wp:anchor")[0];
15957
+ const parent = inline ?? anchor;
15958
+ if (!parent) return void 0;
15959
+ const extent = findChild(parent, "wp:extent");
15960
+ let width;
15961
+ let height;
15962
+ if (extent) {
15963
+ const cxEmu = attrNum(extent, "cx");
15964
+ const cyEmu = attrNum(extent, "cy");
15965
+ if (cxEmu !== void 0) width = convertEmuToPixels(cxEmu);
15966
+ if (cyEmu !== void 0) height = convertEmuToPixels(cyEmu);
15967
+ }
15968
+ const blip = findDeep(parent, "a:blip")[0];
15969
+ if (!blip) return void 0;
15970
+ const rEmbed = attr(blip, "r:embed");
15971
+ if (!rEmbed) return void 0;
15972
+ const mediaPath = ctx.docx.partRefs.media.get(rEmbed);
15973
+ if (!mediaPath) return void 0;
15974
+ const imageData = ctx.docx.doc.getRaw(mediaPath);
15975
+ if (!imageData) return void 0;
15976
+ const imageOpts = {
15977
+ type: imageTypeFromPath(mediaPath),
15978
+ data: imageData,
15979
+ transformation: {
15980
+ ...width !== void 0 ? { width } : {},
15981
+ ...height !== void 0 ? { height } : {}
16223
15982
  }
16224
- case "w:br": {
16225
- const brType = attr(child, "w:type");
16226
- if (brType === "page") children.push(PARSED_PAGE_BREAK);
16227
- else if (brType === "column") children.push(PARSED_PAGE_BREAK);
16228
- else children.push(PARSED_LINE_BREAK);
16229
- break;
15983
+ };
15984
+ const docPr = findChild(parent, "wp:docPr");
15985
+ if (docPr) {
15986
+ const name = attr(docPr, "name");
15987
+ const descr = attr(docPr, "descr");
15988
+ const title = attr(docPr, "title");
15989
+ if (name || descr || title) imageOpts.altText = {
15990
+ ...name ? { name } : {},
15991
+ ...descr ? { description: descr } : {},
15992
+ ...title ? { title } : {}
15993
+ };
15994
+ }
15995
+ if (anchor && !inline) {
15996
+ const floating = {};
15997
+ const posH = findChild(anchor, "wp:positionH");
15998
+ if (posH) {
15999
+ const align = findChild(posH, "wp:align");
16000
+ const posOffset = findChild(posH, "wp:posOffset");
16001
+ if (align) floating.horizontalPosition = { align: textOf(align) };
16002
+ else if (posOffset) {
16003
+ const val = Number(textOf(posOffset));
16004
+ if (!isNaN(val)) floating.horizontalPosition = { offset: val };
16005
+ }
16230
16006
  }
16231
- case "w:tab":
16232
- children.push(PARSED_TAB);
16233
- break;
16234
- case "w:cr":
16235
- children.push(PARSED_CR);
16236
- break;
16237
- case "w:noBreakHyphen":
16238
- children.push(PARSED_NO_BREAK_HYPHEN);
16239
- break;
16240
- case "w:softHyphen":
16241
- children.push(PARSED_SOFT_HYPHEN);
16242
- break;
16243
- case "w:commentReference": {
16244
- const id = attrNum(child, "w:id");
16245
- if (id !== void 0) children.push({ commentReference: id });
16246
- break;
16007
+ const posV = findChild(anchor, "wp:positionV");
16008
+ if (posV) {
16009
+ const align = findChild(posV, "wp:align");
16010
+ const posOffset = findChild(posV, "wp:posOffset");
16011
+ if (align) floating.verticalPosition = { align: textOf(align) };
16012
+ else if (posOffset) {
16013
+ const val = Number(textOf(posOffset));
16014
+ if (!isNaN(val)) floating.verticalPosition = { offset: val };
16015
+ }
16247
16016
  }
16248
- case "w:drawing":
16249
- case "w:pict": break;
16250
- case "w:footnoteReference":
16251
- case "w:endnoteReference": break;
16252
- default:
16253
- if (child.name && child.elements && child.elements.length > 0) children.push(new RawPassthrough(child));
16017
+ for (const wrapType of [
16018
+ "wrapSquare",
16019
+ "wrapTight",
16020
+ "wrapTopAndBottom",
16021
+ "wrapNone"
16022
+ ]) if (findChild(anchor, `wp:${wrapType}`)) {
16023
+ floating.wrap = wrapType;
16254
16024
  break;
16025
+ }
16026
+ if (attrBool(anchor, "behindDoc")) floating.behindDocument = true;
16027
+ if (Object.keys(floating).length > 0) imageOpts.floating = floating;
16255
16028
  }
16029
+ return { image: imageOpts };
16030
+ }
16031
+ function getDrawingExtent(el) {
16032
+ const inline = findDeep(el, "wp:inline")[0];
16033
+ const anchor = inline ? void 0 : findDeep(el, "wp:anchor")[0];
16034
+ const parent = inline ?? anchor;
16035
+ if (!parent) return {};
16036
+ const extent = findChild(parent, "wp:extent");
16037
+ if (!extent) return {};
16038
+ const cxEmu = attrNum(extent, "cx");
16039
+ const cyEmu = attrNum(extent, "cy");
16256
16040
  return {
16257
- properties,
16258
- children
16041
+ ...cxEmu !== void 0 ? { width: convertEmuToPixels(cxEmu) } : {},
16042
+ ...cyEmu !== void 0 ? { height: convertEmuToPixels(cyEmu) } : {}
16259
16043
  };
16260
16044
  }
16261
16045
  /**
16262
- * Convert parsed run data into an RunOptions suitable for the Document constructor.
16263
- * Simplifies the parsed children into text + break format.
16264
- * If the run contains only a commentReference, returns { commentReference: id } instead.
16046
+ * Look up a relationship ID in a map, with fallback for double "rId" prefix
16047
+ * that the library's generation code produces (e.g. "rIdrId7" → "rId7").
16265
16048
  */
16266
- function parsedRunToOptions(parsed) {
16267
- const opts = { ...parsed.properties };
16268
- const commentRefs = parsed.children.filter((c) => typeof c === "object" && c !== null && "commentReference" in c);
16269
- const nonCommentChildren = parsed.children.filter((c) => !(typeof c === "object" && c !== null && "commentReference" in c));
16270
- if (commentRefs.length > 0 && nonCommentChildren.length === 0 && !parsed.properties) return commentRefs[0];
16271
- const textParts = [];
16272
- let breakCount = 0;
16273
- for (const child of nonCommentChildren) if (typeof child === "string") textParts.push(child);
16274
- else if (child === PARSED_LINE_BREAK) breakCount++;
16275
- if (textParts.length > 0) opts.text = textParts.join("");
16276
- if (breakCount > 0) opts.break = breakCount;
16277
- return opts;
16049
+ function lookupRId(map, rId) {
16050
+ if (!rId) return void 0;
16051
+ const direct = map.get(rId);
16052
+ if (direct) return direct;
16053
+ if (rId.startsWith("rIdrId")) return map.get(rId.slice(3));
16054
+ }
16055
+ function parseChartDrawing(el, ctx) {
16056
+ const chartRef = findDeep(el, "c:chart")[0];
16057
+ if (!chartRef) return void 0;
16058
+ const rId = attr(chartRef, "r:id");
16059
+ const chartPath = lookupRId(ctx.docx.partRefs.charts, rId);
16060
+ if (!chartPath) return void 0;
16061
+ const chartXml = ctx.docx.doc.get(chartPath);
16062
+ if (!chartXml) return void 0;
16063
+ const opts = parseChartXml(chartXml);
16064
+ if (!opts) return void 0;
16065
+ const ext = getDrawingExtent(el);
16066
+ if (ext.width !== void 0 || ext.height !== void 0) opts.transformation = { ...ext };
16067
+ return { chart: opts };
16278
16068
  }
16279
- //#endregion
16280
- //#region src/file/paragraph/paragraph-parse.ts
16281
- /**
16282
- * Paragraph parser for DOCX documents.
16283
- *
16284
- * Parses w:p and w:pPr Element trees into ParagraphOptions objects.
16285
- *
16286
- * @module
16287
- */
16288
- init_style();
16289
- init_math_parse();
16290
- const HEADING_MAP = {
16291
- Heading1: HeadingLevel.HEADING_1,
16292
- Heading2: HeadingLevel.HEADING_2,
16293
- Heading3: HeadingLevel.HEADING_3,
16294
- Heading4: HeadingLevel.HEADING_4,
16295
- Heading5: HeadingLevel.HEADING_5,
16296
- Heading6: HeadingLevel.HEADING_6,
16297
- Title: HeadingLevel.TITLE
16298
- };
16299
16069
  /**
16300
- * Parse w:pPr element into paragraph properties (without children).
16070
+ * Parse c:chartSpace element into ChartOptions.
16301
16071
  */
16302
- function parseParagraphProperties(el, _ctx) {
16072
+ function parseChartXml(el) {
16073
+ const chart = findChild(el, "c:chart");
16074
+ if (!chart) return void 0;
16303
16075
  const opts = {};
16304
- const pStyle = findChild(el, "w:pStyle");
16305
- if (pStyle) {
16306
- const styleVal = attr(pStyle, "w:val");
16307
- if (styleVal) if (HEADING_MAP[styleVal]) opts.heading = HEADING_MAP[styleVal];
16308
- else opts.style = styleVal;
16076
+ const titleEl = findChild(chart, "c:title");
16077
+ if (titleEl) {
16078
+ const rich = findDeep(titleEl, "c:rich")[0];
16079
+ if (rich) {
16080
+ const t = findDeep(rich, "a:t")[0];
16081
+ if (t) {
16082
+ const title = textOf(t);
16083
+ if (title) opts.title = title;
16084
+ }
16085
+ }
16309
16086
  }
16310
- const jc = findChild(el, "w:jc");
16311
- if (jc) {
16312
- const val = attr(jc, "w:val");
16313
- if (val) opts.alignment = val;
16087
+ const plotArea = findChild(chart, "c:plotArea");
16088
+ if (!plotArea) return void 0;
16089
+ let chartType;
16090
+ let typeElement;
16091
+ for (const child of plotArea.elements ?? []) {
16092
+ switch (child.name) {
16093
+ case "c:barChart": {
16094
+ const barDir = findChild(child, "c:barDir");
16095
+ chartType = barDir && attr(barDir, "val") === "bar" ? "bar" : "column";
16096
+ typeElement = child;
16097
+ break;
16098
+ }
16099
+ case "c:lineChart":
16100
+ chartType = "line";
16101
+ typeElement = child;
16102
+ break;
16103
+ case "c:pieChart":
16104
+ chartType = "pie";
16105
+ typeElement = child;
16106
+ break;
16107
+ case "c:areaChart":
16108
+ chartType = "area";
16109
+ typeElement = child;
16110
+ break;
16111
+ case "c:scatterChart":
16112
+ chartType = "scatter";
16113
+ typeElement = child;
16114
+ break;
16115
+ }
16116
+ if (chartType) break;
16314
16117
  }
16315
- const spacing = findChild(el, "w:spacing");
16316
- if (spacing) {
16317
- const sp = {};
16318
- const before = attrNum(spacing, "w:before");
16319
- if (before !== void 0) sp.before = before;
16320
- const after = attrNum(spacing, "w:after");
16321
- if (after !== void 0) sp.after = after;
16322
- const line = attrNum(spacing, "w:line");
16323
- if (line !== void 0) sp.line = line;
16324
- const lineRule = attr(spacing, "w:lineRule");
16325
- if (lineRule) sp.lineRule = lineRule;
16326
- const beforeAuto = attrBool(spacing, "w:beforeAutospacing") ?? attrBool(spacing, "w:beforeLines");
16327
- if (beforeAuto !== void 0) sp.beforeAutoSpacing = beforeAuto;
16328
- const afterAuto = attrBool(spacing, "w:afterAutospacing") ?? attrBool(spacing, "w:afterLines");
16329
- if (afterAuto !== void 0) sp.afterAutoSpacing = afterAuto;
16330
- if (Object.keys(sp).length > 0) opts.spacing = sp;
16118
+ if (!chartType || !typeElement) return void 0;
16119
+ opts.type = chartType;
16120
+ const series = [];
16121
+ let categories;
16122
+ for (const serEl of typeElement.elements ?? []) {
16123
+ if (serEl.name !== "c:ser") continue;
16124
+ const nameParts = extractStrCache(serEl, "c:tx");
16125
+ const cats = extractStrCache(serEl, "c:cat");
16126
+ if (cats.length > 0 && !categories) categories = cats;
16127
+ const vals = extractNumCache(serEl);
16128
+ series.push({
16129
+ name: nameParts[0] ?? "",
16130
+ values: vals
16131
+ });
16331
16132
  }
16332
- const ind = findChild(el, "w:ind");
16333
- if (ind) {
16334
- const indentObj = {};
16335
- const left = attrNum(ind, "w:left");
16336
- if (left !== void 0) indentObj.left = left;
16337
- const right = attrNum(ind, "w:right");
16338
- if (right !== void 0) indentObj.right = right;
16339
- const start = attrNum(ind, "w:start");
16340
- if (start !== void 0) indentObj.start = start;
16341
- const end = attrNum(ind, "w:end");
16342
- if (end !== void 0) indentObj.end = end;
16343
- const hanging = attrNum(ind, "w:hanging");
16344
- if (hanging !== void 0) indentObj.hanging = hanging;
16345
- const firstLine = attrNum(ind, "w:firstLine");
16346
- if (firstLine !== void 0) indentObj.firstLine = firstLine;
16347
- if (Object.keys(indentObj).length > 0) opts.indent = indentObj;
16133
+ opts.data = {
16134
+ categories: categories ?? [],
16135
+ series
16136
+ };
16137
+ opts.showLegend = findChild(chart, "c:legend") !== void 0;
16138
+ const styleEl = findChild(el, "c:style");
16139
+ if (styleEl) {
16140
+ const val = attrNum(styleEl, "val");
16141
+ if (val !== void 0) opts.style = val;
16348
16142
  }
16349
- const numPr = findChild(el, "w:numPr");
16350
- if (numPr) {
16351
- const ilvl = findChild(numPr, "w:ilvl");
16352
- opts.bullet = { level: ilvl ? attrNum(ilvl, "w:val") ?? 0 : 0 };
16143
+ return opts;
16144
+ }
16145
+ /**
16146
+ * Extract string values from c:strCache within a container element.
16147
+ */
16148
+ function extractStrCache(parent, containerName) {
16149
+ const container = findChild(parent, containerName);
16150
+ if (!container) return [];
16151
+ const cache = findDeep(container, "c:strCache")[0];
16152
+ if (!cache) return [];
16153
+ const values = [];
16154
+ for (const pt of cache.elements ?? []) {
16155
+ if (pt.name !== "c:pt") continue;
16156
+ const v = findChild(pt, "c:v");
16157
+ if (v) values.push(textOf(v) ?? "");
16353
16158
  }
16354
- const tabs = findChild(el, "w:tabs");
16355
- if (tabs) {
16356
- const tabStops = [];
16357
- for (const tab of children(tabs, "w:tab")) {
16358
- const tabObj = {};
16359
- const pos = attrNum(tab, "w:pos");
16360
- if (pos !== void 0) tabObj.position = pos;
16361
- const val = attr(tab, "w:val");
16362
- if (val) tabObj.type = val;
16363
- const leader = attr(tab, "w:leader");
16364
- if (leader) tabObj.leader = leader;
16365
- tabStops.push(tabObj);
16159
+ return values;
16160
+ }
16161
+ /**
16162
+ * Extract numeric values from c:numCache within a c:val container.
16163
+ */
16164
+ function extractNumCache(parent) {
16165
+ const valEl = findChild(parent, "c:val");
16166
+ if (!valEl) return [];
16167
+ const cache = findDeep(valEl, "c:numCache")[0];
16168
+ if (!cache) return [];
16169
+ const values = [];
16170
+ for (const pt of cache.elements ?? []) {
16171
+ if (pt.name !== "c:pt") continue;
16172
+ const v = findChild(pt, "c:v");
16173
+ if (v) {
16174
+ const num = Number(textOf(v));
16175
+ if (!isNaN(num)) values.push(num);
16366
16176
  }
16367
- if (tabStops.length > 0) opts.tabStops = tabStops;
16368
- }
16369
- for (const [name, optKey] of [
16370
- ["w:keepNext", "keepNext"],
16371
- ["w:keepLines", "keepLines"],
16372
- ["w:pageBreakBefore", "pageBreakBefore"],
16373
- ["w:widowControl", "widowControl"],
16374
- ["w:suppressLineNumbers", "suppressLineNumbers"],
16375
- ["w:contextualSpacing", "contextualSpacing"],
16376
- ["w:bidi", "bidirectional"],
16377
- ["w:wordWrap", "wordWrap"],
16378
- ["w:suppressAutoHyphens", "suppressAutoHyphens"],
16379
- ["w:adjustRightInd", "adjustRightInd"],
16380
- ["w:snapToGrid", "snapToGrid"],
16381
- ["w:mirrorIndents", "mirrorIndents"],
16382
- ["w:kinsoku", "kinsoku"],
16383
- ["w:topLinePunct", "topLinePunct"],
16384
- ["w:autoSpaceDE", "autoSpaceDE"],
16385
- ["w:overflowPunct", "overflowPunctuation"],
16386
- ["w:suppressOverlap", "suppressOverlap"]
16387
- ]) {
16388
- const child = findChild(el, name);
16389
- if (child) opts[optKey] = attrBool(child, "w:val") ?? true;
16390
16177
  }
16391
- if (findChild(el, "w:pBdr")) {
16392
- const pBdr = findChild(el, "w:pBdr");
16393
- const border = {};
16394
- for (const side of [
16395
- "top",
16396
- "bottom",
16397
- "left",
16398
- "right"
16399
- ]) {
16400
- const sideEl = findChild(pBdr, `w:${side}`);
16401
- if (sideEl) {
16402
- const sideOpts = {};
16403
- const style = attr(sideEl, "w:val");
16404
- if (style) sideOpts.style = style;
16405
- const color = attr(sideEl, "w:color");
16406
- if (color) sideOpts.color = color;
16407
- const size = attrNum(sideEl, "w:sz");
16408
- if (size !== void 0) sideOpts.size = size;
16409
- const space = attrNum(sideEl, "w:space");
16410
- if (space !== void 0) sideOpts.space = space;
16411
- border[side] = sideOpts;
16178
+ return values;
16179
+ }
16180
+ function parseSmartArtDrawing(el, ctx) {
16181
+ const relIds = findDeep(el, "dgm:relIds")[0];
16182
+ if (!relIds) return void 0;
16183
+ const rId = attr(relIds, "r:dm");
16184
+ const dataPath = lookupRId(ctx.docx.partRefs.diagramData, rId);
16185
+ if (!dataPath) return void 0;
16186
+ const dataEl = ctx.docx.doc.get(dataPath);
16187
+ if (!dataEl) return void 0;
16188
+ const opts = parseSmartArtDataXml(dataEl);
16189
+ if (!opts) return void 0;
16190
+ const ext = getDrawingExtent(el);
16191
+ if (ext.width !== void 0 || ext.height !== void 0) opts.transformation = { ...ext };
16192
+ return { smartArt: opts };
16193
+ }
16194
+ /**
16195
+ * Parse dgm:dataModel element into SmartArtOptions.
16196
+ */
16197
+ function parseSmartArtDataXml(el) {
16198
+ const ptLst = findChild(el, "dgm:ptLst");
16199
+ if (!ptLst) return void 0;
16200
+ const opts = {};
16201
+ const nodeMap = /* @__PURE__ */ new Map();
16202
+ for (const pt of ptLst.elements ?? []) {
16203
+ if (pt.name !== "dgm:pt") continue;
16204
+ const type = attr(pt, "type");
16205
+ const modelId = attr(pt, "modelId");
16206
+ if (type === "doc") {
16207
+ const prSet = findChild(pt, "dgm:prSet");
16208
+ if (prSet) {
16209
+ const loTypeId = attr(prSet, "loTypeId") ?? "";
16210
+ const qsTypeId = attr(prSet, "qsTypeId") ?? "";
16211
+ const csTypeId = attr(prSet, "csTypeId") ?? "";
16212
+ const layout = loTypeId.split("/").pop();
16213
+ if (layout) opts.layout = layout;
16214
+ const style = qsTypeId.split("/").pop();
16215
+ if (style) opts.style = style;
16216
+ const color = csTypeId.split("/").pop();
16217
+ if (color) opts.color = color;
16412
16218
  }
16219
+ } else if (type === "node" && modelId) {
16220
+ const t = findDeep(pt, "a:t")[0];
16221
+ nodeMap.set(modelId, t ? textOf(t) ?? "" : "");
16413
16222
  }
16414
- if (Object.keys(border).length > 0) opts.border = border;
16415
- }
16416
- const shd = findChild(el, "w:shd");
16417
- if (shd) {
16418
- const shdObj = {};
16419
- const fill = attr(shd, "w:fill");
16420
- if (fill) shdObj.fill = fill;
16421
- const color = attr(shd, "w:color");
16422
- if (color) shdObj.color = color;
16423
- const val = attr(shd, "w:val");
16424
- if (val) shdObj.type = val;
16425
- if (Object.keys(shdObj).length > 0) opts.shading = shdObj;
16426
- }
16427
- const textAlignment = findChild(el, "w:textAlignment");
16428
- if (textAlignment) {
16429
- const val = attr(textAlignment, "w:val");
16430
- if (val) opts.textAlignment = val;
16431
- }
16432
- const outlineLvl = findChild(el, "w:outlineLvl");
16433
- if (outlineLvl) {
16434
- const val = attrNum(outlineLvl, "w:val");
16435
- if (val !== void 0) opts.outlineLevel = val;
16436
16223
  }
16437
- const cnfStyle = findChild(el, "w:cnfStyle");
16438
- if (cnfStyle) {
16439
- const val = attr(cnfStyle, "w:val");
16440
- if (val) opts.cnfStyle = { val };
16224
+ const cxnLst = findChild(el, "dgm:cxnLst");
16225
+ if (!cxnLst) {
16226
+ opts.data = { nodes: [] };
16227
+ return opts;
16441
16228
  }
16442
- const rPr = findChild(el, "w:rPr");
16443
- if (rPr) opts.run = parseRunProperties(rPr);
16444
- const framePr = findChild(el, "w:framePr");
16445
- if (framePr) {
16446
- const frame = {};
16447
- for (const [attrName, optName] of [
16448
- ["w:dropCap", "dropCap"],
16449
- ["w:lines", "lines"],
16450
- ["w:wrap", "wrap"],
16451
- ["w:vAnchor", "vAnchor"],
16452
- ["w:hAnchor", "hAnchor"],
16453
- ["w:x", "x"],
16454
- ["w:y", "y"],
16455
- ["w:hRule", "hRule"],
16456
- ["w:hSpace", "hSpace"],
16457
- ["w:vSpace", "vSpace"]
16458
- ]) {
16459
- const val = attr(framePr, attrName);
16460
- if (val !== void 0) frame[optName] = val;
16229
+ const childrenMap = /* @__PURE__ */ new Map();
16230
+ for (const cxn of cxnLst.elements ?? []) {
16231
+ if (cxn.name !== "dgm:cxn") continue;
16232
+ const srcId = attr(cxn, "srcId");
16233
+ const destId = attr(cxn, "destId");
16234
+ if (!srcId || !destId || !nodeMap.has(destId)) continue;
16235
+ let arr = childrenMap.get(srcId);
16236
+ if (!arr) {
16237
+ arr = [];
16238
+ childrenMap.set(srcId, arr);
16461
16239
  }
16462
- const w = attrNum(framePr, "w:w");
16463
- if (w !== void 0) frame.width = w;
16464
- const h = attrNum(framePr, "w:h");
16465
- if (h !== void 0) frame.height = h;
16466
- if (Object.keys(frame).length > 0) opts.frame = frame;
16240
+ arr.push(destId);
16467
16241
  }
16242
+ opts.data = { nodes: (childrenMap.get("0") ?? []).map((id) => buildSmartArtNode(id, nodeMap, childrenMap)) };
16468
16243
  return opts;
16469
16244
  }
16245
+ function buildSmartArtNode(id, nodeMap, childrenMap) {
16246
+ const text = nodeMap.get(id) ?? "";
16247
+ const childIds = childrenMap.get(id) ?? [];
16248
+ if (childIds.length === 0) return { text };
16249
+ return {
16250
+ text,
16251
+ children: childIds.map((cid) => buildSmartArtNode(cid, nodeMap, childrenMap))
16252
+ };
16253
+ }
16254
+ //#endregion
16255
+ //#region src/file/paragraph/run/run-parse.ts
16470
16256
  /**
16471
- * Parse a w:p element into ParagraphOptions.
16257
+ * Run properties parser for DOCX documents.
16258
+ *
16259
+ * Parses w:rPr Element trees into RunPropertiesOptions objects.
16260
+ *
16261
+ * @module
16472
16262
  */
16473
- function parseParagraph(el, ctx) {
16263
+ /**
16264
+ * Parse a w:rPr element into RunPropertiesOptions.
16265
+ */
16266
+ function parseRunProperties(el) {
16474
16267
  const opts = {};
16475
- const pPr = findChild(el, "w:pPr");
16476
- if (pPr) Object.assign(opts, parseParagraphProperties(pPr, ctx));
16477
- const childList = [];
16478
- for (const child of el.elements ?? []) switch (child.name) {
16479
- case "w:pPr": break;
16480
- case "w:r": {
16481
- const parsed = parseRun(child, ctx);
16482
- const rawChildren = parsed.children.filter((c) => c instanceof RawPassthrough);
16483
- const runOpts = parsedRunToOptions({
16484
- ...parsed,
16485
- children: parsed.children.filter((c) => !(c instanceof RawPassthrough))
16486
- });
16487
- childList.push(runOpts);
16488
- childList.push(...rawChildren);
16268
+ const rStyle = findChild(el, "w:rStyle");
16269
+ if (rStyle) opts.style = attr(rStyle, "w:val");
16270
+ const font = findChild(el, "w:rFonts");
16271
+ if (font) {
16272
+ const ascii = attr(font, "w:ascii");
16273
+ const eastAsia = attr(font, "w:eastAsia");
16274
+ const hAnsi = attr(font, "w:hAnsi");
16275
+ const cs = attr(font, "w:cs");
16276
+ const hint = attr(font, "w:hint");
16277
+ if (ascii && !eastAsia && !hAnsi && !cs) opts.font = hint ? {
16278
+ name: ascii,
16279
+ hint
16280
+ } : ascii;
16281
+ else {
16282
+ const fontObj = {};
16283
+ if (ascii) fontObj.ascii = ascii;
16284
+ if (eastAsia) fontObj.eastAsia = eastAsia;
16285
+ if (hAnsi) fontObj.hAnsi = hAnsi;
16286
+ if (cs) fontObj.cs = cs;
16287
+ if (hint) fontObj.hint = hint;
16288
+ opts.font = fontObj;
16289
+ }
16290
+ }
16291
+ const bold = findChild(el, "w:b");
16292
+ if (bold) opts.bold = attrBool(bold, "w:val") ?? true;
16293
+ const boldCs = findChild(el, "w:bCs");
16294
+ if (boldCs) opts.boldComplexScript = attrBool(boldCs, "w:val") ?? true;
16295
+ const italics = findChild(el, "w:i");
16296
+ if (italics) opts.italics = attrBool(italics, "w:val") ?? true;
16297
+ const italicsCs = findChild(el, "w:iCs");
16298
+ if (italicsCs) opts.italicsComplexScript = attrBool(italicsCs, "w:val") ?? true;
16299
+ const underline = findChild(el, "w:u");
16300
+ if (underline) {
16301
+ const ul = {};
16302
+ const uType = attr(underline, "w:val");
16303
+ if (uType) ul.type = uType;
16304
+ const uColor = colorAttr(underline, "w:color");
16305
+ if (uColor) ul.color = uColor;
16306
+ opts.underline = ul;
16307
+ }
16308
+ for (const [name, optKey] of [
16309
+ ["w:strike", "strike"],
16310
+ ["w:dstrike", "doubleStrike"],
16311
+ ["w:outline", "outline"],
16312
+ ["w:shadow", "shadow"],
16313
+ ["w:emboss", "emboss"],
16314
+ ["w:imprint", "imprint"],
16315
+ ["w:vanish", "vanish"],
16316
+ ["w:webHidden", "webHidden"],
16317
+ ["w:noProof", "noProof"],
16318
+ ["w:snapToGrid", "snapToGrid"],
16319
+ ["w:smallCaps", "smallCaps"],
16320
+ ["w:caps", "allCaps"],
16321
+ ["w:rtl", "rightToLeft"],
16322
+ ["w:cs", "complexScript"],
16323
+ ["w:specVanish", "specVanish"],
16324
+ ["w:math", "math"]
16325
+ ]) {
16326
+ const child = findChild(el, name);
16327
+ if (child) opts[optKey] = attrBool(child, "w:val") ?? true;
16328
+ }
16329
+ const color = findChild(el, "w:color");
16330
+ if (color) {
16331
+ const c = colorAttr(color, "w:val");
16332
+ if (c) opts.color = c;
16333
+ }
16334
+ const sz = findChild(el, "w:sz");
16335
+ if (sz) {
16336
+ const halfPts = attrNum(sz, "w:val");
16337
+ if (halfPts !== void 0) opts.size = halfPts;
16338
+ }
16339
+ const szCs = findChild(el, "w:szCs");
16340
+ if (szCs) {
16341
+ const halfPts = attrNum(szCs, "w:val");
16342
+ if (halfPts !== void 0) opts.sizeComplexScript = halfPts;
16343
+ }
16344
+ const highlight = findChild(el, "w:highlight");
16345
+ if (highlight) {
16346
+ const val = attr(highlight, "w:val");
16347
+ if (val) opts.highlight = val;
16348
+ }
16349
+ const highlightCs = findChild(el, "w:highlightCs");
16350
+ if (highlightCs) {
16351
+ const val = attr(highlightCs, "w:val");
16352
+ if (val) opts.highlightComplexScript = val;
16353
+ }
16354
+ const vertAlign = findChild(el, "w:vertAlign");
16355
+ if (vertAlign) {
16356
+ const val = attr(vertAlign, "w:val");
16357
+ if (val === "subscript") opts.subScript = true;
16358
+ else if (val === "superscript") opts.superScript = true;
16359
+ }
16360
+ const effect = findChild(el, "w:effect");
16361
+ if (effect) {
16362
+ const val = attr(effect, "w:val");
16363
+ if (val) opts.effect = val;
16364
+ }
16365
+ const emphasisMark = findChild(el, "w:em");
16366
+ if (emphasisMark) {
16367
+ const val = attr(emphasisMark, "w:val");
16368
+ if (val) opts.emphasisMark = { type: val };
16369
+ }
16370
+ const spacing = findChild(el, "w:spacing");
16371
+ if (spacing) {
16372
+ const val = attrNum(spacing, "w:val");
16373
+ if (val !== void 0) opts.characterSpacing = val;
16374
+ }
16375
+ const scale = findChild(el, "w:w");
16376
+ if (scale) {
16377
+ const val = attrNum(scale, "w:val");
16378
+ if (val !== void 0) opts.scale = val;
16379
+ }
16380
+ const kern = findChild(el, "w:kern");
16381
+ if (kern) {
16382
+ const val = attrNum(kern, "w:val");
16383
+ if (val !== void 0) opts.kern = val;
16384
+ }
16385
+ const position = findChild(el, "w:position");
16386
+ if (position) {
16387
+ const val = attr(position, "w:val");
16388
+ if (val !== void 0) opts.position = val;
16389
+ }
16390
+ const fitText = findChild(el, "w:fitText");
16391
+ if (fitText) {
16392
+ const val = attrNum(fitText, "w:val");
16393
+ if (val !== void 0) opts.fitText = val;
16394
+ }
16395
+ const lang = findChild(el, "w:lang");
16396
+ if (lang) {
16397
+ const langObj = {};
16398
+ const val = attr(lang, "w:val");
16399
+ if (val) langObj.val = val;
16400
+ const eastAsia = attr(lang, "w:eastAsia");
16401
+ if (eastAsia) langObj.eastAsia = eastAsia;
16402
+ const bidi = attr(lang, "w:bidi");
16403
+ if (bidi) langObj.bidi = bidi;
16404
+ if (Object.keys(langObj).length > 0) opts.language = langObj;
16405
+ }
16406
+ const bdr = findChild(el, "w:bdr");
16407
+ if (bdr) opts.border = parseBorder(bdr);
16408
+ const shd = findChild(el, "w:shd");
16409
+ if (shd) opts.shading = parseShading(shd);
16410
+ return opts;
16411
+ }
16412
+ /**
16413
+ * Parse a w:bdr element into BorderOptions.
16414
+ */
16415
+ function parseBorder(el) {
16416
+ const opts = {};
16417
+ const style = attr(el, "w:val");
16418
+ if (style) opts.style = style;
16419
+ const color = colorAttr(el, "w:color");
16420
+ if (color) opts.color = color;
16421
+ const size = attrNum(el, "w:sz");
16422
+ if (size !== void 0) opts.size = size;
16423
+ const space = attrNum(el, "w:space");
16424
+ if (space !== void 0) opts.space = space;
16425
+ const shadow = attrBool(el, "w:shadow");
16426
+ if (shadow !== void 0) opts.shadow = shadow;
16427
+ const frame = attrBool(el, "w:frame");
16428
+ if (frame !== void 0) opts.frame = frame;
16429
+ return opts;
16430
+ }
16431
+ /**
16432
+ * Parse a w:shd element into ShadingAttributesProperties.
16433
+ */
16434
+ function parseShading(el) {
16435
+ const opts = {};
16436
+ const fill = colorAttr(el, "w:fill");
16437
+ if (fill) opts.fill = fill;
16438
+ const color = colorAttr(el, "w:color");
16439
+ if (color) opts.color = color;
16440
+ const type = attr(el, "w:val");
16441
+ if (type) opts.type = type;
16442
+ return opts;
16443
+ }
16444
+ /** Matches w:br[@w:type="page"] → PageBreak */
16445
+ const PARSED_PAGE_BREAK = Symbol("PageBreak");
16446
+ /** Matches w:br (line break) */
16447
+ const PARSED_LINE_BREAK = Symbol("LineBreak");
16448
+ /** Matches w:tab */
16449
+ const PARSED_TAB = Symbol("Tab");
16450
+ /** Matches w:cr */
16451
+ const PARSED_CR = Symbol("CarriageReturn");
16452
+ /** Matches w:noBreakHyphen */
16453
+ const PARSED_NO_BREAK_HYPHEN = Symbol("NoBreakHyphen");
16454
+ /** Matches w:softHyphen */
16455
+ const PARSED_SOFT_HYPHEN = Symbol("SoftHyphen");
16456
+ /** Matches w:footnoteRef — auto-generated by Footnote class */
16457
+ const PARSED_FOOTNOTE_REF = Symbol("FootnoteRef");
16458
+ /** Matches w:br[@w:type="column"] */
16459
+ const PARSED_COLUMN_BREAK = Symbol("ColumnBreak");
16460
+ /**
16461
+ * Parse a w:r element into run data.
16462
+ * Returns { properties, children } where children are parsed run content items.
16463
+ */
16464
+ function parseRun(el, _ctx) {
16465
+ const rPr = findChild(el, "w:rPr");
16466
+ const properties = rPr ? parseRunProperties(rPr) : void 0;
16467
+ const children = [];
16468
+ for (const child of el.elements ?? []) switch (child.name) {
16469
+ case "w:rPr": break;
16470
+ case "w:t": {
16471
+ const preserveSpace = attrBool(child, "xml:space");
16472
+ let text = textOf(child);
16473
+ if (preserveSpace && text) {}
16474
+ children.push(text);
16489
16475
  break;
16490
16476
  }
16491
- case "w:hyperlink": {
16492
- const hl = {};
16493
- const rId = attr(child, "r:id");
16494
- if (rId) {
16495
- const target = ctx.docx.partRefs.hyperlinks.get(rId);
16496
- if (target) hl.link = target;
16497
- }
16498
- const anchor = attr(child, "w:anchor");
16499
- if (anchor) hl.anchor = anchor;
16500
- const tooltip = attr(child, "w:tooltip");
16501
- if (tooltip) hl.tooltip = tooltip;
16502
- const linkRuns = [];
16503
- for (const sub of child.elements ?? []) if (sub.name === "w:r") {
16504
- const runOpts = parsedRunToOptions(parseRun(sub, ctx));
16505
- linkRuns.push(runOpts);
16506
- }
16507
- if (linkRuns.length > 0) {
16508
- hl.children = linkRuns;
16509
- childList.push({ hyperlink: hl });
16510
- }
16477
+ case "w:delText": {
16478
+ const text = textOf(child);
16479
+ if (text) children.push(text);
16511
16480
  break;
16512
16481
  }
16513
- case "w:bookmarkStart": {
16482
+ case "w:br": {
16483
+ const brType = attr(child, "w:type");
16484
+ if (brType === "page") children.push(PARSED_PAGE_BREAK);
16485
+ else if (brType === "column") children.push(PARSED_COLUMN_BREAK);
16486
+ else children.push(PARSED_LINE_BREAK);
16487
+ break;
16488
+ }
16489
+ case "w:tab":
16490
+ children.push(PARSED_TAB);
16491
+ break;
16492
+ case "w:cr":
16493
+ children.push(PARSED_CR);
16494
+ break;
16495
+ case "w:noBreakHyphen":
16496
+ children.push(PARSED_NO_BREAK_HYPHEN);
16497
+ break;
16498
+ case "w:softHyphen":
16499
+ children.push(PARSED_SOFT_HYPHEN);
16500
+ break;
16501
+ case "w:commentReference": {
16514
16502
  const id = attrNum(child, "w:id");
16515
- const name = attr(child, "w:name");
16516
- if (id !== void 0 && name) childList.push({ bookmarkStart: {
16517
- id,
16518
- name
16503
+ if (id !== void 0) children.push({ commentReference: id });
16504
+ break;
16505
+ }
16506
+ case "w:drawing":
16507
+ case "w:pict": break;
16508
+ case "w:sym": {
16509
+ const charVal = attr(child, "w:char");
16510
+ const fontVal = attr(child, "w:font");
16511
+ if (charVal) children.push({ symbolRun: {
16512
+ char: charVal,
16513
+ symbolfont: fontVal ?? "Wingdings"
16519
16514
  } });
16520
16515
  break;
16521
16516
  }
16522
- case "w:bookmarkEnd": {
16517
+ case "w:footnoteReference": {
16523
16518
  const id = attrNum(child, "w:id");
16524
- if (id !== void 0) childList.push({ bookmarkEnd: id });
16519
+ if (id !== void 0) children.push({ footnoteReference: id });
16525
16520
  break;
16526
16521
  }
16527
- case "w:commentRangeStart": {
16522
+ case "w:endnoteReference": {
16528
16523
  const id = attrNum(child, "w:id");
16529
- if (id !== void 0) childList.push({ commentRangeStart: id });
16524
+ if (id !== void 0) children.push({ endnoteReference: id });
16530
16525
  break;
16531
16526
  }
16532
- case "w:commentRangeEnd": {
16533
- const id = attrNum(child, "w:id");
16534
- if (id !== void 0) childList.push({ commentRangeEnd: id });
16535
- break;
16536
- }
16537
- case "w:commentReference": {
16538
- const id = attrNum(child, "w:id");
16539
- if (id !== void 0) childList.push({ commentReference: id });
16527
+ case "w:footnoteRef":
16528
+ case "w:endnoteRef":
16529
+ children.push(PARSED_FOOTNOTE_REF);
16540
16530
  break;
16541
- }
16542
- case "m:oMath": {
16543
- const mathChildren = parseMathChildren(child);
16544
- childList.push({ math: { children: mathChildren } });
16545
- break;
16546
- }
16547
16531
  default:
16548
- if (child.name && child.elements && child.elements.length > 0) childList.push(new RawPassthrough(child));
16532
+ if (child.name && child.elements && child.elements.length > 0) children.push(new RawPassthrough(child));
16549
16533
  break;
16550
16534
  }
16551
- if (childList.length > 0) {
16552
- if (childList.every((c) => typeof c === "object" && c !== null && "text" in c && Object.keys(c).length <= 2)) {
16553
- const combined = childList.map((c) => c.text).join("");
16554
- if (combined && Object.keys(opts).length === 0) return combined;
16555
- if (combined) {
16556
- opts.text = combined;
16557
- return opts;
16558
- }
16559
- }
16560
- opts.children = childList;
16561
- }
16562
- return opts;
16535
+ return {
16536
+ properties,
16537
+ children
16538
+ };
16563
16539
  }
16564
- //#endregion
16565
- //#region src/file/alt-chunk/alt-chunk-parse.ts
16566
16540
  /**
16567
- * AltChunk parser for DOCX documents.
16568
- *
16569
- * Parses w:altChunk elements and extracts embedded content from the ZIP.
16570
- *
16571
- * @module
16572
- */
16573
- /**
16574
- * Parse a w:altChunk element into AltChunkOptions.
16575
- * Reads the referenced data from the ZIP package.
16541
+ * Convert parsed run data into an RunOptions suitable for the Document constructor.
16542
+ * Simplifies the parsed children into text + break format.
16543
+ * If the run contains only a commentReference, returns { commentReference: id } instead.
16544
+ * If the run only contains footnoteRef/endnoteRef (auto-generated), returns empty options.
16576
16545
  */
16577
- function parseAltChunk(el, ctx) {
16578
- const rId = attr(el, "r:id");
16579
- if (!rId) throw new Error("w:altChunk missing r:id attribute");
16580
- const path = ctx.docx.partRefs.afChunks.get(rId);
16581
- if (!path) throw new Error(`AltChunk relationship ${rId} not found`);
16582
- const data = ctx.docx.doc.getRaw(path);
16583
- if (!data) throw new Error(`AltChunk data not found at ${path}`);
16584
- const ext = path.split(".").pop() ?? "txt";
16585
- let contentType;
16586
- let extension;
16587
- switch (ext) {
16588
- case "html":
16589
- contentType = "text/html";
16590
- extension = "html";
16591
- break;
16592
- case "rtf":
16593
- contentType = "application/rtf";
16594
- extension = "rtf";
16595
- break;
16596
- default:
16597
- contentType = "text/plain";
16598
- extension = "txt";
16599
- break;
16600
- }
16601
- return {
16602
- data,
16603
- contentType,
16604
- extension
16605
- };
16546
+ function parsedRunToOptions(parsed) {
16547
+ const contentChildren = parsed.children.filter((c) => c !== PARSED_FOOTNOTE_REF);
16548
+ if (contentChildren.length === 0 && parsed.children.some((c) => c === PARSED_FOOTNOTE_REF)) return null;
16549
+ const opts = { ...parsed.properties };
16550
+ const isRefChild = (c) => typeof c === "object" && c !== null && ("commentReference" in c || "footnoteReference" in c || "endnoteReference" in c);
16551
+ const refChildren = contentChildren.filter(isRefChild);
16552
+ const nonRefChildren = contentChildren.filter((c) => !isRefChild(c));
16553
+ if (refChildren.length > 0 && nonRefChildren.length === 0) return refChildren[0];
16554
+ const symbolIdx = nonRefChildren.findIndex((c) => typeof c === "object" && c !== null && "symbolRun" in c);
16555
+ if (symbolIdx >= 0 && nonRefChildren.length === 1 && !parsed.properties) return nonRefChildren[symbolIdx];
16556
+ const textParts = [];
16557
+ let breakCount = 0;
16558
+ let hasPageBreak = false;
16559
+ let hasColumnBreak = false;
16560
+ for (const child of nonRefChildren) if (typeof child === "string") textParts.push(child);
16561
+ else if (child === PARSED_LINE_BREAK) breakCount++;
16562
+ else if (child === PARSED_PAGE_BREAK) hasPageBreak = true;
16563
+ else if (child === PARSED_COLUMN_BREAK) hasColumnBreak = true;
16564
+ if (textParts.length > 0) opts.text = textParts.join("");
16565
+ if (breakCount > 0) opts.break = breakCount;
16566
+ if (hasPageBreak) opts.pageBreak = true;
16567
+ if (hasColumnBreak) opts.columnBreak = true;
16568
+ if (Object.keys(opts).length === 0 && textParts.length === 0 && breakCount === 0 && !hasPageBreak && !hasColumnBreak) return null;
16569
+ return opts;
16606
16570
  }
16607
16571
  //#endregion
16608
- //#region src/file/drawing/drawing-parse.ts
16572
+ //#region src/file/paragraph/paragraph-parse.ts
16609
16573
  /**
16610
- * Drawing parser for DOCX documents.
16574
+ * Paragraph parser for DOCX documents.
16611
16575
  *
16612
- * Parses w:drawing elements and extracts image, chart, or SmartArt data.
16576
+ * Parses w:p and w:pPr Element trees into ParagraphOptions objects.
16613
16577
  *
16614
16578
  * @module
16615
16579
  */
16580
+ init_style();
16581
+ init_math_parse();
16582
+ const HEADING_MAP = {
16583
+ Heading1: HeadingLevel.HEADING_1,
16584
+ Heading2: HeadingLevel.HEADING_2,
16585
+ Heading3: HeadingLevel.HEADING_3,
16586
+ Heading4: HeadingLevel.HEADING_4,
16587
+ Heading5: HeadingLevel.HEADING_5,
16588
+ Heading6: HeadingLevel.HEADING_6,
16589
+ Title: HeadingLevel.TITLE
16590
+ };
16616
16591
  /**
16617
- * Parse a w:drawing element and dispatch to the correct parser
16618
- * based on the graphicData URI.
16619
- */
16620
- function parseDrawingRun(el, ctx) {
16621
- const graphicData = findDeep(el, "a:graphicData")[0];
16622
- if (!graphicData) return void 0;
16623
- const uri = attr(graphicData, "uri") ?? "";
16624
- if (uri.includes("/chart")) return parseChartDrawing(el, ctx);
16625
- if (uri.includes("/diagram")) return parseSmartArtDrawing(el, ctx);
16626
- return parseImageRun(el, ctx);
16627
- }
16628
- /**
16629
- * Determine image type from file extension or MIME type.
16592
+ * Parse w:pPr element into paragraph properties (without children).
16630
16593
  */
16631
- function imageTypeFromPath(path) {
16632
- switch (path.split(".").pop()?.toLowerCase() ?? "") {
16633
- case "jpg":
16634
- case "jpeg": return "jpg";
16635
- case "png": return "png";
16636
- case "gif": return "gif";
16637
- case "bmp": return "bmp";
16638
- case "tif":
16639
- case "tiff": return "tif";
16640
- case "ico": return "ico";
16641
- case "emf": return "emf";
16642
- case "wmf": return "wmf";
16643
- default: return "png";
16594
+ function parseParagraphProperties(el, _ctx) {
16595
+ const opts = {};
16596
+ const pStyle = findChild(el, "w:pStyle");
16597
+ if (pStyle) {
16598
+ const styleVal = attr(pStyle, "w:val");
16599
+ if (styleVal) if (HEADING_MAP[styleVal]) opts.heading = HEADING_MAP[styleVal];
16600
+ else opts.style = styleVal;
16644
16601
  }
16645
- }
16646
- /**
16647
- * Parse a w:drawing element and return image data wrapped in { image: ... }.
16648
- */
16649
- function parseImageRun(el, ctx) {
16650
- const inline = findDeep(el, "wp:inline")[0];
16651
- const anchor = inline ? void 0 : findDeep(el, "wp:anchor")[0];
16652
- const parent = inline ?? anchor;
16653
- if (!parent) return void 0;
16654
- const extent = findChild(parent, "wp:extent");
16655
- let width;
16656
- let height;
16657
- if (extent) {
16658
- const cxEmu = attrNum(extent, "cx");
16659
- const cyEmu = attrNum(extent, "cy");
16660
- if (cxEmu !== void 0) width = convertEmuToPixels(cxEmu);
16661
- if (cyEmu !== void 0) height = convertEmuToPixels(cyEmu);
16602
+ const jc = findChild(el, "w:jc");
16603
+ if (jc) {
16604
+ const val = attr(jc, "w:val");
16605
+ if (val) opts.alignment = val;
16662
16606
  }
16663
- const blip = findDeep(parent, "a:blip")[0];
16664
- if (!blip) return void 0;
16665
- const rEmbed = attr(blip, "r:embed");
16666
- if (!rEmbed) return void 0;
16667
- const mediaPath = ctx.docx.partRefs.media.get(rEmbed);
16668
- if (!mediaPath) return void 0;
16669
- const imageData = ctx.docx.doc.getRaw(mediaPath);
16670
- if (!imageData) return void 0;
16671
- const imageOpts = {
16672
- type: imageTypeFromPath(mediaPath),
16673
- data: imageData,
16674
- transformation: {
16675
- ...width !== void 0 ? { width } : {},
16676
- ...height !== void 0 ? { height } : {}
16677
- }
16678
- };
16679
- const docPr = findChild(parent, "wp:docPr");
16680
- if (docPr) {
16681
- const name = attr(docPr, "name");
16682
- const descr = attr(docPr, "descr");
16683
- if (name || descr) imageOpts.altText = {
16684
- ...name ? { name } : {},
16685
- ...descr ? { description: descr } : {}
16686
- };
16607
+ const spacing = findChild(el, "w:spacing");
16608
+ if (spacing) {
16609
+ const sp = {};
16610
+ const before = attrNum(spacing, "w:before");
16611
+ if (before !== void 0) sp.before = before;
16612
+ const after = attrNum(spacing, "w:after");
16613
+ if (after !== void 0) sp.after = after;
16614
+ const line = attrNum(spacing, "w:line");
16615
+ if (line !== void 0) sp.line = line;
16616
+ const lineRule = attr(spacing, "w:lineRule");
16617
+ if (lineRule) sp.lineRule = lineRule;
16618
+ const beforeAuto = attrBool(spacing, "w:beforeAutospacing") ?? attrBool(spacing, "w:beforeLines");
16619
+ if (beforeAuto !== void 0) sp.beforeAutoSpacing = beforeAuto;
16620
+ const afterAuto = attrBool(spacing, "w:afterAutospacing") ?? attrBool(spacing, "w:afterLines");
16621
+ if (afterAuto !== void 0) sp.afterAutoSpacing = afterAuto;
16622
+ if (Object.keys(sp).length > 0) opts.spacing = sp;
16687
16623
  }
16688
- if (anchor && !inline) {
16689
- const floating = {};
16690
- const posH = findChild(anchor, "wp:positionH");
16691
- if (posH) {
16692
- const align = findChild(posH, "wp:align");
16693
- const posOffset = findChild(posH, "wp:posOffset");
16694
- if (align) floating.horizontalPosition = { align: textOf(align) };
16695
- else if (posOffset) floating.horizontalPosition = { offset: attrNum(posOffset, "offset") ?? 0 };
16696
- }
16697
- const posV = findChild(anchor, "wp:positionV");
16698
- if (posV) {
16699
- const align = findChild(posV, "wp:align");
16700
- const posOffset = findChild(posV, "wp:posOffset");
16701
- if (align) floating.verticalPosition = { align: textOf(align) };
16702
- else if (posOffset) floating.verticalPosition = { offset: attrNum(posOffset, "offset") ?? 0 };
16703
- }
16704
- for (const wrapType of [
16705
- "wrapSquare",
16706
- "wrapTight",
16707
- "wrapTopAndBottom",
16708
- "wrapNone"
16709
- ]) if (findChild(anchor, `wp:${wrapType}`)) {
16710
- floating.wrap = wrapType;
16711
- break;
16712
- }
16713
- if (attrBool(anchor, "behindDoc")) floating.behindDocument = true;
16714
- if (Object.keys(floating).length > 0) imageOpts.floating = floating;
16624
+ const ind = findChild(el, "w:ind");
16625
+ if (ind) {
16626
+ const indentObj = {};
16627
+ const left = attrNum(ind, "w:left");
16628
+ if (left !== void 0) indentObj.left = left;
16629
+ const right = attrNum(ind, "w:right");
16630
+ if (right !== void 0) indentObj.right = right;
16631
+ const start = attrNum(ind, "w:start");
16632
+ if (start !== void 0) indentObj.start = start;
16633
+ const end = attrNum(ind, "w:end");
16634
+ if (end !== void 0) indentObj.end = end;
16635
+ const hanging = attrNum(ind, "w:hanging");
16636
+ if (hanging !== void 0) indentObj.hanging = hanging;
16637
+ const firstLine = attrNum(ind, "w:firstLine");
16638
+ if (firstLine !== void 0) indentObj.firstLine = firstLine;
16639
+ if (Object.keys(indentObj).length > 0) opts.indent = indentObj;
16715
16640
  }
16716
- return { image: imageOpts };
16717
- }
16718
- function getDrawingExtent(el) {
16719
- const inline = findDeep(el, "wp:inline")[0];
16720
- const anchor = inline ? void 0 : findDeep(el, "wp:anchor")[0];
16721
- const parent = inline ?? anchor;
16722
- if (!parent) return {};
16723
- const extent = findChild(parent, "wp:extent");
16724
- if (!extent) return {};
16725
- const cxEmu = attrNum(extent, "cx");
16726
- const cyEmu = attrNum(extent, "cy");
16727
- return {
16728
- ...cxEmu !== void 0 ? { width: convertEmuToPixels(cxEmu) } : {},
16729
- ...cyEmu !== void 0 ? { height: convertEmuToPixels(cyEmu) } : {}
16730
- };
16731
- }
16732
- /**
16733
- * Look up a relationship ID in a map, with fallback for double "rId" prefix
16734
- * that the library's generation code produces (e.g. "rIdrId7" → "rId7").
16735
- */
16736
- function lookupRId(map, rId) {
16737
- if (!rId) return void 0;
16738
- const direct = map.get(rId);
16739
- if (direct) return direct;
16740
- if (rId.startsWith("rIdrId")) return map.get(rId.slice(3));
16741
- }
16742
- function parseChartDrawing(el, ctx) {
16743
- const chartRef = findDeep(el, "c:chart")[0];
16744
- if (!chartRef) return void 0;
16745
- const rId = attr(chartRef, "r:id");
16746
- const chartPath = lookupRId(ctx.docx.partRefs.charts, rId);
16747
- if (!chartPath) return void 0;
16748
- const chartXml = ctx.docx.doc.get(chartPath);
16749
- if (!chartXml) return void 0;
16750
- const opts = parseChartXml(chartXml);
16751
- if (!opts) return void 0;
16752
- const ext = getDrawingExtent(el);
16753
- if (ext.width !== void 0 || ext.height !== void 0) opts.transformation = { ...ext };
16754
- return { chart: opts };
16755
- }
16756
- /**
16757
- * Parse c:chartSpace element into ChartOptions.
16758
- */
16759
- function parseChartXml(el) {
16760
- const chart = findChild(el, "c:chart");
16761
- if (!chart) return void 0;
16762
- const opts = {};
16763
- const titleEl = findChild(chart, "c:title");
16764
- if (titleEl) {
16765
- const rich = findDeep(titleEl, "c:rich")[0];
16766
- if (rich) {
16767
- const t = findDeep(rich, "a:t")[0];
16768
- if (t) {
16769
- const title = textOf(t);
16770
- if (title) opts.title = title;
16771
- }
16641
+ const numPr = findChild(el, "w:numPr");
16642
+ if (numPr) {
16643
+ const ilvl = findChild(numPr, "w:ilvl");
16644
+ const level = ilvl ? attrNum(ilvl, "w:val") ?? 0 : 0;
16645
+ const numIdEl = findChild(numPr, "w:numId");
16646
+ const numId = numIdEl ? attr(numIdEl, "w:val") : void 0;
16647
+ if (numId !== void 0 && _ctx.numberingCache.size > 0) {
16648
+ const numEl = _ctx.docx.numbering;
16649
+ if (numEl) {
16650
+ let abstractNumId;
16651
+ for (const child of numEl.elements ?? []) {
16652
+ if (child.name !== "w:num") continue;
16653
+ if (attr(child, "w:numId") === numId) {
16654
+ const absRef = findChild(child, "w:abstractNumId");
16655
+ abstractNumId = absRef ? attr(absRef, "w:val") : void 0;
16656
+ break;
16657
+ }
16658
+ }
16659
+ if (abstractNumId !== void 0) opts.numbering = {
16660
+ reference: `list_${numId}`,
16661
+ level
16662
+ };
16663
+ else opts.bullet = { level };
16664
+ } else opts.bullet = { level };
16665
+ } else opts.bullet = { level };
16666
+ }
16667
+ const tabs = findChild(el, "w:tabs");
16668
+ if (tabs) {
16669
+ const tabStops = [];
16670
+ for (const tab of children(tabs, "w:tab")) {
16671
+ const tabObj = {};
16672
+ const pos = attrNum(tab, "w:pos");
16673
+ if (pos !== void 0) tabObj.position = pos;
16674
+ const val = attr(tab, "w:val");
16675
+ if (val) tabObj.type = val;
16676
+ const leader = attr(tab, "w:leader");
16677
+ if (leader) tabObj.leader = leader;
16678
+ tabStops.push(tabObj);
16772
16679
  }
16680
+ if (tabStops.length > 0) opts.tabStops = tabStops;
16773
16681
  }
16774
- const plotArea = findChild(chart, "c:plotArea");
16775
- if (!plotArea) return void 0;
16776
- let chartType;
16777
- let typeElement;
16778
- for (const child of plotArea.elements ?? []) {
16779
- switch (child.name) {
16780
- case "c:barChart": {
16781
- const barDir = findChild(child, "c:barDir");
16782
- chartType = barDir && attr(barDir, "val") === "bar" ? "bar" : "column";
16783
- typeElement = child;
16784
- break;
16682
+ for (const [name, optKey] of [
16683
+ ["w:keepNext", "keepNext"],
16684
+ ["w:keepLines", "keepLines"],
16685
+ ["w:pageBreakBefore", "pageBreakBefore"],
16686
+ ["w:widowControl", "widowControl"],
16687
+ ["w:suppressLineNumbers", "suppressLineNumbers"],
16688
+ ["w:contextualSpacing", "contextualSpacing"],
16689
+ ["w:bidi", "bidirectional"],
16690
+ ["w:wordWrap", "wordWrap"],
16691
+ ["w:suppressAutoHyphens", "suppressAutoHyphens"],
16692
+ ["w:adjustRightInd", "adjustRightInd"],
16693
+ ["w:snapToGrid", "snapToGrid"],
16694
+ ["w:mirrorIndents", "mirrorIndents"],
16695
+ ["w:kinsoku", "kinsoku"],
16696
+ ["w:topLinePunct", "topLinePunct"],
16697
+ ["w:autoSpaceDE", "autoSpaceDE"],
16698
+ ["w:overflowPunct", "overflowPunctuation"],
16699
+ ["w:suppressOverlap", "suppressOverlap"]
16700
+ ]) {
16701
+ const child = findChild(el, name);
16702
+ if (child) opts[optKey] = attrBool(child, "w:val") ?? true;
16703
+ }
16704
+ if (findChild(el, "w:pBdr")) {
16705
+ const pBdr = findChild(el, "w:pBdr");
16706
+ const border = {};
16707
+ for (const side of [
16708
+ "top",
16709
+ "bottom",
16710
+ "left",
16711
+ "right"
16712
+ ]) {
16713
+ const sideEl = findChild(pBdr, `w:${side}`);
16714
+ if (sideEl) {
16715
+ const sideOpts = {};
16716
+ const style = attr(sideEl, "w:val");
16717
+ if (style) sideOpts.style = style;
16718
+ const color = attr(sideEl, "w:color");
16719
+ if (color) sideOpts.color = color;
16720
+ const size = attrNum(sideEl, "w:sz");
16721
+ if (size !== void 0) sideOpts.size = size;
16722
+ const space = attrNum(sideEl, "w:space");
16723
+ if (space !== void 0) sideOpts.space = space;
16724
+ border[side] = sideOpts;
16785
16725
  }
16786
- case "c:lineChart":
16787
- chartType = "line";
16788
- typeElement = child;
16789
- break;
16790
- case "c:pieChart":
16791
- chartType = "pie";
16792
- typeElement = child;
16793
- break;
16794
- case "c:areaChart":
16795
- chartType = "area";
16796
- typeElement = child;
16797
- break;
16798
- case "c:scatterChart":
16799
- chartType = "scatter";
16800
- typeElement = child;
16801
- break;
16802
16726
  }
16803
- if (chartType) break;
16727
+ if (Object.keys(border).length > 0) opts.border = border;
16804
16728
  }
16805
- if (!chartType || !typeElement) return void 0;
16806
- opts.type = chartType;
16807
- const series = [];
16808
- let categories;
16809
- for (const serEl of typeElement.elements ?? []) {
16810
- if (serEl.name !== "c:ser") continue;
16811
- const nameParts = extractStrCache(serEl, "c:tx");
16812
- const cats = extractStrCache(serEl, "c:cat");
16813
- if (cats.length > 0 && !categories) categories = cats;
16814
- const vals = extractNumCache(serEl);
16815
- series.push({
16816
- name: nameParts[0] ?? "",
16817
- values: vals
16818
- });
16729
+ const shd = findChild(el, "w:shd");
16730
+ if (shd) {
16731
+ const shdObj = {};
16732
+ const fill = attr(shd, "w:fill");
16733
+ if (fill) shdObj.fill = fill;
16734
+ const color = attr(shd, "w:color");
16735
+ if (color) shdObj.color = color;
16736
+ const val = attr(shd, "w:val");
16737
+ if (val) shdObj.type = val;
16738
+ if (Object.keys(shdObj).length > 0) opts.shading = shdObj;
16819
16739
  }
16820
- opts.data = {
16821
- categories: categories ?? [],
16822
- series
16823
- };
16824
- opts.showLegend = findChild(chart, "c:legend") !== void 0;
16825
- const styleEl = findChild(el, "c:style");
16826
- if (styleEl) {
16827
- const val = attrNum(styleEl, "val");
16828
- if (val !== void 0) opts.style = val;
16740
+ const textAlignment = findChild(el, "w:textAlignment");
16741
+ if (textAlignment) {
16742
+ const val = attr(textAlignment, "w:val");
16743
+ if (val) opts.textAlignment = val;
16829
16744
  }
16830
- return opts;
16831
- }
16832
- /**
16833
- * Extract string values from c:strCache within a container element.
16834
- */
16835
- function extractStrCache(parent, containerName) {
16836
- const container = findChild(parent, containerName);
16837
- if (!container) return [];
16838
- const cache = findDeep(container, "c:strCache")[0];
16839
- if (!cache) return [];
16840
- const values = [];
16841
- for (const pt of cache.elements ?? []) {
16842
- if (pt.name !== "c:pt") continue;
16843
- const v = findChild(pt, "c:v");
16844
- if (v) values.push(textOf(v) ?? "");
16745
+ const outlineLvl = findChild(el, "w:outlineLvl");
16746
+ if (outlineLvl) {
16747
+ const val = attrNum(outlineLvl, "w:val");
16748
+ if (val !== void 0) opts.outlineLevel = val;
16845
16749
  }
16846
- return values;
16847
- }
16848
- /**
16849
- * Extract numeric values from c:numCache within a c:val container.
16850
- */
16851
- function extractNumCache(parent) {
16852
- const valEl = findChild(parent, "c:val");
16853
- if (!valEl) return [];
16854
- const cache = findDeep(valEl, "c:numCache")[0];
16855
- if (!cache) return [];
16856
- const values = [];
16857
- for (const pt of cache.elements ?? []) {
16858
- if (pt.name !== "c:pt") continue;
16859
- const v = findChild(pt, "c:v");
16860
- if (v) {
16861
- const num = Number(textOf(v));
16862
- if (!isNaN(num)) values.push(num);
16750
+ const cnfStyle = findChild(el, "w:cnfStyle");
16751
+ if (cnfStyle) {
16752
+ const val = attr(cnfStyle, "w:val");
16753
+ if (val) opts.cnfStyle = { val };
16754
+ }
16755
+ const rPr = findChild(el, "w:rPr");
16756
+ if (rPr) opts.run = parseRunProperties(rPr);
16757
+ const framePr = findChild(el, "w:framePr");
16758
+ if (framePr) {
16759
+ const frame = {};
16760
+ for (const [attrName, optName] of [
16761
+ ["w:dropCap", "dropCap"],
16762
+ ["w:lines", "lines"],
16763
+ ["w:wrap", "wrap"],
16764
+ ["w:vAnchor", "vAnchor"],
16765
+ ["w:hAnchor", "hAnchor"],
16766
+ ["w:x", "x"],
16767
+ ["w:y", "y"],
16768
+ ["w:hRule", "hRule"],
16769
+ ["w:hSpace", "hSpace"],
16770
+ ["w:vSpace", "vSpace"]
16771
+ ]) {
16772
+ const val = attr(framePr, attrName);
16773
+ if (val !== void 0) frame[optName] = val;
16863
16774
  }
16775
+ const w = attrNum(framePr, "w:w");
16776
+ if (w !== void 0) frame.width = w;
16777
+ const h = attrNum(framePr, "w:h");
16778
+ if (h !== void 0) frame.height = h;
16779
+ if (Object.keys(frame).length > 0) opts.frame = frame;
16864
16780
  }
16865
- return values;
16866
- }
16867
- function parseSmartArtDrawing(el, ctx) {
16868
- const relIds = findDeep(el, "dgm:relIds")[0];
16869
- if (!relIds) return void 0;
16870
- const rId = attr(relIds, "r:dm");
16871
- const dataPath = lookupRId(ctx.docx.partRefs.diagramData, rId);
16872
- if (!dataPath) return void 0;
16873
- const dataEl = ctx.docx.doc.get(dataPath);
16874
- if (!dataEl) return void 0;
16875
- const opts = parseSmartArtDataXml(dataEl);
16876
- if (!opts) return void 0;
16877
- const ext = getDrawingExtent(el);
16878
- if (ext.width !== void 0 || ext.height !== void 0) opts.transformation = { ...ext };
16879
- return { smartArt: opts };
16781
+ return opts;
16880
16782
  }
16881
16783
  /**
16882
- * Parse dgm:dataModel element into SmartArtOptions.
16784
+ * Parse a w:p element into ParagraphOptions.
16883
16785
  */
16884
- function parseSmartArtDataXml(el) {
16885
- const ptLst = findChild(el, "dgm:ptLst");
16886
- if (!ptLst) return void 0;
16786
+ function parseParagraph(el, ctx) {
16887
16787
  const opts = {};
16888
- const nodeMap = /* @__PURE__ */ new Map();
16889
- for (const pt of ptLst.elements ?? []) {
16890
- if (pt.name !== "dgm:pt") continue;
16891
- const type = attr(pt, "type");
16892
- const modelId = attr(pt, "modelId");
16893
- if (type === "doc") {
16894
- const prSet = findChild(pt, "dgm:prSet");
16895
- if (prSet) {
16896
- const loTypeId = attr(prSet, "loTypeId") ?? "";
16897
- const qsTypeId = attr(prSet, "qsTypeId") ?? "";
16898
- const csTypeId = attr(prSet, "csTypeId") ?? "";
16899
- const layout = loTypeId.split("/").pop();
16900
- if (layout) opts.layout = layout;
16901
- const style = qsTypeId.split("/").pop();
16902
- if (style) opts.style = style;
16903
- const color = csTypeId.split("/").pop();
16904
- if (color) opts.color = color;
16788
+ const pPr = findChild(el, "w:pPr");
16789
+ if (pPr) Object.assign(opts, parseParagraphProperties(pPr, ctx));
16790
+ const childList = [];
16791
+ for (const child of el.elements ?? []) switch (child.name) {
16792
+ case "w:pPr": break;
16793
+ case "w:r": {
16794
+ const drawingEl = findChild(child, "w:drawing");
16795
+ if (drawingEl) {
16796
+ const drawingChild = parseDrawingRun(drawingEl, ctx);
16797
+ if (drawingChild) {
16798
+ childList.push(drawingChild);
16799
+ break;
16800
+ }
16905
16801
  }
16906
- } else if (type === "node" && modelId) {
16907
- const t = findDeep(pt, "a:t")[0];
16908
- nodeMap.set(modelId, t ? textOf(t) ?? "" : "");
16802
+ const parsed = parseRun(child, ctx);
16803
+ const rawChildren = parsed.children.filter((c) => c instanceof RawPassthrough);
16804
+ const runOpts = parsedRunToOptions({
16805
+ ...parsed,
16806
+ children: parsed.children.filter((c) => !(c instanceof RawPassthrough))
16807
+ });
16808
+ if (runOpts !== null) childList.push(runOpts);
16809
+ childList.push(...rawChildren);
16810
+ break;
16909
16811
  }
16812
+ case "w:hyperlink": {
16813
+ const hl = {};
16814
+ const rId = attr(child, "r:id");
16815
+ if (rId) {
16816
+ const target = ctx.docx.partRefs.hyperlinks.get(rId);
16817
+ if (target) hl.link = target;
16818
+ }
16819
+ const anchor = attr(child, "w:anchor");
16820
+ if (anchor) hl.anchor = anchor;
16821
+ const tooltip = attr(child, "w:tooltip");
16822
+ if (tooltip) hl.tooltip = tooltip;
16823
+ const linkRuns = [];
16824
+ for (const sub of child.elements ?? []) if (sub.name === "w:r") {
16825
+ const runOpts = parsedRunToOptions(parseRun(sub, ctx));
16826
+ linkRuns.push(runOpts);
16827
+ }
16828
+ if (linkRuns.length > 0) {
16829
+ hl.children = linkRuns;
16830
+ childList.push({ hyperlink: hl });
16831
+ }
16832
+ break;
16833
+ }
16834
+ case "w:bookmarkStart": {
16835
+ const id = attrNum(child, "w:id");
16836
+ const name = attr(child, "w:name");
16837
+ if (id !== void 0 && name) childList.push({ bookmarkStart: {
16838
+ id,
16839
+ name
16840
+ } });
16841
+ break;
16842
+ }
16843
+ case "w:bookmarkEnd": {
16844
+ const id = attrNum(child, "w:id");
16845
+ if (id !== void 0) childList.push({ bookmarkEnd: id });
16846
+ break;
16847
+ }
16848
+ case "w:commentRangeStart": {
16849
+ const id = attrNum(child, "w:id");
16850
+ if (id !== void 0) childList.push({ commentRangeStart: id });
16851
+ break;
16852
+ }
16853
+ case "w:commentRangeEnd": {
16854
+ const id = attrNum(child, "w:id");
16855
+ if (id !== void 0) childList.push({ commentRangeEnd: id });
16856
+ break;
16857
+ }
16858
+ case "w:commentReference": {
16859
+ const id = attrNum(child, "w:id");
16860
+ if (id !== void 0) childList.push({ commentReference: id });
16861
+ break;
16862
+ }
16863
+ case "m:oMath": {
16864
+ const mathChildren = parseMathChildren(child);
16865
+ childList.push({ math: { children: mathChildren } });
16866
+ break;
16867
+ }
16868
+ case "w:ins": {
16869
+ const insRun = findChild(child, "w:r");
16870
+ if (insRun) {
16871
+ const runOpts = parsedRunToOptions(parseRun(insRun, ctx));
16872
+ if (runOpts !== null && typeof runOpts === "object" && !("commentReference" in runOpts)) childList.push({ insertion: {
16873
+ id: attrNum(child, "w:id") ?? 0,
16874
+ author: attr(child, "w:author") ?? "",
16875
+ date: attr(child, "w:date") ?? "",
16876
+ ...runOpts
16877
+ } });
16878
+ }
16879
+ break;
16880
+ }
16881
+ case "w:del": {
16882
+ const delRun = findChild(child, "w:r");
16883
+ if (delRun) {
16884
+ const runOpts = parsedRunToOptions(parseRun(delRun, ctx));
16885
+ if (runOpts !== null && typeof runOpts === "object" && !("commentReference" in runOpts)) childList.push({ deletion: {
16886
+ id: attrNum(child, "w:id") ?? 0,
16887
+ author: attr(child, "w:author") ?? "",
16888
+ date: attr(child, "w:date") ?? "",
16889
+ ...runOpts
16890
+ } });
16891
+ }
16892
+ break;
16893
+ }
16894
+ default:
16895
+ if (child.name && child.elements && child.elements.length > 0) childList.push(new RawPassthrough(child));
16896
+ break;
16910
16897
  }
16911
- const cxnLst = findChild(el, "dgm:cxnLst");
16912
- if (!cxnLst) {
16913
- opts.data = { nodes: [] };
16914
- return opts;
16915
- }
16916
- const childrenMap = /* @__PURE__ */ new Map();
16917
- for (const cxn of cxnLst.elements ?? []) {
16918
- if (cxn.name !== "dgm:cxn") continue;
16919
- const srcId = attr(cxn, "srcId");
16920
- const destId = attr(cxn, "destId");
16921
- if (!srcId || !destId || !nodeMap.has(destId)) continue;
16922
- let arr = childrenMap.get(srcId);
16923
- if (!arr) {
16924
- arr = [];
16925
- childrenMap.set(srcId, arr);
16898
+ if (childList.length > 0) {
16899
+ if (childList.every((c) => typeof c === "object" && c !== null && "text" in c && Object.keys(c).length === 1)) {
16900
+ const combined = childList.map((c) => c.text).join("");
16901
+ if (combined && Object.keys(opts).length === 0) return combined;
16902
+ if (combined) {
16903
+ opts.text = combined;
16904
+ return opts;
16905
+ }
16926
16906
  }
16927
- arr.push(destId);
16907
+ opts.children = childList;
16928
16908
  }
16929
- opts.data = { nodes: (childrenMap.get("0") ?? []).map((id) => buildSmartArtNode(id, nodeMap, childrenMap)) };
16930
16909
  return opts;
16931
16910
  }
16932
- function buildSmartArtNode(id, nodeMap, childrenMap) {
16933
- const text = nodeMap.get(id) ?? "";
16934
- const childIds = childrenMap.get(id) ?? [];
16935
- if (childIds.length === 0) return { text };
16911
+ //#endregion
16912
+ //#region src/file/alt-chunk/alt-chunk-parse.ts
16913
+ /**
16914
+ * AltChunk parser for DOCX documents.
16915
+ *
16916
+ * Parses w:altChunk elements and extracts embedded content from the ZIP.
16917
+ *
16918
+ * @module
16919
+ */
16920
+ /**
16921
+ * Parse a w:altChunk element into AltChunkOptions.
16922
+ * Reads the referenced data from the ZIP package.
16923
+ */
16924
+ function parseAltChunk(el, ctx) {
16925
+ const rId = attr(el, "r:id");
16926
+ if (!rId) throw new Error("w:altChunk missing r:id attribute");
16927
+ const path = ctx.docx.partRefs.afChunks.get(rId);
16928
+ if (!path) throw new Error(`AltChunk relationship ${rId} not found`);
16929
+ const data = ctx.docx.doc.getRaw(path);
16930
+ if (!data) throw new Error(`AltChunk data not found at ${path}`);
16931
+ const ext = path.split(".").pop() ?? "txt";
16932
+ let contentType;
16933
+ let extension;
16934
+ switch (ext) {
16935
+ case "html":
16936
+ contentType = "text/html";
16937
+ extension = "html";
16938
+ break;
16939
+ case "rtf":
16940
+ contentType = "application/rtf";
16941
+ extension = "rtf";
16942
+ break;
16943
+ default:
16944
+ contentType = "text/plain";
16945
+ extension = "txt";
16946
+ break;
16947
+ }
16936
16948
  return {
16937
- text,
16938
- children: childIds.map((cid) => buildSmartArtNode(cid, nodeMap, childrenMap))
16949
+ data,
16950
+ contentType,
16951
+ extension
16939
16952
  };
16940
16953
  }
16941
16954
  //#endregion
@@ -17223,8 +17236,9 @@ function parseTableProperties(el) {
17223
17236
  }
17224
17237
  const tblW = findChild(el, "w:tblW");
17225
17238
  if (tblW) {
17226
- const size = attrNum(tblW, "w:w");
17239
+ const rawSize = attr(tblW, "w:w");
17227
17240
  const type = attr(tblW, "w:type");
17241
+ const size = type === "pct" ? rawSize : attrNum(tblW, "w:w");
17228
17242
  if (size !== void 0 || type) opts.width = {
17229
17243
  size: size ?? 0,
17230
17244
  ...type ? { type } : {}
@@ -17395,6 +17409,29 @@ function parseTableCellProperties(el) {
17395
17409
  if (Object.keys(borders).length > 0) opts.borders = borders;
17396
17410
  }
17397
17411
  if (findChild(el, "w:noWrap")) opts.noWrap = true;
17412
+ const tcMar = findChild(el, "w:tcMar");
17413
+ if (tcMar) {
17414
+ const margins = {};
17415
+ let marginUnitType;
17416
+ for (const side of [
17417
+ "top",
17418
+ "bottom",
17419
+ "left",
17420
+ "right"
17421
+ ]) {
17422
+ const sideEl = findChild(tcMar, `w:${side}`);
17423
+ if (sideEl) {
17424
+ const size = attrNum(sideEl, "w:w");
17425
+ const type = attr(sideEl, "w:type");
17426
+ if (size !== void 0) {
17427
+ margins[side] = size;
17428
+ if (type && !marginUnitType) marginUnitType = type;
17429
+ }
17430
+ }
17431
+ }
17432
+ if (marginUnitType) margins.marginUnitType = marginUnitType;
17433
+ if (Object.keys(margins).length > 0) opts.margins = margins;
17434
+ }
17398
17435
  const textDirection = findChild(el, "w:textDirection");
17399
17436
  if (textDirection) {
17400
17437
  const val = attr(textDirection, "w:val");
@@ -17538,10 +17575,15 @@ function parseSectionProperties(el, ctx) {
17538
17575
  const page = {};
17539
17576
  const size = {};
17540
17577
  const w = attrNum(pgSz, "w:w");
17541
- if (w !== void 0) size.width = w;
17542
17578
  const h = attrNum(pgSz, "w:h");
17543
- if (h !== void 0) size.height = h;
17544
17579
  const orient = attr(pgSz, "w:orient");
17580
+ if (orient === "landscape" && w !== void 0 && h !== void 0) {
17581
+ size.width = h;
17582
+ size.height = w;
17583
+ } else {
17584
+ if (w !== void 0) size.width = w;
17585
+ if (h !== void 0) size.height = h;
17586
+ }
17545
17587
  if (orient) size.orientation = orient;
17546
17588
  if (Object.keys(size).length > 0) page.size = size;
17547
17589
  const pgMar = findChild(el, "w:pgMar");
@@ -17612,8 +17654,8 @@ function parseSectionProperties(el, ctx) {
17612
17654
  const lnNumType = findChild(el, "w:lnNumType");
17613
17655
  if (lnNumType) {
17614
17656
  const lineNumbers = {};
17615
- const count = attrNum(lnNumType, "w:count");
17616
- if (count !== void 0) lineNumbers.count = count;
17657
+ const countBy = attrNum(lnNumType, "w:countBy");
17658
+ if (countBy !== void 0) lineNumbers.countBy = countBy;
17617
17659
  const start = attrNum(lnNumType, "w:start");
17618
17660
  if (start !== void 0) lineNumbers.start = start;
17619
17661
  const restart = attr(lnNumType, "w:restart");
@@ -17622,6 +17664,41 @@ function parseSectionProperties(el, ctx) {
17622
17664
  if (distance !== void 0) lineNumbers.distance = distance;
17623
17665
  if (Object.keys(lineNumbers).length > 0) opts.lineNumbers = lineNumbers;
17624
17666
  }
17667
+ const pgBorders = findChild(el, "w:pgBorders");
17668
+ if (pgBorders) {
17669
+ const borders = {};
17670
+ for (const side of [
17671
+ "top",
17672
+ "left",
17673
+ "bottom",
17674
+ "right"
17675
+ ]) {
17676
+ const sideEl = findChild(pgBorders, `w:${side}`);
17677
+ if (sideEl) {
17678
+ const b = {};
17679
+ const val = attr(sideEl, "w:val");
17680
+ if (val) b.style = val;
17681
+ const color = attr(sideEl, "w:color");
17682
+ if (color) b.color = color;
17683
+ const sz = attrNum(sideEl, "w:sz");
17684
+ if (sz !== void 0) b.size = sz;
17685
+ const space = attrNum(sideEl, "w:space");
17686
+ if (space !== void 0) b.space = space;
17687
+ borders[side] = b;
17688
+ }
17689
+ }
17690
+ const display = attr(pgBorders, "w:display");
17691
+ if (display) borders.display = display;
17692
+ const offsetFrom = attr(pgBorders, "w:offsetFrom");
17693
+ if (offsetFrom) borders.offsetFrom = offsetFrom;
17694
+ const zOrder = attr(pgBorders, "w:zOrder");
17695
+ if (zOrder) borders.zOrder = zOrder;
17696
+ if (Object.keys(borders).length > 0) {
17697
+ const page = opts.page ?? {};
17698
+ page.borders = borders;
17699
+ opts.page = page;
17700
+ }
17701
+ }
17625
17702
  const vAlign = findChild(el, "w:vAlign");
17626
17703
  if (vAlign) {
17627
17704
  const val = attr(vAlign, "w:val");
@@ -17672,18 +17749,6 @@ function parseHeaderFooterRef(rId, ctx) {
17672
17749
  function parseSectionChild(el, ctx) {
17673
17750
  switch (el.name) {
17674
17751
  case "w:p": {
17675
- const drawing = findDeepElement(el, "w:drawing");
17676
- if (drawing) {
17677
- const drawingChild = parseDrawingRun(drawing, ctx);
17678
- if (drawingChild) {
17679
- const paraOpts = parseParagraph(el, ctx);
17680
- const existingChildren = paraOpts.children ?? [];
17681
- return { paragraph: {
17682
- ...paraOpts,
17683
- children: [...existingChildren ?? [], drawingChild]
17684
- } };
17685
- }
17686
- }
17687
17752
  const pict = findChild(el, "w:pict");
17688
17753
  if (pict) {
17689
17754
  if (findDeepElement(pict, "v:textbox")) return { textbox: parseTextbox(pict, ctx) };
@@ -17750,7 +17815,8 @@ function parseBody(body, ctx) {
17750
17815
  let start = 0;
17751
17816
  for (let i = 0; i < boundaries.length; i++) {
17752
17817
  const boundary = boundaries[i];
17753
- const sectionElements = bodyChildren.slice(start, boundary.index);
17818
+ const endIdx = i < boundaries.length - 1 ? Math.max(start, boundary.index - 1) : boundary.index;
17819
+ const sectionElements = bodyChildren.slice(start, endIdx);
17754
17820
  const parsedProps = parseSectionProperties(boundary.sectPr, ctx);
17755
17821
  const rawProps = parsedProps;
17756
17822
  const parsedHeaders = rawProps.parsedHeaders;
@@ -17841,6 +17907,7 @@ function parseNumberingDefinitions(el) {
17841
17907
  const levelOpts = parseLevel(child);
17842
17908
  if (levelOpts) levels.push(levelOpts);
17843
17909
  }
17910
+ if (levels.length > 0 && levels.every((l) => l.format === "bullet")) continue;
17844
17911
  if (levels.length > 0) configs.push({
17845
17912
  reference: `list_${numId}`,
17846
17913
  levels
@@ -17941,7 +18008,11 @@ function parseLevel(el) {
17941
18008
  function parseSettings(el) {
17942
18009
  if (!el) return {};
17943
18010
  const opts = {};
17944
- if (findChild(el, "w:evenAndOddHeaders")) opts.evenAndOddHeaderAndFooters = true;
18011
+ const eohEl = findChild(el, "w:evenAndOddHeaders");
18012
+ if (eohEl) {
18013
+ const val = attr(eohEl, "w:val");
18014
+ opts.evenAndOddHeaderAndFooters = val !== "false" && val !== "0" && val !== "off";
18015
+ }
17945
18016
  const viewEl = findChild(el, "w:view");
17946
18017
  if (viewEl) {
17947
18018
  const val = attr(viewEl, "w:val");
@@ -17993,15 +18064,6 @@ function parseSettings(el) {
17993
18064
  }
17994
18065
  if (vars.length > 0) opts.docVars = vars;
17995
18066
  }
17996
- const bgEl = findChild(el, "w:background");
17997
- if (bgEl) {
17998
- const bg = {};
17999
- const color = attr(bgEl, "w:color");
18000
- if (color) bg.color = color;
18001
- const themeColor = attr(bgEl, "w:themeColor");
18002
- if (themeColor) bg.themeColor = themeColor;
18003
- if (Object.keys(bg).length > 0) opts.background = bg;
18004
- }
18005
18067
  const cscEl = findChild(el, "w:characterSpacingControl");
18006
18068
  if (cscEl) {
18007
18069
  const val = attr(cscEl, "w:val");
@@ -18052,8 +18114,30 @@ function buildNumberingCache(docx) {
18052
18114
  }
18053
18115
  return cache;
18054
18116
  }
18117
+ /** Style IDs generated by DefaultStylesFactory — skip these during parsing. */
18118
+ const BUILTIN_STYLE_IDS = new Set([
18119
+ "Title",
18120
+ "Heading1",
18121
+ "Heading2",
18122
+ "Heading3",
18123
+ "Heading4",
18124
+ "Heading5",
18125
+ "Heading6",
18126
+ "Strong",
18127
+ "ListParagraph",
18128
+ "Hyperlink",
18129
+ "FootnoteText",
18130
+ "FootnoteTextChar",
18131
+ "EndnoteText",
18132
+ "EndnoteTextChar",
18133
+ "FootnoteReference",
18134
+ "EndnoteReference"
18135
+ ]);
18055
18136
  /**
18056
18137
  * Parse w:styles element into StylesOptions.
18138
+ *
18139
+ * Skips built-in styles that DefaultStylesFactory already generates,
18140
+ * keeping only user-defined custom styles for round-trip fidelity.
18057
18141
  */
18058
18142
  function parseStyleDefinitions(el, ctx) {
18059
18143
  const opts = {};
@@ -18065,6 +18149,8 @@ function parseStyleDefinitions(el, ctx) {
18065
18149
  } else if (child.name === "w:style") {
18066
18150
  const styleOpts = parseStyleElement(child, ctx);
18067
18151
  if (!styleOpts) continue;
18152
+ const styleId = styleOpts.id;
18153
+ if (styleId && BUILTIN_STYLE_IDS.has(styleId)) continue;
18068
18154
  const type = styleOpts._type;
18069
18155
  delete styleOpts._type;
18070
18156
  if (type === "paragraph") paragraphStyles.push(styleOpts);
@@ -18232,6 +18318,12 @@ function parseDocument(data) {
18232
18318
  const docx = parseDocx(data);
18233
18319
  const ctx = new ParseContext(docx, buildStyleCache(docx), buildNumberingCache(docx));
18234
18320
  const opts = { sections: parseBody(docx.body, ctx) };
18321
+ if (docx.background) {
18322
+ const bg = {};
18323
+ const color = attr(docx.background, "w:color");
18324
+ if (color) bg.color = color;
18325
+ if (Object.keys(bg).length > 0) opts.background = bg;
18326
+ }
18235
18327
  if (docx.coreProps) {
18236
18328
  const corePropsEl = docx.doc.get(docx.coreProps);
18237
18329
  if (corePropsEl) {
@@ -18294,6 +18386,7 @@ function parseDocx(data) {
18294
18386
  if (!documentEl) throw new Error("word/document.xml not found");
18295
18387
  const body = documentEl.elements?.find((e) => e.name === "w:body");
18296
18388
  if (!body) throw new Error("w:body not found in word/document.xml");
18389
+ const background = documentEl.elements?.find((e) => e.name === "w:background");
18297
18390
  const styles = doc.get("word/styles.xml");
18298
18391
  const numbering = doc.get("word/numbering.xml");
18299
18392
  const settings = doc.get("word/settings.xml");
@@ -18304,6 +18397,7 @@ function parseDocx(data) {
18304
18397
  return {
18305
18398
  doc,
18306
18399
  body,
18400
+ background,
18307
18401
  styles,
18308
18402
  numbering,
18309
18403
  settings,