@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.
Files changed (48) hide show
  1. package/dist/{build-DfUfpeTR.js → build-CvsOak5B.js} +1 -1
  2. package/dist/{check-CHxiOkQG.js → check-CbUBwYmf.js} +3 -3
  3. package/dist/cli/bin.js +47 -10
  4. package/dist/config-BWtOZ1jc.d.ts +45 -0
  5. package/dist/{config-9IdbhVuT.js → config-CltJJVsw.js} +398 -493
  6. package/dist/{context-BLI1-64_.js → context-CWgfsHoE.js} +2 -1
  7. package/dist/deploy-gcp-BUiSuqz7.js +758 -0
  8. package/dist/{dev-yNYKv5mm.js → dev-B8H2qT6G.js} +1 -1
  9. package/dist/{diagram-BK4jTZr4.js → diagram-CKf3ptOE.js} +293 -13
  10. package/dist/{diff-Bs205mOx.js → diff-BvIjjgnc.js} +2 -2
  11. package/dist/{export-tkquS5O5.js → export-DX30_s2q.js} +3 -3
  12. package/dist/{sdk-CHEGeINh.d.ts → flow-CS5apebG.d.ts} +72 -3
  13. package/dist/{import-D1hIKIr3.js → import-DgsdJT5e.js} +2 -2
  14. package/dist/index.d.ts +155 -59
  15. package/dist/index.js +896 -90
  16. package/dist/open-doc-plugin-DnX5usgI.js +320 -0
  17. package/dist/ops/index.d.ts +98 -13
  18. package/dist/ops/index.js +3 -3
  19. package/dist/{ops-Dgqujq5a.js → ops-CSR5RlrE.js} +2 -1
  20. package/dist/{preview-BImdTH6K.js → preview-DYMUNjXL.js} +1 -1
  21. package/dist/{templates-DT5zzqHq.js → templates-B5Tz0AKb.js} +3 -3
  22. package/dist/vite/index.d.ts +1 -1
  23. package/dist/vite/index.js +2 -1
  24. package/package.json +1 -1
  25. package/skills/doc-authoring/SKILL.md +15 -16
  26. package/skills/doc-authoring/references/long-form.md +43 -2
  27. package/skills/doc-authoring/references/pagination.md +14 -2
  28. package/skills/doc-authoring/references/tables-and-charts.md +21 -17
  29. package/src/app/components/callout.tsx +101 -0
  30. package/src/app/components/chart.tsx +191 -33
  31. package/src/app/components/code-block.tsx +249 -0
  32. package/src/app/components/data-table.tsx +146 -18
  33. package/src/app/components/flow-page.tsx +57 -8
  34. package/src/app/components/numbering.tsx +226 -12
  35. package/src/app/components/page-frame.tsx +42 -0
  36. package/src/app/lib/chart.test.ts +15 -0
  37. package/src/app/lib/chart.ts +134 -9
  38. package/src/app/lib/diagnostics.ts +45 -1
  39. package/src/app/lib/export-dom.ts +15 -2
  40. package/src/app/lib/export-pdf.ts +9 -1
  41. package/src/app/lib/flow-measure.ts +33 -4
  42. package/src/app/lib/flow.test.ts +20 -1
  43. package/src/app/lib/flow.ts +120 -20
  44. package/src/app/lib/labels.ts +29 -10
  45. package/src/app/lib/sdk.ts +6 -0
  46. package/src/app/lib/use-doc-pages.ts +23 -8
  47. package/src/app/routes/doc.tsx +1 -0
  48. package/dist/config-P61niZMf.d.ts +0 -24
package/dist/index.js CHANGED
@@ -1,7 +1,98 @@
1
- import { a as defaultDesign, i as cssVarsToString, n as DiagramSyntaxError, o as designToCssVars, r as parseDelimited, s as measureText, t as compileDiagram } from "./diagram-BK4jTZr4.js";
1
+ import { a as defaultDesign, i as cssVarsToString, n as DiagramSyntaxError, o as designToCssVars, r as parseDelimited, s as measureText, t as compileDiagram } from "./diagram-CKf3ptOE.js";
2
2
  import { a as PAGE_SIZES, c as isPageSizeName, i as ORIENTATIONS, l as resolvePageGeometry, n as DEFAULT_PAGE_SIZE, o as PAGE_SIZE_NAMES, s as isOrientation, t as DEFAULT_ORIENTATION } from "./sdk-CqNZzbkz.js";
3
- import { Children, Fragment, createContext, createElement, isValidElement, useContext, useEffect, useId, useRef, useSyncExternalStore } from "react";
4
- import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
3
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
+ import { Children, Fragment as Fragment$1, createContext, createElement, isValidElement, useContext, useEffect, useId, useRef, useSyncExternalStore } from "react";
5
+ //#region src/app/lib/source-loc.ts
6
+ /**
7
+ * In dev, `loc-tags-plugin` stamps `data-od-loc` onto the call site of a
8
+ * framework component that forwards it. The component puts it back on the
9
+ * host that prints the call site's words, so the inspector can select what it
10
+ * rendered — a table, a caption, a footnote — and find the source behind it.
11
+ * `data-od-prop` says which attribute of the call site those words come from.
12
+ */
13
+ const LOC_PROP = "data-od-loc";
14
+ const PROP_ATTR = "data-od-prop";
15
+ /** The attributes pointing a host back at its call site; nothing outside dev. */
16
+ function sourceAttrs(loc, prop) {
17
+ if (!loc) return {};
18
+ return prop ? {
19
+ [LOC_PROP]: loc,
20
+ [PROP_ATTR]: prop
21
+ } : { [LOC_PROP]: loc };
22
+ }
23
+ //#endregion
24
+ //#region src/app/components/callout.tsx
25
+ const PALETTES = {
26
+ info: {
27
+ border: "var(--od-accent, #2563eb)",
28
+ bg: "color-mix(in srgb, var(--od-accent, #2563eb) 7%, var(--od-bg, #ffffff))",
29
+ badge: "var(--od-accent, #2563eb)",
30
+ label: "NOTE"
31
+ },
32
+ tip: {
33
+ border: "#15803d",
34
+ bg: "color-mix(in srgb, #15803d 7%, var(--od-bg, #ffffff))",
35
+ badge: "#15803d",
36
+ label: "TIP"
37
+ },
38
+ warning: {
39
+ border: "#b45309",
40
+ bg: "color-mix(in srgb, #d97706 8%, var(--od-bg, #ffffff))",
41
+ badge: "#b45309",
42
+ label: "WARNING"
43
+ },
44
+ danger: {
45
+ border: "#b91c1c",
46
+ bg: "color-mix(in srgb, #dc2626 7%, var(--od-bg, #ffffff))",
47
+ badge: "#b91c1c",
48
+ label: "CRITICAL"
49
+ },
50
+ neutral: {
51
+ border: "var(--od-muted, #6b7280)",
52
+ bg: "color-mix(in srgb, var(--od-text, #16181d) 4%, var(--od-bg, #ffffff))",
53
+ badge: "var(--od-muted, #6b7280)",
54
+ label: "SUMMARY"
55
+ }
56
+ };
57
+ /**
58
+ * A structured admonition box (`info`, `tip`, `warning`, `danger`, `neutral`)
59
+ * rendered as a `<blockquote data-od-callout>` so Word and PDF exporters keep
60
+ * its panel border and shading intact.
61
+ */
62
+ function Callout({ variant = "info", title, children, style, className, [LOC_PROP]: loc }) {
63
+ const palette = PALETTES[variant] ?? PALETTES.info;
64
+ return /* @__PURE__ */ jsxs("blockquote", {
65
+ ...sourceAttrs(loc),
66
+ "data-od-callout": variant,
67
+ className,
68
+ style: {
69
+ margin: "4px 0 12px",
70
+ padding: "10px 14px",
71
+ borderLeft: `3px solid ${palette.border}`,
72
+ background: palette.bg,
73
+ borderRadius: "0 var(--od-radius, 4px) var(--od-radius, 4px) 0",
74
+ color: "var(--od-text, #16181d)",
75
+ fontStyle: "normal",
76
+ fontSize: "0.95em",
77
+ lineHeight: 1.55,
78
+ ...style
79
+ },
80
+ children: [title !== void 0 && /* @__PURE__ */ jsx("div", {
81
+ style: {
82
+ fontFamily: "var(--od-font-heading, sans-serif)",
83
+ fontWeight: 650,
84
+ fontSize: "0.92em",
85
+ color: palette.badge,
86
+ marginBottom: 4,
87
+ letterSpacing: "0.01em"
88
+ },
89
+ children: typeof title === "string" ? /* @__PURE__ */ jsx("span", {
90
+ ...sourceAttrs(loc, "title"),
91
+ children: title
92
+ }) : title
93
+ }), /* @__PURE__ */ jsx("div", { children })]
94
+ });
95
+ }
5
96
  const LEGEND_GAP = 14;
6
97
  /** A number read the way a CSV cell or a typed literal would hold it. */
7
98
  function toNumber(value) {
@@ -134,8 +225,108 @@ function layoutPie(spec) {
134
225
  values
135
226
  };
136
227
  }
228
+ function layoutHorizontalBar(spec) {
229
+ const names = spec.y.map((key) => seriesName(spec, key));
230
+ const categories = spec.data.map((row) => String(row[spec.x] ?? ""));
231
+ const matrix = spec.data.map((row) => spec.y.map((key) => toNumber(row[key])));
232
+ let lo = 0;
233
+ let hi = 0;
234
+ for (const values of matrix) if (spec.stacked) {
235
+ const up = values.reduce((sum, v) => sum + Math.max(0, v ?? 0), 0);
236
+ const down = values.reduce((sum, v) => sum + Math.min(0, v ?? 0), 0);
237
+ lo = Math.min(lo, down);
238
+ hi = Math.max(hi, up);
239
+ } else for (const v of values) {
240
+ if (v === null) continue;
241
+ lo = Math.min(lo, v);
242
+ hi = Math.max(hi, v);
243
+ }
244
+ if (lo === 0 && hi === 0) hi = 1;
245
+ const tickValues = niceTicks(lo, hi);
246
+ const min = tickValues[0] ?? 0;
247
+ const max = tickValues[tickValues.length - 1] ?? 1;
248
+ const tickLabels = tickValues.map((value) => formatChartValue(value, spec.format));
249
+ const top = 6 + (spec.y.length > 1 ? 22 : 0);
250
+ const left = Math.ceil(Math.max(24, ...categories.map((c) => measureText(c, 10))) * 1.12) + 12;
251
+ const bottom = 20;
252
+ const right = spec.values ? 44 : 14;
253
+ const plot = {
254
+ x: left,
255
+ y: top,
256
+ width: Math.max(10, spec.width - left - right),
257
+ height: Math.max(10, spec.height - top - bottom)
258
+ };
259
+ const xOf = (value) => round(plot.x + (value - min) / (max - min) * plot.width);
260
+ const ticks = tickValues.map((value, i) => ({
261
+ value,
262
+ at: xOf(value),
263
+ label: tickLabels[i] ?? ""
264
+ }));
265
+ const band = plot.height / Math.max(1, categories.length);
266
+ const categoryLabels = categories.map((text, i) => ({
267
+ text,
268
+ x: plot.x - 8,
269
+ y: round(plot.y + band * (i + .5) + 3.5)
270
+ }));
271
+ const bars = [];
272
+ const values = [];
273
+ const group = band * .68;
274
+ const each = spec.stacked ? group : group / Math.max(1, spec.y.length);
275
+ matrix.forEach((row, i) => {
276
+ const startY = plot.y + band * i + (band - group) / 2;
277
+ let up = 0;
278
+ let down = 0;
279
+ row.forEach((value, series) => {
280
+ if (value === null) return;
281
+ let from;
282
+ let to;
283
+ if (spec.stacked) {
284
+ from = value >= 0 ? up : down;
285
+ to = from + value;
286
+ if (value >= 0) up = to;
287
+ else down = to;
288
+ } else {
289
+ from = 0;
290
+ to = value;
291
+ }
292
+ const x1 = xOf(Math.min(from, to));
293
+ const x2 = xOf(Math.max(from, to));
294
+ const y = round(spec.stacked ? startY : startY + each * series);
295
+ const height = round(Math.max(1, each - (spec.stacked ? 0 : 2)));
296
+ bars.push({
297
+ x: x1,
298
+ y,
299
+ width: round(Math.max(0, x2 - x1)),
300
+ height,
301
+ series,
302
+ value
303
+ });
304
+ if (spec.values && !spec.stacked) values.push({
305
+ text: formatChartValue(value, spec.format),
306
+ x: round(value >= 0 ? x2 + 5 : x1 - 5),
307
+ y: round(y + height / 2 + 3.5),
308
+ anchor: value >= 0 ? "start" : "end"
309
+ });
310
+ });
311
+ });
312
+ return {
313
+ width: spec.width,
314
+ height: spec.height,
315
+ plot,
316
+ horizontal: true,
317
+ baseline: min <= 0 && max >= 0 ? xOf(0) : null,
318
+ ticks,
319
+ categories: categoryLabels,
320
+ bars,
321
+ lines: [],
322
+ slices: [],
323
+ legend: spec.y.length > 1 ? legendRow(names, plot.x, 14) : [],
324
+ values
325
+ };
326
+ }
137
327
  function layoutChart(spec) {
138
328
  if (spec.type === "pie") return layoutPie(spec);
329
+ if (spec.type === "horizontal-bar") return layoutHorizontalBar(spec);
139
330
  const names = spec.y.map((key) => seriesName(spec, key));
140
331
  const categories = spec.data.map((row) => String(row[spec.x] ?? ""));
141
332
  const matrix = spec.data.map((row) => spec.y.map((key) => toNumber(row[key])));
@@ -155,8 +346,8 @@ function layoutChart(spec) {
155
346
  lo = 0;
156
347
  hi = 1;
157
348
  }
158
- if (spec.type === "bar" || lo >= 0 && lo <= hi * .5) lo = Math.min(0, lo);
159
- if (spec.type === "bar") hi = Math.max(0, hi);
349
+ if (spec.type === "bar" || spec.type === "area" || lo >= 0 && lo <= hi * .5) lo = Math.min(0, lo);
350
+ if (spec.type === "bar" || spec.type === "area") hi = Math.max(0, hi);
160
351
  const tickValues = niceTicks(lo, hi);
161
352
  const min = tickValues[0] ?? 0;
162
353
  const max = tickValues[tickValues.length - 1] ?? 1;
@@ -185,6 +376,7 @@ function layoutChart(spec) {
185
376
  const bars = [];
186
377
  const lines = [];
187
378
  const values = [];
379
+ const baseLineY = yOf(Math.max(min, Math.min(max, 0)));
188
380
  if (spec.type === "bar") {
189
381
  const group = band * .68;
190
382
  const each = spec.stacked ? group : group / Math.max(1, spec.y.length);
@@ -240,9 +432,16 @@ function layoutChart(spec) {
240
432
  value
241
433
  }];
242
434
  });
435
+ let areaPath;
436
+ if (spec.type === "area" && points.length >= 2) {
437
+ const first = points[0];
438
+ const last = points[points.length - 1];
439
+ areaPath = `${points.map((p, idx) => `${idx === 0 ? "M" : "L"}${p.x},${p.y}`).join(" ")} L${last.x},${baseLineY} L${first.x},${baseLineY} Z`;
440
+ }
243
441
  lines.push({
244
442
  series,
245
- points
443
+ points,
444
+ ...areaPath ? { areaPath } : {}
246
445
  });
247
446
  if (spec.values) for (const point of points) values.push({
248
447
  text: formatChartValue(point.value, spec.format),
@@ -268,12 +467,12 @@ function layoutChart(spec) {
268
467
  //#endregion
269
468
  //#region src/app/lib/outline.ts
270
469
  const GLOBAL_KEY$4 = "__open_doc_outline_store__";
271
- const g$4 = globalThis;
272
- if (!g$4[GLOBAL_KEY$4]) g$4[GLOBAL_KEY$4] = {
470
+ const g$5 = globalThis;
471
+ if (!g$5[GLOBAL_KEY$4]) g$5[GLOBAL_KEY$4] = {
273
472
  snapshot: [],
274
473
  listeners: /* @__PURE__ */ new Set()
275
474
  };
276
- const store$2 = g$4[GLOBAL_KEY$4];
475
+ const store$2 = g$5[GLOBAL_KEY$4];
277
476
  function getOutline() {
278
477
  return store$2.snapshot;
279
478
  }
@@ -300,16 +499,17 @@ const EMPTY = {
300
499
  figure: "Figure",
301
500
  table: "Table",
302
501
  footnotes: "",
502
+ bibliography: "References",
303
503
  onPage: " (p. {page})"
304
504
  }
305
505
  };
306
506
  const GLOBAL_KEY$3 = "__open_doc_labels_store__";
307
- const g$3 = globalThis;
308
- if (!g$3[GLOBAL_KEY$3]) g$3[GLOBAL_KEY$3] = {
507
+ const g$4 = globalThis;
508
+ if (!g$4[GLOBAL_KEY$3]) g$4[GLOBAL_KEY$3] = {
309
509
  snapshot: EMPTY,
310
510
  listeners: /* @__PURE__ */ new Set()
311
511
  };
312
- const store$1 = g$3[GLOBAL_KEY$3];
512
+ const store$1 = g$4[GLOBAL_KEY$3];
313
513
  function getLabels() {
314
514
  return store$1.snapshot;
315
515
  }
@@ -325,8 +525,8 @@ function useDocLabels(kind) {
325
525
  return useLabelSnapshot().entries.filter((entry) => entry.kind === kind);
326
526
  }
327
527
  /** One numbered item by id, once the scan has run. */
328
- function useDocLabel(id) {
329
- return useLabelSnapshot().entries.find((entry) => entry.id === id) ?? null;
528
+ function useDocLabel(id, kind) {
529
+ return useLabelSnapshot().entries.find((entry) => entry.id === id && (kind === void 0 || entry.kind === kind)) ?? null;
330
530
  }
331
531
  function useLabelVocabulary() {
332
532
  return useLabelSnapshot().vocabulary;
@@ -335,32 +535,13 @@ function formatOnPage(vocabulary, page) {
335
535
  return vocabulary.onPage.replace("{page}", String(page));
336
536
  }
337
537
  //#endregion
338
- //#region src/app/lib/source-loc.ts
339
- /**
340
- * In dev, `loc-tags-plugin` stamps `data-od-loc` onto the call site of a
341
- * framework component that forwards it. The component puts it back on the
342
- * host that prints the call site's words, so the inspector can select what it
343
- * rendered — a table, a caption, a footnote — and find the source behind it.
344
- * `data-od-prop` says which attribute of the call site those words come from.
345
- */
346
- const LOC_PROP = "data-od-loc";
347
- const PROP_ATTR = "data-od-prop";
348
- /** The attributes pointing a host back at its call site; nothing outside dev. */
349
- function sourceAttrs(loc, prop) {
350
- if (!loc) return {};
351
- return prop ? {
352
- [LOC_PROP]: loc,
353
- [PROP_ATTR]: prop
354
- } : { [LOC_PROP]: loc };
355
- }
356
- //#endregion
357
538
  //#region src/app/components/footnote.tsx
358
539
  /** Stands in for a number the scan has not produced yet, or never will. */
359
540
  const UNNUMBERED = "•";
360
541
  const GLOBAL_KEY$2 = "__open_doc_footnote_context__";
361
- const g$2 = globalThis;
362
- if (!g$2[GLOBAL_KEY$2]) g$2[GLOBAL_KEY$2] = createContext(null);
363
- const FootnoteContext = g$2[GLOBAL_KEY$2];
542
+ const g$3 = globalThis;
543
+ if (!g$3[GLOBAL_KEY$2]) g$3[GLOBAL_KEY$2] = createContext(null);
544
+ const FootnoteContext = g$3[GLOBAL_KEY$2];
364
545
  const FOOTNOTE_MARKER_FLAG = "__odFootnote";
365
546
  function markerStyle() {
366
547
  return {
@@ -478,9 +659,9 @@ function Footnotes({ notes, style, className }) {
478
659
  //#endregion
479
660
  //#region src/app/lib/page-context.tsx
480
661
  const GLOBAL_KEY$1 = "__open_doc_page_context__";
481
- const g$1 = globalThis;
482
- if (!g$1[GLOBAL_KEY$1]) g$1[GLOBAL_KEY$1] = createContext(null);
483
- const PageContext = g$1[GLOBAL_KEY$1];
662
+ const g$2 = globalThis;
663
+ if (!g$2[GLOBAL_KEY$1]) g$2[GLOBAL_KEY$1] = createContext(null);
664
+ const PageContext = g$2[GLOBAL_KEY$1];
484
665
  /** 1-based page number of the page currently rendering. `0` outside a page. */
485
666
  function useDocPageNumber() {
486
667
  const ctx = useContext(PageContext);
@@ -504,7 +685,7 @@ function nameFor(kind, vocabulary) {
504
685
  *
505
686
  * Caption and content are one block, so a `flow()` section never separates them.
506
687
  */
507
- function Figure({ id, caption, kind = "figure", captionPosition, captionText, style, captionStyle, className, children, [LOC_PROP]: loc }) {
688
+ function Figure({ id, caption, kind = "figure", captionPosition, captionText, numbered = true, style, captionStyle, className, children, [LOC_PROP]: loc }) {
508
689
  const generated = useId();
509
690
  const labelId = id ?? generated;
510
691
  const entry = useDocLabel(labelId);
@@ -519,7 +700,7 @@ function Figure({ id, caption, kind = "figure", captionPosition, captionText, st
519
700
  margin: position === "above" ? "0 0 6px" : "6px 0 0",
520
701
  ...captionStyle
521
702
  },
522
- children: [/* @__PURE__ */ jsxs("span", {
703
+ children: [numbered && /* @__PURE__ */ jsxs("span", {
523
704
  style: {
524
705
  fontWeight: 600,
525
706
  color: "var(--od-text)"
@@ -529,16 +710,18 @@ function Figure({ id, caption, kind = "figure", captionPosition, captionText, st
529
710
  " ",
530
711
  entry?.number ?? ""
531
712
  ]
532
- }), typeof caption === "string" || typeof caption === "number" ? /* @__PURE__ */ jsxs("span", { children: [" — ", /* @__PURE__ */ jsx("span", {
713
+ }), typeof caption === "string" || typeof caption === "number" ? /* @__PURE__ */ jsxs("span", { children: [numbered ? " — " : "", /* @__PURE__ */ jsx("span", {
533
714
  ...sourceAttrs(loc, "caption"),
534
715
  children: caption
535
- })] }) : caption ? /* @__PURE__ */ jsxs("span", { children: [" — ", caption] }) : null]
716
+ })] }) : caption ? /* @__PURE__ */ jsxs("span", { children: [numbered ? " — " : "", caption] }) : null]
536
717
  }) : null;
537
718
  return /* @__PURE__ */ jsxs("figure", {
538
- [LABEL_ATTR]: kind,
539
- [LABEL_ID_ATTR]: labelId,
540
- [LABEL_TEXT_ATTR]: text,
541
- ...sourceAttrs(loc),
719
+ ...numbered ? {
720
+ [LABEL_ATTR]: kind,
721
+ [LABEL_ID_ATTR]: labelId,
722
+ [LABEL_TEXT_ATTR]: text,
723
+ ...sourceAttrs(loc)
724
+ } : sourceAttrs(loc),
542
725
  className,
543
726
  style: {
544
727
  margin: "0 0 16px",
@@ -573,7 +756,7 @@ function Ref({ to, showPage = "auto", style, className }) {
573
756
  "]"
574
757
  ]
575
758
  });
576
- const name = entry.kind === "footnote" ? "" : `${nameFor(entry.kind, vocabulary)} `;
759
+ const name = entry.kind === "footnote" || entry.kind === "citation" ? "" : `${nameFor(entry.kind, vocabulary)} `;
577
760
  const withPage = showPage === "auto" ? entry.page !== here : showPage;
578
761
  return /* @__PURE__ */ jsxs("span", {
579
762
  "data-od-ref": to,
@@ -624,7 +807,7 @@ function ListOf({ kind = "figure", showPageNumbers = true, style, className }) {
624
807
  ]
625
808
  }),
626
809
  /* @__PURE__ */ jsx("span", { children: entry.text }),
627
- showPageNumbers && /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", {
810
+ showPageNumbers && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
628
811
  "aria-hidden": true,
629
812
  style: {
630
813
  flex: 1,
@@ -651,6 +834,153 @@ function ListOfTables(props) {
651
834
  kind: "table"
652
835
  });
653
836
  }
837
+ /**
838
+ * An inline bibliographic citation (`[1]`), numbered in order of first
839
+ * appearance across the rendered pages. Multiple `<Cite id="x" />` calls share
840
+ * the same number.
841
+ */
842
+ function Cite({ id, source, style, className }) {
843
+ const entry = useDocLabel(id, "citation");
844
+ return /* @__PURE__ */ jsxs("span", {
845
+ [LABEL_ATTR]: "citation",
846
+ [LABEL_ID_ATTR]: id,
847
+ ...source ? { [LABEL_TEXT_ATTR]: source } : {},
848
+ "data-od-cite": id,
849
+ className,
850
+ style: {
851
+ fontSize: "0.82em",
852
+ verticalAlign: "super",
853
+ lineHeight: 0,
854
+ fontWeight: 600,
855
+ color: "var(--od-accent)",
856
+ fontVariantNumeric: "tabular-nums",
857
+ ...style
858
+ },
859
+ children: [
860
+ "[",
861
+ entry?.number ?? "·",
862
+ "]"
863
+ ]
864
+ });
865
+ }
866
+ function renderBibItem(spec, fallback) {
867
+ if (!spec) return fallback;
868
+ if (typeof spec === "string") return spec;
869
+ if (spec.source && !spec.title) return spec.source;
870
+ return /* @__PURE__ */ jsxs("span", { children: [
871
+ spec.author ? `${spec.author}. ` : "",
872
+ /* @__PURE__ */ jsx("strong", {
873
+ style: {
874
+ fontWeight: 600,
875
+ color: "var(--od-text)"
876
+ },
877
+ children: spec.title
878
+ }),
879
+ spec.year ? ` (${spec.year}).` : ".",
880
+ spec.note ? ` ${spec.note}` : "",
881
+ spec.url ? /* @__PURE__ */ jsxs(Fragment, { children: [" ", /* @__PURE__ */ jsx("span", {
882
+ style: {
883
+ fontFamily: "var(--od-font-mono)",
884
+ fontSize: "0.92em",
885
+ color: "var(--od-muted)"
886
+ },
887
+ children: spec.url
888
+ })] }) : null
889
+ ] });
890
+ }
891
+ /**
892
+ * Renders the numbered list of all `<Cite>` references in order of appearance,
893
+ * plus any additional uncited entries passed in `items`.
894
+ */
895
+ function Bibliography({ items, title, showPageNumbers = false, style, className }) {
896
+ const cited = useDocLabels("citation");
897
+ const vocabulary = useLabelVocabulary();
898
+ const map = /* @__PURE__ */ new Map();
899
+ if (Array.isArray(items)) items.forEach((item, idx) => {
900
+ map.set(item.id ?? `bib-${idx + 1}`, item);
901
+ });
902
+ else if (items) for (const [k, v] of Object.entries(items)) map.set(k, v);
903
+ const rows = cited.map((entry) => ({
904
+ id: entry.id,
905
+ number: entry.number,
906
+ content: renderBibItem(map.get(entry.id), entry.text || entry.id),
907
+ page: entry.page
908
+ }));
909
+ for (const [id, spec] of map.entries()) if (!rows.some((r) => r.id === id)) rows.push({
910
+ id,
911
+ number: rows.length + 1,
912
+ content: renderBibItem(spec, id)
913
+ });
914
+ const heading = title !== void 0 ? title : vocabulary.bibliography;
915
+ return /* @__PURE__ */ jsxs("div", {
916
+ "data-od-bibliography": "",
917
+ className,
918
+ style: {
919
+ fontFamily: "var(--od-font-body)",
920
+ fontSize: "var(--od-size-caption, 11px)",
921
+ lineHeight: 1.55,
922
+ color: "var(--od-text)",
923
+ margin: "8px 0 14px",
924
+ ...style
925
+ },
926
+ children: [heading ? /* @__PURE__ */ jsx("div", {
927
+ style: {
928
+ fontFamily: "var(--od-font-heading)",
929
+ fontSize: "var(--od-size-h3, 14px)",
930
+ fontWeight: 600,
931
+ marginBottom: 8,
932
+ color: "var(--od-text)"
933
+ },
934
+ children: heading
935
+ }) : null, /* @__PURE__ */ jsx("ol", {
936
+ style: {
937
+ listStyle: "none",
938
+ padding: 0,
939
+ margin: 0
940
+ },
941
+ children: rows.map((row) => /* @__PURE__ */ jsxs("li", {
942
+ "data-od-bib-entry": row.id,
943
+ style: {
944
+ display: "flex",
945
+ alignItems: "baseline",
946
+ gap: 8,
947
+ marginBottom: 5
948
+ },
949
+ children: [
950
+ /* @__PURE__ */ jsxs("span", {
951
+ style: {
952
+ flex: "none",
953
+ minWidth: 24,
954
+ fontWeight: 600,
955
+ color: "var(--od-accent)",
956
+ fontVariantNumeric: "tabular-nums"
957
+ },
958
+ children: [
959
+ "[",
960
+ row.number,
961
+ "]"
962
+ ]
963
+ }),
964
+ /* @__PURE__ */ jsx("span", {
965
+ style: {
966
+ flex: 1,
967
+ color: "var(--od-text)"
968
+ },
969
+ children: row.content
970
+ }),
971
+ showPageNumbers && row.page !== void 0 && /* @__PURE__ */ jsxs("span", {
972
+ style: {
973
+ flex: "none",
974
+ color: "var(--od-muted)",
975
+ fontVariantNumeric: "tabular-nums"
976
+ },
977
+ children: ["p. ", row.page]
978
+ })
979
+ ]
980
+ }, row.id))
981
+ })]
982
+ });
983
+ }
654
984
  //#endregion
655
985
  //#region src/app/components/chart.tsx
656
986
  const ACCENT = "var(--od-accent, #2563eb)";
@@ -713,7 +1043,23 @@ function Chart({ type = "bar", data, x, y, labels, stacked, format, values, colo
713
1043
  },
714
1044
  className: caption ? void 0 : className,
715
1045
  children: [
716
- chart.ticks.map((tick) => /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("line", {
1046
+ chart.ticks.map((tick) => chart.horizontal ? /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("line", {
1047
+ x1: tick.at,
1048
+ x2: tick.at,
1049
+ y1: chart.plot.y,
1050
+ y2: chart.plot.y + chart.plot.height,
1051
+ style: { stroke: RULE },
1052
+ strokeWidth: 1
1053
+ }), /* @__PURE__ */ jsx("text", {
1054
+ x: tick.at,
1055
+ y: chart.plot.y + chart.plot.height + 14,
1056
+ textAnchor: "middle",
1057
+ style: {
1058
+ ...text,
1059
+ fill: MUTED
1060
+ },
1061
+ children: tick.label
1062
+ })] }, tick.value) : /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("line", {
717
1063
  x1: chart.plot.x,
718
1064
  x2: chart.plot.x + chart.plot.width,
719
1065
  y1: tick.at,
@@ -737,28 +1083,43 @@ function Chart({ type = "bar", data, x, y, labels, stacked, format, values, colo
737
1083
  height: bar.height,
738
1084
  style: { fill: colorOf(bar.series, colors) }
739
1085
  }, `${bar.series}-${bar.x}-${bar.y}`)),
740
- chart.baseline !== null && chart.bars.length > 0 && /* @__PURE__ */ jsx("line", {
1086
+ chart.baseline !== null && chart.bars.length > 0 && (chart.horizontal ? /* @__PURE__ */ jsx("line", {
1087
+ x1: chart.baseline,
1088
+ x2: chart.baseline,
1089
+ y1: chart.plot.y,
1090
+ y2: chart.plot.y + chart.plot.height,
1091
+ style: { stroke: MUTED },
1092
+ strokeWidth: 1
1093
+ }) : /* @__PURE__ */ jsx("line", {
741
1094
  x1: chart.plot.x,
742
1095
  x2: chart.plot.x + chart.plot.width,
743
1096
  y1: chart.baseline,
744
1097
  y2: chart.baseline,
745
1098
  style: { stroke: MUTED },
746
1099
  strokeWidth: 1
747
- }),
1100
+ })),
748
1101
  chart.lines.map((line) => /* @__PURE__ */ jsxs("g", {
749
1102
  style: { stroke: colorOf(line.series, colors) },
750
- children: [/* @__PURE__ */ jsx("polyline", {
751
- points: line.points.map((point) => `${point.x},${point.y}`).join(" "),
752
- fill: "none",
753
- strokeWidth: 2,
754
- strokeLinejoin: "round"
755
- }), line.points.map((point) => /* @__PURE__ */ jsx("circle", {
756
- cx: point.x,
757
- cy: point.y,
758
- r: 3,
759
- strokeWidth: 1.5,
760
- style: { fill: "var(--od-bg, #ffffff)" }
761
- }, point.x))]
1103
+ children: [
1104
+ line.areaPath && /* @__PURE__ */ jsx("path", {
1105
+ d: line.areaPath,
1106
+ stroke: "none",
1107
+ style: { fill: `color-mix(in srgb, ${colorOf(line.series, colors)} 20%, transparent)` }
1108
+ }),
1109
+ /* @__PURE__ */ jsx("polyline", {
1110
+ points: line.points.map((point) => `${point.x},${point.y}`).join(" "),
1111
+ fill: "none",
1112
+ strokeWidth: 2,
1113
+ strokeLinejoin: "round"
1114
+ }),
1115
+ line.points.map((point) => /* @__PURE__ */ jsx("circle", {
1116
+ cx: point.x,
1117
+ cy: point.y,
1118
+ r: 3,
1119
+ strokeWidth: 1.5,
1120
+ style: { fill: "var(--od-bg, #ffffff)" }
1121
+ }, point.x))
1122
+ ]
762
1123
  }, line.series)),
763
1124
  chart.slices.map((slice) => /* @__PURE__ */ jsx("path", {
764
1125
  d: slice.path,
@@ -770,14 +1131,14 @@ function Chart({ type = "bar", data, x, y, labels, stacked, format, values, colo
770
1131
  }, slice.series)),
771
1132
  chart.categories.map((category) => /* @__PURE__ */ jsx("text", {
772
1133
  x: category.x,
773
- y: chart.plot.y + chart.plot.height + 15,
774
- textAnchor: "middle",
1134
+ y: category.y ?? chart.plot.y + chart.plot.height + 15,
1135
+ textAnchor: chart.horizontal ? "end" : "middle",
775
1136
  style: {
776
1137
  ...text,
777
1138
  fill: MUTED
778
1139
  },
779
1140
  children: category.text
780
- }, category.x)),
1141
+ }, `${category.x}-${category.y ?? 0}-${category.text}`)),
781
1142
  chart.values.map((value) => /* @__PURE__ */ jsx("text", {
782
1143
  x: value.x,
783
1144
  y: value.y,
@@ -817,6 +1178,318 @@ function Chart({ type = "bar", data, x, y, labels, stacked, format, values, colo
817
1178
  children: drawing
818
1179
  });
819
1180
  }
1181
+ /**
1182
+ * A compact word-sized chart that sits inline inside a paragraph or table cell.
1183
+ */
1184
+ function Sparkline({ data, type = "line", width = 76, height = 20, color = ACCENT, showEndDot = true, style, className }) {
1185
+ const nums = data.filter((v) => typeof v === "number" && Number.isFinite(v));
1186
+ if (nums.length === 0) return null;
1187
+ const min = Math.min(...nums);
1188
+ const max = Math.max(...nums);
1189
+ const span = max - min || 1;
1190
+ const pad = 2.5;
1191
+ const w = Math.max(4, width - pad * 2);
1192
+ const h = Math.max(4, height - pad * 2);
1193
+ if (type === "bar") {
1194
+ const baseSpan = (Math.max(0, max) || 1) - Math.min(0, min) || 1;
1195
+ const step = w / nums.length;
1196
+ const barW = Math.max(1.5, step * .72);
1197
+ return /* @__PURE__ */ jsx("svg", {
1198
+ viewBox: `0 0 ${width} ${height}`,
1199
+ width,
1200
+ height,
1201
+ "aria-hidden": "true",
1202
+ className,
1203
+ style: {
1204
+ display: "inline-block",
1205
+ verticalAlign: "middle",
1206
+ overflow: "visible",
1207
+ ...style
1208
+ },
1209
+ children: nums.map((val, idx) => {
1210
+ const bh = Math.max(1.5, Math.abs(val) / baseSpan * h);
1211
+ const x = pad + idx * step + (step - barW) / 2;
1212
+ const y = pad + h - bh;
1213
+ return /* @__PURE__ */ jsx("rect", {
1214
+ x,
1215
+ y,
1216
+ width: barW,
1217
+ height: bh,
1218
+ rx: 1,
1219
+ style: { fill: color }
1220
+ }, idx);
1221
+ })
1222
+ });
1223
+ }
1224
+ const pts = nums.map((val, idx) => {
1225
+ const x = pad + (nums.length === 1 ? w / 2 : idx / (nums.length - 1) * w);
1226
+ const y = pad + h - (val - min) / span * h;
1227
+ return {
1228
+ x: Math.round(x * 10) / 10,
1229
+ y: Math.round(y * 10) / 10
1230
+ };
1231
+ });
1232
+ const poly = pts.map((p) => `${p.x},${p.y}`).join(" ");
1233
+ const first = pts[0];
1234
+ const last = pts[pts.length - 1];
1235
+ const area = pts.length >= 2 && first && last ? `M${pts.map((p) => `${p.x},${p.y}`).join(" L")} L${last.x},${pad + h} L${first.x},${pad + h} Z` : null;
1236
+ return /* @__PURE__ */ jsxs("svg", {
1237
+ viewBox: `0 0 ${width} ${height}`,
1238
+ width,
1239
+ height,
1240
+ "aria-hidden": "true",
1241
+ className,
1242
+ style: {
1243
+ display: "inline-block",
1244
+ verticalAlign: "middle",
1245
+ overflow: "visible",
1246
+ ...style
1247
+ },
1248
+ children: [
1249
+ area && /* @__PURE__ */ jsx("path", {
1250
+ d: area,
1251
+ stroke: "none",
1252
+ style: { fill: `color-mix(in srgb, ${color} 18%, transparent)` }
1253
+ }),
1254
+ /* @__PURE__ */ jsx("polyline", {
1255
+ points: poly,
1256
+ fill: "none",
1257
+ strokeWidth: 1.6,
1258
+ strokeLinecap: "round",
1259
+ strokeLinejoin: "round",
1260
+ style: { stroke: color }
1261
+ }),
1262
+ showEndDot && last && /* @__PURE__ */ jsx("circle", {
1263
+ cx: last.x,
1264
+ cy: last.y,
1265
+ r: 2.2,
1266
+ style: { fill: color }
1267
+ })
1268
+ ]
1269
+ });
1270
+ }
1271
+ //#endregion
1272
+ //#region src/app/components/code-block.tsx
1273
+ const KEYWORDS = /* @__PURE__ */ new Set([
1274
+ "import",
1275
+ "from",
1276
+ "export",
1277
+ "default",
1278
+ "const",
1279
+ "let",
1280
+ "var",
1281
+ "function",
1282
+ "return",
1283
+ "if",
1284
+ "else",
1285
+ "for",
1286
+ "while",
1287
+ "switch",
1288
+ "case",
1289
+ "break",
1290
+ "continue",
1291
+ "async",
1292
+ "await",
1293
+ "try",
1294
+ "catch",
1295
+ "finally",
1296
+ "throw",
1297
+ "new",
1298
+ "class",
1299
+ "extends",
1300
+ "implements",
1301
+ "interface",
1302
+ "type",
1303
+ "satisfies",
1304
+ "as",
1305
+ "true",
1306
+ "false",
1307
+ "null",
1308
+ "undefined",
1309
+ "def",
1310
+ "elif",
1311
+ "in",
1312
+ "and",
1313
+ "or",
1314
+ "not",
1315
+ "SELECT",
1316
+ "FROM",
1317
+ "WHERE",
1318
+ "GROUP",
1319
+ "BY",
1320
+ "ORDER",
1321
+ "LIMIT",
1322
+ "JOIN",
1323
+ "ON"
1324
+ ]);
1325
+ const TOKEN_RE = /(\/\/[^\n]*|#[^\n]*|\/\*[\s\S]*?\*\/)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)|\b(\d+(?:\.\d+)?)\b|\b([A-Za-z_][A-Za-z0-9_]*)\b/g;
1326
+ function tokenizeLine(line) {
1327
+ const out = [];
1328
+ let cursor = 0;
1329
+ for (const match of line.matchAll(TOKEN_RE)) {
1330
+ const idx = match.index ?? 0;
1331
+ if (idx > cursor) out.push({
1332
+ kind: "plain",
1333
+ text: line.slice(cursor, idx)
1334
+ });
1335
+ const [full, comment, str, num, ident] = match;
1336
+ if (comment !== void 0) out.push({
1337
+ kind: "comment",
1338
+ text: full
1339
+ });
1340
+ else if (str !== void 0) out.push({
1341
+ kind: "string",
1342
+ text: full
1343
+ });
1344
+ else if (num !== void 0) out.push({
1345
+ kind: "number",
1346
+ text: full
1347
+ });
1348
+ else if (ident !== void 0) {
1349
+ if (KEYWORDS.has(ident)) out.push({
1350
+ kind: "keyword",
1351
+ text: full
1352
+ });
1353
+ else if (/^[A-Z]/.test(ident)) out.push({
1354
+ kind: "type",
1355
+ text: full
1356
+ });
1357
+ else out.push({
1358
+ kind: "plain",
1359
+ text: full
1360
+ });
1361
+ }
1362
+ cursor = idx + full.length;
1363
+ }
1364
+ if (cursor < line.length) out.push({
1365
+ kind: "plain",
1366
+ text: line.slice(cursor)
1367
+ });
1368
+ return out;
1369
+ }
1370
+ function tokenStyle(kind) {
1371
+ switch (kind) {
1372
+ case "keyword": return {
1373
+ color: "var(--od-accent, #2563eb)",
1374
+ fontWeight: 600
1375
+ };
1376
+ case "string": return { color: "#0f766e" };
1377
+ case "comment": return {
1378
+ color: "var(--od-muted, #6b7280)",
1379
+ fontStyle: "italic"
1380
+ };
1381
+ case "number": return { color: "#b45309" };
1382
+ case "type": return {
1383
+ color: "color-mix(in srgb, var(--od-accent, #2563eb) 75%, var(--od-text, #16181d))",
1384
+ fontWeight: 500
1385
+ };
1386
+ default: return;
1387
+ }
1388
+ }
1389
+ /**
1390
+ * Print-ready syntax-highlighted code block with optional header bar, line
1391
+ * numbers, and highlighted lines. Uses `--od-*` variables so it harmonizes with
1392
+ * the document's design system and exports cleanly to PDF, HTML, and Word.
1393
+ */
1394
+ function CodeBlock({ code, children, lang, title, lineNumbers = false, highlightLines, style, className, [LOC_PROP]: loc }) {
1395
+ const lines = (code ?? children ?? "").replace(/^\n+|\s+$/g, "").split("\n");
1396
+ const highlighted = new Set(highlightLines ?? []);
1397
+ return /* @__PURE__ */ jsxs("div", {
1398
+ ...sourceAttrs(loc),
1399
+ className,
1400
+ style: {
1401
+ border: "1px solid var(--od-rule, #e5e7eb)",
1402
+ borderRadius: "var(--od-radius, 6px)",
1403
+ background: "color-mix(in srgb, var(--od-text, #16181d) 3%, var(--od-bg, #ffffff))",
1404
+ overflow: "hidden",
1405
+ margin: "0 0 12px",
1406
+ ...style
1407
+ },
1408
+ children: [(title || lang) && /* @__PURE__ */ jsxs("div", {
1409
+ style: {
1410
+ display: "flex",
1411
+ alignItems: "center",
1412
+ justifyContent: "space-between",
1413
+ padding: "5px 12px",
1414
+ borderBottom: "1px solid var(--od-rule, #e5e7eb)",
1415
+ background: "color-mix(in srgb, var(--od-text, #16181d) 5%, var(--od-bg, #ffffff))",
1416
+ fontFamily: "var(--od-font-mono, monospace)",
1417
+ fontSize: 10.5,
1418
+ color: "var(--od-muted, #6b7280)"
1419
+ },
1420
+ children: [/* @__PURE__ */ jsx("span", {
1421
+ style: {
1422
+ fontWeight: 600,
1423
+ color: "var(--od-text, #16181d)"
1424
+ },
1425
+ children: title ?? ""
1426
+ }), lang && /* @__PURE__ */ jsx("span", {
1427
+ style: {
1428
+ textTransform: "uppercase",
1429
+ letterSpacing: "0.05em",
1430
+ fontSize: 9.5
1431
+ },
1432
+ children: lang
1433
+ })]
1434
+ }), /* @__PURE__ */ jsx("pre", {
1435
+ style: {
1436
+ margin: 0,
1437
+ padding: "10px 12px",
1438
+ fontFamily: "var(--od-font-mono, monospace)",
1439
+ fontSize: 11,
1440
+ lineHeight: 1.55,
1441
+ color: "var(--od-text, #16181d)",
1442
+ whiteSpace: "pre-wrap",
1443
+ overflowWrap: "anywhere"
1444
+ },
1445
+ children: lines.map((line, index) => {
1446
+ const lineNo = index + 1;
1447
+ const isHighlighted = highlighted.has(lineNo);
1448
+ const tokens = tokenizeLine(line);
1449
+ return /* @__PURE__ */ jsxs("div", {
1450
+ style: {
1451
+ display: "flex",
1452
+ ...isHighlighted ? {
1453
+ background: "color-mix(in srgb, var(--od-accent, #2563eb) 10%, transparent)",
1454
+ margin: "0 -12px",
1455
+ padding: "0 12px",
1456
+ borderLeft: "2.5px solid var(--od-accent, #2563eb)"
1457
+ } : {}
1458
+ },
1459
+ children: [lineNumbers && /* @__PURE__ */ jsx("span", {
1460
+ "aria-hidden": "true",
1461
+ style: {
1462
+ flex: "none",
1463
+ width: 24,
1464
+ paddingRight: 8,
1465
+ textAlign: "right",
1466
+ color: "var(--od-muted, #6b7280)",
1467
+ userSelect: "none",
1468
+ fontVariantNumeric: "tabular-nums",
1469
+ opacity: .65
1470
+ },
1471
+ children: lineNo
1472
+ }), /* @__PURE__ */ jsx("span", {
1473
+ style: { flex: 1 },
1474
+ children: tokens.length === 0 ? "\xA0" : tokens.map((tok, ti) => /* @__PURE__ */ jsx("span", {
1475
+ style: tokenStyle(tok.kind),
1476
+ children: tok.text
1477
+ }, ti))
1478
+ })]
1479
+ }, index);
1480
+ })
1481
+ })]
1482
+ });
1483
+ }
1484
+ //#endregion
1485
+ //#region src/app/components/flow-page.tsx
1486
+ const SLICE_CONTEXT_KEY = "__open_doc_table_slice_context__";
1487
+ const g$1 = globalThis;
1488
+ if (!g$1[SLICE_CONTEXT_KEY]) g$1[SLICE_CONTEXT_KEY] = createContext(null);
1489
+ const TableSliceContext = g$1[SLICE_CONTEXT_KEY];
1490
+ function useTableSlice() {
1491
+ return useContext(TableSliceContext);
1492
+ }
820
1493
  //#endregion
821
1494
  //#region src/app/components/data-table.tsx
822
1495
  function normalizeColumn(column) {
@@ -842,23 +1515,66 @@ function formatValue(value, format, row, emptyValue) {
842
1515
  if (isNumber(value)) {
843
1516
  if (format === "integer") return Math.round(value).toLocaleString();
844
1517
  if (format === "percent") return `${(value * 100).toLocaleString(void 0, { maximumFractionDigits: 1 })}%`;
1518
+ if (format === "currency") return `$${value.toLocaleString(void 0, {
1519
+ minimumFractionDigits: 0,
1520
+ maximumFractionDigits: 2
1521
+ })}`;
1522
+ if (format === "delta") {
1523
+ const text = `${value > 0 ? "+" : ""}${value.toLocaleString(void 0, { maximumFractionDigits: 2 })}`;
1524
+ return /* @__PURE__ */ jsx("span", {
1525
+ style: {
1526
+ color: value > 0 ? "#15803d" : value < 0 ? "#b91c1c" : "var(--od-muted)",
1527
+ fontWeight: 500
1528
+ },
1529
+ children: text
1530
+ });
1531
+ }
845
1532
  if (format === "text") return String(value);
846
1533
  return value.toLocaleString(void 0, { maximumFractionDigits: 2 });
847
1534
  }
848
1535
  return String(value);
849
1536
  }
1537
+ function computeSummary(op, values, format, emptyValue) {
1538
+ if (typeof op === "function") return op(values);
1539
+ if (op === "sum" || op === "avg" || op === "min" || op === "max" || op === "count") {
1540
+ if (values.length === 0) return emptyValue;
1541
+ let num = 0;
1542
+ if (op === "count") num = values.length;
1543
+ else if (op === "sum") num = values.reduce((a, b) => a + b, 0);
1544
+ else if (op === "avg") num = values.reduce((a, b) => a + b, 0) / values.length;
1545
+ else if (op === "min") num = Math.min(...values);
1546
+ else if (op === "max") num = Math.max(...values);
1547
+ return formatValue(num, op === "count" ? "integer" : format, {}, emptyValue);
1548
+ }
1549
+ return op;
1550
+ }
850
1551
  /**
851
1552
  * A print-shaped table from data, so the numbers in a report come from a file
852
1553
  * instead of being retyped into JSX. Alignment and grouping follow the column's
853
1554
  * contents, which is the part people get wrong by hand.
854
1555
  */
855
- function DataTable({ rows, columns, caption, id, limit, compact = false, emptyValue = "—", style, className, [LOC_PROP]: loc }) {
1556
+ function DataTable({ rows, columns, caption, id, limit, compact = false, splittable = false, summaryRow, summaryLabel = "Total", emptyValue = "—", style, className, [LOC_PROP]: loc }) {
1557
+ const slice = useTableSlice();
856
1558
  const resolved = (columns ?? Object.keys(rows[0] ?? {})).map(normalizeColumn);
857
- const shown = limit !== void 0 ? rows.slice(0, limit) : rows;
858
- const hidden = rows.length - shown.length;
1559
+ const limited = limit !== void 0 ? rows.slice(0, limit) : rows;
1560
+ const hidden = rows.length - limited.length;
1561
+ const isContinued = splittable && slice !== null && slice.rowStart > 0;
1562
+ const isLastSlice = !splittable || slice === null || slice.rowEnd >= limited.length;
1563
+ const shown = splittable && slice !== null ? limited.slice(slice.rowStart, slice.rowEnd) : limited;
1564
+ const maxByCol = /* @__PURE__ */ new Map();
1565
+ for (const col of resolved) {
1566
+ if (!col.dataBar) continue;
1567
+ let max = 0;
1568
+ for (const row of limited) {
1569
+ const v = row[col.key];
1570
+ if (isNumber(v) && Math.abs(v) > max) max = Math.abs(v);
1571
+ }
1572
+ if (max > 0) maxByCol.set(col.key, max);
1573
+ }
859
1574
  const cellPadding = compact ? "4px 8px" : "7px 8px";
860
1575
  const table = /* @__PURE__ */ jsxs("table", {
861
1576
  ...caption ? {} : sourceAttrs(loc),
1577
+ ...splittable ? { "data-od-splittable": "" } : {},
862
1578
  className,
863
1579
  style: {
864
1580
  width: "100%",
@@ -891,6 +1607,9 @@ function DataTable({ rows, columns, caption, id, limit, compact = false, emptyVa
891
1607
  }) }) }),
892
1608
  /* @__PURE__ */ jsx("tbody", { children: shown.map((row, rowIndex) => /* @__PURE__ */ jsx("tr", { children: resolved.map((column) => {
893
1609
  const align = column.align ?? inferAlign(rows, column.key);
1610
+ const val = row[column.key];
1611
+ const maxBar = maxByCol.get(column.key);
1612
+ const barRatio = maxBar && isNumber(val) ? Math.min(1, Math.max(0, Math.abs(val) / maxBar)) : 0;
894
1613
  return /* @__PURE__ */ jsx("td", {
895
1614
  style: {
896
1615
  textAlign: align,
@@ -898,12 +1617,35 @@ function DataTable({ rows, columns, caption, id, limit, compact = false, emptyVa
898
1617
  padding: cellPadding,
899
1618
  borderBottom: "1px solid var(--od-rule)",
900
1619
  fontVariantNumeric: align === "right" ? "tabular-nums" : void 0,
901
- overflowWrap: "anywhere"
1620
+ overflowWrap: "anywhere",
1621
+ ...barRatio > 0 ? { backgroundImage: `linear-gradient(to right, color-mix(in srgb, var(--od-accent, #2563eb) 14%, transparent) ${(barRatio * 100).toFixed(1)}%, transparent ${(barRatio * 100).toFixed(1)}%)` } : {}
902
1622
  },
903
- children: formatValue(row[column.key], column.format, row, emptyValue)
1623
+ children: formatValue(val, column.format, row, emptyValue)
904
1624
  }, column.key);
905
1625
  }) }, rowIndex)) }),
906
- hidden > 0 && /* @__PURE__ */ jsx("tfoot", { children: /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsxs("td", {
1626
+ isLastSlice && (summaryRow || hidden > 0) && /* @__PURE__ */ jsxs("tfoot", { children: [summaryRow && /* @__PURE__ */ jsx("tr", { children: resolved.map((column, colIndex) => {
1627
+ const align = column.align ?? inferAlign(rows, column.key);
1628
+ const explicit = typeof summaryRow === "object" ? summaryRow[column.key] : column.summary;
1629
+ let content = null;
1630
+ if (explicit !== void 0) {
1631
+ if (explicit === "count") {
1632
+ const nonNull = limited.filter((r) => r[column.key] !== null && r[column.key] !== void 0 && r[column.key] !== "").length;
1633
+ content = formatValue(nonNull, "integer", {}, emptyValue);
1634
+ } else content = computeSummary(explicit, limited.map((r) => r[column.key]).filter(isNumber), column.format, emptyValue);
1635
+ } else if (colIndex === 0) content = summaryLabel;
1636
+ return /* @__PURE__ */ jsx("td", {
1637
+ style: {
1638
+ textAlign: align,
1639
+ fontSize: compact ? 11 : 12,
1640
+ fontWeight: 600,
1641
+ padding: cellPadding,
1642
+ borderTop: "1.5px solid var(--od-text)",
1643
+ borderBottom: "1px solid var(--od-rule)",
1644
+ fontVariantNumeric: align === "right" ? "tabular-nums" : void 0
1645
+ },
1646
+ children: content
1647
+ }, column.key);
1648
+ }) }), hidden > 0 && /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsxs("td", {
907
1649
  colSpan: resolved.length,
908
1650
  style: {
909
1651
  fontSize: "var(--od-size-caption)",
@@ -916,14 +1658,16 @@ function DataTable({ rows, columns, caption, id, limit, compact = false, emptyVa
916
1658
  hidden === 1 ? "" : "s",
917
1659
  " not shown"
918
1660
  ]
919
- }) }) })
1661
+ }) })] })
920
1662
  ]
921
1663
  });
922
1664
  if (!caption) return table;
1665
+ const effectiveCaption = isContinued && typeof caption === "string" ? `${caption} (cont.)` : caption;
923
1666
  return /* @__PURE__ */ jsx(Figure, {
924
1667
  kind: "table",
925
- caption,
926
- ...id !== void 0 ? { id } : {},
1668
+ caption: effectiveCaption,
1669
+ ...id !== void 0 && !isContinued ? { id } : {},
1670
+ ...isContinued ? { numbered: false } : {},
927
1671
  ...sourceAttrs(loc),
928
1672
  children: table
929
1673
  });
@@ -1032,7 +1776,7 @@ function TableOfContents({ maxLevel = 2, showPageNumbers = true, includeOwnPage
1032
1776
  fontWeight: entry.level === 1 ? 600 : 400,
1033
1777
  color: entry.level === 1 ? "var(--od-text)" : "var(--od-muted)"
1034
1778
  },
1035
- children: [/* @__PURE__ */ jsx("span", { children: entry.text }), showPageNumbers && /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", {
1779
+ children: [/* @__PURE__ */ jsx("span", { children: entry.text }), showPageNumbers && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
1036
1780
  "aria-hidden": true,
1037
1781
  style: {
1038
1782
  flex: 1,
@@ -1056,7 +1800,7 @@ function toBlocks(node) {
1056
1800
  const out = [];
1057
1801
  for (const child of Children.toArray(node)) {
1058
1802
  if (!isValidElement(child)) continue;
1059
- if (child.type === Fragment) {
1803
+ if (child.type === Fragment$1) {
1060
1804
  out.push(...toBlocks(child.props.children));
1061
1805
  continue;
1062
1806
  }
@@ -1082,7 +1826,9 @@ function isFlowSection(entry) {
1082
1826
  /**
1083
1827
  * Greedy top-to-bottom packing: fill a page until the next block would cross
1084
1828
  * the bottom edge, then push that block — plus anything glued to it — onto the
1085
- * next page. Blocks are atomic; nothing is split mid-block.
1829
+ * next page. Blocks are atomic unless marked `splittable`, in which case rows
1830
+ * pack into the remaining space and continue on the next sheet with the header
1831
+ * repeated.
1086
1832
  *
1087
1833
  * Footnotes are packed from the same budget: a block that carries notes brings
1088
1834
  * their height with it, because those notes print at the foot of whichever page
@@ -1090,45 +1836,105 @@ function isFlowSection(entry) {
1090
1836
  */
1091
1837
  function paginateBlocks(blocks, available, opts = {}) {
1092
1838
  const overhead = opts.footnoteOverhead ?? 0;
1093
- const pages = [];
1839
+ const slices = [];
1094
1840
  const overflowing = [];
1095
1841
  let current = [];
1096
1842
  let used = 0;
1097
1843
  let notes = 0;
1098
- const heightOf = (indices) => indices.reduce((sum, index) => sum + (blocks[index]?.height ?? 0), 0);
1099
- const notesOf = (indices) => indices.reduce((sum, index) => sum + (blocks[index]?.footnoteHeight ?? 0), 0);
1844
+ const sliceHeight = (slice) => {
1845
+ const block = blocks[slice.index];
1846
+ if (!block) return 0;
1847
+ if (slice.rowStart !== void 0 && slice.rowEnd !== void 0 && block.splittable) {
1848
+ let rows = 0;
1849
+ for (let r = slice.rowStart; r < slice.rowEnd; r++) rows += block.splittable.rowHeights[r] ?? 0;
1850
+ const isLast = slice.rowEnd >= block.splittable.rowHeights.length;
1851
+ return block.splittable.headerHeight + rows + (isLast ? block.splittable.footerHeight : 0);
1852
+ }
1853
+ return block.height;
1854
+ };
1855
+ const heightOf = (items) => items.reduce((sum, item) => sum + sliceHeight(item), 0);
1856
+ const notesOf = (items) => items.reduce((sum, item) => sum + (item.rowStart === void 0 || item.rowStart === 0 ? blocks[item.index]?.footnoteHeight ?? 0 : 0), 0);
1100
1857
  /** A page with no notes pays nothing; the first note also pays for the rule. */
1101
1858
  const reserve = (total) => total > 0 ? total + overhead : 0;
1102
1859
  const closePage = () => {
1103
1860
  if (current.length === 0) return;
1104
- pages.push(current);
1861
+ slices.push(current);
1105
1862
  current = [];
1106
1863
  used = 0;
1107
1864
  notes = 0;
1108
1865
  };
1109
1866
  blocks.forEach((block, index) => {
1110
1867
  const own = block.footnoteHeight ?? 0;
1111
- if (block.height + reserve(own) > available) overflowing.push(index);
1112
1868
  if (block.breakBefore) closePage();
1869
+ const split = block.splittable;
1870
+ const canSplit = split && split.rowHeights.length > 1;
1871
+ if (!canSplit && block.height + reserve(own) > available) overflowing.push(index);
1113
1872
  if (current.length > 0 && used + block.height + reserve(notes + own) > available) {
1114
1873
  let splitAt = current.length;
1115
- while (splitAt > 0 && blocks[current[splitAt - 1]]?.keepWithNext) splitAt--;
1874
+ while (splitAt > 0 && blocks[current[splitAt - 1].index]?.keepWithNext) splitAt--;
1116
1875
  if (block.keepWithPrevious && splitAt === current.length) splitAt--;
1117
- if (splitAt > 0 && splitAt < current.length) {
1876
+ if (canSplit) {
1877
+ const firstRowCost = split.headerHeight + (split.rowHeights[0] ?? 0);
1878
+ if (used + firstRowCost + reserve(notes + own) > available) {
1879
+ if (splitAt > 0 && splitAt < current.length) {
1880
+ const moved = current.slice(splitAt);
1881
+ slices.push(current.slice(0, splitAt));
1882
+ current = moved;
1883
+ used = heightOf(moved);
1884
+ notes = notesOf(moved);
1885
+ } else closePage();
1886
+ }
1887
+ } else if (splitAt > 0 && splitAt < current.length) {
1118
1888
  const moved = current.slice(splitAt);
1119
- pages.push(current.slice(0, splitAt));
1889
+ slices.push(current.slice(0, splitAt));
1120
1890
  current = moved;
1121
1891
  used = heightOf(moved);
1122
1892
  notes = notesOf(moved);
1123
1893
  } else closePage();
1124
1894
  }
1125
- current.push(index);
1895
+ if (canSplit && used + block.height + reserve(notes + own) > available) {
1896
+ let rowCursor = 0;
1897
+ const totalRows = split.rowHeights.length;
1898
+ let firstSlice = true;
1899
+ while (rowCursor < totalRows) {
1900
+ const sliceNotes = firstSlice ? own : 0;
1901
+ const budget = available - used - reserve(notes + sliceNotes) - split.headerHeight;
1902
+ let rowEnd = rowCursor;
1903
+ let rowSum = 0;
1904
+ while (rowEnd < totalRows) {
1905
+ const rHeight = split.rowHeights[rowEnd] ?? 0;
1906
+ const tail = rowEnd + 1 === totalRows ? split.footerHeight : 0;
1907
+ if (rowSum + rHeight + tail <= budget || rowEnd === rowCursor && current.length === 0) {
1908
+ rowSum += rHeight;
1909
+ rowEnd++;
1910
+ } else break;
1911
+ }
1912
+ if (rowEnd === rowCursor) {
1913
+ closePage();
1914
+ continue;
1915
+ }
1916
+ const slice = {
1917
+ index,
1918
+ rowStart: rowCursor,
1919
+ rowEnd
1920
+ };
1921
+ current.push(slice);
1922
+ used += sliceHeight(slice);
1923
+ notes += sliceNotes;
1924
+ firstSlice = false;
1925
+ rowCursor = rowEnd;
1926
+ if (rowCursor < totalRows) closePage();
1927
+ }
1928
+ return;
1929
+ }
1930
+ current.push({ index });
1126
1931
  used += block.height;
1127
1932
  notes += own;
1128
1933
  });
1129
1934
  closePage();
1130
1935
  return {
1131
- pages,
1936
+ pages: slices.map((page) => page.map((s) => s.index)),
1937
+ slices,
1132
1938
  overflowing
1133
1939
  };
1134
1940
  }
@@ -1168,4 +1974,4 @@ function Field({ name, fallback }) {
1168
1974
  return createElement("span", null, String(value));
1169
1975
  }
1170
1976
  //#endregion
1171
- export { Chart, DEFAULT_ORIENTATION, DEFAULT_PAGE_SIZE, DataTable, Diagram, DiagramSyntaxError, Field, 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, useRecord };
1977
+ export { Bibliography, Callout, Chart, Cite, CodeBlock, DEFAULT_ORIENTATION, DEFAULT_PAGE_SIZE, DataTable, Diagram, DiagramSyntaxError, Field, Figure, Footnote, Footnotes, ImagePlaceholder, ListOf, ListOfFigures, ListOfTables, ORIENTATIONS, PAGE_SIZES, PAGE_SIZE_NAMES, Ref, Sparkline, TableOfContents, compileDiagram, cssVarsToString, defaultDesign, designToCssVars, flow, isFlowSection, isOrientation, isPageSizeName, paginateBlocks, parseDelimited, resolvePageGeometry, useDocLabel, useDocLabels, useDocOutline, useDocPageCount, useDocPageNumber, useRecord };