@open-document/core 0.2.0 → 0.4.0

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