@nypl/web-reader 4.3.5 → 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/README.md +2 -27
- package/dist/index.css +17 -344
- package/dist/index.css.map +1 -1
- package/dist/index.d.mts +549 -0
- package/dist/index.d.ts +65 -52
- package/dist/index.js +3835 -3797
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3694 -3643
- package/dist/index.mjs.map +1 -1
- package/dist/injectable-html-styles/ReadiumCSS-after.css.map +1 -1
- package/dist/injectable-html-styles/ReadiumCSS-after.d.mts +2 -0
- package/dist/injectable-html-styles/ReadiumCSS-after.d.ts +1 -1
- package/dist/injectable-html-styles/ReadiumCSS-before.css.map +1 -1
- package/dist/injectable-html-styles/ReadiumCSS-before.d.mts +2 -0
- package/dist/injectable-html-styles/ReadiumCSS-before.d.ts +1 -1
- package/dist/injectable-html-styles/ReadiumCSS-default.css.map +1 -1
- package/dist/injectable-html-styles/ReadiumCSS-default.d.mts +2 -0
- package/dist/injectable-html-styles/ReadiumCSS-default.d.ts +1 -1
- package/package.json +16 -26
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
|
|
40
|
-
declare const
|
|
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
|
-
|
|
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
|
-
|
|
288
|
+
type Contributor = string | (string | ContributorObject)[] | ContributorObject;
|
|
286
289
|
|
|
287
|
-
|
|
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
|
-
|
|
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
|
-
|
|
364
|
-
|
|
365
|
-
|
|
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
|
-
|
|
377
|
+
type PdfNavigator = Navigator & {
|
|
372
378
|
zoomIn: () => Promise<void>;
|
|
373
379
|
zoomOut: () => Promise<void>;
|
|
380
|
+
rotateCounterClockwise: () => void;
|
|
374
381
|
};
|
|
375
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
401
|
-
|
|
409
|
+
type InactiveReader = null;
|
|
410
|
+
type LoadingReader = {
|
|
402
411
|
isLoading: true;
|
|
403
412
|
content: JSX.Element;
|
|
404
413
|
navigator: null;
|
|
@@ -406,28 +415,28 @@ declare type LoadingReader = {
|
|
|
406
415
|
manifest: null;
|
|
407
416
|
type: null;
|
|
408
417
|
};
|
|
409
|
-
|
|
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
|
-
|
|
426
|
+
type PDFActiveReader = CommonReader & {
|
|
415
427
|
state: ReaderState;
|
|
416
428
|
navigator: PdfNavigator;
|
|
417
429
|
type: 'PDF';
|
|
418
430
|
};
|
|
419
|
-
|
|
431
|
+
type HTMLActiveReader = CommonReader & {
|
|
420
432
|
state: ReaderState;
|
|
421
433
|
navigator: HtmlNavigator;
|
|
422
434
|
type: 'HTML';
|
|
423
435
|
};
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
headerLeft?: JSX.Element;
|
|
429
|
-
};
|
|
430
|
-
declare type UseWebReaderArguments<T extends string | Uint8Array> = {
|
|
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
442
|
getContent?: GetContent<T>;
|
|
@@ -469,24 +478,21 @@ declare type UseWebReaderArguments<T extends string | Uint8Array> = {
|
|
|
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
|
-
|
|
486
|
+
type ActiveReaderArguments<T extends string | Uint8Array> = UseWebReaderArguments<T> & {
|
|
474
487
|
manifest: WebpubManifest;
|
|
475
488
|
};
|
|
476
|
-
|
|
489
|
+
type InactiveReaderArguments = undefined;
|
|
477
490
|
|
|
478
|
-
|
|
479
|
-
* The React hook that exposes the main API into the reader. It
|
|
480
|
-
* will determine the type of the webpub, and then use the correct reader
|
|
481
|
-
* for that type.
|
|
482
|
-
*/
|
|
483
|
-
declare function useWebReader(args: UseWebReaderArguments<string | Uint8Array>): HTMLActiveReader | PDFActiveReader | LoadingReader;
|
|
484
|
-
|
|
485
|
-
declare type HtmlReaderArguments = ActiveReaderArguments<string> | InactiveReaderArguments;
|
|
491
|
+
type HtmlReaderArguments = ActiveReaderArguments<string> | InactiveReaderArguments;
|
|
486
492
|
|
|
487
493
|
declare function useHtmlReader(args: HtmlReaderArguments): ReaderReturn;
|
|
488
494
|
|
|
489
|
-
|
|
495
|
+
type PdfReaderArguments = ActiveReaderArguments<Uint8Array> | InactiveReaderArguments;
|
|
490
496
|
|
|
491
497
|
/**
|
|
492
498
|
* The PDF reader
|
|
@@ -499,7 +505,19 @@ declare type PdfReaderArguments = ActiveReaderArguments<Uint8Array> | InactiveRe
|
|
|
499
505
|
*/
|
|
500
506
|
declare function usePdfReader(args: PdfReaderArguments): ReaderReturn;
|
|
501
507
|
|
|
502
|
-
|
|
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>;
|
|
503
521
|
|
|
504
522
|
/**
|
|
505
523
|
* See Chakra default theme for shape of theme object:
|
|
@@ -512,25 +530,20 @@ declare type Dict<T = any> = Record<string, T>;
|
|
|
512
530
|
*/
|
|
513
531
|
declare function getTheme(colorMode?: ColorMode): Dict<unknown>;
|
|
514
532
|
|
|
515
|
-
declare const useColorModeValue: (light: string, dark: string, sepia: string) => string;
|
|
516
|
-
|
|
517
|
-
declare function clearWebReaderLocalStorage(): void;
|
|
518
|
-
|
|
519
533
|
/**
|
|
520
|
-
*
|
|
521
|
-
*
|
|
522
|
-
*
|
|
523
|
-
* to decide how to get the resource, for example through a proxy if necessary.
|
|
524
|
-
* @param pdfWorkerSrc - the path to the pdfjs worker file. Necessary to use pdfjs.
|
|
525
|
-
* @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.
|
|
526
537
|
*/
|
|
527
|
-
declare function
|
|
538
|
+
declare function useWebReader(args: UseWebReaderArguments<string | Uint8Array>): HTMLActiveReader | PDFActiveReader | LoadingReader;
|
|
539
|
+
|
|
540
|
+
declare function clearWebReaderLocalStorage(): void;
|
|
528
541
|
|
|
529
542
|
/**
|
|
530
543
|
* The main React component export.
|
|
531
544
|
*/
|
|
532
|
-
|
|
545
|
+
type WebReaderProps = UseWebReaderArguments<string | Uint8Array>;
|
|
533
546
|
declare const WebReaderWithoutBoundary: FC<WebReaderProps>;
|
|
534
547
|
declare const WebReader: FC<WebReaderProps>;
|
|
535
548
|
|
|
536
|
-
export { CHROME_HEIGHT, DEFAULT_HEIGHT, DEFAULT_SETTINGS, DEFAULT_SHOULD_GROW_WHEN_SCROLLING, FONT_DETAILS,
|
|
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 };
|