@openpresentation/opf 0.33.0 → 0.34.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.
- package/README.md +3 -3
- package/dist/browser.js +20 -19
- package/dist/catalog-refs-CoIrOdAw.d.ts +937 -0
- package/dist/{catalog-schemas-CQTM-G8p.d.ts → catalog-schemas-FjLRPtjB.d.ts} +1 -1
- package/dist/{chart-data-oIZQlFGi.d.ts → chart-data-B_k-WTex.d.ts} +7 -4
- package/dist/{chunk-XIOC6N5P.js → chunk-244OPLAV.js} +1 -1
- package/dist/{chunk-KVHNDHVS.js → chunk-2B6GLT2O.js} +1 -1
- package/dist/{chunk-VMBLNCX2.js → chunk-6PMXVP5G.js} +117 -30
- package/dist/{chunk-BI4ERFAA.js → chunk-AAWHOCXS.js} +48 -13
- package/dist/{chunk-QD6DPS7X.js → chunk-ABA2D6X5.js} +2 -2
- package/dist/{chunk-UK3J6FSU.js → chunk-AEHDXNZX.js} +862 -269
- package/dist/{chunk-DAS75LGR.js → chunk-AGYPRTEC.js} +4 -4
- package/dist/chunk-BLCDUM7B.js +7 -0
- package/dist/{chunk-OPVJLL7H.js → chunk-CJVKOJ6B.js} +11841 -8687
- package/dist/{chunk-Y557TYML.js → chunk-CQXBGZQP.js} +19 -16
- package/dist/{chunk-VKEYV3ZK.js → chunk-FCSYIBVR.js} +2 -2
- package/dist/{chunk-PJSPHHRK.js → chunk-FK5XG742.js} +3 -16
- package/dist/{chunk-R6C6BQOG.js → chunk-HHVQ2SDT.js} +1 -1
- package/dist/{chunk-ABWEUXLV.js → chunk-L3MCLD3X.js} +117 -21
- package/dist/{chunk-QF5RSRXU.js → chunk-LCT5ZV3Q.js} +750 -199
- package/dist/{chunk-E7WQHMCL.js → chunk-MAFJ5O2D.js} +16 -14
- package/dist/{chunk-XANW7MB7.js → chunk-MUILZGRY.js} +4 -4
- package/dist/chunk-NLJFNCZ4.js +1560 -0
- package/dist/{chunk-VSBZC2PR.js → chunk-SR6T4LKI.js} +3 -3
- package/dist/chunk-UJZN2ZH6.js +1 -0
- package/dist/{chunk-IJXKVM4W.js → chunk-VDZXNNZF.js} +1 -1
- package/dist/{chunk-YYT6N7AI.js → chunk-WCPDN7AY.js} +1 -1
- package/dist/{chunk-S5QRGMUQ.js → chunk-X72WPTST.js} +6 -6
- package/dist/{chunk-INIMUBSE.js → chunk-XJUMFH33.js} +1 -1
- package/dist/{chunk-YS333HLA.js → chunk-XLSWZSQS.js} +2 -2
- package/dist/{composition-zMiIgzip.d.ts → composition-CvtvgBDE.d.ts} +1360 -1531
- package/dist/composition.d.ts +3 -3
- package/dist/composition.js +2 -1
- package/dist/conversion-CSQ5EHD2.js +25 -0
- package/dist/{conversion-mNth9XKm.d.ts → conversion-CyNRlWGw.d.ts} +25 -7
- package/dist/convert.d.ts +4 -4
- package/dist/convert.js +15 -11
- package/dist/data.d.ts +2 -2
- package/dist/data.js +3 -2
- package/dist/{deck-report-BSlRiR0_.d.ts → deck-report-BVlQZ42f.d.ts} +3 -3
- package/dist/deck.d.ts +6 -6
- package/dist/deck.js +12 -11
- package/dist/diagram-engine-eager.js +5 -1
- package/dist/diagram-engine-lazy.js +13 -0
- package/dist/diagram-plantuml-XRZ6VAOL.js +3 -0
- package/dist/diff.js +5 -4
- package/dist/docs.js +65 -53
- package/dist/examples.js +4070 -1083
- package/dist/font-policy.js +1 -1
- package/dist/format.js +2 -2
- package/dist/ids.js +5 -4
- package/dist/index.d.ts +18 -16
- package/dist/index.js +35 -24
- package/dist/markdown.d.ts +2 -2
- package/dist/markdown.js +9 -8
- package/dist/node-engine.d.ts +43 -11
- package/dist/node-engine.js +45 -26
- package/dist/{pagination-CYzNMazO.d.ts → pagination-CZQQYk7L.d.ts} +4 -3
- package/dist/pagination.d.ts +4 -4
- package/dist/pagination.js +5 -4
- package/dist/patch.js +4 -3
- package/dist/precompiled.js +2 -2
- package/dist/{presentation-CXhfpB_z.d.ts → presentation-s9262acV.d.ts} +357 -230
- package/dist/repo-readme.js +1 -1
- package/dist/schema-engine-ajv.js +1 -1
- package/dist/schema-engine-precompiled.js +2 -2
- package/dist/schema.d.ts +3 -3
- package/dist/schema.js +4 -3
- package/dist/schemas.d.ts +16 -0
- package/dist/schemas.js +1 -1
- package/dist/shape-engine-eager.js +2 -2
- package/dist/shape-engine-lazy.js +1 -1
- package/dist/{shape-engine-module-BK7JNEUV.js → shape-engine-module-N74FCHGY.js} +2 -2
- package/dist/shape-geometry.js +1 -1
- package/dist/source.d.ts +10 -5
- package/dist/source.js +11 -10
- package/dist/spec/reference/engine-vocabularies.json +135 -0
- package/dist/spec/reference/font-policy.json +3 -16
- package/dist/spec/reference/preset-geometry.json +3 -3
- package/dist/spec/schemas/icon-set.schema.json +1 -1
- package/dist/spec/schemas/layout.schema.json +71 -25
- package/dist/spec/schemas/opf.schema.json +540 -168
- package/dist/spec/schemas/theme.schema.json +11 -5
- package/dist/types.d.ts +81 -73
- package/dist/{validation-types-COwTel3H.d.ts → validation-types-CYbsUuZ9.d.ts} +8 -5
- package/dist/validator.d.ts +34 -7
- package/dist/validator.js +4 -3
- package/dist/yaml.d.ts +2 -2
- package/dist/yaml.js +8 -7
- package/package.json +6 -6
- package/dist/catalog-refs-B_0_vZg0.d.ts +0 -134
- package/dist/chunk-ZXOIGUHX.js +0 -1
- package/dist/conversion-POHRAMSN.js +0 -24
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { parseQuoteLines, levelsFromIndents, parseCodeFence, splitWhen } from './chunk-
|
|
2
|
-
import { Ctx, splitLines, lineRange, readYamlMapping, readCsv, DECIMAL } from './chunk-
|
|
3
|
-
import { runText, isRecord, FORMATTING } from './chunk-
|
|
4
|
-
import { METRIC_KEYS, nearest, BLOCK_AS_VALUES, SLIDE_OPTION_KEYS, BLOCK_OPTION_KEYS } from './chunk-
|
|
5
|
-
import { PROMOTED_REGION_KEY } from './chunk-
|
|
1
|
+
import { parseQuoteLines, levelsFromIndents, parseCodeFence, splitWhen } from './chunk-2B6GLT2O.js';
|
|
2
|
+
import { Ctx, splitLines, lineRange, readYamlMapping, readCsv, DECIMAL } from './chunk-ABA2D6X5.js';
|
|
3
|
+
import { runText, isRecord, FORMATTING } from './chunk-FCSYIBVR.js';
|
|
4
|
+
import { METRIC_KEYS, nearest, BLOCK_AS_VALUES, SLIDE_OPTION_KEYS, BLOCK_OPTION_KEYS } from './chunk-AEHDXNZX.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: "
|
|
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.
|
|
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.
|
|
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:
|
|
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,
|
|
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)}.`,
|
|
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
|
-
|
|
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-
|
|
1
|
+
import { validate } from './chunk-AEHDXNZX.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", "
|
|
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 ?? "";
|
|
@@ -3075,14 +3075,7 @@ var fontPolicySource = {
|
|
|
3075
3075
|
"replacement": {
|
|
3076
3076
|
"decision": "segoe-ui-preview",
|
|
3077
3077
|
"weight": 300,
|
|
3078
|
-
"measured":
|
|
3079
|
-
"replacement": "Red Hat Display",
|
|
3080
|
-
"meanAbsWidthDelta": 0.0187,
|
|
3081
|
-
"meanWidthDelta": 0.0179,
|
|
3082
|
-
"maxAbsWidthDelta": 0.0662,
|
|
3083
|
-
"styles": 2,
|
|
3084
|
-
"reference": "Segoe UI Light 5.71"
|
|
3085
|
-
}
|
|
3078
|
+
"measured": null
|
|
3086
3079
|
},
|
|
3087
3080
|
"alternates": [
|
|
3088
3081
|
"Carlito"
|
|
@@ -3140,14 +3133,8 @@ var fontPolicySource = {
|
|
|
3140
3133
|
"embeddableByOpf": false,
|
|
3141
3134
|
"replacement": {
|
|
3142
3135
|
"decision": "segoe-ui-preview",
|
|
3143
|
-
"
|
|
3144
|
-
|
|
3145
|
-
"meanAbsWidthDelta": 0.0322,
|
|
3146
|
-
"meanWidthDelta": 0.0321,
|
|
3147
|
-
"maxAbsWidthDelta": 0.0905,
|
|
3148
|
-
"styles": 2,
|
|
3149
|
-
"reference": "Segoe UI Semilight 5.71"
|
|
3150
|
-
}
|
|
3136
|
+
"weight": 350,
|
|
3137
|
+
"measured": null
|
|
3151
3138
|
},
|
|
3152
3139
|
"alternates": [
|
|
3153
3140
|
"Roboto"
|
|
@@ -1,5 +1,62 @@
|
|
|
1
|
-
import { assertValid, resolveSlideScriptMeasurement, resolveDrawnFontFamilies, resolveSlideContext } from './chunk-
|
|
2
|
-
import { composeSlide, resolveSlideVariables, slideBlockIds, OPFCompositionError, checkCatalogsOption, usesSlideBuiltin, isOverlayConnector, codeHighlightSlice, tableRowBoundaries, visitContentPayloads, regionAccepts, slideTokenSpans, sliceNumberedItems, isShapeBlock } from './chunk-
|
|
1
|
+
import { assertValid, resolveSlideScriptMeasurement, resolveDrawnFontFamilies, resolveSlideContext } from './chunk-AEHDXNZX.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
|
|
99
|
-
const
|
|
100
|
-
if (
|
|
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|
|
|
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|
|
|
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
|
|
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
|
-
|
|
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|
|
|
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;
|