react-native-readium 1.0.4 → 1.1.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 (42) hide show
  1. package/README.md +12 -2
  2. package/lib/commonjs/components/ReadiumView.js.map +1 -1
  3. package/lib/commonjs/index.web.js +54 -0
  4. package/lib/commonjs/index.web.js.map +1 -0
  5. package/lib/commonjs/web/ReadiumView.js +90 -0
  6. package/lib/commonjs/web/ReadiumView.js.map +1 -0
  7. package/lib/commonjs/web/hooks/index.js +45 -0
  8. package/lib/commonjs/web/hooks/index.js.map +1 -0
  9. package/lib/commonjs/web/hooks/useLocationObserver.js +21 -0
  10. package/lib/commonjs/web/hooks/useLocationObserver.js.map +1 -0
  11. package/lib/commonjs/web/hooks/useReaderRef.js +60 -0
  12. package/lib/commonjs/web/hooks/useReaderRef.js.map +1 -0
  13. package/lib/commonjs/web/hooks/useSettingsObserver.js +21 -0
  14. package/lib/commonjs/web/hooks/useSettingsObserver.js.map +1 -0
  15. package/lib/module/components/ReadiumView.js.map +1 -1
  16. package/lib/module/index.web.js +5 -0
  17. package/lib/module/index.web.js.map +1 -0
  18. package/lib/module/web/ReadiumView.js +75 -0
  19. package/lib/module/web/ReadiumView.js.map +1 -0
  20. package/lib/module/web/hooks/index.js +4 -0
  21. package/lib/module/web/hooks/index.js.map +1 -0
  22. package/lib/module/web/hooks/useLocationObserver.js +11 -0
  23. package/lib/module/web/hooks/useLocationObserver.js.map +1 -0
  24. package/lib/module/web/hooks/useReaderRef.js +47 -0
  25. package/lib/module/web/hooks/useReaderRef.js.map +1 -0
  26. package/lib/module/web/hooks/useSettingsObserver.js +11 -0
  27. package/lib/module/web/hooks/useSettingsObserver.js.map +1 -0
  28. package/lib/typescript/components/ReadiumView.d.ts +1 -2
  29. package/lib/typescript/index.web.d.ts +4 -0
  30. package/lib/typescript/web/ReadiumView.d.ts +3 -0
  31. package/lib/typescript/web/hooks/index.d.ts +3 -0
  32. package/lib/typescript/web/hooks/useLocationObserver.d.ts +3 -0
  33. package/lib/typescript/web/hooks/useReaderRef.d.ts +4 -0
  34. package/lib/typescript/web/hooks/useSettingsObserver.d.ts +3 -0
  35. package/package.json +9 -6
  36. package/src/components/ReadiumView.tsx +2 -2
  37. package/src/index.web.tsx +5 -0
  38. package/src/web/ReadiumView.tsx +75 -0
  39. package/src/web/hooks/index.ts +3 -0
  40. package/src/web/hooks/useLocationObserver.ts +21 -0
  41. package/src/web/hooks/useReaderRef.ts +56 -0
  42. package/src/web/hooks/useSettingsObserver.ts +21 -0
package/README.md CHANGED
@@ -154,15 +154,25 @@ DRM is not supported at this time. However, there is a clear path to [support it
154
154
  | Name | Type | Optional | Description |
155
155
  |------|------|----------|-------------|
156
156
  | `file` | [`File`](https://github.com/5-stones/react-native-readium/blob/main/src/interfaces/File.ts) | :x: | A file object containing the path to the eBook file on disk. |
157
- | `location` | [`Locator`](https://github.com/5-stones/react-native-readium/blob/main/src/interfaces/Locator.ts) | [`Link`](https://github.com/5-stones/react-native-readium/blob/main/src/interfaces/Link.ts) | :white_check_mark: | A locator prop that allows you to externally control the location of the reader (e.g. Chapters or Bookmarks)|
157
+ | `location` | [`Locator`](https://github.com/5-stones/react-native-readium/blob/main/src/interfaces/Locator.ts) \| [`Link`](https://github.com/5-stones/react-native-readium/blob/main/src/interfaces/Link.ts) | :white_check_mark: | A locator prop that allows you to externally control the location of the reader (e.g. Chapters or Bookmarks). <br/><br/>:warning: If you want to set the `location` of an ebook on initial load, you should use the `File.initialLocation` property (look at the `file` prop). See more [here](https://github.com/5-stones/react-native-readium/issues/16#issuecomment-1344128937) |
158
158
  | `settings` | [`Partial<Settings>`](https://github.com/5-stones/react-native-readium/blob/main/src/interfaces/Settings.ts) | :white_check_mark: | An object that allows you to control various aspects of the reader's UI (epub only) |
159
159
  | `style` | `ViewStyle` | :white_check_mark: | A traditional style object. |
160
160
  | `onLocationChange` | `(locator: Locator) => void` | :white_check_mark: | A callback that fires whenever the location is changed (e.g. the user transitions to a new page)|
161
161
  | `onTableOfContents` | `(toc: Link[] \| null) => void` | :white_check_mark: | A callback that fires once the file is parsed and emits the table of contents embedded in the file. Returns `null` or an empty `[]` if no TOC exists. See the [`Link`](https://github.com/5-stones/react-native-readium/blob/main/src/interfaces/Link.ts) interface for more info. |
162
162
 
163
+ #### :warning: Web vs Native File URLs
164
+
165
+ Please note that on `web` the `File.url` should be a web accessible URL path to
166
+ the `manifest.json` of the unpacked epub. In native contexts it needs to be a
167
+ local filepath to the epub file itself on disk. If you're not sure how to
168
+ serve epub books [take a look at this example](https://github.com/d-i-t-a/R2D2BC/blob/production/examples/server.ts)
169
+ which is based on the `dita-streamer-js` project (which is built on all the
170
+ readium [r2-*-js](https://github.com/readium?q=js) libraries)
171
+
163
172
  ## Contributing
164
173
 
165
- See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
174
+ See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the
175
+ repository and the development workflow.
166
176
 
167
177
  ## Release
168
178
 
@@ -1 +1 @@
1
- {"version":3,"sources":["ReadiumView.tsx"],"names":["ReadiumView","onLocationChange","wrappedOnLocationChange","onTableOfContents","wrappedOnTableOfContents","settings","unmappedSettings","props","ref","height","width","setDimensions","onLayout","nativeEvent","layout","event","toc","Platform","OS","viewId","current","styles","container","Settings","map","undefined","StyleSheet","create"],"mappings":";;;;;;;AAAA;;AACA;;AAGA;;AACA;;AAEA;;;;;;;;AAIO,MAAMA,WAAmC,GAAG,QAK7C;AAAA,MAL8C;AAClDC,IAAAA,gBAAgB,EAAEC,uBADgC;AAElDC,IAAAA,iBAAiB,EAAEC,wBAF+B;AAGlDC,IAAAA,QAAQ,EAAEC,gBAHwC;AAIlD,OAAGC;AAJ+C,GAK9C;AACJ,QAAMC,GAAG,GAAG,mBAAO,IAAP,CAAZ;AACA,QAAM,CAAC;AAAEC,IAAAA,MAAF;AAAUC,IAAAA;AAAV,GAAD,EAAoBC,aAApB,IAAqC,qBAAqB;AAC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,IAAA,gBAAgB,EAAEN,gBAJpB;AAKE,IAAA,iBAAiB,EAAEE,iBALrB;AAME,IAAA,QAAQ,EAAEG,gBAAgB,GAAGiB,qBAASC,GAAT,CAAalB,gBAAb,CAAH,GAAoCmB,SANhE;AAOE,IAAA,GAAG,EAAEjB;AAPP,KAJF,CADF;AAgBD,CAvDM;;;;AAyDP,MAAMa,MAAM,GAAGK,wBAAWC,MAAX,CAAkB;AAC/BL,EAAAA,SAAS,EAAE;AAAEZ,IAAAA,KAAK,EAAE,MAAT;AAAiBD,IAAAA,MAAM,EAAE;AAAzB;AADoB,CAAlB,CAAf","sourcesContent":["import React, { useCallback, useState, useRef, useEffect } from 'react';\nimport { View, Platform, findNodeHandle, StyleSheet } from 'react-native';\n\nimport type { Dimensions } from '../interfaces';\nimport { Settings } from '../interfaces';\nimport { createFragment, getWidthOrHeightValue as dimension } from '../utils';\nimport type { BaseReadiumViewProps } from './BaseReadiumView';\nimport { BaseReadiumView } from './BaseReadiumView';\n\ntype ReadiumProps = BaseReadiumViewProps;\n\nexport const ReadiumView: React.FC<ReadiumProps> = ({\n onLocationChange: wrappedOnLocationChange,\n onTableOfContents: wrappedOnTableOfContents,\n settings: unmappedSettings,\n ...props\n}) => {\n const ref = useRef(null);\n const [{ height, width }, setDimensions] = useState<Dimensions>({\n width: 0,\n height: 0,\n });\n // set the view dimensions on layout\n const onLayout = useCallback(({ nativeEvent: { layout: { width, height } }}) => {\n setDimensions({\n width: dimension(width),\n height: dimension(height),\n });\n }, []);\n // wrap the native onLocationChange and extract the raw event value\n const onLocationChange = useCallback((event: any) => {\n if (wrappedOnLocationChange) {\n wrappedOnLocationChange(event.nativeEvent);\n }\n }, [wrappedOnLocationChange]);\n\n const onTableOfContents = useCallback((event: any) => {\n if (wrappedOnTableOfContents) {\n const toc = event.nativeEvent.toc || null;\n wrappedOnTableOfContents(toc);\n }\n }, [wrappedOnTableOfContents]);\n\n useEffect(() => {\n if (Platform.OS === 'android') {\n const viewId = findNodeHandle(ref.current);\n createFragment(viewId);\n }\n }, [])\n\n return (\n <View\n style={styles.container}\n onLayout={onLayout}\n >\n <BaseReadiumView\n height={height}\n width={width}\n {...props}\n onLocationChange={onLocationChange}\n onTableOfContents={onTableOfContents}\n settings={unmappedSettings ? Settings.map(unmappedSettings) : undefined}\n ref={ref}\n />\n </View>\n );\n};\n\nconst styles = StyleSheet.create({\n container: { width: '100%', height: '100%' },\n});\n"]}
1
+ {"version":3,"sources":["ReadiumView.tsx"],"names":["ReadiumView","onLocationChange","wrappedOnLocationChange","onTableOfContents","wrappedOnTableOfContents","settings","unmappedSettings","props","ref","height","width","setDimensions","onLayout","nativeEvent","layout","event","toc","Platform","OS","viewId","current","styles","container","Settings","map","undefined","StyleSheet","create"],"mappings":";;;;;;;AAAA;;AACA;;AAGA;;AACA;;AAEA;;;;;;;;AAIO,MAAMA,WAAmC,GAAG,QAK7C;AAAA,MAL8C;AAClDC,IAAAA,gBAAgB,EAAEC,uBADgC;AAElDC,IAAAA,iBAAiB,EAAEC,wBAF+B;AAGlDC,IAAAA,QAAQ,EAAEC,gBAHwC;AAIlD,OAAGC;AAJ+C,GAK9C;AACJ,QAAMC,GAAG,GAAG,mBAAO,IAAP,CAAZ;AACA,QAAM,CAAC;AAAEC,IAAAA,MAAF;AAAUC,IAAAA;AAAV,GAAD,EAAoBC,aAApB,IAAqC,qBAAqB;AAC9DD,IAAAA,KAAK,EAAE,CADuD;AAE9DD,IAAAA,MAAM,EAAE;AAFsD,GAArB,CAA3C,CAFI,CAMJ;;AACA,QAAMG,QAAQ,GAAG,wBAAY,SAAwD;AAAA,QAAvD;AAAEC,MAAAA,WAAW,EAAE;AAAEC,QAAAA,MAAM,EAAE;AAAEJ,UAAAA,KAAF;AAASD,UAAAA;AAAT;AAAV;AAAf,KAAuD;AACnFE,IAAAA,aAAa,CAAC;AACZD,MAAAA,KAAK,EAAE,kCAAUA,KAAV,CADK;AAEZD,MAAAA,MAAM,EAAE,kCAAUA,MAAV;AAFI,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CAAf","sourcesContent":["import React, { useCallback, useState, useRef, useEffect } from 'react';\nimport { View, Platform, findNodeHandle, StyleSheet } from 'react-native';\n\nimport type { Dimensions } from '../interfaces';\nimport { Settings } from '../interfaces';\nimport { createFragment, getWidthOrHeightValue as dimension } from '../utils';\nimport type { BaseReadiumViewProps } from './BaseReadiumView';\nimport { BaseReadiumView } from './BaseReadiumView';\n\nexport type ReadiumProps = BaseReadiumViewProps;\n\nexport const ReadiumView: React.FC<ReadiumProps> = ({\n onLocationChange: wrappedOnLocationChange,\n onTableOfContents: wrappedOnTableOfContents,\n settings: unmappedSettings,\n ...props\n}) => {\n const ref = useRef(null);\n const [{ height, width }, setDimensions] = useState<Dimensions>({\n width: 0,\n height: 0,\n });\n // set the view dimensions on layout\n const onLayout = useCallback(({ nativeEvent: { layout: { width, height } }}: any) => {\n setDimensions({\n width: dimension(width),\n height: dimension(height),\n });\n }, []);\n // wrap the native onLocationChange and extract the raw event value\n const onLocationChange = useCallback((event: any) => {\n if (wrappedOnLocationChange) {\n wrappedOnLocationChange(event.nativeEvent);\n }\n }, [wrappedOnLocationChange]);\n\n const onTableOfContents = useCallback((event: any) => {\n if (wrappedOnTableOfContents) {\n const toc = event.nativeEvent.toc || null;\n wrappedOnTableOfContents(toc);\n }\n }, [wrappedOnTableOfContents]);\n\n useEffect(() => {\n if (Platform.OS === 'android') {\n const viewId = findNodeHandle(ref.current);\n createFragment(viewId);\n }\n }, [])\n\n return (\n <View\n style={styles.container}\n onLayout={onLayout}\n >\n <BaseReadiumView\n height={height}\n width={width}\n {...props}\n onLocationChange={onLocationChange}\n onTableOfContents={onTableOfContents}\n settings={unmappedSettings ? Settings.map(unmappedSettings) : undefined}\n ref={ref}\n />\n </View>\n );\n};\n\nconst styles = StyleSheet.create({\n container: { width: '100%', height: '100%' },\n});\n"]}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ RANGES: true,
8
+ ReadiumView: true
9
+ };
10
+ Object.defineProperty(exports, "RANGES", {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _utils.RANGES;
14
+ }
15
+ });
16
+ Object.defineProperty(exports, "ReadiumView", {
17
+ enumerable: true,
18
+ get: function () {
19
+ return _ReadiumView.ReadiumView;
20
+ }
21
+ });
22
+
23
+ var _enums = require("./enums");
24
+
25
+ Object.keys(_enums).forEach(function (key) {
26
+ if (key === "default" || key === "__esModule") return;
27
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
28
+ if (key in exports && exports[key] === _enums[key]) return;
29
+ Object.defineProperty(exports, key, {
30
+ enumerable: true,
31
+ get: function () {
32
+ return _enums[key];
33
+ }
34
+ });
35
+ });
36
+
37
+ var _interfaces = require("./interfaces");
38
+
39
+ Object.keys(_interfaces).forEach(function (key) {
40
+ if (key === "default" || key === "__esModule") return;
41
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
42
+ if (key in exports && exports[key] === _interfaces[key]) return;
43
+ Object.defineProperty(exports, key, {
44
+ enumerable: true,
45
+ get: function () {
46
+ return _interfaces[key];
47
+ }
48
+ });
49
+ });
50
+
51
+ var _utils = require("./utils");
52
+
53
+ var _ReadiumView = require("./web/ReadiumView");
54
+ //# sourceMappingURL=index.web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.web.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAEA","sourcesContent":["export * from './enums';\nexport * from './interfaces';\nexport { RANGES } from './utils';\n\nexport { ReadiumView } from './web/ReadiumView';\n"]}
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ReadiumView = void 0;
7
+
8
+ var _react = _interopRequireDefault(require("react"));
9
+
10
+ var _reactNative = require("react-native");
11
+
12
+ var _hooks = require("./hooks");
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ const ReadiumView = _ref => {
17
+ let {
18
+ file,
19
+ settings,
20
+ location,
21
+ onLocationChange,
22
+ onTableOfContents
23
+ } = _ref;
24
+ const readerRef = (0, _hooks.useReaderRef)({
25
+ file,
26
+ onLocationChange,
27
+ onTableOfContents
28
+ });
29
+ const reader = readerRef.current;
30
+ (0, _hooks.useSettingsObserver)(reader, settings);
31
+ (0, _hooks.useLocationObserver)(reader, location);
32
+ return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
33
+ style: styles.container
34
+ }, !reader && /*#__PURE__*/_react.default.createElement("div", {
35
+ style: styles.loader
36
+ }, "Loading reader..."), /*#__PURE__*/_react.default.createElement("div", {
37
+ id: "D2Reader-Container",
38
+ style: styles.d2Container
39
+ }, reader && /*#__PURE__*/_react.default.createElement("button", {
40
+ onClick: reader.previousPage,
41
+ style: styles.button
42
+ }, "\u2039"), /*#__PURE__*/_react.default.createElement("main", {
43
+ style: styles.maximize,
44
+ tabIndex: -1,
45
+ id: "iframe-wrapper"
46
+ }, /*#__PURE__*/_react.default.createElement("div", {
47
+ id: "reader-loading",
48
+ className: "loading",
49
+ style: styles.loader
50
+ }), /*#__PURE__*/_react.default.createElement("div", {
51
+ id: "reader-error",
52
+ className: "error"
53
+ })), reader && /*#__PURE__*/_react.default.createElement("button", {
54
+ onClick: reader.nextPage,
55
+ style: styles.button
56
+ }, "\u203A")));
57
+ };
58
+
59
+ exports.ReadiumView = ReadiumView;
60
+
61
+ const styles = _reactNative.StyleSheet.create({
62
+ container: {
63
+ width: '100%',
64
+ height: '100%'
65
+ },
66
+ d2Container: {
67
+ width: '100%',
68
+ height: '100%',
69
+ display: 'flex'
70
+ },
71
+ maximize: {
72
+ width: 'calc(100% - 100px)',
73
+ height: '100%',
74
+ display: 'flex'
75
+ },
76
+ button: {
77
+ width: 50,
78
+ fontSize: 100,
79
+ backgroundColor: 'transparent',
80
+ border: 'none'
81
+ },
82
+ loader: {
83
+ width: '100%',
84
+ height: '100%',
85
+ textAlign: 'center',
86
+ position: 'relative',
87
+ top: 'calc(50% - 10px)'
88
+ }
89
+ });
90
+ //# sourceMappingURL=ReadiumView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["ReadiumView.tsx"],"names":["ReadiumView","file","settings","location","onLocationChange","onTableOfContents","readerRef","reader","current","styles","container","loader","d2Container","previousPage","button","maximize","nextPage","StyleSheet","create","width","height","display","fontSize","backgroundColor","border","textAlign","position","top"],"mappings":";;;;;;;AAAA;;AACA;;AAGA;;;;AAMO,MAAMA,WAAmC,GAAG,QAM7C;AAAA,MAN8C;AAClDC,IAAAA,IADkD;AAElDC,IAAAA,QAFkD;AAGlDC,IAAAA,QAHkD;AAIlDC,IAAAA,gBAJkD;AAKlDC,IAAAA;AALkD,GAM9C;AACJ,QAAMC,SAAS,GAAG,yBAAa;AAC7BL,IAAAA,IAD6B;AAE7BG,IAAAA,gBAF6B;AAG7BC,IAAAA;AAH6B,GAAb,CAAlB;AAKA,QAAME,MAAM,GAAGD,SAAS,CAACE,OAAzB;AAEA,kCAAoBD,MAApB,EAA4BL,QAA5B;AACA,kCAAoBK,MAApB,EAA4BJ,QAA5B;AAEA,sBACE,6BAAC,iBAAD;AAAM,IAAA,KAAK,EAAEM,MAAM,CAACC;AAApB,KACG,CAACH,MAAD,iBAAW;AAAK,IAAA,KAAK,EAAEE,MAAM,CAACE;AAAnB,yBADd,eAEE;AAAK,IAAA,EAAE,EAAC,oBAAR;AAA6B,IAAA,KAAK,EAAEF,MAAM,CAACG;AAA3C,KACGL,MAAM,iBAAI;AAAQ,IAAA,OAAO,EAAEA,MAAM,CAACM,YAAxB;AAAsC,IAAA,KAAK,EAAEJ,MAAM,CAACK;AAApD,cADb,eAEE;AACE,IAAA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":["import React from 'react';\nimport { View, StyleSheet } from 'react-native';\n\nimport type { ReadiumProps } from '../components/ReadiumView';\nimport {\n useReaderRef,\n useSettingsObserver,\n useLocationObserver,\n} from './hooks';\n\nexport const ReadiumView: React.FC<ReadiumProps> = ({\n file,\n settings,\n location,\n onLocationChange,\n onTableOfContents,\n}) => {\n const readerRef = useReaderRef({\n file,\n onLocationChange,\n onTableOfContents,\n });\n const reader = readerRef.current;\n\n useSettingsObserver(reader, settings);\n useLocationObserver(reader, location);\n\n return (\n <View style={styles.container}>\n {!reader && <div style={styles.loader}>Loading reader...</div>}\n <div id=\"D2Reader-Container\" style={styles.d2Container}>\n {reader && <button onClick={reader.previousPage} style={styles.button}>&lsaquo;</button>}\n <main\n style={styles.maximize}\n tabIndex={-1}\n id=\"iframe-wrapper\"\n >\n <div id=\"reader-loading\" className=\"loading\" style={styles.loader}></div>\n <div id=\"reader-error\" className=\"error\"></div>\n </main>\n {reader && <button onClick={reader.nextPage} style={styles.button}>&rsaquo;</button>}\n </div>\n </View>\n );\n};\n\nconst styles = StyleSheet.create({\n container: {\n width: '100%',\n height: '100%',\n },\n d2Container: {\n width: '100%',\n height: '100%',\n display: 'flex',\n },\n maximize: {\n width: 'calc(100% - 100px)',\n height: '100%',\n display: 'flex',\n },\n button: {\n width: 50,\n fontSize: 100,\n backgroundColor: 'transparent',\n border: 'none',\n },\n loader: {\n width: '100%',\n height: '100%',\n textAlign: 'center',\n position: 'relative',\n top: 'calc(50% - 10px)',\n },\n});\n"]}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _useReaderRef = require("./useReaderRef");
8
+
9
+ Object.keys(_useReaderRef).forEach(function (key) {
10
+ if (key === "default" || key === "__esModule") return;
11
+ if (key in exports && exports[key] === _useReaderRef[key]) return;
12
+ Object.defineProperty(exports, key, {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _useReaderRef[key];
16
+ }
17
+ });
18
+ });
19
+
20
+ var _useSettingsObserver = require("./useSettingsObserver");
21
+
22
+ Object.keys(_useSettingsObserver).forEach(function (key) {
23
+ if (key === "default" || key === "__esModule") return;
24
+ if (key in exports && exports[key] === _useSettingsObserver[key]) return;
25
+ Object.defineProperty(exports, key, {
26
+ enumerable: true,
27
+ get: function () {
28
+ return _useSettingsObserver[key];
29
+ }
30
+ });
31
+ });
32
+
33
+ var _useLocationObserver = require("./useLocationObserver");
34
+
35
+ Object.keys(_useLocationObserver).forEach(function (key) {
36
+ if (key === "default" || key === "__esModule") return;
37
+ if (key in exports && exports[key] === _useLocationObserver[key]) return;
38
+ Object.defineProperty(exports, key, {
39
+ enumerable: true,
40
+ get: function () {
41
+ return _useLocationObserver[key];
42
+ }
43
+ });
44
+ });
45
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './useReaderRef';\nexport * from './useSettingsObserver';\nexport * from './useLocationObserver';\n"]}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useLocationObserver = void 0;
7
+
8
+ var _useDeepCompare = require("use-deep-compare");
9
+
10
+ const useLocationObserver = (reader, location) => {
11
+ (0, _useDeepCompare.useDeepCompareEffect)(() => {
12
+ if (reader && location) {
13
+ // NOTE: technically this is a Link | Locator. However, under the hood the
14
+ // R2D2BC is converting Links to locators, so just force the type here.
15
+ reader.goTo(location);
16
+ }
17
+ }, [location, !!reader]);
18
+ };
19
+
20
+ exports.useLocationObserver = useLocationObserver;
21
+ //# sourceMappingURL=useLocationObserver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useLocationObserver.ts"],"names":["useLocationObserver","reader","location","goTo"],"mappings":";;;;;;;AAAA;;AAMO,MAAMA,mBAAmB,GAAG,CACjCC,MADiC,EAEjCC,QAFiC,KAG9B;AACH,4CAAqB,MAAM;AACzB,QAAID,MAAM,IAAIC,QAAd,EAAwB;AACtB;AACA;AACAD,MAAAA,MAAM,CAACE,IAAP,CAAYD,QAAZ;AACD;AACF,GAND,EAMG,CACDA,QADC,EAED,CAAC,CAACD,MAFD,CANH;AAUD,CAdM","sourcesContent":["import { useDeepCompareEffect } from 'use-deep-compare';\nimport type D2Reader from '@d-i-t-a/reader';\nimport type { Locator as R2Locator } from '@d-i-t-a/reader';\n\nimport type { Link, Locator } from '../../interfaces';\n\nexport const useLocationObserver = (\n reader?: D2Reader | null,\n location?: Link | Locator | null,\n) => {\n useDeepCompareEffect(() => {\n if (reader && location) {\n // NOTE: technically this is a Link | Locator. However, under the hood the\n // R2D2BC is converting Links to locators, so just force the type here.\n reader.goTo(location as R2Locator);\n }\n }, [\n location,\n !!reader,\n ]);\n};\n"]}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useReaderRef = void 0;
7
+
8
+ var _react = require("react");
9
+
10
+ var _reader = _interopRequireDefault(require("@d-i-t-a/reader"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ const useReaderRef = _ref => {
15
+ let {
16
+ file,
17
+ onLocationChange,
18
+ onTableOfContents
19
+ } = _ref;
20
+ const readerRef = (0, _react.useRef)(null);
21
+ (0, _react.useEffect)(() => {
22
+ _reader.default.load({
23
+ url: new URL(file.url),
24
+ lastReadingPosition: file.initialLocation,
25
+ api: {
26
+ updateCurrentLocation: async location => {
27
+ if (onLocationChange) onLocationChange(location);
28
+ return location;
29
+ }
30
+ },
31
+ injectables: injectables
32
+ }).then(r => {
33
+ if (onTableOfContents) {
34
+ onTableOfContents(r.tableOfContents);
35
+ }
36
+
37
+ readerRef.current = r;
38
+ });
39
+ }, []);
40
+ return readerRef;
41
+ }; // NOTE: right now we're serving these through statically.io, which is just
42
+ // pulling them from Github... Might not be the best way and maybe we should
43
+ // consider bundling them with the library.
44
+
45
+
46
+ exports.useReaderRef = useReaderRef;
47
+ const injectables = [{
48
+ type: "style",
49
+ url: "https://cdn.statically.io/gh/d-i-t-a/R2D2BC/production/viewer/readium-css/ReadiumCSS-before.css",
50
+ r2before: true
51
+ }, {
52
+ type: "style",
53
+ url: "https://cdn.statically.io/gh/d-i-t-a/R2D2BC/production/viewer/readium-css/ReadiumCSS-default.css",
54
+ r2default: true
55
+ }, {
56
+ type: "style",
57
+ url: "https://cdn.statically.io/gh/d-i-t-a/R2D2BC/production/viewer/readium-css/ReadiumCSS-after.css",
58
+ r2after: true
59
+ }];
60
+ //# sourceMappingURL=useReaderRef.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useReaderRef.ts"],"names":["useReaderRef","file","onLocationChange","onTableOfContents","readerRef","D2Reader","load","url","URL","lastReadingPosition","initialLocation","api","updateCurrentLocation","location","injectables","then","r","tableOfContents","current","type","r2before","r2default","r2after"],"mappings":";;;;;;;AAAA;;AACA;;;;AAKO,MAAMA,YAAY,GAAG,QAIkD;AAAA,MAJjD;AAC3BC,IAAAA,IAD2B;AAE3BC,IAAAA,gBAF2B;AAG3BC,IAAAA;AAH2B,GAIiD;AAC5E,QAAMC,SAAS,GAAG,mBAAwB,IAAxB,CAAlB;AAEA,wBAAU,MAAM;AACdC,oBAASC,IAAT,CAAc;AACZC,MAAAA,GAAG,EAAE,IAAIC,GAAJ,CAAQP,IAAI,CAACM,GAAb,CADO;AAEZE,MAAAA,mBAAmB,EAAER,IAAI,CAACS,eAFd;AAGZC,MAAAA,GAAG,EAAE;AACHC,QAAAA,qBAAqB,EAAE,MAAOC,QAAP,IAA6B;AAClD,cAAIX,gBAAJ,EAAsBA,gBAAgB,CAACW,QAAD,CAAhB;AACtB,iBAAOA,QAAP;AACD;AAJE,OAHO;AASZC,MAAAA,WAAW,EAAEA;AATD,KAAd,EAUGC,IAVH,CAUSC,CAAD,IAAO;AACb,UAAIb,iBAAJ,EAAuB;AACrBA,QAAAA,iBAAiB,CAACa,CAAC,CAACC,eAAH,CAAjB;AACD;;AACDb,MAAAA,SAAS,CAACc,OAAV,GAAoBF,CAApB;AACD,KAfD;AAgBD,GAjBD,EAiBG,EAjBH;AAmBA,SAAOZ,SAAP;AACD,CA3BM,C,CA6BP;AACA;AACA;;;;AACA,MAAMU,WAAkB,GAAG,CACzB;AACEK,EAAAA,IAAI,EAAE,OADR;AAEEZ,EAAAA,GAAG,EAAE,iGAFP;AAGEa,EAAAA,QAAQ,EAAE;AAHZ,CADyB,EAMzB;AACED,EAAAA,IAAI,EAAE,OADR;AAEEZ,EAAAA,GAAG,EAAE,kGAFP;AAGEc,EAAAA,SAAS,EAAE;AAHb,CANyB,EAWzB;AACEF,EAAAA,IAAI,EAAE,OADR;AAEEZ,EAAAA,GAAG,EAAE,gGAFP;AAGEe,EAAAA,OAAO,EAAE;AAHX,CAXyB,CAA3B","sourcesContent":["import { useEffect, useRef } from 'react';\nimport D2Reader from '@d-i-t-a/reader';\n\nimport type { ReadiumProps } from '../../components/ReadiumView';\nimport type { Locator } from '../../interfaces';\n\nexport const useReaderRef = ({\n file,\n onLocationChange,\n onTableOfContents,\n}: Pick<ReadiumProps, 'file' | 'onLocationChange' | 'onTableOfContents' >) => {\n const readerRef = useRef<D2Reader | null>(null);\n\n useEffect(() => {\n D2Reader.load({\n url: new URL(file.url),\n lastReadingPosition: file.initialLocation,\n api: {\n updateCurrentLocation: async (location: Locator) => {\n if (onLocationChange) onLocationChange(location);\n return location;\n },\n },\n injectables: injectables,\n }).then((r) => {\n if (onTableOfContents) {\n onTableOfContents(r.tableOfContents);\n }\n readerRef.current = r;\n });\n }, []);\n\n return readerRef\n};\n\n// NOTE: right now we're serving these through statically.io, which is just\n// pulling them from Github... Might not be the best way and maybe we should\n// consider bundling them with the library.\nconst injectables: any[] = [\n {\n type: \"style\",\n url: \"https://cdn.statically.io/gh/d-i-t-a/R2D2BC/production/viewer/readium-css/ReadiumCSS-before.css\",\n r2before: true,\n },\n {\n type: \"style\",\n url: \"https://cdn.statically.io/gh/d-i-t-a/R2D2BC/production/viewer/readium-css/ReadiumCSS-default.css\",\n r2default: true,\n },\n {\n type: \"style\",\n url: \"https://cdn.statically.io/gh/d-i-t-a/R2D2BC/production/viewer/readium-css/ReadiumCSS-after.css\",\n r2after: true,\n },\n];\n\n"]}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useSettingsObserver = void 0;
7
+
8
+ var _useDeepCompare = require("use-deep-compare");
9
+
10
+ const useSettingsObserver = (reader, settings) => {
11
+ (0, _useDeepCompare.useDeepCompareEffect)(() => {
12
+ if (reader && settings) {
13
+ // @ts-ignore - FIXME need to do some deeper investigation if these
14
+ // are equivalent or not
15
+ reader === null || reader === void 0 ? void 0 : reader.applyUserSettings(settings);
16
+ }
17
+ }, [settings, !!reader]);
18
+ };
19
+
20
+ exports.useSettingsObserver = useSettingsObserver;
21
+ //# sourceMappingURL=useSettingsObserver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useSettingsObserver.ts"],"names":["useSettingsObserver","reader","settings","applyUserSettings"],"mappings":";;;;;;;AAAA;;AAMO,MAAMA,mBAAmB,GAAG,CACjCC,MADiC,EAEjCC,QAFiC,KAG9B;AACH,4CAAqB,MAAM;AACzB,QAAID,MAAM,IAAIC,QAAd,EAAwB;AACtB;AACA;AACAD,MAAAA,MAAM,SAAN,IAAAA,MAAM,WAAN,YAAAA,MAAM,CAAEE,iBAAR,CAA0BD,QAA1B;AACD;AACF,GAND,EAMG,CACDA,QADC,EAED,CAAC,CAACD,MAFD,CANH;AAUD,CAdM","sourcesContent":["import { useDeepCompareEffect } from 'use-deep-compare';\nimport type D2Reader from '@d-i-t-a/reader';\nimport type { UserSettings } from '@d-i-t-a/reader/dist/types/model/user-settings/UserSettings';\n\nimport type { Settings } from '../../interfaces';\n\nexport const useSettingsObserver = (\n reader?: D2Reader | null,\n settings?: Partial<Settings> | null,\n) => {\n useDeepCompareEffect(() => {\n if (reader && settings) {\n // @ts-ignore - FIXME need to do some deeper investigation if these\n // are equivalent or not\n reader?.applyUserSettings(settings as Partial<UserSettings>);\n }\n }, [\n settings,\n !!reader,\n ]);\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["ReadiumView.tsx"],"names":["React","useCallback","useState","useRef","useEffect","View","Platform","findNodeHandle","StyleSheet","Settings","createFragment","getWidthOrHeightValue","dimension","BaseReadiumView","ReadiumView","onLocationChange","wrappedOnLocationChange","onTableOfContents","wrappedOnTableOfContents","settings","unmappedSettings","props","ref","height","width","setDimensions","onLayout","nativeEvent","layout","event","toc","OS","viewId","current","styles","container","map","undefined","create"],"mappings":";;AAAA,OAAOA,KAAP,IAAgBC,WAAhB,EAA6BC,QAA7B,EAAuCC,MAAvC,EAA+CC,SAA/C,QAAgE,OAAhE;AACA,SAASC,IAAT,EAAeC,QAAf,EAAyBC,cAAzB,EAAyCC,UAAzC,QAA2D,cAA3D;AAGA,SAASC,QAAT,QAAyB,eAAzB;AACA,SAASC,cAAT,EAAyBC,qBAAqB,IAAIC,SAAlD,QAAmE,UAAnE;AAEA,SAASC,eAAT,QAAgC,mBAAhC;AAIA,OAAO,MAAMC,WAAmC,GAAG,QAK7C;AAAA,MAL8C;AAClDC,IAAAA,gBAAgB,EAAEC,uBADgC;AAElDC,IAAAA,iBAAiB,EAAEC,wBAF+B;AAGlDC,IAAAA,QAAQ,EAAEC,gBAHwC;AAIlD,OAAGC;AAJ+C,GAK9C;AACJ,QAAMC,GAAG,GAAGnB,MAAM,CAAC,IAAD,CAAlB;AACA,QAAM,CAAC;A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IAAD;AACE,IAAA,KAAK,EAAEE,MAAM,CAACC,SADhB;AAEE,IAAA,QAAQ,EAAET;AAFZ,kBAIE,oBAAC,eAAD;AACE,IAAA,MAAM,EAAEH,MADV;AAEE,IAAA,KAAK,EAAEC;AAFT,KAGMH,KAHN;AAIE,IAAA,gBAAgB,EAAEN,gBAJpB;AAKE,IAAA,iBAAiB,EAAEE,iBALrB;AAME,IAAA,QAAQ,EAAEG,gBAAgB,GAAGX,QAAQ,CAAC2B,GAAT,CAAahB,gBAAb,CAAH,GAAoCiB,SANhE;AAOE,IAAA,GAAG,EAAEf;AAPP,KAJF,CADF;AAgBD,CAvDM;AAyDP,MAAMY,MAAM,GAAG1B,UAAU,CAAC8B,MAAX,CAAkB;AAC/BH,EAAAA,SAAS,EAAE;AAAEX,IAAAA,KAAK,EAAE,MAAT;AAAiBD,IAAAA,MAAM,EAAE;AAAzB;AADoB,CAAlB,CAAf","sourcesContent":["import React, { useCallback, useState, useRef, useEffect } from 'react';\nimport { View, Platform, findNodeHandle, StyleSheet } from 'react-native';\n\nimport type { Dimensions } from '../interfaces';\nimport { Settings } from '../interfaces';\nimport { createFragment, getWidthOrHeightValue as dimension } from '../utils';\nimport type { BaseReadiumViewProps } from './BaseReadiumView';\nimport { BaseReadiumView } from './BaseReadiumView';\n\ntype ReadiumProps = BaseReadiumViewProps;\n\nexport const ReadiumView: React.FC<ReadiumProps> = ({\n onLocationChange: wrappedOnLocationChange,\n onTableOfContents: wrappedOnTableOfContents,\n settings: unmappedSettings,\n ...props\n}) => {\n const ref = useRef(null);\n const [{ height, width }, setDimensions] = useState<Dimensions>({\n width: 0,\n height: 0,\n });\n // set the view dimensions on layout\n const onLayout = useCallback(({ nativeEvent: { layout: { width, height } }}) => {\n setDimensions({\n width: dimension(width),\n height: dimension(height),\n });\n }, []);\n // wrap the native onLocationChange and extract the raw event value\n const onLocationChange = useCallback((event: any) => {\n if (wrappedOnLocationChange) {\n wrappedOnLocationChange(event.nativeEvent);\n }\n }, [wrappedOnLocationChange]);\n\n const onTableOfContents = useCallback((event: any) => {\n if (wrappedOnTableOfContents) {\n const toc = event.nativeEvent.toc || null;\n wrappedOnTableOfContents(toc);\n }\n }, [wrappedOnTableOfContents]);\n\n useEffect(() => {\n if (Platform.OS === 'android') {\n const viewId = findNodeHandle(ref.current);\n createFragment(viewId);\n }\n }, [])\n\n return (\n <View\n style={styles.container}\n onLayout={onLayout}\n >\n <BaseReadiumView\n height={height}\n width={width}\n {...props}\n onLocationChange={onLocationChange}\n onTableOfContents={onTableOfContents}\n settings={unmappedSettings ? Settings.map(unmappedSettings) : undefined}\n ref={ref}\n />\n </View>\n );\n};\n\nconst styles = StyleSheet.create({\n container: { width: '100%', height: '100%' },\n});\n"]}
1
+ {"version":3,"sources":["ReadiumView.tsx"],"names":["React","useCallback","useState","useRef","useEffect","View","Platform","findNodeHandle","StyleSheet","Settings","createFragment","getWidthOrHeightValue","dimension","BaseReadiumView","ReadiumView","onLocationChange","wrappedOnLocationChange","onTableOfContents","wrappedOnTableOfContents","settings","unmappedSettings","props","ref","height","width","setDimensions","onLayout","nativeEvent","layout","event","toc","OS","viewId","current","styles","container","map","undefined","create"],"mappings":";;AAAA,OAAOA,KAAP,IAAgBC,WAAhB,EAA6BC,QAA7B,EAAuCC,MAAvC,EAA+CC,SAA/C,QAAgE,OAAhE;AACA,SAASC,IAAT,EAAeC,QAAf,EAAyBC,cAAzB,EAAyCC,UAAzC,QAA2D,cAA3D;AAGA,SAASC,QAAT,QAAyB,eAAzB;AACA,SAASC,cAAT,EAAyBC,qBAAqB,IAAIC,SAAlD,QAAmE,UAAnE;AAEA,SAASC,eAAT,QAAgC,mBAAhC;AAIA,OAAO,MAAMC,WAAmC,GAAG,QAK7C;AAAA,MAL8C;AAClDC,IAAAA,gBAAgB,EAAEC,uBADgC;AAElDC,IAAAA,iBAAiB,EAAEC,wBAF+B;AAGlDC,IAAAA,QAAQ,EAAEC,gBAHwC;AAIlD,OAAGC;AAJ+C,GAK9C;A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ACsB,MAAD,CAAd;AACD;AACF,GALQ,EAKN,EALM,CAAT;AAOA,sBACE,oBAAC,IAAD;AACE,IAAA,KAAK,EAAEE,MAAM,CAACC,SADhB;AAEE,IAAA,QAAQ,EAAET;AAFZ,kBAIE,oBAAC,eAAD;AACE,IAAA,MAAM,EAAEH,MADV;AAEE,IAAA,KAAK,EAAEC;AAFT,KAGMH,KAHN;AAIE,IAAA,gBAAgB,EAAEN,gBAJpB;AAKE,IAAA,iBAAiB,EAAEE,iBALrB;AAME,IAAA,QAAQ,EAAEG,gBAAgB,GAAGX,QAAQ,CAAC2B,GAAT,CAAahB,gBAAb,CAAH,GAAoCiB,SANhE;AAOE,IAAA,GAAG,EAAEf;AAPP,KAJF,CADF;AAgBD,CAvDM;AAyDP,MAAMY,MAAM,GAAG1B,UAAU,CAAC8B,MAAX,CAAkB;AAC/BH,EAAAA,SAAS,EAAE;AAAEX,IAAAA,KAAK,EAAE,MAAT;AAAiBD,IAAAA,MAAM,EAAE;AAAzB;AADoB,CAAlB,CAAf","sourcesContent":["import React, { useCallback, useState, useRef, useEffect } from 'react';\nimport { View, Platform, findNodeHandle, StyleSheet } from 'react-native';\n\nimport type { Dimensions } from '../interfaces';\nimport { Settings } from '../interfaces';\nimport { createFragment, getWidthOrHeightValue as dimension } from '../utils';\nimport type { BaseReadiumViewProps } from './BaseReadiumView';\nimport { BaseReadiumView } from './BaseReadiumView';\n\nexport type ReadiumProps = BaseReadiumViewProps;\n\nexport const ReadiumView: React.FC<ReadiumProps> = ({\n onLocationChange: wrappedOnLocationChange,\n onTableOfContents: wrappedOnTableOfContents,\n settings: unmappedSettings,\n ...props\n}) => {\n const ref = useRef(null);\n const [{ height, width }, setDimensions] = useState<Dimensions>({\n width: 0,\n height: 0,\n });\n // set the view dimensions on layout\n const onLayout = useCallback(({ nativeEvent: { layout: { width, height } }}: any) => {\n setDimensions({\n width: dimension(width),\n height: dimension(height),\n });\n }, []);\n // wrap the native onLocationChange and extract the raw event value\n const onLocationChange = useCallback((event: any) => {\n if (wrappedOnLocationChange) {\n wrappedOnLocationChange(event.nativeEvent);\n }\n }, [wrappedOnLocationChange]);\n\n const onTableOfContents = useCallback((event: any) => {\n if (wrappedOnTableOfContents) {\n const toc = event.nativeEvent.toc || null;\n wrappedOnTableOfContents(toc);\n }\n }, [wrappedOnTableOfContents]);\n\n useEffect(() => {\n if (Platform.OS === 'android') {\n const viewId = findNodeHandle(ref.current);\n createFragment(viewId);\n }\n }, [])\n\n return (\n <View\n style={styles.container}\n onLayout={onLayout}\n >\n <BaseReadiumView\n height={height}\n width={width}\n {...props}\n onLocationChange={onLocationChange}\n onTableOfContents={onTableOfContents}\n settings={unmappedSettings ? Settings.map(unmappedSettings) : undefined}\n ref={ref}\n />\n </View>\n );\n};\n\nconst styles = StyleSheet.create({\n container: { width: '100%', height: '100%' },\n});\n"]}
@@ -0,0 +1,5 @@
1
+ export * from './enums';
2
+ export * from './interfaces';
3
+ export { RANGES } from './utils';
4
+ export { ReadiumView } from './web/ReadiumView';
5
+ //# sourceMappingURL=index.web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.web.tsx"],"names":["RANGES","ReadiumView"],"mappings":"AAAA,cAAc,SAAd;AACA,cAAc,cAAd;AACA,SAASA,MAAT,QAAuB,SAAvB;AAEA,SAASC,WAAT,QAA4B,mBAA5B","sourcesContent":["export * from './enums';\nexport * from './interfaces';\nexport { RANGES } from './utils';\n\nexport { ReadiumView } from './web/ReadiumView';\n"]}
@@ -0,0 +1,75 @@
1
+ import React from 'react';
2
+ import { View, StyleSheet } from 'react-native';
3
+ import { useReaderRef, useSettingsObserver, useLocationObserver } from './hooks';
4
+ export const ReadiumView = _ref => {
5
+ let {
6
+ file,
7
+ settings,
8
+ location,
9
+ onLocationChange,
10
+ onTableOfContents
11
+ } = _ref;
12
+ const readerRef = useReaderRef({
13
+ file,
14
+ onLocationChange,
15
+ onTableOfContents
16
+ });
17
+ const reader = readerRef.current;
18
+ useSettingsObserver(reader, settings);
19
+ useLocationObserver(reader, location);
20
+ return /*#__PURE__*/React.createElement(View, {
21
+ style: styles.container
22
+ }, !reader && /*#__PURE__*/React.createElement("div", {
23
+ style: styles.loader
24
+ }, "Loading reader..."), /*#__PURE__*/React.createElement("div", {
25
+ id: "D2Reader-Container",
26
+ style: styles.d2Container
27
+ }, reader && /*#__PURE__*/React.createElement("button", {
28
+ onClick: reader.previousPage,
29
+ style: styles.button
30
+ }, "\u2039"), /*#__PURE__*/React.createElement("main", {
31
+ style: styles.maximize,
32
+ tabIndex: -1,
33
+ id: "iframe-wrapper"
34
+ }, /*#__PURE__*/React.createElement("div", {
35
+ id: "reader-loading",
36
+ className: "loading",
37
+ style: styles.loader
38
+ }), /*#__PURE__*/React.createElement("div", {
39
+ id: "reader-error",
40
+ className: "error"
41
+ })), reader && /*#__PURE__*/React.createElement("button", {
42
+ onClick: reader.nextPage,
43
+ style: styles.button
44
+ }, "\u203A")));
45
+ };
46
+ const styles = StyleSheet.create({
47
+ container: {
48
+ width: '100%',
49
+ height: '100%'
50
+ },
51
+ d2Container: {
52
+ width: '100%',
53
+ height: '100%',
54
+ display: 'flex'
55
+ },
56
+ maximize: {
57
+ width: 'calc(100% - 100px)',
58
+ height: '100%',
59
+ display: 'flex'
60
+ },
61
+ button: {
62
+ width: 50,
63
+ fontSize: 100,
64
+ backgroundColor: 'transparent',
65
+ border: 'none'
66
+ },
67
+ loader: {
68
+ width: '100%',
69
+ height: '100%',
70
+ textAlign: 'center',
71
+ position: 'relative',
72
+ top: 'calc(50% - 10px)'
73
+ }
74
+ });
75
+ //# sourceMappingURL=ReadiumView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["ReadiumView.tsx"],"names":["React","View","StyleSheet","useReaderRef","useSettingsObserver","useLocationObserver","ReadiumView","file","settings","location","onLocationChange","onTableOfContents","readerRef","reader","current","styles","container","loader","d2Container","previousPage","button","maximize","nextPage","create","width","height","display","fontSize","backgroundColor","border","textAlign","position","top"],"mappings":"AAAA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F,EAUGJ,MAAM,iBAAI;AAAQ,IAAA,OAAO,EAAEA,MAAM,CAACS,QAAxB;AAAkC,IAAA,KAAK,EAAEP,MAAM,CAACK;AAAhD,cAVb,CAFF,CADF;AAiBD,CAlCM;AAoCP,MAAML,MAAM,GAAGb,UAAU,CAACqB,MAAX,CAAkB;AAC/BP,EAAAA,SAAS,EAAE;AACTQ,IAAAA,KAAK,EAAE,MADE;AAETC,IAAAA,MAAM,EAAE;AAFC,GADoB;AAK/BP,EAAAA,WAAW,EAAE;AACXM,IAAAA,KAAK,EAAE,MADI;AAEXC,IAAAA,MAAM,EAAE,MAFG;AAGXC,IAAAA,OAAO,EAAE;AAHE,GALkB;AAU/BL,EAAAA,QAAQ,EAAE;AACRG,IAAAA,KAAK,EAAE,oBADC;AAERC,IAAAA,MAAM,EAAE,MAFA;AAGRC,IAAAA,OAAO,EAAE;AAHD,GAVqB;AAe/BN,EAAAA,MAAM,EAAE;AACNI,IAAAA,KAAK,EAAE,EADD;AAENG,IAAAA,QAAQ,EAAE,GAFJ;AAGNC,IAAAA,eAAe,EAAE,aAHX;AAINC,IAAAA,MAAM,EAAE;AAJF,GAfuB;AAqB/BZ,EAAAA,MAAM,EAAE;AACNO,IAAAA,KAAK,EAAE,MADD;AAENC,IAAAA,MAAM,EAAE,MAFF;AAGNK,IAAAA,SAAS,EAAE,QAHL;AAINC,IAAAA,QAAQ,EAAE,UAJJ;AAKNC,IAAAA,GAAG,EAAE;AALC;AArBuB,CAAlB,CAAf","sourcesContent":["import React from 'react';\nimport { View, StyleSheet } from 'react-native';\n\nimport type { ReadiumProps } from '../components/ReadiumView';\nimport {\n useReaderRef,\n useSettingsObserver,\n useLocationObserver,\n} from './hooks';\n\nexport const ReadiumView: React.FC<ReadiumProps> = ({\n file,\n settings,\n location,\n onLocationChange,\n onTableOfContents,\n}) => {\n const readerRef = useReaderRef({\n file,\n onLocationChange,\n onTableOfContents,\n });\n const reader = readerRef.current;\n\n useSettingsObserver(reader, settings);\n useLocationObserver(reader, location);\n\n return (\n <View style={styles.container}>\n {!reader && <div style={styles.loader}>Loading reader...</div>}\n <div id=\"D2Reader-Container\" style={styles.d2Container}>\n {reader && <button onClick={reader.previousPage} style={styles.button}>&lsaquo;</button>}\n <main\n style={styles.maximize}\n tabIndex={-1}\n id=\"iframe-wrapper\"\n >\n <div id=\"reader-loading\" className=\"loading\" style={styles.loader}></div>\n <div id=\"reader-error\" className=\"error\"></div>\n </main>\n {reader && <button onClick={reader.nextPage} style={styles.button}>&rsaquo;</button>}\n </div>\n </View>\n );\n};\n\nconst styles = StyleSheet.create({\n container: {\n width: '100%',\n height: '100%',\n },\n d2Container: {\n width: '100%',\n height: '100%',\n display: 'flex',\n },\n maximize: {\n width: 'calc(100% - 100px)',\n height: '100%',\n display: 'flex',\n },\n button: {\n width: 50,\n fontSize: 100,\n backgroundColor: 'transparent',\n border: 'none',\n },\n loader: {\n width: '100%',\n height: '100%',\n textAlign: 'center',\n position: 'relative',\n top: 'calc(50% - 10px)',\n },\n});\n"]}
@@ -0,0 +1,4 @@
1
+ export * from './useReaderRef';
2
+ export * from './useSettingsObserver';
3
+ export * from './useLocationObserver';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAd;AACA,cAAc,uBAAd;AACA,cAAc,uBAAd","sourcesContent":["export * from './useReaderRef';\nexport * from './useSettingsObserver';\nexport * from './useLocationObserver';\n"]}
@@ -0,0 +1,11 @@
1
+ import { useDeepCompareEffect } from 'use-deep-compare';
2
+ export const useLocationObserver = (reader, location) => {
3
+ useDeepCompareEffect(() => {
4
+ if (reader && location) {
5
+ // NOTE: technically this is a Link | Locator. However, under the hood the
6
+ // R2D2BC is converting Links to locators, so just force the type here.
7
+ reader.goTo(location);
8
+ }
9
+ }, [location, !!reader]);
10
+ };
11
+ //# sourceMappingURL=useLocationObserver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useLocationObserver.ts"],"names":["useDeepCompareEffect","useLocationObserver","reader","location","goTo"],"mappings":"AAAA,SAASA,oBAAT,QAAqC,kBAArC;AAMA,OAAO,MAAMC,mBAAmB,GAAG,CACjCC,MADiC,EAEjCC,QAFiC,KAG9B;AACHH,EAAAA,oBAAoB,CAAC,MAAM;AACzB,QAAIE,MAAM,IAAIC,QAAd,EAAwB;AACtB;AACA;AACAD,MAAAA,MAAM,CAACE,IAAP,CAAYD,QAAZ;AACD;AACF,GANmB,EAMjB,CACDA,QADC,EAED,CAAC,CAACD,MAFD,CANiB,CAApB;AAUD,CAdM","sourcesContent":["import { useDeepCompareEffect } from 'use-deep-compare';\nimport type D2Reader from '@d-i-t-a/reader';\nimport type { Locator as R2Locator } from '@d-i-t-a/reader';\n\nimport type { Link, Locator } from '../../interfaces';\n\nexport const useLocationObserver = (\n reader?: D2Reader | null,\n location?: Link | Locator | null,\n) => {\n useDeepCompareEffect(() => {\n if (reader && location) {\n // NOTE: technically this is a Link | Locator. However, under the hood the\n // R2D2BC is converting Links to locators, so just force the type here.\n reader.goTo(location as R2Locator);\n }\n }, [\n location,\n !!reader,\n ]);\n};\n"]}
@@ -0,0 +1,47 @@
1
+ import { useEffect, useRef } from 'react';
2
+ import D2Reader from '@d-i-t-a/reader';
3
+ export const useReaderRef = _ref => {
4
+ let {
5
+ file,
6
+ onLocationChange,
7
+ onTableOfContents
8
+ } = _ref;
9
+ const readerRef = useRef(null);
10
+ useEffect(() => {
11
+ D2Reader.load({
12
+ url: new URL(file.url),
13
+ lastReadingPosition: file.initialLocation,
14
+ api: {
15
+ updateCurrentLocation: async location => {
16
+ if (onLocationChange) onLocationChange(location);
17
+ return location;
18
+ }
19
+ },
20
+ injectables: injectables
21
+ }).then(r => {
22
+ if (onTableOfContents) {
23
+ onTableOfContents(r.tableOfContents);
24
+ }
25
+
26
+ readerRef.current = r;
27
+ });
28
+ }, []);
29
+ return readerRef;
30
+ }; // NOTE: right now we're serving these through statically.io, which is just
31
+ // pulling them from Github... Might not be the best way and maybe we should
32
+ // consider bundling them with the library.
33
+
34
+ const injectables = [{
35
+ type: "style",
36
+ url: "https://cdn.statically.io/gh/d-i-t-a/R2D2BC/production/viewer/readium-css/ReadiumCSS-before.css",
37
+ r2before: true
38
+ }, {
39
+ type: "style",
40
+ url: "https://cdn.statically.io/gh/d-i-t-a/R2D2BC/production/viewer/readium-css/ReadiumCSS-default.css",
41
+ r2default: true
42
+ }, {
43
+ type: "style",
44
+ url: "https://cdn.statically.io/gh/d-i-t-a/R2D2BC/production/viewer/readium-css/ReadiumCSS-after.css",
45
+ r2after: true
46
+ }];
47
+ //# sourceMappingURL=useReaderRef.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useReaderRef.ts"],"names":["useEffect","useRef","D2Reader","useReaderRef","file","onLocationChange","onTableOfContents","readerRef","load","url","URL","lastReadingPosition","initialLocation","api","updateCurrentLocation","location","injectables","then","r","tableOfContents","current","type","r2before","r2default","r2after"],"mappings":"AAAA,SAASA,SAAT,EAAoBC,MAApB,QAAkC,OAAlC;AACA,OAAOC,QAAP,MAAqB,iBAArB;AAKA,OAAO,MAAMC,YAAY,GAAG,QAIkD;AAAA,MAJjD;AAC3BC,IAAAA,IAD2B;AAE3BC,IAAAA,gBAF2B;AAG3BC,IAAAA;AAH2B,GAIiD;AAC5E,QAAMC,SAAS,GAAGN,MAAM,CAAkB,IAAlB,CAAxB;AAEAD,EAAAA,SAAS,CAAC,MAAM;AACdE,IAAAA,QAAQ,CAACM,IAAT,CAAc;AACZC,MAAAA,GAAG,EAAE,IAAIC,GAAJ,CAAQN,IAAI,CAACK,GAAb,CADO;AAEZE,MAAAA,mBAAmB,EAAEP,IAAI,CAACQ,eAFd;AAGZC,MAAAA,GAAG,EAAE;AACHC,QAAAA,qBAAqB,EAAE,MAAOC,QAAP,IAA6B;AAClD,cAAIV,gBAAJ,EAAsBA,gBAAgB,CAACU,QAAD,CAAhB;AACtB,iBAAOA,QAAP;AACD;AAJE,OAHO;AASZC,MAAAA,WAAW,EAAEA;AATD,KAAd,EAUGC,IAVH,CAUSC,CAAD,IAAO;AACb,UAAIZ,iBAAJ,EAAuB;AACrBA,QAAAA,iBAAiB,CAACY,CAAC,CAACC,eAAH,CAAjB;AACD;;AACDZ,MAAAA,SAAS,CAACa,OAAV,GAAoBF,CAApB;AACD,KAfD;AAgBD,GAjBQ,EAiBN,EAjBM,CAAT;AAmBA,SAAOX,SAAP;AACD,CA3BM,C,CA6BP;AACA;AACA;;AACA,MAAMS,WAAkB,GAAG,CACzB;AACEK,EAAAA,IAAI,EAAE,OADR;AAEEZ,EAAAA,GAAG,EAAE,iGAFP;AAGEa,EAAAA,QAAQ,EAAE;AAHZ,CADyB,EAMzB;AACED,EAAAA,IAAI,EAAE,OADR;AAEEZ,EAAAA,GAAG,EAAE,kGAFP;AAGEc,EAAAA,SAAS,EAAE;AAHb,CANyB,EAWzB;AACEF,EAAAA,IAAI,EAAE,OADR;AAEEZ,EAAAA,GAAG,EAAE,gGAFP;AAGEe,EAAAA,OAAO,EAAE;AAHX,CAXyB,CAA3B","sourcesContent":["import { useEffect, useRef } from 'react';\nimport D2Reader from '@d-i-t-a/reader';\n\nimport type { ReadiumProps } from '../../components/ReadiumView';\nimport type { Locator } from '../../interfaces';\n\nexport const useReaderRef = ({\n file,\n onLocationChange,\n onTableOfContents,\n}: Pick<ReadiumProps, 'file' | 'onLocationChange' | 'onTableOfContents' >) => {\n const readerRef = useRef<D2Reader | null>(null);\n\n useEffect(() => {\n D2Reader.load({\n url: new URL(file.url),\n lastReadingPosition: file.initialLocation,\n api: {\n updateCurrentLocation: async (location: Locator) => {\n if (onLocationChange) onLocationChange(location);\n return location;\n },\n },\n injectables: injectables,\n }).then((r) => {\n if (onTableOfContents) {\n onTableOfContents(r.tableOfContents);\n }\n readerRef.current = r;\n });\n }, []);\n\n return readerRef\n};\n\n// NOTE: right now we're serving these through statically.io, which is just\n// pulling them from Github... Might not be the best way and maybe we should\n// consider bundling them with the library.\nconst injectables: any[] = [\n {\n type: \"style\",\n url: \"https://cdn.statically.io/gh/d-i-t-a/R2D2BC/production/viewer/readium-css/ReadiumCSS-before.css\",\n r2before: true,\n },\n {\n type: \"style\",\n url: \"https://cdn.statically.io/gh/d-i-t-a/R2D2BC/production/viewer/readium-css/ReadiumCSS-default.css\",\n r2default: true,\n },\n {\n type: \"style\",\n url: \"https://cdn.statically.io/gh/d-i-t-a/R2D2BC/production/viewer/readium-css/ReadiumCSS-after.css\",\n r2after: true,\n },\n];\n\n"]}
@@ -0,0 +1,11 @@
1
+ import { useDeepCompareEffect } from 'use-deep-compare';
2
+ export const useSettingsObserver = (reader, settings) => {
3
+ useDeepCompareEffect(() => {
4
+ if (reader && settings) {
5
+ // @ts-ignore - FIXME need to do some deeper investigation if these
6
+ // are equivalent or not
7
+ reader === null || reader === void 0 ? void 0 : reader.applyUserSettings(settings);
8
+ }
9
+ }, [settings, !!reader]);
10
+ };
11
+ //# sourceMappingURL=useSettingsObserver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useSettingsObserver.ts"],"names":["useDeepCompareEffect","useSettingsObserver","reader","settings","applyUserSettings"],"mappings":"AAAA,SAASA,oBAAT,QAAqC,kBAArC;AAMA,OAAO,MAAMC,mBAAmB,GAAG,CACjCC,MADiC,EAEjCC,QAFiC,KAG9B;AACHH,EAAAA,oBAAoB,CAAC,MAAM;AACzB,QAAIE,MAAM,IAAIC,QAAd,EAAwB;AACtB;AACA;AACAD,MAAAA,MAAM,SAAN,IAAAA,MAAM,WAAN,YAAAA,MAAM,CAAEE,iBAAR,CAA0BD,QAA1B;AACD;AACF,GANmB,EAMjB,CACDA,QADC,EAED,CAAC,CAACD,MAFD,CANiB,CAApB;AAUD,CAdM","sourcesContent":["import { useDeepCompareEffect } from 'use-deep-compare';\nimport type D2Reader from '@d-i-t-a/reader';\nimport type { UserSettings } from '@d-i-t-a/reader/dist/types/model/user-settings/UserSettings';\n\nimport type { Settings } from '../../interfaces';\n\nexport const useSettingsObserver = (\n reader?: D2Reader | null,\n settings?: Partial<Settings> | null,\n) => {\n useDeepCompareEffect(() => {\n if (reader && settings) {\n // @ts-ignore - FIXME need to do some deeper investigation if these\n // are equivalent or not\n reader?.applyUserSettings(settings as Partial<UserSettings>);\n }\n }, [\n settings,\n !!reader,\n ]);\n};\n"]}
@@ -1,5 +1,4 @@
1
1
  import React from 'react';
2
2
  import type { BaseReadiumViewProps } from './BaseReadiumView';
3
- declare type ReadiumProps = BaseReadiumViewProps;
3
+ export declare type ReadiumProps = BaseReadiumViewProps;
4
4
  export declare const ReadiumView: React.FC<ReadiumProps>;
5
- export {};
@@ -0,0 +1,4 @@
1
+ export * from './enums';
2
+ export * from './interfaces';
3
+ export { RANGES } from './utils';
4
+ export { ReadiumView } from './web/ReadiumView';
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import type { ReadiumProps } from '../components/ReadiumView';
3
+ export declare const ReadiumView: React.FC<ReadiumProps>;
@@ -0,0 +1,3 @@
1
+ export * from './useReaderRef';
2
+ export * from './useSettingsObserver';
3
+ export * from './useLocationObserver';
@@ -0,0 +1,3 @@
1
+ import type D2Reader from '@d-i-t-a/reader';
2
+ import type { Link, Locator } from '../../interfaces';
3
+ export declare const useLocationObserver: (reader?: D2Reader | null | undefined, location?: Link | Locator | null | undefined) => void;
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import D2Reader from '@d-i-t-a/reader';
3
+ import type { ReadiumProps } from '../../components/ReadiumView';
4
+ export declare const useReaderRef: ({ file, onLocationChange, onTableOfContents, }: Pick<ReadiumProps, 'file' | 'onLocationChange' | 'onTableOfContents'>) => import("react").MutableRefObject<D2Reader | null>;
@@ -0,0 +1,3 @@
1
+ import type D2Reader from '@d-i-t-a/reader';
2
+ import type { Settings } from '../../interfaces';
3
+ export declare const useSettingsObserver: (reader?: D2Reader | null | undefined, settings?: Partial<Settings> | null | undefined) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-readium",
3
- "version": "1.0.4",
3
+ "version": "1.1.0",
4
4
  "description": "A react-native wrapper for https://readium.org/",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -62,8 +62,8 @@
62
62
  "@react-native-community/eslint-config": "^2.0.0",
63
63
  "@release-it/conventional-changelog": "^2.0.0",
64
64
  "@types/jest": "^26.0.0",
65
- "@types/react": "^16.9.19",
66
- "@types/react-native": "0.62.13",
65
+ "@types/react": "^18.0.26",
66
+ "@types/react-native": "^0.70.8",
67
67
  "commitlint": "^11.0.0",
68
68
  "conventional-changelog-cli": "^2.2.2",
69
69
  "eslint": "^7.2.0",
@@ -73,8 +73,8 @@
73
73
  "jest": "^26.0.1",
74
74
  "pod-install": "^0.1.0",
75
75
  "prettier": "^2.0.5",
76
- "react": "16.13.1",
77
- "react-native": "0.63.4",
76
+ "react": "^18.2.0",
77
+ "react-native": "^0.70.6",
78
78
  "react-native-builder-bob": "^0.18.2",
79
79
  "release-it": "^14.2.2",
80
80
  "typescript": "^4.1.3"
@@ -156,5 +156,8 @@
156
156
  ]
157
157
  ]
158
158
  },
159
- "dependencies": {}
159
+ "dependencies": {
160
+ "@d-i-t-a/reader": "^2.1.4",
161
+ "use-deep-compare": "^1.1.0"
162
+ }
160
163
  }
@@ -7,7 +7,7 @@ import { createFragment, getWidthOrHeightValue as dimension } from '../utils';
7
7
  import type { BaseReadiumViewProps } from './BaseReadiumView';
8
8
  import { BaseReadiumView } from './BaseReadiumView';
9
9
 
10
- type ReadiumProps = BaseReadiumViewProps;
10
+ export type ReadiumProps = BaseReadiumViewProps;
11
11
 
12
12
  export const ReadiumView: React.FC<ReadiumProps> = ({
13
13
  onLocationChange: wrappedOnLocationChange,
@@ -21,7 +21,7 @@ export const ReadiumView: React.FC<ReadiumProps> = ({
21
21
  height: 0,
22
22
  });
23
23
  // set the view dimensions on layout
24
- const onLayout = useCallback(({ nativeEvent: { layout: { width, height } }}) => {
24
+ const onLayout = useCallback(({ nativeEvent: { layout: { width, height } }}: any) => {
25
25
  setDimensions({
26
26
  width: dimension(width),
27
27
  height: dimension(height),
@@ -0,0 +1,5 @@
1
+ export * from './enums';
2
+ export * from './interfaces';
3
+ export { RANGES } from './utils';
4
+
5
+ export { ReadiumView } from './web/ReadiumView';
@@ -0,0 +1,75 @@
1
+ import React from 'react';
2
+ import { View, StyleSheet } from 'react-native';
3
+
4
+ import type { ReadiumProps } from '../components/ReadiumView';
5
+ import {
6
+ useReaderRef,
7
+ useSettingsObserver,
8
+ useLocationObserver,
9
+ } from './hooks';
10
+
11
+ export const ReadiumView: React.FC<ReadiumProps> = ({
12
+ file,
13
+ settings,
14
+ location,
15
+ onLocationChange,
16
+ onTableOfContents,
17
+ }) => {
18
+ const readerRef = useReaderRef({
19
+ file,
20
+ onLocationChange,
21
+ onTableOfContents,
22
+ });
23
+ const reader = readerRef.current;
24
+
25
+ useSettingsObserver(reader, settings);
26
+ useLocationObserver(reader, location);
27
+
28
+ return (
29
+ <View style={styles.container}>
30
+ {!reader && <div style={styles.loader}>Loading reader...</div>}
31
+ <div id="D2Reader-Container" style={styles.d2Container}>
32
+ {reader && <button onClick={reader.previousPage} style={styles.button}>&lsaquo;</button>}
33
+ <main
34
+ style={styles.maximize}
35
+ tabIndex={-1}
36
+ id="iframe-wrapper"
37
+ >
38
+ <div id="reader-loading" className="loading" style={styles.loader}></div>
39
+ <div id="reader-error" className="error"></div>
40
+ </main>
41
+ {reader && <button onClick={reader.nextPage} style={styles.button}>&rsaquo;</button>}
42
+ </div>
43
+ </View>
44
+ );
45
+ };
46
+
47
+ const styles = StyleSheet.create({
48
+ container: {
49
+ width: '100%',
50
+ height: '100%',
51
+ },
52
+ d2Container: {
53
+ width: '100%',
54
+ height: '100%',
55
+ display: 'flex',
56
+ },
57
+ maximize: {
58
+ width: 'calc(100% - 100px)',
59
+ height: '100%',
60
+ display: 'flex',
61
+ },
62
+ button: {
63
+ width: 50,
64
+ fontSize: 100,
65
+ backgroundColor: 'transparent',
66
+ border: 'none',
67
+ },
68
+ loader: {
69
+ width: '100%',
70
+ height: '100%',
71
+ textAlign: 'center',
72
+ position: 'relative',
73
+ top: 'calc(50% - 10px)',
74
+ },
75
+ });
@@ -0,0 +1,3 @@
1
+ export * from './useReaderRef';
2
+ export * from './useSettingsObserver';
3
+ export * from './useLocationObserver';
@@ -0,0 +1,21 @@
1
+ import { useDeepCompareEffect } from 'use-deep-compare';
2
+ import type D2Reader from '@d-i-t-a/reader';
3
+ import type { Locator as R2Locator } from '@d-i-t-a/reader';
4
+
5
+ import type { Link, Locator } from '../../interfaces';
6
+
7
+ export const useLocationObserver = (
8
+ reader?: D2Reader | null,
9
+ location?: Link | Locator | null,
10
+ ) => {
11
+ useDeepCompareEffect(() => {
12
+ if (reader && location) {
13
+ // NOTE: technically this is a Link | Locator. However, under the hood the
14
+ // R2D2BC is converting Links to locators, so just force the type here.
15
+ reader.goTo(location as R2Locator);
16
+ }
17
+ }, [
18
+ location,
19
+ !!reader,
20
+ ]);
21
+ };
@@ -0,0 +1,56 @@
1
+ import { useEffect, useRef } from 'react';
2
+ import D2Reader from '@d-i-t-a/reader';
3
+
4
+ import type { ReadiumProps } from '../../components/ReadiumView';
5
+ import type { Locator } from '../../interfaces';
6
+
7
+ export const useReaderRef = ({
8
+ file,
9
+ onLocationChange,
10
+ onTableOfContents,
11
+ }: Pick<ReadiumProps, 'file' | 'onLocationChange' | 'onTableOfContents' >) => {
12
+ const readerRef = useRef<D2Reader | null>(null);
13
+
14
+ useEffect(() => {
15
+ D2Reader.load({
16
+ url: new URL(file.url),
17
+ lastReadingPosition: file.initialLocation,
18
+ api: {
19
+ updateCurrentLocation: async (location: Locator) => {
20
+ if (onLocationChange) onLocationChange(location);
21
+ return location;
22
+ },
23
+ },
24
+ injectables: injectables,
25
+ }).then((r) => {
26
+ if (onTableOfContents) {
27
+ onTableOfContents(r.tableOfContents);
28
+ }
29
+ readerRef.current = r;
30
+ });
31
+ }, []);
32
+
33
+ return readerRef
34
+ };
35
+
36
+ // NOTE: right now we're serving these through statically.io, which is just
37
+ // pulling them from Github... Might not be the best way and maybe we should
38
+ // consider bundling them with the library.
39
+ const injectables: any[] = [
40
+ {
41
+ type: "style",
42
+ url: "https://cdn.statically.io/gh/d-i-t-a/R2D2BC/production/viewer/readium-css/ReadiumCSS-before.css",
43
+ r2before: true,
44
+ },
45
+ {
46
+ type: "style",
47
+ url: "https://cdn.statically.io/gh/d-i-t-a/R2D2BC/production/viewer/readium-css/ReadiumCSS-default.css",
48
+ r2default: true,
49
+ },
50
+ {
51
+ type: "style",
52
+ url: "https://cdn.statically.io/gh/d-i-t-a/R2D2BC/production/viewer/readium-css/ReadiumCSS-after.css",
53
+ r2after: true,
54
+ },
55
+ ];
56
+
@@ -0,0 +1,21 @@
1
+ import { useDeepCompareEffect } from 'use-deep-compare';
2
+ import type D2Reader from '@d-i-t-a/reader';
3
+ import type { UserSettings } from '@d-i-t-a/reader/dist/types/model/user-settings/UserSettings';
4
+
5
+ import type { Settings } from '../../interfaces';
6
+
7
+ export const useSettingsObserver = (
8
+ reader?: D2Reader | null,
9
+ settings?: Partial<Settings> | null,
10
+ ) => {
11
+ useDeepCompareEffect(() => {
12
+ if (reader && settings) {
13
+ // @ts-ignore - FIXME need to do some deeper investigation if these
14
+ // are equivalent or not
15
+ reader?.applyUserSettings(settings as Partial<UserSettings>);
16
+ }
17
+ }, [
18
+ settings,
19
+ !!reader,
20
+ ]);
21
+ };