@taloswork/ose-shared 0.1.11 → 0.1.13

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 (159) hide show
  1. package/package.json +3 -3
  2. package/skills/document/SKILL.md +135 -219
  3. package/skills/document/art-directions/base.css +27 -2
  4. package/skills/document/art-directions/cinematic-depth.css +3 -1
  5. package/skills/document/art-directions/collage-paper.css +5 -1
  6. package/skills/document/art-directions/editorial-cut.css +5 -1
  7. package/skills/document/art-directions/geometric-pop.css +6 -0
  8. package/skills/document/art-directions/gradient-mesh.css +5 -1
  9. package/skills/document/art-directions/illustrated-doodle.css +5 -0
  10. package/skills/document/art-directions/luxury-ornament.css +4 -1
  11. package/skills/document/art-directions/maximalist-blocks.css +6 -0
  12. package/skills/document/art-directions/technical-grid.css +4 -0
  13. package/skills/document/assets/fonts/fonts.json +2 -2
  14. package/skills/document/assets/pdf-fonts/NotoSansSC-PDF-Bold.ttf +0 -0
  15. package/skills/document/assets/pdf-fonts/NotoSansSC-PDF-Regular.ttf +0 -0
  16. package/skills/document/assets/pdf-fonts/OFL.txt +93 -0
  17. package/skills/document/assets/pdf-fonts/README.md +35 -0
  18. package/skills/document/assets/tessdata/LICENSE-Apache-2.0.txt +202 -0
  19. package/skills/document/assets/tessdata/README.md +21 -0
  20. package/skills/document/assets/tessdata/chi_sim.traineddata.gz +0 -0
  21. package/skills/document/assets/tessdata/eng.traineddata.gz +0 -0
  22. package/skills/document/bin/deck-build.cjs +12563 -83
  23. package/skills/document/bin/deck-chart.cjs +771 -0
  24. package/skills/document/bin/deck-plan.cjs +12414 -0
  25. package/skills/document/bin/deck-qa.cjs +1075 -266
  26. package/skills/document/bin/deck-scenario.cjs +1363 -0
  27. package/skills/document/bin/deck-styles.cjs +1604 -0
  28. package/skills/document/bin/doc-convert.cjs +308 -292
  29. package/skills/document/bin/doc-fill.cjs +73264 -192
  30. package/skills/document/bin/doc-gen.cjs +2491 -312
  31. package/skills/document/bin/doc-run.cjs +162 -24
  32. package/skills/document/bin/doc-scan.cjs +13 -0
  33. package/skills/document/bin/doc-text.cjs +13 -0
  34. package/skills/document/bin/doc-validate.cjs +838 -68
  35. package/skills/document/bin/doc-xml.cjs +9 -5
  36. package/skills/document/bin/docx-annotate.cjs +95 -19
  37. package/skills/document/bin/docx-defaults.cjs +9907 -0
  38. package/skills/document/bin/fontkit.cjs +1 -0
  39. package/skills/document/bin/html2pptx.cjs +36622 -31394
  40. package/skills/document/bin/ocr-worker.cjs +1 -0
  41. package/skills/document/bin/ocr.cjs +131 -40
  42. package/skills/document/bin/pdf-form.cjs +682 -177
  43. package/skills/document/bin/pdf-images.cjs +13 -0
  44. package/skills/document/bin/pdf-ops.cjs +642 -199
  45. package/skills/document/bin/pdf-render.cjs +19 -3
  46. package/skills/document/bin/pdf-tables.cjs +13 -0
  47. package/skills/document/bin/pptx-clone.cjs +3 -3
  48. package/skills/document/bin/pptx-notes.cjs +10038 -0
  49. package/skills/document/bin/pptx-slide.cjs +3 -3
  50. package/skills/document/bin/pptx-tokenize.cjs +19 -4
  51. package/skills/document/bin/template-skin.cjs +10910 -0
  52. package/skills/document/bin/xlsx-query.cjs +192 -61
  53. package/skills/document/bin-reference.md +61 -33
  54. package/skills/document/catalog.json +33 -32
  55. package/skills/document/content-pipeline.md +179 -257
  56. package/skills/document/deck-design.md +378 -638
  57. package/skills/document/generated-visuals.md +99 -0
  58. package/skills/document/layouts/MAINTAINERS.md +33 -0
  59. package/skills/document/layouts/README.md +49 -36
  60. package/skills/document/layouts/big-stat.tpl +1 -1
  61. package/skills/document/layouts/capacity.json +1 -0
  62. package/skills/document/layouts/cards-3.tpl +1 -1
  63. package/skills/document/layouts/chart-full.tpl +1 -1
  64. package/skills/document/layouts/chart-kpi.tpl +1 -1
  65. package/skills/document/layouts/comparison.tpl +1 -1
  66. package/skills/document/layouts/data-table.tpl +1 -1
  67. package/skills/document/layouts/funnel.tpl +1 -1
  68. package/skills/document/layouts/gantt.tpl +1 -1
  69. package/skills/document/layouts/hub-flow.tpl +4 -0
  70. package/skills/document/layouts/icon-row.tpl +1 -1
  71. package/skills/document/layouts/image-grid.tpl +1 -1
  72. package/skills/document/layouts/matrix-2x2.tpl +1 -1
  73. package/skills/document/layouts/mock-qa.tpl +4 -0
  74. package/skills/document/layouts/profiles.json +2 -2
  75. package/skills/document/layouts/pyramid.tpl +1 -1
  76. package/skills/document/layouts/radar.tpl +1 -1
  77. package/skills/document/layouts/ring-progress.tpl +1 -1
  78. package/skills/document/layouts/slots.json +1 -1
  79. package/skills/document/layouts/steps-vertical.tpl +1 -1
  80. package/skills/document/layouts/steps.tpl +1 -1
  81. package/skills/document/layouts/three-kpi.tpl +1 -1
  82. package/skills/document/layouts/timeline.tpl +1 -1
  83. package/skills/document/layouts/toc-panel.tpl +2 -2
  84. package/skills/document/layouts/two-kpi.tpl +2 -2
  85. package/skills/document/layouts/versus.tpl +1 -1
  86. package/skills/document/motion/README.md +3 -2
  87. package/skills/document/office.md +3 -3
  88. package/skills/document/packs/README.md +1 -1
  89. package/skills/document/packs/board-brief/backdrop.html +2 -0
  90. package/skills/document/packs/board-brief/pack.css +2 -1
  91. package/skills/document/packs/mckinsey-photo/backdrop.html +2 -0
  92. package/skills/document/packs/mckinsey-photo/pack.css +2 -1
  93. package/skills/document/packs/press-room/backdrop.html +2 -0
  94. package/skills/document/packs/press-room/pack.css +2 -1
  95. package/skills/document/packs/prismatic-3d/backdrop.html +2 -0
  96. package/skills/document/packs/prismatic-3d/pack.css +4 -1
  97. package/skills/document/pdf.md +60 -43
  98. package/skills/document/rewrite.md +257 -309
  99. package/skills/document/scenarios.json +1307 -0
  100. package/skills/document/scenarios.schema.json +104 -0
  101. package/skills/document/styles/README.md +15 -25
  102. package/skills/document/styles/_backdrops/rimlight.html +3 -2
  103. package/skills/document/styles/_contract-defaults.css +31 -2
  104. package/skills/document/styles/_samples/_groups/biz-premium.webp +0 -0
  105. package/skills/document/styles/_samples/mckinsey.webp +0 -0
  106. package/skills/document/styles/anthropic/skin.css +6 -3
  107. package/skills/document/styles/apple/skin.css +4 -3
  108. package/skills/document/styles/bistro-warm/backdrop.html +2 -0
  109. package/skills/document/styles/bistro-warm/skin.css +4 -1
  110. package/skills/document/styles/black-gold/skin.css +6 -5
  111. package/skills/document/styles/bold-clash/backdrop.html +2 -0
  112. package/skills/document/styles/bold-clash/skin.css +2 -1
  113. package/skills/document/styles/branding/skin.css +4 -4
  114. package/skills/document/styles/campus-teal/backdrop.html +2 -0
  115. package/skills/document/styles/campus-teal/skin.css +2 -1
  116. package/skills/document/styles/cinereel/skin.css +7 -3
  117. package/skills/document/styles/clinic-care/backdrop.html +2 -0
  118. package/skills/document/styles/clinic-care/skin.css +2 -1
  119. package/skills/document/styles/cool/skin.css +6 -5
  120. package/skills/document/styles/dark-glass/backdrop.html +2 -0
  121. package/skills/document/styles/dark-glass/skin.css +2 -1
  122. package/skills/document/styles/gov-brief/backdrop.html +2 -0
  123. package/skills/document/styles/gov-brief/skin.css +2 -1
  124. package/skills/document/styles/grid-tech/backdrop.html +2 -0
  125. package/skills/document/styles/grid-tech/skin.css +2 -1
  126. package/skills/document/styles/hand-drawn/skin.css +3 -3
  127. package/skills/document/styles/ivory-gold/skin.css +7 -6
  128. package/skills/document/styles/legal-slate/backdrop.html +2 -0
  129. package/skills/document/styles/legal-slate/skin.css +2 -1
  130. package/skills/document/styles/magazine-ink/skin.css +4 -3
  131. package/skills/document/styles/mckinsey/backdrop.html +7 -5
  132. package/skills/document/styles/mckinsey/skin.css +2 -1
  133. package/skills/document/styles/memphis/backdrop.html +2 -0
  134. package/skills/document/styles/memphis/skin.css +2 -1
  135. package/skills/document/styles/mono/skin.css +6 -2
  136. package/skills/document/styles/neon-cyber/backdrop.html +2 -0
  137. package/skills/document/styles/neon-cyber/skin.css +2 -1
  138. package/skills/document/styles/olive-gold/skin.css +7 -6
  139. package/skills/document/styles/organic-earth/backdrop.html +2 -0
  140. package/skills/document/styles/organic-earth/skin.css +2 -1
  141. package/skills/document/styles/pastel-saas/backdrop.html +2 -0
  142. package/skills/document/styles/pastel-saas/skin.css +2 -1
  143. package/skills/document/styles/portfolio-noir/backdrop.html +2 -0
  144. package/skills/document/styles/portfolio-noir/skin.css +2 -1
  145. package/skills/document/styles/retro-press/backdrop.html +2 -0
  146. package/skills/document/styles/retro-press/skin.css +2 -1
  147. package/skills/document/styles/sport-arena/backdrop.html +2 -0
  148. package/skills/document/styles/sport-arena/skin.css +4 -1
  149. package/skills/document/styles/swiss-grid/skin.css +10 -5
  150. package/skills/document/styles/wedding-blush/backdrop.html +2 -0
  151. package/skills/document/styles/wedding-blush/skin.css +4 -1
  152. package/skills/document/theme-system.md +85 -77
  153. package/skills/document/themes/README.md +7 -5
  154. package/skills/document/vision.md +8 -5
  155. package/skills/document/xlsx.md +15 -25
  156. package/skills/grill-me/SKILL.md +6 -0
  157. package/skills/grill-me/agents/openai.yaml +5 -0
  158. package/skills/grilling/SKILL.md +28 -0
  159. package/skills/grilling/agents/openai.yaml +3 -0
@@ -9790,9 +9790,9 @@ var require_load = __commonJS({
9790
9790
  var require_lib3 = __commonJS({
9791
9791
  "node_modules/jszip/lib/index.js"(exports2, module2) {
9792
9792
  "use strict";
9793
- function JSZip5() {
9794
- if (!(this instanceof JSZip5)) {
9795
- return new JSZip5();
9793
+ function JSZip7() {
9794
+ if (!(this instanceof JSZip7)) {
9795
+ return new JSZip7();
9796
9796
  }
9797
9797
  if (arguments.length) {
9798
9798
  throw new Error("The constructor with parameters has been removed in JSZip 3.0, please check the upgrade guide.");
@@ -9801,7 +9801,7 @@ var require_lib3 = __commonJS({
9801
9801
  this.comment = null;
9802
9802
  this.root = "";
9803
9803
  this.clone = function() {
9804
- var newObj = new JSZip5();
9804
+ var newObj = new JSZip7();
9805
9805
  for (var i in this) {
9806
9806
  if (typeof this[i] !== "function") {
9807
9807
  newObj[i] = this[i];
@@ -9810,16 +9810,411 @@ var require_lib3 = __commonJS({
9810
9810
  return newObj;
9811
9811
  };
9812
9812
  }
9813
- JSZip5.prototype = require_object();
9814
- JSZip5.prototype.loadAsync = require_load();
9815
- JSZip5.support = require_support();
9816
- JSZip5.defaults = require_defaults();
9817
- JSZip5.version = "3.10.1";
9818
- JSZip5.loadAsync = function(content, options) {
9819
- return new JSZip5().loadAsync(content, options);
9813
+ JSZip7.prototype = require_object();
9814
+ JSZip7.prototype.loadAsync = require_load();
9815
+ JSZip7.support = require_support();
9816
+ JSZip7.defaults = require_defaults();
9817
+ JSZip7.version = "3.10.1";
9818
+ JSZip7.loadAsync = function(content, options) {
9819
+ return new JSZip7().loadAsync(content, options);
9820
9820
  };
9821
- JSZip5.external = require_external();
9822
- module2.exports = JSZip5;
9821
+ JSZip7.external = require_external();
9822
+ module2.exports = JSZip7;
9823
+ }
9824
+ });
9825
+
9826
+ // packages/core/dist/document/pdf-encrypted.js
9827
+ var ENCRYPTED_PDF_MESSAGE, PdfEncryptedError;
9828
+ var init_pdf_encrypted = __esm({
9829
+ "packages/core/dist/document/pdf-encrypted.js"() {
9830
+ "use strict";
9831
+ ENCRYPTED_PDF_MESSAGE = "PDF is password-protected (encrypted); decrypt first: pdf-ops decrypt <in> <password> <out>";
9832
+ PdfEncryptedError = class extends Error {
9833
+ constructor() {
9834
+ super(ENCRYPTED_PDF_MESSAGE);
9835
+ this.name = "PdfEncryptedError";
9836
+ }
9837
+ };
9838
+ }
9839
+ });
9840
+
9841
+ // packages/core/dist/document/pdf-extract.js
9842
+ var pdf_extract_exports = {};
9843
+ __export(pdf_extract_exports, {
9844
+ analyzePdfDocument: () => analyzePdfDocument,
9845
+ countVectorOperators: () => countVectorOperators,
9846
+ decryptPdf: () => decryptPdf,
9847
+ encryptPdf: () => encryptPdf,
9848
+ extractPdfImages: () => extractPdfImages,
9849
+ extractPdfTables: () => extractPdfTables,
9850
+ extractPdfText: () => extractPdfText,
9851
+ extractPdfTextLines: () => extractPdfTextLines,
9852
+ pdfNeedsPassword: () => pdfNeedsPassword,
9853
+ pngPixels: () => pngPixels,
9854
+ renderPdfPages: () => renderPdfPages,
9855
+ scanPdfSignals: () => scanPdfSignals,
9856
+ textMathHint: () => textMathHint,
9857
+ textTableHint: () => textTableHint
9858
+ });
9859
+ function loadMupdf() {
9860
+ if (!_mupdf) {
9861
+ const deps = process.env.TALOS_SKILL_DEPS;
9862
+ const spec = deps ? (0, import_node_url.pathToFileURL)((0, import_node_path.join)(deps, "mupdf", "dist", "mupdf.js")).href : "mupdf";
9863
+ _mupdf = import(spec);
9864
+ }
9865
+ return _mupdf;
9866
+ }
9867
+ function textMathHint(text) {
9868
+ if (!text)
9869
+ return false;
9870
+ const hits = (text.match(MATH_CHARS) || []).length;
9871
+ return hits >= 3 || hits / Math.max(text.length, 1) > 0.02;
9872
+ }
9873
+ function textTableHint(text) {
9874
+ if (!text)
9875
+ return false;
9876
+ const gaps = (text.match(/ {2,}|\t/g) || []).length;
9877
+ return gaps >= 6;
9878
+ }
9879
+ async function openDoc(bytes) {
9880
+ const mupdf = await loadMupdf();
9881
+ const doc = mupdf.Document.openDocument(bytes, "application/pdf");
9882
+ if (doc.needsPassword())
9883
+ throw new PdfEncryptedError();
9884
+ if (doc.countPages() === 0) {
9885
+ throw new Error("PDF has no readable pages (corrupt, encrypted, or empty)");
9886
+ }
9887
+ return { mupdf, doc };
9888
+ }
9889
+ async function analyzePdfDocument(bytes, options = {}) {
9890
+ const wantText = options.text !== false;
9891
+ const wantSignals = options.signals === true;
9892
+ const { doc } = await openDoc(bytes);
9893
+ const pageCount = doc.countPages();
9894
+ const signals = [];
9895
+ let out = "";
9896
+ for (let i = 0; i < pageCount; i++) {
9897
+ const page = doc.loadPage(i);
9898
+ if (wantText) {
9899
+ out += `
9900
+ [page ${i + 1}]
9901
+ ${page.toStructuredText().asText()}`;
9902
+ }
9903
+ if (wantSignals) {
9904
+ signals.push(pageSignalsFrom(page, i + 1));
9905
+ }
9906
+ }
9907
+ return { text: wantText ? out.trim() : "", pageCount, signals };
9908
+ }
9909
+ async function extractPdfText(bytes) {
9910
+ const { text, pageCount } = await analyzePdfDocument(bytes, { text: true });
9911
+ return { text, pageCount };
9912
+ }
9913
+ function countVectorOperators(content) {
9914
+ let ops = 0;
9915
+ let curves = 0;
9916
+ let fills = 0;
9917
+ let i = 0;
9918
+ const n = content.length;
9919
+ while (i < n) {
9920
+ const ch = content[i];
9921
+ if (ch === "(") {
9922
+ let depth = 1;
9923
+ i++;
9924
+ while (i < n && depth > 0) {
9925
+ if (content[i] === "\\")
9926
+ i++;
9927
+ else if (content[i] === "(")
9928
+ depth++;
9929
+ else if (content[i] === ")")
9930
+ depth--;
9931
+ i++;
9932
+ }
9933
+ continue;
9934
+ }
9935
+ if (ch === "<" && content[i + 1] !== "<") {
9936
+ while (i < n && content[i] !== ">")
9937
+ i++;
9938
+ i++;
9939
+ continue;
9940
+ }
9941
+ if (ch === "I" && content[i + 1] === "D" && isDelimiter(content[i + 2])) {
9942
+ const end = content.indexOf("EI", i + 2);
9943
+ i = end === -1 ? n : end + 2;
9944
+ continue;
9945
+ }
9946
+ if (!isDelimiter(ch)) {
9947
+ const start = i;
9948
+ while (i < n && !isDelimiter(content[i]))
9949
+ i++;
9950
+ const token = content.slice(start, i);
9951
+ switch (token) {
9952
+ case "m":
9953
+ case "l":
9954
+ case "re":
9955
+ ops++;
9956
+ break;
9957
+ case "c":
9958
+ case "v":
9959
+ case "y":
9960
+ ops++;
9961
+ curves++;
9962
+ break;
9963
+ case "f":
9964
+ case "F":
9965
+ case "f*":
9966
+ fills++;
9967
+ break;
9968
+ case "B":
9969
+ case "B*":
9970
+ case "b":
9971
+ case "b*":
9972
+ fills++;
9973
+ break;
9974
+ default:
9975
+ break;
9976
+ }
9977
+ continue;
9978
+ }
9979
+ i++;
9980
+ }
9981
+ return { ops, curves, fills };
9982
+ }
9983
+ function isDelimiter(ch) {
9984
+ return ch === void 0 || ch === " " || ch === "\n" || ch === "\r" || ch === " " || ch === "\f" || ch === "\0" || ch === "[" || ch === "]" || ch === "/" || ch === "{" || ch === "}";
9985
+ }
9986
+ function pageContentStream(page) {
9987
+ try {
9988
+ const obj = page.getObject?.();
9989
+ const contents = obj?.get?.("Contents");
9990
+ if (!contents)
9991
+ return "";
9992
+ const streams = contents.isArray?.() && contents.get ? Array.from({ length: contents.length ?? 0 }, (_, i) => contents.get(i)) : [contents];
9993
+ let out = "";
9994
+ for (const stream of streams) {
9995
+ const buf = stream?.readStream?.();
9996
+ const bytes = buf?.asUint8Array?.();
9997
+ if (bytes)
9998
+ out += Buffer.from(bytes).toString("latin1");
9999
+ }
10000
+ return out;
10001
+ } catch {
10002
+ return "";
10003
+ }
10004
+ }
10005
+ function pageSignalsFrom(page, pageNumber) {
10006
+ const json = JSON.parse(page.toStructuredText("preserve-images").asJSON());
10007
+ const blocks = json.blocks ?? [];
10008
+ const text = blocks.flatMap((b) => (b.lines ?? []).map((l) => l.text ?? "")).join(" ");
10009
+ const [x0, y0, x1, y1] = page.getBounds();
10010
+ const pageArea = Math.max((x1 - x0) * (y1 - y0), 1);
10011
+ const imgArea = blocks.filter((b) => b.type === "image").reduce((a, b) => a + Math.max((b.bbox?.w ?? 0) * (b.bbox?.h ?? 0), 0), 0);
10012
+ const vector = countVectorOperators(pageContentStream(page));
10013
+ return {
10014
+ page: pageNumber,
10015
+ textChars: text.trim().length,
10016
+ imageCoverage: Math.min(imgArea / pageArea, 1),
10017
+ vectorOps: vector.ops,
10018
+ vectorCurves: vector.curves,
10019
+ vectorFills: vector.fills,
10020
+ mathHint: textMathHint(text),
10021
+ tableHint: textTableHint(text)
10022
+ };
10023
+ }
10024
+ async function scanPdfSignals(bytes) {
10025
+ const { signals } = await analyzePdfDocument(bytes, { text: false, signals: true });
10026
+ return signals;
10027
+ }
10028
+ function median(nums) {
10029
+ if (!nums.length)
10030
+ return 0;
10031
+ const s = [...nums].sort((a, b) => a - b);
10032
+ return s[Math.floor(s.length / 2)];
10033
+ }
10034
+ async function extractPdfTables(bytes, pageNum, minColumns = 2) {
10035
+ const { doc } = await openDoc(bytes);
10036
+ const total = doc.countPages();
10037
+ const from = pageNum ? pageNum : 1;
10038
+ const to = pageNum ? pageNum : total;
10039
+ const out = [];
10040
+ for (let p = from; p <= to; p++) {
10041
+ if (p < 1 || p > total)
10042
+ continue;
10043
+ const json = JSON.parse(doc.loadPage(p - 1).toStructuredText().asJSON());
10044
+ const cells = [];
10045
+ for (const b of json.blocks ?? []) {
10046
+ if (b.type === "image")
10047
+ continue;
10048
+ for (const l of b.lines ?? []) {
10049
+ const text = (l.text ?? "").trim();
10050
+ if (!text)
10051
+ continue;
10052
+ cells.push({ text, x: l.bbox?.x ?? 0, y: l.bbox?.y ?? 0, h: l.bbox?.h ?? 12 });
10053
+ }
10054
+ }
10055
+ if (cells.length < 2)
10056
+ continue;
10057
+ const medH = median(cells.map((c) => c.h)) || 12;
10058
+ const rowTol = Math.max(4, medH * 0.6);
10059
+ const colTol = Math.max(6, medH * 0.9);
10060
+ const byY = [...cells].sort((a, b) => a.y - b.y);
10061
+ const rowGroups = [];
10062
+ let rowRef = Number.NEGATIVE_INFINITY;
10063
+ for (const c of byY) {
10064
+ if (c.y - rowRef > rowTol) {
10065
+ rowGroups.push([]);
10066
+ rowRef = c.y;
10067
+ }
10068
+ rowGroups[rowGroups.length - 1].push(c);
10069
+ }
10070
+ const colRefs = [];
10071
+ for (const x of cells.map((c) => c.x).sort((a, b) => a - b)) {
10072
+ if (!colRefs.length || x - colRefs[colRefs.length - 1] > colTol)
10073
+ colRefs.push(x);
10074
+ }
10075
+ const colIndex = (x) => {
10076
+ let best = 0, bd = Infinity;
10077
+ colRefs.forEach((r, i) => {
10078
+ const d = Math.abs(x - r);
10079
+ if (d < bd) {
10080
+ bd = d;
10081
+ best = i;
10082
+ }
10083
+ });
10084
+ return best;
10085
+ };
10086
+ const rows = [];
10087
+ for (const group of rowGroups) {
10088
+ const arr = Array(colRefs.length).fill("");
10089
+ for (const c of group.sort((a, b) => a.x - b.x)) {
10090
+ const i = colIndex(c.x);
10091
+ arr[i] = arr[i] ? `${arr[i]} ${c.text}` : c.text;
10092
+ }
10093
+ if (arr.filter((v) => v).length >= minColumns)
10094
+ rows.push(arr);
10095
+ }
10096
+ if (rows.length)
10097
+ out.push({ page: p, rows });
10098
+ }
10099
+ return out;
10100
+ }
10101
+ async function extractPdfTextLines(bytes) {
10102
+ const { doc } = await openDoc(bytes);
10103
+ const out = [];
10104
+ for (let p = 1; p <= doc.countPages(); p++) {
10105
+ const page = doc.loadPage(p - 1);
10106
+ const [x0, y0, x1, y1] = page.getBounds();
10107
+ const json = JSON.parse(page.toStructuredText().asJSON());
10108
+ const lines = [];
10109
+ for (const b of json.blocks ?? []) {
10110
+ if (b.type === "image")
10111
+ continue;
10112
+ for (const l of b.lines ?? []) {
10113
+ const text = l.text ?? "";
10114
+ if (!text.trim() || !l.bbox)
10115
+ continue;
10116
+ lines.push({
10117
+ x: l.bbox.x ?? 0,
10118
+ y: l.bbox.y ?? 0,
10119
+ w: l.bbox.w ?? 0,
10120
+ h: l.bbox.h ?? 0,
10121
+ size: l.font?.size ?? 12,
10122
+ text
10123
+ });
10124
+ }
10125
+ }
10126
+ out.push({ page: p, width: x1 - x0, height: y1 - y0, lines });
10127
+ }
10128
+ return out;
10129
+ }
10130
+ async function renderPdfPages(bytes, pages, scale = 2, maxEdge) {
10131
+ const { mupdf, doc } = await openDoc(bytes);
10132
+ const total = doc.countPages();
10133
+ const wanted = pages === "all" ? Array.from({ length: total }, (_, i) => i + 1) : pages;
10134
+ const out = [];
10135
+ for (const p of wanted) {
10136
+ if (p < 1 || p > total)
10137
+ continue;
10138
+ const page = doc.loadPage(p - 1);
10139
+ const [x0, y0, x1, y1] = page.getBounds();
10140
+ const longest = Math.max(x1 - x0, y1 - y0);
10141
+ const s = maxEdge && longest > 0 ? Math.min(scale, maxEdge / longest) : scale;
10142
+ const pix = page.toPixmap(mupdf.Matrix.scale(s, s), mupdf.ColorSpace.DeviceRGB, false, true);
10143
+ out.push({ page: p, png: pix.asPNG() });
10144
+ }
10145
+ return out;
10146
+ }
10147
+ async function pngPixels(png) {
10148
+ const mupdf = await loadMupdf();
10149
+ const pix = new mupdf.Image(png).toPixmap();
10150
+ const width = pix.getWidth(), height = pix.getHeight();
10151
+ const channels = pix.getStride() / width;
10152
+ return { width, height, channels, data: pix.getPixels() };
10153
+ }
10154
+ async function extractPdfImages(bytes, pages) {
10155
+ const { doc } = await openDoc(bytes);
10156
+ const total = doc.countPages();
10157
+ const wanted = pages && pages.length ? pages : Array.from({ length: total }, (_, i) => i + 1);
10158
+ const images = [];
10159
+ let skipped = 0;
10160
+ for (const p of wanted) {
10161
+ if (p < 1 || p > total)
10162
+ continue;
10163
+ const stext = doc.loadPage(p - 1).toStructuredText("preserve-images");
10164
+ let index = 0;
10165
+ stext.walk({
10166
+ onImageBlock(bbox, _matrix, image) {
10167
+ const slot = index++;
10168
+ try {
10169
+ const png = image.toPixmap().asPNG();
10170
+ images.push({
10171
+ page: p,
10172
+ index: slot,
10173
+ bbox: [bbox[0], bbox[1], bbox[2], bbox[3]],
10174
+ width: image.getWidth(),
10175
+ height: image.getHeight(),
10176
+ png
10177
+ });
10178
+ } catch {
10179
+ skipped++;
10180
+ }
10181
+ }
10182
+ });
10183
+ }
10184
+ return { images, skipped };
10185
+ }
10186
+ async function encryptPdf(bytes, userPassword, ownerPassword) {
10187
+ if (!userPassword)
10188
+ throw new Error("a non-empty user password is required");
10189
+ const { doc } = await openDoc(bytes);
10190
+ const opts = `encrypt=aes-256,user-password=${userPassword},owner-password=${ownerPassword || userPassword}`;
10191
+ return doc.saveToBuffer(opts).asUint8Array();
10192
+ }
10193
+ async function pdfNeedsPassword(bytes) {
10194
+ const mupdf = await loadMupdf();
10195
+ const doc = mupdf.Document.openDocument(bytes, "application/pdf");
10196
+ return doc.needsPassword();
10197
+ }
10198
+ async function decryptPdf(bytes, password) {
10199
+ const mupdf = await loadMupdf();
10200
+ const doc = mupdf.Document.openDocument(bytes, "application/pdf");
10201
+ if (doc.needsPassword()) {
10202
+ if (doc.authenticatePassword(password) === 0)
10203
+ throw new Error("wrong password");
10204
+ }
10205
+ if (doc.countPages() === 0)
10206
+ throw new Error("PDF has no readable pages (corrupt or empty)");
10207
+ return doc.saveToBuffer("encrypt=none").asUint8Array();
10208
+ }
10209
+ var import_node_path, import_node_url, _mupdf, MATH_CHARS;
10210
+ var init_pdf_extract = __esm({
10211
+ "packages/core/dist/document/pdf-extract.js"() {
10212
+ "use strict";
10213
+ import_node_path = require("node:path");
10214
+ import_node_url = require("node:url");
10215
+ init_pdf_encrypted();
10216
+ _mupdf = null;
10217
+ MATH_CHARS = /[=∑∫√≤≥≠±∞πθλμσΩ×÷∂∇→←↔∈∉⊂⊃∀∃]/g;
9823
10218
  }
9824
10219
  });
9825
10220
 
@@ -12239,11 +12634,11 @@ var require_PDFName = __commonJS({
12239
12634
  };
12240
12635
  var ENFORCER = {};
12241
12636
  var pool = /* @__PURE__ */ new Map();
12242
- var PDFName = (
12637
+ var PDFName2 = (
12243
12638
  /** @class */
12244
12639
  (function(_super) {
12245
- tslib_1.__extends(PDFName2, _super);
12246
- function PDFName2(enforcer, name) {
12640
+ tslib_1.__extends(PDFName3, _super);
12641
+ function PDFName3(enforcer, name) {
12247
12642
  var _this = this;
12248
12643
  if (enforcer !== ENFORCER)
12249
12644
  throw new errors_1.PrivateConstructorError("PDFName");
@@ -12257,7 +12652,7 @@ var require_PDFName = __commonJS({
12257
12652
  _this.encodedName = encodedName;
12258
12653
  return _this;
12259
12654
  }
12260
- PDFName2.prototype.asBytes = function() {
12655
+ PDFName3.prototype.asBytes = function() {
12261
12656
  var bytes = [];
12262
12657
  var hex = "";
12263
12658
  var escaped = false;
@@ -12289,67 +12684,67 @@ var require_PDFName = __commonJS({
12289
12684
  }
12290
12685
  return new Uint8Array(bytes);
12291
12686
  };
12292
- PDFName2.prototype.decodeText = function() {
12687
+ PDFName3.prototype.decodeText = function() {
12293
12688
  var bytes = this.asBytes();
12294
12689
  return String.fromCharCode.apply(String, Array.from(bytes));
12295
12690
  };
12296
- PDFName2.prototype.asString = function() {
12691
+ PDFName3.prototype.asString = function() {
12297
12692
  return this.encodedName;
12298
12693
  };
12299
- PDFName2.prototype.value = function() {
12694
+ PDFName3.prototype.value = function() {
12300
12695
  return this.encodedName;
12301
12696
  };
12302
- PDFName2.prototype.clone = function() {
12697
+ PDFName3.prototype.clone = function() {
12303
12698
  return this;
12304
12699
  };
12305
- PDFName2.prototype.toString = function() {
12700
+ PDFName3.prototype.toString = function() {
12306
12701
  return this.encodedName;
12307
12702
  };
12308
- PDFName2.prototype.sizeInBytes = function() {
12703
+ PDFName3.prototype.sizeInBytes = function() {
12309
12704
  return this.encodedName.length;
12310
12705
  };
12311
- PDFName2.prototype.copyBytesInto = function(buffer, offset) {
12706
+ PDFName3.prototype.copyBytesInto = function(buffer, offset) {
12312
12707
  offset += utils_1.copyStringIntoBuffer(this.encodedName, buffer, offset);
12313
12708
  return this.encodedName.length;
12314
12709
  };
12315
- PDFName2.of = function(name) {
12710
+ PDFName3.of = function(name) {
12316
12711
  var decodedValue = decodeName(name);
12317
12712
  var instance = pool.get(decodedValue);
12318
12713
  if (!instance) {
12319
- instance = new PDFName2(ENFORCER, decodedValue);
12714
+ instance = new PDFName3(ENFORCER, decodedValue);
12320
12715
  pool.set(decodedValue, instance);
12321
12716
  }
12322
12717
  return instance;
12323
12718
  };
12324
- PDFName2.Length = PDFName2.of("Length");
12325
- PDFName2.FlateDecode = PDFName2.of("FlateDecode");
12326
- PDFName2.Resources = PDFName2.of("Resources");
12327
- PDFName2.Font = PDFName2.of("Font");
12328
- PDFName2.XObject = PDFName2.of("XObject");
12329
- PDFName2.ExtGState = PDFName2.of("ExtGState");
12330
- PDFName2.Contents = PDFName2.of("Contents");
12331
- PDFName2.Type = PDFName2.of("Type");
12332
- PDFName2.Parent = PDFName2.of("Parent");
12333
- PDFName2.MediaBox = PDFName2.of("MediaBox");
12334
- PDFName2.Page = PDFName2.of("Page");
12335
- PDFName2.Annots = PDFName2.of("Annots");
12336
- PDFName2.TrimBox = PDFName2.of("TrimBox");
12337
- PDFName2.ArtBox = PDFName2.of("ArtBox");
12338
- PDFName2.BleedBox = PDFName2.of("BleedBox");
12339
- PDFName2.CropBox = PDFName2.of("CropBox");
12340
- PDFName2.Rotate = PDFName2.of("Rotate");
12341
- PDFName2.Title = PDFName2.of("Title");
12342
- PDFName2.Author = PDFName2.of("Author");
12343
- PDFName2.Subject = PDFName2.of("Subject");
12344
- PDFName2.Creator = PDFName2.of("Creator");
12345
- PDFName2.Keywords = PDFName2.of("Keywords");
12346
- PDFName2.Producer = PDFName2.of("Producer");
12347
- PDFName2.CreationDate = PDFName2.of("CreationDate");
12348
- PDFName2.ModDate = PDFName2.of("ModDate");
12349
- return PDFName2;
12719
+ PDFName3.Length = PDFName3.of("Length");
12720
+ PDFName3.FlateDecode = PDFName3.of("FlateDecode");
12721
+ PDFName3.Resources = PDFName3.of("Resources");
12722
+ PDFName3.Font = PDFName3.of("Font");
12723
+ PDFName3.XObject = PDFName3.of("XObject");
12724
+ PDFName3.ExtGState = PDFName3.of("ExtGState");
12725
+ PDFName3.Contents = PDFName3.of("Contents");
12726
+ PDFName3.Type = PDFName3.of("Type");
12727
+ PDFName3.Parent = PDFName3.of("Parent");
12728
+ PDFName3.MediaBox = PDFName3.of("MediaBox");
12729
+ PDFName3.Page = PDFName3.of("Page");
12730
+ PDFName3.Annots = PDFName3.of("Annots");
12731
+ PDFName3.TrimBox = PDFName3.of("TrimBox");
12732
+ PDFName3.ArtBox = PDFName3.of("ArtBox");
12733
+ PDFName3.BleedBox = PDFName3.of("BleedBox");
12734
+ PDFName3.CropBox = PDFName3.of("CropBox");
12735
+ PDFName3.Rotate = PDFName3.of("Rotate");
12736
+ PDFName3.Title = PDFName3.of("Title");
12737
+ PDFName3.Author = PDFName3.of("Author");
12738
+ PDFName3.Subject = PDFName3.of("Subject");
12739
+ PDFName3.Creator = PDFName3.of("Creator");
12740
+ PDFName3.Keywords = PDFName3.of("Keywords");
12741
+ PDFName3.Producer = PDFName3.of("Producer");
12742
+ PDFName3.CreationDate = PDFName3.of("CreationDate");
12743
+ PDFName3.ModDate = PDFName3.of("ModDate");
12744
+ return PDFName3;
12350
12745
  })(PDFObject_1.default)
12351
12746
  );
12352
- exports2.default = PDFName;
12747
+ exports2.default = PDFName2;
12353
12748
  }
12354
12749
  });
12355
12750
 
@@ -12404,29 +12799,29 @@ var require_PDFDict = __commonJS({
12404
12799
  var PDFNull_1 = tslib_1.__importDefault(require_PDFNull());
12405
12800
  var PDFObject_1 = tslib_1.__importDefault(require_PDFObject());
12406
12801
  var CharCodes_1 = tslib_1.__importDefault(require_CharCodes());
12407
- var PDFDict = (
12802
+ var PDFDict2 = (
12408
12803
  /** @class */
12409
12804
  (function(_super) {
12410
- tslib_1.__extends(PDFDict2, _super);
12411
- function PDFDict2(map, context) {
12805
+ tslib_1.__extends(PDFDict3, _super);
12806
+ function PDFDict3(map, context) {
12412
12807
  var _this = _super.call(this) || this;
12413
12808
  _this.dict = map;
12414
12809
  _this.context = context;
12415
12810
  return _this;
12416
12811
  }
12417
- PDFDict2.prototype.keys = function() {
12812
+ PDFDict3.prototype.keys = function() {
12418
12813
  return Array.from(this.dict.keys());
12419
12814
  };
12420
- PDFDict2.prototype.values = function() {
12815
+ PDFDict3.prototype.values = function() {
12421
12816
  return Array.from(this.dict.values());
12422
12817
  };
12423
- PDFDict2.prototype.entries = function() {
12818
+ PDFDict3.prototype.entries = function() {
12424
12819
  return Array.from(this.dict.entries());
12425
12820
  };
12426
- PDFDict2.prototype.set = function(key, value) {
12821
+ PDFDict3.prototype.set = function(key, value) {
12427
12822
  this.dict.set(key, value);
12428
12823
  };
12429
- PDFDict2.prototype.get = function(key, preservePDFNull) {
12824
+ PDFDict3.prototype.get = function(key, preservePDFNull) {
12430
12825
  if (preservePDFNull === void 0) {
12431
12826
  preservePDFNull = false;
12432
12827
  }
@@ -12435,11 +12830,11 @@ var require_PDFDict = __commonJS({
12435
12830
  return void 0;
12436
12831
  return value;
12437
12832
  };
12438
- PDFDict2.prototype.has = function(key) {
12833
+ PDFDict3.prototype.has = function(key) {
12439
12834
  var value = this.dict.get(key);
12440
12835
  return value !== void 0 && value !== PDFNull_1.default;
12441
12836
  };
12442
- PDFDict2.prototype.lookupMaybe = function(key) {
12837
+ PDFDict3.prototype.lookupMaybe = function(key) {
12443
12838
  var _a;
12444
12839
  var types = [];
12445
12840
  for (var _i = 1; _i < arguments.length; _i++) {
@@ -12451,7 +12846,7 @@ var require_PDFDict = __commonJS({
12451
12846
  return void 0;
12452
12847
  return value;
12453
12848
  };
12454
- PDFDict2.prototype.lookup = function(key) {
12849
+ PDFDict3.prototype.lookup = function(key) {
12455
12850
  var _a;
12456
12851
  var types = [];
12457
12852
  for (var _i = 1; _i < arguments.length; _i++) {
@@ -12463,13 +12858,13 @@ var require_PDFDict = __commonJS({
12463
12858
  return void 0;
12464
12859
  return value;
12465
12860
  };
12466
- PDFDict2.prototype.delete = function(key) {
12861
+ PDFDict3.prototype.delete = function(key) {
12467
12862
  return this.dict.delete(key);
12468
12863
  };
12469
- PDFDict2.prototype.asMap = function() {
12864
+ PDFDict3.prototype.asMap = function() {
12470
12865
  return new Map(this.dict);
12471
12866
  };
12472
- PDFDict2.prototype.uniqueKey = function(tag) {
12867
+ PDFDict3.prototype.uniqueKey = function(tag) {
12473
12868
  if (tag === void 0) {
12474
12869
  tag = "";
12475
12870
  }
@@ -12480,8 +12875,8 @@ var require_PDFDict = __commonJS({
12480
12875
  }
12481
12876
  return key;
12482
12877
  };
12483
- PDFDict2.prototype.clone = function(context) {
12484
- var clone = PDFDict2.withContext(context || this.context);
12878
+ PDFDict3.prototype.clone = function(context) {
12879
+ var clone = PDFDict3.withContext(context || this.context);
12485
12880
  var entries = this.entries();
12486
12881
  for (var idx = 0, len = entries.length; idx < len; idx++) {
12487
12882
  var _a = entries[idx], key = _a[0], value = _a[1];
@@ -12489,7 +12884,7 @@ var require_PDFDict = __commonJS({
12489
12884
  }
12490
12885
  return clone;
12491
12886
  };
12492
- PDFDict2.prototype.toString = function() {
12887
+ PDFDict3.prototype.toString = function() {
12493
12888
  var dictString = "<<\n";
12494
12889
  var entries = this.entries();
12495
12890
  for (var idx = 0, len = entries.length; idx < len; idx++) {
@@ -12499,7 +12894,7 @@ var require_PDFDict = __commonJS({
12499
12894
  dictString += ">>";
12500
12895
  return dictString;
12501
12896
  };
12502
- PDFDict2.prototype.sizeInBytes = function() {
12897
+ PDFDict3.prototype.sizeInBytes = function() {
12503
12898
  var size = 5;
12504
12899
  var entries = this.entries();
12505
12900
  for (var idx = 0, len = entries.length; idx < len; idx++) {
@@ -12508,7 +12903,7 @@ var require_PDFDict = __commonJS({
12508
12903
  }
12509
12904
  return size;
12510
12905
  };
12511
- PDFDict2.prototype.copyBytesInto = function(buffer, offset) {
12906
+ PDFDict3.prototype.copyBytesInto = function(buffer, offset) {
12512
12907
  var initialOffset = offset;
12513
12908
  buffer[offset++] = CharCodes_1.default.LessThan;
12514
12909
  buffer[offset++] = CharCodes_1.default.LessThan;
@@ -12525,16 +12920,16 @@ var require_PDFDict = __commonJS({
12525
12920
  buffer[offset++] = CharCodes_1.default.GreaterThan;
12526
12921
  return offset - initialOffset;
12527
12922
  };
12528
- PDFDict2.withContext = function(context) {
12529
- return new PDFDict2(/* @__PURE__ */ new Map(), context);
12923
+ PDFDict3.withContext = function(context) {
12924
+ return new PDFDict3(/* @__PURE__ */ new Map(), context);
12530
12925
  };
12531
- PDFDict2.fromMapWithContext = function(map, context) {
12532
- return new PDFDict2(map, context);
12926
+ PDFDict3.fromMapWithContext = function(map, context) {
12927
+ return new PDFDict3(map, context);
12533
12928
  };
12534
- return PDFDict2;
12929
+ return PDFDict3;
12535
12930
  })(PDFObject_1.default)
12536
12931
  );
12537
- exports2.default = PDFDict;
12932
+ exports2.default = PDFDict2;
12538
12933
  }
12539
12934
  });
12540
12935
 
@@ -12549,36 +12944,36 @@ var require_PDFStream = __commonJS({
12549
12944
  var PDFNumber_1 = tslib_1.__importDefault(require_PDFNumber());
12550
12945
  var PDFObject_1 = tslib_1.__importDefault(require_PDFObject());
12551
12946
  var CharCodes_1 = tslib_1.__importDefault(require_CharCodes());
12552
- var PDFStream = (
12947
+ var PDFStream2 = (
12553
12948
  /** @class */
12554
12949
  (function(_super) {
12555
- tslib_1.__extends(PDFStream2, _super);
12556
- function PDFStream2(dict) {
12950
+ tslib_1.__extends(PDFStream3, _super);
12951
+ function PDFStream3(dict) {
12557
12952
  var _this = _super.call(this) || this;
12558
12953
  _this.dict = dict;
12559
12954
  return _this;
12560
12955
  }
12561
- PDFStream2.prototype.clone = function(_context) {
12956
+ PDFStream3.prototype.clone = function(_context) {
12562
12957
  throw new errors_1.MethodNotImplementedError(this.constructor.name, "clone");
12563
12958
  };
12564
- PDFStream2.prototype.getContentsString = function() {
12959
+ PDFStream3.prototype.getContentsString = function() {
12565
12960
  throw new errors_1.MethodNotImplementedError(this.constructor.name, "getContentsString");
12566
12961
  };
12567
- PDFStream2.prototype.getContents = function() {
12962
+ PDFStream3.prototype.getContents = function() {
12568
12963
  throw new errors_1.MethodNotImplementedError(this.constructor.name, "getContents");
12569
12964
  };
12570
- PDFStream2.prototype.getContentsSize = function() {
12965
+ PDFStream3.prototype.getContentsSize = function() {
12571
12966
  throw new errors_1.MethodNotImplementedError(this.constructor.name, "getContentsSize");
12572
12967
  };
12573
- PDFStream2.prototype.updateDict = function() {
12968
+ PDFStream3.prototype.updateDict = function() {
12574
12969
  var contentsSize = this.getContentsSize();
12575
12970
  this.dict.set(PDFName_1.default.Length, PDFNumber_1.default.of(contentsSize));
12576
12971
  };
12577
- PDFStream2.prototype.sizeInBytes = function() {
12972
+ PDFStream3.prototype.sizeInBytes = function() {
12578
12973
  this.updateDict();
12579
12974
  return this.dict.sizeInBytes() + this.getContentsSize() + 18;
12580
12975
  };
12581
- PDFStream2.prototype.toString = function() {
12976
+ PDFStream3.prototype.toString = function() {
12582
12977
  this.updateDict();
12583
12978
  var streamString = this.dict.toString();
12584
12979
  streamString += "\nstream\n";
@@ -12586,7 +12981,7 @@ var require_PDFStream = __commonJS({
12586
12981
  streamString += "\nendstream";
12587
12982
  return streamString;
12588
12983
  };
12589
- PDFStream2.prototype.copyBytesInto = function(buffer, offset) {
12984
+ PDFStream3.prototype.copyBytesInto = function(buffer, offset) {
12590
12985
  this.updateDict();
12591
12986
  var initialOffset = offset;
12592
12987
  offset += this.dict.copyBytesInto(buffer, offset);
@@ -12614,10 +13009,10 @@ var require_PDFStream = __commonJS({
12614
13009
  buffer[offset++] = CharCodes_1.default.m;
12615
13010
  return offset - initialOffset;
12616
13011
  };
12617
- return PDFStream2;
13012
+ return PDFStream3;
12618
13013
  })(PDFObject_1.default)
12619
13014
  );
12620
- exports2.default = PDFStream;
13015
+ exports2.default = PDFStream2;
12621
13016
  }
12622
13017
  });
12623
13018
 
@@ -12629,37 +13024,37 @@ var require_PDFRawStream = __commonJS({
12629
13024
  var tslib_1 = (init_tslib_es6(), __toCommonJS(tslib_es6_exports));
12630
13025
  var PDFStream_1 = tslib_1.__importDefault(require_PDFStream());
12631
13026
  var utils_1 = require_utils3();
12632
- var PDFRawStream = (
13027
+ var PDFRawStream2 = (
12633
13028
  /** @class */
12634
13029
  (function(_super) {
12635
- tslib_1.__extends(PDFRawStream2, _super);
12636
- function PDFRawStream2(dict, contents) {
13030
+ tslib_1.__extends(PDFRawStream3, _super);
13031
+ function PDFRawStream3(dict, contents) {
12637
13032
  var _this = _super.call(this, dict) || this;
12638
13033
  _this.contents = contents;
12639
13034
  return _this;
12640
13035
  }
12641
- PDFRawStream2.prototype.asUint8Array = function() {
13036
+ PDFRawStream3.prototype.asUint8Array = function() {
12642
13037
  return this.contents.slice();
12643
13038
  };
12644
- PDFRawStream2.prototype.clone = function(context) {
12645
- return PDFRawStream2.of(this.dict.clone(context), this.contents.slice());
13039
+ PDFRawStream3.prototype.clone = function(context) {
13040
+ return PDFRawStream3.of(this.dict.clone(context), this.contents.slice());
12646
13041
  };
12647
- PDFRawStream2.prototype.getContentsString = function() {
13042
+ PDFRawStream3.prototype.getContentsString = function() {
12648
13043
  return utils_1.arrayAsString(this.contents);
12649
13044
  };
12650
- PDFRawStream2.prototype.getContents = function() {
13045
+ PDFRawStream3.prototype.getContents = function() {
12651
13046
  return this.contents;
12652
13047
  };
12653
- PDFRawStream2.prototype.getContentsSize = function() {
13048
+ PDFRawStream3.prototype.getContentsSize = function() {
12654
13049
  return this.contents.length;
12655
13050
  };
12656
- PDFRawStream2.of = function(dict, contents) {
12657
- return new PDFRawStream2(dict, contents);
13051
+ PDFRawStream3.of = function(dict, contents) {
13052
+ return new PDFRawStream3(dict, contents);
12658
13053
  };
12659
- return PDFRawStream2;
13054
+ return PDFRawStream3;
12660
13055
  })(PDFStream_1.default)
12661
13056
  );
12662
- exports2.default = PDFRawStream;
13057
+ exports2.default = PDFRawStream2;
12663
13058
  }
12664
13059
  });
12665
13060
 
@@ -12674,11 +13069,11 @@ var require_PDFRef = __commonJS({
12674
13069
  var utils_1 = require_utils3();
12675
13070
  var ENFORCER = {};
12676
13071
  var pool = /* @__PURE__ */ new Map();
12677
- var PDFRef = (
13072
+ var PDFRef2 = (
12678
13073
  /** @class */
12679
13074
  (function(_super) {
12680
- tslib_1.__extends(PDFRef2, _super);
12681
- function PDFRef2(enforcer, objectNumber, generationNumber) {
13075
+ tslib_1.__extends(PDFRef3, _super);
13076
+ function PDFRef3(enforcer, objectNumber, generationNumber) {
12682
13077
  var _this = this;
12683
13078
  if (enforcer !== ENFORCER)
12684
13079
  throw new errors_1.PrivateConstructorError("PDFRef");
@@ -12688,35 +13083,35 @@ var require_PDFRef = __commonJS({
12688
13083
  _this.tag = objectNumber + " " + generationNumber + " R";
12689
13084
  return _this;
12690
13085
  }
12691
- PDFRef2.prototype.clone = function() {
13086
+ PDFRef3.prototype.clone = function() {
12692
13087
  return this;
12693
13088
  };
12694
- PDFRef2.prototype.toString = function() {
13089
+ PDFRef3.prototype.toString = function() {
12695
13090
  return this.tag;
12696
13091
  };
12697
- PDFRef2.prototype.sizeInBytes = function() {
13092
+ PDFRef3.prototype.sizeInBytes = function() {
12698
13093
  return this.tag.length;
12699
13094
  };
12700
- PDFRef2.prototype.copyBytesInto = function(buffer, offset) {
13095
+ PDFRef3.prototype.copyBytesInto = function(buffer, offset) {
12701
13096
  offset += utils_1.copyStringIntoBuffer(this.tag, buffer, offset);
12702
13097
  return this.tag.length;
12703
13098
  };
12704
- PDFRef2.of = function(objectNumber, generationNumber) {
13099
+ PDFRef3.of = function(objectNumber, generationNumber) {
12705
13100
  if (generationNumber === void 0) {
12706
13101
  generationNumber = 0;
12707
13102
  }
12708
13103
  var tag = objectNumber + " " + generationNumber + " R";
12709
13104
  var instance = pool.get(tag);
12710
13105
  if (!instance) {
12711
- instance = new PDFRef2(ENFORCER, objectNumber, generationNumber);
13106
+ instance = new PDFRef3(ENFORCER, objectNumber, generationNumber);
12712
13107
  pool.set(tag, instance);
12713
13108
  }
12714
13109
  return instance;
12715
13110
  };
12716
- return PDFRef2;
13111
+ return PDFRef3;
12717
13112
  })(PDFObject_1.default)
12718
13113
  );
12719
- exports2.default = PDFRef;
13114
+ exports2.default = PDFRef2;
12720
13115
  }
12721
13116
  });
12722
13117
 
@@ -18354,14 +18749,14 @@ var require_decode = __commonJS({
18354
18749
  var LZWStream_1 = tslib_1.__importDefault(require_LZWStream());
18355
18750
  var RunLengthStream_1 = tslib_1.__importDefault(require_RunLengthStream());
18356
18751
  var Stream_1 = tslib_1.__importDefault(require_Stream());
18357
- var decodeStream = function(stream, encoding, params) {
18752
+ var decodeStream = function(stream, encoding, params2) {
18358
18753
  if (encoding === PDFName_1.default.of("FlateDecode")) {
18359
18754
  return new FlateStream_1.default(stream);
18360
18755
  }
18361
18756
  if (encoding === PDFName_1.default.of("LZWDecode")) {
18362
18757
  var earlyChange = 1;
18363
- if (params instanceof PDFDict_1.default) {
18364
- var EarlyChange = params.lookup(PDFName_1.default.of("EarlyChange"));
18758
+ if (params2 instanceof PDFDict_1.default) {
18759
+ var EarlyChange = params2.lookup(PDFName_1.default.of("EarlyChange"));
18365
18760
  if (EarlyChange instanceof PDFNumber_1.default) {
18366
18761
  earlyChange = EarlyChange.asNumber();
18367
18762
  }
@@ -22243,11 +22638,11 @@ var require_svgPath = __commonJS({
22243
22638
  var args = [];
22244
22639
  var curArg = "";
22245
22640
  var foundDecimal = false;
22246
- var params = 0;
22641
+ var params2 = 0;
22247
22642
  for (var _i = 0, path_1 = path; _i < path_1.length; _i++) {
22248
22643
  var c = path_1[_i];
22249
22644
  if (parameters.has(c)) {
22250
- params = parameters.get(c);
22645
+ params2 = parameters.get(c);
22251
22646
  if (cmd) {
22252
22647
  if (curArg.length > 0) {
22253
22648
  args[args.length] = +curArg;
@@ -22262,7 +22657,7 @@ var require_svgPath = __commonJS({
22262
22657
  if (curArg.length === 0) {
22263
22658
  continue;
22264
22659
  }
22265
- if (args.length === params) {
22660
+ if (args.length === params2) {
22266
22661
  ret[ret.length] = { cmd, args };
22267
22662
  args = [+curArg];
22268
22663
  if (cmd === "M") {
@@ -22284,7 +22679,7 @@ var require_svgPath = __commonJS({
22284
22679
  }
22285
22680
  }
22286
22681
  if (curArg.length > 0) {
22287
- if (args.length === params) {
22682
+ if (args.length === params2) {
22288
22683
  ret[ret.length] = { cmd, args };
22289
22684
  args = [+curArg];
22290
22685
  if (cmd === "M") {
@@ -25965,10 +26360,10 @@ var require_PDFDocument = __commonJS({
25965
26360
  var PDFEmbeddedFile_1 = tslib_1.__importDefault(require_PDFEmbeddedFile());
25966
26361
  var PDFJavaScript_1 = tslib_1.__importDefault(require_PDFJavaScript());
25967
26362
  var JavaScriptEmbedder_1 = tslib_1.__importDefault(require_JavaScriptEmbedder());
25968
- var PDFDocument2 = (
26363
+ var PDFDocument3 = (
25969
26364
  /** @class */
25970
26365
  (function() {
25971
- function PDFDocument3(context, ignoreEncryption, updateMetadata) {
26366
+ function PDFDocument4(context, ignoreEncryption, updateMetadata) {
25972
26367
  var _this = this;
25973
26368
  this.defaultWordBreaks = [" "];
25974
26369
  this.computePages = function() {
@@ -26007,7 +26402,7 @@ var require_PDFDocument = __commonJS({
26007
26402
  if (updateMetadata)
26008
26403
  this.updateInfoDict();
26009
26404
  }
26010
- PDFDocument3.load = function(pdf, options) {
26405
+ PDFDocument4.load = function(pdf, options) {
26011
26406
  if (options === void 0) {
26012
26407
  options = {};
26013
26408
  }
@@ -26025,12 +26420,12 @@ var require_PDFDocument = __commonJS({
26025
26420
  return [4, core_1.PDFParser.forBytesWithOptions(bytes, parseSpeed, throwOnInvalidObject, capNumbers).parseDocument()];
26026
26421
  case 1:
26027
26422
  context = _f.sent();
26028
- return [2, new PDFDocument3(context, ignoreEncryption, updateMetadata)];
26423
+ return [2, new PDFDocument4(context, ignoreEncryption, updateMetadata)];
26029
26424
  }
26030
26425
  });
26031
26426
  });
26032
26427
  };
26033
- PDFDocument3.create = function(options) {
26428
+ PDFDocument4.create = function(options) {
26034
26429
  if (options === void 0) {
26035
26430
  options = {};
26036
26431
  }
@@ -26043,14 +26438,14 @@ var require_PDFDocument = __commonJS({
26043
26438
  pageTreeRef = context.register(pageTree);
26044
26439
  catalog = core_1.PDFCatalog.withContextAndPages(context, pageTreeRef);
26045
26440
  context.trailerInfo.Root = context.register(catalog);
26046
- return [2, new PDFDocument3(context, false, updateMetadata)];
26441
+ return [2, new PDFDocument4(context, false, updateMetadata)];
26047
26442
  });
26048
26443
  });
26049
26444
  };
26050
- PDFDocument3.prototype.registerFontkit = function(fontkit) {
26445
+ PDFDocument4.prototype.registerFontkit = function(fontkit) {
26051
26446
  this.fontkit = fontkit;
26052
26447
  };
26053
- PDFDocument3.prototype.getForm = function() {
26448
+ PDFDocument4.prototype.getForm = function() {
26054
26449
  var form = this.formCache.access();
26055
26450
  if (form.hasXFA()) {
26056
26451
  console.warn("Removing XFA form data as pdf-lib does not support reading or writing XFA");
@@ -26058,63 +26453,63 @@ var require_PDFDocument = __commonJS({
26058
26453
  }
26059
26454
  return form;
26060
26455
  };
26061
- PDFDocument3.prototype.getTitle = function() {
26456
+ PDFDocument4.prototype.getTitle = function() {
26062
26457
  var title = this.getInfoDict().lookup(core_1.PDFName.Title);
26063
26458
  if (!title)
26064
26459
  return void 0;
26065
26460
  assertIsLiteralOrHexString(title);
26066
26461
  return title.decodeText();
26067
26462
  };
26068
- PDFDocument3.prototype.getAuthor = function() {
26463
+ PDFDocument4.prototype.getAuthor = function() {
26069
26464
  var author = this.getInfoDict().lookup(core_1.PDFName.Author);
26070
26465
  if (!author)
26071
26466
  return void 0;
26072
26467
  assertIsLiteralOrHexString(author);
26073
26468
  return author.decodeText();
26074
26469
  };
26075
- PDFDocument3.prototype.getSubject = function() {
26470
+ PDFDocument4.prototype.getSubject = function() {
26076
26471
  var subject = this.getInfoDict().lookup(core_1.PDFName.Subject);
26077
26472
  if (!subject)
26078
26473
  return void 0;
26079
26474
  assertIsLiteralOrHexString(subject);
26080
26475
  return subject.decodeText();
26081
26476
  };
26082
- PDFDocument3.prototype.getKeywords = function() {
26477
+ PDFDocument4.prototype.getKeywords = function() {
26083
26478
  var keywords = this.getInfoDict().lookup(core_1.PDFName.Keywords);
26084
26479
  if (!keywords)
26085
26480
  return void 0;
26086
26481
  assertIsLiteralOrHexString(keywords);
26087
26482
  return keywords.decodeText();
26088
26483
  };
26089
- PDFDocument3.prototype.getCreator = function() {
26484
+ PDFDocument4.prototype.getCreator = function() {
26090
26485
  var creator = this.getInfoDict().lookup(core_1.PDFName.Creator);
26091
26486
  if (!creator)
26092
26487
  return void 0;
26093
26488
  assertIsLiteralOrHexString(creator);
26094
26489
  return creator.decodeText();
26095
26490
  };
26096
- PDFDocument3.prototype.getProducer = function() {
26491
+ PDFDocument4.prototype.getProducer = function() {
26097
26492
  var producer = this.getInfoDict().lookup(core_1.PDFName.Producer);
26098
26493
  if (!producer)
26099
26494
  return void 0;
26100
26495
  assertIsLiteralOrHexString(producer);
26101
26496
  return producer.decodeText();
26102
26497
  };
26103
- PDFDocument3.prototype.getCreationDate = function() {
26498
+ PDFDocument4.prototype.getCreationDate = function() {
26104
26499
  var creationDate = this.getInfoDict().lookup(core_1.PDFName.CreationDate);
26105
26500
  if (!creationDate)
26106
26501
  return void 0;
26107
26502
  assertIsLiteralOrHexString(creationDate);
26108
26503
  return creationDate.decodeDate();
26109
26504
  };
26110
- PDFDocument3.prototype.getModificationDate = function() {
26505
+ PDFDocument4.prototype.getModificationDate = function() {
26111
26506
  var modificationDate = this.getInfoDict().lookup(core_1.PDFName.ModDate);
26112
26507
  if (!modificationDate)
26113
26508
  return void 0;
26114
26509
  assertIsLiteralOrHexString(modificationDate);
26115
26510
  return modificationDate.decodeDate();
26116
26511
  };
26117
- PDFDocument3.prototype.setTitle = function(title, options) {
26512
+ PDFDocument4.prototype.setTitle = function(title, options) {
26118
26513
  utils_1.assertIs(title, "title", ["string"]);
26119
26514
  var key = core_1.PDFName.of("Title");
26120
26515
  this.getInfoDict().set(key, core_1.PDFHexString.fromText(title));
@@ -26123,63 +26518,63 @@ var require_PDFDocument = __commonJS({
26123
26518
  prefs.setDisplayDocTitle(true);
26124
26519
  }
26125
26520
  };
26126
- PDFDocument3.prototype.setAuthor = function(author) {
26521
+ PDFDocument4.prototype.setAuthor = function(author) {
26127
26522
  utils_1.assertIs(author, "author", ["string"]);
26128
26523
  var key = core_1.PDFName.of("Author");
26129
26524
  this.getInfoDict().set(key, core_1.PDFHexString.fromText(author));
26130
26525
  };
26131
- PDFDocument3.prototype.setSubject = function(subject) {
26526
+ PDFDocument4.prototype.setSubject = function(subject) {
26132
26527
  utils_1.assertIs(subject, "author", ["string"]);
26133
26528
  var key = core_1.PDFName.of("Subject");
26134
26529
  this.getInfoDict().set(key, core_1.PDFHexString.fromText(subject));
26135
26530
  };
26136
- PDFDocument3.prototype.setKeywords = function(keywords) {
26531
+ PDFDocument4.prototype.setKeywords = function(keywords) {
26137
26532
  utils_1.assertIs(keywords, "keywords", [Array]);
26138
26533
  var key = core_1.PDFName.of("Keywords");
26139
26534
  this.getInfoDict().set(key, core_1.PDFHexString.fromText(keywords.join(" ")));
26140
26535
  };
26141
- PDFDocument3.prototype.setCreator = function(creator) {
26536
+ PDFDocument4.prototype.setCreator = function(creator) {
26142
26537
  utils_1.assertIs(creator, "creator", ["string"]);
26143
26538
  var key = core_1.PDFName.of("Creator");
26144
26539
  this.getInfoDict().set(key, core_1.PDFHexString.fromText(creator));
26145
26540
  };
26146
- PDFDocument3.prototype.setProducer = function(producer) {
26541
+ PDFDocument4.prototype.setProducer = function(producer) {
26147
26542
  utils_1.assertIs(producer, "creator", ["string"]);
26148
26543
  var key = core_1.PDFName.of("Producer");
26149
26544
  this.getInfoDict().set(key, core_1.PDFHexString.fromText(producer));
26150
26545
  };
26151
- PDFDocument3.prototype.setLanguage = function(language) {
26546
+ PDFDocument4.prototype.setLanguage = function(language) {
26152
26547
  utils_1.assertIs(language, "language", ["string"]);
26153
26548
  var key = core_1.PDFName.of("Lang");
26154
26549
  this.catalog.set(key, core_1.PDFString.of(language));
26155
26550
  };
26156
- PDFDocument3.prototype.setCreationDate = function(creationDate) {
26551
+ PDFDocument4.prototype.setCreationDate = function(creationDate) {
26157
26552
  utils_1.assertIs(creationDate, "creationDate", [[Date, "Date"]]);
26158
26553
  var key = core_1.PDFName.of("CreationDate");
26159
26554
  this.getInfoDict().set(key, core_1.PDFString.fromDate(creationDate));
26160
26555
  };
26161
- PDFDocument3.prototype.setModificationDate = function(modificationDate) {
26556
+ PDFDocument4.prototype.setModificationDate = function(modificationDate) {
26162
26557
  utils_1.assertIs(modificationDate, "modificationDate", [[Date, "Date"]]);
26163
26558
  var key = core_1.PDFName.of("ModDate");
26164
26559
  this.getInfoDict().set(key, core_1.PDFString.fromDate(modificationDate));
26165
26560
  };
26166
- PDFDocument3.prototype.getPageCount = function() {
26561
+ PDFDocument4.prototype.getPageCount = function() {
26167
26562
  if (this.pageCount === void 0)
26168
26563
  this.pageCount = this.getPages().length;
26169
26564
  return this.pageCount;
26170
26565
  };
26171
- PDFDocument3.prototype.getPages = function() {
26566
+ PDFDocument4.prototype.getPages = function() {
26172
26567
  return this.pageCache.access();
26173
26568
  };
26174
- PDFDocument3.prototype.getPage = function(index) {
26569
+ PDFDocument4.prototype.getPage = function(index) {
26175
26570
  var pages = this.getPages();
26176
26571
  utils_1.assertRange(index, "index", 0, pages.length - 1);
26177
26572
  return pages[index];
26178
26573
  };
26179
- PDFDocument3.prototype.getPageIndices = function() {
26574
+ PDFDocument4.prototype.getPageIndices = function() {
26180
26575
  return utils_1.range(0, this.getPageCount());
26181
26576
  };
26182
- PDFDocument3.prototype.removePage = function(index) {
26577
+ PDFDocument4.prototype.removePage = function(index) {
26183
26578
  var pageCount = this.getPageCount();
26184
26579
  if (this.pageCount === 0)
26185
26580
  throw new errors_1.RemovePageFromEmptyDocumentError();
@@ -26187,11 +26582,11 @@ var require_PDFDocument = __commonJS({
26187
26582
  this.catalog.removeLeafNode(index);
26188
26583
  this.pageCount = pageCount - 1;
26189
26584
  };
26190
- PDFDocument3.prototype.addPage = function(page) {
26585
+ PDFDocument4.prototype.addPage = function(page) {
26191
26586
  utils_1.assertIs(page, "page", ["undefined", [PDFPage_1.default, "PDFPage"], Array]);
26192
26587
  return this.insertPage(this.getPageCount(), page);
26193
26588
  };
26194
- PDFDocument3.prototype.insertPage = function(index, page) {
26589
+ PDFDocument4.prototype.insertPage = function(index, page) {
26195
26590
  var pageCount = this.getPageCount();
26196
26591
  utils_1.assertRange(index, "index", 0, pageCount);
26197
26592
  utils_1.assertIs(page, "page", ["undefined", [PDFPage_1.default, "PDFPage"], Array]);
@@ -26209,13 +26604,13 @@ var require_PDFDocument = __commonJS({
26209
26604
  this.pageCount = pageCount + 1;
26210
26605
  return page;
26211
26606
  };
26212
- PDFDocument3.prototype.copyPages = function(srcDoc, indices) {
26607
+ PDFDocument4.prototype.copyPages = function(srcDoc, indices) {
26213
26608
  return tslib_1.__awaiter(this, void 0, void 0, function() {
26214
26609
  var copier, srcPages, copiedPages, idx, len, srcPage, copiedPage, ref;
26215
26610
  return tslib_1.__generator(this, function(_a) {
26216
26611
  switch (_a.label) {
26217
26612
  case 0:
26218
- utils_1.assertIs(srcDoc, "srcDoc", [[PDFDocument3, "PDFDocument"]]);
26613
+ utils_1.assertIs(srcDoc, "srcDoc", [[PDFDocument4, "PDFDocument"]]);
26219
26614
  utils_1.assertIs(indices, "indices", [Array]);
26220
26615
  return [4, srcDoc.flush()];
26221
26616
  case 1:
@@ -26234,13 +26629,13 @@ var require_PDFDocument = __commonJS({
26234
26629
  });
26235
26630
  });
26236
26631
  };
26237
- PDFDocument3.prototype.copy = function() {
26632
+ PDFDocument4.prototype.copy = function() {
26238
26633
  return tslib_1.__awaiter(this, void 0, void 0, function() {
26239
26634
  var pdfCopy, contentPages, idx, len;
26240
26635
  return tslib_1.__generator(this, function(_a) {
26241
26636
  switch (_a.label) {
26242
26637
  case 0:
26243
- return [4, PDFDocument3.create()];
26638
+ return [4, PDFDocument4.create()];
26244
26639
  case 1:
26245
26640
  pdfCopy = _a.sent();
26246
26641
  return [4, pdfCopy.copyPages(this, this.getPageIndices())];
@@ -26276,7 +26671,7 @@ var require_PDFDocument = __commonJS({
26276
26671
  });
26277
26672
  });
26278
26673
  };
26279
- PDFDocument3.prototype.addJavaScript = function(name, script) {
26674
+ PDFDocument4.prototype.addJavaScript = function(name, script) {
26280
26675
  utils_1.assertIs(name, "name", ["string"]);
26281
26676
  utils_1.assertIs(script, "script", ["string"]);
26282
26677
  var embedder = JavaScriptEmbedder_1.default.for(script, name);
@@ -26284,7 +26679,7 @@ var require_PDFDocument = __commonJS({
26284
26679
  var javaScript = PDFJavaScript_1.default.of(ref, this, embedder);
26285
26680
  this.javaScripts.push(javaScript);
26286
26681
  };
26287
- PDFDocument3.prototype.attach = function(attachment, name, options) {
26682
+ PDFDocument4.prototype.attach = function(attachment, name, options) {
26288
26683
  if (options === void 0) {
26289
26684
  options = {};
26290
26685
  }
@@ -26312,7 +26707,7 @@ var require_PDFDocument = __commonJS({
26312
26707
  });
26313
26708
  });
26314
26709
  };
26315
- PDFDocument3.prototype.embedFont = function(font, options) {
26710
+ PDFDocument4.prototype.embedFont = function(font, options) {
26316
26711
  if (options === void 0) {
26317
26712
  options = {};
26318
26713
  }
@@ -26355,7 +26750,7 @@ var require_PDFDocument = __commonJS({
26355
26750
  });
26356
26751
  });
26357
26752
  };
26358
- PDFDocument3.prototype.embedStandardFont = function(font, customName) {
26753
+ PDFDocument4.prototype.embedStandardFont = function(font, customName) {
26359
26754
  utils_1.assertIs(font, "font", ["string"]);
26360
26755
  if (!utils_1.isStandardFont(font)) {
26361
26756
  throw new TypeError("`font` must be one of type `StandardFonts`");
@@ -26366,7 +26761,7 @@ var require_PDFDocument = __commonJS({
26366
26761
  this.fonts.push(pdfFont);
26367
26762
  return pdfFont;
26368
26763
  };
26369
- PDFDocument3.prototype.embedJpg = function(jpg) {
26764
+ PDFDocument4.prototype.embedJpg = function(jpg) {
26370
26765
  return tslib_1.__awaiter(this, void 0, void 0, function() {
26371
26766
  var bytes, embedder, ref, pdfImage;
26372
26767
  return tslib_1.__generator(this, function(_a) {
@@ -26385,7 +26780,7 @@ var require_PDFDocument = __commonJS({
26385
26780
  });
26386
26781
  });
26387
26782
  };
26388
- PDFDocument3.prototype.embedPng = function(png) {
26783
+ PDFDocument4.prototype.embedPng = function(png) {
26389
26784
  return tslib_1.__awaiter(this, void 0, void 0, function() {
26390
26785
  var bytes, embedder, ref, pdfImage;
26391
26786
  return tslib_1.__generator(this, function(_a) {
@@ -26404,7 +26799,7 @@ var require_PDFDocument = __commonJS({
26404
26799
  });
26405
26800
  });
26406
26801
  };
26407
- PDFDocument3.prototype.embedPdf = function(pdf, indices) {
26802
+ PDFDocument4.prototype.embedPdf = function(pdf, indices) {
26408
26803
  if (indices === void 0) {
26409
26804
  indices = [0];
26410
26805
  }
@@ -26417,14 +26812,14 @@ var require_PDFDocument = __commonJS({
26417
26812
  "string",
26418
26813
  Uint8Array,
26419
26814
  ArrayBuffer,
26420
- [PDFDocument3, "PDFDocument"]
26815
+ [PDFDocument4, "PDFDocument"]
26421
26816
  ]);
26422
26817
  utils_1.assertIs(indices, "indices", [Array]);
26423
- if (!(pdf instanceof PDFDocument3)) return [3, 1];
26818
+ if (!(pdf instanceof PDFDocument4)) return [3, 1];
26424
26819
  _a = pdf;
26425
26820
  return [3, 3];
26426
26821
  case 1:
26427
- return [4, PDFDocument3.load(pdf)];
26822
+ return [4, PDFDocument4.load(pdf)];
26428
26823
  case 2:
26429
26824
  _a = _b.sent();
26430
26825
  _b.label = 3;
@@ -26436,7 +26831,7 @@ var require_PDFDocument = __commonJS({
26436
26831
  });
26437
26832
  });
26438
26833
  };
26439
- PDFDocument3.prototype.embedPage = function(page, boundingBox, transformationMatrix) {
26834
+ PDFDocument4.prototype.embedPage = function(page, boundingBox, transformationMatrix) {
26440
26835
  return tslib_1.__awaiter(this, void 0, void 0, function() {
26441
26836
  var embeddedPage;
26442
26837
  return tslib_1.__generator(this, function(_a) {
@@ -26451,7 +26846,7 @@ var require_PDFDocument = __commonJS({
26451
26846
  });
26452
26847
  });
26453
26848
  };
26454
- PDFDocument3.prototype.embedPages = function(pages, boundingBoxes, transformationMatrices) {
26849
+ PDFDocument4.prototype.embedPages = function(pages, boundingBoxes, transformationMatrices) {
26455
26850
  if (boundingBoxes === void 0) {
26456
26851
  boundingBoxes = [];
26457
26852
  }
@@ -26501,7 +26896,7 @@ var require_PDFDocument = __commonJS({
26501
26896
  });
26502
26897
  });
26503
26898
  };
26504
- PDFDocument3.prototype.flush = function() {
26899
+ PDFDocument4.prototype.flush = function() {
26505
26900
  return tslib_1.__awaiter(this, void 0, void 0, function() {
26506
26901
  return tslib_1.__generator(this, function(_a) {
26507
26902
  switch (_a.label) {
@@ -26529,7 +26924,7 @@ var require_PDFDocument = __commonJS({
26529
26924
  });
26530
26925
  });
26531
26926
  };
26532
- PDFDocument3.prototype.save = function(options) {
26927
+ PDFDocument4.prototype.save = function(options) {
26533
26928
  if (options === void 0) {
26534
26929
  options = {};
26535
26930
  }
@@ -26559,7 +26954,7 @@ var require_PDFDocument = __commonJS({
26559
26954
  });
26560
26955
  });
26561
26956
  };
26562
- PDFDocument3.prototype.saveAsBase64 = function(options) {
26957
+ PDFDocument4.prototype.saveAsBase64 = function(options) {
26563
26958
  if (options === void 0) {
26564
26959
  options = {};
26565
26960
  }
@@ -26579,7 +26974,7 @@ var require_PDFDocument = __commonJS({
26579
26974
  });
26580
26975
  });
26581
26976
  };
26582
- PDFDocument3.prototype.findPageForAnnotationRef = function(ref) {
26977
+ PDFDocument4.prototype.findPageForAnnotationRef = function(ref) {
26583
26978
  var pages = this.getPages();
26584
26979
  for (var idx = 0, len = pages.length; idx < len; idx++) {
26585
26980
  var page = pages[idx];
@@ -26590,7 +26985,7 @@ var require_PDFDocument = __commonJS({
26590
26985
  }
26591
26986
  return void 0;
26592
26987
  };
26593
- PDFDocument3.prototype.embedAll = function(embeddables) {
26988
+ PDFDocument4.prototype.embedAll = function(embeddables) {
26594
26989
  return tslib_1.__awaiter(this, void 0, void 0, function() {
26595
26990
  var idx, len;
26596
26991
  return tslib_1.__generator(this, function(_a) {
@@ -26616,7 +27011,7 @@ var require_PDFDocument = __commonJS({
26616
27011
  });
26617
27012
  });
26618
27013
  };
26619
- PDFDocument3.prototype.updateInfoDict = function() {
27014
+ PDFDocument4.prototype.updateInfoDict = function() {
26620
27015
  var pdfLib = "pdf-lib (https://github.com/Hopding/pdf-lib)";
26621
27016
  var now = /* @__PURE__ */ new Date();
26622
27017
  var info = this.getInfoDict();
@@ -26627,7 +27022,7 @@ var require_PDFDocument = __commonJS({
26627
27022
  if (!info.get(core_1.PDFName.of("CreationDate")))
26628
27023
  this.setCreationDate(now);
26629
27024
  };
26630
- PDFDocument3.prototype.getInfoDict = function() {
27025
+ PDFDocument4.prototype.getInfoDict = function() {
26631
27026
  var existingInfo = this.context.lookup(this.context.trailerInfo.Info);
26632
27027
  if (existingInfo instanceof core_1.PDFDict)
26633
27028
  return existingInfo;
@@ -26635,15 +27030,15 @@ var require_PDFDocument = __commonJS({
26635
27030
  this.context.trailerInfo.Info = this.context.register(newInfo);
26636
27031
  return newInfo;
26637
27032
  };
26638
- PDFDocument3.prototype.assertFontkit = function() {
27033
+ PDFDocument4.prototype.assertFontkit = function() {
26639
27034
  if (!this.fontkit)
26640
27035
  throw new errors_1.FontkitNotRegisteredError();
26641
27036
  return this.fontkit;
26642
27037
  };
26643
- return PDFDocument3;
27038
+ return PDFDocument4;
26644
27039
  })()
26645
27040
  );
26646
- exports2.default = PDFDocument2;
27041
+ exports2.default = PDFDocument3;
26647
27042
  function assertIsLiteralOrHexString(pdfObject) {
26648
27043
  if (!(pdfObject instanceof core_1.PDFHexString) && !(pdfObject instanceof core_1.PDFString)) {
26649
27044
  throw new core_1.UnexpectedObjectTypeError([core_1.PDFHexString, core_1.PDFString], pdfObject);
@@ -27584,7 +27979,6 @@ var require_cjs = __commonJS({
27584
27979
  // apps/admin/data/skills.lib/document/bin-src/deck-qa.mjs
27585
27980
  var import_node_child_process = require("node:child_process");
27586
27981
  var import_promises2 = require("node:fs/promises");
27587
- var import_node_os = require("node:os");
27588
27982
  var import_node_path4 = require("node:path");
27589
27983
  var import_node_util = require("node:util");
27590
27984
 
@@ -27642,6 +28036,126 @@ async function slidePartsInOrder(zip) {
27642
28036
  return toParts(complete ? ordered : byNumber);
27643
28037
  }
27644
28038
 
28039
+ // packages/core/dist/document/png-decode.js
28040
+ var import_node_zlib = require("node:zlib");
28041
+ var SIG = [137, 80, 78, 71, 13, 10, 26, 10];
28042
+ var CHANNELS = { 0: 1, 2: 3, 3: 1, 4: 2, 6: 4 };
28043
+ function decodePng(bytes) {
28044
+ try {
28045
+ if (bytes.length < 33 || SIG.some((b, i) => bytes[i] !== b))
28046
+ return void 0;
28047
+ const buf = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
28048
+ let width = 0, height = 0, depth = 0, type = -1, interlace = 0;
28049
+ let palette;
28050
+ const idat = [];
28051
+ for (let p = 8; p + 8 <= buf.length; ) {
28052
+ const len = buf.readUInt32BE(p);
28053
+ const kind = buf.toString("latin1", p + 4, p + 8);
28054
+ const data = buf.subarray(p + 8, p + 8 + len);
28055
+ if (kind === "IHDR") {
28056
+ width = data.readUInt32BE(0);
28057
+ height = data.readUInt32BE(4);
28058
+ depth = data[8];
28059
+ type = data[9];
28060
+ interlace = data[12];
28061
+ } else if (kind === "PLTE")
28062
+ palette = data;
28063
+ else if (kind === "IDAT")
28064
+ idat.push(data);
28065
+ else if (kind === "IEND")
28066
+ break;
28067
+ p += 12 + len;
28068
+ }
28069
+ const ch = CHANNELS[type];
28070
+ if (!width || !height || depth !== 8 || interlace !== 0 || ch === void 0 || type === 3 && !palette)
28071
+ return void 0;
28072
+ const raw = (0, import_node_zlib.inflateSync)(Buffer.concat(idat));
28073
+ const stride = width * ch;
28074
+ if (raw.length < height * (stride + 1))
28075
+ return void 0;
28076
+ const cur = new Uint8Array(stride);
28077
+ const prev = new Uint8Array(stride);
28078
+ const rgb = new Uint8Array(width * height * 3);
28079
+ for (let y = 0; y < height; y++) {
28080
+ const off = y * (stride + 1);
28081
+ const filter = raw[off];
28082
+ for (let i = 0; i < stride; i++) {
28083
+ const x = raw[off + 1 + i];
28084
+ const a = i >= ch ? cur[i - ch] : 0;
28085
+ const b = prev[i];
28086
+ const c = i >= ch ? prev[i - ch] : 0;
28087
+ let v;
28088
+ switch (filter) {
28089
+ case 0:
28090
+ v = x;
28091
+ break;
28092
+ case 1:
28093
+ v = x + a;
28094
+ break;
28095
+ case 2:
28096
+ v = x + b;
28097
+ break;
28098
+ case 3:
28099
+ v = x + (a + b >> 1);
28100
+ break;
28101
+ case 4: {
28102
+ const pa = Math.abs(b - c), pb = Math.abs(a - c), pc = Math.abs(a + b - 2 * c);
28103
+ v = x + (pa <= pb && pa <= pc ? a : pb <= pc ? b : c);
28104
+ break;
28105
+ }
28106
+ default:
28107
+ return void 0;
28108
+ }
28109
+ cur[i] = v & 255;
28110
+ }
28111
+ for (let px = 0; px < width; px++) {
28112
+ const o = (y * width + px) * 3;
28113
+ const s = px * ch;
28114
+ if (type === 3) {
28115
+ const k = cur[s] * 3;
28116
+ rgb[o] = palette[k];
28117
+ rgb[o + 1] = palette[k + 1];
28118
+ rgb[o + 2] = palette[k + 2];
28119
+ } else if (ch <= 2) {
28120
+ rgb[o] = rgb[o + 1] = rgb[o + 2] = cur[s];
28121
+ } else {
28122
+ rgb[o] = cur[s];
28123
+ rgb[o + 1] = cur[s + 1];
28124
+ rgb[o + 2] = cur[s + 2];
28125
+ }
28126
+ }
28127
+ prev.set(cur);
28128
+ }
28129
+ return { width, height, rgb };
28130
+ } catch {
28131
+ return void 0;
28132
+ }
28133
+ }
28134
+
28135
+ // packages/core/dist/document/readable-type.js
28136
+ var MIN_FONT_PT = 10;
28137
+ var LABEL_MAX_CHARS = 24;
28138
+ var MIN_LABEL_FONT_PT = 8;
28139
+ function readableFloorPt(text) {
28140
+ return [...text.trim()].length <= LABEL_MAX_CHARS ? MIN_LABEL_FONT_PT : MIN_FONT_PT;
28141
+ }
28142
+
28143
+ // packages/core/dist/document/text-slack.js
28144
+ var SLACK_CJK_RE = /[\u3000-\u303F\u3400-\u9FFF\uF900-\uFAFF\uFF00-\uFFEF]/;
28145
+ var PCT = { single: { cjk: 0.22, latin: 0.16 }, multi: { cjk: 0.1, latin: 0.06 } };
28146
+ var FLOOR_EM = { cjk: 1, latin: 0.45 };
28147
+ function params(single, cjk) {
28148
+ const script = cjk ? "cjk" : "latin";
28149
+ return { pct: PCT[single ? "single" : "multi"][script], floor: FLOOR_EM[script] * (single ? 1 : 0.5) };
28150
+ }
28151
+ function unpaddedWidth(padded, fontSize, single, cjk) {
28152
+ const { pct, floor } = params(single, cjk);
28153
+ const floorAbs = floor * fontSize;
28154
+ const viaPct = padded / (1 + pct);
28155
+ return viaPct * pct >= floorAbs ? viaPct : Math.max(0, padded - floorAbs);
28156
+ }
28157
+ var CHART_TEXT_NAME = "talos-chart-text";
28158
+
27645
28159
  // packages/core/dist/document/doc-design-lint.js
27646
28160
  var PLACEHOLDER_RE = /替换为|在这里写|占位|示例文本|Lorem ipsum/i;
27647
28161
  var CJK_TEXT_RE = /[぀-ヿ㐀-䶿一-鿿가-힯豈-﫿]/;
@@ -27782,7 +28296,7 @@ function lintSlideXml(slideXml, slideNumber, masterBg, expectedLang = detectDeck
27782
28296
  }
27783
28297
  }
27784
28298
  }
27785
- if (worst && !worst.onShapeFill && anyVisualShape)
28299
+ if (worst && !worst.onShapeFill && (anyVisualShape || hasPic))
27786
28300
  worst = void 0;
27787
28301
  if (placeholder) {
27788
28302
  const snippet2 = placeholder.length > 24 ? `${placeholder.slice(0, 24)}\u2026` : placeholder;
@@ -27821,8 +28335,9 @@ function lintSlideXml(slideXml, slideNumber, masterBg, expectedLang = detectDeck
27821
28335
  var EMU_PER_INCH = 914400;
27822
28336
  var DEFAULT_CANVAS = { w: 12192e3, h: 6858e3 };
27823
28337
  var OFFCANVAS_TOL = EMU_PER_INCH / 10;
27824
- var MIN_FONT_HUNDREDTHS = 1e3;
27825
- var OVERLAP_RATIO = 0.5;
28338
+ var MIN_FONT_HUNDREDTHS = MIN_FONT_PT * 100;
28339
+ var CHART_TEXT_RE = new RegExp(`<p:cNvPr\\b[^>]*\\bname="${CHART_TEXT_NAME}\\b`);
28340
+ var OVERLAP_RATIO = 0.3;
27826
28341
  function firstBox(block) {
27827
28342
  const xf = /<(?:a|p):xfrm\b[^>]*>[\s\S]*?<\/(?:a|p):xfrm>/.exec(block);
27828
28343
  const scope = xf ? xf[0] : block;
@@ -27840,6 +28355,51 @@ function overlapArea(a, b) {
27840
28355
  const iy = Math.max(0, Math.min(a.y + a.h, b.y + b.h) - Math.max(a.y, b.y));
27841
28356
  return ix * iy;
27842
28357
  }
28358
+ var CJK_WIDE_RE = /[\u2E80-\u9FFF\uAC00-\uD7AF\uF900-\uFAFF\uFF00-\uFFEF]/;
28359
+ var EMU_PER_PT = 12700;
28360
+ function inkBox(block, box) {
28361
+ let maxSz = 0;
28362
+ let inkW = 0;
28363
+ let lines = 0;
28364
+ for (const para of block.match(/<a:p>[\s\S]*?<\/a:p>|<a:p\b[^>]*>[\s\S]*?<\/a:p>/g) ?? []) {
28365
+ let paraW = 0;
28366
+ let paraSz = 0;
28367
+ for (const run of para.match(/<a:r>[\s\S]*?<\/a:r>/g) ?? []) {
28368
+ const raw = /<a:t\b[^>]*>([\s\S]*?)<\/a:t>/.exec(run)?.[1];
28369
+ if (raw === void 0)
28370
+ continue;
28371
+ const sz = +(/<a:rPr\b[^>]*\bsz="(\d+)"/.exec(run)?.[1] ?? 1800) / 100;
28372
+ paraSz = Math.max(paraSz, sz);
28373
+ for (const ch of unescXml(raw))
28374
+ paraW += (CJK_WIDE_RE.test(ch) ? 1 : ch === " " ? 0.3 : 0.55) * sz * EMU_PER_PT;
28375
+ }
28376
+ if (!paraW)
28377
+ continue;
28378
+ maxSz = Math.max(maxSz, paraSz);
28379
+ const paraLines = box.w > 0 ? Math.max(1, Math.ceil(paraW / box.w)) : 1;
28380
+ lines += paraLines;
28381
+ inkW = Math.max(inkW, Math.min(paraW, box.w));
28382
+ }
28383
+ if (!lines)
28384
+ return void 0;
28385
+ const paras = (block.match(/<a:p>[\s\S]*?<\/a:p>|<a:p\b[^>]*>[\s\S]*?<\/a:p>/g) ?? []).filter((p) => /<a:t\b[^>]*>[^<]*\S/.test(p));
28386
+ if (paras.length === 1 && maxSz > 0) {
28387
+ const lnSpc = /<a:lnSpc>\s*<a:spcPts\b[^>]*\bval="(\d+)"/.exec(block)?.[1];
28388
+ const lineH = (lnSpc ? +lnSpc / 100 : maxSz * 1.3) * EMU_PER_PT;
28389
+ const clamped = box.x + box.w >= DEFAULT_CANVAS.w - EMU_PER_PT;
28390
+ if (box.h <= lineH * 1.5 && !clamped) {
28391
+ const text = unescXml((block.match(/<a:t\b[^>]*>([\s\S]*?)<\/a:t>/g) ?? []).join(""));
28392
+ lines = 1;
28393
+ inkW = Math.min(inkW, unpaddedWidth(box.w, maxSz * EMU_PER_PT, true, SLACK_CJK_RE.test(text)));
28394
+ }
28395
+ }
28396
+ const inkH = Math.min(box.h, lines * maxSz * 1.2 * EMU_PER_PT);
28397
+ const algn = /<a:pPr\b[^>]*\balgn="(\w+)"/.exec(block)?.[1];
28398
+ const anchor = /<a:bodyPr\b[^>]*\banchor="(\w+)"/.exec(block)?.[1];
28399
+ const x = algn === "ctr" ? box.x + (box.w - inkW) / 2 : algn === "r" ? box.x + box.w - inkW : box.x;
28400
+ const y = anchor === "ctr" ? box.y + (box.h - inkH) / 2 : anchor === "b" ? box.y + box.h - inkH : box.y;
28401
+ return { x, y, w: inkW, h: inkH };
28402
+ }
27843
28403
  function lintSlideGeometry(slideXml, slideNumber, canvas = DEFAULT_CANVAS) {
27844
28404
  const findings = [];
27845
28405
  const blocks = slideXml.match(/<p:(?:sp|pic|graphicFrame|cxnSp)\b[^>]*>[\s\S]*?<\/p:(?:sp|pic|graphicFrame|cxnSp)>/g) ?? [];
@@ -27863,16 +28423,23 @@ function lintSlideGeometry(slideXml, slideNumber, canvas = DEFAULT_CANVAS) {
27863
28423
  worstOff = { by, edge };
27864
28424
  }
27865
28425
  }
27866
- if (hasText && box.w > 0 && box.h > 0)
27867
- textBoxes2.push(box);
28426
+ if (hasText && box.w > 0 && box.h > 0) {
28427
+ const ink = inkBox(b, box);
28428
+ if (ink)
28429
+ textBoxes2.push(ink);
28430
+ }
27868
28431
  }
28432
+ if (CHART_TEXT_RE.test(b))
28433
+ continue;
27869
28434
  for (const run of b.match(/<a:r>[\s\S]*?<\/a:r>/g) ?? []) {
27870
28435
  const raw = /<a:t\b[^>]*>([\s\S]*?)<\/a:t>/.exec(run)?.[1];
27871
28436
  if (raw === void 0 || !unescXml(raw).trim())
27872
28437
  continue;
28438
+ const text = unescXml(raw).trim();
27873
28439
  const sz = /<a:rPr\b[^>]*\bsz="(\d+)"/.exec(run)?.[1];
27874
- if (sz && +sz < MIN_FONT_HUNDREDTHS && (!smallest || +sz < smallest.sz)) {
27875
- smallest = { sz: +sz, text: unescXml(raw).trim() };
28440
+ const floor = readableFloorPt(text) * 100;
28441
+ if (sz && +sz < floor && (!smallest || +sz < smallest.sz)) {
28442
+ smallest = { sz: +sz, text, floor };
27876
28443
  }
27877
28444
  }
27878
28445
  }
@@ -27888,7 +28455,7 @@ function lintSlideGeometry(slideXml, slideNumber, canvas = DEFAULT_CANVAS) {
27888
28455
  findings.push({
27889
28456
  slide: slideNumber,
27890
28457
  code: "tiny-font",
27891
- message: `text "${snippet2}" is ${(smallest.sz / 100).toFixed(0)}pt \u2014 below the ~10pt readable floor for a projected slide; enlarge it or cut the text`
28458
+ message: `text "${snippet2}" is ${+(smallest.sz / 100).toFixed(1)}pt \u2014 below the ~${smallest.floor / 100}pt readable floor for ${smallest.floor < MIN_FONT_HUNDREDTHS ? "a short label" : "text"} on a projected slide; enlarge it or cut the text`
27892
28459
  });
27893
28460
  }
27894
28461
  let worstPair;
@@ -27913,6 +28480,110 @@ function lintSlideGeometry(slideXml, slideNumber, canvas = DEFAULT_CANVAS) {
27913
28480
  }
27914
28481
  return findings;
27915
28482
  }
28483
+ var BACKDROP_COVER = 0.98;
28484
+ var BACKDROP_FLOOR = 2;
28485
+ var BACKDROP_SAMPLES = 2500;
28486
+ var LIN = Array.from({ length: 256 }, (_, i) => {
28487
+ const c = i / 255;
28488
+ return c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
28489
+ });
28490
+ var lumRgb = (r, g, b) => 0.2126 * LIN[r] + 0.7152 * LIN[g] + 0.0722 * LIN[b];
28491
+ var ratioOf = (a, b) => (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05);
28492
+ var hex2 = (n) => n.toString(16).padStart(2, "0").toUpperCase();
28493
+ var BLOCK_RE = /<p:(?:sp|pic|graphicFrame|cxnSp)\b[^>]*>[\s\S]*?<\/p:(?:sp|pic|graphicFrame|cxnSp)>/g;
28494
+ function backdropPicEmbed(slideXml, canvas = DEFAULT_CANVAS) {
28495
+ const first = (slideXml.match(BLOCK_RE) ?? [])[0];
28496
+ if (!first || !first.startsWith("<p:pic"))
28497
+ return void 0;
28498
+ const box = firstBox(first);
28499
+ if (!box || box.x > canvas.w * (1 - BACKDROP_COVER) || box.y > canvas.h * (1 - BACKDROP_COVER))
28500
+ return void 0;
28501
+ if (box.w < canvas.w * BACKDROP_COVER || box.h < canvas.h * BACKDROP_COVER)
28502
+ return void 0;
28503
+ return /<a:blip\b[^>]*\br:embed="([^"]+)"/.exec(first)?.[1];
28504
+ }
28505
+ function lintBackdropContrast(slideXml, slideNumber, backdrop, canvas = DEFAULT_CANVAS) {
28506
+ const blocks = slideXml.match(BLOCK_RE) ?? [];
28507
+ const sx = backdrop.width / canvas.w;
28508
+ const sy = backdrop.height / canvas.h;
28509
+ const occluders = [];
28510
+ let worst;
28511
+ for (let bi = 1; bi < blocks.length; bi++) {
28512
+ const b = blocks[bi];
28513
+ const box = firstBox(b);
28514
+ if (!box)
28515
+ continue;
28516
+ const txIdx = b.indexOf("<p:txBody>");
28517
+ const spPr = txIdx >= 0 ? b.slice(0, txIdx) : b;
28518
+ const prst = /<a:prstGeom\b[^>]*\bprst="([^"]+)"/.exec(spPr)?.[1];
28519
+ const visual = !b.startsWith("<p:sp") || FILL_RE.test(spPr) || prst !== void 0 && prst !== "rect";
28520
+ const hasText = txIdx >= 0 && /<a:t\b[^>]*>\s*\S/.test(b);
28521
+ if (visual) {
28522
+ occluders.push(box);
28523
+ continue;
28524
+ }
28525
+ if (!hasText)
28526
+ continue;
28527
+ const ink = inkBox(b, box);
28528
+ if (!ink || ink.w <= 0 || ink.h <= 0)
28529
+ continue;
28530
+ if (occluders.some((o2) => overlapArea(o2, ink) > 0))
28531
+ continue;
28532
+ let fg;
28533
+ let alpha = 1;
28534
+ let text = "";
28535
+ for (const run of b.match(/<a:r>[\s\S]*?<\/a:r>/g) ?? []) {
28536
+ const raw = /<a:t\b[^>]*>([\s\S]*?)<\/a:t>/.exec(run)?.[1];
28537
+ if (raw === void 0 || !unescXml(raw).trim())
28538
+ continue;
28539
+ text += unescXml(raw);
28540
+ if (fg)
28541
+ continue;
28542
+ const rPr = run.slice(0, Math.max(0, run.indexOf("</a:rPr>")));
28543
+ fg = firstSrgb(rPr);
28544
+ const a = /<a:srgbClr\b[^>]*>\s*<a:alpha\b[^>]*\bval="(\d+)"/.exec(rPr)?.[1];
28545
+ if (fg && a)
28546
+ alpha = Math.min(1, +a / 1e5);
28547
+ }
28548
+ if (!fg)
28549
+ continue;
28550
+ const x0 = Math.max(0, Math.floor(ink.x * sx));
28551
+ const y0 = Math.max(0, Math.floor(ink.y * sy));
28552
+ const x1 = Math.min(backdrop.width, Math.ceil((ink.x + ink.w) * sx));
28553
+ const y1 = Math.min(backdrop.height, Math.ceil((ink.y + ink.h) * sy));
28554
+ if (x1 <= x0 || y1 <= y0)
28555
+ continue;
28556
+ const step = Math.max(1, Math.floor(Math.sqrt((x1 - x0) * (y1 - y0) / BACKDROP_SAMPLES)));
28557
+ const fr = parseInt(fg.slice(0, 2), 16), fgG = parseInt(fg.slice(2, 4), 16), fb = parseInt(fg.slice(4, 6), 16);
28558
+ const fgLum = lumRgb(fr, fgG, fb);
28559
+ const samples = [];
28560
+ for (let y = y0; y < y1; y += step) {
28561
+ for (let x = x0; x < x1; x += step) {
28562
+ const o2 = (y * backdrop.width + x) * 3;
28563
+ const r = backdrop.rgb[o2], g = backdrop.rgb[o2 + 1], bl = backdrop.rgb[o2 + 2];
28564
+ const l = lumRgb(r, g, bl);
28565
+ const tl = alpha >= 1 ? fgLum : lumRgb(Math.round(alpha * fr + (1 - alpha) * r), Math.round(alpha * fgG + (1 - alpha) * g), Math.round(alpha * fb + (1 - alpha) * bl));
28566
+ samples.push([ratioOf(tl, l), o2]);
28567
+ }
28568
+ }
28569
+ if (!samples.length)
28570
+ continue;
28571
+ samples.sort((p, q) => p[0] - q[0]);
28572
+ const [ratio, o] = samples[samples.length >> 1];
28573
+ if (ratio < BACKDROP_FLOOR && (!worst || ratio < worst.ratio)) {
28574
+ const bg = hex2(backdrop.rgb[o]) + hex2(backdrop.rgb[o + 1]) + hex2(backdrop.rgb[o + 2]);
28575
+ worst = { ratio, text: text.trim(), fg, bg };
28576
+ }
28577
+ }
28578
+ if (!worst)
28579
+ return [];
28580
+ const snippet2 = worst.text.length > 24 ? `${worst.text.slice(0, 24)}\u2026` : worst.text;
28581
+ return [{
28582
+ slide: slideNumber,
28583
+ code: "low-contrast-text",
28584
+ message: `text "${snippet2}" is #${worst.fg} over the slide's rendered background (\u2248#${worst.bg} under it) \u2014 median contrast ${worst.ratio.toFixed(1)}:1, below the ${BACKDROP_FLOOR.toFixed(1)} floor \u2014 it can barely be seen; text over a photo or panel takes that surface's text colour (light on a dark photo/scrim), not the skin's page text colour`
28585
+ }];
28586
+ }
27916
28587
  function canvasFromPresentation(xml) {
27917
28588
  if (!xml)
27918
28589
  return DEFAULT_CANVAS;
@@ -27920,6 +28591,26 @@ function canvasFromPresentation(xml) {
27920
28591
  const cy = /<p:sldSz\b[^>]*\bcy="(\d+)"/.exec(xml)?.[1];
27921
28592
  return cx && cy ? { w: +cx, h: +cy } : DEFAULT_CANVAS;
27922
28593
  }
28594
+ async function backdropRaster(zip, slideXml, relsPath, canvas) {
28595
+ const rId = backdropPicEmbed(slideXml, canvas);
28596
+ const rels = rId ? zip.file(relsPath) : null;
28597
+ if (!rId || !rels)
28598
+ return void 0;
28599
+ const relsXml = await rels.async("string");
28600
+ const rel = [...relsXml.matchAll(/<Relationship\b[^>]*>/g)].map((m) => m[0]).find((r) => new RegExp(`\\bId="${rId}"`).test(r));
28601
+ const target = rel && /\bTarget="([^"]+)"/.exec(rel)?.[1];
28602
+ if (!target || !/\.png$/i.test(target))
28603
+ return void 0;
28604
+ const parts = ["ppt", "slides"];
28605
+ for (const seg of target.split("/")) {
28606
+ if (seg === "..")
28607
+ parts.pop();
28608
+ else if (seg && seg !== ".")
28609
+ parts.push(seg);
28610
+ }
28611
+ const media = zip.file(target.startsWith("/") ? target.slice(1) : parts.join("/"));
28612
+ return media ? decodePng(await media.async("uint8array")) : void 0;
28613
+ }
27923
28614
  async function designLintPptx(bytes) {
27924
28615
  const zip = await import_jszip.default.loadAsync(Buffer.from(bytes));
27925
28616
  const findings = [];
@@ -27930,9 +28621,15 @@ async function designLintPptx(bytes) {
27930
28621
  const presFile = zip.file("ppt/presentation.xml");
27931
28622
  const canvas = canvasFromPresentation(presFile ? await presFile.async("string") : void 0);
27932
28623
  const lang = detectDeckLang();
27933
- for (const { position, path } of await slidePartsInOrder(zip)) {
28624
+ for (const { position, path, relsPath } of await slidePartsInOrder(zip)) {
27934
28625
  const xml = await zip.file(path).async("string");
27935
- findings.push(...lintSlideXml(xml, position, masterBg, lang));
28626
+ const own = lintSlideXml(xml, position, masterBg, lang);
28627
+ findings.push(...own);
28628
+ if (!own.some((f) => f.code === "low-contrast-text")) {
28629
+ const backdrop = await backdropRaster(zip, xml, relsPath, canvas);
28630
+ if (backdrop)
28631
+ findings.push(...lintBackdropContrast(xml, position, backdrop, canvas));
28632
+ }
27936
28633
  findings.push(...lintSlideGeometry(xml, position, canvas));
27937
28634
  }
27938
28635
  return { ok: findings.length === 0, findings };
@@ -27940,76 +28637,101 @@ async function designLintPptx(bytes) {
27940
28637
 
27941
28638
  // packages/core/dist/document/deck-render-check.js
27942
28639
  var import_jszip2 = __toESM(require_lib3(), 1);
28640
+ init_pdf_extract();
27943
28641
 
27944
- // packages/core/dist/document/pdf-extract.js
27945
- var import_node_path = require("node:path");
27946
- var import_node_url = require("node:url");
27947
- var _mupdf = null;
27948
- function loadMupdf() {
27949
- if (!_mupdf) {
27950
- const deps = process.env.TALOS_SKILL_DEPS;
27951
- const spec = deps ? (0, import_node_url.pathToFileURL)((0, import_node_path.join)(deps, "mupdf", "dist", "mupdf.js")).href : "mupdf";
27952
- _mupdf = import(spec);
28642
+ // packages/core/dist/document/pdf-fonts.js
28643
+ var import_pdf_lib = __toESM(require_cjs(), 1);
28644
+ var CJK_RANGES = [
28645
+ [11904, 12031],
28646
+ [12288, 12351],
28647
+ [12352, 12543],
28648
+ [12800, 19903],
28649
+ [19968, 40959],
28650
+ [63744, 64255],
28651
+ [65072, 65103],
28652
+ [65280, 65519]
28653
+ ];
28654
+ var isCjk = (u) => CJK_RANGES.some(([a, b]) => u >= a && u <= b);
28655
+ function toUnicodeHasCjk(cmap) {
28656
+ for (const m of cmap.matchAll(/<([0-9A-Fa-f]{4,})>/g)) {
28657
+ const hex = m[1];
28658
+ for (let i = 0; i + 4 <= hex.length; i += 4)
28659
+ if (isCjk(parseInt(hex.slice(i, i + 4), 16)))
28660
+ return true;
27953
28661
  }
27954
- return _mupdf;
28662
+ return false;
27955
28663
  }
27956
- async function openDoc(bytes) {
27957
- const mupdf = await loadMupdf();
27958
- const doc = mupdf.Document.openDocument(bytes, "application/pdf");
27959
- if (doc.countPages() === 0) {
27960
- throw new Error("PDF has no readable pages (corrupt, encrypted, or empty)");
28664
+ function streamText(stream) {
28665
+ try {
28666
+ if (stream instanceof import_pdf_lib.PDFRawStream)
28667
+ return Buffer.from((0, import_pdf_lib.decodePDFRawStream)(stream).decode()).toString("latin1");
28668
+ if (stream instanceof import_pdf_lib.PDFStream)
28669
+ return Buffer.from(stream.getContents()).toString("latin1");
28670
+ } catch {
27961
28671
  }
27962
- return { mupdf, doc };
28672
+ return "";
27963
28673
  }
27964
- async function extractPdfTextLines(bytes) {
27965
- const { doc } = await openDoc(bytes);
28674
+ var nameOf = (v) => v instanceof import_pdf_lib.PDFName ? v.decodeText() : void 0;
28675
+ async function scanPdfType3Fonts(pdfBytes) {
28676
+ const doc = await import_pdf_lib.PDFDocument.load(pdfBytes, { ignoreEncryption: true, updateMetadata: false, throwOnInvalidObject: false });
28677
+ const ctx = doc.context;
28678
+ const deref = (v) => v instanceof import_pdf_lib.PDFRef ? ctx.lookup(v) : v;
27966
28679
  const out = [];
27967
- for (let p = 1; p <= doc.countPages(); p++) {
27968
- const page = doc.loadPage(p - 1);
27969
- const [x0, y0, x1, y1] = page.getBounds();
27970
- const json = JSON.parse(page.toStructuredText().asJSON());
27971
- const lines = [];
27972
- for (const b of json.blocks ?? []) {
27973
- if (b.type === "image")
27974
- continue;
27975
- for (const l of b.lines ?? []) {
27976
- const text = l.text ?? "";
27977
- if (!text.trim() || !l.bbox)
27978
- continue;
27979
- lines.push({
27980
- x: l.bbox.x ?? 0,
27981
- y: l.bbox.y ?? 0,
27982
- w: l.bbox.w ?? 0,
27983
- h: l.bbox.h ?? 0,
27984
- size: l.font?.size ?? 12,
27985
- text
27986
- });
28680
+ doc.getPages().forEach((page, i) => {
28681
+ const seen = /* @__PURE__ */ new Set();
28682
+ const visitResources = (res, depth) => {
28683
+ const r = deref(res);
28684
+ if (!(r instanceof import_pdf_lib.PDFDict) || depth > 8)
28685
+ return;
28686
+ const fonts = deref(r.get(import_pdf_lib.PDFName.of("Font")));
28687
+ if (fonts instanceof import_pdf_lib.PDFDict) {
28688
+ for (const [key, ref] of fonts.entries()) {
28689
+ const font = deref(ref);
28690
+ if (!(font instanceof import_pdf_lib.PDFDict) || seen.has(font))
28691
+ continue;
28692
+ seen.add(font);
28693
+ if (nameOf(font.get(import_pdf_lib.PDFName.of("Subtype"))) !== "Type3")
28694
+ continue;
28695
+ const name = nameOf(font.get(import_pdf_lib.PDFName.of("BaseFont"))) ?? nameOf(font.get(import_pdf_lib.PDFName.of("Name"))) ?? key.decodeText();
28696
+ out.push({ page: i + 1, name, cjk: toUnicodeHasCjk(streamText(deref(font.get(import_pdf_lib.PDFName.of("ToUnicode"))))) });
28697
+ }
27987
28698
  }
27988
- }
27989
- out.push({ page: p, width: x1 - x0, height: y1 - y0, lines });
27990
- }
27991
- return out;
27992
- }
27993
- async function renderPdfPages(bytes, pages, scale = 2) {
27994
- const { mupdf, doc } = await openDoc(bytes);
27995
- const total = doc.countPages();
27996
- const wanted = pages === "all" ? Array.from({ length: total }, (_, i) => i + 1) : pages;
27997
- const out = [];
27998
- const matrix = mupdf.Matrix.scale(scale, scale);
27999
- for (const p of wanted) {
28000
- if (p < 1 || p > total)
28001
- continue;
28002
- const pix = doc.loadPage(p - 1).toPixmap(matrix, mupdf.ColorSpace.DeviceRGB, false, true);
28003
- out.push({ page: p, png: pix.asPNG() });
28004
- }
28699
+ const xobjects = deref(r.get(import_pdf_lib.PDFName.of("XObject")));
28700
+ if (xobjects instanceof import_pdf_lib.PDFDict) {
28701
+ for (const [, ref] of xobjects.entries()) {
28702
+ const xo = deref(ref);
28703
+ if (!(xo instanceof import_pdf_lib.PDFStream) || seen.has(xo))
28704
+ continue;
28705
+ seen.add(xo);
28706
+ if (nameOf(xo.dict.get(import_pdf_lib.PDFName.of("Subtype"))) === "Form")
28707
+ visitResources(xo.dict.get(import_pdf_lib.PDFName.of("Resources")), depth + 1);
28708
+ }
28709
+ }
28710
+ };
28711
+ visitResources(page.node.Resources(), 0);
28712
+ });
28005
28713
  return out;
28006
28714
  }
28007
28715
 
28008
28716
  // packages/core/dist/document/deck-render-check.js
28717
+ function type3Findings(fonts) {
28718
+ const byPage = /* @__PURE__ */ new Map();
28719
+ for (const f of fonts)
28720
+ byPage.set(f.page, [...byPage.get(f.page) ?? [], f]);
28721
+ return [...byPage].map(([slide, list]) => {
28722
+ const cjk = list.some((f) => f.cjk);
28723
+ return {
28724
+ slide,
28725
+ code: "render-type3-font",
28726
+ message: `the Office render draws ${list.map((f) => f.name + (f.cjk ? " (CJK)" : "")).join(", ")} as a Type 3 font \u2014 ` + (cjk ? "LibreOffice could not embed the face it fell back to, and its Type 3 CJK glyphs paint nothing: that text is blank on the page" : "LibreOffice could not embed the face it fell back to (bitmap or empty glyphs)") + "; render through doc-convert (its font replacement table), never a bare soffice"
28727
+ };
28728
+ });
28729
+ }
28009
28730
  var OVERFLOW_PITCH = 0.5;
28010
28731
  var SIDE_TOL = 0.5;
28011
28732
  var HANG_TOL = 1.1;
28012
28733
  var HANGING_PUNCT = /[、,。;:!?)」』》,.;:!?)]$/;
28734
+ var NEAR_PITCHES = 3;
28013
28735
  var DEFAULT_PT = 18;
28014
28736
  var squash = (s) => s.replace(/\s+/g, "");
28015
28737
  var snippet = (s) => s.length > 24 ? `${s.slice(0, 24)}\u2026` : s;
@@ -28046,10 +28768,11 @@ function checkRenderedSlide(slideXml, slideNumber, canvas, page) {
28046
28768
  let worstSide;
28047
28769
  for (const line of page.lines) {
28048
28770
  const text = squash(line.text);
28049
- let candidates = boxes.filter((b) => b.text.includes(text));
28771
+ const near = (b) => b.text.includes(text) && distance(b, line) <= NEAR_PITCHES * b.pitch;
28772
+ let candidates = boxes.filter(near);
28050
28773
  const merged = !candidates.length && text.length > 1;
28051
28774
  if (merged)
28052
- candidates = boxes.filter((b) => b.text.includes(text.slice(1)));
28775
+ candidates = boxes.filter((b) => b.text.includes(text.slice(1)) && distance(b, line) <= NEAR_PITCHES * b.pitch);
28053
28776
  if (!candidates.length)
28054
28777
  continue;
28055
28778
  const box = candidates.reduce((best, b) => distance(b, line) < distance(best, line) ? b : best);
@@ -28129,7 +28852,8 @@ async function checkRenderedDeck(pptxBytes, pdfBytes) {
28129
28852
  }
28130
28853
  const presXml = await zip.file("ppt/presentation.xml")?.async("string");
28131
28854
  const canvas = canvasFromPresentation(presXml);
28132
- const findings = [];
28855
+ const type3Fonts = await scanPdfType3Fonts(pdfBytes);
28856
+ const findings = type3Findings(type3Fonts);
28133
28857
  const charts = [];
28134
28858
  for (const { position, path } of slides) {
28135
28859
  const xml = await zip.file(path).async("string");
@@ -28137,16 +28861,55 @@ async function checkRenderedDeck(pptxBytes, pdfBytes) {
28137
28861
  if (/drawingml\/2006\/chart"/.test(xml))
28138
28862
  charts.push(position);
28139
28863
  }
28864
+ findings.sort((a, b) => a.slide - b.slide);
28140
28865
  const review = [.../* @__PURE__ */ new Set([...findings.map((f) => f.slide), ...charts])].sort((a, b) => a - b);
28141
- return { findings, charts, review };
28866
+ return { findings, charts, review, type3Fonts };
28142
28867
  }
28143
28868
 
28869
+ // apps/admin/data/skills.lib/document/bin-src/deck-qa.mjs
28870
+ init_pdf_extract();
28871
+
28144
28872
  // apps/admin/data/skills.lib/document/bin-src/lib/check-pptx.mjs
28145
28873
  var import_node_path3 = require("node:path");
28146
28874
 
28147
28875
  // packages/core/dist/document/doc-validate.js
28876
+ var import_jszip5 = __toESM(require_lib3(), 1);
28877
+ var import_pdf_lib2 = __toESM(require_cjs(), 1);
28878
+
28879
+ // packages/core/dist/document/pptx-notes.js
28148
28880
  var import_jszip3 = __toESM(require_lib3(), 1);
28149
- var import_pdf_lib = __toESM(require_cjs(), 1);
28881
+ var REL_NS = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
28882
+ var NOTES_SLIDE_REL = `${REL_NS}/notesSlide`;
28883
+ var NOTES_MASTER_REL = `${REL_NS}/notesMaster`;
28884
+ var SLIDE_REL = `${REL_NS}/slide`;
28885
+ async function notesKeynoteIssues(zip) {
28886
+ const out = [];
28887
+ for (const p of Object.keys(zip.files).filter((p2) => /^ppt\/notesSlides\/notesSlide\d+\.xml$/.test(p2)).sort()) {
28888
+ const xml = await zip.file(p).async("string");
28889
+ if (!/<p:clrMapOvr\b/.test(xml))
28890
+ out.push(p);
28891
+ }
28892
+ return out;
28893
+ }
28894
+ async function unlistedNotesMaster(zip) {
28895
+ const relsFile = zip.file("ppt/_rels/presentation.xml.rels");
28896
+ const presFile = zip.file("ppt/presentation.xml");
28897
+ if (!relsFile || !presFile)
28898
+ return null;
28899
+ const rel = new RegExp(`<Relationship\\b[^>]*Type="${NOTES_MASTER_REL}"[^>]*>`).exec(await relsFile.async("string"))?.[0];
28900
+ const rid = rel ? /\bId="([^"]+)"/.exec(rel)?.[1] : void 0;
28901
+ if (!rid)
28902
+ return null;
28903
+ return /<p:notesMasterId\b/.test(await presFile.async("string")) ? null : rid;
28904
+ }
28905
+
28906
+ // packages/core/dist/document/docx-defaults.js
28907
+ var import_jszip4 = __toESM(require_lib3(), 1);
28908
+ function hasDefaultParagraphStyle(stylesXml) {
28909
+ return [...stylesXml.matchAll(/<w:style\b[^>]*>/g)].some(([tag]) => /\bw:type="paragraph"/.test(tag) && /\bw:default="(1|true|on)"/.test(tag));
28910
+ }
28911
+
28912
+ // packages/core/dist/document/doc-validate.js
28150
28913
  function looksLikePdf(bytes) {
28151
28914
  const head = Buffer.from(bytes.subarray(0, 1024)).toString("latin1");
28152
28915
  return head.includes("%PDF-");
@@ -28156,8 +28919,19 @@ async function validatePdf(bytes) {
28156
28919
  const warnings = [];
28157
28920
  let pages;
28158
28921
  try {
28159
- const doc = await import_pdf_lib.PDFDocument.load(bytes, { ignoreEncryption: true, throwOnInvalidObject: true, updateMetadata: false });
28922
+ const doc = await import_pdf_lib2.PDFDocument.load(bytes, { ignoreEncryption: true, throwOnInvalidObject: true, updateMetadata: false });
28160
28923
  pages = doc.getPageCount();
28924
+ if (doc.isEncrypted) {
28925
+ const { pdfNeedsPassword: pdfNeedsPassword2 } = await Promise.resolve().then(() => (init_pdf_extract(), pdf_extract_exports));
28926
+ if (await pdfNeedsPassword2(bytes).catch(() => true)) {
28927
+ errors.push({
28928
+ code: "pdf-encrypted",
28929
+ message: "the PDF needs a password to open, so its content cannot be checked or rendered \u2014 validate (and render) the unencrypted file before `pdf-ops encrypt`; to inspect this one, `pdf-ops decrypt <in> <password> <out>` first"
28930
+ });
28931
+ return { ok: false, kind: "pdf", errors, warnings, pages };
28932
+ }
28933
+ warnings.push({ code: "pdf-encrypted", message: 'the PDF is encrypted with an owner password only: it opens without a password, but pdf-form / pdf-ops cannot edit it until `pdf-ops decrypt <in> "" <out>`' });
28934
+ }
28161
28935
  if (pages === 0)
28162
28936
  errors.push({ code: "pdf-no-pages", message: "the PDF parses but has no pages" });
28163
28937
  else
@@ -28315,7 +29089,7 @@ async function validateOoxml(bytes) {
28315
29089
  const result = (kind) => ({ ok: errors.length === 0, kind, errors, warnings });
28316
29090
  let zip;
28317
29091
  try {
28318
- zip = await import_jszip3.default.loadAsync(Buffer.from(bytes));
29092
+ zip = await import_jszip5.default.loadAsync(Buffer.from(bytes));
28319
29093
  } catch (e) {
28320
29094
  errors.push({ code: "zip-unreadable", message: `not a readable OOXML zip: ${e.message}` });
28321
29095
  return result("unknown");
@@ -28383,6 +29157,30 @@ async function validateOoxml(bytes) {
28383
29157
  }
28384
29158
  }
28385
29159
  }
29160
+ if (root.kind === "pptx") {
29161
+ const bad = await notesKeynoteIssues(zip);
29162
+ if (bad.length) {
29163
+ errors.push({
29164
+ code: "notes-keynote",
29165
+ part: bad[0],
29166
+ message: `${bad.length} notes slide(s) lack <p:clrMapOvr> (${bad.slice(0, 3).join(", ")}${bad.length > 3 ? ", \u2026" : ""}) \u2014 Keynote refuses the whole file ("\u6587\u4EF6\u683C\u5F0F\u65E0\u6548"). Repair with \`pptx-notes <in.pptx> {} <out.pptx>\`; write notes with pptx-notes, never by hand`
29167
+ });
29168
+ }
29169
+ }
29170
+ if (root.kind === "pptx" && await unlistedNotesMaster(zip)) {
29171
+ errors.push({
29172
+ code: "notes-keynote",
29173
+ part: "ppt/presentation.xml",
29174
+ message: 'the notes master is not listed in <p:notesMasterIdLst> (python-pptx leaves it out) \u2014 Keynote refuses the whole file ("\u6587\u4EF6\u683C\u5F0F\u65E0\u6548"). Repair with `pptx-notes <in.pptx> {} <out.pptx>`'
29175
+ });
29176
+ }
29177
+ if (root.kind === "docx" && has("word/styles.xml") && !hasDefaultParagraphStyle(await text("word/styles.xml"))) {
29178
+ errors.push({
29179
+ code: "docx-default-style",
29180
+ part: "word/styles.xml",
29181
+ message: 'no default paragraph style (w:default="1", usually "Normal") \u2014 Word fills the gap, but Pages lays every unstyled paragraph out like the one before it (a centred title turns the whole body huge and centred). Repair with `docx-defaults <in.docx> <out.docx>`; docx from doc-gen already has it'
29182
+ });
29183
+ }
28386
29184
  return result(root.kind);
28387
29185
  }
28388
29186
 
@@ -28390,7 +29188,7 @@ async function validateOoxml(bytes) {
28390
29188
  var import_node_path2 = require("node:path");
28391
29189
  var import_node_url2 = require("node:url");
28392
29190
  var import_promises = require("node:fs/promises");
28393
- var import_jszip4 = __toESM(require_lib3(), 1);
29191
+ var import_jszip6 = __toESM(require_lib3(), 1);
28394
29192
  var _xmllint = null;
28395
29193
  function loadXmllint() {
28396
29194
  if (!_xmllint) {
@@ -28446,7 +29244,7 @@ function errText(e) {
28446
29244
  }
28447
29245
  async function validateOoxmlStrict(bytes, schemaDir) {
28448
29246
  const [{ validateXML }, schemas] = await Promise.all([loadXmllint(), loadSchemaSet(schemaDir)]);
28449
- const zip = await import_jszip4.default.loadAsync(Buffer.from(bytes));
29247
+ const zip = await import_jszip6.default.loadAsync(Buffer.from(bytes));
28450
29248
  const checked = [];
28451
29249
  const skipped = [];
28452
29250
  const errors = [];
@@ -28528,16 +29326,17 @@ function printLint(result) {
28528
29326
  async function officeRender(deck, pdf, cacheDir) {
28529
29327
  const bin = (0, import_node_path4.join)((0, import_node_path4.dirname)(process.argv[1]), "doc-convert.cjs");
28530
29328
  try {
28531
- const { stdout } = await (0, import_node_util.promisify)(import_node_child_process.execFile)(process.execPath, [bin, deck, pdf, "--cache-dir", cacheDir], {
29329
+ const { stdout } = await (0, import_node_util.promisify)(import_node_child_process.execFile)(process.execPath, [bin, deck, pdf, "--cache-dir", cacheDir, "--require-office"], {
28532
29330
  maxBuffer: 8 * 1024 * 1024
28533
29331
  });
28534
29332
  const engine = /\[([^\]]+)\]\s*$/.exec(stdout.trim())?.[1] ?? "unknown";
28535
29333
  return { engine, faithful: /libreoffice/i.test(engine), pdf };
28536
29334
  } catch (e) {
28537
- return { error: (e.stderr || e.message || String(e)).trim().split("\n").slice(-3).join(" ") };
29335
+ const error = (e.stderr || e.message || String(e)).trim().split("\n").slice(-3).join(" ");
29336
+ return { faithful: false, error, unavailable: e.code === 69 };
28538
29337
  }
28539
29338
  }
28540
- async function finalSignOff(file, bytes, cacheDir) {
29339
+ async function finalSignOff(file, bytes, cacheDir, requireOffice) {
28541
29340
  const check = await checkPptx(bytes, { strict: true });
28542
29341
  if (!check.valid || check.strict?.ok === false) {
28543
29342
  process.stdout.write(JSON.stringify({ ok: false, valid: check.valid, errors: check.errors, strict: check.strict }) + "\n");
@@ -28554,6 +29353,7 @@ async function finalSignOff(file, bytes, cacheDir) {
28554
29353
  const rendered = await checkRenderedDeck(bytes, pdfBytes).catch((e) => die(`render check failed: ${e.message}`));
28555
29354
  findings = [...findings, ...rendered.findings].sort((a, b) => a.slide - b.slide);
28556
29355
  ({ review, charts } = rendered);
29356
+ office.type3Fonts = rendered.type3Fonts;
28557
29357
  if (review.length) {
28558
29358
  for (const r of await renderPdfPages(new Uint8Array(pdfBytes), review, 1)) {
28559
29359
  const path = (0, import_node_path4.join)((0, import_node_path4.dirname)(office.pdf), `${stem}.office_p${r.page}.png`);
@@ -28562,13 +29362,19 @@ async function finalSignOff(file, bytes, cacheDir) {
28562
29362
  }
28563
29363
  }
28564
29364
  }
28565
- const result = { ok: findings.length === 0, valid: true, strict: check.strict, findings, office, review, charts, previews };
29365
+ const blocked = Boolean(office.error) && (!office.unavailable || requireOffice);
29366
+ const result = { ok: findings.length === 0 && !blocked, valid: true, strict: check.strict, findings, office, review, charts, previews };
28566
29367
  process.stdout.write(JSON.stringify(result, null, 1) + "\n");
29368
+ if (office.error && !office.unavailable) {
29369
+ die(`the Office render failed (${office.error}) \u2014 not signing off on a Chromium reconstruction instead; rerun deck-qa --final`);
29370
+ }
29371
+ if (office.error && requireOffice) die(`--require-office: no LibreOffice render is possible here (${office.error})`);
29372
+ if (office.type3Fonts?.length) {
29373
+ process.stderr.write(`deck-qa: the Office render draws ${office.type3Fonts.length} Type 3 font(s) (${[...new Set(office.type3Fonts.map((f) => f.name))].join(", ")}) \u2014 text set in them may be blank; see the render-type3-font findings
29374
+ `);
29375
+ }
28567
29376
  if (office.error) {
28568
29377
  process.stderr.write(`deck-qa: no Office render (${office.error}) \u2014 the HTML preview is the only visual check; say so when delivering
28569
- `);
28570
- } else if (!office.faithful) {
28571
- process.stderr.write(`deck-qa: rendered with ${office.engine}, not LibreOffice \u2014 no Office layout to check; the HTML preview stands
28572
29378
  `);
28573
29379
  } else {
28574
29380
  process.stderr.write(review.length ? `deck-qa: look at ${previews.length} slide image(s) in "previews"; every other slide is as the HTML preview showed
@@ -28580,21 +29386,24 @@ async function main() {
28580
29386
  const asJson = args.includes("--json");
28581
29387
  const final = args.includes("--final");
28582
29388
  const rendered = flagValue(args, "--rendered");
28583
- const cacheDir = flagValue(args, "--cache-dir") ?? process.env.TALOS_OFFICE_CACHE_DIR ?? (0, import_node_path4.join)((0, import_node_os.tmpdir)(), "talos-office-cache");
28584
29389
  const valued = /* @__PURE__ */ new Set(["--rendered", "--cache-dir"]);
28585
29390
  const file = args.find((a, i) => !a.startsWith("--") && !valued.has(args[i - 1]));
28586
- const usage = "usage: deck-qa <file.pptx> [--json] [--rendered <office.pdf> | --final [--cache-dir <dir>]]";
29391
+ const cacheDir = flagValue(args, "--cache-dir") ?? (process.env.TALOS_OFFICE_CACHE_DIR || void 0) ?? (file ? (0, import_node_path4.join)((0, import_node_path4.dirname)(file), ".office-cache") : void 0);
29392
+ const requireOffice = args.includes("--require-office");
29393
+ const usage = "usage: deck-qa <file.pptx> [--json] [--rendered <office.pdf> | --final [--cache-dir <dir>] [--require-office]]";
28587
29394
  if (!file) die(usage, 64);
29395
+ if (/\.html?$/i.test(file)) die("deck-qa checks the exported .pptx, not the HTML. While authoring: `html2pptx deck.html --preview-dir <dir> --style <id>` (previews to look at); the lint runs on every export \u2014 `html2pptx deck.html out.pptx --style <id>` prints it as `qa`. Sign off once with `deck-qa out.pptx --final`.", 64);
28588
29396
  if (!/\.pptx$/i.test(file)) die("deck-qa only lints .pptx decks", 64);
28589
29397
  if (rendered && !/\.pdf$/i.test(rendered)) die("--rendered takes the .pdf doc-convert wrote for this deck", 64);
28590
29398
  if (final && rendered) die("--final renders the deck itself; drop --rendered", 64);
29399
+ if (requireOffice && !final) die("--require-office only applies to --final", 64);
28591
29400
  let bytes;
28592
29401
  try {
28593
29402
  bytes = await (0, import_promises2.readFile)(file);
28594
29403
  } catch (e) {
28595
29404
  die(`cannot read ${file}: ${e.message}`, 66);
28596
29405
  }
28597
- if (final) return finalSignOff(file, new Uint8Array(bytes), cacheDir);
29406
+ if (final) return finalSignOff(file, new Uint8Array(bytes), cacheDir, requireOffice);
28598
29407
  let result;
28599
29408
  try {
28600
29409
  result = await designLintPptx(bytes);
@@ -28615,7 +29424,7 @@ async function main() {
28615
29424
  die(`render check failed: ${e.message}`);
28616
29425
  }
28617
29426
  const findings = [...result.findings, ...check.findings].sort((a, b) => a.slide - b.slide);
28618
- result = { ok: findings.length === 0, findings, charts: check.charts, review: check.review };
29427
+ result = { ok: findings.length === 0, findings, charts: check.charts, review: check.review, type3Fonts: check.type3Fonts };
28619
29428
  }
28620
29429
  if (asJson) {
28621
29430
  process.stdout.write(JSON.stringify(result) + "\n");