@openpresentation/opf 0.33.0 → 0.34.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 (93) hide show
  1. package/README.md +3 -3
  2. package/dist/browser.js +20 -19
  3. package/dist/catalog-refs-CoIrOdAw.d.ts +937 -0
  4. package/dist/{catalog-schemas-CQTM-G8p.d.ts → catalog-schemas-FjLRPtjB.d.ts} +1 -1
  5. package/dist/{chart-data-oIZQlFGi.d.ts → chart-data-B_k-WTex.d.ts} +7 -4
  6. package/dist/{chunk-XIOC6N5P.js → chunk-244OPLAV.js} +1 -1
  7. package/dist/{chunk-S5QRGMUQ.js → chunk-2HX4BGAS.js} +6 -6
  8. package/dist/{chunk-Y557TYML.js → chunk-36DLVJGW.js} +19 -16
  9. package/dist/{chunk-VKEYV3ZK.js → chunk-3THGTDL2.js} +2 -2
  10. package/dist/{chunk-ABWEUXLV.js → chunk-42JBXJKW.js} +117 -21
  11. package/dist/chunk-BLCDUM7B.js +7 -0
  12. package/dist/{chunk-OPVJLL7H.js → chunk-CJVKOJ6B.js} +11841 -8687
  13. package/dist/{chunk-BI4ERFAA.js → chunk-DQ7QYOUV.js} +48 -13
  14. package/dist/{chunk-KVHNDHVS.js → chunk-F6BXO4AI.js} +1 -1
  15. package/dist/{chunk-UK3J6FSU.js → chunk-FAXO3SUE.js} +858 -268
  16. package/dist/{chunk-XANW7MB7.js → chunk-FIQMAIZV.js} +4 -4
  17. package/dist/{chunk-PJSPHHRK.js → chunk-FK5XG742.js} +3 -16
  18. package/dist/{chunk-R6C6BQOG.js → chunk-HHVQ2SDT.js} +1 -1
  19. package/dist/{chunk-DAS75LGR.js → chunk-HUGVYHZ2.js} +4 -4
  20. package/dist/{chunk-QF5RSRXU.js → chunk-LCT5ZV3Q.js} +750 -199
  21. package/dist/chunk-NLJFNCZ4.js +1560 -0
  22. package/dist/{chunk-VSBZC2PR.js → chunk-QGJVOPLG.js} +3 -3
  23. package/dist/{chunk-E7WQHMCL.js → chunk-QGTJF7HV.js} +16 -14
  24. package/dist/{chunk-VMBLNCX2.js → chunk-RUV7CCE6.js} +117 -30
  25. package/dist/{chunk-YS333HLA.js → chunk-U7TYSPYM.js} +2 -2
  26. package/dist/chunk-UJZN2ZH6.js +1 -0
  27. package/dist/{chunk-IJXKVM4W.js → chunk-VDZXNNZF.js} +1 -1
  28. package/dist/{chunk-YYT6N7AI.js → chunk-WCPDN7AY.js} +1 -1
  29. package/dist/{chunk-QD6DPS7X.js → chunk-WMFT5R7I.js} +2 -2
  30. package/dist/{chunk-INIMUBSE.js → chunk-XJUMFH33.js} +1 -1
  31. package/dist/{composition-zMiIgzip.d.ts → composition-CvtvgBDE.d.ts} +1360 -1531
  32. package/dist/composition.d.ts +3 -3
  33. package/dist/composition.js +2 -1
  34. package/dist/{conversion-mNth9XKm.d.ts → conversion-B_5AKTYQ.d.ts} +25 -7
  35. package/dist/conversion-CMBGOTAC.js +25 -0
  36. package/dist/convert.d.ts +4 -4
  37. package/dist/convert.js +15 -11
  38. package/dist/data.d.ts +2 -2
  39. package/dist/data.js +3 -2
  40. package/dist/{deck-report-BSlRiR0_.d.ts → deck-report-BVlQZ42f.d.ts} +3 -3
  41. package/dist/deck.d.ts +6 -6
  42. package/dist/deck.js +12 -11
  43. package/dist/diagram-engine-eager.js +5 -1
  44. package/dist/diagram-engine-lazy.js +13 -0
  45. package/dist/diagram-plantuml-XRZ6VAOL.js +3 -0
  46. package/dist/diff.js +5 -4
  47. package/dist/docs.js +64 -52
  48. package/dist/examples.js +4070 -1083
  49. package/dist/font-policy.js +1 -1
  50. package/dist/format.js +2 -2
  51. package/dist/ids.js +5 -4
  52. package/dist/index.d.ts +18 -16
  53. package/dist/index.js +35 -24
  54. package/dist/markdown.d.ts +2 -2
  55. package/dist/markdown.js +9 -8
  56. package/dist/node-engine.d.ts +43 -11
  57. package/dist/node-engine.js +45 -26
  58. package/dist/{pagination-CYzNMazO.d.ts → pagination-CZQQYk7L.d.ts} +4 -3
  59. package/dist/pagination.d.ts +4 -4
  60. package/dist/pagination.js +5 -4
  61. package/dist/patch.js +4 -3
  62. package/dist/precompiled.js +2 -2
  63. package/dist/{presentation-CXhfpB_z.d.ts → presentation-s9262acV.d.ts} +357 -230
  64. package/dist/repo-readme.js +1 -1
  65. package/dist/schema-engine-ajv.js +1 -1
  66. package/dist/schema-engine-precompiled.js +2 -2
  67. package/dist/schema.d.ts +3 -3
  68. package/dist/schema.js +4 -3
  69. package/dist/schemas.d.ts +16 -0
  70. package/dist/schemas.js +1 -1
  71. package/dist/shape-engine-eager.js +2 -2
  72. package/dist/shape-engine-lazy.js +1 -1
  73. package/dist/{shape-engine-module-BK7JNEUV.js → shape-engine-module-N74FCHGY.js} +2 -2
  74. package/dist/shape-geometry.js +1 -1
  75. package/dist/source.d.ts +10 -5
  76. package/dist/source.js +11 -10
  77. package/dist/spec/reference/engine-vocabularies.json +135 -0
  78. package/dist/spec/reference/font-policy.json +3 -16
  79. package/dist/spec/reference/preset-geometry.json +3 -3
  80. package/dist/spec/schemas/icon-set.schema.json +1 -1
  81. package/dist/spec/schemas/layout.schema.json +71 -25
  82. package/dist/spec/schemas/opf.schema.json +540 -168
  83. package/dist/spec/schemas/theme.schema.json +11 -5
  84. package/dist/types.d.ts +81 -73
  85. package/dist/{validation-types-COwTel3H.d.ts → validation-types-CYbsUuZ9.d.ts} +8 -5
  86. package/dist/validator.d.ts +34 -7
  87. package/dist/validator.js +4 -3
  88. package/dist/yaml.d.ts +2 -2
  89. package/dist/yaml.js +8 -7
  90. package/package.json +6 -6
  91. package/dist/catalog-refs-B_0_vZg0.d.ts +0 -134
  92. package/dist/chunk-ZXOIGUHX.js +0 -1
  93. package/dist/conversion-POHRAMSN.js +0 -24
@@ -1,4 +1,4 @@
1
- import { a as CatalogKind } from './catalog-refs-B_0_vZg0.js';
1
+ import { a as CatalogKind } from './catalog-refs-CoIrOdAw.js';
2
2
  import { SchemaName } from './schemas.js';
3
3
 
4
4
  /**
@@ -57,7 +57,7 @@ interface DataStyledCell {
57
57
  type DataTableCell = DataTableValue | DataStyledCell;
58
58
  /** A table column header: a cell, or a DataColumn. */
59
59
  type DataTableHeader = DataTableCell | DataColumn;
60
- type DataDiagnosticCode = 'chart-value-not-numeric' | 'dataset-unknown' | 'dataset-field-unknown' | 'data-column-duplicate' | 'chart-mapping-unknown-column' | 'chart-mapping-adapted' | 'chart-highlight-unknown-name' | 'chart-highlight-adapted' | 'chart-series-dropped' | 'table-highlight-unknown-name' | 'number-format-invalid';
60
+ type DataDiagnosticCode = 'chart-value-not-numeric' | 'dataset-unknown' | 'dataset-field-unknown' | 'data-column-duplicate' | 'chart-mapping-unknown-column' | 'chart-mapping-adapted' | 'chart-highlight-unknown-name' | 'chart-highlight-adapted' | 'chart-series-dropped' | 'chart-reference-axis-unavailable' | 'chart-reference-unsupported-type' | 'table-highlight-unknown-name' | 'number-format-invalid';
61
61
  interface DataDiagnostic {
62
62
  code: DataDiagnosticCode;
63
63
  severity: 'error' | 'warning';
@@ -117,8 +117,11 @@ interface ResolvedTableData {
117
117
  declare function chartNumber(value: unknown): number | null;
118
118
  /** Why a NumberFormat is invalid, or undefined for a valid one. An absent format is valid (General). */
119
119
  declare function numberFormatError(format: unknown): string | undefined;
120
- /** Format a number with a NumberFormat; an absent or invalid format prints the General form (String(value)). */
121
- declare function formatDataNumber(value: number, format?: string): string;
120
+ /**
121
+ * Format a number with a NumberFormat; an absent or invalid format prints the General form (String(value)). LH-106: with `language`
122
+ * the text is in that language's numbering system (see `formatVariableNumber`); without it, Latin.
123
+ */
124
+ declare function formatDataNumber(value: number, format?: string, language?: string): string;
122
125
  /** NumberFormat -> Excel format code ("General" when absent or invalid). Literal prefix/suffix text is quoted or escaped; placeholders are written '#' before '0' ("0#" -> "#0"). */
123
126
  declare function toExcelNumberFormat(format?: string): string;
124
127
  /** Excel format code -> NumberFormat, or undefined when the code has no exact NumberFormat equivalent (General, sections, scaling commas, and placeholder orders Excel reads by position such as "0#" or "0.#0"). */
@@ -185,7 +188,7 @@ declare function resolveTableData(table: unknown, document?: unknown, options?:
185
188
  /** LH-113: the text of a table cell as its key (the first column): a string, a number, rich runs or a styled cell's value. */
186
189
  declare function tableKeyText(cell: unknown): string;
187
190
  /** Display value of a table cell: a number with a format (cell, else column) becomes formatted text; anything else is returned unchanged. */
188
- declare function tableCellDisplayValue(cell: DataTableCell, columnFormat?: string): DataTableCell;
191
+ declare function tableCellDisplayValue(cell: DataTableCell, columnFormat?: string, language?: string): DataTableCell;
189
192
 
190
193
  export { resolveChartData as A, resolveTableData as B, suggestChartNumberFix as E, tableCellDisplayValue as F, toExcelNumberFormat as G, unusedDatasets as H, tableKeyText as J, chartNumber as q, datasetDiagnostics as r, formatDataNumber as s, fromExcelNumberFormat as t, inlineChartData as u, inlineDatasets as v, inlineTableData as w, isDatasetRef as x, isXYChartType as y, numberFormatError as z };
191
194
  export type { ChartMapping as C, DataCellValue as D, ChartComboSeries as I, ResolvedChartData as R, ChartNumberFix as a, ChartNumberFixOperation as b, ChartNumberFixOptions as c, DataColumn as d, DataDiagnostic as e, DataDiagnosticCode as f, DataResolveOptions as g, DataSourceRef as h, DataStyledCell as i, DataTableCell as j, DataTableHeader as k, DataTableValue as l, DataTextRun as m, Dataset as n, DatasetRef as o, ResolvedTableData as p };
@@ -1,4 +1,4 @@
1
- import { chartNumber } from './chunk-OPVJLL7H.js';
1
+ import { chartNumber } from './chunk-CJVKOJ6B.js';
2
2
 
3
3
  // src/data.ts
4
4
  var OPFDataImportError = class extends Error {
@@ -1,10 +1,10 @@
1
- import { sortPresentationKeys } from './chunk-R6C6BQOG.js';
1
+ import { sortPresentationKeys } from './chunk-HHVQ2SDT.js';
2
2
  import { NOT_CHECKED } from './chunk-RYZPBJLB.js';
3
- import { Ctx, describeYamlErrors } from './chunk-QD6DPS7X.js';
4
- import { same } from './chunk-VKEYV3ZK.js';
5
- import { validate } from './chunk-UK3J6FSU.js';
6
- import { presentation } from './chunk-QF5RSRXU.js';
7
- import { checkCatalogsOption } from './chunk-OPVJLL7H.js';
3
+ import { Ctx, describeYamlErrors } from './chunk-WMFT5R7I.js';
4
+ import { same } from './chunk-3THGTDL2.js';
5
+ import { validate } from './chunk-FAXO3SUE.js';
6
+ import { presentation } from './chunk-LCT5ZV3Q.js';
7
+ import { checkCatalogsOption } from './chunk-CJVKOJ6B.js';
8
8
  import { Parser, parseDocument, isMap, isSeq, Document, visit, isScalar, isAlias } from 'yaml';
9
9
 
10
10
  var MAX_ALIAS_COUNT = 100;
@@ -1,8 +1,8 @@
1
- import { parseQuoteLines, levelsFromIndents, parseCodeFence, splitWhen } from './chunk-KVHNDHVS.js';
2
- import { Ctx, splitLines, lineRange, readYamlMapping, readCsv, DECIMAL } from './chunk-QD6DPS7X.js';
3
- import { runText, isRecord, FORMATTING } from './chunk-VKEYV3ZK.js';
4
- import { METRIC_KEYS, nearest, BLOCK_AS_VALUES, SLIDE_OPTION_KEYS, BLOCK_OPTION_KEYS } from './chunk-UK3J6FSU.js';
5
- import { PROMOTED_REGION_KEY } from './chunk-OPVJLL7H.js';
1
+ import { parseQuoteLines, levelsFromIndents, parseCodeFence, splitWhen } from './chunk-F6BXO4AI.js';
2
+ import { Ctx, splitLines, lineRange, readYamlMapping, readCsv, DECIMAL } from './chunk-WMFT5R7I.js';
3
+ import { runText, isRecord, FORMATTING } from './chunk-3THGTDL2.js';
4
+ import { METRIC_KEYS, nearest, BLOCK_AS_VALUES, SLIDE_OPTION_KEYS, BLOCK_OPTION_KEYS } from './chunk-FAXO3SUE.js';
5
+ import { PROMOTED_REGION_KEY } from './chunk-CJVKOJ6B.js';
6
6
 
7
7
  // src/markdown/inline.ts
8
8
  var PUNCT = /[\p{P}\p{S}]/u;
@@ -23,7 +23,7 @@ var SPAN_FLAGS = {
23
23
  sub: "subscript",
24
24
  subscript: "subscript"
25
25
  };
26
- var SPAN_VALUES = { color: "color", size: "fontSize", fontsize: "fontSize", font: "fontFamily", fontfamily: "fontFamily", lang: "lang" };
26
+ var SPAN_VALUES = { color: "color", size: "fontSize", fontsize: "fontSize", font: "fontFamily", fontfamily: "fontFamily", lang: "language" };
27
27
  function parseAttributes(source) {
28
28
  const pairs = [];
29
29
  let i = 0;
@@ -457,12 +457,12 @@ function serializeRun(run, breakText) {
457
457
  if (!core) return edge(text);
458
458
  out = core.split("\n").map(escapeInline).join(breakText);
459
459
  }
460
- if (run.color !== void 0 || run.fontSize !== void 0 || run.fontFamily !== void 0 || run.lang !== void 0) {
460
+ if (run.color !== void 0 || run.fontSize !== void 0 || run.fontFamily !== void 0 || run.language !== void 0) {
461
461
  const attrs = [];
462
462
  if (run.color !== void 0) attrs.push(`color=${attrValue(String(run.color))}`);
463
463
  if (run.fontSize !== void 0) attrs.push(`size=${String(run.fontSize)}`);
464
464
  if (run.fontFamily !== void 0) attrs.push(`font=${attrValue(String(run.fontFamily))}`);
465
- if (run.lang !== void 0) attrs.push(`lang=${attrValue(String(run.lang))}`);
465
+ if (run.language !== void 0) attrs.push(`lang=${attrValue(String(run.language))}`);
466
466
  out = `[${out}]{${attrs.join(" ")}}`;
467
467
  }
468
468
  if (run.subscript === true) out = `<sub>${out}</sub>`;
@@ -620,7 +620,7 @@ function joinParagraph(lines) {
620
620
  var bold = (value) => typeof value === "string" ? [{ text: value, bold: true }] : value.map((run) => typeof run === "string" ? { text: run, bold: true } : { ...run, bold: true });
621
621
  function parseOptions(text, keys, kind, ctx, range) {
622
622
  const { pairs, error } = parseAttributes(text);
623
- const help = `A ${kind} options comment reads <!-- ${kind}: ${kind === "slide" ? 'id=cover layout=title section="Part 1" hidden' : "id=chart-1 as=bullets region=top:left"} -->. Keys: ${keys.join(", ")}.`;
623
+ const help = `A ${kind} options comment reads <!-- ${kind}: ${kind === "slide" ? 'id=cover layout=title section="Part 1" hidden' : "id=chart-1 as=bullets region=top:start"} -->. Keys: ${keys.join(", ")}.`;
624
624
  if (error) {
625
625
  ctx.error("options-syntax", error, help, range);
626
626
  return void 0;
@@ -955,7 +955,7 @@ var SlideParser = class {
955
955
  if (word === "chart") this.chart(rest, bodyText, range);
956
956
  else if (word === "metric") this.metric(body, range);
957
957
  else if (word === "timeline") this.timeline(rest, body, range);
958
- else if (word === "mermaid") this.diagram(rest, bodyText, range);
958
+ else if (word === "mermaid" || word === "dot" || word === "plantuml") this.diagram(word, rest, bodyText, range);
959
959
  else if (word === "opf-slide") this.embeddedSlide(bodyText, bodyStart, range);
960
960
  else if (word === "opf-block") this.embeddedBlock(bodyText, bodyStart, range);
961
961
  else {
@@ -971,21 +971,23 @@ var SlideParser = class {
971
971
  this.native("code", hasMeta ? value : parsed.source, range);
972
972
  }
973
973
  }
974
- // A ```mermaid fence is a diagram payload; `alt="..."` after the word is its text alternative.
975
- diagram(rest, text, range) {
974
+ // A ```mermaid, ```dot or ```plantuml fence is a diagram payload in that syntax; `alt="..."` after the word is its text alternative.
975
+ diagram(syntax, rest, text, range) {
976
976
  const { ctx } = this;
977
977
  const { pairs, error } = parseAttributes(rest);
978
978
  let alt;
979
- if (error) ctx.error("diagram-attributes", error, 'Write ```mermaid alt="What the diagram shows" (alt is optional).', range, this.path);
979
+ if (error) ctx.error("diagram-attributes", error, `Write \`\`\`${syntax} alt="What the diagram shows" (alt is optional).`, range, this.path);
980
980
  for (const [key, value] of pairs) {
981
981
  if (key === "alt" && typeof value === "string") alt = value;
982
- else ctx.error("diagram-attributes", `Unknown diagram attribute ${JSON.stringify(key)}.`, "A mermaid fence takes alt, a text alternative in double quotes.", range, this.path);
982
+ else ctx.error("diagram-attributes", `Unknown diagram attribute ${JSON.stringify(key)}.`, `A ${syntax} fence takes alt, a text alternative in double quotes.`, range, this.path);
983
983
  }
984
984
  if (!text.trim()) {
985
- ctx.error("diagram-source", "A mermaid block has no source.", "Write the Mermaid diagram between the fences, starting with its type (flowchart LR, sequenceDiagram, mindmap, ...).", range, this.path);
985
+ const advice = syntax === "dot" ? "Write the DOT graph between the fences (digraph { a -> b })." : syntax === "plantuml" ? "Write the PlantUML diagram between the fences, from @startuml to @enduml." : "Write the Mermaid diagram between the fences, starting with its type (flowchart LR, sequenceDiagram, mindmap, ...).";
986
+ ctx.error("diagram-source", `A ${syntax} block has no source.`, advice, range, this.path);
986
987
  return;
987
988
  }
988
- this.native("diagram", alt === void 0 ? text : { source: text, alt }, range);
989
+ if (syntax !== "mermaid") this.native("diagram", alt === void 0 ? { source: text, syntax } : { source: text, syntax, alt }, range);
990
+ else this.native("diagram", alt === void 0 ? text : { source: text, alt }, range);
989
991
  }
990
992
  chart(rest, text, range) {
991
993
  const { ctx } = this;
@@ -1144,6 +1146,7 @@ var SlideParser = class {
1144
1146
  set("layout", options.layout);
1145
1147
  set("section", options.section);
1146
1148
  set("tag", options.tag);
1149
+ set("language", options.language);
1147
1150
  set("title", this.title);
1148
1151
  set("subtitle", this.subtitle);
1149
1152
  const promoted = (block) => typeof block.options?.region === "string" && PROMOTED_REGION_KEY.test(block.options.region);
@@ -1,4 +1,4 @@
1
- import { validate } from './chunk-UK3J6FSU.js';
1
+ import { validate } from './chunk-FAXO3SUE.js';
2
2
 
3
3
  // src/convert/shared.ts
4
4
  var CONTENT_KEYS = ["text", "items", "bullets", "image", "video", "chart", "table", "code", "metric", "quote", "timeline", "diagram"];
@@ -47,7 +47,7 @@ function assertValidOutput(value, as = "block", context = {}) {
47
47
  }
48
48
  }
49
49
  var assertValidOwner = (owner, context = {}) => assertValidOutput(owner, isSlideLike(owner) ? "slide" : "block", context);
50
- var FORMATTING = ["bold", "italic", "underline", "strikethrough", "color", "fontSize", "fontFamily", "link", "superscript", "subscript", "code", "lang"];
50
+ var FORMATTING = ["bold", "italic", "underline", "strikethrough", "color", "fontSize", "fontFamily", "link", "superscript", "subscript", "code", "language"];
51
51
  var RUN_METADATA = [...FORMATTING, "cite", "footnote"];
52
52
  var isPlainRun = (run) => typeof run === "string" || isRecord(run) && !RUN_METADATA.some((key) => run[key] !== void 0);
53
53
  var runText = (run) => typeof run === "string" ? run : run.text ?? "";
@@ -1,5 +1,62 @@
1
- import { assertValid, resolveSlideScriptMeasurement, resolveDrawnFontFamilies, resolveSlideContext } from './chunk-UK3J6FSU.js';
2
- import { composeSlide, resolveSlideVariables, slideBlockIds, OPFCompositionError, checkCatalogsOption, usesSlideBuiltin, isOverlayConnector, codeHighlightSlice, tableRowBoundaries, visitContentPayloads, regionAccepts, slideTokenSpans, sliceNumberedItems, isShapeBlock } from './chunk-OPVJLL7H.js';
1
+ import { assertValid, resolveSlideScriptMeasurement, resolveDrawnFontFamilies, resolveSlideContext } from './chunk-FAXO3SUE.js';
2
+ import { composeSlide, resolveSlideVariables, slideBlockIds, OPFCompositionError, checkCatalogsOption, usesSlideBuiltin, isOverlayConnector, codeHighlightSlice, tableRowBoundaries, visitContentPayloads, layoutTable, regionAccepts, slideTokenSpans, sliceNumberedItems, isShapeBlock } from './chunk-CJVKOJ6B.js';
3
+
4
+ // src/continuation-fonts.ts
5
+ var record = (value) => value && typeof value === "object" ? value : {};
6
+ var continuationFontKey = (font) => JSON.stringify([font.path, font.part, font.style]);
7
+ var continuationFontCohort = (font) => JSON.stringify([font.kind, font.role, font.style, font.constraints]);
8
+ function continuationFonts(composed, options = {}, sourcePath = (path) => path) {
9
+ const scale = Math.min(composed.width, composed.height) / 720, samples = /* @__PURE__ */ new Map();
10
+ for (const item of composed.items) {
11
+ if (["title", "subtitle", "tag"].includes(item.field) || item.eyebrow) continue;
12
+ const kind = item.field === "items" || item.field === "bullets" ? "list" : item.field;
13
+ const constraints = JSON.stringify([item.composition.minFontSize ?? 16, item.composition.maxFontSize ?? null]);
14
+ const add = (size, part, role, style, run = {}, automatic = true) => {
15
+ if (!Number.isFinite(size) || size <= 0) return;
16
+ const family = record(style).sourceFontFamily ?? record(style).fontFamily;
17
+ const font = {
18
+ path: sourcePath(item.path),
19
+ part,
20
+ kind,
21
+ role,
22
+ size: size / scale,
23
+ automatic,
24
+ constraints,
25
+ style: JSON.stringify([family, record(style).fontWeight ?? 400, !!record(style).italic, record(style).lang ?? null, run.fontFamily ?? null, run.fontSize ?? null, run.bold ?? null, run.italic ?? null, !!run.superscript, !!run.subscript])
26
+ };
27
+ const key = continuationFontKey(font), previous = samples.get(key);
28
+ if (!previous || previous.size > font.size) samples.set(key, font);
29
+ };
30
+ const fit = (value, part, role, style, automatic = true) => {
31
+ if (!value) return;
32
+ if (Array.isArray(value.listEntries)) {
33
+ for (const entry of value.listEntries) {
34
+ fit(entry.text, `${part}.entry.${entry.index}`, role, style, automatic);
35
+ fit(entry.description, `${part}.description.${entry.index}`, "description", style, automatic);
36
+ }
37
+ } else if (Array.isArray(value.richLines)) {
38
+ for (const line of value.richLines) for (const fragment of line.fragments) {
39
+ if (fragment.kind !== void 0 || !fragment.text.trim()) continue;
40
+ const run = record(fragment.run);
41
+ add(fragment.fontSize, `${part}.run.${fragment.runIndex}`, role, fragment.style ?? style, run, automatic && run.fontSize === void 0 && !run.superscript && !run.subscript);
42
+ }
43
+ } else if (Number.isFinite(value.fontSize)) add(value.fontSize, part, role, style, {}, automatic);
44
+ };
45
+ const internal = item.quoteLayout ?? item.codeLayout ?? item.metricLayout ?? item.timelineLayout;
46
+ if (internal) for (const part of internal.parts) {
47
+ if ("visible" in part && part.visible === false) continue;
48
+ fit(part.fit, String(part.path).slice(item.path.length), part.role, part.style);
49
+ }
50
+ else if (item.field === "table") {
51
+ const table = layoutTable(item.value, item.box, { scale, minFontSize: item.composition.minFontSize, fontFamily: options.fontFamilies?.body, ...options.fontFamilies?.code ? { codeFontFamily: options.fontFamilies.code } : {}, textMeasurement: options.textMeasurement, path: item.path, presentation: options.presentation, ...item.tableGrowth ? { growth: item.tableGrowth } : {} });
52
+ for (const [rowIndex, row] of table.rows.entries()) for (const [columnIndex, cell] of row.cells.entries()) fit(cell.fit, `cell.${rowIndex}.${columnIndex}`, "cell", item.textStyle);
53
+ } else if (item.listColumns?.length) {
54
+ for (const column of item.listColumns) fit(column.text, "body", "body", item.textStyle);
55
+ } else fit(item.text, "body", "body", item.textStyle);
56
+ if (item.caption) fit(item.caption.fit, "caption", "caption", item.caption.style, false);
57
+ }
58
+ return [...samples.values()];
59
+ }
3
60
 
4
61
  // src/pagination.ts
5
62
  var OPFPaginationError = class extends Error {
@@ -94,16 +151,11 @@ function leafFor(path, field, value) {
94
151
  }
95
152
  return leaf;
96
153
  }
97
- function bodySizes(composed) {
98
- const scale = Math.min(composed.width, composed.height) / 720, sizes = /* @__PURE__ */ new Map();
99
- const add = (kind, size) => {
100
- if (size !== void 0 && Number.isFinite(size) && size > 0) sizes.set(kind, Math.max(sizes.get(kind) ?? 0, Math.round(size / scale * 100) / 100));
101
- };
102
- for (const item of composed.items) {
103
- if (headingFields.has(item.field) || item.eyebrow) continue;
104
- const layout = item.quoteLayout ?? item.metricLayout ?? item.timelineLayout;
105
- if (layout) add(item.field, Math.max(0, ...layout.parts.flatMap((part) => part.visible === false || !part.fit ? [] : [part.fit.fontSize])));
106
- else if (item.text && !item.codeLayout && (item.field === "text" || item.field === "items" || item.field === "bullets")) add(item.field === "text" ? "text" : "list", item.text.fontSize);
154
+ function bodySizes(composed, options = {}) {
155
+ const sizes = /* @__PURE__ */ new Map();
156
+ for (const font of continuationFonts(composed, options)) {
157
+ if (!font.automatic || !["text", "list", "quote", "metric", "timeline"].includes(font.kind)) continue;
158
+ sizes.set(font.kind, Math.max(sizes.get(font.kind) ?? 0, font.size));
107
159
  }
108
160
  return sizes;
109
161
  }
@@ -127,7 +179,7 @@ function paginateSlide(input, options = {}) {
127
179
  });
128
180
  };
129
181
  visit(result, rootMinimum);
130
- for (const [key, value] of Object.entries(result)) if (isRecord(value) && /^(top|middle|bottom|left|center|right)([+:]|$)/.test(key)) visit(value, rootMinimum);
182
+ for (const [key, value] of Object.entries(result)) if (isRecord(value) && /^(top|middle|bottom|start|center|end)([+:]|$)/.test(key)) visit(value, rootMinimum);
131
183
  return result;
132
184
  };
133
185
  if (minFontSize !== void 0) source = withReadability(source);
@@ -293,7 +345,7 @@ function paginateSlide(input, options = {}) {
293
345
  result.blocks = children;
294
346
  hasContent = true;
295
347
  }
296
- } else if (root && isRecord(value) && /^(top|middle|bottom|left|center|right)([+:]|$)/.test(key)) {
348
+ } else if (root && isRecord(value) && /^(top|middle|bottom|start|center|end)([+:]|$)/.test(key)) {
297
349
  const child = visit(value, childPath, outputPath);
298
350
  if (child) {
299
351
  result[key] = child;
@@ -313,17 +365,15 @@ function paginateSlide(input, options = {}) {
313
365
  return { slide, mappings, overlay };
314
366
  };
315
367
  const diagnosticsFor = (portions) => fit(geometry(project(portions, slides.length).slide, slides.length).diagnostics);
316
- let firstSizes;
317
368
  const kindOf = (field) => field === "items" || field === "bullets" ? "list" : field;
369
+ const drawnSizes = [];
318
370
  const finish = () => {
319
371
  if (!selected.size) return;
320
372
  if (slides.length >= maxSlides) throw new OPFPaginationError(`Pagination needs more than ${maxSlides} slides. No partial result was returned.`);
321
373
  const { slide, mappings, overlay } = project(selected, slides.length);
322
- const cap = firstSizes && Math.max(0, ...[...selected.values()].map((portion) => firstSizes.get(kindOf(portion.leaf.field)) ?? 0));
323
- if (cap) slide.composition = { ...slide.composition, maxFontSize: Math.min(Math.max(8, cap), 200, slide.composition?.maxFontSize ?? Infinity) };
324
374
  const drawn = geometry(slide, slides.length), issues = fit(drawn.diagnostics);
325
- if (!firstSizes) firstSizes = bodySizes(drawn);
326
375
  if (issues.length) throw new OPFPaginationError("A continuation page does not fit at its final page number. No partial result was returned.", issues);
376
+ drawnSizes.push({ kinds: new Set([...selected.values()].map((portion) => kindOf(portion.leaf.field))), sizes: bodySizes(drawn, composeOptions) });
327
377
  assignPageIds(slide, slides.length);
328
378
  assertValid({ ...deckContext(options.presentation), slides: [slide] }, { only: ["format"] });
329
379
  slides.push(slide);
@@ -331,6 +381,18 @@ function paginateSlide(input, options = {}) {
331
381
  pageConnectors.push(overlay);
332
382
  selected = /* @__PURE__ */ new Map();
333
383
  };
384
+ const shareSizes = () => {
385
+ const first = drawnSizes[0]?.sizes, shared = /* @__PURE__ */ new Map();
386
+ if (!first) return;
387
+ for (const page of drawnSizes.slice(1)) for (const [kind, size] of page.sizes) shared.set(kind, Math.min(shared.get(kind) ?? Infinity, size));
388
+ for (let index = 1; index < slides.length; index++) {
389
+ const slide = slides[index], cap = Math.max(0, ...[...drawnSizes[index].kinds].map((kind) => Math.max(first.get(kind) ?? 0, shared.get(kind) ?? 0)));
390
+ if (!cap) continue;
391
+ slide.composition = { ...slide.composition, maxFontSize: Math.min(Math.max(8, cap), 200, slide.composition?.maxFontSize ?? Infinity) };
392
+ const issues = fit(geometry(slide, index).diagnostics);
393
+ if (issues.length) throw new OPFPaginationError("A continuation page does not fit at its final page number. No partial result was returned.", issues);
394
+ }
395
+ };
334
396
  if (options.wholeBlocks) {
335
397
  const unitOf = /* @__PURE__ */ new Map();
336
398
  for (const [unit, indices] of (blockUnits(source)?.units ?? []).entries()) for (const index of indices) unitOf.set(index, unit);
@@ -345,13 +407,39 @@ function paginateSlide(input, options = {}) {
345
407
  previous = unit;
346
408
  }
347
409
  const portions = (from, to) => new Map(units.slice(from, to).flat().map((leaf) => [leaf.path, { leaf, start: 0, end: (leaf.boundaries ?? [0, 1]).at(-1), value: leaf.value }]));
348
- const issuesOf = (from, to, pageIndex) => fit(geometry(project(portions(from, to), pageIndex).slide, pageIndex).diagnostics);
410
+ const originalFonts = continuationFonts(initial, composeOptions);
411
+ const cohorts = /* @__PURE__ */ new Map();
412
+ for (const font of originalFonts) if (font.automatic) cohorts.set(continuationFontCohort(font), Math.max(cohorts.get(continuationFontCohort(font)) ?? 0, font.size));
413
+ const retained = originalFonts.map((font) => ({ ...font, size: font.automatic ? cohorts.get(continuationFontCohort(font)) : font.size }));
414
+ const inspect = (from, to, pageIndex, caps) => {
415
+ const selected2 = portions(from, to), projection = project(selected2, pageIndex);
416
+ const cap = caps && Math.max(0, ...[...selected2.values()].map((portion) => caps.get(kindOf(portion.leaf.field)) ?? 0));
417
+ if (cap) projection.slide.composition = { ...projection.slide.composition, maxFontSize: Math.min(Math.max(8, cap), 200, projection.slide.composition?.maxFontSize ?? Infinity) };
418
+ const drawn = geometry(projection.slide, pageIndex), issues = fit(drawn.diagnostics);
419
+ const mappings = projection.mappings;
420
+ const composedPath = (output) => sourceBase + output.slice(output.indexOf(".", 7));
421
+ const sourcePath = (path) => {
422
+ const mapping = mappings.find((entry) => {
423
+ const output = composedPath(entry.outputPath);
424
+ return path === output || path.startsWith(output + ".");
425
+ });
426
+ return mapping ? mapping.sourcePath + path.slice(composedPath(mapping.outputPath).length) : path;
427
+ };
428
+ const fonts2 = new Map(continuationFonts(drawn, composeOptions, sourcePath).map((font) => [continuationFontKey(font), font.size]));
429
+ for (const font of retained) if (mappings.some((mapping) => font.path === mapping.sourcePath) && (fonts2.get(continuationFontKey(font)) ?? 0) < font.size - 1e-6) {
430
+ issues.push({ code: "text-overflow", path: font.path, message: `Continuation would reduce retained ${font.role} text below ${font.size} reference pixels. Use more whole-block pages or change the authored constraint.` });
431
+ }
432
+ return { drawn, issues };
433
+ };
434
+ let planningCaps;
435
+ const issuesOf = (from, to, pageIndex) => inspect(from, to, pageIndex, planningCaps).issues;
349
436
  const greedy = [];
350
437
  for (let start = 0; start < units.length; ) {
351
438
  const alone = issuesOf(start, start + 1, greedy.length);
352
439
  if (alone.length) throw new OPFPaginationError(`The block at ${units[start][0].path} cannot fit on an otherwise empty slide.`, alone);
353
440
  let end = start + 1;
354
441
  while (end < units.length && !issuesOf(start, end + 1, greedy.length).length) end++;
442
+ if (!planningCaps) planningCaps = bodySizes(inspect(start, end, greedy.length).drawn, composeOptions);
355
443
  greedy.push([start, end]);
356
444
  start = end;
357
445
  }
@@ -360,11 +448,18 @@ function paginateSlide(input, options = {}) {
360
448
  const start = page * base + Math.min(page, extra);
361
449
  return [start, start + base + (page < extra ? 1 : 0)];
362
450
  });
363
- const ranges = balanced.every(([from, to], page) => !issuesOf(from, to, page).length) ? balanced : greedy;
451
+ planningCaps = void 0;
452
+ const balancedFits = balanced.every(([from, to], page) => {
453
+ const candidate = inspect(from, to, page, planningCaps);
454
+ if (!planningCaps) planningCaps = bodySizes(candidate.drawn, composeOptions);
455
+ return !candidate.issues.length;
456
+ });
457
+ const ranges = balancedFits ? balanced : greedy;
364
458
  for (const [from, to] of ranges) {
365
459
  selected = portions(from, to);
366
460
  finish();
367
461
  }
462
+ shareSizes();
368
463
  splitDiagnostics();
369
464
  return { slides, pages };
370
465
  }
@@ -415,6 +510,7 @@ function paginateSlide(input, options = {}) {
415
510
  }
416
511
  finish();
417
512
  if (!slides.length) throw new OPFPaginationError("No body content can be paginated.", initial.diagnostics);
513
+ shareSizes();
418
514
  splitDiagnostics();
419
515
  return { slides, pages };
420
516
  }
@@ -422,7 +518,7 @@ function paginate(input, options = {}) {
422
518
  const { presentation, pages } = paginateSlides(input, options, "paginate", options.maxSlides ?? 100, (slide, slideOptions) => paginateSlide(slide, slideOptions));
423
519
  return { presentation, pages, layout: options.fonts ? "measured" : "estimated" };
424
520
  }
425
- var promotedKey = /^(top|middle|bottom|left|center|right)([+:]|$)/;
521
+ var promotedKey = /^(top|middle|bottom|start|center|end)([+:]|$)/;
426
522
  function blockUnits(slide) {
427
523
  if (!isRecord(slide) || !Array.isArray(slide.blocks) || slide.blocks.length < 2) return void 0;
428
524
  if (Object.keys(slide).some((key) => contentFields.has(key) || promotedKey.test(key))) return void 0;
@@ -0,0 +1,7 @@
1
+ // src/diagram-limits.ts
2
+ var DIAGRAM_SOURCE_LIMIT = 2e4;
3
+ var DIAGRAM_MAX_EDGES = 500;
4
+ var DIAGRAM_MAX_NESTING = 16;
5
+ var DIAGRAM_TRANSLATED_LIMIT = DIAGRAM_SOURCE_LIMIT * 16;
6
+
7
+ export { DIAGRAM_MAX_EDGES, DIAGRAM_MAX_NESTING, DIAGRAM_SOURCE_LIMIT, DIAGRAM_TRANSLATED_LIMIT };