@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.
- package/dist/build-Bzy-qlGc.js +19 -0
- package/dist/cli/bin.js +201 -21
- package/dist/{config-AtA2Bqtn.d.ts → config-DjWifhaA.d.ts} +1 -1
- package/dist/{dev-BChELmc-.js → dev-MXa5Tod4.js} +36 -10
- 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/preview-DEpQcKz3.js +24 -0
- package/dist/{types-BzPSOxe-.d.ts → types-BWg-Dtbg.d.ts} +1 -2
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +1 -1
- package/dist/{zh-tw-BxZ_pYqe.js → zh-tw-DlKyeNX7.js} +4 -8
- package/package.json +1 -1
- 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 +172 -0
- package/src/app/lib/pptx/css.ts +450 -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 +1299 -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/routes/slide.tsx +21 -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
- package/dist/build-CfAxF6Dm.js +0 -14
- package/dist/preview-CcCQa268.js +0 -14
- package/dist/{config-C_VI2EpT.js → config-nbSvY7z_.js} +2 -2
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
import { strFromU8, unzipSync, zipSync } from 'fflate';
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
import { buildPptxFiles, escapeXml, geometryXml } from './ooxml';
|
|
6
|
+
import type { DeckScene, RunStyle } from './scene';
|
|
7
|
+
|
|
8
|
+
const PNG_1PX = Uint8Array.from(
|
|
9
|
+
atob(
|
|
10
|
+
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==',
|
|
11
|
+
),
|
|
12
|
+
(c) => c.charCodeAt(0),
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
const style: RunStyle = {
|
|
16
|
+
font: 'Inter',
|
|
17
|
+
sizePx: 40,
|
|
18
|
+
bold: true,
|
|
19
|
+
italic: false,
|
|
20
|
+
underline: false,
|
|
21
|
+
strike: false,
|
|
22
|
+
color: { r: 26, g: 24, b: 20, a: 1 },
|
|
23
|
+
letterSpacingPx: -0.8,
|
|
24
|
+
baselineShift: null,
|
|
25
|
+
shadow: null,
|
|
26
|
+
outline: null,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const deck: DeckScene = {
|
|
30
|
+
images: [{ id: 1, bytes: PNG_1PX, format: 'png' }],
|
|
31
|
+
slides: [
|
|
32
|
+
{
|
|
33
|
+
background: { kind: 'solid', color: { r: 247, g: 245, b: 240, a: 1 } },
|
|
34
|
+
notes: 'Open with the quote.\n\nPause.',
|
|
35
|
+
nodes: [
|
|
36
|
+
{
|
|
37
|
+
kind: 'shape',
|
|
38
|
+
name: 'Card',
|
|
39
|
+
box: { x: 100, y: 100, w: 400, h: 200 },
|
|
40
|
+
rotationDeg: 0,
|
|
41
|
+
flipV: false,
|
|
42
|
+
geometry: { kind: 'roundRect', radius: 24 },
|
|
43
|
+
fill: {
|
|
44
|
+
kind: 'gradient',
|
|
45
|
+
angleDeg: 90,
|
|
46
|
+
stops: [
|
|
47
|
+
{ pos: 0, color: { r: 255, g: 0, b: 0, a: 1 } },
|
|
48
|
+
{ pos: 1, color: { r: 0, g: 0, b: 255, a: 0.5 } },
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
outline: { width: 2, color: { r: 0, g: 0, b: 0, a: 1 }, dash: 'dash' },
|
|
52
|
+
shadow: {
|
|
53
|
+
blur: 30,
|
|
54
|
+
dist: 10,
|
|
55
|
+
dirDeg: 90,
|
|
56
|
+
color: { r: 0, g: 0, b: 0, a: 0.25 },
|
|
57
|
+
spread: 0,
|
|
58
|
+
inner: false,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
kind: 'text',
|
|
63
|
+
name: 'Text: Hello',
|
|
64
|
+
box: { x: 120, y: 120, w: 300, h: 128 },
|
|
65
|
+
rotationDeg: -3,
|
|
66
|
+
flipV: false,
|
|
67
|
+
paragraphs: [
|
|
68
|
+
{
|
|
69
|
+
lineSpacingPx: 64,
|
|
70
|
+
align: 'ctr',
|
|
71
|
+
bullet: { kind: 'char', char: '•', color: { r: 0, g: 0, b: 0, a: 1 }, font: 'Arial' },
|
|
72
|
+
marginLeftPx: 20,
|
|
73
|
+
indentPx: -20,
|
|
74
|
+
endSizePx: 40,
|
|
75
|
+
lines: [
|
|
76
|
+
{ runs: [{ text: 'Hello <world> & "friends"', style }], sizePx: 40 },
|
|
77
|
+
{ runs: [], sizePx: 40 },
|
|
78
|
+
{ runs: [{ text: 'again', style: { ...style, bold: false } }], sizePx: 40 },
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
kind: 'picture',
|
|
85
|
+
name: 'Image',
|
|
86
|
+
box: { x: 600, y: 100, w: 200, h: 100 },
|
|
87
|
+
rotationDeg: 0,
|
|
88
|
+
flipV: false,
|
|
89
|
+
imageId: 1,
|
|
90
|
+
crop: { l: 0.1, t: 0, r: 0.1, b: 0 },
|
|
91
|
+
alpha: 0.8,
|
|
92
|
+
geometry: { kind: 'ellipse' },
|
|
93
|
+
outline: null,
|
|
94
|
+
shadow: null,
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
},
|
|
98
|
+
{ background: null, notes: null, nodes: [] },
|
|
99
|
+
],
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
describe('buildPptxFiles', () => {
|
|
103
|
+
const files = buildPptxFiles(deck);
|
|
104
|
+
const text = (name: string) => strFromU8(files[name]);
|
|
105
|
+
|
|
106
|
+
it('emits every package part and wires the relationships', () => {
|
|
107
|
+
expect(Object.keys(files).sort()).toEqual(
|
|
108
|
+
[
|
|
109
|
+
'[Content_Types].xml',
|
|
110
|
+
'_rels/.rels',
|
|
111
|
+
'ppt/_rels/presentation.xml.rels',
|
|
112
|
+
'ppt/media/image1.png',
|
|
113
|
+
'ppt/notesMasters/_rels/notesMaster1.xml.rels',
|
|
114
|
+
'ppt/notesMasters/notesMaster1.xml',
|
|
115
|
+
'ppt/notesSlides/_rels/notesSlide1.xml.rels',
|
|
116
|
+
'ppt/notesSlides/notesSlide1.xml',
|
|
117
|
+
'ppt/presProps.xml',
|
|
118
|
+
'ppt/presentation.xml',
|
|
119
|
+
'ppt/slideLayouts/_rels/slideLayout1.xml.rels',
|
|
120
|
+
'ppt/slideLayouts/slideLayout1.xml',
|
|
121
|
+
'ppt/slideMasters/_rels/slideMaster1.xml.rels',
|
|
122
|
+
'ppt/slideMasters/slideMaster1.xml',
|
|
123
|
+
'ppt/slides/_rels/slide1.xml.rels',
|
|
124
|
+
'ppt/slides/_rels/slide2.xml.rels',
|
|
125
|
+
'ppt/slides/slide1.xml',
|
|
126
|
+
'ppt/slides/slide2.xml',
|
|
127
|
+
'ppt/theme/theme1.xml',
|
|
128
|
+
'ppt/theme/theme2.xml',
|
|
129
|
+
].sort(),
|
|
130
|
+
);
|
|
131
|
+
expect(text('ppt/presentation.xml')).toContain('<p:sldSz cx="12192000" cy="6858000"/>');
|
|
132
|
+
expect(text('ppt/presentation.xml')).toContain('<p:notesMasterId r:id="rId5"/>');
|
|
133
|
+
expect(text('ppt/slides/_rels/slide1.xml.rels')).toContain('Target="../media/image1.png"');
|
|
134
|
+
expect(text('ppt/slides/_rels/slide1.xml.rels')).toContain('notesSlides/notesSlide1.xml');
|
|
135
|
+
expect(text('ppt/slides/_rels/slide2.xml.rels')).not.toContain('notesSlide');
|
|
136
|
+
expect(text('[Content_Types].xml')).toContain('/ppt/notesSlides/notesSlide1.xml');
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('converts geometry, text and fills into DrawingML', () => {
|
|
140
|
+
const slide = text('ppt/slides/slide1.xml');
|
|
141
|
+
expect(slide).toContain(
|
|
142
|
+
'<p:bg><p:bgPr><a:solidFill><a:srgbClr val="F7F5F0"></a:srgbClr></a:solidFill>',
|
|
143
|
+
);
|
|
144
|
+
expect(slide).toContain('<a:off x="635000" y="635000"/><a:ext cx="2540000" cy="1270000"/>');
|
|
145
|
+
expect(slide).toContain(
|
|
146
|
+
'<a:prstGeom prst="roundRect"><a:avLst><a:gd name="adj" fmla="val 12000"/>',
|
|
147
|
+
);
|
|
148
|
+
expect(slide).toContain('<a:lin ang="0" scaled="0"/>');
|
|
149
|
+
expect(slide).toContain('<a:alpha val="50000"/>');
|
|
150
|
+
expect(slide).toContain('<a:prstDash val="dash"/>');
|
|
151
|
+
expect(slide).toContain('<a:outerShdw blurRad="190500" dist="63500" dir="5400000"');
|
|
152
|
+
expect(slide).toContain('<a:xfrm rot="21420000">');
|
|
153
|
+
expect(slide).toContain('<a:lnSpc><a:spcPts val="3200"/></a:lnSpc>');
|
|
154
|
+
expect(slide).toContain('marL="127000" indent="-127000" algn="ctr"');
|
|
155
|
+
expect(slide).toContain('<a:buChar char="•"/>');
|
|
156
|
+
expect(slide).toContain('sz="2000" b="1" spc="-40" dirty="0"');
|
|
157
|
+
expect(slide).toContain('<a:t>Hello <world> & "friends"</a:t>');
|
|
158
|
+
expect(slide.match(/<a:br>/g)).toHaveLength(2);
|
|
159
|
+
expect(slide).toContain('<a:latin typeface="Inter"/><a:ea typeface="Inter"/>');
|
|
160
|
+
expect(slide).toContain('<a:alphaModFix amt="80000"/>');
|
|
161
|
+
expect(slide).toContain('<a:srcRect l="10000" t="0" r="10000" b="0"/>');
|
|
162
|
+
expect(slide).toContain('<a:prstGeom prst="ellipse">');
|
|
163
|
+
expect(text('ppt/notesSlides/notesSlide1.xml')).toContain('<a:t>Open with the quote.</a:t>');
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('builds a custom rounded path for uneven corners', () => {
|
|
167
|
+
const xml = geometryXml(
|
|
168
|
+
{
|
|
169
|
+
kind: 'custom',
|
|
170
|
+
radii: [
|
|
171
|
+
{ x: 10, y: 10 },
|
|
172
|
+
{ x: 0, y: 0 },
|
|
173
|
+
{ x: 10, y: 10 },
|
|
174
|
+
{ x: 0, y: 0 },
|
|
175
|
+
],
|
|
176
|
+
},
|
|
177
|
+
{ x: 0, y: 0, w: 100, h: 50 },
|
|
178
|
+
);
|
|
179
|
+
expect(xml).toContain('<a:path w="635000" h="317500">');
|
|
180
|
+
expect(xml.match(/<a:arcTo /g)).toHaveLength(2);
|
|
181
|
+
expect(xml).toContain('stAng="10800000"');
|
|
182
|
+
expect(xml).toContain('stAng="0"');
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('strips control characters', () => {
|
|
186
|
+
expect(escapeXml('a\u0000b\u0007c\td')).toBe('abc\td');
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it('round-trips through a zip', () => {
|
|
190
|
+
const zipped = zipSync(files);
|
|
191
|
+
const unzipped = unzipSync(zipped);
|
|
192
|
+
expect(Object.keys(unzipped)).toHaveLength(Object.keys(files).length);
|
|
193
|
+
const out = process.env.PPTX_SAMPLE_OUT;
|
|
194
|
+
if (out) {
|
|
195
|
+
mkdirSync(dirname(out), { recursive: true });
|
|
196
|
+
writeFileSync(out, zipped);
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
});
|