@lemonriver/core 0.4.0 → 0.6.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 (115) hide show
  1. package/README.md +14 -4
  2. package/dist/{build-Nl7EeJ6x.js → build-RlcGG-Ve.js} +1 -1
  3. package/dist/cli/bin.js +4 -4
  4. package/dist/{config-CpC0nM3r.js → config-BJT87wE9.js} +4756 -2012
  5. package/dist/{dev-BB3THd5I.js → dev-DR-j_xda.js} +2 -2
  6. package/dist/{preview-BGjgTg7H.js → preview-BTAhTb5B.js} +1 -1
  7. package/dist/{update-DsxZBtwv.js → update-CMRxtTc9.js} +18 -8
  8. package/dist/vite/index.js +1 -1
  9. package/package.json +2 -2
  10. package/src/agent/types.ts +14 -2
  11. package/src/app/components/agent/agent-panel.tsx +17 -5
  12. package/src/app/components/agent/connect-view.tsx +1 -1
  13. package/src/app/components/agent/provider-logo.tsx +10 -1
  14. package/src/app/lemonriver/agent/provider-marks.tsx +53 -0
  15. package/src/app/lemonriver/agent-providers/section.tsx +75 -0
  16. package/src/app/lemonriver/agent-providers/use-providers.ts +61 -0
  17. package/src/app/lemonriver/board/blocks/block-panel.tsx +666 -0
  18. package/src/app/lemonriver/board/blocks/cache.ts +28 -0
  19. package/src/app/lemonriver/board/blocks/change-list.tsx +189 -0
  20. package/src/app/lemonriver/board/blocks/classify.test.ts +209 -0
  21. package/src/app/lemonriver/board/blocks/classify.ts +152 -0
  22. package/src/app/lemonriver/board/blocks/snapshot.ts +116 -0
  23. package/src/app/lemonriver/board/board-canvas.tsx +627 -104
  24. package/src/app/lemonriver/board/board-page.tsx +1702 -91
  25. package/src/app/lemonriver/board/board.css +58 -7
  26. package/src/app/lemonriver/board/layout.test.ts +84 -0
  27. package/src/app/lemonriver/board/layout.ts +112 -11
  28. package/src/app/lemonriver/board/model/agent-tasks.test.ts +200 -0
  29. package/src/app/lemonriver/board/model/agent-tasks.ts +223 -0
  30. package/src/app/lemonriver/board/model/apply-prompt.test.ts +121 -0
  31. package/src/app/lemonriver/board/model/apply-prompt.ts +115 -0
  32. package/src/app/lemonriver/board/model/apply.ts +71 -0
  33. package/src/app/lemonriver/board/model/cards.test.ts +95 -2
  34. package/src/app/lemonriver/board/model/cards.ts +88 -20
  35. package/src/app/lemonriver/board/model/changes.test.ts +244 -0
  36. package/src/app/lemonriver/board/model/changes.ts +268 -0
  37. package/src/app/lemonriver/board/model/filter.test.ts +50 -0
  38. package/src/app/lemonriver/board/model/filter.ts +42 -0
  39. package/src/app/lemonriver/board/model/history.test.ts +71 -0
  40. package/src/app/lemonriver/board/model/history.ts +51 -0
  41. package/src/app/lemonriver/board/model/restructure.test.ts +205 -0
  42. package/src/app/lemonriver/board/model/restructure.ts +169 -0
  43. package/src/app/lemonriver/board/model/self-check.test.ts +329 -0
  44. package/src/app/lemonriver/board/model/self-check.ts +489 -0
  45. package/src/app/lemonriver/board/model/structure.test.ts +249 -0
  46. package/src/app/lemonriver/board/model/structure.ts +209 -0
  47. package/src/app/lemonriver/board/model/timing.test.ts +113 -0
  48. package/src/app/lemonriver/board/model/timing.ts +117 -0
  49. package/src/app/lemonriver/board/page-node.tsx +258 -55
  50. package/src/app/lemonriver/board/self-check-jump.ts +23 -0
  51. package/src/app/lemonriver/board/self-check-panel.tsx +272 -0
  52. package/src/app/lemonriver/board/self-check-runner.tsx +150 -0
  53. package/src/app/lemonriver/board/status-style.ts +25 -0
  54. package/src/app/lemonriver/board/use-board-apply.ts +206 -0
  55. package/src/app/lemonriver/board/use-board-cards.ts +108 -5
  56. package/src/app/lemonriver/board/use-board-changes.ts +108 -0
  57. package/src/app/lemonriver/board/use-board-columns.ts +37 -56
  58. package/src/app/lemonriver/board/use-board-comments.ts +36 -0
  59. package/src/app/lemonriver/board/use-board-restructures.ts +107 -0
  60. package/src/app/lemonriver/board/use-history.ts +86 -0
  61. package/src/app/lemonriver/board/use-page-order.ts +65 -38
  62. package/src/app/lemonriver/board/use-self-check.ts +117 -0
  63. package/src/app/lemonriver/board/use-target-minutes.ts +47 -0
  64. package/src/app/lemonriver/board/views/block-readings.tsx +46 -0
  65. package/src/app/lemonriver/board/views/list-view.tsx +356 -0
  66. package/src/app/lemonriver/board/views/progress.tsx +32 -0
  67. package/src/app/lemonriver/board/views/timeline-view.tsx +341 -0
  68. package/src/app/lemonriver/chrome/filter-pill.tsx +30 -0
  69. package/src/app/lemonriver/chrome/sidebar-extras.tsx +12 -1
  70. package/src/app/lemonriver/features.test.ts +5 -0
  71. package/src/app/lemonriver/features.ts +2 -1
  72. package/src/app/lemonriver/home/deck-card.tsx +10 -0
  73. package/src/app/lemonriver/home/home-page.tsx +55 -6
  74. package/src/app/lemonriver/home/use-deck-times.ts +4 -1
  75. package/src/app/lemonriver/outline/build-team.tsx +42 -0
  76. package/src/app/lemonriver/outline/describe-page.tsx +128 -27
  77. package/src/app/lemonriver/outline/draft.ts +38 -0
  78. package/src/app/lemonriver/outline/model.test.ts +118 -0
  79. package/src/app/lemonriver/outline/model.ts +92 -7
  80. package/src/app/lemonriver/outline/outline-page.tsx +90 -7
  81. package/src/app/lemonriver/outline/pick-style.tsx +282 -0
  82. package/src/app/lemonriver/routes.test.tsx +17 -5
  83. package/src/app/lemonriver/routes.tsx +28 -0
  84. package/src/app/lemonriver/settings/settings-page.tsx +3 -0
  85. package/src/app/lemonriver/slide-extensions.tsx +14 -2
  86. package/src/app/lemonriver/templates/client.ts +60 -0
  87. package/src/app/lemonriver/templates/demo-page.tsx +79 -0
  88. package/src/app/lemonriver/templates/knobs.test.ts +62 -0
  89. package/src/app/lemonriver/templates/knobs.ts +62 -0
  90. package/src/app/lemonriver/templates/library-page.tsx +292 -0
  91. package/src/app/lemonriver/templates/model.test.ts +175 -0
  92. package/src/app/lemonriver/templates/model.ts +339 -0
  93. package/src/app/lemonriver/templates/preview-content.test.ts +117 -0
  94. package/src/app/lemonriver/templates/preview-content.ts +149 -0
  95. package/src/app/lemonriver/templates/recommend.test.ts +71 -0
  96. package/src/app/lemonriver/templates/recommend.ts +72 -0
  97. package/src/app/lemonriver/templates/use-library.ts +58 -0
  98. package/src/app/lemonriver/templates/virtual.d.ts +28 -0
  99. package/src/app/lemonriver/text/en.ts +228 -0
  100. package/src/app/lemonriver/text/es.ts +220 -0
  101. package/src/app/lemonriver/text/ja.ts +220 -0
  102. package/src/app/lemonriver/text/types.ts +243 -0
  103. package/src/app/lemonriver/text/zh-cn.ts +218 -0
  104. package/src/app/lemonriver/text/zh-tw.ts +218 -0
  105. package/src/app/lemonriver/theme/lemon-icon.tsx +6 -0
  106. package/src/app/lemonriver/theme/pages.test.ts +4 -0
  107. package/src/app/lemonriver/theme/pages.ts +6 -1
  108. package/src/app/lemonriver/theme/theme-menu.tsx +3 -2
  109. package/src/app/lemonriver/theme/use-theme.tsx +2 -2
  110. package/src/app/lemonriver/update/prompt.ts +1 -1
  111. package/src/app/lib/agent/use-agent.ts +4 -3
  112. package/src/app/routes/slide.tsx +1 -1
  113. package/src/app/assets/open-slide.svg +0 -39
  114. package/src/app/favicon.ico +0 -0
  115. package/src/app/favicon.svg +0 -39
@@ -0,0 +1,169 @@
1
+ import type { BlockKind } from '../blocks/classify.ts';
2
+
3
+ /** A block the user picked to move onto a page of its own. */
4
+ export type SplitBlock = { id: string; kind: BlockKind; text: string };
5
+
6
+ /**
7
+ * A page the board is about to break up or put together. Like a block move it
8
+ * is only written down here; the deck changes when the list is applied.
9
+ *
10
+ * A split keeps the words of its blocks beside their ids: the prompt that the
11
+ * server writes names them ("move the title …"), and only the browser can read
12
+ * them off the page.
13
+ */
14
+ export type Restructure =
15
+ | {
16
+ kind: 'split';
17
+ page: string;
18
+ blocks: string[];
19
+ /** One per entry of `blocks`, or absent on a record from an older board. */
20
+ blockInfo?: SplitBlock[];
21
+ }
22
+ | { kind: 'merge'; pages: [string, string] };
23
+
24
+ const MAX_RESTRUCTURES = 50;
25
+ const MAX_BLOCKS = 40;
26
+
27
+ const pagesOf = (entry: Restructure): string[] =>
28
+ entry.kind === 'split' ? [entry.page] : entry.pages;
29
+
30
+ /** Whether a page is already spoken for by a record of the other kind. */
31
+ function overlapsOtherKind(list: Restructure[], entry: Restructure): boolean {
32
+ const pages = new Set(pagesOf(entry));
33
+ return list.some(
34
+ (item) => item.kind !== entry.kind && pagesOf(item).some((page) => pages.has(page)),
35
+ );
36
+ }
37
+
38
+ /**
39
+ * The blocks of `page` that go onto a new page after it. Rows can be dragged
40
+ * around after the fact, so the same page split again replaces the last one.
41
+ */
42
+ export function addSplit(list: Restructure[], page: string, picked: SplitBlock[]): Restructure[] {
43
+ const seen = new Set<string>();
44
+ const kept = picked.filter((block) => block.id && !seen.has(block.id) && seen.add(block.id));
45
+ if (!page || kept.length === 0) return list;
46
+ const limited = kept.slice(0, MAX_BLOCKS);
47
+ const others = list.filter((item) => !pagesOf(item).includes(page));
48
+ return [
49
+ ...others,
50
+ {
51
+ kind: 'split',
52
+ page,
53
+ blocks: limited.map((block) => block.id),
54
+ blockInfo: limited.map((block) => ({ id: block.id, kind: block.kind, text: block.text })),
55
+ },
56
+ ];
57
+ }
58
+
59
+ /** Two pages becoming one, at the place of the earlier of them. */
60
+ export function addMerge(list: Restructure[], a: string, b: string): Restructure[] {
61
+ if (!a || !b || a === b) return list;
62
+ const pages = new Set([a, b]);
63
+ const others = list.filter((item) => !pagesOf(item).some((page) => pages.has(page)));
64
+ return [...others, { kind: 'merge', pages: [a, b] }];
65
+ }
66
+
67
+ export function removeRestructure(list: Restructure[], index: number): Restructure[] {
68
+ return list.filter((_, at) => at !== index);
69
+ }
70
+
71
+ /** True when recording `entry` would take the place of what is already there. */
72
+ export function restructureReplaced(list: Restructure[], entry: Restructure): boolean {
73
+ return overlapsOtherKind(list, entry);
74
+ }
75
+
76
+ /** Every page a split or a merge touches, for the card's own count. */
77
+ export function restructuredPages(list: Restructure[]): Set<string> {
78
+ const pages = new Set<string>();
79
+ for (const entry of list) for (const page of pagesOf(entry)) pages.add(page);
80
+ return pages;
81
+ }
82
+
83
+ /**
84
+ * Follows a page operation the board made: keys are renamed the way cards are,
85
+ * and a split or merge whose page is gone is dropped.
86
+ */
87
+ export function carryRestructures(
88
+ list: Restructure[],
89
+ before: string[],
90
+ after: string[],
91
+ origin: number[],
92
+ ): Restructure[] {
93
+ const rename = new Map<string, string>();
94
+ const created = new Set<string>();
95
+ origin.forEach((from, i) => {
96
+ if (from >= 0 && from < before.length) rename.set(before[from], after[i]);
97
+ else created.add(after[i]);
98
+ });
99
+ const live = new Set(before);
100
+ const resolve = (key: string): string | null => {
101
+ const next = live.has(key) ? (rename.get(key) ?? null) : key;
102
+ return next !== null && !created.has(next) ? next : null;
103
+ };
104
+
105
+ const kept: Restructure[] = [];
106
+ for (const entry of list) {
107
+ if (entry.kind === 'split') {
108
+ const page = resolve(entry.page);
109
+ if (page !== null) kept.push({ ...entry, page });
110
+ continue;
111
+ }
112
+ const [first, second] = entry.pages;
113
+ const a = resolve(first);
114
+ const b = resolve(second);
115
+ if (a !== null && b !== null) kept.push({ kind: 'merge', pages: [a, b] });
116
+ }
117
+ return kept;
118
+ }
119
+
120
+ const KINDS = new Set<BlockKind>(['title', 'point', 'text', 'image', 'chart', 'quote', 'number']);
121
+
122
+ function cleanSplit(raw: Record<string, unknown>): Restructure | null {
123
+ if (typeof raw.page !== 'string' || !raw.page) return null;
124
+ if (!Array.isArray(raw.blocks)) return null;
125
+ const source = Array.isArray(raw.blockInfo) ? raw.blockInfo : [];
126
+ const seen = new Set<string>();
127
+ const blocks: string[] = [];
128
+ const blockInfo: SplitBlock[] = [];
129
+ for (const [at, block] of raw.blocks.entries()) {
130
+ if (blocks.length >= MAX_BLOCKS) break;
131
+ if (typeof block !== 'string' || !block || seen.has(block)) continue;
132
+ seen.add(block);
133
+ blocks.push(block);
134
+ const info = (source[at] ?? null) as Record<string, unknown> | null;
135
+ const kind = info && typeof info.kind === 'string' ? (info.kind as BlockKind) : null;
136
+ const text = info && typeof info.text === 'string' ? info.text : '';
137
+ blockInfo.push({
138
+ id: block,
139
+ kind: kind && KINDS.has(kind) ? kind : 'text',
140
+ text: text.slice(0, 80),
141
+ });
142
+ }
143
+ if (blocks.length === 0) return null;
144
+ return { kind: 'split', page: raw.page, blocks, blockInfo };
145
+ }
146
+
147
+ function cleanEntry(raw: unknown): Restructure | null {
148
+ if (!raw || typeof raw !== 'object') return null;
149
+ const item = raw as Record<string, unknown>;
150
+ if (item.kind === 'split') return cleanSplit(item);
151
+ if (item.kind === 'merge') {
152
+ if (!Array.isArray(item.pages) || item.pages.length !== 2) return null;
153
+ const [a, b] = item.pages;
154
+ if (typeof a !== 'string' || typeof b !== 'string' || !a || !b || a === b) return null;
155
+ return { kind: 'merge', pages: [a, b] };
156
+ }
157
+ return null;
158
+ }
159
+
160
+ export function sanitizeRestructures(raw: unknown): Restructure[] {
161
+ if (!Array.isArray(raw)) return [];
162
+ const list: Restructure[] = [];
163
+ for (const value of raw) {
164
+ if (list.length >= MAX_RESTRUCTURES) break;
165
+ const entry = cleanEntry(value);
166
+ if (entry) list.push(entry);
167
+ }
168
+ return list;
169
+ }
@@ -0,0 +1,329 @@
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
+ });