@embedpdf-editor/vue3-chapter-viewer 0.3.5 → 1.0.2

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/dist/index.d.ts CHANGED
@@ -71,7 +71,7 @@ export declare function buildParagraphBookmarkAnchor(chapterId: string, localPag
71
71
  }): ParagraphBookmark['anchor'];
72
72
 
73
73
  /** 选区浮窗 card 内置操作 */
74
- declare type BuiltinSelectionToolbarAction = 'highlight' | 'underline' | 'squiggly' | 'strikeout' | 'note';
74
+ declare type BuiltinSelectionToolbarAction = 'copy' | 'highlight' | 'underline' | 'squiggly' | 'strikeout' | 'note';
75
75
 
76
76
  /**
77
77
  * 回调型:把决策交给业务侧异步函数(最常用)。
@@ -155,8 +155,16 @@ declare interface ChapterManagerCapability {
155
155
  getVirtualPageMap(): VirtualPageMap;
156
156
  /** ChapterScrollPlugin 在可见页位变化时调用,用以驱动按需加载 */
157
157
  setVisibleGlobalPages(visiblePageIndices: number[]): void;
158
- /** 显式触发某章节加载(如点击章节标题跳转时) */
158
+ /** 显式触发某章节加载(分段章节仅加载第 0 段) */
159
159
  ensureChapterLoaded(chapterId: string): Promise<ChapterLoadStatus>;
160
+ /** 加载章内指定分段 PDF */
161
+ ensureSegmentLoaded(chapterId: string, segmentIndex: number): Promise<ChapterLoadStatus>;
162
+ /** 加载章内全部分段(导出划线等) */
163
+ ensureAllSegmentsLoaded(chapterId: string): Promise<ChapterLoadStatus>;
164
+ /** 将章内 localPageIndex 映射为 documentManager 的 documentId + 段内页码 */
165
+ resolvePageDocument(chapterId: string, localPageIndex: number): ChapterPageDocumentRef | null;
166
+ getSegmentPlan(chapterId: string): ChapterSegmentPlan | null;
167
+ isSegmentLoaded(chapterId: string, segmentIndex: number): boolean;
160
168
  /** 状态查询 */
161
169
  getChapterStatus(chapterId: string): ChapterLoadStatus;
162
170
  getChapter(chapterId: string): ChapterDescriptor | null;
@@ -171,10 +179,8 @@ declare interface ChapterManagerCapability {
171
179
  /**
172
180
  * 章节生命周期管理:以章节为粒度懒加载/预取/卸载 PDF 文件,并屏蔽密码协议细节。
173
181
  *
174
- * 关键不变量:
175
- * - 每个章节对 DocumentManager 用 `documentId === chapterId`,从而保持 1:1 缓存。
176
- * - 视觉上的「activeDocumentId」由本插件根据当前可见页位维护;上层无须感知。
177
- * - 渲染层最终始终通过 `(chapterId, localPageIndex)` 索引到 owner 章节的 PDF 文档。
182
+ * - 单 URL:`documentId === chapterId`
183
+ * - 多段 URL:`documentId === chapterId#s{index}`,滚动时按段加载
178
184
  */
179
185
  export declare class ChapterManagerPlugin extends BasePlugin<ChapterManagerPluginConfig, ChapterManagerCapability> {
180
186
  static readonly id: "chapter-manager";
@@ -186,15 +192,11 @@ export declare class ChapterManagerPlugin extends BasePlugin<ChapterManagerPlugi
186
192
  private manifest;
187
193
  private overlapStrategy;
188
194
  private virtualPageMap;
189
- /** 每个章节当前状态(in-memory;不需要 redux 同步) */
190
195
  private readonly chapterStatus;
191
- /** 章节最近一次进入视口或被显式请求的时间戳,用于卸载判断 */
192
196
  private readonly chapterLastUsed;
193
- /** 章节密码累计尝试次数 */
194
197
  private readonly passwordAttempts;
195
- /** 等待 ensureChapterLoaded 完成的 Promise 列表(按章节去重) */
196
- private readonly pendingLoadPromises;
197
- /** unload tick 句柄 */
198
+ private readonly pendingChapterLoadPromises;
199
+ private readonly pendingSegmentLoadPromises;
198
200
  private unloadTimer;
199
201
  private documentManagerUnsubs;
200
202
  constructor(id: string, registry: PluginRegistry);
@@ -202,16 +204,19 @@ export declare class ChapterManagerPlugin extends BasePlugin<ChapterManagerPlugi
202
204
  protected buildCapability(): ChapterManagerCapability;
203
205
  destroy(): void;
204
206
  private setManifestInternal;
205
- /** manifest 就绪后预取前 N 章(不依赖滚动视口是否已算出可见页) */
206
207
  private eagerPrefetchFromManifest;
207
208
  private findChapter;
208
- private isOwnedChapter;
209
+ private getSegmentPlanForChapter;
210
+ private isSegmentDocumentOpen;
211
+ private syncChapterStatusFromDocuments;
209
212
  private handleVisibleChange;
210
213
  private collectIdleChapters;
211
214
  ensureChapterLoaded(chapterId: string): Promise<ChapterLoadStatus>;
215
+ ensureAllSegmentsLoaded(chapterId: string): Promise<ChapterLoadStatus>;
216
+ ensureSegmentLoaded(chapterId: string, segmentIndex: number): Promise<ChapterLoadStatus>;
217
+ private ensureSingleDocumentChapter;
212
218
  private resolvePdfPayload;
213
- private startLoad;
214
- /** 阻塞等待该章节状态进入 loaded / error / password-required / closed */
219
+ private startLoadSegment;
215
220
  private waitForTerminalStatus;
216
221
  private handleDocumentError;
217
222
  private closeChapter;
@@ -241,6 +246,11 @@ export declare interface ChapterManifest {
241
246
  totalGlobalPages?: number;
242
247
  }
243
248
 
249
+ declare interface ChapterPageDocumentRef {
250
+ documentId: string;
251
+ pageIndex: number;
252
+ }
253
+
244
254
  /**
245
255
  * Backend-supplied chapter contract.
246
256
  *
@@ -277,6 +287,21 @@ export declare interface ChapterPdfViewerProps {
277
287
  viewportClassName?: string;
278
288
  }
279
289
 
290
+ declare interface ChapterSegmentInfo {
291
+ index: number;
292
+ url: string;
293
+ localPageStart: number;
294
+ localPageEnd: number;
295
+ documentId: string;
296
+ }
297
+
298
+ declare interface ChapterSegmentPlan {
299
+ chapterId: string;
300
+ threshold: number;
301
+ pageCount: number;
302
+ segments: ChapterSegmentInfo[];
303
+ }
304
+
280
305
  /**
281
306
  * 章节 PDF 来源(由业务在 manifest 中提供):
282
307
  * - `url`:直接打开该地址
@@ -291,6 +316,14 @@ export declare type ChapterSource = {
291
316
  /** 按章预处理:拉取、解密、转换后返回 url 或 buffer */
292
317
  | {
293
318
  load: () => Promise<ChapterPdfPayload>;
319
+ }
320
+ /**
321
+ * 章内多 PDF 分段(后端已按段拆分)。
322
+ * `urls.length` 须为 ceil(章页数 / segmentPageThreshold)。
323
+ */
324
+ | {
325
+ urls: string[];
326
+ segmentPageThreshold: number;
294
327
  };
295
328
 
296
329
  declare interface ChapterStatusEvent {
@@ -424,6 +457,9 @@ declare interface ChapterViewerZoomConfig {
424
457
  pageWidth?: number;
425
458
  }
426
459
 
460
+ /** 将划选文本写入系统剪贴板(Clipboard API,失败时回退 execCommand) */
461
+ export declare function copyTextToClipboard(text: string): Promise<boolean>;
462
+
427
463
  /** 生成插件列表 + 规范化后的 features(供 EmbedPDF / PdfChapterViewport 使用) */
428
464
  export declare function createChapterViewerBundle(input: ChapterViewerOptions | CreateChapterViewerEditorOptionsInput): {
429
465
  plugins: PluginBatchRegistration<any, any, any, any>[];
@@ -555,7 +591,10 @@ declare interface HoverBookmarkUiConfig_2 {
555
591
  * 适合:所有章节走同一套 API、在内存中解密后再以 buffer 打开、动态签名 URL 等。
556
592
  */
557
593
  export declare interface IChapterPdfLoader {
558
- loadPdf(chapter: ChapterDescriptor): Promise<ChapterPdfPayload>;
594
+ /**
595
+ * @param segmentIndex 章内分段索引;单 URL 章节为 0 或省略
596
+ */
597
+ loadPdf(chapter: ChapterDescriptor, segmentIndex?: number): Promise<ChapterPdfPayload>;
559
598
  }
560
599
 
561
600
  /**
@@ -839,6 +878,8 @@ declare interface SelectionToolbarConfig {
839
878
  enabled?: boolean;
840
879
  /** 隐藏部分内置按钮 */
841
880
  hiddenBuiltinActions?: BuiltinSelectionToolbarAction[];
881
+ /** 自定义复制按钮图标;不提供则使用默认图标 */
882
+ renderCopyIcon?: () => unknown;
842
883
  /** 扩展操作(由宿主在 buildSelectionMenu 或 onExtraAction 中处理) */
843
884
  extraActions?: SelectionToolbarExtraAction[];
844
885
  }
@@ -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,4B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