@openpresentation/opf 0.34.2 → 0.35.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 (89) hide show
  1. package/README.md +6 -6
  2. package/dist/browser.js +19 -19
  3. package/dist/{catalog-refs-wtuudZTe.d.ts → catalog-refs-BgotJhR5.d.ts} +105 -95
  4. package/dist/{catalog-schemas-CSxuFtsu.d.ts → catalog-schemas-BX-VEc5Q.d.ts} +1 -1
  5. package/dist/{chunk-RM4Z7ZSW.js → chunk-2GCTKQDD.js} +4 -4
  6. package/dist/{chunk-VI7VWDTN.js → chunk-3KPTVK77.js} +75 -283
  7. package/dist/{chunk-AQ3WR3H7.js → chunk-3ZTKRX7F.js} +4 -6
  8. package/dist/{chunk-IDYYLJCQ.js → chunk-4UMZDDJG.js} +11 -29
  9. package/dist/{chunk-NLJFNCZ4.js → chunk-6JHV2K67.js} +6 -6
  10. package/dist/{chunk-FK5XG742.js → chunk-6VGLE7C5.js} +114 -2
  11. package/dist/{chunk-V4G3BYPY.js → chunk-7KUUIL7W.js} +7 -7
  12. package/dist/{chunk-PHOSM2RA.js → chunk-ARPMSD7V.js} +1 -1
  13. package/dist/{chunk-UKI43JE6.js → chunk-GGN3NQDK.js} +1 -1
  14. package/dist/{chunk-XLXCXEVF.js → chunk-GKUAVSXU.js} +3 -10
  15. package/dist/{chunk-HX4HEJB4.js → chunk-HORPH6O7.js} +7 -6
  16. package/dist/{chunk-KJFCHCWV.js → chunk-JQNT37IO.js} +4 -13
  17. package/dist/{chunk-WBPXRUZT.js → chunk-KNMMEE67.js} +795 -467
  18. package/dist/{chunk-IGT4523S.js → chunk-LDLLZQPP.js} +706 -432
  19. package/dist/{chunk-6MSH3KCZ.js → chunk-MS2LPR7F.js} +1 -5
  20. package/dist/{chunk-NMZCPZ3R.js → chunk-MVPQEMCP.js} +97 -15
  21. package/dist/{chunk-P2X4BBW2.js → chunk-NPRNWPP4.js} +1 -1
  22. package/dist/{chunk-EQCZ2SFD.js → chunk-P2ACZJUL.js} +6 -6
  23. package/dist/chunk-SEC4IOOS.js +1 -0
  24. package/dist/{chunk-VVPPMHP6.js → chunk-VMPOCXTE.js} +5 -17
  25. package/dist/{chunk-MDAXXFAY.js → chunk-ZZWX4W2G.js} +2 -2
  26. package/dist/{composition-DF07Ha4R.d.ts → composition-BmJfljJl.d.ts} +198 -114
  27. package/dist/composition.d.ts +2 -2
  28. package/dist/composition.js +1 -1
  29. package/dist/{conversion-52ki0lfZ.d.ts → conversion-BbXhlurO.d.ts} +7 -7
  30. package/dist/conversion-VWCH3NKR.js +25 -0
  31. package/dist/convert.d.ts +11 -11
  32. package/dist/convert.js +61 -86
  33. package/dist/data.d.ts +1 -1
  34. package/dist/data.js +2 -2
  35. package/dist/{deck-report-C3EsoHC3.d.ts → deck-report-BYkbL7uT.d.ts} +3 -3
  36. package/dist/deck.d.ts +6 -6
  37. package/dist/deck.js +11 -11
  38. package/dist/diagram-engine-eager.js +1 -1
  39. package/dist/diagram-engine-lazy.js +1 -1
  40. package/dist/{diagram-plantuml-XRZ6VAOL.js → diagram-plantuml-GWXGKY7R.js} +1 -1
  41. package/dist/diff.d.ts +2 -2
  42. package/dist/diff.js +4 -4
  43. package/dist/docs.js +39 -39
  44. package/dist/examples.js +6336 -8170
  45. package/dist/{finding-l9dlQ2NF.d.ts → finding-mcHslZLA.d.ts} +6 -2
  46. package/dist/font-policy.d.ts +16 -2
  47. package/dist/font-policy.js +1 -1
  48. package/dist/format.js +2 -2
  49. package/dist/ids.d.ts +2 -2
  50. package/dist/ids.js +4 -4
  51. package/dist/index.d.ts +125 -27
  52. package/dist/index.js +24 -23
  53. package/dist/markdown.d.ts +1 -1
  54. package/dist/markdown.js +8 -8
  55. package/dist/node-engine.d.ts +6 -6
  56. package/dist/node-engine.js +21 -21
  57. package/dist/{pagination-Do7vNgU-.d.ts → pagination-C0FPjO29.d.ts} +4 -4
  58. package/dist/pagination.d.ts +3 -3
  59. package/dist/pagination.js +4 -4
  60. package/dist/patch.d.ts +4 -4
  61. package/dist/patch.js +3 -3
  62. package/dist/precompiled.js +2 -2
  63. package/dist/{presentation-ANs2WkaS.d.ts → presentation-Dx-kZC8Y.d.ts} +25 -81
  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 +5 -7
  68. package/dist/schema.js +3 -3
  69. package/dist/schemas.js +1 -1
  70. package/dist/source.js +10 -10
  71. package/dist/spec/reference/engine-defaults.json +1 -1
  72. package/dist/spec/reference/engine-vocabularies.json +43 -43
  73. package/dist/spec/reference/font-policy.json +114 -2
  74. package/dist/spec/reference/font-policy.schema.json +45 -1
  75. package/dist/spec/schemas/color-scheme.schema.json +2 -2
  76. package/dist/spec/schemas/finding.schema.json +2 -1
  77. package/dist/spec/schemas/layout.schema.json +27 -85
  78. package/dist/spec/schemas/opf.schema.json +26 -175
  79. package/dist/spec/schemas/theme.schema.json +10 -10
  80. package/dist/symbol-font-encodings.d.ts +2 -2
  81. package/dist/types.d.ts +74 -86
  82. package/dist/{validation-types-BNS41nzb.d.ts → validation-types-DKIe1RQW.d.ts} +5 -5
  83. package/dist/validator.d.ts +5 -7
  84. package/dist/validator.js +3 -3
  85. package/dist/yaml.d.ts +1 -1
  86. package/dist/yaml.js +7 -7
  87. package/package.json +5 -5
  88. package/dist/chunk-HSXWDXKM.js +0 -1
  89. package/dist/conversion-F3HSCFOV.js +0 -25
@@ -1,4 +1,4 @@
1
- import { presentation } from './chunk-VI7VWDTN.js';
1
+ import { presentation } from './chunk-3KPTVK77.js';
2
2
 
3
3
  // src/format.ts
4
4
  var OPFFormatError = class extends Error {
@@ -67,10 +67,6 @@ function format(input, options = {}) {
67
67
  if (!Number.isInteger(indent) || indent < 0 || indent > 8) throw new OPFFormatError("indent must be an integer from 0 to 8.");
68
68
  if (options.eol !== void 0 && options.eol !== "lf" && options.eol !== "crlf") throw new OPFFormatError("eol must be lf or crlf.");
69
69
  const sorted = sortPresentationKeys(document);
70
- const slides = sorted !== null && typeof sorted === "object" && !Array.isArray(sorted) ? sorted.slides : void 0;
71
- if (Array.isArray(slides)) {
72
- for (const slide of slides) if (slide !== null && typeof slide === "object" && slide.layout === "auto") delete slide.layout;
73
- }
74
70
  const text = JSON.stringify(sorted, null, indent);
75
71
  if (text === void 0) throw new OPFFormatError("Nothing to format.");
76
72
  return options.eol === "crlf" ? `${text.replaceAll("\n", "\r\n")}\r
@@ -1,6 +1,6 @@
1
- import { OPFDataImportError, parseTabularData } from './chunk-UKI43JE6.js';
2
- import { applyPatchWithInverse, validate, OPFValidationError } from './chunk-WBPXRUZT.js';
3
- import { embeddedCopy, checkCatalogsOption, catalogReferenceSites, parseReference, catalogGroupDeclared, resolveReference, dottedPath, unresolvedReference, recordReferenceSites, catalogGroupSource, registeredCatalog, catalogKinds, CATALOG_GROUP_PATTERN, isRecord, visitContentPayloads, annotationText, listVariables, resolveVariables, LOGO_SHAPES, resolveDesignRecords, resolveFontFamilies, resolveCanvasDimensions, imageBackground } from './chunk-IGT4523S.js';
1
+ import { OPFDataImportError, parseTabularData } from './chunk-GGN3NQDK.js';
2
+ import { refreshStaleLayouts, applyPatchWithInverse, validate, OPFValidationError, createValidator, documentHash, applyPatch, OPFPatchError, parsePointer } from './chunk-KNMMEE67.js';
3
+ import { embeddedCopy, checkCatalogsOption, catalogReferenceSites, parseReference, catalogGroupDeclared, resolveReference, dottedPath, unresolvedReference, recordReferenceSites, catalogGroupSource, registeredCatalog, catalogKinds, CATALOG_GROUP_PATTERN, isRecord, visitContentPayloads, cellBlocks, annotationText, listVariables, resolveVariables, LOGO_SHAPES, resolveDesignRecords, resolveFontFamilies, resolveCanvasDimensions, imageBackground } from './chunk-LDLLZQPP.js';
4
4
 
5
5
  // src/api-errors.ts
6
6
  var OPFApiError = class extends Error {
@@ -75,6 +75,7 @@ var kindsOf = (group, kind) => {
75
75
  function embed(document, options = {}) {
76
76
  const catalogs = { catalogs: checkCatalogsOption(options.catalogs, "embed") };
77
77
  const out = structuredClone(rec(document));
78
+ const refreshed = refreshStaleLayouts(out, catalogs);
78
79
  const added = [];
79
80
  const unresolved = [];
80
81
  const queue = catalogReferenceSites(out);
@@ -107,7 +108,7 @@ function embed(document, options = {}) {
107
108
  added.push({ group: found.group, kind: site.kind, id: found.id, ...found.source !== void 0 ? { source: found.source } : {} });
108
109
  queue.push(...recordReferenceSites(site.kind, copy, ["catalogs", found.group, site.kind, found.id], found.group));
109
110
  }
110
- return { document: out, added, unresolved };
111
+ return { document: out, added, refreshed, unresolved };
111
112
  }
112
113
  function groupNameFor(source) {
113
114
  const base = source.startsWith("pkg:") ? source.slice(4).replace(/^@/, "").split("/").slice(0, 2).join("-") : (() => {
@@ -329,11 +330,11 @@ function moveToCustom(document, ref, options = {}) {
329
330
  const references = [];
330
331
  sites.forEach((site, index) => {
331
332
  if (inMoved(site) || !isMoved(targets[index])) return;
332
- const written = referenceTo(kind, "custom", toId, site.group);
333
- if (written === site.reference) return;
334
- setAt(after, site.path, written);
333
+ const written2 = referenceTo(kind, "custom", toId, site.group);
334
+ if (written2 === site.reference) return;
335
+ setAt(after, site.path, written2);
335
336
  references.push(pointerOf(site.path));
336
- patch.push({ op: "replace", path: pointerOf(site.path), value: written });
337
+ patch.push({ op: "replace", path: pointerOf(site.path), value: written2 });
337
338
  });
338
339
  return {
339
340
  document: after,
@@ -572,7 +573,7 @@ function compute(presentation2, options, onFile) {
572
573
  };
573
574
  const datasetRecords = isRecord(deck.datasets) ? Object.entries(deck.datasets).filter(([, value]) => isRecord(value)) : [];
574
575
  const datasetUse = /* @__PURE__ */ new Map();
575
- const payloadCounts = { text: 0, items: 0, bullets: 0, quote: 0, metric: 0, code: 0, timeline: 0, diagram: 0, chart: 0, table: 0, image: 0, video: 0, blocks: 0, regions: 0, groups: 0, maxDepth: 0 };
576
+ const payloadCounts = { text: 0, items: 0, bullets: 0, quote: 0, metric: 0, code: 0, timeline: 0, diagram: 0, chart: 0, table: 0, image: 0, video: 0, blocks: 0, cells: 0, groups: 0, maxDepth: 0 };
576
577
  const layouts = /* @__PURE__ */ new Map(), chartTypes = /* @__PURE__ */ new Map(), extensions = /* @__PURE__ */ new Set();
577
578
  const chartData = { inline: 0, dataset: 0, withSource: 0 };
578
579
  const tableItems = [];
@@ -610,11 +611,10 @@ function compute(presentation2, options, onFile) {
610
611
  run(node.caption);
611
612
  }
612
613
  };
613
- const visitNode = (node, path, depth, kind) => {
614
+ const visitNode = (node, path, depth2, kind) => {
614
615
  if (kind === "block") payloadCounts.blocks++;
615
- if (kind === "region") payloadCounts.regions++;
616
616
  if (kind !== "root" && Array.isArray(node.blocks)) payloadCounts.groups++;
617
- if (depth > payloadCounts.maxDepth) payloadCounts.maxDepth = depth;
617
+ if (depth2 > payloadCounts.maxDepth) payloadCounts.maxDepth = depth2;
618
618
  for (const key of KIND_ORDER) if (node[key] !== void 0) {
619
619
  payloadCounts[key]++;
620
620
  kinds.add(key);
@@ -698,9 +698,9 @@ function compute(presentation2, options, onFile) {
698
698
  const slidePath = `/slides/${index}`;
699
699
  visitNode(slide, slidePath, 0, "root");
700
700
  visitContentPayloads(slide, slidePath, (node, path) => {
701
- const relative = path.slice(slidePath.length + 1);
702
- visitNode(node, path, (relative.match(/(^|\/)blocks\//g) ?? []).length, /(^|\/)blocks\/\d+$/.test(relative) ? "block" : "region");
701
+ visitNode(node, path, (path.slice(slidePath.length + 1).match(/(^|\/)blocks\//g) ?? []).length, "block");
703
702
  });
703
+ payloadCounts.cells += cellBlocks(slide)?.length ?? 0;
704
704
  const notes = typeof slide.notes === "string" ? slide.notes : "";
705
705
  const noteWords = wordCount(notes);
706
706
  const hasNotes = notes.trim() !== "";
@@ -859,6 +859,88 @@ function edit(deck, patch, options = {}) {
859
859
  return { presentation: presentation2, findings: report.findings, inverse: result.inverse };
860
860
  }
861
861
 
862
+ // src/fix.ts
863
+ var DEFAULT_FIX_ROUNDS = 10;
864
+ var FIX_REPAIR_CATEGORIES = Object.freeze(["format", "references", "policy", "layout"]);
865
+ var fixesInScope = (finding, audits = false) => audits || FIX_REPAIR_CATEGORIES.includes(finding.category);
866
+ var isSafePatch = (fix2) => fix2.safe === true && (fix2.kind ?? "patch") === "patch" && Array.isArray(fix2.patch) && fix2.patch.length > 0;
867
+ function written(operation) {
868
+ const at = (pointer, structural2) => {
869
+ const tokens = parsePointer(pointer);
870
+ const last = tokens.at(-1);
871
+ return structural2 && last !== void 0 && /^(\d+|-)$/.test(last) ? pointer.slice(0, pointer.lastIndexOf("/")) : pointer;
872
+ };
873
+ if (operation.op === "test") return [];
874
+ const structural = operation.op === "add" || operation.op === "remove" || operation.op === "move" || operation.op === "copy";
875
+ return [at(operation.path, structural), ...operation.op === "move" ? [at(operation.from, true)] : []];
876
+ }
877
+ var overlaps = (a, b) => a === b || a.startsWith(`${b}/`) || b.startsWith(`${a}/`);
878
+ var depth = (paths) => Math.min(...paths.map((pointer) => parsePointer(pointer).length));
879
+ function candidates(findings, audits) {
880
+ const chosen = [];
881
+ for (const finding of findings) {
882
+ if (!fixesInScope(finding, audits)) continue;
883
+ let best;
884
+ for (const fix2 of finding.fixes ?? []) {
885
+ if (!isSafePatch(fix2)) continue;
886
+ const paths = fix2.patch.flatMap(written);
887
+ if (!paths.length) continue;
888
+ const candidate = { finding, fix: fix2, paths, depth: depth(paths) };
889
+ if (!best || candidate.depth < best.depth) best = candidate;
890
+ }
891
+ if (best) chosen.push(best);
892
+ }
893
+ return chosen.sort((a, b) => a.depth - b.depth);
894
+ }
895
+ var designParents = (patch) => patch.flatMap((operation) => operation.op === "remove" && parsePointer(operation.path).at(-2) === "design" ? [operation.path.slice(0, operation.path.lastIndexOf("/"))] : []);
896
+ var readPointer = (root, pointer) => parsePointer(pointer).reduce((value, key) => value !== null && typeof value === "object" ? value[key] : void 0, root);
897
+ var isEmptyObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && !Object.keys(value).length;
898
+ function fix(document, options = {}) {
899
+ const { maxRounds = DEFAULT_FIX_ROUNDS, audits = false, ...validateOptions } = options;
900
+ if (!Number.isInteger(maxRounds) || maxRounds < 1) throw new TypeError("fix: maxRounds must be a positive integer.");
901
+ const validator = createValidator();
902
+ let working = structuredClone(document);
903
+ const applied = [];
904
+ const seen = /* @__PURE__ */ new Set([documentHash(working)]);
905
+ let rounds = 0;
906
+ for (; ; ) {
907
+ const report = validator.validate(working, validateOptions);
908
+ const pending = candidates(report.findings, audits);
909
+ const result = (stopped) => ({ document: working, applied, findings: report.findings, report, rounds, stopped });
910
+ if (!pending.length) return result("stable");
911
+ if (rounds === maxRounds) return result("max-rounds");
912
+ const touched = [];
913
+ let changed = false;
914
+ for (const { finding, fix: chosen, paths } of pending) {
915
+ if (paths.some((path) => touched.some((done) => overlaps(path, done)))) continue;
916
+ const parents = [...new Set(designParents(chosen.patch))].filter((pointer) => !isEmptyObject(readPointer(working, pointer)));
917
+ const patch = structuredClone(chosen.patch);
918
+ try {
919
+ working = applyPatch(working, chosen.patch);
920
+ const removals = parents.filter((pointer) => isEmptyObject(readPointer(working, pointer))).map((pointer) => ({ op: "remove", path: pointer }));
921
+ if (removals.length) {
922
+ working = applyPatch(working, removals);
923
+ patch.push(...removals);
924
+ }
925
+ } catch (error) {
926
+ if (error instanceof OPFPatchError) continue;
927
+ throw error;
928
+ }
929
+ touched.push(...paths, ...patch.slice(chosen.patch.length).map((operation) => operation.path));
930
+ changed = true;
931
+ applied.push({ round: rounds + 1, ruleId: finding.ruleId, path: finding.path, fix: chosen.id ?? chosen.title, title: chosen.title, changesDrawing: chosen.changesDrawing === true, patch });
932
+ }
933
+ if (!changed) return result("no-progress");
934
+ rounds += 1;
935
+ const hash = documentHash(working);
936
+ if (seen.has(hash)) {
937
+ const last = validator.validate(working, validateOptions);
938
+ return { document: working, applied, findings: last.findings, report: last, rounds, stopped: "no-progress" };
939
+ }
940
+ seen.add(hash);
941
+ }
942
+ }
943
+
862
944
  // src/fill.ts
863
945
  var isRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
864
946
  function fillRecords(raw, options = {}) {
@@ -929,4 +1011,4 @@ function summarize(decks) {
929
1011
  return [...merged.values()];
930
1012
  }
931
1013
 
932
- export { OPFApiError, OPFExportError, OPFImportError, OPFMoveToCustomError, asApiError, copySlides, edit, embed, fill, fillRecords, localAssetSources, moveToCustom, parseSlideSelection, sameRecord, stats, updateFromCatalog };
1014
+ export { DEFAULT_FIX_ROUNDS, FIX_REPAIR_CATEGORIES, OPFApiError, OPFExportError, OPFImportError, OPFMoveToCustomError, asApiError, copySlides, edit, embed, fill, fillRecords, fix, isSafePatch, localAssetSources, moveToCustom, parseSlideSelection, sameRecord, stats, updateFromCatalog };
@@ -1,4 +1,4 @@
1
- import { runText } from './chunk-PHOSM2RA.js';
1
+ import { runText } from './chunk-ARPMSD7V.js';
2
2
 
3
3
  // src/convert/text-lines.ts
4
4
  var LIST_PREFIX = /^([ \t]*)(?:([-*•+]|\d{1,3}[.)])[ \t]+)?/;
@@ -1,10 +1,10 @@
1
- import { sortPresentationKeys } from './chunk-6MSH3KCZ.js';
1
+ import { sortPresentationKeys } from './chunk-MS2LPR7F.js';
2
2
  import { NOT_CHECKED } from './chunk-RYZPBJLB.js';
3
- import { Ctx, describeYamlErrors } from './chunk-MDAXXFAY.js';
4
- import { same } from './chunk-PHOSM2RA.js';
5
- import { validate } from './chunk-WBPXRUZT.js';
6
- import { presentation } from './chunk-VI7VWDTN.js';
7
- import { checkCatalogsOption } from './chunk-IGT4523S.js';
3
+ import { Ctx, describeYamlErrors } from './chunk-ZZWX4W2G.js';
4
+ import { same } from './chunk-ARPMSD7V.js';
5
+ import { validate } from './chunk-KNMMEE67.js';
6
+ import { presentation } from './chunk-3KPTVK77.js';
7
+ import { checkCatalogsOption } from './chunk-LDLLZQPP.js';
8
8
  import { Parser, parseDocument, isMap, isSeq, Document, visit, isScalar, isAlias } from 'yaml';
9
9
 
10
10
  var MAX_ALIAS_COUNT = 100;