@poe-platform/safe-bash 0.1.754 → 0.1.755
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/dist/image-ast/index.browser.js +13 -1
- package/dist/image-ast/index.js +13 -1
- package/dist/pdf-ast/fonts/truetype.d.ts +1 -0
- package/dist/pdf-ast/index.js +13 -1
- package/dist/safe-bash/chunks/{chunk-R2WG64VB.js → chunk-6XDKK63A.js} +14 -2
- package/dist/safe-bash/chunks/{chunk-3W6CRM25.js → chunk-JEFBTRY7.js} +553 -289
- package/dist/safe-bash/chunks/{chunk-WNB4XH45.js → chunk-QHB7HBLA.js} +3 -3
- package/dist/safe-bash/chunks/{chunk-37Y7GZTK.js → chunk-RSAWYAEH.js} +2 -2
- package/dist/safe-bash/chunks/{pdf-renderer-DHQDZC6N.js → pdf-renderer-XIFUTX34.js} +3 -3
- package/dist/safe-bash/chunks/{src-S52LORVD.js → src-V4VCM5OX.js} +5 -3
- package/dist/safe-bash/command-chunks/{chunk-IJHV6I6X.js → chunk-3DOHQQJR.js} +8 -6
- package/dist/safe-bash/command-chunks/chunk-IDR3WWKI.js +46 -0
- package/dist/safe-bash/command-chunks/{chunk-XAZ3NTJ4.js → chunk-KB2LQ4HG.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-YY7HJMBG.js → chunk-KOM3FNCE.js} +1 -37
- package/dist/safe-bash/command-chunks/{chunk-CM4SVTIA.js → chunk-MENC7RPR.js} +1 -1
- package/dist/safe-bash/command-chunks/chunk-QQOAK7JQ.js +888 -0
- package/dist/safe-bash/command-chunks/{chunk-BE4AM2JW.js → chunk-UGX6MXDD.js} +5 -3
- package/dist/safe-bash/command-chunks/{chunk-PUOJAS3O.js → chunk-XRVNFK7Z.js} +13 -1
- package/dist/safe-bash/commands/ssconvert/index.d.ts +1 -2
- package/dist/safe-bash/commands/ssconvert/index.js +6 -260
- package/dist/safe-bash/core.browser.js +5 -207
- package/dist/safe-bash-command-csvkit/index.js +277 -49
- package/dist/safe-bash-command-ffmpeg/index.js +1723 -1717
- package/dist/safe-bash-command-imagemagick/index.js +2 -2
- package/dist/safe-bash-command-pandoc/command.js +3 -3
- package/dist/safe-bash-command-pandoc/index.js +3 -3
- package/dist/safe-bash-command-pdfimages/index.js +13 -1
- package/dist/safe-bash-command-pdfinfo/index.js +13 -1
- package/dist/safe-bash-command-pdftk/index.js +13 -1
- package/dist/safe-bash-command-pdftoppm/index.js +13 -1
- package/dist/safe-bash-command-pdftotext/index.js +13 -1
- package/dist/safe-bash-command-qpdf/index.js +13 -1
- package/dist/safe-bash-command-sips/index.js +2 -2
- package/dist/safe-bash-command-soffice/index.js +5 -4
- package/dist/safe-bash-command-ssconvert/formats/csv.js +4 -3
- package/dist/safe-bash-command-ssconvert/formats/spreadsheetml.js +4 -2
- package/dist/safe-bash-command-ssconvert/formats/xls.js +10 -666
- package/dist/safe-bash-command-ssconvert/index.d.ts +1 -0
- package/dist/safe-bash-command-ssconvert/index.js +680 -390
- package/dist/safe-bash-command-ssconvert/sync.d.ts +7 -0
- package/dist/safe-bash-command-timeout/index.js +1 -1
- package/dist/safe-bash-command-wkhtmltopdf/index.js +13 -1
- package/dist/spreadsheet-format-csv/text-export.d.ts +14 -0
- package/dist/spreadsheet-format-csv/text-export.js +2 -2
- package/dist/spreadsheet-format-xls/biff-binary.d.ts +7 -2
- package/dist/spreadsheet-format-xls/biff-binary.js +10 -1
- package/dist/spreadsheet-format-xls/biff-strings.d.ts +2 -3
- package/dist/spreadsheet-format-xls/biff-strings.js +14 -2
- package/package.json +2 -3
- package/third-party/pdf-ast/THIRD_PARTY_NOTICES.md +7 -0
- package/dist/safe-bash/command-chunks/chunk-MPUNHXWI.js +0 -205
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
encodingName
|
|
3
|
-
|
|
4
|
-
} from "./chunk-YY7HJMBG.js";
|
|
2
|
+
encodingName
|
|
3
|
+
} from "./chunk-IDR3WWKI.js";
|
|
5
4
|
import {
|
|
6
5
|
TextConverterUnavailable
|
|
7
6
|
} from "./chunk-JRNLDPLI.js";
|
|
7
|
+
import {
|
|
8
|
+
singleByteTables
|
|
9
|
+
} from "./chunk-KOM3FNCE.js";
|
|
8
10
|
import {
|
|
9
11
|
converterLocale
|
|
10
12
|
} from "./chunk-4HQ7WYSI.js";
|
|
@@ -30494,17 +30494,22 @@ function parseTrueTypeFont(bytes) {
|
|
|
30494
30494
|
const cmapNumTables = cmap ? readU16(view, cmapOffset + 2) : 0;
|
|
30495
30495
|
let format4Offset = 0;
|
|
30496
30496
|
let format12Offset = 0;
|
|
30497
|
+
let format4IsSymbolic = false;
|
|
30498
|
+
let format12IsSymbolic = false;
|
|
30497
30499
|
for (let i = 0; i < cmapNumTables; i++) {
|
|
30498
30500
|
const rec = cmapOffset + 4 + i * 8;
|
|
30499
30501
|
if (rec + 8 > bytes.byteLength) break;
|
|
30500
30502
|
const platformID = readU16(view, rec);
|
|
30503
|
+
const encodingID = readU16(view, rec + 2);
|
|
30501
30504
|
const subOffset = cmapOffset + readU32(view, rec + 4);
|
|
30502
30505
|
if (subOffset + 4 > bytes.byteLength) continue;
|
|
30503
30506
|
const fmt = readU16(view, subOffset);
|
|
30504
30507
|
if (fmt === 12 && (platformID === 3 || platformID === 0)) {
|
|
30505
30508
|
format12Offset = subOffset;
|
|
30509
|
+
format12IsSymbolic = platformID === 3 && encodingID === 0;
|
|
30506
30510
|
} else if (fmt === 4 && (platformID === 3 || platformID === 0)) {
|
|
30507
30511
|
format4Offset = subOffset;
|
|
30512
|
+
format4IsSymbolic = platformID === 3 && encodingID === 0;
|
|
30508
30513
|
}
|
|
30509
30514
|
}
|
|
30510
30515
|
if (format12Offset > 0) {
|
|
@@ -30793,6 +30798,7 @@ function parseTrueTypeFont(bytes) {
|
|
|
30793
30798
|
numGlyphs,
|
|
30794
30799
|
isCff: renderCffGlyph !== void 0,
|
|
30795
30800
|
hasCmap: cmap !== void 0,
|
|
30801
|
+
isSymbolicCmap: format12Offset > 0 ? format12IsSymbolic : format4IsSymbolic,
|
|
30796
30802
|
glyphNames,
|
|
30797
30803
|
getGlyphId(codePoint) {
|
|
30798
30804
|
return codePointToGlyph.get(codePoint) ?? 0;
|
|
@@ -31057,7 +31063,13 @@ function resolvePageFonts(doc, resourcesDict) {
|
|
|
31057
31063
|
embeddedCff = parseEmbeddedCffFont(doc.decodeStream(program), baseEncoding?.kind === "name" ? baseEncoding.decoded : void 0, glyphNames);
|
|
31058
31064
|
} else {
|
|
31059
31065
|
embeddedTrueType = parseTrueTypeFont(doc.decodeStream(program));
|
|
31060
|
-
if (subtype !== "Type0" &&
|
|
31066
|
+
if (subtype !== "Type0" && embeddedTrueType.isSymbolicCmap) {
|
|
31067
|
+
simpleToGid = /* @__PURE__ */ new Map();
|
|
31068
|
+
for (let code = 0; code < 256; code++) {
|
|
31069
|
+
const gid = embeddedTrueType.getGlyphId(61440 + code) || embeddedTrueType.getGlyphId(code);
|
|
31070
|
+
if (gid > 0) simpleToGid.set(code, gid);
|
|
31071
|
+
}
|
|
31072
|
+
} else if (subtype !== "Type0" && !embeddedTrueType.hasCmap) {
|
|
31061
31073
|
simpleToGid = /* @__PURE__ */ new Map();
|
|
31062
31074
|
const encoding = baseEncoding?.kind === "name" ? getEncoding(baseEncoding.decoded) : void 0;
|
|
31063
31075
|
for (let code = 0; code < 256; code++) {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { CommandHandler } from "../../contracts/index.js";
|
|
2
1
|
export * from "../../../safe-bash-command-ssconvert/index.js";
|
|
3
|
-
export declare
|
|
2
|
+
export declare const evalSyncSsconvert: (execute: import("../../../safe-bash-contracts/index.js").CommandHandler, opArgs: readonly string[], inBytes?: Uint8Array, readFileSync?: (filePath: string) => Uint8Array | undefined, writeFileSync?: (filePath: string, bytes: Uint8Array) => boolean) => string | undefined;
|
|
4
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,264 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { syncCommandEvaluators } from "../internal.js";
|
|
2
|
+
import { createSyncSsconvertEvaluator } from "../../../safe-bash-command-ssconvert/index.js";
|
|
3
3
|
import { createStoredZipArchive, readZipArchiveEntries } from "../../../safe-bash-command-soffice/index.js";
|
|
4
4
|
export * from "../../../safe-bash-command-ssconvert/index.js";
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
.replace(/&#x([0-9a-fA-F]+);/g, (_, hex) => String.fromCodePoint(Number.parseInt(hex, 16)))
|
|
10
|
-
.replace(/&#(\d+);/g, (_, dec) => String.fromCodePoint(Number.parseInt(dec, 10)))
|
|
11
|
-
.replace(/</g, "<")
|
|
12
|
-
.replace(/>/g, ">")
|
|
13
|
-
.replace(/"/g, '"')
|
|
14
|
-
.replace(/'/g, "'")
|
|
15
|
-
.replace(/&/g, "&");
|
|
16
|
-
}
|
|
17
|
-
function parseSimpleSeparatedRows(text, sep) {
|
|
18
|
-
const rows = [];
|
|
19
|
-
let row = [];
|
|
20
|
-
let field = "";
|
|
21
|
-
let quoted = false;
|
|
22
|
-
for (let i = 0; i < text.length; i++) {
|
|
23
|
-
const ch = text[i];
|
|
24
|
-
if (ch === '"') {
|
|
25
|
-
if (quoted && text[i + 1] === '"') {
|
|
26
|
-
field += '"';
|
|
27
|
-
i++;
|
|
28
|
-
}
|
|
29
|
-
else if (quoted || field.length === 0) {
|
|
30
|
-
quoted = !quoted;
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
return undefined;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
else if (!quoted && ch === sep) {
|
|
37
|
-
if (field.startsWith("=") || field.startsWith("'"))
|
|
38
|
-
return undefined;
|
|
39
|
-
row.push(field);
|
|
40
|
-
field = "";
|
|
41
|
-
}
|
|
42
|
-
else if (!quoted && (ch === "\r" || ch === "\n")) {
|
|
43
|
-
if (field.startsWith("=") || field.startsWith("'"))
|
|
44
|
-
return undefined;
|
|
45
|
-
row.push(field);
|
|
46
|
-
rows.push(row);
|
|
47
|
-
row = [];
|
|
48
|
-
field = "";
|
|
49
|
-
if (ch === "\r" && text[i + 1] === "\n")
|
|
50
|
-
i++;
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
field += ch;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
if (quoted)
|
|
57
|
-
return undefined;
|
|
58
|
-
if (field.length > 0 || row.length > 0) {
|
|
59
|
-
if (field.startsWith("=") || field.startsWith("'"))
|
|
60
|
-
return undefined;
|
|
61
|
-
row.push(field);
|
|
62
|
-
rows.push(row);
|
|
63
|
-
}
|
|
64
|
-
return rows;
|
|
65
|
-
}
|
|
66
|
-
function parseSimpleXlsxRows(zipBytes) {
|
|
67
|
-
const entries = readZipArchiveEntries(zipBytes);
|
|
68
|
-
if (entries.has("EncryptionInfo") ||
|
|
69
|
-
entries.has("EncryptedPackage") ||
|
|
70
|
-
entries.has("xl/worksheets/sheet2.xml")) {
|
|
71
|
-
return undefined;
|
|
72
|
-
}
|
|
73
|
-
const sharedStrings = [];
|
|
74
|
-
const sstBytes = entries.get("xl/sharedStrings.xml");
|
|
75
|
-
if (sstBytes) {
|
|
76
|
-
const sstXml = syncUtf8Decoder.decode(sstBytes);
|
|
77
|
-
for (const si of sstXml.matchAll(/<si\b[\s\S]*?<\/si>/g)) {
|
|
78
|
-
const parts = [...si[0].matchAll(/<t(?:\s[^>]*)?>([\s\S]*?)<\/t>/g)].map((t) => unescapeXml(t[1] ?? ""));
|
|
79
|
-
sharedStrings.push(parts.join(""));
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
const sheetBytes = entries.get("xl/worksheets/sheet1.xml");
|
|
83
|
-
if (!sheetBytes)
|
|
84
|
-
return undefined;
|
|
85
|
-
const sheetXml = syncUtf8Decoder.decode(sheetBytes);
|
|
86
|
-
if (/<f(?:\s|>)/u.test(sheetXml))
|
|
87
|
-
return undefined;
|
|
88
|
-
const rows = [];
|
|
89
|
-
for (const rowMatch of sheetXml.matchAll(/<row\b([^>]*)>[\s\S]*?<\/row>/g)) {
|
|
90
|
-
// The shortcut only appends dense cells. Let the canonical reader place
|
|
91
|
-
// sparse rows/columns, including leading gaps, before any output is written.
|
|
92
|
-
const rowRef = /\br="(\d+)"/.exec(rowMatch[1] ?? "");
|
|
93
|
-
if (!rowRef || Number(rowRef[1]) !== rows.length + 1)
|
|
94
|
-
return undefined;
|
|
95
|
-
const rowCells = [];
|
|
96
|
-
for (const cellMatch of rowMatch[0].matchAll(/<c\b([^>]*?)(?:\/>|>([\s\S]*?)<\/c>)/g)) {
|
|
97
|
-
const attrs = cellMatch[1] ?? "";
|
|
98
|
-
const body = cellMatch[2] ?? "";
|
|
99
|
-
const refMatch = /\br="([A-Z]+)(\d+)"/i.exec(attrs);
|
|
100
|
-
if (!refMatch || Number(refMatch[2]) !== rows.length + 1)
|
|
101
|
-
return undefined;
|
|
102
|
-
if (refMatch?.[1]) {
|
|
103
|
-
let targetCol = 0;
|
|
104
|
-
for (const ch of refMatch[1].toUpperCase()) {
|
|
105
|
-
targetCol = targetCol * 26 + (ch.charCodeAt(0) - 64);
|
|
106
|
-
}
|
|
107
|
-
targetCol -= 1;
|
|
108
|
-
if (targetCol !== rowCells.length)
|
|
109
|
-
return undefined;
|
|
110
|
-
}
|
|
111
|
-
if (cellMatch[2] === undefined) {
|
|
112
|
-
rowCells.push("");
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
const typeMatch = /\bt="([^"]+)"/.exec(attrs);
|
|
116
|
-
const cellType = typeMatch?.[1] ?? "n";
|
|
117
|
-
if (cellType === "inlineStr") {
|
|
118
|
-
const tVal = /<t(?:\s[^>]*)?>([\s\S]*?)<\/t>/.exec(body);
|
|
119
|
-
rowCells.push(unescapeXml(tVal?.[1] ?? ""));
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
const vVal = /<v>([\s\S]*?)<\/v>/.exec(body);
|
|
123
|
-
const raw = unescapeXml(vVal?.[1] ?? "");
|
|
124
|
-
if (cellType === "s") {
|
|
125
|
-
const idx = Number.parseInt(raw, 10);
|
|
126
|
-
rowCells.push(sharedStrings[idx] ?? "");
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
rowCells.push(raw);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
rows.push(rowCells);
|
|
134
|
-
}
|
|
135
|
-
return rows;
|
|
136
|
-
}
|
|
137
|
-
function buildSimpleXlsx(rows, sheetName = "Sheet1") {
|
|
138
|
-
const esc = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
139
|
-
const colName = (idx) => {
|
|
140
|
-
let n = idx + 1;
|
|
141
|
-
let out = "";
|
|
142
|
-
while (n > 0) {
|
|
143
|
-
const rem = (n - 1) % 26;
|
|
144
|
-
out = String.fromCharCode(65 + rem) + out;
|
|
145
|
-
n = Math.floor((n - 1) / 26);
|
|
146
|
-
}
|
|
147
|
-
return out;
|
|
148
|
-
};
|
|
149
|
-
const sheetRows = rows
|
|
150
|
-
.map((row, rIdx) => {
|
|
151
|
-
const cells = row
|
|
152
|
-
.map((val, cIdx) => {
|
|
153
|
-
const ref = `${colName(cIdx)}${rIdx + 1}`;
|
|
154
|
-
if (/^-?(?:0|[1-9]\d*)(?:\.\d+)?$/u.test(val)) {
|
|
155
|
-
return `<c r="${ref}" t="n"><v>${val}</v></c>`;
|
|
156
|
-
}
|
|
157
|
-
return `<c r="${ref}" t="inlineStr"><is><t>${esc(val)}</t></is></c>`;
|
|
158
|
-
})
|
|
159
|
-
.join("");
|
|
160
|
-
return `<row r="${rIdx + 1}">${cells}</row>`;
|
|
161
|
-
})
|
|
162
|
-
.join("");
|
|
163
|
-
return createStoredZipArchive({
|
|
164
|
-
"[Content_Types].xml": syncUtf8Encoder.encode(`<?xml version="1.0" encoding="UTF-8"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/><Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/></Types>`),
|
|
165
|
-
"_rels/.rels": syncUtf8Encoder.encode(`<?xml version="1.0" encoding="UTF-8"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/></Relationships>`),
|
|
166
|
-
"xl/workbook.xml": syncUtf8Encoder.encode(`<?xml version="1.0" encoding="UTF-8"?><workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><sheets><sheet name="${esc(sheetName)}" sheetId="1" r:id="rId1" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"/></sheets></workbook>`),
|
|
167
|
-
"xl/worksheets/sheet1.xml": syncUtf8Encoder.encode(`<?xml version="1.0" encoding="UTF-8"?><worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><sheetData>${sheetRows}</sheetData></worksheet>`),
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
function formatSimpleCsv(rows) {
|
|
171
|
-
if (rows.length === 0)
|
|
172
|
-
return "";
|
|
173
|
-
return (rows
|
|
174
|
-
.map((row) => row
|
|
175
|
-
.map((cell) => cell.includes(",") || cell.includes('"') || cell.includes("\n") || cell.includes("\r")
|
|
176
|
-
? `"${cell.replace(/"/g, '""')}"`
|
|
177
|
-
: cell)
|
|
178
|
-
.join(","))
|
|
179
|
-
.join("\n") + "\n");
|
|
180
|
-
}
|
|
181
|
-
export function evalSyncSsconvert(execute, opArgs, inBytes, readFileSync, writeFileSync) {
|
|
182
|
-
if (!builtInDirectContextExecutors.has(execute) || opArgs.length === 0)
|
|
183
|
-
return undefined;
|
|
184
|
-
try {
|
|
185
|
-
const parsed = parseCommand(opArgs);
|
|
186
|
-
if (parsed.kind === "terminal") {
|
|
187
|
-
if (parsed.exitCode === 0 && !parsed.stderr && parsed.stdout) {
|
|
188
|
-
return parsed.stdout;
|
|
189
|
-
}
|
|
190
|
-
return undefined;
|
|
191
|
-
}
|
|
192
|
-
if (parsed.action !== "convert" ||
|
|
193
|
-
parsed.flags.length > 0 ||
|
|
194
|
-
Object.keys(parsed.arrays).length > 0 ||
|
|
195
|
-
parsed.scalars.clipboard !== undefined ||
|
|
196
|
-
parsed.scalars.resize !== undefined ||
|
|
197
|
-
parsed.scalars["export-range"] !== undefined ||
|
|
198
|
-
parsed.scalars["export-options"] !== undefined ||
|
|
199
|
-
parsed.scalars["import-encoding"] !== undefined ||
|
|
200
|
-
parsed.operands.length !== 2) {
|
|
201
|
-
return undefined;
|
|
202
|
-
}
|
|
203
|
-
const [srcUri, dstUri] = parsed.operands;
|
|
204
|
-
if (srcUri.includes("%") || dstUri.includes("%"))
|
|
205
|
-
return undefined;
|
|
206
|
-
if (srcUri.includes("://") && srcUri !== "fd://0")
|
|
207
|
-
return undefined;
|
|
208
|
-
if (dstUri.includes("://") && dstUri !== "fd://1")
|
|
209
|
-
return undefined;
|
|
210
|
-
const impType = parsed.scalars["import-type"];
|
|
211
|
-
const expType = parsed.scalars["export-type"];
|
|
212
|
-
const lowerSrc = srcUri.toLowerCase();
|
|
213
|
-
const lowerDst = dstUri.toLowerCase();
|
|
214
|
-
let inFmt;
|
|
215
|
-
if (impType === "Gnumeric_stf:stf_csvtab" || (!impType && lowerSrc.endsWith(".csv")))
|
|
216
|
-
inFmt = "csv";
|
|
217
|
-
else if (!impType && lowerSrc.endsWith(".tsv"))
|
|
218
|
-
inFmt = "tsv";
|
|
219
|
-
else if (impType === "Gnumeric_Excel:xlsx" || (!impType && lowerSrc.endsWith(".xlsx")))
|
|
220
|
-
inFmt = "xlsx";
|
|
221
|
-
if (!inFmt)
|
|
222
|
-
return undefined;
|
|
223
|
-
let outFmt;
|
|
224
|
-
if (expType === "Gnumeric_stf:stf_csv" || (!expType && lowerDst.endsWith(".csv")))
|
|
225
|
-
outFmt = "csv";
|
|
226
|
-
else if (expType === "Gnumeric_Excel:xlsx" || expType === "Gnumeric_Excel:xlsx2" || (!expType && lowerDst.endsWith(".xlsx")))
|
|
227
|
-
outFmt = "xlsx";
|
|
228
|
-
if (!outFmt)
|
|
229
|
-
return undefined;
|
|
230
|
-
if (dstUri === "fd://1" && (!expType || outFmt !== "csv"))
|
|
231
|
-
return undefined;
|
|
232
|
-
const srcBytes = srcUri === "fd://0" ? inBytes : readFileSync?.(srcUri);
|
|
233
|
-
if (!srcBytes || srcBytes.byteLength === 0 || srcBytes.byteLength > 131072)
|
|
234
|
-
return undefined;
|
|
235
|
-
let rows;
|
|
236
|
-
if (inFmt === "csv" || inFmt === "tsv") {
|
|
237
|
-
const text = syncUtf8Decoder.decode(srcBytes);
|
|
238
|
-
rows = parseSimpleSeparatedRows(text, inFmt === "tsv" ? "\t" : ",");
|
|
239
|
-
}
|
|
240
|
-
else {
|
|
241
|
-
rows = parseSimpleXlsxRows(srcBytes);
|
|
242
|
-
}
|
|
243
|
-
if (!rows)
|
|
244
|
-
return undefined;
|
|
245
|
-
if (outFmt === "csv") {
|
|
246
|
-
const csvText = formatSimpleCsv(rows);
|
|
247
|
-
if (dstUri === "fd://1")
|
|
248
|
-
return csvText;
|
|
249
|
-
if (!writeFileSync || !writeFileSync(dstUri, syncUtf8Encoder.encode(csvText)))
|
|
250
|
-
return undefined;
|
|
251
|
-
return "";
|
|
252
|
-
}
|
|
253
|
-
const sheetName = srcUri === "fd://0" ? "Sheet1" : (srcUri.split("/").pop() || "Sheet1");
|
|
254
|
-
const xlsxBytes = buildSimpleXlsx(rows, sheetName);
|
|
255
|
-
if (!writeFileSync || !writeFileSync(dstUri, xlsxBytes))
|
|
256
|
-
return undefined;
|
|
257
|
-
return "";
|
|
258
|
-
}
|
|
259
|
-
catch {
|
|
260
|
-
return undefined;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
5
|
+
export const evalSyncSsconvert = createSyncSsconvertEvaluator({
|
|
6
|
+
read: readZipArchiveEntries,
|
|
7
|
+
write: createStoredZipArchive,
|
|
8
|
+
});
|
|
263
9
|
syncCommandEvaluators.evalSyncSsconvert = evalSyncSsconvert;
|
|
264
10
|
//# sourceMappingURL=index.js.map
|
|
@@ -95292,215 +95292,13 @@ __export(ssconvert_exports, {
|
|
|
95292
95292
|
});
|
|
95293
95293
|
init_platform();
|
|
95294
95294
|
__reExport(ssconvert_exports, safe_bash_command_ssconvert_star);
|
|
95295
|
-
import {
|
|
95295
|
+
import { createSyncSsconvertEvaluator } from "../safe-bash-command-ssconvert/index.js";
|
|
95296
95296
|
import { createStoredZipArchive, readZipArchiveEntries as readZipArchiveEntries2 } from "../safe-bash-command-soffice/index.js";
|
|
95297
95297
|
import * as safe_bash_command_ssconvert_star from "../safe-bash-command-ssconvert/index.js";
|
|
95298
|
-
var
|
|
95299
|
-
|
|
95300
|
-
|
|
95301
|
-
|
|
95302
|
-
}
|
|
95303
|
-
function parseSimpleSeparatedRows(text9, sep) {
|
|
95304
|
-
const rows = [];
|
|
95305
|
-
let row = [];
|
|
95306
|
-
let field2 = "";
|
|
95307
|
-
let quoted2 = false;
|
|
95308
|
-
for (let i = 0; i < text9.length; i++) {
|
|
95309
|
-
const ch = text9[i];
|
|
95310
|
-
if (ch === '"') {
|
|
95311
|
-
if (quoted2 && text9[i + 1] === '"') {
|
|
95312
|
-
field2 += '"';
|
|
95313
|
-
i++;
|
|
95314
|
-
} else if (quoted2 || field2.length === 0) {
|
|
95315
|
-
quoted2 = !quoted2;
|
|
95316
|
-
} else {
|
|
95317
|
-
return void 0;
|
|
95318
|
-
}
|
|
95319
|
-
} else if (!quoted2 && ch === sep) {
|
|
95320
|
-
if (field2.startsWith("=") || field2.startsWith("'")) return void 0;
|
|
95321
|
-
row.push(field2);
|
|
95322
|
-
field2 = "";
|
|
95323
|
-
} else if (!quoted2 && (ch === "\r" || ch === "\n")) {
|
|
95324
|
-
if (field2.startsWith("=") || field2.startsWith("'")) return void 0;
|
|
95325
|
-
row.push(field2);
|
|
95326
|
-
rows.push(row);
|
|
95327
|
-
row = [];
|
|
95328
|
-
field2 = "";
|
|
95329
|
-
if (ch === "\r" && text9[i + 1] === "\n") i++;
|
|
95330
|
-
} else {
|
|
95331
|
-
field2 += ch;
|
|
95332
|
-
}
|
|
95333
|
-
}
|
|
95334
|
-
if (quoted2) return void 0;
|
|
95335
|
-
if (field2.length > 0 || row.length > 0) {
|
|
95336
|
-
if (field2.startsWith("=") || field2.startsWith("'")) return void 0;
|
|
95337
|
-
row.push(field2);
|
|
95338
|
-
rows.push(row);
|
|
95339
|
-
}
|
|
95340
|
-
return rows;
|
|
95341
|
-
}
|
|
95342
|
-
function parseSimpleXlsxRows(zipBytes) {
|
|
95343
|
-
const entries = readZipArchiveEntries2(zipBytes);
|
|
95344
|
-
if (entries.has("EncryptionInfo") || entries.has("EncryptedPackage") || entries.has("xl/worksheets/sheet2.xml")) {
|
|
95345
|
-
return void 0;
|
|
95346
|
-
}
|
|
95347
|
-
const sharedStrings = [];
|
|
95348
|
-
const sstBytes = entries.get("xl/sharedStrings.xml");
|
|
95349
|
-
if (sstBytes) {
|
|
95350
|
-
const sstXml = syncUtf8Decoder2.decode(sstBytes);
|
|
95351
|
-
for (const si of sstXml.matchAll(/<si\b[\s\S]*?<\/si>/g)) {
|
|
95352
|
-
const parts = [...si[0].matchAll(/<t(?:\s[^>]*)?>([\s\S]*?)<\/t>/g)].map(
|
|
95353
|
-
(t) => unescapeXml(t[1] ?? "")
|
|
95354
|
-
);
|
|
95355
|
-
sharedStrings.push(parts.join(""));
|
|
95356
|
-
}
|
|
95357
|
-
}
|
|
95358
|
-
const sheetBytes = entries.get("xl/worksheets/sheet1.xml");
|
|
95359
|
-
if (!sheetBytes) return void 0;
|
|
95360
|
-
const sheetXml = syncUtf8Decoder2.decode(sheetBytes);
|
|
95361
|
-
if (/<f(?:\s|>)/u.test(sheetXml)) return void 0;
|
|
95362
|
-
const rows = [];
|
|
95363
|
-
for (const rowMatch of sheetXml.matchAll(/<row\b([^>]*)>[\s\S]*?<\/row>/g)) {
|
|
95364
|
-
const rowRef = /\br="(\d+)"/.exec(rowMatch[1] ?? "");
|
|
95365
|
-
if (!rowRef || Number(rowRef[1]) !== rows.length + 1) return void 0;
|
|
95366
|
-
const rowCells = [];
|
|
95367
|
-
for (const cellMatch of rowMatch[0].matchAll(/<c\b([^>]*?)(?:\/>|>([\s\S]*?)<\/c>)/g)) {
|
|
95368
|
-
const attrs = cellMatch[1] ?? "";
|
|
95369
|
-
const body = cellMatch[2] ?? "";
|
|
95370
|
-
const refMatch = /\br="([A-Z]+)(\d+)"/i.exec(attrs);
|
|
95371
|
-
if (!refMatch || Number(refMatch[2]) !== rows.length + 1) return void 0;
|
|
95372
|
-
if (refMatch?.[1]) {
|
|
95373
|
-
let targetCol = 0;
|
|
95374
|
-
for (const ch of refMatch[1].toUpperCase()) {
|
|
95375
|
-
targetCol = targetCol * 26 + (ch.charCodeAt(0) - 64);
|
|
95376
|
-
}
|
|
95377
|
-
targetCol -= 1;
|
|
95378
|
-
if (targetCol !== rowCells.length) return void 0;
|
|
95379
|
-
}
|
|
95380
|
-
if (cellMatch[2] === void 0) {
|
|
95381
|
-
rowCells.push("");
|
|
95382
|
-
continue;
|
|
95383
|
-
}
|
|
95384
|
-
const typeMatch = /\bt="([^"]+)"/.exec(attrs);
|
|
95385
|
-
const cellType = typeMatch?.[1] ?? "n";
|
|
95386
|
-
if (cellType === "inlineStr") {
|
|
95387
|
-
const tVal = /<t(?:\s[^>]*)?>([\s\S]*?)<\/t>/.exec(body);
|
|
95388
|
-
rowCells.push(unescapeXml(tVal?.[1] ?? ""));
|
|
95389
|
-
} else {
|
|
95390
|
-
const vVal = /<v>([\s\S]*?)<\/v>/.exec(body);
|
|
95391
|
-
const raw = unescapeXml(vVal?.[1] ?? "");
|
|
95392
|
-
if (cellType === "s") {
|
|
95393
|
-
const idx = Number.parseInt(raw, 10);
|
|
95394
|
-
rowCells.push(sharedStrings[idx] ?? "");
|
|
95395
|
-
} else {
|
|
95396
|
-
rowCells.push(raw);
|
|
95397
|
-
}
|
|
95398
|
-
}
|
|
95399
|
-
}
|
|
95400
|
-
rows.push(rowCells);
|
|
95401
|
-
}
|
|
95402
|
-
return rows;
|
|
95403
|
-
}
|
|
95404
|
-
function buildSimpleXlsx(rows, sheetName = "Sheet1") {
|
|
95405
|
-
const esc = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
95406
|
-
const colName = (idx) => {
|
|
95407
|
-
let n = idx + 1;
|
|
95408
|
-
let out = "";
|
|
95409
|
-
while (n > 0) {
|
|
95410
|
-
const rem = (n - 1) % 26;
|
|
95411
|
-
out = String.fromCharCode(65 + rem) + out;
|
|
95412
|
-
n = Math.floor((n - 1) / 26);
|
|
95413
|
-
}
|
|
95414
|
-
return out;
|
|
95415
|
-
};
|
|
95416
|
-
const sheetRows = rows.map((row, rIdx) => {
|
|
95417
|
-
const cells = row.map((val, cIdx) => {
|
|
95418
|
-
const ref = `${colName(cIdx)}${rIdx + 1}`;
|
|
95419
|
-
if (/^-?(?:0|[1-9]\d*)(?:\.\d+)?$/u.test(val)) {
|
|
95420
|
-
return `<c r="${ref}" t="n"><v>${val}</v></c>`;
|
|
95421
|
-
}
|
|
95422
|
-
return `<c r="${ref}" t="inlineStr"><is><t>${esc(val)}</t></is></c>`;
|
|
95423
|
-
}).join("");
|
|
95424
|
-
return `<row r="${rIdx + 1}">${cells}</row>`;
|
|
95425
|
-
}).join("");
|
|
95426
|
-
return createStoredZipArchive({
|
|
95427
|
-
"[Content_Types].xml": syncUtf8Encoder.encode(
|
|
95428
|
-
`<?xml version="1.0" encoding="UTF-8"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/><Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/></Types>`
|
|
95429
|
-
),
|
|
95430
|
-
"_rels/.rels": syncUtf8Encoder.encode(
|
|
95431
|
-
`<?xml version="1.0" encoding="UTF-8"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/></Relationships>`
|
|
95432
|
-
),
|
|
95433
|
-
"xl/workbook.xml": syncUtf8Encoder.encode(
|
|
95434
|
-
`<?xml version="1.0" encoding="UTF-8"?><workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><sheets><sheet name="${esc(sheetName)}" sheetId="1" r:id="rId1" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"/></sheets></workbook>`
|
|
95435
|
-
),
|
|
95436
|
-
"xl/worksheets/sheet1.xml": syncUtf8Encoder.encode(
|
|
95437
|
-
`<?xml version="1.0" encoding="UTF-8"?><worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><sheetData>${sheetRows}</sheetData></worksheet>`
|
|
95438
|
-
)
|
|
95439
|
-
});
|
|
95440
|
-
}
|
|
95441
|
-
function formatSimpleCsv(rows) {
|
|
95442
|
-
if (rows.length === 0) return "";
|
|
95443
|
-
return rows.map(
|
|
95444
|
-
(row) => row.map(
|
|
95445
|
-
(cell) => cell.includes(",") || cell.includes('"') || cell.includes("\n") || cell.includes("\r") ? `"${cell.replace(/"/g, '""')}"` : cell
|
|
95446
|
-
).join(",")
|
|
95447
|
-
).join("\n") + "\n";
|
|
95448
|
-
}
|
|
95449
|
-
function evalSyncSsconvert(execute2, opArgs, inBytes, readFileSync, writeFileSync) {
|
|
95450
|
-
if (!internal_exports.builtInDirectContextExecutors.has(execute2) || opArgs.length === 0) return void 0;
|
|
95451
|
-
try {
|
|
95452
|
-
const parsed = parseCommand2(opArgs);
|
|
95453
|
-
if (parsed.kind === "terminal") {
|
|
95454
|
-
if (parsed.exitCode === 0 && !parsed.stderr && parsed.stdout) {
|
|
95455
|
-
return parsed.stdout;
|
|
95456
|
-
}
|
|
95457
|
-
return void 0;
|
|
95458
|
-
}
|
|
95459
|
-
if (parsed.action !== "convert" || parsed.flags.length > 0 || Object.keys(parsed.arrays).length > 0 || parsed.scalars.clipboard !== void 0 || parsed.scalars.resize !== void 0 || parsed.scalars["export-range"] !== void 0 || parsed.scalars["export-options"] !== void 0 || parsed.scalars["import-encoding"] !== void 0 || parsed.operands.length !== 2) {
|
|
95460
|
-
return void 0;
|
|
95461
|
-
}
|
|
95462
|
-
const [srcUri, dstUri] = parsed.operands;
|
|
95463
|
-
if (srcUri.includes("%") || dstUri.includes("%")) return void 0;
|
|
95464
|
-
if (srcUri.includes("://") && srcUri !== "fd://0") return void 0;
|
|
95465
|
-
if (dstUri.includes("://") && dstUri !== "fd://1") return void 0;
|
|
95466
|
-
const impType = parsed.scalars["import-type"];
|
|
95467
|
-
const expType = parsed.scalars["export-type"];
|
|
95468
|
-
const lowerSrc = srcUri.toLowerCase();
|
|
95469
|
-
const lowerDst = dstUri.toLowerCase();
|
|
95470
|
-
let inFmt;
|
|
95471
|
-
if (impType === "Gnumeric_stf:stf_csvtab" || !impType && lowerSrc.endsWith(".csv")) inFmt = "csv";
|
|
95472
|
-
else if (!impType && lowerSrc.endsWith(".tsv")) inFmt = "tsv";
|
|
95473
|
-
else if (impType === "Gnumeric_Excel:xlsx" || !impType && lowerSrc.endsWith(".xlsx")) inFmt = "xlsx";
|
|
95474
|
-
if (!inFmt) return void 0;
|
|
95475
|
-
let outFmt;
|
|
95476
|
-
if (expType === "Gnumeric_stf:stf_csv" || !expType && lowerDst.endsWith(".csv")) outFmt = "csv";
|
|
95477
|
-
else if (expType === "Gnumeric_Excel:xlsx" || expType === "Gnumeric_Excel:xlsx2" || !expType && lowerDst.endsWith(".xlsx")) outFmt = "xlsx";
|
|
95478
|
-
if (!outFmt) return void 0;
|
|
95479
|
-
if (dstUri === "fd://1" && (!expType || outFmt !== "csv")) return void 0;
|
|
95480
|
-
const srcBytes = srcUri === "fd://0" ? inBytes : readFileSync?.(srcUri);
|
|
95481
|
-
if (!srcBytes || srcBytes.byteLength === 0 || srcBytes.byteLength > 131072) return void 0;
|
|
95482
|
-
let rows;
|
|
95483
|
-
if (inFmt === "csv" || inFmt === "tsv") {
|
|
95484
|
-
const text9 = syncUtf8Decoder2.decode(srcBytes);
|
|
95485
|
-
rows = parseSimpleSeparatedRows(text9, inFmt === "tsv" ? " " : ",");
|
|
95486
|
-
} else {
|
|
95487
|
-
rows = parseSimpleXlsxRows(srcBytes);
|
|
95488
|
-
}
|
|
95489
|
-
if (!rows) return void 0;
|
|
95490
|
-
if (outFmt === "csv") {
|
|
95491
|
-
const csvText = formatSimpleCsv(rows);
|
|
95492
|
-
if (dstUri === "fd://1") return csvText;
|
|
95493
|
-
if (!writeFileSync || !writeFileSync(dstUri, syncUtf8Encoder.encode(csvText))) return void 0;
|
|
95494
|
-
return "";
|
|
95495
|
-
}
|
|
95496
|
-
const sheetName = srcUri === "fd://0" ? "Sheet1" : srcUri.split("/").pop() || "Sheet1";
|
|
95497
|
-
const xlsxBytes = buildSimpleXlsx(rows, sheetName);
|
|
95498
|
-
if (!writeFileSync || !writeFileSync(dstUri, xlsxBytes)) return void 0;
|
|
95499
|
-
return "";
|
|
95500
|
-
} catch {
|
|
95501
|
-
return void 0;
|
|
95502
|
-
}
|
|
95503
|
-
}
|
|
95298
|
+
var evalSyncSsconvert = createSyncSsconvertEvaluator({
|
|
95299
|
+
read: readZipArchiveEntries2,
|
|
95300
|
+
write: createStoredZipArchive
|
|
95301
|
+
});
|
|
95504
95302
|
internal_exports.syncCommandEvaluators.evalSyncSsconvert = evalSyncSsconvert;
|
|
95505
95303
|
|
|
95506
95304
|
// packages/safe-bash/src/fs/webdav/index.ts
|