@lemonriver/core 1.1.0 → 1.3.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 (98) hide show
  1. package/dist/{build-Dm7gVRhb.js → build-CSkdswfd.js} +1 -1
  2. package/dist/cli/bin.js +5 -5
  3. package/dist/{config-CubOIzrs.js → config-C5-myPY6.js} +129 -2
  4. package/dist/{dev-DgLeXPqp.js → dev-DHtYH8sw.js} +2 -2
  5. package/dist/{mcp-CjYDzcJa.js → mcp-B2UeO1un.js} +1 -1
  6. package/dist/{preview-CxXQpPk5.js → preview-C1B6-umF.js} +1 -1
  7. package/dist/{update-b1dSg_FW.js → update-DzL8fpcI.js} +1 -1
  8. package/dist/vite/index.js +1 -1
  9. package/package.json +5 -2
  10. package/release-notes.json +33 -0
  11. package/src/app/components/player.tsx +6 -1
  12. package/src/app/lemonriver/chrome/app-chrome.tsx +52 -0
  13. package/src/app/lemonriver/chrome/sidebar-extras.tsx +8 -1
  14. package/src/app/lemonriver/feedback/dialog.tsx +222 -0
  15. package/src/app/lemonriver/feedback/export.ts +21 -2
  16. package/src/app/lemonriver/feedback/first-success.ts +30 -0
  17. package/src/app/lemonriver/feedback/install.ts +18 -0
  18. package/src/app/lemonriver/feedback/model.ts +88 -0
  19. package/src/app/lemonriver/help/help-page.tsx +16 -1
  20. package/src/app/lemonriver/links.ts +16 -0
  21. package/src/app/lemonriver/present/dual-screen.ts +154 -0
  22. package/src/app/lemonriver/present/presenter-blocked-hint.tsx +28 -0
  23. package/src/app/lemonriver/present/wake-lock.ts +74 -0
  24. package/src/app/lemonriver/settings/backup-section.tsx +13 -0
  25. package/src/app/lemonriver/settings/settings-page.tsx +20 -0
  26. package/src/app/lemonriver/share/editor-share.tsx +6 -3
  27. package/src/app/lemonriver/share/share-dialog.tsx +2 -0
  28. package/src/app/lemonriver/text/en.ts +48 -0
  29. package/src/app/lemonriver/text/es.ts +45 -0
  30. package/src/app/lemonriver/text/ja.ts +44 -0
  31. package/src/app/lemonriver/text/types.ts +48 -0
  32. package/src/app/lemonriver/text/zh-cn.ts +48 -0
  33. package/src/app/lemonriver/text/zh-tw.ts +48 -0
  34. package/src/app/lemonriver/theme/pages.ts +4 -0
  35. package/src/app/lemonriver/update/release-notes.ts +22 -0
  36. package/src/app/lemonriver/update/update-prompt.tsx +28 -4
  37. package/src/app/routes/presenter.tsx +2 -0
  38. package/src/app/routes/slide.tsx +14 -1
  39. package/src/app/components/note-markdown.test.tsx +0 -42
  40. package/src/app/components/thumbnail-rail-scroll.test.ts +0 -60
  41. package/src/app/lemonriver/agent-prefs/prefs.test.ts +0 -173
  42. package/src/app/lemonriver/backup/guide.test.ts +0 -45
  43. package/src/app/lemonriver/backup/model.test.ts +0 -108
  44. package/src/app/lemonriver/backup/places.test.ts +0 -154
  45. package/src/app/lemonriver/board/blocks/classify.test.ts +0 -209
  46. package/src/app/lemonriver/board/layout.test.ts +0 -245
  47. package/src/app/lemonriver/board/model/agent-tasks.test.ts +0 -200
  48. package/src/app/lemonriver/board/model/apply-prompt.test.ts +0 -121
  49. package/src/app/lemonriver/board/model/cards.test.ts +0 -332
  50. package/src/app/lemonriver/board/model/changes.test.ts +0 -244
  51. package/src/app/lemonriver/board/model/filter.test.ts +0 -50
  52. package/src/app/lemonriver/board/model/history.test.ts +0 -71
  53. package/src/app/lemonriver/board/model/restructure.test.ts +0 -205
  54. package/src/app/lemonriver/board/model/self-check.test.ts +0 -329
  55. package/src/app/lemonriver/board/model/structure.test.ts +0 -350
  56. package/src/app/lemonriver/board/model/timing.test.ts +0 -113
  57. package/src/app/lemonriver/features.test.ts +0 -49
  58. package/src/app/lemonriver/feedback/pending-toast.test.ts +0 -44
  59. package/src/app/lemonriver/feedback/upload.test.ts +0 -26
  60. package/src/app/lemonriver/help/model.test.ts +0 -179
  61. package/src/app/lemonriver/home/brief.test.ts +0 -38
  62. package/src/app/lemonriver/home/drafts.test.ts +0 -23
  63. package/src/app/lemonriver/home/sorting.test.ts +0 -24
  64. package/src/app/lemonriver/home/time.test.ts +0 -33
  65. package/src/app/lemonriver/outline/files.test.ts +0 -90
  66. package/src/app/lemonriver/outline/model.test.ts +0 -751
  67. package/src/app/lemonriver/public-links.test.ts +0 -32
  68. package/src/app/lemonriver/routes.test.tsx +0 -54
  69. package/src/app/lemonriver/share/codes.test.ts +0 -49
  70. package/src/app/lemonriver/share/compare.test.ts +0 -199
  71. package/src/app/lemonriver/share/folder.test.ts +0 -42
  72. package/src/app/lemonriver/share/guide.test.ts +0 -78
  73. package/src/app/lemonriver/share/naming.test.ts +0 -70
  74. package/src/app/lemonriver/share/paths.test.ts +0 -116
  75. package/src/app/lemonriver/share/pdf.test.ts +0 -79
  76. package/src/app/lemonriver/templates/knobs.test.ts +0 -62
  77. package/src/app/lemonriver/templates/model.test.ts +0 -175
  78. package/src/app/lemonriver/templates/preview-content.test.ts +0 -117
  79. package/src/app/lemonriver/templates/recommend.test.ts +0 -71
  80. package/src/app/lemonriver/text/text.test.ts +0 -90
  81. package/src/app/lemonriver/theme/pages.test.ts +0 -74
  82. package/src/app/lemonriver/theme/themes.test.ts +0 -18
  83. package/src/app/lemonriver/trash/api.test.ts +0 -19
  84. package/src/app/lemonriver/update/prompt.test.ts +0 -84
  85. package/src/app/lemonriver/update/version.test.ts +0 -14
  86. package/src/app/lib/asset-filter.test.ts +0 -176
  87. package/src/app/lib/inspector/fiber.test.ts +0 -154
  88. package/src/app/lib/inspector/geometry.test.ts +0 -324
  89. package/src/app/lib/inspector/text-edit-timeline.test.ts +0 -121
  90. package/src/app/lib/note-markdown.test.ts +0 -147
  91. package/src/app/lib/pptx/css.test.ts +0 -205
  92. package/src/app/lib/pptx/ooxml.test.ts +0 -199
  93. package/src/app/lib/pptx/text-lines.test.ts +0 -82
  94. package/src/app/lib/print-ready.test.ts +0 -32
  95. package/src/app/lib/sdk.test.ts +0 -13
  96. package/src/app/lib/transition.test.ts +0 -31
  97. package/src/app/lib/use-document-title.test.ts +0 -14
  98. package/src/app/lib/utils.test.ts +0 -49
@@ -1,173 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import {
3
- type AgentPrefs,
4
- DEFAULT_PREFS,
5
- PREFS_KEY,
6
- prefsLines,
7
- readPrefs,
8
- sanitizePrefs,
9
- savePrefs,
10
- toneForUses,
11
- } from './prefs';
12
-
13
- function memoryStorage(initial: Record<string, string> = {}): Storage {
14
- const data = new Map(Object.entries(initial));
15
- return {
16
- get length() {
17
- return data.size;
18
- },
19
- clear: () => data.clear(),
20
- getItem: (key: string) => data.get(key) ?? null,
21
- key: (index: number) => [...data.keys()][index] ?? null,
22
- removeItem: (key: string) => {
23
- data.delete(key);
24
- },
25
- setItem: (key: string, value: string) => {
26
- data.set(key, value);
27
- },
28
- };
29
- }
30
-
31
- describe('sanitizePrefs', () => {
32
- it('returns the defaults for anything that is not an object', () => {
33
- expect(sanitizePrefs(null)).toEqual(DEFAULT_PREFS);
34
- expect(sanitizePrefs('dense')).toEqual(DEFAULT_PREFS);
35
- expect(sanitizePrefs(['dense'])).toEqual(DEFAULT_PREFS);
36
- });
37
-
38
- it('keeps the values it knows', () => {
39
- const prefs: AgentPrefs = {
40
- confirmEachPage: true,
41
- askOnMismatch: false,
42
- autoImages: false,
43
- tone: 'concise',
44
- research: 'web',
45
- outline: 'direct',
46
- design: 'dense',
47
- review: 'numbers',
48
- };
49
- expect(sanitizePrefs(prefs)).toEqual(prefs);
50
- });
51
-
52
- it('replaces the values it does not know with the defaults', () => {
53
- expect(
54
- sanitizePrefs({
55
- confirmEachPage: 'yes',
56
- askOnMismatch: 0,
57
- autoImages: null,
58
- tone: 'shouty',
59
- research: 'library',
60
- outline: 'auto',
61
- design: 'sparse',
62
- review: 'loose',
63
- }),
64
- ).toEqual(DEFAULT_PREFS);
65
- });
66
-
67
- it('fills a partial record', () => {
68
- expect(sanitizePrefs({ design: 'visual' })).toEqual({ ...DEFAULT_PREFS, design: 'visual' });
69
- });
70
- });
71
-
72
- describe('readPrefs and savePrefs', () => {
73
- it('round-trips through storage', () => {
74
- const storage = memoryStorage();
75
- const prefs: AgentPrefs = { ...DEFAULT_PREFS, tone: 'friendly', confirmEachPage: true };
76
- savePrefs(storage, prefs);
77
- expect(storage.getItem(PREFS_KEY)).toBe(JSON.stringify(prefs));
78
- expect(readPrefs(storage)).toEqual(prefs);
79
- });
80
-
81
- it('falls back to the defaults on junk or a missing key', () => {
82
- expect(readPrefs(memoryStorage())).toEqual(DEFAULT_PREFS);
83
- expect(readPrefs(memoryStorage({ [PREFS_KEY]: 'not json' }))).toEqual(DEFAULT_PREFS);
84
- expect(readPrefs(memoryStorage({ [PREFS_KEY]: '{"tone":"loud"}' }))).toEqual(DEFAULT_PREFS);
85
- });
86
-
87
- it('swallows a storage that throws', () => {
88
- const broken = {
89
- getItem: () => {
90
- throw new Error('blocked');
91
- },
92
- setItem: () => {
93
- throw new Error('blocked');
94
- },
95
- } as unknown as Storage;
96
- expect(readPrefs(broken)).toEqual(DEFAULT_PREFS);
97
- expect(() => savePrefs(broken, DEFAULT_PREFS)).not.toThrow();
98
- });
99
- });
100
-
101
- describe('prefsLines', () => {
102
- const prefs = (patch: Partial<AgentPrefs> = {}): AgentPrefs => ({ ...DEFAULT_PREFS, ...patch });
103
-
104
- it('gives every step the tone', () => {
105
- for (const step of ['outline', 'page', 'review'] as const) {
106
- expect(prefsLines(prefs(), step)[0]).toBe('Write in a steady, professional tone.');
107
- }
108
- expect(prefsLines(prefs({ tone: 'friendly' }), 'page')[0]).toBe(
109
- 'Write in a light, friendly tone.',
110
- );
111
- expect(prefsLines(prefs({ tone: 'concise' }), 'review')[0]).toBe(
112
- 'Keep the wording short and punchy.',
113
- );
114
- });
115
-
116
- it('tells the outline step where facts may come from', () => {
117
- expect(prefsLines(prefs(), 'outline')).toEqual([
118
- 'Write in a steady, professional tone.',
119
- "Use only the user's reference files; do not look anything up on the web.",
120
- ]);
121
- expect(prefsLines(prefs({ research: 'web' }), 'outline')).toContain(
122
- 'You may look up facts the files do not cover; say where each one came from.',
123
- );
124
- });
125
-
126
- it('tells the page step how dense to lay out and whether to use images', () => {
127
- expect(prefsLines(prefs(), 'page')).toEqual([
128
- 'Write in a steady, professional tone.',
129
- 'Balance text and visuals.',
130
- 'Use icons and image placeholders where a picture helps; never invent photos the user did not provide.',
131
- ]);
132
- expect(prefsLines(prefs({ design: 'dense' }), 'page')).toContain(
133
- 'A page may carry more text and data when the content needs it.',
134
- );
135
- expect(prefsLines(prefs({ autoImages: false }), 'page')).toContain(
136
- 'Do not add any image the user did not provide.',
137
- );
138
- });
139
-
140
- it('tells the review step how far to check and what to do with a mismatch', () => {
141
- expect(prefsLines(prefs(), 'review')).toEqual([
142
- 'Write in a steady, professional tone.',
143
- 'Check wording, typos and every number.',
144
- ]);
145
- expect(prefsLines(prefs({ review: 'numbers' }), 'review')).toContain(
146
- 'Check only the numbers against the reference files.',
147
- );
148
- const lenient = prefsLines(prefs({ askOnMismatch: false }), 'review');
149
- expect(lenient).toContain(
150
- 'When two files disagree on a number, use the one from the spreadsheet (.xlsx, .xls or .csv) and say which you used.',
151
- );
152
- });
153
- });
154
-
155
- describe('toneForUses', () => {
156
- it('picks a tone from what the deck is for', () => {
157
- expect(toneForUses(['report'])).toBe('steady');
158
- expect(toneForUses(['pitch'])).toBe('steady');
159
- expect(toneForUses(['lecture'])).toBe('friendly');
160
- expect(toneForUses(['training'])).toBe('friendly');
161
- expect(toneForUses(['launch'])).toBe('concise');
162
- });
163
-
164
- it('lets a launch win over anything else picked with it', () => {
165
- expect(toneForUses(['lecture', 'launch'])).toBe('concise');
166
- expect(toneForUses(['report', 'training'])).toBe('friendly');
167
- });
168
-
169
- it('changes nothing for other or an empty pick', () => {
170
- expect(toneForUses([])).toBeNull();
171
- expect(toneForUses(['other'])).toBeNull();
172
- });
173
- });
@@ -1,45 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { buildRestoreGuide, formatSize, restoreGuideFileName } from './guide.ts';
3
-
4
- const AT = new Date(2026, 10, 1, 21, 30).getTime();
5
-
6
- describe('the restore guide inside a backup', () => {
7
- it('says how to restore, in the language of the interface', () => {
8
- const zh = buildRestoreGuide({
9
- createdAt: AT,
10
- decks: 3,
11
- sizeBytes: 620 * 1024 * 1024,
12
- appVersion: '0.8.0',
13
- locale: 'zh-CN',
14
- });
15
- expect(zh).toContain('LemonRiver 备份 · 2026-11-01 21:30');
16
- expect(zh).toContain('3 份演示 · 620 MB · 用 LemonRiver 0.8.0 备份');
17
- expect(zh).toContain('从备份恢复');
18
- expect(zh).toContain('https://github.com/SegawaBeer/lemonriver-slide/releases/latest');
19
- expect(zh).not.toContain('<script');
20
-
21
- const en = buildRestoreGuide({
22
- createdAt: AT,
23
- decks: 1,
24
- sizeBytes: 2048,
25
- appVersion: '0.8.0',
26
- locale: 'en',
27
- });
28
- expect(en).toContain('LemonRiver backup · 2026-11-01 21:30');
29
- expect(en).toContain('1 decks · 2 KB · Made with LemonRiver 0.8.0');
30
- expect(en).toContain('Settings → Backup');
31
- });
32
-
33
- it('names the file per language', () => {
34
- expect(restoreGuideFileName('zh-CN')).toBe('怎么恢复.html');
35
- expect(restoreGuideFileName('zh-TW')).toBe('怎麼還原.html');
36
- expect(restoreGuideFileName('en')).toBe('How to restore.html');
37
- });
38
-
39
- it('formats sizes the way the backup line shows them', () => {
40
- expect(formatSize(900)).toBe('900 B');
41
- expect(formatSize(18 * 1024)).toBe('18 KB');
42
- expect(formatSize(620 * 1024 * 1024)).toBe('620 MB');
43
- expect(formatSize(1.5 * 1024 * 1024 * 1024)).toBe('1.5 GB');
44
- });
45
- });
@@ -1,108 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import {
3
- backupDue,
4
- backupFileStem,
5
- DAY_MS,
6
- isCompressedFile,
7
- isLargeVideo,
8
- LARGE_VIDEO_BYTES,
9
- looksLikeBackupName,
10
- PREFS_KEYS,
11
- sanitizePrefs,
12
- sanitizeSettings,
13
- } from './model.ts';
14
-
15
- const SETTINGS = { folder: '/Users/me/Backups', auto: true, skipLargeVideos: false, last: null };
16
-
17
- describe('backup settings', () => {
18
- it('falls back to a usable default', () => {
19
- expect(sanitizeSettings(null)).toEqual({
20
- folder: null,
21
- auto: false,
22
- skipLargeVideos: false,
23
- last: null,
24
- });
25
- expect(sanitizeSettings({ folder: 'relative/path' }).folder).toBeNull();
26
- expect(sanitizeSettings({}).skipLargeVideos).toBe(false);
27
- expect(sanitizeSettings({ skipLargeVideos: true }).skipLargeVideos).toBe(true);
28
- expect(sanitizeSettings({ keep: 30, written: ['a.zip'] })).toEqual({
29
- folder: null,
30
- auto: false,
31
- skipLargeVideos: false,
32
- last: null,
33
- });
34
- });
35
-
36
- it('knows when the daily backup is due', () => {
37
- const now = 1_800_000_000_000;
38
- expect(backupDue(sanitizeSettings({ ...SETTINGS, auto: false }), now)).toBe(false);
39
- expect(backupDue(sanitizeSettings({ ...SETTINGS, folder: null }), now)).toBe(false);
40
- expect(backupDue(sanitizeSettings(SETTINGS), now)).toBe(true);
41
- expect(
42
- backupDue(
43
- sanitizeSettings({ ...SETTINGS, last: { at: now - 23 * 3600_000, ok: true } }),
44
- now,
45
- ),
46
- ).toBe(false);
47
- expect(
48
- backupDue(sanitizeSettings({ ...SETTINGS, last: { at: now - DAY_MS - 1, ok: true } }), now),
49
- ).toBe(true);
50
- });
51
-
52
- it('waits an hour before retrying a failed backup', () => {
53
- const now = 1_800_000_000_000;
54
- const failed = { at: now - 10 * 60_000, ok: false, path: '', size: 0, error: 'denied' };
55
- expect(backupDue(sanitizeSettings({ ...SETTINGS, last: failed }), now)).toBe(false);
56
- const older = { ...failed, at: now - 2 * 3600_000 };
57
- expect(backupDue(sanitizeSettings({ ...SETTINGS, last: older }), now)).toBe(true);
58
- });
59
-
60
- it('names the file after the local date and time', () => {
61
- const at = new Date(2026, 10, 1, 21, 30).getTime();
62
- expect(backupFileStem(at)).toBe('LemonRiver 备份 2026-11-01 2130');
63
- });
64
-
65
- it('stores formats that are already compressed', () => {
66
- expect(isCompressedFile('photo.JPG')).toBe(true);
67
- expect(isCompressedFile('report.pdf')).toBe(true);
68
- expect(isCompressedFile('deck.pptx')).toBe(true);
69
- expect(isCompressedFile('index.tsx')).toBe(false);
70
- expect(isCompressedFile('notes.md')).toBe(false);
71
- });
72
-
73
- it('counts only videos past the size limit as large videos', () => {
74
- expect(isLargeVideo('assets/team/clip.MP4', LARGE_VIDEO_BYTES + 1)).toBe(true);
75
- expect(isLargeVideo('assets/team/clip.mov', LARGE_VIDEO_BYTES)).toBe(false);
76
- expect(isLargeVideo('assets/team/huge.zip', LARGE_VIDEO_BYTES + 1)).toBe(false);
77
- expect(isLargeVideo('assets/team/photo.png', LARGE_VIDEO_BYTES + 1)).toBe(false);
78
- });
79
-
80
- it('counts only its own file names as backups', () => {
81
- expect(looksLikeBackupName('LemonRiver 备份 2026-11-01 2130.zip')).toBe(true);
82
- expect(looksLikeBackupName('my stuff.zip')).toBe(false);
83
- expect(looksLikeBackupName('LemonRiver 备份 notes.txt')).toBe(false);
84
- });
85
- });
86
-
87
- describe('prefs that travel with a backup', () => {
88
- it('keeps the whitelist and drops everything else', () => {
89
- const kept = sanitizePrefs({
90
- theme: 'dark',
91
- 'open-slide:locale': 'zh-CN',
92
- 'lemonriver:agent-prefs': '{"tone":"steady"}',
93
- 'open-slide:agent-auto-approve': 'true',
94
- 'lemonriver:session': 'secret',
95
- 'open-slide:home-sort': 3,
96
- });
97
- expect(kept).toEqual({
98
- theme: 'dark',
99
- 'open-slide:locale': 'zh-CN',
100
- 'lemonriver:agent-prefs': '{"tone":"steady"}',
101
- });
102
- });
103
-
104
- it('never carries agent auto-approve', () => {
105
- expect(PREFS_KEYS as readonly string[]).not.toContain('open-slide:agent-auto-approve');
106
- expect(sanitizePrefs({ 'open-slide:agent-auto-approve': 'true' })).toEqual({});
107
- });
108
- });
@@ -1,154 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { helpSectionText } from '../help/model';
3
- import { lrTextFor } from '../text/all';
4
- import type { BackupPlace, BackupPlaceKind } from './model.ts';
5
- import { findBackupPlaces, placeLabel } from './places.ts';
6
-
7
- function io(files: Record<string, string[]>) {
8
- return {
9
- exists: (path: string) => files[path] !== undefined,
10
- list: (path: string) => files[path] ?? [],
11
- };
12
- }
13
-
14
- const HOME = '/Users/me';
15
-
16
- describe('backup places', () => {
17
- it('lists the cloud folders this Mac syncs, and the local default last', () => {
18
- const places = findBackupPlaces(
19
- HOME,
20
- io({
21
- [`${HOME}/Library/Mobile Documents/com~apple~CloudDocs`]: [],
22
- [`${HOME}/Library/CloudStorage`]: ['Dropbox-个人', 'OneDrive - Work'],
23
- [`${HOME}/Library/CloudStorage/Dropbox-个人`]: [],
24
- [`${HOME}/Library/CloudStorage/OneDrive - Work`]: [],
25
- [`${HOME}/BaiduSyncdisk`]: [],
26
- [`${HOME}/Nutstore Files`]: ['我的坚果云'],
27
- [`${HOME}/Nutstore Files/我的坚果云`]: [],
28
- }),
29
- );
30
- expect(places.map((place) => [place.kind, place.path])).toEqual([
31
- ['icloud', `${HOME}/Library/Mobile Documents/com~apple~CloudDocs`],
32
- ['dropbox', `${HOME}/Library/CloudStorage/Dropbox-个人`],
33
- ['onedrive', `${HOME}/Library/CloudStorage/OneDrive - Work`],
34
- ['baidu', `${HOME}/BaiduSyncdisk`],
35
- ['nutstore', `${HOME}/Nutstore Files/我的坚果云`],
36
- ['local', `${HOME}/LemonRiver 备份`],
37
- ]);
38
- expect(places[0]?.label).toBe('iCloud Drive');
39
- expect(places[5]?.label).toBe('LemonRiver 备份');
40
- });
41
-
42
- it('finds the older Dropbox and OneDrive folders too', () => {
43
- const places = findBackupPlaces(
44
- HOME,
45
- io({
46
- [HOME]: ['OneDrive - Contoso'],
47
- [`${HOME}/Dropbox`]: [],
48
- [`${HOME}/OneDrive`]: [],
49
- [`${HOME}/OneDrive - Contoso`]: [],
50
- }),
51
- );
52
- const paths = places.map((place) => place.path);
53
- expect(paths).toContain(`${HOME}/Dropbox`);
54
- expect(paths).toContain(`${HOME}/OneDrive`);
55
- expect(paths).toContain(`${HOME}/OneDrive - Contoso`);
56
- expect(paths.at(-1)).toBe(`${HOME}/LemonRiver 备份`);
57
- });
58
-
59
- it('offers the local default even before it exists', () => {
60
- const places = findBackupPlaces(HOME, io({}));
61
- expect(places).toEqual([
62
- {
63
- id: `${HOME}/LemonRiver 备份`,
64
- label: 'LemonRiver 备份',
65
- path: `${HOME}/LemonRiver 备份`,
66
- kind: 'local',
67
- },
68
- ]);
69
- });
70
- });
71
-
72
- function place(kind: BackupPlaceKind, label: string): BackupPlace {
73
- const path = `/places/${kind}`;
74
- return { id: path, label, path, kind };
75
- }
76
-
77
- describe('backup place names', () => {
78
- const named = [
79
- ['icloud', 'iCloud Drive', 'iCloud 云盘', 'iCloud 雲碟'],
80
- ['baidu', 'Baidu Netdisk Sync Space', '百度网盘同步空间', '百度網盤同步空間'],
81
- ['local', 'LemonRiver 备份', 'LemonRiver 备份', 'LemonRiver 备份'],
82
- ] as const;
83
-
84
- for (const [kind, en, zhCN, zhTW] of named) {
85
- it(`names ${kind} in each language`, () => {
86
- expect(placeLabel(place(kind, 'the folder'), lrTextFor('en'))).toBe(en);
87
- expect(placeLabel(place(kind, 'the folder'), lrTextFor('zh-CN'))).toBe(zhCN);
88
- expect(placeLabel(place(kind, 'the folder'), lrTextFor('zh-TW'))).toBe(zhTW);
89
- });
90
- }
91
-
92
- it('names nutstore by its sync folder in each language', () => {
93
- expect(placeLabel(place('nutstore', 'My Nutstore'), lrTextFor('en'))).toBe(
94
- 'Nutstore · My Nutstore',
95
- );
96
- expect(placeLabel(place('nutstore', '我的坚果云'), lrTextFor('zh-CN'))).toBe(
97
- '坚果云 · 我的坚果云',
98
- );
99
- expect(placeLabel(place('nutstore', '我的堅果雲'), lrTextFor('zh-TW'))).toBe(
100
- '堅果雲 · 我的堅果雲',
101
- );
102
- });
103
-
104
- it('keeps the name another drive gave its folder', () => {
105
- for (const kind of ['dropbox', 'onedrive', 'google', 'other'] as const) {
106
- expect(placeLabel(place(kind, 'Drive Name'), lrTextFor('zh-CN'))).toBe('Drive Name');
107
- }
108
- });
109
- });
110
-
111
- describe('backup place names match the help page', () => {
112
- type HelpLocale = 'en' | 'zh-CN' | 'zh-TW';
113
-
114
- function chosenInHelp(locale: HelpLocale, sectionId: string): string {
115
- const section = lrTextFor(locale).help.sections.find((item) => item.id === sectionId);
116
- if (!section) throw new Error(`the help page has no ${sectionId}`);
117
- const body = helpSectionText(section);
118
- const match = locale === 'en' ? /choose “([^”]+)”/.exec(body) : /[选選]「([^」]+)」/.exec(body);
119
- if (!match?.[1]) throw new Error(`“${sectionId}” does not say which one to choose`);
120
- return match[1];
121
- }
122
-
123
- it('uses the same names as the picker', () => {
124
- expect(chosenInHelp('zh-CN', 'cloud-icloud')).toBe(
125
- placeLabel(place('icloud', 'iCloud Drive'), lrTextFor('zh-CN')),
126
- );
127
- expect(chosenInHelp('zh-CN', 'cloud-baidu')).toBe(
128
- placeLabel(place('baidu', '百度网盘同步空间'), lrTextFor('zh-CN')),
129
- );
130
- expect(chosenInHelp('zh-CN', 'cloud-nutstore')).toBe(
131
- placeLabel(place('nutstore', '我的坚果云'), lrTextFor('zh-CN')),
132
- );
133
-
134
- expect(chosenInHelp('zh-TW', 'cloud-icloud')).toBe(
135
- placeLabel(place('icloud', 'iCloud Drive'), lrTextFor('zh-TW')),
136
- );
137
- expect(chosenInHelp('zh-TW', 'cloud-baidu')).toBe(
138
- placeLabel(place('baidu', '百度網盤同步空間'), lrTextFor('zh-TW')),
139
- );
140
- expect(chosenInHelp('zh-TW', 'cloud-nutstore')).toBe(
141
- placeLabel(place('nutstore', '我的堅果雲'), lrTextFor('zh-TW')),
142
- );
143
-
144
- expect(chosenInHelp('en', 'cloud-icloud')).toBe(
145
- placeLabel(place('icloud', 'iCloud Drive'), lrTextFor('en')),
146
- );
147
- expect(chosenInHelp('en', 'cloud-baidu')).toBe(
148
- placeLabel(place('baidu', 'Baidu Netdisk Sync Space'), lrTextFor('en')),
149
- );
150
- expect(chosenInHelp('en', 'cloud-nutstore')).toBe(
151
- placeLabel(place('nutstore', 'My Nutstore'), lrTextFor('en')),
152
- );
153
- });
154
- });
@@ -1,209 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { readBlocks, type SnapNode } from './classify.ts';
3
-
4
- let counter = 0;
5
-
6
- function node(tag: string, extra: Partial<SnapNode> = {}, children: SnapNode[] = []): SnapNode {
7
- counter += 1;
8
- return {
9
- tag,
10
- text: '',
11
- fullText: extra.fullText ?? extra.text ?? '',
12
- fontSize: 32,
13
- lineHeight: 40,
14
- fontWeight: 400,
15
- color: '',
16
- background: '',
17
- box: { x: 0, y: counter * 10, w: 300, h: 40 },
18
- clip: null,
19
- lines: [],
20
- loc: null,
21
- placeholder: false,
22
- step: false,
23
- children,
24
- ...extra,
25
- };
26
- }
27
-
28
- function page(...children: SnapNode[]): SnapNode {
29
- return node('div', { box: { x: 0, y: 0, w: 1920, h: 1080 } }, children);
30
- }
31
-
32
- function blocksOf(...children: SnapNode[]) {
33
- const result = readBlocks(page(...children));
34
- if ('whole' in result) throw new Error(`expected blocks, got ${result.whole}`);
35
- return result.blocks;
36
- }
37
-
38
- describe('readBlocks kinds', () => {
39
- it('reads a heading as a title', () => {
40
- const [block] = blocksOf(node('h1', { text: 'Alpha page one' }));
41
- expect(block.kind).toBe('title');
42
- expect(block.text).toBe('Alpha page one');
43
- });
44
-
45
- it('reads a large text element as a title and a plain one as text', () => {
46
- const blocks = blocksOf(
47
- node('div', { text: 'Big', fontSize: 60 }),
48
- node('div', { text: 'Small', fontSize: 32 }),
49
- );
50
- expect(blocks.map((b) => b.kind)).toEqual(['title', 'text']);
51
- });
52
-
53
- it('reads images and placeholders as images', () => {
54
- const blocks = blocksOf(node('img'), node('div', { placeholder: true }));
55
- expect(blocks.map((b) => b.kind)).toEqual(['image', 'image']);
56
- });
57
-
58
- it('reads a big svg as a chart but ignores a small one', () => {
59
- const blocks = blocksOf(
60
- node('svg', { box: { x: 0, y: 100, w: 400, h: 300 } }),
61
- node('svg', { box: { x: 500, y: 100, w: 20, h: 20 } }),
62
- );
63
- expect(blocks.map((b) => b.kind)).toEqual(['chart']);
64
- });
65
-
66
- it('reads each list item as a point and never the list itself', () => {
67
- const blocks = blocksOf(
68
- node('ul', {}, [node('li', { text: 'One' }), node('li', { text: 'Two' })]),
69
- );
70
- expect(blocks.map((b) => b.kind)).toEqual(['point', 'point']);
71
- expect(blocks.map((b) => b.text)).toEqual(['One', 'Two']);
72
- });
73
-
74
- it('reads a quote', () => {
75
- const [block] = blocksOf(node('blockquote', { text: 'Stay hungry' }));
76
- expect(block.kind).toBe('quote');
77
- });
78
-
79
- it('reads a large figure as number and a small one as text', () => {
80
- const blocks = blocksOf(
81
- node('div', { text: '$40.0M', fontSize: 50 }),
82
- node('div', { text: '$40.0M', fontSize: 24 }),
83
- );
84
- expect(blocks.map((b) => b.kind)).toEqual(['number', 'text']);
85
- });
86
-
87
- it('reads a heading-sized figure as number and heading-sized words as title', () => {
88
- const blocks = blocksOf(
89
- node('div', { text: '$40.0M', fontSize: 96 }),
90
- node('div', { text: 'Revenue', fontSize: 96 }),
91
- );
92
- expect(blocks.map((b) => b.kind)).toEqual(['number', 'title']);
93
- });
94
-
95
- it('reads an h2 that happens to hold a figure as a title', () => {
96
- const [block] = blocksOf(node('h2', { text: '$40.0M', fontSize: 96 }));
97
- expect(block.kind).toBe('title');
98
- });
99
-
100
- it('reads each element that carries its own text as its own block', () => {
101
- const blocks = blocksOf(
102
- node('div', {}, [node('span', { text: 'First' }), node('span', { text: 'second' })]),
103
- );
104
- expect(blocks.map((b) => b.text)).toEqual(['First', 'second']);
105
- });
106
-
107
- it('keeps the words an inline element carries', () => {
108
- const [block] = blocksOf(
109
- node(
110
- 'p',
111
- {
112
- text: 'How we get from $28.6M to ',
113
- fullText: 'How we get from $28.6M to $40.0M ARR, and who does what.',
114
- },
115
- [node('span', { text: '$40.0M ARR' })],
116
- ),
117
- );
118
- expect(block.kind).toBe('text');
119
- expect(block.text).toBe('How we get from $28.6M to $40.0M ARR, and who does what.');
120
- });
121
-
122
- it('reads a heading split by line breaks as one run of words', () => {
123
- const [block] = blocksOf(
124
- node('h1', { text: 'The FY27', fullText: 'The FY27 operating plan.' }),
125
- );
126
- expect(block.kind).toBe('title');
127
- expect(block.text).toBe('The FY27 operating plan.');
128
- });
129
-
130
- it('gives an image or a chart no words of its own', () => {
131
- const blocks = blocksOf(node('img'), node('svg', { box: { x: 0, y: 100, w: 400, h: 300 } }));
132
- expect(blocks.map((b) => b.text)).toEqual(['', '']);
133
- });
134
-
135
- it('leaves small type on the page', () => {
136
- const blocks = blocksOf(
137
- node('div', { text: 'Fieldwork', fontSize: 12 }),
138
- node('div', { text: '01 / 13', fontSize: 12 }),
139
- node('div', { text: 'Margins held', fontSize: 32 }),
140
- );
141
- expect(blocks.map((b) => b.text)).toEqual(['Margins held']);
142
- });
143
-
144
- it('does not count small type toward the forty', () => {
145
- const small = Array.from({ length: 40 }, (_, i) =>
146
- node('div', { text: `label ${i}`, fontSize: 11 }),
147
- );
148
- const big = Array.from({ length: 40 }, (_, i) => node('div', { text: `point ${i}` }));
149
- expect(blocksOf(...small, ...big)).toHaveLength(40);
150
- });
151
- });
152
-
153
- describe('readBlocks structure', () => {
154
- it('does not read the inside of a block again', () => {
155
- const blocks = blocksOf(node('h1', { text: 'Title' }, [node('span', { text: 'Inner' })]));
156
- expect(blocks).toHaveLength(1);
157
- });
158
-
159
- it('reads top to bottom, then left to right', () => {
160
- const blocks = blocksOf(
161
- node('div', { text: 'bottom-left', box: { x: 0, y: 400, w: 100, h: 40 } }),
162
- node('div', { text: 'right', box: { x: 600, y: 100, w: 100, h: 40 } }),
163
- node('div', { text: 'left', box: { x: 0, y: 105, w: 100, h: 40 } }),
164
- );
165
- expect(blocks.map((b) => b.text)).toEqual(['left', 'right', 'bottom-left']);
166
- });
167
-
168
- it('uses the loc as the id and numbers repeats', () => {
169
- const blocks = blocksOf(
170
- node('div', { text: 'a', loc: '1:1' }),
171
- node('div', { text: 'b', loc: '1:1' }),
172
- node('div', { text: 'c', loc: '2:1' }),
173
- );
174
- expect(blocks.map((b) => b.id)).toEqual(['1:1', '1:1#2', '2:1']);
175
- });
176
-
177
- it('numbers blocks that have no loc', () => {
178
- const blocks = blocksOf(node('div', { text: 'a' }), node('div', { text: 'b' }));
179
- expect(blocks.map((b) => b.id)).toEqual(['n0', 'n1']);
180
- });
181
-
182
- it('squashes whitespace and clips to 80 characters', () => {
183
- const long = 'word '.repeat(40);
184
- const [block] = blocksOf(node('div', { text: long }));
185
- expect(block.text.length).toBe(80);
186
- expect(block.text).not.toContain(' ');
187
- });
188
- });
189
-
190
- describe('readBlocks whole-page reasons', () => {
191
- it('refuses a page with stepped reveals', () => {
192
- expect(readBlocks(page(node('div', { text: 'x', step: true })))).toEqual({
193
- whole: 'steps',
194
- });
195
- });
196
-
197
- it('refuses a page with nothing readable', () => {
198
- expect(readBlocks(page(node('div')))).toEqual({ whole: 'empty' });
199
- });
200
-
201
- it('refuses a page with more than 40 blocks', () => {
202
- const many = Array.from({ length: 41 }, (_, i) => node('div', { text: `item ${i}` }));
203
- expect(readBlocks(page(...many))).toEqual({ whole: 'tooMany' });
204
- });
205
-
206
- it('refuses a page whose tree could not be copied', () => {
207
- expect(readBlocks(null)).toEqual({ whole: 'tooLarge' });
208
- });
209
- });