@open-document/core 0.1.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-BWZJ1gvL.js → build-C3pMGxJN.js} +2 -6
- package/dist/check-Dtwb1wvU.js +42 -0
- package/dist/cli/bin.d.ts +1 -1
- package/dist/cli/bin.js +124 -13
- package/dist/{config-EBFfKtWH.d.ts → config-CSC5lHsR.d.ts} +3 -2
- package/dist/config-Dg1AMP0r.js +2461 -0
- package/dist/context-FoX0afRf.js +26 -0
- package/dist/{dev-CZtw1oqs.js → dev-Cdd7NZRQ.js} +2 -6
- 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 +238 -117
- package/dist/index.js +516 -57
- package/dist/ops/index.d.ts +98 -8
- package/dist/ops/index.js +3 -202
- package/dist/ops-Ci5Xw6QG.js +1270 -0
- package/dist/{preview-DUfQl7Ij.js → preview-BhbCiAKC.js} +2 -6
- package/dist/sdk-CWMsH9Ms.d.ts +123 -0
- package/dist/vite/index.d.ts +9 -4
- package/dist/vite/index.js +2 -5
- package/env.d.ts +33 -1
- package/package.json +17 -6
- package/skills/create-doc/SKILL.md +6 -2
- package/skills/current-doc/SKILL.md +120 -0
- 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/inspector/inspector.tsx +16 -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 +25 -5
- package/dist/config-DBp4mOOf.js +0 -1121
- package/dist/design-BJLvOcCO.js +0 -53
- package/dist/edit-ops-DSdUroVO.js +0 -1225
- package/dist/sync-6GTPAt2t.js +0 -86
- package/dist/sync-C6CsPmyK.js +0 -3
package/dist/index.js
CHANGED
|
@@ -1,7 +1,499 @@
|
|
|
1
|
-
import { cssVarsToString,
|
|
2
|
-
import { Fragment,
|
|
3
|
-
import {
|
|
4
|
-
|
|
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
|
+
}
|
|
19
|
+
/**
|
|
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.
|
|
23
|
+
*/
|
|
24
|
+
function useDocOutline() {
|
|
25
|
+
return useSyncExternalStore(subscribe$1, getOutline, getOutline);
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
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,
|
|
45
|
+
listeners: /* @__PURE__ */ new Set()
|
|
46
|
+
};
|
|
47
|
+
const store = g$2[GLOBAL_KEY$2];
|
|
48
|
+
function getLabels() {
|
|
49
|
+
return store.snapshot;
|
|
50
|
+
}
|
|
51
|
+
function subscribe(listener) {
|
|
52
|
+
store.listeners.add(listener);
|
|
53
|
+
return () => store.listeners.delete(listener);
|
|
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
|
+
}
|
|
91
|
+
/**
|
|
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.
|
|
99
|
+
*/
|
|
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
|
+
});
|
|
187
|
+
}
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region src/app/lib/page-context.tsx
|
|
190
|
+
const GLOBAL_KEY = "__open_doc_page_context__";
|
|
191
|
+
const g = globalThis;
|
|
192
|
+
if (!g[GLOBAL_KEY]) g[GLOBAL_KEY] = createContext(null);
|
|
193
|
+
const PageContext = g[GLOBAL_KEY];
|
|
194
|
+
/** 1-based page number of the page currently rendering. `0` outside a page. */
|
|
195
|
+
function useDocPageNumber() {
|
|
196
|
+
const ctx = useContext(PageContext);
|
|
197
|
+
return ctx ? ctx.index + 1 : 0;
|
|
198
|
+
}
|
|
199
|
+
/** Total page count of the document being rendered. `0` outside a page. */
|
|
200
|
+
function useDocPageCount() {
|
|
201
|
+
const ctx = useContext(PageContext);
|
|
202
|
+
return ctx ? ctx.total : 0;
|
|
203
|
+
}
|
|
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
|
|
5
497
|
//#region src/app/components/image-placeholder.tsx
|
|
6
498
|
/**
|
|
7
499
|
* Stands in for an image the user has to supply (a chart from their data, a
|
|
@@ -33,49 +525,6 @@ function ImagePlaceholder({ hint, width = "100%", height = 200, style, className
|
|
|
33
525
|
children: hint
|
|
34
526
|
});
|
|
35
527
|
}
|
|
36
|
-
|
|
37
|
-
//#endregion
|
|
38
|
-
//#region src/app/lib/outline.ts
|
|
39
|
-
const GLOBAL_KEY$1 = "__open_doc_outline_store__";
|
|
40
|
-
const g$1 = globalThis;
|
|
41
|
-
if (!g$1[GLOBAL_KEY$1]) g$1[GLOBAL_KEY$1] = {
|
|
42
|
-
snapshot: [],
|
|
43
|
-
listeners: new Set()
|
|
44
|
-
};
|
|
45
|
-
const store = g$1[GLOBAL_KEY$1];
|
|
46
|
-
function getOutline() {
|
|
47
|
-
return store.snapshot;
|
|
48
|
-
}
|
|
49
|
-
function subscribe(listener) {
|
|
50
|
-
store.listeners.add(listener);
|
|
51
|
-
return () => store.listeners.delete(listener);
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* The document's headings, filled in after the pages render. Empty on the first
|
|
55
|
-
* pass — a `<TableOfContents>` renders its rows on the second, once the scan
|
|
56
|
-
* has run.
|
|
57
|
-
*/
|
|
58
|
-
function useDocOutline() {
|
|
59
|
-
return useSyncExternalStore(subscribe, getOutline, getOutline);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
//#endregion
|
|
63
|
-
//#region src/app/lib/page-context.tsx
|
|
64
|
-
const GLOBAL_KEY = "__open_doc_page_context__";
|
|
65
|
-
const g = globalThis;
|
|
66
|
-
if (!g[GLOBAL_KEY]) g[GLOBAL_KEY] = createContext(null);
|
|
67
|
-
const PageContext = g[GLOBAL_KEY];
|
|
68
|
-
/** 1-based page number of the page currently rendering. `0` outside a page. */
|
|
69
|
-
function useDocPageNumber() {
|
|
70
|
-
const ctx = useContext(PageContext);
|
|
71
|
-
return ctx ? ctx.index + 1 : 0;
|
|
72
|
-
}
|
|
73
|
-
/** Total page count of the document being rendered. `0` outside a page. */
|
|
74
|
-
function useDocPageCount() {
|
|
75
|
-
const ctx = useContext(PageContext);
|
|
76
|
-
return ctx ? ctx.total : 0;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
528
|
//#endregion
|
|
80
529
|
//#region src/app/components/table-of-contents.tsx
|
|
81
530
|
/**
|
|
@@ -107,7 +556,7 @@ function TableOfContents({ maxLevel = 2, showPageNumbers = true, includeOwnPage
|
|
|
107
556
|
fontWeight: entry.level === 1 ? 600 : 400,
|
|
108
557
|
color: entry.level === 1 ? "var(--od-text)" : "var(--od-muted)"
|
|
109
558
|
},
|
|
110
|
-
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", {
|
|
111
560
|
"aria-hidden": true,
|
|
112
561
|
style: {
|
|
113
562
|
flex: 1,
|
|
@@ -121,7 +570,6 @@ function TableOfContents({ maxLevel = 2, showPageNumbers = true, includeOwnPage
|
|
|
121
570
|
}, entry.id))
|
|
122
571
|
});
|
|
123
572
|
}
|
|
124
|
-
|
|
125
573
|
//#endregion
|
|
126
574
|
//#region src/app/lib/flow.ts
|
|
127
575
|
/**
|
|
@@ -132,7 +580,7 @@ function toBlocks(node) {
|
|
|
132
580
|
const out = [];
|
|
133
581
|
for (const child of Children.toArray(node)) {
|
|
134
582
|
if (!isValidElement(child)) continue;
|
|
135
|
-
if (child.type === Fragment
|
|
583
|
+
if (child.type === Fragment) {
|
|
136
584
|
out.push(...toBlocks(child.props.children));
|
|
137
585
|
continue;
|
|
138
586
|
}
|
|
@@ -159,23 +607,34 @@ function isFlowSection(entry) {
|
|
|
159
607
|
* Greedy top-to-bottom packing: fill a page until the next block would cross
|
|
160
608
|
* the bottom edge, then push that block — plus anything glued to it — onto the
|
|
161
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.
|
|
162
614
|
*/
|
|
163
|
-
function paginateBlocks(blocks, available) {
|
|
615
|
+
function paginateBlocks(blocks, available, opts = {}) {
|
|
616
|
+
const overhead = opts.footnoteOverhead ?? 0;
|
|
164
617
|
const pages = [];
|
|
165
618
|
const overflowing = [];
|
|
166
619
|
let current = [];
|
|
167
620
|
let used = 0;
|
|
621
|
+
let notes = 0;
|
|
168
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;
|
|
169
626
|
const closePage = () => {
|
|
170
627
|
if (current.length === 0) return;
|
|
171
628
|
pages.push(current);
|
|
172
629
|
current = [];
|
|
173
630
|
used = 0;
|
|
631
|
+
notes = 0;
|
|
174
632
|
};
|
|
175
633
|
blocks.forEach((block, index) => {
|
|
176
|
-
|
|
634
|
+
const own = block.footnoteHeight ?? 0;
|
|
635
|
+
if (block.height + reserve(own) > available) overflowing.push(index);
|
|
177
636
|
if (block.breakBefore) closePage();
|
|
178
|
-
if (current.length > 0 && used + block.height > available) {
|
|
637
|
+
if (current.length > 0 && used + block.height + reserve(notes + own) > available) {
|
|
179
638
|
let splitAt = current.length;
|
|
180
639
|
while (splitAt > 0 && blocks[current[splitAt - 1]]?.keepWithNext) splitAt--;
|
|
181
640
|
if (block.keepWithPrevious && splitAt === current.length) splitAt--;
|
|
@@ -184,10 +643,12 @@ function paginateBlocks(blocks, available) {
|
|
|
184
643
|
pages.push(current.slice(0, splitAt));
|
|
185
644
|
current = moved;
|
|
186
645
|
used = heightOf(moved);
|
|
646
|
+
notes = notesOf(moved);
|
|
187
647
|
} else closePage();
|
|
188
648
|
}
|
|
189
649
|
current.push(index);
|
|
190
650
|
used += block.height;
|
|
651
|
+
notes += own;
|
|
191
652
|
});
|
|
192
653
|
closePage();
|
|
193
654
|
return {
|
|
@@ -195,7 +656,6 @@ function paginateBlocks(blocks, available) {
|
|
|
195
656
|
overflowing
|
|
196
657
|
};
|
|
197
658
|
}
|
|
198
|
-
|
|
199
659
|
//#endregion
|
|
200
660
|
//#region src/app/lib/sdk.ts
|
|
201
661
|
/**
|
|
@@ -227,7 +687,7 @@ const PAGE_SIZES = {
|
|
|
227
687
|
};
|
|
228
688
|
const DEFAULT_PAGE_SIZE = "A4";
|
|
229
689
|
function resolvePageGeometry(meta) {
|
|
230
|
-
const size = PAGE_SIZES[meta?.pageSize ??
|
|
690
|
+
const size = PAGE_SIZES[meta?.pageSize ?? "A4"] ?? PAGE_SIZES["A4"];
|
|
231
691
|
const landscape = meta?.orientation === "landscape";
|
|
232
692
|
return {
|
|
233
693
|
width: landscape ? size.height : size.width,
|
|
@@ -235,6 +695,5 @@ function resolvePageGeometry(meta) {
|
|
|
235
695
|
css: landscape ? `${size.css} landscape` : size.css
|
|
236
696
|
};
|
|
237
697
|
}
|
|
238
|
-
|
|
239
698
|
//#endregion
|
|
240
|
-
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 };
|