@prose-reader/react-reader 1.174.0 → 1.176.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/dist/common/useFullscreen.d.ts +4 -0
  2. package/dist/components/ui/avatar.d.ts +16 -0
  3. package/dist/components/ui/checkbox.d.ts +8 -0
  4. package/dist/components/ui/close-button.d.ts +4 -0
  5. package/dist/components/ui/color-mode.d.ts +19 -0
  6. package/dist/components/ui/dialog.d.ts +19 -0
  7. package/dist/components/ui/drawer.d.ts +19 -0
  8. package/dist/components/ui/field.d.ts +9 -0
  9. package/dist/components/ui/input-group.d.ts +12 -0
  10. package/dist/components/ui/popover.d.ts +17 -0
  11. package/dist/components/ui/progress.d.ts +9 -0
  12. package/dist/components/ui/provider.d.ts +2 -0
  13. package/dist/components/ui/radio.d.ts +8 -0
  14. package/dist/components/ui/slider.d.ts +11 -0
  15. package/dist/components/ui/toggle-tip.d.ts +10 -0
  16. package/dist/components/ui/tooltip.d.ts +11 -0
  17. package/dist/context/ReactReaderProvider.d.ts +5 -0
  18. package/dist/context/context.d.ts +3 -0
  19. package/dist/context/useReader.d.ts +2 -0
  20. package/dist/index.d.ts +2 -0
  21. package/dist/index.js +433 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/index.umd.cjs +2 -0
  24. package/dist/index.umd.cjs.map +1 -0
  25. package/dist/navigation/QuickMenu/BottomBar.d.ts +3 -0
  26. package/dist/navigation/QuickMenu/PaginationInfoSection.d.ts +1 -0
  27. package/dist/navigation/QuickMenu/QuickBar.d.ts +4 -0
  28. package/dist/navigation/QuickMenu/QuickMenu.d.ts +5 -0
  29. package/dist/navigation/QuickMenu/Scrubber.d.ts +1 -0
  30. package/dist/navigation/QuickMenu/ThemedSlider.d.ts +3 -0
  31. package/dist/navigation/QuickMenu/TimeIndicator.d.ts +3 -0
  32. package/dist/navigation/QuickMenu/TopBar.d.ts +5 -0
  33. package/dist/navigation/useNavigationContext.d.ts +11 -0
  34. package/dist/pagination/usePagination.d.ts +4 -0
  35. package/dist/settings/useSettings.d.ts +2 -0
  36. package/package.json +5 -2
  37. package/src/common/useFullscreen.ts +0 -44
  38. package/src/components/ui/avatar.tsx +0 -74
  39. package/src/components/ui/checkbox.tsx +0 -25
  40. package/src/components/ui/close-button.tsx +0 -17
  41. package/src/components/ui/color-mode.tsx +0 -75
  42. package/src/components/ui/dialog.tsx +0 -62
  43. package/src/components/ui/drawer.tsx +0 -52
  44. package/src/components/ui/field.tsx +0 -33
  45. package/src/components/ui/input-group.tsx +0 -53
  46. package/src/components/ui/popover.tsx +0 -59
  47. package/src/components/ui/progress.tsx +0 -34
  48. package/src/components/ui/provider.tsx +0 -12
  49. package/src/components/ui/radio.tsx +0 -24
  50. package/src/components/ui/slider.tsx +0 -82
  51. package/src/components/ui/toggle-tip.tsx +0 -70
  52. package/src/components/ui/tooltip.tsx +0 -46
  53. package/src/context/ReactReaderProvider.tsx +0 -14
  54. package/src/context/context.ts +0 -6
  55. package/src/context/useReader.ts +0 -9
  56. package/src/index.ts +0 -2
  57. package/src/navigation/QuickMenu/BottomBar.tsx +0 -65
  58. package/src/navigation/QuickMenu/PaginationInfoSection.tsx +0 -62
  59. package/src/navigation/QuickMenu/QuickBar.tsx +0 -40
  60. package/src/navigation/QuickMenu/QuickMenu.tsx +0 -22
  61. package/src/navigation/QuickMenu/Scrubber.tsx +0 -138
  62. package/src/navigation/QuickMenu/TimeIndicator.tsx +0 -29
  63. package/src/navigation/QuickMenu/TopBar.tsx +0 -72
  64. package/src/navigation/useNavigationContext.ts +0 -46
  65. package/src/pagination/usePagination.ts +0 -29
  66. package/src/settings/useSettings.ts +0 -9
  67. package/src/vite-env.d.ts +0 -1
  68. package/tsconfig.app.json +0 -26
  69. package/tsconfig.json +0 -7
  70. package/tsconfig.node.json +0 -22
  71. package/vite.config.ts +0 -32
@@ -1,22 +0,0 @@
1
- import { memo } from "react"
2
- import { BottomBar } from "./BottomBar"
3
- import { TopBar } from "./TopBar"
4
-
5
- export const QuickMenu = memo(
6
- ({
7
- open,
8
- onBackClick,
9
- onMoreClick,
10
- }: { open: boolean; onBackClick: () => void; onMoreClick: () => void }) => {
11
- return (
12
- <>
13
- <TopBar
14
- open={open}
15
- onBackClick={onBackClick}
16
- onMoreClick={onMoreClick}
17
- />
18
- <BottomBar open={open} />
19
- </>
20
- )
21
- },
22
- )
@@ -1,138 +0,0 @@
1
- import RcSlider from "rc-slider"
2
- import { type ComponentProps, useCallback, useEffect } from "react"
3
- import { useObserve, useSignal, useSubscribe } from "reactjrx"
4
- import { useReader } from "../../context/useReader"
5
- import { usePagination } from "../../pagination/usePagination"
6
- import "rc-slider/assets/index.css"
7
- import { useNavigationContext } from "../useNavigationContext"
8
-
9
- const useSliderValues = () => {
10
- const pagination = usePagination()
11
- const isUsingSpread = pagination?.isUsingSpread
12
- const { beginPageIndex: currentRealPage, totalApproximatePages = 0 } =
13
- useNavigationContext()
14
- const currentPage = isUsingSpread
15
- ? Math.floor((currentRealPage || 0) / 2)
16
- : currentRealPage
17
- const [value, valueSignal] = useSignal({
18
- default: currentPage || 0,
19
- })
20
- const min = 0
21
- const max = Math.max(
22
- 0,
23
- isUsingSpread
24
- ? Math.floor((totalApproximatePages - 1) / 2)
25
- : totalApproximatePages - 1,
26
- )
27
-
28
- useEffect(() => {
29
- valueSignal.setValue(currentPage || 0)
30
- }, [currentPage, valueSignal])
31
-
32
- return {
33
- value,
34
- valueSignal,
35
- min,
36
- max,
37
- }
38
- }
39
-
40
- export const Scrubber = () => {
41
- const reader = useReader()
42
- const pagination = usePagination()
43
- const { manifest } = useObserve(() => reader?.context.state$, []) ?? {}
44
- const reverse = manifest?.readingDirection === "rtl"
45
- const isUsingSpread = pagination?.isUsingSpread
46
- const { totalApproximatePages = 0, isBeginWithinChapter } =
47
- useNavigationContext()
48
- const step = 1
49
- const isScrubberWithinChapter = isBeginWithinChapter
50
- const { value, valueSignal, min, max } = useSliderValues()
51
-
52
- const onChange: NonNullable<ComponentProps<typeof RcSlider>["onChange"]> =
53
- useCallback(
54
- (values) => {
55
- const [value = 0] = Array.isArray(values) ? values : [values]
56
-
57
- valueSignal.setValue(value)
58
-
59
- const pageIndex = isUsingSpread
60
- ? Math.floor(value) * 2
61
- : Math.floor(value)
62
-
63
- if (!isScrubberWithinChapter) {
64
- reader?.navigation.goToAbsolutePageIndex({
65
- absolutePageIndex: pageIndex,
66
- animation: false,
67
- })
68
- } else {
69
- reader?.navigation.goToPageOfSpineItem({
70
- pageIndex,
71
- spineItemId: reader.pagination.getState().beginSpineItemIndex ?? 0,
72
- animation: false,
73
- })
74
- }
75
- },
76
- [reader, isUsingSpread, valueSignal, isScrubberWithinChapter],
77
- )
78
-
79
- /**
80
- * @note
81
- * Scrubber can navigate fast and without lock we may end up with
82
- * slowness due to the reader
83
- * paginating and loading items in between.
84
- * This is good practice (but not required) to throttle it.
85
- */
86
- useSubscribe(
87
- () =>
88
- reader?.navigation.throttleLock({
89
- duration: 100,
90
- trigger: valueSignal.subject,
91
- }),
92
- [reader, valueSignal],
93
- )
94
-
95
- // const marks =
96
- // max > 1
97
- // ? Array.from({ length: max + 1 }, (_, i) => i).reduce(
98
- // (acc: number[], val) => [...acc, val],
99
- // [],
100
- // )
101
- // : []
102
-
103
- if (
104
- totalApproximatePages === 1 ||
105
- (isUsingSpread && totalApproximatePages === 2)
106
- ) {
107
- return null
108
- }
109
-
110
- // @tmp not available yet in chakra
111
- // if (reverse) return null
112
-
113
- return (
114
- <RcSlider
115
- value={[value]}
116
- max={max}
117
- min={min}
118
- reverse={reverse}
119
- step={step}
120
- onChange={onChange}
121
- />
122
- )
123
- // return (
124
- // <Slider
125
- // value={[value]}
126
- // max={max}
127
- // min={min}
128
- // marks={marks}
129
- // onChange={e => {
130
- // debugger
131
- // }}
132
- // onValueChange={onChange}
133
- // // reverse={reverse}
134
- // orientation="horizontal"
135
- // step={step}
136
- // />
137
- // )
138
- }
@@ -1,29 +0,0 @@
1
- import { Text, type TextProps } from "@chakra-ui/react"
2
- import { useEffect, useState } from "react"
3
-
4
- export const useTime = () => {
5
- const [time, setTime] = useState(new Date())
6
-
7
- useEffect(() => {
8
- const interval = setInterval(() => {
9
- setTime(new Date())
10
- }, 1000 * 60)
11
-
12
- return () => clearInterval(interval)
13
- }, [])
14
-
15
- return time
16
- }
17
-
18
- export const TimeIndicator = (props: TextProps) => {
19
- const time = useTime()
20
-
21
- return (
22
- <Text fontSize="xs" {...props}>
23
- {time.toLocaleTimeString(navigator.language, {
24
- hour: "2-digit",
25
- minute: "2-digit",
26
- })}
27
- </Text>
28
- )
29
- }
@@ -1,72 +0,0 @@
1
- import { HStack, IconButton, Stack, Text } from "@chakra-ui/react"
2
- import { IoIosArrowBack, IoMdMore } from "react-icons/io"
3
- import { MdFullscreen, MdFullscreenExit } from "react-icons/md"
4
- import { useObserve } from "reactjrx"
5
- import { useFullscreen } from "../../common/useFullscreen"
6
- import { useReader } from "../../context/useReader"
7
- import { QuickBar } from "./QuickBar"
8
-
9
- export const TopBar = ({
10
- open,
11
- onBackClick,
12
- onMoreClick,
13
- }: {
14
- open: boolean
15
- onBackClick: () => void
16
- onMoreClick: () => void
17
- }) => {
18
- const reader = useReader()
19
- const manifest = useObserve(() => reader?.context.manifest$, [reader])
20
- const { isFullscreen, onToggleFullscreenClick } = useFullscreen()
21
-
22
- return (
23
- <QuickBar
24
- present={open}
25
- position="top"
26
- height="80px"
27
- justifyContent="space-between"
28
- >
29
- <IconButton
30
- aria-label="left"
31
- size="lg"
32
- variant="ghost"
33
- flexShrink={0}
34
- onClick={onBackClick}
35
- >
36
- <IoIosArrowBack />
37
- </IconButton>
38
- <Stack
39
- flex={1}
40
- maxW={600}
41
- gap={1}
42
- alignItems="center"
43
- overflow="auto"
44
- px={4}
45
- >
46
- <Text truncate maxWidth="100%">
47
- {manifest?.title}
48
- </Text>
49
- </Stack>
50
- <HStack>
51
- <IconButton
52
- aria-label="right"
53
- size="lg"
54
- flexShrink={0}
55
- variant="ghost"
56
- onClick={onMoreClick}
57
- >
58
- <IoMdMore />
59
- </IconButton>
60
- <IconButton
61
- aria-label="right"
62
- size="lg"
63
- flexShrink={0}
64
- variant="ghost"
65
- onClick={onToggleFullscreenClick}
66
- >
67
- {isFullscreen ? <MdFullscreenExit /> : <MdFullscreen />}
68
- </IconButton>
69
- </HStack>
70
- </QuickBar>
71
- )
72
- }
@@ -1,46 +0,0 @@
1
- import { usePagination } from "../pagination/usePagination"
2
-
3
- export const useNavigationContext = () => {
4
- const pagination = usePagination()
5
- const hasOnlyOnePage = pagination?.numberOfTotalPages === 1
6
-
7
- const isBeginWithinChapter =
8
- (pagination?.beginNumberOfPagesInSpineItem ?? 0) > 1
9
-
10
- const isEndWithinChapter = (pagination?.endNumberOfPagesInSpineItem ?? 0) > 1
11
-
12
- const beginPageIndex =
13
- (pagination?.hasChapters
14
- ? pagination?.beginPageIndexInSpineItem
15
- : pagination?.beginAbsolutePageIndex) ?? 0
16
- const endPageIndex =
17
- (pagination?.hasChapters
18
- ? pagination?.endPageIndexInSpineItem
19
- : pagination?.endAbsolutePageIndex) ?? 0
20
-
21
- const [leftPageIndex = 0, rightPageIndex = 0] = [
22
- beginPageIndex,
23
- endPageIndex,
24
- ].sort((a, b) => a - b)
25
-
26
- const beginAndEndAreDifferent =
27
- pagination?.beginPageIndexInSpineItem !==
28
- pagination?.endPageIndexInSpineItem ||
29
- pagination?.beginSpineItemIndex !== pagination?.endSpineItemIndex
30
-
31
- const totalApproximatePages = pagination?.hasChapters
32
- ? pagination?.beginNumberOfPagesInSpineItem
33
- : pagination?.numberOfTotalPages
34
-
35
- return {
36
- hasOnlyOnePage,
37
- beginPageIndex,
38
- endPageIndex,
39
- isBeginWithinChapter,
40
- isEndWithinChapter,
41
- beginAndEndAreDifferent,
42
- totalApproximatePages,
43
- leftPageIndex,
44
- rightPageIndex,
45
- }
46
- }
@@ -1,29 +0,0 @@
1
- import type { Reader } from "@prose-reader/core"
2
- import { useObserve } from "reactjrx"
3
- import { NEVER, combineLatest, map } from "rxjs"
4
- import { useReader } from "../context/useReader"
5
-
6
- export const usePagination = ():
7
- | (Reader["pagination"]["state"] & { hasChapters: boolean })
8
- | undefined => {
9
- const reader = useReader()
10
-
11
- return useObserve(
12
- () =>
13
- !reader
14
- ? NEVER
15
- : combineLatest([reader.pagination.state$, reader.context.state$]).pipe(
16
- map(([state, context]) => {
17
- const isOnlyImages = context.manifest?.spineItems.every((item) =>
18
- item.mediaType?.startsWith("image/"),
19
- )
20
-
21
- return {
22
- ...state,
23
- hasChapters: !context.isFullyPrePaginated && !isOnlyImages,
24
- }
25
- }),
26
- ),
27
- [reader],
28
- )
29
- }
@@ -1,9 +0,0 @@
1
- import type { Reader } from "@prose-reader/core"
2
- import { useObserve } from "reactjrx"
3
- import { useReader } from "../context/useReader"
4
-
5
- export const useSettings = (): Reader["settings"]["values"] | undefined => {
6
- const reader = useReader()
7
-
8
- return useObserve(() => reader?.settings.values$, [reader])
9
- }
package/src/vite-env.d.ts DELETED
@@ -1 +0,0 @@
1
- /// <reference types="vite/client" />
package/tsconfig.app.json DELETED
@@ -1,26 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
4
- "target": "ES2020",
5
- "useDefineForClassFields": true,
6
- "lib": ["ES2020", "DOM", "DOM.Iterable"],
7
- "module": "ESNext",
8
- "skipLibCheck": true,
9
- "moduleResolution": "bundler",
10
- "allowImportingTsExtensions": true,
11
- "isolatedModules": true,
12
- "moduleDetection": "force",
13
- "declaration": false,
14
- "noEmit": true,
15
- "jsx": "react-jsx",
16
- "outDir": "dist",
17
- "noUncheckedIndexedAccess": true,
18
- "strict": true,
19
- "noUnusedLocals": true,
20
- "noUnusedParameters": true,
21
- "noFallthroughCasesInSwitch": true,
22
- "noUncheckedSideEffectImports": true,
23
- "esModuleInterop": true
24
- },
25
- "include": ["src"]
26
- }
package/tsconfig.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "files": [],
3
- "references": [
4
- { "path": "./tsconfig.app.json" },
5
- { "path": "./tsconfig.node.json" }
6
- ]
7
- }
@@ -1,22 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
4
- "target": "ES2022",
5
- "lib": ["ES2023"],
6
- "module": "ESNext",
7
- "skipLibCheck": true,
8
-
9
- "moduleResolution": "bundler",
10
- "allowImportingTsExtensions": true,
11
- "isolatedModules": true,
12
- "moduleDetection": "force",
13
- "noEmit": true,
14
-
15
- "strict": true,
16
- "noUnusedLocals": true,
17
- "noUnusedParameters": true,
18
- "noFallthroughCasesInSwitch": true,
19
- "noUncheckedSideEffectImports": true
20
- },
21
- "include": ["vite.config.ts"]
22
- }
package/vite.config.ts DELETED
@@ -1,32 +0,0 @@
1
- import { resolve } from "node:path"
2
- import react from "@vitejs/plugin-react"
3
- import externals from "rollup-plugin-node-externals"
4
- import { defineConfig } from "vite"
5
- import dts from "vite-plugin-dts"
6
-
7
- // https://vite.dev/config/
8
- export default defineConfig(({ mode }) => ({
9
- build: {
10
- lib: {
11
- entry: resolve(__dirname, "src/index.ts"),
12
- name: "prose-react-reader",
13
- fileName: `index`,
14
- },
15
- emptyOutDir: mode !== "development",
16
- sourcemap: true,
17
- },
18
- plugins: [
19
- {
20
- enforce: `pre`,
21
- ...externals({
22
- peerDeps: true,
23
- deps: true,
24
- devDeps: true,
25
- }),
26
- },
27
- react(),
28
- dts({
29
- tsconfigPath: "./tsconfig.app.json",
30
- }),
31
- ],
32
- }))