@openpresentation/opf 0.32.1 → 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 (105) hide show
  1. package/README.md +9 -0
  2. package/dist/browser.js +22 -21
  3. package/dist/catalog-refs-CoIrOdAw.d.ts +937 -0
  4. package/dist/{catalog-schemas-LdqOPebq.d.ts → catalog-schemas-FjLRPtjB.d.ts} +10 -4
  5. package/dist/{chart-data-oIZQlFGi.d.ts → chart-data-B_k-WTex.d.ts} +7 -4
  6. package/dist/{chunk-PB7ME64J.js → chunk-244OPLAV.js} +1 -1
  7. package/dist/{chunk-IT7FQKED.js → chunk-2HX4BGAS.js} +6 -6
  8. package/dist/{chunk-2E6CDYL2.js → chunk-36DLVJGW.js} +19 -16
  9. package/dist/{chunk-XQO2CT6Q.js → chunk-3THGTDL2.js} +2 -2
  10. package/dist/{chunk-CLRYHWQN.js → chunk-42JBXJKW.js} +187 -25
  11. package/dist/chunk-BLCDUM7B.js +7 -0
  12. package/dist/{chunk-NVAJASOD.js → chunk-CJVKOJ6B.js} +10195 -2036
  13. package/dist/{chunk-XFHXQCXL.js → chunk-DQ7QYOUV.js} +99 -13
  14. package/dist/{chunk-NEJ32O7X.js → chunk-F6BXO4AI.js} +1 -1
  15. package/dist/{chunk-OXLA4HXQ.js → chunk-FAXO3SUE.js} +1196 -313
  16. package/dist/{chunk-J63CIRIV.js → chunk-FIQMAIZV.js} +4 -4
  17. package/dist/{chunk-PJSPHHRK.js → chunk-FK5XG742.js} +3 -16
  18. package/dist/{chunk-HKUV7NEN.js → chunk-HHVQ2SDT.js} +1 -1
  19. package/dist/{chunk-SZFO3MAJ.js → chunk-HUGVYHZ2.js} +4 -4
  20. package/dist/{chunk-LEF4X4KI.js → chunk-LCT5ZV3Q.js} +2400 -222
  21. package/dist/chunk-NLJFNCZ4.js +1560 -0
  22. package/dist/{chunk-GM7WFPGG.js → chunk-PRXZD2II.js} +6 -1
  23. package/dist/{chunk-YFJIIIOL.js → chunk-QGJVOPLG.js} +3 -3
  24. package/dist/{chunk-F7DN33UL.js → chunk-QGTJF7HV.js} +16 -14
  25. package/dist/{chunk-ONVFUVQ5.js → chunk-RUV7CCE6.js} +136 -31
  26. package/dist/{chunk-SW676APJ.js → chunk-U7TYSPYM.js} +2 -2
  27. package/dist/chunk-UJZN2ZH6.js +1 -0
  28. package/dist/chunk-VDZXNNZF.js +221 -0
  29. package/dist/{chunk-UJSAR6GF.js → chunk-W4DYDRV2.js} +21 -0
  30. package/dist/chunk-WCPDN7AY.js +642 -0
  31. package/dist/{chunk-BBVW5ZC2.js → chunk-WMFT5R7I.js} +2 -2
  32. package/dist/{chunk-AQEAZDL2.js → chunk-XJUMFH33.js} +2 -1
  33. package/dist/{composition-Ds6WHyO7.d.ts → composition-CvtvgBDE.d.ts} +2783 -873
  34. package/dist/composition.d.ts +4 -3
  35. package/dist/composition.js +3 -2
  36. package/dist/{conversion-CdzrTxib.d.ts → conversion-B_5AKTYQ.d.ts} +39 -10
  37. package/dist/conversion-CMBGOTAC.js +25 -0
  38. package/dist/convert.d.ts +5 -4
  39. package/dist/convert.js +17 -13
  40. package/dist/data.d.ts +2 -2
  41. package/dist/data.js +4 -3
  42. package/dist/{deck-report-CKDNQ2t4.d.ts → deck-report-BVlQZ42f.d.ts} +3 -3
  43. package/dist/deck.d.ts +7 -6
  44. package/dist/deck.js +13 -12
  45. package/dist/diagram-engine-eager.js +6 -2
  46. package/dist/diagram-engine-lazy.js +14 -1
  47. package/dist/diagram-plantuml-XRZ6VAOL.js +3 -0
  48. package/dist/diff.js +6 -5
  49. package/dist/docs.js +88 -52
  50. package/dist/examples.js +28745 -18393
  51. package/dist/font-policy.js +2 -2
  52. package/dist/format.js +3 -3
  53. package/dist/ids.js +6 -5
  54. package/dist/index.d.ts +19 -16
  55. package/dist/index.js +37 -26
  56. package/dist/markdown.d.ts +3 -2
  57. package/dist/markdown.js +10 -9
  58. package/dist/node-engine.d.ts +44 -11
  59. package/dist/node-engine.js +47 -28
  60. package/dist/{pagination-DRZ_JNFY.d.ts → pagination-CZQQYk7L.d.ts} +22 -4
  61. package/dist/pagination.d.ts +5 -4
  62. package/dist/pagination.js +6 -5
  63. package/dist/patch.js +5 -4
  64. package/dist/precompiled.js +3 -3
  65. package/dist/{presentation-DnD7mfmf.d.ts → presentation-s9262acV.d.ts} +1172 -208
  66. package/dist/repo-readme.js +2 -2
  67. package/dist/schema-engine-ajv.js +2 -2
  68. package/dist/schema-engine-precompiled.js +3 -3
  69. package/dist/schema.d.ts +3 -3
  70. package/dist/schema.js +5 -4
  71. package/dist/schemas.d.ts +56 -4
  72. package/dist/schemas.js +2 -2
  73. package/dist/shape-catalog.d.ts +98 -0
  74. package/dist/shape-catalog.js +302 -0
  75. package/dist/shape-engine-eager.js +9 -0
  76. package/dist/shape-engine-lazy.js +12 -0
  77. package/dist/shape-engine-module-N74FCHGY.js +3 -0
  78. package/dist/shape-geometry.d.ts +126 -0
  79. package/dist/shape-geometry.js +2 -0
  80. package/dist/source.d.ts +10 -5
  81. package/dist/source.js +12 -11
  82. package/dist/spec/README.md +1 -1
  83. package/dist/spec/reference/engine-vocabularies.json +135 -0
  84. package/dist/spec/reference/font-policy.json +3 -16
  85. package/dist/spec/reference/preset-geometry.json +10699 -0
  86. package/dist/spec/reference/preset-geometry.schema.json +126 -0
  87. package/dist/spec/schemas/catalog-index.schema.json +1 -0
  88. package/dist/spec/schemas/chart-type.schema.json +4 -4
  89. package/dist/spec/schemas/icon-set.schema.json +75 -0
  90. package/dist/spec/schemas/layout.schema.json +82 -23
  91. package/dist/spec/schemas/opf.schema.json +1616 -296
  92. package/dist/spec/schemas/theme.schema.json +11 -5
  93. package/dist/spec-files.d.ts +1 -1
  94. package/dist/spec-files.js +2 -2
  95. package/dist/symbol-font-encodings.js +1 -1
  96. package/dist/types.d.ts +83 -71
  97. package/dist/{validation-types-DxyYPebs.d.ts → validation-types-CYbsUuZ9.d.ts} +8 -5
  98. package/dist/validator.d.ts +35 -7
  99. package/dist/validator.js +5 -4
  100. package/dist/yaml.d.ts +3 -2
  101. package/dist/yaml.js +9 -8
  102. package/package.json +22 -6
  103. package/dist/catalog-refs-kAefsZWT.d.ts +0 -129
  104. package/dist/chunk-DGS47ONG.js +0 -1
  105. package/dist/conversion-5FUDQPED.js +0 -24
@@ -1,4 +1,4 @@
1
- import { a as CatalogKind } from './catalog-refs-kAefsZWT.js';
1
+ import { a as CatalogKind } from './catalog-refs-CoIrOdAw.js';
2
2
  import { SchemaName } from './schemas.js';
3
3
 
4
4
  /**
@@ -11,10 +11,16 @@ declare const CATALOG_SCHEMA = 4;
11
11
  /** Kinds of catalog display metadata: published by catalogs for pickers, never referenced by documents. */
12
12
  declare const catalogDisplayKinds: readonly ["chartTypes", "languages", "socialPlatforms"];
13
13
  type CatalogDisplayKind = (typeof catalogDisplayKinds)[number];
14
- /** Every kind of record a catalog publishes: the content kinds documents reference, and the display kinds. */
15
- type CatalogRecordKind = CatalogKind | CatalogDisplayKind;
14
+ /**
15
+ * LH-14: icon sets, the records an `icon` names as `<set>:<name>`. They resolve by their own rule (icons.ts), not as a content
16
+ * reference, and a registered catalog may give a set as a function that loads it.
17
+ */
18
+ declare const catalogIconKinds: readonly ["iconSets"];
19
+ type CatalogIconKind = (typeof catalogIconKinds)[number];
20
+ /** Every kind of record a catalog publishes: the content kinds documents reference, the display kinds and the icon sets. */
21
+ type CatalogRecordKind = CatalogKind | CatalogDisplayKind | CatalogIconKind;
16
22
  /** The companion schema each catalog record kind validates against. */
17
23
  declare const catalogSchemaNames: Readonly<Record<CatalogRecordKind, SchemaName>>;
18
24
 
19
- export { CATALOG_SCHEMA as a, catalogDisplayKinds as c, catalogSchemaNames as d };
25
+ export { CATALOG_SCHEMA as a, catalogDisplayKinds as c, catalogIconKinds as d, catalogSchemaNames as e };
20
26
  export type { CatalogRecordKind as C, CatalogDisplayKind as b };
@@ -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-NVAJASOD.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-HKUV7NEN.js';
1
+ import { sortPresentationKeys } from './chunk-HHVQ2SDT.js';
2
2
  import { NOT_CHECKED } from './chunk-RYZPBJLB.js';
3
- import { Ctx, describeYamlErrors } from './chunk-BBVW5ZC2.js';
4
- import { same } from './chunk-XQO2CT6Q.js';
5
- import { validate } from './chunk-OXLA4HXQ.js';
6
- import { presentation } from './chunk-LEF4X4KI.js';
7
- import { checkCatalogsOption } from './chunk-NVAJASOD.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-NEJ32O7X.js';
2
- import { Ctx, splitLines, lineRange, readYamlMapping, readCsv, DECIMAL } from './chunk-BBVW5ZC2.js';
3
- import { runText, isRecord, FORMATTING } from './chunk-XQO2CT6Q.js';
4
- import { METRIC_KEYS, nearest, BLOCK_AS_VALUES, SLIDE_OPTION_KEYS, BLOCK_OPTION_KEYS } from './chunk-OXLA4HXQ.js';
5
- import { PROMOTED_REGION_KEY } from './chunk-NVAJASOD.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-OXLA4HXQ.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-OXLA4HXQ.js';
2
- import { composeSlide, resolveSlideVariables, OPFCompositionError, checkCatalogsOption, usesSlideBuiltin, codeHighlightSlice, tableRowBoundaries, visitContentPayloads, regionAccepts, slideTokenSpans, sliceNumberedItems } from './chunk-NVAJASOD.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 {
@@ -20,6 +77,9 @@ var slideIds = (slide) => {
20
77
  visitContentPayloads(slide, "", (payload) => {
21
78
  if (typeof payload.id === "string") ids.push(payload.id);
22
79
  });
80
+ if (Array.isArray(slide.shapes)) {
81
+ for (const entry of slide.shapes) if (isRecord(entry) && typeof entry.id === "string") ids.push(entry.id);
82
+ }
23
83
  return ids;
24
84
  };
25
85
  var textOf = (value) => typeof value === "string" ? value : Array.isArray(value) ? value.map(textOf).join("") : value?.text ?? "";
@@ -91,16 +151,11 @@ function leafFor(path, field, value) {
91
151
  }
92
152
  return leaf;
93
153
  }
94
- function bodySizes(composed) {
95
- const scale = Math.min(composed.width, composed.height) / 720, sizes = /* @__PURE__ */ new Map();
96
- const add = (kind, size) => {
97
- if (size !== void 0 && Number.isFinite(size) && size > 0) sizes.set(kind, Math.max(sizes.get(kind) ?? 0, Math.round(size / scale * 100) / 100));
98
- };
99
- for (const item of composed.items) {
100
- if (headingFields.has(item.field) || item.eyebrow) continue;
101
- const layout = item.quoteLayout ?? item.metricLayout ?? item.timelineLayout;
102
- if (layout) add(item.field, Math.max(0, ...layout.parts.flatMap((part) => part.visible === false || !part.fit ? [] : [part.fit.fontSize])));
103
- 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));
104
159
  }
105
160
  return sizes;
106
161
  }
@@ -124,7 +179,7 @@ function paginateSlide(input, options = {}) {
124
179
  });
125
180
  };
126
181
  visit(result, rootMinimum);
127
- 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);
128
183
  return result;
129
184
  };
130
185
  if (minFontSize !== void 0) source = withReadability(source);
@@ -202,11 +257,66 @@ function paginateSlide(input, options = {}) {
202
257
  return id;
203
258
  };
204
259
  const assignPageIds = (slide, pageIndex) => {
260
+ const renamed = /* @__PURE__ */ new Map();
205
261
  const assign = (node) => {
206
- if (typeof node.id === "string") node.id = pageId(node.id, pageIndex);
262
+ if (typeof node.id === "string") {
263
+ const id = pageId(node.id, pageIndex);
264
+ if (id !== node.id) renamed.set(node.id, id);
265
+ node.id = id;
266
+ }
207
267
  };
208
268
  assign(slide);
209
269
  visitContentPayloads(slide, "", assign);
270
+ if (!Array.isArray(slide.shapes)) return;
271
+ for (const entry of slide.shapes) if (isRecord(entry)) assign(entry);
272
+ const follow = (id) => typeof id === "string" ? renamed.get(id) ?? id : id;
273
+ for (const entry of slide.shapes) {
274
+ if (!isRecord(entry)) continue;
275
+ if (isRecord(entry.at)) entry.at = { ...entry.at, block: follow(entry.at.block) };
276
+ if (isRecord(entry.connector)) entry.connector = { ...entry.connector, from: follow(entry.connector.from), to: follow(entry.connector.to) };
277
+ }
278
+ };
279
+ const blockIds = slideBlockIds(source, sourceBase);
280
+ const pageOverlay = (mappings) => {
281
+ if (!Array.isArray(source.shapes)) return { connectors: [], starts: [] };
282
+ const onPage = (id) => {
283
+ const path = typeof id === "string" ? blockIds.get(id) : void 0;
284
+ return path !== void 0 && mappings.some((mapping) => mapping.sourcePath.startsWith(`${path}.`));
285
+ };
286
+ const kept = /* @__PURE__ */ new Set(), overlayIds = /* @__PURE__ */ new Set();
287
+ source.shapes.forEach((entry, index) => {
288
+ if (!isRecord(entry) || isOverlayConnector(entry)) return;
289
+ if (entry.at !== void 0 && !onPage(isRecord(entry.at) ? entry.at.block : void 0)) return;
290
+ kept.add(index);
291
+ if (typeof entry.id === "string") overlayIds.add(entry.id);
292
+ });
293
+ const present = (id) => onPage(id) || typeof id === "string" && overlayIds.has(id);
294
+ const connectors = [], starts = [];
295
+ source.shapes.forEach((entry, index) => {
296
+ if (!isRecord(entry) || !isOverlayConnector(entry)) return;
297
+ const connector = isRecord(entry.connector) ? entry.connector : {};
298
+ const from = present(connector.from);
299
+ if (from) starts.push(index);
300
+ if (from && present(connector.to)) {
301
+ kept.add(index);
302
+ connectors.push(index);
303
+ }
304
+ });
305
+ const shapes = source.shapes.filter((_, index) => kept.has(index)).map((entry) => clone(entry));
306
+ return { ...shapes.length ? { shapes } : {}, connectors, starts };
307
+ };
308
+ const pageConnectors = [];
309
+ const splitDiagnostics = () => {
310
+ if (!Array.isArray(source.shapes)) return;
311
+ const drawn = new Set(pageConnectors.flatMap((page) => page.connectors));
312
+ source.shapes.forEach((entry, index) => {
313
+ if (!isRecord(entry) || !isOverlayConnector(entry) || drawn.has(index)) return;
314
+ const page = pageConnectors.findIndex((entry2) => entry2.starts.includes(index));
315
+ if (page < 0) return;
316
+ const connector = isRecord(entry.connector) ? entry.connector : {};
317
+ const target = pages[page];
318
+ target.diagnostics = [...target.diagnostics ?? [], { code: "connector-split", path: `${sourceBase}.shapes.${index}`, message: `The connector from '${String(connector.from)}' to '${String(connector.to)}' is not drawn: its ends landed on different pages. Keep both of them on one page, or join shapes of one page.` }];
319
+ });
210
320
  };
211
321
  const project = (portions, pageIndex) => {
212
322
  const mappings = [];
@@ -235,38 +345,54 @@ function paginateSlide(input, options = {}) {
235
345
  result.blocks = children;
236
346
  hasContent = true;
237
347
  }
238
- } 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)) {
239
349
  const child = visit(value, childPath, outputPath);
240
350
  if (child) {
241
351
  result[key] = child;
242
352
  hasContent = true;
243
353
  }
354
+ } else if (key === "text" && isShapeBlock(node)) {
355
+ if (portions.has(`${path}.shape`) || portions.has(`${path}.path`)) result[key] = clone(value);
244
356
  } else if (!contentFields.has(key)) result[key] = clone(value);
245
357
  }
246
358
  return root || hasContent ? result : void 0;
247
359
  };
248
360
  const slide = visit(source, sourceBase, `slides.${sourceIndex + pageIndex}`, true);
249
361
  if (pageIndex > 0) delete slide.notes;
250
- return { slide, mappings };
362
+ const overlay = pageOverlay(mappings);
363
+ delete slide.shapes;
364
+ if (overlay.shapes) slide.shapes = overlay.shapes;
365
+ return { slide, mappings, overlay };
251
366
  };
252
367
  const diagnosticsFor = (portions) => fit(geometry(project(portions, slides.length).slide, slides.length).diagnostics);
253
- let firstSizes;
254
368
  const kindOf = (field) => field === "items" || field === "bullets" ? "list" : field;
369
+ const drawnSizes = [];
255
370
  const finish = () => {
256
371
  if (!selected.size) return;
257
372
  if (slides.length >= maxSlides) throw new OPFPaginationError(`Pagination needs more than ${maxSlides} slides. No partial result was returned.`);
258
- const { slide, mappings } = project(selected, slides.length);
259
- const cap = firstSizes && Math.max(0, ...[...selected.values()].map((portion) => firstSizes.get(kindOf(portion.leaf.field)) ?? 0));
260
- if (cap) slide.composition = { ...slide.composition, maxFontSize: Math.min(Math.max(8, cap), 200, slide.composition?.maxFontSize ?? Infinity) };
373
+ const { slide, mappings, overlay } = project(selected, slides.length);
261
374
  const drawn = geometry(slide, slides.length), issues = fit(drawn.diagnostics);
262
- if (!firstSizes) firstSizes = bodySizes(drawn);
263
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) });
264
377
  assignPageIds(slide, slides.length);
265
378
  assertValid({ ...deckContext(options.presentation), slides: [slide] }, { only: ["format"] });
266
379
  slides.push(slide);
267
380
  pages.push({ slideIndex: sourceIndex + slides.length - 1, mappings, ...initial.furniture ? { repeatedMappings: repeatedMappings(slides.length - 1) } : {} });
381
+ pageConnectors.push(overlay);
268
382
  selected = /* @__PURE__ */ new Map();
269
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
+ };
270
396
  if (options.wholeBlocks) {
271
397
  const unitOf = /* @__PURE__ */ new Map();
272
398
  for (const [unit, indices] of (blockUnits(source)?.units ?? []).entries()) for (const index of indices) unitOf.set(index, unit);
@@ -281,13 +407,39 @@ function paginateSlide(input, options = {}) {
281
407
  previous = unit;
282
408
  }
283
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 }]));
284
- 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;
285
436
  const greedy = [];
286
437
  for (let start = 0; start < units.length; ) {
287
438
  const alone = issuesOf(start, start + 1, greedy.length);
288
439
  if (alone.length) throw new OPFPaginationError(`The block at ${units[start][0].path} cannot fit on an otherwise empty slide.`, alone);
289
440
  let end = start + 1;
290
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);
291
443
  greedy.push([start, end]);
292
444
  start = end;
293
445
  }
@@ -296,11 +448,19 @@ function paginateSlide(input, options = {}) {
296
448
  const start = page * base + Math.min(page, extra);
297
449
  return [start, start + base + (page < extra ? 1 : 0)];
298
450
  });
299
- 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;
300
458
  for (const [from, to] of ranges) {
301
459
  selected = portions(from, to);
302
460
  finish();
303
461
  }
462
+ shareSizes();
463
+ splitDiagnostics();
304
464
  return { slides, pages };
305
465
  }
306
466
  for (const leaf of leaves) {
@@ -350,13 +510,15 @@ function paginateSlide(input, options = {}) {
350
510
  }
351
511
  finish();
352
512
  if (!slides.length) throw new OPFPaginationError("No body content can be paginated.", initial.diagnostics);
513
+ shareSizes();
514
+ splitDiagnostics();
353
515
  return { slides, pages };
354
516
  }
355
517
  function paginate(input, options = {}) {
356
518
  const { presentation, pages } = paginateSlides(input, options, "paginate", options.maxSlides ?? 100, (slide, slideOptions) => paginateSlide(slide, slideOptions));
357
519
  return { presentation, pages, layout: options.fonts ? "measured" : "estimated" };
358
520
  }
359
- var promotedKey = /^(top|middle|bottom|left|center|right)([+:]|$)/;
521
+ var promotedKey = /^(top|middle|bottom|start|center|end)([+:]|$)/;
360
522
  function blockUnits(slide) {
361
523
  if (!isRecord(slide) || !Array.isArray(slide.blocks) || slide.blocks.length < 2) return void 0;
362
524
  if (Object.keys(slide).some((key) => contentFields.has(key) || promotedKey.test(key))) return void 0;
@@ -445,7 +607,7 @@ function paginateSlides(input, options, name, maxSlides, split) {
445
607
  if (result2.slides.length > 1) splits2.push({ sourceSlideIndex: index, outputStart, count: result2.slides.length });
446
608
  result2.pages.forEach((page, pageIndex) => {
447
609
  const remap = (mapping) => ({ ...mapping, outputPath: mapping.outputPath.replace(/^slides\.\d+/, `slides.${outputStart + pageIndex}`) });
448
- pages2.push({ sourceSlideIndex: index, slideIndex: outputStart + pageIndex, mappings: page.mappings.map(remap), ...page.repeatedMappings ? { repeatedMappings: page.repeatedMappings.map(remap) } : {} });
610
+ pages2.push({ sourceSlideIndex: index, slideIndex: outputStart + pageIndex, mappings: page.mappings.map(remap), ...page.repeatedMappings ? { repeatedMappings: page.repeatedMappings.map(remap) } : {}, ...page.diagnostics ? { diagnostics: page.diagnostics } : {} });
449
611
  });
450
612
  output2.push(...result2.slides);
451
613
  reservedIds.push(...result2.slides.flatMap((slide2) => slideIds(slide2)));
@@ -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 };