@embedpdf-editor/chapter-snippet 0.3.6 → 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.
@@ -43,7 +43,7 @@ export declare function buildParagraphBookmarkAnchor(chapterId: string, localPag
43
43
  }): ParagraphBookmark['anchor'];
44
44
 
45
45
  /** 选区浮窗 card 内置操作 */
46
- declare type BuiltinSelectionToolbarAction = 'highlight' | 'underline' | 'squiggly' | 'strikeout' | 'note';
46
+ declare type BuiltinSelectionToolbarAction = 'copy' | 'highlight' | 'underline' | 'squiggly' | 'strikeout' | 'note';
47
47
 
48
48
  /**
49
49
  * 回调型:把决策交给业务侧异步函数(最常用)。
@@ -140,8 +140,16 @@ declare interface ChapterManagerCapability {
140
140
  getVirtualPageMap(): VirtualPageMap;
141
141
  /** ChapterScrollPlugin 在可见页位变化时调用,用以驱动按需加载 */
142
142
  setVisibleGlobalPages(visiblePageIndices: number[]): void;
143
- /** 显式触发某章节加载(如点击章节标题跳转时) */
143
+ /** 显式触发某章节加载(分段章节仅加载第 0 段) */
144
144
  ensureChapterLoaded(chapterId: string): Promise<ChapterLoadStatus>;
145
+ /** 加载章内指定分段 PDF */
146
+ ensureSegmentLoaded(chapterId: string, segmentIndex: number): Promise<ChapterLoadStatus>;
147
+ /** 加载章内全部分段(导出划线等) */
148
+ ensureAllSegmentsLoaded(chapterId: string): Promise<ChapterLoadStatus>;
149
+ /** 将章内 localPageIndex 映射为 documentManager 的 documentId + 段内页码 */
150
+ resolvePageDocument(chapterId: string, localPageIndex: number): ChapterPageDocumentRef | null;
151
+ getSegmentPlan(chapterId: string): ChapterSegmentPlan | null;
152
+ isSegmentLoaded(chapterId: string, segmentIndex: number): boolean;
145
153
  /** 状态查询 */
146
154
  getChapterStatus(chapterId: string): ChapterLoadStatus;
147
155
  getChapter(chapterId: string): ChapterDescriptor | null;
@@ -156,10 +164,8 @@ declare interface ChapterManagerCapability {
156
164
  /**
157
165
  * 章节生命周期管理:以章节为粒度懒加载/预取/卸载 PDF 文件,并屏蔽密码协议细节。
158
166
  *
159
- * 关键不变量:
160
- * - 每个章节对 DocumentManager 用 `documentId === chapterId`,从而保持 1:1 缓存。
161
- * - 视觉上的「activeDocumentId」由本插件根据当前可见页位维护;上层无须感知。
162
- * - 渲染层最终始终通过 `(chapterId, localPageIndex)` 索引到 owner 章节的 PDF 文档。
167
+ * - 单 URL:`documentId === chapterId`
168
+ * - 多段 URL:`documentId === chapterId#s{index}`,滚动时按段加载
163
169
  */
164
170
  export declare class ChapterManagerPlugin extends BasePlugin<ChapterManagerPluginConfig, ChapterManagerCapability> {
165
171
  static readonly id: "chapter-manager";
@@ -171,15 +177,11 @@ export declare class ChapterManagerPlugin extends BasePlugin<ChapterManagerPlugi
171
177
  private manifest;
172
178
  private overlapStrategy;
173
179
  private virtualPageMap;
174
- /** 每个章节当前状态(in-memory;不需要 redux 同步) */
175
180
  private readonly chapterStatus;
176
- /** 章节最近一次进入视口或被显式请求的时间戳,用于卸载判断 */
177
181
  private readonly chapterLastUsed;
178
- /** 章节密码累计尝试次数 */
179
182
  private readonly passwordAttempts;
180
- /** 等待 ensureChapterLoaded 完成的 Promise 列表(按章节去重) */
181
- private readonly pendingLoadPromises;
182
- /** unload tick 句柄 */
183
+ private readonly pendingChapterLoadPromises;
184
+ private readonly pendingSegmentLoadPromises;
183
185
  private unloadTimer;
184
186
  private documentManagerUnsubs;
185
187
  constructor(id: string, registry: PluginRegistry);
@@ -187,16 +189,19 @@ export declare class ChapterManagerPlugin extends BasePlugin<ChapterManagerPlugi
187
189
  protected buildCapability(): ChapterManagerCapability;
188
190
  destroy(): void;
189
191
  private setManifestInternal;
190
- /** manifest 就绪后预取前 N 章(不依赖滚动视口是否已算出可见页) */
191
192
  private eagerPrefetchFromManifest;
192
193
  private findChapter;
193
- private isOwnedChapter;
194
+ private getSegmentPlanForChapter;
195
+ private isSegmentDocumentOpen;
196
+ private syncChapterStatusFromDocuments;
194
197
  private handleVisibleChange;
195
198
  private collectIdleChapters;
196
199
  ensureChapterLoaded(chapterId: string): Promise<ChapterLoadStatus>;
200
+ ensureAllSegmentsLoaded(chapterId: string): Promise<ChapterLoadStatus>;
201
+ ensureSegmentLoaded(chapterId: string, segmentIndex: number): Promise<ChapterLoadStatus>;
202
+ private ensureSingleDocumentChapter;
197
203
  private resolvePdfPayload;
198
- private startLoad;
199
- /** 阻塞等待该章节状态进入 loaded / error / password-required / closed */
204
+ private startLoadSegment;
200
205
  private waitForTerminalStatus;
201
206
  private handleDocumentError;
202
207
  private closeChapter;
@@ -238,6 +243,11 @@ export declare type ChapterNoteRequestEditDetail = {
238
243
  anchor: NoteAnchor;
239
244
  };
240
245
 
246
+ declare interface ChapterPageDocumentRef {
247
+ documentId: string;
248
+ pageIndex: number;
249
+ }
250
+
241
251
  /**
242
252
  * Backend-supplied chapter contract.
243
253
  *
@@ -253,6 +263,21 @@ export declare type ChapterPdfPayload = {
253
263
  buffer: ArrayBuffer;
254
264
  };
255
265
 
266
+ declare interface ChapterSegmentInfo {
267
+ index: number;
268
+ url: string;
269
+ localPageStart: number;
270
+ localPageEnd: number;
271
+ documentId: string;
272
+ }
273
+
274
+ declare interface ChapterSegmentPlan {
275
+ chapterId: string;
276
+ threshold: number;
277
+ pageCount: number;
278
+ segments: ChapterSegmentInfo[];
279
+ }
280
+
256
281
  /** 划词工具栏扩展操作事件 */
257
282
  export declare type ChapterSelectionActionDetail = {
258
283
  actionId: string;
@@ -272,6 +297,14 @@ export declare type ChapterSource = {
272
297
  /** 按章预处理:拉取、解密、转换后返回 url 或 buffer */
273
298
  | {
274
299
  load: () => Promise<ChapterPdfPayload>;
300
+ }
301
+ /**
302
+ * 章内多 PDF 分段(后端已按段拆分)。
303
+ * `urls.length` 须为 ceil(章页数 / segmentPageThreshold)。
304
+ */
305
+ | {
306
+ urls: string[];
307
+ segmentPageThreshold: number;
275
308
  };
276
309
 
277
310
  declare interface ChapterStatusEvent {
@@ -429,6 +462,9 @@ export declare type ContainerInitConfig = ChapterViewerContainerConfig & {
429
462
  target: Element;
430
463
  };
431
464
 
465
+ /** 将划选文本写入系统剪贴板(Clipboard API,失败时回退 execCommand) */
466
+ export declare function copyTextToClipboard(text: string): Promise<boolean>;
467
+
432
468
  /** 生成插件列表 + 规范化后的 features(供 EmbedPDF / PdfChapterViewport 使用) */
433
469
  export declare function createChapterViewerBundle(input: ChapterViewerOptions | CreateChapterViewerEditorOptionsInput): {
434
470
  plugins: PluginBatchRegistration<any, any, any, any>[];
@@ -567,7 +603,10 @@ declare interface HoverBookmarkUiConfig_2 {
567
603
  * 适合:所有章节走同一套 API、在内存中解密后再以 buffer 打开、动态签名 URL 等。
568
604
  */
569
605
  export declare interface IChapterPdfLoader {
570
- loadPdf(chapter: ChapterDescriptor): Promise<ChapterPdfPayload>;
606
+ /**
607
+ * @param segmentIndex 章内分段索引;单 URL 章节为 0 或省略
608
+ */
609
+ loadPdf(chapter: ChapterDescriptor, segmentIndex?: number): Promise<ChapterPdfPayload>;
571
610
  }
572
611
 
573
612
  /**
@@ -831,6 +870,8 @@ declare interface SelectionToolbarConfig {
831
870
  enabled?: boolean;
832
871
  /** 隐藏部分内置按钮 */
833
872
  hiddenBuiltinActions?: BuiltinSelectionToolbarAction[];
873
+ /** 自定义复制按钮图标;不提供则使用默认图标 */
874
+ renderCopyIcon?: () => unknown;
834
875
  /** 扩展操作(由宿主在 buildSelectionMenu 或 onExtraAction 中处理) */
835
876
  extraActions?: SelectionToolbarExtraAction[];
836
877
  }