@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/README.md +10 -7
- package/lib/cjs/facade/index.js +34 -0
- package/lib/cjs/facade/index.js.map +1 -1
- package/lib/cjs/index.js +1613 -572
- package/lib/cjs/index.js.map +1 -1
- package/lib/es/facade/index.js +39 -0
- package/lib/es/facade/index.js.map +1 -1
- package/lib/es/index.js +1531 -503
- package/lib/es/index.js.map +1 -1
- package/lib/types/facade/index.d.ts +11 -1
- package/lib/types/index.d.ts +161 -6
- package/package.json +1 -1
package/lib/es/index.js
CHANGED
|
@@ -462,6 +462,7 @@ function createDefaultSlideUnitData(partial) {
|
|
|
462
462
|
sections,
|
|
463
463
|
slideOrder,
|
|
464
464
|
slides,
|
|
465
|
+
...partial?.slideshowSettings ? { slideshowSettings: Tools.deepClone(partial.slideshowSettings) } : {},
|
|
465
466
|
...partial?.metadata ? { metadata: Tools.deepClone(partial.metadata) } : {}
|
|
466
467
|
};
|
|
467
468
|
}
|
|
@@ -899,6 +900,9 @@ var SlideUnitModel = class extends UnitModel {
|
|
|
899
900
|
getSections() {
|
|
900
901
|
return this._snapshot.sections;
|
|
901
902
|
}
|
|
903
|
+
getSlideShowSettings() {
|
|
904
|
+
return this._snapshot.slideshowSettings;
|
|
905
|
+
}
|
|
902
906
|
getSlideOrder() {
|
|
903
907
|
return this._snapshot.slideOrder;
|
|
904
908
|
}
|
|
@@ -1652,11 +1656,187 @@ function renderSlideSmartArtToSvg(smartArt, theme) {
|
|
|
1652
1656
|
function renderSlideSmartArtToSvgDataUri(smartArt, theme) {
|
|
1653
1657
|
return svgToDataUri(renderSlideSmartArtToSvg(smartArt, theme));
|
|
1654
1658
|
}
|
|
1659
|
+
function renderSlideMediaToSvg(media, theme) {
|
|
1660
|
+
const w = Math.max(80, Math.round(media.width || (media.type === "video" ? 420 : 320)));
|
|
1661
|
+
const h = Math.max(40, Math.round(media.height || (media.type === "video" ? 240 : 64)));
|
|
1662
|
+
const accent = theme?.colors.accent1 ?? "#2563eb";
|
|
1663
|
+
const fontFamily = theme?.minorFont ?? "PingFang SC, Microsoft YaHei, Inter, Arial, sans-serif";
|
|
1664
|
+
const label = media.name || (media.type === "video" ? "\u89C6\u9891\u5A92\u4F53" : "\u97F3\u9891\u5A92\u4F53");
|
|
1665
|
+
if (media.type === "video") {
|
|
1666
|
+
const cx2 = w / 2;
|
|
1667
|
+
const cy2 = h / 2;
|
|
1668
|
+
const btnR = Math.max(14, Math.min(26, Math.min(w, h) * 0.16));
|
|
1669
|
+
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)}`;
|
|
1670
|
+
const posterImg = media.poster ? `<image href="${escapeSvgXml(media.poster)}" x="0" y="0" width="${w}" height="${h}" preserveAspectRatio="xMidYMid slice" opacity="0.72"/>` : "";
|
|
1671
|
+
return [
|
|
1672
|
+
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${w} ${h}" width="${w}" height="${h}" font-family="${escapeSvgXml(fontFamily)}">`,
|
|
1673
|
+
`<rect x="0.5" y="0.5" width="${w - 1}" height="${h - 1}" rx="8" fill="#0f172a" stroke="#334155" stroke-width="1"/>`,
|
|
1674
|
+
posterImg,
|
|
1675
|
+
`<circle cx="${cx2.toFixed(1)}" cy="${cy2.toFixed(1)}" r="${btnR.toFixed(1)}" fill="${escapeSvgXml(accent)}" fill-opacity="0.92"/>`,
|
|
1676
|
+
`<polygon points="${triPts2}" fill="#ffffff"/>`,
|
|
1677
|
+
`<rect x="0" y="${Math.max(0, h - 28)}" width="${w}" height="28" fill="rgba(15,23,42,0.78)"/>`,
|
|
1678
|
+
`<text x="12" y="${h - 10}" font-size="11" font-weight="600" fill="#e2e8f0">${escapeSvgXml(label)}</text>`,
|
|
1679
|
+
`<text x="${w - 12}" y="${h - 10}" text-anchor="end" font-size="9.5" font-weight="700" fill="#38bdf8">VIDEO</text>`,
|
|
1680
|
+
`</svg>`
|
|
1681
|
+
].join("");
|
|
1682
|
+
}
|
|
1683
|
+
const cy = h / 2;
|
|
1684
|
+
const r = Math.max(11, Math.min(18, h * 0.3));
|
|
1685
|
+
const cx = 14 + r;
|
|
1686
|
+
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)}`;
|
|
1687
|
+
const trackX = cx + r + 12;
|
|
1688
|
+
const trackW = Math.max(24, w - trackX - 54);
|
|
1689
|
+
return [
|
|
1690
|
+
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${w} ${h}" width="${w}" height="${h}" font-family="${escapeSvgXml(fontFamily)}">`,
|
|
1691
|
+
`<rect x="0.5" y="0.5" width="${w - 1}" height="${h - 1}" rx="10" fill="#1e293b" stroke="#475569" stroke-width="1"/>`,
|
|
1692
|
+
`<circle cx="${cx.toFixed(1)}" cy="${cy.toFixed(1)}" r="${r.toFixed(1)}" fill="${escapeSvgXml(accent)}"/>`,
|
|
1693
|
+
`<polygon points="${triPts}" fill="#ffffff"/>`,
|
|
1694
|
+
`<text x="${trackX.toFixed(1)}" y="${(cy - 4).toFixed(1)}" font-size="11" font-weight="600" fill="#f8fafc">${escapeSvgXml(label)}</text>`,
|
|
1695
|
+
`<rect x="${trackX.toFixed(1)}" y="${(cy + 4).toFixed(1)}" width="${trackW.toFixed(1)}" height="4" rx="2" fill="#475569"/>`,
|
|
1696
|
+
`<rect x="${trackX.toFixed(1)}" y="${(cy + 4).toFixed(1)}" width="${(trackW * 0.38).toFixed(1)}" height="4" rx="2" fill="#38bdf8"/>`,
|
|
1697
|
+
`<text x="${w - 12}" y="${(cy + 4).toFixed(1)}" text-anchor="end" font-size="9.5" font-weight="700" fill="#94a3b8">AUDIO</text>`,
|
|
1698
|
+
`</svg>`
|
|
1699
|
+
].join("");
|
|
1700
|
+
}
|
|
1701
|
+
function renderSlideMediaToSvgDataUri(media, theme) {
|
|
1702
|
+
return svgToDataUri(renderSlideMediaToSvg(media, theme));
|
|
1703
|
+
}
|
|
1704
|
+
function appendSlideElementToSvg(el, elementsMap, theme, defs, body, idPrefix = "") {
|
|
1705
|
+
if (!el || el.hidden) return;
|
|
1706
|
+
const opacityAttr = el.opacity !== void 0 && el.opacity < 1 ? ` opacity="${el.opacity}"` : "";
|
|
1707
|
+
const rotCx = el.x + el.width / 2;
|
|
1708
|
+
const rotCy = el.y + el.height / 2;
|
|
1709
|
+
const rotTransform = el.rotation ? ` transform="rotate(${el.rotation} ${rotCx} ${rotCy})"` : "";
|
|
1710
|
+
const safeId = escapeSvgXml(`${idPrefix}${el.id}`);
|
|
1711
|
+
if (el.type === "shape") {
|
|
1712
|
+
const pathD = getShapeSvgPath(el.shapeType, el.width, el.height, el.cornerRadius ?? 8);
|
|
1713
|
+
let fillAttr = escapeSvgXml(el.fillColor || theme.colors.accent1);
|
|
1714
|
+
if (el.gradientFrom && el.gradientTo) {
|
|
1715
|
+
const gid = `grad-${safeId}`;
|
|
1716
|
+
defs.push(
|
|
1717
|
+
`<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>`
|
|
1718
|
+
);
|
|
1719
|
+
fillAttr = `url(#${gid})`;
|
|
1720
|
+
}
|
|
1721
|
+
const dash = el.strokeDash === "dashed" ? ' stroke-dasharray="6 4"' : el.strokeDash === "dotted" ? ' stroke-dasharray="2 3"' : "";
|
|
1722
|
+
body.push(
|
|
1723
|
+
`<g transform="translate(${el.x} ${el.y})${el.rotation ? ` rotate(${el.rotation} ${el.width / 2} ${el.height / 2})` : ""}"${opacityAttr}>`,
|
|
1724
|
+
`<path d="${pathD}" fill="${fillAttr}" stroke="${escapeSvgXml(el.strokeColor || "none")}" stroke-width="${el.strokeWidth ?? 1}"${dash}/>`,
|
|
1725
|
+
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>` : "",
|
|
1726
|
+
`</g>`
|
|
1727
|
+
);
|
|
1728
|
+
} else if (el.type === "connector") {
|
|
1729
|
+
const geom = resolveConnectorEndpoints(el, elementsMap);
|
|
1730
|
+
const markerId = `arrow-${safeId}`;
|
|
1731
|
+
if (el.endArrow || el.startArrow) {
|
|
1732
|
+
defs.push(
|
|
1733
|
+
`<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>`
|
|
1734
|
+
);
|
|
1735
|
+
}
|
|
1736
|
+
body.push(
|
|
1737
|
+
`<path d="${geom.pathD}" fill="none" stroke="${escapeSvgXml(el.strokeColor)}" stroke-width="${el.strokeWidth || 2}"${el.endArrow ? ` marker-end="url(#${markerId})"` : ""}${opacityAttr}/>`
|
|
1738
|
+
);
|
|
1739
|
+
if (el.label) {
|
|
1740
|
+
body.push(
|
|
1741
|
+
`<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>`
|
|
1742
|
+
);
|
|
1743
|
+
}
|
|
1744
|
+
} else if (el.type === "text") {
|
|
1745
|
+
const fs = el.fontSize ?? 18;
|
|
1746
|
+
const fw = el.fontWeight ?? "normal";
|
|
1747
|
+
let fillAttr = escapeSvgXml(el.color || theme.colors.text);
|
|
1748
|
+
if (el.wordArt?.enabled) {
|
|
1749
|
+
const wid = `wordart-${safeId}`;
|
|
1750
|
+
defs.push(
|
|
1751
|
+
`<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>`
|
|
1752
|
+
);
|
|
1753
|
+
fillAttr = `url(#${wid})`;
|
|
1754
|
+
}
|
|
1755
|
+
const lines = (el.text || "").split("\n");
|
|
1756
|
+
const anchor = el.align === "center" ? "middle" : el.align === "right" ? "end" : "start";
|
|
1757
|
+
const tx = el.align === "center" ? el.x + el.width / 2 : el.align === "right" ? el.x + el.width - 8 : el.x + 8;
|
|
1758
|
+
body.push(`<g${rotTransform}${opacityAttr}>`);
|
|
1759
|
+
if (el.fillColor) {
|
|
1760
|
+
body.push(
|
|
1761
|
+
`<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}"/>`
|
|
1762
|
+
);
|
|
1763
|
+
}
|
|
1764
|
+
lines.forEach((line, lIdx) => {
|
|
1765
|
+
const prefix = el.bullet ? el.bullet === "number" ? `${lIdx + 1}. ` : "\u2022 " : "";
|
|
1766
|
+
const ty = el.y + fs + 6 + lIdx * fs * (el.lineHeight ?? 1.35);
|
|
1767
|
+
body.push(
|
|
1768
|
+
`<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>`
|
|
1769
|
+
);
|
|
1770
|
+
});
|
|
1771
|
+
body.push(`</g>`);
|
|
1772
|
+
} else if (el.type === "chart") {
|
|
1773
|
+
const inner = renderSlideChartToSvg({ ...el, width: el.width, height: el.height }, theme).replace(/^<svg[^>]*>/, "").replace(/<\/svg>$/, "");
|
|
1774
|
+
body.push(`<g transform="translate(${el.x} ${el.y})"${opacityAttr}>${inner}</g>`);
|
|
1775
|
+
} else if (el.type === "smartArt") {
|
|
1776
|
+
const inner = renderSlideSmartArtToSvg({ ...el, width: el.width, height: el.height }, theme).replace(/^<svg[^>]*>/, "").replace(/<\/svg>$/, "");
|
|
1777
|
+
body.push(`<g transform="translate(${el.x} ${el.y})"${opacityAttr}>${inner}</g>`);
|
|
1778
|
+
} else if (el.type === "table") {
|
|
1779
|
+
body.push(`<g transform="translate(${el.x} ${el.y})"${opacityAttr}>`);
|
|
1780
|
+
let curY = 0;
|
|
1781
|
+
for (let r = 0; r < el.rows; r++) {
|
|
1782
|
+
const rh = el.rowHeights[r] ?? el.height / Math.max(1, el.rows);
|
|
1783
|
+
let curX = 0;
|
|
1784
|
+
for (let c = 0; c < el.cols; c++) {
|
|
1785
|
+
const cw = el.colWidths[c] ?? el.width / Math.max(1, el.cols);
|
|
1786
|
+
const cell = el.cells[r]?.[c];
|
|
1787
|
+
if (!cell?.mergedInto) {
|
|
1788
|
+
const isHeader = el.headerRow !== false && r === 0;
|
|
1789
|
+
const bgFill = cell?.bg || (isHeader ? el.headerBg || theme.colors.primary : r % 2 === 1 ? el.zebraBg || "#f8fafc" : "#ffffff");
|
|
1790
|
+
const fgFill = cell?.color || (isHeader ? el.headerColor || "#ffffff" : theme.colors.text);
|
|
1791
|
+
body.push(
|
|
1792
|
+
`<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"/>`,
|
|
1793
|
+
`<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>`
|
|
1794
|
+
);
|
|
1795
|
+
}
|
|
1796
|
+
curX += cw;
|
|
1797
|
+
}
|
|
1798
|
+
curY += rh;
|
|
1799
|
+
}
|
|
1800
|
+
body.push(`</g>`);
|
|
1801
|
+
} else if (el.type === "image" || el.type === "svg") {
|
|
1802
|
+
if (el.src) {
|
|
1803
|
+
body.push(
|
|
1804
|
+
`<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}/>`
|
|
1805
|
+
);
|
|
1806
|
+
}
|
|
1807
|
+
} else if (el.type === "codeBlock") {
|
|
1808
|
+
const dark = el.codeTheme !== "light";
|
|
1809
|
+
body.push(
|
|
1810
|
+
`<g transform="translate(${el.x} ${el.y})"${opacityAttr}>`,
|
|
1811
|
+
`<rect x="0" y="0" width="${el.width}" height="${el.height}" rx="8" fill="${dark ? "#0f172a" : "#f8fafc"}" stroke="#334155" stroke-width="1"/>`,
|
|
1812
|
+
`<text x="12" y="20" font-size="10" font-weight="700" fill="#38bdf8">${escapeSvgXml(el.language.toUpperCase())}</text>`
|
|
1813
|
+
);
|
|
1814
|
+
el.code.split("\n").slice(0, 12).forEach((ln, idx) => {
|
|
1815
|
+
body.push(
|
|
1816
|
+
`<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>`
|
|
1817
|
+
);
|
|
1818
|
+
});
|
|
1819
|
+
body.push(`</g>`);
|
|
1820
|
+
} else if (el.type === "sheetEmbed") {
|
|
1821
|
+
body.push(
|
|
1822
|
+
`<g transform="translate(${el.x} ${el.y})"${opacityAttr}>`,
|
|
1823
|
+
`<rect x="0" y="0" width="${el.width}" height="${el.height}" rx="6" fill="#ffffff" stroke="#10b981" stroke-width="1.2"/>`,
|
|
1824
|
+
`<rect x="0" y="0" width="${el.width}" height="24" rx="6" fill="${escapeSvgXml(el.accentColor || "#059669")}"/>`,
|
|
1825
|
+
`<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>`,
|
|
1826
|
+
`</g>`
|
|
1827
|
+
);
|
|
1828
|
+
} else if (el.type === "video" || el.type === "audio") {
|
|
1829
|
+
const inner = renderSlideMediaToSvg({ ...el, width: el.width, height: el.height }, theme).replace(/^<svg[^>]*>/, "").replace(/<\/svg>$/, "");
|
|
1830
|
+
body.push(`<g transform="translate(${el.x} ${el.y})"${rotTransform}${opacityAttr}>${inner}</g>`);
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1655
1833
|
function renderSlidePageToSvg(page, unitData, slideNumber) {
|
|
1656
1834
|
const w = unitData.slideSize.widthPt || 960;
|
|
1657
1835
|
const h = unitData.slideSize.heightPt || 540;
|
|
1658
1836
|
const theme = unitData.theme ?? SLIDE_THEME_PRESETS[0];
|
|
1659
|
-
const
|
|
1837
|
+
const matchedLayout = unitData.layouts?.find((l) => l.id === page.layoutId);
|
|
1838
|
+
const master = (matchedLayout ? unitData.masters.find((m) => m.id === matchedLayout.masterId) : void 0) ?? unitData.masters[0];
|
|
1839
|
+
const bg = page.background ?? matchedLayout?.background ?? master?.background ?? { type: "solid", color: theme.colors.background };
|
|
1660
1840
|
const defs = [];
|
|
1661
1841
|
const body = [];
|
|
1662
1842
|
if (bg.type === "gradient" && bg.gradientFrom && bg.gradientTo) {
|
|
@@ -1675,141 +1855,415 @@ function renderSlidePageToSvg(page, unitData, slideNumber) {
|
|
|
1675
1855
|
);
|
|
1676
1856
|
}
|
|
1677
1857
|
}
|
|
1678
|
-
if (
|
|
1858
|
+
if (master?.accentBar) {
|
|
1679
1859
|
body.push(`<rect x="0" y="0" width="${w}" height="4" fill="${escapeSvgXml(theme.colors.primary)}"/>`);
|
|
1680
1860
|
}
|
|
1861
|
+
if (master?.masterElements && master.masterElements.length > 0) {
|
|
1862
|
+
const masterMap = {};
|
|
1863
|
+
for (const mEl of master.masterElements) {
|
|
1864
|
+
if (mEl) masterMap[mEl.id] = mEl;
|
|
1865
|
+
}
|
|
1866
|
+
for (const mEl of master.masterElements) {
|
|
1867
|
+
appendSlideElementToSvg(mEl, masterMap, theme, defs, body, "master-");
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
if (matchedLayout?.layoutElements && matchedLayout.layoutElements.length > 0) {
|
|
1871
|
+
const layoutMap = {};
|
|
1872
|
+
for (const lEl of matchedLayout.layoutElements) {
|
|
1873
|
+
if (lEl) layoutMap[lEl.id] = lEl;
|
|
1874
|
+
}
|
|
1875
|
+
for (const lEl of matchedLayout.layoutElements) {
|
|
1876
|
+
appendSlideElementToSvg(lEl, layoutMap, theme, defs, body, "layout-");
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1681
1879
|
for (const elId of page.elementOrder) {
|
|
1682
1880
|
const el = page.elements[elId];
|
|
1683
1881
|
if (!el || el.hidden) continue;
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1882
|
+
appendSlideElementToSvg(el, page.elements, theme, defs, body);
|
|
1883
|
+
}
|
|
1884
|
+
if (master?.footerText) {
|
|
1885
|
+
body.push(
|
|
1886
|
+
`<text x="22" y="${h - 14}" font-size="10" fill="#64748b">${escapeSvgXml(master.footerText)}</text>`
|
|
1887
|
+
);
|
|
1888
|
+
}
|
|
1889
|
+
if (page.showSlideNumber !== false && typeof slideNumber === "number") {
|
|
1890
|
+
body.push(
|
|
1891
|
+
`<text x="${w - 22}" y="${h - 14}" text-anchor="end" font-size="10" fill="#64748b">${slideNumber}</text>`
|
|
1892
|
+
);
|
|
1893
|
+
}
|
|
1894
|
+
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>`;
|
|
1895
|
+
}
|
|
1896
|
+
|
|
1897
|
+
// src/renderers/slide-morph-engine.ts
|
|
1898
|
+
import { Tools as Tools2 } from "@univerjs/core";
|
|
1899
|
+
function cubicEaseInOut(t) {
|
|
1900
|
+
const clamped = Math.max(0, Math.min(1, Number.isFinite(t) ? t : 1));
|
|
1901
|
+
return clamped < 0.5 ? 4 * clamped * clamped * clamped : 1 - Math.pow(-2 * clamped + 2, 3) / 2;
|
|
1902
|
+
}
|
|
1903
|
+
function lerpNum(from, to, t, precision = 2) {
|
|
1904
|
+
const val = from + (to - from) * t;
|
|
1905
|
+
const factor = Math.pow(10, precision);
|
|
1906
|
+
return Math.round(val * factor) / factor;
|
|
1907
|
+
}
|
|
1908
|
+
function parseCssHexOrRgb(color) {
|
|
1909
|
+
if (!color) return null;
|
|
1910
|
+
const trimmed = color.trim();
|
|
1911
|
+
const hexMatch = trimmed.match(/^#?([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/);
|
|
1912
|
+
if (hexMatch) {
|
|
1913
|
+
let h = hexMatch[1];
|
|
1914
|
+
if (h.length === 3) {
|
|
1915
|
+
h = `${h[0]}${h[0]}${h[1]}${h[1]}${h[2]}${h[2]}`;
|
|
1916
|
+
}
|
|
1917
|
+
return {
|
|
1918
|
+
r: parseInt(h.slice(0, 2), 16),
|
|
1919
|
+
g: parseInt(h.slice(2, 4), 16),
|
|
1920
|
+
b: parseInt(h.slice(4, 6), 16)
|
|
1921
|
+
};
|
|
1922
|
+
}
|
|
1923
|
+
const rgbMatch = trimmed.match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i);
|
|
1924
|
+
if (rgbMatch) {
|
|
1925
|
+
return {
|
|
1926
|
+
r: Math.max(0, Math.min(255, Number(rgbMatch[1]))),
|
|
1927
|
+
g: Math.max(0, Math.min(255, Number(rgbMatch[2]))),
|
|
1928
|
+
b: Math.max(0, Math.min(255, Number(rgbMatch[3])))
|
|
1929
|
+
};
|
|
1930
|
+
}
|
|
1931
|
+
return null;
|
|
1932
|
+
}
|
|
1933
|
+
function interpolateHexColor(fromColor, toColor, easedT) {
|
|
1934
|
+
if (!fromColor && !toColor) return void 0;
|
|
1935
|
+
const c1 = parseCssHexOrRgb(fromColor);
|
|
1936
|
+
const c2 = parseCssHexOrRgb(toColor);
|
|
1937
|
+
if (c1 && c2) {
|
|
1938
|
+
const r = Math.round(c1.r + (c2.r - c1.r) * easedT).toString(16).padStart(2, "0");
|
|
1939
|
+
const g = Math.round(c1.g + (c2.g - c1.g) * easedT).toString(16).padStart(2, "0");
|
|
1940
|
+
const b = Math.round(c1.b + (c2.b - c1.b) * easedT).toString(16).padStart(2, "0");
|
|
1941
|
+
return `#${r}${g}${b}`;
|
|
1942
|
+
}
|
|
1943
|
+
return easedT < 0.5 ? fromColor ?? toColor : toColor ?? fromColor;
|
|
1944
|
+
}
|
|
1945
|
+
function resolveExplicitMorphKey(el) {
|
|
1946
|
+
if (el.morphName && el.morphName.trim().length > 0) {
|
|
1947
|
+
const raw = el.morphName.trim();
|
|
1948
|
+
const stripped = raw.startsWith("!!") ? raw.slice(2).trim() : raw;
|
|
1949
|
+
if (stripped.length > 0) return stripped;
|
|
1950
|
+
}
|
|
1951
|
+
if (el.name && el.name.trim().startsWith("!!")) {
|
|
1952
|
+
const stripped = el.name.trim().slice(2).trim();
|
|
1953
|
+
if (stripped.length > 0) return stripped;
|
|
1954
|
+
}
|
|
1955
|
+
return null;
|
|
1956
|
+
}
|
|
1957
|
+
function getElementDetailedSignature(el) {
|
|
1958
|
+
switch (el.type) {
|
|
1959
|
+
case "shape":
|
|
1960
|
+
return `shape:${el.shapeType}:${(el.text || el.name || "").trim()}`;
|
|
1961
|
+
case "text":
|
|
1962
|
+
return `text:${el.placeholderRole || ""}:${(el.name || el.text.slice(0, 32) || "").trim()}`;
|
|
1963
|
+
case "chart":
|
|
1964
|
+
return `chart:${el.chartType}:${(el.title || el.name || "").trim()}`;
|
|
1965
|
+
case "smartArt":
|
|
1966
|
+
return `smartArt:${el.layout}:${(el.title || el.name || "").trim()}`;
|
|
1967
|
+
case "image":
|
|
1968
|
+
case "svg":
|
|
1969
|
+
return `${el.type}:${(el.src || el.name || "").trim()}`;
|
|
1970
|
+
case "video":
|
|
1971
|
+
case "audio":
|
|
1972
|
+
return `${el.type}:${(el.src || el.name || "").trim()}`;
|
|
1973
|
+
case "table":
|
|
1974
|
+
return `table:${el.rows}x${el.cols}:${(el.name || "").trim()}`;
|
|
1975
|
+
case "connector":
|
|
1976
|
+
return `connector:${el.connectorType}:${(el.label || el.name || "").trim()}`;
|
|
1977
|
+
case "codeBlock":
|
|
1978
|
+
return `codeBlock:${el.language}:${(el.title || el.name || "").trim()}`;
|
|
1979
|
+
case "sheetEmbed":
|
|
1980
|
+
return `sheetEmbed:${(el.title || el.name || "").trim()}`;
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
function getElementCoarseSignature(el) {
|
|
1984
|
+
switch (el.type) {
|
|
1985
|
+
case "shape":
|
|
1986
|
+
return `shape:${el.shapeType}`;
|
|
1987
|
+
case "text":
|
|
1988
|
+
return `text:${el.placeholderRole || "freeform"}`;
|
|
1989
|
+
case "chart":
|
|
1990
|
+
return `chart:${el.chartType}`;
|
|
1991
|
+
case "smartArt":
|
|
1992
|
+
return `smartArt:${el.layout}`;
|
|
1993
|
+
default:
|
|
1994
|
+
return `${el.type}:${(el.name || "").trim()}`;
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
function getOrderedVisibleElements(slide) {
|
|
1998
|
+
const ordered = [];
|
|
1999
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2000
|
+
for (const id of slide.elementOrder) {
|
|
2001
|
+
const el = slide.elements[id];
|
|
2002
|
+
if (el && !el.hidden) {
|
|
2003
|
+
ordered.push(el);
|
|
2004
|
+
seen.add(id);
|
|
2005
|
+
}
|
|
2006
|
+
}
|
|
2007
|
+
for (const [id, el] of Object.entries(slide.elements)) {
|
|
2008
|
+
if (!seen.has(id) && el && !el.hidden) {
|
|
2009
|
+
ordered.push(el);
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
2012
|
+
return ordered;
|
|
2013
|
+
}
|
|
2014
|
+
function matchMorphSlidePairs(fromSlide, toSlide) {
|
|
2015
|
+
const fromList = getOrderedVisibleElements(fromSlide);
|
|
2016
|
+
const toList = getOrderedVisibleElements(toSlide);
|
|
2017
|
+
const usedFrom = /* @__PURE__ */ new Set();
|
|
2018
|
+
const usedTo = /* @__PURE__ */ new Set();
|
|
2019
|
+
const pairs = [];
|
|
2020
|
+
for (const fromEl of fromList) {
|
|
2021
|
+
const key = resolveExplicitMorphKey(fromEl);
|
|
2022
|
+
if (!key) continue;
|
|
2023
|
+
const candidate = toList.find(
|
|
2024
|
+
(toEl) => !usedTo.has(toEl.id) && resolveExplicitMorphKey(toEl) === key
|
|
2025
|
+
);
|
|
2026
|
+
if (candidate) {
|
|
2027
|
+
usedFrom.add(fromEl.id);
|
|
2028
|
+
usedTo.add(candidate.id);
|
|
2029
|
+
pairs.push({
|
|
2030
|
+
key: `morph:${key}`,
|
|
2031
|
+
matchReason: "morphName",
|
|
2032
|
+
fromElement: fromEl,
|
|
2033
|
+
toElement: candidate
|
|
2034
|
+
});
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
const toById = /* @__PURE__ */ new Map();
|
|
2038
|
+
for (const toEl of toList) {
|
|
2039
|
+
if (!usedTo.has(toEl.id)) toById.set(toEl.id, toEl);
|
|
2040
|
+
}
|
|
2041
|
+
for (const fromEl of fromList) {
|
|
2042
|
+
if (usedFrom.has(fromEl.id)) continue;
|
|
2043
|
+
const sameIdEl = toById.get(fromEl.id);
|
|
2044
|
+
if (sameIdEl && !usedTo.has(sameIdEl.id)) {
|
|
2045
|
+
usedFrom.add(fromEl.id);
|
|
2046
|
+
usedTo.add(sameIdEl.id);
|
|
2047
|
+
pairs.push({
|
|
2048
|
+
key: `id:${fromEl.id}`,
|
|
2049
|
+
matchReason: "id",
|
|
2050
|
+
fromElement: fromEl,
|
|
2051
|
+
toElement: sameIdEl
|
|
2052
|
+
});
|
|
2053
|
+
}
|
|
2054
|
+
}
|
|
2055
|
+
const matchUniqueBySignatureFn = (sigFn) => {
|
|
2056
|
+
const fromSigMap = /* @__PURE__ */ new Map();
|
|
2057
|
+
const toSigMap = /* @__PURE__ */ new Map();
|
|
2058
|
+
for (const fromEl of fromList) {
|
|
2059
|
+
if (usedFrom.has(fromEl.id)) continue;
|
|
2060
|
+
const sig = sigFn(fromEl);
|
|
2061
|
+
const arr = fromSigMap.get(sig) ?? [];
|
|
2062
|
+
arr.push(fromEl);
|
|
2063
|
+
fromSigMap.set(sig, arr);
|
|
2064
|
+
}
|
|
2065
|
+
for (const toEl of toList) {
|
|
2066
|
+
if (usedTo.has(toEl.id)) continue;
|
|
2067
|
+
const sig = sigFn(toEl);
|
|
2068
|
+
const arr = toSigMap.get(sig) ?? [];
|
|
2069
|
+
arr.push(toEl);
|
|
2070
|
+
toSigMap.set(sig, arr);
|
|
2071
|
+
}
|
|
2072
|
+
for (const [sig, fArr] of fromSigMap.entries()) {
|
|
2073
|
+
const tArr = toSigMap.get(sig);
|
|
2074
|
+
if (fArr.length === 1 && tArr && tArr.length === 1) {
|
|
2075
|
+
const fEl = fArr[0];
|
|
2076
|
+
const tEl = tArr[0];
|
|
2077
|
+
usedFrom.add(fEl.id);
|
|
2078
|
+
usedTo.add(tEl.id);
|
|
2079
|
+
pairs.push({
|
|
2080
|
+
key: `sig:${sig}`,
|
|
2081
|
+
matchReason: "signature",
|
|
2082
|
+
fromElement: fEl,
|
|
2083
|
+
toElement: tEl
|
|
2084
|
+
});
|
|
1697
2085
|
}
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
2086
|
+
}
|
|
2087
|
+
};
|
|
2088
|
+
matchUniqueBySignatureFn(getElementDetailedSignature);
|
|
2089
|
+
matchUniqueBySignatureFn(getElementCoarseSignature);
|
|
2090
|
+
const unmatchedFrom = fromList.filter((el) => !usedFrom.has(el.id));
|
|
2091
|
+
const unmatchedTo = toList.filter((el) => !usedTo.has(el.id));
|
|
2092
|
+
return { pairs, unmatchedFrom, unmatchedTo };
|
|
2093
|
+
}
|
|
2094
|
+
function interpolateElementPair(fromEl, toEl, easedT) {
|
|
2095
|
+
const base = Tools2.deepClone(easedT < 0.5 ? fromEl : toEl);
|
|
2096
|
+
base.id = toEl.id;
|
|
2097
|
+
if (toEl.morphName || fromEl.morphName) {
|
|
2098
|
+
base.morphName = toEl.morphName ?? fromEl.morphName;
|
|
2099
|
+
}
|
|
2100
|
+
base.x = lerpNum(fromEl.x, toEl.x, easedT);
|
|
2101
|
+
base.y = lerpNum(fromEl.y, toEl.y, easedT);
|
|
2102
|
+
base.width = Math.max(1, lerpNum(fromEl.width, toEl.width, easedT));
|
|
2103
|
+
base.height = Math.max(1, lerpNum(fromEl.height, toEl.height, easedT));
|
|
2104
|
+
base.rotation = lerpNum(fromEl.rotation ?? 0, toEl.rotation ?? 0, easedT);
|
|
2105
|
+
base.opacity = lerpNum(fromEl.opacity ?? 1, toEl.opacity ?? 1, easedT, 4);
|
|
2106
|
+
if (base.type === "shape" && fromEl.type === "shape" && toEl.type === "shape") {
|
|
2107
|
+
const s = base;
|
|
2108
|
+
s.cornerRadius = lerpNum(fromEl.cornerRadius ?? 8, toEl.cornerRadius ?? 8, easedT);
|
|
2109
|
+
s.strokeWidth = lerpNum(fromEl.strokeWidth ?? 1, toEl.strokeWidth ?? 1, easedT);
|
|
2110
|
+
s.fontSize = lerpNum(fromEl.fontSize ?? 16, toEl.fontSize ?? 16, easedT);
|
|
2111
|
+
s.fillColor = interpolateHexColor(fromEl.fillColor, toEl.fillColor, easedT) ?? s.fillColor;
|
|
2112
|
+
s.strokeColor = interpolateHexColor(fromEl.strokeColor, toEl.strokeColor, easedT) ?? s.strokeColor;
|
|
2113
|
+
const textClr = interpolateHexColor(fromEl.textColor, toEl.textColor, easedT);
|
|
2114
|
+
if (textClr) s.textColor = textClr;
|
|
2115
|
+
if (fromEl.gradientFrom || toEl.gradientFrom) {
|
|
2116
|
+
s.gradientFrom = interpolateHexColor(
|
|
2117
|
+
fromEl.gradientFrom ?? fromEl.fillColor,
|
|
2118
|
+
toEl.gradientFrom ?? toEl.fillColor,
|
|
2119
|
+
easedT
|
|
1704
2120
|
);
|
|
1705
|
-
}
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
);
|
|
1712
|
-
}
|
|
1713
|
-
body.push(
|
|
1714
|
-
`<path d="${geom.pathD}" fill="none" stroke="${escapeSvgXml(el.strokeColor)}" stroke-width="${el.strokeWidth || 2}"${el.endArrow ? ` marker-end="url(#${markerId})"` : ""}${opacityAttr}/>`
|
|
2121
|
+
}
|
|
2122
|
+
if (fromEl.gradientTo || toEl.gradientTo) {
|
|
2123
|
+
s.gradientTo = interpolateHexColor(
|
|
2124
|
+
fromEl.gradientTo ?? fromEl.fillColor,
|
|
2125
|
+
toEl.gradientTo ?? toEl.fillColor,
|
|
2126
|
+
easedT
|
|
1715
2127
|
);
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
);
|
|
1740
|
-
}
|
|
1741
|
-
lines.forEach((line, lIdx) => {
|
|
1742
|
-
const prefix = el.bullet ? el.bullet === "number" ? `${lIdx + 1}. ` : "\u2022 " : "";
|
|
1743
|
-
const ty = el.y + fs + 6 + lIdx * fs * (el.lineHeight ?? 1.35);
|
|
1744
|
-
body.push(
|
|
1745
|
-
`<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>`
|
|
1746
|
-
);
|
|
1747
|
-
});
|
|
1748
|
-
body.push(`</g>`);
|
|
1749
|
-
} else if (el.type === "chart") {
|
|
1750
|
-
const inner = renderSlideChartToSvg({ ...el, width: el.width, height: el.height }, theme).replace(/^<svg[^>]*>/, "").replace(/<\/svg>$/, "");
|
|
1751
|
-
body.push(`<g transform="translate(${el.x} ${el.y})"${opacityAttr}>${inner}</g>`);
|
|
1752
|
-
} else if (el.type === "smartArt") {
|
|
1753
|
-
const inner = renderSlideSmartArtToSvg({ ...el, width: el.width, height: el.height }, theme).replace(/^<svg[^>]*>/, "").replace(/<\/svg>$/, "");
|
|
1754
|
-
body.push(`<g transform="translate(${el.x} ${el.y})"${opacityAttr}>${inner}</g>`);
|
|
1755
|
-
} else if (el.type === "table") {
|
|
1756
|
-
body.push(`<g transform="translate(${el.x} ${el.y})"${opacityAttr}>`);
|
|
1757
|
-
let curY = 0;
|
|
1758
|
-
for (let r = 0; r < el.rows; r++) {
|
|
1759
|
-
const rh = el.rowHeights[r] ?? el.height / Math.max(1, el.rows);
|
|
1760
|
-
let curX = 0;
|
|
1761
|
-
for (let c = 0; c < el.cols; c++) {
|
|
1762
|
-
const cw = el.colWidths[c] ?? el.width / Math.max(1, el.cols);
|
|
1763
|
-
const cell = el.cells[r]?.[c];
|
|
1764
|
-
if (!cell?.mergedInto) {
|
|
1765
|
-
const isHeader = el.headerRow !== false && r === 0;
|
|
1766
|
-
const bgFill = cell?.bg || (isHeader ? el.headerBg || theme.colors.primary : r % 2 === 1 ? el.zebraBg || "#f8fafc" : "#ffffff");
|
|
1767
|
-
const fgFill = cell?.color || (isHeader ? el.headerColor || "#ffffff" : theme.colors.text);
|
|
1768
|
-
body.push(
|
|
1769
|
-
`<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"/>`,
|
|
1770
|
-
`<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>`
|
|
1771
|
-
);
|
|
1772
|
-
}
|
|
1773
|
-
curX += cw;
|
|
2128
|
+
}
|
|
2129
|
+
} else if (base.type === "text" && fromEl.type === "text" && toEl.type === "text") {
|
|
2130
|
+
const tx = base;
|
|
2131
|
+
tx.fontSize = lerpNum(fromEl.fontSize ?? 18, toEl.fontSize ?? 18, easedT);
|
|
2132
|
+
const nextColor = interpolateHexColor(fromEl.color, toEl.color, easedT);
|
|
2133
|
+
if (nextColor) tx.color = nextColor;
|
|
2134
|
+
if (fromEl.fillColor || toEl.fillColor) {
|
|
2135
|
+
tx.fillColor = interpolateHexColor(fromEl.fillColor, toEl.fillColor, easedT);
|
|
2136
|
+
}
|
|
2137
|
+
if (fromEl.strokeColor || toEl.strokeColor) {
|
|
2138
|
+
tx.strokeColor = interpolateHexColor(fromEl.strokeColor, toEl.strokeColor, easedT);
|
|
2139
|
+
}
|
|
2140
|
+
if (fromEl.strokeWidth !== void 0 || toEl.strokeWidth !== void 0) {
|
|
2141
|
+
tx.strokeWidth = lerpNum(fromEl.strokeWidth ?? 0, toEl.strokeWidth ?? 0, easedT);
|
|
2142
|
+
}
|
|
2143
|
+
if (fromEl.borderRadius !== void 0 || toEl.borderRadius !== void 0) {
|
|
2144
|
+
tx.borderRadius = lerpNum(fromEl.borderRadius ?? 4, toEl.borderRadius ?? 4, easedT);
|
|
2145
|
+
}
|
|
2146
|
+
if (tx.paragraphs) {
|
|
2147
|
+
for (const p of tx.paragraphs) {
|
|
2148
|
+
for (const r of p.runs) {
|
|
2149
|
+
r.fontSize = tx.fontSize;
|
|
2150
|
+
if (nextColor) r.color = nextColor;
|
|
1774
2151
|
}
|
|
1775
|
-
curY += rh;
|
|
1776
2152
|
}
|
|
1777
|
-
body.push(`</g>`);
|
|
1778
|
-
} else if (el.type === "image" || el.type === "svg") {
|
|
1779
|
-
if (el.src) {
|
|
1780
|
-
body.push(
|
|
1781
|
-
`<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}/>`
|
|
1782
|
-
);
|
|
1783
|
-
}
|
|
1784
|
-
} else if (el.type === "codeBlock") {
|
|
1785
|
-
const dark = el.codeTheme !== "light";
|
|
1786
|
-
body.push(
|
|
1787
|
-
`<g transform="translate(${el.x} ${el.y})"${opacityAttr}>`,
|
|
1788
|
-
`<rect x="0" y="0" width="${el.width}" height="${el.height}" rx="8" fill="${dark ? "#0f172a" : "#f8fafc"}" stroke="#334155" stroke-width="1"/>`,
|
|
1789
|
-
`<text x="12" y="20" font-size="10" font-weight="700" fill="#38bdf8">${escapeSvgXml(el.language.toUpperCase())}</text>`
|
|
1790
|
-
);
|
|
1791
|
-
el.code.split("\n").slice(0, 12).forEach((ln, idx) => {
|
|
1792
|
-
body.push(
|
|
1793
|
-
`<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>`
|
|
1794
|
-
);
|
|
1795
|
-
});
|
|
1796
|
-
body.push(`</g>`);
|
|
1797
|
-
} else if (el.type === "sheetEmbed") {
|
|
1798
|
-
body.push(
|
|
1799
|
-
`<g transform="translate(${el.x} ${el.y})"${opacityAttr}>`,
|
|
1800
|
-
`<rect x="0" y="0" width="${el.width}" height="${el.height}" rx="6" fill="#ffffff" stroke="#10b981" stroke-width="1.2"/>`,
|
|
1801
|
-
`<rect x="0" y="0" width="${el.width}" height="24" rx="6" fill="${escapeSvgXml(el.accentColor || "#059669")}"/>`,
|
|
1802
|
-
`<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>`,
|
|
1803
|
-
`</g>`
|
|
1804
|
-
);
|
|
1805
2153
|
}
|
|
1806
|
-
}
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
2154
|
+
} else if (base.type === "connector" && fromEl.type === "connector" && toEl.type === "connector") {
|
|
2155
|
+
const c = base;
|
|
2156
|
+
c.strokeWidth = lerpNum(fromEl.strokeWidth ?? 2, toEl.strokeWidth ?? 2, easedT);
|
|
2157
|
+
c.strokeColor = interpolateHexColor(fromEl.strokeColor, toEl.strokeColor, easedT) ?? c.strokeColor;
|
|
2158
|
+
if (fromEl.labelColor || toEl.labelColor) {
|
|
2159
|
+
c.labelColor = interpolateHexColor(fromEl.labelColor, toEl.labelColor, easedT);
|
|
2160
|
+
}
|
|
2161
|
+
c.startX = lerpNum(fromEl.startX ?? fromEl.x, toEl.startX ?? toEl.x, easedT);
|
|
2162
|
+
c.startY = lerpNum(fromEl.startY ?? fromEl.y, toEl.startY ?? toEl.y, easedT);
|
|
2163
|
+
c.endX = lerpNum(
|
|
2164
|
+
fromEl.endX ?? fromEl.x + fromEl.width,
|
|
2165
|
+
toEl.endX ?? toEl.x + toEl.width,
|
|
2166
|
+
easedT
|
|
1810
2167
|
);
|
|
2168
|
+
c.endY = lerpNum(
|
|
2169
|
+
fromEl.endY ?? fromEl.y + fromEl.height,
|
|
2170
|
+
toEl.endY ?? toEl.y + toEl.height,
|
|
2171
|
+
easedT
|
|
2172
|
+
);
|
|
2173
|
+
} else if ((base.type === "image" || base.type === "svg") && (fromEl.type === "image" || fromEl.type === "svg") && (toEl.type === "image" || toEl.type === "svg")) {
|
|
2174
|
+
const img = base;
|
|
2175
|
+
if (fromEl.borderRadius !== void 0 || toEl.borderRadius !== void 0) {
|
|
2176
|
+
img.borderRadius = lerpNum(fromEl.borderRadius ?? 0, toEl.borderRadius ?? 0, easedT);
|
|
2177
|
+
}
|
|
2178
|
+
} else if (base.type === "codeBlock" && fromEl.type === "codeBlock" && toEl.type === "codeBlock") {
|
|
2179
|
+
const cb = base;
|
|
2180
|
+
cb.fontSize = lerpNum(fromEl.fontSize ?? 12, toEl.fontSize ?? 12, easedT);
|
|
2181
|
+
} else if (base.type === "smartArt" && fromEl.type === "smartArt" && toEl.type === "smartArt") {
|
|
2182
|
+
const sa = base;
|
|
2183
|
+
if (fromEl.accentColor || toEl.accentColor) {
|
|
2184
|
+
sa.accentColor = interpolateHexColor(fromEl.accentColor, toEl.accentColor, easedT);
|
|
2185
|
+
}
|
|
2186
|
+
} else if (base.type === "sheetEmbed" && fromEl.type === "sheetEmbed" && toEl.type === "sheetEmbed") {
|
|
2187
|
+
const se = base;
|
|
2188
|
+
if (fromEl.accentColor || toEl.accentColor) {
|
|
2189
|
+
se.accentColor = interpolateHexColor(fromEl.accentColor, toEl.accentColor, easedT);
|
|
2190
|
+
}
|
|
2191
|
+
}
|
|
2192
|
+
return base;
|
|
2193
|
+
}
|
|
2194
|
+
function interpolateSlideBackground(fromBg, toBg, easedT) {
|
|
2195
|
+
if (!fromBg && !toBg) return void 0;
|
|
2196
|
+
if (fromBg?.type === "solid" && toBg?.type === "solid") {
|
|
2197
|
+
return {
|
|
2198
|
+
type: "solid",
|
|
2199
|
+
color: interpolateHexColor(fromBg.color, toBg.color, easedT) ?? toBg.color
|
|
2200
|
+
};
|
|
1811
2201
|
}
|
|
1812
|
-
|
|
2202
|
+
if (fromBg?.type === "gradient" && toBg?.type === "gradient") {
|
|
2203
|
+
return {
|
|
2204
|
+
type: "gradient",
|
|
2205
|
+
gradientFrom: interpolateHexColor(fromBg.gradientFrom, toBg.gradientFrom, easedT),
|
|
2206
|
+
gradientTo: interpolateHexColor(fromBg.gradientTo, toBg.gradientTo, easedT),
|
|
2207
|
+
gradientAngleDeg: lerpNum(
|
|
2208
|
+
fromBg.gradientAngleDeg ?? 135,
|
|
2209
|
+
toBg.gradientAngleDeg ?? 135,
|
|
2210
|
+
easedT
|
|
2211
|
+
)
|
|
2212
|
+
};
|
|
2213
|
+
}
|
|
2214
|
+
return Tools2.deepClone(easedT < 0.5 ? fromBg ?? toBg : toBg ?? fromBg);
|
|
2215
|
+
}
|
|
2216
|
+
function computeMorphInterpolatedSlide(fromSlide, toSlide, progress) {
|
|
2217
|
+
const clamped = Math.max(0, Math.min(1, Number.isFinite(progress) ? progress : 1));
|
|
2218
|
+
const eased = cubicEaseInOut(clamped);
|
|
2219
|
+
const { pairs, unmatchedFrom, unmatchedTo } = matchMorphSlidePairs(fromSlide, toSlide);
|
|
2220
|
+
const elements = {};
|
|
2221
|
+
const elementOrder = [];
|
|
2222
|
+
const toPairMap = /* @__PURE__ */ new Map();
|
|
2223
|
+
for (const p of pairs) {
|
|
2224
|
+
toPairMap.set(p.toElement.id, p);
|
|
2225
|
+
}
|
|
2226
|
+
for (const outEl of unmatchedFrom) {
|
|
2227
|
+
const clone = Tools2.deepClone(outEl);
|
|
2228
|
+
const outId = elements[clone.id] ? `morph-out-${clone.id}` : clone.id;
|
|
2229
|
+
clone.id = outId;
|
|
2230
|
+
clone.opacity = lerpNum(outEl.opacity ?? 1, 0, eased, 4);
|
|
2231
|
+
elements[outId] = clone;
|
|
2232
|
+
elementOrder.push(outId);
|
|
2233
|
+
}
|
|
2234
|
+
const orderedTo = getOrderedVisibleElements(toSlide);
|
|
2235
|
+
const unmatchedToIds = new Set(unmatchedTo.map((e) => e.id));
|
|
2236
|
+
for (const toEl of orderedTo) {
|
|
2237
|
+
const pair = toPairMap.get(toEl.id);
|
|
2238
|
+
if (pair) {
|
|
2239
|
+
const morphed = interpolateElementPair(pair.fromElement, pair.toElement, eased);
|
|
2240
|
+
const id = elements[morphed.id] ? `morph-pair-${morphed.id}` : morphed.id;
|
|
2241
|
+
morphed.id = id;
|
|
2242
|
+
elements[id] = morphed;
|
|
2243
|
+
elementOrder.push(id);
|
|
2244
|
+
} else if (unmatchedToIds.has(toEl.id)) {
|
|
2245
|
+
const clone = Tools2.deepClone(toEl);
|
|
2246
|
+
const inId = elements[clone.id] ? `morph-in-${clone.id}` : clone.id;
|
|
2247
|
+
clone.id = inId;
|
|
2248
|
+
clone.opacity = lerpNum(0, toEl.opacity ?? 1, eased, 4);
|
|
2249
|
+
elements[inId] = clone;
|
|
2250
|
+
elementOrder.push(inId);
|
|
2251
|
+
}
|
|
2252
|
+
}
|
|
2253
|
+
const background = interpolateSlideBackground(fromSlide.background, toSlide.background, eased);
|
|
2254
|
+
return {
|
|
2255
|
+
id: `morph-${fromSlide.id}-${toSlide.id}`,
|
|
2256
|
+
title: clamped < 0.5 ? fromSlide.title : toSlide.title,
|
|
2257
|
+
layoutId: toSlide.layoutId,
|
|
2258
|
+
hidden: false,
|
|
2259
|
+
showSlideNumber: toSlide.showSlideNumber,
|
|
2260
|
+
speakerNotes: toSlide.speakerNotes,
|
|
2261
|
+
...background ? { background } : {},
|
|
2262
|
+
transition: toSlide.transition ? Tools2.deepClone(toSlide.transition) : void 0,
|
|
2263
|
+
animations: [],
|
|
2264
|
+
elementOrder,
|
|
2265
|
+
elements
|
|
2266
|
+
};
|
|
1813
2267
|
}
|
|
1814
2268
|
|
|
1815
2269
|
// src/services/slide-selection.service.ts
|
|
@@ -1837,7 +2291,10 @@ var SlideSelectionService = class extends Disposable {
|
|
|
1837
2291
|
presenterMode: "presenter",
|
|
1838
2292
|
presenterSlideIndex: 0,
|
|
1839
2293
|
inspectorTab: "page",
|
|
1840
|
-
lastFindReplaceCount: 0
|
|
2294
|
+
lastFindReplaceCount: 0,
|
|
2295
|
+
masterViewOpen: false,
|
|
2296
|
+
activeMasterId: null,
|
|
2297
|
+
activeLayoutId: null
|
|
1841
2298
|
});
|
|
1842
2299
|
this.state$ = this._state$.asObservable();
|
|
1843
2300
|
}
|
|
@@ -1928,6 +2385,25 @@ var SlideSelectionService = class extends Disposable {
|
|
|
1928
2385
|
setInspectorTab(tab) {
|
|
1929
2386
|
this._patch({ inspectorTab: tab });
|
|
1930
2387
|
}
|
|
2388
|
+
setMasterViewOpen(open, target) {
|
|
2389
|
+
this._patch({
|
|
2390
|
+
masterViewOpen: open,
|
|
2391
|
+
selectedElementIds: [],
|
|
2392
|
+
editingElementId: null,
|
|
2393
|
+
editingTableCell: null,
|
|
2394
|
+
...target?.masterId !== void 0 ? { activeMasterId: target.masterId } : {},
|
|
2395
|
+
...target?.layoutId !== void 0 ? { activeLayoutId: target.layoutId } : {}
|
|
2396
|
+
});
|
|
2397
|
+
}
|
|
2398
|
+
setActiveMasterTarget(masterId, layoutId = null) {
|
|
2399
|
+
this._patch({
|
|
2400
|
+
activeMasterId: masterId,
|
|
2401
|
+
activeLayoutId: layoutId,
|
|
2402
|
+
selectedElementIds: [],
|
|
2403
|
+
editingElementId: null,
|
|
2404
|
+
editingTableCell: null
|
|
2405
|
+
});
|
|
2406
|
+
}
|
|
1931
2407
|
};
|
|
1932
2408
|
|
|
1933
2409
|
// src/services/slide-io.service.ts
|
|
@@ -1935,10 +2411,10 @@ import { createIdentifier as createIdentifier2, Disposable as Disposable2 } from
|
|
|
1935
2411
|
import { Subject as Subject2 } from "rxjs";
|
|
1936
2412
|
|
|
1937
2413
|
// src/exporter/pptx-codec.ts
|
|
1938
|
-
import { generateRandomId as generateRandomId3, Tools as
|
|
2414
|
+
import { generateRandomId as generateRandomId3, Tools as Tools4 } from "@univerjs/core";
|
|
1939
2415
|
|
|
1940
2416
|
// src/template/slide-template-engine.ts
|
|
1941
|
-
import { generateRandomId as generateRandomId2, Tools as
|
|
2417
|
+
import { generateRandomId as generateRandomId2, Tools as Tools3 } from "@univerjs/core";
|
|
1942
2418
|
var SCALAR_TOKEN_RE = /\$\{\s*([a-zA-Z0-9_$.#-]+)\s*\}/g;
|
|
1943
2419
|
var LOOP_TOKEN_RE = /#\{\s*([a-zA-Z0-9_$.#-]+)\s*\}/g;
|
|
1944
2420
|
function extractSlideDatasetCodes(snapshot) {
|
|
@@ -2077,7 +2553,7 @@ function substituteScalarTokens(text, datasets, fallback, rowContext) {
|
|
|
2077
2553
|
return result;
|
|
2078
2554
|
}
|
|
2079
2555
|
function applyDatasetToChart(chart, datasets, palette, fallback) {
|
|
2080
|
-
const next =
|
|
2556
|
+
const next = Tools3.deepClone(chart);
|
|
2081
2557
|
if (next.title) {
|
|
2082
2558
|
next.title = substituteScalarTokens(next.title, datasets, fallback);
|
|
2083
2559
|
}
|
|
@@ -2119,7 +2595,7 @@ function applyDatasetToChart(chart, datasets, palette, fallback) {
|
|
|
2119
2595
|
}
|
|
2120
2596
|
function expandTableWithDataset(table, datasets, slideHeightPt, options) {
|
|
2121
2597
|
const fallback = options?.missingValueFallback ?? "";
|
|
2122
|
-
const baseTable =
|
|
2598
|
+
const baseTable = Tools3.deepClone(table);
|
|
2123
2599
|
let templateRowIdx = -1;
|
|
2124
2600
|
let detectedLoopCode = baseTable.datasetLoopCode ?? null;
|
|
2125
2601
|
for (let r = 0; r < baseTable.cells.length; r++) {
|
|
@@ -2150,14 +2626,14 @@ function expandTableWithDataset(table, datasets, slideHeightPt, options) {
|
|
|
2150
2626
|
const records = Array.isArray(rawList) ? rawList.filter((item) => Boolean(item && typeof item === "object")) : [];
|
|
2151
2627
|
const headerRowsCells = baseTable.cells.slice(0, templateRowIdx).map(
|
|
2152
2628
|
(row) => row.map((cell) => ({
|
|
2153
|
-
...
|
|
2629
|
+
...Tools3.deepClone(cell),
|
|
2154
2630
|
text: substituteScalarTokens(cell.text, datasets, fallback)
|
|
2155
2631
|
}))
|
|
2156
2632
|
);
|
|
2157
2633
|
const headerRowHeights = baseTable.rowHeights.slice(0, templateRowIdx);
|
|
2158
2634
|
const footerRowsCells = baseTable.cells.slice(templateRowIdx + 1).map(
|
|
2159
2635
|
(row) => row.map((cell) => ({
|
|
2160
|
-
...
|
|
2636
|
+
...Tools3.deepClone(cell),
|
|
2161
2637
|
text: substituteScalarTokens(cell.text, datasets, fallback)
|
|
2162
2638
|
}))
|
|
2163
2639
|
);
|
|
@@ -2166,7 +2642,7 @@ function expandTableWithDataset(table, datasets, slideHeightPt, options) {
|
|
|
2166
2642
|
const templateRowH = baseTable.rowHeights[templateRowIdx] ?? Math.max(28, Math.round(baseTable.height / Math.max(1, baseTable.rows)));
|
|
2167
2643
|
const expandedDetailRows = records.map(
|
|
2168
2644
|
(record, rIdx) => templateRow.map((tplCell) => ({
|
|
2169
|
-
...
|
|
2645
|
+
...Tools3.deepClone(tplCell),
|
|
2170
2646
|
text: substituteScalarTokens(tplCell.text, datasets, fallback, {
|
|
2171
2647
|
record,
|
|
2172
2648
|
rowIndex: rIdx,
|
|
@@ -2207,9 +2683,9 @@ function expandTableWithDataset(table, datasets, slideHeightPt, options) {
|
|
|
2207
2683
|
const slice = expandedDetailRows.slice(offset, offset + maxDetailRows);
|
|
2208
2684
|
const isLastChunk = offset + maxDetailRows >= expandedDetailRows.length;
|
|
2209
2685
|
const chunkCells = [
|
|
2210
|
-
...
|
|
2686
|
+
...Tools3.deepClone(headerRowsCells),
|
|
2211
2687
|
...slice,
|
|
2212
|
-
...isLastChunk ?
|
|
2688
|
+
...isLastChunk ? Tools3.deepClone(footerRowsCells) : []
|
|
2213
2689
|
];
|
|
2214
2690
|
const chunkHeights = [
|
|
2215
2691
|
...headerRowHeights,
|
|
@@ -2217,7 +2693,7 @@ function expandTableWithDataset(table, datasets, slideHeightPt, options) {
|
|
|
2217
2693
|
...isLastChunk ? footerRowHeights : []
|
|
2218
2694
|
];
|
|
2219
2695
|
chunks.push({
|
|
2220
|
-
...
|
|
2696
|
+
...Tools3.deepClone(baseTable),
|
|
2221
2697
|
rows: chunkCells.length,
|
|
2222
2698
|
cells: chunkCells,
|
|
2223
2699
|
rowHeights: chunkHeights,
|
|
@@ -2228,7 +2704,7 @@ function expandTableWithDataset(table, datasets, slideHeightPt, options) {
|
|
|
2228
2704
|
}
|
|
2229
2705
|
function substituteElementScalars(el, datasets, palette, fallback) {
|
|
2230
2706
|
if (el.type === "text") {
|
|
2231
|
-
const next =
|
|
2707
|
+
const next = Tools3.deepClone(el);
|
|
2232
2708
|
next.text = substituteScalarTokens(next.text, datasets, fallback);
|
|
2233
2709
|
if (next.paragraphs) {
|
|
2234
2710
|
for (const p of next.paragraphs) {
|
|
@@ -2243,12 +2719,12 @@ function substituteElementScalars(el, datasets, palette, fallback) {
|
|
|
2243
2719
|
return next;
|
|
2244
2720
|
}
|
|
2245
2721
|
if (el.type === "shape") {
|
|
2246
|
-
const next =
|
|
2722
|
+
const next = Tools3.deepClone(el);
|
|
2247
2723
|
if (next.text) next.text = substituteScalarTokens(next.text, datasets, fallback);
|
|
2248
2724
|
return next;
|
|
2249
2725
|
}
|
|
2250
2726
|
if (el.type === "connector") {
|
|
2251
|
-
const next =
|
|
2727
|
+
const next = Tools3.deepClone(el);
|
|
2252
2728
|
if (next.label) next.label = substituteScalarTokens(next.label, datasets, fallback);
|
|
2253
2729
|
return next;
|
|
2254
2730
|
}
|
|
@@ -2256,7 +2732,7 @@ function substituteElementScalars(el, datasets, palette, fallback) {
|
|
|
2256
2732
|
return applyDatasetToChart(el, datasets, palette, fallback);
|
|
2257
2733
|
}
|
|
2258
2734
|
if (el.type === "smartArt") {
|
|
2259
|
-
const next =
|
|
2735
|
+
const next = Tools3.deepClone(el);
|
|
2260
2736
|
if (next.title) next.title = substituteScalarTokens(next.title, datasets, fallback);
|
|
2261
2737
|
const walk = (items) => {
|
|
2262
2738
|
for (const item of items) {
|
|
@@ -2269,7 +2745,7 @@ function substituteElementScalars(el, datasets, palette, fallback) {
|
|
|
2269
2745
|
return next;
|
|
2270
2746
|
}
|
|
2271
2747
|
if (el.type === "sheetEmbed") {
|
|
2272
|
-
const next =
|
|
2748
|
+
const next = Tools3.deepClone(el);
|
|
2273
2749
|
if (next.title) next.title = substituteScalarTokens(next.title, datasets, fallback);
|
|
2274
2750
|
next.headers = next.headers.map((h) => substituteScalarTokens(h, datasets, fallback));
|
|
2275
2751
|
next.rows = next.rows.map(
|
|
@@ -2277,10 +2753,10 @@ function substituteElementScalars(el, datasets, palette, fallback) {
|
|
|
2277
2753
|
);
|
|
2278
2754
|
return next;
|
|
2279
2755
|
}
|
|
2280
|
-
return
|
|
2756
|
+
return Tools3.deepClone(el);
|
|
2281
2757
|
}
|
|
2282
2758
|
function compileSlidesWithDataset(snapshot, datasets, options) {
|
|
2283
|
-
const result =
|
|
2759
|
+
const result = Tools3.deepClone(snapshot);
|
|
2284
2760
|
const fallback = options?.missingValueFallback ?? "";
|
|
2285
2761
|
const suffixFn = options?.continuationTitleSuffix ?? ((pageIdx, total) => ` (\u7EED ${pageIdx}/${total})`);
|
|
2286
2762
|
const palette = resolveChartPalette(void 0, result.theme);
|
|
@@ -2291,7 +2767,7 @@ function compileSlidesWithDataset(snapshot, datasets, options) {
|
|
|
2291
2767
|
for (const sid of result.slideOrder) {
|
|
2292
2768
|
const origSlide = result.slides[sid];
|
|
2293
2769
|
if (!origSlide) continue;
|
|
2294
|
-
const baseSlide =
|
|
2770
|
+
const baseSlide = Tools3.deepClone(origSlide);
|
|
2295
2771
|
baseSlide.title = substituteScalarTokens(baseSlide.title, datasets, fallback);
|
|
2296
2772
|
if (baseSlide.speakerNotes) {
|
|
2297
2773
|
baseSlide.speakerNotes = substituteScalarTokens(baseSlide.speakerNotes, datasets, fallback);
|
|
@@ -2325,14 +2801,14 @@ function compileSlidesWithDataset(snapshot, datasets, options) {
|
|
|
2325
2801
|
for (let chunkIdx = 1; chunkIdx < totalCont; chunkIdx++) {
|
|
2326
2802
|
const suffix = suffixFn(chunkIdx + 1, totalCont);
|
|
2327
2803
|
const contSlideId = `${sid}-cont-${chunkIdx + 1}-${generateRandomId2(4)}`;
|
|
2328
|
-
const clonedSlide =
|
|
2804
|
+
const clonedSlide = Tools3.deepClone(baseSlide);
|
|
2329
2805
|
clonedSlide.id = contSlideId;
|
|
2330
2806
|
clonedSlide.title = `${baseSlide.title}${suffix}`;
|
|
2331
2807
|
const idRemap = /* @__PURE__ */ new Map();
|
|
2332
2808
|
const newElements = {};
|
|
2333
2809
|
const newOrder = [];
|
|
2334
2810
|
for (const oldElId of baseSlide.elementOrder) {
|
|
2335
|
-
const srcEl = oldElId === paginatedTableId ?
|
|
2811
|
+
const srcEl = oldElId === paginatedTableId ? Tools3.deepClone(paginatedChunks[chunkIdx]) : Tools3.deepClone(baseSlide.elements[oldElId]);
|
|
2336
2812
|
if (!srcEl) continue;
|
|
2337
2813
|
const newElId = `el-${generateRandomId2(6)}`;
|
|
2338
2814
|
idRemap.set(oldElId, newElId);
|
|
@@ -3247,11 +3723,14 @@ function buildTransitionXml(tr) {
|
|
|
3247
3723
|
const spd = durMs <= 300 ? "fast" : durMs >= 800 ? "slow" : "med";
|
|
3248
3724
|
const advAttr = tr.advanceAfterMs && tr.advanceAfterMs > 0 ? ` advTm="${Math.round(tr.advanceAfterMs)}"` : "";
|
|
3249
3725
|
const dir = tr.direction === "right" ? "r" : tr.direction === "up" ? "u" : tr.direction === "down" ? "d" : "l";
|
|
3726
|
+
if (tr.type === "morph") {
|
|
3727
|
+
return `<p:transition xmlns:p159="http://schemas.microsoft.com/office/powerpoint/2015/09/main" spd="${spd}"${advAttr}><p159:morph option="byObject"/></p:transition>`;
|
|
3728
|
+
}
|
|
3250
3729
|
let inner = "<p:fade/>";
|
|
3251
3730
|
if (tr.type === "push") inner = `<p:push dir="${dir}"/>`;
|
|
3252
3731
|
else if (tr.type === "wipe") inner = `<p:wipe dir="${dir}"/>`;
|
|
3253
3732
|
else if (tr.type === "split") inner = `<p:split orient="horz" dir="out"/>`;
|
|
3254
|
-
else if (tr.type === "zoom"
|
|
3733
|
+
else if (tr.type === "zoom") inner = `<p:zoom dir="in"/>`;
|
|
3255
3734
|
return `<p:transition spd="${spd}"${advAttr}>${inner}</p:transition>`;
|
|
3256
3735
|
}
|
|
3257
3736
|
function buildTimingXml(animations, elIdToSpId) {
|
|
@@ -3307,7 +3786,7 @@ function decodeElementMetaDescr(descr) {
|
|
|
3307
3786
|
}
|
|
3308
3787
|
}
|
|
3309
3788
|
function exportPptxBytesSync(rawSnapshot, options) {
|
|
3310
|
-
const snapshot = options?.datasets ? compileSlidesWithDataset(rawSnapshot, options.datasets, options.templateOptions) :
|
|
3789
|
+
const snapshot = options?.datasets ? compileSlidesWithDataset(rawSnapshot, options.datasets, options.templateOptions) : Tools4.deepClone(rawSnapshot);
|
|
3311
3790
|
const files = [];
|
|
3312
3791
|
const mediaExts = /* @__PURE__ */ new Set();
|
|
3313
3792
|
let mediaCounter = 0;
|
|
@@ -3341,6 +3820,60 @@ function exportPptxBytesSync(rawSnapshot, options) {
|
|
|
3341
3820
|
target: "../slideLayouts/slideLayout1.xml"
|
|
3342
3821
|
}
|
|
3343
3822
|
];
|
|
3823
|
+
let actionCounter = 0;
|
|
3824
|
+
const buildCNvPrTag = (spId, el, metaPayload) => {
|
|
3825
|
+
let cNvName = el.name || el.type;
|
|
3826
|
+
let mergedMeta = metaPayload ? { ...metaPayload } : void 0;
|
|
3827
|
+
if (el.morphName && el.morphName.trim().length > 0) {
|
|
3828
|
+
const cleanMorph = el.morphName.trim().startsWith("!!") ? el.morphName.trim().slice(2).trim() : el.morphName.trim();
|
|
3829
|
+
if (cleanMorph) {
|
|
3830
|
+
cNvName = `!!${cleanMorph}`;
|
|
3831
|
+
if (el.name && el.name !== cNvName) {
|
|
3832
|
+
mergedMeta = { ...mergedMeta ?? {}, displayName: el.name };
|
|
3833
|
+
}
|
|
3834
|
+
}
|
|
3835
|
+
}
|
|
3836
|
+
const descrAttr = mergedMeta ? ` descr="${escapeXml(encodeElementMetaDescr(mergedMeta))}"` : "";
|
|
3837
|
+
if (!el.action || el.action.type === "none") {
|
|
3838
|
+
return `<p:cNvPr id="${spId}" name="${escapeXml(cNvName)}"${descrAttr}/>`;
|
|
3839
|
+
}
|
|
3840
|
+
actionCounter += 1;
|
|
3841
|
+
const actRelId = `rIdAct${actionCounter}`;
|
|
3842
|
+
const hlinkRelType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";
|
|
3843
|
+
const tooltipAttr = el.action.tooltip ? ` tooltip="${escapeXml(el.action.tooltip)}"` : "";
|
|
3844
|
+
let hlinkAttrs = "";
|
|
3845
|
+
if (el.action.type === "nextSlide" || el.action.type === "prevSlide" || el.action.type === "firstSlide" || el.action.type === "lastSlide" || el.action.type === "endShow") {
|
|
3846
|
+
const jumpToken = el.action.type === "nextSlide" ? "nextslide" : el.action.type === "prevSlide" ? "previousslide" : el.action.type === "firstSlide" ? "firstslide" : el.action.type === "lastSlide" ? "lastslide" : "endshow";
|
|
3847
|
+
const actionUri = `ppaction://hlinkshowjump?jump=${jumpToken}`;
|
|
3848
|
+
slideRels.push({
|
|
3849
|
+
id: actRelId,
|
|
3850
|
+
type: hlinkRelType,
|
|
3851
|
+
target: actionUri,
|
|
3852
|
+
targetMode: "External"
|
|
3853
|
+
});
|
|
3854
|
+
hlinkAttrs = `r:id="${actRelId}" action="${actionUri}"${tooltipAttr}`;
|
|
3855
|
+
} else if (el.action.type === "slide") {
|
|
3856
|
+
const targetIdx = el.action.targetSlideId ? snapshot.slideOrder.indexOf(el.action.targetSlideId) : 0;
|
|
3857
|
+
const targetSlideNum = (targetIdx >= 0 ? targetIdx : 0) + 1;
|
|
3858
|
+
slideRels.push({
|
|
3859
|
+
id: actRelId,
|
|
3860
|
+
type: hlinkRelType,
|
|
3861
|
+
target: `slide${targetSlideNum}.xml`
|
|
3862
|
+
});
|
|
3863
|
+
hlinkAttrs = `r:id="${actRelId}" action="ppaction://hlinksldjump"${tooltipAttr}`;
|
|
3864
|
+
} else if (el.action.type === "url") {
|
|
3865
|
+
const extUrl = el.action.url || "https://example.com";
|
|
3866
|
+
slideRels.push({
|
|
3867
|
+
id: actRelId,
|
|
3868
|
+
type: hlinkRelType,
|
|
3869
|
+
target: extUrl,
|
|
3870
|
+
targetMode: "External"
|
|
3871
|
+
});
|
|
3872
|
+
hlinkAttrs = `r:id="${actRelId}"${tooltipAttr}`;
|
|
3873
|
+
}
|
|
3874
|
+
const hoverXml = el.action.trigger === "hover" ? `<a:hlinkHover ${hlinkAttrs}/>` : "";
|
|
3875
|
+
return `<p:cNvPr id="${spId}" name="${escapeXml(cNvName)}"${descrAttr}><a:hlinkClick ${hlinkAttrs}/>${hoverXml}</p:cNvPr>`;
|
|
3876
|
+
};
|
|
3344
3877
|
const addMedia = (src) => {
|
|
3345
3878
|
mediaCounter += 1;
|
|
3346
3879
|
const decoded = decodeImageSource(src);
|
|
@@ -3385,22 +3918,19 @@ function exportPptxBytesSync(rawSnapshot, options) {
|
|
|
3385
3918
|
const extCx = Math.max(12700, ptToEmu(el.width));
|
|
3386
3919
|
const extCy = Math.max(12700, ptToEmu(el.height));
|
|
3387
3920
|
const rotAttr = el.rotation ? ` rot="${Math.round(el.rotation * 6e4)}"` : "";
|
|
3388
|
-
const nameAttr = escapeXml(el.name || el.type);
|
|
3389
3921
|
if (el.type === "text") {
|
|
3390
3922
|
const fillXml = el.fillColor ? `<a:solidFill><a:srgbClr val="${normalizeHex6(el.fillColor, "FFFFFF")}"/></a:solidFill>` : "<a:noFill/>";
|
|
3391
3923
|
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>";
|
|
3392
|
-
const
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
})
|
|
3400
|
-
)}"` : "";
|
|
3924
|
+
const textMeta = el.wordArt?.enabled || el.placeholderRole || el.datasetBinding ? {
|
|
3925
|
+
kind: "text",
|
|
3926
|
+
id: el.id,
|
|
3927
|
+
wordArt: el.wordArt,
|
|
3928
|
+
placeholderRole: el.placeholderRole,
|
|
3929
|
+
datasetBinding: el.datasetBinding
|
|
3930
|
+
} : void 0;
|
|
3401
3931
|
spTreeItems.push(`<p:sp>
|
|
3402
3932
|
<p:nvSpPr>
|
|
3403
|
-
|
|
3933
|
+
${buildCNvPrTag(spId, el, textMeta)}
|
|
3404
3934
|
<p:cNvSpPr txBox="1"/>
|
|
3405
3935
|
<p:nvPr/>
|
|
3406
3936
|
</p:nvSpPr>
|
|
@@ -3432,7 +3962,7 @@ function exportPptxBytesSync(rawSnapshot, options) {
|
|
|
3432
3962
|
</p:txBody>` : "<p:txBody><a:bodyPr/><a:lstStyle/><a:p/></p:txBody>";
|
|
3433
3963
|
spTreeItems.push(`<p:sp>
|
|
3434
3964
|
<p:nvSpPr>
|
|
3435
|
-
|
|
3965
|
+
${buildCNvPrTag(spId, el, { kind: "shape", id: el.id, cornerRadius: el.cornerRadius })}
|
|
3436
3966
|
<p:cNvSpPr/>
|
|
3437
3967
|
<p:nvPr/>
|
|
3438
3968
|
</p:nvSpPr>
|
|
@@ -3458,7 +3988,9 @@ function exportPptxBytesSync(rawSnapshot, options) {
|
|
|
3458
3988
|
const headEnd = el.startArrow ? '<a:headEnd type="triangle"/>' : "";
|
|
3459
3989
|
const tailEnd = el.endArrow ? '<a:tailEnd type="triangle"/>' : "";
|
|
3460
3990
|
const dashXml = el.strokeDash === "dashed" ? '<a:prstDash val="dash"/>' : el.strokeDash === "dotted" ? '<a:prstDash val="sysDot"/>' : "";
|
|
3461
|
-
|
|
3991
|
+
spTreeItems.push(`<p:cxnSp>
|
|
3992
|
+
<p:nvCxnSpPr>
|
|
3993
|
+
${buildCNvPrTag(spId, el, {
|
|
3462
3994
|
kind: "connector",
|
|
3463
3995
|
id: el.id,
|
|
3464
3996
|
label: el.label,
|
|
@@ -3469,10 +4001,7 @@ function exportPptxBytesSync(rawSnapshot, options) {
|
|
|
3469
4001
|
startY: el.startY,
|
|
3470
4002
|
endX: el.endX,
|
|
3471
4003
|
endY: el.endY
|
|
3472
|
-
})
|
|
3473
|
-
spTreeItems.push(`<p:cxnSp>
|
|
3474
|
-
<p:nvCxnSpPr>
|
|
3475
|
-
<p:cNvPr id="${spId}" name="${nameAttr}" descr="${escapeXml(descr)}"/>
|
|
4004
|
+
})}
|
|
3476
4005
|
<p:cNvCxnSpPr>${stCxn}${endCxn}</p:cNvCxnSpPr>
|
|
3477
4006
|
<p:nvPr/>
|
|
3478
4007
|
</p:nvCxnSpPr>
|
|
@@ -3488,16 +4017,15 @@ function exportPptxBytesSync(rawSnapshot, options) {
|
|
|
3488
4017
|
} else if (el.type === "image" || el.type === "svg") {
|
|
3489
4018
|
const src = el.svgContent ? svgToDataUri(el.svgContent) : el.src;
|
|
3490
4019
|
const rId = addMedia(src);
|
|
3491
|
-
|
|
4020
|
+
spTreeItems.push(`<p:pic>
|
|
4021
|
+
<p:nvPicPr>
|
|
4022
|
+
${buildCNvPrTag(spId, el, {
|
|
3492
4023
|
kind: el.type,
|
|
3493
4024
|
id: el.id,
|
|
3494
4025
|
fit: el.fit,
|
|
3495
4026
|
crop: el.crop,
|
|
3496
4027
|
altText: el.altText
|
|
3497
|
-
})
|
|
3498
|
-
spTreeItems.push(`<p:pic>
|
|
3499
|
-
<p:nvPicPr>
|
|
3500
|
-
<p:cNvPr id="${spId}" name="${nameAttr}" descr="${escapeXml(descr)}"/>
|
|
4028
|
+
})}
|
|
3501
4029
|
<p:cNvPicPr><a:picLocks noChangeAspect="1"/></p:cNvPicPr>
|
|
3502
4030
|
<p:nvPr/>
|
|
3503
4031
|
</p:nvPicPr>
|
|
@@ -3561,7 +4089,9 @@ function exportPptxBytesSync(rawSnapshot, options) {
|
|
|
3561
4089
|
}).join("");
|
|
3562
4090
|
return `<a:tr h="${ptToEmu(rh)}">${cellsXml}</a:tr>`;
|
|
3563
4091
|
}).join("");
|
|
3564
|
-
|
|
4092
|
+
spTreeItems.push(`<p:graphicFrame>
|
|
4093
|
+
<p:nvGraphicFramePr>
|
|
4094
|
+
${buildCNvPrTag(spId, el, {
|
|
3565
4095
|
kind: "table",
|
|
3566
4096
|
id: el.id,
|
|
3567
4097
|
headerRow: el.headerRow,
|
|
@@ -3570,10 +4100,7 @@ function exportPptxBytesSync(rawSnapshot, options) {
|
|
|
3570
4100
|
borderColor: el.borderColor,
|
|
3571
4101
|
zebraBg: el.zebraBg,
|
|
3572
4102
|
datasetLoopCode: el.datasetLoopCode
|
|
3573
|
-
})
|
|
3574
|
-
spTreeItems.push(`<p:graphicFrame>
|
|
3575
|
-
<p:nvGraphicFramePr>
|
|
3576
|
-
<p:cNvPr id="${spId}" name="${nameAttr}" descr="${escapeXml(descr)}"/>
|
|
4103
|
+
})}
|
|
3577
4104
|
<p:cNvGraphicFramePr><a:graphicFrameLocks noGrp="1"/></p:cNvGraphicFramePr>
|
|
3578
4105
|
<p:nvPr/>
|
|
3579
4106
|
</p:nvGraphicFramePr>
|
|
@@ -3604,7 +4131,9 @@ function exportPptxBytesSync(rawSnapshot, options) {
|
|
|
3604
4131
|
type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart",
|
|
3605
4132
|
target: `../charts/${chartFile}`
|
|
3606
4133
|
});
|
|
3607
|
-
|
|
4134
|
+
spTreeItems.push(`<p:graphicFrame>
|
|
4135
|
+
<p:nvGraphicFramePr>
|
|
4136
|
+
${buildCNvPrTag(spId, el, {
|
|
3608
4137
|
kind: "chart",
|
|
3609
4138
|
id: el.id,
|
|
3610
4139
|
datasetCode: el.datasetCode,
|
|
@@ -3612,10 +4141,7 @@ function exportPptxBytesSync(rawSnapshot, options) {
|
|
|
3612
4141
|
valueFields: el.valueFields,
|
|
3613
4142
|
showGrid: el.showGrid,
|
|
3614
4143
|
showValues: el.showValues
|
|
3615
|
-
})
|
|
3616
|
-
spTreeItems.push(`<p:graphicFrame>
|
|
3617
|
-
<p:nvGraphicFramePr>
|
|
3618
|
-
<p:cNvPr id="${spId}" name="${nameAttr}" descr="${escapeXml(descr)}"/>
|
|
4144
|
+
})}
|
|
3619
4145
|
<p:cNvGraphicFramePr><a:graphicFrameLocks noGrp="1"/></p:cNvGraphicFramePr>
|
|
3620
4146
|
<p:nvPr/>
|
|
3621
4147
|
</p:nvGraphicFramePr>
|
|
@@ -3626,15 +4152,17 @@ function exportPptxBytesSync(rawSnapshot, options) {
|
|
|
3626
4152
|
</a:graphicData>
|
|
3627
4153
|
</a:graphic>
|
|
3628
4154
|
</p:graphicFrame>`);
|
|
3629
|
-
} else if (el.type === "smartArt" || el.type === "codeBlock" || el.type === "sheetEmbed") {
|
|
4155
|
+
} else if (el.type === "smartArt" || el.type === "codeBlock" || el.type === "sheetEmbed" || el.type === "video" || el.type === "audio") {
|
|
3630
4156
|
let svgDataUri;
|
|
3631
4157
|
if (el.type === "smartArt") {
|
|
3632
4158
|
svgDataUri = renderSlideSmartArtToSvgDataUri(el, snapshot.theme);
|
|
4159
|
+
} else if (el.type === "video" || el.type === "audio") {
|
|
4160
|
+
svgDataUri = renderSlideMediaToSvgDataUri(el, snapshot.theme);
|
|
3633
4161
|
} else if (el.type === "codeBlock") {
|
|
3634
4162
|
const lines = el.code.split("\n").slice(0, 12);
|
|
3635
4163
|
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>`;
|
|
3636
4164
|
svgDataUri = svgToDataUri(svg);
|
|
3637
|
-
} else {
|
|
4165
|
+
} else if (el.type === "sheetEmbed") {
|
|
3638
4166
|
const fakeChart = {
|
|
3639
4167
|
id: el.id,
|
|
3640
4168
|
type: "chart",
|
|
@@ -3651,12 +4179,13 @@ function exportPptxBytesSync(rawSnapshot, options) {
|
|
|
3651
4179
|
}))
|
|
3652
4180
|
};
|
|
3653
4181
|
svgDataUri = svgToDataUri(renderSlideChartToSvg(fakeChart, snapshot.theme));
|
|
4182
|
+
} else {
|
|
4183
|
+
svgDataUri = renderSlideMediaToSvgDataUri(el, snapshot.theme);
|
|
3654
4184
|
}
|
|
3655
4185
|
const rId = addMedia(svgDataUri);
|
|
3656
|
-
const descr = encodeElementMetaDescr({ kind: "richElement", element: el });
|
|
3657
4186
|
spTreeItems.push(`<p:pic>
|
|
3658
4187
|
<p:nvPicPr>
|
|
3659
|
-
|
|
4188
|
+
${buildCNvPrTag(spId, el, { kind: "richElement", element: el })}
|
|
3660
4189
|
<p:cNvPicPr><a:picLocks noChangeAspect="1"/></p:cNvPicPr>
|
|
3661
4190
|
<p:nvPr/>
|
|
3662
4191
|
</p:nvPicPr>
|
|
@@ -3732,7 +4261,7 @@ function exportPptxBytesSync(rawSnapshot, options) {
|
|
|
3732
4261
|
name: `ppt/slides/_rels/slide${slideNum}.xml.rels`,
|
|
3733
4262
|
content: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
3734
4263
|
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
|
3735
|
-
${slideRels.map((r) => `<Relationship Id="${r.id}" Type="${r.type}" Target="${r.target}"/>`).join("\n ")}
|
|
4264
|
+
${slideRels.map((r) => `<Relationship Id="${r.id}" Type="${r.type}" Target="${escapeXml(r.target)}"${r.targetMode ? ` TargetMode="${r.targetMode}"` : ""}/>`).join("\n ")}
|
|
3736
4265
|
</Relationships>`
|
|
3737
4266
|
});
|
|
3738
4267
|
});
|
|
@@ -3797,9 +4326,10 @@ function exportPptxBytesSync(rawSnapshot, options) {
|
|
|
3797
4326
|
${presRels.join("\n ")}
|
|
3798
4327
|
</Relationships>`
|
|
3799
4328
|
});
|
|
4329
|
+
const showPrXml = snapshot.slideshowSettings?.loopContinuously ? `<p:showPr loop="1"/>` : "";
|
|
3800
4330
|
files.push({
|
|
3801
4331
|
name: "ppt/presProps.xml",
|
|
3802
|
-
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"
|
|
4332
|
+
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>`
|
|
3803
4333
|
});
|
|
3804
4334
|
files.push({
|
|
3805
4335
|
name: "ppt/viewProps.xml",
|
|
@@ -3813,6 +4343,43 @@ function exportPptxBytesSync(rawSnapshot, options) {
|
|
|
3813
4343
|
name: "ppt/theme/theme1.xml",
|
|
3814
4344
|
content: buildThemeXml(snapshot.theme)
|
|
3815
4345
|
});
|
|
4346
|
+
const primaryMaster = snapshot.masters[0];
|
|
4347
|
+
const masterSpItems = [];
|
|
4348
|
+
if (primaryMaster?.masterElements && primaryMaster.masterElements.length > 0) {
|
|
4349
|
+
primaryMaster.masterElements.forEach((mEl, mIdx) => {
|
|
4350
|
+
if (!mEl || mEl.hidden) return;
|
|
4351
|
+
const mSpId = 100 + mIdx;
|
|
4352
|
+
const mOffX = ptToEmu(mEl.x);
|
|
4353
|
+
const mOffY = ptToEmu(mEl.y);
|
|
4354
|
+
const mExtCx = Math.max(12700, ptToEmu(mEl.width));
|
|
4355
|
+
const mExtCy = Math.max(12700, ptToEmu(mEl.height));
|
|
4356
|
+
if (mEl.type === "text") {
|
|
4357
|
+
masterSpItems.push(`<p:sp>
|
|
4358
|
+
<p:nvSpPr><p:cNvPr id="${mSpId}" name="${escapeXml(mEl.name || "MasterText")}"/><p:cNvSpPr txBox="1"/><p:nvPr/></p:nvSpPr>
|
|
4359
|
+
<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>
|
|
4360
|
+
${buildTextBodyXml(mEl, snapshot.theme)}
|
|
4361
|
+
</p:sp>`);
|
|
4362
|
+
} else if (mEl.type === "shape") {
|
|
4363
|
+
const prst = SHAPE_TO_OOXML_PRST[mEl.shapeType] ?? "rect";
|
|
4364
|
+
masterSpItems.push(`<p:sp>
|
|
4365
|
+
<p:nvSpPr><p:cNvPr id="${mSpId}" name="${escapeXml(mEl.name || "MasterShape")}"/><p:cNvSpPr/><p:nvPr/></p:nvSpPr>
|
|
4366
|
+
<p:spPr>
|
|
4367
|
+
<a:xfrm><a:off x="${mOffX}" y="${mOffY}"/><a:ext cx="${mExtCx}" cy="${mExtCy}"/></a:xfrm>
|
|
4368
|
+
<a:prstGeom prst="${prst}"><a:avLst/></a:prstGeom>
|
|
4369
|
+
<a:solidFill><a:srgbClr val="${normalizeHex6(mEl.fillColor, "2563EB")}"/></a:solidFill>
|
|
4370
|
+
</p:spPr>
|
|
4371
|
+
${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>"}
|
|
4372
|
+
</p:sp>`);
|
|
4373
|
+
}
|
|
4374
|
+
});
|
|
4375
|
+
}
|
|
4376
|
+
const masterMetaDescr = escapeXml(
|
|
4377
|
+
encodeElementMetaDescr({
|
|
4378
|
+
masters: snapshot.masters,
|
|
4379
|
+
layouts: snapshot.layouts,
|
|
4380
|
+
slideshowSettings: snapshot.slideshowSettings
|
|
4381
|
+
})
|
|
4382
|
+
);
|
|
3816
4383
|
files.push({
|
|
3817
4384
|
name: "ppt/slideMasters/slideMaster1.xml",
|
|
3818
4385
|
content: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
@@ -3820,8 +4387,9 @@ function exportPptxBytesSync(rawSnapshot, options) {
|
|
|
3820
4387
|
<p:cSld>
|
|
3821
4388
|
<p:bg><p:bgRef idx="1001"><a:schemeClr val="bg1"/></p:bgRef></p:bg>
|
|
3822
4389
|
<p:spTree>
|
|
3823
|
-
<p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr>
|
|
4390
|
+
<p:nvGrpSpPr><p:cNvPr id="1" name="" descr="${masterMetaDescr}"/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr>
|
|
3824
4391
|
<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>
|
|
4392
|
+
${masterSpItems.join("\n")}
|
|
3825
4393
|
</p:spTree>
|
|
3826
4394
|
</p:cSld>
|
|
3827
4395
|
<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"/>
|
|
@@ -3893,7 +4461,8 @@ function parseRelsXml(xml) {
|
|
|
3893
4461
|
const id = getAttr(attrs, "Id");
|
|
3894
4462
|
const target = getAttr(attrs, "Target");
|
|
3895
4463
|
const type = getAttr(attrs, "Type") ?? "";
|
|
3896
|
-
|
|
4464
|
+
const targetMode = getAttr(attrs, "TargetMode");
|
|
4465
|
+
if (id && target) map.set(id, { target, type, ...targetMode ? { targetMode } : {} });
|
|
3897
4466
|
}
|
|
3898
4467
|
return map;
|
|
3899
4468
|
}
|
|
@@ -3964,7 +4533,7 @@ function parseFirstSrgbHex(xmlFragment, schemeMap) {
|
|
|
3964
4533
|
return void 0;
|
|
3965
4534
|
}
|
|
3966
4535
|
function parseThemeFromXml(xml) {
|
|
3967
|
-
const base =
|
|
4536
|
+
const base = Tools4.deepClone(SLIDE_THEME_PRESETS[0]);
|
|
3968
4537
|
const themeTag = /<a:theme\b([^>]*)>/.exec(xml);
|
|
3969
4538
|
if (themeTag) {
|
|
3970
4539
|
const tName = getAttr(themeTag[1], "name");
|
|
@@ -4214,7 +4783,9 @@ function parseTransitionFromSlideXml(slideXml) {
|
|
|
4214
4783
|
let type = "fade";
|
|
4215
4784
|
let direction;
|
|
4216
4785
|
const parseDir = (d) => d === "r" ? "right" : d === "u" ? "up" : d === "d" ? "down" : d === "l" ? "left" : void 0;
|
|
4217
|
-
if (/<p:
|
|
4786
|
+
if (/<p159:morph\b/.test(trBlock) || /<p:morph\b/.test(trBlock)) {
|
|
4787
|
+
type = "morph";
|
|
4788
|
+
} else if (/<p:push\b/.test(trBlock)) {
|
|
4218
4789
|
type = "push";
|
|
4219
4790
|
direction = parseDir(/<p:push\b[^>]*dir="([^"]+)"/.exec(trBlock)?.[1]);
|
|
4220
4791
|
} else if (/<p:wipe\b/.test(trBlock)) {
|
|
@@ -4261,6 +4832,50 @@ function parseTimingAnimationsFromSlideXml(slideXml, spIdToElId) {
|
|
|
4261
4832
|
}
|
|
4262
4833
|
return animations;
|
|
4263
4834
|
}
|
|
4835
|
+
function parseActionFromCNvPrBlock(cNvPrBlock, slideDir, slideRels, slideZipPathToSlideId) {
|
|
4836
|
+
const hoverMatch = /<a:hlinkHover\b([^>]*)\/?>/.exec(cNvPrBlock);
|
|
4837
|
+
const clickMatch = /<a:hlinkClick\b([^>]*)\/?>/.exec(cNvPrBlock);
|
|
4838
|
+
const chosen = hoverMatch ?? clickMatch;
|
|
4839
|
+
if (!chosen) return void 0;
|
|
4840
|
+
const trigger = hoverMatch ? "hover" : "click";
|
|
4841
|
+
const attrs = chosen[1];
|
|
4842
|
+
const rId = getAttr(attrs, "r:id");
|
|
4843
|
+
const actionUri = (getAttr(attrs, "action") ?? "").trim();
|
|
4844
|
+
const lowerUri = actionUri.toLowerCase();
|
|
4845
|
+
const tooltip = getAttr(attrs, "tooltip");
|
|
4846
|
+
const rel = rId ? slideRels.get(rId) : void 0;
|
|
4847
|
+
let type = "none";
|
|
4848
|
+
let targetSlideId;
|
|
4849
|
+
let url;
|
|
4850
|
+
if (lowerUri.includes("jump=nextslide")) {
|
|
4851
|
+
type = "nextSlide";
|
|
4852
|
+
} else if (lowerUri.includes("jump=previousslide")) {
|
|
4853
|
+
type = "prevSlide";
|
|
4854
|
+
} else if (lowerUri.includes("jump=firstslide")) {
|
|
4855
|
+
type = "firstSlide";
|
|
4856
|
+
} else if (lowerUri.includes("jump=lastslide")) {
|
|
4857
|
+
type = "lastSlide";
|
|
4858
|
+
} else if (lowerUri.includes("jump=endshow")) {
|
|
4859
|
+
type = "endShow";
|
|
4860
|
+
} else if (lowerUri.includes("hlinksldjump") || rel && rel.targetMode !== "External" && /slide\d+\.xml$/i.test(rel.target)) {
|
|
4861
|
+
type = "slide";
|
|
4862
|
+
if (rel) {
|
|
4863
|
+
const targetZipPath = resolveZipRelativePath(slideDir, rel.target);
|
|
4864
|
+
targetSlideId = slideZipPathToSlideId.get(targetZipPath);
|
|
4865
|
+
}
|
|
4866
|
+
} else if (rel?.target) {
|
|
4867
|
+
type = "url";
|
|
4868
|
+
url = rel.target;
|
|
4869
|
+
}
|
|
4870
|
+
if (type === "none") return void 0;
|
|
4871
|
+
return {
|
|
4872
|
+
trigger,
|
|
4873
|
+
type,
|
|
4874
|
+
...targetSlideId ? { targetSlideId } : {},
|
|
4875
|
+
...url ? { url } : {},
|
|
4876
|
+
...tooltip ? { tooltip } : {}
|
|
4877
|
+
};
|
|
4878
|
+
}
|
|
4264
4879
|
function importPptxBytesSync(pptxBytes, options) {
|
|
4265
4880
|
const zipMap = unpackZipSync(pptxBytes);
|
|
4266
4881
|
const decoder = new TextDecoder("utf-8");
|
|
@@ -4294,7 +4909,7 @@ function importPptxBytesSync(pptxBytes, options) {
|
|
|
4294
4909
|
}
|
|
4295
4910
|
}
|
|
4296
4911
|
const themeXml = readText("ppt/theme/theme1.xml");
|
|
4297
|
-
const { theme, schemeMap } = themeXml ? parseThemeFromXml(themeXml) : { theme:
|
|
4912
|
+
const { theme, schemeMap } = themeXml ? parseThemeFromXml(themeXml) : { theme: Tools4.deepClone(SLIDE_THEME_PRESETS[0]), schemeMap: {} };
|
|
4298
4913
|
const presRelsXml = readText("ppt/_rels/presentation.xml.rels") ?? "";
|
|
4299
4914
|
const presRels = parseRelsXml(presRelsXml);
|
|
4300
4915
|
const sldIdList = [];
|
|
@@ -4307,6 +4922,17 @@ function importPptxBytesSync(pptxBytes, options) {
|
|
|
4307
4922
|
const slideOrder = [];
|
|
4308
4923
|
const slides = {};
|
|
4309
4924
|
const ooxmlSldNumIdToSlideId = /* @__PURE__ */ new Map();
|
|
4925
|
+
const slideZipPathToSlideId = /* @__PURE__ */ new Map();
|
|
4926
|
+
sldIdList.forEach(({ rId }, sIdx) => {
|
|
4927
|
+
const rel = presRels.get(rId);
|
|
4928
|
+
const slidePath = rel ? resolveZipRelativePath("ppt", rel.target) : `ppt/slides/slide${sIdx + 1}.xml`;
|
|
4929
|
+
const slideXml = readText(slidePath);
|
|
4930
|
+
if (!slideXml) return;
|
|
4931
|
+
const nvGrpMatch = /<p:nvGrpSpPr>[\s\S]*?<p:cNvPr\b([^>]*)\/?>/.exec(slideXml);
|
|
4932
|
+
const slideMeta = decodeElementMetaDescr(nvGrpMatch ? getAttr(nvGrpMatch[1], "descr") : void 0);
|
|
4933
|
+
const slideId = slideMeta?.slideId || `slide-${sIdx + 1}`;
|
|
4934
|
+
slideZipPathToSlideId.set(slidePath, slideId);
|
|
4935
|
+
});
|
|
4310
4936
|
sldIdList.forEach(({ numId, rId }, sIdx) => {
|
|
4311
4937
|
const rel = presRels.get(rId);
|
|
4312
4938
|
const slidePath = rel ? resolveZipRelativePath("ppt", rel.target) : `ppt/slides/slide${sIdx + 1}.xml`;
|
|
@@ -4374,19 +5000,33 @@ function importPptxBytesSync(pptxBytes, options) {
|
|
|
4374
5000
|
const spIdToElId = /* @__PURE__ */ new Map();
|
|
4375
5001
|
const pendingConnectorRefs = [];
|
|
4376
5002
|
for (const item of tokenPositions) {
|
|
4377
|
-
const
|
|
4378
|
-
const cNvAttrs =
|
|
5003
|
+
const cNvPrBlock = extractBalancedBlocks(item.xml, "p:cNvPr")[0] ?? "";
|
|
5004
|
+
const cNvAttrs = /^<p:cNvPr\b([^>]*?)(?:\/>|>)/.exec(cNvPrBlock)?.[1] ?? "";
|
|
4379
5005
|
const spIdNum = Number(getAttr(cNvAttrs, "id") ?? 0);
|
|
4380
5006
|
const rawName = getAttr(cNvAttrs, "name");
|
|
4381
5007
|
const meta = decodeElementMetaDescr(getAttr(cNvAttrs, "descr"));
|
|
4382
5008
|
const box = parseXfrmBox(item.xml);
|
|
4383
5009
|
if (!box) continue;
|
|
5010
|
+
const parsedMorphName = rawName && rawName.startsWith("!!") && rawName.length > 2 ? rawName.slice(2).trim() : void 0;
|
|
5011
|
+
const parsedAction = parseActionFromCNvPrBlock(
|
|
5012
|
+
cNvPrBlock,
|
|
5013
|
+
slideDir,
|
|
5014
|
+
slideRels,
|
|
5015
|
+
slideZipPathToSlideId
|
|
5016
|
+
);
|
|
5017
|
+
const resolvedDisplayName = typeof meta?.displayName === "string" && meta.displayName ? meta.displayName : rawName;
|
|
5018
|
+
const baseActionAndMorph = {
|
|
5019
|
+
...parsedMorphName ? { morphName: parsedMorphName } : {},
|
|
5020
|
+
...parsedAction ? { action: parsedAction } : {}
|
|
5021
|
+
};
|
|
4384
5022
|
if (meta?.kind === "richElement" && meta.element && typeof meta.element === "object") {
|
|
4385
|
-
const restored =
|
|
5023
|
+
const restored = Tools4.deepClone(meta.element);
|
|
4386
5024
|
restored.x = box.x;
|
|
4387
5025
|
restored.y = box.y;
|
|
4388
5026
|
restored.width = box.width;
|
|
4389
5027
|
restored.height = box.height;
|
|
5028
|
+
if (parsedMorphName) restored.morphName = parsedMorphName;
|
|
5029
|
+
if (parsedAction) restored.action = parsedAction;
|
|
4390
5030
|
elements[restored.id] = restored;
|
|
4391
5031
|
elementOrder.push(restored.id);
|
|
4392
5032
|
if (spIdNum) spIdToElId.set(spIdNum, restored.id);
|
|
@@ -4407,9 +5047,10 @@ function importPptxBytesSync(pptxBytes, options) {
|
|
|
4407
5047
|
const lnW = /<a:ln\b[^>]*w="(\d+)"/.exec(lnBlock);
|
|
4408
5048
|
const bodyAnchor = /<a:bodyPr\b[^>]*anchor="([^"]+)"/.exec(txBodyBlock)?.[1];
|
|
4409
5049
|
const textEl = syncTextAndParagraphs({
|
|
5050
|
+
...baseActionAndMorph,
|
|
4410
5051
|
id: elId,
|
|
4411
5052
|
type: "text",
|
|
4412
|
-
name:
|
|
5053
|
+
name: resolvedDisplayName || "\u6587\u672C\u6846",
|
|
4413
5054
|
x: box.x,
|
|
4414
5055
|
y: box.y,
|
|
4415
5056
|
width: box.width,
|
|
@@ -4446,9 +5087,10 @@ function importPptxBytesSync(pptxBytes, options) {
|
|
|
4446
5087
|
const lnW = /<a:ln\b[^>]*w="(\d+)"/.exec(lnBlock);
|
|
4447
5088
|
const strokeWidth = /<a:noFill\b/.test(lnBlock) ? 0 : lnW ? emuToPt(Number(lnW[1])) : 1;
|
|
4448
5089
|
const shapeEl = {
|
|
5090
|
+
...baseActionAndMorph,
|
|
4449
5091
|
id: elId,
|
|
4450
5092
|
type: "shape",
|
|
4451
|
-
name:
|
|
5093
|
+
name: resolvedDisplayName || "\u5F62\u72B6",
|
|
4452
5094
|
shapeType: OOXML_PRST_TO_SHAPE[prstName] ?? "rect",
|
|
4453
5095
|
x: box.x,
|
|
4454
5096
|
y: box.y,
|
|
@@ -4484,9 +5126,10 @@ function importPptxBytesSync(pptxBytes, options) {
|
|
|
4484
5126
|
const stSpId = Number(/<a:stCxn\s+id="(\d+)"/.exec(item.xml)?.[1] ?? 0);
|
|
4485
5127
|
const endSpId = Number(/<a:endCxn\s+id="(\d+)"/.exec(item.xml)?.[1] ?? 0);
|
|
4486
5128
|
const connEl = {
|
|
5129
|
+
...baseActionAndMorph,
|
|
4487
5130
|
id: elId,
|
|
4488
5131
|
type: "connector",
|
|
4489
|
-
name:
|
|
5132
|
+
name: resolvedDisplayName || "\u8FDE\u63A5\u7EBF",
|
|
4490
5133
|
connectorType,
|
|
4491
5134
|
x: box.x,
|
|
4492
5135
|
y: box.y,
|
|
@@ -4516,9 +5159,10 @@ function importPptxBytesSync(pptxBytes, options) {
|
|
|
4516
5159
|
const rEmbed = /r:embed="([^"]+)"/.exec(item.xml)?.[1];
|
|
4517
5160
|
const media = readMediaAsDataUrl(rEmbed);
|
|
4518
5161
|
const imgEl = {
|
|
5162
|
+
...baseActionAndMorph,
|
|
4519
5163
|
id: elId,
|
|
4520
5164
|
type: meta?.kind === "svg" || media?.isSvg ? "svg" : "image",
|
|
4521
|
-
name:
|
|
5165
|
+
name: resolvedDisplayName || "\u56FE\u7247",
|
|
4522
5166
|
x: box.x,
|
|
4523
5167
|
y: box.y,
|
|
4524
5168
|
width: box.width,
|
|
@@ -4572,9 +5216,10 @@ function importPptxBytesSync(pptxBytes, options) {
|
|
|
4572
5216
|
const rows = cells.length;
|
|
4573
5217
|
const cols = Math.max(colWidths.length, cells[0]?.length ?? 1);
|
|
4574
5218
|
const tblEl = {
|
|
5219
|
+
...baseActionAndMorph,
|
|
4575
5220
|
id: elId,
|
|
4576
5221
|
type: "table",
|
|
4577
|
-
name:
|
|
5222
|
+
name: resolvedDisplayName || "\u8868\u683C",
|
|
4578
5223
|
x: box.x,
|
|
4579
5224
|
y: box.y,
|
|
4580
5225
|
width: box.width,
|
|
@@ -4600,12 +5245,22 @@ function importPptxBytesSync(pptxBytes, options) {
|
|
|
4600
5245
|
const chartPath = cRel ? resolveZipRelativePath(slideDir, cRel.target) : "";
|
|
4601
5246
|
const chartXml = chartPath ? readText(chartPath) : void 0;
|
|
4602
5247
|
if (chartXml) {
|
|
4603
|
-
const chartEl =
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
5248
|
+
const chartEl = {
|
|
5249
|
+
...parseChartXmlToElement(
|
|
5250
|
+
chartXml,
|
|
5251
|
+
{
|
|
5252
|
+
id: elId,
|
|
5253
|
+
name: resolvedDisplayName,
|
|
5254
|
+
x: box.x,
|
|
5255
|
+
y: box.y,
|
|
5256
|
+
width: box.width,
|
|
5257
|
+
height: box.height
|
|
5258
|
+
},
|
|
5259
|
+
schemeMap,
|
|
5260
|
+
meta
|
|
5261
|
+
),
|
|
5262
|
+
...baseActionAndMorph
|
|
5263
|
+
};
|
|
4609
5264
|
elements[chartEl.id] = chartEl;
|
|
4610
5265
|
elementOrder.push(chartEl.id);
|
|
4611
5266
|
if (spIdNum) spIdToElId.set(spIdNum, chartEl.id);
|
|
@@ -4638,7 +5293,12 @@ function importPptxBytesSync(pptxBytes, options) {
|
|
|
4638
5293
|
break;
|
|
4639
5294
|
}
|
|
4640
5295
|
}
|
|
4641
|
-
const
|
|
5296
|
+
const xmlTransition = parseTransitionFromSlideXml(slideXml);
|
|
5297
|
+
const metaTransition = slideMeta?.transition;
|
|
5298
|
+
const parsedTransition = xmlTransition ? {
|
|
5299
|
+
...xmlTransition,
|
|
5300
|
+
...metaTransition?.durationMs ? { durationMs: metaTransition.durationMs } : {}
|
|
5301
|
+
} : metaTransition;
|
|
4642
5302
|
const parsedAnimations = Array.isArray(slideMeta?.animations) ? slideMeta.animations : parseTimingAnimationsFromSlideXml(slideXml, spIdToElId);
|
|
4643
5303
|
slides[slideId] = {
|
|
4644
5304
|
id: slideId,
|
|
@@ -4673,8 +5333,16 @@ function importPptxBytesSync(pptxBytes, options) {
|
|
|
4673
5333
|
});
|
|
4674
5334
|
}
|
|
4675
5335
|
}
|
|
4676
|
-
const
|
|
4677
|
-
const
|
|
5336
|
+
const masterXml = readText("ppt/slideMasters/slideMaster1.xml") ?? "";
|
|
5337
|
+
const masterNvGrp = /<p:nvGrpSpPr>[\s\S]*?<p:cNvPr\b([^>]*)\/?>/.exec(masterXml);
|
|
5338
|
+
const masterMeta = decodeElementMetaDescr(
|
|
5339
|
+
masterNvGrp ? getAttr(masterNvGrp[1], "descr") : void 0
|
|
5340
|
+
);
|
|
5341
|
+
const presPropsXml = readText("ppt/presProps.xml") ?? "";
|
|
5342
|
+
const hasLoopFlag = /<p:showPr\b[^>]*loop="1"/.test(presPropsXml);
|
|
5343
|
+
const masters = Array.isArray(masterMeta?.masters) && masterMeta.masters.length > 0 ? masterMeta.masters : createDefaultSlideMasters(theme);
|
|
5344
|
+
const layouts = Array.isArray(masterMeta?.layouts) && masterMeta.layouts.length > 0 ? masterMeta.layouts : createDefaultSlideLayouts(masters[0].id);
|
|
5345
|
+
const slideshowSettings = masterMeta?.slideshowSettings && typeof masterMeta.slideshowSettings === "object" ? masterMeta.slideshowSettings : hasLoopFlag ? { loopContinuously: true } : void 0;
|
|
4678
5346
|
return createDefaultSlideUnitData({
|
|
4679
5347
|
id: options?.unitId || `slide-pptx-${generateRandomId3(6)}`,
|
|
4680
5348
|
name: deckName,
|
|
@@ -4685,7 +5353,8 @@ function importPptxBytesSync(pptxBytes, options) {
|
|
|
4685
5353
|
layouts,
|
|
4686
5354
|
...sections.length > 0 ? { sections } : {},
|
|
4687
5355
|
slideOrder,
|
|
4688
|
-
slides
|
|
5356
|
+
slides,
|
|
5357
|
+
...slideshowSettings ? { slideshowSettings } : {}
|
|
4689
5358
|
});
|
|
4690
5359
|
}
|
|
4691
5360
|
async function importPptxBytes(source, options) {
|
|
@@ -4703,7 +5372,7 @@ async function importPptxBytes(source, options) {
|
|
|
4703
5372
|
}
|
|
4704
5373
|
|
|
4705
5374
|
// src/exporter/slide-pdf-exporter.ts
|
|
4706
|
-
import { Tools as
|
|
5375
|
+
import { Tools as Tools5 } from "@univerjs/core";
|
|
4707
5376
|
import {
|
|
4708
5377
|
beginText,
|
|
4709
5378
|
closePath,
|
|
@@ -5126,12 +5795,312 @@ function renderSmartArtOntoPdf(page, ctx, smartArt, theme, tf) {
|
|
|
5126
5795
|
}
|
|
5127
5796
|
});
|
|
5128
5797
|
}
|
|
5798
|
+
async function renderSingleElementOntoPdf(page, ctx, el, elementsMap, theme, tf) {
|
|
5799
|
+
if (!el || el.hidden) return;
|
|
5800
|
+
const m = createCoordinateMapper(tf);
|
|
5801
|
+
if (el.type === "shape") {
|
|
5802
|
+
const fillCol = parseColorRgb(el.gradientFrom || el.fillColor, parseColorRgb(theme.colors.accent1));
|
|
5803
|
+
const strokeCol = el.strokeWidth > 0 ? parseColorRgb(el.strokeColor) : null;
|
|
5804
|
+
if (el.shapeType === "ellipse") {
|
|
5805
|
+
page.drawEllipse({
|
|
5806
|
+
x: m.x(el.x + el.width / 2),
|
|
5807
|
+
y: m.y(el.y + el.height / 2),
|
|
5808
|
+
xScale: m.len(el.width / 2),
|
|
5809
|
+
yScale: m.len(el.height / 2),
|
|
5810
|
+
color: rgb(fillCol.r, fillCol.g, fillCol.b),
|
|
5811
|
+
...strokeCol ? { borderColor: rgb(strokeCol.r, strokeCol.g, strokeCol.b), borderWidth: m.len(el.strokeWidth) } : {}
|
|
5812
|
+
});
|
|
5813
|
+
} else if (el.shapeType === "rect" || el.shapeType === "roundRect") {
|
|
5814
|
+
page.drawRectangle({
|
|
5815
|
+
x: m.x(el.x),
|
|
5816
|
+
y: m.rectY(el.y, el.height),
|
|
5817
|
+
width: m.len(el.width),
|
|
5818
|
+
height: m.len(el.height),
|
|
5819
|
+
color: rgb(fillCol.r, fillCol.g, fillCol.b),
|
|
5820
|
+
...strokeCol ? { borderColor: rgb(strokeCol.r, strokeCol.g, strokeCol.b), borderWidth: m.len(el.strokeWidth) } : {}
|
|
5821
|
+
});
|
|
5822
|
+
} else {
|
|
5823
|
+
const localPts = getShapePolygonPoints(el.shapeType, el.width, el.height);
|
|
5824
|
+
const pdfPts = localPts.map((p) => ({ x: m.x(el.x + p.x), y: m.y(el.y + p.y) }));
|
|
5825
|
+
drawPolygonPdf(page, pdfPts, fillCol, strokeCol, m.len(el.strokeWidth));
|
|
5826
|
+
}
|
|
5827
|
+
if (el.text) {
|
|
5828
|
+
const lines = el.text.split("\n");
|
|
5829
|
+
const fs = el.fontSize ?? 15;
|
|
5830
|
+
const totalTextH = lines.length * fs * 1.25;
|
|
5831
|
+
const startY = el.y + (el.height - totalTextH) / 2 + fs * 0.9;
|
|
5832
|
+
const tCol = parseColorRgb(el.textColor, { r: 1, g: 1, b: 1 });
|
|
5833
|
+
lines.forEach((ln, idx) => {
|
|
5834
|
+
drawSafeTextLine(
|
|
5835
|
+
page,
|
|
5836
|
+
ctx,
|
|
5837
|
+
ln,
|
|
5838
|
+
m.x(el.x + el.width / 2),
|
|
5839
|
+
m.y(startY + idx * fs * 1.25),
|
|
5840
|
+
m.len(fs),
|
|
5841
|
+
tCol,
|
|
5842
|
+
el.fontWeight === "bold",
|
|
5843
|
+
"center"
|
|
5844
|
+
);
|
|
5845
|
+
});
|
|
5846
|
+
}
|
|
5847
|
+
} else if (el.type === "connector") {
|
|
5848
|
+
const geom = resolveConnectorEndpoints(el, elementsMap);
|
|
5849
|
+
const sCol = parseColorRgb(el.strokeColor, parseColorRgb(theme.colors.accent1));
|
|
5850
|
+
const thick = Math.max(0.8, m.len(el.strokeWidth || 2));
|
|
5851
|
+
if (el.connectorType === "elbow") {
|
|
5852
|
+
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: rgb(sCol.r, sCol.g, sCol.b) });
|
|
5853
|
+
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: rgb(sCol.r, sCol.g, sCol.b) });
|
|
5854
|
+
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: rgb(sCol.r, sCol.g, sCol.b) });
|
|
5855
|
+
} else {
|
|
5856
|
+
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: rgb(sCol.r, sCol.g, sCol.b) });
|
|
5857
|
+
}
|
|
5858
|
+
if (el.endArrow) {
|
|
5859
|
+
const aLen = 7;
|
|
5860
|
+
const a1 = geom.endAngleRad + Math.PI * 0.82;
|
|
5861
|
+
const a2 = geom.endAngleRad - Math.PI * 0.82;
|
|
5862
|
+
drawPolygonPdf(
|
|
5863
|
+
page,
|
|
5864
|
+
[
|
|
5865
|
+
{ x: m.x(geom.x2), y: m.y(geom.y2) },
|
|
5866
|
+
{ x: m.x(geom.x2 + aLen * Math.cos(a1)), y: m.y(geom.y2 + aLen * Math.sin(a1)) },
|
|
5867
|
+
{ x: m.x(geom.x2 + aLen * Math.cos(a2)), y: m.y(geom.y2 + aLen * Math.sin(a2)) }
|
|
5868
|
+
],
|
|
5869
|
+
sCol,
|
|
5870
|
+
null,
|
|
5871
|
+
0
|
|
5872
|
+
);
|
|
5873
|
+
}
|
|
5874
|
+
if (el.label) {
|
|
5875
|
+
drawSafeTextLine(
|
|
5876
|
+
page,
|
|
5877
|
+
ctx,
|
|
5878
|
+
el.label,
|
|
5879
|
+
m.x(geom.midX),
|
|
5880
|
+
m.y(geom.midY - 5),
|
|
5881
|
+
m.len(10),
|
|
5882
|
+
parseColorRgb(el.labelColor || el.strokeColor),
|
|
5883
|
+
false,
|
|
5884
|
+
"center"
|
|
5885
|
+
);
|
|
5886
|
+
}
|
|
5887
|
+
} else if (el.type === "text") {
|
|
5888
|
+
if (el.fillColor) {
|
|
5889
|
+
const fCol = parseColorRgb(el.fillColor, { r: 1, g: 1, b: 1 });
|
|
5890
|
+
page.drawRectangle({
|
|
5891
|
+
x: m.x(el.x),
|
|
5892
|
+
y: m.rectY(el.y, el.height),
|
|
5893
|
+
width: m.len(el.width),
|
|
5894
|
+
height: m.len(el.height),
|
|
5895
|
+
color: rgb(fCol.r, fCol.g, fCol.b),
|
|
5896
|
+
...el.strokeColor && (el.strokeWidth ?? 0) > 0 ? {
|
|
5897
|
+
borderColor: rgb(
|
|
5898
|
+
parseColorRgb(el.strokeColor).r,
|
|
5899
|
+
parseColorRgb(el.strokeColor).g,
|
|
5900
|
+
parseColorRgb(el.strokeColor).b
|
|
5901
|
+
),
|
|
5902
|
+
borderWidth: m.len(el.strokeWidth ?? 1)
|
|
5903
|
+
} : {}
|
|
5904
|
+
});
|
|
5905
|
+
}
|
|
5906
|
+
const fs = el.fontSize ?? 18;
|
|
5907
|
+
const lh = fs * (el.lineHeight ?? 1.35);
|
|
5908
|
+
const lines = (el.text || "").split("\n");
|
|
5909
|
+
const pad = el.paddingPt ?? 6;
|
|
5910
|
+
const totalH = lines.length * lh;
|
|
5911
|
+
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;
|
|
5912
|
+
const textCol = parseColorRgb(
|
|
5913
|
+
el.wordArt?.enabled ? el.wordArt.gradientFrom : el.color || theme.colors.text
|
|
5914
|
+
);
|
|
5915
|
+
const align = el.align === "center" ? "center" : el.align === "right" ? "right" : "left";
|
|
5916
|
+
const anchorX = align === "center" ? el.x + el.width / 2 : align === "right" ? el.x + el.width - pad : el.x + pad;
|
|
5917
|
+
const isBold = el.fontWeight === "bold" || typeof el.fontWeight === "number" && el.fontWeight >= 600;
|
|
5918
|
+
lines.forEach((line, idx) => {
|
|
5919
|
+
const prefix = el.bullet ? el.bullet === "number" ? `${idx + 1}. ` : "\u2022 " : "";
|
|
5920
|
+
drawSafeTextLine(
|
|
5921
|
+
page,
|
|
5922
|
+
ctx,
|
|
5923
|
+
prefix + line,
|
|
5924
|
+
m.x(anchorX),
|
|
5925
|
+
m.y(startSy + idx * lh),
|
|
5926
|
+
m.len(fs),
|
|
5927
|
+
textCol,
|
|
5928
|
+
isBold,
|
|
5929
|
+
align
|
|
5930
|
+
);
|
|
5931
|
+
});
|
|
5932
|
+
} else if (el.type === "table") {
|
|
5933
|
+
const borderCol = parseColorRgb(el.borderColor || "#cbd5e1");
|
|
5934
|
+
let curY = el.y;
|
|
5935
|
+
for (let r = 0; r < el.rows; r++) {
|
|
5936
|
+
const rh = el.rowHeights[r] ?? el.height / Math.max(1, el.rows);
|
|
5937
|
+
let curX = el.x;
|
|
5938
|
+
const isHeader = el.headerRow !== false && r === 0;
|
|
5939
|
+
for (let c = 0; c < el.cols; c++) {
|
|
5940
|
+
const cw = el.colWidths[c] ?? el.width / Math.max(1, el.cols);
|
|
5941
|
+
const cell = el.cells[r]?.[c];
|
|
5942
|
+
if (!cell?.mergedInto) {
|
|
5943
|
+
const bgCol = parseColorRgb(
|
|
5944
|
+
cell?.bg || (isHeader ? el.headerBg || theme.colors.primary : r % 2 === 1 ? el.zebraBg || "#f8fafc" : "#ffffff")
|
|
5945
|
+
);
|
|
5946
|
+
const fgCol = parseColorRgb(
|
|
5947
|
+
cell?.color || (isHeader ? el.headerColor || "#ffffff" : theme.colors.text)
|
|
5948
|
+
);
|
|
5949
|
+
page.drawRectangle({
|
|
5950
|
+
x: m.x(curX),
|
|
5951
|
+
y: m.rectY(curY, rh),
|
|
5952
|
+
width: m.len(cw),
|
|
5953
|
+
height: m.len(rh),
|
|
5954
|
+
color: rgb(bgCol.r, bgCol.g, bgCol.b),
|
|
5955
|
+
borderColor: rgb(borderCol.r, borderCol.g, borderCol.b),
|
|
5956
|
+
borderWidth: Math.max(0.4, m.len(0.75))
|
|
5957
|
+
});
|
|
5958
|
+
if (cell?.text) {
|
|
5959
|
+
const cellAlign = cell.align ?? "left";
|
|
5960
|
+
const tx = cellAlign === "center" ? curX + cw / 2 : cellAlign === "right" ? curX + cw - 8 : curX + 8;
|
|
5961
|
+
const cfs = cell.fontSize ?? 11;
|
|
5962
|
+
drawSafeTextLine(
|
|
5963
|
+
page,
|
|
5964
|
+
ctx,
|
|
5965
|
+
cell.text,
|
|
5966
|
+
m.x(tx),
|
|
5967
|
+
m.y(curY + rh / 2 + cfs * 0.35),
|
|
5968
|
+
m.len(cfs),
|
|
5969
|
+
fgCol,
|
|
5970
|
+
Boolean(cell.bold || isHeader),
|
|
5971
|
+
cellAlign
|
|
5972
|
+
);
|
|
5973
|
+
}
|
|
5974
|
+
}
|
|
5975
|
+
curX += cw;
|
|
5976
|
+
}
|
|
5977
|
+
curY += rh;
|
|
5978
|
+
}
|
|
5979
|
+
} else if (el.type === "chart") {
|
|
5980
|
+
renderVectorChartOntoPdf(page, ctx, el, theme, tf);
|
|
5981
|
+
} else if (el.type === "smartArt") {
|
|
5982
|
+
renderSmartArtOntoPdf(page, ctx, el, theme, tf);
|
|
5983
|
+
} else if (el.type === "image" && el.src.startsWith("data:image/")) {
|
|
5984
|
+
try {
|
|
5985
|
+
const comma = el.src.indexOf(",");
|
|
5986
|
+
const header = el.src.slice(0, comma);
|
|
5987
|
+
const b64 = el.src.slice(comma + 1);
|
|
5988
|
+
const bytes = typeof Buffer !== "undefined" ? new Uint8Array(Buffer.from(b64, "base64")) : Uint8Array.from(atob(b64), (ch) => ch.charCodeAt(0));
|
|
5989
|
+
if (header.includes("png")) {
|
|
5990
|
+
const img = await ctx.pdfDoc.embedPng(bytes);
|
|
5991
|
+
page.drawImage(img, {
|
|
5992
|
+
x: m.x(el.x),
|
|
5993
|
+
y: m.rectY(el.y, el.height),
|
|
5994
|
+
width: m.len(el.width),
|
|
5995
|
+
height: m.len(el.height)
|
|
5996
|
+
});
|
|
5997
|
+
} else if (header.includes("jpeg") || header.includes("jpg")) {
|
|
5998
|
+
const img = await ctx.pdfDoc.embedJpg(bytes);
|
|
5999
|
+
page.drawImage(img, {
|
|
6000
|
+
x: m.x(el.x),
|
|
6001
|
+
y: m.rectY(el.y, el.height),
|
|
6002
|
+
width: m.len(el.width),
|
|
6003
|
+
height: m.len(el.height)
|
|
6004
|
+
});
|
|
6005
|
+
}
|
|
6006
|
+
} catch {
|
|
6007
|
+
}
|
|
6008
|
+
} else if (el.type === "codeBlock") {
|
|
6009
|
+
page.drawRectangle({
|
|
6010
|
+
x: m.x(el.x),
|
|
6011
|
+
y: m.rectY(el.y, el.height),
|
|
6012
|
+
width: m.len(el.width),
|
|
6013
|
+
height: m.len(el.height),
|
|
6014
|
+
color: rgb(0.06, 0.09, 0.16)
|
|
6015
|
+
});
|
|
6016
|
+
el.code.split("\n").slice(0, 12).forEach((ln, idx) => {
|
|
6017
|
+
drawSafeTextLine(
|
|
6018
|
+
page,
|
|
6019
|
+
ctx,
|
|
6020
|
+
ln,
|
|
6021
|
+
m.x(el.x + 12),
|
|
6022
|
+
m.y(el.y + 24 + idx * 15),
|
|
6023
|
+
m.len(el.fontSize ?? 11),
|
|
6024
|
+
{ r: 0.89, g: 0.91, b: 0.94 },
|
|
6025
|
+
false,
|
|
6026
|
+
"left"
|
|
6027
|
+
);
|
|
6028
|
+
});
|
|
6029
|
+
} else if (el.type === "sheetEmbed") {
|
|
6030
|
+
page.drawRectangle({
|
|
6031
|
+
x: m.x(el.x),
|
|
6032
|
+
y: m.rectY(el.y, el.height),
|
|
6033
|
+
width: m.len(el.width),
|
|
6034
|
+
height: m.len(el.height),
|
|
6035
|
+
color: rgb(1, 1, 1),
|
|
6036
|
+
borderColor: rgb(0.06, 0.72, 0.5),
|
|
6037
|
+
borderWidth: m.len(1)
|
|
6038
|
+
});
|
|
6039
|
+
if (el.title) {
|
|
6040
|
+
drawSafeTextLine(
|
|
6041
|
+
page,
|
|
6042
|
+
ctx,
|
|
6043
|
+
el.title,
|
|
6044
|
+
m.x(el.x + 10),
|
|
6045
|
+
m.y(el.y + 18),
|
|
6046
|
+
m.len(12),
|
|
6047
|
+
parseColorRgb(el.accentColor || "#059669"),
|
|
6048
|
+
true,
|
|
6049
|
+
"left"
|
|
6050
|
+
);
|
|
6051
|
+
}
|
|
6052
|
+
} else if (el.type === "video" || el.type === "audio") {
|
|
6053
|
+
const accentCol = parseColorRgb(theme.colors.accent1);
|
|
6054
|
+
page.drawRectangle({
|
|
6055
|
+
x: m.x(el.x),
|
|
6056
|
+
y: m.rectY(el.y, el.height),
|
|
6057
|
+
width: m.len(el.width),
|
|
6058
|
+
height: m.len(el.height),
|
|
6059
|
+
color: el.type === "video" ? rgb(0.06, 0.09, 0.16) : rgb(0.12, 0.16, 0.23),
|
|
6060
|
+
borderColor: rgb(0.28, 0.33, 0.41),
|
|
6061
|
+
borderWidth: Math.max(0.6, m.len(1))
|
|
6062
|
+
});
|
|
6063
|
+
const cx = el.type === "video" ? el.x + el.width / 2 : el.x + 28;
|
|
6064
|
+
const cy = el.y + el.height / 2;
|
|
6065
|
+
const r = el.type === "video" ? Math.min(20, Math.min(el.width, el.height) * 0.15) : 13;
|
|
6066
|
+
page.drawCircle({
|
|
6067
|
+
x: m.x(cx),
|
|
6068
|
+
y: m.y(cy),
|
|
6069
|
+
size: m.len(r),
|
|
6070
|
+
color: rgb(accentCol.r, accentCol.g, accentCol.b)
|
|
6071
|
+
});
|
|
6072
|
+
drawPolygonPdf(
|
|
6073
|
+
page,
|
|
6074
|
+
[
|
|
6075
|
+
{ x: m.x(cx - r * 0.3), y: m.y(cy - r * 0.42) },
|
|
6076
|
+
{ x: m.x(cx - r * 0.3), y: m.y(cy + r * 0.42) },
|
|
6077
|
+
{ x: m.x(cx + r * 0.46), y: m.y(cy) }
|
|
6078
|
+
],
|
|
6079
|
+
{ r: 1, g: 1, b: 1 },
|
|
6080
|
+
null,
|
|
6081
|
+
0
|
|
6082
|
+
);
|
|
6083
|
+
drawSafeTextLine(
|
|
6084
|
+
page,
|
|
6085
|
+
ctx,
|
|
6086
|
+
el.name || (el.type === "video" ? "\u89C6\u9891\u5A92\u4F53 (VIDEO)" : "\u97F3\u9891\u5A92\u4F53 (AUDIO)"),
|
|
6087
|
+
m.x(el.type === "video" ? el.x + 12 : cx + r + 10),
|
|
6088
|
+
m.y(el.type === "video" ? el.y + el.height - 10 : cy + 4),
|
|
6089
|
+
m.len(10.5),
|
|
6090
|
+
{ r: 0.92, g: 0.95, b: 0.98 },
|
|
6091
|
+
true,
|
|
6092
|
+
"left"
|
|
6093
|
+
);
|
|
6094
|
+
}
|
|
6095
|
+
}
|
|
5129
6096
|
async function renderSlideOntoPdfFrame(page, ctx, slide, snapshot, slideIndexOneBased, tf) {
|
|
5130
6097
|
const m = createCoordinateMapper(tf);
|
|
5131
6098
|
const slideW = snapshot.slideSize.widthPt || 960;
|
|
5132
6099
|
const slideH = snapshot.slideSize.heightPt || 540;
|
|
5133
6100
|
const theme = snapshot.theme ?? SLIDE_THEME_PRESETS[0];
|
|
5134
|
-
const
|
|
6101
|
+
const matchedLayout = snapshot.layouts?.find((l) => l.id === slide.layoutId);
|
|
6102
|
+
const master = (matchedLayout ? snapshot.masters.find((ms) => ms.id === matchedLayout.masterId) : void 0) ?? snapshot.masters[0];
|
|
6103
|
+
const bg = slide.background ?? matchedLayout?.background ?? master?.background ?? { type: "solid", color: theme.colors.background };
|
|
5135
6104
|
if (bg.type === "gradient" && bg.gradientFrom && bg.gradientTo) {
|
|
5136
6105
|
const c1 = parseColorRgb(bg.gradientFrom);
|
|
5137
6106
|
const c2 = parseColorRgb(bg.gradientTo);
|
|
@@ -5157,7 +6126,7 @@ async function renderSlideOntoPdfFrame(page, ctx, slide, snapshot, slideIndexOne
|
|
|
5157
6126
|
color: rgb(bgCol.r, bgCol.g, bgCol.b)
|
|
5158
6127
|
});
|
|
5159
6128
|
}
|
|
5160
|
-
if (
|
|
6129
|
+
if (master?.accentBar) {
|
|
5161
6130
|
const pCol = parseColorRgb(theme.colors.primary);
|
|
5162
6131
|
page.drawRectangle({
|
|
5163
6132
|
x: m.x(0),
|
|
@@ -5167,261 +6136,41 @@ async function renderSlideOntoPdfFrame(page, ctx, slide, snapshot, slideIndexOne
|
|
|
5167
6136
|
color: rgb(pCol.r, pCol.g, pCol.b)
|
|
5168
6137
|
});
|
|
5169
6138
|
}
|
|
6139
|
+
if (master?.masterElements && master.masterElements.length > 0) {
|
|
6140
|
+
const masterMap = {};
|
|
6141
|
+
for (const mEl of master.masterElements) {
|
|
6142
|
+
if (mEl) masterMap[mEl.id] = mEl;
|
|
6143
|
+
}
|
|
6144
|
+
for (const mEl of master.masterElements) {
|
|
6145
|
+
await renderSingleElementOntoPdf(page, ctx, mEl, masterMap, theme, tf);
|
|
6146
|
+
}
|
|
6147
|
+
}
|
|
6148
|
+
if (matchedLayout?.layoutElements && matchedLayout.layoutElements.length > 0) {
|
|
6149
|
+
const layoutMap = {};
|
|
6150
|
+
for (const lEl of matchedLayout.layoutElements) {
|
|
6151
|
+
if (lEl) layoutMap[lEl.id] = lEl;
|
|
6152
|
+
}
|
|
6153
|
+
for (const lEl of matchedLayout.layoutElements) {
|
|
6154
|
+
await renderSingleElementOntoPdf(page, ctx, lEl, layoutMap, theme, tf);
|
|
6155
|
+
}
|
|
6156
|
+
}
|
|
5170
6157
|
for (const elId of slide.elementOrder) {
|
|
5171
6158
|
const el = slide.elements[elId];
|
|
5172
6159
|
if (!el || el.hidden) continue;
|
|
5173
|
-
|
|
5174
|
-
|
|
5175
|
-
|
|
5176
|
-
|
|
5177
|
-
|
|
5178
|
-
|
|
5179
|
-
|
|
5180
|
-
|
|
5181
|
-
|
|
5182
|
-
|
|
5183
|
-
|
|
5184
|
-
|
|
5185
|
-
|
|
5186
|
-
|
|
5187
|
-
x: m.x(el.x),
|
|
5188
|
-
y: m.rectY(el.y, el.height),
|
|
5189
|
-
width: m.len(el.width),
|
|
5190
|
-
height: m.len(el.height),
|
|
5191
|
-
color: rgb(fillCol.r, fillCol.g, fillCol.b),
|
|
5192
|
-
...strokeCol ? { borderColor: rgb(strokeCol.r, strokeCol.g, strokeCol.b), borderWidth: m.len(el.strokeWidth) } : {}
|
|
5193
|
-
});
|
|
5194
|
-
} else {
|
|
5195
|
-
const localPts = getShapePolygonPoints(el.shapeType, el.width, el.height);
|
|
5196
|
-
const pdfPts = localPts.map((p) => ({ x: m.x(el.x + p.x), y: m.y(el.y + p.y) }));
|
|
5197
|
-
drawPolygonPdf(page, pdfPts, fillCol, strokeCol, m.len(el.strokeWidth));
|
|
5198
|
-
}
|
|
5199
|
-
if (el.text) {
|
|
5200
|
-
const lines = el.text.split("\n");
|
|
5201
|
-
const fs = el.fontSize ?? 15;
|
|
5202
|
-
const totalTextH = lines.length * fs * 1.25;
|
|
5203
|
-
const startY = el.y + (el.height - totalTextH) / 2 + fs * 0.9;
|
|
5204
|
-
const tCol = parseColorRgb(el.textColor, { r: 1, g: 1, b: 1 });
|
|
5205
|
-
lines.forEach((ln, idx) => {
|
|
5206
|
-
drawSafeTextLine(
|
|
5207
|
-
page,
|
|
5208
|
-
ctx,
|
|
5209
|
-
ln,
|
|
5210
|
-
m.x(el.x + el.width / 2),
|
|
5211
|
-
m.y(startY + idx * fs * 1.25),
|
|
5212
|
-
m.len(fs),
|
|
5213
|
-
tCol,
|
|
5214
|
-
el.fontWeight === "bold",
|
|
5215
|
-
"center"
|
|
5216
|
-
);
|
|
5217
|
-
});
|
|
5218
|
-
}
|
|
5219
|
-
} else if (el.type === "connector") {
|
|
5220
|
-
const geom = resolveConnectorEndpoints(el, slide.elements);
|
|
5221
|
-
const sCol = parseColorRgb(el.strokeColor, parseColorRgb(theme.colors.accent1));
|
|
5222
|
-
const thick = Math.max(0.8, m.len(el.strokeWidth || 2));
|
|
5223
|
-
if (el.connectorType === "elbow") {
|
|
5224
|
-
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: rgb(sCol.r, sCol.g, sCol.b) });
|
|
5225
|
-
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: rgb(sCol.r, sCol.g, sCol.b) });
|
|
5226
|
-
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: rgb(sCol.r, sCol.g, sCol.b) });
|
|
5227
|
-
} else {
|
|
5228
|
-
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: rgb(sCol.r, sCol.g, sCol.b) });
|
|
5229
|
-
}
|
|
5230
|
-
if (el.endArrow) {
|
|
5231
|
-
const aLen = 7;
|
|
5232
|
-
const a1 = geom.endAngleRad + Math.PI * 0.82;
|
|
5233
|
-
const a2 = geom.endAngleRad - Math.PI * 0.82;
|
|
5234
|
-
drawPolygonPdf(
|
|
5235
|
-
page,
|
|
5236
|
-
[
|
|
5237
|
-
{ x: m.x(geom.x2), y: m.y(geom.y2) },
|
|
5238
|
-
{ x: m.x(geom.x2 + aLen * Math.cos(a1)), y: m.y(geom.y2 + aLen * Math.sin(a1)) },
|
|
5239
|
-
{ x: m.x(geom.x2 + aLen * Math.cos(a2)), y: m.y(geom.y2 + aLen * Math.sin(a2)) }
|
|
5240
|
-
],
|
|
5241
|
-
sCol,
|
|
5242
|
-
null,
|
|
5243
|
-
0
|
|
5244
|
-
);
|
|
5245
|
-
}
|
|
5246
|
-
if (el.label) {
|
|
5247
|
-
drawSafeTextLine(
|
|
5248
|
-
page,
|
|
5249
|
-
ctx,
|
|
5250
|
-
el.label,
|
|
5251
|
-
m.x(geom.midX),
|
|
5252
|
-
m.y(geom.midY - 5),
|
|
5253
|
-
m.len(10),
|
|
5254
|
-
parseColorRgb(el.labelColor || el.strokeColor),
|
|
5255
|
-
false,
|
|
5256
|
-
"center"
|
|
5257
|
-
);
|
|
5258
|
-
}
|
|
5259
|
-
} else if (el.type === "text") {
|
|
5260
|
-
if (el.fillColor) {
|
|
5261
|
-
const fCol = parseColorRgb(el.fillColor, { r: 1, g: 1, b: 1 });
|
|
5262
|
-
page.drawRectangle({
|
|
5263
|
-
x: m.x(el.x),
|
|
5264
|
-
y: m.rectY(el.y, el.height),
|
|
5265
|
-
width: m.len(el.width),
|
|
5266
|
-
height: m.len(el.height),
|
|
5267
|
-
color: rgb(fCol.r, fCol.g, fCol.b),
|
|
5268
|
-
...el.strokeColor && (el.strokeWidth ?? 0) > 0 ? {
|
|
5269
|
-
borderColor: rgb(
|
|
5270
|
-
parseColorRgb(el.strokeColor).r,
|
|
5271
|
-
parseColorRgb(el.strokeColor).g,
|
|
5272
|
-
parseColorRgb(el.strokeColor).b
|
|
5273
|
-
),
|
|
5274
|
-
borderWidth: m.len(el.strokeWidth ?? 1)
|
|
5275
|
-
} : {}
|
|
5276
|
-
});
|
|
5277
|
-
}
|
|
5278
|
-
const fs = el.fontSize ?? 18;
|
|
5279
|
-
const lh = fs * (el.lineHeight ?? 1.35);
|
|
5280
|
-
const lines = (el.text || "").split("\n");
|
|
5281
|
-
const pad = el.paddingPt ?? 6;
|
|
5282
|
-
const totalH = lines.length * lh;
|
|
5283
|
-
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;
|
|
5284
|
-
const textCol = parseColorRgb(
|
|
5285
|
-
el.wordArt?.enabled ? el.wordArt.gradientFrom : el.color || theme.colors.text
|
|
5286
|
-
);
|
|
5287
|
-
const align = el.align === "center" ? "center" : el.align === "right" ? "right" : "left";
|
|
5288
|
-
const anchorX = align === "center" ? el.x + el.width / 2 : align === "right" ? el.x + el.width - pad : el.x + pad;
|
|
5289
|
-
const isBold = el.fontWeight === "bold" || typeof el.fontWeight === "number" && el.fontWeight >= 600;
|
|
5290
|
-
lines.forEach((line, idx) => {
|
|
5291
|
-
const prefix = el.bullet ? el.bullet === "number" ? `${idx + 1}. ` : "\u2022 " : "";
|
|
5292
|
-
drawSafeTextLine(
|
|
5293
|
-
page,
|
|
5294
|
-
ctx,
|
|
5295
|
-
prefix + line,
|
|
5296
|
-
m.x(anchorX),
|
|
5297
|
-
m.y(startSy + idx * lh),
|
|
5298
|
-
m.len(fs),
|
|
5299
|
-
textCol,
|
|
5300
|
-
isBold,
|
|
5301
|
-
align
|
|
5302
|
-
);
|
|
5303
|
-
});
|
|
5304
|
-
} else if (el.type === "table") {
|
|
5305
|
-
const borderCol = parseColorRgb(el.borderColor || "#cbd5e1");
|
|
5306
|
-
let curY = el.y;
|
|
5307
|
-
for (let r = 0; r < el.rows; r++) {
|
|
5308
|
-
const rh = el.rowHeights[r] ?? el.height / Math.max(1, el.rows);
|
|
5309
|
-
let curX = el.x;
|
|
5310
|
-
const isHeader = el.headerRow !== false && r === 0;
|
|
5311
|
-
for (let c = 0; c < el.cols; c++) {
|
|
5312
|
-
const cw = el.colWidths[c] ?? el.width / Math.max(1, el.cols);
|
|
5313
|
-
const cell = el.cells[r]?.[c];
|
|
5314
|
-
if (!cell?.mergedInto) {
|
|
5315
|
-
const bgCol = parseColorRgb(
|
|
5316
|
-
cell?.bg || (isHeader ? el.headerBg || theme.colors.primary : r % 2 === 1 ? el.zebraBg || "#f8fafc" : "#ffffff")
|
|
5317
|
-
);
|
|
5318
|
-
const fgCol = parseColorRgb(
|
|
5319
|
-
cell?.color || (isHeader ? el.headerColor || "#ffffff" : theme.colors.text)
|
|
5320
|
-
);
|
|
5321
|
-
page.drawRectangle({
|
|
5322
|
-
x: m.x(curX),
|
|
5323
|
-
y: m.rectY(curY, rh),
|
|
5324
|
-
width: m.len(cw),
|
|
5325
|
-
height: m.len(rh),
|
|
5326
|
-
color: rgb(bgCol.r, bgCol.g, bgCol.b),
|
|
5327
|
-
borderColor: rgb(borderCol.r, borderCol.g, borderCol.b),
|
|
5328
|
-
borderWidth: Math.max(0.4, m.len(0.75))
|
|
5329
|
-
});
|
|
5330
|
-
if (cell?.text) {
|
|
5331
|
-
const cellAlign = cell.align ?? "left";
|
|
5332
|
-
const tx = cellAlign === "center" ? curX + cw / 2 : cellAlign === "right" ? curX + cw - 8 : curX + 8;
|
|
5333
|
-
const cfs = cell.fontSize ?? 11;
|
|
5334
|
-
drawSafeTextLine(
|
|
5335
|
-
page,
|
|
5336
|
-
ctx,
|
|
5337
|
-
cell.text,
|
|
5338
|
-
m.x(tx),
|
|
5339
|
-
m.y(curY + rh / 2 + cfs * 0.35),
|
|
5340
|
-
m.len(cfs),
|
|
5341
|
-
fgCol,
|
|
5342
|
-
Boolean(cell.bold || isHeader),
|
|
5343
|
-
cellAlign
|
|
5344
|
-
);
|
|
5345
|
-
}
|
|
5346
|
-
}
|
|
5347
|
-
curX += cw;
|
|
5348
|
-
}
|
|
5349
|
-
curY += rh;
|
|
5350
|
-
}
|
|
5351
|
-
} else if (el.type === "chart") {
|
|
5352
|
-
renderVectorChartOntoPdf(page, ctx, el, theme, tf);
|
|
5353
|
-
} else if (el.type === "smartArt") {
|
|
5354
|
-
renderSmartArtOntoPdf(page, ctx, el, theme, tf);
|
|
5355
|
-
} else if (el.type === "image" && el.src.startsWith("data:image/")) {
|
|
5356
|
-
try {
|
|
5357
|
-
const comma = el.src.indexOf(",");
|
|
5358
|
-
const header = el.src.slice(0, comma);
|
|
5359
|
-
const b64 = el.src.slice(comma + 1);
|
|
5360
|
-
const bytes = typeof Buffer !== "undefined" ? new Uint8Array(Buffer.from(b64, "base64")) : Uint8Array.from(atob(b64), (ch) => ch.charCodeAt(0));
|
|
5361
|
-
if (header.includes("png")) {
|
|
5362
|
-
const img = await ctx.pdfDoc.embedPng(bytes);
|
|
5363
|
-
page.drawImage(img, {
|
|
5364
|
-
x: m.x(el.x),
|
|
5365
|
-
y: m.rectY(el.y, el.height),
|
|
5366
|
-
width: m.len(el.width),
|
|
5367
|
-
height: m.len(el.height)
|
|
5368
|
-
});
|
|
5369
|
-
} else if (header.includes("jpeg") || header.includes("jpg")) {
|
|
5370
|
-
const img = await ctx.pdfDoc.embedJpg(bytes);
|
|
5371
|
-
page.drawImage(img, {
|
|
5372
|
-
x: m.x(el.x),
|
|
5373
|
-
y: m.rectY(el.y, el.height),
|
|
5374
|
-
width: m.len(el.width),
|
|
5375
|
-
height: m.len(el.height)
|
|
5376
|
-
});
|
|
5377
|
-
}
|
|
5378
|
-
} catch {
|
|
5379
|
-
}
|
|
5380
|
-
} else if (el.type === "codeBlock") {
|
|
5381
|
-
page.drawRectangle({
|
|
5382
|
-
x: m.x(el.x),
|
|
5383
|
-
y: m.rectY(el.y, el.height),
|
|
5384
|
-
width: m.len(el.width),
|
|
5385
|
-
height: m.len(el.height),
|
|
5386
|
-
color: rgb(0.06, 0.09, 0.16)
|
|
5387
|
-
});
|
|
5388
|
-
el.code.split("\n").slice(0, 12).forEach((ln, idx) => {
|
|
5389
|
-
drawSafeTextLine(
|
|
5390
|
-
page,
|
|
5391
|
-
ctx,
|
|
5392
|
-
ln,
|
|
5393
|
-
m.x(el.x + 12),
|
|
5394
|
-
m.y(el.y + 24 + idx * 15),
|
|
5395
|
-
m.len(el.fontSize ?? 11),
|
|
5396
|
-
{ r: 0.89, g: 0.91, b: 0.94 },
|
|
5397
|
-
false,
|
|
5398
|
-
"left"
|
|
5399
|
-
);
|
|
5400
|
-
});
|
|
5401
|
-
} else if (el.type === "sheetEmbed") {
|
|
5402
|
-
page.drawRectangle({
|
|
5403
|
-
x: m.x(el.x),
|
|
5404
|
-
y: m.rectY(el.y, el.height),
|
|
5405
|
-
width: m.len(el.width),
|
|
5406
|
-
height: m.len(el.height),
|
|
5407
|
-
color: rgb(1, 1, 1),
|
|
5408
|
-
borderColor: rgb(0.06, 0.72, 0.5),
|
|
5409
|
-
borderWidth: m.len(1)
|
|
5410
|
-
});
|
|
5411
|
-
if (el.title) {
|
|
5412
|
-
drawSafeTextLine(
|
|
5413
|
-
page,
|
|
5414
|
-
ctx,
|
|
5415
|
-
el.title,
|
|
5416
|
-
m.x(el.x + 10),
|
|
5417
|
-
m.y(el.y + 18),
|
|
5418
|
-
m.len(12),
|
|
5419
|
-
parseColorRgb(el.accentColor || "#059669"),
|
|
5420
|
-
true,
|
|
5421
|
-
"left"
|
|
5422
|
-
);
|
|
5423
|
-
}
|
|
5424
|
-
}
|
|
6160
|
+
await renderSingleElementOntoPdf(page, ctx, el, slide.elements, theme, tf);
|
|
6161
|
+
}
|
|
6162
|
+
if (master?.footerText) {
|
|
6163
|
+
drawSafeTextLine(
|
|
6164
|
+
page,
|
|
6165
|
+
ctx,
|
|
6166
|
+
master.footerText,
|
|
6167
|
+
m.x(18),
|
|
6168
|
+
m.y(slideH - 14),
|
|
6169
|
+
m.len(9.5),
|
|
6170
|
+
{ r: 0.4, g: 0.45, b: 0.53 },
|
|
6171
|
+
false,
|
|
6172
|
+
"left"
|
|
6173
|
+
);
|
|
5425
6174
|
}
|
|
5426
6175
|
if (slide.showSlideNumber !== false) {
|
|
5427
6176
|
drawSafeTextLine(
|
|
@@ -5438,7 +6187,7 @@ async function renderSlideOntoPdfFrame(page, ctx, slide, snapshot, slideIndexOne
|
|
|
5438
6187
|
}
|
|
5439
6188
|
}
|
|
5440
6189
|
async function exportSlidesToPdfBytes(rawSnapshot, options) {
|
|
5441
|
-
const snapshot = options?.datasets ? compileSlidesWithDataset(rawSnapshot, options.datasets, options.templateOptions) :
|
|
6190
|
+
const snapshot = options?.datasets ? compileSlidesWithDataset(rawSnapshot, options.datasets, options.templateOptions) : Tools5.deepClone(rawSnapshot);
|
|
5442
6191
|
const pdfDoc = await PDFDocument.create();
|
|
5443
6192
|
pdfDoc.setTitle(snapshot.name || "Univer Slides Presentation");
|
|
5444
6193
|
pdfDoc.setCreator("Univer Slides (@yudaocode/univer-slides)");
|
|
@@ -5651,7 +6400,7 @@ import {
|
|
|
5651
6400
|
ICommandService,
|
|
5652
6401
|
IUndoRedoService,
|
|
5653
6402
|
IUniverInstanceService as IUniverInstanceService2,
|
|
5654
|
-
Tools as
|
|
6403
|
+
Tools as Tools6,
|
|
5655
6404
|
UniverInstanceType as UniverInstanceType3
|
|
5656
6405
|
} from "@univerjs/core";
|
|
5657
6406
|
function resolveSlideUnit(accessor, explicitUnitId) {
|
|
@@ -5691,10 +6440,17 @@ function createDefaultSlideElement(elementType, partial, theme) {
|
|
|
5691
6440
|
const accent1 = theme?.colors.accent1 ?? "#2563eb";
|
|
5692
6441
|
const accent2 = theme?.colors.accent2 ?? "#0ea5e9";
|
|
5693
6442
|
const textColor = theme?.colors.text ?? "#0f172a";
|
|
6443
|
+
const baseExtras = {
|
|
6444
|
+
...partial?.morphName ? { morphName: partial.morphName } : {},
|
|
6445
|
+
...partial?.action ? { action: Tools6.deepClone(partial.action) } : {},
|
|
6446
|
+
...partial?.locked !== void 0 ? { locked: partial.locked } : {},
|
|
6447
|
+
...partial?.hidden !== void 0 ? { hidden: partial.hidden } : {}
|
|
6448
|
+
};
|
|
5694
6449
|
switch (elementType) {
|
|
5695
6450
|
case "text": {
|
|
5696
6451
|
const p = partial ?? {};
|
|
5697
6452
|
return syncTextAndParagraphs({
|
|
6453
|
+
...baseExtras,
|
|
5698
6454
|
id,
|
|
5699
6455
|
type: "text",
|
|
5700
6456
|
name: p.name ?? "\u6587\u672C\u6846",
|
|
@@ -5705,7 +6461,7 @@ function createDefaultSlideElement(elementType, partial, theme) {
|
|
|
5705
6461
|
rotation: p.rotation ?? 0,
|
|
5706
6462
|
opacity: p.opacity ?? 1,
|
|
5707
6463
|
text: p.text ?? "\u53CC\u51FB\u8F93\u5165\u6F14\u793A\u6587\u672C\u5185\u5BB9",
|
|
5708
|
-
...p.paragraphs ? { paragraphs:
|
|
6464
|
+
...p.paragraphs ? { paragraphs: Tools6.deepClone(p.paragraphs) } : {},
|
|
5709
6465
|
fontFamily: p.fontFamily ?? theme?.minorFont,
|
|
5710
6466
|
fontSize: p.fontSize ?? 20,
|
|
5711
6467
|
fontWeight: p.fontWeight ?? "normal",
|
|
@@ -5721,7 +6477,7 @@ function createDefaultSlideElement(elementType, partial, theme) {
|
|
|
5721
6477
|
...p.strokeWidth !== void 0 ? { strokeWidth: p.strokeWidth } : {},
|
|
5722
6478
|
...p.borderRadius !== void 0 ? { borderRadius: p.borderRadius } : {},
|
|
5723
6479
|
...p.paddingPt !== void 0 ? { paddingPt: p.paddingPt } : {},
|
|
5724
|
-
...p.wordArt ? { wordArt:
|
|
6480
|
+
...p.wordArt ? { wordArt: Tools6.deepClone(p.wordArt) } : {},
|
|
5725
6481
|
...p.placeholderRole ? { placeholderRole: p.placeholderRole } : {},
|
|
5726
6482
|
...p.datasetBinding ? { datasetBinding: p.datasetBinding } : {}
|
|
5727
6483
|
});
|
|
@@ -5729,6 +6485,7 @@ function createDefaultSlideElement(elementType, partial, theme) {
|
|
|
5729
6485
|
case "shape": {
|
|
5730
6486
|
const p = partial ?? {};
|
|
5731
6487
|
return {
|
|
6488
|
+
...baseExtras,
|
|
5732
6489
|
id,
|
|
5733
6490
|
type: "shape",
|
|
5734
6491
|
name: p.name ?? "\u51E0\u4F55\u5F62\u72B6",
|
|
@@ -5760,6 +6517,7 @@ function createDefaultSlideElement(elementType, partial, theme) {
|
|
|
5760
6517
|
const width = p.width ?? 220;
|
|
5761
6518
|
const height = p.height ?? 60;
|
|
5762
6519
|
return {
|
|
6520
|
+
...baseExtras,
|
|
5763
6521
|
id,
|
|
5764
6522
|
type: "connector",
|
|
5765
6523
|
name: p.name ?? "\u8FDE\u63A5\u7EBF",
|
|
@@ -5789,6 +6547,7 @@ function createDefaultSlideElement(elementType, partial, theme) {
|
|
|
5789
6547
|
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>`;
|
|
5790
6548
|
const fallbackSrc = `data:image/svg+xml;utf8,${encodeURIComponent(defaultSvg)}`;
|
|
5791
6549
|
return {
|
|
6550
|
+
...baseExtras,
|
|
5792
6551
|
id,
|
|
5793
6552
|
type: elementType,
|
|
5794
6553
|
name: p.name ?? (elementType === "svg" ? "\u77E2\u91CF\u56FE\u6807" : "\u56FE\u7247"),
|
|
@@ -5814,7 +6573,7 @@ function createDefaultSlideElement(elementType, partial, theme) {
|
|
|
5814
6573
|
const height = p.height ?? 200;
|
|
5815
6574
|
const colWidths = p.colWidths ?? Array.from({ length: cols }, () => Math.round(width / cols));
|
|
5816
6575
|
const rowHeights = p.rowHeights ?? Array.from({ length: rows }, () => Math.round(height / rows));
|
|
5817
|
-
const cells = p.cells ?
|
|
6576
|
+
const cells = p.cells ? Tools6.deepClone(p.cells) : Array.from(
|
|
5818
6577
|
{ length: rows },
|
|
5819
6578
|
(_, r) => Array.from({ length: cols }, (__, c) => ({
|
|
5820
6579
|
text: r === 0 ? `\u5217\u6807\u9898 ${c + 1}` : `\u6570\u636E R${r}C${c + 1}`,
|
|
@@ -5823,6 +6582,7 @@ function createDefaultSlideElement(elementType, partial, theme) {
|
|
|
5823
6582
|
}))
|
|
5824
6583
|
);
|
|
5825
6584
|
return {
|
|
6585
|
+
...baseExtras,
|
|
5826
6586
|
id,
|
|
5827
6587
|
type: "table",
|
|
5828
6588
|
name: p.name ?? "\u6570\u636E\u8868\u683C",
|
|
@@ -5846,6 +6606,7 @@ function createDefaultSlideElement(elementType, partial, theme) {
|
|
|
5846
6606
|
case "chart": {
|
|
5847
6607
|
const p = partial ?? {};
|
|
5848
6608
|
return {
|
|
6609
|
+
...baseExtras,
|
|
5849
6610
|
id,
|
|
5850
6611
|
type: "chart",
|
|
5851
6612
|
name: p.name ?? "\u7EDF\u8BA1\u56FE\u8868",
|
|
@@ -5856,7 +6617,7 @@ function createDefaultSlideElement(elementType, partial, theme) {
|
|
|
5856
6617
|
chartType: p.chartType ?? "column",
|
|
5857
6618
|
title: p.title ?? "\u5B63\u5EA6\u6838\u5FC3\u6307\u6807\u5BF9\u6BD4",
|
|
5858
6619
|
categories: p.categories ? [...p.categories] : ["Q1", "Q2", "Q3", "Q4"],
|
|
5859
|
-
series: p.series ?
|
|
6620
|
+
series: p.series ? Tools6.deepClone(p.series) : [
|
|
5860
6621
|
{ name: "\u672C\u671F\u5B9E\u9645", values: [120, 158, 186, 224], color: accent1 },
|
|
5861
6622
|
{ name: "\u540C\u671F\u57FA\u51C6", values: [98, 126, 145, 178], color: accent2 }
|
|
5862
6623
|
],
|
|
@@ -5866,12 +6627,13 @@ function createDefaultSlideElement(elementType, partial, theme) {
|
|
|
5866
6627
|
showValues: p.showValues ?? true,
|
|
5867
6628
|
...p.datasetCode ? { datasetCode: p.datasetCode } : {},
|
|
5868
6629
|
...p.categoryField ? { categoryField: p.categoryField } : {},
|
|
5869
|
-
...p.valueFields ? { valueFields:
|
|
6630
|
+
...p.valueFields ? { valueFields: Tools6.deepClone(p.valueFields) } : {}
|
|
5870
6631
|
};
|
|
5871
6632
|
}
|
|
5872
6633
|
case "smartArt": {
|
|
5873
6634
|
const p = partial ?? {};
|
|
5874
6635
|
return {
|
|
6636
|
+
...baseExtras,
|
|
5875
6637
|
id,
|
|
5876
6638
|
type: "smartArt",
|
|
5877
6639
|
name: p.name ?? "\u667A\u80FD\u56FE\u793A",
|
|
@@ -5881,7 +6643,7 @@ function createDefaultSlideElement(elementType, partial, theme) {
|
|
|
5881
6643
|
height: p.height ?? 240,
|
|
5882
6644
|
layout: p.layout ?? "process",
|
|
5883
6645
|
title: p.title ?? "\u6838\u5FC3\u5B9E\u65BD\u6D41\u7A0B",
|
|
5884
|
-
items: p.items ?
|
|
6646
|
+
items: p.items ? Tools6.deepClone(p.items) : [
|
|
5885
6647
|
{ id: `sa-${generateRandomId4(4)}`, title: "\u9700\u6C42\u6D1E\u5BDF", subtitle: "\u4E1A\u52A1\u75DB\u70B9\u68B3\u7406" },
|
|
5886
6648
|
{ id: `sa-${generateRandomId4(4)}`, title: "\u67B6\u6784\u8BBE\u8BA1", subtitle: "\u6A21\u578B\u4E0E\u6307\u6807\u5B9A\u4E49" },
|
|
5887
6649
|
{ id: `sa-${generateRandomId4(4)}`, title: "\u654F\u6377\u4EA4\u4ED8", subtitle: "\u81EA\u52A8\u5316\u9A8C\u8BC1\u4E0A\u7EBF" }
|
|
@@ -5892,6 +6654,7 @@ function createDefaultSlideElement(elementType, partial, theme) {
|
|
|
5892
6654
|
case "codeBlock": {
|
|
5893
6655
|
const p = partial ?? {};
|
|
5894
6656
|
return {
|
|
6657
|
+
...baseExtras,
|
|
5895
6658
|
id,
|
|
5896
6659
|
type: "codeBlock",
|
|
5897
6660
|
name: p.name ?? "\u4EE3\u7801\u5757",
|
|
@@ -5911,6 +6674,7 @@ console.log('Exported bytes:', pptxBytes.byteLength);`,
|
|
|
5911
6674
|
case "sheetEmbed": {
|
|
5912
6675
|
const p = partial ?? {};
|
|
5913
6676
|
return {
|
|
6677
|
+
...baseExtras,
|
|
5914
6678
|
id,
|
|
5915
6679
|
type: "sheetEmbed",
|
|
5916
6680
|
name: p.name ?? "\u5DE5\u4F5C\u8868\u5F15\u7528",
|
|
@@ -5920,7 +6684,7 @@ console.log('Exported bytes:', pptxBytes.byteLength);`,
|
|
|
5920
6684
|
height: p.height ?? 220,
|
|
5921
6685
|
title: p.title ?? "\u8D22\u52A1\u9884\u7B97\u6D4B\u7B97\u6A21\u578B\u5FEB\u7167",
|
|
5922
6686
|
headers: p.headers ? [...p.headers] : ["\u79D1\u76EE", "Q1", "Q2", "Q3", "Q4"],
|
|
5923
|
-
rows: p.rows ?
|
|
6687
|
+
rows: p.rows ? Tools6.deepClone(p.rows) : [
|
|
5924
6688
|
["\u4E3B\u8425\u4E1A\u52A1\u6536\u5165", 3200, 3680, 4150, 4890],
|
|
5925
6689
|
["\u7814\u53D1\u6295\u5165", 640, 710, 780, 860],
|
|
5926
6690
|
["\u7ECF\u8425\u5229\u6DA6", 890, 1080, 1320, 1690]
|
|
@@ -5929,6 +6693,30 @@ console.log('Exported bytes:', pptxBytes.byteLength);`,
|
|
|
5929
6693
|
accentColor: p.accentColor ?? "#059669"
|
|
5930
6694
|
};
|
|
5931
6695
|
}
|
|
6696
|
+
case "video":
|
|
6697
|
+
case "audio": {
|
|
6698
|
+
const p = partial ?? {};
|
|
6699
|
+
const isVideo = elementType === "video";
|
|
6700
|
+
return {
|
|
6701
|
+
...baseExtras,
|
|
6702
|
+
id,
|
|
6703
|
+
type: elementType,
|
|
6704
|
+
name: p.name ?? (isVideo ? "\u89C6\u9891\u5A92\u4F53" : "\u97F3\u9891\u5A92\u4F53"),
|
|
6705
|
+
x: p.x ?? (isVideo ? 270 : 320),
|
|
6706
|
+
y: p.y ?? (isVideo ? 150 : 230),
|
|
6707
|
+
width: p.width ?? (isVideo ? 420 : 320),
|
|
6708
|
+
height: p.height ?? (isVideo ? 240 : 64),
|
|
6709
|
+
rotation: p.rotation ?? 0,
|
|
6710
|
+
opacity: p.opacity ?? 1,
|
|
6711
|
+
src: p.src ?? "",
|
|
6712
|
+
...p.poster ? { poster: p.poster } : {},
|
|
6713
|
+
autoPlay: p.autoPlay ?? false,
|
|
6714
|
+
loop: p.loop ?? false,
|
|
6715
|
+
muted: p.muted ?? false,
|
|
6716
|
+
...p.startTimeSec !== void 0 ? { startTimeSec: p.startTimeSec } : {},
|
|
6717
|
+
...p.endTimeSec !== void 0 ? { endTimeSec: p.endTimeSec } : {}
|
|
6718
|
+
};
|
|
6719
|
+
}
|
|
5932
6720
|
}
|
|
5933
6721
|
}
|
|
5934
6722
|
var AddSlidePageCommand = {
|
|
@@ -5938,10 +6726,10 @@ var AddSlidePageCommand = {
|
|
|
5938
6726
|
const ctx = resolveSlideUnit(accessor, params?.unitId);
|
|
5939
6727
|
if (!ctx) return false;
|
|
5940
6728
|
const prev = ctx.unit.save();
|
|
5941
|
-
const next =
|
|
6729
|
+
const next = Tools6.deepClone(prev);
|
|
5942
6730
|
const layout = findLayoutByTypeOrId(next.layouts, params?.layoutId ?? params?.slide?.layoutId ?? "titleAndContent");
|
|
5943
6731
|
const built = params?.slide?.elements ? {
|
|
5944
|
-
elements:
|
|
6732
|
+
elements: Tools6.deepClone(params.slide.elements),
|
|
5945
6733
|
elementOrder: params.slide.elementOrder ? [...params.slide.elementOrder] : Object.keys(params.slide.elements)
|
|
5946
6734
|
} : createElementsFromLayout(layout, next.theme, next.slideSize);
|
|
5947
6735
|
const slideId = params?.slide?.id || `slide-${generateRandomId4(6)}`;
|
|
@@ -5952,9 +6740,9 @@ var AddSlidePageCommand = {
|
|
|
5952
6740
|
hidden: params?.slide?.hidden ?? false,
|
|
5953
6741
|
showSlideNumber: params?.slide?.showSlideNumber ?? layout.type !== "title",
|
|
5954
6742
|
speakerNotes: params?.slide?.speakerNotes ?? "",
|
|
5955
|
-
background: params?.slide?.background ?
|
|
5956
|
-
transition: params?.slide?.transition ?
|
|
5957
|
-
animations: params?.slide?.animations ?
|
|
6743
|
+
background: params?.slide?.background ? Tools6.deepClone(params.slide.background) : { type: "solid", color: next.theme.colors.background },
|
|
6744
|
+
transition: params?.slide?.transition ? Tools6.deepClone(params.slide.transition) : { type: "fade", durationMs: 400 },
|
|
6745
|
+
animations: params?.slide?.animations ? Tools6.deepClone(params.slide.animations) : [],
|
|
5958
6746
|
elementOrder: built.elementOrder,
|
|
5959
6747
|
elements: built.elements
|
|
5960
6748
|
};
|
|
@@ -5989,7 +6777,7 @@ var DuplicateSlidePageCommand = {
|
|
|
5989
6777
|
const prev = ctx.unit.save();
|
|
5990
6778
|
const sourceSlide = prev.slides[sourceId];
|
|
5991
6779
|
if (!sourceSlide) return false;
|
|
5992
|
-
const next =
|
|
6780
|
+
const next = Tools6.deepClone(prev);
|
|
5993
6781
|
const dupSlideId = `slide-${generateRandomId4(6)}`;
|
|
5994
6782
|
const idMap = /* @__PURE__ */ new Map();
|
|
5995
6783
|
const newElements = {};
|
|
@@ -5999,7 +6787,7 @@ var DuplicateSlidePageCommand = {
|
|
|
5999
6787
|
if (!el) continue;
|
|
6000
6788
|
const newElId = `el-${generateRandomId4(6)}`;
|
|
6001
6789
|
idMap.set(oldElId, newElId);
|
|
6002
|
-
newElements[newElId] = { ...
|
|
6790
|
+
newElements[newElId] = { ...Tools6.deepClone(el), id: newElId };
|
|
6003
6791
|
newOrder.push(newElId);
|
|
6004
6792
|
}
|
|
6005
6793
|
for (const el of Object.values(newElements)) {
|
|
@@ -6013,12 +6801,12 @@ var DuplicateSlidePageCommand = {
|
|
|
6013
6801
|
}
|
|
6014
6802
|
}
|
|
6015
6803
|
const newAnimations = (sourceSlide.animations ?? []).map((anim) => ({
|
|
6016
|
-
...
|
|
6804
|
+
...Tools6.deepClone(anim),
|
|
6017
6805
|
id: `anim-${generateRandomId4(6)}`,
|
|
6018
6806
|
elementId: idMap.get(anim.elementId) ?? anim.elementId
|
|
6019
6807
|
}));
|
|
6020
6808
|
next.slides[dupSlideId] = {
|
|
6021
|
-
...
|
|
6809
|
+
...Tools6.deepClone(sourceSlide),
|
|
6022
6810
|
id: dupSlideId,
|
|
6023
6811
|
title: `${sourceSlide.title} (\u526F\u672C)`,
|
|
6024
6812
|
elementOrder: newOrder,
|
|
@@ -6048,7 +6836,7 @@ var DeleteSlidePageCommand = {
|
|
|
6048
6836
|
if (prev.slideOrder.length <= 1) return false;
|
|
6049
6837
|
const targetId = resolveActiveSlideId(accessor, ctx.unit, params?.slideId);
|
|
6050
6838
|
if (!targetId || !prev.slides[targetId]) return false;
|
|
6051
|
-
const next =
|
|
6839
|
+
const next = Tools6.deepClone(prev);
|
|
6052
6840
|
const oldIdx = next.slideOrder.indexOf(targetId);
|
|
6053
6841
|
delete next.slides[targetId];
|
|
6054
6842
|
next.slideOrder = next.slideOrder.filter((id) => id !== targetId);
|
|
@@ -6082,7 +6870,7 @@ var ReorderSlidePagesCommand = {
|
|
|
6082
6870
|
} else {
|
|
6083
6871
|
return false;
|
|
6084
6872
|
}
|
|
6085
|
-
const next =
|
|
6873
|
+
const next = Tools6.deepClone(prev);
|
|
6086
6874
|
next.slideOrder = nextOrder;
|
|
6087
6875
|
for (const sec of next.sections) {
|
|
6088
6876
|
const set = new Set(sec.slideIds);
|
|
@@ -6101,7 +6889,7 @@ var UpdateSlidePagePropsCommand = {
|
|
|
6101
6889
|
const targetSlideId = resolveActiveSlideId(accessor, ctx.unit, params.slideId);
|
|
6102
6890
|
if (!targetSlideId) return false;
|
|
6103
6891
|
const prev = ctx.unit.save();
|
|
6104
|
-
const next =
|
|
6892
|
+
const next = Tools6.deepClone(prev);
|
|
6105
6893
|
const targetIds = params.applyToAllSlides ? next.slideOrder : [targetSlideId];
|
|
6106
6894
|
for (const sid of targetIds) {
|
|
6107
6895
|
const slide = next.slides[sid];
|
|
@@ -6119,10 +6907,10 @@ var UpdateSlidePagePropsCommand = {
|
|
|
6119
6907
|
slide.speakerNotes = params.patch.speakerNotes;
|
|
6120
6908
|
}
|
|
6121
6909
|
if (params.patch.background !== void 0) {
|
|
6122
|
-
slide.background =
|
|
6910
|
+
slide.background = Tools6.deepClone(params.patch.background);
|
|
6123
6911
|
}
|
|
6124
6912
|
if (params.patch.transition !== void 0) {
|
|
6125
|
-
slide.transition =
|
|
6913
|
+
slide.transition = Tools6.deepClone(params.patch.transition);
|
|
6126
6914
|
}
|
|
6127
6915
|
if (params.patch.layoutId !== void 0) {
|
|
6128
6916
|
const layout = findLayoutByTypeOrId(next.layouts, params.patch.layoutId);
|
|
@@ -6168,7 +6956,7 @@ var AddSlideSectionCommand = {
|
|
|
6168
6956
|
const ctx = resolveSlideUnit(accessor, params?.unitId);
|
|
6169
6957
|
if (!ctx) return false;
|
|
6170
6958
|
const prev = ctx.unit.save();
|
|
6171
|
-
const next =
|
|
6959
|
+
const next = Tools6.deepClone(prev);
|
|
6172
6960
|
const assignedSlideIds = params?.slideIds ? [...params.slideIds] : [next.activeSlideId];
|
|
6173
6961
|
const assignedSet = new Set(assignedSlideIds);
|
|
6174
6962
|
for (const sec of next.sections) {
|
|
@@ -6192,7 +6980,7 @@ var UpdateSlideSectionCommand = {
|
|
|
6192
6980
|
const ctx = resolveSlideUnit(accessor, params.unitId);
|
|
6193
6981
|
if (!ctx) return false;
|
|
6194
6982
|
const prev = ctx.unit.save();
|
|
6195
|
-
const next =
|
|
6983
|
+
const next = Tools6.deepClone(prev);
|
|
6196
6984
|
const sec = next.sections.find((s) => s.id === params.sectionId);
|
|
6197
6985
|
if (!sec) return false;
|
|
6198
6986
|
if (params.patch.title !== void 0) sec.title = params.patch.title;
|
|
@@ -6210,7 +6998,7 @@ var DeleteSlideSectionCommand = {
|
|
|
6210
6998
|
if (!ctx) return false;
|
|
6211
6999
|
const prev = ctx.unit.save();
|
|
6212
7000
|
if (prev.sections.length <= 1) return false;
|
|
6213
|
-
const next =
|
|
7001
|
+
const next = Tools6.deepClone(prev);
|
|
6214
7002
|
const idx = next.sections.findIndex((s) => s.id === params.sectionId);
|
|
6215
7003
|
if (idx < 0) return false;
|
|
6216
7004
|
const removed = next.sections[idx];
|
|
@@ -6233,7 +7021,7 @@ var AddSlideElementCommand = {
|
|
|
6233
7021
|
const slideId = resolveActiveSlideId(accessor, ctx.unit, params?.slideId);
|
|
6234
7022
|
if (!slideId) return false;
|
|
6235
7023
|
const prev = ctx.unit.save();
|
|
6236
|
-
const next =
|
|
7024
|
+
const next = Tools6.deepClone(prev);
|
|
6237
7025
|
const slide = next.slides[slideId];
|
|
6238
7026
|
if (!slide) return false;
|
|
6239
7027
|
const type = params?.elementType ?? params?.element?.type ?? "text";
|
|
@@ -6262,14 +7050,14 @@ var UpdateSlideElementsCommand = {
|
|
|
6262
7050
|
const slideId = resolveActiveSlideId(accessor, ctx.unit, params.slideId);
|
|
6263
7051
|
if (!slideId) return false;
|
|
6264
7052
|
const prev = ctx.unit.save();
|
|
6265
|
-
const next =
|
|
7053
|
+
const next = Tools6.deepClone(prev);
|
|
6266
7054
|
const slide = next.slides[slideId];
|
|
6267
7055
|
if (!slide) return false;
|
|
6268
7056
|
let changed = false;
|
|
6269
7057
|
for (const upd of params.updates) {
|
|
6270
7058
|
const existing = slide.elements[upd.id];
|
|
6271
7059
|
if (!existing) continue;
|
|
6272
|
-
let merged = upd.element ?
|
|
7060
|
+
let merged = upd.element ? Tools6.deepClone(upd.element) : { ...existing, ...Tools6.deepClone(upd.patch ?? {}), id: existing.id };
|
|
6273
7061
|
if (merged.type === "text") {
|
|
6274
7062
|
if (upd.patch && "text" in upd.patch && !("paragraphs" in upd.patch)) {
|
|
6275
7063
|
delete merged.paragraphs;
|
|
@@ -6294,7 +7082,7 @@ var DeleteSlideElementsCommand = {
|
|
|
6294
7082
|
const ids = params?.elementIds ?? (accessor.has(ISlideSelectionService) ? accessor.get(ISlideSelectionService).getSelectedElementIds() : []);
|
|
6295
7083
|
if (!ids.length) return false;
|
|
6296
7084
|
const prev = ctx.unit.save();
|
|
6297
|
-
const next =
|
|
7085
|
+
const next = Tools6.deepClone(prev);
|
|
6298
7086
|
const slide = next.slides[slideId];
|
|
6299
7087
|
if (!slide) return false;
|
|
6300
7088
|
const idSet = new Set(ids);
|
|
@@ -6329,7 +7117,7 @@ var AlignSlideElementsCommand = {
|
|
|
6329
7117
|
const ids = params.elementIds ?? (accessor.has(ISlideSelectionService) ? accessor.get(ISlideSelectionService).getSelectedElementIds() : []);
|
|
6330
7118
|
if (!ids.length) return false;
|
|
6331
7119
|
const prev = ctx.unit.save();
|
|
6332
|
-
const next =
|
|
7120
|
+
const next = Tools6.deepClone(prev);
|
|
6333
7121
|
const slide = next.slides[slideId];
|
|
6334
7122
|
if (!slide) return false;
|
|
6335
7123
|
const targets = ids.map((id) => slide.elements[id]).filter((el) => Boolean(el && !el.locked));
|
|
@@ -6408,7 +7196,7 @@ var ReorderSlideElementLayerCommand = {
|
|
|
6408
7196
|
const slideId = resolveActiveSlideId(accessor, ctx.unit, params?.slideId);
|
|
6409
7197
|
if (!slideId) return false;
|
|
6410
7198
|
const prev = ctx.unit.save();
|
|
6411
|
-
const next =
|
|
7199
|
+
const next = Tools6.deepClone(prev);
|
|
6412
7200
|
const slide = next.slides[slideId];
|
|
6413
7201
|
if (!slide) return false;
|
|
6414
7202
|
if (params?.elementOrder && params.elementOrder.length === slide.elementOrder.length) {
|
|
@@ -6449,10 +7237,10 @@ var SetSlideAnimationsCommand = {
|
|
|
6449
7237
|
const slideId = resolveActiveSlideId(accessor, ctx.unit, params.slideId);
|
|
6450
7238
|
if (!slideId) return false;
|
|
6451
7239
|
const prev = ctx.unit.save();
|
|
6452
|
-
const next =
|
|
7240
|
+
const next = Tools6.deepClone(prev);
|
|
6453
7241
|
const slide = next.slides[slideId];
|
|
6454
7242
|
if (!slide) return false;
|
|
6455
|
-
slide.animations =
|
|
7243
|
+
slide.animations = Tools6.deepClone(params.animations);
|
|
6456
7244
|
return executeSnapshotMutationWithUndo(accessor, ctx.unitId, prev, next);
|
|
6457
7245
|
}
|
|
6458
7246
|
};
|
|
@@ -6464,9 +7252,9 @@ var UpdateSlideThemeCommand = {
|
|
|
6464
7252
|
const ctx = resolveSlideUnit(accessor, params.unitId);
|
|
6465
7253
|
if (!ctx) return false;
|
|
6466
7254
|
const prev = ctx.unit.save();
|
|
6467
|
-
const next =
|
|
7255
|
+
const next = Tools6.deepClone(prev);
|
|
6468
7256
|
const oldBg = prev.theme.colors.background;
|
|
6469
|
-
next.theme =
|
|
7257
|
+
next.theme = Tools6.deepClone(params.theme);
|
|
6470
7258
|
if (next.masters[0]) {
|
|
6471
7259
|
next.masters[0].background = { type: "solid", color: next.theme.colors.background };
|
|
6472
7260
|
}
|
|
@@ -6488,7 +7276,7 @@ var SetSlideSizeCommand = {
|
|
|
6488
7276
|
const ctx = resolveSlideUnit(accessor, params.unitId);
|
|
6489
7277
|
if (!ctx) return false;
|
|
6490
7278
|
const prev = ctx.unit.save();
|
|
6491
|
-
const next =
|
|
7279
|
+
const next = Tools6.deepClone(prev);
|
|
6492
7280
|
let nextSize;
|
|
6493
7281
|
if (params.preset && params.preset !== "custom" && SLIDE_SIZE_PRESETS[params.preset]) {
|
|
6494
7282
|
nextSize = { ...SLIDE_SIZE_PRESETS[params.preset] };
|
|
@@ -6561,7 +7349,7 @@ var FindAndReplaceSlideTextCommand = {
|
|
|
6561
7349
|
const ctx = resolveSlideUnit(accessor, params.unitId);
|
|
6562
7350
|
if (!ctx) return false;
|
|
6563
7351
|
const prev = ctx.unit.save();
|
|
6564
|
-
const next =
|
|
7352
|
+
const next = Tools6.deepClone(prev);
|
|
6565
7353
|
const regex = new RegExp(escapeRegExp(params.findText), params.matchCase ? "g" : "gi");
|
|
6566
7354
|
let replacedCount = 0;
|
|
6567
7355
|
const replaceIn = (str) => str.replace(regex, () => {
|
|
@@ -6616,12 +7404,236 @@ var ReplaceSlideSnapshotCommand = {
|
|
|
6616
7404
|
if (!ctx) return false;
|
|
6617
7405
|
const prev = ctx.unit.save();
|
|
6618
7406
|
const normalized = createDefaultSlideUnitData({
|
|
6619
|
-
...
|
|
7407
|
+
...Tools6.deepClone(params.snapshot),
|
|
6620
7408
|
id: ctx.unitId
|
|
6621
7409
|
});
|
|
6622
7410
|
return executeSnapshotMutationWithUndo(accessor, ctx.unitId, prev, normalized);
|
|
6623
7411
|
}
|
|
6624
7412
|
};
|
|
7413
|
+
var UpdateSlideMasterCommand = {
|
|
7414
|
+
id: "slides.command.update-master",
|
|
7415
|
+
type: CommandType2.COMMAND,
|
|
7416
|
+
handler: (accessor, params) => {
|
|
7417
|
+
if (!params?.patch) return false;
|
|
7418
|
+
const ctx = resolveSlideUnit(accessor, params.unitId);
|
|
7419
|
+
if (!ctx) return false;
|
|
7420
|
+
const prev = ctx.unit.save();
|
|
7421
|
+
const next = Tools6.deepClone(prev);
|
|
7422
|
+
let master = params.masterId ? next.masters.find((m) => m.id === params.masterId) : next.masters[0];
|
|
7423
|
+
if (!master) {
|
|
7424
|
+
master = {
|
|
7425
|
+
id: params.masterId || "master-default",
|
|
7426
|
+
name: "\u6807\u51C6\u5546\u52A1\u6BCD\u7248",
|
|
7427
|
+
background: { type: "solid", color: next.theme.colors.background },
|
|
7428
|
+
accentBar: true,
|
|
7429
|
+
footerText: "",
|
|
7430
|
+
masterElements: []
|
|
7431
|
+
};
|
|
7432
|
+
next.masters.push(master);
|
|
7433
|
+
}
|
|
7434
|
+
const prevMasterBg = prev.masters.find((m) => m.id === master.id)?.background;
|
|
7435
|
+
const prevThemeBg = prev.theme.colors.background;
|
|
7436
|
+
if (params.patch.name !== void 0) {
|
|
7437
|
+
master.name = params.patch.name;
|
|
7438
|
+
}
|
|
7439
|
+
if (params.patch.background !== void 0) {
|
|
7440
|
+
master.background = Tools6.deepClone(params.patch.background);
|
|
7441
|
+
}
|
|
7442
|
+
if (params.patch.accentBar !== void 0) {
|
|
7443
|
+
master.accentBar = params.patch.accentBar;
|
|
7444
|
+
}
|
|
7445
|
+
if (params.patch.footerText !== void 0) {
|
|
7446
|
+
master.footerText = params.patch.footerText;
|
|
7447
|
+
}
|
|
7448
|
+
if (params.patch.masterElements !== void 0) {
|
|
7449
|
+
master.masterElements = params.patch.masterElements.map((el) => {
|
|
7450
|
+
const cloned = Tools6.deepClone(el);
|
|
7451
|
+
return cloned.type === "text" ? syncTextAndParagraphs(cloned) : cloned;
|
|
7452
|
+
});
|
|
7453
|
+
}
|
|
7454
|
+
if (params.patch.theme) {
|
|
7455
|
+
next.theme = {
|
|
7456
|
+
...next.theme,
|
|
7457
|
+
...params.patch.theme.name !== void 0 ? { name: params.patch.theme.name } : {},
|
|
7458
|
+
...params.patch.theme.majorFont !== void 0 ? { majorFont: params.patch.theme.majorFont } : {},
|
|
7459
|
+
...params.patch.theme.minorFont !== void 0 ? { minorFont: params.patch.theme.minorFont } : {},
|
|
7460
|
+
colors: {
|
|
7461
|
+
...next.theme.colors,
|
|
7462
|
+
...params.patch.theme.colors ?? {}
|
|
7463
|
+
}
|
|
7464
|
+
};
|
|
7465
|
+
}
|
|
7466
|
+
if (params.patch.background !== void 0 && params.propagateBackgroundToSlides !== false) {
|
|
7467
|
+
const oldMasterJson = prevMasterBg ? JSON.stringify(prevMasterBg) : "";
|
|
7468
|
+
for (const slide of Object.values(next.slides)) {
|
|
7469
|
+
const matchesOldMaster = !slide.background || oldMasterJson && JSON.stringify(slide.background) === oldMasterJson || slide.background.type === "solid" && slide.background.color === prevThemeBg;
|
|
7470
|
+
if (params.propagateBackgroundToSlides === true || matchesOldMaster) {
|
|
7471
|
+
slide.background = Tools6.deepClone(params.patch.background);
|
|
7472
|
+
}
|
|
7473
|
+
}
|
|
7474
|
+
}
|
|
7475
|
+
return executeSnapshotMutationWithUndo(accessor, ctx.unitId, prev, next);
|
|
7476
|
+
}
|
|
7477
|
+
};
|
|
7478
|
+
var UpdateSlideLayoutCommand = {
|
|
7479
|
+
id: "slides.command.update-layout",
|
|
7480
|
+
type: CommandType2.COMMAND,
|
|
7481
|
+
handler: (accessor, params) => {
|
|
7482
|
+
if (!params?.layoutId || !params.patch) return false;
|
|
7483
|
+
const ctx = resolveSlideUnit(accessor, params.unitId);
|
|
7484
|
+
if (!ctx) return false;
|
|
7485
|
+
const prev = ctx.unit.save();
|
|
7486
|
+
const next = Tools6.deepClone(prev);
|
|
7487
|
+
const layout = next.layouts.find(
|
|
7488
|
+
(l) => l.id === params.layoutId || l.type === params.layoutId
|
|
7489
|
+
);
|
|
7490
|
+
if (!layout) return false;
|
|
7491
|
+
if (params.patch.name !== void 0) {
|
|
7492
|
+
layout.name = params.patch.name;
|
|
7493
|
+
}
|
|
7494
|
+
if (params.patch.background !== void 0) {
|
|
7495
|
+
layout.background = Tools6.deepClone(params.patch.background);
|
|
7496
|
+
}
|
|
7497
|
+
if (params.patch.layoutElements !== void 0) {
|
|
7498
|
+
layout.layoutElements = Tools6.deepClone(params.patch.layoutElements);
|
|
7499
|
+
}
|
|
7500
|
+
if (params.patch.placeholders !== void 0) {
|
|
7501
|
+
layout.placeholders = Tools6.deepClone(params.patch.placeholders);
|
|
7502
|
+
if (params.syncExistingSlides !== false) {
|
|
7503
|
+
const scaleX = (next.slideSize.widthPt || 960) / 960;
|
|
7504
|
+
const scaleY = (next.slideSize.heightPt || 540) / 540;
|
|
7505
|
+
const slotByRole = /* @__PURE__ */ new Map();
|
|
7506
|
+
for (const slot of layout.placeholders) {
|
|
7507
|
+
slotByRole.set(slot.role, slot);
|
|
7508
|
+
}
|
|
7509
|
+
for (const slide of Object.values(next.slides)) {
|
|
7510
|
+
if (slide.layoutId !== layout.id) continue;
|
|
7511
|
+
for (const elId of slide.elementOrder) {
|
|
7512
|
+
const el = slide.elements[elId];
|
|
7513
|
+
if (!el || !el.placeholderRole) continue;
|
|
7514
|
+
const slot = slotByRole.get(el.placeholderRole);
|
|
7515
|
+
if (!slot) continue;
|
|
7516
|
+
el.x = Math.round(slot.x * scaleX);
|
|
7517
|
+
el.y = Math.round(slot.y * scaleY);
|
|
7518
|
+
el.width = Math.round(slot.width * scaleX);
|
|
7519
|
+
el.height = Math.round(slot.height * scaleY);
|
|
7520
|
+
if (el.type === "text") {
|
|
7521
|
+
if (slot.fontSize !== void 0) el.fontSize = slot.fontSize;
|
|
7522
|
+
if (slot.align !== void 0) el.align = slot.align;
|
|
7523
|
+
slide.elements[elId] = syncTextAndParagraphs(el);
|
|
7524
|
+
}
|
|
7525
|
+
}
|
|
7526
|
+
}
|
|
7527
|
+
}
|
|
7528
|
+
}
|
|
7529
|
+
return executeSnapshotMutationWithUndo(accessor, ctx.unitId, prev, next);
|
|
7530
|
+
}
|
|
7531
|
+
};
|
|
7532
|
+
var UpdateSlideShowSettingsCommand = {
|
|
7533
|
+
id: "slides.command.update-slideshow-settings",
|
|
7534
|
+
type: CommandType2.COMMAND,
|
|
7535
|
+
handler: (accessor, params) => {
|
|
7536
|
+
if (!params?.patch) return false;
|
|
7537
|
+
const ctx = resolveSlideUnit(accessor, params.unitId);
|
|
7538
|
+
if (!ctx) return false;
|
|
7539
|
+
const prev = ctx.unit.save();
|
|
7540
|
+
const next = Tools6.deepClone(prev);
|
|
7541
|
+
next.slideshowSettings = {
|
|
7542
|
+
...prev.slideshowSettings ?? {},
|
|
7543
|
+
...Tools6.deepClone(params.patch)
|
|
7544
|
+
};
|
|
7545
|
+
return executeSnapshotMutationWithUndo(accessor, ctx.unitId, prev, next);
|
|
7546
|
+
}
|
|
7547
|
+
};
|
|
7548
|
+
|
|
7549
|
+
// src/exporter/slide-image-exporter.ts
|
|
7550
|
+
function applyScaleToSvgDimensions(svgMarkup, widthPx, heightPx) {
|
|
7551
|
+
return svgMarkup.replace(/(<svg\b[^>]*?\swidth=")[^"]+(")/, `$1${widthPx}$2`).replace(/(<svg\b[^>]*?\sheight=")[^"]+(")/, `$1${heightPx}$2`);
|
|
7552
|
+
}
|
|
7553
|
+
function rasterizeSvgInBrowserCanvas(svgDataUrl, widthPx, heightPx, format, quality) {
|
|
7554
|
+
if (typeof document === "undefined" || typeof Image === "undefined" || typeof HTMLCanvasElement === "undefined") {
|
|
7555
|
+
return Promise.resolve(svgDataUrl);
|
|
7556
|
+
}
|
|
7557
|
+
return new Promise((resolve) => {
|
|
7558
|
+
try {
|
|
7559
|
+
const canvas = document.createElement("canvas");
|
|
7560
|
+
canvas.width = widthPx;
|
|
7561
|
+
canvas.height = heightPx;
|
|
7562
|
+
const ctx = canvas.getContext("2d");
|
|
7563
|
+
if (!ctx) {
|
|
7564
|
+
resolve(svgDataUrl);
|
|
7565
|
+
return;
|
|
7566
|
+
}
|
|
7567
|
+
const img = new Image();
|
|
7568
|
+
img.onload = () => {
|
|
7569
|
+
try {
|
|
7570
|
+
if (format === "jpeg") {
|
|
7571
|
+
ctx.fillStyle = "#ffffff";
|
|
7572
|
+
ctx.fillRect(0, 0, widthPx, heightPx);
|
|
7573
|
+
}
|
|
7574
|
+
ctx.drawImage(img, 0, 0, widthPx, heightPx);
|
|
7575
|
+
const mime = format === "jpeg" ? "image/jpeg" : "image/png";
|
|
7576
|
+
const out = format === "jpeg" ? canvas.toDataURL(mime, Math.max(0.1, Math.min(1, quality))) : canvas.toDataURL(mime);
|
|
7577
|
+
resolve(out && out.startsWith("data:") ? out : svgDataUrl);
|
|
7578
|
+
} catch {
|
|
7579
|
+
resolve(svgDataUrl);
|
|
7580
|
+
}
|
|
7581
|
+
};
|
|
7582
|
+
img.onerror = () => {
|
|
7583
|
+
resolve(svgDataUrl);
|
|
7584
|
+
};
|
|
7585
|
+
img.src = svgDataUrl;
|
|
7586
|
+
} catch {
|
|
7587
|
+
resolve(svgDataUrl);
|
|
7588
|
+
}
|
|
7589
|
+
});
|
|
7590
|
+
}
|
|
7591
|
+
async function exportSlidePageToDataUrl(snapshot, slideId, options) {
|
|
7592
|
+
const slide = snapshot.slides[slideId];
|
|
7593
|
+
if (!slide) {
|
|
7594
|
+
throw new Error(`[UniverSlides] Slide "${slideId}" not found in presentation "${snapshot.id}".`);
|
|
7595
|
+
}
|
|
7596
|
+
const format = options?.format ?? "png";
|
|
7597
|
+
const scale = Math.max(0.5, Math.min(8, options?.scale ?? 2));
|
|
7598
|
+
const quality = options?.quality ?? 0.92;
|
|
7599
|
+
const slideW = snapshot.slideSize.widthPt || 960;
|
|
7600
|
+
const slideH = snapshot.slideSize.heightPt || 540;
|
|
7601
|
+
const widthPx = Math.max(1, Math.round(slideW * scale));
|
|
7602
|
+
const heightPx = Math.max(1, Math.round(slideH * scale));
|
|
7603
|
+
const orderIdx = snapshot.slideOrder.indexOf(slideId);
|
|
7604
|
+
const slideNumber = orderIdx >= 0 ? orderIdx + 1 : 1;
|
|
7605
|
+
const rawSvg = renderSlidePageToSvg(slide, snapshot, slideNumber);
|
|
7606
|
+
const scaledSvg = applyScaleToSvgDimensions(rawSvg, widthPx, heightPx);
|
|
7607
|
+
const svgDataUrl = svgToDataUri(scaledSvg);
|
|
7608
|
+
if (format === "svg") {
|
|
7609
|
+
return svgDataUrl;
|
|
7610
|
+
}
|
|
7611
|
+
return await rasterizeSvgInBrowserCanvas(svgDataUrl, widthPx, heightPx, format, quality);
|
|
7612
|
+
}
|
|
7613
|
+
async function exportAllSlidesToImages(snapshot, options) {
|
|
7614
|
+
const format = options?.format ?? "png";
|
|
7615
|
+
const scale = Math.max(0.5, Math.min(8, options?.scale ?? 2));
|
|
7616
|
+
const widthPx = Math.max(1, Math.round((snapshot.slideSize.widthPt || 960) * scale));
|
|
7617
|
+
const heightPx = Math.max(1, Math.round((snapshot.slideSize.heightPt || 540) * scale));
|
|
7618
|
+
const targetSlides = snapshot.slideOrder.map((id, idx) => ({ slide: snapshot.slides[id], idx })).filter(
|
|
7619
|
+
(entry) => Boolean(entry.slide && (options?.includeHiddenSlides || !entry.slide.hidden))
|
|
7620
|
+
);
|
|
7621
|
+
const results = [];
|
|
7622
|
+
for (const { slide, idx } of targetSlides) {
|
|
7623
|
+
const dataUrl = await exportSlidePageToDataUrl(snapshot, slide.id, options);
|
|
7624
|
+
const actualFormat = dataUrl.startsWith("data:image/png") ? "png" : dataUrl.startsWith("data:image/jpeg") ? "jpeg" : format === "svg" || dataUrl.startsWith("data:image/svg+xml") ? "svg" : format;
|
|
7625
|
+
results.push({
|
|
7626
|
+
slideId: slide.id,
|
|
7627
|
+
slideIndex: idx,
|
|
7628
|
+
title: slide.title,
|
|
7629
|
+
format: actualFormat,
|
|
7630
|
+
widthPx,
|
|
7631
|
+
heightPx,
|
|
7632
|
+
dataUrl
|
|
7633
|
+
});
|
|
7634
|
+
}
|
|
7635
|
+
return results;
|
|
7636
|
+
}
|
|
6625
7637
|
|
|
6626
7638
|
// src/plugin.ts
|
|
6627
7639
|
import {
|
|
@@ -6700,7 +7712,10 @@ var UniverSlidesPlugin = class extends Plugin {
|
|
|
6700
7712
|
UpdateSlideThemeCommand,
|
|
6701
7713
|
SetSlideSizeCommand,
|
|
6702
7714
|
FindAndReplaceSlideTextCommand,
|
|
6703
|
-
ReplaceSlideSnapshotCommand
|
|
7715
|
+
ReplaceSlideSnapshotCommand,
|
|
7716
|
+
UpdateSlideMasterCommand,
|
|
7717
|
+
UpdateSlideLayoutCommand,
|
|
7718
|
+
UpdateSlideShowSettingsCommand
|
|
6704
7719
|
];
|
|
6705
7720
|
for (const cmd of commands) {
|
|
6706
7721
|
this.disposeWithMe(this._commandService.registerCommand(cmd));
|
|
@@ -6714,7 +7729,7 @@ UniverSlidesPlugin = __decorateClass([
|
|
|
6714
7729
|
], UniverSlidesPlugin);
|
|
6715
7730
|
|
|
6716
7731
|
// src/index.ts
|
|
6717
|
-
var VERSION = "1.6.
|
|
7732
|
+
var VERSION = "1.6.219";
|
|
6718
7733
|
export {
|
|
6719
7734
|
AddSlideElementCommand,
|
|
6720
7735
|
AddSlidePageCommand,
|
|
@@ -6746,11 +7761,15 @@ export {
|
|
|
6746
7761
|
UNIVER_SLIDE_SCHEMA_VERSION,
|
|
6747
7762
|
UniverSlidesPlugin,
|
|
6748
7763
|
UpdateSlideElementsCommand,
|
|
7764
|
+
UpdateSlideLayoutCommand,
|
|
7765
|
+
UpdateSlideMasterCommand,
|
|
6749
7766
|
UpdateSlidePagePropsCommand,
|
|
6750
7767
|
UpdateSlideSectionCommand,
|
|
7768
|
+
UpdateSlideShowSettingsCommand,
|
|
6751
7769
|
UpdateSlideThemeCommand,
|
|
6752
7770
|
VERSION,
|
|
6753
7771
|
compileSlidesWithDataset,
|
|
7772
|
+
computeMorphInterpolatedSlide,
|
|
6754
7773
|
countSlideTextMatches,
|
|
6755
7774
|
crc32Bytes,
|
|
6756
7775
|
createDefaultSlideElement,
|
|
@@ -6759,11 +7778,14 @@ export {
|
|
|
6759
7778
|
createDefaultSlideUnitData,
|
|
6760
7779
|
createElementsFromLayout,
|
|
6761
7780
|
createSampleExecutiveDeckData,
|
|
7781
|
+
cubicEaseInOut,
|
|
6762
7782
|
deflateRawSyncPure,
|
|
6763
7783
|
emuToPt,
|
|
6764
7784
|
escapeSvgXml,
|
|
7785
|
+
exportAllSlidesToImages,
|
|
6765
7786
|
exportPptxBytes,
|
|
6766
7787
|
exportPptxBytesSync,
|
|
7788
|
+
exportSlidePageToDataUrl,
|
|
6767
7789
|
exportSlidesToPdfBytes,
|
|
6768
7790
|
extractSlideDatasetCodes,
|
|
6769
7791
|
findLayoutByTypeOrId,
|
|
@@ -6772,15 +7794,21 @@ export {
|
|
|
6772
7794
|
importPptxBytes,
|
|
6773
7795
|
importPptxBytesSync,
|
|
6774
7796
|
inflateRawSyncPure,
|
|
7797
|
+
interpolateHexColor,
|
|
7798
|
+
matchMorphSlidePairs,
|
|
6775
7799
|
packZipSync,
|
|
7800
|
+
parseCssHexOrRgb,
|
|
6776
7801
|
ptToEmu,
|
|
6777
7802
|
renderSlideChartToSvg,
|
|
6778
7803
|
renderSlideChartToSvgDataUri,
|
|
7804
|
+
renderSlideMediaToSvg,
|
|
7805
|
+
renderSlideMediaToSvgDataUri,
|
|
6779
7806
|
renderSlidePageToSvg,
|
|
6780
7807
|
renderSlideSmartArtToSvg,
|
|
6781
7808
|
renderSlideSmartArtToSvgDataUri,
|
|
6782
7809
|
resolveChartPalette,
|
|
6783
7810
|
resolveConnectorEndpoints,
|
|
7811
|
+
resolveExplicitMorphKey,
|
|
6784
7812
|
svgToDataUri,
|
|
6785
7813
|
syncTextAndParagraphs,
|
|
6786
7814
|
unpackZipSync
|