@lemonriver/core 1.1.0 → 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.
Files changed (92) 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 +19 -0
  11. package/src/app/lemonriver/chrome/app-chrome.tsx +52 -0
  12. package/src/app/lemonriver/chrome/sidebar-extras.tsx +8 -1
  13. package/src/app/lemonriver/feedback/dialog.tsx +222 -0
  14. package/src/app/lemonriver/feedback/export.ts +21 -2
  15. package/src/app/lemonriver/feedback/first-success.ts +30 -0
  16. package/src/app/lemonriver/feedback/install.ts +18 -0
  17. package/src/app/lemonriver/feedback/model.ts +88 -0
  18. package/src/app/lemonriver/help/help-page.tsx +16 -1
  19. package/src/app/lemonriver/links.ts +16 -0
  20. package/src/app/lemonriver/settings/backup-section.tsx +13 -0
  21. package/src/app/lemonriver/settings/settings-page.tsx +20 -0
  22. package/src/app/lemonriver/share/editor-share.tsx +6 -3
  23. package/src/app/lemonriver/share/share-dialog.tsx +2 -0
  24. package/src/app/lemonriver/text/en.ts +45 -0
  25. package/src/app/lemonriver/text/es.ts +42 -0
  26. package/src/app/lemonriver/text/ja.ts +41 -0
  27. package/src/app/lemonriver/text/types.ts +44 -0
  28. package/src/app/lemonriver/text/zh-cn.ts +45 -0
  29. package/src/app/lemonriver/text/zh-tw.ts +45 -0
  30. package/src/app/lemonriver/theme/pages.ts +4 -0
  31. package/src/app/lemonriver/update/release-notes.ts +22 -0
  32. package/src/app/lemonriver/update/update-prompt.tsx +28 -4
  33. package/src/app/components/note-markdown.test.tsx +0 -42
  34. package/src/app/components/thumbnail-rail-scroll.test.ts +0 -60
  35. package/src/app/lemonriver/agent-prefs/prefs.test.ts +0 -173
  36. package/src/app/lemonriver/backup/guide.test.ts +0 -45
  37. package/src/app/lemonriver/backup/model.test.ts +0 -108
  38. package/src/app/lemonriver/backup/places.test.ts +0 -154
  39. package/src/app/lemonriver/board/blocks/classify.test.ts +0 -209
  40. package/src/app/lemonriver/board/layout.test.ts +0 -245
  41. package/src/app/lemonriver/board/model/agent-tasks.test.ts +0 -200
  42. package/src/app/lemonriver/board/model/apply-prompt.test.ts +0 -121
  43. package/src/app/lemonriver/board/model/cards.test.ts +0 -332
  44. package/src/app/lemonriver/board/model/changes.test.ts +0 -244
  45. package/src/app/lemonriver/board/model/filter.test.ts +0 -50
  46. package/src/app/lemonriver/board/model/history.test.ts +0 -71
  47. package/src/app/lemonriver/board/model/restructure.test.ts +0 -205
  48. package/src/app/lemonriver/board/model/self-check.test.ts +0 -329
  49. package/src/app/lemonriver/board/model/structure.test.ts +0 -350
  50. package/src/app/lemonriver/board/model/timing.test.ts +0 -113
  51. package/src/app/lemonriver/features.test.ts +0 -49
  52. package/src/app/lemonriver/feedback/pending-toast.test.ts +0 -44
  53. package/src/app/lemonriver/feedback/upload.test.ts +0 -26
  54. package/src/app/lemonriver/help/model.test.ts +0 -179
  55. package/src/app/lemonriver/home/brief.test.ts +0 -38
  56. package/src/app/lemonriver/home/drafts.test.ts +0 -23
  57. package/src/app/lemonriver/home/sorting.test.ts +0 -24
  58. package/src/app/lemonriver/home/time.test.ts +0 -33
  59. package/src/app/lemonriver/outline/files.test.ts +0 -90
  60. package/src/app/lemonriver/outline/model.test.ts +0 -751
  61. package/src/app/lemonriver/public-links.test.ts +0 -32
  62. package/src/app/lemonriver/routes.test.tsx +0 -54
  63. package/src/app/lemonriver/share/codes.test.ts +0 -49
  64. package/src/app/lemonriver/share/compare.test.ts +0 -199
  65. package/src/app/lemonriver/share/folder.test.ts +0 -42
  66. package/src/app/lemonriver/share/guide.test.ts +0 -78
  67. package/src/app/lemonriver/share/naming.test.ts +0 -70
  68. package/src/app/lemonriver/share/paths.test.ts +0 -116
  69. package/src/app/lemonriver/share/pdf.test.ts +0 -79
  70. package/src/app/lemonriver/templates/knobs.test.ts +0 -62
  71. package/src/app/lemonriver/templates/model.test.ts +0 -175
  72. package/src/app/lemonriver/templates/preview-content.test.ts +0 -117
  73. package/src/app/lemonriver/templates/recommend.test.ts +0 -71
  74. package/src/app/lemonriver/text/text.test.ts +0 -90
  75. package/src/app/lemonriver/theme/pages.test.ts +0 -74
  76. package/src/app/lemonriver/theme/themes.test.ts +0 -18
  77. package/src/app/lemonriver/trash/api.test.ts +0 -19
  78. package/src/app/lemonriver/update/prompt.test.ts +0 -84
  79. package/src/app/lemonriver/update/version.test.ts +0 -14
  80. package/src/app/lib/asset-filter.test.ts +0 -176
  81. package/src/app/lib/inspector/fiber.test.ts +0 -154
  82. package/src/app/lib/inspector/geometry.test.ts +0 -324
  83. package/src/app/lib/inspector/text-edit-timeline.test.ts +0 -121
  84. package/src/app/lib/note-markdown.test.ts +0 -147
  85. package/src/app/lib/pptx/css.test.ts +0 -205
  86. package/src/app/lib/pptx/ooxml.test.ts +0 -199
  87. package/src/app/lib/pptx/text-lines.test.ts +0 -82
  88. package/src/app/lib/print-ready.test.ts +0 -32
  89. package/src/app/lib/sdk.test.ts +0 -13
  90. package/src/app/lib/transition.test.ts +0 -31
  91. package/src/app/lib/use-document-title.test.ts +0 -14
  92. package/src/app/lib/utils.test.ts +0 -49
@@ -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
- });
@@ -1,245 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import type { Page } from '../../lib/sdk';
3
- import {
4
- CARD_BOX_H,
5
- CARD_BOX_W,
6
- CARD_H,
7
- CARD_W,
8
- cardAtPoint,
9
- cardMetrics,
10
- gapAtPoint,
11
- layoutBoard,
12
- linkCurve,
13
- NOTE_H,
14
- orderAfterMove,
15
- orderAfterMoveMany,
16
- seedColumns,
17
- slotAtPoint,
18
- } from './layout';
19
-
20
- /** Pages are identified by their component name, so the fixtures need real names. */
21
- function named(name: string): Page {
22
- const page = () => null;
23
- Object.defineProperty(page, 'name', { value: name });
24
- return page as unknown as Page;
25
- }
26
-
27
- const title = (n: number) => `Part ${n}`;
28
- const sizes = (pages: Page[]) => seedColumns(pages, title).map((c) => c.size);
29
-
30
- describe('seedColumns', () => {
31
- it('starts a column at every chapter page', () => {
32
- const pages = ['Cover', 'Agenda', 'ChapterOne', 'Alpha', 'ChapterTwo', 'Beta'].map(named);
33
- expect(seedColumns(pages, title)).toEqual([
34
- { title: 'Cover', size: 2 },
35
- { title: 'Chapter One', size: 2 },
36
- { title: 'Chapter Two', size: 2 },
37
- ]);
38
- });
39
-
40
- it('ignores a chapter page in the first slot so the deck never opens with an empty column', () => {
41
- expect(sizes(['ChapterOne', 'Alpha', 'ChapterTwo'].map(named))).toEqual([2, 1]);
42
- });
43
-
44
- it('falls back to fixed-length columns when no page declares a chapter', () => {
45
- const pages = Array.from({ length: 14 }, (_, i) => named(`Page${i}`));
46
- expect(sizes(pages)).toEqual([6, 6, 2]);
47
- expect(seedColumns(pages, title).map((c) => c.title)).toEqual(['Part 1', 'Part 2', 'Part 3']);
48
- });
49
-
50
- it('reads the column title off the names real decks use', () => {
51
- const pages = [named('P1Cover'), named('PChapter1'), named('P16ScenarioTable')];
52
- expect(seedColumns(pages, title).map((c) => c.title)).toEqual(['Cover', 'Chapter 1']);
53
- });
54
-
55
- it('falls back to the positional title when the chapter page name carries no words', () => {
56
- const pages = [named('Cover'), named('章'), named('Alpha')];
57
- expect(seedColumns(pages, title)[1].title).toBe('Part 2');
58
- });
59
- });
60
-
61
- describe('layoutBoard', () => {
62
- const columns = [
63
- { title: 'Cover', size: 2 },
64
- { title: 'Chapter One', size: 3 },
65
- ];
66
-
67
- it('stacks a column top to bottom and puts the next column to the right', () => {
68
- const { slots } = layoutBoard(columns);
69
- expect(slots.map((s) => s.column)).toEqual([0, 0, 1, 1, 1]);
70
- expect(slots[0].x).toBe(slots[1].x);
71
- expect(slots[1].y).toBeGreaterThan(slots[0].y);
72
- expect(slots[2].x).toBeGreaterThan(slots[0].x);
73
- });
74
-
75
- it('numbers slots by deck position, so column two continues where column one ended', () => {
76
- expect(layoutBoard(columns).slots.map((s) => s.index)).toEqual([0, 1, 2, 3, 4]);
77
- });
78
-
79
- it('keeps a column that has been emptied, so its title survives', () => {
80
- const laid = layoutBoard([
81
- { title: 'Cover', size: 0 },
82
- { title: 'Chapter One', size: 2 },
83
- ]);
84
- expect(laid.columns.map((c) => c.size)).toEqual([0, 2]);
85
- expect(laid.slots).toHaveLength(2);
86
- expect(laid.slots[0].column).toBe(1);
87
- });
88
-
89
- it('keeps the card box in the slide aspect ratio', () => {
90
- expect(CARD_H).toBeCloseTo((CARD_W * 1080) / 1920);
91
- });
92
- });
93
-
94
- describe('slotAtPoint', () => {
95
- const layout = layoutBoard([
96
- { title: 'Cover', size: 2 },
97
- { title: 'Chapter One', size: 2 },
98
- ]);
99
-
100
- it('resolves a drop on top of a slot to that slot', () => {
101
- const target = layout.slots[2];
102
- expect(slotAtPoint(layout, target.x, target.y, 0)).toBe(2);
103
- });
104
-
105
- it('snaps a drop between two slots to the nearer one', () => {
106
- const [a, b] = [layout.slots[0], layout.slots[1]];
107
- expect(slotAtPoint(layout, a.x, a.y + (b.y - a.y) * 0.4, 3)).toBe(0);
108
- expect(slotAtPoint(layout, a.x, a.y + (b.y - a.y) * 0.6, 3)).toBe(1);
109
- });
110
-
111
- it('keeps a drop far outside the layout on the closest edge slot', () => {
112
- expect(slotAtPoint(layout, -5000, -5000, 3)).toBe(0);
113
- const last = layout.slots[layout.slots.length - 1];
114
- expect(slotAtPoint(layout, last.x + 5000, last.y + 5000, 0)).toBe(3);
115
- });
116
- });
117
-
118
- describe('orderAfterMove', () => {
119
- it('lifts the page out and drops it at the target position', () => {
120
- expect(orderAfterMove(5, 0, 3)).toEqual([1, 2, 3, 0, 4]);
121
- expect(orderAfterMove(5, 4, 1)).toEqual([0, 4, 1, 2, 3]);
122
- expect(orderAfterMove(5, 2, 2)).toEqual([0, 1, 2, 3, 4]);
123
- });
124
- });
125
-
126
- describe('cardAtPoint', () => {
127
- const layout = layoutBoard([
128
- { title: 'Cover', size: 2 },
129
- { title: 'Chapter One', size: 2 },
130
- ]);
131
-
132
- it('finds the card under a point anywhere inside it', () => {
133
- const slot = layout.slots[3];
134
- expect(cardAtPoint(layout, slot.x + CARD_BOX_W - 1, slot.y + CARD_BOX_H - 1)).toBe(3);
135
- });
136
-
137
- it('reports empty canvas between cards as no card', () => {
138
- const [a, b] = [layout.slots[0], layout.slots[1]];
139
- expect(cardAtPoint(layout, a.x + 10, (a.y + CARD_BOX_H + b.y) / 2)).toBeNull();
140
- expect(cardAtPoint(layout, a.x + CARD_BOX_W + 20, a.y + 10)).toBeNull();
141
- });
142
- });
143
-
144
- describe('linkCurve', () => {
145
- const box = (x: number, y: number) => ({ x, y, width: 100, height: 60 });
146
-
147
- it('bows a link between cards in one column out to the right of the column', () => {
148
- const curve = linkCurve(box(0, 0), box(0, 400));
149
- expect(curve.x).toBeGreaterThan(100);
150
- expect(curve.path.startsWith('M 100,18')).toBe(true);
151
- });
152
-
153
- it('never ends where the main line does, at the middle of a card side', () => {
154
- const curve = linkCurve(box(0, 0), box(300, 0));
155
- expect(curve.path).not.toContain(',30');
156
- });
157
-
158
- it('joins cards in different columns between their facing sides, whichever is first', () => {
159
- const forward = linkCurve(box(0, 0), box(300, 200));
160
- const backward = linkCurve(box(300, 200), box(0, 0));
161
- expect(forward.path).toBe(backward.path);
162
- expect(forward.path.startsWith('M 100,18')).toBe(true);
163
- expect(forward.path.endsWith('300,218')).toBe(true);
164
- });
165
- });
166
-
167
- describe('card sizes', () => {
168
- it('keeps the large card at the preview size it has always had', () => {
169
- expect(cardMetrics('large')).toMatchObject({ cardW: CARD_W, cardH: CARD_H, noteH: NOTE_H });
170
- });
171
-
172
- it('halves the preview at small, and drops the strips that need the room', () => {
173
- expect(cardMetrics('small').cardW).toBe(CARD_W / 2);
174
- expect(cardMetrics('small').cardH).toBeCloseTo(CARD_H / 2);
175
- expect(cardMetrics('small').memoH).toBe(0);
176
- });
177
-
178
- it('draws no preview at all when only the title is shown', () => {
179
- expect(cardMetrics('title').cardH).toBe(0);
180
- expect(cardMetrics('title').boxH).toBeLessThan(cardMetrics('small').boxH);
181
- });
182
-
183
- it('lays the same structure out with the metrics of the chosen size', () => {
184
- const columns = [{ title: 'A', size: 2 }];
185
- expect(layoutBoard(columns, { size: 'small' }).metrics.cardW).toBe(CARD_W / 2);
186
- expect(layoutBoard(columns).metrics.cardW).toBe(CARD_W);
187
- });
188
- });
189
-
190
- describe('folded chapters', () => {
191
- const columns = [
192
- { title: 'A', size: 2 },
193
- { title: 'B', size: 3 },
194
- ];
195
-
196
- it('draws no cards for a folded chapter but keeps its pages numbered', () => {
197
- const layout = layoutBoard(columns, { collapsed: [false, true] });
198
- expect(layout.slots.map((s) => s.index)).toEqual([0, 1]);
199
- expect(layout.columns[1].collapsed).toBe(true);
200
- });
201
-
202
- it('keeps the folded chapter label in place while its cards are gone', () => {
203
- const open = layoutBoard(columns);
204
- const folded = layoutBoard(columns, { collapsed: [true, false] });
205
- expect(folded.columns[0].x).toBe(open.columns[0].x);
206
- expect(folded.columns[0].size).toBe(2);
207
- expect(folded.slots.map((s) => s.index)).toEqual([2, 3, 4]);
208
- });
209
- });
210
-
211
- describe('gapAtPoint', () => {
212
- const layout = layoutBoard([
213
- { title: 'A', size: 2 },
214
- { title: 'B', size: 2 },
215
- ]);
216
-
217
- it('names the boundary a point between two chapters sits on', () => {
218
- const right = layout.columns[0].x + layout.columns[0].boxW;
219
- expect(gapAtPoint(layout, right + 10, 100)).toBe(1);
220
- });
221
-
222
- it('reports no boundary over a column or past the last one', () => {
223
- expect(gapAtPoint(layout, layout.columns[0].x + 20, 100)).toBeNull();
224
- expect(gapAtPoint(layout, layout.columns[1].x + 400, 100)).toBeNull();
225
- });
226
- });
227
-
228
- describe('orderAfterMoveMany', () => {
229
- it('carries the picked cards as one block, in deck order', () => {
230
- expect(orderAfterMoveMany(5, [3, 1], 0)).toEqual([1, 3, 0, 2, 4]);
231
- });
232
-
233
- it('lands the block on the slot it was dropped on', () => {
234
- expect(orderAfterMoveMany(6, [0, 1], 4)).toEqual([2, 3, 4, 5, 0, 1]);
235
- expect(orderAfterMoveMany(6, [4, 5], 1)).toEqual([0, 4, 5, 1, 2, 3]);
236
- // The same slot a single card takes, so "move to the end" still ends there.
237
- expect(orderAfterMoveMany(3, [0], 2)).toEqual(orderAfterMove(3, 0, 2));
238
- expect(orderAfterMoveMany(5, [4], 1)).toEqual(orderAfterMove(5, 4, 1));
239
- });
240
-
241
- it('keeps every page exactly once', () => {
242
- const order = orderAfterMoveMany(7, [2, 5, 6], 1);
243
- expect([...order].sort((a, b) => a - b)).toEqual([...Array(7).keys()]);
244
- });
245
- });