node-pptx-templater 1.1.3 → 1.1.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/package.json +2 -1
- package/src/core/PPTXTemplater.js +89 -10
- package/src/managers/ShapeManager.js +288 -85
- package/src/managers/TableManager.js +643 -133
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-pptx-templater",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"description": "High-performance, low-level PowerPoint (PPTX) OpenXML template engine for Node.js. Dynamically replace text, insert images, update charts (with Excel workbook data caching), and merge table cells without PowerPoint corruption or Repair Mode prompts.",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"example:table-extraction": "node examples/table-extraction.js",
|
|
38
38
|
"example:nested-rows": "node examples/nested-table-rows.js",
|
|
39
39
|
"example:xml-folder": "node examples/xml-folder-workflow.js",
|
|
40
|
+
"example:shape-cells": "node examples/shape-cells.js",
|
|
40
41
|
"example:all": "node scripts/run-examples-check.js",
|
|
41
42
|
"prepublishOnly": "npm run lint && npm run test"
|
|
42
43
|
},
|
|
@@ -1569,11 +1569,30 @@ class PPTXTemplater {
|
|
|
1569
1569
|
}
|
|
1570
1570
|
|
|
1571
1571
|
/**
|
|
1572
|
-
* Appends one or more rows to a table. Supports flat arrays
|
|
1573
|
-
* for rowspan-merged cells
|
|
1572
|
+
* Appends one or more rows to a table. Supports flat arrays, nested arrays
|
|
1573
|
+
* for rowspan-merged cells, and **Shape Cell** configuration objects that insert
|
|
1574
|
+
* a graphic indicator directly inside a cell.
|
|
1575
|
+
*
|
|
1576
|
+
* ### Shape Cell Object
|
|
1577
|
+
* Instead of a string value you may pass an object with the following keys:
|
|
1578
|
+
*
|
|
1579
|
+
* | Key | Type | Default | Description |
|
|
1580
|
+
* |-----|------|---------|-------------|
|
|
1581
|
+
* | `type` | `string` | **required** | Shape preset: `'circle'`, `'square'`, `'rectangle'`, `'triangle'`, `'diamond'`, `'hexagon'`, `'line'`. |
|
|
1582
|
+
* | `text` | `string` | `''` | Optional label rendered next to the shape. |
|
|
1583
|
+
* | `color` | `string` | `'#4CAF50'` | Fill colour of the shape (hex). |
|
|
1584
|
+
* | `width` | `number` | `14` | Shape width in points. |
|
|
1585
|
+
* | `height` | `number` | `14` | Shape height in points. |
|
|
1586
|
+
* | `position` | `string` | `'center'` | Alignment inside the cell: `'center'`, `'left'`, `'right'`, `'top'`, `'bottom'`, `'top-left'`, `'top-right'`, `'bottom-left'`, `'bottom-right'`. |
|
|
1587
|
+
* | `offsetX` | `number` | `0` | Additional horizontal offset from the resolved anchor (pt). |
|
|
1588
|
+
* | `offsetY` | `number` | `0` | Additional vertical offset from the resolved anchor (pt). |
|
|
1589
|
+
*
|
|
1590
|
+
* The shape is added as a floating overlay anchored to the cell; the table
|
|
1591
|
+
* dimensions (row heights, column widths) are **never mutated**.
|
|
1574
1592
|
*
|
|
1575
1593
|
* @param {string} tableId - Table name or shape ID.
|
|
1576
|
-
* @param {Array<string|Array<string
|
|
1594
|
+
* @param {Array<string|Array<string>|Object>} rowData - Row data. Each element may be
|
|
1595
|
+
* a plain string, a nested array (rowspan), or a Shape Cell configuration object.
|
|
1577
1596
|
* @param {Object} [options] - Row insertion options.
|
|
1578
1597
|
* @param {'rowspan'|'auto'|'none'} [options.mergeStrategy='rowspan'] - How to handle nested arrays.
|
|
1579
1598
|
* `'rowspan'` creates OpenXML vertical spans, `'auto'` merges identical adjacent values,
|
|
@@ -1586,12 +1605,33 @@ class PPTXTemplater {
|
|
|
1586
1605
|
*
|
|
1587
1606
|
* // Nested row with rowspan
|
|
1588
1607
|
* ppt.addTableRow('SalesTable', ['Region', ['Q1', 'Q2'], '$5K'], { mergeStrategy: 'rowspan' });
|
|
1608
|
+
*
|
|
1609
|
+
* // KPI indicator – green circle placed in the cell centre, no label
|
|
1610
|
+
* await ppt.addTableRow('StatusTable', [
|
|
1611
|
+
* 'Alice',
|
|
1612
|
+
* 'Engineering',
|
|
1613
|
+
* { type: 'circle', color: '#4CAF50', width: 12, height: 12, position: 'center' },
|
|
1614
|
+
* ]);
|
|
1615
|
+
*
|
|
1616
|
+
* // Status badge – shape with accompanying text label, aligned to the left
|
|
1617
|
+
* await ppt.addTableRow('StatusTable', [
|
|
1618
|
+
* 'Bob',
|
|
1619
|
+
* 'Design',
|
|
1620
|
+
* { type: 'circle', color: '#F44336', text: 'Blocked', position: 'left' },
|
|
1621
|
+
* ]);
|
|
1589
1622
|
*/
|
|
1590
1623
|
addTableRow(tableId, rowData, options = {}) {
|
|
1591
1624
|
this.#assertLoaded()
|
|
1592
1625
|
const targetIndices = this.#getTargetSlideIndices()
|
|
1593
1626
|
for (const idx of targetIndices) {
|
|
1594
|
-
this.#tableManager.addTableRow(
|
|
1627
|
+
this.#tableManager.addTableRow(
|
|
1628
|
+
idx,
|
|
1629
|
+
tableId,
|
|
1630
|
+
rowData,
|
|
1631
|
+
this.#slideManager,
|
|
1632
|
+
this.#shapeManager,
|
|
1633
|
+
options
|
|
1634
|
+
)
|
|
1595
1635
|
}
|
|
1596
1636
|
return this
|
|
1597
1637
|
}
|
|
@@ -1610,7 +1650,13 @@ class PPTXTemplater {
|
|
|
1610
1650
|
this.#assertLoaded()
|
|
1611
1651
|
const targetIndices = this.#getTargetSlideIndices()
|
|
1612
1652
|
for (const idx of targetIndices) {
|
|
1613
|
-
this.#tableManager.removeTableRow(
|
|
1653
|
+
this.#tableManager.removeTableRow(
|
|
1654
|
+
idx,
|
|
1655
|
+
tableId,
|
|
1656
|
+
rowIndex,
|
|
1657
|
+
this.#slideManager,
|
|
1658
|
+
this.#shapeManager
|
|
1659
|
+
)
|
|
1614
1660
|
}
|
|
1615
1661
|
return this
|
|
1616
1662
|
}
|
|
@@ -1630,7 +1676,14 @@ class PPTXTemplater {
|
|
|
1630
1676
|
this.#assertLoaded()
|
|
1631
1677
|
const targetIndices = this.#getTargetSlideIndices()
|
|
1632
1678
|
for (const idx of targetIndices) {
|
|
1633
|
-
this.#tableManager.insertTableRow(
|
|
1679
|
+
this.#tableManager.insertTableRow(
|
|
1680
|
+
idx,
|
|
1681
|
+
tableId,
|
|
1682
|
+
rowIndex,
|
|
1683
|
+
rowData,
|
|
1684
|
+
this.#slideManager,
|
|
1685
|
+
this.#shapeManager
|
|
1686
|
+
)
|
|
1634
1687
|
}
|
|
1635
1688
|
return this
|
|
1636
1689
|
}
|
|
@@ -1655,7 +1708,8 @@ class PPTXTemplater {
|
|
|
1655
1708
|
tableId,
|
|
1656
1709
|
sourceRowIndex,
|
|
1657
1710
|
targetRowIndex,
|
|
1658
|
-
this.#slideManager
|
|
1711
|
+
this.#slideManager,
|
|
1712
|
+
this.#shapeManager
|
|
1659
1713
|
)
|
|
1660
1714
|
}
|
|
1661
1715
|
return this
|
|
@@ -1735,7 +1789,16 @@ class PPTXTemplater {
|
|
|
1735
1789
|
}
|
|
1736
1790
|
|
|
1737
1791
|
for (const idx of targetIndices) {
|
|
1738
|
-
this.#tableManager.mergeCells(
|
|
1792
|
+
this.#tableManager.mergeCells(
|
|
1793
|
+
idx,
|
|
1794
|
+
tableId,
|
|
1795
|
+
sRow,
|
|
1796
|
+
sCol,
|
|
1797
|
+
eRow,
|
|
1798
|
+
eCol,
|
|
1799
|
+
this.#slideManager,
|
|
1800
|
+
this.#shapeManager
|
|
1801
|
+
)
|
|
1739
1802
|
}
|
|
1740
1803
|
return this
|
|
1741
1804
|
}
|
|
@@ -1786,9 +1849,25 @@ class PPTXTemplater {
|
|
|
1786
1849
|
|
|
1787
1850
|
for (const idx of targetIndices) {
|
|
1788
1851
|
if (isCellCoord) {
|
|
1789
|
-
this.#tableManager.unmergeCells(
|
|
1852
|
+
this.#tableManager.unmergeCells(
|
|
1853
|
+
idx,
|
|
1854
|
+
tableId,
|
|
1855
|
+
cellRow,
|
|
1856
|
+
cellCol,
|
|
1857
|
+
this.#slideManager,
|
|
1858
|
+
this.#shapeManager
|
|
1859
|
+
)
|
|
1790
1860
|
} else {
|
|
1791
|
-
this.#tableManager.unmergeCells(
|
|
1861
|
+
this.#tableManager.unmergeCells(
|
|
1862
|
+
idx,
|
|
1863
|
+
tableId,
|
|
1864
|
+
sRow,
|
|
1865
|
+
sCol,
|
|
1866
|
+
eRow,
|
|
1867
|
+
eCol,
|
|
1868
|
+
this.#slideManager,
|
|
1869
|
+
this.#shapeManager
|
|
1870
|
+
)
|
|
1792
1871
|
}
|
|
1793
1872
|
}
|
|
1794
1873
|
return this
|