@prose-reader/react-reader 1.117.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 (37) hide show
  1. package/README.md +50 -0
  2. package/package.json +36 -0
  3. package/src/common/useFullscreen.ts +44 -0
  4. package/src/components/ui/avatar.tsx +74 -0
  5. package/src/components/ui/checkbox.tsx +25 -0
  6. package/src/components/ui/close-button.tsx +17 -0
  7. package/src/components/ui/color-mode.tsx +75 -0
  8. package/src/components/ui/dialog.tsx +62 -0
  9. package/src/components/ui/drawer.tsx +52 -0
  10. package/src/components/ui/field.tsx +33 -0
  11. package/src/components/ui/input-group.tsx +53 -0
  12. package/src/components/ui/popover.tsx +59 -0
  13. package/src/components/ui/progress.tsx +34 -0
  14. package/src/components/ui/provider.tsx +12 -0
  15. package/src/components/ui/radio.tsx +24 -0
  16. package/src/components/ui/slider.tsx +82 -0
  17. package/src/components/ui/toggle-tip.tsx +70 -0
  18. package/src/components/ui/tooltip.tsx +46 -0
  19. package/src/context/ReactReaderProvider.tsx +14 -0
  20. package/src/context/context.ts +6 -0
  21. package/src/context/useReader.ts +9 -0
  22. package/src/index.ts +2 -0
  23. package/src/navigation/QuickMenu/BottomBar.tsx +65 -0
  24. package/src/navigation/QuickMenu/PaginationInfoSection.tsx +62 -0
  25. package/src/navigation/QuickMenu/QuickBar.tsx +40 -0
  26. package/src/navigation/QuickMenu/QuickMenu.tsx +22 -0
  27. package/src/navigation/QuickMenu/Scrubber.tsx +138 -0
  28. package/src/navigation/QuickMenu/TimeIndicator.tsx +29 -0
  29. package/src/navigation/QuickMenu/TopBar.tsx +72 -0
  30. package/src/navigation/useNavigationContext.ts +46 -0
  31. package/src/pagination/usePagination.ts +29 -0
  32. package/src/settings/useSettings.ts +9 -0
  33. package/src/vite-env.d.ts +1 -0
  34. package/tsconfig.app.json +26 -0
  35. package/tsconfig.json +7 -0
  36. package/tsconfig.node.json +22 -0
  37. package/vite.config.ts +32 -0
@@ -0,0 +1,46 @@
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
+ }
@@ -0,0 +1,29 @@
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
+ }
@@ -0,0 +1,9 @@
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
+ }
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
@@ -0,0 +1,26 @@
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 ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "files": [],
3
+ "references": [
4
+ { "path": "./tsconfig.app.json" },
5
+ { "path": "./tsconfig.node.json" }
6
+ ]
7
+ }
@@ -0,0 +1,22 @@
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 ADDED
@@ -0,0 +1,32 @@
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
+ }))