@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,71 +0,0 @@
1
- import { describe, expect, it, vi } from 'vitest';
2
- import {
3
- canRedo,
4
- canUndo,
5
- dropStep,
6
- emptyHistory,
7
- HISTORY_LIMIT,
8
- nextUndo,
9
- recordStep,
10
- redoStep,
11
- undoStep,
12
- } from './history.ts';
13
-
14
- const step = (name: string) => ({ undo: vi.fn(), redo: vi.fn(), name });
15
-
16
- describe('history', () => {
17
- it('starts with nothing to undo or redo', () => {
18
- const history = emptyHistory();
19
- expect(canUndo(history)).toBe(false);
20
- expect(canRedo(history)).toBe(false);
21
- expect(nextUndo(history)).toBeNull();
22
- });
23
-
24
- it('hands the newest step to undo and moves it onto the redo stack', () => {
25
- const first = step('first');
26
- const second = step('second');
27
- const history = recordStep(recordStep(emptyHistory(), first), second);
28
-
29
- const taken = undoStep(history);
30
- expect(taken?.step).toBe(second);
31
- expect(canUndo(taken?.history ?? history)).toBe(true);
32
- expect(canRedo(taken?.history ?? history)).toBe(true);
33
- expect(nextUndo(taken?.history ?? history)).toBe(first);
34
- });
35
-
36
- it('walks forward again after an undo, newest first', () => {
37
- const first = step('first');
38
- const second = step('second');
39
- const recorded = recordStep(recordStep(emptyHistory(), first), second);
40
- const once = undoStep(recorded)?.history ?? recorded;
41
- const undone = undoStep(once)?.history ?? once;
42
-
43
- const redone = redoStep(undone);
44
- expect(redone?.step).toBe(first);
45
- const again = redoStep(redone?.history ?? undone);
46
- expect(again?.step).toBe(second);
47
- expect(canRedo(again?.history ?? undone)).toBe(false);
48
- });
49
-
50
- it('retires the redo stack when a new operation is recorded', () => {
51
- const history = recordStep(emptyHistory(), step('first'));
52
- const undone = undoStep(history)?.history ?? history;
53
- expect(canRedo(undone)).toBe(true);
54
- expect(canRedo(recordStep(undone, step('other')))).toBe(false);
55
- });
56
-
57
- it('keeps only the newest fifty steps', () => {
58
- let history = emptyHistory();
59
- for (let i = 0; i < HISTORY_LIMIT + 4; i++) history = recordStep(history, step(`${i}`));
60
- expect(history.past).toHaveLength(HISTORY_LIMIT);
61
- expect(nextUndo(history)).toBe(history.past[HISTORY_LIMIT - 1]);
62
- });
63
-
64
- it('drops a step that cannot be undone and reaches the one before it', () => {
65
- const first = step('first');
66
- const blocked = { undo: null, redo: vi.fn() };
67
- const history = recordStep(recordStep(emptyHistory(), first), blocked);
68
- const dropped = dropStep(history);
69
- expect(nextUndo(dropped)).toBe(first);
70
- });
71
- });
@@ -1,205 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import {
3
- addMerge,
4
- addSplit,
5
- carryRestructures,
6
- type Restructure,
7
- removeRestructure,
8
- restructuredPages,
9
- restructureReplaced,
10
- type SplitBlock,
11
- sanitizeRestructures,
12
- } from './restructure.ts';
13
-
14
- const P1 = '@0';
15
- const P2 = '@1';
16
- const P3 = '@2';
17
-
18
- const picked = (id: string, text = `Text of ${id}`): SplitBlock => ({ id, kind: 'text', text });
19
-
20
- describe('addSplit', () => {
21
- it('adds one record per page and replaces the page’s earlier split', () => {
22
- const once = addSplit([], P1, [picked('a'), picked('b')]);
23
- expect(once).toEqual([
24
- {
25
- kind: 'split',
26
- page: P1,
27
- blocks: ['a', 'b'],
28
- blockInfo: [
29
- { id: 'a', kind: 'text', text: 'Text of a' },
30
- { id: 'b', kind: 'text', text: 'Text of b' },
31
- ],
32
- },
33
- ]);
34
- const twice = addSplit(once, P1, [picked('c')]);
35
- expect(twice).toEqual([
36
- {
37
- kind: 'split',
38
- page: P1,
39
- blocks: ['c'],
40
- blockInfo: [{ id: 'c', kind: 'text', text: 'Text of c' }],
41
- },
42
- ]);
43
- });
44
-
45
- it('takes the place of a merge that involved the page', () => {
46
- const merged = addMerge([], P1, P2);
47
- expect(addSplit(merged, P2, [picked('a')])).toEqual([
48
- {
49
- kind: 'split',
50
- page: P2,
51
- blocks: ['a'],
52
- blockInfo: [{ id: 'a', kind: 'text', text: 'Text of a' }],
53
- },
54
- ]);
55
- });
56
-
57
- it('leaves the list alone when no block is named', () => {
58
- expect(addSplit([], P1, [])).toEqual([]);
59
- expect(addSplit([], P1, [picked('')])).toEqual([]);
60
- });
61
- });
62
-
63
- describe('addMerge', () => {
64
- it('records a pair once and replaces the earlier pair', () => {
65
- const once = addMerge([], P1, P2);
66
- expect(once).toEqual([{ kind: 'merge', pages: [P1, P2] }]);
67
- expect(addMerge(once, P1, P2)).toHaveLength(1);
68
- });
69
-
70
- it('takes the place of a split on either page', () => {
71
- const split = addSplit([], P2, [picked('a')]);
72
- expect(addMerge(split, P1, P2)).toEqual([{ kind: 'merge', pages: [P1, P2] }]);
73
- });
74
-
75
- it('drops a merge that shared a page', () => {
76
- const merged = addMerge(addMerge([], P1, P2), P2, P3);
77
- expect(merged).toEqual([{ kind: 'merge', pages: [P2, P3] }]);
78
- });
79
-
80
- it('refuses the same page twice', () => {
81
- expect(addMerge([], P1, P1)).toEqual([]);
82
- });
83
- });
84
-
85
- describe('restructureReplaced', () => {
86
- it('is true only when a record of the other kind is taken away', () => {
87
- const split = addSplit([], P1, [picked('a')]);
88
- expect(restructureReplaced(split, { kind: 'merge', pages: [P1, P2] })).toBe(true);
89
- expect(restructureReplaced(split, { kind: 'split', page: P1, blocks: ['b'] })).toBe(false);
90
- expect(restructureReplaced(split, { kind: 'split', page: P2, blocks: ['b'] })).toBe(false);
91
- });
92
- });
93
-
94
- describe('removeRestructure', () => {
95
- it('drops the record at that index', () => {
96
- const list: Restructure[] = [
97
- { kind: 'split', page: P1, blocks: ['a'] },
98
- { kind: 'merge', pages: [P2, P3] },
99
- ];
100
- expect(removeRestructure(list, 0)).toEqual([{ kind: 'merge', pages: [P2, P3] }]);
101
- });
102
- });
103
-
104
- describe('restructuredPages', () => {
105
- it('names every page a split or merge touches', () => {
106
- const list: Restructure[] = [
107
- { kind: 'split', page: P1, blocks: ['a'] },
108
- { kind: 'merge', pages: [P2, P3] },
109
- ];
110
- expect([...restructuredPages(list)].sort()).toEqual([P1, P2, P3].sort());
111
- });
112
- });
113
-
114
- describe('carryRestructures', () => {
115
- const before = [P1, P2, P3];
116
-
117
- it('renames the pages a reorder moved', () => {
118
- const list: Restructure[] = [
119
- { kind: 'split', page: P2, blocks: ['a'] },
120
- { kind: 'merge', pages: [P1, P3] },
121
- ];
122
- // Pages keyed by position: what was page 2 is now the first page.
123
- expect(carryRestructures(list, before, [P1, P2, P3], [1, 2, 0])).toEqual([
124
- { kind: 'split', page: P1, blocks: ['a'] },
125
- { kind: 'merge', pages: [P3, P2] },
126
- ]);
127
- });
128
-
129
- it('drops a record whose page is gone', () => {
130
- const list: Restructure[] = [
131
- { kind: 'split', page: P2, blocks: ['a'] },
132
- { kind: 'merge', pages: [P1, P3] },
133
- ];
134
- // Page 2 deleted: the pages left are the first and third, re-keyed.
135
- expect(carryRestructures(list, before, [P1, P2], [0, 2])).toEqual([
136
- { kind: 'merge', pages: [P1, P2] },
137
- ]);
138
- });
139
-
140
- it('renames a duplicate so the copy carries nothing', () => {
141
- const list: Restructure[] = [{ kind: 'split', page: P2, blocks: ['a'] }];
142
- // Page 2 duplicated: the copy takes the new key, the split stays on the original.
143
- expect(carryRestructures(list, before, [P1, P2, P3, '@3'], [0, 1, 2, -1])).toEqual([
144
- { kind: 'split', page: P2, blocks: ['a'] },
145
- ]);
146
- });
147
- });
148
-
149
- describe('sanitizeRestructures', () => {
150
- it('keeps only well-formed records', () => {
151
- expect(
152
- sanitizeRestructures([
153
- { kind: 'split', page: P1, blocks: ['a', '', 'a'] },
154
- { kind: 'merge', pages: [P1, P2] },
155
- { kind: 'merge', pages: [P1, P1] },
156
- { kind: 'split', page: '', blocks: ['a'] },
157
- { kind: 'split', page: P1, blocks: [] },
158
- { kind: 'move', page: P1 },
159
- null,
160
- ]),
161
- ).toEqual([
162
- {
163
- kind: 'split',
164
- page: P1,
165
- blocks: ['a'],
166
- blockInfo: [{ id: 'a', kind: 'text', text: '' }],
167
- },
168
- { kind: 'merge', pages: [P1, P2] },
169
- ]);
170
- });
171
-
172
- it('keeps the words stored beside a split’s blocks', () => {
173
- expect(
174
- sanitizeRestructures([
175
- {
176
- kind: 'split',
177
- page: P1,
178
- blocks: ['a'],
179
- blockInfo: [{ id: 'a', kind: 'chart', text: '' }],
180
- },
181
- ]),
182
- ).toEqual([
183
- {
184
- kind: 'split',
185
- page: P1,
186
- blocks: ['a'],
187
- blockInfo: [{ id: 'a', kind: 'chart', text: '' }],
188
- },
189
- ]);
190
- });
191
-
192
- it('caps the list at fifty', () => {
193
- const many = Array.from({ length: 60 }, (_, i) => ({
194
- kind: 'split',
195
- page: `@${i}`,
196
- blocks: ['a'],
197
- }));
198
- expect(sanitizeRestructures(many)).toHaveLength(50);
199
- });
200
-
201
- it('reads anything that is not a list as none', () => {
202
- expect(sanitizeRestructures(null)).toEqual([]);
203
- expect(sanitizeRestructures({ kind: 'split' })).toEqual([]);
204
- });
205
- });
@@ -1,329 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import type { SnapNode } from '../blocks/classify.ts';
3
- import { type CheckedPage, checkDeck, hintsOf, problemsOf, toHex } from './self-check.ts';
4
-
5
- function node(tag: string, extra: Partial<SnapNode> = {}, children: SnapNode[] = []): SnapNode {
6
- return {
7
- tag,
8
- text: '',
9
- fullText: extra.fullText ?? extra.text ?? '',
10
- fontSize: 32,
11
- lineHeight: 0,
12
- fontWeight: 400,
13
- color: '#111111',
14
- background: '',
15
- box: { x: 0, y: 540, w: 0, h: 0 },
16
- clip: null,
17
- lines: [],
18
- loc: null,
19
- placeholder: false,
20
- step: false,
21
- children,
22
- ...extra,
23
- };
24
- }
25
-
26
- const page = (children: SnapNode[], notes = '一句话讲稿'): CheckedPage => ({
27
- n: 1,
28
- tree: node('div', { box: { x: 0, y: 0, w: 1920, h: 1080 } }, children),
29
- notes,
30
- title: '测试页',
31
- });
32
-
33
- const findingsOf = (pages: CheckedPage[], options: { accent?: string; minType?: number } = {}) =>
34
- checkDeck(pages, options).findings;
35
-
36
- const kinds = (pages: CheckedPage[], options: { accent?: string; minType?: number } = {}) =>
37
- findingsOf(pages, options).map((finding) => finding.kind);
38
-
39
- const PARAGRAPH = '这是一段真正的正文,长度超过二十四个字,够格算段落,请认真读。';
40
-
41
- describe('toHex', () => {
42
- it('turns rgb and hex into one lowercase hex form', () => {
43
- expect(toHex('rgb(255, 0, 0)')).toBe('#ff0000');
44
- expect(toHex('rgba(255, 0, 0, 0.5)')).toBe('#ff0000');
45
- expect(toHex('#FF0000')).toBe('#ff0000');
46
- expect(toHex('#f00')).toBe('#ff0000');
47
- expect(toHex('rgba(0, 0, 0, 0)')).toBe('');
48
- expect(toHex('color(srgb 1 0 0)')).toBe('');
49
- });
50
- });
51
-
52
- describe('checkDeck', () => {
53
- it('flags type under 20px and leaves 20px alone', () => {
54
- expect(kinds([page([node('p', { text: '小字', fontSize: 14 })])])).toContain('tiny');
55
- expect(kinds([page([node('p', { text: '小字', fontSize: 21 })])])).not.toContain('tiny');
56
- });
57
-
58
- it('lets a running part in the header or footer band go down to 18px', () => {
59
- const line = (y: number, size: number, text = '页码') =>
60
- node('p', { text, fontSize: size, box: { x: 1600, y, w: 200, h: 30 } });
61
- expect(kinds([page([line(1000, 21)])])).not.toContain('tiny');
62
- expect(kinds([page([line(1000, 17)])])).toContain('tiny');
63
- expect(kinds([page([line(70, 19)])])).not.toContain('tiny');
64
- expect(kinds([page([line(60, 17)])])).toContain('tiny');
65
- const midway = node('p', {
66
- text: '正文',
67
- fontSize: 19,
68
- box: { x: 120, y: 500, w: 300, h: 30 },
69
- });
70
- expect(kinds([page([midway])])).toContain('tiny');
71
- });
72
-
73
- it('does not look for body copy or accent inside the bands', () => {
74
- const body = node('p', {
75
- text: PARAGRAPH,
76
- fontSize: 21,
77
- box: { x: 120, y: 1000, w: 900, h: 30 },
78
- });
79
- expect(kinds([page([body])])).not.toContain('small-body');
80
- const marked = (x: number) =>
81
- node('div', { background: '#ff0000', box: { x, y: 960, w: 300, h: 60 } });
82
- expect(
83
- kinds([page([marked(100), marked(400), marked(700), marked(1000)])], { accent: '#ff0000' }),
84
- ).not.toContain('accent');
85
- });
86
-
87
- it('flags a paragraph under 22px but not a short label at the same size', () => {
88
- const run = (text: string, size: number) => node('p', { text, fontSize: size });
89
- expect(kinds([page([run(PARAGRAPH, 21)])])).toContain('small-body');
90
- expect(kinds([page([run(PARAGRAPH, 22)])])).not.toContain('small-body');
91
- expect(kinds([page([run('坐标轴 2026', 21)])])).not.toContain('small-body');
92
- });
93
-
94
- it('counts a Latin paragraph by its letters', () => {
95
- const run = (text: string) => node('p', { text, fontSize: 21 });
96
- expect(kinds([page([run('A short caption line')])])).not.toContain('small-body');
97
- expect(kinds([page([run('This paragraph is long enough to be real body copy.')])])).toContain(
98
- 'small-body',
99
- );
100
- });
101
-
102
- it('takes a template’s own floor for small type, inside 16 to 20', () => {
103
- const label = node('p', { text: '短标签', fontSize: 17 });
104
- expect(kinds([page([label])])).toContain('tiny');
105
- expect(kinds([page([label])], { minType: 16 })).not.toContain('tiny');
106
- expect(findingsOf([page([label])], { minType: 12 })).toEqual(findingsOf([page([label])]));
107
- });
108
-
109
- it('merges one kind on a page into one entry with every place', () => {
110
- const small = (x: number, size: number) =>
111
- node('p', { text: '小字', fontSize: size, box: { x, y: 300, w: 120, h: 30 } });
112
- const findings = findingsOf([page([small(100, 14), small(400, 18), small(700, 16)])]);
113
- const tiny = findings.filter((finding) => finding.kind === 'tiny');
114
- expect(tiny).toHaveLength(1);
115
- expect(tiny[0].count).toBe(3);
116
- expect(tiny[0].boxes).toHaveLength(3);
117
- expect(tiny[0].size).toBe(14);
118
- expect(tiny[0].detail).toBe('3 runs of type at 14px');
119
- });
120
-
121
- it('keeps a page of many small runs to one problem', () => {
122
- const runs = Array.from({ length: 40 }, (_, i) =>
123
- node('p', { text: '标注', fontSize: 14, box: { x: 40 * i, y: 700, w: 30, h: 20 } }),
124
- );
125
- expect(kinds([page(runs)])).toEqual(['tiny']);
126
- });
127
-
128
- it('flags text and pictures that leave the canvas, not a decorative block', () => {
129
- const bleed = { x: 1600, y: 900, w: 400, h: 100 };
130
- const text = node('p', { text: '出界', box: bleed });
131
- const decoration = node('div', { background: '#dddddd', box: bleed });
132
- const picture = node('img', { box: bleed });
133
- const inside = node('p', { text: '在页内', box: { x: 1600, y: 900, w: 300, h: 100 } });
134
- expect(kinds([page([text])])).toContain('overflow');
135
- expect(kinds([page([decoration])])).not.toContain('overflow');
136
- expect(kinds([page([picture])])).toContain('overflow');
137
- expect(kinds([page([inside])])).not.toContain('overflow');
138
- });
139
-
140
- it('leaves a copy an ancestor clips away alone, and still flags one that shows', () => {
141
- const bleed = { x: 1600, y: 900, w: 400, h: 100 };
142
- const band = { x: 0, y: 860, w: 1920, h: 220 };
143
- const gone = node('p', {
144
- text: '行情带副本',
145
- box: bleed,
146
- clip: { x: 0, y: 0, w: 1920, h: 880 },
147
- });
148
- const trimmed = node('p', { text: '行情带', box: bleed, clip: band });
149
- const seen = node('p', { text: '出界', box: bleed });
150
- expect(kinds([page([gone])])).not.toContain('overflow');
151
- expect(kinds([page([trimmed])])).not.toContain('overflow');
152
- expect(kinds([page([seen])])).toContain('overflow');
153
- });
154
-
155
- it('reads two lines that only touch as separate, and two that overlap as one', () => {
156
- const line = (y: number) => ({ x: 200, y, w: 600, h: 48 });
157
- const lineOf = (text: string, y: number) =>
158
- node('p', {
159
- text,
160
- fontSize: 32,
161
- lineHeight: 48,
162
- box: line(y),
163
- lines: [line(y)],
164
- });
165
- expect(kinds([page([lineOf('第一行', 200), lineOf('第二行', 242)])])).not.toContain('overlap');
166
- expect(kinds([page([lineOf('第一行', 200), lineOf('压上来', 224)])])).toContain('overlap');
167
- });
168
-
169
- it('leaves a giant number or watermark out of overlap and overflow', () => {
170
- const giant = node('div', {
171
- text: 'Q3',
172
- fontSize: 520,
173
- box: { x: 1000, y: 500, w: 900, h: 700 },
174
- });
175
- expect(kinds([page([giant])])).not.toContain('overflow');
176
- const body = node('p', { text: '副标题', box: { x: 1000, y: 520, w: 400, h: 60 } });
177
- expect(kinds([page([giant, body])])).not.toContain('overlap');
178
- });
179
-
180
- it('flags a page with no notes', () => {
181
- expect(kinds([page([], '')])).toContain('no-notes');
182
- expect(kinds([page([], '一句话讲稿')])).not.toContain('no-notes');
183
- });
184
-
185
- it('does not pass a page it could not read', () => {
186
- const unreadPage: CheckedPage = { n: 3, tree: null, notes: '', title: '' };
187
- const result = checkDeck([unreadPage]);
188
- expect(result.unread).toEqual([3]);
189
- expect(result.findings.map((finding) => finding.kind)).toEqual(['no-notes']);
190
- });
191
-
192
- it('flags a title over 24 characters, or over 12 English words', () => {
193
- const title = (text: string) => node('h1', { text, fontSize: 64 });
194
- expect(kinds([page([title('一二三四五六七八九十一二三四五六七八九十一二三四五')])])).toContain(
195
- 'long-title',
196
- );
197
- expect(kinds([page([title('第三季度经营情况')])])).not.toContain('long-title');
198
- expect(
199
- kinds([page([title('one two three four five six seven eight nine ten eleven twelve')])]),
200
- ).not.toContain('long-title');
201
- expect(
202
- kinds([
203
- page([title('one two three four five six seven eight nine ten eleven twelve thirteen')]),
204
- ]),
205
- ).toContain('long-title');
206
- });
207
-
208
- it('counts the accent once per block, and flags more than three blocks', () => {
209
- const accent = (background: string) => node('div', { background });
210
- const three = [accent('#ff0000'), accent('#ff0000'), accent('#ff0000')];
211
- const four = [...three, accent('#ff0000')];
212
- expect(kinds([page(three)], { accent: '#ff0000' })).not.toContain('accent');
213
- expect(kinds([page(four)], { accent: '#ff0000' })).toContain('accent');
214
- expect(findingsOf([page(four)], { accent: '#ff0000' })[0]?.measure).toBe(4);
215
- });
216
-
217
- it('keeps several accent elements of one block as one use', () => {
218
- const marked = (y: number) =>
219
- node('span', { background: '#ff0000', text: '强', box: { x: 20, y, w: 60, h: 40 } });
220
- const block = node(
221
- 'p',
222
- { text: '一段带强调的正文', fontSize: 32, box: { x: 0, y: 100, w: 600, h: 200 } },
223
- [marked(110), marked(160), marked(210), marked(260)],
224
- );
225
- expect(kinds([page([block])], { accent: '#ff0000' })).not.toContain('accent');
226
- });
227
-
228
- it('does not flag text that sits inside a panel, and flags text crossing its edge', () => {
229
- const panel = (children: SnapNode[] = []) =>
230
- node('div', { background: '#eeeeee', box: { x: 100, y: 100, w: 400, h: 400 } }, children);
231
- const inside = node('p', { text: '在面板里面', box: { x: 150, y: 150, w: 200, h: 40 } });
232
- const across = node('p', { text: '跨过边缘', box: { x: 400, y: 150, w: 300, h: 40 } });
233
-
234
- expect(kinds([page([panel(), inside])])).not.toContain('overlap');
235
- expect(kinds([page([panel([inside])])])).not.toContain('overlap');
236
- expect(kinds([page([panel(), across])])).toContain('overlap');
237
- });
238
-
239
- it('judges a crossing by the lines the words fall on', () => {
240
- const panel = node('div', { background: '#eeeeee', box: { x: 100, y: 100, w: 400, h: 400 } });
241
- const line = (box: { x: number; y: number; w: number; h: number }) =>
242
- node('p', {
243
- text: '一行字',
244
- box: { x: box.x, y: box.y - 10, w: box.w + 200, h: box.h + 20 },
245
- lines: [box],
246
- });
247
- expect(kinds([page([panel, line({ x: 150, y: 150, w: 200, h: 40 })])])).not.toContain(
248
- 'overlap',
249
- );
250
- expect(kinds([page([panel, line({ x: 400, y: 150, w: 300, h: 40 })])])).toContain('overlap');
251
- });
252
-
253
- it('flags two blocks of text that overlap, but not two parts of one block', () => {
254
- const a = node('p', { text: '第一段', box: { x: 100, y: 100, w: 300, h: 60 } });
255
- const b = node('p', { text: '第二段', box: { x: 200, y: 120, w: 300, h: 60 } });
256
- const apart = node('p', { text: '第三段', box: { x: 100, y: 400, w: 300, h: 60 } });
257
- expect(kinds([page([a, apart])])).not.toContain('overlap');
258
- expect(kinds([page([a, b])])).toContain('overlap');
259
-
260
- const span = (text: string, y: number) =>
261
- node('span', { text, box: { x: 100, y, w: 200, h: 40 } });
262
- const oneBlock = node('li', { box: { x: 100, y: 200, w: 300, h: 100 } }, [
263
- span('同一块', 210),
264
- span('也是同一块', 240),
265
- ]);
266
- expect(kinds([page([oneBlock])])).not.toContain('overlap');
267
-
268
- const loose = node('div', { box: { x: 100, y: 500, w: 300, h: 100 } }, [
269
- span('第一块', 510),
270
- span('第二块', 540),
271
- ]);
272
- expect(kinds([page([loose])])).toContain('overlap');
273
- });
274
-
275
- it('judges two runs by their line boxes, not their element boxes', () => {
276
- const wide = node('p', {
277
- text: '同一行左边',
278
- box: { x: 100, y: 300, w: 900, h: 60 },
279
- lines: [{ x: 100, y: 310, w: 300, h: 40 }],
280
- });
281
- const neighbour = node('p', {
282
- text: '同一行右边',
283
- box: { x: 500, y: 300, w: 700, h: 60 },
284
- lines: [{ x: 500, y: 310, w: 300, h: 40 }],
285
- });
286
- expect(kinds([page([wide, neighbour])])).not.toContain('overlap');
287
-
288
- const reaching = node('p', {
289
- text: '一行很长的字',
290
- box: { x: 100, y: 600, w: 900, h: 60 },
291
- lines: [{ x: 100, y: 610, w: 800, h: 40 }],
292
- });
293
- const other = node('p', {
294
- text: '右边一段',
295
- box: { x: 700, y: 600, w: 700, h: 60 },
296
- lines: [{ x: 700, y: 610, w: 300, h: 40 }],
297
- });
298
- expect(kinds([page([reaching, other])])).toContain('overlap');
299
- });
300
-
301
- it('does not flag a span inside its paragraph', () => {
302
- const outer = node('p', { text: '整段文字', box: { x: 100, y: 200, w: 400, h: 80 } });
303
- const inner = node('span', { text: '强调', box: { x: 120, y: 210, w: 100, h: 30 } });
304
- expect(kinds([page([outer, inner])])).not.toContain('overlap');
305
- });
306
-
307
- it('counts style choices as hints, not as problems', () => {
308
- const long = node('h1', { text: '一二三四五六七八九十一二三四五六七八九十一二三四五' });
309
- const accent = (x: number) =>
310
- node('div', { background: '#ff0000', box: { x, y: 800, w: 50, h: 50 } });
311
- const findings = findingsOf(
312
- [page([long, accent(100), accent(300), accent(500), accent(700)])],
313
- { accent: '#ff0000' },
314
- );
315
- expect(problemsOf(findings)).toEqual([]);
316
- expect(
317
- hintsOf(findings)
318
- .map((finding) => finding.kind)
319
- .sort(),
320
- ).toEqual(['accent', 'long-title']);
321
- });
322
-
323
- it('reports the page number the deck shows', () => {
324
- const { findings } = checkDeck([
325
- { ...page([node('p', { text: '小字', fontSize: 14 })]), n: 7 },
326
- ]);
327
- expect(findings.every((finding) => finding.page === 7)).toBe(true);
328
- });
329
- });