@vectoad/luxebook-core 0.0.0-stage → 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sleman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,29 @@
1
- # Temporary Holding Version
1
+ # @vectoad/luxebook-core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Framework-free engine for a 3D page-flip PDF viewer, built on Three.js and PDF.js. Use it from plain JavaScript or wrap it for any framework. For React, use [`@vectoad/luxebook-react`](https://www.npmjs.com/package/@vectoad/luxebook-react).
4
+
5
+ ```sh
6
+ npm install @vectoad/luxebook-core
7
+ ```
8
+
9
+ ```ts
10
+ import { LuxeBookViewer } from "@vectoad/luxebook-core";
11
+
12
+ const viewer = new LuxeBookViewer(document.getElementById("book")!, {
13
+ lighting: "warm",
14
+ coverStyle: "hard",
15
+ });
16
+ viewer.on("ready", (info) => console.log(info));
17
+ await viewer.load("/brochure.pdf");
18
+
19
+ viewer.next();
20
+ viewer.goToPage(5);
21
+ ```
22
+
23
+ - `load(source)` takes a URL or the PDF bytes.
24
+ - Controls: `next()`, `previous()`, `goToPage()`, `open()`, `close()`, `zoomIn()`, `zoomOut()`, `resetZoom()`.
25
+ - `setOptions()` updates appearance live; `setOverlay(element, { page })` places your own HTML on a page.
26
+ - Events: `ready`, `pagechange`, `error`, `click`, `bookstate`, `readingzoom`.
27
+ - Call `destroy()` when you're done.
28
+
29
+ MIT license. Source: https://github.com/Vectoad/luxebook
@@ -0,0 +1,211 @@
1
+ import { ViewerOptions, AppearanceOptions, ViewerState, BookState, ViewerEvents, PdfSource, DocumentInfo, OverlayPage, Spread } from '@vectoad/luxebook-types';
2
+ export * from '@vectoad/luxebook-types';
3
+
4
+ type Resolved = Required<Omit<ViewerOptions, "workerSrc" | "pdfAssetsUrl" | "lastPage">> & Pick<ViewerOptions, "workerSrc" | "pdfAssetsUrl" | "lastPage">;
5
+ declare function resolveOptions(options?: ViewerOptions): Resolved;
6
+ /**
7
+ * The LuxeBook viewer: owns one WebGL renderer and at most one open PDF,
8
+ * keeps the visible spread in sync with page textures, and exposes
9
+ * navigation and events. Framework-agnostic; React wraps this.
10
+ */
11
+ declare class LuxeBookViewer {
12
+ private readonly container;
13
+ private readonly options;
14
+ private readonly renderer;
15
+ private readonly resizeObserver;
16
+ private readonly listeners;
17
+ private doc;
18
+ /** Decoded `cover.image`, and the URL it came from. */
19
+ private coverImage;
20
+ private spreads;
21
+ private index;
22
+ private status;
23
+ private loadToken;
24
+ private showToken;
25
+ private box;
26
+ private aspect;
27
+ private resizeTimer;
28
+ private pointer;
29
+ private activeTurn;
30
+ private queuedIndex;
31
+ private zoomLevelValue;
32
+ private revealStop;
33
+ private openStop;
34
+ private openingDolly;
35
+ private openingTargetIndex;
36
+ private bookOpen;
37
+ private bookOpening;
38
+ private bookClosing;
39
+ /** How far the cover has swung open, 0–1 (drives per-state looks). */
40
+ private openAmount;
41
+ private lastBookState;
42
+ /** Reading zoom target (1 = zoomed out). */
43
+ private readingScale;
44
+ private focusStop;
45
+ /** Drag-to-pan while zoomed in. */
46
+ private pan;
47
+ /** The previous tap, to spot a double tap; its single-tap action waits in `timer`. */
48
+ private lastTap;
49
+ /** Texture size rendered for the zoom, evicted from the cache on zoom out. */
50
+ private zoomBox;
51
+ /** Single-page view in use (`layout` resolved). */
52
+ private single;
53
+ /** `setOverlay()` content: its positioned wrapper, and where it goes. */
54
+ private overlay;
55
+ constructor(container: HTMLElement, options?: ViewerOptions);
56
+ /** Current options, with defaults filled in. */
57
+ get config(): Readonly<Resolved>;
58
+ /**
59
+ * Change appearance options live (background, cover, thickness, speed,
60
+ * zoom, rotation…). Other keys are ignored: they need a new viewer.
61
+ */
62
+ setOptions(options: AppearanceOptions): void;
63
+ private setOpen;
64
+ /** Emit "bookstate" when the open/closed state changes. */
65
+ private syncBookState;
66
+ private applyLook;
67
+ get state(): ViewerState;
68
+ /** "closed" (initial pose), "opening", "open" or "closing". */
69
+ get bookState(): BookState;
70
+ /** Open the book (animated). Same as tapping the cover. */
71
+ open(): void;
72
+ /** Close the book (animated) and return it to its closed look. */
73
+ close(): void;
74
+ /** Current reading zoom: 1 when zoomed out. */
75
+ get readingZoom(): number;
76
+ /**
77
+ * Reading zoom: magnify the open book `scale`× (1–5), keeping the point at
78
+ * (clientX, clientY) under the pointer (default: the centre). `zoomTo(1)`
79
+ * zooms back out. Double-click/double-tap on a page does this for the reader;
80
+ * while zoomed in, drag or scroll pans and navigation zooms out first.
81
+ */
82
+ zoomTo(scale: number, clientX?: number, clientY?: number): void;
83
+ private zoomOutForNavigation;
84
+ get zoomLevel(): number;
85
+ on<K extends keyof ViewerEvents>(type: K, handler: (event: ViewerEvents[K]) => void): () => void;
86
+ /**
87
+ * Open a PDF, replacing any current one. Resolves once the first spread is
88
+ * on screen. A load superseded by a newer `load` rejects with code `ABORTED`.
89
+ */
90
+ load(source: PdfSource): Promise<DocumentInfo>;
91
+ private paintCover;
92
+ private loadCoverImage;
93
+ next(): void;
94
+ previous(): void;
95
+ zoomIn(): void;
96
+ zoomOut(): void;
97
+ resetZoom(): void;
98
+ goToPage(page: number): void;
99
+ /**
100
+ * Put your own HTML (a contact form, a video, buttons) on a page: it sits
101
+ * on the page in perspective, follows camera moves and reading zoom, and
102
+ * fades out while that page turns or the book closes (HTML can't curl).
103
+ * Default page: `"end"`. Pass `null` to remove it. Size it with CSS
104
+ * `width/height: 100%`: the wrapper is exactly the page.
105
+ */
106
+ setOverlay(element: HTMLElement | null, options?: {
107
+ page?: OverlayPage;
108
+ }): void;
109
+ /** The side the overlay's page lies on right now, or null while it shouldn't show. */
110
+ private overlaySide;
111
+ private syncOverlay;
112
+ destroy(): void;
113
+ /** Test hook: render synchronously and return the WebGL canvas. */
114
+ snapshot(): HTMLCanvasElement;
115
+ private showSpread;
116
+ private paint;
117
+ /**
118
+ * Texture size for one page: about the page's on-screen size in device
119
+ * pixels, snapped to 128 px steps (stable cache keys during resizes) and
120
+ * clamped to the configured and GPU limits.
121
+ */
122
+ private computeBox;
123
+ /** Re-render the visible pages for the current reading zoom; drop the big renders when zoomed out. */
124
+ private sharpenForZoom;
125
+ /** Jump straight back to the unzoomed view (new document). */
126
+ private resetReadingZoom;
127
+ /** PDF pages the reader can see: all of them, or up to `lastPage`. */
128
+ private get readablePages();
129
+ /** Pages in the book: with `lastPage`, one blank preview page follows the last readable one. */
130
+ private get pageCount();
131
+ private makeSpreads;
132
+ /** The page a reader is on: the right one in single layout, else the lowest visible. */
133
+ private pageOf;
134
+ /**
135
+ * Switch between the spread and the single-page view when `layout` (or,
136
+ * for "auto", the viewer's shape) calls for it, staying on the same page.
137
+ */
138
+ private applyLayout;
139
+ private onResize;
140
+ /** Fade in and settle the camera: restrained, and skipped for reduced motion. */
141
+ private reveal;
142
+ private setZoomLevel;
143
+ private readonly onPointerDown;
144
+ private readonly onPointerMove;
145
+ private readonly onPointerUp;
146
+ /** Is this tap the second of a double tap? Otherwise it becomes the "previous tap". */
147
+ private isDoubleTap;
148
+ /** Trackpad pinch (or ctrl+wheel) zooms; plain scrolling pans while zoomed in. */
149
+ private readonly onWheel;
150
+ private lastWheel;
151
+ private wheelAcc;
152
+ private wheelDir;
153
+ /**
154
+ * Emit a "click" for a tap. Returns what was hit, or null when a listener
155
+ * called preventDefault() or nothing actionable was hit.
156
+ */
157
+ private click;
158
+ private readonly onPointerCancel;
159
+ private beginPointerTurn;
160
+ /** The pointer holds a leaf hinged on `side`: the grabbed point keeps its offset from the pointer. */
161
+ private grab;
162
+ private get softCover();
163
+ /**
164
+ * A fold for the soft cover: held by `pointer` (by its edge, where it was
165
+ * grabbed), or, without one, a timed turn lifting the bottom corner.
166
+ */
167
+ private coverPhysics;
168
+ /** The hover-lifted corner, while it is only that. */
169
+ private get peeking();
170
+ /** A mouse over a page corner lifts it a little, inviting a click or drag; leaving lays it back. */
171
+ private updatePeek;
172
+ private endPeek;
173
+ private readonly onPointerLeave;
174
+ /** A page corner (outer edge, top or bottom) under a client point, with the page-local point; only where a turn can go. */
175
+ private cornerAt;
176
+ private updatePointerTurn;
177
+ private startNavigationTurn;
178
+ private createTurn;
179
+ private prepareTurnBack;
180
+ private settleTurn;
181
+ private runTurnAnimation;
182
+ private requestNavigation;
183
+ private continueQueuedNavigation;
184
+ private openBook;
185
+ /** In cover mode the first spread is the closed book, so going back to it shuts the cover. */
186
+ private closesBook;
187
+ /** Reverse of `openBook`: swing the cover back over the current spread, then settle on the cover. */
188
+ private closeBook;
189
+ /**
190
+ * Soft cover: fold it open (or shut) like a page, the book sliding and the
191
+ * camera moving with it. `timed`: a tap or key; otherwise a drag in
192
+ * progress, which may also be dropped back where it started.
193
+ */
194
+ private foldCover;
195
+ /** The cover's inside shows the page that will lie on the left once it lands. */
196
+ private paintCoverInside;
197
+ private cancelActiveTurn;
198
+ private emit;
199
+ private assertAlive;
200
+ }
201
+
202
+ /**
203
+ * Split a document into two-page openings.
204
+ * With `showCover`, page 1 stands alone on the right (a closed book's
205
+ * cover) and, for an even page count, the last page stands alone on the left.
206
+ */
207
+ declare function computeSpreads(pageCount: number, showCover: boolean): Spread[];
208
+ /** Index of the spread containing `page` (clamped to the document). */
209
+ declare function spreadIndexOf(spreads: readonly Spread[], page: number): number;
210
+
211
+ export { LuxeBookViewer, computeSpreads, resolveOptions, spreadIndexOf };