@lemonriver/core 1.1.0 → 1.2.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 (92) hide show
  1. package/dist/{build-Dm7gVRhb.js → build-CSkdswfd.js} +1 -1
  2. package/dist/cli/bin.js +5 -5
  3. package/dist/{config-CubOIzrs.js → config-C5-myPY6.js} +129 -2
  4. package/dist/{dev-DgLeXPqp.js → dev-DHtYH8sw.js} +2 -2
  5. package/dist/{mcp-CjYDzcJa.js → mcp-B2UeO1un.js} +1 -1
  6. package/dist/{preview-CxXQpPk5.js → preview-C1B6-umF.js} +1 -1
  7. package/dist/{update-b1dSg_FW.js → update-DzL8fpcI.js} +1 -1
  8. package/dist/vite/index.js +1 -1
  9. package/package.json +5 -2
  10. package/release-notes.json +19 -0
  11. package/src/app/lemonriver/chrome/app-chrome.tsx +52 -0
  12. package/src/app/lemonriver/chrome/sidebar-extras.tsx +8 -1
  13. package/src/app/lemonriver/feedback/dialog.tsx +222 -0
  14. package/src/app/lemonriver/feedback/export.ts +21 -2
  15. package/src/app/lemonriver/feedback/first-success.ts +30 -0
  16. package/src/app/lemonriver/feedback/install.ts +18 -0
  17. package/src/app/lemonriver/feedback/model.ts +88 -0
  18. package/src/app/lemonriver/help/help-page.tsx +16 -1
  19. package/src/app/lemonriver/links.ts +16 -0
  20. package/src/app/lemonriver/settings/backup-section.tsx +13 -0
  21. package/src/app/lemonriver/settings/settings-page.tsx +20 -0
  22. package/src/app/lemonriver/share/editor-share.tsx +6 -3
  23. package/src/app/lemonriver/share/share-dialog.tsx +2 -0
  24. package/src/app/lemonriver/text/en.ts +45 -0
  25. package/src/app/lemonriver/text/es.ts +42 -0
  26. package/src/app/lemonriver/text/ja.ts +41 -0
  27. package/src/app/lemonriver/text/types.ts +44 -0
  28. package/src/app/lemonriver/text/zh-cn.ts +45 -0
  29. package/src/app/lemonriver/text/zh-tw.ts +45 -0
  30. package/src/app/lemonriver/theme/pages.ts +4 -0
  31. package/src/app/lemonriver/update/release-notes.ts +22 -0
  32. package/src/app/lemonriver/update/update-prompt.tsx +28 -4
  33. package/src/app/components/note-markdown.test.tsx +0 -42
  34. package/src/app/components/thumbnail-rail-scroll.test.ts +0 -60
  35. package/src/app/lemonriver/agent-prefs/prefs.test.ts +0 -173
  36. package/src/app/lemonriver/backup/guide.test.ts +0 -45
  37. package/src/app/lemonriver/backup/model.test.ts +0 -108
  38. package/src/app/lemonriver/backup/places.test.ts +0 -154
  39. package/src/app/lemonriver/board/blocks/classify.test.ts +0 -209
  40. package/src/app/lemonriver/board/layout.test.ts +0 -245
  41. package/src/app/lemonriver/board/model/agent-tasks.test.ts +0 -200
  42. package/src/app/lemonriver/board/model/apply-prompt.test.ts +0 -121
  43. package/src/app/lemonriver/board/model/cards.test.ts +0 -332
  44. package/src/app/lemonriver/board/model/changes.test.ts +0 -244
  45. package/src/app/lemonriver/board/model/filter.test.ts +0 -50
  46. package/src/app/lemonriver/board/model/history.test.ts +0 -71
  47. package/src/app/lemonriver/board/model/restructure.test.ts +0 -205
  48. package/src/app/lemonriver/board/model/self-check.test.ts +0 -329
  49. package/src/app/lemonriver/board/model/structure.test.ts +0 -350
  50. package/src/app/lemonriver/board/model/timing.test.ts +0 -113
  51. package/src/app/lemonriver/features.test.ts +0 -49
  52. package/src/app/lemonriver/feedback/pending-toast.test.ts +0 -44
  53. package/src/app/lemonriver/feedback/upload.test.ts +0 -26
  54. package/src/app/lemonriver/help/model.test.ts +0 -179
  55. package/src/app/lemonriver/home/brief.test.ts +0 -38
  56. package/src/app/lemonriver/home/drafts.test.ts +0 -23
  57. package/src/app/lemonriver/home/sorting.test.ts +0 -24
  58. package/src/app/lemonriver/home/time.test.ts +0 -33
  59. package/src/app/lemonriver/outline/files.test.ts +0 -90
  60. package/src/app/lemonriver/outline/model.test.ts +0 -751
  61. package/src/app/lemonriver/public-links.test.ts +0 -32
  62. package/src/app/lemonriver/routes.test.tsx +0 -54
  63. package/src/app/lemonriver/share/codes.test.ts +0 -49
  64. package/src/app/lemonriver/share/compare.test.ts +0 -199
  65. package/src/app/lemonriver/share/folder.test.ts +0 -42
  66. package/src/app/lemonriver/share/guide.test.ts +0 -78
  67. package/src/app/lemonriver/share/naming.test.ts +0 -70
  68. package/src/app/lemonriver/share/paths.test.ts +0 -116
  69. package/src/app/lemonriver/share/pdf.test.ts +0 -79
  70. package/src/app/lemonriver/templates/knobs.test.ts +0 -62
  71. package/src/app/lemonriver/templates/model.test.ts +0 -175
  72. package/src/app/lemonriver/templates/preview-content.test.ts +0 -117
  73. package/src/app/lemonriver/templates/recommend.test.ts +0 -71
  74. package/src/app/lemonriver/text/text.test.ts +0 -90
  75. package/src/app/lemonriver/theme/pages.test.ts +0 -74
  76. package/src/app/lemonriver/theme/themes.test.ts +0 -18
  77. package/src/app/lemonriver/trash/api.test.ts +0 -19
  78. package/src/app/lemonriver/update/prompt.test.ts +0 -84
  79. package/src/app/lemonriver/update/version.test.ts +0 -14
  80. package/src/app/lib/asset-filter.test.ts +0 -176
  81. package/src/app/lib/inspector/fiber.test.ts +0 -154
  82. package/src/app/lib/inspector/geometry.test.ts +0 -324
  83. package/src/app/lib/inspector/text-edit-timeline.test.ts +0 -121
  84. package/src/app/lib/note-markdown.test.ts +0 -147
  85. package/src/app/lib/pptx/css.test.ts +0 -205
  86. package/src/app/lib/pptx/ooxml.test.ts +0 -199
  87. package/src/app/lib/pptx/text-lines.test.ts +0 -82
  88. package/src/app/lib/print-ready.test.ts +0 -32
  89. package/src/app/lib/sdk.test.ts +0 -13
  90. package/src/app/lib/transition.test.ts +0 -31
  91. package/src/app/lib/use-document-title.test.ts +0 -14
  92. package/src/app/lib/utils.test.ts +0 -49
@@ -1,79 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { buildImagePdf, jpegSize, PDF_PAGE_HEIGHT, PDF_PAGE_WIDTH, utf16BeHex } from './pdf';
3
-
4
- const latin1 = (bytes: Uint8Array) => Buffer.from(bytes).toString('latin1');
5
- const jpeg = (base64: string) => new Uint8Array(Buffer.from(base64, 'base64'));
6
-
7
- // Two real 2x2 JPEGs, so the builder reads their true size like it will in a package.
8
- const JPEG_WHITE = jpeg(
9
- '/9j/4AAQSkZJRgABAQAASABIAAD/4QBMRXhpZgAATU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAAqADAAQAAAABAAAAAgAAAAD/7QA4UGhvdG9zaG9wIDMuMAA4QklNBAQAAAAAAAA4QklNBCUAAAAAABDUHYzZjwCyBOmACZjs+EJ+/8AAEQgAAgACAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uLj5OXm5+jp6vLz9PX29/j5+v/bAEMAAgICAgICAwICAwUDAwMFBgUFBQUGCAYGBgYGCAoICAgICAgKCgoKCgoKCgwMDAwMDA4ODg4ODw8PDw8PDw8PD//bAEMBAgICBAQEBwQEBxALCQsQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEP/dAAQAAf/aAAwDAQACEQMRAD8A/fyiiigD/9k=',
10
- );
11
- const JPEG_BLACK = jpeg(
12
- '/9j/4AAQSkZJRgABAQAASABIAAD/4QBMRXhpZgAATU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAAqADAAQAAAABAAAAAgAAAAD/7QA4UGhvdG9zaG9wIDMuMAA4QklNBAQAAAAAAAA4QklNBCUAAAAAABDUHYzZjwCyBOmACZjs+EJ+/8AAEQgAAgACAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uLj5OXm5+jp6vLz9PX29/j5+v/bAEMAAgICAgICAwICAwUDAwMFBgUFBQUGCAYGBgYGCAoICAgICAgKCgoKCgoKCgwMDAwMDA4ODg4ODw8PDw8PDw8PD//bAEMBAgICBAQEBwQEBxALCQsQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEP/dAAQAAf/aAAwDAQACEQMRAD8A/E+iiiugD//Z',
13
- );
14
-
15
- function page(bytes: Uint8Array) {
16
- return { jpeg: bytes, width: 2, height: 2 };
17
- }
18
-
19
- describe('buildImagePdf', () => {
20
- const pdf = buildImagePdf([page(JPEG_WHITE), page(JPEG_BLACK)], { title: '季度报告' });
21
- const text = latin1(pdf);
22
-
23
- it('writes one page per image, at the print size', () => {
24
- expect(text.match(/\/Type \/Page\b/g)).toHaveLength(2);
25
- expect(text).toContain(`/MediaBox [0 0 ${PDF_PAGE_WIDTH} ${PDF_PAGE_HEIGHT}]`);
26
- expect(PDF_PAGE_WIDTH).toBe(1440);
27
- expect(PDF_PAGE_HEIGHT).toBe(810);
28
- expect(text).toContain('%PDF-');
29
- });
30
-
31
- it('points every xref entry at its object', () => {
32
- const start = text.lastIndexOf('\nxref\n');
33
- const lines = text.slice(start + 1).split('\n');
34
- const count = Number(lines[1].split(' ')[1]);
35
- expect(count).toBeGreaterThan(3);
36
- for (let id = 1; id < count; id++) {
37
- const offset = Number(lines[2 + id].slice(0, 10));
38
- expect(text.slice(offset, offset + String(id).length + 2), `object ${id}`).toBe(`${id} 0`);
39
- expect(text.slice(offset).startsWith(`${id} 0 obj`), `object ${id} header`).toBe(true);
40
- }
41
- });
42
-
43
- it('declares each image stream with exactly its own byte length', () => {
44
- for (const bytes of [JPEG_WHITE, JPEG_BLACK]) {
45
- const at = pdf.findIndex(
46
- (byte, i) => byte === 0xff && bytes.every((b, k) => pdf[i + k] === b),
47
- );
48
- expect(at).toBeGreaterThan(0);
49
- const before = latin1(pdf.slice(Math.max(0, at - 220), at));
50
- const match = /\/Length (\d+) >>\nstream\n$/.exec(before);
51
- expect(match, 'image stream header').not.toBeNull();
52
- expect(Number(match?.[1])).toBe(bytes.length);
53
- expect(latin1(pdf.slice(at + bytes.length, at + bytes.length + 10))).toBe('\nendstream');
54
- }
55
- });
56
-
57
- it('reads the frame header of a real JPEG', () => {
58
- expect(jpegSize(JPEG_WHITE)).toEqual({ width: 2, height: 2 });
59
- });
60
-
61
- it('refuses a page that is not a JPEG', () => {
62
- const png = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 1, 2, 3]);
63
- expect(() => buildImagePdf([{ jpeg: png, width: 2, height: 2 }], { title: 'x' })).toThrow(
64
- /page 1 is not a JPEG/,
65
- );
66
- });
67
-
68
- it('refuses a page whose size does not match its JPEG', () => {
69
- expect(() =>
70
- buildImagePdf([{ jpeg: JPEG_BLACK, width: 1920, height: 1080 }], { title: 'x' }),
71
- ).toThrow(/is 2x2, not 1920x1080/);
72
- });
73
-
74
- it('writes the title as UTF-16BE with a byte-order mark', () => {
75
- expect(utf16BeHex('季度报告')).toBe('FEFF5B635EA662A5544A');
76
- expect(text).toContain('/Title <FEFF5B635EA662A5544A>');
77
- expect(text).toContain('/Producer (LemonRiver)');
78
- });
79
- });
@@ -1,62 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import type { DesignSystem } from '../../lib/design';
3
- import { applyKnobs, knobFlags } from './knobs';
4
- import type { TemplateKnobs } from './model';
5
-
6
- const design: DesignSystem = {
7
- palette: { bg: '#FFFFFF', text: '#111111', accent: '#AA0000' },
8
- fonts: { display: 'Display Sans', body: 'Body Sans' },
9
- typeScale: { hero: 400, body: 30 },
10
- radius: 0,
11
- };
12
-
13
- const knobs: TemplateKnobs = {
14
- formal: {
15
- left: { label: '正式', design: { fonts: { display: 'Songti SC' }, radius: 0 } },
16
- right: { label: '活泼', design: { fonts: { display: 'PingFang SC' }, radius: 12 } },
17
- },
18
- bright: {
19
- left: { label: '素', design: { palette: { accent: '#333333' } } },
20
- right: { label: '亮', design: { palette: { accent: '#FF6600' } } },
21
- },
22
- motion: {
23
- left: { label: '安静', flags: { motion: 'still' } },
24
- right: { label: '活跃', flags: { motion: 'lively' } },
25
- },
26
- };
27
-
28
- describe('applyKnobs', () => {
29
- it('uses the left and right formal ends and keeps the template design in the middle', () => {
30
- expect(applyKnobs(design, knobs, { formal: 0.2 })).toMatchObject({
31
- fonts: { display: 'Songti SC' },
32
- radius: 0,
33
- });
34
- expect(applyKnobs(design, knobs, { formal: 0.5 })).toEqual(design);
35
- expect(applyKnobs(design, knobs, { formal: 0.8 })).toMatchObject({
36
- fonts: { display: 'PingFang SC' },
37
- radius: 12,
38
- });
39
- });
40
-
41
- it('uses the left and right bright ends and keeps the template design in the middle', () => {
42
- expect(applyKnobs(design, knobs, { bright: 0.2 }).palette.accent).toBe('#333333');
43
- expect(applyKnobs(design, knobs, { bright: 0.5 })).toEqual(design);
44
- expect(applyKnobs(design, knobs, { bright: 0.8 }).palette.accent).toBe('#FF6600');
45
- });
46
-
47
- it('uses the left and right motion ends through the flags', () => {
48
- expect(knobFlags(knobs, { motion: 0.2 })).toEqual({ motion: 'still' });
49
- expect(knobFlags(knobs, { motion: 0.5 })).toEqual({});
50
- expect(knobFlags(knobs, { motion: 0.8 })).toEqual({ motion: 'lively' });
51
- });
52
-
53
- it('leaves a group the template does not define alone', () => {
54
- const partial: Partial<TemplateKnobs> = { formal: knobs.formal, motion: knobs.motion };
55
- expect(applyKnobs(design, partial, { bright: 0.9 })).toEqual(design);
56
- expect(knobFlags(partial, { bright: 0.9 })).toEqual({});
57
- });
58
-
59
- it('treats a missing value as the middle', () => {
60
- expect(applyKnobs(design, knobs)).toEqual(design);
61
- });
62
- });
@@ -1,175 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import {
3
- applyKnobs,
4
- designSnippet,
5
- knobFlags,
6
- sanitizeAppliedTemplate,
7
- sanitizeKnobValues,
8
- sanitizeTemplate,
9
- } from './model.ts';
10
-
11
- const design = {
12
- palette: { bg: '#f4f1ea', text: '#1a1a1a', accent: '#d9480f' },
13
- fonts: { display: '"Songti SC", serif', body: '"PingFang SC", sans-serif' },
14
- typeScale: { hero: 420, body: 30 },
15
- radius: 0,
16
- };
17
-
18
- const knob = (label: string) => ({
19
- left: { label: `${label}左`, design: { palette: { accent: '#2244aa' } } },
20
- right: { label: `${label}右`, flags: { motion: 'lively' } },
21
- });
22
-
23
- const raw = () => ({
24
- id: 'board-report',
25
- name: '董事会报告',
26
- occasions: ['report', 'review'],
27
- audience: '董事会成员与高管',
28
- object: '正式董事会报告',
29
- reason: '数字和审批一目了然',
30
- accent: '最新值与计划的差额',
31
- design,
32
- knobs: { formal: knob('正式'), bright: knob('亮'), motion: knob('动效') },
33
- skeletons: ['cover', 'overview', 'ask', 'end'],
34
- fonts: [],
35
- source: 'northfold',
36
- });
37
-
38
- describe('sanitizeTemplate', () => {
39
- it('accepts a complete template and trims its text', () => {
40
- const input = raw();
41
- input.name = ' 董事会报告 ';
42
- const read = sanitizeTemplate(input, 'board-report');
43
- expect(read.ok).toBe(true);
44
- if (!read.ok) return;
45
- expect(read.template.name).toBe('董事会报告');
46
- expect(read.template.occasions).toEqual(['report', 'review']);
47
- expect(read.template.source).toBe('northfold');
48
- });
49
-
50
- it('drops a template without occasions', () => {
51
- const input: Record<string, unknown> = raw();
52
- delete input.occasions;
53
- const read = sanitizeTemplate(input, 'board-report');
54
- expect(read).toEqual({ ok: false, reason: 'missing occasions' });
55
- });
56
-
57
- it('drops an empty occasions list', () => {
58
- const read = sanitizeTemplate({ ...raw(), occasions: [] }, 'board-report');
59
- expect(read.ok).toBe(false);
60
- });
61
-
62
- it('drops an occasion outside the seven', () => {
63
- const read = sanitizeTemplate({ ...raw(), occasions: ['pitch', 'wedding'] }, 'board-report');
64
- expect(read).toEqual({ ok: false, reason: 'unknown occasion "wedding"' });
65
- });
66
-
67
- it('drops an unknown skeleton', () => {
68
- const read = sanitizeTemplate({ ...raw(), skeletons: ['cover', 'carousel'] }, 'board-report');
69
- expect(read).toEqual({ ok: false, reason: 'unknown skeleton "carousel"' });
70
- });
71
-
72
- it('drops an id that disagrees with its folder', () => {
73
- const read = sanitizeTemplate(raw(), 'other-folder');
74
- expect(read.ok).toBe(false);
75
- if (read.ok) return;
76
- expect(read.reason).toContain('does not match the folder');
77
- });
78
-
79
- it('drops an id with path characters', () => {
80
- const read = sanitizeTemplate({ ...raw(), id: '../escape' }, '../escape');
81
- expect(read.ok).toBe(false);
82
- });
83
-
84
- it('drops a design missing an accent colour', () => {
85
- const read = sanitizeTemplate(
86
- { ...raw(), design: { ...design, palette: { bg: '#fff', text: '#000' } } },
87
- 'board-report',
88
- );
89
- expect(read).toEqual({ ok: false, reason: 'missing or malformed design' });
90
- });
91
-
92
- it('drops knobs missing one of the three', () => {
93
- const knobs = raw().knobs as Record<string, unknown>;
94
- const read = sanitizeTemplate(
95
- { ...raw(), knobs: { formal: knobs.formal, bright: knobs.bright } },
96
- 'board-report',
97
- );
98
- expect(read).toEqual({ ok: false, reason: 'missing or malformed knobs' });
99
- });
100
-
101
- it('treats an absent source as null', () => {
102
- const input: Record<string, unknown> = raw();
103
- delete input.source;
104
- const read = sanitizeTemplate(input, 'board-report');
105
- expect(read.ok).toBe(true);
106
- if (read.ok) expect(read.template.source).toBeNull();
107
- });
108
-
109
- it('reads font licence pairs', () => {
110
- const read = sanitizeTemplate(
111
- {
112
- ...raw(),
113
- fonts: [{ file: 'fonts/Pixel.ttf', license: 'fonts/OFL.txt' }],
114
- },
115
- 'board-report',
116
- );
117
- expect(read.ok).toBe(true);
118
- if (read.ok) expect(read.template.fonts).toHaveLength(1);
119
- });
120
-
121
- it('rejects a font entry without a licence', () => {
122
- const read = sanitizeTemplate(
123
- { ...raw(), fonts: [{ file: 'fonts/Pixel.ttf' }] },
124
- 'board-report',
125
- );
126
- expect(read.ok).toBe(false);
127
- });
128
- });
129
-
130
- describe('knobs', () => {
131
- const read = sanitizeTemplate(raw(), 'board-report');
132
- if (!read.ok) throw new Error('fixture template is invalid');
133
-
134
- it('keeps the base design in the middle', () => {
135
- expect(applyKnobs(read.template.design, read.template.knobs, { formal: 0.5 })).toEqual(design);
136
- });
137
-
138
- it('leans left below a third', () => {
139
- const out = applyKnobs(read.template.design, read.template.knobs, { formal: 0.1 });
140
- expect(out.palette.accent).toBe('#2244aa');
141
- expect(out.palette.bg).toBe(design.palette.bg);
142
- });
143
-
144
- it('leans right above two thirds and reports its flags', () => {
145
- const out = applyKnobs(read.template.design, read.template.knobs, { motion: 0.9 });
146
- expect(out.palette.accent).toBe(design.palette.accent);
147
- expect(knobFlags(read.template.knobs, { motion: 0.9 })).toEqual({ motion: 'lively' });
148
- });
149
-
150
- it('keeps knob values inside [0, 1]', () => {
151
- expect(sanitizeKnobValues({ formal: 2, bright: -0.2, motion: 0.4 })).toEqual({
152
- motion: 0.4,
153
- });
154
- });
155
- });
156
-
157
- describe('applied record', () => {
158
- it('reads back what the board stores', () => {
159
- expect(
160
- sanitizeAppliedTemplate({ id: 'board-report', knobs: { formal: 0.8 }, appliedAt: 12 }),
161
- ).toEqual({ id: 'board-report', knobs: { formal: 0.8 }, appliedAt: 12 });
162
- });
163
-
164
- it('drops a record without a template id', () => {
165
- expect(sanitizeAppliedTemplate({ knobs: {}, appliedAt: 12 })).toBeNull();
166
- });
167
- });
168
-
169
- describe('designSnippet', () => {
170
- it('writes a design constant the deck can paste', () => {
171
- const snippet = designSnippet(design);
172
- expect(snippet.startsWith('export const design: DesignSystem = {')).toBe(true);
173
- expect(snippet).toContain('"accent": "#d9480f"');
174
- });
175
- });
@@ -1,117 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { type PreviewOutline, previewContent } from './preview-content.ts';
3
-
4
- const outline = (over: Partial<PreviewOutline> = {}): PreviewOutline => ({
5
- brief: '给董事会讲第三季度的经营情况。收入超了计划。',
6
- audience: '董事会',
7
- items: [
8
- { title: '第三季度经营情况', kind: 'cover' },
9
- { title: '收入 4.82 亿,超计划 1,700 万', kind: 'kpi' },
10
- { title: '增长来自哪里', kind: 'list' },
11
- ],
12
- ...over,
13
- });
14
-
15
- const NOW = new Date('2026-10-31T09:00:00+08:00');
16
-
17
- describe('previewContent', () => {
18
- it('draws the cover from the outline and the date and audience line', () => {
19
- const { cover } = previewContent(outline(), { now: NOW, locale: 'zh-CN' });
20
- expect(cover.title).toBe('第三季度经营情况');
21
- expect(cover.subtitle).toBe('给董事会讲第三季度的经营情况。');
22
- expect(cover.meta).toContain('2026');
23
- expect(cover.meta).toContain('董事会');
24
- });
25
-
26
- it('leaves the audience out of the meta line when it is empty', () => {
27
- const { cover } = previewContent(outline({ audience: '' }), { now: NOW, locale: 'zh-CN' });
28
- expect(cover.meta).not.toContain('·');
29
- });
30
-
31
- it.each([
32
- ['收入 4.82 亿', '4.82', '亿'],
33
- ['预算 1,700 万', '1,700', '万'],
34
- ['毛利率 32%', '32', '%'],
35
- ['效率提升 3.2 倍', '3.2', '倍'],
36
- ])('reads the number and unit out of %s', (title, value, unit) => {
37
- const page = { title, kind: 'kpi' };
38
- expect(previewContent(outline({ items: [page] })).data).toMatchObject({ value, unit });
39
- });
40
-
41
- it('takes the number from the brief when the page title has none', () => {
42
- const data = previewContent(
43
- outline({
44
- items: [
45
- { title: '第三季度经营情况', kind: 'cover' },
46
- { title: '这一季度的成绩', kind: 'kpi' },
47
- ],
48
- }),
49
- ).data;
50
- expect(data.value).toBe('');
51
- const withNumber = previewContent(
52
- outline({
53
- brief: '给董事会讲第三季度的经营情况,收入 4.82 亿。',
54
- items: [
55
- { title: '第三季度经营情况', kind: 'cover' },
56
- { title: '这一季度的成绩', kind: 'kpi' },
57
- ],
58
- }),
59
- ).data;
60
- expect(withNumber).toMatchObject({ value: '4.82', unit: '亿', sample: false });
61
- });
62
-
63
- it('marks the number as a sample when the outline has none at all', () => {
64
- const data = previewContent(
65
- outline({
66
- brief: '讲讲我们这三个月的进展。',
67
- items: [
68
- { title: '季度进展', kind: 'cover' },
69
- { title: '这一季度的成绩', kind: 'kpi' },
70
- ],
71
- }),
72
- ).data;
73
- expect(data.sample).toBe(true);
74
- expect(data.value).toBe('');
75
- });
76
-
77
- it('truncates a title that would not fit the preview', () => {
78
- const long = '第三季度经营情况与下一阶段的重点工作和资源安排建议';
79
- const { cover, data } = previewContent(
80
- outline({
81
- items: [
82
- { title: long, kind: 'cover' },
83
- { title: `${long} 4.82 亿`, kind: 'kpi' },
84
- ],
85
- }),
86
- );
87
- expect(cover.title).toHaveLength(24);
88
- expect(cover.title.endsWith('…')).toBe(true);
89
- expect(data.title).toHaveLength(24);
90
- });
91
-
92
- it.each([
93
- ['第三季度经营情况', 'Q3'],
94
- ['Q4 复盘', 'Q4'],
95
- ['FY26 全年计划', 'FY26'],
96
- ['2027 财年的目标', 'FY27'],
97
- ['2026 年经营情况', '2026'],
98
- ])('takes the mark from a title that names %s', (title, mark) => {
99
- const made = outline({ items: [{ title, kind: 'cover' }], brief: '没有别的线索。' });
100
- expect(previewContent(made).cover.mark).toBe(mark);
101
- });
102
-
103
- it('falls back to the brief for the mark, and then leaves it empty', () => {
104
- const fromBrief = outline({
105
- items: [{ title: '经营情况', kind: 'cover' }],
106
- brief: '给董事会讲第三季度。',
107
- });
108
- expect(previewContent(fromBrief).cover.mark).toBe('Q3');
109
-
110
- const none = outline({
111
- items: [{ title: '经营情况', kind: 'cover' }],
112
- brief: '给董事会讲这半年的进展。',
113
- });
114
- expect(previewContent(none).cover.mark).toBe('');
115
- expect(previewContent(none).cover.brand).toBe('');
116
- });
117
- });
@@ -1,71 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import type { OccasionId } from './model.ts';
3
- import { type Recommendable, recommendTemplates } from './recommend.ts';
4
-
5
- const template = (id: string, occasions: OccasionId[]): Recommendable => ({
6
- id,
7
- occasions,
8
- reason: `why ${id}`,
9
- });
10
-
11
- const LIBRARY: Recommendable[] = [
12
- template('a-pitch', ['pitch']),
13
- template('b-report', ['report']),
14
- template('c-launch', ['launch']),
15
- template('d-review', ['review']),
16
- template('e-both', ['launch', 'report']),
17
- ];
18
-
19
- const ids = (picks: Recommendable[]) => picks.map((pick) => pick.id);
20
-
21
- describe('recommendTemplates', () => {
22
- it('puts the templates whose first occasion matches first', () => {
23
- const { picks, reasons } = recommendTemplates(LIBRARY, { occasion: 'report' });
24
- expect(ids(picks)).toEqual(['b-report', 'e-both', 'a-pitch']);
25
- expect(reasons).toEqual(['why b-report', 'why e-both', 'why a-pitch']);
26
- });
27
-
28
- it('fills from the report occasion, then any template, when fewer than three match', () => {
29
- const narrow = [template('x', ['review']), ...LIBRARY];
30
- const { picks } = recommendTemplates(narrow, { occasion: 'review' });
31
- expect(ids(picks)).toEqual(['x', 'd-review', 'b-report']);
32
- expect(picks).toHaveLength(3);
33
- });
34
-
35
- it('takes one template per occasion when the user is unsure', () => {
36
- const { picks } = recommendTemplates(LIBRARY, { occasion: null });
37
- expect(ids(picks)).toEqual(['a-pitch', 'b-report', 'c-launch']);
38
- });
39
-
40
- it('leaves out the ones already shown and restarts once all have been seen', () => {
41
- const first = recommendTemplates(LIBRARY, { occasion: 'report' });
42
- const next = recommendTemplates(LIBRARY, {
43
- occasion: 'report',
44
- exclude: ids(first.picks),
45
- });
46
- expect(ids(next.picks)).toEqual(['c-launch', 'd-review']);
47
-
48
- const again = recommendTemplates(LIBRARY, {
49
- occasion: 'report',
50
- exclude: ['a-pitch', 'b-report', 'c-launch', 'd-review', 'e-both'],
51
- });
52
- expect(ids(again.picks)).toEqual(ids(first.picks));
53
- });
54
-
55
- it('returns the one template a one-template library has, without padding', () => {
56
- const single = [template('only', ['report'])];
57
- expect(recommendTemplates(single, { occasion: 'report' }).picks).toHaveLength(1);
58
- expect(recommendTemplates(single, { occasion: null }).picks).toHaveLength(1);
59
- expect(ids(recommendTemplates(single, { occasion: null }).picks)).toEqual(['only']);
60
- });
61
-
62
- it('never repeats a template across the two pools', () => {
63
- const overlapping = [
64
- template('one', ['pitch', 'report', 'launch', 'review']),
65
- template('two', ['report']),
66
- template('three', ['report']),
67
- ];
68
- const { picks } = recommendTemplates(overlapping, { occasion: 'report' });
69
- expect(new Set(ids(picks)).size).toBe(picks.length);
70
- });
71
- });
@@ -1,90 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { format, plural } from '../../../locale/format';
3
- import { en } from './en';
4
- import { es } from './es';
5
- import { ja } from './ja';
6
- import { zhCN } from './zh-cn';
7
- import { zhTW } from './zh-tw';
8
-
9
- const LANGS = { en, es, ja, zhCN, zhTW };
10
-
11
- function leaves(value: unknown, prefix = ''): [string, unknown][] {
12
- if (!value || typeof value !== 'object') return [[prefix, value]];
13
- return Object.entries(value).flatMap(([key, child]) =>
14
- leaves(child, prefix ? `${prefix}.${key}` : key),
15
- );
16
- }
17
-
18
- describe('LemonRiver text', () => {
19
- it('has the same keys in every language as English', () => {
20
- const english = leaves(en)
21
- .map(([key]) => key)
22
- .sort();
23
- for (const [name, text] of Object.entries(LANGS)) {
24
- expect(
25
- leaves(text)
26
- .map(([key]) => key)
27
- .sort(),
28
- name,
29
- ).toEqual(english);
30
- }
31
- });
32
-
33
- it('has no empty strings', () => {
34
- for (const [name, text] of Object.entries(LANGS)) {
35
- for (const [key, value] of leaves(text)) {
36
- expect(typeof value, `${name}.${key}`).toBe('string');
37
- expect(value, `${name}.${key}`).not.toBe('');
38
- }
39
- }
40
- });
41
-
42
- it('keeps every placeholder a template declares', () => {
43
- const english = new Map(leaves(en));
44
- for (const [name, text] of Object.entries(LANGS)) {
45
- for (const [key, value] of leaves(text)) {
46
- const want =
47
- String(english.get(key))
48
- .match(/\{\w+\}/g)
49
- ?.sort() ?? [];
50
- const got =
51
- String(value)
52
- .match(/\{\w+\}/g)
53
- ?.sort() ?? [];
54
- expect(got, `${name}.${key}`).toEqual(want);
55
- }
56
- }
57
- });
58
-
59
- it('spells the build progress and pending lines out', () => {
60
- const cases = [
61
- [en, '3 of 8 pages done', 'Costs', 'Page 4 · Costs'],
62
- [zhCN, '已排 3 / 8 页', '成本', '第 4 页 · 成本'],
63
- ] as const;
64
- for (const [text, progress, title, pending] of cases) {
65
- expect(format(text.build.progress, { k: 3, n: 8 })).toBe(progress);
66
- expect(format(text.build.pendingPage, { k: 4, title })).toBe(pending);
67
- expect(format(text.build.done, { n: 8 })).not.toContain('{');
68
- }
69
- });
70
-
71
- it('says one file, not one files', () => {
72
- expect(format(plural(1, en.build.readFiles), { n: 1 })).toBe('Read 1 file');
73
- expect(format(plural(2, en.build.readFiles), { n: 2 })).toBe('Read 2 files');
74
- });
75
-
76
- it('spells the page check and the recorded choice out', () => {
77
- expect(format(en.prefs.confirmPage, { k: 3 })).toBe(
78
- 'Page 3 is done — check it, then press Continue',
79
- );
80
- expect(format(en.prefs.decisionEvent, { question: 'Which number?', answer: '41%' })).toBe(
81
- 'Check: Which number? → 41%',
82
- );
83
- expect(format(zhCN.prefs.confirmPage, { k: 3 })).toBe('第 3 页排好了,看看没问题就点继续');
84
- expect(format(zhCN.prefs.decisionEvent, { question: '用哪个数字?', answer: '41%' })).toBe(
85
- '核对:用哪个数字? → 41%',
86
- );
87
- expect(format(en.onboarding.progress, { k: 2 })).toBe('Screen 2 of 3');
88
- expect(format(en.prefs.directNotice, {})).not.toContain('{');
89
- });
90
- });
@@ -1,74 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import {
3
- BRAND_PATH_SOURCE,
4
- isBrandPage,
5
- lemonRiverViewFor,
6
- PREVIEW_PATH_SOURCE,
7
- pageForPath,
8
- SETTINGS_VIEW_ID,
9
- TRASH_VIEW_ID,
10
- } from './pages';
11
-
12
- const PATHS = [
13
- '/',
14
- '/themes',
15
- '/themes/',
16
- '/themes/plain',
17
- '/assets',
18
- '/settings',
19
- '/trash',
20
- '/trash/',
21
- '/new',
22
- '/new/',
23
- '/templates',
24
- '/templates/',
25
- '/s/alpha',
26
- '/s/alpha/',
27
- '/s/alpha/board',
28
- '/s/alpha/presenter',
29
- '/s/alpha/preview',
30
- '/settings/x',
31
- '/assetsx',
32
- '/nope',
33
- ];
34
-
35
- describe('pageForPath', () => {
36
- it('names each route', () => {
37
- expect(pageForPath('/')).toBe('home');
38
- expect(pageForPath('/themes/plain')).toBe('themes');
39
- expect(pageForPath('/trash/')).toBe('trash');
40
- expect(pageForPath('/new')).toBe('new');
41
- expect(pageForPath('/new/')).toBe('new');
42
- expect(pageForPath('/templates')).toBe('templates');
43
- expect(pageForPath('/templates/')).toBe('templates');
44
- expect(pageForPath('/s/alpha')).toBe('editor');
45
- expect(pageForPath('/s/alpha/board')).toBe('board');
46
- expect(pageForPath('/s/alpha/presenter')).toBe('presenter');
47
- expect(pageForPath('/s/alpha/preview')).toBe('preview');
48
- expect(pageForPath('/settings/x')).toBe('other');
49
- });
50
-
51
- it('keeps the editor and present views out of the lime theme', () => {
52
- for (const path of ['/s/alpha', '/s/alpha/board', '/s/alpha/presenter', '/s/alpha/preview']) {
53
- expect(isBrandPage(pageForPath(path)), path).toBe(false);
54
- }
55
- });
56
-
57
- it('matches the pre-paint patterns for every path', () => {
58
- const brand = new RegExp(BRAND_PATH_SOURCE);
59
- const preview = new RegExp(PREVIEW_PATH_SOURCE);
60
- for (const path of PATHS) {
61
- expect(brand.test(path), path).toBe(isBrandPage(pageForPath(path)));
62
- expect(preview.test(path), path).toBe(pageForPath(path) === 'preview');
63
- }
64
- });
65
- });
66
-
67
- describe('lemonRiverViewFor', () => {
68
- it('selects our sidebar rows on our pages only', () => {
69
- expect(lemonRiverViewFor('/settings')).toBe(SETTINGS_VIEW_ID);
70
- expect(lemonRiverViewFor('/trash/')).toBe(TRASH_VIEW_ID);
71
- expect(lemonRiverViewFor('/')).toBeNull();
72
- expect(lemonRiverViewFor('/themes')).toBeNull();
73
- });
74
- });