@vutex/vutex 0.0.1 → 0.0.3

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.
@@ -9,7 +9,7 @@
9
9
  "cli.cmd.package.install": "Resolve and install resource packages into the project cache",
10
10
  "cli.cmd.package.update": "Refresh the resource package lockfile",
11
11
  "cli.cmd.package.doctor": "Check manifest, lockfile, and package cache health",
12
- "cli.opt.output": "Output file path, or format id when writing to stdout",
12
+ "cli.opt.output": "Output format id: svg, html, snapshot, or pdf",
13
13
  "cli.opt.profile": "Named language profile from vutex.toml",
14
14
  "cli.opt.input-format": "Override input format id",
15
15
  "cli.opt.json": "Emit machine-readable JSON on stdout",
@@ -1 +1,4 @@
1
- ["en-US"]
1
+ {
2
+ "defaultLocale": "en-US",
3
+ "locales": [{ "id": "en-US", "label": "English", "direction": "ltr" }]
4
+ }
package/package.json CHANGED
@@ -30,11 +30,11 @@
30
30
  "license": "MPL-2.0",
31
31
  "name": "@vutex/vutex",
32
32
  "optionalDependencies": {
33
- "@vutex/vutex-darwin-arm64": "0.0.1",
34
- "@vutex/vutex-darwin-x64": "0.0.1",
35
- "@vutex/vutex-linux-arm64": "0.0.1",
36
- "@vutex/vutex-linux-x64": "0.0.1",
37
- "@vutex/vutex-win32-x64": "0.0.1"
33
+ "@vutex/vutex-darwin-arm64": "0.0.3",
34
+ "@vutex/vutex-darwin-x64": "0.0.3",
35
+ "@vutex/vutex-linux-arm64": "0.0.3",
36
+ "@vutex/vutex-linux-x64": "0.0.3",
37
+ "@vutex/vutex-win32-x64": "0.0.3"
38
38
  },
39
39
  "publishConfig": {
40
40
  "access": "public"
@@ -45,9 +45,9 @@
45
45
  "url": "git+https://github.com/notedge/VuTeX.git"
46
46
  },
47
47
  "scripts": {
48
- "test": "tsx --test tests/package-manager.test.ts",
48
+ "test": "tsx --test tests/package-manager.test.ts tests/render-runtime.test.ts",
49
49
  "typecheck": "tsc --noEmit"
50
50
  },
51
51
  "type": "module",
52
- "version": "0.0.1"
52
+ "version": "0.0.3"
53
53
  }
@@ -1,12 +1,34 @@
1
+ import { writeFile } from "node:fs/promises";
2
+ import { basename, dirname, extname, join, resolve } from "node:path";
3
+
1
4
  import type { Cli, ParsedOptions } from "@vmz/commander";
2
5
 
6
+ import type { RenderDocumentResult } from "../../types.js";
3
7
  import { createVuTeXRuntime } from "../context.js";
4
8
  import { emitJson, presentDiagnostics } from "../diagnostics.js";
5
9
  import { ExitCode } from "../exit-codes.js";
6
10
 
11
+ /**
12
+ * Write PDF bytes beside the input file and build the CLI payload.
13
+ *
14
+ * The text mode prints `outputPath`; the JSON payload carries the render
15
+ * result without the binary body plus the absolute `outputPath`.
16
+ */
17
+ export async function writePdfOutput(
18
+ inputPath: string,
19
+ bytes: Uint8Array,
20
+ result: RenderDocumentResult,
21
+ ): Promise<{ outputPath: string; payload: Record<string, unknown> }> {
22
+ const source = resolve(inputPath);
23
+ const outputPath = join(dirname(source), `${basename(source, extname(source))}.pdf`);
24
+ await writeFile(outputPath, bytes);
25
+ const { pdf: _bytes, ...rest } = result;
26
+ return { outputPath, payload: { ...rest, outputPath } };
27
+ }
28
+
7
29
  export function registerRenderCommand(cli: Cli): void {
8
30
  cli.command("render", "cli.cmd.render")
9
- .option("-o, --output <file>", "cli.opt.output")
31
+ .option("-o, --output <format>", "cli.opt.output")
10
32
  .option("--profile <name>", "cli.opt.profile")
11
33
  .option("--input <format>", "cli.opt.input-format")
12
34
  .option("--json", "cli.opt.json")
@@ -23,10 +45,18 @@ export function registerRenderCommand(cli: Cli): void {
23
45
  input: typeof options.input === "string" ? options.input : undefined,
24
46
  });
25
47
 
48
+ const pdf = result.outputFormat === "pdf" ? result.pdf : undefined;
49
+ const written = pdf ? await writePdfOutput(inputPath, pdf, result) : null;
50
+
26
51
  if (options.json === true) {
27
- emitJson(result);
28
- } else if (result.svg) {
29
- console.log(result.svg);
52
+ emitJson(written ? written.payload : result);
53
+ } else if (written) {
54
+ console.log(written.outputPath);
55
+ } else {
56
+ const body = result.outputFormat === "svg"
57
+ ? result.svg ?? result.html
58
+ : result.html ?? result.svg;
59
+ console.log(body ?? result.reportJson);
30
60
  }
31
61
 
32
62
  if (result.diagnostics.length > 0) {
package/src/index.ts CHANGED
@@ -4,6 +4,7 @@ import type { CreateVuTeXOptions, VuTeXRuntime } from "./types.js";
4
4
 
5
5
  export type {
6
6
  CreateVuTeXOptions,
7
+ DocumentOutputFormat,
7
8
  FormulaDiagnostic,
8
9
  FormulaMetrics,
9
10
  FormulaRender,
package/src/node/load.ts CHANGED
@@ -17,6 +17,8 @@ type NativeBinding = {
17
17
  exitCode: number;
18
18
  outputFormat: string;
19
19
  svg?: string;
20
+ html?: string;
21
+ pdf?: Uint8Array;
20
22
  reportJson: string;
21
23
  };
22
24
  };
package/src/runtime.ts CHANGED
@@ -24,6 +24,14 @@ function decodeFormulaRender(raw: string): FormulaRender {
24
24
  return JSON.parse(raw) as FormulaRender;
25
25
  }
26
26
 
27
+ /**
28
+ * Keep unknown format ids intact so the native side can report them.
29
+ * Only a missing value falls back to the default `svg`.
30
+ */
31
+ function normalizeOutputFormat(value: string | undefined): string {
32
+ return typeof value === "string" && value.length > 0 ? value : "svg";
33
+ }
34
+
27
35
  function diagnosticsFromReport(reportJson: string): VuTeXDiagnostic[] {
28
36
  try {
29
37
  const report = JSON.parse(reportJson) as {
@@ -47,7 +55,7 @@ export function createVuTeXRuntime(
47
55
  async render(inputPath, renderOptions = {}): Promise<RenderDocumentResult> {
48
56
  const manifest = await readManifest(projectRoot);
49
57
  const payload = JSON.stringify({
50
- output: renderOptions.output ?? manifest?.document?.output ?? "svg",
58
+ output: normalizeOutputFormat(renderOptions.output ?? manifest?.document?.output),
51
59
  profile: renderOptions.profile ?? manifest?.profile?.name,
52
60
  input: renderOptions.input ?? manifest?.document?.input,
53
61
  });
@@ -56,6 +64,8 @@ export function createVuTeXRuntime(
56
64
  exitCode: response.exitCode,
57
65
  outputFormat: response.outputFormat,
58
66
  svg: response.svg,
67
+ html: response.html,
68
+ pdf: response.pdf,
59
69
  reportJson: response.reportJson,
60
70
  diagnostics: diagnosticsFromReport(response.reportJson),
61
71
  };
package/src/types.ts CHANGED
@@ -8,8 +8,10 @@ export type CreateVuTeXOptions = {
8
8
  backend?: VuTeXBackend;
9
9
  };
10
10
 
11
+ export type DocumentOutputFormat = "svg" | "html" | "snapshot" | "pdf";
12
+
11
13
  export type RenderDocumentOptions = {
12
- output?: string;
14
+ output?: DocumentOutputFormat | string;
13
15
  profile?: string;
14
16
  input?: string;
15
17
  };
@@ -58,6 +60,8 @@ export type RenderDocumentResult = {
58
60
  exitCode: number;
59
61
  outputFormat: string;
60
62
  svg?: string;
63
+ html?: string;
64
+ pdf?: Uint8Array;
61
65
  reportJson: string;
62
66
  diagnostics: VuTeXDiagnostic[];
63
67
  };
@@ -100,6 +104,8 @@ export type VuTeXBindings = {
100
104
  exitCode: number;
101
105
  outputFormat: string;
102
106
  svg?: string;
107
+ html?: string;
108
+ pdf?: Uint8Array;
103
109
  reportJson: string;
104
110
  };
105
111
  };