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/bundle.js +251 -50
- package/dist/bundle.min.js +243 -243
- package/dist/cli.js +240 -50
- package/dist/packages/docs/common.d.ts +30 -2
- package/dist/packages/docs/common.d.ts.map +1 -1
- package/dist/packages/docs/common.js +40 -0
- package/dist/packages/docs/common.js.map +1 -1
- package/dist/packages/docs/convert.d.ts.map +1 -1
- package/dist/packages/docs/convert.js +91 -21
- package/dist/packages/docs/convert.js.map +1 -1
- package/dist/packages/docs/parse-css.d.ts.map +1 -1
- package/dist/packages/docs/parse-css.js +10 -3
- package/dist/packages/docs/parse-css.js.map +1 -1
- package/dist/packages/docs/parse.d.ts.map +1 -1
- package/dist/packages/docs/parse.js +185 -19
- package/dist/packages/docs/parse.js.map +1 -1
- package/package.json +1 -1
package/dist/bundle.js
CHANGED
|
@@ -47395,6 +47395,34 @@ var docgen = (() => {
|
|
|
47395
47395
|
var UTF16BE = new Uint8Array([254, 255]);
|
|
47396
47396
|
|
|
47397
47397
|
// packages/docs/common.js
|
|
47398
|
+
function isStyledTableCell(cell) {
|
|
47399
|
+
if (typeof cell !== "object" || Array.isArray(cell))
|
|
47400
|
+
return false;
|
|
47401
|
+
if (!("content" in cell))
|
|
47402
|
+
return false;
|
|
47403
|
+
const styledCell = cell;
|
|
47404
|
+
const content = styledCell.content;
|
|
47405
|
+
if (typeof content === "string")
|
|
47406
|
+
return true;
|
|
47407
|
+
if (Array.isArray(content) && content.length > 0) {
|
|
47408
|
+
const first = content[0];
|
|
47409
|
+
if (typeof first === "object" && first !== null && "type" in first) {
|
|
47410
|
+
return false;
|
|
47411
|
+
}
|
|
47412
|
+
}
|
|
47413
|
+
return true;
|
|
47414
|
+
}
|
|
47415
|
+
function isComplexTableCell(cell) {
|
|
47416
|
+
if (typeof cell !== "object" || Array.isArray(cell))
|
|
47417
|
+
return false;
|
|
47418
|
+
if (!("content" in cell))
|
|
47419
|
+
return false;
|
|
47420
|
+
const content = cell.content;
|
|
47421
|
+
if (!Array.isArray(content) || content.length === 0)
|
|
47422
|
+
return false;
|
|
47423
|
+
const first = content[0];
|
|
47424
|
+
return typeof first === "object" && first !== null && "type" in first;
|
|
47425
|
+
}
|
|
47398
47426
|
var HEADING_LEVEL_MAP = {
|
|
47399
47427
|
1: HeadingLevel.HEADING_1,
|
|
47400
47428
|
2: HeadingLevel.HEADING_2,
|
|
@@ -48705,7 +48733,7 @@ var docgen = (() => {
|
|
|
48705
48733
|
}
|
|
48706
48734
|
}
|
|
48707
48735
|
}
|
|
48708
|
-
|
|
48736
|
+
{
|
|
48709
48737
|
const fillIn = (source) => {
|
|
48710
48738
|
for (const [key2, value] of Object.entries(source)) {
|
|
48711
48739
|
if (value !== void 0 && result[key2] === void 0) {
|
|
@@ -50276,6 +50304,46 @@ var docgen = (() => {
|
|
|
50276
50304
|
}
|
|
50277
50305
|
|
|
50278
50306
|
// packages/docs/parse.js
|
|
50307
|
+
function getDirectRows(tableEl) {
|
|
50308
|
+
const result = [];
|
|
50309
|
+
for (const child of tableEl.children) {
|
|
50310
|
+
const childTag = child.tagName.toLowerCase();
|
|
50311
|
+
if (childTag === "tr") {
|
|
50312
|
+
result.push(child);
|
|
50313
|
+
} else if (childTag === "thead" || childTag === "tbody" || childTag === "tfoot") {
|
|
50314
|
+
for (const grandchild of child.children) {
|
|
50315
|
+
if (grandchild.tagName.toLowerCase() === "tr") {
|
|
50316
|
+
result.push(grandchild);
|
|
50317
|
+
}
|
|
50318
|
+
}
|
|
50319
|
+
}
|
|
50320
|
+
}
|
|
50321
|
+
return result;
|
|
50322
|
+
}
|
|
50323
|
+
function getDirectCells(rowEl) {
|
|
50324
|
+
const result = [];
|
|
50325
|
+
for (const child of rowEl.children) {
|
|
50326
|
+
const childTag = child.tagName.toLowerCase();
|
|
50327
|
+
if (childTag === "td" || childTag === "th") {
|
|
50328
|
+
result.push(child);
|
|
50329
|
+
}
|
|
50330
|
+
}
|
|
50331
|
+
return result;
|
|
50332
|
+
}
|
|
50333
|
+
function cellHasNestedTable(cellEl) {
|
|
50334
|
+
return cellEl.querySelector("table") !== null;
|
|
50335
|
+
}
|
|
50336
|
+
function isLayoutTable(tableEl, cssContext) {
|
|
50337
|
+
const styles = getElementStyles(tableEl, cssContext);
|
|
50338
|
+
const inlineStyle = tableEl.getAttribute("style") || "";
|
|
50339
|
+
if (inlineStyle.includes("border: none") || inlineStyle.includes("border:none")) {
|
|
50340
|
+
return true;
|
|
50341
|
+
}
|
|
50342
|
+
if (styles.border && styles.border.includes("none")) {
|
|
50343
|
+
return true;
|
|
50344
|
+
}
|
|
50345
|
+
return false;
|
|
50346
|
+
}
|
|
50279
50347
|
function createParsedImageElement(imageEl, imageKey) {
|
|
50280
50348
|
const src = imageEl.getAttribute("src")?.trim();
|
|
50281
50349
|
if (!src) {
|
|
@@ -50385,18 +50453,50 @@ var docgen = (() => {
|
|
|
50385
50453
|
}
|
|
50386
50454
|
if (tagName19 === "table") {
|
|
50387
50455
|
const rows = [];
|
|
50388
|
-
|
|
50456
|
+
const directRows = getDirectRows(el);
|
|
50457
|
+
for (const tr of directRows) {
|
|
50389
50458
|
const cells = [];
|
|
50390
|
-
|
|
50459
|
+
const directCells = getDirectCells(tr);
|
|
50460
|
+
for (const cell of directCells) {
|
|
50461
|
+
let cellBackgroundColor;
|
|
50462
|
+
const cellStyles = getElementStyles(cell, cssContext, tr);
|
|
50463
|
+
if (cellStyles.backgroundColor) {
|
|
50464
|
+
const hexBg = extractHexColor(cellStyles.backgroundColor);
|
|
50465
|
+
if (hexBg)
|
|
50466
|
+
cellBackgroundColor = hexBg;
|
|
50467
|
+
}
|
|
50468
|
+
if (!cellBackgroundColor) {
|
|
50469
|
+
const inlineStyle = cell.getAttribute("style") || "";
|
|
50470
|
+
if (inlineStyle) {
|
|
50471
|
+
const bgMatch = inlineStyle.match(/background(?:-color)?\s*:\s*([^;]+)/i);
|
|
50472
|
+
if (bgMatch) {
|
|
50473
|
+
const hexBg = extractHexColor(bgMatch[1]);
|
|
50474
|
+
if (hexBg)
|
|
50475
|
+
cellBackgroundColor = hexBg;
|
|
50476
|
+
}
|
|
50477
|
+
}
|
|
50478
|
+
}
|
|
50391
50479
|
const runs = extractInlineRuns(cell, cssContext);
|
|
50392
|
-
if (
|
|
50393
|
-
if (
|
|
50394
|
-
|
|
50480
|
+
if (cellBackgroundColor) {
|
|
50481
|
+
if (runs.length > 0) {
|
|
50482
|
+
if (hasInlineFormatting(runs)) {
|
|
50483
|
+
cells.push({ content: runs, backgroundColor: cellBackgroundColor });
|
|
50484
|
+
} else {
|
|
50485
|
+
cells.push({ content: runs.map((r) => r.text).join(""), backgroundColor: cellBackgroundColor });
|
|
50486
|
+
}
|
|
50395
50487
|
} else {
|
|
50396
|
-
cells.push(
|
|
50488
|
+
cells.push({ content: "", backgroundColor: cellBackgroundColor });
|
|
50397
50489
|
}
|
|
50398
50490
|
} else {
|
|
50399
|
-
|
|
50491
|
+
if (runs.length > 0) {
|
|
50492
|
+
if (hasInlineFormatting(runs)) {
|
|
50493
|
+
cells.push(runs);
|
|
50494
|
+
} else {
|
|
50495
|
+
cells.push(runs.map((r) => r.text).join(""));
|
|
50496
|
+
}
|
|
50497
|
+
} else {
|
|
50498
|
+
cells.push("");
|
|
50499
|
+
}
|
|
50400
50500
|
}
|
|
50401
50501
|
}
|
|
50402
50502
|
if (cells.length > 0) {
|
|
@@ -51159,18 +51259,65 @@ var docgen = (() => {
|
|
|
51159
51259
|
}
|
|
51160
51260
|
if (tagName19 === "table") {
|
|
51161
51261
|
const rows = [];
|
|
51162
|
-
|
|
51262
|
+
const directRows = getDirectRows(element);
|
|
51263
|
+
for (const tr of directRows) {
|
|
51163
51264
|
const cells = [];
|
|
51164
|
-
|
|
51165
|
-
|
|
51166
|
-
if (
|
|
51167
|
-
|
|
51168
|
-
|
|
51265
|
+
const directCells = getDirectCells(tr);
|
|
51266
|
+
for (const cell of directCells) {
|
|
51267
|
+
if (cellHasNestedTable(cell)) {
|
|
51268
|
+
const nestedContent = parseContainerContent(cell, cssContext, nextImageKey);
|
|
51269
|
+
if (nestedContent.length > 0) {
|
|
51270
|
+
cells.push({ content: nestedContent });
|
|
51169
51271
|
} else {
|
|
51170
|
-
cells.push(
|
|
51272
|
+
cells.push("");
|
|
51171
51273
|
}
|
|
51172
51274
|
} else {
|
|
51173
|
-
|
|
51275
|
+
let cellBackgroundColor;
|
|
51276
|
+
const cellStylesWithRowParent = getElementStyles(cell, cssContext, tr);
|
|
51277
|
+
if (cellStylesWithRowParent.backgroundColor) {
|
|
51278
|
+
const hexBg = extractHexColor(cellStylesWithRowParent.backgroundColor);
|
|
51279
|
+
if (hexBg)
|
|
51280
|
+
cellBackgroundColor = hexBg;
|
|
51281
|
+
}
|
|
51282
|
+
if (!cellBackgroundColor) {
|
|
51283
|
+
const cellStylesWithTableParent = getElementStyles(cell, cssContext, element);
|
|
51284
|
+
if (cellStylesWithTableParent.backgroundColor) {
|
|
51285
|
+
const hexBg = extractHexColor(cellStylesWithTableParent.backgroundColor);
|
|
51286
|
+
if (hexBg)
|
|
51287
|
+
cellBackgroundColor = hexBg;
|
|
51288
|
+
}
|
|
51289
|
+
}
|
|
51290
|
+
const inlineStyle = cell.getAttribute("style") || "";
|
|
51291
|
+
if (inlineStyle && !cellBackgroundColor) {
|
|
51292
|
+
const bgMatch = inlineStyle.match(/background(?:-color)?\s*:\s*([^;]+)/i);
|
|
51293
|
+
if (bgMatch) {
|
|
51294
|
+
const hexBg = extractHexColor(bgMatch[1]);
|
|
51295
|
+
if (hexBg)
|
|
51296
|
+
cellBackgroundColor = hexBg;
|
|
51297
|
+
}
|
|
51298
|
+
}
|
|
51299
|
+
const runs = extractInlineRuns(cell, cssContext);
|
|
51300
|
+
if (cellBackgroundColor) {
|
|
51301
|
+
if (runs.length > 0) {
|
|
51302
|
+
if (hasInlineFormatting(runs)) {
|
|
51303
|
+
cells.push({ content: runs, backgroundColor: cellBackgroundColor });
|
|
51304
|
+
} else {
|
|
51305
|
+
cells.push({ content: runs.map((r) => r.text).join(""), backgroundColor: cellBackgroundColor });
|
|
51306
|
+
}
|
|
51307
|
+
} else {
|
|
51308
|
+
cells.push({ content: "", backgroundColor: cellBackgroundColor });
|
|
51309
|
+
}
|
|
51310
|
+
} else {
|
|
51311
|
+
if (runs.length > 0) {
|
|
51312
|
+
if (hasInlineFormatting(runs)) {
|
|
51313
|
+
cells.push(runs);
|
|
51314
|
+
} else {
|
|
51315
|
+
cells.push(runs.map((r) => r.text).join(""));
|
|
51316
|
+
}
|
|
51317
|
+
} else {
|
|
51318
|
+
cells.push("");
|
|
51319
|
+
}
|
|
51320
|
+
}
|
|
51174
51321
|
}
|
|
51175
51322
|
}
|
|
51176
51323
|
if (cells.length > 0) {
|
|
@@ -51321,7 +51468,8 @@ var docgen = (() => {
|
|
|
51321
51468
|
}
|
|
51322
51469
|
}
|
|
51323
51470
|
}
|
|
51324
|
-
|
|
51471
|
+
const noBorders = isLayoutTable(element, cssContext);
|
|
51472
|
+
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) });
|
|
51325
51473
|
}
|
|
51326
51474
|
return;
|
|
51327
51475
|
}
|
|
@@ -52598,35 +52746,83 @@ var docgen = (() => {
|
|
|
52598
52746
|
return new TableRow({
|
|
52599
52747
|
tableHeader: isHeaderRow,
|
|
52600
52748
|
children: cells.map((cell, cellIndex) => {
|
|
52601
|
-
|
|
52602
|
-
|
|
52603
|
-
|
|
52604
|
-
|
|
52605
|
-
|
|
52606
|
-
|
|
52607
|
-
|
|
52608
|
-
|
|
52609
|
-
|
|
52610
|
-
|
|
52611
|
-
|
|
52612
|
-
|
|
52613
|
-
|
|
52614
|
-
|
|
52615
|
-
|
|
52616
|
-
|
|
52617
|
-
|
|
52618
|
-
|
|
52619
|
-
|
|
52620
|
-
|
|
52621
|
-
|
|
52622
|
-
|
|
52623
|
-
|
|
52624
|
-
|
|
52625
|
-
|
|
52626
|
-
|
|
52627
|
-
|
|
52749
|
+
let cellContent;
|
|
52750
|
+
let cellBackgroundColor;
|
|
52751
|
+
if (isComplexTableCell(cell)) {
|
|
52752
|
+
cellContent = [];
|
|
52753
|
+
for (const nestedElement of cell.content) {
|
|
52754
|
+
cellContent.push(...convertElementToDocx(nestedElement));
|
|
52755
|
+
}
|
|
52756
|
+
if (cellContent.length === 0) {
|
|
52757
|
+
cellContent = [new Paragraph({ children: [] })];
|
|
52758
|
+
}
|
|
52759
|
+
} else if (isStyledTableCell(cell)) {
|
|
52760
|
+
cellBackgroundColor = cell.backgroundColor;
|
|
52761
|
+
const content = cell.content;
|
|
52762
|
+
const textRuns = typeof content === "string" ? [new TextRun({
|
|
52763
|
+
text: content,
|
|
52764
|
+
bold: isHeaderRow,
|
|
52765
|
+
color: isHeaderRow && headerTextColor ? headerTextColor : void 0
|
|
52766
|
+
})] : content.map((run) => new TextRun({
|
|
52767
|
+
text: run.text,
|
|
52768
|
+
bold: isHeaderRow || run.bold,
|
|
52769
|
+
italics: run.italic,
|
|
52770
|
+
color: isHeaderRow && headerTextColor ? headerTextColor : run.color,
|
|
52771
|
+
size: run.size,
|
|
52772
|
+
font: run.fontFamily ? mapToOfficeFont(run.fontFamily) : void 0,
|
|
52773
|
+
superScript: run.superscript,
|
|
52774
|
+
subScript: run.subscript,
|
|
52775
|
+
strike: run.strike,
|
|
52776
|
+
characterSpacing: run.letterSpacing,
|
|
52777
|
+
underline: run.underline ? {
|
|
52778
|
+
type: getUnderlineType(run.underline.type),
|
|
52779
|
+
color: run.underline.color
|
|
52780
|
+
} : void 0
|
|
52781
|
+
// Note: Don't apply run-level backgroundColor here - cell background handles it
|
|
52782
|
+
}));
|
|
52783
|
+
cellContent = [new Paragraph({ children: textRuns })];
|
|
52784
|
+
} else if (typeof cell === "string") {
|
|
52785
|
+
const textRuns = [new TextRun({
|
|
52786
|
+
text: cell,
|
|
52787
|
+
bold: isHeaderRow,
|
|
52788
|
+
color: isHeaderRow && headerTextColor ? headerTextColor : void 0
|
|
52789
|
+
})];
|
|
52790
|
+
cellContent = [new Paragraph({ children: textRuns })];
|
|
52791
|
+
} else if (Array.isArray(cell)) {
|
|
52792
|
+
const textRuns = cell.map((run) => new TextRun({
|
|
52793
|
+
text: run.text,
|
|
52794
|
+
bold: isHeaderRow || run.bold,
|
|
52795
|
+
italics: run.italic,
|
|
52796
|
+
color: isHeaderRow && headerTextColor ? headerTextColor : run.color,
|
|
52797
|
+
size: run.size,
|
|
52798
|
+
font: run.fontFamily ? mapToOfficeFont(run.fontFamily) : void 0,
|
|
52799
|
+
superScript: run.superscript,
|
|
52800
|
+
subScript: run.subscript,
|
|
52801
|
+
strike: run.strike,
|
|
52802
|
+
characterSpacing: run.letterSpacing,
|
|
52803
|
+
underline: run.underline ? {
|
|
52804
|
+
type: getUnderlineType(run.underline.type),
|
|
52805
|
+
color: run.underline.color
|
|
52806
|
+
} : void 0,
|
|
52807
|
+
// Preserve inline background colors for badge/pill styling in table cells
|
|
52808
|
+
shading: run.backgroundColor ? {
|
|
52809
|
+
type: ShadingType.CLEAR,
|
|
52810
|
+
fill: run.backgroundColor,
|
|
52811
|
+
color: "auto"
|
|
52812
|
+
} : void 0
|
|
52813
|
+
}));
|
|
52814
|
+
cellContent = [new Paragraph({ children: textRuns })];
|
|
52815
|
+
} else {
|
|
52816
|
+
cellContent = [new Paragraph({ children: [] })];
|
|
52817
|
+
}
|
|
52628
52818
|
let shading;
|
|
52629
|
-
if (
|
|
52819
|
+
if (cellBackgroundColor) {
|
|
52820
|
+
shading = {
|
|
52821
|
+
type: ShadingType.CLEAR,
|
|
52822
|
+
color: "auto",
|
|
52823
|
+
fill: cellBackgroundColor
|
|
52824
|
+
};
|
|
52825
|
+
} else if (isHeaderRow && headerBackgroundColor) {
|
|
52630
52826
|
shading = {
|
|
52631
52827
|
type: ShadingType.CLEAR,
|
|
52632
52828
|
color: "auto",
|
|
@@ -52644,11 +52840,7 @@ var docgen = (() => {
|
|
|
52644
52840
|
const needsSpan = isLastCell && remainingColumns > 0;
|
|
52645
52841
|
const cellColumnSpan = needsSpan ? remainingColumns + 1 : void 0;
|
|
52646
52842
|
return new TableCell({
|
|
52647
|
-
children:
|
|
52648
|
-
new Paragraph({
|
|
52649
|
-
children: textRuns
|
|
52650
|
-
})
|
|
52651
|
-
],
|
|
52843
|
+
children: cellContent,
|
|
52652
52844
|
width: {
|
|
52653
52845
|
size: columnWidths?.[cellIndex] ?? 100 / columnCount,
|
|
52654
52846
|
type: WidthType.PERCENTAGE
|
|
@@ -52968,6 +53160,15 @@ var docgen = (() => {
|
|
|
52968
53160
|
const cell = row[cellIndex];
|
|
52969
53161
|
if (typeof cell === "string") {
|
|
52970
53162
|
children.push(new TextRun({ text: cell }));
|
|
53163
|
+
} else if (isStyledTableCell(cell)) {
|
|
53164
|
+
const content = cell.content;
|
|
53165
|
+
if (typeof content === "string") {
|
|
53166
|
+
children.push(new TextRun({ text: content }));
|
|
53167
|
+
} else {
|
|
53168
|
+
children.push(...inlineRunsToTextRuns(content));
|
|
53169
|
+
}
|
|
53170
|
+
} else if (isComplexTableCell(cell)) {
|
|
53171
|
+
continue;
|
|
52971
53172
|
} else {
|
|
52972
53173
|
children.push(...inlineRunsToTextRuns(cell));
|
|
52973
53174
|
}
|