@poe-platform/safe-bash 0.1.788 → 0.1.789
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/safe-bash/chunks/{chunk-WHURJBET.js → chunk-2MUJ7RLZ.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-PYTLIUST.js → chunk-CTUHLNJM.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-Z3HX3ZBA.js → chunk-D4PHJK4T.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-O6356Z27.js → chunk-H7MMJS26.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-Q3E6C3DX.js → chunk-KHJGUF2W.js} +14 -0
- package/dist/safe-bash/chunks/{chunk-FJZNUUOQ.js → chunk-VUVKC6HV.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-ZMYVCRAF.js → chunk-X5ZCECM6.js} +2 -2
- package/dist/safe-bash/chunks/{git-UFNPAOYZ.js → git-HO7WDPHZ.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-PFBJR2PY.js → chunk-2KRKKW5S.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-4DSJDVBM.js → chunk-32F3RBUW.js} +10 -749
- package/dist/safe-bash/command-chunks/{chunk-L3MLMXL4.js → chunk-3ZK5F23O.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-4QX6XCDD.js → chunk-4RNIZ3RT.js} +79 -0
- package/dist/safe-bash/command-chunks/{chunk-D7TADAYG.js → chunk-64LG3EVJ.js} +17 -0
- package/dist/safe-bash/command-chunks/{chunk-JUDOV5MJ.js → chunk-6F7QJMJ3.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-IJ3FXP4Q.js → chunk-A3ZX6SCY.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-YNT4ZJHW.js → chunk-AT6ZSOE6.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-KSIGF4AG.js → chunk-BK4CMEE6.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-XGMWWUHV.js → chunk-CZ5DAK4K.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-Z57TV6TC.js → chunk-EZ2DTOLI.js} +4 -2
- package/dist/safe-bash/command-chunks/{chunk-ADCGH6A7.js → chunk-FH3D75FC.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-WYJTWJZ5.js → chunk-G3G6W5ZE.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-3HDIDEUJ.js → chunk-GF54KE2M.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-Z7TYZG3A.js → chunk-IHHTTQX6.js} +5 -3
- package/dist/safe-bash/command-chunks/{chunk-INDIFLBW.js → chunk-JTAGNROA.js} +4 -0
- package/dist/safe-bash/command-chunks/chunk-PGEYORBZ.js +25 -0
- package/dist/safe-bash/command-chunks/chunk-QM4UZF3C.js +753 -0
- package/dist/safe-bash/command-chunks/{chunk-TOSM3T3A.js → chunk-UJOO6DKY.js} +20 -9
- package/dist/safe-bash/command-chunks/{chunk-2LP3VMPA.js → chunk-WFDW4XXD.js} +1 -17
- package/dist/safe-bash/command-chunks/chunk-WR37IS4O.js +318 -0
- package/dist/safe-bash/command-chunks/{chunk-Y5IHIAY3.js → chunk-XNHSCU6I.js} +7 -3
- package/dist/safe-bash/commands/basic.js +148 -48
- package/dist/safe-bash/commands/bytes/compression/index.js +5 -6
- package/dist/safe-bash/commands/cmp.d.ts +2 -3
- package/dist/safe-bash/commands/cmp.js +2 -689
- package/dist/safe-bash/commands/docx/index.browser.js +3 -46
- package/dist/safe-bash/commands/docx/index.d.ts +2 -24
- package/dist/safe-bash/commands/docx/index.js +2 -41
- package/dist/safe-bash/commands/docx/io.d.ts +1 -14
- package/dist/safe-bash/commands/docx/io.js +1 -15
- package/dist/safe-bash/commands/llm/index.browser.js +3 -3
- package/dist/safe-bash/commands/network/index.browser.js +3 -3
- package/dist/safe-bash/commands/node/index.browser.js +3 -3
- package/dist/safe-bash/commands/pptx/index.d.ts +2 -28
- package/dist/safe-bash/commands/pptx/index.js +2 -152
- package/dist/safe-bash/commands/printf-float.d.ts +1 -0
- package/dist/safe-bash/commands/printf-float.js +48 -38
- package/dist/safe-bash/commands/printf-format.js +9 -6
- package/dist/safe-bash/commands/printf-quote.d.ts +3 -0
- package/dist/safe-bash/commands/printf-quote.js +62 -0
- package/dist/safe-bash/commands/printf-wide.d.ts +5 -0
- package/dist/safe-bash/commands/printf-wide.js +41 -0
- package/dist/safe-bash/commands/python/index.browser.js +2 -2
- package/dist/safe-bash/commands/truncate.d.ts +2 -3
- package/dist/safe-bash/commands/truncate.js +2 -686
- package/dist/safe-bash/contracts/diagnostics.d.ts +2 -0
- package/dist/safe-bash/contracts/diagnostics.js +2 -0
- package/dist/safe-bash/contracts/runtime-control.d.ts +2 -0
- package/dist/safe-bash/contracts/runtime-control.js +2 -0
- package/dist/safe-bash/core.browser.d.ts +1 -1
- package/dist/safe-bash/core.browser.js +2651 -4871
- package/dist/safe-bash/core.d.ts +10 -0
- package/dist/safe-bash/opt-in/commands/cmp/index.d.ts +6 -2
- package/dist/safe-bash/opt-in/commands/cmp/index.js +776 -79
- package/dist/safe-bash/opt-in/commands/cmp/options.d.ts +0 -12
- package/dist/safe-bash/opt-in/commands/cmp/options.js +0 -153
- package/dist/safe-bash/opt-in/commands/truncate/index.d.ts +8 -3
- package/dist/safe-bash/opt-in/commands/truncate/index.js +790 -272
- package/dist/safe-bash/opt-in/commands/truncate/sync.d.ts +1 -0
- package/dist/safe-bash/opt-in/commands/truncate/sync.js +60 -0
- package/dist/safe-bash/optional-host.browser.js +9 -1
- package/dist/safe-bash/optional-host.d.ts +3 -1
- package/dist/safe-bash/optional-host.js +3 -1
- package/dist/safe-bash/shell/runtime.js +10 -6
- package/dist/safe-bash-checksum-engine/index.d.ts +1 -1
- package/dist/safe-bash-checksum-engine/index.js +14 -2
- package/dist/safe-bash-command-bzip2/index.js +2 -1
- package/dist/safe-bash-command-cmp/index.d.ts +10 -0
- package/dist/safe-bash-command-cmp/index.js +796 -0
- package/dist/safe-bash-command-cmp/options.d.ts +12 -0
- package/dist/safe-bash-command-cmp/options.js +42 -0
- package/dist/safe-bash-command-csvcut/index.js +11 -8
- package/dist/safe-bash-command-csvgrep/index.js +35 -7
- package/dist/safe-bash-command-csvkit/codecs/python.js +4 -3
- package/dist/safe-bash-command-csvkit/codecs/utf8.js +3 -2
- package/dist/safe-bash-command-csvkit/index.js +80 -324
- package/dist/safe-bash-command-csvkit/python-regex.d.ts +5 -0
- package/dist/safe-bash-command-csvkit/python-regex.js +14 -0
- package/dist/safe-bash-command-csvkit/runtime.d.ts +1 -0
- package/dist/safe-bash-command-csvkit/sync-support.js +4 -2
- package/dist/safe-bash-command-diff3/index.js +3 -0
- package/dist/safe-bash-command-docx/LICENSE +21 -0
- package/dist/safe-bash-command-docx/index.d.ts +30 -0
- package/dist/safe-bash-command-docx/index.js +67 -0
- package/dist/safe-bash-command-docx/io.d.ts +14 -0
- package/dist/safe-bash-command-docx/io.js +26 -0
- package/dist/safe-bash-command-envsubst/index.js +34 -3
- package/dist/safe-bash-command-exiftool/index.js +3 -0
- package/dist/safe-bash-command-ffmpeg/index.js +1102 -1088
- package/dist/safe-bash-command-fold/family.js +1 -1
- package/dist/safe-bash-command-fold/index.js +1 -1
- package/dist/safe-bash-command-htmlq/index.js +5 -0
- package/dist/safe-bash-command-imagemagick/index.d.ts +25 -21
- package/dist/safe-bash-command-imagemagick/index.js +669 -271
- package/dist/safe-bash-command-mmdc/index.js +48 -10
- package/dist/safe-bash-command-mmdc/svg.d.ts +1 -0
- package/dist/safe-bash-command-op/index.js +19 -14
- package/dist/safe-bash-command-pandoc/command.js +1 -1
- package/dist/safe-bash-command-pandoc/index.js +1 -1
- package/dist/safe-bash-command-pdfimages/index.d.ts +7 -1
- package/dist/safe-bash-command-pdfimages/index.js +63 -33
- package/dist/safe-bash-command-pdfinfo/index.d.ts +24 -20
- package/dist/safe-bash-command-pdfinfo/index.js +370 -161
- package/dist/safe-bash-command-pdftk/index.d.ts +7 -3
- package/dist/safe-bash-command-pdftk/index.js +114 -45
- package/dist/safe-bash-command-pdftoppm/index.d.ts +15 -7
- package/dist/safe-bash-command-pdftoppm/index.js +179 -109
- package/dist/safe-bash-command-pdftotext/index.d.ts +9 -5
- package/dist/safe-bash-command-pdftotext/index.js +90 -27
- package/dist/safe-bash-command-pptx/LICENSE +21 -0
- package/dist/safe-bash-command-pptx/index.d.ts +33 -0
- package/dist/safe-bash-command-pptx/index.js +168 -0
- package/dist/safe-bash-command-qpdf/index.d.ts +9 -3
- package/dist/safe-bash-command-qpdf/index.js +80 -29
- package/dist/safe-bash-command-sha512sum/index.js +12 -475
- package/dist/safe-bash-command-sips/index.d.ts +9 -5
- package/dist/safe-bash-command-sips/index.js +63 -44
- package/dist/safe-bash-command-soffice/index.d.ts +9 -3
- package/dist/safe-bash-command-soffice/index.js +65 -24
- package/dist/safe-bash-command-sqlite3/engine.d.ts +9 -0
- package/dist/safe-bash-command-sqlite3/index.d.ts +1 -0
- package/dist/safe-bash-command-sqlite3/index.js +851 -352
- package/dist/safe-bash-command-ssconvert/formats/xls.js +3 -3
- package/dist/safe-bash-command-timeout/index.js +3 -3
- package/dist/safe-bash-command-truncate/index.d.ts +8 -3
- package/dist/safe-bash-command-truncate/index.js +790 -272
- package/dist/safe-bash-command-truncate/sync.d.ts +1 -0
- package/dist/safe-bash-command-truncate/sync.js +60 -0
- package/dist/safe-bash-command-wkhtmltopdf/index.js +92 -38
- package/dist/safe-bash-command-wkhtmltopdf/pdf-renderer.d.ts +1 -1
- package/dist/safe-bash-command-xxd/index.js +78 -20
- package/dist/safe-bash-command-xz/command.d.ts +4 -0
- package/dist/safe-bash-command-xz/index.d.ts +1 -1
- package/dist/safe-bash-command-xz/index.js +1 -1
- package/dist/safe-bash-compression-engine/bounded-codec.js +3 -3
- package/dist/safe-bash-compression-engine/codec-loader.js +2 -2
- package/dist/safe-bash-compression-engine/files.js +6 -6
- package/dist/safe-bash-compression-engine/index.js +5 -5
- package/dist/safe-bash-compression-engine/operand.js +6 -6
- package/dist/safe-bash-compression-engine/stream.js +5 -5
- package/dist/safe-bash-compression-engine/zstd-decode.js +4 -4
- package/dist/safe-bash-contracts/command.js +3 -3
- package/dist/safe-bash-contracts/diagnostics.js +3 -3
- package/dist/safe-bash-contracts/escaping.js +9 -9
- package/dist/safe-bash-contracts/filesystem-descriptor.js +3 -3
- package/dist/safe-bash-contracts/filesystem-output.js +8 -8
- package/dist/safe-bash-contracts/index.js +21 -19
- package/dist/safe-bash-contracts/io.d.ts +12 -0
- package/dist/safe-bash-contracts/io.js +4 -1
- package/dist/safe-bash-contracts/output.js +3 -2
- package/dist/safe-bash-contracts/runtime-control.js +2 -2
- package/dist/safe-bash-contracts/signals.js +1 -1
- package/dist/safe-bash-contracts/yield.d.ts +1 -0
- package/dist/safe-bash-contracts/yield.js +3 -1
- package/dist/safe-bash-csv-engine/index.d.ts +10 -1
- package/dist/safe-bash-csv-engine/index.js +78 -6
- package/dist/safe-bash-io-engine/commands/search/requirements.js +3 -3
- package/dist/safe-bash-io-engine/commands/text-programs/shared.js +3 -3
- package/dist/safe-bash-io-engine/gnu-information.js +1 -1
- package/dist/safe-bash-io-engine/internal.d.ts +1 -1
- package/dist/safe-bash-io-engine/internal.js +2 -2
- package/dist/safe-bash-query-engine/index.js +4 -4
- package/dist/safe-bash-query-engine/interpreter.js +2 -2
- package/dist/safe-bash-query-engine/query-core.js +4 -4
- package/package.json +2 -2
- package/dist/safe-bash/opt-in/commands/cmp/compare.js +0 -95
- package/dist/safe-bash/opt-in/commands/cmp/io.js +0 -218
- package/dist/safe-bash/command-chunks/{chunk-FXYWQ6S4.js → chunk-2VTMZTV3.js} +0 -0
- package/dist/safe-bash/command-chunks/{chunk-RTOJNFFL.js → chunk-BJ6DGYJA.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-DEH3CMGL.js → chunk-QJ3ONEBI.js} +3 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function evalSyncTruncate(opArgs: readonly string[], readFileSync?: (filePath: string) => Uint8Array | undefined, writeFileSync?: (filePath: string, bytes: Uint8Array) => boolean): string | undefined;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { parseArguments, helpText } from "./arguments.js";
|
|
2
|
+
import { syncCommandEvaluators } from "../safe-bash-io-engine/internal.js";
|
|
3
|
+
export function evalSyncTruncate(opArgs, readFileSync, writeFileSync) {
|
|
4
|
+
try {
|
|
5
|
+
const args = parseArguments(opArgs, false);
|
|
6
|
+
if (args.display === "help")
|
|
7
|
+
return helpText;
|
|
8
|
+
if (args.display === "version")
|
|
9
|
+
return "truncate (safe-bash; GNU coreutils 9.7 semantics)\n";
|
|
10
|
+
if (!writeFileSync || args.files.length === 0)
|
|
11
|
+
return undefined;
|
|
12
|
+
const blockFactor = args.ioBlocks ? 4096n : 1n;
|
|
13
|
+
let refSize;
|
|
14
|
+
if (args.reference !== undefined) {
|
|
15
|
+
const refBytes = readFileSync?.(args.reference);
|
|
16
|
+
if (!refBytes)
|
|
17
|
+
return undefined;
|
|
18
|
+
refSize = BigInt(refBytes.length);
|
|
19
|
+
}
|
|
20
|
+
for (const file of args.files) {
|
|
21
|
+
const existing = readFileSync?.(file);
|
|
22
|
+
if (!existing && args.noCreate)
|
|
23
|
+
continue;
|
|
24
|
+
const curSize = BigInt(existing?.length ?? 0);
|
|
25
|
+
const base = refSize ?? curSize;
|
|
26
|
+
const scaledSize = args.size === undefined ? undefined : args.size * blockFactor;
|
|
27
|
+
let target;
|
|
28
|
+
if (scaledSize === undefined)
|
|
29
|
+
target = refSize;
|
|
30
|
+
else if (args.mode === "absolute")
|
|
31
|
+
target = scaledSize;
|
|
32
|
+
else if (args.mode === "relative")
|
|
33
|
+
target = base + scaledSize;
|
|
34
|
+
else if (args.mode === "<")
|
|
35
|
+
target = base < scaledSize ? base : scaledSize;
|
|
36
|
+
else if (args.mode === ">")
|
|
37
|
+
target = base > scaledSize ? base : scaledSize;
|
|
38
|
+
else if (args.mode === "/")
|
|
39
|
+
target = (base / scaledSize) * scaledSize;
|
|
40
|
+
else
|
|
41
|
+
target = ((base + scaledSize - 1n) / scaledSize) * scaledSize;
|
|
42
|
+
if (target < 0n)
|
|
43
|
+
target = 0n;
|
|
44
|
+
if (target > 1048576n)
|
|
45
|
+
return undefined;
|
|
46
|
+
const n = Number(target);
|
|
47
|
+
const out = new Uint8Array(n);
|
|
48
|
+
if (existing && existing.length > 0) {
|
|
49
|
+
out.set(existing.subarray(0, Math.min(existing.length, n)));
|
|
50
|
+
}
|
|
51
|
+
if (!writeFileSync(file, out))
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
return "";
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
syncCommandEvaluators.evalSyncTruncate = evalSyncTruncate;
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
|
|
5
5
|
// packages/safe-bash-command-wkhtmltopdf/dist/index.js
|
|
6
6
|
init_buffer();
|
|
7
|
-
import {
|
|
7
|
+
import { drainCooperativeSteps } from "../safe-bash-contracts/yield.js";
|
|
8
8
|
import { commandRuntimeIdentity, getCommandArguments } from "../safe-bash-contracts/command.js";
|
|
9
9
|
import { readBytes, writeBytes } from "../safe-bash-contracts/io.js";
|
|
10
10
|
import { shellValueByteLength } from "../safe-bash-contracts/value.js";
|
|
@@ -45520,10 +45520,14 @@ function extractLinks(html) {
|
|
|
45520
45520
|
}
|
|
45521
45521
|
return links;
|
|
45522
45522
|
}
|
|
45523
|
-
function
|
|
45523
|
+
function* parseHtmlDocumentSteps(rawHtml, replacements, signal) {
|
|
45524
|
+
let cooperativeWork = 0;
|
|
45524
45525
|
let html = rawHtml;
|
|
45525
45526
|
for (const [key, value] of replacements) {
|
|
45526
|
-
if (
|
|
45527
|
+
if (++cooperativeWork % 64 === 0)
|
|
45528
|
+
yield;
|
|
45529
|
+
if (key)
|
|
45530
|
+
html = html.split(key).join(value);
|
|
45527
45531
|
}
|
|
45528
45532
|
const titleMatch = /<title[^>]*>([\s\S]*?)<\/title>/i.exec(html);
|
|
45529
45533
|
const title = titleMatch ? stripTags(titleMatch[1] ?? "") : "";
|
|
@@ -45534,8 +45538,11 @@ function parseHtmlDocumentSync(rawHtml, replacements, signal) {
|
|
|
45534
45538
|
let match;
|
|
45535
45539
|
let work = 0;
|
|
45536
45540
|
while ((match = tokenRegex.exec(bodyHtml)) !== null) {
|
|
45541
|
+
if (++cooperativeWork % 64 === 0)
|
|
45542
|
+
yield;
|
|
45537
45543
|
signal.throwIfAborted();
|
|
45538
|
-
if (++work % 64 === 0)
|
|
45544
|
+
if (++work % 64 === 0)
|
|
45545
|
+
signal.throwIfAborted();
|
|
45539
45546
|
const leadingText = stripTags(bodyHtml.slice(lastIndex, match.index));
|
|
45540
45547
|
if (leadingText) {
|
|
45541
45548
|
blocks.push({ kind: "paragraph", text: leadingText, links: extractLinks(bodyHtml.slice(lastIndex, match.index)) });
|
|
@@ -45584,8 +45591,11 @@ function parseHtmlDocumentSync(rawHtml, replacements, signal) {
|
|
|
45584
45591
|
const liRegex = /<li\b[^>]*>([\s\S]*?)<\/li>/gi;
|
|
45585
45592
|
let liMatch;
|
|
45586
45593
|
while ((liMatch = liRegex.exec(inner)) !== null) {
|
|
45594
|
+
if (++cooperativeWork % 64 === 0)
|
|
45595
|
+
yield;
|
|
45587
45596
|
const itemText = stripTags(liMatch[1] ?? "");
|
|
45588
|
-
if (itemText)
|
|
45597
|
+
if (itemText)
|
|
45598
|
+
items.push(itemText);
|
|
45589
45599
|
}
|
|
45590
45600
|
if (items.length > 0) {
|
|
45591
45601
|
blocks.push({ kind: "list", ordered: tag === "ol", items });
|
|
@@ -45596,6 +45606,8 @@ function parseHtmlDocumentSync(rawHtml, replacements, signal) {
|
|
|
45596
45606
|
let m;
|
|
45597
45607
|
let currentTerm = "";
|
|
45598
45608
|
while ((m = dtDdRegex.exec(inner)) !== null) {
|
|
45609
|
+
if (++cooperativeWork % 64 === 0)
|
|
45610
|
+
yield;
|
|
45599
45611
|
const t = m[1].toLowerCase();
|
|
45600
45612
|
const txt = stripTags(m[2] ?? "");
|
|
45601
45613
|
if (t === "dt") {
|
|
@@ -45617,6 +45629,8 @@ function parseHtmlDocumentSync(rawHtml, replacements, signal) {
|
|
|
45617
45629
|
const rectRe = /<rect\b([^>]*)\/?>/gi;
|
|
45618
45630
|
let rm;
|
|
45619
45631
|
while ((rm = rectRe.exec(inner)) !== null) {
|
|
45632
|
+
if (++cooperativeWork % 64 === 0)
|
|
45633
|
+
yield;
|
|
45620
45634
|
const ra = rm[1] ?? "";
|
|
45621
45635
|
const rx = Number(/\bx=["']?([\d.]+)/i.exec(ra)?.[1] ?? 0);
|
|
45622
45636
|
const ry = Number(/\by=["']?([\d.]+)/i.exec(ra)?.[1] ?? 0);
|
|
@@ -45627,11 +45641,14 @@ function parseHtmlDocumentSync(rawHtml, replacements, signal) {
|
|
|
45627
45641
|
const textRe = /<text\b([^>]*)>([\s\S]*?)<\/text>/gi;
|
|
45628
45642
|
let tm;
|
|
45629
45643
|
while ((tm = textRe.exec(inner)) !== null) {
|
|
45644
|
+
if (++cooperativeWork % 64 === 0)
|
|
45645
|
+
yield;
|
|
45630
45646
|
const ta = tm[1] ?? "";
|
|
45631
45647
|
const tx = Number(/\bx=["']?([\d.]+)/i.exec(ta)?.[1] ?? 8);
|
|
45632
45648
|
const ty = Number(/\by=["']?([\d.]+)/i.exec(ta)?.[1] ?? 16);
|
|
45633
45649
|
const txt = stripTags(tm[2] ?? "");
|
|
45634
|
-
if (txt)
|
|
45650
|
+
if (txt)
|
|
45651
|
+
svgPrimitives.push({ kind: "text", x: tx, y: ty, text: txt });
|
|
45635
45652
|
}
|
|
45636
45653
|
blocks.push({ kind: "svg", displayWidth, displayHeight, svgPrimitives });
|
|
45637
45654
|
} else if (tag === "blockquote") {
|
|
@@ -45644,13 +45661,18 @@ function parseHtmlDocumentSync(rawHtml, replacements, signal) {
|
|
|
45644
45661
|
const trRegex = /<tr\b[^>]*>([\s\S]*?)<\/tr>/gi;
|
|
45645
45662
|
let trMatch;
|
|
45646
45663
|
while ((trMatch = trRegex.exec(inner)) !== null) {
|
|
45664
|
+
if (++cooperativeWork % 64 === 0)
|
|
45665
|
+
yield;
|
|
45647
45666
|
const rowHtml = trMatch[1] ?? "";
|
|
45648
45667
|
const cells = [];
|
|
45649
45668
|
let header = false;
|
|
45650
45669
|
const cellRegex = /<(th|td)\b([^>]*)>([\s\S]*?)<\/\1>/gi;
|
|
45651
45670
|
let cellMatch;
|
|
45652
45671
|
while ((cellMatch = cellRegex.exec(rowHtml)) !== null) {
|
|
45653
|
-
if (
|
|
45672
|
+
if (++cooperativeWork % 64 === 0)
|
|
45673
|
+
yield;
|
|
45674
|
+
if (cellMatch[1]?.toLowerCase() === "th")
|
|
45675
|
+
header = true;
|
|
45654
45676
|
const cellAttrs = cellMatch[2] ?? "";
|
|
45655
45677
|
const colspanMatch = /colspan=["']?(\d+)/i.exec(cellAttrs);
|
|
45656
45678
|
const colspan = Math.max(1, colspanMatch ? Number(colspanMatch[1]) : 1);
|
|
@@ -45665,7 +45687,7 @@ function parseHtmlDocumentSync(rawHtml, replacements, signal) {
|
|
|
45665
45687
|
}
|
|
45666
45688
|
} else {
|
|
45667
45689
|
if (/<(h[1-6]|p|pre|ul|ol|dl|table|svg|hr|img|blockquote|div|section|article)\b/i.test(inner)) {
|
|
45668
|
-
const nested =
|
|
45690
|
+
const nested = yield* parseHtmlDocumentSteps(inner, [], signal);
|
|
45669
45691
|
blocks.push(...nested.blocks);
|
|
45670
45692
|
} else {
|
|
45671
45693
|
const text = stripTags(inner);
|
|
@@ -45712,7 +45734,8 @@ function rgbColor(r, g, b, grayscale) {
|
|
|
45712
45734
|
const lum = Math.round((0.299 * r + 0.587 * g + 0.114 * b) * 1e3) / 1e3;
|
|
45713
45735
|
return { r: lum, g: lum, b: lum };
|
|
45714
45736
|
}
|
|
45715
|
-
function
|
|
45737
|
+
function* layoutObjectPagesSteps(blocks, box, settings, signal) {
|
|
45738
|
+
let cooperativeWork = 0;
|
|
45716
45739
|
const pages = [];
|
|
45717
45740
|
let currentActions = [];
|
|
45718
45741
|
const headerReserve = settings.header.left || settings.header.center || settings.header.right ? 24 : 0;
|
|
@@ -45733,8 +45756,11 @@ function layoutObjectPagesSync(blocks, box, settings, signal) {
|
|
|
45733
45756
|
};
|
|
45734
45757
|
let work = 0;
|
|
45735
45758
|
for (const block of blocks) {
|
|
45759
|
+
if (++cooperativeWork % 64 === 0)
|
|
45760
|
+
yield;
|
|
45736
45761
|
signal.throwIfAborted();
|
|
45737
|
-
if (++work % 64 === 0)
|
|
45762
|
+
if (++work % 64 === 0)
|
|
45763
|
+
signal.throwIfAborted();
|
|
45738
45764
|
if (block.kind === "pagebreak") {
|
|
45739
45765
|
flushPage();
|
|
45740
45766
|
continue;
|
|
@@ -45749,6 +45775,8 @@ function layoutObjectPagesSync(blocks, box, settings, signal) {
|
|
|
45749
45775
|
cursorY -= 4;
|
|
45750
45776
|
const blockTopY = cursorY;
|
|
45751
45777
|
for (const line of lines) {
|
|
45778
|
+
if (++cooperativeWork % 64 === 0)
|
|
45779
|
+
yield;
|
|
45752
45780
|
const drawY = cursorY - fontSize;
|
|
45753
45781
|
const x = box.marginLeft;
|
|
45754
45782
|
currentActions.push((page, _doc, grayscale) => {
|
|
@@ -45766,6 +45794,8 @@ function layoutObjectPagesSync(blocks, box, settings, signal) {
|
|
|
45766
45794
|
const rectBottom = cursorY;
|
|
45767
45795
|
const rectTop = blockTopY;
|
|
45768
45796
|
for (const link of block.links) {
|
|
45797
|
+
if (++cooperativeWork % 64 === 0)
|
|
45798
|
+
yield;
|
|
45769
45799
|
currentActions.push((page) => {
|
|
45770
45800
|
page.addLinkAnnotation({
|
|
45771
45801
|
rect: [box.marginLeft, rectBottom, box.marginLeft + Math.min(contentWidth, 220), rectTop],
|
|
@@ -45785,6 +45815,8 @@ function layoutObjectPagesSync(blocks, box, settings, signal) {
|
|
|
45785
45815
|
ensureHeight(lines.length * lineHeight + 6);
|
|
45786
45816
|
const blockTopY = cursorY;
|
|
45787
45817
|
for (const line of lines) {
|
|
45818
|
+
if (++cooperativeWork % 64 === 0)
|
|
45819
|
+
yield;
|
|
45788
45820
|
const drawY = cursorY - fontSize;
|
|
45789
45821
|
const x = box.marginLeft;
|
|
45790
45822
|
const hasLink = (block.links?.length ?? 0) > 0;
|
|
@@ -45803,6 +45835,8 @@ function layoutObjectPagesSync(blocks, box, settings, signal) {
|
|
|
45803
45835
|
const rectBottom = cursorY;
|
|
45804
45836
|
const rectTop = blockTopY;
|
|
45805
45837
|
for (const link of block.links) {
|
|
45838
|
+
if (++cooperativeWork % 64 === 0)
|
|
45839
|
+
yield;
|
|
45806
45840
|
currentActions.push((page) => {
|
|
45807
45841
|
page.addLinkAnnotation({
|
|
45808
45842
|
rect: [box.marginLeft, rectBottom, box.marginLeft + Math.min(contentWidth, 220), rectTop],
|
|
@@ -45835,6 +45869,8 @@ function layoutObjectPagesSync(blocks, box, settings, signal) {
|
|
|
45835
45869
|
});
|
|
45836
45870
|
cursorY -= 6;
|
|
45837
45871
|
for (const rawLine of rawLines) {
|
|
45872
|
+
if (++cooperativeWork % 64 === 0)
|
|
45873
|
+
yield;
|
|
45838
45874
|
const drawY = cursorY - fontSize;
|
|
45839
45875
|
const x = box.marginLeft + 6;
|
|
45840
45876
|
currentActions.push((page, _doc, grayscale) => {
|
|
@@ -45856,10 +45892,14 @@ function layoutObjectPagesSync(blocks, box, settings, signal) {
|
|
|
45856
45892
|
const lineHeight = 15;
|
|
45857
45893
|
const items = block.items ?? [];
|
|
45858
45894
|
for (let idx = 0; idx < items.length; idx++) {
|
|
45895
|
+
if (++cooperativeWork % 64 === 0)
|
|
45896
|
+
yield;
|
|
45859
45897
|
const prefix = block.ordered ? `${idx + 1}. ` : "\u2022 ";
|
|
45860
45898
|
const lines = wrapTextLines(prefix + items[idx], Math.max(20, Math.floor((contentWidth - 14) / 5.8)));
|
|
45861
45899
|
ensureHeight(lines.length * lineHeight + 2);
|
|
45862
45900
|
for (let lineIdx = 0; lineIdx < lines.length; lineIdx++) {
|
|
45901
|
+
if (++cooperativeWork % 64 === 0)
|
|
45902
|
+
yield;
|
|
45863
45903
|
const drawY = cursorY - fontSize;
|
|
45864
45904
|
const x = box.marginLeft + (lineIdx === 0 ? 10 : 22);
|
|
45865
45905
|
const lineText = lines[lineIdx];
|
|
@@ -45898,6 +45938,8 @@ function layoutObjectPagesSync(blocks, box, settings, signal) {
|
|
|
45898
45938
|
});
|
|
45899
45939
|
});
|
|
45900
45940
|
for (const line of lines) {
|
|
45941
|
+
if (++cooperativeWork % 64 === 0)
|
|
45942
|
+
yield;
|
|
45901
45943
|
const drawY = cursorY - fontSize;
|
|
45902
45944
|
const x = box.marginLeft + 14;
|
|
45903
45945
|
currentActions.push((page, _doc, grayscale) => {
|
|
@@ -45949,19 +45991,21 @@ function layoutObjectPagesSync(blocks, box, settings, signal) {
|
|
|
45949
45991
|
}
|
|
45950
45992
|
if (block.kind === "table") {
|
|
45951
45993
|
const rows = block.rows ?? [];
|
|
45952
|
-
const colCount = Math.max(
|
|
45953
|
-
1,
|
|
45954
|
-
...rows.map((r) => r.cells.reduce((sum, c) => sum + c.colspan, 0))
|
|
45955
|
-
);
|
|
45994
|
+
const colCount = Math.max(1, ...rows.map((r) => r.cells.reduce((sum, c) => sum + c.colspan, 0)));
|
|
45956
45995
|
const colWidth = contentWidth / colCount;
|
|
45957
45996
|
const rowHeight = 20;
|
|
45958
45997
|
ensureHeight(rows.length * rowHeight + 8);
|
|
45959
45998
|
for (const row of rows) {
|
|
45999
|
+
if (++cooperativeWork % 64 === 0)
|
|
46000
|
+
yield;
|
|
45960
46001
|
ensureHeight(rowHeight);
|
|
45961
46002
|
const rowBottom = cursorY - rowHeight;
|
|
45962
46003
|
let colCursor = 0;
|
|
45963
46004
|
for (const cell of row.cells) {
|
|
45964
|
-
if (
|
|
46005
|
+
if (++cooperativeWork % 64 === 0)
|
|
46006
|
+
yield;
|
|
46007
|
+
if (colCursor >= colCount)
|
|
46008
|
+
break;
|
|
45965
46009
|
const span = Math.min(cell.colspan, colCount - colCursor);
|
|
45966
46010
|
const cellX = box.marginLeft + colCursor * colWidth;
|
|
45967
46011
|
const cellW = span * colWidth;
|
|
@@ -46035,7 +46079,8 @@ function substituteFurnitureTokens(template, tokens) {
|
|
|
46035
46079
|
const isoDate = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
46036
46080
|
return template.replace(/\[page\]/g, String(tokens.page)).replace(/\[topage\]/g, String(tokens.topage)).replace(/\[webpage\]/g, tokens.webpage).replace(/\[title\]/g, tokens.title).replace(/\[section\]/g, tokens.section ?? tokens.title).replace(/\[subsection\]/g, tokens.subsection ?? "").replace(/\[isodate\]/g, isoDate).replace(/\[date\]/g, isoDate);
|
|
46037
46081
|
}
|
|
46038
|
-
function
|
|
46082
|
+
function* renderPdfAstSteps(request) {
|
|
46083
|
+
let cooperativeWork = 0;
|
|
46039
46084
|
request.signal.throwIfAborted();
|
|
46040
46085
|
const { job, inputs, signal, limits } = request;
|
|
46041
46086
|
const decoder2 = new TextDecoder("utf-8", { fatal: false, ignoreBOM: true });
|
|
@@ -46045,15 +46090,17 @@ function renderPdfAstSync(request) {
|
|
|
46045
46090
|
const objectMeta = [];
|
|
46046
46091
|
let inferredDocumentTitle = job.global.documentTitle;
|
|
46047
46092
|
for (let i = 0; i < job.objects.length; i++) {
|
|
46093
|
+
if (++cooperativeWork % 64 === 0)
|
|
46094
|
+
yield;
|
|
46048
46095
|
signal.throwIfAborted();
|
|
46049
46096
|
const obj = job.objects[i];
|
|
46050
46097
|
const htmlBytes = inputs[i] ?? new Uint8Array(0);
|
|
46051
46098
|
const htmlText = decoder2.decode(htmlBytes);
|
|
46052
|
-
const parsed =
|
|
46099
|
+
const parsed = yield* parseHtmlDocumentSteps(htmlText, obj.settings.replacements, signal);
|
|
46053
46100
|
if (!inferredDocumentTitle && parsed.title) {
|
|
46054
46101
|
inferredDocumentTitle = parsed.title;
|
|
46055
46102
|
}
|
|
46056
|
-
const pages =
|
|
46103
|
+
const pages = yield* layoutObjectPagesSteps(parsed.blocks, box, obj.settings, signal);
|
|
46057
46104
|
laidOutPerObject.push(pages);
|
|
46058
46105
|
objectMeta.push({
|
|
46059
46106
|
title: parsed.title || inferredDocumentTitle || "Document",
|
|
@@ -46061,23 +46108,20 @@ function renderPdfAstSync(request) {
|
|
|
46061
46108
|
settings: obj.settings
|
|
46062
46109
|
});
|
|
46063
46110
|
}
|
|
46064
|
-
const sequence = planPageSequence(
|
|
46065
|
-
|
|
46066
|
-
|
|
46067
|
-
|
|
46068
|
-
|
|
46069
|
-
|
|
46070
|
-
|
|
46071
|
-
|
|
46072
|
-
|
|
46073
|
-
|
|
46074
|
-
|
|
46075
|
-
|
|
46076
|
-
|
|
46077
|
-
|
|
46078
|
-
signal
|
|
46079
|
-
}
|
|
46080
|
-
);
|
|
46111
|
+
const sequence = planPageSequence(laidOutPerObject.map((pages, idx) => ({
|
|
46112
|
+
physicalPages: pages.length,
|
|
46113
|
+
pagesCount: job.objects[idx].settings.pagesCount
|
|
46114
|
+
})), {
|
|
46115
|
+
copies: job.global.copies,
|
|
46116
|
+
collate: job.global.collate,
|
|
46117
|
+
pageOffset: job.global.pageOffset,
|
|
46118
|
+
limits: {
|
|
46119
|
+
maxObjects: limits.parse.maxObjects,
|
|
46120
|
+
maxPhysicalPages: Infinity,
|
|
46121
|
+
maxWork: limits.resources.maxWork
|
|
46122
|
+
},
|
|
46123
|
+
signal
|
|
46124
|
+
});
|
|
46081
46125
|
const doc = PdfDocument.create();
|
|
46082
46126
|
doc.setMetadata({
|
|
46083
46127
|
title: inferredDocumentTitle || "Document",
|
|
@@ -46085,11 +46129,16 @@ function renderPdfAstSync(request) {
|
|
|
46085
46129
|
producer: "@poe-code/pdf-ast"
|
|
46086
46130
|
});
|
|
46087
46131
|
for (const outPage of sequence.pages) {
|
|
46132
|
+
yield;
|
|
46088
46133
|
signal.throwIfAborted();
|
|
46089
46134
|
const spec = laidOutPerObject[outPage.objectIndex][outPage.pageIndex];
|
|
46090
46135
|
const meta = objectMeta[outPage.objectIndex];
|
|
46091
46136
|
const page = doc.addPage({ width: box.width, height: box.height });
|
|
46092
|
-
for (const action of spec.actions)
|
|
46137
|
+
for (const action of spec.actions) {
|
|
46138
|
+
if (++cooperativeWork % 64 === 0)
|
|
46139
|
+
yield;
|
|
46140
|
+
action(page, doc, grayscale);
|
|
46141
|
+
}
|
|
46093
46142
|
const tokens = {
|
|
46094
46143
|
page: outPage.logicalPage,
|
|
46095
46144
|
topage: sequence.logicalTotal + job.global.pageOffset,
|
|
@@ -46185,8 +46234,7 @@ function createPdfAstRenderer() {
|
|
|
46185
46234
|
return Object.freeze({
|
|
46186
46235
|
profile: pdfAstRendererProfile,
|
|
46187
46236
|
async open(request) {
|
|
46188
|
-
await
|
|
46189
|
-
const pdfBytes = renderPdfAstSync(request);
|
|
46237
|
+
const pdfBytes = await drainCooperativeSteps(renderPdfAstSteps(request), request.signal);
|
|
46190
46238
|
return {
|
|
46191
46239
|
success: true,
|
|
46192
46240
|
errorCode: 0,
|
|
@@ -46211,6 +46259,12 @@ function pdfAstWkhtmltopdfCommands(options = {}) {
|
|
|
46211
46259
|
...options.replace === void 0 ? {} : { replace: options.replace }
|
|
46212
46260
|
});
|
|
46213
46261
|
}
|
|
46262
|
+
function renderPdfAstSync(request) {
|
|
46263
|
+
const steps = renderPdfAstSteps(request);
|
|
46264
|
+
let next = steps.next();
|
|
46265
|
+
while (!next.done) next = steps.next();
|
|
46266
|
+
return next.value;
|
|
46267
|
+
}
|
|
46214
46268
|
var pdfAstRendererProfile;
|
|
46215
46269
|
var PAGE_SIZES_PT;
|
|
46216
46270
|
var pdfAstRenderer;
|
|
@@ -3,9 +3,9 @@ import type { CommandDefinition } from "../safe-bash-contracts/command.js";
|
|
|
3
3
|
import type { VirtualShellPlugin } from "../safe-bash-contracts/plugin.js";
|
|
4
4
|
import { type RendererProfile } from "./engine.js";
|
|
5
5
|
export declare const pdfAstRendererProfile: RendererProfile;
|
|
6
|
-
export declare function renderPdfAstSync(request: Parameters<StaticRenderer["open"]>[0]): Uint8Array;
|
|
7
6
|
export declare function createPdfAstRenderer(): StaticRenderer;
|
|
8
7
|
export declare const pdfAstRenderer: StaticRenderer;
|
|
9
8
|
export declare function createPdfAstWkhtmltopdfCommand(options?: Partial<WkhtmltopdfCommandOptions>): CommandDefinition;
|
|
10
9
|
export declare const pdfAstWkhtmltopdfCommand: CommandDefinition;
|
|
11
10
|
export declare function pdfAstWkhtmltopdfCommands(options?: Partial<WkhtmltopdfCommandOptions>): VirtualShellPlugin;
|
|
11
|
+
export declare function renderPdfAstSync(request: Parameters<StaticRenderer["open"]>[0]): Uint8Array;
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
|
|
5
5
|
// packages/safe-bash-command-xxd/dist/index.js
|
|
6
6
|
init_buffer();
|
|
7
|
+
import { writeFileOutput } from "../safe-bash-contracts/filesystem-output-budget.js";
|
|
7
8
|
import { isAbsolutePath, validatePath } from "@poe-platform/safe-fs/core";
|
|
8
9
|
import { CommandArgumentIdentityError, FsError, readBytes, shellValueByteLength, writeBytes } from "../safe-bash-contracts/index.js";
|
|
9
10
|
import { PublicDiagnostic } from "../safe-bash-contracts/public-diagnostic.js";
|
|
@@ -304,7 +305,18 @@ function hexDigit(byte) {
|
|
|
304
305
|
return byte - 87;
|
|
305
306
|
return -1;
|
|
306
307
|
}
|
|
307
|
-
async function
|
|
308
|
+
async function padToAddress(context, start, address) {
|
|
309
|
+
if (!Number.isSafeInteger(address) || address < start)
|
|
310
|
+
throw new PublicDiagnostic("invalid input: cannot seek backwards on output stream");
|
|
311
|
+
while (start < address) {
|
|
312
|
+
const length = Math.min(blockSize, address - start);
|
|
313
|
+
await output(context, new Uint8Array(length));
|
|
314
|
+
start += length;
|
|
315
|
+
await yieldTurn(context.signal);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
async function reversePlain(context, files, maxInputBytes, seek) {
|
|
319
|
+
await padToAddress(context, 0, seek);
|
|
308
320
|
let high = -1;
|
|
309
321
|
for await (const chunk of sources(context, files, maxInputBytes)) {
|
|
310
322
|
const pending = [];
|
|
@@ -327,7 +339,7 @@ async function reversePlain(context, files, maxInputBytes) {
|
|
|
327
339
|
await output(context, Uint8Array.from(pending));
|
|
328
340
|
}
|
|
329
341
|
}
|
|
330
|
-
async function reverseNormal(context, files, columns, maxInputBytes) {
|
|
342
|
+
async function reverseNormal(context, files, columns, maxInputBytes, seek) {
|
|
331
343
|
let line = "";
|
|
332
344
|
let offset = 0;
|
|
333
345
|
const outBuf = new Uint8Array(8192);
|
|
@@ -342,7 +354,7 @@ async function reverseNormal(context, files, columns, maxInputBytes) {
|
|
|
342
354
|
}
|
|
343
355
|
};
|
|
344
356
|
const rowScratch = new Uint8Array(Math.max(columns, 256));
|
|
345
|
-
const parseLineBytesInto = (buf, startPos, endPos) => {
|
|
357
|
+
const parseLineBytesInto = async (buf, startPos, endPos) => {
|
|
346
358
|
let nonSpace = false;
|
|
347
359
|
for (let i = startPos; i < endPos; i++) {
|
|
348
360
|
const c = buf[i];
|
|
@@ -351,7 +363,7 @@ async function reverseNormal(context, files, columns, maxInputBytes) {
|
|
|
351
363
|
break;
|
|
352
364
|
}
|
|
353
365
|
}
|
|
354
|
-
if (!nonSpace)
|
|
366
|
+
if (!nonSpace || endPos - startPos === 1 && buf[startPos] === 42)
|
|
355
367
|
return 0;
|
|
356
368
|
const colonAbs = buf.indexOf(58, startPos);
|
|
357
369
|
const colon = colonAbs >= 0 && colonAbs < endPos ? colonAbs - startPos : -1;
|
|
@@ -364,8 +376,10 @@ async function reverseNormal(context, files, columns, maxInputBytes) {
|
|
|
364
376
|
throw new PublicDiagnostic("invalid input: expected hexadecimal address and colon");
|
|
365
377
|
address = address * 16 + digit;
|
|
366
378
|
}
|
|
367
|
-
|
|
368
|
-
|
|
379
|
+
address = addOffset(address, seek);
|
|
380
|
+
await flushOut();
|
|
381
|
+
await padToAddress(context, offset, address);
|
|
382
|
+
offset = address;
|
|
369
383
|
let count = 0;
|
|
370
384
|
let high = -1;
|
|
371
385
|
let spaces = 0;
|
|
@@ -406,7 +420,7 @@ async function reverseNormal(context, files, columns, maxInputBytes) {
|
|
|
406
420
|
}
|
|
407
421
|
let count = 0;
|
|
408
422
|
if (line.length === 0) {
|
|
409
|
-
count = parseLineBytesInto(chunk, start, nl);
|
|
423
|
+
count = await parseLineBytesInto(chunk, start, nl);
|
|
410
424
|
} else {
|
|
411
425
|
for (let i = start; i < nl; i++)
|
|
412
426
|
line += String.fromCharCode(chunk[i]);
|
|
@@ -414,7 +428,7 @@ async function reverseNormal(context, files, columns, maxInputBytes) {
|
|
|
414
428
|
for (let i = 0; i < line.length; i++)
|
|
415
429
|
lineBytes[i] = line.charCodeAt(i);
|
|
416
430
|
line = "";
|
|
417
|
-
count = parseLineBytesInto(lineBytes, 0, lineBytes.length);
|
|
431
|
+
count = await parseLineBytesInto(lineBytes, 0, lineBytes.length);
|
|
418
432
|
}
|
|
419
433
|
start = nl + 1;
|
|
420
434
|
if (count > 0) {
|
|
@@ -433,7 +447,7 @@ async function reverseNormal(context, files, columns, maxInputBytes) {
|
|
|
433
447
|
const lineBytes = new Uint8Array(line.length);
|
|
434
448
|
for (let i = 0; i < line.length; i++)
|
|
435
449
|
lineBytes[i] = line.charCodeAt(i);
|
|
436
|
-
const count = parseLineBytesInto(lineBytes, 0, lineBytes.length);
|
|
450
|
+
const count = await parseLineBytesInto(lineBytes, 0, lineBytes.length);
|
|
437
451
|
if (count > 0) {
|
|
438
452
|
if (outUsed + count > outBuf.length)
|
|
439
453
|
await flushOut();
|
|
@@ -472,7 +486,9 @@ function createXxdCommand(optionsOrMaxBytes) {
|
|
|
472
486
|
"-len": "-l",
|
|
473
487
|
"-bits": "-b",
|
|
474
488
|
"-include": "-i",
|
|
475
|
-
"-name": "-n"
|
|
489
|
+
"-name": "-n",
|
|
490
|
+
"-autoskip": "-a",
|
|
491
|
+
"-capitalize": "-C"
|
|
476
492
|
};
|
|
477
493
|
let ended = false;
|
|
478
494
|
const args = context.args.map((argument) => {
|
|
@@ -482,10 +498,17 @@ function createXxdCommand(optionsOrMaxBytes) {
|
|
|
482
498
|
ended = true;
|
|
483
499
|
return aliases[argument] ?? argument;
|
|
484
500
|
});
|
|
485
|
-
const parsed = parseOptions(args, "
|
|
501
|
+
const parsed = parseOptions(args, "aCprdubiec:g:l:s:o:n:");
|
|
486
502
|
requireOperands(parsed.operands, 0, 2);
|
|
487
503
|
if (parsed.operands[1] !== void 0 && parsed.operands[1] !== "-") {
|
|
488
|
-
|
|
504
|
+
const original = context;
|
|
505
|
+
const path = pathOf(context, parsed.operands[1]);
|
|
506
|
+
let started = false;
|
|
507
|
+
context = { ...original, stdout: { async write(bytes) {
|
|
508
|
+
await writeFileOutput(original, bytes, (data) => started ? original.fs.appendFile(path, data, { signal: original.signal }) : original.fs.writeFile(path, data, { signal: original.signal }));
|
|
509
|
+
started = true;
|
|
510
|
+
} } };
|
|
511
|
+
await writeBytes(context.stdout, new Uint8Array(), context.signal);
|
|
489
512
|
}
|
|
490
513
|
const files = parsed.operands.slice(0, 1);
|
|
491
514
|
const plain = parsed.flags.has("p");
|
|
@@ -511,21 +534,31 @@ function createXxdCommand(optionsOrMaxBytes) {
|
|
|
511
534
|
if (littleEndian && group && !Number.isInteger(Math.log2(group))) {
|
|
512
535
|
throw new UsageError("number of octets per group must be a power of 2 with -e");
|
|
513
536
|
}
|
|
514
|
-
|
|
537
|
+
let skip = validatedOption(parsed, "s", (text) => {
|
|
538
|
+
const relative = text.startsWith("+") ? text.slice(1) : text;
|
|
539
|
+
return relative.startsWith("-") ? -numeric(relative.slice(1)) : numeric(relative);
|
|
540
|
+
}, 0);
|
|
515
541
|
const count = validatedOption(parsed, "l", numeric, Infinity);
|
|
516
542
|
const displacement = validatedOption(parsed, "o", numeric, 0);
|
|
517
|
-
if (reverse && ["
|
|
543
|
+
if (reverse && ["l", "o", "d"].some((flag) => parsed.flags.has(flag))) {
|
|
518
544
|
throw new UsageError("reverse does not support seek, length, displacement, or decimal addresses");
|
|
519
545
|
}
|
|
520
546
|
if (reverse) {
|
|
521
547
|
if (plain)
|
|
522
|
-
await reversePlain(context, files, maxInputBytes);
|
|
548
|
+
await reversePlain(context, files, maxInputBytes, skip);
|
|
523
549
|
else
|
|
524
|
-
await reverseNormal(context, files, columns, maxInputBytes);
|
|
550
|
+
await reverseNormal(context, files, columns, maxInputBytes, skip);
|
|
525
551
|
return { exitCode: 0 };
|
|
526
552
|
}
|
|
553
|
+
const input = sources(context, files, maxInputBytes);
|
|
554
|
+
if (skip < 0) {
|
|
555
|
+
if (!files[0] || files[0] === "-")
|
|
556
|
+
throw new UsageError("negative seek requires an input file");
|
|
557
|
+
const size = (await context.fs.stat(pathOf(context, files[0]), { signal: context.signal })).size;
|
|
558
|
+
skip = Math.max(0, size + skip);
|
|
559
|
+
}
|
|
527
560
|
let offset = addOffset(skip, displacement);
|
|
528
|
-
const source = range(
|
|
561
|
+
const source = range(input, skip, count);
|
|
529
562
|
let any = false;
|
|
530
563
|
let includeLength = 0;
|
|
531
564
|
let includeRow = "";
|
|
@@ -539,6 +572,8 @@ function createXxdCommand(optionsOrMaxBytes) {
|
|
|
539
572
|
if (identifier[0] && identifier[0] >= "0" && identifier[0] <= "9")
|
|
540
573
|
identifier = "__" + identifier;
|
|
541
574
|
}
|
|
575
|
+
if (parsed.flags.has("C"))
|
|
576
|
+
identifier = identifier.toUpperCase();
|
|
542
577
|
const upper = parsed.flags.has("u");
|
|
543
578
|
const hexTable = upper ? HEX_UPPER : HEX_LOWER;
|
|
544
579
|
const byteTable = binary ? BIN_TABLE : hexTable;
|
|
@@ -564,6 +599,17 @@ function createXxdCommand(optionsOrMaxBytes) {
|
|
|
564
599
|
await writeOut(`unsigned char ${identifier}[] = {
|
|
565
600
|
`);
|
|
566
601
|
const rowWidth = plain && !columns ? 4096 : columns;
|
|
602
|
+
let zeroRun = 0;
|
|
603
|
+
let zeroSecond = "", zeroLast = "";
|
|
604
|
+
const finishZeros = (atEnd) => {
|
|
605
|
+
if (zeroRun >= (atEnd ? 4 : 3))
|
|
606
|
+
outBuf += "*\n" + (atEnd ? zeroLast : "");
|
|
607
|
+
else if (zeroRun === 3)
|
|
608
|
+
outBuf += zeroSecond + zeroLast;
|
|
609
|
+
else if (zeroRun === 2)
|
|
610
|
+
outBuf += zeroLast;
|
|
611
|
+
zeroRun = 0;
|
|
612
|
+
};
|
|
567
613
|
for await (const batch of rows(source, rowWidth)) {
|
|
568
614
|
any = true;
|
|
569
615
|
for (let rowStart = 0; rowStart < batch.length; rowStart += rowWidth) {
|
|
@@ -578,7 +624,7 @@ function createXxdCommand(optionsOrMaxBytes) {
|
|
|
578
624
|
await flushOut();
|
|
579
625
|
continue;
|
|
580
626
|
}
|
|
581
|
-
if (!plain && !littleEndian && !binary && columns === 16 && group === 2 && row.length === 16) {
|
|
627
|
+
if (!parsed.flags.has("a") && !plain && !littleEndian && !binary && columns === 16 && group === 2 && row.length === 16) {
|
|
582
628
|
const b0 = row[0], b1 = row[1], b2 = row[2], b3 = row[3];
|
|
583
629
|
const b4 = row[4], b5 = row[5], b6 = row[6], b7 = row[7];
|
|
584
630
|
const b8 = row[8], b9 = row[9], b10 = row[10], b11 = row[11];
|
|
@@ -615,20 +661,32 @@ function createXxdCommand(optionsOrMaxBytes) {
|
|
|
615
661
|
outBuf += data + (columns ? "\n" : "");
|
|
616
662
|
else {
|
|
617
663
|
const address = offset.toString(decimalAddress ? 10 : 16).padStart(8, "0");
|
|
618
|
-
|
|
664
|
+
const formatted = `${address}: ${data.padEnd(width)} ${ascii}
|
|
619
665
|
`;
|
|
666
|
+
if (parsed.flags.has("a") && row.length === columns && row.every((byte) => byte === 0)) {
|
|
667
|
+
if (zeroRun === 0)
|
|
668
|
+
outBuf += formatted;
|
|
669
|
+
if (zeroRun === 1)
|
|
670
|
+
zeroSecond = formatted;
|
|
671
|
+
zeroRun++;
|
|
672
|
+
zeroLast = formatted;
|
|
673
|
+
} else {
|
|
674
|
+
finishZeros(false);
|
|
675
|
+
outBuf += formatted;
|
|
676
|
+
}
|
|
620
677
|
}
|
|
621
678
|
offset = addOffset(offset, row.length);
|
|
622
679
|
if (!flushedFirst || outBuf.length >= 16384)
|
|
623
680
|
await flushOut();
|
|
624
681
|
}
|
|
625
682
|
}
|
|
683
|
+
finishZeros(true);
|
|
626
684
|
if (include) {
|
|
627
685
|
if (includeRow)
|
|
628
686
|
await writeOut(includeRow + "\n");
|
|
629
687
|
if (includeName !== void 0)
|
|
630
688
|
await writeOut(`};
|
|
631
|
-
unsigned int ${identifier}_len = ${includeLength};
|
|
689
|
+
unsigned int ${identifier}${parsed.flags.has("C") ? "_LEN" : "_len"} = ${includeLength};
|
|
632
690
|
`);
|
|
633
691
|
}
|
|
634
692
|
if (plain && !columns && any)
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import type { CommandDefinition } from "../safe-bash-contracts/index.js";
|
|
2
2
|
import { type CompressionCommandOptions } from "../safe-bash-compression-engine/stream.js";
|
|
3
3
|
import type { VirtualShellPlugin } from "../safe-bash-contracts/plugin.js";
|
|
4
|
+
export interface XzLimits {
|
|
5
|
+
readonly maxDecodedBytes: number;
|
|
6
|
+
}
|
|
4
7
|
export interface XzCommandsOptions extends CompressionCommandOptions {
|
|
8
|
+
readonly limits?: Partial<XzLimits>;
|
|
5
9
|
readonly replace?: boolean;
|
|
6
10
|
}
|
|
7
11
|
export declare function createXzCommand(config?: XzCommandsOptions, name?: string): CommandDefinition;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { createXzCommands, createXzCommand, xzCommands, type XzCommandsOptions } from "./command.js";
|
|
1
|
+
export { createXzCommands, createXzCommand, xzCommands, type XzLimits, type XzCommandsOptions } from "./command.js";
|
|
2
2
|
export type { CompressionCommandOptions } from "../safe-bash-compression-engine/stream.js";
|
|
@@ -24,7 +24,7 @@ import { runOperand } from "../safe-bash-compression-engine/operand.js";
|
|
|
24
24
|
import { planOperands, verifyOperandDestinations } from "../safe-bash-compression-engine/files.js";
|
|
25
25
|
import { DecodedBudget } from "../safe-bash-compression-engine/stream.js";
|
|
26
26
|
function createXzCommand(config = {}, name = "xz") {
|
|
27
|
-
const maxDecodedBytes = config.maxDecodedBytes;
|
|
27
|
+
const maxDecodedBytes = config.limits?.maxDecodedBytes ?? config.maxDecodedBytes ?? Infinity;
|
|
28
28
|
if (maxDecodedBytes !== void 0 && maxDecodedBytes !== Infinity && (!Number.isSafeInteger(maxDecodedBytes) || maxDecodedBytes < 0)) {
|
|
29
29
|
throw new RangeError("maxDecodedBytes must be a nonnegative safe integer or Infinity");
|
|
30
30
|
}
|