@nypl/web-reader 4.3.4 → 5.0.0-alpha.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.
package/dist/index.d.ts CHANGED
@@ -36,11 +36,14 @@ interface Locations {
36
36
  declare const ReadiumWebpubContext = "http://readium.org/webpub/default.jsonld";
37
37
  declare const IS_DEV: boolean;
38
38
  declare const HEADER_HEIGHT = 48;
39
- declare const FOOTER_HEIGHT = 48;
40
- declare const CHROME_HEIGHT: number;
41
- declare const DEFAULT_HEIGHT: string;
39
+ declare const CHROME_HEIGHT = 48;
40
+ declare const DEFAULT_HEIGHT = "calc(100vh - 48px)";
42
41
  declare const DEFAULT_SHOULD_GROW_WHEN_SCROLLING = true;
42
+ declare const READER_MARGIN = 16;
43
43
  declare const DEFAULT_SETTINGS: ReaderSettings;
44
+ declare const DEFAULT_FIT_MODE = "height";
45
+ declare const DEFAULT_FONT_HEIGHT = 100;
46
+ declare const DEFAULT_FONT_WIDTH = 250;
44
47
  declare const FONT_DETAILS: {
45
48
  publisher: {
46
49
  heading: string;
@@ -73,7 +76,7 @@ declare const MAIN_CONTENT_ID = "mainContent";
73
76
 
74
77
  declare const WebpubPdfConformsTo = "http://librarysimplified.org/terms/profiles/pdf";
75
78
  declare const EpubConformsTo = "https://readium.org/webpub-manifest/profiles/epub";
76
- declare type ConformsTo = typeof WebpubPdfConformsTo | typeof EpubConformsTo;
79
+ type ConformsTo = typeof WebpubPdfConformsTo | typeof EpubConformsTo;
77
80
 
78
81
  interface EPUBExtensionLinkProperties {
79
82
  /**
@@ -282,9 +285,9 @@ interface ContributorObject {
282
285
  links?: ReadiumLink[];
283
286
  [k: string]: unknown;
284
287
  }
285
- declare type Contributor = string | (string | ContributorObject)[] | ContributorObject;
288
+ type Contributor = string | (string | ContributorObject)[] | ContributorObject;
286
289
 
287
- declare type LanguageMap = string | {
290
+ type LanguageMap = string | {
288
291
  [k: string]: string;
289
292
  };
290
293
 
@@ -302,7 +305,7 @@ interface SubjectObject {
302
305
  links?: ReadiumLink[];
303
306
  [k: string]: unknown;
304
307
  }
305
- declare type Subject = string | (string | SubjectObject)[] | SubjectObject;
308
+ type Subject = string | (string | SubjectObject)[] | SubjectObject;
306
309
 
307
310
  interface Metadata extends Contributors, EPUBExtensionMetadata {
308
311
  identifier?: string;
@@ -360,26 +363,30 @@ interface WebpubManifest {
360
363
  toc?: ReadiumLink[];
361
364
  }
362
365
 
363
- declare type ColorMode = 'night' | 'sepia' | 'day';
364
- declare type FontFamily = 'publisher' | 'serif' | 'sans-serif' | 'open-dyslexic';
365
- declare type Navigator = {
366
+ type ColorMode = 'night' | 'sepia' | 'day';
367
+ type FontFamily = 'publisher' | 'serif' | 'sans-serif' | 'open-dyslexic';
368
+ type FitMode = 'width' | 'height';
369
+ type Navigator = {
366
370
  goForward: () => void;
367
371
  goBackward: () => void;
368
372
  setScroll: (val: 'scrolling' | 'paginated') => Promise<void>;
369
373
  goToPage: (href: string) => void;
374
+ goToPageNumber: (pageNumber: number) => void;
375
+ setFitMode: (mode: FitMode) => void;
370
376
  };
371
- declare type PdfNavigator = Navigator & {
377
+ type PdfNavigator = Navigator & {
372
378
  zoomIn: () => Promise<void>;
373
379
  zoomOut: () => Promise<void>;
380
+ rotateCounterClockwise: () => void;
374
381
  };
375
- declare type HtmlNavigator = Navigator & {
382
+ type HtmlNavigator = Navigator & {
376
383
  increaseFontSize: () => Promise<void>;
377
384
  decreaseFontSize: () => Promise<void>;
378
- resetSettings: () => Promise<void>;
379
385
  setFontFamily: (family: FontFamily) => Promise<void>;
380
386
  setColorMode: (mode: ColorMode) => Promise<void>;
387
+ resetSettings: () => Promise<void>;
381
388
  };
382
- declare type ReaderSettings = {
389
+ type ReaderSettings = {
383
390
  colorMode: ColorMode;
384
391
  isScrolling: boolean;
385
392
  fontSize: number;
@@ -391,14 +398,16 @@ declare type ReaderSettings = {
391
398
  * reader (pdf/html) has its own internal state with
392
399
  * more details necessary for rendering
393
400
  */
394
- declare type ReaderState = {
401
+ type ReaderState = {
395
402
  atStart: boolean;
396
403
  atEnd: boolean;
397
404
  location?: Locator;
398
405
  settings: ReaderSettings | undefined;
406
+ fitMode: FitMode;
407
+ rotation?: number;
399
408
  };
400
- declare type InactiveReader = null;
401
- declare type LoadingReader = {
409
+ type InactiveReader = null;
410
+ type LoadingReader = {
402
411
  isLoading: true;
403
412
  content: JSX.Element;
404
413
  navigator: null;
@@ -406,31 +415,31 @@ declare type LoadingReader = {
406
415
  manifest: null;
407
416
  type: null;
408
417
  };
409
- declare type CommonReader = {
418
+ type CommonReader = {
410
419
  isLoading: false;
411
420
  content: JSX.Element;
412
421
  manifest: WebpubManifest;
422
+ currentPage: number;
423
+ totalPages: number;
424
+ toggleFullScreen?: () => void;
413
425
  };
414
- declare type PDFActiveReader = CommonReader & {
426
+ type PDFActiveReader = CommonReader & {
415
427
  state: ReaderState;
416
428
  navigator: PdfNavigator;
417
429
  type: 'PDF';
418
430
  };
419
- declare type HTMLActiveReader = CommonReader & {
431
+ type HTMLActiveReader = CommonReader & {
420
432
  state: ReaderState;
421
433
  navigator: HtmlNavigator;
422
434
  type: 'HTML';
423
435
  };
424
- declare type ActiveReader = PDFActiveReader | HTMLActiveReader;
425
- declare type ReaderReturn = InactiveReader | LoadingReader | ActiveReader;
426
- declare type GetContent = (href: string) => Promise<string>;
427
- declare type ReaderManagerArguments = {
428
- headerLeft?: JSX.Element;
429
- };
430
- declare type UseWebReaderArguments = {
436
+ type ActiveReader = PDFActiveReader | HTMLActiveReader;
437
+ type ReaderReturn = InactiveReader | LoadingReader | ActiveReader;
438
+ type GetContent<T extends string | Uint8Array> = (href: string, proxyUrl?: string) => Promise<T>;
439
+ type UseWebReaderArguments<T extends string | Uint8Array> = {
431
440
  webpubManifestUrl: string;
432
441
  proxyUrl?: string;
433
- getContent?: GetContent;
442
+ getContent?: GetContent<T>;
434
443
  pdfWorkerSrc?: string;
435
444
  injectablesReflowable?: Injectable[];
436
445
  injectablesFixed?: Injectable[];
@@ -469,21 +478,21 @@ declare type UseWebReaderArguments = {
469
478
  * Default: `true`
470
479
  */
471
480
  persistSettings?: boolean;
481
+ /**
482
+ * Optional callback to expand the reader to full viewport.
483
+ */
484
+ toggleFullScreen?: () => void;
472
485
  };
473
- declare type ActiveReaderArguments = UseWebReaderArguments & {
486
+ type ActiveReaderArguments<T extends string | Uint8Array> = UseWebReaderArguments<T> & {
474
487
  manifest: WebpubManifest;
475
488
  };
476
- declare type InactiveReaderArguments = undefined;
477
- declare type ReaderArguments = ActiveReaderArguments | InactiveReaderArguments;
489
+ type InactiveReaderArguments = undefined;
478
490
 
479
- /**
480
- * The React hook that exposes the main API into the reader. It
481
- * will determine the type of the webpub, and then use the correct reader
482
- * for that type.
483
- */
484
- declare function useWebReader(args: UseWebReaderArguments): HTMLActiveReader | PDFActiveReader | LoadingReader;
491
+ type HtmlReaderArguments = ActiveReaderArguments<string> | InactiveReaderArguments;
485
492
 
486
- declare function useHtmlReader(args: ReaderArguments): ReaderReturn;
493
+ declare function useHtmlReader(args: HtmlReaderArguments): ReaderReturn;
494
+
495
+ type PdfReaderArguments = ActiveReaderArguments<Uint8Array> | InactiveReaderArguments;
487
496
 
488
497
  /**
489
498
  * The PDF reader
@@ -494,9 +503,21 @@ declare function useHtmlReader(args: ReaderArguments): ReaderReturn;
494
503
  * @param args T
495
504
  * @returns
496
505
  */
497
- declare function usePdfReader(args: ReaderArguments): ReaderReturn;
506
+ declare function usePdfReader(args: PdfReaderArguments): ReaderReturn;
498
507
 
499
- declare type Dict<T = any> = Record<string, T>;
508
+ /**
509
+ * Adds TOC data to Webpub Manifest from single-resource PDF using PDF.js
510
+ * @param manifest
511
+ * @param getResource - a function to get the resource. This allows the caller
512
+ * to decide how to get the resource, for example through a proxy if necessary.
513
+ * @param pdfWorkerSrc - the path to the pdfjs worker file. Necessary to use pdfjs.
514
+ * @returns {WebpubManifest} manifest object
515
+ */
516
+ declare function addTocToManifest(manifest: WebpubManifest, getResource: (url: string) => Promise<Uint8Array>, pdfWorkerSrc: string): Promise<WebpubManifest>;
517
+
518
+ declare const useColorModeValue: (light: string, dark: string, sepia: string) => string;
519
+
520
+ type Dict<T = any> = Record<string, T>;
500
521
 
501
522
  /**
502
523
  * See Chakra default theme for shape of theme object:
@@ -509,25 +530,20 @@ declare type Dict<T = any> = Record<string, T>;
509
530
  */
510
531
  declare function getTheme(colorMode?: ColorMode): Dict<unknown>;
511
532
 
512
- declare const useColorModeValue: (light: string, dark: string, sepia: string) => string;
513
-
514
- declare function clearWebReaderLocalStorage(): void;
515
-
516
533
  /**
517
- * Adds TOC data to Webpub Manifest from single-resource PDF using PDF.js
518
- * @param manifest
519
- * @param getResource - a function to get the resource. This allows the caller
520
- * to decide how to get the resource, for example through a proxy if necessary.
521
- * @param pdfWorkerSrc - the path to the pdfjs worker file. Necessary to use pdfjs.
522
- * @returns {WebpubManifest} manifest object
534
+ * The React hook that exposes the main API into the reader. It
535
+ * will determine the type of the webpub, and then use the correct reader
536
+ * for that type.
523
537
  */
524
- declare function addTocToManifest(manifest: WebpubManifest, getResource: (url: string) => Promise<Uint8Array>, pdfWorkerSrc: string): Promise<WebpubManifest>;
538
+ declare function useWebReader(args: UseWebReaderArguments<string | Uint8Array>): HTMLActiveReader | PDFActiveReader | LoadingReader;
539
+
540
+ declare function clearWebReaderLocalStorage(): void;
525
541
 
526
542
  /**
527
543
  * The main React component export.
528
544
  */
529
- declare type WebReaderProps = UseWebReaderArguments & ReaderManagerArguments;
545
+ type WebReaderProps = UseWebReaderArguments<string | Uint8Array>;
530
546
  declare const WebReaderWithoutBoundary: FC<WebReaderProps>;
531
547
  declare const WebReader: FC<WebReaderProps>;
532
548
 
533
- export { CHROME_HEIGHT, DEFAULT_HEIGHT, DEFAULT_SETTINGS, DEFAULT_SHOULD_GROW_WHEN_SCROLLING, FONT_DETAILS, FOOTER_HEIGHT, HEADER_HEIGHT, IS_DEV, LOCAL_STORAGE_LOCATIONS_KEY, LOCAL_STORAGE_SETTINGS_KEY, MAIN_CONTENT_ID, ReadiumLink, ReadiumWebpubContext, WebReaderProps, WebReaderWithoutBoundary, WebpubManifest, addTocToManifest, clearWebReaderLocalStorage, WebReader as default, getTheme, useColorModeValue, useHtmlReader, usePdfReader, useWebReader };
549
+ export { CHROME_HEIGHT, DEFAULT_FIT_MODE, DEFAULT_FONT_HEIGHT, DEFAULT_FONT_WIDTH, DEFAULT_HEIGHT, DEFAULT_SETTINGS, DEFAULT_SHOULD_GROW_WHEN_SCROLLING, FONT_DETAILS, HEADER_HEIGHT, IS_DEV, LOCAL_STORAGE_LOCATIONS_KEY, LOCAL_STORAGE_SETTINGS_KEY, MAIN_CONTENT_ID, READER_MARGIN, type ReadiumLink, ReadiumWebpubContext, type WebReaderProps, WebReaderWithoutBoundary, type WebpubManifest, addTocToManifest, clearWebReaderLocalStorage, WebReader as default, getTheme, useColorModeValue, useHtmlReader, usePdfReader, useWebReader };