@nypl/web-reader 0.1.4 → 0.2.0-alpha.3

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 (144) hide show
  1. package/dist/cjs/ServiceWorker/sw.js +2 -0
  2. package/dist/cjs/ServiceWorker/sw.js.map +7 -0
  3. package/dist/cjs/index.js +683 -0
  4. package/dist/cjs/index.js.map +7 -0
  5. package/dist/esm/ServiceWorker/sw.js +1263 -0
  6. package/dist/esm/ServiceWorker/sw.js.map +7 -0
  7. package/dist/esm/index.js +88803 -0
  8. package/dist/esm/index.js.map +7 -0
  9. package/dist/html-styles.css +2 -0
  10. package/dist/html-styles.css.map +7 -0
  11. package/dist/pdf-styles.css +2 -0
  12. package/dist/pdf-styles.css.map +7 -0
  13. package/dist/{HtmlReader → types/HtmlReader}/HtmlReaderContent.d.ts +3 -3
  14. package/dist/{HtmlReader → types/HtmlReader}/index.d.ts +22 -22
  15. package/dist/{HtmlReader → types/HtmlReader}/injectables.d.ts +30 -30
  16. package/dist/{PdfReader → types/PdfReader}/index.d.ts +11 -12
  17. package/dist/{PdfReader → types/PdfReader}/useMeasure.d.ts +7 -4
  18. package/dist/{ServiceWorker → types/ServiceWorker}/client.d.ts +9 -9
  19. package/dist/{ServiceWorker → types/ServiceWorker}/constants.d.ts +3 -3
  20. package/{src/ServiceWorker/index.ts → dist/types/ServiceWorker/index.d.ts} +0 -0
  21. package/dist/{ServiceWorker → types/ServiceWorker}/sw.d.ts +7 -7
  22. package/dist/{ServiceWorker → types/ServiceWorker}/types.d.ts +3 -3
  23. package/dist/{WebpubManifestTypes → types/WebpubManifestTypes}/ConformsTo.d.ts +3 -3
  24. package/dist/{WebpubManifestTypes → types/WebpubManifestTypes}/Contributor.d.ts +17 -17
  25. package/dist/{WebpubManifestTypes → types/WebpubManifestTypes}/EpubExtension.d.ts +47 -47
  26. package/dist/{WebpubManifestTypes → types/WebpubManifestTypes}/LanguageMap.d.ts +3 -3
  27. package/dist/{WebpubManifestTypes → types/WebpubManifestTypes}/Metadata.d.ts +46 -46
  28. package/dist/{WebpubManifestTypes → types/WebpubManifestTypes}/OPDSLink.d.ts +63 -63
  29. package/dist/{WebpubManifestTypes → types/WebpubManifestTypes}/PresentationHints.d.ts +53 -53
  30. package/dist/{WebpubManifestTypes → types/WebpubManifestTypes}/ReadiumLink.d.ts +58 -58
  31. package/dist/{WebpubManifestTypes → types/WebpubManifestTypes}/Subject.d.ts +16 -16
  32. package/dist/{WebpubManifestTypes → types/WebpubManifestTypes}/WebpubManifest.d.ts +14 -14
  33. package/dist/{constants.d.ts → types/constants.d.ts} +2 -2
  34. package/dist/{index.d.ts → types/index.d.ts} +7 -7
  35. package/dist/{types.d.ts → types/types.d.ts} +66 -66
  36. package/dist/{ui → types/ui}/Button.d.ts +9 -7
  37. package/dist/{ui → types/ui}/Header.d.ts +6 -6
  38. package/dist/{ui → types/ui}/HtmlSettings.d.ts +9 -9
  39. package/dist/{ui → types/ui}/PageButton.d.ts +7 -7
  40. package/dist/{ui → types/ui}/PdfSettings.d.ts +9 -9
  41. package/dist/{ui → types/ui}/SettingsButton.d.ts +5 -5
  42. package/dist/{ui → types/ui}/TableOfContent.d.ts +7 -7
  43. package/dist/{ui → types/ui}/ToggleButton.d.ts +10 -10
  44. package/dist/{ui → types/ui}/ToggleGroup.d.ts +8 -8
  45. package/dist/{ui → types/ui}/constants.d.ts +1 -1
  46. package/dist/{ui → types/ui}/hooks/useColorModeValue.d.ts +7 -7
  47. package/dist/{ui → types/ui}/hooks/useContainerWidth.d.ts +6 -6
  48. package/dist/{ui → types/ui}/hooks/useEventListener.d.ts +8 -8
  49. package/dist/{ui → types/ui}/manager.d.ts +9 -9
  50. package/dist/{ui → types/ui}/nypl-base-theme/components/button.d.ts +94 -94
  51. package/dist/{ui → types/ui}/nypl-base-theme/components/checkbox.d.ts +41 -41
  52. package/dist/{ui → types/ui}/nypl-base-theme/components/form-error.d.ts +14 -14
  53. package/dist/{ui → types/ui}/nypl-base-theme/components/form-label.d.ts +14 -14
  54. package/dist/{ui → types/ui}/nypl-base-theme/components/form.d.ts +15 -15
  55. package/dist/{ui → types/ui}/nypl-base-theme/components/input.d.ts +107 -107
  56. package/dist/{ui → types/ui}/nypl-base-theme/components/text-area.d.ts +34 -34
  57. package/dist/{ui → types/ui}/nypl-base-theme/foundations/breakpoints.d.ts +8 -8
  58. package/dist/{ui → types/ui}/nypl-base-theme/foundations/colors.d.ts +3 -3
  59. package/dist/{ui → types/ui}/nypl-base-theme/foundations/global.d.ts +13 -13
  60. package/dist/{ui → types/ui}/nypl-base-theme/foundations/radii.d.ts +12 -12
  61. package/dist/{ui → types/ui}/nypl-base-theme/foundations/spacing.d.ts +49 -49
  62. package/dist/{ui → types/ui}/nypl-base-theme/foundations/typography.d.ts +10 -10
  63. package/dist/{ui → types/ui}/nypl-base-theme/index.d.ts +6 -6
  64. package/dist/{ui → types/ui}/nypl-base-theme/types.d.ts +1 -1
  65. package/dist/{ui → types/ui}/theme/components/button.d.ts +78 -78
  66. package/dist/{ui → types/ui}/theme/components/text.d.ts +20 -20
  67. package/dist/{ui → types/ui}/theme/foundations/colors.d.ts +3 -3
  68. package/dist/{ui → types/ui}/theme/index.d.ts +11 -11
  69. package/dist/{ui → types/ui}/theme/types.d.ts +1 -1
  70. package/dist/{useWebReader.d.ts → types/useWebReader.d.ts} +7 -7
  71. package/dist/{utils → types/utils}/decryptAxisNow.d.ts +0 -0
  72. package/dist/{utils → types/utils}/fetch.d.ts +4 -4
  73. package/dist/{utils → types/utils}/getColor.d.ts +2 -2
  74. package/dist/{utils → types/utils}/toggleFullScreen.d.ts +5 -5
  75. package/package.json +21 -33
  76. package/dist/ServiceWorker/index.d.ts +0 -1
  77. package/dist/index.js +0 -8
  78. package/dist/web-reader.cjs.development.js +0 -3363
  79. package/dist/web-reader.cjs.development.js.map +0 -1
  80. package/dist/web-reader.cjs.production.min.js +0 -2
  81. package/dist/web-reader.cjs.production.min.js.map +0 -1
  82. package/dist/web-reader.esm.js +0 -3356
  83. package/dist/web-reader.esm.js.map +0 -1
  84. package/src/HtmlReader/HtmlReaderContent.tsx +0 -19
  85. package/src/HtmlReader/index.tsx +0 -262
  86. package/src/HtmlReader/injectables.ts +0 -26
  87. package/src/PdfReader/index.tsx +0 -492
  88. package/src/PdfReader/useMeasure.tsx +0 -68
  89. package/src/ServiceWorker/client.ts +0 -106
  90. package/src/ServiceWorker/constants.ts +0 -4
  91. package/src/ServiceWorker/sw.ts +0 -84
  92. package/src/ServiceWorker/types.ts +0 -3
  93. package/src/WebpubManifestTypes/ConformsTo.ts +0 -9
  94. package/src/WebpubManifestTypes/Contributor.ts +0 -24
  95. package/src/WebpubManifestTypes/EpubExtension.ts +0 -48
  96. package/src/WebpubManifestTypes/LanguageMap.ts +0 -5
  97. package/src/WebpubManifestTypes/Metadata.ts +0 -48
  98. package/src/WebpubManifestTypes/OPDSLink.ts +0 -251
  99. package/src/WebpubManifestTypes/PresentationHints.ts +0 -54
  100. package/src/WebpubManifestTypes/ReadiumLink.ts +0 -61
  101. package/src/WebpubManifestTypes/Subject.ts +0 -20
  102. package/src/WebpubManifestTypes/WebpubManifest.ts +0 -15
  103. package/src/constants.ts +0 -3
  104. package/src/index.tsx +0 -25
  105. package/src/types.ts +0 -94
  106. package/src/ui/Button.tsx +0 -12
  107. package/src/ui/Header.tsx +0 -89
  108. package/src/ui/HtmlSettings.tsx +0 -97
  109. package/src/ui/PageButton.tsx +0 -39
  110. package/src/ui/PdfSettings.tsx +0 -85
  111. package/src/ui/SettingsButton.tsx +0 -71
  112. package/src/ui/TableOfContent.tsx +0 -144
  113. package/src/ui/ToggleButton.tsx +0 -60
  114. package/src/ui/ToggleGroup.tsx +0 -41
  115. package/src/ui/constants.ts +0 -2
  116. package/src/ui/hooks/useColorModeValue.tsx +0 -19
  117. package/src/ui/hooks/useContainerWidth.ts +0 -24
  118. package/src/ui/hooks/useEventListener.ts +0 -26
  119. package/src/ui/manager.tsx +0 -73
  120. package/src/ui/nypl-base-theme/components/button.ts +0 -117
  121. package/src/ui/nypl-base-theme/components/checkbox.ts +0 -45
  122. package/src/ui/nypl-base-theme/components/form-error.ts +0 -15
  123. package/src/ui/nypl-base-theme/components/form-label.ts +0 -15
  124. package/src/ui/nypl-base-theme/components/form.ts +0 -16
  125. package/src/ui/nypl-base-theme/components/input.ts +0 -101
  126. package/src/ui/nypl-base-theme/components/text-area.ts +0 -17
  127. package/src/ui/nypl-base-theme/foundations/breakpoints.ts +0 -10
  128. package/src/ui/nypl-base-theme/foundations/colors.ts +0 -136
  129. package/src/ui/nypl-base-theme/foundations/global.ts +0 -16
  130. package/src/ui/nypl-base-theme/foundations/radii.ts +0 -13
  131. package/src/ui/nypl-base-theme/foundations/spacing.ts +0 -58
  132. package/src/ui/nypl-base-theme/foundations/typography.ts +0 -43
  133. package/src/ui/nypl-base-theme/index.ts +0 -42
  134. package/src/ui/nypl-base-theme/types.ts +0 -1
  135. package/src/ui/theme/components/button.ts +0 -85
  136. package/src/ui/theme/components/text.ts +0 -24
  137. package/src/ui/theme/foundations/colors.ts +0 -10
  138. package/src/ui/theme/index.ts +0 -34
  139. package/src/ui/theme/types.ts +0 -1
  140. package/src/useWebReader.tsx +0 -105
  141. package/src/utils/decryptAxisNow.ts +0 -45
  142. package/src/utils/fetch.ts +0 -13
  143. package/src/utils/getColor.ts +0 -14
  144. package/src/utils/toggleFullScreen.ts +0 -71
@@ -1,3356 +0,0 @@
1
- import React__default, { createElement, Fragment, useState, useMemo, useLayoutEffect, useReducer, useEffect, useCallback } from 'react';
2
- import { Button as Button$1, extendTheme, useRadio, useTheme as useTheme$1, ThemeProvider, Box, Circle, useRadioGroup, Flex, ButtonGroup, Popover, PopoverTrigger, Text, PopoverContent, PopoverBody, Menu, MenuButton, Portal, MenuList, MenuItem, Link, chakra, HStack, shouldForwardProp } from '@chakra-ui/react';
3
- import { Icon, IconNames, LogoNames, IconRotationTypes } from '@nypl/design-system-react-components';
4
- import { useTheme } from '@emotion/react';
5
- import { createBreakpoints } from '@chakra-ui/theme-tools';
6
- import { pdfjs, Page, Document } from 'react-pdf';
7
- import 'react-pdf/dist/esm/Page/AnnotationLayer.css';
8
- import D2Reader from '@d-i-t-a/reader';
9
-
10
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
11
- try {
12
- var info = gen[key](arg);
13
- var value = info.value;
14
- } catch (error) {
15
- reject(error);
16
- return;
17
- }
18
-
19
- if (info.done) {
20
- resolve(value);
21
- } else {
22
- Promise.resolve(value).then(_next, _throw);
23
- }
24
- }
25
-
26
- function _asyncToGenerator(fn) {
27
- return function () {
28
- var self = this,
29
- args = arguments;
30
- return new Promise(function (resolve, reject) {
31
- var gen = fn.apply(self, args);
32
-
33
- function _next(value) {
34
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
35
- }
36
-
37
- function _throw(err) {
38
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
39
- }
40
-
41
- _next(undefined);
42
- });
43
- };
44
- }
45
-
46
- function _extends() {
47
- _extends = Object.assign || function (target) {
48
- for (var i = 1; i < arguments.length; i++) {
49
- var source = arguments[i];
50
-
51
- for (var key in source) {
52
- if (Object.prototype.hasOwnProperty.call(source, key)) {
53
- target[key] = source[key];
54
- }
55
- }
56
- }
57
-
58
- return target;
59
- };
60
-
61
- return _extends.apply(this, arguments);
62
- }
63
-
64
- function _objectWithoutPropertiesLoose(source, excluded) {
65
- if (source == null) return {};
66
- var target = {};
67
- var sourceKeys = Object.keys(source);
68
- var key, i;
69
-
70
- for (i = 0; i < sourceKeys.length; i++) {
71
- key = sourceKeys[i];
72
- if (excluded.indexOf(key) >= 0) continue;
73
- target[key] = source[key];
74
- }
75
-
76
- return target;
77
- }
78
-
79
- function getColor(colorMode) {
80
- return function (light, dark, sepia) {
81
- switch (colorMode) {
82
- case 'day':
83
- return light;
84
-
85
- case 'night':
86
- return dark;
87
-
88
- case 'sepia':
89
- return sepia;
90
- }
91
- };
92
- }
93
-
94
- var useColorModeValue = function useColorModeValue(light, dark, sepia) {
95
- var _useTheme = useTheme(),
96
- currentColorMode = _useTheme.currentColorMode;
97
-
98
- var color = getColor(currentColorMode)(light, dark, sepia);
99
- return color;
100
- };
101
-
102
- var doc = document;
103
- var docElm = document.documentElement; // For Safari IOS: Only available on iPad, not on iPhone.
104
-
105
- var enterFullScreen = function enterFullScreen() {
106
- var fullScreenFunc = docElm.requestFullscreen || docElm.mozRequestFullScreen || docElm.webkitRequestFullscreen || docElm.msRequestFullscreen;
107
-
108
- if (typeof fullScreenFunc === 'function') {
109
- fullScreenFunc.call(docElm);
110
- }
111
- };
112
-
113
- var exitFullScreen = function exitFullScreen() {
114
- var exitFunc = doc.exitFullscreen || doc.mozCancelFullScreen || doc.webkitExitFullscreen || doc.msExitFullscreen;
115
-
116
- if (typeof exitFunc === 'function') {
117
- exitFunc.call(doc);
118
- }
119
- };
120
- /**
121
- * Toggles fullscreen mode on the <html> element.
122
- */
123
-
124
-
125
- function toggleFullScreen() {
126
- var isFullscreen = doc.fullscreenElement || doc.mozFullScreenElement || doc.webkitFullscreenElement || doc.msFullscreenElement;
127
-
128
- if (isFullscreen) {
129
- exitFullScreen();
130
- } else {
131
- enterFullScreen();
132
- }
133
- }
134
-
135
- var Button = /*#__PURE__*/React__default.forwardRef(function (props, ref) {
136
- return React__default.createElement(Button$1, Object.assign({
137
- ref: ref,
138
- variant: "solid"
139
- }, props));
140
- });
141
-
142
- var TextStyle = {
143
- // style object for base or default style
144
- baseStyle: {},
145
- // styles for different sizes ("sm", "md", "lg")
146
- sizes: {},
147
- // styles for different visual variants ("outline", "solid")
148
- variants: {
149
- headerNav: variantHeaderNav
150
- },
151
- // default values for `size`, `variant`, `colorScheme`
152
- defaultProps: {}
153
- };
154
-
155
- function variantHeaderNav() {
156
- return {
157
- pl: 2,
158
- my: 0,
159
- letterSpacing: 1,
160
- fontSize: 0,
161
- display: {
162
- sm: 'none',
163
- md: 'none',
164
- lg: 'inline-block'
165
- }
166
- };
167
- }
168
-
169
- var colors = {
170
- transparent: 'transparent',
171
- ui: {
172
- sepia: '#F9F4E9'
173
- }
174
- };
175
-
176
- var sizes = {
177
- lg: {
178
- h: 12,
179
- minW: 12,
180
- fontSize: 'lg',
181
- px: 6
182
- },
183
- md: {
184
- h: '38px',
185
- minW: 10,
186
- fontSize: 'sm',
187
- px: 2.5
188
- },
189
- sm: {
190
- h: 8,
191
- minW: 8,
192
- fontSize: 'sm',
193
- px: 3
194
- },
195
- xs: {
196
- h: 6,
197
- minW: 6,
198
- fontSize: 'xs',
199
- px: 2
200
- }
201
- };
202
- var ButtonStyle = {
203
- // style object for base or default style
204
- baseStyle: {
205
- borderRadius: 'sm',
206
- fontWeight: 'light'
207
- },
208
- // styles for different sizes ("sm", "md", "lg")
209
- sizes: sizes,
210
- // styles for different visual variants ("outline", "solid")
211
- variants: {
212
- pill: {
213
- border: '1px solid',
214
- borderColor: 'gray.200',
215
- borderRadius: '2xl',
216
- height: 6,
217
- px: 6,
218
- fontSize: '-1',
219
- my: 'auto'
220
- },
221
- solid: variantSolid,
222
- secondary: {
223
- border: '1px solid',
224
- borderColor: 'ui.gray.light-cool',
225
- _hover: {
226
- bg: 'ui.gray.x-light-cool',
227
- borderColor: 'ui.gray.medium'
228
- }
229
- }
230
- },
231
- // default values for `size`, `variant`, `colorScheme`
232
- defaultProps: {
233
- size: 'md',
234
- variant: 'solid',
235
- colorScheme: 'gray'
236
- }
237
- };
238
-
239
- function solidColors(colorScheme) {
240
- switch (colorScheme) {
241
- case 'gray':
242
- return {
243
- bg: 'gray.100',
244
- _hover: {
245
- bg: 'gray.200',
246
- _disabled: {
247
- bg: 'gray.100'
248
- }
249
- },
250
- _active: {
251
- bg: 'gray.300'
252
- }
253
- };
254
-
255
- case 'red':
256
- return {
257
- bg: 'brand.nypl-red',
258
- color: 'white',
259
- hoverBg: 'red.500',
260
- activeBg: 'red.600'
261
- };
262
-
263
- default:
264
- return {
265
- bg: colorScheme + ".500",
266
- color: 'white',
267
- hoverBg: colorScheme + ".600",
268
- activeBg: colorScheme + ".700"
269
- };
270
- }
271
- }
272
-
273
- function variantSolid(props) {
274
- var colors = solidColors(props.colorScheme);
275
- return _extends({}, colors, {
276
- _hover: {
277
- _disabled: {
278
- bg: 'ui.gray.light-cool',
279
- color: 'ui.gray.dark'
280
- }
281
- },
282
- _disabled: {
283
- bg: 'ui.gray.light-cool',
284
- color: 'ui.gray.dark'
285
- }
286
- });
287
- }
288
-
289
- // theme.js
290
- var breakpoints = /*#__PURE__*/createBreakpoints({
291
- sm: '20em',
292
- md: '38em',
293
- lg: '60em',
294
- xl: '80em',
295
- '2xl': '96em'
296
- });
297
-
298
- var typography = {
299
- fonts: {
300
- body: '-apple-system, BlinkMacSystemFont, system-ui, sans-serif',
301
- heading: '-apple-system, BlinkMacSystemFont, system-ui, sans-seri',
302
- mono: "Courier,SFMono-Regular,Menlo,Monaco,Consolas,\"Liberation Mono\",\"Courier New\",monospace"
303
- },
304
- fontSizes: {
305
- '-2': '0.75rem',
306
- '-1': '0.875rem',
307
- '0': '1rem',
308
- '1': '1.125rem',
309
- '2': '1.25rem',
310
- '3': '1.75rem',
311
- '4': '2.25rem',
312
- '5': '3rem'
313
- },
314
- fontWeights: {
315
- light: 300,
316
- regular: 400,
317
- medium: 500,
318
- bold: 700
319
- },
320
- lineHeights: [1, 1.1, 1.25, 1.5],
321
- letterSpacings: {
322
- tighter: '-0.05em',
323
- tight: '-0.025em',
324
- normal: '0',
325
- wide: '0.025em',
326
- wider: '0.05em',
327
- widest: '0.1em'
328
- }
329
- };
330
-
331
- var colors$1 = {
332
- transparent: 'transparent',
333
- // ui fills
334
- ui: {
335
- black: '#000',
336
- white: '#fff',
337
- focus: '#4181F1',
338
- link: {
339
- primary: '#0576D3',
340
- secondary: '#004B98'
341
- },
342
- success: {
343
- primary: '#077719',
344
- secondary: '#095212'
345
- },
346
- warning: {
347
- primary: '#F0974E',
348
- secondary: '#EC7B1F'
349
- },
350
- status: {
351
- primary: '#F9E08E',
352
- secondary: '#FBE7E1'
353
- },
354
- error: '#97272C',
355
- disabled: {
356
- primary: '#E0E0E0',
357
- secondary: '#FAFAFA'
358
- },
359
- test: '#FF6347',
360
- gray: {
361
- 'x-dark': '#424242',
362
- dark: '#616161',
363
- medium: '#BDBDBD',
364
- 'light-cool': '#E0E0E0',
365
- 'light-warm': '#EFEDEB',
366
- 'x-light-cool': '#F5F5F5',
367
- 'x-light-warm': '#F8F8F7',
368
- 'xx-light-cool': '#FAFAFA'
369
- }
370
- },
371
- // brand fills. Only primary and secondary filled in for now.
372
- brand: {
373
- primary: '#C60917',
374
- secondary: '#760000',
375
- 'nypl-red': '#D0343A'
376
- },
377
-
378
- /**
379
- * The following color scales are useful for color edge cases
380
- * where a distinct named ui or brand color doesn't quite work.
381
- */
382
- // based on ui/gray/medium
383
- gray: {
384
- '50': '#F2F2F2',
385
- '100': '#DBDBDB',
386
- '200': '#C4C4C4',
387
- '300': '#ADADAD',
388
- '400': '#969696',
389
- '500': '#808080',
390
- '600': '#666666',
391
- '700': '#4D4D4D',
392
- '800': '#333333',
393
- '900': '#1A1A1A'
394
- },
395
- // based on NYPL red
396
- red: {
397
- 50: '#ffe7e6',
398
- 100: '#f6c2bf',
399
- 200: '#e99796',
400
- 300: '#de6d6e',
401
- 400: '#d4454a',
402
- 500: '#ba2f2b',
403
- 600: '#922b21',
404
- 700: '#692216',
405
- 800: '#41150a',
406
- 900: '#1d0a01'
407
- },
408
- // based on ui/warning/secondary
409
- orange: {
410
- '50': '#FDF1E7',
411
- '100': '#F9D8BD',
412
- '200': '#F6BF93',
413
- '300': '#F2A669',
414
- '400': '#EF8D3E',
415
- '500': '#EB7414',
416
- '600': '#BC5D10',
417
- '700': '#8D460C',
418
- '800': '#5E2F08',
419
- '900': '#2F1704'
420
- },
421
- // based on ui/status/primary
422
- yellow: {
423
- '50': '#FEF8E7',
424
- '100': '#FBECBB',
425
- '200': '#F9E090',
426
- '300': '#F7D464',
427
- '400': '#F4C938',
428
- '500': '#F2BD0D',
429
- '600': '#C2970A',
430
- '700': '#917108',
431
- '800': '#614B05',
432
- '900': '#302603'
433
- },
434
- // based on ui/success/primary
435
- green: {
436
- '50': '#E7FEEB',
437
- '100': '#BCFBC6',
438
- '200': '#90F8A1',
439
- '300': '#65F67C',
440
- '400': '#3AF357',
441
- '500': '#0EF133',
442
- '600': '#0BC128',
443
- '700': '#08911E',
444
- '800': '#066014',
445
- '900': '#03300A'
446
- },
447
- // based on NYPL blue
448
- blue: {
449
- 50: '#dbefff',
450
- 100: '#add2ff',
451
- 200: '#7cb8ff',
452
- 300: '#4aa2ff',
453
- 400: '#1a8fff',
454
- 500: '#007ee6',
455
- 600: '#0056b4',
456
- 700: '#003582',
457
- 800: '#001a51',
458
- 900: '#000621'
459
- }
460
- };
461
-
462
- var radii = {
463
- none: '0',
464
- sm: '0.125rem',
465
- base: '0.25rem',
466
- md: '0.375rem',
467
- lg: '0.5rem',
468
- xl: '0.75rem',
469
- '2xl': '1rem',
470
- '3xl': '1.5rem',
471
- full: '9999px'
472
- };
473
-
474
- /**
475
- * A comprehensive spacin scale based on NYPL Design System,
476
- * with intermediate values interpolated. Those marked with comments
477
- * are directly from the NYPL DS.
478
- *
479
- * 1 spacing unit is 4px or 0.25rem.
480
- *
481
- * Mental model: If you need a spacing of 40px, divide it by 4.
482
- * That'll give you 10. Then use it in your component.
483
- */
484
- var spacing = {
485
- space: {
486
- px: '1px',
487
- 0: '0',
488
- 0.5: '0.125rem',
489
- // 4px
490
- 1: '0.25rem',
491
- 1.5: '0.375rem',
492
- // 8px
493
- 2: '0.5rem',
494
- 2.5: '0.625rem',
495
- 3: '0.75rem',
496
- 3.5: '0.875rem',
497
- // 16px
498
- 4: '1rem',
499
- 5: '1.25rem',
500
- // 24px
501
- 6: '1.5rem',
502
- 7: '1.75rem',
503
- // 32 px
504
- 8: '2rem',
505
- 9: '2.25rem',
506
- 10: '2.5rem',
507
- // 48px
508
- 12: '3rem',
509
- 14: '3.5rem',
510
- // 64px
511
- 16: '4rem',
512
- 20: '5rem',
513
- // 96px
514
- 24: '6rem',
515
- 28: '7rem',
516
- 32: '8rem',
517
- 36: '9rem',
518
- 40: '10rem',
519
- 44: '11rem',
520
- 48: '12rem',
521
- 52: '13rem',
522
- 56: '14rem',
523
- 60: '15rem',
524
- 64: '16rem',
525
- 72: '18rem',
526
- 80: '20rem',
527
- 96: '24rem'
528
- }
529
- };
530
-
531
- var baseStyleLabel = {
532
- userSelect: 'none',
533
- fontWeight: 'light',
534
- _disabled: {
535
- color: 'ui.gray.x-dark',
536
- opacity: 1
537
- }
538
- };
539
- var Checkbox = {
540
- // style object for base or default style
541
- baseStyle: {
542
- control: {
543
- borderColor: 'ui.gray.dark',
544
- _hover: {
545
- bg: 'white',
546
- _disabled: {
547
- bg: 'ui.gray.x-light-cool'
548
- }
549
- },
550
- _checked: {
551
- bg: 'white',
552
- color: 'gray.800',
553
- borderColor: 'ui.gray.dark',
554
- _hover: {
555
- bg: 'white',
556
- borderColor: 'ui.gray.x-dark'
557
- }
558
- },
559
- _disabled: {
560
- bg: 'ui.gray.x-light-cool',
561
- borderColor: 'ui.gray.medium'
562
- }
563
- },
564
- label: baseStyleLabel
565
- },
566
- // styles for different sizes ("sm", "md", "lg")
567
- sizes: {},
568
- // styles for different visual variants ("outline", "solid")
569
- variants: {},
570
- // default values for `size`, `variant`, `colorScheme`
571
- defaultProps: {
572
- size: 'md',
573
- colorScheme: 'gray'
574
- }
575
- };
576
-
577
- var size = {
578
- lg: {
579
- fontSize: 'lg',
580
- px: 4,
581
- h: 12,
582
- borderRadius: 'none'
583
- },
584
- md: {
585
- fontSize: 'sm',
586
- px: 4,
587
- h: 9,
588
- borderRadius: 'none'
589
- },
590
- sm: {
591
- fontSize: 'sm',
592
- px: 3,
593
- h: 8,
594
- borderRadius: 'none'
595
- },
596
- xs: {
597
- fontSize: 'xs',
598
- px: 2,
599
- h: 6,
600
- borderRadius: 'none'
601
- }
602
- };
603
- var sizes$1 = {
604
- lg: {
605
- field: size.lg,
606
- addon: size.lg
607
- },
608
- md: {
609
- field: size.md,
610
- addon: size.md
611
- },
612
- sm: {
613
- field: size.sm,
614
- addon: size.sm
615
- },
616
- xs: {
617
- field: size.xs,
618
- addon: size.xs
619
- }
620
- };
621
- var Input = {
622
- // style object for base or default style
623
- baseStyle: {
624
- field: {
625
- borderRadius: 'none',
626
- fontSize: 'sm',
627
- _focus: {
628
- borderColor: 'ui.link.primary',
629
- _hover: {
630
- borderColor: 'ui.link.primary'
631
- }
632
- },
633
- _placeholder: {
634
- fontStyle: 'italic',
635
- color: 'ui.gray.dark'
636
- },
637
- _invalid: {
638
- borderColor: 'ui.error',
639
- _placeholder: {
640
- color: 'ui.error'
641
- },
642
- _hover: {
643
- borderColor: 'ui.error'
644
- }
645
- }
646
- }
647
- },
648
- // styles for different sizes ("sm", "md", "lg")
649
- sizes: sizes$1,
650
- // styles for different visual variants ("outline", "solid")
651
- variants: {
652
- outline: {
653
- field: {
654
- _disabled: {
655
- bg: 'ui.gray.xx-light-cool'
656
- },
657
- _focus: {
658
- boxShadow: 'none',
659
- _hover: {
660
- borderColor: 'ui.link.primary'
661
- }
662
- },
663
- _invalid: {
664
- boxShadow: 'none'
665
- }
666
- }
667
- }
668
- },
669
- // default values for `size`, `variant`, `colorScheme`
670
- defaultProps: {
671
- size: 'md'
672
- }
673
- };
674
-
675
- var global = {
676
- // styles for the `body`
677
- body: {
678
- bg: 'white',
679
- color: 'black'
680
- },
681
- // styles for the `a`
682
- a: {
683
- color: 'ui.link.primary',
684
- _hover: {
685
- textDecoration: 'underline'
686
- }
687
- }
688
- };
689
-
690
- var baseStyle = {
691
- fontSize: 'sm',
692
- marginEnd: 0,
693
- mb: 2,
694
- fontWeight: 'medium',
695
- transition: 'all 0.2s',
696
- opacity: 1,
697
- _disabled: {
698
- opacity: 1
699
- }
700
- };
701
- var FormLabel = {
702
- baseStyle: baseStyle
703
- };
704
-
705
- var baseStyle$1 = {
706
- requiredIndicator: {
707
- marginStart: 1,
708
- color: 'red.500'
709
- },
710
- helperText: {
711
- mt: 2,
712
- color: 'black',
713
- lineHeight: 'normal',
714
- fontSize: 'xs'
715
- }
716
- };
717
- var Form = {
718
- baseStyle: baseStyle$1
719
- };
720
-
721
- var baseStyle$2 = {
722
- text: {
723
- color: 'ui.error',
724
- mt: 2,
725
- fontSize: 'xs'
726
- },
727
- icon: {
728
- marginEnd: '0.5em',
729
- color: 'ui.error'
730
- }
731
- };
732
- var FormError = {
733
- baseStyle: baseStyle$2
734
- };
735
-
736
- var sizes$2 = {
737
- xs: Input.sizes.xs.field,
738
- sm: Input.sizes.sm.field,
739
- md: Input.sizes.md.field,
740
- lg: Input.sizes.lg.field
741
- };
742
- var Textarea = {
743
- baseStyle: {
744
- _disabled: {
745
- bg: 'ui.gray.x-light-cool'
746
- }
747
- },
748
- sizes: sizes$2
749
- };
750
-
751
- /**
752
- * See Chakra default theme for shape of theme object:
753
- * https://github.com/chakra-ui/chakra-ui/tree/main/packages/theme
754
- */
755
-
756
- var theme = /*#__PURE__*/extendTheme( /*#__PURE__*/_extends({
757
- styles: {
758
- global: global
759
- },
760
- breakpoints: breakpoints,
761
- radii: radii,
762
- colors: colors$1
763
- }, typography, {
764
- space: spacing,
765
-
766
- /**
767
- * Chakra documentation on component styles:
768
- * https://chakra-ui.com/docs/theming/component-style
769
- */
770
- components: {
771
- Button: ButtonStyle,
772
- Checkbox: Checkbox,
773
- Input: Input,
774
- FormLabel: FormLabel,
775
- Form: Form,
776
- FormError: FormError,
777
- Textarea: Textarea
778
- }
779
- }));
780
-
781
- var getButtonStyle = function getButtonStyle(getColor) {
782
- return {
783
- // style object for base or default style
784
- baseStyle: {
785
- borderRadius: 'none'
786
- },
787
- // styles for different sizes ("sm", "md", "lg")
788
- sizes: {},
789
- // styles for different visual variants ("outline", "solid")
790
- variants: {
791
- solid: variantSolid$1(getColor),
792
- toggle: variantToggle(getColor)
793
- },
794
- // default values for `size`, `variant`, `colorScheme`
795
- defaultProps: {
796
- size: 'sm',
797
- variant: 'solid'
798
- }
799
- };
800
- };
801
- /* Color Schemes:
802
- ** Light, Sepia, Dark
803
- * States:
804
- ** Normal
805
- ** Selected
806
- ** Disabled
807
- ** Hovered
808
- */
809
-
810
-
811
- var variantSolid$1 = function variantSolid(getColor) {
812
- return function (props) {
813
- var bgColor = getColor('ui.white', 'ui.black', 'ui.sepia');
814
- var color = getColor('gray.800', 'ui.white', 'gray.800');
815
- var _focus = {
816
- bgColor: bgColor,
817
- color: color
818
- };
819
- var _hover = {
820
- bgColor: bgColor,
821
- color: color,
822
- _disabled: {
823
- bgColor: bgColor
824
- }
825
- };
826
- var _active = {
827
- bgColor: bgColor,
828
- color: color
829
- };
830
- var _checked = {
831
- bgColor: bgColor,
832
- color: color
833
- };
834
- var _disabled = {
835
- bgColor: bgColor
836
- };
837
- return {
838
- border: '1px solid',
839
- borderColor: 'gray.100',
840
- transition: 'none',
841
- fontSize: 0,
842
- letterSpacing: 1,
843
- textTransform: 'uppercase',
844
- maxWidth: '100%',
845
- cursor: 'pointer',
846
- bgColor: bgColor,
847
- color: color,
848
- _focus: _focus,
849
- _hover: _hover,
850
- _active: _active,
851
- _checked: _checked,
852
- _disabled: _disabled
853
- };
854
- };
855
- };
856
-
857
- var variantToggle = function variantToggle(getColor) {
858
- return function (props) {
859
- var bgColor = getColor('ui.white', 'gray.800', 'ui.white');
860
- var color = getColor('gray.800', 'ui.white', 'gray.800');
861
- return _extends({}, variantSolid$1(getColor)(props), {
862
- bgColor: bgColor,
863
- color: color,
864
- px: 8,
865
- fontWeight: 'medium',
866
- fontSize: -2,
867
- _focus: {
868
- bgColor: bgColor
869
- },
870
- _hover: {
871
- bgColor: bgColor
872
- },
873
- _active: {
874
- bgColor: bgColor
875
- },
876
- _checked: {
877
- color: 'ui.white',
878
- bgColor: 'green.700'
879
- }
880
- });
881
- };
882
- };
883
-
884
- /**
885
- * See Chakra default theme for shape of theme object:
886
- * https://github.com/chakra-ui/chakra-ui/tree/main/packages/theme
887
- *
888
- * Making this a function because we need to adjust the theme based
889
- * on the colorMode that's being passed in.
890
- *
891
- * Returns the chakra theme object with an additional property `currentColorMode`
892
- */
893
-
894
- function getTheme(colorMode) {
895
- return extendTheme({
896
- colors: colors,
897
-
898
- /**
899
- * Chakra documentation on component styles:
900
- * https://chakra-ui.com/docs/theming/component-style
901
- */
902
- components: {
903
- Button: getButtonStyle(getColor(colorMode)),
904
- Text: TextStyle
905
- },
906
- currentColorMode: colorMode
907
- }, theme);
908
- }
909
-
910
- function ToggleButton(props) {
911
- var isChecked = props.isChecked,
912
- children = props.children,
913
- colorMode = props.colorMode,
914
- rest = _objectWithoutPropertiesLoose(props, ["isChecked", "children", "colorMode"]);
915
-
916
- var _useRadio = useRadio(props),
917
- getInputProps = _useRadio.getInputProps,
918
- getCheckboxProps = _useRadio.getCheckboxProps;
919
-
920
- var input = getInputProps();
921
- var checkbox = getCheckboxProps();
922
- var theme = useTheme$1();
923
- return (// This will override the default theme if we specify the colorMode to the toggle button.
924
- React__default.createElement(ThemeProvider, {
925
- theme: getTheme(colorMode != null ? colorMode : theme.currentColorMode)
926
- }, React__default.createElement(Box, {
927
- as: "label",
928
- d: "flex",
929
- flexGrow: 1
930
- }, React__default.createElement("input", Object.assign({}, input)), React__default.createElement(Button, Object.assign({
931
- as: "div"
932
- }, checkbox, {
933
- variant: "toggle"
934
- }, rest, {
935
- flexGrow: 1
936
- }), children, isChecked && React__default.createElement(Circle, {
937
- position: "absolute",
938
- verticalAlign: "middle",
939
- right: 2,
940
- top: "50%",
941
- transform: "translateY(-50%)",
942
- borderColor: "white",
943
- border: "1px solid",
944
- size: "15px",
945
- alignItems: "baseline"
946
- }, React__default.createElement(Icon, {
947
- decorative: true,
948
- name: IconNames.check,
949
- modifiers: ['small']
950
- })))))
951
- );
952
- }
953
-
954
- var ToggleGroup = function ToggleGroup(_ref) {
955
- var value = _ref.value,
956
- label = _ref.label,
957
- name = _ref.name,
958
- children = _ref.children,
959
- onChange = _ref.onChange;
960
-
961
- var _useRadioGroup = useRadioGroup({
962
- name: name,
963
- onChange: onChange,
964
- value: value
965
- }),
966
- getRootProps = _useRadioGroup.getRootProps,
967
- getRadioProps = _useRadioGroup.getRadioProps;
968
-
969
- var group = getRootProps();
970
- return React__default.createElement(Flex, Object.assign({}, group, {
971
- "aria-label": label,
972
- flex: "1 0 auto",
973
- flexWrap: "wrap",
974
- my: 2
975
- }), React__default.Children.map(children, function (element) {
976
- try {
977
- var _value = element.props.value;
978
- var radio = getRadioProps({
979
- value: _value
980
- });
981
- return React__default.cloneElement(element, radio);
982
- } catch (e) {
983
- throw new Error('ToggleGroup expects ToggleButton children with `value` props.');
984
- }
985
- }));
986
- };
987
-
988
- function PdfSettings(props) {
989
- var navigator = props.navigator,
990
- readerState = props.readerState,
991
- paginationValue = props.paginationValue;
992
- var fontFamily = readerState.fontFamily;
993
- var setFontFamily = navigator.setFontFamily,
994
- decreaseFontSize = navigator.decreaseFontSize,
995
- increaseFontSize = navigator.increaseFontSize,
996
- setScroll = navigator.setScroll;
997
- return createElement(Fragment, null, createElement(ToggleGroup, {
998
- value: fontFamily,
999
- label: "text font options",
1000
- onChange: setFontFamily
1001
- }, createElement(ToggleButton, {
1002
- value: "publisher"
1003
- }, "Publisher"), createElement(ToggleButton, {
1004
- value: "serif"
1005
- }, "Serif"), createElement(ToggleButton, {
1006
- value: "sans-serif"
1007
- }, "Sans-Serif"), createElement(ToggleButton, {
1008
- value: "open-dyslexic"
1009
- }, "Dyslexia-Friendly")), createElement(ButtonGroup, {
1010
- d: "flex",
1011
- spacing: 0
1012
- }, createElement(Button, {
1013
- flexGrow: 1,
1014
- "aria-label": "Zoom In",
1015
- onClick: decreaseFontSize,
1016
- variant: "toggle"
1017
- }, "Zoom", createElement(Circle, {
1018
- border: "1px solid",
1019
- p: 1,
1020
- ml: 1,
1021
- size: "17px",
1022
- alignItems: "baseline"
1023
- }, createElement(Icon, {
1024
- decorative: true,
1025
- name: IconNames.minus,
1026
- modifiers: ['small']
1027
- }), ' ')), createElement(Button, {
1028
- flexGrow: 1,
1029
- "aria-label": "Zoom Out",
1030
- onClick: increaseFontSize,
1031
- variant: "toggle"
1032
- }, "Zoom", createElement(Circle, {
1033
- border: "1px solid",
1034
- p: 1,
1035
- ml: 1,
1036
- size: "17px",
1037
- alignItems: "baseline"
1038
- }, createElement(Icon, {
1039
- decorative: true,
1040
- name: IconNames.plus,
1041
- modifiers: ['small']
1042
- }), ' '))), createElement(ToggleGroup, {
1043
- onChange: setScroll,
1044
- value: paginationValue,
1045
- label: "pagination options"
1046
- }, createElement(ToggleButton, {
1047
- value: "paginated"
1048
- }, "Paginated"), createElement(ToggleButton, {
1049
- value: "scrolling"
1050
- }, "Scrolling")));
1051
- }
1052
-
1053
- function HtmlSettings(props) {
1054
- var navigator = props.navigator,
1055
- readerState = props.readerState,
1056
- paginationValue = props.paginationValue;
1057
- var fontFamily = readerState.fontFamily,
1058
- colorMode = readerState.colorMode;
1059
- var setFontFamily = navigator.setFontFamily,
1060
- decreaseFontSize = navigator.decreaseFontSize,
1061
- increaseFontSize = navigator.increaseFontSize,
1062
- setColorMode = navigator.setColorMode,
1063
- setScroll = navigator.setScroll;
1064
- return createElement(Fragment, null, createElement(ToggleGroup, {
1065
- value: fontFamily,
1066
- label: "text font options",
1067
- onChange: setFontFamily
1068
- }, createElement(ToggleButton, {
1069
- value: "publisher"
1070
- }, "Publisher"), createElement(ToggleButton, {
1071
- value: "serif"
1072
- }, "Serif"), createElement(ToggleButton, {
1073
- value: "sans-serif"
1074
- }, "Sans-Serif"), createElement(ToggleButton, {
1075
- value: "open-dyslexic"
1076
- }, "Dyslexia-Friendly")), createElement(ButtonGroup, {
1077
- d: "flex",
1078
- spacing: 0
1079
- }, createElement(Button, {
1080
- flexGrow: 1,
1081
- "aria-label": "Decrease font size",
1082
- onClick: decreaseFontSize,
1083
- variant: "toggle"
1084
- }, "A-"), createElement(Button, {
1085
- flexGrow: 1,
1086
- "aria-label": "Increase font size",
1087
- onClick: increaseFontSize,
1088
- variant: "toggle"
1089
- }, "A+")), createElement(ToggleGroup, {
1090
- value: colorMode,
1091
- label: "reading theme options",
1092
- onChange: setColorMode
1093
- }, createElement(ToggleButton, {
1094
- colorMode: "day",
1095
- value: "day",
1096
- _checked: {
1097
- bg: 'ui.white'
1098
- }
1099
- }, "Day"), createElement(ToggleButton, {
1100
- colorMode: "sepia",
1101
- value: "sepia",
1102
- bg: "ui.sepia" // distinct case where default needs to be sepia
1103
- ,
1104
- _active: {
1105
- bg: 'ui.sepia'
1106
- },
1107
- _hover: {
1108
- bg: 'ui.sepia'
1109
- },
1110
- _checked: {
1111
- bg: 'ui.sepia'
1112
- }
1113
- }, "Sepia"), createElement(ToggleButton, {
1114
- colorMode: "night",
1115
- value: "night",
1116
- _checked: {
1117
- bg: 'ui.black'
1118
- }
1119
- }, "Night")), createElement(ToggleGroup, {
1120
- onChange: setScroll,
1121
- value: paginationValue,
1122
- label: "pagination options"
1123
- }, createElement(ToggleButton, {
1124
- value: "paginated"
1125
- }, "Paginated"), createElement(ToggleButton, {
1126
- value: "scrolling"
1127
- }, "Scrolling")));
1128
- }
1129
-
1130
- function SettingsCard(props) {
1131
- var _React$useState = useState(false),
1132
- isOpen = _React$useState[0],
1133
- setIsOpen = _React$useState[1];
1134
-
1135
- var open = function open() {
1136
- return setIsOpen(!isOpen);
1137
- };
1138
-
1139
- var close = function close() {
1140
- return setIsOpen(false);
1141
- };
1142
-
1143
- var navigator = props.navigator,
1144
- state = props.state,
1145
- type = props.type;
1146
- var paginationValue = state != null && state.isScrolling ? 'scrolling' : 'paginated';
1147
- var contentBgColor = useColorModeValue('ui.white', 'ui.black', 'ui.white');
1148
- return createElement(Fragment, null, createElement(Popover, {
1149
- placement: "bottom",
1150
- isOpen: isOpen,
1151
- onClose: close,
1152
- autoFocus: true
1153
- }, createElement(PopoverTrigger, null, createElement(Button, {
1154
- onClick: open,
1155
- border: "none"
1156
- }, createElement(Icon, {
1157
- decorative: true,
1158
- name: IconNames.plus,
1159
- modifiers: ['small']
1160
- }), ' ', createElement(Text, {
1161
- variant: "headerNav"
1162
- }, "Settings"))), createElement(PopoverContent, {
1163
- borderColor: "gray.100",
1164
- width: "fit-content",
1165
- bgColor: contentBgColor
1166
- }, createElement(PopoverBody, {
1167
- p: 0,
1168
- maxWidth: "95vw"
1169
- }, type === 'PDF' && createElement(PdfSettings, {
1170
- navigator: navigator,
1171
- readerState: state,
1172
- paginationValue: paginationValue
1173
- }), type === 'HTML' && createElement(HtmlSettings, {
1174
- navigator: navigator,
1175
- readerState: state,
1176
- paginationValue: paginationValue
1177
- })))));
1178
- }
1179
-
1180
- // we have to set a constant height to make this work with R2D2BC
1181
- var HEADER_HEIGHT = 48;
1182
-
1183
- var TocItem = function TocItem(props) {
1184
- var href = props.href,
1185
- title = props.title,
1186
- isActive = props.isActive,
1187
- rest = _objectWithoutPropertiesLoose(props, ["href", "title", "isActive"]);
1188
-
1189
- var bgColor = useColorModeValue('ui.white', 'ui.black', 'ui.sepia');
1190
- var color = useColorModeValue('ui.black', 'ui.white', 'ui.black');
1191
- var borderColor = useColorModeValue('ui.gray.medium', 'gray.500', 'yellow.600');
1192
- var activeColor = 'ui.black';
1193
- var activeBgColor = 'ui.gray.light-cool';
1194
- var _hover = {
1195
- textDecoration: 'none',
1196
- background: isActive ? 'ui.black' : 'ui.gray.x-dark',
1197
- color: 'ui.white'
1198
- };
1199
-
1200
- var _focus = _extends({}, _hover, {
1201
- boxShadow: 'none'
1202
- });
1203
-
1204
- var styles = {
1205
- background: isActive ? activeBgColor : bgColor,
1206
- color: isActive ? activeColor : color,
1207
- borderBottom: "1px solid",
1208
- borderColor: borderColor,
1209
- py: 3,
1210
- _hover: _hover,
1211
- _focus: _focus
1212
- };
1213
- return React__default.createElement(MenuItem, Object.assign({
1214
- as: Link,
1215
- href: href
1216
- }, styles, rest), title);
1217
- };
1218
-
1219
- function TableOfContent(_ref) {
1220
- var navigator = _ref.navigator,
1221
- manifest = _ref.manifest,
1222
- readerState = _ref.readerState;
1223
-
1224
- var _useState = useState(false),
1225
- isOpen = _useState[0],
1226
- setIsOpen = _useState[1];
1227
-
1228
- var tocLinkHandler = function tocLinkHandler(evt) {
1229
- evt.preventDefault();
1230
- var href = evt.currentTarget.getAttribute('href');
1231
-
1232
- if (!href) {
1233
- console.warn('TOC Link clicked without an href');
1234
- return;
1235
- }
1236
-
1237
- navigator.goToPage(href);
1238
- setIsOpen(false);
1239
- };
1240
-
1241
- var tocBgColor = useColorModeValue('ui.white', 'ui.black', 'ui.sepia');
1242
-
1243
- var getLinkHref = function getLinkHref(link) {
1244
- if (link.href) return link.href;
1245
- if (!link.children) throw new Error('Manifest is not well formed');
1246
- return getLinkHref(link.children[0]);
1247
- };
1248
-
1249
- return React__default.createElement(Menu, {
1250
- onOpen: function onOpen() {
1251
- return setIsOpen(true);
1252
- },
1253
- onClose: function onClose() {
1254
- return setIsOpen(false);
1255
- }
1256
- }, React__default.createElement(MenuButton, {
1257
- as: Button,
1258
- border: "none"
1259
- }, React__default.createElement(Icon, {
1260
- decorative: true,
1261
- name: IconNames.download,
1262
- modifiers: ['small']
1263
- }), React__default.createElement(Text, {
1264
- variant: "headerNav"
1265
- }, "Table of Contents")), isOpen && (manifest == null ? void 0 : manifest.toc) && React__default.createElement(Portal, null, React__default.createElement(MenuList, {
1266
- width: "100vw",
1267
- height: "calc(100vh - " + HEADER_HEIGHT + "px)",
1268
- background: tocBgColor,
1269
- borderRadius: "none",
1270
- borderColor: tocBgColor,
1271
- zIndex: "popover",
1272
- px: 7,
1273
- mt: "-2px" // Move the popover slightly higher to hide Header border
1274
- ,
1275
- overflow: "auto"
1276
- }, manifest.toc.map(function (content) {
1277
- return React__default.createElement(React__default.Fragment, {
1278
- key: content.title
1279
- }, React__default.createElement(TocItem, {
1280
- href: getLinkHref(content),
1281
- title: content.title,
1282
- isActive: (readerState == null ? void 0 : readerState.currentTocUrl) === content.href,
1283
- onClick: tocLinkHandler
1284
- }), content.children && content.children.map(function (subLink) {
1285
- return React__default.createElement(TocItem, {
1286
- key: subLink.title,
1287
- href: getLinkHref(subLink),
1288
- title: subLink.title,
1289
- isActive: (readerState == null ? void 0 : readerState.currentTocUrl) === subLink.href,
1290
- onClick: tocLinkHandler,
1291
- pl: 10
1292
- });
1293
- }));
1294
- }))));
1295
- }
1296
-
1297
- function Header(props) {
1298
- var headerLeft = props.headerLeft,
1299
- state = props.state,
1300
- navigator = props.navigator,
1301
- manifest = props.manifest;
1302
- var linkColor = useColorModeValue('gray.700', 'gray.100', 'gray.700');
1303
- var mainBgColor = useColorModeValue('ui.white', 'ui.black', 'ui.sepia'); // Add custom styles to the NYPL Icon
1304
-
1305
- var ChakraIcon = chakra(Icon, {
1306
- baseStyle: {
1307
- height: '100%'
1308
- }
1309
- });
1310
- return React__default.createElement(Flex, {
1311
- as: "header",
1312
- position: "sticky",
1313
- top: 0,
1314
- left: 0,
1315
- right: 0,
1316
- height: HEADER_HEIGHT + "px",
1317
- zIndex: "sticky",
1318
- alignContent: "space-between",
1319
- alignItems: "center",
1320
- px: 8,
1321
- borderBottom: "1px solid",
1322
- borderColor: "gray.100",
1323
- bgColor: mainBgColor
1324
- }, headerLeft ? headerLeft : React__default.createElement(Link, {
1325
- href: "https://www.nypl.org",
1326
- "aria-label": "Return to NYPL",
1327
- tabIndex: 0,
1328
- fontSize: 0,
1329
- py: 1,
1330
- textTransform: "uppercase",
1331
- d: "flex",
1332
- color: linkColor,
1333
- height: "100%",
1334
- alignItems: "center",
1335
- _hover: {
1336
- textDecoration: 'none'
1337
- }
1338
- }, React__default.createElement(ChakraIcon, {
1339
- decorative: true,
1340
- name: LogoNames.logo_nypl,
1341
- modifiers: ['xlarge']
1342
- }), React__default.createElement(Text, {
1343
- variant: "headerNav"
1344
- }, "Return to NYPL")), React__default.createElement(HStack, {
1345
- ml: "auto",
1346
- spacing: 1
1347
- }, React__default.createElement(TableOfContent, {
1348
- navigator: navigator,
1349
- manifest: manifest,
1350
- readerState: state
1351
- }), React__default.createElement(SettingsCard, Object.assign({}, props)), React__default.createElement(Button, {
1352
- border: "none",
1353
- onClick: toggleFullScreen
1354
- }, React__default.createElement(Icon, {
1355
- decorative: true,
1356
- name: IconNames.search,
1357
- modifiers: ['small']
1358
- }), React__default.createElement(Text, {
1359
- variant: "headerNav"
1360
- }, "Toggle Fullscreen"))));
1361
- }
1362
-
1363
- function PageButton(props) {
1364
- var children = props.children,
1365
- onClick = props.onClick,
1366
- rest = _objectWithoutPropertiesLoose(props, ["children", "onClick"]);
1367
-
1368
- var circleColor = useColorModeValue('ui.black', 'ui.white', 'ui.black');
1369
- var circleBgColor = useColorModeValue('ui.white', 'gray.700', 'ui.white');
1370
- return React__default.createElement(Circle, Object.assign({
1371
- as: "button",
1372
- d: "flex",
1373
- position: "fixed",
1374
- zIndex: "docked",
1375
- alignItems: "center",
1376
- border: "1px solid",
1377
- borderColor: "ui.gray.light-cool",
1378
- color: circleColor,
1379
- bg: circleBgColor,
1380
- size: {
1381
- sm: '40px',
1382
- md: '50px'
1383
- },
1384
- mx: {
1385
- sm: 2,
1386
- md: 6
1387
- },
1388
- top: "50%",
1389
- cursor: "pointer",
1390
- onClick: onClick
1391
- }, rest), children);
1392
- }
1393
-
1394
- /**
1395
- * The default Manager UI. This will be broken into individual components
1396
- * that can be imported and used separately or in a customized setup.
1397
- * It takes the return value of useWebReader as props
1398
- */
1399
-
1400
- var ManagerUI = function ManagerUI(props) {
1401
- var _props$state$colorMod, _props$state;
1402
-
1403
- return createElement(ThemeProvider, {
1404
- theme: getTheme((_props$state$colorMod = (_props$state = props.state) == null ? void 0 : _props$state.colorMode) != null ? _props$state$colorMod : 'day')
1405
- }, createElement(WebReaderContent, Object.assign({}, props)));
1406
- };
1407
-
1408
- var WebReaderContent = function WebReaderContent(_ref) {
1409
- var _props$navigator, _props$navigator2;
1410
-
1411
- var children = _ref.children,
1412
- props = _objectWithoutPropertiesLoose(_ref, ["children"]);
1413
-
1414
- var bgColor = useColorModeValue('ui.white', 'ui.black', 'ui.sepia');
1415
- return createElement(Flex, {
1416
- flexDir: "column",
1417
- minHeight: "100vh",
1418
- w: "100vw"
1419
- }, !props.isLoading && createElement(Header, Object.assign({}, props)), createElement(PageButton, {
1420
- onClick: (_props$navigator = props.navigator) == null ? void 0 : _props$navigator.goBackward,
1421
- left: 0,
1422
- pr: 2,
1423
- "aria-label": "Previous Page"
1424
- }, createElement(Icon, {
1425
- decorative: true,
1426
- name: IconNames.arrow,
1427
- modifiers: ['small'],
1428
- iconRotation: IconRotationTypes.rotate90
1429
- })), createElement(Flex, {
1430
- width: "100vw",
1431
- bg: bgColor,
1432
- // accounting for the prev/next buttons
1433
- px: {
1434
- sm: 10,
1435
- md: '5vw'
1436
- },
1437
- flexDir: "column",
1438
- alignItems: "stretch",
1439
- flex: "1 1 100%"
1440
- }, children), createElement(PageButton, {
1441
- onClick: (_props$navigator2 = props.navigator) == null ? void 0 : _props$navigator2.goForward,
1442
- right: 0,
1443
- pl: 2,
1444
- "aria-label": "Next Page"
1445
- }, createElement(Icon, {
1446
- decorative: true,
1447
- name: IconNames.arrow,
1448
- modifiers: ['small'],
1449
- iconRotation: IconRotationTypes.rotate270
1450
- })));
1451
- };
1452
-
1453
- function createCommonjsModule(fn, module) {
1454
- return module = { exports: {} }, fn(module, module.exports), module.exports;
1455
- }
1456
-
1457
- var runtime_1 = createCommonjsModule(function (module) {
1458
- /**
1459
- * Copyright (c) 2014-present, Facebook, Inc.
1460
- *
1461
- * This source code is licensed under the MIT license found in the
1462
- * LICENSE file in the root directory of this source tree.
1463
- */
1464
-
1465
- var runtime = (function (exports) {
1466
-
1467
- var Op = Object.prototype;
1468
- var hasOwn = Op.hasOwnProperty;
1469
- var undefined$1; // More compressible than void 0.
1470
- var $Symbol = typeof Symbol === "function" ? Symbol : {};
1471
- var iteratorSymbol = $Symbol.iterator || "@@iterator";
1472
- var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
1473
- var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
1474
-
1475
- function define(obj, key, value) {
1476
- Object.defineProperty(obj, key, {
1477
- value: value,
1478
- enumerable: true,
1479
- configurable: true,
1480
- writable: true
1481
- });
1482
- return obj[key];
1483
- }
1484
- try {
1485
- // IE 8 has a broken Object.defineProperty that only works on DOM objects.
1486
- define({}, "");
1487
- } catch (err) {
1488
- define = function(obj, key, value) {
1489
- return obj[key] = value;
1490
- };
1491
- }
1492
-
1493
- function wrap(innerFn, outerFn, self, tryLocsList) {
1494
- // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
1495
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
1496
- var generator = Object.create(protoGenerator.prototype);
1497
- var context = new Context(tryLocsList || []);
1498
-
1499
- // The ._invoke method unifies the implementations of the .next,
1500
- // .throw, and .return methods.
1501
- generator._invoke = makeInvokeMethod(innerFn, self, context);
1502
-
1503
- return generator;
1504
- }
1505
- exports.wrap = wrap;
1506
-
1507
- // Try/catch helper to minimize deoptimizations. Returns a completion
1508
- // record like context.tryEntries[i].completion. This interface could
1509
- // have been (and was previously) designed to take a closure to be
1510
- // invoked without arguments, but in all the cases we care about we
1511
- // already have an existing method we want to call, so there's no need
1512
- // to create a new function object. We can even get away with assuming
1513
- // the method takes exactly one argument, since that happens to be true
1514
- // in every case, so we don't have to touch the arguments object. The
1515
- // only additional allocation required is the completion record, which
1516
- // has a stable shape and so hopefully should be cheap to allocate.
1517
- function tryCatch(fn, obj, arg) {
1518
- try {
1519
- return { type: "normal", arg: fn.call(obj, arg) };
1520
- } catch (err) {
1521
- return { type: "throw", arg: err };
1522
- }
1523
- }
1524
-
1525
- var GenStateSuspendedStart = "suspendedStart";
1526
- var GenStateSuspendedYield = "suspendedYield";
1527
- var GenStateExecuting = "executing";
1528
- var GenStateCompleted = "completed";
1529
-
1530
- // Returning this object from the innerFn has the same effect as
1531
- // breaking out of the dispatch switch statement.
1532
- var ContinueSentinel = {};
1533
-
1534
- // Dummy constructor functions that we use as the .constructor and
1535
- // .constructor.prototype properties for functions that return Generator
1536
- // objects. For full spec compliance, you may wish to configure your
1537
- // minifier not to mangle the names of these two functions.
1538
- function Generator() {}
1539
- function GeneratorFunction() {}
1540
- function GeneratorFunctionPrototype() {}
1541
-
1542
- // This is a polyfill for %IteratorPrototype% for environments that
1543
- // don't natively support it.
1544
- var IteratorPrototype = {};
1545
- IteratorPrototype[iteratorSymbol] = function () {
1546
- return this;
1547
- };
1548
-
1549
- var getProto = Object.getPrototypeOf;
1550
- var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
1551
- if (NativeIteratorPrototype &&
1552
- NativeIteratorPrototype !== Op &&
1553
- hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
1554
- // This environment has a native %IteratorPrototype%; use it instead
1555
- // of the polyfill.
1556
- IteratorPrototype = NativeIteratorPrototype;
1557
- }
1558
-
1559
- var Gp = GeneratorFunctionPrototype.prototype =
1560
- Generator.prototype = Object.create(IteratorPrototype);
1561
- GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
1562
- GeneratorFunctionPrototype.constructor = GeneratorFunction;
1563
- GeneratorFunction.displayName = define(
1564
- GeneratorFunctionPrototype,
1565
- toStringTagSymbol,
1566
- "GeneratorFunction"
1567
- );
1568
-
1569
- // Helper for defining the .next, .throw, and .return methods of the
1570
- // Iterator interface in terms of a single ._invoke method.
1571
- function defineIteratorMethods(prototype) {
1572
- ["next", "throw", "return"].forEach(function(method) {
1573
- define(prototype, method, function(arg) {
1574
- return this._invoke(method, arg);
1575
- });
1576
- });
1577
- }
1578
-
1579
- exports.isGeneratorFunction = function(genFun) {
1580
- var ctor = typeof genFun === "function" && genFun.constructor;
1581
- return ctor
1582
- ? ctor === GeneratorFunction ||
1583
- // For the native GeneratorFunction constructor, the best we can
1584
- // do is to check its .name property.
1585
- (ctor.displayName || ctor.name) === "GeneratorFunction"
1586
- : false;
1587
- };
1588
-
1589
- exports.mark = function(genFun) {
1590
- if (Object.setPrototypeOf) {
1591
- Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
1592
- } else {
1593
- genFun.__proto__ = GeneratorFunctionPrototype;
1594
- define(genFun, toStringTagSymbol, "GeneratorFunction");
1595
- }
1596
- genFun.prototype = Object.create(Gp);
1597
- return genFun;
1598
- };
1599
-
1600
- // Within the body of any async function, `await x` is transformed to
1601
- // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
1602
- // `hasOwn.call(value, "__await")` to determine if the yielded value is
1603
- // meant to be awaited.
1604
- exports.awrap = function(arg) {
1605
- return { __await: arg };
1606
- };
1607
-
1608
- function AsyncIterator(generator, PromiseImpl) {
1609
- function invoke(method, arg, resolve, reject) {
1610
- var record = tryCatch(generator[method], generator, arg);
1611
- if (record.type === "throw") {
1612
- reject(record.arg);
1613
- } else {
1614
- var result = record.arg;
1615
- var value = result.value;
1616
- if (value &&
1617
- typeof value === "object" &&
1618
- hasOwn.call(value, "__await")) {
1619
- return PromiseImpl.resolve(value.__await).then(function(value) {
1620
- invoke("next", value, resolve, reject);
1621
- }, function(err) {
1622
- invoke("throw", err, resolve, reject);
1623
- });
1624
- }
1625
-
1626
- return PromiseImpl.resolve(value).then(function(unwrapped) {
1627
- // When a yielded Promise is resolved, its final value becomes
1628
- // the .value of the Promise<{value,done}> result for the
1629
- // current iteration.
1630
- result.value = unwrapped;
1631
- resolve(result);
1632
- }, function(error) {
1633
- // If a rejected Promise was yielded, throw the rejection back
1634
- // into the async generator function so it can be handled there.
1635
- return invoke("throw", error, resolve, reject);
1636
- });
1637
- }
1638
- }
1639
-
1640
- var previousPromise;
1641
-
1642
- function enqueue(method, arg) {
1643
- function callInvokeWithMethodAndArg() {
1644
- return new PromiseImpl(function(resolve, reject) {
1645
- invoke(method, arg, resolve, reject);
1646
- });
1647
- }
1648
-
1649
- return previousPromise =
1650
- // If enqueue has been called before, then we want to wait until
1651
- // all previous Promises have been resolved before calling invoke,
1652
- // so that results are always delivered in the correct order. If
1653
- // enqueue has not been called before, then it is important to
1654
- // call invoke immediately, without waiting on a callback to fire,
1655
- // so that the async generator function has the opportunity to do
1656
- // any necessary setup in a predictable way. This predictability
1657
- // is why the Promise constructor synchronously invokes its
1658
- // executor callback, and why async functions synchronously
1659
- // execute code before the first await. Since we implement simple
1660
- // async functions in terms of async generators, it is especially
1661
- // important to get this right, even though it requires care.
1662
- previousPromise ? previousPromise.then(
1663
- callInvokeWithMethodAndArg,
1664
- // Avoid propagating failures to Promises returned by later
1665
- // invocations of the iterator.
1666
- callInvokeWithMethodAndArg
1667
- ) : callInvokeWithMethodAndArg();
1668
- }
1669
-
1670
- // Define the unified helper method that is used to implement .next,
1671
- // .throw, and .return (see defineIteratorMethods).
1672
- this._invoke = enqueue;
1673
- }
1674
-
1675
- defineIteratorMethods(AsyncIterator.prototype);
1676
- AsyncIterator.prototype[asyncIteratorSymbol] = function () {
1677
- return this;
1678
- };
1679
- exports.AsyncIterator = AsyncIterator;
1680
-
1681
- // Note that simple async functions are implemented on top of
1682
- // AsyncIterator objects; they just return a Promise for the value of
1683
- // the final result produced by the iterator.
1684
- exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
1685
- if (PromiseImpl === void 0) PromiseImpl = Promise;
1686
-
1687
- var iter = new AsyncIterator(
1688
- wrap(innerFn, outerFn, self, tryLocsList),
1689
- PromiseImpl
1690
- );
1691
-
1692
- return exports.isGeneratorFunction(outerFn)
1693
- ? iter // If outerFn is a generator, return the full iterator.
1694
- : iter.next().then(function(result) {
1695
- return result.done ? result.value : iter.next();
1696
- });
1697
- };
1698
-
1699
- function makeInvokeMethod(innerFn, self, context) {
1700
- var state = GenStateSuspendedStart;
1701
-
1702
- return function invoke(method, arg) {
1703
- if (state === GenStateExecuting) {
1704
- throw new Error("Generator is already running");
1705
- }
1706
-
1707
- if (state === GenStateCompleted) {
1708
- if (method === "throw") {
1709
- throw arg;
1710
- }
1711
-
1712
- // Be forgiving, per 25.3.3.3.3 of the spec:
1713
- // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
1714
- return doneResult();
1715
- }
1716
-
1717
- context.method = method;
1718
- context.arg = arg;
1719
-
1720
- while (true) {
1721
- var delegate = context.delegate;
1722
- if (delegate) {
1723
- var delegateResult = maybeInvokeDelegate(delegate, context);
1724
- if (delegateResult) {
1725
- if (delegateResult === ContinueSentinel) continue;
1726
- return delegateResult;
1727
- }
1728
- }
1729
-
1730
- if (context.method === "next") {
1731
- // Setting context._sent for legacy support of Babel's
1732
- // function.sent implementation.
1733
- context.sent = context._sent = context.arg;
1734
-
1735
- } else if (context.method === "throw") {
1736
- if (state === GenStateSuspendedStart) {
1737
- state = GenStateCompleted;
1738
- throw context.arg;
1739
- }
1740
-
1741
- context.dispatchException(context.arg);
1742
-
1743
- } else if (context.method === "return") {
1744
- context.abrupt("return", context.arg);
1745
- }
1746
-
1747
- state = GenStateExecuting;
1748
-
1749
- var record = tryCatch(innerFn, self, context);
1750
- if (record.type === "normal") {
1751
- // If an exception is thrown from innerFn, we leave state ===
1752
- // GenStateExecuting and loop back for another invocation.
1753
- state = context.done
1754
- ? GenStateCompleted
1755
- : GenStateSuspendedYield;
1756
-
1757
- if (record.arg === ContinueSentinel) {
1758
- continue;
1759
- }
1760
-
1761
- return {
1762
- value: record.arg,
1763
- done: context.done
1764
- };
1765
-
1766
- } else if (record.type === "throw") {
1767
- state = GenStateCompleted;
1768
- // Dispatch the exception by looping back around to the
1769
- // context.dispatchException(context.arg) call above.
1770
- context.method = "throw";
1771
- context.arg = record.arg;
1772
- }
1773
- }
1774
- };
1775
- }
1776
-
1777
- // Call delegate.iterator[context.method](context.arg) and handle the
1778
- // result, either by returning a { value, done } result from the
1779
- // delegate iterator, or by modifying context.method and context.arg,
1780
- // setting context.delegate to null, and returning the ContinueSentinel.
1781
- function maybeInvokeDelegate(delegate, context) {
1782
- var method = delegate.iterator[context.method];
1783
- if (method === undefined$1) {
1784
- // A .throw or .return when the delegate iterator has no .throw
1785
- // method always terminates the yield* loop.
1786
- context.delegate = null;
1787
-
1788
- if (context.method === "throw") {
1789
- // Note: ["return"] must be used for ES3 parsing compatibility.
1790
- if (delegate.iterator["return"]) {
1791
- // If the delegate iterator has a return method, give it a
1792
- // chance to clean up.
1793
- context.method = "return";
1794
- context.arg = undefined$1;
1795
- maybeInvokeDelegate(delegate, context);
1796
-
1797
- if (context.method === "throw") {
1798
- // If maybeInvokeDelegate(context) changed context.method from
1799
- // "return" to "throw", let that override the TypeError below.
1800
- return ContinueSentinel;
1801
- }
1802
- }
1803
-
1804
- context.method = "throw";
1805
- context.arg = new TypeError(
1806
- "The iterator does not provide a 'throw' method");
1807
- }
1808
-
1809
- return ContinueSentinel;
1810
- }
1811
-
1812
- var record = tryCatch(method, delegate.iterator, context.arg);
1813
-
1814
- if (record.type === "throw") {
1815
- context.method = "throw";
1816
- context.arg = record.arg;
1817
- context.delegate = null;
1818
- return ContinueSentinel;
1819
- }
1820
-
1821
- var info = record.arg;
1822
-
1823
- if (! info) {
1824
- context.method = "throw";
1825
- context.arg = new TypeError("iterator result is not an object");
1826
- context.delegate = null;
1827
- return ContinueSentinel;
1828
- }
1829
-
1830
- if (info.done) {
1831
- // Assign the result of the finished delegate to the temporary
1832
- // variable specified by delegate.resultName (see delegateYield).
1833
- context[delegate.resultName] = info.value;
1834
-
1835
- // Resume execution at the desired location (see delegateYield).
1836
- context.next = delegate.nextLoc;
1837
-
1838
- // If context.method was "throw" but the delegate handled the
1839
- // exception, let the outer generator proceed normally. If
1840
- // context.method was "next", forget context.arg since it has been
1841
- // "consumed" by the delegate iterator. If context.method was
1842
- // "return", allow the original .return call to continue in the
1843
- // outer generator.
1844
- if (context.method !== "return") {
1845
- context.method = "next";
1846
- context.arg = undefined$1;
1847
- }
1848
-
1849
- } else {
1850
- // Re-yield the result returned by the delegate method.
1851
- return info;
1852
- }
1853
-
1854
- // The delegate iterator is finished, so forget it and continue with
1855
- // the outer generator.
1856
- context.delegate = null;
1857
- return ContinueSentinel;
1858
- }
1859
-
1860
- // Define Generator.prototype.{next,throw,return} in terms of the
1861
- // unified ._invoke helper method.
1862
- defineIteratorMethods(Gp);
1863
-
1864
- define(Gp, toStringTagSymbol, "Generator");
1865
-
1866
- // A Generator should always return itself as the iterator object when the
1867
- // @@iterator function is called on it. Some browsers' implementations of the
1868
- // iterator prototype chain incorrectly implement this, causing the Generator
1869
- // object to not be returned from this call. This ensures that doesn't happen.
1870
- // See https://github.com/facebook/regenerator/issues/274 for more details.
1871
- Gp[iteratorSymbol] = function() {
1872
- return this;
1873
- };
1874
-
1875
- Gp.toString = function() {
1876
- return "[object Generator]";
1877
- };
1878
-
1879
- function pushTryEntry(locs) {
1880
- var entry = { tryLoc: locs[0] };
1881
-
1882
- if (1 in locs) {
1883
- entry.catchLoc = locs[1];
1884
- }
1885
-
1886
- if (2 in locs) {
1887
- entry.finallyLoc = locs[2];
1888
- entry.afterLoc = locs[3];
1889
- }
1890
-
1891
- this.tryEntries.push(entry);
1892
- }
1893
-
1894
- function resetTryEntry(entry) {
1895
- var record = entry.completion || {};
1896
- record.type = "normal";
1897
- delete record.arg;
1898
- entry.completion = record;
1899
- }
1900
-
1901
- function Context(tryLocsList) {
1902
- // The root entry object (effectively a try statement without a catch
1903
- // or a finally block) gives us a place to store values thrown from
1904
- // locations where there is no enclosing try statement.
1905
- this.tryEntries = [{ tryLoc: "root" }];
1906
- tryLocsList.forEach(pushTryEntry, this);
1907
- this.reset(true);
1908
- }
1909
-
1910
- exports.keys = function(object) {
1911
- var keys = [];
1912
- for (var key in object) {
1913
- keys.push(key);
1914
- }
1915
- keys.reverse();
1916
-
1917
- // Rather than returning an object with a next method, we keep
1918
- // things simple and return the next function itself.
1919
- return function next() {
1920
- while (keys.length) {
1921
- var key = keys.pop();
1922
- if (key in object) {
1923
- next.value = key;
1924
- next.done = false;
1925
- return next;
1926
- }
1927
- }
1928
-
1929
- // To avoid creating an additional object, we just hang the .value
1930
- // and .done properties off the next function object itself. This
1931
- // also ensures that the minifier will not anonymize the function.
1932
- next.done = true;
1933
- return next;
1934
- };
1935
- };
1936
-
1937
- function values(iterable) {
1938
- if (iterable) {
1939
- var iteratorMethod = iterable[iteratorSymbol];
1940
- if (iteratorMethod) {
1941
- return iteratorMethod.call(iterable);
1942
- }
1943
-
1944
- if (typeof iterable.next === "function") {
1945
- return iterable;
1946
- }
1947
-
1948
- if (!isNaN(iterable.length)) {
1949
- var i = -1, next = function next() {
1950
- while (++i < iterable.length) {
1951
- if (hasOwn.call(iterable, i)) {
1952
- next.value = iterable[i];
1953
- next.done = false;
1954
- return next;
1955
- }
1956
- }
1957
-
1958
- next.value = undefined$1;
1959
- next.done = true;
1960
-
1961
- return next;
1962
- };
1963
-
1964
- return next.next = next;
1965
- }
1966
- }
1967
-
1968
- // Return an iterator with no values.
1969
- return { next: doneResult };
1970
- }
1971
- exports.values = values;
1972
-
1973
- function doneResult() {
1974
- return { value: undefined$1, done: true };
1975
- }
1976
-
1977
- Context.prototype = {
1978
- constructor: Context,
1979
-
1980
- reset: function(skipTempReset) {
1981
- this.prev = 0;
1982
- this.next = 0;
1983
- // Resetting context._sent for legacy support of Babel's
1984
- // function.sent implementation.
1985
- this.sent = this._sent = undefined$1;
1986
- this.done = false;
1987
- this.delegate = null;
1988
-
1989
- this.method = "next";
1990
- this.arg = undefined$1;
1991
-
1992
- this.tryEntries.forEach(resetTryEntry);
1993
-
1994
- if (!skipTempReset) {
1995
- for (var name in this) {
1996
- // Not sure about the optimal order of these conditions:
1997
- if (name.charAt(0) === "t" &&
1998
- hasOwn.call(this, name) &&
1999
- !isNaN(+name.slice(1))) {
2000
- this[name] = undefined$1;
2001
- }
2002
- }
2003
- }
2004
- },
2005
-
2006
- stop: function() {
2007
- this.done = true;
2008
-
2009
- var rootEntry = this.tryEntries[0];
2010
- var rootRecord = rootEntry.completion;
2011
- if (rootRecord.type === "throw") {
2012
- throw rootRecord.arg;
2013
- }
2014
-
2015
- return this.rval;
2016
- },
2017
-
2018
- dispatchException: function(exception) {
2019
- if (this.done) {
2020
- throw exception;
2021
- }
2022
-
2023
- var context = this;
2024
- function handle(loc, caught) {
2025
- record.type = "throw";
2026
- record.arg = exception;
2027
- context.next = loc;
2028
-
2029
- if (caught) {
2030
- // If the dispatched exception was caught by a catch block,
2031
- // then let that catch block handle the exception normally.
2032
- context.method = "next";
2033
- context.arg = undefined$1;
2034
- }
2035
-
2036
- return !! caught;
2037
- }
2038
-
2039
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
2040
- var entry = this.tryEntries[i];
2041
- var record = entry.completion;
2042
-
2043
- if (entry.tryLoc === "root") {
2044
- // Exception thrown outside of any try block that could handle
2045
- // it, so set the completion value of the entire function to
2046
- // throw the exception.
2047
- return handle("end");
2048
- }
2049
-
2050
- if (entry.tryLoc <= this.prev) {
2051
- var hasCatch = hasOwn.call(entry, "catchLoc");
2052
- var hasFinally = hasOwn.call(entry, "finallyLoc");
2053
-
2054
- if (hasCatch && hasFinally) {
2055
- if (this.prev < entry.catchLoc) {
2056
- return handle(entry.catchLoc, true);
2057
- } else if (this.prev < entry.finallyLoc) {
2058
- return handle(entry.finallyLoc);
2059
- }
2060
-
2061
- } else if (hasCatch) {
2062
- if (this.prev < entry.catchLoc) {
2063
- return handle(entry.catchLoc, true);
2064
- }
2065
-
2066
- } else if (hasFinally) {
2067
- if (this.prev < entry.finallyLoc) {
2068
- return handle(entry.finallyLoc);
2069
- }
2070
-
2071
- } else {
2072
- throw new Error("try statement without catch or finally");
2073
- }
2074
- }
2075
- }
2076
- },
2077
-
2078
- abrupt: function(type, arg) {
2079
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
2080
- var entry = this.tryEntries[i];
2081
- if (entry.tryLoc <= this.prev &&
2082
- hasOwn.call(entry, "finallyLoc") &&
2083
- this.prev < entry.finallyLoc) {
2084
- var finallyEntry = entry;
2085
- break;
2086
- }
2087
- }
2088
-
2089
- if (finallyEntry &&
2090
- (type === "break" ||
2091
- type === "continue") &&
2092
- finallyEntry.tryLoc <= arg &&
2093
- arg <= finallyEntry.finallyLoc) {
2094
- // Ignore the finally entry if control is not jumping to a
2095
- // location outside the try/catch block.
2096
- finallyEntry = null;
2097
- }
2098
-
2099
- var record = finallyEntry ? finallyEntry.completion : {};
2100
- record.type = type;
2101
- record.arg = arg;
2102
-
2103
- if (finallyEntry) {
2104
- this.method = "next";
2105
- this.next = finallyEntry.finallyLoc;
2106
- return ContinueSentinel;
2107
- }
2108
-
2109
- return this.complete(record);
2110
- },
2111
-
2112
- complete: function(record, afterLoc) {
2113
- if (record.type === "throw") {
2114
- throw record.arg;
2115
- }
2116
-
2117
- if (record.type === "break" ||
2118
- record.type === "continue") {
2119
- this.next = record.arg;
2120
- } else if (record.type === "return") {
2121
- this.rval = this.arg = record.arg;
2122
- this.method = "return";
2123
- this.next = "end";
2124
- } else if (record.type === "normal" && afterLoc) {
2125
- this.next = afterLoc;
2126
- }
2127
-
2128
- return ContinueSentinel;
2129
- },
2130
-
2131
- finish: function(finallyLoc) {
2132
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
2133
- var entry = this.tryEntries[i];
2134
- if (entry.finallyLoc === finallyLoc) {
2135
- this.complete(entry.completion, entry.afterLoc);
2136
- resetTryEntry(entry);
2137
- return ContinueSentinel;
2138
- }
2139
- }
2140
- },
2141
-
2142
- "catch": function(tryLoc) {
2143
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
2144
- var entry = this.tryEntries[i];
2145
- if (entry.tryLoc === tryLoc) {
2146
- var record = entry.completion;
2147
- if (record.type === "throw") {
2148
- var thrown = record.arg;
2149
- resetTryEntry(entry);
2150
- }
2151
- return thrown;
2152
- }
2153
- }
2154
-
2155
- // The context.catch method must only be called with a location
2156
- // argument that corresponds to a known catch block.
2157
- throw new Error("illegal catch attempt");
2158
- },
2159
-
2160
- delegateYield: function(iterable, resultName, nextLoc) {
2161
- this.delegate = {
2162
- iterator: values(iterable),
2163
- resultName: resultName,
2164
- nextLoc: nextLoc
2165
- };
2166
-
2167
- if (this.method === "next") {
2168
- // Deliberately forget the last sent value so that we don't
2169
- // accidentally pass it on to the delegate.
2170
- this.arg = undefined$1;
2171
- }
2172
-
2173
- return ContinueSentinel;
2174
- }
2175
- };
2176
-
2177
- // Regardless of whether this script is executing as a CommonJS module
2178
- // or not, return the runtime object so that we can declare the variable
2179
- // regeneratorRuntime in the outer scope, which allows this module to be
2180
- // injected easily by `bin/regenerator --include-runtime script.js`.
2181
- return exports;
2182
-
2183
- }(
2184
- // If this script is executing as a CommonJS module, use module.exports
2185
- // as the regeneratorRuntime namespace. Otherwise create a new empty
2186
- // object. Either way, the resulting object will be used to initialize
2187
- // the regeneratorRuntime variable at the top of this file.
2188
- module.exports
2189
- ));
2190
-
2191
- try {
2192
- regeneratorRuntime = runtime;
2193
- } catch (accidentalStrictMode) {
2194
- // This module should not be running in strict mode, so the above
2195
- // assignment should always work unless something is misconfigured. Just
2196
- // in case runtime.js accidentally runs in strict mode, we can escape
2197
- // strict mode using a global Function call. This could conceivably fail
2198
- // if a Content Security Policy forbids using Function, but in that case
2199
- // the proper solution is to fix the accidental strict mode problem. If
2200
- // you've misconfigured your bundler to force strict mode and applied a
2201
- // CSP to forbid Function, and you're not willing to fix either of those
2202
- // problems, please detail your unique predicament in a GitHub issue.
2203
- Function("r", "regeneratorRuntime = r")(runtime);
2204
- }
2205
- });
2206
-
2207
- /**
2208
- * Utilities for fetching specific types
2209
- */
2210
- function fetchJson(_x) {
2211
- return _fetchJson.apply(this, arguments);
2212
- }
2213
-
2214
- function _fetchJson() {
2215
- _fetchJson = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(url) {
2216
- var response;
2217
- return runtime_1.wrap(function _callee$(_context) {
2218
- while (1) {
2219
- switch (_context.prev = _context.next) {
2220
- case 0:
2221
- _context.next = 2;
2222
- return fetch(url);
2223
-
2224
- case 2:
2225
- response = _context.sent;
2226
-
2227
- if (response.ok) {
2228
- _context.next = 5;
2229
- break;
2230
- }
2231
-
2232
- throw new Error('Response not Ok for URL: ' + url);
2233
-
2234
- case 5:
2235
- _context.next = 7;
2236
- return response.json();
2237
-
2238
- case 7:
2239
- return _context.abrupt("return", _context.sent);
2240
-
2241
- case 8:
2242
- case "end":
2243
- return _context.stop();
2244
- }
2245
- }
2246
- }, _callee);
2247
- }));
2248
- return _fetchJson.apply(this, arguments);
2249
- }
2250
-
2251
- var HtmlReaderContent = function HtmlReaderContent() {
2252
- return createElement("div", {
2253
- id: "D2Reader-Container"
2254
- }, createElement("main", {
2255
- tabIndex: -1,
2256
- id: "iframe-wrapper",
2257
- style: {
2258
- height: "calc(100vh - " + HEADER_HEIGHT + "px)"
2259
- }
2260
- }, createElement("div", {
2261
- id: "reader-loading",
2262
- className: "loading"
2263
- }), createElement("div", {
2264
- id: "reader-error",
2265
- className: "error"
2266
- })));
2267
- };
2268
-
2269
- function useMeasure() {
2270
- // this is a little trick to get a reference to an HTML element. Using useRef wouldn't
2271
- // work because we actually need rerenders when it changes, to update the useLayoutEffect
2272
- var _React$useState = useState(null),
2273
- element = _React$useState[0],
2274
- ref = _React$useState[1];
2275
-
2276
- var _React$useState2 = useState(null),
2277
- rect = _React$useState2[0],
2278
- setRect = _React$useState2[1];
2279
-
2280
- var observer = useMemo(function () {
2281
- return new window.ResizeObserver(function (entries) {
2282
- if (entries[0]) {
2283
- var _entries$0$contentRec = entries[0].contentRect,
2284
- x = _entries$0$contentRec.x,
2285
- y = _entries$0$contentRec.y,
2286
- width = _entries$0$contentRec.width,
2287
- height = _entries$0$contentRec.height,
2288
- top = _entries$0$contentRec.top,
2289
- left = _entries$0$contentRec.left,
2290
- bottom = _entries$0$contentRec.bottom,
2291
- right = _entries$0$contentRec.right;
2292
- setRect({
2293
- x: x,
2294
- y: y,
2295
- width: width,
2296
- height: height,
2297
- top: top,
2298
- left: left,
2299
- bottom: bottom,
2300
- right: right
2301
- });
2302
- }
2303
- });
2304
- }, []);
2305
- useLayoutEffect(function () {
2306
- if (!element) return;
2307
- observer.observe(element);
2308
- return function () {
2309
- observer.disconnect();
2310
- };
2311
- }, [element, observer]);
2312
- return [ref, rect];
2313
- }
2314
-
2315
- pdfjs.GlobalWorkerOptions.workerSrc = "pdf.worker.min.js";
2316
- var IFRAME_WRAPPER_ID = 'iframe-wrapper';
2317
-
2318
- function pdfReducer(state, action) {
2319
- switch (action.type) {
2320
- /**
2321
- * Cleares the current resource and sets the current index, which will cause
2322
- * the useEffect hook to load a new resource.
2323
- */
2324
- case 'SET_CURRENT_RESOURCE':
2325
- return _extends({}, state, {
2326
- resource: null,
2327
- resourceIndex: action.index,
2328
- pageNumber: action.shouldNavigateToEnd ? -1 : 1,
2329
- numPages: null
2330
- });
2331
-
2332
- case 'RESOURCE_FETCH_SUCCESS':
2333
- return _extends({}, state, {
2334
- resource: action.resource
2335
- });
2336
- // called when the resource has been parsed by react-pdf
2337
- // and we know the number of pages
2338
-
2339
- case 'PDF_PARSED':
2340
- return _extends({}, state, {
2341
- numPages: action.numPages,
2342
- // if the state.pageNumber is -1, we know to navigate to the
2343
- // end of the PDF that was just parsed
2344
- pageNumber: state.pageNumber === -1 ? action.numPages : state.pageNumber
2345
- });
2346
- // Navigates to page in resource
2347
-
2348
- case 'NAVIGATE_PAGE':
2349
- return _extends({}, state, {
2350
- pageNumber: action.pageNum
2351
- });
2352
-
2353
- case 'SET_COLOR_MODE':
2354
- return _extends({}, state, {
2355
- colorMode: action.mode
2356
- });
2357
-
2358
- case 'SET_SCROLL':
2359
- return _extends({}, state, {
2360
- isScrolling: action.isScrolling
2361
- });
2362
-
2363
- case 'SET_SCALE':
2364
- return _extends({}, state, {
2365
- scale: action.scale
2366
- });
2367
-
2368
- case 'PAGE_LOAD_SUCCESS':
2369
- return _extends({}, state, {
2370
- pdfWidth: action.width,
2371
- pdfHeight: action.height,
2372
- pageWidth: action.width,
2373
- pageHeight: action.height
2374
- });
2375
-
2376
- case 'RESIZE_PAGE':
2377
- return _extends({}, state, {
2378
- pageWidth: action.width,
2379
- pageHeight: action.height
2380
- });
2381
- }
2382
- }
2383
-
2384
- var getResourceUrl = function getResourceUrl(index, readingOrder) {
2385
- if (!readingOrder || !readingOrder.length) {
2386
- throw new Error('A manifest has been returned, but has no reading order');
2387
- } // If it has no children, return the link href
2388
-
2389
-
2390
- return readingOrder[index].href;
2391
- };
2392
-
2393
- var loadResource = /*#__PURE__*/function () {
2394
- var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(resourceUrl, proxyUrl) {
2395
- var resource, response, array;
2396
- return runtime_1.wrap(function _callee$(_context) {
2397
- while (1) {
2398
- switch (_context.prev = _context.next) {
2399
- case 0:
2400
- // Generate the resource URL using the proxy
2401
- resource = proxyUrl + encodeURI(resourceUrl);
2402
- _context.next = 3;
2403
- return fetch(resource, {
2404
- mode: 'cors'
2405
- });
2406
-
2407
- case 3:
2408
- response = _context.sent;
2409
- _context.t0 = Uint8Array;
2410
- _context.next = 7;
2411
- return response.arrayBuffer();
2412
-
2413
- case 7:
2414
- _context.t1 = _context.sent;
2415
- array = new _context.t0(_context.t1);
2416
-
2417
- if (response.ok) {
2418
- _context.next = 11;
2419
- break;
2420
- }
2421
-
2422
- throw new Error('Response not Ok for URL: ' + resource);
2423
-
2424
- case 11:
2425
- return _context.abrupt("return", array);
2426
-
2427
- case 12:
2428
- case "end":
2429
- return _context.stop();
2430
- }
2431
- }
2432
- }, _callee);
2433
- }));
2434
-
2435
- return function loadResource(_x, _x2) {
2436
- return _ref.apply(this, arguments);
2437
- };
2438
- }();
2439
- /**
2440
- * The PDF reader
2441
- *
2442
- * The PDF reader loads resources in two stages: First, it fetches the PDF resource as an Uint8Array
2443
- * Then, it passes this array into the <Document> object, which loads the PDF inside an iframe
2444
- *
2445
- * @param args T
2446
- * @returns
2447
- */
2448
-
2449
-
2450
- function usePdfReader(args) {
2451
- var _ref2 = args != null ? args : {},
2452
- webpubManifestUrl = _ref2.webpubManifestUrl,
2453
- manifest = _ref2.manifest,
2454
- proxyUrl = _ref2.proxyUrl;
2455
-
2456
- var _React$useReducer = useReducer(pdfReducer, {
2457
- colorMode: 'day',
2458
- isScrolling: false,
2459
- fontSize: 16,
2460
- fontFamily: 'sans-serif',
2461
- resourceIndex: 0,
2462
- resource: null,
2463
- pageNumber: 1,
2464
- numPages: null,
2465
- currentTocUrl: null,
2466
- scale: 1,
2467
- pdfWidth: 0,
2468
- pdfHeight: 0,
2469
- pageHeight: undefined,
2470
- pageWidth: undefined
2471
- }),
2472
- state = _React$useReducer[0],
2473
- dispatch = _React$useReducer[1]; // state we can derive from the state above
2474
-
2475
-
2476
- var isFetching = !state.resource;
2477
- var isParsed = typeof state.numPages === 'number';
2478
-
2479
- var _useMeasure = useMeasure(),
2480
- containerRef = _useMeasure[0],
2481
- containerSize = _useMeasure[1]; // Wrap Page component so that we can pass it styles
2482
-
2483
-
2484
- var ChakraPage = chakra(Page, {
2485
- shouldForwardProp: function shouldForwardProp$1(prop) {
2486
- // Definitely forward width and height
2487
- if (['width', 'height', 'scale'].includes(prop)) return true; // don't forward the rest of Chakra's props
2488
-
2489
- var isChakraProp = !shouldForwardProp(prop);
2490
- if (isChakraProp) return false; // else, only forward `sample` prop
2491
-
2492
- return true;
2493
- },
2494
- baseStyle: {
2495
- outline: '1px',
2496
- outlineColor: 'ui.gray.light-cool'
2497
- }
2498
- });
2499
- /**
2500
- * Load the current resource and set it in state,
2501
- * and reload whenever it changes (via navigation)
2502
- */
2503
-
2504
- useEffect(function () {
2505
- // bail out if there is not manifest passed in,
2506
- // that indicates that this format is inactive
2507
- if (!manifest) return; // throw an error on a badly formed manifest
2508
-
2509
- if (!manifest.readingOrder || !manifest.readingOrder.length) {
2510
- throw new Error('Manifest has no Reading Order');
2511
- }
2512
-
2513
- var resourceUrl = getResourceUrl(state.resourceIndex, manifest.readingOrder);
2514
- loadResource(resourceUrl, proxyUrl).then(function (data) {
2515
- dispatch({
2516
- type: 'RESOURCE_FETCH_SUCCESS',
2517
- resource: {
2518
- data: data
2519
- }
2520
- });
2521
- });
2522
- }, [state.resourceIndex, manifest, proxyUrl]);
2523
- /**
2524
- * calculate the height or width of the pdf page in paginated mode.
2525
- * - if the page's aspect ratio is taller than the container's, we will constrain
2526
- * the page to the height of the container.
2527
- * - if the page's aspect ratio is wider than the container's, we will constrain
2528
- * the page to the width of the container
2529
- */
2530
-
2531
- var resizePage = useCallback(function (pdfWidth, pdfHeight, containerSize) {
2532
- var wRatio = pdfWidth / containerSize.width;
2533
- var hRatio = pdfHeight / containerSize.height;
2534
- var fitHorizontal = wRatio > hRatio;
2535
- var width = fitHorizontal ? Math.round(containerSize.width) : undefined;
2536
- var height = !fitHorizontal ? Math.round(containerSize.height) : undefined;
2537
- dispatch({
2538
- type: 'RESIZE_PAGE',
2539
- width: width,
2540
- height: height
2541
- });
2542
- }, []); //TODO: Somehow, this window size updates when height
2543
-
2544
- useEffect(function () {
2545
- if (containerSize) {
2546
- resizePage(state.pdfWidth, state.pdfHeight, containerSize);
2547
- }
2548
- }, [containerSize, state.pdfWidth, state.pdfHeight, resizePage]); // prev and next page functions
2549
-
2550
- var goForward = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2() {
2551
- var _manifest$readingOrde;
2552
-
2553
- var nextIndex;
2554
- return runtime_1.wrap(function _callee2$(_context2) {
2555
- while (1) {
2556
- switch (_context2.prev = _context2.next) {
2557
- case 0:
2558
- if (state.numPages) {
2559
- _context2.next = 2;
2560
- break;
2561
- }
2562
-
2563
- return _context2.abrupt("return");
2564
-
2565
- case 2:
2566
- if (state.pageNumber < state.numPages && !state.isScrolling) {
2567
- dispatch({
2568
- type: 'NAVIGATE_PAGE',
2569
- pageNum: state.pageNumber + 1
2570
- });
2571
- } else if (manifest && manifest.readingOrder && state.resourceIndex < (manifest == null ? void 0 : (_manifest$readingOrde = manifest.readingOrder) == null ? void 0 : _manifest$readingOrde.length) - 1) {
2572
- nextIndex = state.resourceIndex + 1;
2573
- dispatch({
2574
- type: 'SET_CURRENT_RESOURCE',
2575
- index: nextIndex,
2576
- shouldNavigateToEnd: false
2577
- });
2578
- } // Do nothing if it's at the last page of the last resource
2579
-
2580
-
2581
- case 3:
2582
- case "end":
2583
- return _context2.stop();
2584
- }
2585
- }
2586
- }, _callee2);
2587
- })), [manifest, state.isScrolling, state.numPages, state.pageNumber, state.resourceIndex]);
2588
- var goBackward = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
2589
- var nextIndex;
2590
- return runtime_1.wrap(function _callee3$(_context3) {
2591
- while (1) {
2592
- switch (_context3.prev = _context3.next) {
2593
- case 0:
2594
- if (isParsed) {
2595
- _context3.next = 2;
2596
- break;
2597
- }
2598
-
2599
- return _context3.abrupt("return");
2600
-
2601
- case 2:
2602
- if (state.pageNumber > 1) {
2603
- dispatch({
2604
- type: 'NAVIGATE_PAGE',
2605
- pageNum: state.pageNumber - 1
2606
- });
2607
- } else if (manifest != null && manifest.readingOrder && state.resourceIndex > 0) {
2608
- nextIndex = state.resourceIndex - 1;
2609
- dispatch({
2610
- type: 'SET_CURRENT_RESOURCE',
2611
- index: nextIndex,
2612
- shouldNavigateToEnd: !state.isScrolling
2613
- });
2614
- }
2615
-
2616
- case 3:
2617
- case "end":
2618
- return _context3.stop();
2619
- }
2620
- }
2621
- }, _callee3);
2622
- })), [manifest, isParsed, state.isScrolling, state.pageNumber, state.resourceIndex]);
2623
- /**
2624
- * These ones don't make sense in the PDF case I dont think. I'm still
2625
- * deciding how we will separate the types of Navigators and States, so
2626
- * for now just pass dummies through.
2627
- */
2628
-
2629
- var setColorMode = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4() {
2630
- return runtime_1.wrap(function _callee4$(_context4) {
2631
- while (1) {
2632
- switch (_context4.prev = _context4.next) {
2633
- case 0:
2634
- console.log('unimplemented');
2635
-
2636
- case 1:
2637
- case "end":
2638
- return _context4.stop();
2639
- }
2640
- }
2641
- }, _callee4);
2642
- })), []);
2643
- var setScroll = useCallback( /*#__PURE__*/function () {
2644
- var _ref6 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(val) {
2645
- var isScrolling;
2646
- return runtime_1.wrap(function _callee5$(_context5) {
2647
- while (1) {
2648
- switch (_context5.prev = _context5.next) {
2649
- case 0:
2650
- isScrolling = val === 'scrolling';
2651
- dispatch({
2652
- type: 'SET_SCROLL',
2653
- isScrolling: isScrolling
2654
- });
2655
-
2656
- case 2:
2657
- case "end":
2658
- return _context5.stop();
2659
- }
2660
- }
2661
- }, _callee5);
2662
- }));
2663
-
2664
- return function (_x3) {
2665
- return _ref6.apply(this, arguments);
2666
- };
2667
- }(), []);
2668
- /**
2669
- * TODO: Change this button into a different "scale" button
2670
- */
2671
-
2672
- var increaseFontSize = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6() {
2673
- return runtime_1.wrap(function _callee6$(_context6) {
2674
- while (1) {
2675
- switch (_context6.prev = _context6.next) {
2676
- case 0:
2677
- dispatch({
2678
- type: 'SET_SCALE',
2679
- scale: state.scale + 0.1
2680
- });
2681
-
2682
- case 1:
2683
- case "end":
2684
- return _context6.stop();
2685
- }
2686
- }
2687
- }, _callee6);
2688
- })), [state.scale]);
2689
- var decreaseFontSize = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7() {
2690
- return runtime_1.wrap(function _callee7$(_context7) {
2691
- while (1) {
2692
- switch (_context7.prev = _context7.next) {
2693
- case 0:
2694
- dispatch({
2695
- type: 'SET_SCALE',
2696
- scale: state.scale - 0.1
2697
- });
2698
-
2699
- case 1:
2700
- case "end":
2701
- return _context7.stop();
2702
- }
2703
- }
2704
- }, _callee7);
2705
- })), [state.scale]);
2706
- var setFontFamily = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8() {
2707
- return runtime_1.wrap(function _callee8$(_context8) {
2708
- while (1) {
2709
- switch (_context8.prev = _context8.next) {
2710
- case 0:
2711
- console.log('unimplemented');
2712
-
2713
- case 1:
2714
- case "end":
2715
- return _context8.stop();
2716
- }
2717
- }
2718
- }, _callee8);
2719
- })), []);
2720
- var goToPage = useCallback( /*#__PURE__*/function () {
2721
- var _ref10 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9(href) {
2722
- var getIndexFromHref;
2723
- return runtime_1.wrap(function _callee9$(_context9) {
2724
- while (1) {
2725
- switch (_context9.prev = _context9.next) {
2726
- case 0:
2727
- getIndexFromHref = function getIndexFromHref(href) {
2728
- var _manifest$readingOrde2;
2729
-
2730
- var index = manifest == null ? void 0 : (_manifest$readingOrde2 = manifest.readingOrder) == null ? void 0 : _manifest$readingOrde2.findIndex(function (link) {
2731
- return link.href === href;
2732
- });
2733
-
2734
- if (!index) {
2735
- throw new Error('Cannot find resource in readingOrder');
2736
- }
2737
-
2738
- return index;
2739
- };
2740
-
2741
- dispatch({
2742
- type: 'SET_CURRENT_RESOURCE',
2743
- index: getIndexFromHref(href),
2744
- shouldNavigateToEnd: false
2745
- });
2746
-
2747
- case 2:
2748
- case "end":
2749
- return _context9.stop();
2750
- }
2751
- }
2752
- }, _callee9);
2753
- }));
2754
-
2755
- return function (_x4) {
2756
- return _ref10.apply(this, arguments);
2757
- };
2758
- }(), [manifest == null ? void 0 : manifest.readingOrder]); // this format is inactive, return null
2759
-
2760
- if (!webpubManifestUrl || !manifest) return null;
2761
-
2762
- if (isFetching) {
2763
- // The Reader is fetching a PDF resource
2764
- return {
2765
- type: 'PDF',
2766
- isLoading: false,
2767
- content: createElement(Flex, {
2768
- as: "main",
2769
- tabIndex: -1,
2770
- id: "iframe-wrapper",
2771
- zIndex: "base",
2772
- alignItems: "center",
2773
- justifyContent: "center",
2774
- flex: "1 0 auto"
2775
- }, "PDF is loading"),
2776
- state: state,
2777
- manifest: manifest,
2778
- navigator: {
2779
- goForward: goForward,
2780
- goBackward: goBackward,
2781
- increaseFontSize: increaseFontSize,
2782
- decreaseFontSize: decreaseFontSize,
2783
- setFontFamily: setFontFamily,
2784
- setColorMode: setColorMode,
2785
- setScroll: setScroll,
2786
- goToPage: goToPage
2787
- }
2788
- };
2789
- }
2790
-
2791
- function onDocumentLoadSuccess(_ref11) {
2792
- var numPages = _ref11.numPages;
2793
- dispatch({
2794
- type: 'PDF_PARSED',
2795
- numPages: numPages
2796
- });
2797
- }
2798
-
2799
- function onRenderSuccess(page) {
2800
- if (!page.height || !page.width || !containerSize) throw new Error('Error rendering page from Reader');
2801
-
2802
- if (Math.round(page.height) !== state.pdfHeight || Math.round(page.width) !== state.pdfWidth) {
2803
- dispatch({
2804
- type: 'PAGE_LOAD_SUCCESS',
2805
- height: Math.round(page.height),
2806
- width: Math.round(page.width)
2807
- });
2808
- resizePage(page.width, page.height, containerSize);
2809
- }
2810
- } // the reader is active but loading a page
2811
-
2812
-
2813
- return {
2814
- type: 'PDF',
2815
- isLoading: false,
2816
- content: createElement(Flex, {
2817
- as: "main",
2818
- zIndex: "base",
2819
- flex: "1 0 auto",
2820
- justifyContent: "center",
2821
- alignItems: "center",
2822
- tabIndex: -1,
2823
- id: IFRAME_WRAPPER_ID,
2824
- ref: containerRef
2825
- }, createElement(Document, {
2826
- file: state.resource,
2827
- onLoadSuccess: onDocumentLoadSuccess
2828
- }, isParsed && state.numPages && createElement(Fragment, null, state.isScrolling && Array.from(new Array(state.numPages), function (_, index) {
2829
- return createElement(ChakraPage, {
2830
- key: "page_" + (index + 1),
2831
- width: containerSize == null ? void 0 : containerSize.width,
2832
- scale: state.scale,
2833
- pageNumber: index + 1
2834
- });
2835
- }), !state.isScrolling && createElement(ChakraPage, {
2836
- pageNumber: state.pageNumber,
2837
- onLoadSuccess: onRenderSuccess,
2838
- width: state.pageWidth,
2839
- height: state.pageHeight,
2840
- scale: state.scale,
2841
- loading: createElement(Fragment, null)
2842
- })))),
2843
- state: state,
2844
- manifest: manifest,
2845
- navigator: {
2846
- goForward: goForward,
2847
- goBackward: goBackward,
2848
- setColorMode: setColorMode,
2849
- setScroll: setScroll,
2850
- increaseFontSize: increaseFontSize,
2851
- decreaseFontSize: decreaseFontSize,
2852
- setFontFamily: setFontFamily,
2853
- goToPage: goToPage
2854
- }
2855
- };
2856
- }
2857
-
2858
- var origin = window.location.origin;
2859
- var injectables = [{
2860
- type: 'style',
2861
- url: origin + "/css/ReadiumCSS-before.css",
2862
- r2before: true
2863
- }, {
2864
- type: 'style',
2865
- url: origin + "/css/ReadiumCSS-default.css",
2866
- r2default: true
2867
- }, {
2868
- type: 'style',
2869
- url: origin + "/css/ReadiumCSS-after.css",
2870
- r2after: true
2871
- }, {
2872
- type: 'style',
2873
- url: origin + "/fonts/opendyslexic/opendyslexic.css",
2874
- fontFamily: 'opendyslexic'
2875
- }];
2876
-
2877
- function htmlReducer(state, action) {
2878
- switch (action.type) {
2879
- case 'SET_READER':
2880
- {
2881
- var _r2FamilyToFamily$set;
2882
-
2883
- // set all the initial settings taken from the reader
2884
- var settings = action.reader.currentSettings;
2885
- return {
2886
- reader: action.reader,
2887
- isScrolling: settings.verticalScroll,
2888
- colorMode: getColorMode(settings.appearance),
2889
- fontSize: settings.fontSize,
2890
- fontFamily: (_r2FamilyToFamily$set = r2FamilyToFamily[settings.fontFamily]) != null ? _r2FamilyToFamily$set : 'publisher',
2891
- currentTocUrl: action.reader.mostRecentNavigatedTocItem()
2892
- };
2893
- }
2894
-
2895
- case 'SET_COLOR_MODE':
2896
- return _extends({}, state, {
2897
- colorMode: action.mode
2898
- });
2899
-
2900
- case 'SET_SCROLL':
2901
- return _extends({}, state, {
2902
- isScrolling: action.isScrolling
2903
- });
2904
-
2905
- case 'SET_FONT_SIZE':
2906
- return _extends({}, state, {
2907
- fontSize: action.size
2908
- });
2909
-
2910
- case 'SET_FONT_FAMILY':
2911
- return _extends({}, state, {
2912
- fontFamily: action.family
2913
- });
2914
-
2915
- case 'SET_CURRENT_TOC_URL':
2916
- return _extends({}, state, {
2917
- currentTocUrl: action.currentTocUrl
2918
- });
2919
- }
2920
- }
2921
-
2922
- var FONT_SIZE_STEP = 4;
2923
- function useHtmlReader(args) {
2924
- var _ref = args != null ? args : {},
2925
- webpubManifestUrl = _ref.webpubManifestUrl,
2926
- manifest = _ref.manifest,
2927
- getContent = _ref.getContent;
2928
-
2929
- var _React$useReducer = React__default.useReducer(htmlReducer, {
2930
- colorMode: 'day',
2931
- isScrolling: false,
2932
- fontSize: 16,
2933
- fontFamily: 'sans-serif',
2934
- reader: undefined,
2935
- currentTocUrl: null
2936
- }),
2937
- state = _React$useReducer[0],
2938
- dispatch = _React$useReducer[1];
2939
-
2940
- var reader = state.reader,
2941
- fontSize = state.fontSize; // initialize the reader
2942
-
2943
- React__default.useEffect(function () {
2944
- // bail out if there is no webpubManifestUrl. It indicates this format is not being used.
2945
- if (!webpubManifestUrl) return;
2946
- var url = new URL(webpubManifestUrl);
2947
- D2Reader.build({
2948
- url: url,
2949
- injectables: injectables,
2950
- injectablesFixed: [],
2951
- attributes: {
2952
- navHeight: HEADER_HEIGHT,
2953
- margin: 0
2954
- },
2955
- api: {
2956
- getContent: getContent
2957
- }
2958
- }).then(function (reader) {
2959
- dispatch({
2960
- type: 'SET_READER',
2961
- reader: reader
2962
- });
2963
- });
2964
- }, [webpubManifestUrl, getContent]); // prev and next page functions
2965
-
2966
- var goForward = React__default.useCallback(function () {
2967
- if (!reader) return;
2968
- var isLastPage = reader.atEnd();
2969
- reader.nextPage();
2970
-
2971
- if (isLastPage) {
2972
- dispatch({
2973
- type: 'SET_CURRENT_TOC_URL',
2974
- currentTocUrl: reader.mostRecentNavigatedTocItem()
2975
- });
2976
- }
2977
- }, [reader]);
2978
- var goBackward = React__default.useCallback(function () {
2979
- if (!reader) return;
2980
- var isFirstPage = reader.atStart();
2981
- reader.previousPage();
2982
-
2983
- if (isFirstPage) {
2984
- dispatch({
2985
- type: 'SET_CURRENT_TOC_URL',
2986
- currentTocUrl: reader.mostRecentNavigatedTocItem()
2987
- });
2988
- }
2989
- }, [reader]);
2990
- var setColorMode = React__default.useCallback( /*#__PURE__*/function () {
2991
- var _ref2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(mode) {
2992
- return runtime_1.wrap(function _callee$(_context) {
2993
- while (1) {
2994
- switch (_context.prev = _context.next) {
2995
- case 0:
2996
- if (reader) {
2997
- _context.next = 2;
2998
- break;
2999
- }
3000
-
3001
- return _context.abrupt("return");
3002
-
3003
- case 2:
3004
- dispatch({
3005
- type: 'SET_COLOR_MODE',
3006
- mode: mode
3007
- });
3008
- _context.next = 5;
3009
- return reader.applyUserSettings({
3010
- appearance: mode
3011
- });
3012
-
3013
- case 5:
3014
- case "end":
3015
- return _context.stop();
3016
- }
3017
- }
3018
- }, _callee);
3019
- }));
3020
-
3021
- return function (_x) {
3022
- return _ref2.apply(this, arguments);
3023
- };
3024
- }(), [reader]);
3025
- var setScroll = React__default.useCallback( /*#__PURE__*/function () {
3026
- var _ref3 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(val) {
3027
- var isScrolling;
3028
- return runtime_1.wrap(function _callee2$(_context2) {
3029
- while (1) {
3030
- switch (_context2.prev = _context2.next) {
3031
- case 0:
3032
- isScrolling = val === 'scrolling';
3033
- _context2.next = 3;
3034
- return reader == null ? void 0 : reader.scroll(isScrolling);
3035
-
3036
- case 3:
3037
- dispatch({
3038
- type: 'SET_SCROLL',
3039
- isScrolling: isScrolling
3040
- });
3041
-
3042
- case 4:
3043
- case "end":
3044
- return _context2.stop();
3045
- }
3046
- }
3047
- }, _callee2);
3048
- }));
3049
-
3050
- return function (_x2) {
3051
- return _ref3.apply(this, arguments);
3052
- };
3053
- }(), [reader]);
3054
- var increaseFontSize = React__default.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
3055
- var newSize;
3056
- return runtime_1.wrap(function _callee3$(_context3) {
3057
- while (1) {
3058
- switch (_context3.prev = _context3.next) {
3059
- case 0:
3060
- if (reader) {
3061
- _context3.next = 2;
3062
- break;
3063
- }
3064
-
3065
- return _context3.abrupt("return");
3066
-
3067
- case 2:
3068
- newSize = fontSize + FONT_SIZE_STEP;
3069
- _context3.next = 5;
3070
- return reader.applyUserSettings({
3071
- fontSize: newSize
3072
- });
3073
-
3074
- case 5:
3075
- dispatch({
3076
- type: 'SET_FONT_SIZE',
3077
- size: newSize
3078
- });
3079
-
3080
- case 6:
3081
- case "end":
3082
- return _context3.stop();
3083
- }
3084
- }
3085
- }, _callee3);
3086
- })), [reader, fontSize]);
3087
- var decreaseFontSize = React__default.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4() {
3088
- var newSize;
3089
- return runtime_1.wrap(function _callee4$(_context4) {
3090
- while (1) {
3091
- switch (_context4.prev = _context4.next) {
3092
- case 0:
3093
- if (reader) {
3094
- _context4.next = 2;
3095
- break;
3096
- }
3097
-
3098
- return _context4.abrupt("return");
3099
-
3100
- case 2:
3101
- newSize = fontSize - FONT_SIZE_STEP;
3102
- _context4.next = 5;
3103
- return reader.applyUserSettings({
3104
- fontSize: newSize
3105
- });
3106
-
3107
- case 5:
3108
- dispatch({
3109
- type: 'SET_FONT_SIZE',
3110
- size: newSize
3111
- });
3112
-
3113
- case 6:
3114
- case "end":
3115
- return _context4.stop();
3116
- }
3117
- }
3118
- }, _callee4);
3119
- })), [reader, fontSize]);
3120
- var setFontFamily = React__default.useCallback( /*#__PURE__*/function () {
3121
- var _ref6 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(family) {
3122
- var r2Family;
3123
- return runtime_1.wrap(function _callee5$(_context5) {
3124
- while (1) {
3125
- switch (_context5.prev = _context5.next) {
3126
- case 0:
3127
- if (reader) {
3128
- _context5.next = 2;
3129
- break;
3130
- }
3131
-
3132
- return _context5.abrupt("return");
3133
-
3134
- case 2:
3135
- r2Family = familyToR2Family[family]; // the applyUserSettings type is incorrect. We are supposed to pass in a string.
3136
-
3137
- _context5.next = 5;
3138
- return reader.applyUserSettings({
3139
- fontFamily: r2Family
3140
- });
3141
-
3142
- case 5:
3143
- dispatch({
3144
- type: 'SET_FONT_FAMILY',
3145
- family: family
3146
- });
3147
-
3148
- case 6:
3149
- case "end":
3150
- return _context5.stop();
3151
- }
3152
- }
3153
- }, _callee5);
3154
- }));
3155
-
3156
- return function (_x3) {
3157
- return _ref6.apply(this, arguments);
3158
- };
3159
- }(), [reader]);
3160
- var goToPage = React__default.useCallback(function (href) {
3161
- if (!reader) return; // Adding try/catch here because goTo throws a TypeError
3162
- // if the TOC link you clicked on was the current page..
3163
-
3164
- try {
3165
- reader.goTo({
3166
- href: href
3167
- }); // This needs to be fixed, locations should be optional.
3168
-
3169
- dispatch({
3170
- type: 'SET_CURRENT_TOC_URL',
3171
- currentTocUrl: href
3172
- });
3173
- } catch (error) {
3174
- console.error(error);
3175
- }
3176
- }, [reader]);
3177
- var isLoading = !reader; // this format is inactive, return null
3178
-
3179
- if (!webpubManifestUrl || !manifest) return null; // we are initializing the reader
3180
-
3181
- if (isLoading) {
3182
- return {
3183
- type: null,
3184
- isLoading: true,
3185
- content: React__default.createElement(HtmlReaderContent, null),
3186
- navigator: null,
3187
- manifest: null,
3188
- state: null
3189
- };
3190
- } // the reader is active
3191
-
3192
-
3193
- return {
3194
- type: 'HTML',
3195
- isLoading: false,
3196
- content: React__default.createElement(HtmlReaderContent, null),
3197
- state: state,
3198
- manifest: manifest,
3199
- navigator: {
3200
- goForward: goForward,
3201
- goBackward: goBackward,
3202
- setColorMode: setColorMode,
3203
- setScroll: setScroll,
3204
- increaseFontSize: increaseFontSize,
3205
- decreaseFontSize: decreaseFontSize,
3206
- setFontFamily: setFontFamily,
3207
- goToPage: goToPage
3208
- }
3209
- };
3210
- }
3211
-
3212
- function getColorMode(d2Mode) {
3213
- switch (d2Mode) {
3214
- case 'readium-default-on':
3215
- return 'day';
3216
-
3217
- case 'readium-night-on':
3218
- return 'night';
3219
-
3220
- case 'readium-sepia-on':
3221
- return 'sepia';
3222
-
3223
- default:
3224
- console.error('COLOR MODE SLIPPED THROUG', d2Mode);
3225
- return 'day';
3226
- }
3227
- }
3228
- /**
3229
- * We need to map from our family values to R2D2BC's family values.
3230
- */
3231
-
3232
-
3233
- var familyToR2Family = {
3234
- publisher: 'Original',
3235
- serif: 'serif',
3236
- 'sans-serif': 'sans-serif',
3237
- 'open-dyslexic': 'opendyslexic'
3238
- };
3239
- /**
3240
- * And vice-versa
3241
- */
3242
-
3243
- var r2FamilyToFamily = {
3244
- Original: 'publisher',
3245
- serif: 'serif',
3246
- 'sans-serif': 'sans-serif',
3247
- opendyslexic: 'open-dyslexic'
3248
- };
3249
-
3250
- // a webpub pdf collection
3251
- var WebpubPdfConformsTo = 'https://librarysimplified.org/terms/profiles/pdf'; // a webpub of axisnow content
3252
-
3253
- var AxisNowEpubConformsTo = 'stub/webpub+axisnow';
3254
-
3255
- function getReaderType(conformsTo) {
3256
- switch (conformsTo) {
3257
- case AxisNowEpubConformsTo:
3258
- return 'HTML';
3259
-
3260
- case WebpubPdfConformsTo:
3261
- return 'PDF';
3262
-
3263
- case undefined:
3264
- // the manifest didn't indicate any conformsTo,
3265
- // so return our default
3266
- return 'HTML';
3267
-
3268
- case null:
3269
- // the manifest is still loading, return undefined
3270
- return undefined;
3271
- }
3272
- }
3273
- /**
3274
- * The React hook that exposes the main API into the reader. It
3275
- * will determine the type of the webpub, and then use the correct reader
3276
- * for that type.
3277
- */
3278
-
3279
-
3280
- function useWebReader(args) {
3281
- var webpubManifestUrl = args.webpubManifestUrl,
3282
- getContent = args.getContent,
3283
- proxyUrl = args.proxyUrl;
3284
-
3285
- var _React$useState = React__default.useState(null),
3286
- manifest = _React$useState[0],
3287
- setManifest = _React$useState[1];
3288
-
3289
- var readerType = getReaderType(manifest ? manifest.metadata.conformsTo : null);
3290
- /**
3291
- * Our HTML reader and PDf Reader. Note that we cannot conditionally
3292
- * call a React hook, so we must _always_ call the hook, but allow for the
3293
- * case where we call the hook with `undefined`, which tells the hook that
3294
- * that format is inactive, and it will in turn return the InactiveState.
3295
- */
3296
-
3297
- var htmlReader = useHtmlReader(readerType === 'HTML' && manifest ? {
3298
- webpubManifestUrl: webpubManifestUrl,
3299
- manifest: manifest,
3300
- getContent: getContent
3301
- } : undefined);
3302
- var pdfReader = usePdfReader(readerType === 'PDF' && manifest ? {
3303
- webpubManifestUrl: webpubManifestUrl,
3304
- manifest: manifest,
3305
- proxyUrl: proxyUrl
3306
- } : undefined); // fetch the manifest and set it in state
3307
-
3308
- React__default.useEffect(function () {
3309
- fetchJson(webpubManifestUrl).then(setManifest);
3310
- }, [webpubManifestUrl]); // first if we are still fetching the manifest, return loading
3311
-
3312
- if (manifest === null) {
3313
- return {
3314
- isLoading: true,
3315
- content: React__default.createElement(HtmlReaderContent, null),
3316
- manifest: null,
3317
- navigator: null,
3318
- state: null,
3319
- type: null
3320
- };
3321
- }
3322
- /**
3323
- * Return whichever reader is not Inactive (not `null`)
3324
- */
3325
-
3326
-
3327
- if (htmlReader) {
3328
- return htmlReader;
3329
- }
3330
-
3331
- if (pdfReader) {
3332
- return pdfReader;
3333
- }
3334
-
3335
- throw new Error("No reader was initialized for the webpub with url: " + webpubManifestUrl + " and type: " + readerType + ".");
3336
- }
3337
-
3338
- /**
3339
- * The main React component export.
3340
- */
3341
-
3342
- var WebReader = function WebReader(_ref) {
3343
- var webpubManifestUrl = _ref.webpubManifestUrl,
3344
- proxyUrl = _ref.proxyUrl,
3345
- getContent = _ref.getContent;
3346
- var webReader = useWebReader({
3347
- webpubManifestUrl: webpubManifestUrl,
3348
- proxyUrl: proxyUrl,
3349
- getContent: getContent
3350
- });
3351
- var content = webReader.content;
3352
- return React__default.createElement(ManagerUI, Object.assign({}, webReader), content);
3353
- };
3354
-
3355
- export default WebReader;
3356
- //# sourceMappingURL=web-reader.esm.js.map