merong-docs 0.1.11 → 1.0.0
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/OVERVIEW.md +19 -19
- package/OVERVIEW.zh-CN.md +19 -22
- package/README.md +77 -77
- package/README.zh-CN.md +81 -81
- package/client/android-file-share.ts +25 -25
- package/client/controls.tsx +163 -163
- package/client/document-panel.tsx +166 -166
- package/client/external-file.tsx +78 -78
- package/client/file-reader.tsx +43 -43
- package/client/markdown-panel.tsx +737 -737
- package/client/markdown-scroll.ts +122 -122
- package/client/messages.ts +224 -224
- package/client/native-contacts.ts +145 -145
- package/client/page-render-queue.ts +12 -12
- package/client/page-selection.tsx +227 -227
- package/client/page-tools.tsx +72 -72
- package/client/pdf-geometry.ts +96 -96
- package/client/pdf-panel.tsx +477 -477
- package/client/reader-find.tsx +190 -190
- package/client/reader-notice.tsx +46 -46
- package/client/settings.tsx +143 -143
- package/client/syntax.tsx +55 -55
- package/client/viewport-geometry.ts +61 -61
- package/client/web.ts +462 -462
- package/client/worksheet-panel.tsx +631 -631
- package/client/zoom-controls.tsx +140 -140
- package/index.client.tsx +36 -36
- package/index.server.ts +73 -73
- package/node_modules/markdown-it/bin/markdown-it.mjs +0 -0
- package/node_modules/yaml/bin.mjs +0 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/scripts/prepare-office.mjs +20 -20
- package/server/engine.ts +89 -89
- package/server/external-file.ts +42 -42
- package/server/generated/document-worker.ts +1 -1
- package/server/generated/rust-reader_bg.wasm +0 -0
- package/server/markdown-index.ts +305 -305
- package/server/markdown-links.ts +51 -51
- package/server/markdown-page.ts +120 -120
- package/server/office-fonts.cjs +824 -824
- package/server/office-location.ts +41 -41
- package/server/office-preview.ts +186 -186
- package/server/office-worker.cjs +49 -49
- package/server/office-xml.ts +79 -79
- package/server/pdf-engine.ts +168 -168
- package/server/pdf-text-geometry.ts +60 -60
- package/server/rust-reader.ts +40 -40
- package/server/structured-document.ts +69 -69
- package/server/text-search.ts +15 -15
- package/server/worker-entry.ts +42 -42
- package/server/worker-protocol.ts +38 -38
- package/server/worksheet.ts +67 -67
- package/server/workspace-file.ts +63 -63
- package/shared/contracts.ts +187 -187
- package/shared/file-limits.ts +5 -5
- package/shared/markdown-constants.ts +4 -4
- package/shared/markdown-math.ts +198 -198
- package/shared/markdown-references.ts +83 -83
- package/shared/markdown-source-location.ts +8 -8
- package/shared/reader-settings.ts +15 -15
- package/shared/reader-shortcuts.ts +132 -132
- package/vendor/office2pdf/office2pdf_bg.wasm +2 -2
package/server/workspace-file.ts
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
import { constants } from "node:fs";
|
|
2
|
-
import { open, realpath, stat, type FileHandle } from "node:fs/promises";
|
|
3
|
-
import { extname, isAbsolute, relative, resolve, sep } from "node:path";
|
|
4
|
-
import type { PluginHandlerContext } from "@getpaseo/plugin/server";
|
|
5
|
-
|
|
6
|
-
export async function workspaceDirectory(paseo: PluginHandlerContext["paseo"], id: string) {
|
|
7
|
-
const handle = paseo.workspaces.ref(id);
|
|
8
|
-
await handle.refresh();
|
|
9
|
-
if (!handle.directory) throw new Error("Workspace is unavailable.");
|
|
10
|
-
return handle.directory;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function assertInside(root: string, path: string) {
|
|
14
|
-
const child = relative(root, path);
|
|
15
|
-
if (!child || child === ".." || child.startsWith(`..${sep}`) || isAbsolute(child)) {
|
|
16
|
-
throw new Error("File is outside the workspace.");
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function revisionOf(info: { dev: bigint; ino: bigint; size: bigint; mtimeNs: bigint; ctimeNs: bigint }): string {
|
|
21
|
-
return `${info.dev}:${info.ino}:${info.size}:${info.mtimeNs}:${info.ctimeNs}`;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export async function withWorkspaceFile<Result>(
|
|
25
|
-
directory: string,
|
|
26
|
-
path: string,
|
|
27
|
-
extensions: readonly string[],
|
|
28
|
-
read: (file: FileHandle, size: number, revision: string, path: string) => Promise<Result>,
|
|
29
|
-
): Promise<Result> {
|
|
30
|
-
const extension = (file: string) => extname(file).slice(1).toLowerCase();
|
|
31
|
-
const root = await realpath(directory);
|
|
32
|
-
const lexical = resolve(isAbsolute(path) ? directory : root, path);
|
|
33
|
-
const workspaceRelative = relative(resolve(directory), lexical);
|
|
34
|
-
const candidate = isAbsolute(path) ? resolve(root, workspaceRelative) : lexical;
|
|
35
|
-
assertInside(root, candidate);
|
|
36
|
-
const actual = await realpath(candidate);
|
|
37
|
-
assertInside(root, actual);
|
|
38
|
-
if (!extensions.includes(extension(candidate)) || !extensions.includes(extension(actual))) {
|
|
39
|
-
throw new Error("Unsupported file type.");
|
|
40
|
-
}
|
|
41
|
-
const file = await open(
|
|
42
|
-
actual,
|
|
43
|
-
constants.O_RDONLY | (constants.O_NONBLOCK ?? 0) |
|
|
44
|
-
(process.platform === "win32" ? 0 : constants.O_NOFOLLOW),
|
|
45
|
-
);
|
|
46
|
-
try {
|
|
47
|
-
const info = await file.stat({ bigint: true });
|
|
48
|
-
const confirmed = await realpath(candidate);
|
|
49
|
-
assertInside(root, confirmed);
|
|
50
|
-
const current = await stat(confirmed, { bigint: true });
|
|
51
|
-
if (!info.isFile() || current.ino !== info.ino || current.dev !== info.dev) {
|
|
52
|
-
throw new Error("File is no longer available.");
|
|
53
|
-
}
|
|
54
|
-
const revision = revisionOf(info);
|
|
55
|
-
const value = await read(file, Number(info.size), revision, actual);
|
|
56
|
-
if (revision !== revisionOf(await file.stat({ bigint: true }))) {
|
|
57
|
-
throw new Error("File changed while reading. Reload the file.");
|
|
58
|
-
}
|
|
59
|
-
return value;
|
|
60
|
-
} finally {
|
|
61
|
-
await file.close();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
1
|
+
import { constants } from "node:fs";
|
|
2
|
+
import { open, realpath, stat, type FileHandle } from "node:fs/promises";
|
|
3
|
+
import { extname, isAbsolute, relative, resolve, sep } from "node:path";
|
|
4
|
+
import type { PluginHandlerContext } from "@getpaseo/plugin/server";
|
|
5
|
+
|
|
6
|
+
export async function workspaceDirectory(paseo: PluginHandlerContext["paseo"], id: string) {
|
|
7
|
+
const handle = paseo.workspaces.ref(id);
|
|
8
|
+
await handle.refresh();
|
|
9
|
+
if (!handle.directory) throw new Error("Workspace is unavailable.");
|
|
10
|
+
return handle.directory;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function assertInside(root: string, path: string) {
|
|
14
|
+
const child = relative(root, path);
|
|
15
|
+
if (!child || child === ".." || child.startsWith(`..${sep}`) || isAbsolute(child)) {
|
|
16
|
+
throw new Error("File is outside the workspace.");
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function revisionOf(info: { dev: bigint; ino: bigint; size: bigint; mtimeNs: bigint; ctimeNs: bigint }): string {
|
|
21
|
+
return `${info.dev}:${info.ino}:${info.size}:${info.mtimeNs}:${info.ctimeNs}`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function withWorkspaceFile<Result>(
|
|
25
|
+
directory: string,
|
|
26
|
+
path: string,
|
|
27
|
+
extensions: readonly string[],
|
|
28
|
+
read: (file: FileHandle, size: number, revision: string, path: string) => Promise<Result>,
|
|
29
|
+
): Promise<Result> {
|
|
30
|
+
const extension = (file: string) => extname(file).slice(1).toLowerCase();
|
|
31
|
+
const root = await realpath(directory);
|
|
32
|
+
const lexical = resolve(isAbsolute(path) ? directory : root, path);
|
|
33
|
+
const workspaceRelative = relative(resolve(directory), lexical);
|
|
34
|
+
const candidate = isAbsolute(path) ? resolve(root, workspaceRelative) : lexical;
|
|
35
|
+
assertInside(root, candidate);
|
|
36
|
+
const actual = await realpath(candidate);
|
|
37
|
+
assertInside(root, actual);
|
|
38
|
+
if (!extensions.includes(extension(candidate)) || !extensions.includes(extension(actual))) {
|
|
39
|
+
throw new Error("Unsupported file type.");
|
|
40
|
+
}
|
|
41
|
+
const file = await open(
|
|
42
|
+
actual,
|
|
43
|
+
constants.O_RDONLY | (constants.O_NONBLOCK ?? 0) |
|
|
44
|
+
(process.platform === "win32" ? 0 : constants.O_NOFOLLOW),
|
|
45
|
+
);
|
|
46
|
+
try {
|
|
47
|
+
const info = await file.stat({ bigint: true });
|
|
48
|
+
const confirmed = await realpath(candidate);
|
|
49
|
+
assertInside(root, confirmed);
|
|
50
|
+
const current = await stat(confirmed, { bigint: true });
|
|
51
|
+
if (!info.isFile() || current.ino !== info.ino || current.dev !== info.dev) {
|
|
52
|
+
throw new Error("File is no longer available.");
|
|
53
|
+
}
|
|
54
|
+
const revision = revisionOf(info);
|
|
55
|
+
const value = await read(file, Number(info.size), revision, actual);
|
|
56
|
+
if (revision !== revisionOf(await file.stat({ bigint: true }))) {
|
|
57
|
+
throw new Error("File changed while reading. Reload the file.");
|
|
58
|
+
}
|
|
59
|
+
return value;
|
|
60
|
+
} finally {
|
|
61
|
+
await file.close();
|
|
62
|
+
}
|
|
63
|
+
}
|
package/shared/contracts.ts
CHANGED
|
@@ -1,187 +1,187 @@
|
|
|
1
|
-
import { defineRpc } from "@getpaseo/plugin";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import { maxMarkdownTableLine } from "./markdown-constants";
|
|
4
|
-
|
|
5
|
-
export { markdownExtensions, markdownSearchPageSize } from "./markdown-constants";
|
|
6
|
-
|
|
7
|
-
export const pagedOfficeExtensions = ["docx", "pptx"];
|
|
8
|
-
export const officeExtensions = [...pagedOfficeExtensions, "xlsx"];
|
|
9
|
-
|
|
10
|
-
const fileTarget = z.object({
|
|
11
|
-
workspaceId: z.string().min(1).max(512),
|
|
12
|
-
path: z.string().min(1).max(8192),
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
export const openWorkspaceFile = defineRpc({
|
|
16
|
-
name: "file.open-externally",
|
|
17
|
-
input: fileTarget,
|
|
18
|
-
output: z.object({ opened: z.literal(true) }),
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
const fenceSchema = z.object({
|
|
22
|
-
marker: z.string().regex(/^(?:`{3,256}|~{3,256})$/),
|
|
23
|
-
opening: z.string().max(1024),
|
|
24
|
-
});
|
|
25
|
-
export type Fence = z.infer<typeof fenceSchema>;
|
|
26
|
-
|
|
27
|
-
const markdownTableLine = z.string().min(1).max(maxMarkdownTableLine).regex(/^[^\r\n]+$/);
|
|
28
|
-
const tableContinuation = z.object({ header: markdownTableLine, separator: markdownTableLine });
|
|
29
|
-
export type TableContinuation = z.infer<typeof tableContinuation>;
|
|
30
|
-
|
|
31
|
-
export const readMarkdownPage = defineRpc({
|
|
32
|
-
name: "markdown.page",
|
|
33
|
-
input: fileTarget.extend({
|
|
34
|
-
offset: z.number().int().nonnegative(),
|
|
35
|
-
firstLine: z.number().int().positive().optional(),
|
|
36
|
-
atLine: z.number().int().positive().optional(),
|
|
37
|
-
revision: z.string().max(200).optional(),
|
|
38
|
-
fence: fenceSchema.optional(),
|
|
39
|
-
table: tableContinuation.optional(),
|
|
40
|
-
}),
|
|
41
|
-
output: z.object({
|
|
42
|
-
source: z.string(),
|
|
43
|
-
markdown: z.string(),
|
|
44
|
-
nextOffset: z.number().int().nonnegative().nullable(),
|
|
45
|
-
revision: z.string(),
|
|
46
|
-
offset: z.number().int().nonnegative(),
|
|
47
|
-
firstLine: z.number().int().positive(),
|
|
48
|
-
nextLine: z.number().int().positive(),
|
|
49
|
-
prefixLines: z.number().int().nonnegative(),
|
|
50
|
-
fence: fenceSchema.optional(),
|
|
51
|
-
table: tableContinuation.optional(),
|
|
52
|
-
}),
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const lineNumber = z.number().int().positive();
|
|
56
|
-
const markdownReference = z.object({
|
|
57
|
-
label: z.string(), destination: z.string(), title: z.string().optional(),
|
|
58
|
-
});
|
|
59
|
-
export type MarkdownReference = z.infer<typeof markdownReference>;
|
|
60
|
-
|
|
61
|
-
export const readMarkdownInfo = defineRpc({
|
|
62
|
-
name: "markdown.info",
|
|
63
|
-
input: fileTarget,
|
|
64
|
-
output: z.object({
|
|
65
|
-
revision: z.string(),
|
|
66
|
-
lineCount: lineNumber,
|
|
67
|
-
headings: z.array(z.object({ line: lineNumber, anchor: z.string(), title: z.string(), level: z.number().int() })),
|
|
68
|
-
frontMatter: z.array(z.object({ key: z.string(), value: z.string() })),
|
|
69
|
-
frontMatterEnd: z.number().int().nonnegative(),
|
|
70
|
-
references: z.array(markdownReference),
|
|
71
|
-
}),
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
export const readMarkdownSource = defineRpc({
|
|
75
|
-
name: "markdown.source",
|
|
76
|
-
input: fileTarget.extend({ line: lineNumber, through: lineNumber.optional() }),
|
|
77
|
-
output: z.object({
|
|
78
|
-
revision: z.string(),
|
|
79
|
-
firstLine: lineNumber,
|
|
80
|
-
lines: z.array(z.object({ text: z.string(), ending: z.enum(["", "\n", "\r", "\r\n"]), truncated: z.boolean() })),
|
|
81
|
-
nextLine: lineNumber.nullable(),
|
|
82
|
-
}),
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
const markdownSearchOptions = z.object({
|
|
86
|
-
matchCase: z.boolean(), wholeWord: z.boolean(), regex: z.boolean(),
|
|
87
|
-
});
|
|
88
|
-
export type MarkdownSearchOptions = z.infer<typeof markdownSearchOptions>;
|
|
89
|
-
|
|
90
|
-
export const searchMarkdownFile = defineRpc({
|
|
91
|
-
name: "markdown.search",
|
|
92
|
-
input: fileTarget.extend({
|
|
93
|
-
query: z.string().min(1).max(256), options: markdownSearchOptions, offset: z.number().int().nonnegative(),
|
|
94
|
-
}),
|
|
95
|
-
output: z.object({
|
|
96
|
-
revision: z.string(),
|
|
97
|
-
hits: z.array(z.object({ line: lineNumber, column: z.number().int().nonnegative(), length: z.number().int().nonnegative() })),
|
|
98
|
-
total: z.number().int().nonnegative(),
|
|
99
|
-
invalidPattern: z.boolean(),
|
|
100
|
-
}),
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
const documentBlock = z.discriminatedUnion("kind", [
|
|
104
|
-
z.object({ kind: z.literal("paragraph"), text: z.string(), heading: z.boolean().optional() }),
|
|
105
|
-
z.object({ kind: z.literal("table"), rows: z.array(z.array(z.string())) }),
|
|
106
|
-
]);
|
|
107
|
-
const documentSection = z.object({ title: z.string().optional(), blocks: z.array(documentBlock) });
|
|
108
|
-
export type DocumentBlock = z.infer<typeof documentBlock>;
|
|
109
|
-
export type DocumentSection = z.infer<typeof documentSection>;
|
|
110
|
-
export const readStructuredDocument = defineRpc({
|
|
111
|
-
name: "document.preview",
|
|
112
|
-
input: fileTarget,
|
|
113
|
-
output: z.object({ sections: z.array(documentSection), truncated: z.boolean() }),
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
const sheetCell = z.tuple([z.number(), z.number(), z.string(), z.number(), z.boolean()]);
|
|
117
|
-
const worksheet = z.object({
|
|
118
|
-
columns: z.array(z.number()),
|
|
119
|
-
rows: z.array(z.number()),
|
|
120
|
-
styles: z.array(z.object({
|
|
121
|
-
bold: z.boolean().optional(),
|
|
122
|
-
italic: z.boolean().optional(),
|
|
123
|
-
color: z.string().optional(),
|
|
124
|
-
fill: z.string().optional(),
|
|
125
|
-
fontSize: z.number().optional(),
|
|
126
|
-
align: z.enum(["left", "center", "right"]).optional(),
|
|
127
|
-
wrap: z.boolean().optional(),
|
|
128
|
-
})),
|
|
129
|
-
cells: z.array(sheetCell),
|
|
130
|
-
merges: z.array(z.tuple([z.number(), z.number(), z.number(), z.number()])),
|
|
131
|
-
truncated: z.boolean(),
|
|
132
|
-
});
|
|
133
|
-
export type Worksheet = z.infer<typeof worksheet>;
|
|
134
|
-
export const readWorksheet = defineRpc({
|
|
135
|
-
name: "office.worksheet",
|
|
136
|
-
input: fileTarget.extend({ sheet: z.number().int().min(0).max(255) }),
|
|
137
|
-
output: z.object({ names: z.array(z.string()), sheet: worksheet }),
|
|
138
|
-
});
|
|
139
|
-
const worksheetMatch = z.tuple([z.number().int().nonnegative(), z.number().int().nonnegative(),
|
|
140
|
-
z.number().int().nonnegative(), z.number().int().positive()]);
|
|
141
|
-
export type WorksheetMatch = z.infer<typeof worksheetMatch>;
|
|
142
|
-
export const findWorksheetText = defineRpc({
|
|
143
|
-
name: "office.worksheet-find",
|
|
144
|
-
input: readWorksheet.input.extend({ query: z.string().min(1).max(256), options: markdownSearchOptions }),
|
|
145
|
-
output: z.object({ matches: z.array(worksheetMatch), limited: z.boolean(), invalidPattern: z.boolean() }),
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
const pageTarget = fileTarget.extend({
|
|
149
|
-
page: z.number().int().min(1).max(1_000_000),
|
|
150
|
-
pixels: z.number().int().min(256).max(2560),
|
|
151
|
-
});
|
|
152
|
-
const renderedPage = z.object({
|
|
153
|
-
page: z.number().int().positive(),
|
|
154
|
-
pages: z.number().int().positive(),
|
|
155
|
-
width: z.number().positive(),
|
|
156
|
-
height: z.number().positive(),
|
|
157
|
-
uri: z.string(),
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
const pageRun = z.object({
|
|
161
|
-
count: z.number().int().positive(),
|
|
162
|
-
width: z.number().positive(),
|
|
163
|
-
height: z.number().positive(),
|
|
164
|
-
});
|
|
165
|
-
export type PageRun = z.infer<typeof pageRun>;
|
|
166
|
-
|
|
167
|
-
export const readDocumentLayout = defineRpc({
|
|
168
|
-
name: "document.layout",
|
|
169
|
-
input: fileTarget,
|
|
170
|
-
output: z.union([z.array(pageRun).min(1), z.null(), z.literal("loading")]),
|
|
171
|
-
});
|
|
172
|
-
const pageGlyph = z.tuple([z.number(), z.number(), z.number(), z.number(), z.number(), z.number()]);
|
|
173
|
-
export type PageGlyph = z.infer<typeof pageGlyph>;
|
|
174
|
-
export const readDocumentText = defineRpc({
|
|
175
|
-
name: "document.text",
|
|
176
|
-
input: fileTarget.extend({ page: lineNumber }),
|
|
177
|
-
output: z.object({ text: z.string(), truncated: z.boolean(), glyphs: z.array(pageGlyph).optional() }).nullable(),
|
|
178
|
-
});
|
|
179
|
-
const pageTextMatch = z.tuple([lineNumber, z.number().int().nonnegative(), z.number().int().positive()]);
|
|
180
|
-
export type PageTextMatch = z.infer<typeof pageTextMatch>;
|
|
181
|
-
export const findDocumentText = defineRpc({
|
|
182
|
-
name: "document.find-text",
|
|
183
|
-
input: fileTarget.extend({ query: z.string().min(1).max(256), options: markdownSearchOptions }),
|
|
184
|
-
output: z.object({ matches: z.array(pageTextMatch), limited: z.boolean(), invalidPattern: z.boolean() }).nullable(),
|
|
185
|
-
});
|
|
186
|
-
export const renderPdfPage = defineRpc({ name: "pdf.page", input: pageTarget, output: renderedPage });
|
|
187
|
-
export const renderOfficePage = defineRpc({ name: "office.page", input: pageTarget, output: renderedPage.nullable() });
|
|
1
|
+
import { defineRpc } from "@getpaseo/plugin";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { maxMarkdownTableLine } from "./markdown-constants";
|
|
4
|
+
|
|
5
|
+
export { markdownExtensions, markdownSearchPageSize } from "./markdown-constants";
|
|
6
|
+
|
|
7
|
+
export const pagedOfficeExtensions = ["docx", "pptx"];
|
|
8
|
+
export const officeExtensions = [...pagedOfficeExtensions, "xlsx"];
|
|
9
|
+
|
|
10
|
+
const fileTarget = z.object({
|
|
11
|
+
workspaceId: z.string().min(1).max(512),
|
|
12
|
+
path: z.string().min(1).max(8192),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export const openWorkspaceFile = defineRpc({
|
|
16
|
+
name: "file.open-externally",
|
|
17
|
+
input: fileTarget,
|
|
18
|
+
output: z.object({ opened: z.literal(true) }),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const fenceSchema = z.object({
|
|
22
|
+
marker: z.string().regex(/^(?:`{3,256}|~{3,256})$/),
|
|
23
|
+
opening: z.string().max(1024),
|
|
24
|
+
});
|
|
25
|
+
export type Fence = z.infer<typeof fenceSchema>;
|
|
26
|
+
|
|
27
|
+
const markdownTableLine = z.string().min(1).max(maxMarkdownTableLine).regex(/^[^\r\n]+$/);
|
|
28
|
+
const tableContinuation = z.object({ header: markdownTableLine, separator: markdownTableLine });
|
|
29
|
+
export type TableContinuation = z.infer<typeof tableContinuation>;
|
|
30
|
+
|
|
31
|
+
export const readMarkdownPage = defineRpc({
|
|
32
|
+
name: "markdown.page",
|
|
33
|
+
input: fileTarget.extend({
|
|
34
|
+
offset: z.number().int().nonnegative(),
|
|
35
|
+
firstLine: z.number().int().positive().optional(),
|
|
36
|
+
atLine: z.number().int().positive().optional(),
|
|
37
|
+
revision: z.string().max(200).optional(),
|
|
38
|
+
fence: fenceSchema.optional(),
|
|
39
|
+
table: tableContinuation.optional(),
|
|
40
|
+
}),
|
|
41
|
+
output: z.object({
|
|
42
|
+
source: z.string(),
|
|
43
|
+
markdown: z.string(),
|
|
44
|
+
nextOffset: z.number().int().nonnegative().nullable(),
|
|
45
|
+
revision: z.string(),
|
|
46
|
+
offset: z.number().int().nonnegative(),
|
|
47
|
+
firstLine: z.number().int().positive(),
|
|
48
|
+
nextLine: z.number().int().positive(),
|
|
49
|
+
prefixLines: z.number().int().nonnegative(),
|
|
50
|
+
fence: fenceSchema.optional(),
|
|
51
|
+
table: tableContinuation.optional(),
|
|
52
|
+
}),
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const lineNumber = z.number().int().positive();
|
|
56
|
+
const markdownReference = z.object({
|
|
57
|
+
label: z.string(), destination: z.string(), title: z.string().optional(),
|
|
58
|
+
});
|
|
59
|
+
export type MarkdownReference = z.infer<typeof markdownReference>;
|
|
60
|
+
|
|
61
|
+
export const readMarkdownInfo = defineRpc({
|
|
62
|
+
name: "markdown.info",
|
|
63
|
+
input: fileTarget,
|
|
64
|
+
output: z.object({
|
|
65
|
+
revision: z.string(),
|
|
66
|
+
lineCount: lineNumber,
|
|
67
|
+
headings: z.array(z.object({ line: lineNumber, anchor: z.string(), title: z.string(), level: z.number().int() })),
|
|
68
|
+
frontMatter: z.array(z.object({ key: z.string(), value: z.string() })),
|
|
69
|
+
frontMatterEnd: z.number().int().nonnegative(),
|
|
70
|
+
references: z.array(markdownReference),
|
|
71
|
+
}),
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
export const readMarkdownSource = defineRpc({
|
|
75
|
+
name: "markdown.source",
|
|
76
|
+
input: fileTarget.extend({ line: lineNumber, through: lineNumber.optional() }),
|
|
77
|
+
output: z.object({
|
|
78
|
+
revision: z.string(),
|
|
79
|
+
firstLine: lineNumber,
|
|
80
|
+
lines: z.array(z.object({ text: z.string(), ending: z.enum(["", "\n", "\r", "\r\n"]), truncated: z.boolean() })),
|
|
81
|
+
nextLine: lineNumber.nullable(),
|
|
82
|
+
}),
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const markdownSearchOptions = z.object({
|
|
86
|
+
matchCase: z.boolean(), wholeWord: z.boolean(), regex: z.boolean(),
|
|
87
|
+
});
|
|
88
|
+
export type MarkdownSearchOptions = z.infer<typeof markdownSearchOptions>;
|
|
89
|
+
|
|
90
|
+
export const searchMarkdownFile = defineRpc({
|
|
91
|
+
name: "markdown.search",
|
|
92
|
+
input: fileTarget.extend({
|
|
93
|
+
query: z.string().min(1).max(256), options: markdownSearchOptions, offset: z.number().int().nonnegative(),
|
|
94
|
+
}),
|
|
95
|
+
output: z.object({
|
|
96
|
+
revision: z.string(),
|
|
97
|
+
hits: z.array(z.object({ line: lineNumber, column: z.number().int().nonnegative(), length: z.number().int().nonnegative() })),
|
|
98
|
+
total: z.number().int().nonnegative(),
|
|
99
|
+
invalidPattern: z.boolean(),
|
|
100
|
+
}),
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const documentBlock = z.discriminatedUnion("kind", [
|
|
104
|
+
z.object({ kind: z.literal("paragraph"), text: z.string(), heading: z.boolean().optional() }),
|
|
105
|
+
z.object({ kind: z.literal("table"), rows: z.array(z.array(z.string())) }),
|
|
106
|
+
]);
|
|
107
|
+
const documentSection = z.object({ title: z.string().optional(), blocks: z.array(documentBlock) });
|
|
108
|
+
export type DocumentBlock = z.infer<typeof documentBlock>;
|
|
109
|
+
export type DocumentSection = z.infer<typeof documentSection>;
|
|
110
|
+
export const readStructuredDocument = defineRpc({
|
|
111
|
+
name: "document.preview",
|
|
112
|
+
input: fileTarget,
|
|
113
|
+
output: z.object({ sections: z.array(documentSection), truncated: z.boolean() }),
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const sheetCell = z.tuple([z.number(), z.number(), z.string(), z.number(), z.boolean()]);
|
|
117
|
+
const worksheet = z.object({
|
|
118
|
+
columns: z.array(z.number()),
|
|
119
|
+
rows: z.array(z.number()),
|
|
120
|
+
styles: z.array(z.object({
|
|
121
|
+
bold: z.boolean().optional(),
|
|
122
|
+
italic: z.boolean().optional(),
|
|
123
|
+
color: z.string().optional(),
|
|
124
|
+
fill: z.string().optional(),
|
|
125
|
+
fontSize: z.number().optional(),
|
|
126
|
+
align: z.enum(["left", "center", "right"]).optional(),
|
|
127
|
+
wrap: z.boolean().optional(),
|
|
128
|
+
})),
|
|
129
|
+
cells: z.array(sheetCell),
|
|
130
|
+
merges: z.array(z.tuple([z.number(), z.number(), z.number(), z.number()])),
|
|
131
|
+
truncated: z.boolean(),
|
|
132
|
+
});
|
|
133
|
+
export type Worksheet = z.infer<typeof worksheet>;
|
|
134
|
+
export const readWorksheet = defineRpc({
|
|
135
|
+
name: "office.worksheet",
|
|
136
|
+
input: fileTarget.extend({ sheet: z.number().int().min(0).max(255) }),
|
|
137
|
+
output: z.object({ names: z.array(z.string()), sheet: worksheet }),
|
|
138
|
+
});
|
|
139
|
+
const worksheetMatch = z.tuple([z.number().int().nonnegative(), z.number().int().nonnegative(),
|
|
140
|
+
z.number().int().nonnegative(), z.number().int().positive()]);
|
|
141
|
+
export type WorksheetMatch = z.infer<typeof worksheetMatch>;
|
|
142
|
+
export const findWorksheetText = defineRpc({
|
|
143
|
+
name: "office.worksheet-find",
|
|
144
|
+
input: readWorksheet.input.extend({ query: z.string().min(1).max(256), options: markdownSearchOptions }),
|
|
145
|
+
output: z.object({ matches: z.array(worksheetMatch), limited: z.boolean(), invalidPattern: z.boolean() }),
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
const pageTarget = fileTarget.extend({
|
|
149
|
+
page: z.number().int().min(1).max(1_000_000),
|
|
150
|
+
pixels: z.number().int().min(256).max(2560),
|
|
151
|
+
});
|
|
152
|
+
const renderedPage = z.object({
|
|
153
|
+
page: z.number().int().positive(),
|
|
154
|
+
pages: z.number().int().positive(),
|
|
155
|
+
width: z.number().positive(),
|
|
156
|
+
height: z.number().positive(),
|
|
157
|
+
uri: z.string(),
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
const pageRun = z.object({
|
|
161
|
+
count: z.number().int().positive(),
|
|
162
|
+
width: z.number().positive(),
|
|
163
|
+
height: z.number().positive(),
|
|
164
|
+
});
|
|
165
|
+
export type PageRun = z.infer<typeof pageRun>;
|
|
166
|
+
|
|
167
|
+
export const readDocumentLayout = defineRpc({
|
|
168
|
+
name: "document.layout",
|
|
169
|
+
input: fileTarget,
|
|
170
|
+
output: z.union([z.array(pageRun).min(1), z.null(), z.literal("loading")]),
|
|
171
|
+
});
|
|
172
|
+
const pageGlyph = z.tuple([z.number(), z.number(), z.number(), z.number(), z.number(), z.number()]);
|
|
173
|
+
export type PageGlyph = z.infer<typeof pageGlyph>;
|
|
174
|
+
export const readDocumentText = defineRpc({
|
|
175
|
+
name: "document.text",
|
|
176
|
+
input: fileTarget.extend({ page: lineNumber }),
|
|
177
|
+
output: z.object({ text: z.string(), truncated: z.boolean(), glyphs: z.array(pageGlyph).optional() }).nullable(),
|
|
178
|
+
});
|
|
179
|
+
const pageTextMatch = z.tuple([lineNumber, z.number().int().nonnegative(), z.number().int().positive()]);
|
|
180
|
+
export type PageTextMatch = z.infer<typeof pageTextMatch>;
|
|
181
|
+
export const findDocumentText = defineRpc({
|
|
182
|
+
name: "document.find-text",
|
|
183
|
+
input: fileTarget.extend({ query: z.string().min(1).max(256), options: markdownSearchOptions }),
|
|
184
|
+
output: z.object({ matches: z.array(pageTextMatch), limited: z.boolean(), invalidPattern: z.boolean() }).nullable(),
|
|
185
|
+
});
|
|
186
|
+
export const renderPdfPage = defineRpc({ name: "pdf.page", input: pageTarget, output: renderedPage });
|
|
187
|
+
export const renderOfficePage = defineRpc({ name: "office.page", input: pageTarget, output: renderedPage.nullable() });
|
package/shared/file-limits.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const MiB = 1024 * 1024;
|
|
2
|
-
|
|
3
|
-
export const pdfFileLimit = 192 * MiB;
|
|
4
|
-
export const pagedOfficeFileLimit = 48 * MiB;
|
|
5
|
-
export const worksheetFileLimit = 64 * MiB;
|
|
1
|
+
const MiB = 1024 * 1024;
|
|
2
|
+
|
|
3
|
+
export const pdfFileLimit = 192 * MiB;
|
|
4
|
+
export const pagedOfficeFileLimit = 48 * MiB;
|
|
5
|
+
export const worksheetFileLimit = 64 * MiB;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const markdownExtensions = ["md", "markdown", "mdown", "mkd", "mkdn", "mdwn"];
|
|
2
|
-
export const maxFormulaLength = 2400;
|
|
3
|
-
export const maxMarkdownTableLine = 8192;
|
|
4
|
-
export const markdownSearchPageSize = 512;
|
|
1
|
+
export const markdownExtensions = ["md", "markdown", "mdown", "mkd", "mkdn", "mdwn"];
|
|
2
|
+
export const maxFormulaLength = 2400;
|
|
3
|
+
export const maxMarkdownTableLine = 8192;
|
|
4
|
+
export const markdownSearchPageSize = 512;
|