@libraz/mejiro-react 0.9.1 → 0.10.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 CHANGED
@@ -64,7 +64,9 @@ one-liner that rewrites them to the matching published release — run it before
64
64
 
65
65
  ## Documentation
66
66
 
67
- - [React / Vue guide](https://github.com/libraz/mejiro/tree/main/docs/en/08-react-and-vue.md) — components, hooks, props, theming, SSR
67
+ - [React / Vue guide](https://github.com/libraz/mejiro/tree/main/docs/en/08-react-and-vue.md) — components, hooks, props, theming
68
+ - [API reference](https://github.com/libraz/mejiro/tree/main/docs/en/10-api-reference.md#librazmejiro-react--react-component) — every component prop and hook
69
+ - [SSR first paint](https://github.com/libraz/mejiro/tree/main/docs/en/09-advanced.md#722-first-paint-under-ssr) — a `renderEpubStatic` fallback until the reader hydrates
68
70
  - [Project README](https://github.com/libraz/mejiro)
69
71
  - 日本語ドキュメント: [docs/ja/08-react-and-vue.md](https://github.com/libraz/mejiro/tree/main/docs/ja/08-react-and-vue.md)
70
72
 
package/dist/index.d.ts CHANGED
@@ -4,8 +4,9 @@ import * as react from 'react';
4
4
  import { ReactNode, CSSProperties, PointerEvent, TextareaHTMLAttributes, MutableRefObject, RefObject } from 'react';
5
5
  import { EpubBook, AssetResolver, EpubParseLimits, EditableEpub, ManuscriptDialect, EpubChapter, EditableEpubBook, EditableEpubSelection, AnnotatedParagraph, AddImageInput, EditableEpubImage, EpubExportOptions, EpubProjectMetadata, EpubProjectAsset, EpubProject } from '@libraz/mejiro/epub';
6
6
  export { EditableEpubSelection } from '@libraz/mejiro/epub';
7
- import { ChapterLayout, SpreadResult, BookOptions, ComputePageSizeOptions, InChapterAnchor, ReadingAnchor, ManuscriptChapter, PageResult, AnchorRect, AnchorRange, MejiroBook } from '@libraz/mejiro/book';
8
- import { RenderPage } from '@libraz/mejiro/render';
7
+ import { ChapterLayout, SpreadResult, BookOptions, MejiroBookOptions, ComputePageSizeOptions, InChapterAnchor, ReadingAnchor, ManuscriptChapter, PageResult, AnchorRect, AnchorRange, MejiroBook } from '@libraz/mejiro/book';
8
+ import { PageNumberDisplay, RenderPage } from '@libraz/mejiro/render';
9
+ export { PageNumberDisplay } from '@libraz/mejiro/render';
9
10
  import { FontFamily, InlineAnnotation } from '@libraz/mejiro/browser';
10
11
 
11
12
  /** Provider that scopes a message catalog to its descendants. */
@@ -16,7 +17,10 @@ declare function MejiroI18nProvider({ locale, messages, children, }: {
16
17
  }): ReactNode;
17
18
  /** Options for {@link useI18n}. */
18
19
  interface UseI18nOptions {
19
- /** Built-in locale to use as the base catalog. @defaultValue 'en' */
20
+ /**
21
+ * Built-in locale to use as the base catalog. Defaults to the nearest
22
+ * `MejiroI18nProvider` locale, or `'en'` without one.
23
+ */
20
24
  locale?: MejiroLocale;
21
25
  /** Overrides merged on top of the built-in catalog. */
22
26
  messages?: Partial<MejiroMessages>;
@@ -107,7 +111,9 @@ interface MejiroEditorProps {
107
111
  /** Font choices passed to the preview reader. */
108
112
  fonts?: FontChoice[];
109
113
  /**
110
- * Allow editing paragraph text (the "Proofread" section).
114
+ * Allow editing paragraph text (the "Proofread" section). When `false` and
115
+ * `enableRuby` is on, the paragraph text stays visible read-only so a ruby
116
+ * base range can still be selected.
111
117
  * @defaultValue true
112
118
  */
113
119
  enableProofread?: boolean;
@@ -158,8 +164,9 @@ interface MejiroEditorProps {
158
164
  /** Called after export completes. */
159
165
  onExport?: (buffer: ArrayBuffer) => void;
160
166
  /**
161
- * Called when loading, image insertion or export fails. The error is also
162
- * shown in the editor.
167
+ * Called when loading, image insertion, export or the preview reader fails.
168
+ * The error is also shown in the editor until a later load, image insertion
169
+ * or export succeeds.
163
170
  */
164
171
  onError?: (error: Error) => void;
165
172
  }
@@ -290,11 +297,7 @@ type MejiroReaderMode = 'paginated' | 'scroll';
290
297
  * converting the index so the page on screen stays visible.
291
298
  */
292
299
  type MejiroSpreadMode = 'double' | 'single' | 'auto';
293
- /**
294
- * Which page of a spread prints its page number: `'both'` (right = odd,
295
- * left = even), only `'right'`, only `'left'`, or `'none'`.
296
- */
297
- type PageNumberDisplay = 'both' | 'right' | 'left' | 'none';
300
+
298
301
  /**
299
302
  * How the reader sizes itself inside its container.
300
303
  * - `fill` — fill the container's given height; the spread is fitted inside it,
@@ -360,18 +363,20 @@ interface MejiroReaderHandle {
360
363
  next(): void;
361
364
  /** Go back one spread. */
362
365
  prev(): void;
363
- /** Jump to a chapter (resets spread index to 0). */
366
+ /** Jump to a chapter (clamped to the book's chapters; resets spread index to 0). */
364
367
  goToChapter(index: number): void;
365
368
  /** Read the current reading position. */
366
369
  getReadingPosition(): ReadingPosition;
367
370
  /**
368
371
  * Navigate to a {@link ReadingAnchor}. If the chapter differs from the
369
372
  * current one, the chapter is switched first; once the new layout is ready
370
- * the anchor is resolved and the matching spread is opened.
373
+ * the anchor is resolved and the matching spread is opened. A call made
374
+ * before the book has loaded is applied once it has.
371
375
  *
372
- * Returns a promise that resolves once the spread has been applied. If
373
- * another `goToAnchor` is invoked before the previous one settles, the
374
- * earlier promise resolves immediately (superseded). Resolves on unmount.
376
+ * Returns a promise that resolves once the spread has been applied, or
377
+ * without moving when the anchor's chapter or position does not exist in the
378
+ * book. If another `goToAnchor` is invoked before the previous one settles,
379
+ * the earlier promise resolves immediately (superseded). Resolves on unmount.
375
380
  */
376
381
  goToAnchor(anchor: ReadingAnchor): Promise<void>;
377
382
  /**
@@ -434,8 +439,10 @@ interface MejiroReaderCommonProps {
434
439
  * ```ts
435
440
  * { ...DEFAULT_BOOK_OPTIONS, fontFamily: '"Noto Serif JP"', fontSize: 18 }
436
441
  * ```
442
+ *
443
+ * `strictFontCheck` is read once, when the reader mounts.
437
444
  */
438
- options?: Partial<BookOptions>;
445
+ options?: Partial<MejiroBookOptions>;
439
446
  /**
440
447
  * Page-geometry overrides forwarded to `MejiroBook.computePageSize`. Use to
441
448
  * tune how the spread is sized inside the surface — most usefully to shrink
@@ -522,7 +529,8 @@ interface MejiroReaderCommonProps {
522
529
  fetchEpub?: (url: string) => Promise<ArrayBuffer>;
523
530
  /**
524
531
  * Built-in locale for UI strings (`'en'` / `'ja'`). Pair with `messages`
525
- * to override individual strings. @defaultValue 'en'
532
+ * to override individual strings. Defaults to the nearest `MejiroI18nProvider`
533
+ * locale, or `'en'` without one.
526
534
  */
527
535
  locale?: MejiroLocale;
528
536
  /**
@@ -621,9 +629,11 @@ interface MejiroReaderCommonProps {
621
629
  /** Called when the spread index changes — pair with the `spreadIdx` prop for controlled use. */
622
630
  onSpreadIdxChange?: (spreadIdx: number) => void;
623
631
  /**
624
- * Called when the reader leaves a spread. Receives the anchor of the
625
- * spread that was just left and the dwell time in milliseconds (computed
626
- * via `performance.now()`). Useful for engagement analytics.
632
+ * Called when the reader moves from one spread to another within the shown
633
+ * book (a change of chapter or spread index, like `spreadChanged`). Receives
634
+ * the anchor of the spread that was just left and the dwell time in
635
+ * milliseconds (computed via `performance.now()`). A book swap and unmount
636
+ * do not report the spread being left. Useful for engagement analytics.
627
637
  */
628
638
  onPageRead?: (anchor: ReadingAnchor, dwellMs: number) => void;
629
639
  /**
@@ -809,7 +819,7 @@ interface MejiroManuscriptEditorProps {
809
819
  onExport?: (buffer: ArrayBuffer) => void;
810
820
  /**
811
821
  * Called when the EPUB export fails (asset resolution, cover reading, or
812
- * packaging). The same error is shown in the editor panel, so hosts only
822
+ * packaging) or the preview reader fails. The same error is shown in the editor panel, so hosts only
813
823
  * need this to log or report it.
814
824
  */
815
825
  onError?: (error: Error) => void;
@@ -1013,6 +1023,11 @@ interface MejiroScrollViewProps {
1013
1023
  * provides one on every change.
1014
1024
  */
1015
1025
  images?: MultiImageItem[];
1026
+ /**
1027
+ * Which pages print their page number in the running head, by the same rule
1028
+ * as the paginated reader. @defaultValue 'both'
1029
+ */
1030
+ pageNumbers?: PageNumberDisplay;
1016
1031
  /** Pointer-down on an image overlay. */
1017
1032
  onImagePointerDown?: (id: string, e: PointerEvent) => void;
1018
1033
  /** Pointer-down on an image resize handle. */
@@ -1026,7 +1041,7 @@ interface MejiroScrollViewProps {
1026
1041
  * detected via `IntersectionObserver` and reported through
1027
1042
  * {@link MejiroScrollViewProps.onVisiblePageChange}.
1028
1043
  */
1029
- declare function MejiroScrollView({ layout, pageWidth, pageHeight, contentHeight, fontFamily, fontSize, lineSpacing, slotMode, onVisiblePageChange, scrollToPage, pageGap, selectionRects, spreadIdx, images, onImagePointerDown, onImageResizePointerDown, onImageClose, }: MejiroScrollViewProps): ReactNode;
1044
+ declare function MejiroScrollView({ layout, pageWidth, pageHeight, contentHeight, fontFamily, fontSize, lineSpacing, slotMode, onVisiblePageChange, scrollToPage, pageGap, selectionRects, spreadIdx, images, pageNumbers, onImagePointerDown, onImageResizePointerDown, onImageClose, }: MejiroScrollViewProps): ReactNode;
1030
1045
 
1031
1046
  /** Props for {@link MejiroSelectionLayer}. */
1032
1047
  interface MejiroSelectionLayerProps {
@@ -1281,7 +1296,9 @@ interface UseAnnotationsOptions {
1281
1296
  * every render is safe — only `key` triggers a re-hydration.
1282
1297
  */
1283
1298
  storage?: AnnotationsStorage;
1284
- /** Throttle ms between writes. @defaultValue 250 */
1299
+ /**
1300
+ * Debounce delay (ms): the latest value is written this long after the last change. A pending write is flushed on page hide, key change and unmount. @defaultValue 250
1301
+ */
1285
1302
  throttleMs?: number;
1286
1303
  /**
1287
1304
  * Called immediately after each mutation (`add` / `remove` / `update` /
@@ -1350,6 +1367,12 @@ interface UseChapterLayoutOptions {
1350
1367
  * first. Without it, consume `pendingRestore` yourself.
1351
1368
  */
1352
1369
  restorePosition?: (layout: ChapterLayout, position: InChapterAnchor) => void;
1370
+ /**
1371
+ * Called once when a layout of the current source fails, whichever path
1372
+ * started it (source change, resize or `recompute`); a superseded layout
1373
+ * reports nothing. When supplied, `recompute` resolves instead of rejecting.
1374
+ */
1375
+ onError?: (error: Error) => void;
1353
1376
  }
1354
1377
  /** Options for {@link UseChapterLayoutReturn.recompute}. */
1355
1378
  interface RecomputeOptions {
@@ -1382,7 +1405,10 @@ interface UseChapterLayoutReturn {
1382
1405
  contentHeight: number;
1383
1406
  /** Most recent layout time (ms). */
1384
1407
  elapsedMs: number;
1385
- /** Force a fresh layout computation. */
1408
+ /**
1409
+ * Force a fresh layout computation. A failure goes to `onError` when one is
1410
+ * supplied; otherwise the returned promise rejects.
1411
+ */
1386
1412
  recompute: (opts?: RecomputeOptions) => Promise<void>;
1387
1413
  /**
1388
1414
  * Anchor captured by `capturePosition` before the most recent reflow,
@@ -1612,7 +1638,10 @@ interface UseEpubProjectReturn {
1612
1638
  previewError: Error | null;
1613
1639
  /** Whether a preview build is pending or running. */
1614
1640
  previewing: boolean;
1615
- /** Merges `patch` into the metadata. */
1641
+ /**
1642
+ * Merges `patch` into the metadata. A missing or blank `identifier` keeps the
1643
+ * current one.
1644
+ */
1616
1645
  setMetadata: (patch: Partial<EpubProjectMetadata>) => void;
1617
1646
  /** Replaces every chapter; an empty list becomes one generated chapter. */
1618
1647
  setChapters: (chapters: EpubProjectChapterDraft[]) => void;
@@ -1729,6 +1758,12 @@ interface UseManuscriptLayoutOptions {
1729
1758
  * first. Without it, consume `pendingRestore` yourself.
1730
1759
  */
1731
1760
  restorePosition?: (layout: ChapterLayout, position: InChapterAnchor) => void;
1761
+ /**
1762
+ * Called once when a layout of the current source fails, whichever path
1763
+ * started it (source change, resize or `recompute`); a superseded layout
1764
+ * reports nothing. When supplied, `recompute` resolves instead of rejecting.
1765
+ */
1766
+ onError?: (error: Error) => void;
1732
1767
  }
1733
1768
  /** Options for {@link UseManuscriptLayoutReturn.recompute}. */
1734
1769
  interface ManuscriptRecomputeOptions {
@@ -1761,7 +1796,10 @@ interface UseManuscriptLayoutReturn {
1761
1796
  contentHeight: number;
1762
1797
  /** Most recent layout time (ms). */
1763
1798
  elapsedMs: number;
1764
- /** Force a fresh layout computation. */
1799
+ /**
1800
+ * Force a fresh layout computation. A failure goes to `onError` when one is
1801
+ * supplied; otherwise the returned promise rejects.
1802
+ */
1765
1803
  recompute: (opts?: ManuscriptRecomputeOptions) => Promise<void>;
1766
1804
  /**
1767
1805
  * Anchor captured by `capturePosition` before the most recent reflow,
@@ -1779,7 +1817,8 @@ interface UseManuscriptLayoutReturn {
1779
1817
  * {@link useManuscriptDraft} for the chapter array and feed the resulting
1780
1818
  * {@link ChapterLayout} into {@link MejiroSpread} or {@link MejiroScrollView}.
1781
1819
  *
1782
- * Re-layouts whenever `chapter`, `dialect`, or `book` change. The surface is
1820
+ * Re-layouts whenever the chapter's id, title or body, `dialect`, or `book`
1821
+ * change; a new chapter object with the same content does not. The surface is
1783
1822
  * observed with {@link ResizeObserver}; size changes trigger a full re-layout
1784
1823
  * so pagination stays correct after non-trivial container changes.
1785
1824
  *
@@ -1817,7 +1856,10 @@ interface UseMejiroBookOptions {
1817
1856
  interface UseMejiroBookReturn {
1818
1857
  /** The managed {@link MejiroBook} instance. Stable across renders. */
1819
1858
  book: MejiroBook;
1820
- /** Reactive snapshot of the current options. */
1859
+ /**
1860
+ * Reactive snapshot of the current options. Once the latest application
1861
+ * settles it holds what the book applied, so a rejected change rolls back.
1862
+ */
1821
1863
  options: Readonly<BookOptions>;
1822
1864
  /**
1823
1865
  * Update options on the underlying book and the snapshot. The snapshot is
@@ -1836,7 +1878,7 @@ interface UseMejiroBookReturn {
1836
1878
  * @param initial - Initial book options (passed to the {@link MejiroBook} constructor).
1837
1879
  * @param options - Behavior overrides (debouncing, error reporting).
1838
1880
  */
1839
- declare function useMejiroBook(initial: BookOptions, options?: UseMejiroBookOptions): UseMejiroBookReturn;
1881
+ declare function useMejiroBook(initial: MejiroBookOptions, options?: UseMejiroBookOptions): UseMejiroBookReturn;
1840
1882
 
1841
1883
  /** Minimal storage interface required by {@link useReadingPosition}. */
1842
1884
  type ReadingPositionStorage = MejiroStorage;
@@ -1849,7 +1891,9 @@ interface UseReadingPositionOptions {
1849
1891
  * SSR consumers can omit this and the hook will fall back to in-memory.
1850
1892
  */
1851
1893
  storage?: ReadingPositionStorage;
1852
- /** Throttle ms between writes. @defaultValue 250 */
1894
+ /**
1895
+ * Debounce delay (ms): the latest value is written this long after the last change. A pending write is flushed on page hide, key change and unmount. @defaultValue 250
1896
+ */
1853
1897
  throttleMs?: number;
1854
1898
  /**
1855
1899
  * Called immediately after `save()` (with the new anchor) or `clear()`
@@ -1862,14 +1906,14 @@ interface UseReadingPositionOptions {
1862
1906
  interface UseReadingPositionReturn {
1863
1907
  /** Most recently persisted position, or `null` if none. */
1864
1908
  position: ReadingPositionValue | null;
1865
- /** Persist a new position (throttled). */
1909
+ /** Persist a new position (debounced by `throttleMs`). */
1866
1910
  save(next: ReadingPositionValue): void;
1867
1911
  /** Remove the persisted position. */
1868
1912
  clear(): void;
1869
1913
  }
1870
1914
  /**
1871
1915
  * Persistence helper for reader state. Returns the saved anchor and a
1872
- * throttled saver. Pair with {@link MejiroReaderHandle.goToAnchor} and
1916
+ * debounced saver. Pair with {@link MejiroReaderHandle.goToAnchor} and
1873
1917
  * {@link MejiroReaderHandle.subscribe} for exact reflow-safe restore.
1874
1918
  *
1875
1919
  * ```tsx
@@ -1958,4 +2002,5 @@ interface UseSpreadReturn {
1958
2002
  */
1959
2003
  declare function useSpread(layout: ChapterLayout | null, options?: UseSpreadOptions): UseSpreadReturn;
1960
2004
 
1961
- export { type AnnotationsStorage, type EpubProjectChapterDraft, type ImageRect, type ManuscriptAutosaveDraft, type ManuscriptEditorChapter, type ManuscriptPageDimensions, type ManuscriptPreviewProps, type ManuscriptRecomputeOptions, MejiroChapterNav, type MejiroChapterNavMode, type MejiroChapterNavProps, type MejiroChapterNavVariant, MejiroDropZone, type MejiroDropZoneProps, MejiroEditor, type MejiroEditorProps, type MejiroExportPolicy, MejiroI18nProvider, MejiroImageOverlay, type MejiroImageOverlayProps, MejiroManuscriptEditor, type MejiroManuscriptEditorProps, MejiroNotationHighlighter, type MejiroNotationHighlighterProps, MejiroPage, MejiroPageIndicator, type MejiroPageIndicatorProps, type MejiroPageProps, MejiroPageView, type MejiroPageViewProps, MejiroReader, type MejiroReaderCommonProps, type MejiroReaderControlledProps, type MejiroReaderEventMap, type MejiroReaderFileProps, type MejiroReaderFit, type MejiroReaderHandle, type MejiroReaderManuscriptProps, type MejiroReaderMode, type MejiroReaderProps, type MejiroReaderSettingsSlot, type MejiroReaderUrlProps, MejiroScrollView, type MejiroScrollViewProps, MejiroSelectionLayer, type MejiroSelectionLayerProps, MejiroSettingsPanel, type MejiroSettingsPanelProps, MejiroShelf, type MejiroShelfProps, MejiroSpread, type MejiroSpreadMode, type MejiroSpreadProps, MejiroStats, type MejiroStatsProps, type MejiroTheme, type MejiroThemeName, MejiroToc, type MejiroTocProps, type MultiImageItem, type PageDimensions, type PageNumberDisplay, type ReadingPosition, type ReadingPositionStorage, type RecomputeOptions, type UseAnnotationsOptions, type UseAnnotationsReturn, type UseChapterLayoutOptions, type UseChapterLayoutReturn, type UseEditableEpubOptions, type UseEditableEpubReturn, type UseEpubOptions, type UseEpubProjectOptions, type UseEpubProjectReturn, type UseEpubReturn, type UseI18nOptions, type UseImageOverlayOptions, type UseImageOverlayReturn, type UseLibraryOptions, type UseLibraryReturn, type UseManuscriptDraftOptions, type UseManuscriptDraftReturn, type UseManuscriptLayoutOptions, type UseManuscriptLayoutReturn, type UseMejiroBookOptions, type UseMejiroBookReturn, type UseMultiImageOverlayOptions, type UseMultiImageOverlayReturn, type UseReadingPositionOptions, type UseReadingPositionReturn, type UseSpreadOptions, type UseSpreadReturn, type VolumeInfo, format, resolveMessages, useAnnotations, useChapterLayout, useEditableEpub, useEpub, useEpubProject, useI18n, useImageOverlay, useLibrary, useManuscriptDraft, useManuscriptLayout, useMejiroBook, useMultiImageOverlay, useReadingPosition, useSpread };
2005
+ export { MejiroChapterNav, MejiroDropZone, MejiroEditor, MejiroI18nProvider, MejiroImageOverlay, MejiroManuscriptEditor, MejiroNotationHighlighter, MejiroPage, MejiroPageIndicator, MejiroPageView, MejiroReader, MejiroScrollView, MejiroSelectionLayer, MejiroSettingsPanel, MejiroShelf, MejiroSpread, MejiroStats, MejiroToc, format, resolveMessages, useAnnotations, useChapterLayout, useEditableEpub, useEpub, useEpubProject, useI18n, useImageOverlay, useLibrary, useManuscriptDraft, useManuscriptLayout, useMejiroBook, useMultiImageOverlay, useReadingPosition, useSpread };
2006
+ export type { AnnotationsStorage, EpubProjectChapterDraft, ImageRect, ManuscriptAutosaveDraft, ManuscriptEditorChapter, ManuscriptPageDimensions, ManuscriptPreviewProps, ManuscriptRecomputeOptions, MejiroChapterNavMode, MejiroChapterNavProps, MejiroChapterNavVariant, MejiroDropZoneProps, MejiroEditorProps, MejiroExportPolicy, MejiroImageOverlayProps, MejiroManuscriptEditorProps, MejiroNotationHighlighterProps, MejiroPageIndicatorProps, MejiroPageProps, MejiroPageViewProps, MejiroReaderCommonProps, MejiroReaderControlledProps, MejiroReaderEventMap, MejiroReaderFileProps, MejiroReaderFit, MejiroReaderHandle, MejiroReaderManuscriptProps, MejiroReaderMode, MejiroReaderProps, MejiroReaderSettingsSlot, MejiroReaderUrlProps, MejiroScrollViewProps, MejiroSelectionLayerProps, MejiroSettingsPanelProps, MejiroShelfProps, MejiroSpreadMode, MejiroSpreadProps, MejiroStatsProps, MejiroTheme, MejiroThemeName, MejiroTocProps, MultiImageItem, PageDimensions, ReadingPosition, ReadingPositionStorage, RecomputeOptions, UseAnnotationsOptions, UseAnnotationsReturn, UseChapterLayoutOptions, UseChapterLayoutReturn, UseEditableEpubOptions, UseEditableEpubReturn, UseEpubOptions, UseEpubProjectOptions, UseEpubProjectReturn, UseEpubReturn, UseI18nOptions, UseImageOverlayOptions, UseImageOverlayReturn, UseLibraryOptions, UseLibraryReturn, UseManuscriptDraftOptions, UseManuscriptDraftReturn, UseManuscriptLayoutOptions, UseManuscriptLayoutReturn, UseMejiroBookOptions, UseMejiroBookReturn, UseMultiImageOverlayOptions, UseMultiImageOverlayReturn, UseReadingPositionOptions, UseReadingPositionReturn, UseSpreadOptions, UseSpreadReturn, VolumeInfo };