@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.
Files changed (57) hide show
  1. package/dist/{build-CS1goZxt.js → build-RlcGG-Ve.js} +1 -1
  2. package/dist/cli/bin.js +3 -3
  3. package/dist/{config-BpbcCbUv.js → config-BJT87wE9.js} +1155 -19
  4. package/dist/{dev-BpYnfgLL.js → dev-DR-j_xda.js} +1 -1
  5. package/dist/{preview-HSzPPkSs.js → preview-BTAhTb5B.js} +1 -1
  6. package/dist/vite/index.js +1 -1
  7. package/package.json +1 -1
  8. package/src/app/lemonriver/board/blocks/classify.test.ts +5 -0
  9. package/src/app/lemonriver/board/blocks/classify.ts +29 -2
  10. package/src/app/lemonriver/board/blocks/snapshot.ts +34 -4
  11. package/src/app/lemonriver/board/board-page.tsx +15 -0
  12. package/src/app/lemonriver/board/model/agent-tasks.ts +33 -1
  13. package/src/app/lemonriver/board/model/self-check.test.ts +329 -0
  14. package/src/app/lemonriver/board/model/self-check.ts +489 -0
  15. package/src/app/lemonriver/board/page-node.tsx +23 -1
  16. package/src/app/lemonriver/board/self-check-jump.ts +23 -0
  17. package/src/app/lemonriver/board/self-check-panel.tsx +272 -0
  18. package/src/app/lemonriver/board/self-check-runner.tsx +150 -0
  19. package/src/app/lemonriver/board/use-self-check.ts +117 -0
  20. package/src/app/lemonriver/chrome/filter-pill.tsx +30 -0
  21. package/src/app/lemonriver/chrome/sidebar-extras.tsx +12 -1
  22. package/src/app/lemonriver/features.test.ts +5 -0
  23. package/src/app/lemonriver/features.ts +2 -1
  24. package/src/app/lemonriver/home/deck-card.tsx +10 -0
  25. package/src/app/lemonriver/home/home-page.tsx +55 -6
  26. package/src/app/lemonriver/home/use-deck-times.ts +4 -1
  27. package/src/app/lemonriver/outline/build-team.tsx +42 -0
  28. package/src/app/lemonriver/outline/describe-page.tsx +128 -27
  29. package/src/app/lemonriver/outline/draft.ts +38 -0
  30. package/src/app/lemonriver/outline/model.test.ts +79 -0
  31. package/src/app/lemonriver/outline/model.ts +80 -7
  32. package/src/app/lemonriver/outline/outline-page.tsx +56 -6
  33. package/src/app/lemonriver/outline/pick-style.tsx +282 -0
  34. package/src/app/lemonriver/routes.test.tsx +17 -5
  35. package/src/app/lemonriver/routes.tsx +28 -0
  36. package/src/app/lemonriver/templates/client.ts +60 -0
  37. package/src/app/lemonriver/templates/demo-page.tsx +79 -0
  38. package/src/app/lemonriver/templates/knobs.test.ts +62 -0
  39. package/src/app/lemonriver/templates/knobs.ts +62 -0
  40. package/src/app/lemonriver/templates/library-page.tsx +292 -0
  41. package/src/app/lemonriver/templates/model.test.ts +175 -0
  42. package/src/app/lemonriver/templates/model.ts +339 -0
  43. package/src/app/lemonriver/templates/preview-content.test.ts +117 -0
  44. package/src/app/lemonriver/templates/preview-content.ts +149 -0
  45. package/src/app/lemonriver/templates/recommend.test.ts +71 -0
  46. package/src/app/lemonriver/templates/recommend.ts +72 -0
  47. package/src/app/lemonriver/templates/use-library.ts +58 -0
  48. package/src/app/lemonriver/templates/virtual.d.ts +28 -0
  49. package/src/app/lemonriver/text/en.ts +57 -0
  50. package/src/app/lemonriver/text/es.ts +57 -0
  51. package/src/app/lemonriver/text/ja.ts +57 -0
  52. package/src/app/lemonriver/text/types.ts +73 -0
  53. package/src/app/lemonriver/text/zh-cn.ts +57 -0
  54. package/src/app/lemonriver/text/zh-tw.ts +57 -0
  55. package/src/app/lemonriver/theme/pages.test.ts +4 -0
  56. package/src/app/lemonriver/theme/pages.ts +6 -1
  57. package/src/app/lemonriver/update/prompt.ts +1 -1
@@ -1,5 +1,6 @@
1
1
  import type { AgentItem } from '../../../agent/types';
2
2
  import { type AgentPrefs, prefsLines, sanitizePrefs } from '../agent-prefs/prefs';
3
+ import { OCCASIONS, type OccasionId, SKELETONS, type SkeletonId } from '../templates/model';
3
4
 
4
5
  export const PAGE_KINDS = ['cover', 'kpi', 'chart', 'list', 'page', 'end'] as const;
5
6
  export type PageKind = (typeof PAGE_KINDS)[number];
@@ -31,6 +32,14 @@ export type Outline = {
31
32
  lastTurn: BuildTurn | null;
32
33
  prefs: AgentPrefs;
33
34
  decisions: Decision[];
35
+ occasion: OccasionId | null;
36
+ audience: string;
37
+ /** The template's opening instructions, written when the build copied its kit in. */
38
+ templatePrompt: string;
39
+ /** The skeletons that travelled with that template, for the per-page suggestions. */
40
+ templateSkeletons: SkeletonId[];
41
+ /** The template picked when describing the deck; a direct build applies it. */
42
+ templateId: string | null;
34
43
  };
35
44
 
36
45
  export const OUTLINE_PAGE_SIZES = [5, 8, 12] as const;
@@ -38,8 +47,22 @@ export const MAX_ITEMS = 30;
38
47
  export const MIN_ITEMS = 2;
39
48
  export const MAX_TITLE = 120;
40
49
  export const MAX_BRIEF = 2000;
50
+ export const MAX_AUDIENCE = 40;
41
51
  export const MAX_DECISIONS = 20;
42
52
  export const MAX_DECISION_TEXT = 120;
53
+ export const MAX_TEMPLATE_PROMPT = 8000;
54
+
55
+ const SKELETON_IDS = new Set<string>(SKELETONS.map((skeleton) => skeleton.id));
56
+
57
+ function sanitizeSkeletons(raw: unknown): SkeletonId[] {
58
+ if (!Array.isArray(raw)) return [];
59
+ const out: SkeletonId[] = [];
60
+ for (const entry of raw) {
61
+ if (typeof entry !== 'string' || !SKELETON_IDS.has(entry)) continue;
62
+ if (!out.includes(entry as SkeletonId)) out.push(entry as SkeletonId);
63
+ }
64
+ return out;
65
+ }
43
66
 
44
67
  const ID_RE = /^[a-z0-9-]{1,40}$/;
45
68
  const BLOCK_RE = /<lemonriver-outline>([\s\S]*?)<\/lemonriver-outline>/gi;
@@ -59,6 +82,14 @@ export function isOutlineState(value: unknown): value is OutlineState {
59
82
  return typeof value === 'string' && (OUTLINE_STATES as readonly string[]).includes(value);
60
83
  }
61
84
 
85
+ export function isOccasionId(value: unknown): value is OccasionId {
86
+ return typeof value === 'string' && OCCASIONS.some((occasion) => occasion.id === value);
87
+ }
88
+
89
+ function cleanAudience(value: unknown): string {
90
+ return typeof value === 'string' ? value.trim().slice(0, MAX_AUDIENCE) : '';
91
+ }
92
+
62
93
  function cleanTitle(value: unknown): string {
63
94
  return typeof value === 'string' ? value.trim().slice(0, MAX_TITLE) : '';
64
95
  }
@@ -178,6 +209,15 @@ export function sanitizeOutline(raw: unknown): Outline | null {
178
209
  lastTurn: cleanTurn(r.lastTurn, items.length),
179
210
  prefs: sanitizePrefs(r.prefs),
180
211
  decisions: sanitizeDecisions(r.decisions),
212
+ occasion: isOccasionId(r.occasion) ? r.occasion : null,
213
+ audience: cleanAudience(r.audience),
214
+ templatePrompt:
215
+ typeof r.templatePrompt === 'string' ? r.templatePrompt.slice(0, MAX_TEMPLATE_PROMPT) : '',
216
+ templateSkeletons: sanitizeSkeletons(r.templateSkeletons),
217
+ templateId:
218
+ typeof r.templateId === 'string' && /^[a-z0-9][a-z0-9-]*$/.test(r.templateId)
219
+ ? r.templateId
220
+ : null,
181
221
  };
182
222
  }
183
223
 
@@ -260,6 +300,29 @@ const KIND_GUIDE: Record<PageKind, string> = {
260
300
  end: 'closing — the last page and what should happen next',
261
301
  };
262
302
 
303
+ const TEMPLATE_PAGE_LINE =
304
+ 'Keep using the template in ./kit/ — follow kit/docs/GUIDE.md and pick one skeleton per page.';
305
+
306
+ const TEMPLATE_REVIEW_LINE =
307
+ "Before you finish, take a screenshot of every page (see the slide-authoring skill's preview section) and go through kit/docs/质量清单.md item by item; fix what fails. Reply with the items you could not satisfy, if any.";
308
+
309
+ const FRAMEWORK_REVIEW_LINE =
310
+ "Before you finish, take a screenshot of every page (see the slide-authoring skill's preview section) and go through the pre-delivery checklist at the end of the slide-authoring skill item by item; fix what fails. Reply with the items you could not satisfy, if any.";
311
+
312
+ const SKELETON_FOR_KIND: Record<PageKind, SkeletonId[]> = {
313
+ cover: ['cover'],
314
+ kpi: ['overview', 'bignum'],
315
+ chart: ['figure'],
316
+ list: ['cards'],
317
+ page: ['compare', 'process'],
318
+ end: ['end'],
319
+ };
320
+
321
+ /** The skeleton the template offers for a page of this kind, if it has one. */
322
+ export function skeletonFor(kind: PageKind, available: readonly SkeletonId[]): SkeletonId | null {
323
+ return SKELETON_FOR_KIND[kind].find((id) => available.includes(id)) ?? null;
324
+ }
325
+
263
326
  export function outlinePrompt(outline: Outline, slideId: string, lang: string): string {
264
327
  const fileList =
265
328
  outline.files.length > 0
@@ -286,22 +349,31 @@ export function pagePrompt(outline: Outline, slideId: string, k: number): string
286
349
  const page = outline.items[k - 1];
287
350
  if (k >= 2 && page) {
288
351
  const title = page.title || '(untitled)';
289
- return [
290
- `Page ${k} of ${outline.items.length}: [${page.kind}] ${title}. Write only this page; leave the others as they are.`,
291
- ...prefsLines(outline.prefs, 'page'),
292
- ].join('\n');
352
+ const skeleton = skeletonFor(page.kind, outline.templateSkeletons);
353
+ const lines = [
354
+ `Page ${k} of ${outline.items.length}: [${page.kind}] ${title}${skeleton ? ` → ${skeleton}` : ''}. Write only this page; leave the others as they are.`,
355
+ ];
356
+ if (outline.templatePrompt) lines.push(TEMPLATE_PAGE_LINE);
357
+ lines.push(...prefsLines(outline.prefs, 'page'));
358
+ return lines.join('\n');
293
359
  }
294
360
  const list = outline.items
295
- .map((item, i) => `${i + 1}. [${item.kind}] ${item.title || '(untitled)'}`)
361
+ .map((item, i) => {
362
+ const base = `${i + 1}. [${item.kind}] ${item.title || '(untitled)'}`;
363
+ const skeleton = skeletonFor(item.kind, outline.templateSkeletons);
364
+ return skeleton ? `${base} → ${skeleton}` : base;
365
+ })
296
366
  .join('\n');
297
- return [
367
+ const lines = [
298
368
  `Build ${file} from this outline, one page per turn. This turn: write page 1 only, replacing the placeholder page, and set meta.title to the deck title. Pages:`,
299
369
  list,
300
370
  'Page kinds and how to write them:',
301
371
  ...PAGE_KINDS.map((kind) => `- ${KIND_GUIDE[kind]}`),
302
372
  'Numbers from the reference files stay exactly as written there.',
303
373
  ...prefsLines(outline.prefs, 'page'),
304
- ].join('\n');
374
+ ];
375
+ if (outline.templatePrompt) return `${outline.templatePrompt}\n\n${lines.join('\n')}`;
376
+ return lines.join('\n');
305
377
  }
306
378
 
307
379
  export function reviewPrompt(outline: Outline, slideId: string): string {
@@ -310,6 +382,7 @@ export function reviewPrompt(outline: Outline, slideId: string): string {
310
382
  `Check each page of slides/${slideId}/index.tsx against the outline and the reference files in slides/${slideId}/assets/:`,
311
383
  'fix typos and any number that differs from the files.',
312
384
  ];
385
+ lines.push(outline.templatePrompt ? TEMPLATE_REVIEW_LINE : FRAMEWORK_REVIEW_LINE);
313
386
  if (outline.prefs.askOnMismatch) {
314
387
  lines.push(
315
388
  'If two files give different numbers for the same thing, ask the user which to use before changing it.',
@@ -16,7 +16,7 @@ import {
16
16
  import { CSS } from '@dnd-kit/utilities';
17
17
  import { ArrowDown, ArrowLeft, ArrowUp, GripVertical, Trash2 } from 'lucide-react';
18
18
  import type { ReactNode } from 'react';
19
- import { useCallback, useEffect, useRef, useState } from 'react';
19
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
20
20
  import { useNavigate, useParams } from 'react-router-dom';
21
21
  import { toast } from 'sonner';
22
22
  import { Button } from '@/components/ui/button';
@@ -41,8 +41,11 @@ import { format, useLocale } from '@/lib/use-locale';
41
41
  import { cn } from '@/lib/utils';
42
42
  import { readPrefs } from '../agent-prefs/prefs';
43
43
  import { Mascot } from '../brand/mascot';
44
+ import { previewContent } from '../templates/preview-content';
45
+ import { useTemplateLibrary } from '../templates/use-library';
44
46
  import { useLrText } from '../text';
45
47
  import type { LrText } from '../text/types';
48
+ import { draftTemplateId } from './draft';
46
49
  import {
47
50
  insertPage,
48
51
  lastErrorText,
@@ -56,6 +59,7 @@ import {
56
59
  renamePage,
57
60
  setKind,
58
61
  } from './model';
62
+ import { PickStyle, type TemplateChoice } from './pick-style';
59
63
  import { Steps } from './steps';
60
64
 
61
65
  const SAVE_DELAY_MS = 400;
@@ -99,6 +103,10 @@ export function OutlineView() {
99
103
  const [outline, setOutline] = useState<Outline | null | undefined>(undefined);
100
104
  const [items, setItems] = useState<OutlinePage[]>([]);
101
105
  const [building, setBuilding] = useState(false);
106
+ const [picking, setPicking] = useState(false);
107
+ const library = useTemplateLibrary();
108
+ const draftTemplate = useMemo(() => draftTemplateId(), []);
109
+ const preferredTemplate = outline?.templateId ?? draftTemplate;
102
110
  const dirty = useRef(false);
103
111
  const saveTimer = useRef<number | null>(null);
104
112
  const redirected = useRef(false);
@@ -182,14 +190,18 @@ export function OutlineView() {
182
190
  return session.id;
183
191
  }
184
192
 
185
- async function build() {
193
+ async function build(choice: TemplateChoice | null = null) {
186
194
  if (!outline || building) return;
187
195
  setBuilding(true);
188
196
  try {
189
197
  const res = await fetch('/__lr/outline/build', {
190
198
  method: 'POST',
191
199
  headers: { 'content-type': 'application/json' },
192
- body: JSON.stringify({ slideId, prefs: readPrefs(localStorage) }),
200
+ body: JSON.stringify({
201
+ slideId,
202
+ prefs: readPrefs(localStorage),
203
+ ...(choice ? { template: choice } : {}),
204
+ }),
193
205
  });
194
206
  if (!res.ok) throw new Error('build failed');
195
207
  setDockOpen(true);
@@ -200,6 +212,14 @@ export function OutlineView() {
200
212
  }
201
213
  }
202
214
 
215
+ function startBuild() {
216
+ if (library?.available && library.templates.length > 0) {
217
+ setPicking(true);
218
+ return;
219
+ }
220
+ void build();
221
+ }
222
+
203
223
  async function retry() {
204
224
  if (!outline) return;
205
225
  try {
@@ -243,6 +263,19 @@ export function OutlineView() {
243
263
  (session) => session.slideId === slideId && session.status === 'running',
244
264
  );
245
265
 
266
+ const pickContent = useMemo(
267
+ () =>
268
+ previewContent(
269
+ {
270
+ brief: outline?.brief ?? '',
271
+ audience: outline?.audience ?? '',
272
+ items: items.map((item) => ({ title: item.title, kind: item.kind })),
273
+ },
274
+ { locale: locale.id },
275
+ ),
276
+ [outline?.brief, outline?.audience, items, locale.id],
277
+ );
278
+
246
279
  return (
247
280
  <div data-lr-outline className="min-h-dvh bg-background text-foreground">
248
281
  <div className="mx-auto w-full max-w-[820px] px-6 py-8">
@@ -344,7 +377,24 @@ export function OutlineView() {
344
377
  {outline &&
345
378
  outline.state !== 'drafting' &&
346
379
  outline.state !== 'failed' &&
347
- outline.state !== 'building' && (
380
+ outline.state !== 'building' &&
381
+ picking && (
382
+ <PickStyle
383
+ templates={library?.templates ?? []}
384
+ occasion={outline.occasion}
385
+ content={pickContent}
386
+ preferred={preferredTemplate}
387
+ building={building}
388
+ onBack={() => setPicking(false)}
389
+ onBuild={(choice) => void build(choice)}
390
+ />
391
+ )}
392
+
393
+ {outline &&
394
+ outline.state !== 'drafting' &&
395
+ outline.state !== 'failed' &&
396
+ outline.state !== 'building' &&
397
+ !picking && (
348
398
  <>
349
399
  <ul className="mt-8 flex flex-col gap-2">
350
400
  <DndContext
@@ -395,8 +445,8 @@ export function OutlineView() {
395
445
  <div className="mt-6 flex justify-end">
396
446
  <Button
397
447
  type="button"
398
- disabled={outline.state !== 'ready' || running || building}
399
- onClick={() => void build()}
448
+ disabled={outline.state !== 'ready' || running || building || !library}
449
+ onClick={startBuild}
400
450
  >
401
451
  {lr.build}
402
452
  </Button>
@@ -0,0 +1,282 @@
1
+ import { useEffect, useMemo, useState } from 'react';
2
+ import { toast } from 'sonner';
3
+ import { Button } from '@/components/ui/button';
4
+ import { format } from '@/lib/use-locale';
5
+ import { cn } from '@/lib/utils';
6
+ import { SlideCanvas } from '../../components/slide-canvas';
7
+ import { designToCssVars } from '../../lib/design';
8
+ import { SlidePageProvider } from '../../lib/page-context';
9
+ import {
10
+ loadTemplatePreview,
11
+ type TemplateMeta,
12
+ type TemplatePreviewModule,
13
+ } from '../templates/client';
14
+ import { applyKnobs, type OccasionId, type TemplateKnobValues } from '../templates/model';
15
+ import type { PreviewContent } from '../templates/preview-content';
16
+ import { recommendTemplates } from '../templates/recommend';
17
+ import { useLrText } from '../text';
18
+
19
+ const KNOB_KEYS = ['formal', 'bright', 'motion'] as const;
20
+ type KnobKey = (typeof KNOB_KEYS)[number];
21
+
22
+ const DEFAULT_KNOBS: TemplateKnobValues = { formal: 0.5, bright: 0.5, motion: 0.5 };
23
+
24
+ export type TemplateChoice = { id: string; knobs: TemplateKnobValues };
25
+
26
+ function initialPicks(
27
+ templates: TemplateMeta[],
28
+ occasion: OccasionId | null,
29
+ preferred: string | null,
30
+ ): TemplateMeta[] {
31
+ const base = recommendTemplates(templates, { occasion }).picks;
32
+ if (!preferred) return base;
33
+ const wanted = templates.find((template) => template.id === preferred);
34
+ if (!wanted) return base;
35
+ return [wanted, ...base.filter((template) => template.id !== preferred)].slice(0, 3);
36
+ }
37
+
38
+ function usePreview(id: string): TemplatePreviewModule | null {
39
+ const [preview, setPreview] = useState<TemplatePreviewModule | null>(null);
40
+ useEffect(() => {
41
+ let cancelled = false;
42
+ setPreview(null);
43
+ loadTemplatePreview(id)
44
+ .then((module) => {
45
+ if (!cancelled) setPreview(module);
46
+ })
47
+ .catch(() => {});
48
+ return () => {
49
+ cancelled = true;
50
+ };
51
+ }, [id]);
52
+ return preview;
53
+ }
54
+
55
+ export function PickStyle({
56
+ templates,
57
+ occasion,
58
+ content,
59
+ preferred,
60
+ building,
61
+ onBack,
62
+ onBuild,
63
+ }: {
64
+ templates: TemplateMeta[];
65
+ occasion: OccasionId | null;
66
+ content: PreviewContent;
67
+ preferred: string | null;
68
+ building: boolean;
69
+ onBack: () => void;
70
+ onBuild: (choice: TemplateChoice | null) => void;
71
+ }) {
72
+ const lr = useLrText().outline;
73
+ const [picks, setPicks] = useState<TemplateMeta[]>(() =>
74
+ initialPicks(templates, occasion, preferred),
75
+ );
76
+ const [excluded, setExcluded] = useState<string[]>([]);
77
+ const [selected, setSelected] = useState<string | null>(() =>
78
+ preferred && templates.some((template) => template.id === preferred) ? preferred : null,
79
+ );
80
+ const [knobs, setKnobs] = useState<TemplateKnobValues>(DEFAULT_KNOBS);
81
+
82
+ const chosen = useMemo(
83
+ () => picks.find((template) => template.id === selected) ?? null,
84
+ [picks, selected],
85
+ );
86
+
87
+ function anotherRound() {
88
+ const shown = [...excluded, ...picks.map((template) => template.id)];
89
+ const next = recommendTemplates(templates, { occasion, exclude: shown }).picks;
90
+ setPicks(next);
91
+ setExcluded(shown);
92
+ setSelected(null);
93
+ setKnobs(DEFAULT_KNOBS);
94
+ }
95
+
96
+ function pickForMe() {
97
+ const first = picks[0];
98
+ if (!first) return;
99
+ setSelected(first.id);
100
+ toast.success(format(lr.pickToast, { name: first.name, reason: first.reason }));
101
+ onBuild({ id: first.id, knobs: DEFAULT_KNOBS });
102
+ }
103
+
104
+ if (picks.length === 0) return null;
105
+
106
+ return (
107
+ <div data-lr-pick className="mt-8">
108
+ <div className="flex items-start justify-between gap-4">
109
+ <div>
110
+ <h2 className="font-heading text-[22px] font-bold leading-7">{lr.pickTitle}</h2>
111
+ <p className="mt-1 text-[13.5px] text-muted-foreground">{lr.pickHint}</p>
112
+ </div>
113
+ <Button type="button" variant="ghost" size="sm" onClick={onBack}>
114
+ {lr.pickBack}
115
+ </Button>
116
+ </div>
117
+
118
+ <div role="radiogroup" aria-label={lr.pickTitle} className="mt-5 grid gap-4 md:grid-cols-3">
119
+ {picks.map((template) => (
120
+ <PickColumn
121
+ key={template.id}
122
+ template={template}
123
+ content={content}
124
+ knobs={selected === template.id ? knobs : DEFAULT_KNOBS}
125
+ selected={selected === template.id}
126
+ onSelect={() => setSelected(template.id)}
127
+ />
128
+ ))}
129
+ </div>
130
+
131
+ {chosen && (
132
+ <div data-lr-knobs className="mt-5 rounded-[14px] border border-border bg-card px-5 py-4">
133
+ <p className="text-[13px] font-semibold">
134
+ {format(lr.pickKnobsFor, { name: chosen.name })}
135
+ </p>
136
+ <div className="mt-3 flex flex-col gap-3">
137
+ {KNOB_KEYS.map((key) => {
138
+ const knob = chosen.knobs[key];
139
+ if (!knob) return null;
140
+ return (
141
+ <div key={key} data-lr-knob={key}>
142
+ <label className="flex items-center gap-3 text-[12.5px] text-muted-foreground">
143
+ <span className="w-[104px] shrink-0">{lr[knobLabelKey(key)]}</span>
144
+ <input
145
+ type="range"
146
+ min={0}
147
+ max={1}
148
+ step={0.5}
149
+ value={knobs[key] ?? 0.5}
150
+ aria-label={lr[knobLabelKey(key)]}
151
+ onChange={(event) =>
152
+ setKnobs((prev) => ({ ...prev, [key]: Number(event.target.value) }))
153
+ }
154
+ className="h-1.5 flex-1 accent-[var(--lr-focus)]"
155
+ />
156
+ </label>
157
+ {key === 'motion' && (
158
+ <p className="mt-1 pl-[116px] text-[11.5px] text-muted-foreground">
159
+ {lr.motionHint}
160
+ </p>
161
+ )}
162
+ </div>
163
+ );
164
+ })}
165
+ </div>
166
+ </div>
167
+ )}
168
+
169
+ <div className="mt-5 flex flex-wrap items-center gap-2">
170
+ <Button type="button" variant="outline" size="sm" onClick={anotherRound}>
171
+ {lr.pickMore}
172
+ </Button>
173
+ <Button type="button" variant="ghost" size="sm" onClick={pickForMe} disabled={building}>
174
+ {lr.pickYou}
175
+ </Button>
176
+ <Button
177
+ type="button"
178
+ variant="ghost"
179
+ size="sm"
180
+ disabled={building}
181
+ onClick={() => onBuild(null)}
182
+ >
183
+ {lr.pickNone}
184
+ </Button>
185
+ <Button
186
+ type="button"
187
+ className="ml-auto"
188
+ disabled={!selected || building}
189
+ onClick={() => selected && onBuild({ id: selected, knobs })}
190
+ >
191
+ {lr.pickStart}
192
+ </Button>
193
+ </div>
194
+ </div>
195
+ );
196
+ }
197
+
198
+ function knobLabelKey(key: KnobKey): 'knobFormal' | 'knobBright' | 'knobMotion' {
199
+ if (key === 'formal') return 'knobFormal';
200
+ if (key === 'bright') return 'knobBright';
201
+ return 'knobMotion';
202
+ }
203
+
204
+ function PickColumn({
205
+ template,
206
+ content,
207
+ knobs,
208
+ selected,
209
+ onSelect,
210
+ }: {
211
+ template: TemplateMeta;
212
+ content: PreviewContent;
213
+ knobs: TemplateKnobValues;
214
+ selected: boolean;
215
+ onSelect: () => void;
216
+ }) {
217
+ const lr = useLrText().outline;
218
+ const preview = usePreview(template.id);
219
+ const design = useMemo(
220
+ () => applyKnobs(template.design, template.knobs, knobs),
221
+ [template, knobs],
222
+ );
223
+ const vars = designToCssVars(design);
224
+
225
+ return (
226
+ // biome-ignore lint/a11y/useSemanticElements: the column is a preview card, not a plain radio
227
+ <button
228
+ type="button"
229
+ role="radio"
230
+ aria-checked={selected}
231
+ data-lr-pick-column={template.id}
232
+ onClick={onSelect}
233
+ className={cn(
234
+ 'block w-full overflow-hidden rounded-[14px] border-2 bg-card p-2.5 text-left outline-none transition-colors',
235
+ 'focus-visible:ring-2 focus-visible:ring-ring/40',
236
+ selected
237
+ ? 'border-[var(--lr-focus)] shadow-[var(--lr-shadow-2)]'
238
+ : 'border-border hover:border-[var(--lr-text-3)]',
239
+ )}
240
+ >
241
+ <div
242
+ data-lr-pick-design
243
+ style={vars}
244
+ className="aspect-video overflow-hidden rounded-[8px] border border-border bg-white"
245
+ >
246
+ <SlideCanvas flat freezeMotion design={design}>
247
+ <SlidePageProvider index={0} total={2}>
248
+ {preview ? <preview.CoverPreview {...content.cover} /> : null}
249
+ </SlidePageProvider>
250
+ </SlideCanvas>
251
+ </div>
252
+ <div
253
+ data-lr-pick-design
254
+ style={vars}
255
+ className="mt-2 aspect-video overflow-hidden rounded-[8px] border border-border bg-white"
256
+ >
257
+ <SlideCanvas flat freezeMotion design={design}>
258
+ <SlidePageProvider index={1} total={2}>
259
+ {preview ? (
260
+ <preview.DataPreview
261
+ title={content.data.title}
262
+ value={content.data.sample ? undefined : content.data.value}
263
+ unit={content.data.sample ? undefined : content.data.unit}
264
+ caption={content.data.caption}
265
+ context={content.data.context}
266
+ />
267
+ ) : null}
268
+ </SlidePageProvider>
269
+ </SlideCanvas>
270
+ </div>
271
+ {content.data.sample && (
272
+ <p className="mt-1 text-right text-[11.5px] text-muted-foreground">{lr.pickSample}</p>
273
+ )}
274
+ <div className="mt-2 px-1 pb-1">
275
+ <p className="truncate text-[13.5px] font-semibold">{template.name}</p>
276
+ <p className="mt-0.5 line-clamp-2 text-[12px] leading-4 text-muted-foreground">
277
+ {template.reason}
278
+ </p>
279
+ </div>
280
+ </button>
281
+ );
282
+ }
@@ -14,8 +14,13 @@ const paths = (routes: unknown[]) =>
14
14
  routes.filter(Boolean).map((r) => (r as ReactElement<{ path: string }>).props.path);
15
15
 
16
16
  describe('lemonRiverRoutes', () => {
17
- it('adds the board, the outline and the not-found page', () => {
18
- expect(paths(lemonRiverRoutes())).toEqual(['/s/:slideId/board', '/s/:slideId/outline', '*']);
17
+ it('adds the board, the outline, the template demo and the not-found page', () => {
18
+ expect(paths(lemonRiverRoutes())).toEqual([
19
+ '/s/:slideId/board',
20
+ '/s/:slideId/outline',
21
+ '/template-demo/:templateId',
22
+ '*',
23
+ ]);
19
24
  });
20
25
 
21
26
  it('drops the pages whose feature is off', () => {
@@ -26,12 +31,19 @@ describe('lemonRiverRoutes', () => {
26
31
  });
27
32
 
28
33
  describe('lemonRiverShellRoutes', () => {
29
- it('puts our home and the guided flow first, then settings and trash', () => {
30
- expect(paths(lemonRiverShellRoutes())).toEqual(['/', '/new', '/settings', '/trash']);
34
+ it('puts our home and the guided flow first, then settings, templates and trash', () => {
35
+ expect(paths(lemonRiverShellRoutes())).toEqual([
36
+ '/',
37
+ '/new',
38
+ '/settings',
39
+ '/templates',
40
+ '/trash',
41
+ ]);
31
42
  });
32
43
 
33
44
  it('leaves out the pages whose feature is off', () => {
34
- vi.mocked(isFeatureEnabled).mockImplementation((id) => id !== 'trash');
45
+ vi.mocked(isFeatureEnabled).mockImplementation((id) => id !== 'trash' && id !== 'templates');
35
46
  expect(paths(lemonRiverShellRoutes())).toEqual(['/', '/new', '/settings']);
47
+ vi.mocked(isFeatureEnabled).mockReturnValue(true);
36
48
  });
37
49
  });
@@ -13,6 +13,12 @@ const DescribePage = lazy(() =>
13
13
  const OutlinePage = lazy(() =>
14
14
  import('./outline/outline-page').then((m) => ({ default: m.OutlineView })),
15
15
  );
16
+ const TemplateDemoPage = lazy(() =>
17
+ import('./templates/demo-page').then((m) => ({ default: m.TemplateDemoPage })),
18
+ );
19
+ const TemplatesPage = lazy(() =>
20
+ import('./templates/library-page').then((m) => ({ default: m.TemplatesPage })),
21
+ );
16
22
 
17
23
  /** Routes of our own, outside the home shell. Placed before the official catch-all. */
18
24
  export function lemonRiverRoutes() {
@@ -39,6 +45,17 @@ export function lemonRiverRoutes() {
39
45
  }
40
46
  />
41
47
  ),
48
+ isFeatureEnabled('templates') && (
49
+ <Route
50
+ key="template-demo"
51
+ path="/template-demo/:templateId"
52
+ element={
53
+ <Suspense fallback={null}>
54
+ <TemplateDemoPage />
55
+ </Suspense>
56
+ }
57
+ />
58
+ ),
42
59
  <Route key="not-found" path="*" element={<NotFound />} />,
43
60
  ];
44
61
  }
@@ -61,6 +78,17 @@ export function lemonRiverShellRoutes() {
61
78
  isFeatureEnabled('settings') && (
62
79
  <Route key="settings" path="/settings" element={<SettingsPage />} />
63
80
  ),
81
+ isFeatureEnabled('templates') && (
82
+ <Route
83
+ key="templates"
84
+ path="/templates"
85
+ element={
86
+ <Suspense fallback={null}>
87
+ <TemplatesPage />
88
+ </Suspense>
89
+ }
90
+ />
91
+ ),
64
92
  isFeatureEnabled('trash') && <Route key="trash" path="/trash" element={<TrashPage />} />,
65
93
  ];
66
94
  }