@taloswork/ose-shared 0.1.11 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/skills/document/SKILL.md +143 -215
- package/skills/document/art-directions/base.css +27 -2
- package/skills/document/art-directions/cinematic-depth.css +3 -1
- package/skills/document/art-directions/collage-paper.css +5 -1
- package/skills/document/art-directions/editorial-cut.css +5 -1
- package/skills/document/art-directions/geometric-pop.css +6 -0
- package/skills/document/art-directions/gradient-mesh.css +5 -1
- package/skills/document/art-directions/illustrated-doodle.css +5 -0
- package/skills/document/art-directions/luxury-ornament.css +4 -1
- package/skills/document/art-directions/maximalist-blocks.css +6 -0
- package/skills/document/art-directions/technical-grid.css +4 -0
- package/skills/document/assets/fonts/fonts.json +2 -2
- package/skills/document/assets/pdf-fonts/NotoSansSC-PDF-Bold.ttf +0 -0
- package/skills/document/assets/pdf-fonts/NotoSansSC-PDF-Regular.ttf +0 -0
- package/skills/document/assets/pdf-fonts/OFL.txt +93 -0
- package/skills/document/assets/pdf-fonts/README.md +35 -0
- package/skills/document/assets/tessdata/LICENSE-Apache-2.0.txt +202 -0
- package/skills/document/assets/tessdata/README.md +21 -0
- package/skills/document/assets/tessdata/chi_sim.traineddata.gz +0 -0
- package/skills/document/assets/tessdata/eng.traineddata.gz +0 -0
- package/skills/document/bin/deck-build.cjs +2311 -41
- package/skills/document/bin/deck-chart.cjs +762 -0
- package/skills/document/bin/deck-plan.cjs +802 -0
- package/skills/document/bin/deck-qa.cjs +984 -249
- package/skills/document/bin/deck-scenario.cjs +1346 -0
- package/skills/document/bin/doc-convert.cjs +130 -39
- package/skills/document/bin/doc-fill.cjs +73121 -170
- package/skills/document/bin/doc-gen.cjs +625 -68
- package/skills/document/bin/doc-run.cjs +162 -24
- package/skills/document/bin/doc-scan.cjs +13 -0
- package/skills/document/bin/doc-text.cjs +13 -0
- package/skills/document/bin/doc-validate.cjs +718 -23
- package/skills/document/bin/doc-xml.cjs +9 -5
- package/skills/document/bin/docx-annotate.cjs +95 -19
- package/skills/document/bin/fontkit.cjs +1 -0
- package/skills/document/bin/html2pptx.cjs +1372 -121
- package/skills/document/bin/ocr-worker.cjs +1 -0
- package/skills/document/bin/ocr.cjs +131 -40
- package/skills/document/bin/pdf-form.cjs +674 -177
- package/skills/document/bin/pdf-images.cjs +13 -0
- package/skills/document/bin/pdf-ops.cjs +634 -199
- package/skills/document/bin/pdf-render.cjs +19 -3
- package/skills/document/bin/pdf-tables.cjs +13 -0
- package/skills/document/bin/pptx-clone.cjs +3 -3
- package/skills/document/bin/pptx-slide.cjs +3 -3
- package/skills/document/bin/xlsx-query.cjs +192 -61
- package/skills/document/bin-reference.md +56 -33
- package/skills/document/content-pipeline.md +129 -242
- package/skills/document/deck-design.md +355 -638
- package/skills/document/layouts/README.md +46 -33
- package/skills/document/layouts/capacity.json +1 -0
- package/skills/document/layouts/slots.json +1 -1
- package/skills/document/layouts/toc-panel.tpl +1 -1
- package/skills/document/motion/README.md +3 -2
- package/skills/document/office.md +3 -3
- package/skills/document/packs/board-brief/backdrop.html +2 -0
- package/skills/document/packs/board-brief/pack.css +2 -1
- package/skills/document/packs/mckinsey-photo/backdrop.html +2 -0
- package/skills/document/packs/mckinsey-photo/pack.css +2 -1
- package/skills/document/packs/press-room/backdrop.html +2 -0
- package/skills/document/packs/press-room/pack.css +2 -1
- package/skills/document/packs/prismatic-3d/backdrop.html +2 -0
- package/skills/document/packs/prismatic-3d/pack.css +4 -1
- package/skills/document/pdf.md +53 -49
- package/skills/document/rewrite.md +241 -308
- package/skills/document/scenarios.json +1290 -0
- package/skills/document/scenarios.schema.json +103 -0
- package/skills/document/styles/README.md +15 -25
- package/skills/document/styles/_contract-defaults.css +25 -1
- package/skills/document/styles/anthropic/skin.css +6 -3
- package/skills/document/styles/apple/skin.css +4 -3
- package/skills/document/styles/bistro-warm/backdrop.html +2 -0
- package/skills/document/styles/bistro-warm/skin.css +4 -1
- package/skills/document/styles/black-gold/skin.css +6 -5
- package/skills/document/styles/bold-clash/backdrop.html +2 -0
- package/skills/document/styles/bold-clash/skin.css +2 -1
- package/skills/document/styles/branding/skin.css +4 -4
- package/skills/document/styles/campus-teal/backdrop.html +2 -0
- package/skills/document/styles/campus-teal/skin.css +2 -1
- package/skills/document/styles/cinereel/skin.css +7 -3
- package/skills/document/styles/clinic-care/backdrop.html +2 -0
- package/skills/document/styles/clinic-care/skin.css +2 -1
- package/skills/document/styles/cool/skin.css +6 -5
- package/skills/document/styles/dark-glass/backdrop.html +2 -0
- package/skills/document/styles/dark-glass/skin.css +2 -1
- package/skills/document/styles/gov-brief/backdrop.html +2 -0
- package/skills/document/styles/gov-brief/skin.css +2 -1
- package/skills/document/styles/grid-tech/backdrop.html +2 -0
- package/skills/document/styles/grid-tech/skin.css +2 -1
- package/skills/document/styles/hand-drawn/skin.css +3 -3
- package/skills/document/styles/ivory-gold/skin.css +7 -6
- package/skills/document/styles/legal-slate/backdrop.html +2 -0
- package/skills/document/styles/legal-slate/skin.css +2 -1
- package/skills/document/styles/magazine-ink/skin.css +4 -3
- package/skills/document/styles/mckinsey/skin.css +2 -1
- package/skills/document/styles/memphis/backdrop.html +2 -0
- package/skills/document/styles/memphis/skin.css +2 -1
- package/skills/document/styles/mono/skin.css +6 -2
- package/skills/document/styles/neon-cyber/backdrop.html +2 -0
- package/skills/document/styles/neon-cyber/skin.css +2 -1
- package/skills/document/styles/olive-gold/skin.css +7 -6
- package/skills/document/styles/organic-earth/backdrop.html +2 -0
- package/skills/document/styles/organic-earth/skin.css +2 -1
- package/skills/document/styles/pastel-saas/backdrop.html +2 -0
- package/skills/document/styles/pastel-saas/skin.css +2 -1
- package/skills/document/styles/portfolio-noir/backdrop.html +2 -0
- package/skills/document/styles/portfolio-noir/skin.css +2 -1
- package/skills/document/styles/retro-press/backdrop.html +2 -0
- package/skills/document/styles/retro-press/skin.css +2 -1
- package/skills/document/styles/sport-arena/backdrop.html +2 -0
- package/skills/document/styles/sport-arena/skin.css +4 -1
- package/skills/document/styles/swiss-grid/skin.css +10 -5
- package/skills/document/styles/wedding-blush/backdrop.html +2 -0
- package/skills/document/styles/wedding-blush/skin.css +4 -1
- package/skills/document/theme-system.md +85 -77
- package/skills/document/themes/README.md +7 -5
- package/skills/document/vision.md +8 -5
- package/skills/document/xlsx.md +15 -25
|
@@ -9823,6 +9823,393 @@ var require_lib3 = __commonJS({
|
|
|
9823
9823
|
}
|
|
9824
9824
|
});
|
|
9825
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
|
+
renderPdfPages: () => renderPdfPages,
|
|
9854
|
+
scanPdfSignals: () => scanPdfSignals,
|
|
9855
|
+
textMathHint: () => textMathHint,
|
|
9856
|
+
textTableHint: () => textTableHint
|
|
9857
|
+
});
|
|
9858
|
+
function loadMupdf() {
|
|
9859
|
+
if (!_mupdf) {
|
|
9860
|
+
const deps = process.env.TALOS_SKILL_DEPS;
|
|
9861
|
+
const spec = deps ? (0, import_node_url.pathToFileURL)((0, import_node_path.join)(deps, "mupdf", "dist", "mupdf.js")).href : "mupdf";
|
|
9862
|
+
_mupdf = import(spec);
|
|
9863
|
+
}
|
|
9864
|
+
return _mupdf;
|
|
9865
|
+
}
|
|
9866
|
+
function textMathHint(text) {
|
|
9867
|
+
if (!text)
|
|
9868
|
+
return false;
|
|
9869
|
+
const hits = (text.match(MATH_CHARS) || []).length;
|
|
9870
|
+
return hits >= 3 || hits / Math.max(text.length, 1) > 0.02;
|
|
9871
|
+
}
|
|
9872
|
+
function textTableHint(text) {
|
|
9873
|
+
if (!text)
|
|
9874
|
+
return false;
|
|
9875
|
+
const gaps = (text.match(/ {2,}|\t/g) || []).length;
|
|
9876
|
+
return gaps >= 6;
|
|
9877
|
+
}
|
|
9878
|
+
async function openDoc(bytes) {
|
|
9879
|
+
const mupdf = await loadMupdf();
|
|
9880
|
+
const doc = mupdf.Document.openDocument(bytes, "application/pdf");
|
|
9881
|
+
if (doc.needsPassword())
|
|
9882
|
+
throw new PdfEncryptedError();
|
|
9883
|
+
if (doc.countPages() === 0) {
|
|
9884
|
+
throw new Error("PDF has no readable pages (corrupt, encrypted, or empty)");
|
|
9885
|
+
}
|
|
9886
|
+
return { mupdf, doc };
|
|
9887
|
+
}
|
|
9888
|
+
async function analyzePdfDocument(bytes, options = {}) {
|
|
9889
|
+
const wantText = options.text !== false;
|
|
9890
|
+
const wantSignals = options.signals === true;
|
|
9891
|
+
const { doc } = await openDoc(bytes);
|
|
9892
|
+
const pageCount = doc.countPages();
|
|
9893
|
+
const signals = [];
|
|
9894
|
+
let out = "";
|
|
9895
|
+
for (let i = 0; i < pageCount; i++) {
|
|
9896
|
+
const page = doc.loadPage(i);
|
|
9897
|
+
if (wantText) {
|
|
9898
|
+
out += `
|
|
9899
|
+
[page ${i + 1}]
|
|
9900
|
+
${page.toStructuredText().asText()}`;
|
|
9901
|
+
}
|
|
9902
|
+
if (wantSignals) {
|
|
9903
|
+
signals.push(pageSignalsFrom(page, i + 1));
|
|
9904
|
+
}
|
|
9905
|
+
}
|
|
9906
|
+
return { text: wantText ? out.trim() : "", pageCount, signals };
|
|
9907
|
+
}
|
|
9908
|
+
async function extractPdfText(bytes) {
|
|
9909
|
+
const { text, pageCount } = await analyzePdfDocument(bytes, { text: true });
|
|
9910
|
+
return { text, pageCount };
|
|
9911
|
+
}
|
|
9912
|
+
function countVectorOperators(content) {
|
|
9913
|
+
let ops = 0;
|
|
9914
|
+
let curves = 0;
|
|
9915
|
+
let fills = 0;
|
|
9916
|
+
let i = 0;
|
|
9917
|
+
const n = content.length;
|
|
9918
|
+
while (i < n) {
|
|
9919
|
+
const ch = content[i];
|
|
9920
|
+
if (ch === "(") {
|
|
9921
|
+
let depth = 1;
|
|
9922
|
+
i++;
|
|
9923
|
+
while (i < n && depth > 0) {
|
|
9924
|
+
if (content[i] === "\\")
|
|
9925
|
+
i++;
|
|
9926
|
+
else if (content[i] === "(")
|
|
9927
|
+
depth++;
|
|
9928
|
+
else if (content[i] === ")")
|
|
9929
|
+
depth--;
|
|
9930
|
+
i++;
|
|
9931
|
+
}
|
|
9932
|
+
continue;
|
|
9933
|
+
}
|
|
9934
|
+
if (ch === "<" && content[i + 1] !== "<") {
|
|
9935
|
+
while (i < n && content[i] !== ">")
|
|
9936
|
+
i++;
|
|
9937
|
+
i++;
|
|
9938
|
+
continue;
|
|
9939
|
+
}
|
|
9940
|
+
if (ch === "I" && content[i + 1] === "D" && isDelimiter(content[i + 2])) {
|
|
9941
|
+
const end = content.indexOf("EI", i + 2);
|
|
9942
|
+
i = end === -1 ? n : end + 2;
|
|
9943
|
+
continue;
|
|
9944
|
+
}
|
|
9945
|
+
if (!isDelimiter(ch)) {
|
|
9946
|
+
const start = i;
|
|
9947
|
+
while (i < n && !isDelimiter(content[i]))
|
|
9948
|
+
i++;
|
|
9949
|
+
const token = content.slice(start, i);
|
|
9950
|
+
switch (token) {
|
|
9951
|
+
case "m":
|
|
9952
|
+
case "l":
|
|
9953
|
+
case "re":
|
|
9954
|
+
ops++;
|
|
9955
|
+
break;
|
|
9956
|
+
case "c":
|
|
9957
|
+
case "v":
|
|
9958
|
+
case "y":
|
|
9959
|
+
ops++;
|
|
9960
|
+
curves++;
|
|
9961
|
+
break;
|
|
9962
|
+
case "f":
|
|
9963
|
+
case "F":
|
|
9964
|
+
case "f*":
|
|
9965
|
+
fills++;
|
|
9966
|
+
break;
|
|
9967
|
+
case "B":
|
|
9968
|
+
case "B*":
|
|
9969
|
+
case "b":
|
|
9970
|
+
case "b*":
|
|
9971
|
+
fills++;
|
|
9972
|
+
break;
|
|
9973
|
+
default:
|
|
9974
|
+
break;
|
|
9975
|
+
}
|
|
9976
|
+
continue;
|
|
9977
|
+
}
|
|
9978
|
+
i++;
|
|
9979
|
+
}
|
|
9980
|
+
return { ops, curves, fills };
|
|
9981
|
+
}
|
|
9982
|
+
function isDelimiter(ch) {
|
|
9983
|
+
return ch === void 0 || ch === " " || ch === "\n" || ch === "\r" || ch === " " || ch === "\f" || ch === "\0" || ch === "[" || ch === "]" || ch === "/" || ch === "{" || ch === "}";
|
|
9984
|
+
}
|
|
9985
|
+
function pageContentStream(page) {
|
|
9986
|
+
try {
|
|
9987
|
+
const obj = page.getObject?.();
|
|
9988
|
+
const contents = obj?.get?.("Contents");
|
|
9989
|
+
if (!contents)
|
|
9990
|
+
return "";
|
|
9991
|
+
const streams = contents.isArray?.() && contents.get ? Array.from({ length: contents.length ?? 0 }, (_, i) => contents.get(i)) : [contents];
|
|
9992
|
+
let out = "";
|
|
9993
|
+
for (const stream of streams) {
|
|
9994
|
+
const buf = stream?.readStream?.();
|
|
9995
|
+
const bytes = buf?.asUint8Array?.();
|
|
9996
|
+
if (bytes)
|
|
9997
|
+
out += Buffer.from(bytes).toString("latin1");
|
|
9998
|
+
}
|
|
9999
|
+
return out;
|
|
10000
|
+
} catch {
|
|
10001
|
+
return "";
|
|
10002
|
+
}
|
|
10003
|
+
}
|
|
10004
|
+
function pageSignalsFrom(page, pageNumber) {
|
|
10005
|
+
const json = JSON.parse(page.toStructuredText("preserve-images").asJSON());
|
|
10006
|
+
const blocks = json.blocks ?? [];
|
|
10007
|
+
const text = blocks.flatMap((b) => (b.lines ?? []).map((l) => l.text ?? "")).join(" ");
|
|
10008
|
+
const [x0, y0, x1, y1] = page.getBounds();
|
|
10009
|
+
const pageArea = Math.max((x1 - x0) * (y1 - y0), 1);
|
|
10010
|
+
const imgArea = blocks.filter((b) => b.type === "image").reduce((a, b) => a + Math.max((b.bbox?.w ?? 0) * (b.bbox?.h ?? 0), 0), 0);
|
|
10011
|
+
const vector = countVectorOperators(pageContentStream(page));
|
|
10012
|
+
return {
|
|
10013
|
+
page: pageNumber,
|
|
10014
|
+
textChars: text.trim().length,
|
|
10015
|
+
imageCoverage: Math.min(imgArea / pageArea, 1),
|
|
10016
|
+
vectorOps: vector.ops,
|
|
10017
|
+
vectorCurves: vector.curves,
|
|
10018
|
+
vectorFills: vector.fills,
|
|
10019
|
+
mathHint: textMathHint(text),
|
|
10020
|
+
tableHint: textTableHint(text)
|
|
10021
|
+
};
|
|
10022
|
+
}
|
|
10023
|
+
async function scanPdfSignals(bytes) {
|
|
10024
|
+
const { signals } = await analyzePdfDocument(bytes, { text: false, signals: true });
|
|
10025
|
+
return signals;
|
|
10026
|
+
}
|
|
10027
|
+
function median(nums) {
|
|
10028
|
+
if (!nums.length)
|
|
10029
|
+
return 0;
|
|
10030
|
+
const s = [...nums].sort((a, b) => a - b);
|
|
10031
|
+
return s[Math.floor(s.length / 2)];
|
|
10032
|
+
}
|
|
10033
|
+
async function extractPdfTables(bytes, pageNum, minColumns = 2) {
|
|
10034
|
+
const { doc } = await openDoc(bytes);
|
|
10035
|
+
const total = doc.countPages();
|
|
10036
|
+
const from = pageNum ? pageNum : 1;
|
|
10037
|
+
const to = pageNum ? pageNum : total;
|
|
10038
|
+
const out = [];
|
|
10039
|
+
for (let p = from; p <= to; p++) {
|
|
10040
|
+
if (p < 1 || p > total)
|
|
10041
|
+
continue;
|
|
10042
|
+
const json = JSON.parse(doc.loadPage(p - 1).toStructuredText().asJSON());
|
|
10043
|
+
const cells = [];
|
|
10044
|
+
for (const b of json.blocks ?? []) {
|
|
10045
|
+
if (b.type === "image")
|
|
10046
|
+
continue;
|
|
10047
|
+
for (const l of b.lines ?? []) {
|
|
10048
|
+
const text = (l.text ?? "").trim();
|
|
10049
|
+
if (!text)
|
|
10050
|
+
continue;
|
|
10051
|
+
cells.push({ text, x: l.bbox?.x ?? 0, y: l.bbox?.y ?? 0, h: l.bbox?.h ?? 12 });
|
|
10052
|
+
}
|
|
10053
|
+
}
|
|
10054
|
+
if (cells.length < 2)
|
|
10055
|
+
continue;
|
|
10056
|
+
const medH = median(cells.map((c) => c.h)) || 12;
|
|
10057
|
+
const rowTol = Math.max(4, medH * 0.6);
|
|
10058
|
+
const colTol = Math.max(6, medH * 0.9);
|
|
10059
|
+
const byY = [...cells].sort((a, b) => a.y - b.y);
|
|
10060
|
+
const rowGroups = [];
|
|
10061
|
+
let rowRef = Number.NEGATIVE_INFINITY;
|
|
10062
|
+
for (const c of byY) {
|
|
10063
|
+
if (c.y - rowRef > rowTol) {
|
|
10064
|
+
rowGroups.push([]);
|
|
10065
|
+
rowRef = c.y;
|
|
10066
|
+
}
|
|
10067
|
+
rowGroups[rowGroups.length - 1].push(c);
|
|
10068
|
+
}
|
|
10069
|
+
const colRefs = [];
|
|
10070
|
+
for (const x of cells.map((c) => c.x).sort((a, b) => a - b)) {
|
|
10071
|
+
if (!colRefs.length || x - colRefs[colRefs.length - 1] > colTol)
|
|
10072
|
+
colRefs.push(x);
|
|
10073
|
+
}
|
|
10074
|
+
const colIndex = (x) => {
|
|
10075
|
+
let best = 0, bd = Infinity;
|
|
10076
|
+
colRefs.forEach((r, i) => {
|
|
10077
|
+
const d = Math.abs(x - r);
|
|
10078
|
+
if (d < bd) {
|
|
10079
|
+
bd = d;
|
|
10080
|
+
best = i;
|
|
10081
|
+
}
|
|
10082
|
+
});
|
|
10083
|
+
return best;
|
|
10084
|
+
};
|
|
10085
|
+
const rows = [];
|
|
10086
|
+
for (const group of rowGroups) {
|
|
10087
|
+
const arr = Array(colRefs.length).fill("");
|
|
10088
|
+
for (const c of group.sort((a, b) => a.x - b.x)) {
|
|
10089
|
+
const i = colIndex(c.x);
|
|
10090
|
+
arr[i] = arr[i] ? `${arr[i]} ${c.text}` : c.text;
|
|
10091
|
+
}
|
|
10092
|
+
if (arr.filter((v) => v).length >= minColumns)
|
|
10093
|
+
rows.push(arr);
|
|
10094
|
+
}
|
|
10095
|
+
if (rows.length)
|
|
10096
|
+
out.push({ page: p, rows });
|
|
10097
|
+
}
|
|
10098
|
+
return out;
|
|
10099
|
+
}
|
|
10100
|
+
async function extractPdfTextLines(bytes) {
|
|
10101
|
+
const { doc } = await openDoc(bytes);
|
|
10102
|
+
const out = [];
|
|
10103
|
+
for (let p = 1; p <= doc.countPages(); p++) {
|
|
10104
|
+
const page = doc.loadPage(p - 1);
|
|
10105
|
+
const [x0, y0, x1, y1] = page.getBounds();
|
|
10106
|
+
const json = JSON.parse(page.toStructuredText().asJSON());
|
|
10107
|
+
const lines = [];
|
|
10108
|
+
for (const b of json.blocks ?? []) {
|
|
10109
|
+
if (b.type === "image")
|
|
10110
|
+
continue;
|
|
10111
|
+
for (const l of b.lines ?? []) {
|
|
10112
|
+
const text = l.text ?? "";
|
|
10113
|
+
if (!text.trim() || !l.bbox)
|
|
10114
|
+
continue;
|
|
10115
|
+
lines.push({
|
|
10116
|
+
x: l.bbox.x ?? 0,
|
|
10117
|
+
y: l.bbox.y ?? 0,
|
|
10118
|
+
w: l.bbox.w ?? 0,
|
|
10119
|
+
h: l.bbox.h ?? 0,
|
|
10120
|
+
size: l.font?.size ?? 12,
|
|
10121
|
+
text
|
|
10122
|
+
});
|
|
10123
|
+
}
|
|
10124
|
+
}
|
|
10125
|
+
out.push({ page: p, width: x1 - x0, height: y1 - y0, lines });
|
|
10126
|
+
}
|
|
10127
|
+
return out;
|
|
10128
|
+
}
|
|
10129
|
+
async function renderPdfPages(bytes, pages, scale = 2, maxEdge) {
|
|
10130
|
+
const { mupdf, doc } = await openDoc(bytes);
|
|
10131
|
+
const total = doc.countPages();
|
|
10132
|
+
const wanted = pages === "all" ? Array.from({ length: total }, (_, i) => i + 1) : pages;
|
|
10133
|
+
const out = [];
|
|
10134
|
+
for (const p of wanted) {
|
|
10135
|
+
if (p < 1 || p > total)
|
|
10136
|
+
continue;
|
|
10137
|
+
const page = doc.loadPage(p - 1);
|
|
10138
|
+
const [x0, y0, x1, y1] = page.getBounds();
|
|
10139
|
+
const longest = Math.max(x1 - x0, y1 - y0);
|
|
10140
|
+
const s = maxEdge && longest > 0 ? Math.min(scale, maxEdge / longest) : scale;
|
|
10141
|
+
const pix = page.toPixmap(mupdf.Matrix.scale(s, s), mupdf.ColorSpace.DeviceRGB, false, true);
|
|
10142
|
+
out.push({ page: p, png: pix.asPNG() });
|
|
10143
|
+
}
|
|
10144
|
+
return out;
|
|
10145
|
+
}
|
|
10146
|
+
async function extractPdfImages(bytes, pages) {
|
|
10147
|
+
const { doc } = await openDoc(bytes);
|
|
10148
|
+
const total = doc.countPages();
|
|
10149
|
+
const wanted = pages && pages.length ? pages : Array.from({ length: total }, (_, i) => i + 1);
|
|
10150
|
+
const images = [];
|
|
10151
|
+
let skipped = 0;
|
|
10152
|
+
for (const p of wanted) {
|
|
10153
|
+
if (p < 1 || p > total)
|
|
10154
|
+
continue;
|
|
10155
|
+
const stext = doc.loadPage(p - 1).toStructuredText("preserve-images");
|
|
10156
|
+
let index = 0;
|
|
10157
|
+
stext.walk({
|
|
10158
|
+
onImageBlock(bbox, _matrix, image) {
|
|
10159
|
+
const slot = index++;
|
|
10160
|
+
try {
|
|
10161
|
+
const png = image.toPixmap().asPNG();
|
|
10162
|
+
images.push({
|
|
10163
|
+
page: p,
|
|
10164
|
+
index: slot,
|
|
10165
|
+
bbox: [bbox[0], bbox[1], bbox[2], bbox[3]],
|
|
10166
|
+
width: image.getWidth(),
|
|
10167
|
+
height: image.getHeight(),
|
|
10168
|
+
png
|
|
10169
|
+
});
|
|
10170
|
+
} catch {
|
|
10171
|
+
skipped++;
|
|
10172
|
+
}
|
|
10173
|
+
}
|
|
10174
|
+
});
|
|
10175
|
+
}
|
|
10176
|
+
return { images, skipped };
|
|
10177
|
+
}
|
|
10178
|
+
async function encryptPdf(bytes, userPassword, ownerPassword) {
|
|
10179
|
+
if (!userPassword)
|
|
10180
|
+
throw new Error("a non-empty user password is required");
|
|
10181
|
+
const { doc } = await openDoc(bytes);
|
|
10182
|
+
const opts = `encrypt=aes-256,user-password=${userPassword},owner-password=${ownerPassword || userPassword}`;
|
|
10183
|
+
return doc.saveToBuffer(opts).asUint8Array();
|
|
10184
|
+
}
|
|
10185
|
+
async function pdfNeedsPassword(bytes) {
|
|
10186
|
+
const mupdf = await loadMupdf();
|
|
10187
|
+
const doc = mupdf.Document.openDocument(bytes, "application/pdf");
|
|
10188
|
+
return doc.needsPassword();
|
|
10189
|
+
}
|
|
10190
|
+
async function decryptPdf(bytes, password) {
|
|
10191
|
+
const mupdf = await loadMupdf();
|
|
10192
|
+
const doc = mupdf.Document.openDocument(bytes, "application/pdf");
|
|
10193
|
+
if (doc.needsPassword()) {
|
|
10194
|
+
if (doc.authenticatePassword(password) === 0)
|
|
10195
|
+
throw new Error("wrong password");
|
|
10196
|
+
}
|
|
10197
|
+
if (doc.countPages() === 0)
|
|
10198
|
+
throw new Error("PDF has no readable pages (corrupt or empty)");
|
|
10199
|
+
return doc.saveToBuffer("encrypt=none").asUint8Array();
|
|
10200
|
+
}
|
|
10201
|
+
var import_node_path, import_node_url, _mupdf, MATH_CHARS;
|
|
10202
|
+
var init_pdf_extract = __esm({
|
|
10203
|
+
"packages/core/dist/document/pdf-extract.js"() {
|
|
10204
|
+
"use strict";
|
|
10205
|
+
import_node_path = require("node:path");
|
|
10206
|
+
import_node_url = require("node:url");
|
|
10207
|
+
init_pdf_encrypted();
|
|
10208
|
+
_mupdf = null;
|
|
10209
|
+
MATH_CHARS = /[=∑∫√≤≥≠±∞πθλμσΩ×÷∂∇→←↔∈∉⊂⊃∀∃]/g;
|
|
10210
|
+
}
|
|
10211
|
+
});
|
|
10212
|
+
|
|
9826
10213
|
// node_modules/pdf-lib/node_modules/tslib/tslib.es6.js
|
|
9827
10214
|
var tslib_es6_exports = {};
|
|
9828
10215
|
__export(tslib_es6_exports, {
|
|
@@ -12239,11 +12626,11 @@ var require_PDFName = __commonJS({
|
|
|
12239
12626
|
};
|
|
12240
12627
|
var ENFORCER = {};
|
|
12241
12628
|
var pool = /* @__PURE__ */ new Map();
|
|
12242
|
-
var
|
|
12629
|
+
var PDFName2 = (
|
|
12243
12630
|
/** @class */
|
|
12244
12631
|
(function(_super) {
|
|
12245
|
-
tslib_1.__extends(
|
|
12246
|
-
function
|
|
12632
|
+
tslib_1.__extends(PDFName3, _super);
|
|
12633
|
+
function PDFName3(enforcer, name) {
|
|
12247
12634
|
var _this = this;
|
|
12248
12635
|
if (enforcer !== ENFORCER)
|
|
12249
12636
|
throw new errors_1.PrivateConstructorError("PDFName");
|
|
@@ -12257,7 +12644,7 @@ var require_PDFName = __commonJS({
|
|
|
12257
12644
|
_this.encodedName = encodedName;
|
|
12258
12645
|
return _this;
|
|
12259
12646
|
}
|
|
12260
|
-
|
|
12647
|
+
PDFName3.prototype.asBytes = function() {
|
|
12261
12648
|
var bytes = [];
|
|
12262
12649
|
var hex = "";
|
|
12263
12650
|
var escaped = false;
|
|
@@ -12289,67 +12676,67 @@ var require_PDFName = __commonJS({
|
|
|
12289
12676
|
}
|
|
12290
12677
|
return new Uint8Array(bytes);
|
|
12291
12678
|
};
|
|
12292
|
-
|
|
12679
|
+
PDFName3.prototype.decodeText = function() {
|
|
12293
12680
|
var bytes = this.asBytes();
|
|
12294
12681
|
return String.fromCharCode.apply(String, Array.from(bytes));
|
|
12295
12682
|
};
|
|
12296
|
-
|
|
12683
|
+
PDFName3.prototype.asString = function() {
|
|
12297
12684
|
return this.encodedName;
|
|
12298
12685
|
};
|
|
12299
|
-
|
|
12686
|
+
PDFName3.prototype.value = function() {
|
|
12300
12687
|
return this.encodedName;
|
|
12301
12688
|
};
|
|
12302
|
-
|
|
12689
|
+
PDFName3.prototype.clone = function() {
|
|
12303
12690
|
return this;
|
|
12304
12691
|
};
|
|
12305
|
-
|
|
12692
|
+
PDFName3.prototype.toString = function() {
|
|
12306
12693
|
return this.encodedName;
|
|
12307
12694
|
};
|
|
12308
|
-
|
|
12695
|
+
PDFName3.prototype.sizeInBytes = function() {
|
|
12309
12696
|
return this.encodedName.length;
|
|
12310
12697
|
};
|
|
12311
|
-
|
|
12698
|
+
PDFName3.prototype.copyBytesInto = function(buffer, offset) {
|
|
12312
12699
|
offset += utils_1.copyStringIntoBuffer(this.encodedName, buffer, offset);
|
|
12313
12700
|
return this.encodedName.length;
|
|
12314
12701
|
};
|
|
12315
|
-
|
|
12702
|
+
PDFName3.of = function(name) {
|
|
12316
12703
|
var decodedValue = decodeName(name);
|
|
12317
12704
|
var instance = pool.get(decodedValue);
|
|
12318
12705
|
if (!instance) {
|
|
12319
|
-
instance = new
|
|
12706
|
+
instance = new PDFName3(ENFORCER, decodedValue);
|
|
12320
12707
|
pool.set(decodedValue, instance);
|
|
12321
12708
|
}
|
|
12322
12709
|
return instance;
|
|
12323
12710
|
};
|
|
12324
|
-
|
|
12325
|
-
|
|
12326
|
-
|
|
12327
|
-
|
|
12328
|
-
|
|
12329
|
-
|
|
12330
|
-
|
|
12331
|
-
|
|
12332
|
-
|
|
12333
|
-
|
|
12334
|
-
|
|
12335
|
-
|
|
12336
|
-
|
|
12337
|
-
|
|
12338
|
-
|
|
12339
|
-
|
|
12340
|
-
|
|
12341
|
-
|
|
12342
|
-
|
|
12343
|
-
|
|
12344
|
-
|
|
12345
|
-
|
|
12346
|
-
|
|
12347
|
-
|
|
12348
|
-
|
|
12349
|
-
return
|
|
12711
|
+
PDFName3.Length = PDFName3.of("Length");
|
|
12712
|
+
PDFName3.FlateDecode = PDFName3.of("FlateDecode");
|
|
12713
|
+
PDFName3.Resources = PDFName3.of("Resources");
|
|
12714
|
+
PDFName3.Font = PDFName3.of("Font");
|
|
12715
|
+
PDFName3.XObject = PDFName3.of("XObject");
|
|
12716
|
+
PDFName3.ExtGState = PDFName3.of("ExtGState");
|
|
12717
|
+
PDFName3.Contents = PDFName3.of("Contents");
|
|
12718
|
+
PDFName3.Type = PDFName3.of("Type");
|
|
12719
|
+
PDFName3.Parent = PDFName3.of("Parent");
|
|
12720
|
+
PDFName3.MediaBox = PDFName3.of("MediaBox");
|
|
12721
|
+
PDFName3.Page = PDFName3.of("Page");
|
|
12722
|
+
PDFName3.Annots = PDFName3.of("Annots");
|
|
12723
|
+
PDFName3.TrimBox = PDFName3.of("TrimBox");
|
|
12724
|
+
PDFName3.ArtBox = PDFName3.of("ArtBox");
|
|
12725
|
+
PDFName3.BleedBox = PDFName3.of("BleedBox");
|
|
12726
|
+
PDFName3.CropBox = PDFName3.of("CropBox");
|
|
12727
|
+
PDFName3.Rotate = PDFName3.of("Rotate");
|
|
12728
|
+
PDFName3.Title = PDFName3.of("Title");
|
|
12729
|
+
PDFName3.Author = PDFName3.of("Author");
|
|
12730
|
+
PDFName3.Subject = PDFName3.of("Subject");
|
|
12731
|
+
PDFName3.Creator = PDFName3.of("Creator");
|
|
12732
|
+
PDFName3.Keywords = PDFName3.of("Keywords");
|
|
12733
|
+
PDFName3.Producer = PDFName3.of("Producer");
|
|
12734
|
+
PDFName3.CreationDate = PDFName3.of("CreationDate");
|
|
12735
|
+
PDFName3.ModDate = PDFName3.of("ModDate");
|
|
12736
|
+
return PDFName3;
|
|
12350
12737
|
})(PDFObject_1.default)
|
|
12351
12738
|
);
|
|
12352
|
-
exports2.default =
|
|
12739
|
+
exports2.default = PDFName2;
|
|
12353
12740
|
}
|
|
12354
12741
|
});
|
|
12355
12742
|
|
|
@@ -12404,29 +12791,29 @@ var require_PDFDict = __commonJS({
|
|
|
12404
12791
|
var PDFNull_1 = tslib_1.__importDefault(require_PDFNull());
|
|
12405
12792
|
var PDFObject_1 = tslib_1.__importDefault(require_PDFObject());
|
|
12406
12793
|
var CharCodes_1 = tslib_1.__importDefault(require_CharCodes());
|
|
12407
|
-
var
|
|
12794
|
+
var PDFDict2 = (
|
|
12408
12795
|
/** @class */
|
|
12409
12796
|
(function(_super) {
|
|
12410
|
-
tslib_1.__extends(
|
|
12411
|
-
function
|
|
12797
|
+
tslib_1.__extends(PDFDict3, _super);
|
|
12798
|
+
function PDFDict3(map, context) {
|
|
12412
12799
|
var _this = _super.call(this) || this;
|
|
12413
12800
|
_this.dict = map;
|
|
12414
12801
|
_this.context = context;
|
|
12415
12802
|
return _this;
|
|
12416
12803
|
}
|
|
12417
|
-
|
|
12804
|
+
PDFDict3.prototype.keys = function() {
|
|
12418
12805
|
return Array.from(this.dict.keys());
|
|
12419
12806
|
};
|
|
12420
|
-
|
|
12807
|
+
PDFDict3.prototype.values = function() {
|
|
12421
12808
|
return Array.from(this.dict.values());
|
|
12422
12809
|
};
|
|
12423
|
-
|
|
12810
|
+
PDFDict3.prototype.entries = function() {
|
|
12424
12811
|
return Array.from(this.dict.entries());
|
|
12425
12812
|
};
|
|
12426
|
-
|
|
12813
|
+
PDFDict3.prototype.set = function(key, value) {
|
|
12427
12814
|
this.dict.set(key, value);
|
|
12428
12815
|
};
|
|
12429
|
-
|
|
12816
|
+
PDFDict3.prototype.get = function(key, preservePDFNull) {
|
|
12430
12817
|
if (preservePDFNull === void 0) {
|
|
12431
12818
|
preservePDFNull = false;
|
|
12432
12819
|
}
|
|
@@ -12435,11 +12822,11 @@ var require_PDFDict = __commonJS({
|
|
|
12435
12822
|
return void 0;
|
|
12436
12823
|
return value;
|
|
12437
12824
|
};
|
|
12438
|
-
|
|
12825
|
+
PDFDict3.prototype.has = function(key) {
|
|
12439
12826
|
var value = this.dict.get(key);
|
|
12440
12827
|
return value !== void 0 && value !== PDFNull_1.default;
|
|
12441
12828
|
};
|
|
12442
|
-
|
|
12829
|
+
PDFDict3.prototype.lookupMaybe = function(key) {
|
|
12443
12830
|
var _a;
|
|
12444
12831
|
var types = [];
|
|
12445
12832
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
@@ -12451,7 +12838,7 @@ var require_PDFDict = __commonJS({
|
|
|
12451
12838
|
return void 0;
|
|
12452
12839
|
return value;
|
|
12453
12840
|
};
|
|
12454
|
-
|
|
12841
|
+
PDFDict3.prototype.lookup = function(key) {
|
|
12455
12842
|
var _a;
|
|
12456
12843
|
var types = [];
|
|
12457
12844
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
@@ -12463,13 +12850,13 @@ var require_PDFDict = __commonJS({
|
|
|
12463
12850
|
return void 0;
|
|
12464
12851
|
return value;
|
|
12465
12852
|
};
|
|
12466
|
-
|
|
12853
|
+
PDFDict3.prototype.delete = function(key) {
|
|
12467
12854
|
return this.dict.delete(key);
|
|
12468
12855
|
};
|
|
12469
|
-
|
|
12856
|
+
PDFDict3.prototype.asMap = function() {
|
|
12470
12857
|
return new Map(this.dict);
|
|
12471
12858
|
};
|
|
12472
|
-
|
|
12859
|
+
PDFDict3.prototype.uniqueKey = function(tag) {
|
|
12473
12860
|
if (tag === void 0) {
|
|
12474
12861
|
tag = "";
|
|
12475
12862
|
}
|
|
@@ -12480,8 +12867,8 @@ var require_PDFDict = __commonJS({
|
|
|
12480
12867
|
}
|
|
12481
12868
|
return key;
|
|
12482
12869
|
};
|
|
12483
|
-
|
|
12484
|
-
var clone =
|
|
12870
|
+
PDFDict3.prototype.clone = function(context) {
|
|
12871
|
+
var clone = PDFDict3.withContext(context || this.context);
|
|
12485
12872
|
var entries = this.entries();
|
|
12486
12873
|
for (var idx = 0, len = entries.length; idx < len; idx++) {
|
|
12487
12874
|
var _a = entries[idx], key = _a[0], value = _a[1];
|
|
@@ -12489,7 +12876,7 @@ var require_PDFDict = __commonJS({
|
|
|
12489
12876
|
}
|
|
12490
12877
|
return clone;
|
|
12491
12878
|
};
|
|
12492
|
-
|
|
12879
|
+
PDFDict3.prototype.toString = function() {
|
|
12493
12880
|
var dictString = "<<\n";
|
|
12494
12881
|
var entries = this.entries();
|
|
12495
12882
|
for (var idx = 0, len = entries.length; idx < len; idx++) {
|
|
@@ -12499,7 +12886,7 @@ var require_PDFDict = __commonJS({
|
|
|
12499
12886
|
dictString += ">>";
|
|
12500
12887
|
return dictString;
|
|
12501
12888
|
};
|
|
12502
|
-
|
|
12889
|
+
PDFDict3.prototype.sizeInBytes = function() {
|
|
12503
12890
|
var size = 5;
|
|
12504
12891
|
var entries = this.entries();
|
|
12505
12892
|
for (var idx = 0, len = entries.length; idx < len; idx++) {
|
|
@@ -12508,7 +12895,7 @@ var require_PDFDict = __commonJS({
|
|
|
12508
12895
|
}
|
|
12509
12896
|
return size;
|
|
12510
12897
|
};
|
|
12511
|
-
|
|
12898
|
+
PDFDict3.prototype.copyBytesInto = function(buffer, offset) {
|
|
12512
12899
|
var initialOffset = offset;
|
|
12513
12900
|
buffer[offset++] = CharCodes_1.default.LessThan;
|
|
12514
12901
|
buffer[offset++] = CharCodes_1.default.LessThan;
|
|
@@ -12525,16 +12912,16 @@ var require_PDFDict = __commonJS({
|
|
|
12525
12912
|
buffer[offset++] = CharCodes_1.default.GreaterThan;
|
|
12526
12913
|
return offset - initialOffset;
|
|
12527
12914
|
};
|
|
12528
|
-
|
|
12529
|
-
return new
|
|
12915
|
+
PDFDict3.withContext = function(context) {
|
|
12916
|
+
return new PDFDict3(/* @__PURE__ */ new Map(), context);
|
|
12530
12917
|
};
|
|
12531
|
-
|
|
12532
|
-
return new
|
|
12918
|
+
PDFDict3.fromMapWithContext = function(map, context) {
|
|
12919
|
+
return new PDFDict3(map, context);
|
|
12533
12920
|
};
|
|
12534
|
-
return
|
|
12921
|
+
return PDFDict3;
|
|
12535
12922
|
})(PDFObject_1.default)
|
|
12536
12923
|
);
|
|
12537
|
-
exports2.default =
|
|
12924
|
+
exports2.default = PDFDict2;
|
|
12538
12925
|
}
|
|
12539
12926
|
});
|
|
12540
12927
|
|
|
@@ -12549,36 +12936,36 @@ var require_PDFStream = __commonJS({
|
|
|
12549
12936
|
var PDFNumber_1 = tslib_1.__importDefault(require_PDFNumber());
|
|
12550
12937
|
var PDFObject_1 = tslib_1.__importDefault(require_PDFObject());
|
|
12551
12938
|
var CharCodes_1 = tslib_1.__importDefault(require_CharCodes());
|
|
12552
|
-
var
|
|
12939
|
+
var PDFStream2 = (
|
|
12553
12940
|
/** @class */
|
|
12554
12941
|
(function(_super) {
|
|
12555
|
-
tslib_1.__extends(
|
|
12556
|
-
function
|
|
12942
|
+
tslib_1.__extends(PDFStream3, _super);
|
|
12943
|
+
function PDFStream3(dict) {
|
|
12557
12944
|
var _this = _super.call(this) || this;
|
|
12558
12945
|
_this.dict = dict;
|
|
12559
12946
|
return _this;
|
|
12560
12947
|
}
|
|
12561
|
-
|
|
12948
|
+
PDFStream3.prototype.clone = function(_context) {
|
|
12562
12949
|
throw new errors_1.MethodNotImplementedError(this.constructor.name, "clone");
|
|
12563
12950
|
};
|
|
12564
|
-
|
|
12951
|
+
PDFStream3.prototype.getContentsString = function() {
|
|
12565
12952
|
throw new errors_1.MethodNotImplementedError(this.constructor.name, "getContentsString");
|
|
12566
12953
|
};
|
|
12567
|
-
|
|
12954
|
+
PDFStream3.prototype.getContents = function() {
|
|
12568
12955
|
throw new errors_1.MethodNotImplementedError(this.constructor.name, "getContents");
|
|
12569
12956
|
};
|
|
12570
|
-
|
|
12957
|
+
PDFStream3.prototype.getContentsSize = function() {
|
|
12571
12958
|
throw new errors_1.MethodNotImplementedError(this.constructor.name, "getContentsSize");
|
|
12572
12959
|
};
|
|
12573
|
-
|
|
12960
|
+
PDFStream3.prototype.updateDict = function() {
|
|
12574
12961
|
var contentsSize = this.getContentsSize();
|
|
12575
12962
|
this.dict.set(PDFName_1.default.Length, PDFNumber_1.default.of(contentsSize));
|
|
12576
12963
|
};
|
|
12577
|
-
|
|
12964
|
+
PDFStream3.prototype.sizeInBytes = function() {
|
|
12578
12965
|
this.updateDict();
|
|
12579
12966
|
return this.dict.sizeInBytes() + this.getContentsSize() + 18;
|
|
12580
12967
|
};
|
|
12581
|
-
|
|
12968
|
+
PDFStream3.prototype.toString = function() {
|
|
12582
12969
|
this.updateDict();
|
|
12583
12970
|
var streamString = this.dict.toString();
|
|
12584
12971
|
streamString += "\nstream\n";
|
|
@@ -12586,7 +12973,7 @@ var require_PDFStream = __commonJS({
|
|
|
12586
12973
|
streamString += "\nendstream";
|
|
12587
12974
|
return streamString;
|
|
12588
12975
|
};
|
|
12589
|
-
|
|
12976
|
+
PDFStream3.prototype.copyBytesInto = function(buffer, offset) {
|
|
12590
12977
|
this.updateDict();
|
|
12591
12978
|
var initialOffset = offset;
|
|
12592
12979
|
offset += this.dict.copyBytesInto(buffer, offset);
|
|
@@ -12614,10 +13001,10 @@ var require_PDFStream = __commonJS({
|
|
|
12614
13001
|
buffer[offset++] = CharCodes_1.default.m;
|
|
12615
13002
|
return offset - initialOffset;
|
|
12616
13003
|
};
|
|
12617
|
-
return
|
|
13004
|
+
return PDFStream3;
|
|
12618
13005
|
})(PDFObject_1.default)
|
|
12619
13006
|
);
|
|
12620
|
-
exports2.default =
|
|
13007
|
+
exports2.default = PDFStream2;
|
|
12621
13008
|
}
|
|
12622
13009
|
});
|
|
12623
13010
|
|
|
@@ -12629,37 +13016,37 @@ var require_PDFRawStream = __commonJS({
|
|
|
12629
13016
|
var tslib_1 = (init_tslib_es6(), __toCommonJS(tslib_es6_exports));
|
|
12630
13017
|
var PDFStream_1 = tslib_1.__importDefault(require_PDFStream());
|
|
12631
13018
|
var utils_1 = require_utils3();
|
|
12632
|
-
var
|
|
13019
|
+
var PDFRawStream2 = (
|
|
12633
13020
|
/** @class */
|
|
12634
13021
|
(function(_super) {
|
|
12635
|
-
tslib_1.__extends(
|
|
12636
|
-
function
|
|
13022
|
+
tslib_1.__extends(PDFRawStream3, _super);
|
|
13023
|
+
function PDFRawStream3(dict, contents) {
|
|
12637
13024
|
var _this = _super.call(this, dict) || this;
|
|
12638
13025
|
_this.contents = contents;
|
|
12639
13026
|
return _this;
|
|
12640
13027
|
}
|
|
12641
|
-
|
|
13028
|
+
PDFRawStream3.prototype.asUint8Array = function() {
|
|
12642
13029
|
return this.contents.slice();
|
|
12643
13030
|
};
|
|
12644
|
-
|
|
12645
|
-
return
|
|
13031
|
+
PDFRawStream3.prototype.clone = function(context) {
|
|
13032
|
+
return PDFRawStream3.of(this.dict.clone(context), this.contents.slice());
|
|
12646
13033
|
};
|
|
12647
|
-
|
|
13034
|
+
PDFRawStream3.prototype.getContentsString = function() {
|
|
12648
13035
|
return utils_1.arrayAsString(this.contents);
|
|
12649
13036
|
};
|
|
12650
|
-
|
|
13037
|
+
PDFRawStream3.prototype.getContents = function() {
|
|
12651
13038
|
return this.contents;
|
|
12652
13039
|
};
|
|
12653
|
-
|
|
13040
|
+
PDFRawStream3.prototype.getContentsSize = function() {
|
|
12654
13041
|
return this.contents.length;
|
|
12655
13042
|
};
|
|
12656
|
-
|
|
12657
|
-
return new
|
|
13043
|
+
PDFRawStream3.of = function(dict, contents) {
|
|
13044
|
+
return new PDFRawStream3(dict, contents);
|
|
12658
13045
|
};
|
|
12659
|
-
return
|
|
13046
|
+
return PDFRawStream3;
|
|
12660
13047
|
})(PDFStream_1.default)
|
|
12661
13048
|
);
|
|
12662
|
-
exports2.default =
|
|
13049
|
+
exports2.default = PDFRawStream2;
|
|
12663
13050
|
}
|
|
12664
13051
|
});
|
|
12665
13052
|
|
|
@@ -12674,11 +13061,11 @@ var require_PDFRef = __commonJS({
|
|
|
12674
13061
|
var utils_1 = require_utils3();
|
|
12675
13062
|
var ENFORCER = {};
|
|
12676
13063
|
var pool = /* @__PURE__ */ new Map();
|
|
12677
|
-
var
|
|
13064
|
+
var PDFRef2 = (
|
|
12678
13065
|
/** @class */
|
|
12679
13066
|
(function(_super) {
|
|
12680
|
-
tslib_1.__extends(
|
|
12681
|
-
function
|
|
13067
|
+
tslib_1.__extends(PDFRef3, _super);
|
|
13068
|
+
function PDFRef3(enforcer, objectNumber, generationNumber) {
|
|
12682
13069
|
var _this = this;
|
|
12683
13070
|
if (enforcer !== ENFORCER)
|
|
12684
13071
|
throw new errors_1.PrivateConstructorError("PDFRef");
|
|
@@ -12688,35 +13075,35 @@ var require_PDFRef = __commonJS({
|
|
|
12688
13075
|
_this.tag = objectNumber + " " + generationNumber + " R";
|
|
12689
13076
|
return _this;
|
|
12690
13077
|
}
|
|
12691
|
-
|
|
13078
|
+
PDFRef3.prototype.clone = function() {
|
|
12692
13079
|
return this;
|
|
12693
13080
|
};
|
|
12694
|
-
|
|
13081
|
+
PDFRef3.prototype.toString = function() {
|
|
12695
13082
|
return this.tag;
|
|
12696
13083
|
};
|
|
12697
|
-
|
|
13084
|
+
PDFRef3.prototype.sizeInBytes = function() {
|
|
12698
13085
|
return this.tag.length;
|
|
12699
13086
|
};
|
|
12700
|
-
|
|
13087
|
+
PDFRef3.prototype.copyBytesInto = function(buffer, offset) {
|
|
12701
13088
|
offset += utils_1.copyStringIntoBuffer(this.tag, buffer, offset);
|
|
12702
13089
|
return this.tag.length;
|
|
12703
13090
|
};
|
|
12704
|
-
|
|
13091
|
+
PDFRef3.of = function(objectNumber, generationNumber) {
|
|
12705
13092
|
if (generationNumber === void 0) {
|
|
12706
13093
|
generationNumber = 0;
|
|
12707
13094
|
}
|
|
12708
13095
|
var tag = objectNumber + " " + generationNumber + " R";
|
|
12709
13096
|
var instance = pool.get(tag);
|
|
12710
13097
|
if (!instance) {
|
|
12711
|
-
instance = new
|
|
13098
|
+
instance = new PDFRef3(ENFORCER, objectNumber, generationNumber);
|
|
12712
13099
|
pool.set(tag, instance);
|
|
12713
13100
|
}
|
|
12714
13101
|
return instance;
|
|
12715
13102
|
};
|
|
12716
|
-
return
|
|
13103
|
+
return PDFRef3;
|
|
12717
13104
|
})(PDFObject_1.default)
|
|
12718
13105
|
);
|
|
12719
|
-
exports2.default =
|
|
13106
|
+
exports2.default = PDFRef2;
|
|
12720
13107
|
}
|
|
12721
13108
|
});
|
|
12722
13109
|
|
|
@@ -18354,14 +18741,14 @@ var require_decode = __commonJS({
|
|
|
18354
18741
|
var LZWStream_1 = tslib_1.__importDefault(require_LZWStream());
|
|
18355
18742
|
var RunLengthStream_1 = tslib_1.__importDefault(require_RunLengthStream());
|
|
18356
18743
|
var Stream_1 = tslib_1.__importDefault(require_Stream());
|
|
18357
|
-
var decodeStream = function(stream, encoding,
|
|
18744
|
+
var decodeStream = function(stream, encoding, params2) {
|
|
18358
18745
|
if (encoding === PDFName_1.default.of("FlateDecode")) {
|
|
18359
18746
|
return new FlateStream_1.default(stream);
|
|
18360
18747
|
}
|
|
18361
18748
|
if (encoding === PDFName_1.default.of("LZWDecode")) {
|
|
18362
18749
|
var earlyChange = 1;
|
|
18363
|
-
if (
|
|
18364
|
-
var EarlyChange =
|
|
18750
|
+
if (params2 instanceof PDFDict_1.default) {
|
|
18751
|
+
var EarlyChange = params2.lookup(PDFName_1.default.of("EarlyChange"));
|
|
18365
18752
|
if (EarlyChange instanceof PDFNumber_1.default) {
|
|
18366
18753
|
earlyChange = EarlyChange.asNumber();
|
|
18367
18754
|
}
|
|
@@ -22243,11 +22630,11 @@ var require_svgPath = __commonJS({
|
|
|
22243
22630
|
var args = [];
|
|
22244
22631
|
var curArg = "";
|
|
22245
22632
|
var foundDecimal = false;
|
|
22246
|
-
var
|
|
22633
|
+
var params2 = 0;
|
|
22247
22634
|
for (var _i = 0, path_1 = path; _i < path_1.length; _i++) {
|
|
22248
22635
|
var c = path_1[_i];
|
|
22249
22636
|
if (parameters.has(c)) {
|
|
22250
|
-
|
|
22637
|
+
params2 = parameters.get(c);
|
|
22251
22638
|
if (cmd) {
|
|
22252
22639
|
if (curArg.length > 0) {
|
|
22253
22640
|
args[args.length] = +curArg;
|
|
@@ -22262,7 +22649,7 @@ var require_svgPath = __commonJS({
|
|
|
22262
22649
|
if (curArg.length === 0) {
|
|
22263
22650
|
continue;
|
|
22264
22651
|
}
|
|
22265
|
-
if (args.length ===
|
|
22652
|
+
if (args.length === params2) {
|
|
22266
22653
|
ret[ret.length] = { cmd, args };
|
|
22267
22654
|
args = [+curArg];
|
|
22268
22655
|
if (cmd === "M") {
|
|
@@ -22284,7 +22671,7 @@ var require_svgPath = __commonJS({
|
|
|
22284
22671
|
}
|
|
22285
22672
|
}
|
|
22286
22673
|
if (curArg.length > 0) {
|
|
22287
|
-
if (args.length ===
|
|
22674
|
+
if (args.length === params2) {
|
|
22288
22675
|
ret[ret.length] = { cmd, args };
|
|
22289
22676
|
args = [+curArg];
|
|
22290
22677
|
if (cmd === "M") {
|
|
@@ -25965,10 +26352,10 @@ var require_PDFDocument = __commonJS({
|
|
|
25965
26352
|
var PDFEmbeddedFile_1 = tslib_1.__importDefault(require_PDFEmbeddedFile());
|
|
25966
26353
|
var PDFJavaScript_1 = tslib_1.__importDefault(require_PDFJavaScript());
|
|
25967
26354
|
var JavaScriptEmbedder_1 = tslib_1.__importDefault(require_JavaScriptEmbedder());
|
|
25968
|
-
var
|
|
26355
|
+
var PDFDocument3 = (
|
|
25969
26356
|
/** @class */
|
|
25970
26357
|
(function() {
|
|
25971
|
-
function
|
|
26358
|
+
function PDFDocument4(context, ignoreEncryption, updateMetadata) {
|
|
25972
26359
|
var _this = this;
|
|
25973
26360
|
this.defaultWordBreaks = [" "];
|
|
25974
26361
|
this.computePages = function() {
|
|
@@ -26007,7 +26394,7 @@ var require_PDFDocument = __commonJS({
|
|
|
26007
26394
|
if (updateMetadata)
|
|
26008
26395
|
this.updateInfoDict();
|
|
26009
26396
|
}
|
|
26010
|
-
|
|
26397
|
+
PDFDocument4.load = function(pdf, options) {
|
|
26011
26398
|
if (options === void 0) {
|
|
26012
26399
|
options = {};
|
|
26013
26400
|
}
|
|
@@ -26025,12 +26412,12 @@ var require_PDFDocument = __commonJS({
|
|
|
26025
26412
|
return [4, core_1.PDFParser.forBytesWithOptions(bytes, parseSpeed, throwOnInvalidObject, capNumbers).parseDocument()];
|
|
26026
26413
|
case 1:
|
|
26027
26414
|
context = _f.sent();
|
|
26028
|
-
return [2, new
|
|
26415
|
+
return [2, new PDFDocument4(context, ignoreEncryption, updateMetadata)];
|
|
26029
26416
|
}
|
|
26030
26417
|
});
|
|
26031
26418
|
});
|
|
26032
26419
|
};
|
|
26033
|
-
|
|
26420
|
+
PDFDocument4.create = function(options) {
|
|
26034
26421
|
if (options === void 0) {
|
|
26035
26422
|
options = {};
|
|
26036
26423
|
}
|
|
@@ -26043,14 +26430,14 @@ var require_PDFDocument = __commonJS({
|
|
|
26043
26430
|
pageTreeRef = context.register(pageTree);
|
|
26044
26431
|
catalog = core_1.PDFCatalog.withContextAndPages(context, pageTreeRef);
|
|
26045
26432
|
context.trailerInfo.Root = context.register(catalog);
|
|
26046
|
-
return [2, new
|
|
26433
|
+
return [2, new PDFDocument4(context, false, updateMetadata)];
|
|
26047
26434
|
});
|
|
26048
26435
|
});
|
|
26049
26436
|
};
|
|
26050
|
-
|
|
26437
|
+
PDFDocument4.prototype.registerFontkit = function(fontkit) {
|
|
26051
26438
|
this.fontkit = fontkit;
|
|
26052
26439
|
};
|
|
26053
|
-
|
|
26440
|
+
PDFDocument4.prototype.getForm = function() {
|
|
26054
26441
|
var form = this.formCache.access();
|
|
26055
26442
|
if (form.hasXFA()) {
|
|
26056
26443
|
console.warn("Removing XFA form data as pdf-lib does not support reading or writing XFA");
|
|
@@ -26058,63 +26445,63 @@ var require_PDFDocument = __commonJS({
|
|
|
26058
26445
|
}
|
|
26059
26446
|
return form;
|
|
26060
26447
|
};
|
|
26061
|
-
|
|
26448
|
+
PDFDocument4.prototype.getTitle = function() {
|
|
26062
26449
|
var title = this.getInfoDict().lookup(core_1.PDFName.Title);
|
|
26063
26450
|
if (!title)
|
|
26064
26451
|
return void 0;
|
|
26065
26452
|
assertIsLiteralOrHexString(title);
|
|
26066
26453
|
return title.decodeText();
|
|
26067
26454
|
};
|
|
26068
|
-
|
|
26455
|
+
PDFDocument4.prototype.getAuthor = function() {
|
|
26069
26456
|
var author = this.getInfoDict().lookup(core_1.PDFName.Author);
|
|
26070
26457
|
if (!author)
|
|
26071
26458
|
return void 0;
|
|
26072
26459
|
assertIsLiteralOrHexString(author);
|
|
26073
26460
|
return author.decodeText();
|
|
26074
26461
|
};
|
|
26075
|
-
|
|
26462
|
+
PDFDocument4.prototype.getSubject = function() {
|
|
26076
26463
|
var subject = this.getInfoDict().lookup(core_1.PDFName.Subject);
|
|
26077
26464
|
if (!subject)
|
|
26078
26465
|
return void 0;
|
|
26079
26466
|
assertIsLiteralOrHexString(subject);
|
|
26080
26467
|
return subject.decodeText();
|
|
26081
26468
|
};
|
|
26082
|
-
|
|
26469
|
+
PDFDocument4.prototype.getKeywords = function() {
|
|
26083
26470
|
var keywords = this.getInfoDict().lookup(core_1.PDFName.Keywords);
|
|
26084
26471
|
if (!keywords)
|
|
26085
26472
|
return void 0;
|
|
26086
26473
|
assertIsLiteralOrHexString(keywords);
|
|
26087
26474
|
return keywords.decodeText();
|
|
26088
26475
|
};
|
|
26089
|
-
|
|
26476
|
+
PDFDocument4.prototype.getCreator = function() {
|
|
26090
26477
|
var creator = this.getInfoDict().lookup(core_1.PDFName.Creator);
|
|
26091
26478
|
if (!creator)
|
|
26092
26479
|
return void 0;
|
|
26093
26480
|
assertIsLiteralOrHexString(creator);
|
|
26094
26481
|
return creator.decodeText();
|
|
26095
26482
|
};
|
|
26096
|
-
|
|
26483
|
+
PDFDocument4.prototype.getProducer = function() {
|
|
26097
26484
|
var producer = this.getInfoDict().lookup(core_1.PDFName.Producer);
|
|
26098
26485
|
if (!producer)
|
|
26099
26486
|
return void 0;
|
|
26100
26487
|
assertIsLiteralOrHexString(producer);
|
|
26101
26488
|
return producer.decodeText();
|
|
26102
26489
|
};
|
|
26103
|
-
|
|
26490
|
+
PDFDocument4.prototype.getCreationDate = function() {
|
|
26104
26491
|
var creationDate = this.getInfoDict().lookup(core_1.PDFName.CreationDate);
|
|
26105
26492
|
if (!creationDate)
|
|
26106
26493
|
return void 0;
|
|
26107
26494
|
assertIsLiteralOrHexString(creationDate);
|
|
26108
26495
|
return creationDate.decodeDate();
|
|
26109
26496
|
};
|
|
26110
|
-
|
|
26497
|
+
PDFDocument4.prototype.getModificationDate = function() {
|
|
26111
26498
|
var modificationDate = this.getInfoDict().lookup(core_1.PDFName.ModDate);
|
|
26112
26499
|
if (!modificationDate)
|
|
26113
26500
|
return void 0;
|
|
26114
26501
|
assertIsLiteralOrHexString(modificationDate);
|
|
26115
26502
|
return modificationDate.decodeDate();
|
|
26116
26503
|
};
|
|
26117
|
-
|
|
26504
|
+
PDFDocument4.prototype.setTitle = function(title, options) {
|
|
26118
26505
|
utils_1.assertIs(title, "title", ["string"]);
|
|
26119
26506
|
var key = core_1.PDFName.of("Title");
|
|
26120
26507
|
this.getInfoDict().set(key, core_1.PDFHexString.fromText(title));
|
|
@@ -26123,63 +26510,63 @@ var require_PDFDocument = __commonJS({
|
|
|
26123
26510
|
prefs.setDisplayDocTitle(true);
|
|
26124
26511
|
}
|
|
26125
26512
|
};
|
|
26126
|
-
|
|
26513
|
+
PDFDocument4.prototype.setAuthor = function(author) {
|
|
26127
26514
|
utils_1.assertIs(author, "author", ["string"]);
|
|
26128
26515
|
var key = core_1.PDFName.of("Author");
|
|
26129
26516
|
this.getInfoDict().set(key, core_1.PDFHexString.fromText(author));
|
|
26130
26517
|
};
|
|
26131
|
-
|
|
26518
|
+
PDFDocument4.prototype.setSubject = function(subject) {
|
|
26132
26519
|
utils_1.assertIs(subject, "author", ["string"]);
|
|
26133
26520
|
var key = core_1.PDFName.of("Subject");
|
|
26134
26521
|
this.getInfoDict().set(key, core_1.PDFHexString.fromText(subject));
|
|
26135
26522
|
};
|
|
26136
|
-
|
|
26523
|
+
PDFDocument4.prototype.setKeywords = function(keywords) {
|
|
26137
26524
|
utils_1.assertIs(keywords, "keywords", [Array]);
|
|
26138
26525
|
var key = core_1.PDFName.of("Keywords");
|
|
26139
26526
|
this.getInfoDict().set(key, core_1.PDFHexString.fromText(keywords.join(" ")));
|
|
26140
26527
|
};
|
|
26141
|
-
|
|
26528
|
+
PDFDocument4.prototype.setCreator = function(creator) {
|
|
26142
26529
|
utils_1.assertIs(creator, "creator", ["string"]);
|
|
26143
26530
|
var key = core_1.PDFName.of("Creator");
|
|
26144
26531
|
this.getInfoDict().set(key, core_1.PDFHexString.fromText(creator));
|
|
26145
26532
|
};
|
|
26146
|
-
|
|
26533
|
+
PDFDocument4.prototype.setProducer = function(producer) {
|
|
26147
26534
|
utils_1.assertIs(producer, "creator", ["string"]);
|
|
26148
26535
|
var key = core_1.PDFName.of("Producer");
|
|
26149
26536
|
this.getInfoDict().set(key, core_1.PDFHexString.fromText(producer));
|
|
26150
26537
|
};
|
|
26151
|
-
|
|
26538
|
+
PDFDocument4.prototype.setLanguage = function(language) {
|
|
26152
26539
|
utils_1.assertIs(language, "language", ["string"]);
|
|
26153
26540
|
var key = core_1.PDFName.of("Lang");
|
|
26154
26541
|
this.catalog.set(key, core_1.PDFString.of(language));
|
|
26155
26542
|
};
|
|
26156
|
-
|
|
26543
|
+
PDFDocument4.prototype.setCreationDate = function(creationDate) {
|
|
26157
26544
|
utils_1.assertIs(creationDate, "creationDate", [[Date, "Date"]]);
|
|
26158
26545
|
var key = core_1.PDFName.of("CreationDate");
|
|
26159
26546
|
this.getInfoDict().set(key, core_1.PDFString.fromDate(creationDate));
|
|
26160
26547
|
};
|
|
26161
|
-
|
|
26548
|
+
PDFDocument4.prototype.setModificationDate = function(modificationDate) {
|
|
26162
26549
|
utils_1.assertIs(modificationDate, "modificationDate", [[Date, "Date"]]);
|
|
26163
26550
|
var key = core_1.PDFName.of("ModDate");
|
|
26164
26551
|
this.getInfoDict().set(key, core_1.PDFString.fromDate(modificationDate));
|
|
26165
26552
|
};
|
|
26166
|
-
|
|
26553
|
+
PDFDocument4.prototype.getPageCount = function() {
|
|
26167
26554
|
if (this.pageCount === void 0)
|
|
26168
26555
|
this.pageCount = this.getPages().length;
|
|
26169
26556
|
return this.pageCount;
|
|
26170
26557
|
};
|
|
26171
|
-
|
|
26558
|
+
PDFDocument4.prototype.getPages = function() {
|
|
26172
26559
|
return this.pageCache.access();
|
|
26173
26560
|
};
|
|
26174
|
-
|
|
26561
|
+
PDFDocument4.prototype.getPage = function(index) {
|
|
26175
26562
|
var pages = this.getPages();
|
|
26176
26563
|
utils_1.assertRange(index, "index", 0, pages.length - 1);
|
|
26177
26564
|
return pages[index];
|
|
26178
26565
|
};
|
|
26179
|
-
|
|
26566
|
+
PDFDocument4.prototype.getPageIndices = function() {
|
|
26180
26567
|
return utils_1.range(0, this.getPageCount());
|
|
26181
26568
|
};
|
|
26182
|
-
|
|
26569
|
+
PDFDocument4.prototype.removePage = function(index) {
|
|
26183
26570
|
var pageCount = this.getPageCount();
|
|
26184
26571
|
if (this.pageCount === 0)
|
|
26185
26572
|
throw new errors_1.RemovePageFromEmptyDocumentError();
|
|
@@ -26187,11 +26574,11 @@ var require_PDFDocument = __commonJS({
|
|
|
26187
26574
|
this.catalog.removeLeafNode(index);
|
|
26188
26575
|
this.pageCount = pageCount - 1;
|
|
26189
26576
|
};
|
|
26190
|
-
|
|
26577
|
+
PDFDocument4.prototype.addPage = function(page) {
|
|
26191
26578
|
utils_1.assertIs(page, "page", ["undefined", [PDFPage_1.default, "PDFPage"], Array]);
|
|
26192
26579
|
return this.insertPage(this.getPageCount(), page);
|
|
26193
26580
|
};
|
|
26194
|
-
|
|
26581
|
+
PDFDocument4.prototype.insertPage = function(index, page) {
|
|
26195
26582
|
var pageCount = this.getPageCount();
|
|
26196
26583
|
utils_1.assertRange(index, "index", 0, pageCount);
|
|
26197
26584
|
utils_1.assertIs(page, "page", ["undefined", [PDFPage_1.default, "PDFPage"], Array]);
|
|
@@ -26209,13 +26596,13 @@ var require_PDFDocument = __commonJS({
|
|
|
26209
26596
|
this.pageCount = pageCount + 1;
|
|
26210
26597
|
return page;
|
|
26211
26598
|
};
|
|
26212
|
-
|
|
26599
|
+
PDFDocument4.prototype.copyPages = function(srcDoc, indices) {
|
|
26213
26600
|
return tslib_1.__awaiter(this, void 0, void 0, function() {
|
|
26214
26601
|
var copier, srcPages, copiedPages, idx, len, srcPage, copiedPage, ref;
|
|
26215
26602
|
return tslib_1.__generator(this, function(_a) {
|
|
26216
26603
|
switch (_a.label) {
|
|
26217
26604
|
case 0:
|
|
26218
|
-
utils_1.assertIs(srcDoc, "srcDoc", [[
|
|
26605
|
+
utils_1.assertIs(srcDoc, "srcDoc", [[PDFDocument4, "PDFDocument"]]);
|
|
26219
26606
|
utils_1.assertIs(indices, "indices", [Array]);
|
|
26220
26607
|
return [4, srcDoc.flush()];
|
|
26221
26608
|
case 1:
|
|
@@ -26234,13 +26621,13 @@ var require_PDFDocument = __commonJS({
|
|
|
26234
26621
|
});
|
|
26235
26622
|
});
|
|
26236
26623
|
};
|
|
26237
|
-
|
|
26624
|
+
PDFDocument4.prototype.copy = function() {
|
|
26238
26625
|
return tslib_1.__awaiter(this, void 0, void 0, function() {
|
|
26239
26626
|
var pdfCopy, contentPages, idx, len;
|
|
26240
26627
|
return tslib_1.__generator(this, function(_a) {
|
|
26241
26628
|
switch (_a.label) {
|
|
26242
26629
|
case 0:
|
|
26243
|
-
return [4,
|
|
26630
|
+
return [4, PDFDocument4.create()];
|
|
26244
26631
|
case 1:
|
|
26245
26632
|
pdfCopy = _a.sent();
|
|
26246
26633
|
return [4, pdfCopy.copyPages(this, this.getPageIndices())];
|
|
@@ -26276,7 +26663,7 @@ var require_PDFDocument = __commonJS({
|
|
|
26276
26663
|
});
|
|
26277
26664
|
});
|
|
26278
26665
|
};
|
|
26279
|
-
|
|
26666
|
+
PDFDocument4.prototype.addJavaScript = function(name, script) {
|
|
26280
26667
|
utils_1.assertIs(name, "name", ["string"]);
|
|
26281
26668
|
utils_1.assertIs(script, "script", ["string"]);
|
|
26282
26669
|
var embedder = JavaScriptEmbedder_1.default.for(script, name);
|
|
@@ -26284,7 +26671,7 @@ var require_PDFDocument = __commonJS({
|
|
|
26284
26671
|
var javaScript = PDFJavaScript_1.default.of(ref, this, embedder);
|
|
26285
26672
|
this.javaScripts.push(javaScript);
|
|
26286
26673
|
};
|
|
26287
|
-
|
|
26674
|
+
PDFDocument4.prototype.attach = function(attachment, name, options) {
|
|
26288
26675
|
if (options === void 0) {
|
|
26289
26676
|
options = {};
|
|
26290
26677
|
}
|
|
@@ -26312,7 +26699,7 @@ var require_PDFDocument = __commonJS({
|
|
|
26312
26699
|
});
|
|
26313
26700
|
});
|
|
26314
26701
|
};
|
|
26315
|
-
|
|
26702
|
+
PDFDocument4.prototype.embedFont = function(font, options) {
|
|
26316
26703
|
if (options === void 0) {
|
|
26317
26704
|
options = {};
|
|
26318
26705
|
}
|
|
@@ -26355,7 +26742,7 @@ var require_PDFDocument = __commonJS({
|
|
|
26355
26742
|
});
|
|
26356
26743
|
});
|
|
26357
26744
|
};
|
|
26358
|
-
|
|
26745
|
+
PDFDocument4.prototype.embedStandardFont = function(font, customName) {
|
|
26359
26746
|
utils_1.assertIs(font, "font", ["string"]);
|
|
26360
26747
|
if (!utils_1.isStandardFont(font)) {
|
|
26361
26748
|
throw new TypeError("`font` must be one of type `StandardFonts`");
|
|
@@ -26366,7 +26753,7 @@ var require_PDFDocument = __commonJS({
|
|
|
26366
26753
|
this.fonts.push(pdfFont);
|
|
26367
26754
|
return pdfFont;
|
|
26368
26755
|
};
|
|
26369
|
-
|
|
26756
|
+
PDFDocument4.prototype.embedJpg = function(jpg) {
|
|
26370
26757
|
return tslib_1.__awaiter(this, void 0, void 0, function() {
|
|
26371
26758
|
var bytes, embedder, ref, pdfImage;
|
|
26372
26759
|
return tslib_1.__generator(this, function(_a) {
|
|
@@ -26385,7 +26772,7 @@ var require_PDFDocument = __commonJS({
|
|
|
26385
26772
|
});
|
|
26386
26773
|
});
|
|
26387
26774
|
};
|
|
26388
|
-
|
|
26775
|
+
PDFDocument4.prototype.embedPng = function(png) {
|
|
26389
26776
|
return tslib_1.__awaiter(this, void 0, void 0, function() {
|
|
26390
26777
|
var bytes, embedder, ref, pdfImage;
|
|
26391
26778
|
return tslib_1.__generator(this, function(_a) {
|
|
@@ -26404,7 +26791,7 @@ var require_PDFDocument = __commonJS({
|
|
|
26404
26791
|
});
|
|
26405
26792
|
});
|
|
26406
26793
|
};
|
|
26407
|
-
|
|
26794
|
+
PDFDocument4.prototype.embedPdf = function(pdf, indices) {
|
|
26408
26795
|
if (indices === void 0) {
|
|
26409
26796
|
indices = [0];
|
|
26410
26797
|
}
|
|
@@ -26417,14 +26804,14 @@ var require_PDFDocument = __commonJS({
|
|
|
26417
26804
|
"string",
|
|
26418
26805
|
Uint8Array,
|
|
26419
26806
|
ArrayBuffer,
|
|
26420
|
-
[
|
|
26807
|
+
[PDFDocument4, "PDFDocument"]
|
|
26421
26808
|
]);
|
|
26422
26809
|
utils_1.assertIs(indices, "indices", [Array]);
|
|
26423
|
-
if (!(pdf instanceof
|
|
26810
|
+
if (!(pdf instanceof PDFDocument4)) return [3, 1];
|
|
26424
26811
|
_a = pdf;
|
|
26425
26812
|
return [3, 3];
|
|
26426
26813
|
case 1:
|
|
26427
|
-
return [4,
|
|
26814
|
+
return [4, PDFDocument4.load(pdf)];
|
|
26428
26815
|
case 2:
|
|
26429
26816
|
_a = _b.sent();
|
|
26430
26817
|
_b.label = 3;
|
|
@@ -26436,7 +26823,7 @@ var require_PDFDocument = __commonJS({
|
|
|
26436
26823
|
});
|
|
26437
26824
|
});
|
|
26438
26825
|
};
|
|
26439
|
-
|
|
26826
|
+
PDFDocument4.prototype.embedPage = function(page, boundingBox, transformationMatrix) {
|
|
26440
26827
|
return tslib_1.__awaiter(this, void 0, void 0, function() {
|
|
26441
26828
|
var embeddedPage;
|
|
26442
26829
|
return tslib_1.__generator(this, function(_a) {
|
|
@@ -26451,7 +26838,7 @@ var require_PDFDocument = __commonJS({
|
|
|
26451
26838
|
});
|
|
26452
26839
|
});
|
|
26453
26840
|
};
|
|
26454
|
-
|
|
26841
|
+
PDFDocument4.prototype.embedPages = function(pages, boundingBoxes, transformationMatrices) {
|
|
26455
26842
|
if (boundingBoxes === void 0) {
|
|
26456
26843
|
boundingBoxes = [];
|
|
26457
26844
|
}
|
|
@@ -26501,7 +26888,7 @@ var require_PDFDocument = __commonJS({
|
|
|
26501
26888
|
});
|
|
26502
26889
|
});
|
|
26503
26890
|
};
|
|
26504
|
-
|
|
26891
|
+
PDFDocument4.prototype.flush = function() {
|
|
26505
26892
|
return tslib_1.__awaiter(this, void 0, void 0, function() {
|
|
26506
26893
|
return tslib_1.__generator(this, function(_a) {
|
|
26507
26894
|
switch (_a.label) {
|
|
@@ -26529,7 +26916,7 @@ var require_PDFDocument = __commonJS({
|
|
|
26529
26916
|
});
|
|
26530
26917
|
});
|
|
26531
26918
|
};
|
|
26532
|
-
|
|
26919
|
+
PDFDocument4.prototype.save = function(options) {
|
|
26533
26920
|
if (options === void 0) {
|
|
26534
26921
|
options = {};
|
|
26535
26922
|
}
|
|
@@ -26559,7 +26946,7 @@ var require_PDFDocument = __commonJS({
|
|
|
26559
26946
|
});
|
|
26560
26947
|
});
|
|
26561
26948
|
};
|
|
26562
|
-
|
|
26949
|
+
PDFDocument4.prototype.saveAsBase64 = function(options) {
|
|
26563
26950
|
if (options === void 0) {
|
|
26564
26951
|
options = {};
|
|
26565
26952
|
}
|
|
@@ -26579,7 +26966,7 @@ var require_PDFDocument = __commonJS({
|
|
|
26579
26966
|
});
|
|
26580
26967
|
});
|
|
26581
26968
|
};
|
|
26582
|
-
|
|
26969
|
+
PDFDocument4.prototype.findPageForAnnotationRef = function(ref) {
|
|
26583
26970
|
var pages = this.getPages();
|
|
26584
26971
|
for (var idx = 0, len = pages.length; idx < len; idx++) {
|
|
26585
26972
|
var page = pages[idx];
|
|
@@ -26590,7 +26977,7 @@ var require_PDFDocument = __commonJS({
|
|
|
26590
26977
|
}
|
|
26591
26978
|
return void 0;
|
|
26592
26979
|
};
|
|
26593
|
-
|
|
26980
|
+
PDFDocument4.prototype.embedAll = function(embeddables) {
|
|
26594
26981
|
return tslib_1.__awaiter(this, void 0, void 0, function() {
|
|
26595
26982
|
var idx, len;
|
|
26596
26983
|
return tslib_1.__generator(this, function(_a) {
|
|
@@ -26616,7 +27003,7 @@ var require_PDFDocument = __commonJS({
|
|
|
26616
27003
|
});
|
|
26617
27004
|
});
|
|
26618
27005
|
};
|
|
26619
|
-
|
|
27006
|
+
PDFDocument4.prototype.updateInfoDict = function() {
|
|
26620
27007
|
var pdfLib = "pdf-lib (https://github.com/Hopding/pdf-lib)";
|
|
26621
27008
|
var now = /* @__PURE__ */ new Date();
|
|
26622
27009
|
var info = this.getInfoDict();
|
|
@@ -26627,7 +27014,7 @@ var require_PDFDocument = __commonJS({
|
|
|
26627
27014
|
if (!info.get(core_1.PDFName.of("CreationDate")))
|
|
26628
27015
|
this.setCreationDate(now);
|
|
26629
27016
|
};
|
|
26630
|
-
|
|
27017
|
+
PDFDocument4.prototype.getInfoDict = function() {
|
|
26631
27018
|
var existingInfo = this.context.lookup(this.context.trailerInfo.Info);
|
|
26632
27019
|
if (existingInfo instanceof core_1.PDFDict)
|
|
26633
27020
|
return existingInfo;
|
|
@@ -26635,15 +27022,15 @@ var require_PDFDocument = __commonJS({
|
|
|
26635
27022
|
this.context.trailerInfo.Info = this.context.register(newInfo);
|
|
26636
27023
|
return newInfo;
|
|
26637
27024
|
};
|
|
26638
|
-
|
|
27025
|
+
PDFDocument4.prototype.assertFontkit = function() {
|
|
26639
27026
|
if (!this.fontkit)
|
|
26640
27027
|
throw new errors_1.FontkitNotRegisteredError();
|
|
26641
27028
|
return this.fontkit;
|
|
26642
27029
|
};
|
|
26643
|
-
return
|
|
27030
|
+
return PDFDocument4;
|
|
26644
27031
|
})()
|
|
26645
27032
|
);
|
|
26646
|
-
exports2.default =
|
|
27033
|
+
exports2.default = PDFDocument3;
|
|
26647
27034
|
function assertIsLiteralOrHexString(pdfObject) {
|
|
26648
27035
|
if (!(pdfObject instanceof core_1.PDFHexString) && !(pdfObject instanceof core_1.PDFString)) {
|
|
26649
27036
|
throw new core_1.UnexpectedObjectTypeError([core_1.PDFHexString, core_1.PDFString], pdfObject);
|
|
@@ -27584,7 +27971,6 @@ var require_cjs = __commonJS({
|
|
|
27584
27971
|
// apps/admin/data/skills.lib/document/bin-src/deck-qa.mjs
|
|
27585
27972
|
var import_node_child_process = require("node:child_process");
|
|
27586
27973
|
var import_promises2 = require("node:fs/promises");
|
|
27587
|
-
var import_node_os = require("node:os");
|
|
27588
27974
|
var import_node_path4 = require("node:path");
|
|
27589
27975
|
var import_node_util = require("node:util");
|
|
27590
27976
|
|
|
@@ -27642,6 +28028,118 @@ async function slidePartsInOrder(zip) {
|
|
|
27642
28028
|
return toParts(complete ? ordered : byNumber);
|
|
27643
28029
|
}
|
|
27644
28030
|
|
|
28031
|
+
// packages/core/dist/document/png-decode.js
|
|
28032
|
+
var import_node_zlib = require("node:zlib");
|
|
28033
|
+
var SIG = [137, 80, 78, 71, 13, 10, 26, 10];
|
|
28034
|
+
var CHANNELS = { 0: 1, 2: 3, 3: 1, 4: 2, 6: 4 };
|
|
28035
|
+
function decodePng(bytes) {
|
|
28036
|
+
try {
|
|
28037
|
+
if (bytes.length < 33 || SIG.some((b, i) => bytes[i] !== b))
|
|
28038
|
+
return void 0;
|
|
28039
|
+
const buf = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
28040
|
+
let width = 0, height = 0, depth = 0, type = -1, interlace = 0;
|
|
28041
|
+
let palette;
|
|
28042
|
+
const idat = [];
|
|
28043
|
+
for (let p = 8; p + 8 <= buf.length; ) {
|
|
28044
|
+
const len = buf.readUInt32BE(p);
|
|
28045
|
+
const kind = buf.toString("latin1", p + 4, p + 8);
|
|
28046
|
+
const data = buf.subarray(p + 8, p + 8 + len);
|
|
28047
|
+
if (kind === "IHDR") {
|
|
28048
|
+
width = data.readUInt32BE(0);
|
|
28049
|
+
height = data.readUInt32BE(4);
|
|
28050
|
+
depth = data[8];
|
|
28051
|
+
type = data[9];
|
|
28052
|
+
interlace = data[12];
|
|
28053
|
+
} else if (kind === "PLTE")
|
|
28054
|
+
palette = data;
|
|
28055
|
+
else if (kind === "IDAT")
|
|
28056
|
+
idat.push(data);
|
|
28057
|
+
else if (kind === "IEND")
|
|
28058
|
+
break;
|
|
28059
|
+
p += 12 + len;
|
|
28060
|
+
}
|
|
28061
|
+
const ch = CHANNELS[type];
|
|
28062
|
+
if (!width || !height || depth !== 8 || interlace !== 0 || ch === void 0 || type === 3 && !palette)
|
|
28063
|
+
return void 0;
|
|
28064
|
+
const raw = (0, import_node_zlib.inflateSync)(Buffer.concat(idat));
|
|
28065
|
+
const stride = width * ch;
|
|
28066
|
+
if (raw.length < height * (stride + 1))
|
|
28067
|
+
return void 0;
|
|
28068
|
+
const cur = new Uint8Array(stride);
|
|
28069
|
+
const prev = new Uint8Array(stride);
|
|
28070
|
+
const rgb = new Uint8Array(width * height * 3);
|
|
28071
|
+
for (let y = 0; y < height; y++) {
|
|
28072
|
+
const off = y * (stride + 1);
|
|
28073
|
+
const filter = raw[off];
|
|
28074
|
+
for (let i = 0; i < stride; i++) {
|
|
28075
|
+
const x = raw[off + 1 + i];
|
|
28076
|
+
const a = i >= ch ? cur[i - ch] : 0;
|
|
28077
|
+
const b = prev[i];
|
|
28078
|
+
const c = i >= ch ? prev[i - ch] : 0;
|
|
28079
|
+
let v;
|
|
28080
|
+
switch (filter) {
|
|
28081
|
+
case 0:
|
|
28082
|
+
v = x;
|
|
28083
|
+
break;
|
|
28084
|
+
case 1:
|
|
28085
|
+
v = x + a;
|
|
28086
|
+
break;
|
|
28087
|
+
case 2:
|
|
28088
|
+
v = x + b;
|
|
28089
|
+
break;
|
|
28090
|
+
case 3:
|
|
28091
|
+
v = x + (a + b >> 1);
|
|
28092
|
+
break;
|
|
28093
|
+
case 4: {
|
|
28094
|
+
const pa = Math.abs(b - c), pb = Math.abs(a - c), pc = Math.abs(a + b - 2 * c);
|
|
28095
|
+
v = x + (pa <= pb && pa <= pc ? a : pb <= pc ? b : c);
|
|
28096
|
+
break;
|
|
28097
|
+
}
|
|
28098
|
+
default:
|
|
28099
|
+
return void 0;
|
|
28100
|
+
}
|
|
28101
|
+
cur[i] = v & 255;
|
|
28102
|
+
}
|
|
28103
|
+
for (let px = 0; px < width; px++) {
|
|
28104
|
+
const o = (y * width + px) * 3;
|
|
28105
|
+
const s = px * ch;
|
|
28106
|
+
if (type === 3) {
|
|
28107
|
+
const k = cur[s] * 3;
|
|
28108
|
+
rgb[o] = palette[k];
|
|
28109
|
+
rgb[o + 1] = palette[k + 1];
|
|
28110
|
+
rgb[o + 2] = palette[k + 2];
|
|
28111
|
+
} else if (ch <= 2) {
|
|
28112
|
+
rgb[o] = rgb[o + 1] = rgb[o + 2] = cur[s];
|
|
28113
|
+
} else {
|
|
28114
|
+
rgb[o] = cur[s];
|
|
28115
|
+
rgb[o + 1] = cur[s + 1];
|
|
28116
|
+
rgb[o + 2] = cur[s + 2];
|
|
28117
|
+
}
|
|
28118
|
+
}
|
|
28119
|
+
prev.set(cur);
|
|
28120
|
+
}
|
|
28121
|
+
return { width, height, rgb };
|
|
28122
|
+
} catch {
|
|
28123
|
+
return void 0;
|
|
28124
|
+
}
|
|
28125
|
+
}
|
|
28126
|
+
|
|
28127
|
+
// packages/core/dist/document/text-slack.js
|
|
28128
|
+
var SLACK_CJK_RE = /[\u3000-\u303F\u3400-\u9FFF\uF900-\uFAFF\uFF00-\uFFEF]/;
|
|
28129
|
+
var PCT = { single: { cjk: 0.22, latin: 0.16 }, multi: { cjk: 0.1, latin: 0.06 } };
|
|
28130
|
+
var FLOOR_EM = { cjk: 1, latin: 0.45 };
|
|
28131
|
+
function params(single, cjk) {
|
|
28132
|
+
const script = cjk ? "cjk" : "latin";
|
|
28133
|
+
return { pct: PCT[single ? "single" : "multi"][script], floor: FLOOR_EM[script] * (single ? 1 : 0.5) };
|
|
28134
|
+
}
|
|
28135
|
+
function unpaddedWidth(padded, fontSize, single, cjk) {
|
|
28136
|
+
const { pct, floor } = params(single, cjk);
|
|
28137
|
+
const floorAbs = floor * fontSize;
|
|
28138
|
+
const viaPct = padded / (1 + pct);
|
|
28139
|
+
return viaPct * pct >= floorAbs ? viaPct : Math.max(0, padded - floorAbs);
|
|
28140
|
+
}
|
|
28141
|
+
var CHART_TEXT_NAME = "talos-chart-text";
|
|
28142
|
+
|
|
27645
28143
|
// packages/core/dist/document/doc-design-lint.js
|
|
27646
28144
|
var PLACEHOLDER_RE = /替换为|在这里写|占位|示例文本|Lorem ipsum/i;
|
|
27647
28145
|
var CJK_TEXT_RE = /[-ヿ㐀-䶿一-鿿가-豈-]/;
|
|
@@ -27782,7 +28280,7 @@ function lintSlideXml(slideXml, slideNumber, masterBg, expectedLang = detectDeck
|
|
|
27782
28280
|
}
|
|
27783
28281
|
}
|
|
27784
28282
|
}
|
|
27785
|
-
if (worst && !worst.onShapeFill && anyVisualShape)
|
|
28283
|
+
if (worst && !worst.onShapeFill && (anyVisualShape || hasPic))
|
|
27786
28284
|
worst = void 0;
|
|
27787
28285
|
if (placeholder) {
|
|
27788
28286
|
const snippet2 = placeholder.length > 24 ? `${placeholder.slice(0, 24)}\u2026` : placeholder;
|
|
@@ -27822,7 +28320,10 @@ var EMU_PER_INCH = 914400;
|
|
|
27822
28320
|
var DEFAULT_CANVAS = { w: 12192e3, h: 6858e3 };
|
|
27823
28321
|
var OFFCANVAS_TOL = EMU_PER_INCH / 10;
|
|
27824
28322
|
var MIN_FONT_HUNDREDTHS = 1e3;
|
|
27825
|
-
var
|
|
28323
|
+
var LABEL_MAX_CHARS = 24;
|
|
28324
|
+
var MIN_LABEL_FONT_HUNDREDTHS = 800;
|
|
28325
|
+
var CHART_TEXT_RE = new RegExp(`<p:cNvPr\\b[^>]*\\bname="${CHART_TEXT_NAME}\\b`);
|
|
28326
|
+
var OVERLAP_RATIO = 0.3;
|
|
27826
28327
|
function firstBox(block) {
|
|
27827
28328
|
const xf = /<(?:a|p):xfrm\b[^>]*>[\s\S]*?<\/(?:a|p):xfrm>/.exec(block);
|
|
27828
28329
|
const scope = xf ? xf[0] : block;
|
|
@@ -27840,6 +28341,51 @@ function overlapArea(a, b) {
|
|
|
27840
28341
|
const iy = Math.max(0, Math.min(a.y + a.h, b.y + b.h) - Math.max(a.y, b.y));
|
|
27841
28342
|
return ix * iy;
|
|
27842
28343
|
}
|
|
28344
|
+
var CJK_WIDE_RE = /[\u2E80-\u9FFF\uAC00-\uD7AF\uF900-\uFAFF\uFF00-\uFFEF]/;
|
|
28345
|
+
var EMU_PER_PT = 12700;
|
|
28346
|
+
function inkBox(block, box) {
|
|
28347
|
+
let maxSz = 0;
|
|
28348
|
+
let inkW = 0;
|
|
28349
|
+
let lines = 0;
|
|
28350
|
+
for (const para of block.match(/<a:p>[\s\S]*?<\/a:p>|<a:p\b[^>]*>[\s\S]*?<\/a:p>/g) ?? []) {
|
|
28351
|
+
let paraW = 0;
|
|
28352
|
+
let paraSz = 0;
|
|
28353
|
+
for (const run of para.match(/<a:r>[\s\S]*?<\/a:r>/g) ?? []) {
|
|
28354
|
+
const raw = /<a:t\b[^>]*>([\s\S]*?)<\/a:t>/.exec(run)?.[1];
|
|
28355
|
+
if (raw === void 0)
|
|
28356
|
+
continue;
|
|
28357
|
+
const sz = +(/<a:rPr\b[^>]*\bsz="(\d+)"/.exec(run)?.[1] ?? 1800) / 100;
|
|
28358
|
+
paraSz = Math.max(paraSz, sz);
|
|
28359
|
+
for (const ch of unescXml(raw))
|
|
28360
|
+
paraW += (CJK_WIDE_RE.test(ch) ? 1 : ch === " " ? 0.3 : 0.55) * sz * EMU_PER_PT;
|
|
28361
|
+
}
|
|
28362
|
+
if (!paraW)
|
|
28363
|
+
continue;
|
|
28364
|
+
maxSz = Math.max(maxSz, paraSz);
|
|
28365
|
+
const paraLines = box.w > 0 ? Math.max(1, Math.ceil(paraW / box.w)) : 1;
|
|
28366
|
+
lines += paraLines;
|
|
28367
|
+
inkW = Math.max(inkW, Math.min(paraW, box.w));
|
|
28368
|
+
}
|
|
28369
|
+
if (!lines)
|
|
28370
|
+
return void 0;
|
|
28371
|
+
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));
|
|
28372
|
+
if (paras.length === 1 && maxSz > 0) {
|
|
28373
|
+
const lnSpc = /<a:lnSpc>\s*<a:spcPts\b[^>]*\bval="(\d+)"/.exec(block)?.[1];
|
|
28374
|
+
const lineH = (lnSpc ? +lnSpc / 100 : maxSz * 1.3) * EMU_PER_PT;
|
|
28375
|
+
const clamped = box.x + box.w >= DEFAULT_CANVAS.w - EMU_PER_PT;
|
|
28376
|
+
if (box.h <= lineH * 1.5 && !clamped) {
|
|
28377
|
+
const text = unescXml((block.match(/<a:t\b[^>]*>([\s\S]*?)<\/a:t>/g) ?? []).join(""));
|
|
28378
|
+
lines = 1;
|
|
28379
|
+
inkW = Math.min(inkW, unpaddedWidth(box.w, maxSz * EMU_PER_PT, true, SLACK_CJK_RE.test(text)));
|
|
28380
|
+
}
|
|
28381
|
+
}
|
|
28382
|
+
const inkH = Math.min(box.h, lines * maxSz * 1.2 * EMU_PER_PT);
|
|
28383
|
+
const algn = /<a:pPr\b[^>]*\balgn="(\w+)"/.exec(block)?.[1];
|
|
28384
|
+
const anchor = /<a:bodyPr\b[^>]*\banchor="(\w+)"/.exec(block)?.[1];
|
|
28385
|
+
const x = algn === "ctr" ? box.x + (box.w - inkW) / 2 : algn === "r" ? box.x + box.w - inkW : box.x;
|
|
28386
|
+
const y = anchor === "ctr" ? box.y + (box.h - inkH) / 2 : anchor === "b" ? box.y + box.h - inkH : box.y;
|
|
28387
|
+
return { x, y, w: inkW, h: inkH };
|
|
28388
|
+
}
|
|
27843
28389
|
function lintSlideGeometry(slideXml, slideNumber, canvas = DEFAULT_CANVAS) {
|
|
27844
28390
|
const findings = [];
|
|
27845
28391
|
const blocks = slideXml.match(/<p:(?:sp|pic|graphicFrame|cxnSp)\b[^>]*>[\s\S]*?<\/p:(?:sp|pic|graphicFrame|cxnSp)>/g) ?? [];
|
|
@@ -27863,16 +28409,23 @@ function lintSlideGeometry(slideXml, slideNumber, canvas = DEFAULT_CANVAS) {
|
|
|
27863
28409
|
worstOff = { by, edge };
|
|
27864
28410
|
}
|
|
27865
28411
|
}
|
|
27866
|
-
if (hasText && box.w > 0 && box.h > 0)
|
|
27867
|
-
|
|
28412
|
+
if (hasText && box.w > 0 && box.h > 0) {
|
|
28413
|
+
const ink = inkBox(b, box);
|
|
28414
|
+
if (ink)
|
|
28415
|
+
textBoxes2.push(ink);
|
|
28416
|
+
}
|
|
27868
28417
|
}
|
|
28418
|
+
if (CHART_TEXT_RE.test(b))
|
|
28419
|
+
continue;
|
|
27869
28420
|
for (const run of b.match(/<a:r>[\s\S]*?<\/a:r>/g) ?? []) {
|
|
27870
28421
|
const raw = /<a:t\b[^>]*>([\s\S]*?)<\/a:t>/.exec(run)?.[1];
|
|
27871
28422
|
if (raw === void 0 || !unescXml(raw).trim())
|
|
27872
28423
|
continue;
|
|
28424
|
+
const text = unescXml(raw).trim();
|
|
27873
28425
|
const sz = /<a:rPr\b[^>]*\bsz="(\d+)"/.exec(run)?.[1];
|
|
27874
|
-
|
|
27875
|
-
|
|
28426
|
+
const floor = [...text].length <= LABEL_MAX_CHARS ? MIN_LABEL_FONT_HUNDREDTHS : MIN_FONT_HUNDREDTHS;
|
|
28427
|
+
if (sz && +sz < floor && (!smallest || +sz < smallest.sz)) {
|
|
28428
|
+
smallest = { sz: +sz, text, floor };
|
|
27876
28429
|
}
|
|
27877
28430
|
}
|
|
27878
28431
|
}
|
|
@@ -27888,7 +28441,7 @@ function lintSlideGeometry(slideXml, slideNumber, canvas = DEFAULT_CANVAS) {
|
|
|
27888
28441
|
findings.push({
|
|
27889
28442
|
slide: slideNumber,
|
|
27890
28443
|
code: "tiny-font",
|
|
27891
|
-
message: `text "${snippet2}" is ${(smallest.sz / 100).toFixed(
|
|
28444
|
+
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
28445
|
});
|
|
27893
28446
|
}
|
|
27894
28447
|
let worstPair;
|
|
@@ -27913,6 +28466,110 @@ function lintSlideGeometry(slideXml, slideNumber, canvas = DEFAULT_CANVAS) {
|
|
|
27913
28466
|
}
|
|
27914
28467
|
return findings;
|
|
27915
28468
|
}
|
|
28469
|
+
var BACKDROP_COVER = 0.98;
|
|
28470
|
+
var BACKDROP_FLOOR = 2;
|
|
28471
|
+
var BACKDROP_SAMPLES = 2500;
|
|
28472
|
+
var LIN = Array.from({ length: 256 }, (_, i) => {
|
|
28473
|
+
const c = i / 255;
|
|
28474
|
+
return c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
|
|
28475
|
+
});
|
|
28476
|
+
var lumRgb = (r, g, b) => 0.2126 * LIN[r] + 0.7152 * LIN[g] + 0.0722 * LIN[b];
|
|
28477
|
+
var ratioOf = (a, b) => (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05);
|
|
28478
|
+
var hex2 = (n) => n.toString(16).padStart(2, "0").toUpperCase();
|
|
28479
|
+
var BLOCK_RE = /<p:(?:sp|pic|graphicFrame|cxnSp)\b[^>]*>[\s\S]*?<\/p:(?:sp|pic|graphicFrame|cxnSp)>/g;
|
|
28480
|
+
function backdropPicEmbed(slideXml, canvas = DEFAULT_CANVAS) {
|
|
28481
|
+
const first = (slideXml.match(BLOCK_RE) ?? [])[0];
|
|
28482
|
+
if (!first || !first.startsWith("<p:pic"))
|
|
28483
|
+
return void 0;
|
|
28484
|
+
const box = firstBox(first);
|
|
28485
|
+
if (!box || box.x > canvas.w * (1 - BACKDROP_COVER) || box.y > canvas.h * (1 - BACKDROP_COVER))
|
|
28486
|
+
return void 0;
|
|
28487
|
+
if (box.w < canvas.w * BACKDROP_COVER || box.h < canvas.h * BACKDROP_COVER)
|
|
28488
|
+
return void 0;
|
|
28489
|
+
return /<a:blip\b[^>]*\br:embed="([^"]+)"/.exec(first)?.[1];
|
|
28490
|
+
}
|
|
28491
|
+
function lintBackdropContrast(slideXml, slideNumber, backdrop, canvas = DEFAULT_CANVAS) {
|
|
28492
|
+
const blocks = slideXml.match(BLOCK_RE) ?? [];
|
|
28493
|
+
const sx = backdrop.width / canvas.w;
|
|
28494
|
+
const sy = backdrop.height / canvas.h;
|
|
28495
|
+
const occluders = [];
|
|
28496
|
+
let worst;
|
|
28497
|
+
for (let bi = 1; bi < blocks.length; bi++) {
|
|
28498
|
+
const b = blocks[bi];
|
|
28499
|
+
const box = firstBox(b);
|
|
28500
|
+
if (!box)
|
|
28501
|
+
continue;
|
|
28502
|
+
const txIdx = b.indexOf("<p:txBody>");
|
|
28503
|
+
const spPr = txIdx >= 0 ? b.slice(0, txIdx) : b;
|
|
28504
|
+
const prst = /<a:prstGeom\b[^>]*\bprst="([^"]+)"/.exec(spPr)?.[1];
|
|
28505
|
+
const visual = !b.startsWith("<p:sp") || FILL_RE.test(spPr) || prst !== void 0 && prst !== "rect";
|
|
28506
|
+
const hasText = txIdx >= 0 && /<a:t\b[^>]*>\s*\S/.test(b);
|
|
28507
|
+
if (visual) {
|
|
28508
|
+
occluders.push(box);
|
|
28509
|
+
continue;
|
|
28510
|
+
}
|
|
28511
|
+
if (!hasText)
|
|
28512
|
+
continue;
|
|
28513
|
+
const ink = inkBox(b, box);
|
|
28514
|
+
if (!ink || ink.w <= 0 || ink.h <= 0)
|
|
28515
|
+
continue;
|
|
28516
|
+
if (occluders.some((o2) => overlapArea(o2, ink) > 0))
|
|
28517
|
+
continue;
|
|
28518
|
+
let fg;
|
|
28519
|
+
let alpha = 1;
|
|
28520
|
+
let text = "";
|
|
28521
|
+
for (const run of b.match(/<a:r>[\s\S]*?<\/a:r>/g) ?? []) {
|
|
28522
|
+
const raw = /<a:t\b[^>]*>([\s\S]*?)<\/a:t>/.exec(run)?.[1];
|
|
28523
|
+
if (raw === void 0 || !unescXml(raw).trim())
|
|
28524
|
+
continue;
|
|
28525
|
+
text += unescXml(raw);
|
|
28526
|
+
if (fg)
|
|
28527
|
+
continue;
|
|
28528
|
+
const rPr = run.slice(0, Math.max(0, run.indexOf("</a:rPr>")));
|
|
28529
|
+
fg = firstSrgb(rPr);
|
|
28530
|
+
const a = /<a:srgbClr\b[^>]*>\s*<a:alpha\b[^>]*\bval="(\d+)"/.exec(rPr)?.[1];
|
|
28531
|
+
if (fg && a)
|
|
28532
|
+
alpha = Math.min(1, +a / 1e5);
|
|
28533
|
+
}
|
|
28534
|
+
if (!fg)
|
|
28535
|
+
continue;
|
|
28536
|
+
const x0 = Math.max(0, Math.floor(ink.x * sx));
|
|
28537
|
+
const y0 = Math.max(0, Math.floor(ink.y * sy));
|
|
28538
|
+
const x1 = Math.min(backdrop.width, Math.ceil((ink.x + ink.w) * sx));
|
|
28539
|
+
const y1 = Math.min(backdrop.height, Math.ceil((ink.y + ink.h) * sy));
|
|
28540
|
+
if (x1 <= x0 || y1 <= y0)
|
|
28541
|
+
continue;
|
|
28542
|
+
const step = Math.max(1, Math.floor(Math.sqrt((x1 - x0) * (y1 - y0) / BACKDROP_SAMPLES)));
|
|
28543
|
+
const fr = parseInt(fg.slice(0, 2), 16), fgG = parseInt(fg.slice(2, 4), 16), fb = parseInt(fg.slice(4, 6), 16);
|
|
28544
|
+
const fgLum = lumRgb(fr, fgG, fb);
|
|
28545
|
+
const samples = [];
|
|
28546
|
+
for (let y = y0; y < y1; y += step) {
|
|
28547
|
+
for (let x = x0; x < x1; x += step) {
|
|
28548
|
+
const o2 = (y * backdrop.width + x) * 3;
|
|
28549
|
+
const r = backdrop.rgb[o2], g = backdrop.rgb[o2 + 1], bl = backdrop.rgb[o2 + 2];
|
|
28550
|
+
const l = lumRgb(r, g, bl);
|
|
28551
|
+
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));
|
|
28552
|
+
samples.push([ratioOf(tl, l), o2]);
|
|
28553
|
+
}
|
|
28554
|
+
}
|
|
28555
|
+
if (!samples.length)
|
|
28556
|
+
continue;
|
|
28557
|
+
samples.sort((p, q) => p[0] - q[0]);
|
|
28558
|
+
const [ratio, o] = samples[samples.length >> 1];
|
|
28559
|
+
if (ratio < BACKDROP_FLOOR && (!worst || ratio < worst.ratio)) {
|
|
28560
|
+
const bg = hex2(backdrop.rgb[o]) + hex2(backdrop.rgb[o + 1]) + hex2(backdrop.rgb[o + 2]);
|
|
28561
|
+
worst = { ratio, text: text.trim(), fg, bg };
|
|
28562
|
+
}
|
|
28563
|
+
}
|
|
28564
|
+
if (!worst)
|
|
28565
|
+
return [];
|
|
28566
|
+
const snippet2 = worst.text.length > 24 ? `${worst.text.slice(0, 24)}\u2026` : worst.text;
|
|
28567
|
+
return [{
|
|
28568
|
+
slide: slideNumber,
|
|
28569
|
+
code: "low-contrast-text",
|
|
28570
|
+
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`
|
|
28571
|
+
}];
|
|
28572
|
+
}
|
|
27916
28573
|
function canvasFromPresentation(xml) {
|
|
27917
28574
|
if (!xml)
|
|
27918
28575
|
return DEFAULT_CANVAS;
|
|
@@ -27920,6 +28577,26 @@ function canvasFromPresentation(xml) {
|
|
|
27920
28577
|
const cy = /<p:sldSz\b[^>]*\bcy="(\d+)"/.exec(xml)?.[1];
|
|
27921
28578
|
return cx && cy ? { w: +cx, h: +cy } : DEFAULT_CANVAS;
|
|
27922
28579
|
}
|
|
28580
|
+
async function backdropRaster(zip, slideXml, relsPath, canvas) {
|
|
28581
|
+
const rId = backdropPicEmbed(slideXml, canvas);
|
|
28582
|
+
const rels = rId ? zip.file(relsPath) : null;
|
|
28583
|
+
if (!rId || !rels)
|
|
28584
|
+
return void 0;
|
|
28585
|
+
const relsXml = await rels.async("string");
|
|
28586
|
+
const rel = [...relsXml.matchAll(/<Relationship\b[^>]*>/g)].map((m) => m[0]).find((r) => new RegExp(`\\bId="${rId}"`).test(r));
|
|
28587
|
+
const target = rel && /\bTarget="([^"]+)"/.exec(rel)?.[1];
|
|
28588
|
+
if (!target || !/\.png$/i.test(target))
|
|
28589
|
+
return void 0;
|
|
28590
|
+
const parts = ["ppt", "slides"];
|
|
28591
|
+
for (const seg of target.split("/")) {
|
|
28592
|
+
if (seg === "..")
|
|
28593
|
+
parts.pop();
|
|
28594
|
+
else if (seg && seg !== ".")
|
|
28595
|
+
parts.push(seg);
|
|
28596
|
+
}
|
|
28597
|
+
const media = zip.file(target.startsWith("/") ? target.slice(1) : parts.join("/"));
|
|
28598
|
+
return media ? decodePng(await media.async("uint8array")) : void 0;
|
|
28599
|
+
}
|
|
27923
28600
|
async function designLintPptx(bytes) {
|
|
27924
28601
|
const zip = await import_jszip.default.loadAsync(Buffer.from(bytes));
|
|
27925
28602
|
const findings = [];
|
|
@@ -27930,9 +28607,15 @@ async function designLintPptx(bytes) {
|
|
|
27930
28607
|
const presFile = zip.file("ppt/presentation.xml");
|
|
27931
28608
|
const canvas = canvasFromPresentation(presFile ? await presFile.async("string") : void 0);
|
|
27932
28609
|
const lang = detectDeckLang();
|
|
27933
|
-
for (const { position, path } of await slidePartsInOrder(zip)) {
|
|
28610
|
+
for (const { position, path, relsPath } of await slidePartsInOrder(zip)) {
|
|
27934
28611
|
const xml = await zip.file(path).async("string");
|
|
27935
|
-
|
|
28612
|
+
const own = lintSlideXml(xml, position, masterBg, lang);
|
|
28613
|
+
findings.push(...own);
|
|
28614
|
+
if (!own.some((f) => f.code === "low-contrast-text")) {
|
|
28615
|
+
const backdrop = await backdropRaster(zip, xml, relsPath, canvas);
|
|
28616
|
+
if (backdrop)
|
|
28617
|
+
findings.push(...lintBackdropContrast(xml, position, backdrop, canvas));
|
|
28618
|
+
}
|
|
27936
28619
|
findings.push(...lintSlideGeometry(xml, position, canvas));
|
|
27937
28620
|
}
|
|
27938
28621
|
return { ok: findings.length === 0, findings };
|
|
@@ -27940,76 +28623,101 @@ async function designLintPptx(bytes) {
|
|
|
27940
28623
|
|
|
27941
28624
|
// packages/core/dist/document/deck-render-check.js
|
|
27942
28625
|
var import_jszip2 = __toESM(require_lib3(), 1);
|
|
28626
|
+
init_pdf_extract();
|
|
27943
28627
|
|
|
27944
|
-
// packages/core/dist/document/pdf-
|
|
27945
|
-
var
|
|
27946
|
-
var
|
|
27947
|
-
|
|
27948
|
-
|
|
27949
|
-
|
|
27950
|
-
|
|
27951
|
-
|
|
27952
|
-
|
|
28628
|
+
// packages/core/dist/document/pdf-fonts.js
|
|
28629
|
+
var import_pdf_lib = __toESM(require_cjs(), 1);
|
|
28630
|
+
var CJK_RANGES = [
|
|
28631
|
+
[11904, 12031],
|
|
28632
|
+
[12288, 12351],
|
|
28633
|
+
[12352, 12543],
|
|
28634
|
+
[12800, 19903],
|
|
28635
|
+
[19968, 40959],
|
|
28636
|
+
[63744, 64255],
|
|
28637
|
+
[65072, 65103],
|
|
28638
|
+
[65280, 65519]
|
|
28639
|
+
];
|
|
28640
|
+
var isCjk = (u) => CJK_RANGES.some(([a, b]) => u >= a && u <= b);
|
|
28641
|
+
function toUnicodeHasCjk(cmap) {
|
|
28642
|
+
for (const m of cmap.matchAll(/<([0-9A-Fa-f]{4,})>/g)) {
|
|
28643
|
+
const hex = m[1];
|
|
28644
|
+
for (let i = 0; i + 4 <= hex.length; i += 4)
|
|
28645
|
+
if (isCjk(parseInt(hex.slice(i, i + 4), 16)))
|
|
28646
|
+
return true;
|
|
27953
28647
|
}
|
|
27954
|
-
return
|
|
28648
|
+
return false;
|
|
27955
28649
|
}
|
|
27956
|
-
|
|
27957
|
-
|
|
27958
|
-
|
|
27959
|
-
|
|
27960
|
-
|
|
28650
|
+
function streamText(stream) {
|
|
28651
|
+
try {
|
|
28652
|
+
if (stream instanceof import_pdf_lib.PDFRawStream)
|
|
28653
|
+
return Buffer.from((0, import_pdf_lib.decodePDFRawStream)(stream).decode()).toString("latin1");
|
|
28654
|
+
if (stream instanceof import_pdf_lib.PDFStream)
|
|
28655
|
+
return Buffer.from(stream.getContents()).toString("latin1");
|
|
28656
|
+
} catch {
|
|
27961
28657
|
}
|
|
27962
|
-
return
|
|
28658
|
+
return "";
|
|
27963
28659
|
}
|
|
27964
|
-
|
|
27965
|
-
|
|
28660
|
+
var nameOf = (v) => v instanceof import_pdf_lib.PDFName ? v.decodeText() : void 0;
|
|
28661
|
+
async function scanPdfType3Fonts(pdfBytes) {
|
|
28662
|
+
const doc = await import_pdf_lib.PDFDocument.load(pdfBytes, { ignoreEncryption: true, updateMetadata: false, throwOnInvalidObject: false });
|
|
28663
|
+
const ctx = doc.context;
|
|
28664
|
+
const deref = (v) => v instanceof import_pdf_lib.PDFRef ? ctx.lookup(v) : v;
|
|
27966
28665
|
const out = [];
|
|
27967
|
-
|
|
27968
|
-
const
|
|
27969
|
-
const
|
|
27970
|
-
|
|
27971
|
-
|
|
27972
|
-
|
|
27973
|
-
|
|
27974
|
-
|
|
27975
|
-
|
|
27976
|
-
|
|
27977
|
-
|
|
27978
|
-
|
|
27979
|
-
|
|
27980
|
-
|
|
27981
|
-
|
|
27982
|
-
|
|
27983
|
-
|
|
27984
|
-
|
|
27985
|
-
text
|
|
27986
|
-
});
|
|
28666
|
+
doc.getPages().forEach((page, i) => {
|
|
28667
|
+
const seen = /* @__PURE__ */ new Set();
|
|
28668
|
+
const visitResources = (res, depth) => {
|
|
28669
|
+
const r = deref(res);
|
|
28670
|
+
if (!(r instanceof import_pdf_lib.PDFDict) || depth > 8)
|
|
28671
|
+
return;
|
|
28672
|
+
const fonts = deref(r.get(import_pdf_lib.PDFName.of("Font")));
|
|
28673
|
+
if (fonts instanceof import_pdf_lib.PDFDict) {
|
|
28674
|
+
for (const [key, ref] of fonts.entries()) {
|
|
28675
|
+
const font = deref(ref);
|
|
28676
|
+
if (!(font instanceof import_pdf_lib.PDFDict) || seen.has(font))
|
|
28677
|
+
continue;
|
|
28678
|
+
seen.add(font);
|
|
28679
|
+
if (nameOf(font.get(import_pdf_lib.PDFName.of("Subtype"))) !== "Type3")
|
|
28680
|
+
continue;
|
|
28681
|
+
const name = nameOf(font.get(import_pdf_lib.PDFName.of("BaseFont"))) ?? nameOf(font.get(import_pdf_lib.PDFName.of("Name"))) ?? key.decodeText();
|
|
28682
|
+
out.push({ page: i + 1, name, cjk: toUnicodeHasCjk(streamText(deref(font.get(import_pdf_lib.PDFName.of("ToUnicode"))))) });
|
|
28683
|
+
}
|
|
27987
28684
|
}
|
|
27988
|
-
|
|
27989
|
-
|
|
27990
|
-
|
|
27991
|
-
|
|
27992
|
-
|
|
27993
|
-
|
|
27994
|
-
|
|
27995
|
-
|
|
27996
|
-
|
|
27997
|
-
|
|
27998
|
-
|
|
27999
|
-
|
|
28000
|
-
|
|
28001
|
-
|
|
28002
|
-
const pix = doc.loadPage(p - 1).toPixmap(matrix, mupdf.ColorSpace.DeviceRGB, false, true);
|
|
28003
|
-
out.push({ page: p, png: pix.asPNG() });
|
|
28004
|
-
}
|
|
28685
|
+
const xobjects = deref(r.get(import_pdf_lib.PDFName.of("XObject")));
|
|
28686
|
+
if (xobjects instanceof import_pdf_lib.PDFDict) {
|
|
28687
|
+
for (const [, ref] of xobjects.entries()) {
|
|
28688
|
+
const xo = deref(ref);
|
|
28689
|
+
if (!(xo instanceof import_pdf_lib.PDFStream) || seen.has(xo))
|
|
28690
|
+
continue;
|
|
28691
|
+
seen.add(xo);
|
|
28692
|
+
if (nameOf(xo.dict.get(import_pdf_lib.PDFName.of("Subtype"))) === "Form")
|
|
28693
|
+
visitResources(xo.dict.get(import_pdf_lib.PDFName.of("Resources")), depth + 1);
|
|
28694
|
+
}
|
|
28695
|
+
}
|
|
28696
|
+
};
|
|
28697
|
+
visitResources(page.node.Resources(), 0);
|
|
28698
|
+
});
|
|
28005
28699
|
return out;
|
|
28006
28700
|
}
|
|
28007
28701
|
|
|
28008
28702
|
// packages/core/dist/document/deck-render-check.js
|
|
28703
|
+
function type3Findings(fonts) {
|
|
28704
|
+
const byPage = /* @__PURE__ */ new Map();
|
|
28705
|
+
for (const f of fonts)
|
|
28706
|
+
byPage.set(f.page, [...byPage.get(f.page) ?? [], f]);
|
|
28707
|
+
return [...byPage].map(([slide, list]) => {
|
|
28708
|
+
const cjk = list.some((f) => f.cjk);
|
|
28709
|
+
return {
|
|
28710
|
+
slide,
|
|
28711
|
+
code: "render-type3-font",
|
|
28712
|
+
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"
|
|
28713
|
+
};
|
|
28714
|
+
});
|
|
28715
|
+
}
|
|
28009
28716
|
var OVERFLOW_PITCH = 0.5;
|
|
28010
28717
|
var SIDE_TOL = 0.5;
|
|
28011
28718
|
var HANG_TOL = 1.1;
|
|
28012
28719
|
var HANGING_PUNCT = /[、,。;:!?)」』》,.;:!?)]$/;
|
|
28720
|
+
var NEAR_PITCHES = 3;
|
|
28013
28721
|
var DEFAULT_PT = 18;
|
|
28014
28722
|
var squash = (s) => s.replace(/\s+/g, "");
|
|
28015
28723
|
var snippet = (s) => s.length > 24 ? `${s.slice(0, 24)}\u2026` : s;
|
|
@@ -28046,10 +28754,11 @@ function checkRenderedSlide(slideXml, slideNumber, canvas, page) {
|
|
|
28046
28754
|
let worstSide;
|
|
28047
28755
|
for (const line of page.lines) {
|
|
28048
28756
|
const text = squash(line.text);
|
|
28049
|
-
|
|
28757
|
+
const near = (b) => b.text.includes(text) && distance(b, line) <= NEAR_PITCHES * b.pitch;
|
|
28758
|
+
let candidates = boxes.filter(near);
|
|
28050
28759
|
const merged = !candidates.length && text.length > 1;
|
|
28051
28760
|
if (merged)
|
|
28052
|
-
candidates = boxes.filter((b) => b.text.includes(text.slice(1)));
|
|
28761
|
+
candidates = boxes.filter((b) => b.text.includes(text.slice(1)) && distance(b, line) <= NEAR_PITCHES * b.pitch);
|
|
28053
28762
|
if (!candidates.length)
|
|
28054
28763
|
continue;
|
|
28055
28764
|
const box = candidates.reduce((best, b) => distance(b, line) < distance(best, line) ? b : best);
|
|
@@ -28129,7 +28838,8 @@ async function checkRenderedDeck(pptxBytes, pdfBytes) {
|
|
|
28129
28838
|
}
|
|
28130
28839
|
const presXml = await zip.file("ppt/presentation.xml")?.async("string");
|
|
28131
28840
|
const canvas = canvasFromPresentation(presXml);
|
|
28132
|
-
const
|
|
28841
|
+
const type3Fonts = await scanPdfType3Fonts(pdfBytes);
|
|
28842
|
+
const findings = type3Findings(type3Fonts);
|
|
28133
28843
|
const charts = [];
|
|
28134
28844
|
for (const { position, path } of slides) {
|
|
28135
28845
|
const xml = await zip.file(path).async("string");
|
|
@@ -28137,16 +28847,20 @@ async function checkRenderedDeck(pptxBytes, pdfBytes) {
|
|
|
28137
28847
|
if (/drawingml\/2006\/chart"/.test(xml))
|
|
28138
28848
|
charts.push(position);
|
|
28139
28849
|
}
|
|
28850
|
+
findings.sort((a, b) => a.slide - b.slide);
|
|
28140
28851
|
const review = [.../* @__PURE__ */ new Set([...findings.map((f) => f.slide), ...charts])].sort((a, b) => a - b);
|
|
28141
|
-
return { findings, charts, review };
|
|
28852
|
+
return { findings, charts, review, type3Fonts };
|
|
28142
28853
|
}
|
|
28143
28854
|
|
|
28855
|
+
// apps/admin/data/skills.lib/document/bin-src/deck-qa.mjs
|
|
28856
|
+
init_pdf_extract();
|
|
28857
|
+
|
|
28144
28858
|
// apps/admin/data/skills.lib/document/bin-src/lib/check-pptx.mjs
|
|
28145
28859
|
var import_node_path3 = require("node:path");
|
|
28146
28860
|
|
|
28147
28861
|
// packages/core/dist/document/doc-validate.js
|
|
28148
28862
|
var import_jszip3 = __toESM(require_lib3(), 1);
|
|
28149
|
-
var
|
|
28863
|
+
var import_pdf_lib2 = __toESM(require_cjs(), 1);
|
|
28150
28864
|
function looksLikePdf(bytes) {
|
|
28151
28865
|
const head = Buffer.from(bytes.subarray(0, 1024)).toString("latin1");
|
|
28152
28866
|
return head.includes("%PDF-");
|
|
@@ -28156,8 +28870,19 @@ async function validatePdf(bytes) {
|
|
|
28156
28870
|
const warnings = [];
|
|
28157
28871
|
let pages;
|
|
28158
28872
|
try {
|
|
28159
|
-
const doc = await
|
|
28873
|
+
const doc = await import_pdf_lib2.PDFDocument.load(bytes, { ignoreEncryption: true, throwOnInvalidObject: true, updateMetadata: false });
|
|
28160
28874
|
pages = doc.getPageCount();
|
|
28875
|
+
if (doc.isEncrypted) {
|
|
28876
|
+
const { pdfNeedsPassword: pdfNeedsPassword2 } = await Promise.resolve().then(() => (init_pdf_extract(), pdf_extract_exports));
|
|
28877
|
+
if (await pdfNeedsPassword2(bytes).catch(() => true)) {
|
|
28878
|
+
errors.push({
|
|
28879
|
+
code: "pdf-encrypted",
|
|
28880
|
+
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"
|
|
28881
|
+
});
|
|
28882
|
+
return { ok: false, kind: "pdf", errors, warnings, pages };
|
|
28883
|
+
}
|
|
28884
|
+
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>`' });
|
|
28885
|
+
}
|
|
28161
28886
|
if (pages === 0)
|
|
28162
28887
|
errors.push({ code: "pdf-no-pages", message: "the PDF parses but has no pages" });
|
|
28163
28888
|
else
|
|
@@ -28528,16 +29253,17 @@ function printLint(result) {
|
|
|
28528
29253
|
async function officeRender(deck, pdf, cacheDir) {
|
|
28529
29254
|
const bin = (0, import_node_path4.join)((0, import_node_path4.dirname)(process.argv[1]), "doc-convert.cjs");
|
|
28530
29255
|
try {
|
|
28531
|
-
const { stdout } = await (0, import_node_util.promisify)(import_node_child_process.execFile)(process.execPath, [bin, deck, pdf, "--cache-dir", cacheDir], {
|
|
29256
|
+
const { stdout } = await (0, import_node_util.promisify)(import_node_child_process.execFile)(process.execPath, [bin, deck, pdf, "--cache-dir", cacheDir, "--require-office"], {
|
|
28532
29257
|
maxBuffer: 8 * 1024 * 1024
|
|
28533
29258
|
});
|
|
28534
29259
|
const engine = /\[([^\]]+)\]\s*$/.exec(stdout.trim())?.[1] ?? "unknown";
|
|
28535
29260
|
return { engine, faithful: /libreoffice/i.test(engine), pdf };
|
|
28536
29261
|
} catch (e) {
|
|
28537
|
-
|
|
29262
|
+
const error = (e.stderr || e.message || String(e)).trim().split("\n").slice(-3).join(" ");
|
|
29263
|
+
return { faithful: false, error, unavailable: e.code === 69 };
|
|
28538
29264
|
}
|
|
28539
29265
|
}
|
|
28540
|
-
async function finalSignOff(file, bytes, cacheDir) {
|
|
29266
|
+
async function finalSignOff(file, bytes, cacheDir, requireOffice) {
|
|
28541
29267
|
const check = await checkPptx(bytes, { strict: true });
|
|
28542
29268
|
if (!check.valid || check.strict?.ok === false) {
|
|
28543
29269
|
process.stdout.write(JSON.stringify({ ok: false, valid: check.valid, errors: check.errors, strict: check.strict }) + "\n");
|
|
@@ -28554,6 +29280,7 @@ async function finalSignOff(file, bytes, cacheDir) {
|
|
|
28554
29280
|
const rendered = await checkRenderedDeck(bytes, pdfBytes).catch((e) => die(`render check failed: ${e.message}`));
|
|
28555
29281
|
findings = [...findings, ...rendered.findings].sort((a, b) => a.slide - b.slide);
|
|
28556
29282
|
({ review, charts } = rendered);
|
|
29283
|
+
office.type3Fonts = rendered.type3Fonts;
|
|
28557
29284
|
if (review.length) {
|
|
28558
29285
|
for (const r of await renderPdfPages(new Uint8Array(pdfBytes), review, 1)) {
|
|
28559
29286
|
const path = (0, import_node_path4.join)((0, import_node_path4.dirname)(office.pdf), `${stem}.office_p${r.page}.png`);
|
|
@@ -28562,13 +29289,19 @@ async function finalSignOff(file, bytes, cacheDir) {
|
|
|
28562
29289
|
}
|
|
28563
29290
|
}
|
|
28564
29291
|
}
|
|
28565
|
-
const
|
|
29292
|
+
const blocked = Boolean(office.error) && (!office.unavailable || requireOffice);
|
|
29293
|
+
const result = { ok: findings.length === 0 && !blocked, valid: true, strict: check.strict, findings, office, review, charts, previews };
|
|
28566
29294
|
process.stdout.write(JSON.stringify(result, null, 1) + "\n");
|
|
29295
|
+
if (office.error && !office.unavailable) {
|
|
29296
|
+
die(`the Office render failed (${office.error}) \u2014 not signing off on a Chromium reconstruction instead; rerun deck-qa --final`);
|
|
29297
|
+
}
|
|
29298
|
+
if (office.error && requireOffice) die(`--require-office: no LibreOffice render is possible here (${office.error})`);
|
|
29299
|
+
if (office.type3Fonts?.length) {
|
|
29300
|
+
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
|
|
29301
|
+
`);
|
|
29302
|
+
}
|
|
28567
29303
|
if (office.error) {
|
|
28568
29304
|
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
29305
|
`);
|
|
28573
29306
|
} else {
|
|
28574
29307
|
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 +29313,23 @@ async function main() {
|
|
|
28580
29313
|
const asJson = args.includes("--json");
|
|
28581
29314
|
const final = args.includes("--final");
|
|
28582
29315
|
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
29316
|
const valued = /* @__PURE__ */ new Set(["--rendered", "--cache-dir"]);
|
|
28585
29317
|
const file = args.find((a, i) => !a.startsWith("--") && !valued.has(args[i - 1]));
|
|
28586
|
-
const
|
|
29318
|
+
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);
|
|
29319
|
+
const requireOffice = args.includes("--require-office");
|
|
29320
|
+
const usage = "usage: deck-qa <file.pptx> [--json] [--rendered <office.pdf> | --final [--cache-dir <dir>] [--require-office]]";
|
|
28587
29321
|
if (!file) die(usage, 64);
|
|
28588
29322
|
if (!/\.pptx$/i.test(file)) die("deck-qa only lints .pptx decks", 64);
|
|
28589
29323
|
if (rendered && !/\.pdf$/i.test(rendered)) die("--rendered takes the .pdf doc-convert wrote for this deck", 64);
|
|
28590
29324
|
if (final && rendered) die("--final renders the deck itself; drop --rendered", 64);
|
|
29325
|
+
if (requireOffice && !final) die("--require-office only applies to --final", 64);
|
|
28591
29326
|
let bytes;
|
|
28592
29327
|
try {
|
|
28593
29328
|
bytes = await (0, import_promises2.readFile)(file);
|
|
28594
29329
|
} catch (e) {
|
|
28595
29330
|
die(`cannot read ${file}: ${e.message}`, 66);
|
|
28596
29331
|
}
|
|
28597
|
-
if (final) return finalSignOff(file, new Uint8Array(bytes), cacheDir);
|
|
29332
|
+
if (final) return finalSignOff(file, new Uint8Array(bytes), cacheDir, requireOffice);
|
|
28598
29333
|
let result;
|
|
28599
29334
|
try {
|
|
28600
29335
|
result = await designLintPptx(bytes);
|
|
@@ -28615,7 +29350,7 @@ async function main() {
|
|
|
28615
29350
|
die(`render check failed: ${e.message}`);
|
|
28616
29351
|
}
|
|
28617
29352
|
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 };
|
|
29353
|
+
result = { ok: findings.length === 0, findings, charts: check.charts, review: check.review, type3Fonts: check.type3Fonts };
|
|
28619
29354
|
}
|
|
28620
29355
|
if (asJson) {
|
|
28621
29356
|
process.stdout.write(JSON.stringify(result) + "\n");
|