Skip to content

AI-native design editor. Open-source Figma alternative.

feat(export): add editable PPTX export (#416)

tae.virus679ee9f98f71
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e15815cdf..1d48e96a0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@
### Added
+- Export selections, pages and documents as editable PowerPoint (`.pptx`) files from the File menu, CLI and SDK: text, rectangles, ellipses and lines stay native editable elements, while gradients, masks, blends, vectors and icons fall back to embedded images.
- Figma-style Assets panel browsing with component thumbnails, grid/list views, page grouping, context actions, and drag-to-canvas insertion.
- Import HTML, CSS, Tailwind, and JSX as editable documents from the app, CLI, and SDK, and export standalone browser-ready HTML with compiled CSS and optional external assets.
- Author richer Design JSX with components, instances, variables, gradients, structured fills, shadows, and blur effects.
diff --git a/bun.lock b/bun.lock
index 636b694ef..3d7b4ecca 100644
--- a/bun.lock
+++ b/bun.lock
@@ -161,6 +161,7 @@
"nanoevents": "^9.1.0",
"ofetch": "^1.5.1",
"opentype.js": "^2.0.0",
+ "pptxgenjs": "^4.0.1",
"sucrase": "^3.35.1",
"svg2pdf.js": "^2.7.0",
"svgpath": "^2.6.0",
@@ -1638,6 +1639,8 @@
"core-js-compat": ["[email protected]", "", { "dependencies": { "browserslist": "^4.28.1" } }, "sha512-VQXt1jr9cBz03b331DFDCCP90b3fanciLkgiOoy8SBHy06gNf+vQ1A3WFLqG7I8TipYIKeYK9wxd0tUrvHcOZA=="],
+ "core-util-is": ["[email protected]", "", {}, "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="],
+
"cors": ["[email protected]", "", { "dependencies": { "object-assign": "^4", "vary": "^1" } }, "sha512-tJtZBBHA6vjIAaF6EnIaq6laBBP9aq/Y3ouVJjEfoHbRBcHBAHYcMh/w8LDrk2PvIMMq8gmopa5D4V8RmbrxGw=="],
"cosmiconfig": ["[email protected]", "", { "dependencies": { "env-paths": "^2.2.1", "import-fresh": "^3.3.0", "js-yaml": "^4.1.0", "parse-json": "^5.2.0" }, "peerDependencies": { "typescript": ">=4.9.5" }, "optionalPeers": ["typescript"] }, "sha512-hr4ihw+DBqcvrsEDioRO31Z17x71pUYoNe/4h6Z0wB72p7MU7/9gH8Q3s12NFhHPfYBBOV3qyfUxmr/Yn3shnQ=="],
@@ -1982,6 +1985,8 @@
"http-parser-js": ["[email protected]", "", {}, "sha512-Pysuw9XpUq5dVc/2SMHpuTY01RFl8fttgcyunjL7eEMhGM3cI4eOmiCycJDVCo/7O7ClfQD3SaI6ftDzqOXYMA=="],
+ "https": ["[email protected]", "", {}, "sha512-4EC57ddXrkaF0x83Oj8sM6SLQHAWXw90Skqu2M4AEWENZ3F02dFJE/GARA8igO79tcgYqGrD7ae4f5L3um2lgg=="],
+
"human-signals": ["[email protected]", "", {}, "sha512-SEQu7vl8KjNL2eoGBLF3+wAjpsNfA9XMlXAYj/3EdaNfAlxKthD1xjEQfGOUhllCGGJVNY34bRr6lPINhNjyZw=="],
"iceberg-js": ["[email protected]", "", {}, "sha512-1dhVQZXhcHje7798IVM+xoo/1ZdVfzOMIc8/rgVSijRK38EDqOJoGula9N/8ZI5RD8QTxNQtK/Gozpr+qUqRRA=="],
@@ -1994,6 +1999,10 @@
"ignore": ["[email protected]", "", {}, "sha512-Hs59xBNfUIunMFgWAbGX5cq6893IbWg4KnrjbYwX3tx0ztorVgTDA6B2sxf8ejHJ4wz8BqGUMYlnzNBer5NvGg=="],
+ "image-size": ["[email protected]", "", { "dependencies": { "queue": "6.0.2" }, "bin": { "image-size": "bin/image-size.js" } }, "sha512-rH+46sQJ2dlwfjfhCyNx5thzrv+dtmBIhPHk0zgRUukHzZ/kRueTJXoYYsclBaKcSMBWuGbOFXtioLpzTb5euw=="],
+
+ "immediate": ["[email protected]", "", {}, "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ=="],
+
"immer": ["[email protected]", "", {}, "sha512-d/+XTN3zfODyjr89gM3mPq1WNX2B8pYsu7eORitdwyA2sBubnTl3laYlBk4sXY5FUa5qTZGBDPJICVbvqzjlbw=="],
"import-fresh": ["[email protected]", "", { "dependencies": { "parent-module": "^1.0.0", "resolve-from": "^4.0.0" } }, "sha512-TR3KfrTZTYLPB6jUjfx6MF9WcWrHL9su5TObK4ZkYgBdWKPOFoSoQIdEuTuR82pmtxH2spWG9h6etwfr1pLBqQ=="],
@@ -2100,7 +2109,7 @@
"is-wsl": ["[email protected]", "", { "dependencies": { "is-inside-container": "^1.0.0" } }, "sha512-e6rvdUCiQCAuumZslxRJWR/Doq4VpPR82kqclvcS0efgt430SlGIk05vdCN58+VrzgtIcfNODjozVielycD4Sw=="],
- "isarray": ["[email protected]", "", {}, "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw=="],
+ "isarray": ["[email protected]", "", {}, "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ=="],
"isexe": ["[email protected]", "", {}, "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw=="],
@@ -2196,6 +2205,8 @@
"jstransformer": ["[email protected]", "", { "dependencies": { "is-promise": "^2.0.0", "promise": "^7.0.1" } }, "sha512-C9YK3Rf8q6VAPDCCU9fnqo3mAfOH6vUGnMcP4AQAYIEpWtfGLpwOTmZ+igtdK5y+VvI2n3CyYSzy4Qh34eq24A=="],
+ "jszip": ["[email protected]", "", { "dependencies": { "lie": "~3.3.0", "pako": "~1.0.2", "readable-stream": "~2.3.6", "setimmediate": "^1.0.5" } }, "sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g=="],
+
"katex": ["[email protected]", "", { "dependencies": { "commander": "^8.3.0" }, "bin": { "katex": "cli.js" } }, "sha512-EkxoDTk8ufHqHlf9QxGwcxeLkWRR3iOuYfRpfORgYfqc8s13bgb+YtRY59NK5ZpRaCwq1kqA6a5lpX8C/eLphQ=="],
"kind-of": ["[email protected]", "", {}, "sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw=="],
@@ -2208,6 +2219,8 @@
"libp2p": ["[email protected]", "", { "dependencies": { "@chainsafe/is-ip": "^2.1.0", "@chainsafe/netmask": "^2.0.0", "@libp2p/crypto": "^5.1.6", "@libp2p/interface": "^2.10.4", "@libp2p/interface-internal": "^2.3.17", "@libp2p/logger": "^5.1.20", "@libp2p/multistream-select": "^6.0.27", "@libp2p/peer-collections": "^6.0.33", "@libp2p/peer-id": "^5.1.7", "@libp2p/peer-store": "^11.2.5", "@libp2p/utils": "^6.7.0", "@multiformats/dns": "^1.0.6", "@multiformats/multiaddr": "^12.4.4", "@multiformats/multiaddr-matcher": "^1.7.2", "any-signal": "^4.1.1", "datastore-core": "^10.0.2", "interface-datastore": "^8.3.1", "it-byte-stream": "^2.0.2", "it-merge": "^3.0.11", "it-parallel": "^3.0.11", "main-event": "^1.0.1", "multiformats": "^13.3.6", "p-defer": "^4.0.1", "p-retry": "^6.2.1", "progress-events": "^1.0.1", "race-event": "^1.3.0", "race-signal": "^1.1.3", "uint8arrays": "^5.1.0" } }, "sha512-EjkyN0CI6uP+e4OOkEcZvhbZtlwFl4Y0rkkMvDbXmcfILX4E4n/jKE4Ppoc1qhNufxToxVWCMDS2ipniQgiYaw=="],
+ "lie": ["[email protected]", "", { "dependencies": { "immediate": "~3.0.5" } }, "sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ=="],
+
"lightningcss": ["[email protected]", "", { "dependencies": { "detect-libc": "^2.0.3" }, "optionalDependencies": { "lightningcss-android-arm64": "1.32.0", "lightningcss-darwin-arm64": "1.32.0", "lightningcss-darwin-x64": "1.32.0", "lightningcss-freebsd-x64": "1.32.0", "lightningcss-linux-arm-gnueabihf": "1.32.0", "lightningcss-linux-arm64-gnu": "1.32.0", "lightningcss-linux-arm64-musl": "1.32.0", "lightningcss-linux-x64-gnu": "1.32.0", "lightningcss-linux-x64-musl": "1.32.0", "lightningcss-win32-arm64-msvc": "1.32.0", "lightningcss-win32-x64-msvc": "1.32.0" } }, "sha512-NXYBzinNrblfraPGyrbPoD19C1h9lfI/1mzgWYvXUTe414Gz/X1FD2XBZSZM7rRTrMA8JL3OtAaGifrIKhQ5yQ=="],
"lightningcss-android-arm64": ["[email protected]", "", { "os": "android", "cpu": "arm64" }, "sha512-YK7/ClTt4kAK0vo6w3X+Pnm0D2cf2vPHbhOXdoNti1Ga0al1P4TBZhwjATvjNwLEBCnKvjJc2jQgHXH0NEwlAg=="],
@@ -2568,6 +2581,8 @@
"postcss-values-parser": ["[email protected]", "", { "dependencies": { "color-name": "^1.1.4", "is-url-superb": "^4.0.0", "quote-unquote": "^1.0.0" }, "peerDependencies": { "postcss": "^8.2.9" } }, "sha512-YLJpK0N1brcNJrs9WatuJFtHaV9q5aAOj+S4DI5S7jgHlRfm0PIbDCAFRYMQD5SHq7Fy6xsDhyutgS0QOAs0qw=="],
+ "pptxgenjs": ["[email protected]", "", { "dependencies": { "@types/node": "^22.8.1", "https": "^1.0.0", "image-size": "^1.2.1", "jszip": "^3.10.1" } }, "sha512-TeJISr8wouAuXw4C1F/mC33xbZs/FuEG6nH9FG1Zj+nuPcGMP5YRHl6X+j3HSUnS1f3at6k75ZZXPMZlA5Lj9A=="],
+
"precinct": ["[email protected]", "", { "dependencies": { "@dependents/detective-less": "^5.0.3", "commander": "^12.1.0", "detective-amd": "^6.1.0", "detective-cjs": "^6.1.1", "detective-es6": "^5.0.2", "detective-postcss": "^8.0.3", "detective-sass": "^6.0.2", "detective-scss": "^5.0.2", "detective-stylus": "^5.0.1", "detective-typescript": "^14.1.2", "detective-vue2": "^2.3.0", "module-definition": "^6.0.2", "node-source-walk": "^7.0.2", "postcss": "^8.5.14", "typescript": "^5.9.3" }, "bin": { "precinct": "bin/cli.js" } }, "sha512-JbJevI1K80z8e/WIyDt/4vUN/4qcfBSKKqOjJA4mosPPPb7zODKRJQV7YN7apVWN3k58nZYm/vEsLgEGYmnxwg=="],
"pretty-bytes": ["[email protected]", "", {}, "sha512-mQUvGU6aUFQ+rNvTIAcZuWGRT9a6f6Yrg9bHs4ImKF+HZCEK+plBvnAZYSIQztknZF2qnzNtr6F8s0+IuptdlQ=="],
@@ -2632,6 +2647,8 @@
"quansync": ["[email protected]", "", {}, "sha512-5xZacEEufv3HSTPQuchrvV6soaiACMFnq1H8wkVioctoH3TRha9Sz66lOxRwPK/qZj7HPiSveih9yAyh98gvqA=="],
+ "queue": ["[email protected]", "", { "dependencies": { "inherits": "~2.0.3" } }, "sha512-iHZWu+q3IdFZFX36ro/lKBkSvfkztY5Y7HMiPlOUjhupPcG2JMfst2KKEpu5XndviX/3UhFbRngUPNKtgvtZiA=="],
+
"queue-microtask": ["[email protected]", "", {}, "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A=="],
"quick-lru": ["[email protected]", "", {}, "sha512-k9lSsjl36EJdK7I06v7APZCbyGT2vMTsYSRX1Q2nbYmnkBqgUhRkAuzH08Ciotteu/PLJmIF2+tti7o3C/ts2g=="],
@@ -2736,7 +2753,7 @@
"safe-array-concat": ["[email protected]", "", { "dependencies": { "call-bind": "^1.0.8", "call-bound": "^1.0.2", "get-intrinsic": "^1.2.6", "has-symbols": "^1.1.0", "isarray": "^2.0.5" } }, "sha512-AURm5f0jYEOydBj7VQlVvDrjeFgthDdEF5H1dP+6mNpoXOMo1quQqJ4wvJDyRZ9+pO3kGWoOdmV08cSv2aJV6Q=="],
- "safe-buffer": ["[email protected]", "", {}, "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ=="],
+ "safe-buffer": ["[email protected]", "", {}, "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="],
"safe-push-apply": ["[email protected]", "", { "dependencies": { "es-errors": "^1.3.0", "isarray": "^2.0.5" } }, "sha512-iKE9w/Z7xCzUMIZqdBsp6pEQvwuEebH4vdpjcDWnyzaI6yl6O9FHvVpmGelvEHNsoY6wGblkxR6Zty/h00WiSA=="],
@@ -2764,6 +2781,8 @@
"set-proto": ["[email protected]", "", { "dependencies": { "dunder-proto": "^1.0.1", "es-errors": "^1.3.0", "es-object-atoms": "^1.0.0" } }, "sha512-RJRdvCo6IAnPdsvP/7m6bsQqNnn1FCBX5ZNtFL98MmFF/4xAIJTIg1YbHW5DC2W5SKZanrC6i4HsJqlajw/dZw=="],
+ "setimmediate": ["[email protected]", "", {}, "sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA=="],
+
"setprototypeof": ["[email protected]", "", {}, "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw=="],
"shebang-command": ["[email protected]", "", { "dependencies": { "shebang-regex": "^3.0.0" } }, "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA=="],
@@ -3442,6 +3461,10 @@
"jstransformer/is-promise": ["[email protected]", "", {}, "sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ=="],
+ "jszip/pako": ["[email protected]", "", {}, "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw=="],
+
+ "jszip/readable-stream": ["[email protected]", "", { "dependencies": { "core-util-is": "~1.0.0", "inherits": "~2.0.3", "isarray": "~1.0.0", "process-nextick-args": "~2.0.0", "safe-buffer": "~5.1.1", "string_decoder": "~1.1.1", "util-deprecate": "~1.0.1" } }, "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA=="],
+
"katex/commander": ["[email protected]", "", {}, "sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww=="],
"local-pkg/quansync": ["[email protected]", "", {}, "sha512-AifT7QEbW9Nri4tAwR5M/uzpBuqfZf+zwaEM/QkzEjj7NBuFD2rBuy0K3dE+8wltbezDV7JMA0WfnCPYRSYbXA=="],
@@ -3466,6 +3489,8 @@
"playwright/fsevents": ["[email protected]", "", { "os": "darwin" }, "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA=="],
+ "pptxgenjs/@types/node": ["@types/[email protected]", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-EANqOCF9QFyra+4pfxUcX9STKJpCLjMbObVzljIJomAWSnuSIEAvyzEU53GaajbXJEgdh0iEcPL+DGvpUd4k1Q=="],
+
"precinct/commander": ["[email protected]", "", {}, "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA=="],
"precinct/postcss": ["[email protected]", "", { "dependencies": { "nanoid": "^3.3.11", "picocolors": "^1.1.1", "source-map-js": "^1.2.1" } }, "sha512-SoSL4+OSEtR99LHFZQiJLkT59C5B1amGO1NzTwj7TT1qCUgUO6hxOvzkOYxD+vMrXBM3XJIKzokoERdqQq/Zmg=="],
@@ -3476,6 +3501,8 @@
"pretty-format/ansi-styles": ["[email protected]", "", {}, "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA=="],
+ "randombytes/safe-buffer": ["[email protected]", "", {}, "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ=="],
+
"reka-ui/defu": ["[email protected]", "", {}, "sha512-mEQCMmwJu317oSz8CwdIOdwf3xMif1ttiM8LTufzc3g6kR+9Pe236twL8j3IYT1F7GfRgGcW6MWxzZjLIkuHIg=="],
"rolldown/@rolldown/pluginutils": ["@rolldown/[email protected]", "", {}, "sha512-2j9bGt5Jh8hj+vPtgzPtl72j0yRxHAyumoo6TNfAjsLB04UtpSvPbPcDcBMxz7n+9CYB0c1GxQFxYRg2jimqGw=="],
@@ -3488,6 +3515,10 @@
"router/path-to-regexp": ["[email protected]", "", {}, "sha512-PuseHIvAnz3bjrM2rGJtSgo1zjgxapTLZ7x2pjhzWwlp4SJQgK3f3iZIQwkpEnBaKz6seKBADpM4B4ySkuYypg=="],
+ "safe-array-concat/isarray": ["[email protected]", "", {}, "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw=="],
+
+ "safe-push-apply/isarray": ["[email protected]", "", {}, "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw=="],
+
"shiki/@shikijs/core": ["@shikijs/[email protected]", "", { "dependencies": { "@shikijs/engine-javascript": "2.5.0", "@shikijs/engine-oniguruma": "2.5.0", "@shikijs/types": "2.5.0", "@shikijs/vscode-textmate": "^10.0.2", "@types/hast": "^3.0.4", "hast-util-to-html": "^9.0.4" } }, "sha512-uu/8RExTKtavlpH7XqnVYBrfBkUc20ngXiX9NSrBhOVZYv/7XQRKUyhtkeflY5QsxC0GbJThCerruZfsUaSldg=="],
"shiki/@shikijs/types": ["@shikijs/[email protected]", "", { "dependencies": { "@shikijs/vscode-textmate": "^10.0.2", "@types/hast": "^3.0.4" } }, "sha512-ygl5yhxki9ZLNuNpPitBWvcy9fsSKKaRuO4BAlMyagszQidxcpLAr0qiW/q43DtSIDxO6hEbtYLiFZNXO/hdGw=="],
@@ -3496,6 +3527,8 @@
"storybook/oxc-parser": ["[email protected]", "", { "dependencies": { "@oxc-project/types": "^0.127.0" }, "optionalDependencies": { "@oxc-parser/binding-android-arm-eabi": "0.127.0", "@oxc-parser/binding-android-arm64": "0.127.0", "@oxc-parser/binding-darwin-arm64": "0.127.0", "@oxc-parser/binding-darwin-x64": "0.127.0", "@oxc-parser/binding-freebsd-x64": "0.127.0", "@oxc-parser/binding-linux-arm-gnueabihf": "0.127.0", "@oxc-parser/binding-linux-arm-musleabihf": "0.127.0", "@oxc-parser/binding-linux-arm64-gnu": "0.127.0", "@oxc-parser/binding-linux-arm64-musl": "0.127.0", "@oxc-parser/binding-linux-ppc64-gnu": "0.127.0", "@oxc-parser/binding-linux-riscv64-gnu": "0.127.0", "@oxc-parser/binding-linux-riscv64-musl": "0.127.0", "@oxc-parser/binding-linux-s390x-gnu": "0.127.0", "@oxc-parser/binding-linux-x64-gnu": "0.127.0", "@oxc-parser/binding-linux-x64-musl": "0.127.0", "@oxc-parser/binding-openharmony-arm64": "0.127.0", "@oxc-parser/binding-wasm32-wasi": "0.127.0", "@oxc-parser/binding-win32-arm64-msvc": "0.127.0", "@oxc-parser/binding-win32-ia32-msvc": "0.127.0", "@oxc-parser/binding-win32-x64-msvc": "0.127.0" } }, "sha512-bkgD4qHlN7WxLdX8bLXdaU54TtQtAIg/ZBAfm0aje/mo3MRDo3P0hZSgr4U7O3xfX+fQmR5AP04JS/TGcZLcFA=="],
+ "string_decoder/safe-buffer": ["[email protected]", "", {}, "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ=="],
+
"strip-ansi/ansi-regex": ["[email protected]", "", {}, "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ=="],
"sucrase/commander": ["[email protected]", "", {}, "sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA=="],
@@ -3568,6 +3601,10 @@
"weald/supports-color": ["[email protected]", "", {}, "sha512-SS+jx45GF1QjgEXQx4NJZV9ImqmO2NPz5FNsIHrsDjh2YsHnawpan7SNQ1o8NuhrbHZy9AZhIoCUiCeaW/C80g=="],
+ "websocket-driver/safe-buffer": ["[email protected]", "", {}, "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ=="],
+
+ "which-builtin-type/isarray": ["[email protected]", "", {}, "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw=="],
+
"with/@babel/parser": ["@babel/[email protected]", "", { "dependencies": { "@babel/types": "^7.29.0" }, "bin": "./bin/babel-parser.js" }, "sha512-4GgRzy/+fsBa72/RZVJmGKPmZu9Byn8o4MoLpmNe1m8ZfYnz5emHLQz3U4gLud6Zwl0RZIcgiLD7Uq7ySFuDLA=="],
"workbox-background-sync/idb": ["[email protected]", "", {}, "sha512-gchesWBzyvGHRO9W8tzUWFDycow5gwjvFKfyV9FF32Y7F50yZMp7mP+T2mJIWFx49zicqyC4uefHM17o6xKIVQ=="],
@@ -3646,8 +3683,12 @@
"gray-matter/js-yaml/argparse": ["[email protected]", "", { "dependencies": { "sprintf-js": "~1.0.2" } }, "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg=="],
+ "jszip/readable-stream/string_decoder": ["[email protected]", "", { "dependencies": { "safe-buffer": "~5.1.0" } }, "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg=="],
+
"mlly/pkg-types/confbox": ["[email protected]", "", {}, "sha512-RMtmw0iFkeR4YV+fUOSucriAQNb9g8zFR52MWCtl+cCZOFRNL6zeB395vPzFhEjjn4fMxXudmELnl/KF/WrK6w=="],
+ "pptxgenjs/@types/node/undici-types": ["[email protected]", "", {}, "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ=="],
+
"rolldown-plugin-dts/@babel/generator/@babel/types": ["@babel/[email protected]", "", { "dependencies": { "@babel/helper-string-parser": "^8.0.0", "@babel/helper-validator-identifier": "^8.0.0" } }, "sha512-K8ponJDxBwDHigkeFqaqT5wLGl4bTlwMafR8k7b5CPxr6Ww+UG9ls8Yx6Tcpboxu97eeGVEEyKcHmEyOwN1vSw=="],
"rolldown-plugin-dts/@babel/parser/@babel/types": ["@babel/[email protected]", "", { "dependencies": { "@babel/helper-string-parser": "^8.0.0", "@babel/helper-validator-identifier": "^8.0.0" } }, "sha512-K8ponJDxBwDHigkeFqaqT5wLGl4bTlwMafR8k7b5CPxr6Ww+UG9ls8Yx6Tcpboxu97eeGVEEyKcHmEyOwN1vSw=="],
diff --git a/packages/cli/src/commands/export.ts b/packages/cli/src/commands/export.ts
index 3c3ea91fd..21a3bf5ad 100644
--- a/packages/cli/src/commands/export.ts
+++ b/packages/cli/src/commands/export.ts
@@ -19,7 +19,7 @@ import { loadDocument, populateDocumentPage, populateWholeDocument } from '#cli/
const io = new IORegistry(BUILTIN_IO_FORMATS)
const RASTER_FORMATS = ['PNG', 'JPG', 'WEBP']
-const ALL_FORMATS = new Set([...RASTER_FORMATS, 'SVG', 'PDF', 'JSX', 'FIG', 'HTML'])
+const ALL_FORMATS = new Set([...RASTER_FORMATS, 'SVG', 'PDF', 'PPTX', 'JSX', 'FIG', 'HTML'])
const JSX_STYLES = new Set(['openpencil', 'tailwind'])
const HTML_STYLES = new Set(['inline', 'tailwind'])
const HTML_MODES = new Set(['fragment', 'standalone'])
@@ -83,7 +83,7 @@ async function exportViaApp(format: string, args: ExportArgs) {
return
}
- if (format === 'JSX' || format === 'HTML' || format === 'FIG') {
+ if (format === 'JSX' || format === 'HTML' || format === 'FIG' || format === 'PPTX') {
printError(`${format} export is only available in file mode right now.`)
process.exit(1)
}
@@ -160,7 +160,7 @@ function prepareGraphForExport(
format: string,
args: ExportArgs
): boolean {
- const wholeDocument = format === 'FIG' && !args.page && !args.node
+ const wholeDocument = (format === 'FIG' || format === 'PPTX') && !args.page && !args.node
if (wholeDocument || args.node) populateWholeDocument(graph)
else populateDocumentPage(graph, pageId)
return wholeDocument
@@ -175,7 +175,10 @@ async function executeFileExport(
| undefined,
wholeDocument: boolean
) {
- if (wholeDocument) return io.writeDocument(formatId, graph, options)
+ if (wholeDocument) {
+ if (formatId === 'fig') return io.writeDocument(formatId, graph, options)
+ return io.exportContent(formatId, { graph, target: { scope: 'document' } }, options)
+ }
return io.exportContent(formatId, { graph, target }, options)
}
@@ -248,7 +251,7 @@ async function exportFromFile(format: string, args: ExportArgs) {
}
export default defineCommand({
- meta: { description: 'Export a document to PNG, JPG, WEBP, SVG, PDF, JSX, HTML, or .fig' },
+ meta: { description: 'Export a document to PNG, JPG, WEBP, SVG, PDF, PPTX, JSX, HTML, or .fig' },
args: {
file: {
type: 'positional',
@@ -264,7 +267,7 @@ export default defineCommand({
format: {
type: 'string',
alias: 'f',
- description: 'Export format: png, jpg, webp, svg, pdf, jsx, html, fig (default: png)',
+ description: 'Export format: png, jpg, webp, svg, pdf, pptx, jsx, html, fig (default: png)',
default: 'png'
},
scale: { type: 'string', alias: 's', description: 'Export scale (default: 1)', default: '1' },
@@ -318,7 +321,7 @@ export default defineCommand({
const format = args.format.toUpperCase() as RasterExportFormat | 'SVG' | 'JSX' | 'FIG' | 'HTML'
if (!ALL_FORMATS.has(format)) {
printError(
- `Invalid format "${args.format}". Use png, jpg, webp, svg, pdf, jsx, html, or fig.`
+ `Invalid format "${args.format}". Use png, jpg, webp, svg, pdf, pptx, jsx, html, or fig.`
)
process.exit(1)
}
diff --git a/packages/core/package.json b/packages/core/package.json
index 255e08378..fd46df11a 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -189,6 +189,7 @@
"nanoevents": "^9.1.0",
"ofetch": "^1.5.1",
"opentype.js": "^2.0.0",
+ "pptxgenjs": "^4.0.1",
"sucrase": "^3.35.1",
"svg2pdf.js": "^2.7.0",
"svgpath": "^2.6.0",
diff --git a/packages/core/src/io/formats.ts b/packages/core/src/io/formats.ts
index 0b0273a72..dccb3b2bd 100644
--- a/packages/core/src/io/formats.ts
+++ b/packages/core/src/io/formats.ts
@@ -3,6 +3,7 @@ import { parsePenFile } from '@open-pencil/pen'
import { sceneNodeToJSX, selectionToJSX } from '#core/design-jsx'
import { exportFigFile, parseFigFile } from './formats/fig'
+import type { PPTXExportOptions } from './formats/pptx'
import { headlessRenderNodes, renderNodesToImage, type RasterExportFormat } from './formats/raster'
import { renderNodesToSVG } from './formats/svg'
import { extractExportGraph, findPageId } from './subgraph'
@@ -286,6 +287,54 @@ export const pdfFormat: IOFormatAdapter = {
}
}
+/**
+ * Every top-level frame becomes a slide, so a PPTX document export spans all
+ * pages — the shared resolver only reaches the first one.
+ */
+function resolvePPTXExportNodes(
+ request: ExportRequest
+): { pageId: string; nodeIds: string[] } | null {
+ if (request.target.scope !== 'document') return resolveExportNodes(request)
+ const pages = request.graph.getPages()
+ if (!pages.length) return null
+ return { pageId: pages[0].id, nodeIds: pages.flatMap((page) => page.childIds) }
+}
+
+export const pptxFormat: IOFormatAdapter = {
+ id: 'pptx',
+ label: 'PowerPoint',
+ role: 'derived-export',
+ category: 'print',
+ extensions: ['pptx'],
+ mimeTypes: ['application/vnd.openxmlformats-officedocument.presentationml.presentation'],
+ support: {
+ exportDocument: true,
+ exportPage: true,
+ exportSelection: true,
+ exportNode: true
+ },
+ exportOptions: {
+ scale: false,
+ quality: false
+ },
+ async exportContent(request, options?: PPTXExportOptions, context?: IOContext) {
+ const target = resolvePPTXExportNodes(request)
+ if (!target) throw new Error('Nothing to export')
+ const { renderNodesToPPTX } = await import('./formats/pptx')
+ const data = await renderNodesToPPTX(request.graph, target.pageId, target.nodeIds, {
+ ...options,
+ context: options?.context ?? context
+ })
+ if (!data) throw new Error('Nothing to export')
+ return {
+ format: 'pptx',
+ mimeType: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
+ extension: 'pptx',
+ data
+ }
+ }
+}
+
export const jsxFormat: IOFormatAdapter = {
id: 'jsx',
label: 'JSX',
@@ -329,5 +378,6 @@ export const BUILTIN_IO_FORMATS: IOFormatAdapter[] = [
webpFormat,
svgFormat,
pdfFormat,
+ pptxFormat,
jsxFormat
]
diff --git a/packages/core/src/io/formats/pptx/export.ts b/packages/core/src/io/formats/pptx/export.ts
new file mode 100644
index 000000000..9e2a0d170
--- /dev/null
+++ b/packages/core/src/io/formats/pptx/export.ts
@@ -0,0 +1,581 @@
+import type PptxGenJS from 'pptxgenjs'
+
+import type { Fill, Mat3, SceneGraph, SceneNode } from '@open-pencil/scene-graph'
+import { TransformMatrix, getWorldMatrix } from '@open-pencil/scene-graph'
+
+import { encodeBase64 } from '#core/bytes'
+
+import {
+ hasUnsupportedTransform,
+ inch,
+ nodeBox,
+ nodeScale,
+ pt,
+ transformNodeVector,
+ type SlideBox
+} from './geometry'
+import { makeIsolatedRasterize } from './rasterize'
+import {
+ applyTextCase,
+ effectiveRadius,
+ firstVisibleFill,
+ firstVisibleStroke,
+ getSolidOffsetShadow,
+ hasAsymmetricCorners,
+ hex,
+ isRounded,
+ mapHAlign,
+ mapShadow,
+ mapVAlign,
+ round2,
+ transparency
+} from './style'
+import type {
+ PPTXExportOptions,
+ PPTXExportStats,
+ PPTXRasterize,
+ PPTXRasterizeOptions
+} from './types'
+
+/**
+ * Scene graph → editable PPTX hybrid conversion.
+ *
+ * Text, rectangles, ellipses and lines become native (editable) PowerPoint
+ * elements; vectors, gradients, masks and blended subtrees fall back to PNG
+ * images. Unit conversion uses exact formulas — px→inch for positions/sizes and
+ * px→pt for fonts, letter spacing, line height and stroke widths (1in = 96px =
+ * 72pt) — with no hand-tuned factors.
+ *
+ * Each requested top-level FRAME becomes one slide. Non-frame roots are
+ * exported as a single image on their own slide.
+ */
+
+const BASE_SLIDE_WIDTH_IN = 13.333
+/** Sub-pixel slack when testing whether a clipped container actually crops. */
+const CLIP_EPSILON_PX = 0.5
+const SIMPLE_BLENDS = new Set<SceneNode['blendMode']>(['NORMAL', 'PASS_THROUGH'])
+/** Node types that map to native PPT shapes. Others recurse or fall back to PNG. */
+const SHAPE_TYPES = new Set<SceneNode['type']>([
+ 'FRAME',
+ 'RECTANGLE',
+ 'ROUNDED_RECTANGLE',
+ 'ELLIPSE',
+ 'LINE'
+])
+const CONTAINER_TYPES = new Set<SceneNode['type']>(['FRAME', 'GROUP', 'SECTION'])
+
+interface ExportCtx {
+ slide: PptxGenJS.Slide
+ graph: SceneGraph
+ rasterize: PPTXRasterize
+ /** frame px → slide inch conversion factor */
+ pxPerInch: number
+ /** world → slide-frame local space, so a rotated slide frame stays upright */
+ toSlideSpace: Mat3
+ offsetX: number
+ offsetY: number
+ contentFillsSlide: boolean
+ fallbackScale: number
+ stats: PPTXExportStats
+}
+
+export async function renderNodesToPPTX(
+ graph: SceneGraph,
+ _pageId: string,
+ nodeIds: string[],
+ options: PPTXExportOptions = {}
+): Promise<Uint8Array | null> {
+ const roots = nodeIds
+ .map((id) => graph.getNode(id))
+ .filter((node): node is SceneNode => node?.visible === true)
+ if (!roots.length) return null
+
+ const { default: PptxGen } = await import('pptxgenjs')
+
+ const first = roots[0]
+ const firstWidth = Math.max(first.width, 1)
+ const firstHeight = Math.max(first.height, 1)
+ const slideW = firstWidth >= firstHeight ? BASE_SLIDE_WIDTH_IN : 7.5
+ const slideH = slideW * (firstHeight / firstWidth)
+
+ const pptx = new PptxGen()
+ pptx.defineLayout({ name: 'SCENE', width: slideW, height: slideH })
+ pptx.layout = 'SCENE'
+
+ const rasterize = options.rasterize ?? makeIsolatedRasterize(graph, options.context)
+
+ const stats: PPTXExportStats = { editable: 0, fallback: 0, skipped: 0, fallbackReasons: {} }
+
+ for (const root of roots) {
+ const rootWidth = Math.max(root.width, 1)
+ const rootHeight = Math.max(root.height, 1)
+ const inchesPerPixel = Math.min(slideW / rootWidth, slideH / rootHeight)
+ const contentWidth = rootWidth * inchesPerPixel
+ const contentHeight = rootHeight * inchesPerPixel
+ const offsetX = (slideW - contentWidth) / 2
+ const offsetY = (slideH - contentHeight) / 2
+ const slide = pptx.addSlide()
+ const ctx: ExportCtx = {
+ slide,
+ graph,
+ rasterize,
+ pxPerInch: 1 / inchesPerPixel,
+ toSlideSpace:
+ TransformMatrix.invert(getWorldMatrix(root, graph)) ?? TransformMatrix.identity(),
+ offsetX,
+ offsetY,
+ contentFillsSlide: Math.abs(offsetX) < 1e-6 && Math.abs(offsetY) < 1e-6,
+ fallbackScale: options.fallbackScale ?? 2,
+ stats
+ }
+
+ if (root.type !== 'FRAME') {
+ // Non-frame root: export as a single image on its own slide.
+ await addFallbackImage(ctx, root, root.opacity, `root node type ${root.type}`)
+ continue
+ }
+
+ const contentFallbackReason = rootContentFallbackReason(ctx, root)
+ if (contentFallbackReason) {
+ await addFallbackImage(ctx, root, root.opacity, contentFallbackReason)
+ continue
+ }
+
+ await addSlideFramePaint(ctx, root)
+
+ for (const childId of root.childIds) {
+ const child = graph.getNode(childId)
+ if (child) await walkNode(ctx, child, root.opacity)
+ }
+ }
+
+ const raw = (await pptx.write({ outputType: 'arraybuffer' })) as ArrayBuffer
+ options.onStats?.(stats)
+ return new Uint8Array(raw)
+}
+
+// ── Tree traversal ────────────────────────────────────────
+
+async function walkNode(ctx: ExportCtx, node: SceneNode, inheritedOpacity: number): Promise<void> {
+ if (!node.visible) {
+ ctx.stats.skipped += 1
+ return
+ }
+ const opacity = inheritedOpacity * node.opacity
+
+ const fallbackReason = getFallbackReason(ctx, node)
+ if (fallbackReason) {
+ await addFallbackImage(ctx, node, opacity, fallbackReason)
+ return
+ }
+
+ if (node.type === 'TEXT') {
+ addEditableText(ctx, node, opacity)
+ return
+ }
+
+ // Leaf with an image fill → native picture (movable/replaceable).
+ if (isImageLeaf(node)) {
+ await addFallbackImage(ctx, node, opacity, null)
+ ctx.stats.editable += 1
+ return
+ }
+
+ if (SHAPE_TYPES.has(node.type)) addEditableShape(ctx, node, opacity)
+
+ if (CONTAINER_TYPES.has(node.type)) {
+ for (const childId of node.childIds) {
+ const child = ctx.graph.getNode(childId)
+ if (child) await walkNode(ctx, child, opacity)
+ }
+ }
+}
+
+/**
+ * Paints the slide frame itself. A plain solid fill becomes the slide
+ * background; a stroke, corner radius or translucency still maps to a native
+ * shape covering the slide. Only paint PPTX cannot express at all is
+ * rasterized, and then *without* the frame's children — they are converted
+ * natively right after, and baking them into the image too would draw every
+ * element twice.
+ */
+async function addSlideFramePaint(ctx: ExportCtx, root: SceneNode): Promise<void> {
+ const reason = rootRasterReason(root)
+ if (reason) {
+ await addFallbackImage(ctx, root, root.opacity, reason, { paintOnly: true })
+ return
+ }
+
+ const bg = firstVisibleFill(root)
+ const plainBackground =
+ ctx.contentFillsSlide &&
+ !root.strokes.some((s) => s.visible) &&
+ !root.effects.some((e) => e.visible && e.type === 'INNER_SHADOW') &&
+ effectiveRadius(root) === 0
+ if (bg?.type === 'SOLID' && plainBackground) {
+ ctx.slide.background = {
+ color: hex(bg.color),
+ transparency: transparency(root.opacity * bg.opacity * bg.color.a)
+ }
+ return
+ }
+ addEditableShape(ctx, root, root.opacity)
+}
+
+/** Why a slide frame's content must be rasterized as one composited image. */
+function rootContentFallbackReason(ctx: ExportCtx, root: SceneNode): string | null {
+ if (
+ root.childIds.some((id) => {
+ const child = ctx.graph.getNode(id)
+ return child?.visible === true && child.isMask
+ })
+ ) {
+ return 'contains mask'
+ }
+ if (clipsOverflowingContent(ctx.graph, root)) return 'clipped content'
+ return null
+}
+
+/** Why a slide frame's own paint has to be rasterized. Null means it maps natively. */
+function rootRasterReason(root: SceneNode): string | null {
+ if (!SIMPLE_BLENDS.has(root.blendMode)) return 'blend mode'
+ // A drop shadow on the slide frame paints outside the slide, where nothing is
+ // visible — rasterizing the whole slide for it would only cost editability.
+ if (root.effects.some((e) => e.visible && e.type !== 'DROP_SHADOW' && e.type !== 'INNER_SHADOW'))
+ return 'blur effect'
+ const shadowReason = getShadowFallbackReason(root)
+ if (shadowReason) return shadowReason
+ if (hasAsymmetricCorners(root)) return 'asymmetric corners'
+ if (root.strokes.filter((stroke) => stroke.visible).length > 1) return 'multiple strokes'
+ const fills = root.fills.filter((f) => f.visible)
+ if (fills.length > 1) return 'multiple fills'
+ if (fills[0] && fills[0].type !== 'SOLID') return 'non-solid frame background'
+ return null
+}
+
+function getShadowFallbackReason(node: SceneNode): string | null {
+ const shadows = node.effects.filter(
+ (effect) => effect.visible && (effect.type === 'DROP_SHADOW' || effect.type === 'INNER_SHADOW')
+ )
+ if (shadows.length > 1) return 'multiple shadows'
+ if (shadows.length === 0) return null
+ const shadow = shadows[0]
+ if (shadow.spread !== 0 && getSolidOffsetShadow(node) !== shadow) return 'shadow spread'
+ return null
+}
+
+/** Why a node cannot be converted natively. Null means native conversion is possible. */
+function getFallbackReason(ctx: ExportCtx, node: SceneNode): string | null {
+ const commonReason = getCommonFallbackReason(ctx, node)
+ if (commonReason) return commonReason
+ if (node.type === 'TEXT') return getTextFallbackReason(node)
+ if (SHAPE_TYPES.has(node.type) || CONTAINER_TYPES.has(node.type)) {
+ return getShapeFallbackReason(node)
+ }
+ return `node type ${node.type}`
+}
+
+function getCommonFallbackReason(ctx: ExportCtx, node: SceneNode): string | null {
+ const { graph } = ctx
+ if (hasUnsupportedTransform(ctx, node)) return 'unsupported transform'
+ if (!SIMPLE_BLENDS.has(node.blendMode)) return 'blend mode'
+ if (node.effects.some((e) => e.visible && e.type !== 'DROP_SHADOW' && e.type !== 'INNER_SHADOW'))
+ return 'blur effect'
+ const shadowReason = getShadowFallbackReason(node)
+ if (shadowReason) return shadowReason
+ if (hasAsymmetricCorners(node)) return 'asymmetric corners'
+ if (node.strokes.filter((stroke) => stroke.visible).length > 1) return 'multiple strokes'
+ if (node.childIds.some((id) => graph.getNode(id)?.isMask)) return 'contains mask'
+ if (clipsOverflowingContent(graph, node)) return 'clipped content'
+ if (isVectorOnlyContainer(graph, node)) return 'vector graphics'
+ return null
+}
+
+function getTextFallbackReason(node: SceneNode): string | null {
+ const fills = node.fills.filter((fill) => fill.visible)
+ if (fills.length > 1) return 'multiple text fills'
+ if (fills[0] && fills[0].type !== 'SOLID') return 'non-solid text fill'
+ if (node.strokes.some((stroke) => stroke.visible)) return 'text stroke'
+ for (const run of node.styleRuns) {
+ const runFills = run.style.fills?.filter((fill) => fill.visible) ?? []
+ if (runFills.length > 1 || runFills.some((fill) => fill.type !== 'SOLID')) {
+ return 'unsupported text run fill'
+ }
+ }
+ return null
+}
+
+function getShapeFallbackReason(node: SceneNode): string | null {
+ const visibleFills = node.fills.filter((fill) => fill.visible)
+ if (visibleFills.some((fill) => fill.type.startsWith('GRADIENT'))) return 'gradient fill'
+ if (visibleFills.length > 1) return 'multiple fills'
+ // Image-fill leaves become native pictures at the call site; containers
+ // with an image background fall back so children stay aligned.
+ if (visibleFills.some((fill) => fill.type === 'IMAGE') && node.childIds.length > 0) {
+ return 'image background container'
+ }
+ return null
+}
+
+function isImageLeaf(node: SceneNode): boolean {
+ return node.childIds.length === 0 && node.fills.some((f) => f.visible && f.type === 'IMAGE')
+}
+
+/** True when `node` clips and some descendant actually reaches past its bounds. */
+function clipsOverflowingContent(graph: SceneGraph, node: SceneNode): boolean {
+ if (!node.clipsContent || !CONTAINER_TYPES.has(node.type)) return false
+ const toNodeSpace = TransformMatrix.invert(getWorldMatrix(node, graph))
+ if (!toNodeSpace) return false
+
+ const pending = [...node.childIds]
+ while (pending.length > 0) {
+ const childId = pending.pop()
+ const child = childId ? graph.getNode(childId) : undefined
+ if (!child?.visible) continue
+ const local = TransformMatrix.multiply(toNodeSpace, getWorldMatrix(child, graph))
+ const corners = TransformMatrix.mapPoints(local, [
+ 0,
+ 0,
+ child.width,
+ 0,
+ child.width,
+ child.height,
+ 0,
+ child.height
+ ])
+ for (let i = 0; i < corners.length; i += 2) {
+ const outsideX = corners[i] < -CLIP_EPSILON_PX || corners[i] > node.width + CLIP_EPSILON_PX
+ const outsideY =
+ corners[i + 1] < -CLIP_EPSILON_PX || corners[i + 1] > node.height + CLIP_EPSILON_PX
+ if (outsideX || outsideY) return true
+ }
+ pending.push(...child.childIds)
+ }
+ return false
+}
+
+function isVectorOnlyContainer(graph: SceneGraph, node: SceneNode): boolean {
+ if (!CONTAINER_TYPES.has(node.type)) return false
+ const children = node.childIds
+ .map((id) => graph.getNode(id))
+ .filter((child): child is SceneNode => child?.visible === true)
+ return children.length > 0 && children.every((child) => child.type === 'VECTOR')
+}
+
+// ── Native element conversion ─────────────────────────────
+
+function addEditableShape(ctx: ExportCtx, node: SceneNode, opacity: number): void {
+ const fill = firstVisibleFill(node)
+ const stroke = firstVisibleStroke(node)
+ if (!fill && !stroke) return // paintless container
+
+ const box = nodeBox(ctx, node)
+ const solidShadow = getSolidOffsetShadow(node)
+ if (solidShadow) addSolidShadowShape(ctx, node, box, opacity, solidShadow)
+ const common = {
+ x: box.x,
+ y: box.y,
+ w: box.w,
+ h: box.h,
+ rotate: box.rotate,
+ flipH: box.flipH,
+ shadow: solidShadow ? undefined : mapShadow(node, opacity),
+ fill:
+ fill?.type === 'SOLID'
+ ? {
+ color: hex(fill.color),
+ transparency: transparency(opacity * fill.opacity * fill.color.a)
+ }
+ : { color: 'FFFFFF', transparency: 100 },
+ line: stroke
+ ? {
+ color: hex(stroke.color),
+ width: pt(ctx, stroke.weight),
+ transparency: transparency(opacity * stroke.opacity * stroke.color.a),
+ dashType: (stroke.dashPattern?.length ?? 0) > 0 ? ('dash' as const) : ('solid' as const)
+ }
+ : { color: 'FFFFFF', transparency: 100, width: 0 }
+ }
+
+ if (node.type === 'LINE') {
+ const paint = stroke ?? fill
+ if (!paint) return
+ ctx.slide.addShape('line', {
+ ...common,
+ line: {
+ color: hex(paint.color),
+ width: Math.max(pt(ctx, stroke?.weight ?? node.height), 0.25),
+ transparency: transparency(opacity * paint.opacity * paint.color.a)
+ }
+ })
+ } else if (node.type === 'ELLIPSE') {
+ ctx.slide.addShape('ellipse', common)
+ } else if (isRounded(node)) {
+ const scale = nodeScale(ctx, node)
+ ctx.slide.addShape('roundRect', {
+ ...common,
+ rectRadius: Math.min(
+ inch(ctx, effectiveRadius(node) * Math.min(scale.x, scale.y)),
+ Math.min(box.w, box.h) / 2
+ )
+ })
+ } else {
+ ctx.slide.addShape('rect', common)
+ }
+ ctx.stats.editable += 1
+}
+
+function addEditableText(ctx: ExportCtx, node: SceneNode, opacity: number): void {
+ if (!node.text) {
+ ctx.stats.skipped += 1
+ return
+ }
+ const box = nodeBox(ctx, node)
+ const singleLine = node.maxLines === 1 || node.textAutoResize === 'WIDTH_AND_HEIGHT'
+
+ const runs = buildTextRuns(ctx, node, opacity)
+ ctx.slide.addText(runs, {
+ x: box.x,
+ y: box.y,
+ w: box.w,
+ h: box.h,
+ rotate: box.rotate,
+ flipH: box.flipH,
+ align: mapHAlign(node.textAlignHorizontal),
+ valign: mapVAlign(node.textAlignVertical),
+ margin: 0,
+ wrap: !singleLine,
+ // If the receiving app reflows text past the box, shrink to avoid layout
+ // breakage; otherwise this has no effect.
+ fit: 'shrink',
+ lineSpacing: node.lineHeight != null ? pt(ctx, node.lineHeight) : undefined,
+ shadow: mapShadow(node, opacity)
+ })
+ ctx.stats.editable += 1
+}
+
+/** Merges styleRuns with base style into PPT text runs (keeps partial styling editable). */
+function buildTextRuns(ctx: ExportCtx, node: SceneNode, opacity: number): PptxGenJS.TextProps[] {
+ const text = applyTextCase(node.text, node.textCase)
+
+ interface Seg {
+ start: number
+ end: number
+ style: Partial<SceneNode> & { fills?: Fill[] }
+ }
+ const segs: Seg[] = []
+ const sorted = [...node.styleRuns].sort((a, b) => a.start - b.start)
+ let cursor = 0
+ for (const run of sorted) {
+ const start = Math.max(run.start, cursor)
+ const end = Math.min(run.start + run.length, text.length)
+ if (start > cursor) segs.push({ start: cursor, end: start, style: {} })
+ if (end > start) segs.push({ start, end, style: run.style })
+ cursor = Math.max(cursor, end)
+ }
+ if (cursor < text.length) segs.push({ start: cursor, end: text.length, style: {} })
+ if (segs.length === 0) segs.push({ start: 0, end: text.length, style: {} })
+
+ const baseFill = firstVisibleFill(node)
+ return segs.map((seg) => {
+ const s = seg.style
+ const fill = s.fills?.find((f) => f.visible && f.type === 'SOLID') ?? baseFill
+ const fontSize = s.fontSize ?? node.fontSize
+ const weight = s.fontWeight ?? node.fontWeight
+ const deco = s.textDecoration ?? node.textDecoration
+ return {
+ text: text.slice(seg.start, seg.end),
+ options: {
+ fontFace: s.fontFamily ?? node.fontFamily,
+ fontSize: round2(pt(ctx, fontSize)),
+ bold: weight >= 600,
+ italic: s.italic ?? node.italic,
+ color: fill ? hex(fill.color) : '000000',
+ transparency: transparency(opacity * (fill ? fill.opacity * fill.color.a : 1)),
+ charSpacing: charSpacingPt(ctx, s.letterSpacing ?? node.letterSpacing),
+ underline: deco === 'UNDERLINE' ? { style: 'sng' as const } : undefined,
+ strike: deco === 'STRIKETHROUGH' ? ('sngStrike' as const) : undefined
+ }
+ }
+ })
+}
+
+async function addFallbackImage(
+ ctx: ExportCtx,
+ node: SceneNode,
+ opacity: number,
+ reason: string | null,
+ options?: PPTXRasterizeOptions
+): Promise<void> {
+ const data = await ctx.rasterize([node.id], ctx.fallbackScale, options)
+ if (!data) {
+ ctx.stats.skipped += 1
+ return
+ }
+ const box = nodeBox(ctx, node)
+ ctx.slide.addImage({
+ data: `data:image/png;base64,${encodeBase64(data)}`,
+ x: box.x,
+ y: box.y,
+ w: box.w,
+ h: box.h,
+ rotate: box.rotate,
+ flipH: box.flipH,
+ transparency: transparency(opacity)
+ })
+ if (reason) {
+ ctx.stats.fallback += 1
+ ctx.stats.fallbackReasons[reason] = (ctx.stats.fallbackReasons[reason] ?? 0) + 1
+ }
+}
+
+// ── Unit and style mapping (exact formulas, no hand tuning) ──
+
+/** letterSpacing px → PPT charSpacing (pt). Zero is omitted (default). */
+function charSpacingPt(ctx: ExportCtx, px: number): number | undefined {
+ if (!px) return undefined
+ return round2(pt(ctx, px))
+}
+
+/**
+ * Solid offset shadows (blur 0) cannot be represented crisply with PPT shadow
+ * properties (viewers render them soft), so draw a same-shaped solid shape at
+ * the offset position instead.
+ */
+function addSolidShadowShape(
+ ctx: ExportCtx,
+ node: SceneNode,
+ box: SlideBox,
+ opacity: number,
+ shadow: NonNullable<ReturnType<typeof getSolidOffsetShadow>>
+): void {
+ const sp = shadow.spread
+ const offset = transformNodeVector(ctx, node, shadow.offset)
+ const scale = nodeScale(ctx, node)
+ const spreadX = inch(ctx, sp * scale.x)
+ const spreadY = inch(ctx, sp * scale.y)
+ let shapeType: 'roundRect' | 'ellipse' | 'rect' = 'rect'
+ if (isRounded(node)) shapeType = 'roundRect'
+ else if (node.type === 'ELLIPSE') shapeType = 'ellipse'
+ ctx.slide.addShape(shapeType, {
+ x: box.x + offset.x - spreadX,
+ y: box.y + offset.y - spreadY,
+ w: box.w + spreadX * 2,
+ h: box.h + spreadY * 2,
+ rotate: box.rotate,
+ flipH: box.flipH,
+ fill: {
+ color: hex(shadow.color),
+ transparency: transparency(opacity * shadow.color.a)
+ },
+ line: { color: 'FFFFFF', transparency: 100, width: 0 },
+ ...(shapeType === 'roundRect'
+ ? {
+ rectRadius: Math.min(
+ inch(ctx, effectiveRadius(node) * Math.min(scale.x, scale.y)),
+ Math.min(box.w, box.h) / 2
+ )
+ }
+ : {})
+ })
+}
diff --git a/packages/core/src/io/formats/pptx/geometry.ts b/packages/core/src/io/formats/pptx/geometry.ts
new file mode 100644
index 000000000..bd170ddc3
--- /dev/null
+++ b/packages/core/src/io/formats/pptx/geometry.ts
@@ -0,0 +1,99 @@
+import type { Mat3, SceneGraph, SceneNode, Vector } from '@open-pencil/scene-graph'
+import { TransformMatrix, getWorldMatrix } from '@open-pencil/scene-graph'
+
+import { clampRot, round2 } from './style'
+
+const MIN_SIZE_IN = 0.01
+const MATRIX_EPSILON = 1e-6
+
+export interface PPTXGeometryContext {
+ graph: SceneGraph
+ pxPerInch: number
+ toSlideSpace: Mat3
+ offsetX: number
+ offsetY: number
+}
+
+export interface SlideBox {
+ x: number
+ y: number
+ w: number
+ h: number
+ rotate: number
+ flipH: boolean
+}
+
+interface NodeTransform {
+ matrix: Mat3
+ scaleX: number
+ scaleY: number
+ mirrored: boolean
+ radians: number
+}
+
+export function inch(ctx: PPTXGeometryContext, px: number): number {
+ return px / ctx.pxPerInch
+}
+
+/** px → pt. 1in = 96px (scene units) = 72pt. */
+export function pt(ctx: PPTXGeometryContext, px: number): number {
+ return (px * 72) / ctx.pxPerInch
+}
+
+export function nodeBox(ctx: PPTXGeometryContext, node: SceneNode): SlideBox {
+ const transform = getNodeTransform(ctx, node)
+ const [centerX, centerY] = TransformMatrix.mapPoints(transform.matrix, [
+ node.width / 2,
+ node.height / 2
+ ])
+ const w = Math.max(inch(ctx, node.width * transform.scaleX), MIN_SIZE_IN)
+ const h = Math.max(inch(ctx, node.height * transform.scaleY), MIN_SIZE_IN)
+ return {
+ x: ctx.offsetX + inch(ctx, centerX) - w / 2,
+ y: ctx.offsetY + inch(ctx, centerY) - h / 2,
+ w,
+ h,
+ rotate: clampRot(round2((transform.radians * 180) / Math.PI)),
+ flipH: transform.mirrored
+ }
+}
+
+export function hasUnsupportedTransform(ctx: PPTXGeometryContext, node: SceneNode): boolean {
+ const { matrix, scaleX, scaleY } = getNodeTransform(ctx, node)
+ if (scaleX <= MATRIX_EPSILON || scaleY <= MATRIX_EPSILON) return true
+ if (
+ Math.abs(matrix[6]) > MATRIX_EPSILON ||
+ Math.abs(matrix[7]) > MATRIX_EPSILON ||
+ Math.abs(matrix[8] - 1) > MATRIX_EPSILON
+ ) {
+ return true
+ }
+ const basisDot = matrix[0] * matrix[1] + matrix[3] * matrix[4]
+ return Math.abs(basisDot) > MATRIX_EPSILON * scaleX * scaleY
+}
+
+export function transformNodeVector(
+ ctx: PPTXGeometryContext,
+ node: SceneNode,
+ vector: Vector
+): Vector {
+ const { matrix } = getNodeTransform(ctx, node)
+ return {
+ x: inch(ctx, matrix[0] * vector.x + matrix[1] * vector.y),
+ y: inch(ctx, matrix[3] * vector.x + matrix[4] * vector.y)
+ }
+}
+
+export function nodeScale(ctx: PPTXGeometryContext, node: SceneNode): Vector {
+ const { scaleX, scaleY } = getNodeTransform(ctx, node)
+ return { x: scaleX, y: scaleY }
+}
+
+function getNodeTransform(ctx: PPTXGeometryContext, node: SceneNode): NodeTransform {
+ const matrix = TransformMatrix.multiply(ctx.toSlideSpace, getWorldMatrix(node, ctx.graph))
+ const scaleX = Math.hypot(matrix[0], matrix[3])
+ const scaleY = Math.hypot(matrix[1], matrix[4])
+ const mirrored = matrix[0] * matrix[4] - matrix[1] * matrix[3] < 0
+ const radians = mirrored ? Math.atan2(-matrix[3], matrix[4]) : Math.atan2(matrix[3], matrix[0])
+ return { matrix, scaleX, scaleY, mirrored, radians }
+}
diff --git a/packages/core/src/io/formats/pptx/index.ts b/packages/core/src/io/formats/pptx/index.ts
new file mode 100644
index 000000000..5226d9788
--- /dev/null
+++ b/packages/core/src/io/formats/pptx/index.ts
@@ -0,0 +1,7 @@
+export { renderNodesToPPTX } from './export'
+export type {
+ PPTXExportOptions,
+ PPTXExportStats,
+ PPTXRasterize,
+ PPTXRasterizeOptions
+} from './types'
diff --git a/packages/core/src/io/formats/pptx/rasterize.ts b/packages/core/src/io/formats/pptx/rasterize.ts
new file mode 100644
index 000000000..f8aaac138
--- /dev/null
+++ b/packages/core/src/io/formats/pptx/rasterize.ts
@@ -0,0 +1,56 @@
+import type { SceneGraph } from '@open-pencil/scene-graph'
+
+import { extractExportGraph } from '#core/io/subgraph'
+
+import type { PPTXExportOptions, PPTXRasterize } from './types'
+
+/** Builds a rasterizer that keeps fallback subtrees transparent and isolated. */
+export function makeIsolatedRasterize(
+ graph: SceneGraph,
+ context?: PPTXExportOptions['context']
+): PPTXRasterize {
+ return async (nodeIds, scale, options) => {
+ const extracted = extractExportGraph(graph, { scope: 'selection', nodeIds })
+ if (!extracted.pageId || extracted.nodeIds.length === 0) return null
+
+ if (options?.paintOnly) {
+ // The extracted graph is a copy, so detaching the children only affects
+ // this render — the renderer walks the tree through childIds.
+ for (const nodeId of extracted.nodeIds) {
+ const node = extracted.graph.getNode(nodeId)
+ if (node) node.childIds = []
+ }
+ }
+
+ const targets = new Set(extracted.nodeIds)
+ for (const nodeId of extracted.nodeIds) {
+ let cursor = extracted.graph.getNode(nodeId)?.parentId ?? null
+ while (cursor) {
+ const ancestor = extracted.graph.getNode(cursor)
+ if (!ancestor || targets.has(ancestor.id)) break
+ ancestor.fills = []
+ ancestor.strokes = []
+ ancestor.effects = []
+ cursor = ancestor.parentId
+ }
+ }
+
+ const raster = await import('#core/io/formats/raster')
+ const ck = context?.canvasKit
+ const renderer = context?.renderer
+ if (ck && renderer) {
+ return raster.renderNodesToImage(
+ ck,
+ renderer,
+ extracted.graph,
+ extracted.pageId,
+ extracted.nodeIds,
+ { scale, format: 'PNG' }
+ )
+ }
+ return raster.headlessRenderNodes(extracted.graph, extracted.pageId, extracted.nodeIds, {
+ scale,
+ format: 'PNG'
+ })
+ }
+}
diff --git a/packages/core/src/io/formats/pptx/style.ts b/packages/core/src/io/formats/pptx/style.ts
new file mode 100644
index 000000000..67ce7e6a6
--- /dev/null
+++ b/packages/core/src/io/formats/pptx/style.ts
@@ -0,0 +1,101 @@
+import type PptxGenJS from 'pptxgenjs'
+
+import type { Color, Fill, SceneNode, Stroke } from '@open-pencil/scene-graph'
+
+import { colorToHex } from '#core/color'
+
+/** Scene paint/effect/text style → PPT property mapping (no slide geometry). */
+
+export function firstVisibleFill(node: SceneNode): Fill | null {
+ return node.fills.find((f) => f.visible) ?? null
+}
+
+export function firstVisibleStroke(node: SceneNode): Stroke | null {
+ return node.strokes.find((s) => s.visible) ?? null
+}
+
+export function isRounded(node: SceneNode): boolean {
+ return effectiveRadius(node) > 0
+}
+
+export function hasAsymmetricCorners(node: SceneNode): boolean {
+ if (!node.independentCorners) return false
+ const radii = [
+ node.topLeftRadius,
+ node.topRightRadius,
+ node.bottomRightRadius,
+ node.bottomLeftRadius
+ ]
+ return radii.some((radius) => Math.abs(radius - radii[0]) > 1e-6)
+}
+
+export function effectiveRadius(node: SceneNode): number {
+ return node.independentCorners ? node.topLeftRadius : node.cornerRadius
+}
+
+/** DROP_SHADOW without blur (design-system solid offset shadow) — drawn as a separate shape. */
+export function getSolidOffsetShadow(node: SceneNode) {
+ const e = node.effects.find((fx) => fx.visible && fx.type === 'DROP_SHADOW')
+ if (!e) return null
+ if (e.radius > 1) return null
+ if (Math.abs(e.offset.x) < 0.5 && Math.abs(e.offset.y) < 0.5 && e.spread <= 0) return null
+ return e
+}
+
+export function mapShadow(node: SceneNode, opacity: number): PptxGenJS.ShadowProps | undefined {
+ const e = node.effects.find(
+ (fx) => fx.visible && (fx.type === 'DROP_SHADOW' || fx.type === 'INNER_SHADOW')
+ )
+ if (!e) return undefined
+ const angleRaw = (Math.atan2(e.offset.y, e.offset.x) * 180) / Math.PI
+ return {
+ type: e.type === 'INNER_SHADOW' ? 'inner' : 'outer',
+ color: hex(e.color),
+ opacity: clamp01(e.color.a * opacity),
+ blur: Math.min(Math.max(e.radius, 0), 100),
+ offset: Math.min(Math.hypot(e.offset.x, e.offset.y), 200),
+ angle: angleRaw < 0 ? angleRaw + 360 : angleRaw
+ }
+}
+
+export function mapHAlign(
+ a: SceneNode['textAlignHorizontal']
+): 'left' | 'center' | 'right' | 'justify' {
+ if (a === 'CENTER') return 'center'
+ if (a === 'RIGHT') return 'right'
+ if (a === 'JUSTIFIED') return 'justify'
+ return 'left'
+}
+
+export function mapVAlign(a: SceneNode['textAlignVertical']): 'top' | 'middle' | 'bottom' {
+ if (a === 'CENTER') return 'middle'
+ if (a === 'BOTTOM') return 'bottom'
+ return 'top'
+}
+
+export function applyTextCase(text: string, textCase: SceneNode['textCase']): string {
+ if (textCase === 'UPPER') return text.toUpperCase()
+ if (textCase === 'LOWER') return text.toLowerCase()
+ if (textCase === 'TITLE') return text.replace(/\b\w/g, (c) => c.toUpperCase())
+ return text
+}
+
+export function hex(color: Color): string {
+ return colorToHex(color).replace('#', '').slice(0, 6)
+}
+
+export function transparency(alpha: number): number {
+ return Math.min(Math.max(Math.round((1 - clamp01(alpha)) * 100), 0), 100)
+}
+
+export function clamp01(v: number): number {
+ return Math.min(Math.max(v, 0), 1)
+}
+
+export function clampRot(deg: number): number {
+ return Math.min(Math.max(deg, -360), 360)
+}
+
+export function round2(v: number): number {
+ return Math.round(v * 100) / 100
+}
diff --git a/packages/core/src/io/formats/pptx/types.ts b/packages/core/src/io/formats/pptx/types.ts
new file mode 100644
index 000000000..4b7eb4be1
--- /dev/null
+++ b/packages/core/src/io/formats/pptx/types.ts
@@ -0,0 +1,38 @@
+import type { CanvasKit } from 'canvaskit-wasm'
+
+import type { SkiaRenderer } from '#core/canvas'
+
+export interface PPTXExportStats {
+ editable: number
+ fallback: number
+ skipped: number
+ /** Fallback reason → count, for fidelity measurement. */
+ fallbackReasons: Record<string, number>
+}
+
+export interface PPTXRasterizeOptions {
+ /** Render only the nodes' own paint, dropping their children. */
+ paintOnly?: boolean
+}
+
+/** Renders the given nodes to a PNG byte array (used for fallback images). */
+export type PPTXRasterize = (
+ nodeIds: string[],
+ scale: number,
+ options?: PPTXRasterizeOptions
+) => Promise<Uint8Array | null>
+
+export interface PPTXExportOptions {
+ /** Raster scale for fallback images. Defaults to 2. */
+ fallbackScale?: number
+ /**
+ * Custom rasterizer for fallback images. Defaults to an isolated render of
+ * the node subtree (ancestor backgrounds cleared) through the raster
+ * pipeline — headless, or renderer-bound when `context` provides one.
+ */
+ rasterize?: PPTXRasterize
+ /** Live renderer to reuse for fallback rasterization (browser contexts). */
+ context?: { canvasKit?: CanvasKit; renderer?: SkiaRenderer }
+ /** Receives conversion statistics after the export completes. */
+ onStats?: (stats: PPTXExportStats) => void
+}
diff --git a/packages/core/src/io/index.ts b/packages/core/src/io/index.ts
index e4119094b..e74dc8a6d 100644
--- a/packages/core/src/io/index.ts
+++ b/packages/core/src/io/index.ts
@@ -24,6 +24,12 @@ export {
type ExportFormat
} from './formats/raster'
export { renderNodesToSVG, geometryBlobToSVGPath, vectorNetworkToSVGPaths } from './formats/svg'
+export {
+ renderNodesToPPTX,
+ type PPTXExportOptions,
+ type PPTXExportStats,
+ type PPTXRasterize
+} from './formats/pptx'
export type {
IOFormatRole,
IOFormatCategory,
diff --git a/packages/scene-graph/src/index.ts b/packages/scene-graph/src/index.ts
index 623bc59ef..03241b2ac 100644
--- a/packages/scene-graph/src/index.ts
+++ b/packages/scene-graph/src/index.ts
@@ -28,7 +28,7 @@ import { TEXT_PICTURE_KEYS } from './text-picture'
import * as Variables from './variables'
import { normalizeVectorNetwork } from './vector-network'
-export type { GUID, Color } from './primitives'
+export type { GUID, Color, Vector } from './primitives'
export * from './types'
import type { Emitter } from 'nanoevents'
diff --git a/src/app/document/export/create.ts b/src/app/document/export/create.ts
index 90e75fea6..ca7e4a7b6 100644
--- a/src/app/document/export/create.ts
+++ b/src/app/document/export/create.ts
@@ -105,7 +105,7 @@ export function createDocumentExportActions(
async function exportSelection(
scale: number,
- formatId: 'png' | 'jpg' | 'webp' | 'svg' | 'pdf' | 'fig'
+ formatId: 'png' | 'jpg' | 'webp' | 'svg' | 'pdf' | 'pptx' | 'fig'
) {
await exportTarget(getSelectionExportTarget(), formatId, { scale })
}
diff --git a/src/app/shell/menu/app-menu.ts b/src/app/shell/menu/app-menu.ts
index 90b8bfa0b..3d89d6bc2 100644
--- a/src/app/shell/menu/app-menu.ts
+++ b/src/app/shell/menu/app-menu.ts
@@ -73,7 +73,7 @@ export function useAppMenu() {
}))
)
- function exportSelection(format: 'png' | 'svg' | 'fig') {
+ function exportSelection(format: 'png' | 'svg' | 'pptx' | 'fig') {
if (store.state.selectedIds.size > 0) void store.exportSelection(1, format)
}
@@ -90,6 +90,7 @@ export function useAppMenu() {
paste: () => void executeClipboardCommand(store, 'paste'),
'export-png': () => exportSelection('png'),
'export-svg': () => exportSelection('svg'),
+ 'export-pptx': () => exportSelection('pptx'),
'export-fig': () => exportSelection('fig'),
...createSharedEditorMenuActions(setTheme)
}
diff --git a/src/app/shell/menu/schema.ts b/src/app/shell/menu/schema.ts
index cb540c077..80c864112 100644
--- a/src/app/shell/menu/schema.ts
+++ b/src/app/shell/menu/schema.ts
@@ -44,6 +44,7 @@ export const APP_MENU_SCHEMA = [
sub: [
{ id: 'export-png', label: 'PNG' },
{ id: 'export-svg', label: 'SVG' },
+ { id: 'export-pptx', label: 'PPTX' },
{ id: 'export-fig', label: '.fig' }
]
},
diff --git a/tests/engine/cli/export.test.ts b/tests/engine/cli/export.test.ts
index 226e60ea3..0a2c8bdcc 100644
--- a/tests/engine/cli/export.test.ts
+++ b/tests/engine/cli/export.test.ts
@@ -3,6 +3,8 @@ import { mkdtemp } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
+import { unzipSync } from 'fflate'
+
import { BUILTIN_IO_FORMATS, IORegistry } from '@open-pencil/core/io'
import { runOpenPencilCLI } from '#tests/helpers/cli'
@@ -16,7 +18,12 @@ async function createFigFixture() {
const dir = await mkdtemp(join(tmpdir(), 'open-pencil-export-cli-'))
const figPath = join(dir, 'card.fig')
const graph = makeSceneGraph('Export Page')
- const rect = createRect(graph, firstPageId(graph), {
+ const firstFrame = graph.createNode('FRAME', firstPageId(graph), {
+ name: 'First slide',
+ width: 1280,
+ height: 720
+ })
+ const rect = createRect(graph, firstFrame.id, {
name: 'Export Card',
x: 0,
y: 0,
@@ -32,7 +39,12 @@ async function createFigFixture() {
rect.fills = [{ type: 'SOLID', color: { r: 1, g: 1, b: 1, a: 1 } }]
const secondPage = graph.addPage('Second Page')
- createRect(graph, secondPage.id, {
+ const secondFrame = graph.createNode('FRAME', secondPage.id, {
+ name: 'Second slide',
+ width: 1280,
+ height: 720
+ })
+ createRect(graph, secondFrame.id, {
name: 'Second Card',
x: 0,
y: 0,
@@ -70,6 +82,29 @@ test('FIG export preserves the whole document by default', async () => {
expect(graph.getPages().map((page) => page.name)).toContain('Second Page')
})
+test('PPTX export includes slides from every page by default', async () => {
+ const { dir, figPath } = await createFigFixture()
+ const output = join(dir, 'whole.pptx')
+
+ const { stdout, stderr, exitCode } = await runOpenPencilCLI([
+ 'export',
+ figPath,
+ '--format',
+ 'pptx',
+ '--output',
+ output
+ ])
+
+ expect(stderr).toBe('')
+ expect(exitCode).toBe(0)
+ expect(stdout).toContain('Target: whole document')
+
+ const files = unzipSync(new Uint8Array(await Bun.file(output).arrayBuffer()))
+ expect(files['ppt/slides/slide1.xml']).toBeDefined()
+ expect(files['ppt/slides/slide2.xml']).toBeDefined()
+ expect(files['ppt/slides/slide3.xml']).toBeUndefined()
+})
+
test('FIG export requires an explicit page for a partial archive', async () => {
const { dir, figPath } = await createFigFixture()
const output = join(dir, 'page.fig')
diff --git a/tests/engine/io/pptx/export/fidelity.test.ts b/tests/engine/io/pptx/export/fidelity.test.ts
new file mode 100644
index 000000000..7caff6cf3
--- /dev/null
+++ b/tests/engine/io/pptx/export/fidelity.test.ts
@@ -0,0 +1,166 @@
+import { describe, expect, test } from 'bun:test'
+
+import { renderNodesToPPTX, type Effect, type PPTXExportStats } from '@open-pencil/core'
+import { TransformMatrix } from '@open-pencil/scene-graph'
+
+import { hasUnsupportedTransform, nodeBox } from '#core/io/formats/pptx/geometry'
+
+import {
+ TINY_PNG,
+ inches,
+ makeGraph,
+ makeSlideFrame,
+ pageId,
+ placements,
+ slideXml,
+ solidFill,
+ solidStroke,
+ stubRasterize,
+ unzipPptx
+} from './helpers'
+
+function shadow(overrides: Partial<Effect> = {}): Effect {
+ return {
+ type: 'DROP_SHADOW',
+ color: { r: 0, g: 0, b: 0, a: 1 },
+ offset: { x: 8, y: 8 },
+ radius: 8,
+ spread: 0,
+ visible: true,
+ ...overrides
+ }
+}
+
+describe('PPTX fidelity fallbacks', () => {
+ test('fits later frames with different dimensions into the deck layout', async () => {
+ const graph = makeGraph()
+ const first = makeSlideFrame(graph, 'Wide')
+ const square = graph.createNode('FRAME', pageId(graph), {
+ width: 1000,
+ height: 1000,
+ fills: [solidFill(1, 0, 0)]
+ })
+
+ const data = await renderNodesToPPTX(graph, pageId(graph), [first.id, square.id], {
+ rasterize: stubRasterize
+ })
+ expect(data).not.toBeNull()
+ if (!data) return
+ const [frame] = placements(slideXml(unzipPptx(data), 2))
+ expect(frame.width).toBeCloseTo(7.5, 2)
+ expect(frame.height).toBeCloseTo(7.5, 2)
+ expect(frame.centerX).toBeCloseTo(13.333 / 2, 2)
+ expect(frame.centerY).toBeCloseTo(7.5 / 2, 2)
+ })
+
+ test('rasterizes asymmetric corners and multiple shadow effects', async () => {
+ const graph = makeGraph()
+ const frame = makeSlideFrame(graph, 'Slide')
+ const corners = graph.createNode('RECTANGLE', frame.id, {
+ width: 100,
+ height: 100,
+ independentCorners: true,
+ topLeftRadius: 20,
+ topRightRadius: 0,
+ bottomRightRadius: 0,
+ bottomLeftRadius: 0,
+ fills: [solidFill(1, 0, 0)]
+ })
+ const shadows = graph.createNode('RECTANGLE', frame.id, {
+ x: 200,
+ width: 100,
+ height: 100,
+ fills: [solidFill(0, 0, 1)],
+ effects: [shadow(), shadow({ offset: { x: -8, y: 8 } })]
+ })
+ const calls: string[][] = []
+ let stats: PPTXExportStats | null = null
+
+ await renderNodesToPPTX(graph, pageId(graph), [frame.id], {
+ rasterize: (ids) => {
+ calls.push(ids)
+ return Promise.resolve(TINY_PNG)
+ },
+ onStats: (value) => {
+ stats = value
+ }
+ })
+
+ expect(calls).toEqual([[corners.id], [shadows.id]])
+ expect(stats?.fallbackReasons).toEqual({ 'asymmetric corners': 1, 'multiple shadows': 1 })
+ })
+
+ test('rotates solid shadow offsets with their shape', async () => {
+ const graph = makeGraph()
+ const frame = makeSlideFrame(graph, 'Slide')
+ graph.createNode('RECTANGLE', frame.id, {
+ x: 300,
+ y: 200,
+ width: 100,
+ height: 50,
+ rotation: 90,
+ fills: [solidFill(1, 0, 0)],
+ effects: [shadow({ offset: { x: 10, y: 0 }, radius: 0 })]
+ })
+
+ const data = await renderNodesToPPTX(graph, pageId(graph), [frame.id], {
+ rasterize: stubRasterize
+ })
+ expect(data).not.toBeNull()
+ if (!data) return
+ const [shadowShape, shape] = placements(slideXml(unzipPptx(data), 1))
+ expect(shadowShape.centerX).toBeCloseTo(shape.centerX, 3)
+ expect(shadowShape.centerY - shape.centerY).toBeCloseTo(inches(10), 3)
+ })
+
+ test('preserves scale and rejects skew in decomposed transforms', () => {
+ const graph = makeGraph()
+ const node = graph.createNode('RECTANGLE', pageId(graph), {
+ width: 100,
+ height: 50,
+ fills: [solidFill(1, 0, 0)]
+ })
+ const base = {
+ graph,
+ pxPerInch: 100,
+ offsetX: 0,
+ offsetY: 0,
+ toSlideSpace: TransformMatrix.scaled(2, 3)
+ }
+ const box = nodeBox(base, node)
+ expect(box.w).toBeCloseTo(2)
+ expect(box.h).toBeCloseTo(1.5)
+ expect(hasUnsupportedTransform(base, node)).toBeFalse()
+ expect(
+ hasUnsupportedTransform({ ...base, toSlideSpace: [1, 0.5, 0, 0, 1, 0, 0, 0, 1] }, node)
+ ).toBeTrue()
+ })
+
+ test('rasterizes native styles that would otherwise be silently dropped', async () => {
+ const graph = makeGraph()
+ const frame = makeSlideFrame(graph, 'Slide')
+ const multipleStrokes = graph.createNode('RECTANGLE', frame.id, {
+ width: 100,
+ height: 100,
+ fills: [solidFill(1, 1, 1)],
+ strokes: [solidStroke(1, 0, 0), solidStroke(0, 0, 1)]
+ })
+ const spreadShadow = graph.createNode('RECTANGLE', frame.id, {
+ x: 200,
+ width: 100,
+ height: 100,
+ fills: [solidFill(1, 1, 1)],
+ effects: [shadow({ spread: 4 })]
+ })
+ const calls: string[][] = []
+
+ await renderNodesToPPTX(graph, pageId(graph), [frame.id], {
+ rasterize: (ids) => {
+ calls.push(ids)
+ return Promise.resolve(TINY_PNG)
+ }
+ })
+
+ expect(calls).toEqual([[multipleStrokes.id], [spreadShadow.id]])
+ })
+})
diff --git a/tests/engine/io/pptx/export/helpers.ts b/tests/engine/io/pptx/export/helpers.ts
new file mode 100644
index 000000000..08f78bdb3
--- /dev/null
+++ b/tests/engine/io/pptx/export/helpers.ts
@@ -0,0 +1,82 @@
+import { expect } from 'bun:test'
+
+import { unzipSync } from 'fflate'
+
+import { decodeBase64 } from '@open-pencil/core/bytes'
+import type { Fill, Stroke } from '@open-pencil/scene-graph'
+import { SceneGraph } from '@open-pencil/scene-graph'
+
+// 1x1 transparent PNG — stub rasterizer output so unit tests avoid CanvasKit.
+export const TINY_PNG = decodeBase64(
+ 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg=='
+)
+
+export const stubRasterize = () => Promise.resolve(TINY_PNG)
+
+export function makeGraph(): SceneGraph {
+ return new SceneGraph()
+}
+
+export function solidFill(r: number, g: number, b: number, a = 1): Fill {
+ return { type: 'SOLID', color: { r, g, b, a }, opacity: 1, visible: true }
+}
+
+export function solidStroke(r: number, g: number, b: number, a = 1, weight = 2): Stroke {
+ return { color: { r, g, b, a }, weight, opacity: 1, visible: true, align: 'CENTER' }
+}
+
+export function pageId(graph: SceneGraph): string {
+ return graph.getPages()[0].id
+}
+
+export function makeSlideFrame(graph: SceneGraph, name: string) {
+ return graph.createNode('FRAME', pageId(graph), {
+ name,
+ width: 1280,
+ height: 720,
+ fills: [solidFill(1, 1, 1)]
+ })
+}
+
+export function unzipPptx(data: Uint8Array): Record<string, Uint8Array> {
+ return unzipSync(data)
+}
+
+export function slideXml(files: Record<string, Uint8Array>, index: number): string {
+ const entry = files[`ppt/slides/slide${index}.xml`]
+ expect(entry).toBeDefined()
+ return new TextDecoder().decode(entry)
+}
+
+export const EMU_PER_INCH = 914400
+export const SLIDE_WIDTH_IN = 13.333
+
+/** Slide frames in these tests are 1280px wide, so px → in uses that scale. */
+export function inches(px: number): number {
+ return px / (1280 / SLIDE_WIDTH_IN)
+}
+
+export interface Placement {
+ /** degrees, clockwise */
+ rot: number
+ centerX: number
+ centerY: number
+ width: number
+ height: number
+}
+
+/** Element placements (inches) read back from the slide XML. */
+export function placements(xml: string): Placement[] {
+ const pattern =
+ /<a:xfrm(?: rot="(-?\d+)")?><a:off x="(-?\d+)" y="(-?\d+)"\/><a:ext cx="(-?\d+)" cy="(-?\d+)"\/><\/a:xfrm>/g
+ return [...xml.matchAll(pattern)].map((match) => {
+ const [x, y, width, height] = match.slice(2).map((value) => Number(value) / EMU_PER_INCH)
+ return {
+ rot: Number(match[1] ?? 0) / 60000,
+ centerX: x + width / 2,
+ centerY: y + height / 2,
+ width,
+ height
+ }
+ })
+}
diff --git a/tests/engine/io/pptx/export/render.test.ts b/tests/engine/io/pptx/export/render.test.ts
new file mode 100644
index 000000000..d14b970b4
--- /dev/null
+++ b/tests/engine/io/pptx/export/render.test.ts
@@ -0,0 +1,545 @@
+import { describe, expect, test } from 'bun:test'
+
+import { renderNodesToPPTX, type PPTXExportStats } from '@open-pencil/core'
+import { BUILTIN_IO_FORMATS } from '@open-pencil/core/io'
+
+import {
+ SLIDE_WIDTH_IN,
+ TINY_PNG,
+ inches,
+ makeGraph,
+ makeSlideFrame,
+ pageId,
+ placements,
+ slideXml,
+ solidFill,
+ solidStroke,
+ stubRasterize,
+ unzipPptx
+} from './helpers'
+
+describe('renderNodesToPPTX()', () => {
+ test('returns null for empty or hidden selection', async () => {
+ const graph = makeGraph()
+ expect(
+ await renderNodesToPPTX(graph, pageId(graph), [], { rasterize: stubRasterize })
+ ).toBeNull()
+
+ const hidden = graph.createNode('FRAME', pageId(graph), {
+ width: 100,
+ height: 100,
+ visible: false
+ })
+ expect(
+ await renderNodesToPPTX(graph, pageId(graph), [hidden.id], { rasterize: stubRasterize })
+ ).toBeNull()
+ })
+
+ test('one slide per top-level frame', async () => {
+ const graph = makeGraph()
+ const a = makeSlideFrame(graph, 'Slide A')
+ const b = makeSlideFrame(graph, 'Slide B')
+ const data = await renderNodesToPPTX(graph, pageId(graph), [a.id, b.id], {
+ rasterize: stubRasterize
+ })
+ expect(data).not.toBeNull()
+ if (!data) return
+ const files = unzipPptx(data)
+ expect(files['ppt/presentation.xml']).toBeDefined()
+ expect(files['ppt/slides/slide1.xml']).toBeDefined()
+ expect(files['ppt/slides/slide2.xml']).toBeDefined()
+ expect(files['ppt/slides/slide3.xml']).toBeUndefined()
+ })
+
+ test('text becomes a native run with styles preserved', async () => {
+ const graph = makeGraph()
+ const frame = makeSlideFrame(graph, 'Slide')
+ graph.createNode('TEXT', frame.id, {
+ text: 'Hello PPTX',
+ width: 400,
+ height: 60,
+ x: 100,
+ y: 100,
+ fontSize: 32,
+ fontFamily: 'Inter',
+ fills: [{ type: 'SOLID', color: { r: 1, g: 0, b: 0, a: 1 }, opacity: 1, visible: true }],
+ styleRuns: [{ start: 0, length: 5, style: { fontWeight: 700 } }]
+ })
+ const data = await renderNodesToPPTX(graph, pageId(graph), [frame.id], {
+ rasterize: stubRasterize
+ })
+ expect(data).not.toBeNull()
+ if (!data) return
+ const xml = slideXml(unzipPptx(data), 1)
+ expect(xml).toContain('Hello')
+ expect(xml).toContain('PPTX')
+ // Bold partial run survives as its own <a:r> with b="1".
+ expect(xml).toContain('b="1"')
+ expect(xml).toContain('FF0000')
+ expect(xml).toContain('Inter')
+ })
+
+ test('solid shapes become native shapes, gradients fall back to images', async () => {
+ const graph = makeGraph()
+ const frame = makeSlideFrame(graph, 'Slide')
+ graph.createNode('RECTANGLE', frame.id, {
+ width: 200,
+ height: 100,
+ x: 40,
+ y: 40,
+ fills: [{ type: 'SOLID', color: { r: 0, g: 0, b: 1, a: 1 }, opacity: 1, visible: true }]
+ })
+ graph.createNode('RECTANGLE', frame.id, {
+ width: 200,
+ height: 100,
+ x: 40,
+ y: 200,
+ fills: [
+ {
+ type: 'GRADIENT_LINEAR',
+ color: { r: 0, g: 0, b: 0, a: 1 },
+ opacity: 1,
+ visible: true,
+ gradientStops: [
+ { position: 0, color: { r: 1, g: 0, b: 0, a: 1 } },
+ { position: 1, color: { r: 0, g: 0, b: 1, a: 1 } }
+ ]
+ }
+ ]
+ })
+
+ let stats: PPTXExportStats | null = null
+ const data = await renderNodesToPPTX(graph, pageId(graph), [frame.id], {
+ rasterize: stubRasterize,
+ onStats: (s) => {
+ stats = s
+ }
+ })
+ expect(data).not.toBeNull()
+ if (!data) return
+ const files = unzipPptx(data)
+ const xml = slideXml(files, 1)
+ expect(xml).toContain('0000FF')
+ // Gradient rect got rasterized into a media image.
+ const media = Object.keys(files).filter((f) => f.startsWith('ppt/media/') && !f.endsWith('/'))
+ expect(media.length).toBeGreaterThan(0)
+ expect(stats).not.toBeNull()
+ if (!stats) return
+ const reported: PPTXExportStats = stats
+ expect(reported.editable).toBeGreaterThan(0)
+ expect(reported.fallback).toBe(1)
+ expect(reported.fallbackReasons['gradient fill']).toBe(1)
+ })
+
+ test('vector-only container (icon) rasterizes as one image, not per path', async () => {
+ const graph = makeGraph()
+ const frame = makeSlideFrame(graph, 'Slide')
+ const iconFrame = graph.createNode('FRAME', frame.id, {
+ name: 'Icon / lucide:heart',
+ x: 40,
+ y: 40,
+ width: 48,
+ height: 48,
+ fills: []
+ })
+ for (let i = 0; i < 3; i++) {
+ graph.createNode('VECTOR', iconFrame.id, {
+ name: 'path',
+ width: 48,
+ height: 48,
+ fills: [{ type: 'SOLID', color: { r: 1, g: 0, b: 0, a: 1 }, opacity: 1, visible: true }]
+ })
+ }
+
+ let stats: PPTXExportStats | null = null
+ const rasterCalls: string[][] = []
+ const data = await renderNodesToPPTX(graph, pageId(graph), [frame.id], {
+ rasterize: (ids) => {
+ rasterCalls.push(ids)
+ return Promise.resolve(TINY_PNG)
+ },
+ onStats: (s) => {
+ stats = s
+ }
+ })
+ expect(data).not.toBeNull()
+ if (!data) return
+ // The icon frame rasterized once (whole container), not once per path.
+ expect(rasterCalls).toEqual([[iconFrame.id]])
+ const media = Object.keys(unzipPptx(data)).filter(
+ (f) => f.startsWith('ppt/media/') && !f.endsWith('/')
+ )
+ expect(media).toHaveLength(1)
+ expect(stats).not.toBeNull()
+ if (!stats) return
+ const reported: PPTXExportStats = stats
+ expect(reported.fallbackReasons['vector graphics']).toBe(1)
+ })
+
+ test('a child of a rotated frame keeps the inherited rotation and stays centered', async () => {
+ const graph = makeGraph()
+ const frame = makeSlideFrame(graph, 'Slide')
+ const rotated = graph.createNode('FRAME', frame.id, {
+ name: 'Rotated',
+ x: 400,
+ y: 200,
+ width: 200,
+ height: 100,
+ rotation: 90,
+ fills: []
+ })
+ graph.createNode('RECTANGLE', rotated.id, {
+ width: 200,
+ height: 100,
+ fills: [solidFill(0, 0, 1)]
+ })
+
+ const data = await renderNodesToPPTX(graph, pageId(graph), [frame.id], {
+ rasterize: stubRasterize
+ })
+ expect(data).not.toBeNull()
+ if (!data) return
+ const [rect, ...rest] = placements(slideXml(unzipPptx(data), 1))
+ expect(rest).toHaveLength(0)
+ // Rotation comes from the parent frame, and the rect is centered on it —
+ // the unrotated box origin, not the rotated corner at (550, 150).
+ expect(rect.rot).toBeCloseTo(90, 3)
+ expect(rect.centerX).toBeCloseTo(inches(500), 3)
+ expect(rect.centerY).toBeCloseTo(inches(250), 3)
+ expect(rect.width).toBeCloseTo(inches(200), 3)
+ expect(rect.height).toBeCloseTo(inches(100), 3)
+ })
+
+ test('a root frame with overflowing clipped content rasterizes as one image', async () => {
+ const graph = makeGraph()
+ const frame = makeSlideFrame(graph, 'Clipped slide')
+ frame.clipsContent = true
+ graph.createNode('RECTANGLE', frame.id, {
+ x: 1200,
+ y: 40,
+ width: 200,
+ height: 100,
+ fills: [solidFill(1, 0, 0)]
+ })
+
+ let stats: PPTXExportStats | null = null
+ const rasterCalls: string[][] = []
+ const data = await renderNodesToPPTX(graph, pageId(graph), [frame.id], {
+ rasterize: (ids) => {
+ rasterCalls.push(ids)
+ return Promise.resolve(TINY_PNG)
+ },
+ onStats: (value) => {
+ stats = value
+ }
+ })
+ expect(data).not.toBeNull()
+ if (!data) return
+ expect(rasterCalls).toEqual([[frame.id]])
+ expect(slideXml(unzipPptx(data), 1)).not.toContain('FF0000')
+ expect(stats).not.toBeNull()
+ if (!stats) return
+ const reported: PPTXExportStats = stats
+ expect(reported.fallbackReasons['clipped content']).toBe(1)
+ })
+
+ test('a root frame containing a mask rasterizes as one image', async () => {
+ const graph = makeGraph()
+ const frame = makeSlideFrame(graph, 'Masked slide')
+ graph.createNode('RECTANGLE', frame.id, {
+ width: 200,
+ height: 200,
+ isMask: true,
+ fills: [solidFill(0, 0, 0)]
+ })
+ graph.createNode('RECTANGLE', frame.id, {
+ x: 100,
+ y: 100,
+ width: 300,
+ height: 300,
+ fills: [solidFill(1, 0, 0)]
+ })
+
+ let stats: PPTXExportStats | null = null
+ const rasterCalls: string[][] = []
+ const data = await renderNodesToPPTX(graph, pageId(graph), [frame.id], {
+ rasterize: (ids) => {
+ rasterCalls.push(ids)
+ return Promise.resolve(TINY_PNG)
+ },
+ onStats: (value) => {
+ stats = value
+ }
+ })
+ expect(data).not.toBeNull()
+ if (!data) return
+ expect(rasterCalls).toEqual([[frame.id]])
+ expect(slideXml(unzipPptx(data), 1)).not.toContain('FF0000')
+ expect(stats).not.toBeNull()
+ if (!stats) return
+ const reported: PPTXExportStats = stats
+ expect(reported.fallbackReasons['contains mask']).toBe(1)
+ })
+
+ test('an invisible mask does not flatten an otherwise editable root frame', async () => {
+ const graph = makeGraph()
+ const frame = makeSlideFrame(graph, 'Slide with hidden mask')
+ graph.createNode('RECTANGLE', frame.id, {
+ width: 200,
+ height: 200,
+ isMask: true,
+ visible: false,
+ fills: [solidFill(0, 0, 0)]
+ })
+ graph.createNode('RECTANGLE', frame.id, {
+ x: 100,
+ y: 100,
+ width: 300,
+ height: 300,
+ fills: [solidFill(1, 0, 0)]
+ })
+
+ const rasterCalls: string[][] = []
+ const data = await renderNodesToPPTX(graph, pageId(graph), [frame.id], {
+ rasterize: (ids) => {
+ rasterCalls.push(ids)
+ return Promise.resolve(TINY_PNG)
+ }
+ })
+ expect(data).not.toBeNull()
+ if (!data) return
+ expect(rasterCalls).toEqual([])
+ expect(slideXml(unzipPptx(data), 1)).toContain('FF0000')
+ })
+
+ test('a clipped frame with an overflowing child rasterizes as one image', async () => {
+ const graph = makeGraph()
+ const frame = makeSlideFrame(graph, 'Slide')
+ const clipped = graph.createNode('FRAME', frame.id, {
+ name: 'Clipped',
+ x: 100,
+ y: 100,
+ width: 200,
+ height: 200,
+ clipsContent: true,
+ fills: [solidFill(0, 0, 1)]
+ })
+ graph.createNode('RECTANGLE', clipped.id, {
+ x: 150,
+ y: 20,
+ width: 200,
+ height: 100,
+ fills: [solidFill(1, 0, 0)]
+ })
+
+ let stats: PPTXExportStats | null = null
+ const rasterCalls: string[][] = []
+ const data = await renderNodesToPPTX(graph, pageId(graph), [frame.id], {
+ rasterize: (ids) => {
+ rasterCalls.push(ids)
+ return Promise.resolve(TINY_PNG)
+ },
+ onStats: (s) => {
+ stats = s
+ }
+ })
+ expect(data).not.toBeNull()
+ if (!data) return
+ // The frame rasterized once, so the cropped part of the child cannot leak
+ // back in as a separate native shape.
+ expect(rasterCalls).toEqual([[clipped.id]])
+ expect(slideXml(unzipPptx(data), 1)).not.toContain('FF0000')
+ expect(stats).not.toBeNull()
+ if (!stats) return
+ const reported: PPTXExportStats = stats
+ expect(reported.fallbackReasons['clipped content']).toBe(1)
+ })
+
+ test('a clipped frame whose children fit stays native', async () => {
+ const graph = makeGraph()
+ const frame = makeSlideFrame(graph, 'Slide')
+ const clipped = graph.createNode('FRAME', frame.id, {
+ name: 'Clipped',
+ x: 100,
+ y: 100,
+ width: 200,
+ height: 200,
+ clipsContent: true,
+ fills: [solidFill(0, 0, 1)]
+ })
+ graph.createNode('RECTANGLE', clipped.id, {
+ x: 20,
+ y: 20,
+ width: 100,
+ height: 100,
+ fills: [solidFill(1, 0, 0)]
+ })
+
+ let stats: PPTXExportStats | null = null
+ const data = await renderNodesToPPTX(graph, pageId(graph), [frame.id], {
+ rasterize: stubRasterize,
+ onStats: (s) => {
+ stats = s
+ }
+ })
+ expect(data).not.toBeNull()
+ if (!data) return
+ const xml = slideXml(unzipPptx(data), 1)
+ expect(xml).toContain('FF0000')
+ expect(stats).not.toBeNull()
+ if (!stats) return
+ const reported: PPTXExportStats = stats
+ expect(reported.fallback).toBe(0)
+ })
+
+ test('line transparency includes the stroke paint alpha', async () => {
+ const graph = makeGraph()
+ const frame = makeSlideFrame(graph, 'Slide')
+ graph.createNode('LINE', frame.id, {
+ x: 40,
+ y: 40,
+ width: 200,
+ height: 2,
+ strokes: [solidStroke(1, 0, 0, 0.5)]
+ })
+ const data = await renderNodesToPPTX(graph, pageId(graph), [frame.id], {
+ rasterize: stubRasterize
+ })
+ expect(data).not.toBeNull()
+ if (!data) return
+ const xml = slideXml(unzipPptx(data), 1)
+ expect(xml).toContain('FF0000')
+ // 50% alpha survives instead of rendering fully opaque.
+ expect(xml).toContain('<a:alpha val="50000"/>')
+ })
+
+ test('a stroked slide frame becomes a native shape, not an image', async () => {
+ const graph = makeGraph()
+ const frame = graph.createNode('FRAME', pageId(graph), {
+ width: 1280,
+ height: 720,
+ fills: [solidFill(1, 1, 1)],
+ strokes: [solidStroke(0, 0, 0, 1, 4)]
+ })
+
+ let stats: PPTXExportStats | null = null
+ const data = await renderNodesToPPTX(graph, pageId(graph), [frame.id], {
+ rasterize: stubRasterize,
+ onStats: (s) => {
+ stats = s
+ }
+ })
+ expect(data).not.toBeNull()
+ if (!data) return
+ const files = unzipPptx(data)
+ // A slide-sized shape carries the border instead of a flattened image.
+ const [border, ...rest] = placements(slideXml(files, 1))
+ expect(rest).toHaveLength(0)
+ expect(border.width).toBeCloseTo(SLIDE_WIDTH_IN, 2)
+ expect(
+ Object.keys(files).filter((f) => f.startsWith('ppt/media/') && !f.endsWith('/'))
+ ).toHaveLength(0)
+ expect(stats).not.toBeNull()
+ if (!stats) return
+ const reported: PPTXExportStats = stats
+ expect(reported.fallback).toBe(0)
+ })
+
+ test('a non-solid slide background rasterizes without its children', async () => {
+ const graph = makeGraph()
+ const frame = graph.createNode('FRAME', pageId(graph), {
+ width: 1280,
+ height: 720,
+ fills: [
+ {
+ type: 'GRADIENT_LINEAR',
+ color: { r: 0, g: 0, b: 0, a: 1 },
+ opacity: 1,
+ visible: true,
+ gradientStops: [
+ { position: 0, color: { r: 1, g: 0, b: 0, a: 1 } },
+ { position: 1, color: { r: 0, g: 0, b: 1, a: 1 } }
+ ]
+ }
+ ]
+ })
+ graph.createNode('TEXT', frame.id, {
+ text: 'On the gradient',
+ x: 100,
+ y: 100,
+ width: 400,
+ height: 60,
+ fontSize: 32,
+ fills: [solidFill(1, 1, 1)]
+ })
+
+ const calls: { ids: string[]; paintOnly?: boolean }[] = []
+ const data = await renderNodesToPPTX(graph, pageId(graph), [frame.id], {
+ rasterize: (ids, _scale, options) => {
+ calls.push({ ids, paintOnly: options?.paintOnly })
+ return Promise.resolve(TINY_PNG)
+ }
+ })
+ expect(data).not.toBeNull()
+ if (!data) return
+ // Baking the children into the background image would draw them twice —
+ // once flattened, once as the native text added right after.
+ expect(calls).toEqual([{ ids: [frame.id], paintOnly: true }])
+ expect(slideXml(unzipPptx(data), 1)).toContain('On the gradient')
+ })
+
+ test('solid frame background maps to slide background color', async () => {
+ const graph = makeGraph()
+ const frame = graph.createNode('FRAME', pageId(graph), {
+ width: 1280,
+ height: 720,
+ fills: [{ type: 'SOLID', color: { r: 0.2, g: 0.4, b: 0.6, a: 1 }, opacity: 1, visible: true }]
+ })
+ const data = await renderNodesToPPTX(graph, pageId(graph), [frame.id], {
+ rasterize: stubRasterize
+ })
+ expect(data).not.toBeNull()
+ if (!data) return
+ const xml = slideXml(unzipPptx(data), 1)
+ expect(xml.toUpperCase()).toContain('336699')
+ })
+
+ test('a translucent frame background keeps its alpha', async () => {
+ const graph = makeGraph()
+ const frame = graph.createNode('FRAME', pageId(graph), {
+ width: 1280,
+ height: 720,
+ fills: [solidFill(0.2, 0.4, 0.6, 0.5)]
+ })
+ const data = await renderNodesToPPTX(graph, pageId(graph), [frame.id], {
+ rasterize: stubRasterize
+ })
+ expect(data).not.toBeNull()
+ if (!data) return
+ const xml = slideXml(unzipPptx(data), 1)
+ expect(xml).toContain('<a:alpha val="50000"/>')
+ })
+
+ test('document export covers frames on every page', async () => {
+ const graph = makeGraph()
+ makeSlideFrame(graph, 'Page 1 slide')
+ const second = graph.addPage('Page 2')
+ graph.createNode('FRAME', second.id, {
+ name: 'Page 2 slide',
+ width: 1280,
+ height: 720,
+ fills: [solidFill(1, 1, 1)]
+ })
+
+ const pptx = BUILTIN_IO_FORMATS.find((format) => format.id === 'pptx')
+ expect(pptx).toBeDefined()
+ if (!pptx) return
+ const result = await pptx.exportContent(
+ { graph, target: { scope: 'document' } },
+ { rasterize: stubRasterize }
+ )
+ const files = unzipPptx(result.data as Uint8Array)
+ expect(files['ppt/slides/slide1.xml']).toBeDefined()
+ expect(files['ppt/slides/slide2.xml']).toBeDefined()
+ })
+})