@lemonriver/core 1.0.2 → 1.2.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.
- package/dist/{build-DYN-H65n.js → build-CSkdswfd.js} +1 -1
- package/dist/cli/bin.js +5 -5
- package/dist/{config-DW1wSoxa.js → config-C5-myPY6.js} +2087 -1439
- package/dist/{dev-_VDoRfAK.js → dev-DHtYH8sw.js} +2 -2
- package/dist/{mcp-CjYDzcJa.js → mcp-B2UeO1un.js} +1 -1
- package/dist/{preview-CYIGh3Z8.js → preview-C1B6-umF.js} +1 -1
- package/dist/{update-b1dSg_FW.js → update-DzL8fpcI.js} +1 -1
- package/dist/vite/index.js +1 -1
- package/package.json +5 -2
- package/release-notes.json +19 -0
- package/src/app/components/command/slide-command-menu.tsx +0 -9
- package/src/app/lemonriver/backup/client.ts +25 -1
- package/src/app/lemonriver/backup/model.ts +63 -18
- package/src/app/lemonriver/board/board-page.tsx +2 -2
- package/src/app/lemonriver/chrome/app-chrome.tsx +52 -0
- package/src/app/lemonriver/chrome/sidebar-extras.tsx +8 -1
- package/src/app/lemonriver/feedback/dialog.tsx +222 -0
- package/src/app/lemonriver/feedback/export.ts +21 -2
- package/src/app/lemonriver/feedback/first-success.ts +30 -0
- package/src/app/lemonriver/feedback/install.ts +18 -0
- package/src/app/lemonriver/feedback/model.ts +88 -0
- package/src/app/lemonriver/help/help-page.tsx +16 -1
- package/src/app/lemonriver/help/model.ts +1 -1
- package/src/app/lemonriver/home/drafts.ts +57 -0
- package/src/app/lemonriver/home/home-page.tsx +94 -10
- package/src/app/lemonriver/home/organize-drafts.tsx +192 -0
- package/src/app/lemonriver/links.ts +16 -0
- package/src/app/lemonriver/outline/outline-page.tsx +8 -1
- package/src/app/lemonriver/settings/backup-restore-dialog.tsx +15 -1
- package/src/app/lemonriver/settings/backup-section.tsx +159 -28
- package/src/app/lemonriver/settings/settings-page.tsx +23 -0
- package/src/app/lemonriver/settings/workspace-card.tsx +53 -0
- package/src/app/lemonriver/settings/workspace.ts +37 -0
- package/src/app/lemonriver/share/editor-share.tsx +58 -0
- package/src/app/lemonriver/share/import-dialog.tsx +14 -0
- package/src/app/lemonriver/share/naming.ts +6 -1
- package/src/app/lemonriver/share/share-dialog.tsx +2 -0
- package/src/app/lemonriver/slide-extensions.tsx +37 -53
- package/src/app/lemonriver/text/en.ts +91 -11
- package/src/app/lemonriver/text/es.ts +81 -6
- package/src/app/lemonriver/text/ja.ts +80 -6
- package/src/app/lemonriver/text/types.ts +89 -6
- package/src/app/lemonriver/text/zh-cn.ts +92 -11
- package/src/app/lemonriver/text/zh-tw.ts +92 -11
- package/src/app/lemonriver/theme/pages.ts +4 -0
- package/src/app/lemonriver/update/beta-badge.tsx +69 -0
- package/src/app/lemonriver/update/release-notes.ts +22 -0
- package/src/app/lemonriver/update/update-prompt.tsx +28 -4
- package/src/app/lib/export-html.ts +5 -3
- package/src/app/lib/export-pptx.ts +5 -4
- package/src/app/routes/slide.tsx +6 -57
- package/src/app/components/note-markdown.test.tsx +0 -42
- package/src/app/components/thumbnail-rail-scroll.test.ts +0 -60
- package/src/app/lemonriver/agent-prefs/prefs.test.ts +0 -173
- package/src/app/lemonriver/backup/guide.test.ts +0 -45
- package/src/app/lemonriver/backup/model.test.ts +0 -96
- package/src/app/lemonriver/backup/places.test.ts +0 -154
- package/src/app/lemonriver/board/blocks/classify.test.ts +0 -209
- package/src/app/lemonriver/board/layout.test.ts +0 -245
- package/src/app/lemonriver/board/model/agent-tasks.test.ts +0 -200
- package/src/app/lemonriver/board/model/apply-prompt.test.ts +0 -121
- package/src/app/lemonriver/board/model/cards.test.ts +0 -332
- package/src/app/lemonriver/board/model/changes.test.ts +0 -244
- package/src/app/lemonriver/board/model/filter.test.ts +0 -50
- package/src/app/lemonriver/board/model/history.test.ts +0 -71
- package/src/app/lemonriver/board/model/restructure.test.ts +0 -205
- package/src/app/lemonriver/board/model/self-check.test.ts +0 -329
- package/src/app/lemonriver/board/model/structure.test.ts +0 -350
- package/src/app/lemonriver/board/model/timing.test.ts +0 -113
- package/src/app/lemonriver/features.test.ts +0 -49
- package/src/app/lemonriver/feedback/pending-toast.test.ts +0 -44
- package/src/app/lemonriver/feedback/upload.test.ts +0 -26
- package/src/app/lemonriver/help/model.test.ts +0 -179
- package/src/app/lemonriver/home/brief.test.ts +0 -38
- package/src/app/lemonriver/home/sorting.test.ts +0 -24
- package/src/app/lemonriver/home/time.test.ts +0 -33
- package/src/app/lemonriver/outline/files.test.ts +0 -90
- package/src/app/lemonriver/outline/model.test.ts +0 -751
- package/src/app/lemonriver/public-links.test.ts +0 -32
- package/src/app/lemonriver/routes.test.tsx +0 -54
- package/src/app/lemonriver/share/codes.test.ts +0 -49
- package/src/app/lemonriver/share/compare.test.ts +0 -199
- package/src/app/lemonriver/share/folder.test.ts +0 -42
- package/src/app/lemonriver/share/guide.test.ts +0 -78
- package/src/app/lemonriver/share/naming.test.ts +0 -59
- package/src/app/lemonriver/share/paths.test.ts +0 -116
- package/src/app/lemonriver/share/pdf.test.ts +0 -79
- package/src/app/lemonriver/templates/knobs.test.ts +0 -62
- package/src/app/lemonriver/templates/model.test.ts +0 -175
- package/src/app/lemonriver/templates/preview-content.test.ts +0 -117
- package/src/app/lemonriver/templates/recommend.test.ts +0 -71
- package/src/app/lemonriver/text/text.test.ts +0 -90
- package/src/app/lemonriver/theme/pages.test.ts +0 -74
- package/src/app/lemonriver/theme/themes.test.ts +0 -18
- package/src/app/lemonriver/trash/api.test.ts +0 -19
- package/src/app/lemonriver/update/prompt.test.ts +0 -84
- package/src/app/lemonriver/update/version.test.ts +0 -14
- package/src/app/lib/asset-filter.test.ts +0 -176
- package/src/app/lib/inspector/fiber.test.ts +0 -154
- package/src/app/lib/inspector/geometry.test.ts +0 -324
- package/src/app/lib/inspector/text-edit-timeline.test.ts +0 -121
- package/src/app/lib/note-markdown.test.ts +0 -147
- package/src/app/lib/pptx/css.test.ts +0 -205
- package/src/app/lib/pptx/ooxml.test.ts +0 -199
- package/src/app/lib/pptx/text-lines.test.ts +0 -82
- package/src/app/lib/print-ready.test.ts +0 -32
- package/src/app/lib/sdk.test.ts +0 -13
- package/src/app/lib/transition.test.ts +0 -31
- package/src/app/lib/use-document-title.test.ts +0 -14
- package/src/app/lib/utils.test.ts +0 -49
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
backupDue,
|
|
4
|
-
backupFileStem,
|
|
5
|
-
DAY_MS,
|
|
6
|
-
DEFAULT_KEEP,
|
|
7
|
-
isCompressedFile,
|
|
8
|
-
looksLikeBackupName,
|
|
9
|
-
PREFS_KEYS,
|
|
10
|
-
sanitizePrefs,
|
|
11
|
-
sanitizeSettings,
|
|
12
|
-
} from './model.ts';
|
|
13
|
-
|
|
14
|
-
const SETTINGS = { folder: '/Users/me/Backups', auto: true, keep: 7, last: null, written: [] };
|
|
15
|
-
|
|
16
|
-
describe('backup settings', () => {
|
|
17
|
-
it('falls back to a usable default', () => {
|
|
18
|
-
expect(sanitizeSettings(null)).toEqual({
|
|
19
|
-
folder: null,
|
|
20
|
-
auto: false,
|
|
21
|
-
keep: DEFAULT_KEEP,
|
|
22
|
-
last: null,
|
|
23
|
-
written: [],
|
|
24
|
-
});
|
|
25
|
-
expect(sanitizeSettings({ folder: 'relative/path' }).folder).toBeNull();
|
|
26
|
-
expect(sanitizeSettings({ keep: 5 }).keep).toBe(DEFAULT_KEEP);
|
|
27
|
-
expect(sanitizeSettings({ keep: 30 }).keep).toBe(30);
|
|
28
|
-
expect(sanitizeSettings({ written: ['a.zip', 'a.zip', 'x/y.zip'] }).written).toEqual(['a.zip']);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('knows when the daily backup is due', () => {
|
|
32
|
-
const now = 1_800_000_000_000;
|
|
33
|
-
expect(backupDue(sanitizeSettings({ ...SETTINGS, auto: false }), now)).toBe(false);
|
|
34
|
-
expect(backupDue(sanitizeSettings({ ...SETTINGS, folder: null }), now)).toBe(false);
|
|
35
|
-
expect(backupDue(sanitizeSettings(SETTINGS), now)).toBe(true);
|
|
36
|
-
expect(
|
|
37
|
-
backupDue(
|
|
38
|
-
sanitizeSettings({ ...SETTINGS, last: { at: now - 23 * 3600_000, ok: true } }),
|
|
39
|
-
now,
|
|
40
|
-
),
|
|
41
|
-
).toBe(false);
|
|
42
|
-
expect(
|
|
43
|
-
backupDue(sanitizeSettings({ ...SETTINGS, last: { at: now - DAY_MS - 1, ok: true } }), now),
|
|
44
|
-
).toBe(true);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('waits an hour before retrying a failed backup', () => {
|
|
48
|
-
const now = 1_800_000_000_000;
|
|
49
|
-
const failed = { at: now - 10 * 60_000, ok: false, path: '', size: 0, error: 'denied' };
|
|
50
|
-
expect(backupDue(sanitizeSettings({ ...SETTINGS, last: failed }), now)).toBe(false);
|
|
51
|
-
const older = { ...failed, at: now - 2 * 3600_000 };
|
|
52
|
-
expect(backupDue(sanitizeSettings({ ...SETTINGS, last: older }), now)).toBe(true);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('names the file after the local date and time', () => {
|
|
56
|
-
const at = new Date(2026, 10, 1, 21, 30).getTime();
|
|
57
|
-
expect(backupFileStem(at)).toBe('LemonRiver 备份 2026-11-01 2130');
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('stores formats that are already compressed', () => {
|
|
61
|
-
expect(isCompressedFile('photo.JPG')).toBe(true);
|
|
62
|
-
expect(isCompressedFile('report.pdf')).toBe(true);
|
|
63
|
-
expect(isCompressedFile('deck.pptx')).toBe(true);
|
|
64
|
-
expect(isCompressedFile('index.tsx')).toBe(false);
|
|
65
|
-
expect(isCompressedFile('notes.md')).toBe(false);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('counts only its own file names as backups', () => {
|
|
69
|
-
expect(looksLikeBackupName('LemonRiver 备份 2026-11-01 2130.zip')).toBe(true);
|
|
70
|
-
expect(looksLikeBackupName('my stuff.zip')).toBe(false);
|
|
71
|
-
expect(looksLikeBackupName('LemonRiver 备份 notes.txt')).toBe(false);
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
describe('prefs that travel with a backup', () => {
|
|
76
|
-
it('keeps the whitelist and drops everything else', () => {
|
|
77
|
-
const kept = sanitizePrefs({
|
|
78
|
-
theme: 'dark',
|
|
79
|
-
'open-slide:locale': 'zh-CN',
|
|
80
|
-
'lemonriver:agent-prefs': '{"tone":"steady"}',
|
|
81
|
-
'open-slide:agent-auto-approve': 'true',
|
|
82
|
-
'lemonriver:session': 'secret',
|
|
83
|
-
'open-slide:home-sort': 3,
|
|
84
|
-
});
|
|
85
|
-
expect(kept).toEqual({
|
|
86
|
-
theme: 'dark',
|
|
87
|
-
'open-slide:locale': 'zh-CN',
|
|
88
|
-
'lemonriver:agent-prefs': '{"tone":"steady"}',
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('never carries agent auto-approve', () => {
|
|
93
|
-
expect(PREFS_KEYS as readonly string[]).not.toContain('open-slide:agent-auto-approve');
|
|
94
|
-
expect(sanitizePrefs({ 'open-slide:agent-auto-approve': 'true' })).toEqual({});
|
|
95
|
-
});
|
|
96
|
-
});
|
|
@@ -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
|
-
});
|