@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,116 @@
|
|
|
1
|
+
import type { ImageFormat, SceneImage } from './scene';
|
|
2
|
+
|
|
3
|
+
export type LoadedImage = { id: number; width: number; height: number };
|
|
4
|
+
|
|
5
|
+
function sniffFormat(bytes: Uint8Array): ImageFormat | 'other' {
|
|
6
|
+
if (bytes.length > 8 && bytes[0] === 0x89 && bytes[1] === 0x50 && bytes[2] === 0x4e) return 'png';
|
|
7
|
+
if (bytes.length > 3 && bytes[0] === 0xff && bytes[1] === 0xd8 && bytes[2] === 0xff)
|
|
8
|
+
return 'jpeg';
|
|
9
|
+
if (bytes.length > 6 && bytes[0] === 0x47 && bytes[1] === 0x49 && bytes[2] === 0x46) return 'gif';
|
|
10
|
+
const head = new TextDecoder('utf-8', { fatal: false })
|
|
11
|
+
.decode(bytes.subarray(0, Math.min(bytes.length, 512)))
|
|
12
|
+
.trimStart();
|
|
13
|
+
if (head.startsWith('<') && /<svg[\s>]/i.test(head)) return 'svg';
|
|
14
|
+
return 'other';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async function decodeSize(blob: Blob): Promise<{ width: number; height: number } | null> {
|
|
18
|
+
try {
|
|
19
|
+
const bitmap = await createImageBitmap(blob);
|
|
20
|
+
const size = { width: bitmap.width, height: bitmap.height };
|
|
21
|
+
bitmap.close();
|
|
22
|
+
return size;
|
|
23
|
+
} catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function encodePng(
|
|
29
|
+
source: CanvasImageSource,
|
|
30
|
+
width: number,
|
|
31
|
+
height: number,
|
|
32
|
+
): Promise<Uint8Array | null> {
|
|
33
|
+
const canvas = document.createElement('canvas');
|
|
34
|
+
canvas.width = Math.max(1, Math.round(width));
|
|
35
|
+
canvas.height = Math.max(1, Math.round(height));
|
|
36
|
+
const ctx = canvas.getContext('2d');
|
|
37
|
+
if (!ctx) return null;
|
|
38
|
+
try {
|
|
39
|
+
ctx.drawImage(source, 0, 0, canvas.width, canvas.height);
|
|
40
|
+
const blob = await new Promise<Blob | null>((resolve) => canvas.toBlob(resolve, 'image/png'));
|
|
41
|
+
return blob ? new Uint8Array(await blob.arrayBuffer()) : null;
|
|
42
|
+
} catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function loadImageElement(url: string): Promise<HTMLImageElement | null> {
|
|
48
|
+
return new Promise((resolve) => {
|
|
49
|
+
const img = new Image();
|
|
50
|
+
img.crossOrigin = 'anonymous';
|
|
51
|
+
img.onload = () => resolve(img);
|
|
52
|
+
img.onerror = () => resolve(null);
|
|
53
|
+
img.src = url;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const SVG_RASTER_SCALE = 2;
|
|
58
|
+
|
|
59
|
+
export class ImageStore {
|
|
60
|
+
readonly images: SceneImage[] = [];
|
|
61
|
+
private readonly byKey = new Map<string, Promise<LoadedImage | null>>();
|
|
62
|
+
private nextId = 1;
|
|
63
|
+
|
|
64
|
+
add(bytes: Uint8Array, format: ImageFormat, svg?: Uint8Array): number {
|
|
65
|
+
const id = this.nextId++;
|
|
66
|
+
this.images.push({ id, bytes, format, svg });
|
|
67
|
+
return id;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
fromUrl(url: string): Promise<LoadedImage | null> {
|
|
71
|
+
let pending = this.byKey.get(url);
|
|
72
|
+
if (!pending) {
|
|
73
|
+
pending = this.load(url);
|
|
74
|
+
this.byKey.set(url, pending);
|
|
75
|
+
}
|
|
76
|
+
return pending;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
private async load(url: string): Promise<LoadedImage | null> {
|
|
80
|
+
let bytes: Uint8Array | null = null;
|
|
81
|
+
try {
|
|
82
|
+
const res = await fetch(url);
|
|
83
|
+
if (res.ok) bytes = new Uint8Array(await res.arrayBuffer());
|
|
84
|
+
} catch {}
|
|
85
|
+
|
|
86
|
+
if (bytes) {
|
|
87
|
+
const format = sniffFormat(bytes);
|
|
88
|
+
if (format === 'png' || format === 'jpeg' || format === 'gif') {
|
|
89
|
+
const size = await decodeSize(new Blob([bytes as BlobPart]));
|
|
90
|
+
if (!size) return null;
|
|
91
|
+
return { id: this.add(bytes, format), ...size };
|
|
92
|
+
}
|
|
93
|
+
if (format === 'svg') {
|
|
94
|
+
const img = await loadImageElement(url);
|
|
95
|
+
if (!img || img.naturalWidth === 0) return null;
|
|
96
|
+
const png = await encodePng(
|
|
97
|
+
img,
|
|
98
|
+
img.naturalWidth * SVG_RASTER_SCALE,
|
|
99
|
+
img.naturalHeight * SVG_RASTER_SCALE,
|
|
100
|
+
);
|
|
101
|
+
if (!png) return null;
|
|
102
|
+
return {
|
|
103
|
+
id: this.add(png, 'png', bytes),
|
|
104
|
+
width: img.naturalWidth,
|
|
105
|
+
height: img.naturalHeight,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const img = await loadImageElement(url);
|
|
111
|
+
if (!img || img.naturalWidth === 0) return null;
|
|
112
|
+
const png = await encodePng(img, img.naturalWidth, img.naturalHeight);
|
|
113
|
+
if (!png) return null;
|
|
114
|
+
return { id: this.add(png, 'png'), width: img.naturalWidth, height: img.naturalHeight };
|
|
115
|
+
}
|
|
116
|
+
}
|