@embedpdf-editor/vue3-chapter-viewer 1.0.0 → 1.0.3
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 +81 -43
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +101 -22
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8304 -4679
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -131,6 +131,11 @@ export declare interface ChapterDescriptor {
|
|
|
131
131
|
* PDF 来源。可省略:须在 ChapterManager 配置 `chapterPdfLoader` 中统一加载。
|
|
132
132
|
*/
|
|
133
133
|
source?: ChapterSource;
|
|
134
|
+
/**
|
|
135
|
+
* 章内多 PDF 分段时,每段最多页数(如 5 表示 13 页 → 3 段)。
|
|
136
|
+
* URL 由 `chapterPdfLoader.loadChapterUrls` 按章拉取,**不要**写在 `source` 里。
|
|
137
|
+
*/
|
|
138
|
+
segmentPageThreshold?: number;
|
|
134
139
|
encrypted?: boolean;
|
|
135
140
|
/**
|
|
136
141
|
* 仅当 OverlapOwnerStrategy = 'explicit' 时使用:
|
|
@@ -155,8 +160,16 @@ declare interface ChapterManagerCapability {
|
|
|
155
160
|
getVirtualPageMap(): VirtualPageMap;
|
|
156
161
|
/** ChapterScrollPlugin 在可见页位变化时调用,用以驱动按需加载 */
|
|
157
162
|
setVisibleGlobalPages(visiblePageIndices: number[]): void;
|
|
158
|
-
/**
|
|
163
|
+
/** 显式触发某章节加载(分段章节仅加载第 0 段) */
|
|
159
164
|
ensureChapterLoaded(chapterId: string): Promise<ChapterLoadStatus>;
|
|
165
|
+
/** 加载章内指定分段 PDF */
|
|
166
|
+
ensureSegmentLoaded(chapterId: string, segmentIndex: number): Promise<ChapterLoadStatus>;
|
|
167
|
+
/** 加载章内全部分段(导出划线等) */
|
|
168
|
+
ensureAllSegmentsLoaded(chapterId: string): Promise<ChapterLoadStatus>;
|
|
169
|
+
/** 将章内 localPageIndex 映射为 documentManager 的 documentId + 段内页码 */
|
|
170
|
+
resolvePageDocument(chapterId: string, localPageIndex: number): ChapterPageDocumentRef | null;
|
|
171
|
+
getSegmentPlan(chapterId: string): ChapterSegmentPlan | null;
|
|
172
|
+
isSegmentLoaded(chapterId: string, segmentIndex: number): boolean;
|
|
160
173
|
/** 状态查询 */
|
|
161
174
|
getChapterStatus(chapterId: string): ChapterLoadStatus;
|
|
162
175
|
getChapter(chapterId: string): ChapterDescriptor | null;
|
|
@@ -171,10 +184,8 @@ declare interface ChapterManagerCapability {
|
|
|
171
184
|
/**
|
|
172
185
|
* 章节生命周期管理:以章节为粒度懒加载/预取/卸载 PDF 文件,并屏蔽密码协议细节。
|
|
173
186
|
*
|
|
174
|
-
*
|
|
175
|
-
* -
|
|
176
|
-
* - 视觉上的「activeDocumentId」由本插件根据当前可见页位维护;上层无须感知。
|
|
177
|
-
* - 渲染层最终始终通过 `(chapterId, localPageIndex)` 索引到 owner 章节的 PDF 文档。
|
|
187
|
+
* - 单 URL:`documentId === chapterId`
|
|
188
|
+
* - 多段 URL:`documentId === chapterId#s{index}`,滚动时按段加载
|
|
178
189
|
*/
|
|
179
190
|
export declare class ChapterManagerPlugin extends BasePlugin<ChapterManagerPluginConfig, ChapterManagerCapability> {
|
|
180
191
|
static readonly id: "chapter-manager";
|
|
@@ -186,15 +197,14 @@ export declare class ChapterManagerPlugin extends BasePlugin<ChapterManagerPlugi
|
|
|
186
197
|
private manifest;
|
|
187
198
|
private overlapStrategy;
|
|
188
199
|
private virtualPageMap;
|
|
189
|
-
/** 每个章节当前状态(in-memory;不需要 redux 同步) */
|
|
190
200
|
private readonly chapterStatus;
|
|
191
|
-
/** 章节最近一次进入视口或被显式请求的时间戳,用于卸载判断 */
|
|
192
201
|
private readonly chapterLastUsed;
|
|
193
|
-
/** 章节密码累计尝试次数 */
|
|
194
202
|
private readonly passwordAttempts;
|
|
195
|
-
|
|
196
|
-
private readonly
|
|
197
|
-
/**
|
|
203
|
+
private readonly pendingChapterLoadPromises;
|
|
204
|
+
private readonly pendingSegmentLoadPromises;
|
|
205
|
+
/** 步骤 2:`loadChapterUrls` 按章缓存 */
|
|
206
|
+
private readonly chapterUrlsCache;
|
|
207
|
+
private readonly pendingChapterUrlsPromises;
|
|
198
208
|
private unloadTimer;
|
|
199
209
|
private documentManagerUnsubs;
|
|
200
210
|
constructor(id: string, registry: PluginRegistry);
|
|
@@ -202,16 +212,21 @@ export declare class ChapterManagerPlugin extends BasePlugin<ChapterManagerPlugi
|
|
|
202
212
|
protected buildCapability(): ChapterManagerCapability;
|
|
203
213
|
destroy(): void;
|
|
204
214
|
private setManifestInternal;
|
|
205
|
-
/** manifest 就绪后预取前 N 章(不依赖滚动视口是否已算出可见页) */
|
|
206
215
|
private eagerPrefetchFromManifest;
|
|
207
216
|
private findChapter;
|
|
208
|
-
private
|
|
217
|
+
private getSegmentPlanForChapter;
|
|
218
|
+
private isSegmentDocumentOpen;
|
|
219
|
+
private syncChapterStatusFromDocuments;
|
|
209
220
|
private handleVisibleChange;
|
|
210
221
|
private collectIdleChapters;
|
|
211
222
|
ensureChapterLoaded(chapterId: string): Promise<ChapterLoadStatus>;
|
|
223
|
+
ensureAllSegmentsLoaded(chapterId: string): Promise<ChapterLoadStatus>;
|
|
224
|
+
ensureSegmentLoaded(chapterId: string, segmentIndex: number): Promise<ChapterLoadStatus>;
|
|
225
|
+
private ensureSingleDocumentChapter;
|
|
226
|
+
private resolveChapterUrls;
|
|
227
|
+
private openPayloadFromUrl;
|
|
212
228
|
private resolvePdfPayload;
|
|
213
|
-
private
|
|
214
|
-
/** 阻塞等待该章节状态进入 loaded / error / password-required / closed */
|
|
229
|
+
private startLoadSegment;
|
|
215
230
|
private waitForTerminalStatus;
|
|
216
231
|
private handleDocumentError;
|
|
217
232
|
private closeChapter;
|
|
@@ -241,6 +256,26 @@ export declare interface ChapterManifest {
|
|
|
241
256
|
totalGlobalPages?: number;
|
|
242
257
|
}
|
|
243
258
|
|
|
259
|
+
declare interface ChapterPageDocumentRef {
|
|
260
|
+
documentId: string;
|
|
261
|
+
pageIndex: number;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* 打开某一段 PDF 时的上下文(步骤 2 已拿到 urls,步骤 3 可选处理)。
|
|
266
|
+
*/
|
|
267
|
+
export declare interface ChapterPdfLoadContext {
|
|
268
|
+
chapter: ChapterDescriptor;
|
|
269
|
+
/** 当前要打开的段,0-based */
|
|
270
|
+
segmentIndex: number;
|
|
271
|
+
/** 该章总段数 */
|
|
272
|
+
segmentCount: number;
|
|
273
|
+
/** 步骤 2:`loadChapterUrls` 返回的完整列表 */
|
|
274
|
+
urls: string[];
|
|
275
|
+
/** 当前段对应 URL:`urls[segmentIndex]` */
|
|
276
|
+
url: string;
|
|
277
|
+
}
|
|
278
|
+
|
|
244
279
|
/**
|
|
245
280
|
* Backend-supplied chapter contract.
|
|
246
281
|
*
|
|
@@ -277,6 +312,22 @@ export declare interface ChapterPdfViewerProps {
|
|
|
277
312
|
viewportClassName?: string;
|
|
278
313
|
}
|
|
279
314
|
|
|
315
|
+
declare interface ChapterSegmentInfo {
|
|
316
|
+
index: number;
|
|
317
|
+
/** 静态 manifest 有值;动态 loader 时为空,打开段时再解析 URL */
|
|
318
|
+
url: string;
|
|
319
|
+
localPageStart: number;
|
|
320
|
+
localPageEnd: number;
|
|
321
|
+
documentId: string;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
declare interface ChapterSegmentPlan {
|
|
325
|
+
chapterId: string;
|
|
326
|
+
threshold: number;
|
|
327
|
+
pageCount: number;
|
|
328
|
+
segments: ChapterSegmentInfo[];
|
|
329
|
+
}
|
|
330
|
+
|
|
280
331
|
/**
|
|
281
332
|
* 章节 PDF 来源(由业务在 manifest 中提供):
|
|
282
333
|
* - `url`:直接打开该地址
|
|
@@ -291,6 +342,14 @@ export declare type ChapterSource = {
|
|
|
291
342
|
/** 按章预处理:拉取、解密、转换后返回 url 或 buffer */
|
|
292
343
|
| {
|
|
293
344
|
load: () => Promise<ChapterPdfPayload>;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* @deprecated 请用章节级 `segmentPageThreshold` + `chapterPdfLoader.loadChapterUrls`。
|
|
348
|
+
* 静态多 URL 时:`urls.length` 须为 ceil(章页数 / segmentPageThreshold)。
|
|
349
|
+
*/
|
|
350
|
+
| {
|
|
351
|
+
urls: string[];
|
|
352
|
+
segmentPageThreshold: number;
|
|
294
353
|
};
|
|
295
354
|
|
|
296
355
|
declare interface ChapterStatusEvent {
|
|
@@ -313,6 +372,8 @@ export declare type ChapterTreeInput = {
|
|
|
313
372
|
startPage: number;
|
|
314
373
|
endPage: number;
|
|
315
374
|
source?: ChapterSource;
|
|
375
|
+
/** 章内分段阈值;URL 由 `chapterPdfLoader.loadChapterUrls` 拉取 */
|
|
376
|
+
segmentPageThreshold?: number;
|
|
316
377
|
encrypted?: boolean;
|
|
317
378
|
children?: ChapterTreeInput[];
|
|
318
379
|
};
|
|
@@ -424,6 +485,9 @@ declare interface ChapterViewerZoomConfig {
|
|
|
424
485
|
pageWidth?: number;
|
|
425
486
|
}
|
|
426
487
|
|
|
488
|
+
/** 将划选文本写入系统剪贴板(Clipboard API,失败时回退 execCommand) */
|
|
489
|
+
export declare function copyTextToClipboard(text: string): Promise<boolean>;
|
|
490
|
+
|
|
427
491
|
/** 生成插件列表 + 规范化后的 features(供 EmbedPDF / PdfChapterViewport 使用) */
|
|
428
492
|
export declare function createChapterViewerBundle(input: ChapterViewerOptions | CreateChapterViewerEditorOptionsInput): {
|
|
429
493
|
plugins: PluginBatchRegistration<any, any, any, any>[];
|
|
@@ -545,17 +609,32 @@ declare interface HoverBookmarkUiConfig_2 {
|
|
|
545
609
|
}
|
|
546
610
|
|
|
547
611
|
/**
|
|
548
|
-
*
|
|
612
|
+
* 章节 PDF 加载(推荐三步;`loadPdf` 仍兼容旧版单步写法)。
|
|
549
613
|
*
|
|
550
|
-
*
|
|
551
|
-
*
|
|
552
|
-
*
|
|
553
|
-
*
|
|
614
|
+
* | 步骤 | 方法 | 说明 |
|
|
615
|
+
* | --- | --- | --- |
|
|
616
|
+
* | 1 | manifest 章节树 | 仅 `chapterId`、页码、`segmentPageThreshold` 等,**无 URL** |
|
|
617
|
+
* | 2 | `loadChapterUrls(chapter)` | 按章请求详情,返回 URL 列表(分段时多项) |
|
|
618
|
+
* | 3 | `openPdf(ctx)`(可选) | 对 `ctx.url` 解密/下载;省略则直接用 `ctx.url` 打开 |
|
|
554
619
|
*
|
|
555
|
-
*
|
|
620
|
+
* 仍可使用 `loadPdf(chapter, segmentIndex)` 单步实现(等价于 2+3 合并)。
|
|
556
621
|
*/
|
|
557
622
|
export declare interface IChapterPdfLoader {
|
|
558
|
-
|
|
623
|
+
/**
|
|
624
|
+
* 步骤 2:按章拉取 PDF 地址列表。
|
|
625
|
+
* 单 PDF 章节返回长度为 1 的数组;分段章节返回与 `ceil(页数/threshold)` 一致的多项。
|
|
626
|
+
*/
|
|
627
|
+
loadChapterUrls?(chapter: ChapterDescriptor): Promise<string[]>;
|
|
628
|
+
/**
|
|
629
|
+
* 步骤 3(可选):将步骤 2 的 URL 转为可打开的 payload。
|
|
630
|
+
* 未实现时引擎使用 `{ url: ctx.url }`。
|
|
631
|
+
*/
|
|
632
|
+
openPdf?(ctx: ChapterPdfLoadContext): Promise<ChapterPdfPayload>;
|
|
633
|
+
/**
|
|
634
|
+
* @deprecated 单步加载;新代码请用 `loadChapterUrls` + 可选 `openPdf`。
|
|
635
|
+
* @param segmentIndex 章内分段索引;单 URL 章节为 0 或省略
|
|
636
|
+
*/
|
|
637
|
+
loadPdf?(chapter: ChapterDescriptor, segmentIndex?: number): Promise<ChapterPdfPayload>;
|
|
559
638
|
}
|
|
560
639
|
|
|
561
640
|
/**
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,yBAAyB,EACzB,yBAAyB,EACzB,sBAAsB,EACtB,gCAAgC,EAChC,+BAA+B,EAC/B,6BAA6B,EAC7B,oBAAoB,EACpB,4BAA4B,EAC5B,wBAAwB,EACxB,QAAQ,EACR,aAAa,GACd,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAC/E,OAAO,EACL,wBAAwB,EACxB,2BAA2B,EAC3B,wBAAwB,EACxB,+BAA+B,EAC/B,+BAA+B,EAC/B,kCAAkC,EAClC,gCAAgC,EAChC,mCAAmC,EACnC,iCAAiC,EACjC,kCAAkC,EAClC,gBAAgB,EAChB,mCAAmC,EACnC,KAAK,0BAA0B,EAC/B,KAAK,yBAAyB,EAC9B,KAAK,kCAAkC,EACvC,KAAK,+BAA+B,EACpC,KAAK,+BAA+B,GACrC,MAAM,gCAAgC,CAAC;AACxC,YAAY,EACV,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,2BAA2B,EAC3B,qCAAqC,EACrC,6BAA6B,EAC7B,2BAA2B,EAC3B,+BAA+B,EAC/B,aAAa,EACb,UAAU,EACV,SAAS,EACT,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,oCAAoC,CAAC;AAC5C,YAAY,EACV,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OA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