@nypl/web-reader 4.2.0 → 4.3.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.
@@ -1,15 +1,3 @@
1
1
  import { ReaderReturn, ReaderArguments } from '../types';
2
2
  export declare const IFRAME_ID_SELECTOR = "html-reader-iframe";
3
- /**
4
- * @TODO :
5
- *
6
- * Future:
7
- * - provide default injectables (Readium CSS)
8
- * - Find some way to organize effects and actions together so you can navigate, wait for iframe to load,
9
- * then run some other effect.
10
- * - goForward and goBackward should return a promise that resolves once isNavigated flips to true.
11
- * - Sync settings to localStorage or something similar.
12
- * - Add a way to call a callback when current reading position changes (so OE web can save current position).
13
- * - Maybe use history.pushState when navigating via nextPage or previousPage or toc.
14
- */
15
3
  export default function useHtmlReader(args: ReaderArguments): ReaderReturn;
@@ -7,11 +7,6 @@ import { ActiveState } from './types';
7
7
  * Constants
8
8
  */
9
9
  export declare const FONT_SIZE_STEP = 4;
10
- /**
11
- * If we provide injectables that are not found, the app won't load at all.
12
- * Therefore we will not provide any default injectables.
13
- * @todo - this is not true in our custom renderer. We should provide default injectables.
14
- */
15
10
  export declare const defaultInjectables: Injectable[];
16
11
  export declare const defaultInjectablesFixed: Injectable[];
17
12
  /**
@@ -1,7 +1,6 @@
1
1
  import { WebpubManifest } from '../types';
2
2
  import { HtmlState } from './types';
3
3
  /**
4
- * Set CSS variables when user state changes.
5
- * @todo - narrow down the dependencies so this doesn't run on _every_ state change.
4
+ * Set CSS variables when user state changes
6
5
  */
7
6
  export default function useUpdateCSS(state: HtmlState, manifest: WebpubManifest | undefined): void;
@@ -0,0 +1,10 @@
1
+ import { WebpubManifest } from '../types';
2
+ /**
3
+ * Adds TOC data to Webpub Manifest from single-resource PDF using PDF.js
4
+ * @param manifest
5
+ * @param getResource - a function to get the resource. This allows the caller
6
+ * to decide how to get the resource, for example through a proxy if necessary.
7
+ * @param pdfWorkerSrc - the path to the pdfjs worker file. Necessary to use pdfjs.
8
+ * @returns {WebpubManifest} manifest object
9
+ */
10
+ export default function addTocToManifest(manifest: WebpubManifest, getResource: (url: string) => Promise<Uint8Array>, pdfWorkerSrc: string): Promise<WebpubManifest>;
@@ -1,6 +1,5 @@
1
1
  import { ReaderArguments, ReaderReturn } from '../types';
2
2
  import 'react-pdf/dist/esm/Page/AnnotationLayer.css';
3
- export declare const SCALE_STEP = 0.1;
4
3
  /**
5
4
  * The PDF reader
6
5
  *
@@ -0,0 +1,26 @@
1
+ import { WebpubManifest } from '../types';
2
+ import { ReadiumLink } from '../WebpubManifestTypes/ReadiumLink';
3
+ export declare const IFRAME_WRAPPER_ID = "iframe-wrapper";
4
+ export declare const SCALE_STEP = 0.1;
5
+ export declare const START_QUERY = "start";
6
+ export declare const getResourceUrl: (index: number, readingOrder: ReadiumLink[] | undefined) => string;
7
+ export declare const loadResource: (resourceUrl: string, proxyUrl?: string | undefined) => Promise<Uint8Array>;
8
+ /**
9
+ * Gets the index of the provided href in the readingOrder, or throws an error if one
10
+ * is not found.
11
+ */
12
+ export declare function getIndexFromHref(href: string, manifest: WebpubManifest): number;
13
+ /**
14
+ * Compares two hrefs without query params or hash
15
+ */
16
+ export declare function doHrefsMatch(href1: string | URL, href2: string | URL): boolean;
17
+ /**
18
+ * Extracts a start page from a href if it exists and is in the format
19
+ * `?startPage=1`. Returns undefined if none found.
20
+ */
21
+ export declare const getStartPageFromHref: (href: string) => number | undefined;
22
+ /**
23
+ * Extracts a page number from a href if it exists and is in
24
+ * the format of `#page=1`
25
+ */
26
+ export declare const getPageNumberFromHref: (href: string) => number | undefined;
@@ -0,0 +1,3 @@
1
+ import { ReaderArguments } from '../types';
2
+ import { PdfState, PdfReaderAction } from './types';
3
+ export declare function makePdfReducer(args: ReaderArguments): (state: PdfState, action: PdfReaderAction) => PdfState;
@@ -0,0 +1,61 @@
1
+ import { ReaderArguments, ReaderSettings, ReaderState } from '../types';
2
+ export declare type InternalState = {
3
+ resourceIndex: number;
4
+ resource: {
5
+ data: Uint8Array;
6
+ } | null;
7
+ numPages: number | null;
8
+ pageNumber: number;
9
+ scale: number;
10
+ pdfHeight: number;
11
+ pdfWidth: number;
12
+ pageHeight: number | undefined;
13
+ pageWidth: number | undefined;
14
+ rendered: boolean;
15
+ };
16
+ export declare type InactiveState = ReaderState & InternalState & {
17
+ state: 'INACTIVE';
18
+ settings: undefined;
19
+ };
20
+ export declare type ActiveState = ReaderState & InternalState & {
21
+ state: 'ACTIVE';
22
+ settings: ReaderSettings;
23
+ };
24
+ export declare type PdfState = InactiveState | ActiveState;
25
+ export declare type PdfReaderAction = {
26
+ type: 'ARGS_CHANGED';
27
+ args: ReaderArguments;
28
+ } | {
29
+ type: 'GO_FORWARD';
30
+ } | {
31
+ type: 'GO_BACKWARD';
32
+ } | {
33
+ type: 'GO_TO_HREF';
34
+ href: string;
35
+ } | {
36
+ type: 'RESOURCE_FETCH_SUCCESS';
37
+ resource: {
38
+ data: Uint8Array;
39
+ };
40
+ } | {
41
+ type: 'PDF_PARSED';
42
+ numPages: number;
43
+ } | {
44
+ type: 'SET_SCALE';
45
+ scale: number;
46
+ } | {
47
+ type: 'SET_SCROLL';
48
+ isScrolling: boolean;
49
+ } | {
50
+ type: 'PAGE_LOAD_SUCCESS';
51
+ height: number;
52
+ width: number;
53
+ } | {
54
+ type: 'RESIZE_PAGE';
55
+ height: number | undefined;
56
+ width: number | undefined;
57
+ } | {
58
+ type: 'BOOK_BOUNDARY_CHANGED';
59
+ atStart: boolean;
60
+ atEnd: boolean;
61
+ };
@@ -14,3 +14,4 @@ export { getTheme } from './ui/theme';
14
14
  export { default as useColorModeValue } from './ui/hooks/useColorModeValue';
15
15
  export * from './constants';
16
16
  export { clearWebReaderLocalStorage } from './utils/localstorage';
17
+ export { default as addTocToManifest } from './PdfReader/addTocToManifest';
@@ -1,20 +1,16 @@
1
1
  import { HtmlState } from '../HtmlReader/types';
2
2
  import { Locator } from '../Readium/Locator';
3
3
  import { ReaderArguments, ReaderSettings } from '../types';
4
- /**
5
- * Use getLocalStorageLocation to get the location when
6
- * initializing the reducer. useUpdateLocalStorage will set
7
- * values in local storage as they change.
8
- *
9
- * TODO:
10
- * - PDF Sync
11
- * - how to handle non backwards compatible updates
12
- */
13
4
  export declare type LSLocation = {
14
5
  location: Locator;
15
6
  createdAt: number;
16
7
  };
17
8
  export declare type LSLocationsRecord = Record<string, LSLocation>;
9
+ /**
10
+ * Use getLocalStorageLocation to get the location when
11
+ * initializing the reducer. useUpdateLocalStorage will set
12
+ * values in local storage as they change.
13
+ */
18
14
  export declare function getLocalStorageLocation(identifier: string, args: ReaderArguments): LSLocation | undefined;
19
15
  export declare function getLocalStorageSettings(args: ReaderArguments): ReaderSettings | undefined;
20
16
  export default function useUpdateLocalStorage(identifier: string | null, state: HtmlState, args: ReaderArguments): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nypl/web-reader",
3
- "version": "4.2.0",
3
+ "version": "4.3.0",
4
4
  "license": "MIT",
5
5
  "repository": "https://github.com/NYPL-Simplified/web-reader",
6
6
  "homepage": "https://github.com/NYPL-Simplified/web-reader",
@@ -25,8 +25,6 @@
25
25
  "example:build": "parcel build",
26
26
  "example:nocache": "parcel --no-cache",
27
27
  "example": "parcel",
28
- "example:https": "parcel --cert localhost.pem --key localhost-key.pem",
29
- "example:sw": "ENABLE_SW=true npm run example:https",
30
28
  "start": "ts-node -T build.ts -w",
31
29
  "build": "ts-node -T build.ts",
32
30
  "test": "jest --watch",
@@ -42,8 +40,6 @@
42
40
  "prepare": "npm run build && husky install",
43
41
  "size": "size-limit",
44
42
  "analyze": "size-limit --why",
45
- "storybook": "start-storybook -p 6006",
46
- "build-storybook": "build-storybook",
47
43
  "cors-proxy": "node example/cors-proxy.js",
48
44
  "release": "release-it --verbose",
49
45
  "release:alpha": "release-it --verbose --preRelease=alpha"
@@ -54,7 +50,7 @@
54
50
  "@emotion/styled": "^11.8.1",
55
51
  "react": "^16.8.0 || 17.x || 18.x",
56
52
  "react-dom": "^16.8.0 || 17.x || 18.x",
57
- "swr": "^1.0.1"
53
+ "swr": "^2.0.3"
58
54
  },
59
55
  "prettier": {
60
56
  "printWidth": 80,
@@ -84,13 +80,6 @@
84
80
  "@babel/core": "^7.12.10",
85
81
  "@emotion/jest": "^11.8.0",
86
82
  "@parcel/transformer-typescript-tsc": "^2.4.1",
87
- "@storybook/addon-actions": "^6.5.13",
88
- "@storybook/addon-essentials": "^6.4.22",
89
- "@storybook/addon-info": "^3.0.0",
90
- "@storybook/addon-links": "^6.5.13",
91
- "@storybook/addon-storyshots": "^6.1.21",
92
- "@storybook/addons": "^6.5.13",
93
- "@storybook/react": "^6.1.21",
94
83
  "@testing-library/cypress": "^8.0.2",
95
84
  "@testing-library/jest-dom": "^5.16.3",
96
85
  "@testing-library/react": "^12.0.0",
File without changes