palette-docs 0.1.0 → 0.1.1
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 +1 -1
- package/src/index.js +1 -1
- package/src/read.js +2 -2
- package/src/write.js +6 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "palette-docs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Palette Docs: lets Palette Code read HWP/HWPX/DOCX/XLSX/PPTX/PDF/ZIP and images, and create DOCX/HWPX/XLSX/PPTX (PDF and legacy formats via LibreOffice). MCP server + CLI.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"dependencies": {
|
package/src/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { readDocument, readDocuments, formatsTable, MAX_ARCHIVE_FILES } from "./
|
|
|
7
7
|
import { normalizeImage, extractImages } from "./image.js"
|
|
8
8
|
import { createDocument, convertDocument, NATIVE, VIA_LO, DEFAULT_FONT } from "./write.js"
|
|
9
9
|
|
|
10
|
-
const VERSION = "0.1.
|
|
10
|
+
const VERSION = "0.1.1"
|
|
11
11
|
|
|
12
12
|
async function mcp() {
|
|
13
13
|
const { McpServer } = await import("@modelcontextprotocol/sdk/server/mcp.js")
|
package/src/read.js
CHANGED
|
@@ -24,7 +24,7 @@ export function soffice() {
|
|
|
24
24
|
for (const c of candidates) if (fs.existsSync(c)) return c
|
|
25
25
|
for (const name of ["soffice", "libreoffice"]) {
|
|
26
26
|
try {
|
|
27
|
-
const found = execFileSync(process.platform === "win32" ? "where" : "which", [name], { stdio: ["ignore", "pipe", "ignore"] }).toString().trim().split("\n")[0]
|
|
27
|
+
const found = execFileSync(process.platform === "win32" ? "where" : "which", [name], { stdio: ["ignore", "pipe", "ignore"], windowsHide: true }).toString().trim().split("\n")[0]
|
|
28
28
|
if (found) return found
|
|
29
29
|
} catch {}
|
|
30
30
|
}
|
|
@@ -37,7 +37,7 @@ export function sofficeConvert(src, toExt, outDir) {
|
|
|
37
37
|
if (!bin) throw new Error(`LibreOffice is needed to handle .${extOf(src)} -> .${toExt} (install from libreoffice.org or brew install --cask libreoffice)`)
|
|
38
38
|
fs.mkdirSync(outDir, { recursive: true })
|
|
39
39
|
const profile = path.join(os.tmpdir(), "palette-docs-lo")
|
|
40
|
-
execFileSync(bin, [`-env:UserInstallation=file://${profile}`, "--headless", "--norestore", "--convert-to", toExt, "--outdir", outDir, src], { stdio: ["ignore", "pipe", "pipe"], timeout: 180_000 })
|
|
40
|
+
execFileSync(bin, [`-env:UserInstallation=file://${profile}`, "--headless", "--norestore", "--convert-to", toExt, "--outdir", outDir, src], { stdio: ["ignore", "pipe", "pipe"], timeout: 180_000, windowsHide: true })
|
|
41
41
|
const out = path.join(outDir, path.basename(src, path.extname(src)) + "." + toExt.split(":")[0])
|
|
42
42
|
if (!fs.existsSync(out)) throw new Error(`LibreOffice did not produce ${out}`)
|
|
43
43
|
return out
|
package/src/write.js
CHANGED
|
@@ -307,9 +307,12 @@ function htmlOf(blocks, title, font) {
|
|
|
307
307
|
/** Convert an existing file to another format: native read + create for text-like targets, LibreOffice otherwise. */
|
|
308
308
|
export async function convertDocument(src, to, outDir) {
|
|
309
309
|
const { readDocument } = await import("./read.js")
|
|
310
|
-
|
|
311
|
-
const
|
|
312
|
-
const
|
|
310
|
+
// `to` is a target extension ("pdf") or an output path ("reports/out.pdf"): a dot or a separator means path.
|
|
311
|
+
const asPath = /[\\/]/.test(String(to)) || /\.[A-Za-z0-9]+$/.test(String(to))
|
|
312
|
+
const fmt = (asPath ? path.extname(String(to)).slice(1) : String(to)).toLowerCase()
|
|
313
|
+
const dir = asPath ? path.dirname(path.resolve(String(to))) : outDir || path.dirname(path.resolve(src))
|
|
314
|
+
const out = asPath ? path.resolve(String(to)) : path.join(dir, path.basename(src, path.extname(src)) + "." + fmt)
|
|
315
|
+
fs.mkdirSync(dir, { recursive: true })
|
|
313
316
|
const ext = path.extname(src).slice(1).toLowerCase()
|
|
314
317
|
const loDirect = !["hwp", "hwpx"].includes(ext) && (VIA_LO[fmt] || ["docx", "xlsx", "pptx", "html"].includes(fmt))
|
|
315
318
|
if (loDirect) {
|