@open-document/core 0.12.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{build-DfUfpeTR.js → build-CvsOak5B.js} +1 -1
- package/dist/{check-CHxiOkQG.js → check-CbUBwYmf.js} +3 -3
- package/dist/cli/bin.js +47 -10
- package/dist/config-BWtOZ1jc.d.ts +45 -0
- package/dist/{config-9IdbhVuT.js → config-CltJJVsw.js} +398 -493
- package/dist/{context-BLI1-64_.js → context-CWgfsHoE.js} +2 -1
- package/dist/deploy-gcp-BUiSuqz7.js +758 -0
- package/dist/{dev-yNYKv5mm.js → dev-B8H2qT6G.js} +1 -1
- package/dist/{diagram-BK4jTZr4.js → diagram-CKf3ptOE.js} +293 -13
- package/dist/{diff-Bs205mOx.js → diff-BvIjjgnc.js} +2 -2
- package/dist/{export-tkquS5O5.js → export-DX30_s2q.js} +3 -3
- package/dist/{sdk-CHEGeINh.d.ts → flow-CS5apebG.d.ts} +72 -3
- package/dist/{import-D1hIKIr3.js → import-DgsdJT5e.js} +2 -2
- package/dist/index.d.ts +155 -59
- package/dist/index.js +896 -90
- package/dist/open-doc-plugin-DnX5usgI.js +320 -0
- package/dist/ops/index.d.ts +98 -13
- package/dist/ops/index.js +3 -3
- package/dist/{ops-Dgqujq5a.js → ops-CSR5RlrE.js} +2 -1
- package/dist/{preview-BImdTH6K.js → preview-DYMUNjXL.js} +1 -1
- package/dist/{templates-DT5zzqHq.js → templates-B5Tz0AKb.js} +3 -3
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +2 -1
- package/package.json +1 -1
- package/skills/doc-authoring/SKILL.md +15 -16
- package/skills/doc-authoring/references/long-form.md +43 -2
- package/skills/doc-authoring/references/pagination.md +14 -2
- package/skills/doc-authoring/references/tables-and-charts.md +21 -17
- package/src/app/components/callout.tsx +101 -0
- package/src/app/components/chart.tsx +191 -33
- package/src/app/components/code-block.tsx +249 -0
- package/src/app/components/data-table.tsx +146 -18
- package/src/app/components/flow-page.tsx +57 -8
- package/src/app/components/numbering.tsx +226 -12
- package/src/app/components/page-frame.tsx +42 -0
- package/src/app/lib/chart.test.ts +15 -0
- package/src/app/lib/chart.ts +134 -9
- package/src/app/lib/diagnostics.ts +45 -1
- package/src/app/lib/export-dom.ts +15 -2
- package/src/app/lib/export-pdf.ts +9 -1
- package/src/app/lib/flow-measure.ts +33 -4
- package/src/app/lib/flow.test.ts +20 -1
- package/src/app/lib/flow.ts +120 -20
- package/src/app/lib/labels.ts +29 -10
- package/src/app/lib/sdk.ts +6 -0
- package/src/app/lib/use-doc-pages.ts +23 -8
- package/src/app/routes/doc.tsx +1 -0
- package/dist/config-P61niZMf.d.ts +0 -24
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createElement } from 'react';
|
|
2
2
|
import { createRoot, type Root } from 'react-dom/client';
|
|
3
|
+
import { SheetWatermark } from '../components/page-frame';
|
|
3
4
|
import { designToCssVars } from './design';
|
|
4
5
|
import { PAGE_ATTR, PAGE_INDEX_ATTR } from './outline';
|
|
5
6
|
import { DocPageProvider } from './page-context';
|
|
@@ -124,7 +125,14 @@ export async function mountPrintCopy(
|
|
|
124
125
|
}
|
|
125
126
|
root.appendChild(host);
|
|
126
127
|
const r = createRoot(host);
|
|
127
|
-
r.render(
|
|
128
|
+
r.render(
|
|
129
|
+
createElement(
|
|
130
|
+
DocPageProvider,
|
|
131
|
+
{ index: i, total },
|
|
132
|
+
page.content,
|
|
133
|
+
createElement(SheetWatermark, { text: doc.meta?.watermark }),
|
|
134
|
+
),
|
|
135
|
+
);
|
|
128
136
|
reactRoots.push(r);
|
|
129
137
|
onProgress?.({
|
|
130
138
|
phase: 'rendering',
|
|
@@ -17,6 +17,8 @@ export type MeasurableSection = {
|
|
|
17
17
|
/** Index-aligned with `blocks`. */
|
|
18
18
|
notesByBlock: ExtractedNote[][];
|
|
19
19
|
padding?: number;
|
|
20
|
+
columns?: 1 | 2 | 3;
|
|
21
|
+
columnGap?: number;
|
|
20
22
|
};
|
|
21
23
|
|
|
22
24
|
export function metricsFor(el: HTMLElement, height: number, footnoteHeight: number): BlockMetrics {
|
|
@@ -29,6 +31,27 @@ export function metricsFor(el: HTMLElement, height: number, footnoteHeight: numb
|
|
|
29
31
|
const declaredKeepPrev = inner?.getAttribute('data-od-keep-with-previous') ?? null;
|
|
30
32
|
const declaredBreak = inner?.getAttribute('data-od-break-before') ?? null;
|
|
31
33
|
|
|
34
|
+
let splittable: BlockMetrics['splittable'];
|
|
35
|
+
if (typeof el.querySelector === 'function') {
|
|
36
|
+
const splitTable = el.querySelector<HTMLTableElement>('table[data-od-splittable]');
|
|
37
|
+
if (splitTable) {
|
|
38
|
+
const tbodyRows = Array.from(splitTable.querySelectorAll<HTMLElement>('tbody > tr'));
|
|
39
|
+
if (tbodyRows.length > 1) {
|
|
40
|
+
const blockRect = el.getBoundingClientRect();
|
|
41
|
+
const firstRowRect = tbodyRows[0].getBoundingClientRect();
|
|
42
|
+
const lastRowRect = tbodyRows[tbodyRows.length - 1].getBoundingClientRect();
|
|
43
|
+
const headerHeight = Math.max(0, firstRowRect.top - blockRect.top);
|
|
44
|
+
const footerHeight = Math.max(0, height - (lastRowRect.bottom - blockRect.top));
|
|
45
|
+
const rowHeights = tbodyRows.map((row, idx) => {
|
|
46
|
+
const r = row.getBoundingClientRect();
|
|
47
|
+
const next = tbodyRows[idx + 1]?.getBoundingClientRect();
|
|
48
|
+
return Math.max(0, (next ? next.top : lastRowRect.bottom) - r.top);
|
|
49
|
+
});
|
|
50
|
+
splittable = { headerHeight, footerHeight, rowHeights };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
32
55
|
return {
|
|
33
56
|
height,
|
|
34
57
|
footnoteHeight,
|
|
@@ -37,6 +60,7 @@ export function metricsFor(el: HTMLElement, height: number, footnoteHeight: numb
|
|
|
37
60
|
keepWithNext: declaredKeepNext !== null ? declaredKeepNext !== 'false' : HEADING_TAGS.has(tag),
|
|
38
61
|
keepWithPrevious: declaredKeepPrev !== null && declaredKeepPrev !== 'false',
|
|
39
62
|
breakBefore: declaredBreak !== null && declaredBreak !== 'false',
|
|
63
|
+
...(splittable ? { splittable } : {}),
|
|
40
64
|
};
|
|
41
65
|
}
|
|
42
66
|
|
|
@@ -122,9 +146,12 @@ export async function measureFlowSections(
|
|
|
122
146
|
// Out of the effect that called us, so `flushSync` below may commit.
|
|
123
147
|
await Promise.resolve();
|
|
124
148
|
for (const section of sections) {
|
|
125
|
-
const
|
|
149
|
+
const fullWidth = opts.geometry.width - paddingOf(section) * 2;
|
|
150
|
+
const cols = section.columns && section.columns > 1 ? section.columns : 1;
|
|
151
|
+
const gap = section.columnGap ?? 24;
|
|
152
|
+
const blockWidth = cols > 1 ? (fullWidth - gap * (cols - 1)) / cols : fullWidth;
|
|
126
153
|
|
|
127
|
-
const blocks = makeContainer(
|
|
154
|
+
const blocks = makeContainer(blockWidth);
|
|
128
155
|
blockContainers.push(blocks);
|
|
129
156
|
const blockRoot = createRoot(blocks);
|
|
130
157
|
// Committed now, not on React's schedule: on a slow machine a render
|
|
@@ -144,7 +171,7 @@ export async function measureFlowSections(
|
|
|
144
171
|
noteContainers.push(null);
|
|
145
172
|
continue;
|
|
146
173
|
}
|
|
147
|
-
const notes = makeContainer(
|
|
174
|
+
const notes = makeContainer(fullWidth);
|
|
148
175
|
noteContainers.push(notes);
|
|
149
176
|
const noteRoot = createRoot(notes);
|
|
150
177
|
flushSync(() => noteRoot.render(createElement(Footnotes, { notes: allNotes })));
|
|
@@ -168,6 +195,7 @@ export async function measureFlowSections(
|
|
|
168
195
|
|
|
169
196
|
return sections.map((section, sectionIndex) => {
|
|
170
197
|
const padding = paddingOf(section);
|
|
198
|
+
const cols = section.columns && section.columns > 1 ? section.columns : 1;
|
|
171
199
|
const blocks = blockContainers[sectionIndex];
|
|
172
200
|
const blockHeights = stackedHeights(blocks, `:scope > [${FLOW_BLOCK_ATTR}]`);
|
|
173
201
|
|
|
@@ -190,7 +218,8 @@ export async function measureFlowSections(
|
|
|
190
218
|
let notesHeight = 0;
|
|
191
219
|
for (let i = 0; i < count; i++) notesHeight += rowHeights[noteCursor + i] ?? 0;
|
|
192
220
|
noteCursor += count;
|
|
193
|
-
|
|
221
|
+
const rawHeight = blockHeights[index] ?? 0;
|
|
222
|
+
return metricsFor(node, cols > 1 ? rawHeight / cols : rawHeight, notesHeight);
|
|
194
223
|
});
|
|
195
224
|
|
|
196
225
|
return {
|
package/src/app/lib/flow.test.ts
CHANGED
|
@@ -59,7 +59,26 @@ describe('paginateBlocks', () => {
|
|
|
59
59
|
});
|
|
60
60
|
|
|
61
61
|
it('returns no pages for no blocks', () => {
|
|
62
|
-
expect(paginateBlocks([], 1000)).toEqual({ pages: [], overflowing: [] });
|
|
62
|
+
expect(paginateBlocks([], 1000)).toEqual({ pages: [], slices: [], overflowing: [] });
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('splits a tall splittable table across pages with repeated header', () => {
|
|
66
|
+
const tableBlock = b(680, {
|
|
67
|
+
splittable: {
|
|
68
|
+
headerHeight: 40,
|
|
69
|
+
footerHeight: 40,
|
|
70
|
+
rowHeights: [100, 100, 100, 100, 100, 100],
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
const result = paginateBlocks([b(500), tableBlock], 1000);
|
|
74
|
+
// Page 1 has 500px left: header(40) + 4 rows(400) = 440 <= 500.
|
|
75
|
+
// Page 2 gets the remaining 2 rows + header(40) + footer(40).
|
|
76
|
+
expect(result.pages).toEqual([[0, 1], [1]]);
|
|
77
|
+
expect(result.slices).toEqual([
|
|
78
|
+
[{ index: 0 }, { index: 1, rowStart: 0, rowEnd: 4 }],
|
|
79
|
+
[{ index: 1, rowStart: 4, rowEnd: 6 }],
|
|
80
|
+
]);
|
|
81
|
+
expect(result.overflowing).toEqual([]);
|
|
63
82
|
});
|
|
64
83
|
});
|
|
65
84
|
|
package/src/app/lib/flow.ts
CHANGED
|
@@ -27,7 +27,13 @@ function toBlocks(node: ReactNode): ReactNode[] {
|
|
|
27
27
|
*/
|
|
28
28
|
export function flow(
|
|
29
29
|
children: ReactNode,
|
|
30
|
-
opts: {
|
|
30
|
+
opts: {
|
|
31
|
+
header?: ComponentType;
|
|
32
|
+
footer?: ComponentType;
|
|
33
|
+
padding?: number;
|
|
34
|
+
columns?: 1 | 2 | 3;
|
|
35
|
+
columnGap?: number;
|
|
36
|
+
} = {},
|
|
31
37
|
): FlowSection {
|
|
32
38
|
return { __odFlow: true, blocks: toBlocks(children), ...opts };
|
|
33
39
|
}
|
|
@@ -36,6 +42,12 @@ export function isFlowSection(entry: DocEntry): entry is FlowSection {
|
|
|
36
42
|
return typeof entry === 'object' && entry !== null && (entry as FlowSection).__odFlow === true;
|
|
37
43
|
}
|
|
38
44
|
|
|
45
|
+
export type BlockSlice = {
|
|
46
|
+
index: number;
|
|
47
|
+
rowStart?: number;
|
|
48
|
+
rowEnd?: number;
|
|
49
|
+
};
|
|
50
|
+
|
|
39
51
|
export type BlockMetrics = {
|
|
40
52
|
height: number;
|
|
41
53
|
/** Height this block's footnotes add to the foot of whatever page it lands on. */
|
|
@@ -46,11 +58,19 @@ export type BlockMetrics = {
|
|
|
46
58
|
keepWithPrevious?: boolean;
|
|
47
59
|
/** Always start a new page before this block. */
|
|
48
60
|
breakBefore?: boolean;
|
|
61
|
+
/** When present, this block is a table that can split between rows across page breaks. */
|
|
62
|
+
splittable?: {
|
|
63
|
+
headerHeight: number;
|
|
64
|
+
footerHeight: number;
|
|
65
|
+
rowHeights: number[];
|
|
66
|
+
};
|
|
49
67
|
};
|
|
50
68
|
|
|
51
69
|
export type PaginationResult = {
|
|
52
70
|
/** Block indices per page, in order. */
|
|
53
71
|
pages: number[][];
|
|
72
|
+
/** Detailed block slices per page, carrying row ranges when a table splits across pages. */
|
|
73
|
+
slices: BlockSlice[][];
|
|
54
74
|
/** Blocks taller than one page — they stay whole and overflow. */
|
|
55
75
|
overflowing: number[];
|
|
56
76
|
};
|
|
@@ -63,7 +83,9 @@ export type PaginateOptions = {
|
|
|
63
83
|
/**
|
|
64
84
|
* Greedy top-to-bottom packing: fill a page until the next block would cross
|
|
65
85
|
* the bottom edge, then push that block — plus anything glued to it — onto the
|
|
66
|
-
* next page. Blocks are atomic
|
|
86
|
+
* next page. Blocks are atomic unless marked `splittable`, in which case rows
|
|
87
|
+
* pack into the remaining space and continue on the next sheet with the header
|
|
88
|
+
* repeated.
|
|
67
89
|
*
|
|
68
90
|
* Footnotes are packed from the same budget: a block that carries notes brings
|
|
69
91
|
* their height with it, because those notes print at the foot of whichever page
|
|
@@ -75,22 +97,42 @@ export function paginateBlocks(
|
|
|
75
97
|
opts: PaginateOptions = {},
|
|
76
98
|
): PaginationResult {
|
|
77
99
|
const overhead = opts.footnoteOverhead ?? 0;
|
|
78
|
-
const
|
|
100
|
+
const slices: BlockSlice[][] = [];
|
|
79
101
|
const overflowing: number[] = [];
|
|
80
|
-
let current:
|
|
102
|
+
let current: BlockSlice[] = [];
|
|
81
103
|
let used = 0;
|
|
82
104
|
let notes = 0;
|
|
83
105
|
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
106
|
+
const sliceHeight = (slice: BlockSlice): number => {
|
|
107
|
+
const block = blocks[slice.index];
|
|
108
|
+
if (!block) return 0;
|
|
109
|
+
if (slice.rowStart !== undefined && slice.rowEnd !== undefined && block.splittable) {
|
|
110
|
+
let rows = 0;
|
|
111
|
+
for (let r = slice.rowStart; r < slice.rowEnd; r++) {
|
|
112
|
+
rows += block.splittable.rowHeights[r] ?? 0;
|
|
113
|
+
}
|
|
114
|
+
const isLast = slice.rowEnd >= block.splittable.rowHeights.length;
|
|
115
|
+
return block.splittable.headerHeight + rows + (isLast ? block.splittable.footerHeight : 0);
|
|
116
|
+
}
|
|
117
|
+
return block.height;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const heightOf = (items: BlockSlice[]) => items.reduce((sum, item) => sum + sliceHeight(item), 0);
|
|
121
|
+
const notesOf = (items: BlockSlice[]) =>
|
|
122
|
+
items.reduce(
|
|
123
|
+
(sum, item) =>
|
|
124
|
+
sum +
|
|
125
|
+
(item.rowStart === undefined || item.rowStart === 0
|
|
126
|
+
? (blocks[item.index]?.footnoteHeight ?? 0)
|
|
127
|
+
: 0),
|
|
128
|
+
0,
|
|
129
|
+
);
|
|
88
130
|
/** A page with no notes pays nothing; the first note also pays for the rule. */
|
|
89
131
|
const reserve = (total: number) => (total > 0 ? total + overhead : 0);
|
|
90
132
|
|
|
91
133
|
const closePage = () => {
|
|
92
134
|
if (current.length === 0) return;
|
|
93
|
-
|
|
135
|
+
slices.push(current);
|
|
94
136
|
current = [];
|
|
95
137
|
used = 0;
|
|
96
138
|
notes = 0;
|
|
@@ -98,35 +140,93 @@ export function paginateBlocks(
|
|
|
98
140
|
|
|
99
141
|
blocks.forEach((block, index) => {
|
|
100
142
|
const own = block.footnoteHeight ?? 0;
|
|
101
|
-
if (block.height + reserve(own) > available) overflowing.push(index);
|
|
102
143
|
|
|
103
144
|
if (block.breakBefore) closePage();
|
|
104
145
|
|
|
146
|
+
const split = block.splittable;
|
|
147
|
+
const canSplit = split && split.rowHeights.length > 1;
|
|
148
|
+
|
|
149
|
+
if (!canSplit && block.height + reserve(own) > available) {
|
|
150
|
+
overflowing.push(index);
|
|
151
|
+
}
|
|
152
|
+
|
|
105
153
|
if (current.length > 0 && used + block.height + reserve(notes + own) > available) {
|
|
106
154
|
// Everything glued to this block travels with it: trailing headings
|
|
107
155
|
// (keep-with-next) and, when this block is a caption, its figure.
|
|
108
156
|
let splitAt = current.length;
|
|
109
|
-
while (splitAt > 0 && blocks[current[splitAt - 1]]?.keepWithNext) splitAt--;
|
|
157
|
+
while (splitAt > 0 && blocks[current[splitAt - 1].index]?.keepWithNext) splitAt--;
|
|
110
158
|
if (block.keepWithPrevious && splitAt === current.length) splitAt--;
|
|
111
159
|
|
|
112
|
-
if (
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
160
|
+
if (canSplit) {
|
|
161
|
+
const firstRowCost = split.headerHeight + (split.rowHeights[0] ?? 0);
|
|
162
|
+
if (used + firstRowCost + reserve(notes + own) > available) {
|
|
163
|
+
if (splitAt > 0 && splitAt < current.length) {
|
|
164
|
+
const moved = current.slice(splitAt);
|
|
165
|
+
slices.push(current.slice(0, splitAt));
|
|
166
|
+
current = moved;
|
|
167
|
+
used = heightOf(moved);
|
|
168
|
+
notes = notesOf(moved);
|
|
169
|
+
} else {
|
|
170
|
+
closePage();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
118
173
|
} else {
|
|
119
|
-
|
|
174
|
+
if (splitAt > 0 && splitAt < current.length) {
|
|
175
|
+
const moved = current.slice(splitAt);
|
|
176
|
+
slices.push(current.slice(0, splitAt));
|
|
177
|
+
current = moved;
|
|
178
|
+
used = heightOf(moved);
|
|
179
|
+
notes = notesOf(moved);
|
|
180
|
+
} else {
|
|
181
|
+
closePage();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (canSplit && used + block.height + reserve(notes + own) > available) {
|
|
187
|
+
let rowCursor = 0;
|
|
188
|
+
const totalRows = split.rowHeights.length;
|
|
189
|
+
let firstSlice = true;
|
|
190
|
+
while (rowCursor < totalRows) {
|
|
191
|
+
const sliceNotes = firstSlice ? own : 0;
|
|
192
|
+
const budget = available - used - reserve(notes + sliceNotes) - split.headerHeight;
|
|
193
|
+
let rowEnd = rowCursor;
|
|
194
|
+
let rowSum = 0;
|
|
195
|
+
while (rowEnd < totalRows) {
|
|
196
|
+
const rHeight = split.rowHeights[rowEnd] ?? 0;
|
|
197
|
+
const tail = rowEnd + 1 === totalRows ? split.footerHeight : 0;
|
|
198
|
+
if (rowSum + rHeight + tail <= budget || (rowEnd === rowCursor && current.length === 0)) {
|
|
199
|
+
rowSum += rHeight;
|
|
200
|
+
rowEnd++;
|
|
201
|
+
} else {
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (rowEnd === rowCursor) {
|
|
206
|
+
closePage();
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
const slice: BlockSlice = { index, rowStart: rowCursor, rowEnd };
|
|
210
|
+
current.push(slice);
|
|
211
|
+
used += sliceHeight(slice);
|
|
212
|
+
notes += sliceNotes;
|
|
213
|
+
firstSlice = false;
|
|
214
|
+
rowCursor = rowEnd;
|
|
215
|
+
if (rowCursor < totalRows) {
|
|
216
|
+
closePage();
|
|
217
|
+
}
|
|
120
218
|
}
|
|
219
|
+
return;
|
|
121
220
|
}
|
|
122
221
|
|
|
123
|
-
current.push(index);
|
|
222
|
+
current.push({ index });
|
|
124
223
|
used += block.height;
|
|
125
224
|
notes += own;
|
|
126
225
|
});
|
|
127
226
|
|
|
128
227
|
closePage();
|
|
129
|
-
|
|
228
|
+
const pages = slices.map((page) => page.map((s) => s.index));
|
|
229
|
+
return { pages, slices, overflowing };
|
|
130
230
|
}
|
|
131
231
|
|
|
132
232
|
/** Blocks of the first flow section, for thumbnails that skip measurement. */
|
package/src/app/lib/labels.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useSyncExternalStore } from 'react';
|
|
2
2
|
import { PAGE_ATTR, PAGE_INDEX_ATTR } from './outline';
|
|
3
3
|
|
|
4
|
-
export type LabelKind = 'figure' | 'table' | 'footnote';
|
|
4
|
+
export type LabelKind = 'figure' | 'table' | 'footnote' | 'citation';
|
|
5
5
|
|
|
6
6
|
export type LabelEntry = {
|
|
7
7
|
/** Author-supplied id for `<Ref to>`, or a generated one. */
|
|
@@ -29,6 +29,8 @@ export type LabelVocabulary = {
|
|
|
29
29
|
table: string;
|
|
30
30
|
/** Heading above a page's footnotes. Empty string renders no heading. */
|
|
31
31
|
footnotes: string;
|
|
32
|
+
/** Heading above a bibliography section when not overridden. */
|
|
33
|
+
bibliography: string;
|
|
32
34
|
/** Page suffix for a cross-reference. `{page}` is replaced. */
|
|
33
35
|
onPage: string;
|
|
34
36
|
};
|
|
@@ -37,6 +39,7 @@ export const defaultVocabulary: LabelVocabulary = {
|
|
|
37
39
|
figure: 'Figure',
|
|
38
40
|
table: 'Table',
|
|
39
41
|
footnotes: '',
|
|
42
|
+
bibliography: 'References',
|
|
40
43
|
onPage: ' (p. {page})',
|
|
41
44
|
};
|
|
42
45
|
|
|
@@ -47,7 +50,7 @@ export type LabelSnapshot = {
|
|
|
47
50
|
|
|
48
51
|
const EMPTY: LabelSnapshot = { entries: [], vocabulary: defaultVocabulary };
|
|
49
52
|
|
|
50
|
-
const KINDS: LabelKind[] = ['figure', 'table', 'footnote'];
|
|
53
|
+
const KINDS: LabelKind[] = ['figure', 'table', 'footnote', 'citation'];
|
|
51
54
|
|
|
52
55
|
function isKind(value: string | null): value is LabelKind {
|
|
53
56
|
return value !== null && (KINDS as string[]).includes(value);
|
|
@@ -61,7 +64,12 @@ function isKind(value: string | null): value is LabelKind {
|
|
|
61
64
|
*/
|
|
62
65
|
export function collectLabels(root: ParentNode): LabelEntry[] {
|
|
63
66
|
const entries: LabelEntry[] = [];
|
|
64
|
-
const counters: Record<LabelKind, number> = {
|
|
67
|
+
const counters: Record<LabelKind, number> = {
|
|
68
|
+
figure: 0,
|
|
69
|
+
table: 0,
|
|
70
|
+
footnote: 0,
|
|
71
|
+
citation: 0,
|
|
72
|
+
};
|
|
65
73
|
const frames = Array.from(root.querySelectorAll<HTMLElement>(`[${PAGE_ATTR}]`));
|
|
66
74
|
|
|
67
75
|
frames.forEach((frame, fallbackIndex) => {
|
|
@@ -73,17 +81,23 @@ export function collectLabels(root: ParentNode): LabelEntry[] {
|
|
|
73
81
|
if (!isKind(kind)) continue;
|
|
74
82
|
const id = el.getAttribute(LABEL_ID_ATTR);
|
|
75
83
|
if (!id) continue;
|
|
84
|
+
const text = (el.getAttribute(LABEL_TEXT_ATTR) ?? el.textContent ?? '')
|
|
85
|
+
.replace(/\s+/g, ' ')
|
|
86
|
+
.trim();
|
|
76
87
|
// A footnote's marker and the note at the foot of the page carry the same
|
|
77
|
-
// id; the marker is what fixes its position in the sequence.
|
|
78
|
-
|
|
88
|
+
// id; the marker is what fixes its position in the sequence. Same for repeated `<Cite id>`
|
|
89
|
+
// calls — the first appearance fixes its citation number, and later ones reuse it.
|
|
90
|
+
const existing = entries.find((entry) => entry.kind === kind && entry.id === id);
|
|
91
|
+
if (existing) {
|
|
92
|
+
if (!existing.text && text) existing.text = text;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
79
95
|
counters[kind] += 1;
|
|
80
96
|
entries.push({
|
|
81
97
|
id,
|
|
82
98
|
kind,
|
|
83
99
|
number: counters[kind],
|
|
84
|
-
text
|
|
85
|
-
.replace(/\s+/g, ' ')
|
|
86
|
-
.trim(),
|
|
100
|
+
text,
|
|
87
101
|
page,
|
|
88
102
|
});
|
|
89
103
|
}
|
|
@@ -124,6 +138,7 @@ function sameVocabulary(a: LabelVocabulary, b: LabelVocabulary): boolean {
|
|
|
124
138
|
a.figure === b.figure &&
|
|
125
139
|
a.table === b.table &&
|
|
126
140
|
a.footnotes === b.footnotes &&
|
|
141
|
+
a.bibliography === b.bibliography &&
|
|
127
142
|
a.onPage === b.onPage
|
|
128
143
|
);
|
|
129
144
|
}
|
|
@@ -162,8 +177,12 @@ export function useDocLabels(kind: LabelKind): LabelEntry[] {
|
|
|
162
177
|
}
|
|
163
178
|
|
|
164
179
|
/** One numbered item by id, once the scan has run. */
|
|
165
|
-
export function useDocLabel(id: string): LabelEntry | null {
|
|
166
|
-
return
|
|
180
|
+
export function useDocLabel(id: string, kind?: LabelKind): LabelEntry | null {
|
|
181
|
+
return (
|
|
182
|
+
useLabelSnapshot().entries.find(
|
|
183
|
+
(entry) => entry.id === id && (kind === undefined || entry.kind === kind),
|
|
184
|
+
) ?? null
|
|
185
|
+
);
|
|
167
186
|
}
|
|
168
187
|
|
|
169
188
|
export function useLabelVocabulary(): LabelVocabulary {
|
package/src/app/lib/sdk.ts
CHANGED
|
@@ -62,6 +62,10 @@ export type FlowSection = {
|
|
|
62
62
|
footer?: ComponentType;
|
|
63
63
|
/** Page padding override in px; defaults to the design's `margin`. */
|
|
64
64
|
padding?: number;
|
|
65
|
+
/** Number of columns for body content inside each page of this flow section. */
|
|
66
|
+
columns?: 1 | 2 | 3;
|
|
67
|
+
/** Gap in px between columns when `columns > 1`; defaults to 24. */
|
|
68
|
+
columnGap?: number;
|
|
65
69
|
};
|
|
66
70
|
|
|
67
71
|
/** What a document's default export may contain: fixed pages, flow sections, or both. */
|
|
@@ -101,6 +105,8 @@ export type DocMeta = {
|
|
|
101
105
|
recordName?: string;
|
|
102
106
|
/** With `records`: the column that names a row in the viewer's picker. */
|
|
103
107
|
recordLabel?: string;
|
|
108
|
+
/** Diagonal watermark text stamped across every sheet (e.g. 'CONFIDENTIAL', 'DRAFT'). */
|
|
109
|
+
watermark?: string;
|
|
104
110
|
};
|
|
105
111
|
|
|
106
112
|
/**
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { createElement, type ReactNode, useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import { FlowPage } from '../components/flow-page';
|
|
3
3
|
import type { DesignSystem } from './design';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
type BlockSlice,
|
|
6
|
+
type DocEntry,
|
|
7
|
+
type FlowSection,
|
|
8
|
+
isFlowSection,
|
|
9
|
+
paginateBlocks,
|
|
10
|
+
} from './flow';
|
|
5
11
|
import { type MeasurableSection, measureFlowSections } from './flow-measure';
|
|
6
12
|
import { extractSectionFootnotes, notesForPage, type PreparedSection } from './footnotes';
|
|
7
13
|
import { useRecordIndex } from './records';
|
|
@@ -13,8 +19,8 @@ export type ExpandedPage = {
|
|
|
13
19
|
};
|
|
14
20
|
|
|
15
21
|
type Plan = {
|
|
16
|
-
/** Section index → block
|
|
17
|
-
bySection:
|
|
22
|
+
/** Section index → block slices per page. */
|
|
23
|
+
bySection: BlockSlice[][][];
|
|
18
24
|
overflowing: Array<{ section: number; block: number }>;
|
|
19
25
|
};
|
|
20
26
|
|
|
@@ -59,6 +65,8 @@ export function useDocPages(
|
|
|
59
65
|
blocks: prepared[index].blocks,
|
|
60
66
|
notesByBlock: prepared[index].notesByBlock,
|
|
61
67
|
...(section.padding !== undefined ? { padding: section.padding } : {}),
|
|
68
|
+
...(section.columns !== undefined ? { columns: section.columns } : {}),
|
|
69
|
+
...(section.columnGap !== undefined ? { columnGap: section.columnGap } : {}),
|
|
62
70
|
})),
|
|
63
71
|
[sections, prepared],
|
|
64
72
|
);
|
|
@@ -79,13 +87,13 @@ export function useDocPages(
|
|
|
79
87
|
measureFlowSections(measurable, { geometry, design, lang })
|
|
80
88
|
.then((measurements) => {
|
|
81
89
|
if (cancelled) return;
|
|
82
|
-
const bySection:
|
|
90
|
+
const bySection: BlockSlice[][][] = [];
|
|
83
91
|
const overflowing: Plan['overflowing'] = [];
|
|
84
92
|
measurements.forEach((measurement, sectionIndex) => {
|
|
85
93
|
const result = paginateBlocks(measurement.metrics, measurement.available, {
|
|
86
94
|
footnoteOverhead: measurement.footnoteOverhead,
|
|
87
95
|
});
|
|
88
|
-
bySection.push(result.
|
|
96
|
+
bySection.push(result.slices);
|
|
89
97
|
for (const block of result.overflowing) {
|
|
90
98
|
overflowing.push({ section: sectionIndex, block });
|
|
91
99
|
}
|
|
@@ -118,16 +126,23 @@ export function useDocPages(
|
|
|
118
126
|
const blocks = ready?.blocks ?? section.blocks;
|
|
119
127
|
// Before measurement lands, render the section as a single page so the
|
|
120
128
|
// viewer shows something rather than flashing empty.
|
|
121
|
-
const chunks = plan.bySection[sectionIndex] ?? [
|
|
122
|
-
|
|
129
|
+
const chunks: BlockSlice[][] = plan.bySection[sectionIndex] ?? [
|
|
130
|
+
blocks.map((_, index) => ({ index })),
|
|
131
|
+
];
|
|
132
|
+
chunks.forEach((blockSlices, pageIndex) => {
|
|
133
|
+
const blockIndices = blockSlices.map((s) => s.index);
|
|
134
|
+
const noteIndices = blockSlices
|
|
135
|
+
.filter((s) => s.rowStart === undefined || s.rowStart === 0)
|
|
136
|
+
.map((s) => s.index);
|
|
123
137
|
out.push({
|
|
124
138
|
key: `f${entryIndex}-${pageIndex}`,
|
|
125
139
|
content: createElement(FlowPage, {
|
|
126
140
|
section,
|
|
127
141
|
design,
|
|
128
142
|
blockIndices,
|
|
143
|
+
blockSlices,
|
|
129
144
|
blocks,
|
|
130
|
-
notes: ready ? notesForPage(ready.notesByBlock,
|
|
145
|
+
notes: ready ? notesForPage(ready.notesByBlock, noteIndices) : [],
|
|
131
146
|
}),
|
|
132
147
|
});
|
|
133
148
|
});
|
package/src/app/routes/doc.tsx
CHANGED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
//#region src/config.d.ts
|
|
2
|
-
type OpenDocBuildConfig = {
|
|
3
|
-
/** Ship the document browser (`/`) in the static build. Defaults to true. */
|
|
4
|
-
showDocBrowser?: boolean;
|
|
5
|
-
/** Offer the "Export HTML" button in the static build. Defaults to true. */
|
|
6
|
-
allowHtmlExport?: boolean;
|
|
7
|
-
};
|
|
8
|
-
type OpenDocConfig = {
|
|
9
|
-
base?: string;
|
|
10
|
-
/**
|
|
11
|
-
* Where the viewer's back affordance goes. Unset it points at this app's own
|
|
12
|
-
* document browser; set it to escape the app entirely — a viewer mounted
|
|
13
|
-
* under a larger site needs to return to that site, not to its own index.
|
|
14
|
-
*/
|
|
15
|
-
home?: string;
|
|
16
|
-
docsDir?: string;
|
|
17
|
-
themesDir?: string;
|
|
18
|
-
assetsDir?: string;
|
|
19
|
-
port?: number;
|
|
20
|
-
allowedHosts?: string[] | true;
|
|
21
|
-
build?: OpenDocBuildConfig;
|
|
22
|
-
};
|
|
23
|
-
//#endregion
|
|
24
|
-
export { OpenDocConfig as n, OpenDocBuildConfig as t };
|