docgen-utils 1.0.21 → 1.0.22

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/cli.js CHANGED
@@ -68822,6 +68822,28 @@ var UTF16LE = new Uint8Array([255, 254]);
68822
68822
  var UTF16BE = new Uint8Array([254, 255]);
68823
68823
 
68824
68824
  // packages/docs/common.ts
68825
+ function isStyledTableCell(cell) {
68826
+ if (typeof cell !== "object" || Array.isArray(cell)) return false;
68827
+ if (!("content" in cell)) return false;
68828
+ const styledCell = cell;
68829
+ const content = styledCell.content;
68830
+ if (typeof content === "string") return true;
68831
+ if (Array.isArray(content) && content.length > 0) {
68832
+ const first = content[0];
68833
+ if (typeof first === "object" && first !== null && "type" in first) {
68834
+ return false;
68835
+ }
68836
+ }
68837
+ return true;
68838
+ }
68839
+ function isComplexTableCell(cell) {
68840
+ if (typeof cell !== "object" || Array.isArray(cell)) return false;
68841
+ if (!("content" in cell)) return false;
68842
+ const content = cell.content;
68843
+ if (!Array.isArray(content) || content.length === 0) return false;
68844
+ const first = content[0];
68845
+ return typeof first === "object" && first !== null && "type" in first;
68846
+ }
68825
68847
  var HEADING_LEVEL_MAP = {
68826
68848
  1: HeadingLevel.HEADING_1,
68827
68849
  2: HeadingLevel.HEADING_2,
@@ -70094,7 +70116,7 @@ function getElementStyles(element, cssContext, parentElement2) {
70094
70116
  }
70095
70117
  }
70096
70118
  }
70097
- if (!parentElement2) {
70119
+ {
70098
70120
  const fillIn = (source) => {
70099
70121
  for (const [key2, value] of Object.entries(source)) {
70100
70122
  if (value !== void 0 && result[key2] === void 0) {
@@ -71614,6 +71636,46 @@ function detectTimeline(element, cssContext) {
71614
71636
  }
71615
71637
 
71616
71638
  // packages/docs/parse.ts
71639
+ function getDirectRows(tableEl) {
71640
+ const result = [];
71641
+ for (const child of tableEl.children) {
71642
+ const childTag = child.tagName.toLowerCase();
71643
+ if (childTag === "tr") {
71644
+ result.push(child);
71645
+ } else if (childTag === "thead" || childTag === "tbody" || childTag === "tfoot") {
71646
+ for (const grandchild of child.children) {
71647
+ if (grandchild.tagName.toLowerCase() === "tr") {
71648
+ result.push(grandchild);
71649
+ }
71650
+ }
71651
+ }
71652
+ }
71653
+ return result;
71654
+ }
71655
+ function getDirectCells(rowEl) {
71656
+ const result = [];
71657
+ for (const child of rowEl.children) {
71658
+ const childTag = child.tagName.toLowerCase();
71659
+ if (childTag === "td" || childTag === "th") {
71660
+ result.push(child);
71661
+ }
71662
+ }
71663
+ return result;
71664
+ }
71665
+ function cellHasNestedTable(cellEl) {
71666
+ return cellEl.querySelector("table") !== null;
71667
+ }
71668
+ function isLayoutTable(tableEl, cssContext) {
71669
+ const styles = getElementStyles(tableEl, cssContext);
71670
+ const inlineStyle = tableEl.getAttribute("style") || "";
71671
+ if (inlineStyle.includes("border: none") || inlineStyle.includes("border:none")) {
71672
+ return true;
71673
+ }
71674
+ if (styles.border && styles.border.includes("none")) {
71675
+ return true;
71676
+ }
71677
+ return false;
71678
+ }
71617
71679
  function createParsedImageElement(imageEl, imageKey) {
71618
71680
  const src = imageEl.getAttribute("src")?.trim();
71619
71681
  if (!src) {
@@ -71723,18 +71785,48 @@ function parseContainerContent(element, cssContext, nextImageKey, inheritedColor
71723
71785
  }
71724
71786
  if (tagName19 === "table") {
71725
71787
  const rows = [];
71726
- for (const tr of el.querySelectorAll("tr")) {
71788
+ const directRows = getDirectRows(el);
71789
+ for (const tr of directRows) {
71727
71790
  const cells = [];
71728
- for (const cell of tr.querySelectorAll("td, th")) {
71791
+ const directCells = getDirectCells(tr);
71792
+ for (const cell of directCells) {
71793
+ let cellBackgroundColor;
71794
+ const cellStyles = getElementStyles(cell, cssContext, tr);
71795
+ if (cellStyles.backgroundColor) {
71796
+ const hexBg = extractHexColor(cellStyles.backgroundColor);
71797
+ if (hexBg) cellBackgroundColor = hexBg;
71798
+ }
71799
+ if (!cellBackgroundColor) {
71800
+ const inlineStyle = cell.getAttribute("style") || "";
71801
+ if (inlineStyle) {
71802
+ const bgMatch = inlineStyle.match(/background(?:-color)?\s*:\s*([^;]+)/i);
71803
+ if (bgMatch) {
71804
+ const hexBg = extractHexColor(bgMatch[1]);
71805
+ if (hexBg) cellBackgroundColor = hexBg;
71806
+ }
71807
+ }
71808
+ }
71729
71809
  const runs = extractInlineRuns(cell, cssContext);
71730
- if (runs.length > 0) {
71731
- if (hasInlineFormatting(runs)) {
71732
- cells.push(runs);
71810
+ if (cellBackgroundColor) {
71811
+ if (runs.length > 0) {
71812
+ if (hasInlineFormatting(runs)) {
71813
+ cells.push({ content: runs, backgroundColor: cellBackgroundColor });
71814
+ } else {
71815
+ cells.push({ content: runs.map((r) => r.text).join(""), backgroundColor: cellBackgroundColor });
71816
+ }
71733
71817
  } else {
71734
- cells.push(runs.map((r) => r.text).join(""));
71818
+ cells.push({ content: "", backgroundColor: cellBackgroundColor });
71735
71819
  }
71736
71820
  } else {
71737
- cells.push("");
71821
+ if (runs.length > 0) {
71822
+ if (hasInlineFormatting(runs)) {
71823
+ cells.push(runs);
71824
+ } else {
71825
+ cells.push(runs.map((r) => r.text).join(""));
71826
+ }
71827
+ } else {
71828
+ cells.push("");
71829
+ }
71738
71830
  }
71739
71831
  }
71740
71832
  if (cells.length > 0) {
@@ -72490,18 +72582,62 @@ function parseHtmlContent(html) {
72490
72582
  }
72491
72583
  if (tagName19 === "table") {
72492
72584
  const rows = [];
72493
- for (const tr of element.querySelectorAll("tr")) {
72585
+ const directRows = getDirectRows(element);
72586
+ for (const tr of directRows) {
72494
72587
  const cells = [];
72495
- for (const cell of tr.querySelectorAll("td, th")) {
72496
- const runs = extractInlineRuns(cell, cssContext);
72497
- if (runs.length > 0) {
72498
- if (hasInlineFormatting(runs)) {
72499
- cells.push(runs);
72588
+ const directCells = getDirectCells(tr);
72589
+ for (const cell of directCells) {
72590
+ if (cellHasNestedTable(cell)) {
72591
+ const nestedContent = parseContainerContent(cell, cssContext, nextImageKey);
72592
+ if (nestedContent.length > 0) {
72593
+ cells.push({ content: nestedContent });
72500
72594
  } else {
72501
- cells.push(runs.map((r) => r.text).join(""));
72595
+ cells.push("");
72502
72596
  }
72503
72597
  } else {
72504
- cells.push("");
72598
+ let cellBackgroundColor;
72599
+ const cellStylesWithRowParent = getElementStyles(cell, cssContext, tr);
72600
+ if (cellStylesWithRowParent.backgroundColor) {
72601
+ const hexBg = extractHexColor(cellStylesWithRowParent.backgroundColor);
72602
+ if (hexBg) cellBackgroundColor = hexBg;
72603
+ }
72604
+ if (!cellBackgroundColor) {
72605
+ const cellStylesWithTableParent = getElementStyles(cell, cssContext, element);
72606
+ if (cellStylesWithTableParent.backgroundColor) {
72607
+ const hexBg = extractHexColor(cellStylesWithTableParent.backgroundColor);
72608
+ if (hexBg) cellBackgroundColor = hexBg;
72609
+ }
72610
+ }
72611
+ const inlineStyle = cell.getAttribute("style") || "";
72612
+ if (inlineStyle && !cellBackgroundColor) {
72613
+ const bgMatch = inlineStyle.match(/background(?:-color)?\s*:\s*([^;]+)/i);
72614
+ if (bgMatch) {
72615
+ const hexBg = extractHexColor(bgMatch[1]);
72616
+ if (hexBg) cellBackgroundColor = hexBg;
72617
+ }
72618
+ }
72619
+ const runs = extractInlineRuns(cell, cssContext);
72620
+ if (cellBackgroundColor) {
72621
+ if (runs.length > 0) {
72622
+ if (hasInlineFormatting(runs)) {
72623
+ cells.push({ content: runs, backgroundColor: cellBackgroundColor });
72624
+ } else {
72625
+ cells.push({ content: runs.map((r) => r.text).join(""), backgroundColor: cellBackgroundColor });
72626
+ }
72627
+ } else {
72628
+ cells.push({ content: "", backgroundColor: cellBackgroundColor });
72629
+ }
72630
+ } else {
72631
+ if (runs.length > 0) {
72632
+ if (hasInlineFormatting(runs)) {
72633
+ cells.push(runs);
72634
+ } else {
72635
+ cells.push(runs.map((r) => r.text).join(""));
72636
+ }
72637
+ } else {
72638
+ cells.push("");
72639
+ }
72640
+ }
72505
72641
  }
72506
72642
  }
72507
72643
  if (cells.length > 0) {
@@ -72637,7 +72773,8 @@ function parseHtmlContent(html) {
72637
72773
  }
72638
72774
  }
72639
72775
  }
72640
- elements.push({ type: "table", rows, cellPadding, headerBackgroundColor, headerTextColor, evenRowBackgroundColor, hasHeader: hasExplicitHeader ? true : void 0, horizontalBordersOnly: horizontalBordersOnly || void 0, columnWidths: calculateColumnWidths(rows, element) });
72776
+ const noBorders = isLayoutTable(element, cssContext);
72777
+ elements.push({ type: "table", rows, cellPadding, headerBackgroundColor, headerTextColor, evenRowBackgroundColor, hasHeader: hasExplicitHeader ? true : void 0, horizontalBordersOnly: horizontalBordersOnly || void 0, noBorders: noBorders || void 0, columnWidths: calculateColumnWidths(rows, element) });
72641
72778
  }
72642
72779
  return;
72643
72780
  }
@@ -73719,35 +73856,83 @@ function createTableRow(cells, isHeaderRow, columnCount, cellPadding, headerBack
73719
73856
  tableHeader: isHeaderRow,
73720
73857
  children: cells.map(
73721
73858
  (cell, cellIndex) => {
73722
- const textRuns = typeof cell === "string" ? [new TextRun({
73723
- text: cell,
73724
- bold: isHeaderRow,
73725
- color: isHeaderRow && headerTextColor ? headerTextColor : void 0
73726
- })] : cell.map((run) => new TextRun({
73727
- text: run.text,
73728
- bold: isHeaderRow || run.bold,
73729
- italics: run.italic,
73730
- // Use header text color for header rows, otherwise use run's color
73731
- color: isHeaderRow && headerTextColor ? headerTextColor : run.color,
73732
- size: run.size,
73733
- font: run.fontFamily ? mapToOfficeFont(run.fontFamily) : void 0,
73734
- superScript: run.superscript,
73735
- subScript: run.subscript,
73736
- strike: run.strike,
73737
- characterSpacing: run.letterSpacing,
73738
- underline: run.underline ? {
73739
- type: getUnderlineType(run.underline.type),
73740
- color: run.underline.color
73741
- } : void 0,
73742
- // Preserve inline background colors for badge/pill styling in table cells
73743
- shading: run.backgroundColor ? {
73744
- type: ShadingType.CLEAR,
73745
- fill: run.backgroundColor,
73746
- color: "auto"
73747
- } : void 0
73748
- }));
73859
+ let cellContent;
73860
+ let cellBackgroundColor;
73861
+ if (isComplexTableCell(cell)) {
73862
+ cellContent = [];
73863
+ for (const nestedElement of cell.content) {
73864
+ cellContent.push(...convertElementToDocx(nestedElement));
73865
+ }
73866
+ if (cellContent.length === 0) {
73867
+ cellContent = [new Paragraph({ children: [] })];
73868
+ }
73869
+ } else if (isStyledTableCell(cell)) {
73870
+ cellBackgroundColor = cell.backgroundColor;
73871
+ const content = cell.content;
73872
+ const textRuns = typeof content === "string" ? [new TextRun({
73873
+ text: content,
73874
+ bold: isHeaderRow,
73875
+ color: isHeaderRow && headerTextColor ? headerTextColor : void 0
73876
+ })] : content.map((run) => new TextRun({
73877
+ text: run.text,
73878
+ bold: isHeaderRow || run.bold,
73879
+ italics: run.italic,
73880
+ color: isHeaderRow && headerTextColor ? headerTextColor : run.color,
73881
+ size: run.size,
73882
+ font: run.fontFamily ? mapToOfficeFont(run.fontFamily) : void 0,
73883
+ superScript: run.superscript,
73884
+ subScript: run.subscript,
73885
+ strike: run.strike,
73886
+ characterSpacing: run.letterSpacing,
73887
+ underline: run.underline ? {
73888
+ type: getUnderlineType(run.underline.type),
73889
+ color: run.underline.color
73890
+ } : void 0
73891
+ // Note: Don't apply run-level backgroundColor here - cell background handles it
73892
+ }));
73893
+ cellContent = [new Paragraph({ children: textRuns })];
73894
+ } else if (typeof cell === "string") {
73895
+ const textRuns = [new TextRun({
73896
+ text: cell,
73897
+ bold: isHeaderRow,
73898
+ color: isHeaderRow && headerTextColor ? headerTextColor : void 0
73899
+ })];
73900
+ cellContent = [new Paragraph({ children: textRuns })];
73901
+ } else if (Array.isArray(cell)) {
73902
+ const textRuns = cell.map((run) => new TextRun({
73903
+ text: run.text,
73904
+ bold: isHeaderRow || run.bold,
73905
+ italics: run.italic,
73906
+ color: isHeaderRow && headerTextColor ? headerTextColor : run.color,
73907
+ size: run.size,
73908
+ font: run.fontFamily ? mapToOfficeFont(run.fontFamily) : void 0,
73909
+ superScript: run.superscript,
73910
+ subScript: run.subscript,
73911
+ strike: run.strike,
73912
+ characterSpacing: run.letterSpacing,
73913
+ underline: run.underline ? {
73914
+ type: getUnderlineType(run.underline.type),
73915
+ color: run.underline.color
73916
+ } : void 0,
73917
+ // Preserve inline background colors for badge/pill styling in table cells
73918
+ shading: run.backgroundColor ? {
73919
+ type: ShadingType.CLEAR,
73920
+ fill: run.backgroundColor,
73921
+ color: "auto"
73922
+ } : void 0
73923
+ }));
73924
+ cellContent = [new Paragraph({ children: textRuns })];
73925
+ } else {
73926
+ cellContent = [new Paragraph({ children: [] })];
73927
+ }
73749
73928
  let shading;
73750
- if (isHeaderRow && headerBackgroundColor) {
73929
+ if (cellBackgroundColor) {
73930
+ shading = {
73931
+ type: ShadingType.CLEAR,
73932
+ color: "auto",
73933
+ fill: cellBackgroundColor
73934
+ };
73935
+ } else if (isHeaderRow && headerBackgroundColor) {
73751
73936
  shading = {
73752
73937
  type: ShadingType.CLEAR,
73753
73938
  color: "auto",
@@ -73765,11 +73950,7 @@ function createTableRow(cells, isHeaderRow, columnCount, cellPadding, headerBack
73765
73950
  const needsSpan = isLastCell && remainingColumns > 0;
73766
73951
  const cellColumnSpan = needsSpan ? remainingColumns + 1 : void 0;
73767
73952
  return new TableCell({
73768
- children: [
73769
- new Paragraph({
73770
- children: textRuns
73771
- })
73772
- ],
73953
+ children: cellContent,
73773
73954
  width: {
73774
73955
  size: columnWidths?.[cellIndex] ?? 100 / columnCount,
73775
73956
  type: WidthType.PERCENTAGE
@@ -74098,6 +74279,15 @@ function convertElementToDocx(element) {
74098
74279
  const cell = row[cellIndex];
74099
74280
  if (typeof cell === "string") {
74100
74281
  children.push(new TextRun({ text: cell }));
74282
+ } else if (isStyledTableCell(cell)) {
74283
+ const content = cell.content;
74284
+ if (typeof content === "string") {
74285
+ children.push(new TextRun({ text: content }));
74286
+ } else {
74287
+ children.push(...inlineRunsToTextRuns(content));
74288
+ }
74289
+ } else if (isComplexTableCell(cell)) {
74290
+ continue;
74101
74291
  } else {
74102
74292
  children.push(...inlineRunsToTextRuns(cell));
74103
74293
  }
@@ -42,9 +42,36 @@ export interface InlineRun {
42
42
  }
43
43
  export type TextAlignment = "left" | "center" | "right" | "justify";
44
44
  /**
45
- * Represents a table cell that can have plain text or formatted runs.
45
+ * Represents a table cell with cell-level styling (background color).
46
+ * This applies shading to the entire cell via w:tcPr, not just the text.
46
47
  */
47
- export type TableCell = string | InlineRun[];
48
+ export interface StyledTableCell {
49
+ content: string | InlineRun[];
50
+ backgroundColor?: string;
51
+ }
52
+ /**
53
+ * Represents a table cell with complex nested content (paragraphs, tables).
54
+ * Used for layout tables where cells contain multiple block-level elements.
55
+ */
56
+ export interface ComplexTableCell {
57
+ content: ParsedElement[];
58
+ }
59
+ /**
60
+ * Represents a table cell that can have:
61
+ * - Plain text (string)
62
+ * - Formatted inline runs (InlineRun[])
63
+ * - Styled cell with background (StyledTableCell)
64
+ * - Complex nested content (ComplexTableCell)
65
+ */
66
+ export type TableCell = string | InlineRun[] | StyledTableCell | ComplexTableCell;
67
+ /**
68
+ * Type guard to check if a TableCell is a StyledTableCell with cell-level background.
69
+ */
70
+ export declare function isStyledTableCell(cell: TableCell): cell is StyledTableCell;
71
+ /**
72
+ * Type guard to check if a TableCell is a ComplexTableCell with nested ParsedElement content.
73
+ */
74
+ export declare function isComplexTableCell(cell: TableCell): cell is ComplexTableCell;
48
75
  /**
49
76
  * Represents chart image data for embedding in DOCX.
50
77
  */
@@ -86,6 +113,7 @@ export type ParsedElement = {
86
113
  bold?: boolean;
87
114
  italic?: boolean;
88
115
  color?: string;
116
+ backgroundColor?: string;
89
117
  runs?: InlineRun[];
90
118
  alignment?: TextAlignment;
91
119
  firstLineIndent?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../packages/docs/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEnD;;;GAGG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;A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AC,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,eAAe,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,GACvM;IAAE,IAAI,EAAE,mBAAmB,CAAC;IAAC,OAAO,EAAE;QAAE,OAAO,EAAE,aAAa,EAAE,CAAC;QAAC,eAAe,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAAC,IAAI,EAAE;QAAE,OAAO,EAAE,aAAa,EAAE,CAAA;KAAE,CAAA;CAAE,GAC7K;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,cAAc,CAAA;CAAE,CAAC;AAEnJ,KAAK,gBAAgB,GAAG,SAAS,CAAC,OAAO,YAAY,CAAC,CAAC;AACvD,MAAM,MAAM,kBAAkB,GAAG,SAAS,CAAC,OAAO,aAAa,CAAC,CAAC;AAEjE,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,iBAAiB,EAAE,gBAAgB,CAOzE,CAAC;AAEF,eAAO,MAAM,cAAc,UAgB1B,CAAC"}
@@ -1,4 +1,44 @@
1
1
  import { HeadingLevel } from "docx";
2
+ /**
3
+ * Type guard to check if a TableCell is a StyledTableCell with cell-level background.
4
+ */
5
+ export function isStyledTableCell(cell) {
6
+ if (typeof cell !== "object" || Array.isArray(cell))
7
+ return false;
8
+ if (!("content" in cell))
9
+ return false;
10
+ // StyledTableCell has content: string | InlineRun[]
11
+ // ComplexTableCell has content: ParsedElement[]
12
+ // Check if it's NOT a ComplexTableCell (which has type property on first element)
13
+ const styledCell = cell;
14
+ const content = styledCell.content;
15
+ // If content is a string, it's StyledTableCell
16
+ if (typeof content === "string")
17
+ return true;
18
+ // If content is an array but first element has 'type', it's ComplexTableCell
19
+ if (Array.isArray(content) && content.length > 0) {
20
+ const first = content[0];
21
+ if (typeof first === "object" && first !== null && "type" in first) {
22
+ return false; // This is ComplexTableCell
23
+ }
24
+ }
25
+ return true; // StyledTableCell with InlineRun[] or empty array
26
+ }
27
+ /**
28
+ * Type guard to check if a TableCell is a ComplexTableCell with nested ParsedElement content.
29
+ */
30
+ export function isComplexTableCell(cell) {
31
+ if (typeof cell !== "object" || Array.isArray(cell))
32
+ return false;
33
+ if (!("content" in cell))
34
+ return false;
35
+ const content = cell.content;
36
+ // ComplexTableCell has content: ParsedElement[] where elements have 'type' property
37
+ if (!Array.isArray(content) || content.length === 0)
38
+ return false;
39
+ const first = content[0];
40
+ return typeof first === "object" && first !== null && "type" in first;
41
+ }
2
42
  export const HEADING_LEVEL_MAP = {
3
43
  1: HeadingLevel.HEADING_1,
4
44
  2: HeadingLevel.HEADING_2,
@@ -1 +1 @@
1
- {"version":3,"file":"common.js","sourceRoot":"","sources":["../../../packages/docs/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,YAAY,EAAE,MAAM,MAAM,CAAC;AA4FnD,MAAM,CAAC,MAAM,iBAAiB,GAAgD;IAC5E,CAAC,EAAE,YAAY,CAAC,SAAS;IACzB,CAAC,EAAE,YAAY,CAAC,SAAS;IACzB,CAAC,EAAE,YAAY,CAAC,SAAS;IACzB,CAAC,EAAE,YAAY,CAAC,SAAS;IACzB,CAAC,EAAE,YAAY,CAAC,SAAS;IACzB,CAAC,EAAE,YAAY,CAAC,SAAS;CAC1B,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,KAAK;IACL,MAAM;IACN,SAAS;IACT,SAAS;IACT,MAAM;IACN,QAAQ;IACR,QAAQ;IACR,OAAO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a,GAAG,CAAC,SAAS,GAAG,KAAK,CAAC,EAAE,CA41BlF"}
1
+ {"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../../packages/docs/convert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsD,SAAS,EAAe,KAAK,EAA8G,MAAM,MAAM,CAAC;AACrN,OAAO,EAA0C,aAAa,EAAqG,MAAM,UAAU,CAAC;AA6yBpL;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,aAAa,GAAG,CAAC,SAAS,GAAG,KAAK,CAAC,EAAE,CAu2BlF"}
@@ -1,5 +1,5 @@
1
1
  import { AlignmentType, BorderStyle, ImageRun, LineRuleType, Paragraph, ShadingType, Table, TableCell as DocxTableCell, TableRow, TextRun, UnderlineType, WidthType, convertInchesToTwip, XmlComponent } from "docx";
2
- import { HEADING_LEVEL_MAP } from "./common";
2
+ import { HEADING_LEVEL_MAP, isStyledTableCell, isComplexTableCell } from "./common";
3
3
  import { mapToOfficeFont } from "../shared/fonts";
4
4
  // Line spacing: HTML line-height 1.7
5
5
  // Word LineRuleType.AUTO uses "240ths of a line" - so 240 = single spacing, 360 = 1.5, 480 = double
@@ -531,24 +531,73 @@ function inlineRunsToTextRuns(runs, textTransform) {
531
531
  }
532
532
  /**
533
533
  * Create a table row from cells.
534
+ * Handles:
535
+ * - Plain text cells (string)
536
+ * - Formatted inline runs (InlineRun[])
537
+ * - Styled cells with cell-level backgrounds (StyledTableCell)
538
+ * - Complex cells with nested content like tables (ComplexTableCell)
534
539
  */
535
540
  function createTableRow(cells, isHeaderRow, columnCount, cellPadding, headerBackgroundColor, headerTextColor, columnWidths, rowBackgroundColor) {
536
541
  return new TableRow({
537
542
  tableHeader: isHeaderRow,
538
543
  children: cells.map((cell, cellIndex) => {
539
- // Build text runs with formatting preserved
540
- // Apply header text color if specified, otherwise use run's color or default
541
- const textRuns = typeof cell === "string"
542
- ? [new TextRun({
544
+ // Determine cell content and cell-level background color
545
+ let cellContent;
546
+ let cellBackgroundColor;
547
+ if (isComplexTableCell(cell)) {
548
+ // Complex cell with nested ParsedElement content (like nested tables)
549
+ cellContent = [];
550
+ for (const nestedElement of cell.content) {
551
+ cellContent.push(...convertElementToDocx(nestedElement));
552
+ }
553
+ if (cellContent.length === 0) {
554
+ cellContent = [new Paragraph({ children: [] })];
555
+ }
556
+ }
557
+ else if (isStyledTableCell(cell)) {
558
+ // Styled cell with cell-level background color
559
+ cellBackgroundColor = cell.backgroundColor;
560
+ const content = cell.content;
561
+ const textRuns = typeof content === "string"
562
+ ? [new TextRun({
563
+ text: content,
564
+ bold: isHeaderRow,
565
+ color: isHeaderRow && headerTextColor ? headerTextColor : undefined,
566
+ })]
567
+ : content.map(run => new TextRun({
568
+ text: run.text,
569
+ bold: isHeaderRow || run.bold,
570
+ italics: run.italic,
571
+ color: isHeaderRow && headerTextColor ? headerTextColor : run.color,
572
+ size: run.size,
573
+ font: run.fontFamily ? mapToOfficeFont(run.fontFamily) : undefined,
574
+ superScript: run.superscript,
575
+ subScript: run.subscript,
576
+ strike: run.strike,
577
+ characterSpacing: run.letterSpacing,
578
+ underline: run.underline ? {
579
+ type: getUnderlineType(run.underline.type),
580
+ color: run.underline.color,
581
+ } : undefined,
582
+ // Note: Don't apply run-level backgroundColor here - cell background handles it
583
+ }));
584
+ cellContent = [new Paragraph({ children: textRuns })];
585
+ }
586
+ else if (typeof cell === "string") {
587
+ // Plain text cell
588
+ const textRuns = [new TextRun({
543
589
  text: cell,
544
590
  bold: isHeaderRow,
545
591
  color: isHeaderRow && headerTextColor ? headerTextColor : undefined,
546
- })]
547
- : cell.map(run => new TextRun({
592
+ })];
593
+ cellContent = [new Paragraph({ children: textRuns })];
594
+ }
595
+ else if (Array.isArray(cell)) {
596
+ // InlineRun[] cell
597
+ const textRuns = cell.map(run => new TextRun({
548
598
  text: run.text,
549
599
  bold: isHeaderRow || run.bold,
550
600
  italics: run.italic,
551
- // Use header text color for header rows, otherwise use run's color
552
601
  color: isHeaderRow && headerTextColor ? headerTextColor : run.color,
553
602
  size: run.size,
554
603
  font: run.fontFamily ? mapToOfficeFont(run.fontFamily) : undefined,
@@ -567,9 +616,26 @@ function createTableRow(cells, isHeaderRow, columnCount, cellPadding, headerBack
567
616
  color: "auto",
568
617
  } : undefined,
569
618
  }));
570
- // Determine cell shading: header row uses headerBackgroundColor, even rows use rowBackgroundColor
619
+ cellContent = [new Paragraph({ children: textRuns })];
620
+ }
621
+ else {
622
+ // Unknown cell type - create empty paragraph
623
+ cellContent = [new Paragraph({ children: [] })];
624
+ }
625
+ // Determine cell shading (w:tcPr level):
626
+ // 1. Cell-specific background from StyledTableCell takes priority
627
+ // 2. Header row uses headerBackgroundColor
628
+ // 3. Even rows use rowBackgroundColor
571
629
  let shading;
572
- if (isHeaderRow && headerBackgroundColor) {
630
+ if (cellBackgroundColor) {
631
+ // Cell-level background from StyledTableCell
632
+ shading = {
633
+ type: ShadingType.CLEAR,
634
+ color: "auto",
635
+ fill: cellBackgroundColor,
636
+ };
637
+ }
638
+ else if (isHeaderRow && headerBackgroundColor) {
573
639
  shading = {
574
640
  type: ShadingType.CLEAR,
575
641
  color: "auto",
@@ -583,24 +649,14 @@ function createTableRow(cells, isHeaderRow, columnCount, cellPadding, headerBack
583
649
  fill: rowBackgroundColor,
584
650
  };
585
651
  }
586
- // Note: No default header shading is applied when the CSS doesn't specify one.
587
- // Previously, a light gray F9FAFB was applied to all header rows, but this added
588
- // unwanted shading to tables in clean/minimal designs.
589
652
  // When this row has fewer cells than the table's column count,
590
653
  // the last cell must span the remaining grid columns via columnSpan.
591
- // Without this, the OOXML is structurally invalid (cells don't cover
592
- // all gridCol entries) and strict parsers like Azure Document
593
- // Intelligence will reject the document.
594
654
  const isLastCell = cellIndex === cells.length - 1;
595
655
  const remainingColumns = columnCount - cells.length;
596
656
  const needsSpan = isLastCell && remainingColumns > 0;
597
657
  const cellColumnSpan = needsSpan ? remainingColumns + 1 : undefined;
598
658
  return new DocxTableCell({
599
- children: [
600
- new Paragraph({
601
- children: textRuns,
602
- }),
603
- ],
659
+ children: cellContent,
604
660
  width: {
605
661
  size: columnWidths?.[cellIndex] ?? 100 / columnCount,
606
662
  type: WidthType.PERCENTAGE,
@@ -1005,6 +1061,20 @@ export function convertElementToDocx(element) {
1005
1061
  if (typeof cell === "string") {
1006
1062
  children.push(new TextRun({ text: cell }));
1007
1063
  }
1064
+ else if (isStyledTableCell(cell)) {
1065
+ // StyledTableCell - extract content
1066
+ const content = cell.content;
1067
+ if (typeof content === "string") {
1068
+ children.push(new TextRun({ text: content }));
1069
+ }
1070
+ else {
1071
+ children.push(...inlineRunsToTextRuns(content));
1072
+ }
1073
+ }
1074
+ else if (isComplexTableCell(cell)) {
1075
+ // ComplexTableCell - skip for horizontal flex (too complex)
1076
+ continue;
1077
+ }
1008
1078
  else {
1009
1079
  // InlineRun array
1010
1080
  children.push(...inlineRunsToTextRuns(cell));