@open-document/core 0.2.0 → 0.3.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.
- package/dist/{build-U81g9Hnk.js → build-C3pMGxJN.js} +1 -1
- package/dist/check-Dtwb1wvU.js +42 -0
- package/dist/cli/bin.js +24 -3
- package/dist/config-Dg1AMP0r.js +2461 -0
- package/dist/context-FoX0afRf.js +26 -0
- package/dist/{dev-DwwFT6uX.js → dev-Cdd7NZRQ.js} +1 -1
- package/dist/diagram-xlVDekYk.js +763 -0
- package/dist/export-ClJ4T1uU.js +36 -0
- package/dist/import-D7Psi8WK.js +25 -0
- package/dist/index.d.ts +235 -90
- package/dist/index.js +515 -49
- package/dist/ops/index.d.ts +96 -1
- package/dist/ops/index.js +3 -199
- package/dist/ops-Ci5Xw6QG.js +1270 -0
- package/dist/{preview-C_jbySle.js → preview-BhbCiAKC.js} +1 -1
- package/dist/sdk-CWMsH9Ms.d.ts +123 -0
- package/dist/vite/index.d.ts +6 -0
- package/dist/vite/index.js +1 -2
- package/env.d.ts +33 -1
- package/package.json +10 -1
- package/skills/create-doc/SKILL.md +6 -2
- package/skills/doc-authoring/SKILL.md +79 -0
- package/skills/doc-authoring/references/long-form.md +131 -0
- package/src/app/components/data-table.tsx +196 -0
- package/src/app/components/diagram.tsx +76 -0
- package/src/app/components/flow-page.tsx +20 -3
- package/src/app/components/footnote.tsx +196 -0
- package/src/app/components/numbering.tsx +208 -0
- package/src/app/lib/agent-bridge.ts +128 -0
- package/src/app/lib/diagnostics.ts +282 -0
- package/src/app/lib/export-html.ts +35 -11
- package/src/app/lib/export-pdf.ts +54 -19
- package/src/app/lib/flow-measure.ts +100 -31
- package/src/app/lib/flow.test.ts +46 -0
- package/src/app/lib/flow.ts +28 -3
- package/src/app/lib/footnotes.test.tsx +102 -0
- package/src/app/lib/footnotes.ts +94 -0
- package/src/app/lib/labels.ts +175 -0
- package/src/app/lib/page-context.tsx +6 -1
- package/src/app/lib/scan.ts +26 -0
- package/src/app/lib/sdk.ts +3 -0
- package/src/app/lib/use-doc-pages.ts +50 -15
- package/src/app/routes/doc.tsx +7 -4
- package/dist/config-8zkUElGq.js +0 -1169
- package/dist/design-IyRSwCtK.js +0 -52
- package/dist/edit-ops-D2W2plpc.js +0 -1190
package/dist/index.js
CHANGED
|
@@ -1,60 +1,189 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Fragment,
|
|
3
|
-
import {
|
|
4
|
-
//#region src/app/
|
|
1
|
+
import { a as defaultDesign, i as cssVarsToString, n as DiagramSyntaxError, o as designToCssVars, r as parseDelimited, t as compileDiagram } from "./diagram-xlVDekYk.js";
|
|
2
|
+
import { Children, Fragment, createContext, isValidElement, useContext, useEffect, useId, useRef, useSyncExternalStore } from "react";
|
|
3
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
//#region src/app/lib/outline.ts
|
|
5
|
+
const GLOBAL_KEY$3 = "__open_doc_outline_store__";
|
|
6
|
+
const g$3 = globalThis;
|
|
7
|
+
if (!g$3[GLOBAL_KEY$3]) g$3[GLOBAL_KEY$3] = {
|
|
8
|
+
snapshot: [],
|
|
9
|
+
listeners: /* @__PURE__ */ new Set()
|
|
10
|
+
};
|
|
11
|
+
const store$1 = g$3[GLOBAL_KEY$3];
|
|
12
|
+
function getOutline() {
|
|
13
|
+
return store$1.snapshot;
|
|
14
|
+
}
|
|
15
|
+
function subscribe$1(listener) {
|
|
16
|
+
store$1.listeners.add(listener);
|
|
17
|
+
return () => store$1.listeners.delete(listener);
|
|
18
|
+
}
|
|
5
19
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
20
|
+
* The document's headings, filled in after the pages render. Empty on the first
|
|
21
|
+
* pass — a `<TableOfContents>` renders its rows on the second, once the scan
|
|
22
|
+
* has run.
|
|
9
23
|
*/
|
|
10
|
-
function
|
|
11
|
-
return
|
|
12
|
-
"data-od-image-placeholder": "",
|
|
13
|
-
className,
|
|
14
|
-
style: {
|
|
15
|
-
width,
|
|
16
|
-
height,
|
|
17
|
-
display: "flex",
|
|
18
|
-
alignItems: "center",
|
|
19
|
-
justifyContent: "center",
|
|
20
|
-
textAlign: "center",
|
|
21
|
-
padding: 16,
|
|
22
|
-
boxSizing: "border-box",
|
|
23
|
-
border: "1px dashed var(--od-rule, #d4d4d8)",
|
|
24
|
-
borderRadius: "var(--od-radius, 6px)",
|
|
25
|
-
background: "repeating-linear-gradient(45deg, rgba(0,0,0,.02) 0 8px, transparent 8px 16px)",
|
|
26
|
-
color: "var(--od-muted, #6b7280)",
|
|
27
|
-
fontFamily: "var(--od-font-body, system-ui, sans-serif)",
|
|
28
|
-
fontSize: "var(--od-size-caption, 10px)",
|
|
29
|
-
lineHeight: 1.4,
|
|
30
|
-
...style
|
|
31
|
-
},
|
|
32
|
-
children: hint
|
|
33
|
-
});
|
|
24
|
+
function useDocOutline() {
|
|
25
|
+
return useSyncExternalStore(subscribe$1, getOutline, getOutline);
|
|
34
26
|
}
|
|
35
27
|
//#endregion
|
|
36
|
-
//#region src/app/lib/
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
28
|
+
//#region src/app/lib/labels.ts
|
|
29
|
+
const LABEL_ATTR = "data-od-label";
|
|
30
|
+
const LABEL_ID_ATTR = "data-od-label-id";
|
|
31
|
+
const LABEL_TEXT_ATTR = "data-od-label-text";
|
|
32
|
+
const EMPTY = {
|
|
33
|
+
entries: [],
|
|
34
|
+
vocabulary: {
|
|
35
|
+
figure: "Figure",
|
|
36
|
+
table: "Table",
|
|
37
|
+
footnotes: "",
|
|
38
|
+
onPage: " (p. {page})"
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const GLOBAL_KEY$2 = "__open_doc_labels_store__";
|
|
42
|
+
const g$2 = globalThis;
|
|
43
|
+
if (!g$2[GLOBAL_KEY$2]) g$2[GLOBAL_KEY$2] = {
|
|
44
|
+
snapshot: EMPTY,
|
|
41
45
|
listeners: /* @__PURE__ */ new Set()
|
|
42
46
|
};
|
|
43
|
-
const store = g$
|
|
44
|
-
function
|
|
47
|
+
const store = g$2[GLOBAL_KEY$2];
|
|
48
|
+
function getLabels() {
|
|
45
49
|
return store.snapshot;
|
|
46
50
|
}
|
|
47
51
|
function subscribe(listener) {
|
|
48
52
|
store.listeners.add(listener);
|
|
49
53
|
return () => store.listeners.delete(listener);
|
|
50
54
|
}
|
|
55
|
+
function useLabelSnapshot() {
|
|
56
|
+
return useSyncExternalStore(subscribe, getLabels, getLabels);
|
|
57
|
+
}
|
|
58
|
+
/** The document's numbered items of one kind, in order. Empty on the first render pass. */
|
|
59
|
+
function useDocLabels(kind) {
|
|
60
|
+
return useLabelSnapshot().entries.filter((entry) => entry.kind === kind);
|
|
61
|
+
}
|
|
62
|
+
/** One numbered item by id, once the scan has run. */
|
|
63
|
+
function useDocLabel(id) {
|
|
64
|
+
return useLabelSnapshot().entries.find((entry) => entry.id === id) ?? null;
|
|
65
|
+
}
|
|
66
|
+
function useLabelVocabulary() {
|
|
67
|
+
return useLabelSnapshot().vocabulary;
|
|
68
|
+
}
|
|
69
|
+
function formatOnPage(vocabulary, page) {
|
|
70
|
+
return vocabulary.onPage.replace("{page}", String(page));
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/app/components/footnote.tsx
|
|
74
|
+
/** Stands in for a number the scan has not produced yet, or never will. */
|
|
75
|
+
const UNNUMBERED = "•";
|
|
76
|
+
const GLOBAL_KEY$1 = "__open_doc_footnote_context__";
|
|
77
|
+
const g$1 = globalThis;
|
|
78
|
+
if (!g$1[GLOBAL_KEY$1]) g$1[GLOBAL_KEY$1] = createContext(null);
|
|
79
|
+
const FootnoteContext = g$1[GLOBAL_KEY$1];
|
|
80
|
+
const FOOTNOTE_MARKER_FLAG = "__odFootnote";
|
|
81
|
+
function markerStyle() {
|
|
82
|
+
return {
|
|
83
|
+
fontSize: "0.7em",
|
|
84
|
+
lineHeight: 0,
|
|
85
|
+
verticalAlign: "super",
|
|
86
|
+
fontVariantNumeric: "tabular-nums",
|
|
87
|
+
color: "var(--od-accent)",
|
|
88
|
+
padding: "0 1px"
|
|
89
|
+
};
|
|
90
|
+
}
|
|
51
91
|
/**
|
|
52
|
-
* The
|
|
53
|
-
*
|
|
54
|
-
*
|
|
92
|
+
* The superscript in the text. Its position in the document decides the number.
|
|
93
|
+
*
|
|
94
|
+
* The placeholder is the one the printed note uses, and deliberately not an
|
|
95
|
+
* empty string: the two describe the same unresolved state, a note whose number
|
|
96
|
+
* never arrives has to be visible in both places rather than silently blank,
|
|
97
|
+
* and the packer measures this glyph — an empty marker is narrower than the
|
|
98
|
+
* digit that replaces it.
|
|
55
99
|
*/
|
|
56
|
-
function
|
|
57
|
-
|
|
100
|
+
function FootnoteMarker({ id }) {
|
|
101
|
+
const entry = useDocLabel(id);
|
|
102
|
+
return /* @__PURE__ */ jsx("sup", {
|
|
103
|
+
[LABEL_ATTR]: "footnote",
|
|
104
|
+
[LABEL_ID_ATTR]: id,
|
|
105
|
+
style: markerStyle(),
|
|
106
|
+
children: entry?.number ?? UNNUMBERED
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* A note anchored to this point in the text. Inside a `flow()` section the
|
|
111
|
+
* framework lifts it to the foot of whatever page the marker lands on; on a
|
|
112
|
+
* fixed page, put a `<Footnotes />` where you want them printed.
|
|
113
|
+
*/
|
|
114
|
+
function Footnote({ id, children }) {
|
|
115
|
+
const generated = useId();
|
|
116
|
+
const noteId = id ?? generated;
|
|
117
|
+
const collector = useContext(FootnoteContext);
|
|
118
|
+
const latest = useRef(null);
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
latest.current = collector;
|
|
121
|
+
collector?.register(noteId, children);
|
|
122
|
+
});
|
|
123
|
+
useEffect(() => () => latest.current?.unregister(noteId), [noteId]);
|
|
124
|
+
return /* @__PURE__ */ jsx(FootnoteMarker, { id: noteId });
|
|
125
|
+
}
|
|
126
|
+
Footnote[FOOTNOTE_MARKER_FLAG] = true;
|
|
127
|
+
const FOOTNOTE_ROW_ATTR = "data-od-footnote-row";
|
|
128
|
+
function footnoteAreaStyle() {
|
|
129
|
+
return {
|
|
130
|
+
borderTop: "1px solid var(--od-rule)",
|
|
131
|
+
paddingTop: 6,
|
|
132
|
+
marginTop: 12,
|
|
133
|
+
fontSize: "var(--od-size-caption)",
|
|
134
|
+
lineHeight: 1.45,
|
|
135
|
+
color: "var(--od-muted)"
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/** One note's row. Shared with the measurement pass so the reserved space is real. */
|
|
139
|
+
function FootnoteRow({ id, content }) {
|
|
140
|
+
const entry = useDocLabel(id);
|
|
141
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
142
|
+
[FOOTNOTE_ROW_ATTR]: "",
|
|
143
|
+
style: {
|
|
144
|
+
display: "flex",
|
|
145
|
+
gap: 5,
|
|
146
|
+
marginBottom: 3
|
|
147
|
+
},
|
|
148
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
149
|
+
style: {
|
|
150
|
+
flex: "none",
|
|
151
|
+
fontVariantNumeric: "tabular-nums",
|
|
152
|
+
color: "var(--od-accent)"
|
|
153
|
+
},
|
|
154
|
+
children: entry?.number ?? UNNUMBERED
|
|
155
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
156
|
+
style: { minWidth: 0 },
|
|
157
|
+
children: content
|
|
158
|
+
})]
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
function Footnotes({ notes, style, className }) {
|
|
162
|
+
const collector = useContext(FootnoteContext);
|
|
163
|
+
const vocabulary = useLabelVocabulary();
|
|
164
|
+
const list = notes ?? collector?.ids.map((id) => ({
|
|
165
|
+
id,
|
|
166
|
+
content: collector.contents.get(id)
|
|
167
|
+
})) ?? [];
|
|
168
|
+
if (list.length === 0) return null;
|
|
169
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
170
|
+
"data-od-footnotes": "",
|
|
171
|
+
className,
|
|
172
|
+
style: {
|
|
173
|
+
...footnoteAreaStyle(),
|
|
174
|
+
...style
|
|
175
|
+
},
|
|
176
|
+
children: [vocabulary.footnotes ? /* @__PURE__ */ jsx("div", {
|
|
177
|
+
style: {
|
|
178
|
+
fontWeight: 600,
|
|
179
|
+
marginBottom: 3
|
|
180
|
+
},
|
|
181
|
+
children: vocabulary.footnotes
|
|
182
|
+
}) : null, list.map((note) => /* @__PURE__ */ jsx(FootnoteRow, {
|
|
183
|
+
id: note.id,
|
|
184
|
+
content: note.content
|
|
185
|
+
}, note.id))]
|
|
186
|
+
});
|
|
58
187
|
}
|
|
59
188
|
//#endregion
|
|
60
189
|
//#region src/app/lib/page-context.tsx
|
|
@@ -73,6 +202,330 @@ function useDocPageCount() {
|
|
|
73
202
|
return ctx ? ctx.total : 0;
|
|
74
203
|
}
|
|
75
204
|
//#endregion
|
|
205
|
+
//#region src/app/components/numbering.tsx
|
|
206
|
+
function nameFor(kind, vocabulary) {
|
|
207
|
+
return kind === "table" ? vocabulary.table : vocabulary.figure;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* A numbered figure or table. The number comes from a scan of the rendered
|
|
211
|
+
* pages, not from a counter in the source, so inserting a figure halfway
|
|
212
|
+
* through a document renumbers everything after it — including the references
|
|
213
|
+
* to it — without anyone editing a number.
|
|
214
|
+
*
|
|
215
|
+
* Caption and content are one block, so a `flow()` section never separates them.
|
|
216
|
+
*/
|
|
217
|
+
function Figure({ id, caption, kind = "figure", captionPosition, captionText, style, captionStyle, className, children }) {
|
|
218
|
+
const generated = useId();
|
|
219
|
+
const labelId = id ?? generated;
|
|
220
|
+
const entry = useDocLabel(labelId);
|
|
221
|
+
const vocabulary = useLabelVocabulary();
|
|
222
|
+
const position = captionPosition ?? (kind === "table" ? "above" : "below");
|
|
223
|
+
const text = captionText ?? (typeof caption === "string" || typeof caption === "number" ? String(caption) : "");
|
|
224
|
+
const captionNode = caption ? /* @__PURE__ */ jsxs("figcaption", {
|
|
225
|
+
style: {
|
|
226
|
+
fontSize: "var(--od-size-caption)",
|
|
227
|
+
color: "var(--od-muted)",
|
|
228
|
+
lineHeight: 1.4,
|
|
229
|
+
margin: position === "above" ? "0 0 6px" : "6px 0 0",
|
|
230
|
+
...captionStyle
|
|
231
|
+
},
|
|
232
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
233
|
+
style: {
|
|
234
|
+
fontWeight: 600,
|
|
235
|
+
color: "var(--od-text)"
|
|
236
|
+
},
|
|
237
|
+
children: [
|
|
238
|
+
nameFor(kind, vocabulary),
|
|
239
|
+
" ",
|
|
240
|
+
entry?.number ?? ""
|
|
241
|
+
]
|
|
242
|
+
}), caption ? /* @__PURE__ */ jsxs("span", { children: [" — ", caption] }) : null]
|
|
243
|
+
}) : null;
|
|
244
|
+
return /* @__PURE__ */ jsxs("figure", {
|
|
245
|
+
[LABEL_ATTR]: kind,
|
|
246
|
+
[LABEL_ID_ATTR]: labelId,
|
|
247
|
+
[LABEL_TEXT_ATTR]: text,
|
|
248
|
+
className,
|
|
249
|
+
style: {
|
|
250
|
+
margin: "0 0 16px",
|
|
251
|
+
...style
|
|
252
|
+
},
|
|
253
|
+
children: [
|
|
254
|
+
position === "above" && captionNode,
|
|
255
|
+
children,
|
|
256
|
+
position === "below" && captionNode
|
|
257
|
+
]
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* A cross-reference that resolves after layout: "Figure 3", plus the page when
|
|
262
|
+
* the target is elsewhere. Never write "see Figure 3 on page 12" by hand — both
|
|
263
|
+
* numbers move.
|
|
264
|
+
*/
|
|
265
|
+
function Ref({ to, showPage = "auto", style, className }) {
|
|
266
|
+
const entry = useDocLabel(to);
|
|
267
|
+
const vocabulary = useLabelVocabulary();
|
|
268
|
+
const here = useDocPageNumber();
|
|
269
|
+
if (!entry) return /* @__PURE__ */ jsxs("span", {
|
|
270
|
+
"data-od-ref-unresolved": to,
|
|
271
|
+
className,
|
|
272
|
+
style: {
|
|
273
|
+
color: "var(--od-accent)",
|
|
274
|
+
...style
|
|
275
|
+
},
|
|
276
|
+
children: [
|
|
277
|
+
"[?",
|
|
278
|
+
to,
|
|
279
|
+
"]"
|
|
280
|
+
]
|
|
281
|
+
});
|
|
282
|
+
const name = entry.kind === "footnote" ? "" : `${nameFor(entry.kind, vocabulary)} `;
|
|
283
|
+
const withPage = showPage === "auto" ? entry.page !== here : showPage;
|
|
284
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
285
|
+
"data-od-ref": to,
|
|
286
|
+
className,
|
|
287
|
+
style,
|
|
288
|
+
children: [
|
|
289
|
+
name,
|
|
290
|
+
entry.number,
|
|
291
|
+
withPage ? formatOnPage(vocabulary, entry.page) : ""
|
|
292
|
+
]
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* The document's figures or tables as a contents list. Same lifecycle as
|
|
297
|
+
* `<TableOfContents>`: empty on the first render pass, filled once the scan has
|
|
298
|
+
* run — including before an export serializes.
|
|
299
|
+
*/
|
|
300
|
+
function ListOf({ kind = "figure", showPageNumbers = true, style, className }) {
|
|
301
|
+
const entries = useDocLabels(kind);
|
|
302
|
+
const vocabulary = useLabelVocabulary();
|
|
303
|
+
return /* @__PURE__ */ jsx("div", {
|
|
304
|
+
"data-od-list-of": kind,
|
|
305
|
+
className,
|
|
306
|
+
style: {
|
|
307
|
+
fontFamily: "var(--od-font-body)",
|
|
308
|
+
fontSize: "var(--od-size-body)",
|
|
309
|
+
color: "var(--od-text)",
|
|
310
|
+
...style
|
|
311
|
+
},
|
|
312
|
+
children: entries.map((entry) => /* @__PURE__ */ jsxs("div", {
|
|
313
|
+
style: {
|
|
314
|
+
display: "flex",
|
|
315
|
+
alignItems: "baseline",
|
|
316
|
+
gap: 8,
|
|
317
|
+
marginBottom: 6
|
|
318
|
+
},
|
|
319
|
+
children: [
|
|
320
|
+
/* @__PURE__ */ jsxs("span", {
|
|
321
|
+
style: {
|
|
322
|
+
flex: "none",
|
|
323
|
+
color: "var(--od-muted)"
|
|
324
|
+
},
|
|
325
|
+
children: [
|
|
326
|
+
nameFor(kind, vocabulary),
|
|
327
|
+
" ",
|
|
328
|
+
entry.number
|
|
329
|
+
]
|
|
330
|
+
}),
|
|
331
|
+
/* @__PURE__ */ jsx("span", { children: entry.text }),
|
|
332
|
+
showPageNumbers && /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", {
|
|
333
|
+
"aria-hidden": true,
|
|
334
|
+
style: {
|
|
335
|
+
flex: 1,
|
|
336
|
+
borderBottom: "1px dotted var(--od-rule)",
|
|
337
|
+
transform: "translateY(-3px)"
|
|
338
|
+
}
|
|
339
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
340
|
+
style: { fontVariantNumeric: "tabular-nums" },
|
|
341
|
+
children: entry.page
|
|
342
|
+
})] })
|
|
343
|
+
]
|
|
344
|
+
}, entry.id))
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
function ListOfFigures(props) {
|
|
348
|
+
return /* @__PURE__ */ jsx(ListOf, {
|
|
349
|
+
...props,
|
|
350
|
+
kind: "figure"
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
function ListOfTables(props) {
|
|
354
|
+
return /* @__PURE__ */ jsx(ListOf, {
|
|
355
|
+
...props,
|
|
356
|
+
kind: "table"
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
//#endregion
|
|
360
|
+
//#region src/app/components/data-table.tsx
|
|
361
|
+
function normalizeColumn(column) {
|
|
362
|
+
return typeof column === "string" ? { key: column } : column;
|
|
363
|
+
}
|
|
364
|
+
function isNumber(value) {
|
|
365
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
366
|
+
}
|
|
367
|
+
/** A column of numbers aligns right; anything mixed stays left. */
|
|
368
|
+
function inferAlign(rows, key) {
|
|
369
|
+
let seen = 0;
|
|
370
|
+
for (const row of rows) {
|
|
371
|
+
const value = row[key];
|
|
372
|
+
if (value === null || value === void 0 || value === "") continue;
|
|
373
|
+
if (!isNumber(value)) return "left";
|
|
374
|
+
seen++;
|
|
375
|
+
}
|
|
376
|
+
return seen > 0 ? "right" : "left";
|
|
377
|
+
}
|
|
378
|
+
function formatValue(value, format, row, emptyValue) {
|
|
379
|
+
if (typeof format === "function") return format(value, row);
|
|
380
|
+
if (value === null || value === void 0 || value === "") return emptyValue;
|
|
381
|
+
if (isNumber(value)) {
|
|
382
|
+
if (format === "integer") return Math.round(value).toLocaleString();
|
|
383
|
+
if (format === "percent") return `${(value * 100).toLocaleString(void 0, { maximumFractionDigits: 1 })}%`;
|
|
384
|
+
if (format === "text") return String(value);
|
|
385
|
+
return value.toLocaleString(void 0, { maximumFractionDigits: 2 });
|
|
386
|
+
}
|
|
387
|
+
return String(value);
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* A print-shaped table from data, so the numbers in a report come from a file
|
|
391
|
+
* instead of being retyped into JSX. Alignment and grouping follow the column's
|
|
392
|
+
* contents, which is the part people get wrong by hand.
|
|
393
|
+
*/
|
|
394
|
+
function DataTable({ rows, columns, caption, id, limit, compact = false, emptyValue = "—", style, className }) {
|
|
395
|
+
const resolved = (columns ?? Object.keys(rows[0] ?? {})).map(normalizeColumn);
|
|
396
|
+
const shown = limit !== void 0 ? rows.slice(0, limit) : rows;
|
|
397
|
+
const hidden = rows.length - shown.length;
|
|
398
|
+
const cellPadding = compact ? "4px 8px" : "7px 8px";
|
|
399
|
+
const table = /* @__PURE__ */ jsxs("table", {
|
|
400
|
+
className,
|
|
401
|
+
style: {
|
|
402
|
+
width: "100%",
|
|
403
|
+
borderCollapse: "collapse",
|
|
404
|
+
tableLayout: "fixed",
|
|
405
|
+
margin: 0,
|
|
406
|
+
...style
|
|
407
|
+
},
|
|
408
|
+
children: [
|
|
409
|
+
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", { children: resolved.map((column) => {
|
|
410
|
+
const align = column.align ?? inferAlign(rows, column.key);
|
|
411
|
+
return /* @__PURE__ */ jsx("th", {
|
|
412
|
+
style: {
|
|
413
|
+
textAlign: align,
|
|
414
|
+
width: column.width,
|
|
415
|
+
fontFamily: "var(--od-font-heading)",
|
|
416
|
+
fontSize: 11,
|
|
417
|
+
fontWeight: 600,
|
|
418
|
+
letterSpacing: "0.04em",
|
|
419
|
+
textTransform: "uppercase",
|
|
420
|
+
color: "var(--od-muted)",
|
|
421
|
+
borderBottom: "1px solid var(--od-rule)",
|
|
422
|
+
padding: "0 8px 6px"
|
|
423
|
+
},
|
|
424
|
+
children: column.label ?? column.key
|
|
425
|
+
}, column.key);
|
|
426
|
+
}) }) }),
|
|
427
|
+
/* @__PURE__ */ jsx("tbody", { children: shown.map((row, rowIndex) => /* @__PURE__ */ jsx("tr", { children: resolved.map((column) => {
|
|
428
|
+
const align = column.align ?? inferAlign(rows, column.key);
|
|
429
|
+
return /* @__PURE__ */ jsx("td", {
|
|
430
|
+
style: {
|
|
431
|
+
textAlign: align,
|
|
432
|
+
fontSize: compact ? 11 : 12,
|
|
433
|
+
padding: cellPadding,
|
|
434
|
+
borderBottom: "1px solid var(--od-rule)",
|
|
435
|
+
fontVariantNumeric: align === "right" ? "tabular-nums" : void 0,
|
|
436
|
+
overflowWrap: "anywhere"
|
|
437
|
+
},
|
|
438
|
+
children: formatValue(row[column.key], column.format, row, emptyValue)
|
|
439
|
+
}, column.key);
|
|
440
|
+
}) }, rowIndex)) }),
|
|
441
|
+
hidden > 0 && /* @__PURE__ */ jsx("tfoot", { children: /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsxs("td", {
|
|
442
|
+
colSpan: resolved.length,
|
|
443
|
+
style: {
|
|
444
|
+
fontSize: "var(--od-size-caption)",
|
|
445
|
+
color: "var(--od-muted)",
|
|
446
|
+
padding: "6px 8px 0"
|
|
447
|
+
},
|
|
448
|
+
children: [
|
|
449
|
+
hidden,
|
|
450
|
+
" more row",
|
|
451
|
+
hidden === 1 ? "" : "s",
|
|
452
|
+
" not shown"
|
|
453
|
+
]
|
|
454
|
+
}) }) })
|
|
455
|
+
]
|
|
456
|
+
});
|
|
457
|
+
if (!caption) return table;
|
|
458
|
+
return /* @__PURE__ */ jsx(Figure, {
|
|
459
|
+
kind: "table",
|
|
460
|
+
caption,
|
|
461
|
+
...id !== void 0 ? { id } : {},
|
|
462
|
+
children: table
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
//#endregion
|
|
466
|
+
//#region src/app/components/diagram.tsx
|
|
467
|
+
/**
|
|
468
|
+
* A diagram compiled from Mermaid-flavoured text at build time. The SVG is
|
|
469
|
+
* inlined rather than referenced through `<img>` so it inherits the document's
|
|
470
|
+
* theme variables — an `<img src="data:…">` would be painted in a document of
|
|
471
|
+
* its own, with none of this one's colours or faces.
|
|
472
|
+
*/
|
|
473
|
+
function Diagram({ chart, caption, captionText, kind = "figure", id, width, align = "center", style, className }) {
|
|
474
|
+
const drawing = /* @__PURE__ */ jsx("div", {
|
|
475
|
+
className: caption ? void 0 : className,
|
|
476
|
+
style: {
|
|
477
|
+
width: width ?? chart.width,
|
|
478
|
+
maxWidth: "100%",
|
|
479
|
+
marginLeft: align === "center" ? "auto" : void 0,
|
|
480
|
+
marginRight: align === "center" ? "auto" : void 0,
|
|
481
|
+
...caption ? void 0 : style
|
|
482
|
+
},
|
|
483
|
+
dangerouslySetInnerHTML: { __html: chart.svg }
|
|
484
|
+
});
|
|
485
|
+
if (!caption) return drawing;
|
|
486
|
+
return /* @__PURE__ */ jsx(Figure, {
|
|
487
|
+
...id ? { id } : {},
|
|
488
|
+
caption,
|
|
489
|
+
...captionText ? { captionText } : {},
|
|
490
|
+
kind,
|
|
491
|
+
className,
|
|
492
|
+
...style ? { style } : {},
|
|
493
|
+
children: drawing
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
//#endregion
|
|
497
|
+
//#region src/app/components/image-placeholder.tsx
|
|
498
|
+
/**
|
|
499
|
+
* Stands in for an image the user has to supply (a chart from their data, a
|
|
500
|
+
* product screenshot). Use it instead of inventing filler — never for
|
|
501
|
+
* decoration.
|
|
502
|
+
*/
|
|
503
|
+
function ImagePlaceholder({ hint, width = "100%", height = 200, style, className }) {
|
|
504
|
+
return /* @__PURE__ */ jsx("div", {
|
|
505
|
+
"data-od-image-placeholder": "",
|
|
506
|
+
className,
|
|
507
|
+
style: {
|
|
508
|
+
width,
|
|
509
|
+
height,
|
|
510
|
+
display: "flex",
|
|
511
|
+
alignItems: "center",
|
|
512
|
+
justifyContent: "center",
|
|
513
|
+
textAlign: "center",
|
|
514
|
+
padding: 16,
|
|
515
|
+
boxSizing: "border-box",
|
|
516
|
+
border: "1px dashed var(--od-rule, #d4d4d8)",
|
|
517
|
+
borderRadius: "var(--od-radius, 6px)",
|
|
518
|
+
background: "repeating-linear-gradient(45deg, rgba(0,0,0,.02) 0 8px, transparent 8px 16px)",
|
|
519
|
+
color: "var(--od-muted, #6b7280)",
|
|
520
|
+
fontFamily: "var(--od-font-body, system-ui, sans-serif)",
|
|
521
|
+
fontSize: "var(--od-size-caption, 10px)",
|
|
522
|
+
lineHeight: 1.4,
|
|
523
|
+
...style
|
|
524
|
+
},
|
|
525
|
+
children: hint
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
//#endregion
|
|
76
529
|
//#region src/app/components/table-of-contents.tsx
|
|
77
530
|
/**
|
|
78
531
|
* Renders the document's headings as a contents list. The outline is filled in
|
|
@@ -103,7 +556,7 @@ function TableOfContents({ maxLevel = 2, showPageNumbers = true, includeOwnPage
|
|
|
103
556
|
fontWeight: entry.level === 1 ? 600 : 400,
|
|
104
557
|
color: entry.level === 1 ? "var(--od-text)" : "var(--od-muted)"
|
|
105
558
|
},
|
|
106
|
-
children: [/* @__PURE__ */ jsx("span", { children: entry.text }), showPageNumbers && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
|
|
559
|
+
children: [/* @__PURE__ */ jsx("span", { children: entry.text }), showPageNumbers && /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", {
|
|
107
560
|
"aria-hidden": true,
|
|
108
561
|
style: {
|
|
109
562
|
flex: 1,
|
|
@@ -127,7 +580,7 @@ function toBlocks(node) {
|
|
|
127
580
|
const out = [];
|
|
128
581
|
for (const child of Children.toArray(node)) {
|
|
129
582
|
if (!isValidElement(child)) continue;
|
|
130
|
-
if (child.type === Fragment
|
|
583
|
+
if (child.type === Fragment) {
|
|
131
584
|
out.push(...toBlocks(child.props.children));
|
|
132
585
|
continue;
|
|
133
586
|
}
|
|
@@ -154,23 +607,34 @@ function isFlowSection(entry) {
|
|
|
154
607
|
* Greedy top-to-bottom packing: fill a page until the next block would cross
|
|
155
608
|
* the bottom edge, then push that block — plus anything glued to it — onto the
|
|
156
609
|
* next page. Blocks are atomic; nothing is split mid-block.
|
|
610
|
+
*
|
|
611
|
+
* Footnotes are packed from the same budget: a block that carries notes brings
|
|
612
|
+
* their height with it, because those notes print at the foot of whichever page
|
|
613
|
+
* the block lands on.
|
|
157
614
|
*/
|
|
158
|
-
function paginateBlocks(blocks, available) {
|
|
615
|
+
function paginateBlocks(blocks, available, opts = {}) {
|
|
616
|
+
const overhead = opts.footnoteOverhead ?? 0;
|
|
159
617
|
const pages = [];
|
|
160
618
|
const overflowing = [];
|
|
161
619
|
let current = [];
|
|
162
620
|
let used = 0;
|
|
621
|
+
let notes = 0;
|
|
163
622
|
const heightOf = (indices) => indices.reduce((sum, index) => sum + (blocks[index]?.height ?? 0), 0);
|
|
623
|
+
const notesOf = (indices) => indices.reduce((sum, index) => sum + (blocks[index]?.footnoteHeight ?? 0), 0);
|
|
624
|
+
/** A page with no notes pays nothing; the first note also pays for the rule. */
|
|
625
|
+
const reserve = (total) => total > 0 ? total + overhead : 0;
|
|
164
626
|
const closePage = () => {
|
|
165
627
|
if (current.length === 0) return;
|
|
166
628
|
pages.push(current);
|
|
167
629
|
current = [];
|
|
168
630
|
used = 0;
|
|
631
|
+
notes = 0;
|
|
169
632
|
};
|
|
170
633
|
blocks.forEach((block, index) => {
|
|
171
|
-
|
|
634
|
+
const own = block.footnoteHeight ?? 0;
|
|
635
|
+
if (block.height + reserve(own) > available) overflowing.push(index);
|
|
172
636
|
if (block.breakBefore) closePage();
|
|
173
|
-
if (current.length > 0 && used + block.height > available) {
|
|
637
|
+
if (current.length > 0 && used + block.height + reserve(notes + own) > available) {
|
|
174
638
|
let splitAt = current.length;
|
|
175
639
|
while (splitAt > 0 && blocks[current[splitAt - 1]]?.keepWithNext) splitAt--;
|
|
176
640
|
if (block.keepWithPrevious && splitAt === current.length) splitAt--;
|
|
@@ -179,10 +643,12 @@ function paginateBlocks(blocks, available) {
|
|
|
179
643
|
pages.push(current.slice(0, splitAt));
|
|
180
644
|
current = moved;
|
|
181
645
|
used = heightOf(moved);
|
|
646
|
+
notes = notesOf(moved);
|
|
182
647
|
} else closePage();
|
|
183
648
|
}
|
|
184
649
|
current.push(index);
|
|
185
650
|
used += block.height;
|
|
651
|
+
notes += own;
|
|
186
652
|
});
|
|
187
653
|
closePage();
|
|
188
654
|
return {
|
|
@@ -230,4 +696,4 @@ function resolvePageGeometry(meta) {
|
|
|
230
696
|
};
|
|
231
697
|
}
|
|
232
698
|
//#endregion
|
|
233
|
-
export { DEFAULT_PAGE_SIZE, ImagePlaceholder, PAGE_SIZES, TableOfContents, cssVarsToString, defaultDesign, designToCssVars, flow, isFlowSection, paginateBlocks, resolvePageGeometry, useDocOutline, useDocPageCount, useDocPageNumber };
|
|
699
|
+
export { DEFAULT_PAGE_SIZE, DataTable, Diagram, DiagramSyntaxError, Figure, Footnote, Footnotes, ImagePlaceholder, ListOf, ListOfFigures, ListOfTables, PAGE_SIZES, Ref, TableOfContents, compileDiagram, cssVarsToString, defaultDesign, designToCssVars, flow, isFlowSection, paginateBlocks, parseDelimited, resolvePageGeometry, useDocLabel, useDocLabels, useDocOutline, useDocPageCount, useDocPageNumber };
|