@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,262 +0,0 @@
1
- import D2Reader from '@d-i-t-a/reader';
2
- import React from 'react';
3
- import injectables from './injectables';
4
- import {
5
- ColorMode,
6
- HtmlReaderState,
7
- ReaderReturn,
8
- ReaderArguments,
9
- FontFamily,
10
- } from '../types';
11
- import HtmlReaderContent from './HtmlReaderContent';
12
- import { Locator } from '@d-i-t-a/reader/dist/model/Locator';
13
- import { HEADER_HEIGHT } from '../ui/constants';
14
-
15
- type HtmlState = HtmlReaderState & {
16
- reader: D2Reader | undefined;
17
- };
18
-
19
- export type HtmlAction =
20
- | { type: 'SET_READER'; reader: D2Reader }
21
- | { type: 'SET_COLOR_MODE'; mode: ColorMode }
22
- | { type: 'SET_SCROLL'; isScrolling: boolean }
23
- | { type: 'SET_FONT_SIZE'; size: number }
24
- | { type: 'SET_FONT_FAMILY'; family: FontFamily }
25
- | { type: 'SET_CURRENT_TOC_URL'; currentTocUrl: string };
26
-
27
- function htmlReducer(state: HtmlState, action: HtmlAction): HtmlState {
28
- switch (action.type) {
29
- case 'SET_READER': {
30
- // set all the initial settings taken from the reader
31
- const settings = action.reader.currentSettings;
32
- return {
33
- reader: action.reader,
34
- isScrolling: settings.verticalScroll,
35
- colorMode: getColorMode(settings.appearance),
36
- fontSize: settings.fontSize,
37
- fontFamily: r2FamilyToFamily[settings.fontFamily] ?? 'publisher',
38
- currentTocUrl: action.reader.mostRecentNavigatedTocItem(), // This returns a relative href
39
- };
40
- }
41
-
42
- case 'SET_COLOR_MODE':
43
- return {
44
- ...state,
45
- colorMode: action.mode,
46
- };
47
-
48
- case 'SET_SCROLL':
49
- return {
50
- ...state,
51
- isScrolling: action.isScrolling,
52
- };
53
-
54
- case 'SET_FONT_SIZE':
55
- return {
56
- ...state,
57
- fontSize: action.size,
58
- };
59
-
60
- case 'SET_FONT_FAMILY':
61
- return {
62
- ...state,
63
- fontFamily: action.family,
64
- };
65
-
66
- case 'SET_CURRENT_TOC_URL':
67
- return {
68
- ...state,
69
- currentTocUrl: action.currentTocUrl,
70
- };
71
- }
72
- }
73
-
74
- const FONT_SIZE_STEP = 4;
75
-
76
- export default function useHtmlReader(args: ReaderArguments): ReaderReturn {
77
- const { webpubManifestUrl, manifest, getContent } = args ?? {};
78
- const [state, dispatch] = React.useReducer(htmlReducer, {
79
- colorMode: 'day',
80
- isScrolling: false,
81
- fontSize: 16,
82
- fontFamily: 'sans-serif',
83
- reader: undefined,
84
- currentTocUrl: null,
85
- });
86
-
87
- const { reader, fontSize } = state;
88
-
89
- // initialize the reader
90
- React.useEffect(() => {
91
- // bail out if there is no webpubManifestUrl. It indicates this format is not being used.
92
- if (!webpubManifestUrl) return;
93
- const url = new URL(webpubManifestUrl);
94
-
95
- D2Reader.build({
96
- url,
97
- injectables: injectables,
98
- injectablesFixed: [],
99
- attributes: {
100
- navHeight: HEADER_HEIGHT,
101
- margin: 0,
102
- },
103
- api: {
104
- getContent: getContent as any, //TODO: fix this casting,
105
- } as any, //TODO: fix this casting,,
106
- }).then((reader) => {
107
- dispatch({ type: 'SET_READER', reader });
108
- });
109
- }, [webpubManifestUrl, getContent]);
110
-
111
- // prev and next page functions
112
- const goForward = React.useCallback(() => {
113
- if (!reader) return;
114
- const isLastPage = reader.atEnd();
115
- reader.nextPage();
116
- if (isLastPage) {
117
- dispatch({
118
- type: 'SET_CURRENT_TOC_URL',
119
- currentTocUrl: reader.mostRecentNavigatedTocItem(),
120
- });
121
- }
122
- }, [reader]);
123
-
124
- const goBackward = React.useCallback(() => {
125
- if (!reader) return;
126
- const isFirstPage = reader.atStart();
127
- reader.previousPage();
128
- if (isFirstPage) {
129
- dispatch({
130
- type: 'SET_CURRENT_TOC_URL',
131
- currentTocUrl: reader.mostRecentNavigatedTocItem(),
132
- });
133
- }
134
- }, [reader]);
135
-
136
- const setColorMode = React.useCallback(
137
- async (mode: ColorMode) => {
138
- if (!reader) return;
139
- dispatch({ type: 'SET_COLOR_MODE', mode });
140
- await reader.applyUserSettings({ appearance: mode });
141
- },
142
- [reader]
143
- );
144
-
145
- const setScroll = React.useCallback(
146
- async (val: 'scrolling' | 'paginated') => {
147
- const isScrolling = val === 'scrolling';
148
- await reader?.scroll(isScrolling);
149
- dispatch({ type: 'SET_SCROLL', isScrolling });
150
- },
151
- [reader]
152
- );
153
-
154
- const increaseFontSize = React.useCallback(async () => {
155
- if (!reader) return;
156
- const newSize = fontSize + FONT_SIZE_STEP;
157
- await reader.applyUserSettings({ fontSize: newSize });
158
- dispatch({ type: 'SET_FONT_SIZE', size: newSize });
159
- }, [reader, fontSize]);
160
-
161
- const decreaseFontSize = React.useCallback(async () => {
162
- if (!reader) return;
163
- const newSize = fontSize - FONT_SIZE_STEP;
164
- await reader.applyUserSettings({ fontSize: newSize });
165
- dispatch({ type: 'SET_FONT_SIZE', size: newSize });
166
- }, [reader, fontSize]);
167
-
168
- const setFontFamily = React.useCallback(
169
- async (family: FontFamily) => {
170
- if (!reader) return;
171
- const r2Family = familyToR2Family[family];
172
- // the applyUserSettings type is incorrect. We are supposed to pass in a string.
173
- await reader.applyUserSettings({ fontFamily: r2Family as any });
174
- dispatch({ type: 'SET_FONT_FAMILY', family });
175
- },
176
- [reader]
177
- );
178
-
179
- const goToPage = React.useCallback(
180
- (href) => {
181
- if (!reader) return;
182
- // Adding try/catch here because goTo throws a TypeError
183
- // if the TOC link you clicked on was the current page..
184
- try {
185
- reader.goTo({ href } as Locator); // This needs to be fixed, locations should be optional.
186
- dispatch({ type: 'SET_CURRENT_TOC_URL', currentTocUrl: href });
187
- } catch (error) {
188
- console.error(error);
189
- }
190
- },
191
- [reader]
192
- );
193
-
194
- const isLoading = !reader;
195
-
196
- // this format is inactive, return null
197
- if (!webpubManifestUrl || !manifest) return null;
198
-
199
- // we are initializing the reader
200
- if (isLoading) {
201
- return {
202
- type: null,
203
- isLoading: true,
204
- content: <HtmlReaderContent />,
205
- navigator: null,
206
- manifest: null,
207
- state: null,
208
- };
209
- }
210
-
211
- // the reader is active
212
- return {
213
- type: 'HTML',
214
- isLoading: false,
215
- content: <HtmlReaderContent />,
216
- state,
217
- manifest,
218
- navigator: {
219
- goForward,
220
- goBackward,
221
- setColorMode,
222
- setScroll,
223
- increaseFontSize,
224
- decreaseFontSize,
225
- setFontFamily,
226
- goToPage,
227
- },
228
- };
229
- }
230
-
231
- function getColorMode(d2Mode: string): ColorMode {
232
- switch (d2Mode) {
233
- case 'readium-default-on':
234
- return 'day';
235
- case 'readium-night-on':
236
- return 'night';
237
- case 'readium-sepia-on':
238
- return 'sepia';
239
- default:
240
- console.error('COLOR MODE SLIPPED THROUG', d2Mode);
241
- return 'day';
242
- }
243
- }
244
-
245
- /**
246
- * We need to map from our family values to R2D2BC's family values.
247
- */
248
- const familyToR2Family: Record<FontFamily, string> = {
249
- publisher: 'Original',
250
- serif: 'serif',
251
- 'sans-serif': 'sans-serif',
252
- 'open-dyslexic': 'opendyslexic',
253
- };
254
- /**
255
- * And vice-versa
256
- */
257
- const r2FamilyToFamily: Record<string, FontFamily | undefined> = {
258
- Original: 'publisher',
259
- serif: 'serif',
260
- 'sans-serif': 'sans-serif',
261
- opendyslexic: 'open-dyslexic',
262
- };
@@ -1,26 +0,0 @@
1
- const origin = window.location.origin;
2
-
3
- const injectables = [
4
- {
5
- type: 'style',
6
- url: `${origin}/css/ReadiumCSS-before.css`,
7
- r2before: true,
8
- },
9
- {
10
- type: 'style',
11
- url: `${origin}/css/ReadiumCSS-default.css`,
12
- r2default: true,
13
- },
14
- {
15
- type: 'style',
16
- url: `${origin}/css/ReadiumCSS-after.css`,
17
- r2after: true,
18
- },
19
- {
20
- type: 'style',
21
- url: `${origin}/fonts/opendyslexic/opendyslexic.css`,
22
- fontFamily: 'opendyslexic',
23
- },
24
- ];
25
-
26
- export default injectables;