@embedpdf-editor/vue3-chapter-viewer 1.0.2 → 1.0.4
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 +29 -51
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +57 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5937 -4757
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -140,7 +140,8 @@ type ChapterManifest = {
|
|
|
140
140
|
| { url: string }
|
|
141
141
|
| { buffer: ArrayBuffer }
|
|
142
142
|
| { load: () => Promise<{ url: string } | { buffer: ArrayBuffer }> }
|
|
143
|
-
| { urls: string[]; segmentPageThreshold: number };
|
|
143
|
+
| { urls: string[]; segmentPageThreshold: number }; // legacy
|
|
144
|
+
segmentPageThreshold?: number;
|
|
144
145
|
encrypted?: boolean;
|
|
145
146
|
ownedGlobalPages?: number[];
|
|
146
147
|
}>;
|
|
@@ -210,64 +211,40 @@ const options: ChapterViewerOptions = {
|
|
|
210
211
|
|
|
211
212
|
### PDF 加载与预处理
|
|
212
213
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
1. `chapter.source.url` / `source.buffer` — 直接使用
|
|
216
|
-
2. `chapter.source.load()` — **按章**异步预处理,返回 `{ url }` 或 `{ buffer }`
|
|
217
|
-
3. `chapterPdfLoader.loadPdf(chapter)` — **全局**统一逻辑
|
|
218
|
-
|
|
219
|
-
**按章 `source.load`(单章解密、鉴权 URL):**
|
|
220
|
-
|
|
221
|
-
```ts
|
|
222
|
-
{
|
|
223
|
-
chapterId: 'ch-1',
|
|
224
|
-
title: '第一章',
|
|
225
|
-
globalPageRange: [1, 10],
|
|
226
|
-
localPageRange: [0, 9],
|
|
227
|
-
source: {
|
|
228
|
-
load: async () => {
|
|
229
|
-
const bytes = await fetchDecryptedPdf('ch-1');
|
|
230
|
-
return { buffer: bytes };
|
|
231
|
-
// 或 return { url: URL.createObjectURL(blob) };
|
|
232
|
-
},
|
|
233
|
-
},
|
|
234
|
-
}
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
**全局 `chapterPdfLoader`(所有章走同一套 API):**
|
|
214
|
+
与 React 包一致,推荐 **三步 `chapterPdfLoader`**:`loadChapterUrls` → 可选 `openPdf`。
|
|
215
|
+
`loadChapterUrls` **每章只请求一次**(引擎缓存);PDF 按段各打开一次。
|
|
238
216
|
|
|
239
217
|
```ts
|
|
240
|
-
import type { ChapterViewerOptions,
|
|
241
|
-
|
|
242
|
-
const loader: IChapterPdfLoader = {
|
|
243
|
-
async loadPdf(chapter, segmentIndex) {
|
|
244
|
-
const res = await api.getChapterPdf(chapter.chapterId, segmentIndex ?? 0);
|
|
245
|
-
return { url: res.signedUrl };
|
|
246
|
-
// 或 return { buffer: await res.arrayBuffer() };
|
|
247
|
-
},
|
|
248
|
-
};
|
|
218
|
+
import type { ChapterViewerOptions, ChapterPdfLoadContext } from '@embedpdf-editor/vue3-chapter-viewer';
|
|
249
219
|
|
|
250
220
|
const options: ChapterViewerOptions = {
|
|
251
|
-
manifest: {
|
|
252
|
-
|
|
221
|
+
manifest: {
|
|
222
|
+
chapters: [
|
|
223
|
+
{
|
|
224
|
+
chapterId: 'ch-1',
|
|
225
|
+
title: '第一章',
|
|
226
|
+
globalPageRange: [1, 13],
|
|
227
|
+
localPageRange: [0, 12],
|
|
228
|
+
segmentPageThreshold: 5,
|
|
229
|
+
},
|
|
230
|
+
],
|
|
231
|
+
},
|
|
232
|
+
chapterPdfLoader: {
|
|
233
|
+
async loadChapterUrls(chapter) {
|
|
234
|
+
const res = await getOneChap(chapter.chapterId);
|
|
235
|
+
const raw = res.data.resourceUrl;
|
|
236
|
+
return Array.isArray(raw) ? raw : raw ? [raw] : [];
|
|
237
|
+
},
|
|
238
|
+
async openPdf(ctx: ChapterPdfLoadContext) {
|
|
239
|
+
return { url: ctx.url };
|
|
240
|
+
},
|
|
241
|
+
},
|
|
253
242
|
notes: { /* ... */ },
|
|
254
243
|
bookmarks: { /* ... */ },
|
|
255
244
|
};
|
|
256
245
|
```
|
|
257
246
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
```ts
|
|
261
|
-
source: {
|
|
262
|
-
urls: [part0Url, part1Url, part2Url],
|
|
263
|
-
segmentPageThreshold: 5, // 13 页 → 3 段
|
|
264
|
-
},
|
|
265
|
-
```
|
|
266
|
-
|
|
267
|
-
- 先加载 `urls[0]`,滚动时懒加载后续段。
|
|
268
|
-
- `localPageIndex` 为章内 0-based 连续页;Vue 侧无需为分段改 `features`。
|
|
269
|
-
- 业务持久化:**`chapterId` + `localPageIndex`**,勿存 `chapterId#sN`。
|
|
270
|
-
- 导出划线会加载全部分段并合并页码。
|
|
247
|
+
静态单文件仍可用 `source.url` / `load()`。兼容 `loadPdf(chapter, segmentIndex)`。
|
|
271
248
|
|
|
272
249
|
[03-manifest.md](../../docs/get-started/03-manifest.md) · [12-segmented-pdf-and-per-chapter-storage.md](../../docs/get-started/12-segmented-pdf-and-per-chapter-storage.md)
|
|
273
250
|
|
|
@@ -299,7 +276,7 @@ const passwordProvider = new CallbackPasswordProvider(async (chapter, attempt) =
|
|
|
299
276
|
| `notes` | `enabled`、`marker`(`renderIcon`、`renderMenuActions`、`iconSize`、`highlightColor`) |
|
|
300
277
|
| `zoom` | `enabled`(默认 true)、`min` 0.5、`max` 3、`initial` 1、`pageWidth`;实际上限由 `[data-chapter-scroll-viewport]` 宽度决定,resize 时自动更新 |
|
|
301
278
|
| `scrollViewport` | `background`(默认 `#f1f5f9`),滚动视口背景 |
|
|
302
|
-
| `selectionToolbar` | `enabled`、`hiddenBuiltinActions`(含 `copy`)、`renderCopyIcon`、`extraActions` |
|
|
279
|
+
| `selectionToolbar` | `enabled`、`selectionBackground`(划词底色)、`hiddenBuiltinActions`(含 `copy`)、`renderCopyIcon`、`extraActions` |
|
|
303
280
|
|
|
304
281
|
默认划线 `offsetY`:`squiggly` 为 **4**。内置工具条顺序:**`copy`** → 划线类 → 扩展 → **`note`**。
|
|
305
282
|
|
|
@@ -417,6 +394,7 @@ import { h } from 'vue';
|
|
|
417
394
|
|
|
418
395
|
features: {
|
|
419
396
|
selectionToolbar: {
|
|
397
|
+
selectionBackground: 'rgba(255, 193, 7, 0.35)',
|
|
420
398
|
// hiddenBuiltinActions: ['copy'],
|
|
421
399
|
renderCopyIcon: () =>
|
|
422
400
|
h('span', { 'aria-hidden': true, style: { fontSize: '18px' } }, '📋'),
|