@open-document/core 0.14.0 → 0.14.2

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 (50) hide show
  1. package/dist/{build-CyBlmrjS.js → build-I0cgoERP.js} +1 -1
  2. package/dist/{check-DUKDEem-.js → check-Dys96QSL.js} +3 -3
  3. package/dist/cli/bin.js +9 -9
  4. package/dist/{context-BPApOW9n.js → context-C-osJW5f.js} +1 -1
  5. package/dist/{dev-DrnOvsX3.js → dev-CC4PrIOC.js} +1 -1
  6. package/dist/{diff-BPMD2Knh.js → diff-DhutD4TJ.js} +2 -2
  7. package/dist/{export-DeVtL8aX.js → export-KrajVJO7.js} +3 -3
  8. package/dist/{import-WAgWsuOv.js → import-Yv34za3L.js} +3 -3
  9. package/dist/ops/index.js +2 -2
  10. package/dist/{ops-raK6424A.js → ops-Dux5HlkH.js} +2 -422
  11. package/dist/{preview-B8Vw9QCh.js → preview-7eqn9Wzf.js} +1 -1
  12. package/dist/{config-cNpYUpF6.js → session-BSbrC5gK.js} +510 -4
  13. package/dist/{templates-D9jAFJ8R.js → templates-s-VLTSRc.js} +3 -3
  14. package/dist/vite/index.js +1 -1
  15. package/package.json +6 -1
  16. package/src/agent/check-after-turn.ts +59 -0
  17. package/src/agent/detect.ts +158 -0
  18. package/src/agent/install.ts +73 -0
  19. package/src/agent/prompt.ts +175 -0
  20. package/src/agent/provider.ts +126 -0
  21. package/src/agent/providers/codex.ts +209 -0
  22. package/src/agent/providers/index.ts +7 -0
  23. package/src/agent/providers/sdk-types.ts +71 -0
  24. package/src/agent/runner.ts +392 -0
  25. package/src/agent/status.ts +64 -0
  26. package/src/agent/store.ts +271 -0
  27. package/src/agent/types.ts +174 -0
  28. package/src/app/components/agent/agent-panel.tsx +6 -1
  29. package/src/app/components/agent/transcript.tsx +111 -3
  30. package/src/app/lib/i18n-ja/agent-panel.ts +8 -0
  31. package/src/app/lib/i18n-ko/agent-panel.ts +8 -0
  32. package/src/app/lib/i18n-zh-cn/agent-panel.ts +8 -0
  33. package/src/app/lib/i18n-zh-tw/agent-panel.ts +8 -0
  34. package/src/app/lib/use-locale.ts +7 -0
  35. package/src/diagram/index.ts +46 -0
  36. package/src/diagram/layout.ts +627 -0
  37. package/src/diagram/parse.ts +335 -0
  38. package/src/diagram/render.ts +162 -0
  39. package/src/editing/placeholder-id.ts +2 -0
  40. package/src/app/lib/chart.test.ts +0 -123
  41. package/src/app/lib/docx/ooxml.test.ts +0 -484
  42. package/src/app/lib/flow-measure.test.ts +0 -30
  43. package/src/app/lib/flow.test.ts +0 -129
  44. package/src/app/lib/footnotes.test.tsx +0 -102
  45. package/src/app/lib/i18n.test.ts +0 -24
  46. package/src/app/lib/inspector/inline-edit.test.ts +0 -244
  47. package/src/app/lib/page-range.test.ts +0 -104
  48. package/src/app/lib/records.test.ts +0 -38
  49. package/src/app/lib/sdk.test.ts +0 -30
  50. package/src/app/lib/view-mode.test.ts +0 -46
@@ -1,102 +0,0 @@
1
- import { createElement, isValidElement, type ReactNode } from 'react';
2
- import { describe, expect, it } from 'vitest';
3
- import { Footnote } from '../components/footnote';
4
- import { extractBlockFootnotes, extractSectionFootnotes, notesForPage } from './footnotes';
5
-
6
- function childrenOf(node: ReactNode): ReactNode {
7
- return isValidElement(node) ? (node.props as { children?: ReactNode }).children : undefined;
8
- }
9
-
10
- describe('extractBlockFootnotes', () => {
11
- it('lifts a note out and leaves a marker in its place', () => {
12
- const block = (
13
- <p>
14
- A claim
15
- <Footnote>Source: Q3 billing export.</Footnote>
16
- and the rest.
17
- </p>
18
- );
19
-
20
- const { node, notes } = extractBlockFootnotes(block, 'fn-0-0');
21
- expect(notes).toHaveLength(1);
22
- expect(notes[0].id).toBe('fn-0-0-1');
23
- expect(notes[0].content).toBe('Source: Q3 billing export.');
24
-
25
- const rendered = JSON.stringify(node, (key, value) => (key === 'type' ? undefined : value));
26
- expect(rendered).not.toContain('Source: Q3 billing export.');
27
- expect(node).not.toBe(block);
28
- });
29
-
30
- it('honours an author id so a Ref can point at the note', () => {
31
- const { notes } = extractBlockFootnotes(
32
- <p>
33
- x<Footnote id="billing">note</Footnote>
34
- </p>,
35
- 'fn-0-0',
36
- );
37
- expect(notes[0].id).toBe('billing');
38
- });
39
-
40
- it('finds notes nested several elements deep', () => {
41
- const { notes } = extractBlockFootnotes(
42
- <div>
43
- <ul>
44
- <li>
45
- one<Footnote>first</Footnote>
46
- </li>
47
- <li>
48
- two<Footnote>second</Footnote>
49
- </li>
50
- </ul>
51
- </div>,
52
- 'fn-1-2',
53
- );
54
- expect(notes.map((note) => note.content)).toEqual(['first', 'second']);
55
- expect(notes.map((note) => note.id)).toEqual(['fn-1-2-1', 'fn-1-2-2']);
56
- });
57
-
58
- it('returns the block untouched when it has no footnotes', () => {
59
- const block = <p>Nothing to lift.</p>;
60
- const { node, notes } = extractBlockFootnotes(block, 'fn-0-0');
61
- expect(node).toBe(block);
62
- expect(notes).toEqual([]);
63
- });
64
-
65
- it('leaves a render-prop child alone rather than walking into a function', () => {
66
- const block = createElement('div', null, (() => null) as unknown as ReactNode);
67
- expect(extractBlockFootnotes(block, 'fn-0-0').node).toBe(block);
68
- });
69
-
70
- it('keeps surrounding text intact', () => {
71
- const { node } = extractBlockFootnotes(
72
- <p>
73
- before<Footnote>note</Footnote>after
74
- </p>,
75
- 'fn-0-0',
76
- );
77
- const children = childrenOf(node) as ReactNode[];
78
- expect(children[0]).toBe('before');
79
- expect(children[2]).toBe('after');
80
- });
81
- });
82
-
83
- describe('extractSectionFootnotes', () => {
84
- it('keeps notes index-aligned with their blocks', () => {
85
- const prepared = extractSectionFootnotes(
86
- [
87
- <p key="a">plain</p>,
88
- <p key="b">
89
- x<Footnote>note</Footnote>
90
- </p>,
91
- ],
92
- 0,
93
- );
94
- expect(prepared.notesByBlock[0]).toEqual([]);
95
- expect(prepared.notesByBlock[1]).toHaveLength(1);
96
- });
97
-
98
- it('collects only the notes belonging to a page', () => {
99
- const notesByBlock = [[{ id: 'a', content: 'A' }], [], [{ id: 'c', content: 'C' }]];
100
- expect(notesForPage(notesByBlock, [1, 2]).map((note) => note.id)).toEqual(['c']);
101
- });
102
- });
@@ -1,24 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { DICTIONARIES } from './i18n';
3
-
4
- const placeholders = (text: string) => [...text.matchAll(/\{(\w+)\}/g)].map((m) => m[1]).sort();
5
-
6
- const translated = Object.entries(DICTIONARIES).filter(([locale]) => locale !== 'en');
7
- const reference = Object.keys(DICTIONARIES['zh-TW']).sort();
8
-
9
- describe.each(translated)('%s dictionary', (_locale, dictionary) => {
10
- it('translates exactly the strings the others do', () => {
11
- expect(Object.keys(dictionary).sort()).toEqual(reference);
12
- });
13
-
14
- it('keeps every placeholder of the English key, and no others', () => {
15
- const broken = Object.entries(dictionary).filter(
16
- ([en, text]) => placeholders(en).join() !== placeholders(text).join(),
17
- );
18
- expect(broken).toEqual([]);
19
- });
20
-
21
- it('has no empty translations', () => {
22
- expect(Object.entries(dictionary).filter(([, text]) => text.trim() === '')).toEqual([]);
23
- });
24
- });
@@ -1,244 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import {
3
- cleanRun,
4
- clearFormatting,
5
- hasMark,
6
- holdSpaces,
7
- hrefOf,
8
- isRunDirty,
9
- linkAt,
10
- mapSegmentText,
11
- matchRanges,
12
- mergeSegments,
13
- setHref,
14
- spliceSegments,
15
- toggleMark,
16
- } from './inline-edit.ts';
17
-
18
- const text = (value: string) => ({ text: value, inline: true });
19
- const mark = (value: string) => ({ text: value, inline: true });
20
- const markup = (value: string) => ({ text: value, inline: false });
21
-
22
- describe('matchRanges', () => {
23
- it('pairs runs with text nodes, stepping over separators and markup', () => {
24
- // `{agency} {kind}` renders three text nodes; the ideographic space is
25
- // whitespace and never part of a run.
26
- const parts = [
27
- { index: 0, value: '範例市政府' },
28
- { index: 1, value: '函' },
29
- ];
30
- expect(matchRanges(parts, [text('範例市政府'), text(' '), text('函')])).toEqual([
31
- [0, 0],
32
- [2, 2],
33
- ]);
34
- });
35
-
36
- it('gathers text and bare marks into one run', () => {
37
- const parts = [{ index: 0, value: 'Use real h1/h2 elements' }];
38
- expect(
39
- matchRanges(parts, [text('Use real '), mark('h1'), text('/'), mark('h2'), text(' elements')]),
40
- ).toEqual([[0, 4]]);
41
- });
42
-
43
- it('keeps runs apart at markup that is not a bare mark', () => {
44
- const parts = [
45
- { index: 0, value: 'before' },
46
- { index: 1, value: 'after' },
47
- ];
48
- expect(matchRanges(parts, [text('before '), markup('x'), text(' after')])).toEqual([
49
- [0, 0],
50
- [2, 2],
51
- ]);
52
- });
53
-
54
- it('steps over text the source cannot claim', () => {
55
- // `{count} items`, where the count is computed: its text node is not a run.
56
- const parts = [{ index: 0, value: 'items' }];
57
- expect(matchRanges(parts, [text('3'), text(' items')])).toEqual([[1, 1]]);
58
- });
59
-
60
- it('matches across JSX line collapsing', () => {
61
- const parts = [{ index: 0, value: 'Availability held\n above target.' }];
62
- expect(matchRanges(parts, [text('Availability held above target.')])).toEqual([[0, 0]]);
63
- });
64
-
65
- it('refuses when the rendered text is not what the source says', () => {
66
- expect(matchRanges([{ index: 0, value: 'Title' }], [text('TITLE')])).toBeNull();
67
- });
68
-
69
- it('keeps runs in document order', () => {
70
- const parts = [
71
- { index: 0, value: 'b' },
72
- { index: 1, value: 'a' },
73
- ];
74
- expect(matchRanges(parts, [text('a'), markup('-'), text('b')])).toBeNull();
75
- });
76
- });
77
-
78
- describe('cleanRun', () => {
79
- it('turns the browser’s non-breaking spaces back into spaces', () => {
80
- expect(cleanRun('a b', 'a b')).toBe('a b');
81
- });
82
-
83
- it('trims edges a trimmed source run never had', () => {
84
- expect(cleanRun('端點是 ', '對外端點為')).toBe('端點是');
85
- });
86
-
87
- it('keeps edge whitespace a run really holds', () => {
88
- expect(cleanRun(' indented\n', ' code\n')).toBe(' indented\n');
89
- });
90
- });
91
-
92
- describe('isRunDirty', () => {
93
- it('ignores whitespace-only differences', () => {
94
- expect(isRunDirty('Editable heading ', 'Editable heading')).toBe(false);
95
- expect(isRunDirty('Edited heading', 'Editable heading')).toBe(true);
96
- });
97
- });
98
-
99
- describe('holdSpaces', () => {
100
- it('keeps a trailing space from collapsing while the next word is typed', () => {
101
- expect(holdSpaces('Rewritten ')).toBe('Rewritten\u00a0');
102
- expect(cleanRun(`${holdSpaces('Rewritten ')}heading`, 'Editable heading')).toBe(
103
- 'Rewritten heading',
104
- );
105
- });
106
-
107
- it('holds runs of spaces and leading spaces, not single inner ones', () => {
108
- expect(holdSpaces(' a b c')).toBe('\u00a0a \u00a0b c');
109
- });
110
- });
111
-
112
- describe('segments', () => {
113
- const plain = [{ text: 'Executive summary' }];
114
-
115
- it('bolds a range and splits the run around it', () => {
116
- expect(toggleMark(plain, 10, 17, 'bold')).toEqual([
117
- { text: 'Executive ' },
118
- { text: 'summary', bold: true },
119
- ]);
120
- });
121
-
122
- it('takes the mark off when the whole range already has it', () => {
123
- const bolded = toggleMark(plain, 10, 17, 'bold');
124
- expect(toggleMark(bolded, 10, 17, 'bold')).toEqual(plain);
125
- });
126
-
127
- it('adds the mark when only part of the range has it', () => {
128
- const bolded = toggleMark(plain, 10, 17, 'bold');
129
- expect(hasMark(bolded, 5, 17, 'bold')).toBe(false);
130
- expect(toggleMark(bolded, 5, 17, 'bold')).toEqual([
131
- { text: 'Execu' },
132
- { text: 'tive summary', bold: true },
133
- ]);
134
- });
135
-
136
- it('keeps bold and italic independent', () => {
137
- const both = toggleMark(toggleMark(plain, 0, 9, 'bold'), 5, 9, 'italic');
138
- expect(both).toEqual([
139
- { text: 'Execu', bold: true },
140
- { text: 'tive', bold: true, italic: true },
141
- { text: ' summary' },
142
- ]);
143
- });
144
-
145
- it('continues the emphasis of the character before the caret', () => {
146
- const bolded = toggleMark(plain, 10, 17, 'bold');
147
- expect(spliceSegments(bolded, 17, 17, '!')).toEqual([
148
- { text: 'Executive ' },
149
- { text: 'summary!', bold: true },
150
- ]);
151
- expect(spliceSegments(bolded, 10, 10, 'x')).toEqual([
152
- { text: 'Executive x' },
153
- { text: 'summary', bold: true },
154
- ]);
155
- });
156
-
157
- it('keeps the formatting of the words a selection replaces', () => {
158
- const bolded = toggleMark(plain, 10, 17, 'bold');
159
- expect(spliceSegments(bolded, 10, 17, 'digest')).toEqual([
160
- { text: 'Executive ' },
161
- { text: 'digest', bold: true },
162
- ]);
163
- });
164
-
165
- it('deletes across pieces and merges what is left', () => {
166
- const bolded = toggleMark(plain, 10, 17, 'bold');
167
- expect(spliceSegments(bolded, 9, 17, '')).toEqual([{ text: 'Executive' }]);
168
- });
169
-
170
- it('counts UTF-16 units, as DOM offsets do', () => {
171
- // The emoji is two units; the selection's offsets for "ab" are 2–4.
172
- expect(toggleMark([{ text: '😀ab' }], 2, 4, 'bold')).toEqual([
173
- { text: '😀' },
174
- { text: 'ab', bold: true },
175
- ]);
176
- });
177
-
178
- it('rewrites text across piece boundaries without moving them', () => {
179
- const pieces = [{ text: 'a ' }, { text: ' b', bold: true }];
180
- expect(mapSegmentText(pieces, holdSpaces)).toEqual([
181
- { text: 'a ' },
182
- { text: '\u00a0b', bold: true },
183
- ]);
184
- });
185
-
186
- it('drops empty pieces and joins equal neighbours', () => {
187
- expect(mergeSegments([{ text: 'a' }, { text: '' }, { text: 'b' }])).toEqual([{ text: 'ab' }]);
188
- });
189
- });
190
-
191
- describe('code, links and clearing', () => {
192
- const plain = [{ text: 'See the guide now' }];
193
-
194
- it('toggles code like any other mark', () => {
195
- expect(toggleMark(plain, 8, 13, 'code')).toEqual([
196
- { text: 'See the ' },
197
- { text: 'guide', code: true },
198
- { text: ' now' },
199
- ]);
200
- });
201
-
202
- it('links a range, and finds the whole link from a caret inside it', () => {
203
- const linked = setHref(plain, 4, 13, '/guide');
204
- expect(linked).toEqual([
205
- { text: 'See ' },
206
- { text: 'the guide', href: '/guide' },
207
- { text: ' now' },
208
- ]);
209
- expect(linkAt(linked, 6)).toEqual({ from: 4, to: 13, href: '/guide' });
210
- expect(linkAt(linked, 13)).toEqual({ from: 4, to: 13, href: '/guide' });
211
- expect(linkAt(linked, 2)).toBeNull();
212
- expect(hrefOf(linked, 4, 13)).toBe('/guide');
213
- expect(hrefOf(linked, 2, 13)).toBeNull();
214
- });
215
-
216
- it('unlinks with a null href', () => {
217
- const linked = setHref(plain, 4, 13, '/guide');
218
- expect(setHref(linked, 4, 13, null)).toEqual(plain);
219
- });
220
-
221
- it('does not extend a link when typing just past its end', () => {
222
- const linked = setHref(plain, 4, 13, '/guide');
223
- expect(spliceSegments(linked, 13, 13, 's')).toEqual([
224
- { text: 'See ' },
225
- { text: 'the guide', href: '/guide' },
226
- { text: 's now' },
227
- ]);
228
- // Inside the link, typing stays in it.
229
- expect(spliceSegments(linked, 8, 8, 'x')).toEqual([
230
- { text: 'See ' },
231
- { text: 'the xguide', href: '/guide' },
232
- { text: ' now' },
233
- ]);
234
- });
235
-
236
- it('clears every kind of formatting from the range only', () => {
237
- const busy = toggleMark(setHref(toggleMark(plain, 0, 17, 'bold'), 4, 13, '/g'), 8, 13, 'code');
238
- expect(clearFormatting(busy, 4, 13)).toEqual([
239
- { text: 'See ', bold: true },
240
- { text: 'the guide' },
241
- { text: ' now', bold: true },
242
- ]);
243
- });
244
- });
@@ -1,104 +0,0 @@
1
- /**
2
- * Page ranges, where off-by-one lives.
3
- *
4
- * The reader types "1" and means the first page; the array wants index 0. Every
5
- * assertion here is about that seam, plus the two answers that must stay
6
- * distinct: "nothing you typed names a page" and "you selected no pages". Only
7
- * one of them should ever start a download, and neither should download
8
- * everything by accident.
9
- */
10
-
11
- import { describe, expect, it } from 'vitest';
12
- import { describeSelection, formatPages, parseRange, resolveSelection } from './page-range';
13
-
14
- describe('parseRange', () => {
15
- it('reads single pages, one-based', () => {
16
- expect(parseRange('1', 5)).toEqual([0]);
17
- expect(parseRange('3', 5)).toEqual([2]);
18
- });
19
-
20
- it('reads spans, inclusive at both ends', () => {
21
- expect(parseRange('1-3', 5)).toEqual([0, 1, 2]);
22
- expect(parseRange('4-5', 5)).toEqual([3, 4]);
23
- });
24
-
25
- it('reads a mixed list, sorted and deduplicated', () => {
26
- expect(parseRange('5,1,2-3,1', 9)).toEqual([0, 1, 2, 4]);
27
- });
28
-
29
- /* A range typed backwards is a range, not a mistake worth refusing. */
30
- it('accepts a span written the wrong way round', () => {
31
- expect(parseRange('5-2', 9)).toEqual([1, 2, 3, 4]);
32
- });
33
-
34
- /* 中文鍵盤打出來的全形數字和破折號,使用者不會察覺自己打的是全形。 */
35
- it('accepts full-width digits and dashes', () => {
36
- expect(parseRange('1-3', 5)).toEqual([0, 1, 2]);
37
- expect(parseRange('2,4', 5)).toEqual([1, 3]);
38
- });
39
-
40
- it('clips to the document rather than inventing pages', () => {
41
- expect(parseRange('3-99', 5)).toEqual([2, 3, 4]);
42
- expect(parseRange('0-2', 5)).toEqual([0, 1]);
43
- });
44
-
45
- /*
46
- * The important negative: nothing usable must be null, never an empty array.
47
- * An empty array flowing on would start a download of no pages.
48
- */
49
- it('returns null when nothing names a real page', () => {
50
- expect(parseRange('', 5)).toBeNull();
51
- expect(parseRange(' ', 5)).toBeNull();
52
- expect(parseRange('abc', 5)).toBeNull();
53
- expect(parseRange('9', 5)).toBeNull();
54
- expect(parseRange('-', 5)).toBeNull();
55
- });
56
- });
57
-
58
- describe('resolveSelection', () => {
59
- it('all covers the document', () => {
60
- expect(resolveSelection({ kind: 'all' }, 3, 2)).toEqual([0, 1, 2]);
61
- });
62
-
63
- it('current is the page being read, one-based in and zero-based out', () => {
64
- expect(resolveSelection({ kind: 'current' }, 5, 1)).toEqual([0]);
65
- expect(resolveSelection({ kind: 'current' }, 5, 4)).toEqual([3]);
66
- });
67
-
68
- /* currentPage can lag the document while it reflows; it must not index past. */
69
- it('clamps a current page outside the document', () => {
70
- expect(resolveSelection({ kind: 'current' }, 3, 99)).toEqual([2]);
71
- expect(resolveSelection({ kind: 'current' }, 3, 0)).toEqual([0]);
72
- });
73
-
74
- it('has nothing to give for an empty document', () => {
75
- expect(resolveSelection({ kind: 'all' }, 0, 1)).toBeNull();
76
- });
77
- });
78
-
79
- describe('describeSelection', () => {
80
- it('counts what the button is about to do', () => {
81
- expect(describeSelection({ kind: 'all' }, 4, 1)).toEqual({ count: 4, valid: true });
82
- expect(describeSelection({ kind: 'current' }, 4, 2)).toEqual({ count: 1, valid: true });
83
- expect(describeSelection({ kind: 'custom', text: '2-3' }, 4, 1)).toEqual({
84
- count: 2,
85
- valid: true,
86
- });
87
- });
88
-
89
- it('reports an unreadable range as invalid, not as zero pages', () => {
90
- expect(describeSelection({ kind: 'custom', text: 'nope' }, 4, 1)).toEqual({
91
- count: 0,
92
- valid: false,
93
- });
94
- });
95
- });
96
-
97
- describe('formatPages', () => {
98
- it('writes runs back the way a reader types them', () => {
99
- expect(formatPages([0, 1, 2, 5])).toBe('1–3, 6');
100
- expect(formatPages([4])).toBe('5');
101
- expect(formatPages([0, 2, 4])).toBe('1, 3, 5');
102
- expect(formatPages([])).toBe('');
103
- });
104
- });
@@ -1,38 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { getRecordState, recordFileName, recordLabel, setRecordIndex, setRecords } from './records';
3
-
4
- describe('recordFileName', () => {
5
- const row = { name: 'Lin Mei', company: 'Acme / Asia', score: 92 };
6
-
7
- it('fills columns and the row number', () => {
8
- expect(recordFileName('certificate-{name}', row, 2, 120)).toBe('certificate-Lin Mei');
9
- expect(recordFileName('{#}-{company}', row, 2, 120)).toBe('003-Acme - Asia');
10
- });
11
-
12
- it('numbers a pattern without placeholders, so each row gets its own file', () => {
13
- expect(recordFileName('awards', row, 0, 9)).toBe('awards-1');
14
- });
15
-
16
- it('falls back to the number when the pattern fills to nothing', () => {
17
- expect(recordFileName('{missing}', row, 4, 12)).toBe('05');
18
- });
19
- });
20
-
21
- describe('recordLabel', () => {
22
- it('uses the named column, else the first value', () => {
23
- expect(recordLabel({ id: '', name: 'Ada' }, 0)).toBe('Ada');
24
- expect(recordLabel({ id: 'x7', name: 'Ada' }, 0, 'name')).toBe('Ada');
25
- expect(recordLabel(undefined, 3)).toBe('4');
26
- });
27
- });
28
-
29
- describe('the record store', () => {
30
- it('keeps the index inside the rows', () => {
31
- setRecords([{ a: 1 }, { a: 2 }], 5);
32
- expect(getRecordState().index).toBe(1);
33
- setRecordIndex(-3);
34
- expect(getRecordState().index).toBe(0);
35
- setRecords(undefined);
36
- expect(getRecordState()).toEqual({ records: [], index: 0 });
37
- });
38
- });
@@ -1,30 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { PAGE_SIZE_NAMES, PAGE_SIZES, resolvePageGeometry } from './sdk.ts';
3
-
4
- describe('resolvePageGeometry', () => {
5
- it('defaults to portrait A4', () => {
6
- expect(resolvePageGeometry()).toEqual({
7
- width: PAGE_SIZES.A4.width,
8
- height: PAGE_SIZES.A4.height,
9
- css: '210mm 297mm',
10
- });
11
- });
12
-
13
- it('offers A4, B4 and A3 and nothing else', () => {
14
- expect([...PAGE_SIZE_NAMES]).toEqual(['A4', 'B4', 'A3']);
15
- expect(Object.keys(PAGE_SIZES)).toEqual([...PAGE_SIZE_NAMES]);
16
- });
17
-
18
- it('swaps both the pixel axes and the @page descriptor for landscape', () => {
19
- const geo = resolvePageGeometry({ pageSize: 'B4', orientation: 'landscape' });
20
- expect(geo.width).toBe(PAGE_SIZES.B4.height);
21
- expect(geo.height).toBe(PAGE_SIZES.B4.width);
22
- // Chromium drops `<mm> <mm> landscape` entirely — the axes must be swapped.
23
- expect(geo.css).toBe('364mm 257mm');
24
- });
25
-
26
- it('falls back to A4 for a page size that is no longer offered', () => {
27
- const geo = resolvePageGeometry({ pageSize: 'Letter' as never });
28
- expect(geo.width).toBe(PAGE_SIZES.A4.width);
29
- });
30
- });
@@ -1,46 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { fitWidthScale, pageAtMarker, sheetsAcross } from './view-mode.ts';
3
-
4
- describe('fitWidthScale', () => {
5
- it('fits one sheet, a spread, or a row of three into the width', () => {
6
- expect(sheetsAcross('continuous')).toBe(1);
7
- for (const mode of ['continuous', 'spread', 'grid'] as const) {
8
- const scale = fitWidthScale(mode, 960, 794, 24);
9
- const across = sheetsAcross(mode);
10
- // The row the viewer lays out — scaled sheets plus fixed gaps — fills it exactly.
11
- expect(across * 794 * scale + (across - 1) * 24).toBeCloseTo(960);
12
- }
13
- });
14
- });
15
-
16
- describe('pageAtMarker', () => {
17
- it('follows a single column', () => {
18
- expect(pageAtMarker([0, 1100, 2200], 1500)).toBe(2);
19
- expect(pageAtMarker([0, 1100, 2200], 10)).toBe(1);
20
- });
21
-
22
- it('reports the left page of the spread in view', () => {
23
- // Page 1 alone on the right, then 2–3, 4–5.
24
- const tops = [0, 1100, 1100, 2200, 2200];
25
- expect(pageAtMarker(tops, 1500)).toBe(2);
26
- expect(pageAtMarker(tops, 2300)).toBe(4);
27
- });
28
-
29
- it('reports the first sheet of the grid row in view', () => {
30
- const tops = [0, 0, 0, 300, 300, 300, 600];
31
- expect(pageAtMarker(tops, 450)).toBe(4);
32
- expect(pageAtMarker(tops, 650)).toBe(7);
33
- });
34
-
35
- it('keeps a page just jumped to while its row is in view', () => {
36
- const tops = [0, 1100, 1100, 2200, 2200];
37
- expect(pageAtMarker(tops, 1500, 3)).toBe(3);
38
- // Scrolled on to the next spread: the jump no longer describes the view.
39
- expect(pageAtMarker(tops, 2300, 3)).toBe(4);
40
- });
41
-
42
- it('falls back to the first page before anything has passed the marker', () => {
43
- expect(pageAtMarker([200, 1300], 100)).toBe(1);
44
- expect(pageAtMarker([], 100)).toBe(1);
45
- });
46
- });