@embedpdf-editor/vue3-chapter-viewer 0.2.1 → 0.3.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/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { AnnotationCapability } from '@embedpdf/plugin-annotation';
2
+ import { AnnotationTransferItem } from '@embedpdf/plugin-annotation';
2
3
  import { BasePlugin } from '@embedpdf/core';
3
4
  import { BasePluginConfig } from '@embedpdf/core';
4
5
  import { ChapterTreeNode } from '../vue/chapter-tree';
@@ -22,8 +23,23 @@ import { ToolbarSchema } from '@embedpdf/plugin-ui';
22
23
  import { UISchema } from '@embedpdf/plugin-ui';
23
24
  import { useCapability } from '@embedpdf/core/vue';
24
25
  import { usePdfiumEngine } from '@embedpdf/engines/vue';
26
+ import { useRegistry } from '@embedpdf/core/vue';
25
27
 
26
- declare const __VLS_export: DefineComponent<ChapterPdfViewerProps, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<ChapterPdfViewerProps> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>;
28
+ declare const __VLS_base: DefineComponent<ChapterPdfViewerProps, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<ChapterPdfViewerProps> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>;
29
+
30
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
31
+
32
+ declare type __VLS_Slots = {} & {
33
+ prepend?: (props: typeof __VLS_9) => any;
34
+ } & {
35
+ default?: (props: typeof __VLS_11) => any;
36
+ };
37
+
38
+ declare type __VLS_WithSlots<T, S> = T & {
39
+ new (): {
40
+ $slots: S;
41
+ };
42
+ };
27
43
 
28
44
  /** 对当前选区应用 PDF 划线/高亮,支持按类型自定义颜色、粗细与偏移 */
29
45
  export declare function applySelectionMarkup(documentId: string, kind: SelectionMarkupKind, annotation: AnnotationCapability, selection: SelectionCapability, styles?: MarkupStylesConfig): boolean;
@@ -44,6 +60,11 @@ declare interface BookmarkMarkerUiConfig_2 {
44
60
  iconSize?: number;
45
61
  }
46
62
 
63
+ export declare function buildChapterViewerCatalog(nodes: ChapterTreeInput[]): {
64
+ tree: ChapterTreeNode_2[];
65
+ manifest: ChapterManifest;
66
+ };
67
+
47
68
  export declare function buildParagraphBookmarkAnchor(chapterId: string, localPageIndex: number, rectsPdfCoord: Rect[], virtualPage?: {
48
69
  globalPageIndex: number;
49
70
  globalPageNumber: number;
@@ -61,6 +82,37 @@ export declare class CallbackPasswordProvider implements IPasswordProvider {
61
82
  resolvePassword(chapter: ChapterDescriptor, attempt: number): Promise<string | null>;
62
83
  }
63
84
 
85
+ /** 归档文件格式版本 */
86
+ export declare const CHAPTER_ANNOTATIONS_ARCHIVE_VERSION: 1;
87
+
88
+ /** 全书按 chapterId 分组的归档 */
89
+ export declare interface ChapterAnnotationsArchive {
90
+ version: typeof CHAPTER_ANNOTATIONS_ARCHIVE_VERSION;
91
+ exportedAt: string;
92
+ chapters: Record<string, Omit<ChapterAnnotationsSnapshot, 'chapterId'>>;
93
+ }
94
+
95
+ export declare function chapterAnnotationsArchiveToJson(archive: ChapterAnnotationsArchive): string;
96
+
97
+ declare type ChapterAnnotationsContentFlags = {
98
+ /** 默认 true */
99
+ bookmarks?: boolean;
100
+ /** 默认 true */
101
+ notes?: boolean;
102
+ /** 默认 true;对应 @embedpdf/plugin-annotation 的 export/import */
103
+ markup?: boolean;
104
+ };
105
+
106
+ /** 单章用户标注快照 */
107
+ export declare interface ChapterAnnotationsSnapshot {
108
+ chapterId: string;
109
+ bookmarks?: ParagraphBookmark[];
110
+ notes?: NoteAnchor[];
111
+ markup?: SerializableAnnotationTransferItem[];
112
+ }
113
+
114
+ export declare function chapterAnnotationsSnapshotToJson(snapshot: ChapterAnnotationsSnapshot): string;
115
+
64
116
  export declare interface ChapterDescriptor {
65
117
  /** 业务唯一 ID;同时复用作 documentManager 的 documentId */
66
118
  chapterId: string;
@@ -87,6 +139,8 @@ export declare interface ChapterDescriptor {
87
139
  ownedGlobalPages?: number[];
88
140
  }
89
141
 
142
+ export declare function chapterDescriptorFromTreeNode(node: ChapterTreeInput): ChapterDescriptor;
143
+
90
144
  /**
91
145
  * 章节级加载状态。区别于 `@embedpdf/core` 的 DocumentState:
92
146
  * - `idle` = manifest 已注册但尚未触发 open
@@ -233,7 +287,9 @@ export declare type ChapterSource = {
233
287
  url: string;
234
288
  } | {
235
289
  buffer: ArrayBuffer;
236
- } | {
290
+ }
291
+ /** 按章预处理:拉取、解密、转换后返回 url 或 buffer */
292
+ | {
237
293
  load: () => Promise<ChapterPdfPayload>;
238
294
  };
239
295
 
@@ -247,8 +303,31 @@ declare interface ChapterStatusEvent {
247
303
  };
248
304
  }
249
305
 
306
+ /**
307
+ * 业务目录树输入:父节点页范围可覆盖子节点;flatten 后每条对应一个可加载的 PDF 章节。
308
+ * 父节点若仅作分组、无独立 PDF,请勿放入 manifest(不要 flatten 该节点)。
309
+ */
310
+ export declare type ChapterTreeInput = {
311
+ chapterId: string;
312
+ title: string;
313
+ startPage: number;
314
+ endPage: number;
315
+ source?: ChapterSource;
316
+ encrypted?: boolean;
317
+ children?: ChapterTreeInput[];
318
+ };
319
+
250
320
  export { ChapterTreeNode }
251
321
 
322
+ /** 侧栏目录树节点(仅 UI;渲染以 flatten 后的 manifest 为准) */
323
+ declare type ChapterTreeNode_2 = {
324
+ id: string;
325
+ title: string;
326
+ startPage: number;
327
+ endPage: number;
328
+ children?: ChapterTreeNode_2[];
329
+ };
330
+
252
331
  export { ChapterTreePanel }
253
332
 
254
333
  export { ChapterViewerCatalog }
@@ -307,12 +386,19 @@ export declare interface ChapterViewerOptions {
307
386
  /** 书签持久化与删除回调 */
308
387
  bookmarks: ParagraphBookmarkCallbacks;
309
388
  chapterPdfLoader?: IChapterPdfLoader;
389
+ /**
390
+ * 同一全局页被多个章节条目覆盖时,用哪一个章节的 PDF 渲染(非 owner 的章节在该页不绘制真实 PDF)。
391
+ * - `{ kind: 'first-wins' }`:manifest 中先出现的章节(默认)
392
+ * - `{ kind: 'last-wins' }`:后出现的章节(目录 flatten 后常用于「以当前页最后一节为准」)
393
+ * 亦可用 `overlapStrategyForSamePageOwner('first' | 'last')`(chapter-core 包)
394
+ */
395
+ overlapStrategy?: OverlapOwnerStrategy;
310
396
  /** 功能开关与样式;省略则全开 */
311
397
  features?: ChapterViewerConfig;
312
398
  }
313
399
 
314
400
  declare interface ChapterViewerZoomConfig {
315
- /** 是否启用 pinch/滑块缩放容器,默认 true */
401
+ /** 是否启用 Ctrl+滚轮 / 双指捏合等交互缩放,默认 true;为 false 时仍可用 pageWidth / initial 设置版面宽度 */
316
402
  enabled?: boolean;
317
403
  min?: number;
318
404
  max?: number;
@@ -398,6 +484,15 @@ export declare const DEFAULT_CHAPTER_VIEWER_CONFIG: ChapterViewerConfig;
398
484
  /** 默认全开的功能配置(内部规范化结果) */
399
485
  export declare const DEFAULT_CHAPTER_VIEWER_FEATURES: ChapterViewerFeaturesConfig;
400
486
 
487
+ export declare const defaultOverlapStrategy: OverlapOwnerStrategy;
488
+
489
+ export declare function downloadChapterAnnotationsArchive(archive: ChapterAnnotationsArchive, filename?: string): void;
490
+
491
+ export declare function downloadChapterAnnotationsSnapshot(snapshot: ChapterAnnotationsSnapshot, filename?: string): void;
492
+
493
+ /** 触发浏览器下载 JSON 文件(仅浏览器环境) */
494
+ export declare function downloadJsonFile(filename: string, json: string): void;
495
+
401
496
  /** 与 snippet 主工具栏 mode tabs 对齐的编辑模式 */
402
497
  declare type EditorModeId = 'view' | 'annotate' | 'shapes' | 'insert' | 'form' | 'redact';
403
498
 
@@ -406,6 +501,25 @@ declare const editorSecondaryToolbars: Record<string, ToolbarSchema>;
406
501
 
407
502
  export { EmbedPDF }
408
503
 
504
+ /**
505
+ * 导出 manifest 中全部章节(按 chapterId 存 JSON 对象)。
506
+ */
507
+ export declare function exportAllChapterAnnotations(registry: PluginRegistry, manifest: ChapterManifest, options?: ExportChapterAnnotationsOptions): Promise<ChapterAnnotationsArchive>;
508
+
509
+ /**
510
+ * 导出单章用户标注(书签、笔记、划词划线)。
511
+ * `chapterId` 与章节 documentId 一致。
512
+ */
513
+ export declare function exportChapterAnnotations(registry: PluginRegistry, chapterId: string, options?: ExportChapterAnnotationsOptions): Promise<ChapterAnnotationsSnapshot>;
514
+
515
+ export declare type ExportChapterAnnotationsOptions = ChapterAnnotationsContentFlags & {
516
+ /** 导出前确保章节 PDF 已加载(划线需要),默认 true */
517
+ ensureChapterLoaded?: boolean;
518
+ };
519
+
520
+ /** 深度优先展开目录树为 manifest.chapters(含父、子各一条,与 demo flatten 一致) */
521
+ export declare function flattenChapterTree(nodes: ChapterTreeInput[]): ChapterDescriptor[];
522
+
409
523
  declare interface HoverBookmarkUiConfig {
410
524
  /** 悬停行末「添加书签」自定义图标;无背景 */
411
525
  renderAddIcon?: () => unknown;
@@ -418,13 +532,42 @@ declare interface HoverBookmarkUiConfig_2 {
418
532
  }
419
533
 
420
534
  /**
421
- * 全局章节 PDF 加载器:当 `ChapterDescriptor.source` 未提供 url/buffer/load 时使用。
422
- * 适合统一走业务 API、鉴权下载等场景。
535
+ * 全局章节 PDF 加载器:在打开章节前由引擎调用,用于预处理/拉取 PDF。
536
+ *
537
+ * 优先级(`ChapterManagerPlugin.resolvePdfPayload`):
538
+ * 1. `chapter.source.url` / `source.buffer` — 直接使用
539
+ * 2. `chapter.source.load()` — 按章异步,返回 `{ url }` 或 `{ buffer }`
540
+ * 3. `chapterPdfLoader.loadPdf(chapter)` — 全局统一逻辑(鉴权、解密、转 blob URL 等)
541
+ *
542
+ * 适合:所有章节走同一套 API、在内存中解密后再以 buffer 打开、动态签名 URL 等。
423
543
  */
424
544
  export declare interface IChapterPdfLoader {
425
545
  loadPdf(chapter: ChapterDescriptor): Promise<ChapterPdfPayload>;
426
546
  }
427
547
 
548
+ /**
549
+ * 导入单章快照。
550
+ */
551
+ export declare function importChapterAnnotations(registry: PluginRegistry, snapshot: ChapterAnnotationsSnapshot, options?: ImportChapterAnnotationsOptions): Promise<void>;
552
+
553
+ /**
554
+ * 导入全书归档(仅处理 archive.chapters 中存在的 chapterId)。
555
+ */
556
+ export declare function importChapterAnnotationsArchive(registry: PluginRegistry, archive: ChapterAnnotationsArchive, options?: ImportChapterAnnotationsOptions): Promise<void>;
557
+
558
+ export declare type ImportChapterAnnotationsOptions = ChapterAnnotationsContentFlags & {
559
+ /**
560
+ * replace:先清空该章对应数据再写入;
561
+ * merge:划线/笔记/书签与现有合并(书签按 anchor 去重)。
562
+ */
563
+ mode?: 'replace' | 'merge';
564
+ /** 导入前确保章节已加载,默认 true */
565
+ ensureChapterLoaded?: boolean;
566
+ /** 导入完成后回调,便于写入 localStorage / 后端 */
567
+ persistNotes?: (allNotes: NoteAnchor[]) => void | Promise<void>;
568
+ persistBookmarks?: (allBookmarks: ParagraphBookmark[]) => void | Promise<void>;
569
+ };
570
+
428
571
  /**
429
572
  * 章节加密的抽象接口:当某章节首次或重试加载因密码失败时,
430
573
  * `ChapterManagerPlugin` 会向 provider 询问密码。
@@ -567,12 +710,17 @@ declare interface OperationSpec {
567
710
  }
568
711
 
569
712
  /**
570
- * 决定相邻章节在重叠页上谁拥有该页(owner)。
571
- * - first-wins / last-wins:按 manifest 顺序的先到/后到
572
- * - explicit:依赖 `ChapterDescriptor.ownedGlobalPages`
573
- * - custom:开发者完全接管
713
+ * 决定同一全局页被多个章节 manifest 条目覆盖时,用哪一个章节的 PDF 渲染(owner)。
714
+ * owner 章节在该页仅占位/不绘制真实 PDF,避免重复。
715
+ *
716
+ * - **first-wins**:manifest 中**先**出现的章节(默认)
717
+ * - **last-wins**:**后**出现的章节(目录 flatten 后,重叠页常以「当前页最后一节」为准)
718
+ * - **explicit**:`ChapterDescriptor.ownedGlobalPages` 声明归属
719
+ * - **custom**:`resolve(globalPage, candidates)` 完全自定义
720
+ *
721
+ * 简写:`overlapStrategyForSamePageOwner('first' | 'last')`(chapter-core)
574
722
  */
575
- declare type OverlapOwnerStrategy = {
723
+ export declare type OverlapOwnerStrategy = {
576
724
  kind: 'first-wins';
577
725
  } | {
578
726
  kind: 'last-wins';
@@ -583,6 +731,8 @@ declare type OverlapOwnerStrategy = {
583
731
  resolve: (globalPage: number, candidates: ChapterDescriptor[]) => string;
584
732
  };
585
733
 
734
+ export declare function overlapStrategyForSamePageOwner(owner: SamePageOverlapOwner): OverlapOwnerStrategy;
735
+
586
736
  export declare interface ParagraphBookmark {
587
737
  id: string;
588
738
  label: string;
@@ -628,6 +778,10 @@ declare interface ParagraphBookmarkPluginConfig extends BasePluginConfig {
628
778
  hover?: HoverBookmarkUiConfig_2;
629
779
  }
630
780
 
781
+ export declare function parseChapterAnnotationsArchiveJson(json: string): ChapterAnnotationsArchive;
782
+
783
+ export declare function parseChapterAnnotationsSnapshotJson(json: string): ChapterAnnotationsSnapshot;
784
+
631
785
  export declare interface PdfChapterEditorBookmarksConfig {
632
786
  callbacks: NonNullable<ParagraphBookmarkPluginConfig['callbacks']>;
633
787
  }
@@ -647,6 +801,9 @@ declare interface PdfChapterEditorToolbarConfig extends CreateEditorUiSchemaOpti
647
801
 
648
802
  export { PdfChapterViewport }
649
803
 
804
+ /** 同一全局页多章节重叠时,选用 manifest 中先/后出现的章节 PDF */
805
+ export declare type SamePageOverlapOwner = 'first' | 'last';
806
+
650
807
  /** 划线类型 */
651
808
  declare type SelectionMarkupKind = 'highlight' | 'underline' | 'squiggly' | 'strikeout';
652
809
 
@@ -667,10 +824,23 @@ declare interface SelectionToolbarExtraAction {
667
824
  order?: number;
668
825
  }
669
826
 
827
+ /** JSON 中可存储的划线(stamp 的 ArrayBuffer 转为 base64) */
828
+ export declare interface SerializableAnnotationTransferItem {
829
+ annotation: AnnotationTransferItem['annotation'];
830
+ ctx?: {
831
+ dataBase64?: string;
832
+ mimeType?: string;
833
+ };
834
+ }
835
+
836
+ export declare function toChapterTreeNodes(nodes: ChapterTreeInput[]): ChapterTreeNode_2[];
837
+
670
838
  export { useCapability }
671
839
 
672
840
  export { usePdfiumEngine }
673
841
 
842
+ export { useRegistry }
843
+
674
844
  /**
675
845
  * 一个虚拟页位的解析结果。`localPageIndex` 是 owner 章节 PDF 内的 0-based 索引。
676
846
  */
@@ -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,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAC/E,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"}
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,6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