@embedpdf-editor/vue3-chapter-viewer 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +473 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +221 -28
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3385 -2885
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/README.md
ADDED
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
# @embedpdf-editor/vue3-chapter-viewer
|
|
2
|
+
|
|
3
|
+
面向 Vue 3 的**章节 PDF 阅读器**统一入口:多章 PDF 纵向拼接滚动、划词高亮/划线、段落书签、选区笔记,以及可选缩放。
|
|
4
|
+
|
|
5
|
+
业务侧只需安装本包与 `vue`;PDFium(`@embedpdf/engines`)、`scheduler` 及阅读器依赖的 `@embedpdf/*` 插件由本包 **dependencies** 带入,**不必**在业务 `package.json` 里逐个声明 `@embedpdf/engines` 等。
|
|
6
|
+
|
|
7
|
+
> 组件样式以 **inline style** 为主,**不需要** Tailwind。
|
|
8
|
+
> 下文提供可直接复制到业务项目中的完整示例(不依赖仓库内 demo 工程)。
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 安装
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add @embedpdf-editor/vue3-chapter-viewer
|
|
16
|
+
# 或 npm / yarn
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
| 依赖 | 说明 |
|
|
20
|
+
|------|------|
|
|
21
|
+
| `vue` | **peerDependencies**(建议 Vue 3.3+) |
|
|
22
|
+
| 本包 `dependencies` | 已包含 `@embedpdf/engines`、`scheduler`、章节插件与 `editor-engine` |
|
|
23
|
+
|
|
24
|
+
在业务入口注册本包组件前,请确保已 `import { createApp } from 'vue'` 并正常挂载应用(与常规 Vue 3 项目一致)。
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Vite 项目(推荐)
|
|
29
|
+
|
|
30
|
+
若 dev 时出现 `scheduler` 解析失败,可合并本包提供的 Vite 片段(将 `scheduler` 指到本包依赖目录并加入预构建):
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
// vite.config.ts
|
|
34
|
+
import { defineConfig, mergeConfig } from 'vite';
|
|
35
|
+
import vue from '@vitejs/plugin-vue';
|
|
36
|
+
import { chapterViewerViteResolve } from '@embedpdf-editor/vue3-chapter-viewer/vite';
|
|
37
|
+
|
|
38
|
+
export default mergeConfig(
|
|
39
|
+
defineConfig({
|
|
40
|
+
plugins: [vue()],
|
|
41
|
+
}),
|
|
42
|
+
chapterViewerViteResolve(),
|
|
43
|
+
);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## 你需要准备的数据
|
|
49
|
+
|
|
50
|
+
阅读器**不内置**目录与 PDF 文件,全部由业务提供。
|
|
51
|
+
|
|
52
|
+
### 1. `ChapterManifest`(引擎用)
|
|
53
|
+
|
|
54
|
+
描述每一章对应的 PDF 与在「整本」中的页码区间:
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import type { ChapterManifest } from '@embedpdf-editor/vue3-chapter-viewer';
|
|
58
|
+
|
|
59
|
+
const manifest: ChapterManifest = {
|
|
60
|
+
chapters: [
|
|
61
|
+
{
|
|
62
|
+
chapterId: '001_封面', // 唯一 ID,同时作为 documentId
|
|
63
|
+
title: '封面',
|
|
64
|
+
globalPageRange: [1, 1], // 在整本中的全局页(闭区间)
|
|
65
|
+
localPageRange: [0, 0], // 该 PDF 内 0-based 页(页数须与 global 一致)
|
|
66
|
+
source: { url: '/001_封面.pdf' }, // 或 buffer / load()
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
chapterId: '002_前言',
|
|
70
|
+
title: '前言',
|
|
71
|
+
globalPageRange: [2, 5],
|
|
72
|
+
localPageRange: [0, 3],
|
|
73
|
+
source: { url: '/002_前言.pdf' },
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
};
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**`ChapterSource` 三种写法:**
|
|
80
|
+
|
|
81
|
+
| 写法 | 场景 |
|
|
82
|
+
|------|------|
|
|
83
|
+
| `{ url: string }` | 静态或可直链的 PDF |
|
|
84
|
+
| `{ buffer: ArrayBuffer }` | 已下载的二进制 |
|
|
85
|
+
| `{ load: () => Promise<{ url } \| { buffer }> }` | 单章自定义拉取(鉴权等) |
|
|
86
|
+
|
|
87
|
+
若 manifest 里**未写** `source`,需传入全局加载器 `chapterPdfLoader`(实现 `IChapterPdfLoader.loadPdf(chapter)`)。
|
|
88
|
+
|
|
89
|
+
相邻章节的 `globalPageRange` **允许重叠**(例如上下章各含一页过渡页);默认按 `first-wins` 解析归属。
|
|
90
|
+
|
|
91
|
+
### 2. `ChapterViewerCatalog`(带目录树时)
|
|
92
|
+
|
|
93
|
+
左侧章节目录由业务构造,与 manifest 对应:
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
import type { ChapterViewerCatalog } from '@embedpdf-editor/vue3-chapter-viewer';
|
|
97
|
+
|
|
98
|
+
const catalog: ChapterViewerCatalog = {
|
|
99
|
+
tree: [
|
|
100
|
+
{ id: '001_封面', title: '封面', startPage: 1, endPage: 1 },
|
|
101
|
+
{
|
|
102
|
+
id: '002_前言',
|
|
103
|
+
title: '前言',
|
|
104
|
+
startPage: 2,
|
|
105
|
+
endPage: 5,
|
|
106
|
+
children: [/* 可选子节点 */],
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
manifest,
|
|
110
|
+
};
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
`tree` 仅用于 UI;真正加载 PDF 以 `manifest.chapters` 为准。
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## 快速开始:`<ChapterPdfViewer />`
|
|
118
|
+
|
|
119
|
+
适合「单容器铺满、manifest 已就绪」的页面。推荐只传 **`options`**(不必再拆 `editorOptions` + `features`,也不必包一层 `callbacks`)。
|
|
120
|
+
|
|
121
|
+
`usePdfiumEngine()` 返回的是 **ref**,模板里会自动解包;在 `<script setup>` 中请使用 `engine.value`。
|
|
122
|
+
|
|
123
|
+
```vue
|
|
124
|
+
<script setup lang="ts">
|
|
125
|
+
import { computed } from 'vue';
|
|
126
|
+
import {
|
|
127
|
+
usePdfiumEngine,
|
|
128
|
+
ChapterPdfViewer,
|
|
129
|
+
type ChapterManifest,
|
|
130
|
+
type ChapterViewerOptions,
|
|
131
|
+
} from '@embedpdf-editor/vue3-chapter-viewer';
|
|
132
|
+
|
|
133
|
+
const props = defineProps<{ manifest: ChapterManifest }>();
|
|
134
|
+
const { engine, isLoading, error } = usePdfiumEngine();
|
|
135
|
+
|
|
136
|
+
const options = computed<ChapterViewerOptions>(() => ({
|
|
137
|
+
manifest: props.manifest,
|
|
138
|
+
bookmarks: {
|
|
139
|
+
load: () => fetchBookmarks(),
|
|
140
|
+
persist: (list) => saveBookmarks(list),
|
|
141
|
+
onRequestRemove: async (b) => {
|
|
142
|
+
await api.deleteBookmark(b.id);
|
|
143
|
+
return true;
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
notes: {
|
|
147
|
+
loadNotes: () => fetchNotes(),
|
|
148
|
+
onRequestCreateNote: ({ draft, complete }) => {
|
|
149
|
+
openCreateModal(draft).then((noteId) => complete(noteId));
|
|
150
|
+
},
|
|
151
|
+
onRequestEditNote: (noteId) => openEditModal(noteId),
|
|
152
|
+
onDeleteNote: (id) => api.deleteNote(id),
|
|
153
|
+
},
|
|
154
|
+
features: {
|
|
155
|
+
zoom: { pageWidth: 800 },
|
|
156
|
+
},
|
|
157
|
+
}));
|
|
158
|
+
</script>
|
|
159
|
+
|
|
160
|
+
<template>
|
|
161
|
+
<div v-if="error" style="padding: 16px">引擎失败:{{ error.message }}</div>
|
|
162
|
+
<div v-else-if="isLoading || !engine" style="padding: 16px">正在加载 PDFium…</div>
|
|
163
|
+
<ChapterPdfViewer
|
|
164
|
+
v-else
|
|
165
|
+
:engine="engine"
|
|
166
|
+
:options="options"
|
|
167
|
+
style="height: 100vh; width: 100%"
|
|
168
|
+
/>
|
|
169
|
+
</template>
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### 笔记弹窗(推荐 `onRequestCreateNote`)
|
|
173
|
+
|
|
174
|
+
阅读器不会自带 Modal,需在宿主里监听 `onRequestCreateNote` / `onRequestEditNote`,弹窗确认后调用 `complete(noteId)` 或 `onUpdateNote`:
|
|
175
|
+
|
|
176
|
+
```vue
|
|
177
|
+
<script setup lang="ts">
|
|
178
|
+
import { ref, shallowRef } from 'vue';
|
|
179
|
+
import type { NoteDraft } from '@embedpdf-editor/vue3-chapter-viewer';
|
|
180
|
+
|
|
181
|
+
const pendingCreate = shallowRef<{
|
|
182
|
+
draft: NoteDraft;
|
|
183
|
+
complete: (noteId: string) => void | Promise<void>;
|
|
184
|
+
} | null>(null);
|
|
185
|
+
|
|
186
|
+
function onRequestCreateNote(payload: {
|
|
187
|
+
draft: NoteDraft;
|
|
188
|
+
complete: (noteId: string) => void | Promise<void>;
|
|
189
|
+
}) {
|
|
190
|
+
pendingCreate.value = payload;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async function confirmCreate(content: string) {
|
|
194
|
+
const pending = pendingCreate.value;
|
|
195
|
+
if (!pending) return;
|
|
196
|
+
const noteId = await api.createNote({ ...pending.draft, content });
|
|
197
|
+
await pending.complete(noteId);
|
|
198
|
+
pendingCreate.value = null;
|
|
199
|
+
}
|
|
200
|
+
</script>
|
|
201
|
+
|
|
202
|
+
<template>
|
|
203
|
+
<!-- YourNoteModal:业务自有组件 -->
|
|
204
|
+
<YourNoteModal
|
|
205
|
+
:open="!!pendingCreate"
|
|
206
|
+
:quoted-text="pendingCreate?.draft.selectedText"
|
|
207
|
+
@confirm="confirmCreate"
|
|
208
|
+
@cancel="pendingCreate = null"
|
|
209
|
+
/>
|
|
210
|
+
</template>
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
将 `onRequestCreateNote` 传入上一节的 `options.notes` 即可。
|
|
214
|
+
|
|
215
|
+
### `features` 简写
|
|
216
|
+
|
|
217
|
+
| 写法 | 含义 |
|
|
218
|
+
|------|------|
|
|
219
|
+
| 省略 | 划线、书签、笔记、选区浮窗、缩放 **全部开启** |
|
|
220
|
+
| `markup: false` | 关闭划词高亮/划线 |
|
|
221
|
+
| `zoom: false` | 关闭缩放 |
|
|
222
|
+
| `zoom: { pageWidth: 800 }` | 按宽度适配 |
|
|
223
|
+
|
|
224
|
+
**交互说明(默认开启时):**
|
|
225
|
+
|
|
226
|
+
- 划词 → 浮窗:高亮、下划线、波浪线、删除线、笔记
|
|
227
|
+
- 鼠标移到文本行末 → 显示「添加书签」;已加书签点击 → 删除确认(走 `onRequestRemove`)
|
|
228
|
+
- 笔记区域悬停 → 编辑 / 删除
|
|
229
|
+
- **缩放**:`features.zoom.enabled !== false` 时,在 PDF 滚动区域内 **`Ctrl/Cmd + 滚轮`** 或 **双指捏合**(触控板)缩放;缩放写入 core 的 `document.scale`,PDF 与书签/笔记 overlay 同步变化
|
|
230
|
+
|
|
231
|
+
> 普通滚轮用于上下滚动章节,不会触发缩放;Mac 触控板请按住 Ctrl 或双指捏合。
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
## 进阶:自定义布局(目录 + 首章预加载)
|
|
236
|
+
|
|
237
|
+
需要**左侧章节目录**、或要在挂载视口前**先 `ensureChapterLoaded`** 时,不要用一站式 `<ChapterPdfViewer />`,改用:
|
|
238
|
+
|
|
239
|
+
`createChapterViewerBundle` → `EmbedPDF` → `ChapterTreePanel` + `PdfChapterViewport`
|
|
240
|
+
|
|
241
|
+
**步骤简述:**
|
|
242
|
+
|
|
243
|
+
1. 用 `createChapterViewerBundle(options)` 得到 `{ plugins, features }`(`options` 与上一节相同)。
|
|
244
|
+
2. 用 `<EmbedPDF>` 挂载 `plugins`,在 scoped slot 里等 `pluginsReady === true` 再渲染子树。
|
|
245
|
+
3. 在 `EmbedPDF` 子树内用 `useCapability(ChapterManagerPlugin.id)` 对首章调用 `ensureChapterLoaded`。
|
|
246
|
+
4. 章节状态为 `loaded` 后再挂载 `<PdfChapterViewport :features="bundle.features" />`。
|
|
247
|
+
|
|
248
|
+
**父页面(可复制):**
|
|
249
|
+
|
|
250
|
+
```vue
|
|
251
|
+
<script setup lang="ts">
|
|
252
|
+
import { computed } from 'vue';
|
|
253
|
+
import {
|
|
254
|
+
usePdfiumEngine,
|
|
255
|
+
EmbedPDF,
|
|
256
|
+
createChapterViewerBundle,
|
|
257
|
+
type ChapterViewerCatalog,
|
|
258
|
+
type ChapterViewerOptions,
|
|
259
|
+
} from '@embedpdf-editor/vue3-chapter-viewer';
|
|
260
|
+
import ChapterWorkspace from './ChapterWorkspace.vue';
|
|
261
|
+
|
|
262
|
+
const props = defineProps<{
|
|
263
|
+
catalog: ChapterViewerCatalog;
|
|
264
|
+
notes: ChapterViewerOptions['notes'];
|
|
265
|
+
bookmarks: ChapterViewerOptions['bookmarks'];
|
|
266
|
+
}>();
|
|
267
|
+
|
|
268
|
+
const { engine, isLoading, error } = usePdfiumEngine();
|
|
269
|
+
|
|
270
|
+
const bundle = computed(() =>
|
|
271
|
+
createChapterViewerBundle({
|
|
272
|
+
manifest: props.catalog.manifest,
|
|
273
|
+
notes: props.notes,
|
|
274
|
+
bookmarks: props.bookmarks,
|
|
275
|
+
features: { zoom: { pageWidth: 800 } },
|
|
276
|
+
}),
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
const firstChapterId = computed(
|
|
280
|
+
() => props.catalog.manifest.chapters[0]?.chapterId ?? '',
|
|
281
|
+
);
|
|
282
|
+
</script>
|
|
283
|
+
|
|
284
|
+
<template>
|
|
285
|
+
<div v-if="error">引擎失败:{{ error.message }}</div>
|
|
286
|
+
<div v-else-if="isLoading || !engine">正在加载 PDFium…</div>
|
|
287
|
+
<div v-else style="height: 100vh; display: flex; flex-direction: column">
|
|
288
|
+
<EmbedPDF :engine="engine" :plugins="bundle.plugins">
|
|
289
|
+
<template #default="{ pluginsReady }">
|
|
290
|
+
<ChapterWorkspace
|
|
291
|
+
v-if="pluginsReady"
|
|
292
|
+
:tree="catalog.tree"
|
|
293
|
+
:first-chapter-id="firstChapterId"
|
|
294
|
+
:features="bundle.features"
|
|
295
|
+
/>
|
|
296
|
+
<div v-else>正在初始化插件…</div>
|
|
297
|
+
</template>
|
|
298
|
+
</EmbedPDF>
|
|
299
|
+
</div>
|
|
300
|
+
</template>
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
**`ChapterWorkspace.vue`(须在 `EmbedPDF` 子树内):**
|
|
304
|
+
|
|
305
|
+
```vue
|
|
306
|
+
<script setup lang="ts">
|
|
307
|
+
import { ref, watch } from 'vue';
|
|
308
|
+
import {
|
|
309
|
+
useCapability,
|
|
310
|
+
ChapterManagerPlugin,
|
|
311
|
+
ChapterTreePanel,
|
|
312
|
+
PdfChapterViewport,
|
|
313
|
+
type ChapterViewerFeaturesConfig,
|
|
314
|
+
type ChapterTreeNode,
|
|
315
|
+
} from '@embedpdf-editor/vue3-chapter-viewer';
|
|
316
|
+
|
|
317
|
+
const props = defineProps<{
|
|
318
|
+
tree: ChapterTreeNode[];
|
|
319
|
+
firstChapterId: string;
|
|
320
|
+
features: ChapterViewerFeaturesConfig;
|
|
321
|
+
}>();
|
|
322
|
+
|
|
323
|
+
const activeChapterId = ref(props.firstChapterId);
|
|
324
|
+
const chapterReady = ref(false);
|
|
325
|
+
|
|
326
|
+
const { provides: chapterManager } = useCapability<ChapterManagerPlugin>(
|
|
327
|
+
ChapterManagerPlugin.id,
|
|
328
|
+
);
|
|
329
|
+
|
|
330
|
+
watch(
|
|
331
|
+
[chapterManager, () => props.firstChapterId],
|
|
332
|
+
([mgr, chapterId], _prev, onCleanup) => {
|
|
333
|
+
if (!mgr || !chapterId) return;
|
|
334
|
+
|
|
335
|
+
let cancelled = false;
|
|
336
|
+
chapterReady.value = false;
|
|
337
|
+
|
|
338
|
+
const unsub = mgr.onChapterStatusChange(() => {
|
|
339
|
+
if (cancelled) return;
|
|
340
|
+
if (mgr.getChapterStatus(chapterId) === 'loaded') chapterReady.value = true;
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
void mgr.ensureChapterLoaded(chapterId).then((status) => {
|
|
344
|
+
if (!cancelled && status === 'loaded') chapterReady.value = true;
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
onCleanup(() => {
|
|
348
|
+
cancelled = true;
|
|
349
|
+
unsub();
|
|
350
|
+
});
|
|
351
|
+
},
|
|
352
|
+
{ immediate: true },
|
|
353
|
+
);
|
|
354
|
+
</script>
|
|
355
|
+
|
|
356
|
+
<template>
|
|
357
|
+
<div style="display: flex; flex: 1; min-height: 0; gap: 12px">
|
|
358
|
+
<ChapterTreePanel
|
|
359
|
+
:tree="tree"
|
|
360
|
+
:active-chapter-id="activeChapterId"
|
|
361
|
+
@active-chapter-change="activeChapterId = $event"
|
|
362
|
+
/>
|
|
363
|
+
<div style="flex: 1; min-width: 0; min-height: 0; position: relative">
|
|
364
|
+
<div v-if="chapterReady" style="position: absolute; inset: 0">
|
|
365
|
+
<PdfChapterViewport :features="features" />
|
|
366
|
+
</div>
|
|
367
|
+
<div v-else style="padding: 16px">正在加载章节 PDF…</div>
|
|
368
|
+
</div>
|
|
369
|
+
</div>
|
|
370
|
+
</template>
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
切换目录项时,可对新的 `activeChapterId` 同样调用 `ensureChapterLoaded`(`ChapterTreePanel` 内部也会触发章节加载,按产品需求组合使用即可)。
|
|
374
|
+
|
|
375
|
+
---
|
|
376
|
+
|
|
377
|
+
## 笔记与书签回调
|
|
378
|
+
|
|
379
|
+
直接写在 `options.notes` / `options.bookmarks`(不再嵌套 `callbacks`)。
|
|
380
|
+
|
|
381
|
+
### 笔记 `options.notes`
|
|
382
|
+
|
|
383
|
+
| 回调 | 说明 |
|
|
384
|
+
|------|------|
|
|
385
|
+
| `loadNotes` | 初始化加载已有笔记 |
|
|
386
|
+
| `onRequestCreateNote` | **推荐**:宿主弹窗后 `complete(noteId)` |
|
|
387
|
+
| `onCreateNote` | 内置创建(与上一项二选一) |
|
|
388
|
+
| `onRequestEditNote` / `onUpdateNote` / `onDeleteNote` | 编辑、更新、删除 |
|
|
389
|
+
|
|
390
|
+
### 书签 `options.bookmarks`
|
|
391
|
+
|
|
392
|
+
| 回调 | 说明 |
|
|
393
|
+
|------|------|
|
|
394
|
+
| `load` | 加载已有书签 |
|
|
395
|
+
| `persist` | 增删改后持久化 |
|
|
396
|
+
| `onRequestRemove` | 删除确认,返回 `true` 后从渲染层移除 |
|
|
397
|
+
|
|
398
|
+
---
|
|
399
|
+
|
|
400
|
+
## 内部默认(无需配置)
|
|
401
|
+
|
|
402
|
+
以下由引擎内置,业务**不用**再写:`overlapStrategy`、`passwordProvider`、`prefetchChapters`、`loadDefaultStampLibrary`、`toolbar`(Annotate 模式栏已关闭)等。需要改时再使用进阶 API `createPdfChapterEditor`。
|
|
403
|
+
|
|
404
|
+
---
|
|
405
|
+
|
|
406
|
+
## 主要导出
|
|
407
|
+
|
|
408
|
+
| 导出 | 用途 |
|
|
409
|
+
|------|------|
|
|
410
|
+
| `ChapterPdfViewer` | 一站式阅读器(传 `engine` + `options`) |
|
|
411
|
+
| `createChapterViewerBundle` | 生成 `{ plugins, features }`(自定义布局) |
|
|
412
|
+
| `PdfChapterViewport` | 仅视口(需在 `EmbedPDF` 内) |
|
|
413
|
+
| `ChapterTreePanel` | 章节目录树 |
|
|
414
|
+
| `EmbedPDF` / `useCapability` | 插件宿主与能力钩子 |
|
|
415
|
+
| `usePdfiumEngine` | PDFium 引擎(返回 ref) |
|
|
416
|
+
| `ChapterManagerPlugin` | 章节加载(`ensureChapterLoaded`) |
|
|
417
|
+
| `ChapterViewerOptions` | `options` 的类型 |
|
|
418
|
+
| `ChapterViewerConfig` | `options.features` 的类型 |
|
|
419
|
+
| `ChapterManifest` / `ChapterDescriptor` / `IChapterPdfLoader` | 数据与加载契约 |
|
|
420
|
+
| `ChapterViewerCatalog` / `ChapterTreeNode` | 目录树类型 |
|
|
421
|
+
| `applySelectionMarkup` | 编程式应用划线(高级) |
|
|
422
|
+
| `chapterViewerViteResolve` | Vite 配置辅助(`/vite` 子路径) |
|
|
423
|
+
|
|
424
|
+
类型详见 `dist/index.d.ts`。
|
|
425
|
+
|
|
426
|
+
---
|
|
427
|
+
|
|
428
|
+
## 接入检查清单
|
|
429
|
+
|
|
430
|
+
在业务项目中接入时,请确认:
|
|
431
|
+
|
|
432
|
+
1. **静态资源**:`manifest` 里每章 `source.url` 可被浏览器访问(或实现 `chapterPdfLoader` / `load()`)。
|
|
433
|
+
2. **目录数据**:若使用 `ChapterTreePanel`,自行从后端组装 `ChapterViewerCatalog`(`tree` + `manifest` 字段一致)。
|
|
434
|
+
3. **首章加载**:自定义布局下,首章 `ensureChapterLoaded` 返回 `loaded` 后再挂载 `PdfChapterViewport`。
|
|
435
|
+
4. **笔记 UI**:`onRequestCreateNote` 需在宿主弹窗后调用 `complete(noteId)`。
|
|
436
|
+
5. **Vue ref**:`usePdfiumEngine()` 的 `engine` 在 script 中为 ref,传给 `ChapterPdfViewer` 时模板写 `:engine="engine"` 即可。
|
|
437
|
+
|
|
438
|
+
本包随 npm 发布,**不包含**可运行的示例站点或 mock 数据;请以上文代码片段为模板,在业务仓库中创建页面并放置自有 PDF。
|
|
439
|
+
|
|
440
|
+
---
|
|
441
|
+
|
|
442
|
+
## 其他框架
|
|
443
|
+
|
|
444
|
+
| 包 | 说明 |
|
|
445
|
+
|----|------|
|
|
446
|
+
| `@embedpdf-editor/react-chapter-viewer` | React 18+ |
|
|
447
|
+
| `@embedpdf-editor/chapter-snippet` | Vue 2.6+ Web Component / 无构建集成 |
|
|
448
|
+
|
|
449
|
+
能力与 React 版视口内核对齐;API 命名一致,仅组合方式随框架变化。
|
|
450
|
+
|
|
451
|
+
---
|
|
452
|
+
|
|
453
|
+
## 常见问题
|
|
454
|
+
|
|
455
|
+
**Q:页面一直「正在加载」?**
|
|
456
|
+
确认 `manifest` 中每章 `source.url` 可访问,或 `chapterPdfLoader` / `ensureChapterLoaded` 返回 `loaded`。首章未加载完成时不要提前挂载 `PdfChapterViewport`。
|
|
457
|
+
|
|
458
|
+
**Q:需要用户安装 `@embedpdf/engines` 吗?**
|
|
459
|
+
不需要,已作为本包依赖。只需 `vue`。
|
|
460
|
+
|
|
461
|
+
**Q:如何关闭缩放?**
|
|
462
|
+
`features: { zoom: false }`,或 `zoom: { enabled: false }`。
|
|
463
|
+
|
|
464
|
+
**Q:`zoom.enabled: true` 但缩放手势没反应?**
|
|
465
|
+
1. 确认使用 `<ChapterPdfViewer />` 或 `<PdfChapterViewport :features="..." />`(缩放逻辑在视口内)。
|
|
466
|
+
2. 在 PDF 区域使用 **Ctrl/Cmd + 滚轮**,不要用普通滚轮。
|
|
467
|
+
3. 升级 `@embedpdf-editor/vue3-chapter-viewer` 后硬刷新浏览器。
|
|
468
|
+
|
|
469
|
+
**Q:笔记弹窗想完全自定义?**
|
|
470
|
+
使用 `onRequestCreateNote` + `complete(noteId)`,不要实现 `onCreateNote`。
|
|
471
|
+
|
|
472
|
+
**Q:`useCapability` 报错 “must be used inside EmbedPDF”?**
|
|
473
|
+
`ChapterWorkspace` 等子组件必须渲染在 `<EmbedPDF>` 的默认 slot 内,不能与它平级。
|