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,76 @@
1
+ import { mkdtemp, readdir, readFile, rm } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { LIMITS } from "../constants.js";
4
+ import { TypstError } from "../errors.js";
5
+ import { parseDiagnostics } from "./diagnostics.js";
6
+ import { run } from "./locate.js";
7
+ async function compile(options, output, extra) {
8
+ const rootArgs = options.root ? ["--root", options.root] : [];
9
+ const fontArgs = (options.fontPaths ?? []).flatMap((dir) => [
10
+ "--font-path",
11
+ dir
12
+ ]);
13
+ const result = await run(
14
+ options.typst,
15
+ ["compile", options.main, output, ...extra, ...rootArgs, ...fontArgs],
16
+ {
17
+ cwd: options.cwd,
18
+ env: options.env,
19
+ timeoutMs: options.timeoutMs ?? LIMITS.oneshotTimeoutMs
20
+ }
21
+ );
22
+ if (result.timedOut) {
23
+ throw new TypstError(
24
+ `typst compile did not finish within ${Math.round((options.timeoutMs ?? LIMITS.oneshotTimeoutMs) / 1e3)} s.`,
25
+ "TYPST_TIMEOUT"
26
+ );
27
+ }
28
+ const diagnostics = parseDiagnostics(result.stderr, options.toFile);
29
+ if (result.code !== 0 && !diagnostics.some((entry) => entry.severity === "error")) {
30
+ diagnostics.push({
31
+ severity: "error",
32
+ message: (result.stderr || result.stdout).trim().slice(0, 500) || `typst exited with code ${result.code}`,
33
+ location: null,
34
+ hints: [],
35
+ trace: []
36
+ });
37
+ }
38
+ return { ok: result.code === 0, diagnostics };
39
+ }
40
+ async function renderPages(options, pages, ppi) {
41
+ const dir = await mkdtemp(join(options.scratch, "render-"));
42
+ try {
43
+ const result = await compile(options, join(dir, "page-{p}.png"), [
44
+ "--pages",
45
+ pages.join(","),
46
+ "--ppi",
47
+ String(ppi)
48
+ ]);
49
+ if (!result.ok) return { ...result, images: [] };
50
+ const images = [];
51
+ for (const name of await readdir(dir)) {
52
+ const match = /^page-(\d+)\.png$/.exec(name);
53
+ if (match) {
54
+ images.push({
55
+ page: Number(match[1]),
56
+ png: new Uint8Array(await readFile(join(dir, name)))
57
+ });
58
+ }
59
+ }
60
+ images.sort((a, b) => a.page - b.page);
61
+ return { ...result, images };
62
+ } finally {
63
+ await rm(dir, { recursive: true, force: true });
64
+ }
65
+ }
66
+ async function exportPdf(options, output, extra) {
67
+ const args = [];
68
+ if (extra.pdfStandard) args.push("--pdf-standard", extra.pdfStandard);
69
+ if (extra.pages) args.push("--pages", extra.pages);
70
+ return compile(options, output, args);
71
+ }
72
+ export {
73
+ exportPdf,
74
+ renderPages
75
+ };
76
+ //# sourceMappingURL=oneshot.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/typst/oneshot.ts"],
4
+ "sourcesContent": ["/**\n * One-shot typst compiles that do not touch the preview: rendering pages to\n * PNG for the agent to look at, and exporting PDFs into the workspace.\n * Ported from the ZCode typst-workbench server (0.2.0) `src/typst/\n * oneshot.ts`. Host half only.\n * @module dsh-typst/typst/oneshot\n */\n\nimport { mkdtemp, readdir, readFile, rm } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { LIMITS } from \"../constants.js\";\nimport { TypstError } from \"../errors.js\";\nimport { parseDiagnostics } from \"./diagnostics.js\";\nimport { run } from \"./locate.js\";\nimport type { DiagnosticView } from \"../contract.js\";\n\nexport interface OneshotOptions {\n typst: string;\n cwd: string;\n /** Project sandbox root passed to Typst via `--root`. */\n root?: string;\n /** Extra directories searched recursively for fonts via `--font-path`. */\n fontPaths?: string[];\n main: string;\n env?: NodeJS.ProcessEnv;\n /** Where render scratch directories are created. */\n scratch: string;\n toFile?: (path: string) => string;\n timeoutMs?: number;\n}\n\nexport interface CompileResult {\n ok: boolean;\n diagnostics: DiagnosticView[];\n}\n\nasync function compile(\n options: OneshotOptions,\n output: string,\n extra: string[],\n): Promise<CompileResult> {\n const rootArgs = options.root ? [\"--root\", options.root] : [];\n const fontArgs = (options.fontPaths ?? []).flatMap((dir) => [\n \"--font-path\",\n dir,\n ]);\n const result = await run(\n options.typst,\n [\"compile\", options.main, output, ...extra, ...rootArgs, ...fontArgs],\n {\n cwd: options.cwd,\n env: options.env,\n timeoutMs: options.timeoutMs ?? LIMITS.oneshotTimeoutMs,\n },\n );\n if (result.timedOut) {\n throw new TypstError(\n `typst compile did not finish within ${Math.round((options.timeoutMs ?? LIMITS.oneshotTimeoutMs) / 1e3)} s.`,\n \"TYPST_TIMEOUT\",\n );\n }\n const diagnostics = parseDiagnostics(result.stderr, options.toFile);\n if (\n result.code !== 0 &&\n !diagnostics.some((entry) => entry.severity === \"error\")\n ) {\n diagnostics.push({\n severity: \"error\",\n message:\n (result.stderr || result.stdout).trim().slice(0, 500) ||\n `typst exited with code ${result.code}`,\n location: null,\n hints: [],\n trace: [],\n });\n }\n return { ok: result.code === 0, diagnostics };\n}\n\nexport interface RenderedImage {\n page: number;\n png: Uint8Array;\n}\n\nexport interface RenderPagesResult extends CompileResult {\n images: RenderedImage[];\n}\n\n/**\n * Render the given 1-based pages to PNGs in a scratch directory and read\n * them back, page-ordered; the scratch directory is always removed.\n */\nexport async function renderPages(\n options: OneshotOptions,\n pages: number[],\n ppi: number,\n): Promise<RenderPagesResult> {\n const dir = await mkdtemp(join(options.scratch, \"render-\"));\n try {\n const result = await compile(options, join(dir, \"page-{p}.png\"), [\n \"--pages\",\n pages.join(\",\"),\n \"--ppi\",\n String(ppi),\n ]);\n if (!result.ok) return { ...result, images: [] };\n const images: RenderedImage[] = [];\n for (const name of await readdir(dir)) {\n const match = /^page-(\\d+)\\.png$/.exec(name);\n if (match) {\n images.push({\n page: Number(match[1]),\n png: new Uint8Array(await readFile(join(dir, name))),\n });\n }\n }\n images.sort((a, b) => a.page - b.page);\n return { ...result, images };\n } finally {\n await rm(dir, { recursive: true, force: true });\n }\n}\n\nexport interface ExportExtra {\n pdfStandard?: string;\n pages?: string;\n}\n\n/** Compile a PDF into the workspace (optionally a PDF standard and a page selection). */\nexport async function exportPdf(\n options: OneshotOptions,\n output: string,\n extra: ExportExtra,\n): Promise<CompileResult> {\n const args: string[] = [];\n if (extra.pdfStandard) args.push(\"--pdf-standard\", extra.pdfStandard);\n if (extra.pages) args.push(\"--pages\", extra.pages);\n return compile(options, output, args);\n}\n"],
5
+ "mappings": "AAQA,SAAS,SAAS,SAAS,UAAU,UAAU;AAC/C,SAAS,YAAY;AACrB,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAC3B,SAAS,wBAAwB;AACjC,SAAS,WAAW;AAuBpB,eAAe,QACb,SACA,QACA,OACwB;AACxB,QAAM,WAAW,QAAQ,OAAO,CAAC,UAAU,QAAQ,IAAI,IAAI,CAAC;AAC5D,QAAM,YAAY,QAAQ,aAAa,CAAC,GAAG,QAAQ,CAAC,QAAQ;AAAA,IAC1D;AAAA,IACA;AAAA,EACF,CAAC;AACD,QAAM,SAAS,MAAM;AAAA,IACnB,QAAQ;AAAA,IACR,CAAC,WAAW,QAAQ,MAAM,QAAQ,GAAG,OAAO,GAAG,UAAU,GAAG,QAAQ;AAAA,IACpE;AAAA,MACE,KAAK,QAAQ;AAAA,MACb,KAAK,QAAQ;AAAA,MACb,WAAW,QAAQ,aAAa,OAAO;AAAA,IACzC;AAAA,EACF;AACA,MAAI,OAAO,UAAU;AACnB,UAAM,IAAI;AAAA,MACR,uCAAuC,KAAK,OAAO,QAAQ,aAAa,OAAO,oBAAoB,GAAG,CAAC;AAAA,MACvG;AAAA,IACF;AAAA,EACF;AACA,QAAM,cAAc,iBAAiB,OAAO,QAAQ,QAAQ,MAAM;AAClE,MACE,OAAO,SAAS,KAChB,CAAC,YAAY,KAAK,CAAC,UAAU,MAAM,aAAa,OAAO,GACvD;AACA,gBAAY,KAAK;AAAA,MACf,UAAU;AAAA,MACV,UACG,OAAO,UAAU,OAAO,QAAQ,KAAK,EAAE,MAAM,GAAG,GAAG,KACpD,0BAA0B,OAAO,IAAI;AAAA,MACvC,UAAU;AAAA,MACV,OAAO,CAAC;AAAA,MACR,OAAO,CAAC;AAAA,IACV,CAAC;AAAA,EACH;AACA,SAAO,EAAE,IAAI,OAAO,SAAS,GAAG,YAAY;AAC9C;AAeA,eAAsB,YACpB,SACA,OACA,KAC4B;AAC5B,QAAM,MAAM,MAAM,QAAQ,KAAK,QAAQ,SAAS,SAAS,CAAC;AAC1D,MAAI;AACF,UAAM,SAAS,MAAM,QAAQ,SAAS,KAAK,KAAK,cAAc,GAAG;AAAA,MAC/D;AAAA,MACA,MAAM,KAAK,GAAG;AAAA,MACd;AAAA,MACA,OAAO,GAAG;AAAA,IACZ,CAAC;AACD,QAAI,CAAC,OAAO,GAAI,QAAO,EAAE,GAAG,QAAQ,QAAQ,CAAC,EAAE;AAC/C,UAAM,SAA0B,CAAC;AACjC,eAAW,QAAQ,MAAM,QAAQ,GAAG,GAAG;AACrC,YAAM,QAAQ,oBAAoB,KAAK,IAAI;AAC3C,UAAI,OAAO;AACT,eAAO,KAAK;AAAA,UACV,MAAM,OAAO,MAAM,CAAC,CAAC;AAAA,UACrB,KAAK,IAAI,WAAW,MAAM,SAAS,KAAK,KAAK,IAAI,CAAC,CAAC;AAAA,QACrD,CAAC;AAAA,MACH;AAAA,IACF;AACA,WAAO,KAAK,CAAC,GAAG,MAAM,EAAE,OAAO,EAAE,IAAI;AACrC,WAAO,EAAE,GAAG,QAAQ,OAAO;AAAA,EAC7B,UAAE;AACA,UAAM,GAAG,KAAK,EAAE,WAAW,MAAM,OAAO,KAAK,CAAC;AAAA,EAChD;AACF;AAQA,eAAsB,UACpB,SACA,QACA,OACwB;AACxB,QAAM,OAAiB,CAAC;AACxB,MAAI,MAAM,YAAa,MAAK,KAAK,kBAAkB,MAAM,WAAW;AACpE,MAAI,MAAM,MAAO,MAAK,KAAK,WAAW,MAAM,KAAK;AACjD,SAAO,QAAQ,SAAS,QAAQ,IAAI;AACtC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Server-side PDF inspection with the user-space geometry the highlight
3
+ * engine needs: page count and per-page text + spans. pdf.js runs on the
4
+ * main thread through its fake-worker entry (`globalThis.pdfjsWorker`), the
5
+ * same arrangement the ZCode typst-workbench server (0.2.0) ships. Loading
6
+ * is lazy: a session that never highlights never pays for the module.
7
+ * Host half only.
8
+ * @module dsh-typst/typst/pdf-extract
9
+ */
10
+ import { type PageText } from "./text.js";
11
+ /**
12
+ * The directory pdf.js should read its cmaps and standard fonts from (the
13
+ * installed pdfjs-dist package), or null when it cannot be resolved; typst
14
+ * embeds its fonts, so extraction works without them.
15
+ * @param hint - an extra candidate directory to prefer.
16
+ */
17
+ export declare function pdfjsDataDir(hint?: string | null): string | null;
18
+ /**
19
+ * Number of pages in a PDF, or a rejection when the bytes are not readable.
20
+ * Runs without cmaps: only the structure is read.
21
+ */
22
+ export declare function pageCount(data: Uint8Array): Promise<number>;
23
+ /**
24
+ * Extract per-page text + spans for quote matching and highlight rectangles.
25
+ * @param data - the PDF bytes.
26
+ * @param dataDir - cmap/standard-font directory from {@link pdfjsDataDir}.
27
+ */
28
+ export declare function extractPages(data: Uint8Array, dataDir: string | null): Promise<PageText[]>;
29
+ //# sourceMappingURL=pdf-extract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdf-extract.d.ts","sourceRoot":"","sources":["../../src/typst/pdf-extract.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,OAAO,EAAa,KAAK,QAAQ,EAAoB,MAAM,WAAW,CAAC;AAwCvE;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAahE;AA2BD;;;GAGG;AACH,wBAAsB,SAAS,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAOjE;AAED;;;;GAIG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,MAAM,GAAG,IAAI,GACrB,OAAO,CAAC,QAAQ,EAAE,CAAC,CA0BrB"}
@@ -0,0 +1,87 @@
1
+ import { existsSync } from "node:fs";
2
+ import { createRequire } from "node:module";
3
+ import { dirname, join, resolve, sep } from "node:path";
4
+ import { buildPage } from "./text.js";
5
+ let loading = null;
6
+ async function pdfjs() {
7
+ loading ??= (async () => {
8
+ const [pdf, worker] = await Promise.all([
9
+ // pdf.js's own types describe the browser surface; the extraction
10
+ // surface used here is the small one below, so the module is trusted
11
+ // through `unknown` and consumed via PdfJsModule.
12
+ import("pdfjs-dist/legacy/build/pdf.mjs"),
13
+ import("pdfjs-dist/legacy/build/pdf.worker.mjs")
14
+ ]);
15
+ globalThis.pdfjsWorker = worker;
16
+ return pdf;
17
+ })();
18
+ return loading;
19
+ }
20
+ function pdfjsDataDir(hint) {
21
+ const candidates = [];
22
+ if (hint) candidates.push(hint);
23
+ try {
24
+ const require2 = createRequire(import.meta.url);
25
+ candidates.push(dirname(require2.resolve("pdfjs-dist/package.json")));
26
+ } catch {
27
+ }
28
+ for (const candidate of candidates) {
29
+ if (existsSync(join(candidate, "cmaps"))) return resolve(candidate) + sep;
30
+ }
31
+ return null;
32
+ }
33
+ async function open(data, dataDir) {
34
+ const module = await pdfjs();
35
+ return module.getDocument({
36
+ data: new Uint8Array(data),
37
+ ...dataDir ? {
38
+ cMapUrl: `${dataDir}cmaps${sep}`,
39
+ cMapPacked: true,
40
+ standardFontDataUrl: `${dataDir}standard_fonts${sep}`
41
+ } : {},
42
+ disableFontFace: true,
43
+ useSystemFonts: false,
44
+ verbosity: 0
45
+ });
46
+ }
47
+ async function pageCount(data) {
48
+ const task = await open(data, null);
49
+ try {
50
+ return (await task.promise).numPages;
51
+ } finally {
52
+ await task.destroy();
53
+ }
54
+ }
55
+ async function extractPages(data, dataDir) {
56
+ const task = await open(data, dataDir);
57
+ try {
58
+ const doc = await task.promise;
59
+ const labels = await doc.getPageLabels().catch(() => null);
60
+ const pages = [];
61
+ for (let index = 0; index < doc.numPages; index++) {
62
+ const page = await doc.getPage(index + 1);
63
+ const [x1, y1, x2, y2] = page.view;
64
+ const content = await page.getTextContent();
65
+ pages.push(
66
+ buildPage(content.items, {
67
+ index,
68
+ label: labels?.[index] || String(index + 1),
69
+ width: x2 - x1,
70
+ height: y2 - y1,
71
+ originX: x1,
72
+ originY: y1
73
+ })
74
+ );
75
+ page.cleanup();
76
+ }
77
+ return pages;
78
+ } finally {
79
+ await task.destroy();
80
+ }
81
+ }
82
+ export {
83
+ extractPages,
84
+ pageCount,
85
+ pdfjsDataDir
86
+ };
87
+ //# sourceMappingURL=pdf-extract.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/typst/pdf-extract.ts"],
4
+ "sourcesContent": ["/**\n * Server-side PDF inspection with the user-space geometry the highlight\n * engine needs: page count and per-page text + spans. pdf.js runs on the\n * main thread through its fake-worker entry (`globalThis.pdfjsWorker`), the\n * same arrangement the ZCode typst-workbench server (0.2.0) ships. Loading\n * is lazy: a session that never highlights never pays for the module.\n * Host half only.\n * @module dsh-typst/typst/pdf-extract\n */\n\nimport { existsSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { dirname, join, resolve, sep } from \"node:path\";\nimport { buildPage, type PageText, type PdfTextItem } from \"./text.js\";\n\ninterface PdfJsDocument {\n numPages: number;\n getPageLabels(): Promise<string[] | null>;\n getPage(index: number): Promise<PdfJsPage>;\n destroy(): Promise<void>;\n}\n\ninterface PdfJsPage {\n view: [number, number, number, number];\n getTextContent(): Promise<{ items: PdfTextItem[] }>;\n cleanup(): void;\n}\n\ninterface PdfJsModule {\n getDocument(params: Record<string, unknown>): {\n promise: Promise<PdfJsDocument>;\n destroy(): Promise<void>;\n };\n}\n\nlet loading: Promise<PdfJsModule> | null = null;\n\n/** Load pdf.js (legacy build) once; the fake-worker entry must be set first. */\nasync function pdfjs(): Promise<PdfJsModule> {\n loading ??= (async () => {\n const [pdf, worker] = await Promise.all([\n // pdf.js's own types describe the browser surface; the extraction\n // surface used here is the small one below, so the module is trusted\n // through `unknown` and consumed via PdfJsModule.\n import(\"pdfjs-dist/legacy/build/pdf.mjs\") as Promise<unknown>,\n import(\"pdfjs-dist/legacy/build/pdf.worker.mjs\"),\n ]);\n (globalThis as Record<string, unknown>).pdfjsWorker = worker;\n return pdf as PdfJsModule;\n })();\n return loading;\n}\n\n/**\n * The directory pdf.js should read its cmaps and standard fonts from (the\n * installed pdfjs-dist package), or null when it cannot be resolved; typst\n * embeds its fonts, so extraction works without them.\n * @param hint - an extra candidate directory to prefer.\n */\nexport function pdfjsDataDir(hint?: string | null): string | null {\n const candidates: string[] = [];\n if (hint) candidates.push(hint);\n try {\n const require = createRequire(import.meta.url);\n candidates.push(dirname(require.resolve(\"pdfjs-dist/package.json\")));\n } catch {\n // Not resolvable (vendored without node_modules): fall through.\n }\n for (const candidate of candidates) {\n if (existsSync(join(candidate, \"cmaps\"))) return resolve(candidate) + sep;\n }\n return null;\n}\n\ninterface OpenTask {\n promise: Promise<PdfJsDocument>;\n destroy(): Promise<void>;\n}\n\nasync function open(\n data: Uint8Array,\n dataDir: string | null,\n): Promise<OpenTask> {\n const module = await pdfjs();\n return module.getDocument({\n data: new Uint8Array(data),\n ...(dataDir\n ? {\n cMapUrl: `${dataDir}cmaps${sep}`,\n cMapPacked: true,\n standardFontDataUrl: `${dataDir}standard_fonts${sep}`,\n }\n : {}),\n disableFontFace: true,\n useSystemFonts: false,\n verbosity: 0,\n }) as OpenTask;\n}\n\n/**\n * Number of pages in a PDF, or a rejection when the bytes are not readable.\n * Runs without cmaps: only the structure is read.\n */\nexport async function pageCount(data: Uint8Array): Promise<number> {\n const task = await open(data, null);\n try {\n return (await task.promise).numPages;\n } finally {\n await task.destroy();\n }\n}\n\n/**\n * Extract per-page text + spans for quote matching and highlight rectangles.\n * @param data - the PDF bytes.\n * @param dataDir - cmap/standard-font directory from {@link pdfjsDataDir}.\n */\nexport async function extractPages(\n data: Uint8Array,\n dataDir: string | null,\n): Promise<PageText[]> {\n const task = await open(data, dataDir);\n try {\n const doc = await task.promise;\n const labels = await doc.getPageLabels().catch(() => null);\n const pages: PageText[] = [];\n for (let index = 0; index < doc.numPages; index++) {\n const page = await doc.getPage(index + 1);\n const [x1, y1, x2, y2] = page.view;\n const content = await page.getTextContent();\n pages.push(\n buildPage(content.items, {\n index,\n label: labels?.[index] || String(index + 1),\n width: x2 - x1,\n height: y2 - y1,\n originX: x1,\n originY: y1,\n }),\n );\n page.cleanup();\n }\n return pages;\n } finally {\n await task.destroy();\n }\n}\n"],
5
+ "mappings": "AAUA,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB;AAC9B,SAAS,SAAS,MAAM,SAAS,WAAW;AAC5C,SAAS,iBAAkD;AAsB3D,IAAI,UAAuC;AAG3C,eAAe,QAA8B;AAC3C,eAAa,YAAY;AACvB,UAAM,CAAC,KAAK,MAAM,IAAI,MAAM,QAAQ,IAAI;AAAA;AAAA;AAAA;AAAA,MAItC,OAAO,iCAAiC;AAAA,MACxC,OAAO,wCAAwC;AAAA,IACjD,CAAC;AACD,IAAC,WAAuC,cAAc;AACtD,WAAO;AAAA,EACT,GAAG;AACH,SAAO;AACT;AAQO,SAAS,aAAa,MAAqC;AAChE,QAAM,aAAuB,CAAC;AAC9B,MAAI,KAAM,YAAW,KAAK,IAAI;AAC9B,MAAI;AACF,UAAMA,WAAU,cAAc,YAAY,GAAG;AAC7C,eAAW,KAAK,QAAQA,SAAQ,QAAQ,yBAAyB,CAAC,CAAC;AAAA,EACrE,QAAQ;AAAA,EAER;AACA,aAAW,aAAa,YAAY;AAClC,QAAI,WAAW,KAAK,WAAW,OAAO,CAAC,EAAG,QAAO,QAAQ,SAAS,IAAI;AAAA,EACxE;AACA,SAAO;AACT;AAOA,eAAe,KACb,MACA,SACmB;AACnB,QAAM,SAAS,MAAM,MAAM;AAC3B,SAAO,OAAO,YAAY;AAAA,IACxB,MAAM,IAAI,WAAW,IAAI;AAAA,IACzB,GAAI,UACA;AAAA,MACE,SAAS,GAAG,OAAO,QAAQ,GAAG;AAAA,MAC9B,YAAY;AAAA,MACZ,qBAAqB,GAAG,OAAO,iBAAiB,GAAG;AAAA,IACrD,IACA,CAAC;AAAA,IACL,iBAAiB;AAAA,IACjB,gBAAgB;AAAA,IAChB,WAAW;AAAA,EACb,CAAC;AACH;AAMA,eAAsB,UAAU,MAAmC;AACjE,QAAM,OAAO,MAAM,KAAK,MAAM,IAAI;AAClC,MAAI;AACF,YAAQ,MAAM,KAAK,SAAS;AAAA,EAC9B,UAAE;AACA,UAAM,KAAK,QAAQ;AAAA,EACrB;AACF;AAOA,eAAsB,aACpB,MACA,SACqB;AACrB,QAAM,OAAO,MAAM,KAAK,MAAM,OAAO;AACrC,MAAI;AACF,UAAM,MAAM,MAAM,KAAK;AACvB,UAAM,SAAS,MAAM,IAAI,cAAc,EAAE,MAAM,MAAM,IAAI;AACzD,UAAM,QAAoB,CAAC;AAC3B,aAAS,QAAQ,GAAG,QAAQ,IAAI,UAAU,SAAS;AACjD,YAAM,OAAO,MAAM,IAAI,QAAQ,QAAQ,CAAC;AACxC,YAAM,CAAC,IAAI,IAAI,IAAI,EAAE,IAAI,KAAK;AAC9B,YAAM,UAAU,MAAM,KAAK,eAAe;AAC1C,YAAM;AAAA,QACJ,UAAU,QAAQ,OAAO;AAAA,UACvB;AAAA,UACA,OAAO,SAAS,KAAK,KAAK,OAAO,QAAQ,CAAC;AAAA,UAC1C,OAAO,KAAK;AAAA,UACZ,QAAQ,KAAK;AAAA,UACb,SAAS;AAAA,UACT,SAAS;AAAA,QACX,CAAC;AAAA,MACH;AACA,WAAK,QAAQ;AAAA,IACf;AACA,WAAO;AAAA,EACT,UAAE;AACA,UAAM,KAAK,QAAQ;AAAA,EACrB;AACF;",
6
+ "names": ["require"]
7
+ }
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=pdfjs-worker.d.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Page text model: pdf.js text items → per-page text with span geometry,
3
+ * quote search (tolerant of reflow and punctuation), highlight rectangles,
4
+ * and page-spec parsing. Ported from the ZCode typst-workbench server
5
+ * (0.2.0) `src/domain/text.ts`. Host half only.
6
+ * @module dsh-typst/typst/text
7
+ */
8
+ /** One text item as pdf.js reports it (`getTextContent().items`). */
9
+ export interface PdfTextItem {
10
+ str?: unknown;
11
+ transform?: number[];
12
+ width?: number;
13
+ height?: number;
14
+ hasEOL?: boolean;
15
+ }
16
+ export interface PdfPageInfo {
17
+ index: number;
18
+ label: string;
19
+ width: number;
20
+ height: number;
21
+ originX: number;
22
+ originY: number;
23
+ }
24
+ export interface TextSpan {
25
+ start: number;
26
+ end: number;
27
+ x: number;
28
+ y: number;
29
+ width: number;
30
+ size: number;
31
+ }
32
+ /** One page's extracted text plus the spans that locate it on the page. */
33
+ export interface PageText extends PdfPageInfo {
34
+ text: string;
35
+ spans: TextSpan[];
36
+ }
37
+ /** Build one page's text from pdf.js items, inserting line/space separators. */
38
+ export declare function buildPage(items: PdfTextItem[], page: PdfPageInfo): PageText;
39
+ /** Whitespace-normalized text for display (de-hyphenate line breaks). */
40
+ export declare function readableText(text: string): string;
41
+ interface PageHit {
42
+ pageIndex: number;
43
+ start: number;
44
+ end: number;
45
+ }
46
+ /**
47
+ * Find a quote in the extracted pages: exact (folded) match first, then
48
+ * across adjacent pages, preferring the preferred page when given.
49
+ */
50
+ export declare function findQuote(pages: PageText[], quote: string, preferredPage?: number): PageHit | null;
51
+ /**
52
+ * PDF user-space rectangles covering `page.text[start, end)`, merged across
53
+ * adjacent spans on the same line. The panel maps them through the page
54
+ * viewport to draw highlights.
55
+ */
56
+ export declare function rectsFor(page: PageText, start: number, end: number): number[][];
57
+ /** The rendered text of a range, whitespace-collapsed for display. */
58
+ export declare function textAt(page: PageText, start: number, end: number): string;
59
+ /**
60
+ * Parse a 1-based page spec into 0-based indices, bounded by `pageCount`.
61
+ * @throws when a part of the spec is malformed.
62
+ */
63
+ export declare function parsePages(spec: string, pageCount: number): number[];
64
+ export {};
65
+ //# sourceMappingURL=text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/typst/text.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,qEAAqE;AACrE,MAAM,WAAW,WAAW;IAC1B,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AAED,2EAA2E;AAC3E,MAAM,WAAW,QAAS,SAAQ,WAAW;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,QAAQ,EAAE,CAAC;CACnB;AAED,gFAAgF;AAChF,wBAAgB,SAAS,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,WAAW,GAAG,QAAQ,CAgD3E;AAED,yEAAyE;AACzE,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAOjD;AAgED,UAAU,OAAO;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb;AAiCD;;;GAGG;AACH,wBAAgB,SAAS,CACvB,KAAK,EAAE,QAAQ,EAAE,EACjB,KAAK,EAAE,MAAM,EACb,aAAa,CAAC,EAAE,MAAM,GACrB,OAAO,GAAG,IAAI,CAsBhB;AA2CD;;;;GAIG;AACH,wBAAgB,QAAQ,CACtB,IAAI,EAAE,QAAQ,EACd,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,GACV,MAAM,EAAE,EAAE,CA2BZ;AAED,sEAAsE;AACtE,wBAAgB,MAAM,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAEzE;AAMD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAmBpE"}
@@ -0,0 +1,314 @@
1
+ function buildPage(items, page) {
2
+ let text = "";
3
+ const spans = [];
4
+ let previous = null;
5
+ for (const item of items) {
6
+ if (typeof item.str !== "string") continue;
7
+ const [a = 1, b = 0, c = 0, d = 1, e = 0, f = 0] = item.transform ?? [];
8
+ const size = Math.hypot(c, d) || Math.hypot(a, b) || item.height || 10;
9
+ if (previous && item.str) {
10
+ const sameLine = Math.abs(f - previous.y) < size * 0.5;
11
+ const last = text.at(-1) ?? "\n";
12
+ if (!sameLine && !/\s/.test(last)) text += "\n";
13
+ else if (sameLine && e - previous.x2 > size * 0.15 && !/\s/.test(last) && !/^\s/.test(item.str)) {
14
+ text += " ";
15
+ }
16
+ }
17
+ if (item.str) {
18
+ const start = text.length;
19
+ text += item.str;
20
+ spans.push({
21
+ start,
22
+ end: text.length,
23
+ x: e,
24
+ y: f,
25
+ width: item.width ?? 0,
26
+ size
27
+ });
28
+ previous = { x2: e + (item.width ?? 0), y: f, size };
29
+ }
30
+ if (item.hasEOL && !text.endsWith("\n")) {
31
+ text += "\n";
32
+ }
33
+ }
34
+ return {
35
+ index: page.index,
36
+ label: page.label,
37
+ width: page.width,
38
+ height: page.height,
39
+ originX: page.originX,
40
+ originY: page.originY,
41
+ text,
42
+ spans
43
+ };
44
+ }
45
+ function readableText(text) {
46
+ return text.replace(new RegExp("(\\p{Ll})-\\n(\\p{Ll})", "gu"), "$1$2").replace(/[ \t]+/g, " ").replace(/ *\n */g, "\n").replace(/\n{3,}/g, "\n\n").trim();
47
+ }
48
+ const FOLD = {
49
+ "\u2018": "'",
50
+ "\u2019": "'",
51
+ "\u201A": "'",
52
+ "\u201B": "'",
53
+ "\u2032": "'",
54
+ "\u201C": '"',
55
+ "\u201D": '"',
56
+ "\u201E": '"',
57
+ "\u2033": '"',
58
+ "\u2010": "-",
59
+ "\u2011": "-",
60
+ "\u2012": "-",
61
+ "\u2013": "-",
62
+ "\u2014": "-",
63
+ "\u2015": "-",
64
+ "\u2212": "-",
65
+ "\xAD": "",
66
+ "\u200B": "",
67
+ "\u2026": "..."
68
+ };
69
+ function normalize(text, compact = false) {
70
+ let value = "";
71
+ const map = [];
72
+ let pendingSpace = -1;
73
+ for (let index = 0; index < text.length; index++) {
74
+ const char = text[index];
75
+ if (char === "-" && text[index + 1] === "\n" && new RegExp("\\p{Ll}", "u").test(text[index - 1] ?? "") && new RegExp("\\p{Ll}", "u").test(text[index + 2] ?? "")) {
76
+ index += 1;
77
+ continue;
78
+ }
79
+ if (/\s/.test(char)) {
80
+ if (!compact && pendingSpace < 0 && value.length) pendingSpace = index;
81
+ continue;
82
+ }
83
+ const folded = (FOLD[char] ?? char).normalize("NFKC").toLowerCase();
84
+ if (!folded) continue;
85
+ if (pendingSpace >= 0) {
86
+ value += " ";
87
+ map.push(pendingSpace);
88
+ pendingSpace = -1;
89
+ }
90
+ for (const part of folded) {
91
+ value += part;
92
+ map.push(index);
93
+ }
94
+ }
95
+ return { value, map };
96
+ }
97
+ function findInPage(page, quote, from = 0) {
98
+ for (const compact of [false, true]) {
99
+ const haystack = normalize(page.text, compact);
100
+ const needle = normalize(quote, compact).value.trim();
101
+ if (!needle) return null;
102
+ const startAt = haystack.map.findIndex((original) => original >= from);
103
+ if (startAt < 0) continue;
104
+ const position = haystack.value.indexOf(needle, startAt);
105
+ if (position >= 0) {
106
+ return {
107
+ pageIndex: page.index,
108
+ start: haystack.map[position],
109
+ end: haystack.map[position + needle.length - 1] + 1
110
+ };
111
+ }
112
+ }
113
+ const parts = quote.split(/\s*(?:\.\.\.|…|\[\s*\.\.\.\s*\])\s*/).filter((part) => part.trim().length >= 8);
114
+ if (parts.length >= 2) {
115
+ const first = findInPage(page, parts[0], from);
116
+ if (first) {
117
+ const last = findInPage(page, parts.at(-1), first.end);
118
+ if (last && last.end - first.start < 3e3) {
119
+ return { pageIndex: page.index, start: first.start, end: last.end };
120
+ }
121
+ }
122
+ }
123
+ return null;
124
+ }
125
+ function findQuote(pages, quote, preferredPage) {
126
+ const order = preferredPage !== void 0 && pages[preferredPage] ? [
127
+ pages[preferredPage],
128
+ ...pages.filter((page) => page.index !== preferredPage)
129
+ ] : pages;
130
+ for (const page of order) {
131
+ const match = findInPage(page, quote);
132
+ if (match) return match;
133
+ }
134
+ for (let index = 0; index + 1 < pages.length; index++) {
135
+ const a = pages[index];
136
+ const b = pages[index + 1];
137
+ const joined = { ...a, text: `${a.text}
138
+ ${b.text}` };
139
+ const match = findInPage(joined, quote);
140
+ if (match && match.start < a.text.length && match.end > a.text.length) {
141
+ return { pageIndex: a.index, start: match.start, end: a.text.length };
142
+ }
143
+ }
144
+ return null;
145
+ }
146
+ const ASCII_WIDTHS = [
147
+ 278,
148
+ 278,
149
+ 355,
150
+ 556,
151
+ 556,
152
+ 889,
153
+ 667,
154
+ 191,
155
+ 333,
156
+ 333,
157
+ 389,
158
+ 584,
159
+ 278,
160
+ 333,
161
+ 278,
162
+ 278,
163
+ 556,
164
+ 556,
165
+ 556,
166
+ 556,
167
+ 556,
168
+ 556,
169
+ 556,
170
+ 556,
171
+ 556,
172
+ 556,
173
+ 278,
174
+ 278,
175
+ 584,
176
+ 584,
177
+ 584,
178
+ 556,
179
+ 1015,
180
+ 667,
181
+ 667,
182
+ 722,
183
+ 722,
184
+ 667,
185
+ 611,
186
+ 778,
187
+ 722,
188
+ 278,
189
+ 500,
190
+ 667,
191
+ 556,
192
+ 833,
193
+ 722,
194
+ 778,
195
+ 667,
196
+ 778,
197
+ 722,
198
+ 667,
199
+ 611,
200
+ 722,
201
+ 667,
202
+ 944,
203
+ 667,
204
+ 667,
205
+ 611,
206
+ 278,
207
+ 278,
208
+ 278,
209
+ 469,
210
+ 556,
211
+ 333,
212
+ 556,
213
+ 556,
214
+ 500,
215
+ 556,
216
+ 556,
217
+ 278,
218
+ 556,
219
+ 556,
220
+ 222,
221
+ 222,
222
+ 500,
223
+ 222,
224
+ 833,
225
+ 556,
226
+ 556,
227
+ 556,
228
+ 556,
229
+ 333,
230
+ 500,
231
+ 278,
232
+ 556,
233
+ 500,
234
+ 722,
235
+ 500,
236
+ 500,
237
+ 500,
238
+ 334,
239
+ 260,
240
+ 334,
241
+ 584
242
+ ];
243
+ function charWidth(char) {
244
+ const code = char.codePointAt(0) ?? 32;
245
+ if (code >= 32 && code < 127) return ASCII_WIDTHS[code - 32];
246
+ if (code >= 11904 && code <= 40959 || code >= 44032 && code <= 55215 || code >= 65280 && code <= 65519) {
247
+ return 1e3;
248
+ }
249
+ return 556;
250
+ }
251
+ function fraction(text, offset) {
252
+ let before = 0;
253
+ let total = 0;
254
+ let index = 0;
255
+ for (const char of text) {
256
+ const width = charWidth(char);
257
+ if (index < offset) before += width;
258
+ total += width;
259
+ index += char.length;
260
+ }
261
+ return total ? before / total : 0;
262
+ }
263
+ function rectsFor(page, start, end) {
264
+ const rects = [];
265
+ for (const span of page.spans) {
266
+ if (span.end <= start || span.start >= end) continue;
267
+ const text = page.text.slice(span.start, span.end);
268
+ const from = Math.max(start, span.start) - span.start;
269
+ const to = Math.min(end, span.end) - span.start;
270
+ const x1 = span.x + span.width * fraction(text, from);
271
+ const x2 = span.x + span.width * fraction(text, to);
272
+ const rect = [x1, span.y - span.size * 0.25, x2, span.y + span.size * 0.75];
273
+ const last = rects.at(-1);
274
+ if (last && Math.abs(last[1] - rect[1]) < span.size * 0.3 && rect[0] - last[2] < span.size * 1.5 && rect[0] >= last[0] - 1) {
275
+ last[2] = Math.max(last[2], rect[2]);
276
+ last[1] = Math.min(last[1], rect[1]);
277
+ last[3] = Math.max(last[3], rect[3]);
278
+ } else {
279
+ rects.push(rect);
280
+ }
281
+ }
282
+ return rects.map(
283
+ (rect) => rect.map((value) => Math.round(value * 1e3) / 1e3)
284
+ );
285
+ }
286
+ function textAt(page, start, end) {
287
+ return readableText(page.text.slice(start, end)).replace(/\s+/g, " ");
288
+ }
289
+ function parsePages(spec, pageCount) {
290
+ const result = /* @__PURE__ */ new Set();
291
+ for (const part of spec.split(",").map((piece) => piece.trim()).filter(Boolean)) {
292
+ const match = /^(\d+)?\s*(?:-\s*(\d+)?)?$/.exec(part);
293
+ if (!match || !match[1] && !match[2]) {
294
+ throw new Error(
295
+ `Invalid page range "${part}". Use e.g. "3", "2-5" or "1,4-6".`
296
+ );
297
+ }
298
+ const isRange = part.includes("-");
299
+ const from = match[1] ? Number(match[1]) : 1;
300
+ const to = isRange ? match[2] ? Number(match[2]) : pageCount : from;
301
+ for (let page = Math.max(from, 1); page <= Math.min(to, pageCount); page++)
302
+ result.add(page - 1);
303
+ }
304
+ return [...result].sort((a, b) => a - b);
305
+ }
306
+ export {
307
+ buildPage,
308
+ findQuote,
309
+ parsePages,
310
+ readableText,
311
+ rectsFor,
312
+ textAt
313
+ };
314
+ //# sourceMappingURL=text.js.map