pptx-viewer-mcp 1.1.26 → 1.2.0

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.js CHANGED
@@ -1588,41 +1588,1009 @@ async function convertToMarkdown(ctx, params) {
1588
1588
  }
1589
1589
  };
1590
1590
  }
1591
+ function getThemeInfo(ctx) {
1592
+ const theme = ctx.pptxData.theme;
1593
+ return {
1594
+ pptxData: ctx.pptxData,
1595
+ dirty: false,
1596
+ result: {
1597
+ themeName: theme?.name,
1598
+ colorScheme: theme?.colorScheme,
1599
+ fontScheme: theme?.fontScheme,
1600
+ availablePresets: Object.keys(pptxViewerCore.ThemePresets)
1601
+ }
1602
+ };
1603
+ }
1604
+ function applyThemePreset(ctx, params) {
1605
+ const preset = pptxViewerCore.getThemePreset(params.presetName);
1606
+ if (!preset) {
1607
+ throw new Error(
1608
+ `Unknown theme preset: "${params.presetName}". Available: ${Object.keys(pptxViewerCore.ThemePresets).join(", ")}`
1609
+ );
1610
+ }
1611
+ if (!ctx.pptxData.theme) {
1612
+ ctx.pptxData.theme = {};
1613
+ }
1614
+ const theme = ctx.pptxData.theme;
1615
+ theme.name = preset.name;
1616
+ theme.colorScheme = preset.colors;
1617
+ if (preset.fonts) {
1618
+ theme.fontScheme = preset.fonts;
1619
+ }
1620
+ return {
1621
+ pptxData: ctx.pptxData,
1622
+ dirty: true,
1623
+ result: {
1624
+ appliedPreset: params.presetName,
1625
+ colorScheme: theme.colorScheme
1626
+ }
1627
+ };
1628
+ }
1629
+ function updateThemeColors(ctx, params) {
1630
+ if (!ctx.pptxData.theme) {
1631
+ ctx.pptxData.theme = {};
1632
+ }
1633
+ const theme = ctx.pptxData.theme;
1634
+ if (!theme.colorScheme) {
1635
+ theme.colorScheme = {
1636
+ dk1: "#000000",
1637
+ lt1: "#FFFFFF",
1638
+ dk2: "#44546A",
1639
+ lt2: "#E7E6E6",
1640
+ accent1: "#4472C4",
1641
+ accent2: "#ED7D31",
1642
+ accent3: "#A5A5A5",
1643
+ accent4: "#FFC000",
1644
+ accent5: "#5B9BD5",
1645
+ accent6: "#70AD47",
1646
+ hlink: "#0563C1",
1647
+ folHlink: "#954F72"
1648
+ };
1649
+ }
1650
+ const cs = theme.colorScheme;
1651
+ for (const key of Object.keys(params)) {
1652
+ if (params[key] !== void 0) {
1653
+ cs[key] = params[key];
1654
+ }
1655
+ }
1656
+ return {
1657
+ pptxData: ctx.pptxData,
1658
+ dirty: true,
1659
+ result: { colorScheme: cs }
1660
+ };
1661
+ }
1662
+ function updateThemeFonts(ctx, params) {
1663
+ if (!ctx.pptxData.theme) {
1664
+ ctx.pptxData.theme = {};
1665
+ }
1666
+ const theme = ctx.pptxData.theme;
1667
+ if (!theme.fontScheme) {
1668
+ theme.fontScheme = {};
1669
+ }
1670
+ if (params.majorFont !== void 0) {
1671
+ theme.fontScheme.majorFont = { latin: params.majorFont };
1672
+ }
1673
+ if (params.minorFont !== void 0) {
1674
+ theme.fontScheme.minorFont = { latin: params.minorFont };
1675
+ }
1676
+ return {
1677
+ pptxData: ctx.pptxData,
1678
+ dirty: true,
1679
+ result: { fontScheme: theme.fontScheme }
1680
+ };
1681
+ }
1682
+ function updateChart(ctx, params) {
1683
+ const err = validateSlideIndex(params.slideIndex, ctx.pptxData.slides.length);
1684
+ if (err) {
1685
+ throw new Error(err);
1686
+ }
1687
+ const slide = ctx.pptxData.slides[params.slideIndex];
1688
+ const el = slide.elements.find((e) => e.id === params.elementId);
1689
+ if (!el) {
1690
+ throw new Error(`Element '${params.elementId}' not found on slide ${params.slideIndex}.`);
1691
+ }
1692
+ if (el.type !== "chart") {
1693
+ throw new Error(`Element '${params.elementId}' is not a chart.`);
1694
+ }
1695
+ const chart = el;
1696
+ if (params.chartType) {
1697
+ pptxViewerCore.setChartType(chart, params.chartType);
1698
+ }
1699
+ if (params.title !== void 0) {
1700
+ pptxViewerCore.setChartTitle(chart, params.title);
1701
+ }
1702
+ if (params.grouping) {
1703
+ pptxViewerCore.setChartGrouping(chart, params.grouping);
1704
+ }
1705
+ if (params.legend) {
1706
+ pptxViewerCore.setChartLegend(chart, {
1707
+ show: params.legend.show,
1708
+ position: params.legend.position
1709
+ });
1710
+ }
1711
+ if (params.dataLabels) {
1712
+ pptxViewerCore.setChartDataLabels(chart, params.dataLabels);
1713
+ }
1714
+ if (params.axis) {
1715
+ pptxViewerCore.setChartAxis(chart, params.axis.type, params.axis.edit);
1716
+ }
1717
+ if (params.categories) {
1718
+ pptxViewerCore.setChartCategories(chart, params.categories);
1719
+ }
1720
+ return { pptxData: ctx.pptxData, dirty: true, result: { elementId: params.elementId } };
1721
+ }
1722
+ function addChartSeriesT(ctx, params) {
1723
+ const err = validateSlideIndex(params.slideIndex, ctx.pptxData.slides.length);
1724
+ if (err) {
1725
+ throw new Error(err);
1726
+ }
1727
+ const slide = ctx.pptxData.slides[params.slideIndex];
1728
+ const el = slide.elements.find((e) => e.id === params.elementId);
1729
+ if (!el) {
1730
+ throw new Error(`Element '${params.elementId}' not found on slide ${params.slideIndex}.`);
1731
+ }
1732
+ if (el.type !== "chart") {
1733
+ throw new Error(`Element '${params.elementId}' is not a chart.`);
1734
+ }
1735
+ const chart = el;
1736
+ pptxViewerCore.addChartSeries(chart, { name: params.name, values: params.values, color: params.color });
1737
+ const seriesCount = chart.chartData?.series?.length ?? 0;
1738
+ return {
1739
+ pptxData: ctx.pptxData,
1740
+ dirty: true,
1741
+ result: { elementId: params.elementId, seriesCount }
1742
+ };
1743
+ }
1744
+ function removeChartSeriesT(ctx, params) {
1745
+ const err = validateSlideIndex(params.slideIndex, ctx.pptxData.slides.length);
1746
+ if (err) {
1747
+ throw new Error(err);
1748
+ }
1749
+ const slide = ctx.pptxData.slides[params.slideIndex];
1750
+ const el = slide.elements.find((e) => e.id === params.elementId);
1751
+ if (!el) {
1752
+ throw new Error(`Element '${params.elementId}' not found on slide ${params.slideIndex}.`);
1753
+ }
1754
+ if (el.type !== "chart") {
1755
+ throw new Error(`Element '${params.elementId}' is not a chart.`);
1756
+ }
1757
+ const chart = el;
1758
+ pptxViewerCore.removeChartSeries(chart, params.seriesIndex);
1759
+ const seriesCount = chart.chartData?.series?.length ?? 0;
1760
+ return {
1761
+ pptxData: ctx.pptxData,
1762
+ dirty: true,
1763
+ result: { elementId: params.elementId, seriesCount }
1764
+ };
1765
+ }
1766
+ function updateChartSeriesData(ctx, params) {
1767
+ const err = validateSlideIndex(params.slideIndex, ctx.pptxData.slides.length);
1768
+ if (err) {
1769
+ throw new Error(err);
1770
+ }
1771
+ const slide = ctx.pptxData.slides[params.slideIndex];
1772
+ const el = slide.elements.find((e) => e.id === params.elementId);
1773
+ if (!el) {
1774
+ throw new Error(`Element '${params.elementId}' not found on slide ${params.slideIndex}.`);
1775
+ }
1776
+ if (el.type !== "chart") {
1777
+ throw new Error(`Element '${params.elementId}' is not a chart.`);
1778
+ }
1779
+ const chart = el;
1780
+ pptxViewerCore.updateChartSeriesValues(chart, params.seriesIndex, params.values);
1781
+ return { pptxData: ctx.pptxData, dirty: true, result: { elementId: params.elementId } };
1782
+ }
1783
+ function createChart(ctx, params) {
1784
+ const err = validateSlideIndex(params.slideIndex, ctx.pptxData.slides.length);
1785
+ if (err) {
1786
+ throw new Error(err);
1787
+ }
1788
+ const builder = pptxViewerCore.ChartBuilder.create(
1789
+ params.chartType
1790
+ );
1791
+ builder.position(params.x ?? 100, params.y ?? 100);
1792
+ builder.size(params.width ?? 500, params.height ?? 350);
1793
+ if (params.title) {
1794
+ builder.title(params.title);
1795
+ }
1796
+ if (params.categories) {
1797
+ builder.categories(params.categories);
1798
+ }
1799
+ if (params.series) {
1800
+ for (const s of params.series) {
1801
+ builder.addSeries(s.name, s.values, s.color);
1802
+ }
1803
+ }
1804
+ if (params.legend) {
1805
+ builder.legend(
1806
+ params.legend.show,
1807
+ params.legend.position
1808
+ );
1809
+ }
1810
+ const chart = builder.build();
1811
+ const slide = ctx.pptxData.slides[params.slideIndex];
1812
+ slide.elements.push(chart);
1813
+ return {
1814
+ pptxData: ctx.pptxData,
1815
+ dirty: true,
1816
+ result: { elementId: chart.id, slideIndex: params.slideIndex }
1817
+ };
1818
+ }
1819
+ function extractNodes(data) {
1820
+ if (!data.nodes) {
1821
+ return [];
1822
+ }
1823
+ return data.nodes.map((n) => ({
1824
+ id: n.id,
1825
+ text: n.text ?? "",
1826
+ children: n.children?.map((c) => ({ id: c.id, text: c.text ?? "" }))
1827
+ }));
1828
+ }
1829
+ function manageSmartArt(ctx, params) {
1830
+ const err = validateSlideIndex(params.slideIndex, ctx.pptxData.slides.length);
1831
+ if (err) {
1832
+ throw new Error(err);
1833
+ }
1834
+ const slide = ctx.pptxData.slides[params.slideIndex];
1835
+ const el = slide.elements.find((e) => e.id === params.elementId);
1836
+ if (!el) {
1837
+ throw new Error(`Element '${params.elementId}' not found on slide ${params.slideIndex}.`);
1838
+ }
1839
+ if (el.type !== "smartArt") {
1840
+ throw new Error(`Element '${params.elementId}' is not a SmartArt.`);
1841
+ }
1842
+ const smartArt = el;
1843
+ if (!smartArt.smartArtData) {
1844
+ throw new Error(`SmartArt '${params.elementId}' has no data.`);
1845
+ }
1846
+ switch (params.action) {
1847
+ case "getNodes": {
1848
+ return {
1849
+ pptxData: ctx.pptxData,
1850
+ dirty: false,
1851
+ result: {
1852
+ action: "getNodes",
1853
+ elementId: params.elementId,
1854
+ nodes: extractNodes(smartArt.smartArtData)
1855
+ }
1856
+ };
1857
+ }
1858
+ case "addNode": {
1859
+ smartArt.smartArtData = pptxViewerCore.addSmartArtNode(
1860
+ smartArt.smartArtData,
1861
+ params.text ?? "",
1862
+ params.afterNodeId
1863
+ );
1864
+ return {
1865
+ pptxData: ctx.pptxData,
1866
+ dirty: true,
1867
+ result: {
1868
+ action: "addNode",
1869
+ elementId: params.elementId,
1870
+ nodes: extractNodes(smartArt.smartArtData)
1871
+ }
1872
+ };
1873
+ }
1874
+ case "removeNode": {
1875
+ if (!params.nodeId) {
1876
+ throw new Error("nodeId is required for removeNode.");
1877
+ }
1878
+ smartArt.smartArtData = pptxViewerCore.removeSmartArtNode(smartArt.smartArtData, params.nodeId);
1879
+ return {
1880
+ pptxData: ctx.pptxData,
1881
+ dirty: true,
1882
+ result: {
1883
+ action: "removeNode",
1884
+ elementId: params.elementId,
1885
+ nodes: extractNodes(smartArt.smartArtData)
1886
+ }
1887
+ };
1888
+ }
1889
+ case "updateNodeText": {
1890
+ if (!params.nodeId) {
1891
+ throw new Error("nodeId is required for updateNodeText.");
1892
+ }
1893
+ smartArt.smartArtData = pptxViewerCore.updateSmartArtNodeText(
1894
+ smartArt.smartArtData,
1895
+ params.nodeId,
1896
+ params.text ?? ""
1897
+ );
1898
+ return {
1899
+ pptxData: ctx.pptxData,
1900
+ dirty: true,
1901
+ result: { action: "updateNodeText", elementId: params.elementId }
1902
+ };
1903
+ }
1904
+ case "reorderNode": {
1905
+ if (!params.nodeId) {
1906
+ throw new Error("nodeId is required for reorderNode.");
1907
+ }
1908
+ const dir = params.direction ?? 1;
1909
+ smartArt.smartArtData = pptxViewerCore.reorderSmartArtNode(smartArt.smartArtData, params.nodeId, dir);
1910
+ return {
1911
+ pptxData: ctx.pptxData,
1912
+ dirty: true,
1913
+ result: {
1914
+ action: "reorderNode",
1915
+ elementId: params.elementId,
1916
+ nodes: extractNodes(smartArt.smartArtData)
1917
+ }
1918
+ };
1919
+ }
1920
+ case "promoteNode": {
1921
+ if (!params.nodeId) {
1922
+ throw new Error("nodeId is required for promoteNode.");
1923
+ }
1924
+ smartArt.smartArtData = pptxViewerCore.promoteSmartArtNode(smartArt.smartArtData, params.nodeId);
1925
+ return {
1926
+ pptxData: ctx.pptxData,
1927
+ dirty: true,
1928
+ result: {
1929
+ action: "promoteNode",
1930
+ elementId: params.elementId,
1931
+ nodes: extractNodes(smartArt.smartArtData)
1932
+ }
1933
+ };
1934
+ }
1935
+ case "demoteNode": {
1936
+ if (!params.nodeId) {
1937
+ throw new Error("nodeId is required for demoteNode.");
1938
+ }
1939
+ smartArt.smartArtData = pptxViewerCore.demoteSmartArtNode(smartArt.smartArtData, params.nodeId);
1940
+ return {
1941
+ pptxData: ctx.pptxData,
1942
+ dirty: true,
1943
+ result: {
1944
+ action: "demoteNode",
1945
+ elementId: params.elementId,
1946
+ nodes: extractNodes(smartArt.smartArtData)
1947
+ }
1948
+ };
1949
+ }
1950
+ case "decompose": {
1951
+ const bounds = {
1952
+ x: smartArt.x,
1953
+ y: smartArt.y,
1954
+ width: smartArt.width,
1955
+ height: smartArt.height
1956
+ };
1957
+ const decomposed = pptxViewerCore.decomposeSmartArt(smartArt.smartArtData, bounds);
1958
+ if (!decomposed || decomposed.length === 0) {
1959
+ throw new Error("Failed to decompose SmartArt into shapes.");
1960
+ }
1961
+ const idx = slide.elements.indexOf(el);
1962
+ slide.elements.splice(idx, 1, ...decomposed);
1963
+ return {
1964
+ pptxData: ctx.pptxData,
1965
+ dirty: true,
1966
+ result: {
1967
+ action: "decompose",
1968
+ elementId: params.elementId,
1969
+ decomposedCount: decomposed.length
1970
+ }
1971
+ };
1972
+ }
1973
+ default:
1974
+ throw new Error(`Unknown SmartArt action: ${String(params.action)}`);
1975
+ }
1976
+ }
1977
+ function mergePresentationT(ctx, params) {
1978
+ const options = {};
1979
+ if (params.slideIndices) {
1980
+ options.slideIndices = params.slideIndices;
1981
+ }
1982
+ if (params.insertAt !== void 0) {
1983
+ options.insertAt = params.insertAt;
1984
+ }
1985
+ if (params.keepSourceTheme !== void 0) {
1986
+ options.keepSourceTheme = params.keepSourceTheme;
1987
+ }
1988
+ const added = pptxViewerCore.mergePresentation(ctx.pptxData, params.sourceData, options);
1989
+ return {
1990
+ pptxData: ctx.pptxData,
1991
+ dirty: added > 0,
1992
+ result: { slidesAdded: added, totalSlides: ctx.pptxData.slides.length }
1993
+ };
1994
+ }
1995
+ function diffPresentationsT(ctx, params) {
1996
+ const diff = pptxViewerCore.diffPresentations(ctx.pptxData, params.otherData);
1997
+ return {
1998
+ pptxData: ctx.pptxData,
1999
+ dirty: false,
2000
+ result: diff
2001
+ };
2002
+ }
2003
+ function findPlaceholdersT(ctx) {
2004
+ const placeholders = pptxViewerCore.findPlaceholders(ctx.pptxData);
2005
+ return {
2006
+ pptxData: ctx.pptxData,
2007
+ dirty: false,
2008
+ result: { placeholders, count: placeholders.length }
2009
+ };
2010
+ }
2011
+ function applyTemplateT(ctx, params) {
2012
+ pptxViewerCore.applyTemplate(ctx.pptxData, params.data);
2013
+ return {
2014
+ pptxData: ctx.pptxData,
2015
+ dirty: true,
2016
+ result: { applied: true, slideCount: ctx.pptxData.slides.length }
2017
+ };
2018
+ }
2019
+
2020
+ // src/tools/metadata-tools.ts
2021
+ function getMetadata(ctx) {
2022
+ return {
2023
+ pptxData: ctx.pptxData,
2024
+ dirty: false,
2025
+ result: {
2026
+ coreProperties: ctx.pptxData.coreProperties,
2027
+ appProperties: ctx.pptxData.appProperties,
2028
+ customProperties: ctx.pptxData.customProperties,
2029
+ slideCount: ctx.pptxData.slides.length
2030
+ }
2031
+ };
2032
+ }
2033
+ function updateMetadata(ctx, params) {
2034
+ const updated = [];
2035
+ if (params.title !== void 0 || params.subject !== void 0 || params.creator !== void 0 || params.keywords !== void 0 || params.description !== void 0 || params.lastModifiedBy !== void 0 || params.category !== void 0) {
2036
+ if (!ctx.pptxData.coreProperties) {
2037
+ ctx.pptxData.coreProperties = {};
2038
+ }
2039
+ const cp = ctx.pptxData.coreProperties;
2040
+ if (params.title !== void 0) {
2041
+ cp.title = params.title;
2042
+ updated.push("title");
2043
+ }
2044
+ if (params.subject !== void 0) {
2045
+ cp.subject = params.subject;
2046
+ updated.push("subject");
2047
+ }
2048
+ if (params.creator !== void 0) {
2049
+ cp.creator = params.creator;
2050
+ updated.push("creator");
2051
+ }
2052
+ if (params.keywords !== void 0) {
2053
+ cp.keywords = params.keywords;
2054
+ updated.push("keywords");
2055
+ }
2056
+ if (params.description !== void 0) {
2057
+ cp.description = params.description;
2058
+ updated.push("description");
2059
+ }
2060
+ if (params.lastModifiedBy !== void 0) {
2061
+ cp.lastModifiedBy = params.lastModifiedBy;
2062
+ updated.push("lastModifiedBy");
2063
+ }
2064
+ if (params.category !== void 0) {
2065
+ cp.category = params.category;
2066
+ updated.push("category");
2067
+ }
2068
+ }
2069
+ if (params.company !== void 0 || params.manager !== void 0) {
2070
+ if (!ctx.pptxData.appProperties) {
2071
+ ctx.pptxData.appProperties = {};
2072
+ }
2073
+ const ap = ctx.pptxData.appProperties;
2074
+ if (params.company !== void 0) {
2075
+ ap.company = params.company;
2076
+ updated.push("company");
2077
+ }
2078
+ if (params.manager !== void 0) {
2079
+ ap.manager = params.manager;
2080
+ updated.push("manager");
2081
+ }
2082
+ }
2083
+ if (params.customProperties) {
2084
+ if (!ctx.pptxData.customProperties) {
2085
+ ctx.pptxData.customProperties = [];
2086
+ }
2087
+ for (const cp of params.customProperties) {
2088
+ const valueStr = String(cp.value);
2089
+ const vtType = typeof cp.value === "number" ? "i4" : typeof cp.value === "boolean" ? "bool" : "lpwstr";
2090
+ const existing = ctx.pptxData.customProperties.find((p) => p.name === cp.name);
2091
+ if (existing) {
2092
+ existing.value = valueStr;
2093
+ existing.type = vtType;
2094
+ } else {
2095
+ ctx.pptxData.customProperties.push({ name: cp.name, value: valueStr, type: vtType });
2096
+ }
2097
+ updated.push(`custom:${cp.name}`);
2098
+ }
2099
+ }
2100
+ return {
2101
+ pptxData: ctx.pptxData,
2102
+ dirty: updated.length > 0,
2103
+ result: { updated }
2104
+ };
2105
+ }
2106
+ function manageSections(ctx, params) {
2107
+ switch (params.action) {
2108
+ case "list": {
2109
+ const sections = (ctx.pptxData.sections ?? []).map((s) => ({
2110
+ id: s.id,
2111
+ name: s.name,
2112
+ slideIds: s.slideIds,
2113
+ collapsed: s.collapsed,
2114
+ color: s.color
2115
+ }));
2116
+ return { pptxData: ctx.pptxData, dirty: false, result: { action: "list", sections } };
2117
+ }
2118
+ case "add": {
2119
+ if (!params.name) {
2120
+ throw new Error("name is required for add action.");
2121
+ }
2122
+ const section = pptxViewerCore.addSection(ctx.pptxData, params.name, params.slideIndices ?? []);
2123
+ return {
2124
+ pptxData: ctx.pptxData,
2125
+ dirty: true,
2126
+ result: {
2127
+ action: "add",
2128
+ section: { id: section.id, name: section.name, slideIds: section.slideIds }
2129
+ }
2130
+ };
2131
+ }
2132
+ case "remove": {
2133
+ if (!params.sectionId) {
2134
+ throw new Error("sectionId is required for remove action.");
2135
+ }
2136
+ const success = pptxViewerCore.removeSection(ctx.pptxData, params.sectionId);
2137
+ return { pptxData: ctx.pptxData, dirty: success, result: { action: "remove", success } };
2138
+ }
2139
+ case "reorder": {
2140
+ if (!params.sectionIds) {
2141
+ throw new Error("sectionIds is required for reorder action.");
2142
+ }
2143
+ pptxViewerCore.reorderSections(ctx.pptxData, params.sectionIds);
2144
+ return { pptxData: ctx.pptxData, dirty: true, result: { action: "reorder", success: true } };
2145
+ }
2146
+ case "moveSlides": {
2147
+ if (!params.sectionId) {
2148
+ throw new Error("sectionId is required for moveSlides action.");
2149
+ }
2150
+ if (!params.slideIndices) {
2151
+ throw new Error("slideIndices is required for moveSlides action.");
2152
+ }
2153
+ const success = pptxViewerCore.moveSlidesToSection(ctx.pptxData, params.slideIndices, params.sectionId);
2154
+ return { pptxData: ctx.pptxData, dirty: success, result: { action: "moveSlides", success } };
2155
+ }
2156
+ case "getForSlide": {
2157
+ if (params.slideIndex === void 0) {
2158
+ throw new Error("slideIndex is required for getForSlide action.");
2159
+ }
2160
+ const section = pptxViewerCore.getSectionForSlide(ctx.pptxData, params.slideIndex);
2161
+ const info = section ? { id: section.id, name: section.name, slideIds: section.slideIds } : null;
2162
+ return {
2163
+ pptxData: ctx.pptxData,
2164
+ dirty: false,
2165
+ result: { action: "getForSlide", section: info }
2166
+ };
2167
+ }
2168
+ default:
2169
+ throw new Error(`Unknown section action: ${String(params.action)}`);
2170
+ }
2171
+ }
2172
+ function exportToSvg(ctx, params) {
2173
+ if (params.slideIndices) {
2174
+ for (const si of params.slideIndices) {
2175
+ const err = validateSlideIndex(si, ctx.pptxData.slides.length);
2176
+ if (err) {
2177
+ throw new Error(err);
2178
+ }
2179
+ }
2180
+ }
2181
+ const options = {};
2182
+ if (params.slideIndices) {
2183
+ options.slideIndices = params.slideIndices;
2184
+ }
2185
+ if (params.includeHidden !== void 0) {
2186
+ options.includeHidden = params.includeHidden;
2187
+ }
2188
+ if (params.defaultFontFamily) {
2189
+ options.defaultFontFamily = params.defaultFontFamily;
2190
+ }
2191
+ if (params.defaultFontSize) {
2192
+ options.defaultFontSize = params.defaultFontSize;
2193
+ }
2194
+ const svgStrings = pptxViewerCore.SvgExporter.exportAll(ctx.pptxData, options);
2195
+ return {
2196
+ pptxData: ctx.pptxData,
2197
+ dirty: false,
2198
+ result: { svgStrings, slideCount: svgStrings.length }
2199
+ };
2200
+ }
2201
+ function exportSlideSvg(ctx, params) {
2202
+ const err = validateSlideIndex(params.slideIndex, ctx.pptxData.slides.length);
2203
+ if (err) {
2204
+ throw new Error(err);
2205
+ }
2206
+ const slide = ctx.pptxData.slides[params.slideIndex];
2207
+ const width = ctx.pptxData.width ?? 960;
2208
+ const height = ctx.pptxData.height ?? 540;
2209
+ const options = {};
2210
+ if (params.defaultFontFamily) {
2211
+ options.defaultFontFamily = params.defaultFontFamily;
2212
+ }
2213
+ if (params.defaultFontSize) {
2214
+ options.defaultFontSize = params.defaultFontSize;
2215
+ }
2216
+ const svg = pptxViewerCore.SvgExporter.exportSlide(slide, width, height, options);
2217
+ return {
2218
+ pptxData: ctx.pptxData,
2219
+ dirty: false,
2220
+ result: { svg, slideIndex: params.slideIndex }
2221
+ };
2222
+ }
2223
+
2224
+ // src/tools/hyperlink-tools.ts
2225
+ function manageHyperlinks(ctx, params) {
2226
+ const err = validateSlideIndex(params.slideIndex, ctx.pptxData.slides.length);
2227
+ if (err) {
2228
+ throw new Error(err);
2229
+ }
2230
+ const slide = ctx.pptxData.slides[params.slideIndex];
2231
+ switch (params.action) {
2232
+ case "list": {
2233
+ const hyperlinks = [];
2234
+ for (const el of slide.elements) {
2235
+ if (el.actionClick) {
2236
+ hyperlinks.push({
2237
+ elementId: el.id,
2238
+ trigger: "click",
2239
+ url: el.actionClick.url,
2240
+ tooltip: el.actionClick.tooltip,
2241
+ targetSlideIndex: el.actionClick.targetSlideIndex,
2242
+ actionType: el.actionClick.action
2243
+ });
2244
+ }
2245
+ if (el.actionHover) {
2246
+ hyperlinks.push({
2247
+ elementId: el.id,
2248
+ trigger: "hover",
2249
+ url: el.actionHover.url,
2250
+ tooltip: el.actionHover.tooltip,
2251
+ targetSlideIndex: el.actionHover.targetSlideIndex,
2252
+ actionType: el.actionHover.action
2253
+ });
2254
+ }
2255
+ }
2256
+ return { pptxData: ctx.pptxData, dirty: false, result: { action: "list", hyperlinks } };
2257
+ }
2258
+ case "set": {
2259
+ if (!params.elementId) {
2260
+ throw new Error("elementId is required for set action.");
2261
+ }
2262
+ const el = slide.elements.find((e) => e.id === params.elementId);
2263
+ if (!el) {
2264
+ throw new Error(`Element '${params.elementId}' not found on slide ${params.slideIndex}.`);
2265
+ }
2266
+ const trigger = params.trigger ?? "click";
2267
+ const action = {};
2268
+ if (params.url) {
2269
+ action.url = params.url;
2270
+ }
2271
+ if (params.tooltip) {
2272
+ action.tooltip = params.tooltip;
2273
+ }
2274
+ if (params.targetSlideIndex !== void 0) {
2275
+ action.targetSlideIndex = params.targetSlideIndex;
2276
+ }
2277
+ if (params.actionType) {
2278
+ switch (params.actionType) {
2279
+ case "url":
2280
+ action.action = "ppaction://hlinkpres";
2281
+ break;
2282
+ case "slide":
2283
+ action.action = "ppaction://hlinksldjump";
2284
+ break;
2285
+ case "nextSlide":
2286
+ action.action = "ppaction://hlinkshowjump?jump=nextslide";
2287
+ break;
2288
+ case "prevSlide":
2289
+ action.action = "ppaction://hlinkshowjump?jump=previousslide";
2290
+ break;
2291
+ case "firstSlide":
2292
+ action.action = "ppaction://hlinkshowjump?jump=firstslide";
2293
+ break;
2294
+ case "lastSlide":
2295
+ action.action = "ppaction://hlinkshowjump?jump=lastslide";
2296
+ break;
2297
+ case "endShow":
2298
+ action.action = "ppaction://hlinkshowjump?jump=endshow";
2299
+ break;
2300
+ }
2301
+ }
2302
+ if (trigger === "click") {
2303
+ el.actionClick = action;
2304
+ } else {
2305
+ el.actionHover = action;
2306
+ }
2307
+ return {
2308
+ pptxData: ctx.pptxData,
2309
+ dirty: true,
2310
+ result: { action: "set", elementId: params.elementId }
2311
+ };
2312
+ }
2313
+ case "remove": {
2314
+ if (!params.elementId) {
2315
+ throw new Error("elementId is required for remove action.");
2316
+ }
2317
+ const el = slide.elements.find((e) => e.id === params.elementId);
2318
+ if (!el) {
2319
+ throw new Error(`Element '${params.elementId}' not found on slide ${params.slideIndex}.`);
2320
+ }
2321
+ const trigger = params.trigger ?? "click";
2322
+ if (trigger === "click") {
2323
+ el.actionClick = void 0;
2324
+ } else {
2325
+ el.actionHover = void 0;
2326
+ }
2327
+ return {
2328
+ pptxData: ctx.pptxData,
2329
+ dirty: true,
2330
+ result: { action: "remove", elementId: params.elementId }
2331
+ };
2332
+ }
2333
+ default:
2334
+ throw new Error(`Unknown hyperlink action: ${String(params.action)}`);
2335
+ }
2336
+ }
2337
+ function replaceGeometry(ctx, params) {
2338
+ const err = validateSlideIndex(params.slideIndex, ctx.pptxData.slides.length);
2339
+ if (err) {
2340
+ throw new Error(err);
2341
+ }
2342
+ const slide = ctx.pptxData.slides[params.slideIndex];
2343
+ const el = slide.elements.find((e) => e.id === params.elementId);
2344
+ if (!el) {
2345
+ throw new Error(`Element '${params.elementId}' not found on slide ${params.slideIndex}.`);
2346
+ }
2347
+ if (el.type !== "shape") {
2348
+ throw new Error(`Element '${params.elementId}' is not a shape.`);
2349
+ }
2350
+ const shape = el;
2351
+ if (params.svgPath) {
2352
+ pptxViewerCore.replaceWithCustomGeometry(shape, params.svgPath, params.pathWidth, params.pathHeight);
2353
+ return {
2354
+ pptxData: ctx.pptxData,
2355
+ dirty: true,
2356
+ result: { elementId: params.elementId, geometryType: "custom" }
2357
+ };
2358
+ }
2359
+ if (params.shapeType) {
2360
+ pptxViewerCore.replaceShapeGeometry(shape, params.shapeType, params.adjustments);
2361
+ return {
2362
+ pptxData: ctx.pptxData,
2363
+ dirty: true,
2364
+ result: { elementId: params.elementId, geometryType: params.shapeType }
2365
+ };
2366
+ }
2367
+ throw new Error("Either shapeType or svgPath must be provided.");
2368
+ }
2369
+ function setElementLockT(ctx, params) {
2370
+ const err = validateSlideIndex(params.slideIndex, ctx.pptxData.slides.length);
2371
+ if (err) {
2372
+ throw new Error(err);
2373
+ }
2374
+ const slide = ctx.pptxData.slides[params.slideIndex];
2375
+ const idx = slide.elements.findIndex((e) => e.id === params.elementId);
2376
+ if (idx < 0) {
2377
+ throw new Error(`Element '${params.elementId}' not found on slide ${params.slideIndex}.`);
2378
+ }
2379
+ const extraLocks = {};
2380
+ if (params.noMove !== void 0) {
2381
+ extraLocks["noMove"] = params.noMove;
2382
+ }
2383
+ if (params.noResize !== void 0) {
2384
+ extraLocks["noResize"] = params.noResize;
2385
+ }
2386
+ if (params.noRotation !== void 0) {
2387
+ extraLocks["noRotation"] = params.noRotation;
2388
+ }
2389
+ if (params.noSelect !== void 0) {
2390
+ extraLocks["noSelect"] = params.noSelect;
2391
+ }
2392
+ if (params.noTextEdit !== void 0) {
2393
+ extraLocks["noTextEdit"] = params.noTextEdit;
2394
+ }
2395
+ const updated = pptxViewerCore.setElementLocked(slide.elements[idx], params.locked, extraLocks);
2396
+ slide.elements[idx] = updated;
2397
+ return {
2398
+ pptxData: ctx.pptxData,
2399
+ dirty: true,
2400
+ result: { elementId: params.elementId, locked: params.locked }
2401
+ };
2402
+ }
2403
+ async function validatePresentation(rawBytes) {
2404
+ const result = await pptxViewerCore.validatePptx(rawBytes);
2405
+ return {
2406
+ valid: result.valid,
2407
+ issueCount: result.issues.length,
2408
+ errors: result.issues.filter((i) => i.severity === "error").length,
2409
+ warnings: result.issues.filter((i) => i.severity === "warning").length,
2410
+ issues: result.issues
2411
+ };
2412
+ }
2413
+ async function repairPresentation(rawBytes) {
2414
+ const result = await pptxViewerCore.repairPptx(rawBytes);
2415
+ return {
2416
+ result: {
2417
+ repairCount: result.repairs.length,
2418
+ repairs: result.repairs
2419
+ },
2420
+ repairedBytes: result.repaired
2421
+ };
2422
+ }
2423
+
2424
+ // src/tools/presentation-tools.ts
2425
+ function getPresentationProperties(ctx) {
2426
+ return {
2427
+ pptxData: ctx.pptxData,
2428
+ dirty: false,
2429
+ result: {
2430
+ properties: ctx.pptxData.presentationProperties,
2431
+ slideCount: ctx.pptxData.slides.length,
2432
+ width: ctx.pptxData.width,
2433
+ height: ctx.pptxData.height
2434
+ }
2435
+ };
2436
+ }
2437
+ function updatePresentationProperties(ctx, params) {
2438
+ if (!ctx.pptxData.presentationProperties) {
2439
+ ctx.pptxData.presentationProperties = {};
2440
+ }
2441
+ const pp = ctx.pptxData.presentationProperties;
2442
+ if (params.showType !== void 0) {
2443
+ pp.showType = params.showType;
2444
+ }
2445
+ if (params.loopContinuously !== void 0) {
2446
+ pp.loopContinuously = params.loopContinuously;
2447
+ }
2448
+ if (params.showWithNarration !== void 0) {
2449
+ pp.showWithNarration = params.showWithNarration;
2450
+ }
2451
+ if (params.showWithAnimation !== void 0) {
2452
+ pp.showWithAnimation = params.showWithAnimation;
2453
+ }
2454
+ if (params.advanceMode !== void 0) {
2455
+ pp.advanceMode = params.advanceMode;
2456
+ }
2457
+ if (params.showSlidesMode !== void 0) {
2458
+ pp.showSlidesMode = params.showSlidesMode;
2459
+ }
2460
+ if (params.showSlidesFrom !== void 0) {
2461
+ pp.showSlidesFrom = params.showSlidesFrom;
2462
+ }
2463
+ if (params.showSlidesTo !== void 0) {
2464
+ pp.showSlidesTo = params.showSlidesTo;
2465
+ }
2466
+ if (params.penColor !== void 0) {
2467
+ pp.penColor = params.penColor;
2468
+ }
2469
+ return {
2470
+ pptxData: ctx.pptxData,
2471
+ dirty: true,
2472
+ result: { properties: pp }
2473
+ };
2474
+ }
2475
+ function getLayouts(ctx) {
2476
+ const layouts = [];
2477
+ if (ctx.pptxData.slideMasters) {
2478
+ for (const master of ctx.pptxData.slideMasters) {
2479
+ if (master.layouts) {
2480
+ for (const layout of master.layouts) {
2481
+ layouts.push({
2482
+ name: layout.name ?? "Unknown",
2483
+ path: layout.path
2484
+ });
2485
+ }
2486
+ }
2487
+ }
2488
+ }
2489
+ if (ctx.pptxData.layoutOptions) {
2490
+ for (const opt of ctx.pptxData.layoutOptions) {
2491
+ if (!layouts.some((l) => l.path === opt.path)) {
2492
+ layouts.push({ name: opt.name, path: opt.path, type: opt.type });
2493
+ }
2494
+ }
2495
+ }
2496
+ return {
2497
+ pptxData: ctx.pptxData,
2498
+ dirty: false,
2499
+ result: { layouts, count: layouts.length }
2500
+ };
2501
+ }
2502
+ function applyLayout(ctx, params) {
2503
+ const err = validateSlideIndex(params.slideIndex, ctx.pptxData.slides.length);
2504
+ if (err) {
2505
+ throw new Error(err);
2506
+ }
2507
+ let layout;
2508
+ if (params.layoutName) {
2509
+ layout = pptxViewerCore.findLayoutByName(ctx.pptxData, params.layoutName);
2510
+ } else if (params.layoutType) {
2511
+ layout = pptxViewerCore.findLayoutByType(ctx.pptxData, params.layoutType);
2512
+ } else {
2513
+ throw new Error("Either layoutName or layoutType must be provided.");
2514
+ }
2515
+ if (!layout) {
2516
+ throw new Error(
2517
+ `Layout not found: ${params.layoutName ?? params.layoutType}. Use get_layouts to see available layouts.`
2518
+ );
2519
+ }
2520
+ const slide = ctx.pptxData.slides[params.slideIndex];
2521
+ slide.layoutName = layout.name;
2522
+ if (layout.path) {
2523
+ slide.layoutPath = layout.path;
2524
+ }
2525
+ return {
2526
+ pptxData: ctx.pptxData,
2527
+ dirty: true,
2528
+ result: { slideIndex: params.slideIndex, layoutName: layout.name ?? "Unknown" }
2529
+ };
2530
+ }
1591
2531
 
1592
2532
  Object.defineProperty(exports, "PptxHandler", {
1593
2533
  enumerable: true,
1594
2534
  get: function () { return pptxViewerCore.PptxHandler; }
1595
2535
  });
2536
+ exports.addChartSeriesT = addChartSeriesT;
1596
2537
  exports.addElement = addElement;
1597
2538
  exports.addSlide = addSlide;
2539
+ exports.applyLayout = applyLayout;
2540
+ exports.applyTemplateT = applyTemplateT;
2541
+ exports.applyThemePreset = applyThemePreset;
1598
2542
  exports.arrangeElements = arrangeElements;
1599
2543
  exports.batchUpdateElements = batchUpdateElements;
1600
2544
  exports.cloneElement = cloneElement;
1601
2545
  exports.convertToMarkdown = convertToMarkdown;
2546
+ exports.createChart = createChart;
1602
2547
  exports.deleteElements = deleteElements;
1603
2548
  exports.deleteSlides = deleteSlides;
1604
2549
  exports.describeElement = describeElement;
2550
+ exports.diffPresentationsT = diffPresentationsT;
1605
2551
  exports.duplicateSlide = duplicateSlide;
1606
2552
  exports.executeToolWithContext = executeToolWithContext;
2553
+ exports.exportSlideSvg = exportSlideSvg;
2554
+ exports.exportToSvg = exportToSvg;
1607
2555
  exports.extractSlideText = extractSlideText;
2556
+ exports.findPlaceholdersT = findPlaceholdersT;
1608
2557
  exports.findText = findText;
1609
2558
  exports.generateElementId = generateElementId;
1610
2559
  exports.generateSlideId = generateSlideId;
2560
+ exports.getLayouts = getLayouts;
2561
+ exports.getMetadata = getMetadata;
2562
+ exports.getPresentationProperties = getPresentationProperties;
1611
2563
  exports.getSlide = getSlide;
2564
+ exports.getThemeInfo = getThemeInfo;
1612
2565
  exports.groupElements = groupElements;
1613
2566
  exports.loadPresentation = loadPresentation;
1614
2567
  exports.manageComments = manageComments;
2568
+ exports.manageHyperlinks = manageHyperlinks;
2569
+ exports.manageSections = manageSections;
2570
+ exports.manageSmartArt = manageSmartArt;
1615
2571
  exports.manageTableStructure = manageTableStructure;
2572
+ exports.mergePresentationT = mergePresentationT;
2573
+ exports.removeChartSeriesT = removeChartSeriesT;
1616
2574
  exports.reorderSlides = reorderSlides;
2575
+ exports.repairPresentation = repairPresentation;
2576
+ exports.replaceGeometry = replaceGeometry;
1617
2577
  exports.replaceText = replaceText;
1618
2578
  exports.runAccessibilityCheck = runAccessibilityCheck;
1619
2579
  exports.savePresentation = savePresentation;
1620
2580
  exports.setCanvasSize = setCanvasSize;
1621
2581
  exports.setElementAnimation = setElementAnimation;
2582
+ exports.setElementLockT = setElementLockT;
1622
2583
  exports.setSlideTransition = setSlideTransition;
1623
2584
  exports.ungroupElements = ungroupElements;
2585
+ exports.updateChart = updateChart;
2586
+ exports.updateChartSeriesData = updateChartSeriesData;
1624
2587
  exports.updateElement = updateElement;
1625
2588
  exports.updateElementStyle = updateElementStyle;
2589
+ exports.updateMetadata = updateMetadata;
2590
+ exports.updatePresentationProperties = updatePresentationProperties;
1626
2591
  exports.updateSlideProperties = updateSlideProperties;
1627
2592
  exports.updateTableCells = updateTableCells;
2593
+ exports.updateThemeColors = updateThemeColors;
2594
+ exports.updateThemeFonts = updateThemeFonts;
2595
+ exports.validatePresentation = validatePresentation;
1628
2596
  exports.validateSlideIndex = validateSlideIndex;