@lemonriver/core 0.5.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.
- package/dist/{build-CS1goZxt.js → build-RlcGG-Ve.js} +1 -1
- package/dist/cli/bin.js +3 -3
- package/dist/{config-BpbcCbUv.js → config-BJT87wE9.js} +1155 -19
- package/dist/{dev-BpYnfgLL.js → dev-DR-j_xda.js} +1 -1
- package/dist/{preview-HSzPPkSs.js → preview-BTAhTb5B.js} +1 -1
- package/dist/vite/index.js +1 -1
- package/package.json +1 -1
- package/src/app/lemonriver/board/blocks/classify.test.ts +5 -0
- package/src/app/lemonriver/board/blocks/classify.ts +29 -2
- package/src/app/lemonriver/board/blocks/snapshot.ts +34 -4
- package/src/app/lemonriver/board/board-page.tsx +15 -0
- package/src/app/lemonriver/board/model/agent-tasks.ts +33 -1
- package/src/app/lemonriver/board/model/self-check.test.ts +329 -0
- package/src/app/lemonriver/board/model/self-check.ts +489 -0
- package/src/app/lemonriver/board/page-node.tsx +23 -1
- package/src/app/lemonriver/board/self-check-jump.ts +23 -0
- package/src/app/lemonriver/board/self-check-panel.tsx +272 -0
- package/src/app/lemonriver/board/self-check-runner.tsx +150 -0
- package/src/app/lemonriver/board/use-self-check.ts +117 -0
- package/src/app/lemonriver/chrome/filter-pill.tsx +30 -0
- package/src/app/lemonriver/chrome/sidebar-extras.tsx +12 -1
- package/src/app/lemonriver/features.test.ts +5 -0
- package/src/app/lemonriver/features.ts +2 -1
- package/src/app/lemonriver/home/deck-card.tsx +10 -0
- package/src/app/lemonriver/home/home-page.tsx +55 -6
- package/src/app/lemonriver/home/use-deck-times.ts +4 -1
- package/src/app/lemonriver/outline/build-team.tsx +42 -0
- package/src/app/lemonriver/outline/describe-page.tsx +128 -27
- package/src/app/lemonriver/outline/draft.ts +38 -0
- package/src/app/lemonriver/outline/model.test.ts +79 -0
- package/src/app/lemonriver/outline/model.ts +80 -7
- package/src/app/lemonriver/outline/outline-page.tsx +56 -6
- package/src/app/lemonriver/outline/pick-style.tsx +282 -0
- package/src/app/lemonriver/routes.test.tsx +17 -5
- package/src/app/lemonriver/routes.tsx +28 -0
- package/src/app/lemonriver/templates/client.ts +60 -0
- package/src/app/lemonriver/templates/demo-page.tsx +79 -0
- package/src/app/lemonriver/templates/knobs.test.ts +62 -0
- package/src/app/lemonriver/templates/knobs.ts +62 -0
- package/src/app/lemonriver/templates/library-page.tsx +292 -0
- package/src/app/lemonriver/templates/model.test.ts +175 -0
- package/src/app/lemonriver/templates/model.ts +339 -0
- package/src/app/lemonriver/templates/preview-content.test.ts +117 -0
- package/src/app/lemonriver/templates/preview-content.ts +149 -0
- package/src/app/lemonriver/templates/recommend.test.ts +71 -0
- package/src/app/lemonriver/templates/recommend.ts +72 -0
- package/src/app/lemonriver/templates/use-library.ts +58 -0
- package/src/app/lemonriver/templates/virtual.d.ts +28 -0
- package/src/app/lemonriver/text/en.ts +57 -0
- package/src/app/lemonriver/text/es.ts +57 -0
- package/src/app/lemonriver/text/ja.ts +57 -0
- package/src/app/lemonriver/text/types.ts +73 -0
- package/src/app/lemonriver/text/zh-cn.ts +57 -0
- package/src/app/lemonriver/text/zh-tw.ts +57 -0
- package/src/app/lemonriver/theme/pages.test.ts +4 -0
- package/src/app/lemonriver/theme/pages.ts +6 -1
- package/src/app/lemonriver/update/prompt.ts +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { V as PKG_NAMES } from "./update-CMRxtTc9.js";
|
|
2
2
|
import { a as printUrls, i as printShortcutsHint, n as formatError, o as shortcutsEnabled, r as printHeader, s as startupDuration, t as createCliLogger } from "./cli/bin.js";
|
|
3
|
-
import { n as DEV_SUPERVISED_ENV, t as createViteConfig } from "./config-
|
|
3
|
+
import { n as DEV_SUPERVISED_ENV, t as createViteConfig } from "./config-BJT87wE9.js";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { existsSync } from "node:fs";
|
|
6
6
|
import { fork } from "node:child_process";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as printUrls, i as printShortcutsHint, o as shortcutsEnabled, r as printHeader, s as startupDuration, t as createCliLogger } from "./cli/bin.js";
|
|
2
|
-
import { t as createViteConfig } from "./config-
|
|
2
|
+
import { t as createViteConfig } from "./config-BJT87wE9.js";
|
|
3
3
|
import { mergeConfig, preview as preview$1 } from "vite";
|
|
4
4
|
//#region src/cli/preview.ts
|
|
5
5
|
async function preview(opts = {}) {
|
package/dist/vite/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as createViteConfig } from "../config-
|
|
1
|
+
import { t as createViteConfig } from "../config-BJT87wE9.js";
|
|
2
2
|
export { createViteConfig };
|
package/package.json
CHANGED
|
@@ -10,8 +10,13 @@ function node(tag: string, extra: Partial<SnapNode> = {}, children: SnapNode[] =
|
|
|
10
10
|
text: '',
|
|
11
11
|
fullText: extra.fullText ?? extra.text ?? '',
|
|
12
12
|
fontSize: 32,
|
|
13
|
+
lineHeight: 40,
|
|
13
14
|
fontWeight: 400,
|
|
15
|
+
color: '',
|
|
16
|
+
background: '',
|
|
14
17
|
box: { x: 0, y: counter * 10, w: 300, h: 40 },
|
|
18
|
+
clip: null,
|
|
19
|
+
lines: [],
|
|
15
20
|
loc: null,
|
|
16
21
|
placeholder: false,
|
|
17
22
|
step: false,
|
|
@@ -7,8 +7,17 @@ export type SnapNode = {
|
|
|
7
7
|
/** Everything it shows, in document order; a `<br>` becomes a space. */
|
|
8
8
|
fullText: string;
|
|
9
9
|
fontSize: number;
|
|
10
|
+
/** The used line height in px, or 0 when the browser reports none. */
|
|
11
|
+
lineHeight: number;
|
|
10
12
|
fontWeight: number;
|
|
13
|
+
/** Computed colour and background as `#rrggbb`, or '' when it has no hex. */
|
|
14
|
+
color: string;
|
|
15
|
+
background: string;
|
|
11
16
|
box: SnapBox;
|
|
17
|
+
/** What a clipping ancestor leaves of this element, or null when nothing clips it. */
|
|
18
|
+
clip: SnapBox | null;
|
|
19
|
+
/** Where the words actually fall, one box per line; empty when it shows none. */
|
|
20
|
+
lines: SnapBox[];
|
|
12
21
|
loc: string | null;
|
|
13
22
|
placeholder: boolean;
|
|
14
23
|
step: boolean;
|
|
@@ -16,6 +25,17 @@ export type SnapNode = {
|
|
|
16
25
|
};
|
|
17
26
|
|
|
18
27
|
export type BlockKind = 'title' | 'point' | 'text' | 'image' | 'chart' | 'quote' | 'number';
|
|
28
|
+
|
|
29
|
+
/** The part of a box a clipping ancestor leaves on screen, or null when none of it shows. */
|
|
30
|
+
export function visibleBox(box: SnapBox, clip: SnapBox | null): SnapBox | null {
|
|
31
|
+
if (!clip) return box;
|
|
32
|
+
const x = Math.max(box.x, clip.x);
|
|
33
|
+
const y = Math.max(box.y, clip.y);
|
|
34
|
+
const right = Math.min(box.x + box.w, clip.x + clip.w);
|
|
35
|
+
const bottom = Math.min(box.y + box.h, clip.y + clip.h);
|
|
36
|
+
if (right <= x || bottom <= y) return null;
|
|
37
|
+
return { x, y, w: right - x, h: bottom - y };
|
|
38
|
+
}
|
|
19
39
|
export type Block = {
|
|
20
40
|
id: string;
|
|
21
41
|
kind: BlockKind;
|
|
@@ -44,7 +64,7 @@ function clip(text: string): string {
|
|
|
44
64
|
|
|
45
65
|
const NUMBER_RE = /^[+\-−]?[$€£¥]?\d[\d.,]*\s?(M|K|B|万|亿|[xX])?$/;
|
|
46
66
|
|
|
47
|
-
function
|
|
67
|
+
export function nodeKind(node: SnapNode): BlockKind | null {
|
|
48
68
|
const tag = node.tag.toLowerCase();
|
|
49
69
|
if (tag === 'img' || node.placeholder) return 'image';
|
|
50
70
|
if ((tag === 'svg' || tag === 'canvas') && node.box.w >= 200 && node.box.h >= 120) return 'chart';
|
|
@@ -59,6 +79,13 @@ function ownKind(node: SnapNode): BlockKind | null {
|
|
|
59
79
|
return null;
|
|
60
80
|
}
|
|
61
81
|
|
|
82
|
+
/** The kind the reader files this node under, plain paragraphs included. */
|
|
83
|
+
export function blockKindOf(node: SnapNode): BlockKind | null {
|
|
84
|
+
const kind = nodeKind(node);
|
|
85
|
+
if (kind) return kind;
|
|
86
|
+
return squash(node.text) ? 'text' : null;
|
|
87
|
+
}
|
|
88
|
+
|
|
62
89
|
function hasStep(node: SnapNode): boolean {
|
|
63
90
|
return node.step || node.children.some(hasStep);
|
|
64
91
|
}
|
|
@@ -66,7 +93,7 @@ function hasStep(node: SnapNode): boolean {
|
|
|
66
93
|
type Collected = { kind: BlockKind; text: string; loc: string | null; box: SnapBox };
|
|
67
94
|
|
|
68
95
|
function collect(node: SnapNode, out: Collected[]): void {
|
|
69
|
-
const kind =
|
|
96
|
+
const kind = nodeKind(node);
|
|
70
97
|
if (kind) {
|
|
71
98
|
// Small type travels with its page: nobody moves a page number or an axis
|
|
72
99
|
// label on its own, and a dense page would otherwise read as forty blocks.
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { toHex } from '../model/self-check.ts';
|
|
2
|
+
import { type SnapBox, type SnapNode, visibleBox } from './classify.ts';
|
|
2
3
|
|
|
3
4
|
const MAX_ELEMENTS = 2000;
|
|
5
|
+
const CLIPPING = /^(hidden|clip|scroll|auto)$/;
|
|
6
|
+
|
|
7
|
+
/** An ancestor that clips everything away; its descendants stay in the tree but show nothing. */
|
|
8
|
+
const CLIPPED_AWAY: SnapBox = { x: 0, y: 0, w: 0, h: 0 };
|
|
4
9
|
|
|
5
10
|
function directText(el: Element): string {
|
|
6
11
|
let text = '';
|
|
@@ -42,7 +47,7 @@ export function snapshotPage(canvas: HTMLElement, scale: number): SnapNode | nul
|
|
|
42
47
|
const origin = canvas.getBoundingClientRect();
|
|
43
48
|
let count = 0;
|
|
44
49
|
|
|
45
|
-
const visit = (el: Element): SnapNode | { tooLarge: true } | null => {
|
|
50
|
+
const visit = (el: Element, clip: SnapBox | null): SnapNode | { tooLarge: true } | null => {
|
|
46
51
|
count += 1;
|
|
47
52
|
if (count > MAX_ELEMENTS) return { tooLarge: true };
|
|
48
53
|
|
|
@@ -59,9 +64,29 @@ export function snapshotPage(canvas: HTMLElement, scale: number): SnapNode | nul
|
|
|
59
64
|
h: rect.height / scale,
|
|
60
65
|
};
|
|
61
66
|
|
|
67
|
+
const clips =
|
|
68
|
+
CLIPPING.test(style.overflowX) || CLIPPING.test(style.overflowY)
|
|
69
|
+
? (visibleBox(box, clip) ?? CLIPPED_AWAY)
|
|
70
|
+
: clip;
|
|
71
|
+
|
|
72
|
+
const lines: SnapBox[] = [];
|
|
73
|
+
if (directText(el) !== '') {
|
|
74
|
+
const range = document.createRange();
|
|
75
|
+
range.selectNodeContents(el);
|
|
76
|
+
for (const rect of Array.from(range.getClientRects())) {
|
|
77
|
+
if (rect.width === 0 || rect.height === 0) continue;
|
|
78
|
+
lines.push({
|
|
79
|
+
x: (rect.left - origin.left) / scale,
|
|
80
|
+
y: (rect.top - origin.top) / scale,
|
|
81
|
+
w: rect.width / scale,
|
|
82
|
+
h: rect.height / scale,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
62
87
|
const children: SnapNode[] = [];
|
|
63
88
|
for (const child of el.children) {
|
|
64
|
-
const copied = visit(child);
|
|
89
|
+
const copied = visit(child, clips);
|
|
65
90
|
if (copied && 'tooLarge' in copied) return copied;
|
|
66
91
|
if (copied) children.push(copied);
|
|
67
92
|
}
|
|
@@ -71,8 +96,13 @@ export function snapshotPage(canvas: HTMLElement, scale: number): SnapNode | nul
|
|
|
71
96
|
text: directText(el),
|
|
72
97
|
fullText: allText(el),
|
|
73
98
|
fontSize: Number.parseFloat(style.fontSize) || 0,
|
|
99
|
+
lineHeight: Number.parseFloat(style.lineHeight) || 0,
|
|
74
100
|
fontWeight: Number.parseInt(style.fontWeight, 10) || 400,
|
|
101
|
+
color: toHex(style.color),
|
|
102
|
+
background: toHex(style.backgroundColor),
|
|
75
103
|
box,
|
|
104
|
+
clip,
|
|
105
|
+
lines,
|
|
76
106
|
loc: el.getAttribute('data-slide-loc'),
|
|
77
107
|
placeholder: el.hasAttribute('data-slide-placeholder'),
|
|
78
108
|
step: el.hasAttribute('data-osd-step'),
|
|
@@ -80,7 +110,7 @@ export function snapshotPage(canvas: HTMLElement, scale: number): SnapNode | nul
|
|
|
80
110
|
};
|
|
81
111
|
};
|
|
82
112
|
|
|
83
|
-
const root = visit(canvas);
|
|
113
|
+
const root = visit(canvas, null);
|
|
84
114
|
if (!root || 'tooLarge' in root) return null;
|
|
85
115
|
return root;
|
|
86
116
|
}
|
|
@@ -107,6 +107,8 @@ import {
|
|
|
107
107
|
renameColumnAt,
|
|
108
108
|
} from './model/structure';
|
|
109
109
|
import { useStatusLabels } from './page-node';
|
|
110
|
+
import { publishFindings, SelfCheckButton } from './self-check-panel';
|
|
111
|
+
import { SelfCheckRunner } from './self-check-runner';
|
|
110
112
|
import { useBoardApply } from './use-board-apply';
|
|
111
113
|
import { countAfter, useBoardCards } from './use-board-cards';
|
|
112
114
|
import { useBoardChanges } from './use-board-changes';
|
|
@@ -115,6 +117,7 @@ import { useBoardComments } from './use-board-comments';
|
|
|
115
117
|
import { useBoardRestructures } from './use-board-restructures';
|
|
116
118
|
import { useHistory } from './use-history';
|
|
117
119
|
import { usePageOrder } from './use-page-order';
|
|
120
|
+
import { useSelfCheck } from './use-self-check';
|
|
118
121
|
import { useTargetMinutes } from './use-target-minutes';
|
|
119
122
|
import { BlockReadings } from './views/block-readings';
|
|
120
123
|
import { ListView } from './views/list-view';
|
|
@@ -259,6 +262,11 @@ export function Board() {
|
|
|
259
262
|
const labels = useStatusLabels();
|
|
260
263
|
useDocumentTitle(slide?.meta?.title);
|
|
261
264
|
|
|
265
|
+
const selfCheck = useSelfCheck(slideId);
|
|
266
|
+
useEffect(() => {
|
|
267
|
+
publishFindings(slideId, selfCheck.record?.findings ?? [], selfCheck.record?.unread ?? []);
|
|
268
|
+
}, [selfCheck.record, slideId]);
|
|
269
|
+
|
|
262
270
|
const modulePages = slide?.default ?? NO_PAGES;
|
|
263
271
|
const { pages, reorderAll, duplicate, insert, restore, remove } = usePageOrder(
|
|
264
272
|
slideId,
|
|
@@ -1173,6 +1181,11 @@ export function Board() {
|
|
|
1173
1181
|
<Redo2 />
|
|
1174
1182
|
</Button>
|
|
1175
1183
|
<span className="mx-1 h-5 w-px bg-hairline" aria-hidden />
|
|
1184
|
+
<SelfCheckButton
|
|
1185
|
+
record={selfCheck.record}
|
|
1186
|
+
running={selfCheck.running}
|
|
1187
|
+
onRun={() => void selfCheck.run()}
|
|
1188
|
+
/>
|
|
1176
1189
|
<Button
|
|
1177
1190
|
variant="ghost"
|
|
1178
1191
|
size="icon-sm"
|
|
@@ -1369,6 +1382,8 @@ export function Board() {
|
|
|
1369
1382
|
<span className="folio">{pad2(pages.length)}</span>
|
|
1370
1383
|
</header>
|
|
1371
1384
|
|
|
1385
|
+
{selfCheck.runner && <SelfCheckRunner {...selfCheck.runner} />}
|
|
1386
|
+
|
|
1372
1387
|
<div className="flex min-h-0 flex-1">
|
|
1373
1388
|
<div className="relative min-h-0 min-w-0 flex-1">
|
|
1374
1389
|
{error ? (
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type OutlinePage, sanitizeItems } from '../../outline/model.ts';
|
|
2
|
+
import { type Finding, sanitizeFindings } from './self-check.ts';
|
|
2
3
|
|
|
3
4
|
export const PAGE_ACTIONS = ['rewrite', 'chart', 'memo', 'expand'] as const;
|
|
4
5
|
export type PageAction = (typeof PAGE_ACTIONS)[number];
|
|
@@ -6,13 +7,15 @@ export type PageAction = (typeof PAGE_ACTIONS)[number];
|
|
|
6
7
|
export const MAX_PLAN_ITEMS = 8;
|
|
7
8
|
export const MAX_CHAPTER_BRIEF = 500;
|
|
8
9
|
export const MAX_CHAPTER_TITLE = 120;
|
|
10
|
+
export const MAX_FINDINGS = 40;
|
|
9
11
|
|
|
10
12
|
/** One thing the board asks the agent to do. `changes` is the hand-over list. */
|
|
11
13
|
export type BoardTask =
|
|
12
14
|
| { kind: 'changes' }
|
|
13
15
|
| { kind: 'page'; page: string; action: PageAction }
|
|
14
16
|
| { kind: 'chapter-plan'; chapter: number; title: string; brief: string; count: number }
|
|
15
|
-
| { kind: 'chapter-write'; chapter: number; title: string }
|
|
17
|
+
| { kind: 'chapter-write'; chapter: number; title: string }
|
|
18
|
+
| { kind: 'self-check'; findings: Finding[] };
|
|
16
19
|
|
|
17
20
|
export function isPageAction(value: unknown): value is PageAction {
|
|
18
21
|
return typeof value === 'string' && (PAGE_ACTIONS as readonly string[]).includes(value);
|
|
@@ -57,6 +60,10 @@ export function sanitizeTask(raw: unknown): BoardTask | null {
|
|
|
57
60
|
title: typeof task.title === 'string' ? task.title.slice(0, MAX_CHAPTER_TITLE) : '',
|
|
58
61
|
};
|
|
59
62
|
}
|
|
63
|
+
case 'self-check': {
|
|
64
|
+
const findings = sanitizeFindings(task.findings).slice(0, MAX_FINDINGS);
|
|
65
|
+
return findings.length > 0 ? { kind: 'self-check', findings } : null;
|
|
66
|
+
}
|
|
60
67
|
default:
|
|
61
68
|
return null;
|
|
62
69
|
}
|
|
@@ -75,6 +82,31 @@ const ACTION_LINE: Record<Exclude<PageAction, 'memo'>, string> = {
|
|
|
75
82
|
'Expand this page into two pages: keep this one, and add one more right after it that goes deeper. Add a speaker note for the new page.',
|
|
76
83
|
};
|
|
77
84
|
|
|
85
|
+
/** The problems a finished deck's self-check found, one line each. */
|
|
86
|
+
export function selfCheckPrompt({
|
|
87
|
+
slideId,
|
|
88
|
+
findings,
|
|
89
|
+
lang,
|
|
90
|
+
}: {
|
|
91
|
+
slideId: string;
|
|
92
|
+
findings: readonly Finding[];
|
|
93
|
+
lang: string;
|
|
94
|
+
}): string {
|
|
95
|
+
const lines = findings.map((finding) => {
|
|
96
|
+
const box = finding.boxes[0];
|
|
97
|
+
const at = box ? ` at (${Math.round(box.x)}, ${Math.round(box.y)})` : '';
|
|
98
|
+
const times = finding.count > 1 ? ` (${finding.count} places)` : '';
|
|
99
|
+
return `- page ${finding.page}: ${finding.detail}${times}${at}`;
|
|
100
|
+
});
|
|
101
|
+
return [
|
|
102
|
+
`A finished deck at slides/${slideId}/index.tsx was checked automatically and these problems were found:`,
|
|
103
|
+
...lines,
|
|
104
|
+
'Fix only what is listed above, and only on those pages. Change nothing else, and do not add or remove pages.',
|
|
105
|
+
LANGUAGE(lang),
|
|
106
|
+
DONE,
|
|
107
|
+
].join('\n');
|
|
108
|
+
}
|
|
109
|
+
|
|
78
110
|
/** The message for one page. A note action without a note has nothing to say. */
|
|
79
111
|
export function pageTaskPrompt({
|
|
80
112
|
slideId,
|
|
@@ -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
|
+
});
|