bok-reader 0.5.4 → 0.6.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.
- package/README.md +12 -0
- package/dist/bok.es.js +3098 -2943
- package/dist/bok.umd.js +48 -48
- package/dist/components/BokReader/BokReader.d.ts +53 -1
- package/dist/components/BokReader/syncUtils.d.ts +21 -0
- package/dist/components/Book.d.ts +3 -0
- package/dist/main.d.ts +1 -0
- package/package.json +2 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
|
+
import { Highlight } from '../Book';
|
|
2
3
|
export interface Theme {
|
|
3
4
|
"--bg-color": string;
|
|
4
5
|
"--text-color": string;
|
|
@@ -7,11 +8,62 @@ export interface Theme {
|
|
|
7
8
|
"--page-num-border": string;
|
|
8
9
|
"--color-tint": string;
|
|
9
10
|
}
|
|
11
|
+
export interface BokReaderSyncSnapshot {
|
|
12
|
+
bookId: string;
|
|
13
|
+
progress: number;
|
|
14
|
+
highlights: Highlight[];
|
|
15
|
+
}
|
|
16
|
+
export interface BokReaderSyncState {
|
|
17
|
+
bookId: string;
|
|
18
|
+
progress?: number;
|
|
19
|
+
highlights?: Highlight[];
|
|
20
|
+
revision?: string | number;
|
|
21
|
+
forceApply?: boolean;
|
|
22
|
+
}
|
|
23
|
+
type BokReaderSyncEventBase = {
|
|
24
|
+
mutationId: string;
|
|
25
|
+
bookId: string;
|
|
26
|
+
emittedAt: number;
|
|
27
|
+
};
|
|
28
|
+
export type BokReaderSyncEvent = (BokReaderSyncEventBase & {
|
|
29
|
+
type: "progress.set";
|
|
30
|
+
progress: number;
|
|
31
|
+
}) | (BokReaderSyncEventBase & {
|
|
32
|
+
type: "highlight.add";
|
|
33
|
+
highlight: Highlight;
|
|
34
|
+
}) | (BokReaderSyncEventBase & {
|
|
35
|
+
type: "highlight.remove";
|
|
36
|
+
highlightId: string;
|
|
37
|
+
}) | (BokReaderSyncEventBase & {
|
|
38
|
+
type: "highlight.updateColor";
|
|
39
|
+
highlightId: string;
|
|
40
|
+
color: Highlight["color"];
|
|
41
|
+
});
|
|
42
|
+
export type BokReaderSyncConflictEntity = "progress" | "highlights";
|
|
43
|
+
export interface BokReaderSyncConflict {
|
|
44
|
+
bookId: string;
|
|
45
|
+
entities: BokReaderSyncConflictEntity[];
|
|
46
|
+
detectedAt: number;
|
|
47
|
+
local: BokReaderSyncSnapshot;
|
|
48
|
+
remote: BokReaderSyncSnapshot;
|
|
49
|
+
proposedSyncState: BokReaderSyncState;
|
|
50
|
+
}
|
|
51
|
+
export interface BokReaderHandle {
|
|
52
|
+
getSyncSnapshot: () => BokReaderSyncSnapshot | null;
|
|
53
|
+
applySyncState: (syncState: BokReaderSyncState, options?: {
|
|
54
|
+
forceApply?: boolean;
|
|
55
|
+
}) => boolean;
|
|
56
|
+
getPendingSyncEvents: () => BokReaderSyncEvent[];
|
|
57
|
+
acknowledgeSyncEvents: (mutationIds: string | string[]) => void;
|
|
58
|
+
}
|
|
10
59
|
interface BokReaderProps {
|
|
11
60
|
epubDataSource: File | ArrayBuffer | string | null;
|
|
12
61
|
onTitleChange?: (title: string) => void;
|
|
13
62
|
onLoadingChange?: (isLoading: boolean) => void;
|
|
14
63
|
onError?: (errorMsg: string) => void;
|
|
64
|
+
onSyncEvent?: (event: BokReaderSyncEvent) => void;
|
|
65
|
+
syncState?: BokReaderSyncState | null;
|
|
66
|
+
onConflictDetected?: (conflict: BokReaderSyncConflict) => void;
|
|
15
67
|
className?: string;
|
|
16
68
|
style?: React.CSSProperties;
|
|
17
69
|
supportedFonts?: {
|
|
@@ -22,5 +74,5 @@ interface BokReaderProps {
|
|
|
22
74
|
[key: string]: Theme;
|
|
23
75
|
};
|
|
24
76
|
}
|
|
25
|
-
export declare const BokReader: React.
|
|
77
|
+
export declare const BokReader: React.ForwardRefExoticComponent<BokReaderProps & React.RefAttributes<BokReaderHandle>>;
|
|
26
78
|
export default BokReader;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Highlight } from '../Book';
|
|
2
|
+
export interface SyncStateFingerprintInput {
|
|
3
|
+
bookId: string;
|
|
4
|
+
progress?: number;
|
|
5
|
+
highlights?: Highlight[];
|
|
6
|
+
revision?: string | number;
|
|
7
|
+
forceApply?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface PendingSyncEvent {
|
|
10
|
+
mutationId: string;
|
|
11
|
+
emittedAt: number;
|
|
12
|
+
}
|
|
13
|
+
export declare const PROGRESS_EPSILON = 0.0001;
|
|
14
|
+
export declare function clampProgress(progress: number): number;
|
|
15
|
+
export declare function cloneHighlights(highlights: Highlight[]): Highlight[];
|
|
16
|
+
export declare function areHighlightsEqual(left: Highlight[], right: Highlight[]): boolean;
|
|
17
|
+
export declare function getSyncStateFingerprint(syncState: SyncStateFingerprintInput): string;
|
|
18
|
+
export declare function hasProgressConflict(localProgress: number, remoteProgress: number | undefined): boolean;
|
|
19
|
+
export declare function enqueuePendingSyncEvent<TEvent extends PendingSyncEvent>(pendingEvents: Map<string, TEvent>, event: TEvent): void;
|
|
20
|
+
export declare function listPendingSyncEvents<TEvent extends PendingSyncEvent>(pendingEvents: Map<string, TEvent>): TEvent[];
|
|
21
|
+
export declare function acknowledgePendingSyncEvents<TEvent extends PendingSyncEvent>(pendingEvents: Map<string, TEvent>, mutationIds: string | string[]): void;
|
|
@@ -2,6 +2,8 @@ import { default as React, Dispatch, SetStateAction } from 'react';
|
|
|
2
2
|
export interface BookHandle {
|
|
3
3
|
goToPage: (page: number) => void;
|
|
4
4
|
findAndJumpToHref: (href: string) => void;
|
|
5
|
+
setProgress: (progress: number) => void;
|
|
6
|
+
getProgress: () => number;
|
|
5
7
|
}
|
|
6
8
|
export type HighlightColor = "yellow" | "red" | "blue" | "purple";
|
|
7
9
|
export type Highlight = {
|
|
@@ -25,6 +27,7 @@ interface PageProps {
|
|
|
25
27
|
containerElementRef: React.RefObject<HTMLDivElement | null>;
|
|
26
28
|
onPageChange?: (page: number) => void;
|
|
27
29
|
onPageCountChange?: (count: number) => void;
|
|
30
|
+
onProgressChange?: (progress: number) => void;
|
|
28
31
|
highlights: Highlight[];
|
|
29
32
|
onAddHighlight: (highlight: Highlight) => void;
|
|
30
33
|
onRemoveHighlight: (id: string) => void;
|
package/dist/main.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bok-reader",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.6.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/bok.umd.js",
|
|
7
7
|
"module": "dist/bok.es.js",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"dev": "vite",
|
|
14
14
|
"build": "rimraf dist && vite build",
|
|
15
15
|
"prepublishOnly": "rimraf dist && vite build",
|
|
16
|
+
"test": "bun test",
|
|
16
17
|
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
|
17
18
|
"preview": "vite preview"
|
|
18
19
|
},
|