wolfy-reader 0.1.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/LICENSE +21 -0
- package/README.md +277 -0
- package/dist/core/book.d.ts +75 -0
- package/dist/core/book.d.ts.map +1 -0
- package/dist/core/book.js +2 -0
- package/dist/core/book.js.map +1 -0
- package/dist/core/errors.d.ts +17 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +29 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/format.d.ts +13 -0
- package/dist/core/format.d.ts.map +1 -0
- package/dist/core/format.js +2 -0
- package/dist/core/format.js.map +1 -0
- package/dist/core/graphemes.d.ts +36 -0
- package/dist/core/graphemes.d.ts.map +1 -0
- package/dist/core/graphemes.js +62 -0
- package/dist/core/graphemes.js.map +1 -0
- package/dist/core/index.d.ts +11 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +6 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/lookup.d.ts +10 -0
- package/dist/core/lookup.d.ts.map +1 -0
- package/dist/core/lookup.js +16 -0
- package/dist/core/lookup.js.map +1 -0
- package/dist/core/open.d.ts +12 -0
- package/dist/core/open.d.ts.map +1 -0
- package/dist/core/open.js +23 -0
- package/dist/core/open.js.map +1 -0
- package/dist/core/position.d.ts +121 -0
- package/dist/core/position.d.ts.map +1 -0
- package/dist/core/position.js +327 -0
- package/dist/core/position.js.map +1 -0
- package/dist/core/reading-text.d.ts +77 -0
- package/dist/core/reading-text.d.ts.map +1 -0
- package/dist/core/reading-text.js +144 -0
- package/dist/core/reading-text.js.map +1 -0
- package/dist/core/source.d.ts +17 -0
- package/dist/core/source.d.ts.map +1 -0
- package/dist/core/source.js +39 -0
- package/dist/core/source.js.map +1 -0
- package/dist/core/storage.d.ts +7 -0
- package/dist/core/storage.d.ts.map +1 -0
- package/dist/core/storage.js +2 -0
- package/dist/core/storage.js.map +1 -0
- package/dist/core/text.d.ts +18 -0
- package/dist/core/text.d.ts.map +1 -0
- package/dist/core/text.js +32 -0
- package/dist/core/text.js.map +1 -0
- package/dist/formats/epub/href.d.ts +14 -0
- package/dist/formats/epub/href.d.ts.map +1 -0
- package/dist/formats/epub/href.js +52 -0
- package/dist/formats/epub/href.js.map +1 -0
- package/dist/formats/epub/index.d.ts +3 -0
- package/dist/formats/epub/index.d.ts.map +1 -0
- package/dist/formats/epub/index.js +223 -0
- package/dist/formats/epub/index.js.map +1 -0
- package/dist/formats/epub/opf.d.ts +27 -0
- package/dist/formats/epub/opf.d.ts.map +1 -0
- package/dist/formats/epub/opf.js +110 -0
- package/dist/formats/epub/opf.js.map +1 -0
- package/dist/formats/epub/toc.d.ts +6 -0
- package/dist/formats/epub/toc.d.ts.map +1 -0
- package/dist/formats/epub/toc.js +88 -0
- package/dist/formats/epub/toc.js.map +1 -0
- package/dist/formats/fb2/index.d.ts +13 -0
- package/dist/formats/fb2/index.d.ts.map +1 -0
- package/dist/formats/fb2/index.js +317 -0
- package/dist/formats/fb2/index.js.map +1 -0
- package/dist/formats/index.d.ts +4 -0
- package/dist/formats/index.d.ts.map +1 -0
- package/dist/formats/index.js +4 -0
- package/dist/formats/index.js.map +1 -0
- package/dist/formats/text/index.d.ts +11 -0
- package/dist/formats/text/index.d.ts.map +1 -0
- package/dist/formats/text/index.js +201 -0
- package/dist/formats/text/index.js.map +1 -0
- package/dist/formats/xml.d.ts +33 -0
- package/dist/formats/xml.d.ts.map +1 -0
- package/dist/formats/xml.js +321 -0
- package/dist/formats/xml.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/layout/chunk.d.ts +51 -0
- package/dist/layout/chunk.d.ts.map +1 -0
- package/dist/layout/chunk.js +131 -0
- package/dist/layout/chunk.js.map +1 -0
- package/dist/layout/index.d.ts +238 -0
- package/dist/layout/index.d.ts.map +1 -0
- package/dist/layout/index.js +476 -0
- package/dist/layout/index.js.map +1 -0
- package/dist/reader/index.d.ts +231 -0
- package/dist/reader/index.d.ts.map +1 -0
- package/dist/reader/index.js +958 -0
- package/dist/reader/index.js.map +1 -0
- package/dist/reader/input.d.ts +69 -0
- package/dist/reader/input.d.ts.map +1 -0
- package/dist/reader/input.js +75 -0
- package/dist/reader/input.js.map +1 -0
- package/dist/search/extract.d.ts +51 -0
- package/dist/search/extract.d.ts.map +1 -0
- package/dist/search/extract.js +401 -0
- package/dist/search/extract.js.map +1 -0
- package/dist/search/index.d.ts +11 -0
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/index.js +11 -0
- package/dist/search/index.js.map +1 -0
- package/dist/search/matcher.d.ts +56 -0
- package/dist/search/matcher.d.ts.map +1 -0
- package/dist/search/matcher.js +128 -0
- package/dist/search/matcher.js.map +1 -0
- package/dist/search/normalize.d.ts +48 -0
- package/dist/search/normalize.d.ts.map +1 -0
- package/dist/search/normalize.js +103 -0
- package/dist/search/normalize.js.map +1 -0
- package/dist/view/allowlist.d.ts +59 -0
- package/dist/view/allowlist.d.ts.map +1 -0
- package/dist/view/allowlist.js +198 -0
- package/dist/view/allowlist.js.map +1 -0
- package/dist/view/appearance.d.ts +137 -0
- package/dist/view/appearance.d.ts.map +1 -0
- package/dist/view/appearance.js +274 -0
- package/dist/view/appearance.js.map +1 -0
- package/dist/view/css.d.ts +24 -0
- package/dist/view/css.d.ts.map +1 -0
- package/dist/view/css.js +153 -0
- package/dist/view/css.js.map +1 -0
- package/dist/view/frame.d.ts +54 -0
- package/dist/view/frame.d.ts.map +1 -0
- package/dist/view/frame.js +980 -0
- package/dist/view/frame.js.map +1 -0
- package/dist/view/host.d.ts +160 -0
- package/dist/view/host.d.ts.map +1 -0
- package/dist/view/host.js +385 -0
- package/dist/view/host.js.map +1 -0
- package/dist/view/index.d.ts +12 -0
- package/dist/view/index.d.ts.map +1 -0
- package/dist/view/index.js +7 -0
- package/dist/view/index.js.map +1 -0
- package/dist/view/protocol.d.ts +220 -0
- package/dist/view/protocol.d.ts.map +1 -0
- package/dist/view/protocol.js +246 -0
- package/dist/view/protocol.js.map +1 -0
- package/dist/view/reference.d.ts +18 -0
- package/dist/view/reference.d.ts.map +1 -0
- package/dist/view/reference.js +25 -0
- package/dist/view/reference.js.map +1 -0
- package/dist/view/resources.d.ts +51 -0
- package/dist/view/resources.d.ts.map +1 -0
- package/dist/view/resources.js +242 -0
- package/dist/view/resources.js.map +1 -0
- package/dist/view/sanitize.d.ts +32 -0
- package/dist/view/sanitize.d.ts.map +1 -0
- package/dist/view/sanitize.js +226 -0
- package/dist/view/sanitize.js.map +1 -0
- package/dist/zip/central.d.ts +12 -0
- package/dist/zip/central.d.ts.map +1 -0
- package/dist/zip/central.js +72 -0
- package/dist/zip/central.js.map +1 -0
- package/dist/zip/crc32.d.ts +3 -0
- package/dist/zip/crc32.d.ts.map +1 -0
- package/dist/zip/crc32.js +28 -0
- package/dist/zip/crc32.js.map +1 -0
- package/dist/zip/eocd.d.ts +9 -0
- package/dist/zip/eocd.d.ts.map +1 -0
- package/dist/zip/eocd.js +84 -0
- package/dist/zip/eocd.js.map +1 -0
- package/dist/zip/errors.d.ts +19 -0
- package/dist/zip/errors.d.ts.map +1 -0
- package/dist/zip/errors.js +37 -0
- package/dist/zip/errors.js.map +1 -0
- package/dist/zip/index.d.ts +18 -0
- package/dist/zip/index.d.ts.map +1 -0
- package/dist/zip/index.js +78 -0
- package/dist/zip/index.js.map +1 -0
- package/dist/zip/inflate.d.ts +2 -0
- package/dist/zip/inflate.d.ts.map +1 -0
- package/dist/zip/inflate.js +43 -0
- package/dist/zip/inflate.js.map +1 -0
- package/dist/zip/source.d.ts +15 -0
- package/dist/zip/source.d.ts.map +1 -0
- package/dist/zip/source.js +34 -0
- package/dist/zip/source.js.map +1 -0
- package/package.json +75 -0
- package/src/core/book.ts +80 -0
- package/src/core/errors.ts +31 -0
- package/src/core/format.ts +14 -0
- package/src/core/graphemes.ts +73 -0
- package/src/core/index.ts +27 -0
- package/src/core/lookup.ts +16 -0
- package/src/core/open.ts +31 -0
- package/src/core/position.ts +485 -0
- package/src/core/reading-text.ts +200 -0
- package/src/core/source.ts +61 -0
- package/src/core/storage.ts +6 -0
- package/src/core/text.ts +35 -0
- package/src/formats/epub/href.ts +54 -0
- package/src/formats/epub/index.ts +235 -0
- package/src/formats/epub/opf.ts +143 -0
- package/src/formats/epub/toc.ts +120 -0
- package/src/formats/fb2/index.ts +348 -0
- package/src/formats/index.ts +3 -0
- package/src/formats/text/index.ts +208 -0
- package/src/formats/xml.ts +326 -0
- package/src/index.ts +26 -0
- package/src/layout/chunk.ts +169 -0
- package/src/layout/index.ts +573 -0
- package/src/reader/index.ts +1206 -0
- package/src/reader/input.ts +122 -0
- package/src/search/extract.ts +403 -0
- package/src/search/index.ts +10 -0
- package/src/search/matcher.ts +187 -0
- package/src/search/normalize.ts +122 -0
- package/src/view/allowlist.ts +273 -0
- package/src/view/appearance.ts +380 -0
- package/src/view/css.ts +172 -0
- package/src/view/frame.ts +1018 -0
- package/src/view/host.ts +527 -0
- package/src/view/index.ts +24 -0
- package/src/view/protocol.ts +412 -0
- package/src/view/reference.ts +30 -0
- package/src/view/resources.ts +265 -0
- package/src/view/sanitize.ts +266 -0
- package/src/zip/central.ts +85 -0
- package/src/zip/crc32.ts +30 -0
- package/src/zip/eocd.ts +97 -0
- package/src/zip/errors.ts +41 -0
- package/src/zip/index.ts +114 -0
- package/src/zip/inflate.ts +41 -0
- package/src/zip/source.ts +51 -0
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The public reader facade: opens a decoded {@link Book} into a container element
|
|
3
|
+
* and returns a {@link Reader} that turns pages and sections, navigates to any
|
|
4
|
+
* target, follows internal links with a back-stack, reports position, emits
|
|
5
|
+
* events, and switches paginated↔scrolled without losing the reader's place.
|
|
6
|
+
*
|
|
7
|
+
* This module lives *outside* `src/core` on purpose. Core is headless by rule —
|
|
8
|
+
* nothing reachable from `src/core/index.ts` may import `src/view` or `src/layout`
|
|
9
|
+
* (`npm run check:core`). The PLAN §4 sketch shows `book.render(...)`; that method
|
|
10
|
+
* cannot exist on the core `Book`, so the shape is relocated here as a free
|
|
11
|
+
* function `render(book, element, options)` keeping the sketched object surface
|
|
12
|
+
* (`next/prev`, `nextSection/prevSection`, `goTo`, `back`, `position`, `on`,
|
|
13
|
+
* `setMode`, `destroy`).
|
|
14
|
+
*
|
|
15
|
+
* The facade owns no format vocabulary and never fetches or persists: bytes came
|
|
16
|
+
* in as a `Book`, page geometry comes from the {@link Paginator}, and reading
|
|
17
|
+
* positions are the headless `Position` model from core. It drives the paginator
|
|
18
|
+
* and reads the book; it never reaches past the paginator into frame geometry.
|
|
19
|
+
*/
|
|
20
|
+
import type { Book, Position, SentenceRange, TocItem } from '../core/index.ts';
|
|
21
|
+
import { parsePosition } from '../core/index.ts';
|
|
22
|
+
import { type LayoutMode } from '../layout/index.ts';
|
|
23
|
+
import { type SearchHit, type SearchOptions } from '../search/index.ts';
|
|
24
|
+
import { type Appearance, type TextAlign, type ThemeName } from '../view/appearance.ts';
|
|
25
|
+
import { type InputConfig } from './input.ts';
|
|
26
|
+
export type { InputConfig, TapZones } from './input.ts';
|
|
27
|
+
export type { Appearance, TextAlign, ThemeName } from '../view/appearance.ts';
|
|
28
|
+
export type { SearchHit, SearchOptions } from '../search/index.ts';
|
|
29
|
+
/**
|
|
30
|
+
* Appearance and layout options for {@link render}. All optional. `mode` selects
|
|
31
|
+
* paginated (default) or scrolled layout. The theme and typography fields drive
|
|
32
|
+
* the appearance system and are applied at the first render; change any of them
|
|
33
|
+
* live afterward with {@link Reader.setAppearance}.
|
|
34
|
+
*/
|
|
35
|
+
export interface ReaderOptions {
|
|
36
|
+
/** 'paginated' (default) or 'scrolled'. */
|
|
37
|
+
readonly mode?: LayoutMode;
|
|
38
|
+
/**
|
|
39
|
+
* The theme applied to content: `'light' | 'dark' | 'sepia' | 'custom'`. Omit
|
|
40
|
+
* to follow the OS (`prefers-color-scheme`); a named theme overrides it. Change
|
|
41
|
+
* it live with {@link Reader.setAppearance}.
|
|
42
|
+
*/
|
|
43
|
+
readonly theme?: ThemeName;
|
|
44
|
+
/**
|
|
45
|
+
* Bespoke `--wr-*` CSS custom properties, merged over the resolved theme. The
|
|
46
|
+
* escape hatch for a custom theme; keys may omit the leading `--`.
|
|
47
|
+
*/
|
|
48
|
+
readonly customProperties?: Readonly<Record<string, string>>;
|
|
49
|
+
/** Body font size in CSS px. Applied at the first render; change it live with {@link Reader.setAppearance}. */
|
|
50
|
+
readonly fontSize?: number;
|
|
51
|
+
/** Body font family. Applied at the first render. */
|
|
52
|
+
readonly fontFamily?: string;
|
|
53
|
+
/** Body line height (unitless multiplier). Applied at the first render. */
|
|
54
|
+
readonly lineHeight?: number;
|
|
55
|
+
/** Page-edge margin in CSS px (also the inter-column gutter), threaded to the paginator as `columnGap`. */
|
|
56
|
+
readonly margin?: number;
|
|
57
|
+
/** Body text alignment: `'start'` (publisher default) or `'justify'`. */
|
|
58
|
+
readonly textAlign?: TextAlign;
|
|
59
|
+
/** Shorthand for `textAlign: 'justify'`. */
|
|
60
|
+
readonly justify?: boolean;
|
|
61
|
+
/** Whether the content root hyphenates. */
|
|
62
|
+
readonly hyphenate?: boolean;
|
|
63
|
+
/** Text columns per page: 1 (default) or 2. Applied at the first render. */
|
|
64
|
+
readonly columns?: 1 | 2;
|
|
65
|
+
/** Where to open. Any {@link GoToTarget}; defaults to the book's start. */
|
|
66
|
+
readonly start?: GoToTarget;
|
|
67
|
+
/**
|
|
68
|
+
* Human-input configuration: keyboard, swipe, tap zones. Additive and optional
|
|
69
|
+
* — omitting it enables all three with defaults. See {@link InputConfig}. Input
|
|
70
|
+
* is direction-aware: `Book.direction === 'rtl'` flips the horizontal axis.
|
|
71
|
+
*/
|
|
72
|
+
readonly input?: InputConfig;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* A navigation target for {@link Reader.goTo}. Six forms:
|
|
76
|
+
* - {@link TocItem} — its `sectionId` (+ optional `fragment`)
|
|
77
|
+
* - internal `href` string — resolved to a section (+ fragment), best-effort
|
|
78
|
+
* - {@link Position} — restored by content anchor
|
|
79
|
+
* - a number in `0..1` — a fraction through the whole book
|
|
80
|
+
* - `'start'` — the first section, first page
|
|
81
|
+
* - `'end'` — the last section, last page
|
|
82
|
+
*/
|
|
83
|
+
export type GoToTarget = TocItem | Position | string | number | 'start' | 'end';
|
|
84
|
+
/** The reader's place in the book, assembled from the paginator and the book. */
|
|
85
|
+
export interface ReaderPosition {
|
|
86
|
+
/** 0-based index of the active section in reading order. */
|
|
87
|
+
readonly section: number;
|
|
88
|
+
/** Fraction through the whole book, 0..1 — approximate across unlaid sections. */
|
|
89
|
+
readonly progress: number;
|
|
90
|
+
/** Fraction through the current chapter, 0..1. */
|
|
91
|
+
readonly chapterProgress: number;
|
|
92
|
+
/** 0-based current page within the section. */
|
|
93
|
+
readonly page: number;
|
|
94
|
+
/** Total pages in the section — an estimate until the layout is firm. */
|
|
95
|
+
readonly totalPages: number;
|
|
96
|
+
}
|
|
97
|
+
/** The events a {@link Reader} emits, with their payload types. */
|
|
98
|
+
export interface ReaderEventMap {
|
|
99
|
+
/** Fires once, after the first section paints. Payload: the initial position. */
|
|
100
|
+
readonly ready: ReaderPosition;
|
|
101
|
+
/** Fires after any navigation settles. Payload: the settled position. */
|
|
102
|
+
readonly positionchange: ReaderPosition;
|
|
103
|
+
/** Fires when the active section changes. Payload: the new section index + id. */
|
|
104
|
+
readonly sectionchange: SectionChange;
|
|
105
|
+
/** Fires when an in-frame link is clicked, before it is followed. Payload: the raw href. */
|
|
106
|
+
readonly linkclick: LinkClick;
|
|
107
|
+
/** Fires when the user selects text in the frame. Payload: the text + a resolvable Position. */
|
|
108
|
+
readonly selection: SelectionEvent;
|
|
109
|
+
/** Fires when a navigation or render fails. Payload: the error. */
|
|
110
|
+
readonly error: Error;
|
|
111
|
+
}
|
|
112
|
+
export interface SectionChange {
|
|
113
|
+
/** 0-based index of the now-active section. */
|
|
114
|
+
readonly index: number;
|
|
115
|
+
/** The now-active section's id. */
|
|
116
|
+
readonly sectionId: string;
|
|
117
|
+
}
|
|
118
|
+
export interface LinkClick {
|
|
119
|
+
/** The raw authored href from the frame, exactly as reported. */
|
|
120
|
+
readonly href: string;
|
|
121
|
+
}
|
|
122
|
+
export interface SelectionEvent {
|
|
123
|
+
/** The selected text, exactly as the frame read it. */
|
|
124
|
+
readonly text: string;
|
|
125
|
+
/**
|
|
126
|
+
* A `Position` anchored at the selection's start. Resolves back against the
|
|
127
|
+
* section via {@link Reader.goTo}/`resolvePosition`, so a host can persist it
|
|
128
|
+
* (a bookmark or highlight anchor) and navigate to it later.
|
|
129
|
+
*/
|
|
130
|
+
readonly position: Position;
|
|
131
|
+
}
|
|
132
|
+
export type ReaderEvent = keyof ReaderEventMap;
|
|
133
|
+
export type ReaderEventHandler<E extends ReaderEvent> = (payload: ReaderEventMap[E]) => void;
|
|
134
|
+
/** Removes a previously-registered handler. Idempotent. */
|
|
135
|
+
export type Unsubscribe = () => void;
|
|
136
|
+
/**
|
|
137
|
+
* A live reader over one book. Navigation methods are async and settle once the
|
|
138
|
+
* paginator has moved and the corresponding events have fired. Reads of
|
|
139
|
+
* {@link position} are synchronous snapshots of the last settled state.
|
|
140
|
+
*/
|
|
141
|
+
export interface Reader {
|
|
142
|
+
/** Turn one page forward, rolling to the next section's first page at the end. */
|
|
143
|
+
next(): Promise<void>;
|
|
144
|
+
/** Turn one page back, rolling to the previous section's last page at the start. */
|
|
145
|
+
prev(): Promise<void>;
|
|
146
|
+
/** Jump to the next section's first page. No-op at the last section. */
|
|
147
|
+
nextSection(): Promise<void>;
|
|
148
|
+
/** Jump to the previous section's first page. No-op at the first section. */
|
|
149
|
+
prevSection(): Promise<void>;
|
|
150
|
+
/** Navigate to any of the six {@link GoToTarget} forms. Soft-misses degrade quietly. */
|
|
151
|
+
goTo(target: GoToTarget): Promise<void>;
|
|
152
|
+
/** Pop the internal-link back-stack and restore the pushed position. No-op when empty. */
|
|
153
|
+
back(): Promise<void>;
|
|
154
|
+
/** Switch paginated↔scrolled without reload, preserving the reading position. */
|
|
155
|
+
setMode(mode: LayoutMode): Promise<void>;
|
|
156
|
+
/**
|
|
157
|
+
* Update the live appearance without losing the reading place. Covers the theme
|
|
158
|
+
* half (colours / background) and the typography half (font family/size, line
|
|
159
|
+
* height, margin, text alignment, justification, hyphenation, 1-or-2 columns).
|
|
160
|
+
* Partial: only the fields present in `appearance` change; `customProperties`
|
|
161
|
+
* shallow-merges over the current set. A colour-only change repaints the current
|
|
162
|
+
* page in place with no reflow; a reflowing typography knob (font, size, line
|
|
163
|
+
* height, columns) re-lays out and restores the reading place by content anchor,
|
|
164
|
+
* so the place survives even though the page number may shift.
|
|
165
|
+
*/
|
|
166
|
+
setAppearance(appearance: Appearance): Promise<void>;
|
|
167
|
+
/**
|
|
168
|
+
* Full-text search over the whole book. Returns a **lazy async iterator** of
|
|
169
|
+
* {@link SearchHit}s, streaming each as its section is scanned — the book is never
|
|
170
|
+
* buffered whole, and stopping early (`break`) halts the scan (no later section is
|
|
171
|
+
* loaded). Each hit's `position` is jumpable: `await reader.goTo(hit.position)`
|
|
172
|
+
* lands on its page. Matching is normalized literal substring (case-insensitive,
|
|
173
|
+
* NFC, smart-punctuation- and whitespace-folded); it does not route through the
|
|
174
|
+
* frame — sections are decoded and scanned headlessly, independent of what is
|
|
175
|
+
* painted.
|
|
176
|
+
*/
|
|
177
|
+
search(query: string, options?: SearchOptions): AsyncIterableIterator<SearchHit>;
|
|
178
|
+
/**
|
|
179
|
+
* Draws a decoration — a styled overlay — over the range `position` resolves to,
|
|
180
|
+
* keyed by `id`. Re-issuing the same `id` replaces that overlay; the `className`
|
|
181
|
+
* on `opts` is applied to every overlay box so a host stylesheet can colour it.
|
|
182
|
+
*
|
|
183
|
+
* **Draw-only, never stored.** The reader holds the decoration *intent* (id →
|
|
184
|
+
* position + class) in memory only, so it can re-anchor the overlay across a
|
|
185
|
+
* re-layout (font-size, mode, appearance) — it never persists, serializes, or
|
|
186
|
+
* fetches annotation data. A host owns all annotation storage: to make a highlight
|
|
187
|
+
* durable, persist the `position` (or its serialized string) yourself and re-call
|
|
188
|
+
* `decorate` on the next open. The overlay is pointer-transparent and layout-
|
|
189
|
+
* neutral: it never eats a selection or a click and never changes page geometry.
|
|
190
|
+
*
|
|
191
|
+
* A soft-miss — the anchor no longer resolves, or it belongs to a section other
|
|
192
|
+
* than the one on screen — draws nothing and throws nothing; the intent is kept, so
|
|
193
|
+
* navigating to that section (or re-laying out) redraws it.
|
|
194
|
+
*/
|
|
195
|
+
decorate(id: string, position: Position, opts: {
|
|
196
|
+
className: string;
|
|
197
|
+
}): Promise<void>;
|
|
198
|
+
/** Removes the decoration drawn for `id` and drops its intent. No-op for an unknown id. */
|
|
199
|
+
undecorate(id: string): Promise<void>;
|
|
200
|
+
/**
|
|
201
|
+
* Sentence ranges for the current section, each with a `Position` anchored over
|
|
202
|
+
* the whole sentence. The **TTS enabler**: pair a sentence's `position` with
|
|
203
|
+
* {@link goTo} to jump and {@link decorate} to highlight it, and a host can step
|
|
204
|
+
* a speech engine sentence-by-sentence over the reading view. The library speaks
|
|
205
|
+
* nothing and stores nothing — it exposes ranges only. Returns `[]` before the
|
|
206
|
+
* first paint or for an empty section.
|
|
207
|
+
*/
|
|
208
|
+
sentences(): Promise<readonly SentenceRange[]>;
|
|
209
|
+
/** A synchronous snapshot of the current place in the book. */
|
|
210
|
+
readonly position: ReaderPosition;
|
|
211
|
+
/** The layout mode currently in effect. */
|
|
212
|
+
readonly mode: LayoutMode;
|
|
213
|
+
/** Subscribe to an event; returns an unsubscribe function. */
|
|
214
|
+
on<E extends ReaderEvent>(event: E, handler: ReaderEventHandler<E>): Unsubscribe;
|
|
215
|
+
/** Tear everything down: paginator, frame, data: URLs, listeners, back-stack. Idempotent. */
|
|
216
|
+
destroy(): void;
|
|
217
|
+
}
|
|
218
|
+
/** Something went wrong driving the reader; never a book decoding failure. */
|
|
219
|
+
export declare class ReaderError extends Error {
|
|
220
|
+
constructor(message: string, options?: ErrorOptions);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Renders `book` into `element` and returns a live {@link Reader}. The reader is
|
|
224
|
+
* usable immediately; the first section paints asynchronously and a `ready` event
|
|
225
|
+
* fires once it does. Options are applied where they map today and otherwise
|
|
226
|
+
* retained for M3. Pass `options.start` to open somewhere other than the book's
|
|
227
|
+
* beginning.
|
|
228
|
+
*/
|
|
229
|
+
export declare function render(book: Book, element: HTMLElement, options?: ReaderOptions): Reader;
|
|
230
|
+
export { parsePosition };
|
|
231
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/reader/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAA6B,aAAa,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC1G,OAAO,EAAE,aAAa,EAAoB,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAgC,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACnF,OAAO,EAAc,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACpF,OAAO,EAIL,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAIL,KAAK,WAAW,EAGjB,MAAM,YAAY,CAAC;AAEpB,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACxD,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAC9E,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnE;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,2CAA2C;I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