@vutex/vutex 0.0.0 → 0.0.2
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/bin/vutex.mjs +11 -11
- package/locales/en-US/cli.json +18 -18
- package/locales/locales.json +1 -1
- package/package.json +11 -6
- package/readme.md +18 -18
- package/src/cli/cli.ts +21 -21
- package/src/cli/commands/inspect.ts +33 -33
- package/src/cli/commands/package.ts +99 -99
- package/src/cli/commands/render.ts +38 -38
- package/src/cli/context.ts +27 -27
- package/src/cli/diagnostics.ts +23 -23
- package/src/cli/exit-codes.ts +5 -5
- package/src/cli/main.ts +5 -5
- package/src/index.ts +36 -36
- package/src/node/index.ts +1 -1
- package/src/node/load.ts +50 -50
- package/src/packages/lockfile.ts +35 -35
- package/src/packages/manager.ts +119 -119
- package/src/packages/manifest.ts +28 -28
- package/src/runtime.ts +87 -87
- package/src/types.ts +121 -121
package/src/runtime.ts
CHANGED
|
@@ -1,87 +1,87 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
CreateVuTeXOptions,
|
|
3
|
-
FormulaRender,
|
|
4
|
-
FormulaRenderOptions,
|
|
5
|
-
InspectDocumentOptions,
|
|
6
|
-
InspectDocumentResult,
|
|
7
|
-
RenderDocumentOptions,
|
|
8
|
-
RenderDocumentResult,
|
|
9
|
-
VuTeXBindings,
|
|
10
|
-
VuTeXDiagnostic,
|
|
11
|
-
VuTeXRuntime,
|
|
12
|
-
} from "./types.js";
|
|
13
|
-
import { PackageManager } from "./packages/manager.js";
|
|
14
|
-
import { readManifest } from "./packages/manifest.js";
|
|
15
|
-
|
|
16
|
-
function encodeFormulaOptions(options?: FormulaRenderOptions): string | undefined {
|
|
17
|
-
if (!options) {
|
|
18
|
-
return undefined;
|
|
19
|
-
}
|
|
20
|
-
return JSON.stringify({ displayMode: options.displayMode ?? "inline" });
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function decodeFormulaRender(raw: string): FormulaRender {
|
|
24
|
-
return JSON.parse(raw) as FormulaRender;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function diagnosticsFromReport(reportJson: string): VuTeXDiagnostic[] {
|
|
28
|
-
try {
|
|
29
|
-
const report = JSON.parse(reportJson) as {
|
|
30
|
-
diagnostics?: VuTeXDiagnostic[];
|
|
31
|
-
};
|
|
32
|
-
return report.diagnostics ?? [];
|
|
33
|
-
} catch {
|
|
34
|
-
return [];
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function createVuTeXRuntime(
|
|
39
|
-
bindings: VuTeXBindings,
|
|
40
|
-
options: CreateVuTeXOptions = {},
|
|
41
|
-
): VuTeXRuntime {
|
|
42
|
-
const projectRoot = options.projectRoot ?? process.cwd();
|
|
43
|
-
const packages = new PackageManager(projectRoot);
|
|
44
|
-
|
|
45
|
-
return {
|
|
46
|
-
version: () => bindings.vutexVersion(),
|
|
47
|
-
async render(inputPath, renderOptions = {}): Promise<RenderDocumentResult> {
|
|
48
|
-
const manifest = await readManifest(projectRoot);
|
|
49
|
-
const payload = JSON.stringify({
|
|
50
|
-
output: renderOptions.output ?? manifest?.document?.output ?? "svg",
|
|
51
|
-
profile: renderOptions.profile ?? manifest?.profile?.name,
|
|
52
|
-
input: renderOptions.input ?? manifest?.document?.input,
|
|
53
|
-
});
|
|
54
|
-
const response = bindings.renderDocument(inputPath, payload);
|
|
55
|
-
return {
|
|
56
|
-
exitCode: response.exitCode,
|
|
57
|
-
outputFormat: response.outputFormat,
|
|
58
|
-
svg: response.svg,
|
|
59
|
-
reportJson: response.reportJson,
|
|
60
|
-
diagnostics: diagnosticsFromReport(response.reportJson),
|
|
61
|
-
};
|
|
62
|
-
},
|
|
63
|
-
async inspect(inputPath, _options: InspectDocumentOptions = {}): Promise<InspectDocumentResult> {
|
|
64
|
-
const response = bindings.inspectDocument(inputPath);
|
|
65
|
-
return {
|
|
66
|
-
inputFormat: response.inputFormat,
|
|
67
|
-
path: response.path,
|
|
68
|
-
reportJson: response.reportJson,
|
|
69
|
-
diagnostics: diagnosticsFromReport(response.reportJson),
|
|
70
|
-
};
|
|
71
|
-
},
|
|
72
|
-
measureFormula(source, options) {
|
|
73
|
-
return decodeFormulaRender(bindings.measureFormula(source, encodeFormulaOptions(options)));
|
|
74
|
-
},
|
|
75
|
-
renderFormula(source, options) {
|
|
76
|
-
return decodeFormulaRender(bindings.renderFormula(source, encodeFormulaOptions(options)));
|
|
77
|
-
},
|
|
78
|
-
packages: {
|
|
79
|
-
list: () => packages.list(),
|
|
80
|
-
add: (name, opts) => packages.add(name, opts),
|
|
81
|
-
remove: (name) => packages.remove(name),
|
|
82
|
-
install: (opts) => packages.install(opts),
|
|
83
|
-
update: () => packages.update(),
|
|
84
|
-
doctor: () => packages.doctor(),
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
}
|
|
1
|
+
import type {
|
|
2
|
+
CreateVuTeXOptions,
|
|
3
|
+
FormulaRender,
|
|
4
|
+
FormulaRenderOptions,
|
|
5
|
+
InspectDocumentOptions,
|
|
6
|
+
InspectDocumentResult,
|
|
7
|
+
RenderDocumentOptions,
|
|
8
|
+
RenderDocumentResult,
|
|
9
|
+
VuTeXBindings,
|
|
10
|
+
VuTeXDiagnostic,
|
|
11
|
+
VuTeXRuntime,
|
|
12
|
+
} from "./types.js";
|
|
13
|
+
import { PackageManager } from "./packages/manager.js";
|
|
14
|
+
import { readManifest } from "./packages/manifest.js";
|
|
15
|
+
|
|
16
|
+
function encodeFormulaOptions(options?: FormulaRenderOptions): string | undefined {
|
|
17
|
+
if (!options) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
return JSON.stringify({ displayMode: options.displayMode ?? "inline" });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function decodeFormulaRender(raw: string): FormulaRender {
|
|
24
|
+
return JSON.parse(raw) as FormulaRender;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function diagnosticsFromReport(reportJson: string): VuTeXDiagnostic[] {
|
|
28
|
+
try {
|
|
29
|
+
const report = JSON.parse(reportJson) as {
|
|
30
|
+
diagnostics?: VuTeXDiagnostic[];
|
|
31
|
+
};
|
|
32
|
+
return report.diagnostics ?? [];
|
|
33
|
+
} catch {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function createVuTeXRuntime(
|
|
39
|
+
bindings: VuTeXBindings,
|
|
40
|
+
options: CreateVuTeXOptions = {},
|
|
41
|
+
): VuTeXRuntime {
|
|
42
|
+
const projectRoot = options.projectRoot ?? process.cwd();
|
|
43
|
+
const packages = new PackageManager(projectRoot);
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
version: () => bindings.vutexVersion(),
|
|
47
|
+
async render(inputPath, renderOptions = {}): Promise<RenderDocumentResult> {
|
|
48
|
+
const manifest = await readManifest(projectRoot);
|
|
49
|
+
const payload = JSON.stringify({
|
|
50
|
+
output: renderOptions.output ?? manifest?.document?.output ?? "svg",
|
|
51
|
+
profile: renderOptions.profile ?? manifest?.profile?.name,
|
|
52
|
+
input: renderOptions.input ?? manifest?.document?.input,
|
|
53
|
+
});
|
|
54
|
+
const response = bindings.renderDocument(inputPath, payload);
|
|
55
|
+
return {
|
|
56
|
+
exitCode: response.exitCode,
|
|
57
|
+
outputFormat: response.outputFormat,
|
|
58
|
+
svg: response.svg,
|
|
59
|
+
reportJson: response.reportJson,
|
|
60
|
+
diagnostics: diagnosticsFromReport(response.reportJson),
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
async inspect(inputPath, _options: InspectDocumentOptions = {}): Promise<InspectDocumentResult> {
|
|
64
|
+
const response = bindings.inspectDocument(inputPath);
|
|
65
|
+
return {
|
|
66
|
+
inputFormat: response.inputFormat,
|
|
67
|
+
path: response.path,
|
|
68
|
+
reportJson: response.reportJson,
|
|
69
|
+
diagnostics: diagnosticsFromReport(response.reportJson),
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
measureFormula(source, options) {
|
|
73
|
+
return decodeFormulaRender(bindings.measureFormula(source, encodeFormulaOptions(options)));
|
|
74
|
+
},
|
|
75
|
+
renderFormula(source, options) {
|
|
76
|
+
return decodeFormulaRender(bindings.renderFormula(source, encodeFormulaOptions(options)));
|
|
77
|
+
},
|
|
78
|
+
packages: {
|
|
79
|
+
list: () => packages.list(),
|
|
80
|
+
add: (name, opts) => packages.add(name, opts),
|
|
81
|
+
remove: (name) => packages.remove(name),
|
|
82
|
+
install: (opts) => packages.install(opts),
|
|
83
|
+
update: () => packages.update(),
|
|
84
|
+
doctor: () => packages.doctor(),
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,121 +1,121 @@
|
|
|
1
|
-
export type VuTeXHost = "node" | "browser" | "wasm";
|
|
2
|
-
|
|
3
|
-
export type VuTeXBackend = "auto" | "native" | "wasm";
|
|
4
|
-
|
|
5
|
-
export type CreateVuTeXOptions = {
|
|
6
|
-
projectRoot?: string;
|
|
7
|
-
host?: VuTeXHost;
|
|
8
|
-
backend?: VuTeXBackend;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export type RenderDocumentOptions = {
|
|
12
|
-
output?: string;
|
|
13
|
-
profile?: string;
|
|
14
|
-
input?: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export type InspectDocumentOptions = {
|
|
18
|
-
input?: string;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export type FormulaRenderOptions = {
|
|
22
|
-
displayMode?: "inline" | "block";
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export type FormulaDiagnostic = {
|
|
26
|
-
code: string;
|
|
27
|
-
severity: "info" | "warning" | "error";
|
|
28
|
-
message: string;
|
|
29
|
-
start?: number;
|
|
30
|
-
end?: number;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export type FormulaMetrics = {
|
|
34
|
-
width: number;
|
|
35
|
-
height: number;
|
|
36
|
-
depth: number;
|
|
37
|
-
baseline: number;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export type FormulaRender = {
|
|
41
|
-
metrics: FormulaMetrics;
|
|
42
|
-
svg: string;
|
|
43
|
-
mathml?: string;
|
|
44
|
-
diagnostics: FormulaDiagnostic[];
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export type VuTeXDiagnostic = {
|
|
48
|
-
code: string;
|
|
49
|
-
severity: "info" | "warning" | "error";
|
|
50
|
-
message: string;
|
|
51
|
-
stage?: string;
|
|
52
|
-
path?: string;
|
|
53
|
-
args?: Record<string, unknown>;
|
|
54
|
-
cause?: string;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
export type RenderDocumentResult = {
|
|
58
|
-
exitCode: number;
|
|
59
|
-
outputFormat: string;
|
|
60
|
-
svg?: string;
|
|
61
|
-
reportJson: string;
|
|
62
|
-
diagnostics: VuTeXDiagnostic[];
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export type InspectDocumentResult = {
|
|
66
|
-
inputFormat: string;
|
|
67
|
-
path: string;
|
|
68
|
-
reportJson: string;
|
|
69
|
-
diagnostics: VuTeXDiagnostic[];
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
export type PackageInstallOptions = {
|
|
73
|
-
name?: string;
|
|
74
|
-
version?: string;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
export type PackageRecord = {
|
|
78
|
-
name: string;
|
|
79
|
-
version: string;
|
|
80
|
-
source: string;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
export type PackageDoctorReport = {
|
|
84
|
-
ok: boolean;
|
|
85
|
-
checks: Array<{ id: string; ok: boolean; message: string }>;
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
export type VuTeXBindings = {
|
|
89
|
-
vutexVersion: () => string;
|
|
90
|
-
measureFormula: (source: string, optionsJson?: string) => string;
|
|
91
|
-
renderFormulaSvg: (source: string, optionsJson?: string) => string;
|
|
92
|
-
renderFormulaMathml: (source: string, optionsJson?: string) => string;
|
|
93
|
-
renderFormula: (source: string, optionsJson?: string) => string;
|
|
94
|
-
inspectDocument: (inputPath: string) => {
|
|
95
|
-
inputFormat: string;
|
|
96
|
-
path: string;
|
|
97
|
-
reportJson: string;
|
|
98
|
-
};
|
|
99
|
-
renderDocument: (inputPath: string, optionsJson?: string) => {
|
|
100
|
-
exitCode: number;
|
|
101
|
-
outputFormat: string;
|
|
102
|
-
svg?: string;
|
|
103
|
-
reportJson: string;
|
|
104
|
-
};
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
export type VuTeXRuntime = {
|
|
108
|
-
version: () => string;
|
|
109
|
-
render: (inputPath: string, options?: RenderDocumentOptions) => Promise<RenderDocumentResult>;
|
|
110
|
-
inspect: (inputPath: string, options?: InspectDocumentOptions) => Promise<InspectDocumentResult>;
|
|
111
|
-
measureFormula: (source: string, options?: FormulaRenderOptions) => FormulaRender;
|
|
112
|
-
renderFormula: (source: string, options?: FormulaRenderOptions) => FormulaRender;
|
|
113
|
-
packages: {
|
|
114
|
-
list: () => Promise<PackageRecord[]>;
|
|
115
|
-
add: (name: string, options?: PackageInstallOptions) => Promise<void>;
|
|
116
|
-
remove: (name: string) => Promise<void>;
|
|
117
|
-
install: (options?: PackageInstallOptions) => Promise<void>;
|
|
118
|
-
update: () => Promise<void>;
|
|
119
|
-
doctor: () => Promise<PackageDoctorReport>;
|
|
120
|
-
};
|
|
121
|
-
};
|
|
1
|
+
export type VuTeXHost = "node" | "browser" | "wasm";
|
|
2
|
+
|
|
3
|
+
export type VuTeXBackend = "auto" | "native" | "wasm";
|
|
4
|
+
|
|
5
|
+
export type CreateVuTeXOptions = {
|
|
6
|
+
projectRoot?: string;
|
|
7
|
+
host?: VuTeXHost;
|
|
8
|
+
backend?: VuTeXBackend;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type RenderDocumentOptions = {
|
|
12
|
+
output?: string;
|
|
13
|
+
profile?: string;
|
|
14
|
+
input?: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type InspectDocumentOptions = {
|
|
18
|
+
input?: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type FormulaRenderOptions = {
|
|
22
|
+
displayMode?: "inline" | "block";
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type FormulaDiagnostic = {
|
|
26
|
+
code: string;
|
|
27
|
+
severity: "info" | "warning" | "error";
|
|
28
|
+
message: string;
|
|
29
|
+
start?: number;
|
|
30
|
+
end?: number;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type FormulaMetrics = {
|
|
34
|
+
width: number;
|
|
35
|
+
height: number;
|
|
36
|
+
depth: number;
|
|
37
|
+
baseline: number;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type FormulaRender = {
|
|
41
|
+
metrics: FormulaMetrics;
|
|
42
|
+
svg: string;
|
|
43
|
+
mathml?: string;
|
|
44
|
+
diagnostics: FormulaDiagnostic[];
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type VuTeXDiagnostic = {
|
|
48
|
+
code: string;
|
|
49
|
+
severity: "info" | "warning" | "error";
|
|
50
|
+
message: string;
|
|
51
|
+
stage?: string;
|
|
52
|
+
path?: string;
|
|
53
|
+
args?: Record<string, unknown>;
|
|
54
|
+
cause?: string;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export type RenderDocumentResult = {
|
|
58
|
+
exitCode: number;
|
|
59
|
+
outputFormat: string;
|
|
60
|
+
svg?: string;
|
|
61
|
+
reportJson: string;
|
|
62
|
+
diagnostics: VuTeXDiagnostic[];
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export type InspectDocumentResult = {
|
|
66
|
+
inputFormat: string;
|
|
67
|
+
path: string;
|
|
68
|
+
reportJson: string;
|
|
69
|
+
diagnostics: VuTeXDiagnostic[];
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export type PackageInstallOptions = {
|
|
73
|
+
name?: string;
|
|
74
|
+
version?: string;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export type PackageRecord = {
|
|
78
|
+
name: string;
|
|
79
|
+
version: string;
|
|
80
|
+
source: string;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export type PackageDoctorReport = {
|
|
84
|
+
ok: boolean;
|
|
85
|
+
checks: Array<{ id: string; ok: boolean; message: string }>;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export type VuTeXBindings = {
|
|
89
|
+
vutexVersion: () => string;
|
|
90
|
+
measureFormula: (source: string, optionsJson?: string) => string;
|
|
91
|
+
renderFormulaSvg: (source: string, optionsJson?: string) => string;
|
|
92
|
+
renderFormulaMathml: (source: string, optionsJson?: string) => string;
|
|
93
|
+
renderFormula: (source: string, optionsJson?: string) => string;
|
|
94
|
+
inspectDocument: (inputPath: string) => {
|
|
95
|
+
inputFormat: string;
|
|
96
|
+
path: string;
|
|
97
|
+
reportJson: string;
|
|
98
|
+
};
|
|
99
|
+
renderDocument: (inputPath: string, optionsJson?: string) => {
|
|
100
|
+
exitCode: number;
|
|
101
|
+
outputFormat: string;
|
|
102
|
+
svg?: string;
|
|
103
|
+
reportJson: string;
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export type VuTeXRuntime = {
|
|
108
|
+
version: () => string;
|
|
109
|
+
render: (inputPath: string, options?: RenderDocumentOptions) => Promise<RenderDocumentResult>;
|
|
110
|
+
inspect: (inputPath: string, options?: InspectDocumentOptions) => Promise<InspectDocumentResult>;
|
|
111
|
+
measureFormula: (source: string, options?: FormulaRenderOptions) => FormulaRender;
|
|
112
|
+
renderFormula: (source: string, options?: FormulaRenderOptions) => FormulaRender;
|
|
113
|
+
packages: {
|
|
114
|
+
list: () => Promise<PackageRecord[]>;
|
|
115
|
+
add: (name: string, options?: PackageInstallOptions) => Promise<void>;
|
|
116
|
+
remove: (name: string) => Promise<void>;
|
|
117
|
+
install: (options?: PackageInstallOptions) => Promise<void>;
|
|
118
|
+
update: () => Promise<void>;
|
|
119
|
+
doctor: () => Promise<PackageDoctorReport>;
|
|
120
|
+
};
|
|
121
|
+
};
|