@open-slide/core 2.0.0-beta.1 → 2.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{config-AtA2Bqtn.d.ts → config-DjWifhaA.d.ts} +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -1
- package/dist/locale/index.d.ts +1 -1
- package/dist/locale/index.js +1 -1
- package/dist/{types-BzPSOxe-.d.ts → types-BWg-Dtbg.d.ts} +1 -2
- package/dist/vite/index.d.ts +1 -1
- package/dist/{zh-tw-BxZ_pYqe.js → zh-tw-DlKyeNX7.js} +4 -8
- package/package.json +2 -2
- package/skills/slide-authoring/SKILL.md +3 -3
- package/skills/slide-authoring/references/morph.md +5 -5
- package/skills/slide-authoring/references/transitions.md +38 -37
- package/skills/slide-authoring/references/webfonts.md +25 -6
- package/src/app/components/command/slide-command-menu.tsx +10 -0
- package/src/app/components/slide-transition-layer.tsx +8 -1
- package/src/app/lib/export-pptx.ts +122 -193
- package/src/app/lib/pptx/color.ts +49 -0
- package/src/app/lib/pptx/css.test.ts +205 -0
- package/src/app/lib/pptx/css.ts +462 -0
- package/src/app/lib/pptx/fonts.ts +145 -0
- package/src/app/lib/pptx/images.ts +116 -0
- package/src/app/lib/pptx/measure.ts +1281 -0
- package/src/app/lib/pptx/ooxml.test.ts +199 -0
- package/src/app/lib/pptx/ooxml.ts +470 -0
- package/src/app/lib/pptx/raster.ts +189 -0
- package/src/app/lib/pptx/render.ts +102 -0
- package/src/app/lib/pptx/scene.ts +116 -0
- package/src/app/lib/pptx/text-lines.test.ts +82 -0
- package/src/app/lib/pptx/text-lines.ts +109 -0
- package/src/app/lib/pptx/units.ts +22 -0
- package/src/app/lib/transition.test.ts +31 -0
- package/src/app/lib/transition.ts +13 -0
- package/src/app/lib/use-document-title.test.ts +14 -0
- package/src/app/lib/use-document-title.ts +16 -0
- package/src/app/routes/presenter.tsx +2 -0
- package/src/app/routes/slide.tsx +23 -27
- package/src/locale/en.ts +1 -3
- package/src/locale/ja.ts +1 -3
- package/src/locale/types.ts +1 -2
- package/src/locale/zh-cn.ts +1 -2
- package/src/locale/zh-tw.ts +1 -2
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { createElement } from 'react';
|
|
2
|
+
import { flushSync } from 'react-dom';
|
|
3
|
+
import { createRoot, type Root } from 'react-dom/client';
|
|
4
|
+
import { designToCssVars } from '../design';
|
|
5
|
+
import { nextPaint, sleep } from '../dom';
|
|
6
|
+
import { SlidePageProvider } from '../page-context';
|
|
7
|
+
import { isFrameAnimationSettled, waitForDataWaitfor, waitForFonts } from '../print-ready';
|
|
8
|
+
import { CANVAS_HEIGHT, CANVAS_WIDTH, type SlideModule } from '../sdk';
|
|
9
|
+
|
|
10
|
+
const ANIMATION_TIMEOUT_MS = 15_000;
|
|
11
|
+
const POLL_INTERVAL_MS = 100;
|
|
12
|
+
|
|
13
|
+
export type MountedDeck = {
|
|
14
|
+
container: HTMLElement;
|
|
15
|
+
frames: HTMLElement[];
|
|
16
|
+
dispose: () => void;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// Fast-forward every animation to its end frame in the live DOM: a large negative
|
|
20
|
+
// delay lands past a 1ms duration, so even pseudo-elements paint their final state
|
|
21
|
+
// on the first frame, and html-to-image clones never replay the hidden 0% keyframe.
|
|
22
|
+
function captureStyleText(captureClass: string): string {
|
|
23
|
+
return `.${captureClass} *, .${captureClass} *::before, .${captureClass} *::after {
|
|
24
|
+
animation-delay: -1s !important;
|
|
25
|
+
animation-duration: 1ms !important;
|
|
26
|
+
animation-iteration-count: 1 !important;
|
|
27
|
+
animation-fill-mode: forwards !important;
|
|
28
|
+
transition: none !important;
|
|
29
|
+
}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function mountDeckOffscreen(
|
|
33
|
+
slide: SlideModule,
|
|
34
|
+
captureClass: string,
|
|
35
|
+
): Promise<MountedDeck> {
|
|
36
|
+
const pages = slide.default ?? [];
|
|
37
|
+
const container = document.createElement('div');
|
|
38
|
+
container.className = captureClass;
|
|
39
|
+
container.setAttribute('aria-hidden', 'true');
|
|
40
|
+
Object.assign(container.style, {
|
|
41
|
+
position: 'fixed',
|
|
42
|
+
left: '-99999px',
|
|
43
|
+
top: '0',
|
|
44
|
+
pointerEvents: 'none',
|
|
45
|
+
});
|
|
46
|
+
document.body.appendChild(container);
|
|
47
|
+
|
|
48
|
+
const captureStyle = document.createElement('style');
|
|
49
|
+
captureStyle.textContent = captureStyleText(captureClass);
|
|
50
|
+
document.head.appendChild(captureStyle);
|
|
51
|
+
|
|
52
|
+
const designVars = slide.design ? designToCssVars(slide.design) : null;
|
|
53
|
+
const roots: Root[] = [];
|
|
54
|
+
const frames: HTMLElement[] = [];
|
|
55
|
+
const dispose = () => {
|
|
56
|
+
for (const root of roots) root.unmount();
|
|
57
|
+
container.remove();
|
|
58
|
+
captureStyle.remove();
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
for (let i = 0; i < pages.length; i++) {
|
|
63
|
+
const Page = pages[i];
|
|
64
|
+
if (!Page) continue;
|
|
65
|
+
const host = document.createElement('div');
|
|
66
|
+
host.setAttribute('data-osd-canvas', '');
|
|
67
|
+
host.style.width = `${CANVAS_WIDTH}px`;
|
|
68
|
+
host.style.height = `${CANVAS_HEIGHT}px`;
|
|
69
|
+
host.style.overflow = 'hidden';
|
|
70
|
+
host.style.background = designVars?.['--osd-bg'] ?? '#fff';
|
|
71
|
+
if (designVars) {
|
|
72
|
+
for (const [k, v] of Object.entries(designVars)) host.style.setProperty(k, v);
|
|
73
|
+
}
|
|
74
|
+
container.appendChild(host);
|
|
75
|
+
frames.push(host);
|
|
76
|
+
const root = createRoot(host);
|
|
77
|
+
roots.push(root);
|
|
78
|
+
// Commit synchronously: measurement starts right after mounting, and a
|
|
79
|
+
// concurrent render could otherwise leave later pages empty at that point.
|
|
80
|
+
flushSync(() => {
|
|
81
|
+
root.render(
|
|
82
|
+
createElement(SlidePageProvider, { index: i, total: pages.length }, createElement(Page)),
|
|
83
|
+
);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
await nextPaint();
|
|
88
|
+
await waitForFonts();
|
|
89
|
+
const deadline = performance.now() + ANIMATION_TIMEOUT_MS;
|
|
90
|
+
while (performance.now() < deadline) {
|
|
91
|
+
if (frames.every((frame) => isFrameAnimationSettled(frame))) break;
|
|
92
|
+
await sleep(POLL_INTERVAL_MS);
|
|
93
|
+
}
|
|
94
|
+
await waitForDataWaitfor(container);
|
|
95
|
+
await waitForFonts();
|
|
96
|
+
} catch (err) {
|
|
97
|
+
dispose();
|
|
98
|
+
throw err;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return { container, frames, dispose };
|
|
102
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { GradientStop, Radii, Rgba } from './css';
|
|
2
|
+
|
|
3
|
+
export type Rect = { x: number; y: number; w: number; h: number };
|
|
4
|
+
|
|
5
|
+
export type ImageFormat = 'png' | 'jpeg' | 'gif' | 'svg';
|
|
6
|
+
|
|
7
|
+
export type SceneImage = {
|
|
8
|
+
id: number;
|
|
9
|
+
bytes: Uint8Array;
|
|
10
|
+
format: ImageFormat;
|
|
11
|
+
/** Vector companion embedded next to the PNG fallback via svgBlip. */
|
|
12
|
+
svg?: Uint8Array;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/** Fractions (0..1) of the source image trimmed from each edge. */
|
|
16
|
+
export type Crop = { l: number; t: number; r: number; b: number };
|
|
17
|
+
|
|
18
|
+
export type Fill =
|
|
19
|
+
| { kind: 'solid'; color: Rgba }
|
|
20
|
+
| { kind: 'gradient'; angleDeg: number; stops: GradientStop[] }
|
|
21
|
+
| { kind: 'image'; imageId: number; crop: Crop | null; alpha: number };
|
|
22
|
+
|
|
23
|
+
export type Outline = { width: number; color: Rgba; dash: 'solid' | 'dash' | 'dot' };
|
|
24
|
+
|
|
25
|
+
export type ShadowEffect = {
|
|
26
|
+
blur: number;
|
|
27
|
+
dist: number;
|
|
28
|
+
dirDeg: number;
|
|
29
|
+
color: Rgba;
|
|
30
|
+
spread: number;
|
|
31
|
+
inner: boolean;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type Geometry =
|
|
35
|
+
| { kind: 'rect' }
|
|
36
|
+
| { kind: 'roundRect'; radius: number }
|
|
37
|
+
| { kind: 'ellipse' }
|
|
38
|
+
| { kind: 'custom'; radii: Radii };
|
|
39
|
+
|
|
40
|
+
type NodeBase = {
|
|
41
|
+
name: string;
|
|
42
|
+
box: Rect;
|
|
43
|
+
rotationDeg: number;
|
|
44
|
+
flipV: boolean;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type ShapeNode = NodeBase & {
|
|
48
|
+
kind: 'shape';
|
|
49
|
+
geometry: Geometry;
|
|
50
|
+
fill: Fill | null;
|
|
51
|
+
outline: Outline | null;
|
|
52
|
+
shadow: ShadowEffect | null;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export type PictureNode = NodeBase & {
|
|
56
|
+
kind: 'picture';
|
|
57
|
+
imageId: number;
|
|
58
|
+
crop: Crop | null;
|
|
59
|
+
alpha: number;
|
|
60
|
+
geometry: Geometry;
|
|
61
|
+
outline: Outline | null;
|
|
62
|
+
shadow: ShadowEffect | null;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export type TextShadow = { blur: number; dist: number; dirDeg: number; color: Rgba };
|
|
66
|
+
|
|
67
|
+
export type RunStyle = {
|
|
68
|
+
font: string;
|
|
69
|
+
sizePx: number;
|
|
70
|
+
bold: boolean;
|
|
71
|
+
italic: boolean;
|
|
72
|
+
underline: boolean;
|
|
73
|
+
strike: boolean;
|
|
74
|
+
color: Rgba;
|
|
75
|
+
letterSpacingPx: number;
|
|
76
|
+
baselineShift: 'super' | 'sub' | null;
|
|
77
|
+
shadow: TextShadow | null;
|
|
78
|
+
outline: { width: number; color: Rgba } | null;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export type Run = { text: string; style: RunStyle };
|
|
82
|
+
|
|
83
|
+
export type TextLine = { runs: Run[]; sizePx: number };
|
|
84
|
+
|
|
85
|
+
export type Bullet =
|
|
86
|
+
| { kind: 'char'; char: string; color: Rgba; font: string | null }
|
|
87
|
+
| { kind: 'number'; scheme: string; startAt: number; color: Rgba };
|
|
88
|
+
|
|
89
|
+
export type Paragraph = {
|
|
90
|
+
lineSpacingPx: number;
|
|
91
|
+
lines: TextLine[];
|
|
92
|
+
align: 'l' | 'ctr' | 'r' | 'just';
|
|
93
|
+
bullet: Bullet | null;
|
|
94
|
+
marginLeftPx: number;
|
|
95
|
+
indentPx: number;
|
|
96
|
+
endSizePx: number;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export type TextNode = NodeBase & {
|
|
100
|
+
kind: 'text';
|
|
101
|
+
paragraphs: Paragraph[];
|
|
102
|
+
/** Uniform scale carried by the world transform; font metrics are pre-multiplied. */
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export type SceneNode = ShapeNode | PictureNode | TextNode;
|
|
106
|
+
|
|
107
|
+
export type SlideScene = {
|
|
108
|
+
background: Fill | null;
|
|
109
|
+
nodes: SceneNode[];
|
|
110
|
+
notes: string | null;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export type DeckScene = {
|
|
114
|
+
slides: SlideScene[];
|
|
115
|
+
images: SceneImage[];
|
|
116
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import type { RunStyle } from './scene';
|
|
3
|
+
import { type Atom, fillEmptyLines, groupAtomsIntoLines, lineToRuns } from './text-lines';
|
|
4
|
+
|
|
5
|
+
const style = (over: Partial<RunStyle> = {}): RunStyle => ({
|
|
6
|
+
font: 'Arial',
|
|
7
|
+
sizePx: 40,
|
|
8
|
+
bold: false,
|
|
9
|
+
italic: false,
|
|
10
|
+
underline: false,
|
|
11
|
+
strike: false,
|
|
12
|
+
color: { r: 0, g: 0, b: 0, a: 1 },
|
|
13
|
+
letterSpacingPx: 0,
|
|
14
|
+
baselineShift: null,
|
|
15
|
+
shadow: null,
|
|
16
|
+
outline: null,
|
|
17
|
+
...over,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const atom = (
|
|
21
|
+
text: string,
|
|
22
|
+
x: number,
|
|
23
|
+
y: number,
|
|
24
|
+
w = 10,
|
|
25
|
+
h = 44,
|
|
26
|
+
key = 'a',
|
|
27
|
+
over: Partial<Atom> = {},
|
|
28
|
+
): Atom => ({
|
|
29
|
+
text,
|
|
30
|
+
rect: { x, y, w, h },
|
|
31
|
+
styleKey: key,
|
|
32
|
+
style: style(),
|
|
33
|
+
preserveSpaces: false,
|
|
34
|
+
...over,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('groupAtomsIntoLines', () => {
|
|
38
|
+
it('starts a new line when x moves back or y moves fully below', () => {
|
|
39
|
+
const lines = groupAtomsIntoLines([
|
|
40
|
+
atom('H', 0, 10),
|
|
41
|
+
atom('i', 10, 10),
|
|
42
|
+
atom('t', 0, 74),
|
|
43
|
+
atom('x', 300, 74),
|
|
44
|
+
atom('y', 320, 140),
|
|
45
|
+
]);
|
|
46
|
+
expect(lines.map((l) => l.atoms.map((a) => a.text).join(''))).toEqual(['Hi', 'tx', 'y']);
|
|
47
|
+
expect(lines[0]).toMatchObject({ top: 10, bottom: 54, left: 0, right: 20 });
|
|
48
|
+
});
|
|
49
|
+
it('keeps superscripts on the same line', () => {
|
|
50
|
+
const lines = groupAtomsIntoLines([atom('x', 0, 10), atom('2', 10, 0, 6, 26)]);
|
|
51
|
+
expect(lines).toHaveLength(1);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe('fillEmptyLines', () => {
|
|
56
|
+
it('inserts blank lines for multi-pitch gaps', () => {
|
|
57
|
+
const lines = fillEmptyLines(
|
|
58
|
+
groupAtomsIntoLines([atom('a', 0, 0), atom('b', 0, 60), atom('c', 0, 180)]),
|
|
59
|
+
);
|
|
60
|
+
expect(lines).toHaveLength(4);
|
|
61
|
+
expect(lines[2].atoms).toHaveLength(0);
|
|
62
|
+
expect(lines[2].bottom).toBeCloseTo(164);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe('lineToRuns', () => {
|
|
67
|
+
it('merges same-style atoms, collapses whitespace and trims line edges', () => {
|
|
68
|
+
const [line] = groupAtomsIntoLines([
|
|
69
|
+
atom(' Hello ', 0, 0, 100),
|
|
70
|
+
atom(' big', 100, 0, 50, 44, 'b'),
|
|
71
|
+
atom(' world ', 150, 0, 80, 44, 'b'),
|
|
72
|
+
]);
|
|
73
|
+
const { runs } = lineToRuns(line);
|
|
74
|
+
expect(runs.map((r) => r.text)).toEqual(['Hello ', 'big world']);
|
|
75
|
+
});
|
|
76
|
+
it('keeps indentation for preformatted text', () => {
|
|
77
|
+
const [line] = groupAtomsIntoLines([
|
|
78
|
+
atom(' const x', 0, 0, 100, 44, 'a', { preserveSpaces: true }),
|
|
79
|
+
]);
|
|
80
|
+
expect(lineToRuns(line).runs[0].text).toBe(' const x');
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { Rect, Run, RunStyle, TextLine } from './scene';
|
|
2
|
+
|
|
3
|
+
export type Atom = {
|
|
4
|
+
text: string;
|
|
5
|
+
rect: Rect;
|
|
6
|
+
styleKey: string;
|
|
7
|
+
style: RunStyle;
|
|
8
|
+
preserveSpaces: boolean;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type AtomLine = {
|
|
12
|
+
atoms: Atom[];
|
|
13
|
+
top: number;
|
|
14
|
+
bottom: number;
|
|
15
|
+
left: number;
|
|
16
|
+
right: number;
|
|
17
|
+
sizePx: number;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const VERTICAL_TOLERANCE = 1;
|
|
21
|
+
const HORIZONTAL_TOLERANCE = 1;
|
|
22
|
+
|
|
23
|
+
export function groupAtomsIntoLines(atoms: Atom[]): AtomLine[] {
|
|
24
|
+
const lines: AtomLine[] = [];
|
|
25
|
+
let current: Atom[] = [];
|
|
26
|
+
let prev: Atom | null = null;
|
|
27
|
+
for (const atom of atoms) {
|
|
28
|
+
if (prev) {
|
|
29
|
+
const movedBack = atom.rect.x < prev.rect.x + prev.rect.w - HORIZONTAL_TOLERANCE;
|
|
30
|
+
const below = atom.rect.y >= prev.rect.y + prev.rect.h - VERTICAL_TOLERANCE;
|
|
31
|
+
if (movedBack || below) {
|
|
32
|
+
pushLine(lines, current);
|
|
33
|
+
current = [];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
current.push(atom);
|
|
37
|
+
prev = atom;
|
|
38
|
+
}
|
|
39
|
+
pushLine(lines, current);
|
|
40
|
+
return lines;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function pushLine(lines: AtomLine[], atoms: Atom[]): void {
|
|
44
|
+
if (atoms.length === 0) return;
|
|
45
|
+
const top = Math.min(...atoms.map((a) => a.rect.y));
|
|
46
|
+
const bottom = Math.max(...atoms.map((a) => a.rect.y + a.rect.h));
|
|
47
|
+
const left = Math.min(...atoms.map((a) => a.rect.x));
|
|
48
|
+
const right = Math.max(...atoms.map((a) => a.rect.x + a.rect.w));
|
|
49
|
+
const sizePx = Math.max(...atoms.map((a) => a.style.sizePx));
|
|
50
|
+
lines.push({ atoms, top, bottom, left, right, sizePx });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Lines that carry no glyphs (blank `<br>` rows, empty lines in `pre` text) never
|
|
55
|
+
* produce atoms, so a jump of k pitches between neighbours means k-1 empty lines.
|
|
56
|
+
*/
|
|
57
|
+
export function fillEmptyLines(lines: AtomLine[]): AtomLine[] {
|
|
58
|
+
if (lines.length < 2) return lines;
|
|
59
|
+
const pitches: number[] = [];
|
|
60
|
+
for (let i = 1; i < lines.length; i++) pitches.push(lines[i].bottom - lines[i - 1].bottom);
|
|
61
|
+
const base = Math.min(...pitches.filter((p) => p > 0.5));
|
|
62
|
+
if (!Number.isFinite(base)) return lines;
|
|
63
|
+
const out: AtomLine[] = [lines[0]];
|
|
64
|
+
for (let i = 1; i < lines.length; i++) {
|
|
65
|
+
const pitch = pitches[i - 1];
|
|
66
|
+
const k = Math.round(pitch / base);
|
|
67
|
+
if (k >= 2 && Math.abs(pitch - k * base) < base * 0.15) {
|
|
68
|
+
const prev = lines[i - 1];
|
|
69
|
+
for (let j = 1; j < k; j++) {
|
|
70
|
+
out.push({
|
|
71
|
+
atoms: [],
|
|
72
|
+
top: prev.top + (base * j * (lines[i].top - prev.top)) / pitch,
|
|
73
|
+
bottom: prev.bottom + base * j,
|
|
74
|
+
left: prev.left,
|
|
75
|
+
right: prev.left,
|
|
76
|
+
sizePx: prev.sizePx,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
out.push(lines[i]);
|
|
81
|
+
}
|
|
82
|
+
return out;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function lineToRuns(line: AtomLine): TextLine {
|
|
86
|
+
const runs: Run[] = [];
|
|
87
|
+
const keys: string[] = [];
|
|
88
|
+
for (const atom of line.atoms) {
|
|
89
|
+
let text = atom.text;
|
|
90
|
+
if (!atom.preserveSpaces) {
|
|
91
|
+
text = text.replace(/[\t\n\r ]+/g, ' ');
|
|
92
|
+
const prevText = runs[runs.length - 1]?.text ?? '';
|
|
93
|
+
if (text.startsWith(' ') && (prevText === '' || prevText.endsWith(' '))) text = text.slice(1);
|
|
94
|
+
}
|
|
95
|
+
if (text.length === 0) continue;
|
|
96
|
+
const last = runs[runs.length - 1];
|
|
97
|
+
if (last && keys[keys.length - 1] === atom.styleKey) last.text += text;
|
|
98
|
+
else {
|
|
99
|
+
runs.push({ text, style: atom.style });
|
|
100
|
+
keys.push(atom.styleKey);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const tail = runs[runs.length - 1];
|
|
104
|
+
if (tail && !line.atoms[line.atoms.length - 1]?.preserveSpaces) {
|
|
105
|
+
tail.text = tail.text.replace(/ +$/, '');
|
|
106
|
+
if (tail.text.length === 0) runs.pop();
|
|
107
|
+
}
|
|
108
|
+
return { runs, sizePx: line.sizePx };
|
|
109
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CANVAS_HEIGHT, CANVAS_WIDTH } from '../sdk';
|
|
2
|
+
|
|
3
|
+
export const EMU_PER_PX = 6350;
|
|
4
|
+
export const SLIDE_EMU_W = CANVAS_WIDTH * EMU_PER_PX;
|
|
5
|
+
export const SLIDE_EMU_H = CANVAS_HEIGHT * EMU_PER_PX;
|
|
6
|
+
|
|
7
|
+
export function px(value: number): number {
|
|
8
|
+
return Math.round(value * EMU_PER_PX);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// The 1920px canvas spans 13.333in, so one canvas pixel is exactly half a point.
|
|
12
|
+
export function pxToHundredthsPt(value: number): number {
|
|
13
|
+
return Math.round(value * 50);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function degrees(value: number): number {
|
|
17
|
+
return Math.round((((value % 360) + 360) % 360) * 60000);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function percent(value: number): number {
|
|
21
|
+
return Math.round(Math.min(1, Math.max(0, value)) * 100000);
|
|
22
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { holdOpacity } from './transition';
|
|
3
|
+
|
|
4
|
+
describe('holdOpacity', () => {
|
|
5
|
+
it('drops opacity from array keyframes and keeps everything else', () => {
|
|
6
|
+
const phase = holdOpacity({
|
|
7
|
+
duration: 140,
|
|
8
|
+
keyframes: [
|
|
9
|
+
{ opacity: 1, transform: 'translateY(0)' },
|
|
10
|
+
{ opacity: 0, transform: 'translateY(-4px)', offset: 1 },
|
|
11
|
+
],
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
expect(phase).toEqual({
|
|
15
|
+
duration: 140,
|
|
16
|
+
keyframes: [{ transform: 'translateY(0)' }, { transform: 'translateY(-4px)', offset: 1 }],
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('drops opacity from property-indexed keyframes', () => {
|
|
21
|
+
const phase = holdOpacity({
|
|
22
|
+
keyframes: { opacity: [1, 0], transform: ['scale(1)', 'scale(1.01)'] },
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
expect(phase?.keyframes).toEqual({ transform: ['scale(1)', 'scale(1.01)'] });
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('passes an undefined phase through', () => {
|
|
29
|
+
expect(holdOpacity(undefined)).toBeUndefined();
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -13,6 +13,7 @@ export type SlideTransition = {
|
|
|
13
13
|
enter?: TransitionPhase;
|
|
14
14
|
exit?: TransitionPhase;
|
|
15
15
|
morph?: boolean | MorphTransition;
|
|
16
|
+
throughBackground?: boolean;
|
|
16
17
|
};
|
|
17
18
|
|
|
18
19
|
export type MorphTransition = {
|
|
@@ -28,3 +29,15 @@ export function resolveTransition(
|
|
|
28
29
|
): SlideTransition | undefined {
|
|
29
30
|
return pages[index]?.transition ?? moduleDefault;
|
|
30
31
|
}
|
|
32
|
+
|
|
33
|
+
export function holdOpacity(phase: TransitionPhase | undefined): TransitionPhase | undefined {
|
|
34
|
+
if (!phase) return phase;
|
|
35
|
+
if (Array.isArray(phase.keyframes)) {
|
|
36
|
+
return {
|
|
37
|
+
...phase,
|
|
38
|
+
keyframes: phase.keyframes.map(({ opacity: _opacity, ...frame }) => frame),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const { opacity: _opacity, ...keyframes } = phase.keyframes;
|
|
42
|
+
return { ...phase, keyframes };
|
|
43
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { DEFAULT_DOCUMENT_TITLE, resolveDocumentTitle } from './use-document-title.ts';
|
|
3
|
+
|
|
4
|
+
describe('resolveDocumentTitle', () => {
|
|
5
|
+
it('uses the deck title', () => {
|
|
6
|
+
expect(resolveDocumentTitle('Quarterly Product Review')).toBe('Quarterly Product Review');
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('falls back when the deck has no title', () => {
|
|
10
|
+
expect(resolveDocumentTitle()).toBe(DEFAULT_DOCUMENT_TITLE);
|
|
11
|
+
expect(resolveDocumentTitle('')).toBe(DEFAULT_DOCUMENT_TITLE);
|
|
12
|
+
expect(resolveDocumentTitle(' ')).toBe(DEFAULT_DOCUMENT_TITLE);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_DOCUMENT_TITLE = 'open-slide';
|
|
4
|
+
|
|
5
|
+
export function resolveDocumentTitle(title?: string): string {
|
|
6
|
+
return title?.trim() || DEFAULT_DOCUMENT_TITLE;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function useDocumentTitle(title?: string) {
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
document.title = resolveDocumentTitle(title);
|
|
12
|
+
return () => {
|
|
13
|
+
document.title = DEFAULT_DOCUMENT_TITLE;
|
|
14
|
+
};
|
|
15
|
+
}, [title]);
|
|
16
|
+
}
|
|
@@ -21,6 +21,7 @@ import { useNavigate, useParams } from 'react-router-dom';
|
|
|
21
21
|
import { Button } from '@/components/ui/button';
|
|
22
22
|
import { Dialog, DialogContent, DialogTitle, DialogTrigger } from '@/components/ui/dialog';
|
|
23
23
|
import { hasModifier, isBackwardKey, isForwardKey, isTypingTarget } from '@/lib/keys';
|
|
24
|
+
import { useDocumentTitle } from '@/lib/use-document-title';
|
|
24
25
|
import { format, useLocale } from '@/lib/use-locale';
|
|
25
26
|
import { cn, pad2 } from '@/lib/utils';
|
|
26
27
|
import {
|
|
@@ -38,6 +39,7 @@ import { useSlideModule } from '../lib/use-slide-module';
|
|
|
38
39
|
export function Presenter() {
|
|
39
40
|
const { slideId = '' } = useParams();
|
|
40
41
|
const { slide, error } = useSlideModule(slideId);
|
|
42
|
+
useDocumentTitle(slide?.meta?.title);
|
|
41
43
|
|
|
42
44
|
// Presenter view is a passive mirror of the projection window. It only
|
|
43
45
|
// tracks the index it last heard about; navigation buttons send commands
|
package/src/app/routes/slide.tsx
CHANGED
|
@@ -57,6 +57,7 @@ import { hasModifier, isBackwardKey, isForwardKey, isTypingTarget } from '@/lib/
|
|
|
57
57
|
import { readLastHomeLocation } from '@/lib/last-home-location';
|
|
58
58
|
import { useAgentSocketConnected } from '@/lib/use-agent-socket';
|
|
59
59
|
import { useClickPageNavigation } from '@/lib/use-click-page-navigation';
|
|
60
|
+
import { useDocumentTitle } from '@/lib/use-document-title';
|
|
60
61
|
import { useIsMobile } from '@/lib/use-is-mobile';
|
|
61
62
|
import { format, useLocale } from '@/lib/use-locale';
|
|
62
63
|
import { useWheelPageNavigation } from '@/lib/use-wheel-page-navigation';
|
|
@@ -72,7 +73,11 @@ import { SlideTransitionLayer } from '../components/slide-transition-layer';
|
|
|
72
73
|
import { type ThumbnailActions, ThumbnailRail } from '../components/thumbnail-rail';
|
|
73
74
|
import { exportSlideAsHtml } from '../lib/export-html';
|
|
74
75
|
import { exportSlideAsPdf, isSafari, type PdfExportProgress } from '../lib/export-pdf';
|
|
75
|
-
import {
|
|
76
|
+
import {
|
|
77
|
+
exportSlideAsImagePptx,
|
|
78
|
+
exportSlideAsPptx,
|
|
79
|
+
type PptxExportProgress,
|
|
80
|
+
} from '../lib/export-pptx';
|
|
76
81
|
import { remapNotesSessionCacheAfterReorder } from '../lib/inspector/use-notes';
|
|
77
82
|
import type { SlideModule } from '../lib/sdk';
|
|
78
83
|
import { usePrefersReducedMotion } from '../lib/use-prefers-reduced-motion';
|
|
@@ -97,6 +102,7 @@ export function Slide() {
|
|
|
97
102
|
}
|
|
98
103
|
}, [navigate]);
|
|
99
104
|
const { slide, error } = useSlideModule(slideId);
|
|
105
|
+
useDocumentTitle(slide?.meta?.title);
|
|
100
106
|
const [playMode, setPlayMode] = useState<'window' | 'fullscreen' | null>(null);
|
|
101
107
|
// Last deck the Player showed. During a presenter-driven deck switch the
|
|
102
108
|
// route's slideId changes while the new module loads and warms; rendering
|
|
@@ -543,6 +549,17 @@ export function Slide() {
|
|
|
543
549
|
});
|
|
544
550
|
};
|
|
545
551
|
|
|
552
|
+
const exportPptx = async () => {
|
|
553
|
+
if (!slide || exporting) return;
|
|
554
|
+
await runProgressExport<PptxExportProgress>({
|
|
555
|
+
kind: 'pptx',
|
|
556
|
+
initial: { phase: 'processing', current: 0, total: pages.length, percent: 0 },
|
|
557
|
+
failedMessage: t.slide.pptxExportFailed,
|
|
558
|
+
renderToast: (progress) => <PptxProgressToast progress={progress} />,
|
|
559
|
+
run: (onProgress) => exportSlideAsPptx(slide, slideId, onProgress),
|
|
560
|
+
});
|
|
561
|
+
};
|
|
562
|
+
|
|
546
563
|
const exportImagePptx = async () => {
|
|
547
564
|
if (!slide || exporting) return;
|
|
548
565
|
await runProgressExport<PptxExportProgress>({
|
|
@@ -565,36 +582,14 @@ export function Slide() {
|
|
|
565
582
|
{t.slide.exportAsPdf}
|
|
566
583
|
</DropdownMenuItem>
|
|
567
584
|
<DropdownMenuSeparator />
|
|
585
|
+
<DropdownMenuItem disabled={exporting} onClick={exportPptx}>
|
|
586
|
+
<Presentation />
|
|
587
|
+
{t.slide.exportAsPptx}
|
|
588
|
+
</DropdownMenuItem>
|
|
568
589
|
<DropdownMenuItem disabled={exporting} onClick={exportImagePptx}>
|
|
569
590
|
<FileImage />
|
|
570
591
|
{t.slide.exportAsImagePptx}
|
|
571
592
|
</DropdownMenuItem>
|
|
572
|
-
<TooltipProvider delay={200}>
|
|
573
|
-
<Tooltip>
|
|
574
|
-
<TooltipTrigger
|
|
575
|
-
render={
|
|
576
|
-
<div
|
|
577
|
-
aria-disabled
|
|
578
|
-
className="relative flex cursor-help items-center justify-between gap-2 rounded-[5px] px-2 py-1.5 text-[12.5px] opacity-45 select-none [&_svg]:size-3.5 [&_svg]:shrink-0 [&_svg]:opacity-80"
|
|
579
|
-
>
|
|
580
|
-
<span className="flex items-center gap-2">
|
|
581
|
-
<Presentation />
|
|
582
|
-
{t.slide.exportAsPptx}
|
|
583
|
-
</span>
|
|
584
|
-
<span className="rounded-[3px] bg-muted px-1.5 py-0.5 font-mono text-[9.5px] tracking-[0.04em] text-muted-foreground">
|
|
585
|
-
{t.slide.comingSoon}
|
|
586
|
-
</span>
|
|
587
|
-
</div>
|
|
588
|
-
}
|
|
589
|
-
/>
|
|
590
|
-
<TooltipContent
|
|
591
|
-
side="left"
|
|
592
|
-
className="w-max max-w-[min(520px,calc(100vw-2rem))] text-center leading-relaxed"
|
|
593
|
-
>
|
|
594
|
-
{t.slide.pptxComingSoonTooltip}
|
|
595
|
-
</TooltipContent>
|
|
596
|
-
</Tooltip>
|
|
597
|
-
</TooltipProvider>
|
|
598
593
|
</>
|
|
599
594
|
);
|
|
600
595
|
|
|
@@ -894,6 +889,7 @@ export function Slide() {
|
|
|
894
889
|
onToggleDesignPanel: () => setDesignOpen((v) => !v),
|
|
895
890
|
onExportHtml: exportHtml,
|
|
896
891
|
onExportPdf: exportPdf,
|
|
892
|
+
onExportPptx: exportPptx,
|
|
897
893
|
onExportImagePptx: exportImagePptx,
|
|
898
894
|
onGoToPage: goTo,
|
|
899
895
|
}}
|
package/src/locale/en.ts
CHANGED
|
@@ -113,10 +113,8 @@ export const en: Locale = {
|
|
|
113
113
|
exportAsPdf: 'Export as PDF',
|
|
114
114
|
exportAsImagePptx: 'Export as image PPTX',
|
|
115
115
|
exportAsPptx: 'Export as PPTX',
|
|
116
|
-
comingSoon: 'Coming soon',
|
|
117
|
-
pptxComingSoonTooltip:
|
|
118
|
-
'Editable PPTX export isn’t ready yet. For now, use “Export as image PPTX” instead.',
|
|
119
116
|
pdfExportFailed: 'PDF export failed',
|
|
117
|
+
pptxExportFailed: 'PPTX export failed',
|
|
120
118
|
imagePptxExportFailed: 'PPTX export failed',
|
|
121
119
|
pdfExportSafariUnsupported:
|
|
122
120
|
'Export as PDF is not supported on Safari. Please try a Chromium-based browser instead.',
|
package/src/locale/ja.ts
CHANGED
|
@@ -113,10 +113,8 @@ export const ja: Locale = {
|
|
|
113
113
|
exportAsPdf: 'PDF として書き出し',
|
|
114
114
|
exportAsImagePptx: '画像 PPTX として書き出し',
|
|
115
115
|
exportAsPptx: 'PPTX として書き出し',
|
|
116
|
-
comingSoon: '近日公開',
|
|
117
|
-
pptxComingSoonTooltip:
|
|
118
|
-
'編集可能な PPTX の書き出しはまだ対応していません。それまでは「画像 PPTX として書き出し」をご利用ください。',
|
|
119
116
|
pdfExportFailed: 'PDF の書き出しに失敗しました',
|
|
117
|
+
pptxExportFailed: 'PPTX の書き出しに失敗しました',
|
|
120
118
|
imagePptxExportFailed: 'PPTX の書き出しに失敗しました',
|
|
121
119
|
pdfExportSafariUnsupported:
|
|
122
120
|
'PDF の書き出しは現在 Safari では対応していません。Chromium ベースのブラウザでお試しください。',
|
package/src/locale/types.ts
CHANGED
|
@@ -115,9 +115,8 @@ export type Locale = {
|
|
|
115
115
|
exportAsPdf: string;
|
|
116
116
|
exportAsImagePptx: string;
|
|
117
117
|
exportAsPptx: string;
|
|
118
|
-
comingSoon: string;
|
|
119
|
-
pptxComingSoonTooltip: string;
|
|
120
118
|
pdfExportFailed: string;
|
|
119
|
+
pptxExportFailed: string;
|
|
121
120
|
imagePptxExportFailed: string;
|
|
122
121
|
pdfExportSafariUnsupported: string;
|
|
123
122
|
present: string;
|
package/src/locale/zh-cn.ts
CHANGED
|
@@ -112,9 +112,8 @@ export const zhCN: Locale = {
|
|
|
112
112
|
exportAsPdf: '导出为 PDF',
|
|
113
113
|
exportAsImagePptx: '导出图片 PPTX',
|
|
114
114
|
exportAsPptx: '导出 PPTX',
|
|
115
|
-
comingSoon: '即将推出',
|
|
116
|
-
pptxComingSoonTooltip: '可编辑的 PPTX 导出尚未支持,在此之前可以先使用“导出图片 PPTX”。',
|
|
117
115
|
pdfExportFailed: 'PDF 导出失败',
|
|
116
|
+
pptxExportFailed: 'PPTX 导出失败',
|
|
118
117
|
imagePptxExportFailed: 'PPTX 导出失败',
|
|
119
118
|
pdfExportSafariUnsupported:
|
|
120
119
|
'导出 PDF 目前不支持 Safari 设备,请尝试使用基于 Chromium 的浏览器替代。',
|