dsh-typst-plugin 0.0.0-stage → 0.1.0-alpha.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.
Files changed (106) hide show
  1. package/LICENSE +21 -0
  2. package/README.en.md +87 -0
  3. package/README.md +86 -2
  4. package/cordis.patch.yml +6 -0
  5. package/docs/images/icon.png +0 -0
  6. package/docs/plugin-detail.en.md +2 -0
  7. package/docs/plugin-detail.md +2 -0
  8. package/lib/client.js +41044 -0
  9. package/lib/client.js.map +7 -0
  10. package/lib/config.d.ts +50 -0
  11. package/lib/config.d.ts.map +1 -0
  12. package/lib/config.js +31 -0
  13. package/lib/config.js.map +7 -0
  14. package/lib/constants.d.ts +58 -0
  15. package/lib/constants.d.ts.map +1 -0
  16. package/lib/constants.js +62 -0
  17. package/lib/constants.js.map +7 -0
  18. package/lib/contract.d.ts +179 -0
  19. package/lib/contract.d.ts.map +1 -0
  20. package/lib/contract.js +1 -0
  21. package/lib/contract.js.map +7 -0
  22. package/lib/errors.d.ts +77 -0
  23. package/lib/errors.d.ts.map +1 -0
  24. package/lib/errors.js +86 -0
  25. package/lib/errors.js.map +7 -0
  26. package/lib/host/facts.d.ts +31 -0
  27. package/lib/host/facts.d.ts.map +1 -0
  28. package/lib/host/facts.js +151 -0
  29. package/lib/host/facts.js.map +7 -0
  30. package/lib/index.d.ts +2 -0
  31. package/lib/index.d.ts.map +1 -0
  32. package/lib/index.js +5 -0
  33. package/lib/index.js.map +7 -0
  34. package/lib/remote.d.ts +69 -0
  35. package/lib/remote.d.ts.map +1 -0
  36. package/lib/remote.js +146 -0
  37. package/lib/remote.js.map +7 -0
  38. package/lib/service.d.ts +47 -0
  39. package/lib/service.d.ts.map +1 -0
  40. package/lib/service.js +110 -0
  41. package/lib/service.js.map +7 -0
  42. package/lib/skills/typst.d.ts +13 -0
  43. package/lib/skills/typst.d.ts.map +1 -0
  44. package/lib/skills/typst.js +72 -0
  45. package/lib/skills/typst.js.map +7 -0
  46. package/lib/status-codec.d.ts +11 -0
  47. package/lib/status-codec.d.ts.map +1 -0
  48. package/lib/status-codec.js +6 -0
  49. package/lib/status-codec.js.map +7 -0
  50. package/lib/tools/registration.d.ts +22 -0
  51. package/lib/tools/registration.d.ts.map +1 -0
  52. package/lib/tools/registration.js +525 -0
  53. package/lib/tools/registration.js.map +7 -0
  54. package/lib/tools/shared.d.ts +31 -0
  55. package/lib/tools/shared.d.ts.map +1 -0
  56. package/lib/tools/shared.js +70 -0
  57. package/lib/tools/shared.js.map +7 -0
  58. package/lib/typert.d.ts +23 -0
  59. package/lib/typert.d.ts.map +1 -0
  60. package/lib/typert.js +67 -0
  61. package/lib/typert.js.map +7 -0
  62. package/lib/typst/diagnostics.d.ts +58 -0
  63. package/lib/typst/diagnostics.d.ts.map +1 -0
  64. package/lib/typst/diagnostics.js +171 -0
  65. package/lib/typst/diagnostics.js.map +7 -0
  66. package/lib/typst/locate.d.ts +68 -0
  67. package/lib/typst/locate.d.ts.map +1 -0
  68. package/lib/typst/locate.js +194 -0
  69. package/lib/typst/locate.js.map +7 -0
  70. package/lib/typst/mainfile.d.ts +21 -0
  71. package/lib/typst/mainfile.d.ts.map +1 -0
  72. package/lib/typst/mainfile.js +64 -0
  73. package/lib/typst/mainfile.js.map +7 -0
  74. package/lib/typst/match.d.ts +59 -0
  75. package/lib/typst/match.d.ts.map +1 -0
  76. package/lib/typst/match.js +171 -0
  77. package/lib/typst/match.js.map +7 -0
  78. package/lib/typst/oneshot.d.ts +45 -0
  79. package/lib/typst/oneshot.d.ts.map +1 -0
  80. package/lib/typst/oneshot.js +76 -0
  81. package/lib/typst/oneshot.js.map +7 -0
  82. package/lib/typst/pdf-extract.d.ts +29 -0
  83. package/lib/typst/pdf-extract.d.ts.map +1 -0
  84. package/lib/typst/pdf-extract.js +87 -0
  85. package/lib/typst/pdf-extract.js.map +7 -0
  86. package/lib/typst/pdfjs-worker.d.js +1 -0
  87. package/lib/typst/pdfjs-worker.d.js.map +7 -0
  88. package/lib/typst/text.d.ts +65 -0
  89. package/lib/typst/text.d.ts.map +1 -0
  90. package/lib/typst/text.js +314 -0
  91. package/lib/typst/text.js.map +7 -0
  92. package/lib/typst/watcher.d.ts +77 -0
  93. package/lib/typst/watcher.d.ts.map +1 -0
  94. package/lib/typst/watcher.js +219 -0
  95. package/lib/typst/watcher.js.map +7 -0
  96. package/lib/wire-schemas.d.ts +578 -0
  97. package/lib/wire-schemas.d.ts.map +1 -0
  98. package/lib/wire-schemas.js +384 -0
  99. package/lib/wire-schemas.js.map +7 -0
  100. package/lib/workspace/session.d.ts +209 -0
  101. package/lib/workspace/session.d.ts.map +1 -0
  102. package/lib/workspace/session.js +1232 -0
  103. package/lib/workspace/session.js.map +7 -0
  104. package/locale/en.json +9 -0
  105. package/locale/zh.json +9 -0
  106. package/package.json +256 -4
@@ -0,0 +1,194 @@
1
+ import { spawn } from "node:child_process";
2
+ import { access, constants, stat } from "node:fs/promises";
3
+ import { delimiter, isAbsolute, join, sep } from "node:path";
4
+ import { MIN_TYPST } from "../constants.js";
5
+ function parseVersion(text) {
6
+ const match = /(?:^|\s)typst\s+v?(\d+)\.(\d+)\.(\d+)/i.exec(text) ?? /(\d+)\.(\d+)\.(\d+)/.exec(text);
7
+ return match ? [Number(match[1]), Number(match[2]), Number(match[3])] : null;
8
+ }
9
+ function compareVersion(a, b) {
10
+ for (let index = 0; index < 3; index++) {
11
+ if (a[index] !== b[index]) return a[index] - b[index];
12
+ }
13
+ return 0;
14
+ }
15
+ const versionText = (version) => version.join(".");
16
+ function atLeast(version, required) {
17
+ const parsed = version ? parseVersion(version) : null;
18
+ return !!parsed && compareVersion(parsed, required) >= 0;
19
+ }
20
+ function commonDirs(platform, env, home) {
21
+ if (platform === "win32") {
22
+ const local = env.LOCALAPPDATA ?? join(home, "AppData", "Local");
23
+ return [
24
+ join(local, "Microsoft", "WinGet", "Links"),
25
+ join(local, "Programs", "typst"),
26
+ join(home, ".cargo", "bin"),
27
+ join(home, "scoop", "shims"),
28
+ join(env.ProgramData ?? "C:\\ProgramData", "chocolatey", "bin")
29
+ ];
30
+ }
31
+ return [
32
+ "/opt/homebrew/bin",
33
+ "/usr/local/bin",
34
+ join(home, ".cargo", "bin"),
35
+ join(home, ".local", "bin"),
36
+ join(home, "bin"),
37
+ join(home, ".nix-profile", "bin"),
38
+ "/run/current-system/sw/bin",
39
+ "/nix/var/nix/profiles/default/bin",
40
+ "/snap/bin",
41
+ "/usr/bin"
42
+ ];
43
+ }
44
+ function searchedDirs(platform, env, home, arch = process.arch) {
45
+ const dirs = commonDirs(platform, env, home);
46
+ const first = platform === "win32" ? [dirs[0], join(home, ".cargo", "bin")] : platform === "darwin" ? [
47
+ arch === "arm64" ? "/opt/homebrew/bin" : "/usr/local/bin",
48
+ join(home, ".cargo", "bin")
49
+ ] : [join(home, ".cargo", "bin"), join(home, ".local", "bin")];
50
+ const ordered = [.../* @__PURE__ */ new Set([...first, ...dirs])];
51
+ return ordered.map(
52
+ (dir) => home && dir.startsWith(home + sep) ? `~${dir.slice(home.length)}` : dir
53
+ );
54
+ }
55
+ async function executable(path) {
56
+ try {
57
+ const info = await stat(path);
58
+ if (!info.isFile()) return false;
59
+ await access(
60
+ path,
61
+ process.platform === "win32" ? constants.F_OK : constants.X_OK
62
+ );
63
+ return true;
64
+ } catch {
65
+ return false;
66
+ }
67
+ }
68
+ function run(command, args, options = {}) {
69
+ return new Promise((resolve) => {
70
+ let stdout = "";
71
+ let stderr = "";
72
+ let timedOut = false;
73
+ let child;
74
+ try {
75
+ child = spawn(command, args, {
76
+ cwd: options.cwd,
77
+ env: options.env ?? process.env,
78
+ stdio: ["ignore", "pipe", "pipe"],
79
+ windowsHide: true
80
+ });
81
+ } catch (error) {
82
+ resolve({
83
+ code: null,
84
+ stdout,
85
+ stderr: error instanceof Error ? error.message : String(error),
86
+ timedOut
87
+ });
88
+ return;
89
+ }
90
+ const timer = setTimeout(() => {
91
+ timedOut = true;
92
+ child.kill("SIGKILL");
93
+ }, options.timeoutMs ?? 1e4);
94
+ child.stdout?.on("data", (chunk) => {
95
+ stdout += chunk;
96
+ });
97
+ child.stderr?.on("data", (chunk) => {
98
+ stderr += chunk;
99
+ });
100
+ child.on("error", (error) => {
101
+ stderr += error.message;
102
+ });
103
+ child.on("close", (code) => {
104
+ clearTimeout(timer);
105
+ resolve({ code, stdout, stderr, timedOut });
106
+ });
107
+ });
108
+ }
109
+ async function fromShell(env) {
110
+ const shell = env.SHELL;
111
+ if (!shell || process.platform === "win32") return null;
112
+ for (const flags of ["-lc", "-ilc"]) {
113
+ const result = await run(shell, [flags, "command -v typst"], {
114
+ env,
115
+ timeoutMs: 4e3
116
+ });
117
+ const line = result.stdout.split(/\r?\n/).map((entry) => entry.trim()).reverse().find((entry) => isAbsolute(entry));
118
+ if (line && await executable(line)) return line;
119
+ }
120
+ return null;
121
+ }
122
+ async function locateTypst(options = {}) {
123
+ const env = options.env ?? process.env;
124
+ const platform = options.platform ?? process.platform;
125
+ const home = options.home ?? env.HOME ?? env.USERPROFILE ?? "";
126
+ const names = platform === "win32" ? ["typst.exe", "typst.cmd", "typst"] : ["typst"];
127
+ let found = null;
128
+ if (options.setting) {
129
+ if (!await executable(options.setting)) {
130
+ return {
131
+ state: "error",
132
+ path: options.setting,
133
+ source: "setting",
134
+ error: `The Typst path in the plugin settings (${options.setting}) is not an executable file.`
135
+ };
136
+ }
137
+ found = { path: options.setting, source: "setting" };
138
+ }
139
+ const search = async (dirs, source) => {
140
+ for (const dir of dirs) {
141
+ for (const name of names) {
142
+ const path = join(dir, name);
143
+ if (dir && await executable(path)) return { path, source };
144
+ }
145
+ }
146
+ return null;
147
+ };
148
+ found ??= await search(
149
+ (env.PATH ?? env.Path ?? "").split(delimiter).filter(Boolean),
150
+ "path"
151
+ );
152
+ found ??= await search(
153
+ options.common ?? commonDirs(platform, env, home),
154
+ "common"
155
+ );
156
+ if (!found && options.shell !== false) {
157
+ const path = await fromShell(env);
158
+ if (path) found = { path, source: "shell" };
159
+ }
160
+ if (!found) return { state: "missing" };
161
+ const result = await run(found.path, ["--version"], {
162
+ env,
163
+ timeoutMs: 1e4
164
+ });
165
+ const version = parseVersion(`${result.stdout}
166
+ ${result.stderr}`);
167
+ if (result.code !== 0 || !version) {
168
+ return {
169
+ state: "error",
170
+ ...found,
171
+ error: `\`${found.path} --version\` failed: ${(result.stderr || result.stdout).trim().slice(0, 300) || `exit code ${result.code}`}`
172
+ };
173
+ }
174
+ if (compareVersion(version, MIN_TYPST) < 0) {
175
+ return {
176
+ state: "too_old",
177
+ ...found,
178
+ version: versionText(version),
179
+ error: `Typst ${versionText(version)} is older than ${versionText(MIN_TYPST)}.`
180
+ };
181
+ }
182
+ return { state: "ready", ...found, version: versionText(version) };
183
+ }
184
+ export {
185
+ atLeast,
186
+ commonDirs,
187
+ compareVersion,
188
+ locateTypst,
189
+ parseVersion,
190
+ run,
191
+ searchedDirs,
192
+ versionText
193
+ };
194
+ //# sourceMappingURL=locate.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/typst/locate.ts"],
4
+ "sourcesContent": ["/**\n * Locating and version-checking the typst binary: the configured path, then\n * PATH, then common install locations, then the login shell (version\n * managers). Ported from the ZCode typst-workbench server (0.2.0)\n * `src/typst/locate.ts`. Host half only.\n * @module dsh-typst/typst/locate\n */\n\nimport { spawn } from \"node:child_process\";\nimport { access, constants, stat } from \"node:fs/promises\";\nimport { delimiter, isAbsolute, join, sep } from \"node:path\";\nimport { MIN_TYPST } from \"../constants.js\";\nimport type { TypstSource } from \"../contract.js\";\n\n/** Parse `typst 0.13.1`-style version output. */\nexport function parseVersion(text: string): [number, number, number] | null {\n const match =\n /(?:^|\\s)typst\\s+v?(\\d+)\\.(\\d+)\\.(\\d+)/i.exec(text) ??\n /(\\d+)\\.(\\d+)\\.(\\d+)/.exec(text);\n return match ? [Number(match[1]), Number(match[2]), Number(match[3])] : null;\n}\n\nexport function compareVersion(\n a: readonly number[],\n b: readonly number[],\n): number {\n for (let index = 0; index < 3; index++) {\n if (a[index] !== b[index]) return a[index] - b[index];\n }\n return 0;\n}\n\nexport const versionText = (version: readonly number[]): string =>\n version.join(\".\");\n\nexport function atLeast(version: string, required: readonly number[]): boolean {\n const parsed = version ? parseVersion(version) : null;\n return !!parsed && compareVersion(parsed, required) >= 0;\n}\n\n/** Common typst install directories per platform. */\nexport function commonDirs(\n platform: string,\n env: NodeJS.ProcessEnv,\n home: string,\n): string[] {\n if (platform === \"win32\") {\n const local = env.LOCALAPPDATA ?? join(home, \"AppData\", \"Local\");\n return [\n join(local, \"Microsoft\", \"WinGet\", \"Links\"),\n join(local, \"Programs\", \"typst\"),\n join(home, \".cargo\", \"bin\"),\n join(home, \"scoop\", \"shims\"),\n join(env.ProgramData ?? \"C:\\\\ProgramData\", \"chocolatey\", \"bin\"),\n ];\n }\n return [\n \"/opt/homebrew/bin\",\n \"/usr/local/bin\",\n join(home, \".cargo\", \"bin\"),\n join(home, \".local\", \"bin\"),\n join(home, \"bin\"),\n join(home, \".nix-profile\", \"bin\"),\n \"/run/current-system/sw/bin\",\n \"/nix/var/nix/profiles/default/bin\",\n \"/snap/bin\",\n \"/usr/bin\",\n ];\n}\n\n/**\n * The directories the lookup covers, in report order (for the setup page's\n * \"where we looked\" list), `~`-abbreviated.\n */\nexport function searchedDirs(\n platform: string,\n env: NodeJS.ProcessEnv,\n home: string,\n arch: string = process.arch,\n): string[] {\n const dirs = commonDirs(platform, env, home);\n const first =\n platform === \"win32\"\n ? [dirs[0], join(home, \".cargo\", \"bin\")]\n : platform === \"darwin\"\n ? [\n arch === \"arm64\" ? \"/opt/homebrew/bin\" : \"/usr/local/bin\",\n join(home, \".cargo\", \"bin\"),\n ]\n : [join(home, \".cargo\", \"bin\"), join(home, \".local\", \"bin\")];\n const ordered = [...new Set([...first, ...dirs])];\n return ordered.map((dir) =>\n home && dir.startsWith(home + sep) ? `~${dir.slice(home.length)}` : dir,\n );\n}\n\nasync function executable(path: string): Promise<boolean> {\n try {\n const info = await stat(path);\n if (!info.isFile()) return false;\n await access(\n path,\n process.platform === \"win32\" ? constants.F_OK : constants.X_OK,\n );\n return true;\n } catch {\n return false;\n }\n}\n\nexport interface RunResult {\n code: number | null;\n stdout: string;\n stderr: string;\n timedOut: boolean;\n}\n\n/** Run a short-lived command to completion, capturing both streams. */\nexport function run(\n command: string,\n args: string[],\n options: { cwd?: string; env?: NodeJS.ProcessEnv; timeoutMs?: number } = {},\n): Promise<RunResult> {\n return new Promise((resolve) => {\n let stdout = \"\";\n let stderr = \"\";\n let timedOut = false;\n let child: import(\"node:child_process\").ChildProcess;\n try {\n child = spawn(command, args, {\n cwd: options.cwd,\n env: options.env ?? process.env,\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n windowsHide: true,\n });\n } catch (error) {\n resolve({\n code: null,\n stdout,\n stderr: error instanceof Error ? error.message : String(error),\n timedOut,\n });\n return;\n }\n const timer = setTimeout(() => {\n timedOut = true;\n child.kill(\"SIGKILL\");\n }, options.timeoutMs ?? 10_000);\n child.stdout?.on(\"data\", (chunk: Buffer) => {\n stdout += chunk;\n });\n child.stderr?.on(\"data\", (chunk: Buffer) => {\n stderr += chunk;\n });\n child.on(\"error\", (error: Error) => {\n stderr += error.message;\n });\n child.on(\"close\", (code) => {\n clearTimeout(timer);\n resolve({ code, stdout, stderr, timedOut });\n });\n });\n}\n\n/** Ask the login shell where typst is (mise/asdf and friends). */\nasync function fromShell(env: NodeJS.ProcessEnv): Promise<string | null> {\n const shell = env.SHELL;\n if (!shell || process.platform === \"win32\") return null;\n for (const flags of [\"-lc\", \"-ilc\"]) {\n const result = await run(shell, [flags, \"command -v typst\"], {\n env,\n timeoutMs: 4_000,\n });\n const line = result.stdout\n .split(/\\r?\\n/)\n .map((entry) => entry.trim())\n .reverse()\n .find((entry) => isAbsolute(entry));\n if (line && (await executable(line))) return line;\n }\n return null;\n}\n\nexport type Toolchain =\n | { state: \"ready\"; path: string; source: TypstSource; version: string }\n | { state: \"missing\" }\n | {\n state: \"too_old\";\n path: string;\n source: TypstSource;\n version: string;\n error: string;\n }\n | { state: \"error\"; path?: string; source?: TypstSource; error: string };\n\nexport interface LocateOptions {\n /** The configured \"Typst path\" setting; wins when executable. */\n setting?: string;\n env?: NodeJS.ProcessEnv;\n platform?: string;\n home?: string;\n /** Directory list overriding the common defaults (tests). */\n common?: string[];\n /** Skip the login-shell probe (the panel's periodic recheck does). */\n shell?: boolean;\n}\n\n/**\n * Locate a usable typst and check its version.\n * @returns the toolchain state; `ready` carries path/source/version.\n */\nexport async function locateTypst(\n options: LocateOptions = {},\n): Promise<Toolchain> {\n const env = options.env ?? process.env;\n const platform = options.platform ?? process.platform;\n const home = options.home ?? env.HOME ?? env.USERPROFILE ?? \"\";\n const names =\n platform === \"win32\" ? [\"typst.exe\", \"typst.cmd\", \"typst\"] : [\"typst\"];\n let found: { path: string; source: TypstSource } | null = null;\n if (options.setting) {\n if (!(await executable(options.setting))) {\n return {\n state: \"error\",\n path: options.setting,\n source: \"setting\",\n error: `The Typst path in the plugin settings (${options.setting}) is not an executable file.`,\n };\n }\n found = { path: options.setting, source: \"setting\" };\n }\n const search = async (\n dirs: string[],\n source: TypstSource,\n ): Promise<typeof found> => {\n for (const dir of dirs) {\n for (const name of names) {\n const path = join(dir, name);\n if (dir && (await executable(path))) return { path, source };\n }\n }\n return null;\n };\n found ??= await search(\n (env.PATH ?? env.Path ?? \"\").split(delimiter).filter(Boolean),\n \"path\",\n );\n found ??= await search(\n options.common ?? commonDirs(platform, env, home),\n \"common\",\n );\n if (!found && options.shell !== false) {\n const path = await fromShell(env);\n if (path) found = { path, source: \"shell\" };\n }\n if (!found) return { state: \"missing\" };\n const result = await run(found.path, [\"--version\"], {\n env,\n timeoutMs: 10_000,\n });\n const version = parseVersion(`${result.stdout}\\n${result.stderr}`);\n if (result.code !== 0 || !version) {\n return {\n state: \"error\",\n ...found,\n error: `\\`${found.path} --version\\` failed: ${(result.stderr || result.stdout).trim().slice(0, 300) || `exit code ${result.code}`}`,\n };\n }\n if (compareVersion(version, MIN_TYPST) < 0) {\n return {\n state: \"too_old\",\n ...found,\n version: versionText(version),\n error: `Typst ${versionText(version)} is older than ${versionText(MIN_TYPST)}.`,\n };\n }\n return { state: \"ready\", ...found, version: versionText(version) };\n}\n"],
5
+ "mappings": "AAQA,SAAS,aAAa;AACtB,SAAS,QAAQ,WAAW,YAAY;AACxC,SAAS,WAAW,YAAY,MAAM,WAAW;AACjD,SAAS,iBAAiB;AAInB,SAAS,aAAa,MAA+C;AAC1E,QAAM,QACJ,yCAAyC,KAAK,IAAI,KAClD,sBAAsB,KAAK,IAAI;AACjC,SAAO,QAAQ,CAAC,OAAO,MAAM,CAAC,CAAC,GAAG,OAAO,MAAM,CAAC,CAAC,GAAG,OAAO,MAAM,CAAC,CAAC,CAAC,IAAI;AAC1E;AAEO,SAAS,eACd,GACA,GACQ;AACR,WAAS,QAAQ,GAAG,QAAQ,GAAG,SAAS;AACtC,QAAI,EAAE,KAAK,MAAM,EAAE,KAAK,EAAG,QAAO,EAAE,KAAK,IAAI,EAAE,KAAK;AAAA,EACtD;AACA,SAAO;AACT;AAEO,MAAM,cAAc,CAAC,YAC1B,QAAQ,KAAK,GAAG;AAEX,SAAS,QAAQ,SAAiB,UAAsC;AAC7E,QAAM,SAAS,UAAU,aAAa,OAAO,IAAI;AACjD,SAAO,CAAC,CAAC,UAAU,eAAe,QAAQ,QAAQ,KAAK;AACzD;AAGO,SAAS,WACd,UACA,KACA,MACU;AACV,MAAI,aAAa,SAAS;AACxB,UAAM,QAAQ,IAAI,gBAAgB,KAAK,MAAM,WAAW,OAAO;AAC/D,WAAO;AAAA,MACL,KAAK,OAAO,aAAa,UAAU,OAAO;AAAA,MAC1C,KAAK,OAAO,YAAY,OAAO;AAAA,MAC/B,KAAK,MAAM,UAAU,KAAK;AAAA,MAC1B,KAAK,MAAM,SAAS,OAAO;AAAA,MAC3B,KAAK,IAAI,eAAe,mBAAmB,cAAc,KAAK;AAAA,I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AM,SAAS,MAAM,IAAI,MAAM,MAAM,CAAC,WAAW,GAAG;AAAA,IAClD;AAAA,IACA,WAAW;AAAA,EACb,CAAC;AACD,QAAM,UAAU,aAAa,GAAG,OAAO,MAAM;AAAA,EAAK,OAAO,MAAM,EAAE;AACjE,MAAI,OAAO,SAAS,KAAK,CAAC,SAAS;AACjC,WAAO;AAAA,MACL,OAAO;AAAA,MACP,GAAG;AAAA,MACH,OAAO,KAAK,MAAM,IAAI,yBAAyB,OAAO,UAAU,OAAO,QAAQ,KAAK,EAAE,MAAM,GAAG,GAAG,KAAK,aAAa,OAAO,IAAI,EAAE;AAAA,IACnI;AAAA,EACF;AACA,MAAI,eAAe,SAAS,SAAS,IAAI,GAAG;AAC1C,WAAO;AAAA,MACL,OAAO;AAAA,MACP,GAAG;AAAA,MACH,SAAS,YAAY,OAAO;AAAA,MAC5B,OAAO,SAAS,YAAY,OAAO,CAAC,kBAAkB,YAAY,SAAS,CAAC;AAAA,IAC9E;AAAA,EACF;AACA,SAAO,EAAE,OAAO,SAAS,GAAG,OAAO,SAAS,YAAY,OAAO,EAAE;AACnE;",
6
+ "names": []
7
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Main-file discovery: scan the workspace for `.typ` files and pick the one
3
+ * the user would pass to `typst compile`. Ported from the ZCode
4
+ * typst-workbench server (0.2.0) `src/domain/project.ts`. Host half only.
5
+ * @module dsh-typst/typst/mainfile
6
+ */
7
+ /**
8
+ * Pick the main file: a remembered choice, `main.typ`, the only top-level
9
+ * file, the shallowest `main.typ`, or — when there is exactly one candidate —
10
+ * that file. `null` means the panel should ask.
11
+ * @param candidates - workspace-relative `.typ` paths.
12
+ * @param remembered - the previously chosen main file for this workspace.
13
+ */
14
+ export declare function chooseMain(candidates: string[], remembered: string | null): string | null;
15
+ /** Cancellable complete index; exclusions are explicit rather than hidden scan limits. */
16
+ export declare function indexTypFiles(root: string, includeExcluded: boolean, signal: AbortSignal): AsyncIterable<{
17
+ files: string[];
18
+ visited: number;
19
+ errors: string[];
20
+ }>;
21
+ //# sourceMappingURL=mainfile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mainfile.d.ts","sourceRoot":"","sources":["../../src/typst/mainfile.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAcH;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,UAAU,EAAE,MAAM,EAAE,EACpB,UAAU,EAAE,MAAM,GAAG,IAAI,GACxB,MAAM,GAAG,IAAI,CAiBf;AAED,0FAA0F;AAC1F,wBAAuB,aAAa,CAClC,IAAI,EAAE,MAAM,EACZ,eAAe,EAAE,OAAO,EACxB,MAAM,EAAE,WAAW,GAClB,aAAa,CAAC;IAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CAqCvE"}
@@ -0,0 +1,64 @@
1
+ import { readdir } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ const SKIP = /* @__PURE__ */ new Set([
4
+ "node_modules",
5
+ "target",
6
+ "__pycache__",
7
+ "venv",
8
+ "build",
9
+ "dist"
10
+ ]);
11
+ function chooseMain(candidates, remembered) {
12
+ if (remembered && candidates.includes(remembered)) return remembered;
13
+ if (candidates.includes("main.typ")) return "main.typ";
14
+ const top = candidates.filter((path) => !path.includes("/"));
15
+ if (top.length === 1) return top[0];
16
+ const mains = candidates.filter(
17
+ (path) => path.split("/").pop() === "main.typ"
18
+ );
19
+ if (mains.length) {
20
+ const shallowest = Math.min(...mains.map((path) => path.split("/").length));
21
+ const atDepth = mains.filter(
22
+ (path) => path.split("/").length === shallowest
23
+ );
24
+ if (atDepth.length === 1) return atDepth[0];
25
+ }
26
+ if (candidates.length === 1) return candidates[0];
27
+ return null;
28
+ }
29
+ async function* indexTypFiles(root, includeExcluded, signal) {
30
+ const files = [];
31
+ const errors = [];
32
+ const queue = [{ dir: root, rel: "" }];
33
+ let visited = 0;
34
+ while (queue.length) {
35
+ signal.throwIfAborted();
36
+ const current = queue.shift();
37
+ let entries;
38
+ try {
39
+ entries = await readdir(current.dir, { withFileTypes: true });
40
+ } catch (error) {
41
+ errors.push(`${current.rel || "."}: ${String(error)}`);
42
+ yield { files: [...files], visited, errors: [...errors] };
43
+ continue;
44
+ }
45
+ entries.sort((a, b) => a.name.localeCompare(b.name));
46
+ for (const entry of entries) {
47
+ signal.throwIfAborted();
48
+ visited++;
49
+ const path = current.rel ? `${current.rel}/${entry.name}` : entry.name;
50
+ if (entry.isDirectory() && (includeExcluded || !entry.name.startsWith(".") && !SKIP.has(entry.name)))
51
+ queue.push({ dir: join(current.dir, entry.name), rel: path });
52
+ else if ((entry.isFile() || entry.isSymbolicLink()) && entry.name.endsWith(".typ"))
53
+ files.push(path);
54
+ if (visited % 128 === 0)
55
+ yield { files: [...files], visited, errors: [...errors] };
56
+ }
57
+ yield { files: [...files], visited, errors: [...errors] };
58
+ }
59
+ }
60
+ export {
61
+ chooseMain,
62
+ indexTypFiles
63
+ };
64
+ //# sourceMappingURL=mainfile.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/typst/mainfile.ts"],
4
+ "sourcesContent": ["/**\n * Main-file discovery: scan the workspace for `.typ` files and pick the one\n * the user would pass to `typst compile`. Ported from the ZCode\n * typst-workbench server (0.2.0) `src/domain/project.ts`. Host half only.\n * @module dsh-typst/typst/mainfile\n */\n\nimport { readdir } from \"node:fs/promises\";\nimport { join } from \"node:path\";\n\nconst SKIP = new Set([\n \"node_modules\",\n \"target\",\n \"__pycache__\",\n \"venv\",\n \"build\",\n \"dist\",\n]);\n\n/**\n * Pick the main file: a remembered choice, `main.typ`, the only top-level\n * file, the shallowest `main.typ`, or \u2014 when there is exactly one candidate \u2014\n * that file. `null` means the panel should ask.\n * @param candidates - workspace-relative `.typ` paths.\n * @param remembered - the previously chosen main file for this workspace.\n */\nexport function chooseMain(\n candidates: string[],\n remembered: string | null,\n): string | null {\n if (remembered && candidates.includes(remembered)) return remembered;\n if (candidates.includes(\"main.typ\")) return \"main.typ\";\n const top = candidates.filter((path) => !path.includes(\"/\"));\n if (top.length === 1) return top[0];\n const mains = candidates.filter(\n (path) => path.split(\"/\").pop() === \"main.typ\",\n );\n if (mains.length) {\n const shallowest = Math.min(...mains.map((path) => path.split(\"/\").length));\n const atDepth = mains.filter(\n (path) => path.split(\"/\").length === shallowest,\n );\n if (atDepth.length === 1) return atDepth[0];\n }\n if (candidates.length === 1) return candidates[0];\n return null;\n}\n\n/** Cancellable complete index; exclusions are explicit rather than hidden scan limits. */\nexport async function* indexTypFiles(\n root: string,\n includeExcluded: boolean,\n signal: AbortSignal,\n): AsyncIterable<{ files: string[]; visited: number; errors: string[] }> {\n const files: string[] = [];\n const errors: string[] = [];\n const queue = [{ dir: root, rel: \"\" }];\n let visited = 0;\n while (queue.length) {\n signal.throwIfAborted();\n const current = queue.shift()!;\n let entries: import(\"node:fs\").Dirent[];\n try {\n entries = await readdir(current.dir, { withFileTypes: true });\n } catch (error) {\n errors.push(`${current.rel || \".\"}: ${String(error)}`);\n yield { files: [...files], visited, errors: [...errors] };\n continue;\n }\n entries.sort((a, b) => a.name.localeCompare(b.name));\n for (const entry of entries) {\n signal.throwIfAborted();\n visited++;\n const path = current.rel ? `${current.rel}/${entry.name}` : entry.name;\n if (\n entry.isDirectory() &&\n (includeExcluded ||\n (!entry.name.startsWith(\".\") && !SKIP.has(entry.name)))\n )\n queue.push({ dir: join(current.dir, entry.name), rel: path });\n else if (\n (entry.isFile() || entry.isSymbolicLink()) &&\n entry.name.endsWith(\".typ\")\n )\n files.push(path);\n if (visited % 128 === 0)\n yield { files: [...files], visited, errors: [...errors] };\n }\n yield { files: [...files], visited, errors: [...errors] };\n }\n}\n"],
5
+ "mappings": "AAOA,SAAS,eAAe;AACxB,SAAS,YAAY;AAErB,MAAM,OAAO,oBAAI,IAAI;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAA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ACA,YAAQ,KAAK,CAAC,GAAG,MAAM,EAAE,KAAK,cAAc,EAAE,IAAI,CAAC;AACnD,eAAW,SAAS,SAAS;AAC3B,aAAO,eAAe;AACtB;AACA,YAAM,OAAO,QAAQ,MAAM,GAAG,QAAQ,GAAG,IAAI,MAAM,IAAI,KAAK,MAAM;AAClE,UACE,MAAM,YAAY,MACjB,mBACE,CAAC,MAAM,KAAK,WAAW,GAAG,KAAK,CAAC,KAAK,IAAI,MAAM,IAAI;AAEtD,cAAM,KAAK,EAAE,KAAK,KAAK,QAAQ,KAAK,MAAM,IAAI,GAAG,KAAK,KAAK,CAAC;AAAA,gBAE3D,MAAM,OAAO,KAAK,MAAM,eAAe,MACxC,MAAM,KAAK,SAAS,MAAM;AAE1B,cAAM,KAAK,IAAI;AACjB,UAAI,UAAU,QAAQ;AACpB,cAAM,EAAE,OAAO,CAAC,GAAG,KAAK,GAAG,SAAS,QAAQ,CAAC,GAAG,MAAM,EAAE;AAAA,IAC5D;AACA,UAAM,EAAE,OAAO,CAAC,GAAG,KAAK,GAAG,SAAS,QAAQ,CAAC,GAAG,MAAM,EAAE;AAAA,EAC1D;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Fuzzy text matching between rendered pages and `.typ` sources, plus the
3
+ * line/excerpt helpers the diagnostics and highlights share. Ported from the
4
+ * ZCode typst-workbench server (0.2.0) `src/domain/match.ts`. Host half only
5
+ * (the panel performs its own in-page text search).
6
+ * @module dsh-typst/typst/match
7
+ */
8
+ export interface Skeleton {
9
+ value: string;
10
+ map: number[];
11
+ }
12
+ export interface FuzzyHit {
13
+ start: number;
14
+ end: number;
15
+ score: number;
16
+ }
17
+ /**
18
+ * Fold a text onto its matching skeleton: NFKC + lowercase, letters and
19
+ * numbers only, with an offset map back onto the original string.
20
+ */
21
+ export declare function skeleton(text: string): Skeleton;
22
+ /**
23
+ * Find occurrences of `needle` in a skeleton haystack: exact runs first,
24
+ * then seed-and-chain approximation tolerant of insertions, deletions and
25
+ * reflow. Ported unchanged in behavior; see the ZCode source for the
26
+ * chain-drift rationale.
27
+ */
28
+ export declare function fuzzyFind(needle: string, hay: Skeleton, options?: {
29
+ max?: number;
30
+ minScore?: number;
31
+ }): FuzzyHit[];
32
+ export declare function lineStarts(text: string): number[];
33
+ export declare function lineColumn(starts: number[], offset: number): {
34
+ line: number;
35
+ column: number;
36
+ };
37
+ export declare function lineRange(text: string, starts: number[], from: number, to: number): {
38
+ start: number;
39
+ end: number;
40
+ };
41
+ export declare function excerpt(text: string, from: number, to: number, maxLines?: number): string;
42
+ export interface SourceFile {
43
+ path: string;
44
+ text: string;
45
+ }
46
+ export type { SourceMatch } from "../contract.js";
47
+ import type { SourceMatch } from "../contract.js";
48
+ /**
49
+ * Locate rendered text inside the project's source files: fuzzy-find in
50
+ * every file, optionally re-anchoring around a focus passage, and report
51
+ * the best candidates. Reliable for prose; approximate for math, generated
52
+ * text and function output (the panel says so).
53
+ * @param files - the workspace source files to search.
54
+ * @param text - the rendered text to locate.
55
+ * @param focus - a secondary passage expected near the target, when known.
56
+ * @param max - candidate budget.
57
+ */
58
+ export declare function locateInSources(files: SourceFile[], text: string, focus?: string, max?: number): SourceMatch[];
59
+ //# sourceMappingURL=match.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"match.d.ts","sourceRoot":"","sources":["../../src/typst/match.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,EAAE,CAAC;CACf;AAED,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACf;AAID;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAe/C;AAID;;;;;GAKG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,QAAQ,EACb,OAAO,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAO,GAChD,QAAQ,EAAE,CAmGZ;AAMD,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAUjD;AAED,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,EAAE,EAChB,MAAM,EAAE,MAAM,GACb;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CASlC;AAED,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EAAE,EAChB,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,GACT;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAIhC;AAED,wBAAgB,OAAO,CACrB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,QAAQ,SAAI,GACX,MAAM,CASR;AAMD,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,UAAU,EAAE,EACnB,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,MAAM,EACd,GAAG,SAAI,GACN,WAAW,EAAE,CAoCf"}
@@ -0,0 +1,171 @@
1
+ const FOLD = { \u017F: "s", \u0131: "i" };
2
+ function skeleton(text) {
3
+ let value = "";
4
+ const map = [];
5
+ let index = 0;
6
+ for (const char of text) {
7
+ const folded = (FOLD[char] ?? char).normalize("NFKC").toLowerCase();
8
+ for (const part of folded) {
9
+ if (/[\p{L}\p{N}]/u.test(part)) {
10
+ value += part;
11
+ map.push(index);
12
+ }
13
+ }
14
+ index += char.length;
15
+ }
16
+ return { value, map };
17
+ }
18
+ const SEED = 8;
19
+ function fuzzyFind(needle, hay, options = {}) {
20
+ const max = options.max ?? 5;
21
+ const target = skeleton(needle).value;
22
+ if (target.length < 2 || !hay.value.length) return [];
23
+ const toHit = (from, to, score) => ({
24
+ start: hay.map[from],
25
+ end: hay.map[to - 1] + 1,
26
+ score
27
+ });
28
+ const exact = [];
29
+ for (let at = hay.value.indexOf(target); at >= 0 && exact.length < max; at = hay.value.indexOf(target, at + 1)) {
30
+ exact.push(toHit(at, at + target.length, 1));
31
+ }
32
+ if (exact.length || target.length < SEED * 2) return exact;
33
+ const step = SEED / 2;
34
+ const seeds = [];
35
+ for (let offset = 0; offset + SEED <= target.length; offset += step) {
36
+ const gram = target.slice(offset, offset + SEED);
37
+ const positions = [];
38
+ for (let at = hay.value.indexOf(gram); at >= 0 && positions.length < 64; at = hay.value.indexOf(gram, at + 1)) {
39
+ positions.push(at);
40
+ }
41
+ seeds.push({ offset, positions });
42
+ }
43
+ const tailOffset = target.length - SEED;
44
+ if (seeds.at(-1).offset !== tailOffset) {
45
+ const gram = target.slice(tailOffset);
46
+ const positions = [];
47
+ for (let at = hay.value.indexOf(gram); at >= 0 && positions.length < 64; at = hay.value.indexOf(gram, at + 1)) {
48
+ positions.push(at);
49
+ }
50
+ seeds.push({ offset: tailOffset, positions });
51
+ }
52
+ const chains = [];
53
+ for (const seed of seeds) {
54
+ for (const at of seed.positions) {
55
+ let best = null;
56
+ for (const chain of chains) {
57
+ const needleGap = seed.offset - chain.last.offset;
58
+ const hayGap = at - chain.last.at;
59
+ if (needleGap <= 0 || hayGap <= 0) continue;
60
+ const drift = hayGap - needleGap;
61
+ if (drift < -Math.max(24, needleGap) || drift > 160 + needleGap * 2)
62
+ continue;
63
+ if (!best || chain.covered > best.covered) best = chain;
64
+ }
65
+ const gain = (from) => Math.min(SEED, seed.offset + SEED - from);
66
+ if (best) {
67
+ best.covered += gain(best.last.offset + SEED);
68
+ best.last = { offset: seed.offset, at };
69
+ } else {
70
+ chains.push({
71
+ first: { offset: seed.offset, at },
72
+ last: { offset: seed.offset, at },
73
+ covered: SEED
74
+ });
75
+ }
76
+ }
77
+ }
78
+ const minScore = options.minScore ?? 0.35;
79
+ const results = chains.map((chain) => ({
80
+ chain,
81
+ score: Math.min(1, chain.covered / target.length)
82
+ })).filter(
83
+ ({ chain, score }) => score >= minScore && chain.covered >= SEED * 2
84
+ ).sort((a, b) => b.score - a.score || a.chain.first.at - b.chain.first.at);
85
+ const hits = [];
86
+ for (const { chain, score } of results) {
87
+ const from = Math.max(0, chain.first.at - chain.first.offset);
88
+ const to = Math.min(
89
+ hay.value.length,
90
+ chain.last.at + SEED + (target.length - chain.last.offset - SEED)
91
+ );
92
+ const hit = toHit(from, Math.max(to, from + 1), score);
93
+ if (hits.some((other) => other.start < hit.end && hit.start < other.end))
94
+ continue;
95
+ hits.push(hit);
96
+ if (hits.length >= max) break;
97
+ }
98
+ return hits;
99
+ }
100
+ function lineStarts(text) {
101
+ const starts = [0];
102
+ for (let index = text.indexOf("\n"); index >= 0; index = text.indexOf("\n", index + 1)) {
103
+ starts.push(index + 1);
104
+ }
105
+ return starts;
106
+ }
107
+ function lineColumn(starts, offset) {
108
+ let low = 0;
109
+ let high = starts.length - 1;
110
+ while (low < high) {
111
+ const middle = low + high + 1 >> 1;
112
+ if (starts[middle] <= offset) low = middle;
113
+ else high = middle - 1;
114
+ }
115
+ return { line: low + 1, column: offset - starts[low] + 1 };
116
+ }
117
+ function lineRange(text, starts, from, to) {
118
+ const start = starts[Math.max(1, from) - 1] ?? text.length;
119
+ const next = starts[Math.min(to, starts.length)];
120
+ return { start, end: next === void 0 ? text.length : next - 1 };
121
+ }
122
+ function excerpt(text, from, to, maxLines = 8) {
123
+ const lines = text.split("\n").slice(from - 1, Math.min(to, from + maxLines - 1));
124
+ const more = to - from + 1 > maxLines ? `
125
+ \u2026 (${to - from + 1 - maxLines} more lines)` : "";
126
+ return lines.join("\n").replace(/\s+$/, "") + more;
127
+ }
128
+ function locateInSources(files, text, focus, max = 3) {
129
+ const candidates = [];
130
+ for (const file of files) {
131
+ const hay = skeleton(file.text);
132
+ const starts = lineStarts(file.text);
133
+ for (const hit of fuzzyFind(text, hay, { max })) {
134
+ let { start, end } = hit;
135
+ if (focus && skeleton(focus).value.length >= 2) {
136
+ const windowStart = Math.max(0, start - 400);
137
+ const windowText = file.text.slice(
138
+ windowStart,
139
+ Math.min(file.text.length, end + 400)
140
+ );
141
+ const inner = fuzzyFind(focus, skeleton(windowText), { max: 1 })[0];
142
+ if (inner) {
143
+ start = windowStart + inner.start;
144
+ end = windowStart + inner.end;
145
+ }
146
+ }
147
+ const from = lineColumn(starts, start);
148
+ const to = lineColumn(starts, Math.max(start, end - 1));
149
+ candidates.push({
150
+ file: file.path,
151
+ line: from.line,
152
+ column: from.column,
153
+ endLine: to.line,
154
+ excerpt: excerpt(file.text, from.line, to.line),
155
+ score: hit.score,
156
+ start
157
+ });
158
+ }
159
+ }
160
+ return candidates.sort((a, b) => b.score - a.score).slice(0, max).map(({ start: _start, ...rest }) => rest);
161
+ }
162
+ export {
163
+ excerpt,
164
+ fuzzyFind,
165
+ lineColumn,
166
+ lineRange,
167
+ lineStarts,
168
+ locateInSources,
169
+ skeleton
170
+ };
171
+ //# sourceMappingURL=match.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/typst/match.ts"],
4
+ "sourcesContent": ["/**\n * Fuzzy text matching between rendered pages and `.typ` sources, plus the\n * line/excerpt helpers the diagnostics and highlights share. Ported from the\n * ZCode typst-workbench server (0.2.0) `src/domain/match.ts`. Host half only\n * (the panel performs its own in-page text search).\n * @module dsh-typst/typst/match\n */\n\nexport interface Skeleton {\n value: string;\n map: number[];\n}\n\nexport interface FuzzyHit {\n start: number;\n end: number;\n score: number;\n}\n\nconst FOLD: Record<string, string> = { \u017F: \"s\", \u0131: \"i\" };\n\n/**\n * Fold a text onto its matching skeleton: NFKC + lowercase, letters and\n * numbers only, with an offset map back onto the original string.\n */\nexport function skeleton(text: string): Skeleton {\n let value = \"\";\n const map: number[] = [];\n let index = 0;\n for (const char of text) {\n const folded = (FOLD[char] ?? char).normalize(\"NFKC\").toLowerCase();\n for (const part of folded) {\n if (/[\\p{L}\\p{N}]/u.test(part)) {\n value += part;\n map.push(index);\n }\n }\n index += char.length;\n }\n return { value, map };\n}\n\nconst SEED = 8;\n\n/**\n * Find occurrences of `needle` in a skeleton haystack: exact runs first,\n * then seed-and-chain approximation tolerant of insertions, deletions and\n * reflow. Ported unchanged in behavior; see the ZCode source for the\n * chain-drift rationale.\n */\nexport function fuzzyFind(\n needle: string,\n hay: Skeleton,\n options: { max?: number; minScore?: number } = {},\n): FuzzyHit[] {\n const max = options.max ?? 5;\n const target = skeleton(needle).value;\n if (target.length < 2 || !hay.value.length) return [];\n const toHit = (from: number, to: number, score: number): FuzzyHit => ({\n start: hay.map[from],\n end: hay.map[to - 1] + 1,\n score,\n });\n const exact: FuzzyHit[] = [];\n for (\n let at = hay.value.indexOf(target);\n at >= 0 && exact.length < max;\n at = hay.value.indexOf(target, at + 1)\n ) {\n exact.push(toHit(at, at + target.length, 1));\n }\n if (exact.length || target.length < SEED * 2) return exact;\n const step = SEED / 2;\n const seeds: { offset: number; positions: number[] }[] = [];\n for (let offset = 0; offset + SEED <= target.length; offset += step) {\n const gram = target.slice(offset, offset + SEED);\n const positions: number[] = [];\n for (\n let at = hay.value.indexOf(gram);\n at >= 0 && positions.length < 64;\n at = hay.value.indexOf(gram, at + 1)\n ) {\n positions.push(at);\n }\n seeds.push({ offset, positions });\n }\n const tailOffset = target.length - SEED;\n if (seeds.at(-1)!.offset !== tailOffset) {\n const gram = target.slice(tailOffset);\n const positions: number[] = [];\n for (\n let at = hay.value.indexOf(gram);\n at >= 0 && positions.length < 64;\n at = hay.value.indexOf(gram, at + 1)\n ) {\n positions.push(at);\n }\n seeds.push({ offset: tailOffset, positions });\n }\n const chains: {\n first: { offset: number; at: number };\n last: { offset: number; at: number };\n covered: number;\n }[] = [];\n for (const seed of seeds) {\n for (const at of seed.positions) {\n let best: (typeof chains)[number] | null = null;\n for (const chain of chains) {\n const needleGap = seed.offset - chain.last.offset;\n const hayGap = at - chain.last.at;\n if (needleGap <= 0 || hayGap <= 0) continue;\n const drift = hayGap - needleGap;\n if (drift < -Math.max(24, needleGap) || drift > 160 + needleGap * 2)\n continue;\n if (!best || chain.covered > best.covered) best = chain;\n }\n const gain = (from: number) => Math.min(SEED, seed.offset + SEED - from);\n if (best) {\n best.covered += gain(best.last.offset + SEED);\n best.last = { offset: seed.offset, at };\n } else {\n chains.push({\n first: { offset: seed.offset, at },\n last: { offset: seed.offset, at },\n covered: SEED,\n });\n }\n }\n }\n const minScore = options.minScore ?? 0.35;\n const results = chains\n .map((chain) => ({\n chain,\n score: Math.min(1, chain.covered / target.length),\n }))\n .filter(\n ({ chain, score }) => score >= minScore && chain.covered >= SEED * 2,\n )\n .sort((a, b) => b.score - a.score || a.chain.first.at - b.chain.first.at);\n const hits: FuzzyHit[] = [];\n for (const { chain, score } of results) {\n const from = Math.max(0, chain.first.at - chain.first.offset);\n const to = Math.min(\n hay.value.length,\n chain.last.at + SEED + (target.length - chain.last.offset - SEED),\n );\n const hit = toHit(from, Math.max(to, from + 1), score);\n if (hits.some((other) => other.start < hit.end && hit.start < other.end))\n continue;\n hits.push(hit);\n if (hits.length >= max) break;\n }\n return hits;\n}\n\n// ---------------------------------------------------------------------------\n// Line helpers (shared by diagnostics excerpts and source location)\n// ---------------------------------------------------------------------------\n\nexport function lineStarts(text: string): number[] {\n const starts = [0];\n for (\n let index = text.indexOf(\"\\n\");\n index >= 0;\n index = text.indexOf(\"\\n\", index + 1)\n ) {\n starts.push(index + 1);\n }\n return starts;\n}\n\nexport function lineColumn(\n starts: number[],\n offset: number,\n): { line: number; column: number } {\n let low = 0;\n let high = starts.length - 1;\n while (low < high) {\n const middle = (low + high + 1) >> 1;\n if (starts[middle] <= offset) low = middle;\n else high = middle - 1;\n }\n return { line: low + 1, column: offset - starts[low] + 1 };\n}\n\nexport function lineRange(\n text: string,\n starts: number[],\n from: number,\n to: number,\n): { start: number; end: number } {\n const start = starts[Math.max(1, from) - 1] ?? text.length;\n const next = starts[Math.min(to, starts.length)];\n return { start, end: next === undefined ? text.length : next - 1 };\n}\n\nexport function excerpt(\n text: string,\n from: number,\n to: number,\n maxLines = 8,\n): string {\n const lines = text\n .split(\"\\n\")\n .slice(from - 1, Math.min(to, from + maxLines - 1));\n const more =\n to - from + 1 > maxLines\n ? `\\n\\u2026 (${to - from + 1 - maxLines} more lines)`\n : \"\";\n return lines.join(\"\\n\").replace(/\\s+$/, \"\") + more;\n}\n\n// ---------------------------------------------------------------------------\n// Rendered text \u2192 source location\n// ---------------------------------------------------------------------------\n\nexport interface SourceFile {\n path: string;\n text: string;\n}\n\nexport type { SourceMatch } from \"../contract.js\";\nimport type { SourceMatch } from \"../contract.js\";\n\n/**\n * Locate rendered text inside the project's source files: fuzzy-find in\n * every file, optionally re-anchoring around a focus passage, and report\n * the best candidates. Reliable for prose; approximate for math, generated\n * text and function output (the panel says so).\n * @param files - the workspace source files to search.\n * @param text - the rendered text to locate.\n * @param focus - a secondary passage expected near the target, when known.\n * @param max - candidate budget.\n */\nexport function locateInSources(\n files: SourceFile[],\n text: string,\n focus?: string,\n max = 3,\n): SourceMatch[] {\n const candidates: (SourceMatch & { start: number })[] = [];\n for (const file of files) {\n const hay = skeleton(file.text);\n const starts = lineStarts(file.text);\n for (const hit of fuzzyFind(text, hay, { max })) {\n let { start, end } = hit;\n if (focus && skeleton(focus).value.length >= 2) {\n const windowStart = Math.max(0, start - 400);\n const windowText = file.text.slice(\n windowStart,\n Math.min(file.text.length, end + 400),\n );\n const inner = fuzzyFind(focus, skeleton(windowText), { max: 1 })[0];\n if (inner) {\n start = windowStart + inner.start;\n end = windowStart + inner.end;\n }\n }\n const from = lineColumn(starts, start);\n const to = lineColumn(starts, Math.max(start, end - 1));\n candidates.push({\n file: file.path,\n line: from.line,\n column: from.column,\n endLine: to.line,\n excerpt: excerpt(file.text, from.line, to.line),\n score: hit.score,\n start,\n });\n }\n }\n return candidates\n .sort((a, b) => b.score - a.score)\n .slice(0, max)\n .map(({ start: _start, ...rest }) => rest);\n}\n"],
5
+ "mappings": "AAmBA,MAAM,OAA+B,EAAE,QAAG,KAAK,QAAG,IAAI;AAM/C,SAAS,SAAS,MAAwB;AAC/C,MAAI,QAAQ;AACZ,QAAM,MAAgB,CAAC;AACvB,MAAI,QAAQ;AACZ,aAAW,QAAQ,MAAM;AACvB,UAAM,UAAU,KAAK,IAAI,KAAK,MAAM,UAAU,MAAM,EAAE,YAAY;AAClE,eAAW,QAAQ,QAAQ;AACzB,UAAI,gBAAgB,KAAK,IAAI,GAAG;AAC9B,iBAAS;AACT,YAAI,KAAK,KAAK;AAAA,MAChB;AAAA,IACF;AACA,aAAS,KAAK;AAAA,EAChB;AACA,SAAO,EAAE,OAAO,IAAI;AACtB;AAEA,MAAM,OAAO;AAQN,SAAS,UACd,QACA,KACA,UAA+C,CAAC,GACpC;AACZ,QAAM,MAAM,QAAQ,OAAO;AAC3B,QAAM,SAAS,SAAS,MAAM,EAAE;AAChC,MAAI,OAAO,SAAS,KAAK,CAAC,IAAI,MAAM,OAAQ,QAAO,CAAC;AACpD,QAAM,QAAQ,CAAC,MAAc,IAAY,WAA6B;AAAA,IACpE,OAAO,IAAI,IAAI,IAAI;AAAA,IACnB,KAAK,IAAI,IAAI,KAAK,CAAC,IAAI;AAAA,IACvB;AAAA,EACF;AACA,QAAM,QAAoB,CAAC;AAC3B,WACM,KAAK,IAAI,MAAM,QAAQ,MAAM,GACjC,MAAM,KAAK,MAAM,SAAS,KAC1B,KAAK,IAAI,MAAM,QAAQ,QAAQ,KAAK,CAAC,GACrC;AACA,UAAM,KAAK,M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O;AACxB,UAAM,MAAM,SAAS,KAAK,IAAI;AAC9B,UAAM,SAAS,WAAW,KAAK,IAAI;AACnC,eAAW,OAAO,UAAU,MAAM,KAAK,EAAE,IAAI,CAAC,GAAG;AAC/C,UAAI,EAAE,OAAO,IAAI,IAAI;AACrB,UAAI,SAAS,SAAS,KAAK,EAAE,MAAM,UAAU,GAAG;AAC9C,cAAM,cAAc,KAAK,IAAI,GAAG,QAAQ,GAAG;AAC3C,cAAM,aAAa,KAAK,KAAK;AAAA,UAC3B;AAAA,UACA,KAAK,IAAI,KAAK,KAAK,QAAQ,MAAM,GAAG;AAAA,QACtC;AACA,cAAM,QAAQ,UAAU,OAAO,SAAS,UAAU,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;AAClE,YAAI,OAAO;AACT,kBAAQ,cAAc,MAAM;AAC5B,gBAAM,cAAc,MAAM;AAAA,QAC5B;AAAA,MACF;AACA,YAAM,OAAO,WAAW,QAAQ,KAAK;AACrC,YAAM,KAAK,WAAW,QAAQ,KAAK,IAAI,OAAO,MAAM,CAAC,CAAC;AACtD,iBAAW,KAAK;AAAA,QACd,MAAM,KAAK;AAAA,QACX,MAAM,KAAK;AAAA,QACX,QAAQ,KAAK;AAAA,QACb,SAAS,GAAG;AAAA,QACZ,SAAS,QAAQ,KAAK,MAAM,KAAK,MAAM,GAAG,IAAI;AAAA,QAC9C,OAAO,IAAI;AAAA,QACX;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACA,SAAO,WACJ,KAAK,CAAC,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK,EAChC,MAAM,GAAG,GAAG,EACZ,IAAI,CAAC,EAAE,OAAO,QAAQ,GAAG,KAAK,MAAM,IAAI;AAC7C;",
6
+ "names": []
7
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * One-shot typst compiles that do not touch the preview: rendering pages to
3
+ * PNG for the agent to look at, and exporting PDFs into the workspace.
4
+ * Ported from the ZCode typst-workbench server (0.2.0) `src/typst/
5
+ * oneshot.ts`. Host half only.
6
+ * @module dsh-typst/typst/oneshot
7
+ */
8
+ import type { DiagnosticView } from "../contract.js";
9
+ export interface OneshotOptions {
10
+ typst: string;
11
+ cwd: string;
12
+ /** Project sandbox root passed to Typst via `--root`. */
13
+ root?: string;
14
+ /** Extra directories searched recursively for fonts via `--font-path`. */
15
+ fontPaths?: string[];
16
+ main: string;
17
+ env?: NodeJS.ProcessEnv;
18
+ /** Where render scratch directories are created. */
19
+ scratch: string;
20
+ toFile?: (path: string) => string;
21
+ timeoutMs?: number;
22
+ }
23
+ export interface CompileResult {
24
+ ok: boolean;
25
+ diagnostics: DiagnosticView[];
26
+ }
27
+ export interface RenderedImage {
28
+ page: number;
29
+ png: Uint8Array;
30
+ }
31
+ export interface RenderPagesResult extends CompileResult {
32
+ images: RenderedImage[];
33
+ }
34
+ /**
35
+ * Render the given 1-based pages to PNGs in a scratch directory and read
36
+ * them back, page-ordered; the scratch directory is always removed.
37
+ */
38
+ export declare function renderPages(options: OneshotOptions, pages: number[], ppi: number): Promise<RenderPagesResult>;
39
+ export interface ExportExtra {
40
+ pdfStandard?: string;
41
+ pages?: string;
42
+ }
43
+ /** Compile a PDF into the workspace (optionally a PDF standard and a page selection). */
44
+ export declare function exportPdf(options: OneshotOptions, output: string, extra: ExportExtra): Promise<CompileResult>;
45
+ //# sourceMappingURL=oneshot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oneshot.d.ts","sourceRoot":"","sources":["../../src/typst/oneshot.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAQH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,yDAAyD;IACzD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,0EAA0E;IAC1E,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,IA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