@libraz/mejiro-react 0.9.1 → 0.9.2

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,7 +4,7 @@ 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';
7
+ import { ChapterLayout, SpreadResult, BookOptions, MejiroBookOptions, ComputePageSizeOptions, InChapterAnchor, ReadingAnchor, ManuscriptChapter, PageResult, AnchorRect, AnchorRange, MejiroBook } from '@libraz/mejiro/book';
8
8
  import { RenderPage } from '@libraz/mejiro/render';
9
9
  import { FontFamily, InlineAnnotation } from '@libraz/mejiro/browser';
10
10
 
@@ -360,18 +360,20 @@ interface MejiroReaderHandle {
360
360
  next(): void;
361
361
  /** Go back one spread. */
362
362
  prev(): void;
363
- /** Jump to a chapter (resets spread index to 0). */
363
+ /** Jump to a chapter (clamped to the book's chapters; resets spread index to 0). */
364
364
  goToChapter(index: number): void;
365
365
  /** Read the current reading position. */
366
366
  getReadingPosition(): ReadingPosition;
367
367
  /**
368
368
  * Navigate to a {@link ReadingAnchor}. If the chapter differs from the
369
369
  * current one, the chapter is switched first; once the new layout is ready
370
- * the anchor is resolved and the matching spread is opened.
370
+ * the anchor is resolved and the matching spread is opened. A call made
371
+ * before the book has loaded is applied once it has.
371
372
  *
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.
373
+ * Returns a promise that resolves once the spread has been applied, or
374
+ * without moving when the anchor's chapter or position does not exist in the
375
+ * book. If another `goToAnchor` is invoked before the previous one settles,
376
+ * the earlier promise resolves immediately (superseded). Resolves on unmount.
375
377
  */
376
378
  goToAnchor(anchor: ReadingAnchor): Promise<void>;
377
379
  /**
@@ -434,8 +436,10 @@ interface MejiroReaderCommonProps {
434
436
  * ```ts
435
437
  * { ...DEFAULT_BOOK_OPTIONS, fontFamily: '"Noto Serif JP"', fontSize: 18 }
436
438
  * ```
439
+ *
440
+ * `strictFontCheck` is read once, when the reader mounts.
437
441
  */
438
- options?: Partial<BookOptions>;
442
+ options?: Partial<MejiroBookOptions>;
439
443
  /**
440
444
  * Page-geometry overrides forwarded to `MejiroBook.computePageSize`. Use to
441
445
  * tune how the spread is sized inside the surface — most usefully to shrink
@@ -1350,6 +1354,12 @@ interface UseChapterLayoutOptions {
1350
1354
  * first. Without it, consume `pendingRestore` yourself.
1351
1355
  */
1352
1356
  restorePosition?: (layout: ChapterLayout, position: InChapterAnchor) => void;
1357
+ /**
1358
+ * Called once when a layout of the current source fails, whichever path
1359
+ * started it (source change, resize or `recompute`); a superseded layout
1360
+ * reports nothing. When supplied, `recompute` resolves instead of rejecting.
1361
+ */
1362
+ onError?: (error: Error) => void;
1353
1363
  }
1354
1364
  /** Options for {@link UseChapterLayoutReturn.recompute}. */
1355
1365
  interface RecomputeOptions {
@@ -1382,7 +1392,10 @@ interface UseChapterLayoutReturn {
1382
1392
  contentHeight: number;
1383
1393
  /** Most recent layout time (ms). */
1384
1394
  elapsedMs: number;
1385
- /** Force a fresh layout computation. */
1395
+ /**
1396
+ * Force a fresh layout computation. A failure goes to `onError` when one is
1397
+ * supplied; otherwise the returned promise rejects.
1398
+ */
1386
1399
  recompute: (opts?: RecomputeOptions) => Promise<void>;
1387
1400
  /**
1388
1401
  * Anchor captured by `capturePosition` before the most recent reflow,
@@ -1612,7 +1625,10 @@ interface UseEpubProjectReturn {
1612
1625
  previewError: Error | null;
1613
1626
  /** Whether a preview build is pending or running. */
1614
1627
  previewing: boolean;
1615
- /** Merges `patch` into the metadata. */
1628
+ /**
1629
+ * Merges `patch` into the metadata. A missing or blank `identifier` keeps the
1630
+ * current one.
1631
+ */
1616
1632
  setMetadata: (patch: Partial<EpubProjectMetadata>) => void;
1617
1633
  /** Replaces every chapter; an empty list becomes one generated chapter. */
1618
1634
  setChapters: (chapters: EpubProjectChapterDraft[]) => void;
@@ -1729,6 +1745,12 @@ interface UseManuscriptLayoutOptions {
1729
1745
  * first. Without it, consume `pendingRestore` yourself.
1730
1746
  */
1731
1747
  restorePosition?: (layout: ChapterLayout, position: InChapterAnchor) => void;
1748
+ /**
1749
+ * Called once when a layout of the current source fails, whichever path
1750
+ * started it (source change, resize or `recompute`); a superseded layout
1751
+ * reports nothing. When supplied, `recompute` resolves instead of rejecting.
1752
+ */
1753
+ onError?: (error: Error) => void;
1732
1754
  }
1733
1755
  /** Options for {@link UseManuscriptLayoutReturn.recompute}. */
1734
1756
  interface ManuscriptRecomputeOptions {
@@ -1761,7 +1783,10 @@ interface UseManuscriptLayoutReturn {
1761
1783
  contentHeight: number;
1762
1784
  /** Most recent layout time (ms). */
1763
1785
  elapsedMs: number;
1764
- /** Force a fresh layout computation. */
1786
+ /**
1787
+ * Force a fresh layout computation. A failure goes to `onError` when one is
1788
+ * supplied; otherwise the returned promise rejects.
1789
+ */
1765
1790
  recompute: (opts?: ManuscriptRecomputeOptions) => Promise<void>;
1766
1791
  /**
1767
1792
  * Anchor captured by `capturePosition` before the most recent reflow,
@@ -1817,7 +1842,10 @@ interface UseMejiroBookOptions {
1817
1842
  interface UseMejiroBookReturn {
1818
1843
  /** The managed {@link MejiroBook} instance. Stable across renders. */
1819
1844
  book: MejiroBook;
1820
- /** Reactive snapshot of the current options. */
1845
+ /**
1846
+ * Reactive snapshot of the current options. Once the latest application
1847
+ * settles it holds what the book applied, so a rejected change rolls back.
1848
+ */
1821
1849
  options: Readonly<BookOptions>;
1822
1850
  /**
1823
1851
  * Update options on the underlying book and the snapshot. The snapshot is
@@ -1836,7 +1864,7 @@ interface UseMejiroBookReturn {
1836
1864
  * @param initial - Initial book options (passed to the {@link MejiroBook} constructor).
1837
1865
  * @param options - Behavior overrides (debouncing, error reporting).
1838
1866
  */
1839
- declare function useMejiroBook(initial: BookOptions, options?: UseMejiroBookOptions): UseMejiroBookReturn;
1867
+ declare function useMejiroBook(initial: MejiroBookOptions, options?: UseMejiroBookOptions): UseMejiroBookReturn;
1840
1868
 
1841
1869
  /** Minimal storage interface required by {@link useReadingPosition}. */
1842
1870
  type ReadingPositionStorage = MejiroStorage;