@d-i-t-a/reader 2.4.10 → 2.5.0

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.
Files changed (110) hide show
  1. package/README.md +66 -59
  2. package/dist/esm/index.js +64449 -40471
  3. package/dist/esm/index.js.map +4 -4
  4. package/dist/images/altText_add.svg +3 -0
  5. package/dist/images/altText_disclaimer.svg +3 -0
  6. package/dist/images/altText_done.svg +3 -0
  7. package/dist/images/altText_spinner.svg +30 -0
  8. package/dist/images/altText_warning.svg +3 -0
  9. package/dist/images/annotation-check.svg +11 -0
  10. package/dist/images/annotation-comment.svg +16 -0
  11. package/dist/images/annotation-help.svg +26 -0
  12. package/dist/images/annotation-insert.svg +10 -0
  13. package/dist/images/annotation-key.svg +11 -0
  14. package/dist/images/annotation-newparagraph.svg +11 -0
  15. package/dist/images/annotation-noicon.svg +7 -0
  16. package/dist/images/annotation-note.svg +42 -0
  17. package/dist/images/annotation-paperclip.svg +6 -0
  18. package/dist/images/annotation-paragraph.svg +16 -0
  19. package/dist/images/annotation-pushpin.svg +7 -0
  20. package/dist/images/checkmark.svg +5 -0
  21. package/dist/images/comment-actionsButton.svg +3 -0
  22. package/dist/images/comment-closeButton.svg +3 -0
  23. package/dist/images/comment-editButton.svg +8 -0
  24. package/dist/images/comment-popup-editButton.svg +5 -0
  25. package/dist/images/cursor-editorFreeHighlight.svg +6 -0
  26. package/dist/images/cursor-editorFreeText.svg +3 -0
  27. package/dist/images/cursor-editorInk.svg +4 -0
  28. package/dist/images/cursor-editorTextHighlight.svg +8 -0
  29. package/dist/images/editor-toolbar-delete.svg +5 -0
  30. package/dist/images/editor-toolbar-edit.svg +3 -0
  31. package/dist/images/findbarButton-next.svg +3 -0
  32. package/dist/images/findbarButton-previous.svg +3 -0
  33. package/dist/images/gv-toolbarButton-download.svg +3 -0
  34. package/dist/images/loading-icon.gif +0 -0
  35. package/dist/images/loading.svg +1 -0
  36. package/dist/images/messageBar_closingButton.svg +3 -0
  37. package/dist/images/messageBar_info.svg +3 -0
  38. package/dist/images/messageBar_warning.svg +3 -0
  39. package/dist/images/pages_closeButton.svg +3 -0
  40. package/dist/images/pages_selected.svg +7 -0
  41. package/dist/images/pages_viewArrow.svg +3 -0
  42. package/dist/images/pages_viewButton.svg +3 -0
  43. package/dist/images/secondaryToolbarButton-documentProperties.svg +3 -0
  44. package/dist/images/secondaryToolbarButton-firstPage.svg +3 -0
  45. package/dist/images/secondaryToolbarButton-handTool.svg +3 -0
  46. package/dist/images/secondaryToolbarButton-lastPage.svg +3 -0
  47. package/dist/images/secondaryToolbarButton-rotateCcw.svg +3 -0
  48. package/dist/images/secondaryToolbarButton-rotateCw.svg +3 -0
  49. package/dist/images/secondaryToolbarButton-scrollHorizontal.svg +3 -0
  50. package/dist/images/secondaryToolbarButton-scrollPage.svg +3 -0
  51. package/dist/images/secondaryToolbarButton-scrollVertical.svg +3 -0
  52. package/dist/images/secondaryToolbarButton-scrollWrapped.svg +3 -0
  53. package/dist/images/secondaryToolbarButton-selectTool.svg +3 -0
  54. package/dist/images/secondaryToolbarButton-spreadEven.svg +3 -0
  55. package/dist/images/secondaryToolbarButton-spreadNone.svg +3 -0
  56. package/dist/images/secondaryToolbarButton-spreadOdd.svg +3 -0
  57. package/dist/images/toolbarButton-bookmark.svg +3 -0
  58. package/dist/images/toolbarButton-currentOutlineItem.svg +3 -0
  59. package/dist/images/toolbarButton-download.svg +4 -0
  60. package/dist/images/toolbarButton-editorFreeText.svg +5 -0
  61. package/dist/images/toolbarButton-editorHighlight.svg +6 -0
  62. package/dist/images/toolbarButton-editorInk.svg +4 -0
  63. package/dist/images/toolbarButton-editorSignature.svg +6 -0
  64. package/dist/images/toolbarButton-editorStamp.svg +8 -0
  65. package/dist/images/toolbarButton-menuArrow.svg +3 -0
  66. package/dist/images/toolbarButton-openFile.svg +3 -0
  67. package/dist/images/toolbarButton-pageDown.svg +3 -0
  68. package/dist/images/toolbarButton-pageUp.svg +3 -0
  69. package/dist/images/toolbarButton-presentationMode.svg +3 -0
  70. package/dist/images/toolbarButton-print.svg +3 -0
  71. package/dist/images/toolbarButton-search.svg +3 -0
  72. package/dist/images/toolbarButton-secondaryToolbarToggle.svg +3 -0
  73. package/dist/images/toolbarButton-viewAttachments.svg +3 -0
  74. package/dist/images/toolbarButton-viewLayers.svg +3 -0
  75. package/dist/images/toolbarButton-viewOutline.svg +3 -0
  76. package/dist/images/toolbarButton-viewThumbnail.svg +3 -0
  77. package/dist/images/toolbarButton-viewsManagerToggle.svg +3 -0
  78. package/dist/images/toolbarButton-zoomIn.svg +3 -0
  79. package/dist/images/toolbarButton-zoomOut.svg +3 -0
  80. package/dist/images/treeitem-collapsed.svg +1 -0
  81. package/dist/images/treeitem-expanded.svg +1 -0
  82. package/dist/injectables/click/click.js +637 -153
  83. package/dist/injectables/click/click.js.map +4 -4
  84. package/dist/pdf.worker.min.mjs +28 -0
  85. package/dist/pdf_viewer.css +7129 -0
  86. package/dist/reader.css +1 -1
  87. package/dist/reader.css.map +1 -1
  88. package/dist/reader.js +572 -59
  89. package/dist/reader.js.map +4 -4
  90. package/dist/types/index.d.ts +5 -1
  91. package/dist/types/model/user-settings/ReadiumCSS.d.ts +14 -0
  92. package/dist/types/model/user-settings/UserProperties.d.ts +1 -1
  93. package/dist/types/model/user-settings/UserSettings.d.ts +26 -2
  94. package/dist/types/modules/AnnotationModule.d.ts +2 -2
  95. package/dist/types/modules/BookmarkModule.d.ts +2 -2
  96. package/dist/types/modules/ReaderModule.d.ts +6 -0
  97. package/dist/types/modules/citation/CitationModule.d.ts +21 -5
  98. package/dist/types/modules/highlight/TextHighlighter.d.ts +2 -0
  99. package/dist/types/modules/mediaoverlays/MediaOverlayModule.d.ts +4 -0
  100. package/dist/types/modules/protection/ContentProtectionModule.d.ts +1 -2
  101. package/dist/types/navigator/IFrameNavigator.d.ts +37 -16
  102. package/dist/types/navigator/Navigator.d.ts +25 -22
  103. package/dist/types/navigator/PDFNavigator.d.ts +140 -17
  104. package/dist/types/reader.d.ts +15 -7
  105. package/dist/types/store/Annotator.d.ts +26 -22
  106. package/dist/types/store/LocalAnnotator.d.ts +5 -4
  107. package/dist/types/store/LocalStorageStore.d.ts +4 -4
  108. package/dist/types/views/BookView.d.ts +1 -0
  109. package/dist/types/views/ReflowableBookView.d.ts +7 -0
  110. package/package.json +49 -58
@@ -4,4 +4,8 @@ export default D2Reader;
4
4
  /** for interop with \<script\> based usage */
5
5
  export declare const load: typeof D2Reader.load;
6
6
  export { Link } from "./model/Link";
7
- export { Locator, ReadingPosition } from "./model/Locator";
7
+ export { Locator, Locations, LocatorText, ReadingPosition, Bookmark, Annotation, AnnotationMarker, } from "./model/Locator";
8
+ export type { ReaderConfig, ReaderRights, NavigatorAPI, IFrameAttributes, Injectable, RequestConfig, SampleRead, PublicationServices, InitialAnnotations, } from "./navigator/IFrameNavigator";
9
+ export type { IUserSettings, InitialUserSettings, } from "./model/user-settings/UserSettings";
10
+ export type { UserSettingsIncrementable } from "./model/user-settings/UserProperties";
11
+ export type { LocalStorageStoreConfig } from "./store/LocalStorageStore";
@@ -4,6 +4,7 @@ export declare class ReadiumCSS {
4
4
  static readonly FONT_OVERRIDE_REF = "fontOverride";
5
5
  static readonly APPEARANCE_REF = "appearance";
6
6
  static readonly SCROLL_REF = "scroll";
7
+ static readonly ADVANCED_SETTINGS_REF = "advancedSettings";
7
8
  static readonly TEXT_ALIGNMENT_REF = "textAlign";
8
9
  static readonly COLUMN_COUNT_REF = "colCount";
9
10
  static readonly DIRECTION_REF = "direction";
@@ -11,11 +12,18 @@ export declare class ReadiumCSS {
11
12
  static readonly LETTER_SPACING_REF = "letterSpacing";
12
13
  static readonly PAGE_MARGINS_REF = "pageMargins";
13
14
  static readonly LINE_HEIGHT_REF = "lineHeight";
15
+ static readonly BODY_HYPHENS_REF = "bodyHyphens";
16
+ static readonly PARA_SPACING_REF = "paraSpacing";
17
+ static readonly PARA_INDENT_REF = "paraIndent";
18
+ static readonly TYPE_SCALE_REF = "typeScale";
19
+ static readonly BACKGROUND_COLOR_REF = "backgroundColor";
20
+ static readonly TEXT_COLOR_REF = "textColor";
14
21
  static readonly FONT_SIZE_KEY: string;
15
22
  static readonly FONT_FAMILY_KEY: string;
16
23
  static readonly FONT_OVERRIDE_KEY: string;
17
24
  static readonly APPEARANCE_KEY: string;
18
25
  static readonly SCROLL_KEY: string;
26
+ static readonly ADVANCED_SETTINGS_KEY: string;
19
27
  static readonly TEXT_ALIGNMENT_KEY: string;
20
28
  static readonly COLUMN_COUNT_KEY: string;
21
29
  static readonly DIRECTION_KEY: string;
@@ -23,4 +31,10 @@ export declare class ReadiumCSS {
23
31
  static readonly LETTER_SPACING_KEY: string;
24
32
  static readonly PAGE_MARGINS_KEY: string;
25
33
  static readonly LINE_HEIGHT_KEY: string;
34
+ static readonly BODY_HYPHENS_KEY: string;
35
+ static readonly PARA_SPACING_KEY: string;
36
+ static readonly PARA_INDENT_KEY: string;
37
+ static readonly TYPE_SCALE_KEY: string;
38
+ static readonly BACKGROUND_COLOR_KEY: string;
39
+ static readonly TEXT_COLOR_KEY: string;
26
40
  }
@@ -20,7 +20,7 @@ export declare class Enumerable extends UserProperty {
20
20
  constructor(value: any, values: Array<any>, ref: string, name: string);
21
21
  toString(): string;
22
22
  }
23
- export type UserSettingsIncrementable = "fontSize" | "letterSpacing" | "lineHeight" | "wordSpacing";
23
+ export type UserSettingsIncrementable = "fontSize" | "letterSpacing" | "lineHeight" | "wordSpacing" | "paraSpacing" | "paraIndent" | "typeScale";
24
24
  export declare class Incremental extends UserProperty {
25
25
  value: number;
26
26
  min: number;
@@ -5,7 +5,7 @@ import BookView from "../../views/BookView";
5
5
  export interface UserSettingsConfig {
6
6
  /** Store to save the user's selections in. */
7
7
  store: Store;
8
- initialUserSettings: InitialUserSettings;
8
+ initialUserSettings?: Partial<InitialUserSettings>;
9
9
  headerMenu?: HTMLElement | null;
10
10
  api?: Partial<NavigatorAPI>;
11
11
  injectables?: Array<Injectable>;
@@ -40,6 +40,12 @@ export interface IUserSettings {
40
40
  letterSpacing: number;
41
41
  pageMargins: number;
42
42
  lineHeight: number;
43
+ bodyHyphens: boolean;
44
+ paraSpacing: number;
45
+ paraIndent: number;
46
+ typeScale: number;
47
+ backgroundColor: string;
48
+ textColor: string;
43
49
  }
44
50
  /**
45
51
  * The settings that someone might pass in when instantiating
@@ -59,6 +65,12 @@ export interface InitialUserSettings {
59
65
  letterSpacing: number;
60
66
  pageMargins: number;
61
67
  lineHeight: number;
68
+ bodyHyphens?: boolean;
69
+ paraSpacing?: number;
70
+ paraIndent?: number;
71
+ typeScale?: number;
72
+ backgroundColor?: string;
73
+ textColor?: string;
62
74
  }
63
75
  export declare class UserSettings implements IUserSettings {
64
76
  isPaginated(): Promise<boolean>;
@@ -82,6 +94,12 @@ export declare class UserSettings implements IUserSettings {
82
94
  letterSpacing: number;
83
95
  pageMargins: number;
84
96
  lineHeight: number;
97
+ bodyHyphens: boolean;
98
+ paraSpacing: number;
99
+ paraIndent: number;
100
+ typeScale: number;
101
+ backgroundColor: string;
102
+ textColor: string;
85
103
  userProperties?: UserProperties;
86
104
  view: BookView;
87
105
  private settingsChangeCallback;
@@ -130,6 +148,12 @@ export declare class UserSettings implements IUserSettings {
130
148
  letterSpacing: number;
131
149
  pageMargins: number;
132
150
  lineHeight: number;
151
+ bodyHyphens: boolean;
152
+ paraSpacing: number;
153
+ paraIndent: number;
154
+ typeScale: number;
155
+ backgroundColor: string;
156
+ textColor: string;
133
157
  };
134
158
  applyUserSettings(userSettings: Partial<UserSettings>): Promise<void>;
135
159
  /**
@@ -139,5 +163,5 @@ export declare class UserSettings implements IUserSettings {
139
163
  private static parseAppearanceSetting;
140
164
  scroll(scroll: boolean): Promise<void>;
141
165
  increase(incremental: UserSettingsIncrementable): Promise<void>;
142
- decrease(incremental: any): Promise<void>;
166
+ decrease(incremental: UserSettingsIncrementable): Promise<void>;
143
167
  }
@@ -23,7 +23,7 @@ export interface AnnotationModuleConfig extends AnnotationModuleProperties {
23
23
  headerMenu?: HTMLElement | null;
24
24
  rights: Partial<ReaderRights>;
25
25
  publication: Publication;
26
- initialAnnotations?: any;
26
+ initialAnnotations?: import("../navigator/IFrameNavigator").InitialAnnotations;
27
27
  api?: AnnotationModuleAPI;
28
28
  highlighter: TextHighlighter;
29
29
  }
@@ -35,7 +35,7 @@ export declare class AnnotationModule implements ReaderModule {
35
35
  private commentGutter?;
36
36
  private readonly headerMenu?;
37
37
  private readonly highlighter?;
38
- private readonly initialAnnotations;
38
+ private readonly initialAnnotations?;
39
39
  navigator: IFrameNavigator;
40
40
  properties?: AnnotationModuleProperties;
41
41
  api?: AnnotationModuleAPI;
@@ -16,7 +16,7 @@ export interface BookmarkModuleConfig extends BookmarkModuleProperties {
16
16
  headerMenu?: HTMLElement | null;
17
17
  rights: Partial<ReaderRights>;
18
18
  publication: Publication;
19
- initialAnnotations?: any;
19
+ initialAnnotations?: import("../navigator/IFrameNavigator").InitialAnnotations;
20
20
  properties?: BookmarkModuleProperties;
21
21
  api?: BookmarkModuleAPI;
22
22
  }
@@ -27,7 +27,7 @@ export declare class BookmarkModule implements ReaderModule {
27
27
  private bookmarksView;
28
28
  private sideNavSectionBookmarks;
29
29
  private readonly headerMenu?;
30
- private readonly initialAnnotations;
30
+ private readonly initialAnnotations?;
31
31
  navigator: IFrameNavigator;
32
32
  private readonly properties;
33
33
  private readonly api?;
@@ -1,2 +1,8 @@
1
+ /**
2
+ * Base interface for all optional reader feature modules.
3
+ * Each module must implement `stop()` to clean up event listeners and resources
4
+ * when the reader is destroyed.
5
+ */
1
6
  export interface ReaderModule {
7
+ stop(): void;
2
8
  }
@@ -25,8 +25,8 @@ export interface CitationModuleProperties {
25
25
  published?: string;
26
26
  }
27
27
  export interface CitationModuleAPI {
28
- citationCreated: any;
29
- citationFailed: any;
28
+ citationCreated: (message: string) => void;
29
+ citationFailed: (message: string) => void;
30
30
  }
31
31
  export interface CitationModuleConfig extends CitationModuleProperties {
32
32
  publication: Publication;
@@ -42,8 +42,24 @@ export default class CitationModule implements ReaderModule {
42
42
  private constructor();
43
43
  static create(config: CitationModuleConfig): Promise<CitationModule>;
44
44
  stop(): Promise<void>;
45
- copyToClipboard(textToClipboard: any): void;
46
- createElementForExecCommand(textToClipboard: any): HTMLDivElement;
47
- selectContent(element: any): void;
45
+ copyToClipboard(textToClipboard: string): void;
46
+ /** Fallback clipboard copy using deprecated execCommand — used when the
47
+ * Clipboard API is unavailable (e.g. non-secure context). */
48
+ private legacyCopyToClipboard;
49
+ selectContent(element: HTMLElement): void;
50
+ private authorsFormatted;
51
+ private yearPublishedFormatted;
52
+ private bookTitleFormatted;
53
+ private editionFormatted;
54
+ private publisherFormatted;
55
+ private contributorsFormatted;
56
+ private eBookVersionFormatted;
57
+ private locationFormatted;
58
+ private libraryFormatted;
59
+ private appNameFormatted;
60
+ private appLinkFormatted;
61
+ private seriesFormatted;
62
+ private selectedText;
63
+ private buildCitation;
48
64
  protected start(): Promise<void>;
49
65
  }
@@ -58,6 +58,7 @@ export interface TextHighlighterProperties {
58
58
  export interface TextHighlighterConfig extends TextHighlighterProperties {
59
59
  api?: TextSelectorAPI;
60
60
  layerSettings: LayerSettings;
61
+ colors?: string[];
61
62
  }
62
63
  export declare class TextHighlighter {
63
64
  private options;
@@ -68,6 +69,7 @@ export declare class TextHighlighter {
68
69
  private api?;
69
70
  private hasEventListener;
70
71
  activeAnnotationMarkerId?: string;
72
+ colors: string[];
71
73
  static create(config: TextHighlighterConfig): Promise<any>;
72
74
  private constructor();
73
75
  initialize(iframe: HTMLIFrameElement): Promise<void>;
@@ -45,6 +45,7 @@ export declare class MediaOverlayModule implements ReaderModule {
45
45
  private mediaOverlayTextAudioPair;
46
46
  private pid;
47
47
  private __ontimeupdate;
48
+ private clickHandler;
48
49
  static create(config: MediaOverlayModuleConfig): MediaOverlayModule;
49
50
  private constructor();
50
51
  stop(): void;
@@ -52,6 +53,9 @@ export declare class MediaOverlayModule implements ReaderModule {
52
53
  initialize(): Promise<void>;
53
54
  initializeResource(links: Array<Link | undefined>): Promise<void>;
54
55
  private playLink;
56
+ private bindClickHandler;
57
+ private unbindClickHandler;
58
+ private handleContentClick;
55
59
  startReadAloud(): Promise<void>;
56
60
  stopReadAloud(): Promise<void>;
57
61
  pauseReadAloud(): void;
@@ -96,8 +96,7 @@ export declare class ContentProtectionModule implements ReaderModule {
96
96
  }): false | undefined;
97
97
  restrictCopyKey(event: any): boolean;
98
98
  copyToClipboard(textToClipboard: string | undefined): void;
99
- createElementForExecCommand(textToClipboard: any): HTMLDivElement;
100
- selectContent(element: any): void;
99
+ private execCommandCopy;
101
100
  beforePrint(event: {
102
101
  preventDefault: () => void;
103
102
  stopPropagation: () => void;
@@ -28,17 +28,19 @@ export interface RequestConfig extends RequestInit {
28
28
  encoded?: boolean;
29
29
  }
30
30
  export interface NavigatorAPI {
31
- updateSettings: any;
31
+ updateSettings?: (settings: Record<string, unknown>) => Promise<void>;
32
32
  getContent: GetContent;
33
33
  getContentBytesLength: GetContentBytesLength;
34
- resourceReady: any;
35
- resourceAtStart: any;
36
- resourceAtEnd: any;
37
- resourceFitsScreen: any;
38
- updateCurrentLocation: any;
39
- keydownFallthrough: any;
40
- clickThrough: any;
41
- direction: any;
34
+ resourceReady?: () => void;
35
+ resourceAtStart?: () => void;
36
+ resourceAtEnd?: () => void;
37
+ resourceFitsScreen?: () => void;
38
+ updateCurrentLocation?: (locator: import("../model/Locator").ReadingPosition) => Promise<void>;
39
+ positionInfo?: (locator: import("../model/Locator").Locator) => void;
40
+ chapterInfo?: (title: string | undefined) => void;
41
+ keydownFallthrough?: (event: KeyboardEvent | undefined) => void;
42
+ clickThrough?: (event: MouseEvent | TouchEvent) => void;
43
+ direction?: (dir: string) => void;
42
44
  onError?: (e: Error) => void;
43
45
  }
44
46
  export interface IFrameAttributes {
@@ -47,6 +49,10 @@ export interface IFrameAttributes {
47
49
  iframePaddingTop?: number;
48
50
  bottomInfoHeight?: number;
49
51
  sideNavPosition?: "left" | "right";
52
+ /** Margin (in px) around fixed-layout content. Defaults to 100. */
53
+ fixedLayoutMargin?: number;
54
+ /** Whether to show a drop shadow on fixed-layout spreads. Defaults to true. */
55
+ fixedLayoutShadow?: boolean;
50
56
  }
51
57
  export interface IFrameNavigatorConfig {
52
58
  mainElement: HTMLElement;
@@ -64,7 +70,7 @@ export interface IFrameNavigatorConfig {
64
70
  services?: PublicationServices;
65
71
  sample?: SampleRead;
66
72
  requestConfig?: RequestConfig;
67
- modules: ReaderModule[];
73
+ modules: Array<ReaderModule | undefined>;
68
74
  highlighter: TextHighlighter;
69
75
  }
70
76
  export interface PublicationServices {
@@ -108,12 +114,21 @@ export interface ReaderRights {
108
114
  export interface ReaderUI {
109
115
  settings: UserSettingsUIConfig;
110
116
  }
117
+ /**
118
+ * Shape of the initial annotations object passed to `D2Reader.load()`.
119
+ * Both `bookmarks` and `highlights` are optional arrays of their respective types.
120
+ */
121
+ export interface InitialAnnotations {
122
+ bookmarks?: import("../model/Locator").Bookmark[];
123
+ highlights?: import("../model/Locator").Annotation[];
124
+ }
111
125
  export interface ReaderConfig {
112
- publication?: any;
126
+ /** Pre-parsed publication manifest JSON — if omitted the manifest is fetched from `url`. */
127
+ publication?: Record<string, unknown>;
113
128
  url: URL;
114
- userSettings?: any;
115
- initialAnnotations?: any;
116
- lastReadingPosition?: any;
129
+ userSettings?: Partial<import("../model/user-settings/UserSettings").InitialUserSettings>;
130
+ initialAnnotations?: InitialAnnotations;
131
+ lastReadingPosition?: import("../model/Locator").ReadingPosition;
117
132
  rights?: Partial<ReaderRights>;
118
133
  api?: Partial<NavigatorAPI>;
119
134
  tts?: Partial<TTSModuleConfig>;
@@ -136,6 +151,12 @@ export interface ReaderConfig {
136
151
  services?: PublicationServices;
137
152
  sample?: SampleRead;
138
153
  requestConfig?: RequestConfig;
154
+ /**
155
+ * Override the PDF.js worker URL (PDF publications only).
156
+ * Defaults to the unpkg CDN for the bundled pdfjs-dist version.
157
+ * Set to a local path when self-hosting the worker, e.g. `"/viewer/pdf.worker.min.mjs"`.
158
+ */
159
+ workerSrc?: string;
139
160
  }
140
161
  /** Class that shows webpub resources in an iframe, with navigation controls outside the iframe. */
141
162
  export declare class IFrameNavigator extends EventEmitter implements Navigator {
@@ -214,7 +235,7 @@ export declare class IFrameNavigator extends EventEmitter implements Navigator {
214
235
  requestConfig?: RequestConfig;
215
236
  private didInitKeyboardEventHandler;
216
237
  static create(config: IFrameNavigatorConfig): Promise<IFrameNavigator>;
217
- protected constructor(settings: UserSettings, annotator: Annotator | undefined, initialLastReadingPosition: ReadingPosition | undefined, publication: Publication, api?: Partial<NavigatorAPI>, rights?: Partial<ReaderRights>, tts?: Partial<TTSModuleConfig>, injectables?: Array<Injectable>, attributes?: IFrameAttributes, services?: PublicationServices, sample?: SampleRead, requestConfig?: RequestConfig, highlighter?: TextHighlighter, modules?: ReaderModule[]);
238
+ protected constructor(settings: UserSettings, annotator: Annotator | undefined, initialLastReadingPosition: ReadingPosition | undefined, publication: Publication, api?: Partial<NavigatorAPI>, rights?: Partial<ReaderRights>, tts?: Partial<TTSModuleConfig>, injectables?: Array<Injectable>, attributes?: IFrameAttributes, services?: PublicationServices, sample?: SampleRead, requestConfig?: RequestConfig, highlighter?: TextHighlighter, modules?: Array<ReaderModule | undefined>);
218
239
  stop(): void;
219
240
  spreads: HTMLDivElement;
220
241
  firstSpread: HTMLDivElement;
@@ -262,7 +283,7 @@ export declare class IFrameNavigator extends EventEmitter implements Navigator {
262
283
  nextResource(): any;
263
284
  goTo(locator: Locator): any;
264
285
  currentLocator(): Locator;
265
- positions(): any;
286
+ positions(): Locator[];
266
287
  goToPosition(position: number): void;
267
288
  goToPage(page: number): Promise<void>;
268
289
  snapToSelector(selector: any): void;
@@ -1,10 +1,12 @@
1
1
  import { Locator } from "../model/Locator";
2
2
  import { IFrameAttributes } from "./IFrameNavigator";
3
+ import { Publication } from "../model/Publication";
4
+ import { Link } from "../model/Link";
3
5
  interface Navigator {
4
- publication: any;
5
- rights?: any;
6
- hasMediaOverlays?: any;
7
- addListener?(argument: any, argument2: any): void;
6
+ publication: Publication;
7
+ rights?: Record<string, boolean>;
8
+ hasMediaOverlays?: boolean;
9
+ addListener?(event: string, handler: (...args: any[]) => void): void;
8
10
  startReadAloud?(): void;
9
11
  stopReadAloud?(): void;
10
12
  pauseReadAloud?(): void;
@@ -13,29 +15,30 @@ interface Navigator {
13
15
  stopReadAlong?(): void;
14
16
  pauseReadAlong?(): void;
15
17
  resumeReadAlong?(): void;
16
- hideLayer?(layer: any): any;
17
- showLayer?(layer: any): any;
18
- activateMarker?(id: string, position: string): any;
19
- deactivateMarker?(): any;
20
- tableOfContents(): any;
21
- landmarks(): any;
22
- pageList(): any;
23
- readingOrder(): any;
24
- currentResource(): any;
25
- mostRecentNavigatedTocItem?(): any;
26
- totalResources(): any;
27
- currentLocator(): any;
28
- positions(): any;
18
+ hideLayer?(layer: string): void;
19
+ showLayer?(layer: string): void;
20
+ activateMarker?(id: string, position: string): void;
21
+ deactivateMarker?(): void;
22
+ tableOfContents(): Link[];
23
+ landmarks(): Link[];
24
+ pageList(): Link[];
25
+ readingOrder(): Link[];
26
+ /** Returns the spine index of the current resource, or undefined if not yet loaded. */
27
+ currentResource(): number | undefined;
28
+ mostRecentNavigatedTocItem?(): string | undefined;
29
+ totalResources(): number;
30
+ currentLocator(): Locator;
31
+ positions(): Locator[];
29
32
  goTo(locator: Locator): void;
30
- goToPosition(value: number): any;
31
- goToPage(page: number): any;
33
+ goToPosition(value: number): void;
34
+ goToPage(page: number): void;
32
35
  nextResource(): void;
33
36
  previousResource(): void;
34
37
  nextPage(): void;
35
38
  previousPage(): void;
36
- atStart?(): any;
37
- atEnd?(): any;
38
- snapToSelector?(selector: any): void;
39
+ atStart?(): boolean;
40
+ atEnd?(): boolean;
41
+ snapToSelector?(selector: string): void;
39
42
  applyAttributes?(value: IFrameAttributes): void;
40
43
  stop(): void;
41
44
  }
@@ -2,8 +2,13 @@ import EventEmitter from "eventemitter3";
2
2
  import Navigator from "./Navigator";
3
3
  import { UserSettings } from "../model/user-settings/UserSettings";
4
4
  import { Publication } from "../model/Publication";
5
- import { Locator } from "../model/Locator";
5
+ import { Bookmark, Locator, ReadingPosition } from "../model/Locator";
6
+ import Annotator from "../store/Annotator";
7
+ import Store from "../store/Store";
8
+ import { AnnotationEditorType } from "pdfjs-dist";
9
+ import { EventBus, ScrollMode, SpreadMode } from "pdfjs-dist/web/pdf_viewer.mjs";
6
10
  import { NavigatorAPI } from "./IFrameNavigator";
11
+ export { SpreadMode, ScrollMode, AnnotationEditorType };
7
12
  export interface PDFNavigatorConfig {
8
13
  mainElement: HTMLElement;
9
14
  headerMenu?: HTMLElement | null;
@@ -11,6 +16,22 @@ export interface PDFNavigatorConfig {
11
16
  publication: Publication;
12
17
  settings: UserSettings;
13
18
  api?: Partial<NavigatorAPI>;
19
+ /**
20
+ * Override the PDF.js worker URL.
21
+ * Defaults to unpkg CDN for the bundled pdfjs-dist version.
22
+ * Set this if you want to self-host the worker (copy
23
+ * node_modules/pdfjs-dist/build/pdf.worker.min.mjs to your server).
24
+ */
25
+ workerSrc?: string;
26
+ /** Annotator used to persist the last reading position and bookmarks across sessions. */
27
+ annotator?: Annotator;
28
+ /** Pre-loaded reading position to seed the annotator before navigation. */
29
+ initialLastReadingPosition?: ReadingPosition;
30
+ /**
31
+ * Store used to persist PDF view settings (scroll mode, spread mode, zoom, rotation)
32
+ * across sessions. Pass the publication store from D2Reader.load().
33
+ */
34
+ store?: Store;
14
35
  }
15
36
  export declare enum ScaleType {
16
37
  Page = 0,
@@ -25,45 +46,147 @@ export declare class PDFNavigator extends EventEmitter implements Navigator {
25
46
  pdfContainer: HTMLElement;
26
47
  wrapper: HTMLElement;
27
48
  api?: Partial<NavigatorAPI>;
28
- pdfDoc: any;
29
49
  pageNum: number;
30
- scaleType: ScaleType;
31
- pageRendering: boolean;
32
- pageNumPending: any;
33
- scale: number;
34
50
  resourceIndex: number;
35
- resource: any;
51
+ private pdfDoc;
52
+ private resource;
53
+ private workerSrc;
54
+ private _numPages;
55
+ private annotator?;
56
+ private viewStore?;
57
+ private initialLastReadingPosition?;
58
+ private _positionRestored;
59
+ private _pendingAnnotations;
60
+ private pdfViewer;
61
+ eventBus: EventBus;
62
+ private linkService;
63
+ private findController;
64
+ private pdfHistory;
36
65
  private handTool;
66
+ private resizeTimeout;
37
67
  static create(config: PDFNavigatorConfig): Promise<PDFNavigator>;
38
- protected constructor(settings: UserSettings, publication: Publication, api?: Partial<NavigatorAPI>);
68
+ protected constructor(settings: UserSettings, publication: Publication, api?: Partial<NavigatorAPI>, workerSrc?: string, annotator?: Annotator, initialLastReadingPosition?: ReadingPosition, viewStore?: Store);
39
69
  protected start(mainElement: HTMLElement, headerMenu?: HTMLElement | null, footerMenu?: HTMLElement | null): Promise<void>;
40
- timeout: any;
41
- onResize: () => void;
42
- handleResize(): Promise<void>;
43
- private setupEvents;
44
- loadPDFJS(num: any): void;
45
- queueRenderPage(num: any): void;
70
+ private showLoading;
71
+ private hideLoading;
72
+ private loadDocument;
73
+ private onResize;
46
74
  readingOrder(): any;
47
75
  tableOfContents(): any;
48
76
  landmarks(): any;
49
77
  pageList(): any;
50
- currentResource(): any;
51
- totalResources(): any;
52
- currentLocator(): any;
78
+ atStart(): boolean;
79
+ atEnd(): boolean;
80
+ currentResource(): number;
81
+ totalResources(): number;
82
+ currentLocator(): Locator;
53
83
  positions(): any;
84
+ /** Total page count of the currently loaded document. */
85
+ get numPages(): number;
54
86
  nextPage(): void;
55
87
  previousPage(): void;
56
88
  nextResource(): void;
57
89
  previousResource(): void;
58
90
  goTo(locator: Locator): void;
91
+ /**
92
+ * Extract a 1-based page number from an href.
93
+ * Handles:
94
+ * - `#page=N` — PDF.js / PDF URL fragment convention
95
+ * - `?start=N` — Readium webpub-manifest convention
96
+ * - `?page=N` — alternative query param
97
+ */
98
+ private pageFromHref;
99
+ private toAbsoluteHref;
59
100
  goToPosition(value: number): void;
60
101
  goToPage(page: number): Promise<void>;
102
+ private static readonly KEY_SCROLL;
103
+ private static readonly KEY_SPREAD;
104
+ private static readonly KEY_SCALE;
105
+ private static readonly KEY_ROTATE;
106
+ private saveViewSetting;
107
+ private restoreViewSettings;
108
+ private annotationKey;
109
+ /**
110
+ * Serialize the in-memory AnnotationStorage and write it to the viewStore.
111
+ * Called via `annotationStorage.onSetModified` whenever an annotation is
112
+ * added, edited, or deleted.
113
+ *
114
+ * Entries with bitmaps (image stamps) are skipped because ImageBitmap
115
+ * cannot be JSON-serialised — they would need separate binary storage.
116
+ */
117
+ /**
118
+ * Recursively converts TypedArray instances (Float32Array, etc.) to plain
119
+ * arrays so they survive JSON round-trip. TypedArrays stringify as objects
120
+ * { "0": n, "1": n, … } which have no .length, breaking pdfjs deserialization.
121
+ */
122
+ private static toJsonSafe;
123
+ private saveAnnotations;
124
+ /**
125
+ * Parse saved annotations from the store and group them by page index so
126
+ * the `annotationeditorlayerrendered` listener can inject each page's
127
+ * editors as their layer becomes ready. This must be called right after
128
+ * `pdfViewer.setDocument()` so the data is in place before pages render.
129
+ *
130
+ * We do NOT call `annotationStorage.setValue()` here — that only fills the
131
+ * raw storage map and is never read back by the AnnotationEditorUIManager.
132
+ * Instead, `layer.deserialize()` + `layer.addOrRebuild()` reconstructs
133
+ * proper AnnotationEditor instances from the saved JSON.
134
+ */
135
+ private restoreAnnotations;
61
136
  fitToWidth(): void;
62
137
  fitToPage(): void;
63
138
  zoomIn(): void;
64
139
  zoomOut(): void;
140
+ rotateCw(): void;
141
+ rotateCcw(): void;
142
+ setSpreadMode(mode: number): void;
143
+ /**
144
+ * Activate an annotation editor tool.
145
+ * Pass an `AnnotationEditorType` value:
146
+ * NONE = 0 — editor on, no tool active (cursor / select mode)
147
+ * FREETEXT = 3 — add text notes
148
+ * HIGHLIGHT = 9 — highlight selected text
149
+ * STAMP = 13 — insert image stamps
150
+ * INK = 15 — freehand drawing
151
+ */
152
+ setAnnotationEditorMode(mode: number): void;
153
+ /**
154
+ * The AnnotationStorage instance that holds all user-created annotations
155
+ * for the current document. Serialize with `.serializable` to persist them.
156
+ */
157
+ get annotationStorage(): import("pdfjs-dist/types/src/display/annotation_storage").AnnotationStorage | undefined;
158
+ /**
159
+ * Clear all user-created annotations for the current document and remove
160
+ * the persisted copy from the store.
161
+ */
162
+ /**
163
+ * Returns every annotation across all pages — both those already deserialized
164
+ * into live editor objects (in annotationStorage) and those still waiting for
165
+ * their page to render (in _pendingAnnotations). The sidebar uses this so it
166
+ * can show the complete list without requiring every page to be scrolled into view.
167
+ */
168
+ getAllAnnotations(): Record<string, unknown>[];
169
+ clearAnnotations(): void;
170
+ private makeBookmark;
171
+ /** Save a bookmark for the current page. Returns null if already bookmarked. */
172
+ saveBookmark(): Bookmark | null;
173
+ /** Delete a previously saved bookmark. */
174
+ deleteBookmark(bookmark: Bookmark): void;
175
+ /** Return all bookmarks for the current resource. */
176
+ getBookmarks(): Bookmark[];
177
+ /** True if the current page already has a bookmark. */
178
+ isCurrentPageBookmarked(): boolean;
65
179
  activateHand(): void;
66
180
  deactivateHand(): void;
67
181
  scroll(scroll: boolean, direction?: string): Promise<void>;
182
+ find(query: string, options?: {
183
+ caseSensitive?: boolean;
184
+ highlightAll?: boolean;
185
+ findPrevious?: boolean;
186
+ }): void;
187
+ findNext(): void;
188
+ findPrevious(): void;
189
+ private saveLastReadingPosition;
190
+ private restoreLastReadingPosition;
68
191
  stop(): void;
69
192
  }