@lemonriver/core 0.3.0 → 0.5.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 (146) hide show
  1. package/README.md +14 -4
  2. package/dist/{build-Bqo69DWP.js → build-CS1goZxt.js} +1 -1
  3. package/dist/cli/bin.js +4 -4
  4. package/dist/{config-DJ5rkMMg.js → config-BpbcCbUv.js} +3835 -1532
  5. package/dist/{config-teo3kWz7.d.ts → config-CYNOR93W.d.ts} +1 -1
  6. package/dist/{dev-B2FJD5bJ.js → dev-BpYnfgLL.js} +2 -2
  7. package/dist/index.d.ts +2 -2
  8. package/dist/index.js +1 -1
  9. package/dist/locale/index.d.ts +1 -1
  10. package/dist/locale/index.js +1 -1
  11. package/dist/{preview-C93BOZL1.js → preview-HSzPPkSs.js} +1 -1
  12. package/dist/{types-DFK02XVv.d.ts → types-tdaXSyah.d.ts} +1 -0
  13. package/dist/{update-DsxZBtwv.js → update-CMRxtTc9.js} +18 -8
  14. package/dist/vite/index.d.ts +1 -1
  15. package/dist/vite/index.js +1 -1
  16. package/dist/{zh-tw-DwTAZKa6.js → zh-tw-DcrDeKxr.js} +5 -0
  17. package/package.json +2 -2
  18. package/src/agent/prompt.ts +2 -0
  19. package/src/agent/types.ts +14 -2
  20. package/src/app/components/agent/agent-panel.tsx +19 -5
  21. package/src/app/components/agent/connect-view.tsx +1 -1
  22. package/src/app/components/agent/provider-logo.tsx +10 -1
  23. package/src/app/components/player.tsx +105 -23
  24. package/src/app/components/present/curtain.tsx +52 -0
  25. package/src/app/components/present/last-slide-hint.tsx +36 -0
  26. package/src/app/components/sidebar/sidebar-footer.tsx +6 -1
  27. package/src/app/components/thumbnail-rail.tsx +1 -0
  28. package/src/app/lemonriver/agent/lemon.tsx +16 -1
  29. package/src/app/lemonriver/agent/provider-marks.tsx +53 -0
  30. package/src/app/lemonriver/agent-prefs/prefs.test.ts +173 -0
  31. package/src/app/lemonriver/agent-prefs/prefs.ts +137 -0
  32. package/src/app/lemonriver/agent-prefs/use-prefs.ts +36 -0
  33. package/src/app/lemonriver/agent-providers/section.tsx +75 -0
  34. package/src/app/lemonriver/agent-providers/use-providers.ts +61 -0
  35. package/src/app/lemonriver/board/blocks/block-panel.tsx +666 -0
  36. package/src/app/lemonriver/board/blocks/cache.ts +28 -0
  37. package/src/app/lemonriver/board/blocks/change-list.tsx +189 -0
  38. package/src/app/lemonriver/board/blocks/classify.test.ts +204 -0
  39. package/src/app/lemonriver/board/blocks/classify.ts +125 -0
  40. package/src/app/lemonriver/board/blocks/snapshot.ts +86 -0
  41. package/src/app/lemonriver/board/board-canvas.tsx +627 -104
  42. package/src/app/lemonriver/board/board-page.tsx +1687 -91
  43. package/src/app/lemonriver/board/board.css +58 -7
  44. package/src/app/lemonriver/board/layout.test.ts +84 -0
  45. package/src/app/lemonriver/board/layout.ts +112 -11
  46. package/src/app/lemonriver/board/model/agent-tasks.test.ts +200 -0
  47. package/src/app/lemonriver/board/model/agent-tasks.ts +191 -0
  48. package/src/app/lemonriver/board/model/apply-prompt.test.ts +121 -0
  49. package/src/app/lemonriver/board/model/apply-prompt.ts +115 -0
  50. package/src/app/lemonriver/board/model/apply.ts +71 -0
  51. package/src/app/lemonriver/board/model/cards.test.ts +95 -2
  52. package/src/app/lemonriver/board/model/cards.ts +88 -20
  53. package/src/app/lemonriver/board/model/changes.test.ts +244 -0
  54. package/src/app/lemonriver/board/model/changes.ts +268 -0
  55. package/src/app/lemonriver/board/model/filter.test.ts +50 -0
  56. package/src/app/lemonriver/board/model/filter.ts +42 -0
  57. package/src/app/lemonriver/board/model/history.test.ts +71 -0
  58. package/src/app/lemonriver/board/model/history.ts +51 -0
  59. package/src/app/lemonriver/board/model/restructure.test.ts +205 -0
  60. package/src/app/lemonriver/board/model/restructure.ts +169 -0
  61. package/src/app/lemonriver/board/model/structure.test.ts +249 -0
  62. package/src/app/lemonriver/board/model/structure.ts +209 -0
  63. package/src/app/lemonriver/board/model/timing.test.ts +113 -0
  64. package/src/app/lemonriver/board/model/timing.ts +117 -0
  65. package/src/app/lemonriver/board/page-node.tsx +236 -55
  66. package/src/app/lemonriver/board/status-style.ts +25 -0
  67. package/src/app/lemonriver/board/use-board-apply.ts +206 -0
  68. package/src/app/lemonriver/board/use-board-cards.ts +108 -5
  69. package/src/app/lemonriver/board/use-board-changes.ts +108 -0
  70. package/src/app/lemonriver/board/use-board-columns.ts +37 -56
  71. package/src/app/lemonriver/board/use-board-comments.ts +36 -0
  72. package/src/app/lemonriver/board/use-board-restructures.ts +107 -0
  73. package/src/app/lemonriver/board/use-history.ts +86 -0
  74. package/src/app/lemonriver/board/use-page-order.ts +65 -38
  75. package/src/app/lemonriver/board/use-target-minutes.ts +47 -0
  76. package/src/app/lemonriver/board/views/block-readings.tsx +46 -0
  77. package/src/app/lemonriver/board/views/list-view.tsx +356 -0
  78. package/src/app/lemonriver/board/views/progress.tsx +32 -0
  79. package/src/app/lemonriver/board/views/timeline-view.tsx +341 -0
  80. package/src/app/lemonriver/brand/mascot.tsx +86 -0
  81. package/src/app/lemonriver/brand/mascots/design-done.png +0 -0
  82. package/src/app/lemonriver/brand/mascots/design-idle.png +0 -0
  83. package/src/app/lemonriver/brand/mascots/design-needs-you.png +0 -0
  84. package/src/app/lemonriver/brand/mascots/design-working.png +0 -0
  85. package/src/app/lemonriver/brand/mascots/outline-done.png +0 -0
  86. package/src/app/lemonriver/brand/mascots/outline-idle.png +0 -0
  87. package/src/app/lemonriver/brand/mascots/outline-needs-you.png +0 -0
  88. package/src/app/lemonriver/brand/mascots/outline-working.png +0 -0
  89. package/src/app/lemonriver/brand/mascots/research-done.png +0 -0
  90. package/src/app/lemonriver/brand/mascots/research-idle.png +0 -0
  91. package/src/app/lemonriver/brand/mascots/research-needs-you.png +0 -0
  92. package/src/app/lemonriver/brand/mascots/research-working.png +0 -0
  93. package/src/app/lemonriver/brand/mascots/review-done.png +0 -0
  94. package/src/app/lemonriver/brand/mascots/review-idle.png +0 -0
  95. package/src/app/lemonriver/brand/mascots/review-needs-you.png +0 -0
  96. package/src/app/lemonriver/brand/mascots/review-working.png +0 -0
  97. package/src/app/lemonriver/chrome/app-chrome.tsx +2 -0
  98. package/src/app/lemonriver/features.test.ts +5 -0
  99. package/src/app/lemonriver/features.ts +2 -1
  100. package/src/app/lemonriver/home/brief-card.tsx +8 -1
  101. package/src/app/lemonriver/home/home-page.tsx +11 -7
  102. package/src/app/lemonriver/onboarding/onboarding.tsx +182 -0
  103. package/src/app/lemonriver/outline/build-team.tsx +278 -0
  104. package/src/app/lemonriver/outline/describe-page.tsx +380 -0
  105. package/src/app/lemonriver/outline/files.test.ts +90 -0
  106. package/src/app/lemonriver/outline/files.ts +69 -0
  107. package/src/app/lemonriver/outline/model.test.ts +672 -0
  108. package/src/app/lemonriver/outline/model.ts +455 -0
  109. package/src/app/lemonriver/outline/outline-page.tsx +537 -0
  110. package/src/app/lemonriver/outline/pending-pages.tsx +39 -0
  111. package/src/app/lemonriver/outline/rule.ts +3 -0
  112. package/src/app/lemonriver/outline/steps.tsx +43 -0
  113. package/src/app/lemonriver/outline/use-build-driver.ts +258 -0
  114. package/src/app/lemonriver/routes.test.tsx +6 -6
  115. package/src/app/lemonriver/routes.tsx +28 -0
  116. package/src/app/lemonriver/settings/settings-page.tsx +214 -0
  117. package/src/app/lemonriver/slide-extensions.tsx +45 -26
  118. package/src/app/lemonriver/text/en.ts +320 -0
  119. package/src/app/lemonriver/text/es.ts +311 -0
  120. package/src/app/lemonriver/text/ja.ts +313 -0
  121. package/src/app/lemonriver/text/text.test.ts +33 -0
  122. package/src/app/lemonriver/text/types.ts +339 -0
  123. package/src/app/lemonriver/text/zh-cn.ts +307 -0
  124. package/src/app/lemonriver/text/zh-tw.ts +307 -0
  125. package/src/app/lemonriver/theme/app.css +12 -1
  126. package/src/app/lemonriver/theme/lemon-icon.tsx +6 -0
  127. package/src/app/lemonriver/theme/pages.test.ts +4 -0
  128. package/src/app/lemonriver/theme/pages.ts +11 -2
  129. package/src/app/lemonriver/theme/theme-menu.tsx +3 -2
  130. package/src/app/lemonriver/theme/use-theme.tsx +2 -2
  131. package/src/app/lemonriver/update/beta-badge.tsx +26 -0
  132. package/src/app/lemonriver/update/prompt.test.ts +84 -0
  133. package/src/app/lemonriver/update/prompt.ts +48 -0
  134. package/src/app/lemonriver/update/update-prompt.tsx +113 -0
  135. package/src/app/lib/agent/use-agent.ts +4 -3
  136. package/src/app/routes/home.tsx +13 -5
  137. package/src/app/routes/slide.tsx +71 -14
  138. package/src/locale/en.ts +1 -0
  139. package/src/locale/es.ts +1 -0
  140. package/src/locale/ja.ts +1 -0
  141. package/src/locale/types.ts +1 -0
  142. package/src/locale/zh-cn.ts +1 -0
  143. package/src/locale/zh-tw.ts +1 -0
  144. package/src/app/assets/open-slide.svg +0 -39
  145. package/src/app/favicon.ico +0 -0
  146. package/src/app/favicon.svg +0 -39
@@ -0,0 +1,113 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import type { Block } from '../blocks/classify';
3
+ import {
4
+ estimateSeconds,
5
+ formatDuration,
6
+ sanitizeTargetMinutes,
7
+ speakingSeconds,
8
+ } from './timing.ts';
9
+
10
+ const block = (kind: Block['kind'], text = ''): Block => ({
11
+ id: `${kind}-${text}`,
12
+ kind,
13
+ text,
14
+ loc: null,
15
+ box: { x: 0, y: 0, w: 0, h: 0 },
16
+ });
17
+
18
+ /** A run of Chinese characters, one second per four of them. */
19
+ const han = (count: number) => '字'.repeat(count);
20
+ const words = (count: number) => Array.from({ length: count }, (_, i) => `word${i}`).join(' ');
21
+
22
+ describe('estimateSeconds', () => {
23
+ it('reads Chinese by the character: 240 a minute', () => {
24
+ expect(estimateSeconds({ blocks: null, notes: han(240) })).toEqual({
25
+ seconds: 60,
26
+ basis: 'notes',
27
+ });
28
+ });
29
+
30
+ it('reads English by the word: 150 a minute', () => {
31
+ expect(estimateSeconds({ blocks: null, notes: words(150) })).toEqual({
32
+ seconds: 60,
33
+ basis: 'notes',
34
+ });
35
+ });
36
+
37
+ it('adds up a page that mixes both', () => {
38
+ // Half a minute of Chinese plus half a minute of English.
39
+ expect(speakingSeconds(`${han(120)} ${words(75)}`)).toBeCloseTo(60, 5);
40
+ });
41
+
42
+ it('gives a page with only a chart the minimum', () => {
43
+ expect(estimateSeconds({ blocks: [block('chart')] })).toEqual({
44
+ seconds: 15,
45
+ basis: 'page',
46
+ });
47
+ });
48
+
49
+ it('prefers the speaker notes over the words on the page', () => {
50
+ const timing = estimateSeconds({ notes: han(240), blocks: [block('text', words(300))] });
51
+ expect(timing).toEqual({ seconds: 60, basis: 'notes' });
52
+ });
53
+
54
+ it('never goes under fifteen seconds', () => {
55
+ expect(estimateSeconds({ blocks: null, notes: 'Hi' }).seconds).toBe(15);
56
+ expect(estimateSeconds({ blocks: [block('text', han(4))] }).seconds).toBe(15);
57
+ });
58
+
59
+ it('rounds to five seconds', () => {
60
+ // 224 characters is 56 s, 232 is 58 s.
61
+ expect(estimateSeconds({ blocks: null, notes: han(224) }).seconds).toBe(55);
62
+ expect(estimateSeconds({ blocks: null, notes: han(232) }).seconds).toBe(60);
63
+ });
64
+
65
+ it('adds five seconds for each picture when the page is the source', () => {
66
+ // 120 characters is 30 s, plus two pictures.
67
+ const timing = estimateSeconds({
68
+ blocks: [block('text', han(120)), block('image'), block('chart')],
69
+ });
70
+ expect(timing).toEqual({ seconds: 40, basis: 'page' });
71
+ });
72
+
73
+ it('cannot tell how long a page whose blocks were not read takes', () => {
74
+ expect(estimateSeconds({ blocks: null })).toEqual({ seconds: 15, basis: 'none' });
75
+ });
76
+
77
+ it('falls back to the page when the notes are blank', () => {
78
+ expect(estimateSeconds({ notes: ' ', blocks: [block('text', han(120))] })).toEqual({
79
+ seconds: 30,
80
+ basis: 'page',
81
+ });
82
+ });
83
+ });
84
+
85
+ describe('formatDuration', () => {
86
+ it('writes seconds, minutes and seconds, and whole minutes', () => {
87
+ expect(formatDuration(45, 'en')).toBe('45s');
88
+ expect(formatDuration(80, 'en')).toBe('1m 20s');
89
+ expect(formatDuration(720, 'en')).toBe('12 min');
90
+ });
91
+
92
+ it('writes the same in Chinese', () => {
93
+ expect(formatDuration(45, 'zh-CN')).toBe('45 秒');
94
+ expect(formatDuration(80, 'zh-CN')).toBe('1 分 20 秒');
95
+ expect(formatDuration(720, 'zh-CN')).toBe('12 分钟');
96
+ });
97
+ });
98
+
99
+ describe('sanitizeTargetMinutes', () => {
100
+ it('keeps a whole number of minutes within an hour and a half', () => {
101
+ expect(sanitizeTargetMinutes(12)).toBe(12);
102
+ expect(sanitizeTargetMinutes('7')).toBe(7);
103
+ expect(sanitizeTargetMinutes(180)).toBe(180);
104
+ });
105
+
106
+ it('refuses what cannot be a target', () => {
107
+ expect(sanitizeTargetMinutes(0)).toBeNull();
108
+ expect(sanitizeTargetMinutes(181)).toBeNull();
109
+ expect(sanitizeTargetMinutes('')).toBeNull();
110
+ expect(sanitizeTargetMinutes('soon')).toBeNull();
111
+ expect(sanitizeTargetMinutes(null)).toBeNull();
112
+ });
113
+ });
@@ -0,0 +1,117 @@
1
+ import { format } from '../../../../locale/format';
2
+ import type { Locale } from '../../../../locale/types';
3
+ import { lrTextFor } from '../../text/all';
4
+ import type { Block } from '../blocks/classify';
5
+
6
+ /** How long a page takes to say, and what that number was read from. */
7
+ export type Timing = { seconds: number; basis: 'notes' | 'page' | 'none' };
8
+
9
+ const CHARS_PER_MINUTE = 240;
10
+ const WORDS_PER_MINUTE = 150;
11
+ const MIN_SECONDS = 15;
12
+ /** A picture the speaker has to talk over, when nothing else says how long. */
13
+ const PICTURE_SECONDS = 5;
14
+ const STEP = 5;
15
+
16
+ /** Han, kana and the punctuation that reads as a character of its own. */
17
+ const CJK = /[々〇぀-ヿ㐀-䶿一-鿿豈-﫿ヲ-゚]/g;
18
+
19
+ /** Seconds to say `text`: Chinese and Japanese by the character, the rest by the word. */
20
+ export function speakingSeconds(text: string): number {
21
+ const chars = text.match(CJK)?.length ?? 0;
22
+ const words = text
23
+ .replace(CJK, ' ')
24
+ .split(/\s+/)
25
+ .filter((word) => /[\p{L}\p{N}]/u.test(word)).length;
26
+ return (chars / CHARS_PER_MINUTE) * 60 + (words / WORDS_PER_MINUTE) * 60;
27
+ }
28
+
29
+ /** Rounded to five seconds, and never under the time it takes to switch pages. */
30
+ const settle = (seconds: number) => Math.max(MIN_SECONDS, Math.round(seconds / STEP) * STEP);
31
+
32
+ /**
33
+ * Speaker notes win when the page has them — they are what will actually be
34
+ * said. Otherwise the words on the page stand in for them, with a few seconds
35
+ * for every picture or chart on it. A page whose blocks cannot be read only
36
+ * gets the minimum.
37
+ */
38
+ export function estimateSeconds({
39
+ notes,
40
+ blocks,
41
+ }: {
42
+ notes?: string;
43
+ blocks: Block[] | null;
44
+ }): Timing {
45
+ if (notes?.trim()) return { seconds: settle(speakingSeconds(notes)), basis: 'notes' };
46
+ if (!blocks) return { seconds: MIN_SECONDS, basis: 'none' };
47
+
48
+ const words = blocks
49
+ .map((block) => block.text)
50
+ .filter(Boolean)
51
+ .join(' ');
52
+ const pictures = blocks.filter(
53
+ (block) => block.kind === 'image' || block.kind === 'chart',
54
+ ).length;
55
+ return {
56
+ seconds: settle(speakingSeconds(words) + pictures * PICTURE_SECONDS),
57
+ basis: 'page',
58
+ };
59
+ }
60
+
61
+ /** "45s", "1m 20s", "12 min" — the units come from the deck's language. */
62
+ export function formatDuration(seconds: number, locale: Locale['id']): string {
63
+ const text = lrTextFor(locale).board;
64
+ const total = Math.max(0, Math.round(seconds));
65
+ const minutes = Math.floor(total / 60);
66
+ const rest = total % 60;
67
+ if (minutes === 0) return format(text.durationSeconds, { s: rest });
68
+ if (rest === 0) return format(text.durationMinutes, { m: minutes });
69
+ return format(text.durationMinSec, { m: minutes, s: rest });
70
+ }
71
+
72
+ /** Pixels a second takes on the timeline, and the narrowest a page may be drawn. */
73
+ export const PX_PER_SECOND = 4;
74
+ export const MIN_SEGMENT_PX = 48;
75
+
76
+ const TARGET_MAX_MINUTES = 180;
77
+
78
+ /** The length the deck is aiming for, in whole minutes, or null for no target. */
79
+ export function sanitizeTargetMinutes(raw: unknown): number | null {
80
+ const value =
81
+ typeof raw === 'string' && raw.trim() ? Number(raw) : typeof raw === 'number' ? raw : null;
82
+ if (value === null || !Number.isFinite(value)) return null;
83
+ const minutes = Math.round(value);
84
+ return minutes >= 1 && minutes <= TARGET_MAX_MINUTES ? minutes : null;
85
+ }
86
+
87
+ export type Segment = { start: number; width: number };
88
+
89
+ /** Where each page's stretch sits on the track, in track pixels. */
90
+ export function timelineSegments(seconds: number[]): Segment[] {
91
+ let at = 0;
92
+ return seconds.map((value) => {
93
+ const width = Math.max(MIN_SEGMENT_PX, value * PX_PER_SECOND);
94
+ const segment = { start: at, width };
95
+ at += width;
96
+ return segment;
97
+ });
98
+ }
99
+
100
+ /**
101
+ * Where a moment of the talk falls on the track. Pages drawn at their minimum
102
+ * width take more room than their time, so the moment is read from the time up
103
+ * to the page's own start rather than from the pixel count.
104
+ */
105
+ export function xForSeconds(seconds: number[], target: number): number {
106
+ const segments = timelineSegments(seconds);
107
+ const total = segments.reduce((sum, segment) => sum + segment.width, 0);
108
+ let spoken = 0;
109
+ for (const [index, value] of seconds.entries()) {
110
+ if (value <= 0) continue;
111
+ if (target <= spoken + value) {
112
+ return segments[index].start + ((target - spoken) / value) * segments[index].width;
113
+ }
114
+ spoken += value;
115
+ }
116
+ return total;
117
+ }
@@ -1,6 +1,6 @@
1
1
  import { Handle, type NodeProps, Position } from '@xyflow/react';
2
- import { Copy, MoveRight, Trash2 } from 'lucide-react';
3
- import { memo, useEffect, useRef, useState } from 'react';
2
+ import { BarChart3, Copy, Maximize2, MoveRight, PenLine, StickyNote, Trash2 } from 'lucide-react';
3
+ import { memo, useCallback, useEffect, useRef, useState } from 'react';
4
4
  import {
5
5
  ContextMenu,
6
6
  ContextMenuContent,
@@ -13,7 +13,7 @@ import {
13
13
  ContextMenuSubTrigger,
14
14
  ContextMenuTrigger,
15
15
  } from '@/components/ui/context-menu';
16
- import { format, useLocale } from '@/lib/use-locale';
16
+ import { format, plural, useLocale } from '@/lib/use-locale';
17
17
  import { cn, pad2 } from '@/lib/utils';
18
18
  import { SlideCanvas } from '../../components/slide-canvas';
19
19
  import type { DesignSystem } from '../../lib/design';
@@ -21,7 +21,11 @@ import { useNotes } from '../../lib/inspector/use-notes';
21
21
  import { SlidePageProvider } from '../../lib/page-context';
22
22
  import { CANVAS_WIDTH, type Page } from '../../lib/sdk';
23
23
  import { useLrText } from '../text';
24
- import { CARD_H, CARD_W, MEMO_H, NOTE_H } from './layout';
24
+ import { type PageRead, pageReadOf, rememberPageRead, sameRead } from './blocks/cache';
25
+ import { readBlocks } from './blocks/classify';
26
+ import { snapshotPage } from './blocks/snapshot';
27
+ import type { CardMetrics, CardSize } from './layout';
28
+ import { PAGE_ACTIONS, type PageAction } from './model/agent-tasks';
25
29
  import {
26
30
  type BoardCard,
27
31
  CARD_STATUSES,
@@ -29,6 +33,7 @@ import {
29
33
  type CardStatus,
30
34
  isCardStatus,
31
35
  } from './model/cards';
36
+ import { STATUS_STYLE } from './status-style';
32
37
 
33
38
  export type PageNodeData = {
34
39
  slideId: string;
@@ -43,19 +48,30 @@ export type PageNodeData = {
43
48
  canLink: boolean;
44
49
  design?: DesignSystem;
45
50
  canDelete: boolean;
51
+ size: CardSize;
52
+ metrics: CardMetrics;
53
+ /** True when a filter is on and this card is not one of the ones picked out. */
54
+ dimmed: boolean;
55
+ /** How many block moves this page is a source or a target of. */
56
+ changeCount?: number;
57
+ /** The last apply touched this page: it lights up for a moment. */
58
+ flash?: boolean;
46
59
  onDuplicate: (index: number) => void;
47
60
  onDelete: (index: number) => void;
48
61
  onMoveToEnd: (index: number) => void;
49
62
  onPatchCard: (index: number, patch: CardPatch) => void;
63
+ /** Why the one-page agent actions are off, or null when they can run. */
64
+ agentHint: string | null;
65
+ onPageTask: (index: number, action: PageAction) => void;
50
66
  };
51
67
 
52
68
  const hiddenHandle = { opacity: 0, width: 1, height: 1, minWidth: 1, minHeight: 1 } as const;
53
69
 
54
- const STATUS_STYLE: Record<CardStatus, { dot: string; ring: string }> = {
55
- todo: { dot: 'bg-muted-foreground/50', ring: 'ring-muted-foreground/35' },
56
- doing: { dot: 'bg-[var(--lr-accent)]', ring: 'ring-[var(--lr-accent)]' },
57
- review: { dot: 'bg-[var(--lr-warning)]', ring: 'ring-[var(--lr-warning)]/75' },
58
- done: { dot: 'bg-[var(--lr-success)]', ring: 'ring-[var(--lr-success)]/70' },
70
+ const ASK_ICON: Record<PageAction, typeof PenLine> = {
71
+ rewrite: PenLine,
72
+ chart: BarChart3,
73
+ memo: StickyNote,
74
+ expand: Maximize2,
59
75
  };
60
76
 
61
77
  export function useStatusLabels(): Record<CardStatus, string> {
@@ -80,63 +96,145 @@ export function PageNode({ data, selected, dragging }: NodeProps) {
80
96
  canLink,
81
97
  design,
82
98
  canDelete,
99
+ size,
100
+ metrics,
101
+ dimmed,
102
+ changeCount = 0,
103
+ flash = false,
83
104
  ...actions
84
105
  } = data as unknown as PageNodeData;
85
106
  const t = useLocale();
86
107
  const lr = useLrText();
87
108
  const labels = useStatusLabels();
109
+ const askLabels: Record<PageAction, string> = {
110
+ rewrite: lr.board.askRewrite,
111
+ chart: lr.board.askChart,
112
+ memo: lr.board.askMemo,
113
+ expand: lr.board.askExpand,
114
+ };
88
115
  const status = card?.status;
89
116
  const [renaming, setRenaming] = useState(false);
117
+ const [readFor, setReadFor] = useState<{ page: Page; read: PageRead } | null>(null);
118
+ const onRead = useCallback(
119
+ (next: PageRead) =>
120
+ setReadFor((previous) =>
121
+ previous && previous.page === PageComp && sameRead(previous.read, next)
122
+ ? previous
123
+ : { page: PageComp, read: next },
124
+ ),
125
+ [PageComp],
126
+ );
127
+ const read = readFor && readFor.page === PageComp ? readFor.read : pageReadOf(PageComp);
128
+ const whole = read && 'whole' in read ? read.whole : null;
90
129
  // A menu hands focus back to the card as it closes, which would pull the caret
91
130
  // straight out of the name field "Rename" just opened.
92
131
  const renameFromMenu = useRef(false);
93
132
 
94
- const view = (
95
- <div
96
- className={cn(
97
- 'osd-board-card group/card flex flex-col gap-2 rounded-[8px] bg-card p-1.5',
98
- 'motion-safe:transition-[box-shadow,ring-color,scale]',
99
- selected
100
- ? 'ring-2 ring-brand'
101
- : status
102
- ? cn('ring-2', STATUS_STYLE[status].ring)
103
- : 'ring-1 ring-hairline hover:ring-muted-foreground/30',
104
- dragging ? 'cursor-grabbing' : 'cursor-grab',
133
+ const ring = selected
134
+ ? 'ring-2 ring-brand'
135
+ : status
136
+ ? cn('ring-2', STATUS_STYLE[status].ring)
137
+ : 'ring-1 ring-hairline hover:ring-muted-foreground/30';
138
+
139
+ const statusLabel = status && (
140
+ <span className="flex shrink-0 items-center gap-1.5 text-[11px] text-muted-foreground">
141
+ <span className={cn('size-2 rounded-full', STATUS_STYLE[status].dot)} />
142
+ {labels[status]}
143
+ </span>
144
+ );
145
+
146
+ /** What the board knows about this page's blocks, beside its status. */
147
+ const meta = (whole || changeCount > 0 || statusLabel) && (
148
+ <span className="ml-auto flex shrink-0 items-center gap-1.5">
149
+ {whole && (
150
+ <span
151
+ title={lr.board.whole[whole]}
152
+ className="rounded-[3px] bg-muted px-1 py-0.5 text-[10.5px] text-muted-foreground"
153
+ >
154
+ {lr.board.wholeBadge}
155
+ </span>
105
156
  )}
106
- style={{ width: CARD_W + 12 }}
107
- >
157
+ {changeCount > 0 && (
158
+ <span className="rounded-[3px] bg-[var(--lr-accent)]/12 px-1 py-0.5 text-[10.5px] text-[var(--lr-accent)]">
159
+ {format(plural(changeCount, lr.board.pageChanges), { n: changeCount })}
160
+ </span>
161
+ )}
162
+ {statusLabel}
163
+ </span>
164
+ );
165
+
166
+ const title = (
167
+ <CardTitle
168
+ title={card?.title}
169
+ editing={renaming}
170
+ disabled={!cardsReady}
171
+ onEditingChange={setRenaming}
172
+ onCommit={(next) => actions.onPatchCard(index, { title: next })}
173
+ />
174
+ );
175
+
176
+ const view =
177
+ size === 'title' ? (
108
178
  <div
109
- className="relative overflow-hidden rounded-[4px] bg-white ring-1 ring-hairline"
110
- style={{ width: CARD_W, height: CARD_H }}
179
+ className={cn(
180
+ 'osd-board-card group/card flex items-center gap-2 rounded-[8px] bg-card px-2.5',
181
+ 'motion-safe:transition-[box-shadow,ring-color,scale,opacity]',
182
+ ring,
183
+ flash && 'osd-board-applied',
184
+ dragging ? 'cursor-grabbing' : 'cursor-grab',
185
+ )}
186
+ style={{ width: metrics.boxW, height: metrics.boxH, opacity: dimmed ? 0.35 : 1 }}
111
187
  >
112
- <PagePreview page={PageComp} index={index} total={total} design={design} />
113
- </div>
114
- <div className="flex h-6 items-center gap-2 px-0.5">
115
188
  <span className="font-mono text-[10.5px] tracking-[0.08em] tabular-nums text-muted-foreground/70">
116
189
  {pad2(index + 1)}
117
190
  </span>
118
- <CardTitle
119
- title={card?.title}
120
- editing={renaming}
121
- disabled={!cardsReady}
122
- onEditingChange={setRenaming}
123
- onCommit={(title) => actions.onPatchCard(index, { title })}
124
- />
125
- {status && (
126
- <span className="ml-auto flex shrink-0 items-center gap-1.5 text-[11px] text-muted-foreground">
127
- <span className={cn('size-2 rounded-full', STATUS_STYLE[status].dot)} />
128
- {labels[status]}
191
+ {title}
192
+ {meta}
193
+ </div>
194
+ ) : (
195
+ <div
196
+ className={cn(
197
+ 'osd-board-card group/card flex flex-col gap-2 rounded-[8px] bg-card p-1.5',
198
+ 'motion-safe:transition-[box-shadow,ring-color,scale,opacity]',
199
+ ring,
200
+ flash && 'osd-board-applied',
201
+ dragging ? 'cursor-grabbing' : 'cursor-grab',
202
+ )}
203
+ style={{ width: metrics.boxW, opacity: dimmed ? 0.35 : 1 }}
204
+ >
205
+ <div
206
+ className="relative overflow-hidden rounded-[4px] bg-white ring-1 ring-hairline"
207
+ style={{ width: metrics.cardW, height: metrics.cardH }}
208
+ >
209
+ <PagePreview
210
+ page={PageComp}
211
+ index={index}
212
+ total={total}
213
+ design={design}
214
+ scale={metrics.cardW / CANVAS_WIDTH}
215
+ onRead={onRead}
216
+ />
217
+ </div>
218
+ <div className="flex h-6 items-center gap-2 px-0.5">
219
+ <span className="font-mono text-[10.5px] tracking-[0.08em] tabular-nums text-muted-foreground/70">
220
+ {pad2(index + 1)}
129
221
  </span>
222
+ {title}
223
+ {meta}
224
+ </div>
225
+ {size === 'large' && (
226
+ <NoteStrip slideId={slideId} index={index} initial={note} height={metrics.noteH} />
227
+ )}
228
+ {size === 'large' && (
229
+ <MemoStrip
230
+ memo={card?.memo}
231
+ disabled={!cardsReady}
232
+ height={metrics.memoH}
233
+ onCommit={(memo) => actions.onPatchCard(index, { memo })}
234
+ />
130
235
  )}
131
236
  </div>
132
- <NoteStrip slideId={slideId} index={index} initial={note} />
133
- <MemoStrip
134
- memo={card?.memo}
135
- disabled={!cardsReady}
136
- onCommit={(memo) => actions.onPatchCard(index, { memo })}
137
- />
138
- </div>
139
- );
237
+ );
140
238
 
141
239
  return (
142
240
  <>
@@ -192,6 +290,31 @@ export function PageNode({ data, selected, dragging }: NodeProps) {
192
290
  </ContextMenuSubContent>
193
291
  </ContextMenuSub>
194
292
  <ContextMenuSeparator />
293
+ <ContextMenuSub>
294
+ <ContextMenuSubTrigger>{lr.board.askAgent}</ContextMenuSubTrigger>
295
+ <ContextMenuSubContent className="min-w-[210px]">
296
+ {PAGE_ACTIONS.map((action) => {
297
+ const needsMemo = action === 'memo' && !card?.memo?.trim();
298
+ const hint =
299
+ actions.agentHint ??
300
+ (changeCount > 0 ? lr.board.askHasChanges : null) ??
301
+ (needsMemo ? lr.board.askNeedsMemo : null);
302
+ const Icon = ASK_ICON[action];
303
+ return (
304
+ <ContextMenuItem
305
+ key={action}
306
+ disabled={hint !== null}
307
+ title={hint ?? undefined}
308
+ onClick={() => actions.onPageTask(index, action)}
309
+ >
310
+ <Icon />
311
+ {askLabels[action]}
312
+ </ContextMenuItem>
313
+ );
314
+ })}
315
+ </ContextMenuSubContent>
316
+ </ContextMenuSub>
317
+ <ContextMenuSeparator />
195
318
  <ContextMenuItem onClick={() => actions.onDuplicate(index)}>
196
319
  <Copy />
197
320
  {t.thumbnailRail.duplicatePage}
@@ -239,25 +362,79 @@ export function PageNode({ data, selected, dragging }: NodeProps) {
239
362
 
240
363
  /**
241
364
  * The live page, kept apart so editing a card's title, status or memo does not
242
- * re-render a page that can carry thousands of elements.
365
+ * re-render a page that can carry thousands of elements. It is also where a
366
+ * page is read for its blocks: the DOM is already here, and the reading waits
367
+ * for the browser to be idle so a board of thirty cards still opens quickly.
243
368
  */
244
- const PagePreview = memo(function PagePreview({
369
+ export const PagePreview = memo(function PagePreview({
245
370
  page: PageComp,
246
371
  index,
247
372
  total,
248
373
  design,
374
+ scale,
375
+ onRead,
249
376
  }: {
250
377
  page: Page;
251
378
  index: number;
252
379
  total: number;
253
380
  design?: DesignSystem;
381
+ scale: number;
382
+ onRead?: (read: PageRead) => void;
254
383
  }) {
384
+ const host = useRef<HTMLDivElement | null>(null);
385
+
386
+ useEffect(() => {
387
+ let cancelled = false;
388
+ let timer: number | null = null;
389
+
390
+ const read = () => {
391
+ const canvas = host.current?.querySelector<HTMLElement>('[data-osd-canvas]');
392
+ if (!canvas) return;
393
+ const next = readBlocks(snapshotPage(canvas, scale));
394
+ rememberPageRead(PageComp, next);
395
+ onRead?.(next);
396
+ };
397
+
398
+ const idle =
399
+ typeof window.requestIdleCallback === 'function'
400
+ ? window.requestIdleCallback(read, { timeout: 2000 })
401
+ : window.setTimeout(read, 200);
402
+
403
+ // Editing a page in another tab, or a hot update to its source, redraws the
404
+ // same component in place, so the read is refreshed when the canvas changes.
405
+ const canvas = host.current?.querySelector<HTMLElement>('[data-osd-canvas]');
406
+ const observer = canvas
407
+ ? new MutationObserver(() => {
408
+ if (timer !== null) window.clearTimeout(timer);
409
+ timer = window.setTimeout(() => {
410
+ timer = null;
411
+ if (!cancelled) read();
412
+ }, 300);
413
+ })
414
+ : null;
415
+ observer?.observe(canvas as HTMLElement, {
416
+ childList: true,
417
+ subtree: true,
418
+ characterData: true,
419
+ });
420
+
421
+ return () => {
422
+ cancelled = true;
423
+ observer?.disconnect();
424
+ if (timer !== null) window.clearTimeout(timer);
425
+ if (typeof window.cancelIdleCallback === 'function') window.cancelIdleCallback(idle);
426
+ else window.clearTimeout(idle);
427
+ };
428
+ }, [PageComp, scale, onRead]);
429
+
255
430
  return (
256
- <SlideCanvas scale={CARD_W / CANVAS_WIDTH} center={false} flat freezeMotion design={design}>
257
- <SlidePageProvider index={index} total={total}>
258
- <PageComp />
259
- </SlidePageProvider>
260
- </SlideCanvas>
431
+ <div ref={host} className="h-full w-full">
432
+ <SlideCanvas scale={scale} center={false} flat freezeMotion design={design}>
433
+ <SlidePageProvider index={index} total={total}>
434
+ <PageComp />
435
+ </SlidePageProvider>
436
+ </SlideCanvas>
437
+ </div>
261
438
  );
262
439
  });
263
440
 
@@ -339,10 +516,12 @@ function NoteStrip({
339
516
  slideId,
340
517
  index,
341
518
  initial,
519
+ height,
342
520
  }: {
343
521
  slideId: string;
344
522
  index: number;
345
523
  initial?: string;
524
+ height: number;
346
525
  }) {
347
526
  const t = useLocale();
348
527
  const lr = useLrText();
@@ -357,7 +536,7 @@ function NoteStrip({
357
536
  const shared = 'w-full rounded-[4px] px-1.5 py-1 text-left text-[11px] leading-[1.45]';
358
537
 
359
538
  return (
360
- <div className="nodrag nopan" style={{ height: NOTE_H }}>
539
+ <div className="nodrag nopan" style={{ height }}>
361
540
  {editing ? (
362
541
  <textarea
363
542
  ref={ref}
@@ -416,10 +595,12 @@ function NoteStrip({
416
595
  function MemoStrip({
417
596
  memo,
418
597
  disabled,
598
+ height,
419
599
  onCommit,
420
600
  }: {
421
601
  memo?: string;
422
602
  disabled: boolean;
603
+ height: number;
423
604
  onCommit: (memo: string) => void;
424
605
  }) {
425
606
  const lr = useLrText();
@@ -434,7 +615,7 @@ function MemoStrip({
434
615
  const shared = 'w-full rounded-[4px] px-1.5 py-1 text-left text-[11px] leading-[1.45]';
435
616
 
436
617
  return (
437
- <div className="nodrag nopan" style={{ height: MEMO_H }}>
618
+ <div className="nodrag nopan" style={{ height }}>
438
619
  {editing ? (
439
620
  <textarea
440
621
  ref={ref}
@@ -0,0 +1,25 @@
1
+ import type { CardStatus } from './model/cards';
2
+
3
+ /** One colour per status, shared by the cards, the list and the timeline. */
4
+ export const STATUS_STYLE: Record<CardStatus, { dot: string; ring: string; bar: string }> = {
5
+ todo: {
6
+ dot: 'bg-muted-foreground/50',
7
+ ring: 'ring-muted-foreground/35',
8
+ bar: 'bg-muted-foreground/20',
9
+ },
10
+ doing: {
11
+ dot: 'bg-[var(--lr-accent)]',
12
+ ring: 'ring-[var(--lr-accent)]',
13
+ bar: 'bg-[var(--lr-accent)]/25',
14
+ },
15
+ review: {
16
+ dot: 'bg-[var(--lr-warning)]',
17
+ ring: 'ring-[var(--lr-warning)]/75',
18
+ bar: 'bg-[var(--lr-warning)]/30',
19
+ },
20
+ done: {
21
+ dot: 'bg-[var(--lr-success)]',
22
+ ring: 'ring-[var(--lr-success)]/70',
23
+ bar: 'bg-[var(--lr-success)]/30',
24
+ },
25
+ };