feat(koplugin): add support for annotation sync (#3579)

Add bidirectional annotation/highlight sync between KOReader and Readest:

- Add xpointer0/xpointer1 fields to BookNote and DBBookNote types for
  KOReader XPointer positions alongside Readest's CFI format
- Extend transform layer to pass through xpointer fields to/from DB
- Convert CFI→XPointer on push and XPointer→CFI on pull in useNotesSync,
  discarding notes that fail conversion
- Support KOReader's text()[K].N indexed text node format in xcfi.ts for
  paragraphs with inline elements (e.g. <a> page anchors)
- Generate KOReader-compatible XPointers: text().N for single text nodes,
  text()[K].N only when multiple direct text nodes exist
- Skip cfi-inert elements (injected by Readest at runtime) in XPointer
  path building and resolution
- Map highlight colors between KOReader and Readest color systems
- Implement KOReader plugin annotation push/pull with deterministic IDs,
  auto-sync on document open/close, and UIManager refresh on pull
- Refactor koplugin into focused modules: syncauth, syncconfig,
  syncannotations, selfupdate

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Huang Xin
2026-03-21 23:43:51 +08:00
committed by GitHub
parent 2f430bf2ff
commit 76b239f382
15 changed files with 1507 additions and 686 deletions
+9 -1
View File
@@ -147,6 +147,8 @@ export const transformBookNoteToDB = (bookNote: unknown, userId: string): DBBook
id,
type,
cfi,
xpointer0,
xpointer1,
page,
text,
style,
@@ -164,6 +166,8 @@ export const transformBookNoteToDB = (bookNote: unknown, userId: string): DBBook
id,
type,
cfi,
xpointer0,
xpointer1,
page,
text: sanitizeString(text),
style,
@@ -183,6 +187,8 @@ export const transformBookNoteFromDB = (dbBookNote: DBBookNote): BookNote => {
id,
type,
cfi,
xpointer0,
xpointer1,
page,
text,
style,
@@ -198,7 +204,9 @@ export const transformBookNoteFromDB = (dbBookNote: DBBookNote): BookNote => {
metaHash: meta_hash,
id,
type: type as BookNoteType,
cfi,
cfi: cfi ?? '',
xpointer0,
xpointer1,
page,
text,
style: style as HighlightStyle,