@univer-cli/doc-typst-facade 1.0.0-beta.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/README.md +63 -0
- package/README.zh-CN.md +67 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +70 -0
- package/dist/index.mjs +1 -0
- package/package.json +24 -0
package/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# @univer-cli/doc-typst-facade
|
|
2
|
+
|
|
3
|
+
English | [简体中文](./README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
Compile a constrained Typst source bundle into a plain JavaScript Facade program that creates a complete Univer Doc.
|
|
6
|
+
|
|
7
|
+
The compilation result also includes structured diagnostics. When the layout needs manual review, the package can generate Typst PNG previews from the same source.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @univer-cli/doc-typst-facade
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Requires Node.js 22.12 or higher and uses the platform native binding supported by the package.
|
|
16
|
+
|
|
17
|
+
## Bundle structure
|
|
18
|
+
|
|
19
|
+
Bundle root contains `typst.json`, page source and local assets:
|
|
20
|
+
|
|
21
|
+
```text
|
|
22
|
+
paper/
|
|
23
|
+
├── typst.json
|
|
24
|
+
├── prelude.typ
|
|
25
|
+
├── pages/
|
|
26
|
+
│ ├── 01.typ
|
|
27
|
+
│ └── 02.typ
|
|
28
|
+
└── assets/
|
|
29
|
+
└── logo.png
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The manifest declares `targetUnitId` and an ordered `pages` list. It may also declare `title`, `prelude`, and explicit page IDs. Every path must stay within the bundle root; absolute paths, URLs, parent traversal, and symlinks that escape the root are rejected.
|
|
33
|
+
|
|
34
|
+
## Quick Start
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { compileDocTypstBundle } from "@univer-cli/doc-typst-facade";
|
|
38
|
+
|
|
39
|
+
const result = await compileDocTypstBundle("./paper", {
|
|
40
|
+
previewDir: "./review/typst",
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
console.log(result.javascript);
|
|
44
|
+
console.log(result.diagnostics);
|
|
45
|
+
console.log(result.previews);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`javascript` assumes that `univerAPI` is available in the execution environment. Running it creates the complete Doc identified by `targetUnitId` in the manifest. This ID is internal to the generated program, not the real content identity assigned by Workspace.
|
|
49
|
+
|
|
50
|
+
No PNG is generated when `previewDir` is omitted. When provided, the same official native binding renders the previews, and each result records its page ID, source path, and output path.
|
|
51
|
+
|
|
52
|
+
## Diagnostics and failures
|
|
53
|
+
|
|
54
|
+
Diagnostics have `info`, `warning`, or `error` severity:
|
|
55
|
+
|
|
56
|
+
- A warning means the result is available but has fidelity limitations or needs manual review.
|
|
57
|
+
- An error means the caller should not apply the generated program to a persistent target.
|
|
58
|
+
- If the program cannot be generated, the package throws `DocTypstFacadeError` or `DaCTypstTranslationError` with diagnostics.
|
|
59
|
+
|
|
60
|
+
An adapter can identify capability errors with `isDocTypstFacadeError()` and present each issue by source path/span.
|
|
61
|
+
|
|
62
|
+
For the preset command, see
|
|
63
|
+
[`@univer-cli/doc-typst-facade-command`](../doc-typst-facade-command/README.md).
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# @univer-cli/doc-typst-facade
|
|
2
|
+
|
|
3
|
+
[English](./README.md) | 简体中文
|
|
4
|
+
|
|
5
|
+
把一个受约束的 Typst source bundle 编译为 plain JavaScript Facade program,用于创建完整的 Univer Doc。
|
|
6
|
+
|
|
7
|
+
编译结果同时包含结构化 diagnostics;需要人工复核版式时,还可以生成与同一 source 对应的 Typst PNG preview。
|
|
8
|
+
|
|
9
|
+
## 安装
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @univer-cli/doc-typst-facade
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
要求 Node.js 22.12 或更高版本,并使用 package 支持的平台 native binding。
|
|
16
|
+
|
|
17
|
+
## Bundle 结构
|
|
18
|
+
|
|
19
|
+
Bundle root 包含 `typst.json`、页面 source 和本地 asset:
|
|
20
|
+
|
|
21
|
+
```text
|
|
22
|
+
paper/
|
|
23
|
+
├── typst.json
|
|
24
|
+
├── prelude.typ
|
|
25
|
+
├── pages/
|
|
26
|
+
│ ├── 01.typ
|
|
27
|
+
│ └── 02.typ
|
|
28
|
+
└── assets/
|
|
29
|
+
└── logo.png
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Manifest 声明 `targetUnitId` 和有序 `pages`,也可以声明 `title`、`prelude` 与显式 page ID。所有路径必须
|
|
33
|
+
留在 bundle root 内;绝对路径、URL、parent traversal 和逃逸 root 的 symlink 会被拒绝。
|
|
34
|
+
|
|
35
|
+
## 快速开始
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { compileDocTypstBundle } from "@univer-cli/doc-typst-facade";
|
|
39
|
+
|
|
40
|
+
const result = await compileDocTypstBundle("./paper", {
|
|
41
|
+
previewDir: "./review/typst",
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
console.log(result.javascript);
|
|
45
|
+
console.log(result.diagnostics);
|
|
46
|
+
console.log(result.previews);
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
`javascript` 假定执行环境已注入 `univerAPI`。执行后会创建 manifest 中 `targetUnitId` 指定的完整 Doc;
|
|
50
|
+
这个 ID 是生成 program 内部的 identity,不是 Workspace 分配的真实 content identity。
|
|
51
|
+
|
|
52
|
+
省略 `previewDir` 时不生成 PNG。提供后,preview 由同一官方 native binding 渲染,并记录 page ID、source
|
|
53
|
+
path 和输出 path。
|
|
54
|
+
|
|
55
|
+
## Diagnostics 与失败
|
|
56
|
+
|
|
57
|
+
Diagnostic 包含 `info`、`warning` 或 `error`:
|
|
58
|
+
|
|
59
|
+
- warning 表示结果可用,但存在 fidelity 限制或需要人工复核;
|
|
60
|
+
- error 表示调用方不应把生成 program 应用于持久化 target;
|
|
61
|
+
- 无法产生 program 时抛出 `DocTypstFacadeError` 或带 diagnostics 的
|
|
62
|
+
`DaCTypstTranslationError`。
|
|
63
|
+
|
|
64
|
+
Adapter 可用 `isDocTypstFacadeError()` 识别 capability error,并按 source path/span 呈现问题。
|
|
65
|
+
|
|
66
|
+
预设 command 见
|
|
67
|
+
[`@univer-cli/doc-typst-facade-command`](../doc-typst-facade-command/README.zh-CN.md)。
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';module['exports']=require('./index.mjs');
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
//#region src/doc-typst-pages.d.ts
|
|
2
|
+
type DaCTypstMappingGrade = "native editable" | "approximate editable" | "preserved metadata" | "diagnostic";
|
|
3
|
+
interface DaCTypstPreviewArtifactMetadata {
|
|
4
|
+
readonly pageId: string;
|
|
5
|
+
readonly path: string;
|
|
6
|
+
readonly sourcePath: string;
|
|
7
|
+
}
|
|
8
|
+
interface DaCTypstTranslationDiagnostic {
|
|
9
|
+
readonly fidelityLimit?: string;
|
|
10
|
+
readonly feature?: string;
|
|
11
|
+
readonly mappingGrade?: DaCTypstMappingGrade;
|
|
12
|
+
readonly pageId?: string;
|
|
13
|
+
readonly recommendedNextAction?: string;
|
|
14
|
+
readonly reason: string;
|
|
15
|
+
readonly severity?: "info" | "warning" | "error";
|
|
16
|
+
readonly sourceNodeId?: string;
|
|
17
|
+
readonly sourcePath: string;
|
|
18
|
+
readonly span?: DaCTypstSourceSpan;
|
|
19
|
+
readonly suggestedRewrite?: string;
|
|
20
|
+
}
|
|
21
|
+
interface DaCTypstSourceSpan {
|
|
22
|
+
readonly column?: number;
|
|
23
|
+
readonly endColumn?: number;
|
|
24
|
+
readonly endLine?: number;
|
|
25
|
+
readonly line?: number;
|
|
26
|
+
readonly offset?: number;
|
|
27
|
+
}
|
|
28
|
+
declare function createDaCTranslationDiagnostic(diagnostic: DaCTypstTranslationDiagnostic): DaCTypstTranslationDiagnostic;
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/compiler.d.ts
|
|
31
|
+
interface DocTypstBundleManifest {
|
|
32
|
+
readonly schemaVersion: 1;
|
|
33
|
+
readonly targetUnitId: string;
|
|
34
|
+
readonly title?: string;
|
|
35
|
+
readonly pages: readonly (string | {
|
|
36
|
+
readonly id?: string;
|
|
37
|
+
readonly source: string;
|
|
38
|
+
})[];
|
|
39
|
+
readonly prelude?: readonly string[];
|
|
40
|
+
}
|
|
41
|
+
type DocTypstDiagnostic = DaCTypstTranslationDiagnostic;
|
|
42
|
+
type DocTypstPreview = DaCTypstPreviewArtifactMetadata;
|
|
43
|
+
interface CompileDocTypstBundleOptions {
|
|
44
|
+
readonly previewDir?: string;
|
|
45
|
+
}
|
|
46
|
+
interface CompileDocTypstBundleResult {
|
|
47
|
+
readonly diagnostics: readonly DocTypstDiagnostic[];
|
|
48
|
+
readonly javascript: string;
|
|
49
|
+
readonly targetUnitId: string;
|
|
50
|
+
readonly title: string;
|
|
51
|
+
readonly previews: readonly DocTypstPreview[];
|
|
52
|
+
}
|
|
53
|
+
/** Parse and compile the lifecycle-neutral paper/typst.json bundle exactly once. */
|
|
54
|
+
declare function compileDocTypstBundle(bundleOrManifestPath: string, options?: CompileDocTypstBundleOptions): Promise<CompileDocTypstBundleResult>;
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/error.d.ts
|
|
57
|
+
declare class DocTypstFacadeError extends Error {
|
|
58
|
+
readonly code: string;
|
|
59
|
+
constructor(code: string, message: string);
|
|
60
|
+
}
|
|
61
|
+
declare function isDocTypstFacadeError(error: unknown): error is DocTypstFacadeError;
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/doc-typst-pages-translator.d.ts
|
|
64
|
+
declare class DaCTypstTranslationError extends DocTypstFacadeError {
|
|
65
|
+
readonly diagnostics: readonly ReturnType<typeof createDaCTranslationDiagnostic>[];
|
|
66
|
+
readonly previews: readonly DaCTypstPreviewArtifactMetadata[];
|
|
67
|
+
constructor(message: string, diagnostics: readonly ReturnType<typeof createDaCTranslationDiagnostic>[], previews?: readonly DaCTypstPreviewArtifactMetadata[]);
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
export { type CompileDocTypstBundleOptions, type CompileDocTypstBundleResult, DaCTypstTranslationError, type DocTypstBundleManifest, type DocTypstDiagnostic, DocTypstFacadeError, type DocTypstPreview, compileDocTypstBundle, isDocTypstFacadeError };
|