@gongfpp/dsh-novel-fish 1.1.0 → 1.2.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 (99) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +41 -20
  3. package/docs/evidence/settings-reliability.png +0 -0
  4. package/index.json +12 -0
  5. package/lib/client.js +734 -128
  6. package/locale/en.json +15 -0
  7. package/locale/zh.json +15 -0
  8. package/package.json +5 -7
  9. package/screenshots.json +6 -0
  10. package/docs/acceptance.md +0 -42
  11. package/docs/community-markets.md +0 -88
  12. package/docs/compatibility-017.md +0 -70
  13. package/docs/compatibility-101.md +0 -41
  14. package/docs/continuous-reading-020.md +0 -46
  15. package/docs/ebook-tests.md +0 -99
  16. package/docs/evidence/abc-result.json +0 -9
  17. package/docs/evidence/banner-100.png +0 -0
  18. package/docs/evidence/community-market-014-result.json +0 -170
  19. package/docs/evidence/compatibility-017-result.json +0 -65
  20. package/docs/evidence/continuous-reading-020-result.json +0 -72
  21. package/docs/evidence/formats-result.json +0 -12
  22. package/docs/evidence/live-ab.png +0 -0
  23. package/docs/evidence/live-collapsed.png +0 -0
  24. package/docs/evidence/live-disabled.png +0 -0
  25. package/docs/evidence/live-epub.png +0 -0
  26. package/docs/evidence/live-market.png +0 -0
  27. package/docs/evidence/live-resume.png +0 -0
  28. package/docs/evidence/live-unloaded.png +0 -0
  29. package/docs/evidence/long-result.json +0 -11
  30. package/docs/evidence/multi-region-014-result.json +0 -47
  31. package/docs/evidence/native-disclosure-013-result.json +0 -36
  32. package/docs/evidence/native-disclosures-013.png +0 -0
  33. package/docs/evidence/native-open-013.png +0 -0
  34. package/docs/evidence/native-settings-sample.md +0 -11
  35. package/docs/evidence/native-settings-types-015.png +0 -0
  36. package/docs/evidence/npm-market-014-result.json +0 -132
  37. package/docs/evidence/plugin-settings-details.png +0 -0
  38. package/docs/evidence/public-release-014-result.json +0 -51
  39. package/docs/evidence/public-release-015-result.json +0 -36
  40. package/docs/evidence/public-release-result.json +0 -48
  41. package/docs/evidence/reading-demo-100.png +0 -0
  42. package/docs/evidence/reading-two-expansions-110.gif +0 -0
  43. package/docs/evidence/reading-two-expansions-110.json +0 -89
  44. package/docs/evidence/samples-110-capture.json +0 -49
  45. package/docs/evidence/settings-011-result.json +0 -28
  46. package/docs/evidence/settings-011.png +0 -0
  47. package/docs/evidence/settings-100.png +0 -0
  48. package/docs/evidence/settings-110.png +0 -0
  49. package/docs/evidence/settings-chat-011.png +0 -0
  50. package/docs/evidence/type-append-012-result.json +0 -30
  51. package/docs/evidence/type-append-012.png +0 -0
  52. package/docs/evidence/type-settings-012.png +0 -0
  53. package/docs/evidence/unload-result.json +0 -7
  54. package/docs/host-adapter.md +0 -43
  55. package/docs/icon-metadata-021.md +0 -40
  56. package/docs/interaction-paths-020.md +0 -39
  57. package/docs/marketplace.md +0 -42
  58. package/docs/multi-region-update.md +0 -53
  59. package/docs/native-disclosure-update.md +0 -39
  60. package/docs/native-settings-update.md +0 -48
  61. package/docs/plugin-settings-update.md +0 -61
  62. package/docs/release.md +0 -151
  63. package/docs/settings-update.md +0 -49
  64. package/docs/type-append-update.md +0 -50
  65. package/pnpm-workspace.yaml +0 -5
  66. package/scripts/build.mjs +0 -70
  67. package/scripts/check-host-contracts.mjs +0 -247
  68. package/scripts/licenses/path-webpack.txt +0 -28
  69. package/scripts/make-readme-gif.mjs +0 -69
  70. package/scripts/test-browser-samples.mjs +0 -665
  71. package/scripts/test-candidate-books.mjs +0 -71
  72. package/scripts/test-ebook-corpus.mjs +0 -161
  73. package/src/bundled-books.js +0 -42
  74. package/src/chat-adapter.js +0 -278
  75. package/src/client.js +0 -61
  76. package/src/epub.js +0 -166
  77. package/src/novel-content.js +0 -28
  78. package/src/persistence.js +0 -271
  79. package/src/pg-notice.js +0 -19
  80. package/src/segments.js +0 -185
  81. package/src/settings.js +0 -243
  82. package/src/store.js +0 -429
  83. package/src/text-decoding.js +0 -28
  84. package/test/bundled-library.test.js +0 -526
  85. package/test/chat-adapter.test.js +0 -518
  86. package/test/client.test.js +0 -124
  87. package/test/ebooks.test.js +0 -192
  88. package/test/epub.test.js +0 -185
  89. package/test/helpers/host-primitives.js +0 -28
  90. package/test/helpers/memory-storage.js +0 -48
  91. package/test/host-contracts.test.js +0 -32
  92. package/test/import.test.js +0 -102
  93. package/test/persistence.test.js +0 -27
  94. package/test/pg-notice.test.js +0 -109
  95. package/test/release.test.js +0 -87
  96. package/test/segments.test.js +0 -182
  97. package/test/settings.test.js +0 -312
  98. package/test/store.test.js +0 -617
  99. package/test/text-decoding.test.js +0 -49
package/lib/client.js CHANGED
@@ -15079,6 +15079,40 @@
15079
15079
  }
15080
15080
  });
15081
15081
 
15082
+ // src/settings-data.js
15083
+ var TARGET_TYPES = Object.freeze(["reasoning", "tool-call", "read-file", "command", "file-search"]);
15084
+ var DEFAULT_SETTINGS = Object.freeze({
15085
+ enabled: true,
15086
+ currentBookId: null,
15087
+ targetTypes: Object.freeze(["reasoning"]),
15088
+ mainTitle: "",
15089
+ extraTitle: "",
15090
+ continueOnReopen: false
15091
+ });
15092
+ function settingsPatch(value = {}) {
15093
+ const patch = { ...value };
15094
+ delete patch.targets;
15095
+ delete patch.targetKey;
15096
+ delete patch.targetType;
15097
+ if (Array.isArray(patch.targetTypes)) patch.targetTypes = [...new Set(patch.targetTypes.filter((type) => TARGET_TYPES.includes(type)))];
15098
+ return patch;
15099
+ }
15100
+ function normalizeSettings(value = {}, books = []) {
15101
+ return {
15102
+ enabled: typeof value.enabled === "boolean" ? value.enabled : true,
15103
+ currentBookId: books.some((book) => book.id === value.currentBookId) ? value.currentBookId : null,
15104
+ targetTypes: Object.freeze(Array.isArray(value.targetTypes) ? [...new Set(value.targetTypes.filter((type) => TARGET_TYPES.includes(type)))] : [...DEFAULT_SETTINGS.targetTypes]),
15105
+ mainTitle: typeof value.mainTitle === "string" ? value.mainTitle : "",
15106
+ extraTitle: typeof value.extraTitle === "string" ? value.extraTitle : "",
15107
+ continueOnReopen: value.continueOnReopen === true
15108
+ };
15109
+ }
15110
+
15111
+ // src/random-id.js
15112
+ function randomId() {
15113
+ return globalThis.crypto?.randomUUID?.() ?? `book-${Date.now()}-${Math.random().toString(36).slice(2)}`;
15114
+ }
15115
+
15082
15116
  // src/persistence.js
15083
15117
  var DATABASE_NAME = "dsh-touch-fish-novel";
15084
15118
  var DATABASE_VERSION = 1;
@@ -15091,7 +15125,31 @@
15091
15125
  this.keyRange = keyRange;
15092
15126
  this.database = void 0;
15093
15127
  }
15128
+ subscribe(listener) {
15129
+ if (typeof window === "undefined" || typeof window.addEventListener !== "function" || typeof document === "undefined") return () => {
15130
+ };
15131
+ const channel = typeof window.BroadcastChannel === "function" ? new window.BroadcastChannel(DATABASE_NAME) : null;
15132
+ this.channel = channel;
15133
+ const refresh = () => listener();
15134
+ channel?.addEventListener("message", refresh);
15135
+ window.addEventListener("focus", refresh);
15136
+ const visible = () => {
15137
+ if (document.visibilityState === "visible") refresh();
15138
+ };
15139
+ document.addEventListener("visibilitychange", visible);
15140
+ return () => {
15141
+ channel?.close();
15142
+ if (this.channel === channel) this.channel = null;
15143
+ window.removeEventListener("focus", refresh);
15144
+ document.removeEventListener("visibilitychange", visible);
15145
+ };
15146
+ }
15147
+ notify() {
15148
+ this.channel?.postMessage("changed");
15149
+ }
15094
15150
  close() {
15151
+ this.channel?.close();
15152
+ this.channel = null;
15095
15153
  this.database?.close();
15096
15154
  this.database = void 0;
15097
15155
  }
@@ -15219,18 +15277,29 @@
15219
15277
  throw error;
15220
15278
  }
15221
15279
  }
15222
- async saveSettings(value) {
15280
+ async saveSettings(patch) {
15223
15281
  const db = await this.#open();
15224
- const tx = db.transaction("settings", "readwrite");
15282
+ const tx = db.transaction(["settings", "books"], "readwrite");
15225
15283
  const done = transactionDone(tx);
15226
- tx.objectStore("settings").put({ key: SETTINGS_KEY, value });
15284
+ done.catch(() => void 0);
15285
+ const settings = tx.objectStore("settings");
15286
+ const previous = await requestResult(settings.get(SETTINGS_KEY));
15287
+ const value = settingsPatch({ ...previous?.value, ...patch });
15288
+ if (value.currentBookId && !await requestResult(tx.objectStore("books").get(value.currentBookId))) {
15289
+ await done;
15290
+ throw new Error("\u627E\u4E0D\u5230\u8FD9\u672C\u4E66");
15291
+ }
15292
+ settings.put({ key: SETTINGS_KEY, value });
15227
15293
  await done;
15294
+ this.notify();
15295
+ return value;
15228
15296
  }
15229
- async addBook(book, segments) {
15297
+ async addBook(book, segments, { selectIfEmpty = false } = {}) {
15230
15298
  const db = await this.#open();
15231
- const tx = db.transaction(["books", "segments"], "readwrite");
15299
+ const tx = db.transaction(["books", "segments", "settings"], "readwrite");
15232
15300
  const done = transactionDone(tx);
15233
- tx.objectStore("books").put(book);
15301
+ done.catch(() => void 0);
15302
+ tx.objectStore("books").add(book);
15234
15303
  const segmentStore = tx.objectStore("segments");
15235
15304
  segments.forEach((segment, index) => segmentStore.put({
15236
15305
  id: `${book.id}:${index}`,
@@ -15238,20 +15307,42 @@
15238
15307
  index,
15239
15308
  ...segment
15240
15309
  }));
15310
+ if (selectIfEmpty) {
15311
+ const settings = tx.objectStore("settings");
15312
+ const previous = (await requestResult(settings.get(SETTINGS_KEY)))?.value ?? {};
15313
+ if (!previous.currentBookId) settings.put({ key: SETTINGS_KEY, value: { ...previous, currentBookId: book.id } });
15314
+ }
15241
15315
  await done;
15316
+ this.notify();
15242
15317
  }
15243
- async updateBook(book) {
15318
+ async updateBook(book, { expectedRevision, targetType } = {}) {
15244
15319
  const db = await this.#open();
15245
- const tx = db.transaction("books", "readwrite");
15320
+ const tx = db.transaction(["books", "settings"], "readwrite");
15246
15321
  const done = transactionDone(tx);
15322
+ done.catch(() => void 0);
15247
15323
  const books = tx.objectStore("books");
15248
15324
  const existing = await requestResult(books.get(book.id));
15249
15325
  if (!existing) {
15250
15326
  await done;
15327
+ if (expectedRevision !== void 0) return null;
15251
15328
  throw new Error("\u627E\u4E0D\u5230\u8FD9\u672C\u4E66\uFF0C\u65E0\u6CD5\u4FDD\u5B58\u9605\u8BFB\u8FDB\u5EA6");
15252
15329
  }
15253
- books.put(book);
15330
+ if (expectedRevision !== void 0 && (existing.revision ?? 0) !== expectedRevision) {
15331
+ await done;
15332
+ return null;
15333
+ }
15334
+ if (targetType) {
15335
+ const settings = (await requestResult(tx.objectStore("settings").get(SETTINGS_KEY)))?.value ?? {};
15336
+ if (settings.currentBookId !== book.id || settings.enabled === false || !(settings.targetTypes ?? ["reasoning"]).includes(targetType)) {
15337
+ await done;
15338
+ return null;
15339
+ }
15340
+ }
15341
+ const updated = expectedRevision === void 0 ? book : { ...book, revision: (existing.revision ?? 0) + 1 };
15342
+ books.put(updated);
15254
15343
  await done;
15344
+ this.notify();
15345
+ return updated;
15255
15346
  }
15256
15347
  async getSegment(bookId, index) {
15257
15348
  const db = await this.#open();
@@ -15265,9 +15356,16 @@
15265
15356
  }
15266
15357
  async deleteBook(bookId) {
15267
15358
  const db = await this.#open();
15268
- const tx = db.transaction(["books", "segments"], "readwrite");
15359
+ const tx = db.transaction(["books", "segments", "settings"], "readwrite");
15269
15360
  const done = transactionDone(tx);
15361
+ done.catch(() => void 0);
15270
15362
  tx.objectStore("books").delete(bookId);
15363
+ const settings = tx.objectStore("settings");
15364
+ const previous = (await requestResult(settings.get(SETTINGS_KEY)))?.value;
15365
+ if (previous?.currentBookId === bookId) {
15366
+ const books = await requestResult(tx.objectStore("books").getAll());
15367
+ settings.put({ key: SETTINGS_KEY, value: { ...previous, currentBookId: books[0]?.id ?? null } });
15368
+ }
15271
15369
  const cursorRequest = tx.objectStore("segments").index("bookId").openCursor(this.keyRange.only(bookId));
15272
15370
  cursorRequest.onsuccess = () => {
15273
15371
  const cursor = cursorRequest.result;
@@ -15276,6 +15374,72 @@
15276
15374
  cursor.continue();
15277
15375
  };
15278
15376
  await done;
15377
+ this.notify();
15378
+ }
15379
+ async exportLibrary() {
15380
+ const db = await this.#open();
15381
+ const tx = db.transaction(["books", "segments", "settings"], "readonly");
15382
+ const done = transactionDone(tx);
15383
+ done.catch(() => void 0);
15384
+ const [stored, records] = await Promise.all([readLibrary(tx), requestResult(tx.objectStore("segments").getAll())]);
15385
+ const byBook = /* @__PURE__ */ new Map();
15386
+ for (const { id: _id, bookId, index, ...segment } of records) {
15387
+ if (!byBook.has(bookId)) byBook.set(bookId, []);
15388
+ byBook.get(bookId)[index] = segment;
15389
+ }
15390
+ await done;
15391
+ return { ...stored, books: stored.books.map((book) => ({ book, segments: byBook.get(book.id) ?? [] })) };
15392
+ }
15393
+ /** Merge atomically; existing text/metadata/progress are never overwritten. */
15394
+ async restoreLibrary(backup) {
15395
+ const db = await this.#open();
15396
+ const tx = db.transaction(["books", "segments", "settings"], "readwrite");
15397
+ const done = transactionDone(tx);
15398
+ done.catch(() => void 0);
15399
+ try {
15400
+ const stored = await readLibrary(tx);
15401
+ const books = tx.objectStore("books"), segments = tx.objectStore("segments");
15402
+ const candidates = [...stored.books];
15403
+ const idMap = /* @__PURE__ */ new Map();
15404
+ let added = 0;
15405
+ for (const entry of backup.books) {
15406
+ let match;
15407
+ for (const candidate of candidates) {
15408
+ if (candidate.title !== entry.book.title || candidate.format !== entry.book.format || candidate.segmentCount !== entry.segments.length) continue;
15409
+ const records = await requestResult(segments.index("bookId").getAll(this.keyRange.only(candidate.id)));
15410
+ const byIndex = new Map(records.map((segment) => [segment.index, segment]));
15411
+ if (records.length === entry.segments.length && entry.segments.every((segment, index) => sameSegment(byIndex.get(index), segment))) {
15412
+ match = candidate;
15413
+ break;
15414
+ }
15415
+ }
15416
+ if (match) {
15417
+ idMap.set(entry.book.id, match.id);
15418
+ continue;
15419
+ }
15420
+ const book = { ...entry.book, id: randomId() };
15421
+ books.add(book);
15422
+ entry.segments.forEach((segment, index) => segments.add({ ...segment, id: `${book.id}:${index}`, bookId: book.id, index }));
15423
+ candidates.push(book);
15424
+ idMap.set(entry.book.id, book.id);
15425
+ added++;
15426
+ }
15427
+ const settings = { ...stored.settings };
15428
+ const current = idMap.get(backup.settings.currentBookId);
15429
+ if (!settings.currentBookId && current) settings.currentBookId = current;
15430
+ tx.objectStore("settings").put({ key: SETTINGS_KEY, value: settingsPatch(settings) });
15431
+ tx.objectStore("settings").put({ key: BUNDLED_BOOKS_KEY, value: true });
15432
+ await done;
15433
+ this.notify();
15434
+ return { added, reused: backup.books.length - added };
15435
+ } catch (error) {
15436
+ try {
15437
+ tx.abort();
15438
+ } catch {
15439
+ }
15440
+ await done.catch(() => void 0);
15441
+ throw error;
15442
+ }
15279
15443
  }
15280
15444
  async #open() {
15281
15445
  if (this.database) return this.database;
@@ -15416,12 +15580,33 @@
15416
15580
  const target = positiveInteger(targetLength);
15417
15581
  const segments = [];
15418
15582
  chapters.forEach((chapter, chapterIndex) => {
15419
- for (const text of splitChapter(chapter.text, target)) {
15420
- segments.push({ text, chapterTitle: chapter.title, chapterIndex });
15583
+ for (const block of chapterBlocks(chapter.text)) {
15584
+ for (const text of splitChapter(block, target)) {
15585
+ segments.push({ text, chapterTitle: chapter.title, chapterIndex });
15586
+ }
15421
15587
  }
15422
15588
  });
15423
15589
  return segments;
15424
15590
  }
15591
+ var MAX_CHAPTER_BLOCK = 256 * 1024;
15592
+ function chapterBlocks(text) {
15593
+ const source = String(text);
15594
+ if (source.length <= MAX_CHAPTER_BLOCK) return [source];
15595
+ const blocks = [];
15596
+ let start = 0;
15597
+ while (start < source.length) {
15598
+ let end = Math.min(start + MAX_CHAPTER_BLOCK, source.length);
15599
+ if (end < source.length) {
15600
+ const cut = source.lastIndexOf("\n", end);
15601
+ if (cut > start + MAX_CHAPTER_BLOCK / 2) end = cut + 1;
15602
+ const code = source.charCodeAt(end - 1);
15603
+ if (code >= 55296 && code <= 56319) end -= 1;
15604
+ }
15605
+ blocks.push(source.slice(start, end));
15606
+ start = end;
15607
+ }
15608
+ return blocks;
15609
+ }
15425
15610
  function parseTextBook(text, format = "txt", targetLength = DEFAULT_SEGMENT_LENGTH) {
15426
15611
  const chapters = textToChapters(text, format);
15427
15612
  const segments = segmentChapters(chapters, targetLength);
@@ -15556,8 +15741,9 @@
15556
15741
  const packagePath = archivePath(container.packagePath);
15557
15742
  const packaging = new Packaging(await readXml(packagePath));
15558
15743
  const navPath = packaging.navPath || packaging.ncxPath;
15559
- const navigation = navPath ? new Navigation(await readXml(archivePath(navPath, packagePath))) : null;
15560
- const labels = tocLabels(navigation?.toc ?? [], packagePath);
15744
+ const navigationPath = navPath ? archivePath(navPath, packagePath) : null;
15745
+ const navigation = navigationPath ? new Navigation(await readXml(navigationPath)) : null;
15746
+ const labels = tocLabels(navigation?.toc ?? [], navigationPath ?? packagePath);
15561
15747
  const chapters = [];
15562
15748
  for (const item of packaging.spine) {
15563
15749
  if (item.linear === "no") continue;
@@ -15736,17 +15922,52 @@
15736
15922
  return /\bProject\s+Gutenberg\b/iu.test(String(text ?? ""));
15737
15923
  }
15738
15924
 
15925
+ // src/backup.js
15926
+ var MAX_BACKUP_BYTES = 64 * 1024 * 1024;
15927
+ var BACKUP_FORMAT = "dsh-novel-fish-backup";
15928
+ function validateBackup(value) {
15929
+ const invalid = () => {
15930
+ throw new Error("\u5907\u4EFD\u683C\u5F0F\u65E0\u6548\u6216\u7248\u672C\u4E0D\u53D7\u652F\u6301");
15931
+ };
15932
+ if (!value || value.format !== BACKUP_FORMAT || value.version !== 1 || !Array.isArray(value.books) || !value.settings || typeof value.settings !== "object" || value.books.length > 2e3) invalid();
15933
+ const ids = /* @__PURE__ */ new Set();
15934
+ let count = 0;
15935
+ let textLength = 0;
15936
+ const books = value.books.map((entry) => {
15937
+ const book = entry?.book, segments = entry?.segments;
15938
+ if (!book || typeof book.id !== "string" || !book.id || book.id.length > 512 || ids.has(book.id) || typeof book.title !== "string" || !book.title.trim() || book.title.length > 4096 || !["epub", "txt", "md"].includes(book.format) || !Array.isArray(segments) || !segments.length || book.segmentCount !== segments.length || !Number.isSafeInteger(book.progress) || book.progress < 0 || book.progress > segments.length) invalid();
15939
+ ids.add(book.id);
15940
+ count += segments.length;
15941
+ if (count > 2e5) invalid();
15942
+ const cleanSegments = Array.from(segments, (segment) => {
15943
+ if (!segment || typeof segment.text !== "string" || !segment.text.trim() || segment.chapterTitle !== void 0 && typeof segment.chapterTitle !== "string" || segment.chapterIndex !== void 0 && (!Number.isSafeInteger(segment.chapterIndex) || segment.chapterIndex < 0)) invalid();
15944
+ textLength += segment.text.length + (segment.chapterTitle?.length ?? 0);
15945
+ if (textLength > MAX_BACKUP_BYTES) invalid();
15946
+ return {
15947
+ text: segment.text,
15948
+ ...segment.chapterTitle !== void 0 ? { chapterTitle: segment.chapterTitle } : {},
15949
+ ...segment.chapterIndex !== void 0 ? { chapterIndex: segment.chapterIndex } : {}
15950
+ };
15951
+ });
15952
+ return { book: {
15953
+ id: book.id,
15954
+ title: book.title,
15955
+ format: book.format,
15956
+ segmentCount: segments.length,
15957
+ progress: book.progress,
15958
+ importedAt: Number.isFinite(book.importedAt) ? book.importedAt : Date.now()
15959
+ }, segments: cleanSegments };
15960
+ });
15961
+ const input = value.settings;
15962
+ if (typeof input.enabled !== "boolean" || typeof input.continueOnReopen !== "boolean" || typeof input.mainTitle !== "string" || input.mainTitle.length > 4096 || typeof input.extraTitle !== "string" || input.extraTitle.length > 4096 || !Array.isArray(input.targetTypes) || input.targetTypes.some((type) => !TARGET_TYPES.includes(type)) || input.currentBookId !== null && !ids.has(input.currentBookId)) invalid();
15963
+ const settings = Object.fromEntries(Object.keys(DEFAULT_SETTINGS).map((key) => [key, input[key]]));
15964
+ settings.targetTypes = [...new Set(settings.targetTypes)];
15965
+ return { format: BACKUP_FORMAT, version: 1, books, settings };
15966
+ }
15967
+
15739
15968
  // src/store.js
15740
- var TARGET_TYPES = Object.freeze(["reasoning", "tool-call", "read-file", "command", "file-search"]);
15741
- var DEFAULT_SETTINGS = Object.freeze({
15742
- enabled: true,
15743
- currentBookId: null,
15744
- targetTypes: Object.freeze(["reasoning"]),
15745
- mainTitle: "",
15746
- extraTitle: "",
15747
- continueOnReopen: false
15748
- });
15749
15969
  var EMPTY_STATUS = Object.freeze({ kind: "empty" });
15970
+ var MAX_IMPORT_BYTES = 8 * 1024 * 1024;
15750
15971
  function passageSnapshotKey(bookId, stepKey) {
15751
15972
  return `${bookId}\0${stepKey}`;
15752
15973
  }
@@ -15774,6 +15995,9 @@
15774
15995
  this.persistenceError = null;
15775
15996
  this.mutationQueue = Promise.resolve();
15776
15997
  this.ready = this.#hydrate();
15998
+ this.unsubscribeStorage = storage.subscribe?.(() => {
15999
+ void this.refresh().catch((error) => this.setNotice(`\u540C\u6B65\u4E66\u5E93\u5931\u8D25\uFF1A${messageOf(error)}`));
16000
+ });
15777
16001
  }
15778
16002
  getSnapshot = () => this.state;
15779
16003
  getSettingsSnapshot = () => this.state.settings;
@@ -15798,6 +16022,7 @@
15798
16022
  this.settingsListeners.clear();
15799
16023
  this.uiListeners.clear();
15800
16024
  this.passageListeners.clear();
16025
+ this.unsubscribeStorage?.();
15801
16026
  this.storage.close?.();
15802
16027
  }
15803
16028
  setNotice(notice) {
@@ -15826,15 +16051,19 @@
15826
16051
  return this.#enqueueMutation(async () => {
15827
16052
  if (nextId && !this.state.books.some((book) => book.id === nextId)) throw new Error("\u627E\u4E0D\u5230\u8FD9\u672C\u4E66");
15828
16053
  if (nextId === this.state.settings.currentBookId) return;
15829
- await this.#saveSettings({ ...this.state.settings, currentBookId: nextId });
16054
+ await this.#saveSettings({ currentBookId: nextId });
15830
16055
  this.#clearPassages(false);
15831
16056
  });
15832
16057
  }
15833
16058
  async importFile(file) {
15834
16059
  await this.ready;
15835
- this.#assertWritable();
16060
+ await this.#ensureWritable();
15836
16061
  const extension = String(file.name).split(".").at(-1)?.toLowerCase();
15837
16062
  if (!["epub", "txt", "md"].includes(extension)) throw new Error("\u53EA\u652F\u6301 EPUB\u3001TXT\u3001MD \u6587\u4EF6");
16063
+ if (Number.isFinite(file.size) && file.size > MAX_IMPORT_BYTES) {
16064
+ throw new Error(`\u6587\u4EF6\u4E0D\u80FD\u8D85\u8FC7 ${MAX_IMPORT_BYTES / 1024 / 1024} MiB`);
16065
+ }
16066
+ await new Promise((resolve) => setTimeout(resolve, 0));
15838
16067
  const parsed = extension === "epub" ? await parseEpub(file, DEFAULT_SEGMENT_LENGTH) : parseTextBook(decodeBookText(await file.arrayBuffer()), extension, DEFAULT_SEGMENT_LENGTH);
15839
16068
  const fallbackTitle = String(file.name).replace(/\.(epub|txt|md)$/iu, "");
15840
16069
  return this.#addBook({
@@ -15847,22 +16076,65 @@
15847
16076
  if (bookId === this.state.settings.currentBookId) this.cacheGeneration += 1;
15848
16077
  return this.#enqueueMutation(async () => {
15849
16078
  if (!this.state.books.some((item) => item.id === bookId)) return;
15850
- const books = this.state.books.filter((item) => item.id !== bookId);
15851
- const previousSettings = this.state.settings;
15852
- const settings = {
15853
- ...previousSettings,
15854
- currentBookId: previousSettings.currentBookId === bookId ? books[0]?.id ?? null : previousSettings.currentBookId
15855
- };
15856
- await this.storage.saveSettings(settings);
15857
- try {
15858
- await this.storage.deleteBook(bookId);
15859
- } catch (error) {
15860
- await this.#restore(() => this.storage.saveSettings(previousSettings));
15861
- throw error;
15862
- }
16079
+ await this.storage.deleteBook(bookId);
15863
16080
  this.projectGutenbergBooks.delete(bookId);
15864
- this.#setState({ books, settings });
15865
- if (settings.currentBookId !== previousSettings.currentBookId) this.#clearPassages(false);
16081
+ await this.#refresh();
16082
+ });
16083
+ }
16084
+ /** Set the next unread index (0 = beginning, segmentCount = finished). */
16085
+ async setProgress(bookId, progress) {
16086
+ if (!Number.isSafeInteger(progress) || progress < 0) throw new Error("\u6BB5\u843D\u4F4D\u7F6E\u65E0\u6548");
16087
+ this.#cancelPendingReads();
16088
+ return this.#enqueueMutation(async () => {
16089
+ for (let attempt = 0; attempt < 32; attempt++) {
16090
+ const book = this.state.books.find((item) => item.id === bookId);
16091
+ if (!book || progress > book.segmentCount) throw new Error("\u6BB5\u843D\u4F4D\u7F6E\u65E0\u6548\u6216\u4E66\u7C4D\u5DF2\u5220\u9664");
16092
+ const updated = await this.storage.updateBook({ ...book, progress, positionToken: randomId() }, { expectedRevision: book.revision ?? 0 });
16093
+ if (!updated) {
16094
+ await this.#refresh();
16095
+ continue;
16096
+ }
16097
+ this.#adoptBook(updated);
16098
+ this.#clearPassages();
16099
+ return;
16100
+ }
16101
+ throw new Error("\u5176\u4ED6\u9875\u9762\u6B63\u5728\u9891\u7E41\u66F4\u65B0\u8FDB\u5EA6\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");
16102
+ });
16103
+ }
16104
+ async exportBackup() {
16105
+ return this.#enqueueMutation(async () => {
16106
+ const library = await this.storage.exportLibrary();
16107
+ const data = validateBackup({
16108
+ format: BACKUP_FORMAT,
16109
+ version: 1,
16110
+ books: library.books,
16111
+ settings: normalizeSettings(library.settings, library.books.map((entry) => entry.book))
16112
+ });
16113
+ const json = JSON.stringify(data);
16114
+ if (new TextEncoder().encode(json).byteLength > MAX_BACKUP_BYTES) throw new Error("\u4E66\u5E93\u8D85\u8FC7 64 MiB\uFF0C\u6682\u4E0D\u652F\u6301\u6574\u5E93\u5907\u4EFD");
16115
+ return json;
16116
+ });
16117
+ }
16118
+ async readBackup(file) {
16119
+ if (file.size > MAX_BACKUP_BYTES) throw new Error("\u5907\u4EFD\u6587\u4EF6\u4E0D\u80FD\u8D85\u8FC7 64 MiB");
16120
+ const text = await file.text();
16121
+ if (new TextEncoder().encode(text).byteLength > MAX_BACKUP_BYTES) throw new Error("\u5907\u4EFD\u6587\u4EF6\u4E0D\u80FD\u8D85\u8FC7 64 MiB");
16122
+ try {
16123
+ return validateBackup(JSON.parse(text));
16124
+ } catch (error) {
16125
+ if (error instanceof SyntaxError) throw new Error("\u4E0D\u662F\u6709\u6548\u7684 JSON \u5907\u4EFD\u6587\u4EF6");
16126
+ throw error;
16127
+ }
16128
+ }
16129
+ async restoreBackup(backup) {
16130
+ const validated = validateBackup(backup);
16131
+ this.#cancelPendingReads();
16132
+ return this.#enqueueMutation(async () => {
16133
+ const result = await this.storage.restoreLibrary(validated);
16134
+ this.projectGutenbergBooks.clear();
16135
+ this.#clearPassages();
16136
+ await this.#refresh();
16137
+ return result;
15866
16138
  });
15867
16139
  }
15868
16140
  /** Reopening a region shows the passage it already holds; a first expansion reads the next one. */
@@ -15880,45 +16152,57 @@
15880
16152
  }
15881
16153
  async #readPassage(stepKey, targetType, advance) {
15882
16154
  if (this.disposed) return EMPTY_STATUS;
15883
- const generation = this.cacheGeneration;
16155
+ let generation = this.cacheGeneration;
15884
16156
  const requestKey = `${generation}\0${targetType}\0${stepKey}`;
15885
16157
  const inFlight = this.pendingReads.get(requestKey);
15886
16158
  if (inFlight) return inFlight;
15887
16159
  let bookId;
15888
16160
  let loadingStatus;
15889
- const operation = this.#enqueueMutation(async () => {
16161
+ const operation = this.#enqueueMutation(async (generationBeforeRefresh) => {
16162
+ if (generation === generationBeforeRefresh) generation = this.cacheGeneration;
15890
16163
  if (!this.#canRead(generation, targetType)) return EMPTY_STATUS;
15891
16164
  bookId = this.state.settings.currentBookId;
15892
16165
  if (!bookId) return EMPTY_STATUS;
15893
16166
  const existing = this.getPassageStatus(bookId, stepKey);
15894
16167
  if (existing.kind === "end") return existing;
15895
16168
  if (!advance && existing.kind === "ready") return existing;
15896
- const book = this.state.books.find((item) => item.id === bookId);
15897
- if (!book || book.progress >= book.segmentCount) {
15898
- return this.#writePassageStatus(bookId, stepKey, { kind: "end", bookId });
15899
- }
15900
16169
  loadingStatus = { kind: "loading" };
15901
16170
  this.#writePassageStatus(bookId, stepKey, loadingStatus);
15902
- const index = book.progress;
15903
- const passage = await this.storage.getSegment(bookId, index);
15904
- if (!passage?.text) throw new Error("\u5F53\u524D\u6BB5\u843D\u4E3A\u7A7A\u6216\u5DF2\u635F\u574F");
15905
- if (!this.#canRead(generation, targetType)) return EMPTY_STATUS;
15906
- if (!this.projectGutenbergBooks.has(bookId)) {
15907
- const first = index === 0 ? passage : await this.storage.getSegment(bookId, 0);
16171
+ for (let attempt = 0; attempt < 32; attempt++) {
16172
+ if (!this.#canRead(generation, targetType)) return EMPTY_STATUS;
16173
+ const book = this.state.books.find((item) => item.id === bookId);
16174
+ if (!book || book.progress >= book.segmentCount) {
16175
+ return this.#writePassageStatus(bookId, stepKey, { kind: "end", bookId });
16176
+ }
16177
+ const index = book.progress;
16178
+ const passage = await this.storage.getSegment(bookId, index);
16179
+ if (!passage?.text) throw new Error("\u5F53\u524D\u6BB5\u843D\u4E3A\u7A7A\u6216\u5DF2\u635F\u574F");
15908
16180
  if (!this.#canRead(generation, targetType)) return EMPTY_STATUS;
15909
- if (!first?.text) throw new Error("\u4E66\u7C4D\u9996\u6BB5\u4E3A\u7A7A\u6216\u5DF2\u635F\u574F");
15910
- this.projectGutenbergBooks.set(bookId, hasProjectGutenbergReference(first.text));
15911
- }
15912
- const projectGutenberg = this.projectGutenbergBooks.get(bookId);
15913
- const updated = { ...book, progress: index + 1 };
15914
- await this.storage.updateBook(updated);
15915
- if (!this.#canRead(generation, targetType)) {
15916
- await this.#restore(() => this.storage.updateBook(book));
15917
- return EMPTY_STATUS;
15918
- }
15919
- const result = { kind: "ready", bookId, index, passage, projectGutenberg };
15920
- this.#setState({ books: this.state.books.map((item) => item.id === bookId ? updated : item) });
15921
- return this.#writePassageStatus(bookId, stepKey, result);
16181
+ if (!this.projectGutenbergBooks.has(bookId)) {
16182
+ const first = index === 0 ? passage : await this.storage.getSegment(bookId, 0);
16183
+ if (!this.#canRead(generation, targetType)) return EMPTY_STATUS;
16184
+ if (!first?.text) throw new Error("\u4E66\u7C4D\u9996\u6BB5\u4E3A\u7A7A\u6216\u5DF2\u635F\u574F");
16185
+ this.projectGutenbergBooks.set(bookId, hasProjectGutenbergReference(first.text));
16186
+ }
16187
+ const projectGutenberg = this.projectGutenbergBooks.get(bookId);
16188
+ const updated = await this.storage.updateBook({ ...book, progress: index + 1 }, {
16189
+ expectedRevision: book.revision ?? 0,
16190
+ targetType
16191
+ });
16192
+ if (!updated) {
16193
+ await this.#refresh();
16194
+ continue;
16195
+ }
16196
+ this.#adoptBook(updated);
16197
+ if (!this.#canRead(generation, targetType)) {
16198
+ await this.#restore(() => this.storage.updateBook(book, { expectedRevision: updated.revision }));
16199
+ await this.#refresh();
16200
+ return EMPTY_STATUS;
16201
+ }
16202
+ const result = { kind: "ready", bookId, index, passage, projectGutenberg };
16203
+ return this.#writePassageStatus(bookId, stepKey, result);
16204
+ }
16205
+ throw new Error("\u5176\u4ED6\u9875\u9762\u6B63\u5728\u9891\u7E41\u66F4\u65B0\u8FDB\u5EA6\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");
15922
16206
  }).catch((error) => {
15923
16207
  if (!this.persistenceError && !this.#canRead(generation, targetType)) return EMPTY_STATUS;
15924
16208
  const failure = { kind: "error", message: messageOf(error) };
@@ -15975,15 +16259,8 @@
15975
16259
  stored = await this.storage.migrateBundledCatalog({ ...this.bundledCatalog, updates });
15976
16260
  }
15977
16261
  const books = stored.books ?? [];
15978
- const storedSettings = stored.settings ?? {};
15979
- const availableIds = new Set(books.map((book) => book.id));
15980
- const settings = {
15981
- ...Object.fromEntries(Object.entries(DEFAULT_SETTINGS).map(([key, fallback]) => [key, storedSettings[key] ?? fallback])),
15982
- currentBookId: availableIds.has(storedSettings.currentBookId) ? storedSettings.currentBookId : null,
15983
- // Migrate the old reasoning-only field once; never carry it into writes.
15984
- targetTypes: Object.freeze(Array.isArray(storedSettings.targetTypes) ? [...new Set(storedSettings.targetTypes.filter((type) => TARGET_TYPES.includes(type)))] : [...DEFAULT_SETTINGS.targetTypes])
15985
- };
15986
- this.#setState({ books, settings, hydrated: true, error: null });
16262
+ this.persistenceError = null;
16263
+ this.#setState({ books, settings: normalizeSettings(stored.settings, books), hydrated: true, error: null });
15987
16264
  } catch (error) {
15988
16265
  this.persistenceError = error;
15989
16266
  this.#setState({ hydrated: true, error: messageOf(error) });
@@ -16000,16 +16277,8 @@
16000
16277
  progress: 0,
16001
16278
  importedAt: Date.now()
16002
16279
  };
16003
- await this.storage.addBook(book, segments);
16004
- const settings = this.state.settings.currentBookId ? this.state.settings : { ...this.state.settings, currentBookId: book.id };
16005
- try {
16006
- if (settings !== this.state.settings) await this.storage.saveSettings(settings);
16007
- } catch (error) {
16008
- await this.#restore(() => this.storage.deleteBook(book.id));
16009
- throw error;
16010
- }
16011
- if (settings !== this.state.settings) this.#clearPassages();
16012
- this.#setState({ books: [...this.state.books, book], settings });
16280
+ await this.storage.addBook(book, segments, { selectIfEmpty: true });
16281
+ await this.#refresh();
16013
16282
  return book;
16014
16283
  });
16015
16284
  }
@@ -16017,23 +16286,61 @@
16017
16286
  return this.#enqueueMutation(async () => {
16018
16287
  const patch = update(this.state.settings);
16019
16288
  if (!patch) return this.state.settings;
16020
- return this.#saveSettings({ ...this.state.settings, ...patch });
16289
+ return this.#saveSettings(patch);
16021
16290
  });
16022
16291
  }
16023
- async #saveSettings(settings) {
16024
- await this.storage.saveSettings(settings);
16292
+ async #saveSettings(patch) {
16293
+ const saved = await this.storage.saveSettings(patch);
16294
+ const settings = normalizeSettings(saved, this.state.books);
16025
16295
  this.#setState({ settings });
16026
16296
  return settings;
16027
16297
  }
16298
+ refresh() {
16299
+ return this.#enqueueMutation(() => void 0);
16300
+ }
16301
+ async #refresh() {
16302
+ const stored = await this.storage.load();
16303
+ if (this.disposed) return;
16304
+ const books = stored.books ?? [];
16305
+ const settings = normalizeSettings(stored.settings, books);
16306
+ const previous = this.state.settings;
16307
+ const selectionChanged = previous.currentBookId !== settings.currentBookId;
16308
+ const positionChanged = this.state.books.some((book) => book.positionToken !== books.find((item) => item.id === book.id)?.positionToken);
16309
+ if (selectionChanged || positionChanged) this.#clearPassages();
16310
+ else if (previous.enabled !== settings.enabled || JSON.stringify(previous.targetTypes) !== JSON.stringify(settings.targetTypes)) this.#cancelPendingReads();
16311
+ const changes = {};
16312
+ if (JSON.stringify(this.state.books) !== JSON.stringify(books)) changes.books = books;
16313
+ if (JSON.stringify(previous) !== JSON.stringify(settings)) changes.settings = settings;
16314
+ if (Object.keys(changes).length) this.#setState(changes);
16315
+ }
16028
16316
  #enqueueMutation(action) {
16029
16317
  const operation = this.mutationQueue.then(async () => {
16030
16318
  await this.ready;
16031
- this.#assertWritable();
16032
- return action();
16319
+ await this.#ensureWritable();
16320
+ const generationBeforeRefresh = this.cacheGeneration;
16321
+ await this.#refresh();
16322
+ return action(generationBeforeRefresh);
16033
16323
  });
16034
16324
  this.mutationQueue = operation.catch(() => void 0);
16035
16325
  return operation;
16036
16326
  }
16327
+ /** 采纳一次 CAS 写入返回的完整书籍记录,替代为它重读整个书库。 */
16328
+ #adoptBook(book) {
16329
+ const index = this.state.books.findIndex((item) => item.id === book.id);
16330
+ if (index < 0) return;
16331
+ const books = [...this.state.books];
16332
+ books[index] = book;
16333
+ this.#setState({ books });
16334
+ }
16335
+ /**
16336
+ * 首次读取失败不该让插件在刷新前永久只读:真正要写入时再重试一次 hydrate,
16337
+ * 成功就恢复,仍失败才按原有错误拒绝。
16338
+ */
16339
+ async #ensureWritable() {
16340
+ if (this.disposed) throw new Error("\u672C\u5730\u4E66\u5E93\u5DF2\u5173\u95ED");
16341
+ if (this.persistenceError) await this.#hydrate();
16342
+ this.#assertWritable();
16343
+ }
16037
16344
  #assertWritable() {
16038
16345
  if (this.persistenceError) throw new Error(`\u672C\u5730\u4E66\u5E93\u4E0D\u53EF\u7528\uFF0C\u8BF7\u5237\u65B0\u540E\u91CD\u8BD5\uFF1A${messageOf(this.persistenceError)}`);
16039
16346
  if (this.disposed) throw new Error("\u672C\u5730\u4E66\u5E93\u5DF2\u5173\u95ED");
@@ -16098,9 +16405,6 @@
16098
16405
  return () => listeners.delete(listener);
16099
16406
  }
16100
16407
  };
16101
- function randomId() {
16102
- return globalThis.crypto?.randomUUID?.() ?? `book-${Date.now()}-${Math.random().toString(36).slice(2)}`;
16103
- }
16104
16408
  function messageOf(error) {
16105
16409
  return error instanceof Error ? error.message : String(error);
16106
16410
  }
@@ -16123,6 +16427,13 @@
16123
16427
  borderTop: "1px solid var(--dsw-alias-border-l2)",
16124
16428
  margin: "10px 0 8px"
16125
16429
  };
16430
+ var LABEL_STYLE = {
16431
+ fontSize: "12px",
16432
+ fontWeight: "500",
16433
+ letterSpacing: "0.01em",
16434
+ color: "var(--dsw-alias-label-secondary)",
16435
+ marginBottom: "4px"
16436
+ };
16126
16437
  function novelContent(status, hasBook, t) {
16127
16438
  if (status.kind === "ready") return {
16128
16439
  label: t("chat.novel"),
@@ -16140,6 +16451,9 @@
16140
16451
  var TOOL = '[data-chat-call-id] [data-tool], [data-chat-call-id] [data-sample="bash"]';
16141
16452
  var REGIONS = `${THOUGHT}, ${TOOL}`;
16142
16453
  var EMPTY = Object.freeze({ kind: "empty" });
16454
+ var IDENTITY_ATTRIBUTES = ["data-chat-flow-kind", "data-chat-node-key", "data-chat-call-id", "data-conversation-session", "data-tool", "data-sample"];
16455
+ var IDENTITY_SET = new Set(IDENTITY_ATTRIBUTES);
16456
+ var OBSERVED_ATTRIBUTES = ["data-shimmer-text", "aria-expanded", "data-state", ...IDENTITY_ATTRIBUTES];
16143
16457
  function registerChatAdapter(ctx, store, React, locale, { getSampleLicenseHref: getSampleLicenseHref2 } = {}) {
16144
16458
  const t = ctx.locale?.bind(locale) ?? ((key) => key);
16145
16459
  ctx.slots.inject("conversation.chat.reasoning.body", () => ctx.slots.register({
@@ -16161,22 +16475,32 @@
16161
16475
  root.removeAttribute("data-novel-target");
16162
16476
  decorated.delete(root);
16163
16477
  };
16478
+ let identities = /* @__PURE__ */ new WeakMap();
16479
+ const identity = (root) => {
16480
+ let cached = identities.get(root);
16481
+ if (!cached) {
16482
+ cached = identityOf(root);
16483
+ if (cached) identities.set(root, cached);
16484
+ }
16485
+ return cached ?? null;
16486
+ };
16164
16487
  const refresh = () => {
16165
16488
  const settings = store.getSettingsSnapshot();
16166
16489
  for (const [toggle, intent] of pending) {
16167
- const id = identityOf(intent.root);
16490
+ const id = identity(intent.root);
16168
16491
  if (!toggle.isConnected || !settings.enabled || settings.currentBookId !== intent.bookId || !isTarget(settings, id) || readingKey(id) !== intent.key || store.cacheGeneration !== intent.generation) {
16169
16492
  if (intent.frame !== null) view.cancelAnimationFrame(intent.frame);
16170
16493
  pending.delete(toggle);
16171
16494
  }
16172
16495
  }
16173
16496
  for (const root of decorated.keys()) {
16174
- if (!root.isConnected || !settings.enabled || !isTarget(settings, identityOf(root))) restore(root);
16497
+ if (!root.isConnected || !settings.enabled || !isTarget(settings, identity(root))) restore(root);
16175
16498
  }
16499
+ if (!settings.enabled) return;
16176
16500
  for (const root of document.querySelectorAll(REGIONS)) {
16177
- const id = identityOf(root);
16501
+ const id = identity(root);
16178
16502
  const header = headerOf(root);
16179
- if (!header || !settings.enabled || !isTarget(settings, id)) continue;
16503
+ if (!header || !isTarget(settings, id)) continue;
16180
16504
  let record = decorated.get(root);
16181
16505
  if (!record || record.header !== header) {
16182
16506
  restore(root);
@@ -16277,13 +16601,21 @@
16277
16601
  if (view?.requestAnimationFrame) intent.frame = view.requestAnimationFrame(verify);
16278
16602
  else queueMicrotask(verify);
16279
16603
  };
16280
- const observer = new MutationObserver(scheduleRefresh);
16604
+ const observer = new MutationObserver((records) => {
16605
+ for (const record of records) {
16606
+ if (record.type === "childList" || record.type === "attributes" && IDENTITY_SET.has(record.attributeName)) {
16607
+ identities = /* @__PURE__ */ new WeakMap();
16608
+ break;
16609
+ }
16610
+ }
16611
+ scheduleRefresh();
16612
+ });
16281
16613
  observer.observe(document.body, {
16282
16614
  childList: true,
16283
16615
  subtree: true,
16284
16616
  characterData: true,
16285
16617
  attributes: true,
16286
- attributeFilter: ["data-shimmer-text", "aria-expanded", "data-tool", "data-state"]
16618
+ attributeFilter: OBSERVED_ATTRIBUTES
16287
16619
  });
16288
16620
  document.addEventListener("click", activate, true);
16289
16621
  document.addEventListener("keydown", activate, true);
@@ -16354,7 +16686,7 @@
16354
16686
  "div",
16355
16687
  { "data-novel-append": true, style: NOVEL_STYLE },
16356
16688
  h("hr", { style: SEPARATOR_STYLE }),
16357
- h("div", { "data-novel-label": true }, model.chapter ? `${model.label} \xB7 ${model.chapter}` : model.label),
16689
+ h("div", { "data-novel-label": true, style: LABEL_STYLE }, model.chapter ? `${model.label} \xB7 ${model.chapter}` : model.label),
16358
16690
  model.projectGutenberg ? h(
16359
16691
  "aside",
16360
16692
  { "data-novel-pg-notice": true, style: PG_NOTICE_STYLE },
@@ -16378,6 +16710,7 @@
16378
16710
  Object.assign(divider.style, SEPARATOR_STYLE);
16379
16711
  const label = document.createElement("div");
16380
16712
  label.setAttribute("data-novel-label", "");
16713
+ Object.assign(label.style, LABEL_STYLE);
16381
16714
  label.textContent = model.chapter ? `${model.label} \xB7 ${model.chapter}` : model.label;
16382
16715
  const content = document.createElement("div");
16383
16716
  Object.assign(content.style, PASSAGE_STYLE);
@@ -16455,6 +16788,11 @@
16455
16788
  .novel-fish-book-info{display:flex;flex-direction:column;gap:20px;max-height:60vh;overflow-y:auto;font-size:13px;line-height:1.6}
16456
16789
  .novel-fish-book-info .novel-fish-field{display:flex;flex-direction:column;gap:4px}
16457
16790
  .novel-fish-book-info p{margin:0}
16791
+ .novel-fish-license{display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin-bottom:12px}
16792
+ .novel-fish-help{position:relative;display:inline-flex;align-items:center;justify-content:center;width:18px;height:18px;border-radius:50%;border:1px solid var(--dsw-alias-border-l2);color:var(--dsw-alias-label-secondary);font-size:12px;line-height:1;cursor:help;user-select:none}
16793
+ .novel-fish-help:focus-visible{outline:2px solid var(--dsw-alias-label-secondary);outline-offset:2px}
16794
+ .novel-fish-help-tip{position:absolute;bottom:calc(100% + 8px);right:0;z-index:20;display:none;width:min(340px,72vw);max-height:min(45vh,320px);overflow-y:auto;padding:10px 12px;border-radius:8px;background:var(--dsw-alias-bg-primary,#fff);border:1px solid var(--dsw-alias-border-l2);box-shadow:0 8px 24px rgba(0,0,0,.16);color:var(--dsw-alias-label-primary);font-size:12px;line-height:1.6;white-space:normal;text-align:start}
16795
+ .novel-fish-help:hover .novel-fish-help-tip,.novel-fish-help:focus .novel-fish-help-tip,.novel-fish-help:focus-within .novel-fish-help-tip{display:block}
16458
16796
  `;
16459
16797
  function createSettingsRow(React, { Switch, Button, Input, Menu, Modal, IconChevronDownOutlineRegular }) {
16460
16798
  const h = React.createElement;
@@ -16489,9 +16827,42 @@
16489
16827
  }, h("span", { className: "novel-fish-selection" }, selection), h(IconChevronDownOutlineRegular, { size: 16 }))
16490
16828
  });
16491
16829
  }
16830
+ const TITLE_COMMIT_DELAY = 300;
16492
16831
  function PresetField({ t, label, value, choices, disabled, onChange, testId }) {
16493
16832
  const [custom, setCustom] = React.useState(!choices.includes(value));
16494
16833
  const showCustom = custom || !choices.includes(value);
16834
+ const pending = React.useRef(null);
16835
+ const timer = React.useRef(null);
16836
+ const saved = React.useRef(value);
16837
+ saved.current = value;
16838
+ const change = React.useRef(onChange);
16839
+ change.current = onChange;
16840
+ const flush = React.useCallback(() => {
16841
+ if (timer.current !== null) {
16842
+ clearTimeout(timer.current);
16843
+ timer.current = null;
16844
+ }
16845
+ const next = pending.current;
16846
+ pending.current = null;
16847
+ if (next === null || next === saved.current) return;
16848
+ void change.current(next);
16849
+ }, []);
16850
+ const queue = (event) => {
16851
+ pending.current = event.currentTarget.value;
16852
+ if (timer.current !== null) clearTimeout(timer.current);
16853
+ timer.current = setTimeout(() => {
16854
+ timer.current = null;
16855
+ flush();
16856
+ }, TITLE_COMMIT_DELAY);
16857
+ };
16858
+ React.useEffect(() => () => {
16859
+ if (timer.current === null) return;
16860
+ clearTimeout(timer.current);
16861
+ timer.current = null;
16862
+ const next = pending.current;
16863
+ pending.current = null;
16864
+ if (next !== null && next !== saved.current) void change.current(next);
16865
+ }, []);
16495
16866
  return h(
16496
16867
  "div",
16497
16868
  { className: "novel-fish-field" },
@@ -16504,8 +16875,8 @@
16504
16875
  items: [...choices.map((choice) => ({ id: choice, label: choice || t(testId === "title" ? "settings.nativeTitle" : "settings.noExtra") })), { id: "__custom", label: t("settings.custom") }],
16505
16876
  onChange: (next) => {
16506
16877
  if (next === "__custom") setCustom(true);
16507
- else void onChange(next).then((saved) => {
16508
- if (saved) setCustom(false);
16878
+ else void onChange(next).then((savedValue) => {
16879
+ if (savedValue) setCustom(false);
16509
16880
  });
16510
16881
  }
16511
16882
  }),
@@ -16515,13 +16886,12 @@
16515
16886
  disabled,
16516
16887
  "aria-label": t("settings.customField", { label }),
16517
16888
  [`data-novel-${testId}`]: true,
16518
- onChange: (event) => {
16519
- void onChange(event.currentTarget.value);
16520
- }
16889
+ onChange: queue,
16890
+ onBlur: flush
16521
16891
  }) : null
16522
16892
  );
16523
16893
  }
16524
- function SettingsRow({ t, useNovelState, useNovelUi, onSetOption, onSetNotice, onSelectBook, onDeleteBook, onImportFile, sampleBooks: sampleBooks2 = [], getSampleLicenseHref: getSampleLicenseHref2 }) {
16894
+ function SettingsRow({ t, useNovelState, useNovelUi, onSetOption, onSetNotice, onSelectBook, onDeleteBook, onImportFile, onSetProgress, onExportBackup, onReadBackup, onRestoreBackup, sampleBooks: sampleBooks2 = [], getSampleLicenseHref: getSampleLicenseHref2 }) {
16525
16895
  const state = useNovelState((value) => value);
16526
16896
  const ui = useNovelUi((value) => value);
16527
16897
  const [busy, setBusy] = React.useState(false);
@@ -16531,6 +16901,13 @@
16531
16901
  const [removeBook, setRemoveBook] = React.useState(null);
16532
16902
  const [removeError, setRemoveError] = React.useState(null);
16533
16903
  const [bookInfoOpen, setBookInfoOpen] = React.useState(false);
16904
+ const [importedBook, setImportedBook] = React.useState(null);
16905
+ const [jumpBook, setJumpBook] = React.useState(null);
16906
+ const [nextPassage, setNextPassage] = React.useState("1");
16907
+ const [pendingBackup, setPendingBackup] = React.useState(null);
16908
+ const [dialogError, setDialogError] = React.useState(null);
16909
+ const backupInput = React.useRef(null);
16910
+ const libraryAction = React.useRef(false);
16534
16911
  const enabling = React.useRef(false);
16535
16912
  const continuing = React.useRef(false);
16536
16913
  const changingTypes = React.useRef(false);
@@ -16591,6 +16968,7 @@
16591
16968
  try {
16592
16969
  const book = await onImportFile(file);
16593
16970
  onSetNotice(t("settings.importDone", { count: book.segmentCount }));
16971
+ setImportedBook(book);
16594
16972
  } catch (error) {
16595
16973
  onSetNotice(t("settings.importError", { message: errorMessage(error) }));
16596
16974
  } finally {
@@ -16617,6 +16995,35 @@
16617
16995
  setBusy(false);
16618
16996
  }
16619
16997
  };
16998
+ const runLibraryAction = async (action) => {
16999
+ if (disabled || libraryAction.current) return;
17000
+ libraryAction.current = true;
17001
+ setBusy(true);
17002
+ setDialogError(null);
17003
+ try {
17004
+ await action();
17005
+ } catch (error) {
17006
+ const message = t("settings.actionError", { message: errorMessage(error) });
17007
+ setDialogError(message);
17008
+ onSetNotice(message);
17009
+ } finally {
17010
+ libraryAction.current = false;
17011
+ setBusy(false);
17012
+ }
17013
+ };
17014
+ const readBackup = async (event) => {
17015
+ const input = event.currentTarget, file = input.files?.[0];
17016
+ if (!file) return;
17017
+ await runLibraryAction(async () => {
17018
+ setPendingBackup(await onReadBackup(file));
17019
+ });
17020
+ input.value = "";
17021
+ };
17022
+ const openJump = () => {
17023
+ setDialogError(null);
17024
+ setNextPassage(String(Math.min(selectedBook.progress + 1, selectedBook.segmentCount + 1)));
17025
+ setJumpBook(selectedBook);
17026
+ };
16620
17027
  return h(
16621
17028
  "section",
16622
17029
  { className: "novel-fish-settings", "data-novel-settings": true },
@@ -16663,11 +17070,52 @@
16663
17070
  "div",
16664
17071
  { className: "novel-fish-row" },
16665
17072
  h("span", { className: "novel-fish-hint", "data-novel-progress": true }, t("settings.progressValue", { progress: selectedBook.progress, total: selectedBook.segmentCount, percent: Math.floor(selectedBook.progress / selectedBook.segmentCount * 100) })),
17073
+ h(Button, { variant: "outline", disabled, "data-novel-jump": true, onClick: openJump }, t("settings.adjustProgress")),
16666
17074
  h(Button, { variant: "ghost", disabled, "data-novel-delete": true, onClick: () => {
16667
17075
  setRemoveError(null);
16668
17076
  setRemoveBook(selectedBook);
16669
17077
  } }, t("settings.deleteBook"))
16670
- ) : h("p", { className: "novel-fish-hint" }, t("settings.emptyLibrary"))
17078
+ ) : h("p", { className: "novel-fish-hint" }, t("settings.emptyLibrary")),
17079
+ importedBook?.id && importedBook.id !== state.settings.currentBookId && state.books.some((book) => book.id === importedBook.id) ? h(Button, {
17080
+ variant: "outline",
17081
+ disabled,
17082
+ "data-novel-switch-imported": true,
17083
+ onClick: () => {
17084
+ void perform(() => onSelectBook(importedBook.id));
17085
+ }
17086
+ }, t("settings.switchImported", { title: importedBook.title })) : null,
17087
+ h(
17088
+ "div",
17089
+ { className: "novel-fish-row" },
17090
+ h(Button, {
17091
+ variant: "outline",
17092
+ disabled,
17093
+ "data-novel-export": true,
17094
+ onClick: () => {
17095
+ void runLibraryAction(async () => {
17096
+ await onExportBackup();
17097
+ onSetNotice(t("settings.exportDone"));
17098
+ });
17099
+ }
17100
+ }, t("settings.exportBackup")),
17101
+ h(Button, {
17102
+ variant: "outline",
17103
+ disabled,
17104
+ "data-novel-restore": true,
17105
+ onClick: () => backupInput.current?.click()
17106
+ }, t("settings.restoreBackup"))
17107
+ ),
17108
+ h("input", {
17109
+ ref: backupInput,
17110
+ hidden: true,
17111
+ type: "file",
17112
+ accept: ".json,application/json",
17113
+ disabled,
17114
+ "data-novel-backup-input": true,
17115
+ onChange: (event) => {
17116
+ void readBackup(event);
17117
+ }
17118
+ })
16671
17119
  ),
16672
17120
  h(
16673
17121
  "section",
@@ -16731,32 +17179,140 @@
16731
17179
  )
16732
17180
  ),
16733
17181
  ui.notice ? h("div", { role: "status", "data-novel-notice": true }, ui.notice) : null,
16734
- bookInfoOpen ? h(Modal, {
17182
+ jumpBook ? h(
17183
+ Modal,
17184
+ {
17185
+ open: true,
17186
+ title: t("settings.adjustProgress"),
17187
+ closeLabel: t("settings.cancel"),
17188
+ onClose: () => {
17189
+ if (!busy) setJumpBook(null);
17190
+ },
17191
+ description: t("settings.jumpDescription", { title: jumpBook.title, total: jumpBook.segmentCount, end: jumpBook.segmentCount + 1 }),
17192
+ footer: h(
17193
+ React.Fragment,
17194
+ null,
17195
+ h(Button, { variant: "outline", disabled: busy, onClick: () => setJumpBook(null) }, t("settings.cancel")),
17196
+ h(Button, {
17197
+ variant: "primary",
17198
+ disabled,
17199
+ "data-novel-jump-confirm": true,
17200
+ onClick: () => {
17201
+ void runLibraryAction(async () => {
17202
+ const next = Number(nextPassage);
17203
+ if (!Number.isSafeInteger(next) || next < 1 || next > jumpBook.segmentCount + 1) throw new Error(t("settings.invalidPosition"));
17204
+ await onSetProgress(jumpBook.id, next - 1);
17205
+ setJumpBook(null);
17206
+ onSetNotice(t("settings.progressUpdated"));
17207
+ });
17208
+ }
17209
+ }, t("settings.confirmProgress"))
17210
+ )
17211
+ },
17212
+ h(Input, {
17213
+ type: "number",
17214
+ min: 1,
17215
+ max: jumpBook.segmentCount + 1,
17216
+ step: 1,
17217
+ value: nextPassage,
17218
+ disabled: busy,
17219
+ "aria-label": t("settings.nextPassage"),
17220
+ "data-novel-jump-input": true,
17221
+ onChange: (event) => setNextPassage(event.currentTarget.value)
17222
+ }),
17223
+ h(
17224
+ "div",
17225
+ { className: "novel-fish-row" },
17226
+ h(Button, {
17227
+ variant: "ghost",
17228
+ disabled: busy,
17229
+ "data-novel-back-one": true,
17230
+ onClick: () => setNextPassage(String(Math.max(1, jumpBook.progress)))
17231
+ }, t("settings.backOne")),
17232
+ h(Button, {
17233
+ variant: "ghost",
17234
+ disabled: busy,
17235
+ "data-novel-restart": true,
17236
+ onClick: () => setNextPassage("1")
17237
+ }, t("settings.restart"))
17238
+ ),
17239
+ dialogError ? h("p", { role: "alert" }, dialogError) : null
17240
+ ) : null,
17241
+ pendingBackup ? h(Modal, {
16735
17242
  open: true,
16736
- onClose: () => setBookInfoOpen(false),
16737
- title: t("settings.bookInfo"),
16738
- closeLabel: t("settings.close")
16739
- }, h(
16740
- "div",
16741
- { className: "novel-fish-book-info", "data-novel-book-info": true },
16742
- ...sampleBooks2.map((book) => h(
17243
+ title: t("settings.restoreBackup"),
17244
+ closeLabel: t("settings.cancel"),
17245
+ onClose: () => {
17246
+ if (!busy) setPendingBackup(null);
17247
+ },
17248
+ description: t("settings.restoreDescription", { count: pendingBackup.books.length }),
17249
+ footer: h(
17250
+ React.Fragment,
17251
+ null,
17252
+ h(Button, { variant: "outline", disabled: busy, onClick: () => setPendingBackup(null) }, t("settings.cancel")),
17253
+ h(Button, {
17254
+ variant: "primary",
17255
+ disabled,
17256
+ "data-novel-restore-confirm": true,
17257
+ onClick: () => {
17258
+ void runLibraryAction(async () => {
17259
+ const result = await onRestoreBackup(pendingBackup);
17260
+ setPendingBackup(null);
17261
+ onSetNotice(t("settings.restoreDone", result));
17262
+ });
17263
+ }
17264
+ }, t("settings.confirmRestore"))
17265
+ )
17266
+ }, dialogError ? h("p", { role: "alert" }, dialogError) : null) : null,
17267
+ bookInfoOpen ? h(
17268
+ Modal,
17269
+ {
17270
+ open: true,
17271
+ onClose: () => setBookInfoOpen(false),
17272
+ title: t("settings.bookInfo"),
17273
+ closeLabel: t("settings.close")
17274
+ },
17275
+ h(
16743
17276
  "div",
16744
- { key: book.id, className: "novel-fish-field" },
16745
- h("a", { href: book.source, target: "_blank", rel: "noreferrer" }, book.title),
16746
- h("span", null, book.author),
16747
- h("span", null, book.license)
16748
- )),
16749
- h("a", { href: getSampleLicenseHref2?.(), download: "bundled-ebooks-notices.txt" }, t("settings.sampleLicense")),
17277
+ { className: "novel-fish-book-info", "data-novel-book-info": true },
17278
+ ...sampleBooks2.map((book) => h(
17279
+ "div",
17280
+ { key: book.id, className: "novel-fish-field" },
17281
+ h("a", { href: book.source, target: "_blank", rel: "noreferrer" }, book.title),
17282
+ h("span", null, book.author),
17283
+ h("span", null, book.license)
17284
+ ))
17285
+ ),
17286
+ // 许可行放在书单下方、滚动区之外:问号提示向上展开时不会被书单的滚动
17287
+ // 容器裁掉,过长的声明在提示内部滚动。
16750
17288
  h(
16751
- "p",
16752
- { "data-novel-sample-license": true },
16753
- t("settings.samplePgNotice"),
16754
- " ",
16755
- PG_NOTICE,
16756
- " ",
16757
- h("a", { href: "https://www.gutenberg.org/policy/license.html", target: "_blank", rel: "noreferrer" }, "www.gutenberg.org")
17289
+ "div",
17290
+ { className: "novel-fish-license" },
17291
+ h("a", { href: getSampleLicenseHref2?.(), download: "bundled-ebooks-notices.txt" }, t("settings.sampleLicense")),
17292
+ // 书源许可与 Project Gutenberg 声明默认收起,只在悬停/聚焦问号时展开,
17293
+ // 不把整页法务文本铺在设置里。
17294
+ h(
17295
+ "span",
17296
+ {
17297
+ className: "novel-fish-help",
17298
+ role: "button",
17299
+ tabIndex: 0,
17300
+ "aria-label": t("settings.samplePgNotice"),
17301
+ "data-novel-license-help": true
17302
+ },
17303
+ "?",
17304
+ h(
17305
+ "span",
17306
+ { className: "novel-fish-help-tip", role: "tooltip", "data-novel-sample-license": true },
17307
+ t("settings.samplePgNotice"),
17308
+ " ",
17309
+ PG_NOTICE,
17310
+ " ",
17311
+ h("a", { href: "https://www.gutenberg.org/policy/license.html", target: "_blank", rel: "noreferrer" }, "www.gutenberg.org")
17312
+ )
17313
+ )
16758
17314
  )
16759
- )) : null,
17315
+ ) : null,
16760
17316
  h(Modal, {
16761
17317
  open: Boolean(removeBook),
16762
17318
  onClose: closeRemove,
@@ -16882,6 +17438,22 @@
16882
17438
  return licenseHref;
16883
17439
  }
16884
17440
 
17441
+ // src/download.js
17442
+ function downloadBackup(json) {
17443
+ const href = URL.createObjectURL(new Blob([json], { type: "application/json;charset=utf-8" }));
17444
+ const anchor = document.createElement("a");
17445
+ anchor.href = href;
17446
+ anchor.download = `novel-fish-backup-${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}.json`;
17447
+ anchor.hidden = true;
17448
+ document.body.append(anchor);
17449
+ try {
17450
+ anchor.click();
17451
+ } finally {
17452
+ anchor.remove();
17453
+ setTimeout(() => URL.revokeObjectURL(href), 1e3);
17454
+ }
17455
+ }
17456
+
16885
17457
  // locale/zh.json
16886
17458
  var zh_default = {
16887
17459
  meta: {
@@ -16951,6 +17523,21 @@
16951
17523
  importDone: "\u5BFC\u5165\u5B8C\u6210\uFF1A{count} \u6BB5",
16952
17524
  importError: "\u65E0\u6CD5\u5BFC\u5165\uFF1A{message}",
16953
17525
  actionError: "\u64CD\u4F5C\u5931\u8D25\uFF1A{message}",
17526
+ switchImported: "\u5F00\u59CB\u8BFB\u300A{title}\u300B",
17527
+ adjustProgress: "\u8C03\u6574\u8FDB\u5EA6",
17528
+ jumpDescription: "\u300A{title}\u300B\u5171 {total} \u6BB5\u3002\u9009\u62E9\u4E0B\u4E00\u6B21\u5C55\u5F00\u8981\u8BFB\u7684\u6BB5\u843D\uFF1B\u586B {end} \u8868\u793A\u5DF2\u8BFB\u5B8C\u3002\u786E\u8BA4\u540E\u6E05\u7A7A\u5DF2\u663E\u793A\u7684\u5C0F\u8BF4\u7247\u6BB5\uFF0C\u4E0D\u6539 AI \u539F\u6587\u3002",
17529
+ nextPassage: "\u4E0B\u6B21\u9605\u8BFB\u7684\u6BB5\u843D",
17530
+ backOne: "\u56DE\u9000\u4E00\u6BB5",
17531
+ restart: "\u4ECE\u5934\u5F00\u59CB",
17532
+ confirmProgress: "\u66F4\u65B0\u8FDB\u5EA6",
17533
+ invalidPosition: "\u8BF7\u8F93\u5165\u6709\u6548\u8303\u56F4\u5185\u7684\u6574\u6570\u6BB5\u843D\u53F7",
17534
+ progressUpdated: "\u8FDB\u5EA6\u5DF2\u66F4\u65B0\uFF0C\u4E0B\u6B21\u4E3B\u52A8\u5C55\u5F00\u4ECE\u65B0\u4F4D\u7F6E\u5F00\u59CB",
17535
+ exportBackup: "\u5BFC\u51FA\u5907\u4EFD",
17536
+ restoreBackup: "\u6062\u590D\u5907\u4EFD",
17537
+ exportDone: "\u5907\u4EFD\u5DF2\u4E0B\u8F7D\uFF0C\u5305\u542B\u4E66\u7C4D\u6B63\u6587\u3001\u8FDB\u5EA6\u548C\u8BBE\u7F6E\uFF0C\u8BF7\u59A5\u5584\u4FDD\u5B58",
17538
+ restoreDescription: "\u5907\u4EFD\u4E2D\u6709 {count} \u672C\u4E66\u3002\u5408\u5E76\u5230\u5F53\u524D\u4E66\u5E93\uFF0C\u4E0D\u5220\u9664\u5DF2\u6709\u4E66\u7C4D\uFF1B\u76F8\u540C\u6B63\u6587\u4FDD\u7559\u5F53\u524D\u8FDB\u5EA6\uFF0C\u5E76\u6062\u590D\u5907\u4EFD\u7684\u9009\u4E66\u548C\u9605\u8BFB\u8BBE\u7F6E\u3002\u786E\u8BA4\u540E\u6E05\u7A7A\u5F53\u524D\u9875\u9762\u7684\u5C0F\u8BF4\u7247\u6BB5\u3002",
17539
+ confirmRestore: "\u5408\u5E76\u6062\u590D",
17540
+ restoreDone: "\u6062\u590D\u5B8C\u6210\uFF1A\u65B0\u589E {added} \u672C\uFF0C\u590D\u7528 {reused} \u672C\uFF08\u4FDD\u7559\u5DF2\u6709\u8FDB\u5EA6\uFF09",
16954
17541
  removeConfirm: "\u5220\u9664\u300A{title}\u300B\u53CA\u5176\u672C\u5730\u9605\u8BFB\u8FDB\u5EA6\uFF1F"
16955
17542
  }
16956
17543
  };
@@ -17024,6 +17611,21 @@
17024
17611
  importDone: "Imported: {count} passages",
17025
17612
  importError: "Import failed: {message}",
17026
17613
  actionError: "Action failed: {message}",
17614
+ switchImported: "Read {title}",
17615
+ adjustProgress: "Adjust progress",
17616
+ jumpDescription: "{title} has {total} passages. Choose the next passage to read; enter {end} to mark it finished. Confirming clears displayed novel passages, not the original AI content.",
17617
+ nextPassage: "Next passage to read",
17618
+ backOne: "Back one passage",
17619
+ restart: "Start over",
17620
+ confirmProgress: "Update progress",
17621
+ invalidPosition: "Enter a whole passage number within the allowed range",
17622
+ progressUpdated: "Progress updated; the next active expansion starts at the new position",
17623
+ exportBackup: "Export backup",
17624
+ restoreBackup: "Restore backup",
17625
+ exportDone: "Backup downloaded. It contains book text, progress and settings; keep it safe.",
17626
+ restoreDescription: "The backup contains {count} books. Merge without deleting existing books; identical books keep their current progress. Restore the backup selection and reading settings, and clear this page\u2019s displayed novel passages.",
17627
+ confirmRestore: "Merge backup",
17628
+ restoreDone: "Restored: {added} added, {reused} reused (existing progress preserved)",
17027
17629
  removeConfirm: "Delete {title} and its local reading progress?"
17028
17630
  }
17029
17631
  };
@@ -17057,6 +17659,10 @@
17057
17659
  onSelectBook: (bookId) => store.selectBook(bookId),
17058
17660
  onDeleteBook: (bookId) => store.deleteBook(bookId),
17059
17661
  onImportFile: (file) => store.importFile(file),
17662
+ onSetProgress: (bookId, progress) => store.setProgress(bookId, progress),
17663
+ onExportBackup: async () => downloadBackup(await store.exportBackup()),
17664
+ onReadBackup: (file) => store.readBackup(file),
17665
+ onRestoreBackup: (backup) => store.restoreBackup(backup),
17060
17666
  sampleBooks,
17061
17667
  getSampleLicenseHref
17062
17668
  };