@lemonriver/core 0.6.0 → 0.7.0

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 (44) hide show
  1. package/dist/{build-RlcGG-Ve.js → build-CKwrex8y.js} +1 -1
  2. package/dist/cli/bin.js +3 -3
  3. package/dist/{config-BJT87wE9.js → config-B1_gk0sy.js} +1641 -60
  4. package/dist/{dev-DR-j_xda.js → dev-DZ2Yzl2p.js} +1 -1
  5. package/dist/{preview-BTAhTb5B.js → preview-hMDcuHfP.js} +1 -1
  6. package/dist/vite/index.js +1 -1
  7. package/package.json +1 -1
  8. package/src/app/lemonriver/chrome/app-chrome.tsx +12 -1
  9. package/src/app/lemonriver/features.test.ts +5 -0
  10. package/src/app/lemonriver/features.ts +2 -1
  11. package/src/app/lemonriver/feedback/pending-toast.ts +7 -2
  12. package/src/app/lemonriver/home/deck-card.tsx +10 -1
  13. package/src/app/lemonriver/home/home-page.tsx +52 -1
  14. package/src/app/lemonriver/share/capture.ts +76 -0
  15. package/src/app/lemonriver/share/client.ts +162 -0
  16. package/src/app/lemonriver/share/codes.test.ts +49 -0
  17. package/src/app/lemonriver/share/codes.ts +30 -0
  18. package/src/app/lemonriver/share/compare.test.ts +199 -0
  19. package/src/app/lemonriver/share/compare.ts +367 -0
  20. package/src/app/lemonriver/share/drop.ts +84 -0
  21. package/src/app/lemonriver/share/folder.test.ts +42 -0
  22. package/src/app/lemonriver/share/folder.ts +29 -0
  23. package/src/app/lemonriver/share/freeze.ts +51 -0
  24. package/src/app/lemonriver/share/guide.test.ts +78 -0
  25. package/src/app/lemonriver/share/guide.ts +222 -0
  26. package/src/app/lemonriver/share/import-dialog.tsx +391 -0
  27. package/src/app/lemonriver/share/import-entry.tsx +106 -0
  28. package/src/app/lemonriver/share/model.ts +150 -0
  29. package/src/app/lemonriver/share/naming.test.ts +59 -0
  30. package/src/app/lemonriver/share/naming.ts +71 -0
  31. package/src/app/lemonriver/share/paths.test.ts +75 -0
  32. package/src/app/lemonriver/share/paths.ts +181 -0
  33. package/src/app/lemonriver/share/pdf.test.ts +79 -0
  34. package/src/app/lemonriver/share/pdf.ts +169 -0
  35. package/src/app/lemonriver/share/share-dialog.tsx +286 -0
  36. package/src/app/lemonriver/share/summary.ts +47 -0
  37. package/src/app/lemonriver/slide-extensions.tsx +69 -23
  38. package/src/app/lemonriver/templates/library-page.tsx +5 -2
  39. package/src/app/lemonriver/text/en.ts +67 -0
  40. package/src/app/lemonriver/text/es.ts +67 -0
  41. package/src/app/lemonriver/text/ja.ts +67 -0
  42. package/src/app/lemonriver/text/types.ts +78 -0
  43. package/src/app/lemonriver/text/zh-cn.ts +62 -0
  44. package/src/app/lemonriver/text/zh-tw.ts +62 -0
@@ -0,0 +1,29 @@
1
+ /** One file read out of a folder the user dropped, with its path inside it. */
2
+ export type DroppedFile = { path: string; bytes: Uint8Array };
3
+
4
+ const SKIP_DIRS = new Set(['__MACOSX']);
5
+ const SKIP_FILES = new Set(['.DS_Store']);
6
+
7
+ /**
8
+ * Safari unpacks a downloaded zip, so the drop may be a folder. The browser
9
+ * reads it file by file; this turns those files back into the zip the inspect
10
+ * endpoint expects, keeping the folder's own relative paths.
11
+ */
12
+ export async function zipDroppedFolder(files: DroppedFile[]): Promise<Uint8Array> {
13
+ const entries: Record<string, Uint8Array> = {};
14
+ for (const file of files) {
15
+ const parts = file.path
16
+ .replace(/\\/g, '/')
17
+ .split('/')
18
+ .filter((part) => part !== '' && part !== '.');
19
+ if (parts.length === 0 || parts.includes('..')) continue;
20
+ if (parts.some((part) => SKIP_DIRS.has(part))) continue;
21
+ const name = parts[parts.length - 1] as string;
22
+ if (SKIP_FILES.has(name)) continue;
23
+ entries[parts.join('/')] = file.bytes;
24
+ }
25
+ // Loaded here, not at the top, so the production bundle keeps fflate out of
26
+ // its main chunk the way the PPTX export already does.
27
+ const { zipSync } = await import('fflate');
28
+ return zipSync(entries, { level: 6 });
29
+ }
@@ -0,0 +1,51 @@
1
+ // Same trick as the official PPTX export: pin each element's settled visual
2
+ // state inline and drop its animation, so the rasterised clone cannot replay
3
+ // the keyframes from their invisible first frame.
4
+ const FROZEN_PROPS = ['opacity', 'transform', 'filter', 'clip-path'] as const;
5
+
6
+ export function freezeForCapture(root: HTMLElement): void {
7
+ for (const el of root.querySelectorAll<HTMLElement>('*')) {
8
+ const cs = getComputedStyle(el);
9
+ for (const prop of FROZEN_PROPS) {
10
+ el.style.setProperty(prop, cs.getPropertyValue(prop), 'important');
11
+ }
12
+ el.style.setProperty('animation', 'none', 'important');
13
+ el.style.setProperty('transition', 'none', 'important');
14
+ }
15
+ }
16
+
17
+ /**
18
+ * html-to-image's own toBlob ignores the format it is handed and encodes PNG,
19
+ * so the JPEG is made here from the canvas it returns.
20
+ */
21
+ export function canvasJpeg(canvas: HTMLCanvasElement, quality: number): Promise<Uint8Array> {
22
+ return new Promise((resolve, reject) => {
23
+ canvas.toBlob(
24
+ (blob) => {
25
+ if (!blob) {
26
+ reject(new Error('the canvas could not be encoded as a JPEG'));
27
+ return;
28
+ }
29
+ void blob.arrayBuffer().then((buffer) => resolve(new Uint8Array(buffer)), reject);
30
+ },
31
+ 'image/jpeg',
32
+ quality,
33
+ );
34
+ });
35
+ }
36
+
37
+ /** Scales the full-size capture down instead of drawing the page a second time. */
38
+ export async function canvasThumb(
39
+ source: HTMLCanvasElement,
40
+ width: number,
41
+ height: number,
42
+ quality: number,
43
+ ): Promise<Uint8Array> {
44
+ const canvas = document.createElement('canvas');
45
+ canvas.width = width;
46
+ canvas.height = height;
47
+ const ctx = canvas.getContext('2d');
48
+ if (!ctx) throw new Error('canvas is unavailable');
49
+ ctx.drawImage(source, 0, 0, width, height);
50
+ return canvasJpeg(canvas, quality);
51
+ }
@@ -0,0 +1,78 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { buildGuideHtml, guideFileName, guideLocaleFor } from './guide';
3
+
4
+ const base = {
5
+ pages: 12,
6
+ appVersion: '0.6.0',
7
+ createdAt: new Date(2026, 10, 1).getTime(),
8
+ };
9
+
10
+ const decoder = new TextDecoder();
11
+
12
+ describe('buildGuideHtml', () => {
13
+ it('writes the page in the interface language, English for the rest', () => {
14
+ const zh = buildGuideHtml({ ...base, title: '季度报告', locale: 'zh-CN' });
15
+ const tw = buildGuideHtml({ ...base, title: '季度報告', locale: 'zh-TW' });
16
+ const en = buildGuideHtml({ ...base, title: 'Q3 report', locale: 'en' });
17
+ expect(zh).toContain('怎么打开「季度报告」');
18
+ expect(zh).toContain('12 页 · 用 LemonRiver 0.6.0 制作 · 2026年11月1日');
19
+ expect(tw).toContain('怎麼打開「季度報告」');
20
+ expect(tw).toContain('12 頁 · 用 LemonRiver 0.6.0 製作');
21
+ expect(en).toContain('How to open “Q3 report”');
22
+ expect(en).toContain('12 pages · Made with LemonRiver 0.6.0 · November 1, 2026');
23
+ expect(guideLocaleFor('ja')).toBe('en');
24
+ expect(guideLocaleFor('es')).toBe('en');
25
+ expect(guideLocaleFor('zh-TW')).toBe('zh-TW');
26
+ });
27
+
28
+ it('escapes whatever the deck calls itself', () => {
29
+ const html = buildGuideHtml({
30
+ ...base,
31
+ title: '<script>alert("x")</script> A & B',
32
+ locale: 'en',
33
+ });
34
+ expect(html).not.toContain('<script');
35
+ expect(html).toContain('&lt;script&gt;alert(&quot;x&quot;)&lt;/script&gt; A &amp; B');
36
+ expect(html).toContain('<title>How to open “&lt;script&gt;');
37
+ expect(html).not.toContain('How to open “<script>');
38
+ });
39
+
40
+ it('has no script tag, and links only to the release list', () => {
41
+ for (const locale of ['zh-CN', 'zh-TW', 'en'] as const) {
42
+ const html = buildGuideHtml({ ...base, title: 'Deck', locale });
43
+ expect(html.toLowerCase()).not.toContain('<script');
44
+ expect(html).toContain('https://github.com/SegawaBeer/lemonriver/releases');
45
+ const hrefs = [...html.matchAll(/href="([^"]+)"/g)].map((match) => match[1]);
46
+ for (const href of hrefs) {
47
+ expect(href).toBe('https://github.com/SegawaBeer/lemonriver/releases');
48
+ }
49
+ expect(html).toContain('LemonRiver-0.6.0-arm64.dmg');
50
+ }
51
+ });
52
+
53
+ it('says the package has no PDF when it does not', () => {
54
+ const withPdf = buildGuideHtml({ ...base, title: '季度报告', locale: 'zh-CN' });
55
+ const without = buildGuideHtml({
56
+ ...base,
57
+ title: '季度报告',
58
+ locale: 'zh-CN',
59
+ hasPdf: false,
60
+ });
61
+ expect(withPdf).toContain('打开同一个文件夹里的「季度报告.pdf」就行');
62
+ expect(without).not.toContain('季度报告.pdf');
63
+ expect(without).toContain('这个包没有附带 PDF,装好 LemonRiver 后导入就能看。');
64
+ });
65
+
66
+ it('names the file the way the system would show it', () => {
67
+ expect(guideFileName('zh-CN')).toBe('怎么打开.html');
68
+ expect(guideFileName('zh-TW')).toBe('怎麼打開.html');
69
+ expect(guideFileName('en')).toBe('How to open.html');
70
+ });
71
+
72
+ it('is a complete html file', () => {
73
+ const html = buildGuideHtml({ ...base, title: 'Deck', locale: 'en' });
74
+ expect(html.startsWith('<!doctype html>')).toBe(true);
75
+ expect(html.trim().endsWith('</html>')).toBe(true);
76
+ expect(decoder.decode(new TextEncoder().encode(html))).toBe(html);
77
+ });
78
+ });
@@ -0,0 +1,222 @@
1
+ /**
2
+ * The how-to-open page that rides beside the PDF in a share package. It is a
3
+ * standalone file: no script, all styling inline, and every user-supplied string
4
+ * escaped, because it is opened straight from a downloaded folder.
5
+ */
6
+
7
+ export type GuideLocale = 'zh-CN' | 'zh-TW' | 'en';
8
+
9
+ export type GuideInput = {
10
+ title: string;
11
+ pages: number;
12
+ appVersion: string;
13
+ createdAt: number;
14
+ locale: GuideLocale;
15
+ hasPdf?: boolean;
16
+ };
17
+
18
+ const RELEASES_URL = 'https://github.com/SegawaBeer/lemonriver/releases';
19
+
20
+ export function guideLocaleFor(id: string): GuideLocale {
21
+ if (id === 'zh-CN') return 'zh-CN';
22
+ if (id === 'zh-TW') return 'zh-TW';
23
+ return 'en';
24
+ }
25
+
26
+ export function guideFileName(locale: GuideLocale): string {
27
+ if (locale === 'zh-CN') return '怎么打开.html';
28
+ if (locale === 'zh-TW') return '怎麼打開.html';
29
+ return 'How to open.html';
30
+ }
31
+
32
+ export function htmlEscape(text: string): string {
33
+ return text
34
+ .replace(/&/g, '&amp;')
35
+ .replace(/</g, '&lt;')
36
+ .replace(/>/g, '&gt;')
37
+ .replace(/"/g, '&quot;')
38
+ .replace(/'/g, '&#39;');
39
+ }
40
+
41
+ type Phrases = {
42
+ lang: string;
43
+ heading: (title: string) => string;
44
+ sub: (pages: number, version: string, date: string) => string;
45
+ viewOnly: string;
46
+ viewOnlyNoPdf: string;
47
+ installed: string;
48
+ installedSteps: () => string[];
49
+ installedWarn: string;
50
+ notInstalled: string;
51
+ installSteps: (version: string) => string[];
52
+ footer: string;
53
+ };
54
+
55
+ const PHRASES: Record<GuideLocale, Phrases> = {
56
+ 'zh-CN': {
57
+ lang: 'zh-CN',
58
+ heading: (title) => `怎么打开「${title}」`,
59
+ sub: (pages, version, date) => `${pages} 页 · 用 LemonRiver ${version} 制作 · ${date}`,
60
+ viewOnly: '只想看',
61
+ viewOnlyNoPdf: '这个包没有附带 PDF,装好 LemonRiver 后导入就能看。',
62
+ installed: '已经装了 LemonRiver',
63
+ installedSteps: () => [
64
+ '打开 LemonRiver,回到首页。',
65
+ '把收到的压缩包拖进首页,或者点首页右上角的「导入」选它。用 Safari 下载时压缩包会被自动解开,这时把解开后的文件夹整个拖进去就行。',
66
+ '看一眼预览,确认是你要的,点「导入」。',
67
+ ],
68
+ installedWarn: '演示是程序代码,导入后会在你的电脑上运行,只导入你信任的人发来的。',
69
+ notInstalled: '还没装 LemonRiver',
70
+ installSteps: (version) => [
71
+ `打开 ${RELEASES_URL} ,在最新的版本里下载 LemonRiver-${version}-arm64.dmg(目前只支持 Apple 芯片的 Mac)。`,
72
+ '打开下载的文件,把 LemonRiver 拖进「应用程序」,再从「应用程序」里打开。',
73
+ '第一次打开会被系统拦下:点「完成」,打开「系统设置 → 隐私与安全性」,在「安全性」一栏点「仍要打开」,输入开机密码确认。之后就不用再管了。',
74
+ '装好后照上一节导入。',
75
+ ],
76
+ footer: '「LemonRiver-files」文件夹是导入用的,请不要改动里面的文件,改了会导入失败。',
77
+ },
78
+ 'zh-TW': {
79
+ lang: 'zh-TW',
80
+ heading: (title) => `怎麼打開「${title}」`,
81
+ sub: (pages, version, date) => `${pages} 頁 · 用 LemonRiver ${version} 製作 · ${date}`,
82
+ viewOnly: '只想看',
83
+ viewOnlyNoPdf: '這個包沒有附帶 PDF,裝好 LemonRiver 後匯入就能看。',
84
+ installed: '已經裝了 LemonRiver',
85
+ installedSteps: () => [
86
+ '打開 LemonRiver,回到首頁。',
87
+ '把收到的壓縮檔拖進首頁,或者點首頁右上角的「匯入」選它。用 Safari 下載時壓縮檔會自動解開,這時把解開後的資料夾整個拖進去就行。',
88
+ '看一眼預覽,確認是你要的,點「匯入」。',
89
+ ],
90
+ installedWarn: '演示是程式碼,匯入後會在你的電腦上執行,只匯入你信任的人寄來的。',
91
+ notInstalled: '還沒裝 LemonRiver',
92
+ installSteps: (version) => [
93
+ `打開 ${RELEASES_URL} ,在最新的版本裡下載 LemonRiver-${version}-arm64.dmg(目前只支援 Apple 晶片的 Mac)。`,
94
+ '打開下載的檔案,把 LemonRiver 拖進「應用程式」,再從「應用程式」裡打開。',
95
+ '第一次打開會被系統攔下:點「完成」,打開「系統設定 → 隱私權與安全性」,在「安全性」一欄點「仍要打開」,輸入開機密碼確認。之後就不用再管了。',
96
+ '裝好後照上一節匯入。',
97
+ ],
98
+ footer: '「LemonRiver-files」資料夾是匯入用的,請不要改動裡面的檔案,改了會匯入失敗。',
99
+ },
100
+ en: {
101
+ lang: 'en',
102
+ heading: (title) => `How to open “${title}”`,
103
+ sub: (pages, version, date) => `${pages} pages · Made with LemonRiver ${version} · ${date}`,
104
+ viewOnly: 'Just want to look',
105
+ viewOnlyNoPdf:
106
+ 'This package has no PDF attached. Install LemonRiver and import it to see the slides.',
107
+ installed: 'Already have LemonRiver',
108
+ installedSteps: () => [
109
+ 'Open LemonRiver and go back to the home page.',
110
+ 'Drop the zip you received onto the home page, or click “Import” at the top right and pick it. If Safari unpacked the zip when you downloaded it, drag the whole unpacked folder in instead.',
111
+ 'Take a look at the preview, and if it is the right one, click “Import”.',
112
+ ],
113
+ installedWarn:
114
+ 'A deck is program code that runs on your computer once imported. Only import packages from people you trust.',
115
+ notInstalled: 'Do not have LemonRiver yet',
116
+ installSteps: (version) => [
117
+ `Open ${RELEASES_URL} and, under the newest release, download LemonRiver-${version}-arm64.dmg (Apple silicon Macs only for now).`,
118
+ 'Open the downloaded file, drag LemonRiver into Applications, then open it from there.',
119
+ 'macOS blocks the first launch: click “Done”, open System Settings → Privacy & Security, click “Open Anyway” in the Security section, and enter your login password. You only do this once.',
120
+ 'Once it is installed, import the package as described above.',
121
+ ],
122
+ footer:
123
+ 'The “LemonRiver-files” folder is what gets imported. Do not change anything inside it, or the import will fail.',
124
+ },
125
+ };
126
+
127
+ function formatDate(createdAt: number, locale: GuideLocale): string {
128
+ const date = new Date(createdAt);
129
+ const year = date.getFullYear();
130
+ const month = date.getMonth() + 1;
131
+ const day = date.getDate();
132
+ if (locale === 'en') {
133
+ const names = [
134
+ 'January',
135
+ 'February',
136
+ 'March',
137
+ 'April',
138
+ 'May',
139
+ 'June',
140
+ 'July',
141
+ 'August',
142
+ 'September',
143
+ 'October',
144
+ 'November',
145
+ 'December',
146
+ ];
147
+ return `${names[date.getMonth()]} ${day}, ${year}`;
148
+ }
149
+ return `${year}年${month}月${day}日`;
150
+ }
151
+
152
+ function steps(items: string[]): string {
153
+ return `<ol>\n${items.map((item) => `<li>${item}</li>`).join('\n')}\n</ol>`;
154
+ }
155
+
156
+ export function buildGuideHtml(input: GuideInput): string {
157
+ const p = PHRASES[input.locale];
158
+ const hasPdf = input.hasPdf !== false;
159
+ const date = formatDate(input.createdAt, input.locale);
160
+ const sub = htmlEscape(p.sub(input.pages, input.appVersion, date));
161
+ const viewSection = hasPdf
162
+ ? `<p>${htmlEscape(
163
+ input.locale === 'en'
164
+ ? `Open “${input.title}.pdf” in the same folder — it opens on any computer or phone.`
165
+ : input.locale === 'zh-TW'
166
+ ? `打開同一個資料夾裡的「${input.title}.pdf」就行,任何電腦和手機都能看。`
167
+ : `打开同一个文件夹里的「${input.title}.pdf」就行,任何电脑和手机都能看。`,
168
+ )}</p>`
169
+ : `<p>${htmlEscape(p.viewOnlyNoPdf)}</p>`;
170
+ const installedSteps = p
171
+ .installedSteps()
172
+ .map((step) =>
173
+ htmlEscape(step).replace(RELEASES_URL, `<a href="${RELEASES_URL}">${RELEASES_URL}</a>`),
174
+ );
175
+ const installSteps = p
176
+ .installSteps(input.appVersion)
177
+ .map((step) =>
178
+ htmlEscape(step).replace(RELEASES_URL, `<a href="${RELEASES_URL}">${RELEASES_URL}</a>`),
179
+ );
180
+ const heading = htmlEscape(p.heading(input.title));
181
+
182
+ return `<!doctype html>
183
+ <html lang="${p.lang}">
184
+ <head>
185
+ <meta charset="utf-8">
186
+ <meta name="viewport" content="width=device-width, initial-scale=1">
187
+ <title>${heading}</title>
188
+ <style>
189
+ :root { color-scheme: light dark; }
190
+ body { margin: 0 auto; padding: 40px 24px 72px; max-width: 680px; font: 16px/1.7 -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif; color: #1c1c1e; background: #fff; }
191
+ h1 { font-size: 28px; line-height: 1.25; margin: 0 0 8px; }
192
+ .sub { margin: 0 0 32px; color: #6b6b70; font-size: 14px; }
193
+ h2 { font-size: 18px; margin: 32px 0 8px; }
194
+ ol { margin: 0; padding-left: 1.4em; }
195
+ li { margin: 6px 0; }
196
+ .warn { margin: 12px 0 0; padding: 12px 14px; border-radius: 10px; background: #fff4e5; color: #7a3d00; font-weight: 600; }
197
+ footer { margin-top: 40px; padding-top: 16px; border-top: 1px solid #e5e5ea; color: #6b6b70; font-size: 14px; }
198
+ a { color: #0a58ca; }
199
+ @media (prefers-color-scheme: dark) {
200
+ body { color: #f2f2f7; background: #1c1c1e; }
201
+ .sub, footer { color: #a1a1a6; }
202
+ .warn { background: #3a2a12; color: #ffd9a8; }
203
+ footer { border-top-color: #2c2c2e; }
204
+ a { color: #6cb2ff; }
205
+ }
206
+ </style>
207
+ </head>
208
+ <body>
209
+ <h1>${heading}</h1>
210
+ <p class="sub">${sub}</p>
211
+ <h2>${htmlEscape(p.viewOnly)}</h2>
212
+ ${viewSection}
213
+ <h2>${htmlEscape(p.installed)}</h2>
214
+ ${steps(installedSteps)}
215
+ <p class="warn">${htmlEscape(p.installedWarn)}</p>
216
+ <h2>${htmlEscape(p.notInstalled)}</h2>
217
+ ${steps(installSteps)}
218
+ <footer>${htmlEscape(p.footer)}</footer>
219
+ </body>
220
+ </html>
221
+ `;
222
+ }