@shuji-bonji/pdf-reader-mcp 0.16.1 → 0.18.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/CHANGELOG.md +44 -1
- package/README.ja.md +12 -27
- package/README.md +11 -26
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/schemas/tier3.d.ts +0 -12
- package/dist/schemas/tier3.d.ts.map +1 -1
- package/dist/schemas/tier3.js +0 -14
- package/dist/schemas/tier3.js.map +1 -1
- package/dist/services/page-renderer.d.ts +19 -0
- package/dist/services/page-renderer.d.ts.map +1 -1
- package/dist/services/page-renderer.js +32 -15
- package/dist/services/page-renderer.js.map +1 -1
- package/dist/services/pdfjs-service.d.ts +1 -6
- package/dist/services/pdfjs-service.d.ts.map +1 -1
- package/dist/services/pdfjs-service.js +0 -98
- package/dist/services/pdfjs-service.js.map +1 -1
- package/dist/services/validation-service.d.ts +4 -45
- package/dist/services/validation-service.d.ts.map +1 -1
- package/dist/services/validation-service.js +4 -662
- package/dist/services/validation-service.js.map +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +0 -4
- package/dist/tools/index.js.map +1 -1
- package/dist/types.d.ts +0 -50
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/formatter.d.ts +1 -9
- package/dist/utils/formatter.d.ts.map +1 -1
- package/dist/utils/formatter.js +1 -78
- package/dist/utils/formatter.js.map +1 -1
- package/package.json +1 -1
- package/dist/tools/tier3/validate-metadata.d.ts +0 -6
- package/dist/tools/tier3/validate-metadata.d.ts.map +0 -1
- package/dist/tools/tier3/validate-metadata.js +0 -73
- package/dist/tools/tier3/validate-metadata.js.map +0 -1
- package/dist/tools/tier3/validate-tagged.d.ts +0 -6
- package/dist/tools/tier3/validate-tagged.d.ts.map +0 -1
- package/dist/tools/tier3/validate-tagged.js +0 -74
- package/dist/tools/tier3/validate-tagged.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,7 +5,50 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
-
## [
|
|
8
|
+
## [0.18.0] - 2026-11-02
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- **`render_page` now renders after `@hyzyla/pdfium` is installed into a running server** (#34).
|
|
13
|
+
When the optional renderer was missing, the failed load was remembered as `null` for the life
|
|
14
|
+
of the process, so the tool kept answering "install it next to this server … and call again"
|
|
15
|
+
even after it had been installed — until the server was restarted. MCP hosts keep one server
|
|
16
|
+
process for the whole conversation, so following the message did nothing. A failed import or
|
|
17
|
+
initialisation is now forgotten and retried on the next call; a successful one is still loaded
|
|
18
|
+
once and reused (concurrent first calls share one initialisation).
|
|
19
|
+
- Measured on 0.17.0 (npm): missing → install while running → call again returned the same
|
|
20
|
+
message; after a restart it rendered. With this change the second call renders.
|
|
21
|
+
- While the renderer is missing, each `render_page` call now tries one `import()` that fails.
|
|
22
|
+
The other 17 tools never load the renderer.
|
|
23
|
+
|
|
24
|
+
## [0.17.0] - 2026-10-15
|
|
25
|
+
|
|
26
|
+
### Removed
|
|
27
|
+
|
|
28
|
+
- **BREAKING — `validate_tagged` and `validate_metadata` are removed.** `tools/list` now
|
|
29
|
+
returns 18 tools. Both returned pass/fail against PDF/UA, which is pdf-verify-mcp's job
|
|
30
|
+
in the PDF family ("pass/fail against a standard belongs to pdf-verify-mcp; reporting
|
|
31
|
+
observations belongs to pdf-reader-mcp"). They were deprecated in 0.7.0 with a removal
|
|
32
|
+
notice in their descriptions, and they carried known errors that were not going to be
|
|
33
|
+
fixed: `validate_metadata` read only the document information dictionary (PDF/UA-1 §7.1
|
|
34
|
+
requires `dc:title` in XMP), and `validate_tagged` counted Figure tags without reading
|
|
35
|
+
`/Alt`.
|
|
36
|
+
- **Migration:** for PDF/UA or PDF/A conformance, use pdf-verify-mcp's
|
|
37
|
+
`validate_conformance` (`flavour: "pdfua-1"`, `"pdfua-2"`, `"pdfa-*"`). For the facts
|
|
38
|
+
the two tools looked at, use `inspect_tags` (structure tree) and `get_metadata`
|
|
39
|
+
(metadata fields) here.
|
|
40
|
+
- Calling either name now fails at the protocol level: the MCP SDK returns a JSON-RPC
|
|
41
|
+
error `-32602` ("Tool validate_tagged not found"), not a tool result with
|
|
42
|
+
`isError: true`.
|
|
43
|
+
- Also removed with them, because nothing else used them: `isValidPdfDate` (the
|
|
44
|
+
ISO 32000-2 §7.9.4 date-form check), the per-page structure-tree walk that
|
|
45
|
+
`validate_tagged` used, and their input schemas, Markdown formatters and output types.
|
|
46
|
+
`countImagesFromDoc` stays (`summarize` uses it).
|
|
47
|
+
- Development: the tool set is now specified in `openspec/specs/tools-list`
|
|
48
|
+
(SPEC-READER-TOOLS-LIST-001: the 18 tools; -002: no tool that returns pass/fail, and no
|
|
49
|
+
tool named `validate_*`), checked against `tools/list` by `tests/tier1/tools-list.test.ts`.
|
|
50
|
+
- Development: `scripts/golden.mjs` now covers `inspect_catalog`. It had been missing since
|
|
51
|
+
0.16.0, so `take` stopped with "registered but not in CALLS" until this change.
|
|
9
52
|
|
|
10
53
|
## [0.16.1] - 2026-10-15
|
|
11
54
|
|
package/README.ja.md
CHANGED
|
@@ -22,7 +22,7 @@ PDF 内部構造解析に特化した MCP (Model Context Protocol) サーバー
|
|
|
22
22
|
|
|
23
23
|
## 機能
|
|
24
24
|
|
|
25
|
-
**
|
|
25
|
+
**18 ツール** を 3 層構成で提供します。
|
|
26
26
|
|
|
27
27
|
### Tier 1: 基本機能
|
|
28
28
|
|
|
@@ -33,7 +33,7 @@ PDF 内部構造解析に特化した MCP (Model Context Protocol) サーバー
|
|
|
33
33
|
| `read_text` | テキスト抽出(Y座標ベースの読み順保持。`split_columns: 2 \| 3` で **タグなし** 多カラム PDF、`compact_whitespace` で 帳票 の U+3000 連続空白を畳み込み)。`/ActualText` 置換(§14.9.4。構造要素・`Span` マーク付きコンテンツの両経路)を解決。ページごとに**テキスト抽出可能性**(§9.10.1)を併記するので、空の結果が「空のページ」と取り違えられない。**論理順**が要るタグ付き PDF の本文は `extract_structured_text` を推奨 |
|
|
34
34
|
| `search_text` | 全文検索(前後コンテキスト付き)。`read_text` と同じテキスト(`/ActualText` 解決済み)を検索するため、ヒット=読み手に見えている語(位置合わせできなかったページがあれば `note` で名指し) |
|
|
35
35
|
| `read_images` | 埋め込み画像 XObject を **PNG / JPEG ファイル**として抽出し、MCP の image コンテンツブロックで返す(視覚モデルがそのまま読める)。`max_width` / `max_height` で面積平均による縮小。応答にはバイト予算があり、返さなかった画像は理由付きで名指しする |
|
|
36
|
-
| `read_url` | リモート PDF を取得して**テキストだけ**を返す。取得したバイト列は保存しない。URL 上の PDF に他の
|
|
36
|
+
| `read_url` | リモート PDF を取得して**テキストだけ**を返す。取得したバイト列は保存しない。URL 上の PDF に他の 17 ツールを使うには、先にローカルへダウンロードしてそのパスを渡す(「read_url と read-only の境界」参照) |
|
|
37
37
|
| `render_page` | ページを **PNG/JPEG** にラスタライズ(PDFium の WASM 版・optionalDependencies の `@hyzyla/pdfium`)。テキスト抽出可能性が `no_text_layer` / `not_extractable` のときの次の一手。ベクタ図形・フォーム込みでページ全体を描く |
|
|
38
38
|
| `summarize` | 全体概要レポート(メタデータ + テキスト + 画像数 + 文書全体のテキスト抽出可能性) |
|
|
39
39
|
|
|
@@ -51,19 +51,23 @@ PDF 内部構造解析に特化した MCP (Model Context Protocol) サーバー
|
|
|
51
51
|
| `extract_tables` | Tagged PDF の `<Table>` を Markdown テーブルとして抽出。ページを跨ぐ表は 1 つの表(`pages` 配列)として返す |
|
|
52
52
|
| `locate_objects` | オブジェクト番号 → ページ + 矩形。座標は [pdf-writer-mcp](https://github.com/shuji-bonji/pdf-writer-mcp) の `add_annotation` がそのまま受け取る形(PDF 座標系・左下原点・pt・正規化済み)。[pdf-verify-mcp](https://github.com/shuji-bonji/pdf-verify-mcp) の `verify_integrity` が返す「どのオブジェクトが変わったか」を「どこにあるか」に繋ぐ。各位置は根拠(`basis`)を明示する — 注釈自身の `/Rect` は正確、コンテンツストリームは「ページ全体」までしか言えない |
|
|
53
53
|
|
|
54
|
-
### Tier 3:
|
|
54
|
+
### Tier 3: 比較
|
|
55
55
|
|
|
56
56
|
| ツール | 説明 |
|
|
57
57
|
| ------------------- | ---------------------------------------------- |
|
|
58
|
-
| `validate_tagged` | **非推奨** — ISO 規格への合否判定は [pdf-verify-mcp](https://github.com/shuji-bonji/pdf-verify-mcp) の `validate_conformance`(`flavour: "pdfua-1"`)へ移管。次のメジャーまで残置 |
|
|
59
|
-
| `validate_metadata` | **非推奨** — 移管先は上と同じ。次のメジャーまで残置 |
|
|
60
58
|
| `compare_structure` | 2つのPDFの構造差分比較(プロパティ+フォント) |
|
|
61
59
|
|
|
60
|
+
`validate_tagged` と `validate_metadata` は削除しました(0.7.0 から非推奨)。本サーバは PDF に
|
|
61
|
+
何があるかを報告し、規格に照らした合否は返しません。PDF/UA や PDF/A への適合は
|
|
62
|
+
[pdf-verify-mcp](https://github.com/shuji-bonji/pdf-verify-mcp) の `validate_conformance`
|
|
63
|
+
(`flavour: "pdfua-1"`・`"pdfa-*"` など)で確かめてください。2 ツールが見ていた事実は、
|
|
64
|
+
本サーバの `inspect_tags`(構造ツリー)と `get_metadata`(メタデータの項目)で取り出せます。
|
|
65
|
+
|
|
62
66
|
### read_url と read-only の境界(#25)
|
|
63
67
|
|
|
64
68
|
`read_url` が返すのはテキストだけ。これは設計判断であり、今回それを暗黙から明文にした。
|
|
65
69
|
取得したバイト列は抽出後に破棄する。保存すれば reader のツールがファイルシステムに
|
|
66
|
-
書き込むことになり、本サーバの全
|
|
70
|
+
書き込むことになり、本サーバの全 18 ツールが read-only(`readOnlyHint: true`)という
|
|
67
71
|
不変条件が成り立たなくなるため。
|
|
68
72
|
|
|
69
73
|
URL 上の PDF に `search_text` / `inspect_structure` / `extract_tables` / `render_page`
|
|
@@ -91,7 +95,7 @@ render_page({ file_path: "/path/to/scan.pdf", pages: "1-3", format: "jpeg" })
|
|
|
91
95
|
描画エンジンは **PDFium の WebAssembly 版**(`@hyzyla/pdfium`・optionalDependencies)。
|
|
92
96
|
WASM はどのプラットフォームでも同じバイト列なので、`npx` で入る公開版の挙動が環境に
|
|
93
97
|
よらない — ネイティブアドオンを使わない理由がそのまま満たせる。未インストールなら
|
|
94
|
-
`render_page` はインストール方法を返し、他の
|
|
98
|
+
`render_page` はインストール方法を返し、他の 17 ツールは通常どおり動く。
|
|
95
99
|
PDFium(BSD-3-Clause)はテキスト読み取りに使っている pdf.js とは別エンジンであり、
|
|
96
100
|
その旨は description に明記してある(エンジン間の描画差をファイルの性質と
|
|
97
101
|
取り違えないため)。
|
|
@@ -218,25 +222,6 @@ summarize({ file_path: "/path/to/document.pdf" })
|
|
|
218
222
|
| Images | 15 |
|
|
219
223
|
```
|
|
220
224
|
|
|
221
|
-
### PDF/UA タグ検証
|
|
222
|
-
|
|
223
|
-
```
|
|
224
|
-
validate_tagged({ file_path: "/path/to/document.pdf" })
|
|
225
|
-
→ ✅ [TAG-001] Document is marked as tagged
|
|
226
|
-
✅ [TAG-002] Structure tree root exists
|
|
227
|
-
⚠️ [TAG-004] Heading hierarchy has gaps: H1, H3
|
|
228
|
-
❌ [TAG-005] Document has 3 image(s) but no Figure tags
|
|
229
|
-
```
|
|
230
|
-
|
|
231
|
-
### メタデータ検証
|
|
232
|
-
|
|
233
|
-
```
|
|
234
|
-
validate_metadata({ file_path: "/path/to/document.pdf" })
|
|
235
|
-
→ ✅ [META-001] Title: "Annual Report 2025"
|
|
236
|
-
⚠️ [META-002] Author is missing
|
|
237
|
-
✅ [META-006] PDF version: 2.0
|
|
238
|
-
```
|
|
239
|
-
|
|
240
225
|
### 構造比較
|
|
241
226
|
|
|
242
227
|
```
|
|
@@ -465,7 +450,7 @@ pdf-reader-mcp/
|
|
|
465
450
|
1. `summarize` で PDF の概要を把握
|
|
466
451
|
2. `inspect_tags` でタグ構造を確認
|
|
467
452
|
3. pdf-spec-mcp の `get_requirements` で PDF/UA 要件を取得
|
|
468
|
-
4. `
|
|
453
|
+
4. pdf-verify-mcp の `validate_conformance`(`flavour: "pdfua-1"`)で適合性を検証
|
|
469
454
|
5. `compare_structure` で修正前後の構造差分を確認
|
|
470
455
|
|
|
471
456
|
## ライセンス
|
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ While typical PDF MCP servers are thin wrappers for text extraction, this projec
|
|
|
22
22
|
|
|
23
23
|
## Features
|
|
24
24
|
|
|
25
|
-
**
|
|
25
|
+
**18 tools** organized into three tiers:
|
|
26
26
|
|
|
27
27
|
### Tier 1: Basic Operations
|
|
28
28
|
|
|
@@ -33,7 +33,7 @@ While typical PDF MCP servers are thin wrappers for text extraction, this projec
|
|
|
33
33
|
| `read_text` | Text extraction with Y-coordinate reading order (opt-in `split_columns: 2 \| 3` for untagged multi-column PDFs, `compact_whitespace` for Japanese forms). Resolves `/ActualText` replacements (§14.9.4, both the structure-element and the `Span` marked-content path). Reports **text extractability** per page (§9.10.1) so an empty result is never mistaken for an empty page. For **logical** order in tagged PDFs, prefer `extract_structured_text` |
|
|
34
34
|
| `search_text` | Full-text search with surrounding context. Searches the same text `read_text` returns, `/ActualText` included, so a hit means what a reader sees (a `note` names any page whose marked content could not be aligned) |
|
|
35
35
|
| `read_images` | Embedded image XObjects as **PNG or JPEG files**, returned as MCP image content blocks so a vision model can read them. `max_width` / `max_height` downscale by area average; the response has a byte budget and names anything it leaves out |
|
|
36
|
-
| `read_url` | Fetch a remote PDF and extract its **text** — nothing more. The bytes are not saved; to use the other
|
|
36
|
+
| `read_url` | Fetch a remote PDF and extract its **text** — nothing more. The bytes are not saved; to use the other 17 tools on a URL's PDF, download it first and pass the local path (see "read_url and the read-only boundary") |
|
|
37
37
|
| `render_page` | Rasterise pages to **PNG/JPEG** via PDFium-WASM (optional dependency `@hyzyla/pdfium`). The next step when text extractability says `no_text_layer` / `not_extractable` — draws the whole page, vector art and forms included |
|
|
38
38
|
| `summarize` | Quick overview report (metadata + text + image count + per-document text extractability) |
|
|
39
39
|
|
|
@@ -51,20 +51,24 @@ While typical PDF MCP servers are thin wrappers for text extraction, this projec
|
|
|
51
51
|
| `extract_tables` | Tagged PDF `<Table>` subtree → Markdown table (preserves columns). A table continuing across a page break is ONE table (`pages` array) |
|
|
52
52
|
| `locate_objects` | Object number → page and rectangle, in the coordinate form [pdf-writer-mcp](https://github.com/shuji-bonji/pdf-writer-mcp) `add_annotation` takes. Bridges [pdf-verify-mcp](https://github.com/shuji-bonji/pdf-verify-mcp) `verify_integrity`'s "which objects changed" to "where they are". Each location names its `basis`: an annotation's own `/Rect` is exact, a content stream can only say "the whole page" |
|
|
53
53
|
|
|
54
|
-
### Tier 3:
|
|
54
|
+
### Tier 3: Comparison
|
|
55
55
|
|
|
56
56
|
| Tool | Description |
|
|
57
57
|
| ------------------- | ---------------------------------------------------- |
|
|
58
|
-
| `validate_tagged` | **Deprecated** — PDF/UA pass/fail belongs to [pdf-verify-mcp](https://github.com/shuji-bonji/pdf-verify-mcp) `validate_conformance` (`flavour: "pdfua-1"`). Kept until the next major |
|
|
59
|
-
| `validate_metadata` | **Deprecated** — same migration path as above. Kept until the next major |
|
|
60
58
|
| `compare_structure` | Structural diff between two PDFs (properties + fonts)|
|
|
61
59
|
|
|
60
|
+
`validate_tagged` and `validate_metadata` were removed (deprecated since 0.7.0). This server
|
|
61
|
+
reports what a PDF contains and does not return pass/fail against a standard. For PDF/UA or
|
|
62
|
+
PDF/A conformance, use [pdf-verify-mcp](https://github.com/shuji-bonji/pdf-verify-mcp)
|
|
63
|
+
`validate_conformance` (`flavour: "pdfua-1"`, `"pdfa-*"`, …). For the facts those tools used
|
|
64
|
+
to look at, use `inspect_tags` (structure tree) and `get_metadata` (metadata fields) here.
|
|
65
|
+
|
|
62
66
|
### read_url and the read-only boundary (#25)
|
|
63
67
|
|
|
64
68
|
`read_url` returns text, and only text. This is a decision, now stated rather than implied:
|
|
65
69
|
the fetched bytes are discarded after extraction, because saving them would make a reader
|
|
66
70
|
tool write to the file system, and every tool of this server is read-only
|
|
67
|
-
(`readOnlyHint: true` — all
|
|
71
|
+
(`readOnlyHint: true` — all 18 of them).
|
|
68
72
|
|
|
69
73
|
To run `search_text`, `inspect_structure`, `extract_tables`, `render_page` or anything else
|
|
70
74
|
against a PDF that lives at a URL, download the file first — with whatever fetch capability
|
|
@@ -220,25 +224,6 @@ summarize({ file_path: "/path/to/document.pdf" })
|
|
|
220
224
|
| Images | 15 |
|
|
221
225
|
```
|
|
222
226
|
|
|
223
|
-
### Validate Tagged Structure (PDF/UA)
|
|
224
|
-
|
|
225
|
-
```
|
|
226
|
-
validate_tagged({ file_path: "/path/to/document.pdf" })
|
|
227
|
-
→ ✅ [TAG-001] Document is marked as tagged
|
|
228
|
-
✅ [TAG-002] Structure tree root exists
|
|
229
|
-
⚠️ [TAG-004] Heading hierarchy has gaps: H1, H3
|
|
230
|
-
❌ [TAG-005] Document has 3 image(s) but no Figure tags
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
### Validate Metadata
|
|
234
|
-
|
|
235
|
-
```
|
|
236
|
-
validate_metadata({ file_path: "/path/to/document.pdf" })
|
|
237
|
-
→ ✅ [META-001] Title: "Annual Report 2025"
|
|
238
|
-
⚠️ [META-002] Author is missing
|
|
239
|
-
✅ [META-006] PDF version: 2.0
|
|
240
|
-
```
|
|
241
|
-
|
|
242
227
|
### Compare Structure
|
|
243
228
|
|
|
244
229
|
```
|
|
@@ -473,7 +458,7 @@ On error, every tool returns `isError: true` and the JSON-stringified `LawServic
|
|
|
473
458
|
1. `summarize` — get a PDF overview
|
|
474
459
|
2. `inspect_tags` — examine the tag structure
|
|
475
460
|
3. pdf-spec-mcp `get_requirements` — fetch PDF/UA requirements
|
|
476
|
-
4. `
|
|
461
|
+
4. pdf-verify-mcp `validate_conformance` — check conformance (`flavour: "pdfua-1"`)
|
|
477
462
|
5. `compare_structure` — diff before/after fixes
|
|
478
463
|
|
|
479
464
|
## License
|
package/dist/index.js
CHANGED
|
@@ -36,8 +36,9 @@ What it does NOT do:
|
|
|
36
36
|
- No cryptographic verification. inspect_signatures reads signature fields structurally and
|
|
37
37
|
says so explicitly; whether a signature is mathematically valid is pdf-verify-mcp's answer
|
|
38
38
|
(verify_signatures / verify_integrity).
|
|
39
|
-
- No conformance judgement.
|
|
40
|
-
|
|
39
|
+
- No conformance judgement. Pass/fail against PDF/UA or PDF/A is pdf-verify-mcp's
|
|
40
|
+
validate_conformance, which delegates to veraPDF (validate_tagged / validate_metadata
|
|
41
|
+
were removed from this server).
|
|
41
42
|
- No incremental-update history (that is pdf-verify-mcp verify_integrity), and no OCR. It
|
|
42
43
|
does DETECT that OCR is needed and say so: every text-returning tool reports, per page,
|
|
43
44
|
whether the characters could be converted to Unicode at all (ISO 32000-2 §9.10.1) —
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;GAKG;AAEH,8CAA8C;AAC9C,sEAAsE;AACtE,sEAAsE;AACtE,MAAM,mBAAmB,GAAG,OAAO,CAAC,GAAG,CAAC;AACxC,MAAM,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;AAC1C,OAAO,CAAC,GAAG,GAAG,CAAC,GAAG,IAAe,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;AACtE,OAAO,CAAC,IAAI,GAAG,CAAC,GAAG,IAAe,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC,CAAC;AAExE,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE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;IACjB,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,CAAC,KAAK,CAAC,GAAG,WAAW,KAAK,cAAc,oBAAoB,CAAC,CAAC;AACvE,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/schemas/tier3.d.ts
CHANGED
|
@@ -2,23 +2,11 @@
|
|
|
2
2
|
* Zod schemas for Tier 3 tools.
|
|
3
3
|
*/
|
|
4
4
|
import { z } from 'zod';
|
|
5
|
-
/** validate_tagged */
|
|
6
|
-
export declare const ValidateTaggedSchema: z.ZodObject<{
|
|
7
|
-
file_path: z.ZodString;
|
|
8
|
-
response_format: z.ZodDefault<z.ZodEnum<typeof import("../constants.js").ResponseFormat>>;
|
|
9
|
-
}, z.core.$strict>;
|
|
10
|
-
/** validate_metadata */
|
|
11
|
-
export declare const ValidateMetadataSchema: z.ZodObject<{
|
|
12
|
-
file_path: z.ZodString;
|
|
13
|
-
response_format: z.ZodDefault<z.ZodEnum<typeof import("../constants.js").ResponseFormat>>;
|
|
14
|
-
}, z.core.$strict>;
|
|
15
5
|
/** compare_structure */
|
|
16
6
|
export declare const CompareStructureSchema: z.ZodObject<{
|
|
17
7
|
file_path_1: z.ZodString;
|
|
18
8
|
file_path_2: z.ZodString;
|
|
19
9
|
response_format: z.ZodDefault<z.ZodEnum<typeof import("../constants.js").ResponseFormat>>;
|
|
20
10
|
}, z.core.$strict>;
|
|
21
|
-
export type ValidateTaggedInput = z.infer<typeof ValidateTaggedSchema>;
|
|
22
|
-
export type ValidateMetadataInput = z.infer<typeof ValidateMetadataSchema>;
|
|
23
11
|
export type CompareStructureInput = z.infer<typeof CompareStructureSchema>;
|
|
24
12
|
//# sourceMappingURL=tier3.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tier3.d.ts","sourceRoot":"","sources":["../../src/schemas/tier3.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,
|
|
1
|
+
{"version":3,"file":"tier3.d.ts","sourceRoot":"","sources":["../../src/schemas/tier3.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,wBAAwB;AACxB,eAAO,MAAM,sBAAsB;;;;kBAMxB,CAAC;AAGZ,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC"}
|
package/dist/schemas/tier3.js
CHANGED
|
@@ -3,20 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { FilePathSchema, ResponseFormatSchema } from './common.js';
|
|
6
|
-
/** validate_tagged */
|
|
7
|
-
export const ValidateTaggedSchema = z
|
|
8
|
-
.object({
|
|
9
|
-
file_path: FilePathSchema,
|
|
10
|
-
response_format: ResponseFormatSchema,
|
|
11
|
-
})
|
|
12
|
-
.strict();
|
|
13
|
-
/** validate_metadata */
|
|
14
|
-
export const ValidateMetadataSchema = z
|
|
15
|
-
.object({
|
|
16
|
-
file_path: FilePathSchema,
|
|
17
|
-
response_format: ResponseFormatSchema,
|
|
18
|
-
})
|
|
19
|
-
.strict();
|
|
20
6
|
/** compare_structure */
|
|
21
7
|
export const CompareStructureSchema = z
|
|
22
8
|
.object({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tier3.js","sourceRoot":"","sources":["../../src/schemas/tier3.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnE,
|
|
1
|
+
{"version":3,"file":"tier3.js","sourceRoot":"","sources":["../../src/schemas/tier3.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnE,wBAAwB;AACxB,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC;KACpC,MAAM,CAAC;IACN,WAAW,EAAE,cAAc,CAAC,QAAQ,CAAC,oDAAoD,CAAC;IAC1F,WAAW,EAAE,cAAc,CAAC,QAAQ,CAAC,qDAAqD,CAAC;IAC3F,eAAe,EAAE,oBAAoB;CACtC,CAAC;KACD,MAAM,EAAE,CAAC"}
|
|
@@ -83,6 +83,25 @@ export declare const DEFAULT_RENDER_DPI = 150;
|
|
|
83
83
|
* 越えたページは「時間内に描画できなかった」として申告し、次のページへ進む。
|
|
84
84
|
*/
|
|
85
85
|
export declare const DEFAULT_PAGE_TIMEOUT_MS = 20000;
|
|
86
|
+
/** What `import('@hyzyla/pdfium')` returns — the one entry point this file uses. */
|
|
87
|
+
export interface PdfiumModule {
|
|
88
|
+
PDFiumLibrary: {
|
|
89
|
+
init(): Promise<unknown>;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* A loader for the pdfium module that remembers only success (#34).
|
|
94
|
+
*
|
|
95
|
+
* A failed load used to be remembered as `null` for the life of the process, so
|
|
96
|
+
* `RENDERER_MISSING_MESSAGE` ("install it … and call again") could not come
|
|
97
|
+
* true without a restart — MCP hosts keep one server process for the whole
|
|
98
|
+
* conversation. A failed import or init is now forgotten and tried again on the
|
|
99
|
+
* next call. A successful one is kept as a promise, so concurrent first calls
|
|
100
|
+
* still initialise once.
|
|
101
|
+
*
|
|
102
|
+
* `importModule` is injectable so the tests can fail the import, then succeed.
|
|
103
|
+
*/
|
|
104
|
+
export declare function createPdfiumLoader(importModule: () => Promise<PdfiumModule>): () => Promise<unknown | null>;
|
|
86
105
|
/** True when the renderer is available in this installation. */
|
|
87
106
|
export declare function rendererAvailable(): Promise<boolean>;
|
|
88
107
|
export declare const RENDERER_MISSING_MESSAGE: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page-renderer.d.ts","sourceRoot":"","sources":["../../src/services/page-renderer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAQH,mDAAmD;AACnD,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,wCAAwC;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,uEAAuE;IACvE,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,oEAAoE;IACpE,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,6CAA6C;AAC7C,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,aAAa;IAC5B,8EAA8E;IAC9E,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,uEAAuE;IACvE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2CAA2C;IA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tC;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,QAAS,CAAC;AAE9C,oFAAoF;AACpF,MAAM,WAAW,YAAY;IAC3B,aAAa,EAAE;QAAE,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAAA;KAAE,CAAC;CAC7C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAChC,YAAY,EAAE,MAAM,OAAO,CAAC,YAAY,CAAC,GACxC,MAAM,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAa/B;AAcD,gEAAgE;AAChE,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC,CAE1D;AAED,eAAO,MAAM,wBAAwB,QAGgD,CAAC;AAgBtF;;;;;GAKG;AACH,wBAAsB,WAAW,CAC/B,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,YAAY,CAAC,CAiKvB"}
|
|
@@ -47,8 +47,34 @@ export const DEFAULT_RENDER_DPI = 150;
|
|
|
47
47
|
* 越えたページは「時間内に描画できなかった」として申告し、次のページへ進む。
|
|
48
48
|
*/
|
|
49
49
|
export const DEFAULT_PAGE_TIMEOUT_MS = 20_000;
|
|
50
|
-
/**
|
|
51
|
-
|
|
50
|
+
/**
|
|
51
|
+
* A loader for the pdfium module that remembers only success (#34).
|
|
52
|
+
*
|
|
53
|
+
* A failed load used to be remembered as `null` for the life of the process, so
|
|
54
|
+
* `RENDERER_MISSING_MESSAGE` ("install it … and call again") could not come
|
|
55
|
+
* true without a restart — MCP hosts keep one server process for the whole
|
|
56
|
+
* conversation. A failed import or init is now forgotten and tried again on the
|
|
57
|
+
* next call. A successful one is kept as a promise, so concurrent first calls
|
|
58
|
+
* still initialise once.
|
|
59
|
+
*
|
|
60
|
+
* `importModule` is injectable so the tests can fail the import, then succeed.
|
|
61
|
+
*/
|
|
62
|
+
export function createPdfiumLoader(importModule) {
|
|
63
|
+
let pending;
|
|
64
|
+
return async () => {
|
|
65
|
+
pending ??= importModule().then((module) => module.PDFiumLibrary.init());
|
|
66
|
+
const current = pending;
|
|
67
|
+
try {
|
|
68
|
+
return await current;
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
// Forget the failure — unless a later call already started a new attempt.
|
|
72
|
+
if (pending === current)
|
|
73
|
+
pending = undefined;
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
52
78
|
/**
|
|
53
79
|
* Load `@hyzyla/pdfium` if it is installed.
|
|
54
80
|
*
|
|
@@ -56,19 +82,10 @@ let pdfiumLibrary;
|
|
|
56
82
|
* bundler resolves it at build time: the package is optional, and the server
|
|
57
83
|
* must start (and every other tool must work) without it.
|
|
58
84
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const specifier = '@hyzyla/pdfium';
|
|
64
|
-
const module = (await import(specifier));
|
|
65
|
-
pdfiumLibrary = await module.PDFiumLibrary.init();
|
|
66
|
-
}
|
|
67
|
-
catch {
|
|
68
|
-
pdfiumLibrary = null;
|
|
69
|
-
}
|
|
70
|
-
return pdfiumLibrary;
|
|
71
|
-
}
|
|
85
|
+
const loadPdfium = createPdfiumLoader(async () => {
|
|
86
|
+
const specifier = '@hyzyla/pdfium';
|
|
87
|
+
return (await import(specifier));
|
|
88
|
+
});
|
|
72
89
|
/** True when the renderer is available in this installation. */
|
|
73
90
|
export async function rendererAvailable() {
|
|
74
91
|
return (await loadPdfium()) !== null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page-renderer.js","sourceRoot":"","sources":["../../src/services/page-renderer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,iBA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ageExtractionResult, PageText, PdfMetadata, SearchMatch
|
|
8
|
+
import type { AnnotationsAnalysis, ImageExtractionResult, PageText, PdfMetadata, SearchMatch } from '../types.js';
|
|
9
9
|
/**
|
|
10
10
|
* Load a PDF document from a file path.
|
|
11
11
|
*/
|
|
@@ -156,11 +156,6 @@ export declare function extractImages(filePath: string, pages?: string, options?
|
|
|
156
156
|
* `get_metadata` reports the same flag, and the tests assert it.
|
|
157
157
|
*/
|
|
158
158
|
export declare function isTaggedPdf(filePath: string): Promise<boolean>;
|
|
159
|
-
/**
|
|
160
|
-
* Analyze Tagged PDF structure tree from a pre-loaded document.
|
|
161
|
-
* Does NOT destroy the document — caller is responsible for lifecycle.
|
|
162
|
-
*/
|
|
163
|
-
export declare function analyzeTagsFromDoc(doc: PDFDocumentProxy): Promise<TagsAnalysis>;
|
|
164
159
|
/** A `getTextContent({ includeMarkedContent: true })` item. */
|
|
165
160
|
export interface TextContentItemLike {
|
|
166
161
|
type?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pdfjs-service.d.ts","sourceRoot":"","sources":["../../src/services/pdfjs-service.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAIL,KAAK,gBAAgB,EAEtB,MAAM,iCAAiC,CAAC;AAOzC,OAAO,KAAK,EAEV,mBAAmB,EAEnB,qBAAqB,EAErB,QAAQ,EACR,WAAW,EACX,WAAW,
|
|
1
|
+
{"version":3,"file":"pdfjs-service.d.ts","sourceRoot":"","sources":["../../src/services/pdfjs-service.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAIL,KAAK,gBAAgB,EAEtB,MAAM,iCAAiC,CAAC;AAOzC,OAAO,KAAK,EAEV,mBAAmB,EAEnB,qBAAqB,EAErB,QAAQ,EACR,WAAW,EACX,WA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F,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AA8ED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,kBAAkB,EAAE,EAC3B,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAM,GACzC,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CA+ClC;AAED;;;;;;GAMG;AACH,wBAAsB,uBAAuB,CAC3C,GAAG,EAAE,gBAAgB,GACpB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAiB3C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAcjD;AA4CD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAE3D;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,mBAAmB,CAAC,CAgF9B"}
|
|
@@ -668,71 +668,6 @@ function asStringOrNull(value) {
|
|
|
668
668
|
return value;
|
|
669
669
|
return null;
|
|
670
670
|
}
|
|
671
|
-
// ─── Tier 2: Structure analysis functions ────────────────
|
|
672
|
-
/**
|
|
673
|
-
* Analyze Tagged PDF structure tree from a pre-loaded document.
|
|
674
|
-
* Does NOT destroy the document — caller is responsible for lifecycle.
|
|
675
|
-
*/
|
|
676
|
-
export async function analyzeTagsFromDoc(doc) {
|
|
677
|
-
// Check if tagged
|
|
678
|
-
const markInfo = await getMarkInfo(doc);
|
|
679
|
-
const isTagged = markInfo?.Marked === true;
|
|
680
|
-
if (!isTagged) {
|
|
681
|
-
return {
|
|
682
|
-
isTagged: false,
|
|
683
|
-
rootTag: null,
|
|
684
|
-
maxDepth: 0,
|
|
685
|
-
totalElements: 0,
|
|
686
|
-
roleCounts: {},
|
|
687
|
-
};
|
|
688
|
-
}
|
|
689
|
-
// 全ページの構造ツリーを並列取得
|
|
690
|
-
const pageNumbers = Array.from({ length: doc.numPages }, (_, i) => i + 1);
|
|
691
|
-
const pageResults = await Promise.all(pageNumbers.map(async (pageNum) => {
|
|
692
|
-
const page = await doc.getPage(pageNum);
|
|
693
|
-
try {
|
|
694
|
-
const tree = await page.getStructTree();
|
|
695
|
-
if (tree) {
|
|
696
|
-
const localRoleCounts = {};
|
|
697
|
-
const node = buildTagNode(tree, localRoleCounts, 1);
|
|
698
|
-
return { node, roleCounts: localRoleCounts };
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
catch {
|
|
702
|
-
// Some pages may not have structure tree
|
|
703
|
-
}
|
|
704
|
-
return null;
|
|
705
|
-
}));
|
|
706
|
-
// 各ページの結果を集約
|
|
707
|
-
const roleCounts = {};
|
|
708
|
-
let totalElements = 0;
|
|
709
|
-
let maxDepth = 0;
|
|
710
|
-
const rootChildren = [];
|
|
711
|
-
for (const result of pageResults) {
|
|
712
|
-
if (!result)
|
|
713
|
-
continue;
|
|
714
|
-
rootChildren.push(result.node);
|
|
715
|
-
totalElements += countTagElements(result.node);
|
|
716
|
-
maxDepth = Math.max(maxDepth, getTagDepth(result.node));
|
|
717
|
-
// ページごとの roleCounts をマージ
|
|
718
|
-
for (const [role, count] of Object.entries(result.roleCounts)) {
|
|
719
|
-
roleCounts[role] = (roleCounts[role] ?? 0) + count;
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
const rootTag = rootChildren.length > 0
|
|
723
|
-
? { role: 'StructTreeRoot', children: rootChildren, contentCount: 0 }
|
|
724
|
-
: null;
|
|
725
|
-
if (rootTag) {
|
|
726
|
-
maxDepth += 1; // Account for the root level
|
|
727
|
-
}
|
|
728
|
-
return {
|
|
729
|
-
isTagged,
|
|
730
|
-
rootTag,
|
|
731
|
-
maxDepth,
|
|
732
|
-
totalElements,
|
|
733
|
-
roleCounts,
|
|
734
|
-
};
|
|
735
|
-
}
|
|
736
671
|
/**
|
|
737
672
|
* Build a map from a marked-content `id` (e.g. `p715R_mc4`) to the concatenated
|
|
738
673
|
* raw text inside the corresponding `beginMarkedContentProps`/`endMarkedContent`
|
|
@@ -1173,37 +1108,4 @@ export async function analyzeAnnotations(filePath, pages) {
|
|
|
1173
1108
|
await doc.destroy();
|
|
1174
1109
|
}
|
|
1175
1110
|
}
|
|
1176
|
-
function buildTagNode(node, roleCounts, depth) {
|
|
1177
|
-
const role = node.role ?? 'Unknown';
|
|
1178
|
-
roleCounts[role] = (roleCounts[role] ?? 0) + 1;
|
|
1179
|
-
const children = [];
|
|
1180
|
-
let contentCount = 0;
|
|
1181
|
-
if (node.children) {
|
|
1182
|
-
for (const child of node.children) {
|
|
1183
|
-
if ('role' in child) {
|
|
1184
|
-
children.push(buildTagNode(child, roleCounts, depth + 1));
|
|
1185
|
-
}
|
|
1186
|
-
else {
|
|
1187
|
-
contentCount++;
|
|
1188
|
-
}
|
|
1189
|
-
}
|
|
1190
|
-
}
|
|
1191
|
-
return { role, children, contentCount };
|
|
1192
|
-
}
|
|
1193
|
-
function countTagElements(node) {
|
|
1194
|
-
let count = 1;
|
|
1195
|
-
for (const child of node.children) {
|
|
1196
|
-
count += countTagElements(child);
|
|
1197
|
-
}
|
|
1198
|
-
return count;
|
|
1199
|
-
}
|
|
1200
|
-
function getTagDepth(node) {
|
|
1201
|
-
if (node.children.length === 0)
|
|
1202
|
-
return 1;
|
|
1203
|
-
let max = 0;
|
|
1204
|
-
for (const child of node.children) {
|
|
1205
|
-
max = Math.max(max, getTagDepth(child));
|
|
1206
|
-
}
|
|
1207
|
-
return max + 1;
|
|
1208
|
-
}
|
|
1209
1111
|
//# sourceMappingURL=pdfjs-service.js.map
|