@open-slide/core 2.0.0-beta.0 → 2.0.0-beta.2

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.
Files changed (46) hide show
  1. package/dist/build-Bzy-qlGc.js +19 -0
  2. package/dist/cli/bin.js +201 -21
  3. package/dist/{config-AtA2Bqtn.d.ts → config-DjWifhaA.d.ts} +1 -1
  4. package/dist/{dev-BChELmc-.js → dev-MXa5Tod4.js} +36 -10
  5. package/dist/index.d.ts +3 -2
  6. package/dist/index.js +1 -1
  7. package/dist/locale/index.d.ts +1 -1
  8. package/dist/locale/index.js +1 -1
  9. package/dist/preview-DEpQcKz3.js +24 -0
  10. package/dist/{types-BzPSOxe-.d.ts → types-BWg-Dtbg.d.ts} +1 -2
  11. package/dist/vite/index.d.ts +1 -1
  12. package/dist/vite/index.js +1 -1
  13. package/dist/{zh-tw-BxZ_pYqe.js → zh-tw-DlKyeNX7.js} +4 -8
  14. package/package.json +1 -1
  15. package/skills/slide-authoring/SKILL.md +3 -3
  16. package/skills/slide-authoring/references/morph.md +5 -5
  17. package/skills/slide-authoring/references/transitions.md +38 -37
  18. package/skills/slide-authoring/references/webfonts.md +25 -6
  19. package/src/app/components/command/slide-command-menu.tsx +10 -0
  20. package/src/app/components/slide-transition-layer.tsx +8 -1
  21. package/src/app/lib/export-pptx.ts +122 -193
  22. package/src/app/lib/pptx/color.ts +49 -0
  23. package/src/app/lib/pptx/css.test.ts +172 -0
  24. package/src/app/lib/pptx/css.ts +450 -0
  25. package/src/app/lib/pptx/fonts.ts +145 -0
  26. package/src/app/lib/pptx/images.ts +116 -0
  27. package/src/app/lib/pptx/measure.ts +1299 -0
  28. package/src/app/lib/pptx/ooxml.test.ts +199 -0
  29. package/src/app/lib/pptx/ooxml.ts +470 -0
  30. package/src/app/lib/pptx/raster.ts +189 -0
  31. package/src/app/lib/pptx/render.ts +102 -0
  32. package/src/app/lib/pptx/scene.ts +116 -0
  33. package/src/app/lib/pptx/text-lines.test.ts +82 -0
  34. package/src/app/lib/pptx/text-lines.ts +109 -0
  35. package/src/app/lib/pptx/units.ts +22 -0
  36. package/src/app/lib/transition.test.ts +31 -0
  37. package/src/app/lib/transition.ts +13 -0
  38. package/src/app/routes/slide.tsx +21 -27
  39. package/src/locale/en.ts +1 -3
  40. package/src/locale/ja.ts +1 -3
  41. package/src/locale/types.ts +1 -2
  42. package/src/locale/zh-cn.ts +1 -2
  43. package/src/locale/zh-tw.ts +1 -2
  44. package/dist/build-CfAxF6Dm.js +0 -14
  45. package/dist/preview-CcCQa268.js +0 -14
  46. package/dist/{config-C_VI2EpT.js → config-nbSvY7z_.js} +2 -2
@@ -30,14 +30,15 @@ type TransitionPhase = {
30
30
  keyframes: Keyframe[] | PropertyIndexedKeyframes; // WAAPI keyframes
31
31
  duration?: number; // ms (falls back to top-level duration)
32
32
  easing?: string; // CSS easing
33
- delay?: number; // ms — use to overlap exit + enter
33
+ delay?: number; // ms
34
34
  };
35
35
  type SlideTransition = {
36
36
  duration: number; // top-level fallback
37
37
  easing?: string; // top-level fallback
38
38
  enter?: TransitionPhase; // runs on incoming page
39
- exit?: TransitionPhase; // runs on outgoing page
39
+ exit?: TransitionPhase; // runs on outgoing page — opacity is held at 1 (see below)
40
40
  morph?: boolean | MorphTransition; // shared-element morph — see morph.md
41
+ throughBackground?: boolean; // let exit fade out and dip through --osd-bg
41
42
  };
42
43
  type MorphTransition = {
43
44
  duration?: number;
@@ -48,33 +49,41 @@ type MorphTransition = {
48
49
 
49
50
  The framework also exposes `--osd-dir` (`1` forward, `-1` backward) and `data-osd-dir` (`"forward"` / `"backward"`) on the wrapper, so a single keyframe can mirror direction without a JS callback.
50
51
 
52
+ ## How the layers stack (read this before writing an `exit`)
53
+
54
+ During a cut the outgoing page and the incoming page are stacked in one container painted `--osd-bg`, incoming on top. Every page root fills the canvas and paints its own background, so as long as the outgoing page stays opaque, **the incoming page simply fades in over it and the container colour is never seen**.
55
+
56
+ An exit that fades to `opacity: 0` breaks that: for the stretch where the old page is already transparent and the new one isn't yet opaque, the container shows through. On a deck whose pages all match `--osd-bg` this is invisible; on any page with its own background (a white chapter, a gradient, a full-bleed photo) it reads as a dip to black or a flash. Because this is never what you want by accident, **the framework ignores `opacity` in `exit` keyframes** — the outgoing page holds at full opacity while `transform` / `filter` still apply.
57
+
58
+ - Put the fade on `enter`. The exit is a hold (or a transform-only nudge).
59
+ - Don't delay `enter` — a delay just leaves the old page sitting there for that long.
60
+ - Keep exit transforms tiny or skip them: a translated outgoing page exposes a strip of `--osd-bg` along one edge until the incoming page covers it.
61
+ - If you genuinely want a dip through the background (a section break that goes to black), set `throughBackground: true` on that transition. Exit keyframes then run as written. Only do this where the pages on both sides share `--osd-bg`.
62
+
51
63
  ## Design principles (hold the line)
52
64
 
53
65
  The single loudest signal of "made in PowerPoint" is six different transitions in one deck. Restraint is the rhythm.
54
66
 
55
- - **Pick one DNA, hold it across the deck.** Same duration band, same easing pair, same out-then-in stagger. Variation lives only in *which property* gets the small nudge — Y, X, opacity, scale, blur.
56
- - **Duration: 140–280 ms.** Exit 140–180 ms, enter 200–280 ms, enter delayed ~80 ms so they overlap but don't fight. Past 350 ms is video-editor territory; reserve for genuine state changes.
67
+ - **Pick one DNA, hold it across the deck.** Same duration band, same easing pair, same hold-then-fade-in shape. Variation lives only in *which property* gets the small nudge on enter — Y, X, scale, blur.
68
+ - **Duration: 200–280 ms.** One number for the whole cut; the exit holds for the same duration so the two layers release together. Past 350 ms is video-editor territory; reserve for genuine state changes.
57
69
  - **Magnitude ceiling: 12 px or 3% scale.** A 6 px Y-rise reads as "next thought." A 1920 px translateX reads as "different document." Premium tools move barely enough to register.
58
- - **Opacity is always part of it.** Pure-transform transitions look stiff; pure-opacity transitions are the safest possible default.
59
- - **Easing: ease-in for exit, ease-out for enter.** `cubic-bezier(0.4, 0, 1, 1)` going out, `cubic-bezier(0, 0, 0.2, 1)` coming in. Never `linear` (feels like a slideshow). Reserve symmetric `ease-in-out` for state-anchored morphs only.
70
+ - **Opacity is always part of enter.** Pure-transform enters look stiff; a pure-opacity enter is the safest possible default.
71
+ - **Easing: ease-out for enter.** `cubic-bezier(0, 0, 0.2, 1)`. Never `linear` (feels like a slideshow). Reserve symmetric `ease-in-out` for state-anchored morphs only.
60
72
 
61
73
  ## Tasteful family — six members, one DNA
62
74
 
63
- Use this set as a starting point. Pick one as the deck's house transition; optionally reserve a second for hero/cover slides and a third for genuine section breaks. The CSS-`calc` + `--osd-dir` trick lets a single definition mirror itself on backward navigation when needed.
75
+ Use this set as a starting point. Pick one as the deck's house transition; optionally reserve a second for hero/cover slides and a third for genuine section breaks. Every member holds the outgoing page and fades the incoming one in on top, so none of them can flash the container background.
64
76
 
65
77
  ```tsx
66
78
  const EASE_OUT = 'cubic-bezier(0, 0, 0.2, 1)';
67
79
  const EASE_IN = 'cubic-bezier(0.4, 0, 1, 1)';
80
+ const HOLD: Keyframe[] = [{ opacity: 1 }, { opacity: 1 }];
68
81
 
69
82
  // RISE — house quiet. 6 px Y. Use as module default.
70
83
  export const transition: SlideTransition = {
71
- duration: 200,
72
- exit: { duration: 140, easing: EASE_IN,
73
- keyframes: [
74
- { opacity: 1, transform: 'translateY(0)' },
75
- { opacity: 0, transform: 'translateY(-4px)' },
76
- ] },
77
- enter: { duration: 200, delay: 80, easing: EASE_OUT,
84
+ duration: 260,
85
+ exit: { duration: 260, easing: EASE_IN, keyframes: HOLD },
86
+ enter: { duration: 260, easing: EASE_OUT,
78
87
  keyframes: [
79
88
  { opacity: 0, transform: 'translateY(6px)' },
80
89
  { opacity: 1, transform: 'translateY(0)' },
@@ -84,21 +93,16 @@ export const transition: SlideTransition = {
84
93
  // DISSOLVE — pure opacity. The quietest possible.
85
94
  const dissolve: SlideTransition = {
86
95
  duration: 240,
87
- exit: { duration: 200, easing: EASE_IN,
88
- keyframes: [{ opacity: 1 }, { opacity: 0 }] },
89
- enter: { duration: 240, delay: 40, easing: EASE_OUT,
96
+ exit: { duration: 240, easing: EASE_IN, keyframes: HOLD },
97
+ enter: { duration: 240, easing: EASE_OUT,
90
98
  keyframes: [{ opacity: 0 }, { opacity: 1 }] },
91
99
  };
92
100
 
93
101
  // SETTLE — cover-grade. Rise + a hair of blur on enter only.
94
102
  Cover.transition = {
95
103
  duration: 280,
96
- exit: { duration: 160, easing: EASE_IN,
97
- keyframes: [
98
- { opacity: 1, transform: 'translateY(0)' },
99
- { opacity: 0, transform: 'translateY(-6px)' },
100
- ] },
101
- enter: { duration: 280, delay: 100, easing: EASE_OUT,
104
+ exit: { duration: 280, easing: EASE_IN, keyframes: HOLD },
105
+ enter: { duration: 280, easing: EASE_OUT,
102
106
  keyframes: [
103
107
  { opacity: 0, transform: 'translateY(12px)', filter: 'blur(4px)' },
104
108
  { opacity: 1, transform: 'translateY(0)', filter: 'blur(0)' },
@@ -108,12 +112,8 @@ Cover.transition = {
108
112
  // BLOOM — scale 0.97 → 1, no translate. Materializes in place.
109
113
  const bloom: SlideTransition = {
110
114
  duration: 240,
111
- exit: { duration: 160, easing: EASE_IN,
112
- keyframes: [
113
- { opacity: 1, transform: 'scale(1)' },
114
- { opacity: 0, transform: 'scale(1.01)' },
115
- ] },
116
- enter: { duration: 240, delay: 80, easing: EASE_OUT,
115
+ exit: { duration: 240, easing: EASE_IN, keyframes: HOLD },
116
+ enter: { duration: 240, easing: EASE_OUT,
117
117
  keyframes: [
118
118
  { opacity: 0, transform: 'scale(0.97)' },
119
119
  { opacity: 1, transform: 'scale(1)' },
@@ -122,13 +122,9 @@ const bloom: SlideTransition = {
122
122
 
123
123
  // FALL — mirrored Rise. Incoming page comes down from above.
124
124
  const fall: SlideTransition = {
125
- duration: 200,
126
- exit: { duration: 140, easing: EASE_IN,
127
- keyframes: [
128
- { opacity: 1, transform: 'translateY(0)' },
129
- { opacity: 0, transform: 'translateY(4px)' },
130
- ] },
131
- enter: { duration: 200, delay: 80, easing: EASE_OUT,
125
+ duration: 260,
126
+ exit: { duration: 260, easing: EASE_IN, keyframes: HOLD },
127
+ enter: { duration: 260, easing: EASE_OUT,
132
128
  keyframes: [
133
129
  { opacity: 0, transform: 'translateY(-6px)' },
134
130
  { opacity: 1, transform: 'translateY(0)' },
@@ -136,9 +132,12 @@ const fall: SlideTransition = {
136
132
  };
137
133
 
138
134
  // BREATH — section break. Exit fully, hold 120 ms, then enter.
139
- // Reserve for genuine chapter dividers; use at most 1–2× per deck.
135
+ // The one member that dips through --osd-bg on purpose, so it opts in with
136
+ // `throughBackground`. Use only between pages that share the deck background,
137
+ // and at most 1–2× per deck.
140
138
  const breath: SlideTransition = {
141
139
  duration: 460,
140
+ throughBackground: true,
142
141
  exit: { duration: 180, easing: EASE_IN,
143
142
  keyframes: [{ opacity: 1 }, { opacity: 0 }] },
144
143
  enter: { duration: 240, delay: 300, easing: EASE_OUT,
@@ -164,6 +163,8 @@ If you find yourself reaching for this on every transition, you're probably over
164
163
 
165
164
  ## Anti-patterns
166
165
 
166
+ - ❌ Fading the exit to `opacity: 0` and delaying the enter — the framework ignores the exit fade, so the outgoing page just sits there for the delay (a dead beat); with `throughBackground: true` the same shape becomes a flash of the container background. Write a hold instead.
167
+ - ❌ `throughBackground: true` on the house transition, or between pages with different backgrounds — every cut dips to black.
167
168
  - ❌ Six different transitions across six pages — the single loudest "made in PowerPoint" tell.
168
169
  - ❌ `translateX(100%)` slide-from-side — iOS modal / PowerPoint Push; not a slide change.
169
170
  - ❌ Aggressive scale-pop (e.g. `0.85 → 1`) + blur — lightbox / photo-viewer vocabulary; implies zooming *into* something.
@@ -7,12 +7,31 @@ The default is a system font stack — prefer it. When a deck genuinely needs a
7
7
  ```tsx
8
8
  const FONT_HREF = 'https://fonts.googleapis.com/css2?family=...&display=swap';
9
9
  const FONT_LINK_ID = 'osd-webfont-q2-roadmap'; // suffix = this slide's folder id
10
- if (typeof document !== 'undefined' && !document.getElementById(FONT_LINK_ID)) {
11
- const link = document.createElement('link');
12
- link.id = FONT_LINK_ID;
13
- link.rel = 'stylesheet';
14
- link.href = FONT_HREF;
15
- document.head.appendChild(link);
10
+ if (typeof document !== 'undefined') {
11
+ let link = document.getElementById(FONT_LINK_ID) as HTMLLinkElement | null;
12
+ if (!link) {
13
+ link = document.createElement('link');
14
+ link.id = FONT_LINK_ID;
15
+ link.rel = 'stylesheet';
16
+ document.head.appendChild(link);
17
+ }
18
+ if (link.href !== FONT_HREF) link.href = FONT_HREF;
19
+ }
20
+ ```
21
+
22
+ - **Create-or-update, never create-if-missing.** HMR re-runs the module but leaves the previous `<link>` / `<style>` in the document, so an `if (!document.getElementById(id)) { … }` guard skips the new content and edits don't show up until a full reload. The same shape applies to any `<style>` you inject for `@keyframes`:
23
+
24
+ ```tsx
25
+ const STYLE_ID = 'osd-styles-q2-roadmap';
26
+ const css = `@keyframes rise { from { opacity: 0 } to { opacity: 1 } }`;
27
+ if (typeof document !== 'undefined') {
28
+ let style = document.getElementById(STYLE_ID);
29
+ if (!style) {
30
+ style = document.createElement('style');
31
+ style.id = STYLE_ID;
32
+ document.head.appendChild(style);
33
+ }
34
+ if (style.textContent !== css) style.textContent = css;
16
35
  }
17
36
  ```
18
37
 
@@ -10,6 +10,7 @@ import {
10
10
  MonitorSpeaker,
11
11
  Palette,
12
12
  Play,
13
+ Presentation,
13
14
  RectangleHorizontal,
14
15
  } from 'lucide-react';
15
16
  import { useNavigate } from 'react-router-dom';
@@ -27,6 +28,7 @@ export type SlideCommandHandlers = {
27
28
  onToggleDesignPanel: () => void;
28
29
  onExportHtml: () => void;
29
30
  onExportPdf: () => void;
31
+ onExportPptx: () => void;
30
32
  onExportImagePptx: () => void;
31
33
  onGoToPage: (index: number) => void;
32
34
  };
@@ -132,6 +134,14 @@ export function SlideCommandMenu({
132
134
  disabled: exporting,
133
135
  run: handlers.onExportPdf,
134
136
  },
137
+ {
138
+ id: 'export-pptx',
139
+ label: t.slide.exportAsPptx,
140
+ icon: <Presentation />,
141
+ keywords: ['export', 'pptx', 'powerpoint', 'download', 'editable'],
142
+ disabled: exporting,
143
+ run: handlers.onExportPptx,
144
+ },
135
145
  {
136
146
  id: 'export-image-pptx',
137
147
  label: t.slide.exportAsImagePptx,
@@ -8,6 +8,7 @@ import {
8
8
  StepHost,
9
9
  } from '../lib/step-context';
10
10
  import {
11
+ holdOpacity,
11
12
  type MorphTransition,
12
13
  resolveTransition,
13
14
  type SlideTransition,
@@ -711,8 +712,14 @@ export function SlideTransitionLayer({
711
712
  const morphPhase = resolveMorphTransition(transition.morph, duration, easing);
712
713
  const morphRun = morphPhase ? runMorphTransition(wrapper, out, inc, morphPhase) : null;
713
714
 
715
+ // The wrapper paints --osd-bg under both layers, so an exit that fades
716
+ // out exposes it before the enter has covered it; pages whose own
717
+ // background differs from --osd-bg visibly dip through the wrapper colour.
718
+ // The outgoing page therefore stays opaque unless the deck opts in.
719
+ const exitPhase = transition.throughBackground ? transition.exit : holdOpacity(transition.exit);
720
+
714
721
  const anims: Animation[] = [];
715
- const exitAnim = runPhase(out, transition.exit, duration, easing);
722
+ const exitAnim = runPhase(out, exitPhase, duration, easing);
716
723
  const enterAnim = runPhase(inc, transition.enter, duration, easing);
717
724
  if (exitAnim) anims.push(exitAnim);
718
725
  if (enterAnim) anims.push(enterAnim);
@@ -1,21 +1,8 @@
1
- import { createElement } from 'react';
2
- import { createRoot, type Root } from 'react-dom/client';
3
- import { designToCssVars } from './design';
4
- import { downloadBlob, nextPaint, sleep } from './dom';
5
- import { SlidePageProvider } from './page-context';
6
- import { isFrameAnimationSettled, waitForDataWaitfor, waitForFonts } from './print-ready';
1
+ import { downloadBlob } from './dom';
7
2
  import { CANVAS_HEIGHT, CANVAS_WIDTH, type SlideModule } from './sdk';
8
3
 
9
- // 16:9 widescreen in English Metric Units (914400 EMU per inch → 13.333in × 7.5in).
10
- const EMU_W = 12192000;
11
- const EMU_H = 6858000;
12
- const CAPTURE_PIXEL_RATIO = 2;
13
-
14
- const ANIMATION_TIMEOUT_MS = 15_000;
15
- const POLL_INTERVAL_MS = 100;
16
-
17
4
  const CAPTURE_CLASS = 'os-pptx-capture';
18
- const CAPTURE_STYLE_ID = 'os-pptx-capture-style';
5
+ const CAPTURE_PIXEL_RATIO = 2;
19
6
  // Properties intro animations drive from a hidden start state to a visible end
20
7
  // state. We read them back once settled and pin them inline so the capture clone
21
8
  // can't re-run the keyframes from their invisible 0% frame (see freezeForCapture).
@@ -23,94 +10,117 @@ const FROZEN_PROPS = ['opacity', 'transform', 'filter', 'clip-path'] as const;
23
10
 
24
11
  export type PptxExportProgress = {
25
12
  phase: 'processing' | 'generating' | 'done';
26
- /** Number of pages captured so far (0..total). */
13
+ /** Number of pages converted so far (0..total). */
27
14
  current: number;
28
15
  total: number;
29
- /** 0–95 while capturing, 98 while assembling, 100 when done. */
16
+ /** 0–95 while converting pages, 98 while assembling, 100 when done. */
30
17
  percent: number;
31
18
  };
32
19
 
33
- export async function exportSlideAsImagePptx(
20
+ type ProgressFn = (progress: PptxExportProgress) => void;
21
+
22
+ async function loadPipeline() {
23
+ const [render, measure, images, raster, color, ooxml, fflate] = await Promise.all([
24
+ import('./pptx/render'),
25
+ import('./pptx/measure'),
26
+ import('./pptx/images'),
27
+ import('./pptx/raster'),
28
+ import('./pptx/color'),
29
+ import('./pptx/ooxml'),
30
+ import('fflate'),
31
+ ]);
32
+ return {
33
+ ...render,
34
+ ...measure,
35
+ ...images,
36
+ ...raster,
37
+ ...color,
38
+ ...ooxml,
39
+ zipSync: fflate.zipSync,
40
+ };
41
+ }
42
+
43
+ function download(
44
+ files: Record<string, Uint8Array>,
45
+ zip: (f: Record<string, Uint8Array>) => Uint8Array,
46
+ mime: string,
47
+ slideId: string,
48
+ ) {
49
+ const zipped = zip(files);
50
+ downloadBlob(new Blob([zipped as BlobPart], { type: mime }), `${slideId}.pptx`);
51
+ }
52
+
53
+ /**
54
+ * Converts every page into native PowerPoint objects: text boxes with the browser's
55
+ * line breaks pinned, shapes for boxes and borders, pictures for images, and a
56
+ * pixel-exact raster only for effects PowerPoint cannot express.
57
+ */
58
+ export async function exportSlideAsPptx(
34
59
  slide: SlideModule,
35
60
  slideId: string,
36
- onProgress?: (progress: PptxExportProgress) => void,
61
+ onProgress?: ProgressFn,
37
62
  ): Promise<void> {
38
63
  const pages = slide.default ?? [];
39
64
  if (pages.length === 0) return;
40
-
41
65
  const total = pages.length;
42
66
  onProgress?.({ phase: 'processing', current: 0, total, percent: 0 });
43
67
 
44
- const container = document.createElement('div');
45
- container.className = CAPTURE_CLASS;
46
- container.setAttribute('aria-hidden', 'true');
47
- Object.assign(container.style, {
48
- position: 'fixed',
49
- left: '-99999px',
50
- top: '0',
51
- pointerEvents: 'none',
52
- });
53
- document.body.appendChild(container);
54
-
55
- // html-to-image clones each frame and copies its computed style — including the
56
- // intro animation — into the clone, which then re-runs the keyframes from their
57
- // hidden 0% frame in the rasterised SVG. Fast-forward every animation to its end
58
- // frame in the live DOM (a large negative delay lands past a 1ms duration, so
59
- // even pseudo-elements paint their final state on the first frame).
60
- const captureStyle = document.createElement('style');
61
- captureStyle.id = CAPTURE_STYLE_ID;
62
- captureStyle.textContent = `.${CAPTURE_CLASS} *, .${CAPTURE_CLASS} *::before, .${CAPTURE_CLASS} *::after {
63
- animation-delay: -1s !important;
64
- animation-duration: 1ms !important;
65
- animation-iteration-count: 1 !important;
66
- animation-fill-mode: forwards !important;
67
- transition: none !important;
68
- }`;
69
- document.head.appendChild(captureStyle);
70
-
71
- const designVars = slide.design ? designToCssVars(slide.design) : null;
72
-
73
- const reactRoots: Root[] = [];
74
- const frames: HTMLElement[] = [];
75
- for (let i = 0; i < pages.length; i++) {
76
- const Page = pages[i];
77
- if (!Page) continue;
78
- const host = document.createElement('div');
79
- host.setAttribute('data-osd-canvas', '');
80
- host.style.width = `${CANVAS_WIDTH}px`;
81
- host.style.height = `${CANVAS_HEIGHT}px`;
82
- host.style.overflow = 'hidden';
83
- host.style.background = '#fff';
84
- if (designVars) {
85
- for (const [k, v] of Object.entries(designVars)) host.style.setProperty(k, v);
68
+ const lib = await loadPipeline();
69
+ const mounted = await lib.mountDeckOffscreen(slide, CAPTURE_CLASS);
70
+ try {
71
+ const images = new lib.ImageStore();
72
+ const color = lib.createColorNormalizer();
73
+ const slides = [];
74
+ for (let i = 0; i < mounted.frames.length; i++) {
75
+ const frame = mounted.frames[i];
76
+ slides.push(
77
+ await lib.measurePage({
78
+ frame,
79
+ notes: slide.notes?.[i]?.trim() || null,
80
+ images,
81
+ rasterizer: new lib.Rasterizer(frame),
82
+ color,
83
+ }),
84
+ );
85
+ onProgress?.({
86
+ phase: 'processing',
87
+ current: i + 1,
88
+ total,
89
+ percent: Math.min(95, ((i + 1) / total) * 95),
90
+ });
86
91
  }
87
- container.appendChild(host);
88
- frames.push(host);
89
- const r = createRoot(host);
90
- r.render(
91
- createElement(SlidePageProvider, { index: i, total: pages.length }, createElement(Page)),
92
+ onProgress?.({ phase: 'generating', current: total, total, percent: 98 });
93
+ download(
94
+ lib.buildPptxFiles({ slides, images: images.images }),
95
+ lib.zipSync,
96
+ lib.PPTX_MIME,
97
+ slideId,
92
98
  );
93
- reactRoots.push(r);
99
+ } finally {
100
+ onProgress?.({ phase: 'done', current: total, total, percent: 100 });
101
+ mounted.dispose();
94
102
  }
95
- // Yield once so React commits all pages and intro animations actually start.
96
- await nextPaint();
97
-
98
- try {
99
- await waitForFonts();
103
+ }
100
104
 
101
- const deadline = performance.now() + ANIMATION_TIMEOUT_MS;
102
- while (performance.now() < deadline) {
103
- const settled = frames.every((frame) => isFrameAnimationSettled(frame));
104
- if (settled) break;
105
- await sleep(POLL_INTERVAL_MS);
106
- }
107
- await waitForDataWaitfor(container);
105
+ export async function exportSlideAsImagePptx(
106
+ slide: SlideModule,
107
+ slideId: string,
108
+ onProgress?: ProgressFn,
109
+ ): Promise<void> {
110
+ const pages = slide.default ?? [];
111
+ if (pages.length === 0) return;
112
+ const total = pages.length;
113
+ onProgress?.({ phase: 'processing', current: 0, total, percent: 0 });
108
114
 
109
- const { toBlob } = await import('html-to-image');
110
- const images: Uint8Array[] = [];
111
- for (let i = 0; i < frames.length; i++) {
112
- freezeForCapture(frames[i]);
113
- const blob = await toBlob(frames[i], {
115
+ const [lib, { toBlob }] = await Promise.all([loadPipeline(), import('html-to-image')]);
116
+ const mounted = await lib.mountDeckOffscreen(slide, CAPTURE_CLASS);
117
+ try {
118
+ const images = new lib.ImageStore();
119
+ const slides = [];
120
+ for (let i = 0; i < mounted.frames.length; i++) {
121
+ const frame = mounted.frames[i];
122
+ freezeForCapture(frame);
123
+ const blob = await toBlob(frame, {
114
124
  width: CANVAS_WIDTH,
115
125
  height: CANVAS_HEIGHT,
116
126
  pixelRatio: CAPTURE_PIXEL_RATIO,
@@ -118,7 +128,26 @@ export async function exportSlideAsImagePptx(
118
128
  cacheBust: true,
119
129
  });
120
130
  if (!blob) throw new Error(`failed to capture page ${i + 1}`);
121
- images.push(new Uint8Array(await blob.arrayBuffer()));
131
+ const imageId = images.add(new Uint8Array(await blob.arrayBuffer()), 'png');
132
+ slides.push({
133
+ background: null,
134
+ notes: slide.notes?.[i]?.trim() || null,
135
+ nodes: [
136
+ {
137
+ kind: 'picture' as const,
138
+ name: 'Slide',
139
+ box: { x: 0, y: 0, w: CANVAS_WIDTH, h: CANVAS_HEIGHT },
140
+ rotationDeg: 0,
141
+ flipV: false,
142
+ imageId,
143
+ crop: null,
144
+ alpha: 1,
145
+ geometry: { kind: 'rect' as const },
146
+ outline: null,
147
+ shadow: null,
148
+ },
149
+ ],
150
+ });
122
151
  onProgress?.({
123
152
  phase: 'processing',
124
153
  current: i + 1,
@@ -126,26 +155,22 @@ export async function exportSlideAsImagePptx(
126
155
  percent: Math.min(95, ((i + 1) / total) * 95),
127
156
  });
128
157
  }
129
-
130
158
  onProgress?.({ phase: 'generating', current: total, total, percent: 98 });
131
- const pptx = await buildImagePptx(images);
132
- downloadBlob(
133
- new Blob([pptx as BlobPart], {
134
- type: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
135
- }),
136
- `${slideId}.pptx`,
159
+ download(
160
+ lib.buildPptxFiles({ slides, images: images.images }),
161
+ lib.zipSync,
162
+ lib.PPTX_MIME,
163
+ slideId,
137
164
  );
138
165
  } finally {
139
166
  onProgress?.({ phase: 'done', current: total, total, percent: 100 });
140
- for (const r of reactRoots) r.unmount();
141
- container.remove();
142
- captureStyle.remove();
167
+ mounted.dispose();
143
168
  }
144
169
  }
145
170
 
146
171
  // Pin each element's settled visual state inline and remove its animation so the
147
172
  // clone html-to-image rasterises renders the final frame instead of replaying the
148
- // (initially invisible) keyframes. Pseudo-elements are handled by CAPTURE_STYLE_ID.
173
+ // (initially invisible) keyframes. Pseudo-elements are handled by the capture style.
149
174
  function freezeForCapture(root: HTMLElement): void {
150
175
  for (const el of root.querySelectorAll<HTMLElement>('*')) {
151
176
  const cs = getComputedStyle(el);
@@ -156,99 +181,3 @@ function freezeForCapture(root: HTMLElement): void {
156
181
  el.style.setProperty('transition', 'none', 'important');
157
182
  }
158
183
  }
159
-
160
- const XML_DECL = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n';
161
- const REL_NS = 'http://schemas.openxmlformats.org/package/2006/relationships';
162
- const OD_REL = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships';
163
-
164
- async function buildImagePptx(images: Uint8Array[]): Promise<Uint8Array> {
165
- const { zipSync, strToU8 } = await import('fflate');
166
- const n = images.length;
167
- const files: Record<string, Uint8Array> = {};
168
-
169
- files['[Content_Types].xml'] = strToU8(contentTypesXml(n));
170
- files['_rels/.rels'] = strToU8(rootRelsXml());
171
- files['ppt/presentation.xml'] = strToU8(presentationXml(n));
172
- files['ppt/_rels/presentation.xml.rels'] = strToU8(presentationRelsXml(n));
173
- files['ppt/presProps.xml'] = strToU8(presPropsXml());
174
- files['ppt/theme/theme1.xml'] = strToU8(themeXml());
175
- files['ppt/slideMasters/slideMaster1.xml'] = strToU8(slideMasterXml());
176
- files['ppt/slideMasters/_rels/slideMaster1.xml.rels'] = strToU8(slideMasterRelsXml());
177
- files['ppt/slideLayouts/slideLayout1.xml'] = strToU8(slideLayoutXml());
178
- files['ppt/slideLayouts/_rels/slideLayout1.xml.rels'] = strToU8(slideLayoutRelsXml());
179
-
180
- for (let i = 0; i < n; i++) {
181
- const idx = i + 1;
182
- files[`ppt/slides/slide${idx}.xml`] = strToU8(slideXml());
183
- files[`ppt/slides/_rels/slide${idx}.xml.rels`] = strToU8(slideRelsXml(idx));
184
- files[`ppt/media/image${idx}.png`] = images[i];
185
- }
186
-
187
- return zipSync(files);
188
- }
189
-
190
- function contentTypesXml(n: number): string {
191
- const slideOverrides = Array.from(
192
- { length: n },
193
- (_, i) =>
194
- `<Override PartName="/ppt/slides/slide${i + 1}.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slide+xml"/>`,
195
- ).join('');
196
- return `${XML_DECL}<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Default Extension="png" ContentType="image/png"/><Override PartName="/ppt/presentation.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml"/><Override PartName="/ppt/presProps.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.presProps+xml"/><Override PartName="/ppt/slideMasters/slideMaster1.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml"/><Override PartName="/ppt/slideLayouts/slideLayout1.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml"/><Override PartName="/ppt/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/>${slideOverrides}</Types>`;
197
- }
198
-
199
- function rootRelsXml(): string {
200
- return `${XML_DECL}<Relationships xmlns="${REL_NS}"><Relationship Id="rId1" Type="${OD_REL}/officeDocument" Target="ppt/presentation.xml"/></Relationships>`;
201
- }
202
-
203
- function presentationXml(n: number): string {
204
- const sldIds = Array.from(
205
- { length: n },
206
- (_, i) => `<p:sldId id="${256 + i}" r:id="rId${i + 3}"/>`,
207
- ).join('');
208
- return `${XML_DECL}<p:presentation xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="${OD_REL}" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main"><p:sldMasterIdLst><p:sldMasterId id="2147483648" r:id="rId1"/></p:sldMasterIdLst><p:sldIdLst>${sldIds}</p:sldIdLst><p:sldSz cx="${EMU_W}" cy="${EMU_H}"/><p:notesSz cx="6858000" cy="9144000"/></p:presentation>`;
209
- }
210
-
211
- function presentationRelsXml(n: number): string {
212
- const rels = [
213
- `<Relationship Id="rId1" Type="${OD_REL}/slideMaster" Target="slideMasters/slideMaster1.xml"/>`,
214
- `<Relationship Id="rId2" Type="${OD_REL}/presProps" Target="presProps.xml"/>`,
215
- ];
216
- for (let i = 0; i < n; i++) {
217
- rels.push(
218
- `<Relationship Id="rId${i + 3}" Type="${OD_REL}/slide" Target="slides/slide${i + 1}.xml"/>`,
219
- );
220
- }
221
- return `${XML_DECL}<Relationships xmlns="${REL_NS}">${rels.join('')}</Relationships>`;
222
- }
223
-
224
- function presPropsXml(): string {
225
- return `${XML_DECL}<p:presentationPr xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="${OD_REL}" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main"/>`;
226
- }
227
-
228
- function slideMasterXml(): string {
229
- return `${XML_DECL}<p:sldMaster xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="${OD_REL}" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main"><p:cSld><p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr><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></p:spTree></p:cSld><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"/><p:sldLayoutIdLst><p:sldLayoutId id="2147483649" r:id="rId1"/></p:sldLayoutIdLst></p:sldMaster>`;
230
- }
231
-
232
- function slideMasterRelsXml(): string {
233
- return `${XML_DECL}<Relationships xmlns="${REL_NS}"><Relationship Id="rId1" Type="${OD_REL}/slideLayout" Target="../slideLayouts/slideLayout1.xml"/><Relationship Id="rId2" Type="${OD_REL}/theme" Target="../theme/theme1.xml"/></Relationships>`;
234
- }
235
-
236
- function slideLayoutXml(): string {
237
- return `${XML_DECL}<p:sldLayout xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="${OD_REL}" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" type="blank" preserve="1"><p:cSld name="Blank"><p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr><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></p:spTree></p:cSld><p:clrMapOvr><a:masterClrMapping/></p:clrMapOvr></p:sldLayout>`;
238
- }
239
-
240
- function slideLayoutRelsXml(): string {
241
- return `${XML_DECL}<Relationships xmlns="${REL_NS}"><Relationship Id="rId1" Type="${OD_REL}/slideMaster" Target="../slideMasters/slideMaster1.xml"/></Relationships>`;
242
- }
243
-
244
- function slideXml(): string {
245
- return `${XML_DECL}<p:sld xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="${OD_REL}" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main"><p:cSld><p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr><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><p:pic><p:nvPicPr><p:cNvPr id="2" name="Slide"/><p:cNvPicPr><a:picLocks noChangeAspect="1"/></p:cNvPicPr><p:nvPr/></p:nvPicPr><p:blipFill><a:blip r:embed="rId2"/><a:stretch><a:fillRect/></a:stretch></p:blipFill><p:spPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="${EMU_W}" cy="${EMU_H}"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom></p:spPr></p:pic></p:spTree></p:cSld><p:clrMapOvr><a:masterClrMapping/></p:clrMapOvr></p:sld>`;
246
- }
247
-
248
- function slideRelsXml(idx: number): string {
249
- return `${XML_DECL}<Relationships xmlns="${REL_NS}"><Relationship Id="rId1" Type="${OD_REL}/slideLayout" Target="../slideLayouts/slideLayout1.xml"/><Relationship Id="rId2" Type="${OD_REL}/image" Target="../media/image${idx}.png"/></Relationships>`;
250
- }
251
-
252
- function themeXml(): string {
253
- return `${XML_DECL}<a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="Office Theme"><a:themeElements><a:clrScheme name="Office"><a:dk1><a:sysClr val="windowText" lastClr="000000"/></a:dk1><a:lt1><a:sysClr val="window" lastClr="FFFFFF"/></a:lt1><a:dk2><a:srgbClr val="44546A"/></a:dk2><a:lt2><a:srgbClr val="E7E6E6"/></a:lt2><a:accent1><a:srgbClr val="4472C4"/></a:accent1><a:accent2><a:srgbClr val="ED7D31"/></a:accent2><a:accent3><a:srgbClr val="A5A5A5"/></a:accent3><a:accent4><a:srgbClr val="FFC000"/></a:accent4><a:accent5><a:srgbClr val="5B9BD5"/></a:accent5><a:accent6><a:srgbClr val="70AD47"/></a:accent6><a:hlink><a:srgbClr val="0563C1"/></a:hlink><a:folHlink><a:srgbClr val="954F72"/></a:folHlink></a:clrScheme><a:fontScheme name="Office"><a:majorFont><a:latin typeface="Calibri Light"/><a:ea typeface=""/><a:cs typeface=""/></a:majorFont><a:minorFont><a:latin typeface="Calibri"/><a:ea typeface=""/><a:cs typeface=""/></a:minorFont></a:fontScheme><a:fmtScheme name="Office"><a:fillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:lumMod val="110000"/><a:satMod val="105000"/><a:tint val="67000"/></a:schemeClr></a:gs><a:gs pos="50000"><a:schemeClr val="phClr"><a:lumMod val="105000"/><a:satMod val="103000"/><a:tint val="73000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:lumMod val="105000"/><a:satMod val="109000"/><a:tint val="81000"/></a:schemeClr></a:gs></a:gsLst><a:lin ang="5400000" scaled="0"/></a:gradFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:satMod val="103000"/><a:lumMod val="102000"/><a:tint val="94000"/></a:schemeClr></a:gs><a:gs pos="50000"><a:schemeClr val="phClr"><a:satMod val="110000"/><a:lumMod val="100000"/><a:shade val="100000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:lumMod val="99000"/><a:satMod val="120000"/><a:shade val="78000"/></a:schemeClr></a:gs></a:gsLst><a:lin ang="5400000" scaled="0"/></a:gradFill></a:fillStyleLst><a:lnStyleLst><a:ln w="6350" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/><a:miter lim="800000"/></a:ln><a:ln w="12700" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/><a:miter lim="800000"/></a:ln><a:ln w="19050" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/><a:miter lim="800000"/></a:ln></a:lnStyleLst><a:effectStyleLst><a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst/></a:effectStyle></a:effectStyleLst><a:bgFillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:solidFill><a:schemeClr val="phClr"><a:tint val="95000"/><a:satMod val="170000"/></a:schemeClr></a:solidFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="93000"/><a:satMod val="150000"/><a:shade val="98000"/><a:lumMod val="102000"/></a:schemeClr></a:gs><a:gs pos="50000"><a:schemeClr val="phClr"><a:tint val="98000"/><a:satMod val="130000"/><a:shade val="90000"/><a:lumMod val="103000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="63000"/><a:satMod val="120000"/></a:schemeClr></a:gs></a:gsLst><a:lin ang="5400000" scaled="0"/></a:gradFill></a:bgFillStyleLst></a:fmtScheme></a:themeElements></a:theme>`;
254
- }