@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
package/src/types.ts DELETED
@@ -1,94 +0,0 @@
1
- import { WebpubManifest } from './WebpubManifestTypes/WebpubManifest';
2
-
3
- export { WebpubManifest };
4
-
5
- // the MimeType for a packaged epub
6
- export const EpubMimeType = 'application/epub';
7
- // the Mimetype for a generic webpub
8
- export const WebpubMimeType = 'application/webpub';
9
-
10
- export type ColorMode = 'night' | 'sepia' | 'day';
11
-
12
- export type FontFamily = 'publisher' | 'serif' | 'sans-serif' | 'open-dyslexic';
13
-
14
- export type Navigator = {
15
- goForward: () => void;
16
- goBackward: () => void;
17
- setColorMode: (mode: ColorMode) => Promise<void>;
18
- setScroll: (val: 'scrolling' | 'paginated') => Promise<void>;
19
- increaseFontSize: () => Promise<void>;
20
- decreaseFontSize: () => Promise<void>;
21
- setFontFamily: (family: FontFamily) => Promise<void>;
22
- goToPage: (href: string) => void;
23
- };
24
-
25
- // PDF specific navigator here
26
- export type PdfNavigator = Navigator;
27
-
28
- export type HtmlNavigator = Navigator;
29
-
30
- export type ReaderState = {
31
- colorMode: ColorMode;
32
- isScrolling: boolean;
33
- fontSize: number;
34
- fontFamily: FontFamily;
35
- currentTocUrl: string | null;
36
- };
37
-
38
- // PDF specific reader state
39
- export type PdfReaderState = ReaderState;
40
-
41
- // HTML specific reader state
42
- export type HtmlReaderState = ReaderState;
43
-
44
- export type InactiveReader = null;
45
-
46
- export type LoadingReader = {
47
- isLoading: true;
48
- content: JSX.Element;
49
- navigator: null;
50
- state: null;
51
- manifest: null;
52
- type: null;
53
- };
54
-
55
- type CommonReader = {
56
- isLoading: false;
57
- content: JSX.Element;
58
- manifest: WebpubManifest;
59
- };
60
-
61
- export type PDFActiveReader = CommonReader & {
62
- state: PdfReaderState;
63
- navigator: PdfNavigator;
64
- type: 'PDF';
65
- };
66
-
67
- export type HTMLActiveReader = CommonReader & {
68
- state: HtmlReaderState;
69
- navigator: HtmlNavigator;
70
- type: 'HTML';
71
- };
72
-
73
- export type ActiveReader = PDFActiveReader | HTMLActiveReader;
74
-
75
- export type ReaderReturn = InactiveReader | LoadingReader | ActiveReader;
76
-
77
- // should fetch and decrypt a resource
78
- export type GetContent = (href: string) => Promise<string>;
79
-
80
- export type UseWebReaderArguments = {
81
- webpubManifestUrl: string;
82
- proxyUrl?: string;
83
- getContent?: GetContent;
84
- };
85
-
86
- export type ActiveReaderArguments = UseWebReaderArguments & {
87
- manifest: WebpubManifest;
88
- };
89
-
90
- export type InactiveReaderArguments = undefined;
91
-
92
- export type ReaderArguments = ActiveReaderArguments | InactiveReaderArguments;
93
-
94
- export type GetColor = (light: string, dark: string, sepia: string) => string;
package/src/ui/Button.tsx DELETED
@@ -1,12 +0,0 @@
1
- import React from 'react';
2
- import { Button as ChakraButton } from '@chakra-ui/react';
3
-
4
- export type ButtonProps = React.ComponentPropsWithRef<typeof ChakraButton>;
5
-
6
- const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
7
- (props, ref) => {
8
- return <ChakraButton ref={ref} variant="solid" {...props} />;
9
- }
10
- );
11
-
12
- export default Button;
package/src/ui/Header.tsx DELETED
@@ -1,89 +0,0 @@
1
- import React from 'react';
2
- import { Flex, Link, HStack, Text, chakra } from '@chakra-ui/react';
3
- import {
4
- Icon,
5
- IconNames,
6
- LogoNames,
7
- } from '@nypl/design-system-react-components';
8
- import { ActiveReader } from '../types';
9
- import useColorModeValue from '../ui/hooks/useColorModeValue';
10
- import { toggleFullScreen } from '../utils/toggleFullScreen';
11
-
12
- import SettingsCard from './SettingsButton';
13
- import Button from './Button';
14
- import TableOfContent from './TableOfContent';
15
- import { HEADER_HEIGHT } from './constants';
16
-
17
- export type HeaderProps = ActiveReader & {
18
- headerLeft?: React.ReactNode; // Top-left header section
19
- };
20
-
21
- export default function Header(props: HeaderProps): React.ReactElement {
22
- const { headerLeft, state, navigator, manifest } = props;
23
- const linkColor = useColorModeValue('gray.700', 'gray.100', 'gray.700');
24
- const mainBgColor = useColorModeValue('ui.white', 'ui.black', 'ui.sepia');
25
-
26
- // Add custom styles to the NYPL Icon
27
- const ChakraIcon = chakra(Icon, {
28
- baseStyle: {
29
- height: '100%',
30
- },
31
- });
32
-
33
- return (
34
- <Flex
35
- as="header"
36
- position="sticky"
37
- top={0}
38
- left={0}
39
- right={0}
40
- height={`${HEADER_HEIGHT}px`}
41
- zIndex="sticky"
42
- alignContent="space-between"
43
- alignItems="center"
44
- px={8}
45
- borderBottom="1px solid"
46
- borderColor="gray.100"
47
- bgColor={mainBgColor}
48
- >
49
- {headerLeft ? (
50
- headerLeft
51
- ) : (
52
- <Link
53
- href="https://www.nypl.org"
54
- aria-label="Return to NYPL"
55
- tabIndex={0}
56
- fontSize={0}
57
- py={1}
58
- textTransform="uppercase"
59
- d="flex"
60
- color={linkColor}
61
- height="100%"
62
- alignItems="center"
63
- _hover={{
64
- textDecoration: 'none',
65
- }}
66
- >
67
- <ChakraIcon
68
- decorative
69
- name={LogoNames.logo_nypl}
70
- modifiers={['xlarge']}
71
- />
72
- <Text variant="headerNav">Return to NYPL</Text>
73
- </Link>
74
- )}
75
- <HStack ml="auto" spacing={1}>
76
- <TableOfContent
77
- navigator={navigator}
78
- manifest={manifest}
79
- readerState={state}
80
- />
81
- <SettingsCard {...props} />
82
- <Button border="none" onClick={toggleFullScreen}>
83
- <Icon decorative name={IconNames.search} modifiers={['small']} />
84
- <Text variant="headerNav">Toggle Fullscreen</Text>
85
- </Button>
86
- </HStack>
87
- </Flex>
88
- );
89
- }
@@ -1,97 +0,0 @@
1
- import * as React from 'react';
2
- import { ButtonGroup } from '@chakra-ui/react';
3
- import { HtmlNavigator, HtmlReaderState } from '../types';
4
- import Button from './Button';
5
- import ToggleButton from './ToggleButton';
6
- import ToggleGroup from './ToggleGroup';
7
-
8
- type HtmlSettingsProps = {
9
- navigator: HtmlNavigator;
10
- readerState: HtmlReaderState;
11
- paginationValue: string;
12
- };
13
-
14
- export default function HtmlSettings(
15
- props: HtmlSettingsProps
16
- ): React.ReactElement {
17
- const { navigator, readerState, paginationValue } = props;
18
- const { fontFamily, colorMode } = readerState;
19
- const {
20
- setFontFamily,
21
- decreaseFontSize,
22
- increaseFontSize,
23
- setColorMode,
24
- setScroll,
25
- } = navigator;
26
-
27
- return (
28
- <>
29
- <ToggleGroup
30
- value={fontFamily}
31
- label="text font options"
32
- onChange={setFontFamily}
33
- >
34
- <ToggleButton value="publisher">Publisher</ToggleButton>
35
- <ToggleButton value="serif">Serif</ToggleButton>
36
- <ToggleButton value="sans-serif">Sans-Serif</ToggleButton>
37
- <ToggleButton value="open-dyslexic">Dyslexia-Friendly</ToggleButton>
38
- </ToggleGroup>
39
- <ButtonGroup d="flex" spacing={0}>
40
- <Button
41
- flexGrow={1}
42
- aria-label="Decrease font size"
43
- onClick={decreaseFontSize}
44
- variant="toggle"
45
- >
46
- A-
47
- </Button>
48
- <Button
49
- flexGrow={1}
50
- aria-label="Increase font size"
51
- onClick={increaseFontSize}
52
- variant="toggle"
53
- >
54
- A+
55
- </Button>
56
- </ButtonGroup>
57
- <ToggleGroup
58
- value={colorMode}
59
- label="reading theme options"
60
- onChange={setColorMode}
61
- >
62
- <ToggleButton
63
- colorMode="day"
64
- value="day"
65
- _checked={{ bg: 'ui.white' }} // default _checked color is green for toggles
66
- >
67
- Day
68
- </ToggleButton>
69
- <ToggleButton
70
- colorMode="sepia"
71
- value="sepia"
72
- bg="ui.sepia" // distinct case where default needs to be sepia
73
- _active={{ bg: 'ui.sepia' }}
74
- _hover={{ bg: 'ui.sepia' }}
75
- _checked={{ bg: 'ui.sepia' }}
76
- >
77
- Sepia
78
- </ToggleButton>
79
- <ToggleButton
80
- colorMode="night"
81
- value="night"
82
- _checked={{ bg: 'ui.black' }}
83
- >
84
- Night
85
- </ToggleButton>
86
- </ToggleGroup>
87
- <ToggleGroup
88
- onChange={setScroll}
89
- value={paginationValue}
90
- label="pagination options"
91
- >
92
- <ToggleButton value="paginated">Paginated</ToggleButton>
93
- <ToggleButton value="scrolling">Scrolling</ToggleButton>
94
- </ToggleGroup>
95
- </>
96
- );
97
- }
@@ -1,39 +0,0 @@
1
- import React from 'react';
2
- import { Circle as ChakraCircle, Button } from '@chakra-ui/react';
3
- import useColorModeValue from './hooks/useColorModeValue';
4
-
5
- export type PageButtonProps = React.ComponentPropsWithoutRef<typeof Button> & {
6
- children: React.ReactNode;
7
- };
8
-
9
- function PageButton(
10
- props: React.PropsWithoutRef<PageButtonProps>
11
- ): React.ReactElement {
12
- const { children, onClick, ...rest } = props;
13
- const circleColor = useColorModeValue('ui.black', 'ui.white', 'ui.black');
14
- const circleBgColor = useColorModeValue('ui.white', 'gray.700', 'ui.white');
15
-
16
- return (
17
- <ChakraCircle
18
- as="button"
19
- d="flex"
20
- position="fixed"
21
- zIndex="docked"
22
- alignItems="center"
23
- border="1px solid"
24
- borderColor="ui.gray.light-cool"
25
- color={circleColor}
26
- bg={circleBgColor}
27
- size={{ sm: '40px', md: '50px' }}
28
- mx={{ sm: 2, md: 6 }}
29
- top="50%"
30
- cursor="pointer"
31
- onClick={onClick}
32
- {...rest}
33
- >
34
- {children}
35
- </ChakraCircle>
36
- );
37
- }
38
-
39
- export default PageButton;
@@ -1,85 +0,0 @@
1
- import * as React from 'react';
2
- import { ButtonGroup, Circle } from '@chakra-ui/react';
3
- import { Icon, IconNames } from '@nypl/design-system-react-components';
4
- import { PdfNavigator, PdfReaderState } from '../types';
5
- import Button from './Button';
6
- import ToggleButton from './ToggleButton';
7
- import ToggleGroup from './ToggleGroup';
8
-
9
- type PdfSettingsProps = {
10
- navigator: PdfNavigator;
11
- readerState: PdfReaderState;
12
- paginationValue: string;
13
- };
14
-
15
- export default function PdfSettings(
16
- props: PdfSettingsProps
17
- ): React.ReactElement {
18
- const { navigator, readerState, paginationValue } = props;
19
- const { fontFamily } = readerState;
20
- const {
21
- setFontFamily,
22
- decreaseFontSize,
23
- increaseFontSize,
24
- setScroll,
25
- } = navigator;
26
-
27
- return (
28
- <>
29
- <ToggleGroup
30
- value={fontFamily}
31
- label="text font options"
32
- onChange={setFontFamily}
33
- >
34
- <ToggleButton value="publisher">Publisher</ToggleButton>
35
- <ToggleButton value="serif">Serif</ToggleButton>
36
- <ToggleButton value="sans-serif">Sans-Serif</ToggleButton>
37
- <ToggleButton value="open-dyslexic">Dyslexia-Friendly</ToggleButton>
38
- </ToggleGroup>
39
- <ButtonGroup d="flex" spacing={0}>
40
- <Button
41
- flexGrow={1}
42
- aria-label="Zoom In"
43
- onClick={decreaseFontSize}
44
- variant="toggle"
45
- >
46
- Zoom
47
- <Circle
48
- border="1px solid"
49
- p={1}
50
- ml={1}
51
- size="17px"
52
- alignItems="baseline"
53
- >
54
- <Icon decorative name={IconNames.minus} modifiers={['small']} />{' '}
55
- </Circle>
56
- </Button>
57
- <Button
58
- flexGrow={1}
59
- aria-label="Zoom Out"
60
- onClick={increaseFontSize}
61
- variant="toggle"
62
- >
63
- Zoom
64
- <Circle
65
- border="1px solid"
66
- p={1}
67
- ml={1}
68
- size="17px"
69
- alignItems="baseline"
70
- >
71
- <Icon decorative name={IconNames.plus} modifiers={['small']} />{' '}
72
- </Circle>
73
- </Button>
74
- </ButtonGroup>
75
- <ToggleGroup
76
- onChange={setScroll}
77
- value={paginationValue}
78
- label="pagination options"
79
- >
80
- <ToggleButton value="paginated">Paginated</ToggleButton>
81
- <ToggleButton value="scrolling">Scrolling</ToggleButton>
82
- </ToggleGroup>
83
- </>
84
- );
85
- }
@@ -1,71 +0,0 @@
1
- import * as React from 'react';
2
- import {
3
- Popover,
4
- PopoverTrigger,
5
- PopoverContent,
6
- PopoverBody,
7
- Text,
8
- } from '@chakra-ui/react';
9
- import { PDFActiveReader, HTMLActiveReader } from '../types';
10
- import { Icon, IconNames } from '@nypl/design-system-react-components';
11
-
12
- import Button from './Button';
13
- import useColorModeValue from './hooks/useColorModeValue';
14
- import PdfSettings from './PdfSettings';
15
- import HtmlSettings from './HtmlSettings';
16
-
17
- type SettingsCardProps =
18
- | Pick<PDFActiveReader, 'navigator' | 'state' | 'type'>
19
- | Pick<HTMLActiveReader, 'navigator' | 'state' | 'type'>;
20
-
21
- export default function SettingsCard(
22
- props: SettingsCardProps
23
- ): React.ReactElement {
24
- const [isOpen, setIsOpen] = React.useState(false);
25
- const open = () => setIsOpen(!isOpen);
26
- const close = () => setIsOpen(false);
27
-
28
- const { navigator, state, type } = props;
29
- const paginationValue = state?.isScrolling ? 'scrolling' : 'paginated';
30
- const contentBgColor = useColorModeValue('ui.white', 'ui.black', 'ui.white');
31
-
32
- return (
33
- <>
34
- <Popover
35
- placement="bottom"
36
- isOpen={isOpen}
37
- onClose={close}
38
- autoFocus={true}
39
- >
40
- <PopoverTrigger>
41
- <Button onClick={open} border="none">
42
- <Icon decorative name={IconNames.plus} modifiers={['small']} />{' '}
43
- <Text variant="headerNav">Settings</Text>
44
- </Button>
45
- </PopoverTrigger>
46
- <PopoverContent
47
- borderColor="gray.100"
48
- width="fit-content"
49
- bgColor={contentBgColor}
50
- >
51
- <PopoverBody p={0} maxWidth="95vw">
52
- {type === 'PDF' && (
53
- <PdfSettings
54
- navigator={navigator}
55
- readerState={state}
56
- paginationValue={paginationValue}
57
- />
58
- )}
59
- {type === 'HTML' && (
60
- <HtmlSettings
61
- navigator={navigator}
62
- readerState={state}
63
- paginationValue={paginationValue}
64
- />
65
- )}
66
- </PopoverBody>
67
- </PopoverContent>
68
- </Popover>
69
- </>
70
- );
71
- }
@@ -1,144 +0,0 @@
1
- import React, { useState } from 'react';
2
- import {
3
- Link,
4
- Menu,
5
- MenuButton,
6
- MenuItem,
7
- MenuList,
8
- Portal,
9
- Text,
10
- } from '@chakra-ui/react';
11
- import { Icon, IconNames } from '@nypl/design-system-react-components';
12
- import { Navigator, ReaderState, WebpubManifest } from '../types';
13
- import Button from './Button';
14
- import useColorModeValue from './hooks/useColorModeValue';
15
- import { ReadiumLink } from '../WebpubManifestTypes/ReadiumLink';
16
- import { HEADER_HEIGHT } from './constants';
17
-
18
- type TocItemProps = React.ComponentPropsWithoutRef<typeof MenuItem> & {
19
- href: string;
20
- title: string | undefined;
21
- isActive: boolean;
22
- onClick: React.MouseEventHandler<HTMLButtonElement | HTMLAnchorElement>;
23
- };
24
-
25
- const TocItem = (props: TocItemProps) => {
26
- const { href, title, isActive, ...rest } = props;
27
-
28
- const bgColor = useColorModeValue('ui.white', 'ui.black', 'ui.sepia');
29
- const color = useColorModeValue('ui.black', 'ui.white', 'ui.black');
30
- const borderColor = useColorModeValue(
31
- 'ui.gray.medium',
32
- 'gray.500',
33
- 'yellow.600'
34
- );
35
-
36
- const activeColor = 'ui.black';
37
- const activeBgColor = 'ui.gray.light-cool';
38
-
39
- const _hover = {
40
- textDecoration: 'none',
41
- background: isActive ? 'ui.black' : 'ui.gray.x-dark',
42
- color: 'ui.white',
43
- };
44
-
45
- const _focus = {
46
- ..._hover,
47
- boxShadow: 'none',
48
- };
49
-
50
- const styles = {
51
- background: isActive ? activeBgColor : bgColor,
52
- color: isActive ? activeColor : color,
53
- borderBottom: `1px solid`,
54
- borderColor: borderColor,
55
- py: 3,
56
- _hover,
57
- _focus,
58
- };
59
-
60
- return (
61
- <MenuItem as={Link} href={href} {...styles} {...rest}>
62
- {title}
63
- </MenuItem>
64
- );
65
- };
66
-
67
- export default function TableOfContent({
68
- navigator,
69
- manifest,
70
- readerState,
71
- }: {
72
- navigator: Navigator;
73
- manifest: WebpubManifest;
74
- readerState: ReaderState;
75
- }): React.ReactElement {
76
- const [isOpen, setIsOpen] = useState(false);
77
- const tocLinkHandler: React.MouseEventHandler<HTMLButtonElement> = (evt) => {
78
- evt.preventDefault();
79
- const href = evt.currentTarget.getAttribute('href');
80
- if (!href) {
81
- console.warn('TOC Link clicked without an href');
82
- return;
83
- }
84
- navigator.goToPage(href);
85
- setIsOpen(false);
86
- };
87
-
88
- const tocBgColor = useColorModeValue('ui.white', 'ui.black', 'ui.sepia');
89
-
90
- const getLinkHref = (link: ReadiumLink): string => {
91
- if (link.href) return link.href;
92
- if (!link.children) throw new Error('Manifest is not well formed');
93
- return getLinkHref(link.children[0]);
94
- };
95
-
96
- return (
97
- <Menu
98
- onOpen={() => setIsOpen(true)}
99
- onClose={() => setIsOpen(false)} // To account for "close by lose focus"
100
- >
101
- <MenuButton as={Button} border="none">
102
- <Icon decorative name={IconNames.download} modifiers={['small']} />
103
- <Text variant="headerNav">Table of Contents</Text>
104
- </MenuButton>
105
- {isOpen && manifest?.toc && (
106
- <Portal>
107
- <MenuList
108
- width="100vw"
109
- height={`calc(100vh - ${HEADER_HEIGHT}px)`}
110
- background={tocBgColor}
111
- borderRadius="none"
112
- borderColor={tocBgColor}
113
- zIndex="popover"
114
- px={7}
115
- mt="-2px" // Move the popover slightly higher to hide Header border
116
- overflow="auto"
117
- >
118
- {manifest.toc.map((content: ReadiumLink) => (
119
- <React.Fragment key={content.title}>
120
- <TocItem
121
- href={getLinkHref(content)}
122
- title={content.title}
123
- isActive={readerState?.currentTocUrl === content.href}
124
- onClick={tocLinkHandler}
125
- />
126
- {content.children &&
127
- content.children.map((subLink) => (
128
- <TocItem
129
- key={subLink.title}
130
- href={getLinkHref(subLink)}
131
- title={subLink.title}
132
- isActive={readerState?.currentTocUrl === subLink.href}
133
- onClick={tocLinkHandler}
134
- pl={10}
135
- />
136
- ))}
137
- </React.Fragment>
138
- ))}
139
- </MenuList>
140
- </Portal>
141
- )}
142
- </Menu>
143
- );
144
- }
@@ -1,60 +0,0 @@
1
- import React from 'react';
2
- import {
3
- Box as ChakraBox,
4
- Circle,
5
- ThemeProvider,
6
- useRadio,
7
- useTheme,
8
- } from '@chakra-ui/react';
9
- import { Icon, IconNames } from '@nypl/design-system-react-components';
10
-
11
- import Button from './Button';
12
- import { getTheme } from './theme';
13
- import { ColorMode } from '../types';
14
-
15
- export interface ToggleButtonProps
16
- extends React.ComponentPropsWithoutRef<typeof ChakraBox> {
17
- isChecked?: false;
18
- colorMode?: ColorMode;
19
- value: string;
20
- }
21
-
22
- function ToggleButton(
23
- props: React.PropsWithoutRef<ToggleButtonProps>
24
- ): React.ReactElement {
25
- const { isChecked, children, colorMode, ...rest } = props;
26
- const { getInputProps, getCheckboxProps } = useRadio(props);
27
-
28
- const input = getInputProps();
29
- const checkbox = getCheckboxProps();
30
- const theme = useTheme();
31
-
32
- return (
33
- // This will override the default theme if we specify the colorMode to the toggle button.
34
- <ThemeProvider theme={getTheme(colorMode ?? theme.currentColorMode)}>
35
- <ChakraBox as="label" d="flex" flexGrow={1}>
36
- <input {...input} />
37
- <Button as="div" {...checkbox} variant="toggle" {...rest} flexGrow={1}>
38
- {children}
39
- {isChecked && (
40
- <Circle
41
- position="absolute"
42
- verticalAlign="middle"
43
- right={2}
44
- top="50%"
45
- transform="translateY(-50%)"
46
- borderColor="white"
47
- border="1px solid"
48
- size="15px"
49
- alignItems="baseline"
50
- >
51
- <Icon decorative name={IconNames.check} modifiers={['small']} />
52
- </Circle>
53
- )}
54
- </Button>
55
- </ChakraBox>
56
- </ThemeProvider>
57
- );
58
- }
59
-
60
- export default ToggleButton;