@yudaocode/univer-slides 1.6.218 → 1.6.219

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/lib/cjs/index.js CHANGED
@@ -59,11 +59,15 @@ __export(src_exports, {
59
59
  UNIVER_SLIDE_SCHEMA_VERSION: () => UNIVER_SLIDE_SCHEMA_VERSION,
60
60
  UniverSlidesPlugin: () => UniverSlidesPlugin,
61
61
  UpdateSlideElementsCommand: () => UpdateSlideElementsCommand,
62
+ UpdateSlideLayoutCommand: () => UpdateSlideLayoutCommand,
63
+ UpdateSlideMasterCommand: () => UpdateSlideMasterCommand,
62
64
  UpdateSlidePagePropsCommand: () => UpdateSlidePagePropsCommand,
63
65
  UpdateSlideSectionCommand: () => UpdateSlideSectionCommand,
66
+ UpdateSlideShowSettingsCommand: () => UpdateSlideShowSettingsCommand,
64
67
  UpdateSlideThemeCommand: () => UpdateSlideThemeCommand,
65
68
  VERSION: () => VERSION,
66
69
  compileSlidesWithDataset: () => compileSlidesWithDataset,
70
+ computeMorphInterpolatedSlide: () => computeMorphInterpolatedSlide,
67
71
  countSlideTextMatches: () => countSlideTextMatches,
68
72
  crc32Bytes: () => crc32Bytes,
69
73
  createDefaultSlideElement: () => createDefaultSlideElement,
@@ -72,11 +76,14 @@ __export(src_exports, {
72
76
  createDefaultSlideUnitData: () => createDefaultSlideUnitData,
73
77
  createElementsFromLayout: () => createElementsFromLayout,
74
78
  createSampleExecutiveDeckData: () => createSampleExecutiveDeckData,
79
+ cubicEaseInOut: () => cubicEaseInOut,
75
80
  deflateRawSyncPure: () => deflateRawSyncPure,
76
81
  emuToPt: () => emuToPt,
77
82
  escapeSvgXml: () => escapeSvgXml,
83
+ exportAllSlidesToImages: () => exportAllSlidesToImages,
78
84
  exportPptxBytes: () => exportPptxBytes,
79
85
  exportPptxBytesSync: () => exportPptxBytesSync,
86
+ exportSlidePageToDataUrl: () => exportSlidePageToDataUrl,
80
87
  exportSlidesToPdfBytes: () => exportSlidesToPdfBytes,
81
88
  extractSlideDatasetCodes: () => extractSlideDatasetCodes,
82
89
  findLayoutByTypeOrId: () => findLayoutByTypeOrId,
@@ -85,15 +92,21 @@ __export(src_exports, {
85
92
  importPptxBytes: () => importPptxBytes,
86
93
  importPptxBytesSync: () => importPptxBytesSync,
87
94
  inflateRawSyncPure: () => inflateRawSyncPure,
95
+ interpolateHexColor: () => interpolateHexColor,
96
+ matchMorphSlidePairs: () => matchMorphSlidePairs,
88
97
  packZipSync: () => packZipSync,
98
+ parseCssHexOrRgb: () => parseCssHexOrRgb,
89
99
  ptToEmu: () => ptToEmu,
90
100
  renderSlideChartToSvg: () => renderSlideChartToSvg,
91
101
  renderSlideChartToSvgDataUri: () => renderSlideChartToSvgDataUri,
102
+ renderSlideMediaToSvg: () => renderSlideMediaToSvg,
103
+ renderSlideMediaToSvgDataUri: () => renderSlideMediaToSvgDataUri,
92
104
  renderSlidePageToSvg: () => renderSlidePageToSvg,
93
105
  renderSlideSmartArtToSvg: () => renderSlideSmartArtToSvg,
94
106
  renderSlideSmartArtToSvgDataUri: () => renderSlideSmartArtToSvgDataUri,
95
107
  resolveChartPalette: () => resolveChartPalette,
96
108
  resolveConnectorEndpoints: () => resolveConnectorEndpoints,
109
+ resolveExplicitMorphKey: () => resolveExplicitMorphKey,
97
110
  svgToDataUri: () => svgToDataUri,
98
111
  syncTextAndParagraphs: () => syncTextAndParagraphs,
99
112
  unpackZipSync: () => unpackZipSync
@@ -552,6 +565,7 @@ function createDefaultSlideUnitData(partial) {
552
565
  sections,
553
566
  slideOrder,
554
567
  slides,
568
+ ...partial?.slideshowSettings ? { slideshowSettings: import_core.Tools.deepClone(partial.slideshowSettings) } : {},
555
569
  ...partial?.metadata ? { metadata: import_core.Tools.deepClone(partial.metadata) } : {}
556
570
  };
557
571
  }
@@ -989,6 +1003,9 @@ var SlideUnitModel = class extends import_core.UnitModel {
989
1003
  getSections() {
990
1004
  return this._snapshot.sections;
991
1005
  }
1006
+ getSlideShowSettings() {
1007
+ return this._snapshot.slideshowSettings;
1008
+ }
992
1009
  getSlideOrder() {
993
1010
  return this._snapshot.slideOrder;
994
1011
  }
@@ -1742,11 +1759,187 @@ function renderSlideSmartArtToSvg(smartArt, theme) {
1742
1759
  function renderSlideSmartArtToSvgDataUri(smartArt, theme) {
1743
1760
  return svgToDataUri(renderSlideSmartArtToSvg(smartArt, theme));
1744
1761
  }
1762
+ function renderSlideMediaToSvg(media, theme) {
1763
+ const w = Math.max(80, Math.round(media.width || (media.type === "video" ? 420 : 320)));
1764
+ const h = Math.max(40, Math.round(media.height || (media.type === "video" ? 240 : 64)));
1765
+ const accent = theme?.colors.accent1 ?? "#2563eb";
1766
+ const fontFamily = theme?.minorFont ?? "PingFang SC, Microsoft YaHei, Inter, Arial, sans-serif";
1767
+ const label = media.name || (media.type === "video" ? "\u89C6\u9891\u5A92\u4F53" : "\u97F3\u9891\u5A92\u4F53");
1768
+ if (media.type === "video") {
1769
+ const cx2 = w / 2;
1770
+ const cy2 = h / 2;
1771
+ const btnR = Math.max(14, Math.min(26, Math.min(w, h) * 0.16));
1772
+ const triPts2 = `${(cx2 - btnR * 0.32).toFixed(1)},${(cy2 - btnR * 0.44).toFixed(1)} ${(cx2 - btnR * 0.32).toFixed(1)},${(cy2 + btnR * 0.44).toFixed(1)} ${(cx2 + btnR * 0.48).toFixed(1)},${cy2.toFixed(1)}`;
1773
+ const posterImg = media.poster ? `<image href="${escapeSvgXml(media.poster)}" x="0" y="0" width="${w}" height="${h}" preserveAspectRatio="xMidYMid slice" opacity="0.72"/>` : "";
1774
+ return [
1775
+ `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${w} ${h}" width="${w}" height="${h}" font-family="${escapeSvgXml(fontFamily)}">`,
1776
+ `<rect x="0.5" y="0.5" width="${w - 1}" height="${h - 1}" rx="8" fill="#0f172a" stroke="#334155" stroke-width="1"/>`,
1777
+ posterImg,
1778
+ `<circle cx="${cx2.toFixed(1)}" cy="${cy2.toFixed(1)}" r="${btnR.toFixed(1)}" fill="${escapeSvgXml(accent)}" fill-opacity="0.92"/>`,
1779
+ `<polygon points="${triPts2}" fill="#ffffff"/>`,
1780
+ `<rect x="0" y="${Math.max(0, h - 28)}" width="${w}" height="28" fill="rgba(15,23,42,0.78)"/>`,
1781
+ `<text x="12" y="${h - 10}" font-size="11" font-weight="600" fill="#e2e8f0">${escapeSvgXml(label)}</text>`,
1782
+ `<text x="${w - 12}" y="${h - 10}" text-anchor="end" font-size="9.5" font-weight="700" fill="#38bdf8">VIDEO</text>`,
1783
+ `</svg>`
1784
+ ].join("");
1785
+ }
1786
+ const cy = h / 2;
1787
+ const r = Math.max(11, Math.min(18, h * 0.3));
1788
+ const cx = 14 + r;
1789
+ const triPts = `${(cx - r * 0.28).toFixed(1)},${(cy - r * 0.42).toFixed(1)} ${(cx - r * 0.28).toFixed(1)},${(cy + r * 0.42).toFixed(1)} ${(cx + r * 0.46).toFixed(1)},${cy.toFixed(1)}`;
1790
+ const trackX = cx + r + 12;
1791
+ const trackW = Math.max(24, w - trackX - 54);
1792
+ return [
1793
+ `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${w} ${h}" width="${w}" height="${h}" font-family="${escapeSvgXml(fontFamily)}">`,
1794
+ `<rect x="0.5" y="0.5" width="${w - 1}" height="${h - 1}" rx="10" fill="#1e293b" stroke="#475569" stroke-width="1"/>`,
1795
+ `<circle cx="${cx.toFixed(1)}" cy="${cy.toFixed(1)}" r="${r.toFixed(1)}" fill="${escapeSvgXml(accent)}"/>`,
1796
+ `<polygon points="${triPts}" fill="#ffffff"/>`,
1797
+ `<text x="${trackX.toFixed(1)}" y="${(cy - 4).toFixed(1)}" font-size="11" font-weight="600" fill="#f8fafc">${escapeSvgXml(label)}</text>`,
1798
+ `<rect x="${trackX.toFixed(1)}" y="${(cy + 4).toFixed(1)}" width="${trackW.toFixed(1)}" height="4" rx="2" fill="#475569"/>`,
1799
+ `<rect x="${trackX.toFixed(1)}" y="${(cy + 4).toFixed(1)}" width="${(trackW * 0.38).toFixed(1)}" height="4" rx="2" fill="#38bdf8"/>`,
1800
+ `<text x="${w - 12}" y="${(cy + 4).toFixed(1)}" text-anchor="end" font-size="9.5" font-weight="700" fill="#94a3b8">AUDIO</text>`,
1801
+ `</svg>`
1802
+ ].join("");
1803
+ }
1804
+ function renderSlideMediaToSvgDataUri(media, theme) {
1805
+ return svgToDataUri(renderSlideMediaToSvg(media, theme));
1806
+ }
1807
+ function appendSlideElementToSvg(el, elementsMap, theme, defs, body, idPrefix = "") {
1808
+ if (!el || el.hidden) return;
1809
+ const opacityAttr = el.opacity !== void 0 && el.opacity < 1 ? ` opacity="${el.opacity}"` : "";
1810
+ const rotCx = el.x + el.width / 2;
1811
+ const rotCy = el.y + el.height / 2;
1812
+ const rotTransform = el.rotation ? ` transform="rotate(${el.rotation} ${rotCx} ${rotCy})"` : "";
1813
+ const safeId = escapeSvgXml(`${idPrefix}${el.id}`);
1814
+ if (el.type === "shape") {
1815
+ const pathD = getShapeSvgPath(el.shapeType, el.width, el.height, el.cornerRadius ?? 8);
1816
+ let fillAttr = escapeSvgXml(el.fillColor || theme.colors.accent1);
1817
+ if (el.gradientFrom && el.gradientTo) {
1818
+ const gid = `grad-${safeId}`;
1819
+ defs.push(
1820
+ `<linearGradient id="${gid}" x1="0%" y1="0%" x2="100%" y2="100%"><stop offset="0%" stop-color="${escapeSvgXml(el.gradientFrom)}"/><stop offset="100%" stop-color="${escapeSvgXml(el.gradientTo)}"/></linearGradient>`
1821
+ );
1822
+ fillAttr = `url(#${gid})`;
1823
+ }
1824
+ const dash = el.strokeDash === "dashed" ? ' stroke-dasharray="6 4"' : el.strokeDash === "dotted" ? ' stroke-dasharray="2 3"' : "";
1825
+ body.push(
1826
+ `<g transform="translate(${el.x} ${el.y})${el.rotation ? ` rotate(${el.rotation} ${el.width / 2} ${el.height / 2})` : ""}"${opacityAttr}>`,
1827
+ `<path d="${pathD}" fill="${fillAttr}" stroke="${escapeSvgXml(el.strokeColor || "none")}" stroke-width="${el.strokeWidth ?? 1}"${dash}/>`,
1828
+ el.text ? `<text x="${el.width / 2}" y="${el.height / 2 + (el.fontSize ?? 14) * 0.35}" text-anchor="middle" font-size="${el.fontSize ?? 14}" font-weight="${el.fontWeight ?? "normal"}" fill="${escapeSvgXml(el.textColor || "#ffffff")}">${escapeSvgXml(el.text)}</text>` : "",
1829
+ `</g>`
1830
+ );
1831
+ } else if (el.type === "connector") {
1832
+ const geom = resolveConnectorEndpoints(el, elementsMap);
1833
+ const markerId = `arrow-${safeId}`;
1834
+ if (el.endArrow || el.startArrow) {
1835
+ defs.push(
1836
+ `<marker id="${markerId}" markerWidth="8" markerHeight="8" refX="7" refY="4" orient="auto"><path d="M0,0 L8,4 L0,8 Z" fill="${escapeSvgXml(el.strokeColor)}"/></marker>`
1837
+ );
1838
+ }
1839
+ body.push(
1840
+ `<path d="${geom.pathD}" fill="none" stroke="${escapeSvgXml(el.strokeColor)}" stroke-width="${el.strokeWidth || 2}"${el.endArrow ? ` marker-end="url(#${markerId})"` : ""}${opacityAttr}/>`
1841
+ );
1842
+ if (el.label) {
1843
+ body.push(
1844
+ `<text x="${geom.midX.toFixed(1)}" y="${(geom.midY - 6).toFixed(1)}" text-anchor="middle" font-size="11" fill="${escapeSvgXml(el.labelColor || el.strokeColor)}"${opacityAttr}>${escapeSvgXml(el.label)}</text>`
1845
+ );
1846
+ }
1847
+ } else if (el.type === "text") {
1848
+ const fs = el.fontSize ?? 18;
1849
+ const fw = el.fontWeight ?? "normal";
1850
+ let fillAttr = escapeSvgXml(el.color || theme.colors.text);
1851
+ if (el.wordArt?.enabled) {
1852
+ const wid = `wordart-${safeId}`;
1853
+ defs.push(
1854
+ `<linearGradient id="${wid}" x1="0%" y1="0%" x2="100%" y2="0%"><stop offset="0%" stop-color="${escapeSvgXml(el.wordArt.gradientFrom)}"/><stop offset="100%" stop-color="${escapeSvgXml(el.wordArt.gradientTo)}"/></linearGradient>`
1855
+ );
1856
+ fillAttr = `url(#${wid})`;
1857
+ }
1858
+ const lines = (el.text || "").split("\n");
1859
+ const anchor = el.align === "center" ? "middle" : el.align === "right" ? "end" : "start";
1860
+ const tx = el.align === "center" ? el.x + el.width / 2 : el.align === "right" ? el.x + el.width - 8 : el.x + 8;
1861
+ body.push(`<g${rotTransform}${opacityAttr}>`);
1862
+ if (el.fillColor) {
1863
+ body.push(
1864
+ `<rect x="${el.x}" y="${el.y}" width="${el.width}" height="${el.height}" rx="${el.borderRadius ?? 4}" fill="${escapeSvgXml(el.fillColor)}" stroke="${escapeSvgXml(el.strokeColor || "none")}" stroke-width="${el.strokeWidth ?? 0}"/>`
1865
+ );
1866
+ }
1867
+ lines.forEach((line, lIdx) => {
1868
+ const prefix = el.bullet ? el.bullet === "number" ? `${lIdx + 1}. ` : "\u2022 " : "";
1869
+ const ty = el.y + fs + 6 + lIdx * fs * (el.lineHeight ?? 1.35);
1870
+ body.push(
1871
+ `<text x="${tx}" y="${ty.toFixed(1)}" text-anchor="${anchor}" font-size="${fs}" font-weight="${fw}"${el.italic ? ' font-style="italic"' : ""} fill="${fillAttr}">${escapeSvgXml(prefix + line)}</text>`
1872
+ );
1873
+ });
1874
+ body.push(`</g>`);
1875
+ } else if (el.type === "chart") {
1876
+ const inner = renderSlideChartToSvg({ ...el, width: el.width, height: el.height }, theme).replace(/^<svg[^>]*>/, "").replace(/<\/svg>$/, "");
1877
+ body.push(`<g transform="translate(${el.x} ${el.y})"${opacityAttr}>${inner}</g>`);
1878
+ } else if (el.type === "smartArt") {
1879
+ const inner = renderSlideSmartArtToSvg({ ...el, width: el.width, height: el.height }, theme).replace(/^<svg[^>]*>/, "").replace(/<\/svg>$/, "");
1880
+ body.push(`<g transform="translate(${el.x} ${el.y})"${opacityAttr}>${inner}</g>`);
1881
+ } else if (el.type === "table") {
1882
+ body.push(`<g transform="translate(${el.x} ${el.y})"${opacityAttr}>`);
1883
+ let curY = 0;
1884
+ for (let r = 0; r < el.rows; r++) {
1885
+ const rh = el.rowHeights[r] ?? el.height / Math.max(1, el.rows);
1886
+ let curX = 0;
1887
+ for (let c = 0; c < el.cols; c++) {
1888
+ const cw = el.colWidths[c] ?? el.width / Math.max(1, el.cols);
1889
+ const cell = el.cells[r]?.[c];
1890
+ if (!cell?.mergedInto) {
1891
+ const isHeader = el.headerRow !== false && r === 0;
1892
+ const bgFill = cell?.bg || (isHeader ? el.headerBg || theme.colors.primary : r % 2 === 1 ? el.zebraBg || "#f8fafc" : "#ffffff");
1893
+ const fgFill = cell?.color || (isHeader ? el.headerColor || "#ffffff" : theme.colors.text);
1894
+ body.push(
1895
+ `<rect x="${curX.toFixed(1)}" y="${curY.toFixed(1)}" width="${cw.toFixed(1)}" height="${rh.toFixed(1)}" fill="${escapeSvgXml(bgFill)}" stroke="${escapeSvgXml(el.borderColor || "#cbd5e1")}" stroke-width="0.8"/>`,
1896
+ `<text x="${(curX + 8).toFixed(1)}" y="${(curY + rh / 2 + 4).toFixed(1)}" font-size="${cell?.fontSize ?? 11}" font-weight="${cell?.bold || isHeader ? "700" : "400"}" fill="${escapeSvgXml(fgFill)}">${escapeSvgXml(cell?.text ?? "")}</text>`
1897
+ );
1898
+ }
1899
+ curX += cw;
1900
+ }
1901
+ curY += rh;
1902
+ }
1903
+ body.push(`</g>`);
1904
+ } else if (el.type === "image" || el.type === "svg") {
1905
+ if (el.src) {
1906
+ body.push(
1907
+ `<image href="${escapeSvgXml(el.src)}" x="${el.x}" y="${el.y}" width="${el.width}" height="${el.height}" preserveAspectRatio="${el.fit === "cover" ? "xMidYMid slice" : el.fit === "fill" ? "none" : "xMidYMid meet"}"${opacityAttr}/>`
1908
+ );
1909
+ }
1910
+ } else if (el.type === "codeBlock") {
1911
+ const dark = el.codeTheme !== "light";
1912
+ body.push(
1913
+ `<g transform="translate(${el.x} ${el.y})"${opacityAttr}>`,
1914
+ `<rect x="0" y="0" width="${el.width}" height="${el.height}" rx="8" fill="${dark ? "#0f172a" : "#f8fafc"}" stroke="#334155" stroke-width="1"/>`,
1915
+ `<text x="12" y="20" font-size="10" font-weight="700" fill="#38bdf8">${escapeSvgXml(el.language.toUpperCase())}</text>`
1916
+ );
1917
+ el.code.split("\n").slice(0, 12).forEach((ln, idx) => {
1918
+ body.push(
1919
+ `<text x="12" y="${38 + idx * 15}" font-family="Menlo, Monaco, Consolas, monospace" font-size="${el.fontSize ?? 11}" fill="${dark ? "#e2e8f0" : "#1e293b"}">${escapeSvgXml(ln)}</text>`
1920
+ );
1921
+ });
1922
+ body.push(`</g>`);
1923
+ } else if (el.type === "sheetEmbed") {
1924
+ body.push(
1925
+ `<g transform="translate(${el.x} ${el.y})"${opacityAttr}>`,
1926
+ `<rect x="0" y="0" width="${el.width}" height="${el.height}" rx="6" fill="#ffffff" stroke="#10b981" stroke-width="1.2"/>`,
1927
+ `<rect x="0" y="0" width="${el.width}" height="24" rx="6" fill="${escapeSvgXml(el.accentColor || "#059669")}"/>`,
1928
+ `<text x="10" y="16" font-size="11" font-weight="700" fill="#ffffff">${escapeSvgXml(el.title || "\u7535\u5B50\u8868\u683C\u6570\u636E\u5FEB\u7167")}</text>`,
1929
+ `</g>`
1930
+ );
1931
+ } else if (el.type === "video" || el.type === "audio") {
1932
+ const inner = renderSlideMediaToSvg({ ...el, width: el.width, height: el.height }, theme).replace(/^<svg[^>]*>/, "").replace(/<\/svg>$/, "");
1933
+ body.push(`<g transform="translate(${el.x} ${el.y})"${rotTransform}${opacityAttr}>${inner}</g>`);
1934
+ }
1935
+ }
1745
1936
  function renderSlidePageToSvg(page, unitData, slideNumber) {
1746
1937
  const w = unitData.slideSize.widthPt || 960;
1747
1938
  const h = unitData.slideSize.heightPt || 540;
1748
1939
  const theme = unitData.theme ?? SLIDE_THEME_PRESETS[0];
1749
- const bg = page.background ?? unitData.masters[0]?.background ?? { type: "solid", color: theme.colors.background };
1940
+ const matchedLayout = unitData.layouts?.find((l) => l.id === page.layoutId);
1941
+ const master = (matchedLayout ? unitData.masters.find((m) => m.id === matchedLayout.masterId) : void 0) ?? unitData.masters[0];
1942
+ const bg = page.background ?? matchedLayout?.background ?? master?.background ?? { type: "solid", color: theme.colors.background };
1750
1943
  const defs = [];
1751
1944
  const body = [];
1752
1945
  if (bg.type === "gradient" && bg.gradientFrom && bg.gradientTo) {
@@ -1765,150 +1958,424 @@ function renderSlidePageToSvg(page, unitData, slideNumber) {
1765
1958
  );
1766
1959
  }
1767
1960
  }
1768
- if (unitData.masters[0]?.accentBar) {
1961
+ if (master?.accentBar) {
1769
1962
  body.push(`<rect x="0" y="0" width="${w}" height="4" fill="${escapeSvgXml(theme.colors.primary)}"/>`);
1770
1963
  }
1964
+ if (master?.masterElements && master.masterElements.length > 0) {
1965
+ const masterMap = {};
1966
+ for (const mEl of master.masterElements) {
1967
+ if (mEl) masterMap[mEl.id] = mEl;
1968
+ }
1969
+ for (const mEl of master.masterElements) {
1970
+ appendSlideElementToSvg(mEl, masterMap, theme, defs, body, "master-");
1971
+ }
1972
+ }
1973
+ if (matchedLayout?.layoutElements && matchedLayout.layoutElements.length > 0) {
1974
+ const layoutMap = {};
1975
+ for (const lEl of matchedLayout.layoutElements) {
1976
+ if (lEl) layoutMap[lEl.id] = lEl;
1977
+ }
1978
+ for (const lEl of matchedLayout.layoutElements) {
1979
+ appendSlideElementToSvg(lEl, layoutMap, theme, defs, body, "layout-");
1980
+ }
1981
+ }
1771
1982
  for (const elId of page.elementOrder) {
1772
1983
  const el = page.elements[elId];
1773
1984
  if (!el || el.hidden) continue;
1774
- const opacityAttr = el.opacity !== void 0 && el.opacity < 1 ? ` opacity="${el.opacity}"` : "";
1775
- const rotCx = el.x + el.width / 2;
1776
- const rotCy = el.y + el.height / 2;
1777
- const rotTransform = el.rotation ? ` transform="rotate(${el.rotation} ${rotCx} ${rotCy})"` : "";
1778
- if (el.type === "shape") {
1779
- const pathD = getShapeSvgPath(el.shapeType, el.width, el.height, el.cornerRadius ?? 8);
1780
- let fillAttr = escapeSvgXml(el.fillColor || theme.colors.accent1);
1781
- if (el.gradientFrom && el.gradientTo) {
1782
- const gid = `grad-${escapeSvgXml(el.id)}`;
1783
- defs.push(
1784
- `<linearGradient id="${gid}" x1="0%" y1="0%" x2="100%" y2="100%"><stop offset="0%" stop-color="${escapeSvgXml(el.gradientFrom)}"/><stop offset="100%" stop-color="${escapeSvgXml(el.gradientTo)}"/></linearGradient>`
1785
- );
1786
- fillAttr = `url(#${gid})`;
1985
+ appendSlideElementToSvg(el, page.elements, theme, defs, body);
1986
+ }
1987
+ if (master?.footerText) {
1988
+ body.push(
1989
+ `<text x="22" y="${h - 14}" font-size="10" fill="#64748b">${escapeSvgXml(master.footerText)}</text>`
1990
+ );
1991
+ }
1992
+ if (page.showSlideNumber !== false && typeof slideNumber === "number") {
1993
+ body.push(
1994
+ `<text x="${w - 22}" y="${h - 14}" text-anchor="end" font-size="10" fill="#64748b">${slideNumber}</text>`
1995
+ );
1996
+ }
1997
+ return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${w} ${h}" width="${w}" height="${h}" font-family="${escapeSvgXml(theme.minorFont)}">${defs.length ? `<defs>${defs.join("")}</defs>` : ""}${body.join("")}</svg>`;
1998
+ }
1999
+
2000
+ // src/renderers/slide-morph-engine.ts
2001
+ var import_core2 = require("@univerjs/core");
2002
+ function cubicEaseInOut(t) {
2003
+ const clamped = Math.max(0, Math.min(1, Number.isFinite(t) ? t : 1));
2004
+ return clamped < 0.5 ? 4 * clamped * clamped * clamped : 1 - Math.pow(-2 * clamped + 2, 3) / 2;
2005
+ }
2006
+ function lerpNum(from, to, t, precision = 2) {
2007
+ const val = from + (to - from) * t;
2008
+ const factor = Math.pow(10, precision);
2009
+ return Math.round(val * factor) / factor;
2010
+ }
2011
+ function parseCssHexOrRgb(color) {
2012
+ if (!color) return null;
2013
+ const trimmed = color.trim();
2014
+ const hexMatch = trimmed.match(/^#?([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/);
2015
+ if (hexMatch) {
2016
+ let h = hexMatch[1];
2017
+ if (h.length === 3) {
2018
+ h = `${h[0]}${h[0]}${h[1]}${h[1]}${h[2]}${h[2]}`;
2019
+ }
2020
+ return {
2021
+ r: parseInt(h.slice(0, 2), 16),
2022
+ g: parseInt(h.slice(2, 4), 16),
2023
+ b: parseInt(h.slice(4, 6), 16)
2024
+ };
2025
+ }
2026
+ const rgbMatch = trimmed.match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i);
2027
+ if (rgbMatch) {
2028
+ return {
2029
+ r: Math.max(0, Math.min(255, Number(rgbMatch[1]))),
2030
+ g: Math.max(0, Math.min(255, Number(rgbMatch[2]))),
2031
+ b: Math.max(0, Math.min(255, Number(rgbMatch[3])))
2032
+ };
2033
+ }
2034
+ return null;
2035
+ }
2036
+ function interpolateHexColor(fromColor, toColor, easedT) {
2037
+ if (!fromColor && !toColor) return void 0;
2038
+ const c1 = parseCssHexOrRgb(fromColor);
2039
+ const c2 = parseCssHexOrRgb(toColor);
2040
+ if (c1 && c2) {
2041
+ const r = Math.round(c1.r + (c2.r - c1.r) * easedT).toString(16).padStart(2, "0");
2042
+ const g = Math.round(c1.g + (c2.g - c1.g) * easedT).toString(16).padStart(2, "0");
2043
+ const b = Math.round(c1.b + (c2.b - c1.b) * easedT).toString(16).padStart(2, "0");
2044
+ return `#${r}${g}${b}`;
2045
+ }
2046
+ return easedT < 0.5 ? fromColor ?? toColor : toColor ?? fromColor;
2047
+ }
2048
+ function resolveExplicitMorphKey(el) {
2049
+ if (el.morphName && el.morphName.trim().length > 0) {
2050
+ const raw = el.morphName.trim();
2051
+ const stripped = raw.startsWith("!!") ? raw.slice(2).trim() : raw;
2052
+ if (stripped.length > 0) return stripped;
2053
+ }
2054
+ if (el.name && el.name.trim().startsWith("!!")) {
2055
+ const stripped = el.name.trim().slice(2).trim();
2056
+ if (stripped.length > 0) return stripped;
2057
+ }
2058
+ return null;
2059
+ }
2060
+ function getElementDetailedSignature(el) {
2061
+ switch (el.type) {
2062
+ case "shape":
2063
+ return `shape:${el.shapeType}:${(el.text || el.name || "").trim()}`;
2064
+ case "text":
2065
+ return `text:${el.placeholderRole || ""}:${(el.name || el.text.slice(0, 32) || "").trim()}`;
2066
+ case "chart":
2067
+ return `chart:${el.chartType}:${(el.title || el.name || "").trim()}`;
2068
+ case "smartArt":
2069
+ return `smartArt:${el.layout}:${(el.title || el.name || "").trim()}`;
2070
+ case "image":
2071
+ case "svg":
2072
+ return `${el.type}:${(el.src || el.name || "").trim()}`;
2073
+ case "video":
2074
+ case "audio":
2075
+ return `${el.type}:${(el.src || el.name || "").trim()}`;
2076
+ case "table":
2077
+ return `table:${el.rows}x${el.cols}:${(el.name || "").trim()}`;
2078
+ case "connector":
2079
+ return `connector:${el.connectorType}:${(el.label || el.name || "").trim()}`;
2080
+ case "codeBlock":
2081
+ return `codeBlock:${el.language}:${(el.title || el.name || "").trim()}`;
2082
+ case "sheetEmbed":
2083
+ return `sheetEmbed:${(el.title || el.name || "").trim()}`;
2084
+ }
2085
+ }
2086
+ function getElementCoarseSignature(el) {
2087
+ switch (el.type) {
2088
+ case "shape":
2089
+ return `shape:${el.shapeType}`;
2090
+ case "text":
2091
+ return `text:${el.placeholderRole || "freeform"}`;
2092
+ case "chart":
2093
+ return `chart:${el.chartType}`;
2094
+ case "smartArt":
2095
+ return `smartArt:${el.layout}`;
2096
+ default:
2097
+ return `${el.type}:${(el.name || "").trim()}`;
2098
+ }
2099
+ }
2100
+ function getOrderedVisibleElements(slide) {
2101
+ const ordered = [];
2102
+ const seen = /* @__PURE__ */ new Set();
2103
+ for (const id of slide.elementOrder) {
2104
+ const el = slide.elements[id];
2105
+ if (el && !el.hidden) {
2106
+ ordered.push(el);
2107
+ seen.add(id);
2108
+ }
2109
+ }
2110
+ for (const [id, el] of Object.entries(slide.elements)) {
2111
+ if (!seen.has(id) && el && !el.hidden) {
2112
+ ordered.push(el);
2113
+ }
2114
+ }
2115
+ return ordered;
2116
+ }
2117
+ function matchMorphSlidePairs(fromSlide, toSlide) {
2118
+ const fromList = getOrderedVisibleElements(fromSlide);
2119
+ const toList = getOrderedVisibleElements(toSlide);
2120
+ const usedFrom = /* @__PURE__ */ new Set();
2121
+ const usedTo = /* @__PURE__ */ new Set();
2122
+ const pairs = [];
2123
+ for (const fromEl of fromList) {
2124
+ const key = resolveExplicitMorphKey(fromEl);
2125
+ if (!key) continue;
2126
+ const candidate = toList.find(
2127
+ (toEl) => !usedTo.has(toEl.id) && resolveExplicitMorphKey(toEl) === key
2128
+ );
2129
+ if (candidate) {
2130
+ usedFrom.add(fromEl.id);
2131
+ usedTo.add(candidate.id);
2132
+ pairs.push({
2133
+ key: `morph:${key}`,
2134
+ matchReason: "morphName",
2135
+ fromElement: fromEl,
2136
+ toElement: candidate
2137
+ });
2138
+ }
2139
+ }
2140
+ const toById = /* @__PURE__ */ new Map();
2141
+ for (const toEl of toList) {
2142
+ if (!usedTo.has(toEl.id)) toById.set(toEl.id, toEl);
2143
+ }
2144
+ for (const fromEl of fromList) {
2145
+ if (usedFrom.has(fromEl.id)) continue;
2146
+ const sameIdEl = toById.get(fromEl.id);
2147
+ if (sameIdEl && !usedTo.has(sameIdEl.id)) {
2148
+ usedFrom.add(fromEl.id);
2149
+ usedTo.add(sameIdEl.id);
2150
+ pairs.push({
2151
+ key: `id:${fromEl.id}`,
2152
+ matchReason: "id",
2153
+ fromElement: fromEl,
2154
+ toElement: sameIdEl
2155
+ });
2156
+ }
2157
+ }
2158
+ const matchUniqueBySignatureFn = (sigFn) => {
2159
+ const fromSigMap = /* @__PURE__ */ new Map();
2160
+ const toSigMap = /* @__PURE__ */ new Map();
2161
+ for (const fromEl of fromList) {
2162
+ if (usedFrom.has(fromEl.id)) continue;
2163
+ const sig = sigFn(fromEl);
2164
+ const arr = fromSigMap.get(sig) ?? [];
2165
+ arr.push(fromEl);
2166
+ fromSigMap.set(sig, arr);
2167
+ }
2168
+ for (const toEl of toList) {
2169
+ if (usedTo.has(toEl.id)) continue;
2170
+ const sig = sigFn(toEl);
2171
+ const arr = toSigMap.get(sig) ?? [];
2172
+ arr.push(toEl);
2173
+ toSigMap.set(sig, arr);
2174
+ }
2175
+ for (const [sig, fArr] of fromSigMap.entries()) {
2176
+ const tArr = toSigMap.get(sig);
2177
+ if (fArr.length === 1 && tArr && tArr.length === 1) {
2178
+ const fEl = fArr[0];
2179
+ const tEl = tArr[0];
2180
+ usedFrom.add(fEl.id);
2181
+ usedTo.add(tEl.id);
2182
+ pairs.push({
2183
+ key: `sig:${sig}`,
2184
+ matchReason: "signature",
2185
+ fromElement: fEl,
2186
+ toElement: tEl
2187
+ });
1787
2188
  }
1788
- const dash = el.strokeDash === "dashed" ? ' stroke-dasharray="6 4"' : el.strokeDash === "dotted" ? ' stroke-dasharray="2 3"' : "";
1789
- body.push(
1790
- `<g transform="translate(${el.x} ${el.y})${el.rotation ? ` rotate(${el.rotation} ${el.width / 2} ${el.height / 2})` : ""}"${opacityAttr}>`,
1791
- `<path d="${pathD}" fill="${fillAttr}" stroke="${escapeSvgXml(el.strokeColor || "none")}" stroke-width="${el.strokeWidth ?? 1}"${dash}/>`,
1792
- el.text ? `<text x="${el.width / 2}" y="${el.height / 2 + (el.fontSize ?? 14) * 0.35}" text-anchor="middle" font-size="${el.fontSize ?? 14}" font-weight="${el.fontWeight ?? "normal"}" fill="${escapeSvgXml(el.textColor || "#ffffff")}">${escapeSvgXml(el.text)}</text>` : "",
1793
- `</g>`
2189
+ }
2190
+ };
2191
+ matchUniqueBySignatureFn(getElementDetailedSignature);
2192
+ matchUniqueBySignatureFn(getElementCoarseSignature);
2193
+ const unmatchedFrom = fromList.filter((el) => !usedFrom.has(el.id));
2194
+ const unmatchedTo = toList.filter((el) => !usedTo.has(el.id));
2195
+ return { pairs, unmatchedFrom, unmatchedTo };
2196
+ }
2197
+ function interpolateElementPair(fromEl, toEl, easedT) {
2198
+ const base = import_core2.Tools.deepClone(easedT < 0.5 ? fromEl : toEl);
2199
+ base.id = toEl.id;
2200
+ if (toEl.morphName || fromEl.morphName) {
2201
+ base.morphName = toEl.morphName ?? fromEl.morphName;
2202
+ }
2203
+ base.x = lerpNum(fromEl.x, toEl.x, easedT);
2204
+ base.y = lerpNum(fromEl.y, toEl.y, easedT);
2205
+ base.width = Math.max(1, lerpNum(fromEl.width, toEl.width, easedT));
2206
+ base.height = Math.max(1, lerpNum(fromEl.height, toEl.height, easedT));
2207
+ base.rotation = lerpNum(fromEl.rotation ?? 0, toEl.rotation ?? 0, easedT);
2208
+ base.opacity = lerpNum(fromEl.opacity ?? 1, toEl.opacity ?? 1, easedT, 4);
2209
+ if (base.type === "shape" && fromEl.type === "shape" && toEl.type === "shape") {
2210
+ const s = base;
2211
+ s.cornerRadius = lerpNum(fromEl.cornerRadius ?? 8, toEl.cornerRadius ?? 8, easedT);
2212
+ s.strokeWidth = lerpNum(fromEl.strokeWidth ?? 1, toEl.strokeWidth ?? 1, easedT);
2213
+ s.fontSize = lerpNum(fromEl.fontSize ?? 16, toEl.fontSize ?? 16, easedT);
2214
+ s.fillColor = interpolateHexColor(fromEl.fillColor, toEl.fillColor, easedT) ?? s.fillColor;
2215
+ s.strokeColor = interpolateHexColor(fromEl.strokeColor, toEl.strokeColor, easedT) ?? s.strokeColor;
2216
+ const textClr = interpolateHexColor(fromEl.textColor, toEl.textColor, easedT);
2217
+ if (textClr) s.textColor = textClr;
2218
+ if (fromEl.gradientFrom || toEl.gradientFrom) {
2219
+ s.gradientFrom = interpolateHexColor(
2220
+ fromEl.gradientFrom ?? fromEl.fillColor,
2221
+ toEl.gradientFrom ?? toEl.fillColor,
2222
+ easedT
1794
2223
  );
1795
- } else if (el.type === "connector") {
1796
- const geom = resolveConnectorEndpoints(el, page.elements);
1797
- const markerId = `arrow-${escapeSvgXml(el.id)}`;
1798
- if (el.endArrow || el.startArrow) {
1799
- defs.push(
1800
- `<marker id="${markerId}" markerWidth="8" markerHeight="8" refX="7" refY="4" orient="auto"><path d="M0,0 L8,4 L0,8 Z" fill="${escapeSvgXml(el.strokeColor)}"/></marker>`
1801
- );
1802
- }
1803
- body.push(
1804
- `<path d="${geom.pathD}" fill="none" stroke="${escapeSvgXml(el.strokeColor)}" stroke-width="${el.strokeWidth || 2}"${el.endArrow ? ` marker-end="url(#${markerId})"` : ""}${opacityAttr}/>`
2224
+ }
2225
+ if (fromEl.gradientTo || toEl.gradientTo) {
2226
+ s.gradientTo = interpolateHexColor(
2227
+ fromEl.gradientTo ?? fromEl.fillColor,
2228
+ toEl.gradientTo ?? toEl.fillColor,
2229
+ easedT
1805
2230
  );
1806
- if (el.label) {
1807
- body.push(
1808
- `<text x="${geom.midX.toFixed(1)}" y="${(geom.midY - 6).toFixed(1)}" text-anchor="middle" font-size="11" fill="${escapeSvgXml(el.labelColor || el.strokeColor)}">${escapeSvgXml(el.label)}</text>`
1809
- );
1810
- }
1811
- } else if (el.type === "text") {
1812
- const fs = el.fontSize ?? 18;
1813
- const fw = el.fontWeight ?? "normal";
1814
- let fillAttr = escapeSvgXml(el.color || theme.colors.text);
1815
- if (el.wordArt?.enabled) {
1816
- const wid = `wordart-${escapeSvgXml(el.id)}`;
1817
- defs.push(
1818
- `<linearGradient id="${wid}" x1="0%" y1="0%" x2="100%" y2="0%"><stop offset="0%" stop-color="${escapeSvgXml(el.wordArt.gradientFrom)}"/><stop offset="100%" stop-color="${escapeSvgXml(el.wordArt.gradientTo)}"/></linearGradient>`
1819
- );
1820
- fillAttr = `url(#${wid})`;
1821
- }
1822
- const lines = (el.text || "").split("\n");
1823
- const anchor = el.align === "center" ? "middle" : el.align === "right" ? "end" : "start";
1824
- const tx = el.align === "center" ? el.x + el.width / 2 : el.align === "right" ? el.x + el.width - 8 : el.x + 8;
1825
- body.push(`<g${rotTransform}${opacityAttr}>`);
1826
- if (el.fillColor) {
1827
- body.push(
1828
- `<rect x="${el.x}" y="${el.y}" width="${el.width}" height="${el.height}" rx="${el.borderRadius ?? 4}" fill="${escapeSvgXml(el.fillColor)}" stroke="${escapeSvgXml(el.strokeColor || "none")}" stroke-width="${el.strokeWidth ?? 0}"/>`
1829
- );
1830
- }
1831
- lines.forEach((line, lIdx) => {
1832
- const prefix = el.bullet ? el.bullet === "number" ? `${lIdx + 1}. ` : "\u2022 " : "";
1833
- const ty = el.y + fs + 6 + lIdx * fs * (el.lineHeight ?? 1.35);
1834
- body.push(
1835
- `<text x="${tx}" y="${ty.toFixed(1)}" text-anchor="${anchor}" font-size="${fs}" font-weight="${fw}"${el.italic ? ' font-style="italic"' : ""} fill="${fillAttr}">${escapeSvgXml(prefix + line)}</text>`
1836
- );
1837
- });
1838
- body.push(`</g>`);
1839
- } else if (el.type === "chart") {
1840
- const inner = renderSlideChartToSvg({ ...el, width: el.width, height: el.height }, theme).replace(/^<svg[^>]*>/, "").replace(/<\/svg>$/, "");
1841
- body.push(`<g transform="translate(${el.x} ${el.y})"${opacityAttr}>${inner}</g>`);
1842
- } else if (el.type === "smartArt") {
1843
- const inner = renderSlideSmartArtToSvg({ ...el, width: el.width, height: el.height }, theme).replace(/^<svg[^>]*>/, "").replace(/<\/svg>$/, "");
1844
- body.push(`<g transform="translate(${el.x} ${el.y})"${opacityAttr}>${inner}</g>`);
1845
- } else if (el.type === "table") {
1846
- body.push(`<g transform="translate(${el.x} ${el.y})"${opacityAttr}>`);
1847
- let curY = 0;
1848
- for (let r = 0; r < el.rows; r++) {
1849
- const rh = el.rowHeights[r] ?? el.height / Math.max(1, el.rows);
1850
- let curX = 0;
1851
- for (let c = 0; c < el.cols; c++) {
1852
- const cw = el.colWidths[c] ?? el.width / Math.max(1, el.cols);
1853
- const cell = el.cells[r]?.[c];
1854
- if (!cell?.mergedInto) {
1855
- const isHeader = el.headerRow !== false && r === 0;
1856
- const bgFill = cell?.bg || (isHeader ? el.headerBg || theme.colors.primary : r % 2 === 1 ? el.zebraBg || "#f8fafc" : "#ffffff");
1857
- const fgFill = cell?.color || (isHeader ? el.headerColor || "#ffffff" : theme.colors.text);
1858
- body.push(
1859
- `<rect x="${curX.toFixed(1)}" y="${curY.toFixed(1)}" width="${cw.toFixed(1)}" height="${rh.toFixed(1)}" fill="${escapeSvgXml(bgFill)}" stroke="${escapeSvgXml(el.borderColor || "#cbd5e1")}" stroke-width="0.8"/>`,
1860
- `<text x="${(curX + 8).toFixed(1)}" y="${(curY + rh / 2 + 4).toFixed(1)}" font-size="${cell?.fontSize ?? 11}" font-weight="${cell?.bold || isHeader ? "700" : "400"}" fill="${escapeSvgXml(fgFill)}">${escapeSvgXml(cell?.text ?? "")}</text>`
1861
- );
1862
- }
1863
- curX += cw;
2231
+ }
2232
+ } else if (base.type === "text" && fromEl.type === "text" && toEl.type === "text") {
2233
+ const tx = base;
2234
+ tx.fontSize = lerpNum(fromEl.fontSize ?? 18, toEl.fontSize ?? 18, easedT);
2235
+ const nextColor = interpolateHexColor(fromEl.color, toEl.color, easedT);
2236
+ if (nextColor) tx.color = nextColor;
2237
+ if (fromEl.fillColor || toEl.fillColor) {
2238
+ tx.fillColor = interpolateHexColor(fromEl.fillColor, toEl.fillColor, easedT);
2239
+ }
2240
+ if (fromEl.strokeColor || toEl.strokeColor) {
2241
+ tx.strokeColor = interpolateHexColor(fromEl.strokeColor, toEl.strokeColor, easedT);
2242
+ }
2243
+ if (fromEl.strokeWidth !== void 0 || toEl.strokeWidth !== void 0) {
2244
+ tx.strokeWidth = lerpNum(fromEl.strokeWidth ?? 0, toEl.strokeWidth ?? 0, easedT);
2245
+ }
2246
+ if (fromEl.borderRadius !== void 0 || toEl.borderRadius !== void 0) {
2247
+ tx.borderRadius = lerpNum(fromEl.borderRadius ?? 4, toEl.borderRadius ?? 4, easedT);
2248
+ }
2249
+ if (tx.paragraphs) {
2250
+ for (const p of tx.paragraphs) {
2251
+ for (const r of p.runs) {
2252
+ r.fontSize = tx.fontSize;
2253
+ if (nextColor) r.color = nextColor;
1864
2254
  }
1865
- curY += rh;
1866
- }
1867
- body.push(`</g>`);
1868
- } else if (el.type === "image" || el.type === "svg") {
1869
- if (el.src) {
1870
- body.push(
1871
- `<image href="${escapeSvgXml(el.src)}" x="${el.x}" y="${el.y}" width="${el.width}" height="${el.height}" preserveAspectRatio="${el.fit === "cover" ? "xMidYMid slice" : el.fit === "fill" ? "none" : "xMidYMid meet"}"${opacityAttr}/>`
1872
- );
1873
2255
  }
1874
- } else if (el.type === "codeBlock") {
1875
- const dark = el.codeTheme !== "light";
1876
- body.push(
1877
- `<g transform="translate(${el.x} ${el.y})"${opacityAttr}>`,
1878
- `<rect x="0" y="0" width="${el.width}" height="${el.height}" rx="8" fill="${dark ? "#0f172a" : "#f8fafc"}" stroke="#334155" stroke-width="1"/>`,
1879
- `<text x="12" y="20" font-size="10" font-weight="700" fill="#38bdf8">${escapeSvgXml(el.language.toUpperCase())}</text>`
1880
- );
1881
- el.code.split("\n").slice(0, 12).forEach((ln, idx) => {
1882
- body.push(
1883
- `<text x="12" y="${38 + idx * 15}" font-family="Menlo, Monaco, Consolas, monospace" font-size="${el.fontSize ?? 11}" fill="${dark ? "#e2e8f0" : "#1e293b"}">${escapeSvgXml(ln)}</text>`
1884
- );
1885
- });
1886
- body.push(`</g>`);
1887
- } else if (el.type === "sheetEmbed") {
1888
- body.push(
1889
- `<g transform="translate(${el.x} ${el.y})"${opacityAttr}>`,
1890
- `<rect x="0" y="0" width="${el.width}" height="${el.height}" rx="6" fill="#ffffff" stroke="#10b981" stroke-width="1.2"/>`,
1891
- `<rect x="0" y="0" width="${el.width}" height="24" rx="6" fill="${escapeSvgXml(el.accentColor || "#059669")}"/>`,
1892
- `<text x="10" y="16" font-size="11" font-weight="700" fill="#ffffff">${escapeSvgXml(el.title || "\u7535\u5B50\u8868\u683C\u6570\u636E\u5FEB\u7167")}</text>`,
1893
- `</g>`
1894
- );
1895
2256
  }
1896
- }
1897
- if (page.showSlideNumber !== false && typeof slideNumber === "number") {
1898
- body.push(
1899
- `<text x="${w - 22}" y="${h - 14}" text-anchor="end" font-size="10" fill="#64748b">${slideNumber}</text>`
2257
+ } else if (base.type === "connector" && fromEl.type === "connector" && toEl.type === "connector") {
2258
+ const c = base;
2259
+ c.strokeWidth = lerpNum(fromEl.strokeWidth ?? 2, toEl.strokeWidth ?? 2, easedT);
2260
+ c.strokeColor = interpolateHexColor(fromEl.strokeColor, toEl.strokeColor, easedT) ?? c.strokeColor;
2261
+ if (fromEl.labelColor || toEl.labelColor) {
2262
+ c.labelColor = interpolateHexColor(fromEl.labelColor, toEl.labelColor, easedT);
2263
+ }
2264
+ c.startX = lerpNum(fromEl.startX ?? fromEl.x, toEl.startX ?? toEl.x, easedT);
2265
+ c.startY = lerpNum(fromEl.startY ?? fromEl.y, toEl.startY ?? toEl.y, easedT);
2266
+ c.endX = lerpNum(
2267
+ fromEl.endX ?? fromEl.x + fromEl.width,
2268
+ toEl.endX ?? toEl.x + toEl.width,
2269
+ easedT
2270
+ );
2271
+ c.endY = lerpNum(
2272
+ fromEl.endY ?? fromEl.y + fromEl.height,
2273
+ toEl.endY ?? toEl.y + toEl.height,
2274
+ easedT
1900
2275
  );
2276
+ } else if ((base.type === "image" || base.type === "svg") && (fromEl.type === "image" || fromEl.type === "svg") && (toEl.type === "image" || toEl.type === "svg")) {
2277
+ const img = base;
2278
+ if (fromEl.borderRadius !== void 0 || toEl.borderRadius !== void 0) {
2279
+ img.borderRadius = lerpNum(fromEl.borderRadius ?? 0, toEl.borderRadius ?? 0, easedT);
2280
+ }
2281
+ } else if (base.type === "codeBlock" && fromEl.type === "codeBlock" && toEl.type === "codeBlock") {
2282
+ const cb = base;
2283
+ cb.fontSize = lerpNum(fromEl.fontSize ?? 12, toEl.fontSize ?? 12, easedT);
2284
+ } else if (base.type === "smartArt" && fromEl.type === "smartArt" && toEl.type === "smartArt") {
2285
+ const sa = base;
2286
+ if (fromEl.accentColor || toEl.accentColor) {
2287
+ sa.accentColor = interpolateHexColor(fromEl.accentColor, toEl.accentColor, easedT);
2288
+ }
2289
+ } else if (base.type === "sheetEmbed" && fromEl.type === "sheetEmbed" && toEl.type === "sheetEmbed") {
2290
+ const se = base;
2291
+ if (fromEl.accentColor || toEl.accentColor) {
2292
+ se.accentColor = interpolateHexColor(fromEl.accentColor, toEl.accentColor, easedT);
2293
+ }
2294
+ }
2295
+ return base;
2296
+ }
2297
+ function interpolateSlideBackground(fromBg, toBg, easedT) {
2298
+ if (!fromBg && !toBg) return void 0;
2299
+ if (fromBg?.type === "solid" && toBg?.type === "solid") {
2300
+ return {
2301
+ type: "solid",
2302
+ color: interpolateHexColor(fromBg.color, toBg.color, easedT) ?? toBg.color
2303
+ };
1901
2304
  }
1902
- return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${w} ${h}" width="${w}" height="${h}" font-family="${escapeSvgXml(theme.minorFont)}">${defs.length ? `<defs>${defs.join("")}</defs>` : ""}${body.join("")}</svg>`;
2305
+ if (fromBg?.type === "gradient" && toBg?.type === "gradient") {
2306
+ return {
2307
+ type: "gradient",
2308
+ gradientFrom: interpolateHexColor(fromBg.gradientFrom, toBg.gradientFrom, easedT),
2309
+ gradientTo: interpolateHexColor(fromBg.gradientTo, toBg.gradientTo, easedT),
2310
+ gradientAngleDeg: lerpNum(
2311
+ fromBg.gradientAngleDeg ?? 135,
2312
+ toBg.gradientAngleDeg ?? 135,
2313
+ easedT
2314
+ )
2315
+ };
2316
+ }
2317
+ return import_core2.Tools.deepClone(easedT < 0.5 ? fromBg ?? toBg : toBg ?? fromBg);
2318
+ }
2319
+ function computeMorphInterpolatedSlide(fromSlide, toSlide, progress) {
2320
+ const clamped = Math.max(0, Math.min(1, Number.isFinite(progress) ? progress : 1));
2321
+ const eased = cubicEaseInOut(clamped);
2322
+ const { pairs, unmatchedFrom, unmatchedTo } = matchMorphSlidePairs(fromSlide, toSlide);
2323
+ const elements = {};
2324
+ const elementOrder = [];
2325
+ const toPairMap = /* @__PURE__ */ new Map();
2326
+ for (const p of pairs) {
2327
+ toPairMap.set(p.toElement.id, p);
2328
+ }
2329
+ for (const outEl of unmatchedFrom) {
2330
+ const clone = import_core2.Tools.deepClone(outEl);
2331
+ const outId = elements[clone.id] ? `morph-out-${clone.id}` : clone.id;
2332
+ clone.id = outId;
2333
+ clone.opacity = lerpNum(outEl.opacity ?? 1, 0, eased, 4);
2334
+ elements[outId] = clone;
2335
+ elementOrder.push(outId);
2336
+ }
2337
+ const orderedTo = getOrderedVisibleElements(toSlide);
2338
+ const unmatchedToIds = new Set(unmatchedTo.map((e) => e.id));
2339
+ for (const toEl of orderedTo) {
2340
+ const pair = toPairMap.get(toEl.id);
2341
+ if (pair) {
2342
+ const morphed = interpolateElementPair(pair.fromElement, pair.toElement, eased);
2343
+ const id = elements[morphed.id] ? `morph-pair-${morphed.id}` : morphed.id;
2344
+ morphed.id = id;
2345
+ elements[id] = morphed;
2346
+ elementOrder.push(id);
2347
+ } else if (unmatchedToIds.has(toEl.id)) {
2348
+ const clone = import_core2.Tools.deepClone(toEl);
2349
+ const inId = elements[clone.id] ? `morph-in-${clone.id}` : clone.id;
2350
+ clone.id = inId;
2351
+ clone.opacity = lerpNum(0, toEl.opacity ?? 1, eased, 4);
2352
+ elements[inId] = clone;
2353
+ elementOrder.push(inId);
2354
+ }
2355
+ }
2356
+ const background = interpolateSlideBackground(fromSlide.background, toSlide.background, eased);
2357
+ return {
2358
+ id: `morph-${fromSlide.id}-${toSlide.id}`,
2359
+ title: clamped < 0.5 ? fromSlide.title : toSlide.title,
2360
+ layoutId: toSlide.layoutId,
2361
+ hidden: false,
2362
+ showSlideNumber: toSlide.showSlideNumber,
2363
+ speakerNotes: toSlide.speakerNotes,
2364
+ ...background ? { background } : {},
2365
+ transition: toSlide.transition ? import_core2.Tools.deepClone(toSlide.transition) : void 0,
2366
+ animations: [],
2367
+ elementOrder,
2368
+ elements
2369
+ };
1903
2370
  }
1904
2371
 
1905
2372
  // src/services/slide-selection.service.ts
1906
- var import_core2 = require("@univerjs/core");
2373
+ var import_core3 = require("@univerjs/core");
1907
2374
  var import_rxjs2 = require("rxjs");
1908
- var ISlideSelectionService = (0, import_core2.createIdentifier)(
2375
+ var ISlideSelectionService = (0, import_core3.createIdentifier)(
1909
2376
  "yudao.slides.selection-service"
1910
2377
  );
1911
- var SlideSelectionService = class extends import_core2.Disposable {
2378
+ var SlideSelectionService = class extends import_core3.Disposable {
1912
2379
  constructor() {
1913
2380
  super(...arguments);
1914
2381
  this._state$ = new import_rxjs2.BehaviorSubject({
@@ -1927,7 +2394,10 @@ var SlideSelectionService = class extends import_core2.Disposable {
1927
2394
  presenterMode: "presenter",
1928
2395
  presenterSlideIndex: 0,
1929
2396
  inspectorTab: "page",
1930
- lastFindReplaceCount: 0
2397
+ lastFindReplaceCount: 0,
2398
+ masterViewOpen: false,
2399
+ activeMasterId: null,
2400
+ activeLayoutId: null
1931
2401
  });
1932
2402
  this.state$ = this._state$.asObservable();
1933
2403
  }
@@ -2018,17 +2488,36 @@ var SlideSelectionService = class extends import_core2.Disposable {
2018
2488
  setInspectorTab(tab) {
2019
2489
  this._patch({ inspectorTab: tab });
2020
2490
  }
2491
+ setMasterViewOpen(open, target) {
2492
+ this._patch({
2493
+ masterViewOpen: open,
2494
+ selectedElementIds: [],
2495
+ editingElementId: null,
2496
+ editingTableCell: null,
2497
+ ...target?.masterId !== void 0 ? { activeMasterId: target.masterId } : {},
2498
+ ...target?.layoutId !== void 0 ? { activeLayoutId: target.layoutId } : {}
2499
+ });
2500
+ }
2501
+ setActiveMasterTarget(masterId, layoutId = null) {
2502
+ this._patch({
2503
+ activeMasterId: masterId,
2504
+ activeLayoutId: layoutId,
2505
+ selectedElementIds: [],
2506
+ editingElementId: null,
2507
+ editingTableCell: null
2508
+ });
2509
+ }
2021
2510
  };
2022
2511
 
2023
2512
  // src/services/slide-io.service.ts
2024
- var import_core6 = require("@univerjs/core");
2513
+ var import_core7 = require("@univerjs/core");
2025
2514
  var import_rxjs3 = require("rxjs");
2026
2515
 
2027
2516
  // src/exporter/pptx-codec.ts
2028
- var import_core4 = require("@univerjs/core");
2517
+ var import_core5 = require("@univerjs/core");
2029
2518
 
2030
2519
  // src/template/slide-template-engine.ts
2031
- var import_core3 = require("@univerjs/core");
2520
+ var import_core4 = require("@univerjs/core");
2032
2521
  var SCALAR_TOKEN_RE = /\$\{\s*([a-zA-Z0-9_$.#-]+)\s*\}/g;
2033
2522
  var LOOP_TOKEN_RE = /#\{\s*([a-zA-Z0-9_$.#-]+)\s*\}/g;
2034
2523
  function extractSlideDatasetCodes(snapshot) {
@@ -2167,7 +2656,7 @@ function substituteScalarTokens(text, datasets, fallback, rowContext) {
2167
2656
  return result;
2168
2657
  }
2169
2658
  function applyDatasetToChart(chart, datasets, palette, fallback) {
2170
- const next = import_core3.Tools.deepClone(chart);
2659
+ const next = import_core4.Tools.deepClone(chart);
2171
2660
  if (next.title) {
2172
2661
  next.title = substituteScalarTokens(next.title, datasets, fallback);
2173
2662
  }
@@ -2209,7 +2698,7 @@ function applyDatasetToChart(chart, datasets, palette, fallback) {
2209
2698
  }
2210
2699
  function expandTableWithDataset(table, datasets, slideHeightPt, options) {
2211
2700
  const fallback = options?.missingValueFallback ?? "";
2212
- const baseTable = import_core3.Tools.deepClone(table);
2701
+ const baseTable = import_core4.Tools.deepClone(table);
2213
2702
  let templateRowIdx = -1;
2214
2703
  let detectedLoopCode = baseTable.datasetLoopCode ?? null;
2215
2704
  for (let r = 0; r < baseTable.cells.length; r++) {
@@ -2240,14 +2729,14 @@ function expandTableWithDataset(table, datasets, slideHeightPt, options) {
2240
2729
  const records = Array.isArray(rawList) ? rawList.filter((item) => Boolean(item && typeof item === "object")) : [];
2241
2730
  const headerRowsCells = baseTable.cells.slice(0, templateRowIdx).map(
2242
2731
  (row) => row.map((cell) => ({
2243
- ...import_core3.Tools.deepClone(cell),
2732
+ ...import_core4.Tools.deepClone(cell),
2244
2733
  text: substituteScalarTokens(cell.text, datasets, fallback)
2245
2734
  }))
2246
2735
  );
2247
2736
  const headerRowHeights = baseTable.rowHeights.slice(0, templateRowIdx);
2248
2737
  const footerRowsCells = baseTable.cells.slice(templateRowIdx + 1).map(
2249
2738
  (row) => row.map((cell) => ({
2250
- ...import_core3.Tools.deepClone(cell),
2739
+ ...import_core4.Tools.deepClone(cell),
2251
2740
  text: substituteScalarTokens(cell.text, datasets, fallback)
2252
2741
  }))
2253
2742
  );
@@ -2256,7 +2745,7 @@ function expandTableWithDataset(table, datasets, slideHeightPt, options) {
2256
2745
  const templateRowH = baseTable.rowHeights[templateRowIdx] ?? Math.max(28, Math.round(baseTable.height / Math.max(1, baseTable.rows)));
2257
2746
  const expandedDetailRows = records.map(
2258
2747
  (record, rIdx) => templateRow.map((tplCell) => ({
2259
- ...import_core3.Tools.deepClone(tplCell),
2748
+ ...import_core4.Tools.deepClone(tplCell),
2260
2749
  text: substituteScalarTokens(tplCell.text, datasets, fallback, {
2261
2750
  record,
2262
2751
  rowIndex: rIdx,
@@ -2297,9 +2786,9 @@ function expandTableWithDataset(table, datasets, slideHeightPt, options) {
2297
2786
  const slice = expandedDetailRows.slice(offset, offset + maxDetailRows);
2298
2787
  const isLastChunk = offset + maxDetailRows >= expandedDetailRows.length;
2299
2788
  const chunkCells = [
2300
- ...import_core3.Tools.deepClone(headerRowsCells),
2789
+ ...import_core4.Tools.deepClone(headerRowsCells),
2301
2790
  ...slice,
2302
- ...isLastChunk ? import_core3.Tools.deepClone(footerRowsCells) : []
2791
+ ...isLastChunk ? import_core4.Tools.deepClone(footerRowsCells) : []
2303
2792
  ];
2304
2793
  const chunkHeights = [
2305
2794
  ...headerRowHeights,
@@ -2307,7 +2796,7 @@ function expandTableWithDataset(table, datasets, slideHeightPt, options) {
2307
2796
  ...isLastChunk ? footerRowHeights : []
2308
2797
  ];
2309
2798
  chunks.push({
2310
- ...import_core3.Tools.deepClone(baseTable),
2799
+ ...import_core4.Tools.deepClone(baseTable),
2311
2800
  rows: chunkCells.length,
2312
2801
  cells: chunkCells,
2313
2802
  rowHeights: chunkHeights,
@@ -2318,7 +2807,7 @@ function expandTableWithDataset(table, datasets, slideHeightPt, options) {
2318
2807
  }
2319
2808
  function substituteElementScalars(el, datasets, palette, fallback) {
2320
2809
  if (el.type === "text") {
2321
- const next = import_core3.Tools.deepClone(el);
2810
+ const next = import_core4.Tools.deepClone(el);
2322
2811
  next.text = substituteScalarTokens(next.text, datasets, fallback);
2323
2812
  if (next.paragraphs) {
2324
2813
  for (const p of next.paragraphs) {
@@ -2333,12 +2822,12 @@ function substituteElementScalars(el, datasets, palette, fallback) {
2333
2822
  return next;
2334
2823
  }
2335
2824
  if (el.type === "shape") {
2336
- const next = import_core3.Tools.deepClone(el);
2825
+ const next = import_core4.Tools.deepClone(el);
2337
2826
  if (next.text) next.text = substituteScalarTokens(next.text, datasets, fallback);
2338
2827
  return next;
2339
2828
  }
2340
2829
  if (el.type === "connector") {
2341
- const next = import_core3.Tools.deepClone(el);
2830
+ const next = import_core4.Tools.deepClone(el);
2342
2831
  if (next.label) next.label = substituteScalarTokens(next.label, datasets, fallback);
2343
2832
  return next;
2344
2833
  }
@@ -2346,7 +2835,7 @@ function substituteElementScalars(el, datasets, palette, fallback) {
2346
2835
  return applyDatasetToChart(el, datasets, palette, fallback);
2347
2836
  }
2348
2837
  if (el.type === "smartArt") {
2349
- const next = import_core3.Tools.deepClone(el);
2838
+ const next = import_core4.Tools.deepClone(el);
2350
2839
  if (next.title) next.title = substituteScalarTokens(next.title, datasets, fallback);
2351
2840
  const walk = (items) => {
2352
2841
  for (const item of items) {
@@ -2359,7 +2848,7 @@ function substituteElementScalars(el, datasets, palette, fallback) {
2359
2848
  return next;
2360
2849
  }
2361
2850
  if (el.type === "sheetEmbed") {
2362
- const next = import_core3.Tools.deepClone(el);
2851
+ const next = import_core4.Tools.deepClone(el);
2363
2852
  if (next.title) next.title = substituteScalarTokens(next.title, datasets, fallback);
2364
2853
  next.headers = next.headers.map((h) => substituteScalarTokens(h, datasets, fallback));
2365
2854
  next.rows = next.rows.map(
@@ -2367,10 +2856,10 @@ function substituteElementScalars(el, datasets, palette, fallback) {
2367
2856
  );
2368
2857
  return next;
2369
2858
  }
2370
- return import_core3.Tools.deepClone(el);
2859
+ return import_core4.Tools.deepClone(el);
2371
2860
  }
2372
2861
  function compileSlidesWithDataset(snapshot, datasets, options) {
2373
- const result = import_core3.Tools.deepClone(snapshot);
2862
+ const result = import_core4.Tools.deepClone(snapshot);
2374
2863
  const fallback = options?.missingValueFallback ?? "";
2375
2864
  const suffixFn = options?.continuationTitleSuffix ?? ((pageIdx, total) => ` (\u7EED ${pageIdx}/${total})`);
2376
2865
  const palette = resolveChartPalette(void 0, result.theme);
@@ -2381,7 +2870,7 @@ function compileSlidesWithDataset(snapshot, datasets, options) {
2381
2870
  for (const sid of result.slideOrder) {
2382
2871
  const origSlide = result.slides[sid];
2383
2872
  if (!origSlide) continue;
2384
- const baseSlide = import_core3.Tools.deepClone(origSlide);
2873
+ const baseSlide = import_core4.Tools.deepClone(origSlide);
2385
2874
  baseSlide.title = substituteScalarTokens(baseSlide.title, datasets, fallback);
2386
2875
  if (baseSlide.speakerNotes) {
2387
2876
  baseSlide.speakerNotes = substituteScalarTokens(baseSlide.speakerNotes, datasets, fallback);
@@ -2414,17 +2903,17 @@ function compileSlidesWithDataset(snapshot, datasets, options) {
2414
2903
  const spawnedIds = [];
2415
2904
  for (let chunkIdx = 1; chunkIdx < totalCont; chunkIdx++) {
2416
2905
  const suffix = suffixFn(chunkIdx + 1, totalCont);
2417
- const contSlideId = `${sid}-cont-${chunkIdx + 1}-${(0, import_core3.generateRandomId)(4)}`;
2418
- const clonedSlide = import_core3.Tools.deepClone(baseSlide);
2906
+ const contSlideId = `${sid}-cont-${chunkIdx + 1}-${(0, import_core4.generateRandomId)(4)}`;
2907
+ const clonedSlide = import_core4.Tools.deepClone(baseSlide);
2419
2908
  clonedSlide.id = contSlideId;
2420
2909
  clonedSlide.title = `${baseSlide.title}${suffix}`;
2421
2910
  const idRemap = /* @__PURE__ */ new Map();
2422
2911
  const newElements = {};
2423
2912
  const newOrder = [];
2424
2913
  for (const oldElId of baseSlide.elementOrder) {
2425
- const srcEl = oldElId === paginatedTableId ? import_core3.Tools.deepClone(paginatedChunks[chunkIdx]) : import_core3.Tools.deepClone(baseSlide.elements[oldElId]);
2914
+ const srcEl = oldElId === paginatedTableId ? import_core4.Tools.deepClone(paginatedChunks[chunkIdx]) : import_core4.Tools.deepClone(baseSlide.elements[oldElId]);
2426
2915
  if (!srcEl) continue;
2427
- const newElId = `el-${(0, import_core3.generateRandomId)(6)}`;
2916
+ const newElId = `el-${(0, import_core4.generateRandomId)(6)}`;
2428
2917
  idRemap.set(oldElId, newElId);
2429
2918
  srcEl.id = newElId;
2430
2919
  if (srcEl.type === "text" && (srcEl.placeholderRole === "title" || srcEl.y < 80 && (srcEl.fontSize ?? 18) >= 22)) {
@@ -3337,11 +3826,14 @@ function buildTransitionXml(tr) {
3337
3826
  const spd = durMs <= 300 ? "fast" : durMs >= 800 ? "slow" : "med";
3338
3827
  const advAttr = tr.advanceAfterMs && tr.advanceAfterMs > 0 ? ` advTm="${Math.round(tr.advanceAfterMs)}"` : "";
3339
3828
  const dir = tr.direction === "right" ? "r" : tr.direction === "up" ? "u" : tr.direction === "down" ? "d" : "l";
3829
+ if (tr.type === "morph") {
3830
+ return `<p:transition xmlns:p159="http://schemas.microsoft.com/office/powerpoint/2015/09/main" spd="${spd}"${advAttr}><p159:morph option="byObject"/></p:transition>`;
3831
+ }
3340
3832
  let inner = "<p:fade/>";
3341
3833
  if (tr.type === "push") inner = `<p:push dir="${dir}"/>`;
3342
3834
  else if (tr.type === "wipe") inner = `<p:wipe dir="${dir}"/>`;
3343
3835
  else if (tr.type === "split") inner = `<p:split orient="horz" dir="out"/>`;
3344
- else if (tr.type === "zoom" || tr.type === "morph") inner = `<p:zoom dir="in"/>`;
3836
+ else if (tr.type === "zoom") inner = `<p:zoom dir="in"/>`;
3345
3837
  return `<p:transition spd="${spd}"${advAttr}>${inner}</p:transition>`;
3346
3838
  }
3347
3839
  function buildTimingXml(animations, elIdToSpId) {
@@ -3397,7 +3889,7 @@ function decodeElementMetaDescr(descr) {
3397
3889
  }
3398
3890
  }
3399
3891
  function exportPptxBytesSync(rawSnapshot, options) {
3400
- const snapshot = options?.datasets ? compileSlidesWithDataset(rawSnapshot, options.datasets, options.templateOptions) : import_core4.Tools.deepClone(rawSnapshot);
3892
+ const snapshot = options?.datasets ? compileSlidesWithDataset(rawSnapshot, options.datasets, options.templateOptions) : import_core5.Tools.deepClone(rawSnapshot);
3401
3893
  const files = [];
3402
3894
  const mediaExts = /* @__PURE__ */ new Set();
3403
3895
  let mediaCounter = 0;
@@ -3431,6 +3923,60 @@ function exportPptxBytesSync(rawSnapshot, options) {
3431
3923
  target: "../slideLayouts/slideLayout1.xml"
3432
3924
  }
3433
3925
  ];
3926
+ let actionCounter = 0;
3927
+ const buildCNvPrTag = (spId, el, metaPayload) => {
3928
+ let cNvName = el.name || el.type;
3929
+ let mergedMeta = metaPayload ? { ...metaPayload } : void 0;
3930
+ if (el.morphName && el.morphName.trim().length > 0) {
3931
+ const cleanMorph = el.morphName.trim().startsWith("!!") ? el.morphName.trim().slice(2).trim() : el.morphName.trim();
3932
+ if (cleanMorph) {
3933
+ cNvName = `!!${cleanMorph}`;
3934
+ if (el.name && el.name !== cNvName) {
3935
+ mergedMeta = { ...mergedMeta ?? {}, displayName: el.name };
3936
+ }
3937
+ }
3938
+ }
3939
+ const descrAttr = mergedMeta ? ` descr="${escapeXml(encodeElementMetaDescr(mergedMeta))}"` : "";
3940
+ if (!el.action || el.action.type === "none") {
3941
+ return `<p:cNvPr id="${spId}" name="${escapeXml(cNvName)}"${descrAttr}/>`;
3942
+ }
3943
+ actionCounter += 1;
3944
+ const actRelId = `rIdAct${actionCounter}`;
3945
+ const hlinkRelType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";
3946
+ const tooltipAttr = el.action.tooltip ? ` tooltip="${escapeXml(el.action.tooltip)}"` : "";
3947
+ let hlinkAttrs = "";
3948
+ if (el.action.type === "nextSlide" || el.action.type === "prevSlide" || el.action.type === "firstSlide" || el.action.type === "lastSlide" || el.action.type === "endShow") {
3949
+ const jumpToken = el.action.type === "nextSlide" ? "nextslide" : el.action.type === "prevSlide" ? "previousslide" : el.action.type === "firstSlide" ? "firstslide" : el.action.type === "lastSlide" ? "lastslide" : "endshow";
3950
+ const actionUri = `ppaction://hlinkshowjump?jump=${jumpToken}`;
3951
+ slideRels.push({
3952
+ id: actRelId,
3953
+ type: hlinkRelType,
3954
+ target: actionUri,
3955
+ targetMode: "External"
3956
+ });
3957
+ hlinkAttrs = `r:id="${actRelId}" action="${actionUri}"${tooltipAttr}`;
3958
+ } else if (el.action.type === "slide") {
3959
+ const targetIdx = el.action.targetSlideId ? snapshot.slideOrder.indexOf(el.action.targetSlideId) : 0;
3960
+ const targetSlideNum = (targetIdx >= 0 ? targetIdx : 0) + 1;
3961
+ slideRels.push({
3962
+ id: actRelId,
3963
+ type: hlinkRelType,
3964
+ target: `slide${targetSlideNum}.xml`
3965
+ });
3966
+ hlinkAttrs = `r:id="${actRelId}" action="ppaction://hlinksldjump"${tooltipAttr}`;
3967
+ } else if (el.action.type === "url") {
3968
+ const extUrl = el.action.url || "https://example.com";
3969
+ slideRels.push({
3970
+ id: actRelId,
3971
+ type: hlinkRelType,
3972
+ target: extUrl,
3973
+ targetMode: "External"
3974
+ });
3975
+ hlinkAttrs = `r:id="${actRelId}"${tooltipAttr}`;
3976
+ }
3977
+ const hoverXml = el.action.trigger === "hover" ? `<a:hlinkHover ${hlinkAttrs}/>` : "";
3978
+ return `<p:cNvPr id="${spId}" name="${escapeXml(cNvName)}"${descrAttr}><a:hlinkClick ${hlinkAttrs}/>${hoverXml}</p:cNvPr>`;
3979
+ };
3434
3980
  const addMedia = (src) => {
3435
3981
  mediaCounter += 1;
3436
3982
  const decoded = decodeImageSource(src);
@@ -3475,22 +4021,19 @@ function exportPptxBytesSync(rawSnapshot, options) {
3475
4021
  const extCx = Math.max(12700, ptToEmu(el.width));
3476
4022
  const extCy = Math.max(12700, ptToEmu(el.height));
3477
4023
  const rotAttr = el.rotation ? ` rot="${Math.round(el.rotation * 6e4)}"` : "";
3478
- const nameAttr = escapeXml(el.name || el.type);
3479
4024
  if (el.type === "text") {
3480
4025
  const fillXml = el.fillColor ? `<a:solidFill><a:srgbClr val="${normalizeHex6(el.fillColor, "FFFFFF")}"/></a:solidFill>` : "<a:noFill/>";
3481
4026
  const lnXml = el.strokeColor && (el.strokeWidth ?? 0) > 0 ? `<a:ln w="${ptToEmu(el.strokeWidth ?? 1)}"><a:solidFill><a:srgbClr val="${normalizeHex6(el.strokeColor, "CBD5E1")}"/></a:solidFill></a:ln>` : "<a:ln><a:noFill/></a:ln>";
3482
- const descrAttr = el.wordArt?.enabled || el.placeholderRole || el.datasetBinding ? ` descr="${escapeXml(
3483
- encodeElementMetaDescr({
3484
- kind: "text",
3485
- id: el.id,
3486
- wordArt: el.wordArt,
3487
- placeholderRole: el.placeholderRole,
3488
- datasetBinding: el.datasetBinding
3489
- })
3490
- )}"` : "";
4027
+ const textMeta = el.wordArt?.enabled || el.placeholderRole || el.datasetBinding ? {
4028
+ kind: "text",
4029
+ id: el.id,
4030
+ wordArt: el.wordArt,
4031
+ placeholderRole: el.placeholderRole,
4032
+ datasetBinding: el.datasetBinding
4033
+ } : void 0;
3491
4034
  spTreeItems.push(`<p:sp>
3492
4035
  <p:nvSpPr>
3493
- <p:cNvPr id="${spId}" name="${nameAttr}"${descrAttr}/>
4036
+ ${buildCNvPrTag(spId, el, textMeta)}
3494
4037
  <p:cNvSpPr txBox="1"/>
3495
4038
  <p:nvPr/>
3496
4039
  </p:nvSpPr>
@@ -3522,7 +4065,7 @@ function exportPptxBytesSync(rawSnapshot, options) {
3522
4065
  </p:txBody>` : "<p:txBody><a:bodyPr/><a:lstStyle/><a:p/></p:txBody>";
3523
4066
  spTreeItems.push(`<p:sp>
3524
4067
  <p:nvSpPr>
3525
- <p:cNvPr id="${spId}" name="${nameAttr}" descr="${escapeXml(encodeElementMetaDescr({ kind: "shape", id: el.id, cornerRadius: el.cornerRadius }))}"/>
4068
+ ${buildCNvPrTag(spId, el, { kind: "shape", id: el.id, cornerRadius: el.cornerRadius })}
3526
4069
  <p:cNvSpPr/>
3527
4070
  <p:nvPr/>
3528
4071
  </p:nvSpPr>
@@ -3548,7 +4091,9 @@ function exportPptxBytesSync(rawSnapshot, options) {
3548
4091
  const headEnd = el.startArrow ? '<a:headEnd type="triangle"/>' : "";
3549
4092
  const tailEnd = el.endArrow ? '<a:tailEnd type="triangle"/>' : "";
3550
4093
  const dashXml = el.strokeDash === "dashed" ? '<a:prstDash val="dash"/>' : el.strokeDash === "dotted" ? '<a:prstDash val="sysDot"/>' : "";
3551
- const descr = encodeElementMetaDescr({
4094
+ spTreeItems.push(`<p:cxnSp>
4095
+ <p:nvCxnSpPr>
4096
+ ${buildCNvPrTag(spId, el, {
3552
4097
  kind: "connector",
3553
4098
  id: el.id,
3554
4099
  label: el.label,
@@ -3559,10 +4104,7 @@ function exportPptxBytesSync(rawSnapshot, options) {
3559
4104
  startY: el.startY,
3560
4105
  endX: el.endX,
3561
4106
  endY: el.endY
3562
- });
3563
- spTreeItems.push(`<p:cxnSp>
3564
- <p:nvCxnSpPr>
3565
- <p:cNvPr id="${spId}" name="${nameAttr}" descr="${escapeXml(descr)}"/>
4107
+ })}
3566
4108
  <p:cNvCxnSpPr>${stCxn}${endCxn}</p:cNvCxnSpPr>
3567
4109
  <p:nvPr/>
3568
4110
  </p:nvCxnSpPr>
@@ -3578,16 +4120,15 @@ function exportPptxBytesSync(rawSnapshot, options) {
3578
4120
  } else if (el.type === "image" || el.type === "svg") {
3579
4121
  const src = el.svgContent ? svgToDataUri(el.svgContent) : el.src;
3580
4122
  const rId = addMedia(src);
3581
- const descr = encodeElementMetaDescr({
4123
+ spTreeItems.push(`<p:pic>
4124
+ <p:nvPicPr>
4125
+ ${buildCNvPrTag(spId, el, {
3582
4126
  kind: el.type,
3583
4127
  id: el.id,
3584
4128
  fit: el.fit,
3585
4129
  crop: el.crop,
3586
4130
  altText: el.altText
3587
- });
3588
- spTreeItems.push(`<p:pic>
3589
- <p:nvPicPr>
3590
- <p:cNvPr id="${spId}" name="${nameAttr}" descr="${escapeXml(descr)}"/>
4131
+ })}
3591
4132
  <p:cNvPicPr><a:picLocks noChangeAspect="1"/></p:cNvPicPr>
3592
4133
  <p:nvPr/>
3593
4134
  </p:nvPicPr>
@@ -3651,7 +4192,9 @@ function exportPptxBytesSync(rawSnapshot, options) {
3651
4192
  }).join("");
3652
4193
  return `<a:tr h="${ptToEmu(rh)}">${cellsXml}</a:tr>`;
3653
4194
  }).join("");
3654
- const descr = encodeElementMetaDescr({
4195
+ spTreeItems.push(`<p:graphicFrame>
4196
+ <p:nvGraphicFramePr>
4197
+ ${buildCNvPrTag(spId, el, {
3655
4198
  kind: "table",
3656
4199
  id: el.id,
3657
4200
  headerRow: el.headerRow,
@@ -3660,10 +4203,7 @@ function exportPptxBytesSync(rawSnapshot, options) {
3660
4203
  borderColor: el.borderColor,
3661
4204
  zebraBg: el.zebraBg,
3662
4205
  datasetLoopCode: el.datasetLoopCode
3663
- });
3664
- spTreeItems.push(`<p:graphicFrame>
3665
- <p:nvGraphicFramePr>
3666
- <p:cNvPr id="${spId}" name="${nameAttr}" descr="${escapeXml(descr)}"/>
4206
+ })}
3667
4207
  <p:cNvGraphicFramePr><a:graphicFrameLocks noGrp="1"/></p:cNvGraphicFramePr>
3668
4208
  <p:nvPr/>
3669
4209
  </p:nvGraphicFramePr>
@@ -3694,7 +4234,9 @@ function exportPptxBytesSync(rawSnapshot, options) {
3694
4234
  type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart",
3695
4235
  target: `../charts/${chartFile}`
3696
4236
  });
3697
- const descr = encodeElementMetaDescr({
4237
+ spTreeItems.push(`<p:graphicFrame>
4238
+ <p:nvGraphicFramePr>
4239
+ ${buildCNvPrTag(spId, el, {
3698
4240
  kind: "chart",
3699
4241
  id: el.id,
3700
4242
  datasetCode: el.datasetCode,
@@ -3702,10 +4244,7 @@ function exportPptxBytesSync(rawSnapshot, options) {
3702
4244
  valueFields: el.valueFields,
3703
4245
  showGrid: el.showGrid,
3704
4246
  showValues: el.showValues
3705
- });
3706
- spTreeItems.push(`<p:graphicFrame>
3707
- <p:nvGraphicFramePr>
3708
- <p:cNvPr id="${spId}" name="${nameAttr}" descr="${escapeXml(descr)}"/>
4247
+ })}
3709
4248
  <p:cNvGraphicFramePr><a:graphicFrameLocks noGrp="1"/></p:cNvGraphicFramePr>
3710
4249
  <p:nvPr/>
3711
4250
  </p:nvGraphicFramePr>
@@ -3716,15 +4255,17 @@ function exportPptxBytesSync(rawSnapshot, options) {
3716
4255
  </a:graphicData>
3717
4256
  </a:graphic>
3718
4257
  </p:graphicFrame>`);
3719
- } else if (el.type === "smartArt" || el.type === "codeBlock" || el.type === "sheetEmbed") {
4258
+ } else if (el.type === "smartArt" || el.type === "codeBlock" || el.type === "sheetEmbed" || el.type === "video" || el.type === "audio") {
3720
4259
  let svgDataUri;
3721
4260
  if (el.type === "smartArt") {
3722
4261
  svgDataUri = renderSlideSmartArtToSvgDataUri(el, snapshot.theme);
4262
+ } else if (el.type === "video" || el.type === "audio") {
4263
+ svgDataUri = renderSlideMediaToSvgDataUri(el, snapshot.theme);
3723
4264
  } else if (el.type === "codeBlock") {
3724
4265
  const lines = el.code.split("\n").slice(0, 12);
3725
4266
  const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${el.width} ${el.height}" width="${el.width}" height="${el.height}"><rect width="${el.width}" height="${el.height}" rx="8" fill="#0f172a"/>${lines.map((l, idx) => `<text x="14" y="${28 + idx * 16}" font-family="monospace" font-size="11" fill="#e2e8f0">${escapeXml(l)}</text>`).join("")}</svg>`;
3726
4267
  svgDataUri = svgToDataUri(svg);
3727
- } else {
4268
+ } else if (el.type === "sheetEmbed") {
3728
4269
  const fakeChart = {
3729
4270
  id: el.id,
3730
4271
  type: "chart",
@@ -3741,12 +4282,13 @@ function exportPptxBytesSync(rawSnapshot, options) {
3741
4282
  }))
3742
4283
  };
3743
4284
  svgDataUri = svgToDataUri(renderSlideChartToSvg(fakeChart, snapshot.theme));
4285
+ } else {
4286
+ svgDataUri = renderSlideMediaToSvgDataUri(el, snapshot.theme);
3744
4287
  }
3745
4288
  const rId = addMedia(svgDataUri);
3746
- const descr = encodeElementMetaDescr({ kind: "richElement", element: el });
3747
4289
  spTreeItems.push(`<p:pic>
3748
4290
  <p:nvPicPr>
3749
- <p:cNvPr id="${spId}" name="${nameAttr}" descr="${escapeXml(descr)}"/>
4291
+ ${buildCNvPrTag(spId, el, { kind: "richElement", element: el })}
3750
4292
  <p:cNvPicPr><a:picLocks noChangeAspect="1"/></p:cNvPicPr>
3751
4293
  <p:nvPr/>
3752
4294
  </p:nvPicPr>
@@ -3822,7 +4364,7 @@ function exportPptxBytesSync(rawSnapshot, options) {
3822
4364
  name: `ppt/slides/_rels/slide${slideNum}.xml.rels`,
3823
4365
  content: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
3824
4366
  <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
3825
- ${slideRels.map((r) => `<Relationship Id="${r.id}" Type="${r.type}" Target="${r.target}"/>`).join("\n ")}
4367
+ ${slideRels.map((r) => `<Relationship Id="${r.id}" Type="${r.type}" Target="${escapeXml(r.target)}"${r.targetMode ? ` TargetMode="${r.targetMode}"` : ""}/>`).join("\n ")}
3826
4368
  </Relationships>`
3827
4369
  });
3828
4370
  });
@@ -3887,9 +4429,10 @@ function exportPptxBytesSync(rawSnapshot, options) {
3887
4429
  ${presRels.join("\n ")}
3888
4430
  </Relationships>`
3889
4431
  });
4432
+ const showPrXml = snapshot.slideshowSettings?.loopContinuously ? `<p:showPr loop="1"/>` : "";
3890
4433
  files.push({
3891
4434
  name: "ppt/presProps.xml",
3892
- content: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><p:presentationPr xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main"/>`
4435
+ content: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><p:presentationPr xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main">${showPrXml}</p:presentationPr>`
3893
4436
  });
3894
4437
  files.push({
3895
4438
  name: "ppt/viewProps.xml",
@@ -3903,6 +4446,43 @@ function exportPptxBytesSync(rawSnapshot, options) {
3903
4446
  name: "ppt/theme/theme1.xml",
3904
4447
  content: buildThemeXml(snapshot.theme)
3905
4448
  });
4449
+ const primaryMaster = snapshot.masters[0];
4450
+ const masterSpItems = [];
4451
+ if (primaryMaster?.masterElements && primaryMaster.masterElements.length > 0) {
4452
+ primaryMaster.masterElements.forEach((mEl, mIdx) => {
4453
+ if (!mEl || mEl.hidden) return;
4454
+ const mSpId = 100 + mIdx;
4455
+ const mOffX = ptToEmu(mEl.x);
4456
+ const mOffY = ptToEmu(mEl.y);
4457
+ const mExtCx = Math.max(12700, ptToEmu(mEl.width));
4458
+ const mExtCy = Math.max(12700, ptToEmu(mEl.height));
4459
+ if (mEl.type === "text") {
4460
+ masterSpItems.push(`<p:sp>
4461
+ <p:nvSpPr><p:cNvPr id="${mSpId}" name="${escapeXml(mEl.name || "MasterText")}"/><p:cNvSpPr txBox="1"/><p:nvPr/></p:nvSpPr>
4462
+ <p:spPr><a:xfrm><a:off x="${mOffX}" y="${mOffY}"/><a:ext cx="${mExtCx}" cy="${mExtCy}"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom><a:noFill/></p:spPr>
4463
+ ${buildTextBodyXml(mEl, snapshot.theme)}
4464
+ </p:sp>`);
4465
+ } else if (mEl.type === "shape") {
4466
+ const prst = SHAPE_TO_OOXML_PRST[mEl.shapeType] ?? "rect";
4467
+ masterSpItems.push(`<p:sp>
4468
+ <p:nvSpPr><p:cNvPr id="${mSpId}" name="${escapeXml(mEl.name || "MasterShape")}"/><p:cNvSpPr/><p:nvPr/></p:nvSpPr>
4469
+ <p:spPr>
4470
+ <a:xfrm><a:off x="${mOffX}" y="${mOffY}"/><a:ext cx="${mExtCx}" cy="${mExtCy}"/></a:xfrm>
4471
+ <a:prstGeom prst="${prst}"><a:avLst/></a:prstGeom>
4472
+ <a:solidFill><a:srgbClr val="${normalizeHex6(mEl.fillColor, "2563EB")}"/></a:solidFill>
4473
+ </p:spPr>
4474
+ ${mEl.text ? `<p:txBody><a:bodyPr anchor="ctr"/><a:lstStyle/><a:p><a:pPr algn="ctr"/><a:r><a:rPr sz="${Math.round((mEl.fontSize ?? 14) * 100)}"/><a:t>${escapeXml(mEl.text)}</a:t></a:r></a:p></p:txBody>` : "<p:txBody><a:bodyPr/><a:lstStyle/><a:p/></p:txBody>"}
4475
+ </p:sp>`);
4476
+ }
4477
+ });
4478
+ }
4479
+ const masterMetaDescr = escapeXml(
4480
+ encodeElementMetaDescr({
4481
+ masters: snapshot.masters,
4482
+ layouts: snapshot.layouts,
4483
+ slideshowSettings: snapshot.slideshowSettings
4484
+ })
4485
+ );
3906
4486
  files.push({
3907
4487
  name: "ppt/slideMasters/slideMaster1.xml",
3908
4488
  content: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
@@ -3910,8 +4490,9 @@ function exportPptxBytesSync(rawSnapshot, options) {
3910
4490
  <p:cSld>
3911
4491
  <p:bg><p:bgRef idx="1001"><a:schemeClr val="bg1"/></p:bgRef></p:bg>
3912
4492
  <p:spTree>
3913
- <p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr>
4493
+ <p:nvGrpSpPr><p:cNvPr id="1" name="" descr="${masterMetaDescr}"/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr>
3914
4494
  <p:grpSpPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/><a:chOff x="0" y="0"/><a:chExt cx="0" cy="0"/></a:xfrm></p:grpSpPr>
4495
+ ${masterSpItems.join("\n")}
3915
4496
  </p:spTree>
3916
4497
  </p:cSld>
3917
4498
  <p:clrMap bg1="lt1" tx1="dk1" bg2="lt2" tx2="dk2" accent1="accent1" accent2="accent2" accent3="accent3" accent4="accent4" accent5="accent5" accent6="accent6" hlink="hlink" folHlink="folHlink"/>
@@ -3983,7 +4564,8 @@ function parseRelsXml(xml) {
3983
4564
  const id = getAttr(attrs, "Id");
3984
4565
  const target = getAttr(attrs, "Target");
3985
4566
  const type = getAttr(attrs, "Type") ?? "";
3986
- if (id && target) map.set(id, { target, type });
4567
+ const targetMode = getAttr(attrs, "TargetMode");
4568
+ if (id && target) map.set(id, { target, type, ...targetMode ? { targetMode } : {} });
3987
4569
  }
3988
4570
  return map;
3989
4571
  }
@@ -4054,7 +4636,7 @@ function parseFirstSrgbHex(xmlFragment, schemeMap) {
4054
4636
  return void 0;
4055
4637
  }
4056
4638
  function parseThemeFromXml(xml) {
4057
- const base = import_core4.Tools.deepClone(SLIDE_THEME_PRESETS[0]);
4639
+ const base = import_core5.Tools.deepClone(SLIDE_THEME_PRESETS[0]);
4058
4640
  const themeTag = /<a:theme\b([^>]*)>/.exec(xml);
4059
4641
  if (themeTag) {
4060
4642
  const tName = getAttr(themeTag[1], "name");
@@ -4304,7 +4886,9 @@ function parseTransitionFromSlideXml(slideXml) {
4304
4886
  let type = "fade";
4305
4887
  let direction;
4306
4888
  const parseDir = (d) => d === "r" ? "right" : d === "u" ? "up" : d === "d" ? "down" : d === "l" ? "left" : void 0;
4307
- if (/<p:push\b/.test(trBlock)) {
4889
+ if (/<p159:morph\b/.test(trBlock) || /<p:morph\b/.test(trBlock)) {
4890
+ type = "morph";
4891
+ } else if (/<p:push\b/.test(trBlock)) {
4308
4892
  type = "push";
4309
4893
  direction = parseDir(/<p:push\b[^>]*dir="([^"]+)"/.exec(trBlock)?.[1]);
4310
4894
  } else if (/<p:wipe\b/.test(trBlock)) {
@@ -4340,7 +4924,7 @@ function parseTimingAnimationsFromSlideXml(slideXml, spIdToElId) {
4340
4924
  const trigger = nodeType === "withEffect" ? "withPrevious" : nodeType === "afterEffect" ? "afterPrevious" : "onClick";
4341
4925
  const effect = category === "exit" ? "fadeOut" : presetId === 2 ? "flyIn" : presetId === 23 ? "zoomIn" : presetId === 22 ? "wipe" : presetId === 26 ? "pulse" : presetId === 10 ? "fadeIn" : "appear";
4342
4926
  animations.push({
4343
- id: `anim-${(0, import_core4.generateRandomId)(6)}`,
4927
+ id: `anim-${(0, import_core5.generateRandomId)(6)}`,
4344
4928
  elementId: elId,
4345
4929
  category,
4346
4930
  effect,
@@ -4351,6 +4935,50 @@ function parseTimingAnimationsFromSlideXml(slideXml, spIdToElId) {
4351
4935
  }
4352
4936
  return animations;
4353
4937
  }
4938
+ function parseActionFromCNvPrBlock(cNvPrBlock, slideDir, slideRels, slideZipPathToSlideId) {
4939
+ const hoverMatch = /<a:hlinkHover\b([^>]*)\/?>/.exec(cNvPrBlock);
4940
+ const clickMatch = /<a:hlinkClick\b([^>]*)\/?>/.exec(cNvPrBlock);
4941
+ const chosen = hoverMatch ?? clickMatch;
4942
+ if (!chosen) return void 0;
4943
+ const trigger = hoverMatch ? "hover" : "click";
4944
+ const attrs = chosen[1];
4945
+ const rId = getAttr(attrs, "r:id");
4946
+ const actionUri = (getAttr(attrs, "action") ?? "").trim();
4947
+ const lowerUri = actionUri.toLowerCase();
4948
+ const tooltip = getAttr(attrs, "tooltip");
4949
+ const rel = rId ? slideRels.get(rId) : void 0;
4950
+ let type = "none";
4951
+ let targetSlideId;
4952
+ let url;
4953
+ if (lowerUri.includes("jump=nextslide")) {
4954
+ type = "nextSlide";
4955
+ } else if (lowerUri.includes("jump=previousslide")) {
4956
+ type = "prevSlide";
4957
+ } else if (lowerUri.includes("jump=firstslide")) {
4958
+ type = "firstSlide";
4959
+ } else if (lowerUri.includes("jump=lastslide")) {
4960
+ type = "lastSlide";
4961
+ } else if (lowerUri.includes("jump=endshow")) {
4962
+ type = "endShow";
4963
+ } else if (lowerUri.includes("hlinksldjump") || rel && rel.targetMode !== "External" && /slide\d+\.xml$/i.test(rel.target)) {
4964
+ type = "slide";
4965
+ if (rel) {
4966
+ const targetZipPath = resolveZipRelativePath(slideDir, rel.target);
4967
+ targetSlideId = slideZipPathToSlideId.get(targetZipPath);
4968
+ }
4969
+ } else if (rel?.target) {
4970
+ type = "url";
4971
+ url = rel.target;
4972
+ }
4973
+ if (type === "none") return void 0;
4974
+ return {
4975
+ trigger,
4976
+ type,
4977
+ ...targetSlideId ? { targetSlideId } : {},
4978
+ ...url ? { url } : {},
4979
+ ...tooltip ? { tooltip } : {}
4980
+ };
4981
+ }
4354
4982
  function importPptxBytesSync(pptxBytes, options) {
4355
4983
  const zipMap = unpackZipSync(pptxBytes);
4356
4984
  const decoder = new TextDecoder("utf-8");
@@ -4384,7 +5012,7 @@ function importPptxBytesSync(pptxBytes, options) {
4384
5012
  }
4385
5013
  }
4386
5014
  const themeXml = readText("ppt/theme/theme1.xml");
4387
- const { theme, schemeMap } = themeXml ? parseThemeFromXml(themeXml) : { theme: import_core4.Tools.deepClone(SLIDE_THEME_PRESETS[0]), schemeMap: {} };
5015
+ const { theme, schemeMap } = themeXml ? parseThemeFromXml(themeXml) : { theme: import_core5.Tools.deepClone(SLIDE_THEME_PRESETS[0]), schemeMap: {} };
4388
5016
  const presRelsXml = readText("ppt/_rels/presentation.xml.rels") ?? "";
4389
5017
  const presRels = parseRelsXml(presRelsXml);
4390
5018
  const sldIdList = [];
@@ -4397,6 +5025,17 @@ function importPptxBytesSync(pptxBytes, options) {
4397
5025
  const slideOrder = [];
4398
5026
  const slides = {};
4399
5027
  const ooxmlSldNumIdToSlideId = /* @__PURE__ */ new Map();
5028
+ const slideZipPathToSlideId = /* @__PURE__ */ new Map();
5029
+ sldIdList.forEach(({ rId }, sIdx) => {
5030
+ const rel = presRels.get(rId);
5031
+ const slidePath = rel ? resolveZipRelativePath("ppt", rel.target) : `ppt/slides/slide${sIdx + 1}.xml`;
5032
+ const slideXml = readText(slidePath);
5033
+ if (!slideXml) return;
5034
+ const nvGrpMatch = /<p:nvGrpSpPr>[\s\S]*?<p:cNvPr\b([^>]*)\/?>/.exec(slideXml);
5035
+ const slideMeta = decodeElementMetaDescr(nvGrpMatch ? getAttr(nvGrpMatch[1], "descr") : void 0);
5036
+ const slideId = slideMeta?.slideId || `slide-${sIdx + 1}`;
5037
+ slideZipPathToSlideId.set(slidePath, slideId);
5038
+ });
4400
5039
  sldIdList.forEach(({ numId, rId }, sIdx) => {
4401
5040
  const rel = presRels.get(rId);
4402
5041
  const slidePath = rel ? resolveZipRelativePath("ppt", rel.target) : `ppt/slides/slide${sIdx + 1}.xml`;
@@ -4464,19 +5103,33 @@ function importPptxBytesSync(pptxBytes, options) {
4464
5103
  const spIdToElId = /* @__PURE__ */ new Map();
4465
5104
  const pendingConnectorRefs = [];
4466
5105
  for (const item of tokenPositions) {
4467
- const cNvPrMatch = /<p:cNvPr\b([^>]*)\/?>/.exec(item.xml);
4468
- const cNvAttrs = cNvPrMatch?.[1] ?? "";
5106
+ const cNvPrBlock = extractBalancedBlocks(item.xml, "p:cNvPr")[0] ?? "";
5107
+ const cNvAttrs = /^<p:cNvPr\b([^>]*?)(?:\/>|>)/.exec(cNvPrBlock)?.[1] ?? "";
4469
5108
  const spIdNum = Number(getAttr(cNvAttrs, "id") ?? 0);
4470
5109
  const rawName = getAttr(cNvAttrs, "name");
4471
5110
  const meta = decodeElementMetaDescr(getAttr(cNvAttrs, "descr"));
4472
5111
  const box = parseXfrmBox(item.xml);
4473
5112
  if (!box) continue;
5113
+ const parsedMorphName = rawName && rawName.startsWith("!!") && rawName.length > 2 ? rawName.slice(2).trim() : void 0;
5114
+ const parsedAction = parseActionFromCNvPrBlock(
5115
+ cNvPrBlock,
5116
+ slideDir,
5117
+ slideRels,
5118
+ slideZipPathToSlideId
5119
+ );
5120
+ const resolvedDisplayName = typeof meta?.displayName === "string" && meta.displayName ? meta.displayName : rawName;
5121
+ const baseActionAndMorph = {
5122
+ ...parsedMorphName ? { morphName: parsedMorphName } : {},
5123
+ ...parsedAction ? { action: parsedAction } : {}
5124
+ };
4474
5125
  if (meta?.kind === "richElement" && meta.element && typeof meta.element === "object") {
4475
- const restored = import_core4.Tools.deepClone(meta.element);
5126
+ const restored = import_core5.Tools.deepClone(meta.element);
4476
5127
  restored.x = box.x;
4477
5128
  restored.y = box.y;
4478
5129
  restored.width = box.width;
4479
5130
  restored.height = box.height;
5131
+ if (parsedMorphName) restored.morphName = parsedMorphName;
5132
+ if (parsedAction) restored.action = parsedAction;
4480
5133
  elements[restored.id] = restored;
4481
5134
  elementOrder.push(restored.id);
4482
5135
  if (spIdNum) spIdToElId.set(spIdNum, restored.id);
@@ -4489,7 +5142,7 @@ function importPptxBytesSync(pptxBytes, options) {
4489
5142
  const prstName = prstMatch?.[1] ?? "rect";
4490
5143
  const txBodyBlock = extractBalancedBlocks(item.xml, "p:txBody")[0] ?? "";
4491
5144
  const parsedTx = parseParagraphsFromTxBody(txBodyBlock, schemeMap);
4492
- const elId = meta?.id || `el-${(0, import_core4.generateRandomId)(6)}`;
5145
+ const elId = meta?.id || `el-${(0, import_core5.generateRandomId)(6)}`;
4493
5146
  if (isTxBox && meta?.kind !== "shape") {
4494
5147
  const fillHex = /<a:noFill\b/.test(spPrBlock.replace(/<a:ln[\s\S]*?<\/a:ln>/g, "")) ? void 0 : parseFirstSrgbHex(spPrBlock.replace(/<a:ln[\s\S]*?<\/a:ln>/g, ""), schemeMap);
4495
5148
  const lnBlock = extractBalancedBlocks(spPrBlock, "a:ln")[0] ?? "";
@@ -4497,9 +5150,10 @@ function importPptxBytesSync(pptxBytes, options) {
4497
5150
  const lnW = /<a:ln\b[^>]*w="(\d+)"/.exec(lnBlock);
4498
5151
  const bodyAnchor = /<a:bodyPr\b[^>]*anchor="([^"]+)"/.exec(txBodyBlock)?.[1];
4499
5152
  const textEl = syncTextAndParagraphs({
5153
+ ...baseActionAndMorph,
4500
5154
  id: elId,
4501
5155
  type: "text",
4502
- name: rawName || "\u6587\u672C\u6846",
5156
+ name: resolvedDisplayName || "\u6587\u672C\u6846",
4503
5157
  x: box.x,
4504
5158
  y: box.y,
4505
5159
  width: box.width,
@@ -4536,9 +5190,10 @@ function importPptxBytesSync(pptxBytes, options) {
4536
5190
  const lnW = /<a:ln\b[^>]*w="(\d+)"/.exec(lnBlock);
4537
5191
  const strokeWidth = /<a:noFill\b/.test(lnBlock) ? 0 : lnW ? emuToPt(Number(lnW[1])) : 1;
4538
5192
  const shapeEl = {
5193
+ ...baseActionAndMorph,
4539
5194
  id: elId,
4540
5195
  type: "shape",
4541
- name: rawName || "\u5F62\u72B6",
5196
+ name: resolvedDisplayName || "\u5F62\u72B6",
4542
5197
  shapeType: OOXML_PRST_TO_SHAPE[prstName] ?? "rect",
4543
5198
  x: box.x,
4544
5199
  y: box.y,
@@ -4561,7 +5216,7 @@ function importPptxBytesSync(pptxBytes, options) {
4561
5216
  elementOrder.push(elId);
4562
5217
  if (spIdNum) spIdToElId.set(spIdNum, elId);
4563
5218
  } else if (item.tag === "p:cxnSp") {
4564
- const elId = meta?.id || `el-${(0, import_core4.generateRandomId)(6)}`;
5219
+ const elId = meta?.id || `el-${(0, import_core5.generateRandomId)(6)}`;
4565
5220
  const prst = /<a:prstGeom\s+prst="([^"]+)"/.exec(item.xml)?.[1] ?? "line";
4566
5221
  const connectorType = prst.includes("curved") ? "curved" : prst.includes("bent") ? "elbow" : "straight";
4567
5222
  const lnBlock = extractBalancedBlocks(item.xml, "a:ln")[0] ?? "";
@@ -4574,9 +5229,10 @@ function importPptxBytesSync(pptxBytes, options) {
4574
5229
  const stSpId = Number(/<a:stCxn\s+id="(\d+)"/.exec(item.xml)?.[1] ?? 0);
4575
5230
  const endSpId = Number(/<a:endCxn\s+id="(\d+)"/.exec(item.xml)?.[1] ?? 0);
4576
5231
  const connEl = {
5232
+ ...baseActionAndMorph,
4577
5233
  id: elId,
4578
5234
  type: "connector",
4579
- name: rawName || "\u8FDE\u63A5\u7EBF",
5235
+ name: resolvedDisplayName || "\u8FDE\u63A5\u7EBF",
4580
5236
  connectorType,
4581
5237
  x: box.x,
4582
5238
  y: box.y,
@@ -4602,13 +5258,14 @@ function importPptxBytesSync(pptxBytes, options) {
4602
5258
  pendingConnectorRefs.push({ elId, stSpId: stSpId || void 0, endSpId: endSpId || void 0 });
4603
5259
  }
4604
5260
  } else if (item.tag === "p:pic") {
4605
- const elId = meta?.id || `el-${(0, import_core4.generateRandomId)(6)}`;
5261
+ const elId = meta?.id || `el-${(0, import_core5.generateRandomId)(6)}`;
4606
5262
  const rEmbed = /r:embed="([^"]+)"/.exec(item.xml)?.[1];
4607
5263
  const media = readMediaAsDataUrl(rEmbed);
4608
5264
  const imgEl = {
5265
+ ...baseActionAndMorph,
4609
5266
  id: elId,
4610
5267
  type: meta?.kind === "svg" || media?.isSvg ? "svg" : "image",
4611
- name: rawName || "\u56FE\u7247",
5268
+ name: resolvedDisplayName || "\u56FE\u7247",
4612
5269
  x: box.x,
4613
5270
  y: box.y,
4614
5271
  width: box.width,
@@ -4623,7 +5280,7 @@ function importPptxBytesSync(pptxBytes, options) {
4623
5280
  elementOrder.push(elId);
4624
5281
  if (spIdNum) spIdToElId.set(spIdNum, elId);
4625
5282
  } else if (item.tag === "p:graphicFrame") {
4626
- const elId = meta?.id || `el-${(0, import_core4.generateRandomId)(6)}`;
5283
+ const elId = meta?.id || `el-${(0, import_core5.generateRandomId)(6)}`;
4627
5284
  if (/<a:tbl\b/.test(item.xml)) {
4628
5285
  const tblXml = extractBalancedBlocks(item.xml, "a:tbl")[0] ?? "";
4629
5286
  const colWidths = Array.from(tblXml.matchAll(/<a:gridCol\s+w="(\d+)"/g)).map(
@@ -4662,9 +5319,10 @@ function importPptxBytesSync(pptxBytes, options) {
4662
5319
  const rows = cells.length;
4663
5320
  const cols = Math.max(colWidths.length, cells[0]?.length ?? 1);
4664
5321
  const tblEl = {
5322
+ ...baseActionAndMorph,
4665
5323
  id: elId,
4666
5324
  type: "table",
4667
- name: rawName || "\u8868\u683C",
5325
+ name: resolvedDisplayName || "\u8868\u683C",
4668
5326
  x: box.x,
4669
5327
  y: box.y,
4670
5328
  width: box.width,
@@ -4690,12 +5348,22 @@ function importPptxBytesSync(pptxBytes, options) {
4690
5348
  const chartPath = cRel ? resolveZipRelativePath(slideDir, cRel.target) : "";
4691
5349
  const chartXml = chartPath ? readText(chartPath) : void 0;
4692
5350
  if (chartXml) {
4693
- const chartEl = parseChartXmlToElement(
4694
- chartXml,
4695
- { id: elId, name: rawName, x: box.x, y: box.y, width: box.width, height: box.height },
4696
- schemeMap,
4697
- meta
4698
- );
5351
+ const chartEl = {
5352
+ ...parseChartXmlToElement(
5353
+ chartXml,
5354
+ {
5355
+ id: elId,
5356
+ name: resolvedDisplayName,
5357
+ x: box.x,
5358
+ y: box.y,
5359
+ width: box.width,
5360
+ height: box.height
5361
+ },
5362
+ schemeMap,
5363
+ meta
5364
+ ),
5365
+ ...baseActionAndMorph
5366
+ };
4699
5367
  elements[chartEl.id] = chartEl;
4700
5368
  elementOrder.push(chartEl.id);
4701
5369
  if (spIdNum) spIdToElId.set(spIdNum, chartEl.id);
@@ -4728,7 +5396,12 @@ function importPptxBytesSync(pptxBytes, options) {
4728
5396
  break;
4729
5397
  }
4730
5398
  }
4731
- const parsedTransition = slideMeta?.transition ?? parseTransitionFromSlideXml(slideXml);
5399
+ const xmlTransition = parseTransitionFromSlideXml(slideXml);
5400
+ const metaTransition = slideMeta?.transition;
5401
+ const parsedTransition = xmlTransition ? {
5402
+ ...xmlTransition,
5403
+ ...metaTransition?.durationMs ? { durationMs: metaTransition.durationMs } : {}
5404
+ } : metaTransition;
4732
5405
  const parsedAnimations = Array.isArray(slideMeta?.animations) ? slideMeta.animations : parseTimingAnimationsFromSlideXml(slideXml, spIdToElId);
4733
5406
  slides[slideId] = {
4734
5407
  id: slideId,
@@ -4756,17 +5429,25 @@ function importPptxBytesSync(pptxBytes, options) {
4756
5429
  }
4757
5430
  if (secSlideIds.length > 0) {
4758
5431
  sections.push({
4759
- id: `sec-${(0, import_core4.generateRandomId)(5)}`,
5432
+ id: `sec-${(0, import_core5.generateRandomId)(5)}`,
4760
5433
  title: secName,
4761
5434
  slideIds: secSlideIds,
4762
5435
  collapsed: false
4763
5436
  });
4764
5437
  }
4765
5438
  }
4766
- const masters = createDefaultSlideMasters(theme);
4767
- const layouts = createDefaultSlideLayouts(masters[0].id);
5439
+ const masterXml = readText("ppt/slideMasters/slideMaster1.xml") ?? "";
5440
+ const masterNvGrp = /<p:nvGrpSpPr>[\s\S]*?<p:cNvPr\b([^>]*)\/?>/.exec(masterXml);
5441
+ const masterMeta = decodeElementMetaDescr(
5442
+ masterNvGrp ? getAttr(masterNvGrp[1], "descr") : void 0
5443
+ );
5444
+ const presPropsXml = readText("ppt/presProps.xml") ?? "";
5445
+ const hasLoopFlag = /<p:showPr\b[^>]*loop="1"/.test(presPropsXml);
5446
+ const masters = Array.isArray(masterMeta?.masters) && masterMeta.masters.length > 0 ? masterMeta.masters : createDefaultSlideMasters(theme);
5447
+ const layouts = Array.isArray(masterMeta?.layouts) && masterMeta.layouts.length > 0 ? masterMeta.layouts : createDefaultSlideLayouts(masters[0].id);
5448
+ const slideshowSettings = masterMeta?.slideshowSettings && typeof masterMeta.slideshowSettings === "object" ? masterMeta.slideshowSettings : hasLoopFlag ? { loopContinuously: true } : void 0;
4768
5449
  return createDefaultSlideUnitData({
4769
- id: options?.unitId || `slide-pptx-${(0, import_core4.generateRandomId)(6)}`,
5450
+ id: options?.unitId || `slide-pptx-${(0, import_core5.generateRandomId)(6)}`,
4770
5451
  name: deckName,
4771
5452
  activeSlideId: slideOrder[0],
4772
5453
  slideSize,
@@ -4775,7 +5456,8 @@ function importPptxBytesSync(pptxBytes, options) {
4775
5456
  layouts,
4776
5457
  ...sections.length > 0 ? { sections } : {},
4777
5458
  slideOrder,
4778
- slides
5459
+ slides,
5460
+ ...slideshowSettings ? { slideshowSettings } : {}
4779
5461
  });
4780
5462
  }
4781
5463
  async function importPptxBytes(source, options) {
@@ -4793,7 +5475,7 @@ async function importPptxBytes(source, options) {
4793
5475
  }
4794
5476
 
4795
5477
  // src/exporter/slide-pdf-exporter.ts
4796
- var import_core5 = require("@univerjs/core");
5478
+ var import_core6 = require("@univerjs/core");
4797
5479
  var import_pdf_lib = require("pdf-lib");
4798
5480
  function parseColorRgb(color, fallback = { r: 0.06, g: 0.09, b: 0.16 }) {
4799
5481
  if (!color) return fallback;
@@ -5194,15 +5876,315 @@ function renderSmartArtOntoPdf(page, ctx, smartArt, theme, tf) {
5194
5876
  }
5195
5877
  });
5196
5878
  }
5197
- async function renderSlideOntoPdfFrame(page, ctx, slide, snapshot, slideIndexOneBased, tf) {
5879
+ async function renderSingleElementOntoPdf(page, ctx, el, elementsMap, theme, tf) {
5880
+ if (!el || el.hidden) return;
5198
5881
  const m = createCoordinateMapper(tf);
5199
- const slideW = snapshot.slideSize.widthPt || 960;
5200
- const slideH = snapshot.slideSize.heightPt || 540;
5201
- const theme = snapshot.theme ?? SLIDE_THEME_PRESETS[0];
5202
- const bg = slide.background ?? snapshot.masters[0]?.background ?? { type: "solid", color: theme.colors.background };
5203
- if (bg.type === "gradient" && bg.gradientFrom && bg.gradientTo) {
5204
- const c1 = parseColorRgb(bg.gradientFrom);
5205
- const c2 = parseColorRgb(bg.gradientTo);
5882
+ if (el.type === "shape") {
5883
+ const fillCol = parseColorRgb(el.gradientFrom || el.fillColor, parseColorRgb(theme.colors.accent1));
5884
+ const strokeCol = el.strokeWidth > 0 ? parseColorRgb(el.strokeColor) : null;
5885
+ if (el.shapeType === "ellipse") {
5886
+ page.drawEllipse({
5887
+ x: m.x(el.x + el.width / 2),
5888
+ y: m.y(el.y + el.height / 2),
5889
+ xScale: m.len(el.width / 2),
5890
+ yScale: m.len(el.height / 2),
5891
+ color: (0, import_pdf_lib.rgb)(fillCol.r, fillCol.g, fillCol.b),
5892
+ ...strokeCol ? { borderColor: (0, import_pdf_lib.rgb)(strokeCol.r, strokeCol.g, strokeCol.b), borderWidth: m.len(el.strokeWidth) } : {}
5893
+ });
5894
+ } else if (el.shapeType === "rect" || el.shapeType === "roundRect") {
5895
+ page.drawRectangle({
5896
+ x: m.x(el.x),
5897
+ y: m.rectY(el.y, el.height),
5898
+ width: m.len(el.width),
5899
+ height: m.len(el.height),
5900
+ color: (0, import_pdf_lib.rgb)(fillCol.r, fillCol.g, fillCol.b),
5901
+ ...strokeCol ? { borderColor: (0, import_pdf_lib.rgb)(strokeCol.r, strokeCol.g, strokeCol.b), borderWidth: m.len(el.strokeWidth) } : {}
5902
+ });
5903
+ } else {
5904
+ const localPts = getShapePolygonPoints(el.shapeType, el.width, el.height);
5905
+ const pdfPts = localPts.map((p) => ({ x: m.x(el.x + p.x), y: m.y(el.y + p.y) }));
5906
+ drawPolygonPdf(page, pdfPts, fillCol, strokeCol, m.len(el.strokeWidth));
5907
+ }
5908
+ if (el.text) {
5909
+ const lines = el.text.split("\n");
5910
+ const fs = el.fontSize ?? 15;
5911
+ const totalTextH = lines.length * fs * 1.25;
5912
+ const startY = el.y + (el.height - totalTextH) / 2 + fs * 0.9;
5913
+ const tCol = parseColorRgb(el.textColor, { r: 1, g: 1, b: 1 });
5914
+ lines.forEach((ln, idx) => {
5915
+ drawSafeTextLine(
5916
+ page,
5917
+ ctx,
5918
+ ln,
5919
+ m.x(el.x + el.width / 2),
5920
+ m.y(startY + idx * fs * 1.25),
5921
+ m.len(fs),
5922
+ tCol,
5923
+ el.fontWeight === "bold",
5924
+ "center"
5925
+ );
5926
+ });
5927
+ }
5928
+ } else if (el.type === "connector") {
5929
+ const geom = resolveConnectorEndpoints(el, elementsMap);
5930
+ const sCol = parseColorRgb(el.strokeColor, parseColorRgb(theme.colors.accent1));
5931
+ const thick = Math.max(0.8, m.len(el.strokeWidth || 2));
5932
+ if (el.connectorType === "elbow") {
5933
+ page.drawLine({ start: { x: m.x(geom.x1), y: m.y(geom.y1) }, end: { x: m.x(geom.midX), y: m.y(geom.y1) }, thickness: thick, color: (0, import_pdf_lib.rgb)(sCol.r, sCol.g, sCol.b) });
5934
+ page.drawLine({ start: { x: m.x(geom.midX), y: m.y(geom.y1) }, end: { x: m.x(geom.midX), y: m.y(geom.y2) }, thickness: thick, color: (0, import_pdf_lib.rgb)(sCol.r, sCol.g, sCol.b) });
5935
+ page.drawLine({ start: { x: m.x(geom.midX), y: m.y(geom.y2) }, end: { x: m.x(geom.x2), y: m.y(geom.y2) }, thickness: thick, color: (0, import_pdf_lib.rgb)(sCol.r, sCol.g, sCol.b) });
5936
+ } else {
5937
+ page.drawLine({ start: { x: m.x(geom.x1), y: m.y(geom.y1) }, end: { x: m.x(geom.x2), y: m.y(geom.y2) }, thickness: thick, color: (0, import_pdf_lib.rgb)(sCol.r, sCol.g, sCol.b) });
5938
+ }
5939
+ if (el.endArrow) {
5940
+ const aLen = 7;
5941
+ const a1 = geom.endAngleRad + Math.PI * 0.82;
5942
+ const a2 = geom.endAngleRad - Math.PI * 0.82;
5943
+ drawPolygonPdf(
5944
+ page,
5945
+ [
5946
+ { x: m.x(geom.x2), y: m.y(geom.y2) },
5947
+ { x: m.x(geom.x2 + aLen * Math.cos(a1)), y: m.y(geom.y2 + aLen * Math.sin(a1)) },
5948
+ { x: m.x(geom.x2 + aLen * Math.cos(a2)), y: m.y(geom.y2 + aLen * Math.sin(a2)) }
5949
+ ],
5950
+ sCol,
5951
+ null,
5952
+ 0
5953
+ );
5954
+ }
5955
+ if (el.label) {
5956
+ drawSafeTextLine(
5957
+ page,
5958
+ ctx,
5959
+ el.label,
5960
+ m.x(geom.midX),
5961
+ m.y(geom.midY - 5),
5962
+ m.len(10),
5963
+ parseColorRgb(el.labelColor || el.strokeColor),
5964
+ false,
5965
+ "center"
5966
+ );
5967
+ }
5968
+ } else if (el.type === "text") {
5969
+ if (el.fillColor) {
5970
+ const fCol = parseColorRgb(el.fillColor, { r: 1, g: 1, b: 1 });
5971
+ page.drawRectangle({
5972
+ x: m.x(el.x),
5973
+ y: m.rectY(el.y, el.height),
5974
+ width: m.len(el.width),
5975
+ height: m.len(el.height),
5976
+ color: (0, import_pdf_lib.rgb)(fCol.r, fCol.g, fCol.b),
5977
+ ...el.strokeColor && (el.strokeWidth ?? 0) > 0 ? {
5978
+ borderColor: (0, import_pdf_lib.rgb)(
5979
+ parseColorRgb(el.strokeColor).r,
5980
+ parseColorRgb(el.strokeColor).g,
5981
+ parseColorRgb(el.strokeColor).b
5982
+ ),
5983
+ borderWidth: m.len(el.strokeWidth ?? 1)
5984
+ } : {}
5985
+ });
5986
+ }
5987
+ const fs = el.fontSize ?? 18;
5988
+ const lh = fs * (el.lineHeight ?? 1.35);
5989
+ const lines = (el.text || "").split("\n");
5990
+ const pad = el.paddingPt ?? 6;
5991
+ const totalH = lines.length * lh;
5992
+ const startSy = el.verticalAlign === "middle" ? el.y + (el.height - totalH) / 2 + fs * 0.88 : el.verticalAlign === "bottom" ? el.y + el.height - totalH - pad + fs * 0.88 : el.y + pad + fs * 0.92;
5993
+ const textCol = parseColorRgb(
5994
+ el.wordArt?.enabled ? el.wordArt.gradientFrom : el.color || theme.colors.text
5995
+ );
5996
+ const align = el.align === "center" ? "center" : el.align === "right" ? "right" : "left";
5997
+ const anchorX = align === "center" ? el.x + el.width / 2 : align === "right" ? el.x + el.width - pad : el.x + pad;
5998
+ const isBold = el.fontWeight === "bold" || typeof el.fontWeight === "number" && el.fontWeight >= 600;
5999
+ lines.forEach((line, idx) => {
6000
+ const prefix = el.bullet ? el.bullet === "number" ? `${idx + 1}. ` : "\u2022 " : "";
6001
+ drawSafeTextLine(
6002
+ page,
6003
+ ctx,
6004
+ prefix + line,
6005
+ m.x(anchorX),
6006
+ m.y(startSy + idx * lh),
6007
+ m.len(fs),
6008
+ textCol,
6009
+ isBold,
6010
+ align
6011
+ );
6012
+ });
6013
+ } else if (el.type === "table") {
6014
+ const borderCol = parseColorRgb(el.borderColor || "#cbd5e1");
6015
+ let curY = el.y;
6016
+ for (let r = 0; r < el.rows; r++) {
6017
+ const rh = el.rowHeights[r] ?? el.height / Math.max(1, el.rows);
6018
+ let curX = el.x;
6019
+ const isHeader = el.headerRow !== false && r === 0;
6020
+ for (let c = 0; c < el.cols; c++) {
6021
+ const cw = el.colWidths[c] ?? el.width / Math.max(1, el.cols);
6022
+ const cell = el.cells[r]?.[c];
6023
+ if (!cell?.mergedInto) {
6024
+ const bgCol = parseColorRgb(
6025
+ cell?.bg || (isHeader ? el.headerBg || theme.colors.primary : r % 2 === 1 ? el.zebraBg || "#f8fafc" : "#ffffff")
6026
+ );
6027
+ const fgCol = parseColorRgb(
6028
+ cell?.color || (isHeader ? el.headerColor || "#ffffff" : theme.colors.text)
6029
+ );
6030
+ page.drawRectangle({
6031
+ x: m.x(curX),
6032
+ y: m.rectY(curY, rh),
6033
+ width: m.len(cw),
6034
+ height: m.len(rh),
6035
+ color: (0, import_pdf_lib.rgb)(bgCol.r, bgCol.g, bgCol.b),
6036
+ borderColor: (0, import_pdf_lib.rgb)(borderCol.r, borderCol.g, borderCol.b),
6037
+ borderWidth: Math.max(0.4, m.len(0.75))
6038
+ });
6039
+ if (cell?.text) {
6040
+ const cellAlign = cell.align ?? "left";
6041
+ const tx = cellAlign === "center" ? curX + cw / 2 : cellAlign === "right" ? curX + cw - 8 : curX + 8;
6042
+ const cfs = cell.fontSize ?? 11;
6043
+ drawSafeTextLine(
6044
+ page,
6045
+ ctx,
6046
+ cell.text,
6047
+ m.x(tx),
6048
+ m.y(curY + rh / 2 + cfs * 0.35),
6049
+ m.len(cfs),
6050
+ fgCol,
6051
+ Boolean(cell.bold || isHeader),
6052
+ cellAlign
6053
+ );
6054
+ }
6055
+ }
6056
+ curX += cw;
6057
+ }
6058
+ curY += rh;
6059
+ }
6060
+ } else if (el.type === "chart") {
6061
+ renderVectorChartOntoPdf(page, ctx, el, theme, tf);
6062
+ } else if (el.type === "smartArt") {
6063
+ renderSmartArtOntoPdf(page, ctx, el, theme, tf);
6064
+ } else if (el.type === "image" && el.src.startsWith("data:image/")) {
6065
+ try {
6066
+ const comma = el.src.indexOf(",");
6067
+ const header = el.src.slice(0, comma);
6068
+ const b64 = el.src.slice(comma + 1);
6069
+ const bytes = typeof Buffer !== "undefined" ? new Uint8Array(Buffer.from(b64, "base64")) : Uint8Array.from(atob(b64), (ch) => ch.charCodeAt(0));
6070
+ if (header.includes("png")) {
6071
+ const img = await ctx.pdfDoc.embedPng(bytes);
6072
+ page.drawImage(img, {
6073
+ x: m.x(el.x),
6074
+ y: m.rectY(el.y, el.height),
6075
+ width: m.len(el.width),
6076
+ height: m.len(el.height)
6077
+ });
6078
+ } else if (header.includes("jpeg") || header.includes("jpg")) {
6079
+ const img = await ctx.pdfDoc.embedJpg(bytes);
6080
+ page.drawImage(img, {
6081
+ x: m.x(el.x),
6082
+ y: m.rectY(el.y, el.height),
6083
+ width: m.len(el.width),
6084
+ height: m.len(el.height)
6085
+ });
6086
+ }
6087
+ } catch {
6088
+ }
6089
+ } else if (el.type === "codeBlock") {
6090
+ page.drawRectangle({
6091
+ x: m.x(el.x),
6092
+ y: m.rectY(el.y, el.height),
6093
+ width: m.len(el.width),
6094
+ height: m.len(el.height),
6095
+ color: (0, import_pdf_lib.rgb)(0.06, 0.09, 0.16)
6096
+ });
6097
+ el.code.split("\n").slice(0, 12).forEach((ln, idx) => {
6098
+ drawSafeTextLine(
6099
+ page,
6100
+ ctx,
6101
+ ln,
6102
+ m.x(el.x + 12),
6103
+ m.y(el.y + 24 + idx * 15),
6104
+ m.len(el.fontSize ?? 11),
6105
+ { r: 0.89, g: 0.91, b: 0.94 },
6106
+ false,
6107
+ "left"
6108
+ );
6109
+ });
6110
+ } else if (el.type === "sheetEmbed") {
6111
+ page.drawRectangle({
6112
+ x: m.x(el.x),
6113
+ y: m.rectY(el.y, el.height),
6114
+ width: m.len(el.width),
6115
+ height: m.len(el.height),
6116
+ color: (0, import_pdf_lib.rgb)(1, 1, 1),
6117
+ borderColor: (0, import_pdf_lib.rgb)(0.06, 0.72, 0.5),
6118
+ borderWidth: m.len(1)
6119
+ });
6120
+ if (el.title) {
6121
+ drawSafeTextLine(
6122
+ page,
6123
+ ctx,
6124
+ el.title,
6125
+ m.x(el.x + 10),
6126
+ m.y(el.y + 18),
6127
+ m.len(12),
6128
+ parseColorRgb(el.accentColor || "#059669"),
6129
+ true,
6130
+ "left"
6131
+ );
6132
+ }
6133
+ } else if (el.type === "video" || el.type === "audio") {
6134
+ const accentCol = parseColorRgb(theme.colors.accent1);
6135
+ page.drawRectangle({
6136
+ x: m.x(el.x),
6137
+ y: m.rectY(el.y, el.height),
6138
+ width: m.len(el.width),
6139
+ height: m.len(el.height),
6140
+ color: el.type === "video" ? (0, import_pdf_lib.rgb)(0.06, 0.09, 0.16) : (0, import_pdf_lib.rgb)(0.12, 0.16, 0.23),
6141
+ borderColor: (0, import_pdf_lib.rgb)(0.28, 0.33, 0.41),
6142
+ borderWidth: Math.max(0.6, m.len(1))
6143
+ });
6144
+ const cx = el.type === "video" ? el.x + el.width / 2 : el.x + 28;
6145
+ const cy = el.y + el.height / 2;
6146
+ const r = el.type === "video" ? Math.min(20, Math.min(el.width, el.height) * 0.15) : 13;
6147
+ page.drawCircle({
6148
+ x: m.x(cx),
6149
+ y: m.y(cy),
6150
+ size: m.len(r),
6151
+ color: (0, import_pdf_lib.rgb)(accentCol.r, accentCol.g, accentCol.b)
6152
+ });
6153
+ drawPolygonPdf(
6154
+ page,
6155
+ [
6156
+ { x: m.x(cx - r * 0.3), y: m.y(cy - r * 0.42) },
6157
+ { x: m.x(cx - r * 0.3), y: m.y(cy + r * 0.42) },
6158
+ { x: m.x(cx + r * 0.46), y: m.y(cy) }
6159
+ ],
6160
+ { r: 1, g: 1, b: 1 },
6161
+ null,
6162
+ 0
6163
+ );
6164
+ drawSafeTextLine(
6165
+ page,
6166
+ ctx,
6167
+ el.name || (el.type === "video" ? "\u89C6\u9891\u5A92\u4F53 (VIDEO)" : "\u97F3\u9891\u5A92\u4F53 (AUDIO)"),
6168
+ m.x(el.type === "video" ? el.x + 12 : cx + r + 10),
6169
+ m.y(el.type === "video" ? el.y + el.height - 10 : cy + 4),
6170
+ m.len(10.5),
6171
+ { r: 0.92, g: 0.95, b: 0.98 },
6172
+ true,
6173
+ "left"
6174
+ );
6175
+ }
6176
+ }
6177
+ async function renderSlideOntoPdfFrame(page, ctx, slide, snapshot, slideIndexOneBased, tf) {
6178
+ const m = createCoordinateMapper(tf);
6179
+ const slideW = snapshot.slideSize.widthPt || 960;
6180
+ const slideH = snapshot.slideSize.heightPt || 540;
6181
+ const theme = snapshot.theme ?? SLIDE_THEME_PRESETS[0];
6182
+ const matchedLayout = snapshot.layouts?.find((l) => l.id === slide.layoutId);
6183
+ const master = (matchedLayout ? snapshot.masters.find((ms) => ms.id === matchedLayout.masterId) : void 0) ?? snapshot.masters[0];
6184
+ const bg = slide.background ?? matchedLayout?.background ?? master?.background ?? { type: "solid", color: theme.colors.background };
6185
+ if (bg.type === "gradient" && bg.gradientFrom && bg.gradientTo) {
6186
+ const c1 = parseColorRgb(bg.gradientFrom);
6187
+ const c2 = parseColorRgb(bg.gradientTo);
5206
6188
  const bands = 24;
5207
6189
  const bandH = slideH / bands;
5208
6190
  for (let i = 0; i < bands; i++) {
@@ -5225,7 +6207,7 @@ async function renderSlideOntoPdfFrame(page, ctx, slide, snapshot, slideIndexOne
5225
6207
  color: (0, import_pdf_lib.rgb)(bgCol.r, bgCol.g, bgCol.b)
5226
6208
  });
5227
6209
  }
5228
- if (snapshot.masters[0]?.accentBar) {
6210
+ if (master?.accentBar) {
5229
6211
  const pCol = parseColorRgb(theme.colors.primary);
5230
6212
  page.drawRectangle({
5231
6213
  x: m.x(0),
@@ -5235,261 +6217,41 @@ async function renderSlideOntoPdfFrame(page, ctx, slide, snapshot, slideIndexOne
5235
6217
  color: (0, import_pdf_lib.rgb)(pCol.r, pCol.g, pCol.b)
5236
6218
  });
5237
6219
  }
6220
+ if (master?.masterElements && master.masterElements.length > 0) {
6221
+ const masterMap = {};
6222
+ for (const mEl of master.masterElements) {
6223
+ if (mEl) masterMap[mEl.id] = mEl;
6224
+ }
6225
+ for (const mEl of master.masterElements) {
6226
+ await renderSingleElementOntoPdf(page, ctx, mEl, masterMap, theme, tf);
6227
+ }
6228
+ }
6229
+ if (matchedLayout?.layoutElements && matchedLayout.layoutElements.length > 0) {
6230
+ const layoutMap = {};
6231
+ for (const lEl of matchedLayout.layoutElements) {
6232
+ if (lEl) layoutMap[lEl.id] = lEl;
6233
+ }
6234
+ for (const lEl of matchedLayout.layoutElements) {
6235
+ await renderSingleElementOntoPdf(page, ctx, lEl, layoutMap, theme, tf);
6236
+ }
6237
+ }
5238
6238
  for (const elId of slide.elementOrder) {
5239
6239
  const el = slide.elements[elId];
5240
6240
  if (!el || el.hidden) continue;
5241
- if (el.type === "shape") {
5242
- const fillCol = parseColorRgb(el.gradientFrom || el.fillColor, parseColorRgb(theme.colors.accent1));
5243
- const strokeCol = el.strokeWidth > 0 ? parseColorRgb(el.strokeColor) : null;
5244
- if (el.shapeType === "ellipse") {
5245
- page.drawEllipse({
5246
- x: m.x(el.x + el.width / 2),
5247
- y: m.y(el.y + el.height / 2),
5248
- xScale: m.len(el.width / 2),
5249
- yScale: m.len(el.height / 2),
5250
- color: (0, import_pdf_lib.rgb)(fillCol.r, fillCol.g, fillCol.b),
5251
- ...strokeCol ? { borderColor: (0, import_pdf_lib.rgb)(strokeCol.r, strokeCol.g, strokeCol.b), borderWidth: m.len(el.strokeWidth) } : {}
5252
- });
5253
- } else if (el.shapeType === "rect" || el.shapeType === "roundRect") {
5254
- page.drawRectangle({
5255
- x: m.x(el.x),
5256
- y: m.rectY(el.y, el.height),
5257
- width: m.len(el.width),
5258
- height: m.len(el.height),
5259
- color: (0, import_pdf_lib.rgb)(fillCol.r, fillCol.g, fillCol.b),
5260
- ...strokeCol ? { borderColor: (0, import_pdf_lib.rgb)(strokeCol.r, strokeCol.g, strokeCol.b), borderWidth: m.len(el.strokeWidth) } : {}
5261
- });
5262
- } else {
5263
- const localPts = getShapePolygonPoints(el.shapeType, el.width, el.height);
5264
- const pdfPts = localPts.map((p) => ({ x: m.x(el.x + p.x), y: m.y(el.y + p.y) }));
5265
- drawPolygonPdf(page, pdfPts, fillCol, strokeCol, m.len(el.strokeWidth));
5266
- }
5267
- if (el.text) {
5268
- const lines = el.text.split("\n");
5269
- const fs = el.fontSize ?? 15;
5270
- const totalTextH = lines.length * fs * 1.25;
5271
- const startY = el.y + (el.height - totalTextH) / 2 + fs * 0.9;
5272
- const tCol = parseColorRgb(el.textColor, { r: 1, g: 1, b: 1 });
5273
- lines.forEach((ln, idx) => {
5274
- drawSafeTextLine(
5275
- page,
5276
- ctx,
5277
- ln,
5278
- m.x(el.x + el.width / 2),
5279
- m.y(startY + idx * fs * 1.25),
5280
- m.len(fs),
5281
- tCol,
5282
- el.fontWeight === "bold",
5283
- "center"
5284
- );
5285
- });
5286
- }
5287
- } else if (el.type === "connector") {
5288
- const geom = resolveConnectorEndpoints(el, slide.elements);
5289
- const sCol = parseColorRgb(el.strokeColor, parseColorRgb(theme.colors.accent1));
5290
- const thick = Math.max(0.8, m.len(el.strokeWidth || 2));
5291
- if (el.connectorType === "elbow") {
5292
- page.drawLine({ start: { x: m.x(geom.x1), y: m.y(geom.y1) }, end: { x: m.x(geom.midX), y: m.y(geom.y1) }, thickness: thick, color: (0, import_pdf_lib.rgb)(sCol.r, sCol.g, sCol.b) });
5293
- page.drawLine({ start: { x: m.x(geom.midX), y: m.y(geom.y1) }, end: { x: m.x(geom.midX), y: m.y(geom.y2) }, thickness: thick, color: (0, import_pdf_lib.rgb)(sCol.r, sCol.g, sCol.b) });
5294
- page.drawLine({ start: { x: m.x(geom.midX), y: m.y(geom.y2) }, end: { x: m.x(geom.x2), y: m.y(geom.y2) }, thickness: thick, color: (0, import_pdf_lib.rgb)(sCol.r, sCol.g, sCol.b) });
5295
- } else {
5296
- page.drawLine({ start: { x: m.x(geom.x1), y: m.y(geom.y1) }, end: { x: m.x(geom.x2), y: m.y(geom.y2) }, thickness: thick, color: (0, import_pdf_lib.rgb)(sCol.r, sCol.g, sCol.b) });
5297
- }
5298
- if (el.endArrow) {
5299
- const aLen = 7;
5300
- const a1 = geom.endAngleRad + Math.PI * 0.82;
5301
- const a2 = geom.endAngleRad - Math.PI * 0.82;
5302
- drawPolygonPdf(
5303
- page,
5304
- [
5305
- { x: m.x(geom.x2), y: m.y(geom.y2) },
5306
- { x: m.x(geom.x2 + aLen * Math.cos(a1)), y: m.y(geom.y2 + aLen * Math.sin(a1)) },
5307
- { x: m.x(geom.x2 + aLen * Math.cos(a2)), y: m.y(geom.y2 + aLen * Math.sin(a2)) }
5308
- ],
5309
- sCol,
5310
- null,
5311
- 0
5312
- );
5313
- }
5314
- if (el.label) {
5315
- drawSafeTextLine(
5316
- page,
5317
- ctx,
5318
- el.label,
5319
- m.x(geom.midX),
5320
- m.y(geom.midY - 5),
5321
- m.len(10),
5322
- parseColorRgb(el.labelColor || el.strokeColor),
5323
- false,
5324
- "center"
5325
- );
5326
- }
5327
- } else if (el.type === "text") {
5328
- if (el.fillColor) {
5329
- const fCol = parseColorRgb(el.fillColor, { r: 1, g: 1, b: 1 });
5330
- page.drawRectangle({
5331
- x: m.x(el.x),
5332
- y: m.rectY(el.y, el.height),
5333
- width: m.len(el.width),
5334
- height: m.len(el.height),
5335
- color: (0, import_pdf_lib.rgb)(fCol.r, fCol.g, fCol.b),
5336
- ...el.strokeColor && (el.strokeWidth ?? 0) > 0 ? {
5337
- borderColor: (0, import_pdf_lib.rgb)(
5338
- parseColorRgb(el.strokeColor).r,
5339
- parseColorRgb(el.strokeColor).g,
5340
- parseColorRgb(el.strokeColor).b
5341
- ),
5342
- borderWidth: m.len(el.strokeWidth ?? 1)
5343
- } : {}
5344
- });
5345
- }
5346
- const fs = el.fontSize ?? 18;
5347
- const lh = fs * (el.lineHeight ?? 1.35);
5348
- const lines = (el.text || "").split("\n");
5349
- const pad = el.paddingPt ?? 6;
5350
- const totalH = lines.length * lh;
5351
- const startSy = el.verticalAlign === "middle" ? el.y + (el.height - totalH) / 2 + fs * 0.88 : el.verticalAlign === "bottom" ? el.y + el.height - totalH - pad + fs * 0.88 : el.y + pad + fs * 0.92;
5352
- const textCol = parseColorRgb(
5353
- el.wordArt?.enabled ? el.wordArt.gradientFrom : el.color || theme.colors.text
5354
- );
5355
- const align = el.align === "center" ? "center" : el.align === "right" ? "right" : "left";
5356
- const anchorX = align === "center" ? el.x + el.width / 2 : align === "right" ? el.x + el.width - pad : el.x + pad;
5357
- const isBold = el.fontWeight === "bold" || typeof el.fontWeight === "number" && el.fontWeight >= 600;
5358
- lines.forEach((line, idx) => {
5359
- const prefix = el.bullet ? el.bullet === "number" ? `${idx + 1}. ` : "\u2022 " : "";
5360
- drawSafeTextLine(
5361
- page,
5362
- ctx,
5363
- prefix + line,
5364
- m.x(anchorX),
5365
- m.y(startSy + idx * lh),
5366
- m.len(fs),
5367
- textCol,
5368
- isBold,
5369
- align
5370
- );
5371
- });
5372
- } else if (el.type === "table") {
5373
- const borderCol = parseColorRgb(el.borderColor || "#cbd5e1");
5374
- let curY = el.y;
5375
- for (let r = 0; r < el.rows; r++) {
5376
- const rh = el.rowHeights[r] ?? el.height / Math.max(1, el.rows);
5377
- let curX = el.x;
5378
- const isHeader = el.headerRow !== false && r === 0;
5379
- for (let c = 0; c < el.cols; c++) {
5380
- const cw = el.colWidths[c] ?? el.width / Math.max(1, el.cols);
5381
- const cell = el.cells[r]?.[c];
5382
- if (!cell?.mergedInto) {
5383
- const bgCol = parseColorRgb(
5384
- cell?.bg || (isHeader ? el.headerBg || theme.colors.primary : r % 2 === 1 ? el.zebraBg || "#f8fafc" : "#ffffff")
5385
- );
5386
- const fgCol = parseColorRgb(
5387
- cell?.color || (isHeader ? el.headerColor || "#ffffff" : theme.colors.text)
5388
- );
5389
- page.drawRectangle({
5390
- x: m.x(curX),
5391
- y: m.rectY(curY, rh),
5392
- width: m.len(cw),
5393
- height: m.len(rh),
5394
- color: (0, import_pdf_lib.rgb)(bgCol.r, bgCol.g, bgCol.b),
5395
- borderColor: (0, import_pdf_lib.rgb)(borderCol.r, borderCol.g, borderCol.b),
5396
- borderWidth: Math.max(0.4, m.len(0.75))
5397
- });
5398
- if (cell?.text) {
5399
- const cellAlign = cell.align ?? "left";
5400
- const tx = cellAlign === "center" ? curX + cw / 2 : cellAlign === "right" ? curX + cw - 8 : curX + 8;
5401
- const cfs = cell.fontSize ?? 11;
5402
- drawSafeTextLine(
5403
- page,
5404
- ctx,
5405
- cell.text,
5406
- m.x(tx),
5407
- m.y(curY + rh / 2 + cfs * 0.35),
5408
- m.len(cfs),
5409
- fgCol,
5410
- Boolean(cell.bold || isHeader),
5411
- cellAlign
5412
- );
5413
- }
5414
- }
5415
- curX += cw;
5416
- }
5417
- curY += rh;
5418
- }
5419
- } else if (el.type === "chart") {
5420
- renderVectorChartOntoPdf(page, ctx, el, theme, tf);
5421
- } else if (el.type === "smartArt") {
5422
- renderSmartArtOntoPdf(page, ctx, el, theme, tf);
5423
- } else if (el.type === "image" && el.src.startsWith("data:image/")) {
5424
- try {
5425
- const comma = el.src.indexOf(",");
5426
- const header = el.src.slice(0, comma);
5427
- const b64 = el.src.slice(comma + 1);
5428
- const bytes = typeof Buffer !== "undefined" ? new Uint8Array(Buffer.from(b64, "base64")) : Uint8Array.from(atob(b64), (ch) => ch.charCodeAt(0));
5429
- if (header.includes("png")) {
5430
- const img = await ctx.pdfDoc.embedPng(bytes);
5431
- page.drawImage(img, {
5432
- x: m.x(el.x),
5433
- y: m.rectY(el.y, el.height),
5434
- width: m.len(el.width),
5435
- height: m.len(el.height)
5436
- });
5437
- } else if (header.includes("jpeg") || header.includes("jpg")) {
5438
- const img = await ctx.pdfDoc.embedJpg(bytes);
5439
- page.drawImage(img, {
5440
- x: m.x(el.x),
5441
- y: m.rectY(el.y, el.height),
5442
- width: m.len(el.width),
5443
- height: m.len(el.height)
5444
- });
5445
- }
5446
- } catch {
5447
- }
5448
- } else if (el.type === "codeBlock") {
5449
- page.drawRectangle({
5450
- x: m.x(el.x),
5451
- y: m.rectY(el.y, el.height),
5452
- width: m.len(el.width),
5453
- height: m.len(el.height),
5454
- color: (0, import_pdf_lib.rgb)(0.06, 0.09, 0.16)
5455
- });
5456
- el.code.split("\n").slice(0, 12).forEach((ln, idx) => {
5457
- drawSafeTextLine(
5458
- page,
5459
- ctx,
5460
- ln,
5461
- m.x(el.x + 12),
5462
- m.y(el.y + 24 + idx * 15),
5463
- m.len(el.fontSize ?? 11),
5464
- { r: 0.89, g: 0.91, b: 0.94 },
5465
- false,
5466
- "left"
5467
- );
5468
- });
5469
- } else if (el.type === "sheetEmbed") {
5470
- page.drawRectangle({
5471
- x: m.x(el.x),
5472
- y: m.rectY(el.y, el.height),
5473
- width: m.len(el.width),
5474
- height: m.len(el.height),
5475
- color: (0, import_pdf_lib.rgb)(1, 1, 1),
5476
- borderColor: (0, import_pdf_lib.rgb)(0.06, 0.72, 0.5),
5477
- borderWidth: m.len(1)
5478
- });
5479
- if (el.title) {
5480
- drawSafeTextLine(
5481
- page,
5482
- ctx,
5483
- el.title,
5484
- m.x(el.x + 10),
5485
- m.y(el.y + 18),
5486
- m.len(12),
5487
- parseColorRgb(el.accentColor || "#059669"),
5488
- true,
5489
- "left"
5490
- );
5491
- }
5492
- }
6241
+ await renderSingleElementOntoPdf(page, ctx, el, slide.elements, theme, tf);
6242
+ }
6243
+ if (master?.footerText) {
6244
+ drawSafeTextLine(
6245
+ page,
6246
+ ctx,
6247
+ master.footerText,
6248
+ m.x(18),
6249
+ m.y(slideH - 14),
6250
+ m.len(9.5),
6251
+ { r: 0.4, g: 0.45, b: 0.53 },
6252
+ false,
6253
+ "left"
6254
+ );
5493
6255
  }
5494
6256
  if (slide.showSlideNumber !== false) {
5495
6257
  drawSafeTextLine(
@@ -5506,7 +6268,7 @@ async function renderSlideOntoPdfFrame(page, ctx, slide, snapshot, slideIndexOne
5506
6268
  }
5507
6269
  }
5508
6270
  async function exportSlidesToPdfBytes(rawSnapshot, options) {
5509
- const snapshot = options?.datasets ? compileSlidesWithDataset(rawSnapshot, options.datasets, options.templateOptions) : import_core5.Tools.deepClone(rawSnapshot);
6271
+ const snapshot = options?.datasets ? compileSlidesWithDataset(rawSnapshot, options.datasets, options.templateOptions) : import_core6.Tools.deepClone(rawSnapshot);
5510
6272
  const pdfDoc = await import_pdf_lib.PDFDocument.create();
5511
6273
  pdfDoc.setTitle(snapshot.name || "Univer Slides Presentation");
5512
6274
  pdfDoc.setCreator("Univer Slides (@yudaocode/univer-slides)");
@@ -5615,8 +6377,8 @@ async function exportSlidesToPdfBytes(rawSnapshot, options) {
5615
6377
  }
5616
6378
 
5617
6379
  // src/services/slide-io.service.ts
5618
- var ISlideIoService = (0, import_core6.createIdentifier)("yudao.slides.io-service");
5619
- var SlideIoService = class extends import_core6.Disposable {
6380
+ var ISlideIoService = (0, import_core7.createIdentifier)("yudao.slides.io-service");
6381
+ var SlideIoService = class extends import_core7.Disposable {
5620
6382
  constructor() {
5621
6383
  super(...arguments);
5622
6384
  this._adapter = {};
@@ -5670,16 +6432,16 @@ var SlideIoService = class extends import_core6.Disposable {
5670
6432
  };
5671
6433
 
5672
6434
  // src/commands/mutations/slide.mutation.ts
5673
- var import_core7 = require("@univerjs/core");
6435
+ var import_core8 = require("@univerjs/core");
5674
6436
  var ApplySlideSnapshotMutation = {
5675
6437
  id: "slides.mutation.apply-snapshot",
5676
- type: import_core7.CommandType.MUTATION,
6438
+ type: import_core8.CommandType.MUTATION,
5677
6439
  handler: (accessor, params) => {
5678
6440
  if (!params?.unitId || !params.snapshot) return false;
5679
- const instanceService = accessor.get(import_core7.IUniverInstanceService);
6441
+ const instanceService = accessor.get(import_core8.IUniverInstanceService);
5680
6442
  const unit = instanceService.getUnit(
5681
6443
  params.unitId,
5682
- import_core7.UniverInstanceType.UNIVER_SLIDE
6444
+ import_core8.UniverInstanceType.UNIVER_SLIDE
5683
6445
  );
5684
6446
  if (!unit) return false;
5685
6447
  unit.__replaceSnapshot(params.snapshot, params.preserveUnitId ?? true);
@@ -5691,13 +6453,13 @@ var ApplySlideSnapshotMutation = {
5691
6453
  };
5692
6454
  var SetActiveSlideMutation = {
5693
6455
  id: "slides.mutation.set-active-slide",
5694
- type: import_core7.CommandType.MUTATION,
6456
+ type: import_core8.CommandType.MUTATION,
5695
6457
  handler: (accessor, params) => {
5696
6458
  if (!params?.unitId || !params.slideId) return false;
5697
- const instanceService = accessor.get(import_core7.IUniverInstanceService);
6459
+ const instanceService = accessor.get(import_core8.IUniverInstanceService);
5698
6460
  const unit = instanceService.getUnit(
5699
6461
  params.unitId,
5700
- import_core7.UniverInstanceType.UNIVER_SLIDE
6462
+ import_core8.UniverInstanceType.UNIVER_SLIDE
5701
6463
  );
5702
6464
  if (!unit) return false;
5703
6465
  const ok = unit.__setActiveSlideId(params.slideId);
@@ -5709,10 +6471,10 @@ var SetActiveSlideMutation = {
5709
6471
  };
5710
6472
 
5711
6473
  // src/commands/commands/slide.command.ts
5712
- var import_core8 = require("@univerjs/core");
6474
+ var import_core9 = require("@univerjs/core");
5713
6475
  function resolveSlideUnit(accessor, explicitUnitId) {
5714
- const instanceService = accessor.get(import_core8.IUniverInstanceService);
5715
- const unit = explicitUnitId ? instanceService.getUnit(explicitUnitId, import_core8.UniverInstanceType.UNIVER_SLIDE) : instanceService.getCurrentUnitOfType(import_core8.UniverInstanceType.UNIVER_SLIDE);
6476
+ const instanceService = accessor.get(import_core9.IUniverInstanceService);
6477
+ const unit = explicitUnitId ? instanceService.getUnit(explicitUnitId, import_core9.UniverInstanceType.UNIVER_SLIDE) : instanceService.getCurrentUnitOfType(import_core9.UniverInstanceType.UNIVER_SLIDE);
5716
6478
  if (!unit) return null;
5717
6479
  return { unit, unitId: unit.getUnitId() };
5718
6480
  }
@@ -5727,8 +6489,8 @@ function resolveActiveSlideId(accessor, unit, explicitSlideId) {
5727
6489
  return unit.getSlideOrder()[0] ?? null;
5728
6490
  }
5729
6491
  function executeSnapshotMutationWithUndo(accessor, unitId, prevSnapshot, nextSnapshot) {
5730
- const commandService = accessor.get(import_core8.ICommandService);
5731
- const undoRedoService = accessor.get(import_core8.IUndoRedoService);
6492
+ const commandService = accessor.get(import_core9.ICommandService);
6493
+ const undoRedoService = accessor.get(import_core9.IUndoRedoService);
5732
6494
  const redoParams = { unitId, snapshot: nextSnapshot, preserveUnitId: true };
5733
6495
  const undoParams = { unitId, snapshot: prevSnapshot, preserveUnitId: true };
5734
6496
  const ok = commandService.syncExecuteCommand(ApplySlideSnapshotMutation.id, redoParams);
@@ -5742,15 +6504,22 @@ function executeSnapshotMutationWithUndo(accessor, unitId, prevSnapshot, nextSna
5742
6504
  return Boolean(ok);
5743
6505
  }
5744
6506
  function createDefaultSlideElement(elementType, partial, theme) {
5745
- const id = partial?.id || `el-${(0, import_core8.generateRandomId)(6)}`;
6507
+ const id = partial?.id || `el-${(0, import_core9.generateRandomId)(6)}`;
5746
6508
  const primary = theme?.colors.primary ?? "#1d4ed8";
5747
6509
  const accent1 = theme?.colors.accent1 ?? "#2563eb";
5748
6510
  const accent2 = theme?.colors.accent2 ?? "#0ea5e9";
5749
6511
  const textColor = theme?.colors.text ?? "#0f172a";
6512
+ const baseExtras = {
6513
+ ...partial?.morphName ? { morphName: partial.morphName } : {},
6514
+ ...partial?.action ? { action: import_core9.Tools.deepClone(partial.action) } : {},
6515
+ ...partial?.locked !== void 0 ? { locked: partial.locked } : {},
6516
+ ...partial?.hidden !== void 0 ? { hidden: partial.hidden } : {}
6517
+ };
5750
6518
  switch (elementType) {
5751
6519
  case "text": {
5752
6520
  const p = partial ?? {};
5753
6521
  return syncTextAndParagraphs({
6522
+ ...baseExtras,
5754
6523
  id,
5755
6524
  type: "text",
5756
6525
  name: p.name ?? "\u6587\u672C\u6846",
@@ -5761,7 +6530,7 @@ function createDefaultSlideElement(elementType, partial, theme) {
5761
6530
  rotation: p.rotation ?? 0,
5762
6531
  opacity: p.opacity ?? 1,
5763
6532
  text: p.text ?? "\u53CC\u51FB\u8F93\u5165\u6F14\u793A\u6587\u672C\u5185\u5BB9",
5764
- ...p.paragraphs ? { paragraphs: import_core8.Tools.deepClone(p.paragraphs) } : {},
6533
+ ...p.paragraphs ? { paragraphs: import_core9.Tools.deepClone(p.paragraphs) } : {},
5765
6534
  fontFamily: p.fontFamily ?? theme?.minorFont,
5766
6535
  fontSize: p.fontSize ?? 20,
5767
6536
  fontWeight: p.fontWeight ?? "normal",
@@ -5777,7 +6546,7 @@ function createDefaultSlideElement(elementType, partial, theme) {
5777
6546
  ...p.strokeWidth !== void 0 ? { strokeWidth: p.strokeWidth } : {},
5778
6547
  ...p.borderRadius !== void 0 ? { borderRadius: p.borderRadius } : {},
5779
6548
  ...p.paddingPt !== void 0 ? { paddingPt: p.paddingPt } : {},
5780
- ...p.wordArt ? { wordArt: import_core8.Tools.deepClone(p.wordArt) } : {},
6549
+ ...p.wordArt ? { wordArt: import_core9.Tools.deepClone(p.wordArt) } : {},
5781
6550
  ...p.placeholderRole ? { placeholderRole: p.placeholderRole } : {},
5782
6551
  ...p.datasetBinding ? { datasetBinding: p.datasetBinding } : {}
5783
6552
  });
@@ -5785,6 +6554,7 @@ function createDefaultSlideElement(elementType, partial, theme) {
5785
6554
  case "shape": {
5786
6555
  const p = partial ?? {};
5787
6556
  return {
6557
+ ...baseExtras,
5788
6558
  id,
5789
6559
  type: "shape",
5790
6560
  name: p.name ?? "\u51E0\u4F55\u5F62\u72B6",
@@ -5816,6 +6586,7 @@ function createDefaultSlideElement(elementType, partial, theme) {
5816
6586
  const width = p.width ?? 220;
5817
6587
  const height = p.height ?? 60;
5818
6588
  return {
6589
+ ...baseExtras,
5819
6590
  id,
5820
6591
  type: "connector",
5821
6592
  name: p.name ?? "\u8FDE\u63A5\u7EBF",
@@ -5845,6 +6616,7 @@ function createDefaultSlideElement(elementType, partial, theme) {
5845
6616
  const defaultSvg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 200"><rect width="320" height="200" rx="12" fill="#eff6ff" stroke="#93c5fd" stroke-width="2"/><circle cx="96" cy="72" r="22" fill="#60a5fa"/><path d="M36 168 L118 96 L182 148 L228 112 L288 168 Z" fill="#3b82f6" opacity="0.85"/></svg>`;
5846
6617
  const fallbackSrc = `data:image/svg+xml;utf8,${encodeURIComponent(defaultSvg)}`;
5847
6618
  return {
6619
+ ...baseExtras,
5848
6620
  id,
5849
6621
  type: elementType,
5850
6622
  name: p.name ?? (elementType === "svg" ? "\u77E2\u91CF\u56FE\u6807" : "\u56FE\u7247"),
@@ -5870,7 +6642,7 @@ function createDefaultSlideElement(elementType, partial, theme) {
5870
6642
  const height = p.height ?? 200;
5871
6643
  const colWidths = p.colWidths ?? Array.from({ length: cols }, () => Math.round(width / cols));
5872
6644
  const rowHeights = p.rowHeights ?? Array.from({ length: rows }, () => Math.round(height / rows));
5873
- const cells = p.cells ? import_core8.Tools.deepClone(p.cells) : Array.from(
6645
+ const cells = p.cells ? import_core9.Tools.deepClone(p.cells) : Array.from(
5874
6646
  { length: rows },
5875
6647
  (_, r) => Array.from({ length: cols }, (__, c) => ({
5876
6648
  text: r === 0 ? `\u5217\u6807\u9898 ${c + 1}` : `\u6570\u636E R${r}C${c + 1}`,
@@ -5879,6 +6651,7 @@ function createDefaultSlideElement(elementType, partial, theme) {
5879
6651
  }))
5880
6652
  );
5881
6653
  return {
6654
+ ...baseExtras,
5882
6655
  id,
5883
6656
  type: "table",
5884
6657
  name: p.name ?? "\u6570\u636E\u8868\u683C",
@@ -5902,6 +6675,7 @@ function createDefaultSlideElement(elementType, partial, theme) {
5902
6675
  case "chart": {
5903
6676
  const p = partial ?? {};
5904
6677
  return {
6678
+ ...baseExtras,
5905
6679
  id,
5906
6680
  type: "chart",
5907
6681
  name: p.name ?? "\u7EDF\u8BA1\u56FE\u8868",
@@ -5912,7 +6686,7 @@ function createDefaultSlideElement(elementType, partial, theme) {
5912
6686
  chartType: p.chartType ?? "column",
5913
6687
  title: p.title ?? "\u5B63\u5EA6\u6838\u5FC3\u6307\u6807\u5BF9\u6BD4",
5914
6688
  categories: p.categories ? [...p.categories] : ["Q1", "Q2", "Q3", "Q4"],
5915
- series: p.series ? import_core8.Tools.deepClone(p.series) : [
6689
+ series: p.series ? import_core9.Tools.deepClone(p.series) : [
5916
6690
  { name: "\u672C\u671F\u5B9E\u9645", values: [120, 158, 186, 224], color: accent1 },
5917
6691
  { name: "\u540C\u671F\u57FA\u51C6", values: [98, 126, 145, 178], color: accent2 }
5918
6692
  ],
@@ -5922,12 +6696,13 @@ function createDefaultSlideElement(elementType, partial, theme) {
5922
6696
  showValues: p.showValues ?? true,
5923
6697
  ...p.datasetCode ? { datasetCode: p.datasetCode } : {},
5924
6698
  ...p.categoryField ? { categoryField: p.categoryField } : {},
5925
- ...p.valueFields ? { valueFields: import_core8.Tools.deepClone(p.valueFields) } : {}
6699
+ ...p.valueFields ? { valueFields: import_core9.Tools.deepClone(p.valueFields) } : {}
5926
6700
  };
5927
6701
  }
5928
6702
  case "smartArt": {
5929
6703
  const p = partial ?? {};
5930
6704
  return {
6705
+ ...baseExtras,
5931
6706
  id,
5932
6707
  type: "smartArt",
5933
6708
  name: p.name ?? "\u667A\u80FD\u56FE\u793A",
@@ -5937,10 +6712,10 @@ function createDefaultSlideElement(elementType, partial, theme) {
5937
6712
  height: p.height ?? 240,
5938
6713
  layout: p.layout ?? "process",
5939
6714
  title: p.title ?? "\u6838\u5FC3\u5B9E\u65BD\u6D41\u7A0B",
5940
- items: p.items ? import_core8.Tools.deepClone(p.items) : [
5941
- { id: `sa-${(0, import_core8.generateRandomId)(4)}`, title: "\u9700\u6C42\u6D1E\u5BDF", subtitle: "\u4E1A\u52A1\u75DB\u70B9\u68B3\u7406" },
5942
- { id: `sa-${(0, import_core8.generateRandomId)(4)}`, title: "\u67B6\u6784\u8BBE\u8BA1", subtitle: "\u6A21\u578B\u4E0E\u6307\u6807\u5B9A\u4E49" },
5943
- { id: `sa-${(0, import_core8.generateRandomId)(4)}`, title: "\u654F\u6377\u4EA4\u4ED8", subtitle: "\u81EA\u52A8\u5316\u9A8C\u8BC1\u4E0A\u7EBF" }
6715
+ items: p.items ? import_core9.Tools.deepClone(p.items) : [
6716
+ { id: `sa-${(0, import_core9.generateRandomId)(4)}`, title: "\u9700\u6C42\u6D1E\u5BDF", subtitle: "\u4E1A\u52A1\u75DB\u70B9\u68B3\u7406" },
6717
+ { id: `sa-${(0, import_core9.generateRandomId)(4)}`, title: "\u67B6\u6784\u8BBE\u8BA1", subtitle: "\u6A21\u578B\u4E0E\u6307\u6807\u5B9A\u4E49" },
6718
+ { id: `sa-${(0, import_core9.generateRandomId)(4)}`, title: "\u654F\u6377\u4EA4\u4ED8", subtitle: "\u81EA\u52A8\u5316\u9A8C\u8BC1\u4E0A\u7EBF" }
5944
6719
  ],
5945
6720
  ...p.accentColor ? { accentColor: p.accentColor } : {}
5946
6721
  };
@@ -5948,6 +6723,7 @@ function createDefaultSlideElement(elementType, partial, theme) {
5948
6723
  case "codeBlock": {
5949
6724
  const p = partial ?? {};
5950
6725
  return {
6726
+ ...baseExtras,
5951
6727
  id,
5952
6728
  type: "codeBlock",
5953
6729
  name: p.name ?? "\u4EE3\u7801\u5757",
@@ -5967,6 +6743,7 @@ console.log('Exported bytes:', pptxBytes.byteLength);`,
5967
6743
  case "sheetEmbed": {
5968
6744
  const p = partial ?? {};
5969
6745
  return {
6746
+ ...baseExtras,
5970
6747
  id,
5971
6748
  type: "sheetEmbed",
5972
6749
  name: p.name ?? "\u5DE5\u4F5C\u8868\u5F15\u7528",
@@ -5976,7 +6753,7 @@ console.log('Exported bytes:', pptxBytes.byteLength);`,
5976
6753
  height: p.height ?? 220,
5977
6754
  title: p.title ?? "\u8D22\u52A1\u9884\u7B97\u6D4B\u7B97\u6A21\u578B\u5FEB\u7167",
5978
6755
  headers: p.headers ? [...p.headers] : ["\u79D1\u76EE", "Q1", "Q2", "Q3", "Q4"],
5979
- rows: p.rows ? import_core8.Tools.deepClone(p.rows) : [
6756
+ rows: p.rows ? import_core9.Tools.deepClone(p.rows) : [
5980
6757
  ["\u4E3B\u8425\u4E1A\u52A1\u6536\u5165", 3200, 3680, 4150, 4890],
5981
6758
  ["\u7814\u53D1\u6295\u5165", 640, 710, 780, 860],
5982
6759
  ["\u7ECF\u8425\u5229\u6DA6", 890, 1080, 1320, 1690]
@@ -5985,22 +6762,46 @@ console.log('Exported bytes:', pptxBytes.byteLength);`,
5985
6762
  accentColor: p.accentColor ?? "#059669"
5986
6763
  };
5987
6764
  }
6765
+ case "video":
6766
+ case "audio": {
6767
+ const p = partial ?? {};
6768
+ const isVideo = elementType === "video";
6769
+ return {
6770
+ ...baseExtras,
6771
+ id,
6772
+ type: elementType,
6773
+ name: p.name ?? (isVideo ? "\u89C6\u9891\u5A92\u4F53" : "\u97F3\u9891\u5A92\u4F53"),
6774
+ x: p.x ?? (isVideo ? 270 : 320),
6775
+ y: p.y ?? (isVideo ? 150 : 230),
6776
+ width: p.width ?? (isVideo ? 420 : 320),
6777
+ height: p.height ?? (isVideo ? 240 : 64),
6778
+ rotation: p.rotation ?? 0,
6779
+ opacity: p.opacity ?? 1,
6780
+ src: p.src ?? "",
6781
+ ...p.poster ? { poster: p.poster } : {},
6782
+ autoPlay: p.autoPlay ?? false,
6783
+ loop: p.loop ?? false,
6784
+ muted: p.muted ?? false,
6785
+ ...p.startTimeSec !== void 0 ? { startTimeSec: p.startTimeSec } : {},
6786
+ ...p.endTimeSec !== void 0 ? { endTimeSec: p.endTimeSec } : {}
6787
+ };
6788
+ }
5988
6789
  }
5989
6790
  }
5990
6791
  var AddSlidePageCommand = {
5991
6792
  id: "slides.command.add-page",
5992
- type: import_core8.CommandType.COMMAND,
6793
+ type: import_core9.CommandType.COMMAND,
5993
6794
  handler: (accessor, params) => {
5994
6795
  const ctx = resolveSlideUnit(accessor, params?.unitId);
5995
6796
  if (!ctx) return false;
5996
6797
  const prev = ctx.unit.save();
5997
- const next = import_core8.Tools.deepClone(prev);
6798
+ const next = import_core9.Tools.deepClone(prev);
5998
6799
  const layout = findLayoutByTypeOrId(next.layouts, params?.layoutId ?? params?.slide?.layoutId ?? "titleAndContent");
5999
6800
  const built = params?.slide?.elements ? {
6000
- elements: import_core8.Tools.deepClone(params.slide.elements),
6801
+ elements: import_core9.Tools.deepClone(params.slide.elements),
6001
6802
  elementOrder: params.slide.elementOrder ? [...params.slide.elementOrder] : Object.keys(params.slide.elements)
6002
6803
  } : createElementsFromLayout(layout, next.theme, next.slideSize);
6003
- const slideId = params?.slide?.id || `slide-${(0, import_core8.generateRandomId)(6)}`;
6804
+ const slideId = params?.slide?.id || `slide-${(0, import_core9.generateRandomId)(6)}`;
6004
6805
  const newSlide = {
6005
6806
  id: slideId,
6006
6807
  title: params?.title ?? params?.slide?.title ?? `\u5E7B\u706F\u7247 ${next.slideOrder.length + 1}`,
@@ -6008,9 +6809,9 @@ var AddSlidePageCommand = {
6008
6809
  hidden: params?.slide?.hidden ?? false,
6009
6810
  showSlideNumber: params?.slide?.showSlideNumber ?? layout.type !== "title",
6010
6811
  speakerNotes: params?.slide?.speakerNotes ?? "",
6011
- background: params?.slide?.background ? import_core8.Tools.deepClone(params.slide.background) : { type: "solid", color: next.theme.colors.background },
6012
- transition: params?.slide?.transition ? import_core8.Tools.deepClone(params.slide.transition) : { type: "fade", durationMs: 400 },
6013
- animations: params?.slide?.animations ? import_core8.Tools.deepClone(params.slide.animations) : [],
6812
+ background: params?.slide?.background ? import_core9.Tools.deepClone(params.slide.background) : { type: "solid", color: next.theme.colors.background },
6813
+ transition: params?.slide?.transition ? import_core9.Tools.deepClone(params.slide.transition) : { type: "fade", durationMs: 400 },
6814
+ animations: params?.slide?.animations ? import_core9.Tools.deepClone(params.slide.animations) : [],
6014
6815
  elementOrder: built.elementOrder,
6015
6816
  elements: built.elements
6016
6817
  };
@@ -6036,7 +6837,7 @@ var AddSlidePageCommand = {
6036
6837
  };
6037
6838
  var DuplicateSlidePageCommand = {
6038
6839
  id: "slides.command.duplicate-page",
6039
- type: import_core8.CommandType.COMMAND,
6840
+ type: import_core9.CommandType.COMMAND,
6040
6841
  handler: (accessor, params) => {
6041
6842
  const ctx = resolveSlideUnit(accessor, params?.unitId);
6042
6843
  if (!ctx) return false;
@@ -6045,17 +6846,17 @@ var DuplicateSlidePageCommand = {
6045
6846
  const prev = ctx.unit.save();
6046
6847
  const sourceSlide = prev.slides[sourceId];
6047
6848
  if (!sourceSlide) return false;
6048
- const next = import_core8.Tools.deepClone(prev);
6049
- const dupSlideId = `slide-${(0, import_core8.generateRandomId)(6)}`;
6849
+ const next = import_core9.Tools.deepClone(prev);
6850
+ const dupSlideId = `slide-${(0, import_core9.generateRandomId)(6)}`;
6050
6851
  const idMap = /* @__PURE__ */ new Map();
6051
6852
  const newElements = {};
6052
6853
  const newOrder = [];
6053
6854
  for (const oldElId of sourceSlide.elementOrder) {
6054
6855
  const el = sourceSlide.elements[oldElId];
6055
6856
  if (!el) continue;
6056
- const newElId = `el-${(0, import_core8.generateRandomId)(6)}`;
6857
+ const newElId = `el-${(0, import_core9.generateRandomId)(6)}`;
6057
6858
  idMap.set(oldElId, newElId);
6058
- newElements[newElId] = { ...import_core8.Tools.deepClone(el), id: newElId };
6859
+ newElements[newElId] = { ...import_core9.Tools.deepClone(el), id: newElId };
6059
6860
  newOrder.push(newElId);
6060
6861
  }
6061
6862
  for (const el of Object.values(newElements)) {
@@ -6069,12 +6870,12 @@ var DuplicateSlidePageCommand = {
6069
6870
  }
6070
6871
  }
6071
6872
  const newAnimations = (sourceSlide.animations ?? []).map((anim) => ({
6072
- ...import_core8.Tools.deepClone(anim),
6073
- id: `anim-${(0, import_core8.generateRandomId)(6)}`,
6873
+ ...import_core9.Tools.deepClone(anim),
6874
+ id: `anim-${(0, import_core9.generateRandomId)(6)}`,
6074
6875
  elementId: idMap.get(anim.elementId) ?? anim.elementId
6075
6876
  }));
6076
6877
  next.slides[dupSlideId] = {
6077
- ...import_core8.Tools.deepClone(sourceSlide),
6878
+ ...import_core9.Tools.deepClone(sourceSlide),
6078
6879
  id: dupSlideId,
6079
6880
  title: `${sourceSlide.title} (\u526F\u672C)`,
6080
6881
  elementOrder: newOrder,
@@ -6096,7 +6897,7 @@ var DuplicateSlidePageCommand = {
6096
6897
  };
6097
6898
  var DeleteSlidePageCommand = {
6098
6899
  id: "slides.command.delete-page",
6099
- type: import_core8.CommandType.COMMAND,
6900
+ type: import_core9.CommandType.COMMAND,
6100
6901
  handler: (accessor, params) => {
6101
6902
  const ctx = resolveSlideUnit(accessor, params?.unitId);
6102
6903
  if (!ctx) return false;
@@ -6104,7 +6905,7 @@ var DeleteSlidePageCommand = {
6104
6905
  if (prev.slideOrder.length <= 1) return false;
6105
6906
  const targetId = resolveActiveSlideId(accessor, ctx.unit, params?.slideId);
6106
6907
  if (!targetId || !prev.slides[targetId]) return false;
6107
- const next = import_core8.Tools.deepClone(prev);
6908
+ const next = import_core9.Tools.deepClone(prev);
6108
6909
  const oldIdx = next.slideOrder.indexOf(targetId);
6109
6910
  delete next.slides[targetId];
6110
6911
  next.slideOrder = next.slideOrder.filter((id) => id !== targetId);
@@ -6120,7 +6921,7 @@ var DeleteSlidePageCommand = {
6120
6921
  };
6121
6922
  var ReorderSlidePagesCommand = {
6122
6923
  id: "slides.command.reorder-pages",
6123
- type: import_core8.CommandType.COMMAND,
6924
+ type: import_core9.CommandType.COMMAND,
6124
6925
  handler: (accessor, params) => {
6125
6926
  const ctx = resolveSlideUnit(accessor, params?.unitId);
6126
6927
  if (!ctx) return false;
@@ -6138,7 +6939,7 @@ var ReorderSlidePagesCommand = {
6138
6939
  } else {
6139
6940
  return false;
6140
6941
  }
6141
- const next = import_core8.Tools.deepClone(prev);
6942
+ const next = import_core9.Tools.deepClone(prev);
6142
6943
  next.slideOrder = nextOrder;
6143
6944
  for (const sec of next.sections) {
6144
6945
  const set = new Set(sec.slideIds);
@@ -6149,7 +6950,7 @@ var ReorderSlidePagesCommand = {
6149
6950
  };
6150
6951
  var UpdateSlidePagePropsCommand = {
6151
6952
  id: "slides.command.update-page-props",
6152
- type: import_core8.CommandType.COMMAND,
6953
+ type: import_core9.CommandType.COMMAND,
6153
6954
  handler: (accessor, params) => {
6154
6955
  if (!params?.patch) return false;
6155
6956
  const ctx = resolveSlideUnit(accessor, params.unitId);
@@ -6157,7 +6958,7 @@ var UpdateSlidePagePropsCommand = {
6157
6958
  const targetSlideId = resolveActiveSlideId(accessor, ctx.unit, params.slideId);
6158
6959
  if (!targetSlideId) return false;
6159
6960
  const prev = ctx.unit.save();
6160
- const next = import_core8.Tools.deepClone(prev);
6961
+ const next = import_core9.Tools.deepClone(prev);
6161
6962
  const targetIds = params.applyToAllSlides ? next.slideOrder : [targetSlideId];
6162
6963
  for (const sid of targetIds) {
6163
6964
  const slide = next.slides[sid];
@@ -6175,10 +6976,10 @@ var UpdateSlidePagePropsCommand = {
6175
6976
  slide.speakerNotes = params.patch.speakerNotes;
6176
6977
  }
6177
6978
  if (params.patch.background !== void 0) {
6178
- slide.background = import_core8.Tools.deepClone(params.patch.background);
6979
+ slide.background = import_core9.Tools.deepClone(params.patch.background);
6179
6980
  }
6180
6981
  if (params.patch.transition !== void 0) {
6181
- slide.transition = import_core8.Tools.deepClone(params.patch.transition);
6982
+ slide.transition = import_core9.Tools.deepClone(params.patch.transition);
6182
6983
  }
6183
6984
  if (params.patch.layoutId !== void 0) {
6184
6985
  const layout = findLayoutByTypeOrId(next.layouts, params.patch.layoutId);
@@ -6203,12 +7004,12 @@ var UpdateSlidePagePropsCommand = {
6203
7004
  };
6204
7005
  var SetActiveSlidePageCommand = {
6205
7006
  id: "slides.command.set-active-page",
6206
- type: import_core8.CommandType.COMMAND,
7007
+ type: import_core9.CommandType.COMMAND,
6207
7008
  handler: (accessor, params) => {
6208
7009
  if (!params?.slideId) return false;
6209
7010
  const ctx = resolveSlideUnit(accessor, params.unitId);
6210
7011
  if (!ctx) return false;
6211
- const commandService = accessor.get(import_core8.ICommandService);
7012
+ const commandService = accessor.get(import_core9.ICommandService);
6212
7013
  return Boolean(
6213
7014
  commandService.syncExecuteCommand(SetActiveSlideMutation.id, {
6214
7015
  unitId: ctx.unitId,
@@ -6219,19 +7020,19 @@ var SetActiveSlidePageCommand = {
6219
7020
  };
6220
7021
  var AddSlideSectionCommand = {
6221
7022
  id: "slides.command.add-section",
6222
- type: import_core8.CommandType.COMMAND,
7023
+ type: import_core9.CommandType.COMMAND,
6223
7024
  handler: (accessor, params) => {
6224
7025
  const ctx = resolveSlideUnit(accessor, params?.unitId);
6225
7026
  if (!ctx) return false;
6226
7027
  const prev = ctx.unit.save();
6227
- const next = import_core8.Tools.deepClone(prev);
7028
+ const next = import_core9.Tools.deepClone(prev);
6228
7029
  const assignedSlideIds = params?.slideIds ? [...params.slideIds] : [next.activeSlideId];
6229
7030
  const assignedSet = new Set(assignedSlideIds);
6230
7031
  for (const sec of next.sections) {
6231
7032
  sec.slideIds = sec.slideIds.filter((id) => !assignedSet.has(id));
6232
7033
  }
6233
7034
  const newSec = {
6234
- id: `sec-${(0, import_core8.generateRandomId)(6)}`,
7035
+ id: `sec-${(0, import_core9.generateRandomId)(6)}`,
6235
7036
  title: params?.title ?? `\u7AE0\u8282 ${next.sections.length + 1}`,
6236
7037
  slideIds: assignedSlideIds,
6237
7038
  collapsed: false
@@ -6242,13 +7043,13 @@ var AddSlideSectionCommand = {
6242
7043
  };
6243
7044
  var UpdateSlideSectionCommand = {
6244
7045
  id: "slides.command.update-section",
6245
- type: import_core8.CommandType.COMMAND,
7046
+ type: import_core9.CommandType.COMMAND,
6246
7047
  handler: (accessor, params) => {
6247
7048
  if (!params?.sectionId || !params.patch) return false;
6248
7049
  const ctx = resolveSlideUnit(accessor, params.unitId);
6249
7050
  if (!ctx) return false;
6250
7051
  const prev = ctx.unit.save();
6251
- const next = import_core8.Tools.deepClone(prev);
7052
+ const next = import_core9.Tools.deepClone(prev);
6252
7053
  const sec = next.sections.find((s) => s.id === params.sectionId);
6253
7054
  if (!sec) return false;
6254
7055
  if (params.patch.title !== void 0) sec.title = params.patch.title;
@@ -6259,14 +7060,14 @@ var UpdateSlideSectionCommand = {
6259
7060
  };
6260
7061
  var DeleteSlideSectionCommand = {
6261
7062
  id: "slides.command.delete-section",
6262
- type: import_core8.CommandType.COMMAND,
7063
+ type: import_core9.CommandType.COMMAND,
6263
7064
  handler: (accessor, params) => {
6264
7065
  if (!params?.sectionId) return false;
6265
7066
  const ctx = resolveSlideUnit(accessor, params.unitId);
6266
7067
  if (!ctx) return false;
6267
7068
  const prev = ctx.unit.save();
6268
7069
  if (prev.sections.length <= 1) return false;
6269
- const next = import_core8.Tools.deepClone(prev);
7070
+ const next = import_core9.Tools.deepClone(prev);
6270
7071
  const idx = next.sections.findIndex((s) => s.id === params.sectionId);
6271
7072
  if (idx < 0) return false;
6272
7073
  const removed = next.sections[idx];
@@ -6282,14 +7083,14 @@ var DeleteSlideSectionCommand = {
6282
7083
  };
6283
7084
  var AddSlideElementCommand = {
6284
7085
  id: "slides.command.add-element",
6285
- type: import_core8.CommandType.COMMAND,
7086
+ type: import_core9.CommandType.COMMAND,
6286
7087
  handler: (accessor, params) => {
6287
7088
  const ctx = resolveSlideUnit(accessor, params?.unitId);
6288
7089
  if (!ctx) return false;
6289
7090
  const slideId = resolveActiveSlideId(accessor, ctx.unit, params?.slideId);
6290
7091
  if (!slideId) return false;
6291
7092
  const prev = ctx.unit.save();
6292
- const next = import_core8.Tools.deepClone(prev);
7093
+ const next = import_core9.Tools.deepClone(prev);
6293
7094
  const slide = next.slides[slideId];
6294
7095
  if (!slide) return false;
6295
7096
  const type = params?.elementType ?? params?.element?.type ?? "text";
@@ -6310,7 +7111,7 @@ var AddSlideElementCommand = {
6310
7111
  };
6311
7112
  var UpdateSlideElementsCommand = {
6312
7113
  id: "slides.command.update-elements",
6313
- type: import_core8.CommandType.COMMAND,
7114
+ type: import_core9.CommandType.COMMAND,
6314
7115
  handler: (accessor, params) => {
6315
7116
  if (!params?.updates?.length) return false;
6316
7117
  const ctx = resolveSlideUnit(accessor, params.unitId);
@@ -6318,14 +7119,14 @@ var UpdateSlideElementsCommand = {
6318
7119
  const slideId = resolveActiveSlideId(accessor, ctx.unit, params.slideId);
6319
7120
  if (!slideId) return false;
6320
7121
  const prev = ctx.unit.save();
6321
- const next = import_core8.Tools.deepClone(prev);
7122
+ const next = import_core9.Tools.deepClone(prev);
6322
7123
  const slide = next.slides[slideId];
6323
7124
  if (!slide) return false;
6324
7125
  let changed = false;
6325
7126
  for (const upd of params.updates) {
6326
7127
  const existing = slide.elements[upd.id];
6327
7128
  if (!existing) continue;
6328
- let merged = upd.element ? import_core8.Tools.deepClone(upd.element) : { ...existing, ...import_core8.Tools.deepClone(upd.patch ?? {}), id: existing.id };
7129
+ let merged = upd.element ? import_core9.Tools.deepClone(upd.element) : { ...existing, ...import_core9.Tools.deepClone(upd.patch ?? {}), id: existing.id };
6329
7130
  if (merged.type === "text") {
6330
7131
  if (upd.patch && "text" in upd.patch && !("paragraphs" in upd.patch)) {
6331
7132
  delete merged.paragraphs;
@@ -6341,7 +7142,7 @@ var UpdateSlideElementsCommand = {
6341
7142
  };
6342
7143
  var DeleteSlideElementsCommand = {
6343
7144
  id: "slides.command.delete-elements",
6344
- type: import_core8.CommandType.COMMAND,
7145
+ type: import_core9.CommandType.COMMAND,
6345
7146
  handler: (accessor, params) => {
6346
7147
  const ctx = resolveSlideUnit(accessor, params?.unitId);
6347
7148
  if (!ctx) return false;
@@ -6350,7 +7151,7 @@ var DeleteSlideElementsCommand = {
6350
7151
  const ids = params?.elementIds ?? (accessor.has(ISlideSelectionService) ? accessor.get(ISlideSelectionService).getSelectedElementIds() : []);
6351
7152
  if (!ids.length) return false;
6352
7153
  const prev = ctx.unit.save();
6353
- const next = import_core8.Tools.deepClone(prev);
7154
+ const next = import_core9.Tools.deepClone(prev);
6354
7155
  const slide = next.slides[slideId];
6355
7156
  if (!slide) return false;
6356
7157
  const idSet = new Set(ids);
@@ -6375,7 +7176,7 @@ var DeleteSlideElementsCommand = {
6375
7176
  };
6376
7177
  var AlignSlideElementsCommand = {
6377
7178
  id: "slides.command.align-elements",
6378
- type: import_core8.CommandType.COMMAND,
7179
+ type: import_core9.CommandType.COMMAND,
6379
7180
  handler: (accessor, params) => {
6380
7181
  if (!params?.mode) return false;
6381
7182
  const ctx = resolveSlideUnit(accessor, params.unitId);
@@ -6385,7 +7186,7 @@ var AlignSlideElementsCommand = {
6385
7186
  const ids = params.elementIds ?? (accessor.has(ISlideSelectionService) ? accessor.get(ISlideSelectionService).getSelectedElementIds() : []);
6386
7187
  if (!ids.length) return false;
6387
7188
  const prev = ctx.unit.save();
6388
- const next = import_core8.Tools.deepClone(prev);
7189
+ const next = import_core9.Tools.deepClone(prev);
6389
7190
  const slide = next.slides[slideId];
6390
7191
  if (!slide) return false;
6391
7192
  const targets = ids.map((id) => slide.elements[id]).filter((el) => Boolean(el && !el.locked));
@@ -6457,14 +7258,14 @@ var AlignSlideElementsCommand = {
6457
7258
  };
6458
7259
  var ReorderSlideElementLayerCommand = {
6459
7260
  id: "slides.command.reorder-element-layer",
6460
- type: import_core8.CommandType.COMMAND,
7261
+ type: import_core9.CommandType.COMMAND,
6461
7262
  handler: (accessor, params) => {
6462
7263
  const ctx = resolveSlideUnit(accessor, params?.unitId);
6463
7264
  if (!ctx) return false;
6464
7265
  const slideId = resolveActiveSlideId(accessor, ctx.unit, params?.slideId);
6465
7266
  if (!slideId) return false;
6466
7267
  const prev = ctx.unit.save();
6467
- const next = import_core8.Tools.deepClone(prev);
7268
+ const next = import_core9.Tools.deepClone(prev);
6468
7269
  const slide = next.slides[slideId];
6469
7270
  if (!slide) return false;
6470
7271
  if (params?.elementOrder && params.elementOrder.length === slide.elementOrder.length) {
@@ -6497,7 +7298,7 @@ var ReorderSlideElementLayerCommand = {
6497
7298
  };
6498
7299
  var SetSlideAnimationsCommand = {
6499
7300
  id: "slides.command.set-animations",
6500
- type: import_core8.CommandType.COMMAND,
7301
+ type: import_core9.CommandType.COMMAND,
6501
7302
  handler: (accessor, params) => {
6502
7303
  if (!params || !Array.isArray(params.animations)) return false;
6503
7304
  const ctx = resolveSlideUnit(accessor, params.unitId);
@@ -6505,24 +7306,24 @@ var SetSlideAnimationsCommand = {
6505
7306
  const slideId = resolveActiveSlideId(accessor, ctx.unit, params.slideId);
6506
7307
  if (!slideId) return false;
6507
7308
  const prev = ctx.unit.save();
6508
- const next = import_core8.Tools.deepClone(prev);
7309
+ const next = import_core9.Tools.deepClone(prev);
6509
7310
  const slide = next.slides[slideId];
6510
7311
  if (!slide) return false;
6511
- slide.animations = import_core8.Tools.deepClone(params.animations);
7312
+ slide.animations = import_core9.Tools.deepClone(params.animations);
6512
7313
  return executeSnapshotMutationWithUndo(accessor, ctx.unitId, prev, next);
6513
7314
  }
6514
7315
  };
6515
7316
  var UpdateSlideThemeCommand = {
6516
7317
  id: "slides.command.update-theme",
6517
- type: import_core8.CommandType.COMMAND,
7318
+ type: import_core9.CommandType.COMMAND,
6518
7319
  handler: (accessor, params) => {
6519
7320
  if (!params?.theme) return false;
6520
7321
  const ctx = resolveSlideUnit(accessor, params.unitId);
6521
7322
  if (!ctx) return false;
6522
7323
  const prev = ctx.unit.save();
6523
- const next = import_core8.Tools.deepClone(prev);
7324
+ const next = import_core9.Tools.deepClone(prev);
6524
7325
  const oldBg = prev.theme.colors.background;
6525
- next.theme = import_core8.Tools.deepClone(params.theme);
7326
+ next.theme = import_core9.Tools.deepClone(params.theme);
6526
7327
  if (next.masters[0]) {
6527
7328
  next.masters[0].background = { type: "solid", color: next.theme.colors.background };
6528
7329
  }
@@ -6538,13 +7339,13 @@ var UpdateSlideThemeCommand = {
6538
7339
  };
6539
7340
  var SetSlideSizeCommand = {
6540
7341
  id: "slides.command.set-slide-size",
6541
- type: import_core8.CommandType.COMMAND,
7342
+ type: import_core9.CommandType.COMMAND,
6542
7343
  handler: (accessor, params) => {
6543
7344
  if (!params) return false;
6544
7345
  const ctx = resolveSlideUnit(accessor, params.unitId);
6545
7346
  if (!ctx) return false;
6546
7347
  const prev = ctx.unit.save();
6547
- const next = import_core8.Tools.deepClone(prev);
7348
+ const next = import_core9.Tools.deepClone(prev);
6548
7349
  let nextSize;
6549
7350
  if (params.preset && params.preset !== "custom" && SLIDE_SIZE_PRESETS[params.preset]) {
6550
7351
  nextSize = { ...SLIDE_SIZE_PRESETS[params.preset] };
@@ -6611,13 +7412,13 @@ function countSlideTextMatches(snapshot, query, options) {
6611
7412
  }
6612
7413
  var FindAndReplaceSlideTextCommand = {
6613
7414
  id: "slides.command.find-replace-text",
6614
- type: import_core8.CommandType.COMMAND,
7415
+ type: import_core9.CommandType.COMMAND,
6615
7416
  handler: (accessor, params) => {
6616
7417
  if (!params?.findText) return false;
6617
7418
  const ctx = resolveSlideUnit(accessor, params.unitId);
6618
7419
  if (!ctx) return false;
6619
7420
  const prev = ctx.unit.save();
6620
- const next = import_core8.Tools.deepClone(prev);
7421
+ const next = import_core9.Tools.deepClone(prev);
6621
7422
  const regex = new RegExp(escapeRegExp(params.findText), params.matchCase ? "g" : "gi");
6622
7423
  let replacedCount = 0;
6623
7424
  const replaceIn = (str) => str.replace(regex, () => {
@@ -6665,24 +7466,248 @@ var FindAndReplaceSlideTextCommand = {
6665
7466
  };
6666
7467
  var ReplaceSlideSnapshotCommand = {
6667
7468
  id: "slides.command.replace-snapshot",
6668
- type: import_core8.CommandType.COMMAND,
7469
+ type: import_core9.CommandType.COMMAND,
6669
7470
  handler: (accessor, params) => {
6670
7471
  if (!params?.snapshot) return false;
6671
7472
  const ctx = resolveSlideUnit(accessor, params.unitId);
6672
7473
  if (!ctx) return false;
6673
7474
  const prev = ctx.unit.save();
6674
7475
  const normalized = createDefaultSlideUnitData({
6675
- ...import_core8.Tools.deepClone(params.snapshot),
7476
+ ...import_core9.Tools.deepClone(params.snapshot),
6676
7477
  id: ctx.unitId
6677
7478
  });
6678
7479
  return executeSnapshotMutationWithUndo(accessor, ctx.unitId, prev, normalized);
6679
7480
  }
6680
7481
  };
7482
+ var UpdateSlideMasterCommand = {
7483
+ id: "slides.command.update-master",
7484
+ type: import_core9.CommandType.COMMAND,
7485
+ handler: (accessor, params) => {
7486
+ if (!params?.patch) return false;
7487
+ const ctx = resolveSlideUnit(accessor, params.unitId);
7488
+ if (!ctx) return false;
7489
+ const prev = ctx.unit.save();
7490
+ const next = import_core9.Tools.deepClone(prev);
7491
+ let master = params.masterId ? next.masters.find((m) => m.id === params.masterId) : next.masters[0];
7492
+ if (!master) {
7493
+ master = {
7494
+ id: params.masterId || "master-default",
7495
+ name: "\u6807\u51C6\u5546\u52A1\u6BCD\u7248",
7496
+ background: { type: "solid", color: next.theme.colors.background },
7497
+ accentBar: true,
7498
+ footerText: "",
7499
+ masterElements: []
7500
+ };
7501
+ next.masters.push(master);
7502
+ }
7503
+ const prevMasterBg = prev.masters.find((m) => m.id === master.id)?.background;
7504
+ const prevThemeBg = prev.theme.colors.background;
7505
+ if (params.patch.name !== void 0) {
7506
+ master.name = params.patch.name;
7507
+ }
7508
+ if (params.patch.background !== void 0) {
7509
+ master.background = import_core9.Tools.deepClone(params.patch.background);
7510
+ }
7511
+ if (params.patch.accentBar !== void 0) {
7512
+ master.accentBar = params.patch.accentBar;
7513
+ }
7514
+ if (params.patch.footerText !== void 0) {
7515
+ master.footerText = params.patch.footerText;
7516
+ }
7517
+ if (params.patch.masterElements !== void 0) {
7518
+ master.masterElements = params.patch.masterElements.map((el) => {
7519
+ const cloned = import_core9.Tools.deepClone(el);
7520
+ return cloned.type === "text" ? syncTextAndParagraphs(cloned) : cloned;
7521
+ });
7522
+ }
7523
+ if (params.patch.theme) {
7524
+ next.theme = {
7525
+ ...next.theme,
7526
+ ...params.patch.theme.name !== void 0 ? { name: params.patch.theme.name } : {},
7527
+ ...params.patch.theme.majorFont !== void 0 ? { majorFont: params.patch.theme.majorFont } : {},
7528
+ ...params.patch.theme.minorFont !== void 0 ? { minorFont: params.patch.theme.minorFont } : {},
7529
+ colors: {
7530
+ ...next.theme.colors,
7531
+ ...params.patch.theme.colors ?? {}
7532
+ }
7533
+ };
7534
+ }
7535
+ if (params.patch.background !== void 0 && params.propagateBackgroundToSlides !== false) {
7536
+ const oldMasterJson = prevMasterBg ? JSON.stringify(prevMasterBg) : "";
7537
+ for (const slide of Object.values(next.slides)) {
7538
+ const matchesOldMaster = !slide.background || oldMasterJson && JSON.stringify(slide.background) === oldMasterJson || slide.background.type === "solid" && slide.background.color === prevThemeBg;
7539
+ if (params.propagateBackgroundToSlides === true || matchesOldMaster) {
7540
+ slide.background = import_core9.Tools.deepClone(params.patch.background);
7541
+ }
7542
+ }
7543
+ }
7544
+ return executeSnapshotMutationWithUndo(accessor, ctx.unitId, prev, next);
7545
+ }
7546
+ };
7547
+ var UpdateSlideLayoutCommand = {
7548
+ id: "slides.command.update-layout",
7549
+ type: import_core9.CommandType.COMMAND,
7550
+ handler: (accessor, params) => {
7551
+ if (!params?.layoutId || !params.patch) return false;
7552
+ const ctx = resolveSlideUnit(accessor, params.unitId);
7553
+ if (!ctx) return false;
7554
+ const prev = ctx.unit.save();
7555
+ const next = import_core9.Tools.deepClone(prev);
7556
+ const layout = next.layouts.find(
7557
+ (l) => l.id === params.layoutId || l.type === params.layoutId
7558
+ );
7559
+ if (!layout) return false;
7560
+ if (params.patch.name !== void 0) {
7561
+ layout.name = params.patch.name;
7562
+ }
7563
+ if (params.patch.background !== void 0) {
7564
+ layout.background = import_core9.Tools.deepClone(params.patch.background);
7565
+ }
7566
+ if (params.patch.layoutElements !== void 0) {
7567
+ layout.layoutElements = import_core9.Tools.deepClone(params.patch.layoutElements);
7568
+ }
7569
+ if (params.patch.placeholders !== void 0) {
7570
+ layout.placeholders = import_core9.Tools.deepClone(params.patch.placeholders);
7571
+ if (params.syncExistingSlides !== false) {
7572
+ const scaleX = (next.slideSize.widthPt || 960) / 960;
7573
+ const scaleY = (next.slideSize.heightPt || 540) / 540;
7574
+ const slotByRole = /* @__PURE__ */ new Map();
7575
+ for (const slot of layout.placeholders) {
7576
+ slotByRole.set(slot.role, slot);
7577
+ }
7578
+ for (const slide of Object.values(next.slides)) {
7579
+ if (slide.layoutId !== layout.id) continue;
7580
+ for (const elId of slide.elementOrder) {
7581
+ const el = slide.elements[elId];
7582
+ if (!el || !el.placeholderRole) continue;
7583
+ const slot = slotByRole.get(el.placeholderRole);
7584
+ if (!slot) continue;
7585
+ el.x = Math.round(slot.x * scaleX);
7586
+ el.y = Math.round(slot.y * scaleY);
7587
+ el.width = Math.round(slot.width * scaleX);
7588
+ el.height = Math.round(slot.height * scaleY);
7589
+ if (el.type === "text") {
7590
+ if (slot.fontSize !== void 0) el.fontSize = slot.fontSize;
7591
+ if (slot.align !== void 0) el.align = slot.align;
7592
+ slide.elements[elId] = syncTextAndParagraphs(el);
7593
+ }
7594
+ }
7595
+ }
7596
+ }
7597
+ }
7598
+ return executeSnapshotMutationWithUndo(accessor, ctx.unitId, prev, next);
7599
+ }
7600
+ };
7601
+ var UpdateSlideShowSettingsCommand = {
7602
+ id: "slides.command.update-slideshow-settings",
7603
+ type: import_core9.CommandType.COMMAND,
7604
+ handler: (accessor, params) => {
7605
+ if (!params?.patch) return false;
7606
+ const ctx = resolveSlideUnit(accessor, params.unitId);
7607
+ if (!ctx) return false;
7608
+ const prev = ctx.unit.save();
7609
+ const next = import_core9.Tools.deepClone(prev);
7610
+ next.slideshowSettings = {
7611
+ ...prev.slideshowSettings ?? {},
7612
+ ...import_core9.Tools.deepClone(params.patch)
7613
+ };
7614
+ return executeSnapshotMutationWithUndo(accessor, ctx.unitId, prev, next);
7615
+ }
7616
+ };
7617
+
7618
+ // src/exporter/slide-image-exporter.ts
7619
+ function applyScaleToSvgDimensions(svgMarkup, widthPx, heightPx) {
7620
+ return svgMarkup.replace(/(<svg\b[^>]*?\swidth=")[^"]+(")/, `$1${widthPx}$2`).replace(/(<svg\b[^>]*?\sheight=")[^"]+(")/, `$1${heightPx}$2`);
7621
+ }
7622
+ function rasterizeSvgInBrowserCanvas(svgDataUrl, widthPx, heightPx, format, quality) {
7623
+ if (typeof document === "undefined" || typeof Image === "undefined" || typeof HTMLCanvasElement === "undefined") {
7624
+ return Promise.resolve(svgDataUrl);
7625
+ }
7626
+ return new Promise((resolve) => {
7627
+ try {
7628
+ const canvas = document.createElement("canvas");
7629
+ canvas.width = widthPx;
7630
+ canvas.height = heightPx;
7631
+ const ctx = canvas.getContext("2d");
7632
+ if (!ctx) {
7633
+ resolve(svgDataUrl);
7634
+ return;
7635
+ }
7636
+ const img = new Image();
7637
+ img.onload = () => {
7638
+ try {
7639
+ if (format === "jpeg") {
7640
+ ctx.fillStyle = "#ffffff";
7641
+ ctx.fillRect(0, 0, widthPx, heightPx);
7642
+ }
7643
+ ctx.drawImage(img, 0, 0, widthPx, heightPx);
7644
+ const mime = format === "jpeg" ? "image/jpeg" : "image/png";
7645
+ const out = format === "jpeg" ? canvas.toDataURL(mime, Math.max(0.1, Math.min(1, quality))) : canvas.toDataURL(mime);
7646
+ resolve(out && out.startsWith("data:") ? out : svgDataUrl);
7647
+ } catch {
7648
+ resolve(svgDataUrl);
7649
+ }
7650
+ };
7651
+ img.onerror = () => {
7652
+ resolve(svgDataUrl);
7653
+ };
7654
+ img.src = svgDataUrl;
7655
+ } catch {
7656
+ resolve(svgDataUrl);
7657
+ }
7658
+ });
7659
+ }
7660
+ async function exportSlidePageToDataUrl(snapshot, slideId, options) {
7661
+ const slide = snapshot.slides[slideId];
7662
+ if (!slide) {
7663
+ throw new Error(`[UniverSlides] Slide "${slideId}" not found in presentation "${snapshot.id}".`);
7664
+ }
7665
+ const format = options?.format ?? "png";
7666
+ const scale = Math.max(0.5, Math.min(8, options?.scale ?? 2));
7667
+ const quality = options?.quality ?? 0.92;
7668
+ const slideW = snapshot.slideSize.widthPt || 960;
7669
+ const slideH = snapshot.slideSize.heightPt || 540;
7670
+ const widthPx = Math.max(1, Math.round(slideW * scale));
7671
+ const heightPx = Math.max(1, Math.round(slideH * scale));
7672
+ const orderIdx = snapshot.slideOrder.indexOf(slideId);
7673
+ const slideNumber = orderIdx >= 0 ? orderIdx + 1 : 1;
7674
+ const rawSvg = renderSlidePageToSvg(slide, snapshot, slideNumber);
7675
+ const scaledSvg = applyScaleToSvgDimensions(rawSvg, widthPx, heightPx);
7676
+ const svgDataUrl = svgToDataUri(scaledSvg);
7677
+ if (format === "svg") {
7678
+ return svgDataUrl;
7679
+ }
7680
+ return await rasterizeSvgInBrowserCanvas(svgDataUrl, widthPx, heightPx, format, quality);
7681
+ }
7682
+ async function exportAllSlidesToImages(snapshot, options) {
7683
+ const format = options?.format ?? "png";
7684
+ const scale = Math.max(0.5, Math.min(8, options?.scale ?? 2));
7685
+ const widthPx = Math.max(1, Math.round((snapshot.slideSize.widthPt || 960) * scale));
7686
+ const heightPx = Math.max(1, Math.round((snapshot.slideSize.heightPt || 540) * scale));
7687
+ const targetSlides = snapshot.slideOrder.map((id, idx) => ({ slide: snapshot.slides[id], idx })).filter(
7688
+ (entry) => Boolean(entry.slide && (options?.includeHiddenSlides || !entry.slide.hidden))
7689
+ );
7690
+ const results = [];
7691
+ for (const { slide, idx } of targetSlides) {
7692
+ const dataUrl = await exportSlidePageToDataUrl(snapshot, slide.id, options);
7693
+ const actualFormat = dataUrl.startsWith("data:image/png") ? "png" : dataUrl.startsWith("data:image/jpeg") ? "jpeg" : format === "svg" || dataUrl.startsWith("data:image/svg+xml") ? "svg" : format;
7694
+ results.push({
7695
+ slideId: slide.id,
7696
+ slideIndex: idx,
7697
+ title: slide.title,
7698
+ format: actualFormat,
7699
+ widthPx,
7700
+ heightPx,
7701
+ dataUrl
7702
+ });
7703
+ }
7704
+ return results;
7705
+ }
6681
7706
 
6682
7707
  // src/plugin.ts
6683
- var import_core9 = require("@univerjs/core");
7708
+ var import_core10 = require("@univerjs/core");
6684
7709
  var UNIVER_SLIDES_PLUGIN_NAME = "UNIVER_SLIDES_PLUGIN";
6685
- var UniverSlidesPlugin = class extends import_core9.Plugin {
7710
+ var UniverSlidesPlugin = class extends import_core10.Plugin {
6686
7711
  constructor(_config = {}, _injector, _univerInstanceService, _commandService) {
6687
7712
  super();
6688
7713
  this._config = _config;
@@ -6699,7 +7724,7 @@ var UniverSlidesPlugin = class extends import_core9.Plugin {
6699
7724
  onStarting() {
6700
7725
  this.disposeWithMe(
6701
7726
  this._univerInstanceService.registerCtorForType(
6702
- import_core9.UniverInstanceType.UNIVER_SLIDE,
7727
+ import_core10.UniverInstanceType.UNIVER_SLIDE,
6703
7728
  SlideUnitModel
6704
7729
  )
6705
7730
  );
@@ -6714,7 +7739,7 @@ var UniverSlidesPlugin = class extends import_core9.Plugin {
6714
7739
  if (this._config.io) {
6715
7740
  this._injector.get(ISlideIoService).setAdapter(this._config.io);
6716
7741
  }
6717
- const focusSub = this._univerInstanceService.getCurrentTypeOfUnit$(import_core9.UniverInstanceType.UNIVER_SLIDE).subscribe((unit) => {
7742
+ const focusSub = this._univerInstanceService.getCurrentTypeOfUnit$(import_core10.UniverInstanceType.UNIVER_SLIDE).subscribe((unit) => {
6718
7743
  if (unit) {
6719
7744
  if (this._univerInstanceService.getFocusedUnit()?.getUnitId() !== unit.getUnitId()) {
6720
7745
  this._univerInstanceService.focusUnit(unit.getUnitId());
@@ -6749,7 +7774,10 @@ var UniverSlidesPlugin = class extends import_core9.Plugin {
6749
7774
  UpdateSlideThemeCommand,
6750
7775
  SetSlideSizeCommand,
6751
7776
  FindAndReplaceSlideTextCommand,
6752
- ReplaceSlideSnapshotCommand
7777
+ ReplaceSlideSnapshotCommand,
7778
+ UpdateSlideMasterCommand,
7779
+ UpdateSlideLayoutCommand,
7780
+ UpdateSlideShowSettingsCommand
6753
7781
  ];
6754
7782
  for (const cmd of commands) {
6755
7783
  this.disposeWithMe(this._commandService.registerCommand(cmd));
@@ -6757,13 +7785,13 @@ var UniverSlidesPlugin = class extends import_core9.Plugin {
6757
7785
  }
6758
7786
  };
6759
7787
  UniverSlidesPlugin = __decorateClass([
6760
- __decorateParam(1, (0, import_core9.Inject)(import_core9.Injector)),
6761
- __decorateParam(2, import_core9.IUniverInstanceService),
6762
- __decorateParam(3, import_core9.ICommandService)
7788
+ __decorateParam(1, (0, import_core10.Inject)(import_core10.Injector)),
7789
+ __decorateParam(2, import_core10.IUniverInstanceService),
7790
+ __decorateParam(3, import_core10.ICommandService)
6763
7791
  ], UniverSlidesPlugin);
6764
7792
 
6765
7793
  // src/index.ts
6766
- var VERSION = "1.6.218";
7794
+ var VERSION = "1.6.219";
6767
7795
  // Annotate the CommonJS export names for ESM import in node:
6768
7796
  0 && (module.exports = {
6769
7797
  AddSlideElementCommand,
@@ -6796,11 +7824,15 @@ var VERSION = "1.6.218";
6796
7824
  UNIVER_SLIDE_SCHEMA_VERSION,
6797
7825
  UniverSlidesPlugin,
6798
7826
  UpdateSlideElementsCommand,
7827
+ UpdateSlideLayoutCommand,
7828
+ UpdateSlideMasterCommand,
6799
7829
  UpdateSlidePagePropsCommand,
6800
7830
  UpdateSlideSectionCommand,
7831
+ UpdateSlideShowSettingsCommand,
6801
7832
  UpdateSlideThemeCommand,
6802
7833
  VERSION,
6803
7834
  compileSlidesWithDataset,
7835
+ computeMorphInterpolatedSlide,
6804
7836
  countSlideTextMatches,
6805
7837
  crc32Bytes,
6806
7838
  createDefaultSlideElement,
@@ -6809,11 +7841,14 @@ var VERSION = "1.6.218";
6809
7841
  createDefaultSlideUnitData,
6810
7842
  createElementsFromLayout,
6811
7843
  createSampleExecutiveDeckData,
7844
+ cubicEaseInOut,
6812
7845
  deflateRawSyncPure,
6813
7846
  emuToPt,
6814
7847
  escapeSvgXml,
7848
+ exportAllSlidesToImages,
6815
7849
  exportPptxBytes,
6816
7850
  exportPptxBytesSync,
7851
+ exportSlidePageToDataUrl,
6817
7852
  exportSlidesToPdfBytes,
6818
7853
  extractSlideDatasetCodes,
6819
7854
  findLayoutByTypeOrId,
@@ -6822,15 +7857,21 @@ var VERSION = "1.6.218";
6822
7857
  importPptxBytes,
6823
7858
  importPptxBytesSync,
6824
7859
  inflateRawSyncPure,
7860
+ interpolateHexColor,
7861
+ matchMorphSlidePairs,
6825
7862
  packZipSync,
7863
+ parseCssHexOrRgb,
6826
7864
  ptToEmu,
6827
7865
  renderSlideChartToSvg,
6828
7866
  renderSlideChartToSvgDataUri,
7867
+ renderSlideMediaToSvg,
7868
+ renderSlideMediaToSvgDataUri,
6829
7869
  renderSlidePageToSvg,
6830
7870
  renderSlideSmartArtToSvg,
6831
7871
  renderSlideSmartArtToSvgDataUri,
6832
7872
  resolveChartPalette,
6833
7873
  resolveConnectorEndpoints,
7874
+ resolveExplicitMorphKey,
6834
7875
  svgToDataUri,
6835
7876
  syncTextAndParagraphs,
6836
7877
  unpackZipSync